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 8736db6aed
commit c9739e6aef
6 changed files with 204 additions and 155 deletions

View File

@ -258,18 +258,25 @@ clutter_texture_realize (ClutterActor *actor)
if (priv->fbo_source)
{
CoglTextureFlags flags = COGL_TEXTURE_NONE;
gint max_waste = -1;
/* Handle FBO's */
if (priv->texture != COGL_INVALID_HANDLE)
cogl_texture_unref (priv->texture);
if (!priv->no_slice)
max_waste = priv->max_tile_waste;
if (priv->filter_quality == CLUTTER_TEXTURE_QUALITY_HIGH)
flags |= COGL_TEXTURE_AUTO_MIPMAP;
priv->texture =
cogl_texture_new_with_size
(priv->width,
priv->height,
priv->no_slice ? -1 : priv->max_tile_waste,
priv->filter_quality == CLUTTER_TEXTURE_QUALITY_HIGH,
COGL_PIXEL_FORMAT_RGBA_8888);
cogl_texture_new_with_size (priv->width,
priv->height,
max_waste, flags,
COGL_PIXEL_FORMAT_RGBA_8888);
cogl_texture_set_filters (priv->texture,
clutter_texture_quality_to_cogl_min_filter (priv->filter_quality),
@ -1241,19 +1248,25 @@ clutter_texture_set_from_data (ClutterTexture *texture,
gint bpp,
GError **error)
{
CoglHandle new_texture;
ClutterTexturePrivate *priv;
ClutterTexturePrivate *priv = texture->priv;
CoglHandle new_texture = COGL_INVALID_HANDLE;
CoglTextureFlags flags = COGL_TEXTURE_NONE;
gint max_waste = -1;
priv = texture->priv;
if (!priv->no_slice)
max_waste = priv->max_tile_waste;
if ((new_texture = cogl_texture_new_from_data
(width, height,
priv->no_slice ? -1 : priv->max_tile_waste,
priv->filter_quality == CLUTTER_TEXTURE_QUALITY_HIGH,
source_format,
COGL_PIXEL_FORMAT_ANY,
rowstride,
data)) == COGL_INVALID_HANDLE)
if (priv->filter_quality == CLUTTER_TEXTURE_QUALITY_HIGH)
flags |= COGL_TEXTURE_AUTO_MIPMAP;
new_texture = cogl_texture_new_from_data (width, height,
max_waste, flags,
source_format,
COGL_PIXEL_FORMAT_ANY,
rowstride,
data);
if (G_UNLIKELY (new_texture == COGL_INVALID_HANDLE))
{
g_set_error (error, CLUTTER_TEXTURE_ERROR,
CLUTTER_TEXTURE_ERROR_BAD_FORMAT,
@ -1420,7 +1433,7 @@ clutter_texture_async_load_complete (ClutterTexture *self,
{
ClutterTexturePrivate *priv = self->priv;
CoglHandle handle;
gboolean enable_mipmap = FALSE;
CoglTextureFlags flags = COGL_TEXTURE_NONE;
gint waste = -1;
if (error == NULL)
@ -1429,11 +1442,11 @@ clutter_texture_async_load_complete (ClutterTexture *self,
waste = priv->max_tile_waste;
if (priv->filter_quality == CLUTTER_TEXTURE_QUALITY_HIGH)
enable_mipmap = TRUE;
flags != COGL_TEXTURE_AUTO_MIPMAP;
handle = cogl_texture_new_from_bitmap (priv->load_bitmap,
waste, enable_mipmap,
COGL_PIXEL_FORMAT_ANY);
waste, flags,
COGL_PIXEL_FORMAT_ANY);
clutter_texture_set_cogl_texture (self, handle);
cogl_texture_unref (handle);
@ -1614,7 +1627,7 @@ clutter_texture_set_from_file (ClutterTexture *texture,
ClutterTexturePrivate *priv;
CoglHandle new_texture = COGL_INVALID_HANDLE;
GError *internal_error = NULL;
gboolean enable_mipmap = FALSE;
CoglTextureFlags flags = COGL_TEXTURE_NONE;
gint max_waste = -1;
priv = texture->priv;
@ -1634,10 +1647,10 @@ clutter_texture_set_from_file (ClutterTexture *texture,
max_waste = priv->max_tile_waste;
if (priv->filter_quality == CLUTTER_TEXTURE_QUALITY_HIGH)
enable_mipmap = TRUE;
flags |= COGL_TEXTURE_AUTO_MIPMAP;
new_texture = cogl_texture_new_from_file (filename,
max_waste, enable_mipmap,
max_waste, flags,
COGL_PIXEL_FORMAT_ANY,
&internal_error);
if (new_texture == COGL_INVALID_HANDLE)
@ -2000,18 +2013,23 @@ on_fbo_source_size_change (GObject *object,
if (w != priv->width || h != priv->height)
{
CoglTextureFlags flags = COGL_TEXTURE_NONE;
/* tear down the FBO */
cogl_offscreen_unref (priv->fbo_handle);
texture_free_gl_resources (texture);
priv->width = w;
priv->height = h;
priv->width = w;
priv->height = h;
if (priv->filter_quality == CLUTTER_TEXTURE_QUALITY_HIGH)
flags |= COGL_TEXTURE_AUTO_MIPMAP;
priv->texture = cogl_texture_new_with_size (MAX (priv->width, 1),
MAX (priv->height, 1),
-1,
priv->filter_quality == CLUTTER_TEXTURE_QUALITY_HIGH,
flags,
COGL_PIXEL_FORMAT_RGBA_8888);
cogl_texture_set_filters (priv->texture,

View File

@ -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:

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

@ -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);

View File

@ -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);

View File

@ -272,6 +272,7 @@ cogl_pango_glyph_cache_set (CoglPangoGlyphCache *cache,
texture = texture->next);
if (texture == NULL)
{
CoglTextureFlags flags = COGL_TEXTURE_NONE;
guchar *clear_data;
/* Allocate a new texture that is the nearest power of two
@ -280,19 +281,27 @@ cogl_pango_glyph_cache_set (CoglPangoGlyphCache *cache,
texture = g_slice_new (CoglPangoGlyphCacheTexture);
texture->texture_size = MIN_TEXTURE_SIZE;
while (texture->texture_size < band_height
|| texture->texture_size < width)
texture->texture_size *= 2;
while (texture->texture_size < band_height ||
texture->texture_size < width)
{
texture->texture_size *= 2;
}
/* Allocate an empty buffer to clear the texture */
clear_data = g_malloc0 (texture->texture_size
* texture->texture_size);
clear_data =
g_malloc0 (texture->texture_size * texture->texture_size);
texture->texture = cogl_texture_new_from_data
(texture->texture_size, texture->texture_size,
32, cache->use_mipmapping,
COGL_PIXEL_FORMAT_A_8, COGL_PIXEL_FORMAT_A_8,
texture->texture_size, clear_data);
if (cache->use_mipmapping)
flags |= COGL_TEXTURE_AUTO_MIPMAP;
texture->texture =
cogl_texture_new_from_data (texture->texture_size,
texture->texture_size,
32, flags,
COGL_PIXEL_FORMAT_A_8,
COGL_PIXEL_FORMAT_A_8,
texture->texture_size,
clear_data);
g_free (clear_data);