mirror of
https://github.com/brl/mutter.git
synced 2024-12-23 19:42:05 +00:00
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:
parent
5ea8c5bd12
commit
87240cd764
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user