From d3d04f87639c018e7e67a9682270b442c79c13c8 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 20 Feb 2020 15:49:15 +0100 Subject: [PATCH] Support older 2.x series of glbinding as loader for OpenGL3 For the moment I have only the older 2.x series available on my system which uses slightly different header filenames and initialisation, so as a slight variation of the 3.x series support recently implemented here the glue needed to make 2.x series work as well. As having a versioned and a unversioned definition is deemed to confusing we use the unversioned definition for auto-detection on supporting compilers and add two versioned definitions for explicit requests. References: #2870, 5e2329b98e6562c9e7883e92dcf878e969d81878 --- examples/example_glfw_opengl3/Makefile | 4 ++++ examples/example_glfw_opengl3/main.cpp | 11 +++++++++-- examples/example_sdl_opengl3/Makefile | 4 ++++ examples/example_sdl_opengl3/main.cpp | 13 ++++++++++--- examples/imgui_impl_opengl3.cpp | 16 +++++++++++++--- examples/imgui_impl_opengl3.h | 24 +++++++++++++++++++++--- 6 files changed, 61 insertions(+), 11 deletions(-) diff --git a/examples/example_glfw_opengl3/Makefile b/examples/example_glfw_opengl3/Makefile index f0160b19492b..ac0be13bfe39 100644 --- a/examples/example_glfw_opengl3/Makefile +++ b/examples/example_glfw_opengl3/Makefile @@ -44,6 +44,10 @@ CXXFLAGS += -I../libs/gl3w -DIMGUI_IMPL_OPENGL_LOADER_GL3W ## Using OpenGL loader: glbinding ## (This assumes a system-wide installation) # CXXFLAGS += -lglbinding -DIMGUI_IMPL_OPENGL_LOADER_GLBINDING +## If autodetection fails for some reason you can select one of +## the supported versions explicitly with: +# CXXFLAGS += -lglbinding -DIMGUI_IMPL_OPENGL_LOADER_GLBINDING_2 +# CXXFLAGS += -lglbinding -DIMGUI_IMPL_OPENGL_LOADER_GLBINDING_3 ##--------------------------------------------------------------------- ## BUILD FLAGS PER PLATFORM diff --git a/examples/example_glfw_opengl3/main.cpp b/examples/example_glfw_opengl3/main.cpp index 55b379deb3e7..8bcd53b9e7cb 100644 --- a/examples/example_glfw_opengl3/main.cpp +++ b/examples/example_glfw_opengl3/main.cpp @@ -17,9 +17,13 @@ #include // Initialize with glewInit() #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) #include // Initialize with gladLoadGL() -#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING) +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING_2) || defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING_3) #define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors. +#if defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING_2) +#include // Initialize with glbinding::Binding::initialize() +#else #include // Initialize with glbinding::initialize() +#endif #include using namespace gl; #else @@ -79,7 +83,10 @@ int main(int, char**) bool err = glewInit() != GLEW_OK; #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) bool err = gladLoadGL() == 0; -#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING) +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING_2) + bool err = false; + glbinding::Binding::initialize(); +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING_3) bool err = false; glbinding::initialize([](const char* name) { return (glbinding::ProcAddress)glfwGetProcAddress(name); }); #else diff --git a/examples/example_sdl_opengl3/Makefile b/examples/example_sdl_opengl3/Makefile index 77140b5ef9a4..5449fb581858 100644 --- a/examples/example_sdl_opengl3/Makefile +++ b/examples/example_sdl_opengl3/Makefile @@ -44,6 +44,10 @@ CXXFLAGS += -I../libs/gl3w -DIMGUI_IMPL_OPENGL_LOADER_GL3W ## Using OpenGL loader: glbinding ## (This assumes a system-wide installation) # CXXFLAGS += -lglbinding -DIMGUI_IMPL_OPENGL_LOADER_GLBINDING +## If autodetection fails for some reason you can select one of +## the supported versions explicitly with: +# CXXFLAGS += -lglbinding -DIMGUI_IMPL_OPENGL_LOADER_GLBINDING_2 +# CXXFLAGS += -lglbinding -DIMGUI_IMPL_OPENGL_LOADER_GLBINDING_3 ##--------------------------------------------------------------------- ## BUILD FLAGS PER PLATFORM diff --git a/examples/example_sdl_opengl3/main.cpp b/examples/example_sdl_opengl3/main.cpp index 20801a194043..f383bda9b06e 100644 --- a/examples/example_sdl_opengl3/main.cpp +++ b/examples/example_sdl_opengl3/main.cpp @@ -19,8 +19,12 @@ #include // Initialize with glewInit() #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) #include // Initialize with gladLoadGL() -#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING) +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING_2) || defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING_3) +#if defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING_2) +#include // Initialize with glbinding::Binding::initialize() +#else #include // Initialize with glbinding::initialize() +#endif #include using namespace gl; #else @@ -73,9 +77,12 @@ int main(int, char**) bool err = glewInit() != GLEW_OK; #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) bool err = gladLoadGL() == 0; -#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING) +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING_2) + bool err = false; + glbinding::Binding::initialize(); +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING_3) bool err = false; - glbinding::initialize([](const char* name) { return (glbinding::ProcAddress)SDL_GL_GetProcAddress(name); }); + glbinding::initialize([](const char* name) { return (glbinding::ProcAddress)glfwGetProcAddress(name); }); #else bool err = false; // If you use IMGUI_IMPL_OPENGL_LOADER_CUSTOM, your loader is likely to requires some form of initialization. #endif diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index 9289913ef104..b8b23a95c663 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -87,6 +87,8 @@ #undef IMGUI_IMPL_OPENGL_LOADER_GLEW #undef IMGUI_IMPL_OPENGL_LOADER_GLAD #undef IMGUI_IMPL_OPENGL_LOADER_GLBINDING +#undef IMGUI_IMPL_OPENGL_LOADER_GLBINDING_2 +#undef IMGUI_IMPL_OPENGL_LOADER_GLBINDING_3 #undef IMGUI_IMPL_OPENGL_LOADER_CUSTOM #elif defined(__EMSCRIPTEN__) #define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100" @@ -94,6 +96,8 @@ #undef IMGUI_IMPL_OPENGL_LOADER_GLEW #undef IMGUI_IMPL_OPENGL_LOADER_GLAD #undef IMGUI_IMPL_OPENGL_LOADER_GLBINDING +#undef IMGUI_IMPL_OPENGL_LOADER_GLBINDING_2 +#undef IMGUI_IMPL_OPENGL_LOADER_GLBINDING_3 #undef IMGUI_IMPL_OPENGL_LOADER_CUSTOM #endif #endif @@ -118,9 +122,13 @@ #include // Needs to be initialized with glewInit() in user's code #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) #include // Needs to be initialized with gladLoadGL() in user's code -#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING) +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING_2) || defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING_3) #include // Initialize with glbinding::initialize() +#if defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING_2) +#include +#else #include +#endif using namespace gl; #else #include IMGUI_IMPL_OPENGL_LOADER_CUSTOM @@ -193,8 +201,10 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version) gl_loader = "GLEW"; #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) gl_loader = "GLAD"; -#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING) - gl_loader = "glbinding"; +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING_2) + gl_loader = "glbinding2"; +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING_3) + gl_loader = "glbinding3"; #else // IMGUI_IMPL_OPENGL_LOADER_CUSTOM gl_loader = "Custom"; #endif diff --git a/examples/imgui_impl_opengl3.h b/examples/imgui_impl_opengl3.h index 98cefe7d8583..ebc36481d330 100644 --- a/examples/imgui_impl_opengl3.h +++ b/examples/imgui_impl_opengl3.h @@ -43,10 +43,26 @@ IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects(); // If auto-detection fails or doesn't select the same GL loader file as used by your application, // you are likely to get a crash in ImGui_ImplOpenGL3_Init(). // You can explicitly select a loader by using '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line. +#if defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING) + #if defined(__has_include) + #if __has_include() + #define IMGUI_IMPL_OPENGL_LOADER_GLBINDING_3 + #undef IMGUI_IMPL_OPENGL_LOADER_GLBINDING + #elif __has_include() + #define IMGUI_IMPL_OPENGL_LOADER_GLBINDING_2 + #undef IMGUI_IMPL_OPENGL_LOADER_GLBINDING + #else + #error "Cannot auto-detect GLBinding version as expected headers are not present!" + #endif + #else + #error "Cannot auto-detect GLBinding version as your compiler does not provide a method of header detection!" + #endif +#endif #if !defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) \ && !defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) \ && !defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) \ - && !defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING) \ + && !defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING_2) \ + && !defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING_3) \ && !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM) #if defined(__has_include) #if __has_include() @@ -55,8 +71,10 @@ IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects(); #define IMGUI_IMPL_OPENGL_LOADER_GLAD #elif __has_include() #define IMGUI_IMPL_OPENGL_LOADER_GL3W - #elif __has_include() - #define IMGUI_IMPL_OPENGL_LOADER_GLBINDING + #elif __has_include() + #define IMGUI_IMPL_OPENGL_LOADER_GLBINDING_3 + #elif __has_include() + #define IMGUI_IMPL_OPENGL_LOADER_GLBINDING_2 #else #error "Cannot detect OpenGL loader!" #endif