diff --git a/common/com_image.h b/common/com_image.h index 27e0f6c9..2732079b 100644 --- a/common/com_image.h +++ b/common/com_image.h @@ -38,11 +38,20 @@ typedef enum PF_TOTALCOUNT, // must be last } pixformat_t; +typedef enum +{ + RF_COMPRESSED, + RF_RGBA, + RF_BGRA, + RF_BGR, + RF_LUMINANCE +} rawformat_t; + typedef struct bpc_desc_s { int format; // pixelformat char name[16]; // used for debug - uint glFormat; // RGBA format + rawformat_t rawformat; int bpp; // channels (e.g. rgb = 3, rgba = 4) } bpc_desc_t; diff --git a/engine/common/common.h b/engine/common/common.h index 6f1bcf3e..735e444f 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -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; 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; -extern const bpc_desc_t PFDesc[]; // image get pixelformat 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_SetForceFlags( uint flags ); // set image force flags on loading @@ -502,6 +501,8 @@ void Image_ClearForceFlags( void ); void Image_SetMDLPointer( byte *p ); void Image_CheckPaletteQ1( void ); +extern const bpc_desc_t PFDesc[PF_TOTALCOUNT]; // image get pixelformat + /* ======================================================================== diff --git a/engine/common/imagelib/img_main.c b/engine/common/imagelib/img_main.c index 80e26fcc..1d7cd952 100644 --- a/engine/common/imagelib/img_main.c +++ b/engine/common/imagelib/img_main.c @@ -74,20 +74,29 @@ static const cubepack_t load_cubemap[] = }; // 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_INDEXED_24, "pal 24", 0x1908, 1 }, -{ PF_INDEXED_32, "pal 32", 0x1908, 1 }, -{ PF_RGBA_32, "RGBA 32",0x1908, 4 }, -{ PF_BGRA_32, "BGRA 32",0x80E1, 4 }, -{ PF_RGB_24, "RGB 24", 0x1908, 3 }, -{ PF_BGR_24, "BGR 24", 0x80E0, 3 }, -{ PF_LUMINANCE, "LUM 8", 0x1909, 1 }, -{ PF_DXT1, "DXT 1", 0x83F1, 4 }, -{ PF_DXT3, "DXT 3", 0x83F2, 4 }, -{ PF_DXT5, "DXT 5", 0x83F3, 4 }, -{ PF_ATI2, "ATI 2", 0x8837, 4 }, +{ PF_UNKNOWN, "raw", RF_RGBA, 0 }, +{ PF_INDEXED_24, "pal 24", RF_RGBA, 1 }, +{ PF_INDEXED_32, "pal 32", RF_RGBA, 1 }, +{ PF_RGBA_32, "RGBA 32", RF_RGBA, 4 }, +{ PF_BGRA_32, "BGRA 32", RF_BGRA, 4 }, +{ PF_RGB_24, "RGB 24", RF_RGBA, 3 }, +{ PF_BGR_24, "BGR 24", RF_BGR, 3 }, +{ PF_LUMINANCE, "LUM 8", RF_LUMINANCE, 1 }, +{ PF_DXT1, "DXT 1", RF_COMPRESSED, 4 }, +{ PF_DXT3, "DXT 3", RF_COMPRESSED, 4 }, +{ PF_DXT5, "DXT 5", RF_COMPRESSED, 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 diff --git a/ref/gl/gl_image.c b/ref/gl/gl_image.c index eb6b07c7..9c9ee168 100644 --- a/ref/gl/gl_image.c +++ b/ref/gl/gl_image.c @@ -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 ) { - GLuint cubeTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB; - qboolean subImage = FBitSet( tex->flags, TF_IMG_UPLOADED ) && data != NULL; - GLenum inFormat = gEngfuncs.Image_GetPFDesc( type )->glFormat; - GLint dataType = GL_UNSIGNED_BYTE; - GLsizei samplesCount = 0; + const GLuint cubeTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB; + const qboolean subImage = FBitSet( tex->flags, TF_IMG_UPLOADED ) && data != NULL; + const rawformat_t rawformat = gEngfuncs.Image_GetPFDesc( type )->rawformat; + GLenum inFormat; + GLint dataType; Assert( tex != NULL ); if( FBitSet( tex->flags, TF_DEPTHMAP )) 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 )) dataType = GL_HALF_FLOAT_ARB; else if( FBitSet( tex->flags, TF_ARB_FLOAT )) dataType = GL_FLOAT; + else + dataType = GL_UNSIGNED_BYTE; 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 ) { #if !defined( XASH_GL_STATIC ) || (!defined( XASH_GLES ) && !defined( XASH_GL4ES )) - samplesCount = (GLsizei)gEngfuncs.pfnGetCvarFloat( "gl_msaa_samples" ); - switch (samplesCount) + GLsizei samplesCount = (GLsizei)gEngfuncs.pfnGetCvarFloat( "gl_msaa_samples" ); + switch( samplesCount ) { case 2: case 4: