Commit 809618e4 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

d3dx9/tests: Add a helper to compare filled cube textures.

parent 86bc7dd1
......@@ -1362,119 +1362,133 @@ static float get_cube_coord(enum cube_coord coord, unsigned int x, unsigned int
}
}
static void test_D3DXFillCubeTexture(IDirect3DDevice9 *device)
static DWORD get_argb_color(D3DFORMAT format, DWORD x, DWORD y, const D3DLOCKED_RECT *lock_rect)
{
IDirect3DCubeTexture9 *tex;
HRESULT hr;
D3DLOCKED_RECT lock_rect;
DWORD x, y, f, m;
DWORD v[4], e[4];
DWORD value, expected, size, pitch;
enum cube_coord coordmap[6][3] =
{
{ONE, YCOORDINV, XCOORDINV},
{ZERO, YCOORDINV, XCOORD},
{XCOORD, ONE, YCOORD},
{XCOORD, ZERO, YCOORDINV},
{XCOORD, YCOORDINV, ONE},
{XCOORDINV, YCOORDINV, ZERO}
};
DWORD value, ret;
int pitch;
size = 4;
hr = IDirect3DDevice9_CreateCubeTexture(device, size, 0, 0, D3DFMT_A8R8G8B8,
D3DPOOL_MANAGED, &tex, NULL);
if (SUCCEEDED(hr))
switch (format)
{
hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
ok(hr == D3D_OK, "D3DXFillCubeTexture returned %#lx, expected %#lx\n", hr, D3D_OK);
case D3DFMT_A8R8G8B8:
pitch = lock_rect->Pitch / sizeof(DWORD);
return ((DWORD *)lock_rect->pBits)[y * pitch + x];
case D3DFMT_A1R5G5B5:
pitch = lock_rect->Pitch / sizeof(WORD);
value = ((WORD *)lock_rect->pBits)[y * pitch + x];
for (m = 0; m < 3; m++)
{
for (f = 0; f < 6; f++)
{
hr = IDirect3DCubeTexture9_LockRect(tex, f, m, &lock_rect, NULL, D3DLOCK_READONLY);
ok(hr == D3D_OK, "Couldn't lock the texture, error %#lx\n", hr);
if (SUCCEEDED(hr))
{
pitch = lock_rect.Pitch / sizeof(DWORD);
for (y = 0; y < size; y++)
{
for (x = 0; x < size; x++)
{
value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
v[0] = (value >> 24) & 0xff;
v[1] = (value >> 16) & 0xff;
v[2] = (value >> 8) & 0xff;
v[3] = value & 0xff;
ret = (value >> 15 & 0x1) << 24
| (value >> 10 & 0x1f) << 16
| (value >> 5 & 0x1f) << 8
| (value & 0x1f);
e[0] = (f == 0) || (f == 1) ?
0 : (BYTE)(255.0f / size * 2.0f + 0.5f);
e[1] = get_cube_coord(coordmap[f][0], x, y, size) / size * 255.0f + 0.5f;
e[2] = get_cube_coord(coordmap[f][1], x, y, size) / size * 255.0f + 0.5f;
e[3] = get_cube_coord(coordmap[f][2], x, y, size) / size * 255.0f + 0.5f;
expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
return ret;
ok(color_match(v, e),
"Texel at face %lu (%lu, %lu) doesn't match: %#lx, expected %#lx\n",
f, x, y, value, expected);
}
}
IDirect3DCubeTexture9_UnlockRect(tex, f, m);
}
}
size >>= 1;
}
default:
return 0;
}
}
IDirect3DCubeTexture9_Release(tex);
static DWORD get_expected_argb_color(D3DFORMAT format, const D3DXVECTOR4 *v)
{
switch (format)
{
case D3DFMT_A8R8G8B8:
return (BYTE)(v->w * 255 + 0.5f) << 24
| (BYTE)(v->x * 255 + 0.5f) << 16
| (BYTE)(v->y * 255 + 0.5f) << 8
| (BYTE)(v->z * 255 + 0.5f);
case D3DFMT_A1R5G5B5:
return (BYTE)(v->w + 0.5f) << 24
| (BYTE)(v->x * 31 + 0.5f) << 16
| (BYTE)(v->y * 31 + 0.5f) << 8
| (BYTE)(v->z * 31 + 0.5f);
default:
return 0;
}
else
skip("Failed to create texture\n");
}
hr = IDirect3DDevice9_CreateCubeTexture(device, 4, 1, 0, D3DFMT_A1R5G5B5,
D3DPOOL_MANAGED, &tex, NULL);
#define compare_cube_texture(t,f,d) compare_cube_texture_(t,f,d,__LINE__)
static void compare_cube_texture_(IDirect3DCubeTexture9 *texture,
LPD3DXFILL3D func, BYTE diff, unsigned int line)
{
static const enum cube_coord coordmap[6][3] =
{
{ONE, YCOORDINV, XCOORDINV},
{ZERO, YCOORDINV, XCOORD},
{XCOORD, ONE, YCOORD},
{XCOORD, ZERO, YCOORDINV},
{XCOORD, YCOORDINV, ONE},
{XCOORDINV, YCOORDINV, ZERO}
};
if (SUCCEEDED(hr))
DWORD x, y, m, f, levels, size, value, expected;
D3DXVECTOR3 coord, texelsize;
D3DLOCKED_RECT lock_rect;
D3DSURFACE_DESC desc;
D3DXVECTOR4 out;
HRESULT hr;
levels = IDirect3DCubeTexture9_GetLevelCount(texture);
for (m = 0; m < levels; ++m)
{
hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
ok(hr == D3D_OK, "D3DXFillTexture returned %#lx, expected %#lx\n", hr, D3D_OK);
hr = IDirect3DCubeTexture9_GetLevelDesc(texture, m, &desc);
ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
size = desc.Width;
for (f = 0; f < 6; f++)
{
hr = IDirect3DCubeTexture9_LockRect(tex, f, 0, &lock_rect, NULL, D3DLOCK_READONLY);
ok(hr == D3D_OK, "Couldn't lock the texture, error %#lx\n", hr);
if (SUCCEEDED(hr))
texelsize.x = (f == 0) || (f == 1) ? 0.0f : 2.0f / size;
texelsize.y = (f == 2) || (f == 3) ? 0.0f : 2.0f / size;
texelsize.z = (f == 4) || (f == 5) ? 0.0f : 2.0f / size;
hr = IDirect3DCubeTexture9_LockRect(texture, f, m, &lock_rect, NULL, D3DLOCK_READONLY);
ok(hr == D3D_OK, "Couldn't lock the texture, error %#lx.\n", hr);
for (y = 0; y < size; y++)
{
pitch = lock_rect.Pitch / sizeof(WORD);
for (y = 0; y < 4; y++)
for (x = 0; x < size; x++)
{
for (x = 0; x < 4; x++)
{
value = ((WORD *)lock_rect.pBits)[y * pitch + x];
v[0] = value >> 15;
v[1] = value >> 10 & 0x1f;
v[2] = value >> 5 & 0x1f;
v[3] = value & 0x1f;
coord.x = get_cube_coord(coordmap[f][0], x, y, size) / size * 2.0f - 1.0f;
coord.y = get_cube_coord(coordmap[f][1], x, y, size) / size * 2.0f - 1.0f;
coord.z = get_cube_coord(coordmap[f][2], x, y, size) / size * 2.0f - 1.0f;
e[0] = (f == 0) || (f == 1) ?
0 : (BYTE)(1.0f / size * 2.0f + 0.5f);
e[1] = get_cube_coord(coordmap[f][0], x, y, 4) / 4 * 31.0f + 0.5f;
e[2] = get_cube_coord(coordmap[f][1], x, y, 4) / 4 * 31.0f + 0.5f;
e[3] = get_cube_coord(coordmap[f][2], x, y, 4) / 4 * 31.0f + 0.5f;
expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
func(&out, &coord, &texelsize, NULL);
ok(color_match(v, e),
"Texel at face %lu (%lu, %lu) doesn't match: %#lx, expected %#lx\n",
f, x, y, value, expected);
}
value = get_argb_color(desc.Format, x, y, &lock_rect);
expected = get_expected_argb_color(desc.Format, &out);
ok_(__FILE__, line)(compare_color(value, expected, diff),
"Texel at face %lu (%lu, %lu) doesn't match: %08lx, expected %08lx.\n",
f, x, y, value, expected);
}
IDirect3DCubeTexture9_UnlockRect(tex, f, 0);
}
IDirect3DCubeTexture9_UnlockRect(texture, f, m);
}
IDirect3DCubeTexture9_Release(tex);
}
else
skip("Failed to create texture\n");
}
static void test_D3DXFillCubeTexture(IDirect3DDevice9 *device)
{
IDirect3DCubeTexture9 *tex;
HRESULT hr;
hr = IDirect3DDevice9_CreateCubeTexture(device, 4, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL);
ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
compare_cube_texture(tex, fillfunc_cube, 1);
IDirect3DCubeTexture9_Release(tex);
hr = IDirect3DDevice9_CreateCubeTexture(device, 4, 1, 0, D3DFMT_A1R5G5B5,
D3DPOOL_MANAGED, &tex, NULL);
ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
compare_cube_texture(tex, fillfunc_cube, 2);
IDirect3DCubeTexture9_Release(tex);
}
static void WINAPI fillfunc_volume(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
......
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