Skip to content

Commit a441628

Browse files
committed
tr_image: rework the alpha detection
1 parent 4a6dfa5 commit a441628

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/engine/renderer/tr_image.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,32 +1053,42 @@ void R_UploadImage( const char *name, const byte **dataArray, int numLayers, int
10531053
internalFormat = GL_RGBA8;
10541054
}
10551055
else
1056+
{
1057+
// lightmap does not have alpha channel
1058+
if ( image->bits & IF_LIGHTMAP )
1059+
{
1060+
internalFormat = GL_RGB8;
1061+
}
1062+
else
1063+
{
1064+
internalFormat = GL_RGBA8;
1065+
}
1066+
}
1067+
1068+
if ( internalFormat == GL_RGBA8 )
10561069
{
10571070
// scan the texture for each channel's max values
10581071
// and verify if the alpha channel is being used or not
10591072

10601073
c = image->width * image->height;
10611074
scan = dataArray[0];
10621075

1063-
// lightmap does not have alpha channel
1064-
10651076
// normalmap may have the heightmap in the alpha channel
10661077
// opaque alpha channel means no displacement, so we can enable
10671078
// alpha channel everytime it is used, even for normalmap
10681079

1069-
internalFormat = GL_RGB8;
1080+
bool hasAlpha = false;
10701081

1071-
if ( !( image->bits & IF_LIGHTMAP ) )
1082+
for ( i = 0; i < c * 4; i += 4 )
10721083
{
1073-
for ( i = 0; i < c; i++ )
1084+
if ( scan[ i + 3 ] != 255 )
10741085
{
1075-
if ( scan[ i * 4 + 3 ] != 255 )
1076-
{
1077-
internalFormat = GL_RGBA8;
1078-
break;
1079-
}
1086+
hasAlpha = true;
1087+
break;
10801088
}
10811089
}
1090+
1091+
internalFormat = hasAlpha ? GL_RGBA8 : GL_RGB8;
10821092
}
10831093

10841094
Log::Debug( "Uploading image %s (%d×%d, %d layers, %0#x type, %0#x format)", name, scaledWidth, scaledHeight, numLayers, image->type, internalFormat );

0 commit comments

Comments
 (0)