[PATCH 4/5] d3d9/tests: Add a test for ATI1N and ATI2N texture formats.

Matteo Bruni mbruni at codeweavers.com
Wed Oct 29 12:01:53 CDT 2014


---
 dlls/d3d9/tests/device.c |   1 +
 dlls/d3d9/tests/visual.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 152 insertions(+)

diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c
index 2b7edd7..ddfd773 100644
--- a/dlls/d3d9/tests/device.c
+++ b/dlls/d3d9/tests/device.c
@@ -6145,6 +6145,7 @@ static void test_lockrect_offset(void)
         {D3DFMT_DXT3,                 "D3DFMT_DXT3", 4, 4, 16},
         {D3DFMT_DXT4,                 "D3DFMT_DXT4", 4, 4, 16},
         {D3DFMT_DXT5,                 "D3DFMT_DXT5", 4, 4, 16},
+        {MAKEFOURCC('A','T','I','1'), "ATI1N",       1, 1,  1},
         {MAKEFOURCC('A','T','I','2'), "ATI2N",       1, 1,  1},
     };
     unsigned int expected_offset, offset, i;
diff --git a/dlls/d3d9/tests/visual.c b/dlls/d3d9/tests/visual.c
index 117c8eb..5041ec8 100644
--- a/dlls/d3d9/tests/visual.c
+++ b/dlls/d3d9/tests/visual.c
@@ -16660,6 +16660,156 @@ 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');
+    IDirect3D9 *d3d;
+    IDirect3DDevice9 *device;
+    IDirect3DTexture9 *ati1n_texture, *ati2n_texture;
+    D3DCAPS9 caps;
+    D3DLOCKED_RECT rect;
+    D3DCOLOR color;
+    ULONG refcount;
+    HWND window;
+    HRESULT hr;
+    unsigned int i;
+
+    window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
+            0, 0, 640, 480, NULL, NULL, NULL, NULL);
+    d3d = Direct3DCreate9(D3D_SDK_VERSION);
+    ok(!!d3d, "Failed to create a D3D object.\n");
+    if (FAILED(IDirect3D9_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(IDirect3D9_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 = IDirect3DDevice9_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");
+        IDirect3DDevice9_Release(device);
+        goto done;
+    }
+
+    hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, ati1n_fourcc,
+            D3DPOOL_MANAGED, &ati1n_texture, NULL);
+    ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
+
+    hr = IDirect3DTexture9_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 = IDirect3DTexture9_UnlockRect(ati1n_texture, 0);
+    ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr);
+
+    hr = IDirect3DDevice9_CreateTexture(device, 8, 4, 1, 0, ati2n_fourcc,
+            D3DPOOL_MANAGED, &ati2n_texture, NULL);
+    ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
+
+    hr = IDirect3DTexture9_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 = IDirect3DTexture9_UnlockRect(ati2n_texture, 0);
+    ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr);
+
+    hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE2(0));
+    ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
+    hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA);
+    ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
+    hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
+    ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
+    /* The temporary register is initialized to 0. */
+    hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TEMP);
+    ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
+    hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
+    ok(SUCCEEDED(hr), "Failed to set alpha op, hr %#x.\n", hr);
+    hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
+    ok(SUCCEEDED(hr), "Failed to set alpha arg, hr %#x.\n", hr);
+    hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
+    ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
+    hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
+    ok(SUCCEEDED(hr), "Failed to set mag filter, hr %#x.\n", hr);
+
+    hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff00ff, 1.0f, 0);
+    ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
+    hr = IDirect3DDevice9_BeginScene(device);
+    ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
+    hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)ati1n_texture);
+    ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
+    hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[0], sizeof(*quads));
+    ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
+    hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)ati2n_texture);
+    ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
+    hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[4], sizeof(*quads));
+    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);
+
+    hr = IDirect3DDevice9_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);
+    }
+
+    IDirect3DTexture9_Release(ati2n_texture);
+    IDirect3DTexture9_Release(ati1n_texture);
+    refcount = IDirect3DDevice9_Release(device);
+    ok(!refcount, "Device has %u references left.\n", refcount);
+
+done:
+    IDirect3D9_Release(d3d);
+    DestroyWindow(window);
+}
+
 START_TEST(visual)
 {
     D3DADAPTER_IDENTIFIER9 identifier;
@@ -16767,4 +16917,5 @@ START_TEST(visual)
     resz_test();
     stencil_cull_test();
     test_per_stage_constant();
+    test_3dc_formats();
 }
-- 
2.0.4




More information about the wine-patches mailing list