diff options
author | Fredrik Höglund <[email protected]> | 2013-11-15 19:47:20 +0100 |
---|---|---|
committer | Fredrik Höglund <[email protected]> | 2014-05-02 02:53:26 +0200 |
commit | 28d7335810c2419fa6931260c30717dcf618109a (patch) | |
tree | c4ccfefe848d3084180116140c494d9cee4ac6dd /src/mesa/main/bufferobj.c | |
parent | 19f7eeb6fb7a690c6c2fd43259813070a1e5ee2d (diff) |
mesa: Add helper functions for looking up multiple buffers
v2: Document the difference between _mesa_lookup_bufferobj() and
_mesa_multi_bind_lookup_bufferobj().
v3: Don't create the buffer objects when they don't exist.
Reviewed-by: Brian Paul <[email protected]> (v2)
Reviewed-by: Ian Romanick <[email protected]> (v2)
Diffstat (limited to 'src/mesa/main/bufferobj.c')
-rw-r--r-- | src/mesa/main/bufferobj.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index 4d53e5c793e..7b5140fcdf1 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -975,6 +975,78 @@ _mesa_lookup_bufferobj(struct gl_context *ctx, GLuint buffer) } +struct gl_buffer_object * +_mesa_lookup_bufferobj_locked(struct gl_context *ctx, GLuint buffer) +{ + return (struct gl_buffer_object *) + _mesa_HashLookupLocked(ctx->Shared->BufferObjects, buffer); +} + + +void +_mesa_begin_bufferobj_lookups(struct gl_context *ctx) +{ + _mesa_HashLockMutex(ctx->Shared->BufferObjects); +} + + +void +_mesa_end_bufferobj_lookups(struct gl_context *ctx) +{ + _mesa_HashUnlockMutex(ctx->Shared->BufferObjects); +} + + +/** + * Look up a buffer object for a multi-bind function. + * + * Unlike _mesa_lookup_bufferobj(), this function also takes care + * of generating an error if the buffer ID is not zero or the name + * of an existing buffer object. + * + * If the buffer ID refers to an existing buffer object, a pointer + * to the buffer object is returned. If the ID is zero, a pointer + * to the shared NullBufferObj is returned. If the ID is not zero + * and does not refer to a valid buffer object, this function + * returns NULL. + * + * This function assumes that the caller has already locked the + * hash table mutex by calling _mesa_begin_bufferobj_lookups(). + */ +struct gl_buffer_object * +_mesa_multi_bind_lookup_bufferobj(struct gl_context *ctx, + const GLuint *buffers, + GLuint index, const char *caller) +{ + struct gl_buffer_object *bufObj; + + if (buffers[index] != 0) { + bufObj = _mesa_lookup_bufferobj_locked(ctx, buffers[index]); + + /* The multi-bind functions don't create the buffer objects + when they don't exist. */ + if (bufObj == &DummyBufferObject) + bufObj = NULL; + } else + bufObj = ctx->Shared->NullBufferObj; + + if (!bufObj) { + /* The ARB_multi_bind spec says: + * + * "An INVALID_OPERATION error is generated if any value + * in <buffers> is not zero or the name of an existing + * buffer object (per binding)." + */ + _mesa_error(ctx, GL_INVALID_OPERATION, + "%s(buffers[%u]=%u is not zero or the name " + "of an existing buffer object)", + caller, index, buffers[index]); + } + + return bufObj; +} + + /** * If *ptr points to obj, set ptr = the Null/default buffer object. * This is a helper for buffer object deletion. |