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;
187 /* Set a few lights with funky indices. */
188 memset(&light, 0, sizeof(light));
189 light.dltType = D3DLIGHT_DIRECTIONAL;
190 U1(light.dcvDiffuse).r = 0.5f;
191 U2(light.dcvDiffuse).g = 0.6f;
192 U3(light.dcvDiffuse).b = 0.7f;
193 U2(light.dvDirection).y = 1.f;
195 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 5, &light);
196 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
197 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 10, &light);
198 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
199 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 45, &light);
200 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
203 /* Try to retrieve a light beyond the indices of the lights that have
205 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
206 ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %x\n", rc);
207 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 2, &light);
208 ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %x\n", rc);
211 /* Try to retrieve one of the lights that have been set */
212 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 10, &light);
213 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
216 /* Enable a light that have been previously set. */
217 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 10, TRUE);
218 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
221 /* Enable some lights that have not been previously set, and verify that
222 they have been initialized with proper default values. */
223 memset(&defaultlight, 0, sizeof(D3DLIGHT7));
224 defaultlight.dltType = D3DLIGHT_DIRECTIONAL;
225 U1(defaultlight.dcvDiffuse).r = 1.f;
226 U2(defaultlight.dcvDiffuse).g = 1.f;
227 U3(defaultlight.dcvDiffuse).b = 1.f;
228 U3(defaultlight.dvDirection).z = 1.f;
230 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, TRUE);
231 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
232 memset(&light, 0, sizeof(D3DLIGHT7));
233 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 20, &light);
234 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
235 ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
236 "light data doesn't match expected default values\n" );
238 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 50, TRUE);
239 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
240 memset(&light, 0, sizeof(D3DLIGHT7));
241 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
242 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
243 ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
244 "light data doesn't match expected default values\n" );
247 /* Disable one of the light that have been previously enabled. */
248 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, FALSE);
249 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
251 /* Try to retrieve the enable status of some lights */
252 /* Light 20 is supposed to be disabled */
253 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 20, &bEnabled );
254 ok(rc==D3D_OK, "GetLightEnable returned: %x\n", rc);
255 ok(!bEnabled, "GetLightEnable says the light is enabled\n");
257 /* Light 10 is supposed to be enabled */
259 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 10, &bEnabled );
260 ok(rc==D3D_OK, "GetLightEnable returned: %x\n", rc);
261 ok(bEnabled, "GetLightEnable says the light is disabled\n");
263 /* Light 80 has not been set */
264 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 80, &bEnabled );
265 ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %x\n", rc);
267 /* Light 23 has not been set */
268 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 23, &bEnabled );
269 ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %x\n", rc);
271 /* Set some lights with invalid parameters */
272 memset(&light, 0, sizeof(D3DLIGHT7));
274 U1(light.dcvDiffuse).r = 1.f;
275 U2(light.dcvDiffuse).g = 1.f;
276 U3(light.dcvDiffuse).b = 1.f;
277 U3(light.dvDirection).z = 1.f;
278 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 100, &light);
279 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
281 memset(&light, 0, sizeof(D3DLIGHT7));
282 light.dltType = 12345;
283 U1(light.dcvDiffuse).r = 1.f;
284 U2(light.dcvDiffuse).g = 1.f;
285 U3(light.dcvDiffuse).b = 1.f;
286 U3(light.dvDirection).z = 1.f;
287 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 101, &light);
288 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
290 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 102, NULL);
291 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
293 memset(&light, 0, sizeof(D3DLIGHT7));
294 light.dltType = D3DLIGHT_SPOT;
295 U1(light.dcvDiffuse).r = 1.f;
296 U2(light.dcvDiffuse).g = 1.f;
297 U3(light.dcvDiffuse).b = 1.f;
298 U3(light.dvDirection).z = 1.f;
300 light.dvAttenuation0 = -one / zero; /* -INFINITY */
301 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
302 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
304 light.dvAttenuation0 = -1.0;
305 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
306 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
308 light.dvAttenuation0 = 0.0;
309 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
310 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
312 light.dvAttenuation0 = 1.0;
313 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
314 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
316 light.dvAttenuation0 = one / zero; /* +INFINITY */
317 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
318 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
320 light.dvAttenuation0 = zero / zero; /* NaN */
321 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
322 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
324 /* Directional light ignores attenuation */
325 light.dltType = D3DLIGHT_DIRECTIONAL;
326 light.dvAttenuation0 = -1.0;
327 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
328 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
330 memset(&mat, 0, sizeof(mat));
331 rc = IDirect3DDevice7_SetMaterial(lpD3DDevice, &mat);
332 ok(rc == D3D_OK, "IDirect3DDevice7_SetMaterial returned: %x\n", rc);
334 U4(mat).power = 129.0;
335 rc = IDirect3DDevice7_SetMaterial(lpD3DDevice, &mat);
336 ok(rc == D3D_OK, "IDirect3DDevice7_SetMaterial(power = 129.0) returned: %x\n", rc);
337 memset(&mat, 0, sizeof(mat));
338 rc = IDirect3DDevice7_GetMaterial(lpD3DDevice, &mat);
339 ok(rc == D3D_OK, "IDirect3DDevice7_GetMaterial returned: %x\n", rc);
340 ok(U4(mat).power == 129, "Returned power is %f\n", U4(mat).power);
342 U4(mat).power = -1.0;
343 rc = IDirect3DDevice7_SetMaterial(lpD3DDevice, &mat);
344 ok(rc == D3D_OK, "IDirect3DDevice7_SetMaterial(power = -1.0) returned: %x\n", rc);
345 memset(&mat, 0, sizeof(mat));
346 rc = IDirect3DDevice7_GetMaterial(lpD3DDevice, &mat);
347 ok(rc == D3D_OK, "IDirect3DDevice7_GetMaterial returned: %x\n", rc);
348 ok(U4(mat).power == -1, "Returned power is %f\n", U4(mat).power);
350 memset(&caps, 0, sizeof(caps));
351 rc = IDirect3DDevice7_GetCaps(lpD3DDevice, &caps);
352 ok(rc == D3D_OK, "IDirect3DDevice7_GetCaps failed with %x\n", rc);
354 for(i = 1; i <= caps.dwMaxActiveLights; i++) {
355 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, i, TRUE);
356 ok(rc == D3D_OK, "Enabling light %u failed with %x\n", i, rc);
357 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, i, &enabled);
358 ok(rc == D3D_OK, "GetLightEnable on light %u failed with %x\n", i, rc);
359 ok(enabled, "Light %d is %s\n", i, enabled ? "enabled" : "disabled");
362 /* TODO: Test the rendering results in this situation */
363 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, i + 1, TRUE);
364 ok(rc == D3D_OK, "Enabling one light more than supported returned %x\n", rc);
365 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, i + 1, &enabled);
366 ok(rc == D3D_OK, "GetLightEnable on light %u failed with %x\n", i + 1, rc);
367 ok(enabled, "Light %d is %s\n", i + 1, enabled ? "enabled" : "disabled");
368 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, i + 1, FALSE);
369 ok(rc == D3D_OK, "Disabling the additional returned %x\n", rc);
371 for(i = 1; i <= caps.dwMaxActiveLights; i++) {
372 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, i, FALSE);
373 ok(rc == D3D_OK, "Disabling light %u failed with %x\n", i, rc);
377 static void ProcessVerticesTest(void)
379 D3DVERTEXBUFFERDESC desc;
385 D3DMATRIX view = { 2.0, 0.0, 0.0, 0.0,
388 0.0, 0.0, 0.0, 3.0 };
390 D3DMATRIX world = { 0.0, 1.0, 0.0, 0.0,
393 0.0, 1.0, 1.0, 1.0 };
395 D3DMATRIX proj = { 1.0, 0.0, 0.0, 1.0,
398 1.0, 0.0, 0.0, 1.0 };
399 /* Create some vertex buffers */
401 memset(&desc, 0, sizeof(desc));
402 desc.dwSize = sizeof(desc);
404 desc.dwFVF = D3DFVF_XYZ;
405 desc.dwNumVertices = 16;
406 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufSrc, 0);
407 ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
410 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
414 memset(&desc, 0, sizeof(desc));
415 desc.dwSize = sizeof(desc);
417 desc.dwFVF = D3DFVF_XYZRHW;
418 desc.dwNumVertices = 16;
419 /* Msdn says that the last parameter must be 0 - check that */
420 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufDest1, 4);
421 ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
424 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
428 memset(&desc, 0, sizeof(desc));
429 desc.dwSize = sizeof(desc);
431 desc.dwFVF = D3DFVF_XYZ;
432 desc.dwNumVertices = 16;
433 /* Msdn says that the last parameter must be 0 - check that */
434 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufDest2, 12345678);
435 ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
438 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
442 rc = IDirect3DVertexBuffer7_Lock(lpVBufSrc, 0, (void **) &in, NULL);
443 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
446 /* Check basic transformation */
463 rc = IDirect3DVertexBuffer7_Unlock(lpVBufSrc);
464 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
466 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
467 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
469 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest2, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
470 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
472 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
473 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
476 /* Check the results */
477 ok( comparefloat(out[0].x, 128.0 ) &&
478 comparefloat(out[0].y, 128.0 ) &&
479 comparefloat(out[0].z, 0.0 ) &&
480 comparefloat(out[0].rhw, 1.0 ),
481 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
483 ok( comparefloat(out[1].x, 256.0 ) &&
484 comparefloat(out[1].y, 0.0 ) &&
485 comparefloat(out[1].z, 1.0 ) &&
486 comparefloat(out[1].rhw, 1.0 ),
487 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
489 ok( comparefloat(out[2].x, 0.0 ) &&
490 comparefloat(out[2].y, 256.0 ) &&
491 comparefloat(out[2].z, 0.5 ) &&
492 comparefloat(out[2].rhw, 1.0 ),
493 "Output 2 vertex is (%f , %f , %f , %f)\n", out[2].x, out[2].y, out[2].z, out[2].rhw);
495 ok( comparefloat(out[3].x, 192.0 ) &&
496 comparefloat(out[3].y, 192.0 ) &&
497 comparefloat(out[3].z, 0.25 ) &&
498 comparefloat(out[3].rhw, 1.0 ),
499 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
501 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
502 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
505 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest2, 0, (void **) &out2, NULL);
506 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
508 /* Small thing without much practial meaning, but I stumbled upon it,
509 * so let's check for it: If the output vertex buffer has to RHW value,
510 * The RHW value of the last vertex is written into the next vertex
512 ok( comparefloat(out2[4].x, 1.0 ) &&
513 comparefloat(out2[4].y, 0.0 ) &&
514 comparefloat(out2[4].z, 0.0 ),
515 "Output 4 vertex is (%f , %f , %f)\n", out2[4].x, out2[4].y, out2[4].z);
517 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest2);
518 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
521 /* Try a more complicated viewport, same vertices */
522 memset(&vp, 0, sizeof(vp));
529 rc = IDirect3DDevice7_SetViewport(lpD3DDevice, &vp);
530 ok(rc==D3D_OK, "IDirect3DDevice7_SetViewport failed with rc=%x\n", rc);
533 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
534 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
536 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
537 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
540 /* Check the results */
541 ok( comparefloat(out[0].x, 133.0 ) &&
542 comparefloat(out[0].y, 70.0 ) &&
543 comparefloat(out[0].z, -2.0 ) &&
544 comparefloat(out[0].rhw, 1.0 ),
545 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
547 ok( comparefloat(out[1].x, 256.0 ) &&
548 comparefloat(out[1].y, 5.0 ) &&
549 comparefloat(out[1].z, 4.0 ) &&
550 comparefloat(out[1].rhw, 1.0 ),
551 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
553 ok( comparefloat(out[2].x, 10.0 ) &&
554 comparefloat(out[2].y, 135.0 ) &&
555 comparefloat(out[2].z, 1.0 ) &&
556 comparefloat(out[2].rhw, 1.0 ),
557 "Output 2 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
559 ok( comparefloat(out[3].x, 194.5 ) &&
560 comparefloat(out[3].y, 102.5 ) &&
561 comparefloat(out[3].z, -0.5 ) &&
562 comparefloat(out[3].rhw, 1.0 ),
563 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
565 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
566 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
569 /* Play with some matrices. */
571 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_VIEW, &view);
572 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
574 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_PROJECTION, &proj);
575 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
577 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_WORLD, &world);
578 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
580 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
581 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
583 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
584 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
587 /* Keep the viewport simpler, otherwise we get bad numbers to compare */
594 rc = IDirect3DDevice7_SetViewport(lpD3DDevice, &vp);
595 ok(rc==D3D_OK, "IDirect3DDevice7_SetViewport failed\n");
597 /* Check the results */
598 ok( comparefloat(out[0].x, 256.0 ) && /* X coordinate is cut at the surface edges */
599 comparefloat(out[0].y, 70.0 ) &&
600 comparefloat(out[0].z, -2.0 ) &&
601 comparefloat(out[0].rhw, (1.0 / 3.0)),
602 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
604 ok( comparefloat(out[1].x, 256.0 ) &&
605 comparefloat(out[1].y, 78.125000 ) &&
606 comparefloat(out[1].z, -2.750000 ) &&
607 comparefloat(out[1].rhw, 0.125000 ),
608 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
610 ok( comparefloat(out[2].x, 256.0 ) &&
611 comparefloat(out[2].y, 44.000000 ) &&
612 comparefloat(out[2].z, 0.400000 ) &&
613 comparefloat(out[2].rhw, 0.400000 ),
614 "Output 2 vertex is (%f , %f , %f , %f)\n", out[2].x, out[2].y, out[2].z, out[2].rhw);
616 ok( comparefloat(out[3].x, 256.0 ) &&
617 comparefloat(out[3].y, 81.818184 ) &&
618 comparefloat(out[3].z, -3.090909 ) &&
619 comparefloat(out[3].rhw, 0.363636 ),
620 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
622 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
623 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
627 IDirect3DVertexBuffer7_Release(lpVBufSrc);
628 IDirect3DVertexBuffer7_Release(lpVBufDest1);
629 IDirect3DVertexBuffer7_Release(lpVBufDest2);
632 static void StateTest( void )
636 /* The msdn says its undocumented, does it return an error too? */
637 rc = IDirect3DDevice7_SetRenderState(lpD3DDevice, D3DRENDERSTATE_ZVISIBLE, TRUE);
638 ok(rc == D3D_OK, "IDirect3DDevice7_SetRenderState(D3DRENDERSTATE_ZVISIBLE, TRUE) returned %08x\n", rc);
639 rc = IDirect3DDevice7_SetRenderState(lpD3DDevice, D3DRENDERSTATE_ZVISIBLE, FALSE);
640 ok(rc == D3D_OK, "IDirect3DDevice7_SetRenderState(D3DRENDERSTATE_ZVISIBLE, FALSE) returned %08x\n", rc);
644 static void SceneTest(void)
648 /* Test an EndScene without beginscene. Should return an error */
649 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
650 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
652 /* Test a normal BeginScene / EndScene pair, this should work */
653 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
654 ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed with %08x\n", hr);
658 memset(&fx, 0, sizeof(fx));
659 fx.dwSize = sizeof(fx);
662 hr = IDirectDrawSurface7_Blt(lpDDSdepth, NULL, NULL, NULL, DDBLT_DEPTHFILL, &fx);
663 ok(hr == D3D_OK, "Depthfill failed in a BeginScene / EndScene pair\n");
665 skip("Depth stencil creation failed at startup, skipping\n");
667 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
668 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed with %08x\n", hr);
671 /* Test another EndScene without having begun a new scene. Should return an error */
672 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
673 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
675 /* Two nested BeginScene and EndScene calls */
676 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
677 ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed with %08x\n", hr);
678 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
679 ok(hr == D3DERR_SCENE_IN_SCENE, "IDirect3DDevice7_BeginScene returned %08x\n", hr);
680 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
681 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed with %08x\n", hr);
682 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
683 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
685 /* TODO: Verify that blitting works in the same way as in d3d9 */
688 static void LimitTest(void)
690 IDirectDrawSurface7 *pTexture = NULL;
695 memset(&ddsd, 0, sizeof(ddsd));
696 ddsd.dwSize = sizeof(ddsd);
697 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
698 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
701 hr = IDirectDraw7_CreateSurface(lpDD, &ddsd, &pTexture, NULL);
702 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
703 if(!pTexture) return;
705 for(i = 0; i < 8; i++) {
706 hr = IDirect3DDevice7_SetTexture(lpD3DDevice, i, pTexture);
707 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %08x\n", i, hr);
708 hr = IDirect3DDevice7_SetTexture(lpD3DDevice, i, NULL);
709 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %08x\n", i, hr);
710 hr = IDirect3DDevice7_SetTextureStageState(lpD3DDevice, i, D3DTSS_COLOROP, D3DTOP_ADD);
711 ok(hr == D3D_OK, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %08x\n", i, hr);
714 IDirectDrawSurface7_Release(pTexture);
717 static HRESULT WINAPI enumDevicesCallback(GUID *Guid,LPSTR DeviceDescription,LPSTR DeviceName, D3DDEVICEDESC *hal, D3DDEVICEDESC *hel, VOID *ctx)
719 UINT ver = *((UINT *) ctx);
720 if(IsEqualGUID(&IID_IDirect3DRGBDevice, Guid))
722 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
723 "RGB Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
724 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
725 "RGB Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
726 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
727 "RGB Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
728 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
729 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
731 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
732 "RGB Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
733 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
734 "RGB Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
735 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
736 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
737 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
738 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
740 else if(IsEqualGUID(&IID_IDirect3DHALDevice, Guid))
742 /* pow2 is hardware dependent */
744 ok(hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
745 "HAL Device %d hal line caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
746 ok(hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
747 "HAL Device %d hal tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
748 ok((hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
749 "HAL Device %d hel line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
750 ok((hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
751 "HAL Device %d hel tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
753 else if(IsEqualGUID(&IID_IDirect3DRefDevice, Guid))
755 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
756 "REF Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
757 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
758 "REF Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
759 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
760 "REF Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
761 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
762 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
764 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
765 "REF Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
766 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
767 "REF Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
768 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
769 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
770 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
771 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
773 else if(IsEqualGUID(&IID_IDirect3DRampDevice, Guid))
775 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
776 "Ramp Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
777 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
778 "Ramp Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
779 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
780 "Ramp Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
781 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
782 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
784 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
785 "Ramp Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
786 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
787 "Ramp Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
788 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
789 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
790 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
791 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
793 else if(IsEqualGUID(&IID_IDirect3DMMXDevice, Guid))
795 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
796 "MMX Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
797 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
798 "MMX Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
799 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
800 "MMX Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
801 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
802 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
804 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
805 "MMX Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
806 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
807 "MMX Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
808 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
809 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
810 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
811 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
815 ok(FALSE, "Unexpected device enumerated: \"%s\" \"%s\"\n", DeviceDescription, DeviceName);
816 if(hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hal line has pow2 set\n");
817 else trace("hal line does NOT have pow2 set\n");
818 if(hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hal tri has pow2 set\n");
819 else trace("hal tri does NOT have pow2 set\n");
820 if(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hel line has pow2 set\n");
821 else trace("hel line does NOT have pow2 set\n");
822 if(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hel tri has pow2 set\n");
823 else trace("hel tri does NOT have pow2 set\n");
828 static HRESULT WINAPI enumDevicesCallbackTest7(LPSTR DeviceDescription, LPSTR DeviceName, LPD3DDEVICEDESC7 lpdd7, LPVOID Context)
830 D3D7ETest *d3d7et = (D3D7ETest*)Context;
831 if(IsEqualGUID(&lpdd7->deviceGUID, &IID_IDirect3DRGBDevice))
833 else if(IsEqualGUID(&lpdd7->deviceGUID, &IID_IDirect3DHALDevice))
835 else if(IsEqualGUID(&lpdd7->deviceGUID, &IID_IDirect3DTnLHalDevice))
846 /* Check the deviceGUID of devices enumerated by
847 IDirect3D7_EnumDevices. */
848 static void D3D7EnumTest(void)
853 skip("No Direct3D7 interface.\n");
857 memset(&d3d7et, 0, sizeof(d3d7et));
858 IDirect3D7_EnumDevices(lpD3D, enumDevicesCallbackTest7, (LPVOID) &d3d7et);
861 /* A couple of games (Delta Force LW and TFD) rely on this behaviour */
862 ok(d3d7et.tnlhal < d3d7et.total, "TnLHal device enumerated as only device.\n");
864 /* We make two additional assumptions. */
865 ok(d3d7et.rgb, "No RGB Device enumerated.\n");
868 ok(d3d7et.hal, "TnLHal device enumerated, but no Hal device found.\n");
873 static void CapsTest(void)
881 hr = DirectDrawCreate(NULL, &dd1, NULL);
882 ok(hr == DD_OK, "Cannot create a DirectDraw 1 interface, hr = %08x\n", hr);
883 hr = IDirectDraw_QueryInterface(dd1, &IID_IDirect3D3, (void **) &d3d3);
884 ok(hr == D3D_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
886 IDirect3D3_EnumDevices(d3d3, enumDevicesCallback, &ver);
888 IDirect3D3_Release(d3d3);
889 IDirectDraw_Release(dd1);
891 hr = DirectDrawCreate(NULL, &dd1, NULL);
892 ok(hr == DD_OK, "Cannot create a DirectDraw 1 interface, hr = %08x\n", hr);
893 hr = IDirectDraw_QueryInterface(dd1, &IID_IDirect3D2, (void **) &d3d2);
894 ok(hr == D3D_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
896 IDirect3D2_EnumDevices(d3d2, enumDevicesCallback, &ver);
898 IDirect3D2_Release(d3d2);
899 IDirectDraw_Release(dd1);
909 static void Direct3D1Test(void)
911 IDirect3DDevice *dev1 = NULL;
914 IDirectDrawSurface *dds;
915 IDirect3DExecuteBuffer *exebuf;
916 IDirect3DViewport *vp;
919 D3DEXECUTEBUFFERDESC desc;
921 D3DINSTRUCTION *instr;
923 unsigned int idx = 0;
924 static struct v_in testverts[] = {
925 {0.0, 0.0, 0.0}, { 1.0, 1.0, 1.0}, {-1.0, -1.0, -1.0},
926 {0.5, 0.5, 0.5}, {-0.5, -0.5, -0.5}, {-0.5, -0.5, 0.0},
928 static struct v_in cliptest[] = {
929 {25.59, 25.59, 1.0}, {-25.59, -25.59, 0.0},
930 {25.61, 25.61, 1.01}, {-25.61, -25.61, -0.01},
932 static struct v_in offscreentest[] = {
935 struct v_out out[sizeof(testverts) / sizeof(testverts[0])];
936 D3DHVERTEX outH[sizeof(testverts) / sizeof(testverts[0])];
937 D3DTRANSFORMDATA transformdata;
940 /* An IDirect3DDevice cannot be queryInterfaced from an IDirect3DDevice7 on windows */
941 hr = DirectDrawCreate(NULL, &dd, NULL);
942 ok(hr==DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreate returned: %x\n", hr);
944 trace("DirectDrawCreate() failed with an error %x\n", hr);
948 hr = IDirectDraw_SetCooperativeLevel(dd, NULL, DDSCL_NORMAL);
949 ok(hr==DD_OK, "SetCooperativeLevel returned: %x\n", hr);
951 hr = IDirectDraw_QueryInterface(dd, &IID_IDirect3D, (void**) &d3d);
952 ok(hr==DD_OK, "QueryInterface returned: %x\n", hr);
954 memset(&ddsd, 0, sizeof(ddsd));
955 ddsd.dwSize = sizeof(ddsd);
956 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
957 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
960 hr = IDirectDraw_CreateSurface(dd, &ddsd, &dds, NULL);
961 ok(hr==DD_OK, "CreateSurface returned: %x\n", hr);
964 hr = IDirectDrawSurface_QueryInterface(dds, &IID_IDirect3DRGBDevice, (void **) &dev1);
965 ok(hr==D3D_OK || hr==DDERR_NOPALETTEATTACHED || hr==E_OUTOFMEMORY, "CreateDevice returned: %x\n", hr);
968 memset(&desc, 0, sizeof(desc));
969 desc.dwSize = sizeof(desc);
970 desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
971 desc.dwCaps = D3DDEBCAPS_VIDEOMEMORY;
972 desc.dwBufferSize = 128;
974 hr = IDirect3DDevice_CreateExecuteBuffer(dev1, &desc, &exebuf, NULL);
975 ok(hr == D3D_OK, "IDirect3DDevice_CreateExecuteBuffer failed: %08x\n", hr);
977 memset(&desc, 0, sizeof(desc));
978 desc.dwSize = sizeof(desc);
980 hr = IDirect3DExecuteBuffer_Lock(exebuf, &desc);
981 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Lock failed: %08x\n", hr);
983 instr[idx].bOpcode = D3DOP_BRANCHFORWARD;
984 instr[idx].bSize = sizeof(*branch);
985 instr[idx].wCount = 1;
987 branch = (D3DBRANCH *) &instr[idx];
988 branch->dwMask = 0x0;
990 branch->bNegate = TRUE;
991 branch->dwOffset = 0;
992 idx += (sizeof(*branch) / sizeof(*instr));
993 instr[idx].bOpcode = D3DOP_EXIT;
994 instr[idx].bSize = 0;
995 instr[idx].bSize = 0;
996 hr = IDirect3DExecuteBuffer_Unlock(exebuf);
997 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Unlock failed: %08x\n", hr);
999 hr = IDirect3D_CreateViewport(d3d, &vp, NULL);
1000 ok(hr == D3D_OK, "IDirect3D_CreateViewport failed: %08x\n", hr);
1001 hr = IDirect3DViewport_Initialize(vp, d3d);
1002 ok(hr == DDERR_ALREADYINITIALIZED, "IDirect3DViewport_Initialize returned %08x\n", hr);
1004 hr = IDirect3DDevice_AddViewport(dev1, vp);
1005 ok(hr == D3D_OK, "IDirect3DDevice_AddViewport returned %08x\n", hr);
1006 vp_data.dwSize = sizeof(vp_data);
1009 vp_data.dwWidth = 256;
1010 vp_data.dwHeight = 256;
1011 vp_data.dvScaleX = 1;
1012 vp_data.dvScaleY = 1;
1013 vp_data.dvMaxX = 256;
1014 vp_data.dvMaxY = 256;
1017 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1018 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1020 hr = IDirect3DDevice_Execute(dev1, exebuf, vp, D3DEXECUTE_CLIPPED);
1021 ok(hr == D3D_OK, "IDirect3DDevice_Execute returned %08x\n", hr);
1023 memset(&transformdata, 0, sizeof(transformdata));
1024 transformdata.dwSize = sizeof(transformdata);
1025 transformdata.lpIn = (void *) testverts;
1026 transformdata.dwInSize = sizeof(testverts[0]);
1027 transformdata.lpOut = out;
1028 transformdata.dwOutSize = sizeof(out[0]);
1030 transformdata.lpHOut = NULL;
1031 hr = IDirect3DViewport_TransformVertices(vp, sizeof(testverts) / sizeof(testverts[0]),
1032 &transformdata, D3DTRANSFORM_UNCLIPPED,
1034 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1036 transformdata.lpHOut = outH;
1037 memset(outH, 0xaa, sizeof(outH));
1038 hr = IDirect3DViewport_TransformVertices(vp, sizeof(testverts) / sizeof(testverts[0]),
1039 &transformdata, D3DTRANSFORM_UNCLIPPED,
1041 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1042 ok(i == 0, "Offscreen is %d\n", i);
1044 for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
1045 static const struct v_out cmp[] = {
1046 {128.0, 128.0, 0.0, 1}, {129.0, 127.0, 1.0, 1}, {127.0, 129.0, -1, 1},
1047 {128.5, 127.5, 0.5, 1}, {127.5, 128.5, -0.5, 1}, {127.5, 128.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);
1056 for(i = 0; i < sizeof(outH); i++) {
1057 if(((unsigned char *) outH)[i] != 0xaa) {
1058 ok(FALSE, "Homogeneous output was generated despite UNCLIPPED flag\n");
1063 vp_data.dvScaleX = 5;
1064 vp_data.dvScaleY = 5;
1065 vp_data.dvMinZ = -25;
1066 vp_data.dvMaxZ = 60;
1067 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1068 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1069 hr = IDirect3DViewport_TransformVertices(vp, sizeof(testverts) / sizeof(testverts[0]),
1070 &transformdata, D3DTRANSFORM_UNCLIPPED,
1072 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1073 ok(i == 0, "Offscreen is %d\n", i);
1074 for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
1075 static const struct v_out cmp[] = {
1076 {128.0, 128.0, 0.0, 1}, {133.0, 123.0, 1.0, 1}, {123.0, 133.0, -1, 1},
1077 {130.5, 125.5, 0.5, 1}, {125.5, 130.5, -0.5, 1}, {125.5, 130.5, 0, 1}
1079 ok(cmp[i].x == out[i].x && cmp[i].y == out[i].y &&
1080 cmp[i].z == out[i].z && cmp[i].rhw == out[i].rhw,
1081 "Vertex %d differs. Got %f %f %f %f, expexted %f %f %f %f\n", i + 1,
1082 out[i].x, out[i].y, out[i].z, out[i].rhw,
1083 cmp[i].x, cmp[i].y, cmp[i].z, cmp[i].rhw);
1088 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1089 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1090 hr = IDirect3DViewport_TransformVertices(vp, sizeof(testverts) / sizeof(testverts[0]),
1091 &transformdata, D3DTRANSFORM_UNCLIPPED,
1093 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1094 ok(i == 0, "Offscreen is %d\n", i);
1095 for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
1096 static const struct v_out cmp[] = {
1097 {138.0, 148.0, 0.0, 1}, {143.0, 143.0, 1.0, 1}, {133.0, 153.0, -1, 1},
1098 {140.5, 145.5, 0.5, 1}, {135.5, 150.5, -0.5, 1}, {135.5, 150.5, 0, 1}
1100 ok(cmp[i].x == out[i].x && cmp[i].y == out[i].y &&
1101 cmp[i].z == out[i].z && cmp[i].rhw == out[i].rhw,
1102 "Vertex %d differs. Got %f %f %f %f, expexted %f %f %f %f\n", i + 1,
1103 out[i].x, out[i].y, out[i].z, out[i].rhw,
1104 cmp[i].x, cmp[i].y, cmp[i].z, cmp[i].rhw);
1107 memset(out, 0xbb, sizeof(out));
1108 hr = IDirect3DViewport_TransformVertices(vp, sizeof(testverts) / sizeof(testverts[0]),
1109 &transformdata, D3DTRANSFORM_CLIPPED,
1111 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1112 ok(i == 0, "Offscreen is %d\n", i);
1113 for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
1114 static const D3DHVERTEX cmpH[] = {
1115 {0, { 0.0}, { 0.0}, { 0.0}}, {0, { 1.0}, { 1.0}, {1.0}},
1116 {D3DCLIP_FRONT, {-1.0}, {-1.0}, {-1.0}}, {0, { 0.5}, { 0.5}, {0.5}},
1117 {D3DCLIP_FRONT, {-0.5}, {-0.5}, {-0.5}}, {0, {-0.5}, {-0.5}, {0.0}}
1119 ok(U1(cmpH[i]).hx == U1(outH[i]).hx && U2(cmpH[i]).hy == U2(outH[i]).hy &&
1120 U3(cmpH[i]).hz == U3(outH[i]).hz && cmpH[i].dwFlags == outH[i].dwFlags,
1121 "HVertex %d differs. Got %08x %f %f %f, expexted %08x %f %f %f\n", i + 1,
1122 outH[i].dwFlags, U1(outH[i]).hx, U2(outH[i]).hy, U3(outH[i]).hz,
1123 cmpH[i].dwFlags, U1(cmpH[i]).hx, U2(cmpH[i]).hy, U3(cmpH[i]).hz);
1125 /* No scheme has been found behind those return values. It seems to be
1126 * whatever data windows has when throwing the vertex away. Modify the
1127 * input test vertices to test this more. Depending on the input data
1128 * it can happen that the z coord gets written into y, or similar things
1132 static const struct v_out cmp[] = {
1133 {138.0, 148.0, 0.0, 1}, {143.0, 143.0, 1.0, 1}, { -1.0, -1.0, 0.5, 1},
1134 {140.5, 145.5, 0.5, 1}, { -0.5, -0.5, -0.5, 1}, {135.5, 150.5, 0.0, 1}
1136 ok(cmp[i].x == out[i].x && cmp[i].y == out[i].y &&
1137 cmp[i].z == out[i].z && cmp[i].rhw == out[i].rhw,
1138 "Vertex %d differs. Got %f %f %f %f, expexted %f %f %f %f\n", i + 1,
1139 out[i].x, out[i].y, out[i].z, out[i].rhw,
1140 cmp[i].x, cmp[i].y, cmp[i].z, cmp[i].rhw);
1143 for(i = 0; i < sizeof(out) / sizeof(DWORD); i++) {
1144 ok(((DWORD *) out)[i] != 0xbbbbbbbb,
1145 "Regular output DWORD %d remained untouched\n", i);
1148 transformdata.lpIn = (void *) cliptest;
1149 transformdata.dwInSize = sizeof(cliptest[0]);
1150 hr = IDirect3DViewport_TransformVertices(vp, sizeof(cliptest) / sizeof(cliptest[0]),
1151 &transformdata, D3DTRANSFORM_CLIPPED,
1153 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1154 ok(i == 0, "Offscreen is %d\n", i);
1155 for(i = 0; i < sizeof(cliptest) / sizeof(cliptest[0]); i++) {
1156 DWORD Flags[sizeof(cliptest) / sizeof(cliptest[0])] =
1160 D3DCLIP_RIGHT | D3DCLIP_BACK | D3DCLIP_TOP,
1161 D3DCLIP_LEFT | D3DCLIP_BOTTOM | D3DCLIP_FRONT,
1163 ok(Flags[i] == outH[i].dwFlags,
1164 "Cliptest %d differs. Got %08x expexted %08x\n", i + 1,
1165 outH[i].dwFlags, Flags[i]);
1168 vp_data.dwWidth = 10;
1169 vp_data.dwHeight = 1000;
1170 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1172 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1173 hr = IDirect3DViewport_TransformVertices(vp, sizeof(cliptest) / sizeof(cliptest[0]),
1174 &transformdata, D3DTRANSFORM_CLIPPED,
1176 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1177 ok(i == 0, "Offscreen is %d\n", i);
1178 for(i = 0; i < sizeof(cliptest) / sizeof(cliptest[0]); i++) {
1179 DWORD Flags[sizeof(cliptest) / sizeof(cliptest[0])] =
1183 D3DCLIP_RIGHT | D3DCLIP_BACK,
1184 D3DCLIP_LEFT | D3DCLIP_FRONT,
1186 ok(Flags[i] == outH[i].dwFlags,
1187 "Cliptest %d differs. Got %08x expexted %08x\n", i + 1,
1188 outH[i].dwFlags, Flags[i]);
1190 vp_data.dwWidth = 256;
1191 vp_data.dwHeight = 256;
1192 vp_data.dvScaleX = 1;
1193 vp_data.dvScaleY = 1;
1194 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1195 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1196 hr = IDirect3DViewport_TransformVertices(vp, sizeof(cliptest) / sizeof(cliptest[0]),
1197 &transformdata, D3DTRANSFORM_CLIPPED,
1199 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1200 ok(i == 0, "Offscreen is %s\n", i ? "TRUE" : "FALSE");
1201 for(i = 0; i < sizeof(cliptest) / sizeof(cliptest[0]); i++) {
1202 DWORD Flags[sizeof(cliptest) / sizeof(cliptest[0])] =
1209 ok(Flags[i] == outH[i].dwFlags,
1210 "Cliptest %d differs. Got %08x expexted %08x\n", i + 1,
1211 outH[i].dwFlags, Flags[i]);
1214 /* Finally try to figure out how the DWORD dwOffscreen works.
1215 * Apparently no vertex is offscreen with clipping off,
1216 * and with clipping on the offscreen flag is set if only one vertex
1217 * is transformed, and this vertex is offscreen.
1219 vp_data.dwWidth = 5;
1220 vp_data.dwHeight = 5;
1221 vp_data.dvScaleX = 10000;
1222 vp_data.dvScaleY = 10000;
1223 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1224 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1225 transformdata.lpIn = cliptest;
1226 hr = IDirect3DViewport_TransformVertices(vp, 1,
1227 &transformdata, D3DTRANSFORM_UNCLIPPED,
1229 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1230 ok(i == 0, "Offscreen is %d\n", i);
1231 hr = IDirect3DViewport_TransformVertices(vp, 1,
1232 &transformdata, D3DTRANSFORM_CLIPPED,
1234 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1235 ok(i == (D3DCLIP_RIGHT | D3DCLIP_TOP), "Offscreen is %d\n", i);
1236 hr = IDirect3DViewport_TransformVertices(vp, 2,
1237 &transformdata, D3DTRANSFORM_CLIPPED,
1239 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1240 ok(i == 0, "Offscreen is %d\n", i);
1241 transformdata.lpIn = cliptest + 1;
1242 hr = IDirect3DViewport_TransformVertices(vp, 1,
1243 &transformdata, D3DTRANSFORM_CLIPPED,
1245 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1246 ok(i == (D3DCLIP_BOTTOM | D3DCLIP_LEFT), "Offscreen is %d\n", i);
1248 transformdata.lpIn = (void *) offscreentest;
1249 transformdata.dwInSize = sizeof(offscreentest[0]);
1250 vp_data.dwWidth = 257;
1251 vp_data.dwHeight = 257;
1252 vp_data.dvScaleX = 1;
1253 vp_data.dvScaleY = 1;
1254 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1256 hr = IDirect3DViewport_TransformVertices(vp, sizeof(offscreentest) / sizeof(offscreentest[0]),
1257 &transformdata, D3DTRANSFORM_CLIPPED,
1259 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1260 ok(i == 0, "Offscreen is %d\n", i);
1261 vp_data.dwWidth = 256;
1262 vp_data.dwHeight = 256;
1263 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1265 hr = IDirect3DViewport_TransformVertices(vp, sizeof(offscreentest) / sizeof(offscreentest[0]),
1266 &transformdata, D3DTRANSFORM_CLIPPED,
1268 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1269 ok(i == D3DCLIP_RIGHT, "Offscreen is %d\n", i);
1271 hr = IDirect3DViewport_TransformVertices(vp, sizeof(testverts) / sizeof(testverts[0]),
1274 ok(hr == DDERR_INVALIDPARAMS, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1276 hr = IDirect3DDevice_DeleteViewport(dev1, vp);
1277 ok(hr == D3D_OK, "IDirect3DDevice_DeleteViewport returned %08x\n", hr);
1279 IDirect3DViewport_Release(vp);
1280 IDirect3DExecuteBuffer_Release(exebuf);
1281 IDirect3DDevice_Release(dev1);
1282 IDirectDrawSurface_Release(dds);
1283 IDirect3D_Release(d3d);
1284 IDirectDraw_Release(dd);
1290 init_function_pointers();
1291 if(!pDirectDrawCreateEx) {
1292 skip("function DirectDrawCreateEx not available\n");
1296 if(!CreateDirect3D()) {
1297 trace("Skipping tests\n");
1301 ProcessVerticesTest();