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);
89 rc = IDirect3D7_CreateDevice(lpD3D, &IID_IDirect3DTnLHalDevice, lpDDS,
91 ok(rc==D3D_OK || rc==DDERR_NOPALETTEATTACHED || rc==E_OUTOFMEMORY, "CreateDevice returned: %x\n", rc);
93 trace("IDirect3D7::CreateDevice() for a TnL Hal device failed with an error %x, trying HAL\n", rc);
94 rc = IDirect3D7_CreateDevice(lpD3D, &IID_IDirect3DHALDevice, lpDDS,
97 trace("IDirect3D7::CreateDevice() for a HAL device failed with an error %x, trying RGB\n", rc);
98 rc = IDirect3D7_CreateDevice(lpD3D, &IID_IDirect3DRGBDevice, lpDDS,
101 trace("IDirect3D7::CreateDevice() for a RGB device failed with an error %x, giving up\n", rc);
110 static void ReleaseDirect3D(void)
112 if (lpD3DDevice != NULL)
114 IDirect3DDevice7_Release(lpD3DDevice);
120 IDirectDrawSurface_Release(lpDDS);
126 IDirect3D7_Release(lpD3D);
132 IDirectDraw_Release(lpDD);
137 static void LightTest(void)
141 D3DLIGHT7 defaultlight;
142 BOOL bEnabled = FALSE;
144 /* Set a few lights with funky indices. */
145 memset(&light, 0, sizeof(light));
146 light.dltType = D3DLIGHT_DIRECTIONAL;
147 U1(light.dcvDiffuse).r = 0.5f;
148 U2(light.dcvDiffuse).g = 0.6f;
149 U3(light.dcvDiffuse).b = 0.7f;
150 U2(light.dvDirection).y = 1.f;
152 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 5, &light);
153 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
154 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 10, &light);
155 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
156 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 45, &light);
157 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
160 /* Try to retrieve a light beyond the indices of the lights that have
162 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
163 ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %x\n", rc);
164 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 2, &light);
165 ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %x\n", rc);
168 /* Try to retrieve one of the lights that have been set */
169 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 10, &light);
170 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
173 /* Enable a light that have been previously set. */
174 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 10, TRUE);
175 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
178 /* Enable some lights that have not been previously set, and verify that
179 they have been initialized with proper default values. */
180 memset(&defaultlight, 0, sizeof(D3DLIGHT7));
181 defaultlight.dltType = D3DLIGHT_DIRECTIONAL;
182 U1(defaultlight.dcvDiffuse).r = 1.f;
183 U2(defaultlight.dcvDiffuse).g = 1.f;
184 U3(defaultlight.dcvDiffuse).b = 1.f;
185 U3(defaultlight.dvDirection).z = 1.f;
187 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, TRUE);
188 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
189 memset(&light, 0, sizeof(D3DLIGHT7));
190 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 20, &light);
191 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
192 ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
193 "light data doesn't match expected default values\n" );
195 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 50, TRUE);
196 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
197 memset(&light, 0, sizeof(D3DLIGHT7));
198 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
199 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
200 ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
201 "light data doesn't match expected default values\n" );
204 /* Disable one of the light that have been previously enabled. */
205 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, FALSE);
206 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
208 /* Try to retrieve the enable status of some lights */
209 /* Light 20 is supposed to be disabled */
210 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 20, &bEnabled );
211 ok(rc==D3D_OK, "GetLightEnable returned: %x\n", rc);
212 ok(!bEnabled, "GetLightEnable says the light is enabled\n");
214 /* Light 10 is supposed to be enabled */
216 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 10, &bEnabled );
217 ok(rc==D3D_OK, "GetLightEnable returned: %x\n", rc);
218 ok(bEnabled, "GetLightEnable says the light is disabled\n");
220 /* Light 80 has not been set */
221 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 80, &bEnabled );
222 ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %x\n", rc);
224 /* Light 23 has not been set */
225 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 23, &bEnabled );
226 ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %x\n", rc);
228 /* Set some lights with invalid parameters */
229 memset(&light, 0, sizeof(D3DLIGHT7));
231 U1(light.dcvDiffuse).r = 1.f;
232 U2(light.dcvDiffuse).g = 1.f;
233 U3(light.dcvDiffuse).b = 1.f;
234 U3(light.dvDirection).z = 1.f;
235 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 100, &light);
236 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
238 memset(&light, 0, sizeof(D3DLIGHT7));
239 light.dltType = 12345;
240 U1(light.dcvDiffuse).r = 1.f;
241 U2(light.dcvDiffuse).g = 1.f;
242 U3(light.dcvDiffuse).b = 1.f;
243 U3(light.dvDirection).z = 1.f;
244 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 101, &light);
245 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
247 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 102, NULL);
248 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
250 memset(&light, 0, sizeof(D3DLIGHT7));
251 light.dltType = D3DLIGHT_SPOT;
252 U1(light.dcvDiffuse).r = 1.f;
253 U2(light.dcvDiffuse).g = 1.f;
254 U3(light.dcvDiffuse).b = 1.f;
255 U3(light.dvDirection).z = 1.f;
257 light.dvAttenuation0 = -1.0 / 0.0; /* -INFINITY */
258 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
259 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
261 light.dvAttenuation0 = -1.0;
262 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
263 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
265 light.dvAttenuation0 = 0.0;
266 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
267 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
269 light.dvAttenuation0 = 1.0;
270 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
271 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
273 light.dvAttenuation0 = 1.0 / 0.0; /* +INFINITY */
274 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
275 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
277 light.dvAttenuation0 = 0.0 / 0.0; /* NaN */
278 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
279 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
281 /* Directional light ignores attenuation */
282 light.dltType = D3DLIGHT_DIRECTIONAL;
283 light.dvAttenuation0 = -1.0;
284 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
285 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
288 static void ProcessVerticesTest(void)
290 D3DVERTEXBUFFERDESC desc;
296 D3DMATRIX view = { 2.0, 0.0, 0.0, 0.0,
299 0.0, 0.0, 0.0, 3.0 };
301 D3DMATRIX world = { 0.0, 1.0, 0.0, 0.0,
304 0.0, 1.0, 1.0, 1.0 };
306 D3DMATRIX proj = { 1.0, 0.0, 0.0, 1.0,
309 1.0, 0.0, 0.0, 1.0 };
310 /* Create some vertex buffers */
312 memset(&desc, 0, sizeof(desc));
313 desc.dwSize = sizeof(desc);
315 desc.dwFVF = D3DFVF_XYZ;
316 desc.dwNumVertices = 16;
317 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufSrc, 0);
318 ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
321 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
325 memset(&desc, 0, sizeof(desc));
326 desc.dwSize = sizeof(desc);
328 desc.dwFVF = D3DFVF_XYZRHW;
329 desc.dwNumVertices = 16;
330 /* Msdn says that the last parameter must be 0 - check that */
331 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufDest1, 4);
332 ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
335 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
339 memset(&desc, 0, sizeof(desc));
340 desc.dwSize = sizeof(desc);
342 desc.dwFVF = D3DFVF_XYZ;
343 desc.dwNumVertices = 16;
344 /* Msdn says that the last parameter must be 0 - check that */
345 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufDest2, 12345678);
346 ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
349 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
353 rc = IDirect3DVertexBuffer7_Lock(lpVBufSrc, 0, (void **) &in, NULL);
354 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
357 /* Check basic transformation */
374 rc = IDirect3DVertexBuffer7_Unlock(lpVBufSrc);
375 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
377 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
378 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
380 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest2, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
381 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
383 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
384 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
387 /* Check the results */
388 ok( comparefloat(out[0].x, 128.0 ) &&
389 comparefloat(out[0].y, 128.0 ) &&
390 comparefloat(out[0].z, 0.0 ) &&
391 comparefloat(out[0].rhw, 1.0 ),
392 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
394 ok( comparefloat(out[1].x, 256.0 ) &&
395 comparefloat(out[1].y, 0.0 ) &&
396 comparefloat(out[1].z, 1.0 ) &&
397 comparefloat(out[1].rhw, 1.0 ),
398 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
400 ok( comparefloat(out[2].x, 0.0 ) &&
401 comparefloat(out[2].y, 256.0 ) &&
402 comparefloat(out[2].z, 0.5 ) &&
403 comparefloat(out[2].rhw, 1.0 ),
404 "Output 2 vertex is (%f , %f , %f , %f)\n", out[2].x, out[2].y, out[2].z, out[2].rhw);
406 ok( comparefloat(out[3].x, 192.0 ) &&
407 comparefloat(out[3].y, 192.0 ) &&
408 comparefloat(out[3].z, 0.25 ) &&
409 comparefloat(out[3].rhw, 1.0 ),
410 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
412 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
413 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
416 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest2, 0, (void **) &out2, NULL);
417 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
419 /* Small thing without much practial meaning, but I stumbled upon it,
420 * so let's check for it: If the output vertex buffer has to RHW value,
421 * The RHW value of the last vertex is written into the next vertex
423 ok( comparefloat(out2[4].x, 1.0 ) &&
424 comparefloat(out2[4].y, 0.0 ) &&
425 comparefloat(out2[4].z, 0.0 ),
426 "Output 4 vertex is (%f , %f , %f)\n", out2[4].x, out2[4].y, out2[4].z);
428 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest2);
429 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
432 /* Try a more complicated viewport, same vertices */
433 memset(&vp, 0, sizeof(vp));
440 rc = IDirect3DDevice7_SetViewport(lpD3DDevice, &vp);
441 ok(rc==D3D_OK, "IDirect3DDevice7_SetViewport failed with rc=%x\n", rc);
444 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
445 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
447 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
448 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
451 /* Check the results */
452 ok( comparefloat(out[0].x, 133.0 ) &&
453 comparefloat(out[0].y, 70.0 ) &&
454 comparefloat(out[0].z, -2.0 ) &&
455 comparefloat(out[0].rhw, 1.0 ),
456 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
458 ok( comparefloat(out[1].x, 256.0 ) &&
459 comparefloat(out[1].y, 5.0 ) &&
460 comparefloat(out[1].z, 4.0 ) &&
461 comparefloat(out[1].rhw, 1.0 ),
462 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
464 ok( comparefloat(out[2].x, 10.0 ) &&
465 comparefloat(out[2].y, 135.0 ) &&
466 comparefloat(out[2].z, 1.0 ) &&
467 comparefloat(out[2].rhw, 1.0 ),
468 "Output 2 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
470 ok( comparefloat(out[3].x, 194.5 ) &&
471 comparefloat(out[3].y, 102.5 ) &&
472 comparefloat(out[3].z, -0.5 ) &&
473 comparefloat(out[3].rhw, 1.0 ),
474 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
476 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
477 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
480 /* Play with some matrices. */
482 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_VIEW, &view);
483 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
485 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_PROJECTION, &proj);
486 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
488 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_WORLD, &world);
489 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
491 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
492 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
494 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
495 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
498 /* Keep the viewport simpler, otherwise we get bad numbers to compare */
505 rc = IDirect3DDevice7_SetViewport(lpD3DDevice, &vp);
506 ok(rc==D3D_OK, "IDirect3DDevice7_SetViewport failed\n");
508 /* Check the results */
509 ok( comparefloat(out[0].x, 256.0 ) && /* X coordinate is cut at the surface edges */
510 comparefloat(out[0].y, 70.0 ) &&
511 comparefloat(out[0].z, -2.0 ) &&
512 comparefloat(out[0].rhw, (1.0 / 3.0)),
513 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
515 ok( comparefloat(out[1].x, 256.0 ) &&
516 comparefloat(out[1].y, 78.125000 ) &&
517 comparefloat(out[1].z, -2.750000 ) &&
518 comparefloat(out[1].rhw, 0.125000 ),
519 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
521 ok( comparefloat(out[2].x, 256.0 ) &&
522 comparefloat(out[2].y, 44.000000 ) &&
523 comparefloat(out[2].z, 0.400000 ) &&
524 comparefloat(out[2].rhw, 0.400000 ),
525 "Output 2 vertex is (%f , %f , %f , %f)\n", out[2].x, out[2].y, out[2].z, out[2].rhw);
527 ok( comparefloat(out[3].x, 256.0 ) &&
528 comparefloat(out[3].y, 81.818184 ) &&
529 comparefloat(out[3].z, -3.090909 ) &&
530 comparefloat(out[3].rhw, 0.363636 ),
531 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
533 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
534 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
538 IDirect3DVertexBuffer7_Release(lpVBufSrc);
539 IDirect3DVertexBuffer7_Release(lpVBufDest1);
540 IDirect3DVertexBuffer7_Release(lpVBufDest2);
543 static void StateTest( void )
547 /* The msdn says its undocumented, does it return an error too? */
548 rc = IDirect3DDevice7_SetRenderState(lpD3DDevice, D3DRENDERSTATE_ZVISIBLE, TRUE);
549 ok(rc == D3D_OK, "IDirect3DDevice7_SetRenderState(D3DRENDERSTATE_ZVISIBLE, TRUE) returned %08x\n", rc);
550 rc = IDirect3DDevice7_SetRenderState(lpD3DDevice, D3DRENDERSTATE_ZVISIBLE, FALSE);
551 ok(rc == D3D_OK, "IDirect3DDevice7_SetRenderState(D3DRENDERSTATE_ZVISIBLE, FALSE) returned %08x\n", rc);
555 static void SceneTest(void)
559 /* Test an EndScene without beginscene. Should return an error */
560 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
561 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
563 /* Test a normal BeginScene / EndScene pair, this should work */
564 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
565 ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed with %08x\n", hr);
568 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
569 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed with %08x\n", hr);
572 /* Test another EndScene without having begun a new scene. Should return an error */
573 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
574 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
576 /* Two nested BeginScene and EndScene calls */
577 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
578 ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed with %08x\n", hr);
579 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
580 ok(hr == D3DERR_SCENE_IN_SCENE, "IDirect3DDevice7_BeginScene returned %08x\n", hr);
581 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
582 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed with %08x\n", hr);
583 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
584 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
586 /* TODO: Verify that blitting works in the same way as in d3d9 */
589 static void LimitTest(void)
591 IDirectDrawSurface7 *pTexture = NULL;
596 memset(&ddsd, 0, sizeof(ddsd));
597 ddsd.dwSize = sizeof(ddsd);
598 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
599 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
602 hr = IDirectDraw7_CreateSurface(lpDD, &ddsd, &pTexture, NULL);
603 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
604 if(!pTexture) return;
606 for(i = 0; i < 8; i++) {
607 hr = IDirect3DDevice7_SetTexture(lpD3DDevice, i, pTexture);
608 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %08x\n", i, hr);
609 hr = IDirect3DDevice7_SetTexture(lpD3DDevice, i, NULL);
610 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %08x\n", i, hr);
611 hr = IDirect3DDevice7_SetTextureStageState(lpD3DDevice, i, D3DTSS_COLOROP, D3DTOP_ADD);
612 ok(hr == D3D_OK, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %08x\n", i, hr);
615 IDirectDrawSurface7_Release(pTexture);
618 static HRESULT WINAPI enumDevicesCallback(GUID *Guid,LPSTR DeviceDescription,LPSTR DeviceName, D3DDEVICEDESC *hal, D3DDEVICEDESC *hel, VOID *ctx)
620 UINT ver = *((UINT *) ctx);
621 if(IsEqualGUID(&IID_IDirect3DRGBDevice, Guid))
623 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
624 "RGB Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
625 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
626 "RGB Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
627 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
628 "RGB Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
629 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
630 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
632 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
633 "RGB Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
634 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
635 "RGB Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
636 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
637 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
638 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
639 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
641 else if(IsEqualGUID(&IID_IDirect3DHALDevice, Guid))
643 /* pow2 is hardware dependent */
645 ok(hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
646 "HAL Device %d hal line caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
647 ok(hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
648 "HAL Device %d hal tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
649 ok((hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
650 "HAL Device %d hel line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
651 ok((hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
652 "HAL Device %d hel tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
654 else if(IsEqualGUID(&IID_IDirect3DRefDevice, Guid))
656 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
657 "REF Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
658 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
659 "REF Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
660 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
661 "REF Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
662 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
663 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
665 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
666 "REF Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
667 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
668 "REF Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
669 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
670 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
671 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
672 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
674 else if(IsEqualGUID(&IID_IDirect3DRampDevice, Guid))
676 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
677 "Ramp Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
678 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
679 "Ramp Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
680 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
681 "Ramp Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
682 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
683 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
685 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
686 "Ramp Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
687 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
688 "Ramp Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
689 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
690 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
691 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
692 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
694 else if(IsEqualGUID(&IID_IDirect3DMMXDevice, Guid))
696 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
697 "MMX Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
698 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
699 "MMX Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
700 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
701 "MMX Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
702 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
703 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
705 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
706 "MMX Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
707 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
708 "MMX Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
709 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
710 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
711 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
712 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
716 ok(FALSE, "Unexpected device enumerated: \"%s\" \"%s\"\n", DeviceDescription, DeviceName);
717 if(hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hal line has pow2 set\n");
718 else trace("hal line does NOT have pow2 set\n");
719 if(hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hal tri has pow2 set\n");
720 else trace("hal tri does NOT have pow2 set\n");
721 if(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hel line has pow2 set\n");
722 else trace("hel line does NOT have pow2 set\n");
723 if(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hel tri has pow2 set\n");
724 else trace("hel tri does NOT have pow2 set\n");
729 static void CapsTest(void)
737 hr = DirectDrawCreate(NULL, &dd1, NULL);
738 ok(hr == DD_OK, "Cannot create a DirectDraw 1 interface, hr = %08x\n", hr);
739 hr = IDirectDraw_QueryInterface(dd1, &IID_IDirect3D3, (void **) &d3d3);
740 ok(hr == D3D_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
742 IDirect3D3_EnumDevices(d3d3, enumDevicesCallback, &ver);
744 IDirect3D3_Release(d3d3);
745 IDirectDraw_Release(dd1);
747 hr = DirectDrawCreate(NULL, &dd1, NULL);
748 ok(hr == DD_OK, "Cannot create a DirectDraw 1 interface, hr = %08x\n", hr);
749 hr = IDirectDraw_QueryInterface(dd1, &IID_IDirect3D2, (void **) &d3d2);
750 ok(hr == D3D_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
752 IDirect3D2_EnumDevices(d3d2, enumDevicesCallback, &ver);
754 IDirect3D2_Release(d3d2);
755 IDirectDraw_Release(dd1);
760 init_function_pointers();
761 if(!pDirectDrawCreateEx) {
762 trace("function DirectDrawCreateEx not available, skipping tests\n");
766 if(!CreateDirect3D()) {
767 trace("Skipping tests\n");
771 ProcessVerticesTest();