buffer: remove flag macros

All the macros get used for are to |= (a new flag bit), &= ~(a flag bit)
or use the & operator to test if a flag bit is set. I haven't found the
code more readable with these macros, but several times now I've felt
the need to double check if these macros do anything else behind the
hood or I've forgotten what flags are available so I've had to go to the
macro definition to see what the full enum names are for the flags (the
macros use symbol concatenation) so I can search for the definition of
all the flags. It turns out they are defined next to the macro so you
don't have to search far, but without the macro that wouldn't have been
necessary.

The more common use of the _IS_SET macro is actually more concise
expanded and imho since it doesn't hide anything in a separate header
file the code is more readable without the macro.
This commit is contained in:
Robert Bragg 2010-10-12 11:46:29 +01:00
parent 1bed79d19a
commit 071253c48b
3 changed files with 12 additions and 21 deletions

View File

@ -439,7 +439,7 @@ _cogl_bitmap_bind (CoglBitmap *bitmap,
/* If buffer is using a malloc fallback then we'll just use the /* If buffer is using a malloc fallback then we'll just use the
pointer directly */ pointer directly */
if (COGL_BUFFER_FLAG_IS_SET (bitmap->buffer, BUFFER_OBJECT)) if (bitmap->buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT)
{ {
ptr = NULL; ptr = NULL;
@ -473,7 +473,7 @@ _cogl_bitmap_unbind (CoglBitmap *bitmap)
implementation of unbind is the same as unmap */ implementation of unbind is the same as unmap */
if (bitmap->buffer) if (bitmap->buffer)
{ {
if (COGL_BUFFER_FLAG_IS_SET (bitmap->buffer, BUFFER_OBJECT)) if (bitmap->buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT)
_cogl_buffer_unbind (bitmap->buffer); _cogl_buffer_unbind (bitmap->buffer);
} }
else else

View File

@ -38,15 +38,6 @@ G_BEGIN_DECLS
#define COGL_BUFFER(buffer) ((CoglBuffer *)(buffer)) #define COGL_BUFFER(buffer) ((CoglBuffer *)(buffer))
#define COGL_BUFFER_SET_FLAG(buffer, flag) \
((buffer)->flags |= (COGL_BUFFER_FLAG_ ## flag))
#define COGL_BUFFER_CLEAR_FLAG(buffer, flag) \
((buffer)->flags &= ~(COGL_BUFFER_FLAG_ ## flag))
#define COGL_BUFFER_FLAG_IS_SET(buffer, flag) \
((buffer)->flags & (COGL_BUFFER_FLAG_ ## flag))
typedef struct _CoglBufferVtable CoglBufferVtable; typedef struct _CoglBufferVtable CoglBufferVtable;
struct _CoglBufferVtable struct _CoglBufferVtable

View File

@ -166,7 +166,7 @@ bo_map (CoglBuffer *buffer,
GE_RET( data, glMapBuffer (gl_target, GE_RET( data, glMapBuffer (gl_target,
_cogl_buffer_access_to_gl_enum (access)) ); _cogl_buffer_access_to_gl_enum (access)) );
if (data) if (data)
COGL_BUFFER_SET_FLAG (buffer, MAPPED); buffer->flags |= COGL_BUFFER_FLAG_MAPPED;
_cogl_buffer_unbind (buffer); _cogl_buffer_unbind (buffer);
@ -188,7 +188,7 @@ bo_unmap (CoglBuffer *buffer)
_cogl_buffer_bind (buffer, buffer->last_target); _cogl_buffer_bind (buffer, buffer->last_target);
GE( glUnmapBuffer (convert_bind_target_to_gl_target (buffer->last_target)) ); GE( glUnmapBuffer (convert_bind_target_to_gl_target (buffer->last_target)) );
COGL_BUFFER_CLEAR_FLAG (buffer, MAPPED); buffer->flags &= ~COGL_BUFFER_FLAG_MAPPED;
_cogl_buffer_unbind (buffer); _cogl_buffer_unbind (buffer);
#else #else
@ -242,14 +242,14 @@ malloc_map (CoglBuffer *buffer,
CoglBufferAccess access, CoglBufferAccess access,
CoglBufferMapHint hints) CoglBufferMapHint hints)
{ {
COGL_BUFFER_SET_FLAG (buffer, MAPPED); buffer->flags |= COGL_BUFFER_FLAG_MAPPED;
return buffer->data; return buffer->data;
} }
static void static void
malloc_unmap (CoglBuffer *buffer) malloc_unmap (CoglBuffer *buffer)
{ {
COGL_BUFFER_CLEAR_FLAG (buffer, MAPPED); buffer->flags &= ~COGL_BUFFER_FLAG_MAPPED;
} }
static gboolean static gboolean
@ -294,14 +294,14 @@ _cogl_buffer_initialize (CoglBuffer *buffer,
buffer->vtable.set_data = bo_set_data; buffer->vtable.set_data = bo_set_data;
GE( glGenBuffers (1, &buffer->gl_handle) ); GE( glGenBuffers (1, &buffer->gl_handle) );
COGL_BUFFER_SET_FLAG (buffer, BUFFER_OBJECT); buffer->flags |= COGL_BUFFER_FLAG_BUFFER_OBJECT;
} }
} }
void void
_cogl_buffer_fini (CoglBuffer *buffer) _cogl_buffer_fini (CoglBuffer *buffer)
{ {
g_return_if_fail (!COGL_BUFFER_FLAG_IS_SET (buffer, MAPPED)); g_return_if_fail (!(buffer->flags & COGL_BUFFER_FLAG_MAPPED));
} }
/* OpenGL ES 1.1 and 2 have a GL_OES_mapbuffer extension that is able to map /* OpenGL ES 1.1 and 2 have a GL_OES_mapbuffer extension that is able to map
@ -369,7 +369,7 @@ _cogl_buffer_bind (CoglBuffer *buffer, CoglBufferBindTarget target)
buffer->last_target = target; buffer->last_target = target;
if (COGL_BUFFER_FLAG_IS_SET (buffer, 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) );
@ -388,7 +388,7 @@ _cogl_buffer_unbind (CoglBuffer *buffer)
/* the unbind should pair up with a previous bind */ /* the unbind should pair up with a previous bind */
g_return_if_fail (ctx->current_buffer[buffer->last_target] == buffer); g_return_if_fail (ctx->current_buffer[buffer->last_target] == buffer);
if (COGL_BUFFER_FLAG_IS_SET (buffer, 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, 0) ); GE( glBindBuffer (gl_target, 0) );
@ -436,7 +436,7 @@ cogl_buffer_map (CoglBuffer *buffer,
if (!cogl_is_buffer (buffer)) if (!cogl_is_buffer (buffer))
return NULL; return NULL;
if (COGL_BUFFER_FLAG_IS_SET (buffer, MAPPED)) if (buffer->flags & COGL_BUFFER_FLAG_MAPPED)
return buffer->data; return buffer->data;
buffer->data = buffer->vtable.map (buffer, access, hints); buffer->data = buffer->vtable.map (buffer, access, hints);
@ -449,7 +449,7 @@ cogl_buffer_unmap (CoglBuffer *buffer)
if (!cogl_is_buffer (buffer)) if (!cogl_is_buffer (buffer))
return; return;
if (!COGL_BUFFER_FLAG_IS_SET (buffer, MAPPED)) if (!(buffer->flags & COGL_BUFFER_FLAG_MAPPED))
return; return;
buffer->vtable.unmap (buffer); buffer->vtable.unmap (buffer);