From a80a65ce8f0d77522a70e4cb00a8531a8902c831 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Tue, 5 Oct 2010 17:17:53 +0100 Subject: [PATCH] cogl-texture-2d-sliced: Use the smallest possible waste When picking a size for the last slice in a texture, Cogl would always pick the biggest power of two size that doesn't create too much waste and is less than or equal to the previous slice size. However this can end up creating a texture that is bigger than needed if there is a smaller power of two. For example, if the maximum waste is 127 (the current default) and we try to create a texture that is 257 pixels wide it will decide that the next power of two (512) is too much waste (255) so it will create the first slice at 256 pixels wide. Then we only have 1 pixel left to allocate but Cogl would pick the next smaller size that has a small enough waste which is 128. But of course 1 is already a power of two so that's redundantly oversized by 127. This patch fixes it so that whenever it finds a size that would be big enough, instead of using exactly that it picks the next power of two up from the size we need to fill. http://bugzilla.clutter-project.org/show_bug.cgi?id=2355 --- cogl/cogl-texture-2d-sliced.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cogl/cogl-texture-2d-sliced.c b/cogl/cogl-texture-2d-sliced.c index 51323df8a..f6fd3bf1a 100644 --- a/cogl/cogl-texture-2d-sliced.c +++ b/cogl/cogl-texture-2d-sliced.c @@ -698,6 +698,10 @@ _cogl_pot_slices_for_size (int size_to_fill, else if (span.size - size_to_fill <= max_waste) { /* Yes and waste is small enough */ + /* Pick the next power of two up from size_to_fill. This can + sometimes be less than the span.size that would be chosen + otherwise */ + span.size = _cogl_util_next_p2 (size_to_fill); span.waste = span.size - size_to_fill; if (out_spans) g_array_append_val (out_spans, span);