mesa: implement packing of DEPTH_STENCIL & FLOAT_32_UNSIGNED_INT_24_8_REV combo
authorMarek Olšák <maraeo@gmail.com>
Sun, 10 Jul 2011 23:39:53 +0000 (01:39 +0200)
committerMarek Olšák <maraeo@gmail.com>
Mon, 11 Jul 2011 01:04:17 +0000 (03:04 +0200)
Tested with the new piglit fbo-depthstencil test.

src/mesa/main/pack.c
src/mesa/main/pack.h
src/mesa/state_tracker/st_cb_readpixels.c
src/mesa/swrast/s_readpix.c

index d42ae7bf0f4f2e63ec4b0974d16d541a4bafb883..7de1d05b91915711363b49b4720676e0ad4f042c 100644 (file)
@@ -5056,10 +5056,11 @@ _mesa_pack_depth_span( struct gl_context *ctx, GLuint n, GLvoid *dest,
 
 
 /**
- * Pack depth and stencil values as GL_DEPTH_STENCIL/GL_UNSIGNED_INT_24_8.
+ * Pack depth and stencil values as GL_DEPTH_STENCIL (GL_UNSIGNED_INT_24_8 etc)
  */
 void
-_mesa_pack_depth_stencil_span(struct gl_context *ctx, GLuint n, GLuint *dest,
+_mesa_pack_depth_stencil_span(struct gl_context *ctx,GLuint n,
+                              GLenum dstType, GLuint *dest,
                               const GLfloat *depthVals,
                               const GLstencil *stencilVals,
                               const struct gl_pixelstore_attrib *dstPacking)
@@ -5089,9 +5090,19 @@ _mesa_pack_depth_stencil_span(struct gl_context *ctx, GLuint n, GLuint *dest,
       stencilVals = stencilCopy;
    }
 
-   for (i = 0; i < n; i++) {
-      GLuint z = (GLuint) (depthVals[i] * 0xffffff);
-      dest[i] = (z << 8) | (stencilVals[i] & 0xff);
+   switch (dstType) {
+   case GL_UNSIGNED_INT_24_8:
+      for (i = 0; i < n; i++) {
+         GLuint z = (GLuint) (depthVals[i] * 0xffffff);
+         dest[i] = (z << 8) | (stencilVals[i] & 0xff);
+      }
+      break;
+   case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
+      for (i = 0; i < n; i++) {
+         ((GLfloat*)dest)[i*2] = depthVals[i];
+         dest[i*2+1] = stencilVals[i] & 0xff;
+      }
+      break;
    }
 
    if (dstPacking->SwapBytes) {
index 78238ea5839566088ff813a7800878884d260a84..00aab409e42aae02d88557c66a8f728bf6d5a1b0 100644 (file)
@@ -130,8 +130,8 @@ _mesa_pack_depth_span(struct gl_context *ctx, GLuint n, GLvoid *dest,
 
 
 extern void
-_mesa_pack_depth_stencil_span(struct gl_context *ctx,
-                              GLuint n, GLuint *dest,
+_mesa_pack_depth_stencil_span(struct gl_context *ctx,GLuint n,
+                              GLenum dstType, GLuint *dest,
                               const GLfloat *depthVals,
                               const GLstencil *stencilVals,
                               const struct gl_pixelstore_attrib *dstPacking);
index 02ddad7b2f090b2b8b0ae49d85e61adf7208981c..e2b29fe3068691d3932abde20366863c15275229 100644 (file)
@@ -177,7 +177,7 @@ st_read_stencil_pixels(struct gl_context *ctx, GLint x, GLint y,
       dest = _mesa_image_address2d(packing, pixels, width, height,
                                    format, type, j, 0);
       if (format == GL_DEPTH_STENCIL) {
-         _mesa_pack_depth_stencil_span(ctx, width, dest,
+         _mesa_pack_depth_stencil_span(ctx, width, type, dest,
                                        zValues, sValues, packing);
       }
       else {
index 214f2ea1aaa4959814cf27d32e87152a7f13313e..66ca39293a61ba8bcd22cb93aac8da5efddc316d 100644 (file)
@@ -446,7 +446,7 @@ read_depth_stencil_pixels(struct gl_context *ctx,
             GLfloat depthVals[MAX_WIDTH];
             _swrast_read_depth_span_float(ctx, depthRb, width, x, y + i,
                                           depthVals);
-            _mesa_pack_depth_stencil_span(ctx, width, depthStencilDst,
+            _mesa_pack_depth_stencil_span(ctx, width, type, depthStencilDst,
                                           depthVals, stencilVals, packing);
          }
       }