Allow the software fallback glDrawPixels, glReadPixels, glBitmap commands to
authorBrian Paul <brian.paul@tungstengraphics.com>
Sun, 31 Oct 2004 15:39:04 +0000 (15:39 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Sun, 31 Oct 2004 15:39:04 +0000 (15:39 +0000)
work with real, hardware-based PBOs in the future by mapping/unmapping the
PBO buffer as needed.

src/mesa/swrast/s_bitmap.c
src/mesa/swrast/s_drawpix.c
src/mesa/swrast/s_readpix.c

index 8bd9854f0ca9bf68df1238ddfd896e5126df673e..be728911b69847d260f89e2be315932fe39aeb08 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(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);
@@ -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);
+   }
 }
 
 
index 205022a89d63035595f0fa1eeb76983a60651b47..00cc5e83c0954dfa3361f48263417b8768c9f54f 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.2
+ * Version:  6.3
  *
  * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
  *
@@ -24,6 +24,7 @@
 
 
 #include "glheader.h"
+#include "bufferobj.h"
 #include "context.h"
 #include "convolve.h"
 #include "image.h"
@@ -931,10 +932,25 @@ _swrast_DrawPixels( GLcontext *ctx,
    if (swrast->NewState)
       _swrast_validate_derived( ctx );
 
-   pixels = _swrast_validate_pbo_access(unpack, width, height, 1,
-                                        format, type, (GLvoid *) pixels);
-   if (!pixels)
-      return;
+   if (unpack->BufferObj->Name) {
+      /* unpack from PBO */
+      GLubyte *buf;
+      if (!_mesa_validate_pbo_access(unpack, width, height, 1,
+                                     format, type, pixels)) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "glDrawPixels(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, "glDrawPixels(PBO is mapped)");
+         return;
+      }
+      pixels = ADD_POINTERS(buf, pixels);
+   }
 
    RENDER_START(swrast,ctx);
 
@@ -966,9 +982,16 @@ _swrast_DrawPixels( GLcontext *ctx,
       break;
    default:
       _mesa_error( ctx, GL_INVALID_ENUM, "glDrawPixels(format)" );
+      /* don't return yet, clean-up */
    }
 
    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);
+   }
 }
 
 
index 80f737b052a3938c11f07e38b281061a0dfbfd43..39fac522786db35f72d7505308dfd257c1b66412 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.
  *
@@ -24,6 +24,7 @@
 
 
 #include "glheader.h"
+#include "bufferobj.h"
 #include "colormac.h"
 #include "convolve.h"
 #include "context.h"
@@ -507,15 +508,27 @@ _swrast_ReadPixels( GLcontext *ctx,
    if (swrast->NewState)
       _swrast_validate_derived( ctx );
 
-   pixels = _swrast_validate_pbo_access(pack, width, height, 1,
-                                        format, type, (GLvoid *) pixels);
-
-   if (!pixels) {
-      _mesa_error( ctx, GL_INVALID_VALUE, "glReadPixels(pixels)" );
-      return;
+   if (pack->BufferObj->Name) {
+      /* pack into PBO */
+      GLubyte *buf;
+      if (!_mesa_validate_pbo_access(pack, width, height, 1,
+                                     format, type, pixels)) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "glReadPixels(invalid PBO access)");
+         return;
+      }
+      buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
+                                              GL_WRITE_ONLY_ARB,
+                                              pack->BufferObj);
+      if (!buf) {
+         /* buffer is already mapped - that's an error */
+         _mesa_error(ctx, GL_INVALID_OPERATION, "glReadPixels(PBO is mapped)");
+         return;
+      }
+      pixels = ADD_POINTERS(buf, pixels);
    }
 
-   RENDER_START(swrast,ctx);
+   RENDER_START(swrast, ctx);
 
    switch (format) {
       case GL_COLOR_INDEX:
@@ -543,7 +556,14 @@ _swrast_ReadPixels( GLcontext *ctx,
         break;
       default:
         _mesa_error( ctx, GL_INVALID_ENUM, "glReadPixels(format)" );
+         /* don't return yet, clean-up */
    }
 
-   RENDER_FINISH(swrast,ctx);
+   RENDER_FINISH(swrast, ctx);
+
+   if (pack->BufferObj->Name) {
+      /* done with PBO so unmap it now */
+      ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
+                              pack->BufferObj);
+   }
 }