buffer: explicitly relate buffers to a context

All CoglBuffer constructors now take an explicit CoglContext
constructor. This is part of the on going effort to adapt to Cogl API so
it no longer depends on a global, default context.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
This commit is contained in:
Robert Bragg 2012-02-06 17:08:58 +00:00
parent 269878217f
commit 3ea6acc072
26 changed files with 214 additions and 148 deletions

View File

@ -269,7 +269,8 @@ emit_vertex_buffer_geometry (CoglPangoDisplayListNode *node)
n_verts = node->d.texture.rectangles->len * 4; n_verts = node->d.texture.rectangles->len * 4;
buffer buffer
= cogl_attribute_buffer_new (n_verts * sizeof (CoglVertexP2T2), NULL); = cogl_attribute_buffer_new (ctx,
n_verts * sizeof (CoglVertexP2T2), NULL);
if ((verts = cogl_buffer_map (COGL_BUFFER (buffer), if ((verts = cogl_buffer_map (COGL_BUFFER (buffer),
COGL_BUFFER_ACCESS_WRITE, COGL_BUFFER_ACCESS_WRITE,
@ -351,7 +352,7 @@ emit_vertex_buffer_geometry (CoglPangoDisplayListNode *node)
quads */ quads */
CoglIndices *indices = CoglIndices *indices =
cogl_get_rectangle_indices (node->d.texture.rectangles->len); cogl_get_rectangle_indices (ctx, node->d.texture.rectangles->len);
cogl_primitive_set_indices (prim, indices, cogl_primitive_set_indices (prim, indices,
node->d.texture.rectangles->len * 6); node->d.texture.rectangles->len * 6);

View File

@ -39,20 +39,21 @@ static void _cogl_attribute_buffer_free (CoglAttributeBuffer *array);
COGL_BUFFER_DEFINE (AttributeBuffer, attribute_buffer); COGL_BUFFER_DEFINE (AttributeBuffer, attribute_buffer);
CoglAttributeBuffer * CoglAttributeBuffer *
cogl_attribute_buffer_new (gsize bytes, const void *data) cogl_attribute_buffer_new (CoglContext *context,
gsize bytes,
const void *data)
{ {
CoglAttributeBuffer *array = g_slice_new (CoglAttributeBuffer); CoglAttributeBuffer *array = g_slice_new (CoglAttributeBuffer);
gboolean use_malloc; gboolean use_malloc;
_COGL_GET_CONTEXT (ctx, NULL); if (!(context->private_feature_flags & COGL_PRIVATE_FEATURE_VBOS))
if (!(ctx->private_feature_flags & COGL_PRIVATE_FEATURE_VBOS))
use_malloc = TRUE; use_malloc = TRUE;
else else
use_malloc = FALSE; use_malloc = FALSE;
/* parent's constructor */ /* parent's constructor */
_cogl_buffer_initialize (COGL_BUFFER (array), _cogl_buffer_initialize (COGL_BUFFER (array),
context,
bytes, bytes,
use_malloc, use_malloc,
COGL_BUFFER_BIND_TARGET_ATTRIBUTE_BUFFER, COGL_BUFFER_BIND_TARGET_ATTRIBUTE_BUFFER,

View File

@ -31,6 +31,8 @@
#ifndef __COGL_ATTRIBUTE_BUFFER_H__ #ifndef __COGL_ATTRIBUTE_BUFFER_H__
#define __COGL_ATTRIBUTE_BUFFER_H__ #define __COGL_ATTRIBUTE_BUFFER_H__
#include <cogl/cogl-context.h>
G_BEGIN_DECLS G_BEGIN_DECLS
/** /**
@ -45,6 +47,7 @@ typedef struct _CoglAttributeBuffer CoglAttributeBuffer;
/** /**
* cogl_attribute_buffer_new: * cogl_attribute_buffer_new:
* @context: A #CoglContext
* @bytes: The number of bytes to allocate for vertex attribute data. * @bytes: The number of bytes to allocate for vertex attribute data.
* @data: An optional pointer to vertex data to upload immediately. * @data: An optional pointer to vertex data to upload immediately.
* *
@ -59,7 +62,9 @@ typedef struct _CoglAttributeBuffer CoglAttributeBuffer;
* Stability: Unstable * Stability: Unstable
*/ */
CoglAttributeBuffer * CoglAttributeBuffer *
cogl_attribute_buffer_new (gsize bytes, const void *data); cogl_attribute_buffer_new (CoglContext *context,
gsize bytes,
const void *data);
/** /**
* cogl_is_attribute_buffer: * cogl_is_attribute_buffer:

View File

@ -78,6 +78,9 @@ typedef enum {
struct _CoglBuffer struct _CoglBuffer
{ {
CoglObject _parent; CoglObject _parent;
CoglContext *context;
CoglBufferVtable vtable; CoglBufferVtable vtable;
CoglBufferBindTarget last_target; CoglBufferBindTarget last_target;
@ -111,6 +114,7 @@ _cogl_buffer_register_buffer_type (const CoglObjectClass *klass);
void void
_cogl_buffer_initialize (CoglBuffer *buffer, _cogl_buffer_initialize (CoglBuffer *buffer,
CoglContext *context,
unsigned int size, unsigned int size,
gboolean use_malloc, gboolean use_malloc,
CoglBufferBindTarget default_target, CoglBufferBindTarget default_target,
@ -133,10 +137,6 @@ _cogl_buffer_get_usage_hint (CoglBuffer *buffer);
GLenum GLenum
_cogl_buffer_access_to_gl_enum (CoglBufferAccess access); _cogl_buffer_access_to_gl_enum (CoglBufferAccess access);
GLenum
_cogl_buffer_hints_to_gl_enum (CoglBufferUsageHint usage_hint,
CoglBufferUpdateHint update_hint);
CoglBuffer * CoglBuffer *
_cogl_buffer_immutable_ref (CoglBuffer *buffer); _cogl_buffer_immutable_ref (CoglBuffer *buffer);

View File

@ -77,12 +77,12 @@
* abstract class manually. * abstract class manually.
*/ */
static GSList *_cogl_buffer_types;
void void
_cogl_buffer_register_buffer_type (const CoglObjectClass *klass) _cogl_buffer_register_buffer_type (const CoglObjectClass *klass)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _cogl_buffer_types = g_slist_prepend (_cogl_buffer_types, (void *) klass);
ctx->buffer_types = g_slist_prepend (ctx->buffer_types, (void *) klass);
} }
gboolean gboolean
@ -91,12 +91,10 @@ cogl_is_buffer (const void *object)
const CoglHandleObject *obj = object; const CoglHandleObject *obj = object;
GSList *l; GSList *l;
_COGL_GET_CONTEXT (ctx, FALSE);
if (object == NULL) if (object == NULL)
return FALSE; return FALSE;
for (l = ctx->buffer_types; l; l = l->next) for (l = _cogl_buffer_types; l; l = l->next)
if (l->data == obj->klass) if (l->data == obj->klass)
return TRUE; return TRUE;
@ -121,6 +119,24 @@ convert_bind_target_to_gl_target (CoglBufferBindTarget target)
} }
} }
static GLenum
_cogl_buffer_hints_to_gl_enum (CoglBufferUsageHint usage_hint,
CoglBufferUpdateHint update_hint)
{
/* usage hint is always TEXTURE for now */
if (update_hint == COGL_BUFFER_UPDATE_HINT_STATIC)
return GL_STATIC_DRAW;
if (update_hint == COGL_BUFFER_UPDATE_HINT_DYNAMIC)
return GL_DYNAMIC_DRAW;
/* OpenGL ES 1.1 and 2 only know about STATIC_DRAW and DYNAMIC_DRAW */
#ifdef HAVE_COGL_GL
if (update_hint == COGL_BUFFER_UPDATE_HINT_STREAM)
return GL_STREAM_DRAW;
#endif
return GL_STATIC_DRAW;
}
static void * static void *
bo_map (CoglBuffer *buffer, bo_map (CoglBuffer *buffer,
CoglBufferAccess access, CoglBufferAccess access,
@ -129,8 +145,7 @@ bo_map (CoglBuffer *buffer,
guint8 *data; guint8 *data;
CoglBufferBindTarget target; CoglBufferBindTarget target;
GLenum gl_target; GLenum gl_target;
CoglContext *ctx = buffer->context;
_COGL_GET_CONTEXT (ctx, NULL);
if ((access & COGL_BUFFER_ACCESS_READ) && if ((access & COGL_BUFFER_ACCESS_READ) &&
!cogl_has_feature (ctx, COGL_FEATURE_ID_MAP_BUFFER_FOR_READ)) !cogl_has_feature (ctx, COGL_FEATURE_ID_MAP_BUFFER_FOR_READ))
@ -175,7 +190,7 @@ bo_map (CoglBuffer *buffer,
static void static void
bo_unmap (CoglBuffer *buffer) bo_unmap (CoglBuffer *buffer)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL); CoglContext *ctx = buffer->context;
_cogl_buffer_bind (buffer, buffer->last_target); _cogl_buffer_bind (buffer, buffer->last_target);
@ -194,8 +209,7 @@ bo_set_data (CoglBuffer *buffer,
{ {
CoglBufferBindTarget target; CoglBufferBindTarget target;
GLenum gl_target; GLenum gl_target;
CoglContext *ctx = buffer->context;
_COGL_GET_CONTEXT (ctx, FALSE);
target = buffer->last_target; target = buffer->last_target;
_cogl_buffer_bind (buffer, target); _cogl_buffer_bind (buffer, target);
@ -254,14 +268,14 @@ malloc_set_data (CoglBuffer *buffer,
void void
_cogl_buffer_initialize (CoglBuffer *buffer, _cogl_buffer_initialize (CoglBuffer *buffer,
CoglContext *context,
unsigned int size, unsigned int size,
gboolean use_malloc, gboolean use_malloc,
CoglBufferBindTarget default_target, CoglBufferBindTarget default_target,
CoglBufferUsageHint usage_hint, CoglBufferUsageHint usage_hint,
CoglBufferUpdateHint update_hint) CoglBufferUpdateHint update_hint)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL); buffer->context = cogl_object_ref (context);
buffer->flags = COGL_BUFFER_FLAG_NONE; buffer->flags = COGL_BUFFER_FLAG_NONE;
buffer->store_created = FALSE; buffer->store_created = FALSE;
buffer->size = size; buffer->size = size;
@ -285,7 +299,7 @@ _cogl_buffer_initialize (CoglBuffer *buffer,
buffer->vtable.unmap = bo_unmap; buffer->vtable.unmap = bo_unmap;
buffer->vtable.set_data = bo_set_data; buffer->vtable.set_data = bo_set_data;
GE( ctx, glGenBuffers (1, &buffer->gl_handle) ); GE( context, glGenBuffers (1, &buffer->gl_handle) );
buffer->flags |= COGL_BUFFER_FLAG_BUFFER_OBJECT; buffer->flags |= COGL_BUFFER_FLAG_BUFFER_OBJECT;
} }
} }
@ -293,15 +307,15 @@ _cogl_buffer_initialize (CoglBuffer *buffer,
void void
_cogl_buffer_fini (CoglBuffer *buffer) _cogl_buffer_fini (CoglBuffer *buffer)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
_COGL_RETURN_IF_FAIL (!(buffer->flags & COGL_BUFFER_FLAG_MAPPED)); _COGL_RETURN_IF_FAIL (!(buffer->flags & COGL_BUFFER_FLAG_MAPPED));
_COGL_RETURN_IF_FAIL (buffer->immutable_ref == 0); _COGL_RETURN_IF_FAIL (buffer->immutable_ref == 0);
if (buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT) if (buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT)
GE( ctx, glDeleteBuffers (1, &buffer->gl_handle) ); GE( buffer->context, glDeleteBuffers (1, &buffer->gl_handle) );
else else
g_free (buffer->data); g_free (buffer->data);
cogl_object_unref (buffer->context);
} }
GLenum GLenum
@ -315,30 +329,10 @@ _cogl_buffer_access_to_gl_enum (CoglBufferAccess access)
return GL_READ_ONLY; return GL_READ_ONLY;
} }
GLenum
_cogl_buffer_hints_to_gl_enum (CoglBufferUsageHint usage_hint,
CoglBufferUpdateHint update_hint)
{
_COGL_GET_CONTEXT (ctx, 0);
/* usage hint is always TEXTURE for now */
if (update_hint == COGL_BUFFER_UPDATE_HINT_STATIC)
return GL_STATIC_DRAW;
if (update_hint == COGL_BUFFER_UPDATE_HINT_DYNAMIC)
return GL_DYNAMIC_DRAW;
/* OpenGL ES 1.1 and 2 only know about STATIC_DRAW and DYNAMIC_DRAW */
#ifdef HAVE_COGL_GL
if (update_hint == COGL_BUFFER_UPDATE_HINT_STREAM)
return GL_STREAM_DRAW;
#endif
return GL_STATIC_DRAW;
}
void * void *
_cogl_buffer_bind (CoglBuffer *buffer, CoglBufferBindTarget target) _cogl_buffer_bind (CoglBuffer *buffer, CoglBufferBindTarget target)
{ {
_COGL_GET_CONTEXT (ctx, NULL); CoglContext *ctx = buffer->context;
_COGL_RETURN_VAL_IF_FAIL (buffer != NULL, NULL); _COGL_RETURN_VAL_IF_FAIL (buffer != NULL, NULL);
@ -365,7 +359,7 @@ _cogl_buffer_bind (CoglBuffer *buffer, CoglBufferBindTarget target)
void void
_cogl_buffer_unbind (CoglBuffer *buffer) _cogl_buffer_unbind (CoglBuffer *buffer)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL); CoglContext *ctx = buffer->context;
_COGL_RETURN_IF_FAIL (buffer != NULL); _COGL_RETURN_IF_FAIL (buffer != NULL);
@ -456,10 +450,9 @@ cogl_buffer_unmap (CoglBuffer *buffer)
void * void *
_cogl_buffer_map_for_fill_or_fallback (CoglBuffer *buffer) _cogl_buffer_map_for_fill_or_fallback (CoglBuffer *buffer)
{ {
CoglContext *ctx = buffer->context;
void *ret; void *ret;
_COGL_GET_CONTEXT (ctx, NULL);
_COGL_RETURN_VAL_IF_FAIL (!ctx->buffer_map_fallback_in_use, NULL); _COGL_RETURN_VAL_IF_FAIL (!ctx->buffer_map_fallback_in_use, NULL);
ctx->buffer_map_fallback_in_use = TRUE; ctx->buffer_map_fallback_in_use = TRUE;
@ -487,7 +480,7 @@ _cogl_buffer_map_for_fill_or_fallback (CoglBuffer *buffer)
void void
_cogl_buffer_unmap_for_fill_or_fallback (CoglBuffer *buffer) _cogl_buffer_unmap_for_fill_or_fallback (CoglBuffer *buffer)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL); CoglContext *ctx = buffer->context;
_COGL_RETURN_IF_FAIL (ctx->buffer_map_fallback_in_use); _COGL_RETURN_IF_FAIL (ctx->buffer_map_fallback_in_use);

View File

@ -2610,6 +2610,8 @@ draw_wireframe (CoglFramebuffer *framebuffer,
CoglVertexP3 *lines; CoglVertexP3 *lines;
CoglAttributeBuffer *attribute_buffer; CoglAttributeBuffer *attribute_buffer;
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
for (i = 0; i < n_attributes; i++) for (i = 0; i < n_attributes; i++)
{ {
if (attributes[i]->name_state->name_id == if (attributes[i]->name_state->name_id ==
@ -2628,7 +2630,7 @@ draw_wireframe (CoglFramebuffer *framebuffer,
&n_line_vertices, &n_line_vertices,
indices); indices);
attribute_buffer = attribute_buffer =
cogl_attribute_buffer_new (sizeof (CoglVertexP3) * n_line_vertices, cogl_attribute_buffer_new (ctx, sizeof (CoglVertexP3) * n_line_vertices,
lines); lines);
wire_attribute[0] = wire_attribute[0] =
cogl_attribute_new (attribute_buffer, "cogl_position_in", cogl_attribute_new (attribute_buffer, "cogl_position_in",

View File

@ -42,20 +42,19 @@ COGL_BUFFER_DEFINE (IndexBuffer, index_buffer);
* indices buffer should be able to contain multiple ranges of indices * indices buffer should be able to contain multiple ranges of indices
* which the wiki design doesn't currently consider. */ * which the wiki design doesn't currently consider. */
CoglIndexBuffer * CoglIndexBuffer *
cogl_index_buffer_new (gsize bytes) cogl_index_buffer_new (CoglContext *context, gsize bytes)
{ {
CoglIndexBuffer *indices = g_slice_new (CoglIndexBuffer); CoglIndexBuffer *indices = g_slice_new (CoglIndexBuffer);
gboolean use_malloc; gboolean use_malloc;
_COGL_GET_CONTEXT (ctx, NULL); if (!(context->private_feature_flags & COGL_PRIVATE_FEATURE_VBOS))
if (!(ctx->private_feature_flags & COGL_PRIVATE_FEATURE_VBOS))
use_malloc = TRUE; use_malloc = TRUE;
else else
use_malloc = FALSE; use_malloc = FALSE;
/* parent's constructor */ /* parent's constructor */
_cogl_buffer_initialize (COGL_BUFFER (indices), _cogl_buffer_initialize (COGL_BUFFER (indices),
context,
bytes, bytes,
use_malloc, use_malloc,
COGL_BUFFER_BIND_TARGET_INDEX_BUFFER, COGL_BUFFER_BIND_TARGET_INDEX_BUFFER,

View File

@ -31,6 +31,8 @@
#ifndef __COGL_INDEX_BUFFER_H__ #ifndef __COGL_INDEX_BUFFER_H__
#define __COGL_INDEX_BUFFER_H__ #define __COGL_INDEX_BUFFER_H__
#include <cogl/cogl-context.h>
G_BEGIN_DECLS G_BEGIN_DECLS
/** /**
@ -45,6 +47,7 @@ typedef struct _CoglIndexBuffer CoglIndexBuffer;
/** /**
* cogl_index_buffer_new: * cogl_index_buffer_new:
* @context: A #CoglContext
* @bytes: The number of bytes to allocate for vertex attribute data. * @bytes: The number of bytes to allocate for vertex attribute data.
* *
* Declares a new #CoglIndexBuffer of @size bytes to contain vertex * Declares a new #CoglIndexBuffer of @size bytes to contain vertex
@ -56,7 +59,8 @@ typedef struct _CoglIndexBuffer CoglIndexBuffer;
* Stability: Unstable * Stability: Unstable
*/ */
CoglIndexBuffer * CoglIndexBuffer *
cogl_index_buffer_new (gsize bytes); cogl_index_buffer_new (CoglContext *context,
gsize bytes);
/** /**
* cogl_is_index_buffer: * cogl_is_index_buffer:

View File

@ -76,12 +76,13 @@ cogl_indices_new_for_buffer (CoglIndicesType type,
} }
CoglIndices * CoglIndices *
cogl_indices_new (CoglIndicesType type, cogl_indices_new (CoglContext *context,
CoglIndicesType type,
const void *indices_data, const void *indices_data,
int n_indices) int n_indices)
{ {
size_t buffer_bytes = sizeof_indices_type (type) * n_indices; size_t buffer_bytes = sizeof_indices_type (type) * n_indices;
CoglIndexBuffer *index_buffer = cogl_index_buffer_new (buffer_bytes); CoglIndexBuffer *index_buffer = cogl_index_buffer_new (context, buffer_bytes);
CoglBuffer *buffer = COGL_BUFFER (index_buffer); CoglBuffer *buffer = COGL_BUFFER (index_buffer);
CoglIndices *indices; CoglIndices *indices;
@ -170,12 +171,10 @@ _cogl_indices_immutable_unref (CoglIndices *indices)
} }
CoglIndices * CoglIndices *
cogl_get_rectangle_indices (int n_rectangles) cogl_get_rectangle_indices (CoglContext *ctx, int n_rectangles)
{ {
int n_indices = n_rectangles * 6; int n_indices = n_rectangles * 6;
_COGL_GET_CONTEXT (ctx, NULL);
/* Check if the largest index required will fit in a byte array... */ /* Check if the largest index required will fit in a byte array... */
if (n_indices <= 256 / 4 * 6) if (n_indices <= 256 / 4 * 6)
{ {
@ -198,7 +197,8 @@ cogl_get_rectangle_indices (int n_rectangles)
} }
ctx->rectangle_byte_indices ctx->rectangle_byte_indices
= cogl_indices_new (COGL_INDICES_TYPE_UNSIGNED_BYTE, = cogl_indices_new (ctx,
COGL_INDICES_TYPE_UNSIGNED_BYTE,
byte_array, byte_array,
256 / 4 * 6); 256 / 4 * 6);
@ -241,7 +241,8 @@ cogl_get_rectangle_indices (int n_rectangles)
} }
ctx->rectangle_short_indices ctx->rectangle_short_indices
= cogl_indices_new (COGL_INDICES_TYPE_UNSIGNED_SHORT, = cogl_indices_new (ctx,
COGL_INDICES_TYPE_UNSIGNED_SHORT,
short_array, short_array,
ctx->rectangle_short_indices_len); ctx->rectangle_short_indices_len);

View File

@ -97,7 +97,8 @@ G_BEGIN_DECLS
typedef struct _CoglIndices CoglIndices; typedef struct _CoglIndices CoglIndices;
CoglIndices * CoglIndices *
cogl_indices_new (CoglIndicesType type, cogl_indices_new (CoglContext *context,
CoglIndicesType type,
const void *indices_data, const void *indices_data,
int n_indices); int n_indices);
@ -120,7 +121,7 @@ cogl_indices_set_offset (CoglIndices *indices,
gsize offset); gsize offset);
CoglIndices * CoglIndices *
cogl_get_rectangle_indices (int n_rectangles); cogl_get_rectangle_indices (CoglContext *context, int n_rectangles);
G_END_DECLS G_END_DECLS

View File

@ -576,6 +576,7 @@ _cogl_journal_flush_vbo_offsets_and_entries (CoglJournalEntry *batch_start,
void *data) void *data)
{ {
CoglJournalFlushState *state = data; CoglJournalFlushState *state = data;
CoglContext *ctx = state->framebuffer->context;
gsize stride; gsize stride;
int i; int i;
CoglAttribute **attribute_entry; CoglAttribute **attribute_entry;
@ -586,8 +587,6 @@ _cogl_journal_flush_vbo_offsets_and_entries (CoglJournalEntry *batch_start,
"pipeline + entries", "pipeline + entries",
0 /* no application private data */); 0 /* no application private data */);
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
COGL_TIMER_START (_cogl_uprof_context, COGL_TIMER_START (_cogl_uprof_context,
time_flush_vbo_texcoord_pipeline_entries); time_flush_vbo_texcoord_pipeline_entries);
@ -630,7 +629,7 @@ _cogl_journal_flush_vbo_offsets_and_entries (CoglJournalEntry *batch_start,
COGL_ATTRIBUTE_TYPE_UNSIGNED_BYTE); COGL_ATTRIBUTE_TYPE_UNSIGNED_BYTE);
if (ctx->driver != COGL_DRIVER_GL) if (ctx->driver != COGL_DRIVER_GL)
state->indices = cogl_get_rectangle_indices (batch_len); state->indices = cogl_get_rectangle_indices (ctx, batch_len);
/* We only create new Attributes when the stride within the /* We only create new Attributes when the stride within the
* AttributeBuffer changes. (due to a change in the number of pipeline * AttributeBuffer changes. (due to a change in the number of pipeline
@ -1133,20 +1132,20 @@ create_attribute_buffer (CoglJournal *journal,
really any point in using the pool so we'll just allocate the really any point in using the pool so we'll just allocate the
buffer directly */ buffer directly */
if (!(ctx->private_feature_flags & COGL_PRIVATE_FEATURE_VBOS)) if (!(ctx->private_feature_flags & COGL_PRIVATE_FEATURE_VBOS))
return cogl_attribute_buffer_new (n_bytes, NULL); return cogl_attribute_buffer_new (ctx, n_bytes, NULL);
vbo = journal->vbo_pool[journal->next_vbo_in_pool]; vbo = journal->vbo_pool[journal->next_vbo_in_pool];
if (vbo == NULL) if (vbo == NULL)
{ {
vbo = cogl_attribute_buffer_new (n_bytes, NULL); vbo = cogl_attribute_buffer_new (ctx, n_bytes, NULL);
journal->vbo_pool[journal->next_vbo_in_pool] = vbo; journal->vbo_pool[journal->next_vbo_in_pool] = vbo;
} }
else if (cogl_buffer_get_size (COGL_BUFFER (vbo)) < n_bytes) else if (cogl_buffer_get_size (COGL_BUFFER (vbo)) < n_bytes)
{ {
/* If the buffer is too small then we'll just recreate it */ /* If the buffer is too small then we'll just recreate it */
cogl_object_unref (vbo); cogl_object_unref (vbo);
vbo = cogl_attribute_buffer_new (n_bytes, NULL); vbo = cogl_attribute_buffer_new (ctx, n_bytes, NULL);
journal->vbo_pool[journal->next_vbo_in_pool] = vbo; journal->vbo_pool[journal->next_vbo_in_pool] = vbo;
} }

View File

@ -68,21 +68,20 @@ _cogl_pixel_buffer_free (CoglPixelBuffer *buffer);
COGL_BUFFER_DEFINE (PixelBuffer, pixel_buffer) COGL_BUFFER_DEFINE (PixelBuffer, pixel_buffer)
static CoglPixelBuffer * static CoglPixelBuffer *
_cogl_pixel_buffer_new (unsigned int size) _cogl_pixel_buffer_new (CoglContext *context, unsigned int size)
{ {
CoglPixelBuffer *pixel_buffer = g_slice_new0 (CoglPixelBuffer); CoglPixelBuffer *pixel_buffer = g_slice_new0 (CoglPixelBuffer);
CoglBuffer *buffer = COGL_BUFFER (pixel_buffer); CoglBuffer *buffer = COGL_BUFFER (pixel_buffer);
gboolean use_malloc; gboolean use_malloc;
_COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE); if (!(context->private_feature_flags & COGL_PRIVATE_FEATURE_PBOS))
if (!(ctx->private_feature_flags & COGL_PRIVATE_FEATURE_PBOS))
use_malloc = TRUE; use_malloc = TRUE;
else else
use_malloc = FALSE; use_malloc = FALSE;
/* parent's constructor */ /* parent's constructor */
_cogl_buffer_initialize (buffer, _cogl_buffer_initialize (buffer,
context,
size, size,
use_malloc, use_malloc,
COGL_BUFFER_BIND_TARGET_PIXEL_UNPACK, COGL_BUFFER_BIND_TARGET_PIXEL_UNPACK,
@ -94,7 +93,8 @@ _cogl_pixel_buffer_new (unsigned int size)
} }
CoglPixelBuffer * CoglPixelBuffer *
cogl_pixel_buffer_new_with_size (unsigned int width, cogl_pixel_buffer_new_with_size (CoglContext *context,
unsigned int width,
unsigned int height, unsigned int height,
CoglPixelFormat format, CoglPixelFormat format,
unsigned int *rowstride) unsigned int *rowstride)
@ -113,7 +113,7 @@ cogl_pixel_buffer_new_with_size (unsigned int width,
if (rowstride) if (rowstride)
*rowstride = stride; *rowstride = stride;
buffer = _cogl_pixel_buffer_new (height * stride); buffer = _cogl_pixel_buffer_new (context, height * stride);
if (G_UNLIKELY (buffer == COGL_INVALID_HANDLE)) if (G_UNLIKELY (buffer == COGL_INVALID_HANDLE))
return COGL_INVALID_HANDLE; return COGL_INVALID_HANDLE;
@ -129,8 +129,6 @@ cogl_pixel_buffer_new_with_size (unsigned int width,
static void static void
_cogl_pixel_buffer_free (CoglPixelBuffer *buffer) _cogl_pixel_buffer_free (CoglPixelBuffer *buffer)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
/* parent's destructor */ /* parent's destructor */
_cogl_buffer_fini (COGL_BUFFER (buffer)); _cogl_buffer_fini (COGL_BUFFER (buffer));

View File

@ -34,6 +34,7 @@
#include <glib.h> #include <glib.h>
#include <cogl/cogl-types.h> #include <cogl/cogl-types.h>
#include <cogl/cogl-context.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -54,6 +55,7 @@ typedef struct _CoglPixelBuffer CoglPixelBuffer;
/** /**
* cogl_pixel_buffer_new_with_size: * cogl_pixel_buffer_new_with_size:
* @context: A #CoglContext
* @width: width of the pixel array in pixels * @width: width of the pixel array in pixels
* @height: height of the pixel array in pixels * @height: height of the pixel array in pixels
* @format: the format of the pixels the array will store * @format: the format of the pixels the array will store
@ -75,7 +77,8 @@ typedef struct _CoglPixelBuffer CoglPixelBuffer;
* Stability: Unstable * Stability: Unstable
*/ */
CoglPixelBuffer * CoglPixelBuffer *
cogl_pixel_buffer_new_with_size (unsigned int width, cogl_pixel_buffer_new_with_size (CoglContext *context,
unsigned int width,
unsigned int height, unsigned int height,
CoglPixelFormat format, CoglPixelFormat format,
unsigned int *stride); unsigned int *stride);

View File

@ -127,12 +127,13 @@ cogl_primitive_new (CoglVerticesMode mode,
} }
CoglPrimitive * CoglPrimitive *
cogl_primitive_new_p2 (CoglVerticesMode mode, cogl_primitive_new_p2 (CoglContext *ctx,
CoglVerticesMode mode,
int n_vertices, int n_vertices,
const CoglVertexP2 *data) const CoglVertexP2 *data)
{ {
CoglAttributeBuffer *attribute_buffer = CoglAttributeBuffer *attribute_buffer =
cogl_attribute_buffer_new (n_vertices * sizeof (CoglVertexP2), data); cogl_attribute_buffer_new (ctx, n_vertices * sizeof (CoglVertexP2), data);
CoglAttribute *attributes[1]; CoglAttribute *attributes[1];
attributes[0] = cogl_attribute_new (attribute_buffer, attributes[0] = cogl_attribute_new (attribute_buffer,
@ -150,12 +151,13 @@ cogl_primitive_new_p2 (CoglVerticesMode mode,
} }
CoglPrimitive * CoglPrimitive *
cogl_primitive_new_p3 (CoglVerticesMode mode, cogl_primitive_new_p3 (CoglContext *ctx,
CoglVerticesMode mode,
int n_vertices, int n_vertices,
const CoglVertexP3 *data) const CoglVertexP3 *data)
{ {
CoglAttributeBuffer *attribute_buffer = CoglAttributeBuffer *attribute_buffer =
cogl_attribute_buffer_new (n_vertices * sizeof (CoglVertexP3), data); cogl_attribute_buffer_new (ctx, n_vertices * sizeof (CoglVertexP3), data);
CoglAttribute *attributes[1]; CoglAttribute *attributes[1];
attributes[0] = cogl_attribute_new (attribute_buffer, attributes[0] = cogl_attribute_new (attribute_buffer,
@ -173,12 +175,13 @@ cogl_primitive_new_p3 (CoglVerticesMode mode,
} }
CoglPrimitive * CoglPrimitive *
cogl_primitive_new_p2c4 (CoglVerticesMode mode, cogl_primitive_new_p2c4 (CoglContext *ctx,
CoglVerticesMode mode,
int n_vertices, int n_vertices,
const CoglVertexP2C4 *data) const CoglVertexP2C4 *data)
{ {
CoglAttributeBuffer *attribute_buffer = CoglAttributeBuffer *attribute_buffer =
cogl_attribute_buffer_new (n_vertices * sizeof (CoglVertexP2C4), data); cogl_attribute_buffer_new (ctx, n_vertices * sizeof (CoglVertexP2C4), data);
CoglAttribute *attributes[2]; CoglAttribute *attributes[2];
attributes[0] = cogl_attribute_new (attribute_buffer, attributes[0] = cogl_attribute_new (attribute_buffer,
@ -202,12 +205,13 @@ cogl_primitive_new_p2c4 (CoglVerticesMode mode,
} }
CoglPrimitive * CoglPrimitive *
cogl_primitive_new_p3c4 (CoglVerticesMode mode, cogl_primitive_new_p3c4 (CoglContext *ctx,
CoglVerticesMode mode,
int n_vertices, int n_vertices,
const CoglVertexP3C4 *data) const CoglVertexP3C4 *data)
{ {
CoglAttributeBuffer *attribute_buffer = CoglAttributeBuffer *attribute_buffer =
cogl_attribute_buffer_new (n_vertices * sizeof (CoglVertexP3C4), data); cogl_attribute_buffer_new (ctx, n_vertices * sizeof (CoglVertexP3C4), data);
CoglAttribute *attributes[2]; CoglAttribute *attributes[2];
attributes[0] = cogl_attribute_new (attribute_buffer, attributes[0] = cogl_attribute_new (attribute_buffer,
@ -231,12 +235,13 @@ cogl_primitive_new_p3c4 (CoglVerticesMode mode,
} }
CoglPrimitive * CoglPrimitive *
cogl_primitive_new_p2t2 (CoglVerticesMode mode, cogl_primitive_new_p2t2 (CoglContext *ctx,
CoglVerticesMode mode,
int n_vertices, int n_vertices,
const CoglVertexP2T2 *data) const CoglVertexP2T2 *data)
{ {
CoglAttributeBuffer *attribute_buffer = CoglAttributeBuffer *attribute_buffer =
cogl_attribute_buffer_new (n_vertices * sizeof (CoglVertexP2T2), data); cogl_attribute_buffer_new (ctx, n_vertices * sizeof (CoglVertexP2T2), data);
CoglAttribute *attributes[2]; CoglAttribute *attributes[2];
attributes[0] = cogl_attribute_new (attribute_buffer, attributes[0] = cogl_attribute_new (attribute_buffer,
@ -260,12 +265,13 @@ cogl_primitive_new_p2t2 (CoglVerticesMode mode,
} }
CoglPrimitive * CoglPrimitive *
cogl_primitive_new_p3t2 (CoglVerticesMode mode, cogl_primitive_new_p3t2 (CoglContext *ctx,
CoglVerticesMode mode,
int n_vertices, int n_vertices,
const CoglVertexP3T2 *data) const CoglVertexP3T2 *data)
{ {
CoglAttributeBuffer *attribute_buffer = CoglAttributeBuffer *attribute_buffer =
cogl_attribute_buffer_new (n_vertices * sizeof (CoglVertexP3T2), data); cogl_attribute_buffer_new (ctx, n_vertices * sizeof (CoglVertexP3T2), data);
CoglAttribute *attributes[2]; CoglAttribute *attributes[2];
attributes[0] = cogl_attribute_new (attribute_buffer, attributes[0] = cogl_attribute_new (attribute_buffer,
@ -289,12 +295,14 @@ cogl_primitive_new_p3t2 (CoglVerticesMode mode,
} }
CoglPrimitive * CoglPrimitive *
cogl_primitive_new_p2t2c4 (CoglVerticesMode mode, cogl_primitive_new_p2t2c4 (CoglContext *ctx,
CoglVerticesMode mode,
int n_vertices, int n_vertices,
const CoglVertexP2T2C4 *data) const CoglVertexP2T2C4 *data)
{ {
CoglAttributeBuffer *attribute_buffer = CoglAttributeBuffer *attribute_buffer =
cogl_attribute_buffer_new (n_vertices * sizeof (CoglVertexP2T2C4), data); cogl_attribute_buffer_new (ctx,
n_vertices * sizeof (CoglVertexP2T2C4), data);
CoglAttribute *attributes[3]; CoglAttribute *attributes[3];
attributes[0] = cogl_attribute_new (attribute_buffer, attributes[0] = cogl_attribute_new (attribute_buffer,
@ -324,12 +332,14 @@ cogl_primitive_new_p2t2c4 (CoglVerticesMode mode,
} }
CoglPrimitive * CoglPrimitive *
cogl_primitive_new_p3t2c4 (CoglVerticesMode mode, cogl_primitive_new_p3t2c4 (CoglContext *ctx,
CoglVerticesMode mode,
int n_vertices, int n_vertices,
const CoglVertexP3T2C4 *data) const CoglVertexP3T2C4 *data)
{ {
CoglAttributeBuffer *attribute_buffer = CoglAttributeBuffer *attribute_buffer =
cogl_attribute_buffer_new (n_vertices * sizeof (CoglVertexP3T2C4), data); cogl_attribute_buffer_new (ctx,
n_vertices * sizeof (CoglVertexP3T2C4), data);
CoglAttribute *attributes[3]; CoglAttribute *attributes[3];
attributes[0] = cogl_attribute_new (attribute_buffer, attributes[0] = cogl_attribute_new (attribute_buffer,

View File

@ -244,6 +244,7 @@ cogl_primitive_new_with_attributes (CoglVerticesMode mode,
/** /**
* cogl_primitive_new_p2: * cogl_primitive_new_p2:
* @context: A #CoglContext
* @mode: A #CoglVerticesMode defining how to draw the vertices * @mode: A #CoglVerticesMode defining how to draw the vertices
* @n_vertices: The number of vertices to read from @data and also * @n_vertices: The number of vertices to read from @data and also
* the number of vertices to read when later drawing. * the number of vertices to read when later drawing.
@ -289,12 +290,14 @@ cogl_primitive_new_with_attributes (CoglVerticesMode mode,
* Stability: Unstable * Stability: Unstable
*/ */
CoglPrimitive * CoglPrimitive *
cogl_primitive_new_p2 (CoglVerticesMode mode, cogl_primitive_new_p2 (CoglContext *context,
CoglVerticesMode mode,
int n_vertices, int n_vertices,
const CoglVertexP2 *data); const CoglVertexP2 *data);
/** /**
* cogl_primitive_new_p3: * cogl_primitive_new_p3:
* @context: A #CoglContext
* @mode: A #CoglVerticesMode defining how to draw the vertices * @mode: A #CoglVerticesMode defining how to draw the vertices
* @n_vertices: The number of vertices to read from @data and also * @n_vertices: The number of vertices to read from @data and also
* the number of vertices to read when later drawing. * the number of vertices to read when later drawing.
@ -340,12 +343,14 @@ cogl_primitive_new_p2 (CoglVerticesMode mode,
* Stability: Unstable * Stability: Unstable
*/ */
CoglPrimitive * CoglPrimitive *
cogl_primitive_new_p3 (CoglVerticesMode mode, cogl_primitive_new_p3 (CoglContext *context,
CoglVerticesMode mode,
int n_vertices, int n_vertices,
const CoglVertexP3 *data); const CoglVertexP3 *data);
/** /**
* cogl_primitive_new_p2c4: * cogl_primitive_new_p2c4:
* @context: A #CoglContext
* @mode: A #CoglVerticesMode defining how to draw the vertices * @mode: A #CoglVerticesMode defining how to draw the vertices
* @n_vertices: The number of vertices to read from @data and also * @n_vertices: The number of vertices to read from @data and also
* the number of vertices to read when later drawing. * the number of vertices to read when later drawing.
@ -393,12 +398,14 @@ cogl_primitive_new_p3 (CoglVerticesMode mode,
* Stability: Unstable * Stability: Unstable
*/ */
CoglPrimitive * CoglPrimitive *
cogl_primitive_new_p2c4 (CoglVerticesMode mode, cogl_primitive_new_p2c4 (CoglContext *context,
CoglVerticesMode mode,
int n_vertices, int n_vertices,
const CoglVertexP2C4 *data); const CoglVertexP2C4 *data);
/** /**
* cogl_primitive_new_p3c4: * cogl_primitive_new_p3c4:
* @context: A #CoglContext
* @mode: A #CoglVerticesMode defining how to draw the vertices * @mode: A #CoglVerticesMode defining how to draw the vertices
* @n_vertices: The number of vertices to read from @data and also * @n_vertices: The number of vertices to read from @data and also
* the number of vertices to read when later drawing. * the number of vertices to read when later drawing.
@ -446,12 +453,14 @@ cogl_primitive_new_p2c4 (CoglVerticesMode mode,
* Stability: Unstable * Stability: Unstable
*/ */
CoglPrimitive * CoglPrimitive *
cogl_primitive_new_p3c4 (CoglVerticesMode mode, cogl_primitive_new_p3c4 (CoglContext *context,
CoglVerticesMode mode,
int n_vertices, int n_vertices,
const CoglVertexP3C4 *data); const CoglVertexP3C4 *data);
/** /**
* cogl_primitive_new_p2t2: * cogl_primitive_new_p2t2:
* @context: A #CoglContext
* @mode: A #CoglVerticesMode defining how to draw the vertices * @mode: A #CoglVerticesMode defining how to draw the vertices
* @n_vertices: The number of vertices to read from @data and also * @n_vertices: The number of vertices to read from @data and also
* the number of vertices to read when later drawing. * the number of vertices to read when later drawing.
@ -499,12 +508,14 @@ cogl_primitive_new_p3c4 (CoglVerticesMode mode,
* Stability: Unstable * Stability: Unstable
*/ */
CoglPrimitive * CoglPrimitive *
cogl_primitive_new_p2t2 (CoglVerticesMode mode, cogl_primitive_new_p2t2 (CoglContext *context,
CoglVerticesMode mode,
int n_vertices, int n_vertices,
const CoglVertexP2T2 *data); const CoglVertexP2T2 *data);
/** /**
* cogl_primitive_new_p3t2: * cogl_primitive_new_p3t2:
* @context: A #CoglContext
* @mode: A #CoglVerticesMode defining how to draw the vertices * @mode: A #CoglVerticesMode defining how to draw the vertices
* @n_vertices: The number of vertices to read from @data and also * @n_vertices: The number of vertices to read from @data and also
* the number of vertices to read when later drawing. * the number of vertices to read when later drawing.
@ -552,12 +563,14 @@ cogl_primitive_new_p2t2 (CoglVerticesMode mode,
* Stability: Unstable * Stability: Unstable
*/ */
CoglPrimitive * CoglPrimitive *
cogl_primitive_new_p3t2 (CoglVerticesMode mode, cogl_primitive_new_p3t2 (CoglContext *context,
CoglVerticesMode mode,
int n_vertices, int n_vertices,
const CoglVertexP3T2 *data); const CoglVertexP3T2 *data);
/** /**
* cogl_primitive_new_p2t2c4: * cogl_primitive_new_p2t2c4:
* @context: A #CoglContext
* @mode: A #CoglVerticesMode defining how to draw the vertices * @mode: A #CoglVerticesMode defining how to draw the vertices
* @n_vertices: The number of vertices to read from @data and also * @n_vertices: The number of vertices to read from @data and also
* the number of vertices to read when later drawing. * the number of vertices to read when later drawing.
@ -605,12 +618,14 @@ cogl_primitive_new_p3t2 (CoglVerticesMode mode,
* Stability: Unstable * Stability: Unstable
*/ */
CoglPrimitive * CoglPrimitive *
cogl_primitive_new_p2t2c4 (CoglVerticesMode mode, cogl_primitive_new_p2t2c4 (CoglContext *context,
CoglVerticesMode mode,
int n_vertices, int n_vertices,
const CoglVertexP2T2C4 *data); const CoglVertexP2T2C4 *data);
/** /**
* cogl_primitive_new_p3t2c4: * cogl_primitive_new_p3t2c4:
* @context: A #CoglContext
* @mode: A #CoglVerticesMode defining how to draw the vertices * @mode: A #CoglVerticesMode defining how to draw the vertices
* @n_vertices: The number of vertices to read from @data and also * @n_vertices: The number of vertices to read from @data and also
* the number of vertices to read when later drawing. * the number of vertices to read when later drawing.
@ -658,7 +673,8 @@ cogl_primitive_new_p2t2c4 (CoglVerticesMode mode,
* Stability: Unstable * Stability: Unstable
*/ */
CoglPrimitive * CoglPrimitive *
cogl_primitive_new_p3t2c4 (CoglVerticesMode mode, cogl_primitive_new_p3t2c4 (CoglContext *context,
CoglVerticesMode mode,
int n_vertices, int n_vertices,
const CoglVertexP3T2C4 *data); const CoglVertexP3T2C4 *data);
int int

View File

@ -861,7 +861,10 @@ _cogl_rectangle_immediate (CoglFramebuffer *framebuffer,
CoglAttributeBuffer *attribute_buffer; CoglAttributeBuffer *attribute_buffer;
CoglAttribute *attributes[1]; CoglAttribute *attributes[1];
attribute_buffer = cogl_attribute_buffer_new (sizeof (vertices), vertices); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
attribute_buffer =
cogl_attribute_buffer_new (ctx, sizeof (vertices), vertices);
attributes[0] = cogl_attribute_new (attribute_buffer, attributes[0] = cogl_attribute_new (attribute_buffer,
"cogl_position_in", "cogl_position_in",
sizeof (float) * 2, /* stride */ sizeof (float) * 2, /* stride */
@ -1008,7 +1011,7 @@ cogl_polygon (const CoglTextureVertex *vertices,
g_array_set_size (ctx->polygon_vertices, n_vertices * stride); g_array_set_size (ctx->polygon_vertices, n_vertices * stride);
attribute_buffer = attribute_buffer =
cogl_attribute_buffer_new (n_vertices * stride_bytes, NULL); cogl_attribute_buffer_new (ctx, n_vertices * stride_bytes, NULL);
attributes[0] = cogl_attribute_new (attribute_buffer, attributes[0] = cogl_attribute_new (attribute_buffer,
"cogl_position_in", "cogl_position_in",

View File

@ -1133,8 +1133,10 @@ cogl_vertex_buffer_vbo_resolve (CoglVertexBuffer *buffer,
if (!found_target_vbo) if (!found_target_vbo)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
new_cogl_vbo->attribute_buffer = new_cogl_vbo->attribute_buffer =
cogl_attribute_buffer_new (new_cogl_vbo->buffer_bytes, NULL); cogl_attribute_buffer_new (ctx, new_cogl_vbo->buffer_bytes, NULL);
upload_attributes (new_cogl_vbo); upload_attributes (new_cogl_vbo);
*final_vbos = g_list_prepend (*final_vbos, new_cogl_vbo); *final_vbos = g_list_prepend (*final_vbos, new_cogl_vbo);
@ -1665,8 +1667,11 @@ cogl_vertex_buffer_indices_new (CoglIndicesType indices_type,
const void *indices_array, const void *indices_array,
int indices_len) int indices_len)
{ {
CoglIndices *indices = CoglIndices *indices;
cogl_indices_new (indices_type, indices_array, indices_len);
_COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE);
indices = cogl_indices_new (ctx, indices_type, indices_array, indices_len);
return _cogl_vertex_buffer_indices_new_real (indices); return _cogl_vertex_buffer_indices_new_real (indices);
} }
@ -1747,7 +1752,7 @@ cogl_vertex_buffer_indices_get_for_quads (unsigned int n_indices)
if (ctx->quad_buffer_indices_byte == COGL_INVALID_HANDLE) if (ctx->quad_buffer_indices_byte == COGL_INVALID_HANDLE)
{ {
/* NB: cogl_get_quad_indices takes n_quads not n_indices... */ /* NB: cogl_get_quad_indices takes n_quads not n_indices... */
CoglIndices *indices = cogl_get_rectangle_indices (256 / 4); CoglIndices *indices = cogl_get_rectangle_indices (ctx, 256 / 4);
cogl_object_ref (indices); cogl_object_ref (indices);
ctx->quad_buffer_indices_byte = ctx->quad_buffer_indices_byte =
_cogl_vertex_buffer_indices_new_real (indices); _cogl_vertex_buffer_indices_new_real (indices);
@ -1767,7 +1772,8 @@ cogl_vertex_buffer_indices_get_for_quads (unsigned int n_indices)
if (ctx->quad_buffer_indices == COGL_INVALID_HANDLE) if (ctx->quad_buffer_indices == COGL_INVALID_HANDLE)
{ {
/* NB: cogl_get_quad_indices takes n_quads not n_indices... */ /* NB: cogl_get_quad_indices takes n_quads not n_indices... */
CoglIndices *indices = cogl_get_rectangle_indices (n_indices / 6); CoglIndices *indices =
cogl_get_rectangle_indices (ctx, n_indices / 6);
cogl_object_ref (indices); cogl_object_ref (indices);
ctx->quad_buffer_indices = ctx->quad_buffer_indices =
_cogl_vertex_buffer_indices_new_real (indices); _cogl_vertex_buffer_indices_new_real (indices);

View File

@ -1267,6 +1267,8 @@ _cogl_path_build_fill_attribute_buffer (CoglPath *path)
CoglPathData *data = path->data; CoglPathData *data = path->data;
int i; int i;
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
/* If we've already got a vbo then we don't need to do anything */ /* If we've already got a vbo then we don't need to do anything */
if (data->fill_attribute_buffer) if (data->fill_attribute_buffer)
return; return;
@ -1352,7 +1354,8 @@ _cogl_path_build_fill_attribute_buffer (CoglPath *path)
gluDeleteTess (tess.glu_tess); gluDeleteTess (tess.glu_tess);
data->fill_attribute_buffer = data->fill_attribute_buffer =
cogl_attribute_buffer_new (sizeof (CoglPathTesselatorVertex) * cogl_attribute_buffer_new (ctx,
sizeof (CoglPathTesselatorVertex) *
tess.vertices->len, tess.vertices->len,
tess.vertices->data); tess.vertices->data);
g_array_free (tess.vertices, TRUE); g_array_free (tess.vertices, TRUE);
@ -1372,7 +1375,8 @@ _cogl_path_build_fill_attribute_buffer (CoglPath *path)
2, /* n_components */ 2, /* n_components */
COGL_ATTRIBUTE_TYPE_FLOAT); COGL_ATTRIBUTE_TYPE_FLOAT);
data->fill_vbo_indices = cogl_indices_new (tess.indices_type, data->fill_vbo_indices = cogl_indices_new (ctx,
tess.indices_type,
tess.indices->data, tess.indices->data,
tess.indices->len); tess.indices->len);
data->fill_vbo_n_indices = tess.indices->len; data->fill_vbo_n_indices = tess.indices->len;
@ -1390,12 +1394,14 @@ _cogl_path_build_stroke_attribute_buffer (CoglPath *path)
floatVec2 *buffer_p; floatVec2 *buffer_p;
unsigned int i; unsigned int i;
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
/* If we've already got a cached vbo then we don't need to do anything */ /* If we've already got a cached vbo then we don't need to do anything */
if (data->stroke_attribute_buffer) if (data->stroke_attribute_buffer)
return; return;
data->stroke_attribute_buffer = data->stroke_attribute_buffer =
cogl_attribute_buffer_new (data->path_nodes->len * sizeof (floatVec2), cogl_attribute_buffer_new (ctx, data->path_nodes->len * sizeof (floatVec2),
NULL); NULL);
buffer = COGL_BUFFER (data->stroke_attribute_buffer); buffer = COGL_BUFFER (data->stroke_attribute_buffer);

View File

@ -209,8 +209,8 @@ main (int argc, char **argv)
* cogl_get_rectangle_indices() is a convenience function for * cogl_get_rectangle_indices() is a convenience function for
* accessing internal index buffers that can be shared. * accessing internal index buffers that can be shared.
*/ */
data.indices = cogl_get_rectangle_indices (6 /* n_rectangles */); data.indices = cogl_get_rectangle_indices (ctx, 6 /* n_rectangles */);
data.prim = cogl_primitive_new_p3t2 (COGL_VERTICES_MODE_TRIANGLES, data.prim = cogl_primitive_new_p3t2 (ctx, COGL_VERTICES_MODE_TRIANGLES,
G_N_ELEMENTS (vertices), G_N_ELEMENTS (vertices),
vertices); vertices);
/* Each face will have 6 indices so we have 6 * 6 indices in total... */ /* Each face will have 6 indices so we have 6 * 6 indices in total... */

View File

@ -29,7 +29,7 @@ main (int argc, char **argv)
cogl_onscreen_show (onscreen); cogl_onscreen_show (onscreen);
fb = COGL_FRAMEBUFFER (onscreen); fb = COGL_FRAMEBUFFER (onscreen);
triangle = cogl_primitive_new_p2c4 (COGL_VERTICES_MODE_TRIANGLES, triangle = cogl_primitive_new_p2c4 (ctx, COGL_VERTICES_MODE_TRIANGLES,
3, triangle_vertices); 3, triangle_vertices);
pipeline = cogl_pipeline_new (); pipeline = cogl_pipeline_new ();

View File

@ -77,7 +77,7 @@ main (int argc, char **argv)
cogl_framebuffer_set_samples_per_pixel (offscreen_fb, 0); cogl_framebuffer_set_samples_per_pixel (offscreen_fb, 0);
} }
triangle = cogl_primitive_new_p2c4 (COGL_VERTICES_MODE_TRIANGLES, triangle = cogl_primitive_new_p2c4 (ctx, COGL_VERTICES_MODE_TRIANGLES,
3, triangle_vertices); 3, triangle_vertices);
pipeline = cogl_pipeline_new (); pipeline = cogl_pipeline_new ();

View File

@ -148,7 +148,7 @@ main (int argc, char **argv)
cogl_onscreen_show (onscreen); cogl_onscreen_show (onscreen);
data.triangle = cogl_primitive_new_p2c4 (COGL_VERTICES_MODE_TRIANGLES, data.triangle = cogl_primitive_new_p2c4 (ctx, COGL_VERTICES_MODE_TRIANGLES,
3, triangle_vertices); 3, triangle_vertices);
data.pipeline = cogl_pipeline_new (); data.pipeline = cogl_pipeline_new ();
while (!data.quit) while (!data.quit)

View File

@ -149,7 +149,7 @@ main (int argc, char **argv)
fb = COGL_FRAMEBUFFER (onscreen); fb = COGL_FRAMEBUFFER (onscreen);
triangle = cogl_primitive_new_p2c4 (COGL_VERTICES_MODE_TRIANGLES, triangle = cogl_primitive_new_p2c4 (ctx, COGL_VERTICES_MODE_TRIANGLES,
3, triangle_vertices); 3, triangle_vertices);
pipeline = cogl_pipeline_new (); pipeline = cogl_pipeline_new ();
for (;;) for (;;)

View File

@ -751,7 +751,8 @@ main (int argc, char **argv)
if (wl_display_add_socket (compositor.wayland_display, "wayland-0")) if (wl_display_add_socket (compositor.wayland_display, "wayland-0"))
g_error ("Failed to create socket"); g_error ("Failed to create socket");
compositor.triangle = cogl_primitive_new_p2c4 (COGL_VERTICES_MODE_TRIANGLES, compositor.triangle = cogl_primitive_new_p2c4 (compositor.cogl_context,
COGL_VERTICES_MODE_TRIANGLES,
3, triangle_vertices); 3, triangle_vertices);
compositor.triangle_pipeline = cogl_pipeline_new (); compositor.triangle_pipeline = cogl_pipeline_new ();

View File

@ -6,6 +6,7 @@
typedef struct _TestState typedef struct _TestState
{ {
CoglContext *ctx;
CoglFramebuffer *fb; CoglFramebuffer *fb;
CoglPipeline *pipeline; CoglPipeline *pipeline;
} TestState; } TestState;
@ -44,7 +45,8 @@ test_float_verts (TestState *state, int offset_x, int offset_y)
{ 15, 0, /**/ 0, 1, 0, 1 } { 15, 0, /**/ 0, 1, 0, 1 }
}; };
buffer = cogl_attribute_buffer_new (sizeof (float_verts), float_verts); buffer = cogl_attribute_buffer_new (state->ctx,
sizeof (float_verts), float_verts);
attributes[0] = cogl_attribute_new (buffer, attributes[0] = cogl_attribute_new (buffer,
"cogl_position_in", "cogl_position_in",
sizeof (FloatVert), sizeof (FloatVert),
@ -103,7 +105,8 @@ test_byte_verts (TestState *state, int offset_x, int offset_y)
{ 0, 0, /**/ 0, 0, 1, 1 }, { 0, 0, /**/ 0, 0, 1, 1 },
}; };
buffer = cogl_attribute_buffer_new (sizeof (norm_verts), norm_verts); buffer = cogl_attribute_buffer_new (state->ctx,
sizeof (norm_verts), norm_verts);
attributes[0] = cogl_attribute_new (buffer, attributes[0] = cogl_attribute_new (buffer,
"cogl_position_in", "cogl_position_in",
sizeof (ByteVert), sizeof (ByteVert),
@ -132,7 +135,8 @@ test_byte_verts (TestState *state, int offset_x, int offset_y)
cogl_object_unref (attributes[1]); cogl_object_unref (attributes[1]);
/* Test again with unnormalized attributes */ /* Test again with unnormalized attributes */
unnorm_buffer = cogl_attribute_buffer_new (sizeof (unnorm_verts), unnorm_buffer = cogl_attribute_buffer_new (state->ctx,
sizeof (unnorm_verts),
unnorm_verts); unnorm_verts);
attributes[1] = cogl_attribute_new (unnorm_buffer, attributes[1] = cogl_attribute_new (unnorm_buffer,
"color", "color",
@ -191,7 +195,8 @@ test_short_verts (TestState *state, int offset_x, int offset_y)
cogl_pipeline_set_color4ub (pipeline, 255, 0, 0, 255); cogl_pipeline_set_color4ub (pipeline, 255, 0, 0, 255);
buffer = cogl_attribute_buffer_new (sizeof (short_verts), short_verts); buffer = cogl_attribute_buffer_new (state->ctx,
sizeof (short_verts), short_verts);
attributes[0] = cogl_attribute_new (buffer, attributes[0] = cogl_attribute_new (buffer,
"pos", "pos",
sizeof (ShortVert), sizeof (ShortVert),
@ -274,6 +279,8 @@ test_cogl_custom_attributes (TestUtilsGTestFixture *fixture,
TestState state; TestState state;
state.fb = shared_state->fb; state.fb = shared_state->fb;
state.ctx = shared_state->ctx;
cogl_ortho (/* left, right */ cogl_ortho (/* left, right */
0, cogl_framebuffer_get_width (shared_state->fb), 0, cogl_framebuffer_get_width (shared_state->fb),
/* bottom, top */ /* bottom, top */

View File

@ -17,32 +17,34 @@ typedef struct _TestState
#define N_ATTRIBS 8 #define N_ATTRIBS 8
typedef CoglPrimitive * (* TestPrimFunc) (guint32 *expected_color); typedef CoglPrimitive * (* TestPrimFunc) (CoglContext *ctx, guint32 *expected_color);
static CoglPrimitive * static CoglPrimitive *
test_prim_p2 (guint32 *expected_color) test_prim_p2 (CoglContext *ctx, guint32 *expected_color)
{ {
static const CoglVertexP2 verts[] = static const CoglVertexP2 verts[] =
{ { 0, 0 }, { 0, 10 }, { 10, 0 } }; { { 0, 0 }, { 0, 10 }, { 10, 0 } };
return cogl_primitive_new_p2 (COGL_VERTICES_MODE_TRIANGLES, return cogl_primitive_new_p2 (ctx,
COGL_VERTICES_MODE_TRIANGLES,
3, /* n_vertices */ 3, /* n_vertices */
verts); verts);
} }
static CoglPrimitive * static CoglPrimitive *
test_prim_p3 (guint32 *expected_color) test_prim_p3 (CoglContext *ctx, guint32 *expected_color)
{ {
static const CoglVertexP3 verts[] = static const CoglVertexP3 verts[] =
{ { 0, 0, 0 }, { 0, 10, 0 }, { 10, 0, 0 } }; { { 0, 0, 0 }, { 0, 10, 0 }, { 10, 0, 0 } };
return cogl_primitive_new_p3 (COGL_VERTICES_MODE_TRIANGLES, return cogl_primitive_new_p3 (ctx,
COGL_VERTICES_MODE_TRIANGLES,
3, /* n_vertices */ 3, /* n_vertices */
verts); verts);
} }
static CoglPrimitive * static CoglPrimitive *
test_prim_p2c4 (guint32 *expected_color) test_prim_p2c4 (CoglContext *ctx, guint32 *expected_color)
{ {
static const CoglVertexP2C4 verts[] = static const CoglVertexP2C4 verts[] =
{ { 0, 0, 255, 255, 0, 255 }, { { 0, 0, 255, 255, 0, 255 },
@ -51,13 +53,14 @@ test_prim_p2c4 (guint32 *expected_color)
*expected_color = 0xffff00ff; *expected_color = 0xffff00ff;
return cogl_primitive_new_p2c4 (COGL_VERTICES_MODE_TRIANGLES, return cogl_primitive_new_p2c4 (ctx,
COGL_VERTICES_MODE_TRIANGLES,
3, /* n_vertices */ 3, /* n_vertices */
verts); verts);
} }
static CoglPrimitive * static CoglPrimitive *
test_prim_p3c4 (guint32 *expected_color) test_prim_p3c4 (CoglContext *ctx, guint32 *expected_color)
{ {
static const CoglVertexP3C4 verts[] = static const CoglVertexP3C4 verts[] =
{ { 0, 0, 0, 255, 255, 0, 255 }, { { 0, 0, 0, 255, 255, 0, 255 },
@ -66,13 +69,14 @@ test_prim_p3c4 (guint32 *expected_color)
*expected_color = 0xffff00ff; *expected_color = 0xffff00ff;
return cogl_primitive_new_p3c4 (COGL_VERTICES_MODE_TRIANGLES, return cogl_primitive_new_p3c4 (ctx,
COGL_VERTICES_MODE_TRIANGLES,
3, /* n_vertices */ 3, /* n_vertices */
verts); verts);
} }
static CoglPrimitive * static CoglPrimitive *
test_prim_p2t2 (guint32 *expected_color) test_prim_p2t2 (CoglContext *ctx, guint32 *expected_color)
{ {
static const CoglVertexP2T2 verts[] = static const CoglVertexP2T2 verts[] =
{ { 0, 0, 1, 0 }, { { 0, 0, 1, 0 },
@ -81,13 +85,14 @@ test_prim_p2t2 (guint32 *expected_color)
*expected_color = TEX_COLOR; *expected_color = TEX_COLOR;
return cogl_primitive_new_p2t2 (COGL_VERTICES_MODE_TRIANGLES, return cogl_primitive_new_p2t2 (ctx,
COGL_VERTICES_MODE_TRIANGLES,
3, /* n_vertices */ 3, /* n_vertices */
verts); verts);
} }
static CoglPrimitive * static CoglPrimitive *
test_prim_p3t2 (guint32 *expected_color) test_prim_p3t2 (CoglContext *ctx, guint32 *expected_color)
{ {
static const CoglVertexP3T2 verts[] = static const CoglVertexP3T2 verts[] =
{ { 0, 0, 0, 1, 0 }, { { 0, 0, 0, 1, 0 },
@ -96,13 +101,14 @@ test_prim_p3t2 (guint32 *expected_color)
*expected_color = TEX_COLOR; *expected_color = TEX_COLOR;
return cogl_primitive_new_p3t2 (COGL_VERTICES_MODE_TRIANGLES, return cogl_primitive_new_p3t2 (ctx,
COGL_VERTICES_MODE_TRIANGLES,
3, /* n_vertices */ 3, /* n_vertices */
verts); verts);
} }
static CoglPrimitive * static CoglPrimitive *
test_prim_p2t2c4 (guint32 *expected_color) test_prim_p2t2c4 (CoglContext *ctx, guint32 *expected_color)
{ {
static const CoglVertexP2T2C4 verts[] = static const CoglVertexP2T2C4 verts[] =
{ { 0, 0, 1, 0, 0xff, 0xff, 0xf0, 0xff }, { { 0, 0, 1, 0, 0xff, 0xff, 0xf0, 0xff },
@ -112,13 +118,14 @@ test_prim_p2t2c4 (guint32 *expected_color)
/* The blue component of the texture color should be replaced with 0xf0 */ /* The blue component of the texture color should be replaced with 0xf0 */
*expected_color = (TEX_COLOR & 0xffff00ff) | 0x0000f000; *expected_color = (TEX_COLOR & 0xffff00ff) | 0x0000f000;
return cogl_primitive_new_p2t2c4 (COGL_VERTICES_MODE_TRIANGLES, return cogl_primitive_new_p2t2c4 (ctx,
COGL_VERTICES_MODE_TRIANGLES,
3, /* n_vertices */ 3, /* n_vertices */
verts); verts);
} }
static CoglPrimitive * static CoglPrimitive *
test_prim_p3t2c4 (guint32 *expected_color) test_prim_p3t2c4 (CoglContext *ctx, guint32 *expected_color)
{ {
static const CoglVertexP3T2C4 verts[] = static const CoglVertexP3T2C4 verts[] =
{ { 0, 0, 0, 1, 0, 0xff, 0xff, 0xf0, 0xff }, { { 0, 0, 0, 1, 0, 0xff, 0xff, 0xf0, 0xff },
@ -128,7 +135,8 @@ test_prim_p3t2c4 (guint32 *expected_color)
/* The blue component of the texture color should be replaced with 0xf0 */ /* The blue component of the texture color should be replaced with 0xf0 */
*expected_color = (TEX_COLOR & 0xffff00ff) | 0x0000f000; *expected_color = (TEX_COLOR & 0xffff00ff) | 0x0000f000;
return cogl_primitive_new_p3t2c4 (COGL_VERTICES_MODE_TRIANGLES, return cogl_primitive_new_p3t2c4 (ctx,
COGL_VERTICES_MODE_TRIANGLES,
3, /* n_vertices */ 3, /* n_vertices */
verts); verts);
} }
@ -184,7 +192,7 @@ test_paint (TestState *state)
CoglPrimitive *prim; CoglPrimitive *prim;
guint32 expected_color = PRIM_COLOR; guint32 expected_color = PRIM_COLOR;
prim = test_prim_funcs[i] (&expected_color); prim = test_prim_funcs[i] (state->context, &expected_color);
cogl_push_matrix (); cogl_push_matrix ();
cogl_translate (i * 10, 0, 0); cogl_translate (i * 10, 0, 0);
@ -227,7 +235,8 @@ static void
test_copy (TestState *state) test_copy (TestState *state)
{ {
static const guint16 indices_data[2] = { 1, 2 }; static const guint16 indices_data[2] = { 1, 2 };
CoglAttributeBuffer *buffer = cogl_attribute_buffer_new (100, NULL); CoglAttributeBuffer *buffer =
cogl_attribute_buffer_new (state->context, 100, NULL);
CoglAttribute *attributes[N_ATTRIBS]; CoglAttribute *attributes[N_ATTRIBS];
CoglAttribute *attributes_a[N_ATTRIBS], *attributes_b[N_ATTRIBS]; CoglAttribute *attributes_a[N_ATTRIBS], *attributes_b[N_ATTRIBS];
CoglAttribute **p; CoglAttribute **p;
@ -252,7 +261,8 @@ test_copy (TestState *state)
attributes, attributes,
N_ATTRIBS); N_ATTRIBS);
indices = cogl_indices_new (COGL_INDICES_TYPE_UNSIGNED_SHORT, indices = cogl_indices_new (state->context,
COGL_INDICES_TYPE_UNSIGNED_SHORT,
indices_data, indices_data,
2 /* n_indices */); 2 /* n_indices */);