buffer: make _bind() return base pointer
We now make _cogl_buffer_bind return a base pointer for the bound buffer which can be used with OpenGL. The pointer will be NULL for GPU based buffers or may point to an malloc'd buffer. Since OpenGL expects an offset instead of a pointer when dealing with buffer objects this means we can handle fallback malloc buffers and GPU buffers in a consistent way.
This commit is contained in:
parent
35ddc5407e
commit
efa11f8a8f
@ -437,23 +437,14 @@ _cogl_bitmap_bind (CoglBitmap *bitmap,
|
||||
|
||||
bitmap->bound = TRUE;
|
||||
|
||||
/* If buffer is using a malloc fallback then we'll just use the
|
||||
pointer directly */
|
||||
if (bitmap->buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT)
|
||||
{
|
||||
ptr = NULL;
|
||||
|
||||
if (access == COGL_BUFFER_ACCESS_READ)
|
||||
_cogl_buffer_bind (bitmap->buffer,
|
||||
COGL_BUFFER_BIND_TARGET_PIXEL_UNPACK);
|
||||
else if (access == COGL_BUFFER_ACCESS_WRITE)
|
||||
_cogl_buffer_bind (bitmap->buffer,
|
||||
COGL_BUFFER_BIND_TARGET_PIXEL_PACK);
|
||||
else
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
if (access == COGL_BUFFER_ACCESS_READ)
|
||||
ptr = _cogl_buffer_bind (bitmap->buffer,
|
||||
COGL_BUFFER_BIND_TARGET_PIXEL_UNPACK);
|
||||
else if (access == COGL_BUFFER_ACCESS_WRITE)
|
||||
ptr = _cogl_buffer_bind (bitmap->buffer,
|
||||
COGL_BUFFER_BIND_TARGET_PIXEL_PACK);
|
||||
else
|
||||
ptr = bitmap->buffer->data;
|
||||
g_assert_not_reached ();
|
||||
|
||||
/* The data pointer actually stores the offset */
|
||||
return GPOINTER_TO_INT (bitmap->data) + ptr;
|
||||
@ -472,10 +463,7 @@ _cogl_bitmap_unbind (CoglBitmap *bitmap)
|
||||
/* If the bitmap wasn't created from a pixel array then the
|
||||
implementation of unbind is the same as unmap */
|
||||
if (bitmap->buffer)
|
||||
{
|
||||
if (bitmap->buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT)
|
||||
_cogl_buffer_unbind (bitmap->buffer);
|
||||
}
|
||||
_cogl_buffer_unbind (bitmap->buffer);
|
||||
else
|
||||
_cogl_bitmap_unmap (bitmap);
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ _cogl_buffer_initialize (CoglBuffer *buffer,
|
||||
void
|
||||
_cogl_buffer_fini (CoglBuffer *buffer);
|
||||
|
||||
void
|
||||
void *
|
||||
_cogl_buffer_bind (CoglBuffer *buffer,
|
||||
CoglBufferBindTarget target);
|
||||
|
||||
|
@ -351,28 +351,31 @@ _cogl_buffer_hints_to_gl_enum (CoglBufferUsageHint usage_hint,
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
void *
|
||||
_cogl_buffer_bind (CoglBuffer *buffer, CoglBufferBindTarget target)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
_COGL_GET_CONTEXT (ctx, NULL);
|
||||
|
||||
g_return_if_fail (buffer != NULL);
|
||||
g_return_val_if_fail (buffer != NULL, NULL);
|
||||
|
||||
/* Don't allow binding the buffer to multiple targets at the same time */
|
||||
g_return_if_fail (ctx->current_buffer[buffer->last_target] != buffer);
|
||||
g_return_val_if_fail (ctx->current_buffer[buffer->last_target] != buffer,
|
||||
NULL);
|
||||
|
||||
/* Don't allow nesting binds to the same target */
|
||||
g_return_if_fail (ctx->current_buffer[target] == NULL);
|
||||
g_return_val_if_fail (ctx->current_buffer[target] == NULL, NULL);
|
||||
|
||||
buffer->last_target = target;
|
||||
ctx->current_buffer[target] = buffer;
|
||||
|
||||
if (buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT)
|
||||
{
|
||||
GLenum gl_target = convert_bind_target_to_gl_target (buffer->last_target);
|
||||
GE( glBindBuffer (gl_target, buffer->gl_handle) );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ctx->current_buffer[target] = buffer;
|
||||
else
|
||||
return buffer->data;
|
||||
}
|
||||
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user