<div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 27, 2012 at 3:15 PM, Neil Roberts <span dir="ltr"><<a href="mailto:neil@linux.intel.com" target="_blank">neil@linux.intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im">Robert Bragg <<a href="mailto:robert@sixbynine.org">robert@sixbynine.org</a>> writes:<br>
<br>
> + * A mipmap @level of 0 corresponds to the largest, base image of a<br>
> + * texture and @level 1 is half the width and height of level 0. If<br>
> + * dividing any dimension of the previous level by two results in a<br>
> + * fraction then round the number down (floor()), but clamp to 1<br>
> + * something like this:<br>
> + *<br>
> + * |[<br>
> + * next_width = MAX (1, floor (prev_width));<br>
> + * ]|<br>
<br>
</div>Is there supposed to be a ‘/ 2’ in there somewhere?<br></blockquote><div><br></div><div>er, oops, yeah</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im"><br>
> + /* The OpenGL spec clarifies that this is how you can calculate the<br>
> + * number of mipmap levels a texture requires... */<br>
> + return 1 + floorf (log2f (max_dimension));<br>
<br>
</div>I think this is essentially equivalent to doing ‘fls’ (find last in<br>
set). It seems a shame to use floating point math for something that is quite<br>
simple to calculate. Apparently there is usually an instruction to do<br>
this directly. Mesa has this bit of code, maybe it would be worth<br>
stealing it?<br>
<br>
static inline unsigned int<br>
_mesa_fls(unsigned int n)<br>
{<br>
#if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 304)<br>
return n == 0 ? 0 : 32 - __builtin_clz(n);<br>
#else<br>
unsigned int v = 1;<br>
<br>
if (n == 0)<br>
return 0;<br>
<br>
while (n >>= 1)<br>
v++;<br>
<br>
return v;<br>
#endif<br>
<div class="im">}<br></div></blockquote><div><br></div><div>ah yeah that makes sense</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im">
<br>
> + /* NB: The OpenGL spec (like D3D) uses a floor() convention to<br>
> + * round down the size of a mipmap level when dividing the size<br>
> + * of the previous level results in a fraction...<br>
> + */<br>
> + for (i = 0; i < level; i++)<br>
> + {<br>
> + current_width = MAX (1, current_width >> 1);<br>
> + current_height = MAX (1, current_height >> 1);<br>
> + current_depth = MAX (1, current_depth >> 1);<br>
> + }<br>
<br>
</div>Isn't that loop equivalent to this?<br>
<br>
current_width = MAX (1, current_width >> level);<br>
/* etc */<br></blockquote><div><br></div><div>right, I was originally worried that calculating it iteratively vs directly from the base could be different since an iterative calculation could cumulate imprecision and so since I saw the spec gave an example of calculating iteratively I went with that. Actually looking at the spec again though they do also show calculating level sizes from the base size and given the way the calculation is done in this case it does look like you're right, they would be equivalent.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
I guess both of those are pretty unnecessary optimisations, so I don't<br>
really mind either way.<br></blockquote><div><br></div><div>thanks for taking a look, I'll update with your suggestions.</div><div><br></div><div>- Robert</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Reviewed-by: Neil Roberts <<a href="mailto:neil@linux.intel.com">neil@linux.intel.com</a>><br>
<br>
Regards,<br>
- Neil<br>
---------------------------------------------------------------------<br>
Intel Corporation (UK) Limited<br>
Registered No. 1134945 (England)<br>
Registered Office: Pipers Way, Swindon SN3 1RJ<br>
VAT No: 860 2173 47<br>
<br>
This e-mail and any attachments may contain confidential material for<br>
the sole use of the intended recipient(s). Any review or distribution<br>
by others is strictly prohibited. If you are not the intended<br>
recipient, please contact the sender and delete all copies.<br>
_______________________________________________<br>
Cogl mailing list<br>
<a href="mailto:Cogl@lists.freedesktop.org">Cogl@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/cogl" target="_blank">http://lists.freedesktop.org/mailman/listinfo/cogl</a><br>
</blockquote></div><br></div>