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:
* @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.
*
* 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,
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,
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,
CoglTextureFlags flags,
CoglPixelFormat format,
CoglPixelFormat internal_format,
guint rowstride,
@ -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,22 +142,23 @@ 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,
CoglTextureFlags flags,
CoglPixelFormat internal_format);
/**

View File

@ -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__ */

View File

@ -1192,7 +1192,7 @@ CoglHandle
cogl_texture_new_with_size (guint width,
guint height,
gint max_waste,
gboolean auto_mipmap,
CoglTextureFlags flags,
CoglPixelFormat internal_format)
{
CoglTexture *tex;
@ -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;
@ -1252,7 +1252,7 @@ CoglHandle
cogl_texture_new_from_data (guint width,
guint height,
gint max_waste,
gboolean auto_mipmap,
CoglTextureFlags flags,
CoglPixelFormat format,
CoglPixelFormat internal_format,
guint rowstride,
@ -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;
@ -1326,7 +1326,7 @@ cogl_texture_new_from_data (guint width,
CoglHandle
cogl_texture_new_from_bitmap (CoglBitmap *bmp,
gint max_waste,
gboolean auto_mipmap,
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;
@ -1386,7 +1386,7 @@ cogl_texture_new_from_bitmap (CoglBitmap *bmp,
CoglHandle
cogl_texture_new_from_file (const gchar *filename,
gint max_waste,
gboolean auto_mipmap,
CoglTextureFlags flags,
CoglPixelFormat internal_format,
GError **error)
{
@ -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);

View File

@ -1316,7 +1316,7 @@ CoglHandle
cogl_texture_new_with_size (guint width,
guint height,
gint max_waste,
gboolean auto_mipmap,
CoglTextureFlags flags,
CoglPixelFormat internal_format)
{
CoglTexture *tex;
@ -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;
@ -1376,7 +1376,7 @@ CoglHandle
cogl_texture_new_from_data (guint width,
guint height,
gint max_waste,
gboolean auto_mipmap,
CoglTextureFlags flags,
CoglPixelFormat format,
CoglPixelFormat internal_format,
guint rowstride,
@ -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;
@ -1450,7 +1450,7 @@ cogl_texture_new_from_data (guint width,
CoglHandle
cogl_texture_new_from_bitmap (CoglBitmap *bmp,
gint max_waste,
gboolean auto_mipmap,
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;
@ -1510,7 +1510,7 @@ cogl_texture_new_from_bitmap (CoglBitmap *bmp,
CoglHandle
cogl_texture_new_from_file (const gchar *filename,
gint max_waste,
gboolean auto_mipmap,
CoglTextureFlags flags,
CoglPixelFormat internal_format,
GError **error)
{
@ -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);