2 * Some unit tests for d3d functions
4 * Copyright (C) 2005 Antoine Chavasse
5 * Copyright (C) 2006 Stefan Dösinger for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/test.h"
27 static LPDIRECTDRAW7 lpDD
= NULL
;
28 static LPDIRECT3D7 lpD3D
= NULL
;
29 static LPDIRECTDRAWSURFACE7 lpDDS
= NULL
;
30 static LPDIRECT3DDEVICE7 lpD3DDevice
= NULL
;
31 static LPDIRECT3DVERTEXBUFFER7 lpVBufSrc
= NULL
;
32 static LPDIRECT3DVERTEXBUFFER7 lpVBufDest1
= NULL
;
33 static LPDIRECT3DVERTEXBUFFER7 lpVBufDest2
= NULL
;
35 /* To compare bad floating point numbers. Not the ideal way to do it,
36 * but it should be enough for here */
37 #define comparefloat(a, b) ( (((a) - (b)) < 0.0001) && (((a) - (b)) > -0.0001) )
39 static HRESULT (WINAPI
*pDirectDrawCreateEx
)(LPGUID
,LPVOID
*,REFIID
,LPUNKNOWN
);
41 typedef struct _VERTEX
43 float x
, y
, z
; /* position */
46 typedef struct _TVERTEX
48 float x
, y
, z
; /* position */
50 } TVERTEX
, *LPTVERTEX
;
53 static void init_function_pointers(void)
55 HMODULE hmod
= GetModuleHandleA("ddraw.dll");
56 pDirectDrawCreateEx
= (void*)GetProcAddress(hmod
, "DirectDrawCreateEx");
60 static BOOL
CreateDirect3D(void)
65 rc
= pDirectDrawCreateEx(NULL
, (void**)&lpDD
,
66 &IID_IDirectDraw7
, NULL
);
67 ok(rc
==DD_OK
|| rc
==DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreateEx returned: %x\n", rc
);
69 trace("DirectDrawCreateEx() failed with an error %x\n", rc
);
73 rc
= IDirectDraw_SetCooperativeLevel(lpDD
, NULL
, DDSCL_NORMAL
);
74 ok(rc
==DD_OK
, "SetCooperativeLevel returned: %x\n", rc
);
76 rc
= IDirectDraw7_QueryInterface(lpDD
, &IID_IDirect3D7
, (void**) &lpD3D
);
77 if (rc
== E_NOINTERFACE
) return FALSE
;
78 ok(rc
==DD_OK
, "QueryInterface returned: %x\n", rc
);
80 memset(&ddsd
, 0, sizeof(ddsd
));
81 ddsd
.dwSize
= sizeof(ddsd
);
82 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
83 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
86 rc
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &lpDDS
, NULL
);
87 ok(rc
==DD_OK
, "CreateSurface returned: %x\n", rc
);
91 rc
= IDirect3D7_CreateDevice(lpD3D
, &IID_IDirect3DTnLHalDevice
, lpDDS
,
93 ok(rc
==D3D_OK
|| rc
==DDERR_NOPALETTEATTACHED
|| rc
==E_OUTOFMEMORY
, "CreateDevice returned: %x\n", rc
);
95 trace("IDirect3D7::CreateDevice() for a TnL Hal device failed with an error %x, trying HAL\n", rc
);
96 rc
= IDirect3D7_CreateDevice(lpD3D
, &IID_IDirect3DHALDevice
, lpDDS
,
99 trace("IDirect3D7::CreateDevice() for a HAL device failed with an error %x, trying RGB\n", rc
);
100 rc
= IDirect3D7_CreateDevice(lpD3D
, &IID_IDirect3DRGBDevice
, lpDDS
,
103 trace("IDirect3D7::CreateDevice() for a RGB device failed with an error %x, giving up\n", rc
);
112 static void ReleaseDirect3D(void)
114 if (lpD3DDevice
!= NULL
)
116 IDirect3DDevice7_Release(lpD3DDevice
);
122 IDirectDrawSurface_Release(lpDDS
);
128 IDirect3D7_Release(lpD3D
);
134 IDirectDraw_Release(lpDD
);
139 static void LightTest(void)
143 D3DLIGHT7 defaultlight
;
144 BOOL bEnabled
= FALSE
;
148 /* Set a few lights with funky indices. */
149 memset(&light
, 0, sizeof(light
));
150 light
.dltType
= D3DLIGHT_DIRECTIONAL
;
151 U1(light
.dcvDiffuse
).r
= 0.5f
;
152 U2(light
.dcvDiffuse
).g
= 0.6f
;
153 U3(light
.dcvDiffuse
).b
= 0.7f
;
154 U2(light
.dvDirection
).y
= 1.f
;
156 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 5, &light
);
157 ok(rc
==D3D_OK
, "SetLight returned: %x\n", rc
);
158 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 10, &light
);
159 ok(rc
==D3D_OK
, "SetLight returned: %x\n", rc
);
160 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 45, &light
);
161 ok(rc
==D3D_OK
, "SetLight returned: %x\n", rc
);
164 /* Try to retrieve a light beyond the indices of the lights that have
166 rc
= IDirect3DDevice7_GetLight(lpD3DDevice
, 50, &light
);
167 ok(rc
==DDERR_INVALIDPARAMS
, "GetLight returned: %x\n", rc
);
168 rc
= IDirect3DDevice7_GetLight(lpD3DDevice
, 2, &light
);
169 ok(rc
==DDERR_INVALIDPARAMS
, "GetLight returned: %x\n", rc
);
172 /* Try to retrieve one of the lights that have been set */
173 rc
= IDirect3DDevice7_GetLight(lpD3DDevice
, 10, &light
);
174 ok(rc
==D3D_OK
, "GetLight returned: %x\n", rc
);
177 /* Enable a light that have been previously set. */
178 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, 10, TRUE
);
179 ok(rc
==D3D_OK
, "LightEnable returned: %x\n", rc
);
182 /* Enable some lights that have not been previously set, and verify that
183 they have been initialized with proper default values. */
184 memset(&defaultlight
, 0, sizeof(D3DLIGHT7
));
185 defaultlight
.dltType
= D3DLIGHT_DIRECTIONAL
;
186 U1(defaultlight
.dcvDiffuse
).r
= 1.f
;
187 U2(defaultlight
.dcvDiffuse
).g
= 1.f
;
188 U3(defaultlight
.dcvDiffuse
).b
= 1.f
;
189 U3(defaultlight
.dvDirection
).z
= 1.f
;
191 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, 20, TRUE
);
192 ok(rc
==D3D_OK
, "LightEnable returned: %x\n", rc
);
193 memset(&light
, 0, sizeof(D3DLIGHT7
));
194 rc
= IDirect3DDevice7_GetLight(lpD3DDevice
, 20, &light
);
195 ok(rc
==D3D_OK
, "GetLight returned: %x\n", rc
);
196 ok(!memcmp(&light
, &defaultlight
, sizeof(D3DLIGHT7
)),
197 "light data doesn't match expected default values\n" );
199 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, 50, TRUE
);
200 ok(rc
==D3D_OK
, "LightEnable returned: %x\n", rc
);
201 memset(&light
, 0, sizeof(D3DLIGHT7
));
202 rc
= IDirect3DDevice7_GetLight(lpD3DDevice
, 50, &light
);
203 ok(rc
==D3D_OK
, "GetLight returned: %x\n", rc
);
204 ok(!memcmp(&light
, &defaultlight
, sizeof(D3DLIGHT7
)),
205 "light data doesn't match expected default values\n" );
208 /* Disable one of the light that have been previously enabled. */
209 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, 20, FALSE
);
210 ok(rc
==D3D_OK
, "LightEnable returned: %x\n", rc
);
212 /* Try to retrieve the enable status of some lights */
213 /* Light 20 is supposed to be disabled */
214 rc
= IDirect3DDevice7_GetLightEnable(lpD3DDevice
, 20, &bEnabled
);
215 ok(rc
==D3D_OK
, "GetLightEnable returned: %x\n", rc
);
216 ok(!bEnabled
, "GetLightEnable says the light is enabled\n");
218 /* Light 10 is supposed to be enabled */
220 rc
= IDirect3DDevice7_GetLightEnable(lpD3DDevice
, 10, &bEnabled
);
221 ok(rc
==D3D_OK
, "GetLightEnable returned: %x\n", rc
);
222 ok(bEnabled
, "GetLightEnable says the light is disabled\n");
224 /* Light 80 has not been set */
225 rc
= IDirect3DDevice7_GetLightEnable(lpD3DDevice
, 80, &bEnabled
);
226 ok(rc
==DDERR_INVALIDPARAMS
, "GetLightEnable returned: %x\n", rc
);
228 /* Light 23 has not been set */
229 rc
= IDirect3DDevice7_GetLightEnable(lpD3DDevice
, 23, &bEnabled
);
230 ok(rc
==DDERR_INVALIDPARAMS
, "GetLightEnable returned: %x\n", rc
);
232 /* Set some lights with invalid parameters */
233 memset(&light
, 0, sizeof(D3DLIGHT7
));
235 U1(light
.dcvDiffuse
).r
= 1.f
;
236 U2(light
.dcvDiffuse
).g
= 1.f
;
237 U3(light
.dcvDiffuse
).b
= 1.f
;
238 U3(light
.dvDirection
).z
= 1.f
;
239 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 100, &light
);
240 ok(rc
==DDERR_INVALIDPARAMS
, "SetLight returned: %x\n", rc
);
242 memset(&light
, 0, sizeof(D3DLIGHT7
));
243 light
.dltType
= 12345;
244 U1(light
.dcvDiffuse
).r
= 1.f
;
245 U2(light
.dcvDiffuse
).g
= 1.f
;
246 U3(light
.dcvDiffuse
).b
= 1.f
;
247 U3(light
.dvDirection
).z
= 1.f
;
248 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 101, &light
);
249 ok(rc
==DDERR_INVALIDPARAMS
, "SetLight returned: %x\n", rc
);
251 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 102, NULL
);
252 ok(rc
==DDERR_INVALIDPARAMS
, "SetLight returned: %x\n", rc
);
254 memset(&light
, 0, sizeof(D3DLIGHT7
));
255 light
.dltType
= D3DLIGHT_SPOT
;
256 U1(light
.dcvDiffuse
).r
= 1.f
;
257 U2(light
.dcvDiffuse
).g
= 1.f
;
258 U3(light
.dcvDiffuse
).b
= 1.f
;
259 U3(light
.dvDirection
).z
= 1.f
;
261 light
.dvAttenuation0
= -one
/ zero
; /* -INFINITY */
262 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 103, &light
);
263 ok(rc
==DDERR_INVALIDPARAMS
, "SetLight returned: %x\n", rc
);
265 light
.dvAttenuation0
= -1.0;
266 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 103, &light
);
267 ok(rc
==DDERR_INVALIDPARAMS
, "SetLight returned: %x\n", rc
);
269 light
.dvAttenuation0
= 0.0;
270 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 103, &light
);
271 ok(rc
==D3D_OK
, "SetLight returned: %x\n", rc
);
273 light
.dvAttenuation0
= 1.0;
274 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 103, &light
);
275 ok(rc
==D3D_OK
, "SetLight returned: %x\n", rc
);
277 light
.dvAttenuation0
= one
/ zero
; /* +INFINITY */
278 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 103, &light
);
279 ok(rc
==D3D_OK
, "SetLight returned: %x\n", rc
);
281 light
.dvAttenuation0
= zero
/ zero
; /* NaN */
282 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 103, &light
);
283 ok(rc
==D3D_OK
, "SetLight returned: %x\n", rc
);
285 /* Directional light ignores attenuation */
286 light
.dltType
= D3DLIGHT_DIRECTIONAL
;
287 light
.dvAttenuation0
= -1.0;
288 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 103, &light
);
289 ok(rc
==D3D_OK
, "SetLight returned: %x\n", rc
);
292 static void ProcessVerticesTest(void)
294 D3DVERTEXBUFFERDESC desc
;
300 D3DMATRIX view
= { 2.0, 0.0, 0.0, 0.0,
303 0.0, 0.0, 0.0, 3.0 };
305 D3DMATRIX world
= { 0.0, 1.0, 0.0, 0.0,
308 0.0, 1.0, 1.0, 1.0 };
310 D3DMATRIX proj
= { 1.0, 0.0, 0.0, 1.0,
313 1.0, 0.0, 0.0, 1.0 };
314 /* Create some vertex buffers */
316 memset(&desc
, 0, sizeof(desc
));
317 desc
.dwSize
= sizeof(desc
);
319 desc
.dwFVF
= D3DFVF_XYZ
;
320 desc
.dwNumVertices
= 16;
321 rc
= IDirect3D7_CreateVertexBuffer(lpD3D
, &desc
, &lpVBufSrc
, 0);
322 ok(rc
==D3D_OK
|| rc
==E_OUTOFMEMORY
, "CreateVertexBuffer returned: %x\n", rc
);
325 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc
);
329 memset(&desc
, 0, sizeof(desc
));
330 desc
.dwSize
= sizeof(desc
);
332 desc
.dwFVF
= D3DFVF_XYZRHW
;
333 desc
.dwNumVertices
= 16;
334 /* Msdn says that the last parameter must be 0 - check that */
335 rc
= IDirect3D7_CreateVertexBuffer(lpD3D
, &desc
, &lpVBufDest1
, 4);
336 ok(rc
==D3D_OK
|| rc
==E_OUTOFMEMORY
, "CreateVertexBuffer returned: %x\n", rc
);
339 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc
);
343 memset(&desc
, 0, sizeof(desc
));
344 desc
.dwSize
= sizeof(desc
);
346 desc
.dwFVF
= D3DFVF_XYZ
;
347 desc
.dwNumVertices
= 16;
348 /* Msdn says that the last parameter must be 0 - check that */
349 rc
= IDirect3D7_CreateVertexBuffer(lpD3D
, &desc
, &lpVBufDest2
, 12345678);
350 ok(rc
==D3D_OK
|| rc
==E_OUTOFMEMORY
, "CreateVertexBuffer returned: %x\n", rc
);
353 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc
);
357 rc
= IDirect3DVertexBuffer7_Lock(lpVBufSrc
, 0, (void **) &in
, NULL
);
358 ok(rc
==D3D_OK
, "IDirect3DVertexBuffer::Lock returned: %x\n", rc
);
361 /* Check basic transformation */
378 rc
= IDirect3DVertexBuffer7_Unlock(lpVBufSrc
);
379 ok(rc
==D3D_OK
, "IDirect3DVertexBuffer::Unlock returned: %x\n", rc
);
381 rc
= IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1
, D3DVOP_TRANSFORM
, 0, 4, lpVBufSrc
, 0, lpD3DDevice
, 0);
382 ok(rc
==D3D_OK
, "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc
);
384 rc
= IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest2
, D3DVOP_TRANSFORM
, 0, 4, lpVBufSrc
, 0, lpD3DDevice
, 0);
385 ok(rc
==D3D_OK
, "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc
);
387 rc
= IDirect3DVertexBuffer7_Lock(lpVBufDest1
, 0, (void **) &out
, NULL
);
388 ok(rc
==D3D_OK
, "IDirect3DVertexBuffer::Lock returned: %x\n", rc
);
391 /* Check the results */
392 ok( comparefloat(out
[0].x
, 128.0 ) &&
393 comparefloat(out
[0].y
, 128.0 ) &&
394 comparefloat(out
[0].z
, 0.0 ) &&
395 comparefloat(out
[0].rhw
, 1.0 ),
396 "Output 0 vertex is (%f , %f , %f , %f)\n", out
[0].x
, out
[0].y
, out
[0].z
, out
[0].rhw
);
398 ok( comparefloat(out
[1].x
, 256.0 ) &&
399 comparefloat(out
[1].y
, 0.0 ) &&
400 comparefloat(out
[1].z
, 1.0 ) &&
401 comparefloat(out
[1].rhw
, 1.0 ),
402 "Output 1 vertex is (%f , %f , %f , %f)\n", out
[1].x
, out
[1].y
, out
[1].z
, out
[1].rhw
);
404 ok( comparefloat(out
[2].x
, 0.0 ) &&
405 comparefloat(out
[2].y
, 256.0 ) &&
406 comparefloat(out
[2].z
, 0.5 ) &&
407 comparefloat(out
[2].rhw
, 1.0 ),
408 "Output 2 vertex is (%f , %f , %f , %f)\n", out
[2].x
, out
[2].y
, out
[2].z
, out
[2].rhw
);
410 ok( comparefloat(out
[3].x
, 192.0 ) &&
411 comparefloat(out
[3].y
, 192.0 ) &&
412 comparefloat(out
[3].z
, 0.25 ) &&
413 comparefloat(out
[3].rhw
, 1.0 ),
414 "Output 3 vertex is (%f , %f , %f , %f)\n", out
[3].x
, out
[3].y
, out
[3].z
, out
[3].rhw
);
416 rc
= IDirect3DVertexBuffer7_Unlock(lpVBufDest1
);
417 ok(rc
==D3D_OK
, "IDirect3DVertexBuffer::Unlock returned: %x\n", rc
);
420 rc
= IDirect3DVertexBuffer7_Lock(lpVBufDest2
, 0, (void **) &out2
, NULL
);
421 ok(rc
==D3D_OK
, "IDirect3DVertexBuffer::Lock returned: %x\n", rc
);
423 /* Small thing without much practial meaning, but I stumbled upon it,
424 * so let's check for it: If the output vertex buffer has to RHW value,
425 * The RHW value of the last vertex is written into the next vertex
427 ok( comparefloat(out2
[4].x
, 1.0 ) &&
428 comparefloat(out2
[4].y
, 0.0 ) &&
429 comparefloat(out2
[4].z
, 0.0 ),
430 "Output 4 vertex is (%f , %f , %f)\n", out2
[4].x
, out2
[4].y
, out2
[4].z
);
432 rc
= IDirect3DVertexBuffer7_Unlock(lpVBufDest2
);
433 ok(rc
==D3D_OK
, "IDirect3DVertexBuffer::Unlock returned: %x\n", rc
);
436 /* Try a more complicated viewport, same vertices */
437 memset(&vp
, 0, sizeof(vp
));
444 rc
= IDirect3DDevice7_SetViewport(lpD3DDevice
, &vp
);
445 ok(rc
==D3D_OK
, "IDirect3DDevice7_SetViewport failed with rc=%x\n", rc
);
448 rc
= IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1
, D3DVOP_TRANSFORM
, 0, 4, lpVBufSrc
, 0, lpD3DDevice
, 0);
449 ok(rc
==D3D_OK
, "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc
);
451 rc
= IDirect3DVertexBuffer7_Lock(lpVBufDest1
, 0, (void **) &out
, NULL
);
452 ok(rc
==D3D_OK
, "IDirect3DVertexBuffer::Lock returned: %x\n", rc
);
455 /* Check the results */
456 ok( comparefloat(out
[0].x
, 133.0 ) &&
457 comparefloat(out
[0].y
, 70.0 ) &&
458 comparefloat(out
[0].z
, -2.0 ) &&
459 comparefloat(out
[0].rhw
, 1.0 ),
460 "Output 0 vertex is (%f , %f , %f , %f)\n", out
[0].x
, out
[0].y
, out
[0].z
, out
[0].rhw
);
462 ok( comparefloat(out
[1].x
, 256.0 ) &&
463 comparefloat(out
[1].y
, 5.0 ) &&
464 comparefloat(out
[1].z
, 4.0 ) &&
465 comparefloat(out
[1].rhw
, 1.0 ),
466 "Output 1 vertex is (%f , %f , %f , %f)\n", out
[1].x
, out
[1].y
, out
[1].z
, out
[1].rhw
);
468 ok( comparefloat(out
[2].x
, 10.0 ) &&
469 comparefloat(out
[2].y
, 135.0 ) &&
470 comparefloat(out
[2].z
, 1.0 ) &&
471 comparefloat(out
[2].rhw
, 1.0 ),
472 "Output 2 vertex is (%f , %f , %f , %f)\n", out
[1].x
, out
[1].y
, out
[1].z
, out
[1].rhw
);
474 ok( comparefloat(out
[3].x
, 194.5 ) &&
475 comparefloat(out
[3].y
, 102.5 ) &&
476 comparefloat(out
[3].z
, -0.5 ) &&
477 comparefloat(out
[3].rhw
, 1.0 ),
478 "Output 3 vertex is (%f , %f , %f , %f)\n", out
[3].x
, out
[3].y
, out
[3].z
, out
[3].rhw
);
480 rc
= IDirect3DVertexBuffer7_Unlock(lpVBufDest1
);
481 ok(rc
==D3D_OK
, "IDirect3DVertexBuffer::Unlock returned: %x\n", rc
);
484 /* Play with some matrices. */
486 rc
= IDirect3DDevice7_SetTransform(lpD3DDevice
, D3DTRANSFORMSTATE_VIEW
, &view
);
487 ok(rc
==D3D_OK
, "IDirect3DDevice7_SetTransform failed\n");
489 rc
= IDirect3DDevice7_SetTransform(lpD3DDevice
, D3DTRANSFORMSTATE_PROJECTION
, &proj
);
490 ok(rc
==D3D_OK
, "IDirect3DDevice7_SetTransform failed\n");
492 rc
= IDirect3DDevice7_SetTransform(lpD3DDevice
, D3DTRANSFORMSTATE_WORLD
, &world
);
493 ok(rc
==D3D_OK
, "IDirect3DDevice7_SetTransform failed\n");
495 rc
= IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1
, D3DVOP_TRANSFORM
, 0, 4, lpVBufSrc
, 0, lpD3DDevice
, 0);
496 ok(rc
==D3D_OK
, "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc
);
498 rc
= IDirect3DVertexBuffer7_Lock(lpVBufDest1
, 0, (void **) &out
, NULL
);
499 ok(rc
==D3D_OK
, "IDirect3DVertexBuffer::Lock returned: %x\n", rc
);
502 /* Keep the viewport simpler, otherwise we get bad numbers to compare */
509 rc
= IDirect3DDevice7_SetViewport(lpD3DDevice
, &vp
);
510 ok(rc
==D3D_OK
, "IDirect3DDevice7_SetViewport failed\n");
512 /* Check the results */
513 ok( comparefloat(out
[0].x
, 256.0 ) && /* X coordinate is cut at the surface edges */
514 comparefloat(out
[0].y
, 70.0 ) &&
515 comparefloat(out
[0].z
, -2.0 ) &&
516 comparefloat(out
[0].rhw
, (1.0 / 3.0)),
517 "Output 0 vertex is (%f , %f , %f , %f)\n", out
[0].x
, out
[0].y
, out
[0].z
, out
[0].rhw
);
519 ok( comparefloat(out
[1].x
, 256.0 ) &&
520 comparefloat(out
[1].y
, 78.125000 ) &&
521 comparefloat(out
[1].z
, -2.750000 ) &&
522 comparefloat(out
[1].rhw
, 0.125000 ),
523 "Output 1 vertex is (%f , %f , %f , %f)\n", out
[1].x
, out
[1].y
, out
[1].z
, out
[1].rhw
);
525 ok( comparefloat(out
[2].x
, 256.0 ) &&
526 comparefloat(out
[2].y
, 44.000000 ) &&
527 comparefloat(out
[2].z
, 0.400000 ) &&
528 comparefloat(out
[2].rhw
, 0.400000 ),
529 "Output 2 vertex is (%f , %f , %f , %f)\n", out
[2].x
, out
[2].y
, out
[2].z
, out
[2].rhw
);
531 ok( comparefloat(out
[3].x
, 256.0 ) &&
532 comparefloat(out
[3].y
, 81.818184 ) &&
533 comparefloat(out
[3].z
, -3.090909 ) &&
534 comparefloat(out
[3].rhw
, 0.363636 ),
535 "Output 3 vertex is (%f , %f , %f , %f)\n", out
[3].x
, out
[3].y
, out
[3].z
, out
[3].rhw
);
537 rc
= IDirect3DVertexBuffer7_Unlock(lpVBufDest1
);
538 ok(rc
==D3D_OK
, "IDirect3DVertexBuffer::Unlock returned: %x\n", rc
);
542 IDirect3DVertexBuffer7_Release(lpVBufSrc
);
543 IDirect3DVertexBuffer7_Release(lpVBufDest1
);
544 IDirect3DVertexBuffer7_Release(lpVBufDest2
);
547 static void StateTest( void )
551 /* The msdn says its undocumented, does it return an error too? */
552 rc
= IDirect3DDevice7_SetRenderState(lpD3DDevice
, D3DRENDERSTATE_ZVISIBLE
, TRUE
);
553 ok(rc
== D3D_OK
, "IDirect3DDevice7_SetRenderState(D3DRENDERSTATE_ZVISIBLE, TRUE) returned %08x\n", rc
);
554 rc
= IDirect3DDevice7_SetRenderState(lpD3DDevice
, D3DRENDERSTATE_ZVISIBLE
, FALSE
);
555 ok(rc
== D3D_OK
, "IDirect3DDevice7_SetRenderState(D3DRENDERSTATE_ZVISIBLE, FALSE) returned %08x\n", rc
);
559 static void SceneTest(void)
563 /* Test an EndScene without beginscene. Should return an error */
564 hr
= IDirect3DDevice7_EndScene(lpD3DDevice
);
565 ok(hr
== D3DERR_SCENE_NOT_IN_SCENE
, "IDirect3DDevice7_EndScene returned %08x\n", hr
);
567 /* Test a normal BeginScene / EndScene pair, this should work */
568 hr
= IDirect3DDevice7_BeginScene(lpD3DDevice
);
569 ok(hr
== D3D_OK
, "IDirect3DDevice7_BeginScene failed with %08x\n", hr
);
572 hr
= IDirect3DDevice7_EndScene(lpD3DDevice
);
573 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndScene failed with %08x\n", hr
);
576 /* Test another EndScene without having begun a new scene. Should return an error */
577 hr
= IDirect3DDevice7_EndScene(lpD3DDevice
);
578 ok(hr
== D3DERR_SCENE_NOT_IN_SCENE
, "IDirect3DDevice7_EndScene returned %08x\n", hr
);
580 /* Two nested BeginScene and EndScene calls */
581 hr
= IDirect3DDevice7_BeginScene(lpD3DDevice
);
582 ok(hr
== D3D_OK
, "IDirect3DDevice7_BeginScene failed with %08x\n", hr
);
583 hr
= IDirect3DDevice7_BeginScene(lpD3DDevice
);
584 ok(hr
== D3DERR_SCENE_IN_SCENE
, "IDirect3DDevice7_BeginScene returned %08x\n", hr
);
585 hr
= IDirect3DDevice7_EndScene(lpD3DDevice
);
586 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndScene failed with %08x\n", hr
);
587 hr
= IDirect3DDevice7_EndScene(lpD3DDevice
);
588 ok(hr
== D3DERR_SCENE_NOT_IN_SCENE
, "IDirect3DDevice7_EndScene returned %08x\n", hr
);
590 /* TODO: Verify that blitting works in the same way as in d3d9 */
593 static void LimitTest(void)
595 IDirectDrawSurface7
*pTexture
= NULL
;
600 memset(&ddsd
, 0, sizeof(ddsd
));
601 ddsd
.dwSize
= sizeof(ddsd
);
602 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
603 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
606 hr
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &pTexture
, NULL
);
607 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
608 if(!pTexture
) return;
610 for(i
= 0; i
< 8; i
++) {
611 hr
= IDirect3DDevice7_SetTexture(lpD3DDevice
, i
, pTexture
);
612 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture for sampler %d failed with %08x\n", i
, hr
);
613 hr
= IDirect3DDevice7_SetTexture(lpD3DDevice
, i
, NULL
);
614 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture for sampler %d failed with %08x\n", i
, hr
);
615 hr
= IDirect3DDevice7_SetTextureStageState(lpD3DDevice
, i
, D3DTSS_COLOROP
, D3DTOP_ADD
);
616 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %08x\n", i
, hr
);
619 IDirectDrawSurface7_Release(pTexture
);
622 static HRESULT WINAPI
enumDevicesCallback(GUID
*Guid
,LPSTR DeviceDescription
,LPSTR DeviceName
, D3DDEVICEDESC
*hal
, D3DDEVICEDESC
*hel
, VOID
*ctx
)
624 UINT ver
= *((UINT
*) ctx
);
625 if(IsEqualGUID(&IID_IDirect3DRGBDevice
, Guid
))
627 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
628 "RGB Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
629 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
630 "RGB Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
631 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
632 "RGB Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
633 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
634 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
636 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
637 "RGB Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
638 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
639 "RGB Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
640 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
641 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
642 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
643 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
645 else if(IsEqualGUID(&IID_IDirect3DHALDevice
, Guid
))
647 /* pow2 is hardware dependent */
649 ok(hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
650 "HAL Device %d hal line caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
651 ok(hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
652 "HAL Device %d hal tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
653 ok((hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
654 "HAL Device %d hel line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
655 ok((hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
656 "HAL Device %d hel tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
658 else if(IsEqualGUID(&IID_IDirect3DRefDevice
, Guid
))
660 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
661 "REF Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
662 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
663 "REF Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
664 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
665 "REF Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
666 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
667 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
669 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
670 "REF Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
671 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
672 "REF Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
673 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
674 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
675 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
676 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
678 else if(IsEqualGUID(&IID_IDirect3DRampDevice
, Guid
))
680 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
681 "Ramp Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
682 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
683 "Ramp Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
684 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
685 "Ramp Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
686 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
687 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
689 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
690 "Ramp Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
691 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
692 "Ramp Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
693 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
694 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
695 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
696 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
698 else if(IsEqualGUID(&IID_IDirect3DMMXDevice
, Guid
))
700 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
701 "MMX Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
702 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
703 "MMX Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
704 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
705 "MMX Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
706 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
707 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
709 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
710 "MMX Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
711 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
712 "MMX Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
713 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
714 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
715 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
716 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
720 ok(FALSE
, "Unexpected device enumerated: \"%s\" \"%s\"\n", DeviceDescription
, DeviceName
);
721 if(hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) trace("hal line has pow2 set\n");
722 else trace("hal line does NOT have pow2 set\n");
723 if(hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) trace("hal tri has pow2 set\n");
724 else trace("hal tri does NOT have pow2 set\n");
725 if(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) trace("hel line has pow2 set\n");
726 else trace("hel line does NOT have pow2 set\n");
727 if(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) trace("hel tri has pow2 set\n");
728 else trace("hel tri does NOT have pow2 set\n");
733 static void CapsTest(void)
741 hr
= DirectDrawCreate(NULL
, &dd1
, NULL
);
742 ok(hr
== DD_OK
, "Cannot create a DirectDraw 1 interface, hr = %08x\n", hr
);
743 hr
= IDirectDraw_QueryInterface(dd1
, &IID_IDirect3D3
, (void **) &d3d3
);
744 ok(hr
== D3D_OK
, "IDirectDraw_QueryInterface returned %08x\n", hr
);
746 IDirect3D3_EnumDevices(d3d3
, enumDevicesCallback
, &ver
);
748 IDirect3D3_Release(d3d3
);
749 IDirectDraw_Release(dd1
);
751 hr
= DirectDrawCreate(NULL
, &dd1
, NULL
);
752 ok(hr
== DD_OK
, "Cannot create a DirectDraw 1 interface, hr = %08x\n", hr
);
753 hr
= IDirectDraw_QueryInterface(dd1
, &IID_IDirect3D2
, (void **) &d3d2
);
754 ok(hr
== D3D_OK
, "IDirectDraw_QueryInterface returned %08x\n", hr
);
756 IDirect3D2_EnumDevices(d3d2
, enumDevicesCallback
, &ver
);
758 IDirect3D2_Release(d3d2
);
759 IDirectDraw_Release(dd1
);
764 init_function_pointers();
765 if(!pDirectDrawCreateEx
) {
766 trace("function DirectDrawCreateEx not available, skipping tests\n");
770 if(!CreateDirect3D()) {
771 trace("Skipping tests\n");
775 ProcessVerticesTest();