@@ -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,59 @@ 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+ internalFormat = glConfig.textureRGAvailable ? GL_R8 : GL_RED;
1118+
1119+ bool hasGreen = false ;
1120+ bool hasBlue = false ;
11091121
11101122 for ( i = 0 ; i < c * 4 ; i += 4 )
11111123 {
1112- if ( scan[ i + 1 ] != 0 )
1124+ if ( scan[ i + 2 ] != 0 )
11131125 {
1114- internalFormat = GL_RGB8 ;
1126+ hasBlue = true ;
11151127 break ;
11161128 }
11171129
1118- if ( scan[ i + 2 ] != 0 )
1130+ if ( scan[ i + 1 ] != 0 )
1131+ {
1132+ hasGreen = true ;
1133+
1134+ if ( !glConfig.textureRGAvailable )
1135+ {
1136+ break ;
1137+ }
1138+ }
1139+ }
1140+
1141+ if ( hasBlue )
1142+ {
1143+ if ( isSRGB && !glConfig.textureSrgbR8Available )
1144+ {
1145+ internalFormat = GL_R8;
1146+ }
1147+ else
11191148 {
11201149 internalFormat = GL_RGB8;
1121- break ;
1150+ }
1151+ }
1152+ else if ( hasGreen )
1153+ {
1154+ if ( glConfig.textureRGAvailable )
1155+ {
1156+ if ( isSRGB && !glConfig.textureSrgbRG8Available )
1157+ {
1158+ internalFormat = GL_RGB8;
1159+ }
1160+ else
1161+ {
1162+ internalFormat = GL_RG8;
1163+ }
11221164 }
11231165 }
11241166 }
@@ -2815,8 +2857,15 @@ void R_CreateBuiltinImages()
28152857
28162858 imageParams.bits = IF_NOPICMIP;
28172859
2860+ if ( glConfig.textureRGAvailable )
2861+ {
2862+ imageParams.bits |= IF_RG;
2863+ }
2864+
28182865 tr.greenImage = R_CreateImage ( " _green" , ( const byte ** ) &dataPtr, DIMENSION, DIMENSION, 1 , imageParams );
28192866
2867+ imageParams.bits = IF_NOPICMIP;
2868+
28202869 // blue
28212870 for ( x = DIMENSION * DIMENSION, out = data; x; --x, out += 4 )
28222871 {
0 commit comments