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;
44 /* To compare bad floating point numbers. Not the ideal way to do it,
45 * but it should be enough for here */
46 #define comparefloat(a, b) ( (((a) - (b)) < 0.0001) && (((a) - (b)) > -0.0001) )
48 static HRESULT (WINAPI *pDirectDrawCreateEx)(LPGUID,LPVOID*,REFIID,LPUNKNOWN);
50 typedef struct _VERTEX
52 float x, y, z; /* position */
55 typedef struct _TVERTEX
57 float x, y, z; /* position */
59 } TVERTEX, *LPTVERTEX;
62 static void init_function_pointers(void)
64 HMODULE hmod = GetModuleHandleA("ddraw.dll");
65 pDirectDrawCreateEx = (void*)GetProcAddress(hmod, "DirectDrawCreateEx");
69 static BOOL CreateDirect3D(void)
74 rc = pDirectDrawCreateEx(NULL, (void**)&lpDD,
75 &IID_IDirectDraw7, NULL);
76 ok(rc==DD_OK || rc==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", rc);
78 trace("DirectDrawCreateEx() failed with an error %x\n", rc);
82 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
83 ok(rc==DD_OK, "SetCooperativeLevel returned: %x\n", rc);
85 rc = IDirectDraw7_QueryInterface(lpDD, &IID_IDirect3D7, (void**) &lpD3D);
86 if (rc == E_NOINTERFACE) return FALSE;
87 ok(rc==DD_OK, "QueryInterface returned: %x\n", rc);
89 memset(&ddsd, 0, sizeof(ddsd));
90 ddsd.dwSize = sizeof(ddsd);
91 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
92 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
95 rc = IDirectDraw7_CreateSurface(lpDD, &ddsd, &lpDDS, NULL);
99 memset(&ddsd, 0, sizeof(ddsd));
100 ddsd.dwSize = sizeof(ddsd);
101 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
102 ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
103 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
104 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
105 U1(U4(ddsd).ddpfPixelFormat).dwZBufferBitDepth = 16;
106 U3(U4(ddsd).ddpfPixelFormat).dwZBitMask = 0x0000FFFF;
109 rc = IDirectDraw7_CreateSurface(lpDD, &ddsd, &lpDDSdepth, NULL);
110 ok(rc==DD_OK, "CreateSurface returned: %x\n", rc);
111 if (!SUCCEEDED(rc)) {
114 rc = IDirectDrawSurface_AddAttachedSurface(lpDDS, lpDDSdepth);
115 ok(rc == DD_OK, "IDirectDrawSurface_AddAttachedSurface returned %x\n", rc);
120 rc = IDirect3D7_CreateDevice(lpD3D, &IID_IDirect3DTnLHalDevice, lpDDS,
122 ok(rc==D3D_OK || rc==DDERR_NOPALETTEATTACHED || rc==E_OUTOFMEMORY, "CreateDevice returned: %x\n", rc);
124 trace("IDirect3D7::CreateDevice() for a TnL Hal device failed with an error %x, trying HAL\n", rc);
125 rc = IDirect3D7_CreateDevice(lpD3D, &IID_IDirect3DHALDevice, lpDDS,
128 trace("IDirect3D7::CreateDevice() for a HAL device failed with an error %x, trying RGB\n", rc);
129 rc = IDirect3D7_CreateDevice(lpD3D, &IID_IDirect3DRGBDevice, lpDDS,
132 trace("IDirect3D7::CreateDevice() for a RGB device failed with an error %x, giving up\n", rc);
141 static void ReleaseDirect3D(void)
143 if (lpD3DDevice != NULL)
145 IDirect3DDevice7_Release(lpD3DDevice);
149 if (lpDDSdepth != NULL)
151 IDirectDrawSurface_Release(lpDDSdepth);
157 IDirectDrawSurface_Release(lpDDS);
163 IDirect3D7_Release(lpD3D);
169 IDirectDraw_Release(lpDD);
174 static void LightTest(void)
178 D3DLIGHT7 defaultlight;
179 BOOL bEnabled = FALSE;
184 /* Set a few lights with funky indices. */
185 memset(&light, 0, sizeof(light));
186 light.dltType = D3DLIGHT_DIRECTIONAL;
187 U1(light.dcvDiffuse).r = 0.5f;
188 U2(light.dcvDiffuse).g = 0.6f;
189 U3(light.dcvDiffuse).b = 0.7f;
190 U2(light.dvDirection).y = 1.f;
192 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 5, &light);
193 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
194 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 10, &light);
195 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
196 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 45, &light);
197 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
200 /* Try to retrieve a light beyond the indices of the lights that have
202 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
203 ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %x\n", rc);
204 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 2, &light);
205 ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %x\n", rc);
208 /* Try to retrieve one of the lights that have been set */
209 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 10, &light);
210 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
213 /* Enable a light that have been previously set. */
214 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 10, TRUE);
215 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
218 /* Enable some lights that have not been previously set, and verify that
219 they have been initialized with proper default values. */
220 memset(&defaultlight, 0, sizeof(D3DLIGHT7));
221 defaultlight.dltType = D3DLIGHT_DIRECTIONAL;
222 U1(defaultlight.dcvDiffuse).r = 1.f;
223 U2(defaultlight.dcvDiffuse).g = 1.f;
224 U3(defaultlight.dcvDiffuse).b = 1.f;
225 U3(defaultlight.dvDirection).z = 1.f;
227 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, TRUE);
228 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
229 memset(&light, 0, sizeof(D3DLIGHT7));
230 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 20, &light);
231 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
232 ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
233 "light data doesn't match expected default values\n" );
235 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 50, TRUE);
236 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
237 memset(&light, 0, sizeof(D3DLIGHT7));
238 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
239 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
240 ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
241 "light data doesn't match expected default values\n" );
244 /* Disable one of the light that have been previously enabled. */
245 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, FALSE);
246 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
248 /* Try to retrieve the enable status of some lights */
249 /* Light 20 is supposed to be disabled */
250 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 20, &bEnabled );
251 ok(rc==D3D_OK, "GetLightEnable returned: %x\n", rc);
252 ok(!bEnabled, "GetLightEnable says the light is enabled\n");
254 /* Light 10 is supposed to be enabled */
256 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 10, &bEnabled );
257 ok(rc==D3D_OK, "GetLightEnable returned: %x\n", rc);
258 ok(bEnabled, "GetLightEnable says the light is disabled\n");
260 /* Light 80 has not been set */
261 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 80, &bEnabled );
262 ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %x\n", rc);
264 /* Light 23 has not been set */
265 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 23, &bEnabled );
266 ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %x\n", rc);
268 /* Set some lights with invalid parameters */
269 memset(&light, 0, sizeof(D3DLIGHT7));
271 U1(light.dcvDiffuse).r = 1.f;
272 U2(light.dcvDiffuse).g = 1.f;
273 U3(light.dcvDiffuse).b = 1.f;
274 U3(light.dvDirection).z = 1.f;
275 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 100, &light);
276 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
278 memset(&light, 0, sizeof(D3DLIGHT7));
279 light.dltType = 12345;
280 U1(light.dcvDiffuse).r = 1.f;
281 U2(light.dcvDiffuse).g = 1.f;
282 U3(light.dcvDiffuse).b = 1.f;
283 U3(light.dvDirection).z = 1.f;
284 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 101, &light);
285 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
287 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 102, NULL);
288 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
290 memset(&light, 0, sizeof(D3DLIGHT7));
291 light.dltType = D3DLIGHT_SPOT;
292 U1(light.dcvDiffuse).r = 1.f;
293 U2(light.dcvDiffuse).g = 1.f;
294 U3(light.dcvDiffuse).b = 1.f;
295 U3(light.dvDirection).z = 1.f;
297 light.dvAttenuation0 = -one / zero; /* -INFINITY */
298 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
299 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
301 light.dvAttenuation0 = -1.0;
302 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
303 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
305 light.dvAttenuation0 = 0.0;
306 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
307 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
309 light.dvAttenuation0 = 1.0;
310 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
311 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
313 light.dvAttenuation0 = one / zero; /* +INFINITY */
314 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
315 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
317 light.dvAttenuation0 = zero / zero; /* NaN */
318 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
319 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
321 /* Directional light ignores attenuation */
322 light.dltType = D3DLIGHT_DIRECTIONAL;
323 light.dvAttenuation0 = -1.0;
324 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
325 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
327 memset(&mat, 0, sizeof(mat));
328 rc = IDirect3DDevice7_SetMaterial(lpD3DDevice, &mat);
329 ok(rc == D3D_OK, "IDirect3DDevice7_SetMaterial returned: %x\n", rc);
331 U4(mat).power = 129.0;
332 rc = IDirect3DDevice7_SetMaterial(lpD3DDevice, &mat);
333 ok(rc == D3D_OK, "IDirect3DDevice7_SetMaterial(power = 129.0) returned: %x\n", rc);
334 memset(&mat, 0, sizeof(mat));
335 rc = IDirect3DDevice7_GetMaterial(lpD3DDevice, &mat);
336 ok(rc == D3D_OK, "IDirect3DDevice7_GetMaterial returned: %x\n", rc);
337 ok(U4(mat).power == 129, "Returned power is %f\n", U4(mat).power);
339 U4(mat).power = -1.0;
340 rc = IDirect3DDevice7_SetMaterial(lpD3DDevice, &mat);
341 ok(rc == D3D_OK, "IDirect3DDevice7_SetMaterial(power = -1.0) returned: %x\n", rc);
342 memset(&mat, 0, sizeof(mat));
343 rc = IDirect3DDevice7_GetMaterial(lpD3DDevice, &mat);
344 ok(rc == D3D_OK, "IDirect3DDevice7_GetMaterial returned: %x\n", rc);
345 ok(U4(mat).power == -1, "Returned power is %f\n", U4(mat).power);
348 static void ProcessVerticesTest(void)
350 D3DVERTEXBUFFERDESC desc;
356 D3DMATRIX view = { 2.0, 0.0, 0.0, 0.0,
359 0.0, 0.0, 0.0, 3.0 };
361 D3DMATRIX world = { 0.0, 1.0, 0.0, 0.0,
364 0.0, 1.0, 1.0, 1.0 };
366 D3DMATRIX proj = { 1.0, 0.0, 0.0, 1.0,
369 1.0, 0.0, 0.0, 1.0 };
370 /* Create some vertex buffers */
372 memset(&desc, 0, sizeof(desc));
373 desc.dwSize = sizeof(desc);
375 desc.dwFVF = D3DFVF_XYZ;
376 desc.dwNumVertices = 16;
377 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufSrc, 0);
378 ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
381 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
385 memset(&desc, 0, sizeof(desc));
386 desc.dwSize = sizeof(desc);
388 desc.dwFVF = D3DFVF_XYZRHW;
389 desc.dwNumVertices = 16;
390 /* Msdn says that the last parameter must be 0 - check that */
391 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufDest1, 4);
392 ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
395 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
399 memset(&desc, 0, sizeof(desc));
400 desc.dwSize = sizeof(desc);
402 desc.dwFVF = D3DFVF_XYZ;
403 desc.dwNumVertices = 16;
404 /* Msdn says that the last parameter must be 0 - check that */
405 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufDest2, 12345678);
406 ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
409 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
413 rc = IDirect3DVertexBuffer7_Lock(lpVBufSrc, 0, (void **) &in, NULL);
414 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
417 /* Check basic transformation */
434 rc = IDirect3DVertexBuffer7_Unlock(lpVBufSrc);
435 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
437 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
438 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
440 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest2, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
441 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
443 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
444 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
447 /* Check the results */
448 ok( comparefloat(out[0].x, 128.0 ) &&
449 comparefloat(out[0].y, 128.0 ) &&
450 comparefloat(out[0].z, 0.0 ) &&
451 comparefloat(out[0].rhw, 1.0 ),
452 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
454 ok( comparefloat(out[1].x, 256.0 ) &&
455 comparefloat(out[1].y, 0.0 ) &&
456 comparefloat(out[1].z, 1.0 ) &&
457 comparefloat(out[1].rhw, 1.0 ),
458 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
460 ok( comparefloat(out[2].x, 0.0 ) &&
461 comparefloat(out[2].y, 256.0 ) &&
462 comparefloat(out[2].z, 0.5 ) &&
463 comparefloat(out[2].rhw, 1.0 ),
464 "Output 2 vertex is (%f , %f , %f , %f)\n", out[2].x, out[2].y, out[2].z, out[2].rhw);
466 ok( comparefloat(out[3].x, 192.0 ) &&
467 comparefloat(out[3].y, 192.0 ) &&
468 comparefloat(out[3].z, 0.25 ) &&
469 comparefloat(out[3].rhw, 1.0 ),
470 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
472 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
473 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
476 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest2, 0, (void **) &out2, NULL);
477 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
479 /* Small thing without much practial meaning, but I stumbled upon it,
480 * so let's check for it: If the output vertex buffer has to RHW value,
481 * The RHW value of the last vertex is written into the next vertex
483 ok( comparefloat(out2[4].x, 1.0 ) &&
484 comparefloat(out2[4].y, 0.0 ) &&
485 comparefloat(out2[4].z, 0.0 ),
486 "Output 4 vertex is (%f , %f , %f)\n", out2[4].x, out2[4].y, out2[4].z);
488 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest2);
489 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
492 /* Try a more complicated viewport, same vertices */
493 memset(&vp, 0, sizeof(vp));
500 rc = IDirect3DDevice7_SetViewport(lpD3DDevice, &vp);
501 ok(rc==D3D_OK, "IDirect3DDevice7_SetViewport failed with rc=%x\n", rc);
504 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
505 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
507 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
508 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
511 /* Check the results */
512 ok( comparefloat(out[0].x, 133.0 ) &&
513 comparefloat(out[0].y, 70.0 ) &&
514 comparefloat(out[0].z, -2.0 ) &&
515 comparefloat(out[0].rhw, 1.0 ),
516 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
518 ok( comparefloat(out[1].x, 256.0 ) &&
519 comparefloat(out[1].y, 5.0 ) &&
520 comparefloat(out[1].z, 4.0 ) &&
521 comparefloat(out[1].rhw, 1.0 ),
522 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
524 ok( comparefloat(out[2].x, 10.0 ) &&
525 comparefloat(out[2].y, 135.0 ) &&
526 comparefloat(out[2].z, 1.0 ) &&
527 comparefloat(out[2].rhw, 1.0 ),
528 "Output 2 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
530 ok( comparefloat(out[3].x, 194.5 ) &&
531 comparefloat(out[3].y, 102.5 ) &&
532 comparefloat(out[3].z, -0.5 ) &&
533 comparefloat(out[3].rhw, 1.0 ),
534 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
536 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
537 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
540 /* Play with some matrices. */
542 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_VIEW, &view);
543 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
545 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_PROJECTION, &proj);
546 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
548 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_WORLD, &world);
549 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
551 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
552 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
554 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
555 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
558 /* Keep the viewport simpler, otherwise we get bad numbers to compare */
565 rc = IDirect3DDevice7_SetViewport(lpD3DDevice, &vp);
566 ok(rc==D3D_OK, "IDirect3DDevice7_SetViewport failed\n");
568 /* Check the results */
569 ok( comparefloat(out[0].x, 256.0 ) && /* X coordinate is cut at the surface edges */
570 comparefloat(out[0].y, 70.0 ) &&
571 comparefloat(out[0].z, -2.0 ) &&
572 comparefloat(out[0].rhw, (1.0 / 3.0)),
573 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
575 ok( comparefloat(out[1].x, 256.0 ) &&
576 comparefloat(out[1].y, 78.125000 ) &&
577 comparefloat(out[1].z, -2.750000 ) &&
578 comparefloat(out[1].rhw, 0.125000 ),
579 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
581 ok( comparefloat(out[2].x, 256.0 ) &&
582 comparefloat(out[2].y, 44.000000 ) &&
583 comparefloat(out[2].z, 0.400000 ) &&
584 comparefloat(out[2].rhw, 0.400000 ),
585 "Output 2 vertex is (%f , %f , %f , %f)\n", out[2].x, out[2].y, out[2].z, out[2].rhw);
587 ok( comparefloat(out[3].x, 256.0 ) &&
588 comparefloat(out[3].y, 81.818184 ) &&
589 comparefloat(out[3].z, -3.090909 ) &&
590 comparefloat(out[3].rhw, 0.363636 ),
591 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
593 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
594 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
598 IDirect3DVertexBuffer7_Release(lpVBufSrc);
599 IDirect3DVertexBuffer7_Release(lpVBufDest1);
600 IDirect3DVertexBuffer7_Release(lpVBufDest2);
603 static void StateTest( void )
607 /* The msdn says its undocumented, does it return an error too? */
608 rc = IDirect3DDevice7_SetRenderState(lpD3DDevice, D3DRENDERSTATE_ZVISIBLE, TRUE);
609 ok(rc == D3D_OK, "IDirect3DDevice7_SetRenderState(D3DRENDERSTATE_ZVISIBLE, TRUE) returned %08x\n", rc);
610 rc = IDirect3DDevice7_SetRenderState(lpD3DDevice, D3DRENDERSTATE_ZVISIBLE, FALSE);
611 ok(rc == D3D_OK, "IDirect3DDevice7_SetRenderState(D3DRENDERSTATE_ZVISIBLE, FALSE) returned %08x\n", rc);
615 static void SceneTest(void)
619 /* Test an EndScene without beginscene. Should return an error */
620 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
621 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
623 /* Test a normal BeginScene / EndScene pair, this should work */
624 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
625 ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed with %08x\n", hr);
629 memset(&fx, 0, sizeof(fx));
630 fx.dwSize = sizeof(fx);
633 hr = IDirectDrawSurface7_Blt(lpDDSdepth, NULL, NULL, NULL, DDBLT_DEPTHFILL, &fx);
634 ok(hr == D3D_OK, "Depthfill failed in a BeginScene / EndScene pair\n");
636 skip("Depth stencil creation failed at startup, skipping\n");
638 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
639 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed with %08x\n", hr);
642 /* Test another EndScene without having begun a new scene. Should return an error */
643 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
644 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
646 /* Two nested BeginScene and EndScene calls */
647 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
648 ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed with %08x\n", hr);
649 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
650 ok(hr == D3DERR_SCENE_IN_SCENE, "IDirect3DDevice7_BeginScene returned %08x\n", hr);
651 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
652 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed with %08x\n", hr);
653 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
654 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
656 /* TODO: Verify that blitting works in the same way as in d3d9 */
659 static void LimitTest(void)
661 IDirectDrawSurface7 *pTexture = NULL;
666 memset(&ddsd, 0, sizeof(ddsd));
667 ddsd.dwSize = sizeof(ddsd);
668 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
669 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
672 hr = IDirectDraw7_CreateSurface(lpDD, &ddsd, &pTexture, NULL);
673 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
674 if(!pTexture) return;
676 for(i = 0; i < 8; i++) {
677 hr = IDirect3DDevice7_SetTexture(lpD3DDevice, i, pTexture);
678 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %08x\n", i, hr);
679 hr = IDirect3DDevice7_SetTexture(lpD3DDevice, i, NULL);
680 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %08x\n", i, hr);
681 hr = IDirect3DDevice7_SetTextureStageState(lpD3DDevice, i, D3DTSS_COLOROP, D3DTOP_ADD);
682 ok(hr == D3D_OK, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %08x\n", i, hr);
685 IDirectDrawSurface7_Release(pTexture);
688 static HRESULT WINAPI enumDevicesCallback(GUID *Guid,LPSTR DeviceDescription,LPSTR DeviceName, D3DDEVICEDESC *hal, D3DDEVICEDESC *hel, VOID *ctx)
690 UINT ver = *((UINT *) ctx);
691 if(IsEqualGUID(&IID_IDirect3DRGBDevice, Guid))
693 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
694 "RGB Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
695 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
696 "RGB Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
697 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
698 "RGB Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
699 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
700 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
702 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
703 "RGB Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
704 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
705 "RGB Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
706 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
707 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
708 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
709 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
711 else if(IsEqualGUID(&IID_IDirect3DHALDevice, Guid))
713 /* pow2 is hardware dependent */
715 ok(hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
716 "HAL Device %d hal line caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
717 ok(hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
718 "HAL Device %d hal tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
719 ok((hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
720 "HAL Device %d hel line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
721 ok((hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
722 "HAL Device %d hel tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
724 else if(IsEqualGUID(&IID_IDirect3DRefDevice, Guid))
726 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
727 "REF Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
728 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
729 "REF Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
730 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
731 "REF Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
732 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
733 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
735 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
736 "REF Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
737 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
738 "REF Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
739 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
740 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
741 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
742 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
744 else if(IsEqualGUID(&IID_IDirect3DRampDevice, Guid))
746 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
747 "Ramp Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
748 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
749 "Ramp Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
750 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
751 "Ramp Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
752 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
753 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
755 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
756 "Ramp Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
757 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
758 "Ramp Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
759 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
760 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
761 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
762 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
764 else if(IsEqualGUID(&IID_IDirect3DMMXDevice, Guid))
766 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
767 "MMX Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
768 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
769 "MMX Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
770 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
771 "MMX Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
772 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
773 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
775 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
776 "MMX Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
777 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
778 "MMX Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
779 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
780 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
781 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
782 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
786 ok(FALSE, "Unexpected device enumerated: \"%s\" \"%s\"\n", DeviceDescription, DeviceName);
787 if(hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hal line has pow2 set\n");
788 else trace("hal line does NOT have pow2 set\n");
789 if(hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hal tri has pow2 set\n");
790 else trace("hal tri does NOT have pow2 set\n");
791 if(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hel line has pow2 set\n");
792 else trace("hel line does NOT have pow2 set\n");
793 if(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hel tri has pow2 set\n");
794 else trace("hel tri does NOT have pow2 set\n");
799 static HRESULT WINAPI enumDevicesCallbackTest7(LPSTR DeviceDescription, LPSTR DeviceName, LPD3DDEVICEDESC7 lpdd7, LPVOID Context)
801 D3D7ETest *d3d7et = (D3D7ETest*)Context;
802 if(IsEqualGUID(&lpdd7->deviceGUID, &IID_IDirect3DRGBDevice))
804 else if(IsEqualGUID(&lpdd7->deviceGUID, &IID_IDirect3DHALDevice))
806 else if(IsEqualGUID(&lpdd7->deviceGUID, &IID_IDirect3DTnLHalDevice))
817 /* Check the deviceGUID of devices enumerated by
818 IDirect3D7_EnumDevices. */
819 static void D3D7EnumTest(void)
824 skip("No Direct3D7 interface.\n");
828 memset(&d3d7et, 0, sizeof(d3d7et));
829 IDirect3D7_EnumDevices(lpD3D, enumDevicesCallbackTest7, (LPVOID) &d3d7et);
832 /* A couple of games (Delta Force LW and TFD) rely on this behaviour */
833 ok(d3d7et.tnlhal < d3d7et.total, "TnLHal device enumerated as only device.\n");
835 /* We make two additional assumptions. */
836 ok(d3d7et.rgb, "No RGB Device enumerated.\n");
839 ok(d3d7et.hal, "TnLHal device enumerated, but no Hal device found.\n");
844 static void CapsTest(void)
852 hr = DirectDrawCreate(NULL, &dd1, NULL);
853 ok(hr == DD_OK, "Cannot create a DirectDraw 1 interface, hr = %08x\n", hr);
854 hr = IDirectDraw_QueryInterface(dd1, &IID_IDirect3D3, (void **) &d3d3);
855 ok(hr == D3D_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
857 IDirect3D3_EnumDevices(d3d3, enumDevicesCallback, &ver);
859 IDirect3D3_Release(d3d3);
860 IDirectDraw_Release(dd1);
862 hr = DirectDrawCreate(NULL, &dd1, NULL);
863 ok(hr == DD_OK, "Cannot create a DirectDraw 1 interface, hr = %08x\n", hr);
864 hr = IDirectDraw_QueryInterface(dd1, &IID_IDirect3D2, (void **) &d3d2);
865 ok(hr == D3D_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
867 IDirect3D2_EnumDevices(d3d2, enumDevicesCallback, &ver);
869 IDirect3D2_Release(d3d2);
870 IDirectDraw_Release(dd1);
880 static void Direct3D1Test(void)
882 IDirect3DDevice *dev1 = NULL;
885 IDirectDrawSurface *dds;
886 IDirect3DExecuteBuffer *exebuf;
887 IDirect3DViewport *vp;
890 D3DEXECUTEBUFFERDESC desc;
892 D3DINSTRUCTION *instr;
894 unsigned int idx = 0;
895 static struct v_in testverts[] = {
896 {0.0, 0.0, 0.0}, { 1.0, 1.0, 1.0}, {-1.0, -1.0, -1.0},
897 {0.5, 0.5, 0.5}, {-0.5, -0.5, -0.5}, {-0.5, -0.5, 0.0},
899 static struct v_in cliptest[] = {
900 {25.59, 25.59, 1.0}, {-25.59, -25.59, 0.0},
901 {25.61, 25.61, 1.01}, {-25.60, -25.60, -0.01},
903 static struct v_in offscreentest[] = {
906 struct v_out out[sizeof(testverts) / sizeof(testverts[0])];
907 D3DHVERTEX outH[sizeof(testverts) / sizeof(testverts[0])];
908 D3DTRANSFORMDATA transformdata;
911 /* An IDirect3DDevice cannot be queryInterfaced from an IDirect3DDevice7 on windows */
912 hr = DirectDrawCreate(NULL, &dd, NULL);
913 ok(hr==DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreate returned: %x\n", hr);
915 trace("DirectDrawCreate() failed with an error %x\n", hr);
919 hr = IDirectDraw_SetCooperativeLevel(dd, NULL, DDSCL_NORMAL);
920 ok(hr==DD_OK, "SetCooperativeLevel returned: %x\n", hr);
922 hr = IDirectDraw_QueryInterface(dd, &IID_IDirect3D, (void**) &d3d);
923 ok(hr==DD_OK, "QueryInterface returned: %x\n", hr);
925 memset(&ddsd, 0, sizeof(ddsd));
926 ddsd.dwSize = sizeof(ddsd);
927 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
928 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
931 hr = IDirectDraw_CreateSurface(dd, &ddsd, &dds, NULL);
932 ok(hr==DD_OK, "CreateSurface returned: %x\n", hr);
935 hr = IDirectDrawSurface_QueryInterface(dds, &IID_IDirect3DRGBDevice, (void **) &dev1);
936 ok(hr==D3D_OK || hr==DDERR_NOPALETTEATTACHED || hr==E_OUTOFMEMORY, "CreateDevice returned: %x\n", hr);
939 memset(&desc, 0, sizeof(desc));
940 desc.dwSize = sizeof(desc);
941 desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
942 desc.dwCaps = D3DDEBCAPS_VIDEOMEMORY;
943 desc.dwBufferSize = 128;
945 hr = IDirect3DDevice_CreateExecuteBuffer(dev1, &desc, &exebuf, NULL);
946 ok(hr == D3D_OK, "IDirect3DDevice_CreateExecuteBuffer failed: %08x\n", hr);
948 memset(&desc, 0, sizeof(desc));
949 desc.dwSize = sizeof(desc);
951 hr = IDirect3DExecuteBuffer_Lock(exebuf, &desc);
952 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Lock failed: %08x\n", hr);
954 instr[idx].bOpcode = D3DOP_BRANCHFORWARD;
955 instr[idx].bSize = sizeof(*branch);
956 instr[idx].wCount = 1;
958 branch = (D3DBRANCH *) &instr[idx];
959 branch->dwMask = 0x0;
961 branch->bNegate = TRUE;
962 branch->dwOffset = 0;
963 idx += (sizeof(*branch) / sizeof(*instr));
964 instr[idx].bOpcode = D3DOP_EXIT;
965 instr[idx].bSize = 0;
966 instr[idx].bSize = 0;
967 hr = IDirect3DExecuteBuffer_Unlock(exebuf);
968 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Unlock failed: %08x\n", hr);
970 hr = IDirect3D_CreateViewport(d3d, &vp, NULL);
971 ok(hr == D3D_OK, "IDirect3D_CreateViewport failed: %08x\n", hr);
972 hr = IDirect3DViewport_Initialize(vp, d3d);
973 ok(hr == DDERR_ALREADYINITIALIZED, "IDirect3DViewport_Initialize returned %08x\n", hr);
975 hr = IDirect3DDevice_AddViewport(dev1, vp);
976 ok(hr == D3D_OK, "IDirect3DDevice_AddViewport returned %08x\n", hr);
977 vp_data.dwSize = sizeof(vp_data);
980 vp_data.dwWidth = 256;
981 vp_data.dwHeight = 256;
982 vp_data.dvScaleX = 1;
983 vp_data.dvScaleY = 1;
984 vp_data.dvMaxX = 256;
985 vp_data.dvMaxY = 256;
988 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
989 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
991 hr = IDirect3DDevice_Execute(dev1, exebuf, vp, D3DEXECUTE_CLIPPED);
992 ok(hr == D3D_OK, "IDirect3DDevice_Execute returned %08x\n", hr);
994 memset(&transformdata, 0, sizeof(transformdata));
995 transformdata.dwSize = sizeof(transformdata);
996 transformdata.lpIn = (void *) testverts;
997 transformdata.dwInSize = sizeof(testverts[0]);
998 transformdata.lpOut = out;
999 transformdata.dwOutSize = sizeof(out[0]);
1001 transformdata.lpHOut = NULL;
1002 hr = IDirect3DViewport_TransformVertices(vp, sizeof(testverts) / sizeof(testverts[0]),
1003 &transformdata, D3DTRANSFORM_UNCLIPPED,
1005 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1007 transformdata.lpHOut = outH;
1008 memset(outH, 0xaa, sizeof(outH));
1009 hr = IDirect3DViewport_TransformVertices(vp, sizeof(testverts) / sizeof(testverts[0]),
1010 &transformdata, D3DTRANSFORM_UNCLIPPED,
1012 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1013 ok(i == 0, "Offscreen is %d\n", i);
1015 for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
1016 static const struct v_out cmp[] = {
1017 {128.0, 128.0, 0.0, 1}, {129.0, 127.0, 1.0, 1}, {127.0, 129.0, -1, 1},
1018 {128.5, 127.5, 0.5, 1}, {127.5, 128.5, -0.5, 1}, {127.5, 128.5, 0, 1}
1021 ok(cmp[i].x == out[i].x && cmp[i].y == out[i].y &&
1022 cmp[i].z == out[i].z && cmp[i].rhw == out[i].rhw,
1023 "Vertex %d differs. Got %f %f %f %f, expexted %f %f %f %f\n", i + 1,
1024 out[i].x, out[i].y, out[i].z, out[i].rhw,
1025 cmp[i].x, cmp[i].y, cmp[i].z, cmp[i].rhw);
1027 for(i = 0; i < sizeof(outH); i++) {
1028 if(((unsigned char *) outH)[i] != 0xaa) {
1029 ok(FALSE, "Homogenous output was generated despite UNCLIPPED flag\n");
1034 vp_data.dvScaleX = 5;
1035 vp_data.dvScaleY = 5;
1036 vp_data.dvMinZ = -25;
1037 vp_data.dvMaxZ = 60;
1038 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1039 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1040 hr = IDirect3DViewport_TransformVertices(vp, sizeof(testverts) / sizeof(testverts[0]),
1041 &transformdata, D3DTRANSFORM_UNCLIPPED,
1043 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1044 ok(i == 0, "Offscreen is %d\n", i);
1045 for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
1046 static const struct v_out cmp[] = {
1047 {128.0, 128.0, 0.0, 1}, {133.0, 123.0, 1.0, 1}, {123.0, 133.0, -1, 1},
1048 {130.5, 125.5, 0.5, 1}, {125.5, 130.5, -0.5, 1}, {125.5, 130.5, 0, 1}
1050 ok(cmp[i].x == out[i].x && cmp[i].y == out[i].y &&
1051 cmp[i].z == out[i].z && cmp[i].rhw == out[i].rhw,
1052 "Vertex %d differs. Got %f %f %f %f, expexted %f %f %f %f\n", i + 1,
1053 out[i].x, out[i].y, out[i].z, out[i].rhw,
1054 cmp[i].x, cmp[i].y, cmp[i].z, cmp[i].rhw);
1059 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1060 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1061 hr = IDirect3DViewport_TransformVertices(vp, sizeof(testverts) / sizeof(testverts[0]),
1062 &transformdata, D3DTRANSFORM_UNCLIPPED,
1064 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1065 ok(i == 0, "Offscreen is %d\n", i);
1066 for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
1067 static const struct v_out cmp[] = {
1068 {138.0, 148.0, 0.0, 1}, {143.0, 143.0, 1.0, 1}, {133.0, 153.0, -1, 1},
1069 {140.5, 145.5, 0.5, 1}, {135.5, 150.5, -0.5, 1}, {135.5, 150.5, 0, 1}
1071 ok(cmp[i].x == out[i].x && cmp[i].y == out[i].y &&
1072 cmp[i].z == out[i].z && cmp[i].rhw == out[i].rhw,
1073 "Vertex %d differs. Got %f %f %f %f, expexted %f %f %f %f\n", i + 1,
1074 out[i].x, out[i].y, out[i].z, out[i].rhw,
1075 cmp[i].x, cmp[i].y, cmp[i].z, cmp[i].rhw);
1078 memset(out, 0xbb, sizeof(out));
1079 hr = IDirect3DViewport_TransformVertices(vp, sizeof(testverts) / sizeof(testverts[0]),
1080 &transformdata, D3DTRANSFORM_CLIPPED,
1082 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1083 ok(i == 0, "Offscreen is %d\n", i);
1084 for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
1085 static const D3DHVERTEX cmpH[] = {
1086 {0, { 0.0}, { 0.0}, { 0.0}}, {0, { 1.0}, { 1.0}, {1.0}},
1087 {D3DCLIP_FRONT, {-1.0}, {-1.0}, {-1.0}}, {0, { 0.5}, { 0.5}, {0.5}},
1088 {D3DCLIP_FRONT, {-0.5}, {-0.5}, {-0.5}}, {0, {-0.5}, {-0.5}, {0.0}}
1090 ok(U1(cmpH[i]).hx == U1(outH[i]).hx && U2(cmpH[i]).hy == U2(outH[i]).hy &&
1091 U3(cmpH[i]).hz == U3(outH[i]).hz && cmpH[i].dwFlags == outH[i].dwFlags,
1092 "HVertex %d differs. Got %08x %f %f %f, expexted %08x %f %f %f\n", i + 1,
1093 outH[i].dwFlags, U1(outH[i]).hx, U2(outH[i]).hy, U3(outH[i]).hz,
1094 cmpH[i].dwFlags, U1(cmpH[i]).hx, U2(cmpH[i]).hy, U3(cmpH[i]).hz);
1096 /* No scheme has been found behind those return values. It seems to be
1097 * whatever data windows has when throwing the vertex away. Modify the
1098 * input test vertices to test this more. Depending on the input data
1099 * it can happen that the z coord gets written into y, or similar things
1103 static const struct v_out cmp[] = {
1104 {138.0, 148.0, 0.0, 1}, {143.0, 143.0, 1.0, 1}, { -1.0, -1.0, 0.5, 1},
1105 {140.5, 145.5, 0.5, 1}, { -0.5, -0.5, -0.5, 1}, {135.5, 150.5, 0.0, 1}
1107 ok(cmp[i].x == out[i].x && cmp[i].y == out[i].y &&
1108 cmp[i].z == out[i].z && cmp[i].rhw == out[i].rhw,
1109 "Vertex %d differs. Got %f %f %f %f, expexted %f %f %f %f\n", i + 1,
1110 out[i].x, out[i].y, out[i].z, out[i].rhw,
1111 cmp[i].x, cmp[i].y, cmp[i].z, cmp[i].rhw);
1114 for(i = 0; i < sizeof(out) / sizeof(DWORD); i++) {
1115 ok(((DWORD *) out)[i] != 0xbbbbbbbb,
1116 "Regular output DWORD %d remained untouched\n", i);
1119 transformdata.lpIn = (void *) cliptest;
1120 transformdata.dwInSize = sizeof(cliptest[0]);
1121 hr = IDirect3DViewport_TransformVertices(vp, sizeof(cliptest) / sizeof(cliptest[0]),
1122 &transformdata, D3DTRANSFORM_CLIPPED,
1124 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1125 ok(i == 0, "Offscreen is %d\n", i);
1126 for(i = 0; i < sizeof(cliptest) / sizeof(cliptest[0]); i++) {
1127 DWORD Flags[sizeof(cliptest) / sizeof(cliptest[0])] =
1131 D3DCLIP_RIGHT | D3DCLIP_BACK | D3DCLIP_TOP,
1132 D3DCLIP_LEFT | D3DCLIP_BOTTOM | D3DCLIP_FRONT,
1134 ok(Flags[i] == outH[i].dwFlags,
1135 "Cliptest %d differs. Got %08x expexted %08x\n", i + 1,
1136 outH[i].dwFlags, Flags[i]);
1139 vp_data.dwWidth = 10;
1140 vp_data.dwHeight = 1000;
1141 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1143 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1144 hr = IDirect3DViewport_TransformVertices(vp, sizeof(cliptest) / sizeof(cliptest[0]),
1145 &transformdata, D3DTRANSFORM_CLIPPED,
1147 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1148 ok(i == 0, "Offscreen is %d\n", i);
1149 for(i = 0; i < sizeof(cliptest) / sizeof(cliptest[0]); i++) {
1150 DWORD Flags[sizeof(cliptest) / sizeof(cliptest[0])] =
1154 D3DCLIP_RIGHT | D3DCLIP_BACK,
1155 D3DCLIP_LEFT | D3DCLIP_FRONT,
1157 ok(Flags[i] == outH[i].dwFlags,
1158 "Cliptest %d differs. Got %08x expexted %08x\n", i + 1,
1159 outH[i].dwFlags, Flags[i]);
1161 vp_data.dwWidth = 256;
1162 vp_data.dwHeight = 256;
1163 vp_data.dvScaleX = 1;
1164 vp_data.dvScaleY = 1;
1165 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1166 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1167 hr = IDirect3DViewport_TransformVertices(vp, sizeof(cliptest) / sizeof(cliptest[0]),
1168 &transformdata, D3DTRANSFORM_CLIPPED,
1170 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1171 ok(i == 0, "Offscreen is %s\n", i ? "TRUE" : "FALSE");
1172 for(i = 0; i < sizeof(cliptest) / sizeof(cliptest[0]); i++) {
1173 DWORD Flags[sizeof(cliptest) / sizeof(cliptest[0])] =
1180 ok(Flags[i] == outH[i].dwFlags,
1181 "Cliptest %d differs. Got %08x expexted %08x\n", i + 1,
1182 outH[i].dwFlags, Flags[i]);
1185 /* Finally try to figure out how the DWORD dwOffscreen works.
1186 * Apparently no vertex is offscreen with clipping off,
1187 * and with clipping on the offscreen flag is set if only one vertex
1188 * is transformed, and this vertex is offscreen.
1190 vp_data.dwWidth = 5;
1191 vp_data.dwHeight = 5;
1192 vp_data.dvScaleX = 10000;
1193 vp_data.dvScaleY = 10000;
1194 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1195 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1196 transformdata.lpIn = cliptest;
1197 hr = IDirect3DViewport_TransformVertices(vp, 1,
1198 &transformdata, D3DTRANSFORM_UNCLIPPED,
1200 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1201 ok(i == 0, "Offscreen is %d\n", i);
1202 hr = IDirect3DViewport_TransformVertices(vp, 1,
1203 &transformdata, D3DTRANSFORM_CLIPPED,
1205 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1206 ok(i == (D3DCLIP_RIGHT | D3DCLIP_TOP), "Offscreen is %d\n", i);
1207 hr = IDirect3DViewport_TransformVertices(vp, 2,
1208 &transformdata, D3DTRANSFORM_CLIPPED,
1210 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1211 ok(i == 0, "Offscreen is %d\n", i);
1212 transformdata.lpIn = cliptest + 1;
1213 hr = IDirect3DViewport_TransformVertices(vp, 1,
1214 &transformdata, D3DTRANSFORM_CLIPPED,
1216 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1217 ok(i == (D3DCLIP_BOTTOM | D3DCLIP_LEFT), "Offscreen is %d\n", i);
1219 transformdata.lpIn = (void *) offscreentest;
1220 transformdata.dwInSize = sizeof(offscreentest[0]);
1221 vp_data.dwWidth = 257;
1222 vp_data.dwHeight = 257;
1223 vp_data.dvScaleX = 1;
1224 vp_data.dvScaleY = 1;
1225 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1227 hr = IDirect3DViewport_TransformVertices(vp, sizeof(offscreentest) / sizeof(offscreentest[0]),
1228 &transformdata, D3DTRANSFORM_CLIPPED,
1230 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1231 ok(i == 0, "Offscreen is %d\n", i);
1232 vp_data.dwWidth = 256;
1233 vp_data.dwHeight = 256;
1234 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1236 hr = IDirect3DViewport_TransformVertices(vp, sizeof(offscreentest) / sizeof(offscreentest[0]),
1237 &transformdata, D3DTRANSFORM_CLIPPED,
1239 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1240 ok(i == D3DCLIP_RIGHT, "Offscreen is %d\n", i);
1242 hr = IDirect3DViewport_TransformVertices(vp, sizeof(testverts) / sizeof(testverts[0]),
1245 ok(hr == DDERR_INVALIDPARAMS, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1247 hr = IDirect3DDevice_DeleteViewport(dev1, vp);
1248 ok(hr == D3D_OK, "IDirect3DDevice_DeleteViewport returned %08x\n", hr);
1250 IDirect3DViewport_Release(vp);
1251 IDirect3DExecuteBuffer_Release(exebuf);
1252 IDirect3DDevice_Release(dev1);
1253 IDirectDrawSurface_Release(dds);
1254 IDirect3D_Release(d3d);
1255 IDirectDraw_Release(dd);
1261 init_function_pointers();
1262 if(!pDirectDrawCreateEx) {
1263 skip("function DirectDrawCreateEx not available\n");
1267 if(!CreateDirect3D()) {
1268 trace("Skipping tests\n");
1272 ProcessVerticesTest();