Skip to content

Commit 4312e6f

Browse files
committed
Refactor missing shader handling to make them respect shader remaps.
1 parent 4ccdde1 commit 4312e6f

File tree

3 files changed

+14
-55
lines changed

3 files changed

+14
-55
lines changed

src/renderer/tr_bsp.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,6 @@ static shader_t *ShaderForShaderNum( int shaderNum, const int *lightmapNum, cons
386386

387387
shader = R_FindShader( dsh->shader, lightmapNum, styles, qtrue );
388388

389-
// if the shader had errors, just use default shader
390-
if ( shader->defaultShader ) {
391-
return tr.defaultShader;
392-
}
393-
394389
return shader;
395390
}
396391

src/renderer/tr_shade.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ to overflow.
322322
void RB_BeginSurface( shader_t *shader, int fogNum ) {
323323

324324
shader_t *state = (shader->remappedShaderAdvanced ? shader->remappedShaderAdvanced : (shader->remappedShader ? shader->remappedShader : shader));
325+
if ( state->defaultShader ) state = tr.defaultShader;
325326

326327
tess.numIndexes = 0;
327328
tess.numVertexes = 0;

src/renderer/tr_shader.cpp

Lines changed: 13 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -254,21 +254,10 @@ void R_RemapShaderAdvanced(const char *shaderName, const char *newShaderName, in
254254
char strippedName[MAX_QPATH];
255255
int hash;
256256
shader_t *sh, *sh2 = NULL;
257-
qhandle_t h;
258257
int failed = 0;
259258
const int *lightmapIndex = NULL;
260259
const byte *styles = NULL;
261-
262-
// Check if at least one instance of the original exists
263-
sh = R_FindShaderByName( shaderName );
264-
if (sh == NULL || sh == tr.defaultShader || sh->defaultShader) {
265-
h = RE_RegisterShaderLightMap(shaderName, lightmapsNone, stylesDefault);
266-
sh = R_GetShaderByHandle(h);
267-
}
268-
if (sh == NULL || sh == tr.defaultShader || sh->defaultShader) {
269-
ri.Printf( PRINT_WARNING, "WARNING: R_RemapShaderAdvanced: shader %s not found\n", shaderName );
270-
return;
271-
}
260+
qboolean foundShader = qfalse;
272261

273262
// Lightmap
274263
if ( lightmapMode == SHADERREMAP_LIGHTMAP_FULLBRIGHT ) {
@@ -301,6 +290,8 @@ void R_RemapShaderAdvanced(const char *shaderName, const char *newShaderName, in
301290
hash = generateHashValue(strippedName, FILE_HASH_SIZE);
302291
for (sh = hashTable[hash]; sh; sh = sh->next) {
303292
if (Q_stricmp(sh->name, strippedName) == 0) {
293+
foundShader = qtrue;
294+
304295
if ( lightmapMode == SHADERREMAP_LIGHTMAP_PRESERVE || lightmapMode == SHADERREMAP_LIGHTMAP_VERTEX ) {
305296
// When preserving lightmaps we need to use the correct lightmap index (+styles)
306297
sh2 = R_FindAdvancedRemapShader( newShaderName, lightmapIndex ? lightmapIndex : sh->lightmapIndex, styles ? styles : sh->styles, (qboolean)!sh->upload.noMipMaps );
@@ -319,6 +310,7 @@ void R_RemapShaderAdvanced(const char *shaderName, const char *newShaderName, in
319310
}
320311
}
321312
}
313+
if ( !foundShader ) ri.Printf( PRINT_WARNING, "WARNING: R_RemapShaderAdvanced: shader %s not found\n", shaderName );
322314
if ( failed ) ri.Printf( PRINT_WARNING, "WARNING: R_RemapShaderAdvanced: new shader %s not found (x%i)\n", newShaderName, failed );
323315
}
324316

@@ -3462,18 +3454,15 @@ inline qboolean IsShader(shader_t *sh, const char *name, const int *lightmapInde
34623454
return qfalse;
34633455
}
34643456

3465-
if (!sh->defaultShader)
3457+
for(i=0;i<MAXLIGHTMAPS;i++)
34663458
{
3467-
for(i=0;i<MAXLIGHTMAPS;i++)
3459+
if (sh->lightmapIndex[i] != lightmapIndex[i])
34683460
{
3469-
if (sh->lightmapIndex[i] != lightmapIndex[i])
3470-
{
3471-
return qfalse;
3472-
}
3473-
if (sh->styles[i] != styles[i])
3474-
{
3475-
return qfalse;
3476-
}
3461+
return qfalse;
3462+
}
3463+
if (sh->styles[i] != styles[i])
3464+
{
3465+
return qfalse;
34773466
}
34783467
}
34793468

@@ -3637,7 +3626,8 @@ shader_t *R_FindShader( const char *name, const int *lightmapIndex, const byte *
36373626
if ( !image ) {
36383627
ri.Printf( PRINT_DEVELOPER, "Couldn't find image for shader %s\n", name );
36393628
shader.defaultShader = qtrue;
3640-
return FinishShader();
3629+
//return FinishShader();
3630+
image = tr.defaultImage;
36413631
}
36423632

36433633
//
@@ -3815,15 +3805,6 @@ qhandle_t RE_RegisterShaderLightMap( const char *name, const int *lightmapIndex,
38153805

38163806
sh = R_FindShader( name, lightmapIndex, styles, qtrue );
38173807

3818-
// we want to return 0 if the shader failed to
3819-
// load for some reason, but R_FindShader should
3820-
// still keep a name allocated for it, so if
3821-
// something calls RE_RegisterShader again with
3822-
// the same name, we don't try looking for it again
3823-
if ( sh->defaultShader ) {
3824-
return 0;
3825-
}
3826-
38273808
return sh->index;
38283809
}
38293810

@@ -3849,15 +3830,6 @@ qhandle_t RE_RegisterShader( const char *name ) {
38493830

38503831
sh = R_FindShader( name, lightmaps2d, stylesDefault, qtrue );
38513832

3852-
// we want to return 0 if the shader failed to
3853-
// load for some reason, but R_FindShader should
3854-
// still keep a name allocated for it, so if
3855-
// something calls RE_RegisterShader again with
3856-
// the same name, we don't try looking for it again
3857-
if ( sh->defaultShader ) {
3858-
return 0;
3859-
}
3860-
38613833
return sh->index;
38623834
}
38633835

@@ -3879,15 +3851,6 @@ qhandle_t RE_RegisterShaderNoMip( const char *name ) {
38793851

38803852
sh = R_FindShader( name, lightmaps2d, stylesDefault, qfalse );
38813853

3882-
// we want to return 0 if the shader failed to
3883-
// load for some reason, but R_FindShader should
3884-
// still keep a name allocated for it, so if
3885-
// something calls RE_RegisterShader again with
3886-
// the same name, we don't try looking for it again
3887-
if ( sh->defaultShader ) {
3888-
return 0;
3889-
}
3890-
38913854
return sh->index;
38923855
}
38933856

0 commit comments

Comments
 (0)