cogl-buffer: Handle subclass registration like cogl-texture

Instead of having to extend cogl_is_buffer with new buffer types
manually this now adds a new COGL_BUFFER_DEFINE macro to be used instead
of COGL_OBJECT_DEFINE for CoglBuffer subclasses. This macro will
automatically register the new type with ctx->buffer_types which will
iterated by cogl_is_buffer. This is the same coding pattern used for
CoglTexture.
This commit is contained in:
Robert Bragg
2010-07-03 23:56:44 +01:00
parent 1b7e362189
commit 9ceb0edf26
5 changed files with 44 additions and 4 deletions

View File

@ -68,15 +68,37 @@
#endif
/* XXX:
* The CoglHandle macros don't support any form of inheritance, so for
* now we implement the CoglObject support for the CoglBuffer
* abstract class manually.
*/
void
_cogl_buffer_register_buffer_type (GQuark type)
{
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
ctx->buffer_types = g_slist_prepend (ctx->buffer_types,
GINT_TO_POINTER (type));
}
gboolean
cogl_is_buffer (const void *object)
{
CoglObject *obj = (CoglObject *)object;
const CoglHandleObject *obj = object;
GSList *l;
if (obj == NULL)
_COGL_GET_CONTEXT (ctx, FALSE);
if (object == NULL)
return FALSE;
return obj->klass->type == _cogl_handle_pixel_buffer_get_type ();
for (l = ctx->buffer_types; l; l = l->next)
if (GPOINTER_TO_INT (l->data) == obj->klass->type)
return TRUE;
return FALSE;
}
void