mesa: add _rev signed rgba texture format
authorRoland Scheidegger <sroland@vmware.com>
Fri, 27 Mar 2009 20:59:33 +0000 (21:59 +0100)
committerRoland Scheidegger <sroland@vmware.com>
Sat, 28 Mar 2009 01:03:45 +0000 (02:03 +0100)
src/mesa/main/texformat.c
src/mesa/main/texformat.h
src/mesa/main/texformat_tmp.h
src/mesa/main/texstore.c

index 0ceaaf3ececd802f9f74b27db4319d7ec500d2ec..ee531c45c692940c807a6f243f638acc43663c6f 100644 (file)
@@ -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;
index 3a08339adfd58b62c57b7a9641fc6b1ccf6529d0..5aa1d756cbcdb6824c5493324511af486facdb9d 100644 (file)
@@ -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 */
index 604b1a744cb5ccfe6dbb98057199fb891f1f777d..ae57baf92226993a378057c87d9d2afd9c0c9daa 100644 (file)
@@ -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 *********************************************************/
 
index 785fb5062200dc37d993a258e3c32183b752c863..7e7e0ac07a429a426f19139a85d89e840663251b 100644 (file)
@@ -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;
          }
       }