cogl-texture: List texture subclass types rather than hardcoding them
Instead of having a hardcoded series of if-statements in cogl_is_texture to determine which types should appear as texture subclasses, they are now stored in a GSList attached to the Cogl context. The list is amended to using a new cogl_texture_register_type function. There is a convenience macro called COGL_TEXTURE_DEFINE which uses COGL_HANDLE_DEFINE_WITH_CODE to register the texture type when the _get_type() function is first called.
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user