From bb386a1ecae6d7f805af44df463b0e4d661eef85 Mon Sep 17 00:00:00 2001 From: Roland Scheidegger Date: Fri, 27 Mar 2009 21:59:33 +0100 Subject: mesa: add _rev signed rgba texture format --- src/mesa/main/texformat.c | 25 +++++++++++++++++++++++++ src/mesa/main/texformat.h | 4 +++- src/mesa/main/texformat_tmp.h | 23 ++++++++++++++++++++++- src/mesa/main/texstore.c | 31 ++++++++++++++++++++++++++++--- 4 files changed, 78 insertions(+), 5 deletions(-) diff --git a/src/mesa/main/texformat.c b/src/mesa/main/texformat.c index 0ceaaf3ecec..ee531c45c69 100644 --- a/src/mesa/main/texformat.c +++ b/src/mesa/main/texformat.c @@ -746,6 +746,30 @@ const struct gl_texture_format _mesa_texformat_signed_rgba8888 = { store_texel_signed_rgba8888 /* StoreTexel */ }; +const struct gl_texture_format _mesa_texformat_signed_rgba8888_rev = { + MESA_FORMAT_SIGNED_RGBA8888_REV, /* MesaFormat */ + GL_RGBA, /* BaseFormat */ + GL_SIGNED_NORMALIZED, /* DataType */ + 8, /* RedBits */ + 8, /* GreenBits */ + 8, /* BlueBits */ + 8, /* AlphaBits */ + 0, /* LuminanceBits */ + 0, /* IntensityBits */ + 0, /* IndexBits */ + 0, /* DepthBits */ + 0, /* StencilBits */ + 4, /* TexelBytes */ + _mesa_texstore_signed_rgba8888, /* StoreTexImageFunc */ + NULL, /* FetchTexel1D */ + NULL, /* FetchTexel2D */ + NULL, /* FetchTexel3D */ + fetch_texel_1d_signed_rgba8888_rev, /* FetchTexel1Df */ + fetch_texel_2d_signed_rgba8888_rev, /* FetchTexel2Df */ + fetch_texel_3d_signed_rgba8888_rev, /* FetchTexel3Df */ + store_texel_signed_rgba8888_rev /* StoreTexel */ +}; + /*@}*/ @@ -1854,6 +1878,7 @@ _mesa_format_to_type_and_comps(const struct gl_texture_format *format, return; case MESA_FORMAT_SIGNED_RGBA8888: + case MESA_FORMAT_SIGNED_RGBA8888_REV: *datatype = GL_BYTE; *comps = 4; return; diff --git a/src/mesa/main/texformat.h b/src/mesa/main/texformat.h index 3a08339adfd..5aa1d756cbc 100644 --- a/src/mesa/main/texformat.h +++ b/src/mesa/main/texformat.h @@ -169,7 +169,8 @@ enum _format { */ /*@{*/ MESA_FORMAT_DUDV8, - MESA_FORMAT_SIGNED_RGBA8888 + MESA_FORMAT_SIGNED_RGBA8888, + MESA_FORMAT_SIGNED_RGBA8888_REV /*@}*/ }; @@ -221,6 +222,7 @@ extern const struct gl_texture_format _mesa_texformat_intensity_float16; /*@{*/ extern const struct gl_texture_format _mesa_texformat_dudv8; extern const struct gl_texture_format _mesa_texformat_signed_rgba8888; +extern const struct gl_texture_format _mesa_texformat_signed_rgba8888_rev; /*@}*/ /** \name Assorted hardware-friendly formats */ diff --git a/src/mesa/main/texformat_tmp.h b/src/mesa/main/texformat_tmp.h index 604b1a744cb..ae57baf9222 100644 --- a/src/mesa/main/texformat_tmp.h +++ b/src/mesa/main/texformat_tmp.h @@ -1321,7 +1321,7 @@ static void FETCH(dudv8)(const struct gl_texture_image *texImage, texel[ACOMP] = 0; } -/* MESA_FORMAT_SIGNED_ARGB8888 ***********************************************/ +/* MESA_FORMAT_SIGNED_RGBA8888 ***********************************************/ static void FETCH(signed_rgba8888)( const struct gl_texture_image *texImage, GLint i, GLint j, GLint k, GLfloat *texel ) @@ -1343,6 +1343,27 @@ static void store_texel_signed_rgba8888(struct gl_texture_image *texImage, } #endif +static void FETCH(signed_rgba8888_rev)( const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel ) +{ + const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1); + texel[RCOMP] = BYTE_TO_FLOAT_TEX( (s ) & 0xff ); + texel[GCOMP] = BYTE_TO_FLOAT_TEX( (s >> 8) & 0xff ); + texel[BCOMP] = BYTE_TO_FLOAT_TEX( (s >> 16) & 0xff ); + texel[ACOMP] = BYTE_TO_FLOAT_TEX( (s >> 24) ); +} + +#if DIM == 3 +static void store_texel_signed_rgba8888_rev(struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, const void *texel) +{ + const GLubyte *rgba = (const GLubyte *) texel; + GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1); + *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]); +} +#endif + + /* MESA_FORMAT_YCBCR *********************************************************/ diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c index 785fb506220..7e7e0ac07a4 100644 --- a/src/mesa/main/texstore.c +++ b/src/mesa/main/texstore.c @@ -2564,14 +2564,15 @@ _mesa_texstore_dudv8(TEXSTORE_PARAMS) } /** - * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV. + * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or MESA_FORMAT_SIGNED_RGBA8888_REV */ GLboolean _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS) { const GLboolean littleEndian = _mesa_little_endian(); - ASSERT(dstFormat == &_mesa_texformat_signed_rgba8888); + ASSERT(dstFormat == &_mesa_texformat_signed_rgba8888 || + dstFormat == &_mesa_texformat_signed_rgba8888_rev); ASSERT(dstFormat->TexelBytes == 4); if (!ctx->_ImageTransferState && @@ -2588,6 +2589,20 @@ _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS) srcWidth, srcHeight, srcDepth, srcFormat, srcType, srcAddr, srcPacking); } + else if (!ctx->_ImageTransferState && + !srcPacking->SwapBytes && + dstFormat == &_mesa_texformat_signed_rgba8888_rev && + baseInternalFormat == GL_RGBA && + ((srcFormat == GL_RGBA && srcType == GL_BYTE && littleEndian) || + (srcFormat == GL_ABGR_EXT && srcType == GL_BYTE && !littleEndian))) { + /* simple memcpy path */ + memcpy_texture(ctx, dims, + dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset, + dstRowStride, + dstImageOffsets, + srcWidth, srcHeight, srcDepth, srcFormat, srcType, + srcAddr, srcPacking); + } else if (!ctx->_ImageTransferState && (srcType == GL_BYTE) && can_swizzle(baseInternalFormat) && @@ -2597,7 +2612,8 @@ _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS) /* dstmap - how to swizzle from RGBA to dst format: */ - if (littleEndian && dstFormat == &_mesa_texformat_signed_rgba8888) { + if ((littleEndian && dstFormat == &_mesa_texformat_signed_rgba8888) || + (!littleEndian && dstFormat == &_mesa_texformat_signed_rgba8888_rev)) { dstmap[3] = 0; dstmap[2] = 1; dstmap[1] = 2; @@ -2649,6 +2665,15 @@ _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS) srcRow += 4; } } + else { + for (col = 0; col < srcWidth; col++) { + dstUI[col] = PACK_COLOR_8888_REV( FLOAT_TO_BYTE_TEX(srcRow[RCOMP]), + FLOAT_TO_BYTE_TEX(srcRow[GCOMP]), + FLOAT_TO_BYTE_TEX(srcRow[BCOMP]), + FLOAT_TO_BYTE_TEX(srcRow[ACOMP]) ); + srcRow += 4; + } + } dstRow += dstRowStride; } } -- cgit v1.2.3