OpenGL2: Reduce glsl shader count by using a uniform to disable textures.
This commit is contained in:
parent
7ae49cc237
commit
3846c115e6
7 changed files with 147 additions and 154 deletions
|
@ -730,7 +730,7 @@ static void ForwardDlight( void ) {
|
|||
{
|
||||
int index = pStage->glslShaderIndex;
|
||||
|
||||
index &= ~(LIGHTDEF_LIGHTTYPE_MASK | LIGHTDEF_USE_DELUXEMAP);
|
||||
index &= ~LIGHTDEF_LIGHTTYPE_MASK;
|
||||
index |= LIGHTDEF_USE_LIGHT_VECTOR;
|
||||
|
||||
sp = &tr.lightallShader[index];
|
||||
|
@ -1098,11 +1098,6 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
|
|||
index |= LIGHTDEF_USE_SHADOWMAP;
|
||||
}
|
||||
|
||||
if (!(tr.viewParms.flags & VPF_NOCUBEMAPS) && (index & LIGHTDEF_LIGHTTYPE_MASK) && input->cubemapIndex)
|
||||
{
|
||||
index |= LIGHTDEF_USE_CUBEMAP;
|
||||
}
|
||||
|
||||
if (r_lightmap->integer && index & LIGHTDEF_USE_LIGHTMAP)
|
||||
{
|
||||
index = LIGHTDEF_USE_LIGHTMAP;
|
||||
|
@ -1228,6 +1223,7 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
|
|||
else if ( pStage->glslShaderGroup == tr.lightallShader )
|
||||
{
|
||||
int i;
|
||||
vec4_t enableTextures;
|
||||
|
||||
if ((backEnd.viewParms.flags & VPF_USESUNLIGHT) && (pStage->glslShaderIndex & LIGHTDEF_LIGHTTYPE_MASK))
|
||||
{
|
||||
|
@ -1237,73 +1233,78 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
|
|||
GLSL_SetUniformVec4(sp, UNIFORM_PRIMARYLIGHTORIGIN, backEnd.refdef.sunDir);
|
||||
}
|
||||
|
||||
VectorSet4(enableTextures, 0, 0, 0, 0);
|
||||
if ((r_lightmap->integer == 1 || r_lightmap->integer == 2) && pStage->bundle[TB_LIGHTMAP].image[0])
|
||||
{
|
||||
for (i = 0; i < NUM_TEXTURE_BUNDLES; i++)
|
||||
{
|
||||
if (pStage->bundle[i].image[0])
|
||||
{
|
||||
switch(i)
|
||||
{
|
||||
case TB_LIGHTMAP:
|
||||
R_BindAnimatedImageToTMU( &pStage->bundle[TB_LIGHTMAP], i);
|
||||
break;
|
||||
|
||||
case TB_DIFFUSEMAP:
|
||||
case TB_SPECULARMAP:
|
||||
case TB_SHADOWMAP:
|
||||
case TB_CUBEMAP:
|
||||
default:
|
||||
GL_BindToTMU( tr.whiteImage, i);
|
||||
break;
|
||||
|
||||
case TB_NORMALMAP:
|
||||
case TB_DELUXEMAP:
|
||||
GL_BindToTMU( tr.greyImage, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == TB_LIGHTMAP)
|
||||
R_BindAnimatedImageToTMU( &pStage->bundle[TB_LIGHTMAP], i);
|
||||
else
|
||||
GL_BindToTMU( tr.whiteImage, i );
|
||||
}
|
||||
}
|
||||
else if (r_lightmap->integer == 3 && pStage->bundle[TB_DELUXEMAP].image[0])
|
||||
{
|
||||
for (i = 0; i < NUM_TEXTURE_BUNDLES; i++)
|
||||
{
|
||||
if (pStage->bundle[i].image[0])
|
||||
{
|
||||
switch(i)
|
||||
{
|
||||
case TB_LIGHTMAP:
|
||||
R_BindAnimatedImageToTMU( &pStage->bundle[TB_DELUXEMAP], i);
|
||||
break;
|
||||
|
||||
case TB_DIFFUSEMAP:
|
||||
case TB_SPECULARMAP:
|
||||
case TB_SHADOWMAP:
|
||||
case TB_CUBEMAP:
|
||||
default:
|
||||
GL_BindToTMU( tr.whiteImage, i);
|
||||
break;
|
||||
|
||||
case TB_NORMALMAP:
|
||||
case TB_DELUXEMAP:
|
||||
GL_BindToTMU( tr.greyImage, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == TB_LIGHTMAP)
|
||||
R_BindAnimatedImageToTMU( &pStage->bundle[TB_DELUXEMAP], i);
|
||||
else
|
||||
GL_BindToTMU( tr.whiteImage, i );
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < NUM_TEXTURE_BUNDLES; i++)
|
||||
qboolean light = (pStage->glslShaderIndex & LIGHTDEF_LIGHTTYPE_MASK) != 0;
|
||||
qboolean fastLight = !(r_normalMapping->integer || r_specularMapping->integer);
|
||||
|
||||
if (pStage->bundle[TB_DIFFUSEMAP].image[0])
|
||||
R_BindAnimatedImageToTMU( &pStage->bundle[TB_DIFFUSEMAP], TB_DIFFUSEMAP);
|
||||
|
||||
if (pStage->bundle[TB_LIGHTMAP].image[0])
|
||||
R_BindAnimatedImageToTMU( &pStage->bundle[TB_LIGHTMAP], TB_LIGHTMAP);
|
||||
|
||||
// bind textures that are sampled and used in the glsl shader, and
|
||||
// bind whiteImage to textures that are sampled but zeroed in the glsl shader
|
||||
//
|
||||
// alternatives:
|
||||
// - use the last bound texture
|
||||
// -> costs more to sample a higher res texture then throw out the result
|
||||
// - disable texture sampling in glsl shader with #ifdefs, as before
|
||||
// -> increases the number of shaders that must be compiled
|
||||
//
|
||||
if (light && !fastLight)
|
||||
{
|
||||
if (pStage->bundle[i].image[0])
|
||||
if (pStage->bundle[TB_NORMALMAP].image[0])
|
||||
{
|
||||
R_BindAnimatedImageToTMU( &pStage->bundle[i], i);
|
||||
R_BindAnimatedImageToTMU( &pStage->bundle[TB_NORMALMAP], TB_NORMALMAP);
|
||||
enableTextures[0] = 1.0f;
|
||||
}
|
||||
else if (r_normalMapping->integer)
|
||||
GL_BindToTMU( tr.whiteImage, TB_NORMALMAP );
|
||||
|
||||
if (pStage->bundle[TB_DELUXEMAP].image[0])
|
||||
{
|
||||
R_BindAnimatedImageToTMU( &pStage->bundle[TB_DELUXEMAP], TB_DELUXEMAP);
|
||||
enableTextures[1] = 1.0f;
|
||||
}
|
||||
else if (r_deluxeMapping->integer)
|
||||
GL_BindToTMU( tr.whiteImage, TB_DELUXEMAP );
|
||||
|
||||
if (pStage->bundle[TB_SPECULARMAP].image[0])
|
||||
{
|
||||
R_BindAnimatedImageToTMU( &pStage->bundle[TB_SPECULARMAP], TB_SPECULARMAP);
|
||||
enableTextures[2] = 1.0f;
|
||||
}
|
||||
else if (r_specularMapping->integer)
|
||||
GL_BindToTMU( tr.whiteImage, TB_SPECULARMAP );
|
||||
}
|
||||
|
||||
enableTextures[3] = (r_cubeMapping->integer && !(tr.viewParms.flags & VPF_NOCUBEMAPS) && input->cubemapIndex) ? 1.0f : 0.0f;
|
||||
}
|
||||
|
||||
GLSL_SetUniformVec4(sp, UNIFORM_ENABLETEXTURES, enableTextures);
|
||||
}
|
||||
else if ( pStage->bundle[1].image[0] != 0 )
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue