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( "static", "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( "static", "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 IDirect3DDevice8 *pDevice = NULL;
347 IDirect3DVertexBuffer8 *pVertexBuffer = NULL;
348 IDirect3DIndexBuffer8 *pIndexBuffer = NULL;
349 DWORD dVertexShader = -1;
350 DWORD dPixelShader = -1;
351 IDirect3DCubeTexture8 *pCubeTexture = NULL;
352 IDirect3DTexture8 *pTexture = NULL;
353 IDirect3DVolumeTexture8 *pVolumeTexture = NULL;
354 IDirect3DVolume8 *pVolumeLevel = NULL;
355 IDirect3DSurface8 *pStencilSurface = NULL;
356 IDirect3DSurface8 *pImageSurface = NULL;
357 IDirect3DSurface8 *pRenderTarget = NULL;
358 IDirect3DSurface8 *pRenderTarget2 = NULL;
359 IDirect3DSurface8 *pRenderTarget3 = NULL;
360 IDirect3DSurface8 *pTextureLevel = NULL;
361 IDirect3DSurface8 *pBackBuffer = NULL;
362 DWORD dStateBlock = -1;
363 IDirect3DSwapChain8 *pSwapChain = NULL;
366 D3DPRESENT_PARAMETERS d3dpp;
367 D3DDISPLAYMODE d3ddm;
368 int refcount = 0, tmp;
373 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
374 D3DVSD_REG(D3DVSDE_DIFFUSE, D3DVSDT_D3DCOLOR), /* D3DVSDE_DIFFUSE, Register v5 */
378 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
379 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
380 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
381 ok(hwnd != NULL, "Failed to create window\n");
382 if (!pD3d || !hwnd) goto cleanup;
384 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
385 ZeroMemory( &d3dpp, sizeof(d3dpp) );
386 d3dpp.Windowed = TRUE;
387 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
388 d3dpp.BackBufferFormat = d3ddm.Format;
389 d3dpp.EnableAutoDepthStencil = TRUE;
390 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
392 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
393 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
396 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
399 IDirect3DDevice8_GetDeviceCaps(pDevice, &caps);
401 refcount = get_refcount( (IUnknown *)pDevice );
402 ok(refcount == 1, "Invalid device RefCount %d\n", refcount);
405 * Check refcount of implicit surfaces. Findings:
406 * - the container is the device
407 * - they hold a reference to the device
408 * - they are created with a refcount of 0 (Get/Release returns original refcount)
409 * - they are not freed if refcount reaches 0.
410 * - the refcount is not forwarded to the container.
412 hr = IDirect3DDevice8_GetRenderTarget(pDevice, &pRenderTarget);
413 CHECK_CALL( hr, "GetRenderTarget", pDevice, ++refcount);
416 CHECK_SURFACE_CONTAINER( pRenderTarget, IID_IDirect3DDevice8, pDevice);
417 CHECK_REFCOUNT( pRenderTarget, 1);
419 CHECK_ADDREF_REFCOUNT(pRenderTarget, 2);
420 CHECK_REFCOUNT(pDevice, refcount);
421 CHECK_RELEASE_REFCOUNT(pRenderTarget, 1);
422 CHECK_REFCOUNT(pDevice, refcount);
424 hr = IDirect3DDevice8_GetRenderTarget(pDevice, &pRenderTarget);
425 CHECK_CALL( hr, "GetRenderTarget", pDevice, refcount);
426 CHECK_REFCOUNT( pRenderTarget, 2);
427 CHECK_RELEASE_REFCOUNT( pRenderTarget, 1);
428 CHECK_RELEASE_REFCOUNT( pRenderTarget, 0);
429 CHECK_REFCOUNT( pDevice, --refcount);
431 /* The render target is released with the device, so AddRef with refcount=0 is fine here. */
432 CHECK_ADDREF_REFCOUNT(pRenderTarget, 1);
433 CHECK_REFCOUNT(pDevice, ++refcount);
434 CHECK_RELEASE_REFCOUNT(pRenderTarget, 0);
435 CHECK_REFCOUNT(pDevice, --refcount);
438 /* Render target and back buffer are identical. */
439 hr = IDirect3DDevice8_GetBackBuffer(pDevice, 0, 0, &pBackBuffer);
440 CHECK_CALL( hr, "GetBackBuffer", pDevice, ++refcount);
443 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
444 ok(pRenderTarget == pBackBuffer, "RenderTarget=%p and BackBuffer=%p should be the same.\n",
445 pRenderTarget, pBackBuffer);
448 CHECK_REFCOUNT( pDevice, --refcount);
450 hr = IDirect3DDevice8_GetDepthStencilSurface(pDevice, &pStencilSurface);
451 CHECK_CALL( hr, "GetDepthStencilSurface", pDevice, ++refcount);
454 CHECK_SURFACE_CONTAINER( pStencilSurface, IID_IDirect3DDevice8, pDevice);
455 CHECK_REFCOUNT( pStencilSurface, 1);
457 CHECK_ADDREF_REFCOUNT(pStencilSurface, 2);
458 CHECK_REFCOUNT(pDevice, refcount);
459 CHECK_RELEASE_REFCOUNT(pStencilSurface, 1);
460 CHECK_REFCOUNT(pDevice, refcount);
462 CHECK_RELEASE_REFCOUNT( pStencilSurface, 0);
463 CHECK_REFCOUNT( pDevice, --refcount);
465 /* The stencil surface is released with the device, so AddRef with refcount=0 is fine here. */
466 CHECK_ADDREF_REFCOUNT(pStencilSurface, 1);
467 CHECK_REFCOUNT(pDevice, ++refcount);
468 CHECK_RELEASE_REFCOUNT(pStencilSurface, 0);
469 CHECK_REFCOUNT(pDevice, --refcount);
470 pStencilSurface = NULL;
474 hr = IDirect3DDevice8_CreateIndexBuffer( pDevice, 16, 0, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &pIndexBuffer );
475 CHECK_CALL( hr, "CreateIndexBuffer", pDevice, ++refcount );
478 tmp = get_refcount( (IUnknown *)pIndexBuffer );
480 hr = IDirect3DDevice8_SetIndices(pDevice, pIndexBuffer, 0);
481 CHECK_CALL( hr, "SetIndices", pIndexBuffer, tmp);
482 hr = IDirect3DDevice8_SetIndices(pDevice, NULL, 0);
483 CHECK_CALL( hr, "SetIndices", pIndexBuffer, tmp);
486 hr = IDirect3DDevice8_CreateVertexBuffer( pDevice, 16, 0, D3DFVF_XYZ, D3DPOOL_DEFAULT, &pVertexBuffer );
487 CHECK_CALL( hr, "CreateVertexBuffer", pDevice, ++refcount );
490 IDirect3DVertexBuffer8 *pVBuf = (void*)~0;
493 tmp = get_refcount( (IUnknown *)pVertexBuffer );
495 hr = IDirect3DDevice8_SetStreamSource(pDevice, 0, pVertexBuffer, 3 * sizeof(float));
496 CHECK_CALL( hr, "SetStreamSource", pVertexBuffer, tmp);
497 hr = IDirect3DDevice8_SetStreamSource(pDevice, 0, NULL, 0);
498 CHECK_CALL( hr, "SetStreamSource", pVertexBuffer, tmp);
500 hr = IDirect3DDevice8_GetStreamSource(pDevice, 0, &pVBuf, &stride);
501 ok(SUCCEEDED(hr), "GetStreamSource did not succeed with NULL stream!\n");
502 ok(pVBuf==NULL, "pVBuf not NULL (%p)!\n", pVBuf);
503 ok(stride==3*sizeof(float), "stride not 3 floats (got %u)!\n", stride);
507 hr = IDirect3DDevice8_CreateVertexShader( pDevice, decl, simple_vs, &dVertexShader, 0 );
508 CHECK_CALL( hr, "CreateVertexShader", pDevice, refcount );
509 if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 0))
511 hr = IDirect3DDevice8_CreatePixelShader( pDevice, simple_ps, &dPixelShader );
512 CHECK_CALL( hr, "CreatePixelShader", pDevice, refcount );
515 hr = IDirect3DDevice8_CreateTexture( pDevice, 32, 32, 3, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pTexture );
516 CHECK_CALL( hr, "CreateTexture", pDevice, ++refcount );
519 tmp = get_refcount( (IUnknown *)pTexture );
521 /* SetTexture should not increase refcounts */
522 hr = IDirect3DDevice8_SetTexture(pDevice, 0, (IDirect3DBaseTexture8 *) pTexture);
523 CHECK_CALL( hr, "SetTexture", pTexture, tmp);
524 hr = IDirect3DDevice8_SetTexture(pDevice, 0, NULL);
525 CHECK_CALL( hr, "SetTexture", pTexture, tmp);
527 /* This should not increment device refcount */
528 hr = IDirect3DTexture8_GetSurfaceLevel( pTexture, 1, &pTextureLevel );
529 CHECK_CALL( hr, "GetSurfaceLevel", pDevice, refcount );
530 /* But should increment texture's refcount */
531 CHECK_REFCOUNT( pTexture, tmp+1 );
532 /* Because the texture and surface refcount are identical */
535 CHECK_REFCOUNT ( pTextureLevel, tmp+1 );
536 CHECK_ADDREF_REFCOUNT ( pTextureLevel, tmp+2 );
537 CHECK_REFCOUNT ( pTexture , tmp+2 );
538 CHECK_RELEASE_REFCOUNT( pTextureLevel, tmp+1 );
539 CHECK_REFCOUNT ( pTexture , tmp+1 );
540 CHECK_RELEASE_REFCOUNT( pTexture , tmp );
541 CHECK_REFCOUNT ( pTextureLevel, tmp );
544 if(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP)
546 hr = IDirect3DDevice8_CreateCubeTexture( pDevice, 32, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pCubeTexture );
547 CHECK_CALL( hr, "CreateCubeTexture", pDevice, ++refcount );
551 skip("Cube textures not supported\n");
553 if(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP)
555 hr = IDirect3DDevice8_CreateVolumeTexture( pDevice, 32, 32, 2, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pVolumeTexture );
556 CHECK_CALL( hr, "CreateVolumeTexture", pDevice, ++refcount );
560 skip("Volume textures not supported\n");
565 tmp = get_refcount( (IUnknown *)pVolumeTexture );
567 /* This should not increment device refcount */
568 hr = IDirect3DVolumeTexture8_GetVolumeLevel(pVolumeTexture, 0, &pVolumeLevel);
569 CHECK_CALL( hr, "GetVolumeLevel", pDevice, refcount );
570 /* But should increment volume texture's refcount */
571 CHECK_REFCOUNT( pVolumeTexture, tmp+1 );
572 /* Because the volume texture and volume refcount are identical */
575 CHECK_REFCOUNT ( pVolumeLevel , tmp+1 );
576 CHECK_ADDREF_REFCOUNT ( pVolumeLevel , tmp+2 );
577 CHECK_REFCOUNT ( pVolumeTexture, tmp+2 );
578 CHECK_RELEASE_REFCOUNT( pVolumeLevel , tmp+1 );
579 CHECK_REFCOUNT ( pVolumeTexture, tmp+1 );
580 CHECK_RELEASE_REFCOUNT( pVolumeTexture, tmp );
581 CHECK_REFCOUNT ( pVolumeLevel , tmp );
585 hr = IDirect3DDevice8_CreateDepthStencilSurface( pDevice, 32, 32, D3DFMT_D16, D3DMULTISAMPLE_NONE, &pStencilSurface );
586 CHECK_CALL( hr, "CreateDepthStencilSurface", pDevice, ++refcount );
587 CHECK_REFCOUNT( pStencilSurface, 1);
588 hr = IDirect3DDevice8_CreateImageSurface( pDevice, 32, 32, D3DFMT_X8R8G8B8, &pImageSurface );
589 CHECK_CALL( hr, "CreateImageSurface", pDevice, ++refcount );
590 CHECK_REFCOUNT( pImageSurface, 1);
591 hr = IDirect3DDevice8_CreateRenderTarget( pDevice, 32, 32, D3DFMT_X8R8G8B8, D3DMULTISAMPLE_NONE, TRUE, &pRenderTarget3 );
592 CHECK_CALL( hr, "CreateRenderTarget", pDevice, ++refcount );
593 CHECK_REFCOUNT( pRenderTarget3, 1);
595 hr = IDirect3DDevice8_CreateStateBlock( pDevice, D3DSBT_ALL, &dStateBlock );
596 CHECK_CALL( hr, "CreateStateBlock", pDevice, refcount );
597 hr = IDirect3DDevice8_CreateAdditionalSwapChain( pDevice, &d3dpp, &pSwapChain );
598 CHECK_CALL( hr, "CreateAdditionalSwapChain", pDevice, ++refcount );
601 /* check implicit back buffer */
602 hr = IDirect3DSwapChain8_GetBackBuffer(pSwapChain, 0, 0, &pBackBuffer);
603 CHECK_CALL( hr, "GetBackBuffer", pDevice, ++refcount);
604 CHECK_REFCOUNT( pSwapChain, 1);
607 CHECK_SURFACE_CONTAINER( pBackBuffer, IID_IDirect3DDevice8, pDevice);
608 CHECK_REFCOUNT( pBackBuffer, 1);
609 CHECK_RELEASE_REFCOUNT( pBackBuffer, 0);
610 CHECK_REFCOUNT( pDevice, --refcount);
612 /* The back buffer is released with the swapchain, so AddRef with refcount=0 is fine here. */
613 CHECK_ADDREF_REFCOUNT(pBackBuffer, 1);
614 CHECK_REFCOUNT(pDevice, ++refcount);
615 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
616 CHECK_REFCOUNT(pDevice, --refcount);
619 CHECK_REFCOUNT( pSwapChain, 1);
625 /* Vertex buffers can be locked multiple times */
626 hr = IDirect3DVertexBuffer8_Lock(pVertexBuffer, 0, 0, &data, 0);
627 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr);
628 hr = IDirect3DVertexBuffer8_Lock(pVertexBuffer, 0, 0, &data, 0);
629 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr);
630 hr = IDirect3DVertexBuffer8_Unlock(pVertexBuffer);
631 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr);
632 hr = IDirect3DVertexBuffer8_Unlock(pVertexBuffer);
633 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr);
636 /* The implicit render target is not freed if refcount reaches 0.
637 * Otherwise GetRenderTarget would re-allocate it and the pointer would change.*/
638 hr = IDirect3DDevice8_GetRenderTarget(pDevice, &pRenderTarget2);
639 CHECK_CALL( hr, "GetRenderTarget", pDevice, ++refcount);
642 CHECK_RELEASE_REFCOUNT(pRenderTarget2, 0);
643 ok(pRenderTarget == pRenderTarget2, "RenderTarget=%p and RenderTarget2=%p should be the same.\n",
644 pRenderTarget, pRenderTarget2);
645 CHECK_REFCOUNT( pDevice, --refcount);
646 pRenderTarget2 = NULL;
648 pRenderTarget = NULL;
651 CHECK_RELEASE(pDevice, pDevice, --refcount);
654 CHECK_RELEASE(pVertexBuffer, pDevice, --refcount);
655 CHECK_RELEASE(pIndexBuffer, pDevice, --refcount);
657 if (dVertexShader != ~0U) IDirect3DDevice8_DeleteVertexShader( pDevice, dVertexShader );
658 if (dPixelShader != ~0U) IDirect3DDevice8_DeletePixelShader( pDevice, dPixelShader );
660 CHECK_RELEASE(pTexture, pDevice, --refcount);
661 CHECK_RELEASE(pCubeTexture, pDevice, --refcount);
662 CHECK_RELEASE(pVolumeTexture, pDevice, --refcount);
664 CHECK_RELEASE(pStencilSurface, pDevice, --refcount);
665 CHECK_RELEASE(pImageSurface, pDevice, --refcount);
666 CHECK_RELEASE(pRenderTarget3, pDevice, --refcount);
668 if (dStateBlock != ~0U) IDirect3DDevice8_DeleteStateBlock( pDevice, dStateBlock );
669 /* This will destroy device - cannot check the refcount here */
670 if (pSwapChain) CHECK_RELEASE_REFCOUNT( pSwapChain, 0);
672 if (pD3d) CHECK_RELEASE_REFCOUNT( pD3d, 0);
674 DestroyWindow( hwnd );
677 static void test_cursor(void)
681 IDirect3D8 *pD3d = NULL;
682 IDirect3DDevice8 *pDevice = NULL;
683 D3DPRESENT_PARAMETERS d3dpp;
684 D3DDISPLAYMODE d3ddm;
686 IDirect3DSurface8 *cursor = NULL;
688 HMODULE user32_handle = GetModuleHandleA("user32.dll");
690 pGetCursorInfo = (void *)GetProcAddress(user32_handle, "GetCursorInfo");
693 win_skip("GetCursorInfo is not available\n");
697 memset(&info, 0, sizeof(info));
698 info.cbSize = sizeof(info);
699 ok(pGetCursorInfo(&info), "GetCursorInfo failed\n");
702 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
703 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
704 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
705 ok(hwnd != NULL, "Failed to create window\n");
706 if (!pD3d || !hwnd) goto cleanup;
708 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
709 ZeroMemory( &d3dpp, sizeof(d3dpp) );
710 d3dpp.Windowed = TRUE;
711 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
712 d3dpp.BackBufferFormat = d3ddm.Format;
714 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
715 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
718 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
722 IDirect3DDevice8_CreateImageSurface(pDevice, 32, 32, D3DFMT_A8R8G8B8, &cursor);
723 ok(cursor != NULL, "IDirect3DDevice8_CreateOffscreenPlainSurface failed with %#08x\n", hr);
725 /* Initially hidden */
726 hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
727 ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
729 /* Not enabled without a surface*/
730 hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
731 ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
734 hr = IDirect3DDevice8_SetCursorProperties(pDevice, 0, 0, NULL);
735 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr);
737 hr = IDirect3DDevice8_SetCursorProperties(pDevice, 0, 0, cursor);
738 ok(hr == D3D_OK, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr);
740 IDirect3DSurface8_Release(cursor);
742 memset(&info, 0, sizeof(info));
743 info.cbSize = sizeof(info);
744 ok(pGetCursorInfo(&info), "GetCursorInfo failed\n");
745 ok(info.flags & CURSOR_SHOWING, "The gdi cursor is hidden (%08x)\n", info.flags);
746 ok(info.hCursor == cur, "The cursor handle is %p\n", info.hCursor); /* unchanged */
749 hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
750 ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
753 hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
754 ok(hr == TRUE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
756 /* GDI cursor unchanged */
757 memset(&info, 0, sizeof(info));
758 info.cbSize = sizeof(info);
759 ok(pGetCursorInfo(&info), "GetCursorInfo failed\n");
760 ok(info.flags & CURSOR_SHOWING, "The gdi cursor is hidden (%08x)\n", info.flags);
761 ok(info.hCursor == cur, "The cursor handle is %p\n", info.hCursor); /* unchanged */
766 UINT refcount = IDirect3DDevice8_Release(pDevice);
767 ok(!refcount, "Device has %u references left.\n", refcount);
769 if (pD3d) IDirect3D8_Release(pD3d);
772 static void test_states(void)
776 IDirect3D8 *pD3d = NULL;
777 IDirect3DDevice8 *pDevice = NULL;
778 D3DPRESENT_PARAMETERS d3dpp;
779 D3DDISPLAYMODE d3ddm;
781 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
782 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
783 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
784 ok(hwnd != NULL, "Failed to create window\n");
785 if (!pD3d || !hwnd) goto cleanup;
787 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
788 ZeroMemory( &d3dpp, sizeof(d3dpp) );
789 d3dpp.Windowed = TRUE;
790 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
791 d3dpp.BackBufferWidth = screen_width;
792 d3dpp.BackBufferHeight = screen_height;
793 d3dpp.BackBufferFormat = d3ddm.Format;
795 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
796 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
799 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
803 hr = IDirect3DDevice8_SetRenderState(pDevice, D3DRS_ZVISIBLE, TRUE);
804 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, TRUE) returned %#08x\n", hr);
805 hr = IDirect3DDevice8_SetRenderState(pDevice, D3DRS_ZVISIBLE, FALSE);
806 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, FALSE) returned %#08x\n", hr);
811 UINT refcount = IDirect3DDevice8_Release(pDevice);
812 ok(!refcount, "Device has %u references left.\n", refcount);
814 if (pD3d) IDirect3D8_Release(pD3d);
817 static void test_shader_versions(void)
820 IDirect3D8 *pD3d = NULL;
823 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
824 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
826 hr = IDirect3D8_GetDeviceCaps(pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dcaps);
827 ok(SUCCEEDED(hr) || hr == D3DERR_NOTAVAILABLE, "Failed to get D3D8 caps (%#08x)\n", hr);
829 ok(d3dcaps.VertexShaderVersion <= D3DVS_VERSION(1,1), "Unexpected VertexShaderVersion (%#x > %#x)\n", d3dcaps.VertexShaderVersion, D3DVS_VERSION(1,1));
830 ok(d3dcaps.PixelShaderVersion <= D3DPS_VERSION(1,4), "Unexpected PixelShaderVersion (%#x > %#x)\n", d3dcaps.PixelShaderVersion, D3DPS_VERSION(1,4));
832 skip("No Direct3D support\n");
834 IDirect3D8_Release(pD3d);
839 /* Test adapter display modes */
840 static void test_display_modes(void)
843 D3DDISPLAYMODE dmode;
847 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
848 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
851 max_modes = IDirect3D8_GetAdapterModeCount(pD3d, D3DADAPTER_DEFAULT);
853 broken(max_modes == 0), /* VMware */
854 "GetAdapterModeCount(D3DADAPTER_DEFAULT) returned 0!\n");
856 for(i=0; i<max_modes;i++) {
857 res = IDirect3D8_EnumAdapterModes(pD3d, D3DADAPTER_DEFAULT, i, &dmode);
858 ok(res==D3D_OK, "EnumAdapterModes returned %#08x for mode %u!\n", res, i);
862 ok(dmode.Format==D3DFMT_X8R8G8B8 || dmode.Format==D3DFMT_R5G6B5,
863 "Unexpected display mode returned for mode %u: %#x\n", i , dmode.Format);
866 IDirect3D8_Release(pD3d);
869 static void test_scene(void)
873 IDirect3D8 *pD3d = NULL;
874 IDirect3DDevice8 *pDevice = NULL;
875 D3DPRESENT_PARAMETERS d3dpp;
876 D3DDISPLAYMODE d3ddm;
878 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
879 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
880 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
881 ok(hwnd != NULL, "Failed to create window\n");
882 if (!pD3d || !hwnd) goto cleanup;
884 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
885 ZeroMemory( &d3dpp, sizeof(d3dpp) );
886 d3dpp.Windowed = TRUE;
887 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
888 d3dpp.BackBufferWidth = 800;
889 d3dpp.BackBufferHeight = 600;
890 d3dpp.BackBufferFormat = d3ddm.Format;
893 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
894 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
895 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL || broken(hr == D3DERR_NOTAVAILABLE), "IDirect3D8_CreateDevice failed with %#08x\n", hr);
898 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
902 /* Test an EndScene without beginscene. Should return an error */
903 hr = IDirect3DDevice8_EndScene(pDevice);
904 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
906 /* Test a normal BeginScene / EndScene pair, this should work */
907 hr = IDirect3DDevice8_BeginScene(pDevice);
908 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
911 hr = IDirect3DDevice8_EndScene(pDevice);
912 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
915 /* Test another EndScene without having begun a new scene. Should return an error */
916 hr = IDirect3DDevice8_EndScene(pDevice);
917 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
919 /* Two nested BeginScene and EndScene calls */
920 hr = IDirect3DDevice8_BeginScene(pDevice);
921 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
922 hr = IDirect3DDevice8_BeginScene(pDevice);
923 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_BeginScene returned %#08x\n", hr);
924 hr = IDirect3DDevice8_EndScene(pDevice);
925 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
926 hr = IDirect3DDevice8_EndScene(pDevice);
927 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
929 /* StretchRect does not exit in Direct3D8, so no equivalent to the d3d9 stretchrect tests */
934 UINT refcount = IDirect3DDevice8_Release(pDevice);
935 ok(!refcount, "Device has %u references left.\n", refcount);
937 if (pD3d) IDirect3D8_Release(pD3d);
938 if(hwnd) DestroyWindow(hwnd);
941 static void test_shader(void)
945 IDirect3D8 *pD3d = NULL;
946 IDirect3DDevice8 *pDevice = NULL;
947 D3DPRESENT_PARAMETERS d3dpp;
948 D3DDISPLAYMODE d3ddm;
949 DWORD hPixelShader = 0, hVertexShader = 0;
950 DWORD hPixelShader2 = 0, hVertexShader2 = 0;
953 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
957 static DWORD dwVertexDecl[] =
960 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3),
963 DWORD decl_normal_float2[] =
966 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
967 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT2), /* D3DVSDE_NORMAL, Register v1 */
970 DWORD decl_normal_float4[] =
973 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
974 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT4), /* D3DVSDE_NORMAL, Register v1 */
977 DWORD decl_normal_d3dcolor[] =
980 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
981 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_D3DCOLOR),/* D3DVSDE_NORMAL, Register v1 */
984 const DWORD vertex_decl_size = sizeof(dwVertexDecl);
985 const DWORD simple_vs_size = sizeof(simple_vs);
986 const DWORD simple_ps_size = sizeof(simple_ps);
988 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
989 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
990 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
991 ok(hwnd != NULL, "Failed to create window\n");
992 if (!pD3d || !hwnd) goto cleanup;
994 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
995 ZeroMemory( &d3dpp, sizeof(d3dpp) );
996 d3dpp.Windowed = TRUE;
997 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
998 d3dpp.BackBufferWidth = 800;
999 d3dpp.BackBufferHeight = 600;
1000 d3dpp.BackBufferFormat = d3ddm.Format;
1003 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1004 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
1005 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL || broken(hr == D3DERR_NOTAVAILABLE), "IDirect3D8_CreateDevice failed with %#08x\n", hr);
1008 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
1011 IDirect3DDevice8_GetDeviceCaps(pDevice, &caps);
1013 /* Test setting and retrieving a FVF */
1014 hr = IDirect3DDevice8_SetVertexShader(pDevice, fvf);
1015 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1016 hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
1017 ok(SUCCEEDED(hr), "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1018 ok(hTempHandle == fvf, "Vertex shader %#08x is set, expected %#08x\n", hTempHandle, fvf);
1020 /* First create a vertex shader */
1021 hr = IDirect3DDevice8_SetVertexShader(pDevice, 0);
1022 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1023 hr = IDirect3DDevice8_CreateVertexShader(pDevice, dwVertexDecl, simple_vs, &hVertexShader, 0);
1024 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1025 /* Msdn says that the new vertex shader is set immediately. This is wrong, apparently */
1026 hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
1027 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1028 ok(hTempHandle == 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, 0);
1029 /* Assign the shader, then verify that GetVertexShader works */
1030 hr = IDirect3DDevice8_SetVertexShader(pDevice, hVertexShader);
1031 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1032 hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
1033 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1034 ok(hTempHandle == hVertexShader, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, hVertexShader);
1035 /* Verify that we can retrieve the declaration */
1036 hr = IDirect3DDevice8_GetVertexShaderDeclaration(pDevice, hVertexShader, NULL, &data_size);
1037 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr);
1038 ok(data_size == vertex_decl_size, "Got data_size %u, expected %u\n", data_size, vertex_decl_size);
1039 data = HeapAlloc(GetProcessHeap(), 0, vertex_decl_size);
1041 hr = IDirect3DDevice8_GetVertexShaderDeclaration(pDevice, hVertexShader, data, &data_size);
1042 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetVertexShaderDeclaration returned (%#08x), "
1043 "expected D3DERR_INVALIDCALL\n", hr);
1044 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
1045 data_size = vertex_decl_size;
1046 hr = IDirect3DDevice8_GetVertexShaderDeclaration(pDevice, hVertexShader, data, &data_size);
1047 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr);
1048 ok(data_size == vertex_decl_size, "Got data_size %u, expected %u\n", data_size, vertex_decl_size);
1049 ok(!memcmp(data, dwVertexDecl, vertex_decl_size), "data not equal to shader declaration\n");
1050 HeapFree(GetProcessHeap(), 0, data);
1051 /* Verify that we can retrieve the shader function */
1052 hr = IDirect3DDevice8_GetVertexShaderFunction(pDevice, hVertexShader, NULL, &data_size);
1053 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr);
1054 ok(data_size == simple_vs_size, "Got data_size %u, expected %u\n", data_size, simple_vs_size);
1055 data = HeapAlloc(GetProcessHeap(), 0, simple_vs_size);
1057 hr = IDirect3DDevice8_GetVertexShaderFunction(pDevice, hVertexShader, data, &data_size);
1058 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetVertexShaderFunction returned (%#08x), "
1059 "expected D3DERR_INVALIDCALL\n", hr);
1060 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
1061 data_size = simple_vs_size;
1062 hr = IDirect3DDevice8_GetVertexShaderFunction(pDevice, hVertexShader, data, &data_size);
1063 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr);
1064 ok(data_size == simple_vs_size, "Got data_size %u, expected %u\n", data_size, simple_vs_size);
1065 ok(!memcmp(data, simple_vs, simple_vs_size), "data not equal to shader function\n");
1066 HeapFree(GetProcessHeap(), 0, data);
1067 /* Delete the assigned shader. This is supposed to work */
1068 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1069 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1070 /* The shader should be unset now */
1071 hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
1072 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1073 ok(hTempHandle == 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, 0);
1075 /* Test a broken declaration. 3DMark2001 tries to use normals with 2 components
1076 * First try the fixed function shader function, then a custom one
1078 hr = IDirect3DDevice8_CreateVertexShader(pDevice, decl_normal_float2, 0, &hVertexShader, 0);
1079 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1080 if(SUCCEEDED(hr)) IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1081 hr = IDirect3DDevice8_CreateVertexShader(pDevice, decl_normal_float4, 0, &hVertexShader, 0);
1082 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1083 if(SUCCEEDED(hr)) IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1084 hr = IDirect3DDevice8_CreateVertexShader(pDevice, decl_normal_d3dcolor, 0, &hVertexShader, 0);
1085 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1086 if(SUCCEEDED(hr)) IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1088 hr = IDirect3DDevice8_CreateVertexShader(pDevice, decl_normal_float2, simple_vs, &hVertexShader, 0);
1089 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1090 if(SUCCEEDED(hr)) IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1092 if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 0))
1094 /* The same with a pixel shader */
1095 hr = IDirect3DDevice8_CreatePixelShader(pDevice, simple_ps, &hPixelShader);
1096 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
1097 /* Msdn says that the new pixel shader is set immediately. This is wrong, apparently */
1098 hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle);
1099 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1100 ok(hTempHandle == 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, 0);
1101 /* Assign the shader, then verify that GetPixelShader works */
1102 hr = IDirect3DDevice8_SetPixelShader(pDevice, hPixelShader);
1103 ok(hr == D3D_OK, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr);
1104 hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle);
1105 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1106 ok(hTempHandle == hPixelShader, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, hPixelShader);
1107 /* Verify that we can retrieve the shader function */
1108 hr = IDirect3DDevice8_GetPixelShaderFunction(pDevice, hPixelShader, NULL, &data_size);
1109 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr);
1110 ok(data_size == simple_ps_size, "Got data_size %u, expected %u\n", data_size, simple_ps_size);
1111 data = HeapAlloc(GetProcessHeap(), 0, simple_ps_size);
1113 hr = IDirect3DDevice8_GetPixelShaderFunction(pDevice, hPixelShader, data, &data_size);
1114 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetPixelShaderFunction returned (%#08x), "
1115 "expected D3DERR_INVALIDCALL\n", hr);
1116 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
1117 data_size = simple_ps_size;
1118 hr = IDirect3DDevice8_GetPixelShaderFunction(pDevice, hPixelShader, data, &data_size);
1119 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr);
1120 ok(data_size == simple_ps_size, "Got data_size %u, expected %u\n", data_size, simple_ps_size);
1121 ok(!memcmp(data, simple_ps, simple_ps_size), "data not equal to shader function\n");
1122 HeapFree(GetProcessHeap(), 0, data);
1123 /* Delete the assigned shader. This is supposed to work */
1124 hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader);
1125 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1126 /* The shader should be unset now */
1127 hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle);
1128 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1129 ok(hTempHandle == 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, 0);
1131 /* What happens if a non-bound shader is deleted? */
1132 hr = IDirect3DDevice8_CreatePixelShader(pDevice, simple_ps, &hPixelShader);
1133 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
1134 hr = IDirect3DDevice8_CreatePixelShader(pDevice, simple_ps, &hPixelShader2);
1135 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
1137 hr = IDirect3DDevice8_SetPixelShader(pDevice, hPixelShader);
1138 ok(hr == D3D_OK, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr);
1139 hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader2);
1140 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1141 hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle);
1142 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1143 ok(hTempHandle == hPixelShader, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, hPixelShader);
1144 hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader);
1145 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1147 /* Check for double delete. */
1148 hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader2);
1149 ok(hr == D3DERR_INVALIDCALL || broken(hr == D3D_OK), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1150 hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader);
1151 ok(hr == D3DERR_INVALIDCALL || broken(hr == D3D_OK), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1155 skip("Pixel shaders not supported\n");
1158 /* What happens if a non-bound shader is deleted? */
1159 hr = IDirect3DDevice8_CreateVertexShader(pDevice, dwVertexDecl, NULL, &hVertexShader, 0);
1160 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1161 hr = IDirect3DDevice8_CreateVertexShader(pDevice, dwVertexDecl, NULL, &hVertexShader2, 0);
1162 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1164 hr = IDirect3DDevice8_SetVertexShader(pDevice, hVertexShader);
1165 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1166 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader2);
1167 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1168 hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
1169 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1170 ok(hTempHandle == hVertexShader, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, hVertexShader);
1171 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1172 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1174 /* Check for double delete. */
1175 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader2);
1176 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1177 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1178 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1183 UINT refcount = IDirect3DDevice8_Release(pDevice);
1184 ok(!refcount, "Device has %u references left.\n", refcount);
1186 if (pD3d) IDirect3D8_Release(pD3d);
1187 if(hwnd) DestroyWindow(hwnd);
1190 static void test_limits(void)
1194 IDirect3D8 *pD3d = NULL;
1195 IDirect3DDevice8 *pDevice = NULL;
1196 D3DPRESENT_PARAMETERS d3dpp;
1197 D3DDISPLAYMODE d3ddm;
1198 IDirect3DTexture8 *pTexture = NULL;
1201 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
1202 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
1203 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1204 ok(hwnd != NULL, "Failed to create window\n");
1205 if (!pD3d || !hwnd) goto cleanup;
1207 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
1208 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1209 d3dpp.Windowed = TRUE;
1210 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1211 d3dpp.BackBufferWidth = 800;
1212 d3dpp.BackBufferHeight = 600;
1213 d3dpp.BackBufferFormat = d3ddm.Format;
1214 d3dpp.EnableAutoDepthStencil = TRUE;
1215 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
1217 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1218 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
1219 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL || broken(hr == D3DERR_NOTAVAILABLE), "IDirect3D8_CreateDevice failed with %#08x\n", hr);
1222 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
1226 hr = IDirect3DDevice8_CreateTexture(pDevice, 16, 16, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pTexture);
1227 ok(hr == D3D_OK, "IDirect3DDevice8_CreateTexture failed with %#08x\n", hr);
1228 if(!pTexture) goto cleanup;
1230 /* There are 8 texture stages. We should be able to access all of them */
1231 for(i = 0; i < 8; i++) {
1232 hr = IDirect3DDevice8_SetTexture(pDevice, i, (IDirect3DBaseTexture8 *) pTexture);
1233 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i, hr);
1234 hr = IDirect3DDevice8_SetTexture(pDevice, i, NULL);
1235 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i, hr);
1236 hr = IDirect3DDevice8_SetTextureStageState(pDevice, i, D3DTSS_COLOROP, D3DTOP_ADD);
1237 ok(hr == D3D_OK, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %#08x\n", i, hr);
1240 /* Investigations show that accessing higher textures stage states does not return an error either. Writing
1241 * to too high texture stages(approximately texture 40) causes memory corruption in windows, so there is no
1242 * bounds checking but how do I test that?
1246 if(pTexture) IDirect3DTexture8_Release(pTexture);
1249 UINT refcount = IDirect3DDevice8_Release(pDevice);
1250 ok(!refcount, "Device has %u references left.\n", refcount);
1252 if (pD3d) IDirect3D8_Release(pD3d);
1253 if(hwnd) DestroyWindow(hwnd);
1256 static void test_lights(void)
1258 D3DPRESENT_PARAMETERS d3dpp;
1259 IDirect3DDevice8 *device = NULL;
1266 D3DDISPLAYMODE d3ddm;
1268 d3d8 = pDirect3DCreate8( D3D_SDK_VERSION );
1269 ok(d3d8 != NULL, "Failed to create IDirect3D8 object\n");
1270 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1271 ok(hwnd != NULL, "Failed to create window\n");
1272 if (!d3d8 || !hwnd) goto cleanup;
1274 IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &d3ddm );
1275 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1276 d3dpp.Windowed = TRUE;
1277 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1278 d3dpp.BackBufferWidth = 800;
1279 d3dpp.BackBufferHeight = 600;
1280 d3dpp.BackBufferFormat = d3ddm.Format;
1281 d3dpp.EnableAutoDepthStencil = TRUE;
1282 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
1284 hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1285 D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &d3dpp, &device );
1286 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE || hr == D3DERR_INVALIDCALL,
1287 "IDirect3D8_CreateDevice failed with %08x\n", hr);
1290 skip("Failed to create a d3d device\n");
1294 memset(&caps, 0, sizeof(caps));
1295 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
1296 ok(hr == D3D_OK, "IDirect3DDevice8_GetDeviceCaps failed with %08x\n", hr);
1298 for(i = 1; i <= caps.MaxActiveLights; i++) {
1299 hr = IDirect3DDevice8_LightEnable(device, i, TRUE);
1300 ok(hr == D3D_OK, "Enabling light %u failed with %08x\n", i, hr);
1301 hr = IDirect3DDevice8_GetLightEnable(device, i, &enabled);
1302 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL),
1303 "GetLightEnable on light %u failed with %08x\n", i, hr);
1304 ok(enabled, "Light %d is %s\n", i, enabled ? "enabled" : "disabled");
1307 /* TODO: Test the rendering results in this situation */
1308 hr = IDirect3DDevice8_LightEnable(device, i + 1, TRUE);
1309 ok(hr == D3D_OK, "Enabling one light more than supported returned %08x\n", hr);
1310 hr = IDirect3DDevice8_GetLightEnable(device, i + 1, &enabled);
1311 ok(hr == D3D_OK, "GetLightEnable on light %u failed with %08x\n", i + 1, hr);
1312 ok(enabled, "Light %d is %s\n", i + 1, enabled ? "enabled" : "disabled");
1313 hr = IDirect3DDevice8_LightEnable(device, i + 1, FALSE);
1314 ok(hr == D3D_OK, "Disabling the additional returned %08x\n", hr);
1316 for(i = 1; i <= caps.MaxActiveLights; i++) {
1317 hr = IDirect3DDevice8_LightEnable(device, i, FALSE);
1318 ok(hr == D3D_OK, "Disabling light %u failed with %08x\n", i, hr);
1324 UINT refcount = IDirect3DDevice8_Release(device);
1325 ok(!refcount, "Device has %u references left.\n", refcount);
1327 if (d3d8) IDirect3D8_Release(d3d8);
1330 static void test_render_zero_triangles(void)
1332 D3DPRESENT_PARAMETERS d3dpp;
1333 IDirect3DDevice8 *device = NULL;
1337 D3DDISPLAYMODE d3ddm;
1346 { 0.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
1347 { 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
1348 { 1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
1349 { 1.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
1352 d3d8 = pDirect3DCreate8( D3D_SDK_VERSION );
1353 ok(d3d8 != NULL, "Failed to create IDirect3D8 object\n");
1354 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1355 ok(hwnd != NULL, "Failed to create window\n");
1356 if (!d3d8 || !hwnd) goto cleanup;
1358 IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &d3ddm );
1359 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1360 d3dpp.Windowed = TRUE;
1361 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1362 d3dpp.BackBufferWidth = 800;
1363 d3dpp.BackBufferHeight = 600;
1364 d3dpp.BackBufferFormat = d3ddm.Format;
1365 d3dpp.EnableAutoDepthStencil = TRUE;
1366 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
1368 hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1369 D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &d3dpp, &device );
1370 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE || hr == D3DERR_INVALIDCALL,
1371 "IDirect3D8_CreateDevice failed with %08x\n", hr);
1374 skip("Failed to create a d3d device\n");
1378 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
1379 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1381 hr = IDirect3DDevice8_BeginScene(device);
1382 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
1385 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 0 /* NumVerts */,
1386 0 /*PrimCount */, NULL, D3DFMT_INDEX16, quad, sizeof(quad[0]));
1387 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr);
1389 IDirect3DDevice8_EndScene(device);
1390 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
1393 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1398 UINT refcount = IDirect3DDevice8_Release(device);
1399 ok(!refcount, "Device has %u references left.\n", refcount);
1401 if (d3d8) IDirect3D8_Release(d3d8);
1404 static void test_depth_stencil_reset(void)
1406 D3DPRESENT_PARAMETERS present_parameters;
1407 D3DDISPLAYMODE display_mode;
1408 IDirect3DSurface8 *surface;
1409 IDirect3DDevice8 *device = NULL;
1415 d3d8 = pDirect3DCreate8(D3D_SDK_VERSION);
1416 ok(d3d8 != NULL, "Failed to create IDirect3D8 object\n");
1417 hwnd = CreateWindow("static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL);
1418 ok(hwnd != NULL, "Failed to create window\n");
1419 if (!d3d8 || !hwnd) goto cleanup;
1421 IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &display_mode);
1422 memset(&present_parameters, 0, sizeof(present_parameters));
1423 present_parameters.Windowed = TRUE;
1424 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
1425 present_parameters.BackBufferFormat = display_mode.Format;
1426 present_parameters.EnableAutoDepthStencil = TRUE;
1427 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
1429 hr = IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
1430 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
1433 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr);
1437 hr = IDirect3DDevice8_TestCooperativeLevel(device);
1438 ok(SUCCEEDED(hr), "TestCooperativeLevel failed with %#x\n", hr);
1440 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, NULL);
1441 ok(hr == D3D_OK, "SetRenderTarget failed with 0x%08x\n", hr);
1443 hr = IDirect3DDevice8_GetRenderTarget(device, &surface);
1444 ok(hr == D3D_OK, "GetRenderTarget failed with 0x%08x\n", hr);
1445 ok(surface != NULL, "Render target should not be NULL\n");
1446 if (surface) IDirect3DSurface8_Release(surface);
1448 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
1449 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr);
1450 ok(surface == NULL, "Depth stencil should be NULL\n");
1452 present_parameters.EnableAutoDepthStencil = TRUE;
1453 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
1454 hr = IDirect3DDevice8_Reset(device, &present_parameters);
1455 ok(hr == D3D_OK, "Reset failed with 0x%08x\n", hr);
1457 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
1458 ok(hr == D3D_OK, "GetDepthStencilSurface failed with 0x%08x\n", hr);
1459 ok(surface != NULL, "Depth stencil should not be NULL\n");
1460 if (surface) IDirect3DSurface8_Release(surface);
1462 present_parameters.EnableAutoDepthStencil = FALSE;
1463 hr = IDirect3DDevice8_Reset(device, &present_parameters);
1464 ok(hr == D3D_OK, "Reset failed with 0x%08x\n", hr);
1466 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
1467 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr);
1468 ok(surface == NULL, "Depth stencil should be NULL\n");
1470 refcount = IDirect3DDevice8_Release(device);
1471 ok(!refcount, "Device has %u references left.\n", refcount);
1474 IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &display_mode );
1476 ZeroMemory( &present_parameters, sizeof(present_parameters) );
1477 present_parameters.Windowed = TRUE;
1478 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
1479 present_parameters.BackBufferFormat = display_mode.Format;
1480 present_parameters.EnableAutoDepthStencil = FALSE;
1481 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
1483 hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
1484 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device );
1488 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr);
1492 hr = IDirect3DDevice8_TestCooperativeLevel(device);
1493 ok(hr == D3D_OK, "IDirect3DDevice8_TestCooperativeLevel after creation returned %#x\n", hr);
1495 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
1496 present_parameters.Windowed = TRUE;
1497 present_parameters.BackBufferWidth = 400;
1498 present_parameters.BackBufferHeight = 300;
1499 present_parameters.EnableAutoDepthStencil = TRUE;
1500 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
1502 hr = IDirect3DDevice8_Reset(device, &present_parameters);
1503 ok(hr == D3D_OK, "IDirect3DDevice8_Reset failed with 0x%08x\n", hr);
1505 if (FAILED(hr)) goto cleanup;
1507 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
1508 ok(hr == D3D_OK, "GetDepthStencilSurface failed with 0x%08x\n", hr);
1509 ok(surface != NULL, "Depth stencil should not be NULL\n");
1510 if (surface) IDirect3DSurface8_Release(surface);
1515 refcount = IDirect3DDevice8_Release(device);
1516 ok(!refcount, "Device has %u references left.\n", refcount);
1518 if (d3d8) IDirect3D8_Release(d3d8);
1521 static HWND filter_messages;
1532 enum message_window window;
1535 static const struct message *expect_messages;
1536 static HWND device_window, focus_window;
1538 struct wndproc_thread_param
1541 HANDLE window_created;
1542 HANDLE test_finished;
1543 BOOL running_in_foreground;
1546 static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
1548 if (filter_messages && filter_messages == hwnd)
1550 if (message != WM_DISPLAYCHANGE && message != WM_IME_NOTIFY)
1551 todo_wine ok(0, "Received unexpected message %#x for window %p.\n", message, hwnd);
1554 if (expect_messages)
1558 switch (expect_messages->window)
1573 if (hwnd == w && expect_messages->message == message) ++expect_messages;
1576 return DefWindowProcA(hwnd, message, wparam, lparam);
1579 static DWORD WINAPI wndproc_thread(void *param)
1581 struct wndproc_thread_param *p = param;
1585 p->dummy_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
1586 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, screen_width, screen_height, 0, 0, 0, 0);
1587 p->running_in_foreground = SetForegroundWindow(p->dummy_window);
1589 ret = SetEvent(p->window_created);
1590 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
1596 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
1597 res = WaitForSingleObject(p->test_finished, 100);
1598 if (res == WAIT_OBJECT_0) break;
1599 if (res != WAIT_TIMEOUT)
1601 ok(0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
1606 DestroyWindow(p->dummy_window);
1611 static void test_wndproc(void)
1613 struct wndproc_thread_param thread_params;
1614 IDirect3DDevice8 *device;
1623 static const struct message messages[] =
1625 {WM_WINDOWPOSCHANGING, FOCUS_WINDOW},
1626 {WM_ACTIVATE, FOCUS_WINDOW},
1627 {WM_SETFOCUS, FOCUS_WINDOW},
1628 {WM_WINDOWPOSCHANGING, DEVICE_WINDOW},
1629 {WM_MOVE, DEVICE_WINDOW},
1630 {WM_SIZE, DEVICE_WINDOW},
1634 if (!(d3d8 = pDirect3DCreate8(D3D_SDK_VERSION)))
1636 skip("Failed to create IDirect3D8 object, skipping tests.\n");
1640 wc.lpfnWndProc = test_proc;
1641 wc.lpszClassName = "d3d8_test_wndproc_wc";
1642 ok(RegisterClassA(&wc), "Failed to register window class.\n");
1644 thread_params.window_created = CreateEvent(NULL, FALSE, FALSE, NULL);
1645 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
1646 thread_params.test_finished = CreateEvent(NULL, FALSE, FALSE, NULL);
1647 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
1649 focus_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
1650 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, screen_width, screen_height, 0, 0, 0, 0);
1651 device_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
1652 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, screen_width, screen_height, 0, 0, 0, 0);
1653 thread = CreateThread(NULL, 0, wndproc_thread, &thread_params, 0, &tid);
1654 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
1656 res = WaitForSingleObject(thread_params.window_created, INFINITE);
1657 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
1659 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
1660 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1661 (LONG_PTR)test_proc, proc);
1662 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1663 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1664 (LONG_PTR)test_proc, proc);
1666 trace("device_window %p, focus_window %p, dummy_window %p.\n",
1667 device_window, focus_window, thread_params.dummy_window);
1670 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
1671 if (thread_params.running_in_foreground)
1673 tmp = GetForegroundWindow();
1674 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
1675 thread_params.dummy_window, tmp);
1678 skip("Not running in foreground, skip foreground window test\n");
1682 expect_messages = messages;
1684 device = create_device(d3d8, device_window, focus_window, FALSE);
1687 skip("Failed to create a D3D device, skipping tests.\n");
1691 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
1692 expect_messages->message, expect_messages->window);
1693 expect_messages = NULL;
1695 if (0) /* Disabled until we can make this work in a reliable way on Wine. */
1698 ok(tmp == focus_window, "Expected focus %p, got %p.\n", focus_window, tmp);
1699 tmp = GetForegroundWindow();
1700 ok(tmp == focus_window, "Expected foreground window %p, got %p.\n", focus_window, tmp);
1702 SetForegroundWindow(focus_window);
1705 filter_messages = focus_window;
1707 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
1708 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1709 (LONG_PTR)test_proc, proc);
1711 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1712 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
1713 (LONG_PTR)test_proc, proc);
1715 ref = IDirect3DDevice8_Release(device);
1716 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
1718 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1719 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1720 (LONG_PTR)test_proc, proc);
1722 device = create_device(d3d8, focus_window, focus_window, FALSE);
1725 skip("Failed to create a D3D device, skipping tests.\n");
1729 ref = IDirect3DDevice8_Release(device);
1730 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
1732 device = create_device(d3d8, device_window, focus_window, FALSE);
1735 skip("Failed to create a D3D device, skipping tests.\n");
1739 proc = SetWindowLongPtrA(focus_window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
1740 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
1741 (LONG_PTR)test_proc, proc);
1743 ref = IDirect3DDevice8_Release(device);
1744 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
1746 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1747 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
1748 (LONG_PTR)DefWindowProcA, proc);
1751 filter_messages = NULL;
1752 IDirect3D8_Release(d3d8);
1754 SetEvent(thread_params.test_finished);
1755 WaitForSingleObject(thread, INFINITE);
1756 CloseHandle(thread_params.test_finished);
1757 CloseHandle(thread_params.window_created);
1758 CloseHandle(thread);
1760 DestroyWindow(device_window);
1761 DestroyWindow(focus_window);
1762 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL));
1765 static void test_wndproc_windowed(void)
1767 struct wndproc_thread_param thread_params;
1768 IDirect3DDevice8 *device;
1778 if (!(d3d8 = pDirect3DCreate8(D3D_SDK_VERSION)))
1780 skip("Failed to create IDirect3D8 object, skipping tests.\n");
1784 wc.lpfnWndProc = test_proc;
1785 wc.lpszClassName = "d3d8_test_wndproc_wc";
1786 ok(RegisterClassA(&wc), "Failed to register window class.\n");
1788 thread_params.window_created = CreateEvent(NULL, FALSE, FALSE, NULL);
1789 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
1790 thread_params.test_finished = CreateEvent(NULL, FALSE, FALSE, NULL);
1791 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
1793 focus_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
1794 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, screen_width, screen_height, 0, 0, 0, 0);
1795 device_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
1796 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, screen_width, screen_height, 0, 0, 0, 0);
1797 thread = CreateThread(NULL, 0, wndproc_thread, &thread_params, 0, &tid);
1798 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
1800 res = WaitForSingleObject(thread_params.window_created, INFINITE);
1801 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
1803 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
1804 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1805 (LONG_PTR)test_proc, proc);
1806 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1807 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1808 (LONG_PTR)test_proc, proc);
1810 trace("device_window %p, focus_window %p, dummy_window %p.\n",
1811 device_window, focus_window, thread_params.dummy_window);
1814 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
1815 if (thread_params.running_in_foreground)
1817 tmp = GetForegroundWindow();
1818 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
1819 thread_params.dummy_window, tmp);
1822 skip("Not running in foreground, skip foreground window test\n");
1824 filter_messages = focus_window;
1826 device = create_device(d3d8, device_window, focus_window, TRUE);
1829 skip("Failed to create a D3D device, skipping tests.\n");
1834 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
1835 tmp = GetForegroundWindow();
1836 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
1837 thread_params.dummy_window, tmp);
1839 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
1840 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1841 (LONG_PTR)test_proc, proc);
1843 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1844 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1845 (LONG_PTR)test_proc, proc);
1847 filter_messages = NULL;
1849 hr = reset_device(device, device_window, FALSE);
1850 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
1852 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
1853 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1854 (LONG_PTR)test_proc, proc);
1856 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1857 ok(proc != (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1858 (LONG_PTR)test_proc, proc);
1860 hr = reset_device(device, device_window, TRUE);
1861 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
1863 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
1864 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1865 (LONG_PTR)test_proc, proc);
1867 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1868 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1869 (LONG_PTR)test_proc, proc);
1871 filter_messages = focus_window;
1873 ref = IDirect3DDevice8_Release(device);
1874 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
1876 filter_messages = device_window;
1878 device = create_device(d3d8, focus_window, focus_window, TRUE);
1881 skip("Failed to create a D3D device, skipping tests.\n");
1885 filter_messages = NULL;
1887 hr = reset_device(device, focus_window, FALSE);
1888 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
1890 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
1891 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1892 (LONG_PTR)test_proc, proc);
1894 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1895 ok(proc != (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1896 (LONG_PTR)test_proc, proc);
1898 hr = reset_device(device, focus_window, TRUE);
1899 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
1901 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
1902 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1903 (LONG_PTR)test_proc, proc);
1905 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1906 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1907 (LONG_PTR)test_proc, proc);
1909 filter_messages = device_window;
1911 ref = IDirect3DDevice8_Release(device);
1912 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
1914 device = create_device(d3d8, device_window, focus_window, TRUE);
1917 skip("Failed to create a D3D device, skipping tests.\n");
1921 filter_messages = NULL;
1923 hr = reset_device(device, device_window, FALSE);
1924 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
1926 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
1927 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1928 (LONG_PTR)test_proc, proc);
1930 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1931 ok(proc != (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1932 (LONG_PTR)test_proc, proc);
1934 hr = reset_device(device, device_window, TRUE);
1935 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
1937 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
1938 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1939 (LONG_PTR)test_proc, proc);
1941 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1942 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1943 (LONG_PTR)test_proc, proc);
1945 filter_messages = device_window;
1947 ref = IDirect3DDevice8_Release(device);
1948 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
1951 filter_messages = NULL;
1952 IDirect3D8_Release(d3d8);
1954 SetEvent(thread_params.test_finished);
1955 WaitForSingleObject(thread, INFINITE);
1956 CloseHandle(thread_params.test_finished);
1957 CloseHandle(thread_params.window_created);
1958 CloseHandle(thread);
1960 DestroyWindow(device_window);
1961 DestroyWindow(focus_window);
1962 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL));
1965 static inline void set_fpu_cw(WORD cw)
1967 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1968 __asm__ volatile ("fnclex");
1969 __asm__ volatile ("fldcw %0" : : "m" (cw));
1973 static inline WORD get_fpu_cw(void)
1976 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1977 __asm__ volatile ("fnstcw %0" : "=m" (cw));
1982 static void test_fpu_setup(void)
1984 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1985 D3DPRESENT_PARAMETERS present_parameters;
1986 IDirect3DDevice8 *device;
1987 D3DDISPLAYMODE d3ddm;
1993 d3d8 = pDirect3DCreate8(D3D_SDK_VERSION);
1994 ok(!!d3d8, "Failed to create a d3d8 object.\n");
1997 window = CreateWindowA("static", "d3d8_test", WS_CAPTION, 0, 0, screen_width, screen_height, 0, 0, 0, 0);
1998 ok(!!window, "Failed to create a window.\n");
1999 if (!window) goto done;
2001 hr = IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &d3ddm);
2002 ok(SUCCEEDED(hr), "GetAdapterDisplayMode failed, hr %#x.\n", hr);
2004 memset(&present_parameters, 0, sizeof(present_parameters));
2005 present_parameters.Windowed = TRUE;
2006 present_parameters.hDeviceWindow = window;
2007 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
2008 present_parameters.BackBufferFormat = d3ddm.Format;
2012 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
2014 hr = IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
2015 D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device);
2018 skip("Failed to create a device, hr %#x.\n", hr);
2024 ok(cw == 0x7f, "cw is %#x, expected 0x7f.\n", cw);
2026 IDirect3DDevice8_Release(device);
2029 ok(cw == 0x7f, "cw is %#x, expected 0x7f.\n", cw);
2032 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
2034 hr = IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
2035 D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &present_parameters, &device);
2036 ok(SUCCEEDED(hr), "CreateDevice failed, hr %#x.\n", hr);
2039 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
2042 IDirect3DDevice8_Release(device);
2045 if (window) DestroyWindow(window);
2046 if (d3d8) IDirect3D8_Release(d3d8);
2050 static void test_ApplyStateBlock(void)
2052 D3DPRESENT_PARAMETERS d3dpp;
2053 IDirect3DDevice8 *device = NULL;
2057 D3DDISPLAYMODE d3ddm;
2058 DWORD received, token;
2060 d3d8 = pDirect3DCreate8( D3D_SDK_VERSION );
2061 ok(d3d8 != NULL, "Failed to create IDirect3D8 object\n");
2062 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
2063 ok(hwnd != NULL, "Failed to create window\n");
2064 if (!d3d8 || !hwnd) goto cleanup;
2066 IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &d3ddm );
2067 ZeroMemory( &d3dpp, sizeof(d3dpp) );
2068 d3dpp.Windowed = TRUE;
2069 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
2070 d3dpp.BackBufferWidth = 800;
2071 d3dpp.BackBufferHeight = 600;
2072 d3dpp.BackBufferFormat = d3ddm.Format;
2073 d3dpp.EnableAutoDepthStencil = TRUE;
2074 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
2076 hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
2077 D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &d3dpp, &device );
2078 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE || hr == D3DERR_INVALIDCALL,
2079 "IDirect3D8_CreateDevice failed with %#x\n", hr);
2082 skip("Failed to create a d3d device\n");
2086 IDirect3DDevice8_BeginStateBlock(device);
2087 IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, TRUE);
2088 IDirect3DDevice8_EndStateBlock(device, &token);
2089 ok(token, "Received zero stateblock handle.\n");
2090 IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, FALSE);
2092 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_ZENABLE, &received);
2093 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
2094 ok(!received, "Expected = FALSE, received TRUE.\n");
2096 IDirect3DDevice8_ApplyStateBlock(device, 0);
2097 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
2098 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_ZENABLE, &received);
2099 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
2100 ok(!received, "Expected FALSE, received TRUE.\n");
2102 IDirect3DDevice8_ApplyStateBlock(device, token);
2103 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
2104 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_ZENABLE, &received);
2105 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
2106 ok(received, "Expected TRUE, received FALSE.\n");
2108 IDirect3DDevice8_DeleteStateBlock(device, token);
2109 IDirect3DDevice8_Release(device);
2111 if (d3d8) IDirect3D8_Release(d3d8);
2116 HMODULE d3d8_handle = LoadLibraryA( "d3d8.dll" );
2119 skip("Could not load d3d8.dll\n");
2123 pDirect3DCreate8 = (void *)GetProcAddress( d3d8_handle, "Direct3DCreate8" );
2124 ok(pDirect3DCreate8 != NULL, "Failed to get address of Direct3DCreate8\n");
2125 if (pDirect3DCreate8)
2128 d3d8 = pDirect3DCreate8( D3D_SDK_VERSION );
2131 skip("could not create D3D8\n");
2134 IDirect3D8_Release(d3d8);
2136 screen_width = GetSystemMetrics(SM_CXSCREEN);
2137 screen_height = GetSystemMetrics(SM_CYSCREEN);
2140 test_display_modes();
2141 test_shader_versions();
2144 test_mipmap_levels();
2151 test_ApplyStateBlock();
2152 test_render_zero_triangles();
2153 test_depth_stencil_reset();
2155 test_wndproc_windowed();