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.
This commit is contained in:
Emmanuele Bassi 2009-01-18 14:51:19 +00:00
parent de41fdd9d1
commit 799fdf364e
4 changed files with 140 additions and 118 deletions

View File

@ -41,69 +41,73 @@ G_BEGIN_DECLS
* cogl_texture_new_with_size: * cogl_texture_new_with_size:
* @width: width of texture in pixels. * @width: width of texture in pixels.
* @height: height of texture in pixels. * @height: height of texture in pixels.
* @max_waste: maximum extra horizontal and|or vertical margin pixels to make * @max_waste: maximum extra horizontal and|or vertical margin pixels
* texture fit GPU limitations. * to make the texture fit GPU limitations
* @auto_mipmap: enable or disable automatic generation of mipmap pyramid * @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE
* from the base level image whenever it is updated.
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the * @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 * Return value: a #CoglHandle to the newly created texture or
* if texture creation failed. * %COGL_INVALID_HANDLE on failure
*
* Since: 0.8
*/ */
CoglHandle cogl_texture_new_with_size (guint width, CoglHandle cogl_texture_new_with_size (guint width,
guint height, guint height,
gint max_waste, gint max_waste,
gboolean auto_mipmap, CoglTextureFlags flags,
CoglPixelFormat internal_format); CoglPixelFormat internal_format);
/** /**
* cogl_texture_new_from_file: * cogl_texture_new_from_file:
* @filename: the file to load * @filename: the file to load
* @max_waste: maximum extra horizontal and|or vertical margin pixels to make * @max_waste: maximum extra horizontal and|or vertical margin pixels
* texture fit GPU limitations. * to make the texture fit GPU limitations
* @auto_mipmap: enable or disable automatic generation of mipmap pyramid * @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE
* from the base level image whenever it is updated.
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the * @internal_format: the #CoglPixelFormat to use for the GPU storage of the
* texture. * texture
* @error: a #GError or NULL. * @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 * Return value: a #CoglHandle to the newly created texture or
* if creating the texture failed. * %COGL_INVALID_HANDLE on failure
*
* Since: 0.8
*/ */
CoglHandle cogl_texture_new_from_file (const gchar *filename, CoglHandle cogl_texture_new_from_file (const gchar *filename,
gint max_waste, gint max_waste,
gboolean auto_mipmap, CoglTextureFlags flags,
CoglPixelFormat internal_format, CoglPixelFormat internal_format,
GError **error); GError **error);
/** /**
* cogl_texture_new_from_data: * cogl_texture_new_from_data:
* @width: width of texture in pixels. * @width: width of texture in pixels
* @height: height of texture in pixels. * @height: height of texture in pixels
* @max_waste: maximum extra horizontal and|or vertical margin pixels to make * @max_waste: maximum extra horizontal and|or vertical margin pixels
* @auto_mipmap: enable or disable automatic generation of mipmap pyramid * to make the texture fit GPU limitations
* from the base level image whenever it is updated. * @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE
* @format: the #CoglPixelFormat the buffer is stored in in RAM * @format: the #CoglPixelFormat the buffer is stored in in RAM
* @internal_format: the #CoglPixelFormat that will be used for storing the * @internal_format: the #CoglPixelFormat that will be used for storing
* buffer on the GPU. * the buffer on the GPU
* @rowstride: the memory offset in bytes between the starts of scanlines in * @rowstride: the memory offset in bytes between the starts of
* @data. * scanlines in @data
* @data: pointer the memory region where the source buffer resides. * @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 * Return value: a #CoglHandle to the newly created texture or
* if creating the texture failed. * %COGL_INVALID_HANDLE on failure
*
* Since: 0.8
*/ */
CoglHandle cogl_texture_new_from_data (guint width, CoglHandle cogl_texture_new_from_data (guint width,
guint height, guint height,
gint max_waste, gint max_waste,
gboolean auto_mipmap, CoglTextureFlags flags,
CoglPixelFormat format, CoglPixelFormat format,
CoglPixelFormat internal_format, CoglPixelFormat internal_format,
guint rowstride, guint rowstride,
@ -119,12 +123,14 @@ CoglHandle cogl_texture_new_from_data (guint width,
* @y_pot_waste: maximum vertical waste. * @y_pot_waste: maximum vertical waste.
* @format: format of the foreign texture. * @format: format of the foreign texture.
* *
* Create a cogl texture based on an existing OpenGL texture, the width, height * Creates a COGL texture based on an existing OpenGL texture; the
* and format are passed along since it is not possible to query this from a * width, height and format are passed along since it is not possible
* handle with GLES 1.0. * to query this from a handle with GLES 1.0.
* *
* Returns: a #CoglHandle to the newly created texture or COGL_INVALID_HANDLE * Return value: a #CoglHandle to the newly created texture or
* if creating the texture failed. * %COGL_INVALID_HANDLE on failure
*
* Since: 0.8
*/ */
CoglHandle cogl_texture_new_from_foreign (GLuint gl_handle, CoglHandle cogl_texture_new_from_foreign (GLuint gl_handle,
GLenum gl_target, GLenum gl_target,
@ -136,22 +142,23 @@ CoglHandle cogl_texture_new_from_foreign (GLuint gl_handle,
/** /**
* cogl_texture_new_from_bitmap: * cogl_texture_new_from_bitmap:
* @handle: handle of the preloaded texture. * @handle: handle of the preloaded texture
* @max_waste: maximum extra horizontal and|or vertical margin pixels to make * @max_waste: maximum extra horizontal and|or vertical margin pixels
* texture fit GPU limitations. * to make the texture fit GPU limitations
* @auto_mipmap: enable or disable automatic generation of mipmap pyramid * @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE
* from the base level image whenever it is updated.
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the * @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 * Return value: a #CoglHandle to the newly created texture or
* if creating the texture failed. * %COGL_INVALID_HANDLE on failure
*
* Since: 1.0
*/ */
CoglHandle cogl_texture_new_from_bitmap (CoglBitmap *bitmap, CoglHandle cogl_texture_new_from_bitmap (CoglBitmap *bitmap,
gint max_waste, gint max_waste,
gboolean auto_mipmap, CoglTextureFlags flags,
CoglPixelFormat internal_format); CoglPixelFormat internal_format);
/** /**

View File

@ -269,6 +269,21 @@ struct _CoglTextureVertex
CoglColor color; 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 G_END_DECLS
#endif /* __COGL_TYPES_H__ */ #endif /* __COGL_TYPES_H__ */

View File

@ -1192,7 +1192,7 @@ CoglHandle
cogl_texture_new_with_size (guint width, cogl_texture_new_with_size (guint width,
guint height, guint height,
gint max_waste, gint max_waste,
gboolean auto_mipmap, CoglTextureFlags flags,
CoglPixelFormat internal_format) CoglPixelFormat internal_format)
{ {
CoglTexture *tex; CoglTexture *tex;
@ -1214,7 +1214,7 @@ cogl_texture_new_with_size (guint width,
COGL_HANDLE_DEBUG_NEW (texture, tex); COGL_HANDLE_DEBUG_NEW (texture, tex);
tex->is_foreign = FALSE; tex->is_foreign = FALSE;
tex->auto_mipmap = auto_mipmap; tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0);
tex->bitmap.width = width; tex->bitmap.width = width;
tex->bitmap.height = height; tex->bitmap.height = height;
@ -1252,7 +1252,7 @@ CoglHandle
cogl_texture_new_from_data (guint width, cogl_texture_new_from_data (guint width,
guint height, guint height,
gint max_waste, gint max_waste,
gboolean auto_mipmap, CoglTextureFlags flags,
CoglPixelFormat format, CoglPixelFormat format,
CoglPixelFormat internal_format, CoglPixelFormat internal_format,
guint rowstride, guint rowstride,
@ -1278,7 +1278,7 @@ cogl_texture_new_from_data (guint width,
COGL_HANDLE_DEBUG_NEW (texture, tex); COGL_HANDLE_DEBUG_NEW (texture, tex);
tex->is_foreign = FALSE; tex->is_foreign = FALSE;
tex->auto_mipmap = auto_mipmap; tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0);
tex->bitmap.width = width; tex->bitmap.width = width;
tex->bitmap.height = height; tex->bitmap.height = height;
@ -1326,7 +1326,7 @@ cogl_texture_new_from_data (guint width,
CoglHandle CoglHandle
cogl_texture_new_from_bitmap (CoglBitmap *bmp, cogl_texture_new_from_bitmap (CoglBitmap *bmp,
gint max_waste, gint max_waste,
gboolean auto_mipmap, CoglTextureFlags flags,
CoglPixelFormat internal_format) CoglPixelFormat internal_format)
{ {
CoglTexture *tex; CoglTexture *tex;
@ -1338,7 +1338,7 @@ cogl_texture_new_from_bitmap (CoglBitmap *bmp,
COGL_HANDLE_DEBUG_NEW (texture, tex); COGL_HANDLE_DEBUG_NEW (texture, tex);
tex->is_foreign = FALSE; tex->is_foreign = FALSE;
tex->auto_mipmap = auto_mipmap; tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0);
tex->bitmap = *bmp; tex->bitmap = *bmp;
tex->bitmap_owner = TRUE; tex->bitmap_owner = TRUE;
@ -1386,7 +1386,7 @@ cogl_texture_new_from_bitmap (CoglBitmap *bmp,
CoglHandle CoglHandle
cogl_texture_new_from_file (const gchar *filename, cogl_texture_new_from_file (const gchar *filename,
gint max_waste, gint max_waste,
gboolean auto_mipmap, CoglTextureFlags flags,
CoglPixelFormat internal_format, CoglPixelFormat internal_format,
GError **error) GError **error)
{ {
@ -1400,7 +1400,7 @@ cogl_texture_new_from_file (const gchar *filename,
handle = cogl_texture_new_from_bitmap (bmp, handle = cogl_texture_new_from_bitmap (bmp,
max_waste, max_waste,
auto_mipmap, flags,
internal_format); internal_format);
cogl_bitmap_free (bmp); cogl_bitmap_free (bmp);

View File

@ -1316,7 +1316,7 @@ CoglHandle
cogl_texture_new_with_size (guint width, cogl_texture_new_with_size (guint width,
guint height, guint height,
gint max_waste, gint max_waste,
gboolean auto_mipmap, CoglTextureFlags flags,
CoglPixelFormat internal_format) CoglPixelFormat internal_format)
{ {
CoglTexture *tex; CoglTexture *tex;
@ -1338,7 +1338,7 @@ cogl_texture_new_with_size (guint width,
COGL_HANDLE_DEBUG_NEW (texture, tex); COGL_HANDLE_DEBUG_NEW (texture, tex);
tex->is_foreign = FALSE; tex->is_foreign = FALSE;
tex->auto_mipmap = auto_mipmap; tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0);
tex->bitmap.width = width; tex->bitmap.width = width;
tex->bitmap.height = height; tex->bitmap.height = height;
@ -1376,7 +1376,7 @@ CoglHandle
cogl_texture_new_from_data (guint width, cogl_texture_new_from_data (guint width,
guint height, guint height,
gint max_waste, gint max_waste,
gboolean auto_mipmap, CoglTextureFlags flags,
CoglPixelFormat format, CoglPixelFormat format,
CoglPixelFormat internal_format, CoglPixelFormat internal_format,
guint rowstride, guint rowstride,
@ -1402,7 +1402,7 @@ cogl_texture_new_from_data (guint width,
COGL_HANDLE_DEBUG_NEW (texture, tex); COGL_HANDLE_DEBUG_NEW (texture, tex);
tex->is_foreign = FALSE; tex->is_foreign = FALSE;
tex->auto_mipmap = auto_mipmap; tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0);
tex->bitmap.width = width; tex->bitmap.width = width;
tex->bitmap.height = height; tex->bitmap.height = height;
@ -1450,7 +1450,7 @@ cogl_texture_new_from_data (guint width,
CoglHandle CoglHandle
cogl_texture_new_from_bitmap (CoglBitmap *bmp, cogl_texture_new_from_bitmap (CoglBitmap *bmp,
gint max_waste, gint max_waste,
gboolean auto_mipmap, CoglTextureFlags flags,
CoglPixelFormat internal_format) CoglPixelFormat internal_format)
{ {
CoglTexture *tex; CoglTexture *tex;
@ -1462,7 +1462,7 @@ cogl_texture_new_from_bitmap (CoglBitmap *bmp,
COGL_HANDLE_DEBUG_NEW (texture, tex); COGL_HANDLE_DEBUG_NEW (texture, tex);
tex->is_foreign = FALSE; tex->is_foreign = FALSE;
tex->auto_mipmap = auto_mipmap; tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0);
tex->bitmap = *bmp; tex->bitmap = *bmp;
tex->bitmap_owner = TRUE; tex->bitmap_owner = TRUE;
@ -1510,7 +1510,7 @@ cogl_texture_new_from_bitmap (CoglBitmap *bmp,
CoglHandle CoglHandle
cogl_texture_new_from_file (const gchar *filename, cogl_texture_new_from_file (const gchar *filename,
gint max_waste, gint max_waste,
gboolean auto_mipmap, CoglTextureFlags flags,
CoglPixelFormat internal_format, CoglPixelFormat internal_format,
GError **error) GError **error)
{ {
@ -1524,7 +1524,7 @@ cogl_texture_new_from_file (const gchar *filename,
handle = cogl_texture_new_from_bitmap (bmp, handle = cogl_texture_new_from_bitmap (bmp,
max_waste, max_waste,
auto_mipmap, flags,
internal_format); internal_format);
cogl_bitmap_free (bmp); cogl_bitmap_free (bmp);