st/mesa: fix mapping of zero-sized buffer objects
authorBrian Paul <brianp@vmware.com>
Fri, 26 Nov 2010 20:42:23 +0000 (13:42 -0700)
committerBrian Paul <brianp@vmware.com>
Fri, 26 Nov 2010 20:48:49 +0000 (13:48 -0700)
Fixes http://bugs.freedesktop.org/show_bug.cgi?id=31934

src/mesa/state_tracker/st_cb_bufferobjects.c

index 27540c36ce7013ddd56a265831ab30b01685d246..73c9c2de7a189f96c2f2c82677bea0fd2180ab73 100644 (file)
@@ -210,6 +210,13 @@ st_bufferobj_data(struct gl_context *ctx,
 }
 
 
+/**
+ * Dummy data whose's pointer is used for zero size buffers or ranges.
+ */
+static long st_bufferobj_zero_length = 0;
+
+
+
 /**
  * Called via glMapBufferARB().
  */
@@ -233,10 +240,16 @@ st_bufferobj_map(struct gl_context *ctx, GLenum target, GLenum access,
       break;      
    }
 
-   obj->Pointer = pipe_buffer_map(st_context(ctx)->pipe,
-                                  st_obj->buffer,
-                                  flags,
-                                  &st_obj->transfer);
+   /* Handle zero-size buffers here rather than in drivers */
+   if (obj->Size == 0) {
+      obj->Pointer = &st_bufferobj_zero_length;
+   }
+   else {
+      obj->Pointer = pipe_buffer_map(st_context(ctx)->pipe,
+                                     st_obj->buffer,
+                                     flags,
+                                     &st_obj->transfer);
+   }
 
    if (obj->Pointer) {
       obj->Offset = 0;
@@ -246,13 +259,6 @@ st_bufferobj_map(struct gl_context *ctx, GLenum target, GLenum access,
 }
 
 
-/**
- * Dummy data whose's pointer is used for zero length ranges.
- */
-static long
-st_bufferobj_zero_length_range = 0;
-
-
 /**
  * Called via glMapBufferRange().
  */
@@ -293,7 +299,7 @@ st_bufferobj_map_range(struct gl_context *ctx, GLenum target,
     * length range from the pipe driver.
     */
    if (!length) {
-      obj->Pointer = &st_bufferobj_zero_length_range;
+      obj->Pointer = &st_bufferobj_zero_length;
    }
    else {
       obj->Pointer = pipe_buffer_map_range(pipe,