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
)(LPGUID
,LPVOID
*,REFIID
,LPUNKNOWN
);
72 static void init_function_pointers(void)
74 HMODULE hmod
= GetModuleHandleA("ddraw.dll");
75 pDirectDrawCreateEx
= (void*)GetProcAddress(hmod
, "DirectDrawCreateEx");
79 static ULONG
getRefcount(IUnknown
*iface
)
81 IUnknown_AddRef(iface
);
82 return IUnknown_Release(iface
);
85 static HRESULT WINAPI
SurfaceCounter(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
89 IDirectDrawSurface_Release(surface
);
93 static BOOL
CreateDirect3D(void)
99 rc
= pDirectDrawCreateEx(NULL
, (void**)&lpDD
,
100 &IID_IDirectDraw7
, NULL
);
101 ok(rc
==DD_OK
|| rc
==DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreateEx returned: %x\n", rc
);
103 trace("DirectDrawCreateEx() failed with an error %x\n", rc
);
107 rc
= IDirectDraw_SetCooperativeLevel(lpDD
, NULL
, DDSCL_NORMAL
);
108 ok(rc
==DD_OK
, "SetCooperativeLevel returned: %x\n", rc
);
110 rc
= IDirectDraw7_QueryInterface(lpDD
, &IID_IDirect3D7
, (void**) &lpD3D
);
111 if (rc
== E_NOINTERFACE
) return FALSE
;
112 ok(rc
==DD_OK
, "QueryInterface returned: %x\n", rc
);
114 memset(&ddsd
, 0, sizeof(ddsd
));
115 ddsd
.dwSize
= sizeof(ddsd
);
116 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
117 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
120 rc
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &lpDDS
, NULL
);
125 IDirectDraw7_EnumSurfaces(lpDD
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
, NULL
, &num
, SurfaceCounter
);
126 ok(num
== 1, "Has %d surfaces, expected 1\n", num
);
128 memset(&ddsd
, 0, sizeof(ddsd
));
129 ddsd
.dwSize
= sizeof(ddsd
);
130 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
131 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
132 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
133 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_ZBUFFER
;
134 U1(U4(ddsd
).ddpfPixelFormat
).dwZBufferBitDepth
= 16;
135 U3(U4(ddsd
).ddpfPixelFormat
).dwZBitMask
= 0x0000FFFF;
138 rc
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &lpDDSdepth
, NULL
);
139 ok(rc
==DD_OK
, "CreateSurface returned: %x\n", rc
);
143 rc
= IDirectDrawSurface_AddAttachedSurface(lpDDS
, lpDDSdepth
);
144 ok(rc
== DD_OK
, "IDirectDrawSurface_AddAttachedSurface returned %x\n", rc
);
149 rc
= IDirect3D7_CreateDevice(lpD3D
, &IID_IDirect3DTnLHalDevice
, lpDDS
,
151 ok(rc
==D3D_OK
|| rc
==DDERR_NOPALETTEATTACHED
|| rc
==E_OUTOFMEMORY
, "CreateDevice returned: %x\n", rc
);
153 trace("IDirect3D7::CreateDevice() for a TnL Hal device failed with an error %x, trying HAL\n", rc
);
154 rc
= IDirect3D7_CreateDevice(lpD3D
, &IID_IDirect3DHALDevice
, lpDDS
,
157 trace("IDirect3D7::CreateDevice() for a HAL device failed with an error %x, trying RGB\n", rc
);
158 rc
= IDirect3D7_CreateDevice(lpD3D
, &IID_IDirect3DRGBDevice
, lpDDS
,
161 trace("IDirect3D7::CreateDevice() for a RGB device failed with an error %x, giving up\n", rc
);
170 static void ReleaseDirect3D(void)
172 if (lpD3DDevice
!= NULL
)
174 IDirect3DDevice7_Release(lpD3DDevice
);
178 if (lpDDSdepth
!= NULL
)
180 IDirectDrawSurface_Release(lpDDSdepth
);
186 IDirectDrawSurface_Release(lpDDS
);
192 IDirect3D7_Release(lpD3D
);
198 IDirectDraw_Release(lpDD
);
203 static void LightTest(void)
207 D3DLIGHT7 defaultlight
;
208 BOOL bEnabled
= FALSE
;
216 /* Set a few lights with funky indices. */
217 memset(&light
, 0, sizeof(light
));
218 light
.dltType
= D3DLIGHT_DIRECTIONAL
;
219 U1(light
.dcvDiffuse
).r
= 0.5f
;
220 U2(light
.dcvDiffuse
).g
= 0.6f
;
221 U3(light
.dcvDiffuse
).b
= 0.7f
;
222 U2(light
.dvDirection
).y
= 1.f
;
224 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 5, &light
);
225 ok(rc
==D3D_OK
, "SetLight returned: %x\n", rc
);
226 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 10, &light
);
227 ok(rc
==D3D_OK
, "SetLight returned: %x\n", rc
);
228 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 45, &light
);
229 ok(rc
==D3D_OK
, "SetLight returned: %x\n", rc
);
232 /* Try to retrieve a light beyond the indices of the lights that have
234 rc
= IDirect3DDevice7_GetLight(lpD3DDevice
, 50, &light
);
235 ok(rc
==DDERR_INVALIDPARAMS
, "GetLight returned: %x\n", rc
);
236 rc
= IDirect3DDevice7_GetLight(lpD3DDevice
, 2, &light
);
237 ok(rc
==DDERR_INVALIDPARAMS
, "GetLight returned: %x\n", rc
);
240 /* Try to retrieve one of the lights that have been set */
241 rc
= IDirect3DDevice7_GetLight(lpD3DDevice
, 10, &light
);
242 ok(rc
==D3D_OK
, "GetLight returned: %x\n", rc
);
245 /* Enable a light that have been previously set. */
246 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, 10, TRUE
);
247 ok(rc
==D3D_OK
, "LightEnable returned: %x\n", rc
);
250 /* Enable some lights that have not been previously set, and verify that
251 they have been initialized with proper default values. */
252 memset(&defaultlight
, 0, sizeof(D3DLIGHT7
));
253 defaultlight
.dltType
= D3DLIGHT_DIRECTIONAL
;
254 U1(defaultlight
.dcvDiffuse
).r
= 1.f
;
255 U2(defaultlight
.dcvDiffuse
).g
= 1.f
;
256 U3(defaultlight
.dcvDiffuse
).b
= 1.f
;
257 U3(defaultlight
.dvDirection
).z
= 1.f
;
259 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, 20, TRUE
);
260 ok(rc
==D3D_OK
, "LightEnable returned: %x\n", rc
);
261 memset(&light
, 0, sizeof(D3DLIGHT7
));
262 rc
= IDirect3DDevice7_GetLight(lpD3DDevice
, 20, &light
);
263 ok(rc
==D3D_OK
, "GetLight returned: %x\n", rc
);
264 ok(!memcmp(&light
, &defaultlight
, sizeof(D3DLIGHT7
)),
265 "light data doesn't match expected default values\n" );
267 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, 50, TRUE
);
268 ok(rc
==D3D_OK
, "LightEnable returned: %x\n", rc
);
269 memset(&light
, 0, sizeof(D3DLIGHT7
));
270 rc
= IDirect3DDevice7_GetLight(lpD3DDevice
, 50, &light
);
271 ok(rc
==D3D_OK
, "GetLight returned: %x\n", rc
);
272 ok(!memcmp(&light
, &defaultlight
, sizeof(D3DLIGHT7
)),
273 "light data doesn't match expected default values\n" );
276 /* Disable one of the light that have been previously enabled. */
277 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, 20, FALSE
);
278 ok(rc
==D3D_OK
, "LightEnable returned: %x\n", rc
);
280 /* Try to retrieve the enable status of some lights */
281 /* Light 20 is supposed to be disabled */
282 rc
= IDirect3DDevice7_GetLightEnable(lpD3DDevice
, 20, &bEnabled
);
283 ok(rc
==D3D_OK
, "GetLightEnable returned: %x\n", rc
);
284 ok(!bEnabled
, "GetLightEnable says the light is enabled\n");
286 /* Light 10 is supposed to be enabled */
288 rc
= IDirect3DDevice7_GetLightEnable(lpD3DDevice
, 10, &bEnabled
);
289 ok(rc
==D3D_OK
, "GetLightEnable returned: %x\n", rc
);
290 ok(bEnabled
, "GetLightEnable says the light is disabled\n");
292 /* Light 80 has not been set */
293 rc
= IDirect3DDevice7_GetLightEnable(lpD3DDevice
, 80, &bEnabled
);
294 ok(rc
==DDERR_INVALIDPARAMS
, "GetLightEnable returned: %x\n", rc
);
296 /* Light 23 has not been set */
297 rc
= IDirect3DDevice7_GetLightEnable(lpD3DDevice
, 23, &bEnabled
);
298 ok(rc
==DDERR_INVALIDPARAMS
, "GetLightEnable returned: %x\n", rc
);
300 /* Set some lights with invalid parameters */
301 memset(&light
, 0, sizeof(D3DLIGHT7
));
303 U1(light
.dcvDiffuse
).r
= 1.f
;
304 U2(light
.dcvDiffuse
).g
= 1.f
;
305 U3(light
.dcvDiffuse
).b
= 1.f
;
306 U3(light
.dvDirection
).z
= 1.f
;
307 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 100, &light
);
308 ok(rc
==DDERR_INVALIDPARAMS
, "SetLight returned: %x\n", rc
);
310 memset(&light
, 0, sizeof(D3DLIGHT7
));
311 light
.dltType
= 12345;
312 U1(light
.dcvDiffuse
).r
= 1.f
;
313 U2(light
.dcvDiffuse
).g
= 1.f
;
314 U3(light
.dcvDiffuse
).b
= 1.f
;
315 U3(light
.dvDirection
).z
= 1.f
;
316 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 101, &light
);
317 ok(rc
==DDERR_INVALIDPARAMS
, "SetLight returned: %x\n", rc
);
319 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 102, NULL
);
320 ok(rc
==DDERR_INVALIDPARAMS
, "SetLight returned: %x\n", rc
);
322 memset(&light
, 0, sizeof(D3DLIGHT7
));
323 light
.dltType
= D3DLIGHT_SPOT
;
324 U1(light
.dcvDiffuse
).r
= 1.f
;
325 U2(light
.dcvDiffuse
).g
= 1.f
;
326 U3(light
.dcvDiffuse
).b
= 1.f
;
327 U3(light
.dvDirection
).z
= 1.f
;
329 light
.dvAttenuation0
= -one
/ zero
; /* -INFINITY */
330 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 103, &light
);
331 ok(rc
==DDERR_INVALIDPARAMS
, "SetLight returned: %x\n", rc
);
333 light
.dvAttenuation0
= -1.0;
334 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 103, &light
);
335 ok(rc
==DDERR_INVALIDPARAMS
, "SetLight returned: %x\n", rc
);
337 light
.dvAttenuation0
= 0.0;
338 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 103, &light
);
339 ok(rc
==D3D_OK
, "SetLight returned: %x\n", rc
);
341 light
.dvAttenuation0
= 1.0;
342 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 103, &light
);
343 ok(rc
==D3D_OK
, "SetLight returned: %x\n", rc
);
345 light
.dvAttenuation0
= one
/ zero
; /* +INFINITY */
346 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 103, &light
);
347 ok(rc
==D3D_OK
, "SetLight returned: %x\n", rc
);
349 light
.dvAttenuation0
= zero
/ zero
; /* NaN */
350 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 103, &light
);
352 broken(rc
==DDERR_INVALIDPARAMS
), "SetLight returned: %x\n", rc
);
354 /* Directional light ignores attenuation */
355 light
.dltType
= D3DLIGHT_DIRECTIONAL
;
356 light
.dvAttenuation0
= -1.0;
357 rc
= IDirect3DDevice7_SetLight(lpD3DDevice
, 103, &light
);
358 ok(rc
==D3D_OK
, "SetLight returned: %x\n", rc
);
360 memset(&mat
, 0, sizeof(mat
));
361 rc
= IDirect3DDevice7_SetMaterial(lpD3DDevice
, &mat
);
362 ok(rc
== D3D_OK
, "IDirect3DDevice7_SetMaterial returned: %x\n", rc
);
364 U4(mat
).power
= 129.0;
365 rc
= IDirect3DDevice7_SetMaterial(lpD3DDevice
, &mat
);
366 ok(rc
== D3D_OK
, "IDirect3DDevice7_SetMaterial(power = 129.0) returned: %x\n", rc
);
367 memset(&mat
, 0, sizeof(mat
));
368 rc
= IDirect3DDevice7_GetMaterial(lpD3DDevice
, &mat
);
369 ok(rc
== D3D_OK
, "IDirect3DDevice7_GetMaterial returned: %x\n", rc
);
370 ok(U4(mat
).power
== 129, "Returned power is %f\n", U4(mat
).power
);
372 U4(mat
).power
= -1.0;
373 rc
= IDirect3DDevice7_SetMaterial(lpD3DDevice
, &mat
);
374 ok(rc
== D3D_OK
, "IDirect3DDevice7_SetMaterial(power = -1.0) returned: %x\n", rc
);
375 memset(&mat
, 0, sizeof(mat
));
376 rc
= IDirect3DDevice7_GetMaterial(lpD3DDevice
, &mat
);
377 ok(rc
== D3D_OK
, "IDirect3DDevice7_GetMaterial returned: %x\n", rc
);
378 ok(U4(mat
).power
== -1, "Returned power is %f\n", U4(mat
).power
);
380 memset(&caps
, 0, sizeof(caps
));
381 rc
= IDirect3DDevice7_GetCaps(lpD3DDevice
, &caps
);
382 ok(rc
== D3D_OK
, "IDirect3DDevice7_GetCaps failed with %x\n", rc
);
384 if ( caps
.dwMaxActiveLights
== (DWORD
) -1) {
385 /* Some cards without T&L Support return -1 (Examples: Voodoo Banshee, RivaTNT / NV4) */
386 skip("T&L not supported\n");
390 for(i
= 1; i
<= caps
.dwMaxActiveLights
; i
++) {
391 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, i
, TRUE
);
392 ok(rc
== D3D_OK
, "Enabling light %u failed with %x\n", i
, rc
);
393 rc
= IDirect3DDevice7_GetLightEnable(lpD3DDevice
, i
, &enabled
);
394 ok(rc
== D3D_OK
, "GetLightEnable on light %u failed with %x\n", i
, rc
);
395 ok(enabled
, "Light %d is %s\n", i
, enabled
? "enabled" : "disabled");
398 /* TODO: Test the rendering results in this situation */
399 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, i
+ 1, TRUE
);
400 ok(rc
== D3D_OK
, "Enabling one light more than supported returned %x\n", rc
);
401 rc
= IDirect3DDevice7_GetLightEnable(lpD3DDevice
, i
+ 1, &enabled
);
402 ok(rc
== D3D_OK
, "GetLightEnable on light %u failed with %x\n", i
+ 1, rc
);
403 ok(enabled
, "Light %d is %s\n", i
+ 1, enabled
? "enabled" : "disabled");
404 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, i
+ 1, FALSE
);
405 ok(rc
== D3D_OK
, "Disabling the additional returned %x\n", rc
);
407 for(i
= 1; i
<= caps
.dwMaxActiveLights
; i
++) {
408 rc
= IDirect3DDevice7_LightEnable(lpD3DDevice
, i
, FALSE
);
409 ok(rc
== D3D_OK
, "Disabling light %u failed with %x\n", i
, rc
);
413 static void StateTest( void )
417 /* The msdn says its undocumented, does it return an error too? */
418 rc
= IDirect3DDevice7_SetRenderState(lpD3DDevice
, D3DRENDERSTATE_ZVISIBLE
, TRUE
);
419 ok(rc
== D3D_OK
, "IDirect3DDevice7_SetRenderState(D3DRENDERSTATE_ZVISIBLE, TRUE) returned %08x\n", rc
);
420 rc
= IDirect3DDevice7_SetRenderState(lpD3DDevice
, D3DRENDERSTATE_ZVISIBLE
, FALSE
);
421 ok(rc
== D3D_OK
, "IDirect3DDevice7_SetRenderState(D3DRENDERSTATE_ZVISIBLE, FALSE) returned %08x\n", rc
);
425 static void SceneTest(void)
429 /* Test an EndScene without BeginScene. Should return an error */
430 hr
= IDirect3DDevice7_EndScene(lpD3DDevice
);
431 ok(hr
== D3DERR_SCENE_NOT_IN_SCENE
, "IDirect3DDevice7_EndScene returned %08x\n", hr
);
433 /* Test a normal BeginScene / EndScene pair, this should work */
434 hr
= IDirect3DDevice7_BeginScene(lpD3DDevice
);
435 ok(hr
== D3D_OK
, "IDirect3DDevice7_BeginScene failed with %08x\n", hr
);
438 hr
= IDirect3DDevice7_EndScene(lpD3DDevice
);
439 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndScene failed with %08x\n", hr
);
445 memset(&fx
, 0, sizeof(fx
));
446 fx
.dwSize
= sizeof(fx
);
448 hr
= IDirectDrawSurface7_Blt(lpDDSdepth
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
, &fx
);
449 ok(hr
== D3D_OK
, "Depthfill failed outside a BeginScene / EndScene pair, hr 0x%08x\n", hr
);
451 hr
= IDirect3DDevice7_BeginScene(lpD3DDevice
);
452 ok(hr
== D3D_OK
, "IDirect3DDevice7_BeginScene failed with %08x\n", hr
);
455 hr
= IDirectDrawSurface7_Blt(lpDDSdepth
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
, &fx
);
456 ok(hr
== D3D_OK
|| broken(hr
== E_FAIL
),
457 "Depthfill failed in a BeginScene / EndScene pair, hr 0x%08x\n", hr
);
458 hr
= IDirect3DDevice7_EndScene(lpD3DDevice
);
459 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndScene failed with %08x\n", hr
);
464 skip("Depth stencil creation failed at startup, skipping depthfill test\n");
467 /* Test another EndScene without having begun a new scene. Should return an error */
468 hr
= IDirect3DDevice7_EndScene(lpD3DDevice
);
469 ok(hr
== D3DERR_SCENE_NOT_IN_SCENE
, "IDirect3DDevice7_EndScene returned %08x\n", hr
);
471 /* Two nested BeginScene and EndScene calls */
472 hr
= IDirect3DDevice7_BeginScene(lpD3DDevice
);
473 ok(hr
== D3D_OK
, "IDirect3DDevice7_BeginScene failed with %08x\n", hr
);
474 hr
= IDirect3DDevice7_BeginScene(lpD3DDevice
);
475 ok(hr
== D3DERR_SCENE_IN_SCENE
, "IDirect3DDevice7_BeginScene returned %08x\n", hr
);
476 hr
= IDirect3DDevice7_EndScene(lpD3DDevice
);
477 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndScene failed with %08x\n", hr
);
478 hr
= IDirect3DDevice7_EndScene(lpD3DDevice
);
479 ok(hr
== D3DERR_SCENE_NOT_IN_SCENE
, "IDirect3DDevice7_EndScene returned %08x\n", hr
);
481 /* TODO: Verify that blitting works in the same way as in d3d9 */
484 static void LimitTest(void)
486 IDirectDrawSurface7
*pTexture
= NULL
;
491 memset(&ddsd
, 0, sizeof(ddsd
));
492 ddsd
.dwSize
= sizeof(ddsd
);
493 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
494 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
497 hr
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &pTexture
, NULL
);
498 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
499 if(!pTexture
) return;
501 for(i
= 0; i
< 8; i
++) {
502 hr
= IDirect3DDevice7_SetTexture(lpD3DDevice
, i
, pTexture
);
503 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture for sampler %d failed with %08x\n", i
, hr
);
504 hr
= IDirect3DDevice7_SetTexture(lpD3DDevice
, i
, NULL
);
505 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture for sampler %d failed with %08x\n", i
, hr
);
506 hr
= IDirect3DDevice7_SetTextureStageState(lpD3DDevice
, i
, D3DTSS_COLOROP
, D3DTOP_ADD
);
507 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %08x\n", i
, hr
);
510 IDirectDrawSurface7_Release(pTexture
);
513 static HRESULT WINAPI
enumDevicesCallback(GUID
*Guid
,LPSTR DeviceDescription
,LPSTR DeviceName
, D3DDEVICEDESC
*hal
, D3DDEVICEDESC
*hel
, VOID
*ctx
)
515 UINT ver
= *((UINT
*) ctx
);
516 if(IsEqualGUID(&IID_IDirect3DRGBDevice
, Guid
))
518 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
519 "RGB Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
520 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
521 "RGB Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
522 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
523 "RGB Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
524 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
525 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
527 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
528 "RGB Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
529 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
530 "RGB Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
531 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
532 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
533 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
534 "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
536 ok(hal
->dcmColorModel
== 0, "RGB Device %u hal caps has colormodel %u\n", ver
, hal
->dcmColorModel
);
537 ok(hel
->dcmColorModel
== D3DCOLOR_RGB
, "RGB Device %u hel caps has colormodel %u\n", ver
, hel
->dcmColorModel
);
539 else if(IsEqualGUID(&IID_IDirect3DHALDevice
, Guid
))
541 trace("HAL Device %d\n", ver
);
542 ok(hal
->dcmColorModel
== D3DCOLOR_RGB
, "HAL Device %u hal caps has colormodel %u\n", ver
, hel
->dcmColorModel
);
543 ok(hel
->dcmColorModel
== 0, "HAL Device %u hel caps has colormodel %u\n", ver
, hel
->dcmColorModel
);
545 else if(IsEqualGUID(&IID_IDirect3DRefDevice
, Guid
))
547 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
548 "REF Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
549 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
550 "REF Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
551 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
552 "REF Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
553 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
554 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
556 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
557 "REF Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
558 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
559 "REF Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
560 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
561 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
562 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
563 "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
565 else if(IsEqualGUID(&IID_IDirect3DRampDevice
, Guid
))
567 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
568 "Ramp Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
569 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
570 "Ramp Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
571 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
572 "Ramp Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
573 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
574 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
576 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
577 "Ramp Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
578 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
579 "Ramp Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
580 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
581 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
582 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
583 "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
585 ok(hal
->dcmColorModel
== 0, "Ramp Device %u hal caps has colormodel %u\n", ver
, hal
->dcmColorModel
);
586 ok(hel
->dcmColorModel
== D3DCOLOR_MONO
, "Ramp Device %u hel caps has colormodel %u\n",
587 ver
, hel
->dcmColorModel
);
589 else if(IsEqualGUID(&IID_IDirect3DMMXDevice
, Guid
))
591 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
592 "MMX Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
593 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) == 0,
594 "MMX Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver
);
595 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
596 "MMX Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
597 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
,
598 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver
);
600 ok((hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
601 "MMX Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
602 ok((hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
) == 0,
603 "MMX Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
604 ok(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
605 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
606 ok(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_PERSPECTIVE
,
607 "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver
);
609 ok(hal
->dcmColorModel
== 0, "MMX Device %u hal caps has colormodel %u\n", ver
, hal
->dcmColorModel
);
610 ok(hel
->dcmColorModel
== D3DCOLOR_RGB
, "MMX Device %u hel caps has colormodel %u\n", ver
, hel
->dcmColorModel
);
614 ok(FALSE
, "Unexpected device enumerated: \"%s\" \"%s\"\n", DeviceDescription
, DeviceName
);
615 if(hal
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) trace("hal line has pow2 set\n");
616 else trace("hal line does NOT have pow2 set\n");
617 if(hal
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) trace("hal tri has pow2 set\n");
618 else trace("hal tri does NOT have pow2 set\n");
619 if(hel
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) trace("hel line has pow2 set\n");
620 else trace("hel line does NOT have pow2 set\n");
621 if(hel
->dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
) trace("hel tri has pow2 set\n");
622 else trace("hel tri does NOT have pow2 set\n");
627 static HRESULT WINAPI
enumDevicesCallbackTest7(char *DeviceDescription
, char *DeviceName
,
628 D3DDEVICEDESC7
*lpdd7
, void *Context
)
630 D3D7ETest
*d3d7et
= Context
;
631 if(IsEqualGUID(&lpdd7
->deviceGUID
, &IID_IDirect3DRGBDevice
))
633 else if(IsEqualGUID(&lpdd7
->deviceGUID
, &IID_IDirect3DHALDevice
))
635 else if(IsEqualGUID(&lpdd7
->deviceGUID
, &IID_IDirect3DTnLHalDevice
))
645 static HRESULT WINAPI
enumDevicesCancelTest7(char *DeviceDescription
, char *DeviceName
,
646 D3DDEVICEDESC7
*lpdd7
, void *Context
)
648 D3D7ECancelTest
*d3d7et
= Context
;
652 return d3d7et
->desired_ret
;
655 static HRESULT WINAPI
enumDevicesLifetimeTest7(char *DeviceDescription
, char *DeviceName
,
656 D3DDEVICEDESC7
*lpdd7
, void *Context
)
658 D3D7ELifetimeTest
*ctx
= Context
;
660 if (ctx
->count
== MAX_ENUMERATION_COUNT
)
662 ok(0, "Enumerated too many devices for context in callback\n");
663 return DDENUMRET_CANCEL
;
666 ctx
->callback_description_ptrs
[ctx
->count
] = DeviceDescription
;
667 strcpy(ctx
->callback_description_strings
[ctx
->count
], DeviceDescription
);
668 ctx
->callback_name_ptrs
[ctx
->count
] = DeviceName
;
669 strcpy(ctx
->callback_name_strings
[ctx
->count
], DeviceName
);
675 /* Check the deviceGUID of devices enumerated by
676 IDirect3D7_EnumDevices. */
677 static void D3D7EnumTest(void)
681 D3D7ECancelTest d3d7_cancel_test
;
683 hr
= IDirect3D7_EnumDevices(lpD3D
, NULL
, NULL
);
684 ok(hr
== DDERR_INVALIDPARAMS
, "IDirect3D7_EnumDevices returned 0x%08x\n", hr
);
686 memset(&d3d7et
, 0, sizeof(d3d7et
));
687 hr
= IDirect3D7_EnumDevices(lpD3D
, enumDevicesCallbackTest7
, &d3d7et
);
688 ok(hr
== D3D_OK
, "IDirect3D7_EnumDevices returned 0x%08x\n", hr
);
690 /* A couple of games (Delta Force LW and TFD) rely on this behaviour */
691 ok(d3d7et
.tnlhal
< d3d7et
.total
, "TnLHal device enumerated as only device.\n");
693 /* We make two additional assumptions. */
694 ok(d3d7et
.rgb
, "No RGB Device enumerated.\n");
697 ok(d3d7et
.hal
, "TnLHal device enumerated, but no Hal device found.\n");
699 d3d7_cancel_test
.desired_ret
= DDENUMRET_CANCEL
;
700 d3d7_cancel_test
.total
= 0;
701 hr
= IDirect3D7_EnumDevices(lpD3D
, enumDevicesCancelTest7
, &d3d7_cancel_test
);
702 ok(hr
== D3D_OK
, "IDirect3D7_EnumDevices returned 0x%08x\n", hr
);
704 ok(d3d7_cancel_test
.total
== 1, "Enumerated a total of %u devices\n",
705 d3d7_cancel_test
.total
);
707 /* An enumeration callback can return any value besides DDENUMRET_OK to stop enumeration. */
708 d3d7_cancel_test
.desired_ret
= E_INVALIDARG
;
709 d3d7_cancel_test
.total
= 0;
710 hr
= IDirect3D7_EnumDevices(lpD3D
, enumDevicesCancelTest7
, &d3d7_cancel_test
);
711 ok(hr
== D3D_OK
, "IDirect3D7_EnumDevices returned 0x%08x\n", hr
);
713 ok(d3d7_cancel_test
.total
== 1, "Enumerated a total of %u devices\n",
714 d3d7_cancel_test
.total
);
717 static void D3D7EnumLifetimeTest(void)
719 D3D7ELifetimeTest ctx
, ctx2
;
724 hr
= IDirect3D7_EnumDevices(lpD3D
, enumDevicesLifetimeTest7
, &ctx
);
725 ok(hr
== D3D_OK
, "IDirect3D7_EnumDevices returned 0x%08x\n", hr
);
727 /* The enumeration strings remain valid even after IDirect3D7_EnumDevices finishes. */
728 for (i
= 0; i
< ctx
.count
; i
++)
730 ok(!strcmp(ctx
.callback_description_ptrs
[i
], ctx
.callback_description_strings
[i
]),
731 "Got '%s' and '%s'\n", ctx
.callback_description_ptrs
[i
], ctx
.callback_description_strings
[i
]);
732 ok(!strcmp(ctx
.callback_name_ptrs
[i
], ctx
.callback_name_strings
[i
]),
733 "Got '%s' and '%s'\n", ctx
.callback_name_ptrs
[i
], ctx
.callback_name_strings
[i
]);
737 hr
= IDirect3D7_EnumDevices(lpD3D
, enumDevicesLifetimeTest7
, &ctx2
);
738 ok(hr
== D3D_OK
, "IDirect3D7_EnumDevices returned 0x%08x\n", hr
);
740 /* The enumeration strings and their order are identical across enumerations. */
741 ok(ctx
.count
== ctx2
.count
, "Enumerated %u and %u devices\n", ctx
.count
, ctx2
.count
);
742 if (ctx
.count
== ctx2
.count
)
744 for (i
= 0; i
< ctx
.count
; i
++)
746 ok(ctx
.callback_description_ptrs
[i
] == ctx2
.callback_description_ptrs
[i
],
747 "Unequal description pointers %p and %p\n", ctx
.callback_description_ptrs
[i
], ctx2
.callback_description_ptrs
[i
]);
748 ok(!strcmp(ctx
.callback_description_strings
[i
], ctx2
.callback_description_strings
[i
]),
749 "Got '%s' and '%s'\n", ctx
.callback_description_strings
[i
], ctx2
.callback_description_strings
[i
]);
750 ok(ctx
.callback_name_ptrs
[i
] == ctx2
.callback_name_ptrs
[i
],
751 "Unequal name pointers %p and %p\n", ctx
.callback_name_ptrs
[i
], ctx2
.callback_name_ptrs
[i
]);
752 ok(!strcmp(ctx
.callback_name_strings
[i
], ctx2
.callback_name_strings
[i
]),
753 "Got '%s' and '%s'\n", ctx
.callback_name_strings
[i
], ctx2
.callback_name_strings
[i
]);
757 /* Try altering the contents of the enumeration strings. */
758 for (i
= 0; i
< ctx2
.count
; i
++)
760 strcpy(ctx2
.callback_description_ptrs
[i
], "Fake Description");
761 strcpy(ctx2
.callback_name_ptrs
[i
], "Fake Device");
765 hr
= IDirect3D7_EnumDevices(lpD3D
, enumDevicesLifetimeTest7
, &ctx2
);
766 ok(hr
== D3D_OK
, "IDirect3D7_EnumDevices returned 0x%08x\n", hr
);
768 /* The original contents of the enumeration strings are not restored. */
769 ok(ctx
.count
== ctx2
.count
, "Enumerated %u and %u devices\n", ctx
.count
, ctx2
.count
);
770 if (ctx
.count
== ctx2
.count
)
772 for (i
= 0; i
< ctx
.count
; i
++)
774 ok(ctx
.callback_description_ptrs
[i
] == ctx2
.callback_description_ptrs
[i
],
775 "Unequal description pointers %p and %p\n", ctx
.callback_description_ptrs
[i
], ctx2
.callback_description_ptrs
[i
]);
776 ok(strcmp(ctx
.callback_description_strings
[i
], ctx2
.callback_description_strings
[i
]) != 0,
777 "Got '%s' and '%s'\n", ctx
.callback_description_strings
[i
], ctx2
.callback_description_strings
[i
]);
778 ok(ctx
.callback_name_ptrs
[i
] == ctx2
.callback_name_ptrs
[i
],
779 "Unequal name pointers %p and %p\n", ctx
.callback_name_ptrs
[i
], ctx2
.callback_name_ptrs
[i
]);
780 ok(strcmp(ctx
.callback_name_strings
[i
], ctx2
.callback_name_strings
[i
]) != 0,
781 "Got '%s' and '%s'\n", ctx
.callback_name_strings
[i
], ctx2
.callback_name_strings
[i
]);
786 static void CapsTest(void)
794 hr
= DirectDrawCreate(NULL
, &dd1
, NULL
);
795 ok(hr
== DD_OK
, "Cannot create a DirectDraw 1 interface, hr = %08x\n", hr
);
796 hr
= IDirectDraw_QueryInterface(dd1
, &IID_IDirect3D3
, (void **) &d3d3
);
797 ok(hr
== D3D_OK
, "IDirectDraw_QueryInterface returned %08x\n", hr
);
799 hr
= IDirect3D3_EnumDevices(d3d3
, NULL
, NULL
);
800 ok(hr
== DDERR_INVALIDPARAMS
, "IDirect3D3_EnumDevices returned 0x%08x\n", hr
);
803 IDirect3D3_EnumDevices(d3d3
, enumDevicesCallback
, &ver
);
805 IDirect3D3_Release(d3d3
);
806 IDirectDraw_Release(dd1
);
808 hr
= DirectDrawCreate(NULL
, &dd1
, NULL
);
809 ok(hr
== DD_OK
, "Cannot create a DirectDraw 1 interface, hr = %08x\n", hr
);
810 hr
= IDirectDraw_QueryInterface(dd1
, &IID_IDirect3D2
, (void **) &d3d2
);
811 ok(hr
== D3D_OK
, "IDirectDraw_QueryInterface returned %08x\n", hr
);
813 hr
= IDirect3D2_EnumDevices(d3d2
, NULL
, NULL
);
814 ok(hr
== DDERR_INVALIDPARAMS
, "IDirect3D2_EnumDevices returned 0x%08x\n", hr
);
817 IDirect3D2_EnumDevices(d3d2
, enumDevicesCallback
, &ver
);
819 IDirect3D2_Release(d3d2
);
820 IDirectDraw_Release(dd1
);
830 static BOOL
D3D1_createObjects(void)
834 D3DEXECUTEBUFFERDESC desc
;
837 /* An IDirect3DDevice cannot be queryInterfaced from an IDirect3DDevice7 on windows */
838 hr
= DirectDrawCreate(NULL
, &DirectDraw1
, NULL
);
839 ok(hr
==DD_OK
|| hr
==DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreate returned: %x\n", hr
);
844 hr
= IDirectDraw_SetCooperativeLevel(DirectDraw1
, NULL
, DDSCL_NORMAL
);
845 ok(hr
==DD_OK
, "SetCooperativeLevel returned: %x\n", hr
);
847 hr
= IDirectDraw_QueryInterface(DirectDraw1
, &IID_IDirect3D
, (void**) &Direct3D1
);
848 if (hr
== E_NOINTERFACE
) return FALSE
;
849 ok(hr
==DD_OK
, "QueryInterface returned: %x\n", hr
);
854 memset(&ddsd
, 0, sizeof(ddsd
));
855 ddsd
.dwSize
= sizeof(ddsd
);
856 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
857 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
860 IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &Surface1
, NULL
);
862 skip("DDSCAPS_3DDEVICE surface not available\n");
866 hr
= IDirectDrawSurface_QueryInterface(Surface1
, &IID_IDirect3DRGBDevice
, (void **) &Direct3DDevice1
);
867 ok(hr
==D3D_OK
|| hr
==DDERR_NOPALETTEATTACHED
|| hr
==E_OUTOFMEMORY
, "CreateDevice returned: %x\n", hr
);
868 if(!Direct3DDevice1
) {
872 memset(&desc
, 0, sizeof(desc
));
873 desc
.dwSize
= sizeof(desc
);
874 desc
.dwFlags
= D3DDEB_BUFSIZE
| D3DDEB_CAPS
;
875 desc
.dwCaps
= D3DDEBCAPS_VIDEOMEMORY
;
876 desc
.dwBufferSize
= 128;
878 hr
= IDirect3DDevice_CreateExecuteBuffer(Direct3DDevice1
, &desc
, &ExecuteBuffer
, NULL
);
879 ok(hr
== D3D_OK
, "IDirect3DDevice_CreateExecuteBuffer failed: %08x\n", hr
);
884 hr
= IDirect3D_CreateViewport(Direct3D1
, &Viewport
, NULL
);
885 ok(hr
== D3D_OK
, "IDirect3D_CreateViewport failed: %08x\n", hr
);
890 hr
= IDirect3DViewport_Initialize(Viewport
, Direct3D1
);
891 ok(hr
== DDERR_ALREADYINITIALIZED
, "IDirect3DViewport_Initialize returned %08x\n", hr
);
893 hr
= IDirect3DDevice_AddViewport(Direct3DDevice1
, Viewport
);
894 ok(hr
== D3D_OK
, "IDirect3DDevice_AddViewport returned %08x\n", hr
);
895 vp_data
.dwSize
= sizeof(vp_data
);
898 vp_data
.dwWidth
= 256;
899 vp_data
.dwHeight
= 256;
900 vp_data
.dvScaleX
= 1;
901 vp_data
.dvScaleY
= 1;
902 vp_data
.dvMaxX
= 256;
903 vp_data
.dvMaxY
= 256;
906 hr
= IDirect3DViewport_SetViewport(Viewport
, &vp_data
);
907 ok(hr
== D3D_OK
, "IDirect3DViewport_SetViewport returned %08x\n", hr
);
909 hr
= IDirect3D_CreateLight(Direct3D1
, &Light
, NULL
);
910 ok(hr
== D3D_OK
, "IDirect3D_CreateLight failed: %08x\n", hr
);
917 static void D3D1_releaseObjects(void)
919 if (Light
) IDirect3DLight_Release(Light
);
920 if (Viewport
) IDirect3DViewport_Release(Viewport
);
921 if (ExecuteBuffer
) IDirect3DExecuteBuffer_Release(ExecuteBuffer
);
922 if (Direct3DDevice1
) IDirect3DDevice_Release(Direct3DDevice1
);
923 if (Surface1
) IDirectDrawSurface_Release(Surface1
);
924 if (Direct3D1
) IDirect3D_Release(Direct3D1
);
925 if (DirectDraw1
) IDirectDraw_Release(DirectDraw1
);
928 static void ViewportTest(void)
931 IDirect3DViewport2
*Viewport2
;
932 IDirect3DViewport3
*Viewport3
;
933 D3DVIEWPORT vp1_data
, ret_vp1_data
;
934 D3DVIEWPORT2 vp2_data
, ret_vp2_data
;
937 *(DWORD
*)&infinity
= 0x7f800000;
939 hr
= IDirect3DDevice_AddViewport(Direct3DDevice1
, Viewport
);
940 ok(hr
== D3D_OK
, "IDirect3DDevice_AddViewport returned %08x\n", hr
);
942 hr
= IDirect3DViewport_QueryInterface(Viewport
, &IID_IDirect3DViewport2
, (void**) &Viewport2
);
943 ok(hr
==D3D_OK
, "QueryInterface returned: %x\n", hr
);
944 ok(Viewport2
== (IDirect3DViewport2
*)Viewport
, "IDirect3DViewport2 iface different from IDirect3DViewport\n");
946 hr
= IDirect3DViewport_QueryInterface(Viewport
, &IID_IDirect3DViewport3
, (void**) &Viewport3
);
947 ok(hr
==D3D_OK
, "QueryInterface returned: %x\n", hr
);
948 ok(Viewport3
== (IDirect3DViewport3
*)Viewport
, "IDirect3DViewport3 iface different from IDirect3DViewport\n");
949 IDirect3DViewport3_Release(Viewport3
);
951 vp1_data
.dwSize
= sizeof(vp1_data
);
954 vp1_data
.dwWidth
= 256;
955 vp1_data
.dwHeight
= 257;
958 vp1_data
.dvScaleX
= 0;
959 vp1_data
.dvScaleY
= 0;
960 vp1_data
.dvMinZ
= 0.25;
961 vp1_data
.dvMaxZ
= 0.75;
963 vp2_data
.dwSize
= sizeof(vp2_data
);
966 vp2_data
.dwWidth
= 258;
967 vp2_data
.dwHeight
= 259;
968 vp2_data
.dvClipX
= 0;
969 vp2_data
.dvClipY
= 0;
970 vp2_data
.dvClipWidth
= 0;
971 vp2_data
.dvClipHeight
= 0;
972 vp2_data
.dvMinZ
= 0.1;
973 vp2_data
.dvMaxZ
= 0.9;
975 hr
= IDirect3DViewport2_SetViewport(Viewport2
, &vp1_data
);
976 ok(hr
== D3D_OK
, "IDirect3DViewport2_SetViewport returned %08x\n", hr
);
978 memset(&ret_vp1_data
, 0xff, sizeof(ret_vp1_data
));
979 ret_vp1_data
.dwSize
= sizeof(vp1_data
);
981 hr
= IDirect3DViewport2_GetViewport(Viewport2
, &ret_vp1_data
);
982 ok(hr
== D3D_OK
, "IDirect3DViewport2_GetViewport returned %08x\n", hr
);
984 ok(ret_vp1_data
.dwX
== vp1_data
.dwX
, "dwX is %u, expected %u\n", ret_vp1_data
.dwX
, vp1_data
.dwX
);
985 ok(ret_vp1_data
.dwY
== vp1_data
.dwY
, "dwY is %u, expected %u\n", ret_vp1_data
.dwY
, vp1_data
.dwY
);
986 ok(ret_vp1_data
.dwWidth
== vp1_data
.dwWidth
, "dwWidth is %u, expected %u\n", ret_vp1_data
.dwWidth
, vp1_data
.dwWidth
);
987 ok(ret_vp1_data
.dwHeight
== vp1_data
.dwHeight
, "dwHeight is %u, expected %u\n", ret_vp1_data
.dwHeight
, vp1_data
.dwHeight
);
988 ok(ret_vp1_data
.dvMaxX
== vp1_data
.dvMaxX
, "dvMaxX is %f, expected %f\n", ret_vp1_data
.dvMaxX
, vp1_data
.dvMaxX
);
989 ok(ret_vp1_data
.dvMaxY
== vp1_data
.dvMaxY
, "dvMaxY is %f, expected %f\n", ret_vp1_data
.dvMaxY
, vp1_data
.dvMaxY
);
990 todo_wine
ok(ret_vp1_data
.dvScaleX
== infinity
, "dvScaleX is %f, expected %f\n", ret_vp1_data
.dvScaleX
, infinity
);
991 todo_wine
ok(ret_vp1_data
.dvScaleY
== infinity
, "dvScaleY is %f, expected %f\n", ret_vp1_data
.dvScaleY
, infinity
);
992 ok(ret_vp1_data
.dvMinZ
== 0.0, "dvMinZ is %f, expected 0.0\n", ret_vp1_data
.dvMinZ
);
993 ok(ret_vp1_data
.dvMaxZ
== 1.0, "dvMaxZ is %f, expected 1.0\n", ret_vp1_data
.dvMaxZ
);
995 hr
= IDirect3DViewport2_SetViewport2(Viewport2
, &vp2_data
);
996 ok(hr
== D3D_OK
, "IDirect3DViewport2_SetViewport2 returned %08x\n", hr
);
998 memset(&ret_vp2_data
, 0xff, sizeof(ret_vp2_data
));
999 ret_vp2_data
.dwSize
= sizeof(vp2_data
);
1001 hr
= IDirect3DViewport2_GetViewport2(Viewport2
, &ret_vp2_data
);
1002 ok(hr
== D3D_OK
, "IDirect3DViewport2_GetViewport2 returned %08x\n", hr
);
1004 ok(ret_vp2_data
.dwX
== vp2_data
.dwX
, "dwX is %u, expected %u\n", ret_vp2_data
.dwX
, vp2_data
.dwX
);
1005 ok(ret_vp2_data
.dwY
== vp2_data
.dwY
, "dwY is %u, expected %u\n", ret_vp2_data
.dwY
, vp2_data
.dwY
);
1006 ok(ret_vp2_data
.dwWidth
== vp2_data
.dwWidth
, "dwWidth is %u, expected %u\n", ret_vp2_data
.dwWidth
, vp2_data
.dwWidth
);
1007 ok(ret_vp2_data
.dwHeight
== vp2_data
.dwHeight
, "dwHeight is %u, expected %u\n", ret_vp2_data
.dwHeight
, vp2_data
.dwHeight
);
1008 ok(ret_vp2_data
.dvClipX
== vp2_data
.dvClipX
, "dvClipX is %f, expected %f\n", ret_vp2_data
.dvClipX
, vp2_data
.dvClipX
);
1009 ok(ret_vp2_data
.dvClipY
== vp2_data
.dvClipY
, "dvClipY is %f, expected %f\n", ret_vp2_data
.dvClipY
, vp2_data
.dvClipY
);
1010 ok(ret_vp2_data
.dvClipWidth
== vp2_data
.dvClipWidth
, "dvClipWidth is %f, expected %f\n",
1011 ret_vp2_data
.dvClipWidth
, vp2_data
.dvClipWidth
);
1012 ok(ret_vp2_data
.dvClipHeight
== vp2_data
.dvClipHeight
, "dvClipHeight is %f, expected %f\n",
1013 ret_vp2_data
.dvClipHeight
, vp2_data
.dvClipHeight
);
1014 ok(ret_vp2_data
.dvMinZ
== vp2_data
.dvMinZ
, "dvMinZ is %f, expected %f\n", ret_vp2_data
.dvMinZ
, vp2_data
.dvMinZ
);
1015 ok(ret_vp2_data
.dvMaxZ
== vp2_data
.dvMaxZ
, "dvMaxZ is %f, expected %f\n", ret_vp2_data
.dvMaxZ
, vp2_data
.dvMaxZ
);
1017 memset(&ret_vp1_data
, 0xff, sizeof(ret_vp1_data
));
1018 ret_vp1_data
.dwSize
= sizeof(vp1_data
);
1020 hr
= IDirect3DViewport2_GetViewport(Viewport2
, &ret_vp1_data
);
1021 ok(hr
== D3D_OK
, "IDirect3DViewport2_GetViewport returned %08x\n", hr
);
1023 ok(ret_vp1_data
.dwX
== vp2_data
.dwX
, "dwX is %u, expected %u\n", ret_vp1_data
.dwX
, vp2_data
.dwX
);
1024 ok(ret_vp1_data
.dwY
== vp2_data
.dwY
, "dwY is %u, expected %u\n", ret_vp1_data
.dwY
, vp2_data
.dwY
);
1025 ok(ret_vp1_data
.dwWidth
== vp2_data
.dwWidth
, "dwWidth is %u, expected %u\n", ret_vp1_data
.dwWidth
, vp2_data
.dwWidth
);
1026 ok(ret_vp1_data
.dwHeight
== vp2_data
.dwHeight
, "dwHeight is %u, expected %u\n", ret_vp1_data
.dwHeight
, vp2_data
.dwHeight
);
1027 ok(ret_vp1_data
.dvMaxX
== vp1_data
.dvMaxX
, "dvMaxX is %f, expected %f\n", ret_vp1_data
.dvMaxX
, vp1_data
.dvMaxX
);
1028 ok(ret_vp1_data
.dvMaxY
== vp1_data
.dvMaxY
, "dvMaxY is %f, expected %f\n", ret_vp1_data
.dvMaxY
, vp1_data
.dvMaxY
);
1029 todo_wine
ok(ret_vp1_data
.dvScaleX
== infinity
, "dvScaleX is %f, expected %f\n", ret_vp1_data
.dvScaleX
, infinity
);
1030 todo_wine
ok(ret_vp1_data
.dvScaleY
== infinity
, "dvScaleY is %f, expected %f\n", ret_vp1_data
.dvScaleY
, infinity
);
1031 todo_wine
ok(ret_vp1_data
.dvMinZ
== 0.0, "dvMinZ is %f, expected 0.0\n", ret_vp1_data
.dvMinZ
);
1032 todo_wine
ok(ret_vp1_data
.dvMaxZ
== 1.0, "dvMaxZ is %f, expected 1.0\n", ret_vp1_data
.dvMaxZ
);
1034 hr
= IDirect3DViewport2_SetViewport2(Viewport2
, &vp2_data
);
1035 ok(hr
== D3D_OK
, "IDirect3DViewport2_SetViewport2 returned %08x\n", hr
);
1037 memset(&ret_vp2_data
, 0xff, sizeof(ret_vp2_data
));
1038 ret_vp2_data
.dwSize
= sizeof(vp2_data
);
1040 hr
= IDirect3DViewport2_GetViewport2(Viewport2
, &ret_vp2_data
);
1041 ok(hr
== D3D_OK
, "IDirect3DViewport2_GetViewport2 returned %08x\n", hr
);
1043 ok(ret_vp2_data
.dwX
== vp2_data
.dwX
, "dwX is %u, expected %u\n", ret_vp2_data
.dwX
, vp2_data
.dwX
);
1044 ok(ret_vp2_data
.dwY
== vp2_data
.dwY
, "dwY is %u, expected %u\n", ret_vp2_data
.dwY
, vp2_data
.dwY
);
1045 ok(ret_vp2_data
.dwWidth
== vp2_data
.dwWidth
, "dwWidth is %u, expected %u\n", ret_vp2_data
.dwWidth
, vp2_data
.dwWidth
);
1046 ok(ret_vp2_data
.dwHeight
== vp2_data
.dwHeight
, "dwHeight is %u, expected %u\n", ret_vp2_data
.dwHeight
, vp2_data
.dwHeight
);
1047 ok(ret_vp2_data
.dvClipX
== vp2_data
.dvClipX
, "dvClipX is %f, expected %f\n", ret_vp2_data
.dvClipX
, vp2_data
.dvClipX
);
1048 ok(ret_vp2_data
.dvClipY
== vp2_data
.dvClipY
, "dvClipY is %f, expected %f\n", ret_vp2_data
.dvClipY
, vp2_data
.dvClipY
);
1049 ok(ret_vp2_data
.dvClipWidth
== vp2_data
.dvClipWidth
, "dvClipWidth is %f, expected %f\n",
1050 ret_vp2_data
.dvClipWidth
, vp2_data
.dvClipWidth
);
1051 ok(ret_vp2_data
.dvClipHeight
== vp2_data
.dvClipHeight
, "dvClipHeight is %f, expected %f\n",
1052 ret_vp2_data
.dvClipHeight
, vp2_data
.dvClipHeight
);
1053 ok(ret_vp2_data
.dvMinZ
== vp2_data
.dvMinZ
, "dvMinZ is %f, expected %f\n", ret_vp2_data
.dvMinZ
, vp2_data
.dvMinZ
);
1054 ok(ret_vp2_data
.dvMaxZ
== vp2_data
.dvMaxZ
, "dvMaxZ is %f, expected %f\n", ret_vp2_data
.dvMaxZ
, vp2_data
.dvMaxZ
);
1056 hr
= IDirect3DViewport2_SetViewport(Viewport2
, &vp1_data
);
1057 ok(hr
== D3D_OK
, "IDirect3DViewport2_SetViewport returned %08x\n", hr
);
1059 memset(&ret_vp1_data
, 0xff, sizeof(ret_vp1_data
));
1060 ret_vp1_data
.dwSize
= sizeof(vp1_data
);
1062 hr
= IDirect3DViewport2_GetViewport(Viewport2
, &ret_vp1_data
);
1063 ok(hr
== D3D_OK
, "IDirect3DViewport2_GetViewport returned %08x\n", hr
);
1065 ok(ret_vp1_data
.dwX
== vp1_data
.dwX
, "dwX is %u, expected %u\n", ret_vp1_data
.dwX
, vp1_data
.dwX
);
1066 ok(ret_vp1_data
.dwY
== vp1_data
.dwY
, "dwY is %u, expected %u\n", ret_vp1_data
.dwY
, vp1_data
.dwY
);
1067 ok(ret_vp1_data
.dwWidth
== vp1_data
.dwWidth
, "dwWidth is %u, expected %u\n", ret_vp1_data
.dwWidth
, vp1_data
.dwWidth
);
1068 ok(ret_vp1_data
.dwHeight
== vp1_data
.dwHeight
, "dwHeight is %u, expected %u\n", ret_vp1_data
.dwHeight
, vp1_data
.dwHeight
);
1069 ok(ret_vp1_data
.dvMaxX
== vp1_data
.dvMaxX
, "dvMaxX is %f, expected %f\n", ret_vp1_data
.dvMaxX
, vp1_data
.dvMaxX
);
1070 ok(ret_vp1_data
.dvMaxY
== vp1_data
.dvMaxY
, "dvMaxY is %f, expected %f\n", ret_vp1_data
.dvMaxY
, vp1_data
.dvMaxY
);
1071 todo_wine
ok(ret_vp1_data
.dvScaleX
== infinity
, "dvScaleX is %f, expected %f\n", ret_vp1_data
.dvScaleX
, infinity
);
1072 todo_wine
ok(ret_vp1_data
.dvScaleY
== infinity
, "dvScaleY is %f, expected %f\n", ret_vp1_data
.dvScaleY
, infinity
);
1073 ok(ret_vp1_data
.dvMinZ
== 0.0, "dvMinZ is %f, expected 0.0\n", ret_vp1_data
.dvMinZ
);
1074 ok(ret_vp1_data
.dvMaxZ
== 1.0, "dvMaxZ is %f, expected 1.0\n", ret_vp1_data
.dvMaxZ
);
1076 memset(&ret_vp2_data
, 0xff, sizeof(ret_vp2_data
));
1077 ret_vp2_data
.dwSize
= sizeof(vp2_data
);
1079 hr
= IDirect3DViewport2_GetViewport2(Viewport2
, &ret_vp2_data
);
1080 ok(hr
== D3D_OK
, "IDirect3DViewport2_GetViewport2 returned %08x\n", hr
);
1082 ok(ret_vp2_data
.dwX
== vp1_data
.dwX
, "dwX is %u, expected %u\n", ret_vp2_data
.dwX
, vp1_data
.dwX
);
1083 ok(ret_vp2_data
.dwY
== vp1_data
.dwY
, "dwY is %u, expected %u\n", ret_vp2_data
.dwY
, vp1_data
.dwY
);
1084 ok(ret_vp2_data
.dwWidth
== vp1_data
.dwWidth
, "dwWidth is %u, expected %u\n", ret_vp2_data
.dwWidth
, vp1_data
.dwWidth
);
1085 ok(ret_vp2_data
.dwHeight
== vp1_data
.dwHeight
, "dwHeight is %u, expected %u\n", ret_vp2_data
.dwHeight
, vp1_data
.dwHeight
);
1086 ok(ret_vp2_data
.dvClipX
== vp2_data
.dvClipX
, "dvClipX is %f, expected %f\n", ret_vp2_data
.dvClipX
, vp2_data
.dvClipX
);
1087 ok(ret_vp2_data
.dvClipY
== vp2_data
.dvClipY
, "dvClipY is %f, expected %f\n", ret_vp2_data
.dvClipY
, vp2_data
.dvClipY
);
1088 ok(ret_vp2_data
.dvClipWidth
== vp2_data
.dvClipWidth
, "dvClipWidth is %f, expected %f\n",
1089 ret_vp2_data
.dvClipWidth
, vp2_data
.dvClipWidth
);
1090 ok(ret_vp2_data
.dvClipHeight
== vp2_data
.dvClipHeight
, "dvClipHeight is %f, expected %f\n",
1091 ret_vp2_data
.dvClipHeight
, vp2_data
.dvClipHeight
);
1092 ok(ret_vp2_data
.dvMinZ
== 0.0, "dvMinZ is %f, expected 0.0\n", ret_vp2_data
.dvMinZ
);
1093 ok(ret_vp2_data
.dvMaxZ
== 1.0, "dvMaxZ is %f, expected 1.0\n", ret_vp2_data
.dvMaxZ
);
1095 IDirect3DViewport2_Release(Viewport2
);
1097 hr
= IDirect3DDevice_DeleteViewport(Direct3DDevice1
, Viewport
);
1098 ok(hr
== D3D_OK
, "IDirect3DDevice_DeleteViewport returned %08x\n", hr
);
1101 #define SET_VP_DATA(vp_data) \
1102 vp_data.dwSize = sizeof(vp_data); \
1105 vp_data.dwWidth = 256; \
1106 vp_data.dwHeight = 256; \
1107 vp_data.dvMaxX = 256; \
1108 vp_data.dvMaxY = 256; \
1109 vp_data.dvScaleX = 5; \
1110 vp_data.dvScaleY = 5; \
1111 vp_data.dvMinZ = -25; \
1112 vp_data.dvMaxZ = 60;
1114 static void Direct3D1Test(void)
1117 D3DEXECUTEBUFFERDESC desc
;
1118 D3DVIEWPORT vp_data
;
1119 D3DINSTRUCTION
*instr
;
1121 IDirect3D
*Direct3D_alt
;
1122 IDirect3DLight
*d3dlight
;
1124 unsigned int idx
= 0;
1125 static struct v_in testverts
[] = {
1126 {0.0, 0.0, 0.0}, { 1.0, 1.0, 1.0}, {-1.0, -1.0, -1.0},
1127 {0.5, 0.5, 0.5}, {-0.5, -0.5, -0.5}, {-0.5, -0.5, 0.0},
1129 static struct v_in cliptest
[] = {
1130 {25.59, 25.59, 1.0}, {-25.59, -25.59, 0.0},
1131 {25.61, 25.61, 1.01}, {-25.61, -25.61, -0.01},
1133 static struct v_in offscreentest
[] = {
1136 struct v_out out
[sizeof(testverts
) / sizeof(testverts
[0])];
1137 D3DHVERTEX outH
[sizeof(testverts
) / sizeof(testverts
[0])];
1138 D3DTRANSFORMDATA transformdata
;
1141 /* Interface consistency check. */
1142 hr
= IDirect3DDevice_GetDirect3D(Direct3DDevice1
, &Direct3D_alt
);
1143 ok(hr
== D3D_OK
, "IDirect3DDevice_GetDirect3D failed: %08x\n", hr
);
1144 ok(Direct3D_alt
== Direct3D1
, "Direct3D1 struct pointer missmatch: %p != %p\n", Direct3D_alt
, Direct3D1
);
1145 IDirect3D_Release(Direct3D_alt
);
1147 memset(&desc
, 0, sizeof(desc
));
1148 desc
.dwSize
= sizeof(desc
);
1149 hr
= IDirect3DExecuteBuffer_Lock(ExecuteBuffer
, &desc
);
1150 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Lock failed: %08x\n", hr
);
1152 memset(desc
.lpData
, 0, 128);
1153 instr
= desc
.lpData
;
1154 instr
[idx
].bOpcode
= D3DOP_BRANCHFORWARD
;
1155 instr
[idx
].bSize
= sizeof(*branch
);
1156 instr
[idx
].wCount
= 1;
1158 branch
= (D3DBRANCH
*) &instr
[idx
];
1159 branch
->dwMask
= 0x0;
1160 branch
->dwValue
= 1;
1161 branch
->bNegate
= TRUE
;
1162 branch
->dwOffset
= 0;
1163 idx
+= (sizeof(*branch
) / sizeof(*instr
));
1164 instr
[idx
].bOpcode
= D3DOP_EXIT
;
1165 instr
[idx
].bSize
= 0;
1166 instr
[idx
].wCount
= 0;
1167 hr
= IDirect3DExecuteBuffer_Unlock(ExecuteBuffer
);
1168 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Unlock failed: %08x\n", hr
);
1170 hr
= IDirect3DDevice_Execute(Direct3DDevice1
, ExecuteBuffer
, Viewport
, D3DEXECUTE_CLIPPED
);
1171 ok(hr
== D3D_OK
, "IDirect3DDevice_Execute returned %08x\n", hr
);
1173 memset(&desc
, 0, sizeof(desc
));
1174 desc
.dwSize
= sizeof(desc
);
1176 hr
= IDirect3DExecuteBuffer_Lock(ExecuteBuffer
, &desc
);
1177 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Lock failed: %08x\n", hr
);
1179 memset(desc
.lpData
, 0, 128);
1180 instr
= desc
.lpData
;
1182 instr
[idx
].bOpcode
= D3DOP_BRANCHFORWARD
;
1183 instr
[idx
].bSize
= sizeof(*branch
);
1184 instr
[idx
].wCount
= 1;
1186 branch
= (D3DBRANCH
*) &instr
[idx
];
1187 branch
->dwMask
= 0x0;
1188 branch
->dwValue
= 1;
1189 branch
->bNegate
= TRUE
;
1190 branch
->dwOffset
= 64;
1191 instr
= (D3DINSTRUCTION
*)((char*)desc
.lpData
+ 64);
1192 instr
[0].bOpcode
= D3DOP_EXIT
;
1194 instr
[0].wCount
= 0;
1195 hr
= IDirect3DExecuteBuffer_Unlock(ExecuteBuffer
);
1196 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Unlock failed: %08x\n", hr
);
1198 hr
= IDirect3DDevice_Execute(Direct3DDevice1
, ExecuteBuffer
, Viewport
, D3DEXECUTE_CLIPPED
);
1199 ok(hr
== D3D_OK
, "IDirect3DDevice_Execute returned %08x\n", hr
);
1201 /* Test rendering 0 triangles */
1202 memset(&desc
, 0, sizeof(desc
));
1203 desc
.dwSize
= sizeof(desc
);
1205 hr
= IDirect3DExecuteBuffer_Lock(ExecuteBuffer
, &desc
);
1206 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Lock failed: %08x\n", hr
);
1208 memset(desc
.lpData
, 0, 128);
1209 instr
= desc
.lpData
;
1211 instr
->bOpcode
= D3DOP_TRIANGLE
;
1212 instr
->bSize
= sizeof(D3DOP_TRIANGLE
);
1215 instr
->bOpcode
= D3DOP_EXIT
;
1218 hr
= IDirect3DExecuteBuffer_Unlock(ExecuteBuffer
);
1219 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Unlock failed: %08x\n", hr
);
1221 hr
= IDirect3DDevice_Execute(Direct3DDevice1
, ExecuteBuffer
, Viewport
, D3DEXECUTE_CLIPPED
);
1222 ok(hr
== D3D_OK
, "IDirect3DDevice_Execute returned %08x\n", hr
);
1224 memset(&transformdata
, 0, sizeof(transformdata
));
1225 transformdata
.dwSize
= sizeof(transformdata
);
1226 transformdata
.lpIn
= testverts
;
1227 transformdata
.dwInSize
= sizeof(testverts
[0]);
1228 transformdata
.lpOut
= out
;
1229 transformdata
.dwOutSize
= sizeof(out
[0]);
1231 transformdata
.lpHOut
= NULL
;
1232 hr
= IDirect3DViewport_TransformVertices(Viewport
, sizeof(testverts
) / sizeof(testverts
[0]),
1233 &transformdata
, D3DTRANSFORM_UNCLIPPED
,
1235 ok(hr
== D3D_OK
, "IDirect3DViewport_TransformVertices returned %08x\n", hr
);
1237 transformdata
.lpHOut
= outH
;
1238 memset(outH
, 0xcc, sizeof(outH
));
1239 hr
= IDirect3DViewport_TransformVertices(Viewport
, sizeof(testverts
) / sizeof(testverts
[0]),
1240 &transformdata
, D3DTRANSFORM_UNCLIPPED
,
1242 ok(hr
== D3D_OK
, "IDirect3DViewport_TransformVertices returned %08x\n", hr
);
1243 ok(i
== 0, "Offscreen is %d\n", i
);
1245 for(i
= 0; i
< sizeof(testverts
) / sizeof(testverts
[0]); i
++) {
1246 static const struct v_out cmp
[] = {
1247 {128.0, 128.0, 0.0, 1}, {129.0, 127.0, 1.0, 1}, {127.0, 129.0, -1, 1},
1248 {128.5, 127.5, 0.5, 1}, {127.5, 128.5, -0.5, 1}, {127.5, 128.5, 0, 1}
1251 ok(cmp
[i
].x
== out
[i
].x
&& cmp
[i
].y
== out
[i
].y
&&
1252 cmp
[i
].z
== out
[i
].z
&& cmp
[i
].rhw
== out
[i
].rhw
,
1253 "Vertex %d differs. Got %f %f %f %f, expected %f %f %f %f\n", i
+ 1,
1254 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].rhw
,
1255 cmp
[i
].x
, cmp
[i
].y
, cmp
[i
].z
, cmp
[i
].rhw
);
1257 for(i
= 0; i
< sizeof(outH
); i
++) {
1258 if(((unsigned char *) outH
)[i
] != 0xcc) {
1259 ok(FALSE
, "Homogeneous output was generated despite UNCLIPPED flag\n");
1264 SET_VP_DATA(vp_data
);
1265 hr
= IDirect3DViewport_SetViewport(Viewport
, &vp_data
);
1266 ok(hr
== D3D_OK
, "IDirect3DViewport_SetViewport returned %08x\n", hr
);
1267 hr
= IDirect3DViewport_TransformVertices(Viewport
, sizeof(testverts
) / sizeof(testverts
[0]),
1268 &transformdata
, D3DTRANSFORM_UNCLIPPED
,
1270 ok(hr
== D3D_OK
, "IDirect3DViewport_TransformVertices returned %08x\n", hr
);
1271 ok(i
== 0, "Offscreen is %d\n", i
);
1273 for(i
= 0; i
< sizeof(testverts
) / sizeof(testverts
[0]); i
++) {
1274 static const struct v_out cmp
[] = {
1275 {128.0, 128.0, 0.0, 1}, {133.0, 123.0, 1.0, 1}, {123.0, 133.0, -1, 1},
1276 {130.5, 125.5, 0.5, 1}, {125.5, 130.5, -0.5, 1}, {125.5, 130.5, 0, 1}
1278 ok(cmp
[i
].x
== out
[i
].x
&& cmp
[i
].y
== out
[i
].y
&&
1279 cmp
[i
].z
== out
[i
].z
&& cmp
[i
].rhw
== out
[i
].rhw
,
1280 "Vertex %d differs. Got %f %f %f %f, expected %f %f %f %f\n", i
+ 1,
1281 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].rhw
,
1282 cmp
[i
].x
, cmp
[i
].y
, cmp
[i
].z
, cmp
[i
].rhw
);
1285 SET_VP_DATA(vp_data
);
1288 hr
= IDirect3DViewport_SetViewport(Viewport
, &vp_data
);
1289 ok(hr
== D3D_OK
, "IDirect3DViewport_SetViewport returned %08x\n", hr
);
1290 hr
= IDirect3DViewport_TransformVertices(Viewport
, sizeof(testverts
) / sizeof(testverts
[0]),
1291 &transformdata
, D3DTRANSFORM_UNCLIPPED
,
1293 ok(hr
== D3D_OK
, "IDirect3DViewport_TransformVertices returned %08x\n", hr
);
1294 ok(i
== 0, "Offscreen is %d\n", i
);
1295 for(i
= 0; i
< sizeof(testverts
) / sizeof(testverts
[0]); i
++) {
1296 static const struct v_out cmp
[] = {
1297 {138.0, 148.0, 0.0, 1}, {143.0, 143.0, 1.0, 1}, {133.0, 153.0, -1, 1},
1298 {140.5, 145.5, 0.5, 1}, {135.5, 150.5, -0.5, 1}, {135.5, 150.5, 0, 1}
1300 ok(cmp
[i
].x
== out
[i
].x
&& cmp
[i
].y
== out
[i
].y
&&
1301 cmp
[i
].z
== out
[i
].z
&& cmp
[i
].rhw
== out
[i
].rhw
,
1302 "Vertex %d differs. Got %f %f %f %f, expected %f %f %f %f\n", i
+ 1,
1303 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].rhw
,
1304 cmp
[i
].x
, cmp
[i
].y
, cmp
[i
].z
, cmp
[i
].rhw
);
1307 memset(out
, 0xcc, sizeof(out
));
1308 hr
= IDirect3DViewport_TransformVertices(Viewport
, sizeof(testverts
) / sizeof(testverts
[0]),
1309 &transformdata
, D3DTRANSFORM_CLIPPED
,
1311 ok(hr
== D3D_OK
, "IDirect3DViewport_TransformVertices returned %08x\n", hr
);
1312 ok(i
== 0, "Offscreen is %d\n", i
);
1313 for(i
= 0; i
< sizeof(testverts
) / sizeof(testverts
[0]); i
++) {
1314 static const D3DHVERTEX cmpH
[] = {
1315 {0, { 0.0}, { 0.0}, { 0.0}}, {0, { 1.0}, { 1.0}, {1.0}},
1316 {D3DCLIP_FRONT
, {-1.0}, {-1.0}, {-1.0}}, {0, { 0.5}, { 0.5}, {0.5}},
1317 {D3DCLIP_FRONT
, {-0.5}, {-0.5}, {-0.5}}, {0, {-0.5}, {-0.5}, {0.0}}
1319 ok(U1(cmpH
[i
]).hx
== U1(outH
[i
]).hx
&& U2(cmpH
[i
]).hy
== U2(outH
[i
]).hy
&&
1320 U3(cmpH
[i
]).hz
== U3(outH
[i
]).hz
&& cmpH
[i
].dwFlags
== outH
[i
].dwFlags
,
1321 "HVertex %d differs. Got %08x %f %f %f, expected %08x %f %f %f\n", i
+ 1,
1322 outH
[i
].dwFlags
, U1(outH
[i
]).hx
, U2(outH
[i
]).hy
, U3(outH
[i
]).hz
,
1323 cmpH
[i
].dwFlags
, U1(cmpH
[i
]).hx
, U2(cmpH
[i
]).hy
, U3(cmpH
[i
]).hz
);
1325 /* No scheme has been found behind those return values. It seems to be
1326 * whatever data windows has when throwing the vertex away. Modify the
1327 * input test vertices to test this more. Depending on the input data
1328 * it can happen that the z coord gets written into y, or similar things
1332 static const struct v_out cmp
[] = {
1333 {138.0, 148.0, 0.0, 1}, {143.0, 143.0, 1.0, 1}, { -1.0, -1.0, 0.5, 1},
1334 {140.5, 145.5, 0.5, 1}, { -0.5, -0.5, -0.5, 1}, {135.5, 150.5, 0.0, 1}
1336 ok(cmp
[i
].x
== out
[i
].x
&& cmp
[i
].y
== out
[i
].y
&&
1337 cmp
[i
].z
== out
[i
].z
&& cmp
[i
].rhw
== out
[i
].rhw
,
1338 "Vertex %d differs. Got %f %f %f %f, expected %f %f %f %f\n", i
+ 1,
1339 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].rhw
,
1340 cmp
[i
].x
, cmp
[i
].y
, cmp
[i
].z
, cmp
[i
].rhw
);
1343 for(i
= 0; i
< sizeof(out
) / sizeof(DWORD
); i
++) {
1344 ok(((DWORD
*) out
)[i
] != 0xcccccccc,
1345 "Regular output DWORD %d remained untouched\n", i
);
1348 transformdata
.lpIn
= cliptest
;
1349 transformdata
.dwInSize
= sizeof(cliptest
[0]);
1350 hr
= IDirect3DViewport_TransformVertices(Viewport
, sizeof(cliptest
) / sizeof(cliptest
[0]),
1351 &transformdata
, D3DTRANSFORM_CLIPPED
,
1353 ok(hr
== D3D_OK
, "IDirect3DViewport_TransformVertices returned %08x\n", hr
);
1354 ok(i
== 0, "Offscreen is %d\n", i
);
1355 for(i
= 0; i
< sizeof(cliptest
) / sizeof(cliptest
[0]); i
++) {
1356 DWORD Flags
[sizeof(cliptest
) / sizeof(cliptest
[0])] =
1360 D3DCLIP_RIGHT
| D3DCLIP_BACK
| D3DCLIP_TOP
,
1361 D3DCLIP_LEFT
| D3DCLIP_BOTTOM
| D3DCLIP_FRONT
,
1363 ok(Flags
[i
] == outH
[i
].dwFlags
,
1364 "Cliptest %d differs. Got %08x expected %08x\n", i
+ 1,
1365 outH
[i
].dwFlags
, Flags
[i
]);
1368 SET_VP_DATA(vp_data
);
1369 vp_data
.dwWidth
= 10;
1370 vp_data
.dwHeight
= 1000;
1371 hr
= IDirect3DViewport_SetViewport(Viewport
, &vp_data
);
1373 ok(hr
== D3D_OK
, "IDirect3DViewport_SetViewport returned %08x\n", hr
);
1374 hr
= IDirect3DViewport_TransformVertices(Viewport
, sizeof(cliptest
) / sizeof(cliptest
[0]),
1375 &transformdata
, D3DTRANSFORM_CLIPPED
,
1377 ok(hr
== D3D_OK
, "IDirect3DViewport_TransformVertices returned %08x\n", hr
);
1378 ok(i
== 0, "Offscreen is %d\n", i
);
1379 for(i
= 0; i
< sizeof(cliptest
) / sizeof(cliptest
[0]); i
++) {
1380 DWORD Flags
[sizeof(cliptest
) / sizeof(cliptest
[0])] =
1384 D3DCLIP_RIGHT
| D3DCLIP_BACK
,
1385 D3DCLIP_LEFT
| D3DCLIP_FRONT
,
1387 ok(Flags
[i
] == outH
[i
].dwFlags
,
1388 "Cliptest %d differs. Got %08x expected %08x\n", i
+ 1,
1389 outH
[i
].dwFlags
, Flags
[i
]);
1392 SET_VP_DATA(vp_data
);
1393 vp_data
.dwWidth
= 256;
1394 vp_data
.dwHeight
= 256;
1395 vp_data
.dvScaleX
= 1;
1396 vp_data
.dvScaleY
= 1;
1397 hr
= IDirect3DViewport_SetViewport(Viewport
, &vp_data
);
1398 ok(hr
== D3D_OK
, "IDirect3DViewport_SetViewport returned %08x\n", hr
);
1399 hr
= IDirect3DViewport_TransformVertices(Viewport
, sizeof(cliptest
) / sizeof(cliptest
[0]),
1400 &transformdata
, D3DTRANSFORM_CLIPPED
,
1402 ok(hr
== D3D_OK
, "IDirect3DViewport_TransformVertices returned %08x\n", hr
);
1403 ok(i
== 0, "Offscreen is %s\n", i
? "TRUE" : "FALSE");
1404 for(i
= 0; i
< sizeof(cliptest
) / sizeof(cliptest
[0]); i
++) {
1405 DWORD Flags
[sizeof(cliptest
) / sizeof(cliptest
[0])] =
1412 ok(Flags
[i
] == outH
[i
].dwFlags
,
1413 "Cliptest %d differs. Got %08x expected %08x\n", i
+ 1,
1414 outH
[i
].dwFlags
, Flags
[i
]);
1417 /* Finally try to figure out how the DWORD dwOffscreen works.
1418 * Apparently no vertex is offscreen with clipping off,
1419 * and with clipping on the offscreen flag is set if only one vertex
1420 * is transformed, and this vertex is offscreen.
1422 SET_VP_DATA(vp_data
);
1423 vp_data
.dwWidth
= 5;
1424 vp_data
.dwHeight
= 5;
1425 vp_data
.dvScaleX
= 10000;
1426 vp_data
.dvScaleY
= 10000;
1427 hr
= IDirect3DViewport_SetViewport(Viewport
, &vp_data
);
1428 ok(hr
== D3D_OK
, "IDirect3DViewport_SetViewport returned %08x\n", hr
);
1429 transformdata
.lpIn
= cliptest
;
1430 hr
= IDirect3DViewport_TransformVertices(Viewport
, 1,
1431 &transformdata
, D3DTRANSFORM_UNCLIPPED
,
1433 ok(hr
== D3D_OK
, "IDirect3DViewport_TransformVertices returned %08x\n", hr
);
1434 ok(i
== 0, "Offscreen is %d\n", i
);
1435 hr
= IDirect3DViewport_TransformVertices(Viewport
, 1,
1436 &transformdata
, D3DTRANSFORM_CLIPPED
,
1438 ok(hr
== D3D_OK
, "IDirect3DViewport_TransformVertices returned %08x\n", hr
);
1439 ok(i
== (D3DCLIP_RIGHT
| D3DCLIP_TOP
), "Offscreen is %d\n", i
);
1440 hr
= IDirect3DViewport_TransformVertices(Viewport
, 2,
1441 &transformdata
, D3DTRANSFORM_CLIPPED
,
1443 ok(hr
== D3D_OK
, "IDirect3DViewport_TransformVertices returned %08x\n", hr
);
1444 ok(i
== 0, "Offscreen is %d\n", i
);
1445 transformdata
.lpIn
= cliptest
+ 1;
1446 hr
= IDirect3DViewport_TransformVertices(Viewport
, 1,
1447 &transformdata
, D3DTRANSFORM_CLIPPED
,
1449 ok(hr
== D3D_OK
, "IDirect3DViewport_TransformVertices returned %08x\n", hr
);
1450 ok(i
== (D3DCLIP_BOTTOM
| D3DCLIP_LEFT
), "Offscreen is %d\n", i
);
1452 transformdata
.lpIn
= offscreentest
;
1453 transformdata
.dwInSize
= sizeof(offscreentest
[0]);
1454 SET_VP_DATA(vp_data
);
1455 vp_data
.dwWidth
= 257;
1456 vp_data
.dwHeight
= 257;
1457 vp_data
.dvScaleX
= 1;
1458 vp_data
.dvScaleY
= 1;
1459 hr
= IDirect3DViewport_SetViewport(Viewport
, &vp_data
);
1460 ok(SUCCEEDED(hr
), "IDirect3DViewport_SetViewport returned %#x.\n", hr
);
1462 hr
= IDirect3DViewport_TransformVertices(Viewport
, sizeof(offscreentest
) / sizeof(offscreentest
[0]),
1463 &transformdata
, D3DTRANSFORM_CLIPPED
,
1465 ok(hr
== D3D_OK
, "IDirect3DViewport_TransformVertices returned %08x\n", hr
);
1466 ok(i
== 0, "Offscreen is %d\n", i
);
1467 vp_data
.dwWidth
= 256;
1468 vp_data
.dwHeight
= 256;
1469 hr
= IDirect3DViewport_SetViewport(Viewport
, &vp_data
);
1470 ok(SUCCEEDED(hr
), "IDirect3DViewport_SetViewport returned %#x.\n", hr
);
1472 hr
= IDirect3DViewport_TransformVertices(Viewport
, sizeof(offscreentest
) / sizeof(offscreentest
[0]),
1473 &transformdata
, D3DTRANSFORM_CLIPPED
,
1475 ok(hr
== D3D_OK
, "IDirect3DViewport_TransformVertices returned %08x\n", hr
);
1476 ok(i
== D3DCLIP_RIGHT
, "Offscreen is %d\n", i
);
1478 hr
= IDirect3DViewport_TransformVertices(Viewport
, sizeof(testverts
) / sizeof(testverts
[0]),
1481 ok(hr
== DDERR_INVALIDPARAMS
, "IDirect3DViewport_TransformVertices returned %08x\n", hr
);
1483 hr
= IDirect3DDevice_DeleteViewport(Direct3DDevice1
, Viewport
);
1484 ok(hr
== D3D_OK
, "IDirect3DDevice_DeleteViewport returned %08x\n", hr
);
1486 hr
= IDirect3DViewport_AddLight(Viewport
, Light
);
1487 ok(hr
== D3D_OK
, "IDirect3DViewport_AddLight returned %08x\n", hr
);
1488 refcount
= getRefcount((IUnknown
*) Light
);
1489 ok(refcount
== 2, "Refcount should be 2, returned is %d\n", refcount
);
1491 hr
= IDirect3DViewport_NextLight(Viewport
, NULL
, &d3dlight
, D3DNEXT_HEAD
);
1492 ok(hr
== D3D_OK
, "IDirect3DViewport_AddLight returned %08x\n", hr
);
1493 ok(d3dlight
== Light
, "Got different light returned %p, expected %p\n", d3dlight
, Light
);
1494 refcount
= getRefcount((IUnknown
*) Light
);
1495 ok(refcount
== 3, "Refcount should be 2, returned is %d\n", refcount
);
1497 hr
= IDirect3DViewport_DeleteLight(Viewport
, Light
);
1498 ok(hr
== D3D_OK
, "IDirect3DViewport_DeleteLight returned %08x\n", hr
);
1499 refcount
= getRefcount((IUnknown
*) Light
);
1500 ok(refcount
== 2, "Refcount should be 2, returned is %d\n", refcount
);
1502 IDirect3DLight_Release(Light
);
1505 static BOOL
colortables_check_equality(PALETTEENTRY table1
[256], PALETTEENTRY table2
[256])
1509 for (i
= 0; i
< 256; i
++) {
1510 if (table1
[i
].peRed
!= table2
[i
].peRed
|| table1
[i
].peGreen
!= table2
[i
].peGreen
||
1511 table1
[i
].peBlue
!= table2
[i
].peBlue
) return FALSE
;
1517 /* test palette handling in IDirect3DTexture_Load */
1518 static void TextureLoadTest(void)
1520 IDirectDrawSurface
*TexSurface
= NULL
;
1521 IDirect3DTexture
*Texture
= NULL
;
1522 IDirectDrawSurface
*TexSurface2
= NULL
;
1523 IDirect3DTexture
*Texture2
= NULL
;
1524 IDirectDrawPalette
*palette
= NULL
;
1525 IDirectDrawPalette
*palette2
= NULL
;
1526 IDirectDrawPalette
*palette_tmp
= NULL
;
1527 PALETTEENTRY table1
[256], table2
[256], table_tmp
[256];
1532 memset (&ddsd
, 0, sizeof (ddsd
));
1533 ddsd
.dwSize
= sizeof (ddsd
);
1534 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
1535 ddsd
.dwHeight
= 128;
1537 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1538 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
1539 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_PALETTEINDEXED8
;
1540 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 8;
1542 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &TexSurface
, NULL
);
1543 ok(hr
==D3D_OK
, "CreateSurface returned: %x\n", hr
);
1545 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1549 hr
= IDirectDrawSurface_QueryInterface(TexSurface
, &IID_IDirect3DTexture
,
1551 ok(hr
==D3D_OK
, "IDirectDrawSurface_QueryInterface returned: %x\n", hr
);
1553 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1557 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &TexSurface2
, NULL
);
1558 ok(hr
==D3D_OK
, "CreateSurface returned: %x\n", hr
);
1560 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1564 hr
= IDirectDrawSurface_QueryInterface(TexSurface2
, &IID_IDirect3DTexture
,
1566 ok(hr
==D3D_OK
, "IDirectDrawSurface_QueryInterface returned: %x\n", hr
);
1568 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1572 /* test load of Texture to Texture */
1573 hr
= IDirect3DTexture_Load(Texture
, Texture
);
1574 ok(hr
== DD_OK
, "IDirect3DTexture_Load returned %08x\n", hr
);
1576 /* test Load when both textures have no palette */
1577 hr
= IDirect3DTexture_Load(Texture2
, Texture
);
1578 ok(hr
== DD_OK
, "IDirect3DTexture_Load returned %08x\n", hr
);
1580 for (i
= 0; i
< 256; i
++) {
1581 table1
[i
].peRed
= i
;
1582 table1
[i
].peGreen
= i
;
1583 table1
[i
].peBlue
= i
;
1584 table1
[i
].peFlags
= 0;
1587 hr
= IDirectDraw_CreatePalette(DirectDraw1
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, table1
, &palette
, NULL
);
1588 ok(hr
== DD_OK
, "CreatePalette returned %08x\n", hr
);
1590 skip("IDirectDraw_CreatePalette failed; skipping further tests\n");
1594 /* test Load when source texture has palette and destination has no palette */
1595 hr
= IDirectDrawSurface_SetPalette(TexSurface
, palette
);
1596 ok(hr
== DD_OK
, "IDirectDrawSurface_SetPalette returned %08x\n", hr
);
1597 hr
= IDirect3DTexture_Load(Texture2
, Texture
);
1598 ok(hr
== DDERR_NOPALETTEATTACHED
, "IDirect3DTexture_Load returned %08x\n", hr
);
1600 for (i
= 0; i
< 256; i
++) {
1601 table2
[i
].peRed
= 255 - i
;
1602 table2
[i
].peGreen
= 255 - i
;
1603 table2
[i
].peBlue
= 255 - i
;
1604 table2
[i
].peFlags
= 0;
1607 hr
= IDirectDraw_CreatePalette(DirectDraw1
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, table2
, &palette2
, NULL
);
1608 ok(hr
== DD_OK
, "CreatePalette returned %08x\n", hr
);
1610 skip("IDirectDraw_CreatePalette failed; skipping further tests\n");
1614 /* test Load when source has no palette and destination has a palette */
1615 hr
= IDirectDrawSurface_SetPalette(TexSurface
, NULL
);
1616 ok(hr
== DD_OK
, "IDirectDrawSurface_SetPalette returned %08x\n", hr
);
1617 hr
= IDirectDrawSurface_SetPalette(TexSurface2
, palette2
);
1618 ok(hr
== DD_OK
, "IDirectDrawSurface_SetPalette returned %08x\n", hr
);
1619 hr
= IDirect3DTexture_Load(Texture2
, Texture
);
1620 ok(hr
== DD_OK
, "IDirect3DTexture_Load returned %08x\n", hr
);
1621 hr
= IDirectDrawSurface_GetPalette(TexSurface2
, &palette_tmp
);
1622 ok(hr
== DD_OK
, "IDirectDrawSurface_GetPalette returned %08x\n", hr
);
1624 skip("IDirectDrawSurface_GetPalette failed; skipping color table check\n");
1627 hr
= IDirectDrawPalette_GetEntries(palette_tmp
, 0, 0, 256, table_tmp
);
1628 ok(hr
== DD_OK
, "IDirectDrawPalette_GetEntries returned %08x\n", hr
);
1629 ok(colortables_check_equality(table2
, table_tmp
), "Unexpected palettized texture color table\n");
1630 IDirectDrawPalette_Release(palette_tmp
);
1633 /* test Load when both textures have palettes */
1634 hr
= IDirectDrawSurface_SetPalette(TexSurface
, palette
);
1635 ok(hr
== DD_OK
, "IDirectDrawSurface_SetPalette returned %08x\n", hr
);
1636 hr
= IDirect3DTexture_Load(Texture2
, Texture
);
1637 ok(hr
== DD_OK
, "IDirect3DTexture_Load returned %08x\n", hr
);
1638 hr
= IDirect3DTexture_Load(Texture2
, Texture
);
1639 ok(hr
== DD_OK
, "IDirect3DTexture_Load returned %08x\n", hr
);
1640 hr
= IDirectDrawSurface_GetPalette(TexSurface2
, &palette_tmp
);
1641 ok(hr
== DD_OK
, "IDirectDrawSurface_GetPalette returned %08x\n", hr
);
1643 skip("IDirectDrawSurface_GetPalette failed; skipping color table check\n");
1646 hr
= IDirectDrawPalette_GetEntries(palette_tmp
, 0, 0, 256, table_tmp
);
1647 ok(hr
== DD_OK
, "IDirectDrawPalette_GetEntries returned %08x\n", hr
);
1648 ok(colortables_check_equality(table1
, table_tmp
), "Unexpected palettized texture color table\n");
1649 IDirectDrawPalette_Release(palette_tmp
);
1654 if (palette
) IDirectDrawPalette_Release(palette
);
1655 if (palette2
) IDirectDrawPalette_Release(palette2
);
1656 if (TexSurface
) IDirectDrawSurface_Release(TexSurface
);
1657 if (Texture
) IDirect3DTexture_Release(Texture
);
1658 if (TexSurface2
) IDirectDrawSurface_Release(TexSurface2
);
1659 if (Texture2
) IDirect3DTexture_Release(Texture2
);
1662 static void VertexBufferDescTest(void)
1665 D3DVERTEXBUFFERDESC desc
;
1668 D3DVERTEXBUFFERDESC desc2
;
1669 unsigned char buffer
[512];
1672 memset(&desc
, 0, sizeof(desc
));
1673 desc
.dwSize
= sizeof(desc
);
1675 desc
.dwFVF
= D3DFVF_XYZ
;
1676 desc
.dwNumVertices
= 1;
1677 rc
= IDirect3D7_CreateVertexBuffer(lpD3D
, &desc
, &lpVBufSrc
, 0);
1678 ok(rc
==D3D_OK
|| rc
==E_OUTOFMEMORY
, "CreateVertexBuffer returned: %x\n", rc
);
1681 trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc
);
1685 memset(mem
.buffer
, 0x12, sizeof(mem
.buffer
));
1686 mem
.desc2
.dwSize
= sizeof(D3DVERTEXBUFFERDESC
)*2;
1687 rc
= IDirect3DVertexBuffer7_GetVertexBufferDesc(lpVBufSrc
, &mem
.desc2
);
1689 skip("GetVertexBuffer Failed!\n");
1690 ok( mem
.desc2
.dwSize
== sizeof(D3DVERTEXBUFFERDESC
)*2, "Size returned from GetVertexBufferDesc does not match the value put in\n" );
1691 ok( mem
.buffer
[sizeof(D3DVERTEXBUFFERDESC
)] == 0x12, "GetVertexBufferDesc cleared outside of the struct! (dwSize was double the size of the struct)\n");
1692 ok( mem
.desc2
.dwCaps
== desc
.dwCaps
, "dwCaps returned differs. Got %x, expected %x\n", mem
.desc2
.dwCaps
, desc
.dwCaps
);
1693 ok( mem
.desc2
.dwFVF
== desc
.dwFVF
, "dwFVF returned differs. Got %x, expected %x\n", mem
.desc2
.dwFVF
, desc
.dwFVF
);
1694 ok (mem
.desc2
.dwNumVertices
== desc
.dwNumVertices
, "dwNumVertices returned differs. Got %x, expected %x\n", mem
.desc2
.dwNumVertices
, desc
.dwNumVertices
);
1696 memset(mem
.buffer
, 0x12, sizeof(mem
.buffer
));
1697 mem
.desc2
.dwSize
= 0;
1698 rc
= IDirect3DVertexBuffer7_GetVertexBufferDesc(lpVBufSrc
, &mem
.desc2
);
1700 skip("GetVertexBuffer Failed!\n");
1701 ok( mem
.desc2
.dwSize
== 0, "Size returned from GetVertexBufferDesc does not match the value put in\n" );
1702 ok( mem
.buffer
[sizeof(D3DVERTEXBUFFERDESC
)] == 0x12, "GetVertexBufferDesc cleared outside of the struct! (dwSize was 0)\n");
1703 ok( mem
.desc2
.dwCaps
== desc
.dwCaps
, "dwCaps returned differs. Got %x, expected %x\n", mem
.desc2
.dwCaps
, desc
.dwCaps
);
1704 ok( mem
.desc2
.dwFVF
== desc
.dwFVF
, "dwFVF returned differs. Got %x, expected %x\n", mem
.desc2
.dwFVF
, desc
.dwFVF
);
1705 ok (mem
.desc2
.dwNumVertices
== desc
.dwNumVertices
, "dwNumVertices returned differs. Got %x, expected %x\n", mem
.desc2
.dwNumVertices
, desc
.dwNumVertices
);
1707 memset(mem
.buffer
, 0x12, sizeof(mem
.buffer
));
1708 mem
.desc2
.dwSize
= sizeof(D3DVERTEXBUFFERDESC
);
1709 rc
= IDirect3DVertexBuffer7_GetVertexBufferDesc(lpVBufSrc
, &mem
.desc2
);
1711 skip("GetVertexBuffer Failed!\n");
1712 ok( mem
.desc2
.dwSize
== sizeof(D3DVERTEXBUFFERDESC
), "Size returned from GetVertexBufferDesc does not match the value put in\n" );
1713 ok( mem
.buffer
[sizeof(D3DVERTEXBUFFERDESC
)] == 0x12, "GetVertexBufferDesc cleared outside of the struct! (dwSize was the size of the struct)\n");
1714 ok( mem
.desc2
.dwCaps
== desc
.dwCaps
, "dwCaps returned differs. Got %x, expected %x\n", mem
.desc2
.dwCaps
, desc
.dwCaps
);
1715 ok( mem
.desc2
.dwFVF
== desc
.dwFVF
, "dwFVF returned differs. Got %x, expected %x\n", mem
.desc2
.dwFVF
, desc
.dwFVF
);
1716 ok (mem
.desc2
.dwNumVertices
== desc
.dwNumVertices
, "dwNumVertices returned differs. Got %x, expected %x\n", mem
.desc2
.dwNumVertices
, desc
.dwNumVertices
);
1719 IDirect3DVertexBuffer7_Release(lpVBufSrc
);
1722 static void D3D7_OldRenderStateTest(void)
1727 /* Test reaction to some deprecated states in D3D7. */
1728 hr
= IDirect3DDevice7_SetRenderState(lpD3DDevice
, D3DRENDERSTATE_TEXTUREHANDLE
, 0);
1729 ok(hr
== DDERR_INVALIDPARAMS
, "IDirect3DDevice7_SetRenderState returned %#x.\n", hr
);
1730 hr
= IDirect3DDevice7_GetRenderState(lpD3DDevice
, D3DRENDERSTATE_TEXTUREHANDLE
, &val
);
1731 ok(hr
== DDERR_INVALIDPARAMS
, "IDirect3DDevice7_GetRenderState returned %#x.\n", hr
);
1732 hr
= IDirect3DDevice7_SetRenderState(lpD3DDevice
, D3DRENDERSTATE_TEXTUREMAPBLEND
, D3DTBLEND_MODULATE
);
1733 ok(hr
== DDERR_INVALIDPARAMS
, "IDirect3DDevice7_SetRenderState returned %#x.\n", hr
);
1734 hr
= IDirect3DDevice7_GetRenderState(lpD3DDevice
, D3DRENDERSTATE_TEXTUREMAPBLEND
, &val
);
1735 ok(hr
== DDERR_INVALIDPARAMS
, "IDirect3DDevice7_GetRenderState returned %#x.\n", hr
);
1738 #define IS_VALUE_NEAR(a, b) ( ((a) == (b)) || ((a) == (b) - 1) || ((a) == (b) + 1) )
1739 #define MIN(a, b) ((a) < (b) ? (a) : (b))
1741 static void DeviceLoadTest(void)
1743 DDSURFACEDESC2 ddsd
;
1744 IDirectDrawSurface7
*texture_levels
[2][8];
1745 IDirectDrawSurface7
*cube_face_levels
[2][6][8];
1752 unsigned diff_count
= 0, diff_count2
= 0;
1754 BOOL load_mip_subset_broken
= FALSE
;
1755 IDirectDrawPalette
*palettes
[5];
1756 PALETTEENTRY table1
[256];
1758 D3DDEVICEDESC7 d3dcaps
;
1760 /* Test loading of texture subrectangle with a mipmap surface. */
1761 memset(texture_levels
, 0, sizeof(texture_levels
));
1762 memset(cube_face_levels
, 0, sizeof(cube_face_levels
));
1763 memset(palettes
, 0, sizeof(palettes
));
1765 for (i
= 0; i
< 2; i
++)
1767 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
1768 ddsd
.dwSize
= sizeof(ddsd
);
1769 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
1770 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
1772 ddsd
.dwHeight
= 128;
1773 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
1774 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1775 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
1776 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00FF0000;
1777 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000FF00;
1778 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000FF;
1779 hr
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &texture_levels
[i
][0], NULL
);
1780 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1781 if (FAILED(hr
)) goto out
;
1783 /* Check the number of created mipmaps */
1784 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
1785 ddsd
.dwSize
= sizeof(ddsd
);
1786 hr
= IDirectDrawSurface7_GetSurfaceDesc(texture_levels
[i
][0], &ddsd
);
1787 ok(hr
==DD_OK
,"IDirectDrawSurface7_GetSurfaceDesc returned: %x\n",hr
);
1788 ok(U2(ddsd
).dwMipMapCount
== 8, "unexpected mip count %u\n", U2(ddsd
).dwMipMapCount
);
1789 if (U2(ddsd
).dwMipMapCount
!= 8) goto out
;
1791 for (i1
= 1; i1
< 8; i1
++)
1793 hr
= IDirectDrawSurface7_GetAttachedSurface(texture_levels
[i
][i1
- 1], &ddsd
.ddsCaps
, &texture_levels
[i
][i1
]);
1794 ok(hr
== DD_OK
, "GetAttachedSurface returned %08x\n", hr
);
1795 if (FAILED(hr
)) goto out
;
1799 for (i1
= 0; i1
< 8; i1
++)
1801 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
1802 ddsd
.dwSize
= sizeof(ddsd
);
1803 hr
= IDirectDrawSurface7_Lock(texture_levels
[0][i1
], NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
1804 ok(hr
==DD_OK
, "IDirectDrawSurface7_Lock returned: %x\n",hr
);
1805 if (FAILED(hr
)) goto out
;
1807 for (y
= 0 ; y
< ddsd
.dwHeight
; y
++)
1809 DWORD
*textureRow
= (DWORD
*)((char*)ddsd
.lpSurface
+ y
* U1(ddsd
).lPitch
);
1811 for (x
= 0; x
< ddsd
.dwWidth
; x
++)
1813 /* x stored in green component, y in blue. */
1814 DWORD color
= 0xff0000 | (x
<< 8) | y
;
1815 *textureRow
++ = color
;
1819 hr
= IDirectDrawSurface7_Unlock(texture_levels
[0][i1
], NULL
);
1820 ok(hr
==DD_OK
, "IDirectDrawSurface7_Unlock returned: %x\n",hr
);
1823 for (i1
= 0; i1
< 8; i1
++)
1825 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
1826 ddbltfx
.dwSize
= sizeof(ddbltfx
);
1827 U5(ddbltfx
).dwFillColor
= 0;
1828 hr
= IDirectDrawSurface7_Blt(texture_levels
[1][i1
], NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1829 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt failed with %08x\n", hr
);
1832 /* First test some broken coordinates. */
1833 loadpoint
.x
= loadpoint
.y
= 0;
1837 loadrect
.bottom
= 0;
1838 hr
= IDirect3DDevice7_Load(lpD3DDevice
, texture_levels
[1][0], &loadpoint
, texture_levels
[0][0], &loadrect
, 0);
1839 ok(hr
==DDERR_INVALIDPARAMS
, "IDirect3DDevice7_Load returned: %x\n",hr
);
1841 loadpoint
.x
= loadpoint
.y
= 50;
1844 loadrect
.right
= 100;
1845 loadrect
.bottom
= 100;
1846 hr
= IDirect3DDevice7_Load(lpD3DDevice
, texture_levels
[1][0], &loadpoint
, texture_levels
[0][0], &loadrect
, 0);
1847 ok(hr
==DDERR_INVALIDPARAMS
, "IDirect3DDevice7_Load returned: %x\n",hr
);
1849 /* Test actual loading. */
1850 loadpoint
.x
= loadpoint
.y
= 31;
1853 loadrect
.right
= 93;
1854 loadrect
.bottom
= 52;
1856 hr
= IDirect3DDevice7_Load(lpD3DDevice
, texture_levels
[1][0], &loadpoint
, texture_levels
[0][0], &loadrect
, 0);
1857 ok(hr
==D3D_OK
, "IDirect3DDevice7_Load returned: %x\n",hr
);
1859 for (i1
= 0; i1
< 8; i1
++)
1864 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
1865 ddsd
.dwSize
= sizeof(ddsd
);
1866 hr
= IDirectDrawSurface7_Lock(texture_levels
[1][i1
], NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
1867 ok(hr
==DD_OK
, "IDirectDrawSurface7_Lock returned: %x\n",hr
);
1868 if (FAILED(hr
)) goto out
;
1870 for (y
= 0 ; y
< ddsd
.dwHeight
; y
++)
1872 DWORD
*textureRow
= (DWORD
*)((char*)ddsd
.lpSurface
+ y
* U1(ddsd
).lPitch
);
1874 for (x
= 0; x
< ddsd
.dwWidth
; x
++)
1876 DWORD color
= *textureRow
++;
1878 if (x
< loadpoint
.x
|| x
>= loadpoint
.x
+ loadrect
.right
- loadrect
.left
||
1879 y
< loadpoint
.y
|| y
>= loadpoint
.y
+ loadrect
.bottom
- loadrect
.top
)
1881 if (color
& 0xffffff) diff_count
++;
1885 DWORD r
= (color
& 0xff0000) >> 16;
1886 DWORD g
= (color
& 0xff00) >> 8;
1887 DWORD b
= (color
& 0xff);
1889 if (r
!= 0xff || g
!= x
+ loadrect
.left
- loadpoint
.x
|| b
!= y
+ loadrect
.top
- loadpoint
.y
) diff_count
++;
1892 /* This codepath is for software RGB device. It has what looks like some weird off by one errors, but may
1893 technically be correct as it's not precisely defined by docs. */
1894 if (x
< loadpoint
.x
|| x
>= loadpoint
.x
+ loadrect
.right
- loadrect
.left
||
1895 y
< loadpoint
.y
|| y
>= loadpoint
.y
+ loadrect
.bottom
- loadrect
.top
+ 1)
1897 if (color
& 0xffffff) diff_count2
++;
1901 DWORD r
= (color
& 0xff0000) >> 16;
1902 DWORD g
= (color
& 0xff00) >> 8;
1903 DWORD b
= (color
& 0xff);
1905 if (r
!= 0xff || !IS_VALUE_NEAR(g
, x
+ loadrect
.left
- loadpoint
.x
) ||
1906 !IS_VALUE_NEAR(b
, y
+ loadrect
.top
- loadpoint
.y
)) diff_count2
++;
1911 hr
= IDirectDrawSurface7_Unlock(texture_levels
[1][i1
], NULL
);
1912 ok(hr
==DD_OK
, "IDirectDrawSurface7_Unlock returned: %x\n",hr
);
1914 ok(diff_count
== 0 || diff_count2
== 0, "Unexpected destination texture level pixels; %u differences at %d level\n",
1915 MIN(diff_count
, diff_count2
), i1
);
1921 loadrect
.right
= (loadrect
.right
+ 1) / 2;
1922 loadrect
.bottom
= (loadrect
.bottom
+ 1) / 2;
1925 /* This crashes on native (tested on real windows XP / directx9 / nvidia and
1926 * qemu Win98 / directx7 / RGB software rasterizer):
1927 * passing non toplevel surfaces (sublevels) to Load (DX7 docs tell not to do this)
1928 hr = IDirect3DDevice7_Load(lpD3DDevice, texture_levels[1][1], NULL, texture_levels[0][1], NULL, 0);
1931 /* Freed in reverse order as native seems to dislike and crash on freeing top level surface first. */
1932 for (i
= 0; i
< 2; i
++)
1934 for (i1
= 7; i1
>= 0; i1
--)
1936 if (texture_levels
[i
][i1
]) IDirectDrawSurface7_Release(texture_levels
[i
][i1
]);
1939 memset(texture_levels
, 0, sizeof(texture_levels
));
1941 /* Test texture size mismatch. */
1942 for (i
= 0; i
< 2; i
++)
1944 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
1945 ddsd
.dwSize
= sizeof(ddsd
);
1946 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1947 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1948 ddsd
.dwWidth
= i
? 256 : 128;
1949 ddsd
.dwHeight
= 128;
1950 hr
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &texture_levels
[i
][0], NULL
);
1951 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1952 if (FAILED(hr
)) goto out
;
1955 hr
= IDirect3DDevice7_Load(lpD3DDevice
, texture_levels
[1][0], NULL
, texture_levels
[0][0], NULL
, 0);
1956 ok(hr
==DDERR_INVALIDPARAMS
, "IDirect3DDevice7_Load returned: %x\n",hr
);
1958 hr
= IDirect3DDevice7_Load(lpD3DDevice
, texture_levels
[0][0], NULL
, texture_levels
[1][0], NULL
, 0);
1959 ok(hr
==DDERR_INVALIDPARAMS
, "IDirect3DDevice7_Load returned: %x\n",hr
);
1961 IDirectDrawSurface7_Release(texture_levels
[0][0]);
1962 IDirectDrawSurface7_Release(texture_levels
[1][0]);
1963 memset(texture_levels
, 0, sizeof(texture_levels
));
1965 memset(&d3dcaps
, 0, sizeof(d3dcaps
));
1966 hr
= IDirect3DDevice7_GetCaps(lpD3DDevice
, &d3dcaps
);
1967 ok(hr
== D3D_OK
, "IDirect3DDevice7_GetCaps returned %08x\n", hr
);
1969 if (!(d3dcaps
.dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_CUBEMAP
))
1971 skip("No cubemap support\n");
1975 /* Test loading mipmapped cubemap texture subrectangle from another similar texture. */
1976 for (i
= 0; i
< 2; i
++)
1978 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
1979 ddsd
.dwSize
= sizeof(ddsd
);
1980 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
1981 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
1982 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
;
1984 ddsd
.dwHeight
= 128;
1985 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
1986 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1987 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
1988 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00FF0000;
1989 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000FF00;
1990 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000FF;
1991 hr
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &cube_face_levels
[i
][0][0], NULL
);
1992 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
1993 if (FAILED(hr
)) goto out
;
1995 flags
= DDSCAPS2_CUBEMAP_NEGATIVEX
;
1996 for (i1
= 1; i1
< 6; i1
++, flags
<<= 1)
1998 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1999 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_CUBEMAP
| flags
;
2000 hr
= IDirectDrawSurface7_GetAttachedSurface(cube_face_levels
[i
][0][0], &ddsd
.ddsCaps
, &cube_face_levels
[i
][i1
][0]);
2001 ok(hr
== DD_OK
, "GetAttachedSurface returned %08x\n", hr
);
2002 if (FAILED(hr
)) goto out
;
2005 for (i1
= 0; i1
< 6; i1
++)
2007 /* Check the number of created mipmaps */
2008 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
2009 ddsd
.dwSize
= sizeof(ddsd
);
2010 hr
= IDirectDrawSurface7_GetSurfaceDesc(cube_face_levels
[i
][i1
][0], &ddsd
);
2011 ok(hr
==DD_OK
,"IDirectDrawSurface7_GetSurfaceDesc returned: %x\n",hr
);
2012 ok(U2(ddsd
).dwMipMapCount
== 8, "unexpected mip count %u\n", U2(ddsd
).dwMipMapCount
);
2013 if (U2(ddsd
).dwMipMapCount
!= 8) goto out
;
2015 for (i2
= 1; i2
< 8; i2
++)
2017 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
;
2018 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_MIPMAPSUBLEVEL
;
2019 hr
= IDirectDrawSurface7_GetAttachedSurface(cube_face_levels
[i
][i1
][i2
- 1], &ddsd
.ddsCaps
, &cube_face_levels
[i
][i1
][i2
]);
2020 ok(hr
== DD_OK
, "GetAttachedSurface returned %08x\n", hr
);
2021 if (FAILED(hr
)) goto out
;
2026 for (i
= 0; i
< 6; i
++)
2027 for (i1
= 0; i1
< 8; i1
++)
2029 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
2030 ddsd
.dwSize
= sizeof(ddsd
);
2031 hr
= IDirectDrawSurface7_Lock(cube_face_levels
[0][i
][i1
], NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
2032 ok(hr
==DD_OK
, "IDirectDrawSurface7_Lock returned: %x\n",hr
);
2033 if (FAILED(hr
)) goto out
;
2035 for (y
= 0 ; y
< ddsd
.dwHeight
; y
++)
2037 DWORD
*textureRow
= (DWORD
*)((char*)ddsd
.lpSurface
+ y
* U1(ddsd
).lPitch
);
2039 for (x
= 0; x
< ddsd
.dwWidth
; x
++)
2041 /* face number in low 4 bits of red, x stored in green component, y in blue. */
2042 DWORD color
= 0xf00000 | (i
<< 16) | (x
<< 8) | y
;
2043 *textureRow
++ = color
;
2047 hr
= IDirectDrawSurface7_Unlock(cube_face_levels
[0][i
][i1
], NULL
);
2048 ok(hr
==DD_OK
, "IDirectDrawSurface7_Unlock returned: %x\n",hr
);
2051 for (i
= 0; i
< 6; i
++)
2052 for (i1
= 0; i1
< 8; i1
++)
2054 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
2055 ddbltfx
.dwSize
= sizeof(ddbltfx
);
2056 U5(ddbltfx
).dwFillColor
= 0;
2057 hr
= IDirectDrawSurface7_Blt(cube_face_levels
[1][i
][i1
], NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
2058 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt failed with %08x\n", hr
);
2061 loadpoint
.x
= loadpoint
.y
= 10;
2064 loadrect
.right
= 93;
2065 loadrect
.bottom
= 52;
2067 hr
= IDirect3DDevice7_Load(lpD3DDevice
, cube_face_levels
[1][0][0], &loadpoint
, cube_face_levels
[0][0][0], &loadrect
,
2068 DDSCAPS2_CUBEMAP_ALLFACES
);
2069 ok(hr
==D3D_OK
, "IDirect3DDevice7_Load returned: %x\n",hr
);
2071 for (i
= 0; i
< 6; i
++)
2073 loadpoint
.x
= loadpoint
.y
= 10;
2076 loadrect
.right
= 93;
2077 loadrect
.bottom
= 52;
2079 for (i1
= 0; i1
< 8; i1
++)
2084 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
2085 ddsd
.dwSize
= sizeof(ddsd
);
2086 hr
= IDirectDrawSurface7_Lock(cube_face_levels
[1][i
][i1
], NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
2087 ok(hr
==DD_OK
, "IDirectDrawSurface7_Lock returned: %x\n",hr
);
2088 if (FAILED(hr
)) goto out
;
2090 for (y
= 0 ; y
< ddsd
.dwHeight
; y
++)
2092 DWORD
*textureRow
= (DWORD
*)((char*)ddsd
.lpSurface
+ y
* U1(ddsd
).lPitch
);
2094 for (x
= 0; x
< ddsd
.dwWidth
; x
++)
2096 DWORD color
= *textureRow
++;
2098 if (x
< loadpoint
.x
|| x
>= loadpoint
.x
+ loadrect
.right
- loadrect
.left
||
2099 y
< loadpoint
.y
|| y
>= loadpoint
.y
+ loadrect
.bottom
- loadrect
.top
)
2101 if (color
& 0xffffff) diff_count
++;
2105 DWORD r
= (color
& 0xff0000) >> 16;
2106 DWORD g
= (color
& 0xff00) >> 8;
2107 DWORD b
= (color
& 0xff);
2109 if (r
!= (0xf0 | i
) || g
!= x
+ loadrect
.left
- loadpoint
.x
||
2110 b
!= y
+ loadrect
.top
- loadpoint
.y
) diff_count
++;
2113 /* This codepath is for software RGB device. It has what looks like some weird off by one errors, but may
2114 technically be correct as it's not precisely defined by docs. */
2115 if (x
< loadpoint
.x
|| x
>= loadpoint
.x
+ loadrect
.right
- loadrect
.left
||
2116 y
< loadpoint
.y
|| y
>= loadpoint
.y
+ loadrect
.bottom
- loadrect
.top
+ 1)
2118 if (color
& 0xffffff) diff_count2
++;
2122 DWORD r
= (color
& 0xff0000) >> 16;
2123 DWORD g
= (color
& 0xff00) >> 8;
2124 DWORD b
= (color
& 0xff);
2126 if (r
!= (0xf0 | i
) || !IS_VALUE_NEAR(g
, x
+ loadrect
.left
- loadpoint
.x
) ||
2127 !IS_VALUE_NEAR(b
, y
+ loadrect
.top
- loadpoint
.y
)) diff_count2
++;
2132 hr
= IDirectDrawSurface7_Unlock(cube_face_levels
[1][i
][i1
], NULL
);
2133 ok(hr
==DD_OK
, "IDirectDrawSurface7_Unlock returned: %x\n",hr
);
2135 ok(diff_count
== 0 || diff_count2
== 0,
2136 "Unexpected destination texture level pixels; %u differences at face %x level %d\n",
2137 MIN(diff_count
, diff_count2
), i
, i1
);
2143 loadrect
.right
= (loadrect
.right
+ 1) / 2;
2144 loadrect
.bottom
= (loadrect
.bottom
+ 1) / 2;
2148 for (i
= 0; i
< 2; i
++)
2149 for (i1
= 5; i1
>= 0; i1
--)
2150 for (i2
= 7; i2
>= 0; i2
--)
2152 if (cube_face_levels
[i
][i1
][i2
]) IDirectDrawSurface7_Release(cube_face_levels
[i
][i1
][i2
]);
2154 memset(cube_face_levels
, 0, sizeof(cube_face_levels
));
2156 /* Test cubemap loading from regular texture. */
2157 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
2158 ddsd
.dwSize
= sizeof(ddsd
);
2159 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
2160 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
;
2161 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
;
2163 ddsd
.dwHeight
= 128;
2164 hr
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &cube_face_levels
[0][0][0], NULL
);
2165 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
2166 if (FAILED(hr
)) goto out
;
2168 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
2169 ddsd
.dwSize
= sizeof(ddsd
);
2170 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
2171 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
2173 ddsd
.dwHeight
= 128;
2174 hr
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &texture_levels
[0][0], NULL
);
2175 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
2176 if (FAILED(hr
)) goto out
;
2178 hr
= IDirect3DDevice7_Load(lpD3DDevice
, cube_face_levels
[0][0][0], NULL
, texture_levels
[0][0], NULL
,
2179 DDSCAPS2_CUBEMAP_ALLFACES
);
2180 ok(hr
==DDERR_INVALIDPARAMS
, "IDirect3DDevice7_Load returned: %x\n",hr
);
2182 IDirectDrawSurface7_Release(cube_face_levels
[0][0][0]);
2183 memset(cube_face_levels
, 0, sizeof(cube_face_levels
));
2184 IDirectDrawSurface7_Release(texture_levels
[0][0]);
2185 memset(texture_levels
, 0, sizeof(texture_levels
));
2187 /* Partial cube maps(e.g. created with an explicitly set DDSCAPS2_CUBEMAP_POSITIVEX flag)
2188 * BSOD some Windows machines when an app tries to create them(Radeon X1600, Windows XP,
2189 * Catalyst 10.2 driver, 6.14.10.6925)
2193 /* Test texture loading with different mip level count (larger levels match, smaller levels missing in destination. */
2194 for (i
= 0; i
< 2; i
++)
2196 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
2197 ddsd
.dwSize
= sizeof(ddsd
);
2198 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_MIPMAPCOUNT
;
2199 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
2201 ddsd
.dwHeight
= 128;
2202 U2(ddsd
).dwMipMapCount
= i
? 4 : 8;
2203 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
2204 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
2205 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
2206 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00FF0000;
2207 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000FF00;
2208 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000FF;
2209 hr
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &texture_levels
[i
][0], NULL
);
2210 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
2211 if (FAILED(hr
)) goto out
;
2213 /* Check the number of created mipmaps */
2214 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
2215 ddsd
.dwSize
= sizeof(ddsd
);
2216 hr
= IDirectDrawSurface7_GetSurfaceDesc(texture_levels
[i
][0], &ddsd
);
2217 ok(hr
==DD_OK
,"IDirectDrawSurface7_GetSurfaceDesc returned: %x\n",hr
);
2218 ok(U2(ddsd
).dwMipMapCount
== (i
? 4 : 8), "unexpected mip count %u\n", U2(ddsd
).dwMipMapCount
);
2219 if (U2(ddsd
).dwMipMapCount
!= (i
? 4 : 8)) goto out
;
2221 for (i1
= 1; i1
< (i
? 4 : 8); i1
++)
2223 hr
= IDirectDrawSurface7_GetAttachedSurface(texture_levels
[i
][i1
- 1], &ddsd
.ddsCaps
, &texture_levels
[i
][i1
]);
2224 ok(hr
== DD_OK
, "GetAttachedSurface returned %08x\n", hr
);
2225 if (FAILED(hr
)) goto out
;
2229 for (i1
= 0; i1
< 8; i1
++)
2231 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
2232 ddsd
.dwSize
= sizeof(ddsd
);
2233 hr
= IDirectDrawSurface7_Lock(texture_levels
[0][i1
], NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
2234 ok(hr
==DD_OK
, "IDirectDrawSurface7_Lock returned: %x\n",hr
);
2235 if (FAILED(hr
)) goto out
;
2237 for (y
= 0 ; y
< ddsd
.dwHeight
; y
++)
2239 DWORD
*textureRow
= (DWORD
*)((char*)ddsd
.lpSurface
+ y
* U1(ddsd
).lPitch
);
2241 for (x
= 0; x
< ddsd
.dwWidth
; x
++)
2243 /* x stored in green component, y in blue. */
2244 DWORD color
= 0xf00000 | (i1
<< 16) | (x
<< 8) | y
;
2245 *textureRow
++ = color
;
2249 hr
= IDirectDrawSurface7_Unlock(texture_levels
[0][i1
], NULL
);
2250 ok(hr
==DD_OK
, "IDirectDrawSurface7_Unlock returned: %x\n",hr
);
2253 for (i1
= 0; i1
< 4; i1
++)
2255 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
2256 ddbltfx
.dwSize
= sizeof(ddbltfx
);
2257 U5(ddbltfx
).dwFillColor
= 0;
2258 hr
= IDirectDrawSurface7_Blt(texture_levels
[1][i1
], NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
2259 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt failed with %08x\n", hr
);
2262 loadpoint
.x
= loadpoint
.y
= 31;
2265 loadrect
.right
= 93;
2266 loadrect
.bottom
= 52;
2268 /* Destination mip levels are a subset of source mip levels. */
2269 hr
= IDirect3DDevice7_Load(lpD3DDevice
, texture_levels
[1][0], &loadpoint
, texture_levels
[0][0], &loadrect
, 0);
2270 ok(hr
==D3D_OK
, "IDirect3DDevice7_Load returned: %x\n",hr
);
2272 for (i1
= 0; i1
< 4; i1
++)
2277 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
2278 ddsd
.dwSize
= sizeof(ddsd
);
2279 hr
= IDirectDrawSurface7_Lock(texture_levels
[1][i1
], NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
2280 ok(hr
==DD_OK
, "IDirectDrawSurface7_Lock returned: %x\n",hr
);
2281 if (FAILED(hr
)) goto out
;
2283 for (y
= 0 ; y
< ddsd
.dwHeight
; y
++)
2285 DWORD
*textureRow
= (DWORD
*)((char*)ddsd
.lpSurface
+ y
* U1(ddsd
).lPitch
);
2287 for (x
= 0; x
< ddsd
.dwWidth
; x
++)
2289 DWORD color
= *textureRow
++;
2291 if (x
< loadpoint
.x
|| x
>= loadpoint
.x
+ loadrect
.right
- loadrect
.left
||
2292 y
< loadpoint
.y
|| y
>= loadpoint
.y
+ loadrect
.bottom
- loadrect
.top
)
2294 if (color
& 0xffffff) diff_count
++;
2298 DWORD r
= (color
& 0xff0000) >> 16;
2299 DWORD g
= (color
& 0xff00) >> 8;
2300 DWORD b
= (color
& 0xff);
2302 if (r
!= (0xf0 | i1
) || g
!= x
+ loadrect
.left
- loadpoint
.x
||
2303 b
!= y
+ loadrect
.top
- loadpoint
.y
) diff_count
++;
2306 /* This codepath is for software RGB device. It has what looks like some weird off by one errors, but may
2307 technically be correct as it's not precisely defined by docs. */
2308 if (x
< loadpoint
.x
|| x
>= loadpoint
.x
+ loadrect
.right
- loadrect
.left
||
2309 y
< loadpoint
.y
|| y
>= loadpoint
.y
+ loadrect
.bottom
- loadrect
.top
+ 1)
2311 if (color
& 0xffffff) diff_count2
++;
2315 DWORD r
= (color
& 0xff0000) >> 16;
2316 DWORD g
= (color
& 0xff00) >> 8;
2317 DWORD b
= (color
& 0xff);
2319 if (r
!= (0xf0 | i1
) || !IS_VALUE_NEAR(g
, x
+ loadrect
.left
- loadpoint
.x
) ||
2320 !IS_VALUE_NEAR(b
, y
+ loadrect
.top
- loadpoint
.y
)) diff_count2
++;
2325 hr
= IDirectDrawSurface7_Unlock(texture_levels
[1][i1
], NULL
);
2326 ok(hr
==DD_OK
, "IDirectDrawSurface7_Unlock returned: %x\n",hr
);
2328 ok(diff_count
== 0 || diff_count2
== 0, "Unexpected destination texture level pixels; %u differences at %d level\n",
2329 MIN(diff_count
, diff_count2
), i1
);
2335 loadrect
.right
= (loadrect
.right
+ 1) / 2;
2336 loadrect
.bottom
= (loadrect
.bottom
+ 1) / 2;
2339 /* Destination mip levels are a superset of source mip levels (should fail). */
2340 hr
= IDirect3DDevice7_Load(lpD3DDevice
, texture_levels
[0][0], &loadpoint
, texture_levels
[1][0], &loadrect
, 0);
2341 ok(hr
==DDERR_INVALIDPARAMS
, "IDirect3DDevice7_Load returned: %x\n",hr
);
2343 for (i
= 0; i
< 2; i
++)
2345 for (i1
= 7; i1
>= 0; i1
--)
2347 if (texture_levels
[i
][i1
]) IDirectDrawSurface7_Release(texture_levels
[i
][i1
]);
2350 memset(texture_levels
, 0, sizeof(texture_levels
));
2352 /* Test loading from mipmap texture to a regular texture that matches one sublevel in size. */
2353 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
2354 ddsd
.dwSize
= sizeof(ddsd
);
2355 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
2356 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
2358 ddsd
.dwHeight
= 128;
2359 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
2360 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
2361 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
2362 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00FF0000;
2363 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000FF00;
2364 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000FF;
2365 hr
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &texture_levels
[0][0], NULL
);
2366 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
2367 if (FAILED(hr
)) goto out
;
2369 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
2370 ddsd
.dwSize
= sizeof(ddsd
);
2371 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
2372 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
2375 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
2376 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
2377 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
2378 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00FF0000;
2379 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000FF00;
2380 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000FF;
2381 hr
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &texture_levels
[1][0], NULL
);
2382 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
2383 if (FAILED(hr
)) goto out
;
2385 for (i1
= 1; i1
< 8; i1
++)
2387 hr
= IDirectDrawSurface7_GetAttachedSurface(texture_levels
[0][i1
- 1], &ddsd
.ddsCaps
, &texture_levels
[0][i1
]);
2388 ok(hr
== DD_OK
, "GetAttachedSurface returned %08x\n", hr
);
2389 if (FAILED(hr
)) goto out
;
2392 for (i1
= 0; i1
< 8; i1
++)
2394 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
2395 ddsd
.dwSize
= sizeof(ddsd
);
2396 hr
= IDirectDrawSurface7_Lock(texture_levels
[0][i1
], NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
2397 ok(hr
==DD_OK
, "IDirectDrawSurface7_Lock returned: %x\n",hr
);
2398 if (FAILED(hr
)) goto out
;
2400 for (y
= 0 ; y
< ddsd
.dwHeight
; y
++)
2402 DWORD
*textureRow
= (DWORD
*)((char*)ddsd
.lpSurface
+ y
* U1(ddsd
).lPitch
);
2404 for (x
= 0; x
< ddsd
.dwWidth
; x
++)
2406 /* x stored in green component, y in blue. */
2407 DWORD color
= 0xf00000 | (i1
<< 16) | (x
<< 8) | y
;
2408 *textureRow
++ = color
;
2412 hr
= IDirectDrawSurface7_Unlock(texture_levels
[0][i1
], NULL
);
2413 ok(hr
==DD_OK
, "IDirectDrawSurface7_Unlock returned: %x\n",hr
);
2416 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
2417 ddbltfx
.dwSize
= sizeof(ddbltfx
);
2418 U5(ddbltfx
).dwFillColor
= 0;
2419 hr
= IDirectDrawSurface7_Blt(texture_levels
[1][0], NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
2420 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt failed with %08x\n", hr
);
2422 loadpoint
.x
= loadpoint
.y
= 32;
2425 loadrect
.right
= 96;
2426 loadrect
.bottom
= 96;
2428 hr
= IDirect3DDevice7_Load(lpD3DDevice
, texture_levels
[1][0], &loadpoint
, texture_levels
[0][0], &loadrect
, 0);
2429 ok(hr
==D3D_OK
, "IDirect3DDevice7_Load returned: %x\n",hr
);
2435 loadrect
.right
= (loadrect
.right
+ 3) / 4;
2436 loadrect
.bottom
= (loadrect
.bottom
+ 3) / 4;
2438 /* NOTE: something in either nvidia driver or directx9 on WinXP appears to be broken:
2439 * this kind of Load calls (to subset with smaller surface(s)) produces wrong results with
2440 * copied subrectangles divided more than needed, without apparent logic. But it works
2441 * as expected on qemu / Win98 / directx7 / RGB device. Some things are broken on XP, e.g.
2442 * some games don't work that worked in Win98, so it is assumed here XP results are wrong.
2443 * The following code attempts to detect broken results, actual tests will then be skipped
2445 load_mip_subset_broken
= TRUE
;
2448 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
2449 ddsd
.dwSize
= sizeof(ddsd
);
2450 hr
= IDirectDrawSurface7_Lock(texture_levels
[1][0], NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
2451 ok(hr
==DD_OK
, "IDirectDrawSurface7_Lock returned: %x\n",hr
);
2452 if (FAILED(hr
)) goto out
;
2454 for (y
= 0 ; y
< ddsd
.dwHeight
; y
++)
2456 DWORD
*textureRow
= (DWORD
*)((char*)ddsd
.lpSurface
+ y
* U1(ddsd
).lPitch
);
2458 for (x
= 0; x
< ddsd
.dwWidth
; x
++)
2460 DWORD color
= *textureRow
++;
2462 if (x
< 2 || x
>= 2 + 4 ||
2463 y
< 2 || y
>= 2 + 4)
2465 if (color
& 0xffffff) diff_count
++;
2469 DWORD r
= (color
& 0xff0000) >> 16;
2471 if ((r
& (0xf0)) != 0xf0) diff_count
++;
2476 if (diff_count
) load_mip_subset_broken
= FALSE
;
2478 if (load_mip_subset_broken
) {
2479 skip("IDirect3DDevice7_Load is broken (happens on some modern Windows installations like XP). Skipping affected tests.\n");
2483 for (y
= 0 ; y
< ddsd
.dwHeight
; y
++)
2485 DWORD
*textureRow
= (DWORD
*)((char*)ddsd
.lpSurface
+ y
* U1(ddsd
).lPitch
);
2487 for (x
= 0; x
< ddsd
.dwWidth
; x
++)
2489 DWORD color
= *textureRow
++;
2491 if (x
< loadpoint
.x
|| x
>= loadpoint
.x
+ loadrect
.right
- loadrect
.left
||
2492 y
< loadpoint
.y
|| y
>= loadpoint
.y
+ loadrect
.bottom
- loadrect
.top
)
2494 if (color
& 0xffffff) diff_count
++;
2498 DWORD r
= (color
& 0xff0000) >> 16;
2499 DWORD g
= (color
& 0xff00) >> 8;
2500 DWORD b
= (color
& 0xff);
2502 if (r
!= (0xf0 | 2) || g
!= x
+ loadrect
.left
- loadpoint
.x
||
2503 b
!= y
+ loadrect
.top
- loadpoint
.y
) diff_count
++;
2509 hr
= IDirectDrawSurface7_Unlock(texture_levels
[1][0], NULL
);
2510 ok(hr
==DD_OK
, "IDirectDrawSurface7_Unlock returned: %x\n",hr
);
2512 ok(diff_count
== 0, "Unexpected destination texture level pixels; %u differences\n", diff_count
);
2514 for (i
= 0; i
< 2; i
++)
2516 for (i1
= 7; i1
>= 0; i1
--)
2518 if (texture_levels
[i
][i1
]) IDirectDrawSurface7_Release(texture_levels
[i
][i1
]);
2521 memset(texture_levels
, 0, sizeof(texture_levels
));
2523 if (!load_mip_subset_broken
)
2525 /* Test loading when destination mip levels are a subset of source mip levels and start from smaller
2526 * surface (than first source mip level)
2528 for (i
= 0; i
< 2; i
++)
2530 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
2531 ddsd
.dwSize
= sizeof(ddsd
);
2532 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
2533 if (i
) ddsd
.dwFlags
|= DDSD_MIPMAPCOUNT
;
2534 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
2535 ddsd
.dwWidth
= i
? 32 : 128;
2536 ddsd
.dwHeight
= i
? 32 : 128;
2537 if (i
) U2(ddsd
).dwMipMapCount
= 4;
2538 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
2539 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
2540 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
2541 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00FF0000;
2542 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000FF00;
2543 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000FF;
2544 hr
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &texture_levels
[i
][0], NULL
);
2545 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
2546 if (FAILED(hr
)) goto out
;
2548 /* Check the number of created mipmaps */
2549 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
2550 ddsd
.dwSize
= sizeof(ddsd
);
2551 hr
= IDirectDrawSurface7_GetSurfaceDesc(texture_levels
[i
][0], &ddsd
);
2552 ok(hr
==DD_OK
,"IDirectDrawSurface7_GetSurfaceDesc returned: %x\n",hr
);
2553 ok(U2(ddsd
).dwMipMapCount
== (i
? 4 : 8), "unexpected mip count %u\n", U2(ddsd
).dwMipMapCount
);
2554 if (U2(ddsd
).dwMipMapCount
!= (i
? 4 : 8)) goto out
;
2556 for (i1
= 1; i1
< (i
? 4 : 8); i1
++)
2558 hr
= IDirectDrawSurface7_GetAttachedSurface(texture_levels
[i
][i1
- 1], &ddsd
.ddsCaps
, &texture_levels
[i
][i1
]);
2559 ok(hr
== DD_OK
, "GetAttachedSurface returned %08x\n", hr
);
2560 if (FAILED(hr
)) goto out
;
2564 for (i1
= 0; i1
< 8; i1
++)
2566 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
2567 ddsd
.dwSize
= sizeof(ddsd
);
2568 hr
= IDirectDrawSurface7_Lock(texture_levels
[0][i1
], NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
2569 ok(hr
==DD_OK
, "IDirectDrawSurface7_Lock returned: %x\n",hr
);
2570 if (FAILED(hr
)) goto out
;
2572 for (y
= 0 ; y
< ddsd
.dwHeight
; y
++)
2574 DWORD
*textureRow
= (DWORD
*)((char*)ddsd
.lpSurface
+ y
* U1(ddsd
).lPitch
);
2576 for (x
= 0; x
< ddsd
.dwWidth
; x
++)
2578 /* x stored in green component, y in blue. */
2579 DWORD color
= 0xf00000 | (i1
<< 16) | (x
<< 8) | y
;
2580 *textureRow
++ = color
;
2584 hr
= IDirectDrawSurface7_Unlock(texture_levels
[0][i1
], NULL
);
2585 ok(hr
==DD_OK
, "IDirectDrawSurface7_Unlock returned: %x\n",hr
);
2588 for (i1
= 0; i1
< 4; i1
++)
2590 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
2591 ddbltfx
.dwSize
= sizeof(ddbltfx
);
2592 U5(ddbltfx
).dwFillColor
= 0;
2593 hr
= IDirectDrawSurface7_Blt(texture_levels
[1][i1
], NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
2594 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt failed with %08x\n", hr
);
2597 loadpoint
.x
= loadpoint
.y
= 0;
2600 loadrect
.right
= 64;
2601 loadrect
.bottom
= 64;
2603 hr
= IDirect3DDevice7_Load(lpD3DDevice
, texture_levels
[1][0], &loadpoint
, texture_levels
[0][0], &loadrect
, 0);
2604 ok(hr
==D3D_OK
, "IDirect3DDevice7_Load returned: %x\n",hr
);
2607 for (i1
= 0; i1
< 8 && i
< 4; i1
++)
2609 DDSURFACEDESC2 ddsd2
;
2611 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
2612 ddsd
.dwSize
= sizeof(ddsd
);
2613 hr
= IDirectDrawSurface7_GetSurfaceDesc(texture_levels
[0][i1
], &ddsd
);
2614 ok(SUCCEEDED(hr
), "IDirectDrawSurface7_GetSurfaceDesc returned %#x.\n", hr
);
2616 memset(&ddsd2
, 0, sizeof(DDSURFACEDESC2
));
2617 ddsd2
.dwSize
= sizeof(ddsd2
);
2618 hr
= IDirectDrawSurface7_GetSurfaceDesc(texture_levels
[1][i
], &ddsd2
);
2619 ok(SUCCEEDED(hr
), "IDirectDrawSurface7_GetSurfaceDesc returned %#x.\n", hr
);
2621 if (ddsd
.dwWidth
== ddsd2
.dwWidth
&& ddsd
.dwHeight
== ddsd2
.dwHeight
)
2625 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
2626 ddsd
.dwSize
= sizeof(ddsd
);
2627 hr
= IDirectDrawSurface7_Lock(texture_levels
[1][i
], NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
2628 ok(hr
==DD_OK
, "IDirectDrawSurface7_Lock returned: %x\n",hr
);
2629 if (FAILED(hr
)) goto out
;
2631 for (y
= 0 ; y
< ddsd
.dwHeight
; y
++)
2633 DWORD
*textureRow
= (DWORD
*)((char*)ddsd
.lpSurface
+ y
* U1(ddsd
).lPitch
);
2635 for (x
= 0; x
< ddsd
.dwWidth
; x
++)
2637 DWORD color
= *textureRow
++;
2639 if (x
< loadpoint
.x
|| x
>= loadpoint
.x
+ loadrect
.right
- loadrect
.left
||
2640 y
< loadpoint
.y
|| y
>= loadpoint
.y
+ loadrect
.bottom
- loadrect
.top
)
2642 if (color
& 0xffffff) diff_count
++;
2646 DWORD r
= (color
& 0xff0000) >> 16;
2647 DWORD g
= (color
& 0xff00) >> 8;
2648 DWORD b
= (color
& 0xff);
2650 if (r
!= (0xf0 | i1
) || g
!= x
+ loadrect
.left
- loadpoint
.x
||
2651 b
!= y
+ loadrect
.top
- loadpoint
.y
) diff_count
++;
2656 hr
= IDirectDrawSurface7_Unlock(texture_levels
[1][i
], NULL
);
2657 ok(hr
==DD_OK
, "IDirectDrawSurface7_Unlock returned: %x\n",hr
);
2659 ok(diff_count
== 0, "Unexpected destination texture level pixels; %u differences at %d level\n", diff_count
, i1
);
2668 loadrect
.right
= (loadrect
.right
+ 1) / 2;
2669 loadrect
.bottom
= (loadrect
.bottom
+ 1) / 2;
2672 for (i
= 0; i
< 2; i
++)
2674 for (i1
= 7; i1
>= 0; i1
--)
2676 if (texture_levels
[i
][i1
]) IDirectDrawSurface7_Release(texture_levels
[i
][i1
]);
2679 memset(texture_levels
, 0, sizeof(texture_levels
));
2682 /* Test palette copying. */
2683 for (i
= 0; i
< 2; i
++)
2685 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
2686 ddsd
.dwSize
= sizeof(ddsd
);
2687 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
2688 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
2690 ddsd
.dwHeight
= 128;
2691 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
2692 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_PALETTEINDEXED8
;
2693 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 8;
2694 hr
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &texture_levels
[i
][0], NULL
);
2695 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
2696 if (FAILED(hr
)) goto out
;
2698 /* Check the number of created mipmaps */
2699 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
2700 ddsd
.dwSize
= sizeof(ddsd
);
2701 hr
= IDirectDrawSurface7_GetSurfaceDesc(texture_levels
[i
][0], &ddsd
);
2702 ok(hr
==DD_OK
,"IDirectDrawSurface7_GetSurfaceDesc returned: %x\n",hr
);
2703 ok(U2(ddsd
).dwMipMapCount
== 8, "unexpected mip count %u\n", U2(ddsd
).dwMipMapCount
);
2704 if (U2(ddsd
).dwMipMapCount
!= 8) goto out
;
2706 for (i1
= 1; i1
< 8; i1
++)
2708 hr
= IDirectDrawSurface7_GetAttachedSurface(texture_levels
[i
][i1
- 1], &ddsd
.ddsCaps
, &texture_levels
[i
][i1
]);
2709 ok(hr
== DD_OK
, "GetAttachedSurface returned %08x\n", hr
);
2710 if (FAILED(hr
)) goto out
;
2714 memset(table1
, 0, sizeof(table1
));
2715 for (i
= 0; i
< 3; i
++)
2717 table1
[0].peBlue
= i
+ 1;
2718 hr
= IDirectDraw7_CreatePalette(lpDD
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, table1
, &palettes
[i
], NULL
);
2719 ok(hr
== DD_OK
, "CreatePalette returned %08x\n", hr
);
2722 skip("IDirectDraw7_CreatePalette failed; skipping further tests\n");
2727 hr
= IDirectDrawSurface7_SetPalette(texture_levels
[0][0], palettes
[0]);
2728 ok(hr
==DD_OK
, "IDirectDrawSurface7_SetPalette returned: %x\n", hr
);
2730 hr
= IDirect3DDevice7_Load(lpD3DDevice
, texture_levels
[1][0], NULL
, texture_levels
[0][0], NULL
, 0);
2731 ok(hr
==D3D_OK
, "IDirect3DDevice7_Load returned: %x\n",hr
);
2733 hr
= IDirectDrawSurface7_GetPalette(texture_levels
[0][1], &palettes
[4]);
2734 ok(hr
==DDERR_NOPALETTEATTACHED
, "IDirectDrawSurface7_GetPalette returned: %x\n", hr
);
2736 hr
= IDirectDrawSurface7_GetPalette(texture_levels
[1][0], &palettes
[4]);
2737 ok(hr
==DDERR_NOPALETTEATTACHED
, "IDirectDrawSurface7_GetPalette returned: %x\n", hr
);
2739 hr
= IDirectDrawSurface7_SetPalette(texture_levels
[0][1], palettes
[1]);
2740 ok(hr
==DDERR_NOTONMIPMAPSUBLEVEL
, "IDirectDrawSurface7_SetPalette returned: %x\n", hr
);
2741 hr
= IDirectDrawSurface7_SetPalette(texture_levels
[1][0], palettes
[2]);
2742 ok(hr
==DD_OK
, "IDirectDrawSurface7_SetPalette returned: %x\n", hr
);
2744 hr
= IDirect3DDevice7_Load(lpD3DDevice
, texture_levels
[1][0], NULL
, texture_levels
[0][0], NULL
, 0);
2745 ok(hr
==D3D_OK
, "IDirect3DDevice7_Load returned: %x\n",hr
);
2747 memset(table1
, 0, sizeof(table1
));
2748 hr
= IDirectDrawSurface7_GetPalette(texture_levels
[1][0], &palettes
[4]);
2749 ok(hr
==DD_OK
, "IDirectDrawSurface7_GetPalette returned: %x\n", hr
);
2752 hr
= IDirectDrawPalette_GetEntries(palettes
[4], 0, 0, 256, table1
);
2753 ok(hr
== DD_OK
, "IDirectDrawPalette_GetEntries returned %08x\n", hr
);
2754 ok(table1
[0].peBlue
== 1, "Unexpected palette color after load: %u\n", (unsigned)table1
[0].peBlue
);
2757 /* Test colorkey copying. */
2758 ddckey
.dwColorSpaceLowValue
= ddckey
.dwColorSpaceHighValue
= 64;
2759 hr
= IDirectDrawSurface7_SetColorKey(texture_levels
[0][0], DDCKEY_SRCBLT
, &ddckey
);
2760 ok(hr
==DD_OK
, "IDirectDrawSurface7_SetColorKey returned: %x\n", hr
);
2761 hr
= IDirectDrawSurface7_SetColorKey(texture_levels
[0][1], DDCKEY_SRCBLT
, &ddckey
);
2762 todo_wine
ok(hr
==DDERR_NOTONMIPMAPSUBLEVEL
, "IDirectDrawSurface7_SetColorKey returned: %x\n", hr
);
2764 hr
= IDirectDrawSurface7_GetColorKey(texture_levels
[1][0], DDCKEY_SRCBLT
, &ddckey
);
2765 ok(hr
==DDERR_NOCOLORKEY
, "IDirectDrawSurface7_GetColorKey returned: %x\n", hr
);
2767 hr
= IDirect3DDevice7_Load(lpD3DDevice
, texture_levels
[1][0], NULL
, texture_levels
[0][0], NULL
, 0);
2768 ok(hr
==D3D_OK
, "IDirect3DDevice7_Load returned: %x\n",hr
);
2770 hr
= IDirectDrawSurface7_GetColorKey(texture_levels
[1][0], DDCKEY_SRCBLT
, &ddckey
);
2771 ok(hr
==DD_OK
, "IDirectDrawSurface7_GetColorKey returned: %x\n", hr
);
2772 ok(ddckey
.dwColorSpaceLowValue
== ddckey
.dwColorSpaceHighValue
&& ddckey
.dwColorSpaceLowValue
== 64,
2773 "Unexpected color key values: %u - %u\n", ddckey
.dwColorSpaceLowValue
, ddckey
.dwColorSpaceHighValue
);
2777 for (i
= 0; i
< 5; i
++)
2779 if (palettes
[i
]) IDirectDrawPalette_Release(palettes
[i
]);
2782 for (i
= 0; i
< 2; i
++)
2784 for (i1
= 7; i1
>= 0; i1
--)
2786 if (texture_levels
[i
][i1
]) IDirectDrawSurface7_Release(texture_levels
[i
][i1
]);
2790 for (i
= 0; i
< 2; i
++)
2791 for (i1
= 5; i1
>= 0; i1
--)
2792 for (i2
= 7; i2
>= 0; i2
--)
2794 if (cube_face_levels
[i
][i1
][i2
]) IDirectDrawSurface7_Release(cube_face_levels
[i
][i1
][i2
]);
2798 static void SetMaterialTest(void)
2802 rc
=IDirect3DDevice7_SetMaterial(lpD3DDevice
, NULL
);
2803 ok(rc
== DDERR_INVALIDPARAMS
, "Expected DDERR_INVALIDPARAMS, got %x\n", rc
);
2806 static void ComputeSphereVisibility(void)
2808 D3DMATRIX proj
, view
, world
;
2810 D3DVECTOR center
[3];
2814 world
._11
=1.0; world
._12
=0.0; world
._13
=0.0; world
._14
=0.0;
2815 world
._21
=0.0; world
._22
=1.0; world
._23
=0.0; world
._24
=0.0;
2816 world
._31
=0.0; world
._32
=0.0; world
._33
=1.0; world
._34
=0.0;
2817 world
._41
=0.0; world
._42
=0.0; world
._43
=0.0; world
._44
=1.0;
2819 view
._11
=1.000000; view
._12
=0.000000; view
._13
=0.000000; view
._14
=0.000000;
2820 view
._21
=0.000000; view
._22
=0.768221; view
._23
=-0.640185; view
._24
=0.000000;
2821 view
._31
=-0.000000; view
._32
=0.640185; view
._33
=0.768221; view
._34
=0.000000;
2822 view
._41
=-14.852037; view
._42
=9.857489; view
._43
=11.600972; view
._44
=1.000000;
2824 proj
._11
=1.810660; proj
._12
=0.000000; proj
._13
=0.00000; proj
._14
=0.000000;
2825 proj
._21
=0.000000; proj
._22
=2.414213; proj
._23
=0.000000, proj
._24
=0.000000;
2826 proj
._31
=0.000000; proj
._32
=0.000000; proj
._33
=1.020408, proj
._34
=1.000000;
2827 proj
._41
=0.000000; proj
._42
=0.000000; proj
._43
=-0.102041; proj
._44
=0.000000;
2829 IDirect3DDevice7_SetTransform(lpD3DDevice
, D3DTRANSFORMSTATE_WORLD
, &world
);
2830 IDirect3DDevice7_SetTransform(lpD3DDevice
, D3DTRANSFORMSTATE_VIEW
, &view
);
2831 IDirect3DDevice7_SetTransform(lpD3DDevice
, D3DTRANSFORMSTATE_PROJECTION
, &proj
);
2833 U1(center
[0]).x
=11.461533;
2834 U2(center
[0]).y
=-4.761727;
2835 U3(center
[0]).z
=-1.171646;
2837 radius
[0]=38.252632;
2839 rc
= IDirect3DDevice7_ComputeSphereVisibility(lpD3DDevice
, center
, radius
, 1, 0, result
);
2841 ok(rc
== D3D_OK
, "Expected D3D_OK, received %x\n", rc
);
2842 ok(result
[0] == 0x3f, "Expected 0x3f, got %x\n", result
[0]);
2844 U1(center
[0]).x
=-3.515620; U2(center
[0]).y
=-1.560661; U3(center
[0]).z
=-12.464638;
2846 U1(center
[1]).x
=14.290396; U2(center
[1]).y
=-2.981143; U3(center
[1]).z
=-24.311312;
2847 radius
[1]=12.500704;
2848 U1(center
[2]).x
=1.461626; U2(center
[2]).y
=-6.093709; U3(center
[2]).z
=-13.901010;
2849 radius
[2]=17.251318;
2851 rc
= IDirect3DDevice7_ComputeSphereVisibility(lpD3DDevice
, center
, radius
, 3, 0, result
);
2853 ok(rc
== D3D_OK
, "Expected D3D_OK, received %x\n", rc
);
2854 ok(result
[0] == 0x103d, "Expected 0x103d, got %x\n", result
[0]);
2855 ok(result
[1] == 0x3f, "Expected 0x3f, got %x\n", result
[1]);
2856 ok(result
[2] == 0x3f, "Expected 0x3f, got %x\n", result
[2]);
2858 view
._11
=1.0; view
._12
=0.0; view
._13
=0.0; view
._14
=0.0;
2859 view
._21
=0.0; view
._22
=1.0; view
._23
=0.0; view
._24
=0.0;
2860 view
._31
=0.0; view
._32
=0.0; view
._33
=1.0; view
._34
=0.0;
2861 view
._41
=0.0; view
._42
=0.0; view
._43
=0.0; view
._44
=1.0;
2863 proj
._11
=10.0; proj
._12
=0.0; proj
._13
=0.0; proj
._14
=0.0;
2864 proj
._21
=0.0; proj
._22
=10.0; proj
._23
=0.0, proj
._24
=0.0;
2865 proj
._31
=0.0; proj
._32
=0.0; proj
._33
=10.0, proj
._34
=0.0;
2866 proj
._41
=0.0; proj
._42
=0.0; proj
._43
=0.0; proj
._44
=1.0;
2868 U1(center
[0]).x
=0.0;
2869 U2(center
[0]).y
=0.0;
2870 U3(center
[0]).z
=0.05;
2874 IDirect3DDevice7_SetTransform(lpD3DDevice
, D3DTRANSFORMSTATE_VIEW
, &view
);
2875 IDirect3DDevice7_SetTransform(lpD3DDevice
, D3DTRANSFORMSTATE_PROJECTION
, &proj
);
2877 rc
= IDirect3DDevice7_ComputeSphereVisibility(lpD3DDevice
, center
, radius
, 1, 0, result
);
2879 ok(rc
== D3D_OK
, "Expected D3D_OK, received %x\n", rc
);
2880 ok(result
[0] == 0x0, "Expected 0x0, got %x\n", result
[0]);
2882 proj
._11
=1.0; proj
._12
=0.0; proj
._13
=0.0; proj
._14
=0.0;
2883 proj
._21
=0.0; proj
._22
=1.0; proj
._23
=0.0, proj
._24
=0.0;
2884 proj
._31
=0.0; proj
._32
=0.0; proj
._33
=1.0, proj
._34
=0.0;
2885 proj
._41
=0.0; proj
._42
=0.0; proj
._43
=0.0; proj
._44
=1.0;
2887 IDirect3DDevice7_SetTransform(lpD3DDevice
, D3DTRANSFORMSTATE_PROJECTION
, &proj
);
2889 U1(center
[0]).x
=0.0;
2890 U2(center
[0]).y
=0.0;
2891 U3(center
[0]).z
=0.5;
2895 rc
= IDirect3DDevice7_ComputeSphereVisibility(lpD3DDevice
, center
, radius
, 1, 0, result
);
2897 ok(rc
== D3D_OK
, "Expected D3D_OK, received %x\n", rc
);
2898 ok(result
[0] == 0x0, "Expected 0x0, got %x\n", result
[0]);
2900 U1(center
[0]).x
=0.0;
2901 U2(center
[0]).y
=0.0;
2902 U3(center
[0]).z
=0.0;
2906 rc
= IDirect3DDevice7_ComputeSphereVisibility(lpD3DDevice
, center
, radius
, 1, 0, result
);
2908 ok(rc
== D3D_OK
, "Expected D3D_OK, received %x\n", rc
);
2909 ok(result
[0] == 0x0, "Expected 0x0, got %x\n", result
[0]);
2911 U1(center
[0]).x
=-1.0;
2912 U2(center
[0]).y
=-1.0;
2913 U3(center
[0]).z
=0.50;
2917 rc
= IDirect3DDevice7_ComputeSphereVisibility(lpD3DDevice
, center
, radius
, 1, 0, result
);
2919 ok(rc
== D3D_OK
, "Expected D3D_OK, received %x\n", rc
);
2920 ok(result
[0] == 0x9, "Expected 0x9, got %x\n", result
[0]);
2922 U1(center
[0]).x
=-20.0;
2923 U2(center
[0]).y
=0.0;
2924 U3(center
[0]).z
=0.50;
2928 rc
= IDirect3DDevice7_ComputeSphereVisibility(lpD3DDevice
, center
, radius
, 1, 0, result
);
2930 ok(rc
== D3D_OK
, "Expected D3D_OK, received %x\n", rc
);
2931 ok(result
[0] == 0x103d, "Expected 0x103d, got %x\n", result
[0]);
2933 U1(center
[0]).x
=20.0;
2934 U2(center
[0]).y
=0.0;
2935 U3(center
[0]).z
=0.50;
2939 rc
= IDirect3DDevice7_ComputeSphereVisibility(lpD3DDevice
, center
, radius
, 1, 0, result
);
2941 ok(rc
== D3D_OK
, "Expected D3D_OK, received %x\n", rc
);
2942 ok(result
[0] == 0x203e, "Expected 0x203e, got %x\n", result
[0]);
2944 U1(center
[0]).x
=0.0;
2945 U2(center
[0]).y
=-20.0;
2946 U3(center
[0]).z
=0.50;
2950 rc
= IDirect3DDevice7_ComputeSphereVisibility(lpD3DDevice
, center
, radius
, 1, 0, result
);
2952 ok(rc
== D3D_OK
, "Expected D3D_OK, received %x\n", rc
);
2953 ok(result
[0] == 0x803b, "Expected 0x803b, got %x\n", result
[0]);
2955 U1(center
[0]).x
=0.0;
2956 U2(center
[0]).y
=20.0;
2957 U3(center
[0]).z
=0.5;
2961 rc
= IDirect3DDevice7_ComputeSphereVisibility(lpD3DDevice
, center
, radius
, 1, 0, result
);
2963 ok(rc
== D3D_OK
, "Expected D3D_OK, received %x\n", rc
);
2964 ok(result
[0] == 0x4037, "Expected 0x4037, got %x\n", result
[0]);
2966 U1(center
[0]).x
=0.0;
2967 U2(center
[0]).y
=0.0;
2968 U3(center
[0]).z
=-20;
2972 rc
= IDirect3DDevice7_ComputeSphereVisibility(lpD3DDevice
, center
, radius
, 1, 0, result
);
2974 ok(rc
== D3D_OK
, "Expected D3D_OK, received %x\n", rc
);
2975 ok(result
[0] == 0x1001f, "Expected 0x1001f, got %x\n", result
[0]);
2977 U1(center
[0]).x
=0.0;
2978 U2(center
[0]).y
=0.0;
2979 U3(center
[0]).z
=20.0;
2983 rc
= IDirect3DDevice7_ComputeSphereVisibility(lpD3DDevice
, center
, radius
, 1, 0, result
);
2985 ok(rc
== D3D_OK
, "Expected D3D_OK, received %x\n", rc
);
2986 ok(result
[0] == 0x2002f, "Expected 0x2002f, got %x\n", result
[0]);
2989 static void SetRenderTargetTest(void)
2992 IDirectDrawSurface7
*newrt
, *failrt
, *oldrt
, *temprt
;
2994 DDSURFACEDESC2 ddsd
, ddsd2
;
2998 memset(&ddsd
, 0, sizeof(ddsd
));
2999 ddsd
.dwSize
= sizeof(ddsd
);
3000 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
3001 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_3DDEVICE
;
3005 hr
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &newrt
, NULL
);
3006 ok(hr
== DD_OK
, "IDirectDraw7_CreateSurface failed, hr=0x%08x\n", hr
);
3009 skip("Skipping SetRenderTarget test\n");
3013 memset(&ddsd2
, 0, sizeof(ddsd2
));
3014 ddsd2
.dwSize
= sizeof(ddsd2
);
3015 ddsd2
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
3016 ddsd2
.ddsCaps
.dwCaps
= DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
;
3018 ddsd2
.dwHeight
= 64;
3019 U4(ddsd2
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd2
).ddpfPixelFormat
);
3020 U4(ddsd2
).ddpfPixelFormat
.dwFlags
= DDPF_ZBUFFER
;
3021 U1(U4(ddsd2
).ddpfPixelFormat
).dwZBufferBitDepth
= 16;
3022 U3(U4(ddsd2
).ddpfPixelFormat
).dwZBitMask
= 0x0000FFFF;
3024 hr
= IDirectDraw7_CreateSurface(lpDD
, &ddsd2
, &failrt
, NULL
);
3025 ok(hr
== DD_OK
, "IDirectDraw7_CreateSurface failed, hr=0x%08x\n", hr
);
3027 memset(&vp
, 0, sizeof(vp
));
3034 hr
= IDirect3DDevice7_SetViewport(lpD3DDevice
, &vp
);
3035 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetViewport failed, hr=0x%08x\n", hr
);
3037 hr
= IDirect3DDevice7_GetRenderTarget(lpD3DDevice
, &oldrt
);
3038 ok(hr
== DD_OK
, "IDirect3DDevice7_GetRenderTarget failed, hr=0x%08x\n", hr
);
3040 refcount
= getRefcount((IUnknown
*) oldrt
);
3041 ok(refcount
== 3, "Refcount should be 3, returned is %d\n", refcount
);
3043 refcount
= getRefcount((IUnknown
*) failrt
);
3044 ok(refcount
== 1, "Refcount should be 1, returned is %d\n", refcount
);
3046 hr
= IDirect3DDevice7_SetRenderTarget(lpD3DDevice
, failrt
, 0);
3047 ok(hr
!= D3D_OK
, "IDirect3DDevice7_SetRenderTarget succeeded\n");
3049 refcount
= getRefcount((IUnknown
*) oldrt
);
3050 ok(refcount
== 2, "Refcount should be 2, returned is %d\n", refcount
);
3052 refcount
= getRefcount((IUnknown
*) failrt
);
3053 ok(refcount
== 2, "Refcount should be 2, returned is %d\n", refcount
);
3055 hr
= IDirect3DDevice7_GetRenderTarget(lpD3DDevice
, &temprt
);
3056 ok(hr
== DD_OK
, "IDirect3DDevice7_GetRenderTarget failed, hr=0x%08x\n", hr
);
3057 ok(failrt
== temprt
, "Wrong iface returned\n");
3059 refcount
= getRefcount((IUnknown
*) failrt
);
3060 ok(refcount
== 3, "Refcount should be 3, returned is %d\n", refcount
);
3062 hr
= IDirect3DDevice7_SetRenderTarget(lpD3DDevice
, newrt
, 0);
3063 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderTarget failed, hr=0x%08x\n", hr
);
3065 refcount
= getRefcount((IUnknown
*) failrt
);
3066 ok(refcount
== 2, "Refcount should be 2, returned is %d\n", refcount
);
3068 memset(&vp
, 0xff, sizeof(vp
));
3069 hr
= IDirect3DDevice7_GetViewport(lpD3DDevice
, &vp
);
3070 ok(hr
== D3D_OK
, "IDirect3DDevice7_GetViewport failed, hr=0x%08x\n", hr
);
3071 ok(vp
.dwX
== 10, "vp.dwX is %u, expected 10\n", vp
.dwX
);
3072 ok(vp
.dwY
== 10, "vp.dwY is %u, expected 10\n", vp
.dwY
);
3073 ok(vp
.dwWidth
== 246, "vp.dwWidth is %u, expected 246\n", vp
.dwWidth
);
3074 ok(vp
.dwHeight
== 246, "vp.dwHeight is %u, expected 246\n", vp
.dwHeight
);
3075 ok(vp
.dvMinZ
== 0.25, "vp.dvMinZ is %f, expected 0.25\n", vp
.dvMinZ
);
3076 ok(vp
.dvMaxZ
== 0.75, "vp.dvMaxZ is %f, expected 0.75\n", vp
.dvMaxZ
);
3078 memset(&vp
, 0, sizeof(vp
));
3085 hr
= IDirect3DDevice7_SetViewport(lpD3DDevice
, &vp
);
3086 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetViewport failed, hr=0x%08x\n", hr
);
3088 hr
= IDirect3DDevice7_BeginStateBlock(lpD3DDevice
);
3089 ok(hr
== D3D_OK
, "IDirect3DDevice7_BeginStateblock failed, hr=0x%08x\n", hr
);
3090 hr
= IDirect3DDevice7_SetRenderTarget(lpD3DDevice
, oldrt
, 0);
3091 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderTarget failed, hr=0x%08x\n", hr
);
3093 /* Check this twice, before and after ending the stateblock */
3094 memset(&vp
, 0xff, sizeof(vp
));
3095 hr
= IDirect3DDevice7_GetViewport(lpD3DDevice
, &vp
);
3096 ok(hr
== D3D_OK
, "IDirect3DDevice7_GetViewport failed, hr=0x%08x\n", hr
);
3097 ok(vp
.dwX
== 0, "vp.dwX is %u, expected 0\n", vp
.dwX
);
3098 ok(vp
.dwY
== 0, "vp.dwY is %u, expected 0\n", vp
.dwY
);
3099 ok(vp
.dwWidth
== 64, "vp.dwWidth is %u, expected 64\n", vp
.dwWidth
);
3100 ok(vp
.dwHeight
== 64, "vp.dwHeight is %u, expected 64\n", vp
.dwHeight
);
3101 ok(vp
.dvMinZ
== 0.0, "vp.dvMinZ is %f, expected 0.0\n", vp
.dvMinZ
);
3102 ok(vp
.dvMaxZ
== 1.0, "vp.dvMaxZ is %f, expected 1.0\n", vp
.dvMaxZ
);
3104 hr
= IDirect3DDevice7_EndStateBlock(lpD3DDevice
, &stateblock
);
3105 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndStateblock failed, hr=0x%08x\n", hr
);
3107 memset(&vp
, 0xff, sizeof(vp
));
3108 hr
= IDirect3DDevice7_GetViewport(lpD3DDevice
, &vp
);
3109 ok(hr
== D3D_OK
, "IDirect3DDevice7_GetViewport failed, hr=0x%08x\n", hr
);
3110 ok(vp
.dwX
== 0, "vp.dwX is %u, expected 0\n", vp
.dwX
);
3111 ok(vp
.dwY
== 0, "vp.dwY is %u, expected 0\n", vp
.dwY
);
3112 ok(vp
.dwWidth
== 64, "vp.dwWidth is %u, expected 64\n", vp
.dwWidth
);
3113 ok(vp
.dwHeight
== 64, "vp.dwHeight is %u, expected 64\n", vp
.dwHeight
);
3114 ok(vp
.dvMinZ
== 0.0, "vp.dvMinZ is %f, expected 0.0\n", vp
.dvMinZ
);
3115 ok(vp
.dvMaxZ
== 1.0, "vp.dvMaxZ is %f, expected 1.0\n", vp
.dvMaxZ
);
3117 hr
= IDirect3DDevice7_DeleteStateBlock(lpD3DDevice
, stateblock
);
3118 ok(hr
== D3D_OK
, "IDirect3DDevice7_DeleteStateblock failed, hr=0x%08x\n", hr
);
3120 memset(&vp
, 0, sizeof(vp
));
3127 hr
= IDirect3DDevice7_SetViewport(lpD3DDevice
, &vp
);
3128 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetViewport failed, hr=0x%08x\n", hr
);
3130 IDirectDrawSurface7_Release(oldrt
);
3131 IDirectDrawSurface7_Release(newrt
);
3132 IDirectDrawSurface7_Release(failrt
);
3133 IDirectDrawSurface7_Release(failrt
);
3136 static void VertexBufferLockRest(void)
3138 D3DVERTEXBUFFERDESC desc
;
3139 IDirect3DVertexBuffer7
*buffer
;
3146 const char *debug_string
;
3151 {0, "(none)", D3D_OK
},
3152 {DDLOCK_WAIT
, "DDLOCK_WAIT", D3D_OK
},
3153 {DDLOCK_EVENT
, "DDLOCK_EVENT", D3D_OK
},
3154 {DDLOCK_READONLY
, "DDLOCK_READONLY", D3D_OK
},
3155 {DDLOCK_WRITEONLY
, "DDLOCK_WRITEONLY", D3D_OK
},
3156 {DDLOCK_NOSYSLOCK
, "DDLOCK_NOSYSLOCK", D3D_OK
},
3157 {DDLOCK_NOOVERWRITE
, "DDLOCK_NOOVERWRITE", D3D_OK
},
3158 {DDLOCK_DISCARDCONTENTS
, "DDLOCK_DISCARDCONTENTS", D3D_OK
},
3160 {DDLOCK_READONLY
| DDLOCK_WRITEONLY
, "DDLOCK_READONLY | DDLOCK_WRITEONLY", D3D_OK
},
3161 {DDLOCK_READONLY
| DDLOCK_DISCARDCONTENTS
, "DDLOCK_READONLY | DDLOCK_DISCARDCONTENTS", D3D_OK
},
3162 {0xdeadbeef, "0xdeadbeef", D3D_OK
},
3165 memset(&desc
, 0 , sizeof(desc
));
3166 desc
.dwSize
= sizeof(desc
);
3168 desc
.dwFVF
= D3DFVF_XYZ
;
3169 desc
.dwNumVertices
= 64;
3170 hr
= IDirect3D7_CreateVertexBuffer(lpD3D
, &desc
, &buffer
, 0);
3171 ok(hr
== D3D_OK
, "IDirect3D7_CreateVertexBuffer failed, 0x%08x\n", hr
);
3173 for(i
= 0; i
< (sizeof(test_data
) / sizeof(*test_data
)); i
++)
3175 hr
= IDirect3DVertexBuffer7_Lock(buffer
, test_data
[i
].flags
, &data
, NULL
);
3176 ok(hr
== test_data
[i
].result
, "Lock flags %s returned 0x%08x, expected 0x%08x\n",
3177 test_data
[i
].debug_string
, hr
, test_data
[i
].result
);
3180 ok(data
!= NULL
, "The data pointer returned by Lock is NULL\n");
3181 hr
= IDirect3DVertexBuffer7_Unlock(buffer
);
3182 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer7_Unlock failed, 0x%08x\n", hr
);
3186 IDirect3DVertexBuffer7_Release(buffer
);
3189 static void FindDevice(void)
3197 {&IID_IDirect3DRampDevice
, 1},
3198 {&IID_IDirect3DRGBDevice
},
3201 static const GUID
*nonexistent_deviceGUIDs
[] = {&IID_IDirect3DMMXDevice
,
3202 &IID_IDirect3DRefDevice
,
3203 &IID_IDirect3DTnLHalDevice
,
3204 &IID_IDirect3DNullDevice
};
3206 D3DFINDDEVICESEARCH search
= {0};
3207 D3DFINDDEVICERESULT result
= {0};
3208 IDirect3DDevice
*d3dhal
;
3212 /* Test invalid parameters. */
3213 hr
= IDirect3D_FindDevice(Direct3D1
, NULL
, NULL
);
3214 ok(hr
== DDERR_INVALIDPARAMS
,
3215 "Expected IDirect3D1::FindDevice to return DDERR_INVALIDPARAMS, got 0x%08x\n", hr
);
3217 hr
= IDirect3D_FindDevice(Direct3D1
, NULL
, &result
);
3218 ok(hr
== DDERR_INVALIDPARAMS
,
3219 "Expected IDirect3D1::FindDevice to return DDERR_INVALIDPARAMS, got 0x%08x\n", hr
);
3221 hr
= IDirect3D_FindDevice(Direct3D1
, &search
, NULL
);
3222 ok(hr
== DDERR_INVALIDPARAMS
,
3223 "Expected IDirect3D1::FindDevice to return DDERR_INVALIDPARAMS, got 0x%08x\n", hr
);
3228 hr
= IDirect3D_FindDevice(Direct3D1
, &search
, &result
);
3229 ok(hr
== DDERR_INVALIDPARAMS
,
3230 "Expected IDirect3D1::FindDevice to return DDERR_INVALIDPARAMS, got 0x%08x\n", hr
);
3232 search
.dwSize
= sizeof(search
) + 1;
3233 result
.dwSize
= sizeof(result
) + 1;
3235 hr
= IDirect3D_FindDevice(Direct3D1
, &search
, &result
);
3236 ok(hr
== DDERR_INVALIDPARAMS
,
3237 "Expected IDirect3D1::FindDevice to return DDERR_INVALIDPARAMS, got 0x%08x\n", hr
);
3239 /* Specifying no flags is permitted. */
3240 search
.dwSize
= sizeof(search
);
3242 result
.dwSize
= sizeof(result
);
3244 hr
= IDirect3D_FindDevice(Direct3D1
, &search
, &result
);
3246 "Expected IDirect3D1::FindDevice to return D3D_OK, got 0x%08x\n", hr
);
3248 /* Try an arbitrary non-device GUID. */
3249 search
.dwSize
= sizeof(search
);
3250 search
.dwFlags
= D3DFDS_GUID
;
3251 search
.guid
= IID_IDirect3D
;
3252 result
.dwSize
= sizeof(result
);
3254 hr
= IDirect3D_FindDevice(Direct3D1
, &search
, &result
);
3255 ok(hr
== DDERR_NOTFOUND
,
3256 "Expected IDirect3D1::FindDevice to return DDERR_NOTFOUND, got 0x%08x\n", hr
);
3258 /* These GUIDs appear to be never present. */
3259 for (i
= 0; i
< sizeof(nonexistent_deviceGUIDs
)/sizeof(nonexistent_deviceGUIDs
[0]); i
++)
3261 search
.dwSize
= sizeof(search
);
3262 search
.dwFlags
= D3DFDS_GUID
;
3263 search
.guid
= *nonexistent_deviceGUIDs
[i
];
3264 result
.dwSize
= sizeof(result
);
3266 hr
= IDirect3D_FindDevice(Direct3D1
, &search
, &result
);
3267 ok(hr
== DDERR_NOTFOUND
,
3268 "[%d] Expected IDirect3D1::FindDevice to return DDERR_NOTFOUND, got 0x%08x\n", i
, hr
);
3271 /* The HAL device can only be enumerated if hardware acceleration is present. */
3272 search
.dwSize
= sizeof(search
);
3273 search
.dwFlags
= D3DFDS_GUID
;
3274 search
.guid
= IID_IDirect3DHALDevice
;
3275 result
.dwSize
= sizeof(result
);
3277 hr
= IDirect3D_FindDevice(Direct3D1
, &search
, &result
);
3278 trace("IDirect3D::FindDevice returned 0x%08x for the HAL device GUID\n", hr
);
3281 hr
= IDirectDrawSurface_QueryInterface(Surface1
, &IID_IDirect3DHALDevice
, (void **)&d3dhal
);
3282 /* Currently Wine only supports the creation of one Direct3D device
3283 * for a given DirectDraw instance. */
3284 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPIXELFORMAT
) /* XP/Win2003 Wow64 on VMware */,
3285 "Expected IDirectDrawSurface::QueryInterface to succeed, got 0x%08x\n", hr
);
3288 IDirect3DDevice_Release(d3dhal
);
3292 hr
= IDirectDrawSurface_QueryInterface(Surface1
, &IID_IDirect3DHALDevice
, (void **)&d3dhal
);
3293 ok(FAILED(hr
), "Expected IDirectDrawSurface::QueryInterface to fail, got 0x%08x\n", hr
);
3296 IDirect3DDevice_Release(d3dhal
);
3299 /* These GUIDs appear to be always present. */
3300 for (i
= 0; i
< sizeof(deviceGUIDs
)/sizeof(deviceGUIDs
[0]); i
++)
3302 search
.dwSize
= sizeof(search
);
3303 search
.dwFlags
= D3DFDS_GUID
;
3304 search
.guid
= *deviceGUIDs
[i
].guid
;
3305 result
.dwSize
= sizeof(result
);
3307 hr
= IDirect3D_FindDevice(Direct3D1
, &search
, &result
);
3309 if (deviceGUIDs
[i
].todo
)
3313 "[%d] Expected IDirect3D1::FindDevice to return D3D_OK, got 0x%08x\n", i
, hr
);
3318 "[%d] Expected IDirect3D1::FindDevice to return D3D_OK, got 0x%08x\n", i
, hr
);
3322 /* Curiously the color model criteria seem to be ignored. */
3323 search
.dwSize
= sizeof(search
);
3324 search
.dwFlags
= D3DFDS_COLORMODEL
;
3325 search
.dcmColorModel
= 0xdeadbeef;
3326 result
.dwSize
= sizeof(result
);
3328 hr
= IDirect3D_FindDevice(Direct3D1
, &search
, &result
);
3331 "Expected IDirect3D1::FindDevice to return D3D_OK, got 0x%08x\n", hr
);
3334 static void BackBuffer3DCreateSurfaceTest(void)
3337 DDSURFACEDESC created_ddsd
;
3338 DDSURFACEDESC2 ddsd2
;
3339 IDirectDrawSurface
*surf
;
3340 IDirectDrawSurface4
*surf4
;
3341 IDirectDrawSurface7
*surf7
;
3347 IDirect3DDevice
*d3dhal
;
3349 const DWORD caps
= DDSCAPS_BACKBUFFER
| DDSCAPS_3DDEVICE
;
3350 const DWORD expected_caps
= DDSCAPS_BACKBUFFER
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
;
3352 memset(&ddcaps
, 0, sizeof(ddcaps
));
3353 ddcaps
.dwSize
= sizeof(DDCAPS
);
3354 hr
= IDirectDraw_GetCaps(DirectDraw1
, &ddcaps
, NULL
);
3355 ok(SUCCEEDED(hr
), "DirectDraw_GetCaps failed: 0x%08x\n", hr
);
3356 if (!(ddcaps
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
))
3358 skip("DDraw reported no VIDEOMEMORY cap. Broken video driver? Skipping surface caps tests.\n");
3362 memset(&ddsd
, 0, sizeof(ddsd
));
3363 ddsd
.dwSize
= sizeof(ddsd
);
3364 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
3367 ddsd
.ddsCaps
.dwCaps
= caps
;
3368 memset(&ddsd2
, 0, sizeof(ddsd2
));
3369 ddsd2
.dwSize
= sizeof(ddsd2
);
3370 ddsd2
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
3372 ddsd2
.dwHeight
= 64;
3373 ddsd2
.ddsCaps
.dwCaps
= caps
;
3374 memset(&created_ddsd
, 0, sizeof(created_ddsd
));
3375 created_ddsd
.dwSize
= sizeof(DDSURFACEDESC
);
3377 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &surf
, NULL
);
3378 ok(SUCCEEDED(hr
), "IDirectDraw_CreateSurface failed: 0x%08x\n", hr
);
3381 hr
= IDirectDrawSurface_GetSurfaceDesc(surf
, &created_ddsd
);
3382 ok(SUCCEEDED(hr
), "IDirectDraw_GetSurfaceDesc failed: 0x%08x\n", hr
);
3383 ok(created_ddsd
.ddsCaps
.dwCaps
== expected_caps
,
3384 "GetSurfaceDesc returned caps %x, expected %x\n", created_ddsd
.ddsCaps
.dwCaps
,
3387 hr
= IDirectDrawSurface_QueryInterface(surf
, &IID_IDirect3DHALDevice
, (void **)&d3dhal
);
3388 /* Currently Wine only supports the creation of one Direct3D device
3389 for a given DirectDraw instance. It has been created already
3390 in D3D1_createObjects() - IID_IDirect3DRGBDevice */
3391 todo_wine
ok(SUCCEEDED(hr
), "Expected IDirectDrawSurface::QueryInterface to succeed, got 0x%08x\n", hr
);
3394 IDirect3DDevice_Release(d3dhal
);
3396 IDirectDrawSurface_Release(surf
);
3399 hr
= IDirectDraw_QueryInterface(DirectDraw1
, &IID_IDirectDraw2
, (void **) &dd2
);
3400 ok(SUCCEEDED(hr
), "IDirectDraw_QueryInterface failed: 0x%08x\n", hr
);
3402 hr
= IDirectDraw2_CreateSurface(dd2
, &ddsd
, &surf
, NULL
);
3403 ok(hr
== DDERR_INVALIDCAPS
, "IDirectDraw2_CreateSurface didn't return %x08x, but %x08x\n",
3404 DDERR_INVALIDCAPS
, hr
);
3406 IDirectDraw2_Release(dd2
);
3408 hr
= IDirectDraw_QueryInterface(DirectDraw1
, &IID_IDirectDraw4
, (void **) &dd4
);
3409 ok(SUCCEEDED(hr
), "IDirectDraw_QueryInterface failed: 0x%08x\n", hr
);
3411 hr
= IDirectDraw4_CreateSurface(dd4
, &ddsd2
, &surf4
, NULL
);
3412 ok(hr
== DDERR_INVALIDCAPS
, "IDirectDraw4_CreateSurface didn't return %x08x, but %x08x\n",
3413 DDERR_INVALIDCAPS
, hr
);
3415 IDirectDraw4_Release(dd4
);
3417 hr
= IDirectDraw_QueryInterface(DirectDraw1
, &IID_IDirectDraw7
, (void **) &dd7
);
3418 ok(SUCCEEDED(hr
), "IDirectDraw_QueryInterface failed: 0x%08x\n", hr
);
3420 hr
= IDirectDraw7_CreateSurface(dd7
, &ddsd2
, &surf7
, NULL
);
3421 ok(hr
== DDERR_INVALIDCAPS
, "IDirectDraw7_CreateSurface didn't return %x08x, but %x08x\n",
3422 DDERR_INVALIDCAPS
, hr
);
3424 IDirectDraw7_Release(dd7
);
3427 static void BackBuffer3DAttachmentTest(void)
3430 IDirectDrawSurface
*surface1
, *surface2
, *surface3
, *surface4
;
3432 HWND window
= CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
3434 hr
= IDirectDraw_SetCooperativeLevel(DirectDraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3435 ok(hr
== DD_OK
, "SetCooperativeLevel returned %08x\n", hr
);
3437 /* Perform attachment tests on a back-buffer */
3438 memset(&ddsd
, 0, sizeof(ddsd
));
3439 ddsd
.dwSize
= sizeof(ddsd
);
3440 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
3441 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_BACKBUFFER
| DDSCAPS_3DDEVICE
;
3442 ddsd
.dwWidth
= GetSystemMetrics(SM_CXSCREEN
);
3443 ddsd
.dwHeight
= GetSystemMetrics(SM_CYSCREEN
);
3444 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &surface2
, NULL
);
3445 ok(SUCCEEDED(hr
), "CreateSurface returned: %x\n",hr
);
3447 if (surface2
!= NULL
)
3449 /* Try a single primary and a two back buffers */
3450 memset(&ddsd
, 0, sizeof(ddsd
));
3451 ddsd
.dwSize
= sizeof(ddsd
);
3452 ddsd
.dwFlags
= DDSD_CAPS
;
3453 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3454 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &surface1
, NULL
);
3455 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
3457 memset(&ddsd
, 0, sizeof(ddsd
));
3458 ddsd
.dwSize
= sizeof(ddsd
);
3459 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
3460 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_BACKBUFFER
| DDSCAPS_3DDEVICE
;
3461 ddsd
.dwWidth
= GetSystemMetrics(SM_CXSCREEN
);
3462 ddsd
.dwHeight
= GetSystemMetrics(SM_CYSCREEN
);
3463 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &surface3
, NULL
);
3464 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
3466 /* This one has a different size */
3467 memset(&ddsd
, 0, sizeof(ddsd
));
3468 ddsd
.dwSize
= sizeof(ddsd
);
3469 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
3470 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_BACKBUFFER
| DDSCAPS_3DDEVICE
;
3472 ddsd
.dwHeight
= 128;
3473 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &surface4
, NULL
);
3474 ok(hr
==DD_OK
,"CreateSurface returned: %x\n",hr
);
3476 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
3477 todo_wine
ok(hr
== DD_OK
|| broken(hr
== DDERR_CANNOTATTACHSURFACE
),
3478 "Attaching a back buffer to a front buffer returned %08x\n", hr
);
3481 /* Try the reverse without detaching first */
3482 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
3483 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Attaching an attached surface to its attachee returned %08x\n", hr
);
3484 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
3485 ok(hr
== DD_OK
, "DeleteAttachedSurface failed with %08x\n", hr
);
3487 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
3488 todo_wine
ok(hr
== DD_OK
|| broken(hr
== DDERR_CANNOTATTACHSURFACE
),
3489 "Attaching a front buffer to a back buffer returned %08x\n", hr
);
3492 /* Try to detach reversed */
3493 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
3494 ok(hr
== DDERR_CANNOTDETACHSURFACE
, "DeleteAttachedSurface returned %08x\n", hr
);
3495 /* Now the proper detach */
3496 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface1
);
3497 ok(hr
== DD_OK
, "DeleteAttachedSurface failed with %08x\n", hr
);
3499 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface3
);
3500 todo_wine
ok(hr
== DD_OK
|| broken(hr
== DDERR_CANNOTATTACHSURFACE
),
3501 "Attaching a back buffer to another back buffer returned %08x\n", hr
);
3504 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface3
);
3505 ok(hr
== DD_OK
, "DeleteAttachedSurface failed with %08x\n", hr
);
3507 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
);
3508 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a back buffer to a front buffer of different size returned %08x\n", hr
);
3509 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
3510 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Attaching a front buffer to a back buffer of different size returned %08x\n", hr
);
3512 IDirectDrawSurface_Release(surface4
);
3513 IDirectDrawSurface_Release(surface3
);
3514 IDirectDrawSurface_Release(surface2
);
3515 IDirectDrawSurface_Release(surface1
);
3518 hr
=IDirectDraw_SetCooperativeLevel(DirectDraw1
, NULL
, DDSCL_NORMAL
);
3519 ok(hr
== DD_OK
, "SetCooperativeLevel returned %08x\n", hr
);
3521 DestroyWindow(window
);
3524 static void dump_format(const DDPIXELFORMAT
*fmt
)
3526 trace("dwFlags %08x, FourCC %08x, dwZBufferBitDepth %u, stencil %08x\n", fmt
->dwFlags
, fmt
->dwFourCC
,
3527 U1(*fmt
).dwZBufferBitDepth
, U2(*fmt
).dwStencilBitDepth
);
3528 trace("dwZBitMask %08x, dwStencilBitMask %08x, dwRGBZBitMask %08x\n", U3(*fmt
).dwZBitMask
,
3529 U4(*fmt
).dwStencilBitMask
, U5(*fmt
).dwRGBZBitMask
);
3532 static HRESULT WINAPI
enum_z_fmt_cb(DDPIXELFORMAT
*fmt
, void *ctx
)
3534 static const DDPIXELFORMAT formats
[] =
3537 sizeof(DDPIXELFORMAT
), DDPF_ZBUFFER
, 0,
3538 {16}, {0}, {0x0000ffff}, {0x00000000}, {0x00000000}
3541 sizeof(DDPIXELFORMAT
), DDPF_ZBUFFER
, 0,
3542 {32}, {0}, {0xffffff00}, {0x00000000}, {0x00000000}
3545 sizeof(DDPIXELFORMAT
), DDPF_ZBUFFER
| DDPF_STENCILBUFFER
, 0,
3546 {32}, {8}, {0xffffff00}, {0x000000ff}, {0x00000000}
3549 sizeof(DDPIXELFORMAT
), DDPF_ZBUFFER
, 0,
3550 {32}, {0}, {0x00ffffff}, {0x00000000}, {0x00000000}
3553 sizeof(DDPIXELFORMAT
), DDPF_ZBUFFER
| DDPF_STENCILBUFFER
, 0,
3554 {32}, {8}, {0x00ffffff}, {0xff000000}, {0x00000000}
3557 sizeof(DDPIXELFORMAT
), DDPF_ZBUFFER
, 0,
3558 {24}, {0}, {0x00ffffff}, {0x00000000}, {0x00000000}
3561 sizeof(DDPIXELFORMAT
), DDPF_ZBUFFER
, 0,
3562 {32}, {0}, {0xffffffff}, {0x00000000}, {0x00000000}
3565 unsigned int *count
= ctx
, i
, expected_pitch
;
3566 DDSURFACEDESC2 ddsd
;
3567 IDirectDrawSurface7
*surface
;
3571 memset(&ddsd
, 0, sizeof(ddsd
));
3572 ddsd
.dwSize
= sizeof(ddsd
);
3573 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
3574 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
3575 U4(ddsd
).ddpfPixelFormat
= *fmt
;
3576 ddsd
.dwWidth
= 1024;
3577 ddsd
.dwHeight
= 1024;
3578 hr
= IDirectDraw7_CreateSurface(lpDD
, &ddsd
, &surface
, NULL
);
3579 ok(SUCCEEDED(hr
), "IDirectDraw7_CreateSurface failed, hr %#x.\n", hr
);
3580 memset(&ddsd
, 0, sizeof(ddsd
));
3581 ddsd
.dwSize
= sizeof(ddsd
);
3582 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
3583 ok(SUCCEEDED(hr
), "IDirectDrawSurface7_GetSurfaceDesc failed, hr %#x.\n", hr
);
3584 IDirectDrawSurface7_Release(surface
);
3586 ok(ddsd
.dwFlags
& DDSD_PIXELFORMAT
, "DDSD_PIXELFORMAT is not set\n");
3587 ok(!(ddsd
.dwFlags
& DDSD_ZBUFFERBITDEPTH
), "DDSD_ZBUFFERBITDEPTH is set\n");
3589 /* 24 bit unpadded depth buffers are actually padded(Geforce 9600, Win7,
3590 * Radeon 9000M WinXP) */
3591 if (U1(*fmt
).dwZBufferBitDepth
== 24) expected_pitch
= ddsd
.dwWidth
* 4;
3592 else expected_pitch
= ddsd
.dwWidth
* U1(*fmt
).dwZBufferBitDepth
/ 8;
3594 /* Some formats(16 bit depth without stencil) return pitch 0
3596 * The Radeon X1600 Catalyst 10.2 Windows XP driver returns an otherwise sane
3597 * pitch with an extra 128 bytes, regardless of the format and width */
3598 if (U1(ddsd
).lPitch
!= 0 && U1(ddsd
).lPitch
!= expected_pitch
3599 && !broken(U1(ddsd
).lPitch
== expected_pitch
+ 128))
3601 ok(0, "Z buffer pitch is %u, expected %u\n", U1(ddsd
).lPitch
, expected_pitch
);
3605 for (i
= 0; i
< (sizeof(formats
)/sizeof(*formats
)); i
++)
3607 if (memcmp(&formats
[i
], fmt
, fmt
->dwSize
) == 0) return DDENUMRET_OK
;
3610 ok(0, "Unexpected Z format enumerated\n");
3613 return DDENUMRET_OK
;
3616 static void z_format_test(void)
3618 unsigned int count
= 0;
3621 hr
= IDirect3D7_EnumZBufferFormats(lpD3D
, &IID_IDirect3DHALDevice
, enum_z_fmt_cb
, &count
);
3622 if (hr
== DDERR_NOZBUFFERHW
)
3624 skip("Z buffers not supported, skipping Z buffer format test\n");
3628 ok(SUCCEEDED(hr
), "IDirect3D7_EnumZBufferFormats failed, hr %#x.\n", hr
);
3629 ok(count
, "Expected at least one supported Z Buffer format\n");
3632 static void test_get_caps1(void)
3634 D3DDEVICEDESC hw_caps
, hel_caps
;
3638 memset(&hw_caps
, 0, sizeof(hw_caps
));
3639 hw_caps
.dwSize
= sizeof(hw_caps
);
3640 hw_caps
.dwFlags
= 0xdeadbeef;
3641 memset(&hel_caps
, 0, sizeof(hel_caps
));
3642 hel_caps
.dwSize
= sizeof(hel_caps
);
3643 hel_caps
.dwFlags
= 0xdeadc0de;
3646 hr
= IDirect3DDevice_GetCaps(Direct3DDevice1
, &hw_caps
, NULL
);
3647 ok(hr
== DDERR_INVALIDPARAMS
, "GetCaps with NULL hel caps returned hr %#x, expected INVALIDPARAMS.\n", hr
);
3648 ok(hw_caps
.dwFlags
== 0xdeadbeef, "hw_caps.dwFlags was modified: %#x.\n", hw_caps
.dwFlags
);
3649 hr
= IDirect3DDevice_GetCaps(Direct3DDevice1
, NULL
, &hel_caps
);
3650 ok(hr
== DDERR_INVALIDPARAMS
, "GetCaps with NULL hw caps returned hr %#x, expected INVALIDPARAMS.\n", hr
);
3651 ok(hel_caps
.dwFlags
== 0xdeadc0de, "hel_caps.dwFlags was modified: %#x.\n", hel_caps
.dwFlags
);
3653 /* Successful call: Both are modified */
3654 hr
= IDirect3DDevice_GetCaps(Direct3DDevice1
, &hw_caps
, &hel_caps
);
3655 ok(hr
== D3D_OK
, "GetCaps with correct size returned hr %#x, expected D3D_OK.\n", hr
);
3656 ok(hw_caps
.dwFlags
!= 0xdeadbeef, "hw_caps.dwFlags was not modified: %#x.\n", hw_caps
.dwFlags
);
3657 ok(hel_caps
.dwFlags
!= 0xdeadc0de, "hel_caps.dwFlags was not modified: %#x.\n", hel_caps
.dwFlags
);
3659 memset(&hw_caps
, 0, sizeof(hw_caps
));
3660 hw_caps
.dwSize
= sizeof(hw_caps
);
3661 hw_caps
.dwFlags
= 0xdeadbeef;
3662 memset(&hel_caps
, 0, sizeof(hel_caps
));
3663 /* Keep dwSize at 0 */
3664 hel_caps
.dwFlags
= 0xdeadc0de;
3666 /* If one is invalid the call fails */
3667 hr
= IDirect3DDevice_GetCaps(Direct3DDevice1
, &hw_caps
, &hel_caps
);
3668 ok(hr
== DDERR_INVALIDPARAMS
, "GetCaps with invalid hel_caps size returned hr %#x, expected INVALIDPARAMS.\n", hr
);
3669 ok(hw_caps
.dwFlags
== 0xdeadbeef, "hw_caps.dwFlags was modified: %#x.\n", hw_caps
.dwFlags
);
3670 ok(hel_caps
.dwFlags
== 0xdeadc0de, "hel_caps.dwFlags was modified: %#x.\n", hel_caps
.dwFlags
);
3671 hel_caps
.dwSize
= sizeof(hel_caps
);
3672 hw_caps
.dwSize
= sizeof(hw_caps
) + 1;
3673 hr
= IDirect3DDevice_GetCaps(Direct3DDevice1
, &hw_caps
, &hel_caps
);
3674 ok(hr
== DDERR_INVALIDPARAMS
, "GetCaps with invalid hw_caps size returned hr %#x, expected INVALIDPARAMS.\n", hr
);
3675 ok(hw_caps
.dwFlags
== 0xdeadbeef, "hw_caps.dwFlags was modified: %#x.\n", hw_caps
.dwFlags
);
3676 ok(hel_caps
.dwFlags
== 0xdeadc0de, "hel_caps.dwFlags was modified: %#x.\n", hel_caps
.dwFlags
);
3678 for (i
= 0; i
< 1024; i
++)
3680 memset(&hw_caps
, 0xfe, sizeof(hw_caps
));
3681 memset(&hel_caps
, 0xfe, sizeof(hel_caps
));
3682 hw_caps
.dwSize
= hel_caps
.dwSize
= i
;
3683 hr
= IDirect3DDevice_GetCaps(Direct3DDevice1
, &hw_caps
, &hel_caps
);
3686 /* D3DDEVICEDESCSIZE in old sdk versions */
3687 case FIELD_OFFSET(D3DDEVICEDESC
, dwMinTextureWidth
): /* 172, DirectX 3, IDirect3DDevice1 */
3688 ok(hw_caps
.dwMinTextureWidth
== 0xfefefefe, "hw_caps.dwMinTextureWidth was modified: %#x.\n",
3689 hw_caps
.dwMinTextureWidth
);
3690 ok(hel_caps
.dwMinTextureWidth
== 0xfefefefe, "hel_caps.dwMinTextureWidth was modified: %#x.\n",
3691 hel_caps
.dwMinTextureWidth
);
3693 case FIELD_OFFSET(D3DDEVICEDESC
, dwMaxTextureRepeat
): /* 204, DirectX 5, IDirect3DDevice2 */
3694 ok(hw_caps
.dwMaxTextureRepeat
== 0xfefefefe, "hw_caps.dwMaxTextureRepeat was modified: %#x.\n",
3695 hw_caps
.dwMaxTextureRepeat
);
3696 ok(hel_caps
.dwMaxTextureRepeat
== 0xfefefefe, "hel_caps.dwMaxTextureRepeat was modified: %#x.\n",
3697 hel_caps
.dwMaxTextureRepeat
);
3699 case sizeof(D3DDEVICEDESC
): /* 252, DirectX 6, IDirect3DDevice3 */
3700 ok(hr
== D3D_OK
, "GetCaps with size %u returned hr %#x, expected D3D_OK.\n", i
, hr
);
3704 ok(hr
== DDERR_INVALIDPARAMS
,
3705 "GetCaps with size %u returned hr %#x, expected DDERR_INVALIDPARAMS.\n", i
, hr
);
3710 /* Different valid sizes are OK */
3711 hw_caps
.dwSize
= 172;
3712 hel_caps
.dwSize
= sizeof(D3DDEVICEDESC
);
3713 hr
= IDirect3DDevice_GetCaps(Direct3DDevice1
, &hw_caps
, &hel_caps
);
3714 ok(hr
== D3D_OK
, "GetCaps with different sizes returned hr %#x, expected D3D_OK.\n", hr
);
3717 static void test_get_caps7(void)
3720 D3DDEVICEDESC7 desc
;
3722 hr
= IDirect3DDevice7_GetCaps(lpD3DDevice
, NULL
);
3723 ok(hr
== DDERR_INVALIDPARAMS
, "IDirect3DDevice7::GetCaps(NULL) returned hr %#x, expected INVALIDPARAMS.\n", hr
);
3725 memset(&desc
, 0, sizeof(desc
));
3726 hr
= IDirect3DDevice7_GetCaps(lpD3DDevice
, &desc
);
3727 ok(hr
== D3D_OK
, "IDirect3DDevice7::GetCaps(non-NULL) returned hr %#x, expected D3D_OK.\n", hr
);
3729 /* There's no dwSize in D3DDEVICEDESC7 */
3732 struct d3d2_test_context
3736 IDirectDrawSurface
*surface
;
3737 IDirect3DDevice2
*device
;
3738 IDirect3DViewport2
*viewport
;
3741 static void d3d2_release_objects(struct d3d2_test_context
*context
)
3746 if (context
->viewport
)
3748 hr
= IDirect3DDevice2_DeleteViewport(context
->device
, context
->viewport
);
3749 ok(hr
== D3D_OK
, "DeleteViewport returned %08x.\n", hr
);
3750 ref
= IDirect3DViewport2_Release(context
->viewport
);
3751 ok(ref
== 0, "Viewport has reference count %d, expected 0.\n", ref
);
3753 if (context
->device
)
3755 ref
= IDirect3DDevice2_Release(context
->device
);
3756 ok(ref
== 0, "Device has reference count %d, expected 0.\n", ref
);
3758 if (context
->surface
)
3760 ref
= IDirectDrawSurface_Release(context
->surface
);
3761 ok(ref
== 0, "Surface has reference count %d, expected 0.\n", ref
);
3765 ref
= IDirect3D2_Release(context
->d3d
);
3766 ok(ref
== 1, "IDirect3D2 has reference count %d, expected 1.\n", ref
);
3770 ref
= IDirectDraw_Release(context
->ddraw
);
3771 ok(ref
== 0, "DDraw has reference count %d, expected 0.\n", ref
);
3775 static BOOL
d3d2_create_objects(struct d3d2_test_context
*context
)
3779 D3DVIEWPORT vp_data
;
3781 memset(context
, 0, sizeof(*context
));
3783 hr
= DirectDrawCreate(NULL
, &context
->ddraw
, NULL
);
3784 ok(hr
== DD_OK
|| hr
== DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreate failed: %08x.\n", hr
);
3785 if (!context
->ddraw
) goto error
;
3787 hr
= IDirectDraw_SetCooperativeLevel(context
->ddraw
, NULL
, DDSCL_NORMAL
);
3788 ok(hr
== DD_OK
, "SetCooperativeLevel failed: %08x.\n", hr
);
3789 if (FAILED(hr
)) goto error
;
3791 hr
= IDirectDraw_QueryInterface(context
->ddraw
, &IID_IDirect3D2
, (void**) &context
->d3d
);
3792 ok(hr
== DD_OK
|| hr
== E_NOINTERFACE
, "QueryInterface failed: %08x.\n", hr
);
3793 if (!context
->d3d
) goto error
;
3795 memset(&ddsd
, 0, sizeof(ddsd
));
3796 ddsd
.dwSize
= sizeof(ddsd
);
3797 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
3798 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
3800 ddsd
.dwHeight
= 256;
3801 IDirectDraw_CreateSurface(context
->ddraw
, &ddsd
, &context
->surface
, NULL
);
3802 if (!context
->surface
)
3804 skip("DDSCAPS_3DDEVICE surface not available.\n");
3808 hr
= IDirect3D2_CreateDevice(context
->d3d
, &IID_IDirect3DHALDevice
, context
->surface
, &context
->device
);
3809 ok(hr
== D3D_OK
|| hr
== E_OUTOFMEMORY
|| hr
== E_NOINTERFACE
, "CreateDevice failed: %08x.\n", hr
);
3810 if (!context
->device
) goto error
;
3812 hr
= IDirect3D2_CreateViewport(context
->d3d
, &context
->viewport
, NULL
);
3813 ok(hr
== D3D_OK
, "CreateViewport failed: %08x.\n", hr
);
3814 if (!context
->viewport
) goto error
;
3816 hr
= IDirect3DDevice2_AddViewport(context
->device
, context
->viewport
);
3817 ok(hr
== D3D_OK
, "AddViewport returned %08x.\n", hr
);
3818 vp_data
.dwSize
= sizeof(vp_data
);
3821 vp_data
.dwWidth
= 256;
3822 vp_data
.dwHeight
= 256;
3823 vp_data
.dvScaleX
= 1;
3824 vp_data
.dvScaleY
= 1;
3825 vp_data
.dvMaxX
= 256;
3826 vp_data
.dvMaxY
= 256;
3829 hr
= IDirect3DViewport2_SetViewport(context
->viewport
, &vp_data
);
3830 ok(hr
== D3D_OK
, "SetViewport returned %08x.\n", hr
);
3835 d3d2_release_objects(context
);
3839 static void test_get_caps2(const struct d3d2_test_context
*context
)
3841 D3DDEVICEDESC hw_caps
, hel_caps
;
3845 memset(&hw_caps
, 0, sizeof(hw_caps
));
3846 hw_caps
.dwSize
= sizeof(hw_caps
);
3847 hw_caps
.dwFlags
= 0xdeadbeef;
3848 memset(&hel_caps
, 0, sizeof(hel_caps
));
3849 hel_caps
.dwSize
= sizeof(hel_caps
);
3850 hel_caps
.dwFlags
= 0xdeadc0de;
3853 hr
= IDirect3DDevice2_GetCaps(context
->device
, &hw_caps
, NULL
);
3854 ok(hr
== DDERR_INVALIDPARAMS
, "GetCaps with NULL hel caps returned hr %#x, expected INVALIDPARAMS.\n", hr
);
3855 ok(hw_caps
.dwFlags
== 0xdeadbeef, "hw_caps.dwFlags was modified: %#x.\n", hw_caps
.dwFlags
);
3856 hr
= IDirect3DDevice2_GetCaps(context
->device
, NULL
, &hel_caps
);
3857 ok(hr
== DDERR_INVALIDPARAMS
, "GetCaps with NULL hw caps returned hr %#x, expected INVALIDPARAMS.\n", hr
);
3858 ok(hel_caps
.dwFlags
== 0xdeadc0de, "hel_caps.dwFlags was modified: %#x.\n", hel_caps
.dwFlags
);
3860 /* Successful call: Both are modified */
3861 hr
= IDirect3DDevice2_GetCaps(context
->device
, &hw_caps
, &hel_caps
);
3862 ok(hr
== D3D_OK
, "GetCaps with correct size returned hr %#x, expected D3D_OK.\n", hr
);
3863 ok(hw_caps
.dwFlags
!= 0xdeadbeef, "hw_caps.dwFlags was not modified: %#x.\n", hw_caps
.dwFlags
);
3864 ok(hel_caps
.dwFlags
!= 0xdeadc0de, "hel_caps.dwFlags was not modified: %#x.\n", hel_caps
.dwFlags
);
3866 memset(&hw_caps
, 0, sizeof(hw_caps
));
3867 hw_caps
.dwSize
= sizeof(hw_caps
);
3868 hw_caps
.dwFlags
= 0xdeadbeef;
3869 memset(&hel_caps
, 0, sizeof(hel_caps
));
3870 /* Keep dwSize at 0 */
3871 hel_caps
.dwFlags
= 0xdeadc0de;
3873 /* If one is invalid the call fails */
3874 hr
= IDirect3DDevice2_GetCaps(context
->device
, &hw_caps
, &hel_caps
);
3875 ok(hr
== DDERR_INVALIDPARAMS
, "GetCaps with invalid hel_caps size returned hr %#x, expected INVALIDPARAMS.\n", hr
);
3876 ok(hw_caps
.dwFlags
== 0xdeadbeef, "hw_caps.dwFlags was modified: %#x.\n", hw_caps
.dwFlags
);
3877 ok(hel_caps
.dwFlags
== 0xdeadc0de, "hel_caps.dwFlags was modified: %#x.\n", hel_caps
.dwFlags
);
3878 hel_caps
.dwSize
= sizeof(hel_caps
);
3879 hw_caps
.dwSize
= sizeof(hw_caps
) + 1;
3880 hr
= IDirect3DDevice2_GetCaps(context
->device
, &hw_caps
, &hel_caps
);
3881 ok(hr
== DDERR_INVALIDPARAMS
, "GetCaps with invalid hw_caps size returned hr %#x, expected INVALIDPARAMS.\n", hr
);
3882 ok(hw_caps
.dwFlags
== 0xdeadbeef, "hw_caps.dwFlags was modified: %#x.\n", hw_caps
.dwFlags
);
3883 ok(hel_caps
.dwFlags
== 0xdeadc0de, "hel_caps.dwFlags was modified: %#x.\n", hel_caps
.dwFlags
);
3885 for (i
= 0; i
< 1024; i
++)
3887 memset(&hw_caps
, 0xfe, sizeof(hw_caps
));
3888 memset(&hel_caps
, 0xfe, sizeof(hel_caps
));
3889 hw_caps
.dwSize
= hel_caps
.dwSize
= i
;
3890 hr
= IDirect3DDevice2_GetCaps(context
->device
, &hw_caps
, &hel_caps
);
3893 /* D3DDEVICEDESCSIZE in old sdk versions */
3894 case FIELD_OFFSET(D3DDEVICEDESC
, dwMinTextureWidth
): /* 172, DirectX 3, IDirect3DDevice1 */
3895 ok(hw_caps
.dwMinTextureWidth
== 0xfefefefe, "dwMinTextureWidth was modified: %#x.\n",
3896 hw_caps
.dwMinTextureWidth
);
3897 ok(hel_caps
.dwMinTextureWidth
== 0xfefefefe, "dwMinTextureWidth was modified: %#x.\n",
3898 hel_caps
.dwMinTextureWidth
);
3900 case FIELD_OFFSET(D3DDEVICEDESC
, dwMaxTextureRepeat
): /* 204, DirectX 5, IDirect3DDevice2 */
3901 ok(hw_caps
.dwMaxTextureRepeat
== 0xfefefefe, "dwMaxTextureRepeat was modified: %#x.\n",
3902 hw_caps
.dwMaxTextureRepeat
);
3903 ok(hel_caps
.dwMaxTextureRepeat
== 0xfefefefe, "dwMaxTextureRepeat was modified: %#x.\n",
3904 hel_caps
.dwMaxTextureRepeat
);
3906 case sizeof(D3DDEVICEDESC
): /* 252, DirectX 6, IDirect3DDevice3 */
3907 ok(hr
== D3D_OK
, "GetCaps with size %u returned hr %#x, expected D3D_OK.\n", i
, hr
);
3911 ok(hr
== DDERR_INVALIDPARAMS
,
3912 "GetCaps with size %u returned hr %#x, expected DDERR_INVALIDPARAMS.\n", i
, hr
);
3917 /* Different valid sizes are OK */
3918 hw_caps
.dwSize
= 172;
3919 hel_caps
.dwSize
= sizeof(D3DDEVICEDESC
);
3920 hr
= IDirect3DDevice2_GetCaps(context
->device
, &hw_caps
, &hel_caps
);
3921 ok(hr
== D3D_OK
, "GetCaps with different sizes returned hr %#x, expected D3D_OK.\n", hr
);
3926 struct d3d2_test_context d3d2_context
;
3927 void (* const d3d2_tests
[])(const struct d3d2_test_context
*) =
3933 init_function_pointers();
3934 if(!pDirectDrawCreateEx
) {
3935 win_skip("function DirectDrawCreateEx not available\n");
3939 if(!CreateDirect3D()) {
3940 skip("Skipping d3d7 tests\n");
3947 D3D7EnumLifetimeTest();
3949 ComputeSphereVisibility();
3951 VertexBufferDescTest();
3952 D3D7_OldRenderStateTest();
3954 SetRenderTargetTest();
3955 VertexBufferLockRest();
3961 for (i
= 0; i
< (sizeof(d3d2_tests
) / sizeof(*d3d2_tests
)); i
++)
3963 if (!d3d2_create_objects(&d3d2_context
))
3965 ok(!i
, "Unexpected d3d2 initialization failure.\n");
3966 skip("Skipping d3d2 tests.\n");
3969 d3d2_tests
[i
](&d3d2_context
);
3970 d3d2_release_objects(&d3d2_context
);
3973 if (!D3D1_createObjects()) {
3974 skip("Skipping d3d1 tests\n");
3980 BackBuffer3DCreateSurfaceTest();
3981 BackBuffer3DAttachmentTest();
3983 D3D1_releaseObjects();