@@ -1054,30 +1054,44 @@ void R_UploadImage( const char *name, const byte **dataArray, int numLayers, int
10541054 }
10551055 else
10561056 {
1057- // scan the texture for each channel's max values
1058- // and verify if the alpha channel is being used or not
1057+ // lightmap does not have alpha channel
1058+ if ( image->bits & IF_LIGHTMAP )
1059+ {
1060+ internalFormat = GL_RGB8;
1061+ }
1062+ else
1063+ {
1064+ internalFormat = GL_RGBA8;
1065+ }
1066+ }
10591067
1060- c = image->width * image->height ;
1061- scan = dataArray[0 ];
1068+ // Detect formats.
1069+ if ( dataArray )
1070+ {
1071+ if ( internalFormat == GL_RGBA8 )
1072+ {
1073+ // scan the texture for each channel's max values
1074+ // and verify if the alpha channel is being used or not
10621075
1063- // lightmap does not have alpha channel
1076+ c = image->width * image->height ;
1077+ scan = dataArray[0 ];
10641078
1065- // normalmap may have the heightmap in the alpha channel
1066- // opaque alpha channel means no displacement, so we can enable
1067- // alpha channel everytime it is used, even for normalmap
1079+ // normalmap may have the heightmap in the alpha channel
1080+ // opaque alpha channel means no displacement, so we can enable
1081+ // alpha channel everytime it is used, even for normalmap
10681082
1069- internalFormat = GL_RGB8 ;
1083+ bool hasAlpha = false ;
10701084
1071- if ( !( image->bits & IF_LIGHTMAP ) )
1072- {
1073- for ( i = 0 ; i < c; i++ )
1085+ for ( i = 0 ; i < c * 4 ; i += 4 )
10741086 {
1075- if ( scan[ i * 4 + 3 ] != 255 )
1087+ if ( scan[ i + 3 ] != 255 )
10761088 {
1077- internalFormat = GL_RGBA8 ;
1089+ hasAlpha = true ;
10781090 break ;
10791091 }
10801092 }
1093+
1094+ internalFormat = hasAlpha ? GL_RGBA8 : GL_RGB8;
10811095 }
10821096 }
10831097
0 commit comments