From d60c11b3152b05358687ca36c50c537ccaa2bb2f Mon Sep 17 00:00:00 2001 From: ewasylishen Date: Mon, 15 Jun 2015 21:17:39 +0000 Subject: [PATCH] GLSLGamma_GammaCorrect: support this code path on old cards without the NPOT extension git-svn-id: svn+ssh://svn.code.sf.net/p/quakespasm/code/trunk@1231 af15c1b1-3010-417e-b628-4374ebc0bcbd --- quakespasm/Quake/gl_rmain.c | 23 +++++++++++++++++++---- quakespasm/Quake/gl_vidsdl.c | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/quakespasm/Quake/gl_rmain.c b/quakespasm/Quake/gl_rmain.c index 38541eaf..56b970e5 100644 --- a/quakespasm/Quake/gl_rmain.c +++ b/quakespasm/Quake/gl_rmain.c @@ -113,6 +113,7 @@ qboolean r_drawflat_cheatsafe, r_fullbright_cheatsafe, r_lightmap_cheatsafe, r_d static GLuint r_gamma_texture; static GLuint r_gamma_program; +static int r_gamma_texture_width, r_gamma_texture_height; // uniforms used in gamma shader static GLuint gammaLoc; @@ -173,6 +174,8 @@ GLSLGamma_GammaCorrect */ void GLSLGamma_GammaCorrect (void) { + float smax, tmax; + if (!gl_glsl_gamma_able) return; @@ -184,8 +187,17 @@ void GLSLGamma_GammaCorrect (void) { glGenTextures (1, &r_gamma_texture); glBindTexture (GL_TEXTURE_2D, r_gamma_texture); + + r_gamma_texture_width = glwidth; + r_gamma_texture_height = glheight; + + if (!gl_texture_NPOT) + { + r_gamma_texture_width = TexMgr_Pad(r_gamma_texture_width); + r_gamma_texture_height = TexMgr_Pad(r_gamma_texture_height); + } - glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, glwidth, glheight, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); + glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, r_gamma_texture_width, r_gamma_texture_height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } @@ -215,14 +227,17 @@ void GLSLGamma_GammaCorrect (void) glViewport (glx, gly, glwidth, glheight); + smax = glwidth/(float)r_gamma_texture_width; + tmax = glheight/(float)r_gamma_texture_height; + glBegin (GL_QUADS); glTexCoord2f (0, 0); glVertex2f (-1, -1); - glTexCoord2f (1, 0); + glTexCoord2f (smax, 0); glVertex2f (1, -1); - glTexCoord2f (1, 1); + glTexCoord2f (smax, tmax); glVertex2f (1, 1); - glTexCoord2f (0, 1); + glTexCoord2f (0, tmax); glVertex2f (-1, 1); glEnd (); diff --git a/quakespasm/Quake/gl_vidsdl.c b/quakespasm/Quake/gl_vidsdl.c index 32f5a216..abab3522 100644 --- a/quakespasm/Quake/gl_vidsdl.c +++ b/quakespasm/Quake/gl_vidsdl.c @@ -1160,7 +1160,7 @@ static void GL_CheckExtensions (void) // if (COM_CheckParm("-noglslgamma")) Con_Warning ("GLSL gamma disabled at command line\n"); - else if (gl_glsl_able && gl_texture_NPOT) + else if (gl_glsl_able) { gl_glsl_gamma_able = true; }