From: Paul Gofman <gofmanp(a)gmail.com>
Signed-off-by: Paul Gofman <gofmanp(a)gmail.com>
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
---
dlls/ddraw/tests/ddraw1.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++
dlls/ddraw/tests/ddraw2.c | 127 ++++++++++++++++++++++++++++++++++
dlls/ddraw/tests/ddraw4.c | 118 ++++++++++++++++++++++++++++++++
dlls/ddraw/tests/ddraw7.c | 111 ++++++++++++++++++++++++++++++
4 files changed, 526 insertions(+)
diff --git a/dlls/ddraw/tests/ddraw1.c b/dlls/ddraw/tests/ddraw1.c
index 1f7e2ce04e7..680738eb47c 100644
--- a/dlls/ddraw/tests/ddraw1.c
+++ b/dlls/ddraw/tests/ddraw1.c
@@ -12124,6 +12124,175 @@ static void test_gdi_surface(void)
DestroyWindow(window);
}
+static void test_alphatest(void)
+{
+#define ALPHATEST_PASSED 0x0000ff00
+#define ALPHATEST_FAILED 0x00ff0000
+ D3DRECT rect_full = {{0}, {0}, {640}, {480}};
+ IDirect3DExecuteBuffer *execute_buffer;
+ IDirect3DMaterial *blue, *failed;
+ D3DEXECUTEBUFFERDESC exec_desc;
+ IDirect3DViewport *viewport;
+ IDirect3DDevice *device;
+ IDirectDrawSurface *rt;
+ IDirectDraw *ddraw;
+ UINT inst_length;
+ unsigned int i;
+ D3DCOLOR color;
+ ULONG refcount;
+ HWND window;
+ HRESULT hr;
+ void *ptr;
+
+ static const struct
+ {
+ D3DCMPFUNC func;
+ D3DCOLOR color_less;
+ D3DCOLOR color_equal;
+ D3DCOLOR color_greater;
+ }
+ test_data[] =
+ {
+ {D3DCMP_NEVER, ALPHATEST_FAILED, ALPHATEST_FAILED, ALPHATEST_FAILED},
+ {D3DCMP_LESS, ALPHATEST_PASSED, ALPHATEST_FAILED, ALPHATEST_FAILED},
+ {D3DCMP_EQUAL, ALPHATEST_FAILED, ALPHATEST_PASSED, ALPHATEST_FAILED},
+ {D3DCMP_LESSEQUAL, ALPHATEST_PASSED, ALPHATEST_PASSED, ALPHATEST_FAILED},
+ {D3DCMP_GREATER, ALPHATEST_FAILED, ALPHATEST_FAILED, ALPHATEST_PASSED},
+ {D3DCMP_NOTEQUAL, ALPHATEST_PASSED, ALPHATEST_FAILED, ALPHATEST_PASSED},
+ {D3DCMP_GREATEREQUAL, ALPHATEST_FAILED, ALPHATEST_PASSED, ALPHATEST_PASSED},
+ {D3DCMP_ALWAYS, ALPHATEST_PASSED, ALPHATEST_PASSED, ALPHATEST_PASSED},
+ };
+ static D3DLVERTEX quad[] =
+ {
+ {{-1.0f}, {-1.0f}, {0.1f}, 0, {ALPHATEST_PASSED | 0x80000000}},
+ {{-1.0f}, { 1.0f}, {0.1f}, 0, {ALPHATEST_PASSED | 0x80000000}},
+ {{ 1.0f}, {-1.0f}, {0.1f}, 0, {ALPHATEST_PASSED | 0x80000000}},
+ {{ 1.0f}, { 1.0f}, {0.1f}, 0, {ALPHATEST_PASSED | 0x80000000}},
+ };
+
+ 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.\n");
+ IDirectDraw_Release(ddraw);
+ DestroyWindow(window);
+ return;
+ }
+ hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ blue = create_diffuse_material(device, 0.0f, 0.0f, 1.0f, 1.0f);
+ failed = create_diffuse_material(device, 1.0f, 0.0f, 0.0f, 1.0f);
+
+ viewport = create_viewport(device, 0, 0, 640, 480);
+
+ viewport_set_background(device, viewport, blue);
+ hr = IDirect3DViewport_Clear(viewport, 1, &rect_full, D3DCLEAR_TARGET);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ memset(&exec_desc, 0, sizeof(exec_desc));
+ exec_desc.dwSize = sizeof(exec_desc);
+ exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
+ exec_desc.dwBufferSize = 1024;
+ exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
+
+ hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ ptr = exec_desc.lpData;
+ emit_set_rs(&ptr, D3DRENDERSTATE_LIGHTING, FALSE);
+ emit_set_rs(&ptr, D3DRENDERSTATE_ZENABLE, FALSE);
+ emit_set_rs(&ptr, D3DRENDERSTATE_ALPHATESTENABLE, TRUE);
+ emit_end(&ptr);
+ inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
+
+ hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ set_execute_data(execute_buffer, 0, 0, inst_length);
+ hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ viewport_set_background(device, viewport, failed);
+ for (i = 0; i < ARRAY_SIZE(test_data); ++i)
+ {
+ hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ memcpy(exec_desc.lpData, quad, sizeof(quad));
+ ptr = ((BYTE *)exec_desc.lpData) + sizeof(quad);
+ emit_set_rs(&ptr, D3DRENDERSTATE_ALPHAFUNC, test_data[i].func);
+ emit_set_rs(&ptr, D3DRENDERSTATE_ALPHAREF, 0x70);
+ emit_process_vertices(&ptr, D3DPROCESSVERTICES_TRANSFORM, 0, ARRAY_SIZE(quad));
+ emit_tquad(&ptr, 0);
+ emit_end(&ptr);
+ inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
+ inst_length -= sizeof(quad);
+
+ hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DViewport_Clear(viewport, 1, &rect_full, D3DCLEAR_TARGET);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice_BeginScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ set_execute_data(execute_buffer, ARRAY_SIZE(quad), sizeof(quad), inst_length);
+ hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice_EndScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ color = get_surface_color(rt, 320, 240);
+ ok(compare_color(color, test_data[i].color_greater, 0),
+ "Alphatest failed, color 0x%08x, expected 0x%08x, alpha > ref, func %u.\n",
+ color, test_data[i].color_greater, test_data[i].func);
+
+ hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ memcpy(exec_desc.lpData, quad, sizeof(quad));
+ ptr = ((BYTE *)exec_desc.lpData) + sizeof(quad);
+ emit_set_rs(&ptr, D3DRENDERSTATE_ALPHAREF, 0xff70);
+ emit_process_vertices(&ptr, D3DPROCESSVERTICES_TRANSFORM, 0, ARRAY_SIZE(quad));
+ emit_tquad(&ptr, 0);
+ emit_end(&ptr);
+ inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
+ inst_length -= sizeof(quad);
+
+ hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DViewport_Clear(viewport, 1, &rect_full, D3DCLEAR_TARGET);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice_BeginScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ set_execute_data(execute_buffer, ARRAY_SIZE(quad), sizeof(quad), inst_length);
+ hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice_EndScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ color = get_surface_color(rt, 320, 240);
+ ok(compare_color(color, test_data[i].color_greater, 0),
+ "Alphatest failed, color 0x%08x, expected 0x%08x, alpha > ref, func %u.\n",
+ color, test_data[i].color_greater, test_data[i].func);
+ }
+
+ IDirect3DExecuteBuffer_Release(execute_buffer);
+ destroy_viewport(device, viewport);
+ destroy_material(failed);
+ destroy_material(blue);
+ IDirectDrawSurface_Release(rt);
+ refcount = IDirect3DDevice_Release(device);
+ ok(!refcount, "Device has %u references left.\n", refcount);
+ refcount = IDirectDraw_Release(ddraw);
+ ok(!refcount, "DirectDraw has %u references left.\n", refcount);
+ DestroyWindow(window);
+}
+
START_TEST(ddraw1)
{
DDDEVICEIDENTIFIER identifier;
@@ -12231,4 +12400,5 @@ START_TEST(ddraw1)
test_find_device();
test_killfocus();
test_gdi_surface();
+ test_alphatest();
}
diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c
index 842870d7d78..3dda289ad1f 100644
--- a/dlls/ddraw/tests/ddraw2.c
+++ b/dlls/ddraw/tests/ddraw2.c
@@ -13425,6 +13425,132 @@ static void test_gdi_surface(void)
DestroyWindow(window);
}
+static void test_alphatest(void)
+{
+#define ALPHATEST_PASSED 0x0000ff00
+#define ALPHATEST_FAILED 0x00ff0000
+ D3DRECT rect_full = {{0}, {0}, {640}, {480}};
+ IDirect3DMaterial2 *blue, *failed;
+ IDirect3DViewport2 *viewport;
+ IDirect3DDevice2 *device;
+ IDirectDrawSurface *rt;
+ IDirectDraw2 *ddraw;
+ unsigned int i;
+ D3DCOLOR color;
+ ULONG refcount;
+ HWND window;
+ DWORD value;
+ HRESULT hr;
+
+ static const struct
+ {
+ D3DCMPFUNC func;
+ D3DCOLOR color_less;
+ D3DCOLOR color_equal;
+ D3DCOLOR color_greater;
+ }
+ test_data[] =
+ {
+ {D3DCMP_NEVER, ALPHATEST_FAILED, ALPHATEST_FAILED, ALPHATEST_FAILED},
+ {D3DCMP_LESS, ALPHATEST_PASSED, ALPHATEST_FAILED, ALPHATEST_FAILED},
+ {D3DCMP_EQUAL, ALPHATEST_FAILED, ALPHATEST_PASSED, ALPHATEST_FAILED},
+ {D3DCMP_LESSEQUAL, ALPHATEST_PASSED, ALPHATEST_PASSED, ALPHATEST_FAILED},
+ {D3DCMP_GREATER, ALPHATEST_FAILED, ALPHATEST_FAILED, ALPHATEST_PASSED},
+ {D3DCMP_NOTEQUAL, ALPHATEST_PASSED, ALPHATEST_FAILED, ALPHATEST_PASSED},
+ {D3DCMP_GREATEREQUAL, ALPHATEST_FAILED, ALPHATEST_PASSED, ALPHATEST_PASSED},
+ {D3DCMP_ALWAYS, ALPHATEST_PASSED, ALPHATEST_PASSED, ALPHATEST_PASSED},
+ };
+ static D3DLVERTEX quad[] =
+ {
+ {{-1.0f}, {-1.0f}, {0.1f}, 0, {ALPHATEST_PASSED | 0x80000000}},
+ {{-1.0f}, { 1.0f}, {0.1f}, 0, {ALPHATEST_PASSED | 0x80000000}},
+ {{ 1.0f}, {-1.0f}, {0.1f}, 0, {ALPHATEST_PASSED | 0x80000000}},
+ {{ 1.0f}, { 1.0f}, {0.1f}, 0, {ALPHATEST_PASSED | 0x80000000}},
+ };
+
+ 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.\n");
+ IDirectDraw2_Release(ddraw);
+ DestroyWindow(window);
+ return;
+ }
+ hr = IDirect3DDevice2_GetRenderTarget(device, &rt);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ blue = create_diffuse_material(device, 0.0f, 0.0f, 1.0f, 1.0f);
+ failed = create_diffuse_material(device, 1.0f, 0.0f, 0.0f, 1.0f);
+
+ viewport = create_viewport(device, 0, 0, 640, 480);
+ hr = IDirect3DDevice2_SetCurrentViewport(device, viewport);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ viewport_set_background(device, viewport, blue);
+ hr = IDirect3DViewport2_Clear(viewport, 1, &rect_full, D3DCLEAR_TARGET);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice2_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice2_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice2_SetRenderState(device, D3DRENDERSTATE_ALPHATESTENABLE, TRUE);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ viewport_set_background(device, viewport, failed);
+ for (i = 0; i < ARRAY_SIZE(test_data); ++i)
+ {
+ hr = IDirect3DDevice2_SetRenderState(device, D3DRENDERSTATE_ALPHAFUNC, test_data[i].func);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DViewport2_Clear(viewport, 1, &rect_full, D3DCLEAR_TARGET);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice2_SetRenderState(device, D3DRENDERSTATE_ALPHAREF, 0x70);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice2_BeginScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice2_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
+ D3DVT_LVERTEX, quad, ARRAY_SIZE(quad), 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice2_EndScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ color = get_surface_color(rt, 320, 240);
+ ok(compare_color(color, test_data[i].color_greater, 0),
+ "Alphatest failed, color 0x%08x, expected 0x%08x, alpha > ref, func %u.\n",
+ color, test_data[i].color_greater, test_data[i].func);
+
+ hr = IDirect3DViewport2_Clear(viewport, 1, &rect_full, D3DCLEAR_TARGET);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice2_SetRenderState(device, D3DRENDERSTATE_ALPHAREF, 0xff70);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice2_GetRenderState(device, D3DRENDERSTATE_ALPHAREF, &value);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ ok(value == 0xff70, "Got unexpected value %#x.\n", value);
+ hr = IDirect3DDevice2_BeginScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice2_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
+ D3DVT_LVERTEX, quad, ARRAY_SIZE(quad), 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice2_EndScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ color = get_surface_color(rt, 320, 240);
+ ok(compare_color(color, test_data[i].color_greater, 0),
+ "Alphatest failed, color 0x%08x, expected 0x%08x, alpha > ref, func %u.\n",
+ color, test_data[i].color_greater, test_data[i].func);
+ }
+
+ destroy_viewport(device, viewport);
+ destroy_material(failed);
+ destroy_material(blue);
+ IDirectDrawSurface_Release(rt);
+ refcount = IDirect3DDevice2_Release(device);
+ ok(!refcount, "Device has %u references left.\n", refcount);
+ refcount = IDirectDraw2_Release(ddraw);
+ ok(!refcount, "DirectDraw has %u references left.\n", refcount);
+ DestroyWindow(window);
+}
+
START_TEST(ddraw2)
{
DDDEVICEIDENTIFIER identifier;
@@ -13540,4 +13666,5 @@ START_TEST(ddraw2)
test_find_device();
test_killfocus();
test_gdi_surface();
+ test_alphatest();
}
diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c
index bb4d63a928d..bed5acdb135 100644
--- a/dlls/ddraw/tests/ddraw4.c
+++ b/dlls/ddraw/tests/ddraw4.c
@@ -15680,6 +15680,123 @@ static void test_gdi_surface(void)
DestroyWindow(window);
}
+static void test_alphatest(void)
+{
+#define ALPHATEST_PASSED 0x0000ff00
+#define ALPHATEST_FAILED 0x00ff0000
+ D3DRECT rect_full = {{0}, {0}, {640}, {480}};
+ IDirect3DViewport3 *viewport;
+ IDirect3DDevice3 *device;
+ IDirectDrawSurface4 *rt;
+ unsigned int i;
+ D3DCOLOR color;
+ ULONG refcount;
+ HWND window;
+ DWORD value;
+ HRESULT hr;
+
+ static const struct
+ {
+ D3DCMPFUNC func;
+ D3DCOLOR color_less;
+ D3DCOLOR color_equal;
+ D3DCOLOR color_greater;
+ }
+ test_data[] =
+ {
+ {D3DCMP_NEVER, ALPHATEST_FAILED, ALPHATEST_FAILED, ALPHATEST_FAILED},
+ {D3DCMP_LESS, ALPHATEST_PASSED, ALPHATEST_FAILED, ALPHATEST_FAILED},
+ {D3DCMP_EQUAL, ALPHATEST_FAILED, ALPHATEST_PASSED, ALPHATEST_FAILED},
+ {D3DCMP_LESSEQUAL, ALPHATEST_PASSED, ALPHATEST_PASSED, ALPHATEST_FAILED},
+ {D3DCMP_GREATER, ALPHATEST_FAILED, ALPHATEST_FAILED, ALPHATEST_PASSED},
+ {D3DCMP_NOTEQUAL, ALPHATEST_PASSED, ALPHATEST_FAILED, ALPHATEST_PASSED},
+ {D3DCMP_GREATEREQUAL, ALPHATEST_FAILED, ALPHATEST_PASSED, ALPHATEST_PASSED},
+ {D3DCMP_ALWAYS, ALPHATEST_PASSED, ALPHATEST_PASSED, ALPHATEST_PASSED},
+ };
+ static struct
+ {
+ struct vec3 position;
+ DWORD diffuse;
+ }
+ quad[] =
+ {
+ {{-1.0f, -1.0f, 0.1f}, ALPHATEST_PASSED | 0x80000000},
+ {{-1.0f, 1.0f, 0.1f}, ALPHATEST_PASSED | 0x80000000},
+ {{ 1.0f, -1.0f, 0.1f}, ALPHATEST_PASSED | 0x80000000},
+ {{ 1.0f, 1.0f, 0.1f}, ALPHATEST_PASSED | 0x80000000},
+ };
+
+ window = create_window();
+ if (!(device = create_device(window, DDSCL_NORMAL)))
+ {
+ skip("Failed to create a 3D device.\n");
+ DestroyWindow(window);
+ return;
+ }
+ hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ viewport = create_viewport(device, 0, 0, 640, 480);
+ hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DViewport3_Clear2(viewport, 1, &rect_full, D3DCLEAR_TARGET, 0xff0000ff, 0.0f, 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHATESTENABLE, TRUE);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ for (i = 0; i < ARRAY_SIZE(test_data); ++i)
+ {
+ hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHAFUNC, test_data[i].func);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DViewport3_Clear2(viewport, 1, &rect_full, D3DCLEAR_TARGET, ALPHATEST_FAILED, 0.0f, 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHAREF, 0x70);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice3_BeginScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
+ D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, ARRAY_SIZE(quad), 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice3_EndScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ color = get_surface_color(rt, 320, 240);
+ ok(compare_color(color, test_data[i].color_greater, 0),
+ "Alphatest failed, color 0x%08x, expected 0x%08x, alpha > ref, func %u.\n",
+ color, test_data[i].color_greater, test_data[i].func);
+
+ hr = IDirect3DViewport3_Clear2(viewport, 1, &rect_full, D3DCLEAR_TARGET, ALPHATEST_FAILED, 0.0f, 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHAREF, 0xff70);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ALPHAREF, &value);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ ok(value == 0xff70, "Got unexpected value %#x.\n", value);
+ hr = IDirect3DDevice3_BeginScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
+ D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, ARRAY_SIZE(quad), 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice3_EndScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ color = get_surface_color(rt, 320, 240);
+ ok(compare_color(color, test_data[i].color_greater, 0),
+ "Alphatest failed, color 0x%08x, expected 0x%08x, alpha > ref, func %u.\n",
+ color, test_data[i].color_greater, test_data[i].func);
+ }
+
+ destroy_viewport(device, viewport);
+ IDirectDrawSurface4_Release(rt);
+ refcount = IDirect3DDevice3_Release(device);
+ ok(!refcount, "Device has %u references left.\n", refcount);
+ DestroyWindow(window);
+}
+
START_TEST(ddraw4)
{
DDDEVICEIDENTIFIER identifier;
@@ -15810,4 +15927,5 @@ START_TEST(ddraw4)
test_killfocus();
test_sysmem_draw();
test_gdi_surface();
+ test_alphatest();
}
diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c
index a0637917708..c3ffa45de62 100644
--- a/dlls/ddraw/tests/ddraw7.c
+++ b/dlls/ddraw/tests/ddraw7.c
@@ -15489,6 +15489,116 @@ static void test_multiply_transform(void)
DestroyWindow(window);
}
+static void test_alphatest(void)
+{
+#define ALPHATEST_PASSED 0x0000ff00
+#define ALPHATEST_FAILED 0x00ff0000
+ IDirect3DDevice7 *device;
+ IDirectDrawSurface7 *rt;
+ unsigned int i;
+ D3DCOLOR color;
+ ULONG refcount;
+ HWND window;
+ DWORD value;
+ HRESULT hr;
+
+ static const struct
+ {
+ D3DCMPFUNC func;
+ D3DCOLOR color_less;
+ D3DCOLOR color_equal;
+ D3DCOLOR color_greater;
+ }
+ test_data[] =
+ {
+ {D3DCMP_NEVER, ALPHATEST_FAILED, ALPHATEST_FAILED, ALPHATEST_FAILED},
+ {D3DCMP_LESS, ALPHATEST_PASSED, ALPHATEST_FAILED, ALPHATEST_FAILED},
+ {D3DCMP_EQUAL, ALPHATEST_FAILED, ALPHATEST_PASSED, ALPHATEST_FAILED},
+ {D3DCMP_LESSEQUAL, ALPHATEST_PASSED, ALPHATEST_PASSED, ALPHATEST_FAILED},
+ {D3DCMP_GREATER, ALPHATEST_FAILED, ALPHATEST_FAILED, ALPHATEST_PASSED},
+ {D3DCMP_NOTEQUAL, ALPHATEST_PASSED, ALPHATEST_FAILED, ALPHATEST_PASSED},
+ {D3DCMP_GREATEREQUAL, ALPHATEST_FAILED, ALPHATEST_PASSED, ALPHATEST_PASSED},
+ {D3DCMP_ALWAYS, ALPHATEST_PASSED, ALPHATEST_PASSED, ALPHATEST_PASSED},
+ };
+ static struct
+ {
+ struct vec3 position;
+ DWORD diffuse;
+ }
+ quad[] =
+ {
+ {{-1.0f, -1.0f, 0.1f}, ALPHATEST_PASSED | 0x80000000},
+ {{-1.0f, 1.0f, 0.1f}, ALPHATEST_PASSED | 0x80000000},
+ {{ 1.0f, -1.0f, 0.1f}, ALPHATEST_PASSED | 0x80000000},
+ {{ 1.0f, 1.0f, 0.1f}, ALPHATEST_PASSED | 0x80000000},
+ };
+
+ window = create_window();
+ if (!(device = create_device(window, DDSCL_NORMAL)))
+ {
+ skip("Failed to create a 3D device.\n");
+ DestroyWindow(window);
+ return;
+ }
+ hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0f, 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHATESTENABLE, TRUE);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ for (i = 0; i < ARRAY_SIZE(test_data); ++i)
+ {
+ hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHAFUNC, test_data[i].func);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, ALPHATEST_FAILED, 0.0f, 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHAREF, 0x70);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice7_BeginScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
+ D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, ARRAY_SIZE(quad), 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice7_EndScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ color = get_surface_color(rt, 320, 240);
+ ok(compare_color(color, test_data[i].color_greater, 0),
+ "Alphatest failed, color 0x%08x, expected 0x%08x, alpha > ref, func %u.\n",
+ color, test_data[i].color_greater, test_data[i].func);
+
+ hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, ALPHATEST_FAILED, 0.0f, 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHAREF, 0xff70);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ALPHAREF, &value);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ ok(value == 0xff70, "Got unexpected value %#x.\n", value);
+ hr = IDirect3DDevice7_BeginScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
+ D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, ARRAY_SIZE(quad), 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice7_EndScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ color = get_surface_color(rt, 320, 240);
+ ok(compare_color(color, test_data[i].color_greater, 0),
+ "Alphatest failed, color 0x%08x, expected 0x%08x, alpha > ref, func %u.\n",
+ color, test_data[i].color_greater, test_data[i].func);
+ }
+
+ IDirectDrawSurface7_Release(rt);
+ refcount = IDirect3DDevice7_Release(device);
+ ok(!refcount, "Device has %u references left.\n", refcount);
+ DestroyWindow(window);
+}
+
START_TEST(ddraw7)
{
DDDEVICEIDENTIFIER2 identifier;
@@ -15631,4 +15741,5 @@ START_TEST(ddraw7)
test_sysmem_draw();
test_gdi_surface();
test_multiply_transform();
+ test_alphatest();
}
--
2.11.0