[Mesa-dev] [PATCH 2/3] mesa: rework bind_buffer_object()
Timothy Arceri
tarceri at itsqueeze.com
Wed Apr 5 01:41:26 UTC 2017
This allows internal users to pass buffer objects directly and
alows for KHR_no_error support in the following patch.
---
src/mesa/main/bufferobj.c | 34 ++++++++++++++++------------------
1 file changed, 16 insertions(+), 18 deletions(-)
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index eca86aa..9669f8a 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -1006,32 +1006,27 @@ _mesa_handle_bind_buffer_gen(struct gl_context *ctx,
}
return true;
}
/**
* Bind the specified target to buffer for the specified context.
* Called by glBindBuffer() and other functions.
*/
static void
-bind_buffer_object(struct gl_context *ctx, GLenum target, GLuint buffer)
+bind_buffer_object(struct gl_context *ctx,
+ struct gl_buffer_object **bindTarget, GLuint buffer)
{
struct gl_buffer_object *oldBufObj;
struct gl_buffer_object *newBufObj = NULL;
- struct gl_buffer_object **bindTarget = NULL;
- bindTarget = get_buffer_target(ctx, target);
- if (!bindTarget) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferARB(target %s)",
- _mesa_enum_to_string(target));
- return;
- }
+ assert(bindTarget);
/* Get pointer to old buffer object (to be unbound) */
oldBufObj = *bindTarget;
if (oldBufObj && oldBufObj->Name == buffer && !oldBufObj->DeletePending)
return; /* rebinding the same buffer object- no change */
/*
* Get pointer to new buffer object (newBufObj)
*/
if (buffer == 0) {
@@ -1042,48 +1037,44 @@ bind_buffer_object(struct gl_context *ctx, GLenum target, GLuint buffer)
}
else {
/* non-default buffer object */
newBufObj = _mesa_lookup_bufferobj(ctx, buffer);
if (!_mesa_handle_bind_buffer_gen(ctx, buffer,
&newBufObj, "glBindBuffer"))
return;
}
/* record usage history */
- switch (target) {
- case GL_PIXEL_PACK_BUFFER:
+ if (bindTarget == &ctx->Pack.BufferObj) {
newBufObj->UsageHistory |= USAGE_PIXEL_PACK_BUFFER;
- break;
- default:
- break;
}
/* bind new buffer */
_mesa_reference_buffer_object(ctx, bindTarget, newBufObj);
}
/**
* Update the default buffer objects in the given context to reference those
* specified in the shared state and release those referencing the old
* shared state.
*/
void
_mesa_update_default_objects_buffer_objects(struct gl_context *ctx)
{
/* Bind the NullBufferObj to remove references to those
* in the shared context hash table.
*/
- bind_buffer_object( ctx, GL_ARRAY_BUFFER_ARB, 0);
- bind_buffer_object( ctx, GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
- bind_buffer_object( ctx, GL_PIXEL_PACK_BUFFER_ARB, 0);
- bind_buffer_object( ctx, GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ bind_buffer_object(ctx, &ctx->Array.ArrayBufferObj, 0);
+ bind_buffer_object(ctx, &ctx->Array.VAO->IndexBufferObj, 0);
+ bind_buffer_object(ctx, &ctx->Pack.BufferObj, 0);
+ bind_buffer_object(ctx, &ctx->Unpack.BufferObj, 0);
}
/**
* Return the gl_buffer_object for the given ID.
* Always return NULL for ID 0.
*/
struct gl_buffer_object *
_mesa_lookup_bufferobj(struct gl_context *ctx, GLuint buffer)
@@ -1261,21 +1252,28 @@ _mesa_buffer_unmap_all_mappings(struct gl_context *ctx,
void GLAPIENTRY
_mesa_BindBuffer(GLenum target, GLuint buffer)
{
GET_CURRENT_CONTEXT(ctx);
if (MESA_VERBOSE & VERBOSE_API) {
_mesa_debug(ctx, "glBindBuffer(%s, %u)\n",
_mesa_enum_to_string(target), buffer);
}
- bind_buffer_object(ctx, target, buffer);
+ struct gl_buffer_object **bindTarget = get_buffer_target(ctx, target);
+ if (!bindTarget) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferARB(target %s)",
+ _mesa_enum_to_string(target));
+ return;
+ }
+
+ bind_buffer_object(ctx, bindTarget, buffer);
}
/**
* Delete a set of buffer objects.
*
* \param n Number of buffer objects to delete.
* \param ids Array of \c n buffer object IDs.
*/
void GLAPIENTRY
--
2.9.3
More information about the mesa-dev
mailing list