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 IDirect3D8 *(WINAPI *pDirect3DCreate8)(UINT);
27 static BOOL (WINAPI *pGetCursorInfo)(PCURSORINFO);
29 static const DWORD simple_vs[] = {0xFFFE0101, /* vs_1_1 */
30 0x00000009, 0xC0010000, 0x90E40000, 0xA0E40000, /* dp4 oPos.x, v0, c0 */
31 0x00000009, 0xC0020000, 0x90E40000, 0xA0E40001, /* dp4 oPos.y, v0, c1 */
32 0x00000009, 0xC0040000, 0x90E40000, 0xA0E40002, /* dp4 oPos.z, v0, c2 */
33 0x00000009, 0xC0080000, 0x90E40000, 0xA0E40003, /* dp4 oPos.w, v0, c3 */
34 0x0000FFFF}; /* END */
35 static const DWORD simple_ps[] = {0xFFFF0101, /* ps_1_1 */
36 0x00000051, 0xA00F0001, 0x3F800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
37 0x00000042, 0xB00F0000, /* tex t0 */
38 0x00000008, 0x800F0000, 0xA0E40001, 0xA0E40000, /* dp3 r0, c1, c0 */
39 0x00000005, 0x800F0000, 0x90E40000, 0x80E40000, /* mul r0, v0, r0 */
40 0x00000005, 0x800F0000, 0xB0E40000, 0x80E40000, /* mul r0, t0, r0 */
41 0x0000FFFF}; /* END */
43 static int get_refcount(IUnknown *object)
45 IUnknown_AddRef( object );
46 return IUnknown_Release( object );
49 /* try to make sure pending X events have been processed before continuing */
50 static void flush_events(void)
54 int min_timeout = 100;
55 DWORD time = GetTickCount() + diff;
59 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
60 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
61 diff = time - GetTickCount();
65 static IDirect3DDevice8 *create_device(IDirect3D8 *d3d8, HWND device_window, HWND focus_window, BOOL windowed)
67 D3DPRESENT_PARAMETERS present_parameters = {0};
68 IDirect3DDevice8 *device;
70 present_parameters.Windowed = windowed;
71 present_parameters.hDeviceWindow = device_window;
72 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
73 present_parameters.BackBufferWidth = 640;
74 present_parameters.BackBufferHeight = 480;
75 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
76 present_parameters.EnableAutoDepthStencil = TRUE;
77 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
79 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
80 D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device))) return device;
82 present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
83 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
84 D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device))) return device;
86 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
87 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device))) return device;
92 static HRESULT reset_device(IDirect3DDevice8 *device, HWND device_window, BOOL windowed)
94 D3DPRESENT_PARAMETERS present_parameters = {0};
96 present_parameters.Windowed = windowed;
97 present_parameters.hDeviceWindow = device_window;
98 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
99 present_parameters.BackBufferWidth = 640;
100 present_parameters.BackBufferHeight = 480;
101 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
102 present_parameters.EnableAutoDepthStencil = TRUE;
103 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
105 return IDirect3DDevice8_Reset(device, &present_parameters);
108 #define CHECK_CALL(r,c,d,rc) \
110 int tmp1 = get_refcount( (IUnknown *)d ); \
112 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
114 trace("%s failed: %#08x\n", c, r); \
117 #define CHECK_RELEASE(obj,d,rc) \
119 int tmp1, rc_new = rc; \
120 IUnknown_Release( obj ); \
121 tmp1 = get_refcount( (IUnknown *)d ); \
122 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
125 #define CHECK_REFCOUNT(obj,rc) \
128 int count = get_refcount( (IUnknown *)obj ); \
129 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
132 #define CHECK_RELEASE_REFCOUNT(obj,rc) \
135 int count = IUnknown_Release( (IUnknown *)obj ); \
136 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
139 #define CHECK_ADDREF_REFCOUNT(obj,rc) \
142 int count = IUnknown_AddRef( (IUnknown *)obj ); \
143 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
146 #define CHECK_SURFACE_CONTAINER(obj,iid,expected) \
148 void *container_ptr = (void *)0x1337c0d3; \
149 hr = IDirect3DSurface8_GetContainer(obj, &iid, &container_ptr); \
150 ok(SUCCEEDED(hr) && container_ptr == expected, "GetContainer returned: hr %#08x, container_ptr %p. " \
151 "Expected hr %#08x, container_ptr %p\n", hr, container_ptr, S_OK, expected); \
152 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr); \
155 static void check_mipmap_levels(IDirect3DDevice8 *device, UINT width, UINT height, UINT count)
157 IDirect3DBaseTexture8* texture = NULL;
158 HRESULT hr = IDirect3DDevice8_CreateTexture( device, width, height, 0, 0,
159 D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, (IDirect3DTexture8**) &texture );
162 DWORD levels = IDirect3DBaseTexture8_GetLevelCount(texture);
163 ok(levels == count, "Invalid level count. Expected %d got %u\n", count, levels);
165 trace("CreateTexture failed: %#08x\n", hr);
167 if (texture) IUnknown_Release( texture );
170 static void test_mipmap_levels(void)
176 IDirect3D8 *pD3d = NULL;
177 IDirect3DDevice8 *pDevice = NULL;
178 D3DPRESENT_PARAMETERS d3dpp;
179 D3DDISPLAYMODE d3ddm;
181 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
182 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
183 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
184 ok(hwnd != NULL, "Failed to create window\n");
185 if (!pD3d || !hwnd) goto cleanup;
187 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
188 ZeroMemory( &d3dpp, sizeof(d3dpp) );
189 d3dpp.Windowed = TRUE;
190 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
191 d3dpp.BackBufferFormat = d3ddm.Format;
193 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
194 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
197 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
201 check_mipmap_levels(pDevice, 32, 32, 6);
202 check_mipmap_levels(pDevice, 256, 1, 9);
203 check_mipmap_levels(pDevice, 1, 256, 9);
204 check_mipmap_levels(pDevice, 1, 1, 1);
209 UINT refcount = IUnknown_Release( pDevice );
210 ok(!refcount, "Device has %u references left.\n", refcount);
212 if (pD3d) IUnknown_Release( pD3d );
213 DestroyWindow( hwnd );
216 static void test_swapchain(void)
220 IDirect3D8 *pD3d = NULL;
221 IDirect3DDevice8 *pDevice = NULL;
222 IDirect3DSwapChain8 *swapchain1 = NULL;
223 IDirect3DSwapChain8 *swapchain2 = NULL;
224 IDirect3DSwapChain8 *swapchain3 = NULL;
225 IDirect3DSurface8 *backbuffer = NULL;
226 D3DPRESENT_PARAMETERS d3dpp;
227 D3DDISPLAYMODE d3ddm;
229 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
230 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
231 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
232 ok(hwnd != NULL, "Failed to create window\n");
233 if (!pD3d || !hwnd) goto cleanup;
235 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
236 ZeroMemory( &d3dpp, sizeof(d3dpp) );
237 d3dpp.Windowed = TRUE;
238 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
239 d3dpp.BackBufferFormat = d3ddm.Format;
240 d3dpp.BackBufferCount = 0;
242 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
243 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
246 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
250 /* Check if the back buffer count was modified */
251 ok(d3dpp.BackBufferCount == 1, "The back buffer count in the presentparams struct is %d\n", d3dpp.BackBufferCount);
253 /* Create a bunch of swapchains */
254 d3dpp.BackBufferCount = 0;
255 hr = IDirect3DDevice8_CreateAdditionalSwapChain(pDevice, &d3dpp, &swapchain1);
256 ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr);
257 ok(d3dpp.BackBufferCount == 1, "The back buffer count in the presentparams struct is %d\n", d3dpp.BackBufferCount);
259 d3dpp.BackBufferCount = 1;
260 hr = IDirect3DDevice8_CreateAdditionalSwapChain(pDevice, &d3dpp, &swapchain2);
261 ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr);
263 d3dpp.BackBufferCount = 2;
264 hr = IDirect3DDevice8_CreateAdditionalSwapChain(pDevice, &d3dpp, &swapchain3);
265 ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr);
267 /* Swapchain 3, created with backbuffercount 2 */
268 backbuffer = (void *) 0xdeadbeef;
269 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 0, 0, &backbuffer);
270 ok(SUCCEEDED(hr), "Failed to get the 1st back buffer (%#08x)\n", hr);
271 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
272 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
274 backbuffer = (void *) 0xdeadbeef;
275 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 1, 0, &backbuffer);
276 ok(SUCCEEDED(hr), "Failed to get the 2nd back buffer (%#08x)\n", hr);
277 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
278 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
280 backbuffer = (void *) 0xdeadbeef;
281 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 2, 0, &backbuffer);
282 ok(hr == D3DERR_INVALIDCALL, "GetBackBuffer returned %#08x\n", hr);
283 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
284 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
286 backbuffer = (void *) 0xdeadbeef;
287 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 3, 0, &backbuffer);
288 ok(FAILED(hr), "Failed to get the back buffer (%#08x)\n", hr);
289 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
290 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
293 /* Check the back buffers of the swapchains */
294 /* Swapchain 1, created with backbuffercount 0 */
295 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain1, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
296 ok(SUCCEEDED(hr), "Failed to get the back buffer (%#08x)\n", hr);
297 ok(backbuffer != NULL, "The back buffer is NULL (%#08x)\n", hr);
298 if(backbuffer) IDirect3DSurface8_Release(backbuffer);
300 backbuffer = (void *) 0xdeadbeef;
301 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain1, 1, 0, &backbuffer);
302 ok(FAILED(hr), "Failed to get the back buffer (%#08x)\n", hr);
303 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
304 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
306 /* Swapchain 2 - created with backbuffercount 1 */
307 backbuffer = (void *) 0xdeadbeef;
308 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 0, 0, &backbuffer);
309 ok(SUCCEEDED(hr), "Failed to get the back buffer (%#08x)\n", hr);
310 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
311 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
313 backbuffer = (void *) 0xdeadbeef;
314 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 1, 0, &backbuffer);
315 ok(hr == D3DERR_INVALIDCALL, "GetBackBuffer returned %#08x\n", hr);
316 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
317 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
319 backbuffer = (void *) 0xdeadbeef;
320 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 2, 0, &backbuffer);
321 ok(FAILED(hr), "Failed to get the back buffer (%#08x)\n", hr);
322 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
323 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
326 if(swapchain1) IDirect3DSwapChain8_Release(swapchain1);
327 if(swapchain2) IDirect3DSwapChain8_Release(swapchain2);
328 if(swapchain3) IDirect3DSwapChain8_Release(swapchain3);
331 UINT refcount = IDirect3DDevice8_Release(pDevice);
332 ok(!refcount, "Device has %u references left.\n", refcount);
334 if (pD3d) IDirect3D8_Release(pD3d);
335 DestroyWindow( hwnd );
338 static void test_refcount(void)
342 IDirect3D8 *pD3d = NULL;
343 IDirect3DDevice8 *pDevice = NULL;
344 IDirect3DVertexBuffer8 *pVertexBuffer = NULL;
345 IDirect3DIndexBuffer8 *pIndexBuffer = NULL;
346 DWORD dVertexShader = -1;
347 DWORD dPixelShader = -1;
348 IDirect3DCubeTexture8 *pCubeTexture = NULL;
349 IDirect3DTexture8 *pTexture = NULL;
350 IDirect3DVolumeTexture8 *pVolumeTexture = NULL;
351 IDirect3DVolume8 *pVolumeLevel = NULL;
352 IDirect3DSurface8 *pStencilSurface = NULL;
353 IDirect3DSurface8 *pImageSurface = NULL;
354 IDirect3DSurface8 *pRenderTarget = NULL;
355 IDirect3DSurface8 *pRenderTarget2 = NULL;
356 IDirect3DSurface8 *pRenderTarget3 = NULL;
357 IDirect3DSurface8 *pTextureLevel = NULL;
358 IDirect3DSurface8 *pBackBuffer = NULL;
359 DWORD dStateBlock = -1;
360 IDirect3DSwapChain8 *pSwapChain = NULL;
363 D3DPRESENT_PARAMETERS d3dpp;
364 D3DDISPLAYMODE d3ddm;
365 int refcount = 0, tmp;
370 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
371 D3DVSD_REG(D3DVSDE_DIFFUSE, D3DVSDT_D3DCOLOR), /* D3DVSDE_DIFFUSE, Register v5 */
375 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
376 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
377 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
378 ok(hwnd != NULL, "Failed to create window\n");
379 if (!pD3d || !hwnd) goto cleanup;
381 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
382 ZeroMemory( &d3dpp, sizeof(d3dpp) );
383 d3dpp.Windowed = TRUE;
384 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
385 d3dpp.BackBufferFormat = d3ddm.Format;
386 d3dpp.EnableAutoDepthStencil = TRUE;
387 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
389 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
390 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
393 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
396 IDirect3DDevice8_GetDeviceCaps(pDevice, &caps);
398 refcount = get_refcount( (IUnknown *)pDevice );
399 ok(refcount == 1, "Invalid device RefCount %d\n", refcount);
402 * Check refcount of implicit surfaces. Findings:
403 * - the container is the device
404 * - they hold a reference to the device
405 * - they are created with a refcount of 0 (Get/Release returns original refcount)
406 * - they are not freed if refcount reaches 0.
407 * - the refcount is not forwarded to the container.
409 hr = IDirect3DDevice8_GetRenderTarget(pDevice, &pRenderTarget);
410 CHECK_CALL( hr, "GetRenderTarget", pDevice, ++refcount);
413 CHECK_SURFACE_CONTAINER( pRenderTarget, IID_IDirect3DDevice8, pDevice);
414 CHECK_REFCOUNT( pRenderTarget, 1);
416 CHECK_ADDREF_REFCOUNT(pRenderTarget, 2);
417 CHECK_REFCOUNT(pDevice, refcount);
418 CHECK_RELEASE_REFCOUNT(pRenderTarget, 1);
419 CHECK_REFCOUNT(pDevice, refcount);
421 hr = IDirect3DDevice8_GetRenderTarget(pDevice, &pRenderTarget);
422 CHECK_CALL( hr, "GetRenderTarget", pDevice, refcount);
423 CHECK_REFCOUNT( pRenderTarget, 2);
424 CHECK_RELEASE_REFCOUNT( pRenderTarget, 1);
425 CHECK_RELEASE_REFCOUNT( pRenderTarget, 0);
426 CHECK_REFCOUNT( pDevice, --refcount);
428 /* The render target is released with the device, so AddRef with refcount=0 is fine here. */
429 CHECK_ADDREF_REFCOUNT(pRenderTarget, 1);
430 CHECK_REFCOUNT(pDevice, ++refcount);
431 CHECK_RELEASE_REFCOUNT(pRenderTarget, 0);
432 CHECK_REFCOUNT(pDevice, --refcount);
435 /* Render target and back buffer are identical. */
436 hr = IDirect3DDevice8_GetBackBuffer(pDevice, 0, 0, &pBackBuffer);
437 CHECK_CALL( hr, "GetBackBuffer", pDevice, ++refcount);
440 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
441 ok(pRenderTarget == pBackBuffer, "RenderTarget=%p and BackBuffer=%p should be the same.\n",
442 pRenderTarget, pBackBuffer);
445 CHECK_REFCOUNT( pDevice, --refcount);
447 hr = IDirect3DDevice8_GetDepthStencilSurface(pDevice, &pStencilSurface);
448 CHECK_CALL( hr, "GetDepthStencilSurface", pDevice, ++refcount);
451 CHECK_SURFACE_CONTAINER( pStencilSurface, IID_IDirect3DDevice8, pDevice);
452 CHECK_REFCOUNT( pStencilSurface, 1);
454 CHECK_ADDREF_REFCOUNT(pStencilSurface, 2);
455 CHECK_REFCOUNT(pDevice, refcount);
456 CHECK_RELEASE_REFCOUNT(pStencilSurface, 1);
457 CHECK_REFCOUNT(pDevice, refcount);
459 CHECK_RELEASE_REFCOUNT( pStencilSurface, 0);
460 CHECK_REFCOUNT( pDevice, --refcount);
462 /* The stencil surface is released with the device, so AddRef with refcount=0 is fine here. */
463 CHECK_ADDREF_REFCOUNT(pStencilSurface, 1);
464 CHECK_REFCOUNT(pDevice, ++refcount);
465 CHECK_RELEASE_REFCOUNT(pStencilSurface, 0);
466 CHECK_REFCOUNT(pDevice, --refcount);
467 pStencilSurface = NULL;
471 hr = IDirect3DDevice8_CreateIndexBuffer( pDevice, 16, 0, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &pIndexBuffer );
472 CHECK_CALL( hr, "CreateIndexBuffer", pDevice, ++refcount );
475 tmp = get_refcount( (IUnknown *)pIndexBuffer );
477 hr = IDirect3DDevice8_SetIndices(pDevice, pIndexBuffer, 0);
478 CHECK_CALL( hr, "SetIndices", pIndexBuffer, tmp);
479 hr = IDirect3DDevice8_SetIndices(pDevice, NULL, 0);
480 CHECK_CALL( hr, "SetIndices", pIndexBuffer, tmp);
483 hr = IDirect3DDevice8_CreateVertexBuffer( pDevice, 16, 0, D3DFVF_XYZ, D3DPOOL_DEFAULT, &pVertexBuffer );
484 CHECK_CALL( hr, "CreateVertexBuffer", pDevice, ++refcount );
487 IDirect3DVertexBuffer8 *pVBuf = (void*)~0;
490 tmp = get_refcount( (IUnknown *)pVertexBuffer );
492 hr = IDirect3DDevice8_SetStreamSource(pDevice, 0, pVertexBuffer, 3 * sizeof(float));
493 CHECK_CALL( hr, "SetStreamSource", pVertexBuffer, tmp);
494 hr = IDirect3DDevice8_SetStreamSource(pDevice, 0, NULL, 0);
495 CHECK_CALL( hr, "SetStreamSource", pVertexBuffer, tmp);
497 hr = IDirect3DDevice8_GetStreamSource(pDevice, 0, &pVBuf, &stride);
498 ok(SUCCEEDED(hr), "GetStreamSource did not succeed with NULL stream!\n");
499 ok(pVBuf==NULL, "pVBuf not NULL (%p)!\n", pVBuf);
500 ok(stride==3*sizeof(float), "stride not 3 floats (got %u)!\n", stride);
504 hr = IDirect3DDevice8_CreateVertexShader( pDevice, decl, simple_vs, &dVertexShader, 0 );
505 CHECK_CALL( hr, "CreateVertexShader", pDevice, refcount );
506 if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 0))
508 hr = IDirect3DDevice8_CreatePixelShader( pDevice, simple_ps, &dPixelShader );
509 CHECK_CALL( hr, "CreatePixelShader", pDevice, refcount );
512 hr = IDirect3DDevice8_CreateTexture( pDevice, 32, 32, 3, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pTexture );
513 CHECK_CALL( hr, "CreateTexture", pDevice, ++refcount );
516 tmp = get_refcount( (IUnknown *)pTexture );
518 /* SetTexture should not increase refcounts */
519 hr = IDirect3DDevice8_SetTexture(pDevice, 0, (IDirect3DBaseTexture8 *) pTexture);
520 CHECK_CALL( hr, "SetTexture", pTexture, tmp);
521 hr = IDirect3DDevice8_SetTexture(pDevice, 0, NULL);
522 CHECK_CALL( hr, "SetTexture", pTexture, tmp);
524 /* This should not increment device refcount */
525 hr = IDirect3DTexture8_GetSurfaceLevel( pTexture, 1, &pTextureLevel );
526 CHECK_CALL( hr, "GetSurfaceLevel", pDevice, refcount );
527 /* But should increment texture's refcount */
528 CHECK_REFCOUNT( pTexture, tmp+1 );
529 /* Because the texture and surface refcount are identical */
532 CHECK_REFCOUNT ( pTextureLevel, tmp+1 );
533 CHECK_ADDREF_REFCOUNT ( pTextureLevel, tmp+2 );
534 CHECK_REFCOUNT ( pTexture , tmp+2 );
535 CHECK_RELEASE_REFCOUNT( pTextureLevel, tmp+1 );
536 CHECK_REFCOUNT ( pTexture , tmp+1 );
537 CHECK_RELEASE_REFCOUNT( pTexture , tmp );
538 CHECK_REFCOUNT ( pTextureLevel, tmp );
541 if(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP)
543 hr = IDirect3DDevice8_CreateCubeTexture( pDevice, 32, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pCubeTexture );
544 CHECK_CALL( hr, "CreateCubeTexture", pDevice, ++refcount );
548 skip("Cube textures not supported\n");
550 if(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP)
552 hr = IDirect3DDevice8_CreateVolumeTexture( pDevice, 32, 32, 2, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pVolumeTexture );
553 CHECK_CALL( hr, "CreateVolumeTexture", pDevice, ++refcount );
557 skip("Volume textures not supported\n");
562 tmp = get_refcount( (IUnknown *)pVolumeTexture );
564 /* This should not increment device refcount */
565 hr = IDirect3DVolumeTexture8_GetVolumeLevel(pVolumeTexture, 0, &pVolumeLevel);
566 CHECK_CALL( hr, "GetVolumeLevel", pDevice, refcount );
567 /* But should increment volume texture's refcount */
568 CHECK_REFCOUNT( pVolumeTexture, tmp+1 );
569 /* Because the volume texture and volume refcount are identical */
572 CHECK_REFCOUNT ( pVolumeLevel , tmp+1 );
573 CHECK_ADDREF_REFCOUNT ( pVolumeLevel , tmp+2 );
574 CHECK_REFCOUNT ( pVolumeTexture, tmp+2 );
575 CHECK_RELEASE_REFCOUNT( pVolumeLevel , tmp+1 );
576 CHECK_REFCOUNT ( pVolumeTexture, tmp+1 );
577 CHECK_RELEASE_REFCOUNT( pVolumeTexture, tmp );
578 CHECK_REFCOUNT ( pVolumeLevel , tmp );
582 hr = IDirect3DDevice8_CreateDepthStencilSurface( pDevice, 32, 32, D3DFMT_D16, D3DMULTISAMPLE_NONE, &pStencilSurface );
583 CHECK_CALL( hr, "CreateDepthStencilSurface", pDevice, ++refcount );
584 CHECK_REFCOUNT( pStencilSurface, 1);
585 hr = IDirect3DDevice8_CreateImageSurface( pDevice, 32, 32, D3DFMT_X8R8G8B8, &pImageSurface );
586 CHECK_CALL( hr, "CreateImageSurface", pDevice, ++refcount );
587 CHECK_REFCOUNT( pImageSurface, 1);
588 hr = IDirect3DDevice8_CreateRenderTarget( pDevice, 32, 32, D3DFMT_X8R8G8B8, D3DMULTISAMPLE_NONE, TRUE, &pRenderTarget3 );
589 CHECK_CALL( hr, "CreateRenderTarget", pDevice, ++refcount );
590 CHECK_REFCOUNT( pRenderTarget3, 1);
592 hr = IDirect3DDevice8_CreateStateBlock( pDevice, D3DSBT_ALL, &dStateBlock );
593 CHECK_CALL( hr, "CreateStateBlock", pDevice, refcount );
594 hr = IDirect3DDevice8_CreateAdditionalSwapChain( pDevice, &d3dpp, &pSwapChain );
595 CHECK_CALL( hr, "CreateAdditionalSwapChain", pDevice, ++refcount );
598 /* check implicit back buffer */
599 hr = IDirect3DSwapChain8_GetBackBuffer(pSwapChain, 0, 0, &pBackBuffer);
600 CHECK_CALL( hr, "GetBackBuffer", pDevice, ++refcount);
601 CHECK_REFCOUNT( pSwapChain, 1);
604 CHECK_SURFACE_CONTAINER( pBackBuffer, IID_IDirect3DDevice8, pDevice);
605 CHECK_REFCOUNT( pBackBuffer, 1);
606 CHECK_RELEASE_REFCOUNT( pBackBuffer, 0);
607 CHECK_REFCOUNT( pDevice, --refcount);
609 /* The back buffer is released with the swapchain, so AddRef with refcount=0 is fine here. */
610 CHECK_ADDREF_REFCOUNT(pBackBuffer, 1);
611 CHECK_REFCOUNT(pDevice, ++refcount);
612 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
613 CHECK_REFCOUNT(pDevice, --refcount);
616 CHECK_REFCOUNT( pSwapChain, 1);
622 /* Vertex buffers can be locked multiple times */
623 hr = IDirect3DVertexBuffer8_Lock(pVertexBuffer, 0, 0, &data, 0);
624 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr);
625 hr = IDirect3DVertexBuffer8_Lock(pVertexBuffer, 0, 0, &data, 0);
626 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr);
627 hr = IDirect3DVertexBuffer8_Unlock(pVertexBuffer);
628 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr);
629 hr = IDirect3DVertexBuffer8_Unlock(pVertexBuffer);
630 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr);
633 /* The implicit render target is not freed if refcount reaches 0.
634 * Otherwise GetRenderTarget would re-allocate it and the pointer would change.*/
635 hr = IDirect3DDevice8_GetRenderTarget(pDevice, &pRenderTarget2);
636 CHECK_CALL( hr, "GetRenderTarget", pDevice, ++refcount);
639 CHECK_RELEASE_REFCOUNT(pRenderTarget2, 0);
640 ok(pRenderTarget == pRenderTarget2, "RenderTarget=%p and RenderTarget2=%p should be the same.\n",
641 pRenderTarget, pRenderTarget2);
642 CHECK_REFCOUNT( pDevice, --refcount);
643 pRenderTarget2 = NULL;
645 pRenderTarget = NULL;
648 CHECK_RELEASE(pDevice, pDevice, --refcount);
651 CHECK_RELEASE(pVertexBuffer, pDevice, --refcount);
652 CHECK_RELEASE(pIndexBuffer, pDevice, --refcount);
654 if (dVertexShader != ~0U) IDirect3DDevice8_DeleteVertexShader( pDevice, dVertexShader );
655 if (dPixelShader != ~0U) IDirect3DDevice8_DeletePixelShader( pDevice, dPixelShader );
657 CHECK_RELEASE(pTexture, pDevice, --refcount);
658 CHECK_RELEASE(pCubeTexture, pDevice, --refcount);
659 CHECK_RELEASE(pVolumeTexture, pDevice, --refcount);
661 CHECK_RELEASE(pStencilSurface, pDevice, --refcount);
662 CHECK_RELEASE(pImageSurface, pDevice, --refcount);
663 CHECK_RELEASE(pRenderTarget3, pDevice, --refcount);
665 if (dStateBlock != ~0U) IDirect3DDevice8_DeleteStateBlock( pDevice, dStateBlock );
666 /* This will destroy device - cannot check the refcount here */
667 if (pSwapChain) CHECK_RELEASE_REFCOUNT( pSwapChain, 0);
669 if (pD3d) CHECK_RELEASE_REFCOUNT( pD3d, 0);
671 DestroyWindow( hwnd );
674 static void test_cursor(void)
678 IDirect3D8 *pD3d = NULL;
679 IDirect3DDevice8 *pDevice = NULL;
680 D3DPRESENT_PARAMETERS d3dpp;
681 D3DDISPLAYMODE d3ddm;
683 IDirect3DSurface8 *cursor = NULL;
685 HMODULE user32_handle = GetModuleHandleA("user32.dll");
687 pGetCursorInfo = (void *)GetProcAddress(user32_handle, "GetCursorInfo");
690 win_skip("GetCursorInfo is not available\n");
694 memset(&info, 0, sizeof(info));
695 info.cbSize = sizeof(info);
696 ok(pGetCursorInfo(&info), "GetCursorInfo failed\n");
699 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
700 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
701 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
702 ok(hwnd != NULL, "Failed to create window\n");
703 if (!pD3d || !hwnd) goto cleanup;
705 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
706 ZeroMemory( &d3dpp, sizeof(d3dpp) );
707 d3dpp.Windowed = TRUE;
708 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
709 d3dpp.BackBufferFormat = d3ddm.Format;
711 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
712 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
715 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
719 IDirect3DDevice8_CreateImageSurface(pDevice, 32, 32, D3DFMT_A8R8G8B8, &cursor);
720 ok(cursor != NULL, "IDirect3DDevice8_CreateOffscreenPlainSurface failed with %#08x\n", hr);
722 /* Initially hidden */
723 hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
724 ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
726 /* Not enabled without a surface*/
727 hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
728 ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
731 hr = IDirect3DDevice8_SetCursorProperties(pDevice, 0, 0, NULL);
732 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr);
734 hr = IDirect3DDevice8_SetCursorProperties(pDevice, 0, 0, cursor);
735 ok(hr == D3D_OK, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr);
737 IDirect3DSurface8_Release(cursor);
739 memset(&info, 0, sizeof(info));
740 info.cbSize = sizeof(info);
741 ok(pGetCursorInfo(&info), "GetCursorInfo failed\n");
742 ok(info.flags & CURSOR_SHOWING, "The gdi cursor is hidden (%08x)\n", info.flags);
743 ok(info.hCursor == cur, "The cursor handle is %p\n", info.hCursor); /* unchanged */
746 hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
747 ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
750 hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
751 ok(hr == TRUE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
753 /* GDI cursor unchanged */
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 */
763 UINT refcount = IDirect3DDevice8_Release(pDevice);
764 ok(!refcount, "Device has %u references left.\n", refcount);
766 if (pD3d) IDirect3D8_Release(pD3d);
769 static void test_states(void)
773 IDirect3D8 *pD3d = NULL;
774 IDirect3DDevice8 *pDevice = NULL;
775 D3DPRESENT_PARAMETERS d3dpp;
776 D3DDISPLAYMODE d3ddm;
778 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
779 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
780 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
781 ok(hwnd != NULL, "Failed to create window\n");
782 if (!pD3d || !hwnd) goto cleanup;
784 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
785 ZeroMemory( &d3dpp, sizeof(d3dpp) );
786 d3dpp.Windowed = TRUE;
787 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
788 d3dpp.BackBufferWidth = 640;
789 d3dpp.BackBufferHeight = 480;
790 d3dpp.BackBufferFormat = d3ddm.Format;
792 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
793 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
796 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
800 hr = IDirect3DDevice8_SetRenderState(pDevice, D3DRS_ZVISIBLE, TRUE);
801 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, TRUE) returned %#08x\n", hr);
802 hr = IDirect3DDevice8_SetRenderState(pDevice, D3DRS_ZVISIBLE, FALSE);
803 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, FALSE) returned %#08x\n", hr);
808 UINT refcount = IDirect3DDevice8_Release(pDevice);
809 ok(!refcount, "Device has %u references left.\n", refcount);
811 if (pD3d) IDirect3D8_Release(pD3d);
814 static void test_shader_versions(void)
817 IDirect3D8 *pD3d = NULL;
820 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
821 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
823 hr = IDirect3D8_GetDeviceCaps(pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dcaps);
824 ok(SUCCEEDED(hr) || hr == D3DERR_NOTAVAILABLE, "Failed to get D3D8 caps (%#08x)\n", hr);
826 ok(d3dcaps.VertexShaderVersion <= D3DVS_VERSION(1,1), "Unexpected VertexShaderVersion (%#x > %#x)\n", d3dcaps.VertexShaderVersion, D3DVS_VERSION(1,1));
827 ok(d3dcaps.PixelShaderVersion <= D3DPS_VERSION(1,4), "Unexpected PixelShaderVersion (%#x > %#x)\n", d3dcaps.PixelShaderVersion, D3DPS_VERSION(1,4));
829 skip("No Direct3D support\n");
831 IDirect3D8_Release(pD3d);
836 /* Test adapter display modes */
837 static void test_display_modes(void)
840 D3DDISPLAYMODE dmode;
844 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
845 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
848 max_modes = IDirect3D8_GetAdapterModeCount(pD3d, D3DADAPTER_DEFAULT);
850 broken(max_modes == 0), /* VMware */
851 "GetAdapterModeCount(D3DADAPTER_DEFAULT) returned 0!\n");
853 for(i=0; i<max_modes;i++) {
854 res = IDirect3D8_EnumAdapterModes(pD3d, D3DADAPTER_DEFAULT, i, &dmode);
855 ok(res==D3D_OK, "EnumAdapterModes returned %#08x for mode %u!\n", res, i);
859 ok(dmode.Format==D3DFMT_X8R8G8B8 || dmode.Format==D3DFMT_R5G6B5,
860 "Unexpected display mode returned for mode %u: %#x\n", i , dmode.Format);
863 IDirect3D8_Release(pD3d);
866 static void test_scene(void)
870 IDirect3D8 *pD3d = NULL;
871 IDirect3DDevice8 *pDevice = NULL;
872 D3DPRESENT_PARAMETERS d3dpp;
873 D3DDISPLAYMODE d3ddm;
875 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
876 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
877 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
878 ok(hwnd != NULL, "Failed to create window\n");
879 if (!pD3d || !hwnd) goto cleanup;
881 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
882 ZeroMemory( &d3dpp, sizeof(d3dpp) );
883 d3dpp.Windowed = TRUE;
884 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
885 d3dpp.BackBufferWidth = 800;
886 d3dpp.BackBufferHeight = 600;
887 d3dpp.BackBufferFormat = d3ddm.Format;
890 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
891 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
892 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL || broken(hr == D3DERR_NOTAVAILABLE), "IDirect3D8_CreateDevice failed with %#08x\n", hr);
895 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
899 /* Test an EndScene without beginscene. Should return an error */
900 hr = IDirect3DDevice8_EndScene(pDevice);
901 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
903 /* Test a normal BeginScene / EndScene pair, this should work */
904 hr = IDirect3DDevice8_BeginScene(pDevice);
905 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
908 hr = IDirect3DDevice8_EndScene(pDevice);
909 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
912 /* Test another EndScene without having begun a new scene. Should return an error */
913 hr = IDirect3DDevice8_EndScene(pDevice);
914 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
916 /* Two nested BeginScene and EndScene calls */
917 hr = IDirect3DDevice8_BeginScene(pDevice);
918 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
919 hr = IDirect3DDevice8_BeginScene(pDevice);
920 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_BeginScene returned %#08x\n", hr);
921 hr = IDirect3DDevice8_EndScene(pDevice);
922 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
923 hr = IDirect3DDevice8_EndScene(pDevice);
924 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
926 /* StretchRect does not exit in Direct3D8, so no equivalent to the d3d9 stretchrect tests */
931 UINT refcount = IDirect3DDevice8_Release(pDevice);
932 ok(!refcount, "Device has %u references left.\n", refcount);
934 if (pD3d) IDirect3D8_Release(pD3d);
935 if(hwnd) DestroyWindow(hwnd);
938 static void test_shader(void)
942 IDirect3D8 *pD3d = NULL;
943 IDirect3DDevice8 *pDevice = NULL;
944 D3DPRESENT_PARAMETERS d3dpp;
945 D3DDISPLAYMODE d3ddm;
946 DWORD hPixelShader = 0, hVertexShader = 0;
947 DWORD hPixelShader2 = 0, hVertexShader2 = 0;
950 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
954 static DWORD dwVertexDecl[] =
957 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3),
960 DWORD decl_normal_float2[] =
963 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
964 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT2), /* D3DVSDE_NORMAL, Register v1 */
967 DWORD decl_normal_float4[] =
970 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
971 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT4), /* D3DVSDE_NORMAL, Register v1 */
974 DWORD decl_normal_d3dcolor[] =
977 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
978 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_D3DCOLOR),/* D3DVSDE_NORMAL, Register v1 */
981 const DWORD vertex_decl_size = sizeof(dwVertexDecl);
982 const DWORD simple_vs_size = sizeof(simple_vs);
983 const DWORD simple_ps_size = sizeof(simple_ps);
985 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
986 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
987 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
988 ok(hwnd != NULL, "Failed to create window\n");
989 if (!pD3d || !hwnd) goto cleanup;
991 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
992 ZeroMemory( &d3dpp, sizeof(d3dpp) );
993 d3dpp.Windowed = TRUE;
994 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
995 d3dpp.BackBufferWidth = 800;
996 d3dpp.BackBufferHeight = 600;
997 d3dpp.BackBufferFormat = d3ddm.Format;
1000 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1001 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
1002 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL || broken(hr == D3DERR_NOTAVAILABLE), "IDirect3D8_CreateDevice failed with %#08x\n", hr);
1005 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
1008 IDirect3DDevice8_GetDeviceCaps(pDevice, &caps);
1010 /* Test setting and retrieving a FVF */
1011 hr = IDirect3DDevice8_SetVertexShader(pDevice, fvf);
1012 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1013 hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
1014 ok(SUCCEEDED(hr), "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1015 ok(hTempHandle == fvf, "Vertex shader %#08x is set, expected %#08x\n", hTempHandle, fvf);
1017 /* First create a vertex shader */
1018 hr = IDirect3DDevice8_SetVertexShader(pDevice, 0);
1019 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1020 hr = IDirect3DDevice8_CreateVertexShader(pDevice, dwVertexDecl, simple_vs, &hVertexShader, 0);
1021 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1022 /* Msdn says that the new vertex shader is set immediately. This is wrong, apparently */
1023 hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
1024 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1025 ok(hTempHandle == 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, 0);
1026 /* Assign the shader, then verify that GetVertexShader works */
1027 hr = IDirect3DDevice8_SetVertexShader(pDevice, hVertexShader);
1028 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1029 hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
1030 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1031 ok(hTempHandle == hVertexShader, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, hVertexShader);
1032 /* Verify that we can retrieve the declaration */
1033 hr = IDirect3DDevice8_GetVertexShaderDeclaration(pDevice, hVertexShader, NULL, &data_size);
1034 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr);
1035 ok(data_size == vertex_decl_size, "Got data_size %u, expected %u\n", data_size, vertex_decl_size);
1036 data = HeapAlloc(GetProcessHeap(), 0, vertex_decl_size);
1038 hr = IDirect3DDevice8_GetVertexShaderDeclaration(pDevice, hVertexShader, data, &data_size);
1039 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetVertexShaderDeclaration returned (%#08x), "
1040 "expected D3DERR_INVALIDCALL\n", hr);
1041 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
1042 data_size = vertex_decl_size;
1043 hr = IDirect3DDevice8_GetVertexShaderDeclaration(pDevice, hVertexShader, data, &data_size);
1044 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr);
1045 ok(data_size == vertex_decl_size, "Got data_size %u, expected %u\n", data_size, vertex_decl_size);
1046 ok(!memcmp(data, dwVertexDecl, vertex_decl_size), "data not equal to shader declaration\n");
1047 HeapFree(GetProcessHeap(), 0, data);
1048 /* Verify that we can retrieve the shader function */
1049 hr = IDirect3DDevice8_GetVertexShaderFunction(pDevice, hVertexShader, NULL, &data_size);
1050 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr);
1051 ok(data_size == simple_vs_size, "Got data_size %u, expected %u\n", data_size, simple_vs_size);
1052 data = HeapAlloc(GetProcessHeap(), 0, simple_vs_size);
1054 hr = IDirect3DDevice8_GetVertexShaderFunction(pDevice, hVertexShader, data, &data_size);
1055 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetVertexShaderFunction returned (%#08x), "
1056 "expected D3DERR_INVALIDCALL\n", hr);
1057 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
1058 data_size = simple_vs_size;
1059 hr = IDirect3DDevice8_GetVertexShaderFunction(pDevice, hVertexShader, data, &data_size);
1060 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr);
1061 ok(data_size == simple_vs_size, "Got data_size %u, expected %u\n", data_size, simple_vs_size);
1062 ok(!memcmp(data, simple_vs, simple_vs_size), "data not equal to shader function\n");
1063 HeapFree(GetProcessHeap(), 0, data);
1064 /* Delete the assigned shader. This is supposed to work */
1065 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1066 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1067 /* The shader should be unset now */
1068 hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
1069 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1070 ok(hTempHandle == 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, 0);
1072 /* Test a broken declaration. 3DMark2001 tries to use normals with 2 components
1073 * First try the fixed function shader function, then a custom one
1075 hr = IDirect3DDevice8_CreateVertexShader(pDevice, decl_normal_float2, 0, &hVertexShader, 0);
1076 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1077 if(SUCCEEDED(hr)) IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1078 hr = IDirect3DDevice8_CreateVertexShader(pDevice, decl_normal_float4, 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_d3dcolor, 0, &hVertexShader, 0);
1082 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1083 if(SUCCEEDED(hr)) IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1085 hr = IDirect3DDevice8_CreateVertexShader(pDevice, decl_normal_float2, simple_vs, &hVertexShader, 0);
1086 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1087 if(SUCCEEDED(hr)) IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1089 if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 0))
1091 /* The same with a pixel shader */
1092 hr = IDirect3DDevice8_CreatePixelShader(pDevice, simple_ps, &hPixelShader);
1093 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
1094 /* Msdn says that the new pixel shader is set immediately. This is wrong, apparently */
1095 hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle);
1096 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1097 ok(hTempHandle == 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, 0);
1098 /* Assign the shader, then verify that GetPixelShader works */
1099 hr = IDirect3DDevice8_SetPixelShader(pDevice, hPixelShader);
1100 ok(hr == D3D_OK, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr);
1101 hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle);
1102 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1103 ok(hTempHandle == hPixelShader, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, hPixelShader);
1104 /* Verify that we can retrieve the shader function */
1105 hr = IDirect3DDevice8_GetPixelShaderFunction(pDevice, hPixelShader, NULL, &data_size);
1106 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr);
1107 ok(data_size == simple_ps_size, "Got data_size %u, expected %u\n", data_size, simple_ps_size);
1108 data = HeapAlloc(GetProcessHeap(), 0, simple_ps_size);
1110 hr = IDirect3DDevice8_GetPixelShaderFunction(pDevice, hPixelShader, data, &data_size);
1111 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetPixelShaderFunction returned (%#08x), "
1112 "expected D3DERR_INVALIDCALL\n", hr);
1113 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
1114 data_size = simple_ps_size;
1115 hr = IDirect3DDevice8_GetPixelShaderFunction(pDevice, hPixelShader, data, &data_size);
1116 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr);
1117 ok(data_size == simple_ps_size, "Got data_size %u, expected %u\n", data_size, simple_ps_size);
1118 ok(!memcmp(data, simple_ps, simple_ps_size), "data not equal to shader function\n");
1119 HeapFree(GetProcessHeap(), 0, data);
1120 /* Delete the assigned shader. This is supposed to work */
1121 hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader);
1122 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1123 /* The shader should be unset now */
1124 hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle);
1125 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1126 ok(hTempHandle == 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, 0);
1128 /* What happens if a non-bound shader is deleted? */
1129 hr = IDirect3DDevice8_CreatePixelShader(pDevice, simple_ps, &hPixelShader);
1130 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
1131 hr = IDirect3DDevice8_CreatePixelShader(pDevice, simple_ps, &hPixelShader2);
1132 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
1134 hr = IDirect3DDevice8_SetPixelShader(pDevice, hPixelShader);
1135 ok(hr == D3D_OK, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr);
1136 hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader2);
1137 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1138 hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle);
1139 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1140 ok(hTempHandle == hPixelShader, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, hPixelShader);
1141 hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader);
1142 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1144 /* Check for double delete. */
1145 hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader2);
1146 ok(hr == D3DERR_INVALIDCALL || broken(hr == D3D_OK), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1147 hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader);
1148 ok(hr == D3DERR_INVALIDCALL || broken(hr == D3D_OK), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1152 skip("Pixel shaders not supported\n");
1155 /* What happens if a non-bound shader is deleted? */
1156 hr = IDirect3DDevice8_CreateVertexShader(pDevice, dwVertexDecl, NULL, &hVertexShader, 0);
1157 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1158 hr = IDirect3DDevice8_CreateVertexShader(pDevice, dwVertexDecl, NULL, &hVertexShader2, 0);
1159 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1161 hr = IDirect3DDevice8_SetVertexShader(pDevice, hVertexShader);
1162 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1163 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader2);
1164 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1165 hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
1166 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1167 ok(hTempHandle == hVertexShader, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, hVertexShader);
1168 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1169 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1171 /* Check for double delete. */
1172 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader2);
1173 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1174 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1175 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1180 UINT refcount = IDirect3DDevice8_Release(pDevice);
1181 ok(!refcount, "Device has %u references left.\n", refcount);
1183 if (pD3d) IDirect3D8_Release(pD3d);
1184 if(hwnd) DestroyWindow(hwnd);
1187 static void test_limits(void)
1191 IDirect3D8 *pD3d = NULL;
1192 IDirect3DDevice8 *pDevice = NULL;
1193 D3DPRESENT_PARAMETERS d3dpp;
1194 D3DDISPLAYMODE d3ddm;
1195 IDirect3DTexture8 *pTexture = NULL;
1198 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
1199 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
1200 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1201 ok(hwnd != NULL, "Failed to create window\n");
1202 if (!pD3d || !hwnd) goto cleanup;
1204 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
1205 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1206 d3dpp.Windowed = TRUE;
1207 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1208 d3dpp.BackBufferWidth = 800;
1209 d3dpp.BackBufferHeight = 600;
1210 d3dpp.BackBufferFormat = d3ddm.Format;
1211 d3dpp.EnableAutoDepthStencil = TRUE;
1212 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
1214 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1215 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
1216 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL || broken(hr == D3DERR_NOTAVAILABLE), "IDirect3D8_CreateDevice failed with %#08x\n", hr);
1219 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
1223 hr = IDirect3DDevice8_CreateTexture(pDevice, 16, 16, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pTexture);
1224 ok(hr == D3D_OK, "IDirect3DDevice8_CreateTexture failed with %#08x\n", hr);
1225 if(!pTexture) goto cleanup;
1227 /* There are 8 texture stages. We should be able to access all of them */
1228 for(i = 0; i < 8; i++) {
1229 hr = IDirect3DDevice8_SetTexture(pDevice, i, (IDirect3DBaseTexture8 *) pTexture);
1230 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i, hr);
1231 hr = IDirect3DDevice8_SetTexture(pDevice, i, NULL);
1232 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i, hr);
1233 hr = IDirect3DDevice8_SetTextureStageState(pDevice, i, D3DTSS_COLOROP, D3DTOP_ADD);
1234 ok(hr == D3D_OK, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %#08x\n", i, hr);
1237 /* Investigations show that accessing higher textures stage states does not return an error either. Writing
1238 * to too high texture stages(approximately texture 40) causes memory corruption in windows, so there is no
1239 * bounds checking but how do I test that?
1243 if(pTexture) IDirect3DTexture8_Release(pTexture);
1246 UINT refcount = IDirect3DDevice8_Release(pDevice);
1247 ok(!refcount, "Device has %u references left.\n", refcount);
1249 if (pD3d) IDirect3D8_Release(pD3d);
1250 if(hwnd) DestroyWindow(hwnd);
1253 static void test_lights(void)
1255 D3DPRESENT_PARAMETERS d3dpp;
1256 IDirect3DDevice8 *device = NULL;
1263 D3DDISPLAYMODE d3ddm;
1265 d3d8 = pDirect3DCreate8( D3D_SDK_VERSION );
1266 ok(d3d8 != NULL, "Failed to create IDirect3D8 object\n");
1267 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1268 ok(hwnd != NULL, "Failed to create window\n");
1269 if (!d3d8 || !hwnd) goto cleanup;
1271 IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &d3ddm );
1272 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1273 d3dpp.Windowed = TRUE;
1274 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1275 d3dpp.BackBufferWidth = 800;
1276 d3dpp.BackBufferHeight = 600;
1277 d3dpp.BackBufferFormat = d3ddm.Format;
1278 d3dpp.EnableAutoDepthStencil = TRUE;
1279 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
1281 hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1282 D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &d3dpp, &device );
1283 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE || hr == D3DERR_INVALIDCALL,
1284 "IDirect3D8_CreateDevice failed with %08x\n", hr);
1287 skip("Failed to create a d3d device\n");
1291 memset(&caps, 0, sizeof(caps));
1292 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
1293 ok(hr == D3D_OK, "IDirect3DDevice8_GetDeviceCaps failed with %08x\n", hr);
1295 for(i = 1; i <= caps.MaxActiveLights; i++) {
1296 hr = IDirect3DDevice8_LightEnable(device, i, TRUE);
1297 ok(hr == D3D_OK, "Enabling light %u failed with %08x\n", i, hr);
1298 hr = IDirect3DDevice8_GetLightEnable(device, i, &enabled);
1299 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL),
1300 "GetLightEnable on light %u failed with %08x\n", i, hr);
1301 ok(enabled, "Light %d is %s\n", i, enabled ? "enabled" : "disabled");
1304 /* TODO: Test the rendering results in this situation */
1305 hr = IDirect3DDevice8_LightEnable(device, i + 1, TRUE);
1307 broken(hr == D3DERR_INVALIDCALL), /* Some Win9x and WinME */
1308 "Enabling one light more than supported returned %08x\n", hr);
1309 hr = IDirect3DDevice8_GetLightEnable(device, i + 1, &enabled);
1311 broken(hr == D3DERR_INVALIDCALL), /* Some Win9x and WinME */
1312 "GetLightEnable on light %u failed with %08x\n", i + 1, hr);
1313 ok(enabled, "Light %d is %s\n", i + 1, enabled ? "enabled" : "disabled");
1314 hr = IDirect3DDevice8_LightEnable(device, i + 1, FALSE);
1315 ok(hr == D3D_OK, "Disabling the additional returned %08x\n", hr);
1317 for(i = 1; i <= caps.MaxActiveLights; i++) {
1318 hr = IDirect3DDevice8_LightEnable(device, i, FALSE);
1319 ok(hr == D3D_OK, "Disabling light %u failed with %08x\n", i, hr);
1325 UINT refcount = IDirect3DDevice8_Release(device);
1326 ok(!refcount, "Device has %u references left.\n", refcount);
1328 if (d3d8) IDirect3D8_Release(d3d8);
1331 static void test_render_zero_triangles(void)
1333 D3DPRESENT_PARAMETERS d3dpp;
1334 IDirect3DDevice8 *device = NULL;
1338 D3DDISPLAYMODE d3ddm;
1347 { 0.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
1348 { 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
1349 { 1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
1350 { 1.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
1353 d3d8 = pDirect3DCreate8( D3D_SDK_VERSION );
1354 ok(d3d8 != NULL, "Failed to create IDirect3D8 object\n");
1355 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1356 ok(hwnd != NULL, "Failed to create window\n");
1357 if (!d3d8 || !hwnd) goto cleanup;
1359 IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &d3ddm );
1360 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1361 d3dpp.Windowed = TRUE;
1362 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1363 d3dpp.BackBufferWidth = 800;
1364 d3dpp.BackBufferHeight = 600;
1365 d3dpp.BackBufferFormat = d3ddm.Format;
1366 d3dpp.EnableAutoDepthStencil = TRUE;
1367 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
1369 hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1370 D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &d3dpp, &device );
1371 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE || hr == D3DERR_INVALIDCALL,
1372 "IDirect3D8_CreateDevice failed with %08x\n", hr);
1375 skip("Failed to create a d3d device\n");
1379 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
1380 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1382 hr = IDirect3DDevice8_BeginScene(device);
1383 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
1386 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 0 /* NumVerts */,
1387 0 /*PrimCount */, NULL, D3DFMT_INDEX16, quad, sizeof(quad[0]));
1388 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr);
1390 IDirect3DDevice8_EndScene(device);
1391 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
1394 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1399 UINT refcount = IDirect3DDevice8_Release(device);
1400 ok(!refcount, "Device has %u references left.\n", refcount);
1402 if (d3d8) IDirect3D8_Release(d3d8);
1405 static void test_depth_stencil_reset(void)
1407 D3DPRESENT_PARAMETERS present_parameters;
1408 D3DDISPLAYMODE display_mode;
1409 IDirect3DSurface8 *surface;
1410 IDirect3DDevice8 *device = NULL;
1416 d3d8 = pDirect3DCreate8(D3D_SDK_VERSION);
1417 ok(d3d8 != NULL, "Failed to create IDirect3D8 object\n");
1418 hwnd = CreateWindow("static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL);
1419 ok(hwnd != NULL, "Failed to create window\n");
1420 if (!d3d8 || !hwnd) goto cleanup;
1422 IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &display_mode);
1423 memset(&present_parameters, 0, sizeof(present_parameters));
1424 present_parameters.Windowed = TRUE;
1425 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
1426 present_parameters.BackBufferFormat = display_mode.Format;
1427 present_parameters.EnableAutoDepthStencil = TRUE;
1428 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
1430 hr = IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
1431 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
1434 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr);
1438 hr = IDirect3DDevice8_TestCooperativeLevel(device);
1439 ok(SUCCEEDED(hr), "TestCooperativeLevel failed with %#x\n", hr);
1441 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, NULL);
1442 ok(hr == D3D_OK, "SetRenderTarget failed with 0x%08x\n", hr);
1444 hr = IDirect3DDevice8_GetRenderTarget(device, &surface);
1445 ok(hr == D3D_OK, "GetRenderTarget failed with 0x%08x\n", hr);
1446 ok(surface != NULL, "Render target should not be NULL\n");
1447 if (surface) IDirect3DSurface8_Release(surface);
1449 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
1450 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr);
1451 ok(surface == NULL, "Depth stencil should be NULL\n");
1453 present_parameters.EnableAutoDepthStencil = TRUE;
1454 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
1455 hr = IDirect3DDevice8_Reset(device, &present_parameters);
1456 ok(hr == D3D_OK, "Reset failed with 0x%08x\n", hr);
1458 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
1459 ok(hr == D3D_OK, "GetDepthStencilSurface failed with 0x%08x\n", hr);
1460 ok(surface != NULL, "Depth stencil should not be NULL\n");
1461 if (surface) IDirect3DSurface8_Release(surface);
1463 present_parameters.EnableAutoDepthStencil = FALSE;
1464 hr = IDirect3DDevice8_Reset(device, &present_parameters);
1465 ok(hr == D3D_OK, "Reset failed with 0x%08x\n", hr);
1467 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
1468 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr);
1469 ok(surface == NULL, "Depth stencil should be NULL\n");
1471 refcount = IDirect3DDevice8_Release(device);
1472 ok(!refcount, "Device has %u references left.\n", refcount);
1475 IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &display_mode );
1477 ZeroMemory( &present_parameters, sizeof(present_parameters) );
1478 present_parameters.Windowed = TRUE;
1479 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
1480 present_parameters.BackBufferFormat = display_mode.Format;
1481 present_parameters.EnableAutoDepthStencil = FALSE;
1482 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
1484 hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
1485 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device );
1489 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr);
1493 hr = IDirect3DDevice8_TestCooperativeLevel(device);
1494 ok(hr == D3D_OK, "IDirect3DDevice8_TestCooperativeLevel after creation returned %#x\n", hr);
1496 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
1497 present_parameters.Windowed = TRUE;
1498 present_parameters.BackBufferWidth = 400;
1499 present_parameters.BackBufferHeight = 300;
1500 present_parameters.EnableAutoDepthStencil = TRUE;
1501 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
1503 hr = IDirect3DDevice8_Reset(device, &present_parameters);
1504 ok(hr == D3D_OK, "IDirect3DDevice8_Reset failed with 0x%08x\n", hr);
1506 if (FAILED(hr)) goto cleanup;
1508 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
1509 ok(hr == D3D_OK, "GetDepthStencilSurface failed with 0x%08x\n", hr);
1510 ok(surface != NULL, "Depth stencil should not be NULL\n");
1511 if (surface) IDirect3DSurface8_Release(surface);
1516 refcount = IDirect3DDevice8_Release(device);
1517 ok(!refcount, "Device has %u references left.\n", refcount);
1519 if (d3d8) IDirect3D8_Release(d3d8);
1522 static HWND filter_messages;
1533 enum message_window window;
1536 static const struct message *expect_messages;
1537 static HWND device_window, focus_window;
1539 struct wndproc_thread_param
1542 HANDLE window_created;
1543 HANDLE test_finished;
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, 640, 480, 0, 0, 0, 0);
1588 ret = SetEvent(p->window_created);
1589 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
1595 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
1596 res = WaitForSingleObject(p->test_finished, 100);
1597 if (res == WAIT_OBJECT_0) break;
1598 if (res != WAIT_TIMEOUT)
1600 ok(0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
1605 DestroyWindow(p->dummy_window);
1610 static void test_wndproc(void)
1612 struct wndproc_thread_param thread_params;
1613 IDirect3DDevice8 *device;
1622 static const struct message messages[] =
1624 {WM_WINDOWPOSCHANGING, FOCUS_WINDOW},
1625 {WM_ACTIVATE, FOCUS_WINDOW},
1626 {WM_SETFOCUS, FOCUS_WINDOW},
1627 {WM_WINDOWPOSCHANGING, DEVICE_WINDOW},
1628 {WM_MOVE, DEVICE_WINDOW},
1629 {WM_SIZE, DEVICE_WINDOW},
1633 if (!(d3d8 = pDirect3DCreate8(D3D_SDK_VERSION)))
1635 skip("Failed to create IDirect3D8 object, skipping tests.\n");
1639 wc.lpfnWndProc = test_proc;
1640 wc.lpszClassName = "d3d8_test_wndproc_wc";
1641 ok(RegisterClassA(&wc), "Failed to register window class.\n");
1643 thread_params.window_created = CreateEvent(NULL, FALSE, FALSE, NULL);
1644 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
1645 thread_params.test_finished = CreateEvent(NULL, FALSE, FALSE, NULL);
1646 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
1648 focus_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
1649 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
1650 device_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
1651 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
1652 thread = CreateThread(NULL, 0, wndproc_thread, &thread_params, 0, &tid);
1653 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
1655 res = WaitForSingleObject(thread_params.window_created, INFINITE);
1656 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
1658 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
1659 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1660 (LONG_PTR)test_proc, proc);
1661 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1662 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1663 (LONG_PTR)test_proc, proc);
1665 trace("device_window %p, focus_window %p, dummy_window %p.\n",
1666 device_window, focus_window, thread_params.dummy_window);
1669 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
1670 tmp = GetForegroundWindow();
1671 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
1672 thread_params.dummy_window, tmp);
1676 expect_messages = messages;
1678 device = create_device(d3d8, device_window, focus_window, FALSE);
1681 skip("Failed to create a D3D device, skipping tests.\n");
1685 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
1686 expect_messages->message, expect_messages->window);
1687 expect_messages = NULL;
1689 if (0) /* Disabled until we can make this work in a reliable way on Wine. */
1692 ok(tmp == focus_window, "Expected focus %p, got %p.\n", focus_window, tmp);
1693 tmp = GetForegroundWindow();
1694 ok(tmp == focus_window, "Expected foreground window %p, got %p.\n", focus_window, tmp);
1696 SetForegroundWindow(focus_window);
1699 filter_messages = focus_window;
1701 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
1702 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1703 (LONG_PTR)test_proc, proc);
1705 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1706 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
1707 (LONG_PTR)test_proc, proc);
1709 ref = IDirect3DDevice8_Release(device);
1710 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
1712 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1713 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1714 (LONG_PTR)test_proc, proc);
1716 device = create_device(d3d8, focus_window, focus_window, FALSE);
1719 skip("Failed to create a D3D device, skipping tests.\n");
1723 ref = IDirect3DDevice8_Release(device);
1724 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
1726 device = create_device(d3d8, device_window, focus_window, FALSE);
1729 skip("Failed to create a D3D device, skipping tests.\n");
1733 proc = SetWindowLongPtrA(focus_window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
1734 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
1735 (LONG_PTR)test_proc, proc);
1737 ref = IDirect3DDevice8_Release(device);
1738 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
1740 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1741 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
1742 (LONG_PTR)DefWindowProcA, proc);
1745 filter_messages = NULL;
1746 IDirect3D8_Release(d3d8);
1748 SetEvent(thread_params.test_finished);
1749 WaitForSingleObject(thread, INFINITE);
1750 CloseHandle(thread_params.test_finished);
1751 CloseHandle(thread_params.window_created);
1752 CloseHandle(thread);
1754 DestroyWindow(device_window);
1755 DestroyWindow(focus_window);
1756 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL));
1759 static void test_wndproc_windowed(void)
1761 struct wndproc_thread_param thread_params;
1762 IDirect3DDevice8 *device;
1772 if (!(d3d8 = pDirect3DCreate8(D3D_SDK_VERSION)))
1774 skip("Failed to create IDirect3D8 object, skipping tests.\n");
1778 wc.lpfnWndProc = test_proc;
1779 wc.lpszClassName = "d3d8_test_wndproc_wc";
1780 ok(RegisterClassA(&wc), "Failed to register window class.\n");
1782 thread_params.window_created = CreateEvent(NULL, FALSE, FALSE, NULL);
1783 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
1784 thread_params.test_finished = CreateEvent(NULL, FALSE, FALSE, NULL);
1785 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
1787 focus_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
1788 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, 640, 480, 0, 0, 0, 0);
1789 device_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
1790 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, 640, 480, 0, 0, 0, 0);
1791 thread = CreateThread(NULL, 0, wndproc_thread, &thread_params, 0, &tid);
1792 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
1794 res = WaitForSingleObject(thread_params.window_created, INFINITE);
1795 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
1797 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
1798 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1799 (LONG_PTR)test_proc, proc);
1800 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1801 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1802 (LONG_PTR)test_proc, proc);
1804 trace("device_window %p, focus_window %p, dummy_window %p.\n",
1805 device_window, focus_window, thread_params.dummy_window);
1808 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
1809 tmp = GetForegroundWindow();
1810 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
1811 thread_params.dummy_window, tmp);
1813 filter_messages = focus_window;
1815 device = create_device(d3d8, device_window, focus_window, TRUE);
1818 skip("Failed to create a D3D device, skipping tests.\n");
1823 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
1824 tmp = GetForegroundWindow();
1825 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
1826 thread_params.dummy_window, tmp);
1828 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
1829 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1830 (LONG_PTR)test_proc, proc);
1832 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1833 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1834 (LONG_PTR)test_proc, proc);
1836 filter_messages = NULL;
1838 hr = reset_device(device, device_window, FALSE);
1839 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
1841 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
1842 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1843 (LONG_PTR)test_proc, proc);
1845 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1846 ok(proc != (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1847 (LONG_PTR)test_proc, proc);
1849 hr = reset_device(device, device_window, TRUE);
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 filter_messages = focus_window;
1862 ref = IDirect3DDevice8_Release(device);
1863 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
1865 filter_messages = device_window;
1867 device = create_device(d3d8, focus_window, focus_window, TRUE);
1870 skip("Failed to create a D3D device, skipping tests.\n");
1874 filter_messages = NULL;
1876 hr = reset_device(device, focus_window, FALSE);
1877 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
1879 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
1880 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1881 (LONG_PTR)test_proc, proc);
1883 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1884 ok(proc != (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1885 (LONG_PTR)test_proc, proc);
1887 hr = reset_device(device, focus_window, TRUE);
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 filter_messages = device_window;
1900 ref = IDirect3DDevice8_Release(device);
1901 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
1903 device = create_device(d3d8, device_window, focus_window, TRUE);
1906 skip("Failed to create a D3D device, skipping tests.\n");
1910 filter_messages = NULL;
1912 hr = reset_device(device, device_window, FALSE);
1913 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
1915 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
1916 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1917 (LONG_PTR)test_proc, proc);
1919 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1920 ok(proc != (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1921 (LONG_PTR)test_proc, proc);
1923 hr = reset_device(device, device_window, TRUE);
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 filter_messages = device_window;
1936 ref = IDirect3DDevice8_Release(device);
1937 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
1940 filter_messages = NULL;
1941 IDirect3D8_Release(d3d8);
1943 SetEvent(thread_params.test_finished);
1944 WaitForSingleObject(thread, INFINITE);
1945 CloseHandle(thread_params.test_finished);
1946 CloseHandle(thread_params.window_created);
1947 CloseHandle(thread);
1949 DestroyWindow(device_window);
1950 DestroyWindow(focus_window);
1951 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL));
1954 static inline void set_fpu_cw(WORD cw)
1956 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1957 __asm__ volatile ("fnclex");
1958 __asm__ volatile ("fldcw %0" : : "m" (cw));
1962 static inline WORD get_fpu_cw(void)
1965 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1966 __asm__ volatile ("fnstcw %0" : "=m" (cw));
1971 static void test_fpu_setup(void)
1973 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1974 D3DPRESENT_PARAMETERS present_parameters;
1975 IDirect3DDevice8 *device;
1976 D3DDISPLAYMODE d3ddm;
1982 d3d8 = pDirect3DCreate8(D3D_SDK_VERSION);
1983 ok(!!d3d8, "Failed to create a d3d8 object.\n");
1986 window = CreateWindowA("static", "d3d8_test", WS_CAPTION, 0, 0, 640, 480, 0, 0, 0, 0);
1987 ok(!!window, "Failed to create a window.\n");
1988 if (!window) goto done;
1990 hr = IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &d3ddm);
1991 ok(SUCCEEDED(hr), "GetAdapterDisplayMode failed, hr %#x.\n", hr);
1993 memset(&present_parameters, 0, sizeof(present_parameters));
1994 present_parameters.Windowed = TRUE;
1995 present_parameters.hDeviceWindow = window;
1996 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
1997 present_parameters.BackBufferFormat = d3ddm.Format;
2001 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
2003 hr = IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
2004 D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device);
2007 skip("Failed to create a device, hr %#x.\n", hr);
2013 ok(cw == 0x7f, "cw is %#x, expected 0x7f.\n", cw);
2015 IDirect3DDevice8_Release(device);
2018 ok(cw == 0x7f, "cw is %#x, expected 0x7f.\n", cw);
2021 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
2023 hr = IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
2024 D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &present_parameters, &device);
2025 ok(SUCCEEDED(hr), "CreateDevice failed, hr %#x.\n", hr);
2028 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
2031 IDirect3DDevice8_Release(device);
2034 if (window) DestroyWindow(window);
2035 if (d3d8) IDirect3D8_Release(d3d8);
2039 static void test_ApplyStateBlock(void)
2041 D3DPRESENT_PARAMETERS d3dpp;
2042 IDirect3DDevice8 *device = NULL;
2046 D3DDISPLAYMODE d3ddm;
2047 DWORD received, token;
2049 d3d8 = pDirect3DCreate8( D3D_SDK_VERSION );
2050 ok(d3d8 != NULL, "Failed to create IDirect3D8 object\n");
2051 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
2052 ok(hwnd != NULL, "Failed to create window\n");
2053 if (!d3d8 || !hwnd) goto cleanup;
2055 IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &d3ddm );
2056 ZeroMemory( &d3dpp, sizeof(d3dpp) );
2057 d3dpp.Windowed = TRUE;
2058 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
2059 d3dpp.BackBufferWidth = 800;
2060 d3dpp.BackBufferHeight = 600;
2061 d3dpp.BackBufferFormat = d3ddm.Format;
2062 d3dpp.EnableAutoDepthStencil = TRUE;
2063 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
2065 hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
2066 D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &d3dpp, &device );
2067 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE || hr == D3DERR_INVALIDCALL,
2068 "IDirect3D8_CreateDevice failed with %#x\n", hr);
2071 skip("Failed to create a d3d device\n");
2075 IDirect3DDevice8_CreateStateBlock(device, D3DSBT_ALL, &token);
2076 ok(token !=0, "received null token\n");
2078 IDirect3DDevice8_BeginStateBlock(device);
2079 IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, TRUE);
2080 IDirect3DDevice8_EndStateBlock(device, &token);
2081 IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, FALSE);
2083 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_ZENABLE, &received);
2084 ok(hr==D3D_OK, "Expected= D3D_OK, Got= %#x\n", hr);
2085 ok(received==FALSE, "Expected = TRUE, received FALSE\n");
2087 IDirect3DDevice8_ApplyStateBlock(device, 0);
2088 ok(hr == D3D_OK, "Expected= D3D_OK, Got= %#x\n", hr);
2089 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_ZENABLE, &received);
2090 ok(hr==D3D_OK, "Expected= D3D_OK, Got= %#x\n", hr);
2091 ok(received==FALSE, "Expected = TRUE, received FALSE\n");
2093 IDirect3DDevice8_ApplyStateBlock(device, token);
2094 ok(hr == D3D_OK, "Expected= D3D_OK, Got= %#x\n", hr);
2095 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_ZENABLE, &received);
2096 ok(hr==D3D_OK, "Expected= D3D_OK, Got= %#x\n", hr);
2097 ok(received==TRUE, "Expected = TRUE, received FALSE\n");
2100 if(device) IDirect3DDevice8_Release(device);
2101 if(d3d8) IDirect3D8_Release(d3d8);
2106 HMODULE d3d8_handle = LoadLibraryA( "d3d8.dll" );
2109 skip("Could not load d3d8.dll\n");
2113 pDirect3DCreate8 = (void *)GetProcAddress( d3d8_handle, "Direct3DCreate8" );
2114 ok(pDirect3DCreate8 != NULL, "Failed to get address of Direct3DCreate8\n");
2115 if (pDirect3DCreate8)
2118 d3d8 = pDirect3DCreate8( D3D_SDK_VERSION );
2121 skip("could not create D3D8\n");
2124 IDirect3D8_Release(d3d8);
2127 test_display_modes();
2128 test_shader_versions();
2131 test_mipmap_levels();
2138 test_ApplyStateBlock();
2139 test_render_zero_triangles();
2140 test_depth_stencil_reset();
2142 test_wndproc_windowed();