From 8012eee31f01011d4b6572d924d7a979470c4afe Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Thu, 9 Feb 2012 11:19:04 +0000 Subject: [PATCH] Add _cogl_texture_get_type() This adds an internal function to get the type of the underlying hardware texture for any CoglTexture. It can return one of three values to represent 2D textures, 3D textures or rectangle textures. The idea is that this can be used as a replacement for cogl_texture_get_gl_texture when only the target is required to make it a bit less GL-centric. The implementation adds a new virtual function which all of the texture backends now implement. The enum is in a public header because a later patch will want to use it from the CoglPipeline API. We may want to consider making the function public too later. Reviewed-by: Robert Bragg --- cogl/cogl-atlas-texture.c | 7 +++++++ cogl/cogl-sub-texture.c | 9 +++++++++ cogl/cogl-texture-2d-sliced.c | 7 +++++++ cogl/cogl-texture-2d.c | 7 +++++++ cogl/cogl-texture-3d.c | 7 +++++++ cogl/cogl-texture-private.h | 14 ++++++++++++++ cogl/cogl-texture-rectangle.c | 7 +++++++ cogl/cogl-texture.c | 6 ++++++ cogl/cogl-texture.h | 18 ++++++++++++++++++ cogl/winsys/cogl-texture-pixmap-x11.c | 13 +++++++++++++ .../cogl-2.0-experimental-sections.txt | 1 + 11 files changed, 96 insertions(+) diff --git a/cogl/cogl-atlas-texture.c b/cogl/cogl-atlas-texture.c index e3ecf80a3..06aed4af4 100644 --- a/cogl/cogl-atlas-texture.c +++ b/cogl/cogl-atlas-texture.c @@ -809,6 +809,12 @@ _cogl_atlas_texture_remove_reorganize_callback (GHookFunc callback, g_hook_destroy_link (&ctx->atlas_reorganize_callbacks, hook); } +static CoglTextureType +_cogl_atlas_texture_get_type (CoglTexture *tex) +{ + return COGL_TEXTURE_TYPE_2D; +} + static const CoglTextureVtable cogl_atlas_texture_vtable = { @@ -829,5 +835,6 @@ cogl_atlas_texture_vtable = _cogl_atlas_texture_get_gl_format, _cogl_atlas_texture_get_width, _cogl_atlas_texture_get_height, + _cogl_atlas_texture_get_type, NULL /* is_foreign */ }; diff --git a/cogl/cogl-sub-texture.c b/cogl/cogl-sub-texture.c index 3967ecd68..99ecfcc53 100644 --- a/cogl/cogl-sub-texture.c +++ b/cogl/cogl-sub-texture.c @@ -416,6 +416,14 @@ _cogl_sub_texture_get_height (CoglTexture *tex) return sub_tex->sub_height; } +static CoglTextureType +_cogl_sub_texture_get_type (CoglTexture *tex) +{ + CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex); + + return _cogl_texture_get_type (sub_tex->full_texture); +} + static const CoglTextureVtable cogl_sub_texture_vtable = { @@ -436,5 +444,6 @@ cogl_sub_texture_vtable = _cogl_sub_texture_get_gl_format, _cogl_sub_texture_get_width, _cogl_sub_texture_get_height, + _cogl_sub_texture_get_type, NULL /* is_foreign */ }; diff --git a/cogl/cogl-texture-2d-sliced.c b/cogl/cogl-texture-2d-sliced.c index 03d3299cb..7220bf24c 100644 --- a/cogl/cogl-texture-2d-sliced.c +++ b/cogl/cogl-texture-2d-sliced.c @@ -1293,6 +1293,12 @@ _cogl_texture_2d_sliced_get_height (CoglTexture *tex) return COGL_TEXTURE_2D_SLICED (tex)->height; } +static CoglTextureType +_cogl_texture_2d_sliced_get_type (CoglTexture *tex) +{ + return COGL_TEXTURE_TYPE_2D; +} + static const CoglTextureVtable cogl_texture_2d_sliced_vtable = { @@ -1313,5 +1319,6 @@ cogl_texture_2d_sliced_vtable = _cogl_texture_2d_sliced_get_gl_format, _cogl_texture_2d_sliced_get_width, _cogl_texture_2d_sliced_get_height, + _cogl_texture_2d_sliced_get_type, _cogl_texture_2d_sliced_is_foreign }; diff --git a/cogl/cogl-texture-2d.c b/cogl/cogl-texture-2d.c index 794f18641..89bf63dad 100644 --- a/cogl/cogl-texture-2d.c +++ b/cogl/cogl-texture-2d.c @@ -859,6 +859,12 @@ _cogl_texture_2d_is_foreign (CoglTexture *tex) return COGL_TEXTURE_2D (tex)->is_foreign; } +static CoglTextureType +_cogl_texture_2d_get_type (CoglTexture *tex) +{ + return COGL_TEXTURE_TYPE_2D; +} + static const CoglTextureVtable cogl_texture_2d_vtable = { @@ -879,5 +885,6 @@ cogl_texture_2d_vtable = _cogl_texture_2d_get_gl_format, _cogl_texture_2d_get_width, _cogl_texture_2d_get_height, + _cogl_texture_2d_get_type, _cogl_texture_2d_is_foreign }; diff --git a/cogl/cogl-texture-3d.c b/cogl/cogl-texture-3d.c index d6e36dd4c..f332b68f3 100644 --- a/cogl/cogl-texture-3d.c +++ b/cogl/cogl-texture-3d.c @@ -592,6 +592,12 @@ _cogl_texture_3d_get_height (CoglTexture *tex) return COGL_TEXTURE_3D (tex)->height; } +static CoglTextureType +_cogl_texture_3d_get_type (CoglTexture *tex) +{ + return COGL_TEXTURE_TYPE_3D; +} + static const CoglTextureVtable cogl_texture_3d_vtable = { @@ -612,5 +618,6 @@ cogl_texture_3d_vtable = _cogl_texture_3d_get_gl_format, _cogl_texture_3d_get_width, _cogl_texture_3d_get_height, + _cogl_texture_3d_get_type, NULL /* is_foreign */ }; diff --git a/cogl/cogl-texture-private.h b/cogl/cogl-texture-private.h index 1048b210f..2f7d9251d 100644 --- a/cogl/cogl-texture-private.h +++ b/cogl/cogl-texture-private.h @@ -121,6 +121,8 @@ struct _CoglTextureVtable int (* get_width) (CoglTexture *tex); int (* get_height) (CoglTexture *tex); + CoglTextureType (* get_type) (CoglTexture *tex); + gboolean (* is_foreign) (CoglTexture *tex); }; @@ -274,4 +276,16 @@ _cogl_texture_spans_foreach_in_region (CoglSpan *x_spans, CoglMetaTextureCallback callback, void *user_data); +/* + * _cogl_texture_get_type: + * @texture: a #CoglTexture pointer + * + * Retrieves the texture type of the underlying hardware texture that + * this #CoglTexture will use. + * + * Return value: The type of the hardware texture. + */ +CoglTextureType +_cogl_texture_get_type (CoglTexture *texture); + #endif /* __COGL_TEXTURE_PRIVATE_H */ diff --git a/cogl/cogl-texture-rectangle.c b/cogl/cogl-texture-rectangle.c index c43779b27..556b718ef 100644 --- a/cogl/cogl-texture-rectangle.c +++ b/cogl/cogl-texture-rectangle.c @@ -579,6 +579,12 @@ _cogl_texture_rectangle_is_foreign (CoglTexture *tex) return COGL_TEXTURE_RECTANGLE (tex)->is_foreign; } +static CoglTextureType +_cogl_texture_rectangle_get_type (CoglTexture *tex) +{ + return COGL_TEXTURE_TYPE_RECTANGLE; +} + static const CoglTextureVtable cogl_texture_rectangle_vtable = { @@ -599,5 +605,6 @@ cogl_texture_rectangle_vtable = _cogl_texture_rectangle_get_gl_format, _cogl_texture_rectangle_get_width, _cogl_texture_rectangle_get_height, + _cogl_texture_rectangle_get_type, _cogl_texture_rectangle_is_foreign }; diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c index d957a9448..6f6f96303 100644 --- a/cogl/cogl-texture.c +++ b/cogl/cogl-texture.c @@ -643,6 +643,12 @@ cogl_texture_get_gl_texture (CoglTexture *texture, out_gl_handle, out_gl_target); } +CoglTextureType +_cogl_texture_get_type (CoglTexture *texture) +{ + return texture->vtable->get_type (texture); +} + void _cogl_texture_set_filters (CoglTexture *texture, GLenum min_filter, diff --git a/cogl/cogl-texture.h b/cogl/cogl-texture.h index 6fedfb25a..36fde2a21 100644 --- a/cogl/cogl-texture.h +++ b/cogl/cogl-texture.h @@ -78,6 +78,24 @@ typedef enum { COGL_TEXTURE_ERROR_TYPE } CoglTextureError; +/** + * CoglTextureType: + * @COGL_TEXTURE_TYPE_2D: A #CoglTexture2D + * @COGL_TEXTURE_TYPE_3D: A #CoglTexture3D + * @COGL_TEXTURE_TYPE_RECTANGLE: A #CoglTextureRectangle + * + * Constants representing the underlying hardware texture type of a + * #CoglTexture. + * + * Stability: unstable + * Since: 1.10 + */ +typedef enum { + COGL_TEXTURE_TYPE_2D, + COGL_TEXTURE_TYPE_3D, + COGL_TEXTURE_TYPE_RECTANGLE +} CoglTextureType; + GQuark cogl_texture_error_quark (void); /** diff --git a/cogl/winsys/cogl-texture-pixmap-x11.c b/cogl/winsys/cogl-texture-pixmap-x11.c index 33d74ba33..1b1a1b42e 100644 --- a/cogl/winsys/cogl-texture-pixmap-x11.c +++ b/cogl/winsys/cogl-texture-pixmap-x11.c @@ -998,6 +998,18 @@ _cogl_texture_pixmap_x11_get_height (CoglTexture *tex) return tex_pixmap->height; } +static CoglTextureType +_cogl_texture_pixmap_x11_get_type (CoglTexture *tex) +{ + CoglTexturePixmapX11 *tex_pixmap = COGL_TEXTURE_PIXMAP_X11 (tex); + CoglTexture *child_tex; + + child_tex = _cogl_texture_pixmap_x11_get_texture (tex_pixmap); + + /* Forward on to the child texture */ + return _cogl_texture_get_type (child_tex); +} + static void _cogl_texture_pixmap_x11_free (CoglTexturePixmapX11 *tex_pixmap) { @@ -1049,5 +1061,6 @@ cogl_texture_pixmap_x11_vtable = _cogl_texture_pixmap_x11_get_gl_format, _cogl_texture_pixmap_x11_get_width, _cogl_texture_pixmap_x11_get_height, + _cogl_texture_pixmap_x11_get_type, NULL /* is_foreign */ }; diff --git a/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt b/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt index 36f491937..2c2b561f7 100644 --- a/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt +++ b/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt @@ -318,6 +318,7 @@ cogl_texture_get_format cogl_texture_is_sliced cogl_texture_get_data cogl_texture_set_region +CoglTextureType COGL_TEXTURE_MAX_WASTE