@@ -177,10 +177,12 @@ class ListImagesCmd : public Cmd::StaticCmd
177177 { GL_RGBA32UI, { " RGBA32UI" , 16 } },
178178 { GL_ALPHA16F_ARB, { " A16F" , 2 } },
179179 { GL_ALPHA32F_ARB, { " A32F" , 4 } },
180+ { GL_R8, { " R8" , 1 } },
180181 { GL_R16F, { " R16F" , 2 } },
181182 { GL_R32F, { " R32F" , 4 } },
182183 { GL_LUMINANCE_ALPHA16F_ARB, { " LA16F" , 4 } },
183184 { GL_LUMINANCE_ALPHA32F_ARB, { " LA32F" , 8 } },
185+ { GL_RG8, { " RG8" , 2 } },
184186 { GL_RG16F, { " RG16F" , 4 } },
185187 { GL_RG32F, { " RG32F" , 8 } },
186188
@@ -946,7 +948,19 @@ void R_UploadImage( const char *name, const byte **dataArray, int numLayers, int
946948 }
947949 else
948950 {
949- internalFormat = GL_RED;
951+ internalFormat = glConfig.textureSrgbRG8Available ? GL_R8 : GL_RED;
952+ }
953+ }
954+ else if ( image->bits & IF_RG )
955+ {
956+ if ( isSRGB && !glConfig.textureSrgbRG8Available )
957+ {
958+ Log::Warn (" red-green image '%s' cannot be loaded as sRGB" , image->name );
959+ internalFormat = GL_RGB8;
960+ }
961+ else
962+ {
963+ internalFormat = GL_RG8;
950964 }
951965 }
952966 else if ( image->bits & ( IF_RGBA16F | IF_RGBA32F | IF_TWOCOMP16F | IF_TWOCOMP32F | IF_ONECOMP16F | IF_ONECOMP32F ) )
@@ -1094,31 +1108,70 @@ void R_UploadImage( const char *name, const byte **dataArray, int numLayers, int
10941108
10951109 if ( internalFormat == GL_RGB8 )
10961110 {
1097- if ( isSRGB && !glConfig.textureSrgbR8Available )
1098- {
1099- break ;
1100- }
1101-
11021111 /* Scan the texture for green and blue channels' max values
11031112 and verify if the green and blue channels are being used or not. */
11041113
11051114 c = image->width * image->height ;
11061115 scan = dataArray[0 ];
11071116
1108- internalFormat = GL_RED;
1117+ bool hasGreen = false ;
1118+ bool hasBlue = false ;
11091119
11101120 for ( i = 0 ; i < c * 4 ; i += 4 )
11111121 {
1112- if ( scan[ i + 1 ] != 0 )
1122+ if ( scan[ i + 2 ] != 0 )
11131123 {
1114- internalFormat = GL_RGB8;
1124+ // We need GL_RGB8.
1125+ hasBlue = true ;
11151126 break ;
11161127 }
11171128
1118- if ( scan[ i + 2 ] != 0 )
1129+ if ( scan[ i + 1 ] != 0 )
11191130 {
1120- internalFormat = GL_RGB8;
1121- break ;
1131+ hasGreen = true ;
1132+
1133+ if ( !glConfig.textureRGAvailable )
1134+ {
1135+ // We can't store RG so we can stop there and use GL_RGB8.
1136+ break ;
1137+ }
1138+ // Else continue to make sure there is no blue at all.
1139+ }
1140+
1141+ // Else use GL_RED or GL_R8.
1142+ }
1143+
1144+ if ( hasBlue )
1145+ {
1146+ // Keep GL_RGB8.
1147+ }
1148+ else if ( hasGreen )
1149+ {
1150+ if ( !glConfig.textureRGAvailable )
1151+ {
1152+ // Keep GL_RGB8.
1153+ }
1154+ else
1155+ {
1156+ if ( isSRGB && !glConfig.textureSrgbRG8Available )
1157+ {
1158+ // Keep GL_RGB8.
1159+ }
1160+ else
1161+ {
1162+ internalFormat = GL_RG8;
1163+ }
1164+ }
1165+ }
1166+ else
1167+ {
1168+ if ( isSRGB && !glConfig.textureSrgbR8Available )
1169+ {
1170+ // Keep GL_RGB8.
1171+ }
1172+ else
1173+ {
1174+ internalFormat = glConfig.textureRGAvailable ? GL_R8 : GL_RED;
11221175 }
11231176 }
11241177 }
@@ -2815,8 +2868,15 @@ void R_CreateBuiltinImages()
28152868
28162869 imageParams.bits = IF_NOPICMIP;
28172870
2871+ if ( glConfig.textureRGAvailable )
2872+ {
2873+ imageParams.bits |= IF_RG;
2874+ }
2875+
28182876 tr.greenImage = R_CreateImage ( " _green" , ( const byte ** ) &dataPtr, DIMENSION, DIMENSION, 1 , imageParams );
28192877
2878+ imageParams.bits = IF_NOPICMIP;
2879+
28202880 // blue
28212881 for ( x = DIMENSION * DIMENSION, out = data; x; --x, out += 4 )
28222882 {
0 commit comments