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");
59 pDirectDrawCreateEx = (void*)GetProcAddress(hmod, "DirectDrawCreateEx");
64 static BOOL CreateDirect3D(void)
69 rc = pDirectDrawCreateEx(NULL, (void**)&lpDD,
70 &IID_IDirectDraw7, NULL);
71 ok(rc==DD_OK || rc==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", rc);
73 trace("DirectDrawCreateEx() failed with an error %x\n", rc);
77 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
78 ok(rc==DD_OK, "SetCooperativeLevel returned: %x\n", rc);
80 rc = IDirectDraw7_QueryInterface(lpDD, &IID_IDirect3D7, (void**) &lpD3D);
81 if (rc == E_NOINTERFACE) return FALSE;
82 ok(rc==DD_OK, "QueryInterface returned: %x\n", rc);
84 memset(&ddsd, 0, sizeof(ddsd));
85 ddsd.dwSize = sizeof(ddsd);
86 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
87 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
90 rc = IDirectDraw7_CreateSurface(lpDD, &ddsd, &lpDDS, NULL);
91 ok(rc==DD_OK, "CreateSurface returned: %x\n", rc);
93 rc = IDirect3D7_CreateDevice(lpD3D, &IID_IDirect3DTnLHalDevice, lpDDS,
95 ok(rc==D3D_OK || rc==DDERR_NOPALETTEATTACHED || rc==E_OUTOFMEMORY, "CreateDevice returned: %x\n", rc);
97 trace("IDirect3D7::CreateDevice() failed with an error %x\n", rc);
104 static void ReleaseDirect3D(void)
106 if (lpD3DDevice != NULL)
108 IDirect3DDevice7_Release(lpD3DDevice);
114 IDirectDrawSurface_Release(lpDDS);
120 IDirect3D7_Release(lpD3D);
126 IDirectDraw_Release(lpDD);
131 static void LightTest(void)
135 D3DLIGHT7 defaultlight;
136 BOOL bEnabled = FALSE;
138 /* Set a few lights with funky indices. */
139 memset(&light, 0, sizeof(light));
140 light.dltType = D3DLIGHT_DIRECTIONAL;
141 U1(light.dcvDiffuse).r = 0.5f;
142 U2(light.dcvDiffuse).g = 0.6f;
143 U3(light.dcvDiffuse).b = 0.7f;
144 U2(light.dvDirection).y = 1.f;
146 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 5, &light);
147 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
148 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 10, &light);
149 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
150 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 45, &light);
151 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
154 /* Try to retrieve a light beyond the indices of the lights that have
156 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
157 ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %x\n", rc);
158 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 2, &light);
159 ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %x\n", rc);
162 /* Try to retrieve one of the lights that have been set */
163 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 10, &light);
164 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
167 /* Enable a light that have been previously set. */
168 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 10, TRUE);
169 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
172 /* Enable some lights that have not been previously set, and verify that
173 they have been initialized with proper default values. */
174 memset(&defaultlight, 0, sizeof(D3DLIGHT7));
175 defaultlight.dltType = D3DLIGHT_DIRECTIONAL;
176 U1(defaultlight.dcvDiffuse).r = 1.f;
177 U2(defaultlight.dcvDiffuse).g = 1.f;
178 U3(defaultlight.dcvDiffuse).b = 1.f;
179 U3(defaultlight.dvDirection).z = 1.f;
181 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, TRUE);
182 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
183 memset(&light, 0, sizeof(D3DLIGHT7));
184 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 20, &light);
185 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
186 ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
187 "light data doesn't match expected default values\n" );
189 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 50, TRUE);
190 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
191 memset(&light, 0, sizeof(D3DLIGHT7));
192 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
193 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
194 ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
195 "light data doesn't match expected default values\n" );
198 /* Disable one of the light that have been previously enabled. */
199 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, FALSE);
200 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
202 /* Try to retrieve the enable status of some lights */
203 /* Light 20 is supposed to be disabled */
204 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 20, &bEnabled );
205 ok(rc==D3D_OK, "GetLightEnable returned: %x\n", rc);
206 ok(!bEnabled, "GetLightEnable says the light is enabled\n");
208 /* Light 10 is supposed to be enabled */
210 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 10, &bEnabled );
211 ok(rc==D3D_OK, "GetLightEnable returned: %x\n", rc);
212 ok(bEnabled, "GetLightEnable says the light is disabled\n");
214 /* Light 80 has not been set */
215 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 80, &bEnabled );
216 ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %x\n", rc);
218 /* Light 23 has not been set */
219 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 23, &bEnabled );
220 ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %x\n", rc);
222 /* Set some lights with invalid parameters */
223 memset(&light, 0, sizeof(D3DLIGHT7));
225 U1(light.dcvDiffuse).r = 1.f;
226 U2(light.dcvDiffuse).g = 1.f;
227 U3(light.dcvDiffuse).b = 1.f;
228 U3(light.dvDirection).z = 1.f;
229 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 100, &light);
230 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
232 memset(&light, 0, sizeof(D3DLIGHT7));
233 light.dltType = 12345;
234 U1(light.dcvDiffuse).r = 1.f;
235 U2(light.dcvDiffuse).g = 1.f;
236 U3(light.dcvDiffuse).b = 1.f;
237 U3(light.dvDirection).z = 1.f;
238 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 101, &light);
239 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
241 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 102, NULL);
242 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
244 memset(&light, 0, sizeof(D3DLIGHT7));
245 light.dltType = D3DLIGHT_SPOT;
246 U1(light.dcvDiffuse).r = 1.f;
247 U2(light.dcvDiffuse).g = 1.f;
248 U3(light.dcvDiffuse).b = 1.f;
249 U3(light.dvDirection).z = 1.f;
251 light.dvAttenuation0 = -1.0 / 0.0; /* -INFINITY */
252 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
253 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
255 light.dvAttenuation0 = -1.0;
256 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
257 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
259 light.dvAttenuation0 = 0.0;
260 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
261 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
263 light.dvAttenuation0 = 1.0;
264 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
265 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
267 light.dvAttenuation0 = 1.0 / 0.0; /* +INFINITY */
268 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
269 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
271 light.dvAttenuation0 = 0.0 / 0.0; /* NaN */
272 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
273 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
275 /* Directional light ignores attenuation */
276 light.dltType = D3DLIGHT_DIRECTIONAL;
277 light.dvAttenuation0 = -1.0;
278 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
279 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
282 static void ProcessVerticesTest(void)
284 D3DVERTEXBUFFERDESC desc;
290 D3DMATRIX view = { 2.0, 0.0, 0.0, 0.0,
293 0.0, 0.0, 0.0, 3.0 };
295 D3DMATRIX world = { 0.0, 1.0, 0.0, 0.0,
298 0.0, 1.0, 1.0, 1.0 };
300 D3DMATRIX proj = { 1.0, 0.0, 0.0, 1.0,
303 1.0, 0.0, 0.0, 1.0 };
304 /* Create some vertex buffers */
306 memset(&desc, 0, sizeof(desc));
307 desc.dwSize = sizeof(desc);
309 desc.dwFVF = D3DFVF_XYZ;
310 desc.dwNumVertices = 16;
311 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufSrc, 0);
312 ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
315 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
319 memset(&desc, 0, sizeof(desc));
320 desc.dwSize = sizeof(desc);
322 desc.dwFVF = D3DFVF_XYZRHW;
323 desc.dwNumVertices = 16;
324 /* Msdn says that the last parameter must be 0 - check that */
325 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufDest1, 4);
326 ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
329 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
333 memset(&desc, 0, sizeof(desc));
334 desc.dwSize = sizeof(desc);
336 desc.dwFVF = D3DFVF_XYZ;
337 desc.dwNumVertices = 16;
338 /* Msdn says that the last parameter must be 0 - check that */
339 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufDest2, 12345678);
340 ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
343 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
347 rc = IDirect3DVertexBuffer7_Lock(lpVBufSrc, 0, (void **) &in, NULL);
348 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
351 /* Check basic transformation */
368 rc = IDirect3DVertexBuffer7_Unlock(lpVBufSrc);
369 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
371 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
372 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
374 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest2, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
375 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
377 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
378 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
381 /* Check the results */
382 ok( comparefloat(out[0].x, 128.0 ) &&
383 comparefloat(out[0].y, 128.0 ) &&
384 comparefloat(out[0].z, 0.0 ) &&
385 comparefloat(out[0].rhw, 1.0 ),
386 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
388 ok( comparefloat(out[1].x, 256.0 ) &&
389 comparefloat(out[1].y, 0.0 ) &&
390 comparefloat(out[1].z, 1.0 ) &&
391 comparefloat(out[1].rhw, 1.0 ),
392 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
394 ok( comparefloat(out[2].x, 0.0 ) &&
395 comparefloat(out[2].y, 256.0 ) &&
396 comparefloat(out[2].z, 0.5 ) &&
397 comparefloat(out[2].rhw, 1.0 ),
398 "Output 2 vertex is (%f , %f , %f , %f)\n", out[2].x, out[2].y, out[2].z, out[2].rhw);
400 ok( comparefloat(out[3].x, 192.0 ) &&
401 comparefloat(out[3].y, 192.0 ) &&
402 comparefloat(out[3].z, 0.25 ) &&
403 comparefloat(out[3].rhw, 1.0 ),
404 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
406 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
407 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
410 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest2, 0, (void **) &out2, NULL);
411 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
413 /* Small thing without much practial meaning, but I stumbled upon it,
414 * so let's check for it: If the output vertex buffer has to RHW value,
415 * The RHW value of the last vertex is written into the next vertex
417 ok( comparefloat(out2[4].x, 1.0 ) &&
418 comparefloat(out2[4].y, 0.0 ) &&
419 comparefloat(out2[4].z, 0.0 ),
420 "Output 4 vertex is (%f , %f , %f)\n", out2[4].x, out2[4].y, out2[4].z);
422 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest2);
423 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
426 /* Try a more complicated viewport, same vertices */
427 memset(&vp, 0, sizeof(vp));
434 rc = IDirect3DDevice7_SetViewport(lpD3DDevice, &vp);
435 ok(rc==D3D_OK, "IDirect3DDevice7_SetViewport failed with rc=%x\n", rc);
438 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
439 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
441 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
442 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
445 /* Check the results */
446 ok( comparefloat(out[0].x, 133.0 ) &&
447 comparefloat(out[0].y, 70.0 ) &&
448 comparefloat(out[0].z, -2.0 ) &&
449 comparefloat(out[0].rhw, 1.0 ),
450 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
452 ok( comparefloat(out[1].x, 256.0 ) &&
453 comparefloat(out[1].y, 5.0 ) &&
454 comparefloat(out[1].z, 4.0 ) &&
455 comparefloat(out[1].rhw, 1.0 ),
456 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
458 ok( comparefloat(out[2].x, 10.0 ) &&
459 comparefloat(out[2].y, 135.0 ) &&
460 comparefloat(out[2].z, 1.0 ) &&
461 comparefloat(out[2].rhw, 1.0 ),
462 "Output 2 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
464 ok( comparefloat(out[3].x, 194.5 ) &&
465 comparefloat(out[3].y, 102.5 ) &&
466 comparefloat(out[3].z, -0.5 ) &&
467 comparefloat(out[3].rhw, 1.0 ),
468 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
470 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
471 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
474 /* Play with some matrices. */
476 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_VIEW, &view);
477 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
479 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_PROJECTION, &proj);
480 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
482 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_WORLD, &world);
483 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
485 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
486 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
488 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
489 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
492 /* Keep the viewport simpler, otherwise we get bad numbers to compare */
499 rc = IDirect3DDevice7_SetViewport(lpD3DDevice, &vp);
500 ok(rc==D3D_OK, "IDirect3DDevice7_SetViewport failed\n");
502 /* Check the results */
503 ok( comparefloat(out[0].x, 256.0 ) && /* X coordinate is cut at the surface edges */
504 comparefloat(out[0].y, 70.0 ) &&
505 comparefloat(out[0].z, -2.0 ) &&
506 comparefloat(out[0].rhw, (1.0 / 3.0)),
507 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
509 ok( comparefloat(out[1].x, 256.0 ) &&
510 comparefloat(out[1].y, 78.125000 ) &&
511 comparefloat(out[1].z, -2.750000 ) &&
512 comparefloat(out[1].rhw, 0.125000 ),
513 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
515 ok( comparefloat(out[2].x, 256.0 ) &&
516 comparefloat(out[2].y, 44.000000 ) &&
517 comparefloat(out[2].z, 0.400000 ) &&
518 comparefloat(out[2].rhw, 0.400000 ),
519 "Output 2 vertex is (%f , %f , %f , %f)\n", out[2].x, out[2].y, out[2].z, out[2].rhw);
521 ok( comparefloat(out[3].x, 256.0 ) &&
522 comparefloat(out[3].y, 81.818184 ) &&
523 comparefloat(out[3].z, -3.090909 ) &&
524 comparefloat(out[3].rhw, 0.363636 ),
525 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
527 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
528 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
532 IDirect3DVertexBuffer7_Release(lpVBufSrc);
533 IDirect3DVertexBuffer7_Release(lpVBufDest1);
534 IDirect3DVertexBuffer7_Release(lpVBufDest2);
537 static void StateTest( void )
541 /* The msdn says its undocumented, does it return an error too? */
542 rc = IDirect3DDevice7_SetRenderState(lpD3DDevice, D3DRENDERSTATE_ZVISIBLE, TRUE);
543 ok(rc == D3D_OK, "IDirect3DDevice7_SetRenderState(D3DRENDERSTATE_ZVISIBLE, TRUE) returned %08x\n", rc);
544 rc = IDirect3DDevice7_SetRenderState(lpD3DDevice, D3DRENDERSTATE_ZVISIBLE, FALSE);
545 ok(rc == D3D_OK, "IDirect3DDevice7_SetRenderState(D3DRENDERSTATE_ZVISIBLE, FALSE) returned %08x\n", rc);
549 static void SceneTest(void)
553 /* Test an EndScene without beginscene. Should return an error */
554 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
555 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
557 /* Test a normal BeginScene / EndScene pair, this should work */
558 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
559 ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed with %08x\n", hr);
562 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
563 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed with %08x\n", hr);
566 /* Test another EndScene without having begun a new scene. Should return an error */
567 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
568 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
570 /* Two nested BeginScene and EndScene calls */
571 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
572 ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed with %08x\n", hr);
573 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
574 ok(hr == D3DERR_SCENE_IN_SCENE, "IDirect3DDevice7_BeginScene returned %08x\n", hr);
575 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
576 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed with %08x\n", hr);
577 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
578 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
580 /* TODO: Verify that blitting works in the same way as in d3d9 */
583 static void LimitTest(void)
585 IDirectDrawSurface7 *pTexture = NULL;
590 memset(&ddsd, 0, sizeof(ddsd));
591 ddsd.dwSize = sizeof(ddsd);
592 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
593 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
596 hr = IDirectDraw7_CreateSurface(lpDD, &ddsd, &pTexture, NULL);
597 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
598 if(!pTexture) return;
600 for(i = 0; i < 8; i++) {
601 hr = IDirect3DDevice7_SetTexture(lpD3DDevice, i, pTexture);
602 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %08x\n", i, hr);
603 hr = IDirect3DDevice7_SetTexture(lpD3DDevice, i, NULL);
604 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %08x\n", i, hr);
605 hr = IDirect3DDevice7_SetTextureStageState(lpD3DDevice, i, D3DTSS_COLOROP, D3DTOP_ADD);
606 ok(hr == D3D_OK, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %08x\n", i, hr);
609 IDirectDrawSurface7_Release(pTexture);
614 init_function_pointers();
615 if(!pDirectDrawCreateEx) {
616 trace("function DirectDrawCreateEx not available, skipping tests\n");
620 if(!CreateDirect3D()) {
621 trace("Skipping tests\n");
625 ProcessVerticesTest();