From: Matteo Bruni Subject: [PATCH 5/5] d3d8/tests: Add a test for ATI1N and ATI2N texture formats. Message-Id: <1414602114-12220-5-git-send-email-mbruni@codeweavers.com> Date: Wed, 29 Oct 2014 18:01:54 +0100 --- dlls/d3d8/tests/visual.c | 150 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) diff --git a/dlls/d3d8/tests/visual.c b/dlls/d3d8/tests/visual.c index ba73bb6..fdc8041 100644 --- a/dlls/d3d8/tests/visual.c +++ b/dlls/d3d8/tests/visual.c @@ -5058,6 +5058,155 @@ done: DestroyWindow(window); } +static void test_3dc_formats(void) +{ + static const char ati1n_data[] = + { + /* A 4x4 texture with the color component at 50%. */ + 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }; + static const char ati2n_data[] = + { + /* A 8x4 texture consisting of 2 4x4 blocks. The first block has 50% first color component, + * 0% second component. Second block is the opposite. */ + 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }; + static const struct + { + struct vec3 position; + struct vec2 texcoord; + } + quads[] = + { + {{-1.0f, -1.0f, 0.0f}, {0.0f, 0.0f}}, + {{-1.0f, 1.0f, 0.0f}, {0.0f, 1.0f}}, + {{ 0.0f, -1.0f, 1.0f}, {1.0f, 0.0f}}, + {{ 0.0f, 1.0f, 1.0f}, {1.0f, 1.0f}}, + + {{ 0.0f, -1.0f, 0.0f}, {0.0f, 0.0f}}, + {{ 0.0f, 1.0f, 0.0f}, {0.0f, 1.0f}}, + {{ 1.0f, -1.0f, 1.0f}, {1.0f, 0.0f}}, + {{ 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f}}, + }; + static const DWORD expected_colors_ati[] = {0x003f3f3f, 0x003f3f3f, 0x00007fff, 0x007f00ff}; + static const DWORD expected_colors_nvidia[] = {0x007f0000, 0x007f0000, 0x00007fff, 0x007f00ff}; + static const DWORD ati1n_fourcc = MAKEFOURCC('A','T','I','1'); + static const DWORD ati2n_fourcc = MAKEFOURCC('A','T','I','2'); + IDirect3D8 *d3d; + IDirect3DDevice8 *device; + IDirect3DTexture8 *ati1n_texture, *ati2n_texture; + D3DCAPS8 caps; + D3DLOCKED_RECT rect; + D3DCOLOR color; + ULONG refcount; + HWND window; + HRESULT hr; + unsigned int i; + + window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE, + 0, 0, 640, 480, NULL, NULL, NULL, NULL); + d3d = Direct3DCreate8(D3D_SDK_VERSION); + ok(!!d3d, "Failed to create a D3D object.\n"); + if (FAILED(IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, + D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, ati1n_fourcc))) + { + skip("ATI1N textures are not supported, skipping test.\n"); + goto done; + } + if (FAILED(IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, + D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, ati2n_fourcc))) + { + skip("ATI2N textures are not supported, skipping test.\n"); + goto done; + } + if (!(device = create_device(d3d, window, window, TRUE))) + { + skip("Failed to create a D3D device, skipping tests.\n"); + goto done; + } + hr = IDirect3DDevice8_GetDeviceCaps(device, &caps); + ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr); + if (!(caps.PrimitiveMiscCaps & D3DPMISCCAPS_TSSARGTEMP)) + { + skip("D3DTA_TEMP not supported, skipping tests.\n"); + IDirect3DDevice8_Release(device); + goto done; + } + + hr = IDirect3DDevice8_CreateTexture(device, 4, 4, 1, 0, ati1n_fourcc, + D3DPOOL_MANAGED, &ati1n_texture); + ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr); + + hr = IDirect3DTexture8_LockRect(ati1n_texture, 0, &rect, NULL, 0); + ok(SUCCEEDED(hr), "Failed to lock texture, hr %#x.\n", hr); + memcpy(rect.pBits, ati1n_data, sizeof(ati1n_data)); + hr = IDirect3DTexture8_UnlockRect(ati1n_texture, 0); + ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr); + + hr = IDirect3DDevice8_CreateTexture(device, 8, 4, 1, 0, ati2n_fourcc, + D3DPOOL_MANAGED, &ati2n_texture); + ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr); + + hr = IDirect3DTexture8_LockRect(ati2n_texture, 0, &rect, NULL, 0); + ok(SUCCEEDED(hr), "Failed to lock texture, hr %#x.\n", hr); + memcpy(rect.pBits, ati2n_data, sizeof(ati2n_data)); + hr = IDirect3DTexture8_UnlockRect(ati2n_texture, 0); + ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr); + + hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE2(0)); + ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr); + hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA); + ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr); + hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); + ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr); + hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TEMP); + ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr); + hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); + ok(SUCCEEDED(hr), "Failed to set alpha op, hr %#x.\n", hr); + hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); + ok(SUCCEEDED(hr), "Failed to set alpha arg, hr %#x.\n", hr); + hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_DISABLE); + ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr); + hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MAGFILTER, D3DTEXF_POINT); + ok(SUCCEEDED(hr), "Failed to set mag filter, hr %#x.\n", hr); + + hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff00ff, 1.0f, 0); + ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr); + hr = IDirect3DDevice8_BeginScene(device); + ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr); + hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *)ati1n_texture); + ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr); + hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[0], sizeof(*quads)); + ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr); + hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *)ati2n_texture); + ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr); + hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[4], sizeof(*quads)); + 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); + + hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL); + ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr); + for (i = 0; i < 4; ++i) + { + color = getPixelColor(device, 80 + 160 * i, 240); + trace("Got 0x%08x.\n", color); + ok (color_match(color, expected_colors_ati[i], 1) || color_match(color, expected_colors_nvidia[i], 1), + "Expected color 0x%08x or 0x%08x, got 0x%08x, case %u.\n", + expected_colors_ati[i], expected_colors_nvidia[i], color, i); + } + + IDirect3DTexture8_Release(ati2n_texture); + IDirect3DTexture8_Release(ati1n_texture); + refcount = IDirect3DDevice8_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); + +done: + IDirect3D8_Release(d3d); + DestroyWindow(window); +} + START_TEST(visual) { D3DADAPTER_IDENTIFIER8 identifier; @@ -5107,4 +5256,5 @@ START_TEST(visual) volume_dxt5_test(); volume_v16u16_test(); add_dirty_rect_test(); + test_3dc_formats(); } -- 2.0.4