2 * Copyright (C) 2006 Vitaliy Margolen
3 * Copyright (C) 2006 Chris Robinson
4 * Copyright (C) 2006-2007 Stefan Dösinger(For CodeWeavers)
5 * Copyright 2007 Henri Verbeet
6 * Copyright (C) 2008 Rico Schüller
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/test.h"
27 static IDirect3D9
*(WINAPI
*pDirect3DCreate9
)(UINT
);
29 static int get_refcount(IUnknown
*object
)
31 IUnknown_AddRef( object
);
32 return IUnknown_Release( object
);
35 #define CHECK_CALL(r,c,d,rc) \
37 int tmp1 = get_refcount( (IUnknown *)d ); \
39 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
41 trace("%s failed: %08x\n", c, r); \
44 #define CHECK_RELEASE(obj,d,rc) \
46 int tmp1, rc_new = rc; \
47 IUnknown_Release( obj ); \
48 tmp1 = get_refcount( (IUnknown *)d ); \
49 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
52 #define CHECK_REFCOUNT(obj,rc) \
55 int count = get_refcount( (IUnknown *)obj ); \
56 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
59 #define CHECK_RELEASE_REFCOUNT(obj,rc) \
62 int count = IUnknown_Release( (IUnknown *)obj ); \
63 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
66 #define CHECK_ADDREF_REFCOUNT(obj,rc) \
69 int count = IUnknown_AddRef( (IUnknown *)obj ); \
70 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
73 #define CHECK_SURFACE_CONTAINER(obj,iid,expected) \
75 void *container_ptr = (void *)0x1337c0d3; \
76 hr = IDirect3DSurface9_GetContainer(obj, &iid, &container_ptr); \
77 ok(SUCCEEDED(hr) && container_ptr == expected, "GetContainer returned: hr %#x, container_ptr %p. " \
78 "Expected hr %#x, container_ptr %p\n", hr, container_ptr, S_OK, expected); \
79 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr); \
82 static void check_mipmap_levels(
83 IDirect3DDevice9
* device
,
84 int width
, int height
, int count
)
87 IDirect3DBaseTexture9
* texture
= NULL
;
88 HRESULT hr
= IDirect3DDevice9_CreateTexture( device
, width
, height
, 0, 0,
89 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, (IDirect3DTexture9
**) &texture
, NULL
);
92 DWORD levels
= IDirect3DBaseTexture9_GetLevelCount(texture
);
93 ok(levels
== count
, "Invalid level count. Expected %d got %u\n", count
, levels
);
95 trace("CreateTexture failed: %08x\n", hr
);
97 if (texture
) IUnknown_Release( texture
);
100 static void test_mipmap_levels(void)
106 IDirect3D9
*pD3d
= NULL
;
107 IDirect3DDevice9
*pDevice
= NULL
;
108 D3DPRESENT_PARAMETERS d3dpp
;
109 D3DDISPLAYMODE d3ddm
;
111 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
112 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
113 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
114 ok(hwnd
!= NULL
, "Failed to create window\n");
115 if (!pD3d
|| !hwnd
) goto cleanup
;
117 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
118 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
119 d3dpp
.Windowed
= TRUE
;
120 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
121 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
123 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_NULLREF
, hwnd
,
124 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
125 ok(SUCCEEDED(hr
) || hr
== D3DERR_NOTAVAILABLE
, "Failed to create IDirect3D9Device (%08x)\n", hr
);
127 skip("failed to create a d3d device\n");
131 check_mipmap_levels(pDevice
, 32, 32, 6);
132 check_mipmap_levels(pDevice
, 256, 1, 9);
133 check_mipmap_levels(pDevice
, 1, 256, 9);
134 check_mipmap_levels(pDevice
, 1, 1, 1);
137 if (pD3d
) IUnknown_Release( pD3d
);
138 if (pDevice
) IUnknown_Release( pDevice
);
139 DestroyWindow( hwnd
);
142 static void test_swapchain(void)
146 IDirect3D9
*pD3d
= NULL
;
147 IDirect3DDevice9
*pDevice
= NULL
;
148 IDirect3DSwapChain9
*swapchain0
= NULL
;
149 IDirect3DSwapChain9
*swapchain1
= NULL
;
150 IDirect3DSwapChain9
*swapchain2
= NULL
;
151 IDirect3DSwapChain9
*swapchain3
= NULL
;
152 IDirect3DSwapChain9
*swapchainX
= NULL
;
153 IDirect3DSurface9
*backbuffer
= NULL
;
154 D3DPRESENT_PARAMETERS d3dpp
;
155 D3DDISPLAYMODE d3ddm
;
157 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
158 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
159 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
160 ok(hwnd
!= NULL
, "Failed to create window\n");
161 if (!pD3d
|| !hwnd
) goto cleanup
;
163 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
164 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
165 d3dpp
.Windowed
= TRUE
;
166 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
167 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
168 d3dpp
.BackBufferCount
= 0;
170 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
171 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
172 ok(hr
== S_OK
|| hr
== D3DERR_NOTAVAILABLE
,
173 "Failed to create IDirect3D9Device (%08x)\n", hr
);
174 if (FAILED(hr
)) goto cleanup
;
176 /* Check if the back buffer count was modified */
177 ok(d3dpp
.BackBufferCount
== 1, "The back buffer count in the presentparams struct is %d\n", d3dpp
.BackBufferCount
);
179 /* Get the implicit swapchain */
180 hr
= IDirect3DDevice9_GetSwapChain(pDevice
, 0, &swapchain0
);
181 ok(SUCCEEDED(hr
), "Failed to get the impicit swapchain (%08x)\n", hr
);
182 if(swapchain0
) IDirect3DSwapChain9_Release(swapchain0
);
184 /* Check if there is a back buffer */
185 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain0
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
186 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
187 ok(backbuffer
!= NULL
, "The back buffer is NULL\n");
188 if(backbuffer
) IDirect3DSurface9_Release(backbuffer
);
190 /* Try to get a nonexistent swapchain */
191 hr
= IDirect3DDevice9_GetSwapChain(pDevice
, 1, &swapchainX
);
192 ok(hr
== D3DERR_INVALIDCALL
, "GetSwapChain on an nonexistent swapchain returned (%08x)\n", hr
);
193 ok(swapchainX
== NULL
, "Swapchain 1 is %p\n", swapchainX
);
194 if(swapchainX
) IDirect3DSwapChain9_Release(swapchainX
);
196 /* Create a bunch of swapchains */
197 d3dpp
.BackBufferCount
= 0;
198 hr
= IDirect3DDevice9_CreateAdditionalSwapChain(pDevice
, &d3dpp
, &swapchain1
);
199 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%08x)\n", hr
);
200 ok(d3dpp
.BackBufferCount
== 1, "The back buffer count in the presentparams struct is %d\n", d3dpp
.BackBufferCount
);
202 d3dpp
.BackBufferCount
= 1;
203 hr
= IDirect3DDevice9_CreateAdditionalSwapChain(pDevice
, &d3dpp
, &swapchain2
);
204 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%08x)\n", hr
);
206 d3dpp
.BackBufferCount
= 2;
207 hr
= IDirect3DDevice9_CreateAdditionalSwapChain(pDevice
, &d3dpp
, &swapchain3
);
208 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%08x)\n", hr
);
210 /* Swapchain 3, created with backbuffercount 2 */
211 backbuffer
= (void *) 0xdeadbeef;
212 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain3
, 0, 0, &backbuffer
);
213 ok(SUCCEEDED(hr
), "Failed to get the 1st back buffer (%08x)\n", hr
);
214 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
215 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
217 backbuffer
= (void *) 0xdeadbeef;
218 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain3
, 1, 0, &backbuffer
);
219 ok(SUCCEEDED(hr
), "Failed to get the 2nd back buffer (%08x)\n", hr
);
220 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
221 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
223 backbuffer
= (void *) 0xdeadbeef;
224 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain3
, 2, 0, &backbuffer
);
225 ok(hr
== D3DERR_INVALIDCALL
, "GetBackBuffer returned %08x\n", hr
);
226 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
227 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
229 backbuffer
= (void *) 0xdeadbeef;
230 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain3
, 3, 0, &backbuffer
);
231 ok(FAILED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
232 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
233 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
236 /* Check the back buffers of the swapchains */
237 /* Swapchain 1, created with backbuffercount 0 */
238 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain1
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
239 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
240 ok(backbuffer
!= NULL
, "The back buffer is NULL (%08x)\n", hr
);
241 if(backbuffer
) IDirect3DSurface9_Release(backbuffer
);
243 backbuffer
= (void *) 0xdeadbeef;
244 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain1
, 1, 0, &backbuffer
);
245 ok(FAILED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
246 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
247 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
249 /* Swapchain 2 - created with backbuffercount 1 */
250 backbuffer
= (void *) 0xdeadbeef;
251 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain2
, 0, 0, &backbuffer
);
252 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
253 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
254 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
256 backbuffer
= (void *) 0xdeadbeef;
257 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain2
, 1, 0, &backbuffer
);
258 ok(hr
== D3DERR_INVALIDCALL
, "GetBackBuffer returned %08x\n", hr
);
259 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
260 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
262 backbuffer
= (void *) 0xdeadbeef;
263 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain2
, 2, 0, &backbuffer
);
264 ok(FAILED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
265 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
266 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
268 /* Try getSwapChain on a manually created swapchain
269 * it should fail, apparently GetSwapChain only returns implicit swapchains
271 swapchainX
= (void *) 0xdeadbeef;
272 hr
= IDirect3DDevice9_GetSwapChain(pDevice
, 1, &swapchainX
);
273 ok(hr
== D3DERR_INVALIDCALL
, "Failed to get the second swapchain (%08x)\n", hr
);
274 ok(swapchainX
== NULL
, "The swapchain pointer is %p\n", swapchainX
);
275 if(swapchainX
&& swapchainX
!= (void *) 0xdeadbeef ) IDirect3DSwapChain9_Release(swapchainX
);
278 if(swapchain1
) IDirect3DSwapChain9_Release(swapchain1
);
279 if(swapchain2
) IDirect3DSwapChain9_Release(swapchain2
);
280 if(swapchain3
) IDirect3DSwapChain9_Release(swapchain3
);
281 if(pDevice
) IDirect3DDevice9_Release(pDevice
);
282 if(pD3d
) IDirect3DDevice9_Release(pD3d
);
283 DestroyWindow( hwnd
);
286 /* Shared between two functions */
287 static const DWORD simple_vs
[] = {0xFFFE0101, /* vs_1_1 */
288 0x0000001F, 0x80000000, 0x900F0000, /* dcl_position0 v0 */
289 0x00000009, 0xC0010000, 0x90E40000, 0xA0E40000, /* dp4 oPos.x, v0, c0 */
290 0x00000009, 0xC0020000, 0x90E40000, 0xA0E40001, /* dp4 oPos.y, v0, c1 */
291 0x00000009, 0xC0040000, 0x90E40000, 0xA0E40002, /* dp4 oPos.z, v0, c2 */
292 0x00000009, 0xC0080000, 0x90E40000, 0xA0E40003, /* dp4 oPos.w, v0, c3 */
293 0x0000FFFF}; /* END */
295 static void test_refcount(void)
299 IDirect3D9
*pD3d
= NULL
;
300 IDirect3DDevice9
*pDevice
= NULL
;
301 IDirect3DVertexBuffer9
*pVertexBuffer
= NULL
;
302 IDirect3DIndexBuffer9
*pIndexBuffer
= NULL
;
303 IDirect3DVertexDeclaration9
*pVertexDeclaration
= NULL
;
304 IDirect3DVertexShader9
*pVertexShader
= NULL
;
305 IDirect3DPixelShader9
*pPixelShader
= NULL
;
306 IDirect3DCubeTexture9
*pCubeTexture
= NULL
;
307 IDirect3DTexture9
*pTexture
= NULL
;
308 IDirect3DVolumeTexture9
*pVolumeTexture
= NULL
;
309 IDirect3DVolume9
*pVolumeLevel
= NULL
;
310 IDirect3DSurface9
*pStencilSurface
= NULL
;
311 IDirect3DSurface9
*pOffscreenSurface
= NULL
;
312 IDirect3DSurface9
*pRenderTarget
= NULL
;
313 IDirect3DSurface9
*pRenderTarget2
= NULL
;
314 IDirect3DSurface9
*pRenderTarget3
= NULL
;
315 IDirect3DSurface9
*pTextureLevel
= NULL
;
316 IDirect3DSurface9
*pBackBuffer
= NULL
;
317 IDirect3DStateBlock9
*pStateBlock
= NULL
;
318 IDirect3DStateBlock9
*pStateBlock1
= NULL
;
319 IDirect3DSwapChain9
*pSwapChain
= NULL
;
320 IDirect3DQuery9
*pQuery
= NULL
;
321 D3DPRESENT_PARAMETERS d3dpp
;
322 D3DDISPLAYMODE d3ddm
;
323 int refcount
= 0, tmp
;
325 D3DVERTEXELEMENT9 decl
[] =
329 static DWORD simple_ps
[] = {0xFFFF0101, /* ps_1_1 */
330 0x00000051, 0xA00F0001, 0x3F800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
331 0x00000042, 0xB00F0000, /* tex t0 */
332 0x00000008, 0x800F0000, 0xA0E40001, 0xA0E40000, /* dp3 r0, c1, c0 */
333 0x00000005, 0x800F0000, 0x90E40000, 0x80E40000, /* mul r0, v0, r0 */
334 0x00000005, 0x800F0000, 0xB0E40000, 0x80E40000, /* mul r0, t0, r0 */
335 0x0000FFFF}; /* END */
338 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
339 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
340 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
341 ok(hwnd
!= NULL
, "Failed to create window\n");
342 if (!pD3d
|| !hwnd
) goto cleanup
;
344 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
345 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
346 d3dpp
.Windowed
= TRUE
;
347 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
348 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
349 d3dpp
.EnableAutoDepthStencil
= TRUE
;
350 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
352 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
353 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
354 ok(hr
== S_OK
|| hr
== D3DERR_NOTAVAILABLE
,
355 "Failed to create IDirect3D9Device (%08x)\n", hr
);
356 if (FAILED(hr
)) goto cleanup
;
358 refcount
= get_refcount( (IUnknown
*)pDevice
);
359 ok(refcount
== 1, "Invalid device RefCount %d\n", refcount
);
362 * Check refcount of implicit surfaces and implicit swapchain. Findings:
363 * - the container is the device OR swapchain
364 * - they hold a reference to the device
365 * - they are created with a refcount of 0 (Get/Release returns original refcount)
366 * - they are not freed if refcount reaches 0.
367 * - the refcount is not forwarded to the container.
369 hr
= IDirect3DDevice9_GetSwapChain(pDevice
, 0, &pSwapChain
);
370 CHECK_CALL( hr
, "GetSwapChain", pDevice
, ++refcount
);
373 CHECK_REFCOUNT( pSwapChain
, 1);
375 hr
= IDirect3DDevice9_GetRenderTarget(pDevice
, 0, &pRenderTarget
);
376 CHECK_CALL( hr
, "GetRenderTarget", pDevice
, ++refcount
);
377 CHECK_REFCOUNT( pSwapChain
, 1);
380 CHECK_SURFACE_CONTAINER( pRenderTarget
, IID_IDirect3DSwapChain9
, pSwapChain
);
381 CHECK_REFCOUNT( pRenderTarget
, 1);
383 CHECK_ADDREF_REFCOUNT(pRenderTarget
, 2);
384 CHECK_REFCOUNT(pDevice
, refcount
);
385 CHECK_RELEASE_REFCOUNT(pRenderTarget
, 1);
386 CHECK_REFCOUNT(pDevice
, refcount
);
388 hr
= IDirect3DDevice9_GetRenderTarget(pDevice
, 0, &pRenderTarget
);
389 CHECK_CALL( hr
, "GetRenderTarget", pDevice
, refcount
);
390 CHECK_REFCOUNT( pRenderTarget
, 2);
391 CHECK_RELEASE_REFCOUNT( pRenderTarget
, 1);
392 CHECK_RELEASE_REFCOUNT( pRenderTarget
, 0);
393 CHECK_REFCOUNT( pDevice
, --refcount
);
395 /* The render target is released with the device, so AddRef with refcount=0 is fine here. */
396 CHECK_ADDREF_REFCOUNT(pRenderTarget
, 1);
397 CHECK_REFCOUNT(pDevice
, ++refcount
);
398 CHECK_RELEASE_REFCOUNT(pRenderTarget
, 0);
399 CHECK_REFCOUNT(pDevice
, --refcount
);
402 /* Render target and back buffer are identical. */
403 hr
= IDirect3DDevice9_GetBackBuffer(pDevice
, 0, 0, 0, &pBackBuffer
);
404 CHECK_CALL( hr
, "GetBackBuffer", pDevice
, ++refcount
);
407 CHECK_RELEASE_REFCOUNT(pBackBuffer
, 0);
408 ok(pRenderTarget
== pBackBuffer
, "RenderTarget=%p and BackBuffer=%p should be the same.\n",
409 pRenderTarget
, pBackBuffer
);
412 CHECK_REFCOUNT( pDevice
, --refcount
);
414 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &pStencilSurface
);
415 CHECK_CALL( hr
, "GetDepthStencilSurface", pDevice
, ++refcount
);
416 CHECK_REFCOUNT( pSwapChain
, 1);
419 CHECK_SURFACE_CONTAINER( pStencilSurface
, IID_IDirect3DDevice9
, 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 CHECK_RELEASE_REFCOUNT( pSwapChain
, 0);
439 CHECK_REFCOUNT( pDevice
, --refcount
);
441 /* The implicit swapchwin is released with the device, so AddRef with refcount=0 is fine here. */
442 CHECK_ADDREF_REFCOUNT(pSwapChain
, 1);
443 CHECK_REFCOUNT(pDevice
, ++refcount
);
444 CHECK_RELEASE_REFCOUNT(pSwapChain
, 0);
445 CHECK_REFCOUNT(pDevice
, --refcount
);
450 hr
= IDirect3DDevice9_CreateIndexBuffer( pDevice
, 16, 0, D3DFMT_INDEX32
, D3DPOOL_DEFAULT
, &pIndexBuffer
, NULL
);
451 CHECK_CALL( hr
, "CreateIndexBuffer", pDevice
, ++refcount
);
454 tmp
= get_refcount( (IUnknown
*)pIndexBuffer
);
456 hr
= IDirect3DDevice9_SetIndices(pDevice
, pIndexBuffer
);
457 CHECK_CALL( hr
, "SetIndices", pIndexBuffer
, tmp
);
458 hr
= IDirect3DDevice9_SetIndices(pDevice
, NULL
);
459 CHECK_CALL( hr
, "SetIndices", pIndexBuffer
, tmp
);
462 hr
= IDirect3DDevice9_CreateVertexBuffer( pDevice
, 16, 0, D3DFVF_XYZ
, D3DPOOL_DEFAULT
, &pVertexBuffer
, NULL
);
463 CHECK_CALL( hr
, "CreateVertexBuffer", pDevice
, ++refcount
);
466 IDirect3DVertexBuffer9
*pVBuf
= (void*)~0;
470 tmp
= get_refcount( (IUnknown
*)pVertexBuffer
);
472 hr
= IDirect3DDevice9_SetStreamSource(pDevice
, 0, pVertexBuffer
, 0, 3 * sizeof(float));
473 CHECK_CALL( hr
, "SetStreamSource", pVertexBuffer
, tmp
);
474 hr
= IDirect3DDevice9_SetStreamSource(pDevice
, 0, NULL
, 0, 0);
475 CHECK_CALL( hr
, "SetStreamSource", pVertexBuffer
, tmp
);
477 hr
= IDirect3DDevice9_GetStreamSource(pDevice
, 0, &pVBuf
, &offset
, &stride
);
478 ok(SUCCEEDED(hr
), "GetStreamSource did not succeed with NULL stream!\n");
479 ok(pVBuf
==NULL
, "pVBuf not NULL (%p)!\n", pVBuf
);
480 ok(stride
==3*sizeof(float), "stride not 3 floats (got %u)!\n", stride
);
481 ok(offset
==0, "offset not 0 (got %u)!\n", offset
);
484 hr
= IDirect3DDevice9_CreateVertexDeclaration( pDevice
, decl
, &pVertexDeclaration
);
485 CHECK_CALL( hr
, "CreateVertexDeclaration", pDevice
, ++refcount
);
486 hr
= IDirect3DDevice9_CreateVertexShader( pDevice
, simple_vs
, &pVertexShader
);
487 CHECK_CALL( hr
, "CreateVertexShader", pDevice
, ++refcount
);
488 hr
= IDirect3DDevice9_CreatePixelShader( pDevice
, simple_ps
, &pPixelShader
);
489 CHECK_CALL( hr
, "CreatePixelShader", pDevice
, ++refcount
);
491 hr
= IDirect3DDevice9_CreateTexture( pDevice
, 32, 32, 3, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pTexture
, NULL
);
492 CHECK_CALL( hr
, "CreateTexture", pDevice
, ++refcount
);
495 tmp
= get_refcount( (IUnknown
*)pTexture
);
497 /* SetTexture should not increase refcounts */
498 hr
= IDirect3DDevice9_SetTexture(pDevice
, 0, (IDirect3DBaseTexture9
*) pTexture
);
499 CHECK_CALL( hr
, "SetTexture", pTexture
, tmp
);
500 hr
= IDirect3DDevice9_SetTexture(pDevice
, 0, NULL
);
501 CHECK_CALL( hr
, "SetTexture", pTexture
, tmp
);
503 /* This should not increment device refcount */
504 hr
= IDirect3DTexture9_GetSurfaceLevel( pTexture
, 1, &pTextureLevel
);
505 CHECK_CALL( hr
, "GetSurfaceLevel", pDevice
, refcount
);
506 /* But should increment texture's refcount */
507 CHECK_REFCOUNT( pTexture
, tmp
+1 );
508 /* Because the texture and surface refcount are identical */
511 CHECK_REFCOUNT ( pTextureLevel
, tmp
+1 );
512 CHECK_ADDREF_REFCOUNT ( pTextureLevel
, tmp
+2 );
513 CHECK_REFCOUNT ( pTexture
, tmp
+2 );
514 CHECK_RELEASE_REFCOUNT( pTextureLevel
, tmp
+1 );
515 CHECK_REFCOUNT ( pTexture
, tmp
+1 );
516 CHECK_RELEASE_REFCOUNT( pTexture
, tmp
);
517 CHECK_REFCOUNT ( pTextureLevel
, tmp
);
520 hr
= IDirect3DDevice9_CreateCubeTexture( pDevice
, 32, 0, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pCubeTexture
, NULL
);
521 CHECK_CALL( hr
, "CreateCubeTexture", pDevice
, ++refcount
);
522 hr
= IDirect3DDevice9_CreateVolumeTexture( pDevice
, 32, 32, 2, 0, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pVolumeTexture
, NULL
);
523 CHECK_CALL( hr
, "CreateVolumeTexture", pDevice
, ++refcount
);
526 tmp
= get_refcount( (IUnknown
*)pVolumeTexture
);
528 /* This should not increment device refcount */
529 hr
= IDirect3DVolumeTexture9_GetVolumeLevel(pVolumeTexture
, 0, &pVolumeLevel
);
530 CHECK_CALL( hr
, "GetVolumeLevel", pDevice
, refcount
);
531 /* But should increment volume texture's refcount */
532 CHECK_REFCOUNT( pVolumeTexture
, tmp
+1 );
533 /* Because the volume texture and volume refcount are identical */
536 CHECK_REFCOUNT ( pVolumeLevel
, tmp
+1 );
537 CHECK_ADDREF_REFCOUNT ( pVolumeLevel
, tmp
+2 );
538 CHECK_REFCOUNT ( pVolumeTexture
, tmp
+2 );
539 CHECK_RELEASE_REFCOUNT( pVolumeLevel
, tmp
+1 );
540 CHECK_REFCOUNT ( pVolumeTexture
, tmp
+1 );
541 CHECK_RELEASE_REFCOUNT( pVolumeTexture
, tmp
);
542 CHECK_REFCOUNT ( pVolumeLevel
, tmp
);
546 hr
= IDirect3DDevice9_CreateDepthStencilSurface( pDevice
, 32, 32, D3DFMT_D24S8
, D3DMULTISAMPLE_NONE
, 0, TRUE
, &pStencilSurface
, NULL
);
547 CHECK_CALL( hr
, "CreateDepthStencilSurface", pDevice
, ++refcount
);
548 CHECK_REFCOUNT( pStencilSurface
, 1 );
549 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface( pDevice
, 32, 32, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pOffscreenSurface
, NULL
);
550 CHECK_CALL( hr
, "CreateOffscreenPlainSurface", pDevice
, ++refcount
);
551 CHECK_REFCOUNT( pOffscreenSurface
, 1 );
552 hr
= IDirect3DDevice9_CreateRenderTarget( pDevice
, 32, 32, D3DFMT_X8R8G8B8
, D3DMULTISAMPLE_NONE
, 0, TRUE
, &pRenderTarget3
, NULL
);
553 CHECK_CALL( hr
, "CreateRenderTarget", pDevice
, ++refcount
);
554 CHECK_REFCOUNT( pRenderTarget3
, 1 );
556 hr
= IDirect3DDevice9_CreateStateBlock( pDevice
, D3DSBT_ALL
, &pStateBlock
);
557 CHECK_CALL( hr
, "CreateStateBlock", pDevice
, ++refcount
);
558 hr
= IDirect3DDevice9_CreateAdditionalSwapChain( pDevice
, &d3dpp
, &pSwapChain
);
559 CHECK_CALL( hr
, "CreateAdditionalSwapChain", pDevice
, ++refcount
);
562 /* check implicit back buffer */
563 hr
= IDirect3DSwapChain9_GetBackBuffer(pSwapChain
, 0, 0, &pBackBuffer
);
564 CHECK_CALL( hr
, "GetBackBuffer", pDevice
, ++refcount
);
565 CHECK_REFCOUNT( pSwapChain
, 1);
568 CHECK_SURFACE_CONTAINER( pBackBuffer
, IID_IDirect3DSwapChain9
, pSwapChain
);
569 CHECK_REFCOUNT( pBackBuffer
, 1);
570 CHECK_RELEASE_REFCOUNT( pBackBuffer
, 0);
571 CHECK_REFCOUNT( pDevice
, --refcount
);
573 /* The back buffer is released with the swapchain, so AddRef with refcount=0 is fine here. */
574 CHECK_ADDREF_REFCOUNT(pBackBuffer
, 1);
575 CHECK_REFCOUNT(pDevice
, ++refcount
);
576 CHECK_RELEASE_REFCOUNT(pBackBuffer
, 0);
577 CHECK_REFCOUNT(pDevice
, --refcount
);
580 CHECK_REFCOUNT( pSwapChain
, 1);
582 hr
= IDirect3DDevice9_CreateQuery( pDevice
, D3DQUERYTYPE_EVENT
, &pQuery
);
583 CHECK_CALL( hr
, "CreateQuery", pDevice
, ++refcount
);
585 hr
= IDirect3DDevice9_BeginStateBlock( pDevice
);
586 CHECK_CALL( hr
, "BeginStateBlock", pDevice
, refcount
);
587 hr
= IDirect3DDevice9_EndStateBlock( pDevice
, &pStateBlock1
);
588 CHECK_CALL( hr
, "EndStateBlock", pDevice
, ++refcount
);
590 /* The implicit render target is not freed if refcount reaches 0.
591 * Otherwise GetRenderTarget would re-allocate it and the pointer would change.*/
592 hr
= IDirect3DDevice9_GetRenderTarget(pDevice
, 0, &pRenderTarget2
);
593 CHECK_CALL( hr
, "GetRenderTarget", pDevice
, ++refcount
);
596 CHECK_RELEASE_REFCOUNT(pRenderTarget2
, 0);
597 ok(pRenderTarget
== pRenderTarget2
, "RenderTarget=%p and RenderTarget2=%p should be the same.\n",
598 pRenderTarget
, pRenderTarget2
);
599 CHECK_REFCOUNT( pDevice
, --refcount
);
600 pRenderTarget2
= NULL
;
602 pRenderTarget
= NULL
;
605 CHECK_RELEASE(pDevice
, pDevice
, --refcount
);
608 CHECK_RELEASE(pVertexBuffer
, pDevice
, --refcount
);
609 CHECK_RELEASE(pIndexBuffer
, pDevice
, --refcount
);
611 CHECK_RELEASE(pVertexDeclaration
, pDevice
, --refcount
);
612 CHECK_RELEASE(pVertexShader
, pDevice
, --refcount
);
613 CHECK_RELEASE(pPixelShader
, pDevice
, --refcount
);
615 CHECK_RELEASE(pTextureLevel
, pDevice
, --refcount
);
616 CHECK_RELEASE(pCubeTexture
, pDevice
, --refcount
);
617 CHECK_RELEASE(pVolumeTexture
, pDevice
, --refcount
);
619 CHECK_RELEASE(pStencilSurface
, pDevice
, --refcount
);
620 CHECK_RELEASE(pOffscreenSurface
, pDevice
, --refcount
);
621 CHECK_RELEASE(pRenderTarget3
, pDevice
, --refcount
);
623 CHECK_RELEASE(pStateBlock
, pDevice
, --refcount
);
624 CHECK_RELEASE(pSwapChain
, pDevice
, --refcount
);
625 CHECK_RELEASE(pQuery
, pDevice
, --refcount
);
626 /* This will destroy device - cannot check the refcount here */
627 if (pStateBlock1
) CHECK_RELEASE_REFCOUNT( pStateBlock1
, 0);
629 if (pD3d
) CHECK_RELEASE_REFCOUNT( pD3d
, 0);
631 DestroyWindow( hwnd
);
634 static void test_cursor(void)
638 IDirect3D9
*pD3d
= NULL
;
639 IDirect3DDevice9
*pDevice
= NULL
;
640 D3DPRESENT_PARAMETERS d3dpp
;
641 D3DDISPLAYMODE d3ddm
;
643 IDirect3DSurface9
*cursor
= NULL
;
646 memset(&info
, 0, sizeof(info
));
647 info
.cbSize
= sizeof(info
);
648 ok(GetCursorInfo(&info
), "GetCursorInfo failed\n");
651 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
652 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
653 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
654 ok(hwnd
!= NULL
, "Failed to create window\n");
655 if (!pD3d
|| !hwnd
) goto cleanup
;
657 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
658 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
659 d3dpp
.Windowed
= TRUE
;
660 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
661 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
663 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
664 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
665 ok(hr
== S_OK
|| hr
== D3DERR_NOTAVAILABLE
,
666 "Failed to create IDirect3D9Device (%08x)\n", hr
);
667 if (FAILED(hr
)) goto cleanup
;
669 IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 32, 32, D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &cursor
, 0);
670 ok(cursor
!= NULL
, "IDirect3DDevice9_CreateOffscreenPlainSurface failed with %08x\n", hr
);
672 /* Initially hidden */
673 hr
= IDirect3DDevice9_ShowCursor(pDevice
, TRUE
);
674 ok(hr
== FALSE
, "IDirect3DDevice9_ShowCursor returned %08x\n", hr
);
676 /* Not enabled without a surface*/
677 hr
= IDirect3DDevice9_ShowCursor(pDevice
, TRUE
);
678 ok(hr
== FALSE
, "IDirect3DDevice9_ShowCursor returned %08x\n", hr
);
681 hr
= IDirect3DDevice9_SetCursorProperties(pDevice
, 0, 0, NULL
);
682 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_SetCursorProperties returned %08x\n", hr
);
684 hr
= IDirect3DDevice9_SetCursorProperties(pDevice
, 0, 0, cursor
);
685 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetCursorProperties returned %08x\n", hr
);
687 IDirect3DSurface9_Release(cursor
);
689 memset(&info
, 0, sizeof(info
));
690 info
.cbSize
= sizeof(info
);
691 ok(GetCursorInfo(&info
), "GetCursorInfo failed\n");
692 ok(info
.flags
& CURSOR_SHOWING
, "The gdi cursor is hidden (%08x)\n", info
.flags
);
693 ok(info
.hCursor
== cur
, "The cursor handle is %p\n", info
.hCursor
); /* unchanged */
696 hr
= IDirect3DDevice9_ShowCursor(pDevice
, TRUE
);
697 ok(hr
== FALSE
, "IDirect3DDevice9_ShowCursor returned %08x\n", hr
);
700 hr
= IDirect3DDevice9_ShowCursor(pDevice
, TRUE
);
701 ok(hr
== TRUE
, "IDirect3DDevice9_ShowCursor returned %08x\n", hr
);
703 /* GDI cursor unchanged */
704 memset(&info
, 0, sizeof(info
));
705 info
.cbSize
= sizeof(info
);
706 ok(GetCursorInfo(&info
), "GetCursorInfo failed\n");
707 ok(info
.flags
& CURSOR_SHOWING
, "The gdi cursor is hidden (%08x)\n", info
.flags
);
708 ok(info
.hCursor
== cur
, "The cursor handle is %p\n", info
.hCursor
); /* unchanged */
711 if(pDevice
) IDirect3D9_Release(pDevice
);
712 if(pD3d
) IDirect3D9_Release(pD3d
);
713 DestroyWindow( hwnd
);
716 static void test_reset(void)
720 IDirect3D9
*pD3d
= NULL
;
721 IDirect3DDevice9
*pDevice
= NULL
;
722 D3DPRESENT_PARAMETERS d3dpp
;
723 D3DDISPLAYMODE d3ddm
, d3ddm2
;
725 DWORD width
, orig_width
= GetSystemMetrics(SM_CXSCREEN
);
726 DWORD height
, orig_height
= GetSystemMetrics(SM_CYSCREEN
);
727 IDirect3DSwapChain9
*pSwapchain
;
728 IDirect3DSurface9
*surface
;
729 IDirect3DTexture9
*texture
;
730 IDirect3DVertexShader9
*shader
;
731 BOOL support_800x600
= FALSE
;
733 D3DLOCKED_RECT lockrect
;
735 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
736 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
737 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
738 ok(hwnd
!= NULL
, "Failed to create window\n");
739 if (!pD3d
|| !hwnd
) goto cleanup
;
741 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
742 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
743 d3dpp
.Windowed
= FALSE
;
744 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
745 d3dpp
.BackBufferWidth
= 800;
746 d3dpp
.BackBufferHeight
= 600;
747 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
748 d3dpp
.EnableAutoDepthStencil
= TRUE
;
749 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
751 for(i
= 0; i
< IDirect3D9_GetAdapterModeCount(pD3d
, D3DADAPTER_DEFAULT
, d3ddm
.Format
); i
++) {
752 ZeroMemory( &d3ddm2
, sizeof(d3ddm2
) );
753 hr
= IDirect3D9_EnumAdapterModes(pD3d
, D3DADAPTER_DEFAULT
, d3ddm
.Format
, i
, &d3ddm2
);
754 ok(hr
== D3D_OK
, "IDirect3D9_EnumAdapterModes returned %#x\n", hr
);
756 if(d3ddm2
.Width
== 800 && d3ddm2
.Height
== 600) {
757 support_800x600
= TRUE
;
759 /* We use them as invalid modes */
760 if((d3ddm2
.Width
== 801 && d3ddm2
.Height
== 600) ||
761 (d3ddm2
.Width
== 32 && d3ddm2
.Height
== 32)) {
762 skip("This system supports a screen resolution of %dx%d, not running mode tests\n",
763 d3ddm2
.Width
, d3ddm2
.Height
);
767 if(!support_800x600
) {
768 skip("Mode 800x600 not supported, skipping mode tests\n");
772 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
773 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
777 skip("could not create device, IDirect3D9_CreateDevice returned %#x\n", hr
);
780 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
781 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after creation returned %#x\n", hr
);
783 width
= GetSystemMetrics(SM_CXSCREEN
);
784 height
= GetSystemMetrics(SM_CYSCREEN
);
785 ok(width
== 800, "Screen width is %d\n", width
);
786 ok(height
== 600, "Screen height is %d\n", height
);
788 hr
= IDirect3DDevice9_GetViewport(pDevice
, &vp
);
789 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetViewport failed with %08x\n", hr
);
792 ok(vp
.X
== 0, "D3DVIEWPORT->X = %d\n", vp
.X
);
793 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %d\n", vp
.Y
);
794 ok(vp
.Width
== 800, "D3DVIEWPORT->Width = %d\n", vp
.Width
);
795 ok(vp
.Height
== 600, "D3DVIEWPORT->Height = %d\n", vp
.Height
);
796 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %f\n", vp
.MinZ
);
797 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %f\n", vp
.MaxZ
);
803 hr
= IDirect3DDevice9_SetViewport(pDevice
, &vp
);
804 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetViewport failed with %08x\n", hr
);
806 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
807 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
808 d3dpp
.Windowed
= FALSE
;
809 d3dpp
.BackBufferWidth
= 640;
810 d3dpp
.BackBufferHeight
= 480;
811 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
812 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
813 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
814 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
815 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
817 ZeroMemory(&vp
, sizeof(vp
));
818 hr
= IDirect3DDevice9_GetViewport(pDevice
, &vp
);
819 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetViewport failed with %08x\n", hr
);
822 ok(vp
.X
== 0, "D3DVIEWPORT->X = %d\n", vp
.X
);
823 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %d\n", vp
.Y
);
824 ok(vp
.Width
== 640, "D3DVIEWPORT->Width = %d\n", vp
.Width
);
825 ok(vp
.Height
== 480, "D3DVIEWPORT->Height = %d\n", vp
.Height
);
826 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %f\n", vp
.MinZ
);
827 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %f\n", vp
.MaxZ
);
830 width
= GetSystemMetrics(SM_CXSCREEN
);
831 height
= GetSystemMetrics(SM_CYSCREEN
);
832 ok(width
== 640, "Screen width is %d\n", width
);
833 ok(height
== 480, "Screen height is %d\n", height
);
835 hr
= IDirect3DDevice9_GetSwapChain(pDevice
, 0, &pSwapchain
);
836 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetSwapChain returned %08x\n", hr
);
839 ZeroMemory(&d3dpp
, sizeof(d3dpp
));
840 hr
= IDirect3DSwapChain9_GetPresentParameters(pSwapchain
, &d3dpp
);
841 ok(hr
== D3D_OK
, "IDirect3DSwapChain9_GetPresentParameters returned %08x\n", hr
);
844 ok(d3dpp
.BackBufferWidth
== 640, "Back buffer width is %d\n", d3dpp
.BackBufferWidth
);
845 ok(d3dpp
.BackBufferHeight
== 480, "Back buffer height is %d\n", d3dpp
.BackBufferHeight
);
847 IDirect3DSwapChain9_Release(pSwapchain
);
850 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
851 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
852 d3dpp
.Windowed
= TRUE
;
853 d3dpp
.BackBufferWidth
= 400;
854 d3dpp
.BackBufferHeight
= 300;
855 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
856 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
857 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
858 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
860 width
= GetSystemMetrics(SM_CXSCREEN
);
861 height
= GetSystemMetrics(SM_CYSCREEN
);
862 ok(width
== orig_width
, "Screen width is %d\n", width
);
863 ok(height
== orig_height
, "Screen height is %d\n", height
);
865 ZeroMemory(&vp
, sizeof(vp
));
866 hr
= IDirect3DDevice9_GetViewport(pDevice
, &vp
);
867 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetViewport failed with %08x\n", hr
);
870 ok(vp
.X
== 0, "D3DVIEWPORT->X = %d\n", vp
.X
);
871 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %d\n", vp
.Y
);
872 ok(vp
.Width
== 400, "D3DVIEWPORT->Width = %d\n", vp
.Width
);
873 ok(vp
.Height
== 300, "D3DVIEWPORT->Height = %d\n", vp
.Height
);
874 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %f\n", vp
.MinZ
);
875 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %f\n", vp
.MaxZ
);
878 hr
= IDirect3DDevice9_GetSwapChain(pDevice
, 0, &pSwapchain
);
879 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetSwapChain returned %08x\n", hr
);
882 ZeroMemory(&d3dpp
, sizeof(d3dpp
));
883 hr
= IDirect3DSwapChain9_GetPresentParameters(pSwapchain
, &d3dpp
);
884 ok(hr
== D3D_OK
, "IDirect3DSwapChain9_GetPresentParameters returned %08x\n", hr
);
887 ok(d3dpp
.BackBufferWidth
== 400, "Back buffer width is %d\n", d3dpp
.BackBufferWidth
);
888 ok(d3dpp
.BackBufferHeight
== 300, "Back buffer height is %d\n", d3dpp
.BackBufferHeight
);
890 IDirect3DSwapChain9_Release(pSwapchain
);
893 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
894 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
895 d3dpp
.Windowed
= TRUE
;
896 d3dpp
.BackBufferWidth
= 400;
897 d3dpp
.BackBufferHeight
= 300;
899 /* _Reset fails if there is a resource in the default pool */
900 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 16, 16, D3DFMT_R5G6B5
, D3DPOOL_DEFAULT
, &surface
, NULL
);
901 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr
);
902 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
903 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
904 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
905 ok(hr
== D3DERR_DEVICENOTRESET
, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr
);
906 IDirect3DSurface9_Release(surface
);
907 /* Reset again to get the device out of the lost state */
908 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
909 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
910 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
911 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
913 /* Scratch, sysmem and managed pools are fine */
914 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 16, 16, D3DFMT_R5G6B5
, D3DPOOL_SCRATCH
, &surface
, NULL
);
915 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr
);
916 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
917 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
918 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
919 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
920 IDirect3DSurface9_Release(surface
);
922 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 16, 16, D3DFMT_R5G6B5
, D3DPOOL_SYSTEMMEM
, &surface
, NULL
);
923 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr
);
924 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
925 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
926 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
927 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
928 IDirect3DSurface9_Release(surface
);
930 /* The depth stencil should get reset to the auto depth stencil when present. */
931 hr
= IDirect3DDevice9_SetDepthStencilSurface(pDevice
, NULL
);
932 ok(hr
== D3D_OK
, "SetDepthStencilSurface failed with 0x%08x\n", hr
);
934 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &surface
);
935 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr
);
936 ok(surface
== NULL
, "Depth stencil should be NULL\n");
938 d3dpp
.EnableAutoDepthStencil
= TRUE
;
939 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
940 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
941 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with 0x%08x\n", hr
);
943 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &surface
);
944 ok(hr
== D3D_OK
, "GetDepthStencilSurface failed with 0x%08x\n", hr
);
945 ok(surface
!= NULL
, "Depth stencil should not be NULL\n");
946 if (surface
) IDirect3DSurface9_Release(surface
);
948 d3dpp
.EnableAutoDepthStencil
= FALSE
;
949 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
950 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with 0x%08x\n", hr
);
952 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &surface
);
953 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr
);
954 ok(surface
== NULL
, "Depth stencil should be NULL\n");
956 /* Will a sysmem or scratch survive while locked */
957 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 16, 16, D3DFMT_R5G6B5
, D3DPOOL_SYSTEMMEM
, &surface
, NULL
);
958 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr
);
959 hr
= IDirect3DSurface9_LockRect(surface
, &lockrect
, NULL
, D3DLOCK_DISCARD
);
960 ok(hr
== D3D_OK
, "IDirect3DSurface9_LockRect returned %08x\n", hr
);
961 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
962 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
963 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
964 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
965 IDirect3DSurface9_UnlockRect(surface
);
966 IDirect3DSurface9_Release(surface
);
968 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 16, 16, D3DFMT_R5G6B5
, D3DPOOL_SCRATCH
, &surface
, NULL
);
969 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr
);
970 hr
= IDirect3DSurface9_LockRect(surface
, &lockrect
, NULL
, D3DLOCK_DISCARD
);
971 ok(hr
== D3D_OK
, "IDirect3DSurface9_LockRect returned %08x\n", hr
);
972 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
973 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
974 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
975 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
976 IDirect3DSurface9_UnlockRect(surface
);
977 IDirect3DSurface9_Release(surface
);
979 hr
= IDirect3DDevice9_CreateTexture(pDevice
, 16, 16, 0, 0, D3DFMT_R5G6B5
, D3DPOOL_MANAGED
, &texture
, NULL
);
980 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture returned %08x\n", hr
);
981 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
982 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
983 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
984 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
985 IDirect3DTexture9_Release(texture
);
987 /* A reference held to an implicit surface causes failures as well */
988 hr
= IDirect3DDevice9_GetBackBuffer(pDevice
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &surface
);
989 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetBackBuffer returned %08x\n", hr
);
990 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
991 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
992 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
993 ok(hr
== D3DERR_DEVICENOTRESET
, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr
);
994 IDirect3DSurface9_Release(surface
);
995 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
996 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
997 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
998 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
1000 /* Shaders are fine as well */
1001 hr
= IDirect3DDevice9_CreateVertexShader(pDevice
, simple_vs
, &shader
);
1002 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr
);
1003 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1004 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1005 IDirect3DVertexShader9_Release(shader
);
1007 /* Try setting invalid modes */
1008 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1009 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1010 d3dpp
.Windowed
= FALSE
;
1011 d3dpp
.BackBufferWidth
= 32;
1012 d3dpp
.BackBufferHeight
= 32;
1013 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1014 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Reset to w=32, h=32, windowed=FALSE failed with %08x\n", hr
);
1015 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
1016 ok(hr
== D3DERR_DEVICENOTRESET
, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr
);
1018 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1019 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1020 d3dpp
.Windowed
= FALSE
;
1021 d3dpp
.BackBufferWidth
= 801;
1022 d3dpp
.BackBufferHeight
= 600;
1023 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1024 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Reset to w=801, h=600, windowed=FALSE failed with %08x\n", hr
);
1025 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
1026 ok(hr
== D3DERR_DEVICENOTRESET
, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr
);
1029 if(pD3d
) IDirect3D9_Release(pD3d
);
1030 if(pDevice
) IDirect3D9_Release(pDevice
);
1033 /* Test adapter display modes */
1034 static void test_display_modes(void)
1036 D3DDISPLAYMODE dmode
;
1039 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
1040 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
1043 #define TEST_FMT(x,r) do { \
1044 HRESULT res = IDirect3D9_EnumAdapterModes(pD3d, 0, (x), 0, &dmode); \
1045 ok(res==(r), "EnumAdapterModes("#x") did not return "#r" (got %08x)!\n", res); \
1048 TEST_FMT(D3DFMT_R8G8B8
, D3DERR_INVALIDCALL
);
1049 TEST_FMT(D3DFMT_A8R8G8B8
, D3DERR_INVALIDCALL
);
1050 TEST_FMT(D3DFMT_X8B8G8R8
, D3DERR_INVALIDCALL
);
1052 TEST_FMT(D3DFMT_X1R5G5B5
, D3DERR_INVALIDCALL
);
1053 TEST_FMT(D3DFMT_A1R5G5B5
, D3DERR_INVALIDCALL
);
1054 TEST_FMT(D3DFMT_A4R4G4B4
, D3DERR_INVALIDCALL
);
1055 TEST_FMT(D3DFMT_R3G3B2
, D3DERR_INVALIDCALL
);
1056 TEST_FMT(D3DFMT_A8
, D3DERR_INVALIDCALL
);
1057 TEST_FMT(D3DFMT_A8R3G3B2
, D3DERR_INVALIDCALL
);
1058 TEST_FMT(D3DFMT_X4R4G4B4
, D3DERR_INVALIDCALL
);
1059 TEST_FMT(D3DFMT_A2B10G10R10
, D3DERR_INVALIDCALL
);
1060 TEST_FMT(D3DFMT_A8B8G8R8
, D3DERR_INVALIDCALL
);
1061 TEST_FMT(D3DFMT_X8B8G8R8
, D3DERR_INVALIDCALL
);
1062 TEST_FMT(D3DFMT_G16R16
, D3DERR_INVALIDCALL
);
1063 TEST_FMT(D3DFMT_A2R10G10B10
, D3DERR_INVALIDCALL
);
1064 TEST_FMT(D3DFMT_A16B16G16R16
, D3DERR_INVALIDCALL
);
1066 TEST_FMT(D3DFMT_A8P8
, D3DERR_INVALIDCALL
);
1067 TEST_FMT(D3DFMT_P8
, D3DERR_INVALIDCALL
);
1069 TEST_FMT(D3DFMT_L8
, D3DERR_INVALIDCALL
);
1070 TEST_FMT(D3DFMT_A8L8
, D3DERR_INVALIDCALL
);
1071 TEST_FMT(D3DFMT_A4L4
, D3DERR_INVALIDCALL
);
1073 TEST_FMT(D3DFMT_V8U8
, D3DERR_INVALIDCALL
);
1074 TEST_FMT(D3DFMT_L6V5U5
, D3DERR_INVALIDCALL
);
1075 TEST_FMT(D3DFMT_X8L8V8U8
, D3DERR_INVALIDCALL
);
1076 TEST_FMT(D3DFMT_Q8W8V8U8
, D3DERR_INVALIDCALL
);
1077 TEST_FMT(D3DFMT_V16U16
, D3DERR_INVALIDCALL
);
1078 TEST_FMT(D3DFMT_A2W10V10U10
, D3DERR_INVALIDCALL
);
1080 TEST_FMT(D3DFMT_UYVY
, D3DERR_INVALIDCALL
);
1081 TEST_FMT(D3DFMT_YUY2
, D3DERR_INVALIDCALL
);
1082 TEST_FMT(D3DFMT_DXT1
, D3DERR_INVALIDCALL
);
1083 TEST_FMT(D3DFMT_DXT2
, D3DERR_INVALIDCALL
);
1084 TEST_FMT(D3DFMT_DXT3
, D3DERR_INVALIDCALL
);
1085 TEST_FMT(D3DFMT_DXT4
, D3DERR_INVALIDCALL
);
1086 TEST_FMT(D3DFMT_DXT5
, D3DERR_INVALIDCALL
);
1087 TEST_FMT(D3DFMT_MULTI2_ARGB8
, D3DERR_INVALIDCALL
);
1088 TEST_FMT(D3DFMT_G8R8_G8B8
, D3DERR_INVALIDCALL
);
1089 TEST_FMT(D3DFMT_R8G8_B8G8
, D3DERR_INVALIDCALL
);
1091 TEST_FMT(D3DFMT_D16_LOCKABLE
, D3DERR_INVALIDCALL
);
1092 TEST_FMT(D3DFMT_D32
, D3DERR_INVALIDCALL
);
1093 TEST_FMT(D3DFMT_D15S1
, D3DERR_INVALIDCALL
);
1094 TEST_FMT(D3DFMT_D24S8
, D3DERR_INVALIDCALL
);
1095 TEST_FMT(D3DFMT_D24X8
, D3DERR_INVALIDCALL
);
1096 TEST_FMT(D3DFMT_D24X4S4
, D3DERR_INVALIDCALL
);
1097 TEST_FMT(D3DFMT_D16
, D3DERR_INVALIDCALL
);
1098 TEST_FMT(D3DFMT_L16
, D3DERR_INVALIDCALL
);
1099 TEST_FMT(D3DFMT_D32F_LOCKABLE
, D3DERR_INVALIDCALL
);
1100 TEST_FMT(D3DFMT_D24FS8
, D3DERR_INVALIDCALL
);
1102 TEST_FMT(D3DFMT_VERTEXDATA
, D3DERR_INVALIDCALL
);
1103 TEST_FMT(D3DFMT_INDEX16
, D3DERR_INVALIDCALL
);
1104 TEST_FMT(D3DFMT_INDEX32
, D3DERR_INVALIDCALL
);
1105 TEST_FMT(D3DFMT_Q16W16V16U16
, D3DERR_INVALIDCALL
);
1106 /* Floating point formats */
1107 TEST_FMT(D3DFMT_R16F
, D3DERR_INVALIDCALL
);
1108 TEST_FMT(D3DFMT_G16R16F
, D3DERR_INVALIDCALL
);
1109 TEST_FMT(D3DFMT_A16B16G16R16F
, D3DERR_INVALIDCALL
);
1112 TEST_FMT(D3DFMT_R32F
, D3DERR_INVALIDCALL
);
1113 TEST_FMT(D3DFMT_G32R32F
, D3DERR_INVALIDCALL
);
1114 TEST_FMT(D3DFMT_A32B32G32R32F
, D3DERR_INVALIDCALL
);
1116 TEST_FMT(D3DFMT_CxV8U8
, D3DERR_INVALIDCALL
);
1118 TEST_FMT(0, D3DERR_INVALIDCALL
);
1120 IDirect3D9_Release(pD3d
);
1123 static void test_scene(void)
1127 IDirect3D9
*pD3d
= NULL
;
1128 IDirect3DDevice9
*pDevice
= NULL
;
1129 D3DPRESENT_PARAMETERS d3dpp
;
1130 D3DDISPLAYMODE d3ddm
;
1131 IDirect3DSurface9
*pSurface1
= NULL
, *pSurface2
= NULL
, *pSurface3
= NULL
, *pRenderTarget
= NULL
;
1132 IDirect3DSurface9
*pBackBuffer
= NULL
, *pDepthStencil
= NULL
;
1133 RECT rect
= {0, 0, 128, 128};
1136 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
1137 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
1138 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1139 ok(hwnd
!= NULL
, "Failed to create window\n");
1140 if (!pD3d
|| !hwnd
) goto cleanup
;
1142 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
1143 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1144 d3dpp
.Windowed
= TRUE
;
1145 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1146 d3dpp
.BackBufferWidth
= 800;
1147 d3dpp
.BackBufferHeight
= 600;
1148 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1149 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1150 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
1152 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1153 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
1154 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1157 skip("Failed to create a d3d device\n");
1161 /* Get the caps, they will be needed to tell if an operation is supposed to be valid */
1162 memset(&caps
, 0, sizeof(caps
));
1163 hr
= IDirect3DDevice9_GetDeviceCaps(pDevice
, &caps
);
1164 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetCaps failed with %08x\n", hr
);
1165 if(FAILED(hr
)) goto cleanup
;
1167 /* Test an EndScene without beginscene. Should return an error */
1168 hr
= IDirect3DDevice9_EndScene(pDevice
);
1169 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_EndScene returned %08x\n", hr
);
1171 /* Test a normal BeginScene / EndScene pair, this should work */
1172 hr
= IDirect3DDevice9_BeginScene(pDevice
);
1173 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %08x\n", hr
);
1176 hr
= IDirect3DDevice9_EndScene(pDevice
);
1177 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %08x\n", hr
);
1180 /* Test another EndScene without having begun a new scene. Should return an error */
1181 hr
= IDirect3DDevice9_EndScene(pDevice
);
1182 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_EndScene returned %08x\n", hr
);
1184 /* Two nested BeginScene and EndScene calls */
1185 hr
= IDirect3DDevice9_BeginScene(pDevice
);
1186 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %08x\n", hr
);
1187 hr
= IDirect3DDevice9_BeginScene(pDevice
);
1188 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_BeginScene returned %08x\n", hr
);
1189 hr
= IDirect3DDevice9_EndScene(pDevice
);
1190 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %08x\n", hr
);
1191 hr
= IDirect3DDevice9_EndScene(pDevice
);
1192 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_EndScene returned %08x\n", hr
);
1194 /* Create some surfaces to test stretchrect between the scenes */
1195 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 128, 128, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &pSurface1
, NULL
);
1196 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface failed with %08x\n", hr
);
1197 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 128, 128, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &pSurface2
, NULL
);
1198 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface failed with %08x\n", hr
);
1199 hr
= IDirect3DDevice9_CreateDepthStencilSurface(pDevice
, 800, 600, D3DFMT_D16
, D3DMULTISAMPLE_NONE
, 0, FALSE
, &pSurface3
, NULL
);
1200 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateDepthStencilSurface failed with %08x\n", hr
);
1201 hr
= IDirect3DDevice9_CreateRenderTarget(pDevice
, 128, 128, d3ddm
.Format
, D3DMULTISAMPLE_NONE
, 0, FALSE
, &pRenderTarget
, NULL
);
1202 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateRenderTarget failed with %08x\n", hr
);
1204 hr
= IDirect3DDevice9_GetBackBuffer(pDevice
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &pBackBuffer
);
1205 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetBackBuffer failed with %08x\n", hr
);
1206 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &pDepthStencil
);
1207 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetBackBuffer failed with %08x\n", hr
);
1209 /* First make sure a simple StretchRect call works */
1210 if(pSurface1
&& pSurface2
) {
1211 hr
= IDirect3DDevice9_StretchRect(pDevice
, pSurface1
, NULL
, pSurface2
, NULL
, 0);
1212 ok( hr
== D3D_OK
, "IDirect3DDevice9_StretchRect failed with %08x\n", hr
);
1214 if(pBackBuffer
&& pRenderTarget
) {
1215 hr
= IDirect3DDevice9_StretchRect(pDevice
, pBackBuffer
, &rect
, pRenderTarget
, NULL
, 0);
1216 ok( hr
== D3D_OK
, "IDirect3DDevice9_StretchRect failed with %08x\n", hr
);
1218 if(pDepthStencil
&& pSurface3
) {
1220 if(0) /* Disabled for now because it crashes in wine */ {
1221 expected
= caps
.DevCaps2
& D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES
? D3D_OK
: D3DERR_INVALIDCALL
;
1222 hr
= IDirect3DDevice9_StretchRect(pDevice
, pDepthStencil
, NULL
, pSurface3
, NULL
, 0);
1223 ok( hr
== expected
, "IDirect3DDevice9_StretchRect returned %08x, expected %08x\n", hr
, expected
);
1227 /* Now try it in a BeginScene - EndScene pair. Seems to be allowed in a beginScene - Endscene pair
1228 * width normal surfaces, render targets and depth stencil surfaces.
1230 hr
= IDirect3DDevice9_BeginScene(pDevice
);
1231 ok( hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %08x\n", hr
);
1233 if(pSurface1
&& pSurface2
)
1235 hr
= IDirect3DDevice9_StretchRect(pDevice
, pSurface1
, NULL
, pSurface2
, NULL
, 0);
1236 ok( hr
== D3D_OK
, "IDirect3DDevice9_StretchRect failed with %08x\n", hr
);
1238 if(pBackBuffer
&& pRenderTarget
)
1240 hr
= IDirect3DDevice9_StretchRect(pDevice
, pBackBuffer
, &rect
, pRenderTarget
, NULL
, 0);
1241 ok( hr
== D3D_OK
, "IDirect3DDevice9_StretchRect failed with %08x\n", hr
);
1243 if(pDepthStencil
&& pSurface3
)
1245 /* This is supposed to fail inside a BeginScene - EndScene pair. */
1246 hr
= IDirect3DDevice9_StretchRect(pDevice
, pDepthStencil
, NULL
, pSurface3
, NULL
, 0);
1247 ok( hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_StretchRect returned %08x, expected D3DERR_INVALIDCALL\n", hr
);
1250 hr
= IDirect3DDevice9_EndScene(pDevice
);
1251 ok( hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %08x\n", hr
);
1253 /* Does a SetRenderTarget influence BeginScene / EndScene ?
1254 * Set a new render target, then see if it started a new scene. Flip the rt back and see if that maybe
1255 * ended the scene. Expected result is that the scene is not affected by SetRenderTarget
1257 hr
= IDirect3DDevice9_SetRenderTarget(pDevice
, 0, pRenderTarget
);
1258 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderTarget failed with %08x\n", hr
);
1259 hr
= IDirect3DDevice9_BeginScene(pDevice
);
1260 ok( hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %08x\n", hr
);
1261 hr
= IDirect3DDevice9_SetRenderTarget(pDevice
, 0, pBackBuffer
);
1262 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderTarget failed with %08x\n", hr
);
1263 hr
= IDirect3DDevice9_EndScene(pDevice
);
1264 ok( hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %08x\n", hr
);
1267 if(pRenderTarget
) IDirect3DSurface9_Release(pRenderTarget
);
1268 if(pDepthStencil
) IDirect3DSurface9_Release(pDepthStencil
);
1269 if(pBackBuffer
) IDirect3DSurface9_Release(pBackBuffer
);
1270 if(pSurface1
) IDirect3DSurface9_Release(pSurface1
);
1271 if(pSurface2
) IDirect3DSurface9_Release(pSurface2
);
1272 if(pSurface3
) IDirect3DSurface9_Release(pSurface3
);
1273 if(pD3d
) IDirect3D9_Release(pD3d
);
1274 if(pDevice
) IDirect3D9_Release(pDevice
);
1275 if(hwnd
) DestroyWindow(hwnd
);
1278 static void test_limits(void)
1282 IDirect3D9
*pD3d
= NULL
;
1283 IDirect3DDevice9
*pDevice
= NULL
;
1284 D3DPRESENT_PARAMETERS d3dpp
;
1285 D3DDISPLAYMODE d3ddm
;
1286 IDirect3DTexture9
*pTexture
= NULL
;
1289 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
1290 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
1291 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1292 ok(hwnd
!= NULL
, "Failed to create window\n");
1293 if (!pD3d
|| !hwnd
) goto cleanup
;
1295 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
1296 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1297 d3dpp
.Windowed
= TRUE
;
1298 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1299 d3dpp
.BackBufferWidth
= 800;
1300 d3dpp
.BackBufferHeight
= 600;
1301 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1302 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1303 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
1305 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1306 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
1307 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1310 skip("Failed to create a d3d device\n");
1314 hr
= IDirect3DDevice9_CreateTexture(pDevice
, 16, 16, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &pTexture
, NULL
);
1315 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture failed with %08x\n", hr
);
1316 if(!pTexture
) goto cleanup
;
1318 /* There are 16 pixel samplers. We should be able to access all of them */
1319 for(i
= 0; i
< 16; i
++) {
1320 hr
= IDirect3DDevice9_SetTexture(pDevice
, i
, (IDirect3DBaseTexture9
*) pTexture
);
1321 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture for sampler %d failed with %08x\n", i
, hr
);
1322 hr
= IDirect3DDevice9_SetTexture(pDevice
, i
, NULL
);
1323 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture for sampler %d failed with %08x\n", i
, hr
);
1324 hr
= IDirect3DDevice9_SetSamplerState(pDevice
, i
, D3DSAMP_SRGBTEXTURE
, TRUE
);
1325 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState for sampler %d failed with %08x\n", i
, hr
);
1328 /* Now test all 8 textures stage states */
1329 for(i
= 0; i
< 8; i
++) {
1330 hr
= IDirect3DDevice9_SetTextureStageState(pDevice
, i
, D3DTSS_COLOROP
, D3DTOP_ADD
);
1331 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState for texture %d failed with %08x\n", i
, hr
);
1334 /* Investigations show that accessing higher samplers / textures stage states does not return an error either. Writing
1335 * to too high samplers(approximately sampler 40) causes memory corruption in windows, so there is no bounds checking
1336 * but how do I test that?
1339 if(pTexture
) IDirect3DTexture9_Release(pTexture
);
1340 if(pD3d
) IDirect3D9_Release(pD3d
);
1341 if(pDevice
) IDirect3D9_Release(pDevice
);
1342 if(hwnd
) DestroyWindow(hwnd
);
1345 static void test_depthstenciltest(void)
1349 IDirect3D9
*pD3d
= NULL
;
1350 IDirect3DDevice9
*pDevice
= NULL
;
1351 D3DPRESENT_PARAMETERS d3dpp
;
1352 D3DDISPLAYMODE d3ddm
;
1353 IDirect3DSurface9
*pDepthStencil
= NULL
;
1354 IDirect3DSurface9
*pDepthStencil2
= NULL
;
1355 D3DZBUFFERTYPE state
;
1357 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
1358 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
1359 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1360 ok(hwnd
!= NULL
, "Failed to create window\n");
1361 if (!pD3d
|| !hwnd
) goto cleanup
;
1363 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
1364 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1365 d3dpp
.Windowed
= TRUE
;
1366 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1367 d3dpp
.BackBufferWidth
= 800;
1368 d3dpp
.BackBufferHeight
= 600;
1369 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1370 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1371 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
1373 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1374 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
1375 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1378 skip("Failed to create a d3d device\n");
1382 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &pDepthStencil
);
1383 ok(hr
== D3D_OK
&& pDepthStencil
!= NULL
, "IDirect3DDevice9_GetDepthStencilSurface failed with %08x\n", hr
);
1386 hr
= IDirect3DDevice9_Clear(pDevice
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0x00000000, 1.0, 0);
1387 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1389 hr
= IDirect3DDevice9_SetDepthStencilSurface(pDevice
, NULL
);
1390 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetDepthStencilSurface failed with %08x\n", hr
);
1392 /* Check if the set buffer is returned on a get. WineD3D had a bug with that once, prevent it from coming back */
1393 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &pDepthStencil2
);
1394 ok(hr
== D3DERR_NOTFOUND
&& pDepthStencil2
== NULL
, "IDirect3DDevice9_GetDepthStencilSurface failed with %08x\n", hr
);
1395 if(pDepthStencil2
) IDirect3DSurface9_Release(pDepthStencil2
);
1397 /* This left the render states untouched! */
1398 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_ZENABLE
, &state
);
1399 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1400 ok(state
== D3DZB_TRUE
, "D3DRS_ZENABLE is %s\n", state
== D3DZB_FALSE
? "D3DZB_FALSE" : (state
== D3DZB_TRUE
? "D3DZB_TRUE" : "D3DZB_USEW"));
1401 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_ZWRITEENABLE
, &state
);
1402 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1403 ok(state
== TRUE
, "D3DRS_ZWRITEENABLE is %s\n", state
? "TRUE" : "FALSE");
1404 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_STENCILENABLE
, &state
);
1405 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1406 ok(state
== FALSE
, "D3DRS_STENCILENABLE is %s\n", state
? "TRUE" : "FALSE");
1407 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_STENCILWRITEMASK
, &state
);
1408 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1409 ok(state
== 0xffffffff, "D3DRS_STENCILWRITEMASK is 0x%08x\n", state
);
1411 /* This is supposed to fail now */
1412 hr
= IDirect3DDevice9_Clear(pDevice
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0x00000000, 1.0, 0);
1413 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1415 hr
= IDirect3DDevice9_SetRenderState(pDevice
, D3DRS_ZENABLE
, D3DZB_FALSE
);
1416 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed with %08x\n", hr
);
1418 hr
= IDirect3DDevice9_SetDepthStencilSurface(pDevice
, pDepthStencil
);
1419 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetDepthStencilSurface failed with %08x\n", hr
);
1421 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_ZENABLE
, &state
);
1422 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1423 ok(state
== D3DZB_FALSE
, "D3DRS_ZENABLE is %s\n", state
== D3DZB_FALSE
? "D3DZB_FALSE" : (state
== D3DZB_TRUE
? "D3DZB_TRUE" : "D3DZB_USEW"));
1425 /* Now it works again */
1426 hr
= IDirect3DDevice9_Clear(pDevice
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0x00000000, 1.0, 0);
1427 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1429 if(pDepthStencil
) IDirect3DSurface9_Release(pDepthStencil
);
1430 if(pDevice
) IDirect3D9_Release(pDevice
);
1432 /* Now see if autodepthstencil disable is honored. First, without a format set */
1433 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1434 d3dpp
.Windowed
= TRUE
;
1435 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1436 d3dpp
.BackBufferWidth
= 800;
1437 d3dpp
.BackBufferHeight
= 600;
1438 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1439 d3dpp
.EnableAutoDepthStencil
= FALSE
;
1440 d3dpp
.AutoDepthStencilFormat
= D3DFMT_UNKNOWN
;
1442 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1443 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
1444 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1447 skip("Failed to create a d3d device\n");
1451 pDepthStencil
= NULL
;
1452 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &pDepthStencil
);
1453 ok(hr
== D3DERR_NOTFOUND
&& pDepthStencil
== NULL
, "IDirect3DDevice9_GetDepthStencilSurface returned %08x, surface = %p\n", hr
, pDepthStencil
);
1455 IDirect3DSurface9_Release(pDepthStencil
);
1456 pDepthStencil
= NULL
;
1459 /* Check the depth test state */
1460 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_ZENABLE
, &state
);
1461 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1462 ok(state
== D3DZB_FALSE
, "D3DRS_ZENABLE is %s\n", state
== D3DZB_FALSE
? "D3DZB_FALSE" : (state
== D3DZB_TRUE
? "D3DZB_TRUE" : "D3DZB_USEW"));
1464 if(pDevice
) IDirect3D9_Release(pDevice
);
1466 /* Next, try EnableAutoDepthStencil FALSE with a depth stencil format set */
1467 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1468 d3dpp
.Windowed
= TRUE
;
1469 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1470 d3dpp
.BackBufferWidth
= 800;
1471 d3dpp
.BackBufferHeight
= 600;
1472 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1473 d3dpp
.EnableAutoDepthStencil
= FALSE
;
1474 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
1476 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1477 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
1478 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1481 skip("Failed to create a d3d device\n");
1485 pDepthStencil
= NULL
;
1486 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &pDepthStencil
);
1487 ok(hr
== D3DERR_NOTFOUND
&& pDepthStencil
== NULL
, "IDirect3DDevice9_GetDepthStencilSurface returned %08x, surface = %p\n", hr
, pDepthStencil
);
1489 IDirect3DSurface9_Release(pDepthStencil
);
1490 pDepthStencil
= NULL
;
1493 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_ZENABLE
, &state
);
1494 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1495 ok(state
== D3DZB_FALSE
, "D3DRS_ZENABLE is %s\n", state
== D3DZB_FALSE
? "D3DZB_FALSE" : (state
== D3DZB_TRUE
? "D3DZB_TRUE" : "D3DZB_USEW"));
1498 if(pDepthStencil
) IDirect3DSurface9_Release(pDepthStencil
);
1499 if(pD3d
) IDirect3D9_Release(pD3d
);
1500 if(pDevice
) IDirect3D9_Release(pDevice
);
1501 if(hwnd
) DestroyWindow(hwnd
);
1504 /* Test what happens when IDirect3DDevice9_DrawIndexedPrimitive is called without a valid index buffer set. */
1505 static void test_draw_indexed(void)
1507 static const struct {
1511 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
1512 {{-1.0f
, 1.0f
, 0.0f
}, 0xffff0000},
1513 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffff0000},
1514 {{ 1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
1516 WORD indices
[] = {0, 1, 2, 3, 0, 2};
1518 static const D3DVERTEXELEMENT9 decl_elements
[] = {
1519 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
1520 {0, 12, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
1524 IDirect3DVertexDeclaration9
*vertex_declaration
= NULL
;
1525 IDirect3DVertexBuffer9
*vertex_buffer
= NULL
;
1526 IDirect3DIndexBuffer9
*index_buffer
= NULL
;
1527 D3DPRESENT_PARAMETERS present_parameters
;
1528 IDirect3DDevice9
*device
= NULL
;
1534 hwnd
= CreateWindow("static", "d3d9_test",
1535 0, 0, 0, 10, 10, 0, 0, 0, 0);
1538 skip("Failed to create window\n");
1542 d3d9
= pDirect3DCreate9(D3D_SDK_VERSION
);
1545 skip("Failed to create IDirect3D9 object\n");
1549 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
1550 present_parameters
.Windowed
= TRUE
;
1551 present_parameters
.hDeviceWindow
= hwnd
;
1552 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1554 hr
= IDirect3D9_CreateDevice(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
1555 NULL
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
1556 if (FAILED(hr
) || !device
)
1558 skip("Failed to create device\n");
1562 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &vertex_declaration
);
1563 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (0x%08x)\n", hr
);
1564 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
1565 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed (0x%08x)\n", hr
);
1567 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, sizeof(quad
), 0, 0, D3DPOOL_DEFAULT
, &vertex_buffer
, NULL
);
1568 ok(SUCCEEDED(hr
), "CreateVertexBuffer failed (0x%08x)\n", hr
);
1569 hr
= IDirect3DVertexBuffer9_Lock(vertex_buffer
, 0, 0, &ptr
, D3DLOCK_DISCARD
);
1570 ok(SUCCEEDED(hr
), "Lock failed (0x%08x)\n", hr
);
1571 memcpy(ptr
, quad
, sizeof(quad
));
1572 hr
= IDirect3DVertexBuffer9_Unlock(vertex_buffer
);
1573 ok(SUCCEEDED(hr
), "Unlock failed (0x%08x)\n", hr
);
1574 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vertex_buffer
, 0, sizeof(*quad
));
1575 ok(SUCCEEDED(hr
), "SetStreamSource failed (0x%08x)\n", hr
);
1577 hr
= IDirect3DDevice9_CreateIndexBuffer(device
, sizeof(indices
), 0, D3DFMT_INDEX16
, D3DPOOL_DEFAULT
, &index_buffer
, NULL
);
1578 ok(SUCCEEDED(hr
), "CreateIndexBuffer failed (0x%08x)\n", hr
);
1579 hr
= IDirect3DIndexBuffer9_Lock(index_buffer
, 0, 0, &ptr
, D3DLOCK_DISCARD
);
1580 ok(SUCCEEDED(hr
), "Lock failed (0x%08x)\n", hr
);
1581 memcpy(ptr
, indices
, sizeof(indices
));
1582 hr
= IDirect3DIndexBuffer9_Unlock(index_buffer
);
1583 ok(SUCCEEDED(hr
), "Unlock failed (0x%08x)\n", hr
);
1584 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
1585 ok(SUCCEEDED(hr
), "SetRenderState D3DRS_LIGHTING failed (0x%08x)\n", hr
);
1586 hr
= IDirect3DDevice9_BeginScene(device
);
1587 ok(SUCCEEDED(hr
), "BeginScene failed (0x%08x)\n", hr
);
1589 /* NULL index buffer. Should fail */
1590 hr
= IDirect3DDevice9_SetIndices(device
, NULL
);
1591 ok(SUCCEEDED(hr
), "SetIndices failed (0x%08x)\n", hr
);
1592 hr
= IDirect3DDevice9_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, 0 /* BaseVertexIndex */, 0 /* MinIndex */,
1593 4 /* NumVerts */, 0 /* StartIndex */, 2 /*PrimCount */);
1594 ok(hr
== D3DERR_INVALIDCALL
, "DrawIndexedPrimitive returned 0x%08x, expected D3DERR_INVALIDCALL (0x%08x)\n",
1595 hr
, D3DERR_INVALIDCALL
);
1597 /* Valid index buffer, NULL vertex declaration. Should fail */
1598 hr
= IDirect3DDevice9_SetIndices(device
, index_buffer
);
1599 ok(SUCCEEDED(hr
), "SetIndices failed (0x%08x)\n", hr
);
1600 hr
= IDirect3DDevice9_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, 0 /* BaseVertexIndex */, 0 /* MinIndex */,
1601 4 /* NumVerts */, 0 /* StartIndex */, 2 /*PrimCount */);
1602 ok(hr
== D3DERR_INVALIDCALL
, "DrawIndexedPrimitive returned 0x%08x, expected D3DERR_INVALIDCALL (0x%08x)\n",
1603 hr
, D3DERR_INVALIDCALL
);
1605 /* Valid index buffer and vertex declaration. Should succeed */
1606 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, vertex_declaration
);
1607 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed (0x%08x)\n", hr
);
1608 hr
= IDirect3DDevice9_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, 0 /* BaseVertexIndex */, 0 /* MinIndex */,
1609 4 /* NumVerts */, 0 /* StartIndex */, 2 /*PrimCount */);
1610 ok(SUCCEEDED(hr
), "DrawIndexedPrimitive failed (0x%08x)\n", hr
);
1612 hr
= IDirect3DDevice9_EndScene(device
);
1613 ok(SUCCEEDED(hr
), "EndScene failed (0x%08x)\n", hr
);
1615 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
1616 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
1618 IDirect3DVertexBuffer9_Release(vertex_buffer
);
1619 IDirect3DIndexBuffer9_Release(index_buffer
);
1620 IDirect3DVertexDeclaration9_Release(vertex_declaration
);
1623 if (d3d9
) IDirect3D9_Release(d3d9
);
1624 if (device
) IDirect3DDevice9_Release(device
);
1625 if (hwnd
) DestroyWindow(hwnd
);
1628 static void test_null_stream(void)
1630 IDirect3DVertexBuffer9
*buffer
= NULL
;
1631 D3DPRESENT_PARAMETERS present_parameters
;
1632 IDirect3DDevice9
*device
= NULL
;
1636 IDirect3DVertexShader9
*shader
= NULL
;
1637 IDirect3DVertexDeclaration9
*decl
= NULL
;
1638 DWORD shader_code
[] = {
1639 0xfffe0101, /* vs_1_1 */
1640 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
1641 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
1642 0x0000ffff /* end */
1644 static const D3DVERTEXELEMENT9 decl_elements
[] = {
1645 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
1646 {1, 0, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
1650 d3d9
= pDirect3DCreate9( D3D_SDK_VERSION
);
1651 ok(d3d9
!= NULL
, "Failed to create IDirect3D9 object\n");
1652 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1653 ok(hwnd
!= NULL
, "Failed to create window\n");
1654 if (!d3d9
|| !hwnd
) goto cleanup
;
1656 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
1657 present_parameters
.Windowed
= TRUE
;
1658 present_parameters
.hDeviceWindow
= hwnd
;
1659 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1661 hr
= IDirect3D9_CreateDevice( d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1662 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
1663 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1666 skip("Failed to create a d3d device\n");
1670 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_code
, &shader
);
1672 skip("No vertex shader support\n");
1675 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &decl
);
1676 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateVertexDeclaration failed (0x%08x)\n", hr
);
1678 skip("Vertex declaration handling not possible.\n");
1681 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, 12 * sizeof(float), 0, 0, D3DPOOL_MANAGED
, &buffer
, NULL
);
1682 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateVertexBuffer failed (0x%08x)\n", hr
);
1684 skip("Vertex buffer handling not possible.\n");
1688 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, buffer
, 0, sizeof(float) * 3);
1689 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetStreamSource failed (0x%08x)\n", hr
);
1690 hr
= IDirect3DDevice9_SetStreamSource(device
, 1, NULL
, 0, 0);
1691 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetStreamSource failed (0x%08x)\n", hr
);
1692 hr
= IDirect3DDevice9_SetVertexShader(device
, shader
);
1693 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShader failed (0x%08x)\n", hr
);
1694 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl
);
1695 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexDeclaration failed (0x%08x)\n", hr
);
1697 hr
= IDirect3DDevice9_BeginScene(device
);
1698 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed (0x%08x)\n", hr
);
1700 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_POINTLIST
, 0, 1);
1701 ok(SUCCEEDED(hr
), "IDirect3DDevice9_DrawPrimitive failed (0x%08x)\n", hr
);
1703 hr
= IDirect3DDevice9_EndScene(device
);
1704 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed (0x%08x)\n", hr
);
1707 IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 0, 0);
1708 IDirect3DDevice9_SetVertexShader(device
, NULL
);
1709 IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
1712 if(decl
) IDirect3DVertexDeclaration9_Release(decl
);
1713 if(shader
) IDirect3DVertexShader9_Release(shader
);
1714 if(device
) IDirect3DDevice9_Release(device
);
1715 if(d3d9
) IDirect3D9_Release(d3d9
);
1718 static inline const char *debug_d3dpool(D3DPOOL pool
) {
1720 case D3DPOOL_DEFAULT
: return "D3DPOOL_DEFAULT";
1721 case D3DPOOL_SYSTEMMEM
: return "D3DPOOL_SYSTEMMEM";
1722 case D3DPOOL_SCRATCH
: return "D3DPOOL_SCRATCH";
1723 case D3DPOOL_MANAGED
: return "D3DPOOL_MANAGED";
1725 return "unknown pool";
1729 static void test_vertex_buffer_alignment(void)
1731 IDirect3DVertexBuffer9
*buffer
= NULL
;
1732 D3DPRESENT_PARAMETERS present_parameters
;
1733 IDirect3DDevice9
*device
= NULL
;
1737 D3DPOOL pools
[] = {D3DPOOL_DEFAULT
, D3DPOOL_SYSTEMMEM
, D3DPOOL_SCRATCH
, D3DPOOL_MANAGED
};
1738 DWORD sizes
[] = {1, 4, 16, 17, 32, 33, 64, 65, 1024, 1025, 1048576, 1048577};
1742 d3d9
= pDirect3DCreate9( D3D_SDK_VERSION
);
1743 ok(d3d9
!= NULL
, "Failed to create IDirect3D9 object\n");
1744 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1745 ok(hwnd
!= NULL
, "Failed to create window\n");
1746 if (!d3d9
|| !hwnd
) goto cleanup
;
1748 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
1749 present_parameters
.Windowed
= TRUE
;
1750 present_parameters
.hDeviceWindow
= hwnd
;
1751 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1753 hr
= IDirect3D9_CreateDevice( d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1754 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
1755 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1758 skip("Failed to create a d3d device\n");
1762 for(i
= 0; i
< (sizeof(sizes
) / sizeof(sizes
[0])); i
++) {
1763 for(j
= 0; j
< (sizeof(pools
) / sizeof(pools
[0])); j
++) {
1764 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, sizes
[i
], 0, 0, pools
[j
], &buffer
, NULL
);
1765 if(pools
[j
] == D3DPOOL_SCRATCH
) {
1766 ok(hr
== D3DERR_INVALIDCALL
, "Creating a D3DPOOL_SCRATCH buffer returned (0x%08x)\n", hr
);
1768 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateVertexBuffer failed (0x%08x). Pool = %s, size %d\n", hr
,
1769 debug_d3dpool(pools
[j
]), sizes
[i
]);
1771 if(FAILED(hr
)) continue;
1773 hr
= IDirect3DVertexBuffer9_Lock(buffer
, 0, 0, (void **) &data
, 0);
1774 ok(SUCCEEDED(hr
), "IDirect3DVertexBuffer9_Lock failed (0x%08x)\n", hr
);
1775 ok(((DWORD_PTR
) data
& 31) == 0, "Vertex buffer start address is not 32 byte aligned(size: %d, pool: %s, data: %p)\n",
1776 sizes
[i
], debug_d3dpool(pools
[j
]), data
);
1777 hr
= IDirect3DVertexBuffer9_Unlock(buffer
);
1778 ok(SUCCEEDED(hr
), "IDirect3DVertexBuffer9_Unlock failed (0x%08x)\n", hr
);
1780 if(buffer
) IDirect3DVertexBuffer9_Release(buffer
);
1785 if(d3d9
) IDirect3D9_Release(d3d9
);
1788 static void test_lights(void)
1790 D3DPRESENT_PARAMETERS present_parameters
;
1791 IDirect3DDevice9
*device
= NULL
;
1799 d3d9
= pDirect3DCreate9( D3D_SDK_VERSION
);
1800 ok(d3d9
!= NULL
, "Failed to create IDirect3D9 object\n");
1801 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1802 ok(hwnd
!= NULL
, "Failed to create window\n");
1803 if (!d3d9
|| !hwnd
) goto cleanup
;
1805 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
1806 present_parameters
.Windowed
= TRUE
;
1807 present_parameters
.hDeviceWindow
= hwnd
;
1808 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1810 hr
= IDirect3D9_CreateDevice( d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
1811 D3DCREATE_HARDWARE_VERTEXPROCESSING
| D3DCREATE_PUREDEVICE
, &present_parameters
, &device
);
1812 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
|| hr
== D3DERR_INVALIDCALL
,
1813 "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1816 skip("Failed to create a d3d device\n");
1820 memset(&caps
, 0, sizeof(caps
));
1821 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
1822 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetDeviceCaps failed with %08x\n", hr
);
1824 for(i
= 1; i
<= caps
.MaxActiveLights
; i
++) {
1825 hr
= IDirect3DDevice9_LightEnable(device
, i
, TRUE
);
1826 ok(hr
== D3D_OK
, "Enabling light %u failed with %08x\n", i
, hr
);
1827 hr
= IDirect3DDevice9_GetLightEnable(device
, i
, &enabled
);
1828 ok(hr
== D3D_OK
, "GetLightEnable on light %u failed with %08x\n", i
, hr
);
1829 ok(enabled
, "Light %d is %s\n", i
, enabled
? "enabled" : "disabled");
1832 /* TODO: Test the rendering results in this situation */
1833 hr
= IDirect3DDevice9_LightEnable(device
, i
+ 1, TRUE
);
1834 ok(hr
== D3D_OK
, "Enabling one light more than supported returned %08x\n", hr
);
1835 hr
= IDirect3DDevice9_GetLightEnable(device
, i
+ 1, &enabled
);
1836 ok(hr
== D3D_OK
, "GetLightEnable on light %u failed with %08x\n", i
+ 1, hr
);
1837 ok(enabled
, "Light %d is %s\n", i
+ 1, enabled
? "enabled" : "disabled");
1838 hr
= IDirect3DDevice9_LightEnable(device
, i
+ 1, FALSE
);
1839 ok(hr
== D3D_OK
, "Disabling the additional returned %08x\n", hr
);
1841 for(i
= 1; i
<= caps
.MaxActiveLights
; i
++) {
1842 hr
= IDirect3DDevice9_LightEnable(device
, i
, FALSE
);
1843 ok(hr
== D3D_OK
, "Disabling light %u failed with %08x\n", i
, hr
);
1847 if(device
) IDirect3DDevice9_Release(device
);
1848 if(d3d9
) IDirect3D9_Release(d3d9
);
1851 static void test_set_stream_source(void)
1853 D3DPRESENT_PARAMETERS present_parameters
;
1854 IDirect3DDevice9
*device
= NULL
;
1858 IDirect3DVertexBuffer9
*pVertexBuffer
= NULL
;
1860 d3d9
= pDirect3DCreate9( D3D_SDK_VERSION
);
1861 ok(d3d9
!= NULL
, "Failed to create IDirect3D9 object\n");
1862 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1863 ok(hwnd
!= NULL
, "Failed to create window\n");
1864 if (!d3d9
|| !hwnd
) goto cleanup
;
1866 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
1867 present_parameters
.Windowed
= TRUE
;
1868 present_parameters
.hDeviceWindow
= hwnd
;
1869 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1871 hr
= IDirect3D9_CreateDevice( d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
1872 D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
1873 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
|| hr
== D3DERR_INVALIDCALL
,
1874 "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1877 hr
= IDirect3D9_CreateDevice( d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_REF
, hwnd
,
1878 D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
1879 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1882 skip("Failed to create a d3d device\n");
1887 hr
= IDirect3DDevice9_CreateVertexBuffer( device
, 512, 0, 0, D3DPOOL_DEFAULT
, &pVertexBuffer
, NULL
);
1888 ok(hr
== D3D_OK
, "Failed to create a vertex buffer, hr = %08x\n", hr
);
1889 if (SUCCEEDED(hr
)) {
1890 /* Some cards(Geforce 7400 at least) accept non-aligned offsets, others(radeon 9000 verified) reject it,
1891 * so accept both results. Wine currently rejects this to be able to optimize the vbo conversion, but writes
1894 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, pVertexBuffer
, 0, 32);
1895 ok(hr
== D3D_OK
, "Failed to set the stream source, offset 0, hr = %08x\n", hr
);
1896 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, pVertexBuffer
, 1, 32);
1897 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Unexpected result when setting the stream source, offset 1, hr = %08x\n", hr
);
1898 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, pVertexBuffer
, 2, 32);
1899 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Unexpected result when setting the stream source, offset 2, hr = %08x\n", hr
);
1900 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, pVertexBuffer
, 3, 32);
1901 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Unexpected result when setting the stream source, offset 3, hr = %08x\n", hr
);
1902 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, pVertexBuffer
, 4, 32);
1903 ok(hr
== D3D_OK
, "Failed to set the stream source, offset 4, hr = %08x\n", hr
);
1905 /* Try to set the NULL buffer with an offset and stride 0 */
1906 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 0, 0);
1907 ok(hr
== D3D_OK
, "Failed to set the stream source, offset 0, hr = %08x\n", hr
);
1908 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 1, 0);
1909 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Unexpected result when setting the stream source, offset 1, hr = %08x\n", hr
);
1910 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 2, 0);
1911 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Unexpected result when setting the stream source, offset 2, hr = %08x\n", hr
);
1912 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 3, 0);
1913 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Unexpected result when setting the stream source, offset 3, hr = %08x\n", hr
);
1914 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 4, 0);
1915 ok(hr
== D3D_OK
, "Failed to set the stream source, offset 4, hr = %08x\n", hr
);
1917 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 0, 0);
1918 ok(hr
== D3D_OK
, "Failed to set the stream source, offset 4, hr = %08x\n", hr
);
1920 if(pVertexBuffer
) IDirect3DDevice9_Release(pVertexBuffer
);
1922 if(device
) IDirect3DDevice9_Release(device
);
1923 if(d3d9
) IDirect3D9_Release(d3d9
);
1927 D3DFORMAT DisplayFormat
;
1928 D3DFORMAT BackBufferFormat
;
1932 struct formats r5g6b5_format_list
[] =
1934 { D3DFMT_R5G6B5
, D3DFMT_R5G6B5
, TRUE
},
1935 { D3DFMT_R5G6B5
, D3DFMT_X1R5G5B5
, FALSE
},
1936 { D3DFMT_R5G6B5
, D3DFMT_A1R5G5B5
, FALSE
},
1937 { D3DFMT_R5G6B5
, D3DFMT_X8R8G8B8
, FALSE
},
1938 { D3DFMT_R5G6B5
, D3DFMT_A8R8G8B8
, FALSE
},
1942 struct formats x1r5g5b5_format_list
[] =
1944 { D3DFMT_X1R5G5B5
, D3DFMT_R5G6B5
, FALSE
},
1945 { D3DFMT_X1R5G5B5
, D3DFMT_X1R5G5B5
, TRUE
},
1946 { D3DFMT_X1R5G5B5
, D3DFMT_A1R5G5B5
, TRUE
},
1947 { D3DFMT_X1R5G5B5
, D3DFMT_X8R8G8B8
, FALSE
},
1948 { D3DFMT_X1R5G5B5
, D3DFMT_A8R8G8B8
, FALSE
},
1950 /* A1R5G5B5 should not be usable as a display format, it is backbuffer-only */
1951 { D3DFMT_A1R5G5B5
, D3DFMT_R5G6B5
, FALSE
},
1952 { D3DFMT_A1R5G5B5
, D3DFMT_X1R5G5B5
, FALSE
},
1953 { D3DFMT_A1R5G5B5
, D3DFMT_A1R5G5B5
, FALSE
},
1954 { D3DFMT_A1R5G5B5
, D3DFMT_X8R8G8B8
, FALSE
},
1955 { D3DFMT_A1R5G5B5
, D3DFMT_A8R8G8B8
, FALSE
},
1959 struct formats x8r8g8b8_format_list
[] =
1961 { D3DFMT_X8R8G8B8
, D3DFMT_R5G6B5
, FALSE
},
1962 { D3DFMT_X8R8G8B8
, D3DFMT_X1R5G5B5
, FALSE
},
1963 { D3DFMT_X8R8G8B8
, D3DFMT_A1R5G5B5
, FALSE
},
1964 { D3DFMT_X8R8G8B8
, D3DFMT_X8R8G8B8
, TRUE
},
1965 { D3DFMT_X8R8G8B8
, D3DFMT_A8R8G8B8
, TRUE
},
1967 /* A1R8G8B8 should not be usable as a display format, it is backbuffer-only */
1968 { D3DFMT_A8R8G8B8
, D3DFMT_R5G6B5
, FALSE
},
1969 { D3DFMT_A8R8G8B8
, D3DFMT_X1R5G5B5
, FALSE
},
1970 { D3DFMT_A8R8G8B8
, D3DFMT_A1R5G5B5
, FALSE
},
1971 { D3DFMT_A8R8G8B8
, D3DFMT_X8R8G8B8
, FALSE
},
1972 { D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
, FALSE
},
1976 static void test_display_formats()
1978 /* Direct3D9 offers 4 display formats R5G6B5, X1R5G5B5, X8R8G8B8 and A2R10G10B10.
1979 * Next to these there are 6 different backbuffer formats. Only a fixed number of
1980 * combinations are possible in FULLSCREEN mode. In windowed mode more combinations are
1981 * allowed due to depth conversion and this is likely driver dependent.
1982 * This test checks which combinations are possible in fullscreen mode and this should not be driver dependent.
1983 * TODO: handle A2R10G10B10 but what hardware supports it? Parhelia? It is very rare. */
1985 UINT Adapter
= D3DADAPTER_DEFAULT
;
1986 D3DDEVTYPE DeviceType
= D3DDEVTYPE_HAL
;
1990 IDirect3D9
*d3d9
= pDirect3DCreate9( D3D_SDK_VERSION
);
1991 ok(d3d9
!= NULL
, "Failed to create IDirect3D9 object\n");
1994 nmodes
= IDirect3D9_GetAdapterModeCount(d3d9
, D3DADAPTER_DEFAULT
, D3DFMT_R5G6B5
);
1996 skip("Display format R5G6B5 not supported, skipping\n");
1998 trace("Testing display format R5G6B5\n");
1999 for(i
=0; r5g6b5_format_list
[i
].DisplayFormat
!= 0; i
++)
2001 hr
= IDirect3D9_CheckDeviceType(d3d9
, Adapter
, DeviceType
, r5g6b5_format_list
[i
].DisplayFormat
, r5g6b5_format_list
[i
].BackBufferFormat
, FALSE
);
2003 if(r5g6b5_format_list
[i
].shouldPass
)
2005 broken(hr
== D3DERR_NOTAVAILABLE
),
2006 "format %d %d didn't pass with hr=%#08x\n", r5g6b5_format_list
[i
].DisplayFormat
, r5g6b5_format_list
[i
].BackBufferFormat
, hr
);
2008 ok(hr
!= D3D_OK
, "format %d %d didn't pass while it was expected to\n", r5g6b5_format_list
[i
].DisplayFormat
, r5g6b5_format_list
[i
].BackBufferFormat
);
2012 nmodes
= IDirect3D9_GetAdapterModeCount(d3d9
, D3DADAPTER_DEFAULT
, D3DFMT_X1R5G5B5
);
2014 skip("Display format X1R5G5B5 not supported, skipping\n");
2016 trace("Testing display format X1R5G5B5\n");
2017 for(i
=0; x1r5g5b5_format_list
[i
].DisplayFormat
!= 0; i
++)
2019 hr
= IDirect3D9_CheckDeviceType(d3d9
, Adapter
, DeviceType
, x1r5g5b5_format_list
[i
].DisplayFormat
, x1r5g5b5_format_list
[i
].BackBufferFormat
, FALSE
);
2021 if(x1r5g5b5_format_list
[i
].shouldPass
)
2022 ok(hr
== D3D_OK
, "format %d %d didn't pass with hr=%#08x\n", x1r5g5b5_format_list
[i
].DisplayFormat
, x1r5g5b5_format_list
[i
].BackBufferFormat
, hr
);
2024 ok(hr
!= D3D_OK
, "format %d %d didn't pass while it was expected to\n", x1r5g5b5_format_list
[i
].DisplayFormat
, x1r5g5b5_format_list
[i
].BackBufferFormat
);
2028 nmodes
= IDirect3D9_GetAdapterModeCount(d3d9
, D3DADAPTER_DEFAULT
, D3DFMT_X8R8G8B8
);
2030 skip("Display format X8R8G8B8 not supported, skipping\n");
2032 trace("Testing display format X8R8G8B8\n");
2033 for(i
=0; x8r8g8b8_format_list
[i
].DisplayFormat
!= 0; i
++)
2035 hr
= IDirect3D9_CheckDeviceType(d3d9
, Adapter
, DeviceType
, x8r8g8b8_format_list
[i
].DisplayFormat
, x8r8g8b8_format_list
[i
].BackBufferFormat
, FALSE
);
2037 if(x8r8g8b8_format_list
[i
].shouldPass
)
2039 broken(hr
== D3DERR_NOTAVAILABLE
),
2040 "format %d %d didn't pass with hr=%#08x\n", x8r8g8b8_format_list
[i
].DisplayFormat
, x8r8g8b8_format_list
[i
].BackBufferFormat
, hr
);
2042 ok(hr
!= D3D_OK
, "format %d %d didn't pass while it was expected to\n", x8r8g8b8_format_list
[i
].DisplayFormat
, x8r8g8b8_format_list
[i
].BackBufferFormat
);
2046 if(d3d9
) IDirect3D9_Release(d3d9
);
2049 static void test_scissor_size(void)
2051 IDirect3D9
*d3d9_ptr
= 0;
2053 static const struct {
2054 int winx
; int winy
; int backx
; int backy
; BOOL window
;
2055 } scts
[] = { /* scissor tests */
2056 {800, 600, 640, 480, TRUE
},
2057 {800, 600, 640, 480, FALSE
},
2058 {640, 480, 800, 600, TRUE
},
2059 {640, 480, 800, 600, FALSE
},
2062 d3d9_ptr
= pDirect3DCreate9(D3D_SDK_VERSION
);
2063 ok(d3d9_ptr
!= NULL
, "Failed to create IDirect3D9 object\n");
2065 skip("Failed to create IDirect3D9 object\n");
2069 for(i
=0; i
<sizeof(scts
)/sizeof(scts
[0]); i
++) {
2070 IDirect3DDevice9
*device_ptr
= 0;
2071 D3DPRESENT_PARAMETERS present_parameters
;
2077 wc
.lpfnWndProc
= DefWindowProc
;
2078 wc
.lpszClassName
= "d3d9_test_wc";
2081 hwnd
= CreateWindow("d3d9_test_wc", "d3d9_test",
2082 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, scts
[i
].winx
, scts
[i
].winy
, 0, 0, 0, 0);
2084 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
2085 present_parameters
.Windowed
= scts
[i
].window
;
2086 present_parameters
.hDeviceWindow
= hwnd
;
2087 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2088 present_parameters
.BackBufferWidth
= scts
[i
].backx
;
2089 present_parameters
.BackBufferHeight
= scts
[i
].backy
;
2090 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
2091 present_parameters
.EnableAutoDepthStencil
= TRUE
;
2092 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
2094 hr
= IDirect3D9_CreateDevice(d3d9_ptr
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, present_parameters
.hDeviceWindow
, D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device_ptr
);
2096 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D16
;
2097 hr
= IDirect3D9_CreateDevice(d3d9_ptr
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, present_parameters
.hDeviceWindow
, D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device_ptr
);
2099 hr
= IDirect3D9_CreateDevice(d3d9_ptr
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, present_parameters
.hDeviceWindow
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device_ptr
);
2102 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D_CreateDevice returned: %08x\n", hr
);
2106 DestroyWindow(hwnd
);
2107 skip("Creating the device failed\n");
2111 /* Check for the default scissor rect size */
2112 hr
= IDirect3DDevice9_GetScissorRect(device_ptr
, &scissorrect
);
2113 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetScissorRect failed with: %08x\n", hr
);
2114 ok(scissorrect
.right
== scts
[i
].backx
&& scissorrect
.bottom
== scts
[i
].backy
&& scissorrect
.top
== 0 && scissorrect
.left
== 0, "Scissorrect missmatch (%d, %d) should be (%d, %d)\n", scissorrect
.right
, scissorrect
.bottom
, scts
[i
].backx
, scts
[i
].backy
);
2116 /* check the scissorrect values after a reset */
2117 present_parameters
.BackBufferWidth
= 1024;
2118 present_parameters
.BackBufferHeight
= 768;
2119 hr
= IDirect3DDevice9_Reset(device_ptr
, &present_parameters
);
2120 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
2121 hr
= IDirect3DDevice9_TestCooperativeLevel(device_ptr
);
2122 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
2124 hr
= IDirect3DDevice9_GetScissorRect(device_ptr
, &scissorrect
);
2125 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetScissorRect failed with: %08x\n", hr
);
2126 ok(scissorrect
.right
== 1024 && scissorrect
.bottom
== 768 && scissorrect
.top
== 0 && scissorrect
.left
== 0, "Scissorrect missmatch (%d, %d) should be (%d, %d)\n", scissorrect
.right
, scissorrect
.bottom
, 1024, 768);
2131 ref
= IDirect3DDevice9_Release(device_ptr
);
2132 DestroyWindow(hwnd
);
2133 ok(ref
== 0, "The device was not properly freed: refcount %u\n", ref
);
2138 if(d3d9_ptr
) IDirect3D9_Release(d3d9_ptr
);
2145 HMODULE d3d9_handle
= LoadLibraryA( "d3d9.dll" );
2148 skip("Could not load d3d9.dll\n");
2152 pDirect3DCreate9
= (void *)GetProcAddress( d3d9_handle
, "Direct3DCreate9" );
2153 ok(pDirect3DCreate9
!= NULL
, "Failed to get address of Direct3DCreate9\n");
2154 if (pDirect3DCreate9
)
2156 IDirect3D9
*d3d9
= pDirect3DCreate9( D3D_SDK_VERSION
);
2159 skip("could not create D3D9 object\n");
2162 IDirect3D9_Release(d3d9
);
2164 test_display_formats();
2165 test_display_modes();
2168 test_mipmap_levels();
2173 test_depthstenciltest();
2174 test_draw_indexed();
2176 test_vertex_buffer_alignment();
2178 test_set_stream_source();
2179 test_scissor_size();