From: Matteo Bruni Subject: [PATCH 3/5] d3d8/tests: Add a test for 2D D3DFMT_V16U16 textures. Message-Id: <1424433966-17581-3-git-send-email-mbruni@codeweavers.com> Date: Fri, 20 Feb 2015 13:06:04 +0100 --- dlls/d3d8/tests/visual.c | 149 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) diff --git a/dlls/d3d8/tests/visual.c b/dlls/d3d8/tests/visual.c index 85b3fad..8028070 100644 --- a/dlls/d3d8/tests/visual.c +++ b/dlls/d3d8/tests/visual.c @@ -4727,6 +4727,154 @@ done: DestroyWindow(window); } +static void v16u16_test(void) +{ + IDirect3DTexture8 *texture; + IDirect3DDevice8 *device; + D3DLOCKED_RECT rect; + IDirect3D8 *d3d; + unsigned int i; + D3DCOLOR color; + ULONG refcount; + D3DCAPS8 caps; + DWORD shader; + SHORT *texel; + HWND window; + HRESULT hr; + + static const struct + { + struct vec3 position; + struct vec2 texcrd; + } + quads[] = + { + {{-1.0f, -1.0f, 0.0f}, {0.0f, 0.0f}}, + {{-1.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 shader_code[] = + { + 0xffff0101, /* ps_1_1 */ + 0x00000051, 0xa00f0000, 0x3f000000, 0x3f000000, /* def c0, 0.5, 0.5, */ + 0x3f000000, 0x3f000000, /* 0.5, 0.5 */ + 0x00000042, 0xb00f0000, /* tex t0 */ + 0x00000004, 0x800f0000, 0xb0e40000, 0xa0e40000, 0xa0e40000, /* mad r0, t0, c0, c0 */ + 0x0000ffff /* end */ + }; + + 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 (!(device = create_device(d3d, window, window, TRUE))) + { + skip("Failed to create a D3D device, skipping tests.\n"); + goto done; + } + + if (FAILED(IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, + D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, D3DFMT_V16U16))) + { + skip("V16U16 textures are not supported, skipping test.\n"); + IDirect3DDevice8_Release(device); + goto done; + } + hr = IDirect3DDevice8_GetDeviceCaps(device, &caps); + ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr); + if (caps.PixelShaderVersion < D3DPS_VERSION(1, 1)) + { + skip("No pixel shader 1.1 support, skipping test.\n"); + IDirect3DDevice8_Release(device); + goto done; + } + + hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_TEX1); + ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr); + hr = IDirect3DDevice8_CreatePixelShader(device, shader_code, &shader); + ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr); + hr = IDirect3DDevice8_SetPixelShader(device, shader); + ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr); + hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MAGFILTER, D3DTEXF_POINT); + ok(SUCCEEDED(hr), "Failed to set filter, hr %#x.\n", hr); + + for (i = 0; i < 2; ++i) + { + D3DPOOL pool; + + if (i) + pool = D3DPOOL_SYSTEMMEM; + else + pool = D3DPOOL_MANAGED; + + hr = IDirect3DDevice8_CreateTexture(device, 1, 2, 1, 0, D3DFMT_V16U16, + pool, &texture); + ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr); + + hr = IDirect3DTexture8_LockRect(texture, 0, &rect, NULL, 0); + ok(SUCCEEDED(hr), "Failed to lock texture, hr %#x.\n", hr); + + texel = (SHORT *)((BYTE *)rect.pBits + 0 * rect.Pitch); + texel[0] = 32767; + texel[1] = 32767; + texel = (SHORT *)((BYTE *)rect.pBits + 1 * rect.Pitch); + texel[0] = -32768; + texel[1] = 0; + + hr = IDirect3DTexture8_UnlockRect(texture, 0); + ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr); + + if (i) + { + IDirect3DTexture8 *texture2; + + hr = IDirect3DDevice8_CreateTexture(device, 1, 2, 1, 0, D3DFMT_V16U16, + D3DPOOL_DEFAULT, &texture2); + ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr); + + hr = IDirect3DDevice8_UpdateTexture(device, (IDirect3DBaseTexture8 *)texture, + (IDirect3DBaseTexture8 *)texture2); + ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr); + + IDirect3DTexture8_Release(texture); + texture = texture2; + } + + hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *)texture); + ok(SUCCEEDED(hr), "Failed to set texture, 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_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[0], 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); + + color = getPixelColor(device, 320, 160); + ok (color_match(color, 0x000080ff, 2), + "Expected color 0x000080ff, got %#x, V16U16 input -32768, 0.\n", color); + color = getPixelColor(device, 320, 400); + ok (color_match(color, 0x00ffffff, 2), + "Expected color 0x00ffffff, got %#x, V16U16 input 32767, 32767.\n", color); + + hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL); + ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr); + + IDirect3DTexture8_Release(texture); + } + + hr = IDirect3DDevice8_DeletePixelShader(device, shader); + ok(SUCCEEDED(hr), "Failed delete pixel shader, hr %#x.\n", hr); + refcount = IDirect3DDevice8_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); +done: + IDirect3D8_Release(d3d); + DestroyWindow(window); +} + static void fill_surface(IDirect3DSurface8 *surface, DWORD color, DWORD flags) { D3DSURFACE_DESC desc; @@ -5729,6 +5877,7 @@ START_TEST(visual) fog_special_test(); volume_dxt5_test(); volume_v16u16_test(); + v16u16_test(); add_dirty_rect_test(); test_3dc_formats(); test_fog_interpolation(); -- 2.0.5