From e30685baf233aa39ff6a70a3889b6ac2a460af81 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 6 May 2026 12:27:06 +0200 Subject: [PATCH] OpenGL: only enable stencil testing during level render MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit not 100% sure if this is the most correct thing, but this causes issues with Nvidia Gpu´s under x11 should fix https://github.com/Indev450/SRB2Kart-Saturn/issues/226 --- src/hardware/hw_gl.h | 4 ++++ src/hardware/hw_main.cpp | 4 ++++ src/hardware/r_opengl/r_opengl.c | 12 +++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/hardware/hw_gl.h b/src/hardware/hw_gl.h index 351b36353..b808ed09a 100644 --- a/src/hardware/hw_gl.h +++ b/src/hardware/hw_gl.h @@ -32,8 +32,12 @@ void GL_SetSpecialState(hwdspecialstate_t IdState, INT32 Value); void GL_SetTransform(FTransform *stransform); void GL_SetBlend(FBITFIELD PolyFlags); void GL_SetPalette(RGBA_t *palette); + void GL_ClearBuffer(FBOOLEAN ColorMask, FBOOLEAN DepthMask, FBOOLEAN StencilMask, FRGBAFloat * ClearColor); +void GL_EnableStencilTest(void); +void GL_DisableStencilTest(void); + void GL_DrawPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags); void GL_DrawIndexedTriangles(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, unsigned int *IndexArray); void GL_Draw2DLine(F2DCoord *v1, F2DCoord *v2, RGBA_t Color); diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 57f64e9c0..b0623cb29 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -5537,6 +5537,8 @@ extern "C" { // ========================================================================== static void HWR_RenderFrame(boolean skybox, boolean drawsky) { + GL_EnableStencilTest(); + // Clear view, set viewport (glViewport), set perspective... HWR_ClearView(); @@ -5567,6 +5569,8 @@ static void HWR_RenderFrame(boolean skybox, boolean drawsky) else HWR_RenderViewpoint(NULL, 0, !skybox); + GL_DisableStencilTest(); + // Check for new console commands. NetUpdate(); } diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 18bf2973d..bae5a9f78 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1287,7 +1287,7 @@ void GL_SetStates(void) pglColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - pglEnable(GL_STENCIL_TEST); + pglDisable(GL_STENCIL_TEST); pglEnable(GL_DEPTH_TEST); // check the depth buffer pglDepthMask(GL_TRUE); // enable writing to depth buffer pglClearDepth(1.0f); @@ -1317,6 +1317,16 @@ void GL_SetStates(void) #endif } +void GL_EnableStencilTest(void) +{ + pglEnable(GL_STENCIL_TEST); +} + +void GL_DisableStencilTest(void) +{ + pglDisable(GL_STENCIL_TEST); +} + // -----------------+ // DeleteTexture : Deletes a texture from the GPU and frees its data // -----------------+