Mesa (master): mesa: Enable uploads of only depth to z24s8 textures

Jakob Bornecrantz wallbraker at kemper.freedesktop.org
Fri Jun 12 11:33:13 UTC 2009


Module: Mesa
Branch: master
Commit: c6de08fff483911953692693c501bc200c235dce
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c6de08fff483911953692693c501bc200c235dce

Author: Jakob Bornecrantz <jakob at vmware.com>
Date:   Thu Jun 11 19:26:55 2009 +0100

mesa: Enable uploads of only depth to z24s8 textures

---

 src/mesa/main/texstore.c |   39 ++++++++++++++++++++++++++++++++++++---
 1 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index f3739f9..bfced1b 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -2689,12 +2689,45 @@ GLboolean
 _mesa_texstore_z24_s8(TEXSTORE_PARAMS)
 {
    const GLfloat depthScale = (GLfloat) 0xffffff;
+   const GLint srcRowStride
+      = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType)
+      / sizeof(GLuint);
+   GLint img, row;
 
    ASSERT(dstFormat == &_mesa_texformat_z24_s8);
-   ASSERT(srcFormat == GL_DEPTH_STENCIL_EXT);
-   ASSERT(srcType == GL_UNSIGNED_INT_24_8_EXT);
+   ASSERT(srcFormat == GL_DEPTH_STENCIL_EXT || srcFormat == GL_DEPTH_COMPONENT);
+   ASSERT(srcFormat != GL_DEPTH_STENCIL_EXT || srcType == GL_UNSIGNED_INT_24_8_EXT);
 
-   if (ctx->Pixel.DepthScale == 1.0f &&
+   /* In case 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] << 8 | (dstRow[i] & 0x000000FF);
+
+            src += srcRowStride;
+            dstRow += dstRowStride / sizeof(GLuint);
+         }
+      }
+   }
+   else if (ctx->Pixel.DepthScale == 1.0f &&
        ctx->Pixel.DepthBias == 0.0f &&
        !srcPacking->SwapBytes) {
       /* simple path */




More information about the mesa-commit mailing list