Commit 7d29aecd authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Use a simpler way to calculate the number of texture levels.

It's probably slightly faster too.
parent 70ed814b
......@@ -855,15 +855,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateTexture(IWineD3DDevice *iface, U
}
object->baseTexture.levels = 1;
} else if (Levels == 0) {
TRACE("calculating levels %d\n", object->baseTexture.levels);
object->baseTexture.levels++;
tmpW = Width;
tmpH = Height;
while (tmpW > 1 || tmpH > 1) {
tmpW = max(1, tmpW >> 1);
tmpH = max(1, tmpH >> 1);
object->baseTexture.levels++;
}
object->baseTexture.levels = wined3d_log2i(max(Width, Height)) + 1;
TRACE("Calculated levels = %d\n", object->baseTexture.levels);
}
......@@ -958,16 +950,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateVolumeTexture(IWineD3DDevice *ifa
}
object->baseTexture.levels = 1;
} else if (Levels == 0) {
object->baseTexture.levels++;
tmpW = Width;
tmpH = Height;
tmpD = Depth;
while (tmpW > 1 || tmpH > 1 || tmpD > 1) {
tmpW = max(1, tmpW >> 1);
tmpH = max(1, tmpH >> 1);
tmpD = max(1, tmpD >> 1);
object->baseTexture.levels++;
}
object->baseTexture.levels = wined3d_log2i(max(max(Width, Height), Depth)) + 1;
TRACE("Calculated levels = %d\n", object->baseTexture.levels);
}
......@@ -1117,12 +1100,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateCubeTexture(IWineD3DDevice *iface
}
object->baseTexture.levels = 1;
} else if (Levels == 0) {
object->baseTexture.levels++;
tmpW = EdgeLength;
while (tmpW > 1) {
tmpW = max(1, tmpW >> 1);
object->baseTexture.levels++;
}
object->baseTexture.levels = wined3d_log2i(EdgeLength) + 1;
TRACE("Calculated levels = %d\n", object->baseTexture.levels);
}
......
......@@ -2245,3 +2245,29 @@ BOOL ffp_frag_program_key_compare(const void *keya, const void *keyb)
return memcmp(ka, kb, sizeof(*ka)) == 0;
}
UINT wined3d_log2i(UINT32 x)
{
static const BYTE l[] =
{
0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
};
UINT32 i;
return (i = x >> 16) ? (x = i >> 8) ? l[x] + 24 : l[i] + 16 : (i = x >> 8) ? l[i] + 8 : l[x];
}
......@@ -2031,6 +2031,7 @@ BOOL getDepthStencilBits(WINED3DFORMAT fmt, short *depthSize, short *stencilSize
/* Math utils */
void multiply_matrix(WINED3DMATRIX *dest, const WINED3DMATRIX *src1, const WINED3DMATRIX *src2);
unsigned int count_bits(unsigned int mask);
UINT wined3d_log2i(UINT32 x);
/*****************************************************************************
* To enable calling of inherited functions, requires prototypes
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment