@@ -350,33 +350,27 @@ ALIGNED( 16, shaderCommands_t tess );
350350GetLightMap
351351=================
352352*/
353- static image_t * GetLightMap ( bool noLightMap )
353+ static image_t * GetLightMap ()
354354{
355- image_t *lightmap;
356-
357- if ( noLightMap )
355+ if ( !tr.lightmaps .currentElements )
358356 {
359- lightmap = nullptr ;
357+ return tr. whiteImage ;
360358 }
361359 else if ( tr.fatLightmap )
362360 {
363- lightmap = tr.fatLightmap ;
361+ return tr.fatLightmap ;
364362 }
365363 else if ( tess.lightmapNum >= 0 && tess.lightmapNum < tr.lightmaps .currentElements )
366364 {
365+ // TODO: Check if this test is needed.
366+ image_t *lightmap;
367367 lightmap = ( image_t * ) Com_GrowListElement ( &tr.lightmaps , tess.lightmapNum );
368+ return lightmap == nullptr ? tr.whiteImage : lightmap;
368369 }
369370 else
370- {
371- lightmap = nullptr ;
372- }
373-
374- if ( !tr.lightmaps .currentElements || !lightmap )
375371 {
376372 return tr.whiteImage ;
377373 }
378-
379- return lightmap;
380374}
381375
382376/*
@@ -386,23 +380,22 @@ GetDeluxeMap
386380*/
387381static image_t * GetDeluxeMap ()
388382{
389- image_t *deluxemap;
390383
391- if ( tess. lightmapNum >= 0 && tess. lightmapNum < tr.deluxemaps .currentElements )
384+ if ( ! tr.deluxemaps .currentElements )
392385 {
393- deluxemap = ( image_t * ) Com_GrowListElement ( & tr.deluxemaps , tess. lightmapNum ) ;
386+ return tr.blackImage ;
394387 }
395- else
388+ else if ( tess. lightmapNum >= 0 && tess. lightmapNum < tr. deluxemaps . currentElements )
396389 {
397- deluxemap = nullptr ;
390+ // TODO: Check if this test is needed.
391+ image_t *deluxemap;
392+ deluxemap = ( image_t * ) Com_GrowListElement ( &tr.deluxemaps , tess.lightmapNum );
393+ return deluxemap == nullptr ? tr.blackImage : deluxemap;
398394 }
399-
400- if ( !tr.deluxemaps .currentElements || !deluxemap )
395+ else
401396 {
402397 return tr.blackImage ;
403398 }
404-
405- return deluxemap;
406399}
407400
408401/*
@@ -735,6 +728,10 @@ static void Render_lightMapping( int stage )
735728 && tess.bspSurface \
736729 && tr.worldDeluxeMapping ;
737730
731+ bool noLightMap = !pStage->implicitLightmap
732+ && (tess.surfaceShader ->surfaceFlags & SURF_NOLIGHTMAP)
733+ && !(tess.numSurfaceStages > 0 && tess.surfaceStages [0 ]->rgbGen == colorGen_t::CGEN_VERTEX);
734+
738735 bool isWorldEntity = backEnd.currentEntity == &tr.worldEntity ;
739736
740737 uint32_t stateBits = pStage->stateBits ;
@@ -774,6 +771,47 @@ static void Render_lightMapping( int stage )
774771 break ;
775772 }
776773
774+ // u_LightMap, u_DeluxeMap
775+ image_t *lightmap;
776+ image_t *deluxemap;
777+
778+ if ( noLightMap )
779+ {
780+ lightmap = tr.whiteImage ;
781+ enableLightMapping = true ;
782+ }
783+ else if ( enableLightMapping )
784+ {
785+ lightmap = GetLightMap ();
786+ }
787+ else if ( tr.lightGrid1Image )
788+ {
789+ // Store lightGrid1 as lightmap,
790+ // the GLSL code will know to deal with it.
791+ lightmap = tr.lightGrid1Image ;
792+ }
793+ else
794+ {
795+ lightmap = tr.whiteImage ;
796+ enableLightMapping = true ;
797+ }
798+
799+ if ( enableDeluxeMapping )
800+ {
801+ deluxemap = GetDeluxeMap ();
802+ }
803+ else if ( tr.lightGrid2Image )
804+ {
805+ // Store lightGrid2 as deluxemap,
806+ // the GLSL code will know to deal with it.
807+ deluxemap = tr.lightGrid2Image ;
808+ }
809+ else
810+ {
811+ deluxemap = tr.blackImage ;
812+ enableDeluxeMapping = true ;
813+ }
814+
777815 // choose right shader program ----------------------------------
778816 tess.vboVertexSprite = false ;
779817
@@ -1009,40 +1047,10 @@ static void Render_lightMapping( int stage )
10091047 }
10101048
10111049 // bind u_LightMap
1012- if ( enableLightMapping )
1013- {
1014- bool noLightMap = !pStage->implicitLightmap
1015- && (tess.surfaceShader ->surfaceFlags & SURF_NOLIGHTMAP)
1016- && !(tess.numSurfaceStages > 0 && tess.surfaceStages [0 ]->rgbGen == colorGen_t::CGEN_VERTEX);
1017-
1018- image_t *lightmap = GetLightMap ( noLightMap );
1019- GL_BindToTMU ( BIND_LIGHTMAP, lightmap );
1020- }
1021- else if ( tr.lightGrid1Image )
1022- {
1023- // FIXME: enable lightmapping with whiteImage if not tr.lightGrid1Image
1024- GL_BindToTMU ( BIND_LIGHTMAP, tr.lightGrid1Image );
1025- }
1026- else
1027- {
1028- GL_BindToTMU ( BIND_LIGHTMAP, tr.whiteImage );
1029- }
1050+ GL_BindToTMU ( BIND_LIGHTMAP, lightmap );
10301051
10311052 // bind u_DeluxeMap
1032- if ( enableDeluxeMapping )
1033- {
1034- image_t *deluxemap = GetDeluxeMap ();
1035- GL_BindToTMU ( BIND_DELUXEMAP, deluxemap );
1036- }
1037- else if ( tr.lightGrid2Image )
1038- {
1039- // FIXME: enable deluxemapping with blackImage if not tr.lightGrid2Image
1040- GL_BindToTMU ( BIND_DELUXEMAP, tr.lightGrid2Image );
1041- }
1042- else
1043- {
1044- GL_BindToTMU ( BIND_DELUXEMAP, tr.blackImage );
1045- }
1053+ GL_BindToTMU ( BIND_DELUXEMAP, deluxemap );
10461054
10471055 // bind u_GlowMap
10481056 GL_BindToTMU ( BIND_GLOWMAP, pStage->bundle [ TB_GLOWMAP ].image [ 0 ] );
0 commit comments