[Cogl] [PATCH] texture: expose mipmap level in set region apis
Neil Roberts
neil at linux.intel.com
Tue Nov 27 07:15:24 PST 2012
Robert Bragg <robert at sixbynine.org> writes:
> + * A mipmap @level of 0 corresponds to the largest, base image of a
> + * texture and @level 1 is half the width and height of level 0. If
> + * dividing any dimension of the previous level by two results in a
> + * fraction then round the number down (floor()), but clamp to 1
> + * something like this:
> + *
> + * |[
> + * next_width = MAX (1, floor (prev_width));
> + * ]|
Is there supposed to be a ‘/ 2’ in there somewhere?
> + /* The OpenGL spec clarifies that this is how you can calculate the
> + * number of mipmap levels a texture requires... */
> + return 1 + floorf (log2f (max_dimension));
I think this is essentially equivalent to doing ‘fls’ (find last in
set). It seems a shame to use floating point math for something that is quite
simple to calculate. Apparently there is usually an instruction to do
this directly. Mesa has this bit of code, maybe it would be worth
stealing it?
static inline unsigned int
_mesa_fls(unsigned int n)
{
#if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 304)
return n == 0 ? 0 : 32 - __builtin_clz(n);
#else
unsigned int v = 1;
if (n == 0)
return 0;
while (n >>= 1)
v++;
return v;
#endif
}
> + /* NB: The OpenGL spec (like D3D) uses a floor() convention to
> + * round down the size of a mipmap level when dividing the size
> + * of the previous level results in a fraction...
> + */
> + for (i = 0; i < level; i++)
> + {
> + current_width = MAX (1, current_width >> 1);
> + current_height = MAX (1, current_height >> 1);
> + current_depth = MAX (1, current_depth >> 1);
> + }
Isn't that loop equivalent to this?
current_width = MAX (1, current_width >> level);
/* etc */
I guess both of those are pretty unnecessary optimisations, so I don't
really mind either way.
Reviewed-by: Neil Roberts <neil at linux.intel.com>
Regards,
- Neil
---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
More information about the Cogl
mailing list