From 4a51295c9e72b7339657c7e3baa40a66bc359caa Mon Sep 17 00:00:00 2001 From: Tim-Rex Date: Sat, 12 Jul 2025 16:47:45 +1000 Subject: [PATCH] Backends: OpenGL3: add and call embedded loader shutdown in ImGui_ImplOpenGL3_Shutdown(). (#8792) Include update of imgui_impl_opengl3_loader.h as submitted to gl3w_stripped repository, which adds imgl3wShutdown(). --- backends/imgui_impl_opengl3.cpp | 5 +++++ backends/imgui_impl_opengl3_loader.h | 14 ++++++++++---- docs/CHANGELOG.txt | 2 ++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/backends/imgui_impl_opengl3.cpp b/backends/imgui_impl_opengl3.cpp index 00d1d94c3..607d24371 100644 --- a/backends/imgui_impl_opengl3.cpp +++ b/backends/imgui_impl_opengl3.cpp @@ -23,6 +23,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2025-07-22: OpenGL: Add and call embedded loader shutdown during ImGui_ImplOpenGL3_Shutdown() to facilitate multiple init/shutdown cycles in same process. (#8792) // 2025-07-15: OpenGL: Set GL_UNPACK_ALIGNMENT to 1 before updating textures (#8802) + restore non-WebGL/ES update path that doesn't require a CPU-side copy. // 2025-06-11: OpenGL: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. Removed ImGui_ImplOpenGL3_CreateFontsTexture() and ImGui_ImplOpenGL3_DestroyFontsTexture(). // 2025-06-04: OpenGL: Made GLES 3.20 contexts not access GL_CONTEXT_PROFILE_MASK nor GL_PRIMITIVE_RESTART. (#8664) @@ -422,6 +423,10 @@ void ImGui_ImplOpenGL3_Shutdown() io.BackendRendererUserData = nullptr; io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures); IM_DELETE(bd); + +#ifdef IMGUI_IMPL_OPENGL_LOADER_IMGL3W + imgl3wShutdown(); +#endif } void ImGui_ImplOpenGL3_NewFrame() diff --git a/backends/imgui_impl_opengl3_loader.h b/backends/imgui_impl_opengl3_loader.h index aa8fdc27e..c3f5a93f5 100644 --- a/backends/imgui_impl_opengl3_loader.h +++ b/backends/imgui_impl_opengl3_loader.h @@ -477,6 +477,7 @@ typedef GL3WglProc (*GL3WGetProcAddressProc)(const char *proc); /* gl3w api */ GL3W_API int imgl3wInit(void); GL3W_API int imgl3wInit2(GL3WGetProcAddressProc proc); +GL3W_API void imgl3wShutdown(void); GL3W_API int imgl3wIsSupported(int major, int minor); GL3W_API GL3WglProc imgl3wGetProcAddress(const char *proc); @@ -632,7 +633,7 @@ extern "C" { #endif #include -static HMODULE libgl; +static HMODULE libgl = NULL; typedef PROC(__stdcall* GL3WglGetProcAddr)(LPCSTR); static GL3WglGetProcAddr wgl_get_proc_address; @@ -645,7 +646,7 @@ static int open_libgl(void) return GL3W_OK; } -static void close_libgl(void) { FreeLibrary(libgl); } +static void close_libgl(void) { FreeLibrary(libgl); libgl = NULL; } static GL3WglProc get_proc(const char *proc) { GL3WglProc res; @@ -657,7 +658,7 @@ static GL3WglProc get_proc(const char *proc) #elif defined(__APPLE__) #include -static void *libgl; +static void *libgl = NULL; static int open_libgl(void) { libgl = dlopen("/System/Library/Frameworks/OpenGL.framework/OpenGL", RTLD_LAZY | RTLD_LOCAL); @@ -666,7 +667,7 @@ static int open_libgl(void) return GL3W_OK; } -static void close_libgl(void) { dlclose(libgl); } +static void close_libgl(void) { dlclose(libgl); libgl = NULL; } static GL3WglProc get_proc(const char *proc) { @@ -834,6 +835,11 @@ int imgl3wInit2(GL3WGetProcAddressProc proc) return parse_version(); } +void imgl3wShutdown(void) +{ + close_libgl(); +} + int imgl3wIsSupported(int major, int minor) { if (major < 2) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index da2162b9f..edc43247a 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -50,6 +50,8 @@ Other Changes: and TableSetBgColor() calls. (#1651, #8499) - Misc: removed more redundant inline static linkage from imgui_internal.h to facilitate using in C++ modules. (#8813, #8682, #8358) [@stripe2933] +- Backends: OpenGL3: add and call embedded loader shutdown in ImGui_ImplOpenGL3_Shutdown() + to facilitate multiple init/shutdown cycles in same process. (#8792) [@tim-rex] - Backends: OpenGL2, OpenGL3: set GL_UNPACK_ALIGNMENT to 1 before updating textures. (#8802) [@Daandelange]