Signed-off-by: Zebediah Figura z.figura12@gmail.com --- This is essentially a proposal for a new manner of testing stateblocks. I find this distinctly easier to read than existing stateblock tests for d3d8/9. It also is more flexible for testing interactions between different states (e.g. light parameters / enabled state in patch 4/4). If this is preferred I would also propose to port d3d8/9 stateblock tests to this structure.
dlls/ddraw/tests/ddraw7.c | 316 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 316 insertions(+)
diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c index 5f066a6257..69eba24f99 100644 --- a/dlls/ddraw/tests/ddraw7.c +++ b/dlls/ddraw/tests/ddraw7.c @@ -15893,6 +15893,321 @@ static void test_begin_end_state_block(void) DestroyWindow(window); }
+static void test_transform_state(void) +{ + D3DMATRIX mat1, mat2, ret_mat; + IDirect3DDevice7 *device; + DWORD stateblock; + unsigned int i; + ULONG refcount; + HWND window; + HRESULT hr; + + static const D3DTRANSFORMSTATETYPE tests[] = + { + D3DTRANSFORMSTATE_WORLD, + D3DTRANSFORMSTATE_VIEW, + D3DTRANSFORMSTATE_PROJECTION, + D3DTRANSFORMSTATE_WORLD1, + D3DTRANSFORMSTATE_WORLD2, + D3DTRANSFORMSTATE_WORLD3, + D3DTRANSFORMSTATE_TEXTURE0, + D3DTRANSFORMSTATE_TEXTURE1, + D3DTRANSFORMSTATE_TEXTURE2, + D3DTRANSFORMSTATE_TEXTURE3, + D3DTRANSFORMSTATE_TEXTURE4, + D3DTRANSFORMSTATE_TEXTURE5, + D3DTRANSFORMSTATE_TEXTURE6, + D3DTRANSFORMSTATE_TEXTURE7, + }; + + static const D3DMATRIX identity = + { + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f + }; + + window = create_window(); + if (!(device = create_device(window, DDSCL_NORMAL))) + { + skip("Failed to create 3D device.\n"); + DestroyWindow(window); + return; + } + + memset(&mat1, 0x11, sizeof(mat1)); + memset(&mat2, 0x22, sizeof(mat2)); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + hr = IDirect3DDevice7_GetTransform(device, tests[i], &ret_mat); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + ok(!memcmp(&ret_mat, &identity, sizeof(identity)), "Test %u: Got unexpected transform matrix.\n", tests[i]); + + hr = IDirect3DDevice7_SetTransform(device, tests[i], &mat1); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + + hr = IDirect3DDevice7_GetTransform(device, tests[i], &ret_mat); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + ok(!memcmp(&ret_mat, &mat1, sizeof(mat1)), "Test %u: Got unexpected transform matrix.\n", tests[i]); + } + + /* Recorded stateblock, even states. */ + + hr = IDirect3DDevice7_BeginStateBlock(device); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + if (i % 2) + { + hr = IDirect3DDevice7_SetTransform(device, tests[i], &mat2); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + } + } + + hr = IDirect3DDevice7_EndStateBlock(device, &stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + hr = IDirect3DDevice7_GetTransform(device, tests[i], &ret_mat); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + ok(!memcmp(&ret_mat, &mat1, sizeof(mat1)), "Test %u: Got unexpected transform matrix.\n", tests[i]); + } + + hr = IDirect3DDevice7_ApplyStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + hr = IDirect3DDevice7_GetTransform(device, tests[i], &ret_mat); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + ok(!memcmp(&ret_mat, (i % 2) ? &mat2 : &mat1, sizeof(mat1)), + "Test %u: Got unexpected transform matrix.\n", tests[i]); + + hr = IDirect3DDevice7_SetTransform(device, tests[i], &mat1); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + } + + hr = IDirect3DDevice7_CaptureStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + hr = IDirect3DDevice7_SetTransform(device, tests[i], &mat2); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + } + + hr = IDirect3DDevice7_ApplyStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + hr = IDirect3DDevice7_GetTransform(device, tests[i], &ret_mat); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + ok(!memcmp(&ret_mat, (i % 2) ? &mat1 : &mat2, sizeof(mat1)), + "Test %u: Got unexpected transform matrix.\n", tests[i]); + + hr = IDirect3DDevice7_SetTransform(device, tests[i], &mat1); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + } + + /* Recorded stateblock, odd states. */ + + hr = IDirect3DDevice7_BeginStateBlock(device); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + if (!(i % 2)) + { + hr = IDirect3DDevice7_SetTransform(device, tests[i], &mat2); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + } + } + + hr = IDirect3DDevice7_EndStateBlock(device, &stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + hr = IDirect3DDevice7_GetTransform(device, tests[i], &ret_mat); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + ok(!memcmp(&ret_mat, &mat1, sizeof(mat1)), "Test %u: Got unexpected transform matrix.\n", tests[i]); + } + + hr = IDirect3DDevice7_ApplyStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + hr = IDirect3DDevice7_GetTransform(device, tests[i], &ret_mat); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + ok(!memcmp(&ret_mat, (i % 2) ? &mat1 : &mat2, sizeof(mat1)), + "Test %u: Got unexpected transform matrix.\n", tests[i]); + + hr = IDirect3DDevice7_SetTransform(device, tests[i], &mat1); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + } + + hr = IDirect3DDevice7_CaptureStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + hr = IDirect3DDevice7_SetTransform(device, tests[i], &mat2); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + } + + hr = IDirect3DDevice7_ApplyStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + hr = IDirect3DDevice7_GetTransform(device, tests[i], &ret_mat); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + ok(!memcmp(&ret_mat, (i % 2) ? &mat2 : &mat1, sizeof(mat1)), + "Test %u: Got unexpected transform matrix.\n", tests[i]); + + hr = IDirect3DDevice7_SetTransform(device, tests[i], &mat1); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + } + + /* Predefined stateblock, D3DSBT_ALL. */ + + hr = IDirect3DDevice7_CreateStateBlock(device, D3DSBT_ALL, &stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + hr = IDirect3DDevice7_SetTransform(device, tests[i], &mat2); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + } + + hr = IDirect3DDevice7_ApplyStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + hr = IDirect3DDevice7_GetTransform(device, tests[i], &ret_mat); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + ok(!memcmp(&ret_mat, &mat1, sizeof(mat1)), "Test %u: Got unexpected transform matrix.\n", tests[i]); + + hr = IDirect3DDevice7_SetTransform(device, tests[i], &mat2); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + } + + hr = IDirect3DDevice7_CaptureStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + hr = IDirect3DDevice7_SetTransform(device, tests[i], &mat1); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + } + + hr = IDirect3DDevice7_ApplyStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + hr = IDirect3DDevice7_GetTransform(device, tests[i], &ret_mat); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + ok(!memcmp(&ret_mat, &mat2, sizeof(mat2)), "Test %u: Got unexpected transform matrix.\n", tests[i]); + + hr = IDirect3DDevice7_SetTransform(device, tests[i], &mat1); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + } + + /* Predefined stateblock, D3DSBT_VERTEXSTATE. The documentation incorrectly + * states that transform matrices are included. */ + + hr = IDirect3DDevice7_CreateStateBlock(device, D3DSBT_VERTEXSTATE, &stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + hr = IDirect3DDevice7_SetTransform(device, tests[i], &mat2); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + } + + hr = IDirect3DDevice7_ApplyStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + hr = IDirect3DDevice7_GetTransform(device, tests[i], &ret_mat); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + ok(!memcmp(&ret_mat, &mat2, sizeof(mat2)), "Test %u: Got unexpected transform matrix.\n", tests[i]); + } + + hr = IDirect3DDevice7_CaptureStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + hr = IDirect3DDevice7_SetTransform(device, tests[i], &mat1); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + } + + hr = IDirect3DDevice7_ApplyStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + hr = IDirect3DDevice7_GetTransform(device, tests[i], &ret_mat); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + ok(!memcmp(&ret_mat, &mat1, sizeof(mat1)), "Test %u: Got unexpected transform matrix.\n", tests[i]); + } + + /* Predefined stateblock, D3DSBT_PIXELSTATE. */ + + hr = IDirect3DDevice7_CreateStateBlock(device, D3DSBT_PIXELSTATE, &stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + hr = IDirect3DDevice7_SetTransform(device, tests[i], &mat2); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + } + + hr = IDirect3DDevice7_ApplyStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + hr = IDirect3DDevice7_GetTransform(device, tests[i], &ret_mat); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + ok(!memcmp(&ret_mat, &mat2, sizeof(mat2)), "Test %u: Got unexpected transform matrix.\n", tests[i]); + } + + hr = IDirect3DDevice7_CaptureStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + hr = IDirect3DDevice7_SetTransform(device, tests[i], &mat1); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + } + + hr = IDirect3DDevice7_ApplyStateBlock(device, stateblock); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + hr = IDirect3DDevice7_GetTransform(device, tests[i], &ret_mat); + ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", tests[i], hr); + ok(!memcmp(&ret_mat, &mat1, sizeof(mat1)), "Test %u: Got unexpected transform matrix.\n", tests[i]); + } + + refcount = IDirect3DDevice7_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); + DestroyWindow(window); +} + START_TEST(ddraw7) { DDDEVICEIDENTIFIER2 identifier; @@ -16038,4 +16353,5 @@ START_TEST(ddraw7) test_alphatest(); test_clipper_refcount(); test_begin_end_state_block(); + test_transform_state(); }