From 8afb499ce506b68716b4262bc16eb3d2a031bce1 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 3 Dec 2014 12:12:43 +0000 Subject: [PATCH] image: Do not put large textures in the atlas Atlasing is fine for smaller textures, but once they get too large its downsides outweight the benefits. At worst, the larger texture will end up inside its own atlas, but at worst it will require copying and/or resizing of an existing atlas. The cut-off at 512x512 pixels is a bit arbitrary, and we can change it at any point; it would be nice if we could get the texture limit from Cogl, and then use a fraction of that size as the cut-off limit. Sadly, that's not portable, and it's not guaranteed to work either. --- clutter/clutter-image.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/clutter/clutter-image.c b/clutter/clutter-image.c index 067b799fa..880b7344e 100644 --- a/clutter/clutter-image.c +++ b/clutter/clutter-image.c @@ -246,6 +246,7 @@ clutter_image_set_data (ClutterImage *image, GError **error) { ClutterImagePrivate *priv; + CoglTextureFlags flags; g_return_val_if_fail (CLUTTER_IS_IMAGE (image), FALSE); g_return_val_if_fail (data != NULL, FALSE); @@ -255,8 +256,12 @@ clutter_image_set_data (ClutterImage *image, if (priv->texture != NULL) cogl_object_unref (priv->texture); + flags = COGL_TEXTURE_NONE; + if (width >= 512 && height >= 512) + flags |= COGL_TEXTURE_NO_ATLAS; + priv->texture = cogl_texture_new_from_data (width, height, - COGL_TEXTURE_NONE, + flags, pixel_format, COGL_PIXEL_FORMAT_ANY, row_stride, @@ -309,6 +314,7 @@ clutter_image_set_bytes (ClutterImage *image, GError **error) { ClutterImagePrivate *priv; + CoglTextureFlags flags; g_return_val_if_fail (CLUTTER_IS_IMAGE (image), FALSE); g_return_val_if_fail (data != NULL, FALSE); @@ -318,8 +324,12 @@ clutter_image_set_bytes (ClutterImage *image, if (priv->texture != NULL) cogl_object_unref (priv->texture); + flags = COGL_TEXTURE_NONE; + if (width >= 512 && height >= 512) + flags |= COGL_TEXTURE_NO_ATLAS; + priv->texture = cogl_texture_new_from_data (width, height, - COGL_TEXTURE_NONE, + flags, pixel_format, COGL_PIXEL_FORMAT_ANY, row_stride, @@ -384,9 +394,14 @@ clutter_image_set_area (ClutterImage *image, if (priv->texture == NULL) { + CoglTextureFlags flags = COGL_TEXTURE_NONE; + + if (area->width >= 512 && area->height >= 512) + flags |= COGL_TEXTURE_NO_ATLAS; + priv->texture = cogl_texture_new_from_data (area->width, area->height, - COGL_TEXTURE_NONE, + flags, pixel_format, COGL_PIXEL_FORMAT_ANY, row_stride,