[Mesa-dev] [PATCH 15/22] swrast: remove the copy_depth_stencil_pixels() function

Brian Paul brianp at vmware.com
Sun Dec 18 19:08:20 PST 2011


Hopefully glCopyPixels(GL_DEPTH_STENCIL) will be handled by the
fast copy function.  Otherwise, just do the copy with separate
depth + stencil copies.  That's effectively what the removed code
did anyway.
---
 src/mesa/swrast/s_copypix.c |  181 +------------------------------------------
 1 files changed, 3 insertions(+), 178 deletions(-)

diff --git a/src/mesa/swrast/s_copypix.c b/src/mesa/swrast/s_copypix.c
index 3b6502e..14583bd 100644
--- a/src/mesa/swrast/s_copypix.c
+++ b/src/mesa/swrast/s_copypix.c
@@ -422,183 +422,6 @@ copy_stencil_pixels( struct gl_context *ctx, GLint srcx, GLint srcy,
 
 
 /**
- * This isn't terribly efficient.  If a driver really has combined
- * depth/stencil buffers the driver should implement an optimized
- * CopyPixels function.
- */
-static void
-copy_depth_stencil_pixels(struct gl_context *ctx,
-                          const GLint srcX, const GLint srcY,
-                          const GLint width, const GLint height,
-                          const GLint destX, const GLint destY)
-{
-   struct gl_renderbuffer *stencilReadRb, *depthReadRb, *depthDrawRb;
-   GLint sy, dy, stepy;
-   GLint j;
-   GLubyte *tempStencilImage = NULL, *stencilPtr = NULL;
-   GLfloat *tempDepthImage = NULL, *depthPtr = NULL;
-   const GLfloat depthScale = ctx->DrawBuffer->_DepthMaxF;
-   const GLuint stencilMask = ctx->Stencil.WriteMask[0];
-   const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
-   const GLboolean scaleOrBias
-      = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
-   GLint overlapping;
-
-   depthDrawRb = ctx->DrawBuffer->_DepthBuffer;
-   depthReadRb = ctx->ReadBuffer->_DepthBuffer;
-   stencilReadRb = ctx->ReadBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
-
-   ASSERT(depthDrawRb);
-   ASSERT(depthReadRb);
-   ASSERT(stencilReadRb);
-
-   if (ctx->DrawBuffer == ctx->ReadBuffer) {
-      overlapping = regions_overlap(srcX, srcY, destX, destY, width, height,
-                                    ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
-   }
-   else {
-      overlapping = GL_FALSE;
-   }
-
-   /* Determine if copy should be bottom-to-top or top-to-bottom */
-   if (!overlapping && srcY < destY) {
-      /* top-down  max-to-min */
-      sy = srcY + height - 1;
-      dy = destY + height - 1;
-      stepy = -1;
-   }
-   else {
-      /* bottom-up  min-to-max */
-      sy = srcY;
-      dy = destY;
-      stepy = 1;
-   }
-
-   if (overlapping) {
-      GLint ssy = sy;
-
-      if (stencilMask != 0x0) {
-         tempStencilImage
-            = (GLubyte *) malloc(width * height * sizeof(GLubyte));
-         if (!tempStencilImage) {
-            _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
-            return;
-         }
-
-         /* get copy of stencil pixels */
-         stencilPtr = tempStencilImage;
-         for (j = 0; j < height; j++, ssy += stepy) {
-            _swrast_read_stencil_span(ctx, stencilReadRb,
-                                      width, srcX, ssy, stencilPtr);
-            stencilPtr += width;
-         }
-         stencilPtr = tempStencilImage;
-      }
-
-      if (ctx->Depth.Mask) {
-         tempDepthImage
-            = (GLfloat *) malloc(width * height * sizeof(GLfloat));
-         if (!tempDepthImage) {
-            _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
-            free(tempStencilImage);
-            return;
-         }
-
-         /* get copy of depth pixels */
-         depthPtr = tempDepthImage;
-         for (j = 0; j < height; j++, ssy += stepy) {
-            _swrast_read_depth_span_float(ctx, depthReadRb,
-                                          width, srcX, ssy, depthPtr);
-            depthPtr += width;
-         }
-         depthPtr = tempDepthImage;
-      }
-   }
-
-   for (j = 0; j < height; j++, sy += stepy, dy += stepy) {
-      if (stencilMask != 0x0) {
-         GLubyte stencil[MAX_WIDTH];
-
-         /* Get stencil values */
-         if (overlapping) {
-            memcpy(stencil, stencilPtr, width * sizeof(GLubyte));
-            stencilPtr += width;
-         }
-         else {
-            _swrast_read_stencil_span(ctx, stencilReadRb,
-                                      width, srcX, sy, stencil);
-         }
-
-         _mesa_apply_stencil_transfer_ops(ctx, width, stencil);
-
-         /* Write values */
-         if (zoom) {
-            _swrast_write_zoomed_stencil_span(ctx, destX, destY, width,
-                                              destX, dy, stencil);
-         }
-         else {
-            _swrast_write_stencil_span( ctx, width, destX, dy, stencil );
-         }
-      }
-
-      if (ctx->Depth.Mask) {
-         GLfloat depth[MAX_WIDTH];
-         GLuint zVals32[MAX_WIDTH];
-         GLushort zVals16[MAX_WIDTH];
-         GLvoid *zVals;
-         GLuint zBytes;
-
-         /* get depth values */
-         if (overlapping) {
-            memcpy(depth, depthPtr, width * sizeof(GLfloat));
-            depthPtr += width;
-         }
-         else {
-            _swrast_read_depth_span_float(ctx, depthReadRb,
-                                          width, srcX, sy, depth);
-         }
-
-         /* scale & bias */
-         if (scaleOrBias) {
-            _mesa_scale_and_bias_depth(ctx, width, depth);
-         }
-         /* convert to integer Z values */
-         if (depthDrawRb->DataType == GL_UNSIGNED_SHORT) {
-            GLint k;
-            for (k = 0; k < width; k++)
-               zVals16[k] = (GLushort) (depth[k] * depthScale);
-            zVals = zVals16;
-            zBytes = 2;
-         }
-         else {
-            GLint k;
-            for (k = 0; k < width; k++)
-               zVals32[k] = (GLuint) (depth[k] * depthScale);
-            zVals = zVals32;
-            zBytes = 4;
-         }
-
-         /* Write values */
-         if (zoom) {
-            _swrast_write_zoomed_z_span(ctx, destX, destY, width,
-                                        destX, dy, zVals);
-         }
-         else {
-            _swrast_put_row(ctx, depthDrawRb, width, destX, dy, zVals, zBytes);
-         }
-      }
-   }
-
-   if (tempStencilImage)
-      free(tempStencilImage);
-
-   if (tempDepthImage)
-      free(tempDepthImage);
-}
-
-
-
-/**
  * Try to do a fast copy pixels with memcpy.
  * \return GL_TRUE if successful, GL_FALSE otherwise.
  */
@@ -776,7 +599,9 @@ _swrast_CopyPixels( struct gl_context *ctx,
       copy_stencil_pixels( ctx, srcx, srcy, width, height, destx, desty );
       break;
    case GL_DEPTH_STENCIL_EXT:
-      copy_depth_stencil_pixels(ctx, srcx, srcy, width, height, destx, desty);
+      /* Copy buffers separately (if the fast copy path wasn't taken) */
+      copy_depth_pixels(ctx, srcx, srcy, width, height, destx, desty);
+      copy_stencil_pixels(ctx, srcx, srcy, width, height, destx, desty);
       break;
    default:
       _mesa_problem(ctx, "unexpected type in _swrast_CopyPixels");
-- 
1.7.3.4



More information about the mesa-dev mailing list