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 static IDirect3DDevice9
*create_device(IDirect3D9
*d3d9
, HWND device_window
, HWND focus_window
, BOOL windowed
)
37 D3DPRESENT_PARAMETERS present_parameters
= {0};
38 IDirect3DDevice9
*device
;
40 present_parameters
.Windowed
= windowed
;
41 present_parameters
.hDeviceWindow
= device_window
;
42 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
43 present_parameters
.BackBufferWidth
= 640;
44 present_parameters
.BackBufferHeight
= 480;
45 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
46 present_parameters
.EnableAutoDepthStencil
= TRUE
;
47 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
49 if (SUCCEEDED(IDirect3D9_CreateDevice(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, focus_window
,
50 D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device
))) return device
;
52 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D16
;
53 if (SUCCEEDED(IDirect3D9_CreateDevice(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, focus_window
,
54 D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device
))) return device
;
56 if (SUCCEEDED(IDirect3D9_CreateDevice(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, focus_window
,
57 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
))) return device
;
62 #define CHECK_CALL(r,c,d,rc) \
64 int tmp1 = get_refcount( (IUnknown *)d ); \
66 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
68 trace("%s failed: %08x\n", c, r); \
71 #define CHECK_RELEASE(obj,d,rc) \
73 int tmp1, rc_new = rc; \
74 IUnknown_Release( obj ); \
75 tmp1 = get_refcount( (IUnknown *)d ); \
76 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
79 #define CHECK_REFCOUNT(obj,rc) \
82 int count = get_refcount( (IUnknown *)obj ); \
83 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
86 #define CHECK_RELEASE_REFCOUNT(obj,rc) \
89 int count = IUnknown_Release( (IUnknown *)obj ); \
90 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
93 #define CHECK_ADDREF_REFCOUNT(obj,rc) \
96 int count = IUnknown_AddRef( (IUnknown *)obj ); \
97 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
100 #define CHECK_SURFACE_CONTAINER(obj,iid,expected) \
102 void *container_ptr = (void *)0x1337c0d3; \
103 hr = IDirect3DSurface9_GetContainer(obj, &iid, &container_ptr); \
104 ok(SUCCEEDED(hr) && container_ptr == expected, "GetContainer returned: hr %#x, container_ptr %p. " \
105 "Expected hr %#x, container_ptr %p\n", hr, container_ptr, S_OK, expected); \
106 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr); \
109 static void check_mipmap_levels(IDirect3DDevice9
*device
, UINT width
, UINT height
, UINT count
)
111 IDirect3DBaseTexture9
* texture
= NULL
;
112 HRESULT hr
= IDirect3DDevice9_CreateTexture( device
, width
, height
, 0, 0,
113 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, (IDirect3DTexture9
**) &texture
, NULL
);
116 DWORD levels
= IDirect3DBaseTexture9_GetLevelCount(texture
);
117 ok(levels
== count
, "Invalid level count. Expected %d got %u\n", count
, levels
);
119 trace("CreateTexture failed: %08x\n", hr
);
121 if (texture
) IUnknown_Release( texture
);
124 static void test_mipmap_levels(void)
130 IDirect3D9
*pD3d
= NULL
;
131 IDirect3DDevice9
*pDevice
= NULL
;
132 D3DPRESENT_PARAMETERS d3dpp
;
133 D3DDISPLAYMODE d3ddm
;
135 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
136 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
137 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
138 ok(hwnd
!= NULL
, "Failed to create window\n");
139 if (!pD3d
|| !hwnd
) goto cleanup
;
141 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
142 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
143 d3dpp
.Windowed
= TRUE
;
144 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
145 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
147 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_NULLREF
, hwnd
,
148 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
149 ok(SUCCEEDED(hr
) || hr
== D3DERR_NOTAVAILABLE
, "Failed to create IDirect3D9Device (%08x)\n", hr
);
151 skip("failed to create a d3d device\n");
155 check_mipmap_levels(pDevice
, 32, 32, 6);
156 check_mipmap_levels(pDevice
, 256, 1, 9);
157 check_mipmap_levels(pDevice
, 1, 256, 9);
158 check_mipmap_levels(pDevice
, 1, 1, 1);
163 UINT refcount
= IUnknown_Release( pDevice
);
164 ok(!refcount
, "Device has %u references left.\n", refcount
);
166 if (pD3d
) IUnknown_Release( pD3d
);
167 DestroyWindow( hwnd
);
170 static void test_checkdevicemultisampletype(void)
176 IDirect3D9
*pD3d
= NULL
;
177 IDirect3DDevice9
*pDevice
= NULL
;
178 D3DPRESENT_PARAMETERS d3dpp
;
179 D3DDISPLAYMODE d3ddm
;
182 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
183 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
184 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
185 ok(hwnd
!= NULL
, "Failed to create window\n");
186 if (!pD3d
|| !hwnd
) goto cleanup
;
188 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
189 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
190 d3dpp
.Windowed
= TRUE
;
191 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
192 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
194 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_NULLREF
, hwnd
,
195 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
196 ok(SUCCEEDED(hr
) || hr
== D3DERR_NOTAVAILABLE
, "Failed to create IDirect3D9Device (%08x)\n", hr
);
198 skip("failed to create a d3d device\n");
204 hr
= IDirect3D9_CheckDeviceMultiSampleType(pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
, TRUE
,
205 D3DMULTISAMPLE_NONE
, &qualityLevels
);
206 ok(SUCCEEDED(hr
) || hr
== D3DERR_NOTAVAILABLE
, "CheckDeviceMultiSampleType failed with (%08x)\n", hr
);
207 if(hr
== D3DERR_NOTAVAILABLE
)
209 skip("IDirect3D9_CheckDeviceMultiSampleType not available\n");
212 ok(qualityLevels
== 1,"qualitylevel is not 1 but %d\n",qualityLevels
);
214 hr
= IDirect3D9_CheckDeviceMultiSampleType(pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
, FALSE
,
215 D3DMULTISAMPLE_NONE
, &qualityLevels
);
216 ok(SUCCEEDED(hr
), "CheckDeviceMultiSampleType failed with (%08x)\n", hr
);
217 ok(qualityLevels
== 1,"qualitylevel is not 1 but %d\n",qualityLevels
);
222 UINT refcount
= IUnknown_Release( pDevice
);
223 ok(!refcount
, "Device has %u references left.\n", refcount
);
225 if (pD3d
) IUnknown_Release( pD3d
);
226 DestroyWindow( hwnd
);
229 static void test_swapchain(void)
233 IDirect3D9
*pD3d
= NULL
;
234 IDirect3DDevice9
*pDevice
= NULL
;
235 IDirect3DSwapChain9
*swapchain0
= NULL
;
236 IDirect3DSwapChain9
*swapchain1
= NULL
;
237 IDirect3DSwapChain9
*swapchain2
= NULL
;
238 IDirect3DSwapChain9
*swapchain3
= NULL
;
239 IDirect3DSwapChain9
*swapchainX
= NULL
;
240 IDirect3DSurface9
*backbuffer
= NULL
;
241 D3DPRESENT_PARAMETERS d3dpp
;
242 D3DDISPLAYMODE d3ddm
;
244 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
245 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
246 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
247 ok(hwnd
!= NULL
, "Failed to create window\n");
248 if (!pD3d
|| !hwnd
) goto cleanup
;
250 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
251 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
252 d3dpp
.Windowed
= TRUE
;
253 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
254 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
255 d3dpp
.BackBufferCount
= 0;
257 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
258 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
259 ok(hr
== S_OK
|| hr
== D3DERR_NOTAVAILABLE
,
260 "Failed to create IDirect3D9Device (%08x)\n", hr
);
261 if (FAILED(hr
)) goto cleanup
;
263 /* Check if the back buffer count was modified */
264 ok(d3dpp
.BackBufferCount
== 1, "The back buffer count in the presentparams struct is %d\n", d3dpp
.BackBufferCount
);
266 /* Get the implicit swapchain */
267 hr
= IDirect3DDevice9_GetSwapChain(pDevice
, 0, &swapchain0
);
268 ok(SUCCEEDED(hr
), "Failed to get the impicit swapchain (%08x)\n", hr
);
269 if(swapchain0
) IDirect3DSwapChain9_Release(swapchain0
);
271 /* Check if there is a back buffer */
272 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain0
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
273 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
274 ok(backbuffer
!= NULL
, "The back buffer is NULL\n");
275 if(backbuffer
) IDirect3DSurface9_Release(backbuffer
);
277 /* Try to get a nonexistent swapchain */
278 hr
= IDirect3DDevice9_GetSwapChain(pDevice
, 1, &swapchainX
);
279 ok(hr
== D3DERR_INVALIDCALL
, "GetSwapChain on an nonexistent swapchain returned (%08x)\n", hr
);
280 ok(swapchainX
== NULL
, "Swapchain 1 is %p\n", swapchainX
);
281 if(swapchainX
) IDirect3DSwapChain9_Release(swapchainX
);
283 /* Create a bunch of swapchains */
284 d3dpp
.BackBufferCount
= 0;
285 hr
= IDirect3DDevice9_CreateAdditionalSwapChain(pDevice
, &d3dpp
, &swapchain1
);
286 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%08x)\n", hr
);
287 ok(d3dpp
.BackBufferCount
== 1, "The back buffer count in the presentparams struct is %d\n", d3dpp
.BackBufferCount
);
289 d3dpp
.BackBufferCount
= 1;
290 hr
= IDirect3DDevice9_CreateAdditionalSwapChain(pDevice
, &d3dpp
, &swapchain2
);
291 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%08x)\n", hr
);
293 d3dpp
.BackBufferCount
= 2;
294 hr
= IDirect3DDevice9_CreateAdditionalSwapChain(pDevice
, &d3dpp
, &swapchain3
);
295 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%08x)\n", hr
);
297 /* Swapchain 3, created with backbuffercount 2 */
298 backbuffer
= (void *) 0xdeadbeef;
299 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain3
, 0, 0, &backbuffer
);
300 ok(SUCCEEDED(hr
), "Failed to get the 1st back buffer (%08x)\n", hr
);
301 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
302 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
304 backbuffer
= (void *) 0xdeadbeef;
305 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain3
, 1, 0, &backbuffer
);
306 ok(SUCCEEDED(hr
), "Failed to get the 2nd back buffer (%08x)\n", hr
);
307 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
308 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
310 backbuffer
= (void *) 0xdeadbeef;
311 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain3
, 2, 0, &backbuffer
);
312 ok(hr
== D3DERR_INVALIDCALL
, "GetBackBuffer returned %08x\n", hr
);
313 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
314 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
316 backbuffer
= (void *) 0xdeadbeef;
317 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain3
, 3, 0, &backbuffer
);
318 ok(FAILED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
319 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
320 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
323 /* Check the back buffers of the swapchains */
324 /* Swapchain 1, created with backbuffercount 0 */
325 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain1
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
326 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
327 ok(backbuffer
!= NULL
, "The back buffer is NULL (%08x)\n", hr
);
328 if(backbuffer
) IDirect3DSurface9_Release(backbuffer
);
330 backbuffer
= (void *) 0xdeadbeef;
331 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain1
, 1, 0, &backbuffer
);
332 ok(FAILED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
333 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
334 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
336 /* Swapchain 2 - created with backbuffercount 1 */
337 backbuffer
= (void *) 0xdeadbeef;
338 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain2
, 0, 0, &backbuffer
);
339 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
340 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
341 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
343 backbuffer
= (void *) 0xdeadbeef;
344 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain2
, 1, 0, &backbuffer
);
345 ok(hr
== D3DERR_INVALIDCALL
, "GetBackBuffer returned %08x\n", hr
);
346 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
347 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
349 backbuffer
= (void *) 0xdeadbeef;
350 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain2
, 2, 0, &backbuffer
);
351 ok(FAILED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
352 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
353 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
355 /* Try getSwapChain on a manually created swapchain
356 * it should fail, apparently GetSwapChain only returns implicit swapchains
358 swapchainX
= (void *) 0xdeadbeef;
359 hr
= IDirect3DDevice9_GetSwapChain(pDevice
, 1, &swapchainX
);
360 ok(hr
== D3DERR_INVALIDCALL
, "Failed to get the second swapchain (%08x)\n", hr
);
361 ok(swapchainX
== NULL
, "The swapchain pointer is %p\n", swapchainX
);
362 if(swapchainX
&& swapchainX
!= (void *) 0xdeadbeef ) IDirect3DSwapChain9_Release(swapchainX
);
365 if(swapchain1
) IDirect3DSwapChain9_Release(swapchain1
);
366 if(swapchain2
) IDirect3DSwapChain9_Release(swapchain2
);
367 if(swapchain3
) IDirect3DSwapChain9_Release(swapchain3
);
370 UINT refcount
= IDirect3DDevice9_Release(pDevice
);
371 ok(!refcount
, "Device has %u references left.\n", refcount
);
373 if (pD3d
) IDirect3D9_Release(pD3d
);
374 DestroyWindow( hwnd
);
377 /* Shared between two functions */
378 static const DWORD simple_vs
[] = {0xFFFE0101, /* vs_1_1 */
379 0x0000001F, 0x80000000, 0x900F0000, /* dcl_position0 v0 */
380 0x00000009, 0xC0010000, 0x90E40000, 0xA0E40000, /* dp4 oPos.x, v0, c0 */
381 0x00000009, 0xC0020000, 0x90E40000, 0xA0E40001, /* dp4 oPos.y, v0, c1 */
382 0x00000009, 0xC0040000, 0x90E40000, 0xA0E40002, /* dp4 oPos.z, v0, c2 */
383 0x00000009, 0xC0080000, 0x90E40000, 0xA0E40003, /* dp4 oPos.w, v0, c3 */
384 0x0000FFFF}; /* END */
386 static void test_refcount(void)
390 IDirect3D9
*pD3d
= NULL
;
391 IDirect3DDevice9
*pDevice
= NULL
;
392 IDirect3DVertexBuffer9
*pVertexBuffer
= NULL
;
393 IDirect3DIndexBuffer9
*pIndexBuffer
= NULL
;
394 IDirect3DVertexDeclaration9
*pVertexDeclaration
= NULL
;
395 IDirect3DVertexShader9
*pVertexShader
= NULL
;
396 IDirect3DPixelShader9
*pPixelShader
= NULL
;
397 IDirect3DCubeTexture9
*pCubeTexture
= NULL
;
398 IDirect3DTexture9
*pTexture
= NULL
;
399 IDirect3DVolumeTexture9
*pVolumeTexture
= NULL
;
400 IDirect3DVolume9
*pVolumeLevel
= NULL
;
401 IDirect3DSurface9
*pStencilSurface
= NULL
;
402 IDirect3DSurface9
*pOffscreenSurface
= NULL
;
403 IDirect3DSurface9
*pRenderTarget
= NULL
;
404 IDirect3DSurface9
*pRenderTarget2
= NULL
;
405 IDirect3DSurface9
*pRenderTarget3
= NULL
;
406 IDirect3DSurface9
*pTextureLevel
= NULL
;
407 IDirect3DSurface9
*pBackBuffer
= NULL
;
408 IDirect3DStateBlock9
*pStateBlock
= NULL
;
409 IDirect3DStateBlock9
*pStateBlock1
= NULL
;
410 IDirect3DSwapChain9
*pSwapChain
= NULL
;
411 IDirect3DQuery9
*pQuery
= NULL
;
412 D3DPRESENT_PARAMETERS d3dpp
;
413 D3DDISPLAYMODE d3ddm
;
414 int refcount
= 0, tmp
;
416 D3DVERTEXELEMENT9 decl
[] =
420 static DWORD simple_ps
[] = {0xFFFF0101, /* ps_1_1 */
421 0x00000051, 0xA00F0001, 0x3F800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
422 0x00000042, 0xB00F0000, /* tex t0 */
423 0x00000008, 0x800F0000, 0xA0E40001, 0xA0E40000, /* dp3 r0, c1, c0 */
424 0x00000005, 0x800F0000, 0x90E40000, 0x80E40000, /* mul r0, v0, r0 */
425 0x00000005, 0x800F0000, 0xB0E40000, 0x80E40000, /* mul r0, t0, r0 */
426 0x0000FFFF}; /* END */
429 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
430 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
431 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
432 ok(hwnd
!= NULL
, "Failed to create window\n");
433 if (!pD3d
|| !hwnd
) goto cleanup
;
435 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
436 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
437 d3dpp
.Windowed
= TRUE
;
438 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
439 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
440 d3dpp
.EnableAutoDepthStencil
= TRUE
;
441 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
443 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
444 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
445 ok(hr
== S_OK
|| hr
== D3DERR_NOTAVAILABLE
,
446 "Failed to create IDirect3D9Device (%08x)\n", hr
);
447 if (FAILED(hr
)) goto cleanup
;
449 refcount
= get_refcount( (IUnknown
*)pDevice
);
450 ok(refcount
== 1, "Invalid device RefCount %d\n", refcount
);
453 * Check refcount of implicit surfaces and implicit swapchain. Findings:
454 * - the container is the device OR swapchain
455 * - they hold a reference to the device
456 * - they are created with a refcount of 0 (Get/Release returns original refcount)
457 * - they are not freed if refcount reaches 0.
458 * - the refcount is not forwarded to the container.
460 hr
= IDirect3DDevice9_GetSwapChain(pDevice
, 0, &pSwapChain
);
461 CHECK_CALL( hr
, "GetSwapChain", pDevice
, ++refcount
);
464 CHECK_REFCOUNT( pSwapChain
, 1);
466 hr
= IDirect3DDevice9_GetRenderTarget(pDevice
, 0, &pRenderTarget
);
467 CHECK_CALL( hr
, "GetRenderTarget", pDevice
, ++refcount
);
468 CHECK_REFCOUNT( pSwapChain
, 1);
471 CHECK_SURFACE_CONTAINER( pRenderTarget
, IID_IDirect3DSwapChain9
, pSwapChain
);
472 CHECK_REFCOUNT( pRenderTarget
, 1);
474 CHECK_ADDREF_REFCOUNT(pRenderTarget
, 2);
475 CHECK_REFCOUNT(pDevice
, refcount
);
476 CHECK_RELEASE_REFCOUNT(pRenderTarget
, 1);
477 CHECK_REFCOUNT(pDevice
, refcount
);
479 hr
= IDirect3DDevice9_GetRenderTarget(pDevice
, 0, &pRenderTarget
);
480 CHECK_CALL( hr
, "GetRenderTarget", pDevice
, refcount
);
481 CHECK_REFCOUNT( pRenderTarget
, 2);
482 CHECK_RELEASE_REFCOUNT( pRenderTarget
, 1);
483 CHECK_RELEASE_REFCOUNT( pRenderTarget
, 0);
484 CHECK_REFCOUNT( pDevice
, --refcount
);
486 /* The render target is released with the device, so AddRef with refcount=0 is fine here. */
487 CHECK_ADDREF_REFCOUNT(pRenderTarget
, 1);
488 CHECK_REFCOUNT(pDevice
, ++refcount
);
489 CHECK_RELEASE_REFCOUNT(pRenderTarget
, 0);
490 CHECK_REFCOUNT(pDevice
, --refcount
);
493 /* Render target and back buffer are identical. */
494 hr
= IDirect3DDevice9_GetBackBuffer(pDevice
, 0, 0, 0, &pBackBuffer
);
495 CHECK_CALL( hr
, "GetBackBuffer", pDevice
, ++refcount
);
498 CHECK_RELEASE_REFCOUNT(pBackBuffer
, 0);
499 ok(pRenderTarget
== pBackBuffer
, "RenderTarget=%p and BackBuffer=%p should be the same.\n",
500 pRenderTarget
, pBackBuffer
);
503 CHECK_REFCOUNT( pDevice
, --refcount
);
505 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &pStencilSurface
);
506 CHECK_CALL( hr
, "GetDepthStencilSurface", pDevice
, ++refcount
);
507 CHECK_REFCOUNT( pSwapChain
, 1);
510 CHECK_SURFACE_CONTAINER( pStencilSurface
, IID_IDirect3DDevice9
, pDevice
);
511 CHECK_REFCOUNT( pStencilSurface
, 1);
513 CHECK_ADDREF_REFCOUNT(pStencilSurface
, 2);
514 CHECK_REFCOUNT(pDevice
, refcount
);
515 CHECK_RELEASE_REFCOUNT(pStencilSurface
, 1);
516 CHECK_REFCOUNT(pDevice
, refcount
);
518 CHECK_RELEASE_REFCOUNT( pStencilSurface
, 0);
519 CHECK_REFCOUNT( pDevice
, --refcount
);
521 /* The stencil surface is released with the device, so AddRef with refcount=0 is fine here. */
522 CHECK_ADDREF_REFCOUNT(pStencilSurface
, 1);
523 CHECK_REFCOUNT(pDevice
, ++refcount
);
524 CHECK_RELEASE_REFCOUNT(pStencilSurface
, 0);
525 CHECK_REFCOUNT(pDevice
, --refcount
);
526 pStencilSurface
= NULL
;
529 CHECK_RELEASE_REFCOUNT( pSwapChain
, 0);
530 CHECK_REFCOUNT( pDevice
, --refcount
);
532 /* The implicit swapchwin is released with the device, so AddRef with refcount=0 is fine here. */
533 CHECK_ADDREF_REFCOUNT(pSwapChain
, 1);
534 CHECK_REFCOUNT(pDevice
, ++refcount
);
535 CHECK_RELEASE_REFCOUNT(pSwapChain
, 0);
536 CHECK_REFCOUNT(pDevice
, --refcount
);
541 hr
= IDirect3DDevice9_CreateIndexBuffer( pDevice
, 16, 0, D3DFMT_INDEX32
, D3DPOOL_DEFAULT
, &pIndexBuffer
, NULL
);
542 CHECK_CALL( hr
, "CreateIndexBuffer", pDevice
, ++refcount
);
545 tmp
= get_refcount( (IUnknown
*)pIndexBuffer
);
547 hr
= IDirect3DDevice9_SetIndices(pDevice
, pIndexBuffer
);
548 CHECK_CALL( hr
, "SetIndices", pIndexBuffer
, tmp
);
549 hr
= IDirect3DDevice9_SetIndices(pDevice
, NULL
);
550 CHECK_CALL( hr
, "SetIndices", pIndexBuffer
, tmp
);
553 hr
= IDirect3DDevice9_CreateVertexBuffer( pDevice
, 16, 0, D3DFVF_XYZ
, D3DPOOL_DEFAULT
, &pVertexBuffer
, NULL
);
554 CHECK_CALL( hr
, "CreateVertexBuffer", pDevice
, ++refcount
);
557 IDirect3DVertexBuffer9
*pVBuf
= (void*)~0;
561 tmp
= get_refcount( (IUnknown
*)pVertexBuffer
);
563 hr
= IDirect3DDevice9_SetStreamSource(pDevice
, 0, pVertexBuffer
, 0, 3 * sizeof(float));
564 CHECK_CALL( hr
, "SetStreamSource", pVertexBuffer
, tmp
);
565 hr
= IDirect3DDevice9_SetStreamSource(pDevice
, 0, NULL
, 0, 0);
566 CHECK_CALL( hr
, "SetStreamSource", pVertexBuffer
, tmp
);
568 hr
= IDirect3DDevice9_GetStreamSource(pDevice
, 0, &pVBuf
, &offset
, &stride
);
569 ok(SUCCEEDED(hr
), "GetStreamSource did not succeed with NULL stream!\n");
570 ok(pVBuf
==NULL
, "pVBuf not NULL (%p)!\n", pVBuf
);
571 ok(stride
==3*sizeof(float), "stride not 3 floats (got %u)!\n", stride
);
572 ok(offset
==0, "offset not 0 (got %u)!\n", offset
);
575 hr
= IDirect3DDevice9_CreateVertexDeclaration( pDevice
, decl
, &pVertexDeclaration
);
576 CHECK_CALL( hr
, "CreateVertexDeclaration", pDevice
, ++refcount
);
577 hr
= IDirect3DDevice9_CreateVertexShader( pDevice
, simple_vs
, &pVertexShader
);
578 CHECK_CALL( hr
, "CreateVertexShader", pDevice
, ++refcount
);
579 hr
= IDirect3DDevice9_CreatePixelShader( pDevice
, simple_ps
, &pPixelShader
);
580 CHECK_CALL( hr
, "CreatePixelShader", pDevice
, ++refcount
);
582 hr
= IDirect3DDevice9_CreateTexture( pDevice
, 32, 32, 3, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pTexture
, NULL
);
583 CHECK_CALL( hr
, "CreateTexture", pDevice
, ++refcount
);
586 tmp
= get_refcount( (IUnknown
*)pTexture
);
588 /* SetTexture should not increase refcounts */
589 hr
= IDirect3DDevice9_SetTexture(pDevice
, 0, (IDirect3DBaseTexture9
*) pTexture
);
590 CHECK_CALL( hr
, "SetTexture", pTexture
, tmp
);
591 hr
= IDirect3DDevice9_SetTexture(pDevice
, 0, NULL
);
592 CHECK_CALL( hr
, "SetTexture", pTexture
, tmp
);
594 /* This should not increment device refcount */
595 hr
= IDirect3DTexture9_GetSurfaceLevel( pTexture
, 1, &pTextureLevel
);
596 CHECK_CALL( hr
, "GetSurfaceLevel", pDevice
, refcount
);
597 /* But should increment texture's refcount */
598 CHECK_REFCOUNT( pTexture
, tmp
+1 );
599 /* Because the texture and surface refcount are identical */
602 CHECK_REFCOUNT ( pTextureLevel
, tmp
+1 );
603 CHECK_ADDREF_REFCOUNT ( pTextureLevel
, tmp
+2 );
604 CHECK_REFCOUNT ( pTexture
, tmp
+2 );
605 CHECK_RELEASE_REFCOUNT( pTextureLevel
, tmp
+1 );
606 CHECK_REFCOUNT ( pTexture
, tmp
+1 );
607 CHECK_RELEASE_REFCOUNT( pTexture
, tmp
);
608 CHECK_REFCOUNT ( pTextureLevel
, tmp
);
611 hr
= IDirect3DDevice9_CreateCubeTexture( pDevice
, 32, 0, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pCubeTexture
, NULL
);
612 CHECK_CALL( hr
, "CreateCubeTexture", pDevice
, ++refcount
);
613 hr
= IDirect3DDevice9_CreateVolumeTexture( pDevice
, 32, 32, 2, 0, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pVolumeTexture
, NULL
);
614 CHECK_CALL( hr
, "CreateVolumeTexture", pDevice
, ++refcount
);
617 tmp
= get_refcount( (IUnknown
*)pVolumeTexture
);
619 /* This should not increment device refcount */
620 hr
= IDirect3DVolumeTexture9_GetVolumeLevel(pVolumeTexture
, 0, &pVolumeLevel
);
621 CHECK_CALL( hr
, "GetVolumeLevel", pDevice
, refcount
);
622 /* But should increment volume texture's refcount */
623 CHECK_REFCOUNT( pVolumeTexture
, tmp
+1 );
624 /* Because the volume texture and volume refcount are identical */
627 CHECK_REFCOUNT ( pVolumeLevel
, tmp
+1 );
628 CHECK_ADDREF_REFCOUNT ( pVolumeLevel
, tmp
+2 );
629 CHECK_REFCOUNT ( pVolumeTexture
, tmp
+2 );
630 CHECK_RELEASE_REFCOUNT( pVolumeLevel
, tmp
+1 );
631 CHECK_REFCOUNT ( pVolumeTexture
, tmp
+1 );
632 CHECK_RELEASE_REFCOUNT( pVolumeTexture
, tmp
);
633 CHECK_REFCOUNT ( pVolumeLevel
, tmp
);
637 hr
= IDirect3DDevice9_CreateDepthStencilSurface( pDevice
, 32, 32, D3DFMT_D24S8
, D3DMULTISAMPLE_NONE
, 0, TRUE
, &pStencilSurface
, NULL
);
638 CHECK_CALL( hr
, "CreateDepthStencilSurface", pDevice
, ++refcount
);
639 CHECK_REFCOUNT( pStencilSurface
, 1 );
640 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface( pDevice
, 32, 32, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pOffscreenSurface
, NULL
);
641 CHECK_CALL( hr
, "CreateOffscreenPlainSurface", pDevice
, ++refcount
);
642 CHECK_REFCOUNT( pOffscreenSurface
, 1 );
643 hr
= IDirect3DDevice9_CreateRenderTarget( pDevice
, 32, 32, D3DFMT_X8R8G8B8
, D3DMULTISAMPLE_NONE
, 0, TRUE
, &pRenderTarget3
, NULL
);
644 CHECK_CALL( hr
, "CreateRenderTarget", pDevice
, ++refcount
);
645 CHECK_REFCOUNT( pRenderTarget3
, 1 );
647 hr
= IDirect3DDevice9_CreateStateBlock( pDevice
, D3DSBT_ALL
, &pStateBlock
);
648 CHECK_CALL( hr
, "CreateStateBlock", pDevice
, ++refcount
);
649 hr
= IDirect3DDevice9_CreateAdditionalSwapChain( pDevice
, &d3dpp
, &pSwapChain
);
650 CHECK_CALL( hr
, "CreateAdditionalSwapChain", pDevice
, ++refcount
);
653 /* check implicit back buffer */
654 hr
= IDirect3DSwapChain9_GetBackBuffer(pSwapChain
, 0, 0, &pBackBuffer
);
655 CHECK_CALL( hr
, "GetBackBuffer", pDevice
, ++refcount
);
656 CHECK_REFCOUNT( pSwapChain
, 1);
659 CHECK_SURFACE_CONTAINER( pBackBuffer
, IID_IDirect3DSwapChain9
, pSwapChain
);
660 CHECK_REFCOUNT( pBackBuffer
, 1);
661 CHECK_RELEASE_REFCOUNT( pBackBuffer
, 0);
662 CHECK_REFCOUNT( pDevice
, --refcount
);
664 /* The back buffer is released with the swapchain, so AddRef with refcount=0 is fine here. */
665 CHECK_ADDREF_REFCOUNT(pBackBuffer
, 1);
666 CHECK_REFCOUNT(pDevice
, ++refcount
);
667 CHECK_RELEASE_REFCOUNT(pBackBuffer
, 0);
668 CHECK_REFCOUNT(pDevice
, --refcount
);
671 CHECK_REFCOUNT( pSwapChain
, 1);
673 hr
= IDirect3DDevice9_CreateQuery( pDevice
, D3DQUERYTYPE_EVENT
, &pQuery
);
674 CHECK_CALL( hr
, "CreateQuery", pDevice
, ++refcount
);
676 hr
= IDirect3DDevice9_BeginStateBlock( pDevice
);
677 CHECK_CALL( hr
, "BeginStateBlock", pDevice
, refcount
);
678 hr
= IDirect3DDevice9_EndStateBlock( pDevice
, &pStateBlock1
);
679 CHECK_CALL( hr
, "EndStateBlock", pDevice
, ++refcount
);
681 /* The implicit render target is not freed if refcount reaches 0.
682 * Otherwise GetRenderTarget would re-allocate it and the pointer would change.*/
683 hr
= IDirect3DDevice9_GetRenderTarget(pDevice
, 0, &pRenderTarget2
);
684 CHECK_CALL( hr
, "GetRenderTarget", pDevice
, ++refcount
);
687 CHECK_RELEASE_REFCOUNT(pRenderTarget2
, 0);
688 ok(pRenderTarget
== pRenderTarget2
, "RenderTarget=%p and RenderTarget2=%p should be the same.\n",
689 pRenderTarget
, pRenderTarget2
);
690 CHECK_REFCOUNT( pDevice
, --refcount
);
691 pRenderTarget2
= NULL
;
693 pRenderTarget
= NULL
;
696 CHECK_RELEASE(pDevice
, pDevice
, --refcount
);
699 CHECK_RELEASE(pVertexBuffer
, pDevice
, --refcount
);
700 CHECK_RELEASE(pIndexBuffer
, pDevice
, --refcount
);
702 CHECK_RELEASE(pVertexDeclaration
, pDevice
, --refcount
);
703 CHECK_RELEASE(pVertexShader
, pDevice
, --refcount
);
704 CHECK_RELEASE(pPixelShader
, pDevice
, --refcount
);
706 CHECK_RELEASE(pTextureLevel
, pDevice
, --refcount
);
707 CHECK_RELEASE(pCubeTexture
, pDevice
, --refcount
);
708 CHECK_RELEASE(pVolumeTexture
, pDevice
, --refcount
);
710 CHECK_RELEASE(pStencilSurface
, pDevice
, --refcount
);
711 CHECK_RELEASE(pOffscreenSurface
, pDevice
, --refcount
);
712 CHECK_RELEASE(pRenderTarget3
, pDevice
, --refcount
);
714 CHECK_RELEASE(pStateBlock
, pDevice
, --refcount
);
715 CHECK_RELEASE(pSwapChain
, pDevice
, --refcount
);
716 CHECK_RELEASE(pQuery
, pDevice
, --refcount
);
717 /* This will destroy device - cannot check the refcount here */
718 if (pStateBlock1
) CHECK_RELEASE_REFCOUNT( pStateBlock1
, 0);
720 if (pD3d
) CHECK_RELEASE_REFCOUNT( pD3d
, 0);
722 DestroyWindow( hwnd
);
725 static void test_cursor(void)
729 IDirect3D9
*pD3d
= NULL
;
730 IDirect3DDevice9
*pDevice
= NULL
;
731 D3DPRESENT_PARAMETERS d3dpp
;
732 D3DDISPLAYMODE d3ddm
;
734 IDirect3DSurface9
*cursor
= NULL
;
737 memset(&info
, 0, sizeof(info
));
738 info
.cbSize
= sizeof(info
);
739 ok(GetCursorInfo(&info
), "GetCursorInfo failed\n");
742 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
743 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
744 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
745 ok(hwnd
!= NULL
, "Failed to create window\n");
746 if (!pD3d
|| !hwnd
) goto cleanup
;
748 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
749 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
750 d3dpp
.Windowed
= TRUE
;
751 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
752 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
754 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
755 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
756 ok(hr
== S_OK
|| hr
== D3DERR_NOTAVAILABLE
,
757 "Failed to create IDirect3D9Device (%08x)\n", hr
);
758 if (FAILED(hr
)) goto cleanup
;
760 IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 32, 32, D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &cursor
, 0);
761 ok(cursor
!= NULL
, "IDirect3DDevice9_CreateOffscreenPlainSurface failed with %08x\n", hr
);
763 /* Initially hidden */
764 hr
= IDirect3DDevice9_ShowCursor(pDevice
, TRUE
);
765 ok(hr
== FALSE
, "IDirect3DDevice9_ShowCursor returned %08x\n", hr
);
767 /* Not enabled without a surface*/
768 hr
= IDirect3DDevice9_ShowCursor(pDevice
, TRUE
);
769 ok(hr
== FALSE
, "IDirect3DDevice9_ShowCursor returned %08x\n", hr
);
772 hr
= IDirect3DDevice9_SetCursorProperties(pDevice
, 0, 0, NULL
);
773 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_SetCursorProperties returned %08x\n", hr
);
775 hr
= IDirect3DDevice9_SetCursorProperties(pDevice
, 0, 0, cursor
);
776 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetCursorProperties returned %08x\n", hr
);
778 IDirect3DSurface9_Release(cursor
);
780 memset(&info
, 0, sizeof(info
));
781 info
.cbSize
= sizeof(info
);
782 ok(GetCursorInfo(&info
), "GetCursorInfo failed\n");
783 ok(info
.flags
& CURSOR_SHOWING
, "The gdi cursor is hidden (%08x)\n", info
.flags
);
784 ok(info
.hCursor
== cur
, "The cursor handle is %p\n", info
.hCursor
); /* unchanged */
787 hr
= IDirect3DDevice9_ShowCursor(pDevice
, TRUE
);
788 ok(hr
== FALSE
, "IDirect3DDevice9_ShowCursor returned %08x\n", hr
);
791 hr
= IDirect3DDevice9_ShowCursor(pDevice
, TRUE
);
792 ok(hr
== TRUE
, "IDirect3DDevice9_ShowCursor returned %08x\n", hr
);
794 /* GDI cursor unchanged */
795 memset(&info
, 0, sizeof(info
));
796 info
.cbSize
= sizeof(info
);
797 ok(GetCursorInfo(&info
), "GetCursorInfo failed\n");
798 ok(info
.flags
& CURSOR_SHOWING
, "The gdi cursor is hidden (%08x)\n", info
.flags
);
799 ok(info
.hCursor
== cur
, "The cursor handle is %p\n", info
.hCursor
); /* unchanged */
804 UINT refcount
= IDirect3DDevice9_Release(pDevice
);
805 ok(!refcount
, "Device has %u references left.\n", refcount
);
807 if (pD3d
) IDirect3D9_Release(pD3d
);
808 DestroyWindow( hwnd
);
811 static void test_reset(void)
815 IDirect3D9
*pD3d
= NULL
;
816 IDirect3DDevice9
*pDevice
= NULL
;
817 D3DPRESENT_PARAMETERS d3dpp
;
818 D3DDISPLAYMODE d3ddm
, d3ddm2
;
820 DWORD width
, orig_width
= GetSystemMetrics(SM_CXSCREEN
);
821 DWORD height
, orig_height
= GetSystemMetrics(SM_CYSCREEN
);
822 IDirect3DSwapChain9
*pSwapchain
;
823 IDirect3DSurface9
*surface
;
824 IDirect3DTexture9
*texture
;
825 IDirect3DVertexShader9
*shader
;
826 UINT i
, adapter_mode_count
;
827 D3DLOCKED_RECT lockrect
;
835 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
836 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
837 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
838 ok(hwnd
!= NULL
, "Failed to create window\n");
839 if (!pD3d
|| !hwnd
) goto cleanup
;
841 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
842 adapter_mode_count
= IDirect3D9_GetAdapterModeCount(pD3d
, D3DADAPTER_DEFAULT
, d3ddm
.Format
);
843 modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(*modes
) * adapter_mode_count
);
844 for(i
= 0; i
< adapter_mode_count
; ++i
)
847 ZeroMemory( &d3ddm2
, sizeof(d3ddm2
) );
848 hr
= IDirect3D9_EnumAdapterModes(pD3d
, D3DADAPTER_DEFAULT
, d3ddm
.Format
, i
, &d3ddm2
);
849 ok(hr
== D3D_OK
, "IDirect3D9_EnumAdapterModes returned %#x\n", hr
);
851 for (j
= 0; j
< mode_count
; ++j
)
853 if (modes
[j
].w
== d3ddm2
.Width
&& modes
[j
].h
== d3ddm2
.Height
)
858 modes
[j
].w
= d3ddm2
.Width
;
859 modes
[j
].h
= d3ddm2
.Height
;
863 /* We use them as invalid modes */
864 if((d3ddm2
.Width
== 801 && d3ddm2
.Height
== 600) ||
865 (d3ddm2
.Width
== 32 && d3ddm2
.Height
== 32)) {
866 skip("This system supports a screen resolution of %dx%d, not running mode tests\n",
867 d3ddm2
.Width
, d3ddm2
.Height
);
874 skip("Less than 2 modes supported, skipping mode tests\n");
879 if (modes
[i
].w
== orig_width
&& modes
[i
].h
== orig_height
) ++i
;
881 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
882 d3dpp
.Windowed
= FALSE
;
883 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
884 d3dpp
.BackBufferWidth
= modes
[i
].w
;
885 d3dpp
.BackBufferHeight
= modes
[i
].h
;
886 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
887 d3dpp
.EnableAutoDepthStencil
= TRUE
;
888 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
890 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
891 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
895 skip("could not create device, IDirect3D9_CreateDevice returned %#x\n", hr
);
898 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
899 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after creation returned %#x\n", hr
);
901 width
= GetSystemMetrics(SM_CXSCREEN
);
902 height
= GetSystemMetrics(SM_CYSCREEN
);
903 ok(width
== modes
[i
].w
, "Screen width is %u, expected %u\n", width
, modes
[i
].w
);
904 ok(height
== modes
[i
].h
, "Screen height is %u, expected %u\n", height
, modes
[i
].h
);
906 hr
= IDirect3DDevice9_GetViewport(pDevice
, &vp
);
907 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetViewport failed with %08x\n", hr
);
910 ok(vp
.X
== 0, "D3DVIEWPORT->X = %d\n", vp
.X
);
911 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %d\n", vp
.Y
);
912 ok(vp
.Width
== modes
[i
].w
, "D3DVIEWPORT->Width = %u, expected %u\n", vp
.Width
, modes
[i
].w
);
913 ok(vp
.Height
== modes
[i
].h
, "D3DVIEWPORT->Height = %u, expected %u\n", vp
.Height
, modes
[i
].h
);
914 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %f\n", vp
.MinZ
);
915 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %f\n", vp
.MaxZ
);
923 hr
= IDirect3DDevice9_SetViewport(pDevice
, &vp
);
924 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetViewport failed with %08x\n", hr
);
926 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
927 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
928 d3dpp
.Windowed
= FALSE
;
929 d3dpp
.BackBufferWidth
= modes
[i
].w
;
930 d3dpp
.BackBufferHeight
= modes
[i
].h
;
931 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
932 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
933 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
934 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
935 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
937 ZeroMemory(&vp
, sizeof(vp
));
938 hr
= IDirect3DDevice9_GetViewport(pDevice
, &vp
);
939 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetViewport failed with %08x\n", hr
);
942 ok(vp
.X
== 0, "D3DVIEWPORT->X = %d\n", vp
.X
);
943 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %d\n", vp
.Y
);
944 ok(vp
.Width
== modes
[i
].w
, "D3DVIEWPORT->Width = %u, expected %u\n", vp
.Width
, modes
[i
].w
);
945 ok(vp
.Height
== modes
[i
].h
, "D3DVIEWPORT->Height = %u, expected %u\n", vp
.Height
, modes
[i
].h
);
946 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %f\n", vp
.MinZ
);
947 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %f\n", vp
.MaxZ
);
950 width
= GetSystemMetrics(SM_CXSCREEN
);
951 height
= GetSystemMetrics(SM_CYSCREEN
);
952 ok(width
== modes
[i
].w
, "Screen width is %u, expected %u\n", width
, modes
[i
].w
);
953 ok(height
== modes
[i
].h
, "Screen height is %u, expected %u\n", height
, modes
[i
].h
);
955 hr
= IDirect3DDevice9_GetSwapChain(pDevice
, 0, &pSwapchain
);
956 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetSwapChain returned %08x\n", hr
);
959 ZeroMemory(&d3dpp
, sizeof(d3dpp
));
960 hr
= IDirect3DSwapChain9_GetPresentParameters(pSwapchain
, &d3dpp
);
961 ok(hr
== D3D_OK
, "IDirect3DSwapChain9_GetPresentParameters returned %08x\n", hr
);
964 ok(d3dpp
.BackBufferWidth
== modes
[i
].w
, "Back buffer width is %u, expected %u\n",
965 d3dpp
.BackBufferWidth
, modes
[i
].w
);
966 ok(d3dpp
.BackBufferHeight
== modes
[i
].h
, "Back buffer height is %u, expected %u\n",
967 d3dpp
.BackBufferHeight
, modes
[i
].h
);
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;
977 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
978 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
979 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
980 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
982 width
= GetSystemMetrics(SM_CXSCREEN
);
983 height
= GetSystemMetrics(SM_CYSCREEN
);
984 ok(width
== orig_width
, "Screen width is %d\n", width
);
985 ok(height
== orig_height
, "Screen height is %d\n", height
);
987 ZeroMemory(&vp
, sizeof(vp
));
988 hr
= IDirect3DDevice9_GetViewport(pDevice
, &vp
);
989 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetViewport failed with %08x\n", hr
);
992 ok(vp
.X
== 0, "D3DVIEWPORT->X = %d\n", vp
.X
);
993 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %d\n", vp
.Y
);
994 ok(vp
.Width
== 400, "D3DVIEWPORT->Width = %d\n", vp
.Width
);
995 ok(vp
.Height
== 300, "D3DVIEWPORT->Height = %d\n", vp
.Height
);
996 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %f\n", vp
.MinZ
);
997 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %f\n", vp
.MaxZ
);
1000 hr
= IDirect3DDevice9_GetSwapChain(pDevice
, 0, &pSwapchain
);
1001 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetSwapChain returned %08x\n", hr
);
1004 ZeroMemory(&d3dpp
, sizeof(d3dpp
));
1005 hr
= IDirect3DSwapChain9_GetPresentParameters(pSwapchain
, &d3dpp
);
1006 ok(hr
== D3D_OK
, "IDirect3DSwapChain9_GetPresentParameters returned %08x\n", hr
);
1009 ok(d3dpp
.BackBufferWidth
== 400, "Back buffer width is %d\n", d3dpp
.BackBufferWidth
);
1010 ok(d3dpp
.BackBufferHeight
== 300, "Back buffer height is %d\n", d3dpp
.BackBufferHeight
);
1012 IDirect3DSwapChain9_Release(pSwapchain
);
1015 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1016 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1017 d3dpp
.Windowed
= TRUE
;
1018 d3dpp
.BackBufferWidth
= 400;
1019 d3dpp
.BackBufferHeight
= 300;
1021 /* _Reset fails if there is a resource in the default pool */
1022 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 16, 16, D3DFMT_R5G6B5
, D3DPOOL_DEFAULT
, &surface
, NULL
);
1023 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr
);
1024 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1025 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1026 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
1027 ok(hr
== D3DERR_DEVICENOTRESET
, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr
);
1028 IDirect3DSurface9_Release(surface
);
1029 /* Reset again to get the device out of the lost state */
1030 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1031 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1032 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
1033 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
1035 /* Scratch, sysmem and managed pools are fine */
1036 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 16, 16, D3DFMT_R5G6B5
, D3DPOOL_SCRATCH
, &surface
, NULL
);
1037 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr
);
1038 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1039 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1040 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
1041 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
1042 IDirect3DSurface9_Release(surface
);
1044 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 16, 16, D3DFMT_R5G6B5
, D3DPOOL_SYSTEMMEM
, &surface
, NULL
);
1045 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr
);
1046 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1047 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1048 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
1049 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
1050 IDirect3DSurface9_Release(surface
);
1052 /* The depth stencil should get reset to the auto depth stencil when present. */
1053 hr
= IDirect3DDevice9_SetDepthStencilSurface(pDevice
, NULL
);
1054 ok(hr
== D3D_OK
, "SetDepthStencilSurface failed with 0x%08x\n", hr
);
1056 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &surface
);
1057 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr
);
1058 ok(surface
== NULL
, "Depth stencil should be NULL\n");
1060 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1061 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1062 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1063 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with 0x%08x\n", hr
);
1065 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &surface
);
1066 ok(hr
== D3D_OK
, "GetDepthStencilSurface failed with 0x%08x\n", hr
);
1067 ok(surface
!= NULL
, "Depth stencil should not be NULL\n");
1068 if (surface
) IDirect3DSurface9_Release(surface
);
1070 d3dpp
.EnableAutoDepthStencil
= FALSE
;
1071 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1072 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with 0x%08x\n", hr
);
1074 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &surface
);
1075 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr
);
1076 ok(surface
== NULL
, "Depth stencil should be NULL\n");
1078 /* Will a sysmem or scratch survive while locked */
1079 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 16, 16, D3DFMT_R5G6B5
, D3DPOOL_SYSTEMMEM
, &surface
, NULL
);
1080 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr
);
1081 hr
= IDirect3DSurface9_LockRect(surface
, &lockrect
, NULL
, D3DLOCK_DISCARD
);
1082 ok(hr
== D3D_OK
, "IDirect3DSurface9_LockRect returned %08x\n", hr
);
1083 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1084 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1085 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
1086 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
1087 IDirect3DSurface9_UnlockRect(surface
);
1088 IDirect3DSurface9_Release(surface
);
1090 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 16, 16, D3DFMT_R5G6B5
, D3DPOOL_SCRATCH
, &surface
, NULL
);
1091 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr
);
1092 hr
= IDirect3DSurface9_LockRect(surface
, &lockrect
, NULL
, D3DLOCK_DISCARD
);
1093 ok(hr
== D3D_OK
, "IDirect3DSurface9_LockRect returned %08x\n", hr
);
1094 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1095 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1096 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
1097 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
1098 IDirect3DSurface9_UnlockRect(surface
);
1099 IDirect3DSurface9_Release(surface
);
1101 hr
= IDirect3DDevice9_CreateTexture(pDevice
, 16, 16, 0, 0, D3DFMT_R5G6B5
, D3DPOOL_MANAGED
, &texture
, NULL
);
1102 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture returned %08x\n", hr
);
1103 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1104 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1105 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
1106 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
1107 IDirect3DTexture9_Release(texture
);
1109 /* A reference held to an implicit surface causes failures as well */
1110 hr
= IDirect3DDevice9_GetBackBuffer(pDevice
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &surface
);
1111 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetBackBuffer returned %08x\n", hr
);
1112 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1113 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1114 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
1115 ok(hr
== D3DERR_DEVICENOTRESET
, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr
);
1116 IDirect3DSurface9_Release(surface
);
1117 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1118 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1119 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
1120 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
1122 /* Shaders are fine as well */
1123 hr
= IDirect3DDevice9_CreateVertexShader(pDevice
, simple_vs
, &shader
);
1124 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr
);
1125 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1126 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1127 IDirect3DVertexShader9_Release(shader
);
1129 /* Try setting invalid modes */
1130 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1131 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1132 d3dpp
.Windowed
= FALSE
;
1133 d3dpp
.BackBufferWidth
= 32;
1134 d3dpp
.BackBufferHeight
= 32;
1135 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1136 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Reset to w=32, h=32, windowed=FALSE failed with %08x\n", hr
);
1137 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
1138 ok(hr
== D3DERR_DEVICENOTRESET
, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr
);
1140 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1141 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1142 d3dpp
.Windowed
= FALSE
;
1143 d3dpp
.BackBufferWidth
= 801;
1144 d3dpp
.BackBufferHeight
= 600;
1145 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1146 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Reset to w=801, h=600, windowed=FALSE failed with %08x\n", hr
);
1147 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
1148 ok(hr
== D3DERR_DEVICENOTRESET
, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr
);
1151 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
1153 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1154 d3dpp
.Windowed
= TRUE
;
1155 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1156 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1157 d3dpp
.EnableAutoDepthStencil
= FALSE
;
1158 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1160 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
1161 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
1165 skip("could not create device, IDirect3D9_CreateDevice returned %#x\n", hr
);
1169 hr
= IDirect3DDevice9_TestCooperativeLevel(pDevice
);
1170 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after creation returned %#x\n", hr
);
1172 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1173 d3dpp
.Windowed
= TRUE
;
1174 d3dpp
.BackBufferWidth
= 400;
1175 d3dpp
.BackBufferHeight
= 300;
1176 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1177 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1179 hr
= IDirect3DDevice9_Reset(pDevice
, &d3dpp
);
1180 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with 0x%08x\n", hr
);
1182 if (FAILED(hr
)) goto cleanup
;
1184 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &surface
);
1185 ok(hr
== D3D_OK
, "GetDepthStencilSurface failed with 0x%08x\n", hr
);
1186 ok(surface
!= NULL
, "Depth stencil should not be NULL\n");
1187 if (surface
) IDirect3DSurface9_Release(surface
);
1190 HeapFree(GetProcessHeap(), 0, modes
);
1193 UINT refcount
= IDirect3DDevice9_Release(pDevice
);
1194 ok(!refcount
, "Device has %u references left.\n", refcount
);
1196 if (pD3d
) IDirect3D9_Release(pD3d
);
1199 /* Test adapter display modes */
1200 static void test_display_modes(void)
1202 D3DDISPLAYMODE dmode
;
1205 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
1206 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
1209 #define TEST_FMT(x,r) do { \
1210 HRESULT res = IDirect3D9_EnumAdapterModes(pD3d, 0, (x), 0, &dmode); \
1211 ok(res==(r), "EnumAdapterModes("#x") did not return "#r" (got %08x)!\n", res); \
1214 TEST_FMT(D3DFMT_R8G8B8
, D3DERR_INVALIDCALL
);
1215 TEST_FMT(D3DFMT_A8R8G8B8
, D3DERR_INVALIDCALL
);
1216 TEST_FMT(D3DFMT_X8B8G8R8
, D3DERR_INVALIDCALL
);
1218 TEST_FMT(D3DFMT_X1R5G5B5
, D3DERR_INVALIDCALL
);
1219 TEST_FMT(D3DFMT_A1R5G5B5
, D3DERR_INVALIDCALL
);
1220 TEST_FMT(D3DFMT_A4R4G4B4
, D3DERR_INVALIDCALL
);
1221 TEST_FMT(D3DFMT_R3G3B2
, D3DERR_INVALIDCALL
);
1222 TEST_FMT(D3DFMT_A8
, D3DERR_INVALIDCALL
);
1223 TEST_FMT(D3DFMT_A8R3G3B2
, D3DERR_INVALIDCALL
);
1224 TEST_FMT(D3DFMT_X4R4G4B4
, D3DERR_INVALIDCALL
);
1225 TEST_FMT(D3DFMT_A2B10G10R10
, D3DERR_INVALIDCALL
);
1226 TEST_FMT(D3DFMT_A8B8G8R8
, D3DERR_INVALIDCALL
);
1227 TEST_FMT(D3DFMT_X8B8G8R8
, D3DERR_INVALIDCALL
);
1228 TEST_FMT(D3DFMT_G16R16
, D3DERR_INVALIDCALL
);
1229 TEST_FMT(D3DFMT_A16B16G16R16
, D3DERR_INVALIDCALL
);
1231 TEST_FMT(D3DFMT_A8P8
, D3DERR_INVALIDCALL
);
1232 TEST_FMT(D3DFMT_P8
, D3DERR_INVALIDCALL
);
1234 TEST_FMT(D3DFMT_L8
, D3DERR_INVALIDCALL
);
1235 TEST_FMT(D3DFMT_A8L8
, D3DERR_INVALIDCALL
);
1236 TEST_FMT(D3DFMT_A4L4
, D3DERR_INVALIDCALL
);
1238 TEST_FMT(D3DFMT_V8U8
, D3DERR_INVALIDCALL
);
1239 TEST_FMT(D3DFMT_L6V5U5
, D3DERR_INVALIDCALL
);
1240 TEST_FMT(D3DFMT_X8L8V8U8
, D3DERR_INVALIDCALL
);
1241 TEST_FMT(D3DFMT_Q8W8V8U8
, D3DERR_INVALIDCALL
);
1242 TEST_FMT(D3DFMT_V16U16
, D3DERR_INVALIDCALL
);
1243 TEST_FMT(D3DFMT_A2W10V10U10
, D3DERR_INVALIDCALL
);
1245 TEST_FMT(D3DFMT_UYVY
, D3DERR_INVALIDCALL
);
1246 TEST_FMT(D3DFMT_YUY2
, D3DERR_INVALIDCALL
);
1247 TEST_FMT(D3DFMT_DXT1
, D3DERR_INVALIDCALL
);
1248 TEST_FMT(D3DFMT_DXT2
, D3DERR_INVALIDCALL
);
1249 TEST_FMT(D3DFMT_DXT3
, D3DERR_INVALIDCALL
);
1250 TEST_FMT(D3DFMT_DXT4
, D3DERR_INVALIDCALL
);
1251 TEST_FMT(D3DFMT_DXT5
, D3DERR_INVALIDCALL
);
1252 TEST_FMT(D3DFMT_MULTI2_ARGB8
, D3DERR_INVALIDCALL
);
1253 TEST_FMT(D3DFMT_G8R8_G8B8
, D3DERR_INVALIDCALL
);
1254 TEST_FMT(D3DFMT_R8G8_B8G8
, D3DERR_INVALIDCALL
);
1256 TEST_FMT(D3DFMT_D16_LOCKABLE
, D3DERR_INVALIDCALL
);
1257 TEST_FMT(D3DFMT_D32
, D3DERR_INVALIDCALL
);
1258 TEST_FMT(D3DFMT_D15S1
, D3DERR_INVALIDCALL
);
1259 TEST_FMT(D3DFMT_D24S8
, D3DERR_INVALIDCALL
);
1260 TEST_FMT(D3DFMT_D24X8
, D3DERR_INVALIDCALL
);
1261 TEST_FMT(D3DFMT_D24X4S4
, D3DERR_INVALIDCALL
);
1262 TEST_FMT(D3DFMT_D16
, D3DERR_INVALIDCALL
);
1263 TEST_FMT(D3DFMT_L16
, D3DERR_INVALIDCALL
);
1264 TEST_FMT(D3DFMT_D32F_LOCKABLE
, D3DERR_INVALIDCALL
);
1265 TEST_FMT(D3DFMT_D24FS8
, D3DERR_INVALIDCALL
);
1267 TEST_FMT(D3DFMT_VERTEXDATA
, D3DERR_INVALIDCALL
);
1268 TEST_FMT(D3DFMT_INDEX16
, D3DERR_INVALIDCALL
);
1269 TEST_FMT(D3DFMT_INDEX32
, D3DERR_INVALIDCALL
);
1270 TEST_FMT(D3DFMT_Q16W16V16U16
, D3DERR_INVALIDCALL
);
1271 /* Floating point formats */
1272 TEST_FMT(D3DFMT_R16F
, D3DERR_INVALIDCALL
);
1273 TEST_FMT(D3DFMT_G16R16F
, D3DERR_INVALIDCALL
);
1274 TEST_FMT(D3DFMT_A16B16G16R16F
, D3DERR_INVALIDCALL
);
1277 TEST_FMT(D3DFMT_R32F
, D3DERR_INVALIDCALL
);
1278 TEST_FMT(D3DFMT_G32R32F
, D3DERR_INVALIDCALL
);
1279 TEST_FMT(D3DFMT_A32B32G32R32F
, D3DERR_INVALIDCALL
);
1281 TEST_FMT(D3DFMT_CxV8U8
, D3DERR_INVALIDCALL
);
1283 TEST_FMT(0, D3DERR_INVALIDCALL
);
1285 IDirect3D9_Release(pD3d
);
1288 static void test_scene(void)
1292 IDirect3D9
*pD3d
= NULL
;
1293 IDirect3DDevice9
*pDevice
= NULL
;
1294 D3DPRESENT_PARAMETERS d3dpp
;
1295 D3DDISPLAYMODE d3ddm
;
1296 IDirect3DSurface9
*pSurface1
= NULL
, *pSurface2
= NULL
, *pSurface3
= NULL
, *pRenderTarget
= NULL
;
1297 IDirect3DSurface9
*pBackBuffer
= NULL
, *pDepthStencil
= NULL
;
1298 RECT rect
= {0, 0, 128, 128};
1301 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
1302 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
1303 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1304 ok(hwnd
!= NULL
, "Failed to create window\n");
1305 if (!pD3d
|| !hwnd
) goto cleanup
;
1307 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
1308 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1309 d3dpp
.Windowed
= TRUE
;
1310 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1311 d3dpp
.BackBufferWidth
= 800;
1312 d3dpp
.BackBufferHeight
= 600;
1313 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1314 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1315 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
1317 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1318 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
1319 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1322 skip("Failed to create a d3d device\n");
1326 /* Get the caps, they will be needed to tell if an operation is supposed to be valid */
1327 memset(&caps
, 0, sizeof(caps
));
1328 hr
= IDirect3DDevice9_GetDeviceCaps(pDevice
, &caps
);
1329 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetCaps failed with %08x\n", hr
);
1330 if(FAILED(hr
)) goto cleanup
;
1332 /* Test an EndScene without beginscene. Should return an error */
1333 hr
= IDirect3DDevice9_EndScene(pDevice
);
1334 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_EndScene returned %08x\n", hr
);
1336 /* Test a normal BeginScene / EndScene pair, this should work */
1337 hr
= IDirect3DDevice9_BeginScene(pDevice
);
1338 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %08x\n", hr
);
1341 hr
= IDirect3DDevice9_EndScene(pDevice
);
1342 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %08x\n", hr
);
1345 /* Test another EndScene without having begun a new scene. Should return an error */
1346 hr
= IDirect3DDevice9_EndScene(pDevice
);
1347 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_EndScene returned %08x\n", hr
);
1349 /* Two nested BeginScene and EndScene calls */
1350 hr
= IDirect3DDevice9_BeginScene(pDevice
);
1351 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %08x\n", hr
);
1352 hr
= IDirect3DDevice9_BeginScene(pDevice
);
1353 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_BeginScene returned %08x\n", hr
);
1354 hr
= IDirect3DDevice9_EndScene(pDevice
);
1355 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %08x\n", hr
);
1356 hr
= IDirect3DDevice9_EndScene(pDevice
);
1357 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_EndScene returned %08x\n", hr
);
1359 /* Create some surfaces to test stretchrect between the scenes */
1360 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 128, 128, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &pSurface1
, NULL
);
1361 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface failed with %08x\n", hr
);
1362 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice
, 128, 128, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &pSurface2
, NULL
);
1363 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface failed with %08x\n", hr
);
1364 hr
= IDirect3DDevice9_CreateDepthStencilSurface(pDevice
, 800, 600, D3DFMT_D16
, D3DMULTISAMPLE_NONE
, 0, FALSE
, &pSurface3
, NULL
);
1365 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateDepthStencilSurface failed with %08x\n", hr
);
1366 hr
= IDirect3DDevice9_CreateRenderTarget(pDevice
, 128, 128, d3ddm
.Format
, D3DMULTISAMPLE_NONE
, 0, FALSE
, &pRenderTarget
, NULL
);
1367 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateRenderTarget failed with %08x\n", hr
);
1369 hr
= IDirect3DDevice9_GetBackBuffer(pDevice
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &pBackBuffer
);
1370 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetBackBuffer failed with %08x\n", hr
);
1371 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &pDepthStencil
);
1372 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetBackBuffer failed with %08x\n", hr
);
1374 /* First make sure a simple StretchRect call works */
1375 if(pSurface1
&& pSurface2
) {
1376 hr
= IDirect3DDevice9_StretchRect(pDevice
, pSurface1
, NULL
, pSurface2
, NULL
, 0);
1377 ok( hr
== D3D_OK
, "IDirect3DDevice9_StretchRect failed with %08x\n", hr
);
1379 if(pBackBuffer
&& pRenderTarget
) {
1380 hr
= IDirect3DDevice9_StretchRect(pDevice
, pBackBuffer
, &rect
, pRenderTarget
, NULL
, 0);
1381 ok( hr
== D3D_OK
, "IDirect3DDevice9_StretchRect failed with %08x\n", hr
);
1383 if(pDepthStencil
&& pSurface3
) {
1385 if(0) /* Disabled for now because it crashes in wine */ {
1386 expected
= caps
.DevCaps2
& D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES
? D3D_OK
: D3DERR_INVALIDCALL
;
1387 hr
= IDirect3DDevice9_StretchRect(pDevice
, pDepthStencil
, NULL
, pSurface3
, NULL
, 0);
1388 ok( hr
== expected
, "IDirect3DDevice9_StretchRect returned %08x, expected %08x\n", hr
, expected
);
1392 /* Now try it in a BeginScene - EndScene pair. Seems to be allowed in a beginScene - Endscene pair
1393 * width normal surfaces, render targets and depth stencil surfaces.
1395 hr
= IDirect3DDevice9_BeginScene(pDevice
);
1396 ok( hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %08x\n", hr
);
1398 if(pSurface1
&& pSurface2
)
1400 hr
= IDirect3DDevice9_StretchRect(pDevice
, pSurface1
, NULL
, pSurface2
, NULL
, 0);
1401 ok( hr
== D3D_OK
, "IDirect3DDevice9_StretchRect failed with %08x\n", hr
);
1403 if(pBackBuffer
&& pRenderTarget
)
1405 hr
= IDirect3DDevice9_StretchRect(pDevice
, pBackBuffer
, &rect
, pRenderTarget
, NULL
, 0);
1406 ok( hr
== D3D_OK
, "IDirect3DDevice9_StretchRect failed with %08x\n", hr
);
1408 if(pDepthStencil
&& pSurface3
)
1410 /* This is supposed to fail inside a BeginScene - EndScene pair. */
1411 hr
= IDirect3DDevice9_StretchRect(pDevice
, pDepthStencil
, NULL
, pSurface3
, NULL
, 0);
1412 ok( hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_StretchRect returned %08x, expected D3DERR_INVALIDCALL\n", hr
);
1415 hr
= IDirect3DDevice9_EndScene(pDevice
);
1416 ok( hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %08x\n", hr
);
1418 /* Does a SetRenderTarget influence BeginScene / EndScene ?
1419 * Set a new render target, then see if it started a new scene. Flip the rt back and see if that maybe
1420 * ended the scene. Expected result is that the scene is not affected by SetRenderTarget
1422 hr
= IDirect3DDevice9_SetRenderTarget(pDevice
, 0, pRenderTarget
);
1423 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderTarget failed with %08x\n", hr
);
1424 hr
= IDirect3DDevice9_BeginScene(pDevice
);
1425 ok( hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %08x\n", hr
);
1426 hr
= IDirect3DDevice9_SetRenderTarget(pDevice
, 0, pBackBuffer
);
1427 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderTarget failed with %08x\n", hr
);
1428 hr
= IDirect3DDevice9_EndScene(pDevice
);
1429 ok( hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %08x\n", hr
);
1432 if(pRenderTarget
) IDirect3DSurface9_Release(pRenderTarget
);
1433 if(pDepthStencil
) IDirect3DSurface9_Release(pDepthStencil
);
1434 if(pBackBuffer
) IDirect3DSurface9_Release(pBackBuffer
);
1435 if(pSurface1
) IDirect3DSurface9_Release(pSurface1
);
1436 if(pSurface2
) IDirect3DSurface9_Release(pSurface2
);
1437 if(pSurface3
) IDirect3DSurface9_Release(pSurface3
);
1440 UINT refcount
= IDirect3DDevice9_Release(pDevice
);
1441 ok(!refcount
, "Device has %u references left.\n", refcount
);
1443 if (pD3d
) IDirect3D9_Release(pD3d
);
1444 if(hwnd
) DestroyWindow(hwnd
);
1447 static void test_limits(void)
1451 IDirect3D9
*pD3d
= NULL
;
1452 IDirect3DDevice9
*pDevice
= NULL
;
1453 D3DPRESENT_PARAMETERS d3dpp
;
1454 D3DDISPLAYMODE d3ddm
;
1455 IDirect3DTexture9
*pTexture
= NULL
;
1458 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
1459 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
1460 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1461 ok(hwnd
!= NULL
, "Failed to create window\n");
1462 if (!pD3d
|| !hwnd
) goto cleanup
;
1464 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
1465 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1466 d3dpp
.Windowed
= TRUE
;
1467 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1468 d3dpp
.BackBufferWidth
= 800;
1469 d3dpp
.BackBufferHeight
= 600;
1470 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1471 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1472 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
1474 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1475 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
1476 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1479 skip("Failed to create a d3d device\n");
1483 hr
= IDirect3DDevice9_CreateTexture(pDevice
, 16, 16, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &pTexture
, NULL
);
1484 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture failed with %08x\n", hr
);
1485 if(!pTexture
) goto cleanup
;
1487 /* There are 16 pixel samplers. We should be able to access all of them */
1488 for(i
= 0; i
< 16; i
++) {
1489 hr
= IDirect3DDevice9_SetTexture(pDevice
, i
, (IDirect3DBaseTexture9
*) pTexture
);
1490 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture for sampler %d failed with %08x\n", i
, hr
);
1491 hr
= IDirect3DDevice9_SetTexture(pDevice
, i
, NULL
);
1492 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture for sampler %d failed with %08x\n", i
, hr
);
1493 hr
= IDirect3DDevice9_SetSamplerState(pDevice
, i
, D3DSAMP_SRGBTEXTURE
, TRUE
);
1494 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState for sampler %d failed with %08x\n", i
, hr
);
1497 /* Now test all 8 textures stage states */
1498 for(i
= 0; i
< 8; i
++) {
1499 hr
= IDirect3DDevice9_SetTextureStageState(pDevice
, i
, D3DTSS_COLOROP
, D3DTOP_ADD
);
1500 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState for texture %d failed with %08x\n", i
, hr
);
1503 /* Investigations show that accessing higher samplers / textures stage states does not return an error either. Writing
1504 * to too high samplers(approximately sampler 40) causes memory corruption in windows, so there is no bounds checking
1505 * but how do I test that?
1508 if(pTexture
) IDirect3DTexture9_Release(pTexture
);
1511 UINT refcount
= IDirect3D9_Release(pDevice
);
1512 ok(!refcount
, "Device has %u references left.\n", refcount
);
1514 if (pD3d
) IDirect3D9_Release(pD3d
);
1515 if(hwnd
) DestroyWindow(hwnd
);
1518 static void test_depthstenciltest(void)
1522 IDirect3D9
*pD3d
= NULL
;
1523 IDirect3DDevice9
*pDevice
= NULL
;
1524 D3DPRESENT_PARAMETERS d3dpp
;
1525 D3DDISPLAYMODE d3ddm
;
1526 IDirect3DSurface9
*pDepthStencil
= NULL
;
1527 IDirect3DSurface9
*pDepthStencil2
= NULL
;
1528 D3DZBUFFERTYPE state
;
1530 pD3d
= pDirect3DCreate9( D3D_SDK_VERSION
);
1531 ok(pD3d
!= NULL
, "Failed to create IDirect3D9 object\n");
1532 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1533 ok(hwnd
!= NULL
, "Failed to create window\n");
1534 if (!pD3d
|| !hwnd
) goto cleanup
;
1536 IDirect3D9_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
1537 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1538 d3dpp
.Windowed
= TRUE
;
1539 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1540 d3dpp
.BackBufferWidth
= 800;
1541 d3dpp
.BackBufferHeight
= 600;
1542 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1543 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1544 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
1546 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1547 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
1548 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1551 skip("Failed to create a d3d device\n");
1555 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &pDepthStencil
);
1556 ok(hr
== D3D_OK
&& pDepthStencil
!= NULL
, "IDirect3DDevice9_GetDepthStencilSurface failed with %08x\n", hr
);
1559 hr
= IDirect3DDevice9_Clear(pDevice
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0x00000000, 1.0, 0);
1560 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1562 hr
= IDirect3DDevice9_SetDepthStencilSurface(pDevice
, NULL
);
1563 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetDepthStencilSurface failed with %08x\n", hr
);
1565 /* Check if the set buffer is returned on a get. WineD3D had a bug with that once, prevent it from coming back */
1566 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &pDepthStencil2
);
1567 ok(hr
== D3DERR_NOTFOUND
&& pDepthStencil2
== NULL
, "IDirect3DDevice9_GetDepthStencilSurface failed with %08x\n", hr
);
1568 if(pDepthStencil2
) IDirect3DSurface9_Release(pDepthStencil2
);
1570 /* This left the render states untouched! */
1571 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_ZENABLE
, &state
);
1572 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1573 ok(state
== D3DZB_TRUE
, "D3DRS_ZENABLE is %s\n", state
== D3DZB_FALSE
? "D3DZB_FALSE" : (state
== D3DZB_TRUE
? "D3DZB_TRUE" : "D3DZB_USEW"));
1574 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_ZWRITEENABLE
, &state
);
1575 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1576 ok(state
== TRUE
, "D3DRS_ZWRITEENABLE is %s\n", state
? "TRUE" : "FALSE");
1577 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_STENCILENABLE
, &state
);
1578 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1579 ok(state
== FALSE
, "D3DRS_STENCILENABLE is %s\n", state
? "TRUE" : "FALSE");
1580 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_STENCILWRITEMASK
, &state
);
1581 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1582 ok(state
== 0xffffffff, "D3DRS_STENCILWRITEMASK is 0x%08x\n", state
);
1584 /* This is supposed to fail now */
1585 hr
= IDirect3DDevice9_Clear(pDevice
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0x00000000, 1.0, 0);
1586 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1588 hr
= IDirect3DDevice9_SetRenderState(pDevice
, D3DRS_ZENABLE
, D3DZB_FALSE
);
1589 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed with %08x\n", hr
);
1591 hr
= IDirect3DDevice9_SetDepthStencilSurface(pDevice
, pDepthStencil
);
1592 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetDepthStencilSurface failed with %08x\n", hr
);
1594 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_ZENABLE
, &state
);
1595 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1596 ok(state
== D3DZB_FALSE
, "D3DRS_ZENABLE is %s\n", state
== D3DZB_FALSE
? "D3DZB_FALSE" : (state
== D3DZB_TRUE
? "D3DZB_TRUE" : "D3DZB_USEW"));
1598 /* Now it works again */
1599 hr
= IDirect3DDevice9_Clear(pDevice
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0x00000000, 1.0, 0);
1600 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1602 if(pDepthStencil
) IDirect3DSurface9_Release(pDepthStencil
);
1603 if(pDevice
) IDirect3D9_Release(pDevice
);
1605 /* Now see if autodepthstencil disable is honored. First, without a format set */
1606 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1607 d3dpp
.Windowed
= TRUE
;
1608 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1609 d3dpp
.BackBufferWidth
= 800;
1610 d3dpp
.BackBufferHeight
= 600;
1611 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1612 d3dpp
.EnableAutoDepthStencil
= FALSE
;
1613 d3dpp
.AutoDepthStencilFormat
= D3DFMT_UNKNOWN
;
1615 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1616 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
1617 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1620 skip("Failed to create a d3d device\n");
1624 pDepthStencil
= NULL
;
1625 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &pDepthStencil
);
1626 ok(hr
== D3DERR_NOTFOUND
&& pDepthStencil
== NULL
, "IDirect3DDevice9_GetDepthStencilSurface returned %08x, surface = %p\n", hr
, pDepthStencil
);
1628 IDirect3DSurface9_Release(pDepthStencil
);
1629 pDepthStencil
= NULL
;
1632 /* Check the depth test state */
1633 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_ZENABLE
, &state
);
1634 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1635 ok(state
== D3DZB_FALSE
, "D3DRS_ZENABLE is %s\n", state
== D3DZB_FALSE
? "D3DZB_FALSE" : (state
== D3DZB_TRUE
? "D3DZB_TRUE" : "D3DZB_USEW"));
1637 if(pDevice
) IDirect3D9_Release(pDevice
);
1639 /* Next, try EnableAutoDepthStencil FALSE with a depth stencil format set */
1640 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1641 d3dpp
.Windowed
= TRUE
;
1642 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1643 d3dpp
.BackBufferWidth
= 800;
1644 d3dpp
.BackBufferHeight
= 600;
1645 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1646 d3dpp
.EnableAutoDepthStencil
= FALSE
;
1647 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
1649 hr
= IDirect3D9_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1650 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
1651 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1654 skip("Failed to create a d3d device\n");
1658 pDepthStencil
= NULL
;
1659 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &pDepthStencil
);
1660 ok(hr
== D3DERR_NOTFOUND
&& pDepthStencil
== NULL
, "IDirect3DDevice9_GetDepthStencilSurface returned %08x, surface = %p\n", hr
, pDepthStencil
);
1662 IDirect3DSurface9_Release(pDepthStencil
);
1663 pDepthStencil
= NULL
;
1666 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_ZENABLE
, &state
);
1667 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1668 ok(state
== D3DZB_FALSE
, "D3DRS_ZENABLE is %s\n", state
== D3DZB_FALSE
? "D3DZB_FALSE" : (state
== D3DZB_TRUE
? "D3DZB_TRUE" : "D3DZB_USEW"));
1671 if(pDepthStencil
) IDirect3DSurface9_Release(pDepthStencil
);
1674 UINT refcount
= IDirect3D9_Release(pDevice
);
1675 ok(!refcount
, "Device has %u references left.\n", refcount
);
1677 if (pD3d
) IDirect3D9_Release(pD3d
);
1678 if(hwnd
) DestroyWindow(hwnd
);
1681 /* Test what happens when IDirect3DDevice9_DrawIndexedPrimitive is called without a valid index buffer set. */
1682 static void test_draw_indexed(void)
1684 static const struct {
1688 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
1689 {{-1.0f
, 1.0f
, 0.0f
}, 0xffff0000},
1690 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffff0000},
1691 {{ 1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
1693 WORD indices
[] = {0, 1, 2, 3, 0, 2};
1695 static const D3DVERTEXELEMENT9 decl_elements
[] = {
1696 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
1697 {0, 12, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
1701 IDirect3DVertexDeclaration9
*vertex_declaration
= NULL
;
1702 IDirect3DVertexBuffer9
*vertex_buffer
= NULL
;
1703 IDirect3DIndexBuffer9
*index_buffer
= NULL
;
1704 D3DPRESENT_PARAMETERS present_parameters
;
1705 IDirect3DDevice9
*device
= NULL
;
1711 hwnd
= CreateWindow("static", "d3d9_test",
1712 0, 0, 0, 10, 10, 0, 0, 0, 0);
1715 skip("Failed to create window\n");
1719 d3d9
= pDirect3DCreate9(D3D_SDK_VERSION
);
1722 skip("Failed to create IDirect3D9 object\n");
1726 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
1727 present_parameters
.Windowed
= TRUE
;
1728 present_parameters
.hDeviceWindow
= hwnd
;
1729 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1731 hr
= IDirect3D9_CreateDevice(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
1732 NULL
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
1733 if (FAILED(hr
) || !device
)
1735 skip("Failed to create device\n");
1739 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &vertex_declaration
);
1740 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (0x%08x)\n", hr
);
1741 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
1742 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed (0x%08x)\n", hr
);
1744 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, sizeof(quad
), 0, 0, D3DPOOL_DEFAULT
, &vertex_buffer
, NULL
);
1745 ok(SUCCEEDED(hr
), "CreateVertexBuffer failed (0x%08x)\n", hr
);
1746 hr
= IDirect3DVertexBuffer9_Lock(vertex_buffer
, 0, 0, &ptr
, D3DLOCK_DISCARD
);
1747 ok(SUCCEEDED(hr
), "Lock failed (0x%08x)\n", hr
);
1748 memcpy(ptr
, quad
, sizeof(quad
));
1749 hr
= IDirect3DVertexBuffer9_Unlock(vertex_buffer
);
1750 ok(SUCCEEDED(hr
), "Unlock failed (0x%08x)\n", hr
);
1751 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vertex_buffer
, 0, sizeof(*quad
));
1752 ok(SUCCEEDED(hr
), "SetStreamSource failed (0x%08x)\n", hr
);
1754 hr
= IDirect3DDevice9_CreateIndexBuffer(device
, sizeof(indices
), 0, D3DFMT_INDEX16
, D3DPOOL_DEFAULT
, &index_buffer
, NULL
);
1755 ok(SUCCEEDED(hr
), "CreateIndexBuffer failed (0x%08x)\n", hr
);
1756 hr
= IDirect3DIndexBuffer9_Lock(index_buffer
, 0, 0, &ptr
, D3DLOCK_DISCARD
);
1757 ok(SUCCEEDED(hr
), "Lock failed (0x%08x)\n", hr
);
1758 memcpy(ptr
, indices
, sizeof(indices
));
1759 hr
= IDirect3DIndexBuffer9_Unlock(index_buffer
);
1760 ok(SUCCEEDED(hr
), "Unlock failed (0x%08x)\n", hr
);
1761 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
1762 ok(SUCCEEDED(hr
), "SetRenderState D3DRS_LIGHTING failed (0x%08x)\n", hr
);
1763 hr
= IDirect3DDevice9_BeginScene(device
);
1764 ok(SUCCEEDED(hr
), "BeginScene failed (0x%08x)\n", hr
);
1766 /* NULL index buffer. Should fail */
1767 hr
= IDirect3DDevice9_SetIndices(device
, NULL
);
1768 ok(SUCCEEDED(hr
), "SetIndices failed (0x%08x)\n", hr
);
1769 hr
= IDirect3DDevice9_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, 0 /* BaseVertexIndex */, 0 /* MinIndex */,
1770 4 /* NumVerts */, 0 /* StartIndex */, 2 /*PrimCount */);
1771 ok(hr
== D3DERR_INVALIDCALL
, "DrawIndexedPrimitive returned 0x%08x, expected D3DERR_INVALIDCALL (0x%08x)\n",
1772 hr
, D3DERR_INVALIDCALL
);
1774 /* Valid index buffer, NULL vertex declaration. Should fail */
1775 hr
= IDirect3DDevice9_SetIndices(device
, index_buffer
);
1776 ok(SUCCEEDED(hr
), "SetIndices failed (0x%08x)\n", hr
);
1777 hr
= IDirect3DDevice9_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, 0 /* BaseVertexIndex */, 0 /* MinIndex */,
1778 4 /* NumVerts */, 0 /* StartIndex */, 2 /*PrimCount */);
1779 ok(hr
== D3DERR_INVALIDCALL
, "DrawIndexedPrimitive returned 0x%08x, expected D3DERR_INVALIDCALL (0x%08x)\n",
1780 hr
, D3DERR_INVALIDCALL
);
1782 /* Valid index buffer and vertex declaration. Should succeed */
1783 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, vertex_declaration
);
1784 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed (0x%08x)\n", hr
);
1785 hr
= IDirect3DDevice9_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, 0 /* BaseVertexIndex */, 0 /* MinIndex */,
1786 4 /* NumVerts */, 0 /* StartIndex */, 2 /*PrimCount */);
1787 ok(SUCCEEDED(hr
), "DrawIndexedPrimitive failed (0x%08x)\n", hr
);
1789 hr
= IDirect3DDevice9_EndScene(device
);
1790 ok(SUCCEEDED(hr
), "EndScene failed (0x%08x)\n", hr
);
1792 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
1793 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
1795 IDirect3DVertexBuffer9_Release(vertex_buffer
);
1796 IDirect3DIndexBuffer9_Release(index_buffer
);
1797 IDirect3DVertexDeclaration9_Release(vertex_declaration
);
1802 UINT refcount
= IDirect3DDevice9_Release(device
);
1803 ok(!refcount
, "Device has %u references left.\n", refcount
);
1805 if (d3d9
) IDirect3D9_Release(d3d9
);
1806 if (hwnd
) DestroyWindow(hwnd
);
1809 static void test_null_stream(void)
1811 IDirect3DVertexBuffer9
*buffer
= NULL
;
1812 D3DPRESENT_PARAMETERS present_parameters
;
1813 IDirect3DDevice9
*device
= NULL
;
1817 IDirect3DVertexShader9
*shader
= NULL
;
1818 IDirect3DVertexDeclaration9
*decl
= NULL
;
1819 DWORD shader_code
[] = {
1820 0xfffe0101, /* vs_1_1 */
1821 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
1822 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
1823 0x0000ffff /* end */
1825 static const D3DVERTEXELEMENT9 decl_elements
[] = {
1826 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
1827 {1, 0, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
1831 d3d9
= pDirect3DCreate9( D3D_SDK_VERSION
);
1832 ok(d3d9
!= NULL
, "Failed to create IDirect3D9 object\n");
1833 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1834 ok(hwnd
!= NULL
, "Failed to create window\n");
1835 if (!d3d9
|| !hwnd
) goto cleanup
;
1837 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
1838 present_parameters
.Windowed
= TRUE
;
1839 present_parameters
.hDeviceWindow
= hwnd
;
1840 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1842 hr
= IDirect3D9_CreateDevice( d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1843 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
1844 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1847 skip("Failed to create a d3d device\n");
1851 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_code
, &shader
);
1853 skip("No vertex shader support\n");
1856 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &decl
);
1857 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateVertexDeclaration failed (0x%08x)\n", hr
);
1859 skip("Vertex declaration handling not possible.\n");
1862 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, 12 * sizeof(float), 0, 0, D3DPOOL_MANAGED
, &buffer
, NULL
);
1863 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateVertexBuffer failed (0x%08x)\n", hr
);
1865 skip("Vertex buffer handling not possible.\n");
1869 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, buffer
, 0, sizeof(float) * 3);
1870 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetStreamSource failed (0x%08x)\n", hr
);
1871 hr
= IDirect3DDevice9_SetStreamSource(device
, 1, NULL
, 0, 0);
1872 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetStreamSource failed (0x%08x)\n", hr
);
1873 hr
= IDirect3DDevice9_SetVertexShader(device
, shader
);
1874 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShader failed (0x%08x)\n", hr
);
1875 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl
);
1876 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexDeclaration failed (0x%08x)\n", hr
);
1878 hr
= IDirect3DDevice9_BeginScene(device
);
1879 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed (0x%08x)\n", hr
);
1881 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_POINTLIST
, 0, 1);
1882 ok(SUCCEEDED(hr
), "IDirect3DDevice9_DrawPrimitive failed (0x%08x)\n", hr
);
1884 hr
= IDirect3DDevice9_EndScene(device
);
1885 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed (0x%08x)\n", hr
);
1888 IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 0, 0);
1889 IDirect3DDevice9_SetVertexShader(device
, NULL
);
1890 IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
1893 if (buffer
) IDirect3DVertexBuffer9_Release(buffer
);
1894 if(decl
) IDirect3DVertexDeclaration9_Release(decl
);
1895 if(shader
) IDirect3DVertexShader9_Release(shader
);
1898 UINT refcount
= IDirect3DDevice9_Release(device
);
1899 ok(!refcount
, "Device has %u references left.\n", refcount
);
1901 if(d3d9
) IDirect3D9_Release(d3d9
);
1904 static void test_lights(void)
1906 D3DPRESENT_PARAMETERS present_parameters
;
1907 IDirect3DDevice9
*device
= NULL
;
1915 d3d9
= pDirect3DCreate9( D3D_SDK_VERSION
);
1916 ok(d3d9
!= NULL
, "Failed to create IDirect3D9 object\n");
1917 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1918 ok(hwnd
!= NULL
, "Failed to create window\n");
1919 if (!d3d9
|| !hwnd
) goto cleanup
;
1921 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
1922 present_parameters
.Windowed
= TRUE
;
1923 present_parameters
.hDeviceWindow
= hwnd
;
1924 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1926 hr
= IDirect3D9_CreateDevice( d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
1927 D3DCREATE_HARDWARE_VERTEXPROCESSING
| D3DCREATE_PUREDEVICE
, &present_parameters
, &device
);
1928 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
|| hr
== D3DERR_INVALIDCALL
,
1929 "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1932 skip("Failed to create a d3d device\n");
1936 memset(&caps
, 0, sizeof(caps
));
1937 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
1938 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetDeviceCaps failed with %08x\n", hr
);
1940 for(i
= 1; i
<= caps
.MaxActiveLights
; i
++) {
1941 hr
= IDirect3DDevice9_LightEnable(device
, i
, TRUE
);
1942 ok(hr
== D3D_OK
, "Enabling light %u failed with %08x\n", i
, hr
);
1943 hr
= IDirect3DDevice9_GetLightEnable(device
, i
, &enabled
);
1944 ok(hr
== D3D_OK
, "GetLightEnable on light %u failed with %08x\n", i
, hr
);
1945 ok(enabled
, "Light %d is %s\n", i
, enabled
? "enabled" : "disabled");
1948 /* TODO: Test the rendering results in this situation */
1949 hr
= IDirect3DDevice9_LightEnable(device
, i
+ 1, TRUE
);
1950 ok(hr
== D3D_OK
, "Enabling one light more than supported returned %08x\n", hr
);
1951 hr
= IDirect3DDevice9_GetLightEnable(device
, i
+ 1, &enabled
);
1952 ok(hr
== D3D_OK
, "GetLightEnable on light %u failed with %08x\n", i
+ 1, hr
);
1953 ok(enabled
, "Light %d is %s\n", i
+ 1, enabled
? "enabled" : "disabled");
1954 hr
= IDirect3DDevice9_LightEnable(device
, i
+ 1, FALSE
);
1955 ok(hr
== D3D_OK
, "Disabling the additional returned %08x\n", hr
);
1957 for(i
= 1; i
<= caps
.MaxActiveLights
; i
++) {
1958 hr
= IDirect3DDevice9_LightEnable(device
, i
, FALSE
);
1959 ok(hr
== D3D_OK
, "Disabling light %u failed with %08x\n", i
, hr
);
1965 UINT refcount
= IDirect3DDevice9_Release(device
);
1966 ok(!refcount
, "Device has %u references left.\n", refcount
);
1968 if(d3d9
) IDirect3D9_Release(d3d9
);
1971 static void test_set_stream_source(void)
1973 D3DPRESENT_PARAMETERS present_parameters
;
1974 IDirect3DDevice9
*device
= NULL
;
1978 IDirect3DVertexBuffer9
*pVertexBuffer
= NULL
;
1980 d3d9
= pDirect3DCreate9( D3D_SDK_VERSION
);
1981 ok(d3d9
!= NULL
, "Failed to create IDirect3D9 object\n");
1982 hwnd
= CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1983 ok(hwnd
!= NULL
, "Failed to create window\n");
1984 if (!d3d9
|| !hwnd
) goto cleanup
;
1986 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
1987 present_parameters
.Windowed
= TRUE
;
1988 present_parameters
.hDeviceWindow
= hwnd
;
1989 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1991 hr
= IDirect3D9_CreateDevice( d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
1992 D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
1993 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
|| hr
== D3DERR_INVALIDCALL
,
1994 "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1997 hr
= IDirect3D9_CreateDevice( d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_REF
, hwnd
,
1998 D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
1999 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
2002 skip("Failed to create a d3d device\n");
2007 hr
= IDirect3DDevice9_CreateVertexBuffer( device
, 512, 0, 0, D3DPOOL_DEFAULT
, &pVertexBuffer
, NULL
);
2008 ok(hr
== D3D_OK
, "Failed to create a vertex buffer, hr = %08x\n", hr
);
2009 if (SUCCEEDED(hr
)) {
2010 /* Some cards(Geforce 7400 at least) accept non-aligned offsets, others(radeon 9000 verified) reject it,
2011 * so accept both results. Wine currently rejects this to be able to optimize the vbo conversion, but writes
2014 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, pVertexBuffer
, 0, 32);
2015 ok(hr
== D3D_OK
, "Failed to set the stream source, offset 0, hr = %08x\n", hr
);
2016 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, pVertexBuffer
, 1, 32);
2017 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Unexpected result when setting the stream source, offset 1, hr = %08x\n", hr
);
2018 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, pVertexBuffer
, 2, 32);
2019 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Unexpected result when setting the stream source, offset 2, hr = %08x\n", hr
);
2020 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, pVertexBuffer
, 3, 32);
2021 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Unexpected result when setting the stream source, offset 3, hr = %08x\n", hr
);
2022 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, pVertexBuffer
, 4, 32);
2023 ok(hr
== D3D_OK
, "Failed to set the stream source, offset 4, hr = %08x\n", hr
);
2025 /* Try to set the NULL buffer with an offset and stride 0 */
2026 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 0, 0);
2027 ok(hr
== D3D_OK
, "Failed to set the stream source, offset 0, hr = %08x\n", hr
);
2028 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 1, 0);
2029 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Unexpected result when setting the stream source, offset 1, hr = %08x\n", hr
);
2030 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 2, 0);
2031 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Unexpected result when setting the stream source, offset 2, hr = %08x\n", hr
);
2032 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 3, 0);
2033 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Unexpected result when setting the stream source, offset 3, hr = %08x\n", hr
);
2034 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 4, 0);
2035 ok(hr
== D3D_OK
, "Failed to set the stream source, offset 4, hr = %08x\n", hr
);
2037 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 0, 0);
2038 ok(hr
== D3D_OK
, "Failed to set the stream source, offset 4, hr = %08x\n", hr
);
2041 if (pVertexBuffer
) IDirect3DVertexBuffer9_Release(pVertexBuffer
);
2044 UINT refcount
= IDirect3DDevice9_Release(device
);
2045 ok(!refcount
, "Device has %u references left.\n", refcount
);
2047 if(d3d9
) IDirect3D9_Release(d3d9
);
2051 D3DFORMAT DisplayFormat
;
2052 D3DFORMAT BackBufferFormat
;
2056 struct formats r5g6b5_format_list
[] =
2058 { D3DFMT_R5G6B5
, D3DFMT_R5G6B5
, TRUE
},
2059 { D3DFMT_R5G6B5
, D3DFMT_X1R5G5B5
, FALSE
},
2060 { D3DFMT_R5G6B5
, D3DFMT_A1R5G5B5
, FALSE
},
2061 { D3DFMT_R5G6B5
, D3DFMT_X8R8G8B8
, FALSE
},
2062 { D3DFMT_R5G6B5
, D3DFMT_A8R8G8B8
, FALSE
},
2066 struct formats x1r5g5b5_format_list
[] =
2068 { D3DFMT_X1R5G5B5
, D3DFMT_R5G6B5
, FALSE
},
2069 { D3DFMT_X1R5G5B5
, D3DFMT_X1R5G5B5
, TRUE
},
2070 { D3DFMT_X1R5G5B5
, D3DFMT_A1R5G5B5
, TRUE
},
2071 { D3DFMT_X1R5G5B5
, D3DFMT_X8R8G8B8
, FALSE
},
2072 { D3DFMT_X1R5G5B5
, D3DFMT_A8R8G8B8
, FALSE
},
2074 /* A1R5G5B5 should not be usable as a display format, it is backbuffer-only */
2075 { D3DFMT_A1R5G5B5
, D3DFMT_R5G6B5
, FALSE
},
2076 { D3DFMT_A1R5G5B5
, D3DFMT_X1R5G5B5
, FALSE
},
2077 { D3DFMT_A1R5G5B5
, D3DFMT_A1R5G5B5
, FALSE
},
2078 { D3DFMT_A1R5G5B5
, D3DFMT_X8R8G8B8
, FALSE
},
2079 { D3DFMT_A1R5G5B5
, D3DFMT_A8R8G8B8
, FALSE
},
2083 struct formats x8r8g8b8_format_list
[] =
2085 { D3DFMT_X8R8G8B8
, D3DFMT_R5G6B5
, FALSE
},
2086 { D3DFMT_X8R8G8B8
, D3DFMT_X1R5G5B5
, FALSE
},
2087 { D3DFMT_X8R8G8B8
, D3DFMT_A1R5G5B5
, FALSE
},
2088 { D3DFMT_X8R8G8B8
, D3DFMT_X8R8G8B8
, TRUE
},
2089 { D3DFMT_X8R8G8B8
, D3DFMT_A8R8G8B8
, TRUE
},
2091 /* A1R8G8B8 should not be usable as a display format, it is backbuffer-only */
2092 { D3DFMT_A8R8G8B8
, D3DFMT_R5G6B5
, FALSE
},
2093 { D3DFMT_A8R8G8B8
, D3DFMT_X1R5G5B5
, FALSE
},
2094 { D3DFMT_A8R8G8B8
, D3DFMT_A1R5G5B5
, FALSE
},
2095 { D3DFMT_A8R8G8B8
, D3DFMT_X8R8G8B8
, FALSE
},
2096 { D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
, FALSE
},
2100 static void test_display_formats(void)
2102 /* Direct3D9 offers 4 display formats R5G6B5, X1R5G5B5, X8R8G8B8 and A2R10G10B10.
2103 * Next to these there are 6 different backbuffer formats. Only a fixed number of
2104 * combinations are possible in FULLSCREEN mode. In windowed mode more combinations are
2105 * allowed due to depth conversion and this is likely driver dependent.
2106 * This test checks which combinations are possible in fullscreen mode and this should not be driver dependent.
2107 * TODO: handle A2R10G10B10 but what hardware supports it? Parhelia? It is very rare. */
2109 UINT Adapter
= D3DADAPTER_DEFAULT
;
2110 D3DDEVTYPE DeviceType
= D3DDEVTYPE_HAL
;
2114 IDirect3D9
*d3d9
= pDirect3DCreate9( D3D_SDK_VERSION
);
2115 ok(d3d9
!= NULL
, "Failed to create IDirect3D9 object\n");
2118 nmodes
= IDirect3D9_GetAdapterModeCount(d3d9
, D3DADAPTER_DEFAULT
, D3DFMT_R5G6B5
);
2120 skip("Display format R5G6B5 not supported, skipping\n");
2122 trace("Testing display format R5G6B5\n");
2123 for(i
=0; r5g6b5_format_list
[i
].DisplayFormat
!= 0; i
++)
2125 hr
= IDirect3D9_CheckDeviceType(d3d9
, Adapter
, DeviceType
, r5g6b5_format_list
[i
].DisplayFormat
, r5g6b5_format_list
[i
].BackBufferFormat
, FALSE
);
2127 if(r5g6b5_format_list
[i
].shouldPass
)
2129 broken(hr
== D3DERR_NOTAVAILABLE
),
2130 "format %d %d didn't pass with hr=%#08x\n", r5g6b5_format_list
[i
].DisplayFormat
, r5g6b5_format_list
[i
].BackBufferFormat
, hr
);
2132 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
);
2136 nmodes
= IDirect3D9_GetAdapterModeCount(d3d9
, D3DADAPTER_DEFAULT
, D3DFMT_X1R5G5B5
);
2138 skip("Display format X1R5G5B5 not supported, skipping\n");
2140 trace("Testing display format X1R5G5B5\n");
2141 for(i
=0; x1r5g5b5_format_list
[i
].DisplayFormat
!= 0; i
++)
2143 hr
= IDirect3D9_CheckDeviceType(d3d9
, Adapter
, DeviceType
, x1r5g5b5_format_list
[i
].DisplayFormat
, x1r5g5b5_format_list
[i
].BackBufferFormat
, FALSE
);
2145 if(x1r5g5b5_format_list
[i
].shouldPass
)
2146 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
);
2148 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
);
2152 nmodes
= IDirect3D9_GetAdapterModeCount(d3d9
, D3DADAPTER_DEFAULT
, D3DFMT_X8R8G8B8
);
2154 skip("Display format X8R8G8B8 not supported, skipping\n");
2156 trace("Testing display format X8R8G8B8\n");
2157 for(i
=0; x8r8g8b8_format_list
[i
].DisplayFormat
!= 0; i
++)
2159 hr
= IDirect3D9_CheckDeviceType(d3d9
, Adapter
, DeviceType
, x8r8g8b8_format_list
[i
].DisplayFormat
, x8r8g8b8_format_list
[i
].BackBufferFormat
, FALSE
);
2161 if(x8r8g8b8_format_list
[i
].shouldPass
)
2163 broken(hr
== D3DERR_NOTAVAILABLE
),
2164 "format %d %d didn't pass with hr=%#08x\n", x8r8g8b8_format_list
[i
].DisplayFormat
, x8r8g8b8_format_list
[i
].BackBufferFormat
, hr
);
2166 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
);
2170 if(d3d9
) IDirect3D9_Release(d3d9
);
2173 static void test_scissor_size(void)
2175 IDirect3D9
*d3d9_ptr
= 0;
2177 static const struct {
2178 int winx
; int winy
; int backx
; int backy
; BOOL window
;
2179 } scts
[] = { /* scissor tests */
2180 {800, 600, 640, 480, TRUE
},
2181 {800, 600, 640, 480, FALSE
},
2182 {640, 480, 800, 600, TRUE
},
2183 {640, 480, 800, 600, FALSE
},
2186 d3d9_ptr
= pDirect3DCreate9(D3D_SDK_VERSION
);
2187 ok(d3d9_ptr
!= NULL
, "Failed to create IDirect3D9 object\n");
2189 skip("Failed to create IDirect3D9 object\n");
2193 for(i
=0; i
<sizeof(scts
)/sizeof(scts
[0]); i
++) {
2194 IDirect3DDevice9
*device_ptr
= 0;
2195 D3DPRESENT_PARAMETERS present_parameters
;
2201 wc
.lpfnWndProc
= DefWindowProc
;
2202 wc
.lpszClassName
= "d3d9_test_wc";
2205 hwnd
= CreateWindow("d3d9_test_wc", "d3d9_test",
2206 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, scts
[i
].winx
, scts
[i
].winy
, 0, 0, 0, 0);
2208 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
2209 present_parameters
.Windowed
= scts
[i
].window
;
2210 present_parameters
.hDeviceWindow
= hwnd
;
2211 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2212 present_parameters
.BackBufferWidth
= scts
[i
].backx
;
2213 present_parameters
.BackBufferHeight
= scts
[i
].backy
;
2214 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
2215 present_parameters
.EnableAutoDepthStencil
= TRUE
;
2216 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
2218 hr
= IDirect3D9_CreateDevice(d3d9_ptr
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, present_parameters
.hDeviceWindow
, D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device_ptr
);
2220 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D16
;
2221 hr
= IDirect3D9_CreateDevice(d3d9_ptr
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, present_parameters
.hDeviceWindow
, D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device_ptr
);
2223 hr
= IDirect3D9_CreateDevice(d3d9_ptr
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, present_parameters
.hDeviceWindow
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device_ptr
);
2226 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D_CreateDevice returned: %08x\n", hr
);
2230 DestroyWindow(hwnd
);
2231 skip("Creating the device failed\n");
2235 /* Check for the default scissor rect size */
2236 hr
= IDirect3DDevice9_GetScissorRect(device_ptr
, &scissorrect
);
2237 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetScissorRect failed with: %08x\n", hr
);
2238 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
);
2240 /* check the scissorrect values after a reset */
2241 present_parameters
.BackBufferWidth
= 800;
2242 present_parameters
.BackBufferHeight
= 600;
2243 hr
= IDirect3DDevice9_Reset(device_ptr
, &present_parameters
);
2244 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
2245 hr
= IDirect3DDevice9_TestCooperativeLevel(device_ptr
);
2246 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
2248 hr
= IDirect3DDevice9_GetScissorRect(device_ptr
, &scissorrect
);
2249 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetScissorRect failed with: %08x\n", hr
);
2250 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);
2255 ref
= IDirect3DDevice9_Release(device_ptr
);
2256 DestroyWindow(hwnd
);
2257 ok(ref
== 0, "The device was not properly freed: refcount %u\n", ref
);
2262 if(d3d9_ptr
) IDirect3D9_Release(d3d9_ptr
);
2266 static void test_multi_device(void)
2268 IDirect3DDevice9
*device1
= NULL
, *device2
= NULL
;
2269 D3DPRESENT_PARAMETERS present_parameters
;
2270 HWND hwnd1
= NULL
, hwnd2
= NULL
;
2275 d3d9
= pDirect3DCreate9(D3D_SDK_VERSION
);
2276 ok(d3d9
!= NULL
, "Failed to create a d3d9 object.\n");
2277 if (!d3d9
) goto fail
;
2279 hwnd1
= CreateWindow("static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
2280 ok(hwnd1
!= NULL
, "Failed to create a window.\n");
2281 if (!hwnd1
) goto fail
;
2283 memset(&present_parameters
, 0, sizeof(present_parameters
));
2284 present_parameters
.Windowed
= TRUE
;
2285 present_parameters
.hDeviceWindow
= hwnd1
;
2286 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2288 hr
= IDirect3D9_CreateDevice(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd1
,
2289 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device1
);
2290 IDirect3D9_Release(d3d9
);
2293 skip("Failed to create a device\n");
2297 d3d9
= pDirect3DCreate9(D3D_SDK_VERSION
);
2298 ok(d3d9
!= NULL
, "Failed to create a d3d9 object.\n");
2299 if (!d3d9
) goto fail
;
2301 hwnd2
= CreateWindow("static", "d3d9_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
2302 ok(hwnd2
!= NULL
, "Failed to create a window.\n");
2303 if (!hwnd2
) goto fail
;
2305 memset(&present_parameters
, 0, sizeof(present_parameters
));
2306 present_parameters
.Windowed
= TRUE
;
2307 present_parameters
.hDeviceWindow
= hwnd2
;
2308 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2310 hr
= IDirect3D9_CreateDevice(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd2
,
2311 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device2
);
2312 ok(SUCCEEDED(hr
), "Failed to create a device, hr %#x\n", hr
);
2313 IDirect3D9_Release(d3d9
);
2315 if (FAILED(hr
)) goto fail
;
2318 if (d3d9
) IDirect3D9_Release(d3d9
);
2321 refcount
= IDirect3DDevice9_Release(device1
);
2322 ok(!refcount
, "Device has %u references left.\n", refcount
);
2326 refcount
= IDirect3DDevice9_Release(device2
);
2327 ok(!refcount
, "Device has %u references left.\n", refcount
);
2329 if (hwnd1
) DestroyWindow(hwnd1
);
2330 if (hwnd2
) DestroyWindow(hwnd2
);
2333 static HWND filter_messages
;
2340 struct wndproc_thread_param
2343 HANDLE window_created
;
2344 HANDLE test_finished
;
2347 static LRESULT CALLBACK
test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2349 if (filter_messages
&& filter_messages
== hwnd
)
2351 ok(message
== WM_DISPLAYCHANGE
|| message
== WM_IME_NOTIFY
,
2352 "Received unexpected message %#x for window %p.\n", message
, hwnd
);
2355 if (expect_message
.window
== hwnd
&& expect_message
.message
== message
) expect_message
.message
= 0;
2357 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
2360 static DWORD WINAPI
wndproc_thread(void *param
)
2362 struct wndproc_thread_param
*p
= param
;
2366 p
->dummy_window
= CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test",
2367 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
2369 ret
= SetEvent(p
->window_created
);
2370 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
2376 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage(&msg
);
2377 res
= WaitForSingleObject(p
->test_finished
, 100);
2378 if (res
== WAIT_OBJECT_0
) break;
2379 if (res
!= WAIT_TIMEOUT
)
2381 ok(0, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
2386 DestroyWindow(p
->dummy_window
);
2391 static void test_wndproc(void)
2393 struct wndproc_thread_param thread_params
;
2394 HWND device_window
, focus_window
, tmp
;
2395 IDirect3DDevice9
*device
;
2404 if (!(d3d9
= pDirect3DCreate9(D3D_SDK_VERSION
)))
2406 skip("Failed to create IDirect3D9 object, skipping tests.\n");
2410 wc
.lpfnWndProc
= test_proc
;
2411 wc
.lpszClassName
= "d3d9_test_wndproc_wc";
2412 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2414 thread_params
.window_created
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
2415 ok(!!thread_params
.window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
2416 thread_params
.test_finished
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
2417 ok(!!thread_params
.test_finished
, "CreateEvent failed, last error %#x.\n", GetLastError());
2419 focus_window
= CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test",
2420 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
2421 device_window
= CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test",
2422 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
2423 thread
= CreateThread(NULL
, 0, wndproc_thread
, &thread_params
, 0, &tid
);
2424 ok(!!thread
, "Failed to create thread, last error %#x.\n", GetLastError());
2426 res
= WaitForSingleObject(thread_params
.window_created
, INFINITE
);
2427 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
2429 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2430 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2431 (LONG_PTR
)test_proc
, proc
);
2432 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2433 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2434 (LONG_PTR
)test_proc
, proc
);
2436 trace("device_window %p, focus_window %p, dummy_window %p.\n",
2437 device_window
, focus_window
, thread_params
.dummy_window
);
2440 ok(tmp
== device_window
, "Expected focus %p, got %p.\n", device_window
, tmp
);
2441 tmp
= GetForegroundWindow();
2442 ok(tmp
== thread_params
.dummy_window
, "Expected foreground window %p, got %p.\n",
2443 thread_params
.dummy_window
, tmp
);
2445 expect_message
.window
= focus_window
;
2446 expect_message
.message
= WM_SETFOCUS
;
2448 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage(&msg
);
2450 device
= create_device(d3d9
, device_window
, focus_window
, FALSE
);
2453 skip("Failed to create a D3D device, skipping tests.\n");
2457 ok(!expect_message
.message
, "Expected message %#x for window %p, but didn't receive it.\n",
2458 expect_message
.message
, expect_message
.window
);
2459 if (0) /* Disabled until we can make this work in a reliable way on Wine. */
2462 ok(tmp
== focus_window
, "Expected focus %p, got %p.\n", focus_window
, tmp
);
2463 tmp
= GetForegroundWindow();
2464 ok(tmp
== focus_window
, "Expected foreground window %p, got %p.\n", focus_window
, tmp
);
2466 SetForegroundWindow(focus_window
);
2468 filter_messages
= focus_window
;
2470 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2471 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2472 (LONG_PTR
)test_proc
, proc
);
2474 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2475 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2476 (LONG_PTR
)test_proc
, proc
);
2478 ref
= IDirect3DDevice9_Release(device
);
2479 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2481 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2482 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2483 (LONG_PTR
)test_proc
, proc
);
2485 device
= create_device(d3d9
, focus_window
, focus_window
, FALSE
);
2488 skip("Failed to create a D3D device, skipping tests.\n");
2492 ref
= IDirect3DDevice9_Release(device
);
2493 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2495 device
= create_device(d3d9
, device_window
, focus_window
, FALSE
);
2498 skip("Failed to create a D3D device, skipping tests.\n");
2502 proc
= SetWindowLongPtrA(focus_window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2503 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2504 (LONG_PTR
)test_proc
, proc
);
2506 ref
= IDirect3DDevice9_Release(device
);
2507 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2509 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2510 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2511 (LONG_PTR
)DefWindowProcA
, proc
);
2514 filter_messages
= NULL
;
2515 IDirect3D9_Release(d3d9
);
2517 SetEvent(thread_params
.test_finished
);
2518 WaitForSingleObject(thread
, INFINITE
);
2519 CloseHandle(thread_params
.test_finished
);
2520 CloseHandle(thread_params
.window_created
);
2521 CloseHandle(thread
);
2523 DestroyWindow(device_window
);
2524 DestroyWindow(focus_window
);
2525 UnregisterClassA("d3d9_test_wndproc_wc", GetModuleHandleA(NULL
));
2528 static void test_wndproc_windowed(void)
2530 struct wndproc_thread_param thread_params
;
2531 HWND device_window
, focus_window
, tmp
;
2532 IDirect3DDevice9
*device
;
2540 if (!(d3d9
= pDirect3DCreate9(D3D_SDK_VERSION
)))
2542 skip("Failed to create IDirect3D9 object, skipping tests.\n");
2546 wc
.lpfnWndProc
= test_proc
;
2547 wc
.lpszClassName
= "d3d9_test_wndproc_wc";
2548 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2550 thread_params
.window_created
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
2551 ok(!!thread_params
.window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
2552 thread_params
.test_finished
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
2553 ok(!!thread_params
.test_finished
, "CreateEvent failed, last error %#x.\n", GetLastError());
2555 focus_window
= CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test",
2556 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
2557 device_window
= CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test",
2558 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
2559 thread
= CreateThread(NULL
, 0, wndproc_thread
, &thread_params
, 0, &tid
);
2560 ok(!!thread
, "Failed to create thread, last error %#x.\n", GetLastError());
2562 res
= WaitForSingleObject(thread_params
.window_created
, INFINITE
);
2563 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
2565 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2566 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2567 (LONG_PTR
)test_proc
, proc
);
2568 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2569 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2570 (LONG_PTR
)test_proc
, proc
);
2572 trace("device_window %p, focus_window %p, dummy_window %p.\n",
2573 device_window
, focus_window
, thread_params
.dummy_window
);
2576 ok(tmp
== device_window
, "Expected focus %p, got %p.\n", device_window
, tmp
);
2577 tmp
= GetForegroundWindow();
2578 ok(tmp
== thread_params
.dummy_window
, "Expected foreground window %p, got %p.\n",
2579 thread_params
.dummy_window
, tmp
);
2581 filter_messages
= focus_window
;
2583 device
= create_device(d3d9
, device_window
, focus_window
, TRUE
);
2586 skip("Failed to create a D3D device, skipping tests.\n");
2591 ok(tmp
== device_window
, "Expected focus %p, got %p.\n", device_window
, tmp
);
2592 tmp
= GetForegroundWindow();
2593 ok(tmp
== thread_params
.dummy_window
, "Expected foreground window %p, got %p.\n",
2594 thread_params
.dummy_window
, tmp
);
2596 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2597 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2598 (LONG_PTR
)test_proc
, proc
);
2600 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2601 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2602 (LONG_PTR
)test_proc
, proc
);
2604 ref
= IDirect3DDevice9_Release(device
);
2605 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2607 filter_messages
= device_window
;
2609 device
= create_device(d3d9
, focus_window
, focus_window
, TRUE
);
2612 skip("Failed to create a D3D device, skipping tests.\n");
2616 ref
= IDirect3DDevice9_Release(device
);
2617 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2619 device
= create_device(d3d9
, device_window
, focus_window
, TRUE
);
2622 skip("Failed to create a D3D device, skipping tests.\n");
2626 ref
= IDirect3DDevice9_Release(device
);
2627 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2630 filter_messages
= NULL
;
2631 IDirect3D9_Release(d3d9
);
2633 SetEvent(thread_params
.test_finished
);
2634 WaitForSingleObject(thread
, INFINITE
);
2635 CloseHandle(thread_params
.test_finished
);
2636 CloseHandle(thread_params
.window_created
);
2637 CloseHandle(thread
);
2639 DestroyWindow(device_window
);
2640 DestroyWindow(focus_window
);
2641 UnregisterClassA("d3d9_test_wndproc_wc", GetModuleHandleA(NULL
));
2644 static inline void set_fpu_cw(WORD cw
)
2646 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2647 __asm__
volatile ("fnclex");
2648 __asm__
volatile ("fldcw %0" : : "m" (cw
));
2652 static inline WORD
get_fpu_cw(void)
2655 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2656 __asm__
volatile ("fnstcw %0" : "=m" (cw
));
2661 static void test_fpu_setup(void)
2663 D3DPRESENT_PARAMETERS present_parameters
;
2664 IDirect3DDevice9
*device
;
2670 d3d9
= pDirect3DCreate9(D3D_SDK_VERSION
);
2671 ok(!!d3d9
, "Failed to create a d3d9 object.\n");
2674 window
= CreateWindowA("static", "d3d9_test", WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
2675 ok(!!window
, "Failed to create a window.\n");
2676 if (!window
) goto done
;
2678 memset(&present_parameters
, 0, sizeof(present_parameters
));
2679 present_parameters
.Windowed
= TRUE
;
2680 present_parameters
.hDeviceWindow
= window
;
2681 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2685 ok(cw
== 0xf60, "cw is %#x, expected 0xf60.\n", cw
);
2687 hr
= IDirect3D9_CreateDevice(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, window
,
2688 D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
2691 skip("Failed to create a device, hr %#x.\n", hr
);
2697 ok(cw
== 0x7f, "cw is %#x, expected 0x7f.\n", cw
);
2699 IDirect3DDevice9_Release(device
);
2702 ok(cw
== 0x7f, "cw is %#x, expected 0x7f.\n", cw
);
2705 ok(cw
== 0xf60, "cw is %#x, expected 0xf60.\n", cw
);
2707 hr
= IDirect3D9_CreateDevice(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, window
,
2708 D3DCREATE_HARDWARE_VERTEXPROCESSING
| D3DCREATE_FPU_PRESERVE
, &present_parameters
, &device
);
2709 ok(SUCCEEDED(hr
), "CreateDevice failed, hr %#x.\n", hr
);
2712 ok(cw
== 0xf60, "cw is %#x, expected 0xf60.\n", cw
);
2715 IDirect3DDevice9_Release(device
);
2718 if (window
) DestroyWindow(window
);
2719 if (d3d9
) IDirect3D9_Release(d3d9
);
2724 HMODULE d3d9_handle
= LoadLibraryA( "d3d9.dll" );
2727 skip("Could not load d3d9.dll\n");
2731 pDirect3DCreate9
= (void *)GetProcAddress( d3d9_handle
, "Direct3DCreate9" );
2732 ok(pDirect3DCreate9
!= NULL
, "Failed to get address of Direct3DCreate9\n");
2733 if (pDirect3DCreate9
)
2735 IDirect3D9
*d3d9
= pDirect3DCreate9( D3D_SDK_VERSION
);
2738 skip("could not create D3D9 object\n");
2741 IDirect3D9_Release(d3d9
);
2743 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2746 test_multi_device();
2747 test_display_formats();
2748 test_display_modes();
2751 test_mipmap_levels();
2752 test_checkdevicemultisampletype();
2757 test_depthstenciltest();
2758 test_draw_indexed();
2761 test_set_stream_source();
2762 test_scissor_size();
2764 test_wndproc_windowed();