comctl32: Add support for alpha blending in ImageList_DrawIndirect.
[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;
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             for (i=0; i<4; i++)
266             {
267                 ok(decl[i].Stream == exp1[i].Stream, "Returned stream %d, expected %d\n", decl[i].Stream, exp1[i].Stream);
268                 ok(decl[i].Type == exp1[i].Type, "Returned type %d, expected %d\n", decl[i].Type, exp1[i].Type);
269                 ok(decl[i].Method == exp1[i].Method, "Returned method %d, expected %d\n", decl[i].Method, exp1[i].Method);
270                 ok(decl[i].Usage == exp1[i].Usage, "Returned usage %d, expected %d\n", decl[i].Usage, exp1[i].Usage);
271                 ok(decl[i].UsageIndex == exp1[i].UsageIndex, "Returned usage index %d, expected %d\n", decl[i].UsageIndex, exp1[i].UsageIndex);
272                 ok(decl[i].Offset == exp1[i].Offset, "Returned offset %d, expected %d\n", decl[1].Offset, exp1[i].Offset);
273             }
274             ok(decl[5].Stream == 0xFF, "Returned too long vertex declaration\n"); /* end element */
275         }
276     }
277
278     todo_wine
279     {
280         hr = D3DXDeclaratorFromFVF(D3DFVF_XYZRHW | D3DFVF_PSIZE, decl);
281         ok(hr == D3D_OK, "D3DXDeclaratorFromFVF returned %#x, expected %#x\n", hr, D3D_OK);
282
283         if (hr == D3D_OK)
284         {
285             for (i=0; i<1; i++)
286             {
287                 ok(decl[i].Stream == exp2[i].Stream, "Returned stream %d, expected %d\n", decl[i].Stream, exp2[i].Stream);
288                 ok(decl[i].Type == exp2[i].Type, "Returned type %d, expected %d\n", decl[i].Type, exp1[i].Type);
289                 ok(decl[i].Method == exp2[i].Method, "Returned method %d, expected %d\n", decl[i].Method, exp2[i].Method);
290                 ok(decl[i].Usage == exp2[i].Usage, "Returned usage %d, expected %d\n", decl[i].Usage, exp2[i].Usage);
291                 ok(decl[i].UsageIndex == exp2[i].UsageIndex, "Returned usage index %d, expected %d\n", decl[i].UsageIndex, exp2[i].UsageIndex);
292                 ok(decl[i].Offset == exp2[i].Offset, "Returned offset %d, expected %d\n", decl[1].Offset, exp2[i].Offset);
293             }
294             ok(decl[2].Stream == 0xFF, "Returned too long vertex declaration\n"); /* end element */
295         }
296     }
297
298     todo_wine
299     {
300         hr = D3DXDeclaratorFromFVF(D3DFVF_XYZB5, decl);
301         ok(hr == D3DERR_INVALIDCALL, "D3DXDeclaratorFromFVF returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
302
303         hr = D3DXDeclaratorFromFVF(D3DFVF_XYZB5 | D3DFVF_LASTBETA_UBYTE4, decl);
304         ok(hr == D3D_OK, "D3DXDeclaratorFromFVF returned %#x, expected %#x\n", hr, D3D_OK);
305
306         if (hr == D3D_OK)
307         {
308             for (i=0; i<2; i++)
309             {
310                 ok(decl[i].Stream == exp3[i].Stream, "Returned stream %d, expected %d\n", decl[i].Stream, exp3[i].Stream);
311                 ok(decl[i].Type == exp3[i].Type, "Returned type %d, expected %d\n", decl[i].Type, exp3[i].Type);
312                 ok(decl[i].Method == exp3[i].Method, "Returned method %d, expected %d\n", decl[i].Method, exp3[i].Method);
313                 ok(decl[i].Usage == exp3[i].Usage, "Returned usage %d, expected %d\n", decl[i].Usage, exp3[i].Usage);
314                 ok(decl[i].UsageIndex == exp3[i].UsageIndex, "Returned usage index %d, expected %d\n", decl[i].UsageIndex, exp3[i].UsageIndex);
315                 ok(decl[i].Offset == exp3[i].Offset, "Returned offset %d, expected %d\n", decl[1].Offset, exp3[i].Offset);
316             }
317             ok(decl[3].Stream == 0xFF, "Returned too long vertex declaration\n"); /* end element */
318         }
319     }
320 }
321
322 static void D3DXGetFVFVertexSizeTest(void)
323 {
324     UINT got;
325
326     compare_vertex_sizes (D3DFVF_XYZ, 12);
327
328     compare_vertex_sizes (D3DFVF_XYZB3, 24);
329
330     compare_vertex_sizes (D3DFVF_XYZB5, 32);
331
332     compare_vertex_sizes (D3DFVF_XYZ | D3DFVF_NORMAL, 24);
333
334     compare_vertex_sizes (D3DFVF_XYZ | D3DFVF_DIFFUSE, 16);
335
336     compare_vertex_sizes (
337         D3DFVF_XYZ |
338         D3DFVF_TEX1 |
339         D3DFVF_TEXCOORDSIZE1(0), 16);
340     compare_vertex_sizes (
341         D3DFVF_XYZ |
342         D3DFVF_TEX2 |
343         D3DFVF_TEXCOORDSIZE1(0) |
344         D3DFVF_TEXCOORDSIZE1(1), 20);
345
346     compare_vertex_sizes (
347         D3DFVF_XYZ |
348         D3DFVF_TEX1 |
349         D3DFVF_TEXCOORDSIZE2(0), 20);
350
351     compare_vertex_sizes (
352         D3DFVF_XYZ |
353         D3DFVF_TEX2 |
354         D3DFVF_TEXCOORDSIZE2(0) |
355         D3DFVF_TEXCOORDSIZE2(1), 28);
356
357     compare_vertex_sizes (
358         D3DFVF_XYZ |
359         D3DFVF_TEX6 |
360         D3DFVF_TEXCOORDSIZE2(0) |
361         D3DFVF_TEXCOORDSIZE2(1) |
362         D3DFVF_TEXCOORDSIZE2(2) |
363         D3DFVF_TEXCOORDSIZE2(3) |
364         D3DFVF_TEXCOORDSIZE2(4) |
365         D3DFVF_TEXCOORDSIZE2(5), 60);
366
367     compare_vertex_sizes (
368         D3DFVF_XYZ |
369         D3DFVF_TEX8 |
370         D3DFVF_TEXCOORDSIZE2(0) |
371         D3DFVF_TEXCOORDSIZE2(1) |
372         D3DFVF_TEXCOORDSIZE2(2) |
373         D3DFVF_TEXCOORDSIZE2(3) |
374         D3DFVF_TEXCOORDSIZE2(4) |
375         D3DFVF_TEXCOORDSIZE2(5) |
376         D3DFVF_TEXCOORDSIZE2(6) |
377         D3DFVF_TEXCOORDSIZE2(7), 76);
378
379     compare_vertex_sizes (
380         D3DFVF_XYZ |
381         D3DFVF_TEX1 |
382         D3DFVF_TEXCOORDSIZE3(0), 24);
383
384     compare_vertex_sizes (
385         D3DFVF_XYZ |
386         D3DFVF_TEX4 |
387         D3DFVF_TEXCOORDSIZE3(0) |
388         D3DFVF_TEXCOORDSIZE3(1) |
389         D3DFVF_TEXCOORDSIZE3(2) |
390         D3DFVF_TEXCOORDSIZE3(3), 60);
391
392     compare_vertex_sizes (
393         D3DFVF_XYZ |
394         D3DFVF_TEX1 |
395         D3DFVF_TEXCOORDSIZE4(0), 28);
396
397     compare_vertex_sizes (
398         D3DFVF_XYZ |
399         D3DFVF_TEX2 |
400         D3DFVF_TEXCOORDSIZE4(0) |
401         D3DFVF_TEXCOORDSIZE4(1), 44);
402
403     compare_vertex_sizes (
404         D3DFVF_XYZ |
405         D3DFVF_TEX3 |
406         D3DFVF_TEXCOORDSIZE4(0) |
407         D3DFVF_TEXCOORDSIZE4(1) |
408         D3DFVF_TEXCOORDSIZE4(2), 60);
409
410     compare_vertex_sizes (
411         D3DFVF_XYZB5 |
412         D3DFVF_NORMAL |
413         D3DFVF_DIFFUSE |
414         D3DFVF_SPECULAR |
415         D3DFVF_TEX8 |
416         D3DFVF_TEXCOORDSIZE4(0) |
417         D3DFVF_TEXCOORDSIZE4(1) |
418         D3DFVF_TEXCOORDSIZE4(2) |
419         D3DFVF_TEXCOORDSIZE4(3) |
420         D3DFVF_TEXCOORDSIZE4(4) |
421         D3DFVF_TEXCOORDSIZE4(5) |
422         D3DFVF_TEXCOORDSIZE4(6) |
423         D3DFVF_TEXCOORDSIZE4(7), 180);
424 }
425
426 static void D3DXIntersectTriTest(void)
427 {
428     BOOL exp_res, got_res;
429     D3DXVECTOR3 position, ray, vertex[3];
430     FLOAT exp_dist, got_dist, exp_u, got_u, exp_v, got_v;
431
432     vertex[0].x = 1.0f; vertex[0].y = 0.0f; vertex[0].z = 0.0f;
433     vertex[1].x = 2.0f; vertex[1].y = 0.0f; vertex[1].z = 0.0f;
434     vertex[2].x = 1.0f; vertex[2].y = 1.0f; vertex[2].z = 0.0f;
435
436     position.x = -14.5f; position.y = -23.75f; position.z = -32.0f;
437
438     ray.x = 2.0f; ray.y = 3.0f; ray.z = 4.0f;
439
440     exp_res = TRUE; exp_u = 0.5f; exp_v = 0.25f; exp_dist = 8.0f;
441
442     got_res = D3DXIntersectTri(&vertex[0],&vertex[1],&vertex[2],&position,&ray,&got_u,&got_v,&got_dist);
443     ok( got_res == exp_res, "Expected result = %d, got %d\n",exp_res,got_res);
444     ok( compare(exp_u,got_u), "Expected u = %f, got %f\n",exp_u,got_u);
445     ok( compare(exp_v,got_v), "Expected v = %f, got %f\n",exp_v,got_v);
446     ok( compare(exp_dist,got_dist), "Expected distance = %f, got %f\n",exp_dist,got_dist);
447
448 /*Only positive ray is taken in account*/
449
450     vertex[0].x = 1.0f; vertex[0].y = 0.0f; vertex[0].z = 0.0f;
451     vertex[1].x = 2.0f; vertex[1].y = 0.0f; vertex[1].z = 0.0f;
452     vertex[2].x = 1.0f; vertex[2].y = 1.0f; vertex[2].z = 0.0f;
453
454     position.x = 17.5f; position.y = 24.25f; position.z = 32.0f;
455
456     ray.x = 2.0f; ray.y = 3.0f; ray.z = 4.0f;
457
458     exp_res = FALSE;
459
460     got_res = D3DXIntersectTri(&vertex[0],&vertex[1],&vertex[2],&position,&ray,&got_u,&got_v,&got_dist);
461     ok( got_res == exp_res, "Expected result = %d, got %d\n",exp_res,got_res);
462
463 /*Intersection between ray and triangle in a same plane is considered as empty*/
464
465     vertex[0].x = 4.0f; vertex[0].y = 0.0f; vertex[0].z = 0.0f;
466     vertex[1].x = 6.0f; vertex[1].y = 0.0f; vertex[1].z = 0.0f;
467     vertex[2].x = 4.0f; vertex[2].y = 2.0f; vertex[2].z = 0.0f;
468
469     position.x = 1.0f; position.y = 1.0f; position.z = 0.0f;
470
471     ray.x = 1.0f; ray.y = 0.0f; ray.z = 0.0f;
472
473     exp_res = FALSE;
474
475     got_res = D3DXIntersectTri(&vertex[0],&vertex[1],&vertex[2],&position,&ray,&got_u,&got_v,&got_dist);
476     ok( got_res == exp_res, "Expected result = %d, got %d\n",exp_res,got_res);
477 }
478
479 static void test_get_decl_vertex_size(void)
480 {
481     static const D3DVERTEXELEMENT9 declaration1[] =
482     {
483         {0, 0, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
484         {1, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
485         {2, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
486         {3, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
487         {4, 0, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
488         {5, 0, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
489         {6, 0, D3DDECLTYPE_SHORT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
490         {7, 0, D3DDECLTYPE_SHORT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
491         {8, 0, D3DDECLTYPE_UBYTE4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
492         {9, 0, D3DDECLTYPE_SHORT2N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
493         {10, 0, D3DDECLTYPE_SHORT4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
494         {11, 0, D3DDECLTYPE_UDEC3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
495         {12, 0, D3DDECLTYPE_DEC3N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
496         {13, 0, D3DDECLTYPE_FLOAT16_2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
497         {14, 0, D3DDECLTYPE_FLOAT16_4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
498         D3DDECL_END(),
499     };
500     static const D3DVERTEXELEMENT9 declaration2[] =
501     {
502         {0, 8, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
503         {1, 8, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
504         {2, 8, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
505         {3, 8, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
506         {4, 8, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
507         {5, 8, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
508         {6, 8, D3DDECLTYPE_SHORT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
509         {7, 8, D3DDECLTYPE_SHORT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
510         {0, 8, D3DDECLTYPE_UBYTE4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
511         {1, 8, D3DDECLTYPE_SHORT2N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
512         {2, 8, D3DDECLTYPE_SHORT4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
513         {3, 8, D3DDECLTYPE_UDEC3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
514         {4, 8, D3DDECLTYPE_DEC3N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
515         {5, 8, D3DDECLTYPE_FLOAT16_2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
516         {6, 8, D3DDECLTYPE_FLOAT16_4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
517         {7, 8, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
518         D3DDECL_END(),
519     };
520     static const UINT sizes1[] =
521     {
522         4,  8,  12, 16,
523         4,  4,  4,  8,
524         4,  4,  8,  4,
525         4,  4,  8,  0,
526     };
527     static const UINT sizes2[] =
528     {
529         12, 16, 20, 24,
530         12, 12, 16, 16,
531     };
532     unsigned int i;
533     UINT size;
534
535     size = D3DXGetDeclVertexSize(NULL, 0);
536     ok(size == 0, "Got size %#x, expected 0.\n", size);
537
538     for (i = 0; i < 16; ++i)
539     {
540         size = D3DXGetDeclVertexSize(declaration1, i);
541         ok(size == sizes1[i], "Got size %u for stream %u, expected %u.\n", size, i, sizes1[i]);
542     }
543
544     for (i = 0; i < 8; ++i)
545     {
546         size = D3DXGetDeclVertexSize(declaration2, i);
547         ok(size == sizes2[i], "Got size %u for stream %u, expected %u.\n", size, i, sizes2[i]);
548     }
549 }
550
551 START_TEST(mesh)
552 {
553     D3DXBoundProbeTest();
554     D3DXComputeBoundingBoxTest();
555     D3DXComputeBoundingSphereTest();
556     D3DXDeclaratorFromFVFTest();
557     D3DXGetFVFVertexSizeTest();
558     D3DXIntersectTriTest();
559     test_get_decl_vertex_size();
560 }