mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
engine: common: imagelib: remove dependency on OpenGL declarations in texture formats
This commit is contained in:
@@ -38,11 +38,20 @@ typedef enum
|
|||||||
PF_TOTALCOUNT, // must be last
|
PF_TOTALCOUNT, // must be last
|
||||||
} pixformat_t;
|
} pixformat_t;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
RF_COMPRESSED,
|
||||||
|
RF_RGBA,
|
||||||
|
RF_BGRA,
|
||||||
|
RF_BGR,
|
||||||
|
RF_LUMINANCE
|
||||||
|
} rawformat_t;
|
||||||
|
|
||||||
typedef struct bpc_desc_s
|
typedef struct bpc_desc_s
|
||||||
{
|
{
|
||||||
int format; // pixelformat
|
int format; // pixelformat
|
||||||
char name[16]; // used for debug
|
char name[16]; // used for debug
|
||||||
uint glFormat; // RGBA format
|
rawformat_t rawformat;
|
||||||
int bpp; // channels (e.g. rgb = 3, rgba = 4)
|
int bpp; // channels (e.g. rgb = 3, rgba = 4)
|
||||||
} bpc_desc_t;
|
} bpc_desc_t;
|
||||||
|
|
||||||
|
|||||||
@@ -493,7 +493,6 @@ void FS_FreeImage( rgbdata_t *pack );
|
|||||||
rgbdata_t *FS_LoadImage( const char *filename, const byte *buffer, size_t size ) MALLOC_LIKE( FS_FreeImage, 1 ) WARN_UNUSED_RESULT;
|
rgbdata_t *FS_LoadImage( const char *filename, const byte *buffer, size_t size ) MALLOC_LIKE( FS_FreeImage, 1 ) WARN_UNUSED_RESULT;
|
||||||
qboolean FS_SaveImage( const char *filename, rgbdata_t *pix );
|
qboolean FS_SaveImage( const char *filename, rgbdata_t *pix );
|
||||||
rgbdata_t *FS_CopyImage( const rgbdata_t *in ) MALLOC_LIKE( FS_FreeImage, 1 ) WARN_UNUSED_RESULT;
|
rgbdata_t *FS_CopyImage( const rgbdata_t *in ) MALLOC_LIKE( FS_FreeImage, 1 ) WARN_UNUSED_RESULT;
|
||||||
extern const bpc_desc_t PFDesc[]; // image get pixelformat
|
|
||||||
qboolean Image_Process( rgbdata_t **pix, int width, int height, uint flags, float reserved );
|
qboolean Image_Process( rgbdata_t **pix, int width, int height, uint flags, float reserved );
|
||||||
void Image_PaletteHueReplace( byte *palSrc, int newHue, int start, int end, int pal_size );
|
void Image_PaletteHueReplace( byte *palSrc, int newHue, int start, int end, int pal_size );
|
||||||
void Image_SetForceFlags( uint flags ); // set image force flags on loading
|
void Image_SetForceFlags( uint flags ); // set image force flags on loading
|
||||||
@@ -502,6 +501,8 @@ void Image_ClearForceFlags( void );
|
|||||||
void Image_SetMDLPointer( byte *p );
|
void Image_SetMDLPointer( byte *p );
|
||||||
void Image_CheckPaletteQ1( void );
|
void Image_CheckPaletteQ1( void );
|
||||||
|
|
||||||
|
extern const bpc_desc_t PFDesc[PF_TOTALCOUNT]; // image get pixelformat
|
||||||
|
|
||||||
/*
|
/*
|
||||||
========================================================================
|
========================================================================
|
||||||
|
|
||||||
|
|||||||
@@ -74,20 +74,29 @@ static const cubepack_t load_cubemap[] =
|
|||||||
};
|
};
|
||||||
|
|
||||||
// soul of ImageLib - table of image format constants
|
// soul of ImageLib - table of image format constants
|
||||||
const bpc_desc_t PFDesc[] =
|
const bpc_desc_t PFDesc[PF_TOTALCOUNT] =
|
||||||
{
|
{
|
||||||
{ PF_UNKNOWN, "raw", 0x1908, 0 },
|
{ PF_UNKNOWN, "raw", RF_RGBA, 0 },
|
||||||
{ PF_INDEXED_24, "pal 24", 0x1908, 1 },
|
{ PF_INDEXED_24, "pal 24", RF_RGBA, 1 },
|
||||||
{ PF_INDEXED_32, "pal 32", 0x1908, 1 },
|
{ PF_INDEXED_32, "pal 32", RF_RGBA, 1 },
|
||||||
{ PF_RGBA_32, "RGBA 32",0x1908, 4 },
|
{ PF_RGBA_32, "RGBA 32", RF_RGBA, 4 },
|
||||||
{ PF_BGRA_32, "BGRA 32",0x80E1, 4 },
|
{ PF_BGRA_32, "BGRA 32", RF_BGRA, 4 },
|
||||||
{ PF_RGB_24, "RGB 24", 0x1908, 3 },
|
{ PF_RGB_24, "RGB 24", RF_RGBA, 3 },
|
||||||
{ PF_BGR_24, "BGR 24", 0x80E0, 3 },
|
{ PF_BGR_24, "BGR 24", RF_BGR, 3 },
|
||||||
{ PF_LUMINANCE, "LUM 8", 0x1909, 1 },
|
{ PF_LUMINANCE, "LUM 8", RF_LUMINANCE, 1 },
|
||||||
{ PF_DXT1, "DXT 1", 0x83F1, 4 },
|
{ PF_DXT1, "DXT 1", RF_COMPRESSED, 4 },
|
||||||
{ PF_DXT3, "DXT 3", 0x83F2, 4 },
|
{ PF_DXT3, "DXT 3", RF_COMPRESSED, 4 },
|
||||||
{ PF_DXT5, "DXT 5", 0x83F3, 4 },
|
{ PF_DXT5, "DXT 5", RF_COMPRESSED, 4 },
|
||||||
{ PF_ATI2, "ATI 2", 0x8837, 4 },
|
{ PF_ATI2, "ATI 2", RF_COMPRESSED, 4 },
|
||||||
|
{ PF_BC4_SIGNED, "BC4 S", RF_COMPRESSED, 4 },
|
||||||
|
{ PF_BC4_UNSIGNED, "BC4 U", RF_COMPRESSED, 4 },
|
||||||
|
{ PF_BC5_SIGNED, "BC5 S", RF_COMPRESSED, 4 },
|
||||||
|
{ PF_BC5_UNSIGNED, "BC5 U", RF_COMPRESSED, 4 },
|
||||||
|
{ PF_BC6H_SIGNED, "BC6H S", RF_COMPRESSED, 4 },
|
||||||
|
{ PF_BC6H_UNSIGNED, "BC6H U", RF_COMPRESSED, 4 },
|
||||||
|
{ PF_BC7_UNORM, "BC7 UNORM", RF_COMPRESSED, 4 },
|
||||||
|
{ PF_BC7_SRGB, "BC7 SRGB", RF_COMPRESSED, 4 },
|
||||||
|
{ PF_KTX2_RAW, "KTX2", RF_COMPRESSED, 4 },
|
||||||
};
|
};
|
||||||
|
|
||||||
#if DEBUG_LOOKUPS_COUNT
|
#if DEBUG_LOOKUPS_COUNT
|
||||||
|
|||||||
@@ -988,21 +988,41 @@ static void GL_BuildMipMap( byte *in, int srcWidth, int srcHeight, int srcDepth,
|
|||||||
|
|
||||||
static void GL_TextureImageRAW( gl_texture_t *tex, GLint side, GLint level, GLint width, GLint height, GLint depth, GLint type, const void *data )
|
static void GL_TextureImageRAW( gl_texture_t *tex, GLint side, GLint level, GLint width, GLint height, GLint depth, GLint type, const void *data )
|
||||||
{
|
{
|
||||||
GLuint cubeTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB;
|
const GLuint cubeTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB;
|
||||||
qboolean subImage = FBitSet( tex->flags, TF_IMG_UPLOADED ) && data != NULL;
|
const qboolean subImage = FBitSet( tex->flags, TF_IMG_UPLOADED ) && data != NULL;
|
||||||
GLenum inFormat = gEngfuncs.Image_GetPFDesc( type )->glFormat;
|
const rawformat_t rawformat = gEngfuncs.Image_GetPFDesc( type )->rawformat;
|
||||||
GLint dataType = GL_UNSIGNED_BYTE;
|
GLenum inFormat;
|
||||||
GLsizei samplesCount = 0;
|
GLint dataType;
|
||||||
|
|
||||||
Assert( tex != NULL );
|
Assert( tex != NULL );
|
||||||
|
|
||||||
if( FBitSet( tex->flags, TF_DEPTHMAP ))
|
if( FBitSet( tex->flags, TF_DEPTHMAP ))
|
||||||
inFormat = GL_DEPTH_COMPONENT;
|
inFormat = GL_DEPTH_COMPONENT;
|
||||||
|
else switch( rawformat )
|
||||||
|
{
|
||||||
|
case RF_RGBA:
|
||||||
|
inFormat = GL_RGBA;
|
||||||
|
break;
|
||||||
|
case RF_BGRA:
|
||||||
|
inFormat = GL_BGRA;
|
||||||
|
break;
|
||||||
|
case RF_BGR:
|
||||||
|
inFormat = GL_BGR;
|
||||||
|
break;
|
||||||
|
case RF_LUMINANCE:
|
||||||
|
inFormat = GL_LUMINANCE;
|
||||||
|
break;
|
||||||
|
case RF_COMPRESSED:
|
||||||
|
Assert( 0 );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if( FBitSet( tex->flags, TF_ARB_16BIT ))
|
if( FBitSet( tex->flags, TF_ARB_16BIT ))
|
||||||
dataType = GL_HALF_FLOAT_ARB;
|
dataType = GL_HALF_FLOAT_ARB;
|
||||||
else if( FBitSet( tex->flags, TF_ARB_FLOAT ))
|
else if( FBitSet( tex->flags, TF_ARB_FLOAT ))
|
||||||
dataType = GL_FLOAT;
|
dataType = GL_FLOAT;
|
||||||
|
else
|
||||||
|
dataType = GL_UNSIGNED_BYTE;
|
||||||
|
|
||||||
if( tex->target == GL_TEXTURE_1D )
|
if( tex->target == GL_TEXTURE_1D )
|
||||||
{
|
{
|
||||||
@@ -1022,8 +1042,8 @@ static void GL_TextureImageRAW( gl_texture_t *tex, GLint side, GLint level, GLin
|
|||||||
else if( tex->target == GL_TEXTURE_2D_MULTISAMPLE )
|
else if( tex->target == GL_TEXTURE_2D_MULTISAMPLE )
|
||||||
{
|
{
|
||||||
#if !defined( XASH_GL_STATIC ) || (!defined( XASH_GLES ) && !defined( XASH_GL4ES ))
|
#if !defined( XASH_GL_STATIC ) || (!defined( XASH_GLES ) && !defined( XASH_GL4ES ))
|
||||||
samplesCount = (GLsizei)gEngfuncs.pfnGetCvarFloat( "gl_msaa_samples" );
|
GLsizei samplesCount = (GLsizei)gEngfuncs.pfnGetCvarFloat( "gl_msaa_samples" );
|
||||||
switch (samplesCount)
|
switch( samplesCount )
|
||||||
{
|
{
|
||||||
case 2:
|
case 2:
|
||||||
case 4:
|
case 4:
|
||||||
|
|||||||
Reference in New Issue
Block a user