engine: imagelib: add LUMP_TEXGAMMA palette kind to only pass HL textures through texgamma, not Quake

This commit is contained in:
Alibek Omarov 2024-07-19 06:34:48 +03:00
parent 42a915b04a
commit 85dfaaa2c2
3 changed files with 30 additions and 10 deletions

View file

@ -108,12 +108,13 @@ typedef struct imglib_s
enum enum
{ {
LUMP_NORMAL = 0, // no alpha LUMP_NORMAL = 0, // no alpha
LUMP_MASKED, // 1-bit alpha channel masked texture LUMP_MASKED, // 1-bit alpha channel masked texture
LUMP_GRADIENT, // gradient image (decals) LUMP_GRADIENT, // gradient image (decals)
LUMP_EXTENDED, // bmp images have extened palette with alpha-channel LUMP_EXTENDED, // bmp images have extened palette with alpha-channel
LUMP_HALFLIFE, // get predefined half-life palette LUMP_HALFLIFE, // get predefined half-life palette
LUMP_QUAKE1 // get predefined quake palette LUMP_QUAKE1, // get predefined quake palette
LUMP_TEXGAMMA, // apply texgamma on top of palette, for half-life mips
}; };
enum enum

View file

@ -293,9 +293,18 @@ static void Image_SetPalette( const byte *pal, uint *d_table )
case LUMP_NORMAL: case LUMP_NORMAL:
for( i = 0; i < 256; i++ ) for( i = 0; i < 256; i++ )
{ {
rgba[0] = TextureToGamma( pal[i*3+0] ); memcpy( rgba, &pal[i * 3], 3 );
rgba[1] = TextureToGamma( pal[i*3+1] ); rgba[3] = 0xFF;
rgba[2] = TextureToGamma( pal[i*3+2] ); memcpy( &uirgba, rgba, sizeof( uirgba ));
d_table[i] = uirgba;
}
break;
case LUMP_TEXGAMMA:
for( i = 0; i < 256; i++ )
{
rgba[0] = TextureToGamma( pal[i * 3 + 0] );
rgba[1] = TextureToGamma( pal[i * 3 + 1] );
rgba[2] = TextureToGamma( pal[i * 3 + 2] );
rgba[3] = 0xFF; rgba[3] = 0xFF;
memcpy( &uirgba, rgba, sizeof( uirgba )); memcpy( &uirgba, rgba, sizeof( uirgba ));
d_table[i] = uirgba; d_table[i] = uirgba;

View file

@ -427,8 +427,18 @@ qboolean Image_LoadMIP( const char *name, const byte *buffer, fs_offset_t filesi
} }
if( pal_type == PAL_QUAKE1 ) if( pal_type == PAL_QUAKE1 )
{
SetBits( image.flags, IMAGE_QUAKEPAL ); SetBits( image.flags, IMAGE_QUAKEPAL );
rendermode = LUMP_NORMAL;
// if texture was converted from quake to half-life with no palette changes
// then applying texgamma might make it too dark or even outright broken
rendermode = LUMP_NORMAL;
}
else
{
// half-life mips need texgamma applied
rendermode = LUMP_TEXGAMMA;
}
} }
Image_GetPaletteLMP( pal, rendermode ); Image_GetPaletteLMP( pal, rendermode );