swrast: rewrite glDrawPixels(GL_DEPTH) with zoom
authorBrian Paul <brianp@vmware.com>
Sat, 24 Dec 2011 15:54:27 +0000 (08:54 -0700)
committerBrian Paul <brianp@vmware.com>
Sat, 24 Dec 2011 16:25:41 +0000 (09:25 -0700)
This gets rid of another renderbuffer->PutRow() call and _DepthBuffer
usage.  We always work with 32-bit uint Z values now.

Reviewed-by: Eric Anholt <eric@anholt.net>
src/mesa/swrast/s_drawpix.c
src/mesa/swrast/s_zoom.c
src/mesa/swrast/s_zoom.h

index a3808ee260053c71b3657747a617f2f84017ace3..4231bb4bdf0ae48629c41674ef924f1564320eca 100644 (file)
@@ -28,6 +28,7 @@
 #include "main/colormac.h"
 #include "main/condrender.h"
 #include "main/context.h"
+#include "main/format_pack.h"
 #include "main/image.h"
 #include "main/imports.h"
 #include "main/macros.h"
@@ -547,7 +548,6 @@ draw_depth_stencil_pixels(struct gl_context *ctx, GLint x, GLint y,
    const GLint imgX = x, imgY = y;
    const GLboolean scaleOrBias
       = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
-   const GLuint depthMax = ctx->DrawBuffer->_DepthMax;
    const GLuint stencilMask = ctx->Stencil.WriteMask[0];
    const GLenum stencilType = GL_UNSIGNED_BYTE;
    const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0;
@@ -585,57 +585,27 @@ draw_depth_stencil_pixels(struct gl_context *ctx, GLint x, GLint y,
       /* XXX need to handle very wide images (skippixels) */
       GLint i;
 
-      depthRb = ctx->DrawBuffer->_DepthBuffer;
-
       for (i = 0; i < height; i++) {
          const GLuint *depthStencilSrc = (const GLuint *)
             _mesa_image_address2d(&clippedUnpack, pixels, width, height,
                                   GL_DEPTH_STENCIL_EXT, type, i, 0);
 
          if (ctx->Depth.Mask) {
-            if (!scaleOrBias && ctx->DrawBuffer->Visual.depthBits == 24 &&
-               type == GL_UNSIGNED_INT_24_8) {
-               /* fast path 24-bit zbuffer */
-               GLuint zValues[MAX_WIDTH];
-               GLint j;
-               ASSERT(depthRb->DataType == GL_UNSIGNED_INT);
-               for (j = 0; j < width; j++) {
-                  zValues[j] = depthStencilSrc[j] >> 8;
-               }
-               if (zoom)
-                  _swrast_write_zoomed_z_span(ctx, imgX, imgY, width,
-                                              x, y + i, zValues);
-               else
-                  depthRb->PutRow(ctx, depthRb, width, x, y + i, zValues,NULL);
-            }
-            else if (!scaleOrBias && ctx->DrawBuffer->Visual.depthBits == 16 &&
-                    type == GL_UNSIGNED_INT_24_8) {
-               /* fast path 16-bit zbuffer */
-               GLushort zValues[MAX_WIDTH];
-               GLint j;
-               ASSERT(depthRb->DataType == GL_UNSIGNED_SHORT);
-               for (j = 0; j < width; j++) {
-                  zValues[j] = depthStencilSrc[j] >> 16;
-               }
-               if (zoom)
-                  _swrast_write_zoomed_z_span(ctx, imgX, imgY, width,
-                                              x, y + i, zValues);
-               else
-                  depthRb->PutRow(ctx, depthRb, width, x, y + i, zValues,NULL);
+            GLuint zValues[MAX_WIDTH];  /* 32-bit Z values */
+            _mesa_unpack_depth_span(ctx, width,
+                                    GL_UNSIGNED_INT, /* dest type */
+                                    zValues,         /* dest addr */
+                                    0xffffffff,      /* depth max */
+                                    type,            /* src type */
+                                    depthStencilSrc, /* src addr */
+                                    &clippedUnpack);
+            if (zoom) {
+               _swrast_write_zoomed_z_span(ctx, imgX, imgY, width, x,
+                                           y + i, zValues);
             }
             else {
-               /* general case */
-               GLuint zValues[MAX_WIDTH];  /* 16 or 32-bit Z value storage */
-               _mesa_unpack_depth_span(ctx, width,
-                                       depthRb->DataType, zValues, depthMax,
-                                       type, depthStencilSrc, &clippedUnpack);
-               if (zoom) {
-                  _swrast_write_zoomed_z_span(ctx, imgX, imgY, width, x,
-                                              y + i, zValues);
-               }
-               else {
-                  depthRb->PutRow(ctx, depthRb, width, x, y + i, zValues,NULL);
-               }
+               GLubyte *dst = _swrast_pixel_address(depthRb, x, y + i);
+               _mesa_pack_uint_z_row(depthRb->Format, width, zValues, dst);
             }
          }
 
index f407fdcf4e69976a87e8f4f4bc1b2f9374cee934..73bff482b9a2dd313929a7f82be9c663362ad1a0 100644 (file)
@@ -25,6 +25,7 @@
 #include "main/glheader.h"
 #include "main/macros.h"
 #include "main/imports.h"
+#include "main/format_pack.h"
 #include "main/colormac.h"
 
 #include "s_context.h"
@@ -390,17 +391,17 @@ _swrast_write_zoomed_stencil_span(struct gl_context *ctx, GLint imgX, GLint imgY
 
 
 /**
- * Zoom/write z values (16 or 32-bit).
+ * Zoom/write 32-bit Z values.
  * No per-fragment operations are applied.
  */
 void
 _swrast_write_zoomed_z_span(struct gl_context *ctx, GLint imgX, GLint imgY,
                             GLint width, GLint spanX, GLint spanY,
-                            const GLvoid *z)
+                            const GLuint *zVals)
 {
-   struct gl_renderbuffer *rb = ctx->DrawBuffer->_DepthBuffer;
-   GLushort zoomedVals16[MAX_WIDTH];
-   GLuint zoomedVals32[MAX_WIDTH];
+   struct gl_renderbuffer *rb =
+      ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
+   GLuint zoomedVals[MAX_WIDTH];
    GLint x0, x1, y0, y1, y;
    GLint i, zoomedWidth;
 
@@ -414,28 +415,16 @@ _swrast_write_zoomed_z_span(struct gl_context *ctx, GLint imgX, GLint imgY,
    ASSERT(zoomedWidth <= MAX_WIDTH);
 
    /* zoom the span horizontally */
-   if (rb->DataType == GL_UNSIGNED_SHORT) {
-      for (i = 0; i < zoomedWidth; i++) {
-         GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - spanX;
-         ASSERT(j >= 0);
-         ASSERT(j < width);
-         zoomedVals16[i] = ((GLushort *) z)[j];
-      }
-      z = zoomedVals16;
-   }
-   else {
-      ASSERT(rb->DataType == GL_UNSIGNED_INT);
-      for (i = 0; i < zoomedWidth; i++) {
-         GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - spanX;
-         ASSERT(j >= 0);
-         ASSERT(j < width);
-         zoomedVals32[i] = ((GLuint *) z)[j];
-      }
-      z = zoomedVals32;
+   for (i = 0; i < zoomedWidth; i++) {
+      GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - spanX;
+      ASSERT(j >= 0);
+      ASSERT(j < width);
+      zoomedVals[i] = zVals[j];
    }
 
    /* write the zoomed spans */
    for (y = y0; y < y1; y++) {
-      rb->PutRow(ctx, rb, zoomedWidth, x0, y, z, NULL);
+      GLubyte *dst = _swrast_pixel_address(rb, x0, y);
+      _mesa_pack_uint_z_row(rb->Format, zoomedWidth, zoomedVals, dst);
    }
 }
index 0b82bb82471f349bd410985bc34cc6fcc2ad1d91..1955e7e88390dc34002aefedca8320f478ee4a3d 100644 (file)
@@ -50,7 +50,7 @@ _swrast_write_zoomed_stencil_span(struct gl_context *ctx, GLint imgX, GLint imgY
 extern void
 _swrast_write_zoomed_z_span(struct gl_context *ctx, GLint imgX, GLint imgY,
                             GLint width, GLint spanX, GLint spanY,
-                            const GLvoid *z);
+                            const GLuint *zVals);
 
 
 #endif