ddraw: Remove trailing spaces in ok() calls.
[wine/wine-kai.git] / dlls / ddraw / tests / d3d.c
blobf8c1a9be347ab4aa1b93dfaf2b4ab2168bbea312
1 /*
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
22 #include <assert.h>
23 #include "wine/test.h"
24 #include "ddraw.h"
25 #include "d3d.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 static IDirectDraw *DirectDraw1 = NULL;
37 static IDirectDrawSurface *Surface1 = NULL;
38 static IDirect3D *Direct3D1 = NULL;
39 static IDirect3DDevice *Direct3DDevice1 = NULL;
40 static IDirect3DExecuteBuffer *ExecuteBuffer = NULL;
41 static IDirect3DViewport *Viewport = NULL;
43 typedef struct {
44 int total;
45 int rgb;
46 int hal;
47 int tnlhal;
48 int unk;
49 } D3D7ETest;
51 /* To compare bad floating point numbers. Not the ideal way to do it,
52 * but it should be enough for here */
53 #define comparefloat(a, b) ( (((a) - (b)) < 0.0001) && (((a) - (b)) > -0.0001) )
55 static HRESULT (WINAPI *pDirectDrawCreateEx)(LPGUID,LPVOID*,REFIID,LPUNKNOWN);
57 typedef struct _VERTEX
59 float x, y, z; /* position */
60 } VERTEX, *LPVERTEX;
62 typedef struct _TVERTEX
64 float x, y, z; /* position */
65 float rhw;
66 } TVERTEX, *LPTVERTEX;
69 static void init_function_pointers(void)
71 HMODULE hmod = GetModuleHandleA("ddraw.dll");
72 pDirectDrawCreateEx = (void*)GetProcAddress(hmod, "DirectDrawCreateEx");
76 static BOOL CreateDirect3D(void)
78 HRESULT rc;
79 DDSURFACEDESC2 ddsd;
81 rc = pDirectDrawCreateEx(NULL, (void**)&lpDD,
82 &IID_IDirectDraw7, NULL);
83 ok(rc==DD_OK || rc==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", rc);
84 if (!lpDD) {
85 trace("DirectDrawCreateEx() failed with an error %x\n", rc);
86 return FALSE;
89 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
90 ok(rc==DD_OK, "SetCooperativeLevel returned: %x\n", rc);
92 rc = IDirectDraw7_QueryInterface(lpDD, &IID_IDirect3D7, (void**) &lpD3D);
93 if (rc == E_NOINTERFACE) return FALSE;
94 ok(rc==DD_OK, "QueryInterface returned: %x\n", rc);
96 memset(&ddsd, 0, sizeof(ddsd));
97 ddsd.dwSize = sizeof(ddsd);
98 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
99 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
100 ddsd.dwWidth = 256;
101 ddsd.dwHeight = 256;
102 rc = IDirectDraw7_CreateSurface(lpDD, &ddsd, &lpDDS, NULL);
103 if (!SUCCEEDED(rc))
104 return FALSE;
106 memset(&ddsd, 0, sizeof(ddsd));
107 ddsd.dwSize = sizeof(ddsd);
108 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
109 ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
110 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
111 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
112 U1(U4(ddsd).ddpfPixelFormat).dwZBufferBitDepth = 16;
113 U3(U4(ddsd).ddpfPixelFormat).dwZBitMask = 0x0000FFFF;
114 ddsd.dwWidth = 256;
115 ddsd.dwHeight = 256;
116 rc = IDirectDraw7_CreateSurface(lpDD, &ddsd, &lpDDSdepth, NULL);
117 ok(rc==DD_OK, "CreateSurface returned: %x\n", rc);
118 if (!SUCCEEDED(rc)) {
119 lpDDSdepth = NULL;
120 } else {
121 rc = IDirectDrawSurface_AddAttachedSurface(lpDDS, lpDDSdepth);
122 ok(rc == DD_OK, "IDirectDrawSurface_AddAttachedSurface returned %x\n", rc);
123 if (!SUCCEEDED(rc))
124 return FALSE;
127 rc = IDirect3D7_CreateDevice(lpD3D, &IID_IDirect3DTnLHalDevice, lpDDS,
128 &lpD3DDevice);
129 ok(rc==D3D_OK || rc==DDERR_NOPALETTEATTACHED || rc==E_OUTOFMEMORY, "CreateDevice returned: %x\n", rc);
130 if (!lpD3DDevice) {
131 trace("IDirect3D7::CreateDevice() for a TnL Hal device failed with an error %x, trying HAL\n", rc);
132 rc = IDirect3D7_CreateDevice(lpD3D, &IID_IDirect3DHALDevice, lpDDS,
133 &lpD3DDevice);
134 if (!lpD3DDevice) {
135 trace("IDirect3D7::CreateDevice() for a HAL device failed with an error %x, trying RGB\n", rc);
136 rc = IDirect3D7_CreateDevice(lpD3D, &IID_IDirect3DRGBDevice, lpDDS,
137 &lpD3DDevice);
138 if (!lpD3DDevice) {
139 trace("IDirect3D7::CreateDevice() for a RGB device failed with an error %x, giving up\n", rc);
140 return FALSE;
145 return TRUE;
148 static void ReleaseDirect3D(void)
150 if (lpD3DDevice != NULL)
152 IDirect3DDevice7_Release(lpD3DDevice);
153 lpD3DDevice = NULL;
156 if (lpDDSdepth != NULL)
158 IDirectDrawSurface_Release(lpDDSdepth);
159 lpDDSdepth = NULL;
162 if (lpDDS != NULL)
164 IDirectDrawSurface_Release(lpDDS);
165 lpDDS = NULL;
168 if (lpD3D != NULL)
170 IDirect3D7_Release(lpD3D);
171 lpD3D = NULL;
174 if (lpDD != NULL)
176 IDirectDraw_Release(lpDD);
177 lpDD = NULL;
181 static void LightTest(void)
183 HRESULT rc;
184 D3DLIGHT7 light;
185 D3DLIGHT7 defaultlight;
186 BOOL bEnabled = FALSE;
187 float one = 1.0f;
188 float zero= 0.0f;
189 D3DMATERIAL7 mat;
190 BOOL enabled;
191 unsigned int i;
192 D3DDEVICEDESC7 caps;
194 /* Set a few lights with funky indices. */
195 memset(&light, 0, sizeof(light));
196 light.dltType = D3DLIGHT_DIRECTIONAL;
197 U1(light.dcvDiffuse).r = 0.5f;
198 U2(light.dcvDiffuse).g = 0.6f;
199 U3(light.dcvDiffuse).b = 0.7f;
200 U2(light.dvDirection).y = 1.f;
202 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 5, &light);
203 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
204 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 10, &light);
205 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
206 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 45, &light);
207 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
210 /* Try to retrieve a light beyond the indices of the lights that have
211 been set. */
212 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
213 ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %x\n", rc);
214 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 2, &light);
215 ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %x\n", rc);
218 /* Try to retrieve one of the lights that have been set */
219 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 10, &light);
220 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
223 /* Enable a light that have been previously set. */
224 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 10, TRUE);
225 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
228 /* Enable some lights that have not been previously set, and verify that
229 they have been initialized with proper default values. */
230 memset(&defaultlight, 0, sizeof(D3DLIGHT7));
231 defaultlight.dltType = D3DLIGHT_DIRECTIONAL;
232 U1(defaultlight.dcvDiffuse).r = 1.f;
233 U2(defaultlight.dcvDiffuse).g = 1.f;
234 U3(defaultlight.dcvDiffuse).b = 1.f;
235 U3(defaultlight.dvDirection).z = 1.f;
237 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, TRUE);
238 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
239 memset(&light, 0, sizeof(D3DLIGHT7));
240 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 20, &light);
241 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
242 ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
243 "light data doesn't match expected default values\n" );
245 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 50, TRUE);
246 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
247 memset(&light, 0, sizeof(D3DLIGHT7));
248 rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
249 ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
250 ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
251 "light data doesn't match expected default values\n" );
254 /* Disable one of the light that have been previously enabled. */
255 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, FALSE);
256 ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
258 /* Try to retrieve the enable status of some lights */
259 /* Light 20 is supposed to be disabled */
260 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 20, &bEnabled );
261 ok(rc==D3D_OK, "GetLightEnable returned: %x\n", rc);
262 ok(!bEnabled, "GetLightEnable says the light is enabled\n");
264 /* Light 10 is supposed to be enabled */
265 bEnabled = FALSE;
266 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 10, &bEnabled );
267 ok(rc==D3D_OK, "GetLightEnable returned: %x\n", rc);
268 ok(bEnabled, "GetLightEnable says the light is disabled\n");
270 /* Light 80 has not been set */
271 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 80, &bEnabled );
272 ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %x\n", rc);
274 /* Light 23 has not been set */
275 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 23, &bEnabled );
276 ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %x\n", rc);
278 /* Set some lights with invalid parameters */
279 memset(&light, 0, sizeof(D3DLIGHT7));
280 light.dltType = 0;
281 U1(light.dcvDiffuse).r = 1.f;
282 U2(light.dcvDiffuse).g = 1.f;
283 U3(light.dcvDiffuse).b = 1.f;
284 U3(light.dvDirection).z = 1.f;
285 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 100, &light);
286 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
288 memset(&light, 0, sizeof(D3DLIGHT7));
289 light.dltType = 12345;
290 U1(light.dcvDiffuse).r = 1.f;
291 U2(light.dcvDiffuse).g = 1.f;
292 U3(light.dcvDiffuse).b = 1.f;
293 U3(light.dvDirection).z = 1.f;
294 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 101, &light);
295 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
297 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 102, NULL);
298 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
300 memset(&light, 0, sizeof(D3DLIGHT7));
301 light.dltType = D3DLIGHT_SPOT;
302 U1(light.dcvDiffuse).r = 1.f;
303 U2(light.dcvDiffuse).g = 1.f;
304 U3(light.dcvDiffuse).b = 1.f;
305 U3(light.dvDirection).z = 1.f;
307 light.dvAttenuation0 = -one / zero; /* -INFINITY */
308 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
309 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
311 light.dvAttenuation0 = -1.0;
312 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
313 ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
315 light.dvAttenuation0 = 0.0;
316 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
317 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
319 light.dvAttenuation0 = 1.0;
320 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
321 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
323 light.dvAttenuation0 = one / zero; /* +INFINITY */
324 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
325 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
327 light.dvAttenuation0 = zero / zero; /* NaN */
328 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
329 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
331 /* Directional light ignores attenuation */
332 light.dltType = D3DLIGHT_DIRECTIONAL;
333 light.dvAttenuation0 = -1.0;
334 rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
335 ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
337 memset(&mat, 0, sizeof(mat));
338 rc = IDirect3DDevice7_SetMaterial(lpD3DDevice, &mat);
339 ok(rc == D3D_OK, "IDirect3DDevice7_SetMaterial returned: %x\n", rc);
341 U4(mat).power = 129.0;
342 rc = IDirect3DDevice7_SetMaterial(lpD3DDevice, &mat);
343 ok(rc == D3D_OK, "IDirect3DDevice7_SetMaterial(power = 129.0) returned: %x\n", rc);
344 memset(&mat, 0, sizeof(mat));
345 rc = IDirect3DDevice7_GetMaterial(lpD3DDevice, &mat);
346 ok(rc == D3D_OK, "IDirect3DDevice7_GetMaterial returned: %x\n", rc);
347 ok(U4(mat).power == 129, "Returned power is %f\n", U4(mat).power);
349 U4(mat).power = -1.0;
350 rc = IDirect3DDevice7_SetMaterial(lpD3DDevice, &mat);
351 ok(rc == D3D_OK, "IDirect3DDevice7_SetMaterial(power = -1.0) returned: %x\n", rc);
352 memset(&mat, 0, sizeof(mat));
353 rc = IDirect3DDevice7_GetMaterial(lpD3DDevice, &mat);
354 ok(rc == D3D_OK, "IDirect3DDevice7_GetMaterial returned: %x\n", rc);
355 ok(U4(mat).power == -1, "Returned power is %f\n", U4(mat).power);
357 memset(&caps, 0, sizeof(caps));
358 rc = IDirect3DDevice7_GetCaps(lpD3DDevice, &caps);
359 ok(rc == D3D_OK, "IDirect3DDevice7_GetCaps failed with %x\n", rc);
361 if ( caps.dwMaxActiveLights == (DWORD) -1) {
362 /* Some cards without T&L Support return -1 (Examples: Vodoo banshee, RivaTNT / NV4) */
363 skip("T&L not supported\n");
364 return;
367 for(i = 1; i <= caps.dwMaxActiveLights; i++) {
368 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, i, TRUE);
369 ok(rc == D3D_OK, "Enabling light %u failed with %x\n", i, rc);
370 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, i, &enabled);
371 ok(rc == D3D_OK, "GetLightEnable on light %u failed with %x\n", i, rc);
372 ok(enabled, "Light %d is %s\n", i, enabled ? "enabled" : "disabled");
375 /* TODO: Test the rendering results in this situation */
376 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, i + 1, TRUE);
377 ok(rc == D3D_OK, "Enabling one light more than supported returned %x\n", rc);
378 rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, i + 1, &enabled);
379 ok(rc == D3D_OK, "GetLightEnable on light %u failed with %x\n", i + 1, rc);
380 ok(enabled, "Light %d is %s\n", i + 1, enabled ? "enabled" : "disabled");
381 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, i + 1, FALSE);
382 ok(rc == D3D_OK, "Disabling the additional returned %x\n", rc);
384 for(i = 1; i <= caps.dwMaxActiveLights; i++) {
385 rc = IDirect3DDevice7_LightEnable(lpD3DDevice, i, FALSE);
386 ok(rc == D3D_OK, "Disabling light %u failed with %x\n", i, rc);
390 static void ProcessVerticesTest(void)
392 D3DVERTEXBUFFERDESC desc;
393 HRESULT rc;
394 VERTEX *in;
395 TVERTEX *out;
396 VERTEX *out2;
397 D3DVIEWPORT7 vp;
398 D3DMATRIX view = { 2.0, 0.0, 0.0, 0.0,
399 0.0, -1.0, 0.0, 0.0,
400 0.0, 0.0, 1.0, 0.0,
401 0.0, 0.0, 0.0, 3.0 };
403 D3DMATRIX world = { 0.0, 1.0, 0.0, 0.0,
404 1.0, 0.0, 0.0, 0.0,
405 0.0, 0.0, 0.0, 1.0,
406 0.0, 1.0, 1.0, 1.0 };
408 D3DMATRIX proj = { 1.0, 0.0, 0.0, 1.0,
409 0.0, 1.0, 1.0, 0.0,
410 0.0, 1.0, 1.0, 0.0,
411 1.0, 0.0, 0.0, 1.0 };
412 /* Create some vertex buffers */
414 memset(&desc, 0, sizeof(desc));
415 desc.dwSize = sizeof(desc);
416 desc.dwCaps = 0;
417 desc.dwFVF = D3DFVF_XYZ;
418 desc.dwNumVertices = 16;
419 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufSrc, 0);
420 ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
421 if (!lpVBufSrc)
423 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
424 goto out;
427 memset(&desc, 0, sizeof(desc));
428 desc.dwSize = sizeof(desc);
429 desc.dwCaps = 0;
430 desc.dwFVF = D3DFVF_XYZRHW;
431 desc.dwNumVertices = 16;
432 /* Msdn says that the last parameter must be 0 - check that */
433 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufDest1, 4);
434 ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
435 if (!lpVBufDest1)
437 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
438 goto out;
441 memset(&desc, 0, sizeof(desc));
442 desc.dwSize = sizeof(desc);
443 desc.dwCaps = 0;
444 desc.dwFVF = D3DFVF_XYZ;
445 desc.dwNumVertices = 16;
446 /* Msdn says that the last parameter must be 0 - check that */
447 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufDest2, 12345678);
448 ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
449 if (!lpVBufDest2)
451 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
452 goto out;
455 rc = IDirect3DVertexBuffer7_Lock(lpVBufSrc, 0, (void **) &in, NULL);
456 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
457 if(!in) goto out;
459 /* Check basic transformation */
461 in[0].x = 0.0;
462 in[0].y = 0.0;
463 in[0].z = 0.0;
465 in[1].x = 1.0;
466 in[1].y = 1.0;
467 in[1].z = 1.0;
469 in[2].x = -1.0;
470 in[2].y = -1.0;
471 in[2].z = 0.5;
473 in[3].x = 0.5;
474 in[3].y = -0.5;
475 in[3].z = 0.25;
476 rc = IDirect3DVertexBuffer7_Unlock(lpVBufSrc);
477 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
479 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
480 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
482 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest2, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
483 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
485 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
486 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
487 if(!out) goto out;
489 /* Check the results */
490 ok( comparefloat(out[0].x, 128.0 ) &&
491 comparefloat(out[0].y, 128.0 ) &&
492 comparefloat(out[0].z, 0.0 ) &&
493 comparefloat(out[0].rhw, 1.0 ),
494 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
496 ok( comparefloat(out[1].x, 256.0 ) &&
497 comparefloat(out[1].y, 0.0 ) &&
498 comparefloat(out[1].z, 1.0 ) &&
499 comparefloat(out[1].rhw, 1.0 ),
500 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
502 ok( comparefloat(out[2].x, 0.0 ) &&
503 comparefloat(out[2].y, 256.0 ) &&
504 comparefloat(out[2].z, 0.5 ) &&
505 comparefloat(out[2].rhw, 1.0 ),
506 "Output 2 vertex is (%f , %f , %f , %f)\n", out[2].x, out[2].y, out[2].z, out[2].rhw);
508 ok( comparefloat(out[3].x, 192.0 ) &&
509 comparefloat(out[3].y, 192.0 ) &&
510 comparefloat(out[3].z, 0.25 ) &&
511 comparefloat(out[3].rhw, 1.0 ),
512 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
514 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
515 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
516 out = NULL;
518 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest2, 0, (void **) &out2, NULL);
519 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
520 if(!out2) goto out;
521 /* Small thing without much practial meaning, but I stumbled upon it,
522 * so let's check for it: If the output vertex buffer has to RHW value,
523 * The RHW value of the last vertex is written into the next vertex
525 ok( comparefloat(out2[4].x, 1.0 ) &&
526 comparefloat(out2[4].y, 0.0 ) &&
527 comparefloat(out2[4].z, 0.0 ),
528 "Output 4 vertex is (%f , %f , %f)\n", out2[4].x, out2[4].y, out2[4].z);
530 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest2);
531 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
532 out = NULL;
534 /* Try a more complicated viewport, same vertices */
535 memset(&vp, 0, sizeof(vp));
536 vp.dwX = 10;
537 vp.dwY = 5;
538 vp.dwWidth = 246;
539 vp.dwHeight = 130;
540 vp.dvMinZ = -2.0;
541 vp.dvMaxZ = 4.0;
542 rc = IDirect3DDevice7_SetViewport(lpD3DDevice, &vp);
543 ok(rc==D3D_OK, "IDirect3DDevice7_SetViewport failed with rc=%x\n", rc);
545 /* Process again */
546 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
547 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
549 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
550 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
551 if(!out) goto out;
553 /* Check the results */
554 ok( comparefloat(out[0].x, 133.0 ) &&
555 comparefloat(out[0].y, 70.0 ) &&
556 comparefloat(out[0].z, -2.0 ) &&
557 comparefloat(out[0].rhw, 1.0 ),
558 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
560 ok( comparefloat(out[1].x, 256.0 ) &&
561 comparefloat(out[1].y, 5.0 ) &&
562 comparefloat(out[1].z, 4.0 ) &&
563 comparefloat(out[1].rhw, 1.0 ),
564 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
566 ok( comparefloat(out[2].x, 10.0 ) &&
567 comparefloat(out[2].y, 135.0 ) &&
568 comparefloat(out[2].z, 1.0 ) &&
569 comparefloat(out[2].rhw, 1.0 ),
570 "Output 2 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
572 ok( comparefloat(out[3].x, 194.5 ) &&
573 comparefloat(out[3].y, 102.5 ) &&
574 comparefloat(out[3].z, -0.5 ) &&
575 comparefloat(out[3].rhw, 1.0 ),
576 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
578 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
579 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
580 out = NULL;
582 /* Play with some matrices. */
584 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_VIEW, &view);
585 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
587 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_PROJECTION, &proj);
588 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
590 rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_WORLD, &world);
591 ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
593 rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
594 ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
596 rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
597 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
598 if(!out) goto out;
600 /* Keep the viewport simpler, otherwise we get bad numbers to compare */
601 vp.dwX = 0;
602 vp.dwY = 0;
603 vp.dwWidth = 100;
604 vp.dwHeight = 100;
605 vp.dvMinZ = 1.0;
606 vp.dvMaxZ = 0.0;
607 rc = IDirect3DDevice7_SetViewport(lpD3DDevice, &vp);
608 ok(rc==D3D_OK, "IDirect3DDevice7_SetViewport failed\n");
610 /* Check the results */
611 ok( comparefloat(out[0].x, 256.0 ) && /* X coordinate is cut at the surface edges */
612 comparefloat(out[0].y, 70.0 ) &&
613 comparefloat(out[0].z, -2.0 ) &&
614 comparefloat(out[0].rhw, (1.0 / 3.0)),
615 "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
617 ok( comparefloat(out[1].x, 256.0 ) &&
618 comparefloat(out[1].y, 78.125000 ) &&
619 comparefloat(out[1].z, -2.750000 ) &&
620 comparefloat(out[1].rhw, 0.125000 ),
621 "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
623 ok( comparefloat(out[2].x, 256.0 ) &&
624 comparefloat(out[2].y, 44.000000 ) &&
625 comparefloat(out[2].z, 0.400000 ) &&
626 comparefloat(out[2].rhw, 0.400000 ),
627 "Output 2 vertex is (%f , %f , %f , %f)\n", out[2].x, out[2].y, out[2].z, out[2].rhw);
629 ok( comparefloat(out[3].x, 256.0 ) &&
630 comparefloat(out[3].y, 81.818184 ) &&
631 comparefloat(out[3].z, -3.090909 ) &&
632 comparefloat(out[3].rhw, 0.363636 ),
633 "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
635 rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
636 ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
637 out = NULL;
639 out:
640 IDirect3DVertexBuffer7_Release(lpVBufSrc);
641 IDirect3DVertexBuffer7_Release(lpVBufDest1);
642 IDirect3DVertexBuffer7_Release(lpVBufDest2);
645 static void StateTest( void )
647 HRESULT rc;
649 /* The msdn says its undocumented, does it return an error too? */
650 rc = IDirect3DDevice7_SetRenderState(lpD3DDevice, D3DRENDERSTATE_ZVISIBLE, TRUE);
651 ok(rc == D3D_OK, "IDirect3DDevice7_SetRenderState(D3DRENDERSTATE_ZVISIBLE, TRUE) returned %08x\n", rc);
652 rc = IDirect3DDevice7_SetRenderState(lpD3DDevice, D3DRENDERSTATE_ZVISIBLE, FALSE);
653 ok(rc == D3D_OK, "IDirect3DDevice7_SetRenderState(D3DRENDERSTATE_ZVISIBLE, FALSE) returned %08x\n", rc);
657 static void SceneTest(void)
659 HRESULT hr;
661 /* Test an EndScene without beginscene. Should return an error */
662 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
663 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
665 /* Test a normal BeginScene / EndScene pair, this should work */
666 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
667 ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed with %08x\n", hr);
668 if(SUCCEEDED(hr))
670 DDBLTFX fx;
671 memset(&fx, 0, sizeof(fx));
672 fx.dwSize = sizeof(fx);
674 if(lpDDSdepth) {
675 hr = IDirectDrawSurface7_Blt(lpDDSdepth, NULL, NULL, NULL, DDBLT_DEPTHFILL, &fx);
676 ok(hr == D3D_OK, "Depthfill failed in a BeginScene / EndScene pair\n");
677 } else {
678 skip("Depth stencil creation failed at startup, skipping\n");
680 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
681 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed with %08x\n", hr);
684 /* Test another EndScene without having begun a new scene. Should return an error */
685 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
686 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
688 /* Two nested BeginScene and EndScene calls */
689 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
690 ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed with %08x\n", hr);
691 hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
692 ok(hr == D3DERR_SCENE_IN_SCENE, "IDirect3DDevice7_BeginScene returned %08x\n", hr);
693 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
694 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed with %08x\n", hr);
695 hr = IDirect3DDevice7_EndScene(lpD3DDevice);
696 ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
698 /* TODO: Verify that blitting works in the same way as in d3d9 */
701 static void LimitTest(void)
703 IDirectDrawSurface7 *pTexture = NULL;
704 HRESULT hr;
705 int i;
706 DDSURFACEDESC2 ddsd;
708 memset(&ddsd, 0, sizeof(ddsd));
709 ddsd.dwSize = sizeof(ddsd);
710 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
711 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
712 ddsd.dwWidth = 16;
713 ddsd.dwHeight = 16;
714 hr = IDirectDraw7_CreateSurface(lpDD, &ddsd, &pTexture, NULL);
715 ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
716 if(!pTexture) return;
718 for(i = 0; i < 8; i++) {
719 hr = IDirect3DDevice7_SetTexture(lpD3DDevice, i, pTexture);
720 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %08x\n", i, hr);
721 hr = IDirect3DDevice7_SetTexture(lpD3DDevice, i, NULL);
722 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %08x\n", i, hr);
723 hr = IDirect3DDevice7_SetTextureStageState(lpD3DDevice, i, D3DTSS_COLOROP, D3DTOP_ADD);
724 ok(hr == D3D_OK, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %08x\n", i, hr);
727 IDirectDrawSurface7_Release(pTexture);
730 static HRESULT WINAPI enumDevicesCallback(GUID *Guid,LPSTR DeviceDescription,LPSTR DeviceName, D3DDEVICEDESC *hal, D3DDEVICEDESC *hel, VOID *ctx)
732 UINT ver = *((UINT *) ctx);
733 if(IsEqualGUID(&IID_IDirect3DRGBDevice, Guid))
735 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
736 "RGB Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
737 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
738 "RGB Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
739 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
740 "RGB Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
741 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
742 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
744 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
745 "RGB Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
746 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
747 "RGB Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
748 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
749 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
750 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
751 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
753 else if(IsEqualGUID(&IID_IDirect3DHALDevice, Guid))
755 /* pow2 is hardware dependent */
757 ok(hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
758 "HAL Device %d hal line caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
759 ok(hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
760 "HAL Device %d hal tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
761 ok((hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
762 "HAL Device %d hel line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
763 ok((hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
764 "HAL Device %d hel tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
766 else if(IsEqualGUID(&IID_IDirect3DRefDevice, Guid))
768 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
769 "REF Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
770 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
771 "REF Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
772 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
773 "REF Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
774 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
775 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
777 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
778 "REF Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
779 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
780 "REF Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
781 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
782 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
783 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
784 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
786 else if(IsEqualGUID(&IID_IDirect3DRampDevice, Guid))
788 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
789 "Ramp Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
790 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
791 "Ramp Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
792 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
793 "Ramp Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
794 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
795 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
797 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
798 "Ramp Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
799 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
800 "Ramp Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
801 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
802 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
803 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
804 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
806 else if(IsEqualGUID(&IID_IDirect3DMMXDevice, Guid))
808 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
809 "MMX Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
810 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
811 "MMX Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
812 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
813 "MMX Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
814 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
815 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
817 ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
818 "MMX Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
819 ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
820 "MMX Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
821 ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
822 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
823 ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
824 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
826 else
828 ok(FALSE, "Unexpected device enumerated: \"%s\" \"%s\"\n", DeviceDescription, DeviceName);
829 if(hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hal line has pow2 set\n");
830 else trace("hal line does NOT have pow2 set\n");
831 if(hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hal tri has pow2 set\n");
832 else trace("hal tri does NOT have pow2 set\n");
833 if(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hel line has pow2 set\n");
834 else trace("hel line does NOT have pow2 set\n");
835 if(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hel tri has pow2 set\n");
836 else trace("hel tri does NOT have pow2 set\n");
838 return DDENUMRET_OK;
841 static HRESULT WINAPI enumDevicesCallbackTest7(LPSTR DeviceDescription, LPSTR DeviceName, LPD3DDEVICEDESC7 lpdd7, LPVOID Context)
843 D3D7ETest *d3d7et = (D3D7ETest*)Context;
844 if(IsEqualGUID(&lpdd7->deviceGUID, &IID_IDirect3DRGBDevice))
845 d3d7et->rgb++;
846 else if(IsEqualGUID(&lpdd7->deviceGUID, &IID_IDirect3DHALDevice))
847 d3d7et->hal++;
848 else if(IsEqualGUID(&lpdd7->deviceGUID, &IID_IDirect3DTnLHalDevice))
849 d3d7et->tnlhal++;
850 else
851 d3d7et->unk++;
853 d3d7et->total++;
855 return DDENUMRET_OK;
859 /* Check the deviceGUID of devices enumerated by
860 IDirect3D7_EnumDevices. */
861 static void D3D7EnumTest(void)
863 D3D7ETest d3d7et;
865 if (!lpD3D) {
866 skip("No Direct3D7 interface.\n");
867 return;
870 memset(&d3d7et, 0, sizeof(d3d7et));
871 IDirect3D7_EnumDevices(lpD3D, enumDevicesCallbackTest7, (LPVOID) &d3d7et);
874 /* A couple of games (Delta Force LW and TFD) rely on this behaviour */
875 ok(d3d7et.tnlhal < d3d7et.total, "TnLHal device enumerated as only device.\n");
877 /* We make two additional assumptions. */
878 ok(d3d7et.rgb, "No RGB Device enumerated.\n");
880 if(d3d7et.tnlhal)
881 ok(d3d7et.hal, "TnLHal device enumerated, but no Hal device found.\n");
883 return;
886 static void CapsTest(void)
888 IDirect3D3 *d3d3;
889 IDirect3D3 *d3d2;
890 IDirectDraw *dd1;
891 HRESULT hr;
892 UINT ver;
894 hr = DirectDrawCreate(NULL, &dd1, NULL);
895 ok(hr == DD_OK, "Cannot create a DirectDraw 1 interface, hr = %08x\n", hr);
896 hr = IDirectDraw_QueryInterface(dd1, &IID_IDirect3D3, (void **) &d3d3);
897 ok(hr == D3D_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
898 ver = 3;
899 IDirect3D3_EnumDevices(d3d3, enumDevicesCallback, &ver);
901 IDirect3D3_Release(d3d3);
902 IDirectDraw_Release(dd1);
904 hr = DirectDrawCreate(NULL, &dd1, NULL);
905 ok(hr == DD_OK, "Cannot create a DirectDraw 1 interface, hr = %08x\n", hr);
906 hr = IDirectDraw_QueryInterface(dd1, &IID_IDirect3D2, (void **) &d3d2);
907 ok(hr == D3D_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
908 ver = 2;
909 IDirect3D2_EnumDevices(d3d2, enumDevicesCallback, &ver);
911 IDirect3D2_Release(d3d2);
912 IDirectDraw_Release(dd1);
915 struct v_in {
916 float x, y, z;
918 struct v_out {
919 float x, y, z, rhw;
922 static BOOL D3D1_createObjects(void)
924 HRESULT hr;
925 DDSURFACEDESC ddsd;
926 D3DEXECUTEBUFFERDESC desc;
927 D3DVIEWPORT vp_data;
929 /* An IDirect3DDevice cannot be queryInterfaced from an IDirect3DDevice7 on windows */
930 hr = DirectDrawCreate(NULL, &DirectDraw1, NULL);
931 ok(hr==DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreate returned: %x\n", hr);
932 if (!DirectDraw1) {
933 return FALSE;
936 hr = IDirectDraw_SetCooperativeLevel(DirectDraw1, NULL, DDSCL_NORMAL);
937 ok(hr==DD_OK, "SetCooperativeLevel returned: %x\n", hr);
939 hr = IDirectDraw_QueryInterface(DirectDraw1, &IID_IDirect3D, (void**) &Direct3D1);
940 ok(hr==DD_OK, "QueryInterface returned: %x\n", hr);
941 if (!Direct3D1) {
942 return FALSE;
945 memset(&ddsd, 0, sizeof(ddsd));
946 ddsd.dwSize = sizeof(ddsd);
947 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
948 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
949 ddsd.dwWidth = 256;
950 ddsd.dwHeight = 256;
951 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &Surface1, NULL);
952 ok(hr==DD_OK, "CreateSurface returned: %x\n", hr);
953 if (!Surface1) {
954 return FALSE;
957 hr = IDirectDrawSurface_QueryInterface(Surface1, &IID_IDirect3DRGBDevice, (void **) &Direct3DDevice1);
958 ok(hr==D3D_OK || hr==DDERR_NOPALETTEATTACHED || hr==E_OUTOFMEMORY, "CreateDevice returned: %x\n", hr);
959 if(!Direct3DDevice1) {
960 return FALSE;
963 memset(&desc, 0, sizeof(desc));
964 desc.dwSize = sizeof(desc);
965 desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
966 desc.dwCaps = D3DDEBCAPS_VIDEOMEMORY;
967 desc.dwBufferSize = 128;
968 desc.lpData = NULL;
969 hr = IDirect3DDevice_CreateExecuteBuffer(Direct3DDevice1, &desc, &ExecuteBuffer, NULL);
970 ok(hr == D3D_OK, "IDirect3DDevice_CreateExecuteBuffer failed: %08x\n", hr);
971 if(!ExecuteBuffer) {
972 return FALSE;
975 hr = IDirect3D_CreateViewport(Direct3D1, &Viewport, NULL);
976 ok(hr == D3D_OK, "IDirect3D_CreateViewport failed: %08x\n", hr);
977 if(!Viewport) {
978 return FALSE;
981 hr = IDirect3DViewport_Initialize(Viewport, Direct3D1);
982 ok(hr == DDERR_ALREADYINITIALIZED, "IDirect3DViewport_Initialize returned %08x\n", hr);
984 hr = IDirect3DDevice_AddViewport(Direct3DDevice1, Viewport);
985 ok(hr == D3D_OK, "IDirect3DDevice_AddViewport returned %08x\n", hr);
986 vp_data.dwSize = sizeof(vp_data);
987 vp_data.dwX = 0;
988 vp_data.dwY = 0;
989 vp_data.dwWidth = 256;
990 vp_data.dwHeight = 256;
991 vp_data.dvScaleX = 1;
992 vp_data.dvScaleY = 1;
993 vp_data.dvMaxX = 256;
994 vp_data.dvMaxY = 256;
995 vp_data.dvMinZ = 0;
996 vp_data.dvMaxZ = 1;
997 hr = IDirect3DViewport_SetViewport(Viewport, &vp_data);
998 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1000 return TRUE;
1003 static void D3D1_releaseObjects(void)
1005 if (Viewport) IDirect3DViewport_Release(Viewport);
1006 if (ExecuteBuffer) IDirect3DExecuteBuffer_Release(ExecuteBuffer);
1007 if (Direct3DDevice1) IDirect3DDevice_Release(Direct3DDevice1);
1008 if (Surface1) IDirectDrawSurface_Release(Surface1);
1009 if (Direct3D1) IDirect3D_Release(Direct3D1);
1010 if (DirectDraw1) IDirectDraw_Release(DirectDraw1);
1013 static void Direct3D1Test(void)
1015 HRESULT hr;
1016 D3DEXECUTEBUFFERDESC desc;
1017 D3DVIEWPORT vp_data;
1018 D3DINSTRUCTION *instr;
1019 D3DBRANCH *branch;
1020 unsigned int idx = 0;
1021 static struct v_in testverts[] = {
1022 {0.0, 0.0, 0.0}, { 1.0, 1.0, 1.0}, {-1.0, -1.0, -1.0},
1023 {0.5, 0.5, 0.5}, {-0.5, -0.5, -0.5}, {-0.5, -0.5, 0.0},
1025 static struct v_in cliptest[] = {
1026 {25.59, 25.59, 1.0}, {-25.59, -25.59, 0.0},
1027 {25.61, 25.61, 1.01}, {-25.61, -25.61, -0.01},
1029 static struct v_in offscreentest[] = {
1030 {128.1, 0.0, 0.0},
1032 struct v_out out[sizeof(testverts) / sizeof(testverts[0])];
1033 D3DHVERTEX outH[sizeof(testverts) / sizeof(testverts[0])];
1034 D3DTRANSFORMDATA transformdata;
1035 DWORD i = FALSE;
1037 memset(&desc, 0, sizeof(desc));
1038 desc.dwSize = sizeof(desc);
1039 hr = IDirect3DExecuteBuffer_Lock(ExecuteBuffer, &desc);
1040 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Lock failed: %08x\n", hr);
1042 memset(desc.lpData, 0, 128);
1043 instr = desc.lpData;
1044 instr[idx].bOpcode = D3DOP_BRANCHFORWARD;
1045 instr[idx].bSize = sizeof(*branch);
1046 instr[idx].wCount = 1;
1047 idx++;
1048 branch = (D3DBRANCH *) &instr[idx];
1049 branch->dwMask = 0x0;
1050 branch->dwValue = 1;
1051 branch->bNegate = TRUE;
1052 branch->dwOffset = 0;
1053 idx += (sizeof(*branch) / sizeof(*instr));
1054 instr[idx].bOpcode = D3DOP_EXIT;
1055 instr[idx].bSize = 0;
1056 instr[idx].wCount = 0;
1057 hr = IDirect3DExecuteBuffer_Unlock(ExecuteBuffer);
1058 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Unlock failed: %08x\n", hr);
1060 hr = IDirect3DDevice_Execute(Direct3DDevice1, ExecuteBuffer, Viewport, D3DEXECUTE_CLIPPED);
1061 ok(hr == D3D_OK, "IDirect3DDevice_Execute returned %08x\n", hr);
1063 memset(&desc, 0, sizeof(desc));
1064 desc.dwSize = sizeof(desc);
1066 hr = IDirect3DExecuteBuffer_Lock(ExecuteBuffer, &desc);
1067 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Lock failed: %08x\n", hr);
1069 memset(desc.lpData, 0, 128);
1070 instr = desc.lpData;
1071 idx = 0;
1072 instr[idx].bOpcode = D3DOP_BRANCHFORWARD;
1073 instr[idx].bSize = sizeof(*branch);
1074 instr[idx].wCount = 1;
1075 idx++;
1076 branch = (D3DBRANCH *) &instr[idx];
1077 branch->dwMask = 0x0;
1078 branch->dwValue = 1;
1079 branch->bNegate = TRUE;
1080 branch->dwOffset = 64;
1081 instr = (D3DINSTRUCTION*)((char*)desc.lpData + 64);
1082 instr[0].bOpcode = D3DOP_EXIT;
1083 instr[0].bSize = 0;
1084 instr[0].wCount = 0;
1085 hr = IDirect3DExecuteBuffer_Unlock(ExecuteBuffer);
1086 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Unlock failed: %08x\n", hr);
1088 hr = IDirect3DDevice_Execute(Direct3DDevice1, ExecuteBuffer, Viewport, D3DEXECUTE_CLIPPED);
1089 ok(hr == D3D_OK, "IDirect3DDevice_Execute returned %08x\n", hr);
1091 /* Test rendering 0 triangles */
1092 memset(&desc, 0, sizeof(desc));
1093 desc.dwSize = sizeof(desc);
1095 hr = IDirect3DExecuteBuffer_Lock(ExecuteBuffer, &desc);
1096 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Lock failed: %08x\n", hr);
1098 memset(desc.lpData, 0, 128);
1099 instr = desc.lpData;
1100 idx = 0;
1102 instr->bOpcode = D3DOP_TRIANGLE;
1103 instr->bSize = sizeof(D3DOP_TRIANGLE);
1104 instr->wCount = 0;
1105 instr = ((D3DINSTRUCTION*)(instr))+1;
1106 instr->bOpcode = D3DOP_EXIT;
1107 instr->bSize = 0;
1108 instr->wCount = 0;
1109 hr = IDirect3DExecuteBuffer_Unlock(ExecuteBuffer);
1110 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Unlock failed: %08x\n", hr);
1112 hr = IDirect3DDevice_Execute(Direct3DDevice1, ExecuteBuffer, Viewport, D3DEXECUTE_CLIPPED);
1113 ok(hr == D3D_OK, "IDirect3DDevice_Execute returned %08x\n", hr);
1115 memset(&transformdata, 0, sizeof(transformdata));
1116 transformdata.dwSize = sizeof(transformdata);
1117 transformdata.lpIn = (void *) testverts;
1118 transformdata.dwInSize = sizeof(testverts[0]);
1119 transformdata.lpOut = out;
1120 transformdata.dwOutSize = sizeof(out[0]);
1122 transformdata.lpHOut = NULL;
1123 hr = IDirect3DViewport_TransformVertices(Viewport, sizeof(testverts) / sizeof(testverts[0]),
1124 &transformdata, D3DTRANSFORM_UNCLIPPED,
1125 &i);
1126 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1128 transformdata.lpHOut = outH;
1129 memset(outH, 0xcc, sizeof(outH));
1130 hr = IDirect3DViewport_TransformVertices(Viewport, sizeof(testverts) / sizeof(testverts[0]),
1131 &transformdata, D3DTRANSFORM_UNCLIPPED,
1132 &i);
1133 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1134 ok(i == 0, "Offscreen is %d\n", i);
1136 for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
1137 static const struct v_out cmp[] = {
1138 {128.0, 128.0, 0.0, 1}, {129.0, 127.0, 1.0, 1}, {127.0, 129.0, -1, 1},
1139 {128.5, 127.5, 0.5, 1}, {127.5, 128.5, -0.5, 1}, {127.5, 128.5, 0, 1}
1142 ok(cmp[i].x == out[i].x && cmp[i].y == out[i].y &&
1143 cmp[i].z == out[i].z && cmp[i].rhw == out[i].rhw,
1144 "Vertex %d differs. Got %f %f %f %f, expexted %f %f %f %f\n", i + 1,
1145 out[i].x, out[i].y, out[i].z, out[i].rhw,
1146 cmp[i].x, cmp[i].y, cmp[i].z, cmp[i].rhw);
1148 for(i = 0; i < sizeof(outH); i++) {
1149 if(((unsigned char *) outH)[i] != 0xcc) {
1150 ok(FALSE, "Homogeneous output was generated despite UNCLIPPED flag\n");
1151 break;
1155 vp_data.dwSize = sizeof(vp_data);
1156 vp_data.dwX = 0;
1157 vp_data.dwY = 0;
1158 vp_data.dwWidth = 256;
1159 vp_data.dwHeight = 256;
1160 vp_data.dvMaxX = 256;
1161 vp_data.dvMaxY = 256;
1162 vp_data.dvScaleX = 5;
1163 vp_data.dvScaleY = 5;
1164 vp_data.dvMinZ = -25;
1165 vp_data.dvMaxZ = 60;
1166 hr = IDirect3DViewport_SetViewport(Viewport, &vp_data);
1167 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1168 hr = IDirect3DViewport_TransformVertices(Viewport, sizeof(testverts) / sizeof(testverts[0]),
1169 &transformdata, D3DTRANSFORM_UNCLIPPED,
1170 &i);
1171 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1172 ok(i == 0, "Offscreen is %d\n", i);
1174 for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
1175 static const struct v_out cmp[] = {
1176 {128.0, 128.0, 0.0, 1}, {133.0, 123.0, 1.0, 1}, {123.0, 133.0, -1, 1},
1177 {130.5, 125.5, 0.5, 1}, {125.5, 130.5, -0.5, 1}, {125.5, 130.5, 0, 1}
1179 ok(cmp[i].x == out[i].x && cmp[i].y == out[i].y &&
1180 cmp[i].z == out[i].z && cmp[i].rhw == out[i].rhw,
1181 "Vertex %d differs. Got %f %f %f %f, expexted %f %f %f %f\n", i + 1,
1182 out[i].x, out[i].y, out[i].z, out[i].rhw,
1183 cmp[i].x, cmp[i].y, cmp[i].z, cmp[i].rhw);
1186 vp_data.dwX = 10;
1187 vp_data.dwY = 20;
1188 hr = IDirect3DViewport_SetViewport(Viewport, &vp_data);
1189 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1190 hr = IDirect3DViewport_TransformVertices(Viewport, sizeof(testverts) / sizeof(testverts[0]),
1191 &transformdata, D3DTRANSFORM_UNCLIPPED,
1192 &i);
1193 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1194 ok(i == 0, "Offscreen is %d\n", i);
1195 for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
1196 static const struct v_out cmp[] = {
1197 {138.0, 148.0, 0.0, 1}, {143.0, 143.0, 1.0, 1}, {133.0, 153.0, -1, 1},
1198 {140.5, 145.5, 0.5, 1}, {135.5, 150.5, -0.5, 1}, {135.5, 150.5, 0, 1}
1200 ok(cmp[i].x == out[i].x && cmp[i].y == out[i].y &&
1201 cmp[i].z == out[i].z && cmp[i].rhw == out[i].rhw,
1202 "Vertex %d differs. Got %f %f %f %f, expexted %f %f %f %f\n", i + 1,
1203 out[i].x, out[i].y, out[i].z, out[i].rhw,
1204 cmp[i].x, cmp[i].y, cmp[i].z, cmp[i].rhw);
1207 memset(out, 0xcc, sizeof(out));
1208 hr = IDirect3DViewport_TransformVertices(Viewport, sizeof(testverts) / sizeof(testverts[0]),
1209 &transformdata, D3DTRANSFORM_CLIPPED,
1210 &i);
1211 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1212 ok(i == 0, "Offscreen is %d\n", i);
1213 for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
1214 static const D3DHVERTEX cmpH[] = {
1215 {0, { 0.0}, { 0.0}, { 0.0}}, {0, { 1.0}, { 1.0}, {1.0}},
1216 {D3DCLIP_FRONT, {-1.0}, {-1.0}, {-1.0}}, {0, { 0.5}, { 0.5}, {0.5}},
1217 {D3DCLIP_FRONT, {-0.5}, {-0.5}, {-0.5}}, {0, {-0.5}, {-0.5}, {0.0}}
1219 ok(U1(cmpH[i]).hx == U1(outH[i]).hx && U2(cmpH[i]).hy == U2(outH[i]).hy &&
1220 U3(cmpH[i]).hz == U3(outH[i]).hz && cmpH[i].dwFlags == outH[i].dwFlags,
1221 "HVertex %d differs. Got %08x %f %f %f, expexted %08x %f %f %f\n", i + 1,
1222 outH[i].dwFlags, U1(outH[i]).hx, U2(outH[i]).hy, U3(outH[i]).hz,
1223 cmpH[i].dwFlags, U1(cmpH[i]).hx, U2(cmpH[i]).hy, U3(cmpH[i]).hz);
1225 /* No scheme has been found behind those return values. It seems to be
1226 * whatever data windows has when throwing the vertex away. Modify the
1227 * input test vertices to test this more. Depending on the input data
1228 * it can happen that the z coord gets written into y, or similar things
1230 if(0)
1232 static const struct v_out cmp[] = {
1233 {138.0, 148.0, 0.0, 1}, {143.0, 143.0, 1.0, 1}, { -1.0, -1.0, 0.5, 1},
1234 {140.5, 145.5, 0.5, 1}, { -0.5, -0.5, -0.5, 1}, {135.5, 150.5, 0.0, 1}
1236 ok(cmp[i].x == out[i].x && cmp[i].y == out[i].y &&
1237 cmp[i].z == out[i].z && cmp[i].rhw == out[i].rhw,
1238 "Vertex %d differs. Got %f %f %f %f, expexted %f %f %f %f\n", i + 1,
1239 out[i].x, out[i].y, out[i].z, out[i].rhw,
1240 cmp[i].x, cmp[i].y, cmp[i].z, cmp[i].rhw);
1243 for(i = 0; i < sizeof(out) / sizeof(DWORD); i++) {
1244 ok(((DWORD *) out)[i] != 0xcccccccc,
1245 "Regular output DWORD %d remained untouched\n", i);
1248 transformdata.lpIn = (void *) cliptest;
1249 transformdata.dwInSize = sizeof(cliptest[0]);
1250 hr = IDirect3DViewport_TransformVertices(Viewport, sizeof(cliptest) / sizeof(cliptest[0]),
1251 &transformdata, D3DTRANSFORM_CLIPPED,
1252 &i);
1253 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1254 ok(i == 0, "Offscreen is %d\n", i);
1255 for(i = 0; i < sizeof(cliptest) / sizeof(cliptest[0]); i++) {
1256 DWORD Flags[sizeof(cliptest) / sizeof(cliptest[0])] =
1260 D3DCLIP_RIGHT | D3DCLIP_BACK | D3DCLIP_TOP,
1261 D3DCLIP_LEFT | D3DCLIP_BOTTOM | D3DCLIP_FRONT,
1263 ok(Flags[i] == outH[i].dwFlags,
1264 "Cliptest %d differs. Got %08x expexted %08x\n", i + 1,
1265 outH[i].dwFlags, Flags[i]);
1268 vp_data.dwWidth = 10;
1269 vp_data.dwHeight = 1000;
1270 hr = IDirect3DViewport_SetViewport(Viewport, &vp_data);
1271 i = 10;
1272 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1273 hr = IDirect3DViewport_TransformVertices(Viewport, sizeof(cliptest) / sizeof(cliptest[0]),
1274 &transformdata, D3DTRANSFORM_CLIPPED,
1275 &i);
1276 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1277 ok(i == 0, "Offscreen is %d\n", i);
1278 for(i = 0; i < sizeof(cliptest) / sizeof(cliptest[0]); i++) {
1279 DWORD Flags[sizeof(cliptest) / sizeof(cliptest[0])] =
1281 D3DCLIP_RIGHT,
1282 D3DCLIP_LEFT,
1283 D3DCLIP_RIGHT | D3DCLIP_BACK,
1284 D3DCLIP_LEFT | D3DCLIP_FRONT,
1286 ok(Flags[i] == outH[i].dwFlags,
1287 "Cliptest %d differs. Got %08x expexted %08x\n", i + 1,
1288 outH[i].dwFlags, Flags[i]);
1290 vp_data.dwWidth = 256;
1291 vp_data.dwHeight = 256;
1292 vp_data.dvScaleX = 1;
1293 vp_data.dvScaleY = 1;
1294 hr = IDirect3DViewport_SetViewport(Viewport, &vp_data);
1295 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1296 hr = IDirect3DViewport_TransformVertices(Viewport, sizeof(cliptest) / sizeof(cliptest[0]),
1297 &transformdata, D3DTRANSFORM_CLIPPED,
1298 &i);
1299 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1300 ok(i == 0, "Offscreen is %s\n", i ? "TRUE" : "FALSE");
1301 for(i = 0; i < sizeof(cliptest) / sizeof(cliptest[0]); i++) {
1302 DWORD Flags[sizeof(cliptest) / sizeof(cliptest[0])] =
1306 D3DCLIP_BACK,
1307 D3DCLIP_FRONT,
1309 ok(Flags[i] == outH[i].dwFlags,
1310 "Cliptest %d differs. Got %08x expexted %08x\n", i + 1,
1311 outH[i].dwFlags, Flags[i]);
1314 /* Finally try to figure out how the DWORD dwOffscreen works.
1315 * Apparently no vertex is offscreen with clipping off,
1316 * and with clipping on the offscreen flag is set if only one vertex
1317 * is transformed, and this vertex is offscreen.
1319 vp_data.dwWidth = 5;
1320 vp_data.dwHeight = 5;
1321 vp_data.dvScaleX = 10000;
1322 vp_data.dvScaleY = 10000;
1323 hr = IDirect3DViewport_SetViewport(Viewport, &vp_data);
1324 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1325 transformdata.lpIn = cliptest;
1326 hr = IDirect3DViewport_TransformVertices(Viewport, 1,
1327 &transformdata, D3DTRANSFORM_UNCLIPPED,
1328 &i);
1329 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1330 ok(i == 0, "Offscreen is %d\n", i);
1331 hr = IDirect3DViewport_TransformVertices(Viewport, 1,
1332 &transformdata, D3DTRANSFORM_CLIPPED,
1333 &i);
1334 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1335 ok(i == (D3DCLIP_RIGHT | D3DCLIP_TOP), "Offscreen is %d\n", i);
1336 hr = IDirect3DViewport_TransformVertices(Viewport, 2,
1337 &transformdata, D3DTRANSFORM_CLIPPED,
1338 &i);
1339 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1340 ok(i == 0, "Offscreen is %d\n", i);
1341 transformdata.lpIn = cliptest + 1;
1342 hr = IDirect3DViewport_TransformVertices(Viewport, 1,
1343 &transformdata, D3DTRANSFORM_CLIPPED,
1344 &i);
1345 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1346 ok(i == (D3DCLIP_BOTTOM | D3DCLIP_LEFT), "Offscreen is %d\n", i);
1348 transformdata.lpIn = (void *) offscreentest;
1349 transformdata.dwInSize = sizeof(offscreentest[0]);
1350 vp_data.dwWidth = 257;
1351 vp_data.dwHeight = 257;
1352 vp_data.dvScaleX = 1;
1353 vp_data.dvScaleY = 1;
1354 hr = IDirect3DViewport_SetViewport(Viewport, &vp_data);
1355 i = 12345;
1356 hr = IDirect3DViewport_TransformVertices(Viewport, sizeof(offscreentest) / sizeof(offscreentest[0]),
1357 &transformdata, D3DTRANSFORM_CLIPPED,
1358 &i);
1359 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1360 ok(i == 0, "Offscreen is %d\n", i);
1361 vp_data.dwWidth = 256;
1362 vp_data.dwHeight = 256;
1363 hr = IDirect3DViewport_SetViewport(Viewport, &vp_data);
1364 i = 12345;
1365 hr = IDirect3DViewport_TransformVertices(Viewport, sizeof(offscreentest) / sizeof(offscreentest[0]),
1366 &transformdata, D3DTRANSFORM_CLIPPED,
1367 &i);
1368 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1369 ok(i == D3DCLIP_RIGHT, "Offscreen is %d\n", i);
1371 hr = IDirect3DViewport_TransformVertices(Viewport, sizeof(testverts) / sizeof(testverts[0]),
1372 &transformdata, 0,
1373 &i);
1374 ok(hr == DDERR_INVALIDPARAMS, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1376 hr = IDirect3DDevice_DeleteViewport(Direct3DDevice1, Viewport);
1377 ok(hr == D3D_OK, "IDirect3DDevice_DeleteViewport returned %08x\n", hr);
1380 static BOOL colortables_check_equality(PALETTEENTRY table1[256], PALETTEENTRY table2[256])
1382 int i;
1384 for (i = 0; i < 256; i++) {
1385 if (table1[i].peRed != table2[i].peRed || table1[i].peGreen != table2[i].peGreen ||
1386 table1[i].peBlue != table2[i].peBlue) return FALSE;
1389 return TRUE;
1392 /* test palette handling in IDirect3DTexture_Load */
1393 static void TextureLoadTest(void)
1395 IDirectDrawSurface *TexSurface = NULL;
1396 IDirect3DTexture *Texture = NULL;
1397 IDirectDrawSurface *TexSurface2 = NULL;
1398 IDirect3DTexture *Texture2 = NULL;
1399 IDirectDrawPalette *palette = NULL;
1400 IDirectDrawPalette *palette2 = NULL;
1401 IDirectDrawPalette *palette_tmp = NULL;
1402 PALETTEENTRY table1[256], table2[256], table_tmp[256];
1403 HRESULT hr;
1404 DDSURFACEDESC ddsd;
1405 int i;
1407 memset (&ddsd, 0, sizeof (ddsd));
1408 ddsd.dwSize = sizeof (ddsd);
1409 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
1410 ddsd.dwHeight = 128;
1411 ddsd.dwWidth = 128;
1412 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1413 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
1414 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED8;
1415 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 8;
1417 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &TexSurface, NULL);
1418 ok(hr==D3D_OK, "CreateSurface returned: %x\n", hr);
1419 if (FAILED(hr)) {
1420 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1421 goto cleanup;
1424 hr = IDirectDrawSurface_QueryInterface(TexSurface, &IID_IDirect3DTexture,
1425 (void *)&Texture);
1426 ok(hr==D3D_OK, "IDirectDrawSurface_QueryInterface returned: %x\n", hr);
1427 if (FAILED(hr)) {
1428 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1429 goto cleanup;
1432 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &TexSurface2, NULL);
1433 ok(hr==D3D_OK, "CreateSurface returned: %x\n", hr);
1434 if (FAILED(hr)) {
1435 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1436 goto cleanup;
1439 hr = IDirectDrawSurface_QueryInterface(TexSurface2, &IID_IDirect3DTexture,
1440 (void *)&Texture2);
1441 ok(hr==D3D_OK, "IDirectDrawSurface_QueryInterface returned: %x\n", hr);
1442 if (FAILED(hr)) {
1443 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1444 goto cleanup;
1447 /* test Load when both textures have no palette */
1448 hr = IDirect3DTexture_Load(Texture2, Texture);
1449 ok(hr == DD_OK, "IDirect3DTexture_Load returned %08x\n", hr);
1451 for (i = 0; i < 256; i++) {
1452 table1[i].peRed = i;
1453 table1[i].peGreen = i;
1454 table1[i].peBlue = i;
1455 table1[i].peFlags = 0;
1458 hr = IDirectDraw_CreatePalette(DirectDraw1, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, table1, &palette, NULL);
1459 ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
1460 if (FAILED(hr)) {
1461 skip("IDirectDraw_CreatePalette failed; skipping further tests\n");
1462 goto cleanup;
1465 /* test Load when source texture has palette and destination has no palette */
1466 hr = IDirectDrawSurface_SetPalette(TexSurface, palette);
1467 ok(hr == DD_OK, "IDirectDrawSurface_SetPalette returned %08x\n", hr);
1468 hr = IDirect3DTexture_Load(Texture2, Texture);
1469 ok(hr == DDERR_NOPALETTEATTACHED, "IDirect3DTexture_Load returned %08x\n", hr);
1471 for (i = 0; i < 256; i++) {
1472 table2[i].peRed = 255 - i;
1473 table2[i].peGreen = 255 - i;
1474 table2[i].peBlue = 255 - i;
1475 table2[i].peFlags = 0;
1478 hr = IDirectDraw_CreatePalette(DirectDraw1, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, table2, &palette2, NULL);
1479 ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
1480 if (FAILED(hr)) {
1481 skip("IDirectDraw_CreatePalette failed; skipping further tests\n");
1482 goto cleanup;
1485 /* test Load when source has no palette and destination has a palette */
1486 hr = IDirectDrawSurface_SetPalette(TexSurface, NULL);
1487 ok(hr == DD_OK, "IDirectDrawSurface_SetPalette returned %08x\n", hr);
1488 hr = IDirectDrawSurface_SetPalette(TexSurface2, palette2);
1489 ok(hr == DD_OK, "IDirectDrawSurface_SetPalette returned %08x\n", hr);
1490 hr = IDirect3DTexture_Load(Texture2, Texture);
1491 ok(hr == DD_OK, "IDirect3DTexture_Load returned %08x\n", hr);
1492 hr = IDirectDrawSurface_GetPalette(TexSurface2, &palette_tmp);
1493 ok(hr == DD_OK, "IDirectDrawSurface_GetPalette returned %08x\n", hr);
1494 if (!palette_tmp) {
1495 skip("IDirectDrawSurface_GetPalette failed; skipping color table check\n");
1496 goto cleanup;
1497 } else {
1498 hr = IDirectDrawPalette_GetEntries(palette_tmp, 0, 0, 256, table_tmp);
1499 ok(hr == DD_OK, "IDirectDrawPalette_GetEntries returned %08x\n", hr);
1500 ok(colortables_check_equality(table2, table_tmp), "Unexpected palettized texture color table\n");
1501 IDirectDrawPalette_Release(palette_tmp);
1504 /* test Load when both textures have palettes */
1505 hr = IDirectDrawSurface_SetPalette(TexSurface, palette);
1506 ok(hr == DD_OK, "IDirectDrawSurface_SetPalette returned %08x\n", hr);
1507 hr = IDirect3DTexture_Load(Texture2, Texture);
1508 ok(hr == DD_OK, "IDirect3DTexture_Load returned %08x\n", hr);
1509 hr = IDirect3DTexture_Load(Texture2, Texture);
1510 ok(hr == DD_OK, "IDirect3DTexture_Load returned %08x\n", hr);
1511 hr = IDirectDrawSurface_GetPalette(TexSurface2, &palette_tmp);
1512 ok(hr == DD_OK, "IDirectDrawSurface_GetPalette returned %08x\n", hr);
1513 if (!palette_tmp) {
1514 skip("IDirectDrawSurface_GetPalette failed; skipping color table check\n");
1515 goto cleanup;
1516 } else {
1517 hr = IDirectDrawPalette_GetEntries(palette_tmp, 0, 0, 256, table_tmp);
1518 ok(hr == DD_OK, "IDirectDrawPalette_GetEntries returned %08x\n", hr);
1519 ok(colortables_check_equality(table1, table_tmp), "Unexpected palettized texture color table\n");
1520 IDirectDrawPalette_Release(palette_tmp);
1523 cleanup:
1525 if (palette) IDirectDrawPalette_Release(palette);
1526 if (palette2) IDirectDrawPalette_Release(palette2);
1527 if (TexSurface) IDirectDrawSurface_Release(TexSurface);
1528 if (Texture) IDirect3DTexture_Release(Texture);
1529 if (TexSurface2) IDirectDrawSurface_Release(TexSurface2);
1530 if (Texture2) IDirect3DTexture_Release(Texture2);
1533 static void VertexBufferDescTest(void)
1535 HRESULT rc;
1536 D3DVERTEXBUFFERDESC desc;
1537 union mem_t
1539 D3DVERTEXBUFFERDESC desc2;
1540 unsigned char buffer[512];
1541 } mem;
1543 memset(&desc, 0, sizeof(desc));
1544 desc.dwSize = sizeof(desc);
1545 desc.dwCaps = 0;
1546 desc.dwFVF = D3DFVF_XYZ;
1547 desc.dwNumVertices = 1;
1548 rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufSrc, 0);
1549 ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
1550 if (!lpVBufSrc)
1552 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
1553 goto out;
1556 memset(mem.buffer, 0x12, sizeof(mem.buffer));
1557 mem.desc2.dwSize = sizeof(D3DVERTEXBUFFERDESC)*2;
1558 rc = IDirect3DVertexBuffer7_GetVertexBufferDesc(lpVBufSrc, &mem.desc2);
1559 if(rc != D3D_OK)
1560 skip("GetVertexBuffer Failed!\n");
1561 ok( mem.desc2.dwSize == sizeof(D3DVERTEXBUFFERDESC)*2, "Size returned from GetVertexBufferDesc does not match the value put in\n" );
1562 ok( mem.buffer[sizeof(D3DVERTEXBUFFERDESC)] == 0x12, "GetVertexBufferDesc cleared outside of the struct! (dwSize was double the size of the struct)\n");
1563 ok( mem.desc2.dwCaps == desc.dwCaps, "dwCaps returned differs. Got %x, expected %x\n", mem.desc2.dwCaps, desc.dwCaps);
1564 ok( mem.desc2.dwFVF == desc.dwFVF, "dwFVF returned differs. Got %x, expected %x\n", mem.desc2.dwFVF, desc.dwFVF);
1565 ok (mem.desc2.dwNumVertices == desc.dwNumVertices, "dwNumVertices returned differs. Got %x, expected %x\n", mem.desc2.dwNumVertices, desc.dwNumVertices);
1567 memset(mem.buffer, 0x12, sizeof(mem.buffer));
1568 mem.desc2.dwSize = 0;
1569 rc = IDirect3DVertexBuffer7_GetVertexBufferDesc(lpVBufSrc, &mem.desc2);
1570 if(rc != D3D_OK)
1571 skip("GetVertexBuffer Failed!\n");
1572 ok( mem.desc2.dwSize == 0, "Size returned from GetVertexBufferDesc does not match the value put in\n" );
1573 ok( mem.buffer[sizeof(D3DVERTEXBUFFERDESC)] == 0x12, "GetVertexBufferDesc cleared outside of the struct! (dwSize was 0)\n");
1574 ok( mem.desc2.dwCaps == desc.dwCaps, "dwCaps returned differs. Got %x, expected %x\n", mem.desc2.dwCaps, desc.dwCaps);
1575 ok( mem.desc2.dwFVF == desc.dwFVF, "dwFVF returned differs. Got %x, expected %x\n", mem.desc2.dwFVF, desc.dwFVF);
1576 ok (mem.desc2.dwNumVertices == desc.dwNumVertices, "dwNumVertices returned differs. Got %x, expected %x\n", mem.desc2.dwNumVertices, desc.dwNumVertices);
1578 memset(mem.buffer, 0x12, sizeof(mem.buffer));
1579 mem.desc2.dwSize = sizeof(D3DVERTEXBUFFERDESC);
1580 rc = IDirect3DVertexBuffer7_GetVertexBufferDesc(lpVBufSrc, &mem.desc2);
1581 if(rc != D3D_OK)
1582 skip("GetVertexBuffer Failed!\n");
1583 ok( mem.desc2.dwSize == sizeof(D3DVERTEXBUFFERDESC), "Size returned from GetVertexBufferDesc does not match the value put in\n" );
1584 ok( mem.buffer[sizeof(D3DVERTEXBUFFERDESC)] == 0x12, "GetVertexBufferDesc cleared outside of the struct! (dwSize was the size of the struct)\n");
1585 ok( mem.desc2.dwCaps == desc.dwCaps, "dwCaps returned differs. Got %x, expected %x\n", mem.desc2.dwCaps, desc.dwCaps);
1586 ok( mem.desc2.dwFVF == desc.dwFVF, "dwFVF returned differs. Got %x, expected %x\n", mem.desc2.dwFVF, desc.dwFVF);
1587 ok (mem.desc2.dwNumVertices == desc.dwNumVertices, "dwNumVertices returned differs. Got %x, expected %x\n", mem.desc2.dwNumVertices, desc.dwNumVertices);
1589 out:
1590 IDirect3DVertexBuffer7_Release(lpVBufSrc);
1594 START_TEST(d3d)
1596 init_function_pointers();
1597 if(!pDirectDrawCreateEx) {
1598 skip("function DirectDrawCreateEx not available\n");
1599 return;
1602 if(!CreateDirect3D()) {
1603 skip("Skipping d3d7 tests\n");
1604 } else {
1605 LightTest();
1606 ProcessVerticesTest();
1607 StateTest();
1608 SceneTest();
1609 LimitTest();
1610 D3D7EnumTest();
1611 CapsTest();
1612 VertexBufferDescTest();
1613 ReleaseDirect3D();
1616 if (!D3D1_createObjects()) {
1617 skip("Skipping d3d1 tests\n");
1618 } else {
1619 Direct3D1Test();
1620 TextureLoadTest();
1621 D3D1_releaseObjects();