From 799fdf364e7f3b26f9bc27b7f16e052c38106016 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Sun, 18 Jan 2009 14:51:19 +0000 Subject: [PATCH] Change the COGL texture constructor to use flags Boolean arguments for functions are pretty evil and usually lead to combinatorial explosion of parameters in case multiple settings are added. In the case of the COGL texture constructors we have a boolean argument for enabling the auto-mipmapping; it is conceivable that we might want to add more settings for a COGL texture without breaking API or ABI compatibility, so the boolean argument should become a bitmask. The internals have not been changed: instead of checking for a non-zero value, we check for a bitmask being set. --- cogl-texture.h | 139 +++++++++++++++++++++++--------------------- cogl-types.h | 15 +++++ gl/cogl-texture.c | 52 ++++++++--------- gles/cogl-texture.c | 52 ++++++++--------- 4 files changed, 140 insertions(+), 118 deletions(-) diff --git a/cogl-texture.h b/cogl-texture.h index 5ae3e2839..893e167d7 100644 --- a/cogl-texture.h +++ b/cogl-texture.h @@ -41,73 +41,77 @@ G_BEGIN_DECLS * cogl_texture_new_with_size: * @width: width of texture in pixels. * @height: height of texture in pixels. - * @max_waste: maximum extra horizontal and|or vertical margin pixels to make - * texture fit GPU limitations. - * @auto_mipmap: enable or disable automatic generation of mipmap pyramid - * from the base level image whenever it is updated. + * @max_waste: maximum extra horizontal and|or vertical margin pixels + * to make the texture fit GPU limitations + * @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE * @internal_format: the #CoglPixelFormat to use for the GPU storage of the - * texture. + * texture. * - * Create a new texture with specified dimensions and pixel format. + * Creates a new COGL texture with the specified dimensions and pixel format. * - * Returns: a #CoglHandle to the newly created texture or COGL_INVALID_HANDLE - * if texture creation failed. + * Return value: a #CoglHandle to the newly created texture or + * %COGL_INVALID_HANDLE on failure + * + * Since: 0.8 */ -CoglHandle cogl_texture_new_with_size (guint width, - guint height, - gint max_waste, - gboolean auto_mipmap, - CoglPixelFormat internal_format); +CoglHandle cogl_texture_new_with_size (guint width, + guint height, + gint max_waste, + CoglTextureFlags flags, + CoglPixelFormat internal_format); /** * cogl_texture_new_from_file: * @filename: the file to load - * @max_waste: maximum extra horizontal and|or vertical margin pixels to make - * texture fit GPU limitations. - * @auto_mipmap: enable or disable automatic generation of mipmap pyramid - * from the base level image whenever it is updated. + * @max_waste: maximum extra horizontal and|or vertical margin pixels + * to make the texture fit GPU limitations + * @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE * @internal_format: the #CoglPixelFormat to use for the GPU storage of the - * texture. - * @error: a #GError or NULL. + * texture + * @error: return location for a #GError or %NULL * - * Load an image file from disk. + * Creates a COGL texture from an image file. * - * Returns: a #CoglHandle to the newly created texture or COGL_INVALID_HANDLE - * if creating the texture failed. + * Return value: a #CoglHandle to the newly created texture or + * %COGL_INVALID_HANDLE on failure + * + * Since: 0.8 */ -CoglHandle cogl_texture_new_from_file (const gchar *filename, - gint max_waste, - gboolean auto_mipmap, - CoglPixelFormat internal_format, - GError **error); +CoglHandle cogl_texture_new_from_file (const gchar *filename, + gint max_waste, + CoglTextureFlags flags, + CoglPixelFormat internal_format, + GError **error); /** * cogl_texture_new_from_data: - * @width: width of texture in pixels. - * @height: height of texture in pixels. - * @max_waste: maximum extra horizontal and|or vertical margin pixels to make - * @auto_mipmap: enable or disable automatic generation of mipmap pyramid - * from the base level image whenever it is updated. + * @width: width of texture in pixels + * @height: height of texture in pixels + * @max_waste: maximum extra horizontal and|or vertical margin pixels + * to make the texture fit GPU limitations + * @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE * @format: the #CoglPixelFormat the buffer is stored in in RAM - * @internal_format: the #CoglPixelFormat that will be used for storing the - * buffer on the GPU. - * @rowstride: the memory offset in bytes between the starts of scanlines in - * @data. - * @data: pointer the memory region where the source buffer resides. + * @internal_format: the #CoglPixelFormat that will be used for storing + * the buffer on the GPU + * @rowstride: the memory offset in bytes between the starts of + * scanlines in @data + * @data: pointer the memory region where the source buffer resides * - * Create a new cogl texture based on data residing in memory. + * Creates a new COGL texture based on data residing in memory. * - * Returns: a #CoglHandle to the newly created texture or COGL_INVALID_HANDLE - * if creating the texture failed. + * Return value: a #CoglHandle to the newly created texture or + * %COGL_INVALID_HANDLE on failure + * + * Since: 0.8 */ -CoglHandle cogl_texture_new_from_data (guint width, - guint height, - gint max_waste, - gboolean auto_mipmap, - CoglPixelFormat format, - CoglPixelFormat internal_format, - guint rowstride, - const guchar *data); +CoglHandle cogl_texture_new_from_data (guint width, + guint height, + gint max_waste, + CoglTextureFlags flags, + CoglPixelFormat format, + CoglPixelFormat internal_format, + guint rowstride, + const guchar *data); /** * cogl_texture_new_from_foreign: @@ -119,12 +123,14 @@ CoglHandle cogl_texture_new_from_data (guint width, * @y_pot_waste: maximum vertical waste. * @format: format of the foreign texture. * - * Create a cogl texture based on an existing OpenGL texture, the width, height - * and format are passed along since it is not possible to query this from a - * handle with GLES 1.0. + * Creates a COGL texture based on an existing OpenGL texture; the + * width, height and format are passed along since it is not possible + * to query this from a handle with GLES 1.0. * - * Returns: a #CoglHandle to the newly created texture or COGL_INVALID_HANDLE - * if creating the texture failed. + * Return value: a #CoglHandle to the newly created texture or + * %COGL_INVALID_HANDLE on failure + * + * Since: 0.8 */ CoglHandle cogl_texture_new_from_foreign (GLuint gl_handle, GLenum gl_target, @@ -136,23 +142,24 @@ CoglHandle cogl_texture_new_from_foreign (GLuint gl_handle, /** * cogl_texture_new_from_bitmap: - * @handle: handle of the preloaded texture. - * @max_waste: maximum extra horizontal and|or vertical margin pixels to make - * texture fit GPU limitations. - * @auto_mipmap: enable or disable automatic generation of mipmap pyramid - * from the base level image whenever it is updated. + * @handle: handle of the preloaded texture + * @max_waste: maximum extra horizontal and|or vertical margin pixels + * to make the texture fit GPU limitations + * @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE * @internal_format: the #CoglPixelFormat to use for the GPU storage of the - * texture. + * texture * - * Create a cogl texture from a #CoglBitmap. + * Creates a COGL texture from a #CoglBitmap. * - * Returns: a #CoglHandle to the newly created texture or COGL_INVALID_HANDLE - * if creating the texture failed. + * Return value: a #CoglHandle to the newly created texture or + * %COGL_INVALID_HANDLE on failure + * + * Since: 1.0 */ -CoglHandle cogl_texture_new_from_bitmap (CoglBitmap *bitmap, - gint max_waste, - gboolean auto_mipmap, - CoglPixelFormat internal_format); +CoglHandle cogl_texture_new_from_bitmap (CoglBitmap *bitmap, + gint max_waste, + CoglTextureFlags flags, + CoglPixelFormat internal_format); /** * cogl_is_texture: diff --git a/cogl-types.h b/cogl-types.h index b11091a95..74b912318 100644 --- a/cogl-types.h +++ b/cogl-types.h @@ -269,6 +269,21 @@ struct _CoglTextureVertex CoglColor color; }; +/** + * CoglTextureFlags: + * @COGL_TEXTURE_NONE: No flags specified + * @COGL_TEXTURE_AUTO_MIPMAP: Enables the automatic generation of the + * mipmap pyramid from the base level image whenever it is updated + * + * Flags to pass to the cogl_texture_new_* family of functions. + * + * Since: 1.0 + */ +typedef enum { + COGL_TEXTURE_NONE = 0, + COGL_TEXTURE_AUTO_MIPMAP = 1 << 0 +} CoglTextureFlags; + G_END_DECLS #endif /* __COGL_TYPES_H__ */ diff --git a/gl/cogl-texture.c b/gl/cogl-texture.c index 1dac0731c..84a0dfd16 100644 --- a/gl/cogl-texture.c +++ b/gl/cogl-texture.c @@ -1189,11 +1189,11 @@ _cogl_texture_free (CoglTexture *tex) } CoglHandle -cogl_texture_new_with_size (guint width, - guint height, - gint max_waste, - gboolean auto_mipmap, - CoglPixelFormat internal_format) +cogl_texture_new_with_size (guint width, + guint height, + gint max_waste, + CoglTextureFlags flags, + CoglPixelFormat internal_format) { CoglTexture *tex; gint bpp; @@ -1214,7 +1214,7 @@ cogl_texture_new_with_size (guint width, COGL_HANDLE_DEBUG_NEW (texture, tex); tex->is_foreign = FALSE; - tex->auto_mipmap = auto_mipmap; + tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0); tex->bitmap.width = width; tex->bitmap.height = height; @@ -1249,14 +1249,14 @@ cogl_texture_new_with_size (guint width, } CoglHandle -cogl_texture_new_from_data (guint width, - guint height, - gint max_waste, - gboolean auto_mipmap, - CoglPixelFormat format, - CoglPixelFormat internal_format, - guint rowstride, - const guchar *data) +cogl_texture_new_from_data (guint width, + guint height, + gint max_waste, + CoglTextureFlags flags, + CoglPixelFormat format, + CoglPixelFormat internal_format, + guint rowstride, + const guchar *data) { CoglTexture *tex; gint bpp; @@ -1278,7 +1278,7 @@ cogl_texture_new_from_data (guint width, COGL_HANDLE_DEBUG_NEW (texture, tex); tex->is_foreign = FALSE; - tex->auto_mipmap = auto_mipmap; + tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0); tex->bitmap.width = width; tex->bitmap.height = height; @@ -1324,10 +1324,10 @@ cogl_texture_new_from_data (guint width, } CoglHandle -cogl_texture_new_from_bitmap (CoglBitmap *bmp, - gint max_waste, - gboolean auto_mipmap, - CoglPixelFormat internal_format) +cogl_texture_new_from_bitmap (CoglBitmap *bmp, + gint max_waste, + CoglTextureFlags flags, + CoglPixelFormat internal_format) { CoglTexture *tex; @@ -1338,7 +1338,7 @@ cogl_texture_new_from_bitmap (CoglBitmap *bmp, COGL_HANDLE_DEBUG_NEW (texture, tex); tex->is_foreign = FALSE; - tex->auto_mipmap = auto_mipmap; + tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0); tex->bitmap = *bmp; tex->bitmap_owner = TRUE; @@ -1384,11 +1384,11 @@ cogl_texture_new_from_bitmap (CoglBitmap *bmp, } CoglHandle -cogl_texture_new_from_file (const gchar *filename, - gint max_waste, - gboolean auto_mipmap, - CoglPixelFormat internal_format, - GError **error) +cogl_texture_new_from_file (const gchar *filename, + gint max_waste, + CoglTextureFlags flags, + CoglPixelFormat internal_format, + GError **error) { CoglBitmap *bmp; CoglHandle handle; @@ -1400,7 +1400,7 @@ cogl_texture_new_from_file (const gchar *filename, handle = cogl_texture_new_from_bitmap (bmp, max_waste, - auto_mipmap, + flags, internal_format); cogl_bitmap_free (bmp); diff --git a/gles/cogl-texture.c b/gles/cogl-texture.c index deb7224bd..07ebb23a3 100644 --- a/gles/cogl-texture.c +++ b/gles/cogl-texture.c @@ -1313,11 +1313,11 @@ _cogl_texture_free (CoglTexture *tex) } CoglHandle -cogl_texture_new_with_size (guint width, - guint height, - gint max_waste, - gboolean auto_mipmap, - CoglPixelFormat internal_format) +cogl_texture_new_with_size (guint width, + guint height, + gint max_waste, + CoglTextureFlags flags, + CoglPixelFormat internal_format) { CoglTexture *tex; gint bpp; @@ -1338,7 +1338,7 @@ cogl_texture_new_with_size (guint width, COGL_HANDLE_DEBUG_NEW (texture, tex); tex->is_foreign = FALSE; - tex->auto_mipmap = auto_mipmap; + tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0); tex->bitmap.width = width; tex->bitmap.height = height; @@ -1373,14 +1373,14 @@ cogl_texture_new_with_size (guint width, } CoglHandle -cogl_texture_new_from_data (guint width, - guint height, - gint max_waste, - gboolean auto_mipmap, - CoglPixelFormat format, - CoglPixelFormat internal_format, - guint rowstride, - const guchar *data) +cogl_texture_new_from_data (guint width, + guint height, + gint max_waste, + CoglTextureFlags flags, + CoglPixelFormat format, + CoglPixelFormat internal_format, + guint rowstride, + const guchar *data) { CoglTexture *tex; gint bpp; @@ -1402,7 +1402,7 @@ cogl_texture_new_from_data (guint width, COGL_HANDLE_DEBUG_NEW (texture, tex); tex->is_foreign = FALSE; - tex->auto_mipmap = auto_mipmap; + tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0); tex->bitmap.width = width; tex->bitmap.height = height; @@ -1448,10 +1448,10 @@ cogl_texture_new_from_data (guint width, } CoglHandle -cogl_texture_new_from_bitmap (CoglBitmap *bmp, - gint max_waste, - gboolean auto_mipmap, - CoglPixelFormat internal_format) +cogl_texture_new_from_bitmap (CoglBitmap *bmp, + gint max_waste, + CoglTextureFlags flags, + CoglPixelFormat internal_format) { CoglTexture *tex; @@ -1462,7 +1462,7 @@ cogl_texture_new_from_bitmap (CoglBitmap *bmp, COGL_HANDLE_DEBUG_NEW (texture, tex); tex->is_foreign = FALSE; - tex->auto_mipmap = auto_mipmap; + tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0); tex->bitmap = *bmp; tex->bitmap_owner = TRUE; @@ -1508,11 +1508,11 @@ cogl_texture_new_from_bitmap (CoglBitmap *bmp, } CoglHandle -cogl_texture_new_from_file (const gchar *filename, - gint max_waste, - gboolean auto_mipmap, - CoglPixelFormat internal_format, - GError **error) +cogl_texture_new_from_file (const gchar *filename, + gint max_waste, + CoglTextureFlags flags, + CoglPixelFormat internal_format, + GError **error) { CoglBitmap *bmp; CoglHandle handle; @@ -1524,7 +1524,7 @@ cogl_texture_new_from_file (const gchar *filename, handle = cogl_texture_new_from_bitmap (bmp, max_waste, - auto_mipmap, + flags, internal_format); cogl_bitmap_free (bmp);