diff --git a/clutter/clutter-texture.c b/clutter/clutter-texture.c index 55d3fda24..2321f6304 100644 --- a/clutter/clutter-texture.c +++ b/clutter/clutter-texture.c @@ -79,7 +79,6 @@ struct _ClutterTexturePrivate { gfloat width; gfloat height; - gint max_tile_waste; ClutterTextureQuality filter_quality; CoglHandle material; gboolean no_slice; @@ -136,7 +135,7 @@ enum PROP_0, PROP_NO_SLICE, PROP_MAX_TILE_WASTE, - PROP_PIXEL_FORMAT, /* Texture format */ + PROP_PIXEL_FORMAT, PROP_SYNC_SIZE, PROP_REPEAT_Y, PROP_REPEAT_X, @@ -287,20 +286,19 @@ clutter_texture_realize (ClutterActor *actor) { CoglTextureFlags flags = COGL_TEXTURE_NONE; gint min_filter, mag_filter; - gint max_waste = -1; CoglHandle tex; /* Handle FBO's */ - if (!priv->no_slice) - max_waste = priv->max_tile_waste; + if (priv->no_slice) + flags |= COGL_TEXTURE_NO_SLICING; if (priv->filter_quality == CLUTTER_TEXTURE_QUALITY_HIGH) flags |= COGL_TEXTURE_AUTO_MIPMAP; tex = cogl_texture_new_with_size (priv->width, priv->height, - max_waste, flags, + flags, COGL_PIXEL_FORMAT_RGBA_8888); cogl_material_set_layer (priv->material, 0, tex); @@ -775,10 +773,6 @@ clutter_texture_set_property (GObject *object, switch (prop_id) { - case PROP_MAX_TILE_WASTE: - clutter_texture_set_max_tile_waste (texture, g_value_get_int (value)); - break; - case PROP_SYNC_SIZE: clutter_texture_set_sync_size (texture, g_value_get_boolean (value)); break; @@ -860,14 +854,14 @@ clutter_texture_get_property (GObject *object, switch (prop_id) { - case PROP_MAX_TILE_WASTE: - g_value_set_int (value, clutter_texture_get_max_tile_waste (texture)); - break; - case PROP_PIXEL_FORMAT: g_value_set_enum (value, clutter_texture_get_pixel_format (texture)); break; + case PROP_MAX_TILE_WASTE: + g_value_set_int (value, clutter_texture_get_max_tile_waste (texture)); + break; + case PROP_SYNC_SIZE: g_value_set_boolean (value, priv->sync_actor_size); break; @@ -946,6 +940,14 @@ clutter_texture_class_init (ClutterTextureClass *klass) FALSE, G_PARAM_CONSTRUCT_ONLY | CLUTTER_PARAM_READWRITE)); + g_object_class_install_property + (gobject_class, PROP_MAX_TILE_WASTE, + g_param_spec_int ("tile-waste", + "Tile Waste", + "Maximum waste area of a sliced texture", + -1, G_MAXINT, + COGL_TEXTURE_MAX_WASTE, + CLUTTER_PARAM_READABLE)); g_object_class_install_property (gobject_class, PROP_REPEAT_X, @@ -974,19 +976,6 @@ clutter_texture_class_init (ClutterTextureClass *klass) CLUTTER_TEXTURE_QUALITY_MEDIUM, G_PARAM_CONSTRUCT | CLUTTER_PARAM_READWRITE)); - g_object_class_install_property - (gobject_class, PROP_MAX_TILE_WASTE, - g_param_spec_int ("tile-waste", - "Tile dimension to waste", - "Max wastage dimension of a texture when using " - "sliced textures or -1 to disable slicing. " - "Bigger values use less textures, " - "smaller values less texture memory.", - -1, - G_MAXINT, - 63, - G_PARAM_CONSTRUCT_ONLY | CLUTTER_PARAM_READWRITE)); - g_object_class_install_property (gobject_class, PROP_PIXEL_FORMAT, g_param_spec_enum ("pixel-format", @@ -1199,7 +1188,6 @@ clutter_texture_init (ClutterTexture *self) self->priv = priv = CLUTTER_TEXTURE_GET_PRIVATE (self); - priv->max_tile_waste = 63; priv->filter_quality = CLUTTER_TEXTURE_QUALITY_MEDIUM; priv->repeat_x = FALSE; priv->repeat_y = FALSE; @@ -1240,10 +1228,9 @@ clutter_texture_save_to_local_data (ClutterTexture *texture) /* Align to 4 bytes */ priv->local_data_rowstride = (priv->local_data_width * bpp + 3) & ~3; - /* Store the filter quality and max_tile_waste from the texture - properties so that they will be restored the data is loaded - again */ - priv->max_tile_waste = clutter_texture_get_max_tile_waste (texture); + /* Store the filter quality from the texture properties so that + * they will be restored the data is loaded again + */ priv->filter_quality = clutter_texture_get_filter_quality (texture); priv->local_data = g_malloc (priv->local_data_rowstride @@ -1478,10 +1465,9 @@ clutter_texture_set_from_data (ClutterTexture *texture, CoglHandle new_texture = COGL_INVALID_HANDLE; CoglTextureFlags flags = COGL_TEXTURE_NONE; gint min_filter, mag_filter; - gint max_waste = -1; - if (!priv->no_slice) - max_waste = priv->max_tile_waste; + if (priv->no_slice) + flags |= COGL_TEXTURE_NO_SLICING; if (priv->filter_quality == CLUTTER_TEXTURE_QUALITY_HIGH) flags |= COGL_TEXTURE_AUTO_MIPMAP; @@ -1491,7 +1477,7 @@ clutter_texture_set_from_data (ClutterTexture *texture, */ new_texture = cogl_texture_new_from_data (width, height, - max_waste, flags, + flags, source_format, COGL_PIXEL_FORMAT_ANY, rowstride, @@ -1669,20 +1655,19 @@ clutter_texture_async_load_complete (ClutterTexture *self, ClutterTexturePrivate *priv = self->priv; CoglHandle handle; CoglTextureFlags flags = COGL_TEXTURE_NONE; - gint waste = -1; priv->async_data = NULL; if (error == NULL) { - if (!priv->no_slice) - waste = priv->max_tile_waste; + if (priv->no_slice) + flags |= COGL_TEXTURE_NO_SLICING; if (priv->filter_quality == CLUTTER_TEXTURE_QUALITY_HIGH) flags |= COGL_TEXTURE_AUTO_MIPMAP; handle = cogl_texture_new_from_bitmap (bitmap, - waste, flags, + flags, COGL_PIXEL_FORMAT_ANY); clutter_texture_set_cogl_texture (self, handle); if (priv->load_size_async) @@ -1915,7 +1900,6 @@ clutter_texture_set_from_file (ClutterTexture *texture, GError *internal_error = NULL; CoglTextureFlags flags = COGL_TEXTURE_NONE; gint min_filter, mag_filter; - gint max_waste = -1; priv = texture->priv; @@ -1924,14 +1908,14 @@ clutter_texture_set_from_file (ClutterTexture *texture, if (priv->load_data_async) return clutter_texture_async_load (texture, filename, error); - if (!priv->no_slice) - max_waste = priv->max_tile_waste; + if (priv->no_slice) + flags |= COGL_TEXTURE_NO_SLICING; if (priv->filter_quality == CLUTTER_TEXTURE_QUALITY_HIGH) flags |= COGL_TEXTURE_AUTO_MIPMAP; new_texture = cogl_texture_new_from_file (filename, - max_waste, flags, + flags, COGL_PIXEL_FORMAT_ANY, &internal_error); if (new_texture == COGL_INVALID_HANDLE) @@ -2047,40 +2031,6 @@ clutter_texture_get_filter_quality (ClutterTexture *texture) return priv->filter_quality; } -/** - * clutter_texture_set_max_tile_waste - * @texture: A #ClutterTexture - * @max_tile_waste: Maximum amount of waste in pixels or -1 - * - * Sets the maximum number of pixels in either axis that can be wasted - * for an individual texture slice. If -1 is specified then the - * texture is forced not to be sliced and the texture creation will - * fail if the hardware can't create a texture large enough. - * - * The value is only used when first creating a texture so changing it - * after the texture data has been set has no effect. - * - * Since: 0.8 - */ -void -clutter_texture_set_max_tile_waste (ClutterTexture *texture, - gint max_tile_waste) -{ - ClutterTexturePrivate *priv; - CoglHandle cogl_texture; - - g_return_if_fail (CLUTTER_IS_TEXTURE (texture)); - - priv = texture->priv; - cogl_texture = clutter_texture_get_cogl_texture (texture); - - /* There's no point in changing the max_tile_waste if the texture - has already been created because it will be overridden with the - value from the texture handle */ - if (cogl_texture == COGL_INVALID_HANDLE) - priv->max_tile_waste = max_tile_waste; -} - /** * clutter_texture_get_max_tile_waste * @texture: A #ClutterTexture @@ -2089,7 +2039,7 @@ clutter_texture_set_max_tile_waste (ClutterTexture *texture, * -1 if slicing is disabled. * * Return value: The maximum waste or -1 if the texture waste is - * unlimited. + * unlimited. * * Since: 0.8 */ @@ -2102,13 +2052,12 @@ clutter_texture_get_max_tile_waste (ClutterTexture *texture) g_return_val_if_fail (CLUTTER_IS_TEXTURE (texture), 0); priv = texture->priv; + cogl_texture = clutter_texture_get_cogl_texture (texture); if (cogl_texture == COGL_INVALID_HANDLE) - return texture->priv->max_tile_waste; + return priv->no_slice ? -1 : COGL_TEXTURE_MAX_WASTE; else - /* If we have a valid texture handle then use the value from that - instead */ return cogl_texture_get_max_waste (cogl_texture); } @@ -2312,12 +2261,13 @@ on_fbo_source_size_change (GObject *object, priv->width = w; priv->height = h; + flags |= COGL_TEXTURE_NO_SLICING; + if (priv->filter_quality == CLUTTER_TEXTURE_QUALITY_HIGH) flags |= COGL_TEXTURE_AUTO_MIPMAP; tex = cogl_texture_new_with_size (MAX (priv->width, 1), MAX (priv->height, 1), - -1, flags, COGL_PIXEL_FORMAT_RGBA_8888); diff --git a/clutter/clutter-texture.h b/clutter/clutter-texture.h index 1049910f1..40f84e81a 100644 --- a/clutter/clutter-texture.h +++ b/clutter/clutter-texture.h @@ -202,9 +202,6 @@ void clutter_texture_get_base_size (ClutterTexture void clutter_texture_set_filter_quality (ClutterTexture *texture, ClutterTextureQuality filter_quality); ClutterTextureQuality clutter_texture_get_filter_quality (ClutterTexture *texture); -void clutter_texture_set_max_tile_waste (ClutterTexture *texture, - gint max_tile_waste); -gint clutter_texture_get_max_tile_waste (ClutterTexture *texture); CoglHandle clutter_texture_get_cogl_texture (ClutterTexture *texture); void clutter_texture_set_cogl_texture (ClutterTexture *texture, CoglHandle cogl_tex); @@ -221,6 +218,7 @@ void clutter_texture_get_repeat (ClutterTexture gboolean *repeat_x, gboolean *repeat_y); CoglPixelFormat clutter_texture_get_pixel_format (ClutterTexture *texture); +gint clutter_texture_get_max_tile_waste (ClutterTexture *texture); void clutter_texture_set_keep_aspect_ratio (ClutterTexture *texture, gboolean keep_aspect); gboolean clutter_texture_get_keep_aspect_ratio (ClutterTexture *texture); diff --git a/clutter/cogl/cogl-texture.h b/clutter/cogl/cogl-texture.h index 6a8b00a01..d4cc4e812 100644 --- a/clutter/cogl/cogl-texture.h +++ b/clutter/cogl/cogl-texture.h @@ -41,12 +41,12 @@ G_BEGIN_DECLS * loading and manipulating textures. */ +#define COGL_TEXTURE_MAX_WASTE 127 + /** * 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 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. @@ -60,15 +60,12 @@ G_BEGIN_DECLS */ 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 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 @@ -82,7 +79,6 @@ CoglHandle cogl_texture_new_with_size (guint width, * Since: 0.8 */ CoglHandle cogl_texture_new_from_file (const gchar *filename, - gint max_waste, CoglTextureFlags flags, CoglPixelFormat internal_format, GError **error); @@ -91,8 +87,6 @@ CoglHandle cogl_texture_new_from_file (const gchar *filename, * 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 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 @@ -110,7 +104,6 @@ CoglHandle cogl_texture_new_from_file (const gchar *filename, */ CoglHandle cogl_texture_new_from_data (guint width, guint height, - gint max_waste, CoglTextureFlags flags, CoglPixelFormat format, CoglPixelFormat internal_format, @@ -136,19 +129,17 @@ CoglHandle cogl_texture_new_from_data (guint width, * * Since: 0.8 */ -CoglHandle cogl_texture_new_from_foreign (GLuint gl_handle, - GLenum gl_target, - GLuint width, - GLuint height, - GLuint x_pot_waste, - GLuint y_pot_waste, - CoglPixelFormat format); +CoglHandle cogl_texture_new_from_foreign (GLuint gl_handle, + GLenum gl_target, + GLuint width, + GLuint height, + GLuint x_pot_waste, + GLuint y_pot_waste, + CoglPixelFormat format); /** * cogl_texture_new_from_bitmap: * @bmp_handle: A CoglBitmap handle - * @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 @@ -160,10 +151,9 @@ CoglHandle cogl_texture_new_from_foreign (GLuint gl_handle, * * Since: 1.0 */ -CoglHandle cogl_texture_new_from_bitmap (CoglHandle bmp_handle, - gint max_waste, - CoglTextureFlags flags, - CoglPixelFormat internal_format); +CoglHandle cogl_texture_new_from_bitmap (CoglHandle bmp_handle, + CoglTextureFlags flags, + CoglPixelFormat internal_format); /** * cogl_is_texture: diff --git a/clutter/cogl/cogl-types.h b/clutter/cogl/cogl-types.h index a4ecd4193..719ecd087 100644 --- a/clutter/cogl/cogl-types.h +++ b/clutter/cogl/cogl-types.h @@ -292,6 +292,7 @@ struct _CoglTextureVertex * @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 + * @COGL_TEXTURE_NO_SLICING: Disables the slicing of the texture * * Flags to pass to the cogl_texture_new_* family of functions. * @@ -299,7 +300,8 @@ struct _CoglTextureVertex */ typedef enum { COGL_TEXTURE_NONE = 0, - COGL_TEXTURE_AUTO_MIPMAP = 1 << 0 + COGL_TEXTURE_AUTO_MIPMAP = 1 << 0, + COGL_TEXTURE_NO_SLICING = 1 << 1 } CoglTextureFlags; #define COGL_TYPE_TEXTURE_FLAGS (cogl_texture_flags_get_type ()) diff --git a/clutter/cogl/common/cogl-util.c b/clutter/cogl/common/cogl-util.c index d71b9ffd8..2b9ccba27 100644 --- a/clutter/cogl/common/cogl-util.c +++ b/clutter/cogl/common/cogl-util.c @@ -223,6 +223,7 @@ cogl_texture_flags_get_type (void) static const GFlagsValue values[] = { { COGL_TEXTURE_NONE, "COGL_TEXTURE_NONE", "none" }, { COGL_TEXTURE_AUTO_MIPMAP, "COGL_TEXTURE_AUTO_MIPMAP", "auto-mipmap" }, + { COGL_TEXTURE_NO_SLICING, "COGL_TEXTURE_NO_SLICING", "no-slicing" }, { 0, NULL, NULL } }; diff --git a/clutter/cogl/gl/cogl-context.c b/clutter/cogl/gl/cogl-context.c index 986da8aa8..2c17408c2 100644 --- a/clutter/cogl/gl/cogl-context.c +++ b/clutter/cogl/gl/cogl-context.c @@ -146,8 +146,7 @@ cogl_create_context () _context->default_gl_texture_2d_tex = cogl_texture_new_from_data (1, /* width */ 1, /* height */ - -1, /* max waste */ - COGL_TEXTURE_NONE, /* flags */ + COGL_TEXTURE_NO_SLICING, COGL_PIXEL_FORMAT_RGBA_8888, /* data format */ /* internal format */ COGL_PIXEL_FORMAT_RGBA_8888, @@ -156,8 +155,7 @@ cogl_create_context () _context->default_gl_texture_rect_tex = cogl_texture_new_from_data (1, /* width */ 1, /* height */ - -1, /* max waste */ - COGL_TEXTURE_NONE, /* flags */ + COGL_TEXTURE_NO_SLICING, COGL_PIXEL_FORMAT_RGBA_8888, /* data format */ /* internal format */ COGL_PIXEL_FORMAT_RGBA_8888, diff --git a/clutter/cogl/gl/cogl-texture.c b/clutter/cogl/gl/cogl-texture.c index ce2ee11ed..80e428eba 100644 --- a/clutter/cogl/gl/cogl-texture.c +++ b/clutter/cogl/gl/cogl-texture.c @@ -644,10 +644,10 @@ _cogl_texture_upload_subregion_to_gl (CoglTexture *tex, } static gint -_cogl_rect_slices_for_size (gint size_to_fill, - gint max_span_size, - gint max_waste, - GArray *out_spans) +_cogl_rect_slices_for_size (gint size_to_fill, + gint max_span_size, + gint max_waste, + GArray *out_spans) { gint n_spans = 0; CoglTexSliceSpan span; @@ -679,10 +679,10 @@ _cogl_rect_slices_for_size (gint size_to_fill, } static gint -_cogl_pot_slices_for_size (gint size_to_fill, - gint max_span_size, - gint max_waste, - GArray *out_spans) +_cogl_pot_slices_for_size (gint size_to_fill, + gint max_span_size, + gint max_waste, + GArray *out_spans) { gint n_spans = 0; CoglTexSliceSpan span; @@ -693,7 +693,8 @@ _cogl_pot_slices_for_size (gint size_to_fill, span.waste = 0; /* Fix invalid max_waste */ - if (max_waste < 0) max_waste = 0; + if (max_waste < 0) + max_waste = 0; while (TRUE) { @@ -826,10 +827,10 @@ _cogl_texture_slices_create (CoglTexture *tex) /* Check if size supported else bail out */ if (!_cogl_texture_size_supported (tex->gl_target, - tex->gl_format, - tex->gl_type, - max_width, - max_height)) + tex->gl_format, + tex->gl_type, + max_width, + max_height)) { return FALSE; } @@ -1199,11 +1200,10 @@ _cogl_texture_free (CoglTexture *tex) } CoglHandle -cogl_texture_new_with_size (guint width, - guint height, - gint max_waste, - CoglTextureFlags flags, - CoglPixelFormat internal_format) +cogl_texture_new_with_size (guint width, + guint height, + CoglTextureFlags flags, + CoglPixelFormat internal_format) { CoglTexture *tex; gint bpp; @@ -1234,7 +1234,11 @@ cogl_texture_new_with_size (guint width, tex->slice_y_spans = NULL; tex->slice_gl_handles = NULL; - tex->max_waste = max_waste; + if (flags & COGL_TEXTURE_NO_SLICING) + tex->max_waste = -1; + else + tex->max_waste = COGL_TEXTURE_MAX_WASTE; + tex->min_filter = COGL_TEXTURE_FILTER_NEAREST; tex->mag_filter = COGL_TEXTURE_FILTER_NEAREST; @@ -1258,7 +1262,6 @@ cogl_texture_new_with_size (guint width, CoglHandle cogl_texture_new_from_data (guint width, guint height, - gint max_waste, CoglTextureFlags flags, CoglPixelFormat format, CoglPixelFormat internal_format, @@ -1295,7 +1298,11 @@ cogl_texture_new_from_data (guint width, tex->slice_y_spans = NULL; tex->slice_gl_handles = NULL; - tex->max_waste = max_waste; + if (flags & COGL_TEXTURE_NO_SLICING) + tex->max_waste = -1; + else + tex->max_waste = COGL_TEXTURE_MAX_WASTE; + tex->min_filter = COGL_TEXTURE_FILTER_NEAREST; tex->mag_filter = COGL_TEXTURE_FILTER_NEAREST; @@ -1328,10 +1335,9 @@ cogl_texture_new_from_data (guint width, } CoglHandle -cogl_texture_new_from_bitmap (CoglHandle bmp_handle, - gint max_waste, - CoglTextureFlags flags, - CoglPixelFormat internal_format) +cogl_texture_new_from_bitmap (CoglHandle bmp_handle, + CoglTextureFlags flags, + CoglPixelFormat internal_format) { CoglTexture *tex; CoglBitmap *bmp = (CoglBitmap *)bmp_handle; @@ -1352,7 +1358,11 @@ cogl_texture_new_from_bitmap (CoglHandle bmp_handle, tex->slice_y_spans = NULL; tex->slice_gl_handles = NULL; - tex->max_waste = max_waste; + if (flags & COGL_TEXTURE_NO_SLICING) + tex->max_waste = -1; + else + tex->max_waste = COGL_TEXTURE_MAX_WASTE; + tex->min_filter = COGL_TEXTURE_FILTER_NEAREST; tex->mag_filter = COGL_TEXTURE_FILTER_NEAREST; @@ -1389,13 +1399,12 @@ cogl_texture_new_from_bitmap (CoglHandle bmp_handle, CoglHandle cogl_texture_new_from_file (const gchar *filename, - gint max_waste, CoglTextureFlags flags, CoglPixelFormat internal_format, GError **error) { - CoglHandle bmp; - CoglHandle handle; + CoglHandle bmp; + CoglHandle handle; g_return_val_if_fail (error == NULL || *error == NULL, COGL_INVALID_HANDLE); @@ -1403,10 +1412,7 @@ cogl_texture_new_from_file (const gchar *filename, if (bmp == COGL_INVALID_HANDLE) return COGL_INVALID_HANDLE; - handle = cogl_texture_new_from_bitmap (bmp, - max_waste, - flags, - internal_format); + handle = cogl_texture_new_from_bitmap (bmp, flags, internal_format); cogl_handle_unref (bmp); return handle; @@ -1509,14 +1515,11 @@ cogl_texture_new_from_foreign (GLuint gl_handle, return COGL_INVALID_HANDLE; /* Try and match to a cogl format */ - if (!_cogl_pixel_format_from_gl_internal (gl_int_format, - &format)) - { - return COGL_INVALID_HANDLE; - } + if (!_cogl_pixel_format_from_gl_internal (gl_int_format, &format)) + return COGL_INVALID_HANDLE; /* Create new texture */ - tex = (CoglTexture*) g_malloc ( sizeof (CoglTexture)); + tex = (CoglTexture *) g_malloc (sizeof (CoglTexture)); /* Setup bitmap info */ tex->is_foreign = TRUE; diff --git a/clutter/cogl/gles/cogl-context.c b/clutter/cogl/gles/cogl-context.c index d70d59d35..f187c0b88 100644 --- a/clutter/cogl/gles/cogl-context.c +++ b/clutter/cogl/gles/cogl-context.c @@ -107,8 +107,7 @@ cogl_create_context () _context->default_gl_texture_2d_tex = cogl_texture_new_from_data (1, /* width */ 1, /* height */ - -1, /* max waste */ - COGL_TEXTURE_NONE, /* flags */ + COGL_TEXTURE_NO_SLICING, /* flags */ COGL_PIXEL_FORMAT_RGBA_8888, /* data format */ /* internal format */ COGL_PIXEL_FORMAT_RGBA_8888, @@ -117,8 +116,7 @@ cogl_create_context () _context->default_gl_texture_rect_tex = cogl_texture_new_from_data (1, /* width */ 1, /* height */ - -1, /* max waste */ - COGL_TEXTURE_NONE, /* flags */ + COGL_TEXTURE_NO_SLICING, /* flags */ COGL_PIXEL_FORMAT_RGBA_8888, /* data format */ /* internal format */ COGL_PIXEL_FORMAT_RGBA_8888, diff --git a/clutter/cogl/gles/cogl-texture.c b/clutter/cogl/gles/cogl-texture.c index 1564faf2a..8f4cf733e 100644 --- a/clutter/cogl/gles/cogl-texture.c +++ b/clutter/cogl/gles/cogl-texture.c @@ -858,7 +858,8 @@ _cogl_pot_slices_for_size (gint size_to_fill, span.waste = 0; /* Fix invalid max_waste */ - if (max_waste < 0) max_waste = 0; + if (max_waste < 0) + max_waste = 0; while (TRUE) { @@ -866,7 +867,9 @@ _cogl_pot_slices_for_size (gint size_to_fill, if (size_to_fill > span.size) { /* Not yet - add a span of this size */ - if (out_spans) g_array_append_val (out_spans, span); + if (out_spans) + g_array_append_val (out_spans, span); + span.start += span.size; size_to_fill -= span.size; n_spans++; @@ -875,7 +878,9 @@ _cogl_pot_slices_for_size (gint size_to_fill, { /* Yes and waste is small enough */ span.waste = span.size - size_to_fill; - if (out_spans) g_array_append_val (out_spans, span); + if (out_spans) + g_array_append_val (out_spans, span); + return ++n_spans; } else @@ -971,10 +976,10 @@ _cogl_texture_slices_create (CoglTexture *tex) /* Check if size supported else bail out */ if (!_cogl_texture_size_supported (tex->gl_target, - tex->gl_format, - tex->gl_type, - max_width, - max_height)) + tex->gl_format, + tex->gl_type, + max_width, + max_height)) { return FALSE; } @@ -1288,11 +1293,10 @@ _cogl_texture_free (CoglTexture *tex) } CoglHandle -cogl_texture_new_with_size (guint width, - guint height, - gint max_waste, - CoglTextureFlags flags, - CoglPixelFormat internal_format) +cogl_texture_new_with_size (guint width, + guint height, + CoglTextureFlags flags, + CoglPixelFormat internal_format) { CoglTexture *tex; gint bpp; @@ -1323,7 +1327,11 @@ cogl_texture_new_with_size (guint width, tex->slice_y_spans = NULL; tex->slice_gl_handles = NULL; - tex->max_waste = max_waste; + if (flags & COGL_TEXTURE_NO_SLICING) + tex->max_waste = -1; + else + tex->max_waste = COGL_TEXTURE_MAX_WASTE; + tex->min_filter = CGL_NEAREST; tex->mag_filter = CGL_NEAREST; @@ -1347,7 +1355,6 @@ cogl_texture_new_with_size (guint width, CoglHandle cogl_texture_new_from_data (guint width, guint height, - gint max_waste, CoglTextureFlags flags, CoglPixelFormat format, CoglPixelFormat internal_format, @@ -1384,7 +1391,11 @@ cogl_texture_new_from_data (guint width, tex->slice_y_spans = NULL; tex->slice_gl_handles = NULL; - tex->max_waste = max_waste; + if (flags & COGL_TEXTURE_NO_SLICING) + tex->max_waste = -1; + else + tex->max_waste = COGL_TEXTURE_MAX_WASTE; + tex->min_filter = CGL_NEAREST; tex->mag_filter = CGL_NEAREST; @@ -1417,10 +1428,9 @@ cogl_texture_new_from_data (guint width, } CoglHandle -cogl_texture_new_from_bitmap (CoglHandle bmp_handle, - gint max_waste, - CoglTextureFlags flags, - CoglPixelFormat internal_format) +cogl_texture_new_from_bitmap (CoglHandle bmp_handle, + CoglTextureFlags flags, + CoglPixelFormat internal_format) { CoglTexture *tex; CoglBitmap *bmp = (CoglBitmap *)bmp_handle; @@ -1439,7 +1449,11 @@ cogl_texture_new_from_bitmap (CoglHandle bmp_handle, tex->slice_y_spans = NULL; tex->slice_gl_handles = NULL; - tex->max_waste = max_waste; + if (flags & COGL_TEXTURE_NO_SLICING) + tex->max_waste = -1; + else + tex->max_waste = COGL_TEXTURE_MAX_WASTE; + tex->min_filter = CGL_NEAREST; tex->mag_filter = CGL_NEAREST; @@ -1476,7 +1490,6 @@ cogl_texture_new_from_bitmap (CoglHandle bmp_handle, CoglHandle cogl_texture_new_from_file (const gchar *filename, - gint max_waste, CoglTextureFlags flags, CoglPixelFormat internal_format, GError **error) @@ -1490,10 +1503,7 @@ cogl_texture_new_from_file (const gchar *filename, if (bmp == COGL_INVALID_HANDLE) return COGL_INVALID_HANDLE; - handle = cogl_texture_new_from_bitmap (bmp, - max_waste, - flags, - internal_format); + handle = cogl_texture_new_from_bitmap (bmp, flags, internal_format); cogl_handle_unref (bmp); return handle; diff --git a/clutter/glx/clutter-glx-texture-pixmap.c b/clutter/glx/clutter-glx-texture-pixmap.c index c1a02206e..3c8393df6 100644 --- a/clutter/glx/clutter-glx-texture-pixmap.c +++ b/clutter/glx/clutter-glx-texture-pixmap.c @@ -360,7 +360,7 @@ create_cogl_texture (ClutterTexture *texture, { handle = cogl_texture_new_with_size (width, height, - -1, FALSE, + COGL_TEXTURE_NO_SLICING, cogl_format | COGL_BGR_BIT); using_rectangle = FALSE; diff --git a/clutter/pango/cogl-pango-glyph-cache.c b/clutter/pango/cogl-pango-glyph-cache.c index 892255623..9be1e83b8 100644 --- a/clutter/pango/cogl-pango-glyph-cache.c +++ b/clutter/pango/cogl-pango-glyph-cache.c @@ -297,7 +297,7 @@ cogl_pango_glyph_cache_set (CoglPangoGlyphCache *cache, texture->texture = cogl_texture_new_from_data (texture->texture_size, texture->texture_size, - 32, flags, + flags, COGL_PIXEL_FORMAT_A_8, COGL_PIXEL_FORMAT_A_8, texture->texture_size, diff --git a/tests/conform/test-backface-culling.c b/tests/conform/test-backface-culling.c index 034dcb70a..00f36bfba 100644 --- a/tests/conform/test-backface-culling.c +++ b/tests/conform/test-backface-culling.c @@ -11,20 +11,23 @@ static const ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff }; /* Size the texture so that it is just off a power of two to enourage it so use software tiling when NPOTs aren't available */ -#define TEXTURE_SIZE 33 +#define TEXTURE_SIZE 257 #else /* CLUTTER_COGL_HAS_GL */ /* We can't use the funny-sized texture on GL ES because it will break cogl_texture_polygon. However there is only one code path for rendering quads so there is no need */ -#define TEXTURE_SIZE 32 +#define TEXTURE_SIZE 32 #endif /* CLUTTER_COGL_HAS_GL */ /* Amount of pixels to skip off the top, bottom, left and right of the texture when reading back the stage */ -#define TEST_INSET 4 +#define TEST_INSET 4 + +/* Size to actually render the texture at */ +#define TEXTURE_RENDER_SIZE 32 typedef struct _TestState { @@ -42,15 +45,15 @@ validate_part (int xnum, int ynum, gboolean shown) /* Read the appropriate part but skip out a few pixels around the edges */ pixels = clutter_stage_read_pixels (CLUTTER_STAGE (stage), - xnum * TEXTURE_SIZE + TEST_INSET, - ynum * TEXTURE_SIZE + TEST_INSET, - TEXTURE_SIZE - TEST_INSET * 2, - TEXTURE_SIZE - TEST_INSET * 2); + xnum * TEXTURE_RENDER_SIZE + TEST_INSET, + ynum * TEXTURE_RENDER_SIZE + TEST_INSET, + TEXTURE_RENDER_SIZE - TEST_INSET * 2, + TEXTURE_RENDER_SIZE - TEST_INSET * 2); /* Make sure every pixels is the appropriate color */ for (p = pixels; - p < pixels + ((TEXTURE_SIZE - TEST_INSET * 2) - * (TEXTURE_SIZE - TEST_INSET * 2)); + p < pixels + ((TEXTURE_RENDER_SIZE - TEST_INSET * 2) + * (TEXTURE_RENDER_SIZE - TEST_INSET * 2)); p += 4) { if (p[0] != (shown ? 255 : 0)) @@ -114,7 +117,7 @@ on_paint (ClutterActor *actor, TestState *state) the first */ for (i = 0; i < 2; i++) { - float x1 = 0, x2, y1 = 0, y2 = (float)(TEXTURE_SIZE); + float x1 = 0, x2, y1 = 0, y2 = (float)(TEXTURE_RENDER_SIZE); CoglTextureVertex verts[4]; memset (verts, 0, sizeof (verts)); @@ -124,21 +127,21 @@ on_paint (ClutterActor *actor, TestState *state) cogl_set_source_color4f (1.0, 1.0, 1.0, 1.0); - x2 = x1 + (float)(TEXTURE_SIZE); + x2 = x1 + (float)(TEXTURE_RENDER_SIZE); /* Draw a front-facing texture */ cogl_set_source_texture (state->texture); cogl_rectangle (x1, y1, x2, y2); x1 = x2; - x2 = x1 + (float)(TEXTURE_SIZE); + x2 = x1 + (float)(TEXTURE_RENDER_SIZE); /* Draw a back-facing texture */ cogl_set_source_texture (state->texture); cogl_rectangle (x2, y1, x1, y2); x1 = x2; - x2 = x1 + (float)(TEXTURE_SIZE); + x2 = x1 + (float)(TEXTURE_RENDER_SIZE); /* Draw a front-facing texture polygon */ verts[0].x = x1; verts[0].y = y2; @@ -153,7 +156,7 @@ on_paint (ClutterActor *actor, TestState *state) cogl_polygon (verts, 4, FALSE); x1 = x2; - x2 = x1 + (float)(TEXTURE_SIZE); + x2 = x1 + (float)(TEXTURE_RENDER_SIZE); /* Draw a back-facing texture polygon */ verts[0].x = x1; verts[0].y = y1; @@ -168,7 +171,7 @@ on_paint (ClutterActor *actor, TestState *state) cogl_polygon (verts, 4, FALSE); x1 = x2; - x2 = x1 + (float)(TEXTURE_SIZE); + x2 = x1 + (float)(TEXTURE_RENDER_SIZE); /* Draw a regular rectangle (this should always show) */ cogl_set_source_color4f (1.0, 0, 0, 1.0); @@ -176,7 +179,7 @@ on_paint (ClutterActor *actor, TestState *state) /* The second time round draw beneath the first with backface culling disabled */ - cogl_translate (0, TEXTURE_SIZE, 0); + cogl_translate (0, TEXTURE_RENDER_SIZE, 0); cogl_enable_backface_culling (FALSE); } @@ -221,7 +224,6 @@ make_texture (void) tex = cogl_texture_new_from_data (TEXTURE_SIZE, TEXTURE_SIZE, - 8, COGL_TEXTURE_NONE, COGL_PIXEL_FORMAT_RGBA_8888, COGL_PIXEL_FORMAT_ANY, diff --git a/tests/conform/test-npot-texture.c b/tests/conform/test-npot-texture.c index c1f762c00..69ede37a2 100644 --- a/tests/conform/test-npot-texture.c +++ b/tests/conform/test-npot-texture.c @@ -7,15 +7,20 @@ static const ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff }; /* Non-power-of-two sized texture that should cause slicing */ -#define TEXTURE_SIZE 191 +#define TEXTURE_SIZE 257 /* Number of times to split the texture up on each axis */ -#define PARTS 2 +#define PARTS 2 /* The texture is split into four parts, each with a different colour */ -#define PART_SIZE (TEXTURE_SIZE / PARTS) +#define PART_SIZE (TEXTURE_SIZE / PARTS) /* Amount of pixels to skip off the top, bottom, left and right of the texture when reading back the stage */ -#define TEST_INSET 4 +#define TEST_INSET 4 + +/* Size to actually render the texture at */ +#define TEXTURE_RENDER_SIZE 128 +/* The size of a part once rendered */ +#define PART_RENDER_SIZE (TEXTURE_RENDER_SIZE / PARTS) static const ClutterColor corner_colors[PARTS * PARTS] = { @@ -41,15 +46,15 @@ validate_part (int xnum, int ynum, const ClutterColor *color) /* Read the appropriate part but skip out a few pixels around the edges */ pixels = clutter_stage_read_pixels (CLUTTER_STAGE (stage), - xnum * PART_SIZE + TEST_INSET, - ynum * PART_SIZE + TEST_INSET, - PART_SIZE - TEST_INSET * 2, - PART_SIZE - TEST_INSET * 2); + xnum * PART_RENDER_SIZE + TEST_INSET, + ynum * PART_RENDER_SIZE + TEST_INSET, + PART_RENDER_SIZE - TEST_INSET * 2, + PART_RENDER_SIZE - TEST_INSET * 2); /* Make sure every pixels is the appropriate color */ for (p = pixels; - p < pixels + ((PART_SIZE - TEST_INSET * 2) - * (PART_SIZE - TEST_INSET * 2)); + p < pixels + ((PART_RENDER_SIZE - TEST_INSET * 2) + * (PART_RENDER_SIZE - TEST_INSET * 2)); p += 4) { if (p[0] != color->red) @@ -88,7 +93,7 @@ on_paint (ClutterActor *actor, TestState *state) /* Just render the texture in the top left corner */ cogl_set_source_texture (state->texture); - cogl_rectangle (0, 0, TEXTURE_SIZE, TEXTURE_SIZE); + cogl_rectangle (0, 0, TEXTURE_RENDER_SIZE, TEXTURE_RENDER_SIZE); /* XXX: Experiments have shown that for some buggy drivers, when using * glReadPixels there is some kind of race, so we delay our test for a @@ -152,7 +157,6 @@ make_texture (void) tex = cogl_texture_new_from_data (TEXTURE_SIZE, TEXTURE_SIZE, - 8, COGL_TEXTURE_NONE, COGL_PIXEL_FORMAT_RGBA_8888, COGL_PIXEL_FORMAT_ANY, diff --git a/tests/conform/test-vertex-buffer-contiguous.c b/tests/conform/test-vertex-buffer-contiguous.c index 8b386e650..29558bcbd 100644 --- a/tests/conform/test-vertex-buffer-contiguous.c +++ b/tests/conform/test-vertex-buffer-contiguous.c @@ -184,8 +184,7 @@ test_vertex_buffer_contiguous (TestConformSimpleFixture *fixture, g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state); state.texture = cogl_texture_new_from_data (2, 2, - 0, /* max waste */ - COGL_TEXTURE_NONE, + COGL_TEXTURE_NO_SLICING, COGL_PIXEL_FORMAT_RGBA_8888, COGL_PIXEL_FORMAT_ANY, 0, /* auto calc row stride */ diff --git a/tests/interactive/test-clip.c b/tests/interactive/test-clip.c index bb1dfa536..d756c100a 100644 --- a/tests/interactive/test-clip.c +++ b/tests/interactive/test-clip.c @@ -300,7 +300,7 @@ test_clip_main (int argc, char **argv) stub_actor = clutter_rectangle_new (); clutter_container_add (CLUTTER_CONTAINER (data.stage), stub_actor, NULL); - data.hand = cogl_texture_new_from_file ("redhand.png", 64, + data.hand = cogl_texture_new_from_file ("redhand.png", COGL_TEXTURE_NONE, COGL_PIXEL_FORMAT_ANY, NULL); diff --git a/tests/interactive/test-cogl-multitexture.c b/tests/interactive/test-cogl-multitexture.c index a45b4f965..cddf2b4ca 100644 --- a/tests/interactive/test-cogl-multitexture.c +++ b/tests/interactive/test-cogl-multitexture.c @@ -86,21 +86,21 @@ test_cogl_multitexture_main (int argc, char *argv[]) G_CALLBACK(material_rectangle_paint), state); state->alpha_tex = - cogl_texture_new_from_file ("./redhand_alpha.png", - -1, /* disable slicing */ - TRUE, + cogl_texture_new_from_file ("redhand_alpha.png", + COGL_TEXTURE_NO_SLICING | + COGL_TEXTURE_AUTO_MIPMAP, COGL_PIXEL_FORMAT_ANY, NULL); state->redhand_tex = - cogl_texture_new_from_file ("./redhand.png", - -1, /* disable slicing */ - TRUE, + cogl_texture_new_from_file ("redhand.png", + COGL_TEXTURE_NO_SLICING | + COGL_TEXTURE_AUTO_MIPMAP, COGL_PIXEL_FORMAT_ANY, NULL); state->light_tex0 = - cogl_texture_new_from_file ("./light0.png", - -1, /* disable slicing */ - TRUE, + cogl_texture_new_from_file ("light0.png", + COGL_TEXTURE_NO_SLICING | + COGL_TEXTURE_AUTO_MIPMAP, COGL_PIXEL_FORMAT_ANY, NULL); diff --git a/tests/interactive/test-cogl-offscreen.c b/tests/interactive/test-cogl-offscreen.c index 366053dc9..8b9d8e8f7 100644 --- a/tests/interactive/test-cogl-offscreen.c +++ b/tests/interactive/test-cogl-offscreen.c @@ -143,13 +143,13 @@ test_coglbox_init (TestCoglbox *self) self->priv = priv = TEST_COGLBOX_GET_PRIVATE(self); printf ("Loading redhand.png\n"); - priv->texhand_id = cogl_texture_new_from_file ("redhand.png", 0, + priv->texhand_id = cogl_texture_new_from_file ("redhand.png", COGL_TEXTURE_NONE, COGL_PIXEL_FORMAT_ANY, NULL); printf ("Creating texture with size\n"); - priv->texture_id = cogl_texture_new_with_size (200, 200, 0, + priv->texture_id = cogl_texture_new_with_size (200, 200, COGL_TEXTURE_NONE, COGL_PIXEL_FORMAT_RGB_888); diff --git a/tests/interactive/test-cogl-tex-convert.c b/tests/interactive/test-cogl-tex-convert.c index f0ac101a9..bd10d8773 100644 --- a/tests/interactive/test-cogl-tex-convert.c +++ b/tests/interactive/test-cogl-tex-convert.c @@ -144,22 +144,22 @@ test_coglbox_init (TestCoglbox *self) self->priv = priv = TEST_COGLBOX_GET_PRIVATE(self); priv->cogl_tex_id[0] = - cogl_texture_new_from_file ("redhand.png", 0, + cogl_texture_new_from_file ("redhand.png", COGL_TEXTURE_NONE, COGL_PIXEL_FORMAT_ANY, NULL); priv->cogl_tex_id[1] = - cogl_texture_new_from_file ("redhand.png", 0, + cogl_texture_new_from_file ("redhand.png", COGL_TEXTURE_NONE, COGL_PIXEL_FORMAT_BGRA_8888, NULL); priv->cogl_tex_id[2] = - cogl_texture_new_from_file ("redhand.png", 0, + cogl_texture_new_from_file ("redhand.png", COGL_TEXTURE_NONE, COGL_PIXEL_FORMAT_ARGB_8888, NULL); priv->cogl_tex_id[3] = - cogl_texture_new_from_file ("redhand.png", 0, + cogl_texture_new_from_file ("redhand.png", COGL_TEXTURE_NONE, COGL_PIXEL_FORMAT_G_8, NULL); } diff --git a/tests/interactive/test-cogl-tex-getset.c b/tests/interactive/test-cogl-tex-getset.c index 18c5a2ce2..b85bd7665 100644 --- a/tests/interactive/test-cogl-tex-getset.c +++ b/tests/interactive/test-cogl-tex-getset.c @@ -132,7 +132,7 @@ test_coglbox_init (TestCoglbox *self) /* Load image from file */ priv->cogl_tex_id[0] = - cogl_texture_new_from_file ("redhand.png", 40, + cogl_texture_new_from_file ("redhand.png", COGL_TEXTURE_NONE, COGL_PIXEL_FORMAT_ANY, NULL); @@ -168,7 +168,7 @@ test_coglbox_init (TestCoglbox *self) /* Create new texture from modified data */ priv->cogl_tex_id[1] = - cogl_texture_new_from_data (width, height, 0, + cogl_texture_new_from_data (width, height, COGL_TEXTURE_NONE, format, format, rowstride, data); diff --git a/tests/interactive/test-cogl-tex-polygon.c b/tests/interactive/test-cogl-tex-polygon.c index 0132802a4..540d832a4 100644 --- a/tests/interactive/test-cogl-tex-polygon.c +++ b/tests/interactive/test-cogl-tex-polygon.c @@ -248,7 +248,7 @@ test_coglbox_init (TestCoglbox *self) priv->use_sliced = FALSE; priv->sliced_tex = - cogl_texture_new_from_file ("redhand.png", 10, + cogl_texture_new_from_file ("redhand.png", COGL_TEXTURE_NONE, COGL_PIXEL_FORMAT_ANY, &error); @@ -265,8 +265,8 @@ test_coglbox_init (TestCoglbox *self) } priv->not_sliced_tex = - cogl_texture_new_from_file ("redhand.png", -1, - COGL_TEXTURE_NONE, + cogl_texture_new_from_file ("redhand.png", + COGL_TEXTURE_NO_SLICING, COGL_PIXEL_FORMAT_ANY, &error); if (priv->not_sliced_tex == COGL_INVALID_HANDLE) diff --git a/tests/interactive/test-cogl-tex-tile.c b/tests/interactive/test-cogl-tex-tile.c index 1402d2e28..0325add6a 100644 --- a/tests/interactive/test-cogl-tex-tile.c +++ b/tests/interactive/test-cogl-tex-tile.c @@ -143,7 +143,7 @@ test_coglbox_init (TestCoglbox *self) TestCoglboxPrivate *priv; self->priv = priv = TEST_COGLBOX_GET_PRIVATE(self); - priv->cogl_tex_id = cogl_texture_new_from_file ("redhand.png", 0, + priv->cogl_tex_id = cogl_texture_new_from_file ("redhand.png", COGL_TEXTURE_NONE, COGL_PIXEL_FORMAT_ANY, NULL);