swrast: stop using depth/stencil wrappers in CopyPixels code
authorBrian Paul <brianp@vmware.com>
Sat, 24 Dec 2011 15:54:26 +0000 (08:54 -0700)
committerBrian Paul <brianp@vmware.com>
Sat, 24 Dec 2011 15:59:54 +0000 (08:59 -0700)
The functions that read depth/stencil values understand all (packed)
depth/stencil buffer formats now so there's no reason to use the
wrappers.

Also, improve the format checks in fast_copy_pixels() to catch mismatched
depth/stencil cases.

v2: fix the test for combined depth+stencil buffers, per Eric.

src/mesa/swrast/s_copypix.c

index 9769a477db6e6b3f3dfb849c632cbeed44b90f3c..907645e3ff0319549a907cceb6c8afd8ee49d69b 100644 (file)
@@ -245,7 +245,7 @@ copy_depth_pixels( struct gl_context *ctx, GLint srcx, GLint srcy,
                    GLint destx, GLint desty )
 {
    struct gl_framebuffer *fb = ctx->ReadBuffer;
-   struct gl_renderbuffer *readRb = fb->_DepthBuffer;
+   struct gl_renderbuffer *readRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
    GLfloat *p, *tmpImage;
    GLint sy, dy, stepy;
    GLint j;
@@ -339,7 +339,7 @@ copy_stencil_pixels( struct gl_context *ctx, GLint srcx, GLint srcy,
                      GLint destx, GLint desty )
 {
    struct gl_framebuffer *fb = ctx->ReadBuffer;
-   struct gl_renderbuffer *rb = fb->_StencilBuffer;
+   struct gl_renderbuffer *rb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
    GLint sy, dy, stepy;
    GLint j;
    GLubyte *p, *tmpImage;
@@ -446,7 +446,7 @@ copy_depth_stencil_pixels(struct gl_context *ctx,
 
    depthDrawRb = ctx->DrawBuffer->_DepthBuffer;
    depthReadRb = ctx->ReadBuffer->_DepthBuffer;
-   stencilReadRb = ctx->ReadBuffer->_StencilBuffer;
+   stencilReadRb = ctx->ReadBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
 
    ASSERT(depthDrawRb);
    ASSERT(depthReadRb);
@@ -599,7 +599,7 @@ copy_depth_stencil_pixels(struct gl_context *ctx,
 
 
 /**
- * Try to do a fast copy pixels.
+ * Try to do a fast copy pixels with memcpy.
  * \return GL_TRUE if successful, GL_FALSE otherwise.
  */
 static GLboolean
@@ -630,12 +630,12 @@ fast_copy_pixels(struct gl_context *ctx,
       dstRb = dstFb->_ColorDrawBuffers[0];
    }
    else if (type == GL_STENCIL) {
-      srcRb = srcFb->_StencilBuffer;
-      dstRb = dstFb->_StencilBuffer;
+      srcRb = srcFb->Attachment[BUFFER_STENCIL].Renderbuffer;
+      dstRb = dstFb->Attachment[BUFFER_STENCIL].Renderbuffer;
    }
    else if (type == GL_DEPTH) {
-      srcRb = srcFb->_DepthBuffer;
-      dstRb = dstFb->_DepthBuffer;
+      srcRb = srcFb->Attachment[BUFFER_DEPTH].Renderbuffer;
+      dstRb = dstFb->Attachment[BUFFER_DEPTH].Renderbuffer;
    }
    else {
       ASSERT(type == GL_DEPTH_STENCIL_EXT);
@@ -649,6 +649,19 @@ fast_copy_pixels(struct gl_context *ctx,
       return GL_FALSE;
    }
 
+   if (type == GL_STENCIL || type == GL_DEPTH_COMPONENT) {
+      /* can't handle packed depth+stencil here */
+      if (_mesa_is_format_packed_depth_stencil(srcRb->Format) ||
+          _mesa_is_format_packed_depth_stencil(dstRb->Format))
+         return GL_FALSE;
+   }
+   else if (type == GL_DEPTH_STENCIL) {
+      /* can't handle separate depth/stencil buffers */
+      if (srcRb != srcFb->Attachment[BUFFER_STENCIL].Renderbuffer ||
+          dstRb != dstFb->Attachment[BUFFER_STENCIL].Renderbuffer)
+         return GL_FALSE;
+   }
+
    /* clipping not supported */
    if (srcX < 0 || srcX + width > (GLint) srcFb->Width ||
        srcY < 0 || srcY + height > (GLint) srcFb->Height ||