diff --git a/clutter/cogl/cogl/cogl-atlas-texture.c b/clutter/cogl/cogl/cogl-atlas-texture.c index cf09a6490..5f2d1b373 100644 --- a/clutter/cogl/cogl/cogl-atlas-texture.c +++ b/clutter/cogl/cogl/cogl-atlas-texture.c @@ -72,7 +72,7 @@ static void _cogl_atlas_texture_free (CoglAtlasTexture *sub_tex); -COGL_HANDLE_DEFINE (AtlasTexture, atlas_texture); +COGL_TEXTURE_DEFINE (AtlasTexture, atlas_texture); static const CoglTextureVtable cogl_atlas_texture_vtable; diff --git a/clutter/cogl/cogl/cogl-context.c b/clutter/cogl/cogl/cogl-context.c index 83453f905..2933ed7d7 100644 --- a/clutter/cogl/cogl/cogl-context.c +++ b/clutter/cogl/cogl/cogl-context.c @@ -65,6 +65,8 @@ cogl_create_context (void) _context->feature_flags_private = 0; _context->features_cached = FALSE; + _context->texture_types = NULL; + /* Initialise the driver specific state */ /* TODO: combine these two into one function */ _cogl_create_context_driver (_context); @@ -251,6 +253,8 @@ _cogl_destroy_context (void) _cogl_bitmask_destroy (&_context->temp_bitmask); _cogl_bitmask_destroy (&_context->texcoord_arrays_to_disable); + g_slist_free (_context->texture_types); + g_free (_context); } diff --git a/clutter/cogl/cogl/cogl-context.h b/clutter/cogl/cogl/cogl-context.h index a56f465de..1ed1499d9 100644 --- a/clutter/cogl/cogl/cogl-context.h +++ b/clutter/cogl/cogl/cogl-context.h @@ -162,6 +162,10 @@ typedef struct CoglMaterialProgramType current_use_program_type; GLuint current_gl_program; + /* List of types that will be considered a subclass of CoglTexture in + cogl_is_texture */ + GSList *texture_types; + CoglContextDriver drv; } CoglContext; diff --git a/clutter/cogl/cogl/cogl-sub-texture.c b/clutter/cogl/cogl/cogl-sub-texture.c index 22a1c8869..fd6346d9a 100644 --- a/clutter/cogl/cogl/cogl-sub-texture.c +++ b/clutter/cogl/cogl/cogl-sub-texture.c @@ -42,7 +42,7 @@ static void _cogl_sub_texture_free (CoglSubTexture *sub_tex); -COGL_HANDLE_DEFINE (SubTexture, sub_texture); +COGL_TEXTURE_DEFINE (SubTexture, sub_texture); static const CoglTextureVtable cogl_sub_texture_vtable; diff --git a/clutter/cogl/cogl/cogl-texture-2d-sliced.c b/clutter/cogl/cogl/cogl-texture-2d-sliced.c index e1e3cf42c..9049db5d8 100644 --- a/clutter/cogl/cogl/cogl-texture-2d-sliced.c +++ b/clutter/cogl/cogl/cogl-texture-2d-sliced.c @@ -50,7 +50,7 @@ static void _cogl_texture_2d_sliced_free (CoglTexture2DSliced *tex_2ds); -COGL_HANDLE_DEFINE (Texture2DSliced, texture_2d_sliced); +COGL_TEXTURE_DEFINE (Texture2DSliced, texture_2d_sliced); static const CoglTextureVtable cogl_texture_2d_sliced_vtable; diff --git a/clutter/cogl/cogl/cogl-texture-2d.c b/clutter/cogl/cogl/cogl-texture-2d.c index 3c33a7557..b3296419e 100644 --- a/clutter/cogl/cogl/cogl-texture-2d.c +++ b/clutter/cogl/cogl/cogl-texture-2d.c @@ -44,7 +44,7 @@ static void _cogl_texture_2d_free (CoglTexture2D *tex_2d); -COGL_HANDLE_DEFINE (Texture2D, texture_2d); +COGL_TEXTURE_DEFINE (Texture2D, texture_2d); static const CoglTextureVtable cogl_texture_2d_vtable; diff --git a/clutter/cogl/cogl/cogl-texture-private.h b/clutter/cogl/cogl/cogl-texture-private.h index 74ffe033f..a8b4cc079 100644 --- a/clutter/cogl/cogl/cogl-texture-private.h +++ b/clutter/cogl/cogl/cogl-texture-private.h @@ -142,6 +142,17 @@ typedef enum _CoglTextureChangeFlags void _cogl_texture_free (CoglTexture *texture); +/* This is used to register a type to the list of handle types that + will be considered a texture in cogl_is_texture() */ +void +_cogl_texture_register_texture_type (GQuark type); + +#define COGL_TEXTURE_DEFINE(TypeName, type_name) \ + COGL_HANDLE_DEFINE_WITH_CODE \ + (TypeName, type_name, \ + _cogl_texture_register_texture_type (_cogl_handle_ \ + ## type_name ## _get_type ())) + void _cogl_texture_foreach_sub_texture_in_region (CoglHandle handle, float virtual_tx_1, diff --git a/clutter/cogl/cogl/cogl-texture.c b/clutter/cogl/cogl/cogl-texture.c index 1dbcbbf4e..64f7c54eb 100644 --- a/clutter/cogl/cogl/cogl-texture.c +++ b/clutter/cogl/cogl/cogl-texture.c @@ -59,18 +59,31 @@ * abstract class manually. */ +void +_cogl_texture_register_texture_type (GQuark type) +{ + _COGL_GET_CONTEXT (ctxt, NO_RETVAL); + + ctxt->texture_types = g_slist_prepend (ctxt->texture_types, + GINT_TO_POINTER (type)); +} + gboolean cogl_is_texture (CoglHandle handle) { CoglHandleObject *obj = (CoglHandleObject *)handle; + GSList *l; + + _COGL_GET_CONTEXT (ctxt, FALSE); if (handle == COGL_INVALID_HANDLE) return FALSE; - return (obj->klass->type == _cogl_handle_texture_2d_get_type () || - obj->klass->type == _cogl_handle_atlas_texture_get_type () || - obj->klass->type == _cogl_handle_texture_2d_sliced_get_type () || - obj->klass->type == _cogl_handle_sub_texture_get_type ()); + for (l = ctxt->texture_types; l; l = l->next) + if (GPOINTER_TO_INT (l->data) == obj->klass->type) + return TRUE; + + return FALSE; } CoglHandle