2 * Some unit tests for d3d functions
4 * Copyright (C) 2005 Antoine Chavasse
5 * Copyright (C) 2006 Stefan Dösinger for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/test.h"
27 static LPDIRECTDRAW7 lpDD = NULL;
28 static LPDIRECT3D7 lpD3D = NULL;
29 static LPDIRECTDRAWSURFACE7 lpDDS = NULL;
30 static LPDIRECTDRAWSURFACE7 lpDDSdepth = NULL;
31 static LPDIRECT3DDEVICE7 lpD3DDevice = NULL;
32 static LPDIRECT3DVERTEXBUFFER7 lpVBufSrc = NULL;
33 static LPDIRECT3DVERTEXBUFFER7 lpVBufDest1 = NULL;
34 static LPDIRECT3DVERTEXBUFFER7 lpVBufDest2 = NULL;
36 /* To compare bad floating point numbers. Not the ideal way to do it,
37 * but it should be enough for here */
38 #define comparefloat(a, b) ( (((a) - (b)) < 0.0001) && (((a) - (b)) > -0.0001) )
40 static HRESULT (WINAPI *pDirectDrawCreateEx)(LPGUID,LPVOID*,REFIID,LPUNKNOWN);
42 typedef struct _VERTEX
44 float x, y, z; /* position */
47 typedef struct _TVERTEX
49 float x, y, z; /* position */
51 } TVERTEX, *LPTVERTEX;
54 static void init_function_pointers(void)
56 HMODULE hmod = GetModuleHandleA("ddraw.dll");
57 pDirectDrawCreateEx = (void*)GetProcAddress(hmod, "DirectDrawCreateEx");
61 static BOOL CreateDirect3D(void)
66 rc = pDirectDrawCreateEx(NULL, (void**)&lpDD,
67 &IID_IDirectDraw7, NULL);
68 ok(rc==DD_OK || rc==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", rc);
70 trace("DirectDrawCreateEx() failed with an error %x\n", rc);
74 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
75 ok(rc==DD_OK, "SetCooperativeLevel returned: %x\n", rc);
77 rc = IDirectDraw7_QueryInterface(lpDD, &IID_IDirect3D7, (void**) &lpD3D);
78 if (rc == E_NOINTERFACE) return FALSE;
79 ok(rc==DD_OK, "QueryInterface returned: %x\n", rc);
81 memset(&ddsd, 0, sizeof(ddsd));
82 ddsd.dwSize = sizeof(ddsd);
83 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
84 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
87 rc = IDirectDraw7_CreateSurface(lpDD, &ddsd, &lpDDS, NULL);
88 ok(rc==DD_OK, "CreateSurface returned: %x\n", rc);
92 memset(&ddsd, 0, sizeof(ddsd));
93 ddsd.dwSize = sizeof(ddsd);
94 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
95 ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
96 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
97 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
98 U1(U4(ddsd).ddpfPixelFormat).dwZBufferBitDepth = 16;
99 U3(U4(ddsd).ddpfPixelFormat).dwZBitMask = 0x0000FFFF;
102 rc = IDirectDraw7_CreateSurface(lpDD, &ddsd, &lpDDSdepth, NULL);
103 ok(rc==DD_OK, "CreateSurface returned: %x\n", rc);
104 if (!SUCCEEDED(rc)) {
107 rc = IDirectDrawSurface_AddAttachedSurface(lpDDS, lpDDSdepth);
108 ok(rc == DD_OK, "IDirectDrawSurface_AddAttachedSurface returned %x\n", rc);
113 rc = IDirect3D7_CreateDevice(lpD3D, &IID_IDirect3DTnLHalDevice, lpDDS,
115 ok(rc==D3D_OK || rc==DDERR_NOPALETTEATTACHED || rc==E_OUTOFMEMORY, "CreateDevice returned: %x\n", rc);
117 trace("IDirect3D7::CreateDevice() for a TnL Hal device failed with an error %x, trying HAL\n", rc);
118 rc = IDirect3D7_CreateDevice(lpD3D, &IID_IDirect3DHALDevice, lpDDS,
121 trace("IDirect3D7::CreateDevice() for a HAL device failed with an error %x, trying RGB\n", rc);
122 rc = IDirect3D7_CreateDevice(lpD3D, &IID_IDirect3DRGBDevice, lpDDS,
125 trace("IDirect3D7::CreateDevice() for a RGB device failed with an error %x, giving up\n", rc);
134 static void ReleaseDirect3D(void)
136 if (lpD3DDevice != NULL)
138 IDirect3DDevice7_Release(lpD3DDevice);
142 if (lpDDSdepth != NULL)
144 IDirectDrawSurface_Release(lpDDSdepth);
150 IDirectDrawSurface_Release(lpDDS);
156 IDirect3D7_Release(lpD3D);
162 IDirectDraw_Release(lpDD);
167 static void LightTest(void)
171 D3DLIGHT7 defaultlight;
172 BOOL bEnabled = FALSE;
177 /* Set a few lights with funky indices. */
178 memset(&light, 0, sizeof(light));
179 light.dltType = D3DLIGHT_DIRECTIONAL;
180 U1(light.dcvDiffuse).r = 0.5f;
181 U2(light.dcvDiffuse).g = 0.6f;
182 U3(light.dcvDiffuse).b = 0.7f;
183 U2(light.dvDirection).y = 1.f;
185 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 5, &light);
186 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
187 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 10, &light);
188 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
189 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 45, &light);
190 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
193 /* Try to retrieve a light beyond the indices of the lights that have
195 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
196 ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %x\n", rc);
197 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 2, &light);
198 ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %x\n", rc);
201 /* Try to retrieve one of the lights that have been set */
202 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 10, &light);
203 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
206 /* Enable a light that have been previously set. */
207 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 10, TRUE);
208 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
211 /* Enable some lights that have not been previously set, and verify that
212 they have been initialized with proper default values. */
213 memset(&defaultlight, 0, sizeof(D3DLIGHT7));
214 defaultlight.dltType = D3DLIGHT_DIRECTIONAL;
215 U1(defaultlight.dcvDiffuse).r = 1.f;
216 U2(defaultlight.dcvDiffuse).g = 1.f;
217 U3(defaultlight.dcvDiffuse).b = 1.f;
218 U3(defaultlight.dvDirection).z = 1.f;
220 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, TRUE);
221 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
222 memset(&light, 0, sizeof(D3DLIGHT7));
223 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 20, &light);
224 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
225 ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
226 "light data doesn't match expected default values\n" );
228 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 50, TRUE);
229 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
230 memset(&light, 0, sizeof(D3DLIGHT7));
231 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
232 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
233 ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
234 "light data doesn't match expected default values\n" );
237 /* Disable one of the light that have been previously enabled. */
238 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, FALSE);
239 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
241 /* Try to retrieve the enable status of some lights */
242 /* Light 20 is supposed to be disabled */
243 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 20, &bEnabled );
244 ok(rc==D3D_OK, "GetLightEnable returned: %x\n", rc);
245 ok(!bEnabled, "GetLightEnable says the light is enabled\n");
247 /* Light 10 is supposed to be enabled */
249 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 10, &bEnabled );
250 ok(rc==D3D_OK, "GetLightEnable returned: %x\n", rc);
251 ok(bEnabled, "GetLightEnable says the light is disabled\n");
253 /* Light 80 has not been set */
254 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 80, &bEnabled );
255 ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %x\n", rc);
257 /* Light 23 has not been set */
258 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 23, &bEnabled );
259 ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %x\n", rc);
261 /* Set some lights with invalid parameters */
262 memset(&light, 0, sizeof(D3DLIGHT7));
264 U1(light.dcvDiffuse).r = 1.f;
265 U2(light.dcvDiffuse).g = 1.f;
266 U3(light.dcvDiffuse).b = 1.f;
267 U3(light.dvDirection).z = 1.f;
268 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 100, &light);
269 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
271 memset(&light, 0, sizeof(D3DLIGHT7));
272 light.dltType = 12345;
273 U1(light.dcvDiffuse).r = 1.f;
274 U2(light.dcvDiffuse).g = 1.f;
275 U3(light.dcvDiffuse).b = 1.f;
276 U3(light.dvDirection).z = 1.f;
277 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 101, &light);
278 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
280 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 102, NULL);
281 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
283 memset(&light, 0, sizeof(D3DLIGHT7));
284 light.dltType = D3DLIGHT_SPOT;
285 U1(light.dcvDiffuse).r = 1.f;
286 U2(light.dcvDiffuse).g = 1.f;
287 U3(light.dcvDiffuse).b = 1.f;
288 U3(light.dvDirection).z = 1.f;
290 light.dvAttenuation0 = -one / zero; /* -INFINITY */
291 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
292 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
294 light.dvAttenuation0 = -1.0;
295 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
296 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
298 light.dvAttenuation0 = 0.0;
299 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
300 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
302 light.dvAttenuation0 = 1.0;
303 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
304 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
306 light.dvAttenuation0 = one / zero; /* +INFINITY */
307 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
308 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
310 light.dvAttenuation0 = zero / zero; /* NaN */
311 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
312 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
314 /* Directional light ignores attenuation */
315 light.dltType = D3DLIGHT_DIRECTIONAL;
316 light.dvAttenuation0 = -1.0;
317 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
318 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
320 memset(&mat, 0, sizeof(mat));
321 rc = IDirect3DDevice7_SetMaterial(lpD3DDevice, &mat);
322 ok(rc == D3D_OK, "IDirect3DDevice7_SetMaterial returned: %x\n", rc);
324 U4(mat).power = 129.0;
325 rc = IDirect3DDevice7_SetMaterial(lpD3DDevice, &mat);
326 ok(rc == D3D_OK, "IDirect3DDevice7_SetMaterial(power = 129.0) returned: %x\n", rc);
327 memset(&mat, 0, sizeof(mat));
328 rc = IDirect3DDevice7_GetMaterial(lpD3DDevice, &mat);
329 ok(rc == D3D_OK, "IDirect3DDevice7_GetMaterial returned: %x\n", rc);
330 ok(U4(mat).power == 129, "Returned power is %f\n", U4(mat).power);
332 U4(mat).power = -1.0;
333 rc = IDirect3DDevice7_SetMaterial(lpD3DDevice, &mat);
334 ok(rc == D3D_OK, "IDirect3DDevice7_SetMaterial(power = -1.0) returned: %x\n", rc);
335 memset(&mat, 0, sizeof(mat));
336 rc = IDirect3DDevice7_GetMaterial(lpD3DDevice, &mat);
337 ok(rc == D3D_OK, "IDirect3DDevice7_GetMaterial returned: %x\n", rc);
338 ok(U4(mat).power == -1, "Returned power is %f\n", U4(mat).power);
341 static void ProcessVerticesTest(void)
343 D3DVERTEXBUFFERDESC desc;
349 D3DMATRIX view = { 2.0, 0.0, 0.0, 0.0,
352 0.0, 0.0, 0.0, 3.0 };
354 D3DMATRIX world = { 0.0, 1.0, 0.0, 0.0,
357 0.0, 1.0, 1.0, 1.0 };
359 D3DMATRIX proj = { 1.0, 0.0, 0.0, 1.0,
362 1.0, 0.0, 0.0, 1.0 };
363 /* Create some vertex buffers */
365 memset(&desc, 0, sizeof(desc));
366 desc.dwSize = sizeof(desc);
368 desc.dwFVF = D3DFVF_XYZ;
369 desc.dwNumVertices = 16;
370 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufSrc, 0);
371 ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
374 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
378 memset(&desc, 0, sizeof(desc));
379 desc.dwSize = sizeof(desc);
381 desc.dwFVF = D3DFVF_XYZRHW;
382 desc.dwNumVertices = 16;
383 /* Msdn says that the last parameter must be 0 - check that */
384 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufDest1, 4);
385 ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
388 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
392 memset(&desc, 0, sizeof(desc));
393 desc.dwSize = sizeof(desc);
395 desc.dwFVF = D3DFVF_XYZ;
396 desc.dwNumVertices = 16;
397 /* Msdn says that the last parameter must be 0 - check that */
398 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufDest2, 12345678);
399 ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
402 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
406 rc = IDirect3DVertexBuffer7_Lock(lpVBufSrc, 0, (void **) &in, NULL);
407 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
410 /* Check basic transformation */
427 rc = IDirect3DVertexBuffer7_Unlock(lpVBufSrc);
428 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
430 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
431 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
433 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest2, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
434 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
436 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
437 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
440 /* Check the results */
441 ok( comparefloat(out[0].x, 128.0 ) &&
442 comparefloat(out[0].y, 128.0 ) &&
443 comparefloat(out[0].z, 0.0 ) &&
444 comparefloat(out[0].rhw, 1.0 ),
445 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
447 ok( comparefloat(out[1].x, 256.0 ) &&
448 comparefloat(out[1].y, 0.0 ) &&
449 comparefloat(out[1].z, 1.0 ) &&
450 comparefloat(out[1].rhw, 1.0 ),
451 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
453 ok( comparefloat(out[2].x, 0.0 ) &&
454 comparefloat(out[2].y, 256.0 ) &&
455 comparefloat(out[2].z, 0.5 ) &&
456 comparefloat(out[2].rhw, 1.0 ),
457 "Output 2 vertex is (%f , %f , %f , %f)\n", out[2].x, out[2].y, out[2].z, out[2].rhw);
459 ok( comparefloat(out[3].x, 192.0 ) &&
460 comparefloat(out[3].y, 192.0 ) &&
461 comparefloat(out[3].z, 0.25 ) &&
462 comparefloat(out[3].rhw, 1.0 ),
463 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
465 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
466 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
469 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest2, 0, (void **) &out2, NULL);
470 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
472 /* Small thing without much practial meaning, but I stumbled upon it,
473 * so let's check for it: If the output vertex buffer has to RHW value,
474 * The RHW value of the last vertex is written into the next vertex
476 ok( comparefloat(out2[4].x, 1.0 ) &&
477 comparefloat(out2[4].y, 0.0 ) &&
478 comparefloat(out2[4].z, 0.0 ),
479 "Output 4 vertex is (%f , %f , %f)\n", out2[4].x, out2[4].y, out2[4].z);
481 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest2);
482 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
485 /* Try a more complicated viewport, same vertices */
486 memset(&vp, 0, sizeof(vp));
493 rc = IDirect3DDevice7_SetViewport(lpD3DDevice, &vp);
494 ok(rc==D3D_OK, "IDirect3DDevice7_SetViewport failed with rc=%x\n", rc);
497 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
498 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
500 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
501 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
504 /* Check the results */
505 ok( comparefloat(out[0].x, 133.0 ) &&
506 comparefloat(out[0].y, 70.0 ) &&
507 comparefloat(out[0].z, -2.0 ) &&
508 comparefloat(out[0].rhw, 1.0 ),
509 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
511 ok( comparefloat(out[1].x, 256.0 ) &&
512 comparefloat(out[1].y, 5.0 ) &&
513 comparefloat(out[1].z, 4.0 ) &&
514 comparefloat(out[1].rhw, 1.0 ),
515 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
517 ok( comparefloat(out[2].x, 10.0 ) &&
518 comparefloat(out[2].y, 135.0 ) &&
519 comparefloat(out[2].z, 1.0 ) &&
520 comparefloat(out[2].rhw, 1.0 ),
521 "Output 2 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
523 ok( comparefloat(out[3].x, 194.5 ) &&
524 comparefloat(out[3].y, 102.5 ) &&
525 comparefloat(out[3].z, -0.5 ) &&
526 comparefloat(out[3].rhw, 1.0 ),
527 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
529 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
530 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
533 /* Play with some matrices. */
535 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_VIEW, &view);
536 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
538 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_PROJECTION, &proj);
539 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
541 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_WORLD, &world);
542 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
544 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
545 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
547 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
548 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
551 /* Keep the viewport simpler, otherwise we get bad numbers to compare */
558 rc = IDirect3DDevice7_SetViewport(lpD3DDevice, &vp);
559 ok(rc==D3D_OK, "IDirect3DDevice7_SetViewport failed\n");
561 /* Check the results */
562 ok( comparefloat(out[0].x, 256.0 ) && /* X coordinate is cut at the surface edges */
563 comparefloat(out[0].y, 70.0 ) &&
564 comparefloat(out[0].z, -2.0 ) &&
565 comparefloat(out[0].rhw, (1.0 / 3.0)),
566 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
568 ok( comparefloat(out[1].x, 256.0 ) &&
569 comparefloat(out[1].y, 78.125000 ) &&
570 comparefloat(out[1].z, -2.750000 ) &&
571 comparefloat(out[1].rhw, 0.125000 ),
572 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
574 ok( comparefloat(out[2].x, 256.0 ) &&
575 comparefloat(out[2].y, 44.000000 ) &&
576 comparefloat(out[2].z, 0.400000 ) &&
577 comparefloat(out[2].rhw, 0.400000 ),
578 "Output 2 vertex is (%f , %f , %f , %f)\n", out[2].x, out[2].y, out[2].z, out[2].rhw);
580 ok( comparefloat(out[3].x, 256.0 ) &&
581 comparefloat(out[3].y, 81.818184 ) &&
582 comparefloat(out[3].z, -3.090909 ) &&
583 comparefloat(out[3].rhw, 0.363636 ),
584 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
586 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
587 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
591 IDirect3DVertexBuffer7_Release(lpVBufSrc);
592 IDirect3DVertexBuffer7_Release(lpVBufDest1);
593 IDirect3DVertexBuffer7_Release(lpVBufDest2);
596 static void StateTest( void )
600 /* The msdn says its undocumented, does it return an error too? */
601 rc = IDirect3DDevice7_SetRenderState(lpD3DDevice, D3DRENDERSTATE_ZVISIBLE, TRUE);
602 ok(rc == D3D_OK, "IDirect3DDevice7_SetRenderState(D3DRENDERSTATE_ZVISIBLE, TRUE) returned %08x\n", rc);
603 rc = IDirect3DDevice7_SetRenderState(lpD3DDevice, D3DRENDERSTATE_ZVISIBLE, FALSE);
604 ok(rc == D3D_OK, "IDirect3DDevice7_SetRenderState(D3DRENDERSTATE_ZVISIBLE, FALSE) returned %08x\n", rc);
608 static void SceneTest(void)
612 /* Test an EndScene without beginscene. Should return an error */
613 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
614 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
616 /* Test a normal BeginScene / EndScene pair, this should work */
617 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
618 ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed with %08x\n", hr);
622 memset(&fx, 0, sizeof(fx));
623 fx.dwSize = sizeof(fx);
626 hr = IDirectDrawSurface7_Blt(lpDDSdepth, NULL, NULL, NULL, DDBLT_DEPTHFILL, &fx);
627 ok(hr == D3D_OK, "Depthfill failed in a BeginScene / EndScene pair\n");
629 skip("Depth stencil creation failed at startup, skipping\n");
631 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
632 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed with %08x\n", hr);
635 /* Test another EndScene without having begun a new scene. Should return an error */
636 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
637 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
639 /* Two nested BeginScene and EndScene calls */
640 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
641 ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed with %08x\n", hr);
642 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
643 ok(hr == D3DERR_SCENE_IN_SCENE, "IDirect3DDevice7_BeginScene returned %08x\n", hr);
644 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
645 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed with %08x\n", hr);
646 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
647 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
649 /* TODO: Verify that blitting works in the same way as in d3d9 */
652 static void LimitTest(void)
654 IDirectDrawSurface7 *pTexture = NULL;
659 memset(&ddsd, 0, sizeof(ddsd));
660 ddsd.dwSize = sizeof(ddsd);
661 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
662 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
665 hr = IDirectDraw7_CreateSurface(lpDD, &ddsd, &pTexture, NULL);
666 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
667 if(!pTexture) return;
669 for(i = 0; i < 8; i++) {
670 hr = IDirect3DDevice7_SetTexture(lpD3DDevice, i, pTexture);
671 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %08x\n", i, hr);
672 hr = IDirect3DDevice7_SetTexture(lpD3DDevice, i, NULL);
673 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %08x\n", i, hr);
674 hr = IDirect3DDevice7_SetTextureStageState(lpD3DDevice, i, D3DTSS_COLOROP, D3DTOP_ADD);
675 ok(hr == D3D_OK, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %08x\n", i, hr);
678 IDirectDrawSurface7_Release(pTexture);
681 static HRESULT WINAPI enumDevicesCallback(GUID *Guid,LPSTR DeviceDescription,LPSTR DeviceName, D3DDEVICEDESC *hal, D3DDEVICEDESC *hel, VOID *ctx)
683 UINT ver = *((UINT *) ctx);
684 if(IsEqualGUID(&IID_IDirect3DRGBDevice, Guid))
686 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
687 "RGB Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
688 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
689 "RGB Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
690 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
691 "RGB Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
692 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
693 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
695 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
696 "RGB Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
697 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
698 "RGB Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
699 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
700 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
701 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
702 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
704 else if(IsEqualGUID(&IID_IDirect3DHALDevice, Guid))
706 /* pow2 is hardware dependent */
708 ok(hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
709 "HAL Device %d hal line caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
710 ok(hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
711 "HAL Device %d hal tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
712 ok((hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
713 "HAL Device %d hel line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
714 ok((hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
715 "HAL Device %d hel tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
717 else if(IsEqualGUID(&IID_IDirect3DRefDevice, Guid))
719 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
720 "REF Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
721 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
722 "REF Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
723 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
724 "REF Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
725 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
726 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
728 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
729 "REF Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
730 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
731 "REF Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
732 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
733 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
734 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
735 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
737 else if(IsEqualGUID(&IID_IDirect3DRampDevice, Guid))
739 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
740 "Ramp Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
741 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
742 "Ramp Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
743 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
744 "Ramp Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
745 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
746 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
748 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
749 "Ramp Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
750 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
751 "Ramp Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
752 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
753 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
754 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
755 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
757 else if(IsEqualGUID(&IID_IDirect3DMMXDevice, Guid))
759 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
760 "MMX Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
761 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
762 "MMX Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
763 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
764 "MMX Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
765 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
766 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
768 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
769 "MMX Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
770 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
771 "MMX Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
772 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
773 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
774 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
775 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
779 ok(FALSE, "Unexpected device enumerated: \"%s\" \"%s\"\n", DeviceDescription, DeviceName);
780 if(hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hal line has pow2 set\n");
781 else trace("hal line does NOT have pow2 set\n");
782 if(hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hal tri has pow2 set\n");
783 else trace("hal tri does NOT have pow2 set\n");
784 if(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hel line has pow2 set\n");
785 else trace("hel line does NOT have pow2 set\n");
786 if(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hel tri has pow2 set\n");
787 else trace("hel tri does NOT have pow2 set\n");
792 static void CapsTest(void)
800 hr = DirectDrawCreate(NULL, &dd1, NULL);
801 ok(hr == DD_OK, "Cannot create a DirectDraw 1 interface, hr = %08x\n", hr);
802 hr = IDirectDraw_QueryInterface(dd1, &IID_IDirect3D3, (void **) &d3d3);
803 ok(hr == D3D_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
805 IDirect3D3_EnumDevices(d3d3, enumDevicesCallback, &ver);
807 IDirect3D3_Release(d3d3);
808 IDirectDraw_Release(dd1);
810 hr = DirectDrawCreate(NULL, &dd1, NULL);
811 ok(hr == DD_OK, "Cannot create a DirectDraw 1 interface, hr = %08x\n", hr);
812 hr = IDirectDraw_QueryInterface(dd1, &IID_IDirect3D2, (void **) &d3d2);
813 ok(hr == D3D_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
815 IDirect3D2_EnumDevices(d3d2, enumDevicesCallback, &ver);
817 IDirect3D2_Release(d3d2);
818 IDirectDraw_Release(dd1);
828 static void Direct3D1Test(void)
830 IDirect3DDevice *dev1 = NULL;
833 IDirectDrawSurface *dds;
834 IDirect3DExecuteBuffer *exebuf;
835 IDirect3DViewport *vp;
838 D3DEXECUTEBUFFERDESC desc;
840 D3DINSTRUCTION *instr;
842 unsigned int idx = 0;
843 static struct v_in testverts[] = {
844 {0.0, 0.0, 0.0}, { 1.0, 1.0, 1.0}, {-1.0, -1.0, -1.0},
845 {0.5, 0.5, 0.5}, {-0.5, -0.5, -0.5}, {-0.5, -0.5, 0.0},
847 static struct v_in cliptest[] = {
848 {25.59, 25.59, 1.0}, {-25.59, -25.59, 0.0},
849 {25.61, 25.61, 1.01}, {-25.60, -25.60, -0.01},
851 static struct v_in offscreentest[] = {
854 struct v_out out[sizeof(testverts) / sizeof(testverts[0])];
855 D3DHVERTEX outH[sizeof(testverts) / sizeof(testverts[0])];
856 D3DTRANSFORMDATA transformdata;
859 /* An IDirect3DDevice cannot be queryInterfaced from an IDirect3DDevice7 on windows */
860 hr = DirectDrawCreate(NULL, &dd, NULL);
861 ok(hr==DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreate returned: %x\n", hr);
863 trace("DirectDrawCreate() failed with an error %x\n", hr);
867 hr = IDirectDraw_SetCooperativeLevel(dd, NULL, DDSCL_NORMAL);
868 ok(hr==DD_OK, "SetCooperativeLevel returned: %x\n", hr);
870 hr = IDirectDraw_QueryInterface(dd, &IID_IDirect3D, (void**) &d3d);
871 ok(hr==DD_OK, "QueryInterface returned: %x\n", hr);
873 memset(&ddsd, 0, sizeof(ddsd));
874 ddsd.dwSize = sizeof(ddsd);
875 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
876 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
879 hr = IDirectDraw_CreateSurface(dd, &ddsd, &dds, NULL);
880 ok(hr==DD_OK, "CreateSurface returned: %x\n", hr);
883 hr = IDirectDrawSurface_QueryInterface(dds, &IID_IDirect3DRGBDevice, (void **) &dev1);
884 ok(hr==D3D_OK || hr==DDERR_NOPALETTEATTACHED || hr==E_OUTOFMEMORY, "CreateDevice returned: %x\n", hr);
887 memset(&desc, 0, sizeof(desc));
888 desc.dwSize = sizeof(desc);
889 desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
890 desc.dwCaps = D3DDEBCAPS_VIDEOMEMORY;
891 desc.dwBufferSize = 128;
893 hr = IDirect3DDevice_CreateExecuteBuffer(dev1, &desc, &exebuf, NULL);
894 ok(hr == D3D_OK, "IDirect3DDevice_CreateExecuteBuffer failed: %08x\n", hr);
896 memset(&desc, 0, sizeof(desc));
897 desc.dwSize = sizeof(desc);
899 hr = IDirect3DExecuteBuffer_Lock(exebuf, &desc);
900 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Lock failed: %08x\n", hr);
902 instr[idx].bOpcode = D3DOP_BRANCHFORWARD;
903 instr[idx].bSize = sizeof(*branch);
904 instr[idx].wCount = 1;
906 branch = (D3DBRANCH *) &instr[idx];
907 branch->dwMask = 0x0;
909 branch->bNegate = TRUE;
910 branch->dwOffset = 0;
911 idx += (sizeof(*branch) / sizeof(*instr));
912 instr[idx].bOpcode = D3DOP_EXIT;
913 instr[idx].bSize = 0;
914 instr[idx].bSize = 0;
915 hr = IDirect3DExecuteBuffer_Unlock(exebuf);
916 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Unlock failed: %08x\n", hr);
918 hr = IDirect3D_CreateViewport(d3d, &vp, NULL);
919 ok(hr == D3D_OK, "IDirect3D_CreateViewport failed: %08x\n", hr);
920 hr = IDirect3DViewport_Initialize(vp, d3d);
921 ok(hr == DDERR_ALREADYINITIALIZED, "IDirect3DViewport_Initialize returned %08x\n", hr);
923 hr = IDirect3DDevice_AddViewport(dev1, vp);
924 ok(hr == D3D_OK, "IDirect3DDevice_AddViewport returned %08x\n", hr);
925 vp_data.dwSize = sizeof(vp_data);
928 vp_data.dwWidth = 256;
929 vp_data.dwHeight = 256;
930 vp_data.dvScaleX = 1;
931 vp_data.dvScaleY = 1;
932 vp_data.dvMaxX = 256;
933 vp_data.dvMaxY = 256;
936 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
937 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
939 hr = IDirect3DDevice_Execute(dev1, exebuf, vp, D3DEXECUTE_CLIPPED);
940 ok(hr == D3D_OK, "IDirect3DDevice_Execute returned %08x\n", hr);
942 memset(&transformdata, 0, sizeof(transformdata));
943 transformdata.dwSize = sizeof(transformdata);
944 transformdata.lpIn = (void *) testverts;
945 transformdata.dwInSize = sizeof(testverts[0]);
946 transformdata.lpOut = out;
947 transformdata.dwOutSize = sizeof(out[0]);
949 transformdata.lpHOut = NULL;
950 hr = IDirect3DViewport_TransformVertices(vp, sizeof(testverts) / sizeof(testverts[0]),
951 &transformdata, D3DTRANSFORM_UNCLIPPED,
953 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
955 transformdata.lpHOut = outH;
956 memset(outH, 0xaa, sizeof(outH));
957 hr = IDirect3DViewport_TransformVertices(vp, sizeof(testverts) / sizeof(testverts[0]),
958 &transformdata, D3DTRANSFORM_UNCLIPPED,
960 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
961 ok(i == 0, "Offscreen is %d\n", i);
963 for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
964 static const struct v_out cmp[] = {
965 {128.0, 128.0, 0.0, 1}, {129.0, 127.0, 1.0, 1}, {127.0, 129.0, -1, 1},
966 {128.5, 127.5, 0.5, 1}, {127.5, 128.5, -0.5, 1}, {127.5, 128.5, 0, 1}
969 ok(cmp[i].x == out[i].x && cmp[i].y == out[i].y &&
970 cmp[i].z == out[i].z && cmp[i].rhw == out[i].rhw,
971 "Vertex %d differs. Got %f %f %f %f, expexted %f %f %f %f\n", i + 1,
972 out[i].x, out[i].y, out[i].z, out[i].rhw,
973 cmp[i].x, cmp[i].y, cmp[i].z, cmp[i].rhw);
975 for(i = 0; i < sizeof(outH); i++) {
976 if(((unsigned char *) outH)[i] != 0xaa) {
977 ok(FALSE, "Homogenous output was generated despite UNCLIPPED flag\n");
982 vp_data.dvScaleX = 5;
983 vp_data.dvScaleY = 5;
984 vp_data.dvMinZ = -25;
986 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
987 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
988 hr = IDirect3DViewport_TransformVertices(vp, sizeof(testverts) / sizeof(testverts[0]),
989 &transformdata, D3DTRANSFORM_UNCLIPPED,
991 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
992 ok(i == 0, "Offscreen is %d\n", i);
993 for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
994 static const struct v_out cmp[] = {
995 {128.0, 128.0, 0.0, 1}, {133.0, 123.0, 1.0, 1}, {123.0, 133.0, -1, 1},
996 {130.5, 125.5, 0.5, 1}, {125.5, 130.5, -0.5, 1}, {125.5, 130.5, 0, 1}
998 ok(cmp[i].x == out[i].x && cmp[i].y == out[i].y &&
999 cmp[i].z == out[i].z && cmp[i].rhw == out[i].rhw,
1000 "Vertex %d differs. Got %f %f %f %f, expexted %f %f %f %f\n", i + 1,
1001 out[i].x, out[i].y, out[i].z, out[i].rhw,
1002 cmp[i].x, cmp[i].y, cmp[i].z, cmp[i].rhw);
1007 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1008 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
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);
1014 for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
1015 static const struct v_out cmp[] = {
1016 {138.0, 148.0, 0.0, 1}, {143.0, 143.0, 1.0, 1}, {133.0, 153.0, -1, 1},
1017 {140.5, 145.5, 0.5, 1}, {135.5, 150.5, -0.5, 1}, {135.5, 150.5, 0, 1}
1019 ok(cmp[i].x == out[i].x && cmp[i].y == out[i].y &&
1020 cmp[i].z == out[i].z && cmp[i].rhw == out[i].rhw,
1021 "Vertex %d differs. Got %f %f %f %f, expexted %f %f %f %f\n", i + 1,
1022 out[i].x, out[i].y, out[i].z, out[i].rhw,
1023 cmp[i].x, cmp[i].y, cmp[i].z, cmp[i].rhw);
1026 memset(out, 0xbb, sizeof(out));
1027 hr = IDirect3DViewport_TransformVertices(vp, sizeof(testverts) / sizeof(testverts[0]),
1028 &transformdata, D3DTRANSFORM_CLIPPED,
1030 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1031 ok(i == 0, "Offscreen is %d\n", i);
1032 for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
1033 static const D3DHVERTEX cmpH[] = {
1034 {0, { 0.0}, { 0.0}, { 0.0}}, {0, { 1.0}, { 1.0}, {1.0}},
1035 {D3DCLIP_FRONT, {-1.0}, {-1.0}, {-1.0}}, {0, { 0.5}, { 0.5}, {0.5}},
1036 {D3DCLIP_FRONT, {-0.5}, {-0.5}, {-0.5}}, {0, {-0.5}, {-0.5}, {0.0}}
1038 ok(U1(cmpH[i]).hx == U1(outH[i]).hx && U2(cmpH[i]).hy == U2(outH[i]).hy &&
1039 U3(cmpH[i]).hz == U3(outH[i]).hz && cmpH[i].dwFlags == outH[i].dwFlags,
1040 "HVertex %d differs. Got %08x %f %f %f, expexted %08x %f %f %f\n", i + 1,
1041 outH[i].dwFlags, U1(outH[i]).hx, U2(outH[i]).hy, U3(outH[i]).hz,
1042 cmpH[i].dwFlags, U1(cmpH[i]).hx, U2(cmpH[i]).hy, U3(cmpH[i]).hz);
1044 /* No scheme has been found behind those return values. It seems to be
1045 * whatever data windows has when throwing the vertex away. Modify the
1046 * input test vertices to test this more. Depending on the input data
1047 * it can happen that the z coord gets written into y, or similar things
1051 static const struct v_out cmp[] = {
1052 {138.0, 148.0, 0.0, 1}, {143.0, 143.0, 1.0, 1}, { -1.0, -1.0, 0.5, 1},
1053 {140.5, 145.5, 0.5, 1}, { -0.5, -0.5, -0.5, 1}, {135.5, 150.5, 0.0, 1}
1055 ok(cmp[i].x == out[i].x && cmp[i].y == out[i].y &&
1056 cmp[i].z == out[i].z && cmp[i].rhw == out[i].rhw,
1057 "Vertex %d differs. Got %f %f %f %f, expexted %f %f %f %f\n", i + 1,
1058 out[i].x, out[i].y, out[i].z, out[i].rhw,
1059 cmp[i].x, cmp[i].y, cmp[i].z, cmp[i].rhw);
1062 for(i = 0; i < sizeof(out) / sizeof(DWORD); i++) {
1063 ok(((DWORD *) out)[i] != 0xbbbbbbbb,
1064 "Regular output DWORD %d remained untouched\n", i);
1067 transformdata.lpIn = (void *) cliptest;
1068 transformdata.dwInSize = sizeof(cliptest[0]);
1069 hr = IDirect3DViewport_TransformVertices(vp, sizeof(cliptest) / sizeof(cliptest[0]),
1070 &transformdata, D3DTRANSFORM_CLIPPED,
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(cliptest) / sizeof(cliptest[0]); i++) {
1075 DWORD Flags[sizeof(cliptest) / sizeof(cliptest[0])] =
1079 D3DCLIP_RIGHT | D3DCLIP_BACK | D3DCLIP_TOP,
1080 D3DCLIP_LEFT | D3DCLIP_BOTTOM | D3DCLIP_FRONT,
1082 ok(Flags[i] == outH[i].dwFlags,
1083 "Cliptest %d differs. Got %08x expexted %08x\n", i + 1,
1084 outH[i].dwFlags, Flags[i]);
1087 vp_data.dwWidth = 10;
1088 vp_data.dwHeight = 1000;
1089 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1091 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1092 hr = IDirect3DViewport_TransformVertices(vp, sizeof(cliptest) / sizeof(cliptest[0]),
1093 &transformdata, D3DTRANSFORM_CLIPPED,
1095 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1096 ok(i == 0, "Offscreen is %d\n", i);
1097 for(i = 0; i < sizeof(cliptest) / sizeof(cliptest[0]); i++) {
1098 DWORD Flags[sizeof(cliptest) / sizeof(cliptest[0])] =
1102 D3DCLIP_RIGHT | D3DCLIP_BACK,
1103 D3DCLIP_LEFT | D3DCLIP_FRONT,
1105 ok(Flags[i] == outH[i].dwFlags,
1106 "Cliptest %d differs. Got %08x expexted %08x\n", i + 1,
1107 outH[i].dwFlags, Flags[i]);
1109 vp_data.dwWidth = 256;
1110 vp_data.dwHeight = 256;
1111 vp_data.dvScaleX = 1;
1112 vp_data.dvScaleY = 1;
1113 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1114 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1115 hr = IDirect3DViewport_TransformVertices(vp, sizeof(cliptest) / sizeof(cliptest[0]),
1116 &transformdata, D3DTRANSFORM_CLIPPED,
1118 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1119 ok(i == 0, "Offscreen is %s\n", i ? "TRUE" : "FALSE");
1120 for(i = 0; i < sizeof(cliptest) / sizeof(cliptest[0]); i++) {
1121 DWORD Flags[sizeof(cliptest) / sizeof(cliptest[0])] =
1128 ok(Flags[i] == outH[i].dwFlags,
1129 "Cliptest %d differs. Got %08x expexted %08x\n", i + 1,
1130 outH[i].dwFlags, Flags[i]);
1133 /* Finally try to figure out how the DWORD dwOffscreen works.
1134 * Apparently no vertex is offscreen with clipping off,
1135 * and with clipping on the offscreen flag is set if only one vertex
1136 * is transformed, and this vertex is offscreen.
1138 vp_data.dwWidth = 5;
1139 vp_data.dwHeight = 5;
1140 vp_data.dvScaleX = 10000;
1141 vp_data.dvScaleY = 10000;
1142 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1143 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1144 transformdata.lpIn = cliptest;
1145 hr = IDirect3DViewport_TransformVertices(vp, 1,
1146 &transformdata, D3DTRANSFORM_UNCLIPPED,
1148 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1149 ok(i == 0, "Offscreen is %d\n", i);
1150 hr = IDirect3DViewport_TransformVertices(vp, 1,
1151 &transformdata, D3DTRANSFORM_CLIPPED,
1153 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1154 ok(i == (D3DCLIP_RIGHT | D3DCLIP_TOP), "Offscreen is %d\n", i);
1155 hr = IDirect3DViewport_TransformVertices(vp, 2,
1156 &transformdata, D3DTRANSFORM_CLIPPED,
1158 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1159 ok(i == 0, "Offscreen is %d\n", i);
1160 transformdata.lpIn = cliptest + 1;
1161 hr = IDirect3DViewport_TransformVertices(vp, 1,
1162 &transformdata, D3DTRANSFORM_CLIPPED,
1164 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1165 ok(i == (D3DCLIP_BOTTOM | D3DCLIP_LEFT), "Offscreen is %d\n", i);
1167 transformdata.lpIn = (void *) offscreentest;
1168 transformdata.dwInSize = sizeof(offscreentest[0]);
1169 vp_data.dwWidth = 257;
1170 vp_data.dwHeight = 257;
1171 vp_data.dvScaleX = 1;
1172 vp_data.dvScaleY = 1;
1173 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1175 hr = IDirect3DViewport_TransformVertices(vp, sizeof(offscreentest) / sizeof(offscreentest[0]),
1176 &transformdata, D3DTRANSFORM_CLIPPED,
1178 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1179 ok(i == 0, "Offscreen is %d\n", i);
1180 vp_data.dwWidth = 256;
1181 vp_data.dwHeight = 256;
1182 hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1184 hr = IDirect3DViewport_TransformVertices(vp, sizeof(offscreentest) / sizeof(offscreentest[0]),
1185 &transformdata, D3DTRANSFORM_CLIPPED,
1187 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1188 ok(i == D3DCLIP_RIGHT, "Offscreen is %d\n", i);
1190 hr = IDirect3DViewport_TransformVertices(vp, sizeof(testverts) / sizeof(testverts[0]),
1193 ok(hr == DDERR_INVALIDPARAMS, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1195 hr = IDirect3DDevice_DeleteViewport(dev1, vp);
1196 ok(hr == D3D_OK, "IDirect3DDevice_DeleteViewport returned %08x\n", hr);
1198 IDirect3DViewport_Release(vp);
1199 IDirect3DExecuteBuffer_Release(exebuf);
1200 IDirect3DDevice_Release(dev1);
1201 IDirectDrawSurface_Release(dds);
1202 IDirect3D_Release(d3d);
1203 IDirectDraw_Release(dd);
1209 init_function_pointers();
1210 if(!pDirectDrawCreateEx) {
1211 skip("function DirectDrawCreateEx not available\n");
1215 if(!CreateDirect3D()) {
1216 trace("Skipping tests\n");
1220 ProcessVerticesTest();