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(IDirect3DDevice9
*device
, UINT width
, UINT height
, UINT count
)
84 IDirect3DBaseTexture9
* texture
= NULL
;
85 HRESULT hr
= IDirect3DDevice9_CreateTexture( device
, width
, height
, 0, 0,
86 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, (IDirect3DTexture9
**) &texture
, NULL
);
89 DWORD levels
= IDirect3DBaseTexture9_GetLevelCount(texture
);
90 ok(levels
== count
, "Invalid level count. Expected %d got %u\n", count
, levels
);
92 trace("CreateTexture failed: %08x\n", hr
);
94 if (texture
) IUnknown_Release( texture
);
97 static void test_mipmap_levels(void)
103 IDirect3D9
*pD3d
= NULL
;
104 IDirect3DDevice9
*pDevice
= NULL
;
105 D3DPRESENT_PARAMETERS d3dpp
;
106 D3DDISPLAYMODE d3ddm
;
108 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
109 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
110 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
111 ok(hwnd
!= NULL
, "Failed to create window\n");
112 if (!pD3d
|| !hwnd
) goto cleanup
;
114 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
115 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
116 d3dpp
.Windowed
= TRUE
;
117 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
118 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
120 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_NULLREF
, hwnd
,
121 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
122 ok(SUCCEEDED(hr
) || hr
== D3DERR_NOTAVAILABLE
, "Failed to create IDirect3D9Device (%08x)\n", hr
);
124 skip("failed to create a d3d device\n");
128 check_mipmap_levels(pDevice
, 32, 32, 6);
129 check_mipmap_levels(pDevice
, 256, 1, 9);
130 check_mipmap_levels(pDevice
, 1, 256, 9);
131 check_mipmap_levels(pDevice
, 1, 1, 1);
134 if (pD3d
) IUnknown_Release( pD3d
);
135 if (pDevice
) IUnknown_Release( pDevice
);
136 DestroyWindow( hwnd
);
139 static void test_checkdevicemultisampletype(void)
145 IDirect3D9
*pD3d
= NULL
;
146 IDirect3DDevice9
*pDevice
= NULL
;
147 D3DPRESENT_PARAMETERS d3dpp
;
148 D3DDISPLAYMODE d3ddm
;
151 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
152 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
153 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
154 ok(hwnd
!= NULL
, "Failed to create window\n");
155 if (!pD3d
|| !hwnd
) goto cleanup
;
157 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
158 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
159 d3dpp
.Windowed
= TRUE
;
160 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
161 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
163 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_NULLREF
, hwnd
,
164 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
165 ok(SUCCEEDED(hr
) || hr
== D3DERR_NOTAVAILABLE
, "Failed to create IDirect3D9Device (%08x)\n", hr
);
167 skip("failed to create a d3d device\n");
173 hr
= IDirect3D9_CheckDeviceMultiSampleType(pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
, TRUE
,
174 D3DMULTISAMPLE_NONE
, &qualityLevels
);
175 ok(SUCCEEDED(hr
) || hr
== D3DERR_NOTAVAILABLE
, "CheckDeviceMultiSampleType failed with (%08x)\n", hr
);
176 if(hr
== D3DERR_NOTAVAILABLE
)
178 skip("IDirect3D9_CheckDeviceMultiSampleType not available\n");
181 ok(qualityLevels
== 1,"qualitylevel is not 1 but %d\n",qualityLevels
);
183 hr
= IDirect3D9_CheckDeviceMultiSampleType(pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
, FALSE
,
184 D3DMULTISAMPLE_NONE
, &qualityLevels
);
185 ok(SUCCEEDED(hr
), "CheckDeviceMultiSampleType failed with (%08x)\n", hr
);
186 ok(qualityLevels
== 1,"qualitylevel is not 1 but %d\n",qualityLevels
);
189 if (pD3d
) IUnknown_Release( pD3d
);
190 if (pDevice
) IUnknown_Release( pDevice
);
191 DestroyWindow( hwnd
);
194 static void test_swapchain(void)
198 IDirect3D9
*pD3d
= NULL
;
199 IDirect3DDevice9
*pDevice
= NULL
;
200 IDirect3DSwapChain9
*swapchain0
= NULL
;
201 IDirect3DSwapChain9
*swapchain1
= NULL
;
202 IDirect3DSwapChain9
*swapchain2
= NULL
;
203 IDirect3DSwapChain9
*swapchain3
= NULL
;
204 IDirect3DSwapChain9
*swapchainX
= NULL
;
205 IDirect3DSurface9
*backbuffer
= NULL
;
206 D3DPRESENT_PARAMETERS d3dpp
;
207 D3DDISPLAYMODE d3ddm
;
209 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
210 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
211 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
212 ok(hwnd
!= NULL
, "Failed to create window\n");
213 if (!pD3d
|| !hwnd
) goto cleanup
;
215 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
216 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
217 d3dpp
.Windowed
= TRUE
;
218 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
219 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
220 d3dpp
.BackBufferCount
= 0;
222 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
223 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
224 ok(hr
== S_OK
|| hr
== D3DERR_NOTAVAILABLE
,
225 "Failed to create IDirect3D9Device (%08x)\n", hr
);
226 if (FAILED(hr
)) goto cleanup
;
228 /* Check if the back buffer count was modified */
229 ok(d3dpp
.BackBufferCount
== 1, "The back buffer count in the presentparams struct is %d\n", d3dpp
.BackBufferCount
);
231 /* Get the implicit swapchain */
232 hr
= IDirect3DDevice9_GetSwapChain(pDevice
, 0, &swapchain0
);
233 ok(SUCCEEDED(hr
), "Failed to get the impicit swapchain (%08x)\n", hr
);
234 if(swapchain0
) IDirect3DSwapChain9_Release(swapchain0
);
236 /* Check if there is a back buffer */
237 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain0
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
238 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
239 ok(backbuffer
!= NULL
, "The back buffer is NULL\n");
240 if(backbuffer
) IDirect3DSurface9_Release(backbuffer
);
242 /* Try to get a nonexistent swapchain */
243 hr
= IDirect3DDevice9_GetSwapChain(pDevice
, 1, &swapchainX
);
244 ok(hr
== D3DERR_INVALIDCALL
, "GetSwapChain on an nonexistent swapchain returned (%08x)\n", hr
);
245 ok(swapchainX
== NULL
, "Swapchain 1 is %p\n", swapchainX
);
246 if(swapchainX
) IDirect3DSwapChain9_Release(swapchainX
);
248 /* Create a bunch of swapchains */
249 d3dpp
.BackBufferCount
= 0;
250 hr
= IDirect3DDevice9_CreateAdditionalSwapChain(pDevice
, &d3dpp
, &swapchain1
);
251 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%08x)\n", hr
);
252 ok(d3dpp
.BackBufferCount
== 1, "The back buffer count in the presentparams struct is %d\n", d3dpp
.BackBufferCount
);
254 d3dpp
.BackBufferCount
= 1;
255 hr
= IDirect3DDevice9_CreateAdditionalSwapChain(pDevice
, &d3dpp
, &swapchain2
);
256 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%08x)\n", hr
);
258 d3dpp
.BackBufferCount
= 2;
259 hr
= IDirect3DDevice9_CreateAdditionalSwapChain(pDevice
, &d3dpp
, &swapchain3
);
260 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%08x)\n", hr
);
262 /* Swapchain 3, created with backbuffercount 2 */
263 backbuffer
= (void *) 0xdeadbeef;
264 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain3
, 0, 0, &backbuffer
);
265 ok(SUCCEEDED(hr
), "Failed to get the 1st back buffer (%08x)\n", hr
);
266 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
267 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
269 backbuffer
= (void *) 0xdeadbeef;
270 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain3
, 1, 0, &backbuffer
);
271 ok(SUCCEEDED(hr
), "Failed to get the 2nd back buffer (%08x)\n", hr
);
272 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
273 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
275 backbuffer
= (void *) 0xdeadbeef;
276 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain3
, 2, 0, &backbuffer
);
277 ok(hr
== D3DERR_INVALIDCALL
, "GetBackBuffer returned %08x\n", hr
);
278 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
279 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
281 backbuffer
= (void *) 0xdeadbeef;
282 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain3
, 3, 0, &backbuffer
);
283 ok(FAILED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
284 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
285 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
288 /* Check the back buffers of the swapchains */
289 /* Swapchain 1, created with backbuffercount 0 */
290 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain1
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
291 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
292 ok(backbuffer
!= NULL
, "The back buffer is NULL (%08x)\n", hr
);
293 if(backbuffer
) IDirect3DSurface9_Release(backbuffer
);
295 backbuffer
= (void *) 0xdeadbeef;
296 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain1
, 1, 0, &backbuffer
);
297 ok(FAILED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
298 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
299 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
301 /* Swapchain 2 - created with backbuffercount 1 */
302 backbuffer
= (void *) 0xdeadbeef;
303 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain2
, 0, 0, &backbuffer
);
304 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
305 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
306 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
308 backbuffer
= (void *) 0xdeadbeef;
309 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain2
, 1, 0, &backbuffer
);
310 ok(hr
== D3DERR_INVALIDCALL
, "GetBackBuffer returned %08x\n", hr
);
311 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
312 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
314 backbuffer
= (void *) 0xdeadbeef;
315 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain2
, 2, 0, &backbuffer
);
316 ok(FAILED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
317 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
318 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
320 /* Try getSwapChain on a manually created swapchain
321 * it should fail, apparently GetSwapChain only returns implicit swapchains
323 swapchainX
= (void *) 0xdeadbeef;
324 hr
= IDirect3DDevice9_GetSwapChain(pDevice
, 1, &swapchainX
);
325 ok(hr
== D3DERR_INVALIDCALL
, "Failed to get the second swapchain (%08x)\n", hr
);
326 ok(swapchainX
== NULL
, "The swapchain pointer is %p\n", swapchainX
);
327 if(swapchainX
&& swapchainX
!= (void *) 0xdeadbeef ) IDirect3DSwapChain9_Release(swapchainX
);
330 if(swapchain1
) IDirect3DSwapChain9_Release(swapchain1
);
331 if(swapchain2
) IDirect3DSwapChain9_Release(swapchain2
);
332 if(swapchain3
) IDirect3DSwapChain9_Release(swapchain3
);
333 if(pDevice
) IDirect3DDevice9_Release(pDevice
);
334 if(pD3d
) IDirect3DDevice9_Release(pD3d
);
335 DestroyWindow( hwnd
);
338 /* Shared between two functions */
339 static const DWORD simple_vs
[] = {0xFFFE0101, /* vs_1_1 */
340 0x0000001F, 0x80000000, 0x900F0000, /* dcl_position0 v0 */
341 0x00000009, 0xC0010000, 0x90E40000, 0xA0E40000, /* dp4 oPos.x, v0, c0 */
342 0x00000009, 0xC0020000, 0x90E40000, 0xA0E40001, /* dp4 oPos.y, v0, c1 */
343 0x00000009, 0xC0040000, 0x90E40000, 0xA0E40002, /* dp4 oPos.z, v0, c2 */
344 0x00000009, 0xC0080000, 0x90E40000, 0xA0E40003, /* dp4 oPos.w, v0, c3 */
345 0x0000FFFF}; /* END */
347 static void test_refcount(void)
351 IDirect3D9
*pD3d
= NULL
;
352 IDirect3DDevice9
*pDevice
= NULL
;
353 IDirect3DVertexBuffer9
*pVertexBuffer
= NULL
;
354 IDirect3DIndexBuffer9
*pIndexBuffer
= NULL
;
355 IDirect3DVertexDeclaration9
*pVertexDeclaration
= NULL
;
356 IDirect3DVertexShader9
*pVertexShader
= NULL
;
357 IDirect3DPixelShader9
*pPixelShader
= NULL
;
358 IDirect3DCubeTexture9
*pCubeTexture
= NULL
;
359 IDirect3DTexture9
*pTexture
= NULL
;
360 IDirect3DVolumeTexture9
*pVolumeTexture
= NULL
;
361 IDirect3DVolume9
*pVolumeLevel
= NULL
;
362 IDirect3DSurface9
*pStencilSurface
= NULL
;
363 IDirect3DSurface9
*pOffscreenSurface
= NULL
;
364 IDirect3DSurface9
*pRenderTarget
= NULL
;
365 IDirect3DSurface9
*pRenderTarget2
= NULL
;
366 IDirect3DSurface9
*pRenderTarget3
= NULL
;
367 IDirect3DSurface9
*pTextureLevel
= NULL
;
368 IDirect3DSurface9
*pBackBuffer
= NULL
;
369 IDirect3DStateBlock9
*pStateBlock
= NULL
;
370 IDirect3DStateBlock9
*pStateBlock1
= NULL
;
371 IDirect3DSwapChain9
*pSwapChain
= NULL
;
372 IDirect3DQuery9
*pQuery
= NULL
;
373 D3DPRESENT_PARAMETERS d3dpp
;
374 D3DDISPLAYMODE d3ddm
;
375 int refcount
= 0, tmp
;
377 D3DVERTEXELEMENT9 decl
[] =
381 static DWORD simple_ps
[] = {0xFFFF0101, /* ps_1_1 */
382 0x00000051, 0xA00F0001, 0x3F800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
383 0x00000042, 0xB00F0000, /* tex t0 */
384 0x00000008, 0x800F0000, 0xA0E40001, 0xA0E40000, /* dp3 r0, c1, c0 */
385 0x00000005, 0x800F0000, 0x90E40000, 0x80E40000, /* mul r0, v0, r0 */
386 0x00000005, 0x800F0000, 0xB0E40000, 0x80E40000, /* mul r0, t0, r0 */
387 0x0000FFFF}; /* END */
390 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
391 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
392 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
393 ok(hwnd
!= NULL
, "Failed to create window\n");
394 if (!pD3d
|| !hwnd
) goto cleanup
;
396 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
397 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
398 d3dpp
.Windowed
= TRUE
;
399 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
400 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
401 d3dpp
.EnableAutoDepthStencil
= TRUE
;
402 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
404 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
405 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
406 ok(hr
== S_OK
|| hr
== D3DERR_NOTAVAILABLE
,
407 "Failed to create IDirect3D9Device (%08x)\n", hr
);
408 if (FAILED(hr
)) goto cleanup
;
410 refcount
= get_refcount( (IUnknown
*)pDevice
);
411 ok(refcount
== 1, "Invalid device RefCount %d\n", refcount
);
414 * Check refcount of implicit surfaces and implicit swapchain. Findings:
415 * - the container is the device OR swapchain
416 * - they hold a reference to the device
417 * - they are created with a refcount of 0 (Get/Release returns original refcount)
418 * - they are not freed if refcount reaches 0.
419 * - the refcount is not forwarded to the container.
421 hr
= IDirect3DDevice9_GetSwapChain(pDevice
, 0, &pSwapChain
);
422 CHECK_CALL( hr
, "GetSwapChain", pDevice
, ++refcount
);
425 CHECK_REFCOUNT( pSwapChain
, 1);
427 hr
= IDirect3DDevice9_GetRenderTarget(pDevice
, 0, &pRenderTarget
);
428 CHECK_CALL( hr
, "GetRenderTarget", pDevice
, ++refcount
);
429 CHECK_REFCOUNT( pSwapChain
, 1);
432 CHECK_SURFACE_CONTAINER( pRenderTarget
, IID_IDirect3DSwapChain9
, pSwapChain
);
433 CHECK_REFCOUNT( pRenderTarget
, 1);
435 CHECK_ADDREF_REFCOUNT(pRenderTarget
, 2);
436 CHECK_REFCOUNT(pDevice
, refcount
);
437 CHECK_RELEASE_REFCOUNT(pRenderTarget
, 1);
438 CHECK_REFCOUNT(pDevice
, refcount
);
440 hr
= IDirect3DDevice9_GetRenderTarget(pDevice
, 0, &pRenderTarget
);
441 CHECK_CALL( hr
, "GetRenderTarget", pDevice
, refcount
);
442 CHECK_REFCOUNT( pRenderTarget
, 2);
443 CHECK_RELEASE_REFCOUNT( pRenderTarget
, 1);
444 CHECK_RELEASE_REFCOUNT( pRenderTarget
, 0);
445 CHECK_REFCOUNT( pDevice
, --refcount
);
447 /* The render target is released with the device, so AddRef with refcount=0 is fine here. */
448 CHECK_ADDREF_REFCOUNT(pRenderTarget
, 1);
449 CHECK_REFCOUNT(pDevice
, ++refcount
);
450 CHECK_RELEASE_REFCOUNT(pRenderTarget
, 0);
451 CHECK_REFCOUNT(pDevice
, --refcount
);
454 /* Render target and back buffer are identical. */
455 hr
= IDirect3DDevice9_GetBackBuffer(pDevice
, 0, 0, 0, &pBackBuffer
);
456 CHECK_CALL( hr
, "GetBackBuffer", pDevice
, ++refcount
);
459 CHECK_RELEASE_REFCOUNT(pBackBuffer
, 0);
460 ok(pRenderTarget
== pBackBuffer
, "RenderTarget=%p and BackBuffer=%p should be the same.\n",
461 pRenderTarget
, pBackBuffer
);
464 CHECK_REFCOUNT( pDevice
, --refcount
);
466 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &pStencilSurface
);
467 CHECK_CALL( hr
, "GetDepthStencilSurface", pDevice
, ++refcount
);
468 CHECK_REFCOUNT( pSwapChain
, 1);
471 CHECK_SURFACE_CONTAINER( pStencilSurface
, IID_IDirect3DDevice9
, pDevice
);
472 CHECK_REFCOUNT( pStencilSurface
, 1);
474 CHECK_ADDREF_REFCOUNT(pStencilSurface
, 2);
475 CHECK_REFCOUNT(pDevice
, refcount
);
476 CHECK_RELEASE_REFCOUNT(pStencilSurface
, 1);
477 CHECK_REFCOUNT(pDevice
, refcount
);
479 CHECK_RELEASE_REFCOUNT( pStencilSurface
, 0);
480 CHECK_REFCOUNT( pDevice
, --refcount
);
482 /* The stencil surface is released with the device, so AddRef with refcount=0 is fine here. */
483 CHECK_ADDREF_REFCOUNT(pStencilSurface
, 1);
484 CHECK_REFCOUNT(pDevice
, ++refcount
);
485 CHECK_RELEASE_REFCOUNT(pStencilSurface
, 0);
486 CHECK_REFCOUNT(pDevice
, --refcount
);
487 pStencilSurface
= NULL
;
490 CHECK_RELEASE_REFCOUNT( pSwapChain
, 0);
491 CHECK_REFCOUNT( pDevice
, --refcount
);
493 /* The implicit swapchwin is released with the device, so AddRef with refcount=0 is fine here. */
494 CHECK_ADDREF_REFCOUNT(pSwapChain
, 1);
495 CHECK_REFCOUNT(pDevice
, ++refcount
);
496 CHECK_RELEASE_REFCOUNT(pSwapChain
, 0);
497 CHECK_REFCOUNT(pDevice
, --refcount
);
502 hr
= IDirect3DDevice9_CreateIndexBuffer( pDevice
, 16, 0, D3DFMT_INDEX32
, D3DPOOL_DEFAULT
, &pIndexBuffer
, NULL
);
503 CHECK_CALL( hr
, "CreateIndexBuffer", pDevice
, ++refcount
);
506 tmp
= get_refcount( (IUnknown
*)pIndexBuffer
);
508 hr
= IDirect3DDevice9_SetIndices(pDevice
, pIndexBuffer
);
509 CHECK_CALL( hr
, "SetIndices", pIndexBuffer
, tmp
);
510 hr
= IDirect3DDevice9_SetIndices(pDevice
, NULL
);
511 CHECK_CALL( hr
, "SetIndices", pIndexBuffer
, tmp
);
514 hr
= IDirect3DDevice9_CreateVertexBuffer( pDevice
, 16, 0, D3DFVF_XYZ
, D3DPOOL_DEFAULT
, &pVertexBuffer
, NULL
);
515 CHECK_CALL( hr
, "CreateVertexBuffer", pDevice
, ++refcount
);
518 IDirect3DVertexBuffer9
*pVBuf
= (void*)~0;
522 tmp
= get_refcount( (IUnknown
*)pVertexBuffer
);
524 hr
= IDirect3DDevice9_SetStreamSource(pDevice
, 0, pVertexBuffer
, 0, 3 * sizeof(float));
525 CHECK_CALL( hr
, "SetStreamSource", pVertexBuffer
, tmp
);
526 hr
= IDirect3DDevice9_SetStreamSource(pDevice
, 0, NULL
, 0, 0);
527 CHECK_CALL( hr
, "SetStreamSource", pVertexBuffer
, tmp
);
529 hr
= IDirect3DDevice9_GetStreamSource(pDevice
, 0, &pVBuf
, &offset
, &stride
);
530 ok(SUCCEEDED(hr
), "GetStreamSource did not succeed with NULL stream!\n");
531 ok(pVBuf
==NULL
, "pVBuf not NULL (%p)!\n", pVBuf
);
532 ok(stride
==3*sizeof(float), "stride not 3 floats (got %u)!\n", stride
);
533 ok(offset
==0, "offset not 0 (got %u)!\n", offset
);
536 hr
= IDirect3DDevice9_CreateVertexDeclaration( pDevice
, decl
, &pVertexDeclaration
);
537 CHECK_CALL( hr
, "CreateVertexDeclaration", pDevice
, ++refcount
);
538 hr
= IDirect3DDevice9_CreateVertexShader( pDevice
, simple_vs
, &pVertexShader
);
539 CHECK_CALL( hr
, "CreateVertexShader", pDevice
, ++refcount
);
540 hr
= IDirect3DDevice9_CreatePixelShader( pDevice
, simple_ps
, &pPixelShader
);
541 CHECK_CALL( hr
, "CreatePixelShader", pDevice
, ++refcount
);
543 hr
= IDirect3DDevice9_CreateTexture( pDevice
, 32, 32, 3, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pTexture
, NULL
);
544 CHECK_CALL( hr
, "CreateTexture", pDevice
, ++refcount
);
547 tmp
= get_refcount( (IUnknown
*)pTexture
);
549 /* SetTexture should not increase refcounts */
550 hr
= IDirect3DDevice9_SetTexture(pDevice
, 0, (IDirect3DBaseTexture9
*) pTexture
);
551 CHECK_CALL( hr
, "SetTexture", pTexture
, tmp
);
552 hr
= IDirect3DDevice9_SetTexture(pDevice
, 0, NULL
);
553 CHECK_CALL( hr
, "SetTexture", pTexture
, tmp
);
555 /* This should not increment device refcount */
556 hr
= IDirect3DTexture9_GetSurfaceLevel( pTexture
, 1, &pTextureLevel
);
557 CHECK_CALL( hr
, "GetSurfaceLevel", pDevice
, refcount
);
558 /* But should increment texture's refcount */
559 CHECK_REFCOUNT( pTexture
, tmp
+1 );
560 /* Because the texture and surface refcount are identical */
563 CHECK_REFCOUNT ( pTextureLevel
, tmp
+1 );
564 CHECK_ADDREF_REFCOUNT ( pTextureLevel
, tmp
+2 );
565 CHECK_REFCOUNT ( pTexture
, tmp
+2 );
566 CHECK_RELEASE_REFCOUNT( pTextureLevel
, tmp
+1 );
567 CHECK_REFCOUNT ( pTexture
, tmp
+1 );
568 CHECK_RELEASE_REFCOUNT( pTexture
, tmp
);
569 CHECK_REFCOUNT ( pTextureLevel
, tmp
);
572 hr
= IDirect3DDevice9_CreateCubeTexture( pDevice
, 32, 0, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pCubeTexture
, NULL
);
573 CHECK_CALL( hr
, "CreateCubeTexture", pDevice
, ++refcount
);
574 hr
= IDirect3DDevice9_CreateVolumeTexture( pDevice
, 32, 32, 2, 0, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pVolumeTexture
, NULL
);
575 CHECK_CALL( hr
, "CreateVolumeTexture", pDevice
, ++refcount
);
578 tmp
= get_refcount( (IUnknown
*)pVolumeTexture
);
580 /* This should not increment device refcount */
581 hr
= IDirect3DVolumeTexture9_GetVolumeLevel(pVolumeTexture
, 0, &pVolumeLevel
);
582 CHECK_CALL( hr
, "GetVolumeLevel", pDevice
, refcount
);
583 /* But should increment volume texture's refcount */
584 CHECK_REFCOUNT( pVolumeTexture
, tmp
+1 );
585 /* Because the volume texture and volume refcount are identical */
588 CHECK_REFCOUNT ( pVolumeLevel
, tmp
+1 );
589 CHECK_ADDREF_REFCOUNT ( pVolumeLevel
, tmp
+2 );
590 CHECK_REFCOUNT ( pVolumeTexture
, tmp
+2 );
591 CHECK_RELEASE_REFCOUNT( pVolumeLevel
, tmp
+1 );
592 CHECK_REFCOUNT ( pVolumeTexture
, tmp
+1 );
593 CHECK_RELEASE_REFCOUNT( pVolumeTexture
, tmp
);
594 CHECK_REFCOUNT ( pVolumeLevel
, tmp
);
598 hr
= IDirect3DDevice9_CreateDepthStencilSurface( pDevice
, 32, 32, D3DFMT_D24S8
, D3DMULTISAMPLE_NONE
, 0, TRUE
, &pStencilSurface
, NULL
);
599 CHECK_CALL( hr
, "CreateDepthStencilSurface", pDevice
, ++refcount
);
600 CHECK_REFCOUNT( pStencilSurface
, 1 );
601 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface( pDevice
, 32, 32, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pOffscreenSurface
, NULL
);
602 CHECK_CALL( hr
, "CreateOffscreenPlainSurface", pDevice
, ++refcount
);
603 CHECK_REFCOUNT( pOffscreenSurface
, 1 );
604 hr
= IDirect3DDevice9_CreateRenderTarget( pDevice
, 32, 32, D3DFMT_X8R8G8B8
, D3DMULTISAMPLE_NONE
, 0, TRUE
, &pRenderTarget3
, NULL
);
605 CHECK_CALL( hr
, "CreateRenderTarget", pDevice
, ++refcount
);
606 CHECK_REFCOUNT( pRenderTarget3
, 1 );
608 hr
= IDirect3DDevice9_CreateStateBlock( pDevice
, D3DSBT_ALL
, &pStateBlock
);
609 CHECK_CALL( hr
, "CreateStateBlock", pDevice
, ++refcount
);
610 hr
= IDirect3DDevice9_CreateAdditionalSwapChain( pDevice
, &d3dpp
, &pSwapChain
);
611 CHECK_CALL( hr
, "CreateAdditionalSwapChain", pDevice
, ++refcount
);
614 /* check implicit back buffer */
615 hr
= IDirect3DSwapChain9_GetBackBuffer(pSwapChain
, 0, 0, &pBackBuffer
);
616 CHECK_CALL( hr
, "GetBackBuffer", pDevice
, ++refcount
);
617 CHECK_REFCOUNT( pSwapChain
, 1);
620 CHECK_SURFACE_CONTAINER( pBackBuffer
, IID_IDirect3DSwapChain9
, pSwapChain
);
621 CHECK_REFCOUNT( pBackBuffer
, 1);
622 CHECK_RELEASE_REFCOUNT( pBackBuffer
, 0);
623 CHECK_REFCOUNT( pDevice
, --refcount
);
625 /* The back buffer is released with the swapchain, so AddRef with refcount=0 is fine here. */
626 CHECK_ADDREF_REFCOUNT(pBackBuffer
, 1);
627 CHECK_REFCOUNT(pDevice
, ++refcount
);
628 CHECK_RELEASE_REFCOUNT(pBackBuffer
, 0);
629 CHECK_REFCOUNT(pDevice
, --refcount
);
632 CHECK_REFCOUNT( pSwapChain
, 1);
634 hr
= IDirect3DDevice9_CreateQuery( pDevice
, D3DQUERYTYPE_EVENT
, &pQuery
);
635 CHECK_CALL( hr
, "CreateQuery", pDevice
, ++refcount
);
637 hr
= IDirect3DDevice9_BeginStateBlock( pDevice
);
638 CHECK_CALL( hr
, "BeginStateBlock", pDevice
, refcount
);
639 hr
= IDirect3DDevice9_EndStateBlock( pDevice
, &pStateBlock1
);
640 CHECK_CALL( hr
, "EndStateBlock", pDevice
, ++refcount
);
642 /* The implicit render target is not freed if refcount reaches 0.
643 * Otherwise GetRenderTarget would re-allocate it and the pointer would change.*/
644 hr
= IDirect3DDevice9_GetRenderTarget(pDevice
, 0, &pRenderTarget2
);
645 CHECK_CALL( hr
, "GetRenderTarget", pDevice
, ++refcount
);
648 CHECK_RELEASE_REFCOUNT(pRenderTarget2
, 0);
649 ok(pRenderTarget
== pRenderTarget2
, "RenderTarget=%p and RenderTarget2=%p should be the same.\n",
650 pRenderTarget
, pRenderTarget2
);
651 CHECK_REFCOUNT( pDevice
, --refcount
);
652 pRenderTarget2
= NULL
;
654 pRenderTarget
= NULL
;
657 CHECK_RELEASE(pDevice
, pDevice
, --refcount
);
660 CHECK_RELEASE(pVertexBuffer
, pDevice
, --refcount
);
661 CHECK_RELEASE(pIndexBuffer
, pDevice
, --refcount
);
663 CHECK_RELEASE(pVertexDeclaration
, pDevice
, --refcount
);
664 CHECK_RELEASE(pVertexShader
, pDevice
, --refcount
);
665 CHECK_RELEASE(pPixelShader
, pDevice
, --refcount
);
667 CHECK_RELEASE(pTextureLevel
, pDevice
, --refcount
);
668 CHECK_RELEASE(pCubeTexture
, pDevice
, --refcount
);
669 CHECK_RELEASE(pVolumeTexture
, pDevice
, --refcount
);
671 CHECK_RELEASE(pStencilSurface
, pDevice
, --refcount
);
672 CHECK_RELEASE(pOffscreenSurface
, pDevice
, --refcount
);
673 CHECK_RELEASE(pRenderTarget3
, pDevice
, --refcount
);
675 CHECK_RELEASE(pStateBlock
, pDevice
, --refcount
);
676 CHECK_RELEASE(pSwapChain
, pDevice
, --refcount
);
677 CHECK_RELEASE(pQuery
, pDevice
, --refcount
);
678 /* This will destroy device - cannot check the refcount here */
679 if (pStateBlock1
) CHECK_RELEASE_REFCOUNT( pStateBlock1
, 0);
681 if (pD3d
) CHECK_RELEASE_REFCOUNT( pD3d
, 0);
683 DestroyWindow( hwnd
);
686 static void test_cursor(void)
690 IDirect3D9
*pD3d
= NULL
;
691 IDirect3DDevice9
*pDevice
= NULL
;
692 D3DPRESENT_PARAMETERS d3dpp
;
693 D3DDISPLAYMODE d3ddm
;
695 IDirect3DSurface9
*cursor
= NULL
;
698 memset(&info
, 0, sizeof(info
));
699 info
.cbSize
= sizeof(info
);
700 ok(GetCursorInfo(&info
), "GetCursorInfo failed\n");
703 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
704 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
705 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
706 ok(hwnd
!= NULL
, "Failed to create window\n");
707 if (!pD3d
|| !hwnd
) goto cleanup
;
709 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
710 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
711 d3dpp
.Windowed
= TRUE
;
712 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
713 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
715 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
716 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
717 ok(hr
== S_OK
|| hr
== D3DERR_NOTAVAILABLE
,
718 "Failed to create IDirect3D9Device (%08x)\n", hr
);
719 if (FAILED(hr
)) goto cleanup
;
721 IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 32, 32, D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &cursor
, 0);
722 ok(cursor
!= NULL
, "IDirect3DDevice9_CreateOffscreenPlainSurface failed with %08x\n", hr
);
724 /* Initially hidden */
725 hr
= IDirect3DDevice9_ShowCursor(pDevice
, TRUE
);
726 ok(hr
== FALSE
, "IDirect3DDevice9_ShowCursor returned %08x\n", hr
);
728 /* Not enabled without a surface*/
729 hr
= IDirect3DDevice9_ShowCursor(pDevice
, TRUE
);
730 ok(hr
== FALSE
, "IDirect3DDevice9_ShowCursor returned %08x\n", hr
);
733 hr
= IDirect3DDevice9_SetCursorProperties(pDevice
, 0, 0, NULL
);
734 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_SetCursorProperties returned %08x\n", hr
);
736 hr
= IDirect3DDevice9_SetCursorProperties(pDevice
, 0, 0, cursor
);
737 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetCursorProperties returned %08x\n", hr
);
739 IDirect3DSurface9_Release(cursor
);
741 memset(&info
, 0, sizeof(info
));
742 info
.cbSize
= sizeof(info
);
743 ok(GetCursorInfo(&info
), "GetCursorInfo failed\n");
744 ok(info
.flags
& CURSOR_SHOWING
, "The gdi cursor is hidden (%08x)\n", info
.flags
);
745 ok(info
.hCursor
== cur
, "The cursor handle is %p\n", info
.hCursor
); /* unchanged */
748 hr
= IDirect3DDevice9_ShowCursor(pDevice
, TRUE
);
749 ok(hr
== FALSE
, "IDirect3DDevice9_ShowCursor returned %08x\n", hr
);
752 hr
= IDirect3DDevice9_ShowCursor(pDevice
, TRUE
);
753 ok(hr
== TRUE
, "IDirect3DDevice9_ShowCursor returned %08x\n", hr
);
755 /* GDI cursor unchanged */
756 memset(&info
, 0, sizeof(info
));
757 info
.cbSize
= sizeof(info
);
758 ok(GetCursorInfo(&info
), "GetCursorInfo failed\n");
759 ok(info
.flags
& CURSOR_SHOWING
, "The gdi cursor is hidden (%08x)\n", info
.flags
);
760 ok(info
.hCursor
== cur
, "The cursor handle is %p\n", info
.hCursor
); /* unchanged */
763 if(pDevice
) IDirect3D9_Release(pDevice
);
764 if(pD3d
) IDirect3D9_Release(pD3d
);
765 DestroyWindow( hwnd
);
768 static void test_reset(void)
772 IDirect3D9
*pD3d
= NULL
;
773 IDirect3DDevice9
*pDevice
= NULL
;
774 D3DPRESENT_PARAMETERS d3dpp
;
775 D3DDISPLAYMODE d3ddm
, d3ddm2
;
777 DWORD width
, orig_width
= GetSystemMetrics(SM_CXSCREEN
);
778 DWORD height
, orig_height
= GetSystemMetrics(SM_CYSCREEN
);
779 IDirect3DSwapChain9
*pSwapchain
;
780 IDirect3DSurface9
*surface
;
781 IDirect3DTexture9
*texture
;
782 IDirect3DVertexShader9
*shader
;
783 UINT i
, adapter_mode_count
;
784 D3DLOCKED_RECT lockrect
;
792 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
793 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
794 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
795 ok(hwnd
!= NULL
, "Failed to create window\n");
796 if (!pD3d
|| !hwnd
) goto cleanup
;
798 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
799 adapter_mode_count
= IDirect3D9_GetAdapterModeCount(pD3d
, D3DADAPTER_DEFAULT
, d3ddm
.Format
);
800 modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(*modes
) * adapter_mode_count
);
801 for(i
= 0; i
< adapter_mode_count
; ++i
)
804 ZeroMemory( &d3ddm2
, sizeof(d3ddm2
) );
805 hr
= IDirect3D9_EnumAdapterModes(pD3d
, D3DADAPTER_DEFAULT
, d3ddm
.Format
, i
, &d3ddm2
);
806 ok(hr
== D3D_OK
, "IDirect3D9_EnumAdapterModes returned %#x\n", hr
);
808 for (j
= 0; j
< mode_count
; ++j
)
810 if (modes
[j
].w
== d3ddm2
.Width
&& modes
[j
].h
== d3ddm2
.Height
)
815 modes
[j
].w
= d3ddm2
.Width
;
816 modes
[j
].h
= d3ddm2
.Height
;
820 /* We use them as invalid modes */
821 if((d3ddm2
.Width
== 801 && d3ddm2
.Height
== 600) ||
822 (d3ddm2
.Width
== 32 && d3ddm2
.Height
== 32)) {
823 skip("This system supports a screen resolution of %dx%d, not running mode tests\n",
824 d3ddm2
.Width
, d3ddm2
.Height
);
831 skip("Less than 2 modes supported, skipping mode tests\n");
836 if (modes
[i
].w
== orig_width
&& modes
[i
].h
== orig_height
) ++i
;
838 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
839 d3dpp
.Windowed
= FALSE
;
840 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
841 d3dpp
.BackBufferWidth
= modes
[i
].w
;
842 d3dpp
.BackBufferHeight
= modes
[i
].h
;
843 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
844 d3dpp
.EnableAutoDepthStencil
= TRUE
;
845 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
847 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
848 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
852 skip("could not create device, IDirect3D9_CreateDevice returned %#x\n", hr
);
855 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
856 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after creation returned %#x\n", hr
);
858 width
= GetSystemMetrics(SM_CXSCREEN
);
859 height
= GetSystemMetrics(SM_CYSCREEN
);
860 ok(width
== modes
[i
].w
, "Screen width is %u, expected %u\n", width
, modes
[i
].w
);
861 ok(height
== modes
[i
].h
, "Screen height is %u, expected %u\n", height
, modes
[i
].h
);
863 hr
= IDirect3DDevice9_GetViewport(pDevice
, &vp
);
864 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetViewport failed with %08x\n", hr
);
867 ok(vp
.X
== 0, "D3DVIEWPORT->X = %d\n", vp
.X
);
868 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %d\n", vp
.Y
);
869 ok(vp
.Width
== modes
[i
].w
, "D3DVIEWPORT->Width = %u, expected %u\n", vp
.Width
, modes
[i
].w
);
870 ok(vp
.Height
== modes
[i
].h
, "D3DVIEWPORT->Height = %u, expected %u\n", vp
.Height
, modes
[i
].h
);
871 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %f\n", vp
.MinZ
);
872 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %f\n", vp
.MaxZ
);
880 hr
= IDirect3DDevice9_SetViewport(pDevice
, &vp
);
881 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetViewport failed with %08x\n", hr
);
883 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
884 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
885 d3dpp
.Windowed
= FALSE
;
886 d3dpp
.BackBufferWidth
= modes
[i
].w
;
887 d3dpp
.BackBufferHeight
= modes
[i
].h
;
888 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
889 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
890 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
891 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
892 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
894 ZeroMemory(&vp
, sizeof(vp
));
895 hr
= IDirect3DDevice9_GetViewport(pDevice
, &vp
);
896 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetViewport failed with %08x\n", hr
);
899 ok(vp
.X
== 0, "D3DVIEWPORT->X = %d\n", vp
.X
);
900 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %d\n", vp
.Y
);
901 ok(vp
.Width
== modes
[i
].w
, "D3DVIEWPORT->Width = %u, expected %u\n", vp
.Width
, modes
[i
].w
);
902 ok(vp
.Height
== modes
[i
].h
, "D3DVIEWPORT->Height = %u, expected %u\n", vp
.Height
, modes
[i
].h
);
903 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %f\n", vp
.MinZ
);
904 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %f\n", vp
.MaxZ
);
907 width
= GetSystemMetrics(SM_CXSCREEN
);
908 height
= GetSystemMetrics(SM_CYSCREEN
);
909 ok(width
== modes
[i
].w
, "Screen width is %u, expected %u\n", width
, modes
[i
].w
);
910 ok(height
== modes
[i
].h
, "Screen height is %u, expected %u\n", height
, modes
[i
].h
);
912 hr
= IDirect3DDevice9_GetSwapChain(pDevice
, 0, &pSwapchain
);
913 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetSwapChain returned %08x\n", hr
);
916 ZeroMemory(&d3dpp
, sizeof(d3dpp
));
917 hr
= IDirect3DSwapChain9_GetPresentParameters(pSwapchain
, &d3dpp
);
918 ok(hr
== D3D_OK
, "IDirect3DSwapChain9_GetPresentParameters returned %08x\n", hr
);
921 ok(d3dpp
.BackBufferWidth
== modes
[i
].w
, "Back buffer width is %u, expected %u\n",
922 d3dpp
.BackBufferWidth
, modes
[i
].w
);
923 ok(d3dpp
.BackBufferHeight
== modes
[i
].h
, "Back buffer height is %u, expected %u\n",
924 d3dpp
.BackBufferHeight
, modes
[i
].h
);
926 IDirect3DSwapChain9_Release(pSwapchain
);
929 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
930 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
931 d3dpp
.Windowed
= TRUE
;
932 d3dpp
.BackBufferWidth
= 400;
933 d3dpp
.BackBufferHeight
= 300;
934 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
935 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
936 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
937 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
939 width
= GetSystemMetrics(SM_CXSCREEN
);
940 height
= GetSystemMetrics(SM_CYSCREEN
);
941 ok(width
== orig_width
, "Screen width is %d\n", width
);
942 ok(height
== orig_height
, "Screen height is %d\n", height
);
944 ZeroMemory(&vp
, sizeof(vp
));
945 hr
= IDirect3DDevice9_GetViewport(pDevice
, &vp
);
946 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetViewport failed with %08x\n", hr
);
949 ok(vp
.X
== 0, "D3DVIEWPORT->X = %d\n", vp
.X
);
950 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %d\n", vp
.Y
);
951 ok(vp
.Width
== 400, "D3DVIEWPORT->Width = %d\n", vp
.Width
);
952 ok(vp
.Height
== 300, "D3DVIEWPORT->Height = %d\n", vp
.Height
);
953 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %f\n", vp
.MinZ
);
954 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %f\n", vp
.MaxZ
);
957 hr
= IDirect3DDevice9_GetSwapChain(pDevice
, 0, &pSwapchain
);
958 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetSwapChain returned %08x\n", hr
);
961 ZeroMemory(&d3dpp
, sizeof(d3dpp
));
962 hr
= IDirect3DSwapChain9_GetPresentParameters(pSwapchain
, &d3dpp
);
963 ok(hr
== D3D_OK
, "IDirect3DSwapChain9_GetPresentParameters returned %08x\n", hr
);
966 ok(d3dpp
.BackBufferWidth
== 400, "Back buffer width is %d\n", d3dpp
.BackBufferWidth
);
967 ok(d3dpp
.BackBufferHeight
== 300, "Back buffer height is %d\n", d3dpp
.BackBufferHeight
);
969 IDirect3DSwapChain9_Release(pSwapchain
);
972 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
973 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
974 d3dpp
.Windowed
= TRUE
;
975 d3dpp
.BackBufferWidth
= 400;
976 d3dpp
.BackBufferHeight
= 300;
978 /* _Reset fails if there is a resource in the default pool */
979 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 16, 16, D3DFMT_R5G6B5
, D3DPOOL_DEFAULT
, &surface
, NULL
);
980 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr
);
981 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
982 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
983 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
984 ok(hr
== D3DERR_DEVICENOTRESET
, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr
);
985 IDirect3DSurface9_Release(surface
);
986 /* Reset again to get the device out of the lost state */
987 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
988 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
989 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
990 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
992 /* Scratch, sysmem and managed pools are fine */
993 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 16, 16, D3DFMT_R5G6B5
, D3DPOOL_SCRATCH
, &surface
, NULL
);
994 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr
);
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
);
999 IDirect3DSurface9_Release(surface
);
1001 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 16, 16, D3DFMT_R5G6B5
, D3DPOOL_SYSTEMMEM
, &surface
, NULL
);
1002 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr
);
1003 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1004 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1005 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
1006 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
1007 IDirect3DSurface9_Release(surface
);
1009 /* The depth stencil should get reset to the auto depth stencil when present. */
1010 hr
= IDirect3DDevice9_SetDepthStencilSurface(pDevice
, NULL
);
1011 ok(hr
== D3D_OK
, "SetDepthStencilSurface failed with 0x%08x\n", hr
);
1013 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &surface
);
1014 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr
);
1015 ok(surface
== NULL
, "Depth stencil should be NULL\n");
1017 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1018 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1019 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1020 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with 0x%08x\n", hr
);
1022 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &surface
);
1023 ok(hr
== D3D_OK
, "GetDepthStencilSurface failed with 0x%08x\n", hr
);
1024 ok(surface
!= NULL
, "Depth stencil should not be NULL\n");
1025 if (surface
) IDirect3DSurface9_Release(surface
);
1027 d3dpp
.EnableAutoDepthStencil
= FALSE
;
1028 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1029 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with 0x%08x\n", hr
);
1031 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &surface
);
1032 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr
);
1033 ok(surface
== NULL
, "Depth stencil should be NULL\n");
1035 /* Will a sysmem or scratch survive while locked */
1036 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 16, 16, D3DFMT_R5G6B5
, D3DPOOL_SYSTEMMEM
, &surface
, NULL
);
1037 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr
);
1038 hr
= IDirect3DSurface9_LockRect(surface
, &lockrect
, NULL
, D3DLOCK_DISCARD
);
1039 ok(hr
== D3D_OK
, "IDirect3DSurface9_LockRect returned %08x\n", hr
);
1040 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1041 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1042 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
1043 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
1044 IDirect3DSurface9_UnlockRect(surface
);
1045 IDirect3DSurface9_Release(surface
);
1047 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 16, 16, D3DFMT_R5G6B5
, D3DPOOL_SCRATCH
, &surface
, NULL
);
1048 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr
);
1049 hr
= IDirect3DSurface9_LockRect(surface
, &lockrect
, NULL
, D3DLOCK_DISCARD
);
1050 ok(hr
== D3D_OK
, "IDirect3DSurface9_LockRect returned %08x\n", hr
);
1051 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1052 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1053 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
1054 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
1055 IDirect3DSurface9_UnlockRect(surface
);
1056 IDirect3DSurface9_Release(surface
);
1058 hr
= IDirect3DDevice9_CreateTexture(pDevice
, 16, 16, 0, 0, D3DFMT_R5G6B5
, D3DPOOL_MANAGED
, &texture
, NULL
);
1059 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture returned %08x\n", hr
);
1060 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1061 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1062 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
1063 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
1064 IDirect3DTexture9_Release(texture
);
1066 /* A reference held to an implicit surface causes failures as well */
1067 hr
= IDirect3DDevice9_GetBackBuffer(pDevice
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &surface
);
1068 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetBackBuffer returned %08x\n", hr
);
1069 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1070 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1071 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
1072 ok(hr
== D3DERR_DEVICENOTRESET
, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr
);
1073 IDirect3DSurface9_Release(surface
);
1074 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1075 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1076 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
1077 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
1079 /* Shaders are fine as well */
1080 hr
= IDirect3DDevice9_CreateVertexShader(pDevice
, simple_vs
, &shader
);
1081 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr
);
1082 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1083 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1084 IDirect3DVertexShader9_Release(shader
);
1086 /* Try setting invalid modes */
1087 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1088 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1089 d3dpp
.Windowed
= FALSE
;
1090 d3dpp
.BackBufferWidth
= 32;
1091 d3dpp
.BackBufferHeight
= 32;
1092 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1093 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Reset to w=32, h=32, windowed=FALSE failed with %08x\n", hr
);
1094 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
1095 ok(hr
== D3DERR_DEVICENOTRESET
, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr
);
1097 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1098 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1099 d3dpp
.Windowed
= FALSE
;
1100 d3dpp
.BackBufferWidth
= 801;
1101 d3dpp
.BackBufferHeight
= 600;
1102 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1103 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Reset to w=801, h=600, windowed=FALSE failed with %08x\n", hr
);
1104 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
1105 ok(hr
== D3DERR_DEVICENOTRESET
, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr
);
1108 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
1110 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1111 d3dpp
.Windowed
= TRUE
;
1112 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1113 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1114 d3dpp
.EnableAutoDepthStencil
= FALSE
;
1115 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1117 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
1118 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
1122 skip("could not create device, IDirect3D9_CreateDevice returned %#x\n", hr
);
1126 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
1127 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after creation returned %#x\n", hr
);
1129 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1130 d3dpp
.Windowed
= TRUE
;
1131 d3dpp
.BackBufferWidth
= 400;
1132 d3dpp
.BackBufferHeight
= 300;
1133 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1134 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1136 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1137 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with 0x%08x\n", hr
);
1139 if (FAILED(hr
)) goto cleanup
;
1141 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &surface
);
1142 ok(hr
== D3D_OK
, "GetDepthStencilSurface failed with 0x%08x\n", hr
);
1143 ok(surface
!= NULL
, "Depth stencil should not be NULL\n");
1144 if (surface
) IDirect3DSurface9_Release(surface
);
1147 HeapFree(GetProcessHeap(), 0, modes
);
1148 if(pD3d
) IDirect3D9_Release(pD3d
);
1149 if(pDevice
) IDirect3D9_Release(pDevice
);
1152 /* Test adapter display modes */
1153 static void test_display_modes(void)
1155 D3DDISPLAYMODE dmode
;
1158 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
1159 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
1162 #define TEST_FMT(x,r) do { \
1163 HRESULT res = IDirect3D9_EnumAdapterModes(pD3d, 0, (x), 0, &dmode); \
1164 ok(res==(r), "EnumAdapterModes("#x") did not return "#r" (got %08x)!\n", res); \
1167 TEST_FMT(D3DFMT_R8G8B8
, D3DERR_INVALIDCALL
);
1168 TEST_FMT(D3DFMT_A8R8G8B8
, D3DERR_INVALIDCALL
);
1169 TEST_FMT(D3DFMT_X8B8G8R8
, D3DERR_INVALIDCALL
);
1171 TEST_FMT(D3DFMT_X1R5G5B5
, D3DERR_INVALIDCALL
);
1172 TEST_FMT(D3DFMT_A1R5G5B5
, D3DERR_INVALIDCALL
);
1173 TEST_FMT(D3DFMT_A4R4G4B4
, D3DERR_INVALIDCALL
);
1174 TEST_FMT(D3DFMT_R3G3B2
, D3DERR_INVALIDCALL
);
1175 TEST_FMT(D3DFMT_A8
, D3DERR_INVALIDCALL
);
1176 TEST_FMT(D3DFMT_A8R3G3B2
, D3DERR_INVALIDCALL
);
1177 TEST_FMT(D3DFMT_X4R4G4B4
, D3DERR_INVALIDCALL
);
1178 TEST_FMT(D3DFMT_A2B10G10R10
, D3DERR_INVALIDCALL
);
1179 TEST_FMT(D3DFMT_A8B8G8R8
, D3DERR_INVALIDCALL
);
1180 TEST_FMT(D3DFMT_X8B8G8R8
, D3DERR_INVALIDCALL
);
1181 TEST_FMT(D3DFMT_G16R16
, D3DERR_INVALIDCALL
);
1182 TEST_FMT(D3DFMT_A2R10G10B10
, D3DERR_INVALIDCALL
);
1183 TEST_FMT(D3DFMT_A16B16G16R16
, D3DERR_INVALIDCALL
);
1185 TEST_FMT(D3DFMT_A8P8
, D3DERR_INVALIDCALL
);
1186 TEST_FMT(D3DFMT_P8
, D3DERR_INVALIDCALL
);
1188 TEST_FMT(D3DFMT_L8
, D3DERR_INVALIDCALL
);
1189 TEST_FMT(D3DFMT_A8L8
, D3DERR_INVALIDCALL
);
1190 TEST_FMT(D3DFMT_A4L4
, D3DERR_INVALIDCALL
);
1192 TEST_FMT(D3DFMT_V8U8
, D3DERR_INVALIDCALL
);
1193 TEST_FMT(D3DFMT_L6V5U5
, D3DERR_INVALIDCALL
);
1194 TEST_FMT(D3DFMT_X8L8V8U8
, D3DERR_INVALIDCALL
);
1195 TEST_FMT(D3DFMT_Q8W8V8U8
, D3DERR_INVALIDCALL
);
1196 TEST_FMT(D3DFMT_V16U16
, D3DERR_INVALIDCALL
);
1197 TEST_FMT(D3DFMT_A2W10V10U10
, D3DERR_INVALIDCALL
);
1199 TEST_FMT(D3DFMT_UYVY
, D3DERR_INVALIDCALL
);
1200 TEST_FMT(D3DFMT_YUY2
, D3DERR_INVALIDCALL
);
1201 TEST_FMT(D3DFMT_DXT1
, D3DERR_INVALIDCALL
);
1202 TEST_FMT(D3DFMT_DXT2
, D3DERR_INVALIDCALL
);
1203 TEST_FMT(D3DFMT_DXT3
, D3DERR_INVALIDCALL
);
1204 TEST_FMT(D3DFMT_DXT4
, D3DERR_INVALIDCALL
);
1205 TEST_FMT(D3DFMT_DXT5
, D3DERR_INVALIDCALL
);
1206 TEST_FMT(D3DFMT_MULTI2_ARGB8
, D3DERR_INVALIDCALL
);
1207 TEST_FMT(D3DFMT_G8R8_G8B8
, D3DERR_INVALIDCALL
);
1208 TEST_FMT(D3DFMT_R8G8_B8G8
, D3DERR_INVALIDCALL
);
1210 TEST_FMT(D3DFMT_D16_LOCKABLE
, D3DERR_INVALIDCALL
);
1211 TEST_FMT(D3DFMT_D32
, D3DERR_INVALIDCALL
);
1212 TEST_FMT(D3DFMT_D15S1
, D3DERR_INVALIDCALL
);
1213 TEST_FMT(D3DFMT_D24S8
, D3DERR_INVALIDCALL
);
1214 TEST_FMT(D3DFMT_D24X8
, D3DERR_INVALIDCALL
);
1215 TEST_FMT(D3DFMT_D24X4S4
, D3DERR_INVALIDCALL
);
1216 TEST_FMT(D3DFMT_D16
, D3DERR_INVALIDCALL
);
1217 TEST_FMT(D3DFMT_L16
, D3DERR_INVALIDCALL
);
1218 TEST_FMT(D3DFMT_D32F_LOCKABLE
, D3DERR_INVALIDCALL
);
1219 TEST_FMT(D3DFMT_D24FS8
, D3DERR_INVALIDCALL
);
1221 TEST_FMT(D3DFMT_VERTEXDATA
, D3DERR_INVALIDCALL
);
1222 TEST_FMT(D3DFMT_INDEX16
, D3DERR_INVALIDCALL
);
1223 TEST_FMT(D3DFMT_INDEX32
, D3DERR_INVALIDCALL
);
1224 TEST_FMT(D3DFMT_Q16W16V16U16
, D3DERR_INVALIDCALL
);
1225 /* Floating point formats */
1226 TEST_FMT(D3DFMT_R16F
, D3DERR_INVALIDCALL
);
1227 TEST_FMT(D3DFMT_G16R16F
, D3DERR_INVALIDCALL
);
1228 TEST_FMT(D3DFMT_A16B16G16R16F
, D3DERR_INVALIDCALL
);
1231 TEST_FMT(D3DFMT_R32F
, D3DERR_INVALIDCALL
);
1232 TEST_FMT(D3DFMT_G32R32F
, D3DERR_INVALIDCALL
);
1233 TEST_FMT(D3DFMT_A32B32G32R32F
, D3DERR_INVALIDCALL
);
1235 TEST_FMT(D3DFMT_CxV8U8
, D3DERR_INVALIDCALL
);
1237 TEST_FMT(0, D3DERR_INVALIDCALL
);
1239 IDirect3D9_Release(pD3d
);
1242 static void test_scene(void)
1246 IDirect3D9
*pD3d
= NULL
;
1247 IDirect3DDevice9
*pDevice
= NULL
;
1248 D3DPRESENT_PARAMETERS d3dpp
;
1249 D3DDISPLAYMODE d3ddm
;
1250 IDirect3DSurface9
*pSurface1
= NULL
, *pSurface2
= NULL
, *pSurface3
= NULL
, *pRenderTarget
= NULL
;
1251 IDirect3DSurface9
*pBackBuffer
= NULL
, *pDepthStencil
= NULL
;
1252 RECT rect
= {0, 0, 128, 128};
1255 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
1256 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
1257 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1258 ok(hwnd
!= NULL
, "Failed to create window\n");
1259 if (!pD3d
|| !hwnd
) goto cleanup
;
1261 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
1262 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1263 d3dpp
.Windowed
= TRUE
;
1264 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1265 d3dpp
.BackBufferWidth
= 800;
1266 d3dpp
.BackBufferHeight
= 600;
1267 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1268 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1269 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
1271 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1272 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
1273 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1276 skip("Failed to create a d3d device\n");
1280 /* Get the caps, they will be needed to tell if an operation is supposed to be valid */
1281 memset(&caps
, 0, sizeof(caps
));
1282 hr
= IDirect3DDevice9_GetDeviceCaps(pDevice
, &caps
);
1283 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetCaps failed with %08x\n", hr
);
1284 if(FAILED(hr
)) goto cleanup
;
1286 /* Test an EndScene without beginscene. Should return an error */
1287 hr
= IDirect3DDevice9_EndScene(pDevice
);
1288 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_EndScene returned %08x\n", hr
);
1290 /* Test a normal BeginScene / EndScene pair, this should work */
1291 hr
= IDirect3DDevice9_BeginScene(pDevice
);
1292 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %08x\n", hr
);
1295 hr
= IDirect3DDevice9_EndScene(pDevice
);
1296 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %08x\n", hr
);
1299 /* Test another EndScene without having begun a new scene. Should return an error */
1300 hr
= IDirect3DDevice9_EndScene(pDevice
);
1301 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_EndScene returned %08x\n", hr
);
1303 /* Two nested BeginScene and EndScene calls */
1304 hr
= IDirect3DDevice9_BeginScene(pDevice
);
1305 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %08x\n", hr
);
1306 hr
= IDirect3DDevice9_BeginScene(pDevice
);
1307 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_BeginScene returned %08x\n", hr
);
1308 hr
= IDirect3DDevice9_EndScene(pDevice
);
1309 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %08x\n", hr
);
1310 hr
= IDirect3DDevice9_EndScene(pDevice
);
1311 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_EndScene returned %08x\n", hr
);
1313 /* Create some surfaces to test stretchrect between the scenes */
1314 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 128, 128, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &pSurface1
, NULL
);
1315 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface failed with %08x\n", hr
);
1316 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 128, 128, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &pSurface2
, NULL
);
1317 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface failed with %08x\n", hr
);
1318 hr
= IDirect3DDevice9_CreateDepthStencilSurface(pDevice
, 800, 600, D3DFMT_D16
, D3DMULTISAMPLE_NONE
, 0, FALSE
, &pSurface3
, NULL
);
1319 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateDepthStencilSurface failed with %08x\n", hr
);
1320 hr
= IDirect3DDevice9_CreateRenderTarget(pDevice
, 128, 128, d3ddm
.Format
, D3DMULTISAMPLE_NONE
, 0, FALSE
, &pRenderTarget
, NULL
);
1321 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateRenderTarget failed with %08x\n", hr
);
1323 hr
= IDirect3DDevice9_GetBackBuffer(pDevice
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &pBackBuffer
);
1324 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetBackBuffer failed with %08x\n", hr
);
1325 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &pDepthStencil
);
1326 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetBackBuffer failed with %08x\n", hr
);
1328 /* First make sure a simple StretchRect call works */
1329 if(pSurface1
&& pSurface2
) {
1330 hr
= IDirect3DDevice9_StretchRect(pDevice
, pSurface1
, NULL
, pSurface2
, NULL
, 0);
1331 ok( hr
== D3D_OK
, "IDirect3DDevice9_StretchRect failed with %08x\n", hr
);
1333 if(pBackBuffer
&& pRenderTarget
) {
1334 hr
= IDirect3DDevice9_StretchRect(pDevice
, pBackBuffer
, &rect
, pRenderTarget
, NULL
, 0);
1335 ok( hr
== D3D_OK
, "IDirect3DDevice9_StretchRect failed with %08x\n", hr
);
1337 if(pDepthStencil
&& pSurface3
) {
1339 if(0) /* Disabled for now because it crashes in wine */ {
1340 expected
= caps
.DevCaps2
& D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES
? D3D_OK
: D3DERR_INVALIDCALL
;
1341 hr
= IDirect3DDevice9_StretchRect(pDevice
, pDepthStencil
, NULL
, pSurface3
, NULL
, 0);
1342 ok( hr
== expected
, "IDirect3DDevice9_StretchRect returned %08x, expected %08x\n", hr
, expected
);
1346 /* Now try it in a BeginScene - EndScene pair. Seems to be allowed in a beginScene - Endscene pair
1347 * width normal surfaces, render targets and depth stencil surfaces.
1349 hr
= IDirect3DDevice9_BeginScene(pDevice
);
1350 ok( hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %08x\n", hr
);
1352 if(pSurface1
&& pSurface2
)
1354 hr
= IDirect3DDevice9_StretchRect(pDevice
, pSurface1
, NULL
, pSurface2
, NULL
, 0);
1355 ok( hr
== D3D_OK
, "IDirect3DDevice9_StretchRect failed with %08x\n", hr
);
1357 if(pBackBuffer
&& pRenderTarget
)
1359 hr
= IDirect3DDevice9_StretchRect(pDevice
, pBackBuffer
, &rect
, pRenderTarget
, NULL
, 0);
1360 ok( hr
== D3D_OK
, "IDirect3DDevice9_StretchRect failed with %08x\n", hr
);
1362 if(pDepthStencil
&& pSurface3
)
1364 /* This is supposed to fail inside a BeginScene - EndScene pair. */
1365 hr
= IDirect3DDevice9_StretchRect(pDevice
, pDepthStencil
, NULL
, pSurface3
, NULL
, 0);
1366 ok( hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_StretchRect returned %08x, expected D3DERR_INVALIDCALL\n", hr
);
1369 hr
= IDirect3DDevice9_EndScene(pDevice
);
1370 ok( hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %08x\n", hr
);
1372 /* Does a SetRenderTarget influence BeginScene / EndScene ?
1373 * Set a new render target, then see if it started a new scene. Flip the rt back and see if that maybe
1374 * ended the scene. Expected result is that the scene is not affected by SetRenderTarget
1376 hr
= IDirect3DDevice9_SetRenderTarget(pDevice
, 0, pRenderTarget
);
1377 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderTarget failed with %08x\n", hr
);
1378 hr
= IDirect3DDevice9_BeginScene(pDevice
);
1379 ok( hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %08x\n", hr
);
1380 hr
= IDirect3DDevice9_SetRenderTarget(pDevice
, 0, pBackBuffer
);
1381 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderTarget failed with %08x\n", hr
);
1382 hr
= IDirect3DDevice9_EndScene(pDevice
);
1383 ok( hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %08x\n", hr
);
1386 if(pRenderTarget
) IDirect3DSurface9_Release(pRenderTarget
);
1387 if(pDepthStencil
) IDirect3DSurface9_Release(pDepthStencil
);
1388 if(pBackBuffer
) IDirect3DSurface9_Release(pBackBuffer
);
1389 if(pSurface1
) IDirect3DSurface9_Release(pSurface1
);
1390 if(pSurface2
) IDirect3DSurface9_Release(pSurface2
);
1391 if(pSurface3
) IDirect3DSurface9_Release(pSurface3
);
1392 if(pD3d
) IDirect3D9_Release(pD3d
);
1393 if(pDevice
) IDirect3D9_Release(pDevice
);
1394 if(hwnd
) DestroyWindow(hwnd
);
1397 static void test_limits(void)
1401 IDirect3D9
*pD3d
= NULL
;
1402 IDirect3DDevice9
*pDevice
= NULL
;
1403 D3DPRESENT_PARAMETERS d3dpp
;
1404 D3DDISPLAYMODE d3ddm
;
1405 IDirect3DTexture9
*pTexture
= NULL
;
1408 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
1409 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
1410 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1411 ok(hwnd
!= NULL
, "Failed to create window\n");
1412 if (!pD3d
|| !hwnd
) goto cleanup
;
1414 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
1415 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1416 d3dpp
.Windowed
= TRUE
;
1417 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1418 d3dpp
.BackBufferWidth
= 800;
1419 d3dpp
.BackBufferHeight
= 600;
1420 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1421 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1422 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
1424 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1425 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
1426 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1429 skip("Failed to create a d3d device\n");
1433 hr
= IDirect3DDevice9_CreateTexture(pDevice
, 16, 16, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &pTexture
, NULL
);
1434 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture failed with %08x\n", hr
);
1435 if(!pTexture
) goto cleanup
;
1437 /* There are 16 pixel samplers. We should be able to access all of them */
1438 for(i
= 0; i
< 16; i
++) {
1439 hr
= IDirect3DDevice9_SetTexture(pDevice
, i
, (IDirect3DBaseTexture9
*) pTexture
);
1440 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture for sampler %d failed with %08x\n", i
, hr
);
1441 hr
= IDirect3DDevice9_SetTexture(pDevice
, i
, NULL
);
1442 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture for sampler %d failed with %08x\n", i
, hr
);
1443 hr
= IDirect3DDevice9_SetSamplerState(pDevice
, i
, D3DSAMP_SRGBTEXTURE
, TRUE
);
1444 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState for sampler %d failed with %08x\n", i
, hr
);
1447 /* Now test all 8 textures stage states */
1448 for(i
= 0; i
< 8; i
++) {
1449 hr
= IDirect3DDevice9_SetTextureStageState(pDevice
, i
, D3DTSS_COLOROP
, D3DTOP_ADD
);
1450 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState for texture %d failed with %08x\n", i
, hr
);
1453 /* Investigations show that accessing higher samplers / textures stage states does not return an error either. Writing
1454 * to too high samplers(approximately sampler 40) causes memory corruption in windows, so there is no bounds checking
1455 * but how do I test that?
1458 if(pTexture
) IDirect3DTexture9_Release(pTexture
);
1459 if(pD3d
) IDirect3D9_Release(pD3d
);
1460 if(pDevice
) IDirect3D9_Release(pDevice
);
1461 if(hwnd
) DestroyWindow(hwnd
);
1464 static void test_depthstenciltest(void)
1468 IDirect3D9
*pD3d
= NULL
;
1469 IDirect3DDevice9
*pDevice
= NULL
;
1470 D3DPRESENT_PARAMETERS d3dpp
;
1471 D3DDISPLAYMODE d3ddm
;
1472 IDirect3DSurface9
*pDepthStencil
= NULL
;
1473 IDirect3DSurface9
*pDepthStencil2
= NULL
;
1474 D3DZBUFFERTYPE state
;
1476 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
1477 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
1478 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1479 ok(hwnd
!= NULL
, "Failed to create window\n");
1480 if (!pD3d
|| !hwnd
) goto cleanup
;
1482 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
1483 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1484 d3dpp
.Windowed
= TRUE
;
1485 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1486 d3dpp
.BackBufferWidth
= 800;
1487 d3dpp
.BackBufferHeight
= 600;
1488 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1489 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1490 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
1492 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1493 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
1494 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1497 skip("Failed to create a d3d device\n");
1501 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &pDepthStencil
);
1502 ok(hr
== D3D_OK
&& pDepthStencil
!= NULL
, "IDirect3DDevice9_GetDepthStencilSurface failed with %08x\n", hr
);
1505 hr
= IDirect3DDevice9_Clear(pDevice
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0x00000000, 1.0, 0);
1506 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1508 hr
= IDirect3DDevice9_SetDepthStencilSurface(pDevice
, NULL
);
1509 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetDepthStencilSurface failed with %08x\n", hr
);
1511 /* Check if the set buffer is returned on a get. WineD3D had a bug with that once, prevent it from coming back */
1512 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &pDepthStencil2
);
1513 ok(hr
== D3DERR_NOTFOUND
&& pDepthStencil2
== NULL
, "IDirect3DDevice9_GetDepthStencilSurface failed with %08x\n", hr
);
1514 if(pDepthStencil2
) IDirect3DSurface9_Release(pDepthStencil2
);
1516 /* This left the render states untouched! */
1517 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_ZENABLE
, &state
);
1518 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1519 ok(state
== D3DZB_TRUE
, "D3DRS_ZENABLE is %s\n", state
== D3DZB_FALSE
? "D3DZB_FALSE" : (state
== D3DZB_TRUE
? "D3DZB_TRUE" : "D3DZB_USEW"));
1520 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_ZWRITEENABLE
, &state
);
1521 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1522 ok(state
== TRUE
, "D3DRS_ZWRITEENABLE is %s\n", state
? "TRUE" : "FALSE");
1523 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_STENCILENABLE
, &state
);
1524 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1525 ok(state
== FALSE
, "D3DRS_STENCILENABLE is %s\n", state
? "TRUE" : "FALSE");
1526 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_STENCILWRITEMASK
, &state
);
1527 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1528 ok(state
== 0xffffffff, "D3DRS_STENCILWRITEMASK is 0x%08x\n", state
);
1530 /* This is supposed to fail now */
1531 hr
= IDirect3DDevice9_Clear(pDevice
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0x00000000, 1.0, 0);
1532 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1534 hr
= IDirect3DDevice9_SetRenderState(pDevice
, D3DRS_ZENABLE
, D3DZB_FALSE
);
1535 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed with %08x\n", hr
);
1537 hr
= IDirect3DDevice9_SetDepthStencilSurface(pDevice
, pDepthStencil
);
1538 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetDepthStencilSurface failed with %08x\n", hr
);
1540 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_ZENABLE
, &state
);
1541 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1542 ok(state
== D3DZB_FALSE
, "D3DRS_ZENABLE is %s\n", state
== D3DZB_FALSE
? "D3DZB_FALSE" : (state
== D3DZB_TRUE
? "D3DZB_TRUE" : "D3DZB_USEW"));
1544 /* Now it works again */
1545 hr
= IDirect3DDevice9_Clear(pDevice
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0x00000000, 1.0, 0);
1546 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1548 if(pDepthStencil
) IDirect3DSurface9_Release(pDepthStencil
);
1549 if(pDevice
) IDirect3D9_Release(pDevice
);
1551 /* Now see if autodepthstencil disable is honored. First, without a format set */
1552 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1553 d3dpp
.Windowed
= TRUE
;
1554 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1555 d3dpp
.BackBufferWidth
= 800;
1556 d3dpp
.BackBufferHeight
= 600;
1557 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1558 d3dpp
.EnableAutoDepthStencil
= FALSE
;
1559 d3dpp
.AutoDepthStencilFormat
= D3DFMT_UNKNOWN
;
1561 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1562 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
1563 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1566 skip("Failed to create a d3d device\n");
1570 pDepthStencil
= NULL
;
1571 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &pDepthStencil
);
1572 ok(hr
== D3DERR_NOTFOUND
&& pDepthStencil
== NULL
, "IDirect3DDevice9_GetDepthStencilSurface returned %08x, surface = %p\n", hr
, pDepthStencil
);
1574 IDirect3DSurface9_Release(pDepthStencil
);
1575 pDepthStencil
= NULL
;
1578 /* Check the depth test state */
1579 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_ZENABLE
, &state
);
1580 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1581 ok(state
== D3DZB_FALSE
, "D3DRS_ZENABLE is %s\n", state
== D3DZB_FALSE
? "D3DZB_FALSE" : (state
== D3DZB_TRUE
? "D3DZB_TRUE" : "D3DZB_USEW"));
1583 if(pDevice
) IDirect3D9_Release(pDevice
);
1585 /* Next, try EnableAutoDepthStencil FALSE with a depth stencil format set */
1586 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1587 d3dpp
.Windowed
= TRUE
;
1588 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1589 d3dpp
.BackBufferWidth
= 800;
1590 d3dpp
.BackBufferHeight
= 600;
1591 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1592 d3dpp
.EnableAutoDepthStencil
= FALSE
;
1593 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
1595 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1596 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
1597 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1600 skip("Failed to create a d3d device\n");
1604 pDepthStencil
= NULL
;
1605 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &pDepthStencil
);
1606 ok(hr
== D3DERR_NOTFOUND
&& pDepthStencil
== NULL
, "IDirect3DDevice9_GetDepthStencilSurface returned %08x, surface = %p\n", hr
, pDepthStencil
);
1608 IDirect3DSurface9_Release(pDepthStencil
);
1609 pDepthStencil
= NULL
;
1612 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_ZENABLE
, &state
);
1613 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1614 ok(state
== D3DZB_FALSE
, "D3DRS_ZENABLE is %s\n", state
== D3DZB_FALSE
? "D3DZB_FALSE" : (state
== D3DZB_TRUE
? "D3DZB_TRUE" : "D3DZB_USEW"));
1617 if(pDepthStencil
) IDirect3DSurface9_Release(pDepthStencil
);
1618 if(pD3d
) IDirect3D9_Release(pD3d
);
1619 if(pDevice
) IDirect3D9_Release(pDevice
);
1620 if(hwnd
) DestroyWindow(hwnd
);
1623 /* Test what happens when IDirect3DDevice9_DrawIndexedPrimitive is called without a valid index buffer set. */
1624 static void test_draw_indexed(void)
1626 static const struct {
1630 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
1631 {{-1.0f
, 1.0f
, 0.0f
}, 0xffff0000},
1632 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffff0000},
1633 {{ 1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
1635 WORD indices
[] = {0, 1, 2, 3, 0, 2};
1637 static const D3DVERTEXELEMENT9 decl_elements
[] = {
1638 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
1639 {0, 12, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
1643 IDirect3DVertexDeclaration9
*vertex_declaration
= NULL
;
1644 IDirect3DVertexBuffer9
*vertex_buffer
= NULL
;
1645 IDirect3DIndexBuffer9
*index_buffer
= NULL
;
1646 D3DPRESENT_PARAMETERS present_parameters
;
1647 IDirect3DDevice9
*device
= NULL
;
1653 hwnd
= CreateWindow("static", "d3d9_test",
1654 0, 0, 0, 10, 10, 0, 0, 0, 0);
1657 skip("Failed to create window\n");
1661 d3d9
= pDirect3DCreate9(D3D_SDK_VERSION
);
1664 skip("Failed to create IDirect3D9 object\n");
1668 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
1669 present_parameters
.Windowed
= TRUE
;
1670 present_parameters
.hDeviceWindow
= hwnd
;
1671 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1673 hr
= IDirect3D9_CreateDevice(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
1674 NULL
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
1675 if (FAILED(hr
) || !device
)
1677 skip("Failed to create device\n");
1681 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &vertex_declaration
);
1682 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (0x%08x)\n", hr
);
1683 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
1684 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed (0x%08x)\n", hr
);
1686 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, sizeof(quad
), 0, 0, D3DPOOL_DEFAULT
, &vertex_buffer
, NULL
);
1687 ok(SUCCEEDED(hr
), "CreateVertexBuffer failed (0x%08x)\n", hr
);
1688 hr
= IDirect3DVertexBuffer9_Lock(vertex_buffer
, 0, 0, &ptr
, D3DLOCK_DISCARD
);
1689 ok(SUCCEEDED(hr
), "Lock failed (0x%08x)\n", hr
);
1690 memcpy(ptr
, quad
, sizeof(quad
));
1691 hr
= IDirect3DVertexBuffer9_Unlock(vertex_buffer
);
1692 ok(SUCCEEDED(hr
), "Unlock failed (0x%08x)\n", hr
);
1693 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vertex_buffer
, 0, sizeof(*quad
));
1694 ok(SUCCEEDED(hr
), "SetStreamSource failed (0x%08x)\n", hr
);
1696 hr
= IDirect3DDevice9_CreateIndexBuffer(device
, sizeof(indices
), 0, D3DFMT_INDEX16
, D3DPOOL_DEFAULT
, &index_buffer
, NULL
);
1697 ok(SUCCEEDED(hr
), "CreateIndexBuffer failed (0x%08x)\n", hr
);
1698 hr
= IDirect3DIndexBuffer9_Lock(index_buffer
, 0, 0, &ptr
, D3DLOCK_DISCARD
);
1699 ok(SUCCEEDED(hr
), "Lock failed (0x%08x)\n", hr
);
1700 memcpy(ptr
, indices
, sizeof(indices
));
1701 hr
= IDirect3DIndexBuffer9_Unlock(index_buffer
);
1702 ok(SUCCEEDED(hr
), "Unlock failed (0x%08x)\n", hr
);
1703 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
1704 ok(SUCCEEDED(hr
), "SetRenderState D3DRS_LIGHTING failed (0x%08x)\n", hr
);
1705 hr
= IDirect3DDevice9_BeginScene(device
);
1706 ok(SUCCEEDED(hr
), "BeginScene failed (0x%08x)\n", hr
);
1708 /* NULL index buffer. Should fail */
1709 hr
= IDirect3DDevice9_SetIndices(device
, NULL
);
1710 ok(SUCCEEDED(hr
), "SetIndices failed (0x%08x)\n", hr
);
1711 hr
= IDirect3DDevice9_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, 0 /* BaseVertexIndex */, 0 /* MinIndex */,
1712 4 /* NumVerts */, 0 /* StartIndex */, 2 /*PrimCount */);
1713 ok(hr
== D3DERR_INVALIDCALL
, "DrawIndexedPrimitive returned 0x%08x, expected D3DERR_INVALIDCALL (0x%08x)\n",
1714 hr
, D3DERR_INVALIDCALL
);
1716 /* Valid index buffer, NULL vertex declaration. Should fail */
1717 hr
= IDirect3DDevice9_SetIndices(device
, index_buffer
);
1718 ok(SUCCEEDED(hr
), "SetIndices failed (0x%08x)\n", hr
);
1719 hr
= IDirect3DDevice9_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, 0 /* BaseVertexIndex */, 0 /* MinIndex */,
1720 4 /* NumVerts */, 0 /* StartIndex */, 2 /*PrimCount */);
1721 ok(hr
== D3DERR_INVALIDCALL
, "DrawIndexedPrimitive returned 0x%08x, expected D3DERR_INVALIDCALL (0x%08x)\n",
1722 hr
, D3DERR_INVALIDCALL
);
1724 /* Valid index buffer and vertex declaration. Should succeed */
1725 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, vertex_declaration
);
1726 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed (0x%08x)\n", hr
);
1727 hr
= IDirect3DDevice9_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, 0 /* BaseVertexIndex */, 0 /* MinIndex */,
1728 4 /* NumVerts */, 0 /* StartIndex */, 2 /*PrimCount */);
1729 ok(SUCCEEDED(hr
), "DrawIndexedPrimitive failed (0x%08x)\n", hr
);
1731 hr
= IDirect3DDevice9_EndScene(device
);
1732 ok(SUCCEEDED(hr
), "EndScene failed (0x%08x)\n", hr
);
1734 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
1735 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
1737 IDirect3DVertexBuffer9_Release(vertex_buffer
);
1738 IDirect3DIndexBuffer9_Release(index_buffer
);
1739 IDirect3DVertexDeclaration9_Release(vertex_declaration
);
1742 if (d3d9
) IDirect3D9_Release(d3d9
);
1743 if (device
) IDirect3DDevice9_Release(device
);
1744 if (hwnd
) DestroyWindow(hwnd
);
1747 static void test_null_stream(void)
1749 IDirect3DVertexBuffer9
*buffer
= NULL
;
1750 D3DPRESENT_PARAMETERS present_parameters
;
1751 IDirect3DDevice9
*device
= NULL
;
1755 IDirect3DVertexShader9
*shader
= NULL
;
1756 IDirect3DVertexDeclaration9
*decl
= NULL
;
1757 DWORD shader_code
[] = {
1758 0xfffe0101, /* vs_1_1 */
1759 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
1760 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
1761 0x0000ffff /* end */
1763 static const D3DVERTEXELEMENT9 decl_elements
[] = {
1764 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
1765 {1, 0, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
1769 d3d9
= pDirect3DCreate9( D3D_SDK_VERSION
);
1770 ok(d3d9
!= NULL
, "Failed to create IDirect3D9 object\n");
1771 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1772 ok(hwnd
!= NULL
, "Failed to create window\n");
1773 if (!d3d9
|| !hwnd
) goto cleanup
;
1775 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
1776 present_parameters
.Windowed
= TRUE
;
1777 present_parameters
.hDeviceWindow
= hwnd
;
1778 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1780 hr
= IDirect3D9_CreateDevice( d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1781 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
1782 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1785 skip("Failed to create a d3d device\n");
1789 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_code
, &shader
);
1791 skip("No vertex shader support\n");
1794 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &decl
);
1795 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateVertexDeclaration failed (0x%08x)\n", hr
);
1797 skip("Vertex declaration handling not possible.\n");
1800 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, 12 * sizeof(float), 0, 0, D3DPOOL_MANAGED
, &buffer
, NULL
);
1801 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateVertexBuffer failed (0x%08x)\n", hr
);
1803 skip("Vertex buffer handling not possible.\n");
1807 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, buffer
, 0, sizeof(float) * 3);
1808 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetStreamSource failed (0x%08x)\n", hr
);
1809 hr
= IDirect3DDevice9_SetStreamSource(device
, 1, NULL
, 0, 0);
1810 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetStreamSource failed (0x%08x)\n", hr
);
1811 hr
= IDirect3DDevice9_SetVertexShader(device
, shader
);
1812 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShader failed (0x%08x)\n", hr
);
1813 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl
);
1814 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexDeclaration failed (0x%08x)\n", hr
);
1816 hr
= IDirect3DDevice9_BeginScene(device
);
1817 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed (0x%08x)\n", hr
);
1819 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_POINTLIST
, 0, 1);
1820 ok(SUCCEEDED(hr
), "IDirect3DDevice9_DrawPrimitive failed (0x%08x)\n", hr
);
1822 hr
= IDirect3DDevice9_EndScene(device
);
1823 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed (0x%08x)\n", hr
);
1826 IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 0, 0);
1827 IDirect3DDevice9_SetVertexShader(device
, NULL
);
1828 IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
1831 if(decl
) IDirect3DVertexDeclaration9_Release(decl
);
1832 if(shader
) IDirect3DVertexShader9_Release(shader
);
1833 if(device
) IDirect3DDevice9_Release(device
);
1834 if(d3d9
) IDirect3D9_Release(d3d9
);
1837 static inline const char *debug_d3dpool(D3DPOOL pool
) {
1839 case D3DPOOL_DEFAULT
: return "D3DPOOL_DEFAULT";
1840 case D3DPOOL_SYSTEMMEM
: return "D3DPOOL_SYSTEMMEM";
1841 case D3DPOOL_SCRATCH
: return "D3DPOOL_SCRATCH";
1842 case D3DPOOL_MANAGED
: return "D3DPOOL_MANAGED";
1844 return "unknown pool";
1848 static void test_vertex_buffer_alignment(void)
1850 IDirect3DVertexBuffer9
*buffer
= NULL
;
1851 D3DPRESENT_PARAMETERS present_parameters
;
1852 IDirect3DDevice9
*device
= NULL
;
1856 D3DPOOL pools
[] = {D3DPOOL_DEFAULT
, D3DPOOL_SYSTEMMEM
, D3DPOOL_SCRATCH
, D3DPOOL_MANAGED
};
1857 DWORD sizes
[] = {1, 4, 16, 17, 32, 33, 64, 65, 1024, 1025, 1048576, 1048577};
1861 d3d9
= pDirect3DCreate9( D3D_SDK_VERSION
);
1862 ok(d3d9
!= NULL
, "Failed to create IDirect3D9 object\n");
1863 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1864 ok(hwnd
!= NULL
, "Failed to create window\n");
1865 if (!d3d9
|| !hwnd
) goto cleanup
;
1867 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
1868 present_parameters
.Windowed
= TRUE
;
1869 present_parameters
.hDeviceWindow
= hwnd
;
1870 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1872 hr
= IDirect3D9_CreateDevice( d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1873 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
1874 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1877 skip("Failed to create a d3d device\n");
1881 for(i
= 0; i
< (sizeof(sizes
) / sizeof(sizes
[0])); i
++) {
1882 for(j
= 0; j
< (sizeof(pools
) / sizeof(pools
[0])); j
++) {
1883 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, sizes
[i
], 0, 0, pools
[j
], &buffer
, NULL
);
1884 if(pools
[j
] == D3DPOOL_SCRATCH
) {
1885 ok(hr
== D3DERR_INVALIDCALL
, "Creating a D3DPOOL_SCRATCH buffer returned (0x%08x)\n", hr
);
1887 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateVertexBuffer failed (0x%08x). Pool = %s, size %d\n", hr
,
1888 debug_d3dpool(pools
[j
]), sizes
[i
]);
1890 if(FAILED(hr
)) continue;
1892 hr
= IDirect3DVertexBuffer9_Lock(buffer
, 0, 0, &data
, 0);
1893 ok(SUCCEEDED(hr
), "IDirect3DVertexBuffer9_Lock failed (0x%08x)\n", hr
);
1894 ok(((DWORD_PTR
) data
& 31) == 0, "Vertex buffer start address is not 32 byte aligned(size: %d, pool: %s, data: %p)\n",
1895 sizes
[i
], debug_d3dpool(pools
[j
]), data
);
1896 hr
= IDirect3DVertexBuffer9_Unlock(buffer
);
1897 ok(SUCCEEDED(hr
), "IDirect3DVertexBuffer9_Unlock failed (0x%08x)\n", hr
);
1899 if(buffer
) IDirect3DVertexBuffer9_Release(buffer
);
1904 if(d3d9
) IDirect3D9_Release(d3d9
);
1907 static void test_lights(void)
1909 D3DPRESENT_PARAMETERS present_parameters
;
1910 IDirect3DDevice9
*device
= NULL
;
1918 d3d9
= pDirect3DCreate9( D3D_SDK_VERSION
);
1919 ok(d3d9
!= NULL
, "Failed to create IDirect3D9 object\n");
1920 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1921 ok(hwnd
!= NULL
, "Failed to create window\n");
1922 if (!d3d9
|| !hwnd
) goto cleanup
;
1924 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
1925 present_parameters
.Windowed
= TRUE
;
1926 present_parameters
.hDeviceWindow
= hwnd
;
1927 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1929 hr
= IDirect3D9_CreateDevice( d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
1930 D3DCREATE_HARDWARE_VERTEXPROCESSING
| D3DCREATE_PUREDEVICE
, &present_parameters
, &device
);
1931 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
|| hr
== D3DERR_INVALIDCALL
,
1932 "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1935 skip("Failed to create a d3d device\n");
1939 memset(&caps
, 0, sizeof(caps
));
1940 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
1941 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetDeviceCaps failed with %08x\n", hr
);
1943 for(i
= 1; i
<= caps
.MaxActiveLights
; i
++) {
1944 hr
= IDirect3DDevice9_LightEnable(device
, i
, TRUE
);
1945 ok(hr
== D3D_OK
, "Enabling light %u failed with %08x\n", i
, hr
);
1946 hr
= IDirect3DDevice9_GetLightEnable(device
, i
, &enabled
);
1947 ok(hr
== D3D_OK
, "GetLightEnable on light %u failed with %08x\n", i
, hr
);
1948 ok(enabled
, "Light %d is %s\n", i
, enabled
? "enabled" : "disabled");
1951 /* TODO: Test the rendering results in this situation */
1952 hr
= IDirect3DDevice9_LightEnable(device
, i
+ 1, TRUE
);
1953 ok(hr
== D3D_OK
, "Enabling one light more than supported returned %08x\n", hr
);
1954 hr
= IDirect3DDevice9_GetLightEnable(device
, i
+ 1, &enabled
);
1955 ok(hr
== D3D_OK
, "GetLightEnable on light %u failed with %08x\n", i
+ 1, hr
);
1956 ok(enabled
, "Light %d is %s\n", i
+ 1, enabled
? "enabled" : "disabled");
1957 hr
= IDirect3DDevice9_LightEnable(device
, i
+ 1, FALSE
);
1958 ok(hr
== D3D_OK
, "Disabling the additional returned %08x\n", hr
);
1960 for(i
= 1; i
<= caps
.MaxActiveLights
; i
++) {
1961 hr
= IDirect3DDevice9_LightEnable(device
, i
, FALSE
);
1962 ok(hr
== D3D_OK
, "Disabling light %u failed with %08x\n", i
, hr
);
1966 if(device
) IDirect3DDevice9_Release(device
);
1967 if(d3d9
) IDirect3D9_Release(d3d9
);
1970 static void test_set_stream_source(void)
1972 D3DPRESENT_PARAMETERS present_parameters
;
1973 IDirect3DDevice9
*device
= NULL
;
1977 IDirect3DVertexBuffer9
*pVertexBuffer
= NULL
;
1979 d3d9
= pDirect3DCreate9( D3D_SDK_VERSION
);
1980 ok(d3d9
!= NULL
, "Failed to create IDirect3D9 object\n");
1981 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1982 ok(hwnd
!= NULL
, "Failed to create window\n");
1983 if (!d3d9
|| !hwnd
) goto cleanup
;
1985 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
1986 present_parameters
.Windowed
= TRUE
;
1987 present_parameters
.hDeviceWindow
= hwnd
;
1988 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1990 hr
= IDirect3D9_CreateDevice( d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
1991 D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
1992 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
|| hr
== D3DERR_INVALIDCALL
,
1993 "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1996 hr
= IDirect3D9_CreateDevice( d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_REF
, hwnd
,
1997 D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
1998 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
2001 skip("Failed to create a d3d device\n");
2006 hr
= IDirect3DDevice9_CreateVertexBuffer( device
, 512, 0, 0, D3DPOOL_DEFAULT
, &pVertexBuffer
, NULL
);
2007 ok(hr
== D3D_OK
, "Failed to create a vertex buffer, hr = %08x\n", hr
);
2008 if (SUCCEEDED(hr
)) {
2009 /* Some cards(Geforce 7400 at least) accept non-aligned offsets, others(radeon 9000 verified) reject it,
2010 * so accept both results. Wine currently rejects this to be able to optimize the vbo conversion, but writes
2013 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, pVertexBuffer
, 0, 32);
2014 ok(hr
== D3D_OK
, "Failed to set the stream source, offset 0, hr = %08x\n", hr
);
2015 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, pVertexBuffer
, 1, 32);
2016 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Unexpected result when setting the stream source, offset 1, hr = %08x\n", hr
);
2017 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, pVertexBuffer
, 2, 32);
2018 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Unexpected result when setting the stream source, offset 2, hr = %08x\n", hr
);
2019 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, pVertexBuffer
, 3, 32);
2020 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Unexpected result when setting the stream source, offset 3, hr = %08x\n", hr
);
2021 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, pVertexBuffer
, 4, 32);
2022 ok(hr
== D3D_OK
, "Failed to set the stream source, offset 4, hr = %08x\n", hr
);
2024 /* Try to set the NULL buffer with an offset and stride 0 */
2025 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 0, 0);
2026 ok(hr
== D3D_OK
, "Failed to set the stream source, offset 0, hr = %08x\n", hr
);
2027 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 1, 0);
2028 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Unexpected result when setting the stream source, offset 1, hr = %08x\n", hr
);
2029 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 2, 0);
2030 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Unexpected result when setting the stream source, offset 2, hr = %08x\n", hr
);
2031 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 3, 0);
2032 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Unexpected result when setting the stream source, offset 3, hr = %08x\n", hr
);
2033 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 4, 0);
2034 ok(hr
== D3D_OK
, "Failed to set the stream source, offset 4, hr = %08x\n", hr
);
2036 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 0, 0);
2037 ok(hr
== D3D_OK
, "Failed to set the stream source, offset 4, hr = %08x\n", hr
);
2039 if(pVertexBuffer
) IDirect3DDevice9_Release(pVertexBuffer
);
2041 if(device
) IDirect3DDevice9_Release(device
);
2042 if(d3d9
) IDirect3D9_Release(d3d9
);
2046 D3DFORMAT DisplayFormat
;
2047 D3DFORMAT BackBufferFormat
;
2051 struct formats r5g6b5_format_list
[] =
2053 { D3DFMT_R5G6B5
, D3DFMT_R5G6B5
, TRUE
},
2054 { D3DFMT_R5G6B5
, D3DFMT_X1R5G5B5
, FALSE
},
2055 { D3DFMT_R5G6B5
, D3DFMT_A1R5G5B5
, FALSE
},
2056 { D3DFMT_R5G6B5
, D3DFMT_X8R8G8B8
, FALSE
},
2057 { D3DFMT_R5G6B5
, D3DFMT_A8R8G8B8
, FALSE
},
2061 struct formats x1r5g5b5_format_list
[] =
2063 { D3DFMT_X1R5G5B5
, D3DFMT_R5G6B5
, FALSE
},
2064 { D3DFMT_X1R5G5B5
, D3DFMT_X1R5G5B5
, TRUE
},
2065 { D3DFMT_X1R5G5B5
, D3DFMT_A1R5G5B5
, TRUE
},
2066 { D3DFMT_X1R5G5B5
, D3DFMT_X8R8G8B8
, FALSE
},
2067 { D3DFMT_X1R5G5B5
, D3DFMT_A8R8G8B8
, FALSE
},
2069 /* A1R5G5B5 should not be usable as a display format, it is backbuffer-only */
2070 { D3DFMT_A1R5G5B5
, D3DFMT_R5G6B5
, FALSE
},
2071 { D3DFMT_A1R5G5B5
, D3DFMT_X1R5G5B5
, FALSE
},
2072 { D3DFMT_A1R5G5B5
, D3DFMT_A1R5G5B5
, FALSE
},
2073 { D3DFMT_A1R5G5B5
, D3DFMT_X8R8G8B8
, FALSE
},
2074 { D3DFMT_A1R5G5B5
, D3DFMT_A8R8G8B8
, FALSE
},
2078 struct formats x8r8g8b8_format_list
[] =
2080 { D3DFMT_X8R8G8B8
, D3DFMT_R5G6B5
, FALSE
},
2081 { D3DFMT_X8R8G8B8
, D3DFMT_X1R5G5B5
, FALSE
},
2082 { D3DFMT_X8R8G8B8
, D3DFMT_A1R5G5B5
, FALSE
},
2083 { D3DFMT_X8R8G8B8
, D3DFMT_X8R8G8B8
, TRUE
},
2084 { D3DFMT_X8R8G8B8
, D3DFMT_A8R8G8B8
, TRUE
},
2086 /* A1R8G8B8 should not be usable as a display format, it is backbuffer-only */
2087 { D3DFMT_A8R8G8B8
, D3DFMT_R5G6B5
, FALSE
},
2088 { D3DFMT_A8R8G8B8
, D3DFMT_X1R5G5B5
, FALSE
},
2089 { D3DFMT_A8R8G8B8
, D3DFMT_A1R5G5B5
, FALSE
},
2090 { D3DFMT_A8R8G8B8
, D3DFMT_X8R8G8B8
, FALSE
},
2091 { D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
, FALSE
},
2095 static void test_display_formats(void)
2097 /* Direct3D9 offers 4 display formats R5G6B5, X1R5G5B5, X8R8G8B8 and A2R10G10B10.
2098 * Next to these there are 6 different backbuffer formats. Only a fixed number of
2099 * combinations are possible in FULLSCREEN mode. In windowed mode more combinations are
2100 * allowed due to depth conversion and this is likely driver dependent.
2101 * This test checks which combinations are possible in fullscreen mode and this should not be driver dependent.
2102 * TODO: handle A2R10G10B10 but what hardware supports it? Parhelia? It is very rare. */
2104 UINT Adapter
= D3DADAPTER_DEFAULT
;
2105 D3DDEVTYPE DeviceType
= D3DDEVTYPE_HAL
;
2109 IDirect3D9
*d3d9
= pDirect3DCreate9( D3D_SDK_VERSION
);
2110 ok(d3d9
!= NULL
, "Failed to create IDirect3D9 object\n");
2113 nmodes
= IDirect3D9_GetAdapterModeCount(d3d9
, D3DADAPTER_DEFAULT
, D3DFMT_R5G6B5
);
2115 skip("Display format R5G6B5 not supported, skipping\n");
2117 trace("Testing display format R5G6B5\n");
2118 for(i
=0; r5g6b5_format_list
[i
].DisplayFormat
!= 0; i
++)
2120 hr
= IDirect3D9_CheckDeviceType(d3d9
, Adapter
, DeviceType
, r5g6b5_format_list
[i
].DisplayFormat
, r5g6b5_format_list
[i
].BackBufferFormat
, FALSE
);
2122 if(r5g6b5_format_list
[i
].shouldPass
)
2124 broken(hr
== D3DERR_NOTAVAILABLE
),
2125 "format %d %d didn't pass with hr=%#08x\n", r5g6b5_format_list
[i
].DisplayFormat
, r5g6b5_format_list
[i
].BackBufferFormat
, hr
);
2127 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
);
2131 nmodes
= IDirect3D9_GetAdapterModeCount(d3d9
, D3DADAPTER_DEFAULT
, D3DFMT_X1R5G5B5
);
2133 skip("Display format X1R5G5B5 not supported, skipping\n");
2135 trace("Testing display format X1R5G5B5\n");
2136 for(i
=0; x1r5g5b5_format_list
[i
].DisplayFormat
!= 0; i
++)
2138 hr
= IDirect3D9_CheckDeviceType(d3d9
, Adapter
, DeviceType
, x1r5g5b5_format_list
[i
].DisplayFormat
, x1r5g5b5_format_list
[i
].BackBufferFormat
, FALSE
);
2140 if(x1r5g5b5_format_list
[i
].shouldPass
)
2141 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
);
2143 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
);
2147 nmodes
= IDirect3D9_GetAdapterModeCount(d3d9
, D3DADAPTER_DEFAULT
, D3DFMT_X8R8G8B8
);
2149 skip("Display format X8R8G8B8 not supported, skipping\n");
2151 trace("Testing display format X8R8G8B8\n");
2152 for(i
=0; x8r8g8b8_format_list
[i
].DisplayFormat
!= 0; i
++)
2154 hr
= IDirect3D9_CheckDeviceType(d3d9
, Adapter
, DeviceType
, x8r8g8b8_format_list
[i
].DisplayFormat
, x8r8g8b8_format_list
[i
].BackBufferFormat
, FALSE
);
2156 if(x8r8g8b8_format_list
[i
].shouldPass
)
2158 broken(hr
== D3DERR_NOTAVAILABLE
),
2159 "format %d %d didn't pass with hr=%#08x\n", x8r8g8b8_format_list
[i
].DisplayFormat
, x8r8g8b8_format_list
[i
].BackBufferFormat
, hr
);
2161 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
);
2165 if(d3d9
) IDirect3D9_Release(d3d9
);
2168 static void test_scissor_size(void)
2170 IDirect3D9
*d3d9_ptr
= 0;
2172 static const struct {
2173 int winx
; int winy
; int backx
; int backy
; BOOL window
;
2174 } scts
[] = { /* scissor tests */
2175 {800, 600, 640, 480, TRUE
},
2176 {800, 600, 640, 480, FALSE
},
2177 {640, 480, 800, 600, TRUE
},
2178 {640, 480, 800, 600, FALSE
},
2181 d3d9_ptr
= pDirect3DCreate9(D3D_SDK_VERSION
);
2182 ok(d3d9_ptr
!= NULL
, "Failed to create IDirect3D9 object\n");
2184 skip("Failed to create IDirect3D9 object\n");
2188 for(i
=0; i
<sizeof(scts
)/sizeof(scts
[0]); i
++) {
2189 IDirect3DDevice9
*device_ptr
= 0;
2190 D3DPRESENT_PARAMETERS present_parameters
;
2196 wc
.lpfnWndProc
= DefWindowProc
;
2197 wc
.lpszClassName
= "d3d9_test_wc";
2200 hwnd
= CreateWindow("d3d9_test_wc", "d3d9_test",
2201 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, scts
[i
].winx
, scts
[i
].winy
, 0, 0, 0, 0);
2203 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
2204 present_parameters
.Windowed
= scts
[i
].window
;
2205 present_parameters
.hDeviceWindow
= hwnd
;
2206 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2207 present_parameters
.BackBufferWidth
= scts
[i
].backx
;
2208 present_parameters
.BackBufferHeight
= scts
[i
].backy
;
2209 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
2210 present_parameters
.EnableAutoDepthStencil
= TRUE
;
2211 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
2213 hr
= IDirect3D9_CreateDevice(d3d9_ptr
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, present_parameters
.hDeviceWindow
, D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device_ptr
);
2215 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D16
;
2216 hr
= IDirect3D9_CreateDevice(d3d9_ptr
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, present_parameters
.hDeviceWindow
, D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device_ptr
);
2218 hr
= IDirect3D9_CreateDevice(d3d9_ptr
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, present_parameters
.hDeviceWindow
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device_ptr
);
2221 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D_CreateDevice returned: %08x\n", hr
);
2225 DestroyWindow(hwnd
);
2226 skip("Creating the device failed\n");
2230 /* Check for the default scissor rect size */
2231 hr
= IDirect3DDevice9_GetScissorRect(device_ptr
, &scissorrect
);
2232 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetScissorRect failed with: %08x\n", hr
);
2233 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
);
2235 /* check the scissorrect values after a reset */
2236 present_parameters
.BackBufferWidth
= 800;
2237 present_parameters
.BackBufferHeight
= 600;
2238 hr
= IDirect3DDevice9_Reset(device_ptr
, &present_parameters
);
2239 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
2240 hr
= IDirect3DDevice9_TestCooperativeLevel(device_ptr
);
2241 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
2243 hr
= IDirect3DDevice9_GetScissorRect(device_ptr
, &scissorrect
);
2244 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetScissorRect failed with: %08x\n", hr
);
2245 ok(scissorrect
.right
== 800 && scissorrect
.bottom
== 600 && scissorrect
.top
== 0 && scissorrect
.left
== 0, "Scissorrect missmatch (%d, %d) should be (%d, %d)\n", scissorrect
.right
, scissorrect
.bottom
, 800, 600);
2250 ref
= IDirect3DDevice9_Release(device_ptr
);
2251 DestroyWindow(hwnd
);
2252 ok(ref
== 0, "The device was not properly freed: refcount %u\n", ref
);
2257 if(d3d9_ptr
) IDirect3D9_Release(d3d9_ptr
);
2264 HMODULE d3d9_handle
= LoadLibraryA( "d3d9.dll" );
2267 skip("Could not load d3d9.dll\n");
2271 pDirect3DCreate9
= (void *)GetProcAddress( d3d9_handle
, "Direct3DCreate9" );
2272 ok(pDirect3DCreate9
!= NULL
, "Failed to get address of Direct3DCreate9\n");
2273 if (pDirect3DCreate9
)
2275 IDirect3D9
*d3d9
= pDirect3DCreate9( D3D_SDK_VERSION
);
2278 skip("could not create D3D9 object\n");
2281 IDirect3D9_Release(d3d9
);
2283 test_display_formats();
2284 test_display_modes();
2287 test_mipmap_levels();
2288 test_checkdevicemultisampletype();
2293 test_depthstenciltest();
2294 test_draw_indexed();
2296 test_vertex_buffer_alignment();
2298 test_set_stream_source();
2299 test_scissor_size();