save and restore sampler in GL 3 examples #1145
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
OpenGL 3.2 added the ability to create a separate sampler object that overrides a bound texture's sampler state.
Imgui's GL3 bindings rely on the sampler state stored within the texture object itself, so if the user binds a sampler before
ImGui::Render
is called, it can "accidentally" override the sampler state of ImGui, which can have horrible consequences (in my case, my imgui just turned black.)To fix this, the sampler binding for texture image unit 0 is saved and restored before and after ImGui's OpenGL rendering function, and the call to
glBindTexture
during rendering is followed byglBindSampler(0, 0)
, which explicitly asks to use the texture's built-in sampler state rather than using the currently bound sampler object.Since sampler objects were introduced in OpenGL 3.2, this might cause an incompatibility for people on OpenGL 3.0 or 3.1, which is a bit strange since the example program is titled "opengl3_example". However, OpenGL 3.2 was a major milestone release that introduced the "core" profile, and is widely supported for that reason, so it might not be so bad. If somebody is restricted to GL 3.0 or 3.1 for some reason, they can just delete the 3 related lines of code.