@@ -1591,6 +1591,14 @@ static bool ParseClampType( const char *token, wrapType_t *clamp )
15911591 return true ;
15921592}
15931593
1594+ static void DelayMapLoading ( shaderStage_t *stage, const char * texturePath, const stageType_t stageType, const int bundleIndex )
1595+ {
1596+ Log::Debug (" Delaying the loading of texture %s" , texturePath );
1597+ strncpy ( stage->collapsedStageTextures [ bundleIndex ], texturePath, MAX_QPATH - 1 );
1598+ stage->collapsedStageTypes [ bundleIndex ] = stageType;
1599+ stage->collapsedStages [ bundleIndex ] = true ;
1600+ }
1601+
15941602/*
15951603===================
15961604ParseDifuseMap
@@ -1603,7 +1611,16 @@ static void ParseDiffuseMap( shaderStage_t *stage, const char **text, const int
16031611
16041612 if ( ParseMap ( text, buffer, sizeof ( buffer ) ) )
16051613 {
1606- LoadMap ( stage, buffer, stageType_t::ST_DIFFUSEMAP, bundleIndex );
1614+ stageType_t stageType = stageType_t::ST_DIFFUSEMAP;
1615+
1616+ if ( bundleIndex == TB_DIFFUSEMAP )
1617+ {
1618+ DelayMapLoading ( stage, buffer, stageType, bundleIndex );
1619+ }
1620+ else
1621+ {
1622+ LoadMap ( stage, buffer, stageType, bundleIndex );
1623+ }
16071624 }
16081625}
16091626
@@ -1632,7 +1649,16 @@ static void ParseNormalMap( shaderStage_t *stage, const char **text, const int b
16321649
16331650 if ( ParseMap ( text, buffer, sizeof ( buffer ) ) )
16341651 {
1635- LoadMap ( stage, buffer, stageType_t::ST_NORMALMAP, bundleIndex );
1652+ stageType_t stageType = stageType_t::ST_NORMALMAP;
1653+
1654+ if ( bundleIndex == TB_NORMALMAP )
1655+ {
1656+ DelayMapLoading ( stage, buffer, stageType, bundleIndex );
1657+ }
1658+ else
1659+ {
1660+ LoadMap ( stage, buffer, stageType, bundleIndex );
1661+ }
16361662 }
16371663}
16381664
@@ -1697,7 +1723,16 @@ static void ParseHeightMap( shaderStage_t *stage, const char **text, const int b
16971723
16981724 if ( ParseMap ( text, buffer, sizeof ( buffer ) ) )
16991725 {
1700- LoadMap ( stage, buffer, stageType_t::ST_HEIGHTMAP, bundleIndex );
1726+ stageType_t stageType = stageType_t::ST_HEIGHTMAP;
1727+
1728+ if ( bundleIndex == TB_HEIGHTMAP )
1729+ {
1730+ DelayMapLoading ( stage, buffer, stageType, bundleIndex );
1731+ }
1732+ else
1733+ {
1734+ LoadMap ( stage, buffer, stageType, bundleIndex );
1735+ }
17011736 }
17021737}
17031738
@@ -1709,7 +1744,16 @@ static void ParseSpecularMap( shaderStage_t *stage, const char **text, const int
17091744
17101745 if ( ParseMap ( text, buffer, sizeof ( buffer ) ) )
17111746 {
1712- LoadMap ( stage, buffer, stageType_t::ST_SPECULARMAP, bundleIndex );
1747+ stageType_t stageType = stageType_t::ST_SPECULARMAP;
1748+
1749+ if ( bundleIndex == TB_SPECULARMAP )
1750+ {
1751+ DelayMapLoading ( stage, buffer, stageType, bundleIndex );
1752+ }
1753+ else
1754+ {
1755+ LoadMap ( stage, buffer, stageType, bundleIndex );
1756+ }
17131757 }
17141758}
17151759
@@ -1733,7 +1777,16 @@ static void ParsePhysicalMap( shaderStage_t *stage, const char **text, const int
17331777
17341778 if ( ParseMap ( text, buffer, sizeof ( buffer ) ) )
17351779 {
1736- LoadMap ( stage, buffer, stageType_t::ST_PHYSICALMAP, bundleIndex );
1780+ stageType_t stageType = stageType_t::ST_PHYSICALMAP;
1781+
1782+ if ( bundleIndex == TB_PHYSICALMAP )
1783+ {
1784+ DelayMapLoading ( stage, buffer, stageType, bundleIndex );
1785+ }
1786+ else
1787+ {
1788+ LoadMap ( stage, buffer, stageType, bundleIndex );
1789+ }
17371790 }
17381791}
17391792
@@ -1745,7 +1798,16 @@ static void ParseGlowMap( shaderStage_t *stage, const char **text, const int bun
17451798
17461799 if ( ParseMap ( text, buffer, sizeof ( buffer ) ) )
17471800 {
1748- LoadMap ( stage, buffer, stageType_t::ST_GLOWMAP, bundleIndex );
1801+ stageType_t stageType = stageType_t::ST_GLOWMAP;
1802+
1803+ if ( bundleIndex == TB_GLOWMAP )
1804+ {
1805+ DelayMapLoading ( stage, buffer, stageType, bundleIndex );
1806+ }
1807+ else
1808+ {
1809+ LoadMap ( stage, buffer, stageType, bundleIndex );
1810+ }
17491811 }
17501812}
17511813
@@ -3273,6 +3335,25 @@ static bool ParseStage( shaderStage_t *stage, const char **text )
32733335 return true ;
32743336 }
32753337
3338+ for ( int bundleIndex = 0 ; bundleIndex < MAX_TEXTURE_BUNDLES; bundleIndex++ )
3339+ {
3340+ if ( !stage->collapsedStages [ bundleIndex ] )
3341+ {
3342+ continue ;
3343+ }
3344+
3345+ if ( bundleIndex == TB_COLORMAP && loadMap )
3346+ {
3347+ continue ;
3348+ }
3349+
3350+ stageType_t collapsedStage = stage->collapsedStageTypes [ bundleIndex ];
3351+ char * texturePath = stage->collapsedStageTextures [ bundleIndex ];
3352+
3353+ Log::Debug (" Loading delayed texture %s" , texturePath );
3354+ LoadMap ( stage, texturePath, collapsedStage, bundleIndex );
3355+ }
3356+
32763357 // load image
32773358 if ( loadMap && !LoadMap ( stage, buffer, stage->type ) )
32783359 {
0 commit comments