2 * Some unit tests for d3d functions
4 * Copyright (C) 2005 Antoine Chavasse
5 * Copyright (C) 2006,2011 Stefan Dösinger for CodeWeavers
6 * Copyright (C) 2008 Alexander Dorofeyev
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/test.h"
32 static IDirectDraw7
*lpDD
;
33 static IDirect3D7
*lpD3D
;
34 static IDirectDrawSurface7
*lpDDS
;
35 static IDirectDrawSurface7
*lpDDSdepth
;
36 static IDirect3DDevice7
*lpD3DDevice
;
37 static IDirect3DVertexBuffer7
*lpVBufSrc
;
39 static IDirectDraw
*DirectDraw1
= NULL
;
40 static IDirectDrawSurface
*Surface1
= NULL
;
41 static IDirect3D
*Direct3D1
= NULL
;
42 static IDirect3DDevice
*Direct3DDevice1
= NULL
;
43 static IDirect3DExecuteBuffer
*ExecuteBuffer
= NULL
;
44 static IDirect3DViewport
*Viewport
= NULL
;
45 static IDirect3DLight
*Light
= NULL
;
60 #define MAX_ENUMERATION_COUNT 10
64 char *callback_description_ptrs
[MAX_ENUMERATION_COUNT
];
65 char callback_description_strings
[MAX_ENUMERATION_COUNT
][100];
66 char *callback_name_ptrs
[MAX_ENUMERATION_COUNT
];
67 char callback_name_strings
[MAX_ENUMERATION_COUNT
][100];
70 static HRESULT (WINAPI
*pDirectDrawCreateEx
)(GUID
*driver_guid
,
71 void **ddraw
, REFIID interface_iid
, IUnknown
*outer
);
73 static void init_function_pointers(void)
75 HMODULE hmod
= GetModuleHandleA("ddraw.dll");
76 pDirectDrawCreateEx
= (void*)GetProcAddress(hmod
, "DirectDrawCreateEx");
80 static ULONG
getRefcount(IUnknown
*iface
)
82 IUnknown_AddRef(iface
);
83 return IUnknown_Release(iface
);
86 static HRESULT WINAPI
SurfaceCounter(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
90 IDirectDrawSurface_Release(surface
);
94 static BOOL
CreateDirect3D(void)
100 rc
= pDirectDrawCreateEx(NULL
, (void**)&lpDD
,
101 &IID_IDirectDraw7
, NULL
);
102 ok(rc
==DD_OK
|| rc
==DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreateEx returned: %x\n", rc
);
104 trace("DirectDrawCreateEx() failed with an error %x\n", rc
);
108 rc
= IDirectDraw7_SetCooperativeLevel(lpDD
, NULL
, DDSCL_NORMAL
);
109 ok(rc
==DD_OK
, "SetCooperativeLevel returned: %x\n", rc
);
111 rc
= IDirectDraw7_QueryInterface(lpDD
, &IID_IDirect3D7
, (void**) &lpD3D
);
112 if (rc
== E_NOINTERFACE
)
114 IDirectDraw7_Release(lpDD
);
117 ok(rc
==DD_OK
, "QueryInterface returned: %x\n", rc
);
119 memset(&ddsd
, 0, sizeof(ddsd
));
120 ddsd
.dwSize
= sizeof(ddsd
);
121 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
122 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
125 rc
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &lpDDS
, NULL
);
128 IDirect3D7_Release(lpD3D
);
129 IDirectDraw7_Release(lpDD
);
134 IDirectDraw7_EnumSurfaces(lpDD
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
, NULL
, &num
, SurfaceCounter
);
135 ok(num
== 1, "Has %d surfaces, expected 1\n", num
);
137 memset(&ddsd
, 0, sizeof(ddsd
));
138 ddsd
.dwSize
= sizeof(ddsd
);
139 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
140 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
141 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
142 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_ZBUFFER
;
143 U1(U4(ddsd
).ddpfPixelFormat
).dwZBufferBitDepth
= 16;
144 U3(U4(ddsd
).ddpfPixelFormat
).dwZBitMask
= 0x0000FFFF;
147 rc
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &lpDDSdepth
, NULL
);
148 ok(rc
==DD_OK
, "CreateSurface returned: %x\n", rc
);
152 rc
= IDirectDrawSurface_AddAttachedSurface(lpDDS
, lpDDSdepth
);
153 ok(rc
== DD_OK
, "IDirectDrawSurface_AddAttachedSurface returned %x\n", rc
);
156 IDirectDrawSurface7_Release(lpDDSdepth
);
157 IDirectDrawSurface7_Release(lpDDS
);
158 IDirect3D7_Release(lpD3D
);
159 IDirectDraw7_Release(lpDD
);
164 rc
= IDirect3D7_CreateDevice(lpD3D
, &IID_IDirect3DTnLHalDevice
, lpDDS
,
166 ok(rc
==D3D_OK
|| rc
==DDERR_NOPALETTEATTACHED
|| rc
==E_OUTOFMEMORY
, "CreateDevice returned: %x\n", rc
);
168 trace("IDirect3D7::CreateDevice() for a TnL Hal device failed with an error %x, trying HAL\n", rc
);
169 rc
= IDirect3D7_CreateDevice(lpD3D
, &IID_IDirect3DHALDevice
, lpDDS
,
172 trace("IDirect3D7::CreateDevice() for a HAL device failed with an error %x, trying RGB\n", rc
);
173 rc
= IDirect3D7_CreateDevice(lpD3D
, &IID_IDirect3DRGBDevice
, lpDDS
,
176 trace("IDirect3D7::CreateDevice() for a RGB device failed with an error %x, giving up\n", rc
);
178 IDirectDrawSurface7_Release(lpDDSdepth
);
179 IDirectDrawSurface7_Release(lpDDS
);
180 IDirect3D7_Release(lpD3D
);
181 IDirectDraw7_Release(lpDD
);
190 static void ReleaseDirect3D(void)
192 if (lpD3DDevice
!= NULL
)
194 IDirect3DDevice7_Release(lpD3DDevice
);
198 if (lpDDSdepth
!= NULL
)
200 IDirectDrawSurface_Release(lpDDSdepth
);
206 IDirectDrawSurface_Release(lpDDS
);
212 IDirect3D7_Release(lpD3D
);
218 IDirectDraw7_Release(lpDD
);
223 static void LightTest(void)
227 D3DLIGHT7 defaultlight
;
228 BOOL bEnabled
= FALSE
;
236 /* Set a few lights with funky indices. */
237 memset(&light
, 0, sizeof(light
));
238 light
.dltType
= D3DLIGHT_DIRECTIONAL
;
239 U1(light
.dcvDiffuse
).r
= 0.5f
;
240 U2(light
.dcvDiffuse
).g
= 0.6f
;
241 U3(light
.dcvDiffuse
).b
= 0.7f
;
242 U2(light
.dvDirection
).y
= 1.f
;
244 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 5, &light
);
245 ok(rc
==D3D_OK
, "SetLight returned: %x\n", rc
);
246 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 10, &light
);
247 ok(rc
==D3D_OK
, "SetLight returned: %x\n", rc
);
248 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 45, &light
);
249 ok(rc
==D3D_OK
, "SetLight returned: %x\n", rc
);
252 /* Try to retrieve a light beyond the indices of the lights that have
254 rc
= IDirect3DDevice7_GetLight(lpD3DDevice
, 50, &light
);
255 ok(rc
==DDERR_INVALIDPARAMS
, "GetLight returned: %x\n", rc
);
256 rc
= IDirect3DDevice7_GetLight(lpD3DDevice
, 2, &light
);
257 ok(rc
==DDERR_INVALIDPARAMS
, "GetLight returned: %x\n", rc
);
260 /* Try to retrieve one of the lights that have been set */
261 rc
= IDirect3DDevice7_GetLight(lpD3DDevice
, 10, &light
);
262 ok(rc
==D3D_OK
, "GetLight returned: %x\n", rc
);
265 /* Enable a light that have been previously set. */
266 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, 10, TRUE
);
267 ok(rc
==D3D_OK
, "LightEnable returned: %x\n", rc
);
270 /* Enable some lights that have not been previously set, and verify that
271 they have been initialized with proper default values. */
272 memset(&defaultlight
, 0, sizeof(D3DLIGHT7
));
273 defaultlight
.dltType
= D3DLIGHT_DIRECTIONAL
;
274 U1(defaultlight
.dcvDiffuse
).r
= 1.f
;
275 U2(defaultlight
.dcvDiffuse
).g
= 1.f
;
276 U3(defaultlight
.dcvDiffuse
).b
= 1.f
;
277 U3(defaultlight
.dvDirection
).z
= 1.f
;
279 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, 20, TRUE
);
280 ok(rc
==D3D_OK
, "LightEnable returned: %x\n", rc
);
281 memset(&light
, 0, sizeof(D3DLIGHT7
));
282 rc
= IDirect3DDevice7_GetLight(lpD3DDevice
, 20, &light
);
283 ok(rc
==D3D_OK
, "GetLight returned: %x\n", rc
);
284 ok(!memcmp(&light
, &defaultlight
, sizeof(D3DLIGHT7
)),
285 "light data doesn't match expected default values\n" );
287 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, 50, TRUE
);
288 ok(rc
==D3D_OK
, "LightEnable returned: %x\n", rc
);
289 memset(&light
, 0, sizeof(D3DLIGHT7
));
290 rc
= IDirect3DDevice7_GetLight(lpD3DDevice
, 50, &light
);
291 ok(rc
==D3D_OK
, "GetLight returned: %x\n", rc
);
292 ok(!memcmp(&light
, &defaultlight
, sizeof(D3DLIGHT7
)),
293 "light data doesn't match expected default values\n" );
296 /* Disable one of the light that have been previously enabled. */
297 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, 20, FALSE
);
298 ok(rc
==D3D_OK
, "LightEnable returned: %x\n", rc
);
300 /* Try to retrieve the enable status of some lights */
301 /* Light 20 is supposed to be disabled */
302 rc
= IDirect3DDevice7_GetLightEnable(lpD3DDevice
, 20, &bEnabled
);
303 ok(rc
==D3D_OK
, "GetLightEnable returned: %x\n", rc
);
304 ok(!bEnabled
, "GetLightEnable says the light is enabled\n");
306 /* Light 10 is supposed to be enabled */
308 rc
= IDirect3DDevice7_GetLightEnable(lpD3DDevice
, 10, &bEnabled
);
309 ok(rc
==D3D_OK
, "GetLightEnable returned: %x\n", rc
);
310 ok(bEnabled
, "GetLightEnable says the light is disabled\n");
312 /* Light 80 has not been set */
313 rc
= IDirect3DDevice7_GetLightEnable(lpD3DDevice
, 80, &bEnabled
);
314 ok(rc
==DDERR_INVALIDPARAMS
, "GetLightEnable returned: %x\n", rc
);
316 /* Light 23 has not been set */
317 rc
= IDirect3DDevice7_GetLightEnable(lpD3DDevice
, 23, &bEnabled
);
318 ok(rc
==DDERR_INVALIDPARAMS
, "GetLightEnable returned: %x\n", rc
);
320 /* Set some lights with invalid parameters */
321 memset(&light
, 0, sizeof(D3DLIGHT7
));
323 U1(light
.dcvDiffuse
).r
= 1.f
;
324 U2(light
.dcvDiffuse
).g
= 1.f
;
325 U3(light
.dcvDiffuse
).b
= 1.f
;
326 U3(light
.dvDirection
).z
= 1.f
;
327 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 100, &light
);
328 ok(rc
==DDERR_INVALIDPARAMS
, "SetLight returned: %x\n", rc
);
330 memset(&light
, 0, sizeof(D3DLIGHT7
));
331 light
.dltType
= 12345;
332 U1(light
.dcvDiffuse
).r
= 1.f
;
333 U2(light
.dcvDiffuse
).g
= 1.f
;
334 U3(light
.dcvDiffuse
).b
= 1.f
;
335 U3(light
.dvDirection
).z
= 1.f
;
336 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 101, &light
);
337 ok(rc
==DDERR_INVALIDPARAMS
, "SetLight returned: %x\n", rc
);
339 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 102, NULL
);
340 ok(rc
==DDERR_INVALIDPARAMS
, "SetLight returned: %x\n", rc
);
342 memset(&light
, 0, sizeof(D3DLIGHT7
));
343 light
.dltType
= D3DLIGHT_SPOT
;
344 U1(light
.dcvDiffuse
).r
= 1.f
;
345 U2(light
.dcvDiffuse
).g
= 1.f
;
346 U3(light
.dcvDiffuse
).b
= 1.f
;
347 U3(light
.dvDirection
).z
= 1.f
;
349 light
.dvAttenuation0
= -one
/ zero
; /* -INFINITY */
350 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 103, &light
);
351 ok(rc
==DDERR_INVALIDPARAMS
, "SetLight returned: %x\n", rc
);
353 light
.dvAttenuation0
= -1.0;
354 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 103, &light
);
355 ok(rc
==DDERR_INVALIDPARAMS
, "SetLight returned: %x\n", rc
);
357 light
.dvAttenuation0
= 0.0;
358 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 103, &light
);
359 ok(rc
==D3D_OK
, "SetLight returned: %x\n", rc
);
361 light
.dvAttenuation0
= 1.0;
362 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 103, &light
);
363 ok(rc
==D3D_OK
, "SetLight returned: %x\n", rc
);
365 light
.dvAttenuation0
= one
/ zero
; /* +INFINITY */
366 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 103, &light
);
367 ok(rc
==D3D_OK
, "SetLight returned: %x\n", rc
);
369 light
.dvAttenuation0
= zero
/ zero
; /* NaN */
370 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 103, &light
);
372 broken(rc
==DDERR_INVALIDPARAMS
), "SetLight returned: %x\n", rc
);
374 /* Directional light ignores attenuation */
375 light
.dltType
= D3DLIGHT_DIRECTIONAL
;
376 light
.dvAttenuation0
= -1.0;
377 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 103, &light
);
378 ok(rc
==D3D_OK
, "SetLight returned: %x\n", rc
);
380 memset(&mat
, 0, sizeof(mat
));
381 rc
= IDirect3DDevice7_SetMaterial(lpD3DDevice
, &mat
);
382 ok(rc
== D3D_OK
, "IDirect3DDevice7_SetMaterial returned: %x\n", rc
);
384 U4(mat
).power
= 129.0;
385 rc
= IDirect3DDevice7_SetMaterial(lpD3DDevice
, &mat
);
386 ok(rc
== D3D_OK
, "IDirect3DDevice7_SetMaterial(power = 129.0) returned: %x\n", rc
);
387 memset(&mat
, 0, sizeof(mat
));
388 rc
= IDirect3DDevice7_GetMaterial(lpD3DDevice
, &mat
);
389 ok(rc
== D3D_OK
, "IDirect3DDevice7_GetMaterial returned: %x\n", rc
);
390 ok(U4(mat
).power
== 129, "Returned power is %f\n", U4(mat
).power
);
392 U4(mat
).power
= -1.0;
393 rc
= IDirect3DDevice7_SetMaterial(lpD3DDevice
, &mat
);
394 ok(rc
== D3D_OK
, "IDirect3DDevice7_SetMaterial(power = -1.0) returned: %x\n", rc
);
395 memset(&mat
, 0, sizeof(mat
));
396 rc
= IDirect3DDevice7_GetMaterial(lpD3DDevice
, &mat
);
397 ok(rc
== D3D_OK
, "IDirect3DDevice7_GetMaterial returned: %x\n", rc
);
398 ok(U4(mat
).power
== -1, "Returned power is %f\n", U4(mat
).power
);
400 memset(&caps
, 0, sizeof(caps
));
401 rc
= IDirect3DDevice7_GetCaps(lpD3DDevice
, &caps
);
402 ok(rc
== D3D_OK
, "IDirect3DDevice7_GetCaps failed with %x\n", rc
);
404 if ( caps
.dwMaxActiveLights
== (DWORD
) -1) {
405 /* Some cards without T&L Support return -1 (Examples: Voodoo Banshee, RivaTNT / NV4) */
406 skip("T&L not supported\n");
410 for(i
= 1; i
<= caps
.dwMaxActiveLights
; i
++) {
411 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, i
, TRUE
);
412 ok(rc
== D3D_OK
, "Enabling light %u failed with %x\n", i
, rc
);
413 rc
= IDirect3DDevice7_GetLightEnable(lpD3DDevice
, i
, &enabled
);
414 ok(rc
== D3D_OK
, "GetLightEnable on light %u failed with %x\n", i
, rc
);
415 ok(enabled
, "Light %d is %s\n", i
, enabled
? "enabled" : "disabled");
418 /* TODO: Test the rendering results in this situation */
419 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, i
+ 1, TRUE
);
420 ok(rc
== D3D_OK
, "Enabling one light more than supported returned %x\n", rc
);
421 rc
= IDirect3DDevice7_GetLightEnable(lpD3DDevice
, i
+ 1, &enabled
);
422 ok(rc
== D3D_OK
, "GetLightEnable on light %u failed with %x\n", i
+ 1, rc
);
423 ok(enabled
, "Light %d is %s\n", i
+ 1, enabled
? "enabled" : "disabled");
424 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, i
+ 1, FALSE
);
425 ok(rc
== D3D_OK
, "Disabling the additional returned %x\n", rc
);
427 for(i
= 1; i
<= caps
.dwMaxActiveLights
; i
++) {
428 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, i
, FALSE
);
429 ok(rc
== D3D_OK
, "Disabling light %u failed with %x\n", i
, rc
);
433 static void SceneTest(void)
437 /* Test an EndScene without BeginScene. Should return an error */
438 hr
= IDirect3DDevice7_EndScene(lpD3DDevice
);
439 ok(hr
== D3DERR_SCENE_NOT_IN_SCENE
, "IDirect3DDevice7_EndScene returned %08x\n", hr
);
441 /* Test a normal BeginScene / EndScene pair, this should work */
442 hr
= IDirect3DDevice7_BeginScene(lpD3DDevice
);
443 ok(hr
== D3D_OK
, "IDirect3DDevice7_BeginScene failed with %08x\n", hr
);
446 hr
= IDirect3DDevice7_EndScene(lpD3DDevice
);
447 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndScene failed with %08x\n", hr
);
453 memset(&fx
, 0, sizeof(fx
));
454 fx
.dwSize
= sizeof(fx
);
456 hr
= IDirectDrawSurface7_Blt(lpDDSdepth
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
, &fx
);
457 ok(hr
== D3D_OK
, "Depthfill failed outside a BeginScene / EndScene pair, hr 0x%08x\n", hr
);
459 hr
= IDirect3DDevice7_BeginScene(lpD3DDevice
);
460 ok(hr
== D3D_OK
, "IDirect3DDevice7_BeginScene failed with %08x\n", hr
);
463 hr
= IDirectDrawSurface7_Blt(lpDDSdepth
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
, &fx
);
464 ok(hr
== D3D_OK
|| broken(hr
== E_FAIL
),
465 "Depthfill failed in a BeginScene / EndScene pair, hr 0x%08x\n", hr
);
466 hr
= IDirect3DDevice7_EndScene(lpD3DDevice
);
467 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndScene failed with %08x\n", hr
);
472 skip("Depth stencil creation failed at startup, skipping depthfill test\n");
475 /* Test another EndScene without having begun a new scene. Should return an error */
476 hr
= IDirect3DDevice7_EndScene(lpD3DDevice
);
477 ok(hr
== D3DERR_SCENE_NOT_IN_SCENE
, "IDirect3DDevice7_EndScene returned %08x\n", hr
);
479 /* Two nested BeginScene and EndScene calls */
480 hr
= IDirect3DDevice7_BeginScene(lpD3DDevice
);
481 ok(hr
== D3D_OK
, "IDirect3DDevice7_BeginScene failed with %08x\n", hr
);
482 hr
= IDirect3DDevice7_BeginScene(lpD3DDevice
);
483 ok(hr
== D3DERR_SCENE_IN_SCENE
, "IDirect3DDevice7_BeginScene returned %08x\n", hr
);
484 hr
= IDirect3DDevice7_EndScene(lpD3DDevice
);
485 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndScene failed with %08x\n", hr
);
486 hr
= IDirect3DDevice7_EndScene(lpD3DDevice
);
487 ok(hr
== D3DERR_SCENE_NOT_IN_SCENE
, "IDirect3DDevice7_EndScene returned %08x\n", hr
);
489 /* TODO: Verify that blitting works in the same way as in d3d9 */
492 static HRESULT WINAPI
enumDevicesCallback(GUID
*Guid
, char *DeviceDescription
,
493 char *DeviceName
, D3DDEVICEDESC
*hal
, D3DDEVICEDESC
*hel
, void *ctx
)
495 UINT ver
= *((UINT
*) ctx
);
496 if(IsEqualGUID(&IID_IDirect3DRGBDevice
, Guid
))
498 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
499 "RGB Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
500 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
501 "RGB Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
502 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
503 "RGB Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
504 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
505 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
507 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
508 "RGB Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
509 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
510 "RGB Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
511 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
512 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
513 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
514 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
516 ok(hal
->dcmColorModel
== 0, "RGB Device %u hal caps has colormodel %u\n", ver
, hal
->dcmColorModel
);
517 ok(hel
->dcmColorModel
== D3DCOLOR_RGB
, "RGB Device %u hel caps has colormodel %u\n", ver
, hel
->dcmColorModel
);
519 ok(hal
->dwFlags
== 0, "RGB Device %u hal caps has hardware flags %x\n", ver
, hal
->dwFlags
);
520 ok(hel
->dwFlags
!= 0, "RGB Device %u hel caps has hardware flags %x\n", ver
, hel
->dwFlags
);
522 else if(IsEqualGUID(&IID_IDirect3DHALDevice
, Guid
))
524 trace("HAL Device %d\n", ver
);
525 ok(hal
->dcmColorModel
== D3DCOLOR_RGB
, "HAL Device %u hal caps has colormodel %u\n", ver
, hel
->dcmColorModel
);
526 ok(hel
->dcmColorModel
== 0, "HAL Device %u hel caps has colormodel %u\n", ver
, hel
->dcmColorModel
);
528 ok(hal
->dwFlags
!= 0, "HAL Device %u hal caps has hardware flags %x\n", ver
, hal
->dwFlags
);
529 ok(hel
->dwFlags
!= 0, "HAL Device %u hel caps has hardware flags %x\n", ver
, hel
->dwFlags
);
531 else if(IsEqualGUID(&IID_IDirect3DRefDevice
, Guid
))
533 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
534 "REF Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
535 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
536 "REF Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
537 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
538 "REF Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
539 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
540 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
542 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
543 "REF Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
544 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
545 "REF Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
546 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
547 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
548 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
549 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
551 else if(IsEqualGUID(&IID_IDirect3DRampDevice
, Guid
))
553 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
554 "Ramp Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
555 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
556 "Ramp Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
557 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
558 "Ramp Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
559 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
560 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
562 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
563 "Ramp Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
564 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
565 "Ramp Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
566 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
567 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
568 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
569 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
571 ok(hal
->dcmColorModel
== 0, "Ramp Device %u hal caps has colormodel %u\n", ver
, hal
->dcmColorModel
);
572 ok(hel
->dcmColorModel
== D3DCOLOR_MONO
, "Ramp Device %u hel caps has colormodel %u\n",
573 ver
, hel
->dcmColorModel
);
575 ok(hal
->dwFlags
== 0, "Ramp Device %u hal caps has hardware flags %x\n", ver
, hal
->dwFlags
);
576 ok(hel
->dwFlags
!= 0, "Ramp Device %u hel caps has hardware flags %x\n", ver
, hel
->dwFlags
);
578 else if(IsEqualGUID(&IID_IDirect3DMMXDevice
, Guid
))
580 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
581 "MMX Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
582 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
583 "MMX Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
584 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
585 "MMX Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
586 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
587 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
589 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
590 "MMX Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
591 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
592 "MMX Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
593 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
594 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
595 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
596 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
598 ok(hal
->dcmColorModel
== 0, "MMX Device %u hal caps has colormodel %u\n", ver
, hal
->dcmColorModel
);
599 ok(hel
->dcmColorModel
== D3DCOLOR_RGB
, "MMX Device %u hel caps has colormodel %u\n", ver
, hel
->dcmColorModel
);
601 ok(hal
->dwFlags
== 0, "MMX Device %u hal caps has hardware flags %x\n", ver
, hal
->dwFlags
);
602 ok(hel
->dwFlags
!= 0, "MMX Device %u hel caps has hardware flags %x\n", ver
, hel
->dwFlags
);
606 ok(FALSE
, "Unexpected device enumerated: \"%s\" \"%s\"\n", DeviceDescription
, DeviceName
);
607 if(hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) trace("hal line has pow2 set\n");
608 else trace("hal line does NOT have pow2 set\n");
609 if(hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) trace("hal tri has pow2 set\n");
610 else trace("hal tri does NOT have pow2 set\n");
611 if(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) trace("hel line has pow2 set\n");
612 else trace("hel line does NOT have pow2 set\n");
613 if(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) trace("hel tri has pow2 set\n");
614 else trace("hel tri does NOT have pow2 set\n");
619 static HRESULT WINAPI
enumDevicesCallbackTest7(char *DeviceDescription
, char *DeviceName
,
620 D3DDEVICEDESC7
*lpdd7
, void *Context
)
622 D3D7ETest
*d3d7et
= Context
;
623 if(IsEqualGUID(&lpdd7
->deviceGUID
, &IID_IDirect3DRGBDevice
))
625 else if(IsEqualGUID(&lpdd7
->deviceGUID
, &IID_IDirect3DHALDevice
))
627 else if(IsEqualGUID(&lpdd7
->deviceGUID
, &IID_IDirect3DTnLHalDevice
))
637 static HRESULT WINAPI
enumDevicesCancelTest7(char *DeviceDescription
, char *DeviceName
,
638 D3DDEVICEDESC7
*lpdd7
, void *Context
)
640 D3D7ECancelTest
*d3d7et
= Context
;
644 return d3d7et
->desired_ret
;
647 static HRESULT WINAPI
enumDevicesLifetimeTest7(char *DeviceDescription
, char *DeviceName
,
648 D3DDEVICEDESC7
*lpdd7
, void *Context
)
650 D3D7ELifetimeTest
*ctx
= Context
;
652 if (ctx
->count
== MAX_ENUMERATION_COUNT
)
654 ok(0, "Enumerated too many devices for context in callback\n");
655 return DDENUMRET_CANCEL
;
658 ctx
->callback_description_ptrs
[ctx
->count
] = DeviceDescription
;
659 strcpy(ctx
->callback_description_strings
[ctx
->count
], DeviceDescription
);
660 ctx
->callback_name_ptrs
[ctx
->count
] = DeviceName
;
661 strcpy(ctx
->callback_name_strings
[ctx
->count
], DeviceName
);
667 /* Check the deviceGUID of devices enumerated by
668 IDirect3D7_EnumDevices. */
669 static void D3D7EnumTest(void)
673 D3D7ECancelTest d3d7_cancel_test
;
675 hr
= IDirect3D7_EnumDevices(lpD3D
, NULL
, NULL
);
676 ok(hr
== DDERR_INVALIDPARAMS
, "IDirect3D7_EnumDevices returned 0x%08x\n", hr
);
678 memset(&d3d7et
, 0, sizeof(d3d7et
));
679 hr
= IDirect3D7_EnumDevices(lpD3D
, enumDevicesCallbackTest7
, &d3d7et
);
680 ok(hr
== D3D_OK
, "IDirect3D7_EnumDevices returned 0x%08x\n", hr
);
682 /* A couple of games (Delta Force LW and TFD) rely on this behaviour */
683 ok(d3d7et
.tnlhal
< d3d7et
.total
, "TnLHal device enumerated as only device.\n");
685 /* We make two additional assumptions. */
686 ok(d3d7et
.rgb
, "No RGB Device enumerated.\n");
689 ok(d3d7et
.hal
, "TnLHal device enumerated, but no Hal device found.\n");
691 d3d7_cancel_test
.desired_ret
= DDENUMRET_CANCEL
;
692 d3d7_cancel_test
.total
= 0;
693 hr
= IDirect3D7_EnumDevices(lpD3D
, enumDevicesCancelTest7
, &d3d7_cancel_test
);
694 ok(hr
== D3D_OK
, "IDirect3D7_EnumDevices returned 0x%08x\n", hr
);
696 ok(d3d7_cancel_test
.total
== 1, "Enumerated a total of %u devices\n",
697 d3d7_cancel_test
.total
);
699 /* An enumeration callback can return any value besides DDENUMRET_OK to stop enumeration. */
700 d3d7_cancel_test
.desired_ret
= E_INVALIDARG
;
701 d3d7_cancel_test
.total
= 0;
702 hr
= IDirect3D7_EnumDevices(lpD3D
, enumDevicesCancelTest7
, &d3d7_cancel_test
);
703 ok(hr
== D3D_OK
, "IDirect3D7_EnumDevices returned 0x%08x\n", hr
);
705 ok(d3d7_cancel_test
.total
== 1, "Enumerated a total of %u devices\n",
706 d3d7_cancel_test
.total
);
709 static void D3D7EnumLifetimeTest(void)
711 D3D7ELifetimeTest ctx
, ctx2
;
716 hr
= IDirect3D7_EnumDevices(lpD3D
, enumDevicesLifetimeTest7
, &ctx
);
717 ok(hr
== D3D_OK
, "IDirect3D7_EnumDevices returned 0x%08x\n", hr
);
719 /* The enumeration strings remain valid even after IDirect3D7_EnumDevices finishes. */
720 for (i
= 0; i
< ctx
.count
; i
++)
722 ok(!strcmp(ctx
.callback_description_ptrs
[i
], ctx
.callback_description_strings
[i
]),
723 "Got '%s' and '%s'\n", ctx
.callback_description_ptrs
[i
], ctx
.callback_description_strings
[i
]);
724 ok(!strcmp(ctx
.callback_name_ptrs
[i
], ctx
.callback_name_strings
[i
]),
725 "Got '%s' and '%s'\n", ctx
.callback_name_ptrs
[i
], ctx
.callback_name_strings
[i
]);
729 hr
= IDirect3D7_EnumDevices(lpD3D
, enumDevicesLifetimeTest7
, &ctx2
);
730 ok(hr
== D3D_OK
, "IDirect3D7_EnumDevices returned 0x%08x\n", hr
);
732 /* The enumeration strings and their order are identical across enumerations. */
733 ok(ctx
.count
== ctx2
.count
, "Enumerated %u and %u devices\n", ctx
.count
, ctx2
.count
);
734 if (ctx
.count
== ctx2
.count
)
736 for (i
= 0; i
< ctx
.count
; i
++)
738 ok(ctx
.callback_description_ptrs
[i
] == ctx2
.callback_description_ptrs
[i
],
739 "Unequal description pointers %p and %p\n", ctx
.callback_description_ptrs
[i
], ctx2
.callback_description_ptrs
[i
]);
740 ok(!strcmp(ctx
.callback_description_strings
[i
], ctx2
.callback_description_strings
[i
]),
741 "Got '%s' and '%s'\n", ctx
.callback_description_strings
[i
], ctx2
.callback_description_strings
[i
]);
742 ok(ctx
.callback_name_ptrs
[i
] == ctx2
.callback_name_ptrs
[i
],
743 "Unequal name pointers %p and %p\n", ctx
.callback_name_ptrs
[i
], ctx2
.callback_name_ptrs
[i
]);
744 ok(!strcmp(ctx
.callback_name_strings
[i
], ctx2
.callback_name_strings
[i
]),
745 "Got '%s' and '%s'\n", ctx
.callback_name_strings
[i
], ctx2
.callback_name_strings
[i
]);
749 /* Try altering the contents of the enumeration strings. */
750 for (i
= 0; i
< ctx2
.count
; i
++)
752 strcpy(ctx2
.callback_description_ptrs
[i
], "Fake Description");
753 strcpy(ctx2
.callback_name_ptrs
[i
], "Fake Device");
757 hr
= IDirect3D7_EnumDevices(lpD3D
, enumDevicesLifetimeTest7
, &ctx2
);
758 ok(hr
== D3D_OK
, "IDirect3D7_EnumDevices returned 0x%08x\n", hr
);
760 /* The original contents of the enumeration strings are not restored. */
761 ok(ctx
.count
== ctx2
.count
, "Enumerated %u and %u devices\n", ctx
.count
, ctx2
.count
);
762 if (ctx
.count
== ctx2
.count
)
764 for (i
= 0; i
< ctx
.count
; i
++)
766 ok(ctx
.callback_description_ptrs
[i
] == ctx2
.callback_description_ptrs
[i
],
767 "Unequal description pointers %p and %p\n", ctx
.callback_description_ptrs
[i
], ctx2
.callback_description_ptrs
[i
]);
768 ok(strcmp(ctx
.callback_description_strings
[i
], ctx2
.callback_description_strings
[i
]) != 0,
769 "Got '%s' and '%s'\n", ctx
.callback_description_strings
[i
], ctx2
.callback_description_strings
[i
]);
770 ok(ctx
.callback_name_ptrs
[i
] == ctx2
.callback_name_ptrs
[i
],
771 "Unequal name pointers %p and %p\n", ctx
.callback_name_ptrs
[i
], ctx2
.callback_name_ptrs
[i
]);
772 ok(strcmp(ctx
.callback_name_strings
[i
], ctx2
.callback_name_strings
[i
]) != 0,
773 "Got '%s' and '%s'\n", ctx
.callback_name_strings
[i
], ctx2
.callback_name_strings
[i
]);
778 static void CapsTest(void)
786 hr
= DirectDrawCreate(NULL
, &dd1
, NULL
);
787 ok(hr
== DD_OK
, "Cannot create a DirectDraw 1 interface, hr = %08x\n", hr
);
788 hr
= IDirectDraw_QueryInterface(dd1
, &IID_IDirect3D3
, (void **) &d3d3
);
789 ok(hr
== D3D_OK
, "IDirectDraw_QueryInterface returned %08x\n", hr
);
791 hr
= IDirect3D3_EnumDevices(d3d3
, NULL
, NULL
);
792 ok(hr
== DDERR_INVALIDPARAMS
, "IDirect3D3_EnumDevices returned 0x%08x\n", hr
);
795 IDirect3D3_EnumDevices(d3d3
, enumDevicesCallback
, &ver
);
797 IDirect3D3_Release(d3d3
);
798 IDirectDraw_Release(dd1
);
800 hr
= DirectDrawCreate(NULL
, &dd1
, NULL
);
801 ok(hr
== DD_OK
, "Cannot create a DirectDraw 1 interface, hr = %08x\n", hr
);
802 hr
= IDirectDraw_QueryInterface(dd1
, &IID_IDirect3D2
, (void **) &d3d2
);
803 ok(hr
== D3D_OK
, "IDirectDraw_QueryInterface returned %08x\n", hr
);
805 hr
= IDirect3D2_EnumDevices(d3d2
, NULL
, NULL
);
806 ok(hr
== DDERR_INVALIDPARAMS
, "IDirect3D2_EnumDevices returned 0x%08x\n", hr
);
809 IDirect3D2_EnumDevices(d3d2
, enumDevicesCallback
, &ver
);
811 IDirect3D2_Release(d3d2
);
812 IDirectDraw_Release(dd1
);
822 static BOOL
D3D1_createObjects(void)
826 D3DEXECUTEBUFFERDESC desc
;
829 /* An IDirect3DDevice cannot be queryInterfaced from an IDirect3DDevice7 on windows */
830 hr
= DirectDrawCreate(NULL
, &DirectDraw1
, NULL
);
831 ok(hr
==DD_OK
|| hr
==DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreate returned: %x\n", hr
);
836 hr
= IDirectDraw_SetCooperativeLevel(DirectDraw1
, NULL
, DDSCL_NORMAL
);
837 ok(hr
==DD_OK
, "SetCooperativeLevel returned: %x\n", hr
);
839 hr
= IDirectDraw_QueryInterface(DirectDraw1
, &IID_IDirect3D
, (void**) &Direct3D1
);
840 if (hr
== E_NOINTERFACE
) return FALSE
;
841 ok(hr
==DD_OK
, "QueryInterface returned: %x\n", hr
);
846 memset(&ddsd
, 0, sizeof(ddsd
));
847 ddsd
.dwSize
= sizeof(ddsd
);
848 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
849 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
852 IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &Surface1
, NULL
);
854 skip("DDSCAPS_3DDEVICE surface not available\n");
858 hr
= IDirectDrawSurface_QueryInterface(Surface1
, &IID_IDirect3DRGBDevice
, (void **) &Direct3DDevice1
);
859 ok(hr
==D3D_OK
|| hr
==DDERR_NOPALETTEATTACHED
|| hr
==E_OUTOFMEMORY
, "CreateDevice returned: %x\n", hr
);
860 if(!Direct3DDevice1
) {
864 memset(&desc
, 0, sizeof(desc
));
865 desc
.dwSize
= sizeof(desc
);
866 desc
.dwFlags
= D3DDEB_BUFSIZE
| D3DDEB_CAPS
;
867 desc
.dwCaps
= D3DDEBCAPS_VIDEOMEMORY
;
868 desc
.dwBufferSize
= 128;
870 hr
= IDirect3DDevice_CreateExecuteBuffer(Direct3DDevice1
, &desc
, &ExecuteBuffer
, NULL
);
871 ok(hr
== D3D_OK
, "IDirect3DDevice_CreateExecuteBuffer failed: %08x\n", hr
);
876 hr
= IDirect3D_CreateViewport(Direct3D1
, &Viewport
, NULL
);
877 ok(hr
== D3D_OK
, "IDirect3D_CreateViewport failed: %08x\n", hr
);
882 hr
= IDirect3DViewport_Initialize(Viewport
, Direct3D1
);
883 ok(hr
== DDERR_ALREADYINITIALIZED
, "IDirect3DViewport_Initialize returned %08x\n", hr
);
885 hr
= IDirect3DDevice_AddViewport(Direct3DDevice1
, Viewport
);
886 ok(hr
== D3D_OK
, "IDirect3DDevice_AddViewport returned %08x\n", hr
);
887 vp_data
.dwSize
= sizeof(vp_data
);
890 vp_data
.dwWidth
= 256;
891 vp_data
.dwHeight
= 256;
892 vp_data
.dvScaleX
= 1;
893 vp_data
.dvScaleY
= 1;
894 vp_data
.dvMaxX
= 256;
895 vp_data
.dvMaxY
= 256;
898 hr
= IDirect3DViewport_SetViewport(Viewport
, &vp_data
);
899 ok(hr
== D3D_OK
, "IDirect3DViewport_SetViewport returned %08x\n", hr
);
901 hr
= IDirect3D_CreateLight(Direct3D1
, &Light
, NULL
);
902 ok(hr
== D3D_OK
, "IDirect3D_CreateLight failed: %08x\n", hr
);
909 static void D3D1_releaseObjects(void)
911 if (Light
) IDirect3DLight_Release(Light
);
912 if (Viewport
) IDirect3DViewport_Release(Viewport
);
913 if (ExecuteBuffer
) IDirect3DExecuteBuffer_Release(ExecuteBuffer
);
914 if (Direct3DDevice1
) IDirect3DDevice_Release(Direct3DDevice1
);
915 if (Surface1
) IDirectDrawSurface_Release(Surface1
);
916 if (Direct3D1
) IDirect3D_Release(Direct3D1
);
917 if (DirectDraw1
) IDirectDraw_Release(DirectDraw1
);
920 static void ViewportTest(void)
923 IDirect3DViewport2
*Viewport2
;
924 IDirect3DViewport3
*Viewport3
;
925 D3DVIEWPORT vp1_data
, ret_vp1_data
;
926 D3DVIEWPORT2 vp2_data
, ret_vp2_data
;
929 *(DWORD
*)&infinity
= 0x7f800000;
931 hr
= IDirect3DDevice_AddViewport(Direct3DDevice1
, Viewport
);
932 ok(hr
== D3D_OK
, "IDirect3DDevice_AddViewport returned %08x\n", hr
);
934 hr
= IDirect3DViewport_QueryInterface(Viewport
, &IID_IDirect3DViewport2
, (void**) &Viewport2
);
935 ok(hr
==D3D_OK
, "QueryInterface returned: %x\n", hr
);
936 ok(Viewport2
== (IDirect3DViewport2
*)Viewport
, "IDirect3DViewport2 iface different from IDirect3DViewport\n");
938 hr
= IDirect3DViewport_QueryInterface(Viewport
, &IID_IDirect3DViewport3
, (void**) &Viewport3
);
939 ok(hr
==D3D_OK
, "QueryInterface returned: %x\n", hr
);
940 ok(Viewport3
== (IDirect3DViewport3
*)Viewport
, "IDirect3DViewport3 iface different from IDirect3DViewport\n");
941 IDirect3DViewport3_Release(Viewport3
);
943 vp1_data
.dwSize
= sizeof(vp1_data
);
946 vp1_data
.dwWidth
= 256;
947 vp1_data
.dwHeight
= 257;
950 vp1_data
.dvScaleX
= 0;
951 vp1_data
.dvScaleY
= 0;
952 vp1_data
.dvMinZ
= 0.25;
953 vp1_data
.dvMaxZ
= 0.75;
955 vp2_data
.dwSize
= sizeof(vp2_data
);
958 vp2_data
.dwWidth
= 258;
959 vp2_data
.dwHeight
= 259;
960 vp2_data
.dvClipX
= 0;
961 vp2_data
.dvClipY
= 0;
962 vp2_data
.dvClipWidth
= 0;
963 vp2_data
.dvClipHeight
= 0;
964 vp2_data
.dvMinZ
= 0.1;
965 vp2_data
.dvMaxZ
= 0.9;
967 hr
= IDirect3DViewport2_SetViewport(Viewport2
, &vp1_data
);
968 ok(hr
== D3D_OK
, "IDirect3DViewport2_SetViewport returned %08x\n", hr
);
970 memset(&ret_vp1_data
, 0xff, sizeof(ret_vp1_data
));
971 ret_vp1_data
.dwSize
= sizeof(vp1_data
);
973 hr
= IDirect3DViewport2_GetViewport(Viewport2
, &ret_vp1_data
);
974 ok(hr
== D3D_OK
, "IDirect3DViewport2_GetViewport returned %08x\n", hr
);
976 ok(ret_vp1_data
.dwX
== vp1_data
.dwX
, "dwX is %u, expected %u\n", ret_vp1_data
.dwX
, vp1_data
.dwX
);
977 ok(ret_vp1_data
.dwY
== vp1_data
.dwY
, "dwY is %u, expected %u\n", ret_vp1_data
.dwY
, vp1_data
.dwY
);
978 ok(ret_vp1_data
.dwWidth
== vp1_data
.dwWidth
, "dwWidth is %u, expected %u\n", ret_vp1_data
.dwWidth
, vp1_data
.dwWidth
);
979 ok(ret_vp1_data
.dwHeight
== vp1_data
.dwHeight
, "dwHeight is %u, expected %u\n", ret_vp1_data
.dwHeight
, vp1_data
.dwHeight
);
980 ok(ret_vp1_data
.dvMaxX
== vp1_data
.dvMaxX
, "dvMaxX is %f, expected %f\n", ret_vp1_data
.dvMaxX
, vp1_data
.dvMaxX
);
981 ok(ret_vp1_data
.dvMaxY
== vp1_data
.dvMaxY
, "dvMaxY is %f, expected %f\n", ret_vp1_data
.dvMaxY
, vp1_data
.dvMaxY
);
982 todo_wine
ok(ret_vp1_data
.dvScaleX
== infinity
, "dvScaleX is %f, expected %f\n", ret_vp1_data
.dvScaleX
, infinity
);
983 todo_wine
ok(ret_vp1_data
.dvScaleY
== infinity
, "dvScaleY is %f, expected %f\n", ret_vp1_data
.dvScaleY
, infinity
);
984 ok(ret_vp1_data
.dvMinZ
== 0.0, "dvMinZ is %f, expected 0.0\n", ret_vp1_data
.dvMinZ
);
985 ok(ret_vp1_data
.dvMaxZ
== 1.0, "dvMaxZ is %f, expected 1.0\n", ret_vp1_data
.dvMaxZ
);
987 hr
= IDirect3DViewport2_SetViewport2(Viewport2
, &vp2_data
);
988 ok(hr
== D3D_OK
, "IDirect3DViewport2_SetViewport2 returned %08x\n", hr
);
990 memset(&ret_vp2_data
, 0xff, sizeof(ret_vp2_data
));
991 ret_vp2_data
.dwSize
= sizeof(vp2_data
);
993 hr
= IDirect3DViewport2_GetViewport2(Viewport2
, &ret_vp2_data
);
994 ok(hr
== D3D_OK
, "IDirect3DViewport2_GetViewport2 returned %08x\n", hr
);
996 ok(ret_vp2_data
.dwX
== vp2_data
.dwX
, "dwX is %u, expected %u\n", ret_vp2_data
.dwX
, vp2_data
.dwX
);
997 ok(ret_vp2_data
.dwY
== vp2_data
.dwY
, "dwY is %u, expected %u\n", ret_vp2_data
.dwY
, vp2_data
.dwY
);
998 ok(ret_vp2_data
.dwWidth
== vp2_data
.dwWidth
, "dwWidth is %u, expected %u\n", ret_vp2_data
.dwWidth
, vp2_data
.dwWidth
);
999 ok(ret_vp2_data
.dwHeight
== vp2_data
.dwHeight
, "dwHeight is %u, expected %u\n", ret_vp2_data
.dwHeight
, vp2_data
.dwHeight
);
1000 ok(ret_vp2_data
.dvClipX
== vp2_data
.dvClipX
, "dvClipX is %f, expected %f\n", ret_vp2_data
.dvClipX
, vp2_data
.dvClipX
);
1001 ok(ret_vp2_data
.dvClipY
== vp2_data
.dvClipY
, "dvClipY is %f, expected %f\n", ret_vp2_data
.dvClipY
, vp2_data
.dvClipY
);
1002 ok(ret_vp2_data
.dvClipWidth
== vp2_data
.dvClipWidth
, "dvClipWidth is %f, expected %f\n",
1003 ret_vp2_data
.dvClipWidth
, vp2_data
.dvClipWidth
);
1004 ok(ret_vp2_data
.dvClipHeight
== vp2_data
.dvClipHeight
, "dvClipHeight is %f, expected %f\n",
1005 ret_vp2_data
.dvClipHeight
, vp2_data
.dvClipHeight
);
1006 ok(ret_vp2_data
.dvMinZ
== vp2_data
.dvMinZ
, "dvMinZ is %f, expected %f\n", ret_vp2_data
.dvMinZ
, vp2_data
.dvMinZ
);
1007 ok(ret_vp2_data
.dvMaxZ
== vp2_data
.dvMaxZ
, "dvMaxZ is %f, expected %f\n", ret_vp2_data
.dvMaxZ
, vp2_data
.dvMaxZ
);
1009 memset(&ret_vp1_data
, 0xff, sizeof(ret_vp1_data
));
1010 ret_vp1_data
.dwSize
= sizeof(vp1_data
);
1012 hr
= IDirect3DViewport2_GetViewport(Viewport2
, &ret_vp1_data
);
1013 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1015 ok(ret_vp1_data
.dwX
== vp2_data
.dwX
, "dwX is %u, expected %u.\n", ret_vp1_data
.dwX
, vp2_data
.dwX
);
1016 ok(ret_vp1_data
.dwY
== vp2_data
.dwY
, "dwY is %u, expected %u.\n", ret_vp1_data
.dwY
, vp2_data
.dwY
);
1017 ok(ret_vp1_data
.dwWidth
== vp2_data
.dwWidth
, "dwWidth is %u, expected %u.\n", ret_vp1_data
.dwWidth
, vp2_data
.dwWidth
);
1018 ok(ret_vp1_data
.dwHeight
== vp2_data
.dwHeight
, "dwHeight is %u, expected %u.\n", ret_vp1_data
.dwHeight
, vp2_data
.dwHeight
);
1019 ok(ret_vp1_data
.dvMaxX
== vp1_data
.dvMaxX
, "dvMaxX is %f, expected %f.\n", ret_vp1_data
.dvMaxX
, vp1_data
.dvMaxX
);
1020 ok(ret_vp1_data
.dvMaxY
== vp1_data
.dvMaxY
, "dvMaxY is %f, expected %f.\n", ret_vp1_data
.dvMaxY
, vp1_data
.dvMaxY
);
1021 ok(ret_vp1_data
.dvScaleX
== infinity
, "dvScaleX is %f, expected %f.\n", ret_vp1_data
.dvScaleX
, infinity
);
1022 ok(ret_vp1_data
.dvScaleY
== infinity
, "dvScaleY is %f, expected %f.\n", ret_vp1_data
.dvScaleY
, infinity
);
1023 ok(ret_vp1_data
.dvMinZ
== 0.0, "dvMinZ is %f, expected 0.0.\n", ret_vp1_data
.dvMinZ
);
1024 ok(ret_vp1_data
.dvMaxZ
== 1.0, "dvMaxZ is %f, expected 1.0.\n", ret_vp1_data
.dvMaxZ
);
1026 hr
= IDirect3DViewport2_SetViewport2(Viewport2
, &vp2_data
);
1027 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1029 memset(&ret_vp2_data
, 0xff, sizeof(ret_vp2_data
));
1030 ret_vp2_data
.dwSize
= sizeof(vp2_data
);
1032 hr
= IDirect3DViewport2_GetViewport2(Viewport2
, &ret_vp2_data
);
1033 ok(hr
== D3D_OK
, "IDirect3DViewport2_GetViewport2 returned %08x\n", hr
);
1035 ok(ret_vp2_data
.dwX
== vp2_data
.dwX
, "dwX is %u, expected %u\n", ret_vp2_data
.dwX
, vp2_data
.dwX
);
1036 ok(ret_vp2_data
.dwY
== vp2_data
.dwY
, "dwY is %u, expected %u\n", ret_vp2_data
.dwY
, vp2_data
.dwY
);
1037 ok(ret_vp2_data
.dwWidth
== vp2_data
.dwWidth
, "dwWidth is %u, expected %u\n", ret_vp2_data
.dwWidth
, vp2_data
.dwWidth
);
1038 ok(ret_vp2_data
.dwHeight
== vp2_data
.dwHeight
, "dwHeight is %u, expected %u\n", ret_vp2_data
.dwHeight
, vp2_data
.dwHeight
);
1039 ok(ret_vp2_data
.dvClipX
== vp2_data
.dvClipX
, "dvClipX is %f, expected %f\n", ret_vp2_data
.dvClipX
, vp2_data
.dvClipX
);
1040 ok(ret_vp2_data
.dvClipY
== vp2_data
.dvClipY
, "dvClipY is %f, expected %f\n", ret_vp2_data
.dvClipY
, vp2_data
.dvClipY
);
1041 ok(ret_vp2_data
.dvClipWidth
== vp2_data
.dvClipWidth
, "dvClipWidth is %f, expected %f\n",
1042 ret_vp2_data
.dvClipWidth
, vp2_data
.dvClipWidth
);
1043 ok(ret_vp2_data
.dvClipHeight
== vp2_data
.dvClipHeight
, "dvClipHeight is %f, expected %f\n",
1044 ret_vp2_data
.dvClipHeight
, vp2_data
.dvClipHeight
);
1045 ok(ret_vp2_data
.dvMinZ
== vp2_data
.dvMinZ
, "dvMinZ is %f, expected %f\n", ret_vp2_data
.dvMinZ
, vp2_data
.dvMinZ
);
1046 ok(ret_vp2_data
.dvMaxZ
== vp2_data
.dvMaxZ
, "dvMaxZ is %f, expected %f\n", ret_vp2_data
.dvMaxZ
, vp2_data
.dvMaxZ
);
1048 hr
= IDirect3DViewport2_SetViewport(Viewport2
, &vp1_data
);
1049 ok(hr
== D3D_OK
, "IDirect3DViewport2_SetViewport returned %08x\n", hr
);
1051 memset(&ret_vp1_data
, 0xff, sizeof(ret_vp1_data
));
1052 ret_vp1_data
.dwSize
= sizeof(vp1_data
);
1054 hr
= IDirect3DViewport2_GetViewport(Viewport2
, &ret_vp1_data
);
1055 ok(hr
== D3D_OK
, "IDirect3DViewport2_GetViewport returned %08x\n", hr
);
1057 ok(ret_vp1_data
.dwX
== vp1_data
.dwX
, "dwX is %u, expected %u\n", ret_vp1_data
.dwX
, vp1_data
.dwX
);
1058 ok(ret_vp1_data
.dwY
== vp1_data
.dwY
, "dwY is %u, expected %u\n", ret_vp1_data
.dwY
, vp1_data
.dwY
);
1059 ok(ret_vp1_data
.dwWidth
== vp1_data
.dwWidth
, "dwWidth is %u, expected %u\n", ret_vp1_data
.dwWidth
, vp1_data
.dwWidth
);
1060 ok(ret_vp1_data
.dwHeight
== vp1_data
.dwHeight
, "dwHeight is %u, expected %u\n", ret_vp1_data
.dwHeight
, vp1_data
.dwHeight
);
1061 ok(ret_vp1_data
.dvMaxX
== vp1_data
.dvMaxX
, "dvMaxX is %f, expected %f\n", ret_vp1_data
.dvMaxX
, vp1_data
.dvMaxX
);
1062 ok(ret_vp1_data
.dvMaxY
== vp1_data
.dvMaxY
, "dvMaxY is %f, expected %f\n", ret_vp1_data
.dvMaxY
, vp1_data
.dvMaxY
);
1063 todo_wine
ok(ret_vp1_data
.dvScaleX
== infinity
, "dvScaleX is %f, expected %f\n", ret_vp1_data
.dvScaleX
, infinity
);
1064 todo_wine
ok(ret_vp1_data
.dvScaleY
== infinity
, "dvScaleY is %f, expected %f\n", ret_vp1_data
.dvScaleY
, infinity
);
1065 ok(ret_vp1_data
.dvMinZ
== 0.0, "dvMinZ is %f, expected 0.0\n", ret_vp1_data
.dvMinZ
);
1066 ok(ret_vp1_data
.dvMaxZ
== 1.0, "dvMaxZ is %f, expected 1.0\n", ret_vp1_data
.dvMaxZ
);
1068 memset(&ret_vp2_data
, 0xff, sizeof(ret_vp2_data
));
1069 ret_vp2_data
.dwSize
= sizeof(vp2_data
);
1071 hr
= IDirect3DViewport2_GetViewport2(Viewport2
, &ret_vp2_data
);
1072 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1074 ok(ret_vp2_data
.dwX
== vp1_data
.dwX
, "dwX is %u, expected %u.\n", ret_vp2_data
.dwX
, vp1_data
.dwX
);
1075 ok(ret_vp2_data
.dwY
== vp1_data
.dwY
, "dwY is %u, expected %u.\n", ret_vp2_data
.dwY
, vp1_data
.dwY
);
1076 ok(ret_vp2_data
.dwWidth
== vp1_data
.dwWidth
, "dwWidth is %u, expected %u.\n",
1077 ret_vp2_data
.dwWidth
, vp1_data
.dwWidth
);
1078 ok(ret_vp2_data
.dwHeight
== vp1_data
.dwHeight
, "dwHeight is %u, expected %u.\n",
1079 ret_vp2_data
.dwHeight
, vp1_data
.dwHeight
);
1080 todo_wine
ok(ret_vp2_data
.dvClipX
== vp2_data
.dvClipX
, "dvClipX is %f, expected %f.\n",
1081 ret_vp2_data
.dvClipX
, vp2_data
.dvClipX
);
1082 todo_wine
ok(ret_vp2_data
.dvClipY
== vp2_data
.dvClipY
, "dvClipY is %f, expected %f.\n",
1083 ret_vp2_data
.dvClipY
, vp2_data
.dvClipY
);
1084 todo_wine
ok(ret_vp2_data
.dvClipWidth
== vp2_data
.dvClipWidth
, "dvClipWidth is %f, expected %f.\n",
1085 ret_vp2_data
.dvClipWidth
, vp2_data
.dvClipWidth
);
1086 todo_wine
ok(ret_vp2_data
.dvClipHeight
== vp2_data
.dvClipHeight
, "dvClipHeight is %f, expected %f.\n",
1087 ret_vp2_data
.dvClipHeight
, vp2_data
.dvClipHeight
);
1088 ok(ret_vp2_data
.dvMinZ
== 0.0, "dvMinZ is %f, expected 0.0.\n", ret_vp2_data
.dvMinZ
);
1089 ok(ret_vp2_data
.dvMaxZ
== 1.0, "dvMaxZ is %f, expected 1.0.\n", ret_vp2_data
.dvMaxZ
);
1091 IDirect3DViewport2_Release(Viewport2
);
1093 hr
= IDirect3DDevice_DeleteViewport(Direct3DDevice1
, Viewport
);
1094 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1097 static void Direct3D1Test(void)
1100 D3DEXECUTEBUFFERDESC desc
;
1101 D3DINSTRUCTION
*instr
;
1103 IDirect3D
*Direct3D_alt
;
1104 IDirect3DLight
*d3dlight
;
1106 unsigned int idx
= 0;
1108 /* Interface consistency check. */
1109 hr
= IDirect3DDevice_GetDirect3D(Direct3DDevice1
, &Direct3D_alt
);
1110 ok(hr
== D3D_OK
, "IDirect3DDevice_GetDirect3D failed: %08x\n", hr
);
1111 ok(Direct3D_alt
== Direct3D1
, "Direct3D1 struct pointer mismatch: %p != %p\n", Direct3D_alt
, Direct3D1
);
1112 IDirect3D_Release(Direct3D_alt
);
1114 memset(&desc
, 0, sizeof(desc
));
1115 desc
.dwSize
= sizeof(desc
);
1116 hr
= IDirect3DExecuteBuffer_Lock(ExecuteBuffer
, &desc
);
1117 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Lock failed: %08x\n", hr
);
1119 memset(desc
.lpData
, 0, 128);
1120 instr
= desc
.lpData
;
1121 instr
[idx
].bOpcode
= D3DOP_BRANCHFORWARD
;
1122 instr
[idx
].bSize
= sizeof(*branch
);
1123 instr
[idx
].wCount
= 1;
1125 branch
= (D3DBRANCH
*) &instr
[idx
];
1126 branch
->dwMask
= 0x0;
1127 branch
->dwValue
= 1;
1128 branch
->bNegate
= TRUE
;
1129 branch
->dwOffset
= 0;
1130 idx
+= (sizeof(*branch
) / sizeof(*instr
));
1131 instr
[idx
].bOpcode
= D3DOP_EXIT
;
1132 instr
[idx
].bSize
= 0;
1133 instr
[idx
].wCount
= 0;
1134 hr
= IDirect3DExecuteBuffer_Unlock(ExecuteBuffer
);
1135 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Unlock failed: %08x\n", hr
);
1137 hr
= IDirect3DDevice_Execute(Direct3DDevice1
, ExecuteBuffer
, Viewport
, D3DEXECUTE_CLIPPED
);
1138 ok(hr
== D3D_OK
, "IDirect3DDevice_Execute returned %08x\n", hr
);
1140 memset(&desc
, 0, sizeof(desc
));
1141 desc
.dwSize
= sizeof(desc
);
1143 hr
= IDirect3DExecuteBuffer_Lock(ExecuteBuffer
, &desc
);
1144 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Lock failed: %08x\n", hr
);
1146 memset(desc
.lpData
, 0, 128);
1147 instr
= desc
.lpData
;
1149 instr
[idx
].bOpcode
= D3DOP_BRANCHFORWARD
;
1150 instr
[idx
].bSize
= sizeof(*branch
);
1151 instr
[idx
].wCount
= 1;
1153 branch
= (D3DBRANCH
*) &instr
[idx
];
1154 branch
->dwMask
= 0x0;
1155 branch
->dwValue
= 1;
1156 branch
->bNegate
= TRUE
;
1157 branch
->dwOffset
= 64;
1158 instr
= (D3DINSTRUCTION
*)((char*)desc
.lpData
+ 64);
1159 instr
[0].bOpcode
= D3DOP_EXIT
;
1161 instr
[0].wCount
= 0;
1162 hr
= IDirect3DExecuteBuffer_Unlock(ExecuteBuffer
);
1163 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Unlock failed: %08x\n", hr
);
1165 hr
= IDirect3DDevice_Execute(Direct3DDevice1
, ExecuteBuffer
, Viewport
, D3DEXECUTE_CLIPPED
);
1166 ok(hr
== D3D_OK
, "IDirect3DDevice_Execute returned %08x\n", hr
);
1168 /* Test rendering 0 triangles */
1169 memset(&desc
, 0, sizeof(desc
));
1170 desc
.dwSize
= sizeof(desc
);
1172 hr
= IDirect3DExecuteBuffer_Lock(ExecuteBuffer
, &desc
);
1173 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Lock failed: %08x\n", hr
);
1175 memset(desc
.lpData
, 0, 128);
1176 instr
= desc
.lpData
;
1178 instr
->bOpcode
= D3DOP_TRIANGLE
;
1179 instr
->bSize
= sizeof(D3DOP_TRIANGLE
);
1182 instr
->bOpcode
= D3DOP_EXIT
;
1185 hr
= IDirect3DExecuteBuffer_Unlock(ExecuteBuffer
);
1186 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Unlock failed: %08x\n", hr
);
1188 hr
= IDirect3DDevice_Execute(Direct3DDevice1
, ExecuteBuffer
, Viewport
, D3DEXECUTE_CLIPPED
);
1189 ok(hr
== D3D_OK
, "IDirect3DDevice_Execute returned %08x\n", hr
);
1191 hr
= IDirect3DDevice_DeleteViewport(Direct3DDevice1
, Viewport
);
1192 ok(hr
== D3D_OK
, "IDirect3DDevice_DeleteViewport returned %08x\n", hr
);
1194 hr
= IDirect3DViewport_AddLight(Viewport
, Light
);
1195 ok(hr
== D3D_OK
, "IDirect3DViewport_AddLight returned %08x\n", hr
);
1196 refcount
= getRefcount((IUnknown
*) Light
);
1197 ok(refcount
== 2, "Refcount should be 2, returned is %d\n", refcount
);
1199 hr
= IDirect3DViewport_NextLight(Viewport
, NULL
, &d3dlight
, D3DNEXT_HEAD
);
1200 ok(hr
== D3D_OK
, "IDirect3DViewport_AddLight returned %08x\n", hr
);
1201 ok(d3dlight
== Light
, "Got different light returned %p, expected %p\n", d3dlight
, Light
);
1202 refcount
= getRefcount((IUnknown
*) Light
);
1203 ok(refcount
== 3, "Refcount should be 2, returned is %d\n", refcount
);
1205 hr
= IDirect3DViewport_DeleteLight(Viewport
, Light
);
1206 ok(hr
== D3D_OK
, "IDirect3DViewport_DeleteLight returned %08x\n", hr
);
1207 refcount
= getRefcount((IUnknown
*) Light
);
1208 ok(refcount
== 2, "Refcount should be 2, returned is %d\n", refcount
);
1210 IDirect3DLight_Release(Light
);
1213 static BOOL
colortables_check_equality(PALETTEENTRY table1
[256], PALETTEENTRY table2
[256])
1217 for (i
= 0; i
< 256; i
++) {
1218 if (table1
[i
].peRed
!= table2
[i
].peRed
|| table1
[i
].peGreen
!= table2
[i
].peGreen
||
1219 table1
[i
].peBlue
!= table2
[i
].peBlue
) return FALSE
;
1225 /* test palette handling in IDirect3DTexture_Load */
1226 static void TextureLoadTest(void)
1228 IDirectDrawSurface
*TexSurface
= NULL
;
1229 IDirect3DTexture
*Texture
= NULL
;
1230 IDirectDrawSurface
*TexSurface2
= NULL
;
1231 IDirect3DTexture
*Texture2
= NULL
;
1232 IDirectDrawPalette
*palette
= NULL
;
1233 IDirectDrawPalette
*palette2
= NULL
;
1234 IDirectDrawPalette
*palette_tmp
= NULL
;
1235 PALETTEENTRY table1
[256], table2
[256], table_tmp
[256];
1240 memset (&ddsd
, 0, sizeof (ddsd
));
1241 ddsd
.dwSize
= sizeof (ddsd
);
1242 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
1243 ddsd
.dwHeight
= 128;
1245 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1246 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
1247 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_PALETTEINDEXED8
;
1248 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 8;
1250 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &TexSurface
, NULL
);
1251 ok(hr
==D3D_OK
, "CreateSurface returned: %x\n", hr
);
1253 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1257 hr
= IDirectDrawSurface_QueryInterface(TexSurface
, &IID_IDirect3DTexture
,
1259 ok(hr
==D3D_OK
, "IDirectDrawSurface_QueryInterface returned: %x\n", hr
);
1261 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1265 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &TexSurface2
, NULL
);
1266 ok(hr
==D3D_OK
, "CreateSurface returned: %x\n", hr
);
1268 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1272 hr
= IDirectDrawSurface_QueryInterface(TexSurface2
, &IID_IDirect3DTexture
,
1274 ok(hr
==D3D_OK
, "IDirectDrawSurface_QueryInterface returned: %x\n", hr
);
1276 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1280 /* test load of Texture to Texture */
1281 hr
= IDirect3DTexture_Load(Texture
, Texture
);
1282 ok(hr
== DD_OK
, "IDirect3DTexture_Load returned %08x\n", hr
);
1284 /* test Load when both textures have no palette */
1285 hr
= IDirect3DTexture_Load(Texture2
, Texture
);
1286 ok(hr
== DD_OK
, "IDirect3DTexture_Load returned %08x\n", hr
);
1288 for (i
= 0; i
< 256; i
++) {
1289 table1
[i
].peRed
= i
;
1290 table1
[i
].peGreen
= i
;
1291 table1
[i
].peBlue
= i
;
1292 table1
[i
].peFlags
= 0;
1295 hr
= IDirectDraw_CreatePalette(DirectDraw1
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, table1
, &palette
, NULL
);
1296 ok(hr
== DD_OK
, "CreatePalette returned %08x\n", hr
);
1298 skip("IDirectDraw_CreatePalette failed; skipping further tests\n");
1302 /* test Load when source texture has palette and destination has no palette */
1303 hr
= IDirectDrawSurface_SetPalette(TexSurface
, palette
);
1304 ok(hr
== DD_OK
, "IDirectDrawSurface_SetPalette returned %08x\n", hr
);
1305 hr
= IDirect3DTexture_Load(Texture2
, Texture
);
1306 ok(hr
== DDERR_NOPALETTEATTACHED
, "IDirect3DTexture_Load returned %08x\n", hr
);
1308 for (i
= 0; i
< 256; i
++) {
1309 table2
[i
].peRed
= 255 - i
;
1310 table2
[i
].peGreen
= 255 - i
;
1311 table2
[i
].peBlue
= 255 - i
;
1312 table2
[i
].peFlags
= 0;
1315 hr
= IDirectDraw_CreatePalette(DirectDraw1
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, table2
, &palette2
, NULL
);
1316 ok(hr
== DD_OK
, "CreatePalette returned %08x\n", hr
);
1318 skip("IDirectDraw_CreatePalette failed; skipping further tests\n");
1322 /* test Load when source has no palette and destination has a palette */
1323 hr
= IDirectDrawSurface_SetPalette(TexSurface
, NULL
);
1324 ok(hr
== DD_OK
, "IDirectDrawSurface_SetPalette returned %08x\n", hr
);
1325 hr
= IDirectDrawSurface_SetPalette(TexSurface2
, palette2
);
1326 ok(hr
== DD_OK
, "IDirectDrawSurface_SetPalette returned %08x\n", hr
);
1327 hr
= IDirect3DTexture_Load(Texture2
, Texture
);
1328 ok(hr
== DD_OK
, "IDirect3DTexture_Load returned %08x\n", hr
);
1329 hr
= IDirectDrawSurface_GetPalette(TexSurface2
, &palette_tmp
);
1330 ok(hr
== DD_OK
, "IDirectDrawSurface_GetPalette returned %08x\n", hr
);
1332 skip("IDirectDrawSurface_GetPalette failed; skipping color table check\n");
1335 hr
= IDirectDrawPalette_GetEntries(palette_tmp
, 0, 0, 256, table_tmp
);
1336 ok(hr
== DD_OK
, "IDirectDrawPalette_GetEntries returned %08x\n", hr
);
1337 ok(colortables_check_equality(table2
, table_tmp
), "Unexpected palettized texture color table\n");
1338 IDirectDrawPalette_Release(palette_tmp
);
1341 /* test Load when both textures have palettes */
1342 hr
= IDirectDrawSurface_SetPalette(TexSurface
, palette
);
1343 ok(hr
== DD_OK
, "IDirectDrawSurface_SetPalette returned %08x\n", hr
);
1344 hr
= IDirect3DTexture_Load(Texture2
, Texture
);
1345 ok(hr
== DD_OK
, "IDirect3DTexture_Load returned %08x\n", hr
);
1346 hr
= IDirect3DTexture_Load(Texture2
, Texture
);
1347 ok(hr
== DD_OK
, "IDirect3DTexture_Load returned %08x\n", hr
);
1348 hr
= IDirectDrawSurface_GetPalette(TexSurface2
, &palette_tmp
);
1349 ok(hr
== DD_OK
, "IDirectDrawSurface_GetPalette returned %08x\n", hr
);
1351 skip("IDirectDrawSurface_GetPalette failed; skipping color table check\n");
1354 hr
= IDirectDrawPalette_GetEntries(palette_tmp
, 0, 0, 256, table_tmp
);
1355 ok(hr
== DD_OK
, "IDirectDrawPalette_GetEntries returned %08x\n", hr
);
1356 ok(colortables_check_equality(table1
, table_tmp
), "Unexpected palettized texture color table\n");
1357 IDirectDrawPalette_Release(palette_tmp
);
1362 if (palette
) IDirectDrawPalette_Release(palette
);
1363 if (palette2
) IDirectDrawPalette_Release(palette2
);
1364 if (TexSurface
) IDirectDrawSurface_Release(TexSurface
);
1365 if (Texture
) IDirect3DTexture_Release(Texture
);
1366 if (TexSurface2
) IDirectDrawSurface_Release(TexSurface2
);
1367 if (Texture2
) IDirect3DTexture_Release(Texture2
);
1370 static void VertexBufferDescTest(void)
1373 D3DVERTEXBUFFERDESC desc
;
1376 D3DVERTEXBUFFERDESC desc2
;
1377 unsigned char buffer
[512];
1380 memset(&desc
, 0, sizeof(desc
));
1381 desc
.dwSize
= sizeof(desc
);
1383 desc
.dwFVF
= D3DFVF_XYZ
;
1384 desc
.dwNumVertices
= 1;
1385 rc
= IDirect3D7_CreateVertexBuffer(lpD3D
, &desc
, &lpVBufSrc
, 0);
1386 ok(rc
==D3D_OK
|| rc
==E_OUTOFMEMORY
, "CreateVertexBuffer returned: %x\n", rc
);
1389 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc
);
1393 memset(mem
.buffer
, 0x12, sizeof(mem
.buffer
));
1394 mem
.desc2
.dwSize
= sizeof(D3DVERTEXBUFFERDESC
)*2;
1395 rc
= IDirect3DVertexBuffer7_GetVertexBufferDesc(lpVBufSrc
, &mem
.desc2
);
1397 skip("GetVertexBuffer Failed!\n");
1398 ok( mem
.desc2
.dwSize
== sizeof(D3DVERTEXBUFFERDESC
)*2, "Size returned from GetVertexBufferDesc does not match the value put in\n" );
1399 ok( mem
.buffer
[sizeof(D3DVERTEXBUFFERDESC
)] == 0x12, "GetVertexBufferDesc cleared outside of the struct! (dwSize was double the size of the struct)\n");
1400 ok( mem
.desc2
.dwCaps
== desc
.dwCaps
, "dwCaps returned differs. Got %x, expected %x\n", mem
.desc2
.dwCaps
, desc
.dwCaps
);
1401 ok( mem
.desc2
.dwFVF
== desc
.dwFVF
, "dwFVF returned differs. Got %x, expected %x\n", mem
.desc2
.dwFVF
, desc
.dwFVF
);
1402 ok (mem
.desc2
.dwNumVertices
== desc
.dwNumVertices
, "dwNumVertices returned differs. Got %x, expected %x\n", mem
.desc2
.dwNumVertices
, desc
.dwNumVertices
);
1404 memset(mem
.buffer
, 0x12, sizeof(mem
.buffer
));
1405 mem
.desc2
.dwSize
= 0;
1406 rc
= IDirect3DVertexBuffer7_GetVertexBufferDesc(lpVBufSrc
, &mem
.desc2
);
1408 skip("GetVertexBuffer Failed!\n");
1409 ok( mem
.desc2
.dwSize
== 0, "Size returned from GetVertexBufferDesc does not match the value put in\n" );
1410 ok( mem
.buffer
[sizeof(D3DVERTEXBUFFERDESC
)] == 0x12, "GetVertexBufferDesc cleared outside of the struct! (dwSize was 0)\n");
1411 ok( mem
.desc2
.dwCaps
== desc
.dwCaps
, "dwCaps returned differs. Got %x, expected %x\n", mem
.desc2
.dwCaps
, desc
.dwCaps
);
1412 ok( mem
.desc2
.dwFVF
== desc
.dwFVF
, "dwFVF returned differs. Got %x, expected %x\n", mem
.desc2
.dwFVF
, desc
.dwFVF
);
1413 ok (mem
.desc2
.dwNumVertices
== desc
.dwNumVertices
, "dwNumVertices returned differs. Got %x, expected %x\n", mem
.desc2
.dwNumVertices
, desc
.dwNumVertices
);
1415 memset(mem
.buffer
, 0x12, sizeof(mem
.buffer
));
1416 mem
.desc2
.dwSize
= sizeof(D3DVERTEXBUFFERDESC
);
1417 rc
= IDirect3DVertexBuffer7_GetVertexBufferDesc(lpVBufSrc
, &mem
.desc2
);
1419 skip("GetVertexBuffer Failed!\n");
1420 ok( mem
.desc2
.dwSize
== sizeof(D3DVERTEXBUFFERDESC
), "Size returned from GetVertexBufferDesc does not match the value put in\n" );
1421 ok( mem
.buffer
[sizeof(D3DVERTEXBUFFERDESC
)] == 0x12, "GetVertexBufferDesc cleared outside of the struct! (dwSize was the size of the struct)\n");
1422 ok( mem
.desc2
.dwCaps
== desc
.dwCaps
, "dwCaps returned differs. Got %x, expected %x\n", mem
.desc2
.dwCaps
, desc
.dwCaps
);
1423 ok( mem
.desc2
.dwFVF
== desc
.dwFVF
, "dwFVF returned differs. Got %x, expected %x\n", mem
.desc2
.dwFVF
, desc
.dwFVF
);
1424 ok (mem
.desc2
.dwNumVertices
== desc
.dwNumVertices
, "dwNumVertices returned differs. Got %x, expected %x\n", mem
.desc2
.dwNumVertices
, desc
.dwNumVertices
);
1427 IDirect3DVertexBuffer7_Release(lpVBufSrc
);
1430 static void SetMaterialTest(void)
1434 rc
=IDirect3DDevice7_SetMaterial(lpD3DDevice
, NULL
);
1435 ok(rc
== DDERR_INVALIDPARAMS
, "Expected DDERR_INVALIDPARAMS, got %x\n", rc
);
1438 static void SetRenderTargetTest(void)
1441 IDirectDrawSurface7
*newrt
, *failrt
, *oldrt
, *temprt
;
1443 DDSURFACEDESC2 ddsd
, ddsd2
;
1447 memset(&ddsd
, 0, sizeof(ddsd
));
1448 ddsd
.dwSize
= sizeof(ddsd
);
1449 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1450 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_3DDEVICE
;
1454 hr
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &newrt
, NULL
);
1455 ok(hr
== DD_OK
, "IDirectDraw7_CreateSurface failed, hr=0x%08x\n", hr
);
1458 skip("Skipping SetRenderTarget test\n");
1462 memset(&ddsd2
, 0, sizeof(ddsd2
));
1463 ddsd2
.dwSize
= sizeof(ddsd2
);
1464 ddsd2
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
1465 ddsd2
.ddsCaps
.dwCaps
= DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
;
1467 ddsd2
.dwHeight
= 64;
1468 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
1469 U4(ddsd2
).ddpfPixelFormat
.dwFlags
= DDPF_ZBUFFER
;
1470 U1(U4(ddsd2
).ddpfPixelFormat
).dwZBufferBitDepth
= 16;
1471 U3(U4(ddsd2
).ddpfPixelFormat
).dwZBitMask
= 0x0000FFFF;
1473 hr
= IDirectDraw7_CreateSurface(lpDD
, &ddsd2
, &failrt
, NULL
);
1474 ok(hr
== DD_OK
, "IDirectDraw7_CreateSurface failed, hr=0x%08x\n", hr
);
1476 memset(&vp
, 0, sizeof(vp
));
1483 hr
= IDirect3DDevice7_SetViewport(lpD3DDevice
, &vp
);
1484 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetViewport failed, hr=0x%08x\n", hr
);
1486 hr
= IDirect3DDevice7_GetRenderTarget(lpD3DDevice
, &oldrt
);
1487 ok(hr
== DD_OK
, "IDirect3DDevice7_GetRenderTarget failed, hr=0x%08x\n", hr
);
1489 refcount
= getRefcount((IUnknown
*) oldrt
);
1490 ok(refcount
== 3, "Refcount should be 3, returned is %d\n", refcount
);
1492 refcount
= getRefcount((IUnknown
*) failrt
);
1493 ok(refcount
== 1, "Refcount should be 1, returned is %d\n", refcount
);
1495 hr
= IDirect3DDevice7_SetRenderTarget(lpD3DDevice
, failrt
, 0);
1496 ok(hr
!= D3D_OK
, "IDirect3DDevice7_SetRenderTarget succeeded\n");
1498 refcount
= getRefcount((IUnknown
*) oldrt
);
1499 ok(refcount
== 2, "Refcount should be 2, returned is %d\n", refcount
);
1501 refcount
= getRefcount((IUnknown
*) failrt
);
1502 ok(refcount
== 2, "Refcount should be 2, returned is %d\n", refcount
);
1504 hr
= IDirect3DDevice7_GetRenderTarget(lpD3DDevice
, &temprt
);
1505 ok(hr
== DD_OK
, "IDirect3DDevice7_GetRenderTarget failed, hr=0x%08x\n", hr
);
1506 ok(failrt
== temprt
, "Wrong iface returned\n");
1508 refcount
= getRefcount((IUnknown
*) failrt
);
1509 ok(refcount
== 3, "Refcount should be 3, returned is %d\n", refcount
);
1511 hr
= IDirect3DDevice7_SetRenderTarget(lpD3DDevice
, newrt
, 0);
1512 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderTarget failed, hr=0x%08x\n", hr
);
1514 refcount
= getRefcount((IUnknown
*) failrt
);
1515 ok(refcount
== 2, "Refcount should be 2, returned is %d\n", refcount
);
1517 memset(&vp
, 0xff, sizeof(vp
));
1518 hr
= IDirect3DDevice7_GetViewport(lpD3DDevice
, &vp
);
1519 ok(hr
== D3D_OK
, "IDirect3DDevice7_GetViewport failed, hr=0x%08x\n", hr
);
1520 ok(vp
.dwX
== 10, "vp.dwX is %u, expected 10\n", vp
.dwX
);
1521 ok(vp
.dwY
== 10, "vp.dwY is %u, expected 10\n", vp
.dwY
);
1522 ok(vp
.dwWidth
== 246, "vp.dwWidth is %u, expected 246\n", vp
.dwWidth
);
1523 ok(vp
.dwHeight
== 246, "vp.dwHeight is %u, expected 246\n", vp
.dwHeight
);
1524 ok(vp
.dvMinZ
== 0.25, "vp.dvMinZ is %f, expected 0.25\n", vp
.dvMinZ
);
1525 ok(vp
.dvMaxZ
== 0.75, "vp.dvMaxZ is %f, expected 0.75\n", vp
.dvMaxZ
);
1527 memset(&vp
, 0, sizeof(vp
));
1534 hr
= IDirect3DDevice7_SetViewport(lpD3DDevice
, &vp
);
1535 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetViewport failed, hr=0x%08x\n", hr
);
1537 hr
= IDirect3DDevice7_BeginStateBlock(lpD3DDevice
);
1538 ok(hr
== D3D_OK
, "IDirect3DDevice7_BeginStateblock failed, hr=0x%08x\n", hr
);
1539 hr
= IDirect3DDevice7_SetRenderTarget(lpD3DDevice
, oldrt
, 0);
1540 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderTarget failed, hr=0x%08x\n", hr
);
1542 /* Check this twice, before and after ending the stateblock */
1543 memset(&vp
, 0xff, sizeof(vp
));
1544 hr
= IDirect3DDevice7_GetViewport(lpD3DDevice
, &vp
);
1545 ok(hr
== D3D_OK
, "IDirect3DDevice7_GetViewport failed, hr=0x%08x\n", hr
);
1546 ok(vp
.dwX
== 0, "vp.dwX is %u, expected 0\n", vp
.dwX
);
1547 ok(vp
.dwY
== 0, "vp.dwY is %u, expected 0\n", vp
.dwY
);
1548 ok(vp
.dwWidth
== 64, "vp.dwWidth is %u, expected 64\n", vp
.dwWidth
);
1549 ok(vp
.dwHeight
== 64, "vp.dwHeight is %u, expected 64\n", vp
.dwHeight
);
1550 ok(vp
.dvMinZ
== 0.0, "vp.dvMinZ is %f, expected 0.0\n", vp
.dvMinZ
);
1551 ok(vp
.dvMaxZ
== 1.0, "vp.dvMaxZ is %f, expected 1.0\n", vp
.dvMaxZ
);
1553 hr
= IDirect3DDevice7_EndStateBlock(lpD3DDevice
, &stateblock
);
1554 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndStateblock failed, hr=0x%08x\n", hr
);
1556 memset(&vp
, 0xff, sizeof(vp
));
1557 hr
= IDirect3DDevice7_GetViewport(lpD3DDevice
, &vp
);
1558 ok(hr
== D3D_OK
, "IDirect3DDevice7_GetViewport failed, hr=0x%08x\n", hr
);
1559 ok(vp
.dwX
== 0, "vp.dwX is %u, expected 0\n", vp
.dwX
);
1560 ok(vp
.dwY
== 0, "vp.dwY is %u, expected 0\n", vp
.dwY
);
1561 ok(vp
.dwWidth
== 64, "vp.dwWidth is %u, expected 64\n", vp
.dwWidth
);
1562 ok(vp
.dwHeight
== 64, "vp.dwHeight is %u, expected 64\n", vp
.dwHeight
);
1563 ok(vp
.dvMinZ
== 0.0, "vp.dvMinZ is %f, expected 0.0\n", vp
.dvMinZ
);
1564 ok(vp
.dvMaxZ
== 1.0, "vp.dvMaxZ is %f, expected 1.0\n", vp
.dvMaxZ
);
1566 hr
= IDirect3DDevice7_DeleteStateBlock(lpD3DDevice
, stateblock
);
1567 ok(hr
== D3D_OK
, "IDirect3DDevice7_DeleteStateblock failed, hr=0x%08x\n", hr
);
1569 memset(&vp
, 0, sizeof(vp
));
1576 hr
= IDirect3DDevice7_SetViewport(lpD3DDevice
, &vp
);
1577 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetViewport failed, hr=0x%08x\n", hr
);
1579 IDirectDrawSurface7_Release(oldrt
);
1580 IDirectDrawSurface7_Release(newrt
);
1581 IDirectDrawSurface7_Release(failrt
);
1582 IDirectDrawSurface7_Release(failrt
);
1585 static void VertexBufferLockRest(void)
1587 D3DVERTEXBUFFERDESC desc
;
1588 IDirect3DVertexBuffer7
*buffer
;
1595 const char *debug_string
;
1600 {0, "(none)", D3D_OK
},
1601 {DDLOCK_WAIT
, "DDLOCK_WAIT", D3D_OK
},
1602 {DDLOCK_EVENT
, "DDLOCK_EVENT", D3D_OK
},
1603 {DDLOCK_READONLY
, "DDLOCK_READONLY", D3D_OK
},
1604 {DDLOCK_WRITEONLY
, "DDLOCK_WRITEONLY", D3D_OK
},
1605 {DDLOCK_NOSYSLOCK
, "DDLOCK_NOSYSLOCK", D3D_OK
},
1606 {DDLOCK_NOOVERWRITE
, "DDLOCK_NOOVERWRITE", D3D_OK
},
1607 {DDLOCK_DISCARDCONTENTS
, "DDLOCK_DISCARDCONTENTS", D3D_OK
},
1609 {DDLOCK_READONLY
| DDLOCK_WRITEONLY
, "DDLOCK_READONLY | DDLOCK_WRITEONLY", D3D_OK
},
1610 {DDLOCK_READONLY
| DDLOCK_DISCARDCONTENTS
, "DDLOCK_READONLY | DDLOCK_DISCARDCONTENTS", D3D_OK
},
1611 {0xdeadbeef, "0xdeadbeef", D3D_OK
},
1614 memset(&desc
, 0 , sizeof(desc
));
1615 desc
.dwSize
= sizeof(desc
);
1617 desc
.dwFVF
= D3DFVF_XYZ
;
1618 desc
.dwNumVertices
= 64;
1619 hr
= IDirect3D7_CreateVertexBuffer(lpD3D
, &desc
, &buffer
, 0);
1620 ok(hr
== D3D_OK
, "IDirect3D7_CreateVertexBuffer failed, 0x%08x\n", hr
);
1622 for(i
= 0; i
< (sizeof(test_data
) / sizeof(*test_data
)); i
++)
1624 hr
= IDirect3DVertexBuffer7_Lock(buffer
, test_data
[i
].flags
, &data
, NULL
);
1625 ok(hr
== test_data
[i
].result
, "Lock flags %s returned 0x%08x, expected 0x%08x\n",
1626 test_data
[i
].debug_string
, hr
, test_data
[i
].result
);
1629 ok(data
!= NULL
, "The data pointer returned by Lock is NULL\n");
1630 hr
= IDirect3DVertexBuffer7_Unlock(buffer
);
1631 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer7_Unlock failed, 0x%08x\n", hr
);
1635 IDirect3DVertexBuffer7_Release(buffer
);
1638 static void BackBuffer3DCreateSurfaceTest(void)
1641 DDSURFACEDESC created_ddsd
;
1642 DDSURFACEDESC2 ddsd2
;
1643 IDirectDrawSurface
*surf
;
1644 IDirectDrawSurface4
*surf4
;
1645 IDirectDrawSurface7
*surf7
;
1651 IDirect3DDevice
*d3dhal
;
1653 const DWORD caps
= DDSCAPS_BACKBUFFER
| DDSCAPS_3DDEVICE
;
1654 const DWORD expected_caps
= DDSCAPS_BACKBUFFER
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
;
1656 memset(&ddcaps
, 0, sizeof(ddcaps
));
1657 ddcaps
.dwSize
= sizeof(DDCAPS
);
1658 hr
= IDirectDraw_GetCaps(DirectDraw1
, &ddcaps
, NULL
);
1659 ok(SUCCEEDED(hr
), "DirectDraw_GetCaps failed: 0x%08x\n", hr
);
1660 if (!(ddcaps
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
))
1662 skip("DDraw reported no VIDEOMEMORY cap. Broken video driver? Skipping surface caps tests.\n");
1666 memset(&ddsd
, 0, sizeof(ddsd
));
1667 ddsd
.dwSize
= sizeof(ddsd
);
1668 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1671 ddsd
.ddsCaps
.dwCaps
= caps
;
1672 memset(&ddsd2
, 0, sizeof(ddsd2
));
1673 ddsd2
.dwSize
= sizeof(ddsd2
);
1674 ddsd2
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1676 ddsd2
.dwHeight
= 64;
1677 ddsd2
.ddsCaps
.dwCaps
= caps
;
1678 memset(&created_ddsd
, 0, sizeof(created_ddsd
));
1679 created_ddsd
.dwSize
= sizeof(DDSURFACEDESC
);
1681 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &surf
, NULL
);
1682 ok(SUCCEEDED(hr
), "IDirectDraw_CreateSurface failed: 0x%08x\n", hr
);
1685 hr
= IDirectDrawSurface_GetSurfaceDesc(surf
, &created_ddsd
);
1686 ok(SUCCEEDED(hr
), "IDirectDraw_GetSurfaceDesc failed: 0x%08x\n", hr
);
1687 ok(created_ddsd
.ddsCaps
.dwCaps
== expected_caps
,
1688 "GetSurfaceDesc returned caps %x, expected %x\n", created_ddsd
.ddsCaps
.dwCaps
,
1691 hr
= IDirectDrawSurface_QueryInterface(surf
, &IID_IDirect3DHALDevice
, (void **)&d3dhal
);
1692 /* Currently Wine only supports the creation of one Direct3D device
1693 for a given DirectDraw instance. It has been created already
1694 in D3D1_createObjects() - IID_IDirect3DRGBDevice */
1695 todo_wine
ok(SUCCEEDED(hr
), "Expected IDirectDrawSurface::QueryInterface to succeed, got 0x%08x\n", hr
);
1698 IDirect3DDevice_Release(d3dhal
);
1700 IDirectDrawSurface_Release(surf
);
1703 hr
= IDirectDraw_QueryInterface(DirectDraw1
, &IID_IDirectDraw2
, (void **) &dd2
);
1704 ok(SUCCEEDED(hr
), "IDirectDraw_QueryInterface failed: 0x%08x\n", hr
);
1706 hr
= IDirectDraw2_CreateSurface(dd2
, &ddsd
, &surf
, NULL
);
1707 ok(hr
== DDERR_INVALIDCAPS
, "IDirectDraw2_CreateSurface didn't return %x08x, but %x08x\n",
1708 DDERR_INVALIDCAPS
, hr
);
1710 IDirectDraw2_Release(dd2
);
1712 hr
= IDirectDraw_QueryInterface(DirectDraw1
, &IID_IDirectDraw4
, (void **) &dd4
);
1713 ok(SUCCEEDED(hr
), "IDirectDraw_QueryInterface failed: 0x%08x\n", hr
);
1715 hr
= IDirectDraw4_CreateSurface(dd4
, &ddsd2
, &surf4
, NULL
);
1716 ok(hr
== DDERR_INVALIDCAPS
, "IDirectDraw4_CreateSurface didn't return %x08x, but %x08x\n",
1717 DDERR_INVALIDCAPS
, hr
);
1719 IDirectDraw4_Release(dd4
);
1721 hr
= IDirectDraw_QueryInterface(DirectDraw1
, &IID_IDirectDraw7
, (void **) &dd7
);
1722 ok(SUCCEEDED(hr
), "IDirectDraw_QueryInterface failed: 0x%08x\n", hr
);
1724 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd2
, &surf7
, NULL
);
1725 ok(hr
== DDERR_INVALIDCAPS
, "IDirectDraw7_CreateSurface didn't return %x08x, but %x08x\n",
1726 DDERR_INVALIDCAPS
, hr
);
1728 IDirectDraw7_Release(dd7
);
1731 static void BackBuffer3DAttachmentTest(void)
1734 IDirectDrawSurface
*surface1
, *surface2
, *surface3
, *surface4
;
1736 HWND window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1737 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1739 hr
= IDirectDraw_SetCooperativeLevel(DirectDraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1740 ok(hr
== DD_OK
, "SetCooperativeLevel returned %08x\n", hr
);
1742 /* Perform attachment tests on a back-buffer */
1743 memset(&ddsd
, 0, sizeof(ddsd
));
1744 ddsd
.dwSize
= sizeof(ddsd
);
1745 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1746 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_BACKBUFFER
| DDSCAPS_3DDEVICE
;
1747 ddsd
.dwWidth
= GetSystemMetrics(SM_CXSCREEN
);
1748 ddsd
.dwHeight
= GetSystemMetrics(SM_CYSCREEN
);
1749 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &surface2
, NULL
);
1750 ok(SUCCEEDED(hr
), "CreateSurface returned: %x\n",hr
);
1752 if (surface2
!= NULL
)
1754 /* Try a single primary and a two back buffers */
1755 memset(&ddsd
, 0, sizeof(ddsd
));
1756 ddsd
.dwSize
= sizeof(ddsd
);
1757 ddsd
.dwFlags
= DDSD_CAPS
;
1758 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
1759 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &surface1
, NULL
);
1760 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1762 memset(&ddsd
, 0, sizeof(ddsd
));
1763 ddsd
.dwSize
= sizeof(ddsd
);
1764 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1765 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_BACKBUFFER
| DDSCAPS_3DDEVICE
;
1766 ddsd
.dwWidth
= GetSystemMetrics(SM_CXSCREEN
);
1767 ddsd
.dwHeight
= GetSystemMetrics(SM_CYSCREEN
);
1768 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &surface3
, NULL
);
1769 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1771 /* This one has a different size */
1772 memset(&ddsd
, 0, sizeof(ddsd
));
1773 ddsd
.dwSize
= sizeof(ddsd
);
1774 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1775 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_BACKBUFFER
| DDSCAPS_3DDEVICE
;
1777 ddsd
.dwHeight
= 128;
1778 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &surface4
, NULL
);
1779 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1781 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
1782 todo_wine
ok(hr
== DD_OK
|| broken(hr
== DDERR_CANNOTATTACHSURFACE
),
1783 "Attaching a back buffer to a front buffer returned %08x\n", hr
);
1786 /* Try the reverse without detaching first */
1787 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
1788 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Attaching an attached surface to its attachee returned %08x\n", hr
);
1789 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
1790 ok(hr
== DD_OK
, "DeleteAttachedSurface failed with %08x\n", hr
);
1792 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
1793 todo_wine
ok(hr
== DD_OK
|| broken(hr
== DDERR_CANNOTATTACHSURFACE
),
1794 "Attaching a front buffer to a back buffer returned %08x\n", hr
);
1797 /* Try to detach reversed */
1798 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
1799 ok(hr
== DDERR_CANNOTDETACHSURFACE
, "DeleteAttachedSurface returned %08x\n", hr
);
1800 /* Now the proper detach */
1801 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface1
);
1802 ok(hr
== DD_OK
, "DeleteAttachedSurface failed with %08x\n", hr
);
1804 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface3
);
1805 todo_wine
ok(hr
== DD_OK
|| broken(hr
== DDERR_CANNOTATTACHSURFACE
),
1806 "Attaching a back buffer to another back buffer returned %08x\n", hr
);
1809 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface3
);
1810 ok(hr
== DD_OK
, "DeleteAttachedSurface failed with %08x\n", hr
);
1812 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
);
1813 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a back buffer to a front buffer of different size returned %08x\n", hr
);
1814 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
1815 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a front buffer to a back buffer of different size returned %08x\n", hr
);
1817 IDirectDrawSurface_Release(surface4
);
1818 IDirectDrawSurface_Release(surface3
);
1819 IDirectDrawSurface_Release(surface2
);
1820 IDirectDrawSurface_Release(surface1
);
1823 hr
=IDirectDraw_SetCooperativeLevel(DirectDraw1
, NULL
, DDSCL_NORMAL
);
1824 ok(hr
== DD_OK
, "SetCooperativeLevel returned %08x\n", hr
);
1826 DestroyWindow(window
);
1829 static void dump_format(const DDPIXELFORMAT
*fmt
)
1831 trace("dwFlags %08x, FourCC %08x, dwZBufferBitDepth %u, stencil %08x\n", fmt
->dwFlags
, fmt
->dwFourCC
,
1832 U1(*fmt
).dwZBufferBitDepth
, U2(*fmt
).dwStencilBitDepth
);
1833 trace("dwZBitMask %08x, dwStencilBitMask %08x, dwRGBZBitMask %08x\n", U3(*fmt
).dwZBitMask
,
1834 U4(*fmt
).dwStencilBitMask
, U5(*fmt
).dwRGBZBitMask
);
1837 static HRESULT WINAPI
enum_z_fmt_cb(DDPIXELFORMAT
*fmt
, void *ctx
)
1839 static const DDPIXELFORMAT formats
[] =
1842 sizeof(DDPIXELFORMAT
), DDPF_ZBUFFER
, 0,
1843 {16}, {0}, {0x0000ffff}, {0x00000000}, {0x00000000}
1846 sizeof(DDPIXELFORMAT
), DDPF_ZBUFFER
, 0,
1847 {32}, {0}, {0xffffff00}, {0x00000000}, {0x00000000}
1850 sizeof(DDPIXELFORMAT
), DDPF_ZBUFFER
| DDPF_STENCILBUFFER
, 0,
1851 {32}, {8}, {0xffffff00}, {0x000000ff}, {0x00000000}
1854 sizeof(DDPIXELFORMAT
), DDPF_ZBUFFER
, 0,
1855 {32}, {0}, {0x00ffffff}, {0x00000000}, {0x00000000}
1858 sizeof(DDPIXELFORMAT
), DDPF_ZBUFFER
| DDPF_STENCILBUFFER
, 0,
1859 {32}, {8}, {0x00ffffff}, {0xff000000}, {0x00000000}
1862 sizeof(DDPIXELFORMAT
), DDPF_ZBUFFER
, 0,
1863 {24}, {0}, {0x00ffffff}, {0x00000000}, {0x00000000}
1866 sizeof(DDPIXELFORMAT
), DDPF_ZBUFFER
, 0,
1867 {32}, {0}, {0xffffffff}, {0x00000000}, {0x00000000}
1870 unsigned int *count
= ctx
, i
, expected_pitch
;
1871 DDSURFACEDESC2 ddsd
;
1872 IDirectDrawSurface7
*surface
;
1876 memset(&ddsd
, 0, sizeof(ddsd
));
1877 ddsd
.dwSize
= sizeof(ddsd
);
1878 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
1879 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
1880 U4(ddsd
).ddpfPixelFormat
= *fmt
;
1881 ddsd
.dwWidth
= 1024;
1882 ddsd
.dwHeight
= 1024;
1883 hr
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &surface
, NULL
);
1884 ok(SUCCEEDED(hr
), "IDirectDraw7_CreateSurface failed, hr %#x.\n", hr
);
1885 memset(&ddsd
, 0, sizeof(ddsd
));
1886 ddsd
.dwSize
= sizeof(ddsd
);
1887 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
1888 ok(SUCCEEDED(hr
), "IDirectDrawSurface7_GetSurfaceDesc failed, hr %#x.\n", hr
);
1889 IDirectDrawSurface7_Release(surface
);
1891 ok(ddsd
.dwFlags
& DDSD_PIXELFORMAT
, "DDSD_PIXELFORMAT is not set\n");
1892 ok(!(ddsd
.dwFlags
& DDSD_ZBUFFERBITDEPTH
), "DDSD_ZBUFFERBITDEPTH is set\n");
1894 /* 24 bit unpadded depth buffers are actually padded(Geforce 9600, Win7,
1895 * Radeon 9000M WinXP) */
1896 if (U1(*fmt
).dwZBufferBitDepth
== 24) expected_pitch
= ddsd
.dwWidth
* 4;
1897 else expected_pitch
= ddsd
.dwWidth
* U1(*fmt
).dwZBufferBitDepth
/ 8;
1899 /* Some formats(16 bit depth without stencil) return pitch 0
1901 * The Radeon X1600 Catalyst 10.2 Windows XP driver returns an otherwise sane
1902 * pitch with an extra 128 bytes, regardless of the format and width */
1903 if (U1(ddsd
).lPitch
!= 0 && U1(ddsd
).lPitch
!= expected_pitch
1904 && !broken(U1(ddsd
).lPitch
== expected_pitch
+ 128))
1906 ok(0, "Z buffer pitch is %u, expected %u\n", U1(ddsd
).lPitch
, expected_pitch
);
1910 for (i
= 0; i
< (sizeof(formats
)/sizeof(*formats
)); i
++)
1912 if (memcmp(&formats
[i
], fmt
, fmt
->dwSize
) == 0) return DDENUMRET_OK
;
1915 ok(0, "Unexpected Z format enumerated\n");
1918 return DDENUMRET_OK
;
1921 static void z_format_test(void)
1923 unsigned int count
= 0;
1926 hr
= IDirect3D7_EnumZBufferFormats(lpD3D
, &IID_IDirect3DHALDevice
, enum_z_fmt_cb
, &count
);
1927 if (hr
== DDERR_NOZBUFFERHW
)
1929 skip("Z buffers not supported, skipping Z buffer format test\n");
1933 ok(SUCCEEDED(hr
), "IDirect3D7_EnumZBufferFormats failed, hr %#x.\n", hr
);
1934 ok(count
, "Expected at least one supported Z Buffer format\n");
1937 static void test_get_caps1(void)
1939 D3DDEVICEDESC hw_caps
, hel_caps
;
1943 memset(&hw_caps
, 0, sizeof(hw_caps
));
1944 hw_caps
.dwSize
= sizeof(hw_caps
);
1945 hw_caps
.dwFlags
= 0xdeadbeef;
1946 memset(&hel_caps
, 0, sizeof(hel_caps
));
1947 hel_caps
.dwSize
= sizeof(hel_caps
);
1948 hel_caps
.dwFlags
= 0xdeadc0de;
1951 hr
= IDirect3DDevice_GetCaps(Direct3DDevice1
, &hw_caps
, NULL
);
1952 ok(hr
== DDERR_INVALIDPARAMS
, "GetCaps with NULL hel caps returned hr %#x, expected INVALIDPARAMS.\n", hr
);
1953 ok(hw_caps
.dwFlags
== 0xdeadbeef, "hw_caps.dwFlags was modified: %#x.\n", hw_caps
.dwFlags
);
1954 hr
= IDirect3DDevice_GetCaps(Direct3DDevice1
, NULL
, &hel_caps
);
1955 ok(hr
== DDERR_INVALIDPARAMS
, "GetCaps with NULL hw caps returned hr %#x, expected INVALIDPARAMS.\n", hr
);
1956 ok(hel_caps
.dwFlags
== 0xdeadc0de, "hel_caps.dwFlags was modified: %#x.\n", hel_caps
.dwFlags
);
1958 /* Successful call: Both are modified */
1959 hr
= IDirect3DDevice_GetCaps(Direct3DDevice1
, &hw_caps
, &hel_caps
);
1960 ok(hr
== D3D_OK
, "GetCaps with correct size returned hr %#x, expected D3D_OK.\n", hr
);
1961 ok(hw_caps
.dwFlags
!= 0xdeadbeef, "hw_caps.dwFlags was not modified: %#x.\n", hw_caps
.dwFlags
);
1962 ok(hel_caps
.dwFlags
!= 0xdeadc0de, "hel_caps.dwFlags was not modified: %#x.\n", hel_caps
.dwFlags
);
1964 memset(&hw_caps
, 0, sizeof(hw_caps
));
1965 hw_caps
.dwSize
= sizeof(hw_caps
);
1966 hw_caps
.dwFlags
= 0xdeadbeef;
1967 memset(&hel_caps
, 0, sizeof(hel_caps
));
1968 /* Keep dwSize at 0 */
1969 hel_caps
.dwFlags
= 0xdeadc0de;
1971 /* If one is invalid the call fails */
1972 hr
= IDirect3DDevice_GetCaps(Direct3DDevice1
, &hw_caps
, &hel_caps
);
1973 ok(hr
== DDERR_INVALIDPARAMS
, "GetCaps with invalid hel_caps size returned hr %#x, expected INVALIDPARAMS.\n", hr
);
1974 ok(hw_caps
.dwFlags
== 0xdeadbeef, "hw_caps.dwFlags was modified: %#x.\n", hw_caps
.dwFlags
);
1975 ok(hel_caps
.dwFlags
== 0xdeadc0de, "hel_caps.dwFlags was modified: %#x.\n", hel_caps
.dwFlags
);
1976 hel_caps
.dwSize
= sizeof(hel_caps
);
1977 hw_caps
.dwSize
= sizeof(hw_caps
) + 1;
1978 hr
= IDirect3DDevice_GetCaps(Direct3DDevice1
, &hw_caps
, &hel_caps
);
1979 ok(hr
== DDERR_INVALIDPARAMS
, "GetCaps with invalid hw_caps size returned hr %#x, expected INVALIDPARAMS.\n", hr
);
1980 ok(hw_caps
.dwFlags
== 0xdeadbeef, "hw_caps.dwFlags was modified: %#x.\n", hw_caps
.dwFlags
);
1981 ok(hel_caps
.dwFlags
== 0xdeadc0de, "hel_caps.dwFlags was modified: %#x.\n", hel_caps
.dwFlags
);
1983 for (i
= 0; i
< 1024; i
++)
1985 memset(&hw_caps
, 0xfe, sizeof(hw_caps
));
1986 memset(&hel_caps
, 0xfe, sizeof(hel_caps
));
1987 hw_caps
.dwSize
= hel_caps
.dwSize
= i
;
1988 hr
= IDirect3DDevice_GetCaps(Direct3DDevice1
, &hw_caps
, &hel_caps
);
1991 /* D3DDEVICEDESCSIZE in old sdk versions */
1992 case FIELD_OFFSET(D3DDEVICEDESC
, dwMinTextureWidth
): /* 172, DirectX 3, IDirect3DDevice1 */
1993 ok(hw_caps
.dwMinTextureWidth
== 0xfefefefe, "hw_caps.dwMinTextureWidth was modified: %#x.\n",
1994 hw_caps
.dwMinTextureWidth
);
1995 ok(hel_caps
.dwMinTextureWidth
== 0xfefefefe, "hel_caps.dwMinTextureWidth was modified: %#x.\n",
1996 hel_caps
.dwMinTextureWidth
);
1998 case FIELD_OFFSET(D3DDEVICEDESC
, dwMaxTextureRepeat
): /* 204, DirectX 5, IDirect3DDevice2 */
1999 ok(hw_caps
.dwMaxTextureRepeat
== 0xfefefefe, "hw_caps.dwMaxTextureRepeat was modified: %#x.\n",
2000 hw_caps
.dwMaxTextureRepeat
);
2001 ok(hel_caps
.dwMaxTextureRepeat
== 0xfefefefe, "hel_caps.dwMaxTextureRepeat was modified: %#x.\n",
2002 hel_caps
.dwMaxTextureRepeat
);
2004 case sizeof(D3DDEVICEDESC
): /* 252, DirectX 6, IDirect3DDevice3 */
2005 ok(hr
== D3D_OK
, "GetCaps with size %u returned hr %#x, expected D3D_OK.\n", i
, hr
);
2009 ok(hr
== DDERR_INVALIDPARAMS
,
2010 "GetCaps with size %u returned hr %#x, expected DDERR_INVALIDPARAMS.\n", i
, hr
);
2015 /* Different valid sizes are OK */
2016 hw_caps
.dwSize
= 172;
2017 hel_caps
.dwSize
= sizeof(D3DDEVICEDESC
);
2018 hr
= IDirect3DDevice_GetCaps(Direct3DDevice1
, &hw_caps
, &hel_caps
);
2019 ok(hr
== D3D_OK
, "GetCaps with different sizes returned hr %#x, expected D3D_OK.\n", hr
);
2022 static void test_get_caps7(void)
2025 D3DDEVICEDESC7 desc
;
2027 hr
= IDirect3DDevice7_GetCaps(lpD3DDevice
, NULL
);
2028 ok(hr
== DDERR_INVALIDPARAMS
, "IDirect3DDevice7::GetCaps(NULL) returned hr %#x, expected INVALIDPARAMS.\n", hr
);
2030 memset(&desc
, 0, sizeof(desc
));
2031 hr
= IDirect3DDevice7_GetCaps(lpD3DDevice
, &desc
);
2032 ok(hr
== D3D_OK
, "IDirect3DDevice7::GetCaps(non-NULL) returned hr %#x, expected D3D_OK.\n", hr
);
2034 /* There's no dwSize in D3DDEVICEDESC7 */
2037 struct d3d2_test_context
2041 IDirectDrawSurface
*surface
;
2042 IDirect3DDevice2
*device
;
2043 IDirect3DViewport2
*viewport
;
2046 static void d3d2_release_objects(struct d3d2_test_context
*context
)
2051 if (context
->viewport
)
2053 hr
= IDirect3DDevice2_DeleteViewport(context
->device
, context
->viewport
);
2054 ok(hr
== D3D_OK
, "DeleteViewport returned %08x.\n", hr
);
2055 ref
= IDirect3DViewport2_Release(context
->viewport
);
2056 ok(ref
== 0, "Viewport has reference count %d, expected 0.\n", ref
);
2058 if (context
->device
)
2060 ref
= IDirect3DDevice2_Release(context
->device
);
2061 ok(ref
== 0, "Device has reference count %d, expected 0.\n", ref
);
2063 if (context
->surface
)
2065 ref
= IDirectDrawSurface_Release(context
->surface
);
2066 ok(ref
== 0, "Surface has reference count %d, expected 0.\n", ref
);
2070 ref
= IDirect3D2_Release(context
->d3d
);
2071 ok(ref
== 1, "IDirect3D2 has reference count %d, expected 1.\n", ref
);
2075 ref
= IDirectDraw_Release(context
->ddraw
);
2076 ok(ref
== 0, "DDraw has reference count %d, expected 0.\n", ref
);
2080 static BOOL
d3d2_create_objects(struct d3d2_test_context
*context
)
2084 D3DVIEWPORT vp_data
;
2086 memset(context
, 0, sizeof(*context
));
2088 hr
= DirectDrawCreate(NULL
, &context
->ddraw
, NULL
);
2089 ok(hr
== DD_OK
|| hr
== DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreate failed: %08x.\n", hr
);
2090 if (!context
->ddraw
) goto error
;
2092 hr
= IDirectDraw_SetCooperativeLevel(context
->ddraw
, NULL
, DDSCL_NORMAL
);
2093 ok(hr
== DD_OK
, "SetCooperativeLevel failed: %08x.\n", hr
);
2094 if (FAILED(hr
)) goto error
;
2096 hr
= IDirectDraw_QueryInterface(context
->ddraw
, &IID_IDirect3D2
, (void**) &context
->d3d
);
2097 ok(hr
== DD_OK
|| hr
== E_NOINTERFACE
, "QueryInterface failed: %08x.\n", hr
);
2098 if (!context
->d3d
) goto error
;
2100 memset(&ddsd
, 0, sizeof(ddsd
));
2101 ddsd
.dwSize
= sizeof(ddsd
);
2102 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
2103 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
2105 ddsd
.dwHeight
= 256;
2106 IDirectDraw_CreateSurface(context
->ddraw
, &ddsd
, &context
->surface
, NULL
);
2107 if (!context
->surface
)
2109 skip("DDSCAPS_3DDEVICE surface not available.\n");
2113 hr
= IDirect3D2_CreateDevice(context
->d3d
, &IID_IDirect3DHALDevice
, context
->surface
, &context
->device
);
2114 ok(hr
== D3D_OK
|| hr
== E_OUTOFMEMORY
|| hr
== E_NOINTERFACE
, "CreateDevice failed: %08x.\n", hr
);
2115 if (!context
->device
) goto error
;
2117 hr
= IDirect3D2_CreateViewport(context
->d3d
, &context
->viewport
, NULL
);
2118 ok(hr
== D3D_OK
, "CreateViewport failed: %08x.\n", hr
);
2119 if (!context
->viewport
) goto error
;
2121 hr
= IDirect3DDevice2_AddViewport(context
->device
, context
->viewport
);
2122 ok(hr
== D3D_OK
, "AddViewport returned %08x.\n", hr
);
2123 vp_data
.dwSize
= sizeof(vp_data
);
2126 vp_data
.dwWidth
= 256;
2127 vp_data
.dwHeight
= 256;
2128 vp_data
.dvScaleX
= 1;
2129 vp_data
.dvScaleY
= 1;
2130 vp_data
.dvMaxX
= 256;
2131 vp_data
.dvMaxY
= 256;
2134 hr
= IDirect3DViewport2_SetViewport(context
->viewport
, &vp_data
);
2135 ok(hr
== D3D_OK
, "SetViewport returned %08x.\n", hr
);
2140 d3d2_release_objects(context
);
2144 static void test_get_caps2(const struct d3d2_test_context
*context
)
2146 D3DDEVICEDESC hw_caps
, hel_caps
;
2150 memset(&hw_caps
, 0, sizeof(hw_caps
));
2151 hw_caps
.dwSize
= sizeof(hw_caps
);
2152 hw_caps
.dwFlags
= 0xdeadbeef;
2153 memset(&hel_caps
, 0, sizeof(hel_caps
));
2154 hel_caps
.dwSize
= sizeof(hel_caps
);
2155 hel_caps
.dwFlags
= 0xdeadc0de;
2158 hr
= IDirect3DDevice2_GetCaps(context
->device
, &hw_caps
, NULL
);
2159 ok(hr
== DDERR_INVALIDPARAMS
, "GetCaps with NULL hel caps returned hr %#x, expected INVALIDPARAMS.\n", hr
);
2160 ok(hw_caps
.dwFlags
== 0xdeadbeef, "hw_caps.dwFlags was modified: %#x.\n", hw_caps
.dwFlags
);
2161 hr
= IDirect3DDevice2_GetCaps(context
->device
, NULL
, &hel_caps
);
2162 ok(hr
== DDERR_INVALIDPARAMS
, "GetCaps with NULL hw caps returned hr %#x, expected INVALIDPARAMS.\n", hr
);
2163 ok(hel_caps
.dwFlags
== 0xdeadc0de, "hel_caps.dwFlags was modified: %#x.\n", hel_caps
.dwFlags
);
2165 /* Successful call: Both are modified */
2166 hr
= IDirect3DDevice2_GetCaps(context
->device
, &hw_caps
, &hel_caps
);
2167 ok(hr
== D3D_OK
, "GetCaps with correct size returned hr %#x, expected D3D_OK.\n", hr
);
2168 ok(hw_caps
.dwFlags
!= 0xdeadbeef, "hw_caps.dwFlags was not modified: %#x.\n", hw_caps
.dwFlags
);
2169 ok(hel_caps
.dwFlags
!= 0xdeadc0de, "hel_caps.dwFlags was not modified: %#x.\n", hel_caps
.dwFlags
);
2171 memset(&hw_caps
, 0, sizeof(hw_caps
));
2172 hw_caps
.dwSize
= sizeof(hw_caps
);
2173 hw_caps
.dwFlags
= 0xdeadbeef;
2174 memset(&hel_caps
, 0, sizeof(hel_caps
));
2175 /* Keep dwSize at 0 */
2176 hel_caps
.dwFlags
= 0xdeadc0de;
2178 /* If one is invalid the call fails */
2179 hr
= IDirect3DDevice2_GetCaps(context
->device
, &hw_caps
, &hel_caps
);
2180 ok(hr
== DDERR_INVALIDPARAMS
, "GetCaps with invalid hel_caps size returned hr %#x, expected INVALIDPARAMS.\n", hr
);
2181 ok(hw_caps
.dwFlags
== 0xdeadbeef, "hw_caps.dwFlags was modified: %#x.\n", hw_caps
.dwFlags
);
2182 ok(hel_caps
.dwFlags
== 0xdeadc0de, "hel_caps.dwFlags was modified: %#x.\n", hel_caps
.dwFlags
);
2183 hel_caps
.dwSize
= sizeof(hel_caps
);
2184 hw_caps
.dwSize
= sizeof(hw_caps
) + 1;
2185 hr
= IDirect3DDevice2_GetCaps(context
->device
, &hw_caps
, &hel_caps
);
2186 ok(hr
== DDERR_INVALIDPARAMS
, "GetCaps with invalid hw_caps size returned hr %#x, expected INVALIDPARAMS.\n", hr
);
2187 ok(hw_caps
.dwFlags
== 0xdeadbeef, "hw_caps.dwFlags was modified: %#x.\n", hw_caps
.dwFlags
);
2188 ok(hel_caps
.dwFlags
== 0xdeadc0de, "hel_caps.dwFlags was modified: %#x.\n", hel_caps
.dwFlags
);
2190 for (i
= 0; i
< 1024; i
++)
2192 memset(&hw_caps
, 0xfe, sizeof(hw_caps
));
2193 memset(&hel_caps
, 0xfe, sizeof(hel_caps
));
2194 hw_caps
.dwSize
= hel_caps
.dwSize
= i
;
2195 hr
= IDirect3DDevice2_GetCaps(context
->device
, &hw_caps
, &hel_caps
);
2198 /* D3DDEVICEDESCSIZE in old sdk versions */
2199 case FIELD_OFFSET(D3DDEVICEDESC
, dwMinTextureWidth
): /* 172, DirectX 3, IDirect3DDevice1 */
2200 ok(hw_caps
.dwMinTextureWidth
== 0xfefefefe, "dwMinTextureWidth was modified: %#x.\n",
2201 hw_caps
.dwMinTextureWidth
);
2202 ok(hel_caps
.dwMinTextureWidth
== 0xfefefefe, "dwMinTextureWidth was modified: %#x.\n",
2203 hel_caps
.dwMinTextureWidth
);
2205 case FIELD_OFFSET(D3DDEVICEDESC
, dwMaxTextureRepeat
): /* 204, DirectX 5, IDirect3DDevice2 */
2206 ok(hw_caps
.dwMaxTextureRepeat
== 0xfefefefe, "dwMaxTextureRepeat was modified: %#x.\n",
2207 hw_caps
.dwMaxTextureRepeat
);
2208 ok(hel_caps
.dwMaxTextureRepeat
== 0xfefefefe, "dwMaxTextureRepeat was modified: %#x.\n",
2209 hel_caps
.dwMaxTextureRepeat
);
2211 case sizeof(D3DDEVICEDESC
): /* 252, DirectX 6, IDirect3DDevice3 */
2212 ok(hr
== D3D_OK
, "GetCaps with size %u returned hr %#x, expected D3D_OK.\n", i
, hr
);
2216 ok(hr
== DDERR_INVALIDPARAMS
,
2217 "GetCaps with size %u returned hr %#x, expected DDERR_INVALIDPARAMS.\n", i
, hr
);
2222 /* Different valid sizes are OK */
2223 hw_caps
.dwSize
= 172;
2224 hel_caps
.dwSize
= sizeof(D3DDEVICEDESC
);
2225 hr
= IDirect3DDevice2_GetCaps(context
->device
, &hw_caps
, &hel_caps
);
2226 ok(hr
== D3D_OK
, "GetCaps with different sizes returned hr %#x, expected D3D_OK.\n", hr
);
2231 struct d3d2_test_context d3d2_context
;
2232 void (* const d3d2_tests
[])(const struct d3d2_test_context
*) =
2238 init_function_pointers();
2239 if(!pDirectDrawCreateEx
) {
2240 win_skip("function DirectDrawCreateEx not available\n");
2244 if(!CreateDirect3D()) {
2245 skip("Skipping d3d7 tests\n");
2250 D3D7EnumLifetimeTest();
2253 VertexBufferDescTest();
2254 SetRenderTargetTest();
2255 VertexBufferLockRest();
2261 for (i
= 0; i
< (sizeof(d3d2_tests
) / sizeof(*d3d2_tests
)); i
++)
2263 if (!d3d2_create_objects(&d3d2_context
))
2265 ok(!i
, "Unexpected d3d2 initialization failure.\n");
2266 skip("Skipping d3d2 tests.\n");
2269 d3d2_tests
[i
](&d3d2_context
);
2270 d3d2_release_objects(&d3d2_context
);
2273 if (!D3D1_createObjects()) {
2274 skip("Skipping d3d1 tests\n");
2279 BackBuffer3DCreateSurfaceTest();
2280 BackBuffer3DAttachmentTest();
2282 D3D1_releaseObjects();