Merge commit 'origin/gallium-0.1'
[mesa.git] / src / mesa / swrast / s_readpix.c
index 15dc8106b4a9f3ecc08e7eda60b54addcdf2d29b..e901fc6b5dcdd2d66fc648f3beda019627ad6d98 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5.3
+ * Version:  7.0.3
  *
  * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
  */
 
 
-#include "glheader.h"
-#include "bufferobj.h"
-#include "colormac.h"
-#include "convolve.h"
-#include "context.h"
-#include "feedback.h"
-#include "image.h"
-#include "macros.h"
-#include "imports.h"
-#include "pixel.h"
-#include "state.h"
+#include "main/glheader.h"
+#include "main/bufferobj.h"
+#include "main/colormac.h"
+#include "main/convolve.h"
+#include "main/context.h"
+#include "main/feedback.h"
+#include "main/image.h"
+#include "main/macros.h"
+#include "main/imports.h"
+#include "main/pixel.h"
+#include "main/state.h"
 
 #include "s_context.h"
 #include "s_depth.h"
@@ -119,7 +119,7 @@ read_depth_pixels( GLcontext *ctx,
             && !biasOrScale && !packing->SwapBytes) {
       /* Special case: directly read 24-bit unsigned depth values. */
       GLint j;
-      ASSERT(rb->InternalFormat == GL_DEPTH_COMPONENT32);
+      ASSERT(rb->InternalFormat == GL_DEPTH_COMPONENT24);
       ASSERT(rb->DataType == GL_UNSIGNED_INT);
       for (j = 0; j < height; j++, y++) {
          GLuint *dest = (GLuint *)
@@ -129,7 +129,8 @@ read_depth_pixels( GLcontext *ctx,
          rb->GetRow(ctx, rb, width, x, y, dest);
          /* convert range from 24-bit to 32-bit */
          for (k = 0; k < width; k++) {
-            dest[k] = (dest[k] << 8) | (dest[k] >> 24);
+            /* Note: put MSByte of 24-bit value into LSByte */
+            dest[k] = (dest[k] << 8) | ((dest[k] >> 16) & 0xff);
          }
       }
    }
@@ -404,12 +405,16 @@ read_rgba_pixels( GLcontext *ctx,
       /* no convolution */
       const GLint dstStride
          = _mesa_image_row_stride(packing, width, format, type);
-      GLfloat (*rgba)[4] = swrast->SpanArrays->color.sz4.rgba;
+      GLfloat (*rgba)[4] = swrast->SpanArrays->attribs[FRAG_ATTRIB_COL0];
       GLint row;
       GLubyte *dst
          = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
                                              format, type, 0, 0);
 
+      /* make sure we don't apply 1D convolution */
+      transferOps &= ~(IMAGE_CONVOLUTION_BIT |
+                       IMAGE_POST_CONVOLUTION_SCALE_BIAS);
+
       for (row = 0; row < height; row++, y++) {
 
          /* Get float rgba pixels */
@@ -550,11 +555,11 @@ _swrast_ReadPixels( GLcontext *ctx,
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
    struct gl_pixelstore_attrib clippedPacking = *packing;
 
-   /* Need to do RENDER_START before clipping or anything else since this
-    * is where a driver may grab the hw lock and get an updated window
-    * size.
+   /* Need to do swrast_render_start() before clipping or anything else
+    * since this is where a driver may grab the hw lock and get an updated
+    * window size.
     */
-   RENDER_START(swrast, ctx);
+   swrast_render_start(ctx);
 
    if (ctx->NewState)
       _mesa_update_state(ctx);
@@ -565,29 +570,14 @@ _swrast_ReadPixels( GLcontext *ctx,
    /* Do all needed clipping here, so that we can forget about it later */
    if (!_mesa_clip_readpixels(ctx, &x, &y, &width, &height, &clippedPacking)) {
       /* The ReadPixels region is totally outside the window bounds */
-      goto end;
-   }
-
-   if (clippedPacking.BufferObj->Name) {
-      /* pack into PBO */
-      GLubyte *buf;
-      if (!_mesa_validate_pbo_access(2, &clippedPacking, width, height, 1,
-                                     format, type, pixels)) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glReadPixels(invalid PBO access)");
-         goto end;
-      }
-      buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
-                                              GL_WRITE_ONLY_ARB,
-                                              clippedPacking.BufferObj);
-      if (!buf) {
-         /* buffer is already mapped - that's an error */
-         _mesa_error(ctx, GL_INVALID_OPERATION, "glReadPixels(PBO is mapped)");
-         goto end;
-      }
-      pixels = ADD_POINTERS(buf, pixels);
+      swrast_render_finish(ctx);
+      return;
    }
 
+   pixels = _mesa_map_readpix_pbo(ctx, &clippedPacking, pixels);
+   if (!pixels)
+      return;
+  
    switch (format) {
       case GL_COLOR_INDEX:
          read_index_pixels(ctx, x, y, width, height, type, pixels,
@@ -624,13 +614,7 @@ _swrast_ReadPixels( GLcontext *ctx,
          /* don't return yet, clean-up */
    }
 
+   swrast_render_finish(ctx);
 
-end:
-   RENDER_FINISH(swrast, ctx);
-
-   if (clippedPacking.BufferObj->Name) {
-      /* done with PBO so unmap it now */
-      ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
-                              clippedPacking.BufferObj);
-   }
+   _mesa_unmap_readpix_pbo(ctx, &clippedPacking);
 }