From a338b78eb9b8a73dc049f8e54de1252e3a392f84 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 18 Apr 2023 12:01:40 +0200 Subject: [PATCH] Backends: OpenGL3: amend reset GL_POLYGON_MODE separately for front and back when possible. (#6333) --- backends/imgui_impl_opengl3.cpp | 23 ++++++++++++----------- backends/imgui_impl_opengl3_loader.h | 6 +++++- docs/CHANGELOG.txt | 2 ++ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/backends/imgui_impl_opengl3.cpp b/backends/imgui_impl_opengl3.cpp index b4b4fc0a..b97992d5 100644 --- a/backends/imgui_impl_opengl3.cpp +++ b/backends/imgui_impl_opengl3.cpp @@ -14,6 +14,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2023-04-18: OpenGL: Restore front and back polygon mode separately when supported by context. (#6333) // 2023-03-23: OpenGL: Properly restoring "no shader program bound" if it was the case prior to running the rendering function. (#6267, #6220, #6224) // 2023-03-15: OpenGL: Fixed GL loader crash when GL_VERSION returns NULL. (#6154, #4445, #3530) // 2023-03-06: OpenGL: Fixed restoration of a potentially deleted OpenGL program, by calling glIsProgram(). (#6220, #6224) @@ -204,6 +205,8 @@ struct ImGui_ImplOpenGL3_Data { GLuint GlVersion; // Extracted at runtime using GL_MAJOR_VERSION, GL_MINOR_VERSION queries (e.g. 320 for GL 3.2) char GlslVersionString[32]; // Specified by user or detected based on compile time GL settings. + bool GlProfileIsCompat; + GLint GlProfileMask; GLuint FontTexture; GLuint ShaderHandle; GLint AttribLocationTex; // Uniforms location @@ -284,6 +287,10 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version) sscanf(gl_version, "%d.%d", &major, &minor); } bd->GlVersion = (GLuint)(major * 100 + minor * 10); +#if defined(GL_CONTEXT_PROFILE_MASK) + glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &bd->GlProfileMask); + bd->GlProfileIsCompat = (bd->GlProfileMask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) != 0; +#endif bd->UseBufferSubData = false; /* @@ -613,22 +620,16 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data) #endif #ifdef IMGUI_IMPL_HAS_POLYGON_MODE -// Desktop OpenGL 3.0 and OpenGL 3.1 had separate polygon draw modes for front-facing and back-facing faces of polygons -#if defined(GL_FRONT) && defined(GL_BACK) // possibly Desktop OpenGL 3.0, 3.1 or 3.2+ compatibility profile -#ifdef GL_CONTEXT_PROFILE_MASK // Desktop OpenGL 3.2+ - GLint profile_mask; - glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &profile_mask); - if (profile_mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) -#else - if (bd->GlVersion <= 310) -#endif + // Desktop OpenGL 3.0 and OpenGL 3.1 had separate polygon draw modes for front-facing and back-facing faces of polygons + if (bd->GlVersion <= 310 || bd->GlProfileIsCompat) { glPolygonMode(GL_FRONT, (GLenum)last_polygon_mode[0]); glPolygonMode(GL_BACK, (GLenum)last_polygon_mode[1]); } else -#endif // GL_FRONT & GL_BACK - glPolygonMode(GL_FRONT_AND_BACK, (GLenum)last_polygon_mode[0]); + { + glPolygonMode(GL_FRONT_AND_BACK, (GLenum)last_polygon_mode[0]); + } #endif // IMGUI_IMPL_HAS_POLYGON_MODE glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]); diff --git a/backends/imgui_impl_opengl3_loader.h b/backends/imgui_impl_opengl3_loader.h index af8d20c4..7ca72e37 100644 --- a/backends/imgui_impl_opengl3_loader.h +++ b/backends/imgui_impl_opengl3_loader.h @@ -118,7 +118,7 @@ extern "C" { ** included as . ** ** glcorearb.h includes only APIs in the latest OpenGL core profile -** implementation together with APIs in newer ARB extensions which +** implementation together with APIs in newer ARB extensions which ** can be supported by the core profile. It does not, and never will ** include functionality removed from the core profile, such as ** fixed-function vertex and fragment processing. @@ -154,6 +154,8 @@ typedef khronos_uint8_t GLubyte; #define GL_ONE 1 #define GL_SRC_ALPHA 0x0302 #define GL_ONE_MINUS_SRC_ALPHA 0x0303 +#define GL_FRONT 0x0404 +#define GL_BACK 0x0405 #define GL_FRONT_AND_BACK 0x0408 #define GL_POLYGON_MODE 0x0B40 #define GL_CULL_FACE 0x0B44 @@ -373,6 +375,8 @@ GLAPI void APIENTRY glGenVertexArrays (GLsizei n, GLuint *arrays); typedef struct __GLsync *GLsync; typedef khronos_uint64_t GLuint64; typedef khronos_int64_t GLint64; +#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002 +#define GL_CONTEXT_PROFILE_MASK 0x9126 typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex); typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data); #ifdef GL_GLEXT_PROTOTYPES diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 911be774..d8d85e67 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -48,6 +48,8 @@ Other changes: (#6341) [@lukaasm] - Backends: Clear bits sets io.BackendFlags on backend Shutdown(). (#6334, #6335] [@GereonV] Potentially this would facilitate switching runtime backend mid-session. +- Backends: OpenGL3: Restore front and back polygon mode separately when supported + by context (Desktop 3.0, 3.1, or 3.2+ with compat bit). (#6333) [@GereonV]