d3d9/tests: Merge vertexdeclaration.c into device.c.

This commit is contained in:
Henri Verbeet 2014-05-02 12:50:19 +02:00 committed by Alexandre Julliard
parent ffc01ec648
commit 301a17d556
3 changed files with 750 additions and 868 deletions

View file

@ -5,5 +5,4 @@ C_SRCS = \
d3d9ex.c \
device.c \
stateblock.c \
vertexdeclaration.c \
visual.c

View file

@ -1,9 +1,10 @@
/*
* Copyright (C) 2006 Ivan Gyurdiev
* Copyright (C) 2006 Vitaliy Margolen
* Copyright (C) 2006 Chris Robinson
* Copyright 2006-2008, 2010-2011, 2013 Stefan Dösinger for CodeWeavers
* Copyright 2005, 2006, 2007 Henri Verbeet
* Copyright 2013 Henri Verbeet for CodeWeavers
* Copyright 2013-2014 Henri Verbeet for CodeWeavers
* Copyright (C) 2008 Rico Schüller
*
* This library is free software; you can redistribute it and/or
@ -59,6 +60,42 @@ static int get_refcount(IUnknown *object)
return IUnknown_Release( object );
}
static BOOL compare_elements(IDirect3DVertexDeclaration9 *declaration, const D3DVERTEXELEMENT9 *expected_elements)
{
unsigned int element_count, i;
D3DVERTEXELEMENT9 *elements;
BOOL equal = TRUE;
HRESULT hr;
hr = IDirect3DVertexDeclaration9_GetDeclaration(declaration, NULL, &element_count);
ok(SUCCEEDED(hr), "Failed to get declaration, hr %#x.\n", hr);
elements = HeapAlloc(GetProcessHeap(), 0, element_count * sizeof(*elements));
hr = IDirect3DVertexDeclaration9_GetDeclaration(declaration, elements, &element_count);
ok(SUCCEEDED(hr), "Failed to get declaration, hr %#x.\n", hr);
for (i = 0; i < element_count; ++i)
{
if (memcmp(&elements[i], &expected_elements[i], sizeof(*elements)))
{
equal = FALSE;
break;
}
}
if (!equal)
{
for (i = 0; i < element_count; ++i)
{
trace("[Element %u] stream %u, offset %u, type %#x, method %#x, usage %#x, usage index %u.\n",
i, elements[i].Stream, elements[i].Offset, elements[i].Type,
elements[i].Method, elements[i].Usage, elements[i].UsageIndex);
}
}
HeapFree(GetProcessHeap(), 0, elements);
return equal;
}
/* try to make sure pending X events have been processed before continuing */
static void flush_events(void)
{
@ -165,6 +202,712 @@ static HRESULT reset_device(IDirect3DDevice9 *device, HWND device_window, BOOL w
if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr); \
}
static void test_get_set_vertex_declaration(void)
{
IDirect3DVertexDeclaration9 *declaration, *tmp;
ULONG refcount, expected_refcount;
IDirect3DDevice9 *device;
IDirect3D9 *d3d;
HWND window;
HRESULT hr;
static const D3DVERTEXELEMENT9 simple_decl[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
D3DDECL_END()
};
window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW,
0, 0, 640, 480, NULL, NULL, NULL, NULL);
d3d = Direct3DCreate9(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;
}
hr = IDirect3DDevice9_CreateVertexDeclaration(device, simple_decl, &declaration);
ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
/* SetVertexDeclaration() should not touch the declaration's refcount. */
expected_refcount = get_refcount((IUnknown *)declaration);
hr = IDirect3DDevice9_SetVertexDeclaration(device, declaration);
ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
refcount = get_refcount((IUnknown *)declaration);
ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
/* GetVertexDeclaration() should increase the declaration's refcount by one. */
tmp = NULL;
expected_refcount = refcount + 1;
hr = IDirect3DDevice9_GetVertexDeclaration(device, &tmp);
ok(SUCCEEDED(hr), "Failed to get vertex declaration, hr %#x.\n", hr);
ok(tmp == declaration, "Got unexpected declaration %p, expected %p.\n", tmp, declaration);
refcount = get_refcount((IUnknown *)declaration);
ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
IDirect3DVertexDeclaration9_Release(tmp);
IDirect3DVertexDeclaration9_Release(declaration);
refcount = IDirect3DDevice9_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
done:
IDirect3D9_Release(d3d);
DestroyWindow(window);
}
static void test_get_declaration(void)
{
unsigned int element_count, expected_element_count;
IDirect3DVertexDeclaration9 *declaration;
D3DVERTEXELEMENT9 *elements;
IDirect3DDevice9 *device;
IDirect3D9 *d3d;
ULONG refcount;
HWND window;
HRESULT hr;
static const D3DVERTEXELEMENT9 simple_decl[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
D3DDECL_END()
};
window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW,
0, 0, 640, 480, NULL, NULL, NULL, NULL);
d3d = Direct3DCreate9(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;
}
hr = IDirect3DDevice9_CreateVertexDeclaration(device, simple_decl, &declaration);
ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
/* First test only getting the number of elements. */
element_count = 0x1337c0de;
expected_element_count = sizeof(simple_decl) / sizeof(*simple_decl);
hr = IDirect3DVertexDeclaration9_GetDeclaration(declaration, NULL, &element_count);
ok(SUCCEEDED(hr), "Failed to get declaration, hr %#x.\n", hr);
ok(element_count == expected_element_count, "Got unexpected element count %u, expected %u.\n",
element_count, expected_element_count);
element_count = 0;
hr = IDirect3DVertexDeclaration9_GetDeclaration(declaration, NULL, &element_count);
ok(SUCCEEDED(hr), "Failed to get declaration, hr %#x.\n", hr);
ok(element_count == expected_element_count, "Got unexpected element count %u, expected %u.\n",
element_count, expected_element_count);
/* Also test the returned data. */
elements = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(simple_decl));
element_count = 0x1337c0de;
hr = IDirect3DVertexDeclaration9_GetDeclaration(declaration, elements, &element_count);
ok(SUCCEEDED(hr), "Failed to get declaration, hr %#x.\n", hr);
ok(element_count == expected_element_count, "Got unexpected element count %u, expected %u.\n",
element_count, expected_element_count);
ok(!memcmp(elements, simple_decl, element_count * sizeof(*elements)),
"Original and returned vertexdeclarations are not the same.\n");
memset(elements, 0, sizeof(simple_decl));
element_count = 0;
hr = IDirect3DVertexDeclaration9_GetDeclaration(declaration, elements, &element_count);
ok(SUCCEEDED(hr), "Failed to get declaration, hr %#x.\n", hr);
ok(element_count == expected_element_count, "Got unexpected element count %u, expected %u.\n",
element_count, expected_element_count);
ok(!memcmp(elements, simple_decl, element_count * sizeof(*elements)),
"Original and returned vertexdeclarations are not the same.\n");
HeapFree(GetProcessHeap(), 0, elements);
IDirect3DVertexDeclaration9_Release(declaration);
refcount = IDirect3DDevice9_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
done:
IDirect3D9_Release(d3d);
DestroyWindow(window);
}
static void test_fvf_decl_conversion(void)
{
IDirect3DVertexDeclaration9 *default_decl;
IDirect3DVertexDeclaration9 *declaration;
IDirect3DDevice9 *device;
IDirect3D9 *d3d;
ULONG refcount;
unsigned int i;
HWND window;
HRESULT hr;
static const D3DVERTEXELEMENT9 default_elements[] =
{
{0, 0, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 0},
{0, 4, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 1},
D3DDECL_END()
};
/* Test conversions from vertex declaration to an FVF. For some reason
* those seem to occur only for POSITION/POSITIONT, otherwise the FVF is
* forced to 0 - maybe this is configuration specific. */
static const struct
{
D3DVERTEXELEMENT9 elements[7];
DWORD fvf;
BOOL todo;
}
decl_to_fvf_tests[] =
{
{{{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0}, D3DDECL_END()}, D3DFVF_XYZ, TRUE },
{{{0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_POSITIONT, 0}, D3DDECL_END()}, D3DFVF_XYZRHW, TRUE },
{{{0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_BLENDWEIGHT, 0}, D3DDECL_END()}, 0, FALSE},
{{{0, 0, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_BLENDWEIGHT, 0}, D3DDECL_END()}, 0, FALSE},
{{{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_BLENDWEIGHT, 0}, D3DDECL_END()}, 0, FALSE},
{{{0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_BLENDWEIGHT, 0}, D3DDECL_END()}, 0, FALSE},
{{{0, 0, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0}, D3DDECL_END()}, 0, FALSE},
{{{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_NORMAL, 0}, D3DDECL_END()}, 0, FALSE},
{{{0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_PSIZE, 0}, D3DDECL_END()}, 0, FALSE},
{{{0, 0, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 0}, D3DDECL_END()}, 0, FALSE},
{{{0, 0, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 1}, D3DDECL_END()}, 0, FALSE},
/* No FVF mapping available. */
{{{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 1}, D3DDECL_END()}, 0, FALSE},
{{{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_NORMAL, 1}, D3DDECL_END()}, 0, FALSE},
/* Try empty declaration. */
{{ D3DDECL_END()}, 0, FALSE},
/* Make sure textures of different sizes work. */
{{{0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_TEXCOORD, 0}, D3DDECL_END()}, 0, FALSE},
{{{0, 0, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_TEXCOORD, 0}, D3DDECL_END()}, 0, FALSE},
{{{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_TEXCOORD, 0}, D3DDECL_END()}, 0, FALSE},
{{{0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_TEXCOORD, 0}, D3DDECL_END()}, 0, FALSE},
/* Make sure the TEXCOORD index works correctly - try several textures. */
{
{
{0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_TEXCOORD, 0},
{0, 4, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_TEXCOORD, 1},
{0, 16, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_TEXCOORD, 2},
{0, 24, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_TEXCOORD, 3},
D3DDECL_END(),
}, 0, FALSE,
},
/* Now try a combination test. */
{
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITIONT, 0},
{0, 12, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_NORMAL, 0},
{0, 24, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_PSIZE, 0},
{0, 28, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 1},
{0, 32, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_TEXCOORD, 0},
{0, 44, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_TEXCOORD, 1},
D3DDECL_END(),
}, 0, FALSE,
},
};
/* Test conversions from FVF to a vertex declaration. These seem to always
* occur internally. A new declaration object is created if necessary. */
static const struct
{
DWORD fvf;
D3DVERTEXELEMENT9 elements[7];
}
fvf_to_decl_tests[] =
{
{D3DFVF_XYZ, {{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0}, D3DDECL_END()}},
{D3DFVF_XYZW, {{0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_POSITION, 0}, D3DDECL_END()}},
{D3DFVF_XYZRHW, {{0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_POSITIONT, 0}, D3DDECL_END()}},
{
D3DFVF_XYZB5,
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_BLENDWEIGHT, 0},
{0, 28, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_BLENDINDICES, 0},
D3DDECL_END(),
},
},
{
D3DFVF_XYZB5 | D3DFVF_LASTBETA_UBYTE4,
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_BLENDWEIGHT, 0},
{0, 28, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0},
D3DDECL_END(),
},
},
{
D3DFVF_XYZB5 | D3DFVF_LASTBETA_D3DCOLOR,
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_BLENDWEIGHT, 0},
{0, 28, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_BLENDINDICES, 0},
D3DDECL_END(),
},
},
{
D3DFVF_XYZB1,
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_BLENDWEIGHT, 0},
D3DDECL_END(),
},
},
{
D3DFVF_XYZB1 | D3DFVF_LASTBETA_UBYTE4,
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0},
D3DDECL_END(),
},
},
{
D3DFVF_XYZB1 | D3DFVF_LASTBETA_D3DCOLOR,
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_BLENDINDICES, 0},
D3DDECL_END(),
},
},
{
D3DFVF_XYZB2,
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_BLENDWEIGHT, 0},
D3DDECL_END(),
},
},
{
D3DFVF_XYZB2 | D3DFVF_LASTBETA_UBYTE4,
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_BLENDWEIGHT, 0},
{0, 16, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0},
D3DDECL_END(),
},
},
{
D3DFVF_XYZB2 | D3DFVF_LASTBETA_D3DCOLOR,
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_BLENDWEIGHT, 0},
{0, 16, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0},
D3DDECL_END(),
},
},
{
D3DFVF_XYZB3,
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_BLENDWEIGHT, 0},
D3DDECL_END(),
},
},
{
D3DFVF_XYZB3 | D3DFVF_LASTBETA_UBYTE4,
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_BLENDWEIGHT, 0},
{0, 20, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0},
D3DDECL_END(),
},
},
{
D3DFVF_XYZB3 | D3DFVF_LASTBETA_D3DCOLOR,
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_BLENDWEIGHT, 0},
{0, 20, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_BLENDINDICES, 0},
D3DDECL_END(),
},
},
{
D3DFVF_XYZB4,
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_BLENDWEIGHT, 0},
D3DDECL_END(),
},
},
{
D3DFVF_XYZB4 | D3DFVF_LASTBETA_UBYTE4,
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_BLENDWEIGHT, 0},
{0, 24, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0},
D3DDECL_END(),
},
},
{
D3DFVF_XYZB4 | D3DFVF_LASTBETA_D3DCOLOR,
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_BLENDWEIGHT, 0},
{0, 24, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_BLENDINDICES, 0},
D3DDECL_END(),
},
},
{D3DFVF_NORMAL, {{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_NORMAL, 0}, D3DDECL_END()}},
{D3DFVF_PSIZE, {{0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_PSIZE, 0}, D3DDECL_END()}},
{D3DFVF_DIFFUSE, {{0, 0, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 0}, D3DDECL_END()}},
{D3DFVF_SPECULAR, {{0, 0, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 1}, D3DDECL_END()}},
/* Make sure textures of different sizes work. */
{
D3DFVF_TEXCOORDSIZE1(0) | D3DFVF_TEX1,
{{0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_TEXCOORD, 0}, D3DDECL_END()},
},
{
D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEX1,
{{0, 0, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_TEXCOORD, 0}, D3DDECL_END()},
},
{
D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1,
{{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_TEXCOORD, 0}, D3DDECL_END()},
},
{
D3DFVF_TEXCOORDSIZE4(0) | D3DFVF_TEX1,
{{0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_TEXCOORD, 0}, D3DDECL_END()},
},
/* Make sure the TEXCOORD index works correctly - try several textures. */
{
D3DFVF_TEXCOORDSIZE1(0) | D3DFVF_TEXCOORDSIZE3(1) | D3DFVF_TEXCOORDSIZE2(2)
| D3DFVF_TEXCOORDSIZE4(3) | D3DFVF_TEX4,
{
{0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_TEXCOORD, 0},
{0, 4, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_TEXCOORD, 1},
{0, 16, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_TEXCOORD, 2},
{0, 24, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_TEXCOORD, 3},
D3DDECL_END(),
},
},
/* Now try a combination test. */
{
D3DFVF_XYZB4 | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEXCOORDSIZE2(0)
| D3DFVF_TEXCOORDSIZE3(1) | D3DFVF_TEX2,
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_BLENDWEIGHT, 0},
{0, 28, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 0},
{0, 32, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 1},
{0, 36, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_TEXCOORD, 0},
{0, 44, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_TEXCOORD, 1},
D3DDECL_END(),
},
},
};
window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW,
0, 0, 640, 480, NULL, NULL, NULL, NULL);
d3d = Direct3DCreate9(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;
}
for (i = 0; i < sizeof(decl_to_fvf_tests) / sizeof(*decl_to_fvf_tests); ++i)
{
DWORD fvf = 0xdeadbeef;
HRESULT hr;
/* Set a default FVF of SPECULAR and DIFFUSE to make sure it is changed
* back to 0. */
hr = IDirect3DDevice9_SetFVF(device, D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
ok(SUCCEEDED(hr), "Test %u: Failed to set FVF, hr %#x.\n", i, hr);
hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_to_fvf_tests[i].elements, &declaration);
ok(SUCCEEDED(hr), "Test %u: Failed to create vertex declaration, hr %#x.\n", i, hr);
hr = IDirect3DDevice9_SetVertexDeclaration(device, declaration);
ok(SUCCEEDED(hr), "Test %u: Failed to set vertex declaration, hr %#x.\n", i, hr);
/* Check the FVF. */
hr = IDirect3DDevice9_GetFVF(device, &fvf);
ok(SUCCEEDED(hr), "Test %u: Failed to get FVF, hr %#x.\n", i, hr);
if (decl_to_fvf_tests[i].todo)
todo_wine ok(fvf == decl_to_fvf_tests[i].fvf,
"Test %u: Got unexpected FVF %#x, expected %#x.\n",
i, fvf, decl_to_fvf_tests[i].fvf);
else
ok(fvf == decl_to_fvf_tests[i].fvf,
"Test %u: Got unexpected FVF %#x, expected %#x.\n",
i, fvf, decl_to_fvf_tests[i].fvf);
IDirect3DDevice9_SetVertexDeclaration(device, NULL);
IDirect3DVertexDeclaration9_Release(declaration);
}
/* Create a default declaration and FVF that does not match any of the
* tests. */
hr = IDirect3DDevice9_CreateVertexDeclaration(device, default_elements, &default_decl);
ok(SUCCEEDED(hr), "Failed to create vertex declaration, hr %#x.\n", hr);
for (i = 0; i < sizeof(fvf_to_decl_tests) / sizeof(*fvf_to_decl_tests); ++i)
{
/* Set a default declaration to make sure it is changed. */
hr = IDirect3DDevice9_SetVertexDeclaration(device, default_decl);
ok(SUCCEEDED(hr), "Test %u: Failed to set vertex declaration, hr %#x.\n", i, hr);
hr = IDirect3DDevice9_SetFVF(device, fvf_to_decl_tests[i].fvf);
ok(SUCCEEDED(hr), "Test %u: Failed to set FVF, hr %#x.\n", i, hr);
hr = IDirect3DDevice9_GetVertexDeclaration(device, &declaration);
ok(SUCCEEDED(hr), "Test %u: Failed to get vertex declaration, hr %#x.\n", i, hr);
ok(!!declaration && declaration != default_decl,
"Test %u: Got unexpected declaration %p.\n", i, declaration);
ok(compare_elements(declaration, fvf_to_decl_tests[i].elements),
"Test %u: Declaration does not match.\n", i);
IDirect3DVertexDeclaration9_Release(declaration);
}
/* Setting the FVF to 0 should result in no change to the default decl. */
hr = IDirect3DDevice9_SetVertexDeclaration(device, default_decl);
ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
hr = IDirect3DDevice9_SetFVF(device, 0);
ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
hr = IDirect3DDevice9_GetVertexDeclaration(device, &declaration);
ok(SUCCEEDED(hr), "Failed to get vertex declaration, hr %#x.\n", hr);
ok(declaration == default_decl, "Got unexpected declaration %p, expected %p.\n", declaration, default_decl);
IDirect3DVertexDeclaration9_Release(declaration);
IDirect3DVertexDeclaration9_Release(default_decl);
refcount = IDirect3DDevice9_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
done:
IDirect3D9_Release(d3d);
DestroyWindow(window);
}
/* Check whether a declaration converted from FVF is shared.
* Check whether refcounts behave as expected. */
static void test_fvf_decl_management(void)
{
IDirect3DVertexDeclaration9 *declaration1;
IDirect3DVertexDeclaration9 *declaration2;
IDirect3DVertexDeclaration9 *declaration3;
IDirect3DVertexDeclaration9 *declaration4;
IDirect3DDevice9 *device;
IDirect3D9 *d3d;
ULONG refcount;
HWND window;
HRESULT hr;
static const D3DVERTEXELEMENT9 test_elements1[] =
{{0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_POSITIONT, 0}, D3DDECL_END()};
static const D3DVERTEXELEMENT9 test_elements2[] =
{{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_NORMAL, 0}, D3DDECL_END()};
window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW,
0, 0, 640, 480, NULL, NULL, NULL, NULL);
d3d = Direct3DCreate9(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;
}
/* Clear down any current vertex declaration. */
hr = IDirect3DDevice9_SetVertexDeclaration(device, NULL);
ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
/* Conversion. */
hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZRHW);
ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
/* Get converted decl (#1). */
hr = IDirect3DDevice9_GetVertexDeclaration(device, &declaration1);
ok(SUCCEEDED(hr), "Failed to get vertex declaration, hr %#x.\n", hr);
ok(compare_elements(declaration1, test_elements1), "Declaration does not match.\n");
/* Get converted decl again (#2). */
hr = IDirect3DDevice9_GetVertexDeclaration(device, &declaration2);
ok(SUCCEEDED(hr), "Failed to get vertex declaration, hr %#x.\n", hr);
ok(declaration2 == declaration1, "Got unexpected declaration2 %p, expected %p.\n", declaration2, declaration1);
/* Conversion. */
hr = IDirect3DDevice9_SetFVF(device, D3DFVF_NORMAL);
ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
/* Get converted decl (#3). */
hr = IDirect3DDevice9_GetVertexDeclaration(device, &declaration3);
ok(SUCCEEDED(hr), "Failed to get vertex declaration, hr %#x.\n", hr);
ok(declaration3 != declaration2, "Got unexpected declaration3 %p.\n", declaration3);
/* The contents should correspond to the second conversion. */
ok(compare_elements(declaration3, test_elements2), "Declaration does not match.\n");
/* Re-Check if the first decl was overwritten by the new Get(). */
ok(compare_elements(declaration1, test_elements1), "Declaration does not match.\n");
hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZRHW);
ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
hr = IDirect3DDevice9_GetVertexDeclaration(device, &declaration4);
ok(SUCCEEDED(hr), "Failed to get vertex declaration, hr %#x.\n", hr);
ok(declaration4 == declaration1, "Got unexpected declaration4 %p, expected %p.\n", declaration4, declaration1);
refcount = get_refcount((IUnknown*)declaration1);
ok(refcount == 3, "Got unexpected refcount %u.\n", refcount);
refcount = get_refcount((IUnknown*)declaration2);
ok(refcount == 3, "Got unexpected refcount %u.\n", refcount);
refcount = get_refcount((IUnknown*)declaration3);
ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
refcount = get_refcount((IUnknown*)declaration4);
ok(refcount == 3, "Got unexpected refcount %u.\n", refcount);
IDirect3DVertexDeclaration9_Release(declaration4);
IDirect3DVertexDeclaration9_Release(declaration3);
IDirect3DVertexDeclaration9_Release(declaration2);
IDirect3DVertexDeclaration9_Release(declaration1);
refcount = IDirect3DDevice9_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
done:
IDirect3D9_Release(d3d);
DestroyWindow(window);
}
static void test_vertex_declaration_alignment(void)
{
IDirect3DVertexDeclaration9 *declaration;
IDirect3DDevice9 *device;
IDirect3D9 *d3d;
unsigned int i;
ULONG refcount;
HWND window;
HRESULT hr;
static const struct
{
D3DVERTEXELEMENT9 elements[3];
HRESULT hr;
}
test_data[] =
{
{
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0},
{0, 16, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 0},
D3DDECL_END(),
}, D3D_OK,
},
{
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0},
{0, 17, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 0},
D3DDECL_END(),
}, E_FAIL,
},
{
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0},
{0, 18, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 0},
D3DDECL_END(),
}, E_FAIL,
},
{
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0},
{0, 19, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 0},
D3DDECL_END(),
}, E_FAIL,
},
{
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0},
{0, 20, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 0},
D3DDECL_END(),
}, D3D_OK,
},
};
window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW,
0, 0, 640, 480, NULL, NULL, NULL, NULL);
d3d = Direct3DCreate9(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;
}
for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
{
hr = IDirect3DDevice9_CreateVertexDeclaration(device, test_data[i].elements, &declaration);
ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
if (SUCCEEDED(hr))
IDirect3DVertexDeclaration9_Release(declaration);
}
refcount = IDirect3DDevice9_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
done:
IDirect3D9_Release(d3d);
DestroyWindow(window);
}
static void test_unused_declaration_type(void)
{
IDirect3DVertexDeclaration9 *declaration;
IDirect3DDevice9 *device;
IDirect3D9 *d3d;
unsigned int i;
ULONG refcount;
HWND window;
HRESULT hr;
static const D3DVERTEXELEMENT9 test_elements[][3] =
{
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{0, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_COLOR , 0 },
D3DDECL_END(),
},
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{0, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_TEXCOORD, 0 },
D3DDECL_END(),
},
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{0, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_TEXCOORD, 1 },
D3DDECL_END(),
},
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{0, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_TEXCOORD, 12},
D3DDECL_END(),
},
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{1, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_TEXCOORD, 12},
D3DDECL_END(),
},
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{0, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_NORMAL, 0 },
D3DDECL_END(),
},
{
{0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{1, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_NORMAL, 0 },
D3DDECL_END(),
},
};
window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW,
0, 0, 640, 480, NULL, NULL, NULL, NULL);
d3d = Direct3DCreate9(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;
}
for (i = 0; i < sizeof(test_elements) / sizeof(*test_elements); ++i)
{
hr = IDirect3DDevice9_CreateVertexDeclaration(device, test_elements[i], &declaration);
ok(hr == E_FAIL, "Test %u: Got unexpected hr %#x.\n", i, hr);
}
refcount = IDirect3DDevice9_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
done:
IDirect3D9_Release(d3d);
DestroyWindow(window);
}
static void check_mipmap_levels(IDirect3DDevice9 *device, UINT width, UINT height, UINT count)
{
IDirect3DBaseTexture9* texture = NULL;
@ -8017,6 +8760,12 @@ START_TEST(device)
screen_width = GetSystemMetrics(SM_CXSCREEN);
screen_height = GetSystemMetrics(SM_CYSCREEN);
test_get_set_vertex_declaration();
test_get_declaration();
test_fvf_decl_conversion();
test_fvf_decl_management();
test_vertex_declaration_alignment();
test_unused_declaration_type();
test_fpu_setup();
test_multi_device();
test_display_formats();

View file

@ -1,866 +0,0 @@
/*
* Copyright (C) 2005 Henri Verbeet
* Copyright (C) 2006 Ivan Gyurdiev
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#define COBJMACROS
#include <d3d9.h>
#include "wine/test.h"
#define VDECL_CHECK(fcall) \
if(fcall != S_OK) \
trace(" Test failed on line #%d\n", __LINE__);
static HWND create_window(void)
{
WNDCLASSA wc = {0};
wc.lpfnWndProc = DefWindowProcA;
wc.lpszClassName = "d3d9_test_wc";
RegisterClassA(&wc);
return CreateWindowA("d3d9_test_wc", "d3d9_test", 0,
0, 0, 0, 0, 0, 0, 0, 0);
}
static IDirect3DDevice9 *init_d3d9(void)
{
D3DPRESENT_PARAMETERS present_parameters;
IDirect3DDevice9 *device = NULL;
IDirect3D9 *d3d9;
HRESULT hr;
if (!(d3d9 = Direct3DCreate9(D3D_SDK_VERSION)))
{
skip("could not create D3D9\n");
return NULL;
}
memset(&present_parameters, 0, sizeof(present_parameters));
present_parameters.Windowed = TRUE;
present_parameters.hDeviceWindow = create_window();
present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
if (SUCCEEDED(IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device)))
return device;
if (SUCCEEDED(hr = IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, NULL,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device)))
return device;
trace("Failed to create device, hr %#x.\n", hr);
return NULL;
}
static int get_refcount(IUnknown *object)
{
IUnknown_AddRef(object);
return IUnknown_Release(object);
}
static inline void print_elements(
D3DVERTEXELEMENT9 *elements) {
D3DVERTEXELEMENT9 last = D3DDECL_END();
D3DVERTEXELEMENT9 *ptr = elements;
int count = 0;
while (memcmp(ptr, &last, sizeof(D3DVERTEXELEMENT9))) {
trace(
"[Element %d] Stream = %d, Offset = %d, Type = %d, Method = %d, Usage = %d, UsageIndex = %d\n",
count, ptr->Stream, ptr->Offset, ptr->Type, ptr->Method, ptr->Usage, ptr->UsageIndex);
ptr++;
count++;
}
}
static int compare_elements(
IDirect3DVertexDeclaration9 *decl,
const D3DVERTEXELEMENT9 *expected_elements) {
HRESULT hr;
unsigned int i, size;
D3DVERTEXELEMENT9 last = D3DDECL_END();
D3DVERTEXELEMENT9 *elements = NULL;
/* How many elements are there? */
hr = IDirect3DVertexDeclaration9_GetDeclaration( decl, NULL, &size );
ok(SUCCEEDED(hr), "GetDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
if (FAILED(hr)) goto fail;
/* Allocate buffer */
elements = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(D3DVERTEXELEMENT9) * size);
ok (elements != NULL, "Out of memory, aborting test\n");
if (elements == NULL) goto fail;
/* Get the elements */
hr = IDirect3DVertexDeclaration9_GetDeclaration( decl, elements, &size);
ok(SUCCEEDED(hr), "GetDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
if (FAILED(hr)) goto fail;
/* Compare one by one */
for (i = 0; i < size; i++) {
int status;
int end1 = memcmp(&elements[i], &last, sizeof(D3DVERTEXELEMENT9));
int end2 = memcmp(&expected_elements[i], &last, sizeof(D3DVERTEXELEMENT9));
status = ((end1 && !end2) || (!end1 && end2));
ok (!status, "Mismatch in size, test declaration is %s than expected\n",
(end1 && !end2) ? "shorter" : "longer");
if (status) { print_elements(elements); goto fail; }
status = memcmp(&elements[i], &expected_elements[i], sizeof(D3DVERTEXELEMENT9));
ok (!status, "Mismatch in element %d\n", i);
if (status) { print_elements(elements); goto fail; }
}
HeapFree(GetProcessHeap(), 0, elements);
return S_OK;
fail:
HeapFree(GetProcessHeap(), 0, elements);
return E_FAIL;
}
static IDirect3DVertexDeclaration9 *test_create_vertex_declaration(IDirect3DDevice9 *device_ptr, D3DVERTEXELEMENT9 *vertex_decl)
{
IDirect3DVertexDeclaration9 *decl_ptr = 0;
HRESULT hret = 0;
hret = IDirect3DDevice9_CreateVertexDeclaration(device_ptr, vertex_decl, &decl_ptr);
ok(hret == D3D_OK && decl_ptr != NULL, "CreateVertexDeclaration returned: hret 0x%x, decl_ptr %p. "
"Expected hret 0x%x, decl_ptr != %p. Aborting.\n", hret, decl_ptr, D3D_OK, NULL);
return decl_ptr;
}
static void test_get_set_vertex_declaration(IDirect3DDevice9 *device_ptr, IDirect3DVertexDeclaration9 *decl_ptr)
{
IDirect3DVertexDeclaration9 *current_decl_ptr = 0;
HRESULT hret = 0;
int decl_refcount = 0;
int i = 0;
/* SetVertexDeclaration should not touch the declaration's refcount. */
i = get_refcount((IUnknown *)decl_ptr);
hret = IDirect3DDevice9_SetVertexDeclaration(device_ptr, decl_ptr);
decl_refcount = get_refcount((IUnknown *)decl_ptr);
ok(hret == D3D_OK && decl_refcount == i, "SetVertexDeclaration returned: hret 0x%x, refcount %d. "
"Expected hret 0x%x, refcount %d.\n", hret, decl_refcount, D3D_OK, i);
/* GetVertexDeclaration should increase the declaration's refcount by one. */
i = decl_refcount+1;
hret = IDirect3DDevice9_GetVertexDeclaration(device_ptr, &current_decl_ptr);
decl_refcount = get_refcount((IUnknown *)decl_ptr);
ok(hret == D3D_OK && decl_refcount == i && current_decl_ptr == decl_ptr,
"GetVertexDeclaration returned: hret 0x%x, current_decl_ptr %p refcount %d. "
"Expected hret 0x%x, current_decl_ptr %p, refcount %d.\n", hret, current_decl_ptr, decl_refcount, D3D_OK, decl_ptr, i);
IDirect3DVertexDeclaration9_Release(current_decl_ptr);
}
static void test_get_declaration(IDirect3DVertexDeclaration9 *decl_ptr, D3DVERTEXELEMENT9 *vertex_decl, UINT expected_num_elements)
{
int i;
UINT num_elements = 0;
D3DVERTEXELEMENT9 *decl = 0;
HRESULT hret = 0;
/* First test only getting the number of elements */
num_elements = 0x1337c0de;
hret = IDirect3DVertexDeclaration9_GetDeclaration(decl_ptr, NULL, &num_elements);
ok(hret == D3D_OK && num_elements == expected_num_elements,
"GetDeclaration returned: hret 0x%x, num_elements %d. "
"Expected hret 0x%x, num_elements %d.\n", hret, num_elements, D3D_OK, expected_num_elements);
num_elements = 0;
hret = IDirect3DVertexDeclaration9_GetDeclaration(decl_ptr, NULL, &num_elements);
ok(hret == D3D_OK && num_elements == expected_num_elements,
"GetDeclaration returned: hret 0x%x, num_elements %d. "
"Expected hret 0x%x, num_elements %d.\n", hret, num_elements, D3D_OK, expected_num_elements);
/* Also test the returned data */
decl = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(D3DVERTEXELEMENT9) * expected_num_elements);
num_elements = 0x1337c0de;
hret = IDirect3DVertexDeclaration9_GetDeclaration(decl_ptr, decl, &num_elements);
ok(hret == D3D_OK && num_elements == expected_num_elements,
"GetDeclaration returned: hret 0x%x, num_elements %d. "
"Expected hret 0x%x, num_elements %d.\n", hret, num_elements, D3D_OK, expected_num_elements);
i = memcmp(decl, vertex_decl, num_elements * sizeof(*vertex_decl));
ok (!i, "Original and returned vertexdeclarations are not the same\n");
ZeroMemory(decl, sizeof(D3DVERTEXELEMENT9) * expected_num_elements);
num_elements = 0;
hret = IDirect3DVertexDeclaration9_GetDeclaration(decl_ptr, decl, &num_elements);
ok(hret == D3D_OK && num_elements == expected_num_elements,
"GetDeclaration returned: hret 0x%x, num_elements %d. "
"Expected hret 0x%x, num_elements %d.\n", hret, num_elements, D3D_OK, expected_num_elements);
i = memcmp(decl, vertex_decl, num_elements * sizeof(*vertex_decl));
ok (!i, "Original and returned vertexdeclarations are not the same\n");
HeapFree(GetProcessHeap(), 0, decl);
}
/* FIXME: also write a test, which shows that attempting to set
* an invalid vertex declaration returns E_FAIL */
static HRESULT test_fvf_to_decl(IDirect3DDevice9 *device, IDirect3DVertexDeclaration9 *default_decl,
DWORD test_fvf, const D3DVERTEXELEMENT9 expected_elements[], char object_should_change)
{
HRESULT hr;
IDirect3DVertexDeclaration9 *result_decl = NULL;
/* Set a default declaration to make sure it is changed */
hr = IDirect3DDevice9_SetVertexDeclaration ( device, default_decl );
ok (SUCCEEDED(hr), "SetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
if (FAILED(hr)) goto fail;
/* Set an FVF */
hr = IDirect3DDevice9_SetFVF( device, test_fvf);
ok(SUCCEEDED(hr), "SetFVF returned %#x, expected %#x\n", hr, D3D_OK);
if (FAILED(hr)) goto fail;
/* Check if the declaration object changed underneath */
hr = IDirect3DDevice9_GetVertexDeclaration ( device, &result_decl);
ok(SUCCEEDED(hr), "GetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
if (FAILED(hr)) goto fail;
if (object_should_change) {
ok(result_decl != default_decl, "result declaration matches original\n");
if (result_decl == default_decl) goto fail;
} else {
ok(result_decl == default_decl, "result declaration does not match original\n");
if (result_decl != default_decl) goto fail;
}
/* Declaration content/size test */
ok(result_decl != NULL, "result declaration was null\n");
if (result_decl == NULL)
goto fail;
else if (compare_elements(result_decl, expected_elements) != S_OK)
goto fail;
if (result_decl) IDirect3DVertexDeclaration9_Release( result_decl );
return S_OK;
fail:
if (result_decl) IDirect3DVertexDeclaration9_Release( result_decl );
return E_FAIL;
}
static HRESULT test_decl_to_fvf(IDirect3DDevice9* device, DWORD default_fvf,
const D3DVERTEXELEMENT9 test_decl[], DWORD test_fvf, BOOL todo)
{
HRESULT hr;
IDirect3DVertexDeclaration9 *vdecl = NULL;
DWORD result_fvf = 0xdeadbeef;
/* Set a default FVF of SPECULAR and DIFFUSE to make sure it is changed back to 0 */
hr = IDirect3DDevice9_SetFVF( device, default_fvf);
ok(SUCCEEDED(hr), "SetFVF returned %#x, expected %#x\n", hr, D3D_OK);
if (FAILED(hr)) goto fail;
/* Create a testing declaration */
hr = IDirect3DDevice9_CreateVertexDeclaration( device, test_decl, &vdecl );
ok(SUCCEEDED(hr), "CreateVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
if (FAILED(hr)) goto fail;
/* Set the declaration */
hr = IDirect3DDevice9_SetVertexDeclaration ( device, vdecl );
ok (SUCCEEDED(hr), "SetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
if (FAILED(hr)) goto fail;
/* Check the FVF */
hr = IDirect3DDevice9_GetFVF( device, &result_fvf);
ok(SUCCEEDED(hr), "GetFVF returned %#x, expected %#x\n", hr, D3D_OK);
if (FAILED(hr)) goto fail;
if (todo) todo_wine ok(test_fvf == result_fvf, "result FVF was: %#x, expected: %#x\n", result_fvf, test_fvf);
else ok(test_fvf == result_fvf, "result FVF was: %#x, expected: %#x\n", result_fvf, test_fvf);
if (test_fvf != result_fvf) goto fail;
IDirect3DDevice9_SetVertexDeclaration ( device, NULL );
if (vdecl) IDirect3DVertexDeclaration9_Release( vdecl );
return S_OK;
fail:
IDirect3DDevice9_SetVertexDeclaration ( device, NULL );
if (vdecl) IDirect3DVertexDeclaration9_Release( vdecl );
return E_FAIL;
}
static void test_fvf_decl_conversion(IDirect3DDevice9 *pDevice)
{
HRESULT hr;
unsigned int i;
IDirect3DVertexDeclaration9* default_decl = NULL;
DWORD default_fvf = D3DFVF_SPECULAR | D3DFVF_DIFFUSE;
static const D3DVERTEXELEMENT9 default_elements[] =
{ { 0, 0, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 0 },
{ 0, 4, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 1 }, D3DDECL_END() };
/* Create a default declaration and FVF that does not match any of the tests */
hr = IDirect3DDevice9_CreateVertexDeclaration( pDevice, default_elements, &default_decl );
ok(SUCCEEDED(hr), "CreateVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
if (FAILED(hr)) goto cleanup;
/* Test conversions from vertex declaration to an FVF.
* For some reason those seem to occur only for POSITION/POSITIONT,
* Otherwise the FVF is forced to 0 - maybe this is configuration specific */
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, D3DDECL_END() };
VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, D3DFVF_XYZ, TRUE));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_POSITIONT, 0 }, D3DDECL_END() };
VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, D3DFVF_XYZRHW, TRUE));
}
for (i = 0; i < 4; ++i)
{
const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT1 + i, 0, D3DDECLUSAGE_BLENDWEIGHT, 0}, D3DDECL_END() };
VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0}, D3DDECL_END() };
VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_NORMAL, 0 }, D3DDECL_END() };
VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_PSIZE, 0 }, D3DDECL_END() };
VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 0 }, D3DDECL_END() };
VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 1 }, D3DDECL_END() };
VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
}
/* Make sure textures of different sizes work */
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() };
VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() };
VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() };
VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() };
VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
}
/* Make sure the TEXCOORD index works correctly - try several textures */
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_TEXCOORD, 0 },
{ 0, 4, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_TEXCOORD, 1 },
{ 0, 16, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_TEXCOORD, 2 },
{ 0, 24, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_TEXCOORD, 3 }, D3DDECL_END() };
VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
}
/* No FVF mapping available */
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 1 }, D3DDECL_END() };
VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_NORMAL, 1 }, D3DDECL_END() };
VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
}
/* Try empty declaration */
{
static const D3DVERTEXELEMENT9 test_buffer[] = { D3DDECL_END() };
VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
}
/* Now try a combination test */
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITIONT, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_NORMAL, 0 },
{ 0, 24, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_PSIZE, 0 },
{ 0, 28, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 1 },
{ 0, 32, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_TEXCOORD, 0 },
{ 0, 44, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_TEXCOORD, 1 }, D3DDECL_END() };
VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
}
/* Test conversions from FVF to a vertex declaration
* These seem to always occur internally. A new declaration object is created if necessary */
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZ, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_POSITION, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZW, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_POSITIONT, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZRHW, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 },
{ 0, 28, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
D3DFVF_XYZB5 | D3DFVF_LASTBETA_UBYTE4, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 },
{ 0, 28, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
D3DFVF_XYZB5 | D3DFVF_LASTBETA_D3DCOLOR, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 },
{ 0, 28, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB5, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB1, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
D3DFVF_XYZB1 | D3DFVF_LASTBETA_UBYTE4, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
D3DFVF_XYZB1 | D3DFVF_LASTBETA_D3DCOLOR, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB2, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 },
{ 0, 16, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
D3DFVF_XYZB2 | D3DFVF_LASTBETA_UBYTE4, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 },
{ 0, 16, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
D3DFVF_XYZB2 | D3DFVF_LASTBETA_D3DCOLOR, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB3, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 },
{ 0, 20, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
D3DFVF_XYZB3 | D3DFVF_LASTBETA_UBYTE4, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 },
{ 0, 20, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
D3DFVF_XYZB3 | D3DFVF_LASTBETA_D3DCOLOR, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB4, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 },
{ 0, 24, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
D3DFVF_XYZB4 | D3DFVF_LASTBETA_UBYTE4, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 },
{ 0, 24, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
D3DFVF_XYZB4 | D3DFVF_LASTBETA_D3DCOLOR, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_NORMAL, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_NORMAL, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_PSIZE, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_PSIZE, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_DIFFUSE, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 1 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_SPECULAR, test_buffer, 1));
}
/* Make sure textures of different sizes work */
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
D3DFVF_TEXCOORDSIZE1(0) | D3DFVF_TEX1, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEX1, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1, test_buffer, 1));
}
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
D3DFVF_TEXCOORDSIZE4(0) | D3DFVF_TEX1, test_buffer, 1));
}
/* Make sure the TEXCOORD index works correctly - try several textures */
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_TEXCOORD, 0 },
{ 0, 4, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_TEXCOORD, 1 },
{ 0, 16, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_TEXCOORD, 2 },
{ 0, 24, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_TEXCOORD, 3 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
D3DFVF_TEXCOORDSIZE1(0) | D3DFVF_TEXCOORDSIZE3(1) | D3DFVF_TEXCOORDSIZE2(2) |
D3DFVF_TEXCOORDSIZE4(3) | D3DFVF_TEX4, test_buffer, 1));
}
/* Now try a combination test */
{
static const D3DVERTEXELEMENT9 test_buffer[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 },
{ 0, 28, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 0 },
{ 0, 32, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 1 },
{ 0, 36, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_TEXCOORD, 0 },
{ 0, 44, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_TEXCOORD, 1 }, D3DDECL_END() };
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB4 | D3DFVF_SPECULAR | D3DFVF_DIFFUSE |
D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEXCOORDSIZE3(1) | D3DFVF_TEX2, test_buffer, 1));
}
/* Setting the FVF to 0 should result in no change to the default decl */
VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, 0, default_elements, 0));
cleanup:
IDirect3DDevice9_SetVertexDeclaration ( pDevice, NULL );
if ( default_decl ) IDirect3DVertexDeclaration9_Release (default_decl);
}
/* Check whether a declaration converted from FVF is shared.
* Check whether refcounts behave as expected */
static void test_fvf_decl_management(
IDirect3DDevice9* device) {
HRESULT hr;
IDirect3DVertexDeclaration9* result_decl1 = NULL;
IDirect3DVertexDeclaration9* result_decl2 = NULL;
IDirect3DVertexDeclaration9* result_decl3 = NULL;
IDirect3DVertexDeclaration9* result_decl4 = NULL;
int ref1, ref2, ref3, ref4;
DWORD test_fvf1 = D3DFVF_XYZRHW;
DWORD test_fvf2 = D3DFVF_NORMAL;
static const D3DVERTEXELEMENT9 test_elements1[] =
{ { 0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_POSITIONT, 0 }, D3DDECL_END() };
static const D3DVERTEXELEMENT9 test_elements2[] =
{ { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_NORMAL, 0 }, D3DDECL_END() };
/* Clear down any current vertex declaration */
hr = IDirect3DDevice9_SetVertexDeclaration ( device, NULL );
ok (SUCCEEDED(hr), "SetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
if (FAILED(hr)) return;
/* Conversion */
hr = IDirect3DDevice9_SetFVF( device, test_fvf1);
ok(SUCCEEDED(hr), "SetFVF returned %#x, expected %#x\n", hr, D3D_OK);
if (FAILED(hr)) return;
/* Get converted decl (#1) */
hr = IDirect3DDevice9_GetVertexDeclaration ( device, &result_decl1);
ok(SUCCEEDED(hr), "GetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
if (FAILED(hr)) return;
/* Get converted decl again (#2) */
hr = IDirect3DDevice9_GetVertexDeclaration ( device, &result_decl2);
ok(SUCCEEDED(hr), "GetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
if (FAILED(hr)) return;
/* Conversion */
hr = IDirect3DDevice9_SetFVF( device, test_fvf2);
ok(SUCCEEDED(hr), "SetFVF returned %#x, expected %#x\n", hr, D3D_OK);
if (FAILED(hr)) return;
/* The contents should correspond to the first conversion */
VDECL_CHECK(compare_elements(result_decl1, test_elements1));
/* Get converted decl (#3) */
hr = IDirect3DDevice9_GetVertexDeclaration ( device, &result_decl3);
ok(SUCCEEDED(hr), "GetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
if (FAILED(hr)) return;
/* The object should be the same */
ok (result_decl1 == result_decl2, "Declaration object changes on the second Get() call\n");
ok (result_decl2 != result_decl3, "Declaration object did not change during conversion\n");
/* The contents should correspond to the second conversion */
VDECL_CHECK(compare_elements(result_decl3, test_elements2));
/* Re-Check if the first decl was overwritten by the new Get() */
VDECL_CHECK(compare_elements(result_decl1, test_elements1));
hr = IDirect3DDevice9_SetFVF( device, test_fvf1);
ok(SUCCEEDED(hr), "SetFVF returned %#x, expected %#x\n", hr, D3D_OK);
if (FAILED(hr)) return;
hr = IDirect3DDevice9_GetVertexDeclaration ( device, &result_decl4);
ok(SUCCEEDED(hr), "GetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
if (FAILED(hr)) return;
ok(result_decl4 == result_decl1, "Setting an already used FVF over results in a different vertexdeclaration\n");
ref1 = get_refcount((IUnknown*) result_decl1);
ref2 = get_refcount((IUnknown*) result_decl2);
ref3 = get_refcount((IUnknown*) result_decl3);
ref4 = get_refcount((IUnknown*) result_decl4);
ok (ref1 == 3, "Refcount #1 is %d, expected 3\n", ref1);
ok (ref2 == 3, "Refcount #2 is %d, expected 3\n", ref2);
ok (ref3 == 1, "Refcount #3 is %d, expected 1\n", ref3);
ok (ref4 == 3, "Refcount #4 is %d, expected 3\n", ref4);
/* Clear down any current vertex declaration */
hr = IDirect3DDevice9_SetVertexDeclaration ( device, NULL );
ok (SUCCEEDED(hr), "SetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
if (FAILED(hr)) return;
IDirect3DVertexDeclaration9_Release(result_decl1);
IDirect3DVertexDeclaration9_Release(result_decl2);
IDirect3DVertexDeclaration9_Release(result_decl3);
IDirect3DVertexDeclaration9_Release(result_decl4);
return;
}
static void test_vertex_declaration_alignment(
IDirect3DDevice9* device) {
HRESULT hr;
IDirect3DVertexDeclaration9* result_decl = NULL;
unsigned int i;
static const D3DVERTEXELEMENT9 test_elements[5][3] =
{
{
{ 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 16, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR , 0 },
D3DDECL_END()
},
{
{ 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 17, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR , 0 },
D3DDECL_END()
},
{
{ 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 18, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR , 0 },
D3DDECL_END()
},
{
{ 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 19, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR , 0 },
D3DDECL_END()
},
{
{ 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 20, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR , 0 },
D3DDECL_END()
}
};
HRESULT results[5] = {D3D_OK, E_FAIL, E_FAIL, E_FAIL, D3D_OK};
for(i = 0; i < sizeof(test_elements) / sizeof(test_elements[0]); i++) {
result_decl = NULL;
hr = IDirect3DDevice9_CreateVertexDeclaration(device, test_elements[i], &result_decl);
ok(hr == results[i], "CreateVertexDeclaration for declaration %d returned %#x, expected %#x\n",
i, hr, results[i]);
if(result_decl) IDirect3DVertexDeclaration9_Release(result_decl);
}
}
static void test_unused_type(
IDirect3DDevice9* device) {
HRESULT hr;
IDirect3DVertexDeclaration9* result_decl = NULL;
unsigned int i;
static const D3DVERTEXELEMENT9 test_elements[][3] =
{
{
{ 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_COLOR , 0 },
D3DDECL_END()
},
{
{ 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_TEXCOORD, 0 },
D3DDECL_END()
},
{
{ 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_TEXCOORD, 1 },
D3DDECL_END()
},
{
{ 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_TEXCOORD, 12},
D3DDECL_END()
},
{
{ 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 1, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_TEXCOORD, 12},
D3DDECL_END()
},
{
{ 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 0, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_NORMAL, 0 },
D3DDECL_END()
},
{
{ 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
{ 1, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_NORMAL, 0 },
D3DDECL_END()
},
};
for(i = 0; i < sizeof(test_elements) / sizeof(test_elements[0]); i++) {
result_decl = NULL;
hr = IDirect3DDevice9_CreateVertexDeclaration(device, test_elements[i], &result_decl);
ok(hr == E_FAIL, "CreateVertexDeclaration for declaration %d returned %#x, expected E_FAIL(%#x)\n",
i, hr, E_FAIL);
if(result_decl) IDirect3DVertexDeclaration9_Release(result_decl);
}
}
START_TEST(vertexdeclaration)
{
static D3DVERTEXELEMENT9 simple_decl[] = {
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
D3DDECL_END()};
UINT simple_decl_num_elements = sizeof(simple_decl) / sizeof(*simple_decl);
IDirect3DDevice9 *device_ptr = 0;
IDirect3DVertexDeclaration9 *decl_ptr = 0;
ULONG refcount;
if (!(device_ptr = init_d3d9()))
{
skip("Failed to initialise d3d9\n");
return;
}
decl_ptr = test_create_vertex_declaration(device_ptr, simple_decl);
if (!decl_ptr)
{
skip("Failed to create a vertex declaration\n");
return;
}
test_get_set_vertex_declaration(device_ptr, decl_ptr);
test_get_declaration(decl_ptr, simple_decl, simple_decl_num_elements);
test_fvf_decl_conversion(device_ptr);
test_fvf_decl_management(device_ptr);
test_vertex_declaration_alignment(device_ptr);
test_unused_type(device_ptr);
IDirect3DVertexDeclaration9_Release(decl_ptr);
refcount = IDirect3DDevice9_Release(device_ptr);
ok(!refcount, "Device has %u references left\n", refcount);
}