d3d8/tests: Add a test for reordering texture coordinates via D3DTSS_TEXCOORDINDEX.

This commit is contained in:
Matteo Bruni 2015-06-10 22:30:27 +02:00 committed by Alexandre Julliard
parent 81935797a1
commit db1bee5b9e
1 changed files with 176 additions and 0 deletions

View File

@ -6901,6 +6901,181 @@ done:
DestroyWindow(window);
}
static void test_texcoordindex(void)
{
static const D3DMATRIX mat =
{{{
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f,
}}};
static const struct
{
struct vec3 pos;
struct vec2 texcoord1;
struct vec2 texcoord2;
struct vec2 texcoord3;
}
quad[] =
{
{{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}, {0.0f, 0.0f}, {1.0f, 1.0f}},
{{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 0.0f}},
{{ 1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}, {1.0f, 0.0f}, {0.0f, 1.0f}},
{{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 0.0f}},
};
IDirect3DDevice8 *device;
IDirect3D8 *d3d;
HWND window;
HRESULT hr;
IDirect3DTexture8 *texture1, *texture2;
D3DLOCKED_RECT locked_rect;
ULONG refcount;
D3DCOLOR color;
DWORD *ptr;
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");
IDirect3D8_Release(d3d);
DestroyWindow(window);
return;
}
hr = IDirect3DDevice8_CreateTexture(device, 2, 2, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture1);
ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
hr = IDirect3DDevice8_CreateTexture(device, 2, 2, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture2);
ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
hr = IDirect3DTexture8_LockRect(texture1, 0, &locked_rect, NULL, D3DLOCK_DISCARD);
ok(SUCCEEDED(hr), "Failed to lock texture, hr %#x.\n", hr);
ptr = locked_rect.pBits;
ptr[0] = 0xff000000;
ptr[1] = 0xff00ff00;
ptr[2] = 0xff0000ff;
ptr[3] = 0xff00ffff;
hr = IDirect3DTexture8_UnlockRect(texture1, 0);
ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr);
hr = IDirect3DTexture8_LockRect(texture2, 0, &locked_rect, NULL, D3DLOCK_DISCARD);
ok(SUCCEEDED(hr), "Failed to lock texture, hr %#x.\n", hr);
ptr = locked_rect.pBits;
ptr[0] = 0xff000000;
ptr[1] = 0xff0000ff;
ptr[2] = 0xffff0000;
ptr[3] = 0xffff00ff;
hr = IDirect3DTexture8_UnlockRect(texture2, 0);
ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr);
hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *)texture1);
ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
hr = IDirect3DDevice8_SetTexture(device, 1, (IDirect3DBaseTexture8 *)texture2);
ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_TEX3);
ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
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, 1, D3DTSS_COLOROP, D3DTOP_ADD);
ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_CURRENT);
ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
hr = IDirect3DDevice8_SetTextureStageState(device, 2, D3DTSS_COLOROP, D3DTOP_DISABLE);
ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_TEXCOORDINDEX, 1);
ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#x.\n", hr);
hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_TEXCOORDINDEX, 0);
ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#x.\n", hr);
hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 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, quad, sizeof(*quad));
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, 160, 120);
ok(color_match(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
color = getPixelColor(device, 480, 120);
ok(color_match(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
color = getPixelColor(device, 160, 360);
ok(color_match(color, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color);
color = getPixelColor(device, 480, 360);
ok(color_match(color, 0x00ffffff, 2), "Got unexpected color 0x%08x.\n", color);
hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
ok(SUCCEEDED(hr), "Failed to set texture transform flags, hr %#x.\n", hr);
hr = IDirect3DDevice8_SetTransform(device, D3DTS_TEXTURE1, &mat);
ok(SUCCEEDED(hr), "Failed to set transformation matrix, hr %#x.\n", hr);
hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 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, quad, sizeof(*quad));
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, 160, 120);
ok(color_match(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
color = getPixelColor(device, 480, 120);
ok(color_match(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
color = getPixelColor(device, 160, 360);
ok(color_match(color, 0x00000000, 2), "Got unexpected color 0x%08x.\n", color);
color = getPixelColor(device, 480, 360);
ok(color_match(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
ok(SUCCEEDED(hr), "Failed to set texture transform flags, hr %#x.\n", hr);
hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_TEXCOORDINDEX, 2);
ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#x.\n", hr);
hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 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, quad, sizeof(*quad));
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, 160, 120);
ok(color_match(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
color = getPixelColor(device, 480, 120);
ok(color_match(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
color = getPixelColor(device, 160, 360);
ok(color_match(color, 0x00ff00ff, 2), "Got unexpected color 0x%08x.\n", color);
color = getPixelColor(device, 480, 360);
ok(color_match(color, 0x00ffff00, 2), "Got unexpected color 0x%08x.\n", color);
hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
IDirect3DTexture8_Release(texture1);
IDirect3DTexture8_Release(texture2);
refcount = IDirect3DDevice8_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
IDirect3D8_Release(d3d);
DestroyWindow(window);
}
START_TEST(visual)
{
D3DADAPTER_IDENTIFIER8 identifier;
@ -6958,4 +7133,5 @@ START_TEST(visual)
test_signed_formats();
test_pointsize();
test_multisample_mismatch();
test_texcoordindex();
}