@@ -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,6 +948,18 @@ void R_UploadImage( const char *name, const byte **dataArray, int numLayers, int
946948 internalFormat = GL_RED;
947949 }
948950 }
951+ else if ( image->bits & IF_RG )
952+ {
953+ if ( isSRGB && !glConfig.textureSrgbRG8Available )
954+ {
955+ Log::Warn (" red-green image '%s' cannot be loaded as sRGB" , image->name );
956+ internalFormat = GL_RGB8;
957+ }
958+ else
959+ {
960+ internalFormat = GL_RG8;
961+ }
962+ }
949963 else if ( image->bits & ( IF_RGBA16F | IF_RGBA32F | IF_TWOCOMP16F | IF_TWOCOMP32F | IF_ONECOMP16F | IF_ONECOMP32F ) )
950964 {
951965 if ( !glConfig.textureFloatAvailable ) {
@@ -1091,31 +1105,59 @@ void R_UploadImage( const char *name, const byte **dataArray, int numLayers, int
10911105
10921106 if ( internalFormat == GL_RGB8 )
10931107 {
1094- if ( isSRGB && !glConfig.textureSrgbR8Available )
1095- {
1096- break ;
1097- }
1098-
10991108 /* Scan the texture for green and blue channels' max values
11001109 and verify if the green and blue channels are being used or not. */
11011110
11021111 c = image->width * image->height ;
11031112 scan = dataArray[0 ];
11041113
1105- internalFormat = GL_RED;
1114+ internalFormat = glConfig.textureRGAvailable ? GL_R8 : GL_RED;
1115+
1116+ bool hasGreen = false ;
1117+ bool hasBlue = false ;
11061118
11071119 for ( i = 0 ; i < c * 4 ; i += 4 )
11081120 {
1109- if ( scan[ i + 1 ] != 0 )
1121+ if ( scan[ i + 2 ] != 0 )
11101122 {
1111- internalFormat = GL_RGB8 ;
1123+ hasBlue = true ;
11121124 break ;
11131125 }
11141126
1115- if ( scan[ i + 2 ] != 0 )
1127+ if ( scan[ i + 1 ] != 0 )
1128+ {
1129+ hasGreen = true ;
1130+
1131+ if ( !glConfig.textureRGAvailable )
1132+ {
1133+ break ;
1134+ }
1135+ }
1136+ }
1137+
1138+ if ( hasBlue )
1139+ {
1140+ if ( isSRGB && !glConfig.textureSrgbR8Available )
1141+ {
1142+ internalFormat = GL_R8;
1143+ }
1144+ else
11161145 {
11171146 internalFormat = GL_RGB8;
1118- break ;
1147+ }
1148+ }
1149+ else if ( hasGreen )
1150+ {
1151+ if ( glConfig.textureRGAvailable )
1152+ {
1153+ if ( isSRGB && !glConfig.textureSrgbRG8Available )
1154+ {
1155+ internalFormat = GL_RGB8;
1156+ }
1157+ else
1158+ {
1159+ internalFormat = GL_RG8;
1160+ }
11191161 }
11201162 }
11211163 }
@@ -2812,8 +2854,15 @@ void R_CreateBuiltinImages()
28122854
28132855 imageParams.bits = IF_NOPICMIP;
28142856
2857+ if ( glConfig.textureRGAvailable )
2858+ {
2859+ imageParams.bits |= IF_RG;
2860+ }
2861+
28152862 tr.greenImage = R_CreateImage ( " _green" , ( const byte ** ) &dataPtr, DIMENSION, DIMENSION, 1 , imageParams );
28162863
2864+ imageParams.bits = IF_NOPICMIP;
2865+
28172866 // blue
28182867 for ( x = DIMENSION * DIMENSION, out = data; x; --x, out += 4 )
28192868 {
0 commit comments