Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backends: OpenGL3: Add compatibility of GL_VERSION for GL 2.x #6154

Closed
wants to merge 1 commit into from

Conversation

grauw
Copy link

@grauw grauw commented Feb 9, 2023

GL_MAJOR_VERSION and GL_MINOR_VERSION are available on GL 3.0 and above. So we have to parse GL_VERSION under GL 2.x

Reference https://www.khronos.org/opengl/wiki/OpenGL_Context#Context_information_queries
Regressed since 459de65
See #3530

@ocornut
Copy link
Owner

ocornut commented Feb 9, 2023

Hello,
Thanks for tracking and fixing this!
This file is auto-generated from https://github.com/dearimgui/gl3w_stripped so we would need the fix applied there so future generated files will have the fix applied.

@grauw
Copy link
Author

grauw commented Feb 9, 2023

Hang on.

…t#6154)

GL_MAJOR_VERSION and GL_MINOR_VERSION are available on GL 3.0 and above.
So we have to parse GL_VERSION under GL 2.x

Reference https://www.khronos.org/opengl/wiki/OpenGL_Context#Context_information_queries
Regressed since 459de65
See ocornut#3530
@grauw
Copy link
Author

grauw commented Feb 9, 2023

Accompanying pull request overthere: dearimgui/gl3w_stripped#2.

Additionally, I had missed the minimum version check in imgl3wIsSupported(), which I now also lowered to 2.

grauw added a commit to grauw/gl3w_stripped that referenced this pull request Feb 9, 2023
GL_MAJOR_VERSION and GL_MINOR_VERSION are available on GL 3.0 and above.
So we have to parse GL_VERSION under GL 2.x

Reference https://www.khronos.org/opengl/wiki/OpenGL_Context#Context_information_queries
See ocornut/imgui#6154
grauw added a commit to grauw/gl3w_stripped that referenced this pull request Feb 9, 2023
…gui#2)

GL_MAJOR_VERSION and GL_MINOR_VERSION are available on GL 3.0 and above.
So we have to parse GL_VERSION under GL 2.x

Reference https://www.khronos.org/opengl/wiki/OpenGL_Context#Context_information_queries
See ocornut/imgui#6154
@grauw
Copy link
Author

grauw commented Feb 9, 2023

p.s. I notice that the original project gl3w_stripped was forked from only intended to provide access to the OpenGL core profile specification (introduced in OpenGL 3.2, as I understand it — sorry not an OpenGL whiz). However ImGui supports OpenGL 2.x as well, and depends on imgui_impl_opengl3_loader.h even if we use a different loader (in our case, SDL2).

Maybe instead of taking this approach of modifying gl3w, ImGui_ImplOpenGL3_Init should be modified to not use the custom loader when IMGUI_IMPL_OPENGL_LOADER_CUSTOM is not defined? Though, that may be difficult since from a casual inspection it does seem to rely on it.

@ocornut
Copy link
Owner

ocornut commented Feb 10, 2023

I am not sure I understand your suggestion.
Our loader is used unless IMGUI_IMPL_OPENGL_LOADER_CUSTOM is used.

If the current change works for you I'm fine with it. Can you describe your setup where this is needed?

@PathogenDavid
Copy link
Contributor

However ImGui supports OpenGL 2.x as well, and depends on imgui_impl_opengl3_loader.h

The OpenGL 2 and 3 backends are separate. Unless I'm missing something imgui_impl_opengl3_loader.h should only be used by imgui_impl_opengl3.

@ocornut
Copy link
Owner

ocornut commented Feb 10, 2023

There is a mislabeling but I believe OpenGL 2.0 contexts should be able to use imgui_impl_opengl3.cpp
We should probably rename imgui_impl_opengl2 -> imgui_impl_opengl_legacy
See #1900

@PathogenDavid
Copy link
Contributor

PathogenDavid commented Feb 10, 2023

(Edit: Omar sniped me, this wasn't where the misunderstanding came from.)

Maybe never mind my earlier comment, I see now from looking at the older PR mentioned that this fix is intended for OpenGL ES 2.0.

only intended to provide access to the OpenGL core profile specification

The core profile mainly just deprecates ancient functionality, I don't think it's meaningfully different from the perspective of what Dear ImGui is using in the backends.

@grauw
Copy link
Author

grauw commented Feb 10, 2023

@PathogenDavid Right at the top of imgui_impl_opengl3.cc it says:

// dear imgui: Renderer Backend for modern OpenGL with shaders / programmatic pipeline
// - Desktop GL: 2.x 3.x 4.x
// - Embedded GL: ES 2.0 (WebGL 1.0), ES 3.0 (WebGL 2.0)
// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)

So hence my assumption this backend is supposed to support OpenGL 2.x as well. At least historically it did, but maybe it changed, and comments be comments do tend get out of date.

For context, someone from an emulator project that I contribute to is experimenting adding Dear ImGui to it. The emulator’s OpenGL backend currently uses OpenGL 2.1 (with shaders, not fixed function), although it has provisions for optionally changing to 3.x or ES x.x (something that’s being considered). As far as I understood they followed a tutorial to get started. It works on their Linux PC, but on my Mac it fails on that version number check, and I can make it work by making this modification.

But of course although I have had some cursory encounters with Dear ImGui in the past, I am far from an expert on its code base, so that’s why I was wondering whether this was the right approach.

@PathogenDavid
Copy link
Contributor

@grauw No I think you and that comment are right, I had in my head it wasn't supposed to be compatible. If this is the only thing wrong with it this is definitely a sensible fix.

@grauw
Copy link
Author

grauw commented Feb 10, 2023

Yes I understand it better now too, also with the context of the older issue that @ocornut referred to. The "gl2" backend is intended for the fixed function pipeline (legacy) while the "gl3" is intended for the shaders pipeline (core). And it is probably somewhat confusingly named "gl3" in gl3w because the concept of the core profile was introduced in OpenGL 3, but it equally applies to the shaders pipeline subset of OpenGL 2, so it makes sense for gl3w to also support that.

An additional complicating / confusing factor is that on Apple’s OpenGL implementation apparently you can use GL 2 only in compatibility mode, whereas GL 3 can only be used in core mode. But in the end that doesn’t matter as long as you stick to using only the specific subset appropriate for the pipeline of choice.

Anyway, given that, ignore my thoughts about IMGUI_IMPL_OPENGL_LOADER_CUSTOM.

ocornut pushed a commit to dearimgui/gl3w_stripped that referenced this pull request Feb 14, 2023
GL_MAJOR_VERSION and GL_MINOR_VERSION are available on GL 3.0 and above.
So we have to parse GL_VERSION under GL 2.x
Reference https://www.khronos.org/opengl/wiki/OpenGL_Context#Context_information_queries
See ocornut/imgui#6154
Co-authored-by: Laurens Holst <laurens@grauw.nl>
ocornut pushed a commit that referenced this pull request Feb 14, 2023
…2.x (#6154, #4445, #3530)

GL_MAJOR_VERSION and GL_MINOR_VERSION are available on GL 3.0 and above.
So we have to parse GL_VERSION under GL 2.x
Reference https://www.khronos.org/opengl/wiki/OpenGL_Context#Context_information_queries
Regressed since 459de65
See #3530
@ocornut
Copy link
Owner

ocornut commented Feb 14, 2023

Merged as b0c1816, thank you !

@ocornut ocornut closed this Feb 14, 2023
m9710797 added a commit to openMSX/openMSX that referenced this pull request Feb 15, 2023
ocornut added a commit that referenced this pull request Mar 15, 2023
kjblanchard pushed a commit to kjblanchard/imgui that referenced this pull request May 5, 2023
…2.x (ocornut#6154, ocornut#4445, ocornut#3530)

GL_MAJOR_VERSION and GL_MINOR_VERSION are available on GL 3.0 and above.
So we have to parse GL_VERSION under GL 2.x
Reference https://www.khronos.org/opengl/wiki/OpenGL_Context#Context_information_queries
Regressed since 459de65
See ocornut#3530
kjblanchard pushed a commit to kjblanchard/imgui that referenced this pull request May 5, 2023
ocornut pushed a commit to dearimgui/gl3w_stripped that referenced this pull request May 7, 2024
GL_MAJOR_VERSION and GL_MINOR_VERSION are available on GL 3.0 and above.
So we have to parse GL_VERSION under GL 2.x
Reference https://www.khronos.org/opengl/wiki/OpenGL_Context#Context_information_queries
See ocornut/imgui#6154
Co-authored-by: Laurens Holst <laurens@grauw.nl>
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.

3 participants