@@ -87,6 +87,14 @@ static Cvar::Cvar<float> r_portalDefaultRange(
8787Cvar::Cvar<bool > r_depthShaders (
8888 " r_depthShaders" , " use depth pre-pass shaders" , Cvar::CHEAT, true );
8989
90+ struct delayedStageTexture_t {
91+ bool active;
92+ stageType_t type;
93+ char path[ MAX_QPATH ];
94+ };
95+
96+ delayedStageTexture_t delayedStageTextures[ MAX_TEXTURE_BUNDLES ];
97+
9098/*
9199================
92100return a hash value for the filename
@@ -1591,6 +1599,14 @@ static bool ParseClampType( const char *token, wrapType_t *clamp )
15911599 return true ;
15921600}
15931601
1602+ static void DelayMapLoading ( const char * texturePath, const stageType_t stageType, const int bundleIndex )
1603+ {
1604+ Log::Debug (" Delaying the loading of texture %s" , texturePath );
1605+ strncpy ( delayedStageTextures[ bundleIndex ].path , texturePath, MAX_QPATH - 1 );
1606+ delayedStageTextures[ bundleIndex ].type = stageType;
1607+ delayedStageTextures[ bundleIndex ].active = true ;
1608+ }
1609+
15941610/*
15951611===================
15961612ParseDifuseMap
@@ -1603,7 +1619,16 @@ static void ParseDiffuseMap( shaderStage_t *stage, const char **text, const int
16031619
16041620 if ( ParseMap ( text, buffer, sizeof ( buffer ) ) )
16051621 {
1606- LoadMap ( stage, buffer, stageType_t::ST_DIFFUSEMAP, bundleIndex );
1622+ stageType_t stageType = stageType_t::ST_DIFFUSEMAP;
1623+
1624+ if ( bundleIndex == TB_DIFFUSEMAP )
1625+ {
1626+ DelayMapLoading ( buffer, stageType, bundleIndex );
1627+ }
1628+ else
1629+ {
1630+ LoadMap ( stage, buffer, stageType, bundleIndex );
1631+ }
16071632 }
16081633}
16091634
@@ -1632,7 +1657,16 @@ static void ParseNormalMap( shaderStage_t *stage, const char **text, const int b
16321657
16331658 if ( ParseMap ( text, buffer, sizeof ( buffer ) ) )
16341659 {
1635- LoadMap ( stage, buffer, stageType_t::ST_NORMALMAP, bundleIndex );
1660+ stageType_t stageType = stageType_t::ST_NORMALMAP;
1661+
1662+ if ( bundleIndex == TB_NORMALMAP )
1663+ {
1664+ DelayMapLoading ( buffer, stageType, bundleIndex );
1665+ }
1666+ else
1667+ {
1668+ LoadMap ( stage, buffer, stageType, bundleIndex );
1669+ }
16361670 }
16371671}
16381672
@@ -1697,7 +1731,16 @@ static void ParseHeightMap( shaderStage_t *stage, const char **text, const int b
16971731
16981732 if ( ParseMap ( text, buffer, sizeof ( buffer ) ) )
16991733 {
1700- LoadMap ( stage, buffer, stageType_t::ST_HEIGHTMAP, bundleIndex );
1734+ stageType_t stageType = stageType_t::ST_HEIGHTMAP;
1735+
1736+ if ( bundleIndex == TB_HEIGHTMAP )
1737+ {
1738+ DelayMapLoading ( buffer, stageType, bundleIndex );
1739+ }
1740+ else
1741+ {
1742+ LoadMap ( stage, buffer, stageType, bundleIndex );
1743+ }
17011744 }
17021745}
17031746
@@ -1709,7 +1752,16 @@ static void ParseSpecularMap( shaderStage_t *stage, const char **text, const int
17091752
17101753 if ( ParseMap ( text, buffer, sizeof ( buffer ) ) )
17111754 {
1712- LoadMap ( stage, buffer, stageType_t::ST_SPECULARMAP, bundleIndex );
1755+ stageType_t stageType = stageType_t::ST_SPECULARMAP;
1756+
1757+ if ( bundleIndex == TB_SPECULARMAP )
1758+ {
1759+ DelayMapLoading ( buffer, stageType, bundleIndex );
1760+ }
1761+ else
1762+ {
1763+ LoadMap ( stage, buffer, stageType, bundleIndex );
1764+ }
17131765 }
17141766}
17151767
@@ -1733,7 +1785,16 @@ static void ParsePhysicalMap( shaderStage_t *stage, const char **text, const int
17331785
17341786 if ( ParseMap ( text, buffer, sizeof ( buffer ) ) )
17351787 {
1736- LoadMap ( stage, buffer, stageType_t::ST_PHYSICALMAP, bundleIndex );
1788+ stageType_t stageType = stageType_t::ST_PHYSICALMAP;
1789+
1790+ if ( bundleIndex == TB_PHYSICALMAP )
1791+ {
1792+ DelayMapLoading ( buffer, stageType, bundleIndex );
1793+ }
1794+ else
1795+ {
1796+ LoadMap ( stage, buffer, stageType, bundleIndex );
1797+ }
17371798 }
17381799}
17391800
@@ -1745,7 +1806,16 @@ static void ParseGlowMap( shaderStage_t *stage, const char **text, const int bun
17451806
17461807 if ( ParseMap ( text, buffer, sizeof ( buffer ) ) )
17471808 {
1748- LoadMap ( stage, buffer, stageType_t::ST_GLOWMAP, bundleIndex );
1809+ stageType_t stageType = stageType_t::ST_GLOWMAP;
1810+
1811+ if ( bundleIndex == TB_GLOWMAP )
1812+ {
1813+ DelayMapLoading ( buffer, stageType, bundleIndex );
1814+ }
1815+ else
1816+ {
1817+ LoadMap ( stage, buffer, stageType, bundleIndex );
1818+ }
17491819 }
17501820}
17511821
@@ -2010,6 +2080,8 @@ static bool ParseStage( shaderStage_t *stage, const char **text )
20102080 char buffer[ 1024 ] = " " ;
20112081 bool loadMap = false ;
20122082
2083+ memset ( delayedStageTextures, 0 , sizeof ( delayedStageTextures ) );
2084+
20132085 while ( true )
20142086 {
20152087 token = COM_ParseExt2 ( text, true );
@@ -3273,8 +3345,35 @@ static bool ParseStage( shaderStage_t *stage, const char **text )
32733345 return true ;
32743346 }
32753347
3276- // load image
3277- if ( loadMap && !LoadMap ( stage, buffer, stage->type ) )
3348+ /* If there is more than one colormap, it's a mistake anyway,
3349+ so we don't care about the possibility it overwrites one. */
3350+ if ( loadMap )
3351+ {
3352+ DelayMapLoading ( buffer, stage->type , TB_COLORMAP );
3353+ }
3354+
3355+ /* Make sure we report for the successful loading of all kind
3356+ of colormaps like diffusemap… */
3357+ loadMap = delayedStageTextures[ TB_COLORMAP ].active ;
3358+
3359+ for ( int bundleIndex = 0 ; bundleIndex < MAX_TEXTURE_BUNDLES; bundleIndex++ )
3360+ {
3361+ auto & delayedStageTexture = delayedStageTextures[ bundleIndex ];
3362+
3363+ if ( !delayedStageTexture.active )
3364+ {
3365+ continue ;
3366+ }
3367+
3368+ Log::Debug (" Loading delayed texture %s" , delayedStageTexture.path );
3369+
3370+ // Reuse the boolean to report if the texture was sucessfully loaded or not.
3371+ delayedStageTexture.active =
3372+ LoadMap ( stage, delayedStageTexture.path , delayedStageTexture.type , bundleIndex );
3373+ }
3374+
3375+ // Check if the colormap loaded, if it is required for it to be loaded.
3376+ if ( loadMap && !delayedStageTextures[ TB_COLORMAP ].active )
32783377 {
32793378 return false ;
32803379 }
0 commit comments