[Mesa-dev] [PATCH 13/24] swrast: Switch the remaining depth/stencil readpixels path to MapRenderbuffer.

Eric Anholt eric at anholt.net
Fri Oct 28 12:50:03 PDT 2011


---
 src/mesa/swrast/s_readpix.c |   72 +++++++++++++++++++++++++------------------
 1 files changed, 42 insertions(+), 30 deletions(-)

diff --git a/src/mesa/swrast/s_readpix.c b/src/mesa/swrast/s_readpix.c
index b4db25d..a0dc3e1 100644
--- a/src/mesa/swrast/s_readpix.c
+++ b/src/mesa/swrast/s_readpix.c
@@ -487,6 +487,45 @@ fast_read_depth_stencil_pixels_separate(struct gl_context *ctx,
    return GL_TRUE;
 }
 
+static void
+slow_read_depth_stencil_pixels_separate(struct gl_context *ctx,
+					GLint x, GLint y,
+					GLsizei width, GLsizei height,
+					GLenum type,
+					const struct gl_pixelstore_attrib *packing,
+					GLubyte *dst, int dstStride)
+{
+   struct gl_framebuffer *fb = ctx->ReadBuffer;
+   struct gl_renderbuffer *depthRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
+   struct gl_renderbuffer *stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
+   GLubyte *depthMap, *stencilMap;
+   int depthStride, stencilStride, j;
+
+   ctx->Driver.MapRenderbuffer(ctx, depthRb, x, y, width, height,
+			       GL_MAP_READ_BIT, &depthMap, &depthStride);
+   ctx->Driver.MapRenderbuffer(ctx, stencilRb, x, y, width, height,
+			       GL_MAP_READ_BIT, &stencilMap, &stencilStride);
+
+   for (j = 0; j < height; j++) {
+      GLstencil stencilVals[MAX_WIDTH];
+      GLfloat depthVals[MAX_WIDTH];
+
+      _mesa_unpack_float_z_row(depthRb->Format, width, depthMap, depthVals);
+      _swrast_read_stencil_span_mapped(ctx, stencilRb, stencilMap, width,
+				       stencilVals);
+
+      _mesa_pack_depth_stencil_span(ctx, width, type, (GLuint *)dst,
+				    depthVals, stencilVals, packing);
+
+      depthMap += depthStride;
+      stencilMap += stencilStride;
+      dst += dstStride;
+   }
+
+   ctx->Driver.UnmapRenderbuffer(ctx, depthRb);
+   ctx->Driver.UnmapRenderbuffer(ctx, stencilRb);
+}
+
 
 /**
  * Read combined depth/stencil values.
@@ -504,16 +543,9 @@ read_depth_stencil_pixels(struct gl_context *ctx,
       = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
    const GLboolean stencilTransfer = ctx->Pixel.IndexShift
       || ctx->Pixel.IndexOffset || ctx->Pixel.MapStencilFlag;
-   struct gl_renderbuffer *depthRb, *stencilRb;
    GLubyte *dst;
    int dstStride;
 
-   depthRb = ctx->ReadBuffer->_DepthBuffer;
-   stencilRb = ctx->ReadBuffer->_StencilBuffer;
-
-   if (!depthRb || !stencilRb)
-      return;
-
    dst = (GLubyte *) _mesa_image_address2d(packing, pixels,
 					   width, height,
 					   GL_DEPTH_STENCIL_EXT,
@@ -533,29 +565,9 @@ read_depth_stencil_pixels(struct gl_context *ctx,
 	 return;
    }
 
-      /* Reading GL_DEPTH_STENCIL pixels from separate depth/stencil buffers,
-       * or we need pixel transfer.
-       */
-   {
-      GLint i;
-
-      for (i = 0; i < height; i++) {
-         GLstencil stencilVals[MAX_WIDTH];
-         GLuint *depthStencilDst = (GLuint *) (dst + dstStride * i);
-
-         _swrast_read_stencil_span(ctx, stencilRb, width,
-                                   x, y + i, stencilVals);
-
-	 {
-            /* general case */
-            GLfloat depthVals[MAX_WIDTH];
-            _swrast_read_depth_span_float(ctx, depthRb, width, x, y + i,
-                                          depthVals);
-            _mesa_pack_depth_stencil_span(ctx, width, type, depthStencilDst,
-                                          depthVals, stencilVals, packing);
-         }
-      }
-   }
+   slow_read_depth_stencil_pixels_separate(ctx, x, y, width, height,
+					   type, packing,
+					   dst, dstStride);
 }
 
 
-- 
1.7.7



More information about the mesa-dev mailing list