[Mesa-dev] [PATCH 1/3] mesa: Fix the core GL genned-name handling for glBindBufferBase()/Range().

Eric Anholt eric at anholt.net
Wed Oct 31 18:10:31 PDT 2012


This is part of fixing gl-3.1/genned-names.
---
 src/mesa/main/bufferobj.c |   20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index ac58c99..2f43eb0 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -660,7 +660,7 @@ _mesa_free_buffer_objects( struct gl_context *ctx )
    ctx->UniformBufferBindings = NULL;
 }
 
-static void
+static bool
 handle_bind_buffer_gen(struct gl_context *ctx,
 		       GLenum target,
 		       GLuint buffer,
@@ -668,6 +668,11 @@ handle_bind_buffer_gen(struct gl_context *ctx,
 {
    struct gl_buffer_object *buf = *buf_handle;
 
+   if (!buf && ctx->API == API_OPENGL_CORE) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glBindBuffer(non-gen name)");
+      return false;
+   }
+
    if (!buf || buf == &DummyBufferObject) {
       /* If this is a new buffer object id, or one which was generated but
        * never used before, allocate a buffer object now.
@@ -681,6 +686,8 @@ handle_bind_buffer_gen(struct gl_context *ctx,
       _mesa_HashInsert(ctx->Shared->BufferObjects, buffer, buf);
       *buf_handle = buf;
    }
+
+   return true;
 }
 
 /**
@@ -717,11 +724,8 @@ bind_buffer_object(struct gl_context *ctx, GLenum target, GLuint buffer)
    else {
       /* non-default buffer object */
       newBufObj = _mesa_lookup_bufferobj(ctx, buffer);
-      if (newBufObj == NULL && ctx->API == API_OPENGL_CORE) {
-         _mesa_error(ctx, GL_INVALID_OPERATION, "glBindBuffer(non-gen name)");
+      if (!handle_bind_buffer_gen(ctx, target, buffer, &newBufObj))
          return;
-      }
-      handle_bind_buffer_gen(ctx, target, buffer, &newBufObj);
    }
    
    /* bind new buffer */
@@ -2147,7 +2151,8 @@ _mesa_BindBufferRange(GLenum target, GLuint index,
    } else {
       bufObj = _mesa_lookup_bufferobj(ctx, buffer);
    }
-   handle_bind_buffer_gen(ctx, target, buffer, &bufObj);
+   if (!handle_bind_buffer_gen(ctx, target, buffer, &bufObj))
+      return;
 
    if (!bufObj) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
@@ -2193,7 +2198,8 @@ _mesa_BindBufferBase(GLenum target, GLuint index, GLuint buffer)
    } else {
       bufObj = _mesa_lookup_bufferobj(ctx, buffer);
    }
-   handle_bind_buffer_gen(ctx, target, buffer, &bufObj);
+   if (!handle_bind_buffer_gen(ctx, target, buffer, &bufObj))
+      return;
 
    if (!bufObj) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
-- 
1.7.10.4



More information about the mesa-dev mailing list