# [2/5] d3dx9: Implement D3DXCheckTextureRequirements

Henri Verbeet hverbeet at gmail.com
Thu Jul 22 07:40:04 CDT 2010

```On 21 July 2010 16:06, Owen Rudge <owen at owenrudge.net> wrote:
> +/* Returns TRUE if num is a power of 2, FALSE otherwise */
> +BOOL is_pow2(UINT num)
> +{
> +    return !(num & (num - 1));
> +}
Minor, but this returns TRUE if num is power of two, *or zero*. That's
fine for how it's used, but please mention it.

> +/* Returns the smallest power of 2 which is greater than or equal to num */
> +UINT make_pow2(UINT num)
> +{
> +    UINT result = 1;
> +
> +    while (result < num)
> +        result <<= 1;
> +
> +    return result;
> +}
There's a danger of this looping forever if you pass it something >
0x80000000. I'm not sure if we care though, maybe that simply falls
under the heading of "so don't do that".

> +        if (!width && !height)
> +            max_mipmaps = 9;
This looks like the number of mipmaps in a 256x256 texture, i.e.
log2i(256) + 1. That doesn't match the values of w and h in that case
though, so I think a comment for clarification wouldn't hurt there.

> +            while (mip_width > 1 || mip_height > 1)
> +            {
> +                mip_width >>= 1;
> +                mip_height >>= 1;
> +                max_mipmaps++;
> +            }
This one is also minor, but if you don't need mip_width / mip_height
for anything else, you can just take max(w, h) before the loop. It's
probably not worth the trouble for a single instance of this
calculation, but note that wined3d has a wined3d_log2i() function in
dlls/wined3d/utils.c.

```