summaryrefslogtreecommitdiff
path: root/src/renderergl2/tr_shader.c
diff options
context:
space:
mode:
authorZack Middleton <zturtleman@gmail.com>2014-09-27 01:17:30 -0500
committerTim Angus <tim@ngus.net>2015-03-17 11:38:38 +0000
commitc1d82cb348c1a34224be58649760422ba7f43dd0 (patch)
tree420c31262fc0a6110e167ce21dc47995492ba0f1 /src/renderergl2/tr_shader.c
parentadbdf8a749495e020aa5aebc0e85cc61e010cc78 (diff)
Add function for clearing global shader instead of duplicating the code
Diffstat (limited to 'src/renderergl2/tr_shader.c')
-rw-r--r--src/renderergl2/tr_shader.c77
1 files changed, 33 insertions, 44 deletions
diff --git a/src/renderergl2/tr_shader.c b/src/renderergl2/tr_shader.c
index 6b7cdc7f..867f0a47 100644
--- a/src/renderergl2/tr_shader.c
+++ b/src/renderergl2/tr_shader.c
@@ -2922,6 +2922,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
@@ -3241,7 +3268,7 @@ most world construction surfaces.
*/
shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImage ) {
char strippedName[MAX_QPATH];
- int i, hash;
+ int hash;
char *shaderText;
image_t *image;
shader_t *sh;
@@ -3279,21 +3306,7 @@ shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImag
}
}
- // clear the global shader
- 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;
- }
+ InitShader( strippedName, lightmapIndex );
//
// attempt to define shader from an explicit parameter file
@@ -3400,7 +3413,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) {
- int i, hash;
+ int hash;
shader_t *sh;
hash = generateHashValue(name, FILE_HASH_SIZE);
@@ -3428,21 +3441,7 @@ qhandle_t RE_RegisterShaderFromImage(const char *name, int lightmapIndex, image_
}
}
- // 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;
- }
+ InitShader( name, lightmapIndex );
//
// create the default shading commands
@@ -3864,12 +3863,7 @@ static void CreateInternalShaders( void ) {
tr.numShaders = 0;
// init the default shader
- Com_Memset( &shader, 0, sizeof( shader ) );
- Com_Memset( &stages, 0, sizeof( stages ) );
-
- Q_strncpyz( shader.name, "<default>", sizeof( shader.name ) );
-
- shader.lightmapIndex = LIGHTMAP_NONE;
+ InitShader( "<default>", LIGHTMAP_NONE );
stages[0].bundle[0].image[0] = tr.defaultImage;
stages[0].active = qtrue;
stages[0].stateBits = GLS_DEFAULT;
@@ -3912,12 +3906,7 @@ static void CreateExternalShaders( void ) {
else
image = tr.dlightImage;
- Com_Memset( &shader, 0, sizeof( shader ) );
- Com_Memset( &stages, 0, sizeof( stages ) );
-
- Q_strncpyz( shader.name, "gfx/2d/sunflare", sizeof( shader.name ) );
-
- shader.lightmapIndex = LIGHTMAP_NONE;
+ InitShader( "gfx/2d/sunflare", LIGHTMAP_NONE );
stages[0].bundle[0].image[0] = image;
stages[0].active = qtrue;
stages[0].stateBits = GLS_DEFAULT;