From 1c8b355bbb6f1aa466a8ca0b2a4732135413661b Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Tue, 26 Oct 2010 16:06:46 +0100 Subject: [PATCH] buffer: Add a store_created bit field member This adds a store_created bit field to CoglBuffer so we know if the underlying buffer has been allocated yet. Previously the code was trying to do something really wrong by accidentally using the COGL_PIXEL_ARRAY_FLAG_IS_SET macro (note "PIXEL_ARRAY") and what is more odd was the declaration of a CoglPixelArray *pixel_array in cogl-buffer.c which the buffer was being cast too before calling using the macro. Probably this was the fall-out of some previous code re-factoring. --- clutter/cogl/cogl/cogl-buffer-private.h | 2 ++ clutter/cogl/cogl/cogl-buffer.c | 25 +++++++++++-------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/clutter/cogl/cogl/cogl-buffer-private.h b/clutter/cogl/cogl/cogl-buffer-private.h index 46dff7209..a4b6e89bb 100644 --- a/clutter/cogl/cogl/cogl-buffer-private.h +++ b/clutter/cogl/cogl/cogl-buffer-private.h @@ -93,6 +93,8 @@ struct _CoglBuffer * the CoglBuffer is a VBO, PBO, ... or * points to allocated memory in the * fallback paths */ + + guint store_created:1; }; /* This is used to register a type to the list of handle types that diff --git a/clutter/cogl/cogl/cogl-buffer.c b/clutter/cogl/cogl/cogl-buffer.c index c55613fa8..b1d724236 100644 --- a/clutter/cogl/cogl/cogl-buffer.c +++ b/clutter/cogl/cogl/cogl-buffer.c @@ -136,8 +136,6 @@ bo_map (CoglBuffer *buffer, CoglBufferMapHint hints) { #ifndef COGL_HAS_GLES - - CoglPixelArray *pixel_array = COGL_PIXEL_ARRAY (buffer); guint8 *data; CoglBufferBindTarget target; GLenum gl_target; @@ -152,15 +150,14 @@ bo_map (CoglBuffer *buffer, /* create an empty store if we don't have one yet. creating the store * lazily allows the user of the CoglBuffer to set a hint before the * store is created. */ - if (!COGL_PIXEL_ARRAY_FLAG_IS_SET (pixel_array, STORE_CREATED) || - (hints & COGL_BUFFER_MAP_HINT_DISCARD)) + if (!buffer->store_created || (hints & COGL_BUFFER_MAP_HINT_DISCARD)) { GE( glBufferData (gl_target, buffer->size, NULL, _cogl_buffer_hints_to_gl_enum (buffer->usage_hint, buffer->update_hint)) ); - COGL_PIXEL_ARRAY_SET_FLAG (pixel_array, STORE_CREATED); + buffer->store_created = TRUE; } GE_RET( data, glMapBuffer (gl_target, @@ -202,7 +199,6 @@ bo_set_data (CoglBuffer *buffer, const guint8 *data, unsigned int size) { - CoglPixelArray *pixel_array = COGL_PIXEL_ARRAY (buffer); CoglBufferBindTarget target; GLenum gl_target; @@ -216,14 +212,14 @@ bo_set_data (CoglBuffer *buffer, /* create an empty store if we don't have one yet. creating the store * lazily allows the user of the CoglBuffer to set a hint before the * store is created. */ - if (!COGL_PIXEL_ARRAY_FLAG_IS_SET (pixel_array, STORE_CREATED)) + if (!buffer->store_created) { GE( glBufferData (gl_target, buffer->size, NULL, _cogl_buffer_hints_to_gl_enum (buffer->usage_hint, buffer->update_hint)) ); - COGL_PIXEL_ARRAY_SET_FLAG (pixel_array, STORE_CREATED); + buffer->store_created = TRUE; } GE( glBufferSubData (gl_target, offset, size, data) ); @@ -272,12 +268,13 @@ _cogl_buffer_initialize (CoglBuffer *buffer, { _COGL_GET_CONTEXT (ctx, NO_RETVAL); - buffer->flags = COGL_BUFFER_FLAG_NONE; - buffer->size = size; - buffer->last_target = default_target; - buffer->usage_hint = usage_hint; - buffer->update_hint = update_hint; - buffer->data = NULL; + buffer->flags = COGL_BUFFER_FLAG_NONE; + buffer->store_created = FALSE; + buffer->size = size; + buffer->last_target = default_target; + buffer->usage_hint = usage_hint; + buffer->update_hint = update_hint; + buffer->data = NULL; if (use_malloc) {