diff options
author | Brian Paul <brian.paul@tungstengraphics.com> | 2004-06-19 17:44:23 +0000 |
---|---|---|
committer | Brian Paul <brian.paul@tungstengraphics.com> | 2004-06-19 17:44:23 +0000 |
commit | f252f64430ccb957698fcf85e84c9d64008147eb (patch) | |
tree | 7c1de4462f2a91d6713cb52181f78b00b03211bf /src | |
parent | 07694b8935f69f69352648dd7ebf59a7222f1c8e (diff) |
Big-endian texture fixes from Michel Dänzer.
Diffstat (limited to 'src')
-rw-r--r-- | src/mesa/drivers/dri/common/texmem.c | 56 | ||||
-rw-r--r-- | src/mesa/drivers/dri/common/texmem.h | 14 | ||||
-rw-r--r-- | src/mesa/drivers/dri/r128/r128_tex.c | 24 | ||||
-rw-r--r-- | src/mesa/drivers/dri/r128/r128_texstate.c | 3 | ||||
-rw-r--r-- | src/mesa/drivers/dri/r200/r200_tex.c | 42 | ||||
-rw-r--r-- | src/mesa/drivers/dri/r200/r200_texstate.c | 10 | ||||
-rw-r--r-- | src/mesa/drivers/dri/radeon/radeon_tex.c | 36 | ||||
-rw-r--r-- | src/mesa/drivers/dri/radeon/radeon_texstate.c | 10 | ||||
-rw-r--r-- | src/mesa/main/colormac.h | 20 | ||||
-rw-r--r-- | src/mesa/main/teximage.c | 1 | ||||
-rw-r--r-- | src/mesa/main/texstore.c | 158 |
11 files changed, 263 insertions, 111 deletions
diff --git a/src/mesa/drivers/dri/common/texmem.c b/src/mesa/drivers/dri/common/texmem.c index c76d371682..48a8f5c74e 100644 --- a/src/mesa/drivers/dri/common/texmem.c +++ b/src/mesa/drivers/dri/common/texmem.c @@ -47,6 +47,7 @@ #include "simple_list.h" #include "imports.h" #include "macros.h" +#include "texformat.h" #include <assert.h> @@ -64,11 +65,10 @@ static unsigned dummy_swap_counter; * \param n Value whose \f$\log_2\f$ is to be calculated */ -static unsigned -driLog2( unsigned n ) +static GLuint +driLog2( GLuint n ) { - unsigned log2; - + GLuint log2; for ( log2 = 1 ; n > 1 ; log2++ ) { n >>= 1; @@ -1228,3 +1228,51 @@ driCalculateTextureFirstLastLevel( driTextureObject * t ) t->firstLevel = firstLevel; t->lastLevel = lastLevel; } + + + + +/** + * \name DRI texture formats. Pointers initialized to either the big- or + * little-endian Mesa formats. + */ +/*@{*/ +const struct gl_texture_format *_dri_texformat_rgba8888 = NULL; +const struct gl_texture_format *_dri_texformat_argb8888 = NULL; +const struct gl_texture_format *_dri_texformat_rgb565 = NULL; +const struct gl_texture_format *_dri_texformat_argb4444 = NULL; +const struct gl_texture_format *_dri_texformat_argb1555 = NULL; +const struct gl_texture_format *_dri_texformat_al88 = NULL; +const struct gl_texture_format *_dri_texformat_a8 = &_mesa_texformat_a8; +const struct gl_texture_format *_dri_texformat_ci8 = &_mesa_texformat_ci8; +const struct gl_texture_format *_dri_texformat_i8 = &_mesa_texformat_i8; +const struct gl_texture_format *_dri_texformat_l8 = &_mesa_texformat_l8; +/*@}*/ + + +/** + * Initialize little endian target, host byte order independent texture formats + */ +void +driInitTextureFormats(void) +{ + const GLuint ui = 1; + const GLubyte littleEndian = *((const GLubyte *) &ui); + + if (littleEndian) { + _dri_texformat_rgba8888 = &_mesa_texformat_rgba8888; + _dri_texformat_argb8888 = &_mesa_texformat_argb8888; + _dri_texformat_rgb565 = &_mesa_texformat_rgb565; + _dri_texformat_argb4444 = &_mesa_texformat_argb4444; + _dri_texformat_argb1555 = &_mesa_texformat_argb1555; + _dri_texformat_al88 = &_mesa_texformat_al88; + } + else { + _dri_texformat_rgba8888 = &_mesa_texformat_rgba8888_rev; + _dri_texformat_argb8888 = &_mesa_texformat_argb8888_rev; + _dri_texformat_rgb565 = &_mesa_texformat_rgb565_rev; + _dri_texformat_argb4444 = &_mesa_texformat_argb4444_rev; + _dri_texformat_argb1555 = &_mesa_texformat_argb1555_rev; + _dri_texformat_al88 = &_mesa_texformat_al88_rev; + } +} diff --git a/src/mesa/drivers/dri/common/texmem.h b/src/mesa/drivers/dri/common/texmem.h index f0c416fc61..266afd8bb6 100644 --- a/src/mesa/drivers/dri/common/texmem.h +++ b/src/mesa/drivers/dri/common/texmem.h @@ -293,4 +293,18 @@ GLboolean driValidateTextureHeaps( driTexHeap * const * texture_heaps, extern void driCalculateTextureFirstLastLevel( driTextureObject * t ); + +extern const struct gl_texture_format *_dri_texformat_rgba8888; +extern const struct gl_texture_format *_dri_texformat_argb8888; +extern const struct gl_texture_format *_dri_texformat_rgb565; +extern const struct gl_texture_format *_dri_texformat_argb4444; +extern const struct gl_texture_format *_dri_texformat_argb1555; +extern const struct gl_texture_format *_dri_texformat_al88; +extern const struct gl_texture_format *_dri_texformat_a8; +extern const struct gl_texture_format *_dri_texformat_ci8; +extern const struct gl_texture_format *_dri_texformat_i8; +extern const struct gl_texture_format *_dri_texformat_l8; + +extern void driInitTextureFormats( void ); + #endif /* DRI_TEXMEM_H */ diff --git a/src/mesa/drivers/dri/r128/r128_tex.c b/src/mesa/drivers/dri/r128/r128_tex.c index 973048b622..7355c9f3fe 100644 --- a/src/mesa/drivers/dri/r128/r128_tex.c +++ b/src/mesa/drivers/dri/r128/r128_tex.c @@ -200,9 +200,9 @@ r128ChooseTextureFormat( GLcontext *ctx, GLint internalFormat, case GL_RGBA: case GL_COMPRESSED_RGBA: if (do32bpt) - return &_mesa_texformat_argb8888; + return _dri_texformat_argb8888; else - return &_mesa_texformat_argb4444; + return _dri_texformat_argb4444; /* 16-bit formats with alpha */ case GL_INTENSITY4: @@ -210,7 +210,7 @@ r128ChooseTextureFormat( GLcontext *ctx, GLint internalFormat, case GL_LUMINANCE4_ALPHA4: case GL_RGBA2: case GL_RGBA4: - return &_mesa_texformat_argb4444; + return _dri_texformat_argb4444; /* 32-bit formats with alpha */ case GL_INTENSITY8: @@ -230,9 +230,9 @@ r128ChooseTextureFormat( GLcontext *ctx, GLint internalFormat, case GL_RGBA12: case GL_RGBA16: if (!force16bpt) - return &_mesa_texformat_argb8888; + return _dri_texformat_argb8888; else - return &_mesa_texformat_argb4444; + return _dri_texformat_argb4444; /* non-sized formats without alpha */ case 1: @@ -242,16 +242,16 @@ r128ChooseTextureFormat( GLcontext *ctx, GLint internalFormat, case GL_RGB: case GL_COMPRESSED_RGB: if (do32bpt) - return &_mesa_texformat_argb8888; + return _dri_texformat_argb8888; else - return &_mesa_texformat_rgb565; + return _dri_texformat_rgb565; /* 16-bit formats without alpha */ case GL_LUMINANCE4: case GL_R3_G3_B2: case GL_RGB4: case GL_RGB5: - return &_mesa_texformat_rgb565; + return _dri_texformat_rgb565; /* 32-bit formats without alpha */ case GL_LUMINANCE8: @@ -262,9 +262,9 @@ r128ChooseTextureFormat( GLcontext *ctx, GLint internalFormat, case GL_RGB12: case GL_RGB16: if (!force16bpt) - return &_mesa_texformat_argb8888; + return _dri_texformat_argb8888; else - return &_mesa_texformat_rgb565; + return _dri_texformat_rgb565; /* color-indexed formats */ case GL_COLOR_INDEX: @@ -274,7 +274,7 @@ r128ChooseTextureFormat( GLcontext *ctx, GLint internalFormat, case GL_COLOR_INDEX8_EXT: case GL_COLOR_INDEX12_EXT: case GL_COLOR_INDEX16_EXT: - return &_mesa_texformat_ci8; + return _dri_texformat_ci8; case GL_YCBCR_MESA: if (type == GL_UNSIGNED_SHORT_8_8_APPLE || @@ -612,5 +612,7 @@ void r128InitTextureFuncs( struct dd_function_table *functions ) functions->NewTextureObject = r128NewTextureObject; functions->DeleteTexture = r128DeleteTexture; functions->IsTextureResident = driIsTextureResident; + + driInitTextureFormats(); } diff --git a/src/mesa/drivers/dri/r128/r128_texstate.c b/src/mesa/drivers/dri/r128/r128_texstate.c index 89eda8acfb..c4c9b20fe9 100644 --- a/src/mesa/drivers/dri/r128/r128_texstate.c +++ b/src/mesa/drivers/dri/r128/r128_texstate.c @@ -65,12 +65,15 @@ static void r128SetTexImages( r128ContextPtr rmesa, switch (baseImage->TexFormat->MesaFormat) { case MESA_FORMAT_ARGB8888: + case MESA_FORMAT_ARGB8888_REV: t->textureFormat = R128_DATATYPE_ARGB8888; break; case MESA_FORMAT_ARGB4444: + case MESA_FORMAT_ARGB4444_REV: t->textureFormat = R128_DATATYPE_ARGB4444; break; case MESA_FORMAT_RGB565: + case MESA_FORMAT_RGB565_REV: t->textureFormat = R128_DATATYPE_RGB565; break; case MESA_FORMAT_RGB332: diff --git a/src/mesa/drivers/dri/r200/r200_tex.c b/src/mesa/drivers/dri/r200/r200_tex.c index fd326ad959..20febb508f 100644 --- a/src/mesa/drivers/dri/r200/r200_tex.c +++ b/src/mesa/drivers/dri/r200/r200_tex.c @@ -324,15 +324,15 @@ r200ChooseTextureFormat( GLcontext *ctx, GLint internalFormat, switch ( type ) { case GL_UNSIGNED_INT_10_10_10_2: case GL_UNSIGNED_INT_2_10_10_10_REV: - return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb1555; + return do32bpt ? _dri_texformat_argb8888 : _dri_texformat_argb1555; case GL_UNSIGNED_SHORT_4_4_4_4: case GL_UNSIGNED_SHORT_4_4_4_4_REV: - return &_mesa_texformat_argb4444; + return _dri_texformat_argb4444; case GL_UNSIGNED_SHORT_5_5_5_1: case GL_UNSIGNED_SHORT_1_5_5_5_REV: - return &_mesa_texformat_argb1555; + return _dri_texformat_argb1555; default: - return do32bpt ? &_mesa_texformat_rgba8888 : &_mesa_texformat_argb4444; + return do32bpt ? _dri_texformat_rgba8888 : _dri_texformat_argb4444; } case 3: @@ -341,15 +341,15 @@ r200ChooseTextureFormat( GLcontext *ctx, GLint internalFormat, switch ( type ) { case GL_UNSIGNED_SHORT_4_4_4_4: case GL_UNSIGNED_SHORT_4_4_4_4_REV: - return &_mesa_texformat_argb4444; + return _dri_texformat_argb4444; case GL_UNSIGNED_SHORT_5_5_5_1: case GL_UNSIGNED_SHORT_1_5_5_5_REV: - return &_mesa_texformat_argb1555; + return _dri_texformat_argb1555; case GL_UNSIGNED_SHORT_5_6_5: case GL_UNSIGNED_SHORT_5_6_5_REV: - return &_mesa_texformat_rgb565; + return _dri_texformat_rgb565; default: - return do32bpt ? &_mesa_texformat_rgba8888 : &_mesa_texformat_rgb565; + return do32bpt ? _dri_texformat_rgba8888 : _dri_texformat_rgb565; } case GL_RGBA8: @@ -357,25 +357,25 @@ r200ChooseTextureFormat( GLcontext *ctx, GLint internalFormat, case GL_RGBA12: case GL_RGBA16: return !force16bpt ? - &_mesa_texformat_rgba8888 : &_mesa_texformat_argb4444; + _dri_texformat_rgba8888 : _dri_texformat_argb4444; case GL_RGBA4: case GL_RGBA2: - return &_mesa_texformat_argb4444; + return _dri_texformat_argb4444; case GL_RGB5_A1: - return &_mesa_texformat_argb1555; + return _dri_texformat_argb1555; case GL_RGB8: case GL_RGB10: case GL_RGB12: case GL_RGB16: - return !force16bpt ? &_mesa_texformat_rgba8888 : &_mesa_texformat_rgb565; + return !force16bpt ? _dri_texformat_rgba8888 : _dri_texformat_rgb565; case GL_RGB5: case GL_RGB4: case GL_R3_G3_B2: - return &_mesa_texformat_rgb565; + return _dri_texformat_rgb565; case GL_ALPHA: case GL_ALPHA4: @@ -383,7 +383,7 @@ r200ChooseTextureFormat( GLcontext *ctx, GLint internalFormat, case GL_ALPHA12: case GL_ALPHA16: case GL_COMPRESSED_ALPHA: - return &_mesa_texformat_a8; + return _dri_texformat_a8; case 1: case GL_LUMINANCE: @@ -392,7 +392,7 @@ r200ChooseTextureFormat( GLcontext *ctx, GLint internalFormat, case GL_LUMINANCE12: case GL_LUMINANCE16: case GL_COMPRESSED_LUMINANCE: - return &_mesa_texformat_l8; + return _dri_texformat_l8; case 2: case GL_LUMINANCE_ALPHA: @@ -403,7 +403,7 @@ r200ChooseTextureFormat( GLcontext *ctx, GLint internalFormat, case GL_LUMINANCE12_ALPHA12: case GL_LUMINANCE16_ALPHA16: case GL_COMPRESSED_LUMINANCE_ALPHA: - return &_mesa_texformat_al88; + return _dri_texformat_al88; case GL_INTENSITY: case GL_INTENSITY4: @@ -411,11 +411,11 @@ r200ChooseTextureFormat( GLcontext *ctx, GLint internalFormat, case GL_INTENSITY12: case GL_INTENSITY16: case GL_COMPRESSED_INTENSITY: - return &_mesa_texformat_i8; + return _dri_texformat_i8; case GL_YCBCR_MESA: if (type == GL_UNSIGNED_SHORT_8_8_APPLE || - type == GL_UNSIGNED_BYTE) + type == GL_UNSIGNED_BYTE) return &_mesa_texformat_ycbcr; else return &_mesa_texformat_ycbcr_rev; @@ -461,7 +461,7 @@ r200ValidateClientStorage( GLcontext *ctx, GLenum target, switch ( internalFormat ) { case GL_RGBA: if ( format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8_REV ) { - texImage->TexFormat = &_mesa_texformat_argb8888; + texImage->TexFormat = _dri_texformat_argb8888; } else return 0; @@ -469,7 +469,7 @@ r200ValidateClientStorage( GLcontext *ctx, GLenum target, case GL_RGB: if ( format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5 ) { - texImage->TexFormat = &_mesa_texformat_rgb565; + texImage->TexFormat = _dri_texformat_rgb565; } else return 0; @@ -1034,6 +1034,8 @@ void r200InitTextureFuncs( struct dd_function_table *functions ) functions->TexParameter = r200TexParameter; functions->TexGen = r200TexGen; + driInitTextureFormats(); + #if 000 /* moved or obsolete code */ r200ContextPtr rmesa = R200_CONTEXT(ctx); diff --git a/src/mesa/drivers/dri/r200/r200_texstate.c b/src/mesa/drivers/dri/r200/r200_texstate.c index 08791ff788..cde801b0ab 100644 --- a/src/mesa/drivers/dri/r200/r200_texstate.c +++ b/src/mesa/drivers/dri/r200/r200_texstate.c @@ -56,8 +56,12 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define _COLOR(f) \ [ MESA_FORMAT_ ## f ] = { R200_TXFORMAT_ ## f, 0 } +#define _COLOR_REV(f) \ + [ MESA_FORMAT_ ## f ## _REV ] = { R200_TXFORMAT_ ## f, 0 } #define _ALPHA(f) \ [ MESA_FORMAT_ ## f ] = { R200_TXFORMAT_ ## f | R200_TXFORMAT_ALPHA_IN_MAP, 0 } +#define _ALPHA_REV(f) \ + [ MESA_FORMAT_ ## f ## _REV ] = { R200_TXFORMAT_ ## f | R200_TXFORMAT_ALPHA_IN_MAP, 0 } #define _YUV(f) \ [ MESA_FORMAT_ ## f ] = { R200_TXFORMAT_ ## f, R200_YUV_TO_RGB } #define _INVALID(f) \ @@ -71,12 +75,18 @@ static const struct { tx_table[] = { _ALPHA(RGBA8888), + _ALPHA_REV(RGBA8888), _ALPHA(ARGB8888), + _ALPHA_REV(ARGB8888), _INVALID(RGB888), _COLOR(RGB565), + _COLOR_REV(RGB565), _ALPHA(ARGB4444), + _ALPHA_REV(ARGB4444), _ALPHA(ARGB1555), + _ALPHA_REV(ARGB1555), _ALPHA(AL88), + _ALPHA_REV(AL88), _ALPHA(A8), _COLOR(L8), _ALPHA(I8), diff --git a/src/mesa/drivers/dri/radeon/radeon_tex.c b/src/mesa/drivers/dri/radeon/radeon_tex.c index cb5073d3cc..82b5d940f8 100644 --- a/src/mesa/drivers/dri/radeon/radeon_tex.c +++ b/src/mesa/drivers/dri/radeon/radeon_tex.c @@ -286,15 +286,15 @@ radeonChooseTextureFormat( GLcontext *ctx, GLint internalFormat, switch ( type ) { case GL_UNSIGNED_INT_10_10_10_2: case GL_UNSIGNED_INT_2_10_10_10_REV: - return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb1555; + return do32bpt ? _dri_texformat_argb8888 : _dri_texformat_argb1555; case GL_UNSIGNED_SHORT_4_4_4_4: case GL_UNSIGNED_SHORT_4_4_4_4_REV: - return &_mesa_texformat_argb4444; + return _dri_texformat_argb4444; case GL_UNSIGNED_SHORT_5_5_5_1: case GL_UNSIGNED_SHORT_1_5_5_5_REV: - return &_mesa_texformat_argb1555; + return _dri_texformat_argb1555; default: - return do32bpt ? &_mesa_texformat_rgba8888 : &_mesa_texformat_argb4444; + return do32bpt ? _dri_texformat_rgba8888 : _dri_texformat_argb4444; } case 3: @@ -303,15 +303,15 @@ radeonChooseTextureFormat( GLcontext *ctx, GLint internalFormat, switch ( type ) { case GL_UNSIGNED_SHORT_4_4_4_4: case GL_UNSIGNED_SHORT_4_4_4_4_REV: - return &_mesa_texformat_argb4444; + return _dri_texformat_argb4444; case GL_UNSIGNED_SHORT_5_5_5_1: case GL_UNSIGNED_SHORT_1_5_5_5_REV: - return &_mesa_texformat_argb1555; + return _dri_texformat_argb1555; case GL_UNSIGNED_SHORT_5_6_5: case GL_UNSIGNED_SHORT_5_6_5_REV: - return &_mesa_texformat_rgb565; + return _dri_texformat_rgb565; default: - return do32bpt ? &_mesa_texformat_rgba8888 : &_mesa_texformat_rgb565; + return do32bpt ? _dri_texformat_rgba8888 : _dri_texformat_rgb565; } case GL_RGBA8: @@ -319,25 +319,25 @@ radeonChooseTextureFormat( GLcontext *ctx, GLint internalFormat, case GL_RGBA12: case GL_RGBA16: return !force16bpt ? - &_mesa_texformat_rgba8888 : &_mesa_texformat_argb4444; + _dri_texformat_rgba8888 : _dri_texformat_argb4444; case GL_RGBA4: case GL_RGBA2: - return &_mesa_texformat_argb4444; + return _dri_texformat_argb4444; case GL_RGB5_A1: - return &_mesa_texformat_argb1555; + return _dri_texformat_argb1555; case GL_RGB8: case GL_RGB10: case GL_RGB12: case GL_RGB16: - return !force16bpt ? &_mesa_texformat_rgba8888 : &_mesa_texformat_rgb565; + return !force16bpt ? _dri_texformat_rgba8888 : _dri_texformat_rgb565; case GL_RGB5: case GL_RGB4: case GL_R3_G3_B2: - return &_mesa_texformat_rgb565; + return _dri_texformat_rgb565; case GL_ALPHA: case GL_ALPHA4: @@ -345,7 +345,7 @@ radeonChooseTextureFormat( GLcontext *ctx, GLint internalFormat, case GL_ALPHA12: case GL_ALPHA16: case GL_COMPRESSED_ALPHA: - return &_mesa_texformat_a8; + return _dri_texformat_a8; case 1: case GL_LUMINANCE: @@ -354,7 +354,7 @@ radeonChooseTextureFormat( GLcontext *ctx, GLint internalFormat, case GL_LUMINANCE12: case GL_LUMINANCE16: case GL_COMPRESSED_LUMINANCE: - return &_mesa_texformat_l8; + return _dri_texformat_l8; case 2: case GL_LUMINANCE_ALPHA: @@ -365,7 +365,7 @@ radeonChooseTextureFormat( GLcontext *ctx, GLint internalFormat, case GL_LUMINANCE12_ALPHA12: case GL_LUMINANCE16_ALPHA16: case GL_COMPRESSED_LUMINANCE_ALPHA: - return &_mesa_texformat_al88; + return _dri_texformat_al88; case GL_INTENSITY: case GL_INTENSITY4: @@ -373,7 +373,7 @@ radeonChooseTextureFormat( GLcontext *ctx, GLint internalFormat, case GL_INTENSITY12: case GL_INTENSITY16: case GL_COMPRESSED_INTENSITY: - return &_mesa_texformat_i8; + return _dri_texformat_i8; case GL_YCBCR_MESA: if (type == GL_UNSIGNED_SHORT_8_8_APPLE || @@ -755,4 +755,6 @@ void radeonInitTextureFuncs( struct dd_function_table *functions ) functions->TexEnv = radeonTexEnv; functions->TexParameter = radeonTexParameter; functions->TexGen = radeonTexGen; + + driInitTextureFormats(); } diff --git a/src/mesa/drivers/dri/radeon/radeon_texstate.c b/src/mesa/drivers/dri/radeon/radeon_texstate.c index 1ec4e7dce3..d17d9db4ac 100644 --- a/src/mesa/drivers/dri/radeon/radeon_texstate.c +++ b/src/mesa/drivers/dri/radeon/radeon_texstate.c @@ -58,8 +58,12 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define _COLOR(f) \ [ MESA_FORMAT_ ## f ] = { RADEON_TXFORMAT_ ## f, 0 } +#define _COLOR_REV(f) \ + [ MESA_FORMAT_ ## f ## _REV ] = { RADEON_TXFORMAT_ ## f, 0 } #define _ALPHA(f) \ [ MESA_FORMAT_ ## f ] = { RADEON_TXFORMAT_ ## f | RADEON_TXFORMAT_ALPHA_IN_MAP, 0 } +#define _ALPHA_REV(f) \ + [ MESA_FORMAT_ ## f ## _REV ] = { RADEON_TXFORMAT_ ## f | RADEON_TXFORMAT_ALPHA_IN_MAP, 0 } #define _YUV(f) \ [ MESA_FORMAT_ ## f ] = { RADEON_TXFORMAT_ ## f, RADEON_YUV_TO_RGB } #define _INVALID(f) \ @@ -73,12 +77,18 @@ static const struct { tx_table[] = { _ALPHA(RGBA8888), + _ALPHA_REV(RGBA8888), _ALPHA(ARGB8888), + _ALPHA_REV(ARGB8888), _INVALID(RGB888), _COLOR(RGB565), + _COLOR_REV(RGB565), _ALPHA(ARGB4444), + _ALPHA_REV(ARGB4444), _ALPHA(ARGB1555), + _ALPHA_REV(ARGB1555), _ALPHA(AL88), + _ALPHA_REV(AL88), _ALPHA(A8), _COLOR(L8), _ALPHA(I8), diff --git a/src/mesa/main/colormac.h b/src/mesa/main/colormac.h index 9b67fa19e4..62b80136e9 100644 --- a/src/mesa/main/colormac.h +++ b/src/mesa/main/colormac.h @@ -183,28 +183,38 @@ do { \ #define PACK_COLOR_8888( R, G, B, A ) \ (((R) << 24) | ((G) << 16) | ((B) << 8) | (A)) +#define PACK_COLOR_8888_REV( R, G, B, A ) \ + (((A) << 24) | ((B) << 16) | ((G) << 8) | (R)) + #define PACK_COLOR_888( R, G, B ) \ (((R) << 16) | ((G) << 8) | (B)) #define PACK_COLOR_565( R, G, B ) \ ((((R) & 0xf8) << 8) | (((G) & 0xfc) << 3) | (((B) & 0xf8) >> 3)) +#define PACK_COLOR_565_REV( R, G, B ) \ + (((R) & 0xf8) | ((G) & 0xe0) >> 5 | (((G) & 0x1c) << 11) | (((B) & 0xf8) << 5)) + #define PACK_COLOR_1555( A, B, G, R ) \ ((((B) & 0xf8) << 7) | (((G) & 0xf8) << 2) | (((R) & 0xf8) >> 3) | \ ((A) ? 0x8000 : 0)) -#define PACK_COLOR_5551( R, G, B, A ) \ - ((((B) & 0xf8) << 8) | \ - (((G) & 0xf8) << 3) | \ - (((R) & 0xf8) >> 2) | \ - (((A) & 0x80) >> 7)) +#define PACK_COLOR_1555_REV( A, B, G, R ) \ + ((((B) & 0xf8) >> 1) | (((G) & 0xc0) >> 6) | (((G) & 0x38) << 10) | (((R) & 0xf8) << 5) | \ + ((A) ? 0x80 : 0)) #define PACK_COLOR_4444( R, G, B, A ) \ ((((R) & 0xf0) << 8) | (((G) & 0xf0) << 4) | ((B) & 0xf0) | ((A) >> 4)) +#define PACK_COLOR_4444_REV( R, G, B, A ) \ + ((((B) & 0xf0) << 8) | (((A) & 0xf0) << 4) | ((R) & 0xf0) | ((G) >> 4)) + #define PACK_COLOR_88( L, A ) \ (((L) << 8) | (A)) +#define PACK_COLOR_88_REV( L, A ) \ + (((A) << 8) | (L)) + #define PACK_COLOR_332( R, G, B ) \ (((R) & 0xe0) | (((G) & 0xe0) >> 3) | (((B) & 0xc0) >> 6)) diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c index aa6494a0c5..d11b6e4609 100644 --- a/src/mesa/main/teximage.c +++ b/src/mesa/main/teximage.c @@ -365,6 +365,7 @@ is_color_format(GLenum format) case GL_RGB12: case GL_RGB16: case 4: + case GL_ABGR_EXT: case GL_RGBA: case GL_BGRA: case GL_RGBA2: diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c index 574066ecdd..c5f39c4453 100644 --- a/src/mesa/main/texstore.c +++ b/src/mesa/main/texstore.c @@ -828,13 +828,18 @@ _mesa_texstore_rgb565(STORE_PARAMS) for (row = 0; row < srcHeight; row++) { const GLubyte *srcUB = (const GLubyte *) src; GLushort *dstUS = (GLushort *) dst; - for (col = 0; col < srcWidth; col++) { - dstUS[col] = PACK_COLOR_565( srcUB[0], srcUB[1], srcUB[2] ); - srcUB += 3; - } /* check for byteswapped format */ - if (dstFormat == &_mesa_texformat_rgb565_rev) { - _mesa_swap2(dstUS, srcWidth); + if (dstFormat == &_mesa_texformat_rgb565) { + for (col = 0; col < srcWidth; col++) { + dstUS[col] = PACK_COLOR_565( srcUB[0], srcUB[1], srcUB[2] ); + srcUB += 3; + } + } + else { + for (col = 0; col < srcWidth; col++) { + dstUS[col] = PACK_COLOR_565_REV( srcUB[0], srcUB[1], srcUB[2] ); + srcUB += 3; + } } dst += dstRowStride; src += srcRowStride; @@ -861,15 +866,22 @@ _mesa_texstore_rgb565(STORE_PARAMS) GLubyte *dstRow = dstImage; for (row = 0; row < srcHeight; row++) { GLushort *dstUS = (GLushort *) dstRow; - for (col = 0; col < srcWidth; col++) { - dstUS[col] = PACK_COLOR_565( CHAN_TO_UBYTE(src[RCOMP]), - CHAN_TO_UBYTE(src[GCOMP]), - CHAN_TO_UBYTE(src[BCOMP]) ); - src += 3; - } /* check for byteswapped format */ - if (dstFormat == &_mesa_texformat_rgb565_rev) { - _mesa_swap2(dstUS, srcWidth); + if (dstFormat == &_mesa_texformat_rgb565) { + for (col = 0; col < srcWidth; col++) { + dstUS[col] = PACK_COLOR_565( CHAN_TO_UBYTE(src[RCOMP]), + CHAN_TO_UBYTE(src[GCOMP]), + CHAN_TO_UBYTE(src[BCOMP]) ); + src += 3; + } + } + else { + for (col = 0; col < srcWidth; col++) { + dstUS[col] = PACK_COLOR_565_REV( CHAN_TO_UBYTE(src[RCOMP]), + CHAN_TO_UBYTE(src[GCOMP]), + CHAN_TO_UBYTE(src[BCOMP]) ); + src += 3; + } } dstRow += dstRowStride; } @@ -921,16 +933,23 @@ _mesa_texstore_rgba8888(STORE_PARAMS) GLubyte *dstRow = dstImage; for (row = 0; row < srcHeight; row++) { GLuint *dstUI = (GLuint *) dstRow; - for (col = 0; col < srcWidth; col++) { - dstUI[col] = PACK_COLOR_8888( CHAN_TO_UBYTE(src[RCOMP]), - CHAN_TO_UBYTE(src[GCOMP]), - CHAN_TO_UBYTE(src[BCOMP]), - CHAN_TO_UBYTE(src[ACOMP]) ); - src += 4; + if (dstFormat == &_mesa_texformat_rgba8888) { + for (col = 0; col < srcWidth; col++) { + dstUI[col] = PACK_COLOR_8888( CHAN_TO_UBYTE(src[RCOMP]), + CHAN_TO_UBYTE(src[GCOMP]), + CHAN_TO_UBYTE(src[BCOMP]), + CHAN_TO_UBYTE(src[ACOMP]) ); + src += 4; + } } - /* check for byteswapped format */ - if (dstFormat == &_mesa_texformat_rgba8888_rev) { - _mesa_swap4(dstUI, srcWidth); + else { + for (col = 0; col < srcWidth; col++) { + dstUI[col] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src[RCOMP]), + CHAN_TO_UBYTE(src[GCOMP]), + CHAN_TO_UBYTE(src[BCOMP]), + CHAN_TO_UBYTE(src[ACOMP]) ); + src += 4; + } } dstRow += dstRowStride; } @@ -999,15 +1018,23 @@ _mesa_texstore_argb8888(STORE_PARAMS) GLubyte *dstRow = dstImage; for (row = 0; row < srcHeight; row++) { GLuint *dstUI = (GLuint *) dstRow; - for (col = 0; col < srcWidth; col++) { - dstUI[col] = PACK_COLOR_8888( CHAN_TO_UBYTE(src[ACOMP]), - CHAN_TO_UBYTE(src[RCOMP]), - CHAN_TO_UBYTE(src[GCOMP]), - CHAN_TO_UBYTE(src[BCOMP]) ); - src += 4; + if (dstFormat == &_mesa_texformat_argb8888) { + for (col = 0; col < srcWidth; col++) { + dstUI[col] = PACK_COLOR_8888( CHAN_TO_UBYTE(src[ACOMP]), + CHAN_TO_UBYTE(src[RCOMP]), + CHAN_TO_UBYTE(src[GCOMP]), + CHAN_TO_UBYTE(src[BCOMP]) ); + src += 4; + } } - if (dstFormat == &_mesa_texformat_argb8888_rev) { - _mesa_swap4(dstUI, srcWidth); + else { + for (col = 0; col < srcWidth; col++) { + dstUI[col] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src[ACOMP]), + CHAN_TO_UBYTE(src[RCOMP]), + CHAN_TO_UBYTE(src[GCOMP]), + CHAN_TO_UBYTE(src[BCOMP]) ); + src += 4; + } } dstRow += dstRowStride; } @@ -1248,15 +1275,23 @@ _mesa_texstore_argb4444(STORE_PARAMS) GLubyte *dstRow = dstImage; for (row = 0; row < srcHeight; row++) { GLushort *dstUS = (GLushort *) dstRow; - for (col = 0; col < srcWidth; col++) { - dstUS[col] = PACK_COLOR_4444( CHAN_TO_UBYTE(src[ACOMP]), - CHAN_TO_UBYTE(src[RCOMP]), - CHAN_TO_UBYTE(src[GCOMP]), - CHAN_TO_UBYTE(src[BCOMP]) ); - src += 4; + if (dstFormat == &_mesa_texformat_argb4444) { + for (col = 0; col < srcWidth; col++) { + dstUS[col] = PACK_COLOR_4444( CHAN_TO_UBYTE(src[ACOMP]), + CHAN_TO_UBYTE(src[RCOMP]), + CHAN_TO_UBYTE(src[GCOMP]), + CHAN_TO_UBYTE(src[BCOMP]) ); + src += 4; + } } - if (dstFormat == &_mesa_texformat_argb4444_rev) { - _mesa_swap2(dstUS, srcWidth); + else { + for (col = 0; col < srcWidth; col++) { + dstUS[col] = PACK_COLOR_4444_REV( CHAN_TO_UBYTE(src[ACOMP]), + CHAN_TO_UBYTE(src[RCOMP]), + CHAN_TO_UBYTE(src[GCOMP]), + CHAN_TO_UBYTE(src[BCOMP]) ); + src += 4; + } } dstRow += dstRowStride; } @@ -1309,15 +1344,23 @@ _mesa_texstore_argb1555(STORE_PARAMS) GLubyte *dstRow = dstImage; for (row = 0; row < srcHeight; row++) { GLushort *dstUS = (GLushort *) dstRow; - for (col = 0; col < srcWidth; col++) { - dstUS[col] = PACK_COLOR_1555( CHAN_TO_UBYTE(src[ACOMP]), - CHAN_TO_UBYTE(src[RCOMP]), - CHAN_TO_UBYTE(src[GCOMP]), - CHAN_TO_UBYTE(src[BCOMP]) ); - src += 4; + if (dstFormat == &_mesa_texformat_argb1555) { + for (col = 0; col < srcWidth; col++) { + dstUS[col] = PACK_COLOR_1555( CHAN_TO_UBYTE(src[ACOMP]), + CHAN_TO_UBYTE(src[RCOMP]), + CHAN_TO_UBYTE(src[GCOMP]), + CHAN_TO_UBYTE(src[BCOMP]) ); + src += 4; + } } - if (dstFormat == &_mesa_texformat_argb1555_rev) { - _mesa_swap2(dstUS, srcWidth); + else { + for (col = 0; col < srcWidth; col++) { + dstUS[col] = PACK_COLOR_1555_REV( CHAN_TO_UBYTE(src[ACOMP]), + CHAN_TO_UBYTE(src[RCOMP]), + CHAN_TO_UBYTE(src[GCOMP]), + CHAN_TO_UBYTE(src[BCOMP]) ); + src += 4; + } } dstRow += dstRowStride; } @@ -1373,14 +1416,21 @@ _mesa_texstore_al88(STORE_PARAMS) GLubyte *dstRow = dstImage; for (row = 0; row < srcHeight; row++) { GLushort *dstUS = (GLushort *) dstRow; - for (col = 0; col < srcWidth; col++) { - /* src[0] is luminance, src[1] is alpha */ - dstUS[col] = PACK_COLOR_88( CHAN_TO_UBYTE(src[1]), - CHAN_TO_UBYTE(src[0]) ); - src += 2; + if (dstFormat == &_mesa_texformat_al88) { + for (col = 0; col < srcWidth; col++) { + /* src[0] is luminance, src[1] is alpha */ + dstUS[col] = PACK_COLOR_88( CHAN_TO_UBYTE(src[1]), + CHAN_TO_UBYTE(src[0]) ); + src += 2; + } } - if (dstFormat == &_mesa_texformat_al88_rev) { - _mesa_swap2(dstUS, srcWidth); + else { + for (col = 0; col < srcWidth; col++) { + /* src[0] is luminance, src[1] is alpha */ + dstUS[col] = PACK_COLOR_88_REV( CHAN_TO_UBYTE(src[1]), + CHAN_TO_UBYTE(src[0]) ); + src += 2; + } } dstRow += dstRowStride; } |