From 0d48d97471e75cc4914f9449e43d781ae6482775 Mon Sep 17 00:00:00 2001 From: Eugene Date: Mon, 23 Dec 2024 13:54:43 +0200 Subject: [PATCH 1/2] OpenGL: perform alpha tests after vertex color multiplication in VBO shaders, fixes #308 FS: remove trailing newlines from mod descriptions --- code/client/cl_main.c | 2 +- code/qcommon/files.c | 9 +++++++-- code/renderer/tr_vbo.c | 28 +++++++++++++++++----------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/code/client/cl_main.c b/code/client/cl_main.c index 27de3da24..6d1474acb 100644 --- a/code/client/cl_main.c +++ b/code/client/cl_main.c @@ -661,7 +661,7 @@ static void CL_CompleteRecordName(const char *args, int argNum ) { char demoExt[ 16 ]; - Com_sprintf( demoExt, sizeof( demoExt ), ".%s%d", DEMOEXT, com_protocol->integer ); + Com_sprintf( demoExt, sizeof( demoExt ), "." DEMOEXT "%d", com_protocol->integer ); Field_CompleteFilename( "demos", demoExt, qtrue, FS_MATCH_EXTERN | FS_MATCH_STICK ); } } diff --git a/code/qcommon/files.c b/code/qcommon/files.c index 3189d770d..0ee2e5f6e 100644 --- a/code/qcommon/files.c +++ b/code/qcommon/files.c @@ -3636,6 +3636,11 @@ static void FS_GetModDescription( const char *modDir, char *description, int des nDescLen = FS_Read( description, nDescLen, descHandle ); if ( nDescLen >= 0 ) { description[ nDescLen ] = '\0'; + while ( nDescLen > 0 && description[ nDescLen - 1 ] == '\n' ) { + // strip ending newlines + description[ nDescLen - 1 ] = '\0'; + nDescLen--; + } } } else { Q_strncpyz( description, modDir, descriptionLen ); @@ -3884,9 +3889,9 @@ static int FS_PathCmp( const char *s1, const char *s2 ) { FS_SortFileList ================ */ -static void FS_SortFileList( char **list, int n ) { +static void FS_SortFileList( const char **list, int n ) { const char *m; - char *temp; + const char *temp; int i, j; i = 0; j = n; diff --git a/code/renderer/tr_vbo.c b/code/renderer/tr_vbo.c index 4a55cdf2c..16546229f 100644 --- a/code/renderer/tr_vbo.c +++ b/code/renderer/tr_vbo.c @@ -240,29 +240,26 @@ const char *BuildFP( int multitexture, int alphatest, int fogMode ) return buf; } + if ( alphatest || multitexture == GL_ADD || multitexture == GL_MODULATE ) { + strcat( buf, "TEMP t; \n" ); + } + switch ( multitexture ) { case 0: - strcat( buf, "TEMP t; \n" ); strcat( buf, "TEX base, fragment.texcoord[0], texture[0], 2D; \n" ); - strcat( buf, genATestFP( alphatest ) ); break; case GL_ADD: - strcat( buf, "TEMP t; \n" ); strcat( buf, "TEX base, fragment.texcoord[0], texture[0], 2D; \n" ); - strcat( buf, genATestFP( alphatest ) ); strcat( buf, "TEX t, fragment.texcoord[1], texture[1], 2D; \n" "ADD base, base, t; \n" ); break; case GL_MODULATE: - strcat( buf, "TEMP t; \n" ); strcat( buf, "TEX base, fragment.texcoord[0], texture[0], 2D; \n" ); - strcat( buf, genATestFP( alphatest ) ); strcat( buf, "TEX t, fragment.texcoord[1], texture[1], 2D; \n" ); strcat( buf, "MUL base, base, t; \n" ); break; case GL_REPLACE: strcat( buf, "TEX base, fragment.texcoord[1], texture[1], 2D; \n" ); - //strcat( buf, genATestFP( alphatest ) ); break; default: ri.Error( ERR_DROP, "Invalid multitexture mode %04x", multitexture ); @@ -271,15 +268,24 @@ const char *BuildFP( int multitexture, int alphatest, int fogMode ) if ( fogMode == FP_FOG_BLEND ) { strcat( buf, "MUL base, base, fragment.color; \n" ); + strcat( buf, genATestFP( alphatest ) ); strcat( buf, "TEMP fog; \n" "TEX fog, fragment.texcoord[4], texture[2], 2D; \n" "MUL fog, fog, program.local[0]; \n" "LRP_SAT result.color, fog.a, fog, base; \n" "END \n" ); } else { - strcat( buf, - "MUL result.color, base, fragment.color; \n" - "END \n" ); + if ( alphatest ) { + strcat( buf, "MUL base, base, fragment.color; \n" ); + strcat( buf, genATestFP( alphatest ) ); + strcat( buf, + "MOV result.color, base; \n" + "END \n" ); + } else { + strcat( buf, + "MUL result.color, base, fragment.color; \n" + "END \n" ); + } } return buf; @@ -333,7 +339,7 @@ static int getFPindex( int multitexture, int atest, int fogmode ) index <<= 2; // reserve bits for atest switch ( atest ) { - case GLS_ATEST_GT_0: index |= 1; break; + case GLS_ATEST_GT_0: index |= 1; break; case GLS_ATEST_LT_80: index |= 2; break; case GLS_ATEST_GE_80: index |= 3; break; default: break; From d523bb4dab21085a2fe00bbc67fc80bd5b8d3e99 Mon Sep 17 00:00:00 2001 From: Eugene Date: Mon, 23 Dec 2024 15:07:16 +0200 Subject: [PATCH 2/2] fix gcc compiler warnings --- code/qcommon/files.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/qcommon/files.c b/code/qcommon/files.c index 0ee2e5f6e..eea858b10 100644 --- a/code/qcommon/files.c +++ b/code/qcommon/files.c @@ -3889,9 +3889,9 @@ static int FS_PathCmp( const char *s1, const char *s2 ) { FS_SortFileList ================ */ -static void FS_SortFileList( const char **list, int n ) { +static void FS_SortFileList( char **list, int n ) { const char *m; - const char *temp; + char *temp; int i, j; i = 0; j = n;