pop b0283e26815279d45d201d5585820bb1d1997663
[wine/hacks.git] / dlls / d3d8 / tests / device.c
blobc0e198511ee21a8c4bbb84716c8e9c38daad4e0c
1 /*
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
20 #define COBJMACROS
21 #include <initguid.h>
22 #include <d3d8.h>
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 static IDirect3DDevice8 *create_device(IDirect3D8 *d3d8, HWND device_window, HWND focus_window, BOOL windowed)
51 D3DPRESENT_PARAMETERS present_parameters = {0};
52 IDirect3DDevice8 *device;
54 present_parameters.Windowed = windowed;
55 present_parameters.hDeviceWindow = device_window;
56 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
57 present_parameters.BackBufferWidth = 640;
58 present_parameters.BackBufferHeight = 480;
59 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
60 present_parameters.EnableAutoDepthStencil = TRUE;
61 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
63 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
64 D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device))) return device;
66 present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
67 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
68 D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device))) return device;
70 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
71 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device))) return device;
73 return NULL;
76 #define CHECK_CALL(r,c,d,rc) \
77 if (SUCCEEDED(r)) {\
78 int tmp1 = get_refcount( (IUnknown *)d ); \
79 int rc_new = rc; \
80 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
81 } else {\
82 trace("%s failed: %#08x\n", c, r); \
85 #define CHECK_RELEASE(obj,d,rc) \
86 if (obj) { \
87 int tmp1, rc_new = rc; \
88 IUnknown_Release( obj ); \
89 tmp1 = get_refcount( (IUnknown *)d ); \
90 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
93 #define CHECK_REFCOUNT(obj,rc) \
94 { \
95 int rc_new = rc; \
96 int count = get_refcount( (IUnknown *)obj ); \
97 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
100 #define CHECK_RELEASE_REFCOUNT(obj,rc) \
102 int rc_new = rc; \
103 int count = IUnknown_Release( (IUnknown *)obj ); \
104 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
107 #define CHECK_ADDREF_REFCOUNT(obj,rc) \
109 int rc_new = rc; \
110 int count = IUnknown_AddRef( (IUnknown *)obj ); \
111 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
114 #define CHECK_SURFACE_CONTAINER(obj,iid,expected) \
116 void *container_ptr = (void *)0x1337c0d3; \
117 hr = IDirect3DSurface8_GetContainer(obj, &iid, &container_ptr); \
118 ok(SUCCEEDED(hr) && container_ptr == expected, "GetContainer returned: hr %#08x, container_ptr %p. " \
119 "Expected hr %#08x, container_ptr %p\n", hr, container_ptr, S_OK, expected); \
120 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr); \
123 static void check_mipmap_levels(IDirect3DDevice8 *device, UINT width, UINT height, UINT count)
125 IDirect3DBaseTexture8* texture = NULL;
126 HRESULT hr = IDirect3DDevice8_CreateTexture( device, width, height, 0, 0,
127 D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, (IDirect3DTexture8**) &texture );
129 if (SUCCEEDED(hr)) {
130 DWORD levels = IDirect3DBaseTexture8_GetLevelCount(texture);
131 ok(levels == count, "Invalid level count. Expected %d got %u\n", count, levels);
132 } else
133 trace("CreateTexture failed: %#08x\n", hr);
135 if (texture) IUnknown_Release( texture );
138 static void test_mipmap_levels(void)
141 HRESULT hr;
142 HWND hwnd = NULL;
144 IDirect3D8 *pD3d = NULL;
145 IDirect3DDevice8 *pDevice = NULL;
146 D3DPRESENT_PARAMETERS d3dpp;
147 D3DDISPLAYMODE d3ddm;
149 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
150 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
151 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
152 ok(hwnd != NULL, "Failed to create window\n");
153 if (!pD3d || !hwnd) goto cleanup;
155 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
156 ZeroMemory( &d3dpp, sizeof(d3dpp) );
157 d3dpp.Windowed = TRUE;
158 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
159 d3dpp.BackBufferFormat = d3ddm.Format;
161 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
162 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
163 if(FAILED(hr))
165 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
166 goto cleanup;
169 check_mipmap_levels(pDevice, 32, 32, 6);
170 check_mipmap_levels(pDevice, 256, 1, 9);
171 check_mipmap_levels(pDevice, 1, 256, 9);
172 check_mipmap_levels(pDevice, 1, 1, 1);
174 cleanup:
175 if (pDevice)
177 UINT refcount = IUnknown_Release( pDevice );
178 ok(!refcount, "Device has %u references left.\n", refcount);
180 if (pD3d) IUnknown_Release( pD3d );
181 DestroyWindow( hwnd );
184 static void test_swapchain(void)
186 HRESULT hr;
187 HWND hwnd = NULL;
188 IDirect3D8 *pD3d = NULL;
189 IDirect3DDevice8 *pDevice = NULL;
190 IDirect3DSwapChain8 *swapchain1 = NULL;
191 IDirect3DSwapChain8 *swapchain2 = NULL;
192 IDirect3DSwapChain8 *swapchain3 = NULL;
193 IDirect3DSurface8 *backbuffer = NULL;
194 D3DPRESENT_PARAMETERS d3dpp;
195 D3DDISPLAYMODE d3ddm;
197 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
198 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
199 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
200 ok(hwnd != NULL, "Failed to create window\n");
201 if (!pD3d || !hwnd) goto cleanup;
203 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
204 ZeroMemory( &d3dpp, sizeof(d3dpp) );
205 d3dpp.Windowed = TRUE;
206 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
207 d3dpp.BackBufferFormat = d3ddm.Format;
208 d3dpp.BackBufferCount = 0;
210 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
211 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
212 if(FAILED(hr))
214 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
215 goto cleanup;
218 /* Check if the back buffer count was modified */
219 ok(d3dpp.BackBufferCount == 1, "The back buffer count in the presentparams struct is %d\n", d3dpp.BackBufferCount);
221 /* Create a bunch of swapchains */
222 d3dpp.BackBufferCount = 0;
223 hr = IDirect3DDevice8_CreateAdditionalSwapChain(pDevice, &d3dpp, &swapchain1);
224 ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr);
225 ok(d3dpp.BackBufferCount == 1, "The back buffer count in the presentparams struct is %d\n", d3dpp.BackBufferCount);
227 d3dpp.BackBufferCount = 1;
228 hr = IDirect3DDevice8_CreateAdditionalSwapChain(pDevice, &d3dpp, &swapchain2);
229 ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr);
231 d3dpp.BackBufferCount = 2;
232 hr = IDirect3DDevice8_CreateAdditionalSwapChain(pDevice, &d3dpp, &swapchain3);
233 ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr);
234 if(SUCCEEDED(hr)) {
235 /* Swapchain 3, created with backbuffercount 2 */
236 backbuffer = (void *) 0xdeadbeef;
237 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 0, 0, &backbuffer);
238 ok(SUCCEEDED(hr), "Failed to get the 1st back buffer (%#08x)\n", hr);
239 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
240 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
242 backbuffer = (void *) 0xdeadbeef;
243 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 1, 0, &backbuffer);
244 ok(SUCCEEDED(hr), "Failed to get the 2nd back buffer (%#08x)\n", hr);
245 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
246 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
248 backbuffer = (void *) 0xdeadbeef;
249 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 2, 0, &backbuffer);
250 ok(hr == D3DERR_INVALIDCALL, "GetBackBuffer returned %#08x\n", hr);
251 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
252 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
254 backbuffer = (void *) 0xdeadbeef;
255 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 3, 0, &backbuffer);
256 ok(FAILED(hr), "Failed to get the back buffer (%#08x)\n", hr);
257 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
258 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
261 /* Check the back buffers of the swapchains */
262 /* Swapchain 1, created with backbuffercount 0 */
263 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain1, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
264 ok(SUCCEEDED(hr), "Failed to get the back buffer (%#08x)\n", hr);
265 ok(backbuffer != NULL, "The back buffer is NULL (%#08x)\n", hr);
266 if(backbuffer) IDirect3DSurface8_Release(backbuffer);
268 backbuffer = (void *) 0xdeadbeef;
269 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain1, 1, 0, &backbuffer);
270 ok(FAILED(hr), "Failed to get the back buffer (%#08x)\n", hr);
271 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
272 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
274 /* Swapchain 2 - created with backbuffercount 1 */
275 backbuffer = (void *) 0xdeadbeef;
276 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 0, 0, &backbuffer);
277 ok(SUCCEEDED(hr), "Failed to get the back buffer (%#08x)\n", hr);
278 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
279 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
281 backbuffer = (void *) 0xdeadbeef;
282 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 1, 0, &backbuffer);
283 ok(hr == D3DERR_INVALIDCALL, "GetBackBuffer returned %#08x\n", hr);
284 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
285 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
287 backbuffer = (void *) 0xdeadbeef;
288 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 2, 0, &backbuffer);
289 ok(FAILED(hr), "Failed to get the back buffer (%#08x)\n", hr);
290 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
291 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
293 cleanup:
294 if(swapchain1) IDirect3DSwapChain8_Release(swapchain1);
295 if(swapchain2) IDirect3DSwapChain8_Release(swapchain2);
296 if(swapchain3) IDirect3DSwapChain8_Release(swapchain3);
297 if (pDevice)
299 UINT refcount = IDirect3DDevice8_Release(pDevice);
300 ok(!refcount, "Device has %u references left.\n", refcount);
302 if (pD3d) IDirect3D8_Release(pD3d);
303 DestroyWindow( hwnd );
306 static void test_refcount(void)
308 HRESULT hr;
309 HWND hwnd = NULL;
310 IDirect3D8 *pD3d = NULL;
311 IDirect3DDevice8 *pDevice = NULL;
312 IDirect3DVertexBuffer8 *pVertexBuffer = NULL;
313 IDirect3DIndexBuffer8 *pIndexBuffer = NULL;
314 DWORD dVertexShader = -1;
315 DWORD dPixelShader = -1;
316 IDirect3DCubeTexture8 *pCubeTexture = NULL;
317 IDirect3DTexture8 *pTexture = NULL;
318 IDirect3DVolumeTexture8 *pVolumeTexture = NULL;
319 IDirect3DVolume8 *pVolumeLevel = NULL;
320 IDirect3DSurface8 *pStencilSurface = NULL;
321 IDirect3DSurface8 *pImageSurface = NULL;
322 IDirect3DSurface8 *pRenderTarget = NULL;
323 IDirect3DSurface8 *pRenderTarget2 = NULL;
324 IDirect3DSurface8 *pRenderTarget3 = NULL;
325 IDirect3DSurface8 *pTextureLevel = NULL;
326 IDirect3DSurface8 *pBackBuffer = NULL;
327 DWORD dStateBlock = -1;
328 IDirect3DSwapChain8 *pSwapChain = NULL;
329 D3DCAPS8 caps;
331 D3DPRESENT_PARAMETERS d3dpp;
332 D3DDISPLAYMODE d3ddm;
333 int refcount = 0, tmp;
335 DWORD decl[] =
337 D3DVSD_STREAM(0),
338 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
339 D3DVSD_REG(D3DVSDE_DIFFUSE, D3DVSDT_D3DCOLOR), /* D3DVSDE_DIFFUSE, Register v5 */
340 D3DVSD_END()
343 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
344 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
345 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
346 ok(hwnd != NULL, "Failed to create window\n");
347 if (!pD3d || !hwnd) goto cleanup;
349 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
350 ZeroMemory( &d3dpp, sizeof(d3dpp) );
351 d3dpp.Windowed = TRUE;
352 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
353 d3dpp.BackBufferFormat = d3ddm.Format;
354 d3dpp.EnableAutoDepthStencil = TRUE;
355 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
357 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
358 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
359 if(FAILED(hr))
361 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
362 goto cleanup;
364 IDirect3DDevice8_GetDeviceCaps(pDevice, &caps);
366 refcount = get_refcount( (IUnknown *)pDevice );
367 ok(refcount == 1, "Invalid device RefCount %d\n", refcount);
370 * Check refcount of implicit surfaces. Findings:
371 * - the container is the device
372 * - they hold a reference to the device
373 * - they are created with a refcount of 0 (Get/Release returns original refcount)
374 * - they are not freed if refcount reaches 0.
375 * - the refcount is not forwarded to the container.
377 hr = IDirect3DDevice8_GetRenderTarget(pDevice, &pRenderTarget);
378 CHECK_CALL( hr, "GetRenderTarget", pDevice, ++refcount);
379 if(pRenderTarget)
381 CHECK_SURFACE_CONTAINER( pRenderTarget, IID_IDirect3DDevice8, pDevice);
382 CHECK_REFCOUNT( pRenderTarget, 1);
384 CHECK_ADDREF_REFCOUNT(pRenderTarget, 2);
385 CHECK_REFCOUNT(pDevice, refcount);
386 CHECK_RELEASE_REFCOUNT(pRenderTarget, 1);
387 CHECK_REFCOUNT(pDevice, refcount);
389 hr = IDirect3DDevice8_GetRenderTarget(pDevice, &pRenderTarget);
390 CHECK_CALL( hr, "GetRenderTarget", pDevice, refcount);
391 CHECK_REFCOUNT( pRenderTarget, 2);
392 CHECK_RELEASE_REFCOUNT( pRenderTarget, 1);
393 CHECK_RELEASE_REFCOUNT( pRenderTarget, 0);
394 CHECK_REFCOUNT( pDevice, --refcount);
396 /* The render target is released with the device, so AddRef with refcount=0 is fine here. */
397 CHECK_ADDREF_REFCOUNT(pRenderTarget, 1);
398 CHECK_REFCOUNT(pDevice, ++refcount);
399 CHECK_RELEASE_REFCOUNT(pRenderTarget, 0);
400 CHECK_REFCOUNT(pDevice, --refcount);
403 /* Render target and back buffer are identical. */
404 hr = IDirect3DDevice8_GetBackBuffer(pDevice, 0, 0, &pBackBuffer);
405 CHECK_CALL( hr, "GetBackBuffer", pDevice, ++refcount);
406 if(pBackBuffer)
408 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
409 ok(pRenderTarget == pBackBuffer, "RenderTarget=%p and BackBuffer=%p should be the same.\n",
410 pRenderTarget, pBackBuffer);
411 pBackBuffer = NULL;
413 CHECK_REFCOUNT( pDevice, --refcount);
415 hr = IDirect3DDevice8_GetDepthStencilSurface(pDevice, &pStencilSurface);
416 CHECK_CALL( hr, "GetDepthStencilSurface", pDevice, ++refcount);
417 if(pStencilSurface)
419 CHECK_SURFACE_CONTAINER( pStencilSurface, IID_IDirect3DDevice8, pDevice);
420 CHECK_REFCOUNT( pStencilSurface, 1);
422 CHECK_ADDREF_REFCOUNT(pStencilSurface, 2);
423 CHECK_REFCOUNT(pDevice, refcount);
424 CHECK_RELEASE_REFCOUNT(pStencilSurface, 1);
425 CHECK_REFCOUNT(pDevice, refcount);
427 CHECK_RELEASE_REFCOUNT( pStencilSurface, 0);
428 CHECK_REFCOUNT( pDevice, --refcount);
430 /* The stencil surface is released with the device, so AddRef with refcount=0 is fine here. */
431 CHECK_ADDREF_REFCOUNT(pStencilSurface, 1);
432 CHECK_REFCOUNT(pDevice, ++refcount);
433 CHECK_RELEASE_REFCOUNT(pStencilSurface, 0);
434 CHECK_REFCOUNT(pDevice, --refcount);
435 pStencilSurface = NULL;
438 /* Buffers */
439 hr = IDirect3DDevice8_CreateIndexBuffer( pDevice, 16, 0, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &pIndexBuffer );
440 CHECK_CALL( hr, "CreateIndexBuffer", pDevice, ++refcount );
441 if(pIndexBuffer)
443 tmp = get_refcount( (IUnknown *)pIndexBuffer );
445 hr = IDirect3DDevice8_SetIndices(pDevice, pIndexBuffer, 0);
446 CHECK_CALL( hr, "SetIndices", pIndexBuffer, tmp);
447 hr = IDirect3DDevice8_SetIndices(pDevice, NULL, 0);
448 CHECK_CALL( hr, "SetIndices", pIndexBuffer, tmp);
451 hr = IDirect3DDevice8_CreateVertexBuffer( pDevice, 16, 0, D3DFVF_XYZ, D3DPOOL_DEFAULT, &pVertexBuffer );
452 CHECK_CALL( hr, "CreateVertexBuffer", pDevice, ++refcount );
453 if(pVertexBuffer)
455 IDirect3DVertexBuffer8 *pVBuf = (void*)~0;
456 UINT stride = ~0;
458 tmp = get_refcount( (IUnknown *)pVertexBuffer );
460 hr = IDirect3DDevice8_SetStreamSource(pDevice, 0, pVertexBuffer, 3 * sizeof(float));
461 CHECK_CALL( hr, "SetStreamSource", pVertexBuffer, tmp);
462 hr = IDirect3DDevice8_SetStreamSource(pDevice, 0, NULL, 0);
463 CHECK_CALL( hr, "SetStreamSource", pVertexBuffer, tmp);
465 hr = IDirect3DDevice8_GetStreamSource(pDevice, 0, &pVBuf, &stride);
466 ok(SUCCEEDED(hr), "GetStreamSource did not succeed with NULL stream!\n");
467 ok(pVBuf==NULL, "pVBuf not NULL (%p)!\n", pVBuf);
468 ok(stride==3*sizeof(float), "stride not 3 floats (got %u)!\n", stride);
471 /* Shaders */
472 hr = IDirect3DDevice8_CreateVertexShader( pDevice, decl, simple_vs, &dVertexShader, 0 );
473 CHECK_CALL( hr, "CreateVertexShader", pDevice, refcount );
474 if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 0))
476 hr = IDirect3DDevice8_CreatePixelShader( pDevice, simple_ps, &dPixelShader );
477 CHECK_CALL( hr, "CreatePixelShader", pDevice, refcount );
479 /* Textures */
480 hr = IDirect3DDevice8_CreateTexture( pDevice, 32, 32, 3, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pTexture );
481 CHECK_CALL( hr, "CreateTexture", pDevice, ++refcount );
482 if (pTexture)
484 tmp = get_refcount( (IUnknown *)pTexture );
486 /* SetTexture should not increase refcounts */
487 hr = IDirect3DDevice8_SetTexture(pDevice, 0, (IDirect3DBaseTexture8 *) pTexture);
488 CHECK_CALL( hr, "SetTexture", pTexture, tmp);
489 hr = IDirect3DDevice8_SetTexture(pDevice, 0, NULL);
490 CHECK_CALL( hr, "SetTexture", pTexture, tmp);
492 /* This should not increment device refcount */
493 hr = IDirect3DTexture8_GetSurfaceLevel( pTexture, 1, &pTextureLevel );
494 CHECK_CALL( hr, "GetSurfaceLevel", pDevice, refcount );
495 /* But should increment texture's refcount */
496 CHECK_REFCOUNT( pTexture, tmp+1 );
497 /* Because the texture and surface refcount are identical */
498 if (pTextureLevel)
500 CHECK_REFCOUNT ( pTextureLevel, tmp+1 );
501 CHECK_ADDREF_REFCOUNT ( pTextureLevel, tmp+2 );
502 CHECK_REFCOUNT ( pTexture , tmp+2 );
503 CHECK_RELEASE_REFCOUNT( pTextureLevel, tmp+1 );
504 CHECK_REFCOUNT ( pTexture , tmp+1 );
505 CHECK_RELEASE_REFCOUNT( pTexture , tmp );
506 CHECK_REFCOUNT ( pTextureLevel, tmp );
509 if(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP)
511 hr = IDirect3DDevice8_CreateCubeTexture( pDevice, 32, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pCubeTexture );
512 CHECK_CALL( hr, "CreateCubeTexture", pDevice, ++refcount );
514 else
516 skip("Cube textures not supported\n");
518 if(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP)
520 hr = IDirect3DDevice8_CreateVolumeTexture( pDevice, 32, 32, 2, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pVolumeTexture );
521 CHECK_CALL( hr, "CreateVolumeTexture", pDevice, ++refcount );
523 else
525 skip("Volume textures not supported\n");
528 if (pVolumeTexture)
530 tmp = get_refcount( (IUnknown *)pVolumeTexture );
532 /* This should not increment device refcount */
533 hr = IDirect3DVolumeTexture8_GetVolumeLevel(pVolumeTexture, 0, &pVolumeLevel);
534 CHECK_CALL( hr, "GetVolumeLevel", pDevice, refcount );
535 /* But should increment volume texture's refcount */
536 CHECK_REFCOUNT( pVolumeTexture, tmp+1 );
537 /* Because the volume texture and volume refcount are identical */
538 if (pVolumeLevel)
540 CHECK_REFCOUNT ( pVolumeLevel , tmp+1 );
541 CHECK_ADDREF_REFCOUNT ( pVolumeLevel , tmp+2 );
542 CHECK_REFCOUNT ( pVolumeTexture, tmp+2 );
543 CHECK_RELEASE_REFCOUNT( pVolumeLevel , tmp+1 );
544 CHECK_REFCOUNT ( pVolumeTexture, tmp+1 );
545 CHECK_RELEASE_REFCOUNT( pVolumeTexture, tmp );
546 CHECK_REFCOUNT ( pVolumeLevel , tmp );
549 /* Surfaces */
550 hr = IDirect3DDevice8_CreateDepthStencilSurface( pDevice, 32, 32, D3DFMT_D16, D3DMULTISAMPLE_NONE, &pStencilSurface );
551 CHECK_CALL( hr, "CreateDepthStencilSurface", pDevice, ++refcount );
552 CHECK_REFCOUNT( pStencilSurface, 1);
553 hr = IDirect3DDevice8_CreateImageSurface( pDevice, 32, 32, D3DFMT_X8R8G8B8, &pImageSurface );
554 CHECK_CALL( hr, "CreateImageSurface", pDevice, ++refcount );
555 CHECK_REFCOUNT( pImageSurface, 1);
556 hr = IDirect3DDevice8_CreateRenderTarget( pDevice, 32, 32, D3DFMT_X8R8G8B8, D3DMULTISAMPLE_NONE, TRUE, &pRenderTarget3 );
557 CHECK_CALL( hr, "CreateRenderTarget", pDevice, ++refcount );
558 CHECK_REFCOUNT( pRenderTarget3, 1);
559 /* Misc */
560 hr = IDirect3DDevice8_CreateStateBlock( pDevice, D3DSBT_ALL, &dStateBlock );
561 CHECK_CALL( hr, "CreateStateBlock", pDevice, refcount );
562 hr = IDirect3DDevice8_CreateAdditionalSwapChain( pDevice, &d3dpp, &pSwapChain );
563 CHECK_CALL( hr, "CreateAdditionalSwapChain", pDevice, ++refcount );
564 if(pSwapChain)
566 /* check implicit back buffer */
567 hr = IDirect3DSwapChain8_GetBackBuffer(pSwapChain, 0, 0, &pBackBuffer);
568 CHECK_CALL( hr, "GetBackBuffer", pDevice, ++refcount);
569 CHECK_REFCOUNT( pSwapChain, 1);
570 if(pBackBuffer)
572 CHECK_SURFACE_CONTAINER( pBackBuffer, IID_IDirect3DDevice8, pDevice);
573 CHECK_REFCOUNT( pBackBuffer, 1);
574 CHECK_RELEASE_REFCOUNT( pBackBuffer, 0);
575 CHECK_REFCOUNT( pDevice, --refcount);
577 /* The back buffer is released with the swapchain, so AddRef with refcount=0 is fine here. */
578 CHECK_ADDREF_REFCOUNT(pBackBuffer, 1);
579 CHECK_REFCOUNT(pDevice, ++refcount);
580 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
581 CHECK_REFCOUNT(pDevice, --refcount);
582 pBackBuffer = NULL;
584 CHECK_REFCOUNT( pSwapChain, 1);
587 if(pVertexBuffer)
589 BYTE *data;
590 /* Vertex buffers can be locked multiple times */
591 hr = IDirect3DVertexBuffer8_Lock(pVertexBuffer, 0, 0, &data, 0);
592 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr);
593 hr = IDirect3DVertexBuffer8_Lock(pVertexBuffer, 0, 0, &data, 0);
594 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr);
595 hr = IDirect3DVertexBuffer8_Unlock(pVertexBuffer);
596 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr);
597 hr = IDirect3DVertexBuffer8_Unlock(pVertexBuffer);
598 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr);
601 /* The implicit render target is not freed if refcount reaches 0.
602 * Otherwise GetRenderTarget would re-allocate it and the pointer would change.*/
603 hr = IDirect3DDevice8_GetRenderTarget(pDevice, &pRenderTarget2);
604 CHECK_CALL( hr, "GetRenderTarget", pDevice, ++refcount);
605 if(pRenderTarget2)
607 CHECK_RELEASE_REFCOUNT(pRenderTarget2, 0);
608 ok(pRenderTarget == pRenderTarget2, "RenderTarget=%p and RenderTarget2=%p should be the same.\n",
609 pRenderTarget, pRenderTarget2);
610 CHECK_REFCOUNT( pDevice, --refcount);
611 pRenderTarget2 = NULL;
613 pRenderTarget = NULL;
615 cleanup:
616 CHECK_RELEASE(pDevice, pDevice, --refcount);
618 /* Buffers */
619 CHECK_RELEASE(pVertexBuffer, pDevice, --refcount);
620 CHECK_RELEASE(pIndexBuffer, pDevice, --refcount);
621 /* Shaders */
622 if (dVertexShader != ~0U) IDirect3DDevice8_DeleteVertexShader( pDevice, dVertexShader );
623 if (dPixelShader != ~0U) IDirect3DDevice8_DeletePixelShader( pDevice, dPixelShader );
624 /* Textures */
625 CHECK_RELEASE(pTexture, pDevice, --refcount);
626 CHECK_RELEASE(pCubeTexture, pDevice, --refcount);
627 CHECK_RELEASE(pVolumeTexture, pDevice, --refcount);
628 /* Surfaces */
629 CHECK_RELEASE(pStencilSurface, pDevice, --refcount);
630 CHECK_RELEASE(pImageSurface, pDevice, --refcount);
631 CHECK_RELEASE(pRenderTarget3, pDevice, --refcount);
632 /* Misc */
633 if (dStateBlock != ~0U) IDirect3DDevice8_DeleteStateBlock( pDevice, dStateBlock );
634 /* This will destroy device - cannot check the refcount here */
635 if (pSwapChain) CHECK_RELEASE_REFCOUNT( pSwapChain, 0);
637 if (pD3d) CHECK_RELEASE_REFCOUNT( pD3d, 0);
639 DestroyWindow( hwnd );
642 static void test_cursor(void)
644 HRESULT hr;
645 HWND hwnd = NULL;
646 IDirect3D8 *pD3d = NULL;
647 IDirect3DDevice8 *pDevice = NULL;
648 D3DPRESENT_PARAMETERS d3dpp;
649 D3DDISPLAYMODE d3ddm;
650 CURSORINFO info;
651 IDirect3DSurface8 *cursor = NULL;
652 HCURSOR cur;
653 HMODULE user32_handle = GetModuleHandleA("user32.dll");
655 pGetCursorInfo = (void *)GetProcAddress(user32_handle, "GetCursorInfo");
656 if (!pGetCursorInfo)
658 win_skip("GetCursorInfo is not available\n");
659 return;
662 memset(&info, 0, sizeof(info));
663 info.cbSize = sizeof(info);
664 ok(pGetCursorInfo(&info), "GetCursorInfo failed\n");
665 cur = info.hCursor;
667 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
668 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
669 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
670 ok(hwnd != NULL, "Failed to create window\n");
671 if (!pD3d || !hwnd) goto cleanup;
673 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
674 ZeroMemory( &d3dpp, sizeof(d3dpp) );
675 d3dpp.Windowed = TRUE;
676 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
677 d3dpp.BackBufferFormat = d3ddm.Format;
679 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
680 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
681 if(FAILED(hr))
683 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
684 goto cleanup;
687 IDirect3DDevice8_CreateImageSurface(pDevice, 32, 32, D3DFMT_A8R8G8B8, &cursor);
688 ok(cursor != NULL, "IDirect3DDevice8_CreateOffscreenPlainSurface failed with %#08x\n", hr);
690 /* Initially hidden */
691 hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
692 ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
694 /* Not enabled without a surface*/
695 hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
696 ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
698 /* Fails */
699 hr = IDirect3DDevice8_SetCursorProperties(pDevice, 0, 0, NULL);
700 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr);
702 hr = IDirect3DDevice8_SetCursorProperties(pDevice, 0, 0, cursor);
703 ok(hr == D3D_OK, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr);
705 IDirect3DSurface8_Release(cursor);
707 memset(&info, 0, sizeof(info));
708 info.cbSize = sizeof(info);
709 ok(pGetCursorInfo(&info), "GetCursorInfo failed\n");
710 ok(info.flags & CURSOR_SHOWING, "The gdi cursor is hidden (%08x)\n", info.flags);
711 ok(info.hCursor == cur, "The cursor handle is %p\n", info.hCursor); /* unchanged */
713 /* Still hidden */
714 hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
715 ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
717 /* Enabled now*/
718 hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
719 ok(hr == TRUE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
721 /* GDI cursor unchanged */
722 memset(&info, 0, sizeof(info));
723 info.cbSize = sizeof(info);
724 ok(pGetCursorInfo(&info), "GetCursorInfo failed\n");
725 ok(info.flags & CURSOR_SHOWING, "The gdi cursor is hidden (%08x)\n", info.flags);
726 ok(info.hCursor == cur, "The cursor handle is %p\n", info.hCursor); /* unchanged */
728 cleanup:
729 if (pDevice)
731 UINT refcount = IDirect3DDevice8_Release(pDevice);
732 ok(!refcount, "Device has %u references left.\n", refcount);
734 if (pD3d) IDirect3D8_Release(pD3d);
737 static void test_states(void)
739 HRESULT hr;
740 HWND hwnd = NULL;
741 IDirect3D8 *pD3d = NULL;
742 IDirect3DDevice8 *pDevice = NULL;
743 D3DPRESENT_PARAMETERS d3dpp;
744 D3DDISPLAYMODE d3ddm;
746 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
747 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
748 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
749 ok(hwnd != NULL, "Failed to create window\n");
750 if (!pD3d || !hwnd) goto cleanup;
752 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
753 ZeroMemory( &d3dpp, sizeof(d3dpp) );
754 d3dpp.Windowed = TRUE;
755 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
756 d3dpp.BackBufferWidth = 640;
757 d3dpp.BackBufferHeight = 480;
758 d3dpp.BackBufferFormat = d3ddm.Format;
760 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
761 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
762 if(FAILED(hr))
764 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
765 goto cleanup;
768 hr = IDirect3DDevice8_SetRenderState(pDevice, D3DRS_ZVISIBLE, TRUE);
769 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, TRUE) returned %#08x\n", hr);
770 hr = IDirect3DDevice8_SetRenderState(pDevice, D3DRS_ZVISIBLE, FALSE);
771 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, FALSE) returned %#08x\n", hr);
773 cleanup:
774 if (pDevice)
776 UINT refcount = IDirect3DDevice8_Release(pDevice);
777 ok(!refcount, "Device has %u references left.\n", refcount);
779 if (pD3d) IDirect3D8_Release(pD3d);
782 static void test_shader_versions(void)
784 HRESULT hr;
785 IDirect3D8 *pD3d = NULL;
786 D3DCAPS8 d3dcaps;
788 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
789 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
790 if (pD3d != NULL) {
791 hr = IDirect3D8_GetDeviceCaps(pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dcaps);
792 ok(SUCCEEDED(hr) || hr == D3DERR_NOTAVAILABLE, "Failed to get D3D8 caps (%#08x)\n", hr);
793 if (SUCCEEDED(hr)) {
794 ok(d3dcaps.VertexShaderVersion <= D3DVS_VERSION(1,1), "Unexpected VertexShaderVersion (%#x > %#x)\n", d3dcaps.VertexShaderVersion, D3DVS_VERSION(1,1));
795 ok(d3dcaps.PixelShaderVersion <= D3DPS_VERSION(1,4), "Unexpected PixelShaderVersion (%#x > %#x)\n", d3dcaps.PixelShaderVersion, D3DPS_VERSION(1,4));
796 } else {
797 skip("No Direct3D support\n");
799 IDirect3D8_Release(pD3d);
804 /* Test adapter display modes */
805 static void test_display_modes(void)
807 UINT max_modes, i;
808 D3DDISPLAYMODE dmode;
809 HRESULT res;
810 IDirect3D8 *pD3d;
812 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
813 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
814 if(!pD3d) return;
816 max_modes = IDirect3D8_GetAdapterModeCount(pD3d, D3DADAPTER_DEFAULT);
817 ok(max_modes > 0 ||
818 broken(max_modes == 0), /* VMware */
819 "GetAdapterModeCount(D3DADAPTER_DEFAULT) returned 0!\n");
821 for(i=0; i<max_modes;i++) {
822 res = IDirect3D8_EnumAdapterModes(pD3d, D3DADAPTER_DEFAULT, i, &dmode);
823 ok(res==D3D_OK, "EnumAdapterModes returned %#08x for mode %u!\n", res, i);
824 if(res != D3D_OK)
825 continue;
827 ok(dmode.Format==D3DFMT_X8R8G8B8 || dmode.Format==D3DFMT_R5G6B5,
828 "Unexpected display mode returned for mode %u: %#x\n", i , dmode.Format);
831 IDirect3D8_Release(pD3d);
834 static void test_scene(void)
836 HRESULT hr;
837 HWND hwnd = NULL;
838 IDirect3D8 *pD3d = NULL;
839 IDirect3DDevice8 *pDevice = NULL;
840 D3DPRESENT_PARAMETERS d3dpp;
841 D3DDISPLAYMODE d3ddm;
843 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
844 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
845 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
846 ok(hwnd != NULL, "Failed to create window\n");
847 if (!pD3d || !hwnd) goto cleanup;
849 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
850 ZeroMemory( &d3dpp, sizeof(d3dpp) );
851 d3dpp.Windowed = TRUE;
852 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
853 d3dpp.BackBufferWidth = 800;
854 d3dpp.BackBufferHeight = 600;
855 d3dpp.BackBufferFormat = d3ddm.Format;
858 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
859 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
860 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL || broken(hr == D3DERR_NOTAVAILABLE), "IDirect3D8_CreateDevice failed with %#08x\n", hr);
861 if(!pDevice)
863 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
864 goto cleanup;
867 /* Test an EndScene without beginscene. Should return an error */
868 hr = IDirect3DDevice8_EndScene(pDevice);
869 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
871 /* Test a normal BeginScene / EndScene pair, this should work */
872 hr = IDirect3DDevice8_BeginScene(pDevice);
873 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
874 if(SUCCEEDED(hr))
876 hr = IDirect3DDevice8_EndScene(pDevice);
877 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
880 /* Test another EndScene without having begun a new scene. Should return an error */
881 hr = IDirect3DDevice8_EndScene(pDevice);
882 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
884 /* Two nested BeginScene and EndScene calls */
885 hr = IDirect3DDevice8_BeginScene(pDevice);
886 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
887 hr = IDirect3DDevice8_BeginScene(pDevice);
888 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_BeginScene returned %#08x\n", hr);
889 hr = IDirect3DDevice8_EndScene(pDevice);
890 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
891 hr = IDirect3DDevice8_EndScene(pDevice);
892 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
894 /* StretchRect does not exit in Direct3D8, so no equivalent to the d3d9 stretchrect tests */
896 cleanup:
897 if (pDevice)
899 UINT refcount = IDirect3DDevice8_Release(pDevice);
900 ok(!refcount, "Device has %u references left.\n", refcount);
902 if (pD3d) IDirect3D8_Release(pD3d);
903 if(hwnd) DestroyWindow(hwnd);
906 static void test_shader(void)
908 HRESULT hr;
909 HWND hwnd = NULL;
910 IDirect3D8 *pD3d = NULL;
911 IDirect3DDevice8 *pDevice = NULL;
912 D3DPRESENT_PARAMETERS d3dpp;
913 D3DDISPLAYMODE d3ddm;
914 DWORD hPixelShader = 0, hVertexShader = 0;
915 DWORD hPixelShader2 = 0, hVertexShader2 = 0;
916 DWORD hTempHandle;
917 D3DCAPS8 caps;
918 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
919 DWORD data_size;
920 void *data;
922 static DWORD dwVertexDecl[] =
924 D3DVSD_STREAM(0),
925 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3),
926 D3DVSD_END()
928 DWORD decl_normal_float2[] =
930 D3DVSD_STREAM(0),
931 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
932 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT2), /* D3DVSDE_NORMAL, Register v1 */
933 D3DVSD_END()
935 DWORD decl_normal_float4[] =
937 D3DVSD_STREAM(0),
938 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
939 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT4), /* D3DVSDE_NORMAL, Register v1 */
940 D3DVSD_END()
942 DWORD decl_normal_d3dcolor[] =
944 D3DVSD_STREAM(0),
945 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
946 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_D3DCOLOR),/* D3DVSDE_NORMAL, Register v1 */
947 D3DVSD_END()
949 const DWORD vertex_decl_size = sizeof(dwVertexDecl);
950 const DWORD simple_vs_size = sizeof(simple_vs);
951 const DWORD simple_ps_size = sizeof(simple_ps);
953 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
954 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
955 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
956 ok(hwnd != NULL, "Failed to create window\n");
957 if (!pD3d || !hwnd) goto cleanup;
959 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
960 ZeroMemory( &d3dpp, sizeof(d3dpp) );
961 d3dpp.Windowed = TRUE;
962 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
963 d3dpp.BackBufferWidth = 800;
964 d3dpp.BackBufferHeight = 600;
965 d3dpp.BackBufferFormat = d3ddm.Format;
968 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
969 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
970 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL || broken(hr == D3DERR_NOTAVAILABLE), "IDirect3D8_CreateDevice failed with %#08x\n", hr);
971 if(!pDevice)
973 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
974 goto cleanup;
976 IDirect3DDevice8_GetDeviceCaps(pDevice, &caps);
978 /* Test setting and retrieving a FVF */
979 hr = IDirect3DDevice8_SetVertexShader(pDevice, fvf);
980 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
981 hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
982 ok(SUCCEEDED(hr), "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
983 ok(hTempHandle == fvf, "Vertex shader %#08x is set, expected %#08x\n", hTempHandle, fvf);
985 /* First create a vertex shader */
986 hr = IDirect3DDevice8_SetVertexShader(pDevice, 0);
987 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
988 hr = IDirect3DDevice8_CreateVertexShader(pDevice, dwVertexDecl, simple_vs, &hVertexShader, 0);
989 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
990 /* Msdn says that the new vertex shader is set immediately. This is wrong, apparently */
991 hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
992 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
993 ok(hTempHandle == 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, 0);
994 /* Assign the shader, then verify that GetVertexShader works */
995 hr = IDirect3DDevice8_SetVertexShader(pDevice, hVertexShader);
996 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
997 hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
998 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
999 ok(hTempHandle == hVertexShader, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, hVertexShader);
1000 /* Verify that we can retrieve the declaration */
1001 hr = IDirect3DDevice8_GetVertexShaderDeclaration(pDevice, hVertexShader, NULL, &data_size);
1002 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr);
1003 ok(data_size == vertex_decl_size, "Got data_size %u, expected %u\n", data_size, vertex_decl_size);
1004 data = HeapAlloc(GetProcessHeap(), 0, vertex_decl_size);
1005 data_size = 1;
1006 hr = IDirect3DDevice8_GetVertexShaderDeclaration(pDevice, hVertexShader, data, &data_size);
1007 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetVertexShaderDeclaration returned (%#08x), "
1008 "expected D3DERR_INVALIDCALL\n", hr);
1009 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
1010 data_size = vertex_decl_size;
1011 hr = IDirect3DDevice8_GetVertexShaderDeclaration(pDevice, hVertexShader, data, &data_size);
1012 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr);
1013 ok(data_size == vertex_decl_size, "Got data_size %u, expected %u\n", data_size, vertex_decl_size);
1014 ok(!memcmp(data, dwVertexDecl, vertex_decl_size), "data not equal to shader declaration\n");
1015 HeapFree(GetProcessHeap(), 0, data);
1016 /* Verify that we can retrieve the shader function */
1017 hr = IDirect3DDevice8_GetVertexShaderFunction(pDevice, hVertexShader, NULL, &data_size);
1018 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr);
1019 ok(data_size == simple_vs_size, "Got data_size %u, expected %u\n", data_size, simple_vs_size);
1020 data = HeapAlloc(GetProcessHeap(), 0, simple_vs_size);
1021 data_size = 1;
1022 hr = IDirect3DDevice8_GetVertexShaderFunction(pDevice, hVertexShader, data, &data_size);
1023 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetVertexShaderFunction returned (%#08x), "
1024 "expected D3DERR_INVALIDCALL\n", hr);
1025 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
1026 data_size = simple_vs_size;
1027 hr = IDirect3DDevice8_GetVertexShaderFunction(pDevice, hVertexShader, data, &data_size);
1028 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr);
1029 ok(data_size == simple_vs_size, "Got data_size %u, expected %u\n", data_size, simple_vs_size);
1030 ok(!memcmp(data, simple_vs, simple_vs_size), "data not equal to shader function\n");
1031 HeapFree(GetProcessHeap(), 0, data);
1032 /* Delete the assigned shader. This is supposed to work */
1033 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1034 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1035 /* The shader should be unset now */
1036 hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
1037 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1038 ok(hTempHandle == 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, 0);
1040 /* Test a broken declaration. 3DMark2001 tries to use normals with 2 components
1041 * First try the fixed function shader function, then a custom one
1043 hr = IDirect3DDevice8_CreateVertexShader(pDevice, decl_normal_float2, 0, &hVertexShader, 0);
1044 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1045 if(SUCCEEDED(hr)) IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1046 hr = IDirect3DDevice8_CreateVertexShader(pDevice, decl_normal_float4, 0, &hVertexShader, 0);
1047 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1048 if(SUCCEEDED(hr)) IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1049 hr = IDirect3DDevice8_CreateVertexShader(pDevice, decl_normal_d3dcolor, 0, &hVertexShader, 0);
1050 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1051 if(SUCCEEDED(hr)) IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1053 hr = IDirect3DDevice8_CreateVertexShader(pDevice, decl_normal_float2, simple_vs, &hVertexShader, 0);
1054 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1055 if(SUCCEEDED(hr)) IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1057 if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 0))
1059 /* The same with a pixel shader */
1060 hr = IDirect3DDevice8_CreatePixelShader(pDevice, simple_ps, &hPixelShader);
1061 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
1062 /* Msdn says that the new pixel shader is set immediately. This is wrong, apparently */
1063 hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle);
1064 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1065 ok(hTempHandle == 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, 0);
1066 /* Assign the shader, then verify that GetPixelShader works */
1067 hr = IDirect3DDevice8_SetPixelShader(pDevice, hPixelShader);
1068 ok(hr == D3D_OK, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr);
1069 hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle);
1070 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1071 ok(hTempHandle == hPixelShader, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, hPixelShader);
1072 /* Verify that we can retrieve the shader function */
1073 hr = IDirect3DDevice8_GetPixelShaderFunction(pDevice, hPixelShader, NULL, &data_size);
1074 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr);
1075 ok(data_size == simple_ps_size, "Got data_size %u, expected %u\n", data_size, simple_ps_size);
1076 data = HeapAlloc(GetProcessHeap(), 0, simple_ps_size);
1077 data_size = 1;
1078 hr = IDirect3DDevice8_GetPixelShaderFunction(pDevice, hPixelShader, data, &data_size);
1079 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetPixelShaderFunction returned (%#08x), "
1080 "expected D3DERR_INVALIDCALL\n", hr);
1081 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
1082 data_size = simple_ps_size;
1083 hr = IDirect3DDevice8_GetPixelShaderFunction(pDevice, hPixelShader, data, &data_size);
1084 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr);
1085 ok(data_size == simple_ps_size, "Got data_size %u, expected %u\n", data_size, simple_ps_size);
1086 ok(!memcmp(data, simple_ps, simple_ps_size), "data not equal to shader function\n");
1087 HeapFree(GetProcessHeap(), 0, data);
1088 /* Delete the assigned shader. This is supposed to work */
1089 hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader);
1090 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1091 /* The shader should be unset now */
1092 hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle);
1093 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1094 ok(hTempHandle == 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, 0);
1096 /* What happens if a non-bound shader is deleted? */
1097 hr = IDirect3DDevice8_CreatePixelShader(pDevice, simple_ps, &hPixelShader);
1098 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
1099 hr = IDirect3DDevice8_CreatePixelShader(pDevice, simple_ps, &hPixelShader2);
1100 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
1102 hr = IDirect3DDevice8_SetPixelShader(pDevice, hPixelShader);
1103 ok(hr == D3D_OK, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr);
1104 hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader2);
1105 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1106 hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle);
1107 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1108 ok(hTempHandle == hPixelShader, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, hPixelShader);
1109 hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader);
1110 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1112 /* Check for double delete. */
1113 hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader2);
1114 ok(hr == D3DERR_INVALIDCALL || broken(hr == D3D_OK), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1115 hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader);
1116 ok(hr == D3DERR_INVALIDCALL || broken(hr == D3D_OK), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1118 else
1120 skip("Pixel shaders not supported\n");
1123 /* What happens if a non-bound shader is deleted? */
1124 hr = IDirect3DDevice8_CreateVertexShader(pDevice, dwVertexDecl, NULL, &hVertexShader, 0);
1125 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1126 hr = IDirect3DDevice8_CreateVertexShader(pDevice, dwVertexDecl, NULL, &hVertexShader2, 0);
1127 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1129 hr = IDirect3DDevice8_SetVertexShader(pDevice, hVertexShader);
1130 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1131 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader2);
1132 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1133 hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
1134 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1135 ok(hTempHandle == hVertexShader, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, hVertexShader);
1136 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1137 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1139 /* Check for double delete. */
1140 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader2);
1141 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1142 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1143 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1145 cleanup:
1146 if (pDevice)
1148 UINT refcount = IDirect3DDevice8_Release(pDevice);
1149 ok(!refcount, "Device has %u references left.\n", refcount);
1151 if (pD3d) IDirect3D8_Release(pD3d);
1152 if(hwnd) DestroyWindow(hwnd);
1155 static void test_limits(void)
1157 HRESULT hr;
1158 HWND hwnd = NULL;
1159 IDirect3D8 *pD3d = NULL;
1160 IDirect3DDevice8 *pDevice = NULL;
1161 D3DPRESENT_PARAMETERS d3dpp;
1162 D3DDISPLAYMODE d3ddm;
1163 IDirect3DTexture8 *pTexture = NULL;
1164 int i;
1166 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
1167 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
1168 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1169 ok(hwnd != NULL, "Failed to create window\n");
1170 if (!pD3d || !hwnd) goto cleanup;
1172 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
1173 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1174 d3dpp.Windowed = TRUE;
1175 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1176 d3dpp.BackBufferWidth = 800;
1177 d3dpp.BackBufferHeight = 600;
1178 d3dpp.BackBufferFormat = d3ddm.Format;
1179 d3dpp.EnableAutoDepthStencil = TRUE;
1180 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
1182 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1183 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
1184 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL || broken(hr == D3DERR_NOTAVAILABLE), "IDirect3D8_CreateDevice failed with %#08x\n", hr);
1185 if(!pDevice)
1187 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
1188 goto cleanup;
1191 hr = IDirect3DDevice8_CreateTexture(pDevice, 16, 16, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pTexture);
1192 ok(hr == D3D_OK, "IDirect3DDevice8_CreateTexture failed with %#08x\n", hr);
1193 if(!pTexture) goto cleanup;
1195 /* There are 8 texture stages. We should be able to access all of them */
1196 for(i = 0; i < 8; i++) {
1197 hr = IDirect3DDevice8_SetTexture(pDevice, i, (IDirect3DBaseTexture8 *) pTexture);
1198 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i, hr);
1199 hr = IDirect3DDevice8_SetTexture(pDevice, i, NULL);
1200 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i, hr);
1201 hr = IDirect3DDevice8_SetTextureStageState(pDevice, i, D3DTSS_COLOROP, D3DTOP_ADD);
1202 ok(hr == D3D_OK, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %#08x\n", i, hr);
1205 /* Investigations show that accessing higher textures stage states does not return an error either. Writing
1206 * to too high texture stages(approximately texture 40) causes memory corruption in windows, so there is no
1207 * bounds checking but how do I test that?
1210 cleanup:
1211 if(pTexture) IDirect3DTexture8_Release(pTexture);
1212 if (pDevice)
1214 UINT refcount = IDirect3DDevice8_Release(pDevice);
1215 ok(!refcount, "Device has %u references left.\n", refcount);
1217 if (pD3d) IDirect3D8_Release(pD3d);
1218 if(hwnd) DestroyWindow(hwnd);
1221 static void test_lights(void)
1223 D3DPRESENT_PARAMETERS d3dpp;
1224 IDirect3DDevice8 *device = NULL;
1225 IDirect3D8 *d3d8;
1226 HWND hwnd;
1227 HRESULT hr;
1228 unsigned int i;
1229 BOOL enabled;
1230 D3DCAPS8 caps;
1231 D3DDISPLAYMODE d3ddm;
1233 d3d8 = pDirect3DCreate8( D3D_SDK_VERSION );
1234 ok(d3d8 != NULL, "Failed to create IDirect3D8 object\n");
1235 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1236 ok(hwnd != NULL, "Failed to create window\n");
1237 if (!d3d8 || !hwnd) goto cleanup;
1239 IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &d3ddm );
1240 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1241 d3dpp.Windowed = TRUE;
1242 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1243 d3dpp.BackBufferWidth = 800;
1244 d3dpp.BackBufferHeight = 600;
1245 d3dpp.BackBufferFormat = d3ddm.Format;
1246 d3dpp.EnableAutoDepthStencil = TRUE;
1247 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
1249 hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1250 D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &d3dpp, &device );
1251 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE || hr == D3DERR_INVALIDCALL,
1252 "IDirect3D8_CreateDevice failed with %08x\n", hr);
1253 if(!device)
1255 skip("Failed to create a d3d device\n");
1256 goto cleanup;
1259 memset(&caps, 0, sizeof(caps));
1260 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
1261 ok(hr == D3D_OK, "IDirect3DDevice8_GetDeviceCaps failed with %08x\n", hr);
1263 for(i = 1; i <= caps.MaxActiveLights; i++) {
1264 hr = IDirect3DDevice8_LightEnable(device, i, TRUE);
1265 ok(hr == D3D_OK, "Enabling light %u failed with %08x\n", i, hr);
1266 hr = IDirect3DDevice8_GetLightEnable(device, i, &enabled);
1267 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL),
1268 "GetLightEnable on light %u failed with %08x\n", i, hr);
1269 ok(enabled, "Light %d is %s\n", i, enabled ? "enabled" : "disabled");
1272 /* TODO: Test the rendering results in this situation */
1273 hr = IDirect3DDevice8_LightEnable(device, i + 1, TRUE);
1274 ok(hr == D3D_OK ||
1275 broken(hr == D3DERR_INVALIDCALL), /* Some Win9x and WinME */
1276 "Enabling one light more than supported returned %08x\n", hr);
1277 hr = IDirect3DDevice8_GetLightEnable(device, i + 1, &enabled);
1278 ok(hr == D3D_OK ||
1279 broken(hr == D3DERR_INVALIDCALL), /* Some Win9x and WinME */
1280 "GetLightEnable on light %u failed with %08x\n", i + 1, hr);
1281 ok(enabled, "Light %d is %s\n", i + 1, enabled ? "enabled" : "disabled");
1282 hr = IDirect3DDevice8_LightEnable(device, i + 1, FALSE);
1283 ok(hr == D3D_OK, "Disabling the additional returned %08x\n", hr);
1285 for(i = 1; i <= caps.MaxActiveLights; i++) {
1286 hr = IDirect3DDevice8_LightEnable(device, i, FALSE);
1287 ok(hr == D3D_OK, "Disabling light %u failed with %08x\n", i, hr);
1290 cleanup:
1291 if (device)
1293 UINT refcount = IDirect3DDevice8_Release(device);
1294 ok(!refcount, "Device has %u references left.\n", refcount);
1296 if (d3d8) IDirect3D8_Release(d3d8);
1299 static void test_render_zero_triangles(void)
1301 D3DPRESENT_PARAMETERS d3dpp;
1302 IDirect3DDevice8 *device = NULL;
1303 IDirect3D8 *d3d8;
1304 HWND hwnd;
1305 HRESULT hr;
1306 D3DDISPLAYMODE d3ddm;
1308 struct nvertex
1310 float x, y, z;
1311 float nx, ny, nz;
1312 DWORD diffuse;
1313 } quad[] =
1315 { 0.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
1316 { 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
1317 { 1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
1318 { 1.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
1321 d3d8 = pDirect3DCreate8( D3D_SDK_VERSION );
1322 ok(d3d8 != NULL, "Failed to create IDirect3D8 object\n");
1323 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1324 ok(hwnd != NULL, "Failed to create window\n");
1325 if (!d3d8 || !hwnd) goto cleanup;
1327 IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &d3ddm );
1328 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1329 d3dpp.Windowed = TRUE;
1330 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1331 d3dpp.BackBufferWidth = 800;
1332 d3dpp.BackBufferHeight = 600;
1333 d3dpp.BackBufferFormat = d3ddm.Format;
1334 d3dpp.EnableAutoDepthStencil = TRUE;
1335 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
1337 hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1338 D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &d3dpp, &device );
1339 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE || hr == D3DERR_INVALIDCALL,
1340 "IDirect3D8_CreateDevice failed with %08x\n", hr);
1341 if(!device)
1343 skip("Failed to create a d3d device\n");
1344 goto cleanup;
1347 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
1348 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1350 hr = IDirect3DDevice8_BeginScene(device);
1351 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
1352 if(hr == D3D_OK)
1354 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 0 /* NumVerts */,
1355 0 /*PrimCount */, NULL, D3DFMT_INDEX16, quad, sizeof(quad[0]));
1356 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr);
1358 IDirect3DDevice8_EndScene(device);
1359 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
1362 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1364 cleanup:
1365 if (device)
1367 UINT refcount = IDirect3DDevice8_Release(device);
1368 ok(!refcount, "Device has %u references left.\n", refcount);
1370 if (d3d8) IDirect3D8_Release(d3d8);
1373 static void test_depth_stencil_reset(void)
1375 D3DPRESENT_PARAMETERS present_parameters;
1376 D3DDISPLAYMODE display_mode;
1377 IDirect3DSurface8 *surface;
1378 IDirect3DDevice8 *device = NULL;
1379 IDirect3D8 *d3d8;
1380 UINT refcount;
1381 HRESULT hr;
1382 HWND hwnd;
1384 d3d8 = pDirect3DCreate8(D3D_SDK_VERSION);
1385 ok(d3d8 != NULL, "Failed to create IDirect3D8 object\n");
1386 hwnd = CreateWindow("static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL);
1387 ok(hwnd != NULL, "Failed to create window\n");
1388 if (!d3d8 || !hwnd) goto cleanup;
1390 IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &display_mode);
1391 memset(&present_parameters, 0, sizeof(present_parameters));
1392 present_parameters.Windowed = TRUE;
1393 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
1394 present_parameters.BackBufferFormat = display_mode.Format;
1395 present_parameters.EnableAutoDepthStencil = TRUE;
1396 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
1398 hr = IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
1399 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
1400 if(FAILED(hr))
1402 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr);
1403 goto cleanup;
1406 hr = IDirect3DDevice8_TestCooperativeLevel(device);
1407 ok(SUCCEEDED(hr), "TestCooperativeLevel failed with %#x\n", hr);
1409 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, NULL);
1410 ok(hr == D3D_OK, "SetRenderTarget failed with 0x%08x\n", hr);
1412 hr = IDirect3DDevice8_GetRenderTarget(device, &surface);
1413 ok(hr == D3D_OK, "GetRenderTarget failed with 0x%08x\n", hr);
1414 ok(surface != NULL, "Render target should not be NULL\n");
1415 if (surface) IDirect3DSurface8_Release(surface);
1417 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
1418 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr);
1419 ok(surface == NULL, "Depth stencil should be NULL\n");
1421 present_parameters.EnableAutoDepthStencil = TRUE;
1422 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
1423 hr = IDirect3DDevice8_Reset(device, &present_parameters);
1424 ok(hr == D3D_OK, "Reset failed with 0x%08x\n", hr);
1426 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
1427 ok(hr == D3D_OK, "GetDepthStencilSurface failed with 0x%08x\n", hr);
1428 ok(surface != NULL, "Depth stencil should not be NULL\n");
1429 if (surface) IDirect3DSurface8_Release(surface);
1431 present_parameters.EnableAutoDepthStencil = FALSE;
1432 hr = IDirect3DDevice8_Reset(device, &present_parameters);
1433 ok(hr == D3D_OK, "Reset failed with 0x%08x\n", hr);
1435 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
1436 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr);
1437 ok(surface == NULL, "Depth stencil should be NULL\n");
1439 refcount = IDirect3DDevice8_Release(device);
1440 ok(!refcount, "Device has %u references left.\n", refcount);
1441 device = NULL;
1443 IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &display_mode );
1445 ZeroMemory( &present_parameters, sizeof(present_parameters) );
1446 present_parameters.Windowed = TRUE;
1447 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
1448 present_parameters.BackBufferFormat = display_mode.Format;
1449 present_parameters.EnableAutoDepthStencil = FALSE;
1450 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
1452 hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
1453 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device );
1455 if(FAILED(hr))
1457 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr);
1458 goto cleanup;
1461 hr = IDirect3DDevice8_TestCooperativeLevel(device);
1462 ok(hr == D3D_OK, "IDirect3DDevice8_TestCooperativeLevel after creation returned %#x\n", hr);
1464 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
1465 present_parameters.Windowed = TRUE;
1466 present_parameters.BackBufferWidth = 400;
1467 present_parameters.BackBufferHeight = 300;
1468 present_parameters.EnableAutoDepthStencil = TRUE;
1469 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
1471 hr = IDirect3DDevice8_Reset(device, &present_parameters);
1472 ok(hr == D3D_OK, "IDirect3DDevice8_Reset failed with 0x%08x\n", hr);
1474 if (FAILED(hr)) goto cleanup;
1476 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
1477 ok(hr == D3D_OK, "GetDepthStencilSurface failed with 0x%08x\n", hr);
1478 ok(surface != NULL, "Depth stencil should not be NULL\n");
1479 if (surface) IDirect3DSurface8_Release(surface);
1481 cleanup:
1482 if (device)
1484 refcount = IDirect3DDevice8_Release(device);
1485 ok(!refcount, "Device has %u references left.\n", refcount);
1487 if (d3d8) IDirect3D8_Release(d3d8);
1490 static HWND filter_messages;
1491 struct
1493 HWND window;
1494 UINT message;
1495 } expect_message;
1497 struct wndproc_thread_param
1499 HWND dummy_window;
1500 HANDLE window_created;
1501 HANDLE test_finished;
1504 static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
1506 if (filter_messages && filter_messages == hwnd)
1508 ok(message == WM_DISPLAYCHANGE, "Received unexpected message %#x for window %p.\n", message, hwnd);
1511 if (expect_message.window == hwnd && expect_message.message == message) expect_message.message = 0;
1513 return DefWindowProcA(hwnd, message, wparam, lparam);
1516 static DWORD WINAPI wndproc_thread(void *param)
1518 struct wndproc_thread_param *p = param;
1519 DWORD res;
1520 BOOL ret;
1522 p->dummy_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
1523 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, 640, 480, 0, 0, 0, 0);
1525 ret = SetEvent(p->window_created);
1526 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
1528 res = WaitForSingleObject(p->test_finished, INFINITE);
1529 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
1531 DestroyWindow(p->dummy_window);
1533 return 0;
1536 static void test_wndproc(void)
1538 struct wndproc_thread_param thread_params;
1539 HWND device_window, focus_window, tmp;
1540 IDirect3DDevice8 *device;
1541 WNDCLASSA wc = {0};
1542 IDirect3D8 *d3d8;
1543 HANDLE thread;
1544 LONG_PTR proc;
1545 ULONG ref;
1546 DWORD res, tid;
1548 if (!(d3d8 = pDirect3DCreate8(D3D_SDK_VERSION)))
1550 skip("Failed to create IDirect3D8 object, skipping tests.\n");
1551 return;
1554 wc.lpfnWndProc = test_proc;
1555 wc.lpszClassName = "d3d8_test_wndproc_wc";
1556 ok(RegisterClassA(&wc), "Failed to register window class.\n");
1558 thread_params.window_created = CreateEvent(NULL, FALSE, FALSE, NULL);
1559 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
1560 thread_params.test_finished = CreateEvent(NULL, FALSE, FALSE, NULL);
1561 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
1563 focus_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
1564 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
1565 device_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
1566 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
1567 thread = CreateThread(NULL, 0, wndproc_thread, &thread_params, 0, &tid);
1568 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
1570 res = WaitForSingleObject(thread_params.window_created, INFINITE);
1571 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
1573 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
1574 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1575 (LONG_PTR)test_proc, proc);
1576 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1577 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1578 (LONG_PTR)test_proc, proc);
1580 trace("device_window %p, focus_window %p, dummy_window %p.\n",
1581 device_window, focus_window, thread_params.dummy_window);
1583 tmp = GetFocus();
1584 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
1585 tmp = GetForegroundWindow();
1586 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
1587 thread_params.dummy_window, tmp);
1589 expect_message.window = focus_window;
1590 expect_message.message = WM_SETFOCUS;
1592 device = create_device(d3d8, device_window, focus_window, FALSE);
1593 if (!device)
1595 skip("Failed to create a D3D device, skipping tests.\n");
1596 goto done;
1599 ok(!expect_message.message, "Expected message %#x for window %p, but didn't receive it.\n",
1600 expect_message.message, expect_message.window);
1601 tmp = GetFocus();
1602 todo_wine ok(tmp == focus_window, "Expected focus %p, got %p.\n", focus_window, tmp);
1603 tmp = GetForegroundWindow();
1604 todo_wine ok(tmp == focus_window, "Expected foreground window %p, got %p.\n", focus_window, tmp);
1605 SetForegroundWindow(focus_window);
1607 filter_messages = focus_window;
1609 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
1610 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1611 (LONG_PTR)test_proc, proc);
1613 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1614 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
1615 (LONG_PTR)test_proc, proc);
1617 ref = IDirect3DDevice8_Release(device);
1618 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
1620 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1621 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1622 (LONG_PTR)test_proc, proc);
1624 device = create_device(d3d8, focus_window, focus_window, FALSE);
1625 if (!device)
1627 skip("Failed to create a D3D device, skipping tests.\n");
1628 goto done;
1631 ref = IDirect3DDevice8_Release(device);
1632 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
1634 device = create_device(d3d8, device_window, focus_window, FALSE);
1635 if (!device)
1637 skip("Failed to create a D3D device, skipping tests.\n");
1638 goto done;
1641 proc = SetWindowLongPtrA(focus_window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
1642 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
1643 (LONG_PTR)test_proc, proc);
1645 ref = IDirect3DDevice8_Release(device);
1646 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
1648 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1649 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
1650 (LONG_PTR)DefWindowProcA, proc);
1652 done:
1653 filter_messages = NULL;
1654 IDirect3D8_Release(d3d8);
1656 SetEvent(thread_params.test_finished);
1657 WaitForSingleObject(thread, INFINITE);
1658 CloseHandle(thread_params.test_finished);
1659 CloseHandle(thread_params.window_created);
1660 CloseHandle(thread);
1662 DestroyWindow(device_window);
1663 DestroyWindow(focus_window);
1664 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL));
1667 static void test_wndproc_windowed(void)
1669 struct wndproc_thread_param thread_params;
1670 HWND device_window, focus_window, tmp;
1671 IDirect3DDevice8 *device;
1672 WNDCLASSA wc = {0};
1673 IDirect3D8 *d3d8;
1674 HANDLE thread;
1675 LONG_PTR proc;
1676 ULONG ref;
1677 DWORD res, tid;
1679 if (!(d3d8 = pDirect3DCreate8(D3D_SDK_VERSION)))
1681 skip("Failed to create IDirect3D8 object, skipping tests.\n");
1682 return;
1685 wc.lpfnWndProc = test_proc;
1686 wc.lpszClassName = "d3d8_test_wndproc_wc";
1687 ok(RegisterClassA(&wc), "Failed to register window class.\n");
1689 thread_params.window_created = CreateEvent(NULL, FALSE, FALSE, NULL);
1690 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
1691 thread_params.test_finished = CreateEvent(NULL, FALSE, FALSE, NULL);
1692 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
1694 focus_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
1695 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, 640, 480, 0, 0, 0, 0);
1696 device_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
1697 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, 640, 480, 0, 0, 0, 0);
1698 thread = CreateThread(NULL, 0, wndproc_thread, &thread_params, 0, &tid);
1699 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
1701 res = WaitForSingleObject(thread_params.window_created, INFINITE);
1702 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
1704 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
1705 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1706 (LONG_PTR)test_proc, proc);
1707 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
1708 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1709 (LONG_PTR)test_proc, proc);
1711 trace("device_window %p, focus_window %p, dummy_window %p.\n",
1712 device_window, focus_window, thread_params.dummy_window);
1714 tmp = GetFocus();
1715 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
1716 tmp = GetForegroundWindow();
1717 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
1718 thread_params.dummy_window, tmp);
1720 filter_messages = focus_window;
1722 device = create_device(d3d8, device_window, focus_window, TRUE);
1723 if (!device)
1725 skip("Failed to create a D3D device, skipping tests.\n");
1726 goto done;
1729 tmp = GetFocus();
1730 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
1731 tmp = GetForegroundWindow();
1732 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
1733 thread_params.dummy_window, tmp);
1735 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
1736 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1737 (LONG_PTR)test_proc, proc);
1739 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
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 filter_messages = device_window;
1748 device = create_device(d3d8, focus_window, focus_window, TRUE);
1749 if (!device)
1751 skip("Failed to create a D3D device, skipping tests.\n");
1752 goto done;
1755 ref = IDirect3DDevice8_Release(device);
1756 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
1758 device = create_device(d3d8, device_window, focus_window, TRUE);
1759 if (!device)
1761 skip("Failed to create a D3D device, skipping tests.\n");
1762 goto done;
1765 ref = IDirect3DDevice8_Release(device);
1766 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
1768 done:
1769 filter_messages = NULL;
1770 IDirect3D8_Release(d3d8);
1772 SetEvent(thread_params.test_finished);
1773 WaitForSingleObject(thread, INFINITE);
1774 CloseHandle(thread_params.test_finished);
1775 CloseHandle(thread_params.window_created);
1776 CloseHandle(thread);
1778 DestroyWindow(device_window);
1779 DestroyWindow(focus_window);
1780 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL));
1783 START_TEST(device)
1785 HMODULE d3d8_handle = LoadLibraryA( "d3d8.dll" );
1786 if (!d3d8_handle)
1788 skip("Could not load d3d8.dll\n");
1789 return;
1792 pDirect3DCreate8 = (void *)GetProcAddress( d3d8_handle, "Direct3DCreate8" );
1793 ok(pDirect3DCreate8 != NULL, "Failed to get address of Direct3DCreate8\n");
1794 if (pDirect3DCreate8)
1796 IDirect3D8 *d3d8;
1797 d3d8 = pDirect3DCreate8( D3D_SDK_VERSION );
1798 if(!d3d8)
1800 skip("could not create D3D8\n");
1801 return;
1803 IDirect3D8_Release(d3d8);
1805 test_display_modes();
1806 test_shader_versions();
1807 test_swapchain();
1808 test_refcount();
1809 test_mipmap_levels();
1810 test_cursor();
1811 test_states();
1812 test_scene();
1813 test_shader();
1814 test_limits();
1815 test_lights();
1816 test_render_zero_triangles();
1817 test_depth_stencil_reset();
1818 test_wndproc();
1819 test_wndproc_windowed();