Signed-off-by: Paul Gofman gofmanp@gmail.com --- dlls/ddraw/tests/visual.c | 94 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+)
diff --git a/dlls/ddraw/tests/visual.c b/dlls/ddraw/tests/visual.c index 2cb1c89231..5ce751b5b5 100644 --- a/dlls/ddraw/tests/visual.c +++ b/dlls/ddraw/tests/visual.c @@ -1594,6 +1594,99 @@ static void DX1_BackBufferFlipTest(void) if (window) DestroyWindow(window); }
+static void alphatest_test(IDirect3DDevice7 *device) +{ +#define ALPHATEST_PASSED 0x0000ff00 +#define ALPHATEST_FAILED 0x00ff0000 + unsigned int i, j; + D3DCOLOR color; + 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}, + }; + + hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0f, 0); + ok(hr == D3D_OK, "IDirect3DDevice7_Clear failed, hr %#x.\n", hr); + hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE); + ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr %#x.\n", hr); + hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE); + ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr %#x.\n", hr); + hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHATESTENABLE, TRUE); + ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, 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, "IDirect3DDevice7_SetRenderState failed, hr %#x.\n", hr); + + hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, ALPHATEST_FAILED, 0.0f, 0); + ok(hr == D3D_OK, "IDirect3DDevice7_Clear failed, hr %#x.\n", hr); + hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHAREF, 0x70); + ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr %#x.\n", hr); + hr = IDirect3DDevice7_BeginScene(device); + ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed, hr %#x.\n", hr); + hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, + D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, ARRAY_SIZE(quad), 0); + ok(hr == D3D_OK, "IDirect3DDevice7_DrawPrimitive failed, hr %#x.\n", hr); + hr = IDirect3DDevice7_EndScene(device); + ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed, hr %#x.\n", hr); + color = getPixelColor(device, 320, 240); + ok(color_match(color, test_data[i].color_greater, 1), + "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, "IDirect3DDevice7_Clear failed, hr %#x.\n", hr); + hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHAREF, 0xff70); + ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr %#x.\n", hr); + hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ALPHAREF, &value); + ok(hr == D3D_OK, "IDirect3DDevice7_GetRenderState failed, hr %#x.\n", hr); + ok(value == 0xff70, "Unexpected D3DRS_ALPHAREF value %#x.\n", value); + hr = IDirect3DDevice7_BeginScene(device); + ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed, hr %#x.\n", hr); + hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, + D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, ARRAY_SIZE(quad), 0); + ok(hr == D3D_OK, "IDirect3DDevice7_DrawPrimitive failed, hr %#x.\n", hr); + hr = IDirect3DDevice7_EndScene(device); + ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed, hr %#x.\n", hr); + color = getPixelColor(device, 320, 240); + ok(color_match(color, test_data[i].color_greater, 1), + "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_SetRenderState(device, D3DRENDERSTATE_ALPHATESTENABLE, FALSE); + ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr %#x.\n", hr); +} + START_TEST(visual) { HRESULT hr; @@ -1640,6 +1733,7 @@ START_TEST(visual) test_blend(Direct3DDevice); rhw_zero_test(Direct3DDevice); cubemap_test(Direct3DDevice); + alphatest_test(Direct3DDevice);
releaseObjects(); /* release DX7 interfaces to test D3D1 */