Skip to content

Conversation

nlguillemot
Copy link
Contributor

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 by glBindSampler(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.

@nlguillemot
Copy link
Contributor Author

Just a guess, but this might be related to #1141

@ocornut ocornut merged commit ad3c1e6 into ocornut:master Sep 1, 2017
ocornut added a commit that referenced this pull request Sep 1, 2017
@ocornut
Copy link
Owner

ocornut commented Sep 1, 2017

Thanks Nicolas, this is now merged.

@ocornut ocornut added the opengl label Jan 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants