diff options
Diffstat (limited to 'src/mesa/main/bufferobj.c')
-rw-r--r-- | src/mesa/main/bufferobj.c | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index 0a68008a10..4d62f54a95 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -55,6 +55,13 @@ /** + * Used as a placeholder for buffer objects between glGenBuffers() and + * glBindBuffer() so that glIsBuffer() can work correctly. + */ +static struct gl_buffer_object DummyBufferObject; + + +/** * Return pointer to address of a buffer object target. * \param ctx the GL context * \param target the buffer object target to be retrieved. @@ -548,6 +555,9 @@ _mesa_copy_buffer_subdata(struct gl_context *ctx, void _mesa_init_buffer_objects( struct gl_context *ctx ) { + memset(&DummyBufferObject, 0, sizeof(DummyBufferObject)); + DummyBufferObject.RefCount = 1000*1000*1000; /* never delete */ + _mesa_reference_buffer_object(ctx, &ctx->Array.ArrayBufferObj, ctx->Shared->NullBufferObj); _mesa_reference_buffer_object(ctx, &ctx->Array.ElementArrayBufferObj, @@ -605,8 +615,10 @@ bind_buffer_object(struct gl_context *ctx, GLenum target, GLuint buffer) else { /* non-default buffer object */ newBufObj = _mesa_lookup_bufferobj(ctx, buffer); - if (!newBufObj) { - /* if this is a new buffer object id, allocate a buffer object now */ + if (!newBufObj || newBufObj == &DummyBufferObject) { + /* If this is a new buffer object id, or one which was generated but + * never used before, allocate a buffer object now. + */ ASSERT(ctx->Driver.NewBufferObject); newBufObj = ctx->Driver.NewBufferObject(ctx, buffer, target); if (!newBufObj) { @@ -986,7 +998,7 @@ _mesa_DeleteBuffersARB(GLsizei n, const GLuint *ids) struct gl_array_object *arrayObj = ctx->Array.ArrayObj; GLuint j; - ASSERT(bufObj->Name == ids[i]); + ASSERT(bufObj->Name == ids[i] || bufObj == &DummyBufferObject); if (_mesa_bufferobj_mapped(bufObj)) { /* if mapped, unmap it now */ @@ -1027,7 +1039,7 @@ _mesa_DeleteBuffersARB(GLsizei n, const GLuint *ids) } /* The ID is immediately freed for re-use */ - _mesa_HashRemove(ctx->Shared->BufferObjects, bufObj->Name); + _mesa_HashRemove(ctx->Shared->BufferObjects, ids[i]); _mesa_reference_buffer_object(ctx, &bufObj, NULL); } } @@ -1066,18 +1078,10 @@ _mesa_GenBuffersARB(GLsizei n, GLuint *buffer) first = _mesa_HashFindFreeKeyBlock(ctx->Shared->BufferObjects, n); - /* Allocate new, empty buffer objects and return identifiers */ + /* Insert the ID and pointer to dummy buffer object into hash table */ for (i = 0; i < n; i++) { - struct gl_buffer_object *bufObj; - GLuint name = first + i; - GLenum target = 0; - bufObj = ctx->Driver.NewBufferObject( ctx, name, target ); - if (!bufObj) { - _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenBuffersARB"); - return; - } - _mesa_HashInsert(ctx->Shared->BufferObjects, first + i, bufObj); + _mesa_HashInsert(ctx->Shared->BufferObjects, first + i, + &DummyBufferObject); buffer[i] = first + i; } @@ -1103,7 +1107,7 @@ _mesa_IsBufferARB(GLuint id) bufObj = _mesa_lookup_bufferobj(ctx, id); _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); - return bufObj ? GL_TRUE : GL_FALSE; + return bufObj && bufObj != &DummyBufferObject; } @@ -1189,6 +1193,9 @@ _mesa_BufferSubDataARB(GLenum target, GLintptrARB offset, return; } + if (size == 0) + return; + bufObj->Written = GL_TRUE; ASSERT(ctx->Driver.BufferSubData); |