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() failed with an error %x\n", rc);
100 static void ReleaseDirect3D(void)
102 if (lpD3DDevice != NULL)
104 IDirect3DDevice7_Release(lpD3DDevice);
110 IDirectDrawSurface_Release(lpDDS);
116 IDirect3D7_Release(lpD3D);
122 IDirectDraw_Release(lpDD);
127 static void LightTest(void)
131 D3DLIGHT7 defaultlight;
132 BOOL bEnabled = FALSE;
134 /* Set a few lights with funky indices. */
135 memset(&light, 0, sizeof(light));
136 light.dltType = D3DLIGHT_DIRECTIONAL;
137 U1(light.dcvDiffuse).r = 0.5f;
138 U2(light.dcvDiffuse).g = 0.6f;
139 U3(light.dcvDiffuse).b = 0.7f;
140 U2(light.dvDirection).y = 1.f;
142 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 5, &light);
143 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
144 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 10, &light);
145 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
146 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 45, &light);
147 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
150 /* Try to retrieve a light beyond the indices of the lights that have
152 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
153 ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %x\n", rc);
154 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 2, &light);
155 ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %x\n", rc);
158 /* Try to retrieve one of the lights that have been set */
159 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 10, &light);
160 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
163 /* Enable a light that have been previously set. */
164 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 10, TRUE);
165 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
168 /* Enable some lights that have not been previously set, and verify that
169 they have been initialized with proper default values. */
170 memset(&defaultlight, 0, sizeof(D3DLIGHT7));
171 defaultlight.dltType = D3DLIGHT_DIRECTIONAL;
172 U1(defaultlight.dcvDiffuse).r = 1.f;
173 U2(defaultlight.dcvDiffuse).g = 1.f;
174 U3(defaultlight.dcvDiffuse).b = 1.f;
175 U3(defaultlight.dvDirection).z = 1.f;
177 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, TRUE);
178 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
179 memset(&light, 0, sizeof(D3DLIGHT7));
180 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 20, &light);
181 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
182 ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
183 "light data doesn't match expected default values\n" );
185 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 50, TRUE);
186 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
187 memset(&light, 0, sizeof(D3DLIGHT7));
188 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
189 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
190 ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
191 "light data doesn't match expected default values\n" );
194 /* Disable one of the light that have been previously enabled. */
195 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, FALSE);
196 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
198 /* Try to retrieve the enable status of some lights */
199 /* Light 20 is supposed to be disabled */
200 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 20, &bEnabled );
201 ok(rc==D3D_OK, "GetLightEnable returned: %x\n", rc);
202 ok(!bEnabled, "GetLightEnable says the light is enabled\n");
204 /* Light 10 is supposed to be enabled */
206 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 10, &bEnabled );
207 ok(rc==D3D_OK, "GetLightEnable returned: %x\n", rc);
208 ok(bEnabled, "GetLightEnable says the light is disabled\n");
210 /* Light 80 has not been set */
211 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 80, &bEnabled );
212 ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %x\n", rc);
214 /* Light 23 has not been set */
215 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 23, &bEnabled );
216 ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %x\n", rc);
218 /* Set some lights with invalid parameters */
219 memset(&light, 0, sizeof(D3DLIGHT7));
221 U1(light.dcvDiffuse).r = 1.f;
222 U2(light.dcvDiffuse).g = 1.f;
223 U3(light.dcvDiffuse).b = 1.f;
224 U3(light.dvDirection).z = 1.f;
225 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 100, &light);
226 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
228 memset(&light, 0, sizeof(D3DLIGHT7));
229 light.dltType = 12345;
230 U1(light.dcvDiffuse).r = 1.f;
231 U2(light.dcvDiffuse).g = 1.f;
232 U3(light.dcvDiffuse).b = 1.f;
233 U3(light.dvDirection).z = 1.f;
234 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 101, &light);
235 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
237 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 102, NULL);
238 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
240 memset(&light, 0, sizeof(D3DLIGHT7));
241 light.dltType = D3DLIGHT_SPOT;
242 U1(light.dcvDiffuse).r = 1.f;
243 U2(light.dcvDiffuse).g = 1.f;
244 U3(light.dcvDiffuse).b = 1.f;
245 U3(light.dvDirection).z = 1.f;
247 light.dvAttenuation0 = -1.0 / 0.0; /* -INFINITY */
248 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
249 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
251 light.dvAttenuation0 = -1.0;
252 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
253 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
255 light.dvAttenuation0 = 0.0;
256 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
257 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
259 light.dvAttenuation0 = 1.0;
260 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
261 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
263 light.dvAttenuation0 = 1.0 / 0.0; /* +INFINITY */
264 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
265 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
267 light.dvAttenuation0 = 0.0 / 0.0; /* NaN */
268 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
269 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
271 /* Directional light ignores attenuation */
272 light.dltType = D3DLIGHT_DIRECTIONAL;
273 light.dvAttenuation0 = -1.0;
274 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
275 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
278 static void ProcessVerticesTest(void)
280 D3DVERTEXBUFFERDESC desc;
286 D3DMATRIX view = { 2.0, 0.0, 0.0, 0.0,
289 0.0, 0.0, 0.0, 3.0 };
291 D3DMATRIX world = { 0.0, 1.0, 0.0, 0.0,
294 0.0, 1.0, 1.0, 1.0 };
296 D3DMATRIX proj = { 1.0, 0.0, 0.0, 1.0,
299 1.0, 0.0, 0.0, 1.0 };
300 /* Create some vertex buffers */
302 memset(&desc, 0, sizeof(desc));
303 desc.dwSize = sizeof(desc);
305 desc.dwFVF = D3DFVF_XYZ;
306 desc.dwNumVertices = 16;
307 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufSrc, 0);
308 ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
311 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
315 memset(&desc, 0, sizeof(desc));
316 desc.dwSize = sizeof(desc);
318 desc.dwFVF = D3DFVF_XYZRHW;
319 desc.dwNumVertices = 16;
320 /* Msdn says that the last parameter must be 0 - check that */
321 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufDest1, 4);
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_XYZ;
333 desc.dwNumVertices = 16;
334 /* Msdn says that the last parameter must be 0 - check that */
335 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufDest2, 12345678);
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 rc = IDirect3DVertexBuffer7_Lock(lpVBufSrc, 0, (void **) &in, NULL);
344 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
347 /* Check basic transformation */
364 rc = IDirect3DVertexBuffer7_Unlock(lpVBufSrc);
365 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
367 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
368 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
370 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest2, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
371 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
373 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
374 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
377 /* Check the results */
378 ok( comparefloat(out[0].x, 128.0 ) &&
379 comparefloat(out[0].y, 128.0 ) &&
380 comparefloat(out[0].z, 0.0 ) &&
381 comparefloat(out[0].rhw, 1.0 ),
382 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
384 ok( comparefloat(out[1].x, 256.0 ) &&
385 comparefloat(out[1].y, 0.0 ) &&
386 comparefloat(out[1].z, 1.0 ) &&
387 comparefloat(out[1].rhw, 1.0 ),
388 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
390 ok( comparefloat(out[2].x, 0.0 ) &&
391 comparefloat(out[2].y, 256.0 ) &&
392 comparefloat(out[2].z, 0.5 ) &&
393 comparefloat(out[2].rhw, 1.0 ),
394 "Output 2 vertex is (%f , %f , %f , %f)\n", out[2].x, out[2].y, out[2].z, out[2].rhw);
396 ok( comparefloat(out[3].x, 192.0 ) &&
397 comparefloat(out[3].y, 192.0 ) &&
398 comparefloat(out[3].z, 0.25 ) &&
399 comparefloat(out[3].rhw, 1.0 ),
400 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
402 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
403 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
406 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest2, 0, (void **) &out2, NULL);
407 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
409 /* Small thing without much practial meaning, but I stumbled upon it,
410 * so let's check for it: If the output vertex buffer has to RHW value,
411 * The RHW value of the last vertex is written into the next vertex
413 ok( comparefloat(out2[4].x, 1.0 ) &&
414 comparefloat(out2[4].y, 0.0 ) &&
415 comparefloat(out2[4].z, 0.0 ),
416 "Output 4 vertex is (%f , %f , %f)\n", out2[4].x, out2[4].y, out2[4].z);
418 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest2);
419 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
422 /* Try a more complicated viewport, same vertices */
423 memset(&vp, 0, sizeof(vp));
430 rc = IDirect3DDevice7_SetViewport(lpD3DDevice, &vp);
431 ok(rc==D3D_OK, "IDirect3DDevice7_SetViewport failed with rc=%x\n", rc);
434 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
435 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
437 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
438 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
441 /* Check the results */
442 ok( comparefloat(out[0].x, 133.0 ) &&
443 comparefloat(out[0].y, 70.0 ) &&
444 comparefloat(out[0].z, -2.0 ) &&
445 comparefloat(out[0].rhw, 1.0 ),
446 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
448 ok( comparefloat(out[1].x, 256.0 ) &&
449 comparefloat(out[1].y, 5.0 ) &&
450 comparefloat(out[1].z, 4.0 ) &&
451 comparefloat(out[1].rhw, 1.0 ),
452 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
454 ok( comparefloat(out[2].x, 10.0 ) &&
455 comparefloat(out[2].y, 135.0 ) &&
456 comparefloat(out[2].z, 1.0 ) &&
457 comparefloat(out[2].rhw, 1.0 ),
458 "Output 2 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
460 ok( comparefloat(out[3].x, 194.5 ) &&
461 comparefloat(out[3].y, 102.5 ) &&
462 comparefloat(out[3].z, -0.5 ) &&
463 comparefloat(out[3].rhw, 1.0 ),
464 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
466 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
467 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
470 /* Play with some matrices. */
472 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_VIEW, &view);
473 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
475 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_PROJECTION, &proj);
476 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
478 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_WORLD, &world);
479 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
481 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
482 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
484 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
485 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
488 /* Keep the viewport simpler, otherwise we get bad numbers to compare */
495 rc = IDirect3DDevice7_SetViewport(lpD3DDevice, &vp);
496 ok(rc==D3D_OK, "IDirect3DDevice7_SetViewport failed\n");
498 /* Check the results */
499 ok( comparefloat(out[0].x, 256.0 ) && /* X coordinate is cut at the surface edges */
500 comparefloat(out[0].y, 70.0 ) &&
501 comparefloat(out[0].z, -2.0 ) &&
502 comparefloat(out[0].rhw, (1.0 / 3.0)),
503 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
505 ok( comparefloat(out[1].x, 256.0 ) &&
506 comparefloat(out[1].y, 78.125000 ) &&
507 comparefloat(out[1].z, -2.750000 ) &&
508 comparefloat(out[1].rhw, 0.125000 ),
509 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
511 ok( comparefloat(out[2].x, 256.0 ) &&
512 comparefloat(out[2].y, 44.000000 ) &&
513 comparefloat(out[2].z, 0.400000 ) &&
514 comparefloat(out[2].rhw, 0.400000 ),
515 "Output 2 vertex is (%f , %f , %f , %f)\n", out[2].x, out[2].y, out[2].z, out[2].rhw);
517 ok( comparefloat(out[3].x, 256.0 ) &&
518 comparefloat(out[3].y, 81.818184 ) &&
519 comparefloat(out[3].z, -3.090909 ) &&
520 comparefloat(out[3].rhw, 0.363636 ),
521 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
523 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
524 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
528 IDirect3DVertexBuffer7_Release(lpVBufSrc);
529 IDirect3DVertexBuffer7_Release(lpVBufDest1);
530 IDirect3DVertexBuffer7_Release(lpVBufDest2);
533 static void StateTest( void )
537 /* The msdn says its undocumented, does it return an error too? */
538 rc = IDirect3DDevice7_SetRenderState(lpD3DDevice, D3DRENDERSTATE_ZVISIBLE, TRUE);
539 ok(rc == D3D_OK, "IDirect3DDevice7_SetRenderState(D3DRENDERSTATE_ZVISIBLE, TRUE) returned %08x\n", rc);
540 rc = IDirect3DDevice7_SetRenderState(lpD3DDevice, D3DRENDERSTATE_ZVISIBLE, FALSE);
541 ok(rc == D3D_OK, "IDirect3DDevice7_SetRenderState(D3DRENDERSTATE_ZVISIBLE, FALSE) returned %08x\n", rc);
545 static void SceneTest(void)
549 /* Test an EndScene without beginscene. Should return an error */
550 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
551 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
553 /* Test a normal BeginScene / EndScene pair, this should work */
554 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
555 ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed with %08x\n", hr);
558 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
559 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed with %08x\n", hr);
562 /* Test another EndScene without having begun a new scene. Should return an error */
563 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
564 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
566 /* Two nested BeginScene and EndScene calls */
567 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
568 ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed with %08x\n", hr);
569 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
570 ok(hr == D3DERR_SCENE_IN_SCENE, "IDirect3DDevice7_BeginScene returned %08x\n", hr);
571 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
572 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed with %08x\n", hr);
573 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
574 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
576 /* TODO: Verify that blitting works in the same way as in d3d9 */
579 static void LimitTest(void)
581 IDirectDrawSurface7 *pTexture = NULL;
586 memset(&ddsd, 0, sizeof(ddsd));
587 ddsd.dwSize = sizeof(ddsd);
588 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
589 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
592 hr = IDirectDraw7_CreateSurface(lpDD, &ddsd, &pTexture, NULL);
593 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
594 if(!pTexture) return;
596 for(i = 0; i < 8; i++) {
597 hr = IDirect3DDevice7_SetTexture(lpD3DDevice, i, pTexture);
598 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %08x\n", i, hr);
599 hr = IDirect3DDevice7_SetTexture(lpD3DDevice, i, NULL);
600 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %08x\n", i, hr);
601 hr = IDirect3DDevice7_SetTextureStageState(lpD3DDevice, i, D3DTSS_COLOROP, D3DTOP_ADD);
602 ok(hr == D3D_OK, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %08x\n", i, hr);
605 IDirectDrawSurface7_Release(pTexture);
610 init_function_pointers();
611 if(!pDirectDrawCreateEx) {
612 trace("function DirectDrawCreateEx not available, skipping tests\n");
616 if(!CreateDirect3D()) {
617 trace("Skipping tests\n");
621 ProcessVerticesTest();