mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-04 10:07:58 +00:00
OpenGL backend now embeds its own GL loader (imgui_impl_opengl3_loader.h) #4445
Labels
No labels
accidentally closed
android
backends
bug
building
clipper
coloredit
color spaces
cplusplus
data types
demo
disabled
doc
docking
dpi
drag drop
drawing/drawlist
dropped
dx12
enhancement
focus
font/text
gallery
help wanted
idle/power saving
ime
in progress
inputs
inputtext
internals
label/id and id stack
language bindings
layout
linux/bsd
menus
multi-contexts
multi-threading
multi-viewports
nav
news/info
opengl
optimization
osx/ios
overlap
plot/graph
popups
question
scrolling
selection
settings
sliders/drags
style
tables/columns
tabs
test wanted
tools
tooltips
tree
tricks & tips
useful widgets
vulkan
web
window pos/depth
window sizing
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ocornut/imgui#4445
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
TL;DR;
Our GL backend now embed its own minimal GL loader (embedded file; full source repo)
User/application don't need to configure anything related to GL loader.
User/application can use their own GL loader of choice regardless of what our backend does.
Thanks @rokups!
What is an OpenGL loader
Desktop OpenGL doesn't have standard portable header/libs files for all features GL offers.
Helper libraries are often used for this purpose. There are many of them: glew, glad, glbinding, glext to name a few (easy to recreate one). Those libraries tend to two things:
WebGL and GL ES do not suffer from this as the headers and libraries are better standardized.
What our imgui_impl_opengl backend did (and the problems)
Until recently, the OpenGL3 backends and examples made a best effort to support variety of GL loaders. This turned to be a mistake which created confusion for users (many of them being newcomers to OpenGL, to Dear ImGui or to C++ programming in general), as this support relied on compile-time defines, plus an attempt at detecting available system includes (which I also now firmly regret).
To be able to provide examples that would compile out of the box we had to include a loader in the examples folder. We included gl3w, which was picked at the time because its output was small and neat, but as many existing GL users used another loader it was confusing for them.
What frequently happened is user's existing application used loader X and compiled our backend in a way that used loader Y which was either not initialized, either not linked. This made integrating Dear ImGui in an established OpenGL codebase more confusing.
Our setup, which required the user to provide and initialize (on their side) the GL loader that the backend used, unwillingly contributed to perpetuate a common misconception that "an application can't use multiple GL loaders". A loader is merely a bunch of defines and function pointers, of course we can!
Things got even more complicated as package managers like vcpkg are trying to provide a seamless experience where the user can grab e.g. "imgui" + "opengl3 backend" but that needed to drag loader libraries into the mix and they would need to be initialized by a call that vcpkg couldn't magically inject into user app. (See their issue https://github.com/microsoft/vcpkg/issues/14753)
What are are now doing
(This is the work of @rokups)
We decided to simply embed and use own loader, solely for usage by imgui_impl_opengl3.cpp.
The new loader is backends/imgui_impl_opengl3_loader.h and automatically used by our backend.
If you update your backends by copying files, you'll have to grab this file too.
It means that it doesn't matter which GL loader your existing application is using. We don't care. We have our own. Both can cohabit.
Because we are committed to our bloat free approach, we had concerns with adding a "regular" loader inside
backends/as most available loaders are now a bit large. We forked gl3w into gl3w_stripped which greps for symbols used by imgui_impl_opengl3.cpp and only include the one we need. As a result, backends/imgui_impl_opengl3_loader.h is only about ~32 KB of source file and compiles to almost nothing.That's all!
(
PS: on the unlikely case that your app ended up using our old copy of gl3w directly from our repository in examples/libs/gl3w: (1) You may access gl3w original repository https://github.com/skaslev/gl3w, (2) You may grab the files from dear imgui 1.83 repo, or (3) You may look at https://github.com/dearimgui/gl3w_stripped which is our fork of gl3w that handle filtering.
)
Links
Here's a partial list of issues related to compiling/linking/configuring GL loaders:
#4390 #4279 #4428 #3986 #3860 #3769 #3736 #3507 #3330 #3246 #2798 #3061 #2919 #2870 #2806 #2785 #2444 #2180 #2178 #2002 #2001 #1988 #1956 #1806 #1576 #880 #483
This is my OpenGL ES 3.2 Loader. (Lazy import)
https://github.com/metarutaiga/TensorFlowLiteReduce/blob/master/third_party/GLES3/gl3_loader.c
https://github.com/metarutaiga/xxGraphic/blob/master/internal/xxGraphicInternalGL.cpp
1.It can prevent to run a null pointer calling.
2.Not to need include its header, like a library linking.
3.To add a function needs one line only.
4.It can reduce code size because it linked we need functions.
This is great news and will help other programming language communities re-use the official C++ backend instead of each re-implementing their own due to problems with some loaders unable to cross the FFI boundary. Looks significantly simpler now, thank you.
After I updated to the version with this, the images I load with my (complete) gl3w loader end up black. If I replace
#include "imgui_impl_opengl3_loader.h"with my owngl3w.hthen it works. Am I not supposed to be able to create GL texture id's with one loader and use them with the new embedded one?Thanks for reporting @parbo. I can't understand how this would have an impact. The loader are essentially merely function pointers to GL functions and a bunch of defines. We also made sure that our forked-stripped-gl3w used non conflicting symbols so gl3w could still be used...
But it is arguably troubling if just replacing the header included from imgui_impl_opengl3.cpp works.
Could there be a difference in the #ifdef paths taken by the backend?
That was my theory too, but I didn't find anything obvious. I will try some more tomorrow..
When I updated it too and then executed the program, I got some memory access violations on Windows during the loader initialization. However, when I tried to compile the same project on Linux, I got "multiple definitions for gl3wProcs" during linking. It appears that the definitions for the union GL3WProcs are different in the files gl3w.c and imgui_impl_opengl3.h. Could it be the reason for your black images?
OK it looks like we broke something (@rokups?) the symbols in that file are called
gl3wProcsand not static, it might conflict with another copy of gl3w.@parbo @MachSilva in
imgui_impl_opengl3_loader.hCan you try renaming
gl3wProcstoimgl3wProcs(using CASE SENSITIVE, FULL WORD search & replace to not mess with the union name).It should be those lines:
Yes. It solved my problem on both platforms. Thank you.
It does indeed fix my problems too!
Merged
4c22b3e5to fix this.the loader is including "<dlfcn.h>", which is not present on my embedded system. I am not sure how to resolve this issue. Am i stuck on an earlier version?
@Slluxx which loader did you use that worked in the earlier version? Whats your embedded system and how did the previous loader access the functions?
i was using imgui v1.77, which did not have a loader file. If it did but hidden, then im unsure about the details.
Im using the nintendo switch, glfw and opengl3.
It always used a loader. Add a printf in the init function to display the gl_loader variable and find which one you used.
I would like to get this fixed but we can’t do it without the help of affected users.
could you please teach me how to solve this problem
""" fatal error C1189: #error: "Cannot detect OpenGL loader!" """,
@feipiefei This is not a problem anymore with latest version.
sorry for the super late reply, i havent tried to update since then.
gl_loader is "glad". now i am struggeling to figure out how to get it back working
Well we should look how GLAD worked on your system and mimick that.
What's your Nintendo Switch SDK name/version?
Maybe get back to a old setup with GLAD and see what code GLAD calls.
If I skim at GLAD sources (https://glad.dav1d.de/)
It seems to always use
<dlfcn.h>on non-Windows systems, so I think the assumption that dlfcn.h is not available on your compiler setup may be wrong...I am just using a plain old hacked switch together with a toolchain from devkitpro.
There are a few examples on how to work with GLAD on the system, one being this.
In my 1.77 code, i use
imgui_impl_opengl3andimgui_impl_glfwand none of them seem to include<dlfcn.h>.Maybe i am just doing something super wrong? all that glad, glfw, opengl, gles, ... stuff is very confusing.
I wish markdown had spoilers. Anyway, this code works on my console.
Where's the code for GLAD.c ?
Glad.c here seems to always include dlfnc.h
We should probably include a way to optional pass in a function loader to the OpenGL backend, may help some users, but right now I don't see how things would compile.
@ocornut here it is
@Slluxx Somebody would need to study that version of Glad and see how the logic can be ported to our GL3W, find how to make it compile and if we can make it possible for your code to initialize it with a custom GL3WGetProcAddressProc function.
This should be done by someone using your devkit.
Closing this as idle (and the big issue/news is done).
@Slluxx I am open to add support for a custom loader function, but someone using that homebrew Switch SDK would need to investigate this and submit the PR.