GL_(UN)PACK_SKIP_IMAGES should only be applied to 3D texture pack/unpacking
[mesa.git] / src / mesa / swrast / s_bitmap.c
index 8bd9854f0ca9bf68df1238ddfd896e5126df673e..1afb4875468febeb30b7448697290a5ce07d6acf 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.1
+ * Version:  6.3
  *
  * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
  *
@@ -29,6 +29,7 @@
  */
 
 #include "glheader.h"
+#include "bufferobj.h"
 #include "image.h"
 #include "macros.h"
 #include "pixel.h"
@@ -54,13 +55,24 @@ _swrast_Bitmap( GLcontext *ctx, GLint px, GLint py,
 
    ASSERT(ctx->RenderMode == GL_RENDER);
 
-   bitmap = (const GLubyte *) _swrast_validate_pbo_access(unpack, width,
-                                        height, 1,
-                                        GL_COLOR_INDEX, GL_BITMAP,
-                                        (GLvoid *) bitmap);
-   if (!bitmap) {
-      /* XXX GL_INVALID_OPERATION? */
-      return;
+   if (unpack->BufferObj->Name) {
+      /* unpack from PBO */
+      GLubyte *buf;
+      if (!_mesa_validate_pbo_access(2, unpack, width, height, 1,
+                                     GL_COLOR_INDEX, GL_BITMAP,
+                                     (GLvoid *) bitmap)) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,"glBitmap(invalid PBO access)");
+         return;
+      }
+      buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
+                                              GL_READ_ONLY_ARB,
+                                              unpack->BufferObj);
+      if (!buf) {
+         /* buffer is already mapped - that's an error */
+         _mesa_error(ctx, GL_INVALID_OPERATION, "glBitmap(PBO is mapped)");
+         return;
+      }
+      bitmap = ADD_POINTERS(buf, bitmap);
    }
 
    RENDER_START(swrast,ctx);
@@ -92,8 +104,8 @@ _swrast_Bitmap( GLcontext *ctx, GLint px, GLint py,
       _swrast_span_default_texcoords(ctx, &span);
 
    for (row = 0; row < height; row++, span.y++) {
-      const GLubyte *src = (const GLubyte *) _mesa_image_addressunpack,
-                 bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, 0, row, 0 );
+      const GLubyte *src = (const GLubyte *) _mesa_image_address2d(unpack,
+                 bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0);
 
       if (unpack->LsbFirst) {
          /* Lsb first */
@@ -153,6 +165,12 @@ _swrast_Bitmap( GLcontext *ctx, GLint px, GLint py,
    }
 
    RENDER_FINISH(swrast,ctx);
+
+   if (unpack->BufferObj->Name) {
+      /* done with PBO so unmap it now */
+      ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
+                              unpack->BufferObj);
+   }
 }
 
 
@@ -208,8 +226,8 @@ _swrast_Bitmap( GLcontext *ctx, GLint px, GLint py,
       _swrast_span_default_texcoords(ctx, &span);
 
    for (row=0; row<height; row++, span.y++) {
-      const GLubyte *src = (const GLubyte *) _mesa_image_addressunpack,
-                 bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, 0, row, 0 );
+      const GLubyte *src = (const GLubyte *) _mesa_image_address2d(unpack,
+                 bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0);
 
       if (unpack->LsbFirst) {
          /* Lsb first */