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 LPDIRECTDRAWSURFACE7 lpDDSdepth = NULL;
31 static LPDIRECT3DDEVICE7 lpD3DDevice = NULL;
32 static LPDIRECT3DVERTEXBUFFER7 lpVBufSrc = NULL;
33 static LPDIRECT3DVERTEXBUFFER7 lpVBufDest1 = NULL;
34 static LPDIRECT3DVERTEXBUFFER7 lpVBufDest2 = NULL;
36 /* To compare bad floating point numbers. Not the ideal way to do it,
37 * but it should be enough for here */
38 #define comparefloat(a, b) ( (((a) - (b)) < 0.0001) && (((a) - (b)) > -0.0001) )
40 static HRESULT (WINAPI *pDirectDrawCreateEx)(LPGUID,LPVOID*,REFIID,LPUNKNOWN);
42 typedef struct _VERTEX
44 float x, y, z; /* position */
47 typedef struct _TVERTEX
49 float x, y, z; /* position */
51 } TVERTEX, *LPTVERTEX;
54 static void init_function_pointers(void)
56 HMODULE hmod = GetModuleHandleA("ddraw.dll");
57 pDirectDrawCreateEx = (void*)GetProcAddress(hmod, "DirectDrawCreateEx");
61 static BOOL CreateDirect3D(void)
66 rc = pDirectDrawCreateEx(NULL, (void**)&lpDD,
67 &IID_IDirectDraw7, NULL);
68 ok(rc==DD_OK || rc==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", rc);
70 trace("DirectDrawCreateEx() failed with an error %x\n", rc);
74 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
75 ok(rc==DD_OK, "SetCooperativeLevel returned: %x\n", rc);
77 rc = IDirectDraw7_QueryInterface(lpDD, &IID_IDirect3D7, (void**) &lpD3D);
78 if (rc == E_NOINTERFACE) return FALSE;
79 ok(rc==DD_OK, "QueryInterface returned: %x\n", rc);
81 memset(&ddsd, 0, sizeof(ddsd));
82 ddsd.dwSize = sizeof(ddsd);
83 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
84 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
87 rc = IDirectDraw7_CreateSurface(lpDD, &ddsd, &lpDDS, NULL);
88 ok(rc==DD_OK, "CreateSurface returned: %x\n", rc);
92 memset(&ddsd, 0, sizeof(ddsd));
93 ddsd.dwSize = sizeof(ddsd);
94 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
95 ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
96 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
97 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
98 U1(U4(ddsd).ddpfPixelFormat).dwZBufferBitDepth = 16;
99 U3(U4(ddsd).ddpfPixelFormat).dwZBitMask = 0x0000FFFF;
102 rc = IDirectDraw7_CreateSurface(lpDD, &ddsd, &lpDDSdepth, NULL);
103 ok(rc==DD_OK, "CreateSurface returned: %x\n", rc);
104 if (!SUCCEEDED(rc)) {
107 rc = IDirectDrawSurface_AddAttachedSurface(lpDDS, lpDDSdepth);
108 ok(rc == DD_OK, "IDirectDrawSurface_AddAttachedSurface returned %x\n", rc);
113 rc = IDirect3D7_CreateDevice(lpD3D, &IID_IDirect3DTnLHalDevice, lpDDS,
115 ok(rc==D3D_OK || rc==DDERR_NOPALETTEATTACHED || rc==E_OUTOFMEMORY, "CreateDevice returned: %x\n", rc);
117 trace("IDirect3D7::CreateDevice() for a TnL Hal device failed with an error %x, trying HAL\n", rc);
118 rc = IDirect3D7_CreateDevice(lpD3D, &IID_IDirect3DHALDevice, lpDDS,
121 trace("IDirect3D7::CreateDevice() for a HAL device failed with an error %x, trying RGB\n", rc);
122 rc = IDirect3D7_CreateDevice(lpD3D, &IID_IDirect3DRGBDevice, lpDDS,
125 trace("IDirect3D7::CreateDevice() for a RGB device failed with an error %x, giving up\n", rc);
134 static void ReleaseDirect3D(void)
136 if (lpD3DDevice != NULL)
138 IDirect3DDevice7_Release(lpD3DDevice);
142 if (lpDDSdepth != NULL)
144 IDirectDrawSurface_Release(lpDDSdepth);
150 IDirectDrawSurface_Release(lpDDS);
156 IDirect3D7_Release(lpD3D);
162 IDirectDraw_Release(lpDD);
167 static void LightTest(void)
171 D3DLIGHT7 defaultlight;
172 BOOL bEnabled = FALSE;
177 /* Set a few lights with funky indices. */
178 memset(&light, 0, sizeof(light));
179 light.dltType = D3DLIGHT_DIRECTIONAL;
180 U1(light.dcvDiffuse).r = 0.5f;
181 U2(light.dcvDiffuse).g = 0.6f;
182 U3(light.dcvDiffuse).b = 0.7f;
183 U2(light.dvDirection).y = 1.f;
185 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 5, &light);
186 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
187 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 10, &light);
188 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
189 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 45, &light);
190 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
193 /* Try to retrieve a light beyond the indices of the lights that have
195 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
196 ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %x\n", rc);
197 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 2, &light);
198 ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %x\n", rc);
201 /* Try to retrieve one of the lights that have been set */
202 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 10, &light);
203 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
206 /* Enable a light that have been previously set. */
207 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 10, TRUE);
208 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
211 /* Enable some lights that have not been previously set, and verify that
212 they have been initialized with proper default values. */
213 memset(&defaultlight, 0, sizeof(D3DLIGHT7));
214 defaultlight.dltType = D3DLIGHT_DIRECTIONAL;
215 U1(defaultlight.dcvDiffuse).r = 1.f;
216 U2(defaultlight.dcvDiffuse).g = 1.f;
217 U3(defaultlight.dcvDiffuse).b = 1.f;
218 U3(defaultlight.dvDirection).z = 1.f;
220 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, TRUE);
221 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
222 memset(&light, 0, sizeof(D3DLIGHT7));
223 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 20, &light);
224 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
225 ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
226 "light data doesn't match expected default values\n" );
228 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 50, TRUE);
229 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
230 memset(&light, 0, sizeof(D3DLIGHT7));
231 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
232 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
233 ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
234 "light data doesn't match expected default values\n" );
237 /* Disable one of the light that have been previously enabled. */
238 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, FALSE);
239 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
241 /* Try to retrieve the enable status of some lights */
242 /* Light 20 is supposed to be disabled */
243 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 20, &bEnabled );
244 ok(rc==D3D_OK, "GetLightEnable returned: %x\n", rc);
245 ok(!bEnabled, "GetLightEnable says the light is enabled\n");
247 /* Light 10 is supposed to be enabled */
249 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 10, &bEnabled );
250 ok(rc==D3D_OK, "GetLightEnable returned: %x\n", rc);
251 ok(bEnabled, "GetLightEnable says the light is disabled\n");
253 /* Light 80 has not been set */
254 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 80, &bEnabled );
255 ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %x\n", rc);
257 /* Light 23 has not been set */
258 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 23, &bEnabled );
259 ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %x\n", rc);
261 /* Set some lights with invalid parameters */
262 memset(&light, 0, sizeof(D3DLIGHT7));
264 U1(light.dcvDiffuse).r = 1.f;
265 U2(light.dcvDiffuse).g = 1.f;
266 U3(light.dcvDiffuse).b = 1.f;
267 U3(light.dvDirection).z = 1.f;
268 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 100, &light);
269 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
271 memset(&light, 0, sizeof(D3DLIGHT7));
272 light.dltType = 12345;
273 U1(light.dcvDiffuse).r = 1.f;
274 U2(light.dcvDiffuse).g = 1.f;
275 U3(light.dcvDiffuse).b = 1.f;
276 U3(light.dvDirection).z = 1.f;
277 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 101, &light);
278 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
280 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 102, NULL);
281 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
283 memset(&light, 0, sizeof(D3DLIGHT7));
284 light.dltType = D3DLIGHT_SPOT;
285 U1(light.dcvDiffuse).r = 1.f;
286 U2(light.dcvDiffuse).g = 1.f;
287 U3(light.dcvDiffuse).b = 1.f;
288 U3(light.dvDirection).z = 1.f;
290 light.dvAttenuation0 = -one / zero; /* -INFINITY */
291 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
292 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
294 light.dvAttenuation0 = -1.0;
295 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
296 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
298 light.dvAttenuation0 = 0.0;
299 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
300 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
302 light.dvAttenuation0 = 1.0;
303 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
304 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
306 light.dvAttenuation0 = one / zero; /* +INFINITY */
307 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
308 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
310 light.dvAttenuation0 = zero / zero; /* NaN */
311 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
312 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
314 /* Directional light ignores attenuation */
315 light.dltType = D3DLIGHT_DIRECTIONAL;
316 light.dvAttenuation0 = -1.0;
317 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
318 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
320 memset(&mat, 0, sizeof(mat));
321 rc = IDirect3DDevice7_SetMaterial(lpD3DDevice, &mat);
322 ok(rc == D3D_OK, "IDirect3DDevice7_SetMaterial returned: %x\n", rc);
325 rc = IDirect3DDevice7_SetMaterial(lpD3DDevice, &mat);
326 ok(rc == D3D_OK, "IDirect3DDevice7_SetMaterial(power = 129.0) returned: %x\n", rc);
327 memset(&mat, 0, sizeof(mat));
328 rc = IDirect3DDevice7_GetMaterial(lpD3DDevice, &mat);
329 ok(rc == D3D_OK, "IDirect3DDevice7_GetMaterial returned: %x\n", rc);
330 ok(mat.power == 129, "Returned power is %f\n", mat.power);
333 rc = IDirect3DDevice7_SetMaterial(lpD3DDevice, &mat);
334 ok(rc == D3D_OK, "IDirect3DDevice7_SetMaterial(power = -1.0) returned: %x\n", rc);
335 memset(&mat, 0, sizeof(mat));
336 rc = IDirect3DDevice7_GetMaterial(lpD3DDevice, &mat);
337 ok(rc == D3D_OK, "IDirect3DDevice7_GetMaterial returned: %x\n", rc);
338 ok(mat.power == -1, "Returned power is %f\n", mat.power);
341 static void ProcessVerticesTest(void)
343 D3DVERTEXBUFFERDESC desc;
349 D3DMATRIX view = { 2.0, 0.0, 0.0, 0.0,
352 0.0, 0.0, 0.0, 3.0 };
354 D3DMATRIX world = { 0.0, 1.0, 0.0, 0.0,
357 0.0, 1.0, 1.0, 1.0 };
359 D3DMATRIX proj = { 1.0, 0.0, 0.0, 1.0,
362 1.0, 0.0, 0.0, 1.0 };
363 /* Create some vertex buffers */
365 memset(&desc, 0, sizeof(desc));
366 desc.dwSize = sizeof(desc);
368 desc.dwFVF = D3DFVF_XYZ;
369 desc.dwNumVertices = 16;
370 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufSrc, 0);
371 ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
374 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
378 memset(&desc, 0, sizeof(desc));
379 desc.dwSize = sizeof(desc);
381 desc.dwFVF = D3DFVF_XYZRHW;
382 desc.dwNumVertices = 16;
383 /* Msdn says that the last parameter must be 0 - check that */
384 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufDest1, 4);
385 ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
388 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
392 memset(&desc, 0, sizeof(desc));
393 desc.dwSize = sizeof(desc);
395 desc.dwFVF = D3DFVF_XYZ;
396 desc.dwNumVertices = 16;
397 /* Msdn says that the last parameter must be 0 - check that */
398 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufDest2, 12345678);
399 ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
402 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
406 rc = IDirect3DVertexBuffer7_Lock(lpVBufSrc, 0, (void **) &in, NULL);
407 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
410 /* Check basic transformation */
427 rc = IDirect3DVertexBuffer7_Unlock(lpVBufSrc);
428 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
430 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
431 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
433 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest2, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
434 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
436 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
437 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
440 /* Check the results */
441 ok( comparefloat(out[0].x, 128.0 ) &&
442 comparefloat(out[0].y, 128.0 ) &&
443 comparefloat(out[0].z, 0.0 ) &&
444 comparefloat(out[0].rhw, 1.0 ),
445 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
447 ok( comparefloat(out[1].x, 256.0 ) &&
448 comparefloat(out[1].y, 0.0 ) &&
449 comparefloat(out[1].z, 1.0 ) &&
450 comparefloat(out[1].rhw, 1.0 ),
451 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
453 ok( comparefloat(out[2].x, 0.0 ) &&
454 comparefloat(out[2].y, 256.0 ) &&
455 comparefloat(out[2].z, 0.5 ) &&
456 comparefloat(out[2].rhw, 1.0 ),
457 "Output 2 vertex is (%f , %f , %f , %f)\n", out[2].x, out[2].y, out[2].z, out[2].rhw);
459 ok( comparefloat(out[3].x, 192.0 ) &&
460 comparefloat(out[3].y, 192.0 ) &&
461 comparefloat(out[3].z, 0.25 ) &&
462 comparefloat(out[3].rhw, 1.0 ),
463 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
465 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
466 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
469 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest2, 0, (void **) &out2, NULL);
470 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
472 /* Small thing without much practial meaning, but I stumbled upon it,
473 * so let's check for it: If the output vertex buffer has to RHW value,
474 * The RHW value of the last vertex is written into the next vertex
476 ok( comparefloat(out2[4].x, 1.0 ) &&
477 comparefloat(out2[4].y, 0.0 ) &&
478 comparefloat(out2[4].z, 0.0 ),
479 "Output 4 vertex is (%f , %f , %f)\n", out2[4].x, out2[4].y, out2[4].z);
481 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest2);
482 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
485 /* Try a more complicated viewport, same vertices */
486 memset(&vp, 0, sizeof(vp));
493 rc = IDirect3DDevice7_SetViewport(lpD3DDevice, &vp);
494 ok(rc==D3D_OK, "IDirect3DDevice7_SetViewport failed with rc=%x\n", rc);
497 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
498 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
500 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
501 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
504 /* Check the results */
505 ok( comparefloat(out[0].x, 133.0 ) &&
506 comparefloat(out[0].y, 70.0 ) &&
507 comparefloat(out[0].z, -2.0 ) &&
508 comparefloat(out[0].rhw, 1.0 ),
509 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
511 ok( comparefloat(out[1].x, 256.0 ) &&
512 comparefloat(out[1].y, 5.0 ) &&
513 comparefloat(out[1].z, 4.0 ) &&
514 comparefloat(out[1].rhw, 1.0 ),
515 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
517 ok( comparefloat(out[2].x, 10.0 ) &&
518 comparefloat(out[2].y, 135.0 ) &&
519 comparefloat(out[2].z, 1.0 ) &&
520 comparefloat(out[2].rhw, 1.0 ),
521 "Output 2 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
523 ok( comparefloat(out[3].x, 194.5 ) &&
524 comparefloat(out[3].y, 102.5 ) &&
525 comparefloat(out[3].z, -0.5 ) &&
526 comparefloat(out[3].rhw, 1.0 ),
527 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
529 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
530 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
533 /* Play with some matrices. */
535 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_VIEW, &view);
536 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
538 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_PROJECTION, &proj);
539 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
541 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_WORLD, &world);
542 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
544 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
545 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
547 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
548 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
551 /* Keep the viewport simpler, otherwise we get bad numbers to compare */
558 rc = IDirect3DDevice7_SetViewport(lpD3DDevice, &vp);
559 ok(rc==D3D_OK, "IDirect3DDevice7_SetViewport failed\n");
561 /* Check the results */
562 ok( comparefloat(out[0].x, 256.0 ) && /* X coordinate is cut at the surface edges */
563 comparefloat(out[0].y, 70.0 ) &&
564 comparefloat(out[0].z, -2.0 ) &&
565 comparefloat(out[0].rhw, (1.0 / 3.0)),
566 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
568 ok( comparefloat(out[1].x, 256.0 ) &&
569 comparefloat(out[1].y, 78.125000 ) &&
570 comparefloat(out[1].z, -2.750000 ) &&
571 comparefloat(out[1].rhw, 0.125000 ),
572 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
574 ok( comparefloat(out[2].x, 256.0 ) &&
575 comparefloat(out[2].y, 44.000000 ) &&
576 comparefloat(out[2].z, 0.400000 ) &&
577 comparefloat(out[2].rhw, 0.400000 ),
578 "Output 2 vertex is (%f , %f , %f , %f)\n", out[2].x, out[2].y, out[2].z, out[2].rhw);
580 ok( comparefloat(out[3].x, 256.0 ) &&
581 comparefloat(out[3].y, 81.818184 ) &&
582 comparefloat(out[3].z, -3.090909 ) &&
583 comparefloat(out[3].rhw, 0.363636 ),
584 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
586 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
587 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
591 IDirect3DVertexBuffer7_Release(lpVBufSrc);
592 IDirect3DVertexBuffer7_Release(lpVBufDest1);
593 IDirect3DVertexBuffer7_Release(lpVBufDest2);
596 static void StateTest( void )
600 /* The msdn says its undocumented, does it return an error too? */
601 rc = IDirect3DDevice7_SetRenderState(lpD3DDevice, D3DRENDERSTATE_ZVISIBLE, TRUE);
602 ok(rc == D3D_OK, "IDirect3DDevice7_SetRenderState(D3DRENDERSTATE_ZVISIBLE, TRUE) returned %08x\n", rc);
603 rc = IDirect3DDevice7_SetRenderState(lpD3DDevice, D3DRENDERSTATE_ZVISIBLE, FALSE);
604 ok(rc == D3D_OK, "IDirect3DDevice7_SetRenderState(D3DRENDERSTATE_ZVISIBLE, FALSE) returned %08x\n", rc);
608 static void SceneTest(void)
612 /* Test an EndScene without beginscene. Should return an error */
613 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
614 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
616 /* Test a normal BeginScene / EndScene pair, this should work */
617 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
618 ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed with %08x\n", hr);
622 memset(&fx, 0, sizeof(fx));
623 fx.dwSize = sizeof(fx);
626 hr = IDirectDrawSurface7_Blt(lpDDSdepth, NULL, NULL, NULL, DDBLT_DEPTHFILL, &fx);
627 ok(hr == D3D_OK, "Depthfill failed in a BeginScene / EndScene pair\n");
629 skip("Depth stencil creation failed at startup, skipping\n");
631 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
632 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed with %08x\n", hr);
635 /* Test another EndScene without having begun a new scene. Should return an error */
636 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
637 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
639 /* Two nested BeginScene and EndScene calls */
640 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
641 ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed with %08x\n", hr);
642 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
643 ok(hr == D3DERR_SCENE_IN_SCENE, "IDirect3DDevice7_BeginScene returned %08x\n", hr);
644 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
645 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed with %08x\n", hr);
646 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
647 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
649 /* TODO: Verify that blitting works in the same way as in d3d9 */
652 static void LimitTest(void)
654 IDirectDrawSurface7 *pTexture = NULL;
659 memset(&ddsd, 0, sizeof(ddsd));
660 ddsd.dwSize = sizeof(ddsd);
661 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
662 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
665 hr = IDirectDraw7_CreateSurface(lpDD, &ddsd, &pTexture, NULL);
666 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
667 if(!pTexture) return;
669 for(i = 0; i < 8; i++) {
670 hr = IDirect3DDevice7_SetTexture(lpD3DDevice, i, pTexture);
671 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %08x\n", i, hr);
672 hr = IDirect3DDevice7_SetTexture(lpD3DDevice, i, NULL);
673 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %08x\n", i, hr);
674 hr = IDirect3DDevice7_SetTextureStageState(lpD3DDevice, i, D3DTSS_COLOROP, D3DTOP_ADD);
675 ok(hr == D3D_OK, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %08x\n", i, hr);
678 IDirectDrawSurface7_Release(pTexture);
681 static HRESULT WINAPI enumDevicesCallback(GUID *Guid,LPSTR DeviceDescription,LPSTR DeviceName, D3DDEVICEDESC *hal, D3DDEVICEDESC *hel, VOID *ctx)
683 UINT ver = *((UINT *) ctx);
684 if(IsEqualGUID(&IID_IDirect3DRGBDevice, Guid))
686 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
687 "RGB Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
688 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
689 "RGB Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
690 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
691 "RGB Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
692 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
693 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
695 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
696 "RGB Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
697 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
698 "RGB Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
699 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
700 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
701 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
702 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
704 else if(IsEqualGUID(&IID_IDirect3DHALDevice, Guid))
706 /* pow2 is hardware dependent */
708 ok(hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
709 "HAL Device %d hal line caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
710 ok(hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
711 "HAL Device %d hal tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
712 ok((hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
713 "HAL Device %d hel line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
714 ok((hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
715 "HAL Device %d hel tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
717 else if(IsEqualGUID(&IID_IDirect3DRefDevice, Guid))
719 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
720 "REF Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
721 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
722 "REF Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
723 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
724 "REF Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
725 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
726 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
728 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
729 "REF Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
730 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
731 "REF Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
732 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
733 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
734 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
735 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
737 else if(IsEqualGUID(&IID_IDirect3DRampDevice, Guid))
739 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
740 "Ramp Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
741 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
742 "Ramp Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
743 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
744 "Ramp Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
745 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
746 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
748 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
749 "Ramp Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
750 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
751 "Ramp Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
752 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
753 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
754 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
755 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
757 else if(IsEqualGUID(&IID_IDirect3DMMXDevice, Guid))
759 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
760 "MMX Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
761 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
762 "MMX Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
763 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
764 "MMX Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
765 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
766 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
768 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
769 "MMX Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
770 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
771 "MMX Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
772 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
773 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
774 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
775 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
779 ok(FALSE, "Unexpected device enumerated: \"%s\" \"%s\"\n", DeviceDescription, DeviceName);
780 if(hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hal line has pow2 set\n");
781 else trace("hal line does NOT have pow2 set\n");
782 if(hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hal tri has pow2 set\n");
783 else trace("hal tri does NOT have pow2 set\n");
784 if(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hel line has pow2 set\n");
785 else trace("hel line does NOT have pow2 set\n");
786 if(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hel tri has pow2 set\n");
787 else trace("hel tri does NOT have pow2 set\n");
792 static void CapsTest(void)
800 hr = DirectDrawCreate(NULL, &dd1, NULL);
801 ok(hr == DD_OK, "Cannot create a DirectDraw 1 interface, hr = %08x\n", hr);
802 hr = IDirectDraw_QueryInterface(dd1, &IID_IDirect3D3, (void **) &d3d3);
803 ok(hr == D3D_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
805 IDirect3D3_EnumDevices(d3d3, enumDevicesCallback, &ver);
807 IDirect3D3_Release(d3d3);
808 IDirectDraw_Release(dd1);
810 hr = DirectDrawCreate(NULL, &dd1, NULL);
811 ok(hr == DD_OK, "Cannot create a DirectDraw 1 interface, hr = %08x\n", hr);
812 hr = IDirectDraw_QueryInterface(dd1, &IID_IDirect3D2, (void **) &d3d2);
813 ok(hr == D3D_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
815 IDirect3D2_EnumDevices(d3d2, enumDevicesCallback, &ver);
817 IDirect3D2_Release(d3d2);
818 IDirectDraw_Release(dd1);
823 init_function_pointers();
824 if(!pDirectDrawCreateEx) {
825 trace("function DirectDrawCreateEx not available, skipping tests\n");
829 if(!CreateDirect3D()) {
830 trace("Skipping tests\n");
834 ProcessVerticesTest();