quartz: Free two assert calls from having side effects.
[wine/testsucceed.git] / dlls / d3d9 / tests / vertexdeclaration.c
blob9d507a144aa1f54f6ca62707f5d399bde783f676
1 /*
2 * Copyright (C) 2005 Henri Verbeet
3 * Copyright (C) 2006 Ivan Gyurdiev
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #define COBJMACROS
21 #include <d3d9.h>
22 #include "wine/test.h"
24 static HMODULE d3d9_handle = 0;
26 #define VDECL_CHECK(fcall) \
27 if(fcall != S_OK) \
28 trace(" Test failed on line #%d\n", __LINE__);
30 static HWND create_window(void)
32 WNDCLASS wc = {0};
33 wc.lpfnWndProc = DefWindowProc;
34 wc.lpszClassName = "d3d9_test_wc";
35 RegisterClass(&wc);
37 return CreateWindow("d3d9_test_wc", "d3d9_test",
38 0, 0, 0, 0, 0, 0, 0, 0, 0);
41 static IDirect3DDevice9 *init_d3d9(void)
43 IDirect3D9 * (__stdcall * d3d9_create)(UINT SDKVersion) = 0;
44 IDirect3D9 *d3d9_ptr = 0;
45 IDirect3DDevice9 *device_ptr = 0;
46 D3DPRESENT_PARAMETERS present_parameters;
47 HRESULT hres;
49 d3d9_create = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
50 ok(d3d9_create != NULL, "Failed to get address of Direct3DCreate9\n");
51 if (!d3d9_create) return NULL;
53 d3d9_ptr = d3d9_create(D3D_SDK_VERSION);
54 if (!d3d9_ptr)
56 skip("could not create D3D9\n");
57 return NULL;
60 ZeroMemory(&present_parameters, sizeof(present_parameters));
61 present_parameters.Windowed = TRUE;
62 present_parameters.hDeviceWindow = create_window();
63 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
65 hres = IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
67 if(FAILED(hres))
69 hres = IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, NULL, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
70 if(FAILED(hres))
72 trace("could not create device, IDirect3D9_CreateDevice returned %#x\n", hres);
73 return NULL;
77 return device_ptr;
80 static int get_refcount(IUnknown *object)
82 IUnknown_AddRef(object);
83 return IUnknown_Release(object);
86 static inline void print_elements(
87 D3DVERTEXELEMENT9 *elements) {
89 D3DVERTEXELEMENT9 last = D3DDECL_END();
90 D3DVERTEXELEMENT9 *ptr = elements;
91 int count = 0;
93 while (memcmp(ptr, &last, sizeof(D3DVERTEXELEMENT9))) {
95 trace(
96 "[Element %d] Stream = %d, Offset = %d, Type = %d, Method = %d, Usage = %d, UsageIndex = %d\n",
97 count, ptr->Stream, ptr->Offset, ptr->Type, ptr->Method, ptr->Usage, ptr->UsageIndex);
99 ptr++;
100 count++;
104 static int compare_elements(
105 IDirect3DVertexDeclaration9 *decl,
106 const D3DVERTEXELEMENT9 *expected_elements) {
108 HRESULT hr;
109 unsigned int i, size;
110 D3DVERTEXELEMENT9 last = D3DDECL_END();
111 D3DVERTEXELEMENT9 *elements = NULL;
113 /* How many elements are there? */
114 hr = IDirect3DVertexDeclaration9_GetDeclaration( decl, NULL, &size );
115 ok(SUCCEEDED(hr), "GetDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
116 if (FAILED(hr)) goto fail;
118 /* Allocate buffer */
119 elements = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(D3DVERTEXELEMENT9) * size);
120 ok (elements != NULL, "Out of memory, aborting test\n");
121 if (elements == NULL) goto fail;
123 /* Get the elements */
124 hr = IDirect3DVertexDeclaration9_GetDeclaration( decl, elements, &size);
125 ok(SUCCEEDED(hr), "GetDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
126 if (FAILED(hr)) goto fail;
128 /* Compare one by one */
129 for (i = 0; i < size; i++) {
131 int status;
133 int end1 = memcmp(&elements[i], &last, sizeof(D3DVERTEXELEMENT9));
134 int end2 = memcmp(&expected_elements[i], &last, sizeof(D3DVERTEXELEMENT9));
135 status = ((end1 && !end2) || (!end1 && end2));
136 ok (!status, "Mismatch in size, test declaration is %s than expected\n",
137 (end1 && !end2) ? "shorter" : "longer");
138 if (status) { print_elements(elements); goto fail; }
140 status = memcmp(&elements[i], &expected_elements[i], sizeof(D3DVERTEXELEMENT9));
141 ok (!status, "Mismatch in element %d\n", i);
142 if (status) { print_elements(elements); goto fail; }
145 HeapFree(GetProcessHeap(), 0, elements);
146 return S_OK;
148 fail:
149 HeapFree(GetProcessHeap(), 0, elements);
150 return E_FAIL;
153 static IDirect3DVertexDeclaration9 *test_create_vertex_declaration(IDirect3DDevice9 *device_ptr, D3DVERTEXELEMENT9 *vertex_decl)
155 IDirect3DVertexDeclaration9 *decl_ptr = 0;
156 HRESULT hret = 0;
158 hret = IDirect3DDevice9_CreateVertexDeclaration(device_ptr, vertex_decl, &decl_ptr);
159 ok(hret == D3D_OK && decl_ptr != NULL, "CreateVertexDeclaration returned: hret 0x%x, decl_ptr %p. "
160 "Expected hret 0x%x, decl_ptr != %p. Aborting.\n", hret, decl_ptr, D3D_OK, NULL);
162 return decl_ptr;
165 static void test_get_set_vertex_declaration(IDirect3DDevice9 *device_ptr, IDirect3DVertexDeclaration9 *decl_ptr)
167 IDirect3DVertexDeclaration9 *current_decl_ptr = 0;
168 HRESULT hret = 0;
169 int decl_refcount = 0;
170 int i = 0;
172 /* SetVertexDeclaration should not touch the declaration's refcount. */
173 i = get_refcount((IUnknown *)decl_ptr);
174 hret = IDirect3DDevice9_SetVertexDeclaration(device_ptr, decl_ptr);
175 decl_refcount = get_refcount((IUnknown *)decl_ptr);
176 ok(hret == D3D_OK && decl_refcount == i, "SetVertexDeclaration returned: hret 0x%x, refcount %d. "
177 "Expected hret 0x%x, refcount %d.\n", hret, decl_refcount, D3D_OK, i);
179 /* GetVertexDeclaration should increase the declaration's refcount by one. */
180 i = decl_refcount+1;
181 hret = IDirect3DDevice9_GetVertexDeclaration(device_ptr, &current_decl_ptr);
182 decl_refcount = get_refcount((IUnknown *)decl_ptr);
183 ok(hret == D3D_OK && decl_refcount == i && current_decl_ptr == decl_ptr,
184 "GetVertexDeclaration returned: hret 0x%x, current_decl_ptr %p refcount %d. "
185 "Expected hret 0x%x, current_decl_ptr %p, refcount %d.\n", hret, current_decl_ptr, decl_refcount, D3D_OK, decl_ptr, i);
186 IDirect3DVertexDeclaration9_Release(current_decl_ptr);
189 static void test_get_declaration(IDirect3DVertexDeclaration9 *decl_ptr, D3DVERTEXELEMENT9 *vertex_decl, UINT expected_num_elements)
191 int i;
192 UINT num_elements = 0;
193 D3DVERTEXELEMENT9 *decl = 0;
194 HRESULT hret = 0;
196 /* First test only getting the number of elements */
197 num_elements = 0x1337c0de;
198 hret = IDirect3DVertexDeclaration9_GetDeclaration(decl_ptr, NULL, &num_elements);
199 ok(hret == D3D_OK && num_elements == expected_num_elements,
200 "GetDeclaration returned: hret 0x%x, num_elements %d. "
201 "Expected hret 0x%x, num_elements %d.\n", hret, num_elements, D3D_OK, expected_num_elements);
203 num_elements = 0;
204 hret = IDirect3DVertexDeclaration9_GetDeclaration(decl_ptr, NULL, &num_elements);
205 ok(hret == D3D_OK && num_elements == expected_num_elements,
206 "GetDeclaration returned: hret 0x%x, num_elements %d. "
207 "Expected hret 0x%x, num_elements %d.\n", hret, num_elements, D3D_OK, expected_num_elements);
209 /* Also test the returned data */
210 decl = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(D3DVERTEXELEMENT9) * expected_num_elements);
212 num_elements = 0x1337c0de;
213 hret = IDirect3DVertexDeclaration9_GetDeclaration(decl_ptr, decl, &num_elements);
214 ok(hret == D3D_OK && num_elements == expected_num_elements,
215 "GetDeclaration returned: hret 0x%x, num_elements %d. "
216 "Expected hret 0x%x, num_elements %d.\n", hret, num_elements, D3D_OK, expected_num_elements);
217 i = memcmp(decl, vertex_decl, num_elements * sizeof(*vertex_decl));
218 ok (!i, "Original and returned vertexdeclarations are not the same\n");
219 ZeroMemory(decl, sizeof(D3DVERTEXELEMENT9) * expected_num_elements);
221 num_elements = 0;
222 hret = IDirect3DVertexDeclaration9_GetDeclaration(decl_ptr, decl, &num_elements);
223 ok(hret == D3D_OK && num_elements == expected_num_elements,
224 "GetDeclaration returned: hret 0x%x, num_elements %d. "
225 "Expected hret 0x%x, num_elements %d.\n", hret, num_elements, D3D_OK, expected_num_elements);
226 i = memcmp(decl, vertex_decl, num_elements * sizeof(*vertex_decl));
227 ok (!i, "Original and returned vertexdeclarations are not the same\n");
229 HeapFree(GetProcessHeap(), 0, decl);
232 /* FIXME: also write a test, which shows that attempting to set
233 * an invalid vertex declaration returns E_FAIL */
234 static HRESULT test_fvf_to_decl(IDirect3DDevice9 *device, IDirect3DVertexDeclaration9 *default_decl,
235 DWORD test_fvf, const D3DVERTEXELEMENT9 expected_elements[], char object_should_change)
238 HRESULT hr;
239 IDirect3DVertexDeclaration9 *result_decl = NULL;
241 /* Set a default declaration to make sure it is changed */
242 hr = IDirect3DDevice9_SetVertexDeclaration ( device, default_decl );
243 ok (SUCCEEDED(hr), "SetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
244 if (FAILED(hr)) goto fail;
246 /* Set an FVF */
247 hr = IDirect3DDevice9_SetFVF( device, test_fvf);
248 ok(SUCCEEDED(hr), "SetFVF returned %#x, expected %#x\n", hr, D3D_OK);
249 if (FAILED(hr)) goto fail;
251 /* Check if the declaration object changed underneath */
252 hr = IDirect3DDevice9_GetVertexDeclaration ( device, &result_decl);
253 ok(SUCCEEDED(hr), "GetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
254 if (FAILED(hr)) goto fail;
255 if (object_should_change) {
256 ok(result_decl != default_decl, "result declaration matches original\n");
257 if (result_decl == default_decl) goto fail;
258 } else {
259 ok(result_decl == default_decl, "result declaration does not match original\n");
260 if (result_decl != default_decl) goto fail;
263 /* Declaration content/size test */
264 ok(result_decl != NULL, "result declaration was null\n");
265 if (result_decl == NULL)
266 goto fail;
267 else if (compare_elements(result_decl, expected_elements) != S_OK)
268 goto fail;
270 if (result_decl) IUnknown_Release( result_decl );
271 return S_OK;
273 fail:
274 if (result_decl) IUnknown_Release( result_decl );
275 return E_FAIL;
278 static HRESULT test_decl_to_fvf(IDirect3DDevice9* device, DWORD default_fvf,
279 const D3DVERTEXELEMENT9 test_decl[], DWORD test_fvf, BOOL todo)
282 HRESULT hr;
283 IDirect3DVertexDeclaration9 *vdecl = NULL;
285 DWORD result_fvf = 0xdeadbeef;
287 /* Set a default FVF of SPECULAR and DIFFUSE to make sure it is changed back to 0 */
288 hr = IDirect3DDevice9_SetFVF( device, default_fvf);
289 ok(SUCCEEDED(hr), "SetFVF returned %#x, expected %#x\n", hr, D3D_OK);
290 if (FAILED(hr)) goto fail;
292 /* Create a testing declaration */
293 hr = IDirect3DDevice9_CreateVertexDeclaration( device, test_decl, &vdecl );
294 ok(SUCCEEDED(hr), "CreateVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
295 if (FAILED(hr)) goto fail;
297 /* Set the declaration */
298 hr = IDirect3DDevice9_SetVertexDeclaration ( device, vdecl );
299 ok (SUCCEEDED(hr), "SetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
300 if (FAILED(hr)) goto fail;
302 /* Check the FVF */
303 hr = IDirect3DDevice9_GetFVF( device, &result_fvf);
304 ok(SUCCEEDED(hr), "GetFVF returned %#x, expected %#x\n", hr, D3D_OK);
305 if (FAILED(hr)) goto fail;
306 if (todo) todo_wine ok(test_fvf == result_fvf, "result FVF was: %#x, expected: %#x\n", result_fvf, test_fvf);
307 else ok(test_fvf == result_fvf, "result FVF was: %#x, expected: %#x\n", result_fvf, test_fvf);
308 if (test_fvf != result_fvf) goto fail;
310 IDirect3DDevice9_SetVertexDeclaration ( device, NULL );
311 if (vdecl) IUnknown_Release( vdecl );
312 return S_OK;
314 fail:
315 IDirect3DDevice9_SetVertexDeclaration ( device, NULL );
316 if (vdecl) IUnknown_Release( vdecl );
317 return E_FAIL;
320 static void test_fvf_decl_conversion(IDirect3DDevice9 *pDevice)
323 HRESULT hr;
324 unsigned int i;
326 IDirect3DVertexDeclaration9* default_decl = NULL;
327 DWORD default_fvf = D3DFVF_SPECULAR | D3DFVF_DIFFUSE;
328 D3DVERTEXELEMENT9 default_elements[] =
329 { { 0, 0, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 0 },
330 { 0, 4, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 1 }, D3DDECL_END() };
332 /* Create a default declaration and FVF that does not match any of the tests */
333 hr = IDirect3DDevice9_CreateVertexDeclaration( pDevice, default_elements, &default_decl );
334 ok(SUCCEEDED(hr), "CreateVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
335 if (FAILED(hr)) goto cleanup;
337 /* Test conversions from vertex declaration to an FVF.
338 * For some reason those seem to occur only for POSITION/POSITIONT,
339 * Otherwise the FVF is forced to 0 - maybe this is configuration specific */
341 CONST D3DVERTEXELEMENT9 test_buffer[] =
342 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, D3DDECL_END() };
343 VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, D3DFVF_XYZ, TRUE));
346 CONST D3DVERTEXELEMENT9 test_buffer[] =
347 { { 0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_POSITIONT, 0 }, D3DDECL_END() };
348 VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, D3DFVF_XYZRHW, TRUE));
350 for (i = 0; i < 4; i++) {
351 CONST D3DVERTEXELEMENT9 test_buffer[] =
352 { { 0, 0, D3DDECLTYPE_FLOAT1+i, 0, D3DDECLUSAGE_BLENDWEIGHT, 0}, D3DDECL_END() };
353 VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
356 CONST D3DVERTEXELEMENT9 test_buffer[] =
357 { { 0, 0, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0}, D3DDECL_END() };
358 VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
361 CONST D3DVERTEXELEMENT9 test_buffer[] =
362 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_NORMAL, 0 }, D3DDECL_END() };
363 VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
366 CONST D3DVERTEXELEMENT9 test_buffer[] =
367 { { 0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_PSIZE, 0 }, D3DDECL_END() };
368 VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
371 CONST D3DVERTEXELEMENT9 test_buffer[] =
372 { { 0, 0, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 0 }, D3DDECL_END() };
373 VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
376 CONST D3DVERTEXELEMENT9 test_buffer[] =
377 { { 0, 0, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 1 }, D3DDECL_END() };
378 VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
381 /* Make sure textures of different sizes work */
383 CONST D3DVERTEXELEMENT9 test_buffer[] =
384 { { 0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() };
385 VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
388 CONST D3DVERTEXELEMENT9 test_buffer[] =
389 { { 0, 0, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() };
390 VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
393 CONST D3DVERTEXELEMENT9 test_buffer[] =
394 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() };
395 VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
398 CONST D3DVERTEXELEMENT9 test_buffer[] =
399 { { 0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() };
400 VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
403 /* Make sure the TEXCOORD index works correctly - try several textures */
405 CONST D3DVERTEXELEMENT9 test_buffer[] =
406 { { 0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_TEXCOORD, 0 },
407 { 0, 4, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_TEXCOORD, 1 },
408 { 0, 16, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_TEXCOORD, 2 },
409 { 0, 24, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_TEXCOORD, 3 }, D3DDECL_END() };
410 VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
413 /* No FVF mapping available */
415 CONST D3DVERTEXELEMENT9 test_buffer[] =
416 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 1 }, D3DDECL_END() };
417 VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
420 CONST D3DVERTEXELEMENT9 test_buffer[] =
421 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_NORMAL, 1 }, D3DDECL_END() };
422 VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
425 /* Try empty declaration */
427 CONST D3DVERTEXELEMENT9 test_buffer[] = { D3DDECL_END() };
428 VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
431 /* Now try a combination test */
433 CONST D3DVERTEXELEMENT9 test_buffer[] =
434 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITIONT, 0 },
435 { 0, 12, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_NORMAL, 0 },
436 { 0, 24, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_PSIZE, 0 },
437 { 0, 28, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 1 },
438 { 0, 32, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_TEXCOORD, 0 },
439 { 0, 44, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_TEXCOORD, 1 }, D3DDECL_END() };
440 VDECL_CHECK(test_decl_to_fvf(pDevice, default_fvf, test_buffer, 0, FALSE));
443 /* Test conversions from FVF to a vertex declaration
444 * These seem to always occur internally. A new declaration object is created if necessary */
447 CONST D3DVERTEXELEMENT9 test_buffer[] =
448 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 }, D3DDECL_END() };
449 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZ, test_buffer, 1));
452 CONST D3DVERTEXELEMENT9 test_buffer[] =
453 { { 0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_POSITION, 0 }, D3DDECL_END() };
454 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZW, test_buffer, 1));
457 CONST D3DVERTEXELEMENT9 test_buffer[] =
458 { { 0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_POSITIONT, 0 }, D3DDECL_END() };
459 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZRHW, test_buffer, 1));
462 CONST D3DVERTEXELEMENT9 test_buffer[] =
463 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
464 { 0, 12, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 },
465 { 0, 28, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() };
466 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
467 D3DFVF_XYZB5 | D3DFVF_LASTBETA_UBYTE4, test_buffer, 1));
470 CONST D3DVERTEXELEMENT9 test_buffer[] =
471 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
472 { 0, 12, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 },
473 { 0, 28, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() };
474 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
475 D3DFVF_XYZB5 | D3DFVF_LASTBETA_D3DCOLOR, test_buffer, 1));
478 CONST D3DVERTEXELEMENT9 test_buffer[] =
479 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
480 { 0, 12, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 },
481 { 0, 28, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() };
482 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB5, test_buffer, 1));
485 CONST D3DVERTEXELEMENT9 test_buffer[] =
486 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
487 { 0, 12, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 }, D3DDECL_END() };
488 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB1, test_buffer, 1));
491 CONST D3DVERTEXELEMENT9 test_buffer[] =
492 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
493 { 0, 12, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() };
494 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
495 D3DFVF_XYZB1 | D3DFVF_LASTBETA_UBYTE4, test_buffer, 1));
498 CONST D3DVERTEXELEMENT9 test_buffer[] =
499 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
500 { 0, 12, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() };
501 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
502 D3DFVF_XYZB1 | D3DFVF_LASTBETA_D3DCOLOR, test_buffer, 1));
505 CONST D3DVERTEXELEMENT9 test_buffer[] =
506 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
507 { 0, 12, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 }, D3DDECL_END() };
508 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB2, test_buffer, 1));
511 CONST D3DVERTEXELEMENT9 test_buffer[] =
512 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
513 { 0, 12, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 },
514 { 0, 16, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() };
515 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
516 D3DFVF_XYZB2 | D3DFVF_LASTBETA_UBYTE4, test_buffer, 1));
519 CONST D3DVERTEXELEMENT9 test_buffer[] =
520 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
521 { 0, 12, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 },
522 { 0, 16, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() };
523 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
524 D3DFVF_XYZB2 | D3DFVF_LASTBETA_D3DCOLOR, test_buffer, 1));
527 CONST D3DVERTEXELEMENT9 test_buffer[] =
528 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
529 { 0, 12, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 }, D3DDECL_END() };
530 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB3, test_buffer, 1));
533 CONST D3DVERTEXELEMENT9 test_buffer[] =
534 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
535 { 0, 12, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 },
536 { 0, 20, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() };
537 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
538 D3DFVF_XYZB3 | D3DFVF_LASTBETA_UBYTE4, test_buffer, 1));
541 CONST D3DVERTEXELEMENT9 test_buffer[] =
542 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
543 { 0, 12, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 },
544 { 0, 20, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() };
545 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
546 D3DFVF_XYZB3 | D3DFVF_LASTBETA_D3DCOLOR, test_buffer, 1));
549 CONST D3DVERTEXELEMENT9 test_buffer[] =
550 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
551 { 0, 12, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 }, D3DDECL_END() };
552 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB4, test_buffer, 1));
555 CONST D3DVERTEXELEMENT9 test_buffer[] =
556 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
557 { 0, 12, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 },
558 { 0, 24, D3DDECLTYPE_UBYTE4, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() };
559 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
560 D3DFVF_XYZB4 | D3DFVF_LASTBETA_UBYTE4, test_buffer, 1));
563 CONST D3DVERTEXELEMENT9 test_buffer[] =
564 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
565 { 0, 12, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 },
566 { 0, 24, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_BLENDINDICES, 0 }, D3DDECL_END() };
567 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
568 D3DFVF_XYZB4 | D3DFVF_LASTBETA_D3DCOLOR, test_buffer, 1));
571 CONST D3DVERTEXELEMENT9 test_buffer[] =
572 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_NORMAL, 0 }, D3DDECL_END() };
573 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_NORMAL, test_buffer, 1));
576 CONST D3DVERTEXELEMENT9 test_buffer[] =
577 { { 0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_PSIZE, 0 }, D3DDECL_END() };
578 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_PSIZE, test_buffer, 1));
581 CONST D3DVERTEXELEMENT9 test_buffer[] =
582 { { 0, 0, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 0 }, D3DDECL_END() };
583 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_DIFFUSE, test_buffer, 1));
586 CONST D3DVERTEXELEMENT9 test_buffer[] =
587 { { 0, 0, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 1 }, D3DDECL_END() };
588 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_SPECULAR, test_buffer, 1));
591 /* Make sure textures of different sizes work */
593 CONST D3DVERTEXELEMENT9 test_buffer[] =
594 { { 0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() };
595 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
596 D3DFVF_TEXCOORDSIZE1(0) | D3DFVF_TEX1, test_buffer, 1));
599 CONST D3DVERTEXELEMENT9 test_buffer[] =
600 { { 0, 0, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() };
601 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
602 D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEX1, test_buffer, 1));
605 CONST D3DVERTEXELEMENT9 test_buffer[] =
606 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() };
607 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
608 D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1, test_buffer, 1));
611 CONST D3DVERTEXELEMENT9 test_buffer[] =
612 { { 0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() };
613 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
614 D3DFVF_TEXCOORDSIZE4(0) | D3DFVF_TEX1, test_buffer, 1));
617 /* Make sure the TEXCOORD index works correctly - try several textures */
619 CONST D3DVERTEXELEMENT9 test_buffer[] =
620 { { 0, 0, D3DDECLTYPE_FLOAT1, 0, D3DDECLUSAGE_TEXCOORD, 0 },
621 { 0, 4, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_TEXCOORD, 1 },
622 { 0, 16, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_TEXCOORD, 2 },
623 { 0, 24, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_TEXCOORD, 3 }, D3DDECL_END() };
624 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl,
625 D3DFVF_TEXCOORDSIZE1(0) | D3DFVF_TEXCOORDSIZE3(1) | D3DFVF_TEXCOORDSIZE2(2) |
626 D3DFVF_TEXCOORDSIZE4(3) | D3DFVF_TEX4, test_buffer, 1));
629 /* Now try a combination test */
631 CONST D3DVERTEXELEMENT9 test_buffer[] =
632 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
633 { 0, 12, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_BLENDWEIGHT, 0 },
634 { 0, 28, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 0 },
635 { 0, 32, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR, 1 },
636 { 0, 36, D3DDECLTYPE_FLOAT2, 0, D3DDECLUSAGE_TEXCOORD, 0 },
637 { 0, 44, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_TEXCOORD, 1 }, D3DDECL_END() };
638 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, D3DFVF_XYZB4 | D3DFVF_SPECULAR | D3DFVF_DIFFUSE |
639 D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEXCOORDSIZE3(1) | D3DFVF_TEX2, test_buffer, 1));
642 /* Setting the FVF to 0 should result in no change to the default decl */
643 VDECL_CHECK(test_fvf_to_decl(pDevice, default_decl, 0, default_elements, 0));
645 cleanup:
646 IDirect3DDevice9_SetVertexDeclaration ( pDevice, NULL );
647 if ( default_decl ) IUnknown_Release (default_decl);
650 /* Check whether a declaration converted from FVF is shared.
651 * Check whether refcounts behave as expected */
652 static void test_fvf_decl_management(
653 IDirect3DDevice9* device) {
655 HRESULT hr;
656 IDirect3DVertexDeclaration9* result_decl1 = NULL;
657 IDirect3DVertexDeclaration9* result_decl2 = NULL;
658 IDirect3DVertexDeclaration9* result_decl3 = NULL;
659 IDirect3DVertexDeclaration9* result_decl4 = NULL;
660 int ref1, ref2, ref3, ref4;
662 DWORD test_fvf1 = D3DFVF_XYZRHW;
663 DWORD test_fvf2 = D3DFVF_NORMAL;
664 CONST D3DVERTEXELEMENT9 test_elements1[] =
665 { { 0, 0, D3DDECLTYPE_FLOAT4, 0, D3DDECLUSAGE_POSITIONT, 0 }, D3DDECL_END() };
666 CONST D3DVERTEXELEMENT9 test_elements2[] =
667 { { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_NORMAL, 0 }, D3DDECL_END() };
669 /* Clear down any current vertex declaration */
670 hr = IDirect3DDevice9_SetVertexDeclaration ( device, NULL );
671 ok (SUCCEEDED(hr), "SetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
672 if (FAILED(hr)) return;
674 /* Conversion */
675 hr = IDirect3DDevice9_SetFVF( device, test_fvf1);
676 ok(SUCCEEDED(hr), "SetFVF returned %#x, expected %#x\n", hr, D3D_OK);
677 if (FAILED(hr)) return;
679 /* Get converted decl (#1) */
680 hr = IDirect3DDevice9_GetVertexDeclaration ( device, &result_decl1);
681 ok(SUCCEEDED(hr), "GetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
682 if (FAILED(hr)) return;
684 /* Get converted decl again (#2) */
685 hr = IDirect3DDevice9_GetVertexDeclaration ( device, &result_decl2);
686 ok(SUCCEEDED(hr), "GetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
687 if (FAILED(hr)) return;
689 /* Conversion */
690 hr = IDirect3DDevice9_SetFVF( device, test_fvf2);
691 ok(SUCCEEDED(hr), "SetFVF returned %#x, expected %#x\n", hr, D3D_OK);
692 if (FAILED(hr)) return;
694 /* The contents should correspond to the first conversion */
695 VDECL_CHECK(compare_elements(result_decl1, test_elements1));
697 /* Get converted decl (#3) */
698 hr = IDirect3DDevice9_GetVertexDeclaration ( device, &result_decl3);
699 ok(SUCCEEDED(hr), "GetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
700 if (FAILED(hr)) return;
702 /* The object should be the same */
703 ok (result_decl1 == result_decl2, "Declaration object changes on the second Get() call\n");
704 ok (result_decl2 != result_decl3, "Declaration object did not change during conversion\n");
706 /* The contents should correspond to the second conversion */
707 VDECL_CHECK(compare_elements(result_decl3, test_elements2));
708 /* Re-Check if the first decl was overwritten by the new Get() */
709 VDECL_CHECK(compare_elements(result_decl1, test_elements1));
711 hr = IDirect3DDevice9_SetFVF( device, test_fvf1);
712 ok(SUCCEEDED(hr), "SetFVF returned %#x, expected %#x\n", hr, D3D_OK);
713 if (FAILED(hr)) return;
715 hr = IDirect3DDevice9_GetVertexDeclaration ( device, &result_decl4);
716 ok(SUCCEEDED(hr), "GetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
717 if (FAILED(hr)) return;
719 ok(result_decl4 == result_decl1, "Setting an already used FVF over results in a different vertexdeclaration\n");
721 ref1 = get_refcount((IUnknown*) result_decl1);
722 ref2 = get_refcount((IUnknown*) result_decl2);
723 ref3 = get_refcount((IUnknown*) result_decl3);
724 ref4 = get_refcount((IUnknown*) result_decl4);
725 ok (ref1 == 3, "Refcount #1 is %d, expected 3\n", ref1);
726 ok (ref2 == 3, "Refcount #2 is %d, expected 3\n", ref2);
727 ok (ref3 == 1, "Refcount #3 is %d, expected 1\n", ref3);
728 ok (ref4 == 3, "Refcount #4 is %d, expected 3\n", ref4);
730 /* Clear down any current vertex declaration */
731 hr = IDirect3DDevice9_SetVertexDeclaration ( device, NULL );
732 ok (SUCCEEDED(hr), "SetVertexDeclaration returned %#x, expected %#x\n", hr, D3D_OK);
733 if (FAILED(hr)) return;
735 IDirect3DVertexDeclaration9_Release(result_decl1);
736 IDirect3DVertexDeclaration9_Release(result_decl2);
737 IDirect3DVertexDeclaration9_Release(result_decl3);
738 IDirect3DVertexDeclaration9_Release(result_decl4);
740 return;
743 static void test_vertex_declaration_alignment(
744 IDirect3DDevice9* device) {
746 HRESULT hr;
747 IDirect3DVertexDeclaration9* result_decl = NULL;
748 unsigned int i;
750 CONST D3DVERTEXELEMENT9 test_elements[5][3] =
753 { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
754 { 0, 16, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR , 0 },
755 D3DDECL_END()
758 { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
759 { 0, 17, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR , 0 },
760 D3DDECL_END()
763 { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
764 { 0, 18, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR , 0 },
765 D3DDECL_END()
768 { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
769 { 0, 19, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR , 0 },
770 D3DDECL_END()
773 { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
774 { 0, 20, D3DDECLTYPE_D3DCOLOR, 0, D3DDECLUSAGE_COLOR , 0 },
775 D3DDECL_END()
778 HRESULT results[5] = {D3D_OK, E_FAIL, E_FAIL, E_FAIL, D3D_OK};
780 for(i = 0; i < sizeof(test_elements) / sizeof(test_elements[0]); i++) {
781 result_decl = NULL;
782 hr = IDirect3DDevice9_CreateVertexDeclaration(device, test_elements[i], &result_decl);
783 ok(hr == results[i], "CreateVertexDeclaration for declaration %d returned %#x, expected %#x\n",
784 i, hr, results[i]);
785 if(result_decl) IDirect3DVertexDeclaration9_Release(result_decl);
789 static void test_unused_type(
790 IDirect3DDevice9* device) {
792 HRESULT hr;
793 IDirect3DVertexDeclaration9* result_decl = NULL;
794 unsigned int i;
796 static const D3DVERTEXELEMENT9 test_elements[][3] =
799 { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
800 { 0, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_COLOR , 0 },
801 D3DDECL_END()
804 { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
805 { 0, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_TEXCOORD, 0 },
806 D3DDECL_END()
809 { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
810 { 0, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_TEXCOORD, 1 },
811 D3DDECL_END()
814 { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
815 { 0, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_TEXCOORD, 12},
816 D3DDECL_END()
819 { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
820 { 1, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_TEXCOORD, 12},
821 D3DDECL_END()
824 { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
825 { 0, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_NORMAL, 0 },
826 D3DDECL_END()
829 { 0, 0, D3DDECLTYPE_FLOAT3, 0, D3DDECLUSAGE_POSITION, 0 },
830 { 1, 16, D3DDECLTYPE_UNUSED, 0, D3DDECLUSAGE_NORMAL, 0 },
831 D3DDECL_END()
835 for(i = 0; i < sizeof(test_elements) / sizeof(test_elements[0]); i++) {
836 result_decl = NULL;
837 hr = IDirect3DDevice9_CreateVertexDeclaration(device, test_elements[i], &result_decl);
838 ok(hr == E_FAIL, "CreateVertexDeclaration for declaration %d returned %#x, expected E_FAIL(%#x)\n",
839 i, hr, E_FAIL);
840 if(result_decl) IDirect3DVertexDeclaration9_Release(result_decl);
843 START_TEST(vertexdeclaration)
845 static D3DVERTEXELEMENT9 simple_decl[] = {
846 { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
847 D3DDECL_END()};
848 UINT simple_decl_num_elements = sizeof(simple_decl) / sizeof(*simple_decl);
849 IDirect3DDevice9 *device_ptr = 0;
850 IDirect3DVertexDeclaration9 *decl_ptr = 0;
851 ULONG refcount;
853 d3d9_handle = LoadLibraryA("d3d9.dll");
854 if (!d3d9_handle)
856 skip("Could not load d3d9.dll\n");
857 return;
860 device_ptr = init_d3d9();
861 if (!device_ptr)
863 skip("Failed to initialise d3d9\n");
864 return;
867 decl_ptr = test_create_vertex_declaration(device_ptr, simple_decl);
868 if (!decl_ptr)
870 skip("Failed to create a vertex declaration\n");
871 return;
874 test_get_set_vertex_declaration(device_ptr, decl_ptr);
875 test_get_declaration(decl_ptr, simple_decl, simple_decl_num_elements);
876 test_fvf_decl_conversion(device_ptr);
877 test_fvf_decl_management(device_ptr);
878 test_vertex_declaration_alignment(device_ptr);
879 test_unused_type(device_ptr);
881 IDirect3DVertexDeclaration9_Release(decl_ptr);
883 refcount = IDirect3DDevice9_Release(device_ptr);
884 ok(!refcount, "Device has %u references left\n", refcount);