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
This commit is contained in:
Neil Roberts 2010-10-05 17:17:53 +01:00
parent 1f106b35a9
commit 7e112472b5

View File

@ -698,6 +698,10 @@ _cogl_pot_slices_for_size (int size_to_fill,
else if (span.size - size_to_fill <= max_waste) else if (span.size - size_to_fill <= max_waste)
{ {
/* Yes and waste is small enough */ /* 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; span.waste = span.size - size_to_fill;
if (out_spans) if (out_spans)
g_array_append_val (out_spans, span); g_array_append_val (out_spans, span);