engine: fix palette and builtin textures on BE

This commit is contained in:
Alibek Omarov
2026-04-25 02:33:24 +05:00
committed by a1batross
parent 22391eba1b
commit e30ce9c150
3 changed files with 25 additions and 52 deletions

View File

@@ -243,6 +243,9 @@ typedef int qboolean;
#define Swap32Store( x ) ( x = Swap32( x ))
#define Swap16Store( x ) ( x = Swap16( x ))
#define LittleFourCC( a, b, c, d ) (((uint32_t)( d ) << 24 ) | ((uint32_t)( c ) << 16 ) | ((uint32_t)( b ) << 8 ) | (uint32_t)( a ))
#define BigFourCC( a, b, c, d ) (((uint32_t)( a ) << 24 ) | ((uint32_t)( b ) << 16 ) | ((uint32_t)( c ) << 8 ) | (uint32_t)( d ))
#if XASH_BIG_ENDIAN
#define LittleLong( x ) Swap32( x )
#define LittleShort( x ) Swap16( x )
@@ -252,6 +255,7 @@ typedef int qboolean;
#define BigLong( x ) ( x )
#define BigShort( x ) ( x )
#define BigFloat( x ) ( x )
#define HostFourCC( a, b, c, d ) BigFourCC( a, b, c, d )
#else
#define LittleLong( x ) ( x )
#define LittleShort( x ) ( x )
@@ -261,6 +265,7 @@ typedef int qboolean;
#define BigLong( x ) Swap32( x )
#define BigShort( x ) Swap16( x )
#define BigFloat( x ) SwapFloat( x )
#define HostFourCC( a, b, c, d ) LittleFourCC( a, b, c, d )
#endif
#endif // XASH_TYPES_H

View File

@@ -505,9 +505,9 @@ static void R_CreateBuiltinTextures( void )
for( int x = 0; x < 16; x++ )
{
if(( y < 8 ) ^ ( x < 8 ))
data16x16[y * 16 + x] = 0xFFFF00FF;
data16x16[y * 16 + x] = HostFourCC( 255, 0, 255, 255 );
else
data16x16[y * 16 + x] = 0xFF000000;
data16x16[y * 16 + x] = HostFourCC( 0, 0, 0, 255 );
}
}
ref.dllFuncs.GL_CreateTexture( REF_DEFAULT_TEXTURE, 16, 16, data16x16, 0 );
@@ -517,7 +517,7 @@ static void R_CreateBuiltinTextures( void )
for( int y = 0; y < 8; y++ )
{
for( int x = 0; x < 8; x++ )
particle[y * 8 + x] = 0x00FFFFFF; // fill it with invisible white
particle[y * 8 + x] = HostFourCC( 255, 255, 255, 0 ); // fill it with invisible white
}
// a1ba: moved one pixel down and to the right to make it look better with linear interpolation
@@ -530,7 +530,7 @@ static void R_CreateBuiltinTextures( void )
if(( x == corner || x == 3 + corner ) && ( y == corner || y == 3 + corner ))
continue;
particle[y * 8 + x] = 0xFFFFFFFF;
particle[y * 8 + x] = HostFourCC( 255, 255, 255, 255 );
}
}
ref.dllFuncs.GL_CreateTexture( REF_PARTICLE_TEXTURE, 8, 8, particle, TF_CLAMP|TF_HAS_ALPHA );
@@ -541,11 +541,11 @@ static void R_CreateBuiltinTextures( void )
ref.dllFuncs.GL_CreateTexture( REF_WHITE_TEXTURE, 4, 4, data4x4, 0 );
for( int x = 0; x < 16; x++ )
data4x4[x] = 0xFF7F7F7F;
data4x4[x] = HostFourCC( 127, 127, 127, 255 );
ref.dllFuncs.GL_CreateTexture( REF_GRAY_TEXTURE, 4, 4, data4x4, 0 );
for( int x = 0; x < 16; x++ )
data4x4[x] = 0xFF000000;
data4x4[x] = HostFourCC( 0, 0, 0, 255 );
ref.dllFuncs.GL_CreateTexture( REF_BLACK_TEXTURE, 4, 4, data4x4, 0 );
}

View File

@@ -285,66 +285,34 @@ int Image_ComparePalette( const byte *pal )
static void Image_SetPalette( const byte *pal, uint *d_table )
{
byte rgba[4];
uint uirgba; // TODO: palette looks byte-swapped on big-endian
int i;
// setup palette
switch( image.d_rendermode )
{
case LUMP_NORMAL:
for( i = 0; i < 256; i++ )
{
memcpy( rgba, &pal[i * 3], 3 );
rgba[3] = 0xFF;
memcpy( &uirgba, rgba, sizeof( uirgba ));
d_table[i] = uirgba;
}
for( int i = 0; i < 256; i++ )
d_table[i] = HostFourCC( pal[i * 3 + 0], pal[i * 3 + 1], pal[i * 3 + 2], 0xFF );
break;
case LUMP_TEXGAMMA:
for( i = 0; i < 256; i++ )
for( int 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;
memcpy( &uirgba, rgba, sizeof( uirgba ));
d_table[i] = uirgba;
d_table[i] = HostFourCC(
TextureToGamma( pal[i * 3 + 0] ),
TextureToGamma( pal[i * 3 + 1] ),
TextureToGamma( pal[i * 3 + 2] ),
0xFF );
}
break;
case LUMP_GRADIENT:
for( i = 0; i < 256; i++ )
{
rgba[0] = pal[765];
rgba[1] = pal[766];
rgba[2] = pal[767];
rgba[3] = i;
memcpy( &uirgba, rgba, sizeof( uirgba ));
d_table[i] = uirgba;
}
for( int i = 0; i < 256; i++ )
d_table[i] = HostFourCC( pal[765], pal[766], pal[767], i );
break;
case LUMP_MASKED:
for( i = 0; i < 255; i++ )
{
rgba[0] = pal[i*3+0];
rgba[1] = pal[i*3+1];
rgba[2] = pal[i*3+2];
rgba[3] = 0xFF;
memcpy( &uirgba, rgba, sizeof( uirgba ));
d_table[i] = uirgba;
}
for( int i = 0; i < 255; i++ )
d_table[i] = HostFourCC( pal[i * 3 + 0], pal[i * 3 + 1], pal[i * 3 + 2], 0xFF );
d_table[255] = 0;
break;
case LUMP_EXTENDED:
for( i = 0; i < 256; i++ )
{
rgba[0] = pal[i*4+0];
rgba[1] = pal[i*4+1];
rgba[2] = pal[i*4+2];
rgba[3] = pal[i*4+3];
memcpy( &uirgba, rgba, sizeof( uirgba ));
d_table[i] = uirgba;
}
for( int i = 0; i < 256; i++ )
d_table[i] = HostFourCC( pal[i * 4 + 0], pal[i * 4 + 1], pal[i * 4 + 2], pal[i * 4 + 3] );
break;
}
}