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:
Robert Bragg 2010-10-12 13:14:17 +01:00
parent 35ddc5407e
commit efa11f8a8f
3 changed files with 19 additions and 28 deletions

View File

@ -437,23 +437,14 @@ _cogl_bitmap_bind (CoglBitmap *bitmap,
bitmap->bound = TRUE; bitmap->bound = TRUE;
/* If buffer is using a malloc fallback then we'll just use the if (access == COGL_BUFFER_ACCESS_READ)
pointer directly */ ptr = _cogl_buffer_bind (bitmap->buffer,
if (bitmap->buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT) COGL_BUFFER_BIND_TARGET_PIXEL_UNPACK);
{ else if (access == COGL_BUFFER_ACCESS_WRITE)
ptr = NULL; ptr = _cogl_buffer_bind (bitmap->buffer,
COGL_BUFFER_BIND_TARGET_PIXEL_PACK);
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 ();
}
else else
ptr = bitmap->buffer->data; g_assert_not_reached ();
/* The data pointer actually stores the offset */ /* The data pointer actually stores the offset */
return GPOINTER_TO_INT (bitmap->data) + ptr; 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 /* If the bitmap wasn't created from a pixel array then the
implementation of unbind is the same as unmap */ implementation of unbind is the same as unmap */
if (bitmap->buffer) if (bitmap->buffer)
{ _cogl_buffer_unbind (bitmap->buffer);
if (bitmap->buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT)
_cogl_buffer_unbind (bitmap->buffer);
}
else else
_cogl_bitmap_unmap (bitmap); _cogl_bitmap_unmap (bitmap);
} }

View File

@ -120,7 +120,7 @@ _cogl_buffer_initialize (CoglBuffer *buffer,
void void
_cogl_buffer_fini (CoglBuffer *buffer); _cogl_buffer_fini (CoglBuffer *buffer);
void void *
_cogl_buffer_bind (CoglBuffer *buffer, _cogl_buffer_bind (CoglBuffer *buffer,
CoglBufferBindTarget target); CoglBufferBindTarget target);

View File

@ -351,28 +351,31 @@ _cogl_buffer_hints_to_gl_enum (CoglBufferUsageHint usage_hint,
} }
#endif #endif
void void *
_cogl_buffer_bind (CoglBuffer *buffer, CoglBufferBindTarget target) _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 */ /* 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 */ /* 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; buffer->last_target = target;
ctx->current_buffer[target] = buffer;
if (buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT) if (buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT)
{ {
GLenum gl_target = convert_bind_target_to_gl_target (buffer->last_target); GLenum gl_target = convert_bind_target_to_gl_target (buffer->last_target);
GE( glBindBuffer (gl_target, buffer->gl_handle) ); GE( glBindBuffer (gl_target, buffer->gl_handle) );
return NULL;
} }
else
ctx->current_buffer[target] = buffer; return buffer->data;
} }
void void