d3d9/tests: Add a shadow sampler test.

This commit is contained in:
Henri Verbeet 2010-05-17 11:14:50 +02:00 committed by Alexandre Julliard
parent fabc7ecd97
commit 123bfa20f5

View File

@ -11075,6 +11075,208 @@ static void depth_buffer_test(IDirect3DDevice9 *device)
ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
}
static void shadow_test(IDirect3DDevice9 *device)
{
static const DWORD ps_code[] =
{
0xffff0200, /* ps_2_0 */
0x0200001f, 0x90000000, 0xa00f0800, /* dcl_2d s0 */
0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0.0, 0.0, 0.0, 1.0 */
0x02000001, 0x800f0001, 0xa0e40000, /* mov r1, c0 */
0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texld r0, t0, s0 */
0x02000001, 0x80010001, 0x80e40000, /* mov r1.x, r0 */
0x03010042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texldp r0, t0, s0 */
0x02000001, 0x80020001, 0x80000000, /* mov r1.y, r0.x */
0x02000001, 0x800f0800, 0x80e40001, /* mov 0C0, r1 */
0x0000ffff, /* end */
};
struct
{
D3DFORMAT format;
const char *name;
}
formats[] =
{
{D3DFMT_D16_LOCKABLE, "D3DFMT_D16_LOCKABLE"},
{D3DFMT_D32, "D3DFMT_D32"},
{D3DFMT_D15S1, "D3DFMT_D15S1"},
{D3DFMT_D24S8, "D3DFMT_D24S8"},
{D3DFMT_D24X8, "D3DFMT_D24X8"},
{D3DFMT_D24X4S4, "D3DFMT_D24X4S4"},
{D3DFMT_D16, "D3DFMT_D16"},
{D3DFMT_D32F_LOCKABLE, "D3DFMT_D32F_LOCKABLE"},
{D3DFMT_D24FS8, "D3DFMT_D24FS8"},
};
struct
{
float x, y, z;
float s, t, p, q;
}
quad[] =
{
{ -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f},
{ 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f},
{ -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
{ 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f},
};
struct
{
UINT x, y;
D3DCOLOR color;
}
expected_colors[] =
{
{400, 60, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00)},
{560, 180, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x00)},
{560, 300, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x00)},
{400, 420, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x00)},
{240, 420, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x00)},
{ 80, 300, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00)},
{ 80, 180, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00)},
{240, 60, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00)},
};
IDirect3DSurface9 *original_ds, *original_rt, *rt;
IDirect3DPixelShader9 *ps;
IDirect3D9 *d3d9;
D3DCAPS9 caps;
HRESULT hr;
UINT i;
hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
if (caps.PixelShaderVersion < D3DPS_VERSION(2, 0))
{
skip("No pixel shader 2.0 support, skipping shadow test.\n");
return;
}
hr = IDirect3DDevice9_GetDirect3D(device, &d3d9);
ok(SUCCEEDED(hr), "GetDirect3D failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_GetRenderTarget(device, 0, &original_rt);
ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_GetDepthStencilSurface(device, &original_ds);
ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_CreateRenderTarget(device, 1024, 1024, D3DFMT_A8R8G8B8,
D3DMULTISAMPLE_NONE, 0, FALSE, &rt, NULL);
ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_CreatePixelShader(device, ps_code, &ps);
ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE4(0));
ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_ALWAYS);
ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
for (i = 0; i < sizeof(formats) / sizeof(*formats); ++i)
{
D3DFORMAT format = formats[i].format;
IDirect3DTexture9 *texture;
IDirect3DSurface9 *ds;
unsigned int j;
hr = IDirect3D9_CheckDeviceFormat(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, format);
if (FAILED(hr)) continue;
hr = IDirect3DDevice9_CreateTexture(device, 1024, 1024, 1,
D3DUSAGE_DEPTHSTENCIL, format, D3DPOOL_DEFAULT, &texture, NULL);
ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &ds);
ok(SUCCEEDED(hr), "GetSurfaceLevel failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
ok(SUCCEEDED(hr), "SetDepthStencilSurface failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
IDirect3DDevice9_SetPixelShader(device, NULL);
ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
/* Setup the depth/stencil surface. */
hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_BeginScene(device);
ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_EndScene(device);
ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
ok(SUCCEEDED(hr), "SetDepthStencilSurface failed, hr %#x.\n", hr);
IDirect3DSurface9_Release(ds);
hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_SetPixelShader(device, ps);
ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
/* Do the actual shadow mapping. */
hr = IDirect3DDevice9_BeginScene(device);
ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_EndScene(device);
ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
IDirect3DTexture9_Release(texture);
for (j = 0; j < sizeof(expected_colors) / sizeof(*expected_colors); ++j)
{
D3DCOLOR color = getPixelColor(device, expected_colors[j].x, expected_colors[j].y);
ok(color_match(color, expected_colors[j].color, 0),
"Expected color 0x%08x at (%u, %u) for format %s, got 0x%08x.\n",
expected_colors[j].color, expected_colors[j].x, expected_colors[j].y,
formats[i].name, color);
}
hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
}
hr = IDirect3DDevice9_SetPixelShader(device, NULL);
ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
IDirect3DPixelShader9_Release(ps);
hr = IDirect3DDevice9_SetDepthStencilSurface(device, original_ds);
ok(SUCCEEDED(hr), "SetDepthStencilSurface failed, hr %#x.\n", hr);
IDirect3DSurface9_Release(original_ds);
IDirect3DSurface9_Release(original_rt);
IDirect3DSurface9_Release(rt);
IDirect3D9_Release(d3d9);
}
START_TEST(visual)
{
IDirect3DDevice9 *device_ptr;
@ -11245,6 +11447,7 @@ START_TEST(visual)
alphareplicate_test(device_ptr);
dp3_alpha_test(device_ptr);
depth_buffer_test(device_ptr);
shadow_test(device_ptr);
cleanup:
if(device_ptr) {