From 80595133bef6090ba05eeffd66fa0d8d4b22a68e Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 18 Oct 2025 16:52:31 +0200 Subject: [PATCH] use npow2 screen textures if GL_ARB_texture_non_power_of_two is supported apparently some gl drivers may use a slower path for streamed textures that only get partly updated, this tricks them into thinking this did a "full update" and resulting in using a faster renderpath --- src/hardware/r_opengl/r_opengl.c | 23 +++++++++++++++-------- src/hardware/r_opengl/r_opengl.h | 1 + src/sdl/ogl_sdl.c | 3 +++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 23c2a8da0..3a5fd059a 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -110,6 +110,7 @@ GLint screen_texsizew = 512; // Power-of-two screen texture render resolution GLint screen_texsizeh = 512; // Power-of-two screen texture render resolution GLbyte screen_depth = 0; GLint maximumAnisotropy = 0; +boolean supportNPO2tex = false; static GLboolean MipMap = GL_FALSE; static GLint min_filter = GL_LINEAR; static GLint mag_filter = GL_LINEAR; @@ -1176,12 +1177,20 @@ void GL_SetModelView(GLint w, GLint h) screen_texsizew = screen_texsizeh = 512; - // look for power of two that is large enough for the screen - while (screen_texsizew < w) - screen_texsizew <<= 1; + if (supportNPO2tex) + { + screen_texsizew = screen_width; + screen_texsizeh = screen_height; + } + else + { + // look for power of two that is large enough for the screen + while (screen_texsizew < w) + screen_texsizew <<= 1; - while (screen_texsizeh < h) - screen_texsizeh <<= 1; + while (screen_texsizeh < h) + screen_texsizeh <<= 1; + } pglGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxtexsize); // Get the maximum supported texture size if ((screen_texsizew > maxtexsize || screen_texsizeh > maxtexsize) && maxtexsize > 0) @@ -3692,7 +3701,6 @@ void GL_DrawScreenFinalTexture(int tex, INT32 width, INT32 height, boolean usesh float xfix, yfix; float origaspect, newaspect; float xoff = 1, yoff = 1; // xoffset and yoffset for the polygon to have black bars around the screen - FRGBAFloat clearColour; static float off[12]; static float fix[8]; @@ -3743,8 +3751,7 @@ void GL_DrawScreenFinalTexture(int tex, INT32 width, INT32 height, boolean usesh pglViewport(0, 0, width, height); - clearColour.red = clearColour.green = clearColour.blue = 0; - clearColour.alpha = 1; + FRGBAFloat clearColour = {0, 0, 0, 1}; GL_ClearBuffer(true, false, false, &clearColour); GL_SetBlend(PF_NoDepthTest); diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index 4cf2b2e46..34d4b9da3 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -124,6 +124,7 @@ extern GLint screen_width; extern GLint screen_height; extern GLbyte screen_depth; extern GLint maximumAnisotropy; +extern boolean supportNPO2tex; extern boolean supportMipMap; /** \brief OpenGL flags for video driver diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 4e60801b3..0816ecfec 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -197,6 +197,9 @@ boolean OglSdlSurface(INT32 w, INT32 h) else maximumAnisotropy = 1; + if (GL_isExtAvailable("GL_ARB_texture_non_power_of_two", gl_extensions)) + supportNPO2tex = true; + glanisotropicmode_cons_t[1].value = maximumAnisotropy; #if defined (__unix__)