[PATCH 2/3] ddraw/tests: Port the depth blit test to d3d7
Stefan Dösinger
stefan at codeweavers.com
Fri Dec 9 05:54:29 CST 2011
I've also ported this to d3d1. Windows is behaving in the same way, but
the test isn't working on Wine yet due to some blit-unrelated
issue, so I'm not sending the d3d1 test yet.
---
dlls/ddraw/tests/visual.c | 166 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 166 insertions(+), 0 deletions(-)
diff --git a/dlls/ddraw/tests/visual.c b/dlls/ddraw/tests/visual.c
index 1bac70c..92b33e9 100644
--- a/dlls/ddraw/tests/visual.c
+++ b/dlls/ddraw/tests/visual.c
@@ -240,6 +240,8 @@ static void set_viewport_size(IDirect3DDevice7 *device)
vp.dwWidth = ddsd.dwWidth;
vp.dwHeight = ddsd.dwHeight;
+ vp.dvMinZ = 0.0f;
+ vp.dvMaxZ = 1.0f;
hr = IDirect3DDevice7_SetViewport(device, &vp);
ok(hr == D3D_OK, "IDirect3DDevice7_SetViewport returned %08x\n", hr);
return;
@@ -3183,6 +3185,169 @@ static void DX1_BackBufferFlipTest(void)
if (window) DestroyWindow(window);
}
+static void get_depth_stencil7(IDirect3DDevice7 *device, IDirectDrawSurface7 **ds)
+{
+ IDirectDrawSurface7 *rt;
+ DDSCAPS2 caps = {DDSCAPS_ZBUFFER, 0, 0, 0};
+ HRESULT hr;
+
+ hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
+ ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
+ hr = IDirectDrawSurface7_GetAttachedSurface(rt, &caps, ds);
+ ok(SUCCEEDED(hr) || hr == DDERR_NOTFOUND, "GetAttachedSurface failed, hr %#x.\n", hr);
+ IDirectDrawSurface7_Release(rt);
+}
+
+static void depth_blit_test(IDirect3DDevice7 *device)
+{
+ struct vertex quad1[] =
+ {
+ { -1.0, 1.0, 0.50f, 0xff00ff00},
+ { 1.0, 1.0, 0.50f, 0xff00ff00},
+ { -1.0, -1.0, 0.50f, 0xff00ff00},
+ { 1.0, -1.0, 0.50f, 0xff00ff00},
+ };
+ static const DWORD expected_colors[4][4] =
+ {
+ {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
+ {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
+ {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
+ {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
+ };
+ DDSURFACEDESC2 ddsd, ddsd2;
+
+ IDirectDrawSurface7 *ds1, *ds2, *ds3;
+ RECT src_rect, dst_rect;
+ unsigned int i, j;
+ D3DCOLOR color;
+ HRESULT hr;
+ IDirect3D7 *d3d;
+ IDirectDraw7 *ddraw;
+ DDBLTFX fx;
+
+ hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
+ ok(SUCCEEDED(hr), "GetDirect3D failed, hr %#x.\n", hr);
+ hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **) &ddraw);
+ ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
+ IDirect3D7_Release(d3d);
+
+ get_depth_stencil7(device, &ds1);
+
+ memset(&ddsd, 0, sizeof(ddsd));
+ ddsd.dwSize = sizeof(ddsd);
+ memset(&ddsd2, 0, sizeof(ddsd2));
+ ddsd2.dwSize = sizeof(ddsd2);
+ hr = IDirectDrawSurface7_GetSurfaceDesc(ds1, &ddsd2);
+ ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
+ ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
+ ddsd.dwWidth = ddsd2.dwWidth;
+ ddsd.dwHeight = ddsd2.dwHeight;
+ U4(ddsd).ddpfPixelFormat = U4(ddsd2).ddpfPixelFormat;
+ hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &ds2, NULL);
+ ok(SUCCEEDED(hr), "CreateSurface failed, hr %#x.\n", hr);
+ hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &ds3, NULL);
+ ok(SUCCEEDED(hr), "CreateSurface failed, hr %#x.\n", hr);
+ IDirectDraw7_Release(ddraw);
+
+ hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
+ ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
+ hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL);
+ ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
+ ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
+
+ /* Partial blit. */
+ SetRect(&src_rect, 0, 0, 320, 240);
+ SetRect(&dst_rect, 0, 0, 320, 240);
+ hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
+ ok(SUCCEEDED(hr), "Blt failed, hr %#x.\n", hr);
+ /* Different locations. */
+ SetRect(&src_rect, 0, 0, 320, 240);
+ SetRect(&dst_rect, 320, 240, 640, 480);
+ hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
+ ok(SUCCEEDED(hr), "Blt failed, hr %#x.\n", hr);
+ /* Streched. */
+ SetRect(&src_rect, 0, 0, 320, 240);
+ SetRect(&dst_rect, 0, 0, 640, 480);
+ hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
+ ok(SUCCEEDED(hr), "Blt failed, hr %#x.\n", hr);
+ /* Flipped. */
+ SetRect(&src_rect, 0, 480, 640, 0);
+ SetRect(&dst_rect, 0, 0, 640, 480);
+ hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
+ ok(hr == DDERR_INVALIDRECT, "Blt returned %#x, expected %#x.\n", hr, DDERR_INVALIDRECT);
+ SetRect(&src_rect, 0, 0, 640, 480);
+ SetRect(&dst_rect, 0, 480, 640, 0);
+ hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
+ ok(hr == DDERR_INVALIDRECT, "Blt returned %#x, expected %#x.\n", hr, DDERR_INVALIDRECT);
+ /* Full, explicit. */
+ SetRect(&src_rect, 0, 0, 640, 480);
+ SetRect(&dst_rect, 0, 0, 640, 480);
+ hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
+ ok(SUCCEEDED(hr), "Blt failed, hr %#x.\n", hr);
+ /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
+
+ /* Depth blit inside a BeginScene / EndScene pair */
+ hr = IDirect3DDevice7_BeginScene(device);
+ ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
+ /* From the current depth stencil */
+ hr = IDirectDrawSurface7_Blt(ds2, NULL, ds1, NULL, DDBLT_WAIT, NULL);
+ ok(SUCCEEDED(hr), "Blt failed, hr %#x.\n", hr);
+ /* To the current depth stencil */
+ hr = IDirectDrawSurface7_Blt(ds1, NULL, ds2, NULL, DDBLT_WAIT, NULL);
+ ok(SUCCEEDED(hr), "Blt failed, hr %#x.\n", hr);
+ /* Between unbound surfaces */
+ hr = IDirectDrawSurface7_Blt(ds3, NULL, ds2, NULL, DDBLT_WAIT, NULL);
+ ok(SUCCEEDED(hr), "Blt failed, hr %#x.\n", hr);
+ hr = IDirect3DDevice7_EndScene(device);
+ ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
+
+ /* Avoid changing the depth stencil, it doesn't work properly on Windows.
+ * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
+ * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
+ * a reliable result(z = 0.0) */
+ memset(&fx, 0, sizeof(fx));
+ fx.dwSize = sizeof(fx);
+ fx.dwFillDepth = 0;
+ hr = IDirectDrawSurface7_Blt(ds2, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
+ ok(SUCCEEDED(hr), "Blt failed, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, 0xffff0000, 1.0f, 0);
+ ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
+ SetRect(&dst_rect, 0, 0, 320, 240);
+ hr = IDirectDrawSurface7_Blt(ds1, &dst_rect, ds2, NULL, DDBLT_WAIT, NULL);
+ ok(SUCCEEDED(hr), "Blt failed, hr %#x.\n", hr);
+ IDirectDrawSurface7_Release(ds3);
+ IDirectDrawSurface7_Release(ds2);
+ IDirectDrawSurface7_Release(ds1);
+
+ hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZWRITEENABLE, FALSE);
+ ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
+ hr = IDirect3DDevice7_BeginScene(device);
+ ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
+ hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
+ quad1, 4, 0);
+ ok(SUCCEEDED(hr), "DrawPrimitive failed, hr %#x.\n", hr);
+ hr = IDirect3DDevice7_EndScene(device);
+ ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
+
+ for (i = 0; i < 4; ++i)
+ {
+ for (j = 0; j < 4; ++j)
+ {
+ unsigned int x = 80 * ((2 * j) + 1);
+ unsigned int y = 60 * ((2 * i) + 1);
+ color = getPixelColor(device, x, y);
+ ok(color_match(color, expected_colors[i][j], 0),
+ "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors[i][j], x, y, color);
+ }
+ }
+
+ hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
+ ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
+}
+
START_TEST(visual)
{
HRESULT hr;
@@ -3232,6 +3397,7 @@ START_TEST(visual)
alpha_test(Direct3DDevice);
rhw_zero_test(Direct3DDevice);
cubemap_test(Direct3DDevice);
+ depth_blit_test(Direct3DDevice);
releaseObjects(); /* release DX7 interfaces to test D3D1 */
--
1.7.3.4
More information about the wine-patches
mailing list