vmap: skip remapped materials when looking for an already allocated material.

This commit is contained in:
Marco Cawthorne 2022-06-08 16:38:08 -07:00
parent f753e6f3ba
commit d8e2eb103c
Signed by: eukara
GPG key ID: CE2032F0A2882A22
12 changed files with 96 additions and 30 deletions

View file

@ -251,7 +251,7 @@ static void ConvertShader( FILE *f, bspShader_t *shader, int shaderNum ){
/* get shader */ /* get shader */
si = ShaderInfoForShader( shader->shader ); si = ShaderInfoForShader( shader->shader, 0 );
if ( si == NULL ) { if ( si == NULL ) {
Sys_FPrintf( SYS_WRN, "WARNING: NULL shader in BSP\n" ); Sys_FPrintf( SYS_WRN, "WARNING: NULL shader in BSP\n" );
return; return;

View file

@ -269,7 +269,7 @@ static void ConvertBrush( FILE *f, int num, bspBrush_t *brush, vec3_t origin, qb
buildBrush->numsides++; buildBrush->numsides++;
/* tag it */ /* tag it */
buildSide->shaderInfo = ShaderInfoForShader( shader->shader ); buildSide->shaderInfo = ShaderInfoForShader( shader->shader, 0 );
buildSide->planenum = side->planeNum; buildSide->planenum = side->planeNum;
buildSide->winding = NULL; buildSide->winding = NULL;
} }

View file

@ -158,7 +158,7 @@ static void ConvertShaderToMTL( FILE *f, bspShader_t *shader, int shaderNum ){
/* get shader */ /* get shader */
si = ShaderInfoForShader( shader->shader ); si = ShaderInfoForShader( shader->shader, 0 );
if ( si == NULL ) { if ( si == NULL ) {
Sys_FPrintf( SYS_WRN, "WARNING: NULL shader in BSP\n" ); Sys_FPrintf( SYS_WRN, "WARNING: NULL shader in BSP\n" );
return; return;

View file

@ -1190,7 +1190,7 @@ void SetupSurfaceLightmaps( void ){
/* get extra data */ /* get extra data */
info->si = GetSurfaceExtraShaderInfo( num ); info->si = GetSurfaceExtraShaderInfo( num );
if ( info->si == NULL ) { if ( info->si == NULL ) {
info->si = ShaderInfoForShader( bspShaders[ ds->shaderNum ].shader ); info->si = ShaderInfoForShader( bspShaders[ ds->shaderNum ].shader, 0 );
} }
info->parentSurfaceNum = GetSurfaceExtraParentSurfaceNum( num ); info->parentSurfaceNum = GetSurfaceExtraParentSurfaceNum( num );
info->entityNum = GetSurfaceExtraEntityNum( num ); info->entityNum = GetSurfaceExtraEntityNum( num );

View file

@ -1128,7 +1128,7 @@ static void ParseRawBrush( qboolean onlyLights ){
si = &shaderInfo[ 0 ]; si = &shaderInfo[ 0 ];
} }
else{ else{
si = ShaderInfoForShader( shader ); si = ShaderInfoForShader( shader, 0 );
} }
side->shaderInfo = si; side->shaderInfo = si;
side->surfaceFlags = si->surfaceFlags; side->surfaceFlags = si->surfaceFlags;
@ -1847,7 +1847,7 @@ static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups )
if ( value[ 0 ] != '\0' ) { if ( value[ 0 ] != '\0' ) {
if ( strcmp( value, "none" ) ) { if ( strcmp( value, "none" ) ) {
sprintf( shader, "textures/%s", value ); sprintf( shader, "textures/%s", value );
celShader = ShaderInfoForShader( shader ); celShader = ShaderInfoForShader( shader, 0 );
Sys_Printf( "Entity %d (%s) has cel shader %s\n", mapEnt->mapEntityNum, classname, celShader->shader ); Sys_Printf( "Entity %d (%s) has cel shader %s\n", mapEnt->mapEntityNum, classname, celShader->shader );
} }
else else
@ -1856,7 +1856,7 @@ static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups )
} }
} }
else{ else{
celShader = ( *globalCelShader ? ShaderInfoForShader( globalCelShader ) : NULL ); celShader = ( *globalCelShader ? ShaderInfoForShader( globalCelShader, 0 ) : NULL );
} }
/* jal : entity based _shadeangle */ /* jal : entity based _shadeangle */

View file

@ -392,10 +392,10 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
else{ else{
strcat( shaderName, "_BSP" ); strcat( shaderName, "_BSP" );
} }
si = ShaderInfoForShader( shaderName ); si = ShaderInfoForShader( shaderName, 0 );
} }
else{ else{
si = ShaderInfoForShader( picoShaderName ); si = ShaderInfoForShader( picoShaderName, 0 );
} }
/* allocate a surface (ydnar: gs mods) */ /* allocate a surface (ydnar: gs mods) */
@ -860,10 +860,10 @@ void AddTriangleModels( entity_t *e ){
} }
if ( value[ 0 ] != '\0' ) { if ( value[ 0 ] != '\0' ) {
sprintf( shader, "textures/%s", value ); sprintf( shader, "textures/%s", value );
celShader = ShaderInfoForShader( shader ); celShader = ShaderInfoForShader( shader, 0 );
} }
else{ else{
celShader = *globalCelShader ? ShaderInfoForShader( globalCelShader ) : NULL; celShader = *globalCelShader ? ShaderInfoForShader( globalCelShader, 0 ) : NULL;
} }
/* jal : entity based _samplesize */ /* jal : entity based _samplesize */

View file

@ -406,7 +406,7 @@ void ParsePatch( qboolean onlyLights, qboolean fixedtess, qboolean extended ){
/* set shader */ /* set shader */
sprintf( shader, "textures/%s", texture ); sprintf( shader, "textures/%s", texture );
pm->shaderInfo = ShaderInfoForShader( shader ); pm->shaderInfo = ShaderInfoForShader( shader, 0 );
/* set mesh */ /* set mesh */
pm->mesh = m; pm->mesh = m;

View file

@ -439,7 +439,7 @@ shaderInfo_t *CustomShader( shaderInfo_t *si, char *find, char *replace ){
/* dummy check */ /* dummy check */
if ( si == NULL ) { if ( si == NULL ) {
return ShaderInfoForShader( "default" ); return ShaderInfoForShader( "default", 0 );
} }
/* default shader text source */ /* default shader text source */
@ -561,7 +561,7 @@ shaderInfo_t *CustomShader( shaderInfo_t *si, char *find, char *replace ){
digest[ 8 ], digest[ 9 ], digest[ 10 ], digest[ 11 ], digest[ 12 ], digest[ 13 ], digest[ 14 ], digest[ 15 ] ); digest[ 8 ], digest[ 9 ], digest[ 10 ], digest[ 11 ], digest[ 12 ], digest[ 13 ], digest[ 14 ], digest[ 15 ] );
/* get shader */ /* get shader */
csi = ShaderInfoForShader( shader ); csi = ShaderInfoForShader( shader, 0 );
/* might be a preexisting shader */ /* might be a preexisting shader */
if ( csi->custom ) { if ( csi->custom ) {
@ -662,6 +662,7 @@ static shaderInfo_t *AllocShaderInfo( void ){
si->forceSunlight = qfalse; si->forceSunlight = qfalse;
si->vertexScale = 1.0; si->vertexScale = 1.0;
si->notjunc = qfalse; si->notjunc = qfalse;
si->remapped = qfalse;
/* ydnar: set texture coordinate transform matrix to identity */ /* ydnar: set texture coordinate transform matrix to identity */
TCModIdentity( si->mod ); TCModIdentity( si->mod );
@ -820,7 +821,7 @@ shaderInfo_t *ShaderInfoForShaderNull( const char *shaderName ){
if ( !strcmp( shaderName, "noshader" ) ) { if ( !strcmp( shaderName, "noshader" ) ) {
return NULL; return NULL;
} }
return ShaderInfoForShader( shaderName ); return ShaderInfoForShader( shaderName, 0 );
} }
/* /*
@ -887,7 +888,64 @@ void Parse1DMatMatrixAppend( char *buffer, int x, vec_t *m ){
} }
} }
shaderInfo_t *ShaderInfoForShader( const char *shaderName ){ int
ShaderInfoExists(const char *shaderName)
{
int i;
shaderInfo_t *si;
char shader[ MAX_QPATH ];
char filename[ MAX_QPATH ];
char shaderText[ 8192 ], temp[ 1024 ];
int val;
qboolean parsedContent;
/* init */
si = NULL;
/* dummy check */
if ( shaderName == NULL || shaderName[ 0 ] == '\0' ) {
Sys_FPrintf( SYS_WRN, "WARNING: Null or empty shader name\n" );
shaderName = "missing";
}
/* strip off extension */
strcpy( shader, shaderName );
StripExtension( shader );
int deprecationDepth = 0;
for ( i = 0; i < numShaderInfo; i++ )
{
si = &shaderInfo[ i ];
if ( !Q_stricmp( shader, si->shader ) ) {
/* check if shader is deprecated */
if ( deprecationDepth < MAX_SHADER_DEPRECATION_DEPTH && si->deprecateShader && si->deprecateShader[ 0 ] ) {
/* override name */
strcpy( shader, si->deprecateShader );
StripExtension( shader );
/* increase deprecation depth */
deprecationDepth++;
if ( deprecationDepth == MAX_SHADER_DEPRECATION_DEPTH ) {
Sys_FPrintf( SYS_WRN, "WARNING: Max deprecation depth of %i is reached on shader '%s'\n", MAX_SHADER_DEPRECATION_DEPTH, shader );
}
/* search again from beginning */
i = -1;
continue;
}
/* load image if necessary */
if ( si->finished == qfalse ) {
return 0;
}
return 1;
}
}
return 0;
}
shaderInfo_t *ShaderInfoForShader( const char *shaderName, int force ){
int i; int i;
int deprecationDepth; int deprecationDepth;
shaderInfo_t *si; shaderInfo_t *si;
@ -911,7 +969,8 @@ shaderInfo_t *ShaderInfoForShader( const char *shaderName ){
strcpy( shader, shaderName ); strcpy( shader, shaderName );
StripExtension( shader ); StripExtension( shader );
#if 1 /* force new allocation */
if (force == 0) {
deprecationDepth = 0; deprecationDepth = 0;
for ( i = 0; i < numShaderInfo; i++ ) for ( i = 0; i < numShaderInfo; i++ )
{ {
@ -938,11 +997,16 @@ shaderInfo_t *ShaderInfoForShader( const char *shaderName ){
FinishShader( si ); FinishShader( si );
} }
/* this is a remapped shader, continue */
if (si->remapped == qtrue) {
continue;
}
/* return it */ /* return it */
return si; return si;
} }
} }
#endif }
/* allocate a default shader */ /* allocate a default shader */
si = AllocShaderInfo(); si = AllocShaderInfo();
@ -1174,7 +1238,7 @@ shaderInfo_t *ShaderInfoForShader( const char *shaderName ){
//% Sys_FPrintf( SYS_VRB, "Shader %s has base shader %s\n", si->shader, mattoken ); //% Sys_FPrintf( SYS_VRB, "Shader %s has base shader %s\n", si->shader, mattoken );
oldWarnImage = warnImage; oldWarnImage = warnImage;
warnImage = qfalse; warnImage = qfalse;
si2 = ShaderInfoForShader( mattoken ); si2 = ShaderInfoForShader( mattoken, 0 );
warnImage = oldWarnImage; warnImage = oldWarnImage;
/* subclass it */ /* subclass it */
@ -2245,7 +2309,7 @@ static void ParseShaderFile( const char *filename ){
//% Sys_FPrintf( SYS_VRB, "Shader %s has base shader %s\n", si->shader, token ); //% Sys_FPrintf( SYS_VRB, "Shader %s has base shader %s\n", si->shader, token );
oldWarnImage = warnImage; oldWarnImage = warnImage;
warnImage = qfalse; warnImage = qfalse;
si2 = ShaderInfoForShader( token ); si2 = ShaderInfoForShader( token, 0 );
warnImage = oldWarnImage; warnImage = oldWarnImage;
/* subclass it */ /* subclass it */

View file

@ -99,12 +99,12 @@ void FinishSurface( mapDrawSurface_t *ds ){
/* ydnar: rocking surface cloning (fur baby yeah!) */ /* ydnar: rocking surface cloning (fur baby yeah!) */
if ( ds->shaderInfo->cloneShader != NULL && ds->shaderInfo->cloneShader[ 0 ] != '\0' ) { if ( ds->shaderInfo->cloneShader != NULL && ds->shaderInfo->cloneShader[ 0 ] != '\0' ) {
CloneSurface( ds, ShaderInfoForShader( ds->shaderInfo->cloneShader ) ); CloneSurface( ds, ShaderInfoForShader( ds->shaderInfo->cloneShader, 0 ) );
} }
/* ydnar: q3map_backShader support */ /* ydnar: q3map_backShader support */
if ( ds->shaderInfo->backShader != NULL && ds->shaderInfo->backShader[ 0 ] != '\0' ) { if ( ds->shaderInfo->backShader != NULL && ds->shaderInfo->backShader[ 0 ] != '\0' ) {
ds2 = CloneSurface( ds, ShaderInfoForShader( ds->shaderInfo->backShader ) ); ds2 = CloneSurface( ds, ShaderInfoForShader( ds->shaderInfo->backShader, 0 ) );
ds2->backSide = qtrue; ds2->backSide = qtrue;
} }
} }
@ -1038,7 +1038,7 @@ mapDrawSurface_t *DrawSurfaceForShader( char *shader ){
/* get shader */ /* get shader */
si = ShaderInfoForShader( shader ); si = ShaderInfoForShader( shader, 0 );
/* find existing surface */ /* find existing surface */
for ( i = 0; i < numMapDrawSurfs; i++ ) for ( i = 0; i < numMapDrawSurfs; i++ )
@ -1055,7 +1055,7 @@ mapDrawSurface_t *DrawSurfaceForShader( char *shader ){
/* create a new surface */ /* create a new surface */
ds = AllocDrawSurface( SURFACE_SHADER ); ds = AllocDrawSurface( SURFACE_SHADER );
ds->entityNum = 0; ds->entityNum = 0;
ds->shaderInfo = ShaderInfoForShader( shader ); ds->shaderInfo = ShaderInfoForShader( shader, 0 );
/* return to sender */ /* return to sender */
return ds; return ds;
@ -2788,7 +2788,7 @@ void MakeDebugPortalSurfs( tree_t *tree ){
Sys_FPrintf( SYS_VRB, "--- MakeDebugPortalSurfs ---\n" ); Sys_FPrintf( SYS_VRB, "--- MakeDebugPortalSurfs ---\n" );
/* get portal debug shader */ /* get portal debug shader */
si = ShaderInfoForShader( "debugportals" ); si = ShaderInfoForShader( "debugportals", 0 );
/* walk the tree */ /* walk the tree */
MakeDebugPortalSurfs_r( tree->headnode, si ); MakeDebugPortalSurfs_r( tree->headnode, si );
@ -2834,7 +2834,7 @@ void MakeFogHullSurfs( entity_t *e, tree_t *tree, char *shader ){
} }
/* get foghull shader */ /* get foghull shader */
si = ShaderInfoForShader( shader ); si = ShaderInfoForShader( shader, 0 );
/* allocate a drawsurface */ /* allocate a drawsurface */
ds = AllocDrawSurface( SURFACE_FOGHULL ); ds = AllocDrawSurface( SURFACE_FOGHULL );
@ -3377,8 +3377,9 @@ void FilterDrawsurfsIntoTree( entity_t *e, tree_t *tree ){
/* ydnar: remap shader */ /* ydnar: remap shader */
if ( ds->shaderInfo->remapShader && ds->shaderInfo->remapShader[ 0 ] ) { if ( ds->shaderInfo->remapShader && ds->shaderInfo->remapShader[ 0 ] ) {
int surfaceflags = ds->shaderInfo->surfaceFlags; int surfaceflags = ds->shaderInfo->surfaceFlags;
ds->shaderInfo = ShaderInfoForShader( ds->shaderInfo->remapShader ); ds->shaderInfo = ShaderInfoForShader( ds->shaderInfo->remapShader, 1 );
ds->shaderInfo->surfaceFlags = surfaceflags; ds->shaderInfo->surfaceFlags = surfaceflags;
ds->shaderInfo->remapped = qtrue;
} }
/* ydnar: gs mods: handle the various types of surfaces */ /* ydnar: gs mods: handle the various types of surfaces */

View file

@ -380,7 +380,7 @@ void LoadSurfaceExtraFile( const char *surfaceFilePath ){
/* shader */ /* shader */
if ( !Q_stricmp( token, "shader" ) ) { if ( !Q_stricmp( token, "shader" ) ) {
GetToken( qfalse ); GetToken( qfalse );
se->si = ShaderInfoForShader( token ); se->si = ShaderInfoForShader( token, 0 );
} }
/* parent surface number */ /* parent surface number */

View file

@ -782,6 +782,7 @@ typedef struct shaderInfo_s
char *shaderText; /* ydnar */ char *shaderText; /* ydnar */
qb_t custom; qb_t custom;
qb_t finished; qb_t finished;
qb_t remapped;
} }
shaderInfo_t; shaderInfo_t;
@ -1886,7 +1887,7 @@ shaderInfo_t *CustomShader( shaderInfo_t *si, char *find, char *r
void EmitVertexRemapShader( char *from, char *to ); void EmitVertexRemapShader( char *from, char *to );
void LoadShaderInfo( void ); void LoadShaderInfo( void );
shaderInfo_t *ShaderInfoForShader( const char *shader ); shaderInfo_t *ShaderInfoForShader( const char *shader, int force );
shaderInfo_t *ShaderInfoForShaderNull( const char *shader ); shaderInfo_t *ShaderInfoForShaderNull( const char *shader );

View file

@ -71,7 +71,7 @@ int EmitShader( const char *shader, int *contentFlags, int *surfaceFlags ){
} }
/* get shaderinfo */ /* get shaderinfo */
si = ShaderInfoForShader( shader ); si = ShaderInfoForShader( shader, 0 );
/* emit a new shader */ /* emit a new shader */
AUTOEXPAND_BY_REALLOC_BSP( Shaders, 1024 ); AUTOEXPAND_BY_REALLOC_BSP( Shaders, 1024 );