From 03b17f565a3636bb8a9f65c5c25df3830b251198 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 2 Jun 2025 19:29:28 +1000 Subject: [PATCH] OpenGL: Always restore all state --- src/Graphics_GL1.c | 20 ++++++++++++++++++-- src/Graphics_GL2.c | 14 ++++++++++++++ src/_GLShared.h | 10 ++-------- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/Graphics_GL1.c b/src/Graphics_GL1.c index 17ba0c496..8b29cfe86 100644 --- a/src/Graphics_GL1.c +++ b/src/Graphics_GL1.c @@ -378,8 +378,8 @@ void Gfx_BindTexture(GfxResourceID texId) { *-----------------------------------------------------State management----------------------------------------------------* *#########################################################################################################################*/ static PackedCol gfx_fogColor; -static float gfx_fogEnd = -1.0f, gfx_fogDensity = -1.0f; -static int gfx_fogMode = -1; +static float gfx_fogEnd, gfx_fogDensity; +static int gfx_fogMode; void Gfx_SetFog(cc_bool enabled) { gfx_fogEnabled = enabled; @@ -477,7 +477,15 @@ static void Gfx_RestoreState(void) { InitDefaultResources(); _glEnableClientState(GL_VERTEX_ARRAY); _glEnableClientState(GL_COLOR_ARRAY); + gfx_format = -1; + lastMatrix = -1; + + gfx_clearColor = 0; + gfx_fogColor = 0; + gfx_fogEnd = -1.0f; + gfx_fogDensity = -1.0f; + gfx_fogMode = -1; _glHint(GL_FOG_HINT, GL_NICEST); #if defined CC_BUILD_SYMBIAN @@ -518,8 +526,16 @@ cc_bool Gfx_WarnIfNecessary(void) { } return false; } + cc_bool Gfx_GetUIOptions(struct MenuOptionsScreen* s) { return false; } +void Gfx_GetApiInfo(cc_string* info) { + int pointerSize = sizeof(void*) * 8; + + String_Format1(info, "-- Using OpenGL (%i bit) --\n", &pointerSize); + GetGLApiInfo(info); +} + /*########################################################################################################################* *-------------------------------------------------------Compatibility-----------------------------------------------------* diff --git a/src/Graphics_GL2.c b/src/Graphics_GL2.c index e0ad13053..4eefa9174 100644 --- a/src/Graphics_GL2.c +++ b/src/Graphics_GL2.c @@ -600,8 +600,15 @@ static void Gfx_RestoreState(void) { InitDefaultResources(); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); + gfx_format = -1; + gfx_clearColor = 0; + gfx_fogColor = 0; + gfx_fogEnd = -1.0f; + gfx_fogDensity = -1.0f; + gfx_fogMode = -1; + DirtyUniform(UNI_MASK_ALL); GL_ClearColor(gfx_clearColor); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -639,6 +646,13 @@ cc_bool Gfx_GetUIOptions(struct MenuOptionsScreen* s) { return false; } +void Gfx_GetApiInfo(cc_string* info) { + int pointerSize = sizeof(void*) * 8; + + String_Format1(info, "-- Using OpenGL Modern (%i bit) --\n", &pointerSize); + GetGLApiInfo(info); +} + /*########################################################################################################################* *----------------------------------------------------------Drawing--------------------------------------------------------* diff --git a/src/_GLShared.h b/src/_GLShared.h index 3003017e4..721ced8f1 100644 --- a/src/_GLShared.h +++ b/src/_GLShared.h @@ -352,16 +352,10 @@ static void AppendVRAMStats(cc_string* info) { String_Format2(info, "Video memory: %f2 MB total, %f2 free\n", &total, &cur); } -void Gfx_GetApiInfo(cc_string* info) { +static void GetGLApiInfo(cc_string* info) { GLint depthBits = 0; - int pointerSize = sizeof(void*) * 8; - _glGetIntegerv(GL_DEPTH_BITS, &depthBits); -#if CC_GFX_BACKEND == CC_GFX_BACKEND_GL2 - String_Format1(info, "-- Using OpenGL Modern (%i bit) --\n", &pointerSize); -#else - String_Format1(info, "-- Using OpenGL (%i bit) --\n", &pointerSize); -#endif + String_Format1(info, "Vendor: %c\n", _glGetString(GL_VENDOR)); String_Format1(info, "Renderer: %c\n", _glGetString(GL_RENDERER)); String_Format1(info, "GL version: %c\n", _glGetString(GL_VERSION));