|
24 | 24 | // CHANGELOG
|
25 | 25 | // (minor and older changes stripped away, please see git history for details)
|
26 | 26 | // 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
| 27 | +// 2025-02-18: OpenGL: Lazily reinitialize embedded GL loader for when calling backend from e.g. other DLL boundaries. (#8406) |
27 | 28 | // 2024-10-07: OpenGL: Changed default texture sampler to Clamp instead of Repeat/Wrap.
|
28 | 29 | // 2024-06-28: OpenGL: ImGui_ImplOpenGL3_NewFrame() recreates font texture if it has been destroyed by ImGui_ImplOpenGL3_DestroyFontsTexture(). (#7748)
|
29 | 30 | // 2024-05-07: OpenGL: Update loader for Linux to support EGL/GLVND. (#7562)
|
|
171 | 172 | // - You can temporarily use an unstripped version. See https://github.com/dearimgui/gl3w_stripped/releases
|
172 | 173 | // Changes to this backend using new APIs should be accompanied by a regenerated stripped loader version.
|
173 | 174 | #define IMGL3W_IMPL
|
| 175 | +#define IMGUI_IMPL_OPENGL_LOADER_IMGL3W |
174 | 176 | #include "imgui_impl_opengl3_loader.h"
|
175 | 177 | #endif
|
176 | 178 |
|
@@ -282,21 +284,31 @@ struct ImGui_ImplOpenGL3_VtxAttribState
|
282 | 284 | };
|
283 | 285 | #endif
|
284 | 286 |
|
| 287 | +// Not static to allow third-party code to use that if they want to (but undocumented) |
| 288 | +bool ImGui_ImplOpenGL3_InitLoader(); |
| 289 | +bool ImGui_ImplOpenGL3_InitLoader() |
| 290 | +{ |
| 291 | + // Initialize our loader |
| 292 | +#ifdef IMGUI_IMPL_OPENGL_LOADER_IMGL3W |
| 293 | + if (glGetIntegerv == NULL && imgl3wInit() != 0) |
| 294 | + { |
| 295 | + fprintf(stderr, "Failed to initialize OpenGL loader!\n"); |
| 296 | + return false; |
| 297 | + } |
| 298 | +#endif |
| 299 | + return true; |
| 300 | +} |
| 301 | + |
285 | 302 | // Functions
|
286 | 303 | bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
|
287 | 304 | {
|
288 | 305 | ImGuiIO& io = ImGui::GetIO();
|
289 | 306 | IMGUI_CHECKVERSION();
|
290 | 307 | IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
291 | 308 |
|
292 |
| - // Initialize our loader |
293 |
| -#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) && !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM) |
294 |
| - if (imgl3wInit() != 0) |
295 |
| - { |
296 |
| - fprintf(stderr, "Failed to initialize OpenGL loader!\n"); |
| 309 | + // Initialize loader |
| 310 | + if (!ImGui_ImplOpenGL3_InitLoader()) |
297 | 311 | return false;
|
298 |
| - } |
299 |
| -#endif |
300 | 312 |
|
301 | 313 | // Setup backend capabilities flags
|
302 | 314 | ImGui_ImplOpenGL3_Data* bd = IM_NEW(ImGui_ImplOpenGL3_Data)();
|
@@ -416,6 +428,8 @@ void ImGui_ImplOpenGL3_NewFrame()
|
416 | 428 | ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
417 | 429 | IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplOpenGL3_Init()?");
|
418 | 430 |
|
| 431 | + ImGui_ImplOpenGL3_InitLoader(); // Lazily init loader if not already done for e.g. DLL boundaries. |
| 432 | + |
419 | 433 | if (!bd->ShaderHandle)
|
420 | 434 | ImGui_ImplOpenGL3_CreateDeviceObjects();
|
421 | 435 | if (!bd->FontTexture)
|
@@ -507,6 +521,8 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
|
507 | 521 | if (fb_width <= 0 || fb_height <= 0)
|
508 | 522 | return;
|
509 | 523 |
|
| 524 | + ImGui_ImplOpenGL3_InitLoader(); // Lazily init loader if not already done for e.g. DLL boundaries. |
| 525 | + |
510 | 526 | ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
|
511 | 527 |
|
512 | 528 | // Backup GL state
|
|
0 commit comments