Skip to content

Commit 6e38dad

Browse files
committed
tr_image: detect RED images
1 parent 0119903 commit 6e38dad

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/engine/renderer/tr_image.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,8 +1090,37 @@ void R_UploadImage( const char *name, const byte **dataArray, int numLayers, int
10901090
break;
10911091
}
10921092
}
1093+
}
1094+
1095+
if ( internalFormat == GL_RGB8 )
1096+
{
1097+
if ( isSRGB && !glConfig.textureSrgbR8Available )
1098+
{
1099+
break;
1100+
}
1101+
1102+
/* Scan the texture for green and blue channels' max values
1103+
and verify if the green and blue channels are being used or not. */
1104+
1105+
c = image->width * image->height;
1106+
scan = dataArray[0];
1107+
1108+
internalFormat = GL_RED;
10931109

1094-
internalFormat = hasAlpha ? GL_RGBA8 : GL_RGB8;
1110+
for ( i = 0; i < c * 4; i += 4 )
1111+
{
1112+
if ( scan[ i + 1 ] != 0 )
1113+
{
1114+
internalFormat = GL_RGB8;
1115+
break;
1116+
}
1117+
1118+
if ( scan[ i + 2 ] != 0 )
1119+
{
1120+
internalFormat = GL_RGB8;
1121+
break;
1122+
}
1123+
}
10951124
}
10961125
}
10971126

0 commit comments

Comments
 (0)