summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2012-06-14 19:48:02 -0700
committerEric Anholt <[email protected]>2012-06-21 10:58:07 -0700
commitfb76ddc13384bc04ee093c8fc20eab5705067359 (patch)
tree1fc3ccd54ad273802b9a57412571566ef10b226b /src
parentb82c47215689d1243d1aa810bff7f06d8288d686 (diff)
mesa: Add support for glBindBufferBase/Range on GL_UNIFORM_BUFFER.
Fixes piglits: GL_ARB_uniform_buffer_object/bindbuffer-general-point. GL_ARB_uniform_buffer_object/negative-bindbuffer-buffer GL_ARB_uniform_buffer_object/negative-bindbuffer-index GL_ARB_uniform_buffer_object/negative-bindbuffer-target GL_ARB_uniform_buffer_object/negative-bindbufferrange-range Reviewed-by: Brian Paul <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/mesa/main/bufferobj.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index 2e34744e8b8..d0d98027aad 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -1994,6 +1994,85 @@ _mesa_GetObjectParameterivAPPLE(GLenum objectType, GLuint name, GLenum pname,
#endif /* FEATURE_APPLE_object_purgeable */
+static void
+set_ubo_binding(struct gl_context *ctx,
+ int index,
+ struct gl_buffer_object *bufObj,
+ GLintptr offset,
+ GLsizeiptr size,
+ GLboolean autoSize)
+{
+ struct gl_uniform_buffer_binding *binding;
+
+ binding = &ctx->UniformBufferBindings[index];
+ if (binding->BufferObject == bufObj &&
+ binding->Offset == offset &&
+ binding->Size == size &&
+ binding->AutomaticSize == autoSize) {
+ return;
+ }
+
+ FLUSH_VERTICES(ctx, _NEW_BUFFER_OBJECT);
+
+ _mesa_reference_buffer_object(ctx, &binding->BufferObject, bufObj);
+ binding->Offset = offset;
+ binding->Size = size;
+ binding->AutomaticSize = autoSize;
+}
+
+/**
+ * Specify a buffer object to receive vertex shader results. Plus,
+ * specify the starting offset to place the results, and max size.
+ */
+static void
+bind_buffer_range_uniform_buffer(struct gl_context *ctx,
+ GLuint index,
+ struct gl_buffer_object *bufObj,
+ GLintptr offset,
+ GLsizeiptr size)
+{
+ if (index >= ctx->Const.MaxUniformBufferBindings) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferRange(index=%d)", index);
+ return;
+ }
+
+ if (offset & (ctx->Const.UniformBufferOffsetAlignment - 1)) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glBindBufferRange(offset misalgned %d/%d)", (int) offset,
+ ctx->Const.UniformBufferOffsetAlignment);
+ return;
+ }
+
+ if (bufObj == ctx->Shared->NullBufferObj) {
+ offset = -1;
+ size = -1;
+ }
+
+ _mesa_reference_buffer_object(ctx, &ctx->UniformBuffer, bufObj);
+ set_ubo_binding(ctx, index, bufObj, offset, size, GL_FALSE);
+}
+
+
+/**
+ * Specify a buffer object to receive vertex shader results.
+ * As above, but start at offset = 0.
+ */
+static void
+bind_buffer_base_uniform_buffer(struct gl_context *ctx,
+ GLuint index,
+ struct gl_buffer_object *bufObj)
+{
+ if (index >= ctx->Const.MaxUniformBufferBindings) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferBase(index=%d)", index);
+ return;
+ }
+
+ _mesa_reference_buffer_object(ctx, &ctx->UniformBuffer, bufObj);
+ if (bufObj == ctx->Shared->NullBufferObj)
+ set_ubo_binding(ctx, index, bufObj, -1, -1, GL_TRUE);
+ else
+ set_ubo_binding(ctx, index, bufObj, 0, 0, GL_TRUE);
+}
void GLAPIENTRY
_mesa_BindBufferRange(GLenum target, GLuint index,
@@ -2032,6 +2111,9 @@ _mesa_BindBufferRange(GLenum target, GLuint index,
_mesa_bind_buffer_range_transform_feedback(ctx, index, bufObj,
offset, size);
return;
+ case GL_UNIFORM_BUFFER:
+ bind_buffer_range_uniform_buffer(ctx, index, bufObj, offset, size);
+ return;
default:
_mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferRange(target)");
return;
@@ -2060,6 +2142,9 @@ _mesa_BindBufferBase(GLenum target, GLuint index, GLuint buffer)
case GL_TRANSFORM_FEEDBACK_BUFFER:
_mesa_bind_buffer_base_transform_feedback(ctx, index, bufObj);
return;
+ case GL_UNIFORM_BUFFER:
+ bind_buffer_base_uniform_buffer(ctx, index, bufObj);
+ return;
default:
_mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferBase(target)");
return;