dmusic: Assign to structs instead of using memcpy.
[wine.git] / dlls / ddraw / tests / d3d.c
blob678b1f0f196b1b388f1b1b4fd545f48a6f388d7a
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 memset(&transformdata, 0, sizeof(transformdata));
1092 transformdata.dwSize = sizeof(transformdata);
1093 transformdata.lpIn = (void *) testverts;
1094 transformdata.dwInSize = sizeof(testverts[0]);
1095 transformdata.lpOut = out;
1096 transformdata.dwOutSize = sizeof(out[0]);
1098 transformdata.lpHOut = NULL;
1099 hr = IDirect3DViewport_TransformVertices(Viewport, sizeof(testverts) / sizeof(testverts[0]),
1100 &transformdata, D3DTRANSFORM_UNCLIPPED,
1101 &i);
1102 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1104 transformdata.lpHOut = outH;
1105 memset(outH, 0xaa, sizeof(outH));
1106 hr = IDirect3DViewport_TransformVertices(Viewport, sizeof(testverts) / sizeof(testverts[0]),
1107 &transformdata, D3DTRANSFORM_UNCLIPPED,
1108 &i);
1109 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1110 ok(i == 0, "Offscreen is %d\n", i);
1112 for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
1113 static const struct v_out cmp[] = {
1114 {128.0, 128.0, 0.0, 1}, {129.0, 127.0, 1.0, 1}, {127.0, 129.0, -1, 1},
1115 {128.5, 127.5, 0.5, 1}, {127.5, 128.5, -0.5, 1}, {127.5, 128.5, 0, 1}
1118 ok(cmp[i].x == out[i].x && cmp[i].y == out[i].y &&
1119 cmp[i].z == out[i].z && cmp[i].rhw == out[i].rhw,
1120 "Vertex %d differs. Got %f %f %f %f, expexted %f %f %f %f\n", i + 1,
1121 out[i].x, out[i].y, out[i].z, out[i].rhw,
1122 cmp[i].x, cmp[i].y, cmp[i].z, cmp[i].rhw);
1124 for(i = 0; i < sizeof(outH); i++) {
1125 if(((unsigned char *) outH)[i] != 0xaa) {
1126 ok(FALSE, "Homogeneous output was generated despite UNCLIPPED flag\n");
1127 break;
1131 vp_data.dwSize = sizeof(vp_data);
1132 vp_data.dwX = 0;
1133 vp_data.dwY = 0;
1134 vp_data.dwWidth = 256;
1135 vp_data.dwHeight = 256;
1136 vp_data.dvMaxX = 256;
1137 vp_data.dvMaxY = 256;
1138 vp_data.dvScaleX = 5;
1139 vp_data.dvScaleY = 5;
1140 vp_data.dvMinZ = -25;
1141 vp_data.dvMaxZ = 60;
1142 hr = IDirect3DViewport_SetViewport(Viewport, &vp_data);
1143 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1144 hr = IDirect3DViewport_TransformVertices(Viewport, sizeof(testverts) / sizeof(testverts[0]),
1145 &transformdata, D3DTRANSFORM_UNCLIPPED,
1146 &i);
1147 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1148 ok(i == 0, "Offscreen is %d\n", i);
1150 for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
1151 static const struct v_out cmp[] = {
1152 {128.0, 128.0, 0.0, 1}, {133.0, 123.0, 1.0, 1}, {123.0, 133.0, -1, 1},
1153 {130.5, 125.5, 0.5, 1}, {125.5, 130.5, -0.5, 1}, {125.5, 130.5, 0, 1}
1155 ok(cmp[i].x == out[i].x && cmp[i].y == out[i].y &&
1156 cmp[i].z == out[i].z && cmp[i].rhw == out[i].rhw,
1157 "Vertex %d differs. Got %f %f %f %f, expexted %f %f %f %f\n", i + 1,
1158 out[i].x, out[i].y, out[i].z, out[i].rhw,
1159 cmp[i].x, cmp[i].y, cmp[i].z, cmp[i].rhw);
1162 vp_data.dwX = 10;
1163 vp_data.dwY = 20;
1164 hr = IDirect3DViewport_SetViewport(Viewport, &vp_data);
1165 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1166 hr = IDirect3DViewport_TransformVertices(Viewport, sizeof(testverts) / sizeof(testverts[0]),
1167 &transformdata, D3DTRANSFORM_UNCLIPPED,
1168 &i);
1169 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1170 ok(i == 0, "Offscreen is %d\n", i);
1171 for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
1172 static const struct v_out cmp[] = {
1173 {138.0, 148.0, 0.0, 1}, {143.0, 143.0, 1.0, 1}, {133.0, 153.0, -1, 1},
1174 {140.5, 145.5, 0.5, 1}, {135.5, 150.5, -0.5, 1}, {135.5, 150.5, 0, 1}
1176 ok(cmp[i].x == out[i].x && cmp[i].y == out[i].y &&
1177 cmp[i].z == out[i].z && cmp[i].rhw == out[i].rhw,
1178 "Vertex %d differs. Got %f %f %f %f, expexted %f %f %f %f\n", i + 1,
1179 out[i].x, out[i].y, out[i].z, out[i].rhw,
1180 cmp[i].x, cmp[i].y, cmp[i].z, cmp[i].rhw);
1183 memset(out, 0xbb, sizeof(out));
1184 hr = IDirect3DViewport_TransformVertices(Viewport, sizeof(testverts) / sizeof(testverts[0]),
1185 &transformdata, D3DTRANSFORM_CLIPPED,
1186 &i);
1187 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1188 ok(i == 0, "Offscreen is %d\n", i);
1189 for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
1190 static const D3DHVERTEX cmpH[] = {
1191 {0, { 0.0}, { 0.0}, { 0.0}}, {0, { 1.0}, { 1.0}, {1.0}},
1192 {D3DCLIP_FRONT, {-1.0}, {-1.0}, {-1.0}}, {0, { 0.5}, { 0.5}, {0.5}},
1193 {D3DCLIP_FRONT, {-0.5}, {-0.5}, {-0.5}}, {0, {-0.5}, {-0.5}, {0.0}}
1195 ok(U1(cmpH[i]).hx == U1(outH[i]).hx && U2(cmpH[i]).hy == U2(outH[i]).hy &&
1196 U3(cmpH[i]).hz == U3(outH[i]).hz && cmpH[i].dwFlags == outH[i].dwFlags,
1197 "HVertex %d differs. Got %08x %f %f %f, expexted %08x %f %f %f\n", i + 1,
1198 outH[i].dwFlags, U1(outH[i]).hx, U2(outH[i]).hy, U3(outH[i]).hz,
1199 cmpH[i].dwFlags, U1(cmpH[i]).hx, U2(cmpH[i]).hy, U3(cmpH[i]).hz);
1201 /* No scheme has been found behind those return values. It seems to be
1202 * whatever data windows has when throwing the vertex away. Modify the
1203 * input test vertices to test this more. Depending on the input data
1204 * it can happen that the z coord gets written into y, or similar things
1206 if(0)
1208 static const struct v_out cmp[] = {
1209 {138.0, 148.0, 0.0, 1}, {143.0, 143.0, 1.0, 1}, { -1.0, -1.0, 0.5, 1},
1210 {140.5, 145.5, 0.5, 1}, { -0.5, -0.5, -0.5, 1}, {135.5, 150.5, 0.0, 1}
1212 ok(cmp[i].x == out[i].x && cmp[i].y == out[i].y &&
1213 cmp[i].z == out[i].z && cmp[i].rhw == out[i].rhw,
1214 "Vertex %d differs. Got %f %f %f %f, expexted %f %f %f %f\n", i + 1,
1215 out[i].x, out[i].y, out[i].z, out[i].rhw,
1216 cmp[i].x, cmp[i].y, cmp[i].z, cmp[i].rhw);
1219 for(i = 0; i < sizeof(out) / sizeof(DWORD); i++) {
1220 ok(((DWORD *) out)[i] != 0xbbbbbbbb,
1221 "Regular output DWORD %d remained untouched\n", i);
1224 transformdata.lpIn = (void *) cliptest;
1225 transformdata.dwInSize = sizeof(cliptest[0]);
1226 hr = IDirect3DViewport_TransformVertices(Viewport, sizeof(cliptest) / sizeof(cliptest[0]),
1227 &transformdata, D3DTRANSFORM_CLIPPED,
1228 &i);
1229 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1230 ok(i == 0, "Offscreen is %d\n", i);
1231 for(i = 0; i < sizeof(cliptest) / sizeof(cliptest[0]); i++) {
1232 DWORD Flags[sizeof(cliptest) / sizeof(cliptest[0])] =
1236 D3DCLIP_RIGHT | D3DCLIP_BACK | D3DCLIP_TOP,
1237 D3DCLIP_LEFT | D3DCLIP_BOTTOM | D3DCLIP_FRONT,
1239 ok(Flags[i] == outH[i].dwFlags,
1240 "Cliptest %d differs. Got %08x expexted %08x\n", i + 1,
1241 outH[i].dwFlags, Flags[i]);
1244 vp_data.dwWidth = 10;
1245 vp_data.dwHeight = 1000;
1246 hr = IDirect3DViewport_SetViewport(Viewport, &vp_data);
1247 i = 10;
1248 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1249 hr = IDirect3DViewport_TransformVertices(Viewport, sizeof(cliptest) / sizeof(cliptest[0]),
1250 &transformdata, D3DTRANSFORM_CLIPPED,
1251 &i);
1252 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1253 ok(i == 0, "Offscreen is %d\n", i);
1254 for(i = 0; i < sizeof(cliptest) / sizeof(cliptest[0]); i++) {
1255 DWORD Flags[sizeof(cliptest) / sizeof(cliptest[0])] =
1257 D3DCLIP_RIGHT,
1258 D3DCLIP_LEFT,
1259 D3DCLIP_RIGHT | D3DCLIP_BACK,
1260 D3DCLIP_LEFT | D3DCLIP_FRONT,
1262 ok(Flags[i] == outH[i].dwFlags,
1263 "Cliptest %d differs. Got %08x expexted %08x\n", i + 1,
1264 outH[i].dwFlags, Flags[i]);
1266 vp_data.dwWidth = 256;
1267 vp_data.dwHeight = 256;
1268 vp_data.dvScaleX = 1;
1269 vp_data.dvScaleY = 1;
1270 hr = IDirect3DViewport_SetViewport(Viewport, &vp_data);
1271 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1272 hr = IDirect3DViewport_TransformVertices(Viewport, sizeof(cliptest) / sizeof(cliptest[0]),
1273 &transformdata, D3DTRANSFORM_CLIPPED,
1274 &i);
1275 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1276 ok(i == 0, "Offscreen is %s\n", i ? "TRUE" : "FALSE");
1277 for(i = 0; i < sizeof(cliptest) / sizeof(cliptest[0]); i++) {
1278 DWORD Flags[sizeof(cliptest) / sizeof(cliptest[0])] =
1282 D3DCLIP_BACK,
1283 D3DCLIP_FRONT,
1285 ok(Flags[i] == outH[i].dwFlags,
1286 "Cliptest %d differs. Got %08x expexted %08x\n", i + 1,
1287 outH[i].dwFlags, Flags[i]);
1290 /* Finally try to figure out how the DWORD dwOffscreen works.
1291 * Apparently no vertex is offscreen with clipping off,
1292 * and with clipping on the offscreen flag is set if only one vertex
1293 * is transformed, and this vertex is offscreen.
1295 vp_data.dwWidth = 5;
1296 vp_data.dwHeight = 5;
1297 vp_data.dvScaleX = 10000;
1298 vp_data.dvScaleY = 10000;
1299 hr = IDirect3DViewport_SetViewport(Viewport, &vp_data);
1300 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1301 transformdata.lpIn = cliptest;
1302 hr = IDirect3DViewport_TransformVertices(Viewport, 1,
1303 &transformdata, D3DTRANSFORM_UNCLIPPED,
1304 &i);
1305 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1306 ok(i == 0, "Offscreen is %d\n", i);
1307 hr = IDirect3DViewport_TransformVertices(Viewport, 1,
1308 &transformdata, D3DTRANSFORM_CLIPPED,
1309 &i);
1310 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1311 ok(i == (D3DCLIP_RIGHT | D3DCLIP_TOP), "Offscreen is %d\n", i);
1312 hr = IDirect3DViewport_TransformVertices(Viewport, 2,
1313 &transformdata, D3DTRANSFORM_CLIPPED,
1314 &i);
1315 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1316 ok(i == 0, "Offscreen is %d\n", i);
1317 transformdata.lpIn = cliptest + 1;
1318 hr = IDirect3DViewport_TransformVertices(Viewport, 1,
1319 &transformdata, D3DTRANSFORM_CLIPPED,
1320 &i);
1321 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1322 ok(i == (D3DCLIP_BOTTOM | D3DCLIP_LEFT), "Offscreen is %d\n", i);
1324 transformdata.lpIn = (void *) offscreentest;
1325 transformdata.dwInSize = sizeof(offscreentest[0]);
1326 vp_data.dwWidth = 257;
1327 vp_data.dwHeight = 257;
1328 vp_data.dvScaleX = 1;
1329 vp_data.dvScaleY = 1;
1330 hr = IDirect3DViewport_SetViewport(Viewport, &vp_data);
1331 i = 12345;
1332 hr = IDirect3DViewport_TransformVertices(Viewport, sizeof(offscreentest) / sizeof(offscreentest[0]),
1333 &transformdata, D3DTRANSFORM_CLIPPED,
1334 &i);
1335 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1336 ok(i == 0, "Offscreen is %d\n", i);
1337 vp_data.dwWidth = 256;
1338 vp_data.dwHeight = 256;
1339 hr = IDirect3DViewport_SetViewport(Viewport, &vp_data);
1340 i = 12345;
1341 hr = IDirect3DViewport_TransformVertices(Viewport, sizeof(offscreentest) / sizeof(offscreentest[0]),
1342 &transformdata, D3DTRANSFORM_CLIPPED,
1343 &i);
1344 ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1345 ok(i == D3DCLIP_RIGHT, "Offscreen is %d\n", i);
1347 hr = IDirect3DViewport_TransformVertices(Viewport, sizeof(testverts) / sizeof(testverts[0]),
1348 &transformdata, 0,
1349 &i);
1350 ok(hr == DDERR_INVALIDPARAMS, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1352 hr = IDirect3DDevice_DeleteViewport(Direct3DDevice1, Viewport);
1353 ok(hr == D3D_OK, "IDirect3DDevice_DeleteViewport returned %08x\n", hr);
1356 static BOOL colortables_check_equality(PALETTEENTRY table1[256], PALETTEENTRY table2[256])
1358 int i;
1360 for (i = 0; i < 256; i++) {
1361 if (table1[i].peRed != table2[i].peRed || table1[i].peGreen != table2[i].peGreen ||
1362 table1[i].peBlue != table2[i].peBlue) return FALSE;
1365 return TRUE;
1368 /* test palette handling in IDirect3DTexture_Load */
1369 static void TextureLoadTest(void)
1371 IDirectDrawSurface *TexSurface = NULL;
1372 IDirect3DTexture *Texture = NULL;
1373 IDirectDrawSurface *TexSurface2 = NULL;
1374 IDirect3DTexture *Texture2 = NULL;
1375 IDirectDrawPalette *palette = NULL;
1376 IDirectDrawPalette *palette2 = NULL;
1377 IDirectDrawPalette *palette_tmp = NULL;
1378 PALETTEENTRY table1[256], table2[256], table_tmp[256];
1379 HRESULT hr;
1380 DDSURFACEDESC ddsd;
1381 int i;
1383 memset (&ddsd, 0, sizeof (ddsd));
1384 ddsd.dwSize = sizeof (ddsd);
1385 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
1386 ddsd.dwHeight = 128;
1387 ddsd.dwWidth = 128;
1388 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1389 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
1390 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED8;
1391 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 8;
1393 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &TexSurface, NULL);
1394 ok(hr==D3D_OK, "CreateSurface returned: %x\n", hr);
1395 if (FAILED(hr)) {
1396 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1397 goto cleanup;
1400 hr = IDirectDrawSurface_QueryInterface(TexSurface, &IID_IDirect3DTexture,
1401 (void *)&Texture);
1402 ok(hr==D3D_OK, "IDirectDrawSurface_QueryInterface returned: %x\n", hr);
1403 if (FAILED(hr)) {
1404 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1405 goto cleanup;
1408 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &TexSurface2, NULL);
1409 ok(hr==D3D_OK, "CreateSurface returned: %x\n", hr);
1410 if (FAILED(hr)) {
1411 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1412 goto cleanup;
1415 hr = IDirectDrawSurface_QueryInterface(TexSurface2, &IID_IDirect3DTexture,
1416 (void *)&Texture2);
1417 ok(hr==D3D_OK, "IDirectDrawSurface_QueryInterface returned: %x\n", hr);
1418 if (FAILED(hr)) {
1419 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1420 goto cleanup;
1423 /* test Load when both textures have no palette */
1424 hr = IDirect3DTexture_Load(Texture2, Texture);
1425 ok(hr == DD_OK, "IDirect3DTexture_Load returned %08x\n", hr);
1427 for (i = 0; i < 256; i++) {
1428 table1[i].peRed = i;
1429 table1[i].peGreen = i;
1430 table1[i].peBlue = i;
1431 table1[i].peFlags = 0;
1434 hr = IDirectDraw_CreatePalette(DirectDraw1, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, table1, &palette, NULL);
1435 ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
1436 if (FAILED(hr)) {
1437 skip("IDirectDraw_CreatePalette failed; skipping further tests\n");
1438 goto cleanup;
1441 /* test Load when source texture has palette and destination has no palette */
1442 hr = IDirectDrawSurface_SetPalette(TexSurface, palette);
1443 ok(hr == DD_OK, "IDirectDrawSurface_SetPalette returned %08x\n", hr);
1444 hr = IDirect3DTexture_Load(Texture2, Texture);
1445 ok(hr == DDERR_NOPALETTEATTACHED, "IDirect3DTexture_Load returned %08x\n", hr);
1447 for (i = 0; i < 256; i++) {
1448 table2[i].peRed = 255 - i;
1449 table2[i].peGreen = 255 - i;
1450 table2[i].peBlue = 255 - i;
1451 table2[i].peFlags = 0;
1454 hr = IDirectDraw_CreatePalette(DirectDraw1, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, table2, &palette2, NULL);
1455 ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
1456 if (FAILED(hr)) {
1457 skip("IDirectDraw_CreatePalette failed; skipping further tests\n");
1458 goto cleanup;
1461 /* test Load when source has no palette and destination has a palette */
1462 hr = IDirectDrawSurface_SetPalette(TexSurface, NULL);
1463 ok(hr == DD_OK, "IDirectDrawSurface_SetPalette returned %08x\n", hr);
1464 hr = IDirectDrawSurface_SetPalette(TexSurface2, palette2);
1465 ok(hr == DD_OK, "IDirectDrawSurface_SetPalette returned %08x\n", hr);
1466 hr = IDirect3DTexture_Load(Texture2, Texture);
1467 ok(hr == DD_OK, "IDirect3DTexture_Load returned %08x\n", hr);
1468 hr = IDirectDrawSurface_GetPalette(TexSurface2, &palette_tmp);
1469 ok(hr == DD_OK, "IDirectDrawSurface_GetPalette returned %08x\n", hr);
1470 if (!palette_tmp) {
1471 skip("IDirectDrawSurface_GetPalette failed; skipping color table check\n");
1472 goto cleanup;
1473 } else {
1474 hr = IDirectDrawPalette_GetEntries(palette_tmp, 0, 0, 256, table_tmp);
1475 ok(hr == DD_OK, "IDirectDrawPalette_GetEntries returned %08x\n", hr);
1476 ok(colortables_check_equality(table2, table_tmp), "Unexpected palettized texture color table\n");
1477 IDirectDrawPalette_Release(palette_tmp);
1480 /* test Load when both textures have palettes */
1481 hr = IDirectDrawSurface_SetPalette(TexSurface, palette);
1482 ok(hr == DD_OK, "IDirectDrawSurface_SetPalette returned %08x\n", hr);
1483 hr = IDirect3DTexture_Load(Texture2, Texture);
1484 ok(hr == DD_OK, "IDirect3DTexture_Load returned %08x\n", hr);
1485 hr = IDirect3DTexture_Load(Texture2, Texture);
1486 ok(hr == DD_OK, "IDirect3DTexture_Load returned %08x\n", hr);
1487 hr = IDirectDrawSurface_GetPalette(TexSurface2, &palette_tmp);
1488 ok(hr == DD_OK, "IDirectDrawSurface_GetPalette returned %08x\n", hr);
1489 if (!palette_tmp) {
1490 skip("IDirectDrawSurface_GetPalette failed; skipping color table check\n");
1491 goto cleanup;
1492 } else {
1493 hr = IDirectDrawPalette_GetEntries(palette_tmp, 0, 0, 256, table_tmp);
1494 ok(hr == DD_OK, "IDirectDrawPalette_GetEntries returned %08x\n", hr);
1495 ok(colortables_check_equality(table1, table_tmp), "Unexpected palettized texture color table\n");
1496 IDirectDrawPalette_Release(palette_tmp);
1499 cleanup:
1501 if (palette) IDirectDrawPalette_Release(palette);
1502 if (palette2) IDirectDrawPalette_Release(palette2);
1503 if (TexSurface) IDirectDrawSurface_Release(TexSurface);
1504 if (Texture) IDirect3DTexture_Release(Texture);
1505 if (TexSurface2) IDirectDrawSurface_Release(TexSurface2);
1506 if (Texture2) IDirect3DTexture_Release(Texture2);
1509 START_TEST(d3d)
1511 init_function_pointers();
1512 if(!pDirectDrawCreateEx) {
1513 skip("function DirectDrawCreateEx not available\n");
1514 return;
1517 if(!CreateDirect3D()) {
1518 skip("Skipping d3d7 tests\n");
1519 } else {
1520 LightTest();
1521 ProcessVerticesTest();
1522 StateTest();
1523 SceneTest();
1524 LimitTest();
1525 D3D7EnumTest();
1526 CapsTest();
1527 ReleaseDirect3D();
1530 if (!D3D1_createObjects()) {
1531 skip("Skipping d3d1 tests\n");
1532 } else {
1533 Direct3D1Test();
1534 TextureLoadTest();
1535 D3D1_releaseObjects();