mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-25 00:00:11 +01:00
mesa: Make glBindBufferBase/glBindBufferRange() work on just-genned names.
In between glGenBuffers() and glBindBuffer(), the buffer object points to this dummy buffer with a name of 0, and a glBindBufferBase() would point to that. It seems pretty clear, given that glBindBufferBase() only cares about the current size of the buffer at render time, that it should bind up the buffer that you passed in instead of pointing it at this useless dummy buffer. However, what should glBindBufferRange() do? As of this patch, it will promote the genned buffer to a proper buffer like it had been glBindBuffer()ed, and then detect that the size is greater than the buffer's current size of 0 and throw INVALID_VALUE. It seems like the most reasonable answer here. Note that this also changes the behavior of these two on non-glGenBuffers() bo names. We haven't yet set up the error throwing for glBindBuffers() on gl 3.1+, and my assumption is that these two functions should inherit their behavior on un-genned names from glBindBuffers(). Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
This commit is contained in:
parent
a75f2681d2
commit
56e82e30cb
1 changed files with 25 additions and 12 deletions
|
|
@ -656,6 +656,28 @@ _mesa_free_buffer_objects( struct gl_context *ctx )
|
|||
ctx->UniformBufferBindings = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
handle_bind_buffer_gen(struct gl_context *ctx,
|
||||
GLenum target,
|
||||
GLuint buffer,
|
||||
struct gl_buffer_object **buf_handle)
|
||||
{
|
||||
struct gl_buffer_object *buf = *buf_handle;
|
||||
|
||||
if (!buf || buf == &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);
|
||||
buf = ctx->Driver.NewBufferObject(ctx, buffer, target);
|
||||
if (!buf) {
|
||||
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindBufferARB");
|
||||
return;
|
||||
}
|
||||
_mesa_HashInsert(ctx->Shared->BufferObjects, buffer, buf);
|
||||
*buf_handle = buf;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind the specified target to buffer for the specified context.
|
||||
|
|
@ -691,18 +713,7 @@ bind_buffer_object(struct gl_context *ctx, GLenum target, GLuint buffer)
|
|||
else {
|
||||
/* non-default buffer object */
|
||||
newBufObj = _mesa_lookup_bufferobj(ctx, buffer);
|
||||
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) {
|
||||
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindBufferARB");
|
||||
return;
|
||||
}
|
||||
_mesa_HashInsert(ctx->Shared->BufferObjects, buffer, newBufObj);
|
||||
}
|
||||
handle_bind_buffer_gen(ctx, target, buffer, &newBufObj);
|
||||
}
|
||||
|
||||
/* bind new buffer */
|
||||
|
|
@ -2089,6 +2100,7 @@ _mesa_BindBufferRange(GLenum target, GLuint index,
|
|||
} else {
|
||||
bufObj = _mesa_lookup_bufferobj(ctx, buffer);
|
||||
}
|
||||
handle_bind_buffer_gen(ctx, target, buffer, &bufObj);
|
||||
|
||||
if (!bufObj) {
|
||||
_mesa_error(ctx, GL_INVALID_OPERATION,
|
||||
|
|
@ -2134,6 +2146,7 @@ _mesa_BindBufferBase(GLenum target, GLuint index, GLuint buffer)
|
|||
} else {
|
||||
bufObj = _mesa_lookup_bufferobj(ctx, buffer);
|
||||
}
|
||||
handle_bind_buffer_gen(ctx, target, buffer, &bufObj);
|
||||
|
||||
if (!bufObj) {
|
||||
_mesa_error(ctx, GL_INVALID_OPERATION,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue