2 * Copyright (C) 2006 Vitaliy Margolen
3 * Copyright (C) 2006 Chris Robinson
4 * Copyright 2006-2008, 2010-2011, 2013 Stefan Dösinger for CodeWeavers
5 * Copyright 2005, 2006, 2007 Henri Verbeet
6 * Copyright 2013 Henri Verbeet for CodeWeavers
7 * Copyright (C) 2008 Rico Schüller
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/test.h"
28 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
29 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
31 static INT screen_width
;
32 static INT screen_height
;
34 static const DWORD simple_vs
[] =
36 0xfffe0101, /* vs_1_1 */
37 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position0 v0 */
38 0x00000009, 0xc0010000, 0x90e40000, 0xa0e40000, /* dp4 oPos.x, v0, c0 */
39 0x00000009, 0xc0020000, 0x90e40000, 0xa0e40001, /* dp4 oPos.y, v0, c1 */
40 0x00000009, 0xc0040000, 0x90e40000, 0xa0e40002, /* dp4 oPos.z, v0, c2 */
41 0x00000009, 0xc0080000, 0x90e40000, 0xa0e40003, /* dp4 oPos.w, v0, c3 */
45 static const DWORD simple_ps
[] =
47 0xffff0101, /* ps_1_1 */
48 0x00000051, 0xa00f0001, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
49 0x00000042, 0xb00f0000, /* tex t0 */
50 0x00000008, 0x800f0000, 0xa0e40001, 0xa0e40000, /* dp3 r0, c1, c0 */
51 0x00000005, 0x800f0000, 0x90e40000, 0x80e40000, /* mul r0, v0, r0 */
52 0x00000005, 0x800f0000, 0xb0e40000, 0x80e40000, /* mul r0, t0, r0 */
56 static int get_refcount(IUnknown
*object
)
58 IUnknown_AddRef( object
);
59 return IUnknown_Release( object
);
62 /* try to make sure pending X events have been processed before continuing */
63 static void flush_events(void)
67 int min_timeout
= 100;
68 DWORD time
= GetTickCount() + diff
;
72 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
73 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
74 diff
= time
- GetTickCount();
78 static IDirect3DDevice9
*create_device(IDirect3D9
*d3d9
, HWND device_window
, HWND focus_window
, BOOL windowed
)
80 D3DPRESENT_PARAMETERS present_parameters
= {0};
81 IDirect3DDevice9
*device
;
83 present_parameters
.Windowed
= windowed
;
84 present_parameters
.hDeviceWindow
= device_window
;
85 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
86 present_parameters
.BackBufferWidth
= screen_width
;
87 present_parameters
.BackBufferHeight
= screen_height
;
88 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
89 present_parameters
.EnableAutoDepthStencil
= TRUE
;
90 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
92 if (SUCCEEDED(IDirect3D9_CreateDevice(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, focus_window
,
93 D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device
))) return device
;
95 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D16
;
96 if (SUCCEEDED(IDirect3D9_CreateDevice(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, focus_window
,
97 D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device
))) return device
;
99 if (SUCCEEDED(IDirect3D9_CreateDevice(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, focus_window
,
100 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
))) return device
;
105 static HRESULT
reset_device(IDirect3DDevice9
*device
, HWND device_window
, BOOL windowed
)
107 D3DPRESENT_PARAMETERS present_parameters
= {0};
109 present_parameters
.Windowed
= windowed
;
110 present_parameters
.hDeviceWindow
= device_window
;
111 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
112 present_parameters
.BackBufferWidth
= screen_width
;
113 present_parameters
.BackBufferHeight
= screen_height
;
114 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
115 present_parameters
.EnableAutoDepthStencil
= TRUE
;
116 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
118 return IDirect3DDevice9_Reset(device
, &present_parameters
);
121 #define CHECK_CALL(r,c,d,rc) \
123 int tmp1 = get_refcount( (IUnknown *)d ); \
125 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
127 trace("%s failed: %08x\n", c, r); \
130 #define CHECK_RELEASE(obj,d,rc) \
132 int tmp1, rc_new = rc; \
133 IUnknown_Release( (IUnknown*)obj ); \
134 tmp1 = get_refcount( (IUnknown *)d ); \
135 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
138 #define CHECK_REFCOUNT(obj,rc) \
141 int count = get_refcount( (IUnknown *)obj ); \
142 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
145 #define CHECK_RELEASE_REFCOUNT(obj,rc) \
148 int count = IUnknown_Release( (IUnknown *)obj ); \
149 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
152 #define CHECK_ADDREF_REFCOUNT(obj,rc) \
155 int count = IUnknown_AddRef( (IUnknown *)obj ); \
156 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
159 #define CHECK_SURFACE_CONTAINER(obj,iid,expected) \
161 void *container_ptr = (void *)0x1337c0d3; \
162 hr = IDirect3DSurface9_GetContainer(obj, &iid, &container_ptr); \
163 ok(SUCCEEDED(hr) && container_ptr == expected, "GetContainer returned: hr %#x, container_ptr %p. " \
164 "Expected hr %#x, container_ptr %p\n", hr, container_ptr, S_OK, expected); \
165 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr); \
168 static void check_mipmap_levels(IDirect3DDevice9
*device
, UINT width
, UINT height
, UINT count
)
170 IDirect3DBaseTexture9
* texture
= NULL
;
171 HRESULT hr
= IDirect3DDevice9_CreateTexture( device
, width
, height
, 0, 0,
172 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, (IDirect3DTexture9
**) &texture
, NULL
);
175 DWORD levels
= IDirect3DBaseTexture9_GetLevelCount(texture
);
176 ok(levels
== count
, "Invalid level count. Expected %d got %u\n", count
, levels
);
178 trace("CreateTexture failed: %08x\n", hr
);
180 if (texture
) IDirect3DBaseTexture9_Release( texture
);
183 static void test_mipmap_levels(void)
185 IDirect3DDevice9
*device
;
190 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
191 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
192 ok(!!window
, "Failed to create a window.\n");
193 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
194 ok(!!d3d
, "Failed to create a D3D object.\n");
195 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
197 skip("Failed to create a 3D device, skipping test.\n");
201 check_mipmap_levels(device
, 32, 32, 6);
202 check_mipmap_levels(device
, 256, 1, 9);
203 check_mipmap_levels(device
, 1, 256, 9);
204 check_mipmap_levels(device
, 1, 1, 1);
206 refcount
= IDirect3DDevice9_Release(device
);
207 ok(!refcount
, "Device has %u references left.\n", refcount
);
209 IDirect3D9_Release(d3d
);
210 DestroyWindow(window
);
213 static void test_checkdevicemultisampletype(void)
215 IDirect3DDevice9
*device
;
216 DWORD quality_levels
;
222 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
223 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
224 ok(!!window
, "Failed to create a window.\n");
225 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
226 ok(!!d3d
, "Failed to create a D3D object.\n");
227 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
229 skip("Failed to create a 3D device, skipping test.\n");
234 hr
= IDirect3D9_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
235 D3DFMT_X8R8G8B8
, TRUE
, D3DMULTISAMPLE_NONE
, &quality_levels
);
236 ok(SUCCEEDED(hr
) || hr
== D3DERR_NOTAVAILABLE
, "CheckDeviceMultiSampleType failed with (%08x)\n", hr
);
237 if (hr
== D3DERR_NOTAVAILABLE
)
239 skip("IDirect3D9_CheckDeviceMultiSampleType not available\n");
242 ok(quality_levels
== 1, "Got unexpected quality_levels %u.\n", quality_levels
);
244 hr
= IDirect3D9_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
245 D3DFMT_X8R8G8B8
, FALSE
, D3DMULTISAMPLE_NONE
, &quality_levels
);
246 ok(SUCCEEDED(hr
), "CheckDeviceMultiSampleType failed with (%08x)\n", hr
);
247 ok(quality_levels
== 1, "Got unexpected quality_levels %u.\n", quality_levels
);
252 refcount
= IDirect3DDevice9_Release(device
);
253 ok(!refcount
, "Device has %u references left.\n", refcount
);
255 IDirect3D9_Release(d3d
);
256 DestroyWindow(window
);
259 static void test_swapchain(void)
261 IDirect3DSwapChain9
*swapchain0
;
262 IDirect3DSwapChain9
*swapchain1
;
263 IDirect3DSwapChain9
*swapchain2
;
264 IDirect3DSwapChain9
*swapchain3
;
265 IDirect3DSwapChain9
*swapchainX
;
266 IDirect3DSurface9
*backbuffer
;
267 D3DPRESENT_PARAMETERS d3dpp
;
268 IDirect3DDevice9
*device
;
274 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
275 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
276 ok(!!window
, "Failed to create a window.\n");
277 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
278 ok(!!d3d
, "Failed to create a D3D object.\n");
279 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
281 skip("Failed to create a 3D device, skipping test.\n");
285 /* Get the implicit swapchain */
286 hr
= IDirect3DDevice9_GetSwapChain(device
, 0, &swapchain0
);
287 ok(SUCCEEDED(hr
), "Failed to get the implicit swapchain (%08x)\n", hr
);
288 /* Check if the back buffer count was modified */
289 hr
= IDirect3DSwapChain9_GetPresentParameters(swapchain0
, &d3dpp
);
290 ok(d3dpp
.BackBufferCount
== 1, "Got unexpected back buffer count %u.\n", d3dpp
.BackBufferCount
);
291 IDirect3DSwapChain9_Release(swapchain0
);
293 /* Check if there is a back buffer */
294 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain0
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
295 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
296 ok(backbuffer
!= NULL
, "The back buffer is NULL\n");
297 if(backbuffer
) IDirect3DSurface9_Release(backbuffer
);
299 /* Try to get a nonexistent swapchain */
300 hr
= IDirect3DDevice9_GetSwapChain(device
, 1, &swapchainX
);
301 ok(hr
== D3DERR_INVALIDCALL
, "GetSwapChain on an nonexistent swapchain returned (%08x)\n", hr
);
302 ok(swapchainX
== NULL
, "Swapchain 1 is %p\n", swapchainX
);
303 if(swapchainX
) IDirect3DSwapChain9_Release(swapchainX
);
305 /* Create a bunch of swapchains */
306 d3dpp
.BackBufferCount
= 0;
307 hr
= IDirect3DDevice9_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain1
);
308 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%08x)\n", hr
);
309 ok(d3dpp
.BackBufferCount
== 1, "The back buffer count in the presentparams struct is %d\n", d3dpp
.BackBufferCount
);
311 d3dpp
.BackBufferCount
= 1;
312 hr
= IDirect3DDevice9_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain2
);
313 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%08x)\n", hr
);
315 d3dpp
.BackBufferCount
= 2;
316 hr
= IDirect3DDevice9_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain3
);
317 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%08x)\n", hr
);
319 /* Swapchain 3, created with backbuffercount 2 */
320 backbuffer
= (void *) 0xdeadbeef;
321 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain3
, 0, 0, &backbuffer
);
322 ok(SUCCEEDED(hr
), "Failed to get the 1st back buffer (%08x)\n", hr
);
323 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
324 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
326 backbuffer
= (void *) 0xdeadbeef;
327 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain3
, 1, 0, &backbuffer
);
328 ok(SUCCEEDED(hr
), "Failed to get the 2nd back buffer (%08x)\n", hr
);
329 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
330 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
332 backbuffer
= (void *) 0xdeadbeef;
333 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain3
, 2, 0, &backbuffer
);
334 ok(hr
== D3DERR_INVALIDCALL
, "GetBackBuffer returned %08x\n", hr
);
335 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
336 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
338 backbuffer
= (void *) 0xdeadbeef;
339 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain3
, 3, 0, &backbuffer
);
340 ok(FAILED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
341 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
342 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
345 /* Check the back buffers of the swapchains */
346 /* Swapchain 1, created with backbuffercount 0 */
347 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain1
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
348 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
349 ok(backbuffer
!= NULL
, "The back buffer is NULL (%08x)\n", hr
);
350 if(backbuffer
) IDirect3DSurface9_Release(backbuffer
);
352 backbuffer
= (void *) 0xdeadbeef;
353 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain1
, 1, 0, &backbuffer
);
354 ok(FAILED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
355 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
356 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
358 /* Swapchain 2 - created with backbuffercount 1 */
359 backbuffer
= (void *) 0xdeadbeef;
360 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain2
, 0, 0, &backbuffer
);
361 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
362 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
363 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
365 backbuffer
= (void *) 0xdeadbeef;
366 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain2
, 1, 0, &backbuffer
);
367 ok(hr
== D3DERR_INVALIDCALL
, "GetBackBuffer returned %08x\n", hr
);
368 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
369 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
371 backbuffer
= (void *) 0xdeadbeef;
372 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain2
, 2, 0, &backbuffer
);
373 ok(FAILED(hr
), "Failed to get the back buffer (%08x)\n", hr
);
374 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
375 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer
);
377 /* Try getSwapChain on a manually created swapchain
378 * it should fail, apparently GetSwapChain only returns implicit swapchains
380 swapchainX
= (void *) 0xdeadbeef;
381 hr
= IDirect3DDevice9_GetSwapChain(device
, 1, &swapchainX
);
382 ok(hr
== D3DERR_INVALIDCALL
, "Failed to get the second swapchain (%08x)\n", hr
);
383 ok(swapchainX
== NULL
, "The swapchain pointer is %p\n", swapchainX
);
384 if(swapchainX
&& swapchainX
!= (void *) 0xdeadbeef ) IDirect3DSwapChain9_Release(swapchainX
);
386 IDirect3DSwapChain9_Release(swapchain3
);
387 IDirect3DSwapChain9_Release(swapchain2
);
388 IDirect3DSwapChain9_Release(swapchain1
);
389 refcount
= IDirect3DDevice9_Release(device
);
390 ok(!refcount
, "Device has %u references left.\n", refcount
);
392 IDirect3D9_Release(d3d
);
393 DestroyWindow(window
);
396 static void test_refcount(void)
398 IDirect3DVertexBuffer9
*pVertexBuffer
= NULL
;
399 IDirect3DIndexBuffer9
*pIndexBuffer
= NULL
;
400 IDirect3DVertexDeclaration9
*pVertexDeclaration
= NULL
;
401 IDirect3DVertexShader9
*pVertexShader
= NULL
;
402 IDirect3DPixelShader9
*pPixelShader
= NULL
;
403 IDirect3DCubeTexture9
*pCubeTexture
= NULL
;
404 IDirect3DTexture9
*pTexture
= NULL
;
405 IDirect3DVolumeTexture9
*pVolumeTexture
= NULL
;
406 IDirect3DVolume9
*pVolumeLevel
= NULL
;
407 IDirect3DSurface9
*pStencilSurface
= NULL
;
408 IDirect3DSurface9
*pOffscreenSurface
= NULL
;
409 IDirect3DSurface9
*pRenderTarget
= NULL
;
410 IDirect3DSurface9
*pRenderTarget2
= NULL
;
411 IDirect3DSurface9
*pRenderTarget3
= NULL
;
412 IDirect3DSurface9
*pTextureLevel
= NULL
;
413 IDirect3DSurface9
*pBackBuffer
= NULL
;
414 IDirect3DStateBlock9
*pStateBlock
= NULL
;
415 IDirect3DStateBlock9
*pStateBlock1
= NULL
;
416 IDirect3DSwapChain9
*pSwapChain
= NULL
;
417 IDirect3DQuery9
*pQuery
= NULL
;
418 D3DPRESENT_PARAMETERS d3dpp
;
419 IDirect3DDevice9
*device
;
420 ULONG refcount
= 0, tmp
;
421 IDirect3D9
*d3d
, *d3d2
;
425 D3DVERTEXELEMENT9 decl
[] =
430 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
431 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
432 ok(!!window
, "Failed to create a window.\n");
433 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
434 ok(!!d3d
, "Failed to create a D3D object.\n");
436 CHECK_REFCOUNT(d3d
, 1);
438 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
440 skip("Failed to create a 3D device, skipping test.\n");
444 refcount
= get_refcount((IUnknown
*)device
);
445 ok(refcount
== 1, "Invalid device RefCount %d\n", refcount
);
447 CHECK_REFCOUNT(d3d
, 2);
449 hr
= IDirect3DDevice9_GetDirect3D(device
, &d3d2
);
450 CHECK_CALL(hr
, "GetDirect3D", device
, refcount
);
452 ok(d3d2
== d3d
, "Expected IDirect3D9 pointers to be equal.\n");
453 CHECK_REFCOUNT(d3d
, 3);
454 CHECK_RELEASE_REFCOUNT(d3d
, 2);
457 * Check refcount of implicit surfaces and implicit swapchain. Findings:
458 * - the container is the device OR swapchain
459 * - they hold a reference to the device
460 * - they are created with a refcount of 0 (Get/Release returns original refcount)
461 * - they are not freed if refcount reaches 0.
462 * - the refcount is not forwarded to the container.
464 hr
= IDirect3DDevice9_GetSwapChain(device
, 0, &pSwapChain
);
465 CHECK_CALL(hr
, "GetSwapChain", device
, ++refcount
);
468 CHECK_REFCOUNT( pSwapChain
, 1);
470 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &pRenderTarget
);
471 CHECK_CALL(hr
, "GetRenderTarget", device
, ++refcount
);
472 CHECK_REFCOUNT( pSwapChain
, 1);
475 CHECK_SURFACE_CONTAINER( pRenderTarget
, IID_IDirect3DSwapChain9
, pSwapChain
);
476 CHECK_REFCOUNT( pRenderTarget
, 1);
478 CHECK_ADDREF_REFCOUNT(pRenderTarget
, 2);
479 CHECK_REFCOUNT(device
, refcount
);
480 CHECK_RELEASE_REFCOUNT(pRenderTarget
, 1);
481 CHECK_REFCOUNT(device
, refcount
);
483 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &pRenderTarget
);
484 CHECK_CALL(hr
, "GetRenderTarget", device
, refcount
);
485 CHECK_REFCOUNT( pRenderTarget
, 2);
486 CHECK_RELEASE_REFCOUNT( pRenderTarget
, 1);
487 CHECK_RELEASE_REFCOUNT( pRenderTarget
, 0);
488 CHECK_REFCOUNT(device
, --refcount
);
490 /* The render target is released with the device, so AddRef with refcount=0 is fine here. */
491 CHECK_ADDREF_REFCOUNT(pRenderTarget
, 1);
492 CHECK_REFCOUNT(device
, ++refcount
);
493 CHECK_RELEASE_REFCOUNT(pRenderTarget
, 0);
494 CHECK_REFCOUNT(device
, --refcount
);
497 /* Render target and back buffer are identical. */
498 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, 0, &pBackBuffer
);
499 CHECK_CALL(hr
, "GetBackBuffer", device
, ++refcount
);
502 CHECK_RELEASE_REFCOUNT(pBackBuffer
, 0);
503 ok(pRenderTarget
== pBackBuffer
, "RenderTarget=%p and BackBuffer=%p should be the same.\n",
504 pRenderTarget
, pBackBuffer
);
507 CHECK_REFCOUNT(device
, --refcount
);
509 hr
= IDirect3DDevice9_GetDepthStencilSurface(device
, &pStencilSurface
);
510 CHECK_CALL(hr
, "GetDepthStencilSurface", device
, ++refcount
);
511 CHECK_REFCOUNT( pSwapChain
, 1);
514 CHECK_SURFACE_CONTAINER(pStencilSurface
, IID_IDirect3DDevice9
, device
);
515 CHECK_REFCOUNT( pStencilSurface
, 1);
517 CHECK_ADDREF_REFCOUNT(pStencilSurface
, 2);
518 CHECK_REFCOUNT(device
, refcount
);
519 CHECK_RELEASE_REFCOUNT(pStencilSurface
, 1);
520 CHECK_REFCOUNT(device
, refcount
);
522 CHECK_RELEASE_REFCOUNT( pStencilSurface
, 0);
523 CHECK_REFCOUNT(device
, --refcount
);
525 /* The stencil surface is released with the device, so AddRef with refcount=0 is fine here. */
526 CHECK_ADDREF_REFCOUNT(pStencilSurface
, 1);
527 CHECK_REFCOUNT(device
, ++refcount
);
528 CHECK_RELEASE_REFCOUNT(pStencilSurface
, 0);
529 CHECK_REFCOUNT(device
, --refcount
);
530 pStencilSurface
= NULL
;
533 CHECK_RELEASE_REFCOUNT( pSwapChain
, 0);
534 CHECK_REFCOUNT(device
, --refcount
);
536 /* The implicit swapchwin is released with the device, so AddRef with refcount=0 is fine here. */
537 CHECK_ADDREF_REFCOUNT(pSwapChain
, 1);
538 CHECK_REFCOUNT(device
, ++refcount
);
539 CHECK_RELEASE_REFCOUNT(pSwapChain
, 0);
540 CHECK_REFCOUNT(device
, --refcount
);
545 hr
= IDirect3DDevice9_CreateIndexBuffer(device
, 16, 0, D3DFMT_INDEX32
, D3DPOOL_DEFAULT
, &pIndexBuffer
, NULL
);
546 CHECK_CALL(hr
, "CreateIndexBuffer", device
, ++refcount
);
549 tmp
= get_refcount( (IUnknown
*)pIndexBuffer
);
551 hr
= IDirect3DDevice9_SetIndices(device
, pIndexBuffer
);
552 CHECK_CALL( hr
, "SetIndices", pIndexBuffer
, tmp
);
553 hr
= IDirect3DDevice9_SetIndices(device
, NULL
);
554 CHECK_CALL( hr
, "SetIndices", pIndexBuffer
, tmp
);
557 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, 16, 0, D3DFVF_XYZ
, D3DPOOL_DEFAULT
, &pVertexBuffer
, NULL
);
558 CHECK_CALL(hr
, "CreateVertexBuffer", device
, ++refcount
);
561 IDirect3DVertexBuffer9
*pVBuf
= (void*)~0;
565 tmp
= get_refcount( (IUnknown
*)pVertexBuffer
);
567 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, pVertexBuffer
, 0, 3 * sizeof(float));
568 CHECK_CALL( hr
, "SetStreamSource", pVertexBuffer
, tmp
);
569 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 0, 0);
570 CHECK_CALL( hr
, "SetStreamSource", pVertexBuffer
, tmp
);
572 hr
= IDirect3DDevice9_GetStreamSource(device
, 0, &pVBuf
, &offset
, &stride
);
573 ok(SUCCEEDED(hr
), "GetStreamSource did not succeed with NULL stream!\n");
574 ok(pVBuf
==NULL
, "pVBuf not NULL (%p)!\n", pVBuf
);
575 ok(stride
==3*sizeof(float), "stride not 3 floats (got %u)!\n", stride
);
576 ok(offset
==0, "offset not 0 (got %u)!\n", offset
);
579 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl
, &pVertexDeclaration
);
580 CHECK_CALL(hr
, "CreateVertexDeclaration", device
, ++refcount
);
581 hr
= IDirect3DDevice9_CreateVertexShader(device
, simple_vs
, &pVertexShader
);
582 CHECK_CALL(hr
, "CreateVertexShader", device
, ++refcount
);
583 hr
= IDirect3DDevice9_CreatePixelShader(device
, simple_ps
, &pPixelShader
);
584 CHECK_CALL(hr
, "CreatePixelShader", device
, ++refcount
);
586 hr
= IDirect3DDevice9_CreateTexture(device
, 32, 32, 3, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pTexture
, NULL
);
587 CHECK_CALL(hr
, "CreateTexture", device
, ++refcount
);
590 tmp
= get_refcount( (IUnknown
*)pTexture
);
592 /* SetTexture should not increase refcounts */
593 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)pTexture
);
594 CHECK_CALL(hr
, "SetTexture", pTexture
, tmp
);
595 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
596 CHECK_CALL(hr
, "SetTexture", pTexture
, tmp
);
598 /* This should not increment device refcount */
599 hr
= IDirect3DTexture9_GetSurfaceLevel( pTexture
, 1, &pTextureLevel
);
600 CHECK_CALL(hr
, "GetSurfaceLevel", device
, refcount
);
601 /* But should increment texture's refcount */
602 CHECK_REFCOUNT( pTexture
, tmp
+1 );
603 /* Because the texture and surface refcount are identical */
606 CHECK_REFCOUNT ( pTextureLevel
, tmp
+1 );
607 CHECK_ADDREF_REFCOUNT ( pTextureLevel
, tmp
+2 );
608 CHECK_REFCOUNT ( pTexture
, tmp
+2 );
609 CHECK_RELEASE_REFCOUNT( pTextureLevel
, tmp
+1 );
610 CHECK_REFCOUNT ( pTexture
, tmp
+1 );
611 CHECK_RELEASE_REFCOUNT( pTexture
, tmp
);
612 CHECK_REFCOUNT ( pTextureLevel
, tmp
);
615 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 32, 0, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pCubeTexture
, NULL
);
616 CHECK_CALL(hr
, "CreateCubeTexture", device
, ++refcount
);
617 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 32, 32, 2, 0, 0,
618 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pVolumeTexture
, NULL
);
619 CHECK_CALL(hr
, "CreateVolumeTexture", device
, ++refcount
);
622 tmp
= get_refcount( (IUnknown
*)pVolumeTexture
);
624 /* This should not increment device refcount */
625 hr
= IDirect3DVolumeTexture9_GetVolumeLevel(pVolumeTexture
, 0, &pVolumeLevel
);
626 CHECK_CALL(hr
, "GetVolumeLevel", device
, refcount
);
627 /* But should increment volume texture's refcount */
628 CHECK_REFCOUNT( pVolumeTexture
, tmp
+1 );
629 /* Because the volume texture and volume refcount are identical */
632 CHECK_REFCOUNT ( pVolumeLevel
, tmp
+1 );
633 CHECK_ADDREF_REFCOUNT ( pVolumeLevel
, tmp
+2 );
634 CHECK_REFCOUNT ( pVolumeTexture
, tmp
+2 );
635 CHECK_RELEASE_REFCOUNT( pVolumeLevel
, tmp
+1 );
636 CHECK_REFCOUNT ( pVolumeTexture
, tmp
+1 );
637 CHECK_RELEASE_REFCOUNT( pVolumeTexture
, tmp
);
638 CHECK_REFCOUNT ( pVolumeLevel
, tmp
);
642 hr
= IDirect3DDevice9_CreateDepthStencilSurface(device
, 32, 32,
643 D3DFMT_D24S8
, D3DMULTISAMPLE_NONE
, 0, TRUE
, &pStencilSurface
, NULL
);
644 CHECK_CALL(hr
, "CreateDepthStencilSurface", device
, ++refcount
);
645 CHECK_REFCOUNT( pStencilSurface
, 1 );
646 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 32, 32,
647 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pOffscreenSurface
, NULL
);
648 CHECK_CALL(hr
, "CreateOffscreenPlainSurface", device
, ++refcount
);
649 CHECK_REFCOUNT( pOffscreenSurface
, 1 );
650 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 32, 32,
651 D3DFMT_X8R8G8B8
, D3DMULTISAMPLE_NONE
, 0, TRUE
, &pRenderTarget3
, NULL
);
652 CHECK_CALL(hr
, "CreateRenderTarget", device
, ++refcount
);
653 CHECK_REFCOUNT( pRenderTarget3
, 1 );
655 hr
= IDirect3DDevice9_CreateStateBlock(device
, D3DSBT_ALL
, &pStateBlock
);
656 CHECK_CALL(hr
, "CreateStateBlock", device
, ++refcount
);
658 memset(&d3dpp
, 0, sizeof(d3dpp
));
659 d3dpp
.Windowed
= TRUE
;
660 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
661 d3dpp
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
662 d3dpp
.EnableAutoDepthStencil
= TRUE
;
663 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
664 hr
= IDirect3DDevice9_CreateAdditionalSwapChain(device
, &d3dpp
, &pSwapChain
);
665 CHECK_CALL(hr
, "CreateAdditionalSwapChain", device
, ++refcount
);
668 /* check implicit back buffer */
669 hr
= IDirect3DSwapChain9_GetBackBuffer(pSwapChain
, 0, 0, &pBackBuffer
);
670 CHECK_CALL(hr
, "GetBackBuffer", device
, ++refcount
);
671 CHECK_REFCOUNT( pSwapChain
, 1);
674 CHECK_SURFACE_CONTAINER( pBackBuffer
, IID_IDirect3DSwapChain9
, pSwapChain
);
675 CHECK_REFCOUNT( pBackBuffer
, 1);
676 CHECK_RELEASE_REFCOUNT( pBackBuffer
, 0);
677 CHECK_REFCOUNT(device
, --refcount
);
679 /* The back buffer is released with the swapchain, so AddRef with refcount=0 is fine here. */
680 CHECK_ADDREF_REFCOUNT(pBackBuffer
, 1);
681 CHECK_REFCOUNT(device
, ++refcount
);
682 CHECK_RELEASE_REFCOUNT(pBackBuffer
, 0);
683 CHECK_REFCOUNT(device
, --refcount
);
686 CHECK_REFCOUNT( pSwapChain
, 1);
688 hr
= IDirect3DDevice9_CreateQuery(device
, D3DQUERYTYPE_EVENT
, &pQuery
);
689 CHECK_CALL(hr
, "CreateQuery", device
, ++refcount
);
691 hr
= IDirect3DDevice9_BeginStateBlock(device
);
692 CHECK_CALL(hr
, "BeginStateBlock", device
, refcount
);
693 hr
= IDirect3DDevice9_EndStateBlock(device
, &pStateBlock1
);
694 CHECK_CALL(hr
, "EndStateBlock", device
, ++refcount
);
696 /* The implicit render target is not freed if refcount reaches 0.
697 * Otherwise GetRenderTarget would re-allocate it and the pointer would change.*/
698 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &pRenderTarget2
);
699 CHECK_CALL(hr
, "GetRenderTarget", device
, ++refcount
);
702 CHECK_RELEASE_REFCOUNT(pRenderTarget2
, 0);
703 ok(pRenderTarget
== pRenderTarget2
, "RenderTarget=%p and RenderTarget2=%p should be the same.\n",
704 pRenderTarget
, pRenderTarget2
);
705 CHECK_REFCOUNT(device
, --refcount
);
706 pRenderTarget2
= NULL
;
708 pRenderTarget
= NULL
;
711 CHECK_RELEASE(device
, device
, --refcount
);
714 CHECK_RELEASE(pVertexBuffer
, device
, --refcount
);
715 CHECK_RELEASE(pIndexBuffer
, device
, --refcount
);
717 CHECK_RELEASE(pVertexDeclaration
, device
, --refcount
);
718 CHECK_RELEASE(pVertexShader
, device
, --refcount
);
719 CHECK_RELEASE(pPixelShader
, device
, --refcount
);
721 CHECK_RELEASE(pTextureLevel
, device
, --refcount
);
722 CHECK_RELEASE(pCubeTexture
, device
, --refcount
);
723 CHECK_RELEASE(pVolumeTexture
, device
, --refcount
);
725 CHECK_RELEASE(pStencilSurface
, device
, --refcount
);
726 CHECK_RELEASE(pOffscreenSurface
, device
, --refcount
);
727 CHECK_RELEASE(pRenderTarget3
, device
, --refcount
);
729 CHECK_RELEASE(pStateBlock
, device
, --refcount
);
730 CHECK_RELEASE(pSwapChain
, device
, --refcount
);
731 CHECK_RELEASE(pQuery
, device
, --refcount
);
732 /* This will destroy device - cannot check the refcount here */
733 if (pStateBlock1
) CHECK_RELEASE_REFCOUNT( pStateBlock1
, 0);
734 CHECK_RELEASE_REFCOUNT(d3d
, 0);
735 DestroyWindow(window
);
738 static void test_cursor(void)
740 IDirect3DSurface9
*cursor
= NULL
;
741 IDirect3DDevice9
*device
;
749 memset(&info
, 0, sizeof(info
));
750 info
.cbSize
= sizeof(info
);
751 ok(GetCursorInfo(&info
), "GetCursorInfo failed\n");
754 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
755 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
756 ok(!!window
, "Failed to create a window.\n");
757 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
758 ok(!!d3d
, "Failed to create a D3D object.\n");
759 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
761 skip("Failed to create a 3D device, skipping test.\n");
765 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 32, 32,
766 D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &cursor
, NULL
);
767 ok(SUCCEEDED(hr
), "Failed to create cursor surface, hr %#x.\n", hr
);
769 /* Initially hidden */
770 hr
= IDirect3DDevice9_ShowCursor(device
, TRUE
);
771 ok(hr
== FALSE
, "IDirect3DDevice9_ShowCursor returned %08x\n", hr
);
773 /* Not enabled without a surface*/
774 hr
= IDirect3DDevice9_ShowCursor(device
, TRUE
);
775 ok(hr
== FALSE
, "IDirect3DDevice9_ShowCursor returned %08x\n", hr
);
778 hr
= IDirect3DDevice9_SetCursorProperties(device
, 0, 0, NULL
);
779 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_SetCursorProperties returned %08x\n", hr
);
781 hr
= IDirect3DDevice9_SetCursorProperties(device
, 0, 0, cursor
);
782 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetCursorProperties returned %08x\n", hr
);
784 IDirect3DSurface9_Release(cursor
);
786 memset(&info
, 0, sizeof(info
));
787 info
.cbSize
= sizeof(info
);
788 ok(GetCursorInfo(&info
), "GetCursorInfo failed\n");
789 ok(info
.flags
& CURSOR_SHOWING
, "The gdi cursor is hidden (%08x)\n", info
.flags
);
790 ok(info
.hCursor
== cur
, "The cursor handle is %p\n", info
.hCursor
); /* unchanged */
793 hr
= IDirect3DDevice9_ShowCursor(device
, TRUE
);
794 ok(hr
== FALSE
, "IDirect3DDevice9_ShowCursor returned %08x\n", hr
);
797 hr
= IDirect3DDevice9_ShowCursor(device
, TRUE
);
798 ok(hr
== TRUE
, "IDirect3DDevice9_ShowCursor returned %08x\n", hr
);
800 /* GDI cursor unchanged */
801 memset(&info
, 0, sizeof(info
));
802 info
.cbSize
= sizeof(info
);
803 ok(GetCursorInfo(&info
), "GetCursorInfo failed\n");
804 ok(info
.flags
& CURSOR_SHOWING
, "The gdi cursor is hidden (%08x)\n", info
.flags
);
805 ok(info
.hCursor
== cur
, "The cursor handle is %p\n", info
.hCursor
); /* unchanged */
807 refcount
= IDirect3DDevice9_Release(device
);
808 ok(!refcount
, "Device has %u references left.\n", refcount
);
810 IDirect3D9_Release(d3d
);
811 DestroyWindow(window
);
814 static void test_reset(void)
818 D3DPRESENT_PARAMETERS d3dpp
;
819 D3DDISPLAYMODE d3ddm
, d3ddm2
;
821 DWORD width
, orig_width
= GetSystemMetrics(SM_CXSCREEN
);
822 DWORD height
, orig_height
= GetSystemMetrics(SM_CYSCREEN
);
823 IDirect3DSwapChain9
*pSwapchain
;
824 IDirect3DSurface9
*surface
;
825 IDirect3DTexture9
*texture
;
826 IDirect3DVertexShader9
*shader
;
827 UINT i
, adapter_mode_count
;
828 D3DLOCKED_RECT lockrect
;
829 IDirect3DDevice9
*device1
= NULL
;
830 IDirect3DDevice9
*device2
= NULL
;
842 hwnd
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
843 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
844 ok(!!hwnd
, "Failed to create a window.\n");
845 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
846 ok(!!d3d
, "Failed to create a D3D object.\n");
848 IDirect3D9_GetAdapterDisplayMode(d3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
849 adapter_mode_count
= IDirect3D9_GetAdapterModeCount(d3d
, D3DADAPTER_DEFAULT
, d3ddm
.Format
);
850 modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(*modes
) * adapter_mode_count
);
851 for(i
= 0; i
< adapter_mode_count
; ++i
)
854 ZeroMemory( &d3ddm2
, sizeof(d3ddm2
) );
855 hr
= IDirect3D9_EnumAdapterModes(d3d
, D3DADAPTER_DEFAULT
, d3ddm
.Format
, i
, &d3ddm2
);
856 ok(hr
== D3D_OK
, "IDirect3D9_EnumAdapterModes returned %#x\n", hr
);
858 for (j
= 0; j
< mode_count
; ++j
)
860 if (modes
[j
].w
== d3ddm2
.Width
&& modes
[j
].h
== d3ddm2
.Height
)
865 modes
[j
].w
= d3ddm2
.Width
;
866 modes
[j
].h
= d3ddm2
.Height
;
870 /* We use them as invalid modes */
871 if((d3ddm2
.Width
== 801 && d3ddm2
.Height
== 600) ||
872 (d3ddm2
.Width
== 32 && d3ddm2
.Height
== 32)) {
873 skip("This system supports a screen resolution of %dx%d, not running mode tests\n",
874 d3ddm2
.Width
, d3ddm2
.Height
);
881 skip("Less than 2 modes supported, skipping mode tests\n");
886 if (modes
[i
].w
== orig_width
&& modes
[i
].h
== orig_height
) ++i
;
888 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
889 d3dpp
.Windowed
= FALSE
;
890 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
891 d3dpp
.BackBufferWidth
= modes
[i
].w
;
892 d3dpp
.BackBufferHeight
= modes
[i
].h
;
893 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
894 d3dpp
.EnableAutoDepthStencil
= TRUE
;
895 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
897 hr
= IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
898 hwnd
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &device1
);
901 skip("could not create device, IDirect3D9_CreateDevice returned %#x\n", hr
);
904 hr
= IDirect3DDevice9_TestCooperativeLevel(device1
);
905 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after creation returned %#x\n", hr
);
907 hr
= IDirect3DDevice9_GetDeviceCaps(device1
, &caps
);
908 ok(SUCCEEDED(hr
), "GetDeviceCaps failed, hr %#x.\n", hr
);
910 width
= GetSystemMetrics(SM_CXSCREEN
);
911 height
= GetSystemMetrics(SM_CYSCREEN
);
912 ok(width
== modes
[i
].w
, "Screen width is %u, expected %u\n", width
, modes
[i
].w
);
913 ok(height
== modes
[i
].h
, "Screen height is %u, expected %u\n", height
, modes
[i
].h
);
915 hr
= IDirect3DDevice9_GetViewport(device1
, &vp
);
916 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetViewport failed with %08x\n", hr
);
919 ok(vp
.X
== 0, "D3DVIEWPORT->X = %d\n", vp
.X
);
920 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %d\n", vp
.Y
);
921 ok(vp
.Width
== modes
[i
].w
, "D3DVIEWPORT->Width = %u, expected %u\n", vp
.Width
, modes
[i
].w
);
922 ok(vp
.Height
== modes
[i
].h
, "D3DVIEWPORT->Height = %u, expected %u\n", vp
.Height
, modes
[i
].h
);
923 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %f\n", vp
.MinZ
);
924 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %f\n", vp
.MaxZ
);
932 hr
= IDirect3DDevice9_SetViewport(device1
, &vp
);
933 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetViewport failed with %08x\n", hr
);
935 hr
= IDirect3DDevice9_GetRenderState(device1
, D3DRS_LIGHTING
, &value
);
936 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
937 ok(!!value
, "Got unexpected value %#x for D3DRS_LIGHTING.\n", value
);
938 hr
= IDirect3DDevice9_SetRenderState(device1
, D3DRS_LIGHTING
, FALSE
);
939 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
941 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
942 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
943 d3dpp
.Windowed
= FALSE
;
944 d3dpp
.BackBufferWidth
= modes
[i
].w
;
945 d3dpp
.BackBufferHeight
= modes
[i
].h
;
946 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
947 hr
= IDirect3DDevice9_Reset(device1
, &d3dpp
);
948 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
949 hr
= IDirect3DDevice9_TestCooperativeLevel(device1
);
950 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
952 hr
= IDirect3DDevice9_GetRenderState(device1
, D3DRS_LIGHTING
, &value
);
953 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
954 ok(!!value
, "Got unexpected value %#x for D3DRS_LIGHTING.\n", value
);
956 ZeroMemory(&vp
, sizeof(vp
));
957 hr
= IDirect3DDevice9_GetViewport(device1
, &vp
);
958 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetViewport failed with %08x\n", hr
);
961 ok(vp
.X
== 0, "D3DVIEWPORT->X = %d\n", vp
.X
);
962 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %d\n", vp
.Y
);
963 ok(vp
.Width
== modes
[i
].w
, "D3DVIEWPORT->Width = %u, expected %u\n", vp
.Width
, modes
[i
].w
);
964 ok(vp
.Height
== modes
[i
].h
, "D3DVIEWPORT->Height = %u, expected %u\n", vp
.Height
, modes
[i
].h
);
965 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %f\n", vp
.MinZ
);
966 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %f\n", vp
.MaxZ
);
969 width
= GetSystemMetrics(SM_CXSCREEN
);
970 height
= GetSystemMetrics(SM_CYSCREEN
);
971 ok(width
== modes
[i
].w
, "Screen width is %u, expected %u\n", width
, modes
[i
].w
);
972 ok(height
== modes
[i
].h
, "Screen height is %u, expected %u\n", height
, modes
[i
].h
);
974 hr
= IDirect3DDevice9_GetSwapChain(device1
, 0, &pSwapchain
);
975 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetSwapChain returned %08x\n", hr
);
978 ZeroMemory(&d3dpp
, sizeof(d3dpp
));
979 hr
= IDirect3DSwapChain9_GetPresentParameters(pSwapchain
, &d3dpp
);
980 ok(hr
== D3D_OK
, "IDirect3DSwapChain9_GetPresentParameters returned %08x\n", hr
);
983 ok(d3dpp
.BackBufferWidth
== modes
[i
].w
, "Back buffer width is %u, expected %u\n",
984 d3dpp
.BackBufferWidth
, modes
[i
].w
);
985 ok(d3dpp
.BackBufferHeight
== modes
[i
].h
, "Back buffer height is %u, expected %u\n",
986 d3dpp
.BackBufferHeight
, modes
[i
].h
);
988 IDirect3DSwapChain9_Release(pSwapchain
);
991 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
992 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
993 d3dpp
.Windowed
= TRUE
;
994 d3dpp
.BackBufferWidth
= 400;
995 d3dpp
.BackBufferHeight
= 300;
996 hr
= IDirect3DDevice9_Reset(device1
, &d3dpp
);
997 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
998 hr
= IDirect3DDevice9_TestCooperativeLevel(device1
);
999 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
1001 width
= GetSystemMetrics(SM_CXSCREEN
);
1002 height
= GetSystemMetrics(SM_CYSCREEN
);
1003 ok(width
== orig_width
, "Screen width is %d\n", width
);
1004 ok(height
== orig_height
, "Screen height is %d\n", height
);
1006 ZeroMemory(&vp
, sizeof(vp
));
1007 hr
= IDirect3DDevice9_GetViewport(device1
, &vp
);
1008 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetViewport failed with %08x\n", hr
);
1011 ok(vp
.X
== 0, "D3DVIEWPORT->X = %d\n", vp
.X
);
1012 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %d\n", vp
.Y
);
1013 ok(vp
.Width
== 400, "D3DVIEWPORT->Width = %d\n", vp
.Width
);
1014 ok(vp
.Height
== 300, "D3DVIEWPORT->Height = %d\n", vp
.Height
);
1015 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %f\n", vp
.MinZ
);
1016 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %f\n", vp
.MaxZ
);
1019 hr
= IDirect3DDevice9_GetSwapChain(device1
, 0, &pSwapchain
);
1020 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetSwapChain returned %08x\n", hr
);
1023 ZeroMemory(&d3dpp
, sizeof(d3dpp
));
1024 hr
= IDirect3DSwapChain9_GetPresentParameters(pSwapchain
, &d3dpp
);
1025 ok(hr
== D3D_OK
, "IDirect3DSwapChain9_GetPresentParameters returned %08x\n", hr
);
1028 ok(d3dpp
.BackBufferWidth
== 400, "Back buffer width is %d\n", d3dpp
.BackBufferWidth
);
1029 ok(d3dpp
.BackBufferHeight
== 300, "Back buffer height is %d\n", d3dpp
.BackBufferHeight
);
1031 IDirect3DSwapChain9_Release(pSwapchain
);
1036 winrect
.right
= 200;
1037 winrect
.bottom
= 150;
1038 ok(AdjustWindowRect(&winrect
, WS_OVERLAPPEDWINDOW
, FALSE
), "AdjustWindowRect failed\n");
1039 ok(SetWindowPos(hwnd
, NULL
, 0, 0,
1040 winrect
.right
-winrect
.left
,
1041 winrect
.bottom
-winrect
.top
,
1042 SWP_NOMOVE
|SWP_NOZORDER
),
1043 "SetWindowPos failed\n");
1045 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1046 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1047 d3dpp
.Windowed
= TRUE
;
1048 d3dpp
.BackBufferWidth
= 0;
1049 d3dpp
.BackBufferHeight
= 0;
1050 hr
= IDirect3DDevice9_Reset(device1
, &d3dpp
);
1051 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1052 hr
= IDirect3DDevice9_TestCooperativeLevel(device1
);
1053 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
1055 ZeroMemory(&vp
, sizeof(vp
));
1056 hr
= IDirect3DDevice9_GetViewport(device1
, &vp
);
1057 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetViewport failed with %08x\n", hr
);
1060 ok(vp
.X
== 0, "D3DVIEWPORT->X = %d\n", vp
.X
);
1061 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %d\n", vp
.Y
);
1062 ok(vp
.Width
== 200, "D3DVIEWPORT->Width = %d\n", vp
.Width
);
1063 ok(vp
.Height
== 150, "D3DVIEWPORT->Height = %d\n", vp
.Height
);
1064 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %f\n", vp
.MinZ
);
1065 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %f\n", vp
.MaxZ
);
1068 hr
= IDirect3DDevice9_GetSwapChain(device1
, 0, &pSwapchain
);
1069 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetSwapChain returned %08x\n", hr
);
1072 ZeroMemory(&d3dpp
, sizeof(d3dpp
));
1073 hr
= IDirect3DSwapChain9_GetPresentParameters(pSwapchain
, &d3dpp
);
1074 ok(hr
== D3D_OK
, "IDirect3DSwapChain9_GetPresentParameters returned %08x\n", hr
);
1077 ok(d3dpp
.BackBufferWidth
== 200, "Back buffer width is %d\n", d3dpp
.BackBufferWidth
);
1078 ok(d3dpp
.BackBufferHeight
== 150, "Back buffer height is %d\n", d3dpp
.BackBufferHeight
);
1080 IDirect3DSwapChain9_Release(pSwapchain
);
1083 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1084 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1085 d3dpp
.Windowed
= TRUE
;
1086 d3dpp
.BackBufferWidth
= 400;
1087 d3dpp
.BackBufferHeight
= 300;
1089 /* _Reset fails if there is a resource in the default pool */
1090 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device1
, 16, 16, D3DFMT_R5G6B5
, D3DPOOL_DEFAULT
, &surface
, NULL
);
1091 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr
);
1092 hr
= IDirect3DDevice9_Reset(device1
, &d3dpp
);
1093 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1094 hr
= IDirect3DDevice9_TestCooperativeLevel(device1
);
1095 ok(hr
== D3DERR_DEVICENOTRESET
, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr
);
1096 IDirect3DSurface9_Release(surface
);
1097 /* Reset again to get the device out of the lost state */
1098 hr
= IDirect3DDevice9_Reset(device1
, &d3dpp
);
1099 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1100 hr
= IDirect3DDevice9_TestCooperativeLevel(device1
);
1101 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
1103 if (caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
)
1105 IDirect3DVolumeTexture9
*volume_texture
;
1107 hr
= IDirect3DDevice9_CreateVolumeTexture(device1
, 16, 16, 4, 1, 0,
1108 D3DFMT_R5G6B5
, D3DPOOL_DEFAULT
, &volume_texture
, NULL
);
1109 ok(SUCCEEDED(hr
), "CreateVolumeTexture failed, hr %#x.\n", hr
);
1110 hr
= IDirect3DDevice9_Reset(device1
, &d3dpp
);
1111 ok(hr
== D3DERR_INVALIDCALL
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
1112 hr
= IDirect3DDevice9_TestCooperativeLevel(device1
);
1113 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n",
1114 hr
, D3DERR_DEVICENOTRESET
);
1115 IDirect3DVolumeTexture9_Release(volume_texture
);
1116 hr
= IDirect3DDevice9_Reset(device1
, &d3dpp
);
1117 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1118 hr
= IDirect3DDevice9_TestCooperativeLevel(device1
);
1119 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1123 skip("Volume textures not supported.\n");
1126 /* Scratch, sysmem and managed pools are fine */
1127 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device1
, 16, 16, D3DFMT_R5G6B5
, D3DPOOL_SCRATCH
, &surface
, NULL
);
1128 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr
);
1129 hr
= IDirect3DDevice9_Reset(device1
, &d3dpp
);
1130 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1131 hr
= IDirect3DDevice9_TestCooperativeLevel(device1
);
1132 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
1133 IDirect3DSurface9_Release(surface
);
1135 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device1
, 16, 16,
1136 D3DFMT_R5G6B5
, D3DPOOL_SYSTEMMEM
, &surface
, NULL
);
1137 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr
);
1138 hr
= IDirect3DDevice9_Reset(device1
, &d3dpp
);
1139 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1140 hr
= IDirect3DDevice9_TestCooperativeLevel(device1
);
1141 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
1142 IDirect3DSurface9_Release(surface
);
1144 /* The depth stencil should get reset to the auto depth stencil when present. */
1145 hr
= IDirect3DDevice9_SetDepthStencilSurface(device1
, NULL
);
1146 ok(hr
== D3D_OK
, "SetDepthStencilSurface failed with 0x%08x\n", hr
);
1148 hr
= IDirect3DDevice9_GetDepthStencilSurface(device1
, &surface
);
1149 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr
);
1150 ok(surface
== NULL
, "Depth stencil should be NULL\n");
1152 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1153 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1154 hr
= IDirect3DDevice9_Reset(device1
, &d3dpp
);
1155 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with 0x%08x\n", hr
);
1157 hr
= IDirect3DDevice9_GetDepthStencilSurface(device1
, &surface
);
1158 ok(hr
== D3D_OK
, "GetDepthStencilSurface failed with 0x%08x\n", hr
);
1159 ok(surface
!= NULL
, "Depth stencil should not be NULL\n");
1160 if (surface
) IDirect3DSurface9_Release(surface
);
1162 d3dpp
.EnableAutoDepthStencil
= FALSE
;
1163 hr
= IDirect3DDevice9_Reset(device1
, &d3dpp
);
1164 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with 0x%08x\n", hr
);
1166 hr
= IDirect3DDevice9_GetDepthStencilSurface(device1
, &surface
);
1167 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr
);
1168 ok(surface
== NULL
, "Depth stencil should be NULL\n");
1170 /* Will a sysmem or scratch survive while locked */
1171 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device1
, 16, 16,
1172 D3DFMT_R5G6B5
, D3DPOOL_SYSTEMMEM
, &surface
, NULL
);
1173 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr
);
1174 hr
= IDirect3DSurface9_LockRect(surface
, &lockrect
, NULL
, D3DLOCK_DISCARD
);
1175 ok(hr
== D3D_OK
, "IDirect3DSurface9_LockRect returned %08x\n", hr
);
1176 hr
= IDirect3DDevice9_Reset(device1
, &d3dpp
);
1177 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1178 hr
= IDirect3DDevice9_TestCooperativeLevel(device1
);
1179 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
1180 IDirect3DSurface9_UnlockRect(surface
);
1181 IDirect3DSurface9_Release(surface
);
1183 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device1
, 16, 16, D3DFMT_R5G6B5
, D3DPOOL_SCRATCH
, &surface
, NULL
);
1184 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr
);
1185 hr
= IDirect3DSurface9_LockRect(surface
, &lockrect
, NULL
, D3DLOCK_DISCARD
);
1186 ok(hr
== D3D_OK
, "IDirect3DSurface9_LockRect returned %08x\n", hr
);
1187 hr
= IDirect3DDevice9_Reset(device1
, &d3dpp
);
1188 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1189 hr
= IDirect3DDevice9_TestCooperativeLevel(device1
);
1190 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
1191 IDirect3DSurface9_UnlockRect(surface
);
1192 IDirect3DSurface9_Release(surface
);
1194 hr
= IDirect3DDevice9_CreateTexture(device1
, 16, 16, 0, 0, D3DFMT_R5G6B5
, D3DPOOL_MANAGED
, &texture
, NULL
);
1195 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture returned %08x\n", hr
);
1196 hr
= IDirect3DDevice9_Reset(device1
, &d3dpp
);
1197 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1198 hr
= IDirect3DDevice9_TestCooperativeLevel(device1
);
1199 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
1200 IDirect3DTexture9_Release(texture
);
1202 /* A reference held to an implicit surface causes failures as well */
1203 hr
= IDirect3DDevice9_GetBackBuffer(device1
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &surface
);
1204 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetBackBuffer returned %08x\n", hr
);
1205 hr
= IDirect3DDevice9_Reset(device1
, &d3dpp
);
1206 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1207 hr
= IDirect3DDevice9_TestCooperativeLevel(device1
);
1208 ok(hr
== D3DERR_DEVICENOTRESET
, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr
);
1209 IDirect3DSurface9_Release(surface
);
1210 hr
= IDirect3DDevice9_Reset(device1
, &d3dpp
);
1211 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1212 hr
= IDirect3DDevice9_TestCooperativeLevel(device1
);
1213 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
1215 /* Shaders are fine as well */
1216 hr
= IDirect3DDevice9_CreateVertexShader(device1
, simple_vs
, &shader
);
1217 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr
);
1218 hr
= IDirect3DDevice9_Reset(device1
, &d3dpp
);
1219 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
1220 IDirect3DVertexShader9_Release(shader
);
1222 /* Try setting invalid modes */
1223 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1224 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1225 d3dpp
.Windowed
= FALSE
;
1226 d3dpp
.BackBufferWidth
= 32;
1227 d3dpp
.BackBufferHeight
= 32;
1228 hr
= IDirect3DDevice9_Reset(device1
, &d3dpp
);
1229 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Reset to w=32, h=32, windowed=FALSE failed with %08x\n", hr
);
1230 hr
= IDirect3DDevice9_TestCooperativeLevel(device1
);
1231 ok(hr
== D3DERR_DEVICENOTRESET
, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr
);
1233 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1234 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1235 d3dpp
.Windowed
= FALSE
;
1236 d3dpp
.BackBufferWidth
= 801;
1237 d3dpp
.BackBufferHeight
= 600;
1238 hr
= IDirect3DDevice9_Reset(device1
, &d3dpp
);
1239 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Reset to w=801, h=600, windowed=FALSE failed with %08x\n", hr
);
1240 hr
= IDirect3DDevice9_TestCooperativeLevel(device1
);
1241 ok(hr
== D3DERR_DEVICENOTRESET
, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr
);
1243 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1244 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1245 d3dpp
.Windowed
= FALSE
;
1246 d3dpp
.BackBufferWidth
= 0;
1247 d3dpp
.BackBufferHeight
= 0;
1248 hr
= IDirect3DDevice9_Reset(device1
, &d3dpp
);
1249 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Reset to w=0, h=0, windowed=FALSE failed with %08x\n", hr
);
1250 hr
= IDirect3DDevice9_TestCooperativeLevel(device1
);
1251 ok(hr
== D3DERR_DEVICENOTRESET
, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr
);
1253 IDirect3D9_GetAdapterDisplayMode(d3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
1255 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1256 d3dpp
.Windowed
= TRUE
;
1257 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1258 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1259 d3dpp
.EnableAutoDepthStencil
= FALSE
;
1260 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1262 if (FAILED(hr
= IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
1263 hwnd
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &device2
)))
1265 skip("could not create device, IDirect3D9_CreateDevice returned %#x\n", hr
);
1269 hr
= IDirect3DDevice9_TestCooperativeLevel(device2
);
1270 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after creation returned %#x\n", hr
);
1272 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1273 d3dpp
.Windowed
= TRUE
;
1274 d3dpp
.BackBufferWidth
= 400;
1275 d3dpp
.BackBufferHeight
= 300;
1276 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1277 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1279 hr
= IDirect3DDevice9_Reset(device2
, &d3dpp
);
1280 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with 0x%08x\n", hr
);
1282 if (FAILED(hr
)) goto cleanup
;
1284 hr
= IDirect3DDevice9_GetDepthStencilSurface(device2
, &surface
);
1285 ok(hr
== D3D_OK
, "GetDepthStencilSurface failed with 0x%08x\n", hr
);
1286 ok(surface
!= NULL
, "Depth stencil should not be NULL\n");
1287 if (surface
) IDirect3DSurface9_Release(surface
);
1290 HeapFree(GetProcessHeap(), 0, modes
);
1293 UINT refcount
= IDirect3DDevice9_Release(device2
);
1294 ok(!refcount
, "Device has %u references left.\n", refcount
);
1298 UINT refcount
= IDirect3DDevice9_Release(device1
);
1299 ok(!refcount
, "Device has %u references left.\n", refcount
);
1301 IDirect3D9_Release(d3d
);
1302 DestroyWindow(hwnd
);
1305 /* Test adapter display modes */
1306 static void test_display_modes(void)
1308 D3DDISPLAYMODE dmode
;
1311 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
1312 ok(!!d3d
, "Failed to create a D3D object.\n");
1314 #define TEST_FMT(x,r) do { \
1315 HRESULT res = IDirect3D9_EnumAdapterModes(d3d, 0, (x), 0, &dmode); \
1316 ok(res==(r), "EnumAdapterModes("#x") did not return "#r" (got %08x)!\n", res); \
1319 TEST_FMT(D3DFMT_R8G8B8
, D3DERR_INVALIDCALL
);
1320 TEST_FMT(D3DFMT_A8R8G8B8
, D3DERR_INVALIDCALL
);
1321 TEST_FMT(D3DFMT_X8B8G8R8
, D3DERR_INVALIDCALL
);
1323 TEST_FMT(D3DFMT_X1R5G5B5
, D3DERR_INVALIDCALL
);
1324 TEST_FMT(D3DFMT_A1R5G5B5
, D3DERR_INVALIDCALL
);
1325 TEST_FMT(D3DFMT_A4R4G4B4
, D3DERR_INVALIDCALL
);
1326 TEST_FMT(D3DFMT_R3G3B2
, D3DERR_INVALIDCALL
);
1327 TEST_FMT(D3DFMT_A8
, D3DERR_INVALIDCALL
);
1328 TEST_FMT(D3DFMT_A8R3G3B2
, D3DERR_INVALIDCALL
);
1329 TEST_FMT(D3DFMT_X4R4G4B4
, D3DERR_INVALIDCALL
);
1330 TEST_FMT(D3DFMT_A2B10G10R10
, D3DERR_INVALIDCALL
);
1331 TEST_FMT(D3DFMT_A8B8G8R8
, D3DERR_INVALIDCALL
);
1332 TEST_FMT(D3DFMT_X8B8G8R8
, D3DERR_INVALIDCALL
);
1333 TEST_FMT(D3DFMT_G16R16
, D3DERR_INVALIDCALL
);
1334 TEST_FMT(D3DFMT_A16B16G16R16
, D3DERR_INVALIDCALL
);
1336 TEST_FMT(D3DFMT_A8P8
, D3DERR_INVALIDCALL
);
1337 TEST_FMT(D3DFMT_P8
, D3DERR_INVALIDCALL
);
1339 TEST_FMT(D3DFMT_L8
, D3DERR_INVALIDCALL
);
1340 TEST_FMT(D3DFMT_A8L8
, D3DERR_INVALIDCALL
);
1341 TEST_FMT(D3DFMT_A4L4
, D3DERR_INVALIDCALL
);
1343 TEST_FMT(D3DFMT_V8U8
, D3DERR_INVALIDCALL
);
1344 TEST_FMT(D3DFMT_L6V5U5
, D3DERR_INVALIDCALL
);
1345 TEST_FMT(D3DFMT_X8L8V8U8
, D3DERR_INVALIDCALL
);
1346 TEST_FMT(D3DFMT_Q8W8V8U8
, D3DERR_INVALIDCALL
);
1347 TEST_FMT(D3DFMT_V16U16
, D3DERR_INVALIDCALL
);
1348 TEST_FMT(D3DFMT_A2W10V10U10
, D3DERR_INVALIDCALL
);
1350 TEST_FMT(D3DFMT_UYVY
, D3DERR_INVALIDCALL
);
1351 TEST_FMT(D3DFMT_YUY2
, D3DERR_INVALIDCALL
);
1352 TEST_FMT(D3DFMT_DXT1
, D3DERR_INVALIDCALL
);
1353 TEST_FMT(D3DFMT_DXT2
, D3DERR_INVALIDCALL
);
1354 TEST_FMT(D3DFMT_DXT3
, D3DERR_INVALIDCALL
);
1355 TEST_FMT(D3DFMT_DXT4
, D3DERR_INVALIDCALL
);
1356 TEST_FMT(D3DFMT_DXT5
, D3DERR_INVALIDCALL
);
1357 TEST_FMT(D3DFMT_MULTI2_ARGB8
, D3DERR_INVALIDCALL
);
1358 TEST_FMT(D3DFMT_G8R8_G8B8
, D3DERR_INVALIDCALL
);
1359 TEST_FMT(D3DFMT_R8G8_B8G8
, D3DERR_INVALIDCALL
);
1361 TEST_FMT(D3DFMT_D16_LOCKABLE
, D3DERR_INVALIDCALL
);
1362 TEST_FMT(D3DFMT_D32
, D3DERR_INVALIDCALL
);
1363 TEST_FMT(D3DFMT_D15S1
, D3DERR_INVALIDCALL
);
1364 TEST_FMT(D3DFMT_D24S8
, D3DERR_INVALIDCALL
);
1365 TEST_FMT(D3DFMT_D24X8
, D3DERR_INVALIDCALL
);
1366 TEST_FMT(D3DFMT_D24X4S4
, D3DERR_INVALIDCALL
);
1367 TEST_FMT(D3DFMT_D16
, D3DERR_INVALIDCALL
);
1368 TEST_FMT(D3DFMT_L16
, D3DERR_INVALIDCALL
);
1369 TEST_FMT(D3DFMT_D32F_LOCKABLE
, D3DERR_INVALIDCALL
);
1370 TEST_FMT(D3DFMT_D24FS8
, D3DERR_INVALIDCALL
);
1372 TEST_FMT(D3DFMT_VERTEXDATA
, D3DERR_INVALIDCALL
);
1373 TEST_FMT(D3DFMT_INDEX16
, D3DERR_INVALIDCALL
);
1374 TEST_FMT(D3DFMT_INDEX32
, D3DERR_INVALIDCALL
);
1375 TEST_FMT(D3DFMT_Q16W16V16U16
, D3DERR_INVALIDCALL
);
1376 /* Floating point formats */
1377 TEST_FMT(D3DFMT_R16F
, D3DERR_INVALIDCALL
);
1378 TEST_FMT(D3DFMT_G16R16F
, D3DERR_INVALIDCALL
);
1379 TEST_FMT(D3DFMT_A16B16G16R16F
, D3DERR_INVALIDCALL
);
1382 TEST_FMT(D3DFMT_R32F
, D3DERR_INVALIDCALL
);
1383 TEST_FMT(D3DFMT_G32R32F
, D3DERR_INVALIDCALL
);
1384 TEST_FMT(D3DFMT_A32B32G32R32F
, D3DERR_INVALIDCALL
);
1386 TEST_FMT(D3DFMT_CxV8U8
, D3DERR_INVALIDCALL
);
1388 TEST_FMT(0, D3DERR_INVALIDCALL
);
1390 IDirect3D9_Release(d3d
);
1393 static void test_scene(void)
1395 IDirect3DSurface9
*surface1
, *surface2
, *surface3
;
1396 IDirect3DSurface9
*backBuffer
, *rt
, *ds
;
1397 RECT rect
= {0, 0, 128, 128};
1398 IDirect3DDevice9
*device
;
1405 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
1406 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
1407 ok(!!window
, "Failed to create a window.\n");
1408 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
1409 ok(!!d3d
, "Failed to create a D3D object.\n");
1410 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
1412 skip("Failed to create a 3D device, skipping test.\n");
1416 /* Get the caps, they will be needed to tell if an operation is supposed to be valid */
1417 memset(&caps
, 0, sizeof(caps
));
1418 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
1419 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetCaps failed with %08x\n", hr
);
1421 /* Test an EndScene without BeginScene. Should return an error */
1422 hr
= IDirect3DDevice9_EndScene(device
);
1423 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_EndScene returned %08x\n", hr
);
1425 /* Test a normal BeginScene / EndScene pair, this should work */
1426 hr
= IDirect3DDevice9_BeginScene(device
);
1427 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %08x\n", hr
);
1428 hr
= IDirect3DDevice9_EndScene(device
);
1429 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %08x\n", hr
);
1431 /* Test another EndScene without having begun a new scene. Should return an error */
1432 hr
= IDirect3DDevice9_EndScene(device
);
1433 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_EndScene returned %08x\n", hr
);
1435 /* Two nested BeginScene and EndScene calls */
1436 hr
= IDirect3DDevice9_BeginScene(device
);
1437 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %08x\n", hr
);
1438 hr
= IDirect3DDevice9_BeginScene(device
);
1439 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_BeginScene returned %08x\n", hr
);
1440 hr
= IDirect3DDevice9_EndScene(device
);
1441 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %08x\n", hr
);
1442 hr
= IDirect3DDevice9_EndScene(device
);
1443 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_EndScene returned %08x\n", hr
);
1445 /* Create some surfaces to test stretchrect between the scenes */
1446 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 128, 128,
1447 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &surface1
, NULL
);
1448 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface failed with %08x\n", hr
);
1449 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 128, 128,
1450 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &surface2
, NULL
);
1451 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface failed with %08x\n", hr
);
1452 hr
= IDirect3DDevice9_CreateDepthStencilSurface(device
, 800, 600,
1453 D3DFMT_D16
, D3DMULTISAMPLE_NONE
, 0, FALSE
, &surface3
, NULL
);
1454 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateDepthStencilSurface failed with %08x\n", hr
);
1455 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 128, 128,
1456 D3DFMT_A8R8G8B8
, D3DMULTISAMPLE_NONE
, 0, FALSE
, &rt
, NULL
);
1457 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateRenderTarget failed with %08x\n", hr
);
1459 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &backBuffer
);
1460 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetBackBuffer failed with %08x\n", hr
);
1461 hr
= IDirect3DDevice9_GetDepthStencilSurface(device
, &ds
);
1462 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetBackBuffer failed with %08x\n", hr
);
1464 /* First make sure a simple StretchRect call works */
1465 hr
= IDirect3DDevice9_StretchRect(device
, surface1
, NULL
, surface2
, NULL
, 0);
1466 ok(hr
== D3D_OK
, "IDirect3DDevice9_StretchRect failed with %08x\n", hr
);
1467 hr
= IDirect3DDevice9_StretchRect(device
, backBuffer
, &rect
, rt
, NULL
, 0);
1468 ok(hr
== D3D_OK
, "IDirect3DDevice9_StretchRect failed with %08x\n", hr
);
1469 if (0) /* Disabled for now because it crashes in wine */
1471 HRESULT expected
= caps
.DevCaps2
& D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES
? D3D_OK
: D3DERR_INVALIDCALL
;
1472 hr
= IDirect3DDevice9_StretchRect(device
, ds
, NULL
, surface3
, NULL
, 0);
1473 ok(hr
== expected
, "Got unexpected hr %#x, expected %#x.\n", hr
, expected
);
1476 /* Now try it in a BeginScene - EndScene pair. Seems to be allowed in a
1477 * BeginScene - Endscene pair with normal surfaces and render targets, but
1478 * not depth stencil surfaces. */
1479 hr
= IDirect3DDevice9_BeginScene(device
);
1480 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %08x\n", hr
);
1482 hr
= IDirect3DDevice9_StretchRect(device
, surface1
, NULL
, surface2
, NULL
, 0);
1483 ok(hr
== D3D_OK
, "IDirect3DDevice9_StretchRect failed with %08x\n", hr
);
1484 hr
= IDirect3DDevice9_StretchRect(device
, backBuffer
, &rect
, rt
, NULL
, 0);
1485 ok(hr
== D3D_OK
, "IDirect3DDevice9_StretchRect failed with %08x\n", hr
);
1486 /* This is supposed to fail inside a BeginScene - EndScene pair. */
1487 hr
= IDirect3DDevice9_StretchRect(device
, ds
, NULL
, surface3
, NULL
, 0);
1488 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_StretchRect returned %08x, expected D3DERR_INVALIDCALL\n", hr
);
1490 hr
= IDirect3DDevice9_EndScene(device
);
1491 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %08x\n", hr
);
1493 /* Does a SetRenderTarget influence BeginScene / EndScene ?
1494 * Set a new render target, then see if it started a new scene. Flip the rt back and see if that maybe
1495 * ended the scene. Expected result is that the scene is not affected by SetRenderTarget
1497 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt
);
1498 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderTarget failed with %08x\n", hr
);
1499 hr
= IDirect3DDevice9_BeginScene(device
);
1500 ok( hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %08x\n", hr
);
1501 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backBuffer
);
1502 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderTarget failed with %08x\n", hr
);
1503 hr
= IDirect3DDevice9_EndScene(device
);
1504 ok( hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %08x\n", hr
);
1506 IDirect3DSurface9_Release(rt
);
1507 IDirect3DSurface9_Release(ds
);
1508 IDirect3DSurface9_Release(backBuffer
);
1509 IDirect3DSurface9_Release(surface1
);
1510 IDirect3DSurface9_Release(surface2
);
1511 IDirect3DSurface9_Release(surface3
);
1512 refcount
= IDirect3DDevice9_Release(device
);
1513 ok(!refcount
, "Device has %u references left.\n", refcount
);
1515 IDirect3D9_Release(d3d
);
1516 DestroyWindow(window
);
1519 static void test_limits(void)
1521 IDirect3DTexture9
*texture
;
1522 IDirect3DDevice9
*device
;
1529 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
1530 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
1531 ok(!!window
, "Failed to create a window.\n");
1532 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
1533 ok(!!d3d
, "Failed to create a D3D object.\n");
1534 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
1536 skip("Failed to create a 3D device, skipping test.\n");
1540 hr
= IDirect3DDevice9_CreateTexture(device
, 16, 16, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &texture
, NULL
);
1541 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture failed with %08x\n", hr
);
1543 /* There are 16 pixel samplers. We should be able to access all of them */
1544 for (i
= 0; i
< 16; ++i
)
1546 hr
= IDirect3DDevice9_SetTexture(device
, i
, (IDirect3DBaseTexture9
*)texture
);
1547 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture for sampler %d failed with %08x\n", i
, hr
);
1548 hr
= IDirect3DDevice9_SetTexture(device
, i
, NULL
);
1549 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture for sampler %d failed with %08x\n", i
, hr
);
1550 hr
= IDirect3DDevice9_SetSamplerState(device
, i
, D3DSAMP_SRGBTEXTURE
, TRUE
);
1551 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState for sampler %d failed with %08x\n", i
, hr
);
1554 /* Now test all 8 textures stage states */
1555 for (i
= 0; i
< 8; ++i
)
1557 hr
= IDirect3DDevice9_SetTextureStageState(device
, i
, D3DTSS_COLOROP
, D3DTOP_ADD
);
1558 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState for texture %d failed with %08x\n", i
, hr
);
1561 /* Investigations show that accessing higher samplers / textures stage
1562 * states does not return an error either. Writing to too high samplers
1563 * (approximately sampler 40) causes memory corruption in Windows, so
1564 * there is no bounds checking. */
1565 IDirect3DTexture9_Release(texture
);
1566 refcount
= IDirect3D9_Release(device
);
1567 ok(!refcount
, "Device has %u references left.\n", refcount
);
1569 IDirect3D9_Release(d3d
);
1570 DestroyWindow(window
);
1573 static void test_depthstenciltest(void)
1576 IDirect3DDevice9
*pDevice
= NULL
;
1577 D3DPRESENT_PARAMETERS d3dpp
;
1578 D3DDISPLAYMODE d3ddm
;
1579 IDirect3DSurface9
*pDepthStencil
= NULL
;
1580 IDirect3DSurface9
*pDepthStencil2
= NULL
;
1585 hwnd
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
1586 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1587 ok(!!hwnd
, "Failed to create a window.\n");
1588 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
1589 ok(!!d3d
, "Failed to create a D3D object.\n");
1591 IDirect3D9_GetAdapterDisplayMode(d3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
1592 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1593 d3dpp
.Windowed
= TRUE
;
1594 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1595 d3dpp
.BackBufferWidth
= 800;
1596 d3dpp
.BackBufferHeight
= 600;
1597 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1598 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1599 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
1601 hr
= IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */,
1602 hwnd
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
1603 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
|| broken(hr
== D3DERR_INVALIDCALL
), "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1606 skip("Failed to create a d3d device\n");
1610 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &pDepthStencil
);
1611 ok(hr
== D3D_OK
&& pDepthStencil
!= NULL
, "IDirect3DDevice9_GetDepthStencilSurface failed with %08x\n", hr
);
1614 hr
= IDirect3DDevice9_Clear(pDevice
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0x00000000, 1.0, 0);
1615 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1617 hr
= IDirect3DDevice9_SetDepthStencilSurface(pDevice
, NULL
);
1618 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetDepthStencilSurface failed with %08x\n", hr
);
1620 /* Check if the set buffer is returned on a get. WineD3D had a bug with that once, prevent it from coming back */
1621 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &pDepthStencil2
);
1622 ok(hr
== D3DERR_NOTFOUND
&& pDepthStencil2
== NULL
, "IDirect3DDevice9_GetDepthStencilSurface failed with %08x\n", hr
);
1623 if(pDepthStencil2
) IDirect3DSurface9_Release(pDepthStencil2
);
1625 /* This left the render states untouched! */
1626 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_ZENABLE
, &state
);
1627 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1628 ok(state
== D3DZB_TRUE
, "D3DRS_ZENABLE is %s\n", state
== D3DZB_FALSE
? "D3DZB_FALSE" : (state
== D3DZB_TRUE
? "D3DZB_TRUE" : "D3DZB_USEW"));
1629 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_ZWRITEENABLE
, &state
);
1630 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1631 ok(state
== TRUE
, "D3DRS_ZWRITEENABLE is %s\n", state
? "TRUE" : "FALSE");
1632 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_STENCILENABLE
, &state
);
1633 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1634 ok(state
== FALSE
, "D3DRS_STENCILENABLE is %s\n", state
? "TRUE" : "FALSE");
1635 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_STENCILWRITEMASK
, &state
);
1636 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1637 ok(state
== 0xffffffff, "D3DRS_STENCILWRITEMASK is 0x%08x\n", state
);
1639 /* This is supposed to fail now */
1640 hr
= IDirect3DDevice9_Clear(pDevice
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0x00000000, 1.0, 0);
1641 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1643 hr
= IDirect3DDevice9_SetRenderState(pDevice
, D3DRS_ZENABLE
, D3DZB_FALSE
);
1644 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed with %08x\n", hr
);
1646 hr
= IDirect3DDevice9_SetDepthStencilSurface(pDevice
, pDepthStencil
);
1647 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetDepthStencilSurface failed with %08x\n", hr
);
1649 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_ZENABLE
, &state
);
1650 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1651 ok(state
== D3DZB_FALSE
, "D3DRS_ZENABLE is %s\n", state
== D3DZB_FALSE
? "D3DZB_FALSE" : (state
== D3DZB_TRUE
? "D3DZB_TRUE" : "D3DZB_USEW"));
1653 /* Now it works again */
1654 hr
= IDirect3DDevice9_Clear(pDevice
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0x00000000, 1.0, 0);
1655 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1657 if(pDepthStencil
) IDirect3DSurface9_Release(pDepthStencil
);
1658 if(pDevice
) IDirect3D9_Release(pDevice
);
1660 /* Now see if autodepthstencil disable is honored. First, without a format set */
1661 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1662 d3dpp
.Windowed
= TRUE
;
1663 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1664 d3dpp
.BackBufferWidth
= 800;
1665 d3dpp
.BackBufferHeight
= 600;
1666 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1667 d3dpp
.EnableAutoDepthStencil
= FALSE
;
1668 d3dpp
.AutoDepthStencilFormat
= D3DFMT_UNKNOWN
;
1670 hr
= IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */,
1671 hwnd
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
1672 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1675 skip("Failed to create a d3d device\n");
1679 pDepthStencil
= NULL
;
1680 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &pDepthStencil
);
1681 ok(hr
== D3DERR_NOTFOUND
&& pDepthStencil
== NULL
, "IDirect3DDevice9_GetDepthStencilSurface returned %08x, surface = %p\n", hr
, pDepthStencil
);
1683 IDirect3DSurface9_Release(pDepthStencil
);
1684 pDepthStencil
= NULL
;
1687 /* Check the depth test state */
1688 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_ZENABLE
, &state
);
1689 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1690 ok(state
== D3DZB_FALSE
, "D3DRS_ZENABLE is %s\n", state
== D3DZB_FALSE
? "D3DZB_FALSE" : (state
== D3DZB_TRUE
? "D3DZB_TRUE" : "D3DZB_USEW"));
1692 if(pDevice
) IDirect3D9_Release(pDevice
);
1694 /* Next, try EnableAutoDepthStencil FALSE with a depth stencil format set */
1695 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1696 d3dpp
.Windowed
= TRUE
;
1697 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1698 d3dpp
.BackBufferWidth
= 800;
1699 d3dpp
.BackBufferHeight
= 600;
1700 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1701 d3dpp
.EnableAutoDepthStencil
= FALSE
;
1702 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
1704 hr
= IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */,
1705 hwnd
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
1706 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D9_CreateDevice failed with %08x\n", hr
);
1709 skip("Failed to create a d3d device\n");
1713 pDepthStencil
= NULL
;
1714 hr
= IDirect3DDevice9_GetDepthStencilSurface(pDevice
, &pDepthStencil
);
1715 ok(hr
== D3DERR_NOTFOUND
&& pDepthStencil
== NULL
, "IDirect3DDevice9_GetDepthStencilSurface returned %08x, surface = %p\n", hr
, pDepthStencil
);
1717 IDirect3DSurface9_Release(pDepthStencil
);
1718 pDepthStencil
= NULL
;
1721 hr
= IDirect3DDevice9_GetRenderState(pDevice
, D3DRS_ZENABLE
, &state
);
1722 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1723 ok(state
== D3DZB_FALSE
, "D3DRS_ZENABLE is %s\n", state
== D3DZB_FALSE
? "D3DZB_FALSE" : (state
== D3DZB_TRUE
? "D3DZB_TRUE" : "D3DZB_USEW"));
1726 if(pDepthStencil
) IDirect3DSurface9_Release(pDepthStencil
);
1729 UINT refcount
= IDirect3D9_Release(pDevice
);
1730 ok(!refcount
, "Device has %u references left.\n", refcount
);
1732 IDirect3D9_Release(d3d
);
1733 DestroyWindow(hwnd
);
1736 static void test_get_rt(void)
1738 IDirect3DSurface9
*backbuffer
, *rt
;
1739 IDirect3DDevice9
*device
;
1747 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
1748 0, 0, 128, 128, 0, 0, 0, 0);
1749 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
1750 ok(!!d3d9
, "Failed to create a D3D object.\n");
1751 device
= create_device(d3d9
, window
, window
, TRUE
);
1754 skip("Failed to create a D3D device, skipping tests.\n");
1758 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &backbuffer
);
1759 ok(SUCCEEDED(hr
), "Failed to get backbuffer, hr %#x.\n", hr
);
1760 ok(!!backbuffer
, "Got a NULL backbuffer.\n");
1762 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
1763 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
1765 for (i
= 1; i
< caps
.NumSimultaneousRTs
; ++i
)
1768 hr
= IDirect3DDevice9_GetRenderTarget(device
, i
, &rt
);
1769 ok(hr
== D3DERR_NOTFOUND
, "IDirect3DDevice9_GetRenderTarget returned %#x.\n", hr
);
1770 ok(!rt
, "Got rt %p.\n", rt
);
1773 IDirect3DSurface9_Release(backbuffer
);
1775 ref
= IDirect3DDevice9_Release(device
);
1776 ok(!ref
, "The device was not properly freed: refcount %u.\n", ref
);
1778 IDirect3D9_Release(d3d9
);
1779 DestroyWindow(window
);
1782 /* Test what happens when IDirect3DDevice9_DrawIndexedPrimitive is called without a valid index buffer set. */
1783 static void test_draw_indexed(void)
1785 static const struct {
1789 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
1790 {{-1.0f
, 1.0f
, 0.0f
}, 0xffff0000},
1791 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffff0000},
1792 {{ 1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
1794 WORD indices
[] = {0, 1, 2, 3, 0, 2};
1796 static const D3DVERTEXELEMENT9 decl_elements
[] = {
1797 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
1798 {0, 12, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
1802 IDirect3DVertexDeclaration9
*vertex_declaration
;
1803 IDirect3DVertexBuffer9
*vertex_buffer
;
1804 IDirect3DIndexBuffer9
*index_buffer
;
1805 IDirect3DDevice9
*device
;
1812 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", 0,
1813 0, 0, 640, 480, 0, 0, 0, 0);
1814 ok(!!window
, "Failed to create a window.\n");
1815 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
1816 ok(!!d3d9
, "Failed to create a D3D object.\n");
1817 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
1819 skip("Failed to create a 3D device, skipping test.\n");
1823 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &vertex_declaration
);
1824 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (0x%08x)\n", hr
);
1825 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
1826 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed (0x%08x)\n", hr
);
1828 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, sizeof(quad
), 0, 0, D3DPOOL_DEFAULT
, &vertex_buffer
, NULL
);
1829 ok(SUCCEEDED(hr
), "CreateVertexBuffer failed (0x%08x)\n", hr
);
1830 hr
= IDirect3DVertexBuffer9_Lock(vertex_buffer
, 0, 0, &ptr
, D3DLOCK_DISCARD
);
1831 ok(SUCCEEDED(hr
), "Lock failed (0x%08x)\n", hr
);
1832 memcpy(ptr
, quad
, sizeof(quad
));
1833 hr
= IDirect3DVertexBuffer9_Unlock(vertex_buffer
);
1834 ok(SUCCEEDED(hr
), "Unlock failed (0x%08x)\n", hr
);
1835 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vertex_buffer
, 0, sizeof(*quad
));
1836 ok(SUCCEEDED(hr
), "SetStreamSource failed (0x%08x)\n", hr
);
1838 hr
= IDirect3DDevice9_CreateIndexBuffer(device
, sizeof(indices
), 0, D3DFMT_INDEX16
, D3DPOOL_DEFAULT
, &index_buffer
, NULL
);
1839 ok(SUCCEEDED(hr
), "CreateIndexBuffer failed (0x%08x)\n", hr
);
1840 hr
= IDirect3DIndexBuffer9_Lock(index_buffer
, 0, 0, &ptr
, D3DLOCK_DISCARD
);
1841 ok(SUCCEEDED(hr
), "Lock failed (0x%08x)\n", hr
);
1842 memcpy(ptr
, indices
, sizeof(indices
));
1843 hr
= IDirect3DIndexBuffer9_Unlock(index_buffer
);
1844 ok(SUCCEEDED(hr
), "Unlock failed (0x%08x)\n", hr
);
1845 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
1846 ok(SUCCEEDED(hr
), "SetRenderState D3DRS_LIGHTING failed (0x%08x)\n", hr
);
1847 hr
= IDirect3DDevice9_BeginScene(device
);
1848 ok(SUCCEEDED(hr
), "BeginScene failed (0x%08x)\n", hr
);
1850 /* NULL index buffer. Should fail */
1851 hr
= IDirect3DDevice9_SetIndices(device
, NULL
);
1852 ok(SUCCEEDED(hr
), "SetIndices failed (0x%08x)\n", hr
);
1853 hr
= IDirect3DDevice9_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, 0 /* BaseVertexIndex */, 0 /* MinIndex */,
1854 4 /* NumVerts */, 0 /* StartIndex */, 2 /*PrimCount */);
1855 ok(hr
== D3DERR_INVALIDCALL
, "DrawIndexedPrimitive returned 0x%08x, expected D3DERR_INVALIDCALL (0x%08x)\n",
1856 hr
, D3DERR_INVALIDCALL
);
1858 /* Valid index buffer, NULL vertex declaration. Should fail */
1859 hr
= IDirect3DDevice9_SetIndices(device
, index_buffer
);
1860 ok(SUCCEEDED(hr
), "SetIndices failed (0x%08x)\n", hr
);
1861 hr
= IDirect3DDevice9_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, 0 /* BaseVertexIndex */, 0 /* MinIndex */,
1862 4 /* NumVerts */, 0 /* StartIndex */, 2 /*PrimCount */);
1863 ok(hr
== D3DERR_INVALIDCALL
, "DrawIndexedPrimitive returned 0x%08x, expected D3DERR_INVALIDCALL (0x%08x)\n",
1864 hr
, D3DERR_INVALIDCALL
);
1866 /* Valid index buffer and vertex declaration. Should succeed */
1867 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, vertex_declaration
);
1868 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed (0x%08x)\n", hr
);
1869 hr
= IDirect3DDevice9_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, 0 /* BaseVertexIndex */, 0 /* MinIndex */,
1870 4 /* NumVerts */, 0 /* StartIndex */, 2 /*PrimCount */);
1871 ok(SUCCEEDED(hr
), "DrawIndexedPrimitive failed (0x%08x)\n", hr
);
1873 hr
= IDirect3DDevice9_EndScene(device
);
1874 ok(SUCCEEDED(hr
), "EndScene failed (0x%08x)\n", hr
);
1876 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
1877 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
1879 IDirect3DVertexBuffer9_Release(vertex_buffer
);
1880 IDirect3DIndexBuffer9_Release(index_buffer
);
1881 IDirect3DVertexDeclaration9_Release(vertex_declaration
);
1882 refcount
= IDirect3DDevice9_Release(device
);
1883 ok(!refcount
, "Device has %u references left.\n", refcount
);
1885 IDirect3D9_Release(d3d9
);
1886 DestroyWindow(window
);
1889 static void test_null_stream(void)
1891 IDirect3DVertexBuffer9
*buffer
= NULL
;
1892 IDirect3DDevice9
*device
;
1897 IDirect3DVertexShader9
*shader
= NULL
;
1898 IDirect3DVertexDeclaration9
*decl
= NULL
;
1899 static const DWORD shader_code
[] =
1901 0xfffe0101, /* vs_1_1 */
1902 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
1903 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
1904 0x0000ffff /* end */
1906 static const D3DVERTEXELEMENT9 decl_elements
[] = {
1907 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
1908 {1, 0, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
1912 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
1913 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
1914 ok(!!window
, "Failed to create a window.\n");
1915 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
1916 ok(!!d3d9
, "Failed to create a D3D object.\n");
1917 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
1919 skip("Failed to create a 3D device, skipping test.\n");
1923 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_code
, &shader
);
1925 skip("No vertex shader support\n");
1928 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &decl
);
1929 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateVertexDeclaration failed (0x%08x)\n", hr
);
1931 skip("Vertex declaration handling not possible.\n");
1934 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, 12 * sizeof(float), 0, 0, D3DPOOL_MANAGED
, &buffer
, NULL
);
1935 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateVertexBuffer failed (0x%08x)\n", hr
);
1937 skip("Vertex buffer handling not possible.\n");
1941 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, buffer
, 0, sizeof(float) * 3);
1942 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetStreamSource failed (0x%08x)\n", hr
);
1943 hr
= IDirect3DDevice9_SetStreamSource(device
, 1, NULL
, 0, 0);
1944 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetStreamSource failed (0x%08x)\n", hr
);
1945 hr
= IDirect3DDevice9_SetVertexShader(device
, shader
);
1946 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShader failed (0x%08x)\n", hr
);
1947 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl
);
1948 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexDeclaration failed (0x%08x)\n", hr
);
1950 hr
= IDirect3DDevice9_BeginScene(device
);
1951 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1952 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_POINTLIST
, 0, 1);
1953 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1954 hr
= IDirect3DDevice9_EndScene(device
);
1955 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1957 IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 0, 0);
1958 IDirect3DDevice9_SetVertexShader(device
, NULL
);
1959 IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
1962 if (buffer
) IDirect3DVertexBuffer9_Release(buffer
);
1963 if (decl
) IDirect3DVertexDeclaration9_Release(decl
);
1964 if (shader
) IDirect3DVertexShader9_Release(shader
);
1967 refcount
= IDirect3DDevice9_Release(device
);
1968 ok(!refcount
, "Device has %u references left.\n", refcount
);
1970 IDirect3D9_Release(d3d9
);
1971 DestroyWindow(window
);
1974 static void test_lights(void)
1976 IDirect3DDevice9
*device
;
1985 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
1986 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
1987 ok(!!window
, "Failed to create a window.\n");
1988 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
1989 ok(!!d3d9
, "Failed to create a D3D object.\n");
1990 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
1992 skip("Failed to create a 3D device, skipping test.\n");
1996 memset(&caps
, 0, sizeof(caps
));
1997 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
1998 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetDeviceCaps failed with %08x\n", hr
);
2000 for(i
= 1; i
<= caps
.MaxActiveLights
; i
++) {
2001 hr
= IDirect3DDevice9_LightEnable(device
, i
, TRUE
);
2002 ok(hr
== D3D_OK
, "Enabling light %u failed with %08x\n", i
, hr
);
2003 hr
= IDirect3DDevice9_GetLightEnable(device
, i
, &enabled
);
2004 ok(hr
== D3D_OK
, "GetLightEnable on light %u failed with %08x\n", i
, hr
);
2005 ok(enabled
, "Light %d is %s\n", i
, enabled
? "enabled" : "disabled");
2008 /* TODO: Test the rendering results in this situation */
2009 hr
= IDirect3DDevice9_LightEnable(device
, i
+ 1, TRUE
);
2010 ok(hr
== D3D_OK
, "Enabling one light more than supported returned %08x\n", hr
);
2011 hr
= IDirect3DDevice9_GetLightEnable(device
, i
+ 1, &enabled
);
2012 ok(hr
== D3D_OK
, "GetLightEnable on light %u failed with %08x\n", i
+ 1, hr
);
2013 ok(enabled
, "Light %d is %s\n", i
+ 1, enabled
? "enabled" : "disabled");
2014 hr
= IDirect3DDevice9_LightEnable(device
, i
+ 1, FALSE
);
2015 ok(hr
== D3D_OK
, "Disabling the additional returned %08x\n", hr
);
2017 for(i
= 1; i
<= caps
.MaxActiveLights
; i
++) {
2018 hr
= IDirect3DDevice9_LightEnable(device
, i
, FALSE
);
2019 ok(hr
== D3D_OK
, "Disabling light %u failed with %08x\n", i
, hr
);
2022 refcount
= IDirect3DDevice9_Release(device
);
2023 ok(!refcount
, "Device has %u references left.\n", refcount
);
2025 IDirect3D9_Release(d3d9
);
2026 DestroyWindow(window
);
2029 static void test_set_stream_source(void)
2031 IDirect3DVertexBuffer9
*vb
;
2032 IDirect3DDevice9
*device
;
2038 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
2039 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
2040 ok(!!window
, "Failed to create a window.\n");
2041 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
2042 ok(!!d3d9
, "Failed to create a D3D object.\n");
2043 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
2045 skip("Failed to create a 3D device, skipping test.\n");
2049 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, 512, 0, 0, D3DPOOL_DEFAULT
, &vb
, NULL
);
2050 ok(SUCCEEDED(hr
), "Failed to create a vertex buffer, hr %#x.\n", hr
);
2052 /* Some cards (GeForce 7400 at least) accept non-aligned offsets, others
2053 * (Radeon 9000 verified) reject them, so accept both results. Wine
2054 * currently rejects this to be able to optimize the vbo conversion, but
2056 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vb
, 0, 32);
2057 ok(SUCCEEDED(hr
), "Failed to set the stream source, hr %#x.\n", hr
);
2058 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vb
, 1, 32);
2059 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
2060 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vb
, 2, 32);
2061 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
2062 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vb
, 3, 32);
2063 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
2064 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vb
, 4, 32);
2065 ok(SUCCEEDED(hr
), "Failed to set the stream source, hr %#x.\n", hr
);
2067 /* Try to set the NULL buffer with an offset and stride 0 */
2068 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 0, 0);
2069 ok(SUCCEEDED(hr
), "Failed to set the stream source, hr %#x.\n", hr
);
2070 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 1, 0);
2071 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
2072 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 2, 0);
2073 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
2074 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 3, 0);
2075 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
2076 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 4, 0);
2077 ok(SUCCEEDED(hr
), "Failed to set the stream source, hr %#x.\n", hr
);
2079 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 0, 0);
2080 ok(SUCCEEDED(hr
), "Failed to set the stream source, hr %#x.\n", hr
);
2082 IDirect3DVertexBuffer9_Release(vb
);
2083 refcount
= IDirect3DDevice9_Release(device
);
2084 ok(!refcount
, "Device has %u references left.\n", refcount
);
2086 IDirect3D9_Release(d3d9
);
2087 DestroyWindow(window
);
2090 /* Direct3D9 offers 4 display formats: R5G6B5, X1R5G5B5, X8R8G8B8 and
2091 * A2R10G10B10. Next to these there are 6 different back buffer formats. Only
2092 * a fixed number of combinations are possible in fullscreen mode. In windowed
2093 * mode more combinations are allowed due to format conversion and this is
2094 * likely driver dependent. */
2095 static void test_display_formats(void)
2097 D3DDEVTYPE device_type
= D3DDEVTYPE_HAL
;
2098 unsigned int backbuffer
, display
;
2099 unsigned int windowed
;
2109 D3DFORMAT alpha_format
;
2115 {"D3DFMT_R5G6B5", D3DFMT_R5G6B5
, 0, TRUE
, TRUE
},
2116 {"D3DFMT_X1R5G5B5", D3DFMT_X1R5G5B5
, D3DFMT_A1R5G5B5
, TRUE
, TRUE
},
2117 {"D3DFMT_A1R5G5B5", D3DFMT_A1R5G5B5
, D3DFMT_A1R5G5B5
, FALSE
, FALSE
},
2118 {"D3DFMT_X8R8G8B8", D3DFMT_X8R8G8B8
, D3DFMT_A8R8G8B8
, TRUE
, TRUE
},
2119 {"D3DFMT_A8R8G8B8", D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
, FALSE
, FALSE
},
2120 {"D3DFMT_A2R10G10B10", D3DFMT_A2R10G10B10
, 0, TRUE
, FALSE
},
2121 {"D3DFMT_UNKNOWN", D3DFMT_UNKNOWN
, 0, FALSE
, FALSE
},
2124 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
2125 ok(!!d3d9
, "Failed to create a D3D object.\n");
2127 for (display
= 0; display
< sizeof(formats
) / sizeof(*formats
); ++display
)
2129 has_modes
= IDirect3D9_GetAdapterModeCount(d3d9
, D3DADAPTER_DEFAULT
, formats
[display
].format
);
2131 for (windowed
= 0; windowed
<= 1; ++windowed
)
2133 for (backbuffer
= 0; backbuffer
< sizeof(formats
) / sizeof(*formats
); ++backbuffer
)
2135 should_pass
= FALSE
;
2137 if (formats
[display
].display
&& (formats
[display
].windowed
|| !windowed
) && (has_modes
|| windowed
))
2139 D3DFORMAT backbuffer_format
;
2141 if (windowed
&& formats
[backbuffer
].format
== D3DFMT_UNKNOWN
)
2142 backbuffer_format
= formats
[display
].format
;
2144 backbuffer_format
= formats
[backbuffer
].format
;
2146 hr
= IDirect3D9_CheckDeviceFormat(d3d9
, D3DADAPTER_DEFAULT
, device_type
, formats
[display
].format
,
2147 D3DUSAGE_RENDERTARGET
, D3DRTYPE_SURFACE
, backbuffer_format
);
2152 hr
= IDirect3D9_CheckDeviceFormatConversion(d3d9
, D3DADAPTER_DEFAULT
, device_type
,
2153 backbuffer_format
, formats
[display
].format
);
2154 should_pass
= (hr
== D3D_OK
);
2157 should_pass
= (formats
[display
].format
== formats
[backbuffer
].format
2158 || (formats
[display
].alpha_format
2159 && formats
[display
].alpha_format
== formats
[backbuffer
].alpha_format
));
2163 hr
= IDirect3D9_CheckDeviceType(d3d9
, D3DADAPTER_DEFAULT
, device_type
,
2164 formats
[display
].format
, formats
[backbuffer
].format
, windowed
);
2165 ok(SUCCEEDED(hr
) == should_pass
|| broken(SUCCEEDED(hr
) && !has_modes
) /* Win8 64-bit */,
2166 "Got unexpected hr %#x for %s / %s, windowed %#x, should_pass %#x.\n",
2167 hr
, formats
[display
].name
, formats
[backbuffer
].name
, windowed
, should_pass
);
2172 IDirect3D9_Release(d3d9
);
2175 static void test_scissor_size(void)
2177 IDirect3D9
*d3d9_ptr
;
2180 int winx
; int winy
; int backx
; int backy
; BOOL window
;
2181 } scts
[] = { /* scissor tests */
2182 {800, 600, 640, 480, TRUE
},
2183 {800, 600, 640, 480, FALSE
},
2184 {640, 480, 800, 600, TRUE
},
2185 {640, 480, 800, 600, FALSE
},
2188 d3d9_ptr
= Direct3DCreate9(D3D_SDK_VERSION
);
2189 ok(!!d3d9_ptr
, "Failed to create a D3D object.\n");
2191 for(i
=0; i
<sizeof(scts
)/sizeof(scts
[0]); i
++) {
2192 IDirect3DDevice9
*device_ptr
= 0;
2193 D3DPRESENT_PARAMETERS present_parameters
;
2198 hwnd
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
,
2199 0, 0, scts
[i
].winx
, scts
[i
].winy
, 0, 0, 0, 0);
2201 if (!scts
[i
].window
)
2203 scts
[i
].backx
= screen_width
;
2204 scts
[i
].backy
= screen_height
;
2207 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
2208 present_parameters
.Windowed
= scts
[i
].window
;
2209 present_parameters
.hDeviceWindow
= hwnd
;
2210 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2211 present_parameters
.BackBufferWidth
= scts
[i
].backx
;
2212 present_parameters
.BackBufferHeight
= scts
[i
].backy
;
2213 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
2214 present_parameters
.EnableAutoDepthStencil
= TRUE
;
2215 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
2217 hr
= IDirect3D9_CreateDevice(d3d9_ptr
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, present_parameters
.hDeviceWindow
, D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device_ptr
);
2219 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D16
;
2220 hr
= IDirect3D9_CreateDevice(d3d9_ptr
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, present_parameters
.hDeviceWindow
, D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device_ptr
);
2222 hr
= IDirect3D9_CreateDevice(d3d9_ptr
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, present_parameters
.hDeviceWindow
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device_ptr
);
2225 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D_CreateDevice returned: %08x\n", hr
);
2229 DestroyWindow(hwnd
);
2230 skip("Creating the device failed\n");
2234 /* Check for the default scissor rect size */
2235 hr
= IDirect3DDevice9_GetScissorRect(device_ptr
, &scissorrect
);
2236 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetScissorRect failed with: %08x\n", hr
);
2237 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
);
2239 /* check the scissorrect values after a reset */
2240 present_parameters
.BackBufferWidth
= screen_width
;
2241 present_parameters
.BackBufferHeight
= screen_height
;
2242 hr
= IDirect3DDevice9_Reset(device_ptr
, &present_parameters
);
2243 ok(hr
== D3D_OK
, "IDirect3DDevice9_Reset failed with %08x\n", hr
);
2244 hr
= IDirect3DDevice9_TestCooperativeLevel(device_ptr
);
2245 ok(hr
== D3D_OK
, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr
);
2247 hr
= IDirect3DDevice9_GetScissorRect(device_ptr
, &scissorrect
);
2248 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetScissorRect failed with: %08x\n", hr
);
2249 ok(scissorrect
.right
== screen_width
&& scissorrect
.bottom
== screen_height
&& scissorrect
.top
== 0 && scissorrect
.left
== 0, "Scissorrect missmatch (%d, %d) should be (%d, %d)\n", scissorrect
.right
, scissorrect
.bottom
, screen_width
, screen_height
);
2254 ref
= IDirect3DDevice9_Release(device_ptr
);
2255 DestroyWindow(hwnd
);
2256 ok(ref
== 0, "The device was not properly freed: refcount %u\n", ref
);
2261 IDirect3D9_Release(d3d9_ptr
);
2264 static void test_multi_device(void)
2266 IDirect3DDevice9
*device1
, *device2
;
2267 HWND window1
, window2
;
2271 window1
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
2272 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
2273 ok(!!window1
, "Failed to create a window.\n");
2274 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
2275 ok(!!d3d9
, "Failed to create a D3D object.\n");
2276 if (!(device1
= create_device(d3d9
, window1
, window1
, TRUE
)))
2278 skip("Failed to create a 3D device, skipping test.\n");
2279 IDirect3D9_Release(d3d9
);
2280 DestroyWindow(window1
);
2283 IDirect3D9_Release(d3d9
);
2285 window2
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
2286 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
2287 ok(!!window2
, "Failed to create a window.\n");
2288 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
2289 ok(!!d3d9
, "Failed to create a D3D object.\n");
2290 device2
= create_device(d3d9
, window2
, window2
, TRUE
);
2291 IDirect3D9_Release(d3d9
);
2293 refcount
= IDirect3DDevice9_Release(device2
);
2294 ok(!refcount
, "Device has %u references left.\n", refcount
);
2295 refcount
= IDirect3DDevice9_Release(device1
);
2296 ok(!refcount
, "Device has %u references left.\n", refcount
);
2297 DestroyWindow(window2
);
2298 DestroyWindow(window1
);
2301 static HWND filter_messages
;
2312 enum message_window window
;
2315 static const struct message
*expect_messages
;
2316 static HWND device_window
, focus_window
;
2318 struct wndproc_thread_param
2321 HANDLE window_created
;
2322 HANDLE test_finished
;
2323 BOOL running_in_foreground
;
2326 static LRESULT CALLBACK
test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2328 if (filter_messages
&& filter_messages
== hwnd
)
2330 if (message
!= WM_DISPLAYCHANGE
&& message
!= WM_IME_NOTIFY
)
2331 todo_wine
ok( 0, "Received unexpected message %#x for window %p.\n", message
, hwnd
);
2334 if (expect_messages
)
2338 switch (expect_messages
->window
)
2353 if (hwnd
== w
&& expect_messages
->message
== message
) ++expect_messages
;
2356 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
2359 static DWORD WINAPI
wndproc_thread(void *param
)
2361 struct wndproc_thread_param
*p
= param
;
2365 p
->dummy_window
= CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test",
2366 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, screen_width
, screen_height
, 0, 0, 0, 0);
2367 p
->running_in_foreground
= SetForegroundWindow(p
->dummy_window
);
2369 ret
= SetEvent(p
->window_created
);
2370 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
2376 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&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 IDirect3DDevice9
*device
;
2403 static const struct message messages
[] =
2405 {WM_WINDOWPOSCHANGING
, FOCUS_WINDOW
},
2406 {WM_ACTIVATE
, FOCUS_WINDOW
},
2407 {WM_SETFOCUS
, FOCUS_WINDOW
},
2411 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
2412 ok(!!d3d9
, "Failed to create a D3D object.\n");
2414 wc
.lpfnWndProc
= test_proc
;
2415 wc
.lpszClassName
= "d3d9_test_wndproc_wc";
2416 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2418 thread_params
.window_created
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2419 ok(!!thread_params
.window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
2420 thread_params
.test_finished
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2421 ok(!!thread_params
.test_finished
, "CreateEvent failed, last error %#x.\n", GetLastError());
2423 focus_window
= CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test",
2424 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, screen_width
, screen_height
, 0, 0, 0, 0);
2425 device_window
= CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test",
2426 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, screen_width
, screen_height
, 0, 0, 0, 0);
2427 thread
= CreateThread(NULL
, 0, wndproc_thread
, &thread_params
, 0, &tid
);
2428 ok(!!thread
, "Failed to create thread, last error %#x.\n", GetLastError());
2430 res
= WaitForSingleObject(thread_params
.window_created
, INFINITE
);
2431 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
2433 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2434 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2435 (LONG_PTR
)test_proc
, proc
);
2436 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2437 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2438 (LONG_PTR
)test_proc
, proc
);
2440 trace("device_window %p, focus_window %p, dummy_window %p.\n",
2441 device_window
, focus_window
, thread_params
.dummy_window
);
2444 ok(tmp
== device_window
, "Expected focus %p, got %p.\n", device_window
, tmp
);
2445 if (thread_params
.running_in_foreground
)
2447 tmp
= GetForegroundWindow();
2448 ok(tmp
== thread_params
.dummy_window
, "Expected foreground window %p, got %p.\n",
2449 thread_params
.dummy_window
, tmp
);
2452 skip("Not running in foreground, skip foreground window test\n");
2456 expect_messages
= messages
;
2458 device
= create_device(d3d9
, device_window
, focus_window
, FALSE
);
2461 skip("Failed to create a D3D device, skipping tests.\n");
2465 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2466 expect_messages
->message
, expect_messages
->window
);
2467 expect_messages
= NULL
;
2469 if (0) /* Disabled until we can make this work in a reliable way on Wine. */
2472 ok(tmp
== focus_window
, "Expected focus %p, got %p.\n", focus_window
, tmp
);
2473 tmp
= GetForegroundWindow();
2474 ok(tmp
== focus_window
, "Expected foreground window %p, got %p.\n", focus_window
, tmp
);
2476 SetForegroundWindow(focus_window
);
2479 filter_messages
= focus_window
;
2481 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2482 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2483 (LONG_PTR
)test_proc
, proc
);
2485 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2486 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2487 (LONG_PTR
)test_proc
, proc
);
2489 ref
= IDirect3DDevice9_Release(device
);
2490 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2492 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2493 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2494 (LONG_PTR
)test_proc
, proc
);
2496 device
= create_device(d3d9
, focus_window
, focus_window
, FALSE
);
2499 skip("Failed to create a D3D device, skipping tests.\n");
2503 ref
= IDirect3DDevice9_Release(device
);
2504 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2506 device
= create_device(d3d9
, device_window
, focus_window
, FALSE
);
2509 skip("Failed to create a D3D device, skipping tests.\n");
2513 proc
= SetWindowLongPtrA(focus_window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2514 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2515 (LONG_PTR
)test_proc
, proc
);
2517 ref
= IDirect3DDevice9_Release(device
);
2518 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2520 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2521 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2522 (LONG_PTR
)DefWindowProcA
, proc
);
2525 filter_messages
= NULL
;
2526 IDirect3D9_Release(d3d9
);
2528 SetEvent(thread_params
.test_finished
);
2529 WaitForSingleObject(thread
, INFINITE
);
2530 CloseHandle(thread_params
.test_finished
);
2531 CloseHandle(thread_params
.window_created
);
2532 CloseHandle(thread
);
2534 DestroyWindow(device_window
);
2535 DestroyWindow(focus_window
);
2536 UnregisterClassA("d3d9_test_wndproc_wc", GetModuleHandleA(NULL
));
2539 static void test_wndproc_windowed(void)
2541 struct wndproc_thread_param thread_params
;
2542 IDirect3DDevice9
*device
;
2552 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
2553 ok(!!d3d9
, "Failed to create a D3D object.\n");
2555 wc
.lpfnWndProc
= test_proc
;
2556 wc
.lpszClassName
= "d3d9_test_wndproc_wc";
2557 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2559 thread_params
.window_created
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2560 ok(!!thread_params
.window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
2561 thread_params
.test_finished
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2562 ok(!!thread_params
.test_finished
, "CreateEvent failed, last error %#x.\n", GetLastError());
2564 focus_window
= CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test",
2565 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, screen_width
, screen_height
, 0, 0, 0, 0);
2566 device_window
= CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test",
2567 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, screen_width
, screen_height
, 0, 0, 0, 0);
2568 thread
= CreateThread(NULL
, 0, wndproc_thread
, &thread_params
, 0, &tid
);
2569 ok(!!thread
, "Failed to create thread, last error %#x.\n", GetLastError());
2571 res
= WaitForSingleObject(thread_params
.window_created
, INFINITE
);
2572 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
2574 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2575 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2576 (LONG_PTR
)test_proc
, proc
);
2577 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2578 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2579 (LONG_PTR
)test_proc
, proc
);
2581 trace("device_window %p, focus_window %p, dummy_window %p.\n",
2582 device_window
, focus_window
, thread_params
.dummy_window
);
2585 ok(tmp
== device_window
, "Expected focus %p, got %p.\n", device_window
, tmp
);
2586 if (thread_params
.running_in_foreground
)
2588 tmp
= GetForegroundWindow();
2589 ok(tmp
== thread_params
.dummy_window
, "Expected foreground window %p, got %p.\n",
2590 thread_params
.dummy_window
, tmp
);
2593 skip("Not running in foreground, skip foreground window test\n");
2595 filter_messages
= focus_window
;
2597 device
= create_device(d3d9
, device_window
, focus_window
, TRUE
);
2600 skip("Failed to create a D3D device, skipping tests.\n");
2605 ok(tmp
== device_window
, "Expected focus %p, got %p.\n", device_window
, tmp
);
2606 tmp
= GetForegroundWindow();
2607 ok(tmp
== thread_params
.dummy_window
, "Expected foreground window %p, got %p.\n",
2608 thread_params
.dummy_window
, tmp
);
2610 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2611 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2612 (LONG_PTR
)test_proc
, proc
);
2614 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2615 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2616 (LONG_PTR
)test_proc
, proc
);
2618 filter_messages
= NULL
;
2620 hr
= reset_device(device
, device_window
, FALSE
);
2621 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
2623 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2624 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2625 (LONG_PTR
)test_proc
, proc
);
2627 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2628 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2629 (LONG_PTR
)test_proc
, proc
);
2631 hr
= reset_device(device
, device_window
, TRUE
);
2632 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
2634 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2635 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2636 (LONG_PTR
)test_proc
, proc
);
2638 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2639 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2640 (LONG_PTR
)test_proc
, proc
);
2642 filter_messages
= focus_window
;
2644 ref
= IDirect3DDevice9_Release(device
);
2645 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2647 filter_messages
= device_window
;
2649 device
= create_device(d3d9
, focus_window
, focus_window
, TRUE
);
2652 skip("Failed to create a D3D device, skipping tests.\n");
2656 filter_messages
= NULL
;
2658 hr
= reset_device(device
, focus_window
, FALSE
);
2659 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
2661 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2662 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2663 (LONG_PTR
)test_proc
, proc
);
2665 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2666 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2667 (LONG_PTR
)test_proc
, proc
);
2669 hr
= reset_device(device
, focus_window
, TRUE
);
2670 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
2672 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2673 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2674 (LONG_PTR
)test_proc
, proc
);
2676 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2677 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2678 (LONG_PTR
)test_proc
, proc
);
2680 filter_messages
= device_window
;
2682 ref
= IDirect3DDevice9_Release(device
);
2683 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2685 device
= create_device(d3d9
, device_window
, focus_window
, TRUE
);
2688 skip("Failed to create a D3D device, skipping tests.\n");
2692 filter_messages
= NULL
;
2694 hr
= reset_device(device
, device_window
, FALSE
);
2695 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
2697 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2698 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2699 (LONG_PTR
)test_proc
, proc
);
2701 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2702 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2703 (LONG_PTR
)test_proc
, proc
);
2705 hr
= reset_device(device
, device_window
, TRUE
);
2706 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
2708 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2709 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2710 (LONG_PTR
)test_proc
, proc
);
2712 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2713 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2714 (LONG_PTR
)test_proc
, proc
);
2716 filter_messages
= device_window
;
2718 ref
= IDirect3DDevice9_Release(device
);
2719 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2722 filter_messages
= NULL
;
2723 IDirect3D9_Release(d3d9
);
2725 SetEvent(thread_params
.test_finished
);
2726 WaitForSingleObject(thread
, INFINITE
);
2727 CloseHandle(thread_params
.test_finished
);
2728 CloseHandle(thread_params
.window_created
);
2729 CloseHandle(thread
);
2731 DestroyWindow(device_window
);
2732 DestroyWindow(focus_window
);
2733 UnregisterClassA("d3d9_test_wndproc_wc", GetModuleHandleA(NULL
));
2736 static void test_reset_fullscreen(void)
2738 WNDCLASSEXA wc
= {0};
2739 IDirect3DDevice9
*device
= NULL
;
2742 static const struct message messages
[] =
2744 {WM_ACTIVATEAPP
, FOCUS_WINDOW
},
2748 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
2749 ok(!!d3d
, "Failed to create a D3D object.\n");
2750 expect_messages
= messages
;
2752 wc
.cbSize
= sizeof(wc
);
2753 wc
.lpfnWndProc
= test_proc
;
2754 wc
.lpszClassName
= "test_reset_fullscreen";
2756 atom
= RegisterClassExA(&wc
);
2757 ok(atom
, "Failed to register a new window class. GetLastError:%d\n", GetLastError());
2759 device_window
= focus_window
= CreateWindowExA(0, wc
.lpszClassName
, "Test Reset Fullscreen", 0,
2760 0, 0, screen_width
, screen_height
, NULL
, NULL
, NULL
, NULL
);
2761 ok(device_window
!= NULL
, "Failed to create a window. GetLastError:%d\n", GetLastError());
2764 * Create a device in windowed mode.
2765 * Since the device is windowed and we haven't called any methods that
2766 * could show the window (such as ShowWindow or SetWindowPos) yet,
2767 * WM_ACTIVATEAPP will not have been sent.
2769 device
= create_device(d3d
, device_window
, focus_window
, TRUE
);
2772 skip("Unable to create device. Skipping test.\n");
2777 * Switch to fullscreen mode.
2778 * This will force the window to be shown and will cause the WM_ACTIVATEAPP
2779 * message to be sent.
2781 ok(SUCCEEDED(reset_device(device
, device_window
, FALSE
)), "Failed to reset device.\n");
2784 ok(expect_messages
->message
== 0, "Expected to receive message %#x.\n", expect_messages
->message
);
2785 expect_messages
= NULL
;
2788 if (device
) IDirect3DDevice9_Release(device
);
2789 IDirect3D9_Release(d3d
);
2790 DestroyWindow(device_window
);
2791 device_window
= focus_window
= NULL
;
2792 UnregisterClassA(wc
.lpszClassName
, GetModuleHandleA(NULL
));
2796 static inline void set_fpu_cw(WORD cw
)
2798 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2799 #define D3D9_TEST_SET_FPU_CW 1
2800 __asm__
volatile ("fnclex");
2801 __asm__
volatile ("fldcw %0" : : "m" (cw
));
2802 #elif defined(__i386__) && defined(_MSC_VER)
2803 #define D3D9_TEST_SET_FPU_CW 1
2809 static inline WORD
get_fpu_cw(void)
2812 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2813 #define D3D9_TEST_GET_FPU_CW 1
2814 __asm__
volatile ("fnstcw %0" : "=m" (cw
));
2815 #elif defined(__i386__) && defined(_MSC_VER)
2816 #define D3D9_TEST_GET_FPU_CW 1
2822 static void test_fpu_setup(void)
2824 #if defined(D3D9_TEST_SET_FPU_CW) && defined(D3D9_TEST_GET_FPU_CW)
2825 D3DPRESENT_PARAMETERS present_parameters
;
2826 IDirect3DDevice9
*device
;
2832 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_CAPTION
, 0, 0, screen_width
, screen_height
, 0, 0, 0, 0);
2833 ok(!!window
, "Failed to create a window.\n");
2834 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
2835 ok(!!d3d9
, "Failed to create a D3D object.\n");
2837 memset(&present_parameters
, 0, sizeof(present_parameters
));
2838 present_parameters
.Windowed
= TRUE
;
2839 present_parameters
.hDeviceWindow
= window
;
2840 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2844 ok(cw
== 0xf60, "cw is %#x, expected 0xf60.\n", cw
);
2846 hr
= IDirect3D9_CreateDevice(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, window
,
2847 D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
2850 skip("Failed to create a device, hr %#x.\n", hr
);
2856 ok(cw
== 0x7f, "cw is %#x, expected 0x7f.\n", cw
);
2858 IDirect3DDevice9_Release(device
);
2861 ok(cw
== 0x7f, "cw is %#x, expected 0x7f.\n", cw
);
2864 ok(cw
== 0xf60, "cw is %#x, expected 0xf60.\n", cw
);
2866 hr
= IDirect3D9_CreateDevice(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, window
,
2867 D3DCREATE_HARDWARE_VERTEXPROCESSING
| D3DCREATE_FPU_PRESERVE
, &present_parameters
, &device
);
2868 ok(SUCCEEDED(hr
), "CreateDevice failed, hr %#x.\n", hr
);
2871 ok(cw
== 0xf60, "cw is %#x, expected 0xf60.\n", cw
);
2874 IDirect3DDevice9_Release(device
);
2877 IDirect3D9_Release(d3d9
);
2878 DestroyWindow(window
);
2882 static void test_window_style(void)
2884 RECT focus_rect
, fullscreen_rect
, r
;
2885 LONG device_style
, device_exstyle
;
2886 LONG focus_style
, focus_exstyle
;
2887 LONG style
, expected_style
;
2888 IDirect3DDevice9
*device
;
2893 focus_window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
2894 0, 0, screen_width
/ 2, screen_height
/ 2, 0, 0, 0, 0);
2895 device_window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
2896 0, 0, screen_width
/ 2, screen_height
/ 2, 0, 0, 0, 0);
2897 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
2898 ok(!!d3d9
, "Failed to create a D3D object.\n");
2900 device_style
= GetWindowLongA(device_window
, GWL_STYLE
);
2901 device_exstyle
= GetWindowLongA(device_window
, GWL_EXSTYLE
);
2902 focus_style
= GetWindowLongA(focus_window
, GWL_STYLE
);
2903 focus_exstyle
= GetWindowLongA(focus_window
, GWL_EXSTYLE
);
2905 SetRect(&fullscreen_rect
, 0, 0, screen_width
, screen_height
);
2906 GetWindowRect(focus_window
, &focus_rect
);
2908 device
= create_device(d3d9
, device_window
, focus_window
, FALSE
);
2911 skip("Failed to create a D3D device, skipping tests.\n");
2915 style
= GetWindowLongA(device_window
, GWL_STYLE
);
2916 expected_style
= device_style
| WS_VISIBLE
;
2917 todo_wine
ok(style
== expected_style
, "Expected device window style %#x, got %#x.\n",
2918 expected_style
, style
);
2919 style
= GetWindowLongA(device_window
, GWL_EXSTYLE
);
2920 expected_style
= device_exstyle
| WS_EX_TOPMOST
;
2921 todo_wine
ok(style
== expected_style
, "Expected device window extended style %#x, got %#x.\n",
2922 expected_style
, style
);
2924 style
= GetWindowLongA(focus_window
, GWL_STYLE
);
2925 ok(style
== focus_style
, "Expected focus window style %#x, got %#x.\n",
2926 focus_style
, style
);
2927 style
= GetWindowLongA(focus_window
, GWL_EXSTYLE
);
2928 ok(style
== focus_exstyle
, "Expected focus window extended style %#x, got %#x.\n",
2929 focus_exstyle
, style
);
2931 GetWindowRect(device_window
, &r
);
2932 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2933 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2934 r
.left
, r
.top
, r
.right
, r
.bottom
);
2935 GetClientRect(device_window
, &r
);
2936 todo_wine
ok(!EqualRect(&r
, &fullscreen_rect
), "Client rect and window rect are equal.\n");
2937 GetWindowRect(focus_window
, &r
);
2938 ok(EqualRect(&r
, &focus_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2939 focus_rect
.left
, focus_rect
.top
, focus_rect
.right
, focus_rect
.bottom
,
2940 r
.left
, r
.top
, r
.right
, r
.bottom
);
2942 hr
= reset_device(device
, device_window
, TRUE
);
2943 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
2945 style
= GetWindowLongA(device_window
, GWL_STYLE
);
2946 expected_style
= device_style
| WS_VISIBLE
;
2947 ok(style
== expected_style
, "Expected device window style %#x, got %#x.\n",
2948 expected_style
, style
);
2949 style
= GetWindowLongA(device_window
, GWL_EXSTYLE
);
2950 expected_style
= device_exstyle
| WS_EX_TOPMOST
;
2951 ok(style
== expected_style
, "Expected device window extended style %#x, got %#x.\n",
2952 expected_style
, style
);
2954 style
= GetWindowLongA(focus_window
, GWL_STYLE
);
2955 ok(style
== focus_style
, "Expected focus window style %#x, got %#x.\n",
2956 focus_style
, style
);
2957 style
= GetWindowLongA(focus_window
, GWL_EXSTYLE
);
2958 ok(style
== focus_exstyle
, "Expected focus window extended style %#x, got %#x.\n",
2959 focus_exstyle
, style
);
2961 ref
= IDirect3DDevice9_Release(device
);
2962 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2965 IDirect3D9_Release(d3d9
);
2967 DestroyWindow(device_window
);
2968 DestroyWindow(focus_window
);
2971 static const POINT
*expect_pos
;
2973 static LRESULT CALLBACK
test_cursor_proc(HWND window
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2975 if (message
== WM_MOUSEMOVE
)
2977 if (expect_pos
&& expect_pos
->x
&& expect_pos
->y
)
2979 POINT p
= {GET_X_LPARAM(lparam
), GET_Y_LPARAM(lparam
)};
2981 ClientToScreen(window
, &p
);
2982 if (expect_pos
->x
== p
.x
&& expect_pos
->y
== p
.y
)
2987 return DefWindowProcA(window
, message
, wparam
, lparam
);
2990 static void test_cursor_pos(void)
2992 IDirect3DSurface9
*cursor
;
2993 IDirect3DDevice9
*device
;
3001 /* Note that we don't check for movement we're not supposed to receive.
3002 * That's because it's hard to distinguish from the user accidentally
3003 * moving the mouse. */
3004 static const POINT points
[] =
3017 wc
.lpfnWndProc
= test_cursor_proc
;
3018 wc
.lpszClassName
= "d3d9_test_cursor_wc";
3019 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
3020 window
= CreateWindowA("d3d9_test_cursor_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
3021 0, 0, 320, 240, NULL
, NULL
, NULL
, NULL
);
3022 ShowWindow(window
, SW_SHOW
);
3023 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
3024 ok(!!d3d9
, "Failed to create a D3D object.\n");
3026 device
= create_device(d3d9
, window
, window
, TRUE
);
3029 skip("Failed to create a D3D device, skipping tests.\n");
3033 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 32, 32,
3034 D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &cursor
, NULL
);
3035 ok(SUCCEEDED(hr
), "Failed to create cursor surface, hr %#x.\n", hr
);
3036 hr
= IDirect3DDevice9_SetCursorProperties(device
, 0, 0, cursor
);
3037 ok(SUCCEEDED(hr
), "Failed to set cursor properties, hr %#x.\n", hr
);
3038 IDirect3DSurface9_Release(cursor
);
3039 ret
= IDirect3DDevice9_ShowCursor(device
, TRUE
);
3040 ok(!ret
, "Failed to show cursor, hr %#x.\n", ret
);
3043 expect_pos
= points
;
3045 ret
= SetCursorPos(50, 50);
3046 ok(ret
, "Failed to set cursor position.\n");
3049 IDirect3DDevice9_SetCursorPosition(device
, 75, 75, 0);
3051 /* SetCursorPosition() eats duplicates. */
3052 IDirect3DDevice9_SetCursorPosition(device
, 75, 75, 0);
3055 ret
= SetCursorPos(100, 100);
3056 ok(ret
, "Failed to set cursor position.\n");
3058 /* Even if the position was set with SetCursorPos(). */
3059 IDirect3DDevice9_SetCursorPosition(device
, 100, 100, 0);
3062 IDirect3DDevice9_SetCursorPosition(device
, 125, 125, 0);
3064 ret
= SetCursorPos(150, 150);
3065 ok(ret
, "Failed to set cursor position.\n");
3067 IDirect3DDevice9_SetCursorPosition(device
, 125, 125, 0);
3070 IDirect3DDevice9_SetCursorPosition(device
, 150, 150, 0);
3072 /* SetCursorPos() doesn't. */
3073 ret
= SetCursorPos(150, 150);
3074 ok(ret
, "Failed to set cursor position.\n");
3077 ok(!expect_pos
->x
&& !expect_pos
->y
, "Didn't receive MOUSEMOVE %u (%d, %d).\n",
3078 (unsigned)(expect_pos
- points
), expect_pos
->x
, expect_pos
->y
);
3080 refcount
= IDirect3DDevice9_Release(device
);
3081 ok(!refcount
, "Device has %u references left.\n", refcount
);
3083 DestroyWindow(window
);
3084 UnregisterClassA("d3d9_test_cursor_wc", GetModuleHandleA(NULL
));
3085 IDirect3D9_Release(d3d9
);
3088 static void test_mode_change(void)
3090 RECT fullscreen_rect
, focus_rect
, r
;
3091 IDirect3DSurface9
*backbuffer
;
3092 IDirect3DDevice9
*device
;
3093 D3DSURFACE_DESC desc
;
3100 focus_window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
3101 0, 0, screen_width
/ 2, screen_height
/ 2, 0, 0, 0, 0);
3102 device_window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
3103 0, 0, screen_width
/ 2, screen_height
/ 2, 0, 0, 0, 0);
3104 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
3105 ok(!!d3d9
, "Failed to create a D3D object.\n");
3107 SetRect(&fullscreen_rect
, 0, 0, screen_width
, screen_height
);
3108 GetWindowRect(focus_window
, &focus_rect
);
3110 device
= create_device(d3d9
, device_window
, focus_window
, FALSE
);
3113 skip("Failed to create a D3D device, skipping tests.\n");
3117 memset(&devmode
, 0, sizeof(devmode
));
3118 devmode
.dmSize
= sizeof(devmode
);
3119 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
3120 devmode
.dmPelsWidth
= 640;
3121 devmode
.dmPelsHeight
= 480;
3123 ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
3124 ok(ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", ret
);
3126 memset(&devmode
, 0, sizeof(devmode
));
3127 devmode
.dmSize
= sizeof(devmode
);
3128 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3129 ok(ret
, "Failed to get display mode.\n");
3130 ok(devmode
.dmPelsWidth
== 640, "Got unexpect width %u.\n", devmode
.dmPelsWidth
);
3131 ok(devmode
.dmPelsHeight
== 480, "Got unexpect height %u.\n", devmode
.dmPelsHeight
);
3133 GetWindowRect(device_window
, &r
);
3134 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3135 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
3136 r
.left
, r
.top
, r
.right
, r
.bottom
);
3137 GetWindowRect(focus_window
, &r
);
3138 ok(EqualRect(&r
, &focus_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3139 focus_rect
.left
, focus_rect
.top
, focus_rect
.right
, focus_rect
.bottom
,
3140 r
.left
, r
.top
, r
.right
, r
.bottom
);
3142 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
3143 ok(SUCCEEDED(hr
), "Failed to get backbuffer, hr %#x.\n", hr
);
3144 hr
= IDirect3DSurface9_GetDesc(backbuffer
, &desc
);
3145 ok(SUCCEEDED(hr
), "Failed to get backbuffer desc, hr %#x.\n", hr
);
3146 ok(desc
.Width
== screen_width
, "Got unexpected backbuffer width %u.\n", desc
.Width
);
3147 ok(desc
.Height
== screen_height
, "Got unexpected backbuffer height %u.\n", desc
.Height
);
3148 IDirect3DSurface9_Release(backbuffer
);
3150 refcount
= IDirect3DDevice9_Release(device
);
3151 ok(!refcount
, "Device has %u references left.\n", refcount
);
3153 memset(&devmode
, 0, sizeof(devmode
));
3154 devmode
.dmSize
= sizeof(devmode
);
3155 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3156 ok(ret
, "Failed to get display mode.\n");
3157 ok(devmode
.dmPelsWidth
== screen_width
, "Got unexpect width %u.\n", devmode
.dmPelsWidth
);
3158 ok(devmode
.dmPelsHeight
== screen_height
, "Got unexpect height %u.\n", devmode
.dmPelsHeight
);
3161 DestroyWindow(device_window
);
3162 DestroyWindow(focus_window
);
3163 IDirect3D9_Release(d3d9
);
3165 memset(&devmode
, 0, sizeof(devmode
));
3166 devmode
.dmSize
= sizeof(devmode
);
3167 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3168 ok(ret
, "Failed to get display mode.\n");
3169 ok(devmode
.dmPelsWidth
== screen_width
, "Got unexpect width %u.\n", devmode
.dmPelsWidth
);
3170 ok(devmode
.dmPelsHeight
== screen_height
, "Got unexpect height %u.\n", devmode
.dmPelsHeight
);
3173 static void test_device_window_reset(void)
3175 RECT fullscreen_rect
, device_rect
, r
;
3176 IDirect3DDevice9
*device
;
3183 wc
.lpfnWndProc
= test_proc
;
3184 wc
.lpszClassName
= "d3d9_test_wndproc_wc";
3185 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
3187 focus_window
= CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
3188 0, 0, screen_width
/ 2, screen_height
/ 2, 0, 0, 0, 0);
3189 device_window
= CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
3190 0, 0, screen_width
/ 2, screen_height
/ 2, 0, 0, 0, 0);
3191 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
3192 ok(!!d3d9
, "Failed to create a D3D object.\n");
3194 SetRect(&fullscreen_rect
, 0, 0, screen_width
, screen_height
);
3195 GetWindowRect(device_window
, &device_rect
);
3197 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3198 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3199 (LONG_PTR
)test_proc
, proc
);
3200 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3201 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3202 (LONG_PTR
)test_proc
, proc
);
3204 device
= create_device(d3d9
, NULL
, focus_window
, FALSE
);
3207 skip("Failed to create a D3D device, skipping tests.\n");
3211 GetWindowRect(focus_window
, &r
);
3212 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3213 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
3214 r
.left
, r
.top
, r
.right
, r
.bottom
);
3215 GetWindowRect(device_window
, &r
);
3216 ok(EqualRect(&r
, &device_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3217 device_rect
.left
, device_rect
.top
, device_rect
.right
, device_rect
.bottom
,
3218 r
.left
, r
.top
, r
.right
, r
.bottom
);
3220 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3221 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3222 (LONG_PTR
)test_proc
, proc
);
3223 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3224 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3225 (LONG_PTR
)test_proc
, proc
);
3227 hr
= reset_device(device
, device_window
, FALSE
);
3228 ok(SUCCEEDED(hr
), "Failed to reset device.\n");
3230 GetWindowRect(focus_window
, &r
);
3231 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3232 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
3233 r
.left
, r
.top
, r
.right
, r
.bottom
);
3234 GetWindowRect(device_window
, &r
);
3235 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3236 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
3237 r
.left
, r
.top
, r
.right
, r
.bottom
);
3239 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3240 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3241 (LONG_PTR
)test_proc
, proc
);
3242 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3243 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3244 (LONG_PTR
)test_proc
, proc
);
3246 ref
= IDirect3DDevice9_Release(device
);
3247 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
3250 IDirect3D9_Release(d3d9
);
3251 DestroyWindow(device_window
);
3252 DestroyWindow(focus_window
);
3253 UnregisterClassA("d3d9_test_wndproc_wc", GetModuleHandleA(NULL
));
3256 static void test_reset_resources(void)
3258 IDirect3DSurface9
*surface
, *rt
;
3259 IDirect3DTexture9
*texture
;
3260 IDirect3DDevice9
*device
;
3268 window
= CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW
,
3269 0, 0, 640, 480, 0, 0, 0, 0);
3270 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
3271 ok(!!d3d9
, "Failed to create a D3D object.\n");
3273 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
3275 skip("Failed to create a D3D device, skipping tests.\n");
3279 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
3280 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
3282 hr
= IDirect3DDevice9_CreateDepthStencilSurface(device
, 128, 128,
3283 D3DFMT_D24S8
, D3DMULTISAMPLE_NONE
, 0, TRUE
, &surface
, NULL
);
3284 ok(SUCCEEDED(hr
), "Failed to create depth/stencil surface, hr %#x.\n", hr
);
3285 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, surface
);
3286 ok(SUCCEEDED(hr
), "Failed to set depth/stencil surface, hr %#x.\n", hr
);
3287 IDirect3DSurface9_Release(surface
);
3289 for (i
= 0; i
< caps
.NumSimultaneousRTs
; ++i
)
3291 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
,
3292 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &texture
, NULL
);
3293 ok(SUCCEEDED(hr
), "Failed to create render target texture %u, hr %#x.\n", i
, hr
);
3294 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
3295 ok(SUCCEEDED(hr
), "Failed to get surface %u, hr %#x.\n", i
, hr
);
3296 IDirect3DTexture9_Release(texture
);
3297 hr
= IDirect3DDevice9_SetRenderTarget(device
, i
, surface
);
3298 ok(SUCCEEDED(hr
), "Failed to set render target surface %u, hr %#x.\n", i
, hr
);
3299 IDirect3DSurface9_Release(surface
);
3302 hr
= reset_device(device
, device_window
, TRUE
);
3303 ok(SUCCEEDED(hr
), "Failed to reset device.\n");
3305 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &rt
);
3306 ok(SUCCEEDED(hr
), "Failed to get back buffer, hr %#x.\n", hr
);
3307 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &surface
);
3308 ok(SUCCEEDED(hr
), "Failed to get render target surface, hr %#x.\n", hr
);
3309 ok(surface
== rt
, "Got unexpected surface %p for render target.\n", surface
);
3310 IDirect3DSurface9_Release(surface
);
3311 IDirect3DSurface9_Release(rt
);
3313 for (i
= 1; i
< caps
.NumSimultaneousRTs
; ++i
)
3315 hr
= IDirect3DDevice9_GetRenderTarget(device
, i
, &surface
);
3316 ok(hr
== D3DERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
3319 ref
= IDirect3DDevice9_Release(device
);
3320 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
3323 IDirect3D9_Release(d3d9
);
3324 DestroyWindow(window
);
3327 static void test_set_rt_vp_scissor(void)
3329 IDirect3DStateBlock9
*stateblock
;
3330 IDirect3DDevice9
*device
;
3331 IDirect3DSurface9
*rt
;
3339 window
= CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW
,
3340 0, 0, 640, 480, 0, 0, 0, 0);
3341 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
3342 ok(!!d3d9
, "Failed to create a D3D object.\n");
3343 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
3345 skip("Failed to create a D3D device, skipping tests.\n");
3346 DestroyWindow(window
);
3350 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 128, 128, D3DFMT_A8R8G8B8
,
3351 D3DMULTISAMPLE_NONE
, 0, FALSE
, &rt
, NULL
);
3352 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
3354 hr
= IDirect3DDevice9_GetViewport(device
, &vp
);
3355 ok(SUCCEEDED(hr
), "Failed to get viewport, hr %#x.\n", hr
);
3356 ok(!vp
.X
, "Got unexpected vp.X %u.\n", vp
.X
);
3357 ok(!vp
.Y
, "Got unexpected vp.Y %u.\n", vp
.Y
);
3358 ok(vp
.Width
== screen_width
, "Got unexpected vp.Width %u.\n", vp
.Width
);
3359 ok(vp
.Height
== screen_height
, "Got unexpected vp.Height %u.\n", vp
.Height
);
3360 ok(vp
.MinZ
== 0.0f
, "Got unexpected vp.MinZ %.8e.\n", vp
.MinZ
);
3361 ok(vp
.MaxZ
== 1.0f
, "Got unexpected vp.MaxZ %.8e.\n", vp
.MaxZ
);
3363 hr
= IDirect3DDevice9_GetScissorRect(device
, &rect
);
3364 ok(SUCCEEDED(hr
), "Failed to get scissor rect, hr %#x.\n", hr
);
3365 ok(rect
.left
== 0 && rect
.top
== 0 && rect
.right
== screen_width
&& rect
.bottom
== screen_height
,
3366 "Got unexpected scissor rect {%d, %d, %d, %d}.\n",
3367 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3369 hr
= IDirect3DDevice9_BeginStateBlock(device
);
3370 ok(SUCCEEDED(hr
), "Failed to begin stateblock, hr %#x.\n", hr
);
3372 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt
);
3373 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
3375 hr
= IDirect3DDevice9_EndStateBlock(device
, &stateblock
);
3376 ok(SUCCEEDED(hr
), "Failed to end stateblock, hr %#x.\n", hr
);
3377 IDirect3DStateBlock9_Release(stateblock
);
3379 hr
= IDirect3DDevice9_GetViewport(device
, &vp
);
3380 ok(SUCCEEDED(hr
), "Failed to get viewport, hr %#x.\n", hr
);
3381 ok(!vp
.X
, "Got unexpected vp.X %u.\n", vp
.X
);
3382 ok(!vp
.Y
, "Got unexpected vp.Y %u.\n", vp
.Y
);
3383 ok(vp
.Width
== 128, "Got unexpected vp.Width %u.\n", vp
.Width
);
3384 ok(vp
.Height
== 128, "Got unexpected vp.Height %u.\n", vp
.Height
);
3385 ok(vp
.MinZ
== 0.0f
, "Got unexpected vp.MinZ %.8e.\n", vp
.MinZ
);
3386 ok(vp
.MaxZ
== 1.0f
, "Got unexpected vp.MaxZ %.8e.\n", vp
.MaxZ
);
3388 hr
= IDirect3DDevice9_GetScissorRect(device
, &rect
);
3389 ok(SUCCEEDED(hr
), "Failed to get scissor rect, hr %#x.\n", hr
);
3390 ok(rect
.left
== 0 && rect
.top
== 0 && rect
.right
== 128 && rect
.bottom
== 128,
3391 "Got unexpected scissor rect {%d, %d, %d, %d}.\n",
3392 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3394 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt
);
3395 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
3403 hr
= IDirect3DDevice9_SetViewport(device
, &vp
);
3404 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
3406 SetRect(&rect
, 50, 60, 70, 80);
3407 hr
= IDirect3DDevice9_SetScissorRect(device
, &rect
);
3408 ok(SUCCEEDED(hr
), "Failed to set scissor rect, hr %#x.\n", hr
);
3410 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt
);
3411 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
3413 hr
= IDirect3DDevice9_GetViewport(device
, &vp
);
3414 ok(SUCCEEDED(hr
), "Failed to get viewport, hr %#x.\n", hr
);
3415 ok(!vp
.X
, "Got unexpected vp.X %u.\n", vp
.X
);
3416 ok(!vp
.Y
, "Got unexpected vp.Y %u.\n", vp
.Y
);
3417 ok(vp
.Width
== 128, "Got unexpected vp.Width %u.\n", vp
.Width
);
3418 ok(vp
.Height
== 128, "Got unexpected vp.Height %u.\n", vp
.Height
);
3419 ok(vp
.MinZ
== 0.0f
, "Got unexpected vp.MinZ %.8e.\n", vp
.MinZ
);
3420 ok(vp
.MaxZ
== 1.0f
, "Got unexpected vp.MaxZ %.8e.\n", vp
.MaxZ
);
3422 hr
= IDirect3DDevice9_GetScissorRect(device
, &rect
);
3423 ok(SUCCEEDED(hr
), "Failed to get scissor rect, hr %#x.\n", hr
);
3424 ok(rect
.left
== 0 && rect
.top
== 0 && rect
.right
== 128 && rect
.bottom
== 128,
3425 "Got unexpected scissor rect {%d, %d, %d, %d}.\n",
3426 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3428 IDirect3DSurface9_Release(rt
);
3429 refcount
= IDirect3DDevice9_Release(device
);
3430 ok(!refcount
, "Device has %u references left.\n", refcount
);
3431 IDirect3D9_Release(d3d9
);
3432 DestroyWindow(window
);
3435 static void test_volume_get_container(void)
3437 IDirect3DVolumeTexture9
*texture
= NULL
;
3438 IDirect3DVolume9
*volume
= NULL
;
3439 IDirect3DDevice9
*device
;
3440 IUnknown
*container
;
3447 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
3448 0, 0, 640, 480, 0, 0, 0, 0);
3449 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
3450 ok(!!d3d9
, "Failed to create a D3D object.\n");
3451 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
3453 skip("Failed to create a D3D device, skipping tests.\n");
3454 IDirect3D9_Release(d3d9
);
3455 DestroyWindow(window
);
3459 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
3460 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
3461 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
))
3463 skip("No volume texture support, skipping tests.\n");
3464 IDirect3DDevice9_Release(device
);
3465 IDirect3D9_Release(d3d9
);
3466 DestroyWindow(window
);
3470 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 128, 128, 128, 1, 0,
3471 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &texture
, 0);
3472 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
3473 ok(!!texture
, "Got unexpected texture %p.\n", texture
);
3475 hr
= IDirect3DVolumeTexture9_GetVolumeLevel(texture
, 0, &volume
);
3476 ok(SUCCEEDED(hr
), "Failed to get volume level, hr %#x.\n", hr
);
3477 ok(!!volume
, "Got unexpected volume %p.\n", volume
);
3479 /* These should work... */
3481 hr
= IDirect3DVolume9_GetContainer(volume
, &IID_IUnknown
, (void **)&container
);
3482 ok(SUCCEEDED(hr
), "Failed to get volume container, hr %#x.\n", hr
);
3483 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
3484 IUnknown_Release(container
);
3487 hr
= IDirect3DVolume9_GetContainer(volume
, &IID_IDirect3DResource9
, (void **)&container
);
3488 ok(SUCCEEDED(hr
), "Failed to get volume container, hr %#x.\n", hr
);
3489 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
3490 IUnknown_Release(container
);
3493 hr
= IDirect3DVolume9_GetContainer(volume
, &IID_IDirect3DBaseTexture9
, (void **)&container
);
3494 ok(SUCCEEDED(hr
), "Failed to get volume container, hr %#x.\n", hr
);
3495 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
3496 IUnknown_Release(container
);
3499 hr
= IDirect3DVolume9_GetContainer(volume
, &IID_IDirect3DVolumeTexture9
, (void **)&container
);
3500 ok(SUCCEEDED(hr
), "Failed to get volume container, hr %#x.\n", hr
);
3501 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
3502 IUnknown_Release(container
);
3504 /* ...and this one shouldn't. This should return E_NOINTERFACE and set container to NULL. */
3505 hr
= IDirect3DVolume9_GetContainer(volume
, &IID_IDirect3DVolume9
, (void **)&container
);
3506 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
3507 ok(!container
, "Got unexpected container %p.\n", container
);
3509 IDirect3DVolume9_Release(volume
);
3510 IDirect3DVolumeTexture9_Release(texture
);
3511 refcount
= IDirect3DDevice9_Release(device
);
3512 ok(!refcount
, "Device has %u references left.\n", refcount
);
3513 IDirect3D9_Release(d3d9
);
3514 DestroyWindow(window
);
3517 static void test_volume_resource(void)
3519 IDirect3DVolumeTexture9
*texture
;
3520 IDirect3DResource9
*resource
;
3521 IDirect3DVolume9
*volume
;
3522 IDirect3DDevice9
*device
;
3529 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
3530 0, 0, 640, 480, 0, 0, 0, 0);
3531 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
3532 ok(!!d3d9
, "Failed to create a D3D object.\n");
3533 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
3535 skip("Failed to create a D3D device, skipping tests.\n");
3536 IDirect3D9_Release(d3d9
);
3537 DestroyWindow(window
);
3541 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
3542 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
3543 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
))
3545 skip("No volume texture support, skipping tests.\n");
3546 IDirect3DDevice9_Release(device
);
3547 IDirect3D9_Release(d3d9
);
3548 DestroyWindow(window
);
3552 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 128, 128, 128, 1, 0,
3553 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &texture
, 0);
3554 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
3555 hr
= IDirect3DVolumeTexture9_GetVolumeLevel(texture
, 0, &volume
);
3556 ok(SUCCEEDED(hr
), "Failed to get volume level, hr %#x.\n", hr
);
3557 IDirect3DVolumeTexture9_Release(texture
);
3559 hr
= IDirect3DVolume9_QueryInterface(volume
, &IID_IDirect3DResource9
, (void **)&resource
);
3560 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
3562 IDirect3DVolume9_Release(volume
);
3563 refcount
= IDirect3DDevice9_Release(device
);
3564 ok(!refcount
, "Device has %u references left.\n", refcount
);
3565 IDirect3D9_Release(d3d9
);
3566 DestroyWindow(window
);
3569 static void test_vb_lock_flags(void)
3574 const char *debug_string
;
3575 HRESULT win7_result
;
3579 {D3DLOCK_READONLY
, "D3DLOCK_READONLY", D3D_OK
},
3580 {D3DLOCK_DISCARD
, "D3DLOCK_DISCARD", D3D_OK
},
3581 {D3DLOCK_NOOVERWRITE
, "D3DLOCK_NOOVERWRITE", D3D_OK
},
3582 {D3DLOCK_NOOVERWRITE
| D3DLOCK_DISCARD
, "D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD", D3D_OK
},
3583 {D3DLOCK_NOOVERWRITE
| D3DLOCK_READONLY
, "D3DLOCK_NOOVERWRITE | D3DLOCK_READONLY", D3D_OK
},
3584 {D3DLOCK_READONLY
| D3DLOCK_DISCARD
, "D3DLOCK_READONLY | D3DLOCK_DISCARD", D3DERR_INVALIDCALL
},
3585 /* Completely bogus flags aren't an error. */
3586 {0xdeadbeef, "0xdeadbeef", D3DERR_INVALIDCALL
},
3588 IDirect3DVertexBuffer9
*buffer
;
3589 IDirect3DDevice9
*device
;
3597 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
3598 0, 0, 640, 480, 0, 0, 0, 0);
3599 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
3600 ok(!!d3d9
, "Failed to create a D3D object.\n");
3601 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
3603 skip("Failed to create a D3D device, skipping tests.\n");
3604 IDirect3D9_Release(d3d9
);
3605 DestroyWindow(window
);
3609 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, 1024, D3DUSAGE_DYNAMIC
, 0, D3DPOOL_DEFAULT
, &buffer
, NULL
);
3610 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
3612 for (i
= 0; i
< (sizeof(test_data
) / sizeof(*test_data
)); ++i
)
3614 hr
= IDirect3DVertexBuffer9_Lock(buffer
, 0, 0, &data
, test_data
[i
].flags
);
3615 /* Windows XP always returns D3D_OK even with flags that don't make
3616 * sense. Windows 7 returns an error. At least one game (Shaiya)
3617 * depends on the Windows XP result, so mark the Windows 7 behavior as
3619 ok(hr
== D3D_OK
|| broken(hr
== test_data
[i
].win7_result
), "Got unexpected hr %#x for %s.\n",
3620 hr
, test_data
[i
].debug_string
);
3623 ok(!!data
, "Got unexpected data %p.\n", data
);
3624 hr
= IDirect3DVertexBuffer9_Unlock(buffer
);
3625 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
3629 IDirect3DVertexBuffer9_Release(buffer
);
3630 refcount
= IDirect3DDevice9_Release(device
);
3631 ok(!refcount
, "Device has %u references left.\n", refcount
);
3632 IDirect3D9_Release(d3d9
);
3633 DestroyWindow(window
);
3636 static const char *debug_d3dpool(D3DPOOL pool
)
3640 case D3DPOOL_DEFAULT
:
3641 return "D3DPOOL_DEFAULT";
3642 case D3DPOOL_SYSTEMMEM
:
3643 return "D3DPOOL_SYSTEMMEM";
3644 case D3DPOOL_SCRATCH
:
3645 return "D3DPOOL_SCRATCH";
3646 case D3DPOOL_MANAGED
:
3647 return "D3DPOOL_MANAGED";
3649 return "unknown pool";
3653 static void test_vertex_buffer_alignment(void)
3655 static const D3DPOOL pools
[] = {D3DPOOL_DEFAULT
, D3DPOOL_SYSTEMMEM
, D3DPOOL_SCRATCH
, D3DPOOL_MANAGED
};
3656 static const DWORD sizes
[] = {1, 4, 16, 17, 32, 33, 64, 65, 1024, 1025, 1048576, 1048577};
3657 IDirect3DVertexBuffer9
*buffer
= NULL
;
3658 const unsigned int align
= 16;
3659 IDirect3DDevice9
*device
;
3667 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
3668 0, 0, 640, 480, 0, 0, 0, 0);
3669 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
3670 ok(!!d3d9
, "Failed to create a D3D object.\n");
3671 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
3673 skip("Failed to create a D3D device, skipping tests.\n");
3674 IDirect3D9_Release(d3d9
);
3675 DestroyWindow(window
);
3679 for (i
= 0; i
< (sizeof(sizes
) / sizeof(*sizes
)); ++i
)
3681 for (j
= 0; j
< (sizeof(pools
) / sizeof(*pools
)); ++j
)
3683 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, sizes
[i
], 0, 0, pools
[j
], &buffer
, NULL
);
3684 if (pools
[j
] == D3DPOOL_SCRATCH
)
3685 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x trying to create a D3DPOOL_SCRATCH buffer.\n", hr
);
3687 ok(SUCCEEDED(hr
), "Failed to create vertex buffer in pool %s with size %u, hr %#x.\n",
3688 debug_d3dpool(pools
[j
]), sizes
[i
], hr
);
3692 hr
= IDirect3DVertexBuffer9_Lock(buffer
, 0, 0, &data
, 0);
3693 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
3694 ok(!((DWORD_PTR
)data
& (align
- 1)),
3695 "Vertex buffer start address %p is not %u byte aligned (size %u, pool %s).\n",
3696 data
, align
, sizes
[i
], debug_d3dpool(pools
[j
]));
3697 hr
= IDirect3DVertexBuffer9_Unlock(buffer
);
3698 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
3699 IDirect3DVertexBuffer9_Release(buffer
);
3703 refcount
= IDirect3DDevice9_Release(device
);
3704 ok(!refcount
, "Device has %u references left.\n", refcount
);
3705 IDirect3D9_Release(d3d9
);
3706 DestroyWindow(window
);
3709 static void test_query_support(void)
3711 static const D3DQUERYTYPE queries
[] =
3713 D3DQUERYTYPE_VCACHE
,
3714 D3DQUERYTYPE_RESOURCEMANAGER
,
3715 D3DQUERYTYPE_VERTEXSTATS
,
3717 D3DQUERYTYPE_OCCLUSION
,
3718 D3DQUERYTYPE_TIMESTAMP
,
3719 D3DQUERYTYPE_TIMESTAMPDISJOINT
,
3720 D3DQUERYTYPE_TIMESTAMPFREQ
,
3721 D3DQUERYTYPE_PIPELINETIMINGS
,
3722 D3DQUERYTYPE_INTERFACETIMINGS
,
3723 D3DQUERYTYPE_VERTEXTIMINGS
,
3724 D3DQUERYTYPE_PIXELTIMINGS
,
3725 D3DQUERYTYPE_BANDWIDTHTIMINGS
,
3726 D3DQUERYTYPE_CACHEUTILIZATION
,
3728 IDirect3DQuery9
*query
= NULL
;
3729 IDirect3DDevice9
*device
;
3737 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
3738 0, 0, 640, 480, 0, 0, 0, 0);
3739 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
3740 ok(!!d3d9
, "Failed to create a D3D object.\n");
3741 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
3743 skip("Failed to create a D3D device, skipping tests.\n");
3744 IDirect3D9_Release(d3d9
);
3745 DestroyWindow(window
);
3749 for (i
= 0; i
< sizeof(queries
) / sizeof(*queries
); ++i
)
3751 hr
= IDirect3DDevice9_CreateQuery(device
, queries
[i
], NULL
);
3752 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "Got unexpected hr %#x for query %#x.\n", hr
, queries
[i
]);
3754 supported
= hr
== D3D_OK
;
3756 hr
= IDirect3DDevice9_CreateQuery(device
, queries
[i
], &query
);
3757 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "Got unexpected hr %#x for query %#x.\n", hr
, queries
[i
]);
3759 ok(!supported
|| query
, "Query %#x was claimed to be supported, but can't be created.\n", queries
[i
]);
3760 ok(supported
|| !query
, "Query %#x was claimed not to be supported, but can be created.\n", queries
[i
]);
3764 IDirect3DQuery9_Release(query
);
3769 refcount
= IDirect3DDevice9_Release(device
);
3770 ok(!refcount
, "Device has %u references left.\n", refcount
);
3771 IDirect3D9_Release(d3d9
);
3772 DestroyWindow(window
);
3775 static void test_occlusion_query_states(void)
3777 static const float point
[3] = {0.0, 0.0, 0.0};
3778 IDirect3DQuery9
*query
= NULL
;
3779 unsigned int data_size
, i
;
3780 IDirect3DDevice9
*device
;
3787 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
3788 0, 0, 640, 480, 0, 0, 0, 0);
3789 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
3790 ok(!!d3d9
, "Failed to create a D3D object.\n");
3791 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
3793 skip("Failed to create a D3D device, skipping tests.\n");
3794 IDirect3D9_Release(d3d9
);
3795 DestroyWindow(window
);
3799 hr
= IDirect3DDevice9_CreateQuery(device
, D3DQUERYTYPE_OCCLUSION
, &query
);
3800 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "Got unexpected hr %#x.\n", hr
);
3803 skip("Occlusion queries are not supported, skipping tests.\n");
3804 IDirect3DDevice9_Release(device
);
3805 IDirect3D9_Release(d3d9
);
3806 DestroyWindow(window
);
3810 data_size
= IDirect3DQuery9_GetDataSize(query
);
3811 data
= HeapAlloc(GetProcessHeap(), 0, data_size
);
3813 hr
= IDirect3DQuery9_GetData(query
, NULL
, 0, D3DGETDATA_FLUSH
);
3814 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
3815 hr
= IDirect3DQuery9_GetData(query
, data
, data_size
, D3DGETDATA_FLUSH
);
3816 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
3818 hr
= IDirect3DQuery9_Issue(query
, D3DISSUE_END
);
3819 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3820 hr
= IDirect3DQuery9_Issue(query
, D3DISSUE_BEGIN
);
3821 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3822 hr
= IDirect3DQuery9_Issue(query
, D3DISSUE_BEGIN
);
3823 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3825 *((DWORD
*)data
) = 0x12345678;
3826 hr
= IDirect3DQuery9_GetData(query
, NULL
, 0, D3DGETDATA_FLUSH
);
3827 ok(hr
== S_FALSE
|| hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3828 hr
= IDirect3DQuery9_GetData(query
, data
, data_size
, D3DGETDATA_FLUSH
);
3829 ok(hr
== S_FALSE
|| hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3831 ok(!*(DWORD
*)data
, "Got unexpected query result %u.\n", *(DWORD
*)data
);
3833 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
3834 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
3835 hr
= IDirect3DDevice9_BeginScene(device
);
3836 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3837 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_POINTLIST
, 1, point
, 3 * sizeof(float));
3838 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3839 hr
= IDirect3DDevice9_EndScene(device
);
3840 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3842 hr
= IDirect3DQuery9_Issue(query
, D3DISSUE_END
);
3843 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3844 for (i
= 0; i
< 500; ++i
)
3846 if ((hr
= IDirect3DQuery9_GetData(query
, NULL
, 0, D3DGETDATA_FLUSH
)) != S_FALSE
)
3850 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
3852 hr
= IDirect3DQuery9_GetData(query
, data
, data_size
, D3DGETDATA_FLUSH
);
3853 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
3854 hr
= IDirect3DQuery9_GetData(query
, data
, data_size
, D3DGETDATA_FLUSH
);
3855 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
3857 hr
= IDirect3DQuery9_Issue(query
, D3DISSUE_BEGIN
);
3858 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3859 hr
= IDirect3DQuery9_Issue(query
, D3DISSUE_END
);
3860 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3861 hr
= IDirect3DQuery9_Issue(query
, D3DISSUE_END
);
3862 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3864 HeapFree(GetProcessHeap(), 0, data
);
3865 IDirect3DQuery9_Release(query
);
3866 refcount
= IDirect3DDevice9_Release(device
);
3867 ok(!refcount
, "Device has %u references left.\n", refcount
);
3868 IDirect3D9_Release(d3d9
);
3869 DestroyWindow(window
);
3872 static void test_get_set_vertex_shader(void)
3874 IDirect3DVertexShader9
*current_shader
= NULL
;
3875 IDirect3DVertexShader9
*shader
= NULL
;
3876 IDirect3DDevice9
*device
;
3883 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
3884 0, 0, 640, 480, 0, 0, 0, 0);
3885 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
3886 ok(!!d3d
, "Failed to create a D3D object.\n");
3887 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
3889 skip("Failed to create a D3D device, skipping tests.\n");
3890 IDirect3D9_Release(d3d
);
3891 DestroyWindow(window
);
3895 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
3896 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
3897 if (!(caps
.VertexShaderVersion
& 0xffff))
3899 skip("No vertex shader support, skipping tests.\n");
3900 IDirect3DDevice9_Release(device
);
3901 IDirect3D9_Release(d3d
);
3902 DestroyWindow(window
);
3906 hr
= IDirect3DDevice9_CreateVertexShader(device
, simple_vs
, &shader
);
3907 ok(SUCCEEDED(hr
), "Failed to create shader, hr %#x.\n", hr
);
3908 ok(!!shader
, "Got unexpected shader %p.\n", shader
);
3910 /* SetVertexShader() should not touch the shader's refcount. */
3911 i
= get_refcount((IUnknown
*)shader
);
3912 hr
= IDirect3DDevice9_SetVertexShader(device
, shader
);
3913 refcount
= get_refcount((IUnknown
*)shader
);
3914 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
3915 ok(refcount
== i
, "Got unexpected refcount %u, expected %u.\n", refcount
, i
);
3917 /* GetVertexShader() should increase the shader's refcount by one. */
3919 hr
= IDirect3DDevice9_GetVertexShader(device
, ¤t_shader
);
3920 refcount
= get_refcount((IUnknown
*)shader
);
3921 ok(SUCCEEDED(hr
), "Failed to get vertex shader, hr %#x.\n", hr
);
3922 ok(refcount
== i
, "Got unexpected refcount %u, expected %u.\n", refcount
, i
);
3923 ok(current_shader
== shader
, "Got unexpected shader %p, expected %p.\n", current_shader
, shader
);
3924 IDirect3DVertexShader9_Release(current_shader
);
3926 IDirect3DVertexShader9_Release(shader
);
3927 refcount
= IDirect3DDevice9_Release(device
);
3928 ok(!refcount
, "Device has %u references left.\n", refcount
);
3929 IDirect3D9_Release(d3d
);
3930 DestroyWindow(window
);
3933 static void test_vertex_shader_constant(void)
3935 static const float d
[16] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
3936 static const float c
[4] = {0.0, 0.0, 0.0, 0.0};
3937 IDirect3DDevice9
*device
;
3945 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
3946 0, 0, 640, 480, 0, 0, 0, 0);
3947 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
3948 ok(!!d3d
, "Failed to create a D3D object.\n");
3949 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
3951 skip("Failed to create a D3D device, skipping tests.\n");
3952 IDirect3D9_Release(d3d
);
3953 DestroyWindow(window
);
3957 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
3958 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
3959 if (!(caps
.VertexShaderVersion
& 0xffff))
3961 skip("No vertex shader support, skipping tests.\n");
3962 IDirect3DDevice9_Release(device
);
3963 IDirect3D9_Release(d3d
);
3964 DestroyWindow(window
);
3967 consts
= caps
.MaxVertexShaderConst
;
3969 /* A simple check that the stuff works at all. */
3970 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 0, c
, 1);
3971 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3973 /* Test corner cases: Write to const MAX - 1, MAX, MAX + 1, and writing 4
3974 * consts from MAX - 1. */
3975 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, consts
- 1, c
, 1);
3976 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3977 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, consts
+ 0, c
, 1);
3978 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3979 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, consts
+ 1, c
, 1);
3980 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3981 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, consts
- 1, d
, 4);
3982 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3985 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, -1, c
, 1);
3986 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3988 refcount
= IDirect3DDevice9_Release(device
);
3989 ok(!refcount
, "Device has %u references left.\n", refcount
);
3990 IDirect3D9_Release(d3d
);
3991 DestroyWindow(window
);
3994 static void test_get_set_pixel_shader(void)
3996 IDirect3DPixelShader9
*current_shader
= NULL
;
3997 IDirect3DPixelShader9
*shader
= NULL
;
3998 IDirect3DDevice9
*device
;
4005 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
4006 0, 0, 640, 480, 0, 0, 0, 0);
4007 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
4008 ok(!!d3d
, "Failed to create a D3D object.\n");
4009 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
4011 skip("Failed to create a D3D device, skipping tests.\n");
4012 IDirect3D9_Release(d3d
);
4013 DestroyWindow(window
);
4017 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
4018 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
4019 if (!(caps
.PixelShaderVersion
& 0xffff))
4021 skip("No pixel shader support, skipping tests.\n");
4022 IDirect3DDevice9_Release(device
);
4023 IDirect3D9_Release(d3d
);
4024 DestroyWindow(window
);
4028 hr
= IDirect3DDevice9_CreatePixelShader(device
, simple_ps
, &shader
);
4029 ok(SUCCEEDED(hr
), "Failed to create shader, hr %#x.\n", hr
);
4030 ok(!!shader
, "Got unexpected shader %p.\n", shader
);
4032 /* SetPixelShader() should not touch the shader's refcount. */
4033 i
= get_refcount((IUnknown
*)shader
);
4034 hr
= IDirect3DDevice9_SetPixelShader(device
, shader
);
4035 refcount
= get_refcount((IUnknown
*)shader
);
4036 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
4037 ok(refcount
== i
, "Got unexpected refcount %u, expected %u.\n", refcount
, i
);
4039 /* GetPixelShader() should increase the shader's refcount by one. */
4041 hr
= IDirect3DDevice9_GetPixelShader(device
, ¤t_shader
);
4042 refcount
= get_refcount((IUnknown
*)shader
);
4043 ok(SUCCEEDED(hr
), "Failed to get pixel shader, hr %#x.\n", hr
);
4044 ok(refcount
== i
, "Got unexpected refcount %u, expected %u.\n", refcount
, i
);
4045 ok(current_shader
== shader
, "Got unexpected shader %p, expected %p.\n", current_shader
, shader
);
4046 IDirect3DPixelShader9_Release(current_shader
);
4048 IDirect3DPixelShader9_Release(shader
);
4049 refcount
= IDirect3DDevice9_Release(device
);
4050 ok(!refcount
, "Device has %u references left.\n", refcount
);
4051 IDirect3D9_Release(d3d
);
4052 DestroyWindow(window
);
4055 static void test_pixel_shader_constant(void)
4057 static const float d
[16] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
4058 static const float c
[4] = {0.0, 0.0, 0.0, 0.0};
4059 IDirect3DDevice9
*device
;
4067 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
4068 0, 0, 640, 480, 0, 0, 0, 0);
4069 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
4070 ok(!!d3d
, "Failed to create a D3D object.\n");
4071 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
4073 skip("Failed to create a D3D device, skipping tests.\n");
4074 IDirect3D9_Release(d3d
);
4075 DestroyWindow(window
);
4079 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
4080 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
4081 if (!(caps
.PixelShaderVersion
& 0xffff))
4083 skip("No pixel shader support, skipping tests.\n");
4084 IDirect3DDevice9_Release(device
);
4085 IDirect3D9_Release(d3d
);
4086 DestroyWindow(window
);
4090 /* A simple check that the stuff works at all. */
4091 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 0, c
, 1);
4092 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4094 /* Is there really no max pixel shader constant value??? Test how far I can go. */
4095 while (SUCCEEDED(IDirect3DDevice9_SetPixelShaderConstantF(device
, consts
++, c
, 1)));
4096 consts
= consts
- 1;
4097 trace("SetPixelShaderConstantF was able to set %u shader constants.\n", consts
);
4099 /* Test corner cases: Write 4 consts from MAX - 1, everything else is
4100 * pointless given the way the constant limit was determined. */
4101 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, consts
- 1, d
, 4);
4102 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4105 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, -1, c
, 1);
4106 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4108 refcount
= IDirect3DDevice9_Release(device
);
4109 ok(!refcount
, "Device has %u references left.\n", refcount
);
4110 IDirect3D9_Release(d3d
);
4111 DestroyWindow(window
);
4114 static void test_wrong_shader(void)
4116 static const DWORD vs_3_0
[] =
4118 0xfffe0300, /* vs_3_0 */
4119 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
4120 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
4121 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
4122 0x0000ffff, /* end */
4126 float4
main(const float4 color
: COLOR
) : SV_TARGET
4135 static const DWORD ps_4_0
[] =
4137 0x43425844, 0x4da9446f, 0xfbe1f259, 0x3fdb3009, 0x517521fa, 0x00000001, 0x000001ac, 0x00000005,
4138 0x00000034, 0x0000008c, 0x000000bc, 0x000000f0, 0x00000130, 0x46454452, 0x00000050, 0x00000000,
4139 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100, 0x0000001c, 0x7263694d, 0x666f736f,
4140 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x39207265, 0x2e39322e,
4141 0x2e323539, 0x31313133, 0xababab00, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
4142 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
4143 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4144 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4145 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
4146 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453, 0x00000074, 0x00000002, 0x00000000,
4147 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000,
4148 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
4149 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
4150 0x00000000, 0x00000000, 0x00000000,
4153 IDirect3DVertexShader9
*vs
= NULL
;
4154 IDirect3DPixelShader9
*ps
= NULL
;
4155 IDirect3DDevice9
*device
;
4162 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
4163 0, 0, 640, 480, 0, 0, 0, 0);
4164 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
4165 ok(!!d3d
, "Failed to create a D3D object.\n");
4166 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
4168 skip("Failed to create a D3D device, skipping tests.\n");
4169 IDirect3D9_Release(d3d
);
4170 DestroyWindow(window
);
4174 /* These should always fail, regardless of supported shader version. */
4175 hr
= IDirect3DDevice9_CreateVertexShader(device
, simple_ps
, &vs
);
4176 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4177 hr
= IDirect3DDevice9_CreatePixelShader(device
, simple_vs
, &ps
);
4178 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4179 hr
= IDirect3DDevice9_CreatePixelShader(device
, ps_4_0
, &ps
);
4180 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4182 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
4183 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
4184 if (caps
.VertexShaderVersion
< D3DVS_VERSION(3, 0))
4186 hr
= IDirect3DDevice9_CreateVertexShader(device
, vs_3_0
, &vs
);
4187 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4190 skip("This GPU supports SM3, skipping unsupported shader test.\n");
4192 refcount
= IDirect3DDevice9_Release(device
);
4193 ok(!refcount
, "Device has %u references left.\n", refcount
);
4194 IDirect3D9_Release(d3d
);
4195 DestroyWindow(window
);
4198 /* Test the default texture stage state values */
4199 static void test_texture_stage_states(void)
4201 IDirect3DDevice9
*device
;
4210 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
4211 0, 0, 640, 480, 0, 0, 0, 0);
4212 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
4213 ok(!!d3d
, "Failed to create a D3D object.\n");
4214 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
4216 skip("Failed to create a D3D device, skipping tests.\n");
4217 IDirect3D9_Release(d3d
);
4218 DestroyWindow(window
);
4222 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
4223 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
4225 for (i
= 0; i
< caps
.MaxTextureBlendStages
; ++i
)
4227 hr
= IDirect3DDevice9_GetTextureStageState(device
, i
, D3DTSS_COLOROP
, &value
);
4228 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4229 ok(value
== (i
? D3DTOP_DISABLE
: D3DTOP_MODULATE
),
4230 "Got unexpected value %#x for D3DTSS_COLOROP, stage %u.\n", value
, i
);
4231 hr
= IDirect3DDevice9_GetTextureStageState(device
, i
, D3DTSS_COLORARG1
, &value
);
4232 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4233 ok(value
== D3DTA_TEXTURE
, "Got unexpected value %#x for D3DTSS_COLORARG1, stage %u.\n", value
, i
);
4234 hr
= IDirect3DDevice9_GetTextureStageState(device
, i
, D3DTSS_COLORARG2
, &value
);
4235 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4236 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_COLORARG2, stage %u.\n", value
, i
);
4237 hr
= IDirect3DDevice9_GetTextureStageState(device
, i
, D3DTSS_ALPHAOP
, &value
);
4238 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4239 ok(value
== (i
? D3DTOP_DISABLE
: D3DTOP_SELECTARG1
),
4240 "Got unexpected value %#x for D3DTSS_ALPHAOP, stage %u.\n", value
, i
);
4241 hr
= IDirect3DDevice9_GetTextureStageState(device
, i
, D3DTSS_ALPHAARG1
, &value
);
4242 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4243 ok(value
== D3DTA_TEXTURE
, "Got unexpected value %#x for D3DTSS_ALPHAARG1, stage %u.\n", value
, i
);
4244 hr
= IDirect3DDevice9_GetTextureStageState(device
, i
, D3DTSS_ALPHAARG2
, &value
);
4245 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4246 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_ALPHAARG2, stage %u.\n", value
, i
);
4247 hr
= IDirect3DDevice9_GetTextureStageState(device
, i
, D3DTSS_BUMPENVMAT00
, &value
);
4248 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4249 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVMAT00, stage %u.\n", value
, i
);
4250 hr
= IDirect3DDevice9_GetTextureStageState(device
, i
, D3DTSS_BUMPENVMAT01
, &value
);
4251 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4252 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVMAT01, stage %u.\n", value
, i
);
4253 hr
= IDirect3DDevice9_GetTextureStageState(device
, i
, D3DTSS_BUMPENVMAT10
, &value
);
4254 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4255 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVMAT10, stage %u.\n", value
, i
);
4256 hr
= IDirect3DDevice9_GetTextureStageState(device
, i
, D3DTSS_BUMPENVMAT11
, &value
);
4257 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4258 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVMAT11, stage %u.\n", value
, i
);
4259 hr
= IDirect3DDevice9_GetTextureStageState(device
, i
, D3DTSS_TEXCOORDINDEX
, &value
);
4260 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4261 ok(value
== i
, "Got unexpected value %#x for D3DTSS_TEXCOORDINDEX, stage %u.\n", value
, i
);
4262 hr
= IDirect3DDevice9_GetTextureStageState(device
, i
, D3DTSS_BUMPENVLSCALE
, &value
);
4263 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4264 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVLSCALE, stage %u.\n", value
, i
);
4265 hr
= IDirect3DDevice9_GetTextureStageState(device
, i
, D3DTSS_BUMPENVLOFFSET
, &value
);
4266 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4267 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVLOFFSET, stage %u.\n", value
, i
);
4268 hr
= IDirect3DDevice9_GetTextureStageState(device
, i
, D3DTSS_TEXTURETRANSFORMFLAGS
, &value
);
4269 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4270 ok(value
== D3DTTFF_DISABLE
,
4271 "Got unexpected value %#x for D3DTSS_TEXTURETRANSFORMFLAGS, stage %u.\n", value
, i
);
4272 hr
= IDirect3DDevice9_GetTextureStageState(device
, i
, D3DTSS_COLORARG0
, &value
);
4273 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4274 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_COLORARG0, stage %u.\n", value
, i
);
4275 hr
= IDirect3DDevice9_GetTextureStageState(device
, i
, D3DTSS_ALPHAARG0
, &value
);
4276 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4277 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_ALPHAARG0, stage %u.\n", value
, i
);
4278 hr
= IDirect3DDevice9_GetTextureStageState(device
, i
, D3DTSS_RESULTARG
, &value
);
4279 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4280 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_RESULTARG, stage %u.\n", value
, i
);
4281 hr
= IDirect3DDevice9_GetTextureStageState(device
, i
, D3DTSS_CONSTANT
, &value
);
4282 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4283 ok(!value
, "Got unexpected value %#x for D3DTSS_CONSTANT, stage %u.\n", value
, i
);
4286 refcount
= IDirect3DDevice9_Release(device
);
4287 ok(!refcount
, "Device has %u references left.\n", refcount
);
4288 IDirect3D9_Release(d3d
);
4289 DestroyWindow(window
);
4292 static void test_cube_texture_mipmap_gen(IDirect3DDevice9
*device
)
4294 IDirect3DCubeTexture9
*texture
;
4298 hr
= IDirect3DDevice9_GetDirect3D(device
, &d3d
);
4299 ok(SUCCEEDED(hr
), "Failed to get D3D, hr %#x.\n", hr
);
4300 hr
= IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
4301 D3DUSAGE_AUTOGENMIPMAP
, D3DRTYPE_CUBETEXTURE
, D3DFMT_X8R8G8B8
);
4302 IDirect3D9_Release(d3d
);
4305 skip("No cube mipmap generation support, skipping tests.\n");
4309 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 64, 0, (D3DUSAGE_RENDERTARGET
| D3DUSAGE_AUTOGENMIPMAP
),
4310 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &texture
, NULL
);
4311 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4312 IDirect3DCubeTexture9_Release(texture
);
4314 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 64, 0, D3DUSAGE_AUTOGENMIPMAP
,
4315 D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &texture
, NULL
);
4316 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4317 IDirect3DCubeTexture9_Release(texture
);
4320 static void test_cube_texture_levels(IDirect3DDevice9
*device
)
4322 IDirect3DCubeTexture9
*texture
;
4323 IDirect3DSurface9
*surface
;
4324 D3DSURFACE_DESC desc
;
4329 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
4330 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
4331 if (FAILED(IDirect3DDevice9_CreateCubeTexture(device
, 64, 0, 0,
4332 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &texture
, NULL
)))
4334 skip("Failed to create cube texture, skipping tests.\n");
4338 levels
= IDirect3DCubeTexture9_GetLevelCount(texture
);
4339 if (caps
.TextureCaps
& D3DPTEXTURECAPS_MIPCUBEMAP
)
4340 ok(levels
== 7, "Got unexpected levels %u.\n", levels
);
4342 ok(levels
== 1, "Got unexpected levels %u.\n", levels
);
4344 hr
= IDirect3DCubeTexture9_GetLevelDesc(texture
, levels
- 1, &desc
);
4345 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4346 hr
= IDirect3DCubeTexture9_GetLevelDesc(texture
, levels
, &desc
);
4347 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4348 hr
= IDirect3DCubeTexture9_GetLevelDesc(texture
, levels
+ 1, &desc
);
4349 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4351 hr
= IDirect3DCubeTexture9_GetCubeMapSurface(texture
, D3DCUBEMAP_FACE_POSITIVE_X
, 0, &surface
);
4352 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4353 IDirect3DSurface9_Release(surface
);
4354 hr
= IDirect3DCubeTexture9_GetCubeMapSurface(texture
, D3DCUBEMAP_FACE_NEGATIVE_Z
+ 1, 0, &surface
);
4355 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4356 hr
= IDirect3DCubeTexture9_GetCubeMapSurface(texture
, D3DCUBEMAP_FACE_POSITIVE_X
- 1, 0, &surface
);
4357 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4359 IDirect3DCubeTexture9_Release(texture
);
4362 static void test_cube_textures(void)
4364 IDirect3DCubeTexture9
*texture
;
4365 IDirect3DDevice9
*device
;
4372 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
4373 0, 0, 640, 480, 0, 0, 0, 0);
4374 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
4375 ok(!!d3d
, "Failed to create a D3D object.\n");
4376 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
4378 skip("Failed to create a D3D device, skipping tests.\n");
4379 IDirect3D9_Release(d3d
);
4380 DestroyWindow(window
);
4384 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
4385 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
4387 if (caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
)
4389 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &texture
, NULL
);
4390 ok(hr
== D3D_OK
, "Failed to create D3DPOOL_DEFAULT cube texture, hr %#x.\n", hr
);
4391 IDirect3DCubeTexture9_Release(texture
);
4392 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &texture
, NULL
);
4393 ok(hr
== D3D_OK
, "Failed to create D3DPOOL_MANAGED cube texture, hr %#x.\n", hr
);
4394 IDirect3DCubeTexture9_Release(texture
);
4395 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_SYSTEMMEM
, &texture
, NULL
);
4396 ok(hr
== D3D_OK
, "Failed to create D3DPOOL_SYSTEMMEM cube texture, hr %#x.\n", hr
);
4397 IDirect3DCubeTexture9_Release(texture
);
4401 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &texture
, NULL
);
4402 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for D3DPOOL_DEFAULT cube texture.\n", hr
);
4403 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &texture
, NULL
);
4404 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for D3DPOOL_MANAGED cube texture.\n", hr
);
4405 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_SYSTEMMEM
, &texture
, NULL
);
4406 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for D3DPOOL_SYSTEMMEM cube texture.\n", hr
);
4408 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_SCRATCH
, &texture
, NULL
);
4409 ok(hr
== D3D_OK
, "Failed to create D3DPOOL_SCRATCH cube texture, hr %#x.\n", hr
);
4410 IDirect3DCubeTexture9_Release(texture
);
4412 test_cube_texture_mipmap_gen(device
);
4413 test_cube_texture_levels(device
);
4415 refcount
= IDirect3DDevice9_Release(device
);
4416 ok(!refcount
, "Device has %u references left.\n", refcount
);
4417 IDirect3D9_Release(d3d
);
4418 DestroyWindow(window
);
4421 static void test_mipmap_gen(void)
4423 D3DTEXTUREFILTERTYPE filter_type
;
4424 IDirect3DTexture9
*texture
;
4425 IDirect3DSurface9
*surface
;
4426 IDirect3DDevice9
*device
;
4427 D3DSURFACE_DESC desc
;
4436 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
4437 ok(!!d3d
, "Failed to create a D3D object.\n");
4439 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
4440 D3DUSAGE_AUTOGENMIPMAP
, D3DRTYPE_TEXTURE
, D3DFMT_X8R8G8B8
)))
4442 skip("No mipmap generation support, skipping tests.\n");
4443 IDirect3D9_Release(d3d
);
4447 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
4448 0, 0, 640, 480, 0, 0, 0, 0);
4449 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
4451 skip("Failed to create a D3D device, skipping tests.\n");
4452 IDirect3D9_Release(d3d
);
4453 DestroyWindow(window
);
4457 hr
= IDirect3DDevice9_CreateTexture(device
, 64, 64, 0, (D3DUSAGE_RENDERTARGET
| D3DUSAGE_AUTOGENMIPMAP
),
4458 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &texture
, NULL
);
4459 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4460 IDirect3DTexture9_Release(texture
);
4462 hr
= IDirect3DDevice9_CreateTexture(device
, 64, 64, 0, D3DUSAGE_AUTOGENMIPMAP
,
4463 D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &texture
, NULL
);
4464 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4466 filter_type
= IDirect3DTexture9_GetAutoGenFilterType(texture
);
4467 ok(filter_type
== D3DTEXF_LINEAR
/* || broken(filter_type == D3DTEXF_POINT)*/,
4468 "Got unexpected filter_type %#x.\n", filter_type
);
4469 hr
= IDirect3DTexture9_SetAutoGenFilterType(texture
, D3DTEXF_NONE
);
4470 todo_wine
ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4471 hr
= IDirect3DTexture9_SetAutoGenFilterType(texture
, D3DTEXF_ANISOTROPIC
);
4472 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4473 filter_type
= IDirect3DTexture9_GetAutoGenFilterType(texture
);
4474 ok(filter_type
== D3DTEXF_ANISOTROPIC
, "Got unexpected filter_type %#x.\n", filter_type
);
4475 hr
= IDirect3DTexture9_SetAutoGenFilterType(texture
, D3DTEXF_LINEAR
);
4476 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4478 levels
= IDirect3DTexture9_GetLevelCount(texture
);
4479 ok(levels
== 1, "Got unexpected levels %u.\n", levels
);
4481 for (i
= 0; i
< 6 /* 64 = 2 ^ 6 */; ++i
)
4484 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, i
, &surface
);
4485 ok(hr
== (i
? D3DERR_INVALIDCALL
: D3D_OK
), "Got unexpected hr %#x for level %u.\n", hr
, i
);
4487 IDirect3DSurface9_Release(surface
);
4489 hr
= IDirect3DTexture9_GetLevelDesc(texture
, i
, &desc
);
4490 ok(hr
== (i
? D3DERR_INVALIDCALL
: D3D_OK
), "Got unexpected hr %#x for level %u.\n", hr
, i
);
4492 hr
= IDirect3DTexture9_LockRect(texture
, i
, &lr
, NULL
, 0);
4493 ok(hr
== (i
? D3DERR_INVALIDCALL
: D3D_OK
), "Got unexpected hr %#x for level %u.\n", hr
, i
);
4496 hr
= IDirect3DTexture9_UnlockRect(texture
, i
);
4497 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x.\n", hr
);
4500 IDirect3DTexture9_Release(texture
);
4502 hr
= IDirect3DDevice9_CreateTexture(device
, 64, 64, 2, D3DUSAGE_AUTOGENMIPMAP
,
4503 D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &texture
, 0);
4504 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4505 hr
= IDirect3DDevice9_CreateTexture(device
, 64, 64, 6, D3DUSAGE_AUTOGENMIPMAP
,
4506 D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &texture
, 0);
4507 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4509 hr
= IDirect3DDevice9_CreateTexture(device
, 64, 64, 1, D3DUSAGE_AUTOGENMIPMAP
,
4510 D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &texture
, 0);
4511 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4512 levels
= IDirect3DTexture9_GetLevelCount(texture
);
4513 ok(levels
== 1, "Got unexpected levels %u.\n", levels
);
4514 IDirect3DTexture9_Release(texture
);
4516 refcount
= IDirect3DDevice9_Release(device
);
4517 ok(!refcount
, "Device has %u references left.\n", refcount
);
4518 IDirect3D9_Release(d3d
);
4519 DestroyWindow(window
);
4522 static void test_filter(void)
4526 DWORD magfilter
, minfilter
, mipfilter
;
4532 {D3DTEXF_NONE
, D3DTEXF_NONE
, D3DTEXF_NONE
, FALSE
, D3DERR_UNSUPPORTEDTEXTUREFILTER
},
4533 {D3DTEXF_POINT
, D3DTEXF_NONE
, D3DTEXF_NONE
, FALSE
, D3DERR_UNSUPPORTEDTEXTUREFILTER
},
4534 {D3DTEXF_NONE
, D3DTEXF_POINT
, D3DTEXF_NONE
, FALSE
, D3DERR_UNSUPPORTEDTEXTUREFILTER
},
4535 {D3DTEXF_POINT
, D3DTEXF_POINT
, D3DTEXF_NONE
, FALSE
, D3D_OK
},
4536 {D3DTEXF_POINT
, D3DTEXF_POINT
, D3DTEXF_POINT
, FALSE
, D3D_OK
},
4538 {D3DTEXF_NONE
, D3DTEXF_NONE
, D3DTEXF_NONE
, TRUE
, D3DERR_UNSUPPORTEDTEXTUREFILTER
},
4539 {D3DTEXF_POINT
, D3DTEXF_NONE
, D3DTEXF_NONE
, TRUE
, D3DERR_UNSUPPORTEDTEXTUREFILTER
},
4540 {D3DTEXF_POINT
, D3DTEXF_POINT
, D3DTEXF_NONE
, TRUE
, D3D_OK
},
4541 {D3DTEXF_POINT
, D3DTEXF_POINT
, D3DTEXF_POINT
, TRUE
, D3D_OK
},
4543 {D3DTEXF_NONE
, D3DTEXF_NONE
, D3DTEXF_NONE
, TRUE
, D3DERR_UNSUPPORTEDTEXTUREFILTER
},
4544 {D3DTEXF_LINEAR
, D3DTEXF_NONE
, D3DTEXF_NONE
, TRUE
, D3DERR_UNSUPPORTEDTEXTUREFILTER
},
4545 {D3DTEXF_LINEAR
, D3DTEXF_POINT
, D3DTEXF_NONE
, TRUE
, E_FAIL
},
4546 {D3DTEXF_POINT
, D3DTEXF_LINEAR
, D3DTEXF_NONE
, TRUE
, E_FAIL
},
4547 {D3DTEXF_POINT
, D3DTEXF_POINT
, D3DTEXF_LINEAR
, TRUE
, E_FAIL
},
4549 IDirect3DTexture9
*texture
;
4550 IDirect3DDevice9
*device
;
4558 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
4559 ok(!!d3d
, "Failed to create a D3D object.\n");
4561 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
4562 0, D3DRTYPE_TEXTURE
, D3DFMT_A32B32G32R32F
)))
4564 skip("D3DFMT_A32B32G32R32F not supported, skipping tests.\n");
4565 IDirect3D9_Release(d3d
);
4569 if (SUCCEEDED(hr
= IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
4570 D3DUSAGE_QUERY_FILTER
, D3DRTYPE_TEXTURE
, D3DFMT_A32B32G32R32F
)))
4572 skip("D3DFMT_A32B32G32R32F supports filtering, skipping tests.\n");
4573 IDirect3D9_Release(d3d
);
4577 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
4578 0, 0, 640, 480, 0, 0, 0, 0);
4579 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
4581 skip("Failed to create a D3D device, skipping tests.\n");
4582 IDirect3D9_Release(d3d
);
4583 DestroyWindow(window
);
4587 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 0, 0,
4588 D3DFMT_A32B32G32R32F
, D3DPOOL_MANAGED
, &texture
, NULL
);
4589 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
4591 /* Needed for ValidateDevice(). */
4592 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
4593 ok(SUCCEEDED(hr
), "Failed to set fvf, hr %#x.\n", hr
);
4595 for (i
= 0; i
< (sizeof(tests
) / sizeof(*tests
)); ++i
)
4597 if (tests
[i
].has_texture
)
4599 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)texture
);
4600 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
4604 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
4605 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
4608 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAGFILTER
, tests
[i
].magfilter
);
4609 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
4610 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MINFILTER
, tests
[i
].minfilter
);
4611 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
4612 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MIPFILTER
, tests
[i
].mipfilter
);
4613 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
4615 passes
= 0xdeadbeef;
4616 hr
= IDirect3DDevice9_ValidateDevice(device
, &passes
);
4617 ok(hr
== tests
[i
].result
,
4618 "Got unexpected hr %#x, expected %#x (mag %#x, min %#x, mip %#x, has_texture %#x).\n",
4619 hr
, tests
[i
].result
, tests
[i
].magfilter
, tests
[i
].minfilter
,
4620 tests
[i
].mipfilter
, tests
[i
].has_texture
);
4622 ok(!!passes
, "Got unexpected passes %#x.\n", passes
);
4624 ok(passes
== 0xdeadbeef, "Got unexpected passes %#x.\n", passes
);
4627 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
4628 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
4629 IDirect3DTexture9_Release(texture
);
4631 refcount
= IDirect3DDevice9_Release(device
);
4632 ok(!refcount
, "Device has %u references left.\n", refcount
);
4633 IDirect3D9_Release(d3d
);
4634 DestroyWindow(window
);
4637 static void test_get_texture(void)
4639 IDirect3DBaseTexture9
*texture
;
4640 IDirect3DDevice9
*device
;
4646 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
4647 0, 0, 640, 480, 0, 0, 0, 0);
4648 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
4649 ok(!!d3d
, "Failed to create a D3D object.\n");
4650 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
4652 skip("Failed to create a D3D device, skipping tests.\n");
4653 IDirect3D9_Release(d3d
);
4654 DestroyWindow(window
);
4658 texture
= (IDirect3DBaseTexture9
*)0xdeadbeef;
4659 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
4660 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4661 hr
= IDirect3DDevice9_GetTexture(device
, 0, &texture
);
4662 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4663 ok(!texture
, "Got unexpected texture %p.\n", texture
);
4665 refcount
= IDirect3DDevice9_Release(device
);
4666 ok(!refcount
, "Device has %u references left.\n", refcount
);
4667 IDirect3D9_Release(d3d
);
4668 DestroyWindow(window
);
4671 static void test_lod(void)
4673 IDirect3DTexture9
*texture
;
4674 IDirect3DDevice9
*device
;
4681 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
4682 0, 0, 640, 480, 0, 0, 0, 0);
4683 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
4684 ok(!!d3d
, "Failed to create a D3D object.\n");
4685 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
4687 skip("Failed to create a D3D device, skipping tests.\n");
4688 IDirect3D9_Release(d3d
);
4689 DestroyWindow(window
);
4693 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 3, 0,
4694 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &texture
, NULL
);
4695 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
4697 /* SetLOD() is only supported on D3DPOOL_MANAGED textures, but doesn't
4698 * return a HRESULT, so it can't return a normal error. Instead, the call
4699 * is simply ignored. */
4700 ret
= IDirect3DTexture9_SetLOD(texture
, 0);
4701 ok(!ret
, "Got unexpected ret %u.\n", ret
);
4702 ret
= IDirect3DTexture9_SetLOD(texture
, 1);
4703 ok(!ret
, "Got unexpected ret %u.\n", ret
);
4704 ret
= IDirect3DTexture9_SetLOD(texture
, 2);
4705 ok(!ret
, "Got unexpected ret %u.\n", ret
);
4706 ret
= IDirect3DTexture9_GetLOD(texture
);
4707 ok(!ret
, "Got unexpected ret %u.\n", ret
);
4709 IDirect3DTexture9_Release(texture
);
4710 refcount
= IDirect3DDevice9_Release(device
);
4711 ok(!refcount
, "Device has %u references left.\n", refcount
);
4712 IDirect3D9_Release(d3d
);
4713 DestroyWindow(window
);
4716 static void test_surface_get_container(void)
4718 IDirect3DTexture9
*texture
= NULL
;
4719 IDirect3DSurface9
*surface
= NULL
;
4720 IDirect3DDevice9
*device
;
4721 IUnknown
*container
;
4727 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
4728 0, 0, 640, 480, 0, 0, 0, 0);
4729 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
4730 ok(!!d3d
, "Failed to create a D3D object.\n");
4731 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
4733 skip("Failed to create a D3D device, skipping tests.\n");
4734 IDirect3D9_Release(d3d
);
4735 DestroyWindow(window
);
4739 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 1, 0,
4740 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &texture
, NULL
);
4741 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
4742 ok(!!texture
, "Got unexpected texture %p.\n", texture
);
4744 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
4745 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
4746 ok(!!surface
, "Got unexpected surface %p.\n", surface
);
4748 /* These should work... */
4750 hr
= IDirect3DSurface9_GetContainer(surface
, &IID_IUnknown
, (void **)&container
);
4751 ok(SUCCEEDED(hr
), "Failed to get surface container, hr %#x.\n", hr
);
4752 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4753 IUnknown_Release(container
);
4756 hr
= IDirect3DSurface9_GetContainer(surface
, &IID_IDirect3DResource9
, (void **)&container
);
4757 ok(SUCCEEDED(hr
), "Failed to get surface container, hr %#x.\n", hr
);
4758 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4759 IUnknown_Release(container
);
4762 hr
= IDirect3DSurface9_GetContainer(surface
, &IID_IDirect3DBaseTexture9
, (void **)&container
);
4763 ok(SUCCEEDED(hr
), "Failed to get surface container, hr %#x.\n", hr
);
4764 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4765 IUnknown_Release(container
);
4768 hr
= IDirect3DSurface9_GetContainer(surface
, &IID_IDirect3DTexture9
, (void **)&container
);
4769 ok(SUCCEEDED(hr
), "Failed to get surface container, hr %#x.\n", hr
);
4770 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4771 IUnknown_Release(container
);
4773 /* ...and this one shouldn't. This should return E_NOINTERFACE and set container to NULL. */
4774 hr
= IDirect3DSurface9_GetContainer(surface
, &IID_IDirect3DSurface9
, (void **)&container
);
4775 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
4776 ok(!container
, "Got unexpected container %p.\n", container
);
4778 IDirect3DSurface9_Release(surface
);
4779 IDirect3DTexture9_Release(texture
);
4780 refcount
= IDirect3DDevice9_Release(device
);
4781 ok(!refcount
, "Device has %u references left.\n", refcount
);
4782 IDirect3D9_Release(d3d
);
4783 DestroyWindow(window
);
4786 static void test_surface_alignment(void)
4788 IDirect3DSurface9
*surface
;
4789 IDirect3DDevice9
*device
;
4797 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
4798 0, 0, 640, 480, 0, 0, 0, 0);
4799 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
4800 ok(!!d3d
, "Failed to create a D3D object.\n");
4801 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
4803 skip("Failed to create a D3D device, skipping tests.\n");
4804 IDirect3D9_Release(d3d
);
4805 DestroyWindow(window
);
4809 /* Test a sysmem surface because those aren't affected by the hardware's np2 restrictions. */
4810 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 5, 5,
4811 D3DFMT_R5G6B5
, D3DPOOL_SYSTEMMEM
, &surface
, NULL
);
4812 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4814 hr
= IDirect3DSurface9_LockRect(surface
, &lr
, NULL
, 0);
4815 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4816 ok(!(lr
.Pitch
& 3), "Got misaligned pitch %d.\n", lr
.Pitch
);
4817 /* Some applications also depend on the exact pitch, rather than just the
4819 ok(lr
.Pitch
== 12, "Got unexpected pitch %d.\n", lr
.Pitch
);
4820 hr
= IDirect3DSurface9_UnlockRect(surface
);
4821 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4822 IDirect3DSurface9_Release(surface
);
4824 for (i
= 0; i
< 5; ++i
)
4826 IDirect3DTexture9
*texture
;
4827 unsigned int level_count
;
4828 D3DSURFACE_DESC desc
;
4831 hr
= IDirect3DDevice9_CreateTexture(device
, 64, 64, 0, 0,
4832 MAKEFOURCC('D', 'X', 'T', '1' + i
), D3DPOOL_MANAGED
, &texture
, NULL
);
4833 ok(SUCCEEDED(hr
) || hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4836 skip("DXT%u surfaces are not supported, skipping tests.\n", i
+ 1);
4840 level_count
= IDirect3DBaseTexture9_GetLevelCount(texture
);
4841 for (j
= 0; j
< level_count
; ++j
)
4843 IDirect3DTexture9_GetLevelDesc(texture
, j
, &desc
);
4844 hr
= IDirect3DTexture9_LockRect(texture
, j
, &lr
, NULL
, 0);
4845 ok(SUCCEEDED(hr
), "Failed to lock texture, hr %#x.\n", hr
);
4846 hr
= IDirect3DTexture9_UnlockRect(texture
, j
);
4847 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x.\n", hr
);
4849 expected_pitch
= ((desc
.Width
+ 3) >> 2) << 3;
4851 expected_pitch
<<= 1;
4852 ok(lr
.Pitch
== expected_pitch
, "Got unexpected pitch %d for DXT%u level %u (%ux%u), expected %d.\n",
4853 lr
.Pitch
, i
+ 1, j
, desc
.Width
, desc
.Height
, expected_pitch
);
4855 IDirect3DTexture9_Release(texture
);
4858 refcount
= IDirect3DDevice9_Release(device
);
4859 ok(!refcount
, "Device has %u references left.\n", refcount
);
4860 IDirect3D9_Release(d3d
);
4861 DestroyWindow(window
);
4864 /* Since the DXT formats are based on 4x4 blocks, locking works slightly
4865 * different from regular formats. This test verifies we return the correct
4866 * memory offsets. */
4867 static void test_lockrect_offset(void)
4873 unsigned int block_width
;
4874 unsigned int block_height
;
4875 unsigned int block_size
;
4879 {D3DFMT_DXT1
, "D3DFMT_DXT1", 4, 4, 8},
4880 {D3DFMT_DXT2
, "D3DFMT_DXT2", 4, 4, 16},
4881 {D3DFMT_DXT3
, "D3DFMT_DXT3", 4, 4, 16},
4882 {D3DFMT_DXT4
, "D3DFMT_DXT4", 4, 4, 16},
4883 {D3DFMT_DXT5
, "D3DFMT_DXT5", 4, 4, 16},
4884 {MAKEFOURCC('A','T','I','2'), "ATI2N", 1, 1, 1},
4886 unsigned int expected_offset
, offset
, i
;
4887 const RECT rect
= {60, 60, 68, 68};
4888 IDirect3DSurface9
*surface
;
4889 D3DLOCKED_RECT locked_rect
;
4890 IDirect3DDevice9
*device
;
4898 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
4899 0, 0, 640, 480, 0, 0, 0, 0);
4900 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
4901 ok(!!d3d
, "Failed to create a D3D object.\n");
4902 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
4904 skip("Failed to create a D3D device, skipping tests.\n");
4905 IDirect3D9_Release(d3d
);
4906 DestroyWindow(window
);
4910 for (i
= 0; i
< (sizeof(dxt_formats
) / sizeof(*dxt_formats
)); ++i
)
4912 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
4913 0, D3DRTYPE_TEXTURE
, dxt_formats
[i
].format
)))
4915 skip("Format %s not supported, skipping lockrect offset tests.\n", dxt_formats
[i
].name
);
4919 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 128, 128,
4920 dxt_formats
[i
].format
, D3DPOOL_SCRATCH
, &surface
, NULL
);
4921 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4923 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, NULL
, 0);
4924 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4926 base
= locked_rect
.pBits
;
4927 expected_pitch
= (128 + dxt_formats
[i
].block_height
- 1) / dxt_formats
[i
].block_width
4928 * dxt_formats
[i
].block_size
;
4929 ok(locked_rect
.Pitch
== expected_pitch
, "Got unexpected pitch %d for format %s, expected %d.\n",
4930 locked_rect
.Pitch
, dxt_formats
[i
].name
, expected_pitch
);
4932 hr
= IDirect3DSurface9_UnlockRect(surface
);
4933 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4935 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, &rect
, 0);
4936 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4938 offset
= (BYTE
*)locked_rect
.pBits
- base
;
4939 expected_offset
= (rect
.top
/ dxt_formats
[i
].block_height
) * expected_pitch
4940 + (rect
.left
/ dxt_formats
[i
].block_width
) * dxt_formats
[i
].block_size
;
4941 ok(offset
== expected_offset
, "Got unexpected offset %u for format %s, expected %u.\n",
4942 offset
, dxt_formats
[i
].name
, expected_offset
);
4944 hr
= IDirect3DSurface9_UnlockRect(surface
);
4945 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4947 IDirect3DSurface9_Release(surface
);
4950 refcount
= IDirect3DDevice9_Release(device
);
4951 ok(!refcount
, "Device has %u references left.\n", refcount
);
4952 IDirect3D9_Release(d3d
);
4953 DestroyWindow(window
);
4956 static void test_lockrect_invalid(void)
4961 HRESULT win7_result
;
4965 {{60, 60, 68, 68}, D3D_OK
}, /* Valid */
4966 {{60, 60, 60, 68}, D3DERR_INVALIDCALL
}, /* 0 height */
4967 {{60, 60, 68, 60}, D3DERR_INVALIDCALL
}, /* 0 width */
4968 {{68, 60, 60, 68}, D3DERR_INVALIDCALL
}, /* left > right */
4969 {{60, 68, 68, 60}, D3DERR_INVALIDCALL
}, /* top > bottom */
4970 {{-8, 60, 0, 68}, D3DERR_INVALIDCALL
}, /* left < surface */
4971 {{60, -8, 68, 0}, D3DERR_INVALIDCALL
}, /* top < surface */
4972 {{-16, 60, -8, 68}, D3DERR_INVALIDCALL
}, /* right < surface */
4973 {{60, -16, 68, -8}, D3DERR_INVALIDCALL
}, /* bottom < surface */
4974 {{60, 60, 136, 68}, D3DERR_INVALIDCALL
}, /* right > surface */
4975 {{60, 60, 68, 136}, D3DERR_INVALIDCALL
}, /* bottom > surface */
4976 {{136, 60, 144, 68}, D3DERR_INVALIDCALL
}, /* left > surface */
4977 {{60, 136, 68, 144}, D3DERR_INVALIDCALL
}, /* top > surface */
4979 static const RECT test_rect_2
= {0, 0, 8, 8};
4980 IDirect3DSurface9
*surface
= NULL
;
4981 D3DLOCKED_RECT locked_rect
;
4982 IDirect3DDevice9
*device
;
4990 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
4991 0, 0, 640, 480, 0, 0, 0, 0);
4992 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
4993 ok(!!d3d
, "Failed to create a D3D object.\n");
4994 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
4996 skip("Failed to create a D3D device, skipping tests.\n");
4997 IDirect3D9_Release(d3d
);
4998 DestroyWindow(window
);
5002 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 128, 128,
5003 D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &surface
, NULL
);
5004 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5005 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, NULL
, 0);
5006 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5007 base
= locked_rect
.pBits
;
5008 hr
= IDirect3DSurface9_UnlockRect(surface
);
5009 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5011 for (i
= 0; i
< (sizeof(test_data
) / sizeof(*test_data
)); ++i
)
5013 unsigned int offset
, expected_offset
;
5014 const RECT
*rect
= &test_data
[i
].rect
;
5016 locked_rect
.pBits
= (BYTE
*)0xdeadbeef;
5017 locked_rect
.Pitch
= 0xdeadbeef;
5019 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, rect
, 0);
5020 /* Windows XP accepts invalid locking rectangles, windows 7 rejects
5021 * them. Some games (C&C3) depend on the XP behavior, mark the Win 7
5023 ok(SUCCEEDED(hr
) || broken(hr
== test_data
[i
].win7_result
),
5024 "Failed to lock surface with rect [%d, %d]->[%d, %d], hr %#x.\n",
5025 rect
->left
, rect
->top
, rect
->right
, rect
->bottom
, hr
);
5029 offset
= (BYTE
*)locked_rect
.pBits
- base
;
5030 expected_offset
= rect
->top
* locked_rect
.Pitch
+ rect
->left
* 4;
5031 ok(offset
== expected_offset
,
5032 "Got unexpected offset %u (expected %u) for rect [%d, %d]->[%d, %d].\n",
5033 offset
, expected_offset
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
5035 hr
= IDirect3DSurface9_UnlockRect(surface
);
5036 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5039 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, NULL
, 0);
5040 ok(SUCCEEDED(hr
), "Failed to lock surface with rect NULL, hr %#x.\n", hr
);
5041 locked_rect
.pBits
= (BYTE
*)0xdeadbeef;
5042 locked_rect
.Pitch
= 1;
5043 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, NULL
, 0);
5044 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5045 ok(locked_rect
.pBits
== (BYTE
*)0xdeadbeef, "Got unexpected pBits: %p\n",
5047 ok(locked_rect
.Pitch
== 1, "Got unexpected pitch %d\n", locked_rect
.Pitch
);
5048 hr
= IDirect3DSurface9_UnlockRect(surface
);
5049 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5051 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, &test_data
[0].rect
, 0);
5052 ok(hr
== D3D_OK
, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d].\n",
5053 hr
, test_data
[0].rect
.left
, test_data
[0].rect
.top
, test_data
[0].rect
.right
, test_data
[0].rect
.bottom
);
5054 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, &test_data
[0].rect
, 0);
5055 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d].\n",
5056 hr
, test_data
[0].rect
.left
, test_data
[0].rect
.top
, test_data
[0].rect
.right
, test_data
[0].rect
.bottom
);
5057 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, &test_rect_2
, 0);
5058 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d].\n",
5059 hr
, test_rect_2
.left
, test_rect_2
.top
, test_rect_2
.right
, test_rect_2
.bottom
);
5060 hr
= IDirect3DSurface9_UnlockRect(surface
);
5061 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5063 IDirect3DSurface9_Release(surface
);
5064 refcount
= IDirect3DDevice9_Release(device
);
5065 ok(!refcount
, "Device has %u references left.\n", refcount
);
5066 IDirect3D9_Release(d3d
);
5067 DestroyWindow(window
);
5070 static void test_private_data(void)
5072 ULONG refcount
, expected_refcount
;
5073 IDirect3DTexture9
*texture
;
5074 IDirect3DSurface9
*surface
, *surface2
;
5075 IDirect3DDevice9
*device
;
5081 DWORD data
[4] = {1, 2, 3, 4};
5082 static const GUID d3d9_private_data_test_guid
=
5087 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
5089 static const GUID d3d9_private_data_test_guid2
=
5094 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
5097 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
5098 0, 0, 640, 480, 0, 0, 0, 0);
5099 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
5100 ok(!!d3d
, "Failed to create a D3D object.\n");
5101 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
5103 skip("Failed to create a D3D device, skipping tests.\n");
5104 IDirect3D9_Release(d3d
);
5105 DestroyWindow(window
);
5109 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 4, 4,
5110 D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &surface
, NULL
);
5111 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5113 hr
= IDirect3DSurface9_SetPrivateData(surface
, &d3d9_private_data_test_guid
,
5114 device
, 0, D3DSPD_IUNKNOWN
);
5115 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5116 hr
= IDirect3DSurface9_SetPrivateData(surface
, &d3d9_private_data_test_guid
,
5117 device
, 5, D3DSPD_IUNKNOWN
);
5118 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5119 hr
= IDirect3DSurface9_SetPrivateData(surface
, &d3d9_private_data_test_guid
,
5120 device
, sizeof(IUnknown
*) * 2, D3DSPD_IUNKNOWN
);
5121 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5123 /* A failing SetPrivateData call does not clear the old data with the same tag. */
5124 hr
= IDirect3DSurface9_SetPrivateData(surface
, &d3d9_private_data_test_guid
, device
,
5125 sizeof(device
), D3DSPD_IUNKNOWN
);
5126 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
5127 hr
= IDirect3DSurface9_SetPrivateData(surface
, &d3d9_private_data_test_guid
, device
,
5128 sizeof(device
) * 2, D3DSPD_IUNKNOWN
);
5129 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5131 hr
= IDirect3DSurface9_GetPrivateData(surface
, &d3d9_private_data_test_guid
, &ptr
, &size
);
5132 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
5133 IUnknown_Release(ptr
);
5134 hr
= IDirect3DSurface9_FreePrivateData(surface
, &d3d9_private_data_test_guid
);
5135 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
5137 refcount
= get_refcount((IUnknown
*)device
);
5138 hr
= IDirect3DSurface9_SetPrivateData(surface
, &d3d9_private_data_test_guid
,
5139 device
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
5140 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5141 expected_refcount
= refcount
+ 1;
5142 refcount
= get_refcount((IUnknown
*)device
);
5143 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5144 hr
= IDirect3DSurface9_FreePrivateData(surface
, &d3d9_private_data_test_guid
);
5145 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5146 expected_refcount
= refcount
- 1;
5147 refcount
= get_refcount((IUnknown
*)device
);
5148 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5150 hr
= IDirect3DSurface9_SetPrivateData(surface
, &d3d9_private_data_test_guid
,
5151 device
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
5152 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5153 hr
= IDirect3DSurface9_SetPrivateData(surface
, &d3d9_private_data_test_guid
,
5154 surface
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
5155 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5156 refcount
= get_refcount((IUnknown
*)device
);
5157 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5159 hr
= IDirect3DSurface9_SetPrivateData(surface
, &d3d9_private_data_test_guid
,
5160 device
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
5161 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5162 size
= 2 * sizeof(ptr
);
5163 hr
= IDirect3DSurface9_GetPrivateData(surface
, &d3d9_private_data_test_guid
, &ptr
, &size
);
5164 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5165 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
5166 expected_refcount
= refcount
+ 2;
5167 refcount
= get_refcount((IUnknown
*)device
);
5168 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5169 ok(ptr
== (IUnknown
*)device
, "Got unexpected ptr %p, expected %p.\n", ptr
, device
);
5170 IUnknown_Release(ptr
);
5171 expected_refcount
--;
5173 ptr
= (IUnknown
*)0xdeadbeef;
5175 hr
= IDirect3DSurface9_GetPrivateData(surface
, &d3d9_private_data_test_guid
, NULL
, &size
);
5176 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5177 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
5178 size
= 2 * sizeof(ptr
);
5179 hr
= IDirect3DSurface9_GetPrivateData(surface
, &d3d9_private_data_test_guid
, NULL
, &size
);
5180 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5181 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
5182 refcount
= get_refcount((IUnknown
*)device
);
5183 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5185 hr
= IDirect3DSurface9_GetPrivateData(surface
, &d3d9_private_data_test_guid
, &ptr
, &size
);
5186 ok(hr
== D3DERR_MOREDATA
, "Got unexpected hr %#x.\n", hr
);
5187 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
5188 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
5189 hr
= IDirect3DSurface9_GetPrivateData(surface
, &d3d9_private_data_test_guid2
, NULL
, NULL
);
5190 ok(hr
== D3DERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5192 hr
= IDirect3DSurface9_GetPrivateData(surface
, &d3d9_private_data_test_guid2
, &ptr
, &size
);
5193 ok(hr
== D3DERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5194 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
5195 ok(size
== 0xdeadbabe, "Got unexpected size %u.\n", size
);
5196 /* GetPrivateData with size = NULL causes an access violation on Windows if the
5197 * requested data exists. */
5199 /* Destroying the surface frees the held reference. */
5200 IDirect3DSurface9_Release(surface
);
5201 expected_refcount
= refcount
- 2;
5202 refcount
= get_refcount((IUnknown
*)device
);
5203 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5205 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 2, 0, D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
,
5207 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
5208 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
5209 ok(SUCCEEDED(hr
), "Failed to get texture level 0, hr %#x.\n", hr
);
5210 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 1, &surface2
);
5211 ok(SUCCEEDED(hr
), "Failed to get texture level 1, hr %#x.\n", hr
);
5213 hr
= IDirect3DTexture9_SetPrivateData(texture
, &d3d9_private_data_test_guid
, data
, sizeof(data
), 0);
5214 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
5216 memset(data
, 0, sizeof(data
));
5217 size
= sizeof(data
);
5218 hr
= IDirect3DSurface9_GetPrivateData(surface
, &d3d9_private_data_test_guid
, data
, &size
);
5219 ok(hr
== D3DERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5220 hr
= IDirect3DTexture9_GetPrivateData(texture
, &d3d9_private_data_test_guid
, data
, &size
);
5221 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
5222 ok(data
[0] == 1 && data
[1] == 2 && data
[2] == 3 && data
[3] == 4,
5223 "Got unexpected private data: %u, %u, %u, %u.\n", data
[0], data
[1], data
[2], data
[3]);
5225 hr
= IDirect3DTexture9_FreePrivateData(texture
, &d3d9_private_data_test_guid
);
5226 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
5228 hr
= IDirect3DSurface9_SetPrivateData(surface
, &d3d9_private_data_test_guid
, data
, sizeof(data
), 0);
5229 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
5230 hr
= IDirect3DSurface9_GetPrivateData(surface2
, &d3d9_private_data_test_guid
, data
, &size
);
5231 ok(hr
== D3DERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5233 hr
= IDirect3DSurface9_FreePrivateData(surface
, &d3d9_private_data_test_guid
);
5234 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
5236 IDirect3DSurface9_Release(surface2
);
5237 IDirect3DSurface9_Release(surface
);
5238 IDirect3DTexture9_Release(texture
);
5240 refcount
= IDirect3DDevice9_Release(device
);
5241 ok(!refcount
, "Device has %u references left.\n", refcount
);
5242 IDirect3D9_Release(d3d
);
5243 DestroyWindow(window
);
5246 static void test_getdc(void)
5252 BOOL getdc_supported
;
5256 {"D3DFMT_A8R8G8B8", D3DFMT_A8R8G8B8
, TRUE
},
5257 {"D3DFMT_X8R8G8B8", D3DFMT_X8R8G8B8
, TRUE
},
5258 {"D3DFMT_R5G6B5", D3DFMT_R5G6B5
, TRUE
},
5259 {"D3DFMT_X1R5G5B5", D3DFMT_X1R5G5B5
, TRUE
},
5260 {"D3DFMT_A1R5G5B5", D3DFMT_A1R5G5B5
, TRUE
},
5261 {"D3DFMT_R8G8B8", D3DFMT_R8G8B8
, TRUE
},
5262 {"D3DFMT_A2R10G10B10", D3DFMT_A2R10G10B10
, FALSE
}, /* Untested, card on windows didn't support it. */
5263 {"D3DFMT_V8U8", D3DFMT_V8U8
, FALSE
},
5264 {"D3DFMT_Q8W8V8U8", D3DFMT_Q8W8V8U8
, FALSE
},
5265 {"D3DFMT_A8B8G8R8", D3DFMT_A8B8G8R8
, FALSE
},
5266 {"D3DFMT_X8B8G8R8", D3DFMT_A8B8G8R8
, FALSE
},
5267 {"D3DFMT_R3G3B2", D3DFMT_R3G3B2
, FALSE
},
5268 {"D3DFMT_P8", D3DFMT_P8
, FALSE
},
5269 {"D3DFMT_L8", D3DFMT_L8
, FALSE
},
5270 {"D3DFMT_A8L8", D3DFMT_A8L8
, FALSE
},
5271 {"D3DFMT_DXT1", D3DFMT_DXT1
, FALSE
},
5272 {"D3DFMT_DXT2", D3DFMT_DXT2
, FALSE
},
5273 {"D3DFMT_DXT3", D3DFMT_DXT3
, FALSE
},
5274 {"D3DFMT_DXT4", D3DFMT_DXT4
, FALSE
},
5275 {"D3DFMT_DXT5", D3DFMT_DXT5
, FALSE
},
5277 IDirect3DTexture9
*texture
;
5278 IDirect3DSurface9
*surface
;
5279 IDirect3DDevice9
*device
;
5287 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
5288 0, 0, 640, 480, 0, 0, 0, 0);
5289 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
5290 ok(!!d3d
, "Failed to create a D3D object.\n");
5291 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
5293 skip("Failed to create a D3D device, skipping tests.\n");
5294 IDirect3D9_Release(d3d
);
5295 DestroyWindow(window
);
5299 for (i
= 0; i
< (sizeof(testdata
) / sizeof(*testdata
)); ++i
)
5302 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 64, 64,
5303 testdata
[i
].format
, D3DPOOL_SYSTEMMEM
, &surface
, NULL
);
5306 hr
= IDirect3DDevice9_CreateTexture(device
, 64, 64, 1, 0,
5307 testdata
[i
].format
, D3DPOOL_MANAGED
, &texture
, NULL
);
5310 skip("Failed to create surface for format %s (hr %#x), skipping tests.\n", testdata
[i
].name
, hr
);
5313 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
5314 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
5317 dc
= (void *)0x1234;
5318 hr
= IDirect3DSurface9_GetDC(surface
, &dc
);
5319 if (testdata
[i
].getdc_supported
)
5320 ok(SUCCEEDED(hr
), "Got unexpected hr %#x for format %s.\n", hr
, testdata
[i
].name
);
5322 ok(FAILED(hr
), "Got unexpected hr %#x for format %s.\n", hr
, testdata
[i
].name
);
5326 hr
= IDirect3DSurface9_ReleaseDC(surface
, dc
);
5327 ok(hr
== D3D_OK
, "Failed to release DC, hr %#x.\n", hr
);
5331 ok(dc
== (void *)0x1234, "Got unexpected dc %p.\n", dc
);
5334 IDirect3DSurface9_Release(surface
);
5336 IDirect3DTexture9_Release(texture
);
5339 refcount
= IDirect3DDevice9_Release(device
);
5340 ok(!refcount
, "Device has %u references left.\n", refcount
);
5341 IDirect3D9_Release(d3d
);
5342 DestroyWindow(window
);
5345 static void test_surface_dimensions(void)
5347 IDirect3DSurface9
*surface
;
5348 IDirect3DDevice9
*device
;
5354 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
5355 0, 0, 640, 480, 0, 0, 0, 0);
5356 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
5357 ok(!!d3d
, "Failed to create a D3D object.\n");
5358 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
5360 skip("Failed to create a D3D device, skipping tests.\n");
5361 IDirect3D9_Release(d3d
);
5362 DestroyWindow(window
);
5366 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 0, 1,
5367 D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &surface
, NULL
);
5368 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5369 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 1, 0,
5370 D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &surface
, NULL
);
5371 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5373 refcount
= IDirect3DDevice9_Release(device
);
5374 ok(!refcount
, "Device has %u references left.\n", refcount
);
5375 IDirect3D9_Release(d3d
);
5376 DestroyWindow(window
);
5379 static void test_surface_format_null(void)
5381 static const D3DFORMAT D3DFMT_NULL
= MAKEFOURCC('N','U','L','L');
5382 IDirect3DTexture9
*texture
;
5383 IDirect3DSurface9
*surface
;
5384 IDirect3DSurface9
*rt
, *ds
;
5385 D3DLOCKED_RECT locked_rect
;
5386 IDirect3DDevice9
*device
;
5387 D3DSURFACE_DESC desc
;
5393 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
5394 ok(!!d3d
, "Failed to create a D3D object.\n");
5396 hr
= IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5397 D3DUSAGE_RENDERTARGET
, D3DRTYPE_SURFACE
, D3DFMT_NULL
);
5400 skip("No D3DFMT_NULL support, skipping test.\n");
5401 IDirect3D9_Release(d3d
);
5405 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
5406 0, 0, 640, 480, 0, 0, 0, 0);
5407 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
5409 skip("Failed to create a D3D device, skipping tests.\n");
5410 IDirect3D9_Release(d3d
);
5411 DestroyWindow(window
);
5415 hr
= IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5416 D3DUSAGE_RENDERTARGET
, D3DRTYPE_TEXTURE
, D3DFMT_NULL
);
5417 ok(hr
== D3D_OK
, "D3DFMT_NULL should be supported for render target textures, hr %#x.\n", hr
);
5419 hr
= IDirect3D9_CheckDepthStencilMatch(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5420 D3DFMT_NULL
, D3DFMT_D24S8
);
5421 ok(SUCCEEDED(hr
), "Depth stencil match failed for D3DFMT_NULL, hr %#x.\n", hr
);
5423 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 128, 128, D3DFMT_NULL
,
5424 D3DMULTISAMPLE_NONE
, 0, TRUE
, &surface
, NULL
);
5425 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
5427 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &rt
);
5428 ok(SUCCEEDED(hr
), "Failed to get original render target, hr %#x.\n", hr
);
5430 hr
= IDirect3DDevice9_GetDepthStencilSurface(device
, &ds
);
5431 ok(SUCCEEDED(hr
), "Failed to get original depth/stencil, hr %#x.\n", hr
);
5433 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, NULL
);
5434 ok(FAILED(hr
), "Succeeded in setting render target 0 to NULL, should fail.\n");
5436 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, surface
);
5437 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
5439 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, NULL
);
5440 ok(SUCCEEDED(hr
), "Failed to set depth/stencil, hr %#x.\n", hr
);
5442 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00000000, 0.0f
, 0);
5443 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
5445 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt
);
5446 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
5448 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, ds
);
5449 ok(SUCCEEDED(hr
), "Failed to set depth/stencil, hr %#x.\n", hr
);
5451 IDirect3DSurface9_Release(rt
);
5452 IDirect3DSurface9_Release(ds
);
5454 hr
= IDirect3DSurface9_GetDesc(surface
, &desc
);
5455 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5456 ok(desc
.Width
== 128, "Expected width 128, got %u.\n", desc
.Width
);
5457 ok(desc
.Height
== 128, "Expected height 128, got %u.\n", desc
.Height
);
5459 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, NULL
, 0);
5460 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5461 ok(locked_rect
.Pitch
, "Expected non-zero pitch, got %u.\n", locked_rect
.Pitch
);
5462 ok(!!locked_rect
.pBits
, "Expected non-NULL pBits, got %p.\n", locked_rect
.pBits
);
5464 hr
= IDirect3DSurface9_UnlockRect(surface
);
5465 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5467 IDirect3DSurface9_Release(surface
);
5469 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 0, D3DUSAGE_RENDERTARGET
,
5470 D3DFMT_NULL
, D3DPOOL_DEFAULT
, &texture
, NULL
);
5471 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
5472 IDirect3DTexture9_Release(texture
);
5474 refcount
= IDirect3DDevice9_Release(device
);
5475 ok(!refcount
, "Device has %u references left.\n", refcount
);
5476 IDirect3D9_Release(d3d
);
5477 DestroyWindow(window
);
5480 static void test_surface_double_unlock(void)
5482 static const D3DPOOL pools
[] =
5488 IDirect3DSurface9
*surface
;
5489 IDirect3DDevice9
*device
;
5497 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
5498 0, 0, 640, 480, 0, 0, 0, 0);
5499 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
5500 ok(!!d3d
, "Failed to create a D3D object.\n");
5501 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
5503 skip("Failed to create a D3D device, skipping tests.\n");
5504 IDirect3D9_Release(d3d
);
5505 DestroyWindow(window
);
5509 for (i
= 0; i
< (sizeof(pools
) / sizeof(*pools
)); ++i
)
5511 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 64, 64,
5512 D3DFMT_X8R8G8B8
, pools
[i
], &surface
, NULL
);
5513 ok(SUCCEEDED(hr
), "Failed to create surface in pool %#x, hr %#x.\n", pools
[i
], hr
);
5515 hr
= IDirect3DSurface9_UnlockRect(surface
);
5516 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, for surface in pool %#x.\n", hr
, pools
[i
]);
5517 hr
= IDirect3DSurface9_LockRect(surface
, &lr
, NULL
, 0);
5518 ok(SUCCEEDED(hr
), "Failed to lock surface in pool %#x, hr %#x.\n", pools
[i
], hr
);
5519 hr
= IDirect3DSurface9_UnlockRect(surface
);
5520 ok(SUCCEEDED(hr
), "Failed to unlock surface in pool %#x, hr %#x.\n", pools
[i
], hr
);
5521 hr
= IDirect3DSurface9_UnlockRect(surface
);
5522 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, for surface in pool %#x.\n", hr
, pools
[i
]);
5524 IDirect3DSurface9_Release(surface
);
5527 refcount
= IDirect3DDevice9_Release(device
);
5528 ok(!refcount
, "Device has %u references left.\n", refcount
);
5529 IDirect3D9_Release(d3d
);
5530 DestroyWindow(window
);
5533 static void test_surface_blocks(void)
5539 unsigned int block_width
;
5540 unsigned int block_height
;
5542 BOOL create_size_checked
, core_fmt
;
5546 {D3DFMT_DXT1
, "D3DFMT_DXT1", 4, 4, FALSE
, TRUE
, TRUE
},
5547 {D3DFMT_DXT2
, "D3DFMT_DXT2", 4, 4, FALSE
, TRUE
, TRUE
},
5548 {D3DFMT_DXT3
, "D3DFMT_DXT3", 4, 4, FALSE
, TRUE
, TRUE
},
5549 {D3DFMT_DXT4
, "D3DFMT_DXT4", 4, 4, FALSE
, TRUE
, TRUE
},
5550 {D3DFMT_DXT5
, "D3DFMT_DXT5", 4, 4, FALSE
, TRUE
, TRUE
},
5551 /* ATI2N has 2x2 blocks on all AMD cards and Geforce 7 cards,
5552 * which doesn't match the format spec. On newer Nvidia cards
5553 * it has the correct 4x4 block size */
5554 {MAKEFOURCC('A','T','I','2'), "ATI2N", 4, 4, TRUE
, FALSE
, FALSE
},
5555 {D3DFMT_YUY2
, "D3DFMT_YUY2", 2, 1, FALSE
, FALSE
, TRUE
},
5556 {D3DFMT_UYVY
, "D3DFMT_UYVY", 2, 1, FALSE
, FALSE
, TRUE
},
5562 /* Don't check the return value, Nvidia returns D3DERR_INVALIDCALL for some formats
5563 * and E_INVALIDARG/DDERR_INVALIDPARAMS for others. */
5568 {D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", FALSE
},
5569 {D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", TRUE
},
5570 {D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM",TRUE
},
5571 {D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
},
5575 D3DRESOURCETYPE rtype
;
5576 const char *type_name
;
5578 const char *pool_name
;
5579 BOOL need_driver_support
, need_runtime_support
;
5583 {D3DRTYPE_SURFACE
, "D3DRTYPE_SURFACE", D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", TRUE
, FALSE
},
5584 {D3DRTYPE_SURFACE
, "D3DRTYPE_SURFACE", D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", TRUE
, TRUE
},
5585 /* Managed offscreen plain surfaces are not supported */
5586 {D3DRTYPE_SURFACE
, "D3DRTYPE_SURFACE", D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", FALSE
, TRUE
},
5588 {D3DRTYPE_TEXTURE
, "D3DRTYPE_TEXTURE", D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", TRUE
, FALSE
},
5589 {D3DRTYPE_TEXTURE
, "D3DRTYPE_TEXTURE", D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", TRUE
, FALSE
},
5590 {D3DRTYPE_TEXTURE
, "D3DRTYPE_TEXTURE", D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
, FALSE
},
5591 {D3DRTYPE_TEXTURE
, "D3DRTYPE_TEXTURE", D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", FALSE
, TRUE
},
5593 {D3DRTYPE_CUBETEXTURE
, "D3DRTYPE_CUBETEXTURE", D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", TRUE
, FALSE
},
5594 {D3DRTYPE_CUBETEXTURE
, "D3DRTYPE_CUBETEXTURE", D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", TRUE
, FALSE
},
5595 {D3DRTYPE_CUBETEXTURE
, "D3DRTYPE_CUBETEXTURE", D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
, FALSE
},
5596 {D3DRTYPE_CUBETEXTURE
, "D3DRTYPE_CUBETEXTURE", D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", FALSE
, TRUE
},
5598 IDirect3DTexture9
*texture
;
5599 IDirect3DCubeTexture9
*cube_texture
;
5600 IDirect3DSurface9
*surface
;
5601 D3DLOCKED_RECT locked_rect
;
5602 IDirect3DDevice9
*device
;
5603 unsigned int i
, j
, w
, h
;
5610 BOOL tex_pow2
, cube_pow2
;
5613 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
5614 0, 0, 640, 480, 0, 0, 0, 0);
5615 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
5616 ok(!!d3d
, "Failed to create a D3D object.\n");
5617 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
5619 skip("Failed to create a D3D device, skipping tests.\n");
5620 IDirect3D9_Release(d3d
);
5621 DestroyWindow(window
);
5625 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
5626 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
5627 tex_pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
);
5629 tex_pow2
= !(caps
.TextureCaps
& D3DPTEXTURECAPS_NONPOW2CONDITIONAL
);
5630 cube_pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP_POW2
);
5632 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
5634 BOOL tex_support
, cube_support
, surface_support
, format_known
, dynamic_tex_support
;
5636 hr
= IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5637 0, D3DRTYPE_TEXTURE
, formats
[i
].fmt
);
5638 tex_support
= SUCCEEDED(hr
);
5639 hr
= IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5640 0, D3DRTYPE_CUBETEXTURE
, formats
[i
].fmt
);
5641 cube_support
= SUCCEEDED(hr
);
5642 hr
= IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5643 0, D3DRTYPE_SURFACE
, formats
[i
].fmt
);
5644 surface_support
= SUCCEEDED(hr
);
5646 /* Scratch pool in general allows texture creation even if the driver does
5647 * not support the format. If the format is an extension format that is not
5648 * known to the runtime, like ATI2N, some driver support is required for
5651 * It is also possible that Windows Vista and Windows 7 d3d9 runtimes know
5652 * about ATI2N. I cannot check this because all my Vista+ machines support
5653 * ATI2N in hardware, but none of my WinXP machines do. */
5654 format_known
= tex_support
|| cube_support
|| surface_support
;
5656 for (w
= 1; w
<= 8; w
++)
5658 for (h
= 1; h
<= 8; h
++)
5660 BOOL block_aligned
= TRUE
;
5663 if (w
& (formats
[i
].block_width
- 1) || h
& (formats
[i
].block_height
- 1))
5664 block_aligned
= FALSE
;
5666 size_is_pow2
= !(w
& (w
- 1) || h
& (h
- 1));
5668 for (j
= 0; j
< sizeof(create_tests
) / sizeof(*create_tests
); j
++)
5672 BOOL may_succeed
= FALSE
;
5673 IUnknown
**check_null
;
5675 if (!formats
[i
].core_fmt
)
5677 /* AMD warns against creating ATI2N textures smaller than
5678 * the block size because the runtime cannot calculate the
5679 * correct texture size. Generalize this for all extension
5681 if (w
< formats
[i
].block_width
|| h
< formats
[i
].block_height
)
5685 texture
= (IDirect3DTexture9
*)0xdeadbeef;
5686 cube_texture
= (IDirect3DCubeTexture9
*)0xdeadbeef;
5687 surface
= (IDirect3DSurface9
*)0xdeadbeef;
5689 switch (create_tests
[j
].rtype
)
5691 case D3DRTYPE_TEXTURE
:
5692 check_null
= (IUnknown
**)&texture
;
5693 hr
= IDirect3DDevice9_CreateTexture(device
, w
, h
, 1, 0,
5694 formats
[i
].fmt
, create_tests
[j
].pool
, &texture
, NULL
);
5695 support
= tex_support
;
5699 case D3DRTYPE_CUBETEXTURE
:
5702 check_null
= (IUnknown
**)&cube_texture
;
5703 hr
= IDirect3DDevice9_CreateCubeTexture(device
, w
, 1, 0,
5704 formats
[i
].fmt
, create_tests
[j
].pool
, &cube_texture
, NULL
);
5705 support
= cube_support
;
5709 case D3DRTYPE_SURFACE
:
5710 check_null
= (IUnknown
**)&surface
;
5711 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, w
, h
,
5712 formats
[i
].fmt
, create_tests
[j
].pool
, &surface
, NULL
);
5713 support
= surface_support
;
5724 if (create_tests
[j
].need_driver_support
&& !support
)
5725 expect_hr
= D3DERR_INVALIDCALL
;
5726 else if (create_tests
[j
].need_runtime_support
&& !formats
[i
].core_fmt
&& !format_known
)
5727 expect_hr
= D3DERR_INVALIDCALL
;
5728 else if (formats
[i
].create_size_checked
&& !block_aligned
)
5729 expect_hr
= D3DERR_INVALIDCALL
;
5730 else if (pow2
&& !size_is_pow2
&& create_tests
[j
].need_driver_support
)
5731 expect_hr
= D3DERR_INVALIDCALL
;
5735 /* Wine knows about ATI2N and happily creates a scratch resource even if GL
5736 * does not support it. Accept scratch creation of extension formats on
5737 * Windows as well if it occurs. We don't really care if e.g. a Windows 7
5738 * on an r200 GPU creates scratch ATI2N texture even though the card doesn't
5740 if (!formats
[i
].core_fmt
&& !format_known
&& FAILED(expect_hr
))
5743 ok(hr
== expect_hr
|| ((SUCCEEDED(hr
) && may_succeed
)),
5744 "Got unexpected hr %#x for format %s, pool %s, type %s, size %ux%u.\n",
5745 hr
, formats
[i
].name
, create_tests
[j
].pool_name
, create_tests
[j
].type_name
, w
, h
);
5747 ok(*check_null
== NULL
, "Got object ptr %p, expected NULL.\n", *check_null
);
5749 IUnknown_Release(*check_null
);
5754 surface_only
= FALSE
;
5755 hr
= IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5756 D3DUSAGE_DYNAMIC
, D3DRTYPE_TEXTURE
, formats
[i
].fmt
);
5757 dynamic_tex_support
= SUCCEEDED(hr
);
5758 if (!dynamic_tex_support
)
5760 if (!surface_support
)
5762 skip("Format %s not supported, skipping lockrect offset tests.\n", formats
[i
].name
);
5765 surface_only
= TRUE
;
5768 for (j
= 0; j
< (sizeof(pools
) / sizeof(*pools
)); ++j
)
5770 switch (pools
[j
].pool
)
5772 case D3DPOOL_SYSTEMMEM
:
5773 case D3DPOOL_MANAGED
:
5777 case D3DPOOL_DEFAULT
:
5780 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 128, 128,
5781 formats
[i
].fmt
, pools
[j
].pool
, &surface
, NULL
);
5782 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5786 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 1,
5787 pools
[j
].pool
== D3DPOOL_DEFAULT
? D3DUSAGE_DYNAMIC
: 0,
5788 formats
[i
].fmt
, pools
[j
].pool
, &texture
, NULL
);
5789 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
5790 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
5791 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
5792 IDirect3DTexture9_Release(texture
);
5796 case D3DPOOL_SCRATCH
:
5797 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 128, 128,
5798 formats
[i
].fmt
, pools
[j
].pool
, &surface
, NULL
);
5799 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5806 if (formats
[i
].block_width
> 1)
5808 SetRect(&rect
, formats
[i
].block_width
>> 1, 0, formats
[i
].block_width
, formats
[i
].block_height
);
5809 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, &rect
, 0);
5810 ok(FAILED(hr
) == !pools
[j
].success
|| broken(formats
[i
].broken
),
5811 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5812 SUCCEEDED(hr
) ? "succeeded" : "failed",
5813 pools
[j
].success
? "success" : "failure", formats
[i
].name
, pools
[j
].name
);
5816 hr
= IDirect3DSurface9_UnlockRect(surface
);
5817 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5820 SetRect(&rect
, 0, 0, formats
[i
].block_width
>> 1, formats
[i
].block_height
);
5821 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, &rect
, 0);
5822 ok(FAILED(hr
) == !pools
[j
].success
|| broken(formats
[i
].broken
),
5823 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5824 SUCCEEDED(hr
) ? "succeeded" : "failed",
5825 pools
[j
].success
? "success" : "failure", formats
[i
].name
, pools
[j
].name
);
5828 hr
= IDirect3DSurface9_UnlockRect(surface
);
5829 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5833 if (formats
[i
].block_height
> 1)
5835 SetRect(&rect
, 0, formats
[i
].block_height
>> 1, formats
[i
].block_width
, formats
[i
].block_height
);
5836 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, &rect
, 0);
5837 ok(FAILED(hr
) == !pools
[j
].success
|| broken(formats
[i
].broken
),
5838 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5839 SUCCEEDED(hr
) ? "succeeded" : "failed",
5840 pools
[j
].success
? "success" : "failure", formats
[i
].name
, pools
[j
].name
);
5843 hr
= IDirect3DSurface9_UnlockRect(surface
);
5844 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5847 SetRect(&rect
, 0, 0, formats
[i
].block_width
, formats
[i
].block_height
>> 1);
5848 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, &rect
, 0);
5849 ok(FAILED(hr
) == !pools
[j
].success
|| broken(formats
[i
].broken
),
5850 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5851 SUCCEEDED(hr
) ? "succeeded" : "failed",
5852 pools
[j
].success
? "success" : "failure", formats
[i
].name
, pools
[j
].name
);
5855 hr
= IDirect3DSurface9_UnlockRect(surface
);
5856 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5860 SetRect(&rect
, 0, 0, formats
[i
].block_width
, formats
[i
].block_height
);
5861 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, &rect
, 0);
5862 ok(SUCCEEDED(hr
), "Got unexpected hr %#x for format %s, pool %s.\n", hr
, formats
[i
].name
, pools
[j
].name
);
5863 hr
= IDirect3DSurface9_UnlockRect(surface
);
5864 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5866 IDirect3DSurface9_Release(surface
);
5869 if (!dynamic_tex_support
)
5871 skip("Dynamic %s textures not supported, skipping mipmap test.\n", formats
[i
].name
);
5875 if (formats
[i
].block_width
== 1 && formats
[i
].block_height
== 1)
5877 if (!formats
[i
].core_fmt
)
5880 hr
= IDirect3DDevice9_CreateTexture(device
, formats
[i
].block_width
, formats
[i
].block_height
, 2,
5881 D3DUSAGE_DYNAMIC
, formats
[i
].fmt
, D3DPOOL_DEFAULT
, &texture
, NULL
);
5882 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x, format %s.\n", hr
, formats
[i
].name
);
5884 hr
= IDirect3DTexture9_LockRect(texture
, 1, &locked_rect
, NULL
, 0);
5885 ok(SUCCEEDED(hr
), "Failed lock texture, hr %#x.\n", hr
);
5886 hr
= IDirect3DTexture9_UnlockRect(texture
, 1);
5887 ok(SUCCEEDED(hr
), "Failed lock texture, hr %#x.\n", hr
);
5891 rect
.right
= formats
[i
].block_width
== 1 ? 1 : formats
[i
].block_width
>> 1;
5892 rect
.bottom
= formats
[i
].block_height
== 1 ? 1 : formats
[i
].block_height
>> 1;
5893 hr
= IDirect3DTexture9_LockRect(texture
, 1, &locked_rect
, &rect
, 0);
5894 ok(SUCCEEDED(hr
), "Failed lock texture, hr %#x.\n", hr
);
5895 hr
= IDirect3DTexture9_UnlockRect(texture
, 1);
5896 ok(SUCCEEDED(hr
), "Failed lock texture, hr %#x.\n", hr
);
5898 rect
.right
= formats
[i
].block_width
;
5899 rect
.bottom
= formats
[i
].block_height
;
5900 hr
= IDirect3DTexture9_LockRect(texture
, 1, &locked_rect
, &rect
, 0);
5901 todo_wine
ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5903 IDirect3DTexture9_UnlockRect(texture
, 1);
5905 IDirect3DTexture9_Release(texture
);
5908 refcount
= IDirect3DDevice9_Release(device
);
5909 ok(!refcount
, "Device has %u references left.\n", refcount
);
5910 IDirect3D9_Release(d3d
);
5911 DestroyWindow(window
);
5914 static void test_set_palette(void)
5916 IDirect3DDevice9
*device
;
5921 PALETTEENTRY pal
[256];
5925 window
= CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW
,
5926 0, 0, 640, 480, 0, 0, 0, 0);
5927 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
5928 ok(!!d3d9
, "Failed to create a D3D object.\n");
5929 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
5931 skip("Failed to create a D3D device, skipping tests.\n");
5932 DestroyWindow(window
);
5936 for (i
= 0; i
< sizeof(pal
) / sizeof(*pal
); i
++)
5941 pal
[i
].peFlags
= 0xff;
5943 hr
= IDirect3DDevice9_SetPaletteEntries(device
, 0, pal
);
5944 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
5946 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
5947 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
5948 for (i
= 0; i
< sizeof(pal
) / sizeof(*pal
); i
++)
5955 if (caps
.TextureCaps
& D3DPTEXTURECAPS_ALPHAPALETTE
)
5957 hr
= IDirect3DDevice9_SetPaletteEntries(device
, 0, pal
);
5958 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
5962 hr
= IDirect3DDevice9_SetPaletteEntries(device
, 0, pal
);
5963 ok(hr
== D3DERR_INVALIDCALL
, "SetPaletteEntries returned %#x, expected D3DERR_INVALIDCALL.\n", hr
);
5966 refcount
= IDirect3DDevice9_Release(device
);
5967 ok(!refcount
, "Device has %u references left.\n", refcount
);
5968 IDirect3D9_Release(d3d9
);
5969 DestroyWindow(window
);
5972 static void test_swvp_buffer(void)
5974 IDirect3DDevice9
*device
;
5980 IDirect3DVertexBuffer9
*buffer
;
5981 static const unsigned int bufsize
= 1024;
5982 D3DVERTEXBUFFER_DESC desc
;
5983 D3DPRESENT_PARAMETERS present_parameters
= {0};
5989 window
= CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW
,
5990 0, 0, 640, 480, 0, 0, 0, 0);
5991 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
5992 ok(!!d3d9
, "Failed to create a D3D object.\n");
5994 present_parameters
.Windowed
= TRUE
;
5995 present_parameters
.hDeviceWindow
= window
;
5996 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
5997 present_parameters
.BackBufferWidth
= screen_width
;
5998 present_parameters
.BackBufferHeight
= screen_height
;
5999 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
6000 present_parameters
.EnableAutoDepthStencil
= FALSE
;
6001 if (FAILED(IDirect3D9_CreateDevice(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, window
,
6002 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
)))
6004 skip("Failed to create a D3D device, skipping tests.\n");
6005 DestroyWindow(window
);
6006 IDirect3D9_Release(d3d9
);
6010 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, bufsize
* sizeof(*ptr
), D3DUSAGE_DYNAMIC
| D3DUSAGE_WRITEONLY
, 0,
6011 D3DPOOL_DEFAULT
, &buffer
, NULL
);
6012 ok(SUCCEEDED(hr
), "Failed to create buffer, hr %#x.\n", hr
);
6013 hr
= IDirect3DVertexBuffer9_GetDesc(buffer
, &desc
);
6014 ok(SUCCEEDED(hr
), "Failed to get desc, hr %#x.\n", hr
);
6015 ok(desc
.Pool
== D3DPOOL_DEFAULT
, "Got pool %u, expected D3DPOOL_DEFAULT\n", desc
.Pool
);
6016 ok(desc
.Usage
== (D3DUSAGE_DYNAMIC
| D3DUSAGE_WRITEONLY
),
6017 "Got usage %u, expected D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY\n", desc
.Usage
);
6019 hr
= IDirect3DVertexBuffer9_Lock(buffer
, 0, bufsize
* sizeof(*ptr
), (void **)&ptr
, D3DLOCK_DISCARD
);
6020 ok(SUCCEEDED(hr
), "Failed to lock buffer, hr %#x.\n", hr
);
6021 for (i
= 0; i
< bufsize
; i
++)
6023 ptr
[i
].x
= i
* 1.0f
;
6024 ptr
[i
].y
= i
* 2.0f
;
6025 ptr
[i
].z
= i
* 3.0f
;
6027 hr
= IDirect3DVertexBuffer9_Unlock(buffer
);
6028 ok(SUCCEEDED(hr
), "Failed to unlock buffer, hr %#x.\n", hr
);
6030 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
6031 ok(SUCCEEDED(hr
), "Failed to set fvf, hr %#x.\n", hr
);
6032 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, buffer
, 0, sizeof(*ptr
));
6033 ok(SUCCEEDED(hr
), "Failed to set stream source, hr %#x.\n", hr
);
6034 hr
= IDirect3DDevice9_BeginScene(device
);
6035 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6036 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLELIST
, 0, 2);
6037 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6038 hr
= IDirect3DDevice9_EndScene(device
);
6039 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6041 hr
= IDirect3DVertexBuffer9_Lock(buffer
, 0, bufsize
* sizeof(*ptr2
), (void **)&ptr2
, D3DLOCK_DISCARD
);
6042 ok(SUCCEEDED(hr
), "Failed to lock buffer, hr %#x.\n", hr
);
6043 ok(ptr
== ptr2
, "Lock returned two different pointers: %p, %p\n", ptr
, ptr2
);
6044 for (i
= 0; i
< bufsize
; i
++)
6046 if (ptr2
[i
].x
!= i
* 1.0f
|| ptr2
[i
].y
!= i
* 2.0f
|| ptr2
[i
].z
!= i
* 3.0f
)
6048 ok(FALSE
, "Vertex %u is %f,%f,%f, expected %f,%f,%f\n", i
,
6049 ptr2
[i
].x
, ptr2
[i
].y
, ptr2
[i
].z
, i
* 1.0f
, i
* 2.0f
, i
* 3.0f
);
6053 hr
= IDirect3DVertexBuffer9_Unlock(buffer
);
6054 ok(SUCCEEDED(hr
), "Failed to unlock buffer, hr %#x.\n", hr
);
6056 IDirect3DVertexBuffer9_Release(buffer
);
6057 refcount
= IDirect3DDevice9_Release(device
);
6058 ok(!refcount
, "Device has %u references left.\n", refcount
);
6059 IDirect3D9_Release(d3d9
);
6060 DestroyWindow(window
);
6063 static void test_npot_textures(void)
6065 IDirect3DDevice9
*device
= NULL
;
6071 IDirect3DTexture9
*texture
;
6072 IDirect3DCubeTexture9
*cube_texture
;
6073 IDirect3DVolumeTexture9
*volume_texture
;
6077 const char *pool_name
;
6082 { D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", D3DERR_INVALIDCALL
},
6083 { D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", D3DERR_INVALIDCALL
},
6084 { D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", D3DERR_INVALIDCALL
},
6085 { D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", D3D_OK
},
6087 unsigned int i
, levels
;
6088 BOOL tex_pow2
, cube_pow2
, vol_pow2
;
6090 window
= CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW
,
6091 0, 0, 640, 480, 0, 0, 0, 0);
6092 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
6093 ok(!!d3d9
, "Failed to create a D3D object.\n");
6094 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
6096 skip("Failed to create a D3D device, skipping tests.\n");
6100 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
6101 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6102 tex_pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
);
6103 cube_pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP_POW2
);
6104 vol_pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP_POW2
);
6105 ok(cube_pow2
== tex_pow2
, "Cube texture and 2d texture pow2 restrictions mismatch.\n");
6106 ok(vol_pow2
== tex_pow2
, "Volume texture and 2d texture pow2 restrictions mismatch.\n");
6108 for (i
= 0; i
< sizeof(pools
) / sizeof(*pools
); i
++)
6110 for (levels
= 0; levels
<= 2; levels
++)
6114 hr
= IDirect3DDevice9_CreateTexture(device
, 10, 10, levels
, 0, D3DFMT_X8R8G8B8
,
6115 pools
[i
].pool
, &texture
, NULL
);
6120 else if (caps
.TextureCaps
& D3DPTEXTURECAPS_NONPOW2CONDITIONAL
)
6125 expected
= pools
[i
].hr
;
6129 expected
= pools
[i
].hr
;
6131 ok(hr
== expected
, "CreateTexture(w=h=10, %s, levels=%u) returned hr %#x, expected %#x.\n",
6132 pools
[i
].pool_name
, levels
, hr
, expected
);
6135 IDirect3DTexture9_Release(texture
);
6138 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 3, 1, 0, D3DFMT_X8R8G8B8
, pools
[i
].pool
,
6139 &cube_texture
, NULL
);
6142 ok(hr
== pools
[i
].hr
, "CreateCubeTexture(EdgeLength=3, %s) returned hr %#x, expected %#x.\n",
6143 pools
[i
].pool_name
, hr
, pools
[i
].hr
);
6147 ok(SUCCEEDED(hr
), "CreateCubeTexture(EdgeLength=3, %s) returned hr %#x, expected %#x.\n",
6148 pools
[i
].pool_name
, hr
, D3D_OK
);
6152 IDirect3DCubeTexture9_Release(cube_texture
);
6154 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 2, 2, 3, 1, 0, D3DFMT_X8R8G8B8
, pools
[i
].pool
,
6155 &volume_texture
, NULL
);
6158 ok(hr
== pools
[i
].hr
, "CreateVolumeTextur(Depth=3, %s) returned hr %#x, expected %#x.\n",
6159 pools
[i
].pool_name
, hr
, pools
[i
].hr
);
6163 ok(SUCCEEDED(hr
), "CreateVolumeTextur(Depth=3, %s) returned hr %#x, expected %#x.\n",
6164 pools
[i
].pool_name
, hr
, D3D_OK
);
6168 IDirect3DVolumeTexture9_Release(volume_texture
);
6174 refcount
= IDirect3DDevice9_Release(device
);
6175 ok(!refcount
, "Device has %u references left.\n", refcount
);
6177 IDirect3D9_Release(d3d9
);
6178 DestroyWindow(window
);
6182 static void test_vidmem_accounting(void)
6184 IDirect3DDevice9
*device
;
6188 HRESULT hr
= D3D_OK
;
6189 IDirect3DTexture9
*textures
[20];
6191 UINT vidmem_start
, vidmem_end
, diff
;
6193 window
= CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW
,
6194 0, 0, 640, 480, 0, 0, 0, 0);
6195 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
6196 ok(!!d3d9
, "Failed to create a D3D object.\n");
6197 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
6199 skip("Failed to create a D3D device, skipping tests.\n");
6200 IDirect3D9_Release(d3d9
);
6201 DestroyWindow(window
);
6205 vidmem_start
= IDirect3DDevice9_GetAvailableTextureMem(device
);
6206 memset(textures
, 0, sizeof(textures
));
6207 for (i
= 0; i
< sizeof(textures
) / sizeof(*textures
) && SUCCEEDED(hr
); i
++)
6209 hr
= IDirect3DDevice9_CreateTexture(device
, 1024, 1024, 1, D3DUSAGE_RENDERTARGET
,
6210 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &textures
[i
], NULL
);
6211 /* D3DERR_OUTOFVIDEOMEMORY is returned when the card runs out of video memory
6212 * E_FAIL is returned on address space or system memory exhaustion */
6213 ok(SUCCEEDED(hr
) || hr
== D3DERR_OUTOFVIDEOMEMORY
|| hr
== E_OUTOFMEMORY
,
6214 "Failed to create texture, hr %#x.\n", hr
);
6216 vidmem_end
= IDirect3DDevice9_GetAvailableTextureMem(device
);
6218 ok(vidmem_start
> vidmem_end
, "Expected available texture memory to decrease during texture creation.\n");
6219 diff
= vidmem_start
- vidmem_end
;
6220 ok(diff
> 1024 * 1024 * 2 * i
, "Expected a video memory difference of at least %u MB, got %u MB.\n",
6221 2 * i
, diff
/ 1024 / 1024);
6223 for (i
= 0; i
< sizeof(textures
) / sizeof(*textures
); i
++)
6226 IDirect3DTexture9_Release(textures
[i
]);
6229 refcount
= IDirect3DDevice9_Release(device
);
6230 ok(!refcount
, "Device has %u references left.\n", refcount
);
6231 IDirect3D9_Release(d3d9
);
6232 DestroyWindow(window
);
6235 static void test_volume_locking(void)
6237 IDirect3DDevice9
*device
;
6241 IDirect3DVolumeTexture9
*texture
;
6243 D3DLOCKED_BOX locked_box
;
6250 HRESULT create_hr
, lock_hr
;
6254 { D3DPOOL_DEFAULT
, 0, D3D_OK
, D3DERR_INVALIDCALL
},
6255 { D3DPOOL_DEFAULT
, D3DUSAGE_DYNAMIC
, D3D_OK
, D3D_OK
},
6256 { D3DPOOL_SYSTEMMEM
, 0, D3D_OK
, D3D_OK
},
6257 { D3DPOOL_SYSTEMMEM
, D3DUSAGE_DYNAMIC
, D3D_OK
, D3D_OK
},
6258 { D3DPOOL_MANAGED
, 0, D3D_OK
, D3D_OK
},
6259 { D3DPOOL_MANAGED
, D3DUSAGE_DYNAMIC
, D3DERR_INVALIDCALL
, D3D_OK
},
6260 { D3DPOOL_SCRATCH
, 0, D3D_OK
, D3D_OK
},
6261 { D3DPOOL_SCRATCH
, D3DUSAGE_DYNAMIC
, D3DERR_INVALIDCALL
, D3D_OK
},
6264 window
= CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW
,
6265 0, 0, 640, 480, 0, 0, 0, 0);
6266 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
6267 ok(!!d3d9
, "Failed to create a D3D object.\n");
6268 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
6270 skip("Failed to create a D3D device, skipping tests.\n");
6271 IDirect3D9_Release(d3d9
);
6272 DestroyWindow(window
);
6276 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
6277 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6278 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
))
6280 skip("Volume textures not supported, skipping test.\n");
6284 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
6286 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 4, 4, 4, 1, tests
[i
].usage
,
6287 D3DFMT_A8R8G8B8
, tests
[i
].pool
, &texture
, NULL
);
6288 ok(hr
== tests
[i
].create_hr
, "Creating volume texture pool=%u, usage=%#x returned %#x, expected %#x.\n",
6289 tests
[i
].pool
, tests
[i
].usage
, hr
, tests
[i
].create_hr
);
6293 locked_box
.pBits
= (void *)0xdeadbeef;
6294 hr
= IDirect3DVolumeTexture9_LockBox(texture
, 0, &locked_box
, NULL
, 0);
6295 ok(hr
== tests
[i
].lock_hr
, "Lock returned %#x, expected %#x.\n", hr
, tests
[i
].lock_hr
);
6298 hr
= IDirect3DVolumeTexture9_UnlockBox(texture
, 0);
6299 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6303 ok (locked_box
.pBits
== NULL
, "Failed lock set pBits = %p, expected NULL.\n", locked_box
.pBits
);
6305 IDirect3DVolumeTexture9_Release(texture
);
6309 refcount
= IDirect3DDevice9_Release(device
);
6310 ok(!refcount
, "Device has %u references left.\n", refcount
);
6311 IDirect3D9_Release(d3d9
);
6312 DestroyWindow(window
);
6315 static void test_update_volumetexture(void)
6317 IDirect3DDevice9
*device
;
6321 IDirect3DVolumeTexture9
*src
, *dst
;
6323 D3DLOCKED_BOX locked_box
;
6328 D3DPOOL src_pool
, dst_pool
;
6333 { D3DPOOL_DEFAULT
, D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
},
6334 { D3DPOOL_MANAGED
, D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
},
6335 { D3DPOOL_SYSTEMMEM
, D3DPOOL_DEFAULT
, D3D_OK
},
6336 { D3DPOOL_SCRATCH
, D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
},
6338 { D3DPOOL_DEFAULT
, D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
},
6339 { D3DPOOL_MANAGED
, D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
},
6340 { D3DPOOL_SYSTEMMEM
, D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
},
6341 { D3DPOOL_SCRATCH
, D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
},
6343 { D3DPOOL_DEFAULT
, D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
},
6344 { D3DPOOL_MANAGED
, D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
},
6345 { D3DPOOL_SYSTEMMEM
, D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
},
6346 { D3DPOOL_SCRATCH
, D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
},
6348 { D3DPOOL_DEFAULT
, D3DPOOL_SCRATCH
, D3DERR_INVALIDCALL
},
6349 { D3DPOOL_MANAGED
, D3DPOOL_SCRATCH
, D3DERR_INVALIDCALL
},
6350 { D3DPOOL_SYSTEMMEM
, D3DPOOL_SCRATCH
, D3DERR_INVALIDCALL
},
6351 { D3DPOOL_SCRATCH
, D3DPOOL_SCRATCH
, D3DERR_INVALIDCALL
},
6355 UINT src_size
, dst_size
;
6356 UINT src_lvl
, dst_lvl
;
6357 D3DFORMAT src_fmt
, dst_fmt
;
6361 { 8, 8, 0, 0, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
6362 { 8, 8, 4, 4, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
6363 { 8, 8, 2, 2, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
6364 { 8, 8, 1, 1, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
6365 { 8, 8, 4, 0, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
6366 { 8, 8, 1, 4, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
}, /* Different level count */
6367 { 4, 8, 1, 1, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
}, /* Different size */
6368 { 8, 8, 4, 4, D3DFMT_A8R8G8B8
, D3DFMT_X8R8G8B8
}, /* Different format */
6371 window
= CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW
,
6372 0, 0, 640, 480, 0, 0, 0, 0);
6373 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
6374 ok(!!d3d9
, "Failed to create a D3D object.\n");
6375 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
6377 skip("Failed to create a D3D device, skipping tests.\n");
6378 IDirect3D9_Release(d3d9
);
6379 DestroyWindow(window
);
6383 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
6384 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6385 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
))
6387 skip("Volume textures not supported, skipping test.\n");
6391 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
6393 DWORD src_usage
= tests
[i
].src_pool
== D3DPOOL_DEFAULT
? D3DUSAGE_DYNAMIC
: 0;
6394 DWORD dst_usage
= tests
[i
].dst_pool
== D3DPOOL_DEFAULT
? D3DUSAGE_DYNAMIC
: 0;
6396 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 1, 1, 1, 1, src_usage
,
6397 D3DFMT_A8R8G8B8
, tests
[i
].src_pool
, &src
, NULL
);
6398 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
6399 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 1, 1, 1, 1, dst_usage
,
6400 D3DFMT_A8R8G8B8
, tests
[i
].dst_pool
, &dst
, NULL
);
6401 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
6403 hr
= IDirect3DVolumeTexture9_LockBox(src
, 0, &locked_box
, NULL
, 0);
6404 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
6405 *((DWORD
*)locked_box
.pBits
) = 0x11223344;
6406 hr
= IDirect3DVolumeTexture9_UnlockBox(src
, 0);
6407 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6409 hr
= IDirect3DDevice9_UpdateTexture(device
, (IDirect3DBaseTexture9
*)src
, (IDirect3DBaseTexture9
*)dst
);
6410 ok(hr
== tests
[i
].hr
, "UpdateTexture returned %#x, expected %#x, src pool %x, dst pool %u.\n",
6411 hr
, tests
[i
].hr
, tests
[i
].src_pool
, tests
[i
].dst_pool
);
6415 DWORD content
= *((DWORD
*)locked_box
.pBits
);
6416 hr
= IDirect3DVolumeTexture9_LockBox(dst
, 0, &locked_box
, NULL
, 0);
6417 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
6418 ok(content
== 0x11223344, "Dest texture contained %#x, expected 0x11223344.\n", content
);
6419 hr
= IDirect3DVolumeTexture9_UnlockBox(dst
, 0);
6420 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6422 IDirect3DVolumeTexture9_Release(src
);
6423 IDirect3DVolumeTexture9_Release(dst
);
6426 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_MIPVOLUMEMAP
))
6428 skip("Mipmapped volume maps not supported.\n");
6432 for (i
= 0; i
< sizeof(tests2
) / sizeof(*tests2
); i
++)
6434 hr
= IDirect3DDevice9_CreateVolumeTexture(device
,
6435 tests2
[i
].src_size
, tests2
[i
].src_size
, tests2
[i
].src_size
,
6436 tests2
[i
].src_lvl
, 0, tests2
[i
].src_fmt
, D3DPOOL_SYSTEMMEM
, &src
, NULL
);
6437 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x, case %u.\n", hr
, i
);
6438 hr
= IDirect3DDevice9_CreateVolumeTexture(device
,
6439 tests2
[i
].dst_size
, tests2
[i
].dst_size
, tests2
[i
].dst_size
,
6440 tests2
[i
].dst_lvl
, 0, tests2
[i
].dst_fmt
, D3DPOOL_DEFAULT
, &dst
, NULL
);
6441 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x, case %u.\n", hr
, i
);
6443 hr
= IDirect3DDevice9_UpdateTexture(device
, (IDirect3DBaseTexture9
*)src
, (IDirect3DBaseTexture9
*)dst
);
6445 todo_wine
ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x, case %u.\n", hr
, i
);
6447 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x, case %u.\n", hr
, i
);
6449 IDirect3DVolumeTexture9_Release(src
);
6450 IDirect3DVolumeTexture9_Release(dst
);
6453 /* As far as I can see, UpdateTexture on non-matching texture behaves like a memcpy. The raw data
6454 * stays the same in a format change, a 2x2x1 texture is copied into the first row of a 4x4x1 texture,
6455 * etc. I could not get it to segfault, but the nonexistent 5th pixel of a 2x2x1 texture is copied into
6456 * pixel 1x2x1 of a 4x4x1 texture, demonstrating a read beyond the texture's end. I suspect any bad
6457 * memory access is silently ignored by the runtime, in the kernel or on the GPU.
6459 * I'm not adding tests for this behavior until an application needs it. */
6462 refcount
= IDirect3DDevice9_Release(device
);
6463 ok(!refcount
, "Device has %u references left.\n", refcount
);
6464 IDirect3D9_Release(d3d9
);
6465 DestroyWindow(window
);
6468 static void test_create_rt_ds_fail(void)
6470 IDirect3DDevice9
*device
;
6475 IDirect3DSurface9
*surface
;
6477 window
= CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW
,
6478 0, 0, 640, 480, 0, 0, 0, 0);
6479 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
6480 ok(!!d3d9
, "Failed to create a D3D object.\n");
6481 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
6483 skip("Failed to create a D3D device, skipping tests.\n");
6484 IDirect3D9_Release(d3d9
);
6485 DestroyWindow(window
);
6489 /* Output pointer == NULL segfaults on Windows. */
6491 surface
= (IDirect3DSurface9
*)0xdeadbeef;
6492 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 4, 4, D3DFMT_D16
,
6493 D3DMULTISAMPLE_NONE
, 0, FALSE
, &surface
, NULL
);
6494 ok(hr
== D3DERR_INVALIDCALL
, "Creating a D16 render target returned hr %#x.\n", hr
);
6495 ok(surface
== NULL
, "Got pointer %p, expected NULL.\n", surface
);
6497 IDirect3DSurface9_Release(surface
);
6499 surface
= (IDirect3DSurface9
*)0xdeadbeef;
6500 hr
= IDirect3DDevice9_CreateDepthStencilSurface(device
, 4, 4, D3DFMT_A8R8G8B8
,
6501 D3DMULTISAMPLE_NONE
, 0, TRUE
, &surface
, NULL
);
6502 ok(hr
== D3DERR_INVALIDCALL
, "Creating a A8R8G8B8 depth stencil returned hr %#x.\n", hr
);
6503 ok(surface
== NULL
, "Got pointer %p, expected NULL.\n", surface
);
6505 IDirect3DSurface9_Release(surface
);
6507 refcount
= IDirect3DDevice9_Release(device
);
6508 ok(!refcount
, "Device has %u references left.\n", refcount
);
6509 IDirect3D9_Release(d3d9
);
6510 DestroyWindow(window
);
6513 static void test_volume_blocks(void)
6515 IDirect3DDevice9
*device
;
6521 IDirect3DVolumeTexture9
*texture
;
6522 unsigned int w
, h
, d
, i
, j
;
6527 unsigned int block_width
;
6528 unsigned int block_height
;
6529 unsigned int block_depth
;
6530 unsigned int block_size
;
6532 BOOL create_size_checked
, core_fmt
;
6536 /* Scratch volumes enforce DXTn block locks, unlike their surface counterparts.
6537 * ATI2N and YUV blocks are not enforced on any tested card (r200, gtx 460). */
6538 {D3DFMT_DXT1
, "D3DFMT_DXT1", 4, 4, 1, 8, FALSE
, TRUE
, TRUE
},
6539 {D3DFMT_DXT2
, "D3DFMT_DXT2", 4, 4, 1, 16, FALSE
, TRUE
, TRUE
},
6540 {D3DFMT_DXT3
, "D3DFMT_DXT3", 4, 4, 1, 16, FALSE
, TRUE
, TRUE
},
6541 {D3DFMT_DXT4
, "D3DFMT_DXT4", 4, 4, 1, 16, FALSE
, TRUE
, TRUE
},
6542 {D3DFMT_DXT5
, "D3DFMT_DXT5", 4, 4, 1, 16, FALSE
, TRUE
, TRUE
},
6543 {D3DFMT_DXT5
, "D3DFMT_DXT5", 4, 4, 1, 16, FALSE
, TRUE
, TRUE
},
6544 /* ATI2N has 2x2 blocks on all AMD cards and Geforce 7 cards,
6545 * which doesn't match the format spec. On newer Nvidia cards
6546 * it has the correct 4x4 block size */
6547 {MAKEFOURCC('A','T','I','2'), "ATI2N", 4, 4, 1, 16, TRUE
, FALSE
, FALSE
},
6548 {D3DFMT_YUY2
, "D3DFMT_YUY2", 2, 1, 1, 4, TRUE
, FALSE
, TRUE
},
6549 {D3DFMT_UYVY
, "D3DFMT_UYVY", 2, 1, 1, 4, TRUE
, FALSE
, TRUE
},
6555 BOOL need_driver_support
, need_runtime_support
;
6559 {D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", TRUE
, FALSE
},
6560 {D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", FALSE
, TRUE
},
6561 {D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM",TRUE
, FALSE
},
6562 {D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
, FALSE
},
6566 unsigned int x
, y
, z
, x2
, y2
, z2
;
6580 D3DLOCKED_BOX locked_box
;
6582 INT expected_row_pitch
, expected_slice_pitch
;
6583 BOOL support
, support_2d
;
6585 unsigned int offset
, expected_offset
;
6587 window
= CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW
,
6588 0, 0, 640, 480, 0, 0, 0, 0);
6589 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
6590 ok(!!d3d9
, "Failed to create a D3D object.\n");
6591 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
6593 skip("Failed to create a D3D device, skipping tests.\n");
6594 IDirect3D9_Release(d3d9
);
6595 DestroyWindow(window
);
6598 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
6599 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6600 pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP_POW2
);
6602 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
6604 hr
= IDirect3D9_CheckDeviceFormat(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
6605 0, D3DRTYPE_VOLUMETEXTURE
, formats
[i
].fmt
);
6606 support
= SUCCEEDED(hr
);
6607 hr
= IDirect3D9_CheckDeviceFormat(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
6608 0, D3DRTYPE_TEXTURE
, formats
[i
].fmt
);
6609 support_2d
= SUCCEEDED(hr
);
6611 /* Test creation restrictions */
6612 for (w
= 1; w
<= 8; w
++)
6614 for (h
= 1; h
<= 8; h
++)
6616 for (d
= 1; d
<= 8; d
++)
6620 BOOL block_aligned
= TRUE
;
6622 if (w
& (formats
[i
].block_width
- 1) || h
& (formats
[i
].block_height
- 1))
6623 block_aligned
= FALSE
;
6625 size_is_pow2
= !((w
& (w
- 1)) || (h
& (h
- 1)) || (d
& (d
- 1)));
6627 for (j
= 0; j
< sizeof(create_tests
) / sizeof(*create_tests
); j
++)
6629 BOOL may_succeed
= FALSE
;
6632 if (create_tests
[j
].need_runtime_support
&& !formats
[i
].core_fmt
&& !support
)
6633 expect_hr
= D3DERR_INVALIDCALL
;
6634 else if (formats
[i
].create_size_checked
&& !block_aligned
)
6635 expect_hr
= D3DERR_INVALIDCALL
;
6636 else if (pow2
&& !size_is_pow2
&& create_tests
[j
].need_driver_support
)
6637 expect_hr
= D3DERR_INVALIDCALL
;
6638 else if (create_tests
[j
].need_driver_support
&& !support
)
6641 expect_hr
= D3DERR_INVALIDCALL
;
6646 texture
= (IDirect3DVolumeTexture9
*)0xdeadbeef;
6647 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, w
, h
, d
, 1, 0,
6648 formats
[i
].fmt
, create_tests
[j
].pool
, &texture
, NULL
);
6650 /* Wine knows about ATI2N and happily creates a scratch resource even if GL
6651 * does not support it. Accept scratch creation of extension formats on
6652 * Windows as well if it occurs. We don't really care if e.g. a Windows 7
6653 * on an r200 GPU creates scratch ATI2N texture even though the card doesn't
6655 if (!formats
[i
].core_fmt
&& !support
&& FAILED(expect_hr
))
6660 todo_wine
ok(hr
== expect_hr
|| ((SUCCEEDED(hr
) && may_succeed
)),
6661 "Got unexpected hr %#x for format %s, pool %s, size %ux%ux%u.\n",
6662 hr
, formats
[i
].name
, create_tests
[j
].name
, w
, h
, d
);
6666 ok(hr
== expect_hr
|| ((SUCCEEDED(hr
) && may_succeed
)),
6667 "Got unexpected hr %#x for format %s, pool %s, size %ux%ux%u.\n",
6668 hr
, formats
[i
].name
, create_tests
[j
].name
, w
, h
, d
);
6672 ok(texture
== NULL
, "Got texture ptr %p, expected NULL.\n", texture
);
6674 IDirect3DVolumeTexture9_Release(texture
);
6680 if (!support
&& !formats
[i
].core_fmt
)
6683 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 24, 8, 8, 1, 0,
6684 formats
[i
].fmt
, D3DPOOL_SCRATCH
, &texture
, NULL
);
6685 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
6687 /* Test lockrect offset */
6688 for (j
= 0; j
< sizeof(offset_tests
) / sizeof(*offset_tests
); j
++)
6690 unsigned int bytes_per_pixel
;
6691 bytes_per_pixel
= formats
[i
].block_size
/ (formats
[i
].block_width
* formats
[i
].block_height
);
6693 hr
= IDirect3DVolumeTexture9_LockBox(texture
, 0, &locked_box
, NULL
, 0);
6694 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6696 base
= locked_box
.pBits
;
6697 if (formats
[i
].broken
)
6699 expected_row_pitch
= bytes_per_pixel
* 24;
6703 expected_row_pitch
= (24 /* tex width */ + formats
[i
].block_height
- 1) / formats
[i
].block_width
6704 * formats
[i
].block_size
;
6706 ok(locked_box
.RowPitch
== expected_row_pitch
, "Got unexpected row pitch %d for format %s, expected %d.\n",
6707 locked_box
.RowPitch
, formats
[i
].name
, expected_row_pitch
);
6709 if (formats
[i
].broken
)
6711 expected_slice_pitch
= expected_row_pitch
* 8;
6715 expected_slice_pitch
= (8 /* tex height */ + formats
[i
].block_depth
- 1) / formats
[i
].block_height
6716 * expected_row_pitch
;
6718 ok(locked_box
.SlicePitch
== expected_slice_pitch
,
6719 "Got unexpected slice pitch %d for format %s, expected %d.\n",
6720 locked_box
.SlicePitch
, formats
[i
].name
, expected_slice_pitch
);
6722 hr
= IDirect3DVolumeTexture9_UnlockBox(texture
, 0);
6723 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x, j %u.\n", hr
, j
);
6725 box
.Left
= offset_tests
[j
].x
;
6726 box
.Top
= offset_tests
[j
].y
;
6727 box
.Front
= offset_tests
[j
].z
;
6728 box
.Right
= offset_tests
[j
].x2
;
6729 box
.Bottom
= offset_tests
[j
].y2
;
6730 box
.Back
= offset_tests
[j
].z2
;
6731 hr
= IDirect3DVolumeTexture9_LockBox(texture
, 0, &locked_box
, &box
, 0);
6732 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x, j %u.\n", hr
, j
);
6734 offset
= (BYTE
*)locked_box
.pBits
- base
;
6735 if (formats
[i
].broken
)
6737 expected_offset
= box
.Front
* expected_slice_pitch
6738 + box
.Top
* expected_row_pitch
6739 + box
.Left
* bytes_per_pixel
;
6743 expected_offset
= (box
.Front
/ formats
[i
].block_depth
) * expected_slice_pitch
6744 + (box
.Top
/ formats
[i
].block_height
) * expected_row_pitch
6745 + (box
.Left
/ formats
[i
].block_width
) * formats
[i
].block_size
;
6747 ok(offset
== expected_offset
, "Got unexpected offset %u for format %s, expected %u, box start %ux%ux%u.\n",
6748 offset
, formats
[i
].name
, expected_offset
, box
.Left
, box
.Top
, box
.Front
);
6750 hr
= IDirect3DVolumeTexture9_UnlockBox(texture
, 0);
6751 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6754 /* Test partial block locks */
6757 if (formats
[i
].block_width
> 1)
6759 box
.Left
= formats
[i
].block_width
>> 1;
6761 box
.Right
= formats
[i
].block_width
;
6762 box
.Bottom
= formats
[i
].block_height
;
6763 hr
= IDirect3DVolumeTexture9_LockBox(texture
, 0, &locked_box
, &box
, 0);
6764 ok(FAILED(hr
) || broken(formats
[i
].broken
),
6765 "Partial block lock succeeded, expected failure, format %s.\n",
6769 hr
= IDirect3DVolumeTexture9_UnlockBox(texture
, 0);
6770 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6775 box
.Right
= formats
[i
].block_width
>> 1;
6776 box
.Bottom
= formats
[i
].block_height
;
6777 hr
= IDirect3DVolumeTexture9_LockBox(texture
, 0, &locked_box
, &box
, 0);
6778 ok(FAILED(hr
) || broken(formats
[i
].broken
),
6779 "Partial block lock succeeded, expected failure, format %s.\n",
6783 hr
= IDirect3DVolumeTexture9_UnlockBox(texture
, 0);
6784 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6788 if (formats
[i
].block_height
> 1)
6791 box
.Top
= formats
[i
].block_height
>> 1;
6792 box
.Right
= formats
[i
].block_width
;
6793 box
.Bottom
= formats
[i
].block_height
;
6794 hr
= IDirect3DVolumeTexture9_LockBox(texture
, 0, &locked_box
, &box
, 0);
6795 ok(FAILED(hr
) || broken(formats
[i
].broken
),
6796 "Partial block lock succeeded, expected failure, format %s.\n",
6800 hr
= IDirect3DVolumeTexture9_UnlockBox(texture
, 0);
6801 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6806 box
.Right
= formats
[i
].block_width
;
6807 box
.Bottom
= formats
[i
].block_height
>> 1;
6808 hr
= IDirect3DVolumeTexture9_LockBox(texture
, 0, &locked_box
, &box
, 0);
6809 ok(FAILED(hr
) || broken(formats
[i
].broken
),
6810 "Partial block lock succeeded, expected failure, format %s.\n",
6814 hr
= IDirect3DVolumeTexture9_UnlockBox(texture
, 0);
6815 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6819 /* Test full block lock */
6822 box
.Right
= formats
[i
].block_width
;
6823 box
.Bottom
= formats
[i
].block_height
;
6824 hr
= IDirect3DVolumeTexture9_LockBox(texture
, 0, &locked_box
, &box
, 0);
6825 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
6826 hr
= IDirect3DVolumeTexture9_UnlockBox(texture
, 0);
6827 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6829 IDirect3DVolumeTexture9_Release(texture
);
6831 /* Test mipmap locks. Don't do this with ATI2N, AMD warns that the runtime
6832 * does not allocate surfaces smaller than the blocksize properly. */
6833 if ((formats
[i
].block_width
> 1 || formats
[i
].block_height
> 1) && formats
[i
].core_fmt
)
6835 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, formats
[i
].block_width
, formats
[i
].block_height
,
6836 2, 2, 0, formats
[i
].fmt
, D3DPOOL_SCRATCH
, &texture
, NULL
);
6838 hr
= IDirect3DVolumeTexture9_LockBox(texture
, 1, &locked_box
, NULL
, 0);
6839 ok(SUCCEEDED(hr
), "Failed to lock volume texture mipmap, hr %#x.\n", hr
);
6840 hr
= IDirect3DVolumeTexture9_UnlockBox(texture
, 1);
6841 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6843 box
.Left
= box
.Top
= box
.Front
= 0;
6844 box
.Right
= formats
[i
].block_width
== 1 ? 1 : formats
[i
].block_width
>> 1;
6845 box
.Bottom
= formats
[i
].block_height
== 1 ? 1 : formats
[i
].block_height
>> 1;
6847 hr
= IDirect3DVolumeTexture9_LockBox(texture
, 1, &locked_box
, &box
, 0);
6848 ok(SUCCEEDED(hr
), "Failed to lock volume texture mipmap, hr %#x.\n", hr
);
6849 hr
= IDirect3DVolumeTexture9_UnlockBox(texture
, 1);
6850 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6852 box
.Right
= formats
[i
].block_width
;
6853 box
.Bottom
= formats
[i
].block_height
;
6854 hr
= IDirect3DVolumeTexture9_LockBox(texture
, 1, &locked_box
, &box
, 0);
6855 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
6857 IDirect3DVolumeTexture9_UnlockBox(texture
, 1);
6859 IDirect3DVolumeTexture9_Release(texture
);
6863 refcount
= IDirect3DDevice9_Release(device
);
6864 ok(!refcount
, "Device has %u references left.\n", refcount
);
6865 IDirect3D9_Release(d3d9
);
6866 DestroyWindow(window
);
6869 static void test_lockbox_invalid(void)
6878 {{0, 0, 2, 2, 0, 1}, D3D_OK
}, /* Valid */
6879 {{0, 0, 4, 4, 0, 1}, D3D_OK
}, /* Valid */
6880 {{0, 0, 0, 4, 0, 1}, D3DERR_INVALIDCALL
}, /* 0 height */
6881 {{0, 0, 4, 0, 0, 1}, D3DERR_INVALIDCALL
}, /* 0 width */
6882 {{0, 0, 4, 4, 1, 1}, D3DERR_INVALIDCALL
}, /* 0 depth */
6883 {{4, 0, 0, 4, 0, 1}, D3DERR_INVALIDCALL
}, /* left > right */
6884 {{0, 4, 4, 0, 0, 1}, D3DERR_INVALIDCALL
}, /* top > bottom */
6885 {{0, 0, 4, 4, 1, 0}, D3DERR_INVALIDCALL
}, /* back > front */
6886 {{0, 0, 8, 4, 0, 1}, D3DERR_INVALIDCALL
}, /* right > surface */
6887 {{0, 0, 4, 8, 0, 1}, D3DERR_INVALIDCALL
}, /* bottom > surface */
6888 {{0, 0, 4, 4, 0, 3}, D3DERR_INVALIDCALL
}, /* back > surface */
6889 {{8, 0, 16, 4, 0, 1}, D3DERR_INVALIDCALL
}, /* left > surface */
6890 {{0, 8, 4, 16, 0, 1}, D3DERR_INVALIDCALL
}, /* top > surface */
6891 {{0, 0, 4, 4, 2, 4}, D3DERR_INVALIDCALL
}, /* top > surface */
6893 static const D3DBOX test_boxt_2
= {2, 2, 4, 4, 0, 1};
6894 IDirect3DVolumeTexture9
*texture
= NULL
;
6895 D3DLOCKED_BOX locked_box
;
6896 IDirect3DDevice9
*device
;
6904 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
6905 0, 0, 640, 480, 0, 0, 0, 0);
6906 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
6907 ok(!!d3d
, "Failed to create a D3D object.\n");
6908 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
6910 skip("Failed to create a D3D device, skipping tests.\n");
6911 IDirect3D9_Release(d3d
);
6912 DestroyWindow(window
);
6916 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 4, 4, 2, 1, 0,
6917 D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &texture
, NULL
);
6918 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
6919 hr
= IDirect3DVolumeTexture9_LockBox(texture
, 0, &locked_box
, NULL
, 0);
6920 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
6921 base
= locked_box
.pBits
;
6922 hr
= IDirect3DVolumeTexture9_UnlockBox(texture
, 0);
6923 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6925 for (i
= 0; i
< (sizeof(test_data
) / sizeof(*test_data
)); ++i
)
6927 unsigned int offset
, expected_offset
;
6928 const D3DBOX
*box
= &test_data
[i
].box
;
6930 locked_box
.pBits
= (BYTE
*)0xdeadbeef;
6931 locked_box
.RowPitch
= 0xdeadbeef;
6932 locked_box
.SlicePitch
= 0xdeadbeef;
6934 hr
= IDirect3DVolumeTexture9_LockBox(texture
, 0, &locked_box
, box
, 0);
6935 /* Unlike surfaces, volumes properly check the box even in Windows XP */
6936 ok(hr
== test_data
[i
].result
,
6937 "Got unexpected hr %#x with box [%u, %u, %u]->[%u, %u, %u], expected %#x.\n",
6938 hr
, box
->Left
, box
->Top
, box
->Front
, box
->Right
, box
->Bottom
, box
->Back
,
6939 test_data
[i
].result
);
6943 offset
= (BYTE
*)locked_box
.pBits
- base
;
6944 expected_offset
= box
->Front
* locked_box
.SlicePitch
+ box
->Top
* locked_box
.RowPitch
+ box
->Left
* 4;
6945 ok(offset
== expected_offset
,
6946 "Got unexpected offset %u (expected %u) for rect [%u, %u, %u]->[%u, %u, %u].\n",
6947 offset
, expected_offset
, box
->Left
, box
->Top
, box
->Front
, box
->Right
, box
->Bottom
, box
->Back
);
6949 hr
= IDirect3DVolumeTexture9_UnlockBox(texture
, 0);
6950 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6953 /* locked_box = NULL throws an exception on Windows */
6954 hr
= IDirect3DVolumeTexture9_LockBox(texture
, 0, &locked_box
, NULL
, 0);
6955 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
6956 hr
= IDirect3DVolumeTexture9_LockBox(texture
, 0, &locked_box
, NULL
, 0);
6957 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
6958 hr
= IDirect3DVolumeTexture9_UnlockBox(texture
, 0);
6959 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6960 hr
= IDirect3DVolumeTexture9_UnlockBox(texture
, 0);
6961 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
6963 hr
= IDirect3DVolumeTexture9_LockBox(texture
, 0, &locked_box
, &test_data
[0].box
, 0);
6964 ok(hr
== D3D_OK
, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
6965 hr
, test_data
[0].box
.Left
, test_data
[0].box
.Top
, test_data
[0].box
.Front
,
6966 test_data
[0].box
.Right
, test_data
[0].box
.Bottom
, test_data
[0].box
.Back
);
6967 hr
= IDirect3DVolumeTexture9_LockBox(texture
, 0, &locked_box
, &test_data
[0].box
, 0);
6968 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
6969 hr
, test_data
[0].box
.Left
, test_data
[0].box
.Top
, test_data
[0].box
.Front
,
6970 test_data
[0].box
.Right
, test_data
[0].box
.Bottom
, test_data
[0].box
.Back
);
6971 hr
= IDirect3DVolumeTexture9_LockBox(texture
, 0, &locked_box
, &test_boxt_2
, 0);
6972 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
6973 hr
, test_boxt_2
.Left
, test_boxt_2
.Top
, test_boxt_2
.Front
,
6974 test_boxt_2
.Right
, test_boxt_2
.Bottom
, test_boxt_2
.Back
);
6975 hr
= IDirect3DVolumeTexture9_UnlockBox(texture
, 0);
6976 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6978 IDirect3DVolumeTexture9_Release(texture
);
6979 refcount
= IDirect3DDevice9_Release(device
);
6980 ok(!refcount
, "Device has %u references left.\n", refcount
);
6981 IDirect3D9_Release(d3d
);
6982 DestroyWindow(window
);
6985 static void test_shared_handle(void)
6987 IDirect3DDevice9
*device
;
6992 /* Native d3d9ex refuses to create a shared texture if the texture pointer
6993 * is not initialized to NULL. Make sure this doesn't cause issues here. */
6994 IDirect3DTexture9
*texture
= NULL
;
6995 IDirect3DSurface9
*surface
= NULL
;
6996 IDirect3DVertexBuffer9
*vertex_buffer
= NULL
;
6997 IDirect3DIndexBuffer9
*index_buffer
= NULL
;
6998 HANDLE handle
= NULL
;
7002 window
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
7003 0, 0, 640, 480, 0, 0, 0, 0);
7004 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
7005 ok(!!d3d
, "Failed to create a D3D object.\n");
7006 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
7008 skip("Failed to create a D3D device, skipping tests.\n");
7009 IDirect3D9_Release(d3d
);
7010 DestroyWindow(window
);
7014 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
7015 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7016 mem
= HeapAlloc(GetProcessHeap(), 0, 128 * 128 * 4);
7018 /* Windows XP returns E_NOTIMPL, Windows 7 returns INVALIDCALL, except for
7019 * CreateVertexBuffer, where it returns NOTAVAILABLE. */
7020 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 1, 0, D3DFMT_A8R8G8B8
,
7021 D3DPOOL_DEFAULT
, &texture
, &handle
);
7022 ok(hr
== E_NOTIMPL
|| broken(hr
== D3DERR_INVALIDCALL
), "Got unexpected hr %#x.\n", hr
);
7023 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 1, 0, D3DFMT_A8R8G8B8
,
7024 D3DPOOL_SYSTEMMEM
, &texture
, &mem
);
7025 ok(hr
== E_NOTIMPL
|| broken(hr
== D3DERR_INVALIDCALL
), "Got unexpected hr %#x.\n", hr
);
7027 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 128, 128,
7028 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &surface
, &handle
);
7029 ok(hr
== E_NOTIMPL
|| broken(hr
== D3DERR_INVALIDCALL
), "Got unexpected hr %#x.\n", hr
);
7030 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 128, 128,
7031 D3DFMT_A8R8G8B8
, D3DPOOL_SYSTEMMEM
, &surface
, &mem
);
7032 ok(hr
== E_NOTIMPL
|| broken(hr
== D3DERR_INVALIDCALL
), "Got unexpected hr %#x.\n", hr
);
7034 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, 16, 0, 0, D3DPOOL_DEFAULT
,
7035 &vertex_buffer
, &handle
);
7036 ok(hr
== E_NOTIMPL
|| broken(hr
== D3DERR_INVALIDCALL
), "Got unexpected hr %#x.\n", hr
);
7037 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, 16, 0, 0, D3DPOOL_SYSTEMMEM
,
7038 &vertex_buffer
, &mem
);
7039 ok(hr
== E_NOTIMPL
|| broken(hr
== D3DERR_NOTAVAILABLE
), "Got unexpected hr %#x.\n", hr
);
7041 hr
= IDirect3DDevice9_CreateIndexBuffer(device
, 16, 0, 0, D3DPOOL_DEFAULT
,
7042 &index_buffer
, &handle
);
7043 ok(hr
== E_NOTIMPL
|| broken(hr
== D3DERR_INVALIDCALL
), "Got unexpected hr %#x.\n", hr
);
7044 hr
= IDirect3DDevice9_CreateIndexBuffer(device
, 16, 0, 0, D3DPOOL_SYSTEMMEM
,
7045 &index_buffer
, &mem
);
7046 ok(hr
== E_NOTIMPL
|| broken(hr
== D3DERR_INVALIDCALL
), "Got unexpected hr %#x.\n", hr
);
7048 if (caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
)
7050 IDirect3DCubeTexture9
*cube_texture
= NULL
;
7051 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 8, 0, 0, D3DFMT_A8R8G8B8
,
7052 D3DPOOL_DEFAULT
, &cube_texture
, &handle
);
7053 ok(hr
== E_NOTIMPL
|| broken(hr
== D3DERR_INVALIDCALL
), "Got unexpected hr %#x.\n", hr
);
7054 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 8, 0, 0, D3DFMT_A8R8G8B8
,
7055 D3DPOOL_SYSTEMMEM
, &cube_texture
, &mem
);
7056 ok(hr
== E_NOTIMPL
|| broken(hr
== D3DERR_INVALIDCALL
), "Got unexpected hr %#x.\n", hr
);
7059 if (caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
)
7061 IDirect3DVolumeTexture9
*volume_texture
= NULL
;
7062 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 4, 4, 4, 0, 0, D3DFMT_A8R8G8B8
,
7063 D3DPOOL_DEFAULT
, &volume_texture
, &handle
);
7064 ok(hr
== E_NOTIMPL
|| broken(hr
== D3DERR_INVALIDCALL
), "Got unexpected hr %#x.\n", hr
);
7065 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 4, 4, 4, 0, 0, D3DFMT_A8R8G8B8
,
7066 D3DPOOL_SYSTEMMEM
, &volume_texture
, &mem
);
7067 ok(hr
== E_NOTIMPL
|| broken(hr
== D3DERR_INVALIDCALL
), "Got unexpected hr %#x.\n", hr
);
7070 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 128, 128, D3DFMT_A8R8G8B8
,
7071 D3DMULTISAMPLE_NONE
, 0, TRUE
, &surface
, &handle
);
7072 ok(hr
== E_NOTIMPL
|| broken(hr
== D3DERR_INVALIDCALL
), "Got unexpected hr %#x.\n", hr
);
7074 hr
= IDirect3DDevice9_CreateDepthStencilSurface(device
, 128, 128, D3DFMT_D24X8
,
7075 D3DMULTISAMPLE_NONE
, 0, TRUE
, &surface
, &handle
);
7076 ok(hr
== E_NOTIMPL
|| broken(hr
== D3DERR_INVALIDCALL
), "Got unexpected hr %#x.\n", hr
);
7078 HeapFree(GetProcessHeap(), 0, mem
);
7079 refcount
= IDirect3DDevice9_Release(device
);
7080 ok(!refcount
, "Device has %u references left.\n", refcount
);
7081 IDirect3D9_Release(d3d
);
7082 DestroyWindow(window
);
7085 static void test_pixel_format(void)
7087 HWND hwnd
, hwnd2
= NULL
;
7088 HDC hdc
, hdc2
= NULL
;
7090 int format
, test_format
;
7091 PIXELFORMATDESCRIPTOR pfd
;
7092 IDirect3D9
*d3d9
= NULL
;
7093 IDirect3DDevice9
*device
= NULL
;
7095 static const float point
[3] = {0.0, 0.0, 0.0};
7097 hwnd
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
7098 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
7101 skip("Failed to create window\n");
7105 hwnd2
= CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW
,
7106 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
7111 skip("Failed to get DC\n");
7116 hdc2
= GetDC(hwnd2
);
7118 gl
= LoadLibraryA("opengl32.dll");
7119 ok(!!gl
, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
7121 format
= GetPixelFormat(hdc
);
7122 ok(format
== 0, "new window has pixel format %d\n", format
);
7124 ZeroMemory(&pfd
, sizeof(pfd
));
7125 pfd
.nSize
= sizeof(pfd
);
7127 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
7128 pfd
.iPixelType
= PFD_TYPE_RGBA
;
7129 pfd
.iLayerType
= PFD_MAIN_PLANE
;
7130 format
= ChoosePixelFormat(hdc
, &pfd
);
7133 skip("no pixel format available\n");
7137 if (!SetPixelFormat(hdc
, format
, &pfd
) || GetPixelFormat(hdc
) != format
)
7139 skip("failed to set pixel format\n");
7143 if (!hdc2
|| !SetPixelFormat(hdc2
, format
, &pfd
) || GetPixelFormat(hdc2
) != format
)
7145 skip("failed to set pixel format on second window\n");
7148 ReleaseDC(hwnd2
, hdc2
);
7153 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
7154 ok(!!d3d9
, "Failed to create a D3D object.\n");
7156 test_format
= GetPixelFormat(hdc
);
7157 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7159 if (!(device
= create_device(d3d9
, hwnd
, hwnd
, TRUE
)))
7161 skip("Failed to create device\n");
7165 test_format
= GetPixelFormat(hdc
);
7166 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7168 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
7169 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
7171 test_format
= GetPixelFormat(hdc
);
7172 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7174 hr
= IDirect3DDevice9_BeginScene(device
);
7175 ok(SUCCEEDED(hr
), "BeginScene failed %#x\n", hr
);
7177 test_format
= GetPixelFormat(hdc
);
7178 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7180 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_POINTLIST
, 1, point
, 3 * sizeof(float));
7181 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7183 test_format
= GetPixelFormat(hdc
);
7184 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7186 hr
= IDirect3DDevice9_EndScene(device
);
7187 ok(SUCCEEDED(hr
), "EndScene failed %#x\n", hr
);
7189 test_format
= GetPixelFormat(hdc
);
7190 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7192 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
7193 ok(SUCCEEDED(hr
), "Present failed %#x\n", hr
);
7195 test_format
= GetPixelFormat(hdc
);
7196 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7200 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, hwnd2
, NULL
);
7201 ok(SUCCEEDED(hr
), "Present failed %#x\n", hr
);
7203 test_format
= GetPixelFormat(hdc
);
7204 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7206 test_format
= GetPixelFormat(hdc2
);
7207 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7213 UINT refcount
= IDirect3DDevice9_Release(device
);
7214 ok(!refcount
, "Device has %u references left.\n", refcount
);
7216 if (d3d9
) IDirect3D9_Release(d3d9
);
7217 if (gl
) FreeLibrary(gl
);
7218 if (hdc
) ReleaseDC(hwnd
, hdc
);
7219 if (hdc2
) ReleaseDC(hwnd2
, hdc2
);
7220 if (hwnd
) DestroyWindow(hwnd
);
7221 if (hwnd2
) DestroyWindow(hwnd2
);
7224 static void test_begin_end_state_block(void)
7226 IDirect3DStateBlock9
*stateblock
;
7227 IDirect3DDevice9
*device
;
7233 window
= CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW
,
7234 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
7235 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
7236 ok(!!d3d
, "Failed to create a D3D object.\n");
7237 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
7239 skip("Failed to create a D3D device, skipping tests.\n");
7240 IDirect3D9_Release(d3d
);
7241 DestroyWindow(window
);
7245 /* Should succeed. */
7246 hr
= IDirect3DDevice9_BeginStateBlock(device
);
7247 ok(SUCCEEDED(hr
), "Failed to begin stateblock, hr %#x.\n", hr
);
7249 /* Calling BeginStateBlock() while recording should return
7250 * D3DERR_INVALIDCALL. */
7251 hr
= IDirect3DDevice9_BeginStateBlock(device
);
7252 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
7254 /* Should succeed. */
7255 stateblock
= (IDirect3DStateBlock9
*)0xdeadbeef;
7256 hr
= IDirect3DDevice9_EndStateBlock(device
, &stateblock
);
7257 ok(SUCCEEDED(hr
), "Failed to end stateblock, hr %#x.\n", hr
);
7258 ok(!!stateblock
&& stateblock
!= (IDirect3DStateBlock9
*)0xdeadbeef,
7259 "Got unexpected stateblock %p.\n", stateblock
);
7260 IDirect3DStateBlock9_Release(stateblock
);
7262 /* Calling EndStateBlock() while not recording should return
7263 * D3DERR_INVALIDCALL. stateblock should not be touched. */
7264 stateblock
= (IDirect3DStateBlock9
*)0xdeadbeef;
7265 hr
= IDirect3DDevice9_EndStateBlock(device
, &stateblock
);
7266 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
7267 ok(stateblock
== (IDirect3DStateBlock9
*)0xdeadbeef,
7268 "Got unexpected stateblock %p.\n", stateblock
);
7270 refcount
= IDirect3DDevice9_Release(device
);
7271 ok(!refcount
, "Device has %u references left.\n", refcount
);
7272 IDirect3D9_Release(d3d
);
7273 DestroyWindow(window
);
7276 static void test_shader_constant_apply(void)
7278 static const float vs_const
[] = {1.0f
, 2.0f
, 3.0f
, 4.0f
};
7279 static const float ps_const
[] = {5.0f
, 6.0f
, 7.0f
, 8.0f
};
7280 static const float initial
[] = {0.0f
, 0.0f
, 0.0f
, 0.0f
};
7281 IDirect3DStateBlock9
*stateblock
;
7282 DWORD vs_version
, ps_version
;
7283 IDirect3DDevice9
*device
;
7291 window
= CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW
,
7292 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
7293 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
7294 ok(!!d3d
, "Failed to create a D3D object.\n");
7295 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
7297 skip("Failed to create a D3D device, skipping tests.\n");
7298 IDirect3D9_Release(d3d
);
7299 DestroyWindow(window
);
7303 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
7304 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
7305 vs_version
= caps
.VertexShaderVersion
& 0xffff;
7306 ps_version
= caps
.PixelShaderVersion
& 0xffff;
7310 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 0, initial
, 1);
7311 ok(SUCCEEDED(hr
), "Failed to set vertex shader constant, hr %#x.\n", hr
);
7312 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 1, initial
, 1);
7313 ok(SUCCEEDED(hr
), "Failed to set vertex shader constant, hr %#x.\n", hr
);
7315 hr
= IDirect3DDevice9_GetVertexShaderConstantF(device
, 0, ret
, 1);
7316 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7317 ok(!memcmp(ret
, initial
, sizeof(initial
)),
7318 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7319 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
7320 hr
= IDirect3DDevice9_GetVertexShaderConstantF(device
, 1, ret
, 1);
7321 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7322 ok(!memcmp(ret
, initial
, sizeof(initial
)),
7323 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7324 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
7326 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 0, vs_const
, 1);
7327 ok(SUCCEEDED(hr
), "Failed to set vertex shader constant, hr %#x.\n", hr
);
7331 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 0, initial
, 1);
7332 ok(SUCCEEDED(hr
), "Failed to set pixel shader constant, hr %#x.\n", hr
);
7333 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 1, initial
, 1);
7334 ok(SUCCEEDED(hr
), "Failed to set pixel shader constant, hr %#x.\n", hr
);
7336 hr
= IDirect3DDevice9_GetPixelShaderConstantF(device
, 0, ret
, 1);
7337 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
7338 ok(!memcmp(ret
, initial
, sizeof(initial
)),
7339 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7340 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
7341 hr
= IDirect3DDevice9_GetPixelShaderConstantF(device
, 1, ret
, 1);
7342 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
7343 ok(!memcmp(ret
, initial
, sizeof(initial
)),
7344 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7345 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
7347 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 0, ps_const
, 1);
7348 ok(SUCCEEDED(hr
), "Failed to set pixel shader constant, hr %#x.\n", hr
);
7351 hr
= IDirect3DDevice9_BeginStateBlock(device
);
7352 ok(SUCCEEDED(hr
), "Failed to begin stateblock, hr %#x.\n", hr
);
7356 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 1, vs_const
, 1);
7357 ok(SUCCEEDED(hr
), "Failed to set vertex shader constant, hr %#x.\n", hr
);
7361 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 1, ps_const
, 1);
7362 ok(SUCCEEDED(hr
), "Failed to set pixel shader constant, hr %#x.\n", hr
);
7365 hr
= IDirect3DDevice9_EndStateBlock(device
, &stateblock
);
7366 ok(SUCCEEDED(hr
), "Failed to end stateblock, hr %#x.\n", hr
);
7370 hr
= IDirect3DDevice9_GetVertexShaderConstantF(device
, 0, ret
, 1);
7371 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7372 ok(!memcmp(ret
, vs_const
, sizeof(vs_const
)),
7373 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7374 ret
[0], ret
[1], ret
[2], ret
[3], vs_const
[0], vs_const
[1], vs_const
[2], vs_const
[3]);
7375 hr
= IDirect3DDevice9_GetVertexShaderConstantF(device
, 1, ret
, 1);
7376 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7377 ok(!memcmp(ret
, initial
, sizeof(initial
)),
7378 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7379 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
7383 hr
= IDirect3DDevice9_GetPixelShaderConstantF(device
, 0, ret
, 1);
7384 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
7385 ok(!memcmp(ret
, ps_const
, sizeof(ps_const
)),
7386 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7387 ret
[0], ret
[1], ret
[2], ret
[3], ps_const
[0], ps_const
[1], ps_const
[2], ps_const
[3]);
7388 hr
= IDirect3DDevice9_GetPixelShaderConstantF(device
, 1, ret
, 1);
7389 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
7390 ok(!memcmp(ret
, initial
, sizeof(initial
)),
7391 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7392 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
7395 /* Apply doesn't overwrite constants that aren't explicitly set on the
7396 * source stateblock. */
7397 hr
= IDirect3DStateBlock9_Apply(stateblock
);
7398 ok(SUCCEEDED(hr
), "Failed to apply stateblock, hr %#x.\n", hr
);
7402 hr
= IDirect3DDevice9_GetVertexShaderConstantF(device
, 0, ret
, 1);
7403 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7404 ok(!memcmp(ret
, vs_const
, sizeof(vs_const
)),
7405 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7406 ret
[0], ret
[1], ret
[2], ret
[3], vs_const
[0], vs_const
[1], vs_const
[2], vs_const
[3]);
7407 hr
= IDirect3DDevice9_GetVertexShaderConstantF(device
, 1, ret
, 1);
7408 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7409 ok(!memcmp(ret
, vs_const
, sizeof(vs_const
)),
7410 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7411 ret
[0], ret
[1], ret
[2], ret
[3], vs_const
[0], vs_const
[1], vs_const
[2], vs_const
[3]);
7415 hr
= IDirect3DDevice9_GetPixelShaderConstantF(device
, 0, ret
, 1);
7416 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
7417 ok(!memcmp(ret
, ps_const
, sizeof(ps_const
)),
7418 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7419 ret
[0], ret
[1], ret
[2], ret
[3], ps_const
[0], ps_const
[1], ps_const
[2], ps_const
[3]);
7420 hr
= IDirect3DDevice9_GetPixelShaderConstantF(device
, 1, ret
, 1);
7421 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
7422 ok(!memcmp(ret
, ps_const
, sizeof(ps_const
)),
7423 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7424 ret
[0], ret
[1], ret
[2], ret
[3], ps_const
[0], ps_const
[1], ps_const
[2], ps_const
[3]);
7427 IDirect3DStateBlock9_Release(stateblock
);
7428 refcount
= IDirect3DDevice9_Release(device
);
7429 ok(!refcount
, "Device has %u references left.\n", refcount
);
7430 IDirect3D9_Release(d3d
);
7431 DestroyWindow(window
);
7434 static void test_vdecl_apply(void)
7436 IDirect3DVertexDeclaration9
*declaration
, *declaration1
, *declaration2
;
7437 IDirect3DStateBlock9
*stateblock
;
7438 IDirect3DDevice9
*device
;
7444 static const D3DVERTEXELEMENT9 decl1
[] =
7446 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
7447 {0, 12, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
7451 static const D3DVERTEXELEMENT9 decl2
[] =
7453 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
7454 {0, 12, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
7455 {0, 16, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_NORMAL
, 0},
7459 window
= CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW
,
7460 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
7461 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
7462 ok(!!d3d
, "Failed to create a D3D object.\n");
7463 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
7465 skip("Failed to create a D3D device, skipping tests.\n");
7466 IDirect3D9_Release(d3d
);
7467 DestroyWindow(window
);
7471 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl1
, &declaration1
);
7472 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed, hr %#x.\n", hr
);
7474 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl2
, &declaration2
);
7475 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed, hr %#x.\n", hr
);
7477 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
7478 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed, hr %#x.\n", hr
);
7479 hr
= IDirect3DDevice9_BeginStateBlock(device
);
7480 ok(SUCCEEDED(hr
), "BeginStateBlock failed, hr %#x.\n", hr
);
7481 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, declaration1
);
7482 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed, hr %#x.\n", hr
);
7483 hr
= IDirect3DDevice9_EndStateBlock(device
, &stateblock
);
7484 ok(SUCCEEDED(hr
), "EndStateBlock failed, hr %#x.\n", hr
);
7485 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
7486 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed, hr %#x.\n", hr
);
7487 hr
= IDirect3DStateBlock9_Apply(stateblock
);
7488 ok(SUCCEEDED(hr
), "Apply failed, hr %#x.\n", hr
);
7489 hr
= IDirect3DDevice9_GetVertexDeclaration(device
, &declaration
);
7490 ok(SUCCEEDED(hr
), "GetVertexDeclaration failed, hr %#x.\n", hr
);
7491 ok(declaration
== declaration1
, "Got unexpected vertex declaration %p, expected %p.\n",
7492 declaration
, declaration1
);
7493 IDirect3DVertexDeclaration9_Release(declaration
);
7495 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
7496 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed, hr %#x.\n", hr
);
7497 hr
= IDirect3DStateBlock9_Capture(stateblock
);
7498 ok(SUCCEEDED(hr
), "Capture failed, hr %#x.\n", hr
);
7499 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, declaration2
);
7500 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed, hr %#x.\n", hr
);
7501 hr
= IDirect3DStateBlock9_Apply(stateblock
);
7502 ok(SUCCEEDED(hr
), "Apply failed, hr %#x.\n", hr
);
7503 hr
= IDirect3DDevice9_GetVertexDeclaration(device
, &declaration
);
7504 ok(SUCCEEDED(hr
), "GetVertexDeclaration failed, hr %#x.\n", hr
);
7505 ok(declaration
== declaration2
, "Got unexpected vertex declaration %p, expected %p.\n",
7506 declaration
, declaration2
);
7507 IDirect3DVertexDeclaration9_Release(declaration
);
7509 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, declaration2
);
7510 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed, hr %#x.\n", hr
);
7511 hr
= IDirect3DStateBlock9_Capture(stateblock
);
7512 ok(SUCCEEDED(hr
), "Capture failed, hr %#x.\n", hr
);
7513 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
7514 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed, hr %#x.\n", hr
);
7515 hr
= IDirect3DStateBlock9_Apply(stateblock
);
7516 ok(SUCCEEDED(hr
), "Apply failed, hr %#x.\n", hr
);
7517 hr
= IDirect3DDevice9_GetVertexDeclaration(device
, &declaration
);
7518 ok(SUCCEEDED(hr
), "GetVertexDeclaration failed, hr %#x.\n", hr
);
7519 ok(declaration
== declaration2
, "Got unexpected vertex declaration %p, expected %p.\n",
7520 declaration
, declaration2
);
7521 IDirect3DVertexDeclaration9_Release(declaration
);
7523 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
7524 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed, hr %#x.\n", hr
);
7525 hr
= IDirect3DStateBlock9_Capture(stateblock
);
7526 ok(SUCCEEDED(hr
), "Capture failed, hr %#x.\n", hr
);
7527 hr
= IDirect3DStateBlock9_Apply(stateblock
);
7528 ok(SUCCEEDED(hr
), "Apply failed, hr %#x.\n", hr
);
7529 hr
= IDirect3DDevice9_GetVertexDeclaration(device
, &declaration
);
7530 ok(SUCCEEDED(hr
), "GetVertexDeclaration failed, hr %#x.\n", hr
);
7531 ok(!declaration
, "Got unexpected vertex declaration %p.\n", declaration
);
7533 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, declaration2
);
7534 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed, hr %#x.\n", hr
);
7535 hr
= IDirect3DStateBlock9_Capture(stateblock
);
7536 ok(SUCCEEDED(hr
), "Capture failed, hr %#x.\n", hr
);
7537 hr
= IDirect3DStateBlock9_Apply(stateblock
);
7538 ok(SUCCEEDED(hr
), "Apply failed, hr %#x.\n", hr
);
7539 hr
= IDirect3DDevice9_GetVertexDeclaration(device
, &declaration
);
7540 ok(SUCCEEDED(hr
), "GetVertexDeclaration failed, hr %#x.\n", hr
);
7541 ok(declaration
== declaration2
, "Got unexpected vertex declaration %p, expected %p.\n",
7542 declaration
, declaration2
);
7543 IDirect3DVertexDeclaration9_Release(declaration
);
7545 IDirect3DStateBlock9_Release(stateblock
);
7546 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, declaration1
);
7547 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed, hr %#x.\n", hr
);
7548 hr
= IDirect3DDevice9_CreateStateBlock(device
, D3DSBT_VERTEXSTATE
, &stateblock
);
7549 ok(SUCCEEDED(hr
), "CreateStateBlock failed, hr %#x.\n", hr
);
7550 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
7551 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed, hr %#x.\n", hr
);
7552 hr
= IDirect3DStateBlock9_Apply(stateblock
);
7553 ok(SUCCEEDED(hr
), "Apply failed, hr %#x.\n", hr
);
7554 hr
= IDirect3DDevice9_GetVertexDeclaration(device
, &declaration
);
7555 ok(SUCCEEDED(hr
), "GetVertexDeclaration failed, hr %#x.\n", hr
);
7556 ok(declaration
== declaration1
, "Got unexpected vertex declaration %p, expected %p.\n",
7557 declaration
, declaration1
);
7558 IDirect3DVertexDeclaration9_Release(declaration
);
7560 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
7561 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed, hr %#x.\n", hr
);
7562 hr
= IDirect3DStateBlock9_Capture(stateblock
);
7563 ok(SUCCEEDED(hr
), "Capture failed, hr %#x.\n", hr
);
7564 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, declaration2
);
7565 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed, hr %#x.\n", hr
);
7566 hr
= IDirect3DStateBlock9_Apply(stateblock
);
7567 ok(SUCCEEDED(hr
), "Apply failed, hr %#x.\n", hr
);
7568 hr
= IDirect3DDevice9_GetVertexDeclaration(device
, &declaration
);
7569 ok(SUCCEEDED(hr
), "GetVertexDeclaration failed, hr %#x.\n", hr
);
7570 ok(declaration
== declaration2
, "Got unexpected vertex declaration %p, expected %p.\n",
7571 declaration
, declaration2
);
7572 IDirect3DVertexDeclaration9_Release(declaration
);
7574 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, declaration2
);
7575 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed, hr %#x.\n", hr
);
7576 hr
= IDirect3DStateBlock9_Capture(stateblock
);
7577 ok(SUCCEEDED(hr
), "Capture failed, hr %#x.\n", hr
);
7578 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
7579 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed, hr %#x.\n", hr
);
7580 hr
= IDirect3DStateBlock9_Apply(stateblock
);
7581 ok(SUCCEEDED(hr
), "Apply failed, hr %#x.\n", hr
);
7582 hr
= IDirect3DDevice9_GetVertexDeclaration(device
, &declaration
);
7583 ok(SUCCEEDED(hr
), "GetVertexDeclaration failed, hr %#x.\n", hr
);
7584 ok(declaration
== declaration2
, "Got unexpected vertex declaration %p, expected %p.\n",
7585 declaration
, declaration2
);
7586 IDirect3DVertexDeclaration9_Release(declaration
);
7588 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
7589 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed, hr %#x.\n", hr
);
7590 hr
= IDirect3DStateBlock9_Capture(stateblock
);
7591 ok(SUCCEEDED(hr
), "Capture failed, hr %#x.\n", hr
);
7592 hr
= IDirect3DStateBlock9_Apply(stateblock
);
7593 ok(SUCCEEDED(hr
), "Apply failed, hr %#x.\n", hr
);
7594 hr
= IDirect3DDevice9_GetVertexDeclaration(device
, &declaration
);
7595 ok(SUCCEEDED(hr
), "GetVertexDeclaration failed, hr %#x.\n", hr
);
7596 ok(!declaration
, "Got unexpected vertex declaration %p.\n", declaration
);
7598 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, declaration2
);
7599 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed, hr %#x.\n", hr
);
7600 hr
= IDirect3DStateBlock9_Capture(stateblock
);
7601 ok(SUCCEEDED(hr
), "Capture failed, hr %#x.\n", hr
);
7602 hr
= IDirect3DStateBlock9_Apply(stateblock
);
7603 ok(SUCCEEDED(hr
), "Apply failed, hr %#x.\n", hr
);
7604 hr
= IDirect3DDevice9_GetVertexDeclaration(device
, &declaration
);
7605 ok(SUCCEEDED(hr
), "GetVertexDeclaration failed, hr %#x.\n", hr
);
7606 ok(declaration
== declaration2
, "Got unexpected vertex declaration %p, expected %p.\n",
7607 declaration
, declaration2
);
7608 IDirect3DVertexDeclaration9_Release(declaration
);
7610 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
7611 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed, hr %#x.\n", hr
);
7612 IDirect3DVertexDeclaration9_Release(declaration1
);
7613 IDirect3DVertexDeclaration9_Release(declaration2
);
7614 IDirect3DStateBlock9_Release(stateblock
);
7615 refcount
= IDirect3DDevice9_Release(device
);
7616 ok(!refcount
, "Device has %u references left.\n", refcount
);
7617 IDirect3D9_Release(d3d
);
7618 DestroyWindow(window
);
7621 static void test_resource_type(void)
7623 IDirect3DDevice9
*device
;
7624 IDirect3DSurface9
*surface
;
7625 IDirect3DTexture9
*texture
;
7626 IDirect3DCubeTexture9
*cube_texture
;
7627 IDirect3DVolume9
*volume
;
7628 IDirect3DVolumeTexture9
*volume_texture
;
7629 D3DSURFACE_DESC surface_desc
;
7630 D3DVOLUME_DESC volume_desc
;
7631 D3DRESOURCETYPE type
;
7637 window
= CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW
,
7638 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
7639 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
7640 ok(!!d3d
, "Failed to create a D3D object.\n");
7641 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
7643 skip("Failed to create a D3D device, skipping tests.\n");
7644 IDirect3D9_Release(d3d
);
7645 DestroyWindow(window
);
7649 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 4, 4, D3DFMT_X8R8G8B8
,
7650 D3DPOOL_SYSTEMMEM
, &surface
, NULL
);
7651 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7652 type
= IDirect3DSurface9_GetType(surface
);
7653 ok(type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n", type
);
7654 hr
= IDirect3DSurface9_GetDesc(surface
, &surface_desc
);
7655 ok(SUCCEEDED(hr
), "Failed to get surface description, hr %#x.\n", hr
);
7656 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7658 IDirect3DSurface9_Release(surface
);
7660 hr
= IDirect3DDevice9_CreateTexture(device
, 2, 8, 4, 0, D3DFMT_X8R8G8B8
,
7661 D3DPOOL_SYSTEMMEM
, &texture
, NULL
);
7662 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
7663 type
= IDirect3DTexture9_GetType(texture
);
7664 ok(type
== D3DRTYPE_TEXTURE
, "Expected type D3DRTYPE_TEXTURE, got %u.\n", type
);
7666 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
7667 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7668 /* The following code crashes, for the sake of completeness:
7669 * type = texture->lpVtbl->GetType((IDirect3DTexture9 *)surface);
7670 * ok(type == D3DRTYPE_PONIES, "Expected type D3DRTYPE_PONIES, got %u.\n", type);
7672 * So applications will not depend on getting the "right" resource type - whatever it
7673 * may be - from the "wrong" vtable. */
7674 type
= IDirect3DSurface9_GetType(surface
);
7675 ok(type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n", type
);
7676 hr
= IDirect3DSurface9_GetDesc(surface
, &surface_desc
);
7677 ok(SUCCEEDED(hr
), "Failed to get surface description, hr %#x.\n", hr
);
7678 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7680 ok(surface_desc
.Width
== 2, "Expected width 2, got %u.\n", surface_desc
.Width
);
7681 ok(surface_desc
.Height
== 8, "Expected height 8, got %u.\n", surface_desc
.Height
);
7682 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 0, &surface_desc
);
7683 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
7684 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7686 ok(surface_desc
.Width
== 2, "Expected width 2, got %u.\n", surface_desc
.Width
);
7687 ok(surface_desc
.Height
== 8, "Expected height 8, got %u.\n", surface_desc
.Height
);
7688 IDirect3DSurface9_Release(surface
);
7690 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 2, &surface
);
7691 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7692 type
= IDirect3DSurface9_GetType(surface
);
7693 ok(type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n", type
);
7694 hr
= IDirect3DSurface9_GetDesc(surface
, &surface_desc
);
7695 ok(SUCCEEDED(hr
), "Failed to get surface description, hr %#x.\n", hr
);
7696 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7698 ok(surface_desc
.Width
== 1, "Expected width 1, got %u.\n", surface_desc
.Width
);
7699 ok(surface_desc
.Height
== 2, "Expected height 2, got %u.\n", surface_desc
.Height
);
7700 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 2, &surface_desc
);
7701 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
7702 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7704 ok(surface_desc
.Width
== 1, "Expected width 1, got %u.\n", surface_desc
.Width
);
7705 ok(surface_desc
.Height
== 2, "Expected height 2, got %u.\n", surface_desc
.Height
);
7706 IDirect3DSurface9_Release(surface
);
7707 IDirect3DTexture9_Release(texture
);
7709 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 1, 1, 0, D3DFMT_X8R8G8B8
,
7710 D3DPOOL_SYSTEMMEM
, &cube_texture
, NULL
);
7711 ok(SUCCEEDED(hr
), "Failed to create cube texture, hr %#x.\n", hr
);
7712 type
= IDirect3DCubeTexture9_GetType(cube_texture
);
7713 ok(type
== D3DRTYPE_CUBETEXTURE
, "Expected type D3DRTYPE_CUBETEXTURE, got %u.\n", type
);
7715 hr
= IDirect3DCubeTexture9_GetCubeMapSurface(cube_texture
,
7716 D3DCUBEMAP_FACE_NEGATIVE_X
, 0, &surface
);
7717 ok(SUCCEEDED(hr
), "Failed to get cube map surface, hr %#x.\n", hr
);
7718 type
= IDirect3DSurface9_GetType(surface
);
7719 ok(type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n", type
);
7720 hr
= IDirect3DSurface9_GetDesc(surface
, &surface_desc
);
7721 ok(SUCCEEDED(hr
), "Failed to get surface description, hr %#x.\n", hr
);
7722 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7724 hr
= IDirect3DCubeTexture9_GetLevelDesc(cube_texture
, 0, &surface_desc
);
7725 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
7726 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7728 IDirect3DSurface9_Release(surface
);
7729 IDirect3DCubeTexture9_Release(cube_texture
);
7731 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 2, 4, 8, 4, 0, D3DFMT_X8R8G8B8
,
7732 D3DPOOL_SYSTEMMEM
, &volume_texture
, NULL
);
7733 type
= IDirect3DVolumeTexture9_GetType(volume_texture
);
7734 ok(type
== D3DRTYPE_VOLUMETEXTURE
, "Expected type D3DRTYPE_VOLUMETEXTURE, got %u.\n", type
);
7736 hr
= IDirect3DVolumeTexture9_GetVolumeLevel(volume_texture
, 0, &volume
);
7737 ok(SUCCEEDED(hr
), "Failed to get volume level, hr %#x.\n", hr
);
7738 /* IDirect3DVolume9 is not an IDirect3DResource9 and has no GetType method. */
7739 hr
= IDirect3DVolume9_GetDesc(volume
, &volume_desc
);
7740 ok(SUCCEEDED(hr
), "Failed to get volume description, hr %#x.\n", hr
);
7741 ok(volume_desc
.Type
== D3DRTYPE_VOLUME
, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7743 ok(volume_desc
.Width
== 2, "Expected width 2, got %u.\n", volume_desc
.Width
);
7744 ok(volume_desc
.Height
== 4, "Expected height 4, got %u.\n", volume_desc
.Height
);
7745 ok(volume_desc
.Depth
== 8, "Expected depth 8, got %u.\n", volume_desc
.Depth
);
7746 hr
= IDirect3DVolumeTexture9_GetLevelDesc(volume_texture
, 0, &volume_desc
);
7747 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
7748 ok(volume_desc
.Type
== D3DRTYPE_VOLUME
, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7750 ok(volume_desc
.Width
== 2, "Expected width 2, got %u.\n", volume_desc
.Width
);
7751 ok(volume_desc
.Height
== 4, "Expected height 4, got %u.\n", volume_desc
.Height
);
7752 ok(volume_desc
.Depth
== 8, "Expected depth 8, got %u.\n", volume_desc
.Depth
);
7753 IDirect3DVolume9_Release(volume
);
7755 hr
= IDirect3DVolumeTexture9_GetVolumeLevel(volume_texture
, 2, &volume
);
7756 ok(SUCCEEDED(hr
), "Failed to get volume level, hr %#x.\n", hr
);
7757 /* IDirect3DVolume9 is not an IDirect3DResource9 and has no GetType method. */
7758 hr
= IDirect3DVolume9_GetDesc(volume
, &volume_desc
);
7759 ok(SUCCEEDED(hr
), "Failed to get volume description, hr %#x.\n", hr
);
7760 ok(volume_desc
.Type
== D3DRTYPE_VOLUME
, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7762 ok(volume_desc
.Width
== 1, "Expected width 1, got %u.\n", volume_desc
.Width
);
7763 ok(volume_desc
.Height
== 1, "Expected height 1, got %u.\n", volume_desc
.Height
);
7764 ok(volume_desc
.Depth
== 2, "Expected depth 2, got %u.\n", volume_desc
.Depth
);
7765 hr
= IDirect3DVolumeTexture9_GetLevelDesc(volume_texture
, 2, &volume_desc
);
7766 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
7767 ok(volume_desc
.Type
== D3DRTYPE_VOLUME
, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7769 ok(volume_desc
.Width
== 1, "Expected width 1, got %u.\n", volume_desc
.Width
);
7770 ok(volume_desc
.Height
== 1, "Expected height 1, got %u.\n", volume_desc
.Height
);
7771 ok(volume_desc
.Depth
== 2, "Expected depth 2, got %u.\n", volume_desc
.Depth
);
7772 IDirect3DVolume9_Release(volume
);
7773 IDirect3DVolumeTexture9_Release(volume_texture
);
7775 refcount
= IDirect3DDevice9_Release(device
);
7776 ok(!refcount
, "Device has %u references left.\n", refcount
);
7777 IDirect3D9_Release(d3d
);
7778 DestroyWindow(window
);
7781 static void test_mipmap_lock(void)
7783 IDirect3DDevice9
*device
;
7784 IDirect3DSurface9
*surface
, *surface2
, *surface_dst
, *surface_dst2
;
7785 IDirect3DTexture9
*texture
, *texture_dst
;
7790 D3DLOCKED_RECT locked_rect
;
7792 window
= CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW
,
7793 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
7794 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
7795 ok(!!d3d
, "Failed to create a D3D object.\n");
7796 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
7798 skip("Failed to create a D3D device, skipping tests.\n");
7799 IDirect3D9_Release(d3d
);
7800 DestroyWindow(window
);
7804 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 2, 0, D3DFMT_X8R8G8B8
,
7805 D3DPOOL_DEFAULT
, &texture_dst
, NULL
);
7806 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
7807 hr
= IDirect3DTexture9_GetSurfaceLevel(texture_dst
, 0, &surface_dst
);
7808 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7809 hr
= IDirect3DTexture9_GetSurfaceLevel(texture_dst
, 1, &surface_dst2
);
7810 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7812 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 2, 0, D3DFMT_X8R8G8B8
,
7813 D3DPOOL_SYSTEMMEM
, &texture
, NULL
);
7814 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
7815 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
7816 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7817 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 1, &surface2
);
7818 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7820 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, NULL
, 0);
7821 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
7822 hr
= IDirect3DSurface9_LockRect(surface2
, &locked_rect
, NULL
, 0);
7823 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
7824 hr
= IDirect3DSurface9_UnlockRect(surface
);
7825 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
7827 hr
= IDirect3DDevice9_UpdateSurface(device
, surface
, NULL
, surface_dst
, NULL
);
7828 ok(SUCCEEDED(hr
), "Failed to update surface, hr %#x.\n", hr
);
7829 hr
= IDirect3DDevice9_UpdateSurface(device
, surface2
, NULL
, surface_dst2
, NULL
);
7830 todo_wine
ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
7832 /* Apparently there's no validation on the container. */
7833 hr
= IDirect3DDevice9_UpdateTexture(device
, (IDirect3DBaseTexture9
*)texture
,
7834 (IDirect3DBaseTexture9
*)texture_dst
);
7835 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x.\n", hr
);
7837 hr
= IDirect3DSurface9_UnlockRect(surface2
);
7838 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
7840 IDirect3DSurface9_Release(surface_dst2
);
7841 IDirect3DSurface9_Release(surface_dst
);
7842 IDirect3DSurface9_Release(surface2
);
7843 IDirect3DSurface9_Release(surface
);
7844 IDirect3DTexture9_Release(texture_dst
);
7845 IDirect3DTexture9_Release(texture
);
7847 refcount
= IDirect3DDevice9_Release(device
);
7848 ok(!refcount
, "Device has %u references left.\n", refcount
);
7849 IDirect3D9_Release(d3d
);
7850 DestroyWindow(window
);
7858 if (!(d3d9
= Direct3DCreate9(D3D_SDK_VERSION
)))
7860 skip("could not create D3D9 object\n");
7863 IDirect3D9_Release(d3d9
);
7865 wc
.lpfnWndProc
= DefWindowProcA
;
7866 wc
.lpszClassName
= "d3d9_test_wc";
7867 RegisterClassA(&wc
);
7869 screen_width
= GetSystemMetrics(SM_CXSCREEN
);
7870 screen_height
= GetSystemMetrics(SM_CYSCREEN
);
7873 test_multi_device();
7874 test_display_formats();
7875 test_display_modes();
7878 test_mipmap_levels();
7879 test_checkdevicemultisampletype();
7882 test_reset_fullscreen();
7886 test_depthstenciltest();
7888 test_draw_indexed();
7891 test_set_stream_source();
7892 test_scissor_size();
7894 test_wndproc_windowed();
7895 test_window_style();
7897 test_device_window_reset();
7898 test_reset_resources();
7899 test_set_rt_vp_scissor();
7900 test_volume_get_container();
7901 test_volume_resource();
7902 test_vb_lock_flags();
7903 test_vertex_buffer_alignment();
7904 test_query_support();
7905 test_occlusion_query_states();
7906 test_get_set_vertex_shader();
7907 test_vertex_shader_constant();
7908 test_get_set_pixel_shader();
7909 test_pixel_shader_constant();
7910 test_wrong_shader();
7911 test_texture_stage_states();
7912 test_cube_textures();
7917 test_surface_get_container();
7918 test_surface_alignment();
7919 test_lockrect_offset();
7920 test_lockrect_invalid();
7921 test_private_data();
7923 test_surface_dimensions();
7924 test_surface_format_null();
7925 test_surface_double_unlock();
7926 test_surface_blocks();
7929 test_npot_textures();
7930 test_vidmem_accounting();
7931 test_volume_locking();
7932 test_update_volumetexture();
7933 test_create_rt_ds_fail();
7934 test_volume_blocks();
7935 test_lockbox_invalid();
7936 test_shared_handle();
7937 test_pixel_format();
7938 test_begin_end_state_block();
7939 test_shader_constant_apply();
7941 test_resource_type();
7944 UnregisterClassA("d3d9_test_wc", GetModuleHandleA(NULL
));