Mesa (master): mesa: Add indexed binding points for uniform buffer objects.

Eric Anholt anholt at kemper.freedesktop.org
Thu Jun 21 18:06:52 UTC 2012


Module: Mesa
Branch: master
Commit: 5527c2d22027e9e27e55372d8adf2ba4ff855b53
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=5527c2d22027e9e27e55372d8adf2ba4ff855b53

Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jun 14 16:37:22 2012 -0700

mesa: Add indexed binding points for uniform buffer objects.

Reviewed-by: Brian Paul <brianp at vmware.com>
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

---

 src/mesa/main/bufferobj.c |   29 +++++++++++++++++++++++++++++
 src/mesa/main/mtypes.h    |   22 ++++++++++++++++++++++
 2 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index b646baa..3fc2908 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -603,6 +603,8 @@ _mesa_copy_buffer_subdata(struct gl_context *ctx,
 void
 _mesa_init_buffer_objects( struct gl_context *ctx )
 {
+   GLuint i;
+
    memset(&DummyBufferObject, 0, sizeof(DummyBufferObject));
    _glthread_INIT_MUTEX(DummyBufferObject.Mutex);
    DummyBufferObject.RefCount = 1000*1000*1000; /* never delete */
@@ -614,16 +616,43 @@ _mesa_init_buffer_objects( struct gl_context *ctx )
                                  ctx->Shared->NullBufferObj);
    _mesa_reference_buffer_object(ctx, &ctx->CopyWriteBuffer,
                                  ctx->Shared->NullBufferObj);
+
+   ctx->UniformBufferBindings = calloc(ctx->Const.MaxUniformBufferBindings,
+				      sizeof(*ctx->UniformBufferBindings));
+
+   _mesa_reference_buffer_object(ctx, &ctx->UniformBuffer,
+				 ctx->Shared->NullBufferObj);
+
+   for (i = 0; i < ctx->Const.MaxUniformBufferBindings; i++) {
+      _mesa_reference_buffer_object(ctx,
+				    &ctx->UniformBufferBindings[i].BufferObject,
+				    ctx->Shared->NullBufferObj);
+      ctx->UniformBufferBindings[i].Offset = -1;
+      ctx->UniformBufferBindings[i].Size = -1;
+   }
 }
 
 
 void
 _mesa_free_buffer_objects( struct gl_context *ctx )
 {
+   GLuint i;
+
    _mesa_reference_buffer_object(ctx, &ctx->Array.ArrayBufferObj, NULL);
 
    _mesa_reference_buffer_object(ctx, &ctx->CopyReadBuffer, NULL);
    _mesa_reference_buffer_object(ctx, &ctx->CopyWriteBuffer, NULL);
+
+   _mesa_reference_buffer_object(ctx, &ctx->UniformBuffer, NULL);
+
+   for (i = 0; i < ctx->Const.MaxUniformBufferBindings; i++) {
+      _mesa_reference_buffer_object(ctx,
+				    &ctx->UniformBufferBindings[i].BufferObject,
+				    NULL);
+   }
+
+   free(ctx->UniformBufferBindings);
+   ctx->UniformBufferBindings = NULL;
 }
 
 
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index cf6d9c1..def0db1 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -3295,6 +3295,20 @@ struct gl_driver_flags
    GLbitfield NewArray;             /**< Vertex array state */
 };
 
+struct gl_uniform_buffer_binding
+{
+   struct gl_buffer_object *BufferObject;
+   /** Start of uniform block data in the buffer */
+   GLintptr Offset;
+   /** Size of data allowed to be referenced from the buffer (in bytes) */
+   GLsizeiptr Size;
+   /**
+    * glBindBufferBase() indicates that the Size should be ignored and only
+    * limited by the current size of the BufferObject.
+    */
+   GLboolean AutomaticSize;
+};
+
 /**
  * Mesa rendering context.
  *
@@ -3437,6 +3451,14 @@ struct gl_context
     */
    struct gl_buffer_object *UniformBuffer;
 
+   /**
+    * Array of uniform buffers for GL_ARB_uniform_buffer_object and GL 3.1.
+    * This is set up using glBindBufferRange() or glBindBufferBase().  They are
+    * associated with uniform blocks by glUniformBlockBinding()'s state in the
+    * shader program.
+    */
+   struct gl_uniform_buffer_binding *UniformBufferBindings;
+
    /*@}*/
 
    struct gl_meta_state *Meta;  /**< for "meta" operations */




More information about the mesa-commit mailing list