2 * Copyright 2008 David Adam
3 * Copyright 2008 Luis Busquets
4 * Copyright 2009 Henri Verbeet for CodeWeavers
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.
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.
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
21 #include "wine/test.h"
24 #define admitted_error 0.0001f
26 #define compare_vertex_sizes(type, exp) \
27 got=D3DXGetFVFVertexSize(type); \
28 ok(got==exp, "Expected: %d, Got: %d\n", exp, got);
30 static BOOL
compare(FLOAT u
, FLOAT v
)
32 return (fabs(u
-v
) < admitted_error
);
35 static BOOL
compare_vec3(D3DXVECTOR3 u
, D3DXVECTOR3 v
)
37 return ( compare(u
.x
, v
.x
) && compare(u
.y
, v
.y
) && compare(u
.z
, v
.z
) );
40 static void D3DXBoundProbeTest(void)
43 D3DXVECTOR3 bottom_point
, center
, top_point
, raydirection
, rayposition
;
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
;
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");
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");
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");
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");
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
;
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");
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
;
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");
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");
92 /*____________Test the Sphere case________________________*/
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
;
97 rayposition
.x
= 5.0f
; rayposition
.y
= 5.0f
; rayposition
.z
= 9.0f
;
98 result
= D3DXSphereBoundProbe(¢er
, radius
, &rayposition
, &raydirection
);
99 ok(result
== TRUE
, "expected TRUE, received FALSE\n");
101 rayposition
.x
= 45.0f
; rayposition
.y
= -75.0f
; rayposition
.z
= 49.0f
;
102 result
= D3DXSphereBoundProbe(¢er
, radius
, &rayposition
, &raydirection
);
103 ok(result
== FALSE
, "expected FALSE, received TRUE\n");
105 rayposition
.x
= 5.0f
; rayposition
.y
= 11.0f
; rayposition
.z
= 9.0f
;
106 result
= D3DXSphereBoundProbe(¢er
, radius
, &rayposition
, &raydirection
);
107 ok(result
== FALSE
, "expected FALSE, received TRUE\n");
110 static void D3DXComputeBoundingBoxTest(void)
112 D3DXVECTOR3 exp_max
, exp_min
, got_max
, got_min
, vertex
[5];
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
;
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
;
124 hr
= D3DXComputeBoundingBox(&vertex
[3],2,D3DXGetFVFVertexSize(D3DFVF_XYZ
),&got_min
,&got_max
);
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
);
130 /*________________________*/
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
;
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
;
141 hr
= D3DXComputeBoundingBox(&vertex
[0],5,D3DXGetFVFVertexSize(D3DFVF_XYZ
),&got_min
,&got_max
);
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
);
147 /*________________________*/
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
;
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
;
158 hr
= D3DXComputeBoundingBox(&vertex
[0],4,D3DXGetFVFVertexSize(D3DFVF_XYZ
),&got_min
,&got_max
);
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
);
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
);
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
);
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
);
177 static void D3DXComputeBoundingSphereTest(void)
179 D3DXVECTOR3 exp_cen
, got_cen
, vertex
[5];
180 FLOAT exp_rad
, got_rad
;
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
;
190 exp_cen
.x
= 5.0; exp_cen
.y
= 5.0; exp_cen
.z
= 5.0;
192 hr
= D3DXComputeBoundingSphere(&vertex
[3],2,D3DXGetFVFVertexSize(D3DFVF_XYZ
),&got_cen
,&got_rad
);
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
);
198 /*________________________*/
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
;
206 exp_rad
= 13.707883f
;
207 exp_cen
.x
= 2.408f
; exp_cen
.y
= 2.22f
; exp_cen
.z
= 3.76f
;
209 hr
= D3DXComputeBoundingSphere(&vertex
[0],5,D3DXGetFVFVertexSize(D3DFVF_XYZ
),&got_cen
,&got_rad
);
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
);
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
);
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
);
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
);
228 static void D3DXDeclaratorFromFVFTest(void)
230 D3DVERTEXELEMENT9 decl
[MAX_FVF_DECL_SIZE
];
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},
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},
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},
253 /* Note: passing NULL as declaration segfaults */
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 */
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
);
265 size
= sizeof(exp1
)/sizeof(exp1
[0]);
266 for (i
=0; i
<size
-1; i
++)
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
);
275 ok(decl
[size
-1].Stream
== 0xFF, "Returned too long vertex declaration\n"); /* end element */
281 hr
= D3DXDeclaratorFromFVF(D3DFVF_XYZRHW
| D3DFVF_PSIZE
, decl
);
282 ok(hr
== D3D_OK
, "D3DXDeclaratorFromFVF returned %#x, expected %#x\n", hr
, D3D_OK
);
286 size
= sizeof(exp2
)/sizeof(exp2
[0]);
287 for (i
=0; i
<size
-1; i
++)
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
);
296 ok(decl
[size
-1].Stream
== 0xFF, "Returned too long vertex declaration\n"); /* end element */
302 hr
= D3DXDeclaratorFromFVF(D3DFVF_XYZB5
, decl
);
303 ok(hr
== D3DERR_INVALIDCALL
, "D3DXDeclaratorFromFVF returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
305 hr
= D3DXDeclaratorFromFVF(D3DFVF_XYZB5
| D3DFVF_LASTBETA_UBYTE4
, decl
);
306 ok(hr
== D3D_OK
, "D3DXDeclaratorFromFVF returned %#x, expected %#x\n", hr
, D3D_OK
);
310 size
= sizeof(exp3
)/sizeof(exp3
[0]);
311 for (i
=0; i
<size
-1; i
++)
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
);
320 ok(decl
[size
-1].Stream
== 0xFF, "Returned too long vertex declaration\n"); /* end element */
325 static void D3DXGetFVFVertexSizeTest(void)
329 compare_vertex_sizes (D3DFVF_XYZ
, 12);
331 compare_vertex_sizes (D3DFVF_XYZB3
, 24);
333 compare_vertex_sizes (D3DFVF_XYZB5
, 32);
335 compare_vertex_sizes (D3DFVF_XYZ
| D3DFVF_NORMAL
, 24);
337 compare_vertex_sizes (D3DFVF_XYZ
| D3DFVF_DIFFUSE
, 16);
339 compare_vertex_sizes (
342 D3DFVF_TEXCOORDSIZE1(0), 16);
343 compare_vertex_sizes (
346 D3DFVF_TEXCOORDSIZE1(0) |
347 D3DFVF_TEXCOORDSIZE1(1), 20);
349 compare_vertex_sizes (
352 D3DFVF_TEXCOORDSIZE2(0), 20);
354 compare_vertex_sizes (
357 D3DFVF_TEXCOORDSIZE2(0) |
358 D3DFVF_TEXCOORDSIZE2(1), 28);
360 compare_vertex_sizes (
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);
370 compare_vertex_sizes (
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);
382 compare_vertex_sizes (
385 D3DFVF_TEXCOORDSIZE3(0), 24);
387 compare_vertex_sizes (
390 D3DFVF_TEXCOORDSIZE3(0) |
391 D3DFVF_TEXCOORDSIZE3(1) |
392 D3DFVF_TEXCOORDSIZE3(2) |
393 D3DFVF_TEXCOORDSIZE3(3), 60);
395 compare_vertex_sizes (
398 D3DFVF_TEXCOORDSIZE4(0), 28);
400 compare_vertex_sizes (
403 D3DFVF_TEXCOORDSIZE4(0) |
404 D3DFVF_TEXCOORDSIZE4(1), 44);
406 compare_vertex_sizes (
409 D3DFVF_TEXCOORDSIZE4(0) |
410 D3DFVF_TEXCOORDSIZE4(1) |
411 D3DFVF_TEXCOORDSIZE4(2), 60);
413 compare_vertex_sizes (
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);
429 static void D3DXIntersectTriTest(void)
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
;
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
;
439 position
.x
= -14.5f
; position
.y
= -23.75f
; position
.z
= -32.0f
;
441 ray
.x
= 2.0f
; ray
.y
= 3.0f
; ray
.z
= 4.0f
;
443 exp_res
= TRUE
; exp_u
= 0.5f
; exp_v
= 0.25f
; exp_dist
= 8.0f
;
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
);
451 /*Only positive ray is taken in account*/
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
;
457 position
.x
= 17.5f
; position
.y
= 24.25f
; position
.z
= 32.0f
;
459 ray
.x
= 2.0f
; ray
.y
= 3.0f
; ray
.z
= 4.0f
;
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
);
466 /*Intersection between ray and triangle in a same plane is considered as empty*/
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
;
472 position
.x
= 1.0f
; position
.y
= 1.0f
; position
.z
= 0.0f
;
474 ray
.x
= 1.0f
; ray
.y
= 0.0f
; ray
.z
= 0.0f
;
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
);
482 static void test_get_decl_vertex_size(void)
484 static const D3DVERTEXELEMENT9 declaration1
[] =
486 {0, 0, D3DDECLTYPE_FLOAT1
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
487 {1, 0, D3DDECLTYPE_FLOAT2
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
488 {2, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
489 {3, 0, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
490 {4, 0, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
491 {5, 0, D3DDECLTYPE_UBYTE4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
492 {6, 0, D3DDECLTYPE_SHORT2
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
493 {7, 0, D3DDECLTYPE_SHORT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
494 {8, 0, D3DDECLTYPE_UBYTE4N
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
495 {9, 0, D3DDECLTYPE_SHORT2N
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
496 {10, 0, D3DDECLTYPE_SHORT4N
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
497 {11, 0, D3DDECLTYPE_UDEC3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
498 {12, 0, D3DDECLTYPE_DEC3N
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
499 {13, 0, D3DDECLTYPE_FLOAT16_2
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
500 {14, 0, D3DDECLTYPE_FLOAT16_4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
503 static const D3DVERTEXELEMENT9 declaration2
[] =
505 {0, 8, D3DDECLTYPE_FLOAT1
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
506 {1, 8, D3DDECLTYPE_FLOAT2
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
507 {2, 8, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
508 {3, 8, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
509 {4, 8, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
510 {5, 8, D3DDECLTYPE_UBYTE4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
511 {6, 8, D3DDECLTYPE_SHORT2
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
512 {7, 8, D3DDECLTYPE_SHORT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
513 {0, 8, D3DDECLTYPE_UBYTE4N
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
514 {1, 8, D3DDECLTYPE_SHORT2N
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
515 {2, 8, D3DDECLTYPE_SHORT4N
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
516 {3, 8, D3DDECLTYPE_UDEC3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
517 {4, 8, D3DDECLTYPE_DEC3N
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
518 {5, 8, D3DDECLTYPE_FLOAT16_2
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
519 {6, 8, D3DDECLTYPE_FLOAT16_4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
520 {7, 8, D3DDECLTYPE_FLOAT1
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
523 static const UINT sizes1
[] =
530 static const UINT sizes2
[] =
538 size
= D3DXGetDeclVertexSize(NULL
, 0);
539 ok(size
== 0, "Got size %#x, expected 0.\n", size
);
541 for (i
= 0; i
< 16; ++i
)
543 size
= D3DXGetDeclVertexSize(declaration1
, i
);
544 ok(size
== sizes1
[i
], "Got size %u for stream %u, expected %u.\n", size
, i
, sizes1
[i
]);
547 for (i
= 0; i
< 8; ++i
)
549 size
= D3DXGetDeclVertexSize(declaration2
, i
);
550 ok(size
== sizes2
[i
], "Got size %u for stream %u, expected %u.\n", size
, i
, sizes2
[i
]);
556 D3DXBoundProbeTest();
557 D3DXComputeBoundingBoxTest();
558 D3DXComputeBoundingSphereTest();
559 D3DXDeclaratorFromFVFTest();
560 D3DXGetFVFVertexSizeTest();
561 D3DXIntersectTriTest();
562 test_get_decl_vertex_size();