From 1e154f5f840fb6ef517b5063feb74ecf080366bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20D=C3=B6singer?= Date: Sun, 5 Aug 2018 02:47:55 +0430 Subject: [PATCH] d3d8/tests: Add a test for D3DMCS_COLOR{1/2}. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stefan Dösinger Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/d3d8/tests/visual.c | 113 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/dlls/d3d8/tests/visual.c b/dlls/d3d8/tests/visual.c index 3379f072cc4..24481bd0533 100644 --- a/dlls/d3d8/tests/visual.c +++ b/dlls/d3d8/tests/visual.c @@ -10335,6 +10335,118 @@ done: DestroyWindow(window); } +static void test_color_vertex(void) +{ + IDirect3DDevice8 *device; + D3DMATERIAL8 material; + IDirect3D8 *d3d; + D3DCOLOR colour; + unsigned int i; + ULONG refcount; + HWND window; + HRESULT hr; + + /* The idea here is to set up ambient light parameters in a way that the + * ambient colour from the material is just passed through. The emissive + * colour is just passed through anyway. The sum of ambient + emissive + * should allow deduction of where the material colour came from. + * + * Note that in cases without a D3DFVF_DIFFUSE flag the first colour value + * in the struct will be fed into the specular vertex colour slot. */ + static const struct + { + DWORD fvf, color_vertex, ambient, emissive, result; + } + tests[] = + { + {D3DFVF_DIFFUSE | D3DFVF_SPECULAR, FALSE, D3DMCS_COLOR1, D3DMCS_COLOR2, 0x000000c0}, + + {D3DFVF_DIFFUSE | D3DFVF_SPECULAR, TRUE, D3DMCS_COLOR1, D3DMCS_COLOR2, 0x00ffff00}, + {D3DFVF_DIFFUSE | D3DFVF_SPECULAR, TRUE, D3DMCS_MATERIAL, D3DMCS_COLOR2, 0x0000ff80}, + {D3DFVF_DIFFUSE | D3DFVF_SPECULAR, TRUE, D3DMCS_COLOR1, D3DMCS_MATERIAL, 0x00ff0040}, + {D3DFVF_DIFFUSE | D3DFVF_SPECULAR, TRUE, D3DMCS_COLOR1, D3DMCS_COLOR1, 0x00ff0000}, + {D3DFVF_DIFFUSE | D3DFVF_SPECULAR, TRUE, D3DMCS_COLOR2, D3DMCS_COLOR2, 0x0000ff00}, + + {D3DFVF_SPECULAR, TRUE, D3DMCS_COLOR1, D3DMCS_COLOR2, 0x00ff0080}, + {D3DFVF_SPECULAR, TRUE, D3DMCS_COLOR1, D3DMCS_MATERIAL, 0x000000c0}, + {D3DFVF_SPECULAR, TRUE, D3DMCS_MATERIAL, D3DMCS_COLOR2, 0x00ff0080}, + {D3DFVF_DIFFUSE, TRUE, D3DMCS_COLOR1, D3DMCS_COLOR2, 0x00ff0040}, + {D3DFVF_DIFFUSE, TRUE, D3DMCS_COLOR1, D3DMCS_MATERIAL, 0x00ff0040}, + {D3DFVF_DIFFUSE, TRUE, D3DMCS_COLOR2, D3DMCS_MATERIAL, 0x000000c0}, + + {0, TRUE, D3DMCS_COLOR1, D3DMCS_COLOR2, 0x000000c0}, + }; + static const struct + { + struct vec3 position; + DWORD diffuse; + DWORD specular; + } + quad[] = + { + {{-1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff00ff00}, + {{-1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff00ff00}, + {{ 1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff00ff00}, + {{ 1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff00ff00}, + }; + + window = create_window(); + ok(!!window, "Failed to create a window.\n"); + + d3d = Direct3DCreate8(D3D_SDK_VERSION); + ok(!!d3d, "Failed to create a D3D object.\n"); + if (!(device = create_device(d3d, window, window, TRUE))) + { + skip("Failed to create a D3D device, skipping tests.\n"); + IDirect3D8_Release(d3d); + DestroyWindow(window); + return; + } + + hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, TRUE); + ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr); + hr = IDirect3DDevice8_SetRenderState(device, D3DRS_AMBIENT, 0xffffffff); + ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr); + + memset(&material, 0, sizeof(material)); + material.Ambient.b = 0.5f; + material.Emissive.b = 0.25f; + hr = IDirect3DDevice8_SetMaterial(device, &material); + ok(SUCCEEDED(hr), "Failed to set material, hr %#x\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + hr = IDirect3DDevice8_SetRenderState(device, D3DRS_COLORVERTEX, tests[i].color_vertex); + ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr); + hr = IDirect3DDevice8_SetRenderState(device, D3DRS_AMBIENTMATERIALSOURCE, tests[i].ambient); + ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr); + hr = IDirect3DDevice8_SetRenderState(device, D3DRS_EMISSIVEMATERIALSOURCE, tests[i].emissive); + ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr); + hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | tests[i].fvf); + ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr); + + hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x77777777, 0.0f, 0); + ok(SUCCEEDED(hr), "Failed to clear depth/stencil, hr %#x.\n", hr); + + hr = IDirect3DDevice8_BeginScene(device); + ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr); + hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad)); + ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr); + hr = IDirect3DDevice8_EndScene(device); + ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr); + + colour = getPixelColor(device, 320, 240); + ok(color_match(colour, tests[i].result, 1), + "Expected colour 0x%08x for test %u, got 0x%08x.\n", + tests[i].result, i, colour); + } + + refcount = IDirect3DDevice8_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); + IDirect3D8_Release(d3d); + DestroyWindow(window); +} + START_TEST(visual) { D3DADAPTER_IDENTIFIER8 identifier; @@ -10408,4 +10520,5 @@ START_TEST(visual) test_drawindexedprimitiveup(); test_map_synchronisation(); test_viewport(); + test_color_vertex(); }