swrast: Use BITFIELD64_BIT for arrayAttribs.
[mesa.git] / src / mesa / swrast / s_drawpix.c
index 41b50ab71b3a6c0c356ee59c08a4a1c0ef8715ce..bf427266cef69a458e5b4425e9638b1ccc84330a 100644 (file)
@@ -1,6 +1,5 @@
 /*
  * Mesa 3-D graphics library
- * Version:  7.1
  *
  * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
@@ -30,6 +29,8 @@
 #include "main/condrender.h"
 #include "main/context.h"
 #include "main/format_pack.h"
+#include "main/format_utils.h"
+#include "main/glformats.h"
 #include "main/image.h"
 #include "main/imports.h"
 #include "main/macros.h"
@@ -224,8 +225,8 @@ fast_draw_rgba_pixels(struct gl_context *ctx, GLint x, GLint y,
 
    if (format == GL_RGB &&
        type == GL_UNSIGNED_BYTE &&
-       (rb->Format == MESA_FORMAT_XRGB8888 ||
-        rb->Format == MESA_FORMAT_ARGB8888)) {
+       (rb->Format == MESA_FORMAT_B8G8R8X8_UNORM ||
+        rb->Format == MESA_FORMAT_B8G8R8A8_UNORM)) {
       fast_draw_rgb_ubyte_pixels(ctx, rb, x, y, width, height,
                                  &unpack, pixels);
       return GL_TRUE;
@@ -233,8 +234,8 @@ fast_draw_rgba_pixels(struct gl_context *ctx, GLint x, GLint y,
 
    if (format == GL_RGBA &&
        type == GL_UNSIGNED_BYTE &&
-       (rb->Format == MESA_FORMAT_XRGB8888 ||
-        rb->Format == MESA_FORMAT_ARGB8888)) {
+       (rb->Format == MESA_FORMAT_B8G8R8X8_UNORM ||
+        rb->Format == MESA_FORMAT_B8G8R8A8_UNORM)) {
       fast_draw_rgba_ubyte_pixels(ctx, rb, x, y, width, height,
                                   &unpack, pixels);
       return GL_TRUE;
@@ -372,7 +373,7 @@ draw_depth_pixels( struct gl_context *ctx, GLint x, GLint y,
       while (skipPixels < width) {
          const GLint spanWidth = MIN2(width - skipPixels, SWRAST_MAX_WIDTH);
          GLint row;
-         ASSERT(span.end <= SWRAST_MAX_WIDTH);
+         assert(span.end <= SWRAST_MAX_WIDTH);
          for (row = 0; row < height; row++) {
             const GLvoid *zSrc = _mesa_image_address2d(unpack,
                                                       pixels, width, height,
@@ -415,7 +416,6 @@ draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint y,
 {
    const GLint imgX = x, imgY = y;
    const GLboolean zoom = ctx->Pixel.ZoomX!=1.0 || ctx->Pixel.ZoomY!=1.0;
-   GLfloat *convImage = NULL;
    GLbitfield transferOps = ctx->_ImageTransferState;
    SWspan span;
 
@@ -453,6 +453,28 @@ draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint y,
       GLint skipPixels = 0;
       /* use span array for temp color storage */
       GLfloat *rgba = (GLfloat *) span.array->attribs[VARYING_SLOT_COL0];
+      void *tempImage = NULL;
+
+      if (unpack->SwapBytes) {
+         /* We have to handle byte-swapping scenarios before calling
+          * _mesa_format_convert
+          */
+         GLint swapSize = _mesa_sizeof_packed_type(type);
+         if (swapSize == 2 || swapSize == 4) {
+            int components = _mesa_components_in_format(format);
+            int elementCount = width * height * components;
+            tempImage = malloc(elementCount * swapSize);
+            if (!tempImage) {
+               _mesa_error(ctx, GL_OUT_OF_MEMORY, "glDrawPixels");
+               return;
+            }
+            if (swapSize == 2)
+               _mesa_swap2_copy(tempImage, (GLushort *) pixels, elementCount);
+            else
+               _mesa_swap4_copy(tempImage, (GLuint *) pixels, elementCount);
+            pixels = tempImage;
+         }
+      }
 
       /* if the span is wider than SWRAST_MAX_WIDTH we have to do it in chunks */
       while (skipPixels < width) {
@@ -463,11 +485,15 @@ draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint y,
                                                       type, 0, skipPixels);
          GLint row;
 
+         /* get image row as float/RGBA */
+         uint32_t srcMesaFormat = _mesa_format_from_format_and_type(format, type);
          for (row = 0; row < height; row++) {
-            /* get image row as float/RGBA */
-            _mesa_unpack_color_span_float(ctx, spanWidth, GL_RGBA, rgba,
-                                     format, type, source, unpack,
-                                     transferOps);
+            int dstRowStride = 4 * width * sizeof(float);
+            _mesa_format_convert(rgba, RGBA32_FLOAT, dstRowStride,
+                                 (void*)source, srcMesaFormat, srcStride,
+                                 spanWidth, 1, NULL);
+            if (transferOps)
+               _mesa_apply_rgba_transfer_ops(ctx, transferOps, spanWidth, (GLfloat (*)[4])rgba);
            /* Set these for each row since the _swrast_write_* functions
             * may change them while clipping/rendering.
             */
@@ -492,16 +518,16 @@ draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint y,
 
       /* XXX this is ugly/temporary, to undo above change */
       span.array->ChanType = CHAN_TYPE;
-   }
 
-   free(convImage);
+      free(tempImage);
+   }
 
    swrast_render_finish(ctx);
 }
 
 
 /**
- * Draw depth+stencil values into a MESA_FORAMT_Z24_S8 or MESA_FORMAT_S8_Z24
+ * Draw depth+stencil values into a MESA_FORAMT_Z24_S8 or MESA_FORMAT_Z24_UNORM_S8_UINT
  * renderbuffer.  No masking, zooming, scaling, etc.
  */
 static void
@@ -569,12 +595,12 @@ draw_depth_stencil_pixels(struct gl_context *ctx, GLint x, GLint y,
    
    depthRb = ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
    stencilRb = ctx->ReadBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
-   ASSERT(depthRb);
-   ASSERT(stencilRb);
+   assert(depthRb);
+   assert(stencilRb);
 
    if (depthRb == stencilRb &&
-       (depthRb->Format == MESA_FORMAT_Z24_S8 ||
-        depthRb->Format == MESA_FORMAT_S8_Z24) &&
+       (depthRb->Format == MESA_FORMAT_S8_UINT_Z24_UNORM ||
+        depthRb->Format == MESA_FORMAT_Z24_UNORM_S8_UINT) &&
        type == GL_UNSIGNED_INT_24_8 &&
        !scaleOrBias &&
        !zoom &&