mesa: Support for MESA_FORMAT_S8_Z24 texture
authorJakob Bornecrantz <jakob@tungstengraphics.com>
Thu, 4 Sep 2008 02:35:01 +0000 (10:35 +0800)
committerXiang, Haihao <haihao.xiang@intel.com>
Thu, 4 Sep 2008 02:35:01 +0000 (10:35 +0800)
cherry-picked from gallium-0.1

src/mesa/main/texformat.c
src/mesa/main/texformat.h
src/mesa/main/texformat_tmp.h
src/mesa/main/texstore.c
src/mesa/main/texstore.h

index acc268e622d6f6ab2ad0692751db60804750b09c..a32ad6380c4535247929346962002a530b297cf3 100644 (file)
@@ -1207,6 +1207,30 @@ const struct gl_texture_format _mesa_texformat_z24_s8 = {
    store_texel_z24_s8                  /* StoreTexel */
 };
 
+const struct gl_texture_format _mesa_texformat_s8_z24 = {
+   MESA_FORMAT_S8_Z24,                 /* MesaFormat */
+   GL_DEPTH_STENCIL_EXT,               /* BaseFormat */
+   GL_UNSIGNED_NORMALIZED_ARB,         /* DataType */
+   0,                                  /* RedBits */
+   0,                                  /* GreenBits */
+   0,                                  /* BlueBits */
+   0,                                  /* AlphaBits */
+   0,                                  /* LuminanceBits */
+   0,                                  /* IntensityBits */
+   0,                                  /* IndexBits */
+   24,                                 /* DepthBits */
+   8,                                  /* StencilBits */
+   4,                                  /* TexelBytes */
+   _mesa_texstore_s8_z24,              /* StoreTexImageFunc */
+   NULL,                               /* FetchTexel1D */
+   NULL,                               /* FetchTexel2D */
+   NULL,                               /* FetchTexel3D */
+   fetch_texel_1d_f_s8_z24,            /* FetchTexel1Df */
+   fetch_texel_2d_f_s8_z24,            /* FetchTexel2Df */
+   fetch_texel_3d_f_s8_z24,            /* FetchTexel3Df */
+   store_texel_s8_z24                  /* StoreTexel */
+};
+
 const struct gl_texture_format _mesa_texformat_z16 = {
    MESA_FORMAT_Z16,                    /* MesaFormat */
    GL_DEPTH_COMPONENT,                 /* BaseFormat */
index 82023b946d5ab4ca14ad31ab4136fa535bf88faa..f5f851ca212068e15d1f73f9ffd3cf2ec0f9e11c 100644 (file)
@@ -84,6 +84,7 @@ enum _format {
    MESA_FORMAT_YCBCR,          /*                     YYYY YYYY UorV UorV */
    MESA_FORMAT_YCBCR_REV,      /*                     UorV UorV YYYY YYYY */
    MESA_FORMAT_Z24_S8,          /* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ SSSS SSSS */
+   MESA_FORMAT_S8_Z24,          /* SSSS SSSS ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
    MESA_FORMAT_Z16,             /*                     ZZZZ ZZZZ ZZZZ ZZZZ */
    MESA_FORMAT_Z32,             /* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
    /*@}*/
@@ -211,6 +212,7 @@ extern const struct gl_texture_format _mesa_texformat_l8;
 extern const struct gl_texture_format _mesa_texformat_i8;
 extern const struct gl_texture_format _mesa_texformat_ci8;
 extern const struct gl_texture_format _mesa_texformat_z24_s8;
+extern const struct gl_texture_format _mesa_texformat_s8_z24;
 extern const struct gl_texture_format _mesa_texformat_z16;
 extern const struct gl_texture_format _mesa_texformat_z32;
 /*@}*/
index 99785da1a0a2f6206d2bcaa932a875f24ca78dfa..63939f40111ae3d97d81347ea3ffa92022320430 100644 (file)
@@ -1363,6 +1363,32 @@ static void store_texel_z24_s8(struct gl_texture_image *texImage,
 #endif
 
 
+/* MESA_TEXFORMAT_S8_Z24 ***************************************************/
+
+static void FETCH(f_s8_z24)( const struct gl_texture_image *texImage,
+                             GLint i, GLint j, GLint k, GLfloat *texel )
+{
+   /* only return Z, not stencil data */
+   const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+   const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
+   texel[0] = ((*src) & 0x00ffffff) * scale;
+   ASSERT(texImage->TexFormat->MesaFormat == MESA_FORMAT_S8_Z24);
+   ASSERT(texel[0] >= 0.0F);
+   ASSERT(texel[0] <= 1.0F);
+}
+
+#if DIM == 3
+static void store_texel_s8_z24(struct gl_texture_image *texImage,
+                               GLint i, GLint j, GLint k, const void *texel)
+{
+   /* only store Z, not stencil */
+   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+   GLfloat depth = *((GLfloat *) texel);
+   GLuint zi = (GLuint) (depth * 0xffffff);
+   *dst = zi | (*dst & 0xff000000);
+}
+#endif
+
 
 #undef TEXEL_ADDR
 #undef DIM
index 25381e32dc74e21261b157767f432c46ed115dd8..1efaf97fb696f342c35960b8f540ac0c925099e2 100644 (file)
@@ -2445,6 +2445,87 @@ _mesa_texstore_z24_s8(TEXSTORE_PARAMS)
 }
 
 
+/**
+ * Store a combined depth/stencil texture image.
+ */
+GLboolean
+_mesa_texstore_s8_z24(TEXSTORE_PARAMS)
+{
+   const GLuint depthScale = 0xffffff;
+   const GLint srcRowStride
+      = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType)
+      / sizeof(GLuint);
+   GLint img, row;
+
+   ASSERT(dstFormat == &_mesa_texformat_s8_z24);
+   ASSERT(srcFormat == GL_DEPTH_STENCIL_EXT || srcFormat == GL_DEPTH_COMPONENT);
+   ASSERT(srcFormat != GL_DEPTH_STENCIL_EXT || srcType == GL_UNSIGNED_INT_24_8_EXT);
+
+   /* Incase we only upload depth we need to preserve the stencil */
+   if (srcFormat == GL_DEPTH_COMPONENT) {
+      for (img = 0; img < srcDepth; img++) {
+         GLuint *dstRow = (GLuint *) dstAddr
+            + dstImageOffsets[dstZoffset + img]
+            + dstYoffset * dstRowStride / sizeof(GLuint)
+            + dstXoffset;
+         const GLuint *src
+            = (const GLuint *) _mesa_image_address(dims, srcPacking, srcAddr,
+                  srcWidth, srcHeight,
+                  srcFormat, srcType,
+                  img, 0, 0);
+         for (row = 0; row < srcHeight; row++) {
+            GLuint depth[MAX_WIDTH];
+            GLint i;
+            _mesa_unpack_depth_span(ctx, srcWidth,
+                                    GL_UNSIGNED_INT, /* dst type */
+                                    depth, /* dst addr */
+                                    depthScale,
+                                    srcType, src, srcPacking);
+
+            for (i = 0; i < srcWidth; i++)
+               dstRow[i] = depth[i] | (dstRow[i] & 0xFF000000);
+
+            src += srcRowStride;
+            dstRow += dstRowStride / sizeof(GLuint);
+         }
+      }
+   } else {
+      for (img = 0; img < srcDepth; img++) {
+         GLuint *dstRow = (GLuint *) dstAddr
+            + dstImageOffsets[dstZoffset + img]
+            + dstYoffset * dstRowStride / sizeof(GLuint)
+            + dstXoffset;
+         const GLuint *src
+            = (const GLuint *) _mesa_image_address(dims, srcPacking, srcAddr,
+                  srcWidth, srcHeight,
+                  srcFormat, srcType,
+                  img, 0, 0);
+         for (row = 0; row < srcHeight; row++) {
+            GLubyte stencil[MAX_WIDTH];
+            GLint i;
+            /* the 24 depth bits will be in the high position: */
+            _mesa_unpack_depth_span(ctx, srcWidth,
+                                    GL_UNSIGNED_INT, /* dst type */
+                                    dstRow, /* dst addr */
+                                    depthScale,
+                                    srcType, src, srcPacking);
+            /* get the 8-bit stencil values */
+            _mesa_unpack_stencil_span(ctx, srcWidth,
+                                      GL_UNSIGNED_BYTE, /* dst type */
+                                      stencil, /* dst addr */
+                                      srcType, src, srcPacking,
+                                      ctx->_ImageTransferState);
+            /* merge stencil values into depth values */
+            for (i = 0; i < srcWidth; i++)
+               dstRow[i] = stencil[i] << 24;
+
+            src += srcRowStride;
+            dstRow += dstRowStride / sizeof(GLuint);
+         }
+      }
+   }
+   return GL_TRUE;
+}
 
 /**
  * Store an image in any of the formats:
index 5128bc58276393ecc0d8c733ed47792485873294..c9edf14dbc5fe5910c3579c653c8173e858183ba 100644 (file)
@@ -57,6 +57,7 @@ extern GLboolean _mesa_texstore_a8(TEXSTORE_PARAMS);
 extern GLboolean _mesa_texstore_ci8(TEXSTORE_PARAMS);
 extern GLboolean _mesa_texstore_ycbcr(TEXSTORE_PARAMS);
 extern GLboolean _mesa_texstore_z24_s8(TEXSTORE_PARAMS);
+extern GLboolean _mesa_texstore_s8_z24(TEXSTORE_PARAMS);
 extern GLboolean _mesa_texstore_z16(TEXSTORE_PARAMS);
 extern GLboolean _mesa_texstore_z32(TEXSTORE_PARAMS);
 extern GLboolean _mesa_texstore_rgba_float32(TEXSTORE_PARAMS);