d3d8: Back buffer is identical to the render target, test it only once.
[wine.git] / dlls / d3d8 / tests / device.c
blob9be338164583b32196a038c65505d8f3bb247f2f
1 /*
2 * Copyright (C) 2006 Vitaliy Margolen
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
20 #include <d3d8.h>
21 #include <dxerr8.h>
22 #include "wine/test.h"
24 static IDirect3D8 *(WINAPI *pDirect3DCreate8)(UINT);
26 static int get_refcount(IUnknown *object)
28 IUnknown_AddRef( object );
29 return IUnknown_Release( object );
32 #define CHECK_CALL(r,c,d,rc) \
33 if (SUCCEEDED(r)) {\
34 int tmp1 = get_refcount( (IUnknown *)d ); \
35 int rc_new = rc; \
36 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
37 } else {\
38 trace("%s failed: %s\n", c, DXGetErrorString8(r)); \
41 #define CHECK_RELEASE(obj,d,rc) \
42 if (obj) { \
43 int tmp1, rc_new = rc; \
44 IUnknown_Release( obj ); \
45 tmp1 = get_refcount( (IUnknown *)d ); \
46 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
49 #define CHECK_REFCOUNT(obj,rc) \
50 { \
51 int rc_new = rc; \
52 int count = get_refcount( (IUnknown *)obj ); \
53 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
56 #define CHECK_RELEASE_REFCOUNT(obj,rc) \
57 { \
58 int rc_new = rc; \
59 int count = IUnknown_Release( (IUnknown *)obj ); \
60 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
63 #define CHECK_SURFACE_CONTAINER(obj,iid,expected) \
64 { \
65 void *container_ptr = (void *)0x1337c0d3; \
66 hr = IDirect3DSurface8_GetContainer(obj, &iid, &container_ptr); \
67 ok(SUCCEEDED(hr) && container_ptr == expected, "GetContainer returned: hr %#x, container_ptr %p. " \
68 "Expected hr %#x, container_ptr %p\n", hr, container_ptr, S_OK, expected); \
69 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr); \
72 static void check_mipmap_levels(
73 IDirect3DDevice8* device,
74 int width, int height, int count)
77 IDirect3DBaseTexture8* texture = NULL;
78 HRESULT hr = IDirect3DDevice8_CreateTexture( device, width, height, 0, 0,
79 D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, (IDirect3DTexture8**) &texture );
81 if (SUCCEEDED(hr)) {
82 DWORD levels = IDirect3DBaseTexture8_GetLevelCount(texture);
83 ok(levels == count, "Invalid level count. Expected %d got %u\n", count, levels);
84 } else
85 trace("CreateTexture failed: %s\n", DXGetErrorString8(hr));
87 if (texture) IUnknown_Release( texture );
90 static void test_mipmap_levels(void)
93 HRESULT hr;
94 HWND hwnd = NULL;
96 IDirect3D8 *pD3d = NULL;
97 IDirect3DDevice8 *pDevice = NULL;
98 D3DPRESENT_PARAMETERS d3dpp;
99 D3DDISPLAYMODE d3ddm;
101 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
102 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
103 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
104 ok(hwnd != NULL, "Failed to create window\n");
105 if (!pD3d || !hwnd) goto cleanup;
107 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
108 ZeroMemory( &d3dpp, sizeof(d3dpp) );
109 d3dpp.Windowed = TRUE;
110 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
111 d3dpp.BackBufferFormat = d3ddm.Format;
113 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
114 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
115 ok(SUCCEEDED(hr), "Failed to create IDirect3D8Device (%s)\n", DXGetErrorString8(hr));
116 if (FAILED(hr)) goto cleanup;
118 check_mipmap_levels(pDevice, 32, 32, 6);
119 check_mipmap_levels(pDevice, 256, 1, 9);
120 check_mipmap_levels(pDevice, 1, 256, 9);
121 check_mipmap_levels(pDevice, 1, 1, 1);
123 cleanup:
124 if (pD3d) IUnknown_Release( pD3d );
125 if (pDevice) IUnknown_Release( pDevice );
126 DestroyWindow( hwnd );
129 static void test_swapchain(void)
131 HRESULT hr;
132 HWND hwnd = NULL;
133 IDirect3D8 *pD3d = NULL;
134 IDirect3DDevice8 *pDevice = NULL;
135 IDirect3DSwapChain8 *swapchain1 = NULL;
136 IDirect3DSwapChain8 *swapchain2 = NULL;
137 IDirect3DSwapChain8 *swapchain3 = NULL;
138 IDirect3DSurface8 *backbuffer = NULL;
139 D3DPRESENT_PARAMETERS d3dpp;
140 D3DDISPLAYMODE d3ddm;
142 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
143 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
144 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
145 ok(hwnd != NULL, "Failed to create window\n");
146 if (!pD3d || !hwnd) goto cleanup;
148 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
149 ZeroMemory( &d3dpp, sizeof(d3dpp) );
150 d3dpp.Windowed = TRUE;
151 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
152 d3dpp.BackBufferFormat = d3ddm.Format;
153 d3dpp.BackBufferCount = 0;
155 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
156 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
157 ok(SUCCEEDED(hr), "Failed to create IDirect3D8Device (%s)\n", DXGetErrorString8(hr));
158 if (FAILED(hr)) goto cleanup;
160 /* Check if the back buffer count was modified */
161 ok(d3dpp.BackBufferCount == 1, "The back buffer count in the presentparams struct is %d\n", d3dpp.BackBufferCount);
163 /* Create a bunch of swapchains */
164 d3dpp.BackBufferCount = 0;
165 hr = IDirect3DDevice8_CreateAdditionalSwapChain(pDevice, &d3dpp, &swapchain1);
166 ok(SUCCEEDED(hr), "Failed to create a swapchain (%s)\n", DXGetErrorString8(hr));
167 ok(d3dpp.BackBufferCount == 1, "The back buffer count in the presentparams struct is %d\n", d3dpp.BackBufferCount);
169 d3dpp.BackBufferCount = 1;
170 hr = IDirect3DDevice8_CreateAdditionalSwapChain(pDevice, &d3dpp, &swapchain2);
171 ok(SUCCEEDED(hr), "Failed to create a swapchain (%s)\n", DXGetErrorString8(hr));
173 d3dpp.BackBufferCount = 2;
174 hr = IDirect3DDevice8_CreateAdditionalSwapChain(pDevice, &d3dpp, &swapchain3);
175 ok(SUCCEEDED(hr), "Failed to create a swapchain (%s)\n", DXGetErrorString8(hr));
176 if(SUCCEEDED(hr)) {
177 /* Swapchain 3, created with backbuffercount 2 */
178 backbuffer = (void *) 0xdeadbeef;
179 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 0, 0, &backbuffer);
180 ok(SUCCEEDED(hr), "Failed to get the 1st back buffer (%s)\n", DXGetErrorString8(hr));
181 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
182 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
184 backbuffer = (void *) 0xdeadbeef;
185 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 1, 0, &backbuffer);
186 ok(SUCCEEDED(hr), "Failed to get the 2nd back buffer (%s)\n", DXGetErrorString8(hr));
187 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
188 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
190 backbuffer = (void *) 0xdeadbeef;
191 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 2, 0, &backbuffer);
192 ok(hr == D3DERR_INVALIDCALL, "GetBackBuffer returned %s\n", DXGetErrorString8(hr));
193 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
194 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
196 backbuffer = (void *) 0xdeadbeef;
197 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 3, 0, &backbuffer);
198 ok(FAILED(hr), "Failed to get the back buffer (%s)\n", DXGetErrorString8(hr));
199 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
200 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
203 /* Check the back buffers of the swapchains */
204 /* Swapchain 1, created with backbuffercount 0 */
205 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain1, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
206 ok(SUCCEEDED(hr), "Failed to get the back buffer (%s)\n", DXGetErrorString8(hr));
207 ok(backbuffer != NULL, "The back buffer is NULL (%s)\n", DXGetErrorString8(hr));
208 if(backbuffer) IDirect3DSurface8_Release(backbuffer);
210 backbuffer = (void *) 0xdeadbeef;
211 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain1, 1, 0, &backbuffer);
212 ok(FAILED(hr), "Failed to get the back buffer (%s)\n", DXGetErrorString8(hr));
213 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
214 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
216 /* Swapchain 2 - created with backbuffercount 1 */
217 backbuffer = (void *) 0xdeadbeef;
218 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 0, 0, &backbuffer);
219 ok(SUCCEEDED(hr), "Failed to get the back buffer (%s)\n", DXGetErrorString8(hr));
220 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
221 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
223 backbuffer = (void *) 0xdeadbeef;
224 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 1, 0, &backbuffer);
225 ok(hr == D3DERR_INVALIDCALL, "GetBackBuffer returned %s\n", DXGetErrorString8(hr));
226 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
227 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
229 backbuffer = (void *) 0xdeadbeef;
230 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 2, 0, &backbuffer);
231 ok(FAILED(hr), "Failed to get the back buffer (%s)\n", DXGetErrorString8(hr));
232 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
233 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
235 cleanup:
236 if(swapchain1) IDirect3DSwapChain8_Release(swapchain1);
237 if(swapchain2) IDirect3DSwapChain8_Release(swapchain2);
238 if(swapchain3) IDirect3DSwapChain8_Release(swapchain3);
239 if(pDevice) IDirect3DDevice8_Release(pDevice);
240 if(pD3d) IDirect3DDevice8_Release(pD3d);
241 DestroyWindow( hwnd );
244 static void test_refcount(void)
246 HRESULT hr;
247 HWND hwnd = NULL;
248 IDirect3D8 *pD3d = NULL;
249 IDirect3DDevice8 *pDevice = NULL;
250 IDirect3DVertexBuffer8 *pVertexBuffer = NULL;
251 IDirect3DIndexBuffer8 *pIndexBuffer = NULL;
252 DWORD dVertexShader = -1;
253 DWORD dPixelShader = -1;
254 IDirect3DCubeTexture8 *pCubeTexture = NULL;
255 IDirect3DTexture8 *pTexture = NULL;
256 IDirect3DVolumeTexture8 *pVolumeTexture = NULL;
257 IDirect3DSurface8 *pStencilSurface = NULL;
258 IDirect3DSurface8 *pImageSurface = NULL;
259 IDirect3DSurface8 *pRenderTarget = NULL;
260 IDirect3DSurface8 *pTextureLevel = NULL;
261 IDirect3DSurface8 *pBackBuffer = NULL;
262 DWORD dStateBlock = -1;
263 IDirect3DSwapChain8 *pSwapChain = NULL;
265 D3DPRESENT_PARAMETERS d3dpp;
266 D3DDISPLAYMODE d3ddm;
267 int refcount = 0, tmp;
269 DWORD decl[] =
271 D3DVSD_STREAM(0),
272 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
273 D3DVSD_REG(D3DVSDE_DIFFUSE, D3DVSDT_D3DCOLOR), /* D3DVSDE_DIFFUSE, Register v5 */
274 D3DVSD_END()
276 static DWORD simple_vs[] = {0xFFFE0101, /* vs_1_1 */
277 0x00000009, 0xC0010000, 0x90E40000, 0xA0E40000, /* dp4 oPos.x, v0, c0 */
278 0x00000009, 0xC0020000, 0x90E40000, 0xA0E40001, /* dp4 oPos.y, v0, c1 */
279 0x00000009, 0xC0040000, 0x90E40000, 0xA0E40002, /* dp4 oPos.z, v0, c2 */
280 0x00000009, 0xC0080000, 0x90E40000, 0xA0E40003, /* dp4 oPos.w, v0, c3 */
281 0x0000FFFF}; /* END */
282 static DWORD simple_ps[] = {0xFFFF0101, /* ps_1_1 */
283 0x00000051, 0xA00F0001, 0x3F800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
284 0x00000042, 0xB00F0000, /* tex t0 */
285 0x00000008, 0x800F0000, 0xA0E40001, 0xA0E40000, /* dp3 r0, c1, c0 */
286 0x00000005, 0x800F0000, 0x90E40000, 0x80E40000, /* mul r0, v0, r0 */
287 0x00000005, 0x800F0000, 0xB0E40000, 0x80E40000, /* mul r0, t0, r0 */
288 0x0000FFFF}; /* END */
291 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
292 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
293 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
294 ok(hwnd != NULL, "Failed to create window\n");
295 if (!pD3d || !hwnd) goto cleanup;
297 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
298 ZeroMemory( &d3dpp, sizeof(d3dpp) );
299 d3dpp.Windowed = TRUE;
300 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
301 d3dpp.BackBufferFormat = d3ddm.Format;
302 d3dpp.EnableAutoDepthStencil = TRUE;
303 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
305 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
306 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
307 ok(SUCCEEDED(hr), "Failed to create IDirect3D8Device (%s)\n", DXGetErrorString8(hr));
308 if (FAILED(hr)) goto cleanup;
310 refcount = get_refcount( (IUnknown *)pDevice );
311 ok(refcount == 1, "Invalid device RefCount %d\n", refcount);
314 * Check refcount of implicit surfaces. Findings:
315 * - the container is the device
316 * - they hold a refernce to the device
317 * - they are created with a refcount of 0 (Get/Release returns orignial refcount)
319 hr = IDirect3DDevice8_GetRenderTarget(pDevice, &pRenderTarget);
320 todo_wine CHECK_CALL( hr, "GetRenderTarget", pDevice, ++refcount);
321 if(pRenderTarget)
323 todo_wine CHECK_SURFACE_CONTAINER( pRenderTarget, IID_IDirect3DDevice8, pDevice);
324 todo_wine CHECK_REFCOUNT( pRenderTarget, 1);
325 hr = IDirect3DDevice8_GetRenderTarget(pDevice, &pRenderTarget);
326 todo_wine CHECK_CALL( hr, "GetRenderTarget", pDevice, refcount);
327 todo_wine CHECK_REFCOUNT( pRenderTarget, 2);
328 todo_wine CHECK_RELEASE_REFCOUNT( pRenderTarget, 1);
329 todo_wine CHECK_RELEASE_REFCOUNT( pRenderTarget, 0);
331 CHECK_REFCOUNT( pDevice, --refcount);
333 /* Render target and back buffer are identical. */
334 hr = IDirect3DDevice8_GetBackBuffer(pDevice, 0, 0, &pBackBuffer);
335 todo_wine CHECK_CALL( hr, "GetBackBuffer", pDevice, ++refcount);
336 if(pBackBuffer)
338 todo_wine CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
339 ok(pRenderTarget == pBackBuffer, "RenderTarget=%p and BackBuffer=%p should be the same.\n",
340 pRenderTarget, pBackBuffer);
341 pBackBuffer = NULL;
343 CHECK_REFCOUNT( pDevice, --refcount);
344 pRenderTarget = NULL;
346 hr = IDirect3DDevice8_GetDepthStencilSurface(pDevice, &pStencilSurface);
347 todo_wine CHECK_CALL( hr, "GetDepthStencilSurface", pDevice, ++refcount);
348 if(pStencilSurface)
350 CHECK_SURFACE_CONTAINER( pStencilSurface, IID_IDirect3DDevice8, pDevice);
351 todo_wine CHECK_REFCOUNT( pStencilSurface, 1);
352 todo_wine CHECK_RELEASE_REFCOUNT( pStencilSurface, 0);
353 pStencilSurface = NULL;
355 CHECK_REFCOUNT( pDevice, --refcount);
357 /* Buffers */
358 hr = IDirect3DDevice8_CreateIndexBuffer( pDevice, 16, 0, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &pIndexBuffer );
359 CHECK_CALL( hr, "CreateIndexBuffer", pDevice, ++refcount );
360 if(pIndexBuffer)
362 tmp = get_refcount( (IUnknown *)pIndexBuffer );
364 hr = IDirect3DDevice8_SetIndices(pDevice, pIndexBuffer, 0);
365 CHECK_CALL( hr, "SetIndices", pIndexBuffer, tmp);
366 hr = IDirect3DDevice8_SetIndices(pDevice, NULL, 0);
367 CHECK_CALL( hr, "SetIndices", pIndexBuffer, tmp);
370 hr = IDirect3DDevice8_CreateVertexBuffer( pDevice, 16, 0, D3DFVF_XYZ, D3DPOOL_DEFAULT, &pVertexBuffer );
371 CHECK_CALL( hr, "CreateVertexBuffer", pDevice, ++refcount );
372 if(pVertexBuffer)
374 tmp = get_refcount( (IUnknown *)pVertexBuffer );
376 hr = IDirect3DDevice8_SetStreamSource(pDevice, 0, pVertexBuffer, 3 * sizeof(float));
377 CHECK_CALL( hr, "SetStreamSource", pVertexBuffer, tmp);
378 hr = IDirect3DDevice8_SetStreamSource(pDevice, 0, NULL, 0);
379 CHECK_CALL( hr, "SetStreamSource", pVertexBuffer, tmp);
381 /* Shaders */
382 hr = IDirect3DDevice8_CreateVertexShader( pDevice, decl, simple_vs, &dVertexShader, 0 );
383 CHECK_CALL( hr, "CreateVertexShader", pDevice, refcount );
384 hr = IDirect3DDevice8_CreatePixelShader( pDevice, simple_ps, &dPixelShader );
385 CHECK_CALL( hr, "CreatePixelShader", pDevice, refcount );
386 /* Textures */
387 hr = IDirect3DDevice8_CreateTexture( pDevice, 32, 32, 3, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pTexture );
388 CHECK_CALL( hr, "CreateTexture", pDevice, ++refcount );
389 if (pTexture)
391 tmp = get_refcount( (IUnknown *)pTexture );
393 /* SetTexture should not increase refcounts */
394 hr = IDirect3DDevice8_SetTexture(pDevice, 0, (IDirect3DBaseTexture8 *) pTexture);
395 CHECK_CALL( hr, "SetTexture", pTexture, tmp);
396 hr = IDirect3DDevice8_SetTexture(pDevice, 0, NULL);
397 CHECK_CALL( hr, "SetTexture", pTexture, tmp);
399 /* This should not increment device refcount */
400 hr = IDirect3DTexture8_GetSurfaceLevel( pTexture, 1, &pTextureLevel );
401 CHECK_CALL( hr, "GetSurfaceLevel", pDevice, refcount );
402 /* But should increment texture's refcount */
403 CHECK_CALL( hr, "GetSurfaceLevel", pTexture, tmp+1 );
405 hr = IDirect3DDevice8_CreateCubeTexture( pDevice, 32, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pCubeTexture );
406 CHECK_CALL( hr, "CreateCubeTexture", pDevice, ++refcount );
407 hr = IDirect3DDevice8_CreateVolumeTexture( pDevice, 32, 32, 2, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pVolumeTexture );
408 CHECK_CALL( hr, "CreateVolumeTexture", pDevice, ++refcount );
409 /* Surfaces */
410 hr = IDirect3DDevice8_CreateDepthStencilSurface( pDevice, 32, 32, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, &pStencilSurface );
411 CHECK_CALL( hr, "CreateDepthStencilSurface", pDevice, ++refcount );
412 hr = IDirect3DDevice8_CreateImageSurface( pDevice, 32, 32, D3DFMT_X8R8G8B8, &pImageSurface );
413 CHECK_CALL( hr, "CreateImageSurface", pDevice, ++refcount );
414 hr = IDirect3DDevice8_CreateRenderTarget( pDevice, 32, 32, D3DFMT_X8R8G8B8, D3DMULTISAMPLE_NONE, TRUE, &pRenderTarget );
415 CHECK_CALL( hr, "CreateRenderTarget", pDevice, ++refcount );
416 /* Misc */
417 hr = IDirect3DDevice8_CreateStateBlock( pDevice, D3DSBT_ALL, &dStateBlock );
418 CHECK_CALL( hr, "CreateStateBlock", pDevice, refcount );
419 hr = IDirect3DDevice8_CreateAdditionalSwapChain( pDevice, &d3dpp, &pSwapChain );
420 CHECK_CALL( hr, "CreateAdditionalSwapChain", pDevice, ++refcount );
421 if(pSwapChain)
423 /* check implicit back buffer */
424 hr = IDirect3DSwapChain8_GetBackBuffer(pSwapChain, 0, 0, &pBackBuffer);
425 todo_wine CHECK_CALL( hr, "GetBackBuffer", pDevice, ++refcount);
426 todo_wine CHECK_REFCOUNT( pSwapChain, 1);
427 if(pBackBuffer)
429 todo_wine CHECK_SURFACE_CONTAINER( pBackBuffer, IID_IDirect3DDevice8, pDevice);
430 todo_wine CHECK_REFCOUNT( pBackBuffer, 1);
431 todo_wine CHECK_RELEASE_REFCOUNT( pBackBuffer, 0);
432 pBackBuffer = NULL;
434 CHECK_REFCOUNT( pSwapChain, 1);
435 CHECK_REFCOUNT( pDevice, --refcount);
438 if(pVertexBuffer)
440 BYTE *data;
441 /* Vertex buffers can be locked multiple times */
442 hr = IDirect3DVertexBuffer8_Lock(pVertexBuffer, 0, 0, &data, 0);
443 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Lock failed with %08x\n", hr);
444 hr = IDirect3DVertexBuffer8_Lock(pVertexBuffer, 0, 0, &data, 0);
445 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Lock failed with %08x\n", hr);
446 hr = IDirect3DVertexBuffer8_Unlock(pVertexBuffer);
447 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Unlock failed with %08x\n", hr);
448 hr = IDirect3DVertexBuffer8_Unlock(pVertexBuffer);
449 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Unlock failed with %08x\n", hr);
452 cleanup:
453 CHECK_RELEASE(pDevice, pDevice, --refcount);
455 /* Buffers */
456 CHECK_RELEASE(pVertexBuffer, pDevice, --refcount);
457 CHECK_RELEASE(pIndexBuffer, pDevice, --refcount);
458 /* Shaders */
459 if (dVertexShader != -1) IDirect3DDevice8_DeleteVertexShader( pDevice, dVertexShader );
460 if (dPixelShader != -1) IDirect3DDevice8_DeletePixelShader( pDevice, dPixelShader );
461 /* Textures */
462 /* pTextureLevel is holding a reference to the pTexture */
463 CHECK_RELEASE(pTexture, pDevice, refcount);
464 CHECK_RELEASE(pTextureLevel, pDevice, --refcount);
465 CHECK_RELEASE(pCubeTexture, pDevice, --refcount);
466 CHECK_RELEASE(pVolumeTexture, pDevice, --refcount);
467 /* Surfaces */
468 CHECK_RELEASE(pStencilSurface, pDevice, --refcount);
469 CHECK_RELEASE(pImageSurface, pDevice, --refcount);
470 CHECK_RELEASE(pRenderTarget, pDevice, --refcount);
471 /* Misc */
472 if (dStateBlock != -1) IDirect3DDevice8_DeleteStateBlock( pDevice, dStateBlock );
473 /* This will destroy device - cannot check the refcount here */
474 if (pSwapChain) CHECK_RELEASE_REFCOUNT( pSwapChain, 0);
476 if (pD3d) CHECK_RELEASE_REFCOUNT( pD3d, 0);
478 DestroyWindow( hwnd );
481 static void test_cursor(void)
483 HRESULT hr;
484 HWND hwnd = NULL;
485 IDirect3D8 *pD3d = NULL;
486 IDirect3DDevice8 *pDevice = NULL;
487 D3DPRESENT_PARAMETERS d3dpp;
488 D3DDISPLAYMODE d3ddm;
489 CURSORINFO info;
490 IDirect3DSurface8 *cursor = NULL;
491 HCURSOR cur;
493 memset(&info, 0, sizeof(info));
494 info.cbSize = sizeof(info);
495 hr = GetCursorInfo(&info);
496 cur = info.hCursor;
498 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
499 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
500 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
501 ok(hwnd != NULL, "Failed to create window\n");
502 if (!pD3d || !hwnd) goto cleanup;
504 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
505 ZeroMemory( &d3dpp, sizeof(d3dpp) );
506 d3dpp.Windowed = TRUE;
507 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
508 d3dpp.BackBufferFormat = d3ddm.Format;
510 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
511 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
512 ok(SUCCEEDED(hr), "Failed to create IDirect3D8Device (%s)\n", DXGetErrorString8(hr));
513 if (FAILED(hr)) goto cleanup;
515 IDirect3DDevice8_CreateImageSurface(pDevice, 32, 32, D3DFMT_A8R8G8B8, &cursor);
516 ok(cursor != NULL, "IDirect3DDevice8_CreateOffscreenPlainSurface failed with %08x\n", hr);
518 /* Initially hidden */
519 hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
520 ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %08x\n", hr);
522 /* Not enabled without a surface*/
523 hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
524 ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %08x\n", hr);
526 /* Fails */
527 hr = IDirect3DDevice8_SetCursorProperties(pDevice, 0, 0, NULL);
528 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_SetCursorProperties returned %08x\n", hr);
530 hr = IDirect3DDevice8_SetCursorProperties(pDevice, 0, 0, cursor);
531 ok(hr == D3D_OK, "IDirect3DDevice8_SetCursorProperties returned %08x\n", hr);
533 IDirect3DSurface8_Release(cursor);
535 memset(&info, 0, sizeof(info));
536 info.cbSize = sizeof(info);
537 hr = GetCursorInfo(&info);
538 ok(hr != 0, "GetCursorInfo returned %08x\n", hr);
539 ok(info.flags & CURSOR_SHOWING, "The gdi cursor is hidden (%08x)\n", info.flags);
540 ok(info.hCursor == cur, "The cursor handle is %p\n", info.hCursor); /* unchanged */
542 /* Still hidden */
543 hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
544 ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %08x\n", hr);
546 /* Enabled now*/
547 hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
548 ok(hr == TRUE, "IDirect3DDevice8_ShowCursor returned %08x\n", hr);
550 /* GDI cursor unchanged */
551 memset(&info, 0, sizeof(info));
552 info.cbSize = sizeof(info);
553 hr = GetCursorInfo(&info);
554 ok(hr != 0, "GetCursorInfo returned %08x\n", hr);
555 ok(info.flags & CURSOR_SHOWING, "The gdi cursor is hidden (%08x)\n", info.flags);
556 ok(info.hCursor == cur, "The cursor handle is %p\n", info.hCursor); /* unchanged */
558 cleanup:
559 if(pD3d) IDirect3D8_Release(pD3d);
560 if(pDevice) IDirect3D8_Release(pDevice);
563 START_TEST(device)
565 HMODULE d3d8_handle = LoadLibraryA( "d3d8.dll" );
567 pDirect3DCreate8 = (void *)GetProcAddress( d3d8_handle, "Direct3DCreate8" );
568 if (pDirect3DCreate8)
570 test_swapchain();
571 test_refcount();
572 test_mipmap_levels();
573 test_cursor();