Commit 399694ed authored by Stefan Dösinger's avatar Stefan Dösinger Committed by Alexandre Julliard

d3d9/tests: Add a test for D3DMCS_COLOR{1/2}.

parent 46d5d9a6
......@@ -24085,6 +24085,119 @@ done:
DestroyWindow(window);
}
static void test_color_vertex(void)
{
IDirect3DDevice9 *device;
D3DMATERIAL9 material;
IDirect3D9 *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 = Direct3DCreate9(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");
IDirect3D9_Release(d3d);
DestroyWindow(window);
return;
}
hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, TRUE);
ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
hr = IDirect3DDevice9_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 = IDirect3DDevice9_SetMaterial(device, &material);
ok(SUCCEEDED(hr), "Failed to set material, hr %#x\n", hr);
for (i = 0; i < ARRAY_SIZE(tests); ++i)
{
hr = IDirect3DDevice9_SetRenderState(device, D3DRS_COLORVERTEX, tests[i].color_vertex);
ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
hr = IDirect3DDevice9_SetRenderState(device, D3DRS_AMBIENTMATERIALSOURCE, tests[i].ambient);
ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
hr = IDirect3DDevice9_SetRenderState(device, D3DRS_EMISSIVEMATERIALSOURCE, tests[i].emissive);
ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | tests[i].fvf);
ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x77777777, 0.0f, 0);
ok(SUCCEEDED(hr), "Failed to clear depth/stencil, hr %#x.\n", hr);
hr = IDirect3DDevice9_BeginScene(device);
ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
hr = IDirect3DDevice9_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 = IDirect3DDevice9_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
IDirect3D9_Release(d3d);
DestroyWindow(window);
}
START_TEST(visual)
{
D3DADAPTER_IDENTIFIER9 identifier;
......@@ -24222,4 +24335,5 @@ START_TEST(visual)
test_mvp_software_vertex_shaders();
test_null_format();
test_map_synchronisation();
test_color_vertex();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment