Skip to content

Commit 0e4a305

Browse files
committed
Don't search generated textures in shader hash table
RE_RegisterShaderFromImage creates a q3shader object for textures that have just been generated at runtime. Don't attempt to find them in the shader hash table. This doesn't make much sense and even if a match were found, an image was already uploaded at that point so the memory is already wasted.
1 parent 20dbe47 commit 0e4a305

File tree

1 file changed

+3
-22
lines changed

1 file changed

+3
-22
lines changed

src/engine/renderer/tr_shader.cpp

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6243,27 +6243,9 @@ shader_t *R_FindShader( const char *name, shaderType_t type, int flags )
62436243
return FinishShader();
62446244
}
62456245

6246+
// This is used for textures for 2D rendering generated at runtime.
62466247
qhandle_t RE_RegisterShaderFromImage( const char *name, image_t *image )
62476248
{
6248-
int i, hash;
6249-
shader_t *sh;
6250-
6251-
hash = generateHashValue( name, FILE_HASH_SIZE );
6252-
6253-
// see if the shader is already loaded
6254-
for ( sh = shaderHashTable[ hash ]; sh; sh = sh->next )
6255-
{
6256-
// NOTE: if there was no shader or image available with the name strippedName
6257-
// then a default shader is created with type == SHADER_3D_DYNAMIC, so we
6258-
// have to check all default shaders otherwise for every call to R_FindShader
6259-
// with that same strippedName a new default shader is created.
6260-
if ( ( sh->type == shaderType_t::SHADER_2D || sh->defaultShader ) && !Q_stricmp( sh->name, name ) )
6261-
{
6262-
// match found
6263-
return sh->index;
6264-
}
6265-
}
6266-
62676249
// make sure the render thread is stopped, because we are probably
62686250
// going to have to upload an image
62696251
R_SyncRenderThread();
@@ -6274,7 +6256,7 @@ qhandle_t RE_RegisterShaderFromImage( const char *name, image_t *image )
62746256
shader.type = shaderType_t::SHADER_2D;
62756257
shader.cullType = CT_TWO_SIDED;
62766258

6277-
for ( i = 0; i < MAX_SHADER_STAGES; i++ )
6259+
for ( int i = 0; i < MAX_SHADER_STAGES; i++ )
62786260
{
62796261
stages[ i ].bundle[ 0 ].texMods = texMods[ i ];
62806262
}
@@ -6288,8 +6270,7 @@ qhandle_t RE_RegisterShaderFromImage( const char *name, image_t *image )
62886270
stages[ 0 ].alphaGen = alphaGen_t::AGEN_VERTEX;
62896271
stages[ 0 ].stateBits = GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA;
62906272

6291-
sh = FinishShader();
6292-
return sh->index;
6273+
return FinishShader()->index;
62936274
}
62946275

62956276
/*

0 commit comments

Comments
 (0)