2 * Copyright (C) 2006 Vitaliy Margolen
3 * Copyright (C) 2006 Chris Robinson
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/test.h"
25 static INT screen_width;
26 static INT screen_height;
28 static IDirect3D8 *(WINAPI *pDirect3DCreate8)(UINT);
30 static BOOL (WINAPI *pGetCursorInfo)(PCURSORINFO);
32 static const DWORD simple_vs[] = {0xFFFE0101, /* vs_1_1 */
33 0x00000009, 0xC0010000, 0x90E40000, 0xA0E40000, /* dp4 oPos.x, v0, c0 */
34 0x00000009, 0xC0020000, 0x90E40000, 0xA0E40001, /* dp4 oPos.y, v0, c1 */
35 0x00000009, 0xC0040000, 0x90E40000, 0xA0E40002, /* dp4 oPos.z, v0, c2 */
36 0x00000009, 0xC0080000, 0x90E40000, 0xA0E40003, /* dp4 oPos.w, v0, c3 */
37 0x0000FFFF}; /* END */
38 static const DWORD simple_ps[] = {0xFFFF0101, /* ps_1_1 */
39 0x00000051, 0xA00F0001, 0x3F800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
40 0x00000042, 0xB00F0000, /* tex t0 */
41 0x00000008, 0x800F0000, 0xA0E40001, 0xA0E40000, /* dp3 r0, c1, c0 */
42 0x00000005, 0x800F0000, 0x90E40000, 0x80E40000, /* mul r0, v0, r0 */
43 0x00000005, 0x800F0000, 0xB0E40000, 0x80E40000, /* mul r0, t0, r0 */
44 0x0000FFFF}; /* END */
46 static int get_refcount(IUnknown *object)
48 IUnknown_AddRef( object );
49 return IUnknown_Release( object );
52 /* try to make sure pending X events have been processed before continuing */
53 static void flush_events(void)
57 int min_timeout = 100;
58 DWORD time = GetTickCount() + diff;
62 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
63 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
64 diff = time - GetTickCount();
68 static IDirect3DDevice8 *create_device(IDirect3D8 *d3d8, HWND device_window, HWND focus_window, BOOL windowed)
70 D3DPRESENT_PARAMETERS present_parameters = {0};
71 IDirect3DDevice8 *device;
73 present_parameters.Windowed = windowed;
74 present_parameters.hDeviceWindow = device_window;
75 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
76 present_parameters.BackBufferWidth = screen_width;
77 present_parameters.BackBufferHeight = screen_height;
78 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
79 present_parameters.EnableAutoDepthStencil = TRUE;
80 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
82 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
83 D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device))) return device;
85 present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
86 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
87 D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device))) return device;
89 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
90 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device))) return device;
95 static HRESULT reset_device(IDirect3DDevice8 *device, HWND device_window, BOOL windowed)
97 D3DPRESENT_PARAMETERS present_parameters = {0};
99 present_parameters.Windowed = windowed;
100 present_parameters.hDeviceWindow = device_window;
101 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
102 present_parameters.BackBufferWidth = screen_width;
103 present_parameters.BackBufferHeight = screen_height;
104 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
105 present_parameters.EnableAutoDepthStencil = TRUE;
106 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
108 return IDirect3DDevice8_Reset(device, &present_parameters);
111 #define CHECK_CALL(r,c,d,rc) \
113 int tmp1 = get_refcount( (IUnknown *)d ); \
115 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
117 trace("%s failed: %#08x\n", c, r); \
120 #define CHECK_RELEASE(obj,d,rc) \
122 int tmp1, rc_new = rc; \
123 IUnknown_Release( obj ); \
124 tmp1 = get_refcount( (IUnknown *)d ); \
125 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
128 #define CHECK_REFCOUNT(obj,rc) \
131 int count = get_refcount( (IUnknown *)obj ); \
132 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
135 #define CHECK_RELEASE_REFCOUNT(obj,rc) \
138 int count = IUnknown_Release( (IUnknown *)obj ); \
139 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
142 #define CHECK_ADDREF_REFCOUNT(obj,rc) \
145 int count = IUnknown_AddRef( (IUnknown *)obj ); \
146 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
149 #define CHECK_SURFACE_CONTAINER(obj,iid,expected) \
151 void *container_ptr = (void *)0x1337c0d3; \
152 hr = IDirect3DSurface8_GetContainer(obj, &iid, &container_ptr); \
153 ok(SUCCEEDED(hr) && container_ptr == expected, "GetContainer returned: hr %#08x, container_ptr %p. " \
154 "Expected hr %#08x, container_ptr %p\n", hr, container_ptr, S_OK, expected); \
155 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr); \
158 static void check_mipmap_levels(IDirect3DDevice8 *device, UINT width, UINT height, UINT count)
160 IDirect3DBaseTexture8* texture = NULL;
161 HRESULT hr = IDirect3DDevice8_CreateTexture( device, width, height, 0, 0,
162 D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, (IDirect3DTexture8**) &texture );
165 DWORD levels = IDirect3DBaseTexture8_GetLevelCount(texture);
166 ok(levels == count, "Invalid level count. Expected %d got %u\n", count, levels);
168 trace("CreateTexture failed: %#08x\n", hr);
170 if (texture) IUnknown_Release( texture );
173 static void test_mipmap_levels(void)
179 IDirect3D8 *pD3d = NULL;
180 IDirect3DDevice8 *pDevice = NULL;
181 D3DPRESENT_PARAMETERS d3dpp;
182 D3DDISPLAYMODE d3ddm;
184 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
185 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
186 hwnd = CreateWindow( "d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
187 ok(hwnd != NULL, "Failed to create window\n");
188 if (!pD3d || !hwnd) goto cleanup;
190 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
191 ZeroMemory( &d3dpp, sizeof(d3dpp) );
192 d3dpp.Windowed = TRUE;
193 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
194 d3dpp.BackBufferFormat = d3ddm.Format;
196 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
197 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
200 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
204 check_mipmap_levels(pDevice, 32, 32, 6);
205 check_mipmap_levels(pDevice, 256, 1, 9);
206 check_mipmap_levels(pDevice, 1, 256, 9);
207 check_mipmap_levels(pDevice, 1, 1, 1);
212 UINT refcount = IUnknown_Release( pDevice );
213 ok(!refcount, "Device has %u references left.\n", refcount);
215 if (pD3d) IUnknown_Release( pD3d );
216 DestroyWindow( hwnd );
219 static void test_swapchain(void)
223 IDirect3D8 *pD3d = NULL;
224 IDirect3DDevice8 *pDevice = NULL;
225 IDirect3DSwapChain8 *swapchain1 = NULL;
226 IDirect3DSwapChain8 *swapchain2 = NULL;
227 IDirect3DSwapChain8 *swapchain3 = NULL;
228 IDirect3DSurface8 *backbuffer = NULL;
229 D3DPRESENT_PARAMETERS d3dpp;
230 D3DDISPLAYMODE d3ddm;
232 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
233 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
234 hwnd = CreateWindow( "d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
235 ok(hwnd != NULL, "Failed to create window\n");
236 if (!pD3d || !hwnd) goto cleanup;
238 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
239 ZeroMemory( &d3dpp, sizeof(d3dpp) );
240 d3dpp.Windowed = TRUE;
241 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
242 d3dpp.BackBufferFormat = d3ddm.Format;
243 d3dpp.BackBufferCount = 0;
245 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
246 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
249 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
253 /* Check if the back buffer count was modified */
254 ok(d3dpp.BackBufferCount == 1, "The back buffer count in the presentparams struct is %d\n", d3dpp.BackBufferCount);
256 /* Create a bunch of swapchains */
257 d3dpp.BackBufferCount = 0;
258 hr = IDirect3DDevice8_CreateAdditionalSwapChain(pDevice, &d3dpp, &swapchain1);
259 ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr);
260 ok(d3dpp.BackBufferCount == 1, "The back buffer count in the presentparams struct is %d\n", d3dpp.BackBufferCount);
262 d3dpp.BackBufferCount = 1;
263 hr = IDirect3DDevice8_CreateAdditionalSwapChain(pDevice, &d3dpp, &swapchain2);
264 ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr);
266 d3dpp.BackBufferCount = 2;
267 hr = IDirect3DDevice8_CreateAdditionalSwapChain(pDevice, &d3dpp, &swapchain3);
268 ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr);
270 /* Swapchain 3, created with backbuffercount 2 */
271 backbuffer = (void *) 0xdeadbeef;
272 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 0, 0, &backbuffer);
273 ok(SUCCEEDED(hr), "Failed to get the 1st back buffer (%#08x)\n", hr);
274 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
275 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
277 backbuffer = (void *) 0xdeadbeef;
278 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 1, 0, &backbuffer);
279 ok(SUCCEEDED(hr), "Failed to get the 2nd back buffer (%#08x)\n", hr);
280 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
281 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
283 backbuffer = (void *) 0xdeadbeef;
284 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 2, 0, &backbuffer);
285 ok(hr == D3DERR_INVALIDCALL, "GetBackBuffer returned %#08x\n", hr);
286 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
287 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
289 backbuffer = (void *) 0xdeadbeef;
290 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 3, 0, &backbuffer);
291 ok(FAILED(hr), "Failed to get the back buffer (%#08x)\n", hr);
292 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
293 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
296 /* Check the back buffers of the swapchains */
297 /* Swapchain 1, created with backbuffercount 0 */
298 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain1, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
299 ok(SUCCEEDED(hr), "Failed to get the back buffer (%#08x)\n", hr);
300 ok(backbuffer != NULL, "The back buffer is NULL (%#08x)\n", hr);
301 if(backbuffer) IDirect3DSurface8_Release(backbuffer);
303 backbuffer = (void *) 0xdeadbeef;
304 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain1, 1, 0, &backbuffer);
305 ok(FAILED(hr), "Failed to get the back buffer (%#08x)\n", hr);
306 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
307 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
309 /* Swapchain 2 - created with backbuffercount 1 */
310 backbuffer = (void *) 0xdeadbeef;
311 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 0, 0, &backbuffer);
312 ok(SUCCEEDED(hr), "Failed to get the back buffer (%#08x)\n", hr);
313 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
314 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
316 backbuffer = (void *) 0xdeadbeef;
317 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 1, 0, &backbuffer);
318 ok(hr == D3DERR_INVALIDCALL, "GetBackBuffer returned %#08x\n", hr);
319 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
320 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
322 backbuffer = (void *) 0xdeadbeef;
323 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 2, 0, &backbuffer);
324 ok(FAILED(hr), "Failed to get the back buffer (%#08x)\n", hr);
325 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
326 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
329 if(swapchain1) IDirect3DSwapChain8_Release(swapchain1);
330 if(swapchain2) IDirect3DSwapChain8_Release(swapchain2);
331 if(swapchain3) IDirect3DSwapChain8_Release(swapchain3);
334 UINT refcount = IDirect3DDevice8_Release(pDevice);
335 ok(!refcount, "Device has %u references left.\n", refcount);
337 if (pD3d) IDirect3D8_Release(pD3d);
338 DestroyWindow( hwnd );
341 static void test_refcount(void)
345 IDirect3D8 *pD3d = NULL;
346 IDirect3D8 *pD3d2 = NULL;
347 IDirect3DDevice8 *pDevice = NULL;
348 IDirect3DVertexBuffer8 *pVertexBuffer = NULL;
349 IDirect3DIndexBuffer8 *pIndexBuffer = NULL;
350 DWORD dVertexShader = -1;
351 DWORD dPixelShader = -1;
352 IDirect3DCubeTexture8 *pCubeTexture = NULL;
353 IDirect3DTexture8 *pTexture = NULL;
354 IDirect3DVolumeTexture8 *pVolumeTexture = NULL;
355 IDirect3DVolume8 *pVolumeLevel = NULL;
356 IDirect3DSurface8 *pStencilSurface = NULL;
357 IDirect3DSurface8 *pImageSurface = NULL;
358 IDirect3DSurface8 *pRenderTarget = NULL;
359 IDirect3DSurface8 *pRenderTarget2 = NULL;
360 IDirect3DSurface8 *pRenderTarget3 = NULL;
361 IDirect3DSurface8 *pTextureLevel = NULL;
362 IDirect3DSurface8 *pBackBuffer = NULL;
363 DWORD dStateBlock = -1;
364 IDirect3DSwapChain8 *pSwapChain = NULL;
367 D3DPRESENT_PARAMETERS d3dpp;
368 D3DDISPLAYMODE d3ddm;
369 int refcount = 0, tmp;
374 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
375 D3DVSD_REG(D3DVSDE_DIFFUSE, D3DVSDT_D3DCOLOR), /* D3DVSDE_DIFFUSE, Register v5 */
379 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
380 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
381 hwnd = CreateWindow( "d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
382 ok(hwnd != NULL, "Failed to create window\n");
383 if (!pD3d || !hwnd) goto cleanup;
385 CHECK_REFCOUNT( pD3d, 1 );
387 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
388 ZeroMemory( &d3dpp, sizeof(d3dpp) );
389 d3dpp.Windowed = TRUE;
390 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
391 d3dpp.BackBufferFormat = d3ddm.Format;
392 d3dpp.EnableAutoDepthStencil = TRUE;
393 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
395 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
396 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
399 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
402 IDirect3DDevice8_GetDeviceCaps(pDevice, &caps);
404 refcount = get_refcount( (IUnknown *)pDevice );
405 ok(refcount == 1, "Invalid device RefCount %d\n", refcount);
407 CHECK_REFCOUNT( pD3d, 2 );
409 hr = IDirect3DDevice8_GetDirect3D(pDevice, &pD3d2);
410 CHECK_CALL( hr, "GetDirect3D", pDevice, refcount );
412 ok(pD3d2 == pD3d, "Expected IDirect3D8 pointers to be equal\n");
413 CHECK_REFCOUNT( pD3d, 3 );
414 CHECK_RELEASE_REFCOUNT( pD3d, 2 );
417 * Check refcount of implicit surfaces. Findings:
418 * - the container is the device
419 * - they hold a reference to the device
420 * - they are created with a refcount of 0 (Get/Release returns original refcount)
421 * - they are not freed if refcount reaches 0.
422 * - the refcount is not forwarded to the container.
424 hr = IDirect3DDevice8_GetRenderTarget(pDevice, &pRenderTarget);
425 CHECK_CALL( hr, "GetRenderTarget", pDevice, ++refcount);
428 CHECK_SURFACE_CONTAINER( pRenderTarget, IID_IDirect3DDevice8, pDevice);
429 CHECK_REFCOUNT( pRenderTarget, 1);
431 CHECK_ADDREF_REFCOUNT(pRenderTarget, 2);
432 CHECK_REFCOUNT(pDevice, refcount);
433 CHECK_RELEASE_REFCOUNT(pRenderTarget, 1);
434 CHECK_REFCOUNT(pDevice, refcount);
436 hr = IDirect3DDevice8_GetRenderTarget(pDevice, &pRenderTarget);
437 CHECK_CALL( hr, "GetRenderTarget", pDevice, refcount);
438 CHECK_REFCOUNT( pRenderTarget, 2);
439 CHECK_RELEASE_REFCOUNT( pRenderTarget, 1);
440 CHECK_RELEASE_REFCOUNT( pRenderTarget, 0);
441 CHECK_REFCOUNT( pDevice, --refcount);
443 /* The render target is released with the device, so AddRef with refcount=0 is fine here. */
444 CHECK_ADDREF_REFCOUNT(pRenderTarget, 1);
445 CHECK_REFCOUNT(pDevice, ++refcount);
446 CHECK_RELEASE_REFCOUNT(pRenderTarget, 0);
447 CHECK_REFCOUNT(pDevice, --refcount);
450 /* Render target and back buffer are identical. */
451 hr = IDirect3DDevice8_GetBackBuffer(pDevice, 0, 0, &pBackBuffer);
452 CHECK_CALL( hr, "GetBackBuffer", pDevice, ++refcount);
455 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
456 ok(pRenderTarget == pBackBuffer, "RenderTarget=%p and BackBuffer=%p should be the same.\n",
457 pRenderTarget, pBackBuffer);
460 CHECK_REFCOUNT( pDevice, --refcount);
462 hr = IDirect3DDevice8_GetDepthStencilSurface(pDevice, &pStencilSurface);
463 CHECK_CALL( hr, "GetDepthStencilSurface", pDevice, ++refcount);
466 CHECK_SURFACE_CONTAINER( pStencilSurface, IID_IDirect3DDevice8, pDevice);
467 CHECK_REFCOUNT( pStencilSurface, 1);
469 CHECK_ADDREF_REFCOUNT(pStencilSurface, 2);
470 CHECK_REFCOUNT(pDevice, refcount);
471 CHECK_RELEASE_REFCOUNT(pStencilSurface, 1);
472 CHECK_REFCOUNT(pDevice, refcount);
474 CHECK_RELEASE_REFCOUNT( pStencilSurface, 0);
475 CHECK_REFCOUNT( pDevice, --refcount);
477 /* The stencil surface is released with the device, so AddRef with refcount=0 is fine here. */
478 CHECK_ADDREF_REFCOUNT(pStencilSurface, 1);
479 CHECK_REFCOUNT(pDevice, ++refcount);
480 CHECK_RELEASE_REFCOUNT(pStencilSurface, 0);
481 CHECK_REFCOUNT(pDevice, --refcount);
482 pStencilSurface = NULL;
486 hr = IDirect3DDevice8_CreateIndexBuffer( pDevice, 16, 0, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &pIndexBuffer );
487 CHECK_CALL( hr, "CreateIndexBuffer", pDevice, ++refcount );
490 tmp = get_refcount( (IUnknown *)pIndexBuffer );
492 hr = IDirect3DDevice8_SetIndices(pDevice, pIndexBuffer, 0);
493 CHECK_CALL( hr, "SetIndices", pIndexBuffer, tmp);
494 hr = IDirect3DDevice8_SetIndices(pDevice, NULL, 0);
495 CHECK_CALL( hr, "SetIndices", pIndexBuffer, tmp);
498 hr = IDirect3DDevice8_CreateVertexBuffer( pDevice, 16, 0, D3DFVF_XYZ, D3DPOOL_DEFAULT, &pVertexBuffer );
499 CHECK_CALL( hr, "CreateVertexBuffer", pDevice, ++refcount );
502 IDirect3DVertexBuffer8 *pVBuf = (void*)~0;
505 tmp = get_refcount( (IUnknown *)pVertexBuffer );
507 hr = IDirect3DDevice8_SetStreamSource(pDevice, 0, pVertexBuffer, 3 * sizeof(float));
508 CHECK_CALL( hr, "SetStreamSource", pVertexBuffer, tmp);
509 hr = IDirect3DDevice8_SetStreamSource(pDevice, 0, NULL, 0);
510 CHECK_CALL( hr, "SetStreamSource", pVertexBuffer, tmp);
512 hr = IDirect3DDevice8_GetStreamSource(pDevice, 0, &pVBuf, &stride);
513 ok(SUCCEEDED(hr), "GetStreamSource did not succeed with NULL stream!\n");
514 ok(pVBuf==NULL, "pVBuf not NULL (%p)!\n", pVBuf);
515 ok(stride==3*sizeof(float), "stride not 3 floats (got %u)!\n", stride);
519 hr = IDirect3DDevice8_CreateVertexShader( pDevice, decl, simple_vs, &dVertexShader, 0 );
520 CHECK_CALL( hr, "CreateVertexShader", pDevice, refcount );
521 if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 0))
523 hr = IDirect3DDevice8_CreatePixelShader( pDevice, simple_ps, &dPixelShader );
524 CHECK_CALL( hr, "CreatePixelShader", pDevice, refcount );
527 hr = IDirect3DDevice8_CreateTexture( pDevice, 32, 32, 3, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pTexture );
528 CHECK_CALL( hr, "CreateTexture", pDevice, ++refcount );
531 tmp = get_refcount( (IUnknown *)pTexture );
533 /* SetTexture should not increase refcounts */
534 hr = IDirect3DDevice8_SetTexture(pDevice, 0, (IDirect3DBaseTexture8 *) pTexture);
535 CHECK_CALL( hr, "SetTexture", pTexture, tmp);
536 hr = IDirect3DDevice8_SetTexture(pDevice, 0, NULL);
537 CHECK_CALL( hr, "SetTexture", pTexture, tmp);
539 /* This should not increment device refcount */
540 hr = IDirect3DTexture8_GetSurfaceLevel( pTexture, 1, &pTextureLevel );
541 CHECK_CALL( hr, "GetSurfaceLevel", pDevice, refcount );
542 /* But should increment texture's refcount */
543 CHECK_REFCOUNT( pTexture, tmp+1 );
544 /* Because the texture and surface refcount are identical */
547 CHECK_REFCOUNT ( pTextureLevel, tmp+1 );
548 CHECK_ADDREF_REFCOUNT ( pTextureLevel, tmp+2 );
549 CHECK_REFCOUNT ( pTexture , tmp+2 );
550 CHECK_RELEASE_REFCOUNT( pTextureLevel, tmp+1 );
551 CHECK_REFCOUNT ( pTexture , tmp+1 );
552 CHECK_RELEASE_REFCOUNT( pTexture , tmp );
553 CHECK_REFCOUNT ( pTextureLevel, tmp );
556 if(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP)
558 hr = IDirect3DDevice8_CreateCubeTexture( pDevice, 32, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pCubeTexture );
559 CHECK_CALL( hr, "CreateCubeTexture", pDevice, ++refcount );
563 skip("Cube textures not supported\n");
565 if(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP)
567 hr = IDirect3DDevice8_CreateVolumeTexture( pDevice, 32, 32, 2, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pVolumeTexture );
568 CHECK_CALL( hr, "CreateVolumeTexture", pDevice, ++refcount );
572 skip("Volume textures not supported\n");
577 tmp = get_refcount( (IUnknown *)pVolumeTexture );
579 /* This should not increment device refcount */
580 hr = IDirect3DVolumeTexture8_GetVolumeLevel(pVolumeTexture, 0, &pVolumeLevel);
581 CHECK_CALL( hr, "GetVolumeLevel", pDevice, refcount );
582 /* But should increment volume texture's refcount */
583 CHECK_REFCOUNT( pVolumeTexture, tmp+1 );
584 /* Because the volume texture and volume refcount are identical */
587 CHECK_REFCOUNT ( pVolumeLevel , tmp+1 );
588 CHECK_ADDREF_REFCOUNT ( pVolumeLevel , tmp+2 );
589 CHECK_REFCOUNT ( pVolumeTexture, tmp+2 );
590 CHECK_RELEASE_REFCOUNT( pVolumeLevel , tmp+1 );
591 CHECK_REFCOUNT ( pVolumeTexture, tmp+1 );
592 CHECK_RELEASE_REFCOUNT( pVolumeTexture, tmp );
593 CHECK_REFCOUNT ( pVolumeLevel , tmp );
597 hr = IDirect3DDevice8_CreateDepthStencilSurface( pDevice, 32, 32, D3DFMT_D16, D3DMULTISAMPLE_NONE, &pStencilSurface );
598 CHECK_CALL( hr, "CreateDepthStencilSurface", pDevice, ++refcount );
599 CHECK_REFCOUNT( pStencilSurface, 1);
600 hr = IDirect3DDevice8_CreateImageSurface( pDevice, 32, 32, D3DFMT_X8R8G8B8, &pImageSurface );
601 CHECK_CALL( hr, "CreateImageSurface", pDevice, ++refcount );
602 CHECK_REFCOUNT( pImageSurface, 1);
603 hr = IDirect3DDevice8_CreateRenderTarget( pDevice, 32, 32, D3DFMT_X8R8G8B8, D3DMULTISAMPLE_NONE, TRUE, &pRenderTarget3 );
604 CHECK_CALL( hr, "CreateRenderTarget", pDevice, ++refcount );
605 CHECK_REFCOUNT( pRenderTarget3, 1);
607 hr = IDirect3DDevice8_CreateStateBlock( pDevice, D3DSBT_ALL, &dStateBlock );
608 CHECK_CALL( hr, "CreateStateBlock", pDevice, refcount );
609 hr = IDirect3DDevice8_CreateAdditionalSwapChain( pDevice, &d3dpp, &pSwapChain );
610 CHECK_CALL( hr, "CreateAdditionalSwapChain", pDevice, ++refcount );
613 /* check implicit back buffer */
614 hr = IDirect3DSwapChain8_GetBackBuffer(pSwapChain, 0, 0, &pBackBuffer);
615 CHECK_CALL( hr, "GetBackBuffer", pDevice, ++refcount);
616 CHECK_REFCOUNT( pSwapChain, 1);
619 CHECK_SURFACE_CONTAINER( pBackBuffer, IID_IDirect3DDevice8, pDevice);
620 CHECK_REFCOUNT( pBackBuffer, 1);
621 CHECK_RELEASE_REFCOUNT( pBackBuffer, 0);
622 CHECK_REFCOUNT( pDevice, --refcount);
624 /* The back buffer is released with the swapchain, so AddRef with refcount=0 is fine here. */
625 CHECK_ADDREF_REFCOUNT(pBackBuffer, 1);
626 CHECK_REFCOUNT(pDevice, ++refcount);
627 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
628 CHECK_REFCOUNT(pDevice, --refcount);
631 CHECK_REFCOUNT( pSwapChain, 1);
637 /* Vertex buffers can be locked multiple times */
638 hr = IDirect3DVertexBuffer8_Lock(pVertexBuffer, 0, 0, &data, 0);
639 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr);
640 hr = IDirect3DVertexBuffer8_Lock(pVertexBuffer, 0, 0, &data, 0);
641 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr);
642 hr = IDirect3DVertexBuffer8_Unlock(pVertexBuffer);
643 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr);
644 hr = IDirect3DVertexBuffer8_Unlock(pVertexBuffer);
645 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr);
648 /* The implicit render target is not freed if refcount reaches 0.
649 * Otherwise GetRenderTarget would re-allocate it and the pointer would change.*/
650 hr = IDirect3DDevice8_GetRenderTarget(pDevice, &pRenderTarget2);
651 CHECK_CALL( hr, "GetRenderTarget", pDevice, ++refcount);
654 CHECK_RELEASE_REFCOUNT(pRenderTarget2, 0);
655 ok(pRenderTarget == pRenderTarget2, "RenderTarget=%p and RenderTarget2=%p should be the same.\n",
656 pRenderTarget, pRenderTarget2);
657 CHECK_REFCOUNT( pDevice, --refcount);
658 pRenderTarget2 = NULL;
660 pRenderTarget = NULL;
663 CHECK_RELEASE(pDevice, pDevice, --refcount);
666 CHECK_RELEASE(pVertexBuffer, pDevice, --refcount);
667 CHECK_RELEASE(pIndexBuffer, pDevice, --refcount);
669 if (dVertexShader != ~0U) IDirect3DDevice8_DeleteVertexShader( pDevice, dVertexShader );
670 if (dPixelShader != ~0U) IDirect3DDevice8_DeletePixelShader( pDevice, dPixelShader );
672 CHECK_RELEASE(pTexture, pDevice, --refcount);
673 CHECK_RELEASE(pCubeTexture, pDevice, --refcount);
674 CHECK_RELEASE(pVolumeTexture, pDevice, --refcount);
676 CHECK_RELEASE(pStencilSurface, pDevice, --refcount);
677 CHECK_RELEASE(pImageSurface, pDevice, --refcount);
678 CHECK_RELEASE(pRenderTarget3, pDevice, --refcount);
680 if (dStateBlock != ~0U) IDirect3DDevice8_DeleteStateBlock( pDevice, dStateBlock );
681 /* This will destroy device - cannot check the refcount here */
682 if (pSwapChain) CHECK_RELEASE_REFCOUNT( pSwapChain, 0);
684 if (pD3d) CHECK_RELEASE_REFCOUNT( pD3d, 0);
686 DestroyWindow( hwnd );
689 static void test_cursor(void)
693 IDirect3D8 *pD3d = NULL;
694 IDirect3DDevice8 *pDevice = NULL;
695 D3DPRESENT_PARAMETERS d3dpp;
696 D3DDISPLAYMODE d3ddm;
698 IDirect3DSurface8 *cursor = NULL;
700 HMODULE user32_handle = GetModuleHandleA("user32.dll");
702 pGetCursorInfo = (void *)GetProcAddress(user32_handle, "GetCursorInfo");
705 win_skip("GetCursorInfo is not available\n");
709 memset(&info, 0, sizeof(info));
710 info.cbSize = sizeof(info);
711 ok(pGetCursorInfo(&info), "GetCursorInfo failed\n");
714 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
715 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
716 hwnd = CreateWindow( "d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
717 ok(hwnd != NULL, "Failed to create window\n");
718 if (!pD3d || !hwnd) goto cleanup;
720 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
721 ZeroMemory( &d3dpp, sizeof(d3dpp) );
722 d3dpp.Windowed = TRUE;
723 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
724 d3dpp.BackBufferFormat = d3ddm.Format;
726 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
727 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
730 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
734 IDirect3DDevice8_CreateImageSurface(pDevice, 32, 32, D3DFMT_A8R8G8B8, &cursor);
735 ok(cursor != NULL, "IDirect3DDevice8_CreateOffscreenPlainSurface failed with %#08x\n", hr);
737 /* Initially hidden */
738 hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
739 ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
741 /* Not enabled without a surface*/
742 hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
743 ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
746 hr = IDirect3DDevice8_SetCursorProperties(pDevice, 0, 0, NULL);
747 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr);
749 hr = IDirect3DDevice8_SetCursorProperties(pDevice, 0, 0, cursor);
750 ok(hr == D3D_OK, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr);
752 IDirect3DSurface8_Release(cursor);
754 memset(&info, 0, sizeof(info));
755 info.cbSize = sizeof(info);
756 ok(pGetCursorInfo(&info), "GetCursorInfo failed\n");
757 ok(info.flags & CURSOR_SHOWING, "The gdi cursor is hidden (%08x)\n", info.flags);
758 ok(info.hCursor == cur, "The cursor handle is %p\n", info.hCursor); /* unchanged */
761 hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
762 ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
765 hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
766 ok(hr == TRUE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
768 /* GDI cursor unchanged */
769 memset(&info, 0, sizeof(info));
770 info.cbSize = sizeof(info);
771 ok(pGetCursorInfo(&info), "GetCursorInfo failed\n");
772 ok(info.flags & CURSOR_SHOWING, "The gdi cursor is hidden (%08x)\n", info.flags);
773 ok(info.hCursor == cur, "The cursor handle is %p\n", info.hCursor); /* unchanged */
778 UINT refcount = IDirect3DDevice8_Release(pDevice);
779 ok(!refcount, "Device has %u references left.\n", refcount);
781 if (pD3d) IDirect3D8_Release(pD3d);
785 static void test_states(void)
789 IDirect3D8 *pD3d = NULL;
790 IDirect3DDevice8 *pDevice = NULL;
791 D3DPRESENT_PARAMETERS d3dpp;
792 D3DDISPLAYMODE d3ddm;
794 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
795 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
796 hwnd = CreateWindow( "d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
797 ok(hwnd != NULL, "Failed to create window\n");
798 if (!pD3d || !hwnd) goto cleanup;
800 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
801 ZeroMemory( &d3dpp, sizeof(d3dpp) );
802 d3dpp.Windowed = TRUE;
803 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
804 d3dpp.BackBufferWidth = screen_width;
805 d3dpp.BackBufferHeight = screen_height;
806 d3dpp.BackBufferFormat = d3ddm.Format;
808 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
809 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
812 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
816 hr = IDirect3DDevice8_SetRenderState(pDevice, D3DRS_ZVISIBLE, TRUE);
817 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, TRUE) returned %#08x\n", hr);
818 hr = IDirect3DDevice8_SetRenderState(pDevice, D3DRS_ZVISIBLE, FALSE);
819 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, FALSE) returned %#08x\n", hr);
824 UINT refcount = IDirect3DDevice8_Release(pDevice);
825 ok(!refcount, "Device has %u references left.\n", refcount);
827 if (pD3d) IDirect3D8_Release(pD3d);
831 static void test_shader_versions(void)
834 IDirect3D8 *pD3d = NULL;
837 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
838 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
840 hr = IDirect3D8_GetDeviceCaps(pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dcaps);
841 ok(SUCCEEDED(hr) || hr == D3DERR_NOTAVAILABLE, "Failed to get D3D8 caps (%#08x)\n", hr);
843 ok(d3dcaps.VertexShaderVersion <= D3DVS_VERSION(1,1), "Unexpected VertexShaderVersion (%#x > %#x)\n", d3dcaps.VertexShaderVersion, D3DVS_VERSION(1,1));
844 ok(d3dcaps.PixelShaderVersion <= D3DPS_VERSION(1,4), "Unexpected PixelShaderVersion (%#x > %#x)\n", d3dcaps.PixelShaderVersion, D3DPS_VERSION(1,4));
846 skip("No Direct3D support\n");
848 IDirect3D8_Release(pD3d);
853 /* Test adapter display modes */
854 static void test_display_modes(void)
857 D3DDISPLAYMODE dmode;
861 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
862 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
865 max_modes = IDirect3D8_GetAdapterModeCount(pD3d, D3DADAPTER_DEFAULT);
867 broken(max_modes == 0), /* VMware */
868 "GetAdapterModeCount(D3DADAPTER_DEFAULT) returned 0!\n");
870 for(i=0; i<max_modes;i++) {
871 res = IDirect3D8_EnumAdapterModes(pD3d, D3DADAPTER_DEFAULT, i, &dmode);
872 ok(res==D3D_OK, "EnumAdapterModes returned %#08x for mode %u!\n", res, i);
876 ok(dmode.Format==D3DFMT_X8R8G8B8 || dmode.Format==D3DFMT_R5G6B5,
877 "Unexpected display mode returned for mode %u: %#x\n", i , dmode.Format);
880 IDirect3D8_Release(pD3d);
883 static void test_reset(void)
885 UINT width, orig_width = GetSystemMetrics(SM_CXSCREEN);
886 UINT height, orig_height = GetSystemMetrics(SM_CYSCREEN);
887 IDirect3DDevice8 *device1 = NULL;
888 IDirect3DDevice8 *device2 = NULL;
889 D3DDISPLAYMODE d3ddm, d3ddm2;
890 D3DSURFACE_DESC surface_desc;
891 D3DPRESENT_PARAMETERS d3dpp;
892 IDirect3DSurface8 *surface;
893 IDirect3DTexture8 *texture;
894 UINT adapter_mode_count;
895 D3DLOCKED_RECT lockrect;
896 IDirect3D8 *d3d8 = NULL;
905 static const DWORD decl[] =
908 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT4),
918 d3d8 = pDirect3DCreate8(D3D_SDK_VERSION);
919 ok(!!d3d8, "Failed to create IDirect3D8 object.\n");
920 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
921 100, 100, 160, 160, NULL, NULL, NULL, NULL);
922 ok(!!window, "Failed to create window.\n");
923 if (!d3d8 || !window)
926 hr = IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &d3ddm);
927 ok(SUCCEEDED(hr), "GetAdapterDisplayMode failed, hr %#x.\n", hr);
928 adapter_mode_count = IDirect3D8_GetAdapterModeCount(d3d8, D3DADAPTER_DEFAULT);
929 modes = HeapAlloc(GetProcessHeap(), 0, sizeof(*modes) * adapter_mode_count);
930 for (i = 0; i < adapter_mode_count; ++i)
934 memset(&d3ddm2, 0, sizeof(d3ddm2));
935 hr = IDirect3D8_EnumAdapterModes(d3d8, D3DADAPTER_DEFAULT, i, &d3ddm2);
936 ok(SUCCEEDED(hr), "EnumAdapterModes failed, hr %#x.\n", hr);
938 if (d3ddm2.Format != d3ddm.Format)
941 for (j = 0; j < mode_count; ++j)
943 if (modes[j].w == d3ddm2.Width && modes[j].h == d3ddm2.Height)
948 modes[j].w = d3ddm2.Width;
949 modes[j].h = d3ddm2.Height;
953 /* We use them as invalid modes. */
954 if ((d3ddm2.Width == 801 && d3ddm2.Height == 600)
955 || (d3ddm2.Width == 32 && d3ddm2.Height == 32))
957 skip("This system supports a screen resolution of %dx%d, not running mode tests.\n",
958 d3ddm2.Width, d3ddm2.Height);
965 skip("Less than 2 modes supported, skipping mode tests.\n");
970 if (modes[i].w == orig_width && modes[i].h == orig_height) ++i;
972 memset(&d3dpp, 0, sizeof(d3dpp));
973 d3dpp.Windowed = FALSE;
974 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
975 d3dpp.BackBufferWidth = modes[i].w;
976 d3dpp.BackBufferHeight = modes[i].h;
977 d3dpp.BackBufferFormat = d3ddm.Format;
978 d3dpp.EnableAutoDepthStencil = TRUE;
979 d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
981 hr = IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
982 window, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device1);
985 skip("Failed to create device, hr %#x.\n", hr);
988 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
989 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
991 hr = IDirect3DDevice8_GetDeviceCaps(device1, &caps);
992 ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
994 width = GetSystemMetrics(SM_CXSCREEN);
995 height = GetSystemMetrics(SM_CYSCREEN);
996 ok(width == modes[i].w, "Screen width is %u, expected %u.\n", width, modes[i].w);
997 ok(height == modes[i].h, "Screen height is %u, expected %u.\n", height, modes[i].h);
999 hr = IDirect3DDevice8_GetViewport(device1, &vp);
1000 ok(SUCCEEDED(hr), "GetViewport failed, hr %#x.\n", hr);
1003 ok(vp.X == 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp.X);
1004 ok(vp.Y == 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp.Y);
1005 ok(vp.Width == modes[i].w, "D3DVIEWPORT->Width = %u, expected %u.\n", vp.Width, modes[i].w);
1006 ok(vp.Height == modes[i].h, "D3DVIEWPORT->Height = %u, expected %u.\n", vp.Height, modes[i].h);
1007 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp.MinZ);
1008 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp.MaxZ);
1014 vp.Width = modes[i].w / 2;
1015 vp.Height = modes[i].h / 2;
1018 hr = IDirect3DDevice8_SetViewport(device1, &vp);
1019 ok(SUCCEEDED(hr), "SetViewport failed, hr %#x.\n", hr);
1021 memset(&d3dpp, 0, sizeof(d3dpp));
1022 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1023 d3dpp.Windowed = FALSE;
1024 d3dpp.BackBufferWidth = modes[i].w;
1025 d3dpp.BackBufferHeight = modes[i].h;
1026 d3dpp.BackBufferFormat = d3ddm.Format;
1027 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1028 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1029 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1030 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1032 memset(&vp, 0, sizeof(vp));
1033 hr = IDirect3DDevice8_GetViewport(device1, &vp);
1034 ok(SUCCEEDED(hr), "GetViewport failed, hr %#x.\n", hr);
1037 ok(vp.X == 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp.X);
1038 ok(vp.Y == 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp.Y);
1039 ok(vp.Width == modes[i].w, "D3DVIEWPORT->Width = %u, expected %u.\n", vp.Width, modes[i].w);
1040 ok(vp.Height == modes[i].h, "D3DVIEWPORT->Height = %u, expected %u.\n", vp.Height, modes[i].h);
1041 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp.MinZ);
1042 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp.MaxZ);
1045 width = GetSystemMetrics(SM_CXSCREEN);
1046 height = GetSystemMetrics(SM_CYSCREEN);
1047 ok(width == modes[i].w, "Screen width is %u, expected %u.\n", width, modes[i].w);
1048 ok(height == modes[i].h, "Screen height is %u, expected %u.\n", height, modes[i].h);
1050 hr = IDirect3DDevice8_GetRenderTarget(device1, &surface);
1051 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
1052 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
1053 ok(hr == D3D_OK, "GetDesc failed, hr %#x.\n", hr);
1054 ok(surface_desc.Width == modes[i].w, "Back buffer width is %u, expected %u.\n",
1055 surface_desc.Width, modes[i].w);
1056 ok(surface_desc.Height == modes[i].h, "Back buffer height is %u, expected %u.\n",
1057 surface_desc.Height, modes[i].h);
1058 IDirect3DSurface8_Release(surface);
1060 memset(&d3dpp, 0, sizeof(d3dpp));
1061 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1062 d3dpp.Windowed = TRUE;
1063 d3dpp.BackBufferWidth = 400;
1064 d3dpp.BackBufferHeight = 300;
1065 d3dpp.BackBufferFormat = d3ddm.Format;
1066 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1067 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1068 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1069 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1071 memset(&vp, 0, sizeof(vp));
1072 hr = IDirect3DDevice8_GetViewport(device1, &vp);
1073 ok(SUCCEEDED(hr), "GetViewport failed, hr %#x.\n", hr);
1076 ok(vp.X == 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp.X);
1077 ok(vp.Y == 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp.Y);
1078 ok(vp.Width == 400, "D3DVIEWPORT->Width = %u, expected 400.\n", vp.Width);
1079 ok(vp.Height == 300, "D3DVIEWPORT->Height = %u, expected 300.\n", vp.Height);
1080 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp.MinZ);
1081 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp.MaxZ);
1084 width = GetSystemMetrics(SM_CXSCREEN);
1085 height = GetSystemMetrics(SM_CYSCREEN);
1086 ok(width == orig_width, "Screen width is %u, expected %u.\n", width, orig_width);
1087 ok(height == orig_height, "Screen height is %u, expected %u.\n", height, orig_height);
1089 hr = IDirect3DDevice8_GetRenderTarget(device1, &surface);
1090 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
1091 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
1092 ok(hr == D3D_OK, "GetDesc failed, hr %#x.\n", hr);
1093 ok(surface_desc.Width == 400, "Back buffer width is %u, expected 400.\n",
1094 surface_desc.Width);
1095 ok(surface_desc.Height == 300, "Back buffer height is %u, expected 300.\n",
1096 surface_desc.Height);
1097 IDirect3DSurface8_Release(surface);
1099 memset(&d3dpp, 0, sizeof(d3dpp));
1100 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1101 d3dpp.Windowed = TRUE;
1102 d3dpp.BackBufferWidth = 400;
1103 d3dpp.BackBufferHeight = 300;
1104 d3dpp.BackBufferFormat = d3ddm.Format;
1106 /* Reset fails if there is a resource in the default pool. */
1107 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &texture);
1108 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1109 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1110 ok(hr == D3DERR_DEVICELOST, "Reset returned %#x, expected %#x.\n", hr, D3DERR_DEVICELOST);
1111 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1112 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
1113 IDirect3DTexture8_Release(texture);
1114 /* Reset again to get the device out of the lost state. */
1115 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1116 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1117 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1118 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1120 if (caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP)
1122 IDirect3DVolumeTexture8 *volume_texture;
1124 hr = IDirect3DDevice8_CreateVolumeTexture(device1, 16, 16, 4, 1, 0,
1125 D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &volume_texture);
1126 ok(SUCCEEDED(hr), "CreateVolumeTexture failed, hr %#x.\n", hr);
1127 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1128 ok(hr == D3DERR_DEVICELOST, "Reset returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
1129 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1130 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n",
1131 hr, D3DERR_DEVICENOTRESET);
1132 IDirect3DVolumeTexture8_Release(volume_texture);
1133 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1134 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1135 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1136 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1140 skip("Volume textures not supported.\n");
1143 /* Scratch, sysmem and managed pool resources are fine. */
1144 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_SCRATCH, &texture);
1145 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1146 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1147 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1148 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1149 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1150 IDirect3DTexture8_Release(texture);
1152 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_SYSTEMMEM, &texture);
1153 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1154 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1155 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1156 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1157 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1158 IDirect3DTexture8_Release(texture);
1160 /* The depth stencil should get reset to the auto depth stencil when present. */
1161 hr = IDirect3DDevice8_SetRenderTarget(device1, NULL, NULL);
1162 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
1164 hr = IDirect3DDevice8_GetDepthStencilSurface(device1, &surface);
1165 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned %#x, expected %#x.\n", hr, D3DERR_NOTFOUND);
1166 ok(!surface, "Depth / stencil buffer should be NULL.\n");
1168 d3dpp.EnableAutoDepthStencil = TRUE;
1169 d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
1170 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1171 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1173 hr = IDirect3DDevice8_GetDepthStencilSurface(device1, &surface);
1174 ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
1175 ok(!!surface, "Depth / stencil buffer should not be NULL.\n");
1176 if (surface) IDirect3DSurface8_Release(surface);
1178 d3dpp.EnableAutoDepthStencil = FALSE;
1179 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1180 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1182 hr = IDirect3DDevice8_GetDepthStencilSurface(device1, &surface);
1183 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned %#x, expected %#x.\n", hr, D3DERR_NOTFOUND);
1184 ok(!surface, "Depth / stencil buffer should be NULL.\n");
1186 /* Will a sysmem or scratch resource survive while locked? */
1187 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_SYSTEMMEM, &texture);
1188 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1189 hr = IDirect3DTexture8_LockRect(texture, 0, &lockrect, NULL, D3DLOCK_DISCARD);
1190 ok(SUCCEEDED(hr), "LockRect failed, hr %#x.\n", hr);
1191 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1192 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1193 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1194 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1195 IDirect3DTexture8_UnlockRect(texture, 0);
1196 IDirect3DTexture8_Release(texture);
1198 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_SCRATCH, &texture);
1199 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1200 hr = IDirect3DTexture8_LockRect(texture, 0, &lockrect, NULL, D3DLOCK_DISCARD);
1201 ok(SUCCEEDED(hr), "LockRect failed, hr %#x.\n", hr);
1202 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1203 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1204 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1205 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1206 IDirect3DTexture8_UnlockRect(texture, 0);
1207 IDirect3DTexture8_Release(texture);
1209 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_MANAGED, &texture);
1210 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1211 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1212 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1213 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1214 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1215 IDirect3DTexture8_Release(texture);
1217 /* A reference held to an implicit surface causes failures as well. */
1218 hr = IDirect3DDevice8_GetBackBuffer(device1, 0, D3DBACKBUFFER_TYPE_MONO, &surface);
1219 ok(SUCCEEDED(hr), "GetBackBuffer failed, hr %#x.\n", hr);
1220 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1221 ok(hr == D3DERR_DEVICELOST, "Reset returned %#x, expected %#x.\n", hr, D3DERR_DEVICELOST);
1222 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1223 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
1224 IDirect3DSurface8_Release(surface);
1225 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1226 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1227 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1228 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1230 /* Shaders are fine as well. */
1231 hr = IDirect3DDevice8_CreateVertexShader(device1, decl, simple_vs, &shader, 0);
1232 ok(SUCCEEDED(hr), "CreateVertexShader failed, hr %#x.\n", hr);
1233 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1234 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1235 hr = IDirect3DDevice8_DeleteVertexShader(device1, shader);
1236 ok(SUCCEEDED(hr), "DeleteVertexShader failed, hr %#x.\n", hr);
1238 /* Try setting invalid modes. */
1239 memset(&d3dpp, 0, sizeof(d3dpp));
1240 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1241 d3dpp.Windowed = FALSE;
1242 d3dpp.BackBufferWidth = 32;
1243 d3dpp.BackBufferHeight = 32;
1244 d3dpp.BackBufferFormat = d3ddm.Format;
1245 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1246 ok(hr == D3DERR_INVALIDCALL, "Reset returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
1247 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1248 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
1250 memset(&d3dpp, 0, sizeof(d3dpp));
1251 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1252 d3dpp.Windowed = FALSE;
1253 d3dpp.BackBufferWidth = 801;
1254 d3dpp.BackBufferHeight = 600;
1255 d3dpp.BackBufferFormat = d3ddm.Format;
1256 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1257 ok(hr == D3DERR_INVALIDCALL, "Reset returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
1258 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1259 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
1261 hr = IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &d3ddm);
1262 ok(SUCCEEDED(hr), "GetAdapterDisplayMode failed, hr %#x.\n", hr);
1264 memset(&d3dpp, 0, sizeof(d3dpp));
1265 d3dpp.Windowed = TRUE;
1266 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1267 d3dpp.BackBufferFormat = d3ddm.Format;
1268 d3dpp.EnableAutoDepthStencil = FALSE;
1269 d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
1271 hr = IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
1272 window, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device2);
1275 skip("Failed to create device, hr %#x.\n", hr);
1279 hr = IDirect3DDevice8_TestCooperativeLevel(device2);
1280 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1282 d3dpp.Windowed = TRUE;
1283 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1284 d3dpp.BackBufferWidth = 400;
1285 d3dpp.BackBufferHeight = 300;
1286 d3dpp.BackBufferFormat = d3ddm.Format;
1287 d3dpp.EnableAutoDepthStencil = TRUE;
1288 d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
1290 hr = IDirect3DDevice8_Reset(device2, &d3dpp);
1291 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1295 hr = IDirect3DDevice8_GetDepthStencilSurface(device2, &surface);
1296 ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
1297 ok(!!surface, "Depth / stencil buffer should not be NULL.\n");
1299 IDirect3DSurface8_Release(surface);
1302 HeapFree(GetProcessHeap(), 0, modes);
1304 IDirect3DDevice8_Release(device2);
1306 IDirect3DDevice8_Release(device1);
1308 IDirect3D8_Release(d3d8);
1310 DestroyWindow(window);
1313 static void test_scene(void)
1317 IDirect3D8 *pD3d = NULL;
1318 IDirect3DDevice8 *pDevice = NULL;
1319 D3DPRESENT_PARAMETERS d3dpp;
1320 D3DDISPLAYMODE d3ddm;
1322 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
1323 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
1324 hwnd = CreateWindow( "d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1325 ok(hwnd != NULL, "Failed to create window\n");
1326 if (!pD3d || !hwnd) goto cleanup;
1328 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
1329 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1330 d3dpp.Windowed = TRUE;
1331 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1332 d3dpp.BackBufferWidth = 800;
1333 d3dpp.BackBufferHeight = 600;
1334 d3dpp.BackBufferFormat = d3ddm.Format;
1337 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1338 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
1339 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL || broken(hr == D3DERR_NOTAVAILABLE), "IDirect3D8_CreateDevice failed with %#08x\n", hr);
1342 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
1346 /* Test an EndScene without BeginScene. Should return an error */
1347 hr = IDirect3DDevice8_EndScene(pDevice);
1348 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
1350 /* Test a normal BeginScene / EndScene pair, this should work */
1351 hr = IDirect3DDevice8_BeginScene(pDevice);
1352 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
1355 hr = IDirect3DDevice8_EndScene(pDevice);
1356 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
1359 /* Test another EndScene without having begun a new scene. Should return an error */
1360 hr = IDirect3DDevice8_EndScene(pDevice);
1361 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
1363 /* Two nested BeginScene and EndScene calls */
1364 hr = IDirect3DDevice8_BeginScene(pDevice);
1365 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
1366 hr = IDirect3DDevice8_BeginScene(pDevice);
1367 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_BeginScene returned %#08x\n", hr);
1368 hr = IDirect3DDevice8_EndScene(pDevice);
1369 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
1370 hr = IDirect3DDevice8_EndScene(pDevice);
1371 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
1373 /* StretchRect does not exit in Direct3D8, so no equivalent to the d3d9 stretchrect tests */
1378 UINT refcount = IDirect3DDevice8_Release(pDevice);
1379 ok(!refcount, "Device has %u references left.\n", refcount);
1381 if (pD3d) IDirect3D8_Release(pD3d);
1382 DestroyWindow(hwnd);
1385 static void test_shader(void)
1389 IDirect3D8 *pD3d = NULL;
1390 IDirect3DDevice8 *pDevice = NULL;
1391 D3DPRESENT_PARAMETERS d3dpp;
1392 D3DDISPLAYMODE d3ddm;
1393 DWORD hPixelShader = 0, hVertexShader = 0;
1394 DWORD hPixelShader2 = 0, hVertexShader2 = 0;
1397 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
1401 static DWORD dwVertexDecl[] =
1404 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3),
1407 DWORD decl_normal_float2[] =
1410 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
1411 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT2), /* D3DVSDE_NORMAL, Register v1 */
1414 DWORD decl_normal_float4[] =
1417 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
1418 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT4), /* D3DVSDE_NORMAL, Register v1 */
1421 DWORD decl_normal_d3dcolor[] =
1424 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
1425 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_D3DCOLOR),/* D3DVSDE_NORMAL, Register v1 */
1428 const DWORD vertex_decl_size = sizeof(dwVertexDecl);
1429 const DWORD simple_vs_size = sizeof(simple_vs);
1430 const DWORD simple_ps_size = sizeof(simple_ps);
1432 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
1433 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
1434 hwnd = CreateWindow( "d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1435 ok(hwnd != NULL, "Failed to create window\n");
1436 if (!pD3d || !hwnd) goto cleanup;
1438 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
1439 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1440 d3dpp.Windowed = TRUE;
1441 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1442 d3dpp.BackBufferWidth = 800;
1443 d3dpp.BackBufferHeight = 600;
1444 d3dpp.BackBufferFormat = d3ddm.Format;
1447 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1448 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
1449 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL || broken(hr == D3DERR_NOTAVAILABLE), "IDirect3D8_CreateDevice failed with %#08x\n", hr);
1452 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
1455 IDirect3DDevice8_GetDeviceCaps(pDevice, &caps);
1457 /* Test setting and retrieving a FVF */
1458 hr = IDirect3DDevice8_SetVertexShader(pDevice, fvf);
1459 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1460 hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
1461 ok(SUCCEEDED(hr), "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1462 ok(hTempHandle == fvf, "Vertex shader %#08x is set, expected %#08x\n", hTempHandle, fvf);
1464 /* First create a vertex shader */
1465 hr = IDirect3DDevice8_SetVertexShader(pDevice, 0);
1466 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1467 hr = IDirect3DDevice8_CreateVertexShader(pDevice, dwVertexDecl, simple_vs, &hVertexShader, 0);
1468 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1469 /* Msdn says that the new vertex shader is set immediately. This is wrong, apparently */
1470 hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
1471 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1472 ok(hTempHandle == 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, 0);
1473 /* Assign the shader, then verify that GetVertexShader works */
1474 hr = IDirect3DDevice8_SetVertexShader(pDevice, hVertexShader);
1475 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1476 hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
1477 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1478 ok(hTempHandle == hVertexShader, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, hVertexShader);
1479 /* Verify that we can retrieve the declaration */
1480 hr = IDirect3DDevice8_GetVertexShaderDeclaration(pDevice, hVertexShader, NULL, &data_size);
1481 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr);
1482 ok(data_size == vertex_decl_size, "Got data_size %u, expected %u\n", data_size, vertex_decl_size);
1483 data = HeapAlloc(GetProcessHeap(), 0, vertex_decl_size);
1485 hr = IDirect3DDevice8_GetVertexShaderDeclaration(pDevice, hVertexShader, data, &data_size);
1486 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetVertexShaderDeclaration returned (%#08x), "
1487 "expected D3DERR_INVALIDCALL\n", hr);
1488 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
1489 data_size = vertex_decl_size;
1490 hr = IDirect3DDevice8_GetVertexShaderDeclaration(pDevice, hVertexShader, data, &data_size);
1491 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr);
1492 ok(data_size == vertex_decl_size, "Got data_size %u, expected %u\n", data_size, vertex_decl_size);
1493 ok(!memcmp(data, dwVertexDecl, vertex_decl_size), "data not equal to shader declaration\n");
1494 HeapFree(GetProcessHeap(), 0, data);
1495 /* Verify that we can retrieve the shader function */
1496 hr = IDirect3DDevice8_GetVertexShaderFunction(pDevice, hVertexShader, NULL, &data_size);
1497 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr);
1498 ok(data_size == simple_vs_size, "Got data_size %u, expected %u\n", data_size, simple_vs_size);
1499 data = HeapAlloc(GetProcessHeap(), 0, simple_vs_size);
1501 hr = IDirect3DDevice8_GetVertexShaderFunction(pDevice, hVertexShader, data, &data_size);
1502 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetVertexShaderFunction returned (%#08x), "
1503 "expected D3DERR_INVALIDCALL\n", hr);
1504 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
1505 data_size = simple_vs_size;
1506 hr = IDirect3DDevice8_GetVertexShaderFunction(pDevice, hVertexShader, data, &data_size);
1507 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr);
1508 ok(data_size == simple_vs_size, "Got data_size %u, expected %u\n", data_size, simple_vs_size);
1509 ok(!memcmp(data, simple_vs, simple_vs_size), "data not equal to shader function\n");
1510 HeapFree(GetProcessHeap(), 0, data);
1511 /* Delete the assigned shader. This is supposed to work */
1512 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1513 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1514 /* The shader should be unset now */
1515 hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
1516 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1517 ok(hTempHandle == 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, 0);
1519 /* Test a broken declaration. 3DMark2001 tries to use normals with 2 components
1520 * First try the fixed function shader function, then a custom one
1522 hr = IDirect3DDevice8_CreateVertexShader(pDevice, decl_normal_float2, 0, &hVertexShader, 0);
1523 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1524 if(SUCCEEDED(hr)) IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1525 hr = IDirect3DDevice8_CreateVertexShader(pDevice, decl_normal_float4, 0, &hVertexShader, 0);
1526 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1527 if(SUCCEEDED(hr)) IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1528 hr = IDirect3DDevice8_CreateVertexShader(pDevice, decl_normal_d3dcolor, 0, &hVertexShader, 0);
1529 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1530 if(SUCCEEDED(hr)) IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1532 hr = IDirect3DDevice8_CreateVertexShader(pDevice, decl_normal_float2, simple_vs, &hVertexShader, 0);
1533 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1534 if(SUCCEEDED(hr)) IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1536 if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 0))
1538 /* The same with a pixel shader */
1539 hr = IDirect3DDevice8_CreatePixelShader(pDevice, simple_ps, &hPixelShader);
1540 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
1541 /* Msdn says that the new pixel shader is set immediately. This is wrong, apparently */
1542 hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle);
1543 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1544 ok(hTempHandle == 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, 0);
1545 /* Assign the shader, then verify that GetPixelShader works */
1546 hr = IDirect3DDevice8_SetPixelShader(pDevice, hPixelShader);
1547 ok(hr == D3D_OK, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr);
1548 hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle);
1549 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1550 ok(hTempHandle == hPixelShader, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, hPixelShader);
1551 /* Verify that we can retrieve the shader function */
1552 hr = IDirect3DDevice8_GetPixelShaderFunction(pDevice, hPixelShader, NULL, &data_size);
1553 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr);
1554 ok(data_size == simple_ps_size, "Got data_size %u, expected %u\n", data_size, simple_ps_size);
1555 data = HeapAlloc(GetProcessHeap(), 0, simple_ps_size);
1557 hr = IDirect3DDevice8_GetPixelShaderFunction(pDevice, hPixelShader, data, &data_size);
1558 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetPixelShaderFunction returned (%#08x), "
1559 "expected D3DERR_INVALIDCALL\n", hr);
1560 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
1561 data_size = simple_ps_size;
1562 hr = IDirect3DDevice8_GetPixelShaderFunction(pDevice, hPixelShader, data, &data_size);
1563 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr);
1564 ok(data_size == simple_ps_size, "Got data_size %u, expected %u\n", data_size, simple_ps_size);
1565 ok(!memcmp(data, simple_ps, simple_ps_size), "data not equal to shader function\n");
1566 HeapFree(GetProcessHeap(), 0, data);
1567 /* Delete the assigned shader. This is supposed to work */
1568 hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader);
1569 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1570 /* The shader should be unset now */
1571 hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle);
1572 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1573 ok(hTempHandle == 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, 0);
1575 /* What happens if a non-bound shader is deleted? */
1576 hr = IDirect3DDevice8_CreatePixelShader(pDevice, simple_ps, &hPixelShader);
1577 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
1578 hr = IDirect3DDevice8_CreatePixelShader(pDevice, simple_ps, &hPixelShader2);
1579 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
1581 hr = IDirect3DDevice8_SetPixelShader(pDevice, hPixelShader);
1582 ok(hr == D3D_OK, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr);
1583 hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader2);
1584 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1585 hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle);
1586 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1587 ok(hTempHandle == hPixelShader, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, hPixelShader);
1588 hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader);
1589 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1591 /* Check for double delete. */
1592 hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader2);
1593 ok(hr == D3DERR_INVALIDCALL || broken(hr == D3D_OK), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1594 hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader);
1595 ok(hr == D3DERR_INVALIDCALL || broken(hr == D3D_OK), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1599 skip("Pixel shaders not supported\n");
1602 /* What happens if a non-bound shader is deleted? */
1603 hr = IDirect3DDevice8_CreateVertexShader(pDevice, dwVertexDecl, NULL, &hVertexShader, 0);
1604 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1605 hr = IDirect3DDevice8_CreateVertexShader(pDevice, dwVertexDecl, NULL, &hVertexShader2, 0);
1606 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1608 hr = IDirect3DDevice8_SetVertexShader(pDevice, hVertexShader);
1609 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1610 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader2);
1611 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1612 hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
1613 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1614 ok(hTempHandle == hVertexShader, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, hVertexShader);
1615 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1616 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1618 /* Check for double delete. */
1619 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader2);
1620 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1621 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1622 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1627 UINT refcount = IDirect3DDevice8_Release(pDevice);
1628 ok(!refcount, "Device has %u references left.\n", refcount);
1630 if (pD3d) IDirect3D8_Release(pD3d);
1631 DestroyWindow(hwnd);
1634 static void test_limits(void)
1638 IDirect3D8 *pD3d = NULL;
1639 IDirect3DDevice8 *pDevice = NULL;
1640 D3DPRESENT_PARAMETERS d3dpp;
1641 D3DDISPLAYMODE d3ddm;
1642 IDirect3DTexture8 *pTexture = NULL;
1645 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
1646 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
1647 hwnd = CreateWindow( "d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1648 ok(hwnd != NULL, "Failed to create window\n");
1649 if (!pD3d || !hwnd) goto cleanup;
1651 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
1652 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1653 d3dpp.Windowed = TRUE;
1654 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1655 d3dpp.BackBufferWidth = 800;
1656 d3dpp.BackBufferHeight = 600;
1657 d3dpp.BackBufferFormat = d3ddm.Format;
1658 d3dpp.EnableAutoDepthStencil = TRUE;
1659 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
1661 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1662 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
1663 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL || broken(hr == D3DERR_NOTAVAILABLE), "IDirect3D8_CreateDevice failed with %#08x\n", hr);
1666 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
1670 hr = IDirect3DDevice8_CreateTexture(pDevice, 16, 16, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pTexture);
1671 ok(hr == D3D_OK, "IDirect3DDevice8_CreateTexture failed with %#08x\n", hr);
1672 if(!pTexture) goto cleanup;
1674 /* There are 8 texture stages. We should be able to access all of them */
1675 for(i = 0; i < 8; i++) {
1676 hr = IDirect3DDevice8_SetTexture(pDevice, i, (IDirect3DBaseTexture8 *) pTexture);
1677 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i, hr);
1678 hr = IDirect3DDevice8_SetTexture(pDevice, i, NULL);
1679 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i, hr);
1680 hr = IDirect3DDevice8_SetTextureStageState(pDevice, i, D3DTSS_COLOROP, D3DTOP_ADD);
1681 ok(hr == D3D_OK, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %#08x\n", i, hr);
1684 /* Investigations show that accessing higher textures stage states does not return an error either. Writing
1685 * to too high texture stages(approximately texture 40) causes memory corruption in windows, so there is no
1686 * bounds checking but how do I test that?
1690 if(pTexture) IDirect3DTexture8_Release(pTexture);
1693 UINT refcount = IDirect3DDevice8_Release(pDevice);
1694 ok(!refcount, "Device has %u references left.\n", refcount);
1696 if (pD3d) IDirect3D8_Release(pD3d);
1697 DestroyWindow(hwnd);
1700 static void test_lights(void)
1702 D3DPRESENT_PARAMETERS d3dpp;
1703 IDirect3DDevice8 *device = NULL;
1710 D3DDISPLAYMODE d3ddm;
1712 d3d8 = pDirect3DCreate8( D3D_SDK_VERSION );
1713 ok(d3d8 != NULL, "Failed to create IDirect3D8 object\n");
1714 hwnd = CreateWindow( "d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1715 ok(hwnd != NULL, "Failed to create window\n");
1716 if (!d3d8 || !hwnd) goto cleanup;
1718 IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &d3ddm );
1719 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1720 d3dpp.Windowed = TRUE;
1721 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1722 d3dpp.BackBufferWidth = 800;
1723 d3dpp.BackBufferHeight = 600;
1724 d3dpp.BackBufferFormat = d3ddm.Format;
1725 d3dpp.EnableAutoDepthStencil = TRUE;
1726 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
1728 hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1729 D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &d3dpp, &device );
1730 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE || hr == D3DERR_INVALIDCALL,
1731 "IDirect3D8_CreateDevice failed with %08x\n", hr);
1734 skip("Failed to create a d3d device\n");
1738 memset(&caps, 0, sizeof(caps));
1739 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
1740 ok(hr == D3D_OK, "IDirect3DDevice8_GetDeviceCaps failed with %08x\n", hr);
1742 for(i = 1; i <= caps.MaxActiveLights; i++) {
1743 hr = IDirect3DDevice8_LightEnable(device, i, TRUE);
1744 ok(hr == D3D_OK, "Enabling light %u failed with %08x\n", i, hr);
1745 hr = IDirect3DDevice8_GetLightEnable(device, i, &enabled);
1746 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL),
1747 "GetLightEnable on light %u failed with %08x\n", i, hr);
1748 ok(enabled, "Light %d is %s\n", i, enabled ? "enabled" : "disabled");
1751 /* TODO: Test the rendering results in this situation */
1752 hr = IDirect3DDevice8_LightEnable(device, i + 1, TRUE);
1753 ok(hr == D3D_OK, "Enabling one light more than supported returned %08x\n", hr);
1754 hr = IDirect3DDevice8_GetLightEnable(device, i + 1, &enabled);
1755 ok(hr == D3D_OK, "GetLightEnable on light %u failed with %08x\n", i + 1, hr);
1756 ok(enabled, "Light %d is %s\n", i + 1, enabled ? "enabled" : "disabled");
1757 hr = IDirect3DDevice8_LightEnable(device, i + 1, FALSE);
1758 ok(hr == D3D_OK, "Disabling the additional returned %08x\n", hr);
1760 for(i = 1; i <= caps.MaxActiveLights; i++) {
1761 hr = IDirect3DDevice8_LightEnable(device, i, FALSE);
1762 ok(hr == D3D_OK, "Disabling light %u failed with %08x\n", i, hr);
1768 UINT refcount = IDirect3DDevice8_Release(device);
1769 ok(!refcount, "Device has %u references left.\n", refcount);
1771 if (d3d8) IDirect3D8_Release(d3d8);
1772 DestroyWindow(hwnd);
1775 static void test_render_zero_triangles(void)
1777 D3DPRESENT_PARAMETERS d3dpp;
1778 IDirect3DDevice8 *device = NULL;
1782 D3DDISPLAYMODE d3ddm;
1791 { 0.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
1792 { 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
1793 { 1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
1794 { 1.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
1797 d3d8 = pDirect3DCreate8( D3D_SDK_VERSION );
1798 ok(d3d8 != NULL, "Failed to create IDirect3D8 object\n");
1799 hwnd = CreateWindow( "d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1800 ok(hwnd != NULL, "Failed to create window\n");
1801 if (!d3d8 || !hwnd) goto cleanup;
1803 IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &d3ddm );
1804 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1805 d3dpp.Windowed = TRUE;
1806 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1807 d3dpp.BackBufferWidth = 800;
1808 d3dpp.BackBufferHeight = 600;
1809 d3dpp.BackBufferFormat = d3ddm.Format;
1810 d3dpp.EnableAutoDepthStencil = TRUE;
1811 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
1813 hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1814 D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &d3dpp, &device );
1815 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE || hr == D3DERR_INVALIDCALL,
1816 "IDirect3D8_CreateDevice failed with %08x\n", hr);
1819 skip("Failed to create a d3d device\n");
1823 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
1824 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1826 hr = IDirect3DDevice8_BeginScene(device);
1827 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
1830 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 0 /* NumVerts */,
1831 0 /*PrimCount */, NULL, D3DFMT_INDEX16, quad, sizeof(quad[0]));
1832 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr);
1834 IDirect3DDevice8_EndScene(device);
1835 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
1838 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1843 UINT refcount = IDirect3DDevice8_Release(device);
1844 ok(!refcount, "Device has %u references left.\n", refcount);
1846 if (d3d8) IDirect3D8_Release(d3d8);
1847 DestroyWindow(hwnd);
1850 static void test_depth_stencil_reset(void)
1852 D3DPRESENT_PARAMETERS present_parameters;
1853 D3DDISPLAYMODE display_mode;
1854 IDirect3DSurface8 *surface, *orig_rt;
1855 IDirect3DDevice8 *device = NULL;
1861 d3d8 = pDirect3DCreate8(D3D_SDK_VERSION);
1862 ok(d3d8 != NULL, "Failed to create IDirect3D8 object\n");
1863 hwnd = CreateWindow("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL);
1864 ok(hwnd != NULL, "Failed to create window\n");
1865 if (!d3d8 || !hwnd) goto cleanup;
1867 IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &display_mode);
1868 memset(&present_parameters, 0, sizeof(present_parameters));
1869 present_parameters.Windowed = TRUE;
1870 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
1871 present_parameters.BackBufferFormat = display_mode.Format;
1872 present_parameters.EnableAutoDepthStencil = TRUE;
1873 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
1875 hr = IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
1876 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
1879 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr);
1883 hr = IDirect3DDevice8_GetRenderTarget(device, &orig_rt);
1884 ok(hr == D3D_OK, "GetRenderTarget failed with 0x%08x\n", hr);
1886 hr = IDirect3DDevice8_TestCooperativeLevel(device);
1887 ok(SUCCEEDED(hr), "TestCooperativeLevel failed with %#x\n", hr);
1889 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, NULL);
1890 ok(hr == D3D_OK, "SetRenderTarget failed with 0x%08x\n", hr);
1892 hr = IDirect3DDevice8_GetRenderTarget(device, &surface);
1893 ok(hr == D3D_OK, "GetRenderTarget failed with 0x%08x\n", hr);
1894 ok(surface == orig_rt, "Render target is %p, should be %p\n", surface, orig_rt);
1895 if (surface) IDirect3DSurface8_Release(surface);
1896 IDirect3DSurface8_Release(orig_rt);
1898 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
1899 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr);
1900 ok(surface == NULL, "Depth stencil should be NULL\n");
1902 present_parameters.EnableAutoDepthStencil = TRUE;
1903 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
1904 hr = IDirect3DDevice8_Reset(device, &present_parameters);
1905 ok(hr == D3D_OK, "Reset failed with 0x%08x\n", hr);
1907 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
1908 ok(hr == D3D_OK, "GetDepthStencilSurface failed with 0x%08x\n", hr);
1909 ok(surface != NULL, "Depth stencil should not be NULL\n");
1910 if (surface) IDirect3DSurface8_Release(surface);
1912 present_parameters.EnableAutoDepthStencil = FALSE;
1913 hr = IDirect3DDevice8_Reset(device, &present_parameters);
1914 ok(hr == D3D_OK, "Reset failed with 0x%08x\n", hr);
1916 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
1917 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr);
1918 ok(surface == NULL, "Depth stencil should be NULL\n");
1920 refcount = IDirect3DDevice8_Release(device);
1921 ok(!refcount, "Device has %u references left.\n", refcount);
1924 IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &display_mode );
1926 ZeroMemory( &present_parameters, sizeof(present_parameters) );
1927 present_parameters.Windowed = TRUE;
1928 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
1929 present_parameters.BackBufferFormat = display_mode.Format;
1930 present_parameters.EnableAutoDepthStencil = FALSE;
1931 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
1933 hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
1934 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device );
1938 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr);
1942 hr = IDirect3DDevice8_TestCooperativeLevel(device);
1943 ok(hr == D3D_OK, "IDirect3DDevice8_TestCooperativeLevel after creation returned %#x\n", hr);
1945 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
1946 present_parameters.Windowed = TRUE;
1947 present_parameters.BackBufferWidth = 400;
1948 present_parameters.BackBufferHeight = 300;
1949 present_parameters.EnableAutoDepthStencil = TRUE;
1950 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
1952 hr = IDirect3DDevice8_Reset(device, &present_parameters);
1953 ok(hr == D3D_OK, "IDirect3DDevice8_Reset failed with 0x%08x\n", hr);
1955 if (FAILED(hr)) goto cleanup;
1957 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
1958 ok(hr == D3D_OK, "GetDepthStencilSurface failed with 0x%08x\n", hr);
1959 ok(surface != NULL, "Depth stencil should not be NULL\n");
1960 if (surface) IDirect3DSurface8_Release(surface);
1965 refcount = IDirect3DDevice8_Release(device);
1966 ok(!refcount, "Device has %u references left.\n", refcount);
1968 if (d3d8) IDirect3D8_Release(d3d8);
1969 DestroyWindow(hwnd);
1972 static HWND filter_messages;
1983 enum message_window window;
1986 static const struct message *expect_messages;
1987 static HWND device_window, focus_window;
1989 struct wndproc_thread_param
1992 HANDLE window_created;
1993 HANDLE test_finished;
1994 BOOL running_in_foreground;
1997 static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
1999 if (filter_messages && filter_messages == hwnd)
2001 if (message != WM_DISPLAYCHANGE && message != WM_IME_NOTIFY)
2002 todo_wine ok(0, "Received unexpected message %#x for window %p.\n", message, hwnd);
2005 if (expect_messages)
2009 switch (expect_messages->window)
2024 if (hwnd == w && expect_messages->message == message) ++expect_messages;
2027 return DefWindowProcA(hwnd, message, wparam, lparam);
2030 static DWORD WINAPI wndproc_thread(void *param)
2032 struct wndproc_thread_param *p = param;
2036 p->dummy_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2037 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, screen_width, screen_height, 0, 0, 0, 0);
2038 p->running_in_foreground = SetForegroundWindow(p->dummy_window);
2040 ret = SetEvent(p->window_created);
2041 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
2047 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
2048 res = WaitForSingleObject(p->test_finished, 100);
2049 if (res == WAIT_OBJECT_0) break;
2050 if (res != WAIT_TIMEOUT)
2052 ok(0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2057 DestroyWindow(p->dummy_window);
2062 static void test_wndproc(void)
2064 struct wndproc_thread_param thread_params;
2065 IDirect3DDevice8 *device;
2074 static const struct message messages[] =
2076 {WM_WINDOWPOSCHANGING, FOCUS_WINDOW},
2077 {WM_ACTIVATE, FOCUS_WINDOW},
2078 {WM_SETFOCUS, FOCUS_WINDOW},
2079 {WM_WINDOWPOSCHANGING, DEVICE_WINDOW},
2080 {WM_MOVE, DEVICE_WINDOW},
2081 {WM_SIZE, DEVICE_WINDOW},
2085 if (!(d3d8 = pDirect3DCreate8(D3D_SDK_VERSION)))
2087 skip("Failed to create IDirect3D8 object, skipping tests.\n");
2091 wc.lpfnWndProc = test_proc;
2092 wc.lpszClassName = "d3d8_test_wndproc_wc";
2093 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2095 thread_params.window_created = CreateEvent(NULL, FALSE, FALSE, NULL);
2096 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
2097 thread_params.test_finished = CreateEvent(NULL, FALSE, FALSE, NULL);
2098 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
2100 focus_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2101 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, screen_width, screen_height, 0, 0, 0, 0);
2102 device_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2103 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, screen_width, screen_height, 0, 0, 0, 0);
2104 thread = CreateThread(NULL, 0, wndproc_thread, &thread_params, 0, &tid);
2105 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
2107 res = WaitForSingleObject(thread_params.window_created, INFINITE);
2108 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2110 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2111 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2112 (LONG_PTR)test_proc, proc);
2113 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2114 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2115 (LONG_PTR)test_proc, proc);
2117 trace("device_window %p, focus_window %p, dummy_window %p.\n",
2118 device_window, focus_window, thread_params.dummy_window);
2121 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
2122 if (thread_params.running_in_foreground)
2124 tmp = GetForegroundWindow();
2125 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
2126 thread_params.dummy_window, tmp);
2129 skip("Not running in foreground, skip foreground window test\n");
2133 expect_messages = messages;
2135 device = create_device(d3d8, device_window, focus_window, FALSE);
2138 skip("Failed to create a D3D device, skipping tests.\n");
2142 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2143 expect_messages->message, expect_messages->window);
2144 expect_messages = NULL;
2146 if (0) /* Disabled until we can make this work in a reliable way on Wine. */
2149 ok(tmp == focus_window, "Expected focus %p, got %p.\n", focus_window, tmp);
2150 tmp = GetForegroundWindow();
2151 ok(tmp == focus_window, "Expected foreground window %p, got %p.\n", focus_window, tmp);
2153 SetForegroundWindow(focus_window);
2156 filter_messages = focus_window;
2158 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2159 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2160 (LONG_PTR)test_proc, proc);
2162 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2163 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2164 (LONG_PTR)test_proc, proc);
2166 ref = IDirect3DDevice8_Release(device);
2167 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
2169 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2170 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2171 (LONG_PTR)test_proc, proc);
2173 device = create_device(d3d8, focus_window, focus_window, FALSE);
2176 skip("Failed to create a D3D device, skipping tests.\n");
2180 ref = IDirect3DDevice8_Release(device);
2181 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
2183 device = create_device(d3d8, device_window, focus_window, FALSE);
2186 skip("Failed to create a D3D device, skipping tests.\n");
2190 proc = SetWindowLongPtrA(focus_window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2191 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2192 (LONG_PTR)test_proc, proc);
2194 ref = IDirect3DDevice8_Release(device);
2195 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
2197 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2198 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2199 (LONG_PTR)DefWindowProcA, proc);
2202 filter_messages = NULL;
2203 IDirect3D8_Release(d3d8);
2205 SetEvent(thread_params.test_finished);
2206 WaitForSingleObject(thread, INFINITE);
2207 CloseHandle(thread_params.test_finished);
2208 CloseHandle(thread_params.window_created);
2209 CloseHandle(thread);
2211 DestroyWindow(device_window);
2212 DestroyWindow(focus_window);
2213 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL));
2216 static void test_wndproc_windowed(void)
2218 struct wndproc_thread_param thread_params;
2219 IDirect3DDevice8 *device;
2229 if (!(d3d8 = pDirect3DCreate8(D3D_SDK_VERSION)))
2231 skip("Failed to create IDirect3D8 object, skipping tests.\n");
2235 wc.lpfnWndProc = test_proc;
2236 wc.lpszClassName = "d3d8_test_wndproc_wc";
2237 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2239 thread_params.window_created = CreateEvent(NULL, FALSE, FALSE, NULL);
2240 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
2241 thread_params.test_finished = CreateEvent(NULL, FALSE, FALSE, NULL);
2242 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
2244 focus_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2245 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, screen_width, screen_height, 0, 0, 0, 0);
2246 device_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2247 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, screen_width, screen_height, 0, 0, 0, 0);
2248 thread = CreateThread(NULL, 0, wndproc_thread, &thread_params, 0, &tid);
2249 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
2251 res = WaitForSingleObject(thread_params.window_created, INFINITE);
2252 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2254 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2255 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2256 (LONG_PTR)test_proc, proc);
2257 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2258 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2259 (LONG_PTR)test_proc, proc);
2261 trace("device_window %p, focus_window %p, dummy_window %p.\n",
2262 device_window, focus_window, thread_params.dummy_window);
2265 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
2266 if (thread_params.running_in_foreground)
2268 tmp = GetForegroundWindow();
2269 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
2270 thread_params.dummy_window, tmp);
2273 skip("Not running in foreground, skip foreground window test\n");
2275 filter_messages = focus_window;
2277 device = create_device(d3d8, device_window, focus_window, TRUE);
2280 skip("Failed to create a D3D device, skipping tests.\n");
2285 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
2286 tmp = GetForegroundWindow();
2287 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
2288 thread_params.dummy_window, tmp);
2290 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2291 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2292 (LONG_PTR)test_proc, proc);
2294 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2295 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2296 (LONG_PTR)test_proc, proc);
2298 filter_messages = NULL;
2300 hr = reset_device(device, device_window, FALSE);
2301 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2303 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2304 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2305 (LONG_PTR)test_proc, proc);
2307 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2308 ok(proc != (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2309 (LONG_PTR)test_proc, proc);
2311 hr = reset_device(device, device_window, TRUE);
2312 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2314 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2315 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2316 (LONG_PTR)test_proc, proc);
2318 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2319 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2320 (LONG_PTR)test_proc, proc);
2322 filter_messages = focus_window;
2324 ref = IDirect3DDevice8_Release(device);
2325 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
2327 filter_messages = device_window;
2329 device = create_device(d3d8, focus_window, focus_window, TRUE);
2332 skip("Failed to create a D3D device, skipping tests.\n");
2336 filter_messages = NULL;
2338 hr = reset_device(device, focus_window, FALSE);
2339 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2341 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2342 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2343 (LONG_PTR)test_proc, proc);
2345 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2346 ok(proc != (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2347 (LONG_PTR)test_proc, proc);
2349 hr = reset_device(device, focus_window, TRUE);
2350 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2352 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2353 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2354 (LONG_PTR)test_proc, proc);
2356 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2357 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2358 (LONG_PTR)test_proc, proc);
2360 filter_messages = device_window;
2362 ref = IDirect3DDevice8_Release(device);
2363 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
2365 device = create_device(d3d8, device_window, focus_window, TRUE);
2368 skip("Failed to create a D3D device, skipping tests.\n");
2372 filter_messages = NULL;
2374 hr = reset_device(device, device_window, FALSE);
2375 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2377 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2378 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2379 (LONG_PTR)test_proc, proc);
2381 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2382 ok(proc != (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2383 (LONG_PTR)test_proc, proc);
2385 hr = reset_device(device, device_window, TRUE);
2386 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2388 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2389 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2390 (LONG_PTR)test_proc, proc);
2392 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2393 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2394 (LONG_PTR)test_proc, proc);
2396 filter_messages = device_window;
2398 ref = IDirect3DDevice8_Release(device);
2399 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
2402 filter_messages = NULL;
2403 IDirect3D8_Release(d3d8);
2405 SetEvent(thread_params.test_finished);
2406 WaitForSingleObject(thread, INFINITE);
2407 CloseHandle(thread_params.test_finished);
2408 CloseHandle(thread_params.window_created);
2409 CloseHandle(thread);
2411 DestroyWindow(device_window);
2412 DestroyWindow(focus_window);
2413 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL));
2416 static inline void set_fpu_cw(WORD cw)
2418 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2419 __asm__ volatile ("fnclex");
2420 __asm__ volatile ("fldcw %0" : : "m" (cw));
2424 static inline WORD get_fpu_cw(void)
2427 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2428 __asm__ volatile ("fnstcw %0" : "=m" (cw));
2433 static void test_fpu_setup(void)
2435 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2436 D3DPRESENT_PARAMETERS present_parameters;
2437 IDirect3DDevice8 *device;
2438 D3DDISPLAYMODE d3ddm;
2444 d3d8 = pDirect3DCreate8(D3D_SDK_VERSION);
2445 ok(!!d3d8, "Failed to create a d3d8 object.\n");
2448 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_CAPTION, 0, 0, screen_width, screen_height, 0, 0, 0, 0);
2449 ok(!!window, "Failed to create a window.\n");
2450 if (!window) goto done;
2452 hr = IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &d3ddm);
2453 ok(SUCCEEDED(hr), "GetAdapterDisplayMode failed, hr %#x.\n", hr);
2455 memset(&present_parameters, 0, sizeof(present_parameters));
2456 present_parameters.Windowed = TRUE;
2457 present_parameters.hDeviceWindow = window;
2458 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
2459 present_parameters.BackBufferFormat = d3ddm.Format;
2463 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
2465 hr = IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
2466 D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device);
2469 skip("Failed to create a device, hr %#x.\n", hr);
2475 ok(cw == 0x7f, "cw is %#x, expected 0x7f.\n", cw);
2477 IDirect3DDevice8_Release(device);
2480 ok(cw == 0x7f, "cw is %#x, expected 0x7f.\n", cw);
2483 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
2485 hr = IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
2486 D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &present_parameters, &device);
2487 ok(SUCCEEDED(hr), "CreateDevice failed, hr %#x.\n", hr);
2490 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
2493 IDirect3DDevice8_Release(device);
2496 if (window) DestroyWindow(window);
2497 if (d3d8) IDirect3D8_Release(d3d8);
2501 static void test_ApplyStateBlock(void)
2503 D3DPRESENT_PARAMETERS d3dpp;
2504 IDirect3DDevice8 *device = NULL;
2508 D3DDISPLAYMODE d3ddm;
2509 DWORD received, token;
2511 d3d8 = pDirect3DCreate8( D3D_SDK_VERSION );
2512 ok(d3d8 != NULL, "Failed to create IDirect3D8 object\n");
2513 hwnd = CreateWindow( "d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
2514 ok(hwnd != NULL, "Failed to create window\n");
2515 if (!d3d8 || !hwnd) goto cleanup;
2517 IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &d3ddm );
2518 ZeroMemory( &d3dpp, sizeof(d3dpp) );
2519 d3dpp.Windowed = TRUE;
2520 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
2521 d3dpp.BackBufferWidth = 800;
2522 d3dpp.BackBufferHeight = 600;
2523 d3dpp.BackBufferFormat = d3ddm.Format;
2524 d3dpp.EnableAutoDepthStencil = TRUE;
2525 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
2527 hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
2528 D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &d3dpp, &device );
2529 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE || hr == D3DERR_INVALIDCALL,
2530 "IDirect3D8_CreateDevice failed with %#x\n", hr);
2533 skip("Failed to create a d3d device\n");
2537 IDirect3DDevice8_BeginStateBlock(device);
2538 IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, TRUE);
2539 IDirect3DDevice8_EndStateBlock(device, &token);
2540 ok(token, "Received zero stateblock handle.\n");
2541 IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, FALSE);
2543 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_ZENABLE, &received);
2544 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
2545 ok(!received, "Expected = FALSE, received TRUE.\n");
2547 IDirect3DDevice8_ApplyStateBlock(device, 0);
2548 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
2549 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_ZENABLE, &received);
2550 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
2551 ok(!received, "Expected FALSE, received TRUE.\n");
2553 IDirect3DDevice8_ApplyStateBlock(device, token);
2554 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
2555 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_ZENABLE, &received);
2556 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
2557 ok(received, "Expected TRUE, received FALSE.\n");
2559 IDirect3DDevice8_DeleteStateBlock(device, token);
2560 IDirect3DDevice8_Release(device);
2562 if (d3d8) IDirect3D8_Release(d3d8);
2563 DestroyWindow(hwnd);
2566 static void test_depth_stencil_size(void)
2568 IDirect3DDevice8 *device;
2569 IDirect3DSurface8 *ds, *rt, *ds_bigger, *ds_bigger2;
2570 IDirect3DSurface8 *surf;
2575 d3d8 = pDirect3DCreate8( D3D_SDK_VERSION );
2576 ok(d3d8 != NULL, "Failed to create IDirect3D8 object\n");
2577 hwnd = CreateWindow( "d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
2578 ok(hwnd != NULL, "Failed to create window\n");
2579 if (!d3d8 || !hwnd) goto cleanup;
2581 device = create_device(d3d8, hwnd, hwnd, TRUE);
2582 if (!device) goto cleanup;
2584 hr = IDirect3DDevice8_CreateRenderTarget(device, 64, 64, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, FALSE, &rt);
2585 ok(SUCCEEDED(hr), "IDirect3DDevice8_CreateRenderTarget failed, hr %#x.\n", hr);
2586 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 32, 32, D3DFMT_D24X8, D3DMULTISAMPLE_NONE, &ds);
2587 ok(SUCCEEDED(hr), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr);
2588 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 128, 128, D3DFMT_D24X8, D3DMULTISAMPLE_NONE, &ds_bigger);
2589 ok(SUCCEEDED(hr), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr);
2590 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 128, 128, D3DFMT_D24X8, D3DMULTISAMPLE_NONE, &ds_bigger2);
2591 ok(SUCCEEDED(hr), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr);
2593 hr = IDirect3DDevice8_SetRenderTarget(device, rt, ds);
2594 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_SetRenderTarget returned %#x, expected D3DERR_INVALIDCALL.\n", hr);
2595 hr = IDirect3DDevice8_SetRenderTarget(device, rt, ds_bigger);
2596 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr);
2598 /* try to set the small ds without changing the render target at the same time */
2599 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, ds);
2600 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_SetRenderTarget returned %#x, expected D3DERR_INVALIDCALL.\n", hr);
2601 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, ds_bigger2);
2602 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr);
2604 hr = IDirect3DDevice8_GetRenderTarget(device, &surf);
2605 ok(hr == D3D_OK, "IDirect3DDevice8_GetRenderTarget failed, hr %#x.\n", hr);
2606 ok(surf == rt, "The render target is %p, expected %p\n", surf, rt);
2607 IDirect3DSurface8_Release(surf);
2608 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surf);
2609 ok(hr == D3D_OK, "IDirect3DDevice8_GetDepthStencilSurface failed, hr %#x.\n", hr);
2610 ok(surf == ds_bigger2, "The depth stencil is %p, expected %p\n", surf, ds_bigger2);
2611 IDirect3DSurface8_Release(surf);
2613 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, NULL);
2614 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr);
2615 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surf);
2616 ok(FAILED(hr), "IDirect3DDevice8_GetDepthStencilSurface should have failed, hr %#x.\n", hr);
2617 ok(surf == NULL, "The depth stencil is %p, expected NULL\n", surf);
2618 if (surf) IDirect3DSurface8_Release(surf);
2620 IDirect3DSurface8_Release(rt);
2621 IDirect3DSurface8_Release(ds);
2622 IDirect3DSurface8_Release(ds_bigger);
2623 IDirect3DSurface8_Release(ds_bigger2);
2626 if (d3d8) IDirect3D8_Release(d3d8);
2627 DestroyWindow(hwnd);
2630 static void test_window_style(void)
2632 RECT focus_rect, fullscreen_rect, r;
2633 LONG device_style, device_exstyle;
2634 LONG focus_style, focus_exstyle;
2635 LONG style, expected_style;
2636 IDirect3DDevice8 *device;
2641 if (!(d3d8 = pDirect3DCreate8(D3D_SDK_VERSION)))
2643 skip("Failed to create IDirect3D8 object, skipping tests.\n");
2647 focus_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
2648 0, 0, screen_width / 2, screen_height / 2, 0, 0, 0, 0);
2649 device_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
2650 0, 0, screen_width / 2, screen_height / 2, 0, 0, 0, 0);
2652 device_style = GetWindowLongA(device_window, GWL_STYLE);
2653 device_exstyle = GetWindowLongA(device_window, GWL_EXSTYLE);
2654 focus_style = GetWindowLongA(focus_window, GWL_STYLE);
2655 focus_exstyle = GetWindowLongA(focus_window, GWL_EXSTYLE);
2657 SetRect(&fullscreen_rect, 0, 0, screen_width, screen_height);
2658 GetWindowRect(focus_window, &focus_rect);
2660 device = create_device(d3d8, device_window, focus_window, FALSE);
2663 skip("Failed to create a D3D device, skipping tests.\n");
2667 style = GetWindowLongA(device_window, GWL_STYLE);
2668 expected_style = device_style | WS_VISIBLE;
2669 todo_wine ok(style == expected_style, "Expected device window style %#x, got %#x.\n",
2670 expected_style, style);
2671 style = GetWindowLongA(device_window, GWL_EXSTYLE);
2672 expected_style = device_exstyle | WS_EX_TOPMOST;
2673 todo_wine ok(style == expected_style, "Expected device window extended style %#x, got %#x.\n",
2674 expected_style, style);
2676 style = GetWindowLongA(focus_window, GWL_STYLE);
2677 ok(style == focus_style, "Expected focus window style %#x, got %#x.\n",
2678 focus_style, style);
2679 style = GetWindowLongA(focus_window, GWL_EXSTYLE);
2680 ok(style == focus_exstyle, "Expected focus window extended style %#x, got %#x.\n",
2681 focus_exstyle, style);
2683 GetWindowRect(device_window, &r);
2684 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2685 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2686 r.left, r.top, r.right, r.bottom);
2687 GetClientRect(device_window, &r);
2688 todo_wine ok(!EqualRect(&r, &fullscreen_rect), "Client rect and window rect are equal.\n");
2689 GetWindowRect(focus_window, &r);
2690 ok(EqualRect(&r, &focus_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2691 focus_rect.left, focus_rect.top, focus_rect.right, focus_rect.bottom,
2692 r.left, r.top, r.right, r.bottom);
2694 ref = IDirect3DDevice8_Release(device);
2695 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
2698 IDirect3D8_Release(d3d8);
2700 DestroyWindow(device_window);
2701 DestroyWindow(focus_window);
2706 HMODULE d3d8_handle = LoadLibraryA( "d3d8.dll" );
2710 skip("Could not load d3d8.dll\n");
2714 wc.lpfnWndProc = DefWindowProc;
2715 wc.lpszClassName = "d3d8_test_wc";
2718 pDirect3DCreate8 = (void *)GetProcAddress( d3d8_handle, "Direct3DCreate8" );
2719 ok(pDirect3DCreate8 != NULL, "Failed to get address of Direct3DCreate8\n");
2720 if (pDirect3DCreate8)
2723 d3d8 = pDirect3DCreate8( D3D_SDK_VERSION );
2726 skip("could not create D3D8\n");
2729 IDirect3D8_Release(d3d8);
2731 screen_width = GetSystemMetrics(SM_CXSCREEN);
2732 screen_height = GetSystemMetrics(SM_CYSCREEN);
2735 test_display_modes();
2736 test_shader_versions();
2739 test_mipmap_levels();
2747 test_ApplyStateBlock();
2748 test_render_zero_triangles();
2749 test_depth_stencil_reset();
2751 test_wndproc_windowed();
2752 test_depth_stencil_size();
2753 test_window_style();
2755 UnregisterClassA("d3d8_test_wc", GetModuleHandleA(NULL));