Skip to content

Commit c0f2bf3

Browse files
committed
tr_image: detect RED images
1 parent 17dcadc commit c0f2bf3

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/engine/renderer/tr_image.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,31 @@ void R_UploadImage( const char *name, const byte **dataArray, int numLayers, int
10681068
// Detect formats.
10691069
if ( dataArray )
10701070
{
1071-
if ( internalFormat == GL_RGBA8 )
1071+
if ( internalFormat == GL_RGB8 )
1072+
{
1073+
c = image->width * image->height;
1074+
scan = dataArray[0];
1075+
1076+
bool hasRGB = false;
1077+
1078+
for ( i = 0; i < c * 4; i += 4 )
1079+
{
1080+
if ( scan[ i + 1 ] != 0 )
1081+
{
1082+
hasRGB = true;
1083+
break;
1084+
}
1085+
1086+
if ( scan[ i + 2 ] != 0 )
1087+
{
1088+
hasRGB = true;
1089+
break;
1090+
}
1091+
}
1092+
1093+
internalFormat = hasRGB ? GL_RGB8 : GL_RED;
1094+
}
1095+
else if ( internalFormat == GL_RGBA8 )
10721096
{
10731097
// scan the texture for each channel's max values
10741098
// and verify if the alpha channel is being used or not

0 commit comments

Comments
 (0)