-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Questions about Desktop OpenGL loaders #4390
Comments
Related issue in vcpkg: |
OpenGL loaders are a terrible mess but somehow in 13 years since GL3 nothing has been standardized leaving it to third party loaders to retrieve the function pointers. This makes sharing/reusing OpenGL code accross projects immensely painful.
The loaders essentially provide two things: variety of defines/enum, and function pointers named after OpenGL functions. Those functions pointers are NULL during startup, and “initializing” a loader essentially sets them at runtime.
The main confusion - what many people misunderstand - it that what matter is which loader the imgui_impl_opengl3.cpp COMPILATION UNIT sees.
And because we don’t attempt to initialize the loader ourselves, the user application needs to initialize the same loader on their side too (*).
What your snippets omit is telling the opengl3.cpp backend which loader to use. There is a define for that. It’s not possible to make a runtime option because in a same compilation unit, two loaders would conflicts since their headers provide defines and function pointers. In a same project it is technically possible to have multiple loaders (not particularly useful but i imagine in megaapps with many librairies it’s probable that it happens). Conservely there is not added value to using user’s loader or any specific loader. We just somehow need those opengl defines and function pointers, regardless of where they come from (**)
Adding to the confusion the fact that is that define is omitted, we attempt to detect a loader based on available include paths. In retrospect maybe this wasn’t a good idea as it can make things confusing for users. You can’t rely on autodetection if your include paths contains other loaders.
From vcpkg point of view, each loader should be its own library and the user should still be responsible for initializing it. Its annoying.
(*) Last time I checked none of the loader had issue initializing more than once, so I was thinking maybe if imgui_impl_opengl3 did also try to initlaize the loader it sees, it would decrease number of issues (but essentially it’ll make cases where user think they are using loader A but backend actually see loader B “silently work” instead of “fail”. That’s quite debatable)
(**) Another solution may be to bite the bullet and develop/embed our own loader OR find a loader we can embed into the backend and get done with it…..
|
There are two ways you could go about this. If you can somehow detect that GLAD is being used then vcpkg could define I’m tempted to recommend we could investigate the solution of embedding our own loader and not supporting/requiring a user loader…. Would simplify many things for users (with and without vcpkg). |
If we decided that imgui_impl_opengl3 always initialized the loader it knows about, it would mean that a system like vcpkg could also decide that adding imgui_impl_opengl3 would automatically drag and enforce a certain loader (whichever you choose) and set the define for it, user won’t have an extra init call to do. Even if user app used another loader it would work then. |
Thanks for your so detailed information and suggestion to solve the problem. I think we should set the define for it according to a certain loader. |
Update: we decided to bite the bullet and we (and by we I mean @rokups) are working toward embedding our own minimalist OpenGL loader into the backend, in order to put in end to that endless amount of confusion/misery caused by the OpenGL loaders. We already have a version working and we'll either aim to use it in 1.84 or right after 1.84 is released. TL;DR; ihmo don't put effort into solving this on your end now. |
Should now be solved and made much simpler by #4445 |
Version/Branch of Dear ImGui:
Version: 1.83
Branch: master
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_opengl3.cpp
Compiler: GCC 11.1.0
Operating System: Ubuntu 18.04
My Issue/Question:
When using
imgui
in vcpkg, we found thatimgui
failed to compile with the following errors(Please see the details in Screenshots/Video part). Through investigation, we noticed that it seems like there is only one OpenGL loader supported for once in imgui_impl_opengl3.h.https://github.com/ocornut/imgui/blob/f99fe72c42bd5d578c2443409192b139b1c6623d/backends/imgui_impl_opengl3.h#L48-#L83
Could you please help confirm if these OpenGL loaders are mutually exclusive each other?
Thanks in advance.
Screenshots/Video
Standalone, minimal, complete and verifiable example: (see #2261)
The text was updated successfully, but these errors were encountered: