Skip to content

Commit

Permalink
spearmint: Initialize all state in InitShader()
Browse files Browse the repository at this point in the history
Set all variables for shader parsing/loading in InitShader(). Otherwise
it may affect dynamic fonts (RE_RegisterShaderFromImage()) and OpenGL2
built-in sun flare shader.

(I don't know of issues this specifically caused.)
  • Loading branch information
zturtleman committed Feb 21, 2024
1 parent c602f5a commit 2417ecb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 44 deletions.
50 changes: 22 additions & 28 deletions code/renderergl1/tr_shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -3672,6 +3672,28 @@ static void InitShader( const char *name, int lightmapIndex ) {
Q_strncpyz( shader.name, name, sizeof( shader.name ) );
shader.lightmapIndex = lightmapIndex;

shader_picmipFlag = IMGFLAG_PICMIP;
shader_novlcollapse = qfalse;

if ( r_ext_compressed_textures->integer == 2 ) {
// if the shader hasn't specifically asked for it, don't allow compression
shader_allowCompress = qfalse;
} else {
shader_allowCompress = qtrue;
}

// FIXME: set these "need" values appropriately
shader.needsNormal = qtrue;
shader.needsST1 = qtrue;
shader.needsST2 = qtrue;
shader.needsColor = qtrue;

// default to no implicit mappings
implicitMap[ 0 ] = '\0';
implicitStateBits = GLS_DEFAULT;
implicitCullType = CT_FRONT_SIDED;
aliasShader[ 0 ] = '\0';

for ( i = 0 ; i < MAX_SHADER_STAGES ; i++ ) {
for ( b = 0; b < NUM_TEXTURE_BUNDLES; b++ ) {
stages[i].bundle[b].texMods = texMods[i][b];
Expand Down Expand Up @@ -4116,28 +4138,6 @@ shader_t *R_FindShader( const char *name, int lightmapIndex, imgFlags_t rawImage

InitShader( strippedName, lightmapIndex );

shader_picmipFlag = IMGFLAG_PICMIP;
shader_novlcollapse = qfalse;

if ( r_ext_compressed_textures->integer == 2 ) {
// if the shader hasn't specifically asked for it, don't allow compression
shader_allowCompress = qfalse;
} else {
shader_allowCompress = qtrue;
}

// FIXME: set these "need" values appropriately
shader.needsNormal = qtrue;
shader.needsST1 = qtrue;
shader.needsST2 = qtrue;
shader.needsColor = qtrue;

// default to no implicit mappings
implicitMap[ 0 ] = '\0';
implicitStateBits = GLS_DEFAULT;
implicitCullType = CT_FRONT_SIDED;
aliasShader[ 0 ] = '\0';

//
// attempt to define shader from an explicit parameter file
//
Expand Down Expand Up @@ -4249,12 +4249,6 @@ qhandle_t RE_RegisterShaderFromImage(const char *name, int lightmapIndex, image_

InitShader( name, lightmapIndex );

// FIXME: set these "need" values appropriately
shader.needsNormal = qtrue;
shader.needsST1 = qtrue;
shader.needsST2 = qtrue;
shader.needsColor = qtrue;

// set default stages
SetImplicitShaderStages( image );

Expand Down
32 changes: 16 additions & 16 deletions code/renderergl2/tr_shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -4727,6 +4727,22 @@ static void InitShaderEx( const char *name, int lightmapIndex, int realLightmapI
shader.lightmapIndex = lightmapIndex;
shader_realLightmapIndex = realLightmapIndex;

shader_picmipFlag = IMGFLAG_PICMIP;
shader_novlcollapse = qfalse;

if ( r_ext_compressed_textures->integer == 2 ) {
// if the shader hasn't specifically asked for it, don't allow compression
shader_allowCompress = qfalse;
} else {
shader_allowCompress = qtrue;
}

// default to no implicit mappings
implicitMap[ 0 ] = '\0';
implicitStateBits = GLS_DEFAULT;
implicitCullType = CT_FRONT_SIDED;
aliasShader[ 0 ] = '\0';

for ( i = 0 ; i < MAX_SHADER_STAGES ; i++ ) {
for ( b = 0; b < NUM_TEXTURE_BUNDLES; b++ ) {
stages[i].bundle[b].texMods = texMods[i][b];
Expand Down Expand Up @@ -5199,22 +5215,6 @@ shader_t *R_FindShaderEx( const char *name, int lightmapIndex, imgFlags_t rawIma

InitShaderEx( strippedName, lightmapIndex, realLightmapIndex );

shader_picmipFlag = IMGFLAG_PICMIP;
shader_novlcollapse = qfalse;

if ( r_ext_compressed_textures->integer == 2 ) {
// if the shader hasn't specifically asked for it, don't allow compression
shader_allowCompress = qfalse;
} else {
shader_allowCompress = qtrue;
}

// default to no implicit mappings
implicitMap[ 0 ] = '\0';
implicitStateBits = GLS_DEFAULT;
implicitCullType = CT_FRONT_SIDED;
aliasShader[ 0 ] = '\0';

//
// attempt to define shader from an explicit parameter file
//
Expand Down

0 comments on commit 2417ecb

Please sign in to comment.