d3dx9: Add stub and basic test for D3DXCreateSphere.
[wine] / dlls / d3dx9_36 / tests / mesh.c
1 /*
2  * Copyright 2008 David Adam
3  * Copyright 2008 Luis Busquets
4  * Copyright 2009 Henri Verbeet for CodeWeavers
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "wine/test.h"
22 #include "d3dx9.h"
23
24 #define admitted_error 0.0001f
25
26 #define compare_vertex_sizes(type, exp) \
27     got=D3DXGetFVFVertexSize(type); \
28     ok(got==exp, "Expected: %d, Got: %d\n", exp, got);
29
30 static BOOL compare(FLOAT u, FLOAT v)
31 {
32     return (fabs(u-v) < admitted_error);
33 }
34
35 static BOOL compare_vec3(D3DXVECTOR3 u, D3DXVECTOR3 v)
36 {
37     return ( compare(u.x, v.x) && compare(u.y, v.y) && compare(u.z, v.z) );
38 }
39
40 static void D3DXBoundProbeTest(void)
41 {
42     BOOL result;
43     D3DXVECTOR3 bottom_point, center, top_point, raydirection, rayposition;
44     FLOAT radius;
45
46 /*____________Test the Box case___________________________*/
47     bottom_point.x = -3.0f; bottom_point.y = -2.0f; bottom_point.z = -1.0f;
48     top_point.x = 7.0f; top_point.y = 8.0f; top_point.z = 9.0f;
49
50     raydirection.x = -4.0f; raydirection.y = -5.0f; raydirection.z = -6.0f;
51     rayposition.x = 5.0f; rayposition.y = 5.0f; rayposition.z = 11.0f;
52     result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
53     ok(result == TRUE, "expected TRUE, received FALSE\n");
54
55     raydirection.x = 4.0f; raydirection.y = 5.0f; raydirection.z = 6.0f;
56     rayposition.x = 5.0f; rayposition.y = 5.0f; rayposition.z = 11.0f;
57     result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
58     ok(result == FALSE, "expected FALSE, received TRUE\n");
59
60     rayposition.x = -4.0f; rayposition.y = 1.0f; rayposition.z = -2.0f;
61     result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
62     ok(result == TRUE, "expected TRUE, received FALSE\n");
63
64     bottom_point.x = 1.0f; bottom_point.y = 0.0f; bottom_point.z = 0.0f;
65     top_point.x = 1.0f; top_point.y = 0.0f; top_point.z = 0.0f;
66     rayposition.x = 0.0f; rayposition.y = 1.0f; rayposition.z = 0.0f;
67     raydirection.x = 0.0f; raydirection.y = 3.0f; raydirection.z = 0.0f;
68     result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
69     ok(result == FALSE, "expected FALSE, received TRUE\n");
70
71     bottom_point.x = 1.0f; bottom_point.y = 2.0f; bottom_point.z = 3.0f;
72     top_point.x = 10.0f; top_point.y = 15.0f; top_point.z = 20.0f;
73
74     raydirection.x = 7.0f; raydirection.y = 8.0f; raydirection.z = 9.0f;
75     rayposition.x = 3.0f; rayposition.y = 7.0f; rayposition.z = -6.0f;
76     result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
77     ok(result == TRUE, "expected TRUE, received FALSE\n");
78
79     bottom_point.x = 0.0f; bottom_point.y = 0.0f; bottom_point.z = 0.0f;
80     top_point.x = 1.0f; top_point.y = 1.0f; top_point.z = 1.0f;
81
82     raydirection.x = 0.0f; raydirection.y = 1.0f; raydirection.z = .0f;
83     rayposition.x = -3.0f; rayposition.y = 0.0f; rayposition.z = 0.0f;
84     result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
85     ok(result == FALSE, "expected FALSE, received TRUE\n");
86
87     raydirection.x = 1.0f; raydirection.y = 0.0f; raydirection.z = .0f;
88     rayposition.x = -3.0f; rayposition.y = 0.0f; rayposition.z = 0.0f;
89     result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
90     ok(result == TRUE, "expected TRUE, received FALSE\n");
91
92 /*____________Test the Sphere case________________________*/
93     radius = sqrt(77.0f);
94     center.x = 1.0f; center.y = 2.0f; center.z = 3.0f;
95     raydirection.x = 2.0f; raydirection.y = -4.0f; raydirection.z = 2.0f;
96
97     rayposition.x = 5.0f; rayposition.y = 5.0f; rayposition.z = 9.0f;
98     result = D3DXSphereBoundProbe(&center, radius, &rayposition, &raydirection);
99     ok(result == TRUE, "expected TRUE, received FALSE\n");
100
101     rayposition.x = 45.0f; rayposition.y = -75.0f; rayposition.z = 49.0f;
102     result = D3DXSphereBoundProbe(&center, radius, &rayposition, &raydirection);
103     ok(result == FALSE, "expected FALSE, received TRUE\n");
104
105     rayposition.x = 5.0f; rayposition.y = 11.0f; rayposition.z = 9.0f;
106     result = D3DXSphereBoundProbe(&center, radius, &rayposition, &raydirection);
107     ok(result == FALSE, "expected FALSE, received TRUE\n");
108 }
109
110 static void D3DXComputeBoundingBoxTest(void)
111 {
112     D3DXVECTOR3 exp_max, exp_min, got_max, got_min, vertex[5];
113     HRESULT hr;
114
115     vertex[0].x = 1.0f; vertex[0].y = 1.0f; vertex[0].z = 1.0f;
116     vertex[1].x = 1.0f; vertex[1].y = 1.0f; vertex[1].z = 1.0f;
117     vertex[2].x = 1.0f; vertex[2].y = 1.0f; vertex[2].z = 1.0f;
118     vertex[3].x = 1.0f; vertex[3].y = 1.0f; vertex[3].z = 1.0f;
119     vertex[4].x = 9.0f; vertex[4].y = 9.0f; vertex[4].z = 9.0f;
120
121     exp_min.x = 1.0f; exp_min.y = 1.0f; exp_min.z = 1.0f;
122     exp_max.x = 9.0f; exp_max.y = 9.0f; exp_max.z = 9.0f;
123
124     hr = D3DXComputeBoundingBox(&vertex[3],2,D3DXGetFVFVertexSize(D3DFVF_XYZ),&got_min,&got_max);
125
126     ok( hr == D3D_OK, "Expected D3D_OK, got %#x\n", hr);
127     ok( compare_vec3(exp_min,got_min), "Expected min: (%f, %f, %f), got: (%f, %f, %f)\n", exp_min.x,exp_min.y,exp_min.z,got_min.x,got_min.y,got_min.z);
128     ok( compare_vec3(exp_max,got_max), "Expected max: (%f, %f, %f), got: (%f, %f, %f)\n", exp_max.x,exp_max.y,exp_max.z,got_max.x,got_max.y,got_max.z);
129
130 /*________________________*/
131
132     vertex[0].x = 2.0f; vertex[0].y = 5.9f; vertex[0].z = -1.2f;
133     vertex[1].x = -1.87f; vertex[1].y = 7.9f; vertex[1].z = 7.4f;
134     vertex[2].x = 7.43f; vertex[2].y = -0.9f; vertex[2].z = 11.9f;
135     vertex[3].x = -6.92f; vertex[3].y = 6.3f; vertex[3].z = -3.8f;
136     vertex[4].x = 11.4f; vertex[4].y = -8.1f; vertex[4].z = 4.5f;
137
138     exp_min.x = -6.92f; exp_min.y = -8.1f; exp_min.z = -3.80f;
139     exp_max.x = 11.4f; exp_max.y = 7.90f; exp_max.z = 11.9f;
140
141     hr = D3DXComputeBoundingBox(&vertex[0],5,D3DXGetFVFVertexSize(D3DFVF_XYZ),&got_min,&got_max);
142
143     ok( hr == D3D_OK, "Expected D3D_OK, got %#x\n", hr);
144     ok( compare_vec3(exp_min,got_min), "Expected min: (%f, %f, %f), got: (%f, %f, %f)\n", exp_min.x,exp_min.y,exp_min.z,got_min.x,got_min.y,got_min.z);
145     ok( compare_vec3(exp_max,got_max), "Expected max: (%f, %f, %f), got: (%f, %f, %f)\n", exp_max.x,exp_max.y,exp_max.z,got_max.x,got_max.y,got_max.z);
146
147 /*________________________*/
148
149     vertex[0].x = 2.0f; vertex[0].y = 5.9f; vertex[0].z = -1.2f;
150     vertex[1].x = -1.87f; vertex[1].y = 7.9f; vertex[1].z = 7.4f;
151     vertex[2].x = 7.43f; vertex[2].y = -0.9f; vertex[2].z = 11.9f;
152     vertex[3].x = -6.92f; vertex[3].y = 6.3f; vertex[3].z = -3.8f;
153     vertex[4].x = 11.4f; vertex[4].y = -8.1f; vertex[4].z = 4.5f;
154
155     exp_min.x = -6.92f; exp_min.y = -0.9f; exp_min.z = -3.8f;
156     exp_max.x = 7.43f; exp_max.y = 7.90f; exp_max.z = 11.9f;
157
158     hr = D3DXComputeBoundingBox(&vertex[0],4,D3DXGetFVFVertexSize(D3DFVF_XYZ),&got_min,&got_max);
159
160     ok( hr == D3D_OK, "Expected D3D_OK, got %#x\n", hr);
161     ok( compare_vec3(exp_min,got_min), "Expected min: (%f, %f, %f), got: (%f, %f, %f)\n", exp_min.x,exp_min.y,exp_min.z,got_min.x,got_min.y,got_min.z);
162     ok( compare_vec3(exp_max,got_max), "Expected max: (%f, %f, %f), got: (%f, %f, %f)\n", exp_max.x,exp_max.y,exp_max.z,got_max.x,got_max.y,got_max.z);
163
164 /*________________________*/
165     hr = D3DXComputeBoundingBox(NULL,5,D3DXGetFVFVertexSize(D3DFVF_XYZ),&got_min,&got_max);
166     ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
167
168 /*________________________*/
169     hr = D3DXComputeBoundingBox(&vertex[3],5,D3DXGetFVFVertexSize(D3DFVF_XYZ),NULL,&got_max);
170     ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
171
172 /*________________________*/
173     hr = D3DXComputeBoundingBox(&vertex[3],5,D3DXGetFVFVertexSize(D3DFVF_XYZ),&got_min,NULL);
174     ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
175 }
176
177 static void D3DXComputeBoundingSphereTest(void)
178 {
179     D3DXVECTOR3 exp_cen, got_cen, vertex[5];
180     FLOAT exp_rad, got_rad;
181     HRESULT hr;
182
183     vertex[0].x = 1.0f; vertex[0].y = 1.0f; vertex[0].z = 1.0f;
184     vertex[1].x = 1.0f; vertex[1].y = 1.0f; vertex[1].z = 1.0f;
185     vertex[2].x = 1.0f; vertex[2].y = 1.0f; vertex[2].z = 1.0f;
186     vertex[3].x = 1.0f; vertex[3].y = 1.0f; vertex[3].z = 1.0f;
187     vertex[4].x = 9.0f; vertex[4].y = 9.0f; vertex[4].z = 9.0f;
188
189     exp_rad = 6.928203f;
190     exp_cen.x = 5.0; exp_cen.y = 5.0; exp_cen.z = 5.0;
191
192     hr = D3DXComputeBoundingSphere(&vertex[3],2,D3DXGetFVFVertexSize(D3DFVF_XYZ),&got_cen,&got_rad);
193
194     ok( hr == D3D_OK, "Expected D3D_OK, got %#x\n", hr);
195     ok( compare(exp_rad, got_rad), "Expected radius: %f, got radius: %f\n", exp_rad, got_rad);
196     ok( compare_vec3(exp_cen,got_cen), "Expected center: (%f, %f, %f), got center: (%f, %f, %f)\n", exp_cen.x,exp_cen.y,exp_cen.z,got_cen.x,got_cen.y,got_cen.z);
197
198 /*________________________*/
199
200     vertex[0].x = 2.0f; vertex[0].y = 5.9f; vertex[0].z = -1.2f;
201     vertex[1].x = -1.87f; vertex[1].y = 7.9f; vertex[1].z = 7.4f;
202     vertex[2].x = 7.43f; vertex[2].y = -0.9f; vertex[2].z = 11.9f;
203     vertex[3].x = -6.92f; vertex[3].y = 6.3f; vertex[3].z = -3.8f;
204     vertex[4].x = 11.4f; vertex[4].y = -8.1f; vertex[4].z = 4.5f;
205
206     exp_rad = 13.707883f;
207     exp_cen.x = 2.408f; exp_cen.y = 2.22f; exp_cen.z = 3.76f;
208
209     hr = D3DXComputeBoundingSphere(&vertex[0],5,D3DXGetFVFVertexSize(D3DFVF_XYZ),&got_cen,&got_rad);
210
211     ok( hr == D3D_OK, "Expected D3D_OK, got %#x\n", hr);
212     ok( compare(exp_rad, got_rad), "Expected radius: %f, got radius: %f\n", exp_rad, got_rad);
213     ok( compare_vec3(exp_cen,got_cen), "Expected center: (%f, %f, %f), got center: (%f, %f, %f)\n", exp_cen.x,exp_cen.y,exp_cen.z,got_cen.x,got_cen.y,got_cen.z);
214
215 /*________________________*/
216     hr = D3DXComputeBoundingSphere(NULL,5,D3DXGetFVFVertexSize(D3DFVF_XYZ),&got_cen,&got_rad);
217     ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
218
219 /*________________________*/
220     hr = D3DXComputeBoundingSphere(&vertex[3],5,D3DXGetFVFVertexSize(D3DFVF_XYZ),NULL,&got_rad);
221     ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
222
223 /*________________________*/
224     hr = D3DXComputeBoundingSphere(&vertex[3],5,D3DXGetFVFVertexSize(D3DFVF_XYZ),&got_cen,NULL);
225     ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
226 }
227
228 static void D3DXDeclaratorFromFVFTest(void)
229 {
230     D3DVERTEXELEMENT9 decl[MAX_FVF_DECL_SIZE];
231     HRESULT hr;
232     int i, size;
233
234     static const D3DVERTEXELEMENT9 exp1[6] = {
235         {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
236         {0, 0xC, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
237         {0, 0x18, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
238         {0, 0x1C,  D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 1},
239         {0, 0x20, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT,D3DDECLUSAGE_TEXCOORD, 0},
240         D3DDECL_END(), };
241
242     static const D3DVERTEXELEMENT9 exp2[3] = {
243         {0, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITIONT, 0},
244         {0, 0x10, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_PSIZE, 0},
245         D3DDECL_END(), };
246
247     static const D3DVERTEXELEMENT9 exp3[4] = {
248         {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
249         {0, 0xC, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0},
250         {0, 0x1C, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDINDICES, 0},
251         D3DDECL_END(), };
252
253     /* Note: passing NULL as declaration segfaults */
254     todo_wine
255     {
256         hr = D3DXDeclaratorFromFVF(0, decl);
257         ok(hr == D3D_OK, "D3DXDeclaratorFromFVF returned %#x, expected %#x\n", hr, D3D_OK);
258         ok(decl[0].Stream == 0xFF, "D3DXDeclaratorFromFVF returned an incorrect vertex declaration\n"); /* end element */
259
260         hr = D3DXDeclaratorFromFVF(D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, decl);
261         ok(hr == D3D_OK, "D3DXDeclaratorFromFVF returned %#x, expected %#x\n", hr, D3D_OK);
262
263         if (hr == D3D_OK)
264         {
265             size = sizeof(exp1)/sizeof(exp1[0]);
266             for (i=0; i<size-1; i++)
267             {
268                 ok(decl[i].Stream == exp1[i].Stream, "Returned stream %d, expected %d\n", decl[i].Stream, exp1[i].Stream);
269                 ok(decl[i].Type == exp1[i].Type, "Returned type %d, expected %d\n", decl[i].Type, exp1[i].Type);
270                 ok(decl[i].Method == exp1[i].Method, "Returned method %d, expected %d\n", decl[i].Method, exp1[i].Method);
271                 ok(decl[i].Usage == exp1[i].Usage, "Returned usage %d, expected %d\n", decl[i].Usage, exp1[i].Usage);
272                 ok(decl[i].UsageIndex == exp1[i].UsageIndex, "Returned usage index %d, expected %d\n", decl[i].UsageIndex, exp1[i].UsageIndex);
273                 ok(decl[i].Offset == exp1[i].Offset, "Returned offset %d, expected %d\n", decl[i].Offset, exp1[i].Offset);
274             }
275             ok(decl[size-1].Stream == 0xFF, "Returned too long vertex declaration\n"); /* end element */
276         }
277     }
278
279     todo_wine
280     {
281         hr = D3DXDeclaratorFromFVF(D3DFVF_XYZRHW | D3DFVF_PSIZE, decl);
282         ok(hr == D3D_OK, "D3DXDeclaratorFromFVF returned %#x, expected %#x\n", hr, D3D_OK);
283
284         if (hr == D3D_OK)
285         {
286             size = sizeof(exp2)/sizeof(exp2[0]);
287             for (i=0; i<size-1; i++)
288             {
289                 ok(decl[i].Stream == exp2[i].Stream, "Returned stream %d, expected %d\n", decl[i].Stream, exp2[i].Stream);
290                 ok(decl[i].Type == exp2[i].Type, "Returned type %d, expected %d\n", decl[i].Type, exp1[i].Type);
291                 ok(decl[i].Method == exp2[i].Method, "Returned method %d, expected %d\n", decl[i].Method, exp2[i].Method);
292                 ok(decl[i].Usage == exp2[i].Usage, "Returned usage %d, expected %d\n", decl[i].Usage, exp2[i].Usage);
293                 ok(decl[i].UsageIndex == exp2[i].UsageIndex, "Returned usage index %d, expected %d\n", decl[i].UsageIndex, exp2[i].UsageIndex);
294                 ok(decl[i].Offset == exp2[i].Offset, "Returned offset %d, expected %d\n", decl[i].Offset, exp2[i].Offset);
295             }
296             ok(decl[size-1].Stream == 0xFF, "Returned too long vertex declaration\n"); /* end element */
297         }
298     }
299
300     todo_wine
301     {
302         hr = D3DXDeclaratorFromFVF(D3DFVF_XYZB5, decl);
303         ok(hr == D3DERR_INVALIDCALL, "D3DXDeclaratorFromFVF returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
304
305         hr = D3DXDeclaratorFromFVF(D3DFVF_XYZB5 | D3DFVF_LASTBETA_UBYTE4, decl);
306         ok(hr == D3D_OK, "D3DXDeclaratorFromFVF returned %#x, expected %#x\n", hr, D3D_OK);
307
308         if (hr == D3D_OK)
309         {
310             size = sizeof(exp3)/sizeof(exp3[0]);
311             for (i=0; i<size-1; i++)
312             {
313                 ok(decl[i].Stream == exp3[i].Stream, "Returned stream %d, expected %d\n", decl[i].Stream, exp3[i].Stream);
314                 ok(decl[i].Type == exp3[i].Type, "Returned type %d, expected %d\n", decl[i].Type, exp3[i].Type);
315                 ok(decl[i].Method == exp3[i].Method, "Returned method %d, expected %d\n", decl[i].Method, exp3[i].Method);
316                 ok(decl[i].Usage == exp3[i].Usage, "Returned usage %d, expected %d\n", decl[i].Usage, exp3[i].Usage);
317                 ok(decl[i].UsageIndex == exp3[i].UsageIndex, "Returned usage index %d, expected %d\n", decl[i].UsageIndex, exp3[i].UsageIndex);
318                 ok(decl[i].Offset == exp3[i].Offset, "Returned offset %d, expected %d\n", decl[i].Offset, exp3[i].Offset);
319             }
320             ok(decl[size-1].Stream == 0xFF, "Returned too long vertex declaration\n"); /* end element */
321         }
322     }
323 }
324
325 static void D3DXGetFVFVertexSizeTest(void)
326 {
327     UINT got;
328
329     compare_vertex_sizes (D3DFVF_XYZ, 12);
330
331     compare_vertex_sizes (D3DFVF_XYZB3, 24);
332
333     compare_vertex_sizes (D3DFVF_XYZB5, 32);
334
335     compare_vertex_sizes (D3DFVF_XYZ | D3DFVF_NORMAL, 24);
336
337     compare_vertex_sizes (D3DFVF_XYZ | D3DFVF_DIFFUSE, 16);
338
339     compare_vertex_sizes (
340         D3DFVF_XYZ |
341         D3DFVF_TEX1 |
342         D3DFVF_TEXCOORDSIZE1(0), 16);
343     compare_vertex_sizes (
344         D3DFVF_XYZ |
345         D3DFVF_TEX2 |
346         D3DFVF_TEXCOORDSIZE1(0) |
347         D3DFVF_TEXCOORDSIZE1(1), 20);
348
349     compare_vertex_sizes (
350         D3DFVF_XYZ |
351         D3DFVF_TEX1 |
352         D3DFVF_TEXCOORDSIZE2(0), 20);
353
354     compare_vertex_sizes (
355         D3DFVF_XYZ |
356         D3DFVF_TEX2 |
357         D3DFVF_TEXCOORDSIZE2(0) |
358         D3DFVF_TEXCOORDSIZE2(1), 28);
359
360     compare_vertex_sizes (
361         D3DFVF_XYZ |
362         D3DFVF_TEX6 |
363         D3DFVF_TEXCOORDSIZE2(0) |
364         D3DFVF_TEXCOORDSIZE2(1) |
365         D3DFVF_TEXCOORDSIZE2(2) |
366         D3DFVF_TEXCOORDSIZE2(3) |
367         D3DFVF_TEXCOORDSIZE2(4) |
368         D3DFVF_TEXCOORDSIZE2(5), 60);
369
370     compare_vertex_sizes (
371         D3DFVF_XYZ |
372         D3DFVF_TEX8 |
373         D3DFVF_TEXCOORDSIZE2(0) |
374         D3DFVF_TEXCOORDSIZE2(1) |
375         D3DFVF_TEXCOORDSIZE2(2) |
376         D3DFVF_TEXCOORDSIZE2(3) |
377         D3DFVF_TEXCOORDSIZE2(4) |
378         D3DFVF_TEXCOORDSIZE2(5) |
379         D3DFVF_TEXCOORDSIZE2(6) |
380         D3DFVF_TEXCOORDSIZE2(7), 76);
381
382     compare_vertex_sizes (
383         D3DFVF_XYZ |
384         D3DFVF_TEX1 |
385         D3DFVF_TEXCOORDSIZE3(0), 24);
386
387     compare_vertex_sizes (
388         D3DFVF_XYZ |
389         D3DFVF_TEX4 |
390         D3DFVF_TEXCOORDSIZE3(0) |
391         D3DFVF_TEXCOORDSIZE3(1) |
392         D3DFVF_TEXCOORDSIZE3(2) |
393         D3DFVF_TEXCOORDSIZE3(3), 60);
394
395     compare_vertex_sizes (
396         D3DFVF_XYZ |
397         D3DFVF_TEX1 |
398         D3DFVF_TEXCOORDSIZE4(0), 28);
399
400     compare_vertex_sizes (
401         D3DFVF_XYZ |
402         D3DFVF_TEX2 |
403         D3DFVF_TEXCOORDSIZE4(0) |
404         D3DFVF_TEXCOORDSIZE4(1), 44);
405
406     compare_vertex_sizes (
407         D3DFVF_XYZ |
408         D3DFVF_TEX3 |
409         D3DFVF_TEXCOORDSIZE4(0) |
410         D3DFVF_TEXCOORDSIZE4(1) |
411         D3DFVF_TEXCOORDSIZE4(2), 60);
412
413     compare_vertex_sizes (
414         D3DFVF_XYZB5 |
415         D3DFVF_NORMAL |
416         D3DFVF_DIFFUSE |
417         D3DFVF_SPECULAR |
418         D3DFVF_TEX8 |
419         D3DFVF_TEXCOORDSIZE4(0) |
420         D3DFVF_TEXCOORDSIZE4(1) |
421         D3DFVF_TEXCOORDSIZE4(2) |
422         D3DFVF_TEXCOORDSIZE4(3) |
423         D3DFVF_TEXCOORDSIZE4(4) |
424         D3DFVF_TEXCOORDSIZE4(5) |
425         D3DFVF_TEXCOORDSIZE4(6) |
426         D3DFVF_TEXCOORDSIZE4(7), 180);
427 }
428
429 static void D3DXIntersectTriTest(void)
430 {
431     BOOL exp_res, got_res;
432     D3DXVECTOR3 position, ray, vertex[3];
433     FLOAT exp_dist, got_dist, exp_u, got_u, exp_v, got_v;
434
435     vertex[0].x = 1.0f; vertex[0].y = 0.0f; vertex[0].z = 0.0f;
436     vertex[1].x = 2.0f; vertex[1].y = 0.0f; vertex[1].z = 0.0f;
437     vertex[2].x = 1.0f; vertex[2].y = 1.0f; vertex[2].z = 0.0f;
438
439     position.x = -14.5f; position.y = -23.75f; position.z = -32.0f;
440
441     ray.x = 2.0f; ray.y = 3.0f; ray.z = 4.0f;
442
443     exp_res = TRUE; exp_u = 0.5f; exp_v = 0.25f; exp_dist = 8.0f;
444
445     got_res = D3DXIntersectTri(&vertex[0],&vertex[1],&vertex[2],&position,&ray,&got_u,&got_v,&got_dist);
446     ok( got_res == exp_res, "Expected result = %d, got %d\n",exp_res,got_res);
447     ok( compare(exp_u,got_u), "Expected u = %f, got %f\n",exp_u,got_u);
448     ok( compare(exp_v,got_v), "Expected v = %f, got %f\n",exp_v,got_v);
449     ok( compare(exp_dist,got_dist), "Expected distance = %f, got %f\n",exp_dist,got_dist);
450
451 /*Only positive ray is taken in account*/
452
453     vertex[0].x = 1.0f; vertex[0].y = 0.0f; vertex[0].z = 0.0f;
454     vertex[1].x = 2.0f; vertex[1].y = 0.0f; vertex[1].z = 0.0f;
455     vertex[2].x = 1.0f; vertex[2].y = 1.0f; vertex[2].z = 0.0f;
456
457     position.x = 17.5f; position.y = 24.25f; position.z = 32.0f;
458
459     ray.x = 2.0f; ray.y = 3.0f; ray.z = 4.0f;
460
461     exp_res = FALSE;
462
463     got_res = D3DXIntersectTri(&vertex[0],&vertex[1],&vertex[2],&position,&ray,&got_u,&got_v,&got_dist);
464     ok( got_res == exp_res, "Expected result = %d, got %d\n",exp_res,got_res);
465
466 /*Intersection between ray and triangle in a same plane is considered as empty*/
467
468     vertex[0].x = 4.0f; vertex[0].y = 0.0f; vertex[0].z = 0.0f;
469     vertex[1].x = 6.0f; vertex[1].y = 0.0f; vertex[1].z = 0.0f;
470     vertex[2].x = 4.0f; vertex[2].y = 2.0f; vertex[2].z = 0.0f;
471
472     position.x = 1.0f; position.y = 1.0f; position.z = 0.0f;
473
474     ray.x = 1.0f; ray.y = 0.0f; ray.z = 0.0f;
475
476     exp_res = FALSE;
477
478     got_res = D3DXIntersectTri(&vertex[0],&vertex[1],&vertex[2],&position,&ray,&got_u,&got_v,&got_dist);
479     ok( got_res == exp_res, "Expected result = %d, got %d\n",exp_res,got_res);
480 }
481
482 static void D3DXCreateSphereTest(void)
483 {
484     HRESULT hr;
485     HWND wnd;
486     IDirect3D9* d3d;
487     IDirect3DDevice9* device;
488     D3DPRESENT_PARAMETERS d3dpp;
489     ID3DXMesh* sphere = NULL;
490
491     hr = D3DXCreateSphere(NULL, 0.0f, 0, 0, NULL, NULL);
492     todo_wine ok( hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n",hr,D3DERR_INVALIDCALL);
493
494     hr = D3DXCreateSphere(NULL, 0.1f, 0, 0, NULL, NULL);
495     todo_wine ok( hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n",hr,D3DERR_INVALIDCALL);
496
497     hr = D3DXCreateSphere(NULL, 0.0f, 1, 0, NULL, NULL);
498     todo_wine ok( hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n",hr,D3DERR_INVALIDCALL);
499
500     hr = D3DXCreateSphere(NULL, 0.0f, 0, 1, NULL, NULL);
501     todo_wine ok( hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n",hr,D3DERR_INVALIDCALL);
502
503     wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
504     d3d = Direct3DCreate9(D3D_SDK_VERSION);
505     if (!wnd)
506     {
507         skip("Couldn't create application window\n");
508         return;
509     }
510     if (!d3d)
511     {
512         skip("Couldn't create IDirect3D9 object\n");
513         DestroyWindow(wnd);
514         return;
515     }
516
517     ZeroMemory(&d3dpp, sizeof(d3dpp));
518     d3dpp.Windowed = TRUE;
519     d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
520     hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device);
521     if (FAILED(hr))
522     {
523         skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
524         IDirect3D9_Release(d3d);
525         DestroyWindow(wnd);
526         return;
527     }
528
529     hr = D3DXCreateSphere(device, 1.0f, 1, 1, &sphere, NULL);
530     todo_wine ok( hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n",hr,D3DERR_INVALIDCALL);
531
532     hr = D3DXCreateSphere(device, 1.0f, 2, 2, &sphere, NULL);
533     todo_wine ok( hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n",hr);
534
535     if (sphere)
536         sphere->lpVtbl->Release(sphere);
537
538     IDirect3DDevice9_Release(device);
539     IDirect3D9_Release(d3d);
540     DestroyWindow(wnd);
541 }
542
543 static void test_get_decl_vertex_size(void)
544 {
545     static const D3DVERTEXELEMENT9 declaration1[] =
546     {
547         {0, 0, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
548         {1, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
549         {2, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
550         {3, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
551         {4, 0, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
552         {5, 0, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
553         {6, 0, D3DDECLTYPE_SHORT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
554         {7, 0, D3DDECLTYPE_SHORT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
555         {8, 0, D3DDECLTYPE_UBYTE4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
556         {9, 0, D3DDECLTYPE_SHORT2N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
557         {10, 0, D3DDECLTYPE_SHORT4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
558         {11, 0, D3DDECLTYPE_UDEC3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
559         {12, 0, D3DDECLTYPE_DEC3N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
560         {13, 0, D3DDECLTYPE_FLOAT16_2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
561         {14, 0, D3DDECLTYPE_FLOAT16_4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
562         D3DDECL_END(),
563     };
564     static const D3DVERTEXELEMENT9 declaration2[] =
565     {
566         {0, 8, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
567         {1, 8, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
568         {2, 8, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
569         {3, 8, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
570         {4, 8, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
571         {5, 8, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
572         {6, 8, D3DDECLTYPE_SHORT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
573         {7, 8, D3DDECLTYPE_SHORT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
574         {0, 8, D3DDECLTYPE_UBYTE4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
575         {1, 8, D3DDECLTYPE_SHORT2N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
576         {2, 8, D3DDECLTYPE_SHORT4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
577         {3, 8, D3DDECLTYPE_UDEC3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
578         {4, 8, D3DDECLTYPE_DEC3N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
579         {5, 8, D3DDECLTYPE_FLOAT16_2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
580         {6, 8, D3DDECLTYPE_FLOAT16_4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
581         {7, 8, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
582         D3DDECL_END(),
583     };
584     static const UINT sizes1[] =
585     {
586         4,  8,  12, 16,
587         4,  4,  4,  8,
588         4,  4,  8,  4,
589         4,  4,  8,  0,
590     };
591     static const UINT sizes2[] =
592     {
593         12, 16, 20, 24,
594         12, 12, 16, 16,
595     };
596     unsigned int i;
597     UINT size;
598
599     size = D3DXGetDeclVertexSize(NULL, 0);
600     ok(size == 0, "Got size %#x, expected 0.\n", size);
601
602     for (i = 0; i < 16; ++i)
603     {
604         size = D3DXGetDeclVertexSize(declaration1, i);
605         ok(size == sizes1[i], "Got size %u for stream %u, expected %u.\n", size, i, sizes1[i]);
606     }
607
608     for (i = 0; i < 8; ++i)
609     {
610         size = D3DXGetDeclVertexSize(declaration2, i);
611         ok(size == sizes2[i], "Got size %u for stream %u, expected %u.\n", size, i, sizes2[i]);
612     }
613 }
614
615 START_TEST(mesh)
616 {
617     D3DXBoundProbeTest();
618     D3DXComputeBoundingBoxTest();
619     D3DXComputeBoundingSphereTest();
620     D3DXDeclaratorFromFVFTest();
621     D3DXGetFVFVertexSizeTest();
622     D3DXIntersectTriTest();
623     D3DXCreateSphereTest();
624     test_get_decl_vertex_size();
625 }