Add function for clearing global shader instead of duplicating the code

This commit is contained in:
Zack Middleton 2014-09-27 01:17:30 -05:00
parent f83334d81b
commit a955d975b7
2 changed files with 58 additions and 68 deletions

View file

@ -2145,6 +2145,26 @@ static void VertexLightingCollapse( void ) {
} }
} }
/*
===============
InitShader
===============
*/
static void InitShader( const char *name, int lightmapIndex ) {
int i;
// clear the global shader
Com_Memset( &shader, 0, sizeof( shader ) );
Com_Memset( &stages, 0, sizeof( stages ) );
Q_strncpyz( shader.name, name, sizeof( shader.name ) );
shader.lightmapIndex = lightmapIndex;
for ( i = 0 ; i < MAX_SHADER_STAGES ; i++ ) {
stages[i].bundle[0].texMods = texMods[i];
}
}
/* /*
========================= =========================
FinishShader FinishShader
@ -2464,7 +2484,7 @@ most world construction surfaces.
*/ */
shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImage ) { shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImage ) {
char strippedName[MAX_QPATH]; char strippedName[MAX_QPATH];
int i, hash; int hash;
char *shaderText; char *shaderText;
image_t *image; image_t *image;
shader_t *sh; shader_t *sh;
@ -2502,14 +2522,7 @@ shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImag
} }
} }
// clear the global shader InitShader( strippedName, lightmapIndex );
Com_Memset( &shader, 0, sizeof( shader ) );
Com_Memset( &stages, 0, sizeof( stages ) );
Q_strncpyz(shader.name, strippedName, sizeof(shader.name));
shader.lightmapIndex = lightmapIndex;
for ( i = 0 ; i < MAX_SHADER_STAGES ; i++ ) {
stages[i].bundle[0].texMods = texMods[i];
}
// FIXME: set these "need" values apropriately // FIXME: set these "need" values apropriately
shader.needsNormal = qtrue; shader.needsNormal = qtrue;
@ -2619,7 +2632,7 @@ shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImag
qhandle_t RE_RegisterShaderFromImage(const char *name, int lightmapIndex, image_t *image, qboolean mipRawImage) { qhandle_t RE_RegisterShaderFromImage(const char *name, int lightmapIndex, image_t *image, qboolean mipRawImage) {
int i, hash; int hash;
shader_t *sh; shader_t *sh;
hash = generateHashValue(name, FILE_HASH_SIZE); hash = generateHashValue(name, FILE_HASH_SIZE);
@ -2647,14 +2660,7 @@ qhandle_t RE_RegisterShaderFromImage(const char *name, int lightmapIndex, image_
} }
} }
// clear the global shader InitShader( name, lightmapIndex );
Com_Memset( &shader, 0, sizeof( shader ) );
Com_Memset( &stages, 0, sizeof( stages ) );
Q_strncpyz(shader.name, name, sizeof(shader.name));
shader.lightmapIndex = lightmapIndex;
for ( i = 0 ; i < MAX_SHADER_STAGES ; i++ ) {
stages[i].bundle[0].texMods = texMods[i];
}
// FIXME: set these "need" values apropriately // FIXME: set these "need" values apropriately
shader.needsNormal = qtrue; shader.needsNormal = qtrue;
@ -3072,12 +3078,7 @@ static void CreateInternalShaders( void ) {
tr.numShaders = 0; tr.numShaders = 0;
// init the default shader // init the default shader
Com_Memset( &shader, 0, sizeof( shader ) ); InitShader( "<default>", LIGHTMAP_NONE );
Com_Memset( &stages, 0, sizeof( stages ) );
Q_strncpyz( shader.name, "<default>", sizeof( shader.name ) );
shader.lightmapIndex = LIGHTMAP_NONE;
stages[0].bundle[0].image[0] = tr.defaultImage; stages[0].bundle[0].image[0] = tr.defaultImage;
stages[0].active = qtrue; stages[0].active = qtrue;
stages[0].stateBits = GLS_DEFAULT; stages[0].stateBits = GLS_DEFAULT;

View file

@ -2920,6 +2920,33 @@ static void VertexLightingCollapse( void ) {
} }
} }
/*
===============
InitShader
===============
*/
static void InitShader( const char *name, int lightmapIndex ) {
int i;
// clear the global shader
Com_Memset( &shader, 0, sizeof( shader ) );
Com_Memset( &stages, 0, sizeof( stages ) );
Q_strncpyz( shader.name, name, sizeof( shader.name ) );
shader.lightmapIndex = lightmapIndex;
for ( i = 0 ; i < MAX_SHADER_STAGES ; i++ ) {
stages[i].bundle[0].texMods = texMods[i];
// default normal/specular
VectorSet4(stages[i].normalScale, 0.0f, 0.0f, 0.0f, 0.0f);
stages[i].specularScale[0] =
stages[i].specularScale[1] =
stages[i].specularScale[2] = r_baseSpecular->value;
stages[i].specularScale[3] = r_baseGloss->value;
}
}
/* /*
========================= =========================
FinishShader FinishShader
@ -3240,7 +3267,7 @@ most world construction surfaces.
*/ */
shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImage ) { shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImage ) {
char strippedName[MAX_QPATH]; char strippedName[MAX_QPATH];
int i, hash; int hash;
char *shaderText; char *shaderText;
image_t *image; image_t *image;
shader_t *sh; shader_t *sh;
@ -3278,21 +3305,7 @@ shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImag
} }
} }
// clear the global shader InitShader( strippedName, lightmapIndex );
Com_Memset( &shader, 0, sizeof( shader ) );
Com_Memset( &stages, 0, sizeof( stages ) );
Q_strncpyz(shader.name, strippedName, sizeof(shader.name));
shader.lightmapIndex = lightmapIndex;
for ( i = 0 ; i < MAX_SHADER_STAGES ; i++ ) {
stages[i].bundle[0].texMods = texMods[i];
// default normal/specular
VectorSet4(stages[i].normalScale, 0.0f, 0.0f, 0.0f, 0.0f);
stages[i].specularScale[0] =
stages[i].specularScale[1] =
stages[i].specularScale[2] = r_baseSpecular->value;
stages[i].specularScale[3] = r_baseGloss->value;
}
// //
// attempt to define shader from an explicit parameter file // attempt to define shader from an explicit parameter file
@ -3399,7 +3412,7 @@ shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImag
qhandle_t RE_RegisterShaderFromImage(const char *name, int lightmapIndex, image_t *image, qboolean mipRawImage) { qhandle_t RE_RegisterShaderFromImage(const char *name, int lightmapIndex, image_t *image, qboolean mipRawImage) {
int i, hash; int hash;
shader_t *sh; shader_t *sh;
hash = generateHashValue(name, FILE_HASH_SIZE); hash = generateHashValue(name, FILE_HASH_SIZE);
@ -3427,21 +3440,7 @@ qhandle_t RE_RegisterShaderFromImage(const char *name, int lightmapIndex, image_
} }
} }
// clear the global shader InitShader( name, lightmapIndex );
Com_Memset( &shader, 0, sizeof( shader ) );
Com_Memset( &stages, 0, sizeof( stages ) );
Q_strncpyz(shader.name, name, sizeof(shader.name));
shader.lightmapIndex = lightmapIndex;
for ( i = 0 ; i < MAX_SHADER_STAGES ; i++ ) {
stages[i].bundle[0].texMods = texMods[i];
// default normal/specular
VectorSet4(stages[i].normalScale, 0.0f, 0.0f, 0.0f, 0.0f);
stages[i].specularScale[0] =
stages[i].specularScale[1] =
stages[i].specularScale[2] = r_baseSpecular->value;
stages[i].specularScale[3] = r_baseGloss->value;
}
// //
// create the default shading commands // create the default shading commands
@ -3863,12 +3862,7 @@ static void CreateInternalShaders( void ) {
tr.numShaders = 0; tr.numShaders = 0;
// init the default shader // init the default shader
Com_Memset( &shader, 0, sizeof( shader ) ); InitShader( "<default>", LIGHTMAP_NONE );
Com_Memset( &stages, 0, sizeof( stages ) );
Q_strncpyz( shader.name, "<default>", sizeof( shader.name ) );
shader.lightmapIndex = LIGHTMAP_NONE;
stages[0].bundle[0].image[0] = tr.defaultImage; stages[0].bundle[0].image[0] = tr.defaultImage;
stages[0].active = qtrue; stages[0].active = qtrue;
stages[0].stateBits = GLS_DEFAULT; stages[0].stateBits = GLS_DEFAULT;
@ -3911,12 +3905,7 @@ static void CreateExternalShaders( void ) {
else else
image = tr.dlightImage; image = tr.dlightImage;
Com_Memset( &shader, 0, sizeof( shader ) ); InitShader( "gfx/2d/sunflare", LIGHTMAP_NONE );
Com_Memset( &stages, 0, sizeof( stages ) );
Q_strncpyz( shader.name, "gfx/2d/sunflare", sizeof( shader.name ) );
shader.lightmapIndex = LIGHTMAP_NONE;
stages[0].bundle[0].image[0] = image; stages[0].bundle[0].image[0] = image;
stages[0].active = qtrue; stages[0].active = qtrue;
stages[0].stateBits = GLS_DEFAULT; stages[0].stateBits = GLS_DEFAULT;