[Mesa-dev] [PATCH 1/2] st/mesa: allow creating buffers of size = 0

Brian Paul brianp at vmware.com
Sat Nov 12 12:26:11 PST 2011


Calling glBufferData(size=0) is legal.  Instead of no-oping it, go ahead
and create a gallium buffer of size zero.  This lets us avoid a bunch of
NULL pointer checking elsewhere.  In the case of a zero-sized VBO, the
bounds checking we do later will prevent invalid memory accesses.
---
 src/mesa/state_tracker/st_cb_bufferobjects.c |   22 +++++++++-------------
 1 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c
index adac92f..3abf029 100644
--- a/src/mesa/state_tracker/st_cb_bufferobjects.c
+++ b/src/mesa/state_tracker/st_cb_bufferobjects.c
@@ -221,21 +221,17 @@ st_bufferobj_data(struct gl_context *ctx,
 
    pipe_resource_reference( &st_obj->buffer, NULL );
 
-   if (size != 0) {
-      st_obj->buffer = pipe_buffer_create(pipe->screen, bind,
-                                          pipe_usage, size);
-
-      if (!st_obj->buffer) {
-         /* out of memory */
-         st_obj->Base.Size = 0;
-         return GL_FALSE;
-      }
-
-      if (data)
-         pipe_buffer_write(pipe, st_obj->buffer, 0, size, data);
-      return GL_TRUE;
+   st_obj->buffer = pipe_buffer_create(pipe->screen, bind, pipe_usage, size);
+
+   if (!st_obj->buffer) {
+      /* out of memory */
+      st_obj->Base.Size = 0;
+      return GL_FALSE;
    }
 
+   if (data && size > 0)
+      pipe_buffer_write(pipe, st_obj->buffer, 0, size, data);
+
    return GL_TRUE;
 }
 
-- 
1.7.3.4



More information about the mesa-dev mailing list