Signed-off-by: Stefan Dösinger <stefan(a)codeweavers.com>
---
This is merely a port of the existing test back to ddraw. The next patch
will address the WARP test failure.
---
dlls/ddraw/tests/ddraw1.c | 187 +++++++++++++++++++++++++++++++++++++++++++
dlls/ddraw/tests/ddraw2.c | 197 ++++++++++++++++++++++++++++++++++++++++++++++
dlls/ddraw/tests/ddraw4.c | 176 +++++++++++++++++++++++++++++++++++++++++
dlls/ddraw/tests/ddraw7.c | 134 +++++++++++++++++++++++++++++++
dlls/ddraw/tests/visual.c | 47 -----------
5 files changed, 694 insertions(+), 47 deletions(-)
diff --git a/dlls/ddraw/tests/ddraw1.c b/dlls/ddraw/tests/ddraw1.c
index 109910b820..671beeaa8e 100644
--- a/dlls/ddraw/tests/ddraw1.c
+++ b/dlls/ddraw/tests/ddraw1.c
@@ -10782,6 +10782,192 @@ done:
DestroyWindow(window);
}
+static void test_clear(void)
+{
+ IDirectDraw *ddraw;
+ IDirect3DDevice *device;
+ IDirectDrawSurface *rt;
+ ULONG refcount;
+ HWND window;
+ HRESULT hr;
+ D3DRECT rect[2];
+ D3DRECT rect_negneg, rect_full = {{0}, {0}, {640}, {480}};
+ D3DCOLOR color;
+ IDirect3DViewport *viewport, *viewport2, *viewport3;
+ IDirect3DMaterial *white, *red, *green, *blue;
+
+ window = create_window();
+ ddraw = create_ddraw();
+ ok(!!ddraw, "Failed to create a ddraw object.\n");
+ if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
+ {
+ skip("Failed to create a 3D device, skipping test.\n");
+ IDirectDraw_Release(ddraw);
+ DestroyWindow(window);
+ return;
+ }
+ hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
+ ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
+
+ viewport = create_viewport(device, 0, 0, 640, 480);
+
+ white = create_diffuse_material(device, 1.0f, 1.0f, 1.0f, 1.0f);
+ red = create_diffuse_material(device, 1.0f, 0.0f, 0.0f, 1.0f);
+ green = create_diffuse_material(device, 0.0f, 1.0f, 0.0f, 1.0f);
+ blue = create_diffuse_material(device, 0.0f, 0.0f, 1.0f, 1.0f);
+
+ viewport_set_background(device, viewport, white);
+ hr = IDirect3DViewport_Clear(viewport, 1, &rect_full, D3DCLEAR_TARGET);
+ ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
+
+ /* Positive x, negative y. */
+ U1(rect[0]).x1 = 0;
+ U2(rect[0]).y1 = 480;
+ U3(rect[0]).x2 = 320;
+ U4(rect[0]).y2 = 240;
+
+ /* Positive x, positive y. */
+ U1(rect[1]).x1 = 0;
+ U2(rect[1]).y1 = 0;
+ U3(rect[1]).x2 = 320;
+ U4(rect[1]).y2 = 240;
+
+ /* Clear 2 rectangles with one call. Unlike d3d8/9, the refrast does not refuse negative
+ * rectangles, but it will not clear them either. */
+ viewport_set_background(device, viewport, red);
+ hr = IDirect3DViewport_Clear(viewport, 2, rect, D3DCLEAR_TARGET);
+ ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
+
+ /* negative x, negative y.
+ *
+ * FIXME: WARP seems to clear the entire screen here.*/
+ rect_negneg.x1 = 640;
+ rect_negneg.y1 = 240;
+ rect_negneg.x2 = 320;
+ rect_negneg.y2 = 0;
+ viewport_set_background(device, viewport, green);
+ hr = IDirect3DViewport_Clear(viewport, 1, &rect_negneg, D3DCLEAR_TARGET);
+ ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
+
+ color = get_surface_color(rt, 160, 360);
+ ok(compare_color(color, 0x00ffffff, 0), "Clear rectangle 3(pos, neg) has color %08x.\n", color);
+ color = get_surface_color(rt, 160, 120);
+ ok(compare_color(color, 0x00ff0000, 0), "Clear rectangle 1(pos, pos) has color %08x.\n", color);
+ color = get_surface_color(rt, 480, 360);
+ ok(compare_color(color, 0x00ffffff, 0), "Clear rectangle 4(NULL) has color %08x.\n", color);
+ color = get_surface_color(rt, 480, 120);
+ ok(compare_color(color, 0x00ffffff, 0), "Clear rectangle 4(neg, neg) has color %08x.\n", color);
+
+ /* Test how the viewport affects clears */
+ viewport_set_background(device, viewport, white);
+ hr = IDirect3DViewport_Clear(viewport, 1, &rect_full, D3DCLEAR_TARGET);
+ ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
+
+ viewport2 = create_viewport(device, 160, 120, 160, 120);
+ viewport_set_background(device, viewport2, blue);
+ hr = IDirect3DViewport_Clear(viewport2, 1, &rect_full, D3DCLEAR_TARGET);
+ ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
+
+ viewport3 = create_viewport(device, 320, 240, 320, 240);
+ viewport_set_background(device, viewport3, green);
+
+ U1(rect[0]).x1 = 160;
+ U2(rect[0]).y1 = 120;
+ U3(rect[0]).x2 = 480;
+ U4(rect[0]).y2 = 360;
+ hr = IDirect3DViewport_Clear(viewport3, 1, &rect[0], D3DCLEAR_TARGET);
+ ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
+
+ color = get_surface_color(rt, 158, 118);
+ ok(compare_color(color, 0x00ffffff, 0), "(158,118) has color %08x\n", color);
+ color = get_surface_color(rt, 162, 118);
+ ok(compare_color(color, 0x00ffffff, 0), "(162,118) has color %08x\n", color);
+ color = get_surface_color(rt, 158, 122);
+ ok(compare_color(color, 0x00ffffff, 0), "(158,122) has color %08x\n", color);
+ color = get_surface_color(rt, 162, 122);
+ ok(compare_color(color, 0x000000ff, 0), "(162,122) has color %08x\n", color);
+
+ color = get_surface_color(rt, 318, 238);
+ ok(compare_color(color, 0x000000ff, 0), "(318,238) has color %08x\n", color);
+ color = get_surface_color(rt, 322, 238);
+ ok(compare_color(color, 0x00ffffff, 0), "(322,328) has color %08x\n", color);
+ color = get_surface_color(rt, 318, 242);
+ ok(compare_color(color, 0x00ffffff, 0), "(318,242) has color %08x\n", color);
+ color = get_surface_color(rt, 322, 242);
+ ok(compare_color(color, 0x0000ff00, 0), "(322,242) has color %08x\n", color);
+
+ color = get_surface_color(rt, 478, 358);
+ ok(compare_color(color, 0x0000ff00, 0), "(478,358 has color %08x\n", color);
+ color = get_surface_color(rt, 482, 358);
+ ok(compare_color(color, 0x00ffffff, 0), "(482,358) has color %08x\n", color);
+ color = get_surface_color(rt, 478, 362);
+ ok(compare_color(color, 0x00ffffff, 0), "(478,362) has color %08x\n", color);
+ color = get_surface_color(rt, 482, 362);
+ ok(compare_color(color, 0x00ffffff, 0), "(482,362) has color %08x\n", color);
+
+ /* The clear rectangle is rendertarget absolute, not relative to the viewport. */
+ hr = IDirect3DViewport_Clear(viewport, 1, &rect_full, D3DCLEAR_TARGET);
+ ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
+ U1(rect[0]).x1 = 330;
+ U2(rect[0]).y1 = 250;
+ U3(rect[0]).x2 = 340;
+ U4(rect[0]).y2 = 260;
+ hr = IDirect3DViewport_Clear(viewport3, 1, &rect[0], D3DCLEAR_TARGET);
+ ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
+
+ color = get_surface_color(rt, 328, 248);
+ ok(compare_color(color, 0x00ffffff, 0), "(328,248) has color %08x\n", color);
+ color = get_surface_color(rt, 332, 248);
+ ok(compare_color(color, 0x00ffffff, 0), "(332,248) has color %08x\n", color);
+ color = get_surface_color(rt, 328, 252);
+ ok(compare_color(color, 0x00ffffff, 0), "(328,252) has color %08x\n", color);
+ color = get_surface_color(rt, 332, 252);
+ ok(compare_color(color, 0x0000ff00, 0), "(332,252) has color %08x\n", color);
+
+ color = get_surface_color(rt, 338, 248);
+ ok(compare_color(color, 0x00ffffff, 0), "(338,248) has color %08x\n", color);
+ color = get_surface_color(rt, 342, 248);
+ ok(compare_color(color, 0x00ffffff, 0), "(342,248) has color %08x\n", color);
+ color = get_surface_color(rt, 338, 252);
+ ok(compare_color(color, 0x0000ff00, 0), "(338,252) has color %08x\n", color);
+ color = get_surface_color(rt, 342, 252);
+ ok(compare_color(color, 0x00ffffff, 0), "(342,252) has color %08x\n", color);
+
+ color = get_surface_color(rt, 328, 258);
+ ok(compare_color(color, 0x00ffffff, 0), "(328,258 has color %08x\n", color);
+ color = get_surface_color(rt, 332, 258);
+ ok(compare_color(color, 0x0000ff00, 0), "(332,258) has color %08x\n", color);
+ color = get_surface_color(rt, 328, 262);
+ ok(compare_color(color, 0x00ffffff, 0), "(328,262) has color %08x\n", color);
+ color = get_surface_color(rt, 332, 262);
+ ok(compare_color(color, 0x00ffffff, 0), "(332,262) has color %08x\n", color);
+
+ color = get_surface_color(rt, 338, 258);
+ ok(compare_color(color, 0x0000ff00, 0), "(328,258 has color %08x\n", color);
+ color = get_surface_color(rt, 342, 258);
+ ok(compare_color(color, 0x00ffffff, 0), "(332,258) has color %08x\n", color);
+ color = get_surface_color(rt, 338, 262);
+ ok(compare_color(color, 0x00ffffff, 0), "(328,262) has color %08x\n", color);
+ color = get_surface_color(rt, 342, 262);
+ ok(compare_color(color, 0x00ffffff, 0), "(332,262) has color %08x\n", color);
+
+ /* COLORWRITEENABLE, SRGBWRITEENABLE and scissor rectangles do not exist in d3d1. */
+
+ IDirect3DViewport_Release(viewport3);
+ IDirect3DViewport_Release(viewport2);
+ IDirect3DViewport_Release(viewport);
+ IDirect3DMaterial_Release(white);
+ IDirect3DMaterial_Release(red);
+ IDirect3DMaterial_Release(green);
+ IDirect3DMaterial_Release(blue);
+ IDirectDrawSurface_Release(rt);
+ refcount = IDirect3DDevice_Release(device);
+ ok(!refcount, "Device has %u references left.\n", refcount);
+ refcount = IDirectDraw_Release(ddraw);
+ ok(!refcount, "Ddraw object has %u references left.\n", refcount);
+ DestroyWindow(window);
+}
+
START_TEST(ddraw1)
{
IDirectDraw *ddraw;
@@ -10870,4 +11056,5 @@ START_TEST(ddraw1)
test_surface_desc_size();
test_texture_load();
test_ck_operation();
+ test_clear();
}
diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c
index 1db7ad9329..6a13764859 100644
--- a/dlls/ddraw/tests/ddraw2.c
+++ b/dlls/ddraw/tests/ddraw2.c
@@ -12158,6 +12158,202 @@ done:
DestroyWindow(window);
}
+static void test_clear(void)
+{
+ IDirectDraw2 *ddraw;
+ IDirect3DDevice2 *device;
+ IDirectDrawSurface *rt;
+ ULONG refcount;
+ HWND window;
+ HRESULT hr;
+ D3DRECT rect[2];
+ D3DRECT rect_negneg, rect_full = {{0}, {0}, {640}, {480}};
+ D3DCOLOR color;
+ IDirect3DViewport2 *viewport, *viewport2, *viewport3;
+ IDirect3DMaterial2 *white, *red, *green, *blue;
+
+ window = create_window();
+ ddraw = create_ddraw();
+ ok(!!ddraw, "Failed to create a ddraw object.\n");
+ if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
+ {
+ skip("Failed to create a 3D device, skipping test.\n");
+ IDirectDraw2_Release(ddraw);
+ DestroyWindow(window);
+ return;
+ }
+ hr = IDirect3DDevice2_GetRenderTarget(device, &rt);
+ ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
+
+ viewport = create_viewport(device, 0, 0, 640, 480);
+ hr = IDirect3DDevice2_SetCurrentViewport(device, viewport);
+ ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
+
+ white = create_diffuse_material(device, 1.0f, 1.0f, 1.0f, 1.0f);
+ red = create_diffuse_material(device, 1.0f, 0.0f, 0.0f, 1.0f);
+ green = create_diffuse_material(device, 0.0f, 1.0f, 0.0f, 1.0f);
+ blue = create_diffuse_material(device, 0.0f, 0.0f, 1.0f, 1.0f);
+
+ viewport_set_background(device, viewport, white);
+ hr = IDirect3DViewport2_Clear(viewport, 1, &rect_full, D3DCLEAR_TARGET);
+ ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
+
+ /* Positive x, negative y. */
+ U1(rect[0]).x1 = 0;
+ U2(rect[0]).y1 = 480;
+ U3(rect[0]).x2 = 320;
+ U4(rect[0]).y2 = 240;
+
+ /* Positive x, positive y. */
+ U1(rect[1]).x1 = 0;
+ U2(rect[1]).y1 = 0;
+ U3(rect[1]).x2 = 320;
+ U4(rect[1]).y2 = 240;
+
+ /* Clear 2 rectangles with one call. Unlike d3d8/9, the refrast does not refuse negative
+ * rectangles, but it will not clear them either. */
+ viewport_set_background(device, viewport, red);
+ hr = IDirect3DViewport2_Clear(viewport, 2, rect, D3DCLEAR_TARGET);
+ ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
+
+ /* negative x, negative y.
+ *
+ * FIXME: WARP seems to clear the entire screen here.*/
+ rect_negneg.x1 = 640;
+ rect_negneg.y1 = 240;
+ rect_negneg.x2 = 320;
+ rect_negneg.y2 = 0;
+ viewport_set_background(device, viewport, green);
+ hr = IDirect3DViewport2_Clear(viewport, 1, &rect_negneg, D3DCLEAR_TARGET);
+ ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
+
+ color = get_surface_color(rt, 160, 360);
+ ok(compare_color(color, 0x00ffffff, 0), "Clear rectangle 3(pos, neg) has color %08x.\n", color);
+ color = get_surface_color(rt, 160, 120);
+ ok(compare_color(color, 0x00ff0000, 0), "Clear rectangle 1(pos, pos) has color %08x.\n", color);
+ color = get_surface_color(rt, 480, 360);
+ ok(compare_color(color, 0x00ffffff, 0), "Clear rectangle 4(NULL) has color %08x.\n", color);
+ color = get_surface_color(rt, 480, 120);
+ ok(compare_color(color, 0x00ffffff, 0), "Clear rectangle 4(neg, neg) has color %08x.\n", color);
+
+ /* Test how the viewport affects clears */
+ viewport_set_background(device, viewport, white);
+ hr = IDirect3DViewport2_Clear(viewport, 1, &rect_full, D3DCLEAR_TARGET);
+ ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
+
+ viewport2 = create_viewport(device, 160, 120, 160, 120);
+ hr = IDirect3DDevice2_SetCurrentViewport(device, viewport2);
+ ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
+
+ viewport_set_background(device, viewport2, blue);
+ hr = IDirect3DViewport2_Clear(viewport2, 1, &rect_full, D3DCLEAR_TARGET);
+ ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
+
+ viewport3 = create_viewport(device, 320, 240, 320, 240);
+ hr = IDirect3DDevice2_SetCurrentViewport(device, viewport3);
+ ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
+
+ U1(rect[0]).x1 = 160;
+ U2(rect[0]).y1 = 120;
+ U3(rect[0]).x2 = 480;
+ U4(rect[0]).y2 = 360;
+ viewport_set_background(device, viewport3, green);
+ hr = IDirect3DViewport2_Clear(viewport3, 1, &rect[0], D3DCLEAR_TARGET);
+ ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice2_SetCurrentViewport(device, viewport);
+ ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
+
+ color = get_surface_color(rt, 158, 118);
+ ok(compare_color(color, 0x00ffffff, 0), "(158,118) has color %08x\n", color);
+ color = get_surface_color(rt, 162, 118);
+ ok(compare_color(color, 0x00ffffff, 0), "(162,118) has color %08x\n", color);
+ color = get_surface_color(rt, 158, 122);
+ ok(compare_color(color, 0x00ffffff, 0), "(158,122) has color %08x\n", color);
+ color = get_surface_color(rt, 162, 122);
+ ok(compare_color(color, 0x000000ff, 0), "(162,122) has color %08x\n", color);
+
+ color = get_surface_color(rt, 318, 238);
+ ok(compare_color(color, 0x000000ff, 0), "(318,238) has color %08x\n", color);
+ color = get_surface_color(rt, 322, 238);
+ ok(compare_color(color, 0x00ffffff, 0), "(322,328) has color %08x\n", color);
+ color = get_surface_color(rt, 318, 242);
+ ok(compare_color(color, 0x00ffffff, 0), "(318,242) has color %08x\n", color);
+ color = get_surface_color(rt, 322, 242);
+ ok(compare_color(color, 0x0000ff00, 0), "(322,242) has color %08x\n", color);
+
+ color = get_surface_color(rt, 478, 358);
+ ok(compare_color(color, 0x0000ff00, 0), "(478,358 has color %08x\n", color);
+ color = get_surface_color(rt, 482, 358);
+ ok(compare_color(color, 0x00ffffff, 0), "(482,358) has color %08x\n", color);
+ color = get_surface_color(rt, 478, 362);
+ ok(compare_color(color, 0x00ffffff, 0), "(478,362) has color %08x\n", color);
+ color = get_surface_color(rt, 482, 362);
+ ok(compare_color(color, 0x00ffffff, 0), "(482,362) has color %08x\n", color);
+
+ /* The clear rectangle is rendertarget absolute, not relative to the viewport. */
+ hr = IDirect3DViewport2_Clear(viewport, 1, &rect_full, D3DCLEAR_TARGET);
+ ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
+ U1(rect[0]).x1 = 330;
+ U2(rect[0]).y1 = 250;
+ U3(rect[0]).x2 = 340;
+ U4(rect[0]).y2 = 260;
+ hr = IDirect3DViewport2_Clear(viewport3, 1, &rect[0], D3DCLEAR_TARGET);
+ ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
+
+ color = get_surface_color(rt, 328, 248);
+ ok(compare_color(color, 0x00ffffff, 0), "(328,248) has color %08x\n", color);
+ color = get_surface_color(rt, 332, 248);
+ ok(compare_color(color, 0x00ffffff, 0), "(332,248) has color %08x\n", color);
+ color = get_surface_color(rt, 328, 252);
+ ok(compare_color(color, 0x00ffffff, 0), "(328,252) has color %08x\n", color);
+ color = get_surface_color(rt, 332, 252);
+ ok(compare_color(color, 0x0000ff00, 0), "(332,252) has color %08x\n", color);
+
+ color = get_surface_color(rt, 338, 248);
+ ok(compare_color(color, 0x00ffffff, 0), "(338,248) has color %08x\n", color);
+ color = get_surface_color(rt, 342, 248);
+ ok(compare_color(color, 0x00ffffff, 0), "(342,248) has color %08x\n", color);
+ color = get_surface_color(rt, 338, 252);
+ ok(compare_color(color, 0x0000ff00, 0), "(338,252) has color %08x\n", color);
+ color = get_surface_color(rt, 342, 252);
+ ok(compare_color(color, 0x00ffffff, 0), "(342,252) has color %08x\n", color);
+
+ color = get_surface_color(rt, 328, 258);
+ ok(compare_color(color, 0x00ffffff, 0), "(328,258 has color %08x\n", color);
+ color = get_surface_color(rt, 332, 258);
+ ok(compare_color(color, 0x0000ff00, 0), "(332,258) has color %08x\n", color);
+ color = get_surface_color(rt, 328, 262);
+ ok(compare_color(color, 0x00ffffff, 0), "(328,262) has color %08x\n", color);
+ color = get_surface_color(rt, 332, 262);
+ ok(compare_color(color, 0x00ffffff, 0), "(332,262) has color %08x\n", color);
+
+ color = get_surface_color(rt, 338, 258);
+ ok(compare_color(color, 0x0000ff00, 0), "(328,258 has color %08x\n", color);
+ color = get_surface_color(rt, 342, 258);
+ ok(compare_color(color, 0x00ffffff, 0), "(332,258) has color %08x\n", color);
+ color = get_surface_color(rt, 338, 262);
+ ok(compare_color(color, 0x00ffffff, 0), "(328,262) has color %08x\n", color);
+ color = get_surface_color(rt, 342, 262);
+ ok(compare_color(color, 0x00ffffff, 0), "(332,262) has color %08x\n", color);
+
+ /* COLORWRITEENABLE, SRGBWRITEENABLE and scissor rectangles do not exist in d3d2. */
+
+ IDirect3DViewport2_Release(viewport3);
+ IDirect3DViewport2_Release(viewport2);
+ IDirect3DViewport2_Release(viewport);
+ IDirect3DMaterial2_Release(white);
+ IDirect3DMaterial2_Release(red);
+ IDirect3DMaterial2_Release(green);
+ IDirect3DMaterial2_Release(blue);
+ IDirectDrawSurface_Release(rt);
+ refcount = IDirect3DDevice2_Release(device);
+ ok(!refcount, "Device has %u references left.\n", refcount);
+ refcount = IDirectDraw2_Release(ddraw);
+ ok(!refcount, "Ddraw object has %u references left.\n", refcount);
+ DestroyWindow(window);
+}
+
START_TEST(ddraw2)
{
IDirectDraw2 *ddraw;
@@ -12254,4 +12450,5 @@ START_TEST(ddraw2)
test_display_mode_surface_pixel_format();
test_surface_desc_size();
test_ck_operation();
+ test_clear();
}
diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c
index 98c86d0bf0..b79e6c67a2 100644
--- a/dlls/ddraw/tests/ddraw4.c
+++ b/dlls/ddraw/tests/ddraw4.c
@@ -14006,6 +14006,181 @@ static void test_compute_sphere_visibility(void)
DestroyWindow(window);
}
+static void test_clear(void)
+{
+ IDirect3DDevice3 *device;
+ IDirectDrawSurface4 *rt;
+ ULONG refcount;
+ HWND window;
+ HRESULT hr;
+ D3DRECT rect[2];
+ D3DRECT rect_negneg, rect_full = {{0}, {0}, {640}, {480}};
+ D3DCOLOR color;
+ IDirect3DViewport3 *viewport, *viewport2, *viewport3;
+
+ window = create_window();
+ if (!(device = create_device(window, DDSCL_NORMAL)))
+ {
+ skip("Failed to create 3D device.\n");
+ DestroyWindow(window);
+ return;
+ }
+
+ hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
+ ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
+
+ viewport = create_viewport(device, 0, 0, 640, 480);
+ hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
+ ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
+
+ hr = IDirect3DViewport3_Clear2(viewport, 1, &rect_full, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
+ ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
+
+ /* Positive x, negative y. */
+ U1(rect[0]).x1 = 0;
+ U2(rect[0]).y1 = 480;
+ U3(rect[0]).x2 = 320;
+ U4(rect[0]).y2 = 240;
+
+ /* Positive x, positive y. */
+ U1(rect[1]).x1 = 0;
+ U2(rect[1]).y1 = 0;
+ U3(rect[1]).x2 = 320;
+ U4(rect[1]).y2 = 240;
+
+ /* Clear 2 rectangles with one call. Unlike d3d8/9, the refrast does not refuse negative
+ * rectangles, but it will not clear them either. */
+ hr = IDirect3DViewport3_Clear2(viewport, 2, rect, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
+ ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
+
+ /* negative x, negative y.
+ *
+ * FIXME: WARP seems to clear the entire screen here.*/
+ rect_negneg.x1 = 640;
+ rect_negneg.y1 = 240;
+ rect_negneg.x2 = 320;
+ rect_negneg.y2 = 0;
+ hr = IDirect3DViewport3_Clear2(viewport, 1, &rect_negneg, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
+ ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
+
+ color = get_surface_color(rt, 160, 360);
+ ok(compare_color(color, 0x00ffffff, 0), "Clear rectangle 3(pos, neg) has color %08x.\n", color);
+ color = get_surface_color(rt, 160, 120);
+ ok(compare_color(color, 0x00ff0000, 0), "Clear rectangle 1(pos, pos) has color %08x.\n", color);
+ color = get_surface_color(rt, 480, 360);
+ ok(compare_color(color, 0x00ffffff, 0), "Clear rectangle 4(NULL) has color %08x.\n", color);
+ color = get_surface_color(rt, 480, 120);
+ ok(compare_color(color, 0x00ffffff, 0), "Clear rectangle 4(neg, neg) has color %08x.\n", color);
+
+ /* Test how the viewport affects clears */
+ hr = IDirect3DViewport3_Clear2(viewport, 1, &rect_full, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
+ ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
+
+ viewport2 = create_viewport(device, 160, 120, 160, 120);
+ hr = IDirect3DDevice3_SetCurrentViewport(device, viewport2);
+ ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
+
+ hr = IDirect3DViewport3_Clear2(viewport2, 1, &rect_full, D3DCLEAR_TARGET, 0xff0000ff, 0.0, 0);
+ ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
+
+ viewport3 = create_viewport(device, 320, 240, 320, 240);
+ hr = IDirect3DDevice3_SetCurrentViewport(device, viewport3);
+ ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
+
+ U1(rect[0]).x1 = 160;
+ U2(rect[0]).y1 = 120;
+ U3(rect[0]).x2 = 480;
+ U4(rect[0]).y2 = 360;
+ hr = IDirect3DViewport3_Clear2(viewport3, 1, &rect[0], D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
+ ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
+ ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
+
+ color = get_surface_color(rt, 158, 118);
+ ok(compare_color(color, 0x00ffffff, 0), "(158,118) has color %08x\n", color);
+ color = get_surface_color(rt, 162, 118);
+ ok(compare_color(color, 0x00ffffff, 0), "(162,118) has color %08x\n", color);
+ color = get_surface_color(rt, 158, 122);
+ ok(compare_color(color, 0x00ffffff, 0), "(158,122) has color %08x\n", color);
+ color = get_surface_color(rt, 162, 122);
+ ok(compare_color(color, 0x000000ff, 0), "(162,122) has color %08x\n", color);
+
+ color = get_surface_color(rt, 318, 238);
+ ok(compare_color(color, 0x000000ff, 0), "(318,238) has color %08x\n", color);
+ color = get_surface_color(rt, 322, 238);
+ ok(compare_color(color, 0x00ffffff, 0), "(322,328) has color %08x\n", color);
+ color = get_surface_color(rt, 318, 242);
+ ok(compare_color(color, 0x00ffffff, 0), "(318,242) has color %08x\n", color);
+ color = get_surface_color(rt, 322, 242);
+ ok(compare_color(color, 0x0000ff00, 0), "(322,242) has color %08x\n", color);
+
+ color = get_surface_color(rt, 478, 358);
+ ok(compare_color(color, 0x0000ff00, 0), "(478,358 has color %08x\n", color);
+ color = get_surface_color(rt, 482, 358);
+ ok(compare_color(color, 0x00ffffff, 0), "(482,358) has color %08x\n", color);
+ color = get_surface_color(rt, 478, 362);
+ ok(compare_color(color, 0x00ffffff, 0), "(478,362) has color %08x\n", color);
+ color = get_surface_color(rt, 482, 362);
+ ok(compare_color(color, 0x00ffffff, 0), "(482,362) has color %08x\n", color);
+
+ /* The clear rectangle is rendertarget absolute, not relative to the viewport. */
+ hr = IDirect3DViewport3_Clear2(viewport, 1, &rect_full, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
+ ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
+ U1(rect[0]).x1 = 330;
+ U2(rect[0]).y1 = 250;
+ U3(rect[0]).x2 = 340;
+ U4(rect[0]).y2 = 260;
+ hr = IDirect3DViewport3_Clear2(viewport3, 1, &rect[0], D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
+ ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
+
+ color = get_surface_color(rt, 328, 248);
+ ok(compare_color(color, 0x00ffffff, 0), "(328,248) has color %08x\n", color);
+ color = get_surface_color(rt, 332, 248);
+ ok(compare_color(color, 0x00ffffff, 0), "(332,248) has color %08x\n", color);
+ color = get_surface_color(rt, 328, 252);
+ ok(compare_color(color, 0x00ffffff, 0), "(328,252) has color %08x\n", color);
+ color = get_surface_color(rt, 332, 252);
+ ok(compare_color(color, 0x0000ff00, 0), "(332,252) has color %08x\n", color);
+
+ color = get_surface_color(rt, 338, 248);
+ ok(compare_color(color, 0x00ffffff, 0), "(338,248) has color %08x\n", color);
+ color = get_surface_color(rt, 342, 248);
+ ok(compare_color(color, 0x00ffffff, 0), "(342,248) has color %08x\n", color);
+ color = get_surface_color(rt, 338, 252);
+ ok(compare_color(color, 0x0000ff00, 0), "(338,252) has color %08x\n", color);
+ color = get_surface_color(rt, 342, 252);
+ ok(compare_color(color, 0x00ffffff, 0), "(342,252) has color %08x\n", color);
+
+ color = get_surface_color(rt, 328, 258);
+ ok(compare_color(color, 0x00ffffff, 0), "(328,258 has color %08x\n", color);
+ color = get_surface_color(rt, 332, 258);
+ ok(compare_color(color, 0x0000ff00, 0), "(332,258) has color %08x\n", color);
+ color = get_surface_color(rt, 328, 262);
+ ok(compare_color(color, 0x00ffffff, 0), "(328,262) has color %08x\n", color);
+ color = get_surface_color(rt, 332, 262);
+ ok(compare_color(color, 0x00ffffff, 0), "(332,262) has color %08x\n", color);
+
+ color = get_surface_color(rt, 338, 258);
+ ok(compare_color(color, 0x0000ff00, 0), "(328,258 has color %08x\n", color);
+ color = get_surface_color(rt, 342, 258);
+ ok(compare_color(color, 0x00ffffff, 0), "(332,258) has color %08x\n", color);
+ color = get_surface_color(rt, 338, 262);
+ ok(compare_color(color, 0x00ffffff, 0), "(328,262) has color %08x\n", color);
+ color = get_surface_color(rt, 342, 262);
+ ok(compare_color(color, 0x00ffffff, 0), "(332,262) has color %08x\n", color);
+
+ /* COLORWRITEENABLE, SRGBWRITEENABLE and scissor rectangles do not exist in d3d3. */
+
+ IDirect3DViewport3_Release(viewport3);
+ IDirect3DViewport3_Release(viewport2);
+ IDirect3DViewport3_Release(viewport);
+ IDirectDrawSurface4_Release(rt);
+ refcount = IDirect3DDevice3_Release(device);
+ ok(!refcount, "Device has %u references left.\n", refcount);
+ DestroyWindow(window);
+}
+
START_TEST(ddraw4)
{
IDirectDraw4 *ddraw;
@@ -14114,4 +14289,5 @@ START_TEST(ddraw4)
test_ck_operation();
test_vb_refcount();
test_compute_sphere_visibility();
+ test_clear();
}
diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c
index 91822281d0..ebcb972034 100644
--- a/dlls/ddraw/tests/ddraw7.c
+++ b/dlls/ddraw/tests/ddraw7.c
@@ -13385,6 +13385,139 @@ static void test_clip_planes_limits(void)
DestroyWindow(window);
}
+static void test_clear(void)
+{
+ IDirect3DDevice7 *device;
+ IDirectDrawSurface7 *rt;
+ ULONG refcount;
+ HWND window;
+ HRESULT hr;
+ D3DRECT rect[2];
+ D3DRECT rect_negneg;
+ D3DCOLOR color;
+ D3DVIEWPORT7 vp, old_vp;
+
+ window = create_window();
+ if (!(device = create_device(window, DDSCL_NORMAL)))
+ {
+ skip("Failed to create 3D device.\n");
+ DestroyWindow(window);
+ return;
+ }
+
+ hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
+ ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
+ ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
+
+ /* Positive x, negative y. */
+ U1(rect[0]).x1 = 0;
+ U2(rect[0]).y1 = 480;
+ U3(rect[0]).x2 = 320;
+ U4(rect[0]).y2 = 240;
+
+ /* Positive x, positive y. */
+ U1(rect[1]).x1 = 0;
+ U2(rect[1]).y1 = 0;
+ U3(rect[1]).x2 = 320;
+ U4(rect[1]).y2 = 240;
+
+ /* Clear 2 rectangles with one call. Unlike d3d8/9, the refrast does not refuse negative
+ * rectangles, but it will not clear them either. */
+ hr = IDirect3DDevice7_Clear(device, 2, rect, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
+ ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
+
+ /* negative x, negative y.
+ *
+ * FIXME: WARP seems to clear the entire screen here.*/
+ rect_negneg.x1 = 640;
+ rect_negneg.y1 = 240;
+ rect_negneg.x2 = 320;
+ rect_negneg.y2 = 0;
+ hr = IDirect3DDevice7_Clear(device, 1, &rect_negneg, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
+ ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
+
+ color = get_surface_color(rt, 160, 360);
+ ok(compare_color(color, 0x00ffffff, 0), "Clear rectangle 3(pos, neg) has color %08x.\n", color);
+ color = get_surface_color(rt, 160, 120);
+ ok(compare_color(color, 0x00ff0000, 0), "Clear rectangle 1(pos, pos) has color %08x.\n", color);
+ color = get_surface_color(rt, 480, 360);
+ ok(compare_color(color, 0x00ffffff, 0), "Clear rectangle 4(NULL) has color %08x.\n", color);
+ color = get_surface_color(rt, 480, 120);
+ ok(compare_color(color, 0x00ffffff, 0), "Clear rectangle 4(neg, neg) has color %08x.\n", color);
+
+ /* Test how the viewport affects clears */
+ hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
+ ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
+ hr = IDirect3DDevice7_GetViewport(device, &old_vp);
+ ok(hr == D3D_OK, "Failed to get viewport, hr %#x.\n", hr);
+
+ vp.dwX = 160;
+ vp.dwY = 120;
+ vp.dwWidth = 160;
+ vp.dwHeight = 120;
+ vp.dvMinZ = 0.0;
+ vp.dvMaxZ = 1.0;
+ hr = IDirect3DDevice7_SetViewport(device, &vp);
+ ok(hr == D3D_OK, "Failed to set viewport, hr %#x.\n", hr);
+ hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0, 0);
+ ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
+
+ vp.dwX = 320;
+ vp.dwY = 240;
+ vp.dwWidth = 320;
+ vp.dwHeight = 240;
+ vp.dvMinZ = 0.0;
+ vp.dvMaxZ = 1.0;
+ hr = IDirect3DDevice7_SetViewport(device, &vp);
+ ok(hr == D3D_OK, "Failed to set viewport, hr %#x.\n", hr);
+
+ U1(rect[0]).x1 = 160;
+ U2(rect[0]).y1 = 120;
+ U3(rect[0]).x2 = 480;
+ U4(rect[0]).y2 = 360;
+ hr = IDirect3DDevice7_Clear(device, 1, &rect[0], D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
+ ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice7_SetViewport(device, &old_vp);
+ ok(hr == D3D_OK, "Failed to set viewport, hr %#x.\n", hr);
+
+ color = get_surface_color(rt, 158, 118);
+ ok(compare_color(color, 0x00ffffff, 0), "(158,118) has color %08x\n", color);
+ color = get_surface_color(rt, 162, 118);
+ ok(compare_color(color, 0x00ffffff, 0), "(162,118) has color %08x\n", color);
+ color = get_surface_color(rt, 158, 122);
+ ok(compare_color(color, 0x00ffffff, 0), "(158,122) has color %08x\n", color);
+ color = get_surface_color(rt, 162, 122);
+ ok(compare_color(color, 0x000000ff, 0), "(162,122) has color %08x\n", color);
+
+ color = get_surface_color(rt, 318, 238);
+ ok(compare_color(color, 0x000000ff, 0), "(318,238) has color %08x\n", color);
+ color = get_surface_color(rt, 322, 238);
+ ok(compare_color(color, 0x00ffffff, 0), "(322,328) has color %08x\n", color);
+ color = get_surface_color(rt, 318, 242);
+ ok(compare_color(color, 0x00ffffff, 0), "(318,242) has color %08x\n", color);
+ color = get_surface_color(rt, 322, 242);
+ ok(compare_color(color, 0x0000ff00, 0), "(322,242) has color %08x\n", color);
+
+ color = get_surface_color(rt, 478, 358);
+ ok(compare_color(color, 0x0000ff00, 0), "(478,358 has color %08x\n", color);
+ color = get_surface_color(rt, 482, 358);
+ ok(compare_color(color, 0x00ffffff, 0), "(482,358) has color %08x\n", color);
+ color = get_surface_color(rt, 478, 362);
+ ok(compare_color(color, 0x00ffffff, 0), "(478,362) has color %08x\n", color);
+ color = get_surface_color(rt, 482, 362);
+ ok(compare_color(color, 0x00ffffff, 0), "(482,362) has color %08x\n", color);
+
+ /* COLORWRITEENABLE, SRGBWRITEENABLE and scissor rectangles do not exist in d3d7. */
+
+ IDirectDrawSurface7_Release(rt);
+ refcount = IDirect3DDevice7_Release(device);
+ ok(!refcount, "Device has %u references left.\n", refcount);
+ DestroyWindow(window);
+}
+
START_TEST(ddraw7)
{
HMODULE module = GetModuleHandleA("ddraw.dll");
@@ -13503,4 +13636,5 @@ START_TEST(ddraw7)
test_vb_refcount();
test_compute_sphere_visibility();
test_clip_planes_limits();
+ test_clear();
}
diff --git a/dlls/ddraw/tests/visual.c b/dlls/ddraw/tests/visual.c
index 4f6213354d..2cb1c89231 100644
--- a/dlls/ddraw/tests/visual.c
+++ b/dlls/ddraw/tests/visual.c
@@ -267,52 +267,6 @@ static void set_viewport_size(IDirect3DDevice7 *device)
return;
}
-static void clear_test(IDirect3DDevice7 *device)
-{
- /* Tests the correctness of clearing parameters */
- HRESULT hr;
- D3DRECT rect[2];
- D3DRECT rect_negneg;
- DWORD color;
-
- hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
- ok(hr == D3D_OK, "IDirect3DDevice7_Clear failed with %08x\n", hr);
-
- /* Positive x, negative y */
- U1(rect[0]).x1 = 0;
- U2(rect[0]).y1 = 480;
- U3(rect[0]).x2 = 320;
- U4(rect[0]).y2 = 240;
-
- /* Positive x, positive y */
- U1(rect[1]).x1 = 0;
- U2(rect[1]).y1 = 0;
- U3(rect[1]).x2 = 320;
- U4(rect[1]).y2 = 240;
- /* Clear 2 rectangles with one call. Shows that a positive value is returned, but the negative rectangle
- * is ignored, the positive is still cleared afterwards
- */
- hr = IDirect3DDevice7_Clear(device, 2, rect, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
- ok(hr == D3D_OK, "IDirect3DDevice7_Clear failed with %08x\n", hr);
-
- /* negative x, negative y */
- U1(rect_negneg).x1 = 640;
- U2(rect_negneg).y1 = 240;
- U3(rect_negneg).x2 = 320;
- U4(rect_negneg).y2 = 0;
- hr = IDirect3DDevice7_Clear(device, 1, &rect_negneg, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
- ok(hr == D3D_OK, "IDirect3DDevice7_Clear failed with %08x\n", hr);
-
- color = getPixelColor(device, 160, 360); /* lower left quad */
- ok(color == 0x00ffffff, "Clear rectangle 3(pos, neg) has color %08x\n", color);
- color = getPixelColor(device, 160, 120); /* upper left quad */
- ok(color == 0x00ff0000, "Clear rectangle 1(pos, pos) has color %08x\n", color);
- color = getPixelColor(device, 480, 360); /* lower right quad */
- ok(color == 0x00ffffff, "Clear rectangle 4(NULL) has color %08x\n", color);
- color = getPixelColor(device, 480, 120); /* upper right quad */
- ok(color == 0x00ffffff, "Clear rectangle 4(neg, neg) has color %08x\n", color);
-}
-
static void fog_test(IDirect3DDevice7 *device)
{
HRESULT hr;
@@ -1681,7 +1635,6 @@ START_TEST(visual)
/* Now run the tests */
depth_clamp_test(Direct3DDevice);
- clear_test(Direct3DDevice);
fog_test(Direct3DDevice);
offscreen_test(Direct3DDevice);
test_blend(Direct3DDevice);
--
2.13.6