Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/ddraw/tests/ddraw7.c | 279 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 279 insertions(+)
diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c index 3dca4dc2da..3867b6992b 100644 --- a/dlls/ddraw/tests/ddraw7.c +++ b/dlls/ddraw/tests/ddraw7.c @@ -16555,6 +16555,284 @@ static void test_material_state(void) DestroyWindow(window); }
+#define check_light(a, b, c, d) check_light_(__LINE__, a, b, c, d) +static void check_light_(int line, IDirect3DDevice7 *device, DWORD index, + const D3DLIGHT7 *expected_params, BOOL expected_enabled) +{ + D3DLIGHT7 params; + BOOL enabled; + HRESULT hr; + + hr = IDirect3DDevice7_GetLight(device, index, ¶ms); + if (expected_params) + { + ok_(__FILE__, line)(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + todo_wine_if(memcmp(¶ms, expected_params, sizeof(params))) + ok_(__FILE__, line)(!memcmp(¶ms, expected_params, sizeof(params)), "Light didn't match.\n"); + } + else + { + ok_(__FILE__, line)(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr); + } + + hr = IDirect3DDevice7_GetLightEnable(device, index, &enabled); + if (expected_params) + { + ok_(__FILE__, line)(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + todo_wine_if(enabled != expected_enabled) + ok_(__FILE__, line)(enabled == expected_enabled, "Got enabled %u, expected %u.\n", enabled, expected_enabled); + } + else + { + ok_(__FILE__, line)(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr); + } +} + +static void test_light_state(void) +{ + D3DLIGHT7 light1, light2, default_light = {}, empty_light = {}; + IDirect3DDevice7 *device; + DWORD stateblock; + ULONG refcount; + HWND window; + HRESULT hr; + + window = create_window(); + if (!(device = create_device(window, DDSCL_NORMAL))) + { + skip("Failed to create 3D device.\n"); + DestroyWindow(window); + return; + } + + default_light.dltType = D3DLIGHT_DIRECTIONAL; + U1(default_light.dcvDiffuse).r = 1.0f; + U2(default_light.dcvDiffuse).g = 1.0f; + U3(default_light.dcvDiffuse).b = 1.0f; + default_light.dvDirection.z = 1.0f; + light1 = light2 = default_light; + light1.dltType = D3DLIGHT_POINT; + light2.dltType = D3DLIGHT_SPOT; + + check_light(device, 0, NULL, 0); + + hr = IDirect3DDevice7_SetLight(device, 0, &light1); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + check_light(device, 0, &light1, 0); + + hr = IDirect3DDevice7_LightEnable(device, 0, TRUE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + check_light(device, 0, &light1, 128); + + hr = IDirect3DDevice7_LightEnable(device, 1, TRUE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + check_light(device, 1, &default_light, 128); + + hr = IDirect3DDevice7_LightEnable(device, 2, FALSE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + check_light(device, 2, &default_light, 0); + + hr = IDirect3DDevice7_SetLight(device, 1, &light1); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + check_light(device, 1, &light1, 128); + + hr = IDirect3DDevice7_SetLight(device, 4, &light1); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + check_light(device, 4, &light1, 0); + + hr = IDirect3DDevice7_BeginStateBlock(device); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice7_SetLight(device, 0, &light2); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_SetLight(device, 3, &light2); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_LightEnable(device, 4, TRUE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_LightEnable(device, 5, TRUE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice7_EndStateBlock(device, &stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + check_light(device, 0, &light1, 128); + check_light(device, 1, &light1, 128); + check_light(device, 2, &default_light, 0); + check_light(device, 3, NULL, 0); + check_light(device, 4, &light1, 0); + check_light(device, 5, NULL, 0); + + hr = IDirect3DDevice7_ApplyStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + check_light(device, 0, &light2, 128); + check_light(device, 3, &light2, 0); + check_light(device, 4, &light1, 128); + check_light(device, 5, &default_light, 128); + + hr = IDirect3DDevice7_SetLight(device, 0, &light1); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_LightEnable(device, 0, TRUE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_SetLight(device, 3, &light1); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_LightEnable(device, 3, TRUE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_SetLight(device, 4, &light2); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_LightEnable(device, 4, FALSE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_SetLight(device, 5, &light2); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_LightEnable(device, 5, FALSE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice7_CaptureStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice7_SetLight(device, 0, &light2); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_LightEnable(device, 0, FALSE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_SetLight(device, 3, &light2); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_LightEnable(device, 3, FALSE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_SetLight(device, 4, &light1); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_LightEnable(device, 4, TRUE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_SetLight(device, 5, &light1); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_LightEnable(device, 5, TRUE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice7_ApplyStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + check_light(device, 0, &light1, 0); + check_light(device, 3, &light1, 0); + check_light(device, 4, &light1, 0); + check_light(device, 5, &light1, 0); + + /* Test trying to capture an unset light. */ + + hr = IDirect3DDevice7_BeginStateBlock(device); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice7_SetLight(device, 6, &light1); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_LightEnable(device, 7, TRUE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice7_EndStateBlock(device, &stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + check_light(device, 6, NULL, 0); + check_light(device, 7, NULL, 0); + + hr = IDirect3DDevice7_CaptureStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice7_ApplyStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + check_light(device, 6, &empty_light, 0); + check_light(device, 7, &default_light, 0); + + hr = IDirect3DDevice7_CreateStateBlock(device, D3DSBT_VERTEXSTATE, &stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice7_SetLight(device, 0, &light2); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_LightEnable(device, 0, TRUE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_SetLight(device, 8, &light2); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_LightEnable(device, 8, TRUE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice7_ApplyStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + check_light(device, 0, &light2, 0); + check_light(device, 8, &light2, 128); + + hr = IDirect3DDevice7_CaptureStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice7_SetLight(device, 0, &light1); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_LightEnable(device, 0, TRUE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_SetLight(device, 8, &light1); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_LightEnable(device, 8, FALSE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice7_ApplyStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + check_light(device, 0, &light1, 0); + check_light(device, 8, &light1, 0); + + hr = IDirect3DDevice7_CreateStateBlock(device, D3DSBT_PIXELSTATE, &stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice7_SetLight(device, 0, &light2); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_LightEnable(device, 0, TRUE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice7_ApplyStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + check_light(device, 0, &light2, 128); + + hr = IDirect3DDevice7_SetLight(device, 0, &light1); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_LightEnable(device, 0, FALSE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice7_CreateStateBlock(device, D3DSBT_ALL, &stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice7_SetLight(device, 0, &light2); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_LightEnable(device, 0, TRUE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_SetLight(device, 9, &light2); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_LightEnable(device, 9, TRUE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice7_ApplyStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + check_light(device, 0, &light1, 0); + check_light(device, 9, &light2, 128); + + hr = IDirect3DDevice7_CaptureStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice7_SetLight(device, 0, &light2); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_LightEnable(device, 0, TRUE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_SetLight(device, 9, &light1); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice7_LightEnable(device, 9, FALSE); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice7_ApplyStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + check_light(device, 0, &light1, 0); + check_light(device, 9, &light1, 0); + + refcount = IDirect3DDevice7_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); + DestroyWindow(window); +} + START_TEST(ddraw7) { DDDEVICEIDENTIFIER2 identifier; @@ -16703,4 +16981,5 @@ START_TEST(ddraw7) test_transform_state(); test_viewport_state(); test_material_state(); + test_light_state(); }