2 * Copyright (C) 2006 Vitaliy Margolen
3 * Copyright (C) 2006 Chris Robinson
4 * Copyright (C) 2006 Louis Lenders
5 * Copyright 2006-2007 Henri Verbeet
6 * Copyright 2006-2007, 2011-2013 Stefan Dösinger for CodeWeavers
7 * Copyright 2013 Henri Verbeet for CodeWeavers
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
27 #include "wine/test.h"
34 #define CREATE_DEVICE_FULLSCREEN 0x01
35 #define CREATE_DEVICE_FPU_PRESERVE 0x02
36 #define CREATE_DEVICE_SWVP_ONLY 0x04
46 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
47 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
49 static DEVMODEW registry_mode
;
51 static HRESULT (WINAPI
*ValidateVertexShader
)(DWORD
*, DWORD
*, DWORD
*, int, DWORD
*);
52 static HRESULT (WINAPI
*ValidatePixelShader
)(DWORD
*, DWORD
*, int, DWORD
*);
54 static BOOL (WINAPI
*pGetCursorInfo
)(PCURSORINFO
);
56 static const DWORD simple_vs
[] = {0xFFFE0101, /* vs_1_1 */
57 0x00000009, 0xC0010000, 0x90E40000, 0xA0E40000, /* dp4 oPos.x, v0, c0 */
58 0x00000009, 0xC0020000, 0x90E40000, 0xA0E40001, /* dp4 oPos.y, v0, c1 */
59 0x00000009, 0xC0040000, 0x90E40000, 0xA0E40002, /* dp4 oPos.z, v0, c2 */
60 0x00000009, 0xC0080000, 0x90E40000, 0xA0E40003, /* dp4 oPos.w, v0, c3 */
61 0x0000FFFF}; /* END */
62 static const DWORD simple_ps
[] = {0xFFFF0101, /* ps_1_1 */
63 0x00000051, 0xA00F0001, 0x3F800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
64 0x00000042, 0xB00F0000, /* tex t0 */
65 0x00000008, 0x800F0000, 0xA0E40001, 0xA0E40000, /* dp3 r0, c1, c0 */
66 0x00000005, 0x800F0000, 0x90E40000, 0x80E40000, /* mul r0, v0, r0 */
67 0x00000005, 0x800F0000, 0xB0E40000, 0x80E40000, /* mul r0, t0, r0 */
68 0x0000FFFF}; /* END */
70 static int get_refcount(IUnknown
*object
)
72 IUnknown_AddRef( object
);
73 return IUnknown_Release( object
);
76 /* try to make sure pending X events have been processed before continuing */
77 static void flush_events(void)
81 int min_timeout
= 100;
82 DWORD time
= GetTickCount() + diff
;
86 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
87 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
88 diff
= time
- GetTickCount();
92 static IDirect3DDevice8
*create_device(IDirect3D8
*d3d8
, HWND focus_window
, const struct device_desc
*desc
)
94 D3DPRESENT_PARAMETERS present_parameters
= {0};
95 IDirect3DDevice8
*device
;
96 DWORD behavior_flags
= D3DCREATE_HARDWARE_VERTEXPROCESSING
;
98 present_parameters
.BackBufferWidth
= 640;
99 present_parameters
.BackBufferHeight
= 480;
100 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
101 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
102 present_parameters
.hDeviceWindow
= focus_window
;
103 present_parameters
.Windowed
= TRUE
;
104 present_parameters
.EnableAutoDepthStencil
= TRUE
;
105 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
109 present_parameters
.BackBufferWidth
= desc
->width
;
110 present_parameters
.BackBufferHeight
= desc
->height
;
111 present_parameters
.hDeviceWindow
= desc
->device_window
;
112 present_parameters
.Windowed
= !(desc
->flags
& CREATE_DEVICE_FULLSCREEN
);
113 if (desc
->flags
& CREATE_DEVICE_SWVP_ONLY
)
114 behavior_flags
= D3DCREATE_SOFTWARE_VERTEXPROCESSING
;
115 if (desc
->flags
& CREATE_DEVICE_FPU_PRESERVE
)
116 behavior_flags
|= D3DCREATE_FPU_PRESERVE
;
119 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, focus_window
,
120 behavior_flags
, &present_parameters
, &device
)))
123 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D16
;
124 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, focus_window
,
125 behavior_flags
, &present_parameters
, &device
)))
128 if (desc
&& desc
->flags
& CREATE_DEVICE_SWVP_ONLY
)
130 behavior_flags
^= (D3DCREATE_HARDWARE_VERTEXPROCESSING
| D3DCREATE_SOFTWARE_VERTEXPROCESSING
);
132 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, focus_window
,
133 behavior_flags
, &present_parameters
, &device
)))
139 static HRESULT
reset_device(IDirect3DDevice8
*device
, const struct device_desc
*desc
)
141 D3DPRESENT_PARAMETERS present_parameters
= {0};
143 present_parameters
.BackBufferWidth
= 640;
144 present_parameters
.BackBufferHeight
= 480;
145 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
146 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
147 present_parameters
.hDeviceWindow
= NULL
;
148 present_parameters
.Windowed
= TRUE
;
149 present_parameters
.EnableAutoDepthStencil
= TRUE
;
150 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
154 present_parameters
.BackBufferWidth
= desc
->width
;
155 present_parameters
.BackBufferHeight
= desc
->height
;
156 present_parameters
.hDeviceWindow
= desc
->device_window
;
157 present_parameters
.Windowed
= !(desc
->flags
& CREATE_DEVICE_FULLSCREEN
);
160 return IDirect3DDevice8_Reset(device
, &present_parameters
);
163 #define CHECK_CALL(r,c,d,rc) \
165 int tmp1 = get_refcount( (IUnknown *)d ); \
167 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
169 trace("%s failed: %#08x\n", c, r); \
172 #define CHECK_RELEASE(obj,d,rc) \
174 int tmp1, rc_new = rc; \
175 IUnknown_Release( (IUnknown*)obj ); \
176 tmp1 = get_refcount( (IUnknown *)d ); \
177 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
180 #define CHECK_REFCOUNT(obj,rc) \
183 int count = get_refcount( (IUnknown *)obj ); \
184 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
187 #define CHECK_RELEASE_REFCOUNT(obj,rc) \
190 int count = IUnknown_Release( (IUnknown *)obj ); \
191 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
194 #define CHECK_ADDREF_REFCOUNT(obj,rc) \
197 int count = IUnknown_AddRef( (IUnknown *)obj ); \
198 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
201 #define CHECK_SURFACE_CONTAINER(obj,iid,expected) \
203 void *container_ptr = (void *)0x1337c0d3; \
204 hr = IDirect3DSurface8_GetContainer(obj, &iid, &container_ptr); \
205 ok(SUCCEEDED(hr) && container_ptr == expected, "GetContainer returned: hr %#08x, container_ptr %p. " \
206 "Expected hr %#08x, container_ptr %p\n", hr, container_ptr, S_OK, expected); \
207 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr); \
210 static void check_mipmap_levels(IDirect3DDevice8
*device
, UINT width
, UINT height
, UINT count
)
212 IDirect3DBaseTexture8
* texture
= NULL
;
213 HRESULT hr
= IDirect3DDevice8_CreateTexture( device
, width
, height
, 0, 0,
214 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, (IDirect3DTexture8
**) &texture
);
217 DWORD levels
= IDirect3DBaseTexture8_GetLevelCount(texture
);
218 ok(levels
== count
, "Invalid level count. Expected %d got %u\n", count
, levels
);
220 trace("CreateTexture failed: %#08x\n", hr
);
222 if (texture
) IDirect3DBaseTexture8_Release( texture
);
225 static void test_mipmap_levels(void)
227 IDirect3DDevice8
*device
;
232 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
233 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
234 ok(!!window
, "Failed to create a window.\n");
235 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
236 ok(!!d3d
, "Failed to create a D3D object.\n");
237 if (!(device
= create_device(d3d
, window
, NULL
)))
239 skip("Failed to create a 3D device, skipping test.\n");
243 check_mipmap_levels(device
, 32, 32, 6);
244 check_mipmap_levels(device
, 256, 1, 9);
245 check_mipmap_levels(device
, 1, 256, 9);
246 check_mipmap_levels(device
, 1, 1, 1);
248 refcount
= IDirect3DDevice8_Release(device
);
249 ok(!refcount
, "Device has %u references left.\n", refcount
);
251 IDirect3D8_Release(d3d
);
252 DestroyWindow(window
);
255 static void test_swapchain(void)
257 IDirect3DSwapChain8
*swapchain1
;
258 IDirect3DSwapChain8
*swapchain2
;
259 IDirect3DSwapChain8
*swapchain3
;
260 IDirect3DSurface8
*backbuffer
;
261 D3DPRESENT_PARAMETERS d3dpp
;
262 IDirect3DDevice8
*device
;
265 HWND window
, window2
;
267 struct device_desc device_desc
;
269 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
270 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
271 ok(!!window
, "Failed to create a window.\n");
272 window2
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
273 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
274 ok(!!window2
, "Failed to create a window.\n");
275 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
276 ok(!!d3d
, "Failed to create a D3D object.\n");
277 if (!(device
= create_device(d3d
, window
, NULL
)))
279 skip("Failed to create a 3D device, skipping test.\n");
283 memset(&d3dpp
, 0, sizeof(d3dpp
));
284 d3dpp
.Windowed
= TRUE
;
285 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
286 d3dpp
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
288 /* Create a bunch of swapchains */
289 d3dpp
.BackBufferCount
= 0;
290 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain1
);
291 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%#08x)\n", hr
);
292 ok(d3dpp
.BackBufferCount
== 1, "The back buffer count in the presentparams struct is %d\n", d3dpp
.BackBufferCount
);
294 d3dpp
.BackBufferCount
= 1;
295 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain2
);
296 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%#08x)\n", hr
);
298 d3dpp
.BackBufferCount
= 2;
299 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain3
);
300 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%#08x)\n", hr
);
302 /* Swapchain 3, created with backbuffercount 2 */
303 backbuffer
= (void *) 0xdeadbeef;
304 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 0, 0, &backbuffer
);
305 ok(SUCCEEDED(hr
), "Failed to get the 1st back buffer (%#08x)\n", hr
);
306 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
307 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
309 backbuffer
= (void *) 0xdeadbeef;
310 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 1, 0, &backbuffer
);
311 ok(SUCCEEDED(hr
), "Failed to get the 2nd back buffer (%#08x)\n", hr
);
312 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
313 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
315 backbuffer
= (void *) 0xdeadbeef;
316 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 2, 0, &backbuffer
);
317 ok(hr
== D3DERR_INVALIDCALL
, "GetBackBuffer returned %#08x\n", hr
);
318 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
319 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
321 backbuffer
= (void *) 0xdeadbeef;
322 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 3, 0, &backbuffer
);
323 ok(FAILED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
324 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
325 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
328 /* Check the back buffers of the swapchains */
329 /* Swapchain 1, created with backbuffercount 0 */
330 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain1
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
331 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
332 ok(backbuffer
!= NULL
, "The back buffer is NULL (%#08x)\n", hr
);
333 if(backbuffer
) IDirect3DSurface8_Release(backbuffer
);
335 backbuffer
= (void *) 0xdeadbeef;
336 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain1
, 1, 0, &backbuffer
);
337 ok(FAILED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
338 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
339 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
341 /* Swapchain 2 - created with backbuffercount 1 */
342 backbuffer
= (void *) 0xdeadbeef;
343 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain2
, 0, 0, &backbuffer
);
344 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
345 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
346 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
348 backbuffer
= (void *) 0xdeadbeef;
349 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain2
, 1, 0, &backbuffer
);
350 ok(hr
== D3DERR_INVALIDCALL
, "GetBackBuffer returned %#08x\n", hr
);
351 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
352 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
354 backbuffer
= (void *) 0xdeadbeef;
355 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain2
, 2, 0, &backbuffer
);
356 ok(FAILED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
357 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
358 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
360 IDirect3DSwapChain8_Release(swapchain3
);
361 IDirect3DSwapChain8_Release(swapchain2
);
362 IDirect3DSwapChain8_Release(swapchain1
);
364 d3dpp
.Windowed
= FALSE
;
365 d3dpp
.hDeviceWindow
= window
;
366 d3dpp
.BackBufferCount
= 1;
367 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain1
);
368 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x\n", hr
);
369 d3dpp
.hDeviceWindow
= window2
;
370 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain1
);
371 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x\n", hr
);
373 device_desc
.width
= registry_mode
.dmPelsWidth
;
374 device_desc
.height
= registry_mode
.dmPelsHeight
;
375 device_desc
.device_window
= window
;
376 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
377 hr
= reset_device(device
, &device_desc
);
378 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
380 d3dpp
.hDeviceWindow
= window
;
381 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain1
);
382 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x\n", hr
);
383 d3dpp
.hDeviceWindow
= window2
;
384 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain1
);
385 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x\n", hr
);
386 d3dpp
.Windowed
= TRUE
;
387 d3dpp
.hDeviceWindow
= window
;
388 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain1
);
389 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x\n", hr
);
390 d3dpp
.hDeviceWindow
= window2
;
391 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain1
);
392 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x\n", hr
);
394 refcount
= IDirect3DDevice8_Release(device
);
395 ok(!refcount
, "Device has %u references left.\n", refcount
);
397 IDirect3D8_Release(d3d
);
398 DestroyWindow(window2
);
399 DestroyWindow(window
);
402 static void test_refcount(void)
404 IDirect3DVertexBuffer8
*pVertexBuffer
= NULL
;
405 IDirect3DIndexBuffer8
*pIndexBuffer
= NULL
;
406 DWORD dVertexShader
= -1;
407 DWORD dPixelShader
= -1;
408 IDirect3DCubeTexture8
*pCubeTexture
= NULL
;
409 IDirect3DTexture8
*pTexture
= NULL
;
410 IDirect3DVolumeTexture8
*pVolumeTexture
= NULL
;
411 IDirect3DVolume8
*pVolumeLevel
= NULL
;
412 IDirect3DSurface8
*pStencilSurface
= NULL
;
413 IDirect3DSurface8
*pImageSurface
= NULL
;
414 IDirect3DSurface8
*pRenderTarget
= NULL
;
415 IDirect3DSurface8
*pRenderTarget2
= NULL
;
416 IDirect3DSurface8
*pRenderTarget3
= NULL
;
417 IDirect3DSurface8
*pTextureLevel
= NULL
;
418 IDirect3DSurface8
*pBackBuffer
= NULL
;
419 DWORD dStateBlock
= -1;
420 IDirect3DSwapChain8
*pSwapChain
= NULL
;
422 D3DPRESENT_PARAMETERS d3dpp
;
423 IDirect3DDevice8
*device
= NULL
;
424 ULONG refcount
= 0, tmp
;
425 IDirect3D8
*d3d
, *d3d2
;
432 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
433 D3DVSD_REG(D3DVSDE_DIFFUSE
, D3DVSDT_D3DCOLOR
), /* D3DVSDE_DIFFUSE, Register v5 */
437 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
438 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
439 ok(!!window
, "Failed to create a window.\n");
440 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
441 ok(!!d3d
, "Failed to create a D3D object.\n");
443 CHECK_REFCOUNT(d3d
, 1);
445 if (!(device
= create_device(d3d
, window
, NULL
)))
447 skip("Failed to create a 3D device, skipping test.\n");
451 IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
453 refcount
= get_refcount((IUnknown
*)device
);
454 ok(refcount
== 1, "Invalid device RefCount %d\n", refcount
);
456 CHECK_REFCOUNT(d3d
, 2);
458 hr
= IDirect3DDevice8_GetDirect3D(device
, &d3d2
);
459 CHECK_CALL(hr
, "GetDirect3D", device
, refcount
);
461 ok(d3d2
== d3d
, "Expected IDirect3D8 pointers to be equal.\n");
462 CHECK_REFCOUNT(d3d
, 3);
463 CHECK_RELEASE_REFCOUNT(d3d
, 2);
466 * Check refcount of implicit surfaces. Findings:
467 * - the container is the device
468 * - they hold a reference to the device
469 * - they are created with a refcount of 0 (Get/Release returns original refcount)
470 * - they are not freed if refcount reaches 0.
471 * - the refcount is not forwarded to the container.
473 hr
= IDirect3DDevice8_GetRenderTarget(device
, &pRenderTarget
);
474 CHECK_CALL(hr
, "GetRenderTarget", device
, ++refcount
);
477 CHECK_SURFACE_CONTAINER(pRenderTarget
, IID_IDirect3DDevice8
, device
);
478 CHECK_REFCOUNT( pRenderTarget
, 1);
480 CHECK_ADDREF_REFCOUNT(pRenderTarget
, 2);
481 CHECK_REFCOUNT(device
, refcount
);
482 CHECK_RELEASE_REFCOUNT(pRenderTarget
, 1);
483 CHECK_REFCOUNT(device
, refcount
);
485 hr
= IDirect3DDevice8_GetRenderTarget(device
, &pRenderTarget
);
486 CHECK_CALL(hr
, "GetRenderTarget", device
, refcount
);
487 CHECK_REFCOUNT( pRenderTarget
, 2);
488 CHECK_RELEASE_REFCOUNT( pRenderTarget
, 1);
489 CHECK_RELEASE_REFCOUNT( pRenderTarget
, 0);
490 CHECK_REFCOUNT(device
, --refcount
);
492 /* The render target is released with the device, so AddRef with refcount=0 is fine here. */
493 CHECK_ADDREF_REFCOUNT(pRenderTarget
, 1);
494 CHECK_REFCOUNT(device
, ++refcount
);
495 CHECK_RELEASE_REFCOUNT(pRenderTarget
, 0);
496 CHECK_REFCOUNT(device
, --refcount
);
499 /* Render target and back buffer are identical. */
500 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, 0, &pBackBuffer
);
501 CHECK_CALL(hr
, "GetBackBuffer", device
, ++refcount
);
504 CHECK_RELEASE_REFCOUNT(pBackBuffer
, 0);
505 ok(pRenderTarget
== pBackBuffer
, "RenderTarget=%p and BackBuffer=%p should be the same.\n",
506 pRenderTarget
, pBackBuffer
);
509 CHECK_REFCOUNT(device
, --refcount
);
511 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &pStencilSurface
);
512 CHECK_CALL(hr
, "GetDepthStencilSurface", device
, ++refcount
);
515 CHECK_SURFACE_CONTAINER(pStencilSurface
, IID_IDirect3DDevice8
, device
);
516 CHECK_REFCOUNT( pStencilSurface
, 1);
518 CHECK_ADDREF_REFCOUNT(pStencilSurface
, 2);
519 CHECK_REFCOUNT(device
, refcount
);
520 CHECK_RELEASE_REFCOUNT(pStencilSurface
, 1);
521 CHECK_REFCOUNT(device
, refcount
);
523 CHECK_RELEASE_REFCOUNT( pStencilSurface
, 0);
524 CHECK_REFCOUNT(device
, --refcount
);
526 /* The stencil surface is released with the device, so AddRef with refcount=0 is fine here. */
527 CHECK_ADDREF_REFCOUNT(pStencilSurface
, 1);
528 CHECK_REFCOUNT(device
, ++refcount
);
529 CHECK_RELEASE_REFCOUNT(pStencilSurface
, 0);
530 CHECK_REFCOUNT(device
, --refcount
);
531 pStencilSurface
= NULL
;
535 hr
= IDirect3DDevice8_CreateIndexBuffer(device
, 16, 0, D3DFMT_INDEX32
, D3DPOOL_DEFAULT
, &pIndexBuffer
);
536 CHECK_CALL(hr
, "CreateIndexBuffer", device
, ++refcount
);
539 tmp
= get_refcount( (IUnknown
*)pIndexBuffer
);
541 hr
= IDirect3DDevice8_SetIndices(device
, pIndexBuffer
, 0);
542 CHECK_CALL( hr
, "SetIndices", pIndexBuffer
, tmp
);
543 hr
= IDirect3DDevice8_SetIndices(device
, NULL
, 0);
544 CHECK_CALL( hr
, "SetIndices", pIndexBuffer
, tmp
);
547 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, 16, 0, D3DFVF_XYZ
, D3DPOOL_DEFAULT
, &pVertexBuffer
);
548 CHECK_CALL(hr
, "CreateVertexBuffer", device
, ++refcount
);
551 IDirect3DVertexBuffer8
*pVBuf
= (void*)~0;
554 tmp
= get_refcount( (IUnknown
*)pVertexBuffer
);
556 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, pVertexBuffer
, 3 * sizeof(float));
557 CHECK_CALL( hr
, "SetStreamSource", pVertexBuffer
, tmp
);
558 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, NULL
, 0);
559 CHECK_CALL( hr
, "SetStreamSource", pVertexBuffer
, tmp
);
561 hr
= IDirect3DDevice8_GetStreamSource(device
, 0, &pVBuf
, &stride
);
562 ok(SUCCEEDED(hr
), "GetStreamSource did not succeed with NULL stream!\n");
563 ok(pVBuf
==NULL
, "pVBuf not NULL (%p)!\n", pVBuf
);
564 ok(stride
==3*sizeof(float), "stride not 3 floats (got %u)!\n", stride
);
568 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, simple_vs
, &dVertexShader
, 0);
569 CHECK_CALL(hr
, "CreateVertexShader", device
, refcount
);
570 if (caps
.PixelShaderVersion
>= D3DPS_VERSION(1, 0))
572 hr
= IDirect3DDevice8_CreatePixelShader(device
, simple_ps
, &dPixelShader
);
573 CHECK_CALL(hr
, "CreatePixelShader", device
, refcount
);
576 hr
= IDirect3DDevice8_CreateTexture(device
, 32, 32, 3, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pTexture
);
577 CHECK_CALL(hr
, "CreateTexture", device
, ++refcount
);
580 tmp
= get_refcount( (IUnknown
*)pTexture
);
582 /* SetTexture should not increase refcounts */
583 hr
= IDirect3DDevice8_SetTexture(device
, 0, (IDirect3DBaseTexture8
*) pTexture
);
584 CHECK_CALL( hr
, "SetTexture", pTexture
, tmp
);
585 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
586 CHECK_CALL( hr
, "SetTexture", pTexture
, tmp
);
588 /* This should not increment device refcount */
589 hr
= IDirect3DTexture8_GetSurfaceLevel( pTexture
, 1, &pTextureLevel
);
590 CHECK_CALL(hr
, "GetSurfaceLevel", device
, refcount
);
591 /* But should increment texture's refcount */
592 CHECK_REFCOUNT( pTexture
, tmp
+1 );
593 /* Because the texture and surface refcount are identical */
596 CHECK_REFCOUNT ( pTextureLevel
, tmp
+1 );
597 CHECK_ADDREF_REFCOUNT ( pTextureLevel
, tmp
+2 );
598 CHECK_REFCOUNT ( pTexture
, tmp
+2 );
599 CHECK_RELEASE_REFCOUNT( pTextureLevel
, tmp
+1 );
600 CHECK_REFCOUNT ( pTexture
, tmp
+1 );
601 CHECK_RELEASE_REFCOUNT( pTexture
, tmp
);
602 CHECK_REFCOUNT ( pTextureLevel
, tmp
);
605 if(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
)
607 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 32, 0, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pCubeTexture
);
608 CHECK_CALL(hr
, "CreateCubeTexture", device
, ++refcount
);
612 skip("Cube textures not supported\n");
614 if(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
)
616 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 32, 32, 2, 0, 0,
617 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pVolumeTexture
);
618 CHECK_CALL(hr
, "CreateVolumeTexture", device
, ++refcount
);
622 skip("Volume textures not supported\n");
627 tmp
= get_refcount( (IUnknown
*)pVolumeTexture
);
629 /* This should not increment device refcount */
630 hr
= IDirect3DVolumeTexture8_GetVolumeLevel(pVolumeTexture
, 0, &pVolumeLevel
);
631 CHECK_CALL(hr
, "GetVolumeLevel", device
, refcount
);
632 /* But should increment volume texture's refcount */
633 CHECK_REFCOUNT( pVolumeTexture
, tmp
+1 );
634 /* Because the volume texture and volume refcount are identical */
637 CHECK_REFCOUNT ( pVolumeLevel
, tmp
+1 );
638 CHECK_ADDREF_REFCOUNT ( pVolumeLevel
, tmp
+2 );
639 CHECK_REFCOUNT ( pVolumeTexture
, tmp
+2 );
640 CHECK_RELEASE_REFCOUNT( pVolumeLevel
, tmp
+1 );
641 CHECK_REFCOUNT ( pVolumeTexture
, tmp
+1 );
642 CHECK_RELEASE_REFCOUNT( pVolumeTexture
, tmp
);
643 CHECK_REFCOUNT ( pVolumeLevel
, tmp
);
647 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 32, 32,
648 D3DFMT_D16
, D3DMULTISAMPLE_NONE
, &pStencilSurface
);
649 CHECK_CALL(hr
, "CreateDepthStencilSurface", device
, ++refcount
);
650 CHECK_REFCOUNT( pStencilSurface
, 1);
651 hr
= IDirect3DDevice8_CreateImageSurface(device
, 32, 32,
652 D3DFMT_X8R8G8B8
, &pImageSurface
);
653 CHECK_CALL(hr
, "CreateImageSurface", device
, ++refcount
);
654 CHECK_REFCOUNT( pImageSurface
, 1);
655 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 32, 32,
656 D3DFMT_X8R8G8B8
, D3DMULTISAMPLE_NONE
, TRUE
, &pRenderTarget3
);
657 CHECK_CALL(hr
, "CreateRenderTarget", device
, ++refcount
);
658 CHECK_REFCOUNT( pRenderTarget3
, 1);
660 hr
= IDirect3DDevice8_CreateStateBlock(device
, D3DSBT_ALL
, &dStateBlock
);
661 CHECK_CALL(hr
, "CreateStateBlock", device
, refcount
);
663 memset(&d3dpp
, 0, sizeof(d3dpp
));
664 d3dpp
.Windowed
= TRUE
;
665 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
666 d3dpp
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
667 d3dpp
.EnableAutoDepthStencil
= TRUE
;
668 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
669 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &pSwapChain
);
670 CHECK_CALL(hr
, "CreateAdditionalSwapChain", device
, ++refcount
);
673 /* check implicit back buffer */
674 hr
= IDirect3DSwapChain8_GetBackBuffer(pSwapChain
, 0, 0, &pBackBuffer
);
675 CHECK_CALL(hr
, "GetBackBuffer", device
, ++refcount
);
676 CHECK_REFCOUNT( pSwapChain
, 1);
679 CHECK_SURFACE_CONTAINER(pBackBuffer
, IID_IDirect3DDevice8
, device
);
680 CHECK_REFCOUNT( pBackBuffer
, 1);
681 CHECK_RELEASE_REFCOUNT( pBackBuffer
, 0);
682 CHECK_REFCOUNT(device
, --refcount
);
684 /* The back buffer is released with the swapchain, so AddRef with refcount=0 is fine here. */
685 CHECK_ADDREF_REFCOUNT(pBackBuffer
, 1);
686 CHECK_REFCOUNT(device
, ++refcount
);
687 CHECK_RELEASE_REFCOUNT(pBackBuffer
, 0);
688 CHECK_REFCOUNT(device
, --refcount
);
691 CHECK_REFCOUNT( pSwapChain
, 1);
697 /* Vertex buffers can be locked multiple times */
698 hr
= IDirect3DVertexBuffer8_Lock(pVertexBuffer
, 0, 0, &data
, 0);
699 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr
);
700 hr
= IDirect3DVertexBuffer8_Lock(pVertexBuffer
, 0, 0, &data
, 0);
701 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr
);
702 hr
= IDirect3DVertexBuffer8_Unlock(pVertexBuffer
);
703 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr
);
704 hr
= IDirect3DVertexBuffer8_Unlock(pVertexBuffer
);
705 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr
);
708 /* The implicit render target is not freed if refcount reaches 0.
709 * Otherwise GetRenderTarget would re-allocate it and the pointer would change.*/
710 hr
= IDirect3DDevice8_GetRenderTarget(device
, &pRenderTarget2
);
711 CHECK_CALL(hr
, "GetRenderTarget", device
, ++refcount
);
714 CHECK_RELEASE_REFCOUNT(pRenderTarget2
, 0);
715 ok(pRenderTarget
== pRenderTarget2
, "RenderTarget=%p and RenderTarget2=%p should be the same.\n",
716 pRenderTarget
, pRenderTarget2
);
717 CHECK_REFCOUNT(device
, --refcount
);
718 pRenderTarget2
= NULL
;
720 pRenderTarget
= NULL
;
723 CHECK_RELEASE(device
, device
, --refcount
);
726 CHECK_RELEASE(pVertexBuffer
, device
, --refcount
);
727 CHECK_RELEASE(pIndexBuffer
, device
, --refcount
);
729 if (dVertexShader
!= ~0u)
730 IDirect3DDevice8_DeleteVertexShader(device
, dVertexShader
);
731 if (dPixelShader
!= ~0u)
732 IDirect3DDevice8_DeletePixelShader(device
, dPixelShader
);
734 CHECK_RELEASE(pTexture
, device
, --refcount
);
735 CHECK_RELEASE(pCubeTexture
, device
, --refcount
);
736 CHECK_RELEASE(pVolumeTexture
, device
, --refcount
);
738 CHECK_RELEASE(pStencilSurface
, device
, --refcount
);
739 CHECK_RELEASE(pImageSurface
, device
, --refcount
);
740 CHECK_RELEASE(pRenderTarget3
, device
, --refcount
);
742 if (dStateBlock
!= ~0u)
743 IDirect3DDevice8_DeleteStateBlock(device
, dStateBlock
);
744 /* This will destroy device - cannot check the refcount here */
746 CHECK_RELEASE_REFCOUNT(pSwapChain
, 0);
747 CHECK_RELEASE_REFCOUNT(d3d
, 0);
748 DestroyWindow(window
);
751 static void test_cursor(void)
753 HMODULE user32_handle
= GetModuleHandleA("user32.dll");
754 IDirect3DSurface8
*cursor
= NULL
;
755 IDirect3DDevice8
*device
;
764 pGetCursorInfo
= (void *)GetProcAddress(user32_handle
, "GetCursorInfo");
767 win_skip("GetCursorInfo is not available\n");
771 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
772 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
773 ok(!!window
, "Failed to create a window.\n");
775 ret
= SetCursorPos(50, 50);
776 ok(ret
, "Failed to set cursor position.\n");
779 memset(&info
, 0, sizeof(info
));
780 info
.cbSize
= sizeof(info
);
781 ok(pGetCursorInfo(&info
), "GetCursorInfo failed\n");
784 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
785 ok(!!d3d
, "Failed to create a D3D object.\n");
786 if (!(device
= create_device(d3d
, window
, NULL
)))
788 skip("Failed to create a 3D device, skipping test.\n");
792 hr
= IDirect3DDevice8_CreateImageSurface(device
, 32, 32, D3DFMT_A8R8G8B8
, &cursor
);
793 ok(SUCCEEDED(hr
), "Failed to create cursor surface, hr %#x.\n", hr
);
795 /* Initially hidden */
796 hr
= IDirect3DDevice8_ShowCursor(device
, TRUE
);
797 ok(hr
== FALSE
, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr
);
799 /* Not enabled without a surface*/
800 hr
= IDirect3DDevice8_ShowCursor(device
, TRUE
);
801 ok(hr
== FALSE
, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr
);
804 hr
= IDirect3DDevice8_SetCursorProperties(device
, 0, 0, NULL
);
805 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr
);
807 hr
= IDirect3DDevice8_SetCursorProperties(device
, 0, 0, cursor
);
808 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr
);
810 IDirect3DSurface8_Release(cursor
);
812 memset(&info
, 0, sizeof(info
));
813 info
.cbSize
= sizeof(info
);
814 ok(pGetCursorInfo(&info
), "GetCursorInfo failed\n");
815 ok(info
.flags
& CURSOR_SHOWING
, "The gdi cursor is hidden (%08x)\n", info
.flags
);
816 ok(info
.hCursor
== cur
, "The cursor handle is %p\n", info
.hCursor
); /* unchanged */
819 hr
= IDirect3DDevice8_ShowCursor(device
, TRUE
);
820 ok(hr
== FALSE
, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr
);
823 hr
= IDirect3DDevice8_ShowCursor(device
, TRUE
);
824 ok(hr
== TRUE
, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr
);
826 memset(&info
, 0, sizeof(info
));
827 info
.cbSize
= sizeof(info
);
828 ok(pGetCursorInfo(&info
), "GetCursorInfo failed\n");
829 ok(info
.flags
& CURSOR_SHOWING
, "The gdi cursor is hidden (%08x)\n", info
.flags
);
830 ok(info
.hCursor
!= cur
, "The cursor handle is %p\n", info
.hCursor
);
832 refcount
= IDirect3DDevice8_Release(device
);
833 ok(!refcount
, "Device has %u references left.\n", refcount
);
835 IDirect3D8_Release(d3d
);
836 DestroyWindow(window
);
839 static const POINT
*expect_pos
;
841 static LRESULT CALLBACK
test_cursor_proc(HWND window
, UINT message
, WPARAM wparam
, LPARAM lparam
)
843 if (message
== WM_MOUSEMOVE
)
845 if (expect_pos
&& expect_pos
->x
&& expect_pos
->y
)
847 POINT p
= {GET_X_LPARAM(lparam
), GET_Y_LPARAM(lparam
)};
849 ClientToScreen(window
, &p
);
850 if (expect_pos
->x
== p
.x
&& expect_pos
->y
== p
.y
)
855 return DefWindowProcA(window
, message
, wparam
, lparam
);
858 static void test_cursor_pos(void)
860 IDirect3DSurface8
*cursor
;
861 IDirect3DDevice8
*device
;
869 /* Note that we don't check for movement we're not supposed to receive.
870 * That's because it's hard to distinguish from the user accidentally
871 * moving the mouse. */
872 static const POINT points
[] =
885 wc
.lpfnWndProc
= test_cursor_proc
;
886 wc
.lpszClassName
= "d3d8_test_cursor_wc";
887 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
888 window
= CreateWindowA("d3d8_test_cursor_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
889 0, 0, 320, 240, NULL
, NULL
, NULL
, NULL
);
890 ShowWindow(window
, SW_SHOW
);
891 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
892 ok(!!d3d8
, "Failed to create a D3D object.\n");
894 if (!(device
= create_device(d3d8
, window
, NULL
)))
896 skip("Failed to create a D3D device, skipping tests.\n");
900 hr
= IDirect3DDevice8_CreateImageSurface(device
, 32, 32, D3DFMT_A8R8G8B8
, &cursor
);
901 ok(SUCCEEDED(hr
), "Failed to create cursor surface, hr %#x.\n", hr
);
902 hr
= IDirect3DDevice8_SetCursorProperties(device
, 0, 0, cursor
);
903 ok(SUCCEEDED(hr
), "Failed to set cursor properties, hr %#x.\n", hr
);
904 IDirect3DSurface8_Release(cursor
);
905 ret
= IDirect3DDevice8_ShowCursor(device
, TRUE
);
906 ok(!ret
, "Failed to show cursor, hr %#x.\n", ret
);
911 ret
= SetCursorPos(50, 50);
912 ok(ret
, "Failed to set cursor position.\n");
915 IDirect3DDevice8_SetCursorPosition(device
, 75, 75, 0);
917 /* SetCursorPosition() eats duplicates. */
918 IDirect3DDevice8_SetCursorPosition(device
, 75, 75, 0);
921 ret
= SetCursorPos(100, 100);
922 ok(ret
, "Failed to set cursor position.\n");
924 /* Even if the position was set with SetCursorPos(). */
925 IDirect3DDevice8_SetCursorPosition(device
, 100, 100, 0);
928 IDirect3DDevice8_SetCursorPosition(device
, 125, 125, 0);
930 ret
= SetCursorPos(150, 150);
931 ok(ret
, "Failed to set cursor position.\n");
933 IDirect3DDevice8_SetCursorPosition(device
, 125, 125, 0);
936 IDirect3DDevice8_SetCursorPosition(device
, 150, 150, 0);
938 /* SetCursorPos() doesn't. */
939 ret
= SetCursorPos(150, 150);
940 ok(ret
, "Failed to set cursor position.\n");
943 ok(!expect_pos
->x
&& !expect_pos
->y
, "Didn't receive MOUSEMOVE %u (%d, %d).\n",
944 (unsigned)(expect_pos
- points
), expect_pos
->x
, expect_pos
->y
);
946 refcount
= IDirect3DDevice8_Release(device
);
947 ok(!refcount
, "Device has %u references left.\n", refcount
);
949 DestroyWindow(window
);
950 UnregisterClassA("d3d8_test_cursor_wc", GetModuleHandleA(NULL
));
951 IDirect3D8_Release(d3d8
);
954 static void test_states(void)
956 IDirect3DDevice8
*device
;
962 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
963 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
964 ok(!!window
, "Failed to create a window.\n");
965 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
966 ok(!!d3d
, "Failed to create a D3D object.\n");
967 if (!(device
= create_device(d3d
, window
, NULL
)))
969 skip("Failed to create a 3D device, skipping test.\n");
973 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZVISIBLE
, TRUE
);
974 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, TRUE) returned %#08x\n", hr
);
975 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZVISIBLE
, FALSE
);
976 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, FALSE) returned %#08x\n", hr
);
978 refcount
= IDirect3DDevice8_Release(device
);
979 ok(!refcount
, "Device has %u references left.\n", refcount
);
981 IDirect3D8_Release(d3d
);
982 DestroyWindow(window
);
985 static void test_shader_versions(void)
991 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
992 ok(!!d3d
, "Failed to create a D3D object.\n");
994 hr
= IDirect3D8_GetDeviceCaps(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, &caps
);
995 ok(SUCCEEDED(hr
) || hr
== D3DERR_NOTAVAILABLE
, "Failed to get device caps, hr %#x.\n", hr
);
996 IDirect3D8_Release(d3d
);
999 skip("No Direct3D support, skipping test.\n");
1003 ok(caps
.VertexShaderVersion
<= D3DVS_VERSION(1,1),
1004 "Got unexpected VertexShaderVersion %#x.\n", caps
.VertexShaderVersion
);
1005 ok(caps
.PixelShaderVersion
<= D3DPS_VERSION(1,4),
1006 "Got unexpected PixelShaderVersion %#x.\n", caps
.PixelShaderVersion
);
1009 static void test_display_formats(void)
1011 D3DDEVTYPE device_type
= D3DDEVTYPE_HAL
;
1012 unsigned int backbuffer
, display
;
1013 unsigned int windowed
, i
;
1014 D3DDISPLAYMODE mode
;
1024 D3DFORMAT alpha_format
;
1030 {"D3DFMT_R5G6B5", D3DFMT_R5G6B5
, 0, TRUE
, TRUE
},
1031 {"D3DFMT_X1R5G5B5", D3DFMT_X1R5G5B5
, D3DFMT_A1R5G5B5
, TRUE
, TRUE
},
1032 {"D3DFMT_A1R5G5B5", D3DFMT_A1R5G5B5
, D3DFMT_A1R5G5B5
, FALSE
, FALSE
},
1033 {"D3DFMT_X8R8G8B8", D3DFMT_X8R8G8B8
, D3DFMT_A8R8G8B8
, TRUE
, TRUE
},
1034 {"D3DFMT_A8R8G8B8", D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
, FALSE
, FALSE
},
1035 {"D3DFMT_UNKNOWN", D3DFMT_UNKNOWN
, 0, FALSE
, FALSE
},
1038 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
1039 ok(!!d3d8
, "Failed to create a D3D object.\n");
1041 for (display
= 0; display
< sizeof(formats
) / sizeof(*formats
); ++display
)
1043 for (i
= 0, has_modes
= FALSE
; SUCCEEDED(IDirect3D8_EnumAdapterModes(d3d8
, D3DADAPTER_DEFAULT
, i
, &mode
)); ++i
)
1045 if (mode
.Format
== formats
[display
].format
)
1052 for (windowed
= 0; windowed
<= 1; ++windowed
)
1054 for (backbuffer
= 0; backbuffer
< sizeof(formats
) / sizeof(*formats
); ++backbuffer
)
1056 should_pass
= FALSE
;
1058 if (formats
[display
].display
&& (formats
[display
].windowed
|| !windowed
) && (has_modes
|| windowed
))
1060 D3DFORMAT backbuffer_format
;
1062 if (windowed
&& formats
[backbuffer
].format
== D3DFMT_UNKNOWN
)
1063 backbuffer_format
= formats
[display
].format
;
1065 backbuffer_format
= formats
[backbuffer
].format
;
1067 hr
= IDirect3D8_CheckDeviceFormat(d3d8
, D3DADAPTER_DEFAULT
, device_type
, formats
[display
].format
,
1068 D3DUSAGE_RENDERTARGET
, D3DRTYPE_SURFACE
, backbuffer_format
);
1069 should_pass
= (hr
== D3D_OK
) && (formats
[display
].format
== formats
[backbuffer
].format
1070 || (formats
[display
].alpha_format
1071 && formats
[display
].alpha_format
== formats
[backbuffer
].alpha_format
));
1074 hr
= IDirect3D8_CheckDeviceType(d3d8
, D3DADAPTER_DEFAULT
, device_type
,
1075 formats
[display
].format
, formats
[backbuffer
].format
, windowed
);
1076 ok(SUCCEEDED(hr
) == should_pass
|| broken(SUCCEEDED(hr
) && !has_modes
) /* Win8 64-bit */,
1077 "Got unexpected hr %#x for %s / %s, windowed %#x, should_pass %#x.\n",
1078 hr
, formats
[display
].name
, formats
[backbuffer
].name
, windowed
, should_pass
);
1083 IDirect3D8_Release(d3d8
);
1086 /* Test adapter display modes */
1087 static void test_display_modes(void)
1090 D3DDISPLAYMODE dmode
;
1094 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
1095 ok(!!d3d
, "Failed to create a D3D object.\n");
1097 max_modes
= IDirect3D8_GetAdapterModeCount(d3d
, D3DADAPTER_DEFAULT
);
1099 broken(max_modes
== 0), /* VMware */
1100 "GetAdapterModeCount(D3DADAPTER_DEFAULT) returned 0!\n");
1102 for (i
= 0; i
< max_modes
; ++i
)
1104 res
= IDirect3D8_EnumAdapterModes(d3d
, D3DADAPTER_DEFAULT
, i
, &dmode
);
1105 ok(res
==D3D_OK
, "EnumAdapterModes returned %#08x for mode %u!\n", res
, i
);
1109 ok(dmode
.Format
==D3DFMT_X8R8G8B8
|| dmode
.Format
==D3DFMT_R5G6B5
,
1110 "Unexpected display mode returned for mode %u: %#x\n", i
, dmode
.Format
);
1113 IDirect3D8_Release(d3d
);
1116 static void test_reset(void)
1118 UINT width
, orig_width
= GetSystemMetrics(SM_CXSCREEN
);
1119 UINT height
, orig_height
= GetSystemMetrics(SM_CYSCREEN
);
1120 IDirect3DDevice8
*device1
= NULL
;
1121 IDirect3DDevice8
*device2
= NULL
;
1122 D3DDISPLAYMODE d3ddm
, d3ddm2
;
1123 D3DSURFACE_DESC surface_desc
;
1124 D3DPRESENT_PARAMETERS d3dpp
;
1125 IDirect3DSurface8
*surface
;
1126 IDirect3DTexture8
*texture
;
1127 UINT adapter_mode_count
;
1128 D3DLOCKED_RECT lockrect
;
1129 UINT mode_count
= 0;
1140 static const DWORD decl
[] =
1143 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT4
),
1153 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
1154 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1155 ok(!!window
, "Failed to create a window.\n");
1156 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
1157 ok(!!d3d8
, "Failed to create a D3D object.\n");
1159 hr
= IDirect3D8_GetAdapterDisplayMode(d3d8
, D3DADAPTER_DEFAULT
, &d3ddm
);
1160 ok(SUCCEEDED(hr
), "GetAdapterDisplayMode failed, hr %#x.\n", hr
);
1161 adapter_mode_count
= IDirect3D8_GetAdapterModeCount(d3d8
, D3DADAPTER_DEFAULT
);
1162 modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(*modes
) * adapter_mode_count
);
1163 for (i
= 0; i
< adapter_mode_count
; ++i
)
1167 memset(&d3ddm2
, 0, sizeof(d3ddm2
));
1168 hr
= IDirect3D8_EnumAdapterModes(d3d8
, D3DADAPTER_DEFAULT
, i
, &d3ddm2
);
1169 ok(SUCCEEDED(hr
), "EnumAdapterModes failed, hr %#x.\n", hr
);
1171 if (d3ddm2
.Format
!= d3ddm
.Format
)
1174 for (j
= 0; j
< mode_count
; ++j
)
1176 if (modes
[j
].w
== d3ddm2
.Width
&& modes
[j
].h
== d3ddm2
.Height
)
1179 if (j
== mode_count
)
1181 modes
[j
].w
= d3ddm2
.Width
;
1182 modes
[j
].h
= d3ddm2
.Height
;
1186 /* We use them as invalid modes. */
1187 if ((d3ddm2
.Width
== 801 && d3ddm2
.Height
== 600)
1188 || (d3ddm2
.Width
== 32 && d3ddm2
.Height
== 32))
1190 skip("This system supports a screen resolution of %dx%d, not running mode tests.\n",
1191 d3ddm2
.Width
, d3ddm2
.Height
);
1198 skip("Less than 2 modes supported, skipping mode tests.\n");
1203 if (modes
[i
].w
== orig_width
&& modes
[i
].h
== orig_height
) ++i
;
1205 memset(&d3dpp
, 0, sizeof(d3dpp
));
1206 d3dpp
.Windowed
= FALSE
;
1207 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1208 d3dpp
.BackBufferWidth
= modes
[i
].w
;
1209 d3dpp
.BackBufferHeight
= modes
[i
].h
;
1210 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1211 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1212 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1214 hr
= IDirect3D8_CreateDevice(d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
1215 window
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &device1
);
1218 skip("Failed to create device, hr %#x.\n", hr
);
1221 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1222 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1224 hr
= IDirect3DDevice8_GetDeviceCaps(device1
, &caps
);
1225 ok(SUCCEEDED(hr
), "GetDeviceCaps failed, hr %#x.\n", hr
);
1227 width
= GetSystemMetrics(SM_CXSCREEN
);
1228 height
= GetSystemMetrics(SM_CYSCREEN
);
1229 ok(width
== modes
[i
].w
, "Screen width is %u, expected %u.\n", width
, modes
[i
].w
);
1230 ok(height
== modes
[i
].h
, "Screen height is %u, expected %u.\n", height
, modes
[i
].h
);
1232 hr
= IDirect3DDevice8_GetViewport(device1
, &vp
);
1233 ok(SUCCEEDED(hr
), "GetViewport failed, hr %#x.\n", hr
);
1236 ok(vp
.X
== 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp
.X
);
1237 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp
.Y
);
1238 ok(vp
.Width
== modes
[i
].w
, "D3DVIEWPORT->Width = %u, expected %u.\n", vp
.Width
, modes
[i
].w
);
1239 ok(vp
.Height
== modes
[i
].h
, "D3DVIEWPORT->Height = %u, expected %u.\n", vp
.Height
, modes
[i
].h
);
1240 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp
.MinZ
);
1241 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp
.MaxZ
);
1247 vp
.Width
= modes
[i
].w
/ 2;
1248 vp
.Height
= modes
[i
].h
/ 2;
1251 hr
= IDirect3DDevice8_SetViewport(device1
, &vp
);
1252 ok(SUCCEEDED(hr
), "SetViewport failed, hr %#x.\n", hr
);
1254 hr
= IDirect3DDevice8_GetRenderState(device1
, D3DRS_LIGHTING
, &value
);
1255 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1256 ok(!!value
, "Got unexpected value %#x for D3DRS_LIGHTING.\n", value
);
1257 hr
= IDirect3DDevice8_SetRenderState(device1
, D3DRS_LIGHTING
, FALSE
);
1258 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
1260 memset(&d3dpp
, 0, sizeof(d3dpp
));
1261 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1262 d3dpp
.Windowed
= FALSE
;
1263 d3dpp
.BackBufferWidth
= modes
[i
].w
;
1264 d3dpp
.BackBufferHeight
= modes
[i
].h
;
1265 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1266 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1267 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1268 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1269 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1271 hr
= IDirect3DDevice8_GetRenderState(device1
, D3DRS_LIGHTING
, &value
);
1272 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1273 ok(!!value
, "Got unexpected value %#x for D3DRS_LIGHTING.\n", value
);
1275 memset(&vp
, 0, sizeof(vp
));
1276 hr
= IDirect3DDevice8_GetViewport(device1
, &vp
);
1277 ok(SUCCEEDED(hr
), "GetViewport failed, hr %#x.\n", hr
);
1280 ok(vp
.X
== 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp
.X
);
1281 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp
.Y
);
1282 ok(vp
.Width
== modes
[i
].w
, "D3DVIEWPORT->Width = %u, expected %u.\n", vp
.Width
, modes
[i
].w
);
1283 ok(vp
.Height
== modes
[i
].h
, "D3DVIEWPORT->Height = %u, expected %u.\n", vp
.Height
, modes
[i
].h
);
1284 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp
.MinZ
);
1285 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp
.MaxZ
);
1288 width
= GetSystemMetrics(SM_CXSCREEN
);
1289 height
= GetSystemMetrics(SM_CYSCREEN
);
1290 ok(width
== modes
[i
].w
, "Screen width is %u, expected %u.\n", width
, modes
[i
].w
);
1291 ok(height
== modes
[i
].h
, "Screen height is %u, expected %u.\n", height
, modes
[i
].h
);
1293 hr
= IDirect3DDevice8_GetRenderTarget(device1
, &surface
);
1294 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
1295 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
1296 ok(hr
== D3D_OK
, "GetDesc failed, hr %#x.\n", hr
);
1297 ok(surface_desc
.Width
== modes
[i
].w
, "Back buffer width is %u, expected %u.\n",
1298 surface_desc
.Width
, modes
[i
].w
);
1299 ok(surface_desc
.Height
== modes
[i
].h
, "Back buffer height is %u, expected %u.\n",
1300 surface_desc
.Height
, modes
[i
].h
);
1301 IDirect3DSurface8_Release(surface
);
1303 memset(&d3dpp
, 0, sizeof(d3dpp
));
1304 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1305 d3dpp
.Windowed
= TRUE
;
1306 d3dpp
.BackBufferWidth
= 400;
1307 d3dpp
.BackBufferHeight
= 300;
1308 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1309 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1310 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1311 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1312 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1314 memset(&vp
, 0, sizeof(vp
));
1315 hr
= IDirect3DDevice8_GetViewport(device1
, &vp
);
1316 ok(SUCCEEDED(hr
), "GetViewport failed, hr %#x.\n", hr
);
1319 ok(vp
.X
== 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp
.X
);
1320 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp
.Y
);
1321 ok(vp
.Width
== 400, "D3DVIEWPORT->Width = %u, expected 400.\n", vp
.Width
);
1322 ok(vp
.Height
== 300, "D3DVIEWPORT->Height = %u, expected 300.\n", vp
.Height
);
1323 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp
.MinZ
);
1324 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp
.MaxZ
);
1327 width
= GetSystemMetrics(SM_CXSCREEN
);
1328 height
= GetSystemMetrics(SM_CYSCREEN
);
1329 ok(width
== orig_width
, "Screen width is %u, expected %u.\n", width
, orig_width
);
1330 ok(height
== orig_height
, "Screen height is %u, expected %u.\n", height
, orig_height
);
1332 hr
= IDirect3DDevice8_GetRenderTarget(device1
, &surface
);
1333 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
1334 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
1335 ok(hr
== D3D_OK
, "GetDesc failed, hr %#x.\n", hr
);
1336 ok(surface_desc
.Width
== 400, "Back buffer width is %u, expected 400.\n",
1337 surface_desc
.Width
);
1338 ok(surface_desc
.Height
== 300, "Back buffer height is %u, expected 300.\n",
1339 surface_desc
.Height
);
1340 IDirect3DSurface8_Release(surface
);
1344 winrect
.right
= 200;
1345 winrect
.bottom
= 150;
1346 ok(AdjustWindowRect(&winrect
, WS_OVERLAPPEDWINDOW
, FALSE
), "AdjustWindowRect failed\n");
1347 ok(SetWindowPos(window
, NULL
, 0, 0,
1348 winrect
.right
-winrect
.left
,
1349 winrect
.bottom
-winrect
.top
,
1350 SWP_NOMOVE
|SWP_NOZORDER
),
1351 "SetWindowPos failed\n");
1353 memset(&d3dpp
, 0, sizeof(d3dpp
));
1354 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1355 d3dpp
.Windowed
= TRUE
;
1356 d3dpp
.BackBufferWidth
= 0;
1357 d3dpp
.BackBufferHeight
= 0;
1358 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1359 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1360 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1361 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1362 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1364 memset(&vp
, 0, sizeof(vp
));
1365 hr
= IDirect3DDevice8_GetViewport(device1
, &vp
);
1366 ok(SUCCEEDED(hr
), "GetViewport failed, hr %#x.\n", hr
);
1369 ok(vp
.X
== 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp
.X
);
1370 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp
.Y
);
1371 ok(vp
.Width
== 200, "D3DVIEWPORT->Width = %u, expected 200.\n", vp
.Width
);
1372 ok(vp
.Height
== 150, "D3DVIEWPORT->Height = %u, expected 150.\n", vp
.Height
);
1373 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp
.MinZ
);
1374 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp
.MaxZ
);
1377 hr
= IDirect3DDevice8_GetRenderTarget(device1
, &surface
);
1378 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
1379 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
1380 ok(hr
== D3D_OK
, "GetDesc failed, hr %#x.\n", hr
);
1381 ok(surface_desc
.Width
== 200, "Back buffer width is %u, expected 200.\n", surface_desc
.Width
);
1382 ok(surface_desc
.Height
== 150, "Back buffer height is %u, expected 150.\n", surface_desc
.Height
);
1383 IDirect3DSurface8_Release(surface
);
1385 memset(&d3dpp
, 0, sizeof(d3dpp
));
1386 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1387 d3dpp
.Windowed
= TRUE
;
1388 d3dpp
.BackBufferWidth
= 400;
1389 d3dpp
.BackBufferHeight
= 300;
1390 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1392 /* Reset fails if there is a resource in the default pool. */
1393 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_DEFAULT
, &texture
);
1394 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
1395 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1396 ok(hr
== D3DERR_DEVICELOST
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_DEVICELOST
);
1397 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1398 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n", hr
, D3DERR_DEVICENOTRESET
);
1399 IDirect3DTexture8_Release(texture
);
1400 /* Reset again to get the device out of the lost state. */
1401 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1402 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1403 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1404 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1406 if (caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
)
1408 IDirect3DVolumeTexture8
*volume_texture
;
1410 hr
= IDirect3DDevice8_CreateVolumeTexture(device1
, 16, 16, 4, 1, 0,
1411 D3DFMT_R5G6B5
, D3DPOOL_DEFAULT
, &volume_texture
);
1412 ok(SUCCEEDED(hr
), "CreateVolumeTexture failed, hr %#x.\n", hr
);
1413 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1414 ok(hr
== D3DERR_DEVICELOST
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
1415 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1416 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n",
1417 hr
, D3DERR_DEVICENOTRESET
);
1418 IDirect3DVolumeTexture8_Release(volume_texture
);
1419 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1420 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1421 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1422 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1426 skip("Volume textures not supported.\n");
1429 /* Scratch, sysmem and managed pool resources are fine. */
1430 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_SCRATCH
, &texture
);
1431 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
1432 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1433 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1434 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1435 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1436 IDirect3DTexture8_Release(texture
);
1438 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_SYSTEMMEM
, &texture
);
1439 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
1440 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1441 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1442 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1443 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1444 IDirect3DTexture8_Release(texture
);
1446 /* The depth stencil should get reset to the auto depth stencil when present. */
1447 hr
= IDirect3DDevice8_SetRenderTarget(device1
, NULL
, NULL
);
1448 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
1450 hr
= IDirect3DDevice8_GetDepthStencilSurface(device1
, &surface
);
1451 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned %#x, expected %#x.\n", hr
, D3DERR_NOTFOUND
);
1452 ok(!surface
, "Depth / stencil buffer should be NULL.\n");
1454 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1455 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1456 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1457 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1459 hr
= IDirect3DDevice8_GetDepthStencilSurface(device1
, &surface
);
1460 ok(SUCCEEDED(hr
), "GetDepthStencilSurface failed, hr %#x.\n", hr
);
1461 ok(!!surface
, "Depth / stencil buffer should not be NULL.\n");
1462 if (surface
) IDirect3DSurface8_Release(surface
);
1464 d3dpp
.EnableAutoDepthStencil
= FALSE
;
1465 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1466 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1468 hr
= IDirect3DDevice8_GetDepthStencilSurface(device1
, &surface
);
1469 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned %#x, expected %#x.\n", hr
, D3DERR_NOTFOUND
);
1470 ok(!surface
, "Depth / stencil buffer should be NULL.\n");
1472 /* Will a sysmem or scratch resource survive while locked? */
1473 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_SYSTEMMEM
, &texture
);
1474 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
1475 hr
= IDirect3DTexture8_LockRect(texture
, 0, &lockrect
, NULL
, D3DLOCK_DISCARD
);
1476 ok(SUCCEEDED(hr
), "LockRect failed, hr %#x.\n", hr
);
1477 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1478 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1479 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1480 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1481 IDirect3DTexture8_UnlockRect(texture
, 0);
1482 IDirect3DTexture8_Release(texture
);
1484 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_SCRATCH
, &texture
);
1485 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
1486 hr
= IDirect3DTexture8_LockRect(texture
, 0, &lockrect
, NULL
, D3DLOCK_DISCARD
);
1487 ok(SUCCEEDED(hr
), "LockRect failed, hr %#x.\n", hr
);
1488 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1489 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1490 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1491 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1492 IDirect3DTexture8_UnlockRect(texture
, 0);
1493 IDirect3DTexture8_Release(texture
);
1495 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_MANAGED
, &texture
);
1496 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
1497 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1498 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1499 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1500 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1501 IDirect3DTexture8_Release(texture
);
1503 /* A reference held to an implicit surface causes failures as well. */
1504 hr
= IDirect3DDevice8_GetBackBuffer(device1
, 0, D3DBACKBUFFER_TYPE_MONO
, &surface
);
1505 ok(SUCCEEDED(hr
), "GetBackBuffer failed, hr %#x.\n", hr
);
1506 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1507 ok(hr
== D3DERR_DEVICELOST
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_DEVICELOST
);
1508 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1509 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n", hr
, D3DERR_DEVICENOTRESET
);
1510 IDirect3DSurface8_Release(surface
);
1511 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1512 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1513 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1514 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1516 /* Shaders are fine as well. */
1517 hr
= IDirect3DDevice8_CreateVertexShader(device1
, decl
, simple_vs
, &shader
, 0);
1518 ok(SUCCEEDED(hr
), "CreateVertexShader failed, hr %#x.\n", hr
);
1519 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1520 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1521 hr
= IDirect3DDevice8_DeleteVertexShader(device1
, shader
);
1522 ok(SUCCEEDED(hr
), "DeleteVertexShader failed, hr %#x.\n", hr
);
1524 /* Try setting invalid modes. */
1525 memset(&d3dpp
, 0, sizeof(d3dpp
));
1526 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1527 d3dpp
.Windowed
= FALSE
;
1528 d3dpp
.BackBufferWidth
= 32;
1529 d3dpp
.BackBufferHeight
= 32;
1530 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1531 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1532 ok(hr
== D3DERR_INVALIDCALL
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
1533 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1534 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n", hr
, D3DERR_DEVICENOTRESET
);
1536 memset(&d3dpp
, 0, sizeof(d3dpp
));
1537 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1538 d3dpp
.Windowed
= FALSE
;
1539 d3dpp
.BackBufferWidth
= 801;
1540 d3dpp
.BackBufferHeight
= 600;
1541 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1542 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1543 ok(hr
== D3DERR_INVALIDCALL
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
1544 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1545 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n", hr
, D3DERR_DEVICENOTRESET
);
1547 memset(&d3dpp
, 0, sizeof(d3dpp
));
1548 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1549 d3dpp
.Windowed
= FALSE
;
1550 d3dpp
.BackBufferWidth
= 0;
1551 d3dpp
.BackBufferHeight
= 0;
1552 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1553 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1554 ok(hr
== D3DERR_INVALIDCALL
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
1555 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1556 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n", hr
, D3DERR_DEVICENOTRESET
);
1558 hr
= IDirect3D8_GetAdapterDisplayMode(d3d8
, D3DADAPTER_DEFAULT
, &d3ddm
);
1559 ok(SUCCEEDED(hr
), "GetAdapterDisplayMode failed, hr %#x.\n", hr
);
1561 memset(&d3dpp
, 0, sizeof(d3dpp
));
1562 d3dpp
.Windowed
= TRUE
;
1563 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1564 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1565 d3dpp
.EnableAutoDepthStencil
= FALSE
;
1566 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1568 hr
= IDirect3D8_CreateDevice(d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
1569 window
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &device2
);
1572 skip("Failed to create device, hr %#x.\n", hr
);
1576 hr
= IDirect3DDevice8_TestCooperativeLevel(device2
);
1577 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1579 d3dpp
.Windowed
= TRUE
;
1580 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1581 d3dpp
.BackBufferWidth
= 400;
1582 d3dpp
.BackBufferHeight
= 300;
1583 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1584 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1585 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1587 hr
= IDirect3DDevice8_Reset(device2
, &d3dpp
);
1588 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1592 hr
= IDirect3DDevice8_GetDepthStencilSurface(device2
, &surface
);
1593 ok(SUCCEEDED(hr
), "GetDepthStencilSurface failed, hr %#x.\n", hr
);
1594 ok(!!surface
, "Depth / stencil buffer should not be NULL.\n");
1596 IDirect3DSurface8_Release(surface
);
1599 HeapFree(GetProcessHeap(), 0, modes
);
1601 IDirect3DDevice8_Release(device2
);
1603 IDirect3DDevice8_Release(device1
);
1604 IDirect3D8_Release(d3d8
);
1605 DestroyWindow(window
);
1608 static void test_scene(void)
1610 IDirect3DDevice8
*device
;
1616 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
1617 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
1618 ok(!!window
, "Failed to create a window.\n");
1619 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
1620 ok(!!d3d
, "Failed to create a D3D object.\n");
1621 if (!(device
= create_device(d3d
, window
, NULL
)))
1623 skip("Failed to create a 3D device, skipping test.\n");
1627 /* Test an EndScene without BeginScene. Should return an error */
1628 hr
= IDirect3DDevice8_EndScene(device
);
1629 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
1631 /* Test a normal BeginScene / EndScene pair, this should work */
1632 hr
= IDirect3DDevice8_BeginScene(device
);
1633 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr
);
1634 hr
= IDirect3DDevice8_EndScene(device
);
1635 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed with %#08x\n", hr
);
1637 /* Test another EndScene without having begun a new scene. Should return an error */
1638 hr
= IDirect3DDevice8_EndScene(device
);
1639 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
1641 /* Two nested BeginScene and EndScene calls */
1642 hr
= IDirect3DDevice8_BeginScene(device
);
1643 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr
);
1644 hr
= IDirect3DDevice8_BeginScene(device
);
1645 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_BeginScene returned %#08x\n", hr
);
1646 hr
= IDirect3DDevice8_EndScene(device
);
1647 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed with %#08x\n", hr
);
1648 hr
= IDirect3DDevice8_EndScene(device
);
1649 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
1651 /* StretchRect does not exit in Direct3D8, so no equivalent to the d3d9 stretchrect tests */
1653 refcount
= IDirect3DDevice8_Release(device
);
1654 ok(!refcount
, "Device has %u references left.\n", refcount
);
1656 IDirect3D8_Release(d3d
);
1657 DestroyWindow(window
);
1660 static void test_shader(void)
1662 DWORD hPixelShader
= 0, hVertexShader
= 0;
1663 DWORD hPixelShader2
= 0, hVertexShader2
= 0;
1666 DWORD fvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
1667 IDirect3DDevice8
*device
;
1675 static DWORD dwVertexDecl
[] =
1678 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
),
1681 DWORD decl_normal_float2
[] =
1684 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
1685 D3DVSD_REG(D3DVSDE_NORMAL
, D3DVSDT_FLOAT2
), /* D3DVSDE_NORMAL, Register v1 */
1688 DWORD decl_normal_float4
[] =
1691 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
1692 D3DVSD_REG(D3DVSDE_NORMAL
, D3DVSDT_FLOAT4
), /* D3DVSDE_NORMAL, Register v1 */
1695 DWORD decl_normal_d3dcolor
[] =
1698 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
1699 D3DVSD_REG(D3DVSDE_NORMAL
, D3DVSDT_D3DCOLOR
),/* D3DVSDE_NORMAL, Register v1 */
1702 const DWORD vertex_decl_size
= sizeof(dwVertexDecl
);
1703 const DWORD simple_vs_size
= sizeof(simple_vs
);
1704 const DWORD simple_ps_size
= sizeof(simple_ps
);
1706 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
1707 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
1708 ok(!!window
, "Failed to create a window.\n");
1709 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
1710 ok(!!d3d
, "Failed to create a D3D object.\n");
1711 if (!(device
= create_device(d3d
, window
, NULL
)))
1713 skip("Failed to create a 3D device, skipping test.\n");
1717 IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
1719 /* Test setting and retrieving a FVF */
1720 hr
= IDirect3DDevice8_SetVertexShader(device
, fvf
);
1721 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
1722 hr
= IDirect3DDevice8_GetVertexShader(device
, &hTempHandle
);
1723 ok(SUCCEEDED(hr
), "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
1724 ok(hTempHandle
== fvf
, "Vertex shader %#08x is set, expected %#08x\n", hTempHandle
, fvf
);
1726 /* First create a vertex shader */
1727 hr
= IDirect3DDevice8_SetVertexShader(device
, 0);
1728 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
1729 hr
= IDirect3DDevice8_CreateVertexShader(device
, dwVertexDecl
, simple_vs
, &hVertexShader
, 0);
1730 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1731 /* Msdn says that the new vertex shader is set immediately. This is wrong, apparently */
1732 hr
= IDirect3DDevice8_GetVertexShader(device
, &hTempHandle
);
1733 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
1734 ok(hTempHandle
== 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, 0);
1735 /* Assign the shader, then verify that GetVertexShader works */
1736 hr
= IDirect3DDevice8_SetVertexShader(device
, hVertexShader
);
1737 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
1738 hr
= IDirect3DDevice8_GetVertexShader(device
, &hTempHandle
);
1739 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
1740 ok(hTempHandle
== hVertexShader
, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, hVertexShader
);
1741 /* Verify that we can retrieve the declaration */
1742 hr
= IDirect3DDevice8_GetVertexShaderDeclaration(device
, hVertexShader
, NULL
, &data_size
);
1743 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr
);
1744 ok(data_size
== vertex_decl_size
, "Got data_size %u, expected %u\n", data_size
, vertex_decl_size
);
1745 data
= HeapAlloc(GetProcessHeap(), 0, vertex_decl_size
);
1747 hr
= IDirect3DDevice8_GetVertexShaderDeclaration(device
, hVertexShader
, data
, &data_size
);
1748 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_GetVertexShaderDeclaration returned (%#08x), "
1749 "expected D3DERR_INVALIDCALL\n", hr
);
1750 ok(data_size
== 1, "Got data_size %u, expected 1\n", data_size
);
1751 data_size
= vertex_decl_size
;
1752 hr
= IDirect3DDevice8_GetVertexShaderDeclaration(device
, hVertexShader
, data
, &data_size
);
1753 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr
);
1754 ok(data_size
== vertex_decl_size
, "Got data_size %u, expected %u\n", data_size
, vertex_decl_size
);
1755 ok(!memcmp(data
, dwVertexDecl
, vertex_decl_size
), "data not equal to shader declaration\n");
1756 HeapFree(GetProcessHeap(), 0, data
);
1757 /* Verify that we can retrieve the shader function */
1758 hr
= IDirect3DDevice8_GetVertexShaderFunction(device
, hVertexShader
, NULL
, &data_size
);
1759 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr
);
1760 ok(data_size
== simple_vs_size
, "Got data_size %u, expected %u\n", data_size
, simple_vs_size
);
1761 data
= HeapAlloc(GetProcessHeap(), 0, simple_vs_size
);
1763 hr
= IDirect3DDevice8_GetVertexShaderFunction(device
, hVertexShader
, data
, &data_size
);
1764 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_GetVertexShaderFunction returned (%#08x), "
1765 "expected D3DERR_INVALIDCALL\n", hr
);
1766 ok(data_size
== 1, "Got data_size %u, expected 1\n", data_size
);
1767 data_size
= simple_vs_size
;
1768 hr
= IDirect3DDevice8_GetVertexShaderFunction(device
, hVertexShader
, data
, &data_size
);
1769 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr
);
1770 ok(data_size
== simple_vs_size
, "Got data_size %u, expected %u\n", data_size
, simple_vs_size
);
1771 ok(!memcmp(data
, simple_vs
, simple_vs_size
), "data not equal to shader function\n");
1772 HeapFree(GetProcessHeap(), 0, data
);
1773 /* Delete the assigned shader. This is supposed to work */
1774 hr
= IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader
);
1775 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
1776 /* The shader should be unset now */
1777 hr
= IDirect3DDevice8_GetVertexShader(device
, &hTempHandle
);
1778 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
1779 ok(hTempHandle
== 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, 0);
1781 /* Test a broken declaration. 3DMark2001 tries to use normals with 2 components
1782 * First try the fixed function shader function, then a custom one
1784 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl_normal_float2
, 0, &hVertexShader
, 0);
1785 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1786 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl_normal_float4
, 0, &hVertexShader
, 0);
1787 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1788 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl_normal_d3dcolor
, 0, &hVertexShader
, 0);
1789 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1791 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl_normal_float2
, simple_vs
, &hVertexShader
, 0);
1792 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1793 IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader
);
1795 if (caps
.PixelShaderVersion
>= D3DPS_VERSION(1, 0))
1797 /* The same with a pixel shader */
1798 hr
= IDirect3DDevice8_CreatePixelShader(device
, simple_ps
, &hPixelShader
);
1799 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
1800 /* Msdn says that the new pixel shader is set immediately. This is wrong, apparently */
1801 hr
= IDirect3DDevice8_GetPixelShader(device
, &hTempHandle
);
1802 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
1803 ok(hTempHandle
== 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, 0);
1804 /* Assign the shader, then verify that GetPixelShader works */
1805 hr
= IDirect3DDevice8_SetPixelShader(device
, hPixelShader
);
1806 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr
);
1807 hr
= IDirect3DDevice8_GetPixelShader(device
, &hTempHandle
);
1808 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
1809 ok(hTempHandle
== hPixelShader
, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, hPixelShader
);
1810 /* Verify that we can retrieve the shader function */
1811 hr
= IDirect3DDevice8_GetPixelShaderFunction(device
, hPixelShader
, NULL
, &data_size
);
1812 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr
);
1813 ok(data_size
== simple_ps_size
, "Got data_size %u, expected %u\n", data_size
, simple_ps_size
);
1814 data
= HeapAlloc(GetProcessHeap(), 0, simple_ps_size
);
1816 hr
= IDirect3DDevice8_GetPixelShaderFunction(device
, hPixelShader
, data
, &data_size
);
1817 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_GetPixelShaderFunction returned (%#08x), "
1818 "expected D3DERR_INVALIDCALL\n", hr
);
1819 ok(data_size
== 1, "Got data_size %u, expected 1\n", data_size
);
1820 data_size
= simple_ps_size
;
1821 hr
= IDirect3DDevice8_GetPixelShaderFunction(device
, hPixelShader
, data
, &data_size
);
1822 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr
);
1823 ok(data_size
== simple_ps_size
, "Got data_size %u, expected %u\n", data_size
, simple_ps_size
);
1824 ok(!memcmp(data
, simple_ps
, simple_ps_size
), "data not equal to shader function\n");
1825 HeapFree(GetProcessHeap(), 0, data
);
1826 /* Delete the assigned shader. This is supposed to work */
1827 hr
= IDirect3DDevice8_DeletePixelShader(device
, hPixelShader
);
1828 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
1829 /* The shader should be unset now */
1830 hr
= IDirect3DDevice8_GetPixelShader(device
, &hTempHandle
);
1831 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
1832 ok(hTempHandle
== 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, 0);
1834 /* What happens if a non-bound shader is deleted? */
1835 hr
= IDirect3DDevice8_CreatePixelShader(device
, simple_ps
, &hPixelShader
);
1836 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
1837 hr
= IDirect3DDevice8_CreatePixelShader(device
, simple_ps
, &hPixelShader2
);
1838 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
1840 hr
= IDirect3DDevice8_SetPixelShader(device
, hPixelShader
);
1841 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr
);
1842 hr
= IDirect3DDevice8_DeletePixelShader(device
, hPixelShader2
);
1843 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
1844 hr
= IDirect3DDevice8_GetPixelShader(device
, &hTempHandle
);
1845 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
1846 ok(hTempHandle
== hPixelShader
, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, hPixelShader
);
1847 hr
= IDirect3DDevice8_DeletePixelShader(device
, hPixelShader
);
1848 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
1850 /* Check for double delete. */
1851 hr
= IDirect3DDevice8_DeletePixelShader(device
, hPixelShader2
);
1852 ok(hr
== D3DERR_INVALIDCALL
|| broken(hr
== D3D_OK
), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
1853 hr
= IDirect3DDevice8_DeletePixelShader(device
, hPixelShader
);
1854 ok(hr
== D3DERR_INVALIDCALL
|| broken(hr
== D3D_OK
), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
1858 skip("Pixel shaders not supported\n");
1861 /* What happens if a non-bound shader is deleted? */
1862 hr
= IDirect3DDevice8_CreateVertexShader(device
, dwVertexDecl
, NULL
, &hVertexShader
, 0);
1863 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1864 hr
= IDirect3DDevice8_CreateVertexShader(device
, dwVertexDecl
, NULL
, &hVertexShader2
, 0);
1865 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1867 hr
= IDirect3DDevice8_SetVertexShader(device
, hVertexShader
);
1868 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
1869 hr
= IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader2
);
1870 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
1871 hr
= IDirect3DDevice8_GetVertexShader(device
, &hTempHandle
);
1872 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
1873 ok(hTempHandle
== hVertexShader
, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, hVertexShader
);
1874 hr
= IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader
);
1875 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
1877 /* Check for double delete. */
1878 hr
= IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader2
);
1879 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
1880 hr
= IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader
);
1881 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
1883 refcount
= IDirect3DDevice8_Release(device
);
1884 ok(!refcount
, "Device has %u references left.\n", refcount
);
1886 IDirect3D8_Release(d3d
);
1887 DestroyWindow(window
);
1890 static void test_limits(void)
1892 IDirect3DTexture8
*texture
;
1893 IDirect3DDevice8
*device
;
1900 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
1901 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
1902 ok(!!window
, "Failed to create a window.\n");
1903 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
1904 ok(!!d3d
, "Failed to create a D3D object.\n");
1905 if (!(device
= create_device(d3d
, window
, NULL
)))
1907 skip("Failed to create a 3D device, skipping test.\n");
1911 hr
= IDirect3DDevice8_CreateTexture(device
, 16, 16, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &texture
);
1912 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateTexture failed with %#08x\n", hr
);
1914 /* There are 8 texture stages. We should be able to access all of them */
1915 for (i
= 0; i
< 8; ++i
)
1917 hr
= IDirect3DDevice8_SetTexture(device
, i
, (IDirect3DBaseTexture8
*)texture
);
1918 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i
, hr
);
1919 hr
= IDirect3DDevice8_SetTexture(device
, i
, NULL
);
1920 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i
, hr
);
1921 hr
= IDirect3DDevice8_SetTextureStageState(device
, i
, D3DTSS_COLOROP
, D3DTOP_ADD
);
1922 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %#08x\n", i
, hr
);
1925 /* Investigations show that accessing higher textures stage states does
1926 * not return an error either. Writing to too high texture stages
1927 * (approximately texture 40) causes memory corruption in windows, so
1928 * there is no bounds checking. */
1929 IDirect3DTexture8_Release(texture
);
1930 refcount
= IDirect3DDevice8_Release(device
);
1931 ok(!refcount
, "Device has %u references left.\n", refcount
);
1933 IDirect3D8_Release(d3d
);
1934 DestroyWindow(window
);
1937 static void test_lights(void)
1939 IDirect3DDevice8
*device
;
1948 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
1949 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
1950 ok(!!window
, "Failed to create a window.\n");
1951 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
1952 ok(!!d3d8
, "Failed to create a D3D object.\n");
1953 if (!(device
= create_device(d3d8
, window
, NULL
)))
1955 skip("Failed to create a 3D device, skipping test.\n");
1959 memset(&caps
, 0, sizeof(caps
));
1960 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
1961 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetDeviceCaps failed with %08x\n", hr
);
1963 for(i
= 1; i
<= caps
.MaxActiveLights
; i
++) {
1964 hr
= IDirect3DDevice8_LightEnable(device
, i
, TRUE
);
1965 ok(hr
== D3D_OK
, "Enabling light %u failed with %08x\n", i
, hr
);
1966 hr
= IDirect3DDevice8_GetLightEnable(device
, i
, &enabled
);
1967 ok(hr
== D3D_OK
|| broken(hr
== D3DERR_INVALIDCALL
),
1968 "GetLightEnable on light %u failed with %08x\n", i
, hr
);
1969 ok(enabled
, "Light %d is %s\n", i
, enabled
? "enabled" : "disabled");
1972 /* TODO: Test the rendering results in this situation */
1973 hr
= IDirect3DDevice8_LightEnable(device
, i
+ 1, TRUE
);
1974 ok(hr
== D3D_OK
, "Enabling one light more than supported returned %08x\n", hr
);
1975 hr
= IDirect3DDevice8_GetLightEnable(device
, i
+ 1, &enabled
);
1976 ok(hr
== D3D_OK
, "GetLightEnable on light %u failed with %08x\n", i
+ 1, hr
);
1977 ok(enabled
, "Light %d is %s\n", i
+ 1, enabled
? "enabled" : "disabled");
1978 hr
= IDirect3DDevice8_LightEnable(device
, i
+ 1, FALSE
);
1979 ok(hr
== D3D_OK
, "Disabling the additional returned %08x\n", hr
);
1981 for(i
= 1; i
<= caps
.MaxActiveLights
; i
++) {
1982 hr
= IDirect3DDevice8_LightEnable(device
, i
, FALSE
);
1983 ok(hr
== D3D_OK
, "Disabling light %u failed with %08x\n", i
, hr
);
1986 refcount
= IDirect3DDevice8_Release(device
);
1987 ok(!refcount
, "Device has %u references left.\n", refcount
);
1989 IDirect3D8_Release(d3d8
);
1990 DestroyWindow(window
);
1993 static void test_render_zero_triangles(void)
1995 IDirect3DDevice8
*device
;
2003 struct vec3 position
;
2009 {{0.0f
, -1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
2010 {{0.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
2011 {{1.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
2012 {{1.0f
, -1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
2015 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
2016 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
2017 ok(!!window
, "Failed to create a window.\n");
2018 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
2019 ok(!!d3d8
, "Failed to create a D3D object.\n");
2020 if (!(device
= create_device(d3d8
, window
, NULL
)))
2022 skip("Failed to create a 3D device, skipping test.\n");
2026 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
2027 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
2029 hr
= IDirect3DDevice8_BeginScene(device
);
2030 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
2031 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 0 /* NumVerts */,
2032 0 /* PrimCount */, NULL
, D3DFMT_INDEX16
, quad
, sizeof(quad
[0]));
2033 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
2034 hr
= IDirect3DDevice8_EndScene(device
);
2035 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
2037 IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
2039 refcount
= IDirect3DDevice8_Release(device
);
2040 ok(!refcount
, "Device has %u references left.\n", refcount
);
2042 IDirect3D8_Release(d3d8
);
2043 DestroyWindow(window
);
2046 static void test_depth_stencil_reset(void)
2048 D3DPRESENT_PARAMETERS present_parameters
;
2049 D3DDISPLAYMODE display_mode
;
2050 IDirect3DSurface8
*surface
, *orig_rt
;
2051 IDirect3DDevice8
*device
= NULL
;
2057 hwnd
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
2058 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
2059 ok(!!hwnd
, "Failed to create a window.\n");
2060 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
2061 ok(!!d3d8
, "Failed to create a D3D object.\n");
2063 IDirect3D8_GetAdapterDisplayMode(d3d8
, D3DADAPTER_DEFAULT
, &display_mode
);
2064 memset(&present_parameters
, 0, sizeof(present_parameters
));
2065 present_parameters
.Windowed
= TRUE
;
2066 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2067 present_parameters
.BackBufferFormat
= display_mode
.Format
;
2068 present_parameters
.EnableAutoDepthStencil
= TRUE
;
2069 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
2071 hr
= IDirect3D8_CreateDevice(d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
2072 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
2075 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr
);
2079 hr
= IDirect3DDevice8_GetRenderTarget(device
, &orig_rt
);
2080 ok(hr
== D3D_OK
, "GetRenderTarget failed with 0x%08x\n", hr
);
2082 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
2083 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed with %#x\n", hr
);
2085 hr
= IDirect3DDevice8_SetRenderTarget(device
, NULL
, NULL
);
2086 ok(hr
== D3D_OK
, "SetRenderTarget failed with 0x%08x\n", hr
);
2088 hr
= IDirect3DDevice8_GetRenderTarget(device
, &surface
);
2089 ok(hr
== D3D_OK
, "GetRenderTarget failed with 0x%08x\n", hr
);
2090 ok(surface
== orig_rt
, "Render target is %p, should be %p\n", surface
, orig_rt
);
2091 if (surface
) IDirect3DSurface8_Release(surface
);
2092 IDirect3DSurface8_Release(orig_rt
);
2094 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surface
);
2095 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr
);
2096 ok(surface
== NULL
, "Depth stencil should be NULL\n");
2098 present_parameters
.EnableAutoDepthStencil
= TRUE
;
2099 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
2100 hr
= IDirect3DDevice8_Reset(device
, &present_parameters
);
2101 ok(hr
== D3D_OK
, "Reset failed with 0x%08x\n", hr
);
2103 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surface
);
2104 ok(hr
== D3D_OK
, "GetDepthStencilSurface failed with 0x%08x\n", hr
);
2105 ok(surface
!= NULL
, "Depth stencil should not be NULL\n");
2106 if (surface
) IDirect3DSurface8_Release(surface
);
2108 present_parameters
.EnableAutoDepthStencil
= FALSE
;
2109 hr
= IDirect3DDevice8_Reset(device
, &present_parameters
);
2110 ok(hr
== D3D_OK
, "Reset failed with 0x%08x\n", hr
);
2112 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surface
);
2113 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr
);
2114 ok(surface
== NULL
, "Depth stencil should be NULL\n");
2116 refcount
= IDirect3DDevice8_Release(device
);
2117 ok(!refcount
, "Device has %u references left.\n", refcount
);
2120 IDirect3D8_GetAdapterDisplayMode( d3d8
, D3DADAPTER_DEFAULT
, &display_mode
);
2122 ZeroMemory( &present_parameters
, sizeof(present_parameters
) );
2123 present_parameters
.Windowed
= TRUE
;
2124 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2125 present_parameters
.BackBufferFormat
= display_mode
.Format
;
2126 present_parameters
.EnableAutoDepthStencil
= FALSE
;
2127 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
2129 hr
= IDirect3D8_CreateDevice( d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
2130 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
2134 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr
);
2138 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
2139 ok(hr
== D3D_OK
, "IDirect3DDevice8_TestCooperativeLevel after creation returned %#x\n", hr
);
2141 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2142 present_parameters
.Windowed
= TRUE
;
2143 present_parameters
.BackBufferWidth
= 400;
2144 present_parameters
.BackBufferHeight
= 300;
2145 present_parameters
.EnableAutoDepthStencil
= TRUE
;
2146 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
2148 hr
= IDirect3DDevice8_Reset(device
, &present_parameters
);
2149 ok(hr
== D3D_OK
, "IDirect3DDevice8_Reset failed with 0x%08x\n", hr
);
2151 if (FAILED(hr
)) goto cleanup
;
2153 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surface
);
2154 ok(hr
== D3D_OK
, "GetDepthStencilSurface failed with 0x%08x\n", hr
);
2155 ok(surface
!= NULL
, "Depth stencil should not be NULL\n");
2156 if (surface
) IDirect3DSurface8_Release(surface
);
2161 refcount
= IDirect3DDevice8_Release(device
);
2162 ok(!refcount
, "Device has %u references left.\n", refcount
);
2164 IDirect3D8_Release(d3d8
);
2165 DestroyWindow(hwnd
);
2168 static HWND filter_messages
;
2179 enum message_window window
;
2181 WPARAM expect_wparam
;
2184 static const struct message
*expect_messages
, *unexpected_messages
;
2185 static HWND device_window
, focus_window
;
2187 struct wndproc_thread_param
2190 HANDLE window_created
;
2191 HANDLE test_finished
;
2192 BOOL running_in_foreground
;
2195 static LRESULT CALLBACK
test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2197 if (filter_messages
&& filter_messages
== hwnd
)
2199 if (message
!= WM_DISPLAYCHANGE
&& message
!= WM_IME_NOTIFY
)
2200 todo_wine
ok(0, "Received unexpected message %#x for window %p.\n", message
, hwnd
);
2203 if (expect_messages
)
2207 switch (expect_messages
->window
)
2222 if (hwnd
== w
&& expect_messages
->message
== message
)
2224 if (expect_messages
->check_wparam
)
2225 ok(wparam
== expect_messages
->expect_wparam
,
2226 "Got unexpected wparam %lx for message %x, expected %lx.\n",
2227 wparam
, message
, expect_messages
->expect_wparam
);
2233 if (unexpected_messages
)
2235 const struct message
*i
;
2236 for (i
= unexpected_messages
; i
->message
; i
++)
2237 ok(i
->message
!= message
, "Got unexpected message %x on window %p.\n", message
, hwnd
);
2240 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
2243 static DWORD WINAPI
wndproc_thread(void *param
)
2245 struct wndproc_thread_param
*p
= param
;
2249 p
->dummy_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2250 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, registry_mode
.dmPelsWidth
,
2251 registry_mode
.dmPelsHeight
, 0, 0, 0, 0);
2252 p
->running_in_foreground
= SetForegroundWindow(p
->dummy_window
);
2254 ret
= SetEvent(p
->window_created
);
2255 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
2261 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2262 res
= WaitForSingleObject(p
->test_finished
, 100);
2263 if (res
== WAIT_OBJECT_0
) break;
2264 if (res
!= WAIT_TIMEOUT
)
2266 ok(0, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
2271 DestroyWindow(p
->dummy_window
);
2276 static void test_wndproc(void)
2278 struct wndproc_thread_param thread_params
;
2279 struct device_desc device_desc
;
2280 IDirect3DDevice8
*device
;
2288 UINT i
, adapter_mode_count
;
2290 D3DDISPLAYMODE d3ddm
;
2291 DWORD d3d_width
= 0, d3d_height
= 0, user32_width
= 0, user32_height
= 0;
2296 static const struct message create_messages
[] =
2298 {WM_WINDOWPOSCHANGING
, FOCUS_WINDOW
, FALSE
, 0},
2299 /* Do not test wparam here. If device creation succeeds,
2300 * wparam is WA_ACTIVE. If device creation fails (testbot)
2301 * wparam is set to WA_INACTIVE on some Windows versions. */
2302 {WM_ACTIVATE
, FOCUS_WINDOW
, FALSE
, 0},
2303 {WM_SETFOCUS
, FOCUS_WINDOW
, FALSE
, 0},
2304 {WM_WINDOWPOSCHANGING
, DEVICE_WINDOW
, FALSE
, 0},
2305 {WM_MOVE
, DEVICE_WINDOW
, FALSE
, 0},
2306 {WM_SIZE
, DEVICE_WINDOW
, FALSE
, 0},
2309 static const struct message focus_loss_messages
[] =
2311 /* WM_ACTIVATE (wparam = WA_INACTIVE) is sent on Windows. It is
2312 * not reliable on X11 WMs. When the window focus follows the
2313 * mouse pointer the message is not sent.
2314 * {WM_ACTIVATE, FOCUS_WINDOW, TRUE, WA_INACTIVE}, */
2315 {WM_DISPLAYCHANGE
, DEVICE_WINDOW
, FALSE
, 0},
2316 /* WM_DISPLAYCHANGE is sent to the focus window too, but the order is
2317 * not deterministic. */
2318 {WM_WINDOWPOSCHANGING
, DEVICE_WINDOW
, FALSE
, 0},
2319 /* Windows sends WM_ACTIVATE to the device window, indicating that
2320 * SW_SHOWMINIMIZED is used instead of SW_MINIMIZE. Yet afterwards
2321 * the foreground and focus window are NULL. On Wine SW_SHOWMINIMIZED
2322 * leaves the device window active, breaking re-activation in the
2324 * {WM_ACTIVATE, DEVICE_WINDOW, TRUE, 0x200000 | WA_ACTIVE}, */
2325 {WM_WINDOWPOSCHANGED
, DEVICE_WINDOW
, FALSE
, 0},
2326 {WM_SIZE
, DEVICE_WINDOW
, TRUE
, SIZE_MINIMIZED
},
2327 {WM_ACTIVATEAPP
, FOCUS_WINDOW
, TRUE
, FALSE
},
2328 /* WM_ACTIVATEAPP is sent to the device window too, but the order is
2329 * not deterministic. It may be sent after the focus window handling
2333 static const struct message reactivate_messages
[] =
2335 {WM_WINDOWPOSCHANGING
, DEVICE_WINDOW
, FALSE
, 0},
2336 {WM_WINDOWPOSCHANGED
, DEVICE_WINDOW
, FALSE
, 0},
2337 {WM_MOVE
, DEVICE_WINDOW
, FALSE
, 0},
2338 {WM_ACTIVATEAPP
, FOCUS_WINDOW
, TRUE
, TRUE
},
2341 static const struct message focus_loss_messages_hidden
[] =
2343 {WM_DISPLAYCHANGE
, DEVICE_WINDOW
, FALSE
, 0},
2344 {WM_ACTIVATEAPP
, FOCUS_WINDOW
, TRUE
, FALSE
},
2347 static const struct message focus_loss_messages_hidden_unexpected
[] =
2349 /* KDE randomly does something with the hidden window during the
2350 * mode change that sometimes generates a WM_WINDOWPOSCHANGING
2351 * message. A WM_WINDOWPOSCHANGED message is not generated, so
2352 * just flag WM_WINDOWPOSCHANGED as bad. */
2353 {WM_WINDOWPOSCHANGED
, 0, FALSE
, 0},
2357 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
2358 ok(!!d3d8
, "Failed to create a D3D object.\n");
2360 adapter_mode_count
= IDirect3D8_GetAdapterModeCount(d3d8
, D3DADAPTER_DEFAULT
);
2361 for (i
= 0; i
< adapter_mode_count
; ++i
)
2363 hr
= IDirect3D8_EnumAdapterModes(d3d8
, D3DADAPTER_DEFAULT
, i
, &d3ddm
);
2364 ok(SUCCEEDED(hr
), "Failed to enumerate display mode, hr %#x.\n", hr
);
2366 if (d3ddm
.Format
!= D3DFMT_X8R8G8B8
)
2368 if (d3ddm
.Width
== registry_mode
.dmPelsWidth
&& d3ddm
.Height
== registry_mode
.dmPelsHeight
)
2370 /* The r200 driver on Windows XP enumerates modes like 320x200 and 320x240 but
2371 * refuses to create a device at these sizes. */
2372 if (d3ddm
.Width
< 640 || d3ddm
.Height
< 480)
2377 user32_width
= d3ddm
.Width
;
2378 user32_height
= d3ddm
.Height
;
2382 /* Make sure the d3d mode is smaller in width or height and at most
2383 * equal in the other dimension than the mode passed to
2384 * ChangeDisplaySettings. Otherwise Windows shrinks the window to
2385 * the ChangeDisplaySettings parameters + 12. */
2386 if (d3ddm
.Width
== user32_width
&& d3ddm
.Height
== user32_height
)
2388 if (d3ddm
.Width
<= user32_width
&& d3ddm
.Height
<= user32_height
)
2390 d3d_width
= d3ddm
.Width
;
2391 d3d_height
= d3ddm
.Height
;
2394 if (user32_width
<= d3ddm
.Width
&& user32_height
<= d3ddm
.Height
)
2396 d3d_width
= user32_width
;
2397 d3d_height
= user32_height
;
2398 user32_width
= d3ddm
.Width
;
2399 user32_height
= d3ddm
.Height
;
2406 skip("Could not find adequate modes, skipping mode tests.\n");
2407 IDirect3D8_Release(d3d8
);
2411 wc
.lpfnWndProc
= test_proc
;
2412 wc
.lpszClassName
= "d3d8_test_wndproc_wc";
2413 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2415 thread_params
.window_created
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2416 ok(!!thread_params
.window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
2417 thread_params
.test_finished
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2418 ok(!!thread_params
.test_finished
, "CreateEvent failed, last error %#x.\n", GetLastError());
2420 memset(&devmode
, 0, sizeof(devmode
));
2421 devmode
.dmSize
= sizeof(devmode
);
2422 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2423 devmode
.dmPelsWidth
= user32_width
;
2424 devmode
.dmPelsHeight
= user32_height
;
2425 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2426 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2428 focus_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2429 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, user32_width
, user32_height
, 0, 0, 0, 0);
2430 device_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2431 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, user32_width
, user32_height
, 0, 0, 0, 0);
2432 thread
= CreateThread(NULL
, 0, wndproc_thread
, &thread_params
, 0, &tid
);
2433 ok(!!thread
, "Failed to create thread, last error %#x.\n", GetLastError());
2435 res
= WaitForSingleObject(thread_params
.window_created
, INFINITE
);
2436 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
2438 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2439 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2440 (LONG_PTR
)test_proc
, proc
);
2441 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2442 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2443 (LONG_PTR
)test_proc
, proc
);
2445 trace("device_window %p, focus_window %p, dummy_window %p.\n",
2446 device_window
, focus_window
, thread_params
.dummy_window
);
2449 ok(tmp
== device_window
, "Expected focus %p, got %p.\n", device_window
, tmp
);
2450 if (thread_params
.running_in_foreground
)
2452 tmp
= GetForegroundWindow();
2453 ok(tmp
== thread_params
.dummy_window
, "Expected foreground window %p, got %p.\n",
2454 thread_params
.dummy_window
, tmp
);
2457 skip("Not running in foreground, skip foreground window test\n");
2461 expect_messages
= create_messages
;
2463 device_desc
.device_window
= device_window
;
2464 device_desc
.width
= d3d_width
;
2465 device_desc
.height
= d3d_height
;
2466 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
2467 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
2469 skip("Failed to create a D3D device, skipping tests.\n");
2473 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2474 expect_messages
->message
, expect_messages
->window
);
2475 expect_messages
= NULL
;
2477 if (0) /* Disabled until we can make this work in a reliable way on Wine. */
2480 ok(tmp
== focus_window
, "Expected focus %p, got %p.\n", focus_window
, tmp
);
2481 tmp
= GetForegroundWindow();
2482 ok(tmp
== focus_window
, "Expected foreground window %p, got %p.\n", focus_window
, tmp
);
2484 SetForegroundWindow(focus_window
);
2487 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2488 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2489 (LONG_PTR
)test_proc
, proc
);
2491 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2492 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
2494 /* Change the mode while the device is in use and then drop focus. */
2495 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2496 devmode
.dmPelsWidth
= user32_width
;
2497 devmode
.dmPelsHeight
= user32_height
;
2498 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2499 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x, i=%u.\n", change_ret
, i
);
2501 /* Wine doesn't (yet) mark the device not reset when the mode is changed, thus the todo_wine.
2502 * But sometimes focus-follows-mouse WMs also temporarily drop window focus, which makes
2503 * mark the device lost, then not reset, causing the test to succeed for the wrong reason. */
2504 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
2505 if (hr
== D3DERR_DEVICENOTRESET
)
2506 ok(hr
== D3DERR_DEVICENOTRESET
, "Got unexpected hr %#x.\n", hr
);
2508 todo_wine
ok(hr
== D3DERR_DEVICENOTRESET
, "Got unexpected hr %#x.\n", hr
);
2510 expect_messages
= focus_loss_messages
;
2511 /* SetForegroundWindow is a poor replacement for the user pressing alt-tab or
2512 * manually changing the focus. It generates the same messages, but the task
2513 * bar still shows the previous foreground window as active, and the window has
2514 * an inactive titlebar if reactivated with SetForegroundWindow. Reactivating
2515 * the device is difficult, see below. */
2516 SetForegroundWindow(GetDesktopWindow());
2517 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2518 expect_messages
->message
, expect_messages
->window
);
2519 expect_messages
= NULL
;
2521 ok(tmp
!= device_window
, "The device window is active.\n");
2522 ok(tmp
!= focus_window
, "The focus window is active.\n");
2524 /* The Present call is necessary to make native realize the device is lost. */
2525 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
2526 ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
2527 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
2528 /* Focus-follows-mouse WMs prematurely reactivate our window. */
2529 if (hr
== D3DERR_DEVICENOTRESET
)
2530 todo_wine
ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
2532 ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
2534 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2535 ok(ret
, "Failed to get display mode.\n");
2536 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2537 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpect screen size %ux%u.\n",
2538 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2540 /* I have to minimize and restore the focus window, otherwise native d3d9 fails
2541 * device::reset with D3DERR_DEVICELOST. This does not happen when the window
2542 * restore is triggered by the user. */
2543 expect_messages
= reactivate_messages
;
2544 ShowWindow(focus_window
, SW_MINIMIZE
);
2545 ShowWindow(focus_window
, SW_RESTORE
);
2546 /* Set focus twice to make KDE and fvwm in focus-follows-mouse mode happy. */
2547 SetForegroundWindow(focus_window
);
2549 SetForegroundWindow(focus_window
);
2550 flush_events(); /* WM_WINDOWPOSCHANGING etc arrive after SetForegroundWindow returns. */
2551 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it, i=%u.\n",
2552 expect_messages
->message
, expect_messages
->window
, i
);
2553 expect_messages
= NULL
;
2555 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
2556 ok(hr
== D3DERR_DEVICENOTRESET
, "Got unexpected hr %#x.\n", hr
);
2558 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2559 ok(ret
, "Failed to get display mode.\n");
2560 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2561 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpect screen size %ux%u.\n",
2562 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2564 hr
= reset_device(device
, &device_desc
);
2565 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
2567 ShowWindow(device_window
, SW_HIDE
);
2570 expect_messages
= focus_loss_messages_hidden
;
2571 unexpected_messages
= focus_loss_messages_hidden_unexpected
;
2572 SetForegroundWindow(GetDesktopWindow());
2573 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2574 expect_messages
->message
, expect_messages
->window
);
2575 expect_messages
= NULL
;
2576 unexpected_messages
= NULL
;
2578 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2579 ok(ret
, "Failed to get display mode.\n");
2580 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
, "Got unexpect width %u.\n", devmode
.dmPelsWidth
);
2581 ok(devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpect height %u.\n", devmode
.dmPelsHeight
);
2583 ShowWindow(focus_window
, SW_MINIMIZE
);
2584 ShowWindow(focus_window
, SW_RESTORE
);
2585 SetForegroundWindow(focus_window
);
2588 /* Releasing a device in lost state breaks follow-up tests on native. */
2589 hr
= reset_device(device
, &device_desc
);
2590 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
2592 filter_messages
= focus_window
;
2593 ref
= IDirect3DDevice8_Release(device
);
2594 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2596 /* Fix up the mode until Wine's device release behavior is fixed. */
2597 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2598 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2600 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2601 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2602 (LONG_PTR
)test_proc
, proc
);
2604 device_desc
.device_window
= focus_window
;
2605 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
2607 skip("Failed to create a D3D device, skipping tests.\n");
2611 ref
= IDirect3DDevice8_Release(device
);
2612 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2614 device_desc
.device_window
= device_window
;
2615 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
2617 skip("Failed to create a D3D device, skipping tests.\n");
2621 proc
= SetWindowLongPtrA(focus_window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2622 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
2624 ref
= IDirect3DDevice8_Release(device
);
2625 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2627 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2628 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2629 (LONG_PTR
)DefWindowProcA
, proc
);
2632 filter_messages
= NULL
;
2633 IDirect3D8_Release(d3d8
);
2635 SetEvent(thread_params
.test_finished
);
2636 WaitForSingleObject(thread
, INFINITE
);
2637 CloseHandle(thread_params
.test_finished
);
2638 CloseHandle(thread_params
.window_created
);
2639 CloseHandle(thread
);
2641 DestroyWindow(device_window
);
2642 DestroyWindow(focus_window
);
2643 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL
));
2646 static void test_wndproc_windowed(void)
2648 struct wndproc_thread_param thread_params
;
2649 struct device_desc device_desc
;
2650 IDirect3DDevice8
*device
;
2660 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
2661 ok(!!d3d8
, "Failed to create a D3D object.\n");
2663 wc
.lpfnWndProc
= test_proc
;
2664 wc
.lpszClassName
= "d3d8_test_wndproc_wc";
2665 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2667 thread_params
.window_created
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2668 ok(!!thread_params
.window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
2669 thread_params
.test_finished
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2670 ok(!!thread_params
.test_finished
, "CreateEvent failed, last error %#x.\n", GetLastError());
2672 focus_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2673 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, registry_mode
.dmPelsWidth
,
2674 registry_mode
.dmPelsHeight
, 0, 0, 0, 0);
2675 device_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2676 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, registry_mode
.dmPelsWidth
,
2677 registry_mode
.dmPelsHeight
, 0, 0, 0, 0);
2678 thread
= CreateThread(NULL
, 0, wndproc_thread
, &thread_params
, 0, &tid
);
2679 ok(!!thread
, "Failed to create thread, last error %#x.\n", GetLastError());
2681 res
= WaitForSingleObject(thread_params
.window_created
, INFINITE
);
2682 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
2684 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2685 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2686 (LONG_PTR
)test_proc
, proc
);
2687 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2688 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2689 (LONG_PTR
)test_proc
, proc
);
2691 trace("device_window %p, focus_window %p, dummy_window %p.\n",
2692 device_window
, focus_window
, thread_params
.dummy_window
);
2695 ok(tmp
== device_window
, "Expected focus %p, got %p.\n", device_window
, tmp
);
2696 if (thread_params
.running_in_foreground
)
2698 tmp
= GetForegroundWindow();
2699 ok(tmp
== thread_params
.dummy_window
, "Expected foreground window %p, got %p.\n",
2700 thread_params
.dummy_window
, tmp
);
2703 skip("Not running in foreground, skip foreground window test\n");
2705 filter_messages
= focus_window
;
2707 device_desc
.device_window
= device_window
;
2708 device_desc
.width
= registry_mode
.dmPelsWidth
;
2709 device_desc
.height
= registry_mode
.dmPelsHeight
;
2710 device_desc
.flags
= 0;
2711 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
2713 skip("Failed to create a D3D device, skipping tests.\n");
2718 ok(tmp
== device_window
, "Expected focus %p, got %p.\n", device_window
, tmp
);
2719 tmp
= GetForegroundWindow();
2720 ok(tmp
== thread_params
.dummy_window
, "Expected foreground window %p, got %p.\n",
2721 thread_params
.dummy_window
, tmp
);
2723 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2724 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2725 (LONG_PTR
)test_proc
, proc
);
2727 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2728 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2729 (LONG_PTR
)test_proc
, proc
);
2731 filter_messages
= NULL
;
2733 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
2734 hr
= reset_device(device
, &device_desc
);
2735 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
2737 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2738 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2739 (LONG_PTR
)test_proc
, proc
);
2741 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2742 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
2744 device_desc
.flags
= 0;
2745 hr
= reset_device(device
, &device_desc
);
2746 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
2748 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2749 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2750 (LONG_PTR
)test_proc
, proc
);
2752 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2753 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2754 (LONG_PTR
)test_proc
, proc
);
2756 filter_messages
= focus_window
;
2758 ref
= IDirect3DDevice8_Release(device
);
2759 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2761 filter_messages
= device_window
;
2763 device_desc
.device_window
= focus_window
;
2764 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
2766 skip("Failed to create a D3D device, skipping tests.\n");
2770 filter_messages
= NULL
;
2772 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
2773 hr
= reset_device(device
, &device_desc
);
2774 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
2776 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2777 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2778 (LONG_PTR
)test_proc
, proc
);
2780 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2781 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
2783 device_desc
.flags
= 0;
2784 hr
= reset_device(device
, &device_desc
);
2785 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
2787 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2788 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2789 (LONG_PTR
)test_proc
, proc
);
2791 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2792 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2793 (LONG_PTR
)test_proc
, proc
);
2795 filter_messages
= device_window
;
2797 ref
= IDirect3DDevice8_Release(device
);
2798 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2800 device_desc
.device_window
= device_window
;
2801 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
2803 skip("Failed to create a D3D device, skipping tests.\n");
2807 filter_messages
= NULL
;
2809 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
2810 hr
= reset_device(device
, &device_desc
);
2811 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
2813 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2814 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2815 (LONG_PTR
)test_proc
, proc
);
2817 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2818 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
2820 device_desc
.flags
= 0;
2821 hr
= reset_device(device
, &device_desc
);
2822 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
2824 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2825 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2826 (LONG_PTR
)test_proc
, proc
);
2828 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2829 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2830 (LONG_PTR
)test_proc
, proc
);
2832 filter_messages
= device_window
;
2834 ref
= IDirect3DDevice8_Release(device
);
2835 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2838 filter_messages
= NULL
;
2839 IDirect3D8_Release(d3d8
);
2841 SetEvent(thread_params
.test_finished
);
2842 WaitForSingleObject(thread
, INFINITE
);
2843 CloseHandle(thread_params
.test_finished
);
2844 CloseHandle(thread_params
.window_created
);
2845 CloseHandle(thread
);
2847 DestroyWindow(device_window
);
2848 DestroyWindow(focus_window
);
2849 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL
));
2852 static inline void set_fpu_cw(WORD cw
)
2854 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2855 #define D3D8_TEST_SET_FPU_CW 1
2856 __asm__
volatile ("fnclex");
2857 __asm__
volatile ("fldcw %0" : : "m" (cw
));
2858 #elif defined(__i386__) && defined(_MSC_VER)
2859 #define D3D8_TEST_SET_FPU_CW 1
2865 static inline WORD
get_fpu_cw(void)
2868 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2869 #define D3D8_TEST_GET_FPU_CW 1
2870 __asm__
volatile ("fnstcw %0" : "=m" (cw
));
2871 #elif defined(__i386__) && defined(_MSC_VER)
2872 #define D3D8_TEST_GET_FPU_CW 1
2878 static void test_fpu_setup(void)
2880 #if defined(D3D8_TEST_SET_FPU_CW) && defined(D3D8_TEST_GET_FPU_CW)
2881 struct device_desc device_desc
;
2882 IDirect3DDevice8
*device
;
2883 D3DDISPLAYMODE d3ddm
;
2889 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_CAPTION
, 0, 0,
2890 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, 0, 0, 0, 0);
2891 ok(!!window
, "Failed to create a window.\n");
2892 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
2893 ok(!!d3d8
, "Failed to create a D3D object.\n");
2895 hr
= IDirect3D8_GetAdapterDisplayMode(d3d8
, D3DADAPTER_DEFAULT
, &d3ddm
);
2896 ok(SUCCEEDED(hr
), "GetAdapterDisplayMode failed, hr %#x.\n", hr
);
2898 device_desc
.device_window
= window
;
2899 device_desc
.width
= 640;
2900 device_desc
.height
= 480;
2901 device_desc
.flags
= 0;
2905 ok(cw
== 0xf60, "cw is %#x, expected 0xf60.\n", cw
);
2907 if (!(device
= create_device(d3d8
, window
, &device_desc
)))
2909 skip("Failed to create a 3D device, skipping test.\n");
2915 ok(cw
== 0x7f, "cw is %#x, expected 0x7f.\n", cw
);
2917 IDirect3DDevice8_Release(device
);
2920 ok(cw
== 0x7f, "cw is %#x, expected 0x7f.\n", cw
);
2923 ok(cw
== 0xf60, "cw is %#x, expected 0xf60.\n", cw
);
2925 device_desc
.flags
= CREATE_DEVICE_FPU_PRESERVE
;
2926 device
= create_device(d3d8
, window
, &device_desc
);
2927 ok(!!device
, "CreateDevice failed.\n");
2930 ok(cw
== 0xf60, "cw is %#x, expected 0xf60.\n", cw
);
2933 IDirect3DDevice8_Release(device
);
2936 DestroyWindow(window
);
2937 IDirect3D8_Release(d3d8
);
2941 static void test_ApplyStateBlock(void)
2943 IDirect3DDevice8
*device
;
2947 DWORD received
, token
;
2949 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
2950 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
2951 ok(!!window
, "Failed to create a window.\n");
2952 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
2953 ok(!!d3d8
, "Failed to create a D3D object.\n");
2954 if (!(device
= create_device(d3d8
, window
, NULL
)))
2956 skip("Failed to create a 3D device, skipping test.\n");
2960 IDirect3DDevice8_BeginStateBlock(device
);
2961 IDirect3DDevice8_SetRenderState(device
, D3DRS_ZENABLE
, TRUE
);
2962 IDirect3DDevice8_EndStateBlock(device
, &token
);
2963 ok(token
, "Received zero stateblock handle.\n");
2964 IDirect3DDevice8_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
2966 hr
= IDirect3DDevice8_GetRenderState(device
, D3DRS_ZENABLE
, &received
);
2967 ok(hr
== D3D_OK
, "Expected D3D_OK, received %#x.\n", hr
);
2968 ok(!received
, "Expected = FALSE, received TRUE.\n");
2970 hr
= IDirect3DDevice8_ApplyStateBlock(device
, 0);
2971 ok(hr
== D3D_OK
, "Expected D3D_OK, received %#x.\n", hr
);
2972 hr
= IDirect3DDevice8_GetRenderState(device
, D3DRS_ZENABLE
, &received
);
2973 ok(hr
== D3D_OK
, "Expected D3D_OK, received %#x.\n", hr
);
2974 ok(!received
, "Expected FALSE, received TRUE.\n");
2976 hr
= IDirect3DDevice8_ApplyStateBlock(device
, token
);
2977 ok(hr
== D3D_OK
, "Expected D3D_OK, received %#x.\n", hr
);
2978 hr
= IDirect3DDevice8_GetRenderState(device
, D3DRS_ZENABLE
, &received
);
2979 ok(hr
== D3D_OK
, "Expected D3D_OK, received %#x.\n", hr
);
2980 ok(received
, "Expected TRUE, received FALSE.\n");
2982 IDirect3DDevice8_DeleteStateBlock(device
, token
);
2983 IDirect3DDevice8_Release(device
);
2985 IDirect3D8_Release(d3d8
);
2986 DestroyWindow(window
);
2989 static void test_depth_stencil_size(void)
2991 IDirect3DDevice8
*device
;
2992 IDirect3DSurface8
*ds
, *rt
, *ds_bigger
, *ds_bigger2
;
2993 IDirect3DSurface8
*surf
;
2998 hwnd
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
2999 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
3000 ok(!!hwnd
, "Failed to create a window.\n");
3001 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3002 ok(!!d3d8
, "Failed to create a D3D object.\n");
3004 if (!(device
= create_device(d3d8
, hwnd
, NULL
)))
3006 skip("Failed to create a 3D device, skipping test.\n");
3010 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 64, 64, D3DFMT_A8R8G8B8
, D3DMULTISAMPLE_NONE
, FALSE
, &rt
);
3011 ok(SUCCEEDED(hr
), "IDirect3DDevice8_CreateRenderTarget failed, hr %#x.\n", hr
);
3012 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 32, 32, D3DFMT_D24X8
, D3DMULTISAMPLE_NONE
, &ds
);
3013 ok(SUCCEEDED(hr
), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr
);
3014 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 128, 128, D3DFMT_D24X8
, D3DMULTISAMPLE_NONE
, &ds_bigger
);
3015 ok(SUCCEEDED(hr
), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr
);
3016 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 128, 128, D3DFMT_D24X8
, D3DMULTISAMPLE_NONE
, &ds_bigger2
);
3017 ok(SUCCEEDED(hr
), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr
);
3019 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, ds
);
3020 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_SetRenderTarget returned %#x, expected D3DERR_INVALIDCALL.\n", hr
);
3021 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, ds_bigger
);
3022 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr
);
3024 /* try to set the small ds without changing the render target at the same time */
3025 hr
= IDirect3DDevice8_SetRenderTarget(device
, NULL
, ds
);
3026 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_SetRenderTarget returned %#x, expected D3DERR_INVALIDCALL.\n", hr
);
3027 hr
= IDirect3DDevice8_SetRenderTarget(device
, NULL
, ds_bigger2
);
3028 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr
);
3030 hr
= IDirect3DDevice8_GetRenderTarget(device
, &surf
);
3031 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetRenderTarget failed, hr %#x.\n", hr
);
3032 ok(surf
== rt
, "The render target is %p, expected %p\n", surf
, rt
);
3033 IDirect3DSurface8_Release(surf
);
3034 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surf
);
3035 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetDepthStencilSurface failed, hr %#x.\n", hr
);
3036 ok(surf
== ds_bigger2
, "The depth stencil is %p, expected %p\n", surf
, ds_bigger2
);
3037 IDirect3DSurface8_Release(surf
);
3039 hr
= IDirect3DDevice8_SetRenderTarget(device
, NULL
, NULL
);
3040 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr
);
3041 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surf
);
3042 ok(FAILED(hr
), "IDirect3DDevice8_GetDepthStencilSurface should have failed, hr %#x.\n", hr
);
3043 ok(surf
== NULL
, "The depth stencil is %p, expected NULL\n", surf
);
3044 if (surf
) IDirect3DSurface8_Release(surf
);
3046 IDirect3DSurface8_Release(rt
);
3047 IDirect3DSurface8_Release(ds
);
3048 IDirect3DSurface8_Release(ds_bigger
);
3049 IDirect3DSurface8_Release(ds_bigger2
);
3052 IDirect3D8_Release(d3d8
);
3053 DestroyWindow(hwnd
);
3056 static void test_window_style(void)
3058 RECT focus_rect
, fullscreen_rect
, r
;
3059 LONG device_style
, device_exstyle
;
3060 LONG focus_style
, focus_exstyle
;
3061 struct device_desc device_desc
;
3062 LONG style
, expected_style
;
3063 IDirect3DDevice8
*device
;
3069 focus_window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3070 0, 0, registry_mode
.dmPelsWidth
/ 2, registry_mode
.dmPelsHeight
/ 2, 0, 0, 0, 0);
3071 device_window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3072 0, 0, registry_mode
.dmPelsWidth
/ 2, registry_mode
.dmPelsHeight
/ 2, 0, 0, 0, 0);
3073 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3074 ok(!!d3d8
, "Failed to create a D3D object.\n");
3076 device_style
= GetWindowLongA(device_window
, GWL_STYLE
);
3077 device_exstyle
= GetWindowLongA(device_window
, GWL_EXSTYLE
);
3078 focus_style
= GetWindowLongA(focus_window
, GWL_STYLE
);
3079 focus_exstyle
= GetWindowLongA(focus_window
, GWL_EXSTYLE
);
3081 SetRect(&fullscreen_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
3082 GetWindowRect(focus_window
, &focus_rect
);
3084 device_desc
.device_window
= device_window
;
3085 device_desc
.width
= registry_mode
.dmPelsWidth
;
3086 device_desc
.height
= registry_mode
.dmPelsHeight
;
3087 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3088 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
3090 skip("Failed to create a D3D device, skipping tests.\n");
3094 style
= GetWindowLongA(device_window
, GWL_STYLE
);
3095 expected_style
= device_style
| WS_VISIBLE
;
3096 todo_wine
ok(style
== expected_style
, "Expected device window style %#x, got %#x.\n",
3097 expected_style
, style
);
3098 style
= GetWindowLongA(device_window
, GWL_EXSTYLE
);
3099 expected_style
= device_exstyle
| WS_EX_TOPMOST
;
3100 todo_wine
ok(style
== expected_style
, "Expected device window extended style %#x, got %#x.\n",
3101 expected_style
, style
);
3103 style
= GetWindowLongA(focus_window
, GWL_STYLE
);
3104 ok(style
== focus_style
, "Expected focus window style %#x, got %#x.\n",
3105 focus_style
, style
);
3106 style
= GetWindowLongA(focus_window
, GWL_EXSTYLE
);
3107 ok(style
== focus_exstyle
, "Expected focus window extended style %#x, got %#x.\n",
3108 focus_exstyle
, style
);
3110 GetWindowRect(device_window
, &r
);
3111 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3112 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
3113 r
.left
, r
.top
, r
.right
, r
.bottom
);
3114 GetClientRect(device_window
, &r
);
3115 todo_wine
ok(!EqualRect(&r
, &fullscreen_rect
), "Client rect and window rect are equal.\n");
3116 GetWindowRect(focus_window
, &r
);
3117 ok(EqualRect(&r
, &focus_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3118 focus_rect
.left
, focus_rect
.top
, focus_rect
.right
, focus_rect
.bottom
,
3119 r
.left
, r
.top
, r
.right
, r
.bottom
);
3121 device_desc
.flags
= 0;
3122 hr
= reset_device(device
, &device_desc
);
3123 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3125 style
= GetWindowLongA(device_window
, GWL_STYLE
);
3126 expected_style
= device_style
| WS_VISIBLE
;
3127 ok(style
== expected_style
, "Expected device window style %#x, got %#x.\n",
3128 expected_style
, style
);
3129 style
= GetWindowLongA(device_window
, GWL_EXSTYLE
);
3130 expected_style
= device_exstyle
| WS_EX_TOPMOST
;
3131 ok(style
== expected_style
, "Expected device window extended style %#x, got %#x.\n",
3132 expected_style
, style
);
3134 style
= GetWindowLongA(focus_window
, GWL_STYLE
);
3135 ok(style
== focus_style
, "Expected focus window style %#x, got %#x.\n",
3136 focus_style
, style
);
3137 style
= GetWindowLongA(focus_window
, GWL_EXSTYLE
);
3138 ok(style
== focus_exstyle
, "Expected focus window extended style %#x, got %#x.\n",
3139 focus_exstyle
, style
);
3141 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3142 hr
= reset_device(device
, &device_desc
);
3143 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3144 ret
= SetForegroundWindow(GetDesktopWindow());
3145 ok(ret
, "Failed to set foreground window.\n");
3147 style
= GetWindowLongA(device_window
, GWL_STYLE
);
3148 expected_style
= device_style
| WS_MINIMIZE
| WS_VISIBLE
;
3149 todo_wine
ok(style
== expected_style
, "Expected device window style %#x, got %#x.\n",
3150 expected_style
, style
);
3151 style
= GetWindowLongA(device_window
, GWL_EXSTYLE
);
3152 expected_style
= device_exstyle
| WS_EX_TOPMOST
;
3153 todo_wine
ok(style
== expected_style
, "Expected device window extended style %#x, got %#x.\n",
3154 expected_style
, style
);
3156 style
= GetWindowLongA(focus_window
, GWL_STYLE
);
3157 ok(style
== focus_style
, "Expected focus window style %#x, got %#x.\n",
3158 focus_style
, style
);
3159 style
= GetWindowLongA(focus_window
, GWL_EXSTYLE
);
3160 ok(style
== focus_exstyle
, "Expected focus window extended style %#x, got %#x.\n",
3161 focus_exstyle
, style
);
3163 /* Follow-up tests fail on native if the device is destroyed while lost. */
3164 ShowWindow(focus_window
, SW_MINIMIZE
);
3165 ShowWindow(focus_window
, SW_RESTORE
);
3166 ret
= SetForegroundWindow(focus_window
);
3167 ok(ret
, "Failed to set foreground window.\n");
3169 hr
= reset_device(device
, &device_desc
);
3170 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3172 ref
= IDirect3DDevice8_Release(device
);
3173 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
3176 IDirect3D8_Release(d3d8
);
3178 DestroyWindow(device_window
);
3179 DestroyWindow(focus_window
);
3182 static void test_unsupported_shaders(void)
3184 IDirect3DDevice8
*device
;
3192 static const DWORD vs_2_0
[] =
3194 0xfffe0200, /* vs_2_0 */
3195 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
3196 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
3197 0x03000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
3198 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
3199 0x0000ffff /* end */
3201 static const DWORD ps_2_0
[] =
3203 0xffff0200, /* ps_2_0 */
3204 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
3205 0x03000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
3206 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
3207 0x0000ffff /* end */
3212 def c255
, 1.0, 1.0, 1.0, 1.0
3216 static const DWORD vs_1_255
[] =
3219 0x0000001f, 0x80000000, 0x900f0000,
3220 0x00000051, 0xa00f00ff, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
3221 0x00000002, 0x800f0000, 0x90e40000, 0xa0e400ff,
3222 0x00000001, 0xc00f0000, 0x80e40000,
3228 def c256
, 1.0, 1.0, 1.0, 1.0
3232 static const DWORD vs_1_256
[] =
3235 0x0000001f, 0x80000000, 0x900f0000,
3236 0x00000051, 0xa00f0100, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
3237 0x00000002, 0x800f0000, 0x90e40000, 0xa0e40100,
3238 0x00000001, 0xc00f0000, 0x80e40000,
3242 static const DWORD decl
[] =
3245 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
),
3249 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3250 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
3251 ok(!!window
, "Failed to create a window.\n");
3252 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
3253 ok(!!d3d
, "Failed to create a D3D object.\n");
3254 if (!(device
= create_device(d3d
, window
, NULL
)))
3256 skip("Failed to create a D3D device, skipping tests.\n");
3257 IDirect3D8_Release(d3d
);
3258 DestroyWindow(window
);
3262 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, simple_ps
, &vs
, 0);
3263 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
3265 hr
= IDirect3DDevice8_CreatePixelShader(device
, simple_vs
, &ps
);
3266 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
3268 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, vs_2_0
, &vs
, 0);
3269 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
3271 hr
= IDirect3DDevice8_CreatePixelShader(device
, ps_2_0
, &ps
);
3272 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
3274 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
3275 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
3276 if (caps
.MaxVertexShaderConst
< 256)
3278 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, vs_1_255
, &vs
, 0);
3279 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3283 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, vs_1_255
, &vs
, 0);
3284 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3285 hr
= IDirect3DDevice8_DeleteVertexShader(device
, vs
);
3286 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
3287 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, vs_1_256
, &vs
, 0);
3288 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3291 refcount
= IDirect3DDevice8_Release(device
);
3292 ok(!refcount
, "Device has %u references left.\n", refcount
);
3293 IDirect3D8_Release(d3d
);
3294 DestroyWindow(window
);
3297 static void test_mode_change(void)
3299 RECT d3d_rect
, focus_rect
, r
;
3300 struct device_desc device_desc
;
3301 IDirect3DSurface8
*backbuffer
;
3302 IDirect3DDevice8
*device
;
3303 D3DSURFACE_DESC desc
;
3307 UINT adapter_mode_count
, i
;
3311 D3DDISPLAYMODE d3ddm
;
3312 DWORD d3d_width
= 0, d3d_height
= 0, user32_width
= 0, user32_height
= 0;
3314 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3315 ok(!!d3d8
, "Failed to create a D3D object.\n");
3317 adapter_mode_count
= IDirect3D8_GetAdapterModeCount(d3d8
, D3DADAPTER_DEFAULT
);
3318 for (i
= 0; i
< adapter_mode_count
; ++i
)
3320 hr
= IDirect3D8_EnumAdapterModes(d3d8
, D3DADAPTER_DEFAULT
, i
, &d3ddm
);
3321 ok(SUCCEEDED(hr
), "Failed to enumerate display mode, hr %#x.\n", hr
);
3323 if (d3ddm
.Format
!= D3DFMT_X8R8G8B8
)
3325 if (d3ddm
.Width
== registry_mode
.dmPelsWidth
&& d3ddm
.Height
== registry_mode
.dmPelsHeight
)
3327 /* The r200 driver on Windows XP enumerates modes like 320x200 and 320x240 but
3328 * refuses to create a device at these sizes. */
3329 if (d3ddm
.Width
< 640 || d3ddm
.Height
< 480)
3334 user32_width
= d3ddm
.Width
;
3335 user32_height
= d3ddm
.Height
;
3339 /* Make sure the d3d mode is smaller in width or height and at most
3340 * equal in the other dimension than the mode passed to
3341 * ChangeDisplaySettings. Otherwise Windows shrinks the window to
3342 * the ChangeDisplaySettings parameters + 12. */
3343 if (d3ddm
.Width
== user32_width
&& d3ddm
.Height
== user32_height
)
3345 if (d3ddm
.Width
<= user32_width
&& d3ddm
.Height
<= user32_height
)
3347 d3d_width
= d3ddm
.Width
;
3348 d3d_height
= d3ddm
.Height
;
3351 if (user32_width
<= d3ddm
.Width
&& user32_height
<= d3ddm
.Height
)
3353 d3d_width
= user32_width
;
3354 d3d_height
= user32_height
;
3355 user32_width
= d3ddm
.Width
;
3356 user32_height
= d3ddm
.Height
;
3363 skip("Could not find adequate modes, skipping mode tests.\n");
3364 IDirect3D8_Release(d3d8
);
3368 memset(&devmode
, 0, sizeof(devmode
));
3369 devmode
.dmSize
= sizeof(devmode
);
3370 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
3371 devmode
.dmPelsWidth
= user32_width
;
3372 devmode
.dmPelsHeight
= user32_height
;
3373 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
3374 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3376 /* Make the windows visible, otherwise device::release does not restore the mode if
3377 * the application is not in foreground like on the testbot. */
3378 focus_window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
3379 0, 0, user32_width
/ 2, user32_height
/ 2, 0, 0, 0, 0);
3380 device_window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
3381 0, 0, user32_width
/ 2, user32_height
/ 2, 0, 0, 0, 0);
3383 SetRect(&d3d_rect
, 0, 0, d3d_width
, d3d_height
);
3384 GetWindowRect(focus_window
, &focus_rect
);
3386 device_desc
.device_window
= device_window
;
3387 device_desc
.width
= d3d_width
;
3388 device_desc
.height
= d3d_height
;
3389 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3390 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
3392 skip("Failed to create a D3D device, skipping tests.\n");
3393 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
3394 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3398 devmode
.dmPelsWidth
= user32_width
;
3399 devmode
.dmPelsHeight
= user32_height
;
3400 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
3401 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3403 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3404 ok(ret
, "Failed to get display mode.\n");
3405 ok(devmode
.dmPelsWidth
== user32_width
&& devmode
.dmPelsHeight
== user32_height
,
3406 "Expected resolution %ux%u, got %ux%u.\n",
3407 user32_width
, user32_height
, devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
3409 GetWindowRect(device_window
, &r
);
3410 ok(EqualRect(&r
, &d3d_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3411 d3d_rect
.left
, d3d_rect
.top
, d3d_rect
.right
, d3d_rect
.bottom
,
3412 r
.left
, r
.top
, r
.right
, r
.bottom
);
3413 GetWindowRect(focus_window
, &r
);
3414 ok(EqualRect(&r
, &focus_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3415 focus_rect
.left
, focus_rect
.top
, focus_rect
.right
, focus_rect
.bottom
,
3416 r
.left
, r
.top
, r
.right
, r
.bottom
);
3418 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
3419 ok(SUCCEEDED(hr
), "Failed to get backbuffer, hr %#x.\n", hr
);
3420 hr
= IDirect3DSurface8_GetDesc(backbuffer
, &desc
);
3421 ok(SUCCEEDED(hr
), "Failed to get backbuffer desc, hr %#x.\n", hr
);
3422 ok(desc
.Width
== d3d_width
, "Got unexpected backbuffer width %u, expected %u.\n",
3423 desc
.Width
, d3d_width
);
3424 ok(desc
.Height
== d3d_height
, "Got unexpected backbuffer height %u, expected %u.\n",
3425 desc
.Height
, d3d_height
);
3426 IDirect3DSurface8_Release(backbuffer
);
3428 refcount
= IDirect3DDevice8_Release(device
);
3429 ok(!refcount
, "Device has %u references left.\n", refcount
);
3431 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3432 ok(ret
, "Failed to get display mode.\n");
3433 todo_wine
ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
3434 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
3435 "Expected resolution %ux%u, got %ux%u.\n",
3436 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
3438 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
3439 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3441 /* The mode restore also happens when the device was created at the original screen size. */
3443 device_desc
.device_window
= device_window
;
3444 device_desc
.width
= registry_mode
.dmPelsWidth
;
3445 device_desc
.height
= registry_mode
.dmPelsHeight
;
3446 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3447 ok(!!(device
= create_device(d3d8
, focus_window
, &device_desc
)), "Failed to create a D3D device.\n");
3449 devmode
.dmPelsWidth
= user32_width
;
3450 devmode
.dmPelsHeight
= user32_height
;
3451 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
3452 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3454 refcount
= IDirect3DDevice8_Release(device
);
3455 ok(!refcount
, "Device has %u references left.\n", refcount
);
3457 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3458 ok(ret
, "Failed to get display mode.\n");
3459 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
3460 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
3461 "Expected resolution %ux%u, got %ux%u.\n",
3462 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
3465 DestroyWindow(device_window
);
3466 DestroyWindow(focus_window
);
3467 IDirect3D8_Release(d3d8
);
3470 static void test_device_window_reset(void)
3472 RECT fullscreen_rect
, device_rect
, r
;
3473 struct device_desc device_desc
;
3474 IDirect3DDevice8
*device
;
3481 wc
.lpfnWndProc
= test_proc
;
3482 wc
.lpszClassName
= "d3d8_test_wndproc_wc";
3483 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
3485 focus_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3486 0, 0, registry_mode
.dmPelsWidth
/ 2, registry_mode
.dmPelsHeight
/ 2, 0, 0, 0, 0);
3487 device_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3488 0, 0, registry_mode
.dmPelsWidth
/ 2, registry_mode
.dmPelsHeight
/ 2, 0, 0, 0, 0);
3489 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3490 ok(!!d3d8
, "Failed to create a D3D object.\n");
3492 SetRect(&fullscreen_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
3493 GetWindowRect(device_window
, &device_rect
);
3495 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3496 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3497 (LONG_PTR
)test_proc
, proc
);
3498 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3499 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3500 (LONG_PTR
)test_proc
, proc
);
3502 device_desc
.device_window
= NULL
;
3503 device_desc
.width
= registry_mode
.dmPelsWidth
;
3504 device_desc
.height
= registry_mode
.dmPelsHeight
;
3505 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3506 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
3508 skip("Failed to create a D3D device, skipping tests.\n");
3512 GetWindowRect(focus_window
, &r
);
3513 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3514 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
3515 r
.left
, r
.top
, r
.right
, r
.bottom
);
3516 GetWindowRect(device_window
, &r
);
3517 ok(EqualRect(&r
, &device_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3518 device_rect
.left
, device_rect
.top
, device_rect
.right
, device_rect
.bottom
,
3519 r
.left
, r
.top
, r
.right
, r
.bottom
);
3521 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3522 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3523 (LONG_PTR
)test_proc
, proc
);
3524 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3525 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
3527 device_desc
.device_window
= device_window
;
3528 hr
= reset_device(device
, &device_desc
);
3529 ok(SUCCEEDED(hr
), "Failed to reset device.\n");
3531 GetWindowRect(focus_window
, &r
);
3532 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3533 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
3534 r
.left
, r
.top
, r
.right
, r
.bottom
);
3535 GetWindowRect(device_window
, &r
);
3536 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3537 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
3538 r
.left
, r
.top
, r
.right
, r
.bottom
);
3540 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3541 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3542 (LONG_PTR
)test_proc
, proc
);
3543 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3544 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
3546 ref
= IDirect3DDevice8_Release(device
);
3547 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
3550 IDirect3D8_Release(d3d8
);
3551 DestroyWindow(device_window
);
3552 DestroyWindow(focus_window
);
3553 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL
));
3556 static void depth_blit_test(void)
3558 IDirect3DDevice8
*device
= NULL
;
3559 IDirect3DSurface8
*backbuffer
, *ds1
, *ds2
, *ds3
;
3561 const POINT dst_point
= {0, 0};
3566 hwnd
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3567 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
3568 ok(!!hwnd
, "Failed to create a window.\n");
3569 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3570 ok(!!d3d8
, "Failed to create a D3D object.\n");
3572 if (!(device
= create_device(d3d8
, hwnd
, NULL
)))
3574 skip("Failed to create a D3D device, skipping tests.\n");
3578 hr
= IDirect3DDevice8_GetRenderTarget(device
, &backbuffer
);
3579 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
3580 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &ds1
);
3581 ok(SUCCEEDED(hr
), "GetDepthStencilSurface failed, hr %#x.\n", hr
);
3582 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 640, 480, D3DFMT_D24S8
, D3DMULTISAMPLE_NONE
, &ds2
);
3583 ok(SUCCEEDED(hr
), "CreateDepthStencilSurface failed, hr %#x.\n", hr
);
3584 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 640, 480, D3DFMT_D24S8
, D3DMULTISAMPLE_NONE
, &ds3
);
3585 ok(SUCCEEDED(hr
), "CreateDepthStencilSurface failed, hr %#x.\n", hr
);
3587 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0, 0.0f
, 0);
3588 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
3591 SetRect(&src_rect
, 0, 0, 320, 240);
3592 hr
= IDirect3DDevice8_CopyRects(device
, ds1
, &src_rect
, 1, ds2
, &dst_point
);
3593 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
3595 SetRect(&src_rect
, 0, 480, 640, 0);
3596 hr
= IDirect3DDevice8_CopyRects(device
, ds1
, &src_rect
, 1, ds2
, &dst_point
);
3597 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
3598 /* Full, explicit. */
3599 SetRect(&src_rect
, 0, 0, 640, 480);
3600 hr
= IDirect3DDevice8_CopyRects(device
, ds1
, &src_rect
, 1, ds2
, &dst_point
);
3601 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
3602 /* Depth -> color blit.*/
3603 hr
= IDirect3DDevice8_CopyRects(device
, ds1
, &src_rect
, 1, backbuffer
, &dst_point
);
3604 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
3605 /* Full, NULL rects, current depth stencil -> unbound depth stencil */
3606 hr
= IDirect3DDevice8_CopyRects(device
, ds1
, NULL
, 0, ds2
, NULL
);
3607 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
3608 /* Full, NULL rects, unbound depth stencil -> current depth stencil */
3609 hr
= IDirect3DDevice8_CopyRects(device
, ds2
, NULL
, 0, ds1
, NULL
);
3610 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
3611 /* Full, NULL rects, unbound depth stencil -> unbound depth stencil */
3612 hr
= IDirect3DDevice8_CopyRects(device
, ds2
, NULL
, 0, ds3
, NULL
);
3613 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
3615 IDirect3DSurface8_Release(backbuffer
);
3616 IDirect3DSurface8_Release(ds3
);
3617 IDirect3DSurface8_Release(ds2
);
3618 IDirect3DSurface8_Release(ds1
);
3621 if (device
) IDirect3DDevice8_Release(device
);
3622 IDirect3D8_Release(d3d8
);
3623 DestroyWindow(hwnd
);
3626 static void test_reset_resources(void)
3628 IDirect3DSurface8
*surface
, *rt
;
3629 IDirect3DTexture8
*texture
;
3630 IDirect3DDevice8
*device
;
3636 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3637 0, 0, 640, 480, 0, 0, 0, 0);
3638 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3639 ok(!!d3d8
, "Failed to create a D3D object.\n");
3641 if (!(device
= create_device(d3d8
, window
, NULL
)))
3643 skip("Failed to create a D3D device, skipping tests.\n");
3647 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 128, 128, D3DFMT_D24S8
,
3648 D3DMULTISAMPLE_NONE
, &surface
);
3649 ok(SUCCEEDED(hr
), "Failed to create depth/stencil surface, hr %#x.\n", hr
);
3651 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
,
3652 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &texture
);
3653 ok(SUCCEEDED(hr
), "Failed to create render target texture, hr %#x.\n", hr
);
3654 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &rt
);
3655 ok(SUCCEEDED(hr
), "Failed to get surface, hr %#x.\n", hr
);
3656 IDirect3DTexture8_Release(texture
);
3658 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, surface
);
3659 ok(SUCCEEDED(hr
), "Failed to set render target surface, hr %#x.\n", hr
);
3660 IDirect3DSurface8_Release(rt
);
3661 IDirect3DSurface8_Release(surface
);
3663 hr
= reset_device(device
, NULL
);
3664 ok(SUCCEEDED(hr
), "Failed to reset device.\n");
3666 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_MONO
, &rt
);
3667 ok(SUCCEEDED(hr
), "Failed to get back buffer, hr %#x.\n", hr
);
3668 hr
= IDirect3DDevice8_GetRenderTarget(device
, &surface
);
3669 ok(SUCCEEDED(hr
), "Failed to get render target surface, hr %#x.\n", hr
);
3670 ok(surface
== rt
, "Got unexpected surface %p for render target.\n", surface
);
3671 IDirect3DSurface8_Release(surface
);
3672 IDirect3DSurface8_Release(rt
);
3674 ref
= IDirect3DDevice8_Release(device
);
3675 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
3678 IDirect3D8_Release(d3d8
);
3679 DestroyWindow(window
);
3682 static void test_set_rt_vp_scissor(void)
3684 IDirect3DDevice8
*device
;
3685 IDirect3DSurface8
*rt
;
3693 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3694 0, 0, 640, 480, 0, 0, 0, 0);
3695 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3696 ok(!!d3d8
, "Failed to create a D3D object.\n");
3697 if (!(device
= create_device(d3d8
, window
, NULL
)))
3699 skip("Failed to create a D3D device, skipping tests.\n");
3700 IDirect3D8_Release(d3d8
);
3701 DestroyWindow(window
);
3705 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 128, 128, D3DFMT_A8R8G8B8
,
3706 D3DMULTISAMPLE_NONE
, FALSE
, &rt
);
3707 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
3709 hr
= IDirect3DDevice8_GetViewport(device
, &vp
);
3710 ok(SUCCEEDED(hr
), "Failed to get viewport, hr %#x.\n", hr
);
3711 ok(!vp
.X
, "Got unexpected vp.X %u.\n", vp
.X
);
3712 ok(!vp
.Y
, "Got unexpected vp.Y %u.\n", vp
.Y
);
3713 ok(vp
.Width
== 640, "Got unexpected vp.Width %u.\n", vp
.Width
);
3714 ok(vp
.Height
== 480, "Got unexpected vp.Height %u.\n", vp
.Height
);
3715 ok(vp
.MinZ
== 0.0f
, "Got unexpected vp.MinZ %.8e.\n", vp
.MinZ
);
3716 ok(vp
.MaxZ
== 1.0f
, "Got unexpected vp.MaxZ %.8e.\n", vp
.MaxZ
);
3718 hr
= IDirect3DDevice8_BeginStateBlock(device
);
3719 ok(SUCCEEDED(hr
), "Failed to begin stateblock, hr %#x.\n", hr
);
3721 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, NULL
);
3722 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
3724 hr
= IDirect3DDevice8_EndStateBlock(device
, &stateblock
);
3725 ok(SUCCEEDED(hr
), "Failed to end stateblock, hr %#x.\n", hr
);
3726 hr
= IDirect3DDevice8_DeleteStateBlock(device
, stateblock
);
3727 ok(SUCCEEDED(hr
), "Failed to delete stateblock, hr %#x.\n", hr
);
3729 hr
= IDirect3DDevice8_GetViewport(device
, &vp
);
3730 ok(SUCCEEDED(hr
), "Failed to get viewport, hr %#x.\n", hr
);
3731 ok(!vp
.X
, "Got unexpected vp.X %u.\n", vp
.X
);
3732 ok(!vp
.Y
, "Got unexpected vp.Y %u.\n", vp
.Y
);
3733 ok(vp
.Width
== 128, "Got unexpected vp.Width %u.\n", vp
.Width
);
3734 ok(vp
.Height
== 128, "Got unexpected vp.Height %u.\n", vp
.Height
);
3735 ok(vp
.MinZ
== 0.0f
, "Got unexpected vp.MinZ %.8e.\n", vp
.MinZ
);
3736 ok(vp
.MaxZ
== 1.0f
, "Got unexpected vp.MaxZ %.8e.\n", vp
.MaxZ
);
3738 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, NULL
);
3739 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
3747 hr
= IDirect3DDevice8_SetViewport(device
, &vp
);
3748 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
3750 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, NULL
);
3751 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
3753 hr
= IDirect3DDevice8_GetViewport(device
, &vp
);
3754 ok(SUCCEEDED(hr
), "Failed to get viewport, hr %#x.\n", hr
);
3755 ok(!vp
.X
, "Got unexpected vp.X %u.\n", vp
.X
);
3756 ok(!vp
.Y
, "Got unexpected vp.Y %u.\n", vp
.Y
);
3757 ok(vp
.Width
== 128, "Got unexpected vp.Width %u.\n", vp
.Width
);
3758 ok(vp
.Height
== 128, "Got unexpected vp.Height %u.\n", vp
.Height
);
3759 ok(vp
.MinZ
== 0.0f
, "Got unexpected vp.MinZ %.8e.\n", vp
.MinZ
);
3760 ok(vp
.MaxZ
== 1.0f
, "Got unexpected vp.MaxZ %.8e.\n", vp
.MaxZ
);
3762 IDirect3DSurface8_Release(rt
);
3763 refcount
= IDirect3DDevice8_Release(device
);
3764 ok(!refcount
, "Device has %u references left.\n", refcount
);
3765 IDirect3D8_Release(d3d8
);
3766 DestroyWindow(window
);
3769 static void test_validate_vs(void)
3773 0xfffe0101, /* vs_1_1 */
3774 0x00000009, 0xc0010000, 0x90e40000, 0xa0e40000, /* dp4 oPos.x, v0, c0 */
3775 0x00000009, 0xc0020000, 0x90e40000, 0xa0e40001, /* dp4 oPos.y, v0, c1 */
3776 0x00000009, 0xc0040000, 0x90e40000, 0xa0e40002, /* dp4 oPos.z, v0, c2 */
3777 0x00000009, 0xc0080000, 0x90e40000, 0xa0e40003, /* dp4 oPos.w, v0, c3 */
3778 0x0000ffff, /* end */
3782 hr
= ValidateVertexShader(0, 0, 0, 0, 0);
3783 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
3784 hr
= ValidateVertexShader(0, 0, 0, 1, 0);
3785 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
3786 hr
= ValidateVertexShader(vs
, 0, 0, 0, 0);
3787 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
3789 hr
= ValidateVertexShader(vs
, 0, 0, 1, 0);
3790 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
3791 /* Seems to do some version checking. */
3792 *vs
= 0xfffe0100; /* vs_1_0 */
3793 hr
= ValidateVertexShader(vs
, 0, 0, 0, 0);
3794 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
3796 *vs
= 0xfffe0102; /* bogus version */
3797 hr
= ValidateVertexShader(vs
, 0, 0, 1, 0);
3798 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
3799 /* I've seen that applications always pass the 2nd and 3rd parameter as 0.
3800 * Simple test with non-zero parameters. */
3801 *vs
= 0xfffe0101; /* vs_1_1 */
3802 hr
= ValidateVertexShader(vs
, vs
, 0, 1, 0);
3803 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
3805 hr
= ValidateVertexShader(vs
, 0, vs
, 1, 0);
3806 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
3807 /* I've seen the 4th parameter always passed as either 0 or 1, but passing
3808 * other values doesn't seem to hurt. */
3809 hr
= ValidateVertexShader(vs
, 0, 0, 12345, 0);
3810 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
3811 /* What is the 5th parameter? The following seems to work ok. */
3812 hr
= ValidateVertexShader(vs
, 0, 0, 1, vs
);
3813 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
3816 static void test_validate_ps(void)
3820 0xffff0101, /* ps_1_1 */
3821 0x00000051, 0xa00f0001, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
3822 0x00000042, 0xb00f0000, /* tex t0 */
3823 0x00000008, 0x800f0000, 0xa0e40001, 0xa0e40000, /* dp3 r0, c1, c0 */
3824 0x00000005, 0x800f0000, 0x90e40000, 0x80e40000, /* mul r0, v0, r0 */
3825 0x00000005, 0x800f0000, 0xb0e40000, 0x80e40000, /* mul r0, t0, r0 */
3826 0x0000ffff, /* end */
3830 hr
= ValidatePixelShader(0, 0, 0, 0);
3831 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
3832 hr
= ValidatePixelShader(0, 0, 1, 0);
3833 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
3834 hr
= ValidatePixelShader(ps
, 0, 0, 0);
3835 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
3837 hr
= ValidatePixelShader(ps
, 0, 1, 0);
3838 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
3839 /* Seems to do some version checking. */
3840 *ps
= 0xffff0105; /* bogus version */
3841 hr
= ValidatePixelShader(ps
, 0, 1, 0);
3842 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
3843 /* I've seen that applications always pass the 2nd parameter as 0.
3844 * Simple test with a non-zero parameter. */
3845 *ps
= 0xffff0101; /* ps_1_1 */
3846 hr
= ValidatePixelShader(ps
, ps
, 1, 0);
3847 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
3848 /* I've seen the 3rd parameter always passed as either 0 or 1, but passing
3849 * other values doesn't seem to hurt. */
3850 hr
= ValidatePixelShader(ps
, 0, 12345, 0);
3851 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
3852 /* What is the 4th parameter? The following seems to work ok. */
3853 hr
= ValidatePixelShader(ps
, 0, 1, ps
);
3854 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
3857 static void test_volume_get_container(void)
3859 IDirect3DVolumeTexture8
*texture
= NULL
;
3860 IDirect3DVolume8
*volume
= NULL
;
3861 IDirect3DDevice8
*device
;
3862 IUnknown
*container
;
3869 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3870 0, 0, 640, 480, 0, 0, 0, 0);
3871 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3872 ok(!!d3d8
, "Failed to create a D3D object.\n");
3873 if (!(device
= create_device(d3d8
, window
, NULL
)))
3875 skip("Failed to create a D3D device, skipping tests.\n");
3876 IDirect3D8_Release(d3d8
);
3877 DestroyWindow(window
);
3881 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
3882 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
3883 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
))
3885 skip("No volume texture support, skipping tests.\n");
3886 IDirect3DDevice8_Release(device
);
3887 IDirect3D8_Release(d3d8
);
3888 DestroyWindow(window
);
3892 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 128, 128, 128, 1, 0,
3893 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &texture
);
3894 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
3895 ok(!!texture
, "Got unexpected texture %p.\n", texture
);
3897 hr
= IDirect3DVolumeTexture8_GetVolumeLevel(texture
, 0, &volume
);
3898 ok(SUCCEEDED(hr
), "Failed to get volume level, hr %#x.\n", hr
);
3899 ok(!!volume
, "Got unexpected volume %p.\n", volume
);
3901 /* These should work... */
3903 hr
= IDirect3DVolume8_GetContainer(volume
, &IID_IUnknown
, (void **)&container
);
3904 ok(SUCCEEDED(hr
), "Failed to get volume container, hr %#x.\n", hr
);
3905 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
3906 IUnknown_Release(container
);
3909 hr
= IDirect3DVolume8_GetContainer(volume
, &IID_IDirect3DResource8
, (void **)&container
);
3910 ok(SUCCEEDED(hr
), "Failed to get volume container, hr %#x.\n", hr
);
3911 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
3912 IUnknown_Release(container
);
3915 hr
= IDirect3DVolume8_GetContainer(volume
, &IID_IDirect3DBaseTexture8
, (void **)&container
);
3916 ok(SUCCEEDED(hr
), "Failed to get volume container, hr %#x.\n", hr
);
3917 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
3918 IUnknown_Release(container
);
3921 hr
= IDirect3DVolume8_GetContainer(volume
, &IID_IDirect3DVolumeTexture8
, (void **)&container
);
3922 ok(SUCCEEDED(hr
), "Failed to get volume container, hr %#x.\n", hr
);
3923 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
3924 IUnknown_Release(container
);
3926 /* ...and this one shouldn't. This should return E_NOINTERFACE and set container to NULL. */
3927 hr
= IDirect3DVolume8_GetContainer(volume
, &IID_IDirect3DVolume8
, (void **)&container
);
3928 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
3929 ok(!container
, "Got unexpected container %p.\n", container
);
3931 IDirect3DVolume8_Release(volume
);
3932 IDirect3DVolumeTexture8_Release(texture
);
3933 refcount
= IDirect3DDevice8_Release(device
);
3934 ok(!refcount
, "Device has %u references left.\n", refcount
);
3935 IDirect3D8_Release(d3d8
);
3936 DestroyWindow(window
);
3939 static void test_vb_lock_flags(void)
3944 const char *debug_string
;
3949 {D3DLOCK_READONLY
, "D3DLOCK_READONLY", D3D_OK
},
3950 {D3DLOCK_DISCARD
, "D3DLOCK_DISCARD", D3D_OK
},
3951 {D3DLOCK_NOOVERWRITE
, "D3DLOCK_NOOVERWRITE", D3D_OK
},
3952 {D3DLOCK_NOOVERWRITE
| D3DLOCK_DISCARD
, "D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD", D3D_OK
},
3953 {D3DLOCK_NOOVERWRITE
| D3DLOCK_READONLY
, "D3DLOCK_NOOVERWRITE | D3DLOCK_READONLY", D3D_OK
},
3954 {D3DLOCK_READONLY
| D3DLOCK_DISCARD
, "D3DLOCK_READONLY | D3DLOCK_DISCARD", D3D_OK
},
3955 /* Completely bogus flags aren't an error. */
3956 {0xdeadbeef, "0xdeadbeef", D3D_OK
},
3958 IDirect3DVertexBuffer8
*buffer
;
3959 IDirect3DDevice8
*device
;
3967 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3968 0, 0, 640, 480, 0, 0, 0, 0);
3969 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3970 ok(!!d3d8
, "Failed to create a D3D object.\n");
3971 if (!(device
= create_device(d3d8
, window
, NULL
)))
3973 skip("Failed to create a D3D device, skipping tests.\n");
3974 IDirect3D8_Release(d3d8
);
3975 DestroyWindow(window
);
3979 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, 1024, D3DUSAGE_DYNAMIC
, 0, D3DPOOL_DEFAULT
, &buffer
);
3980 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
3982 for (i
= 0; i
< (sizeof(test_data
) / sizeof(*test_data
)); ++i
)
3984 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, 0, &data
, test_data
[i
].flags
);
3985 ok(hr
== test_data
[i
].result
, "Got unexpected hr %#x for %s.\n",
3986 hr
, test_data
[i
].debug_string
);
3989 ok(!!data
, "Got unexpected data %p.\n", data
);
3990 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
3991 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
3995 IDirect3DVertexBuffer8_Release(buffer
);
3996 refcount
= IDirect3DDevice8_Release(device
);
3997 ok(!refcount
, "Device has %u references left.\n", refcount
);
3998 IDirect3D8_Release(d3d8
);
3999 DestroyWindow(window
);
4002 /* Test the default texture stage state values */
4003 static void test_texture_stage_states(void)
4005 IDirect3DDevice8
*device
;
4014 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4015 0, 0, 640, 480, 0, 0, 0, 0);
4016 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4017 ok(!!d3d8
, "Failed to create a D3D object.\n");
4018 if (!(device
= create_device(d3d8
, window
, NULL
)))
4020 skip("Failed to create a D3D device, skipping tests.\n");
4021 IDirect3D8_Release(d3d8
);
4022 DestroyWindow(window
);
4026 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
4027 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
4029 for (i
= 0; i
< caps
.MaxTextureBlendStages
; ++i
)
4031 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_COLOROP
, &value
);
4032 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4033 ok(value
== (i
? D3DTOP_DISABLE
: D3DTOP_MODULATE
),
4034 "Got unexpected value %#x for D3DTSS_COLOROP, stage %u.\n", value
, i
);
4035 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_COLORARG1
, &value
);
4036 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4037 ok(value
== D3DTA_TEXTURE
, "Got unexpected value %#x for D3DTSS_COLORARG1, stage %u.\n", value
, i
);
4038 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_COLORARG2
, &value
);
4039 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4040 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_COLORARG2, stage %u.\n", value
, i
);
4041 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_ALPHAOP
, &value
);
4042 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4043 ok(value
== (i
? D3DTOP_DISABLE
: D3DTOP_SELECTARG1
),
4044 "Got unexpected value %#x for D3DTSS_ALPHAOP, stage %u.\n", value
, i
);
4045 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_ALPHAARG1
, &value
);
4046 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4047 ok(value
== D3DTA_TEXTURE
, "Got unexpected value %#x for D3DTSS_ALPHAARG1, stage %u.\n", value
, i
);
4048 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_ALPHAARG2
, &value
);
4049 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4050 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_ALPHAARG2, stage %u.\n", value
, i
);
4051 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVMAT00
, &value
);
4052 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4053 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVMAT00, stage %u.\n", value
, i
);
4054 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVMAT01
, &value
);
4055 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4056 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVMAT01, stage %u.\n", value
, i
);
4057 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVMAT10
, &value
);
4058 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4059 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVMAT10, stage %u.\n", value
, i
);
4060 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVMAT11
, &value
);
4061 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4062 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVMAT11, stage %u.\n", value
, i
);
4063 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_TEXCOORDINDEX
, &value
);
4064 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4065 ok(value
== i
, "Got unexpected value %#x for D3DTSS_TEXCOORDINDEX, stage %u.\n", value
, i
);
4066 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVLSCALE
, &value
);
4067 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4068 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVLSCALE, stage %u.\n", value
, i
);
4069 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVLOFFSET
, &value
);
4070 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4071 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVLOFFSET, stage %u.\n", value
, i
);
4072 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_TEXTURETRANSFORMFLAGS
, &value
);
4073 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4074 ok(value
== D3DTTFF_DISABLE
,
4075 "Got unexpected value %#x for D3DTSS_TEXTURETRANSFORMFLAGS, stage %u.\n", value
, i
);
4076 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_COLORARG0
, &value
);
4077 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4078 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_COLORARG0, stage %u.\n", value
, i
);
4079 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_ALPHAARG0
, &value
);
4080 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4081 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_ALPHAARG0, stage %u.\n", value
, i
);
4082 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_RESULTARG
, &value
);
4083 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4084 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_RESULTARG, stage %u.\n", value
, i
);
4087 refcount
= IDirect3DDevice8_Release(device
);
4088 ok(!refcount
, "Device has %u references left.\n", refcount
);
4089 IDirect3D8_Release(d3d8
);
4090 DestroyWindow(window
);
4093 static void test_cube_textures(void)
4095 IDirect3DCubeTexture8
*texture
;
4096 IDirect3DDevice8
*device
;
4103 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4104 0, 0, 640, 480, 0, 0, 0, 0);
4105 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4106 ok(!!d3d8
, "Failed to create a D3D object.\n");
4107 if (!(device
= create_device(d3d8
, window
, NULL
)))
4109 skip("Failed to create a D3D device, skipping tests.\n");
4110 IDirect3D8_Release(d3d8
);
4111 DestroyWindow(window
);
4115 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
4116 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
4118 if (caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
)
4120 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &texture
);
4121 ok(hr
== D3D_OK
, "Failed to create D3DPOOL_DEFAULT cube texture, hr %#x.\n", hr
);
4122 IDirect3DCubeTexture8_Release(texture
);
4123 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &texture
);
4124 ok(hr
== D3D_OK
, "Failed to create D3DPOOL_MANAGED cube texture, hr %#x.\n", hr
);
4125 IDirect3DCubeTexture8_Release(texture
);
4126 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_SYSTEMMEM
, &texture
);
4127 ok(hr
== D3D_OK
, "Failed to create D3DPOOL_SYSTEMMEM cube texture, hr %#x.\n", hr
);
4128 IDirect3DCubeTexture8_Release(texture
);
4132 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &texture
);
4133 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for D3DPOOL_DEFAULT cube texture.\n", hr
);
4134 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &texture
);
4135 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for D3DPOOL_MANAGED cube texture.\n", hr
);
4136 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_SYSTEMMEM
, &texture
);
4137 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for D3DPOOL_SYSTEMMEM cube texture.\n", hr
);
4139 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_SCRATCH
, &texture
);
4140 ok(hr
== D3D_OK
, "Failed to create D3DPOOL_SCRATCH cube texture, hr %#x.\n", hr
);
4141 IDirect3DCubeTexture8_Release(texture
);
4143 refcount
= IDirect3DDevice8_Release(device
);
4144 ok(!refcount
, "Device has %u references left.\n", refcount
);
4145 IDirect3D8_Release(d3d8
);
4146 DestroyWindow(window
);
4149 /* Test the behaviour of the IDirect3DDevice8::CreateImageSurface() method.
4151 * The expected behaviour (as documented in the original DX8 docs) is that the
4152 * call returns a surface in the SYSTEMMEM pool. Games like Max Payne 1 and 2
4153 * depend on this behaviour.
4155 * A short remark in the DX9 docs however states that the pool of the returned
4156 * surface object is D3DPOOL_SCRATCH. This is misinformation and would result
4157 * in screenshots not appearing in the savegame loading menu of both games
4158 * mentioned above (engine tries to display a texture from the scratch pool).
4160 * This test verifies that the behaviour described in the original d3d8 docs
4161 * is the correct one. For more information about this issue, see the MSDN:
4162 * d3d9 docs: "Converting to Direct3D 9"
4163 * d3d9 reference: "IDirect3DDevice9::CreateOffscreenPlainSurface"
4164 * d3d8 reference: "IDirect3DDevice8::CreateImageSurface" */
4165 static void test_image_surface_pool(void)
4167 IDirect3DSurface8
*surface
;
4168 IDirect3DDevice8
*device
;
4169 D3DSURFACE_DESC desc
;
4175 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4176 0, 0, 640, 480, 0, 0, 0, 0);
4177 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4178 ok(!!d3d8
, "Failed to create a D3D object.\n");
4179 if (!(device
= create_device(d3d8
, window
, NULL
)))
4181 skip("Failed to create a D3D device, skipping tests.\n");
4182 IDirect3D8_Release(d3d8
);
4183 DestroyWindow(window
);
4187 hr
= IDirect3DDevice8_CreateImageSurface(device
, 128, 128, D3DFMT_A8R8G8B8
, &surface
);
4188 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4189 hr
= IDirect3DSurface8_GetDesc(surface
, &desc
);
4190 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4191 ok(desc
.Pool
== D3DPOOL_SYSTEMMEM
, "Got unexpected pool %#x.\n", desc
.Pool
);
4192 IDirect3DSurface8_Release(surface
);
4194 refcount
= IDirect3DDevice8_Release(device
);
4195 ok(!refcount
, "Device has %u references left.\n", refcount
);
4196 IDirect3D8_Release(d3d8
);
4197 DestroyWindow(window
);
4200 static void test_surface_get_container(void)
4202 IDirect3DTexture8
*texture
= NULL
;
4203 IDirect3DSurface8
*surface
= NULL
;
4204 IDirect3DDevice8
*device
;
4205 IUnknown
*container
;
4211 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4212 0, 0, 640, 480, 0, 0, 0, 0);
4213 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4214 ok(!!d3d8
, "Failed to create a D3D object.\n");
4215 if (!(device
= create_device(d3d8
, window
, NULL
)))
4217 skip("Failed to create a D3D device, skipping tests.\n");
4218 IDirect3D8_Release(d3d8
);
4219 DestroyWindow(window
);
4223 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1, 0,
4224 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &texture
);
4225 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
4226 ok(!!texture
, "Got unexpected texture %p.\n", texture
);
4228 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &surface
);
4229 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
4230 ok(!!surface
, "Got unexpected surface %p.\n", surface
);
4232 /* These should work... */
4234 hr
= IDirect3DSurface8_GetContainer(surface
, &IID_IUnknown
, (void **)&container
);
4235 ok(SUCCEEDED(hr
), "Failed to get surface container, hr %#x.\n", hr
);
4236 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4237 IUnknown_Release(container
);
4240 hr
= IDirect3DSurface8_GetContainer(surface
, &IID_IDirect3DResource8
, (void **)&container
);
4241 ok(SUCCEEDED(hr
), "Failed to get surface container, hr %#x.\n", hr
);
4242 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4243 IUnknown_Release(container
);
4246 hr
= IDirect3DSurface8_GetContainer(surface
, &IID_IDirect3DBaseTexture8
, (void **)&container
);
4247 ok(SUCCEEDED(hr
), "Failed to get surface container, hr %#x.\n", hr
);
4248 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4249 IUnknown_Release(container
);
4252 hr
= IDirect3DSurface8_GetContainer(surface
, &IID_IDirect3DTexture8
, (void **)&container
);
4253 ok(SUCCEEDED(hr
), "Failed to get surface container, hr %#x.\n", hr
);
4254 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4255 IUnknown_Release(container
);
4257 /* ...and this one shouldn't. This should return E_NOINTERFACE and set container to NULL. */
4258 hr
= IDirect3DSurface8_GetContainer(surface
, &IID_IDirect3DSurface8
, (void **)&container
);
4259 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
4260 ok(!container
, "Got unexpected container %p.\n", container
);
4262 IDirect3DSurface8_Release(surface
);
4263 IDirect3DTexture8_Release(texture
);
4264 refcount
= IDirect3DDevice8_Release(device
);
4265 ok(!refcount
, "Device has %u references left.\n", refcount
);
4266 IDirect3D8_Release(d3d8
);
4267 DestroyWindow(window
);
4270 static void test_lockrect_invalid(void)
4272 static const RECT valid
[] =
4278 static const RECT invalid
[] =
4280 {60, 60, 60, 68}, /* 0 height */
4281 {60, 60, 68, 60}, /* 0 width */
4282 {68, 60, 60, 68}, /* left > right */
4283 {60, 68, 68, 60}, /* top > bottom */
4284 {-8, 60, 0, 68}, /* left < surface */
4285 {60, -8, 68, 0}, /* top < surface */
4286 {-16, 60, -8, 68}, /* right < surface */
4287 {60, -16, 68, -8}, /* bottom < surface */
4288 {60, 60, 136, 68}, /* right > surface */
4289 {60, 60, 68, 136}, /* bottom > surface */
4290 {136, 60, 144, 68}, /* left > surface */
4291 {60, 136, 68, 144}, /* top > surface */
4293 IDirect3DSurface8
*surface
= NULL
;
4294 D3DLOCKED_RECT locked_rect
;
4295 IDirect3DDevice8
*device
;
4303 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4304 0, 0, 640, 480, 0, 0, 0, 0);
4305 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4306 ok(!!d3d8
, "Failed to create a D3D object.\n");
4307 if (!(device
= create_device(d3d8
, window
, NULL
)))
4309 skip("Failed to create a D3D device, skipping tests.\n");
4310 IDirect3D8_Release(d3d8
);
4311 DestroyWindow(window
);
4315 hr
= IDirect3DDevice8_CreateImageSurface(device
, 128, 128, D3DFMT_A8R8G8B8
, &surface
);
4316 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4317 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
4318 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4319 base
= locked_rect
.pBits
;
4320 hr
= IDirect3DSurface8_UnlockRect(surface
);
4321 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4323 for (i
= 0; i
< (sizeof(valid
) / sizeof(*valid
)); ++i
)
4325 unsigned int offset
, expected_offset
;
4326 const RECT
*rect
= &valid
[i
];
4328 locked_rect
.pBits
= (BYTE
*)0xdeadbeef;
4329 locked_rect
.Pitch
= 0xdeadbeef;
4331 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, rect
, 0);
4332 ok(SUCCEEDED(hr
), "Failed to lock surface with rect [%d, %d]->[%d, %d], hr %#x.\n",
4333 rect
->left
, rect
->top
, rect
->right
, rect
->bottom
, hr
);
4335 offset
= (BYTE
*)locked_rect
.pBits
- base
;
4336 expected_offset
= rect
->top
* locked_rect
.Pitch
+ rect
->left
* 4;
4337 ok(offset
== expected_offset
,
4338 "Got unexpected offset %u (expected %u) for rect [%d, %d]->[%d, %d].\n",
4339 offset
, expected_offset
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
4341 hr
= IDirect3DSurface8_UnlockRect(surface
);
4342 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4345 for (i
= 0; i
< (sizeof(invalid
) / sizeof(*invalid
)); ++i
)
4347 const RECT
*rect
= &invalid
[i
];
4349 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, rect
, 0);
4350 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d].\n",
4351 hr
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
4354 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
4355 ok(SUCCEEDED(hr
), "Failed to lock surface with rect NULL, hr %#x.\n", hr
);
4356 locked_rect
.pBits
= (void *)0xdeadbeef;
4357 locked_rect
.Pitch
= 1;
4358 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
4359 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4360 ok(!locked_rect
.pBits
, "Got unexpected pBits %p.\n", locked_rect
.pBits
);
4361 ok(!locked_rect
.Pitch
, "Got unexpected Pitch %u.\n", locked_rect
.Pitch
);
4362 hr
= IDirect3DSurface8_UnlockRect(surface
);
4363 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4365 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &valid
[0], 0);
4366 ok(hr
== D3D_OK
, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d].\n",
4367 hr
, valid
[0].left
, valid
[0].top
, valid
[0].right
, valid
[0].bottom
);
4368 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &valid
[0], 0);
4369 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d].\n",
4370 hr
, valid
[0].left
, valid
[0].top
, valid
[0].right
, valid
[0].bottom
);
4371 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &valid
[1], 0);
4372 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d].\n",
4373 hr
, valid
[1].left
, valid
[1].top
, valid
[1].right
, valid
[1].bottom
);
4374 hr
= IDirect3DSurface8_UnlockRect(surface
);
4375 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4377 IDirect3DSurface8_Release(surface
);
4378 refcount
= IDirect3DDevice8_Release(device
);
4379 ok(!refcount
, "Device has %u references left.\n", refcount
);
4380 IDirect3D8_Release(d3d8
);
4381 DestroyWindow(window
);
4384 static void test_private_data(void)
4386 ULONG refcount
, expected_refcount
;
4387 IDirect3DTexture8
*texture
;
4388 IDirect3DSurface8
*surface
, *surface2
;
4389 IDirect3DDevice8
*device
;
4395 DWORD data
[4] = {1, 2, 3, 4};
4396 static const GUID d3d8_private_data_test_guid
=
4401 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
4403 static const GUID d3d8_private_data_test_guid2
=
4408 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
4411 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4412 0, 0, 640, 480, 0, 0, 0, 0);
4413 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4414 ok(!!d3d8
, "Failed to create a D3D object.\n");
4415 if (!(device
= create_device(d3d8
, window
, NULL
)))
4417 skip("Failed to create a D3D device, skipping tests.\n");
4418 IDirect3D8_Release(d3d8
);
4419 DestroyWindow(window
);
4423 hr
= IDirect3DDevice8_CreateImageSurface(device
, 4, 4, D3DFMT_A8R8G8B8
, &surface
);
4424 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4426 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
4427 device
, 0, D3DSPD_IUNKNOWN
);
4428 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4429 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
4430 device
, 5, D3DSPD_IUNKNOWN
);
4431 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4432 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
4433 device
, sizeof(IUnknown
*) * 2, D3DSPD_IUNKNOWN
);
4434 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4436 /* A failing SetPrivateData call does not clear the old data with the same tag. */
4437 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
, device
,
4438 sizeof(device
), D3DSPD_IUNKNOWN
);
4439 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
4440 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
, device
,
4441 sizeof(device
) * 2, D3DSPD_IUNKNOWN
);
4442 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4444 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, &ptr
, &size
);
4445 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
4446 IUnknown_Release(ptr
);
4447 hr
= IDirect3DSurface8_FreePrivateData(surface
, &d3d8_private_data_test_guid
);
4448 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
4450 refcount
= get_refcount((IUnknown
*)device
);
4451 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
4452 device
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
4453 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4454 expected_refcount
= refcount
+ 1;
4455 refcount
= get_refcount((IUnknown
*)device
);
4456 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
4457 hr
= IDirect3DSurface8_FreePrivateData(surface
, &d3d8_private_data_test_guid
);
4458 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4459 expected_refcount
= refcount
- 1;
4460 refcount
= get_refcount((IUnknown
*)device
);
4461 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
4463 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
4464 device
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
4465 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4466 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
4467 surface
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
4468 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4469 refcount
= get_refcount((IUnknown
*)device
);
4470 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
4472 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
4473 device
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
4474 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4475 size
= 2 * sizeof(ptr
);
4476 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, &ptr
, &size
);
4477 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4478 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
4479 expected_refcount
= refcount
+ 2;
4480 refcount
= get_refcount((IUnknown
*)device
);
4481 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
4482 ok(ptr
== (IUnknown
*)device
, "Got unexpected ptr %p, expected %p.\n", ptr
, device
);
4483 IUnknown_Release(ptr
);
4484 expected_refcount
--;
4486 ptr
= (IUnknown
*)0xdeadbeef;
4488 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, NULL
, &size
);
4489 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4490 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
4491 size
= 2 * sizeof(ptr
);
4492 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, NULL
, &size
);
4493 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4494 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
4495 refcount
= get_refcount((IUnknown
*)device
);
4496 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
4498 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, &ptr
, &size
);
4499 ok(hr
== D3DERR_MOREDATA
, "Got unexpected hr %#x.\n", hr
);
4500 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
4501 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
4502 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid2
, NULL
, NULL
);
4503 ok(hr
== D3DERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
4505 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid2
, &ptr
, &size
);
4506 ok(hr
== D3DERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
4507 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
4508 ok(size
== 0xdeadbabe, "Got unexpected size %u.\n", size
);
4509 /* GetPrivateData with size = NULL causes an access violation on Windows if the
4510 * requested data exists. */
4512 /* Destroying the surface frees the held reference. */
4513 IDirect3DSurface8_Release(surface
);
4514 expected_refcount
= refcount
- 2;
4515 refcount
= get_refcount((IUnknown
*)device
);
4516 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
4518 hr
= IDirect3DDevice8_CreateTexture(device
, 4, 4, 2, 0, D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &texture
);
4519 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
4520 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &surface
);
4521 ok(SUCCEEDED(hr
), "Failed to get texture level 0, hr %#x.\n", hr
);
4522 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 1, &surface2
);
4523 ok(SUCCEEDED(hr
), "Failed to get texture level 1, hr %#x.\n", hr
);
4525 hr
= IDirect3DTexture8_SetPrivateData(texture
, &d3d8_private_data_test_guid
, data
, sizeof(data
), 0);
4526 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
4528 memset(data
, 0, sizeof(data
));
4529 size
= sizeof(data
);
4530 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, data
, &size
);
4531 ok(hr
== D3DERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
4532 hr
= IDirect3DTexture8_GetPrivateData(texture
, &d3d8_private_data_test_guid
, data
, &size
);
4533 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
4534 ok(data
[0] == 1 && data
[1] == 2 && data
[2] == 3 && data
[3] == 4,
4535 "Got unexpected private data: %u, %u, %u, %u.\n", data
[0], data
[1], data
[2], data
[3]);
4537 hr
= IDirect3DTexture8_FreePrivateData(texture
, &d3d8_private_data_test_guid
);
4538 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
4540 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
, data
, sizeof(data
), 0);
4541 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
4542 hr
= IDirect3DSurface8_GetPrivateData(surface2
, &d3d8_private_data_test_guid
, data
, &size
);
4543 ok(hr
== D3DERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
4544 hr
= IDirect3DSurface8_FreePrivateData(surface
, &d3d8_private_data_test_guid
);
4545 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
4547 IDirect3DSurface8_Release(surface2
);
4548 IDirect3DSurface8_Release(surface
);
4549 IDirect3DTexture8_Release(texture
);
4551 refcount
= IDirect3DDevice8_Release(device
);
4552 ok(!refcount
, "Device has %u references left.\n", refcount
);
4553 IDirect3D8_Release(d3d8
);
4554 DestroyWindow(window
);
4557 static void test_surface_dimensions(void)
4559 IDirect3DSurface8
*surface
;
4560 IDirect3DDevice8
*device
;
4566 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4567 0, 0, 640, 480, 0, 0, 0, 0);
4568 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4569 ok(!!d3d8
, "Failed to create a D3D object.\n");
4570 if (!(device
= create_device(d3d8
, window
, NULL
)))
4572 skip("Failed to create a D3D device, skipping tests.\n");
4573 IDirect3D8_Release(d3d8
);
4574 DestroyWindow(window
);
4578 hr
= IDirect3DDevice8_CreateImageSurface(device
, 0, 1, D3DFMT_A8R8G8B8
, &surface
);
4579 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4580 hr
= IDirect3DDevice8_CreateImageSurface(device
, 1, 0, D3DFMT_A8R8G8B8
, &surface
);
4581 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4583 refcount
= IDirect3DDevice8_Release(device
);
4584 ok(!refcount
, "Device has %u references left.\n", refcount
);
4585 IDirect3D8_Release(d3d8
);
4586 DestroyWindow(window
);
4589 static void test_surface_format_null(void)
4591 static const D3DFORMAT D3DFMT_NULL
= MAKEFOURCC('N','U','L','L');
4592 IDirect3DTexture8
*texture
;
4593 IDirect3DSurface8
*surface
;
4594 IDirect3DSurface8
*rt
, *ds
;
4595 D3DLOCKED_RECT locked_rect
;
4596 IDirect3DDevice8
*device
;
4597 D3DSURFACE_DESC desc
;
4603 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
4604 ok(!!d3d
, "Failed to create a D3D object.\n");
4606 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
4607 D3DUSAGE_RENDERTARGET
, D3DRTYPE_SURFACE
, D3DFMT_NULL
);
4610 skip("No D3DFMT_NULL support, skipping test.\n");
4611 IDirect3D8_Release(d3d
);
4615 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4616 0, 0, 640, 480, 0, 0, 0, 0);
4617 if (!(device
= create_device(d3d
, window
, NULL
)))
4619 skip("Failed to create a D3D device, skipping tests.\n");
4620 IDirect3D8_Release(d3d
);
4621 DestroyWindow(window
);
4625 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
4626 D3DUSAGE_RENDERTARGET
, D3DRTYPE_TEXTURE
, D3DFMT_NULL
);
4627 ok(hr
== D3D_OK
, "D3DFMT_NULL should be supported for render target textures, hr %#x.\n", hr
);
4629 hr
= IDirect3D8_CheckDepthStencilMatch(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
4630 D3DFMT_NULL
, D3DFMT_D24S8
);
4631 ok(SUCCEEDED(hr
), "Depth stencil match failed for D3DFMT_NULL, hr %#x.\n", hr
);
4633 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 128, 128, D3DFMT_NULL
,
4634 D3DMULTISAMPLE_NONE
, TRUE
, &surface
);
4635 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
4637 hr
= IDirect3DDevice8_GetRenderTarget(device
, &rt
);
4638 ok(SUCCEEDED(hr
), "Failed to get original render target, hr %#x.\n", hr
);
4640 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &ds
);
4641 ok(SUCCEEDED(hr
), "Failed to get original depth/stencil, hr %#x.\n", hr
);
4643 hr
= IDirect3DDevice8_SetRenderTarget(device
, surface
, NULL
);
4644 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
4646 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00000000, 0.0f
, 0);
4647 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
4649 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, ds
);
4650 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
4652 IDirect3DSurface8_Release(rt
);
4653 IDirect3DSurface8_Release(ds
);
4655 hr
= IDirect3DSurface8_GetDesc(surface
, &desc
);
4656 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4657 ok(desc
.Width
== 128, "Expected width 128, got %u.\n", desc
.Width
);
4658 ok(desc
.Height
== 128, "Expected height 128, got %u.\n", desc
.Height
);
4660 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
4661 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4662 ok(locked_rect
.Pitch
, "Expected non-zero pitch, got %u.\n", locked_rect
.Pitch
);
4663 ok(!!locked_rect
.pBits
, "Expected non-NULL pBits, got %p.\n", locked_rect
.pBits
);
4665 hr
= IDirect3DSurface8_UnlockRect(surface
);
4666 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4668 IDirect3DSurface8_Release(surface
);
4670 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 0, D3DUSAGE_RENDERTARGET
,
4671 D3DFMT_NULL
, D3DPOOL_DEFAULT
, &texture
);
4672 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
4673 IDirect3DTexture8_Release(texture
);
4675 refcount
= IDirect3DDevice8_Release(device
);
4676 ok(!refcount
, "Device has %u references left.\n", refcount
);
4677 IDirect3D8_Release(d3d
);
4678 DestroyWindow(window
);
4681 static void test_surface_double_unlock(void)
4683 static const D3DPOOL pools
[] =
4688 IDirect3DSurface8
*surface
;
4689 IDirect3DDevice8
*device
;
4697 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4698 0, 0, 640, 480, 0, 0, 0, 0);
4699 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
4700 ok(!!d3d
, "Failed to create a D3D object.\n");
4701 if (!(device
= create_device(d3d
, window
, NULL
)))
4703 skip("Failed to create a D3D device, skipping tests.\n");
4704 IDirect3D8_Release(d3d
);
4705 DestroyWindow(window
);
4709 for (i
= 0; i
< (sizeof(pools
) / sizeof(*pools
)); ++i
)
4713 case D3DPOOL_DEFAULT
:
4714 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
4715 D3DUSAGE_RENDERTARGET
, D3DRTYPE_SURFACE
, D3DFMT_X8R8G8B8
);
4718 skip("D3DFMT_X8R8G8B8 render targets not supported, skipping double unlock DEFAULT pool test.\n");
4722 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 64, 64, D3DFMT_X8R8G8B8
,
4723 D3DMULTISAMPLE_NONE
, TRUE
, &surface
);
4724 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
4727 case D3DPOOL_SYSTEMMEM
:
4728 hr
= IDirect3DDevice8_CreateImageSurface(device
, 64, 64, D3DFMT_X8R8G8B8
, &surface
);
4729 ok(SUCCEEDED(hr
), "Failed to create image surface, hr %#x.\n", hr
);
4736 hr
= IDirect3DSurface8_UnlockRect(surface
);
4737 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, for surface in pool %#x.\n", hr
, pools
[i
]);
4738 hr
= IDirect3DSurface8_LockRect(surface
, &lr
, NULL
, 0);
4739 ok(SUCCEEDED(hr
), "Failed to lock surface in pool %#x, hr %#x.\n", pools
[i
], hr
);
4740 hr
= IDirect3DSurface8_UnlockRect(surface
);
4741 ok(SUCCEEDED(hr
), "Failed to unlock surface in pool %#x, hr %#x.\n", pools
[i
], hr
);
4742 hr
= IDirect3DSurface8_UnlockRect(surface
);
4743 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, for surface in pool %#x.\n", hr
, pools
[i
]);
4745 IDirect3DSurface8_Release(surface
);
4748 refcount
= IDirect3DDevice8_Release(device
);
4749 ok(!refcount
, "Device has %u references left.\n", refcount
);
4750 IDirect3D8_Release(d3d
);
4751 DestroyWindow(window
);
4754 static void test_surface_blocks(void)
4760 unsigned int block_width
;
4761 unsigned int block_height
;
4763 BOOL create_size_checked
, core_fmt
;
4767 {D3DFMT_DXT1
, "D3DFMT_DXT1", 4, 4, FALSE
, TRUE
, TRUE
},
4768 {D3DFMT_DXT2
, "D3DFMT_DXT2", 4, 4, FALSE
, TRUE
, TRUE
},
4769 {D3DFMT_DXT3
, "D3DFMT_DXT3", 4, 4, FALSE
, TRUE
, TRUE
},
4770 {D3DFMT_DXT4
, "D3DFMT_DXT4", 4, 4, FALSE
, TRUE
, TRUE
},
4771 {D3DFMT_DXT5
, "D3DFMT_DXT5", 4, 4, FALSE
, TRUE
, TRUE
},
4772 /* ATI1N and ATI2N have 2x2 blocks on all AMD cards and Geforce 7 cards,
4773 * which doesn't match the format spec. On newer Nvidia cards
4774 * they have the correct 4x4 block size */
4775 {MAKEFOURCC('A','T','I','1'), "ATI1N", 4, 4, TRUE
, FALSE
, FALSE
},
4776 {MAKEFOURCC('A','T','I','2'), "ATI2N", 4, 4, TRUE
, FALSE
, FALSE
},
4777 /* Windows drivers generally enforce block-aligned locks for
4778 * YUY2 and UYVY. The notable exception is the AMD r500 driver
4779 * in d3d8. The same driver checks the sizes in d3d9. */
4780 {D3DFMT_YUY2
, "D3DFMT_YUY2", 2, 1, TRUE
, FALSE
, TRUE
},
4781 {D3DFMT_UYVY
, "D3DFMT_UYVY", 2, 1, TRUE
, FALSE
, TRUE
},
4787 /* Don't check the return value, Nvidia returns D3DERR_INVALIDCALL for some formats
4788 * and E_INVALIDARG/DDERR_INVALIDPARAMS for others. */
4793 {D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", FALSE
},
4794 {D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", TRUE
},
4795 {D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM",TRUE
},
4796 {D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
},
4800 D3DRESOURCETYPE rtype
;
4801 const char *type_name
;
4803 const char *pool_name
;
4804 BOOL need_driver_support
, need_runtime_support
;
4808 /* D3d8 only supports sysmem surfaces, which are created via CreateImageSurface. Other tests confirm
4809 * that they are D3DPOOL_SYSTEMMEM surfaces, but their creation restriction behaves like the scratch
4811 {D3DRTYPE_SURFACE
, "D3DRTYPE_SURFACE", D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", FALSE
, TRUE
},
4813 {D3DRTYPE_TEXTURE
, "D3DRTYPE_TEXTURE", D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", TRUE
, FALSE
},
4814 {D3DRTYPE_TEXTURE
, "D3DRTYPE_TEXTURE", D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", TRUE
, FALSE
},
4815 {D3DRTYPE_TEXTURE
, "D3DRTYPE_TEXTURE", D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
, FALSE
},
4816 {D3DRTYPE_TEXTURE
, "D3DRTYPE_TEXTURE", D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", FALSE
, TRUE
},
4818 {D3DRTYPE_CUBETEXTURE
, "D3DRTYPE_CUBETEXTURE", D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", TRUE
, FALSE
},
4819 {D3DRTYPE_CUBETEXTURE
, "D3DRTYPE_CUBETEXTURE", D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", TRUE
, FALSE
},
4820 {D3DRTYPE_CUBETEXTURE
, "D3DRTYPE_CUBETEXTURE", D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
, FALSE
},
4821 {D3DRTYPE_CUBETEXTURE
, "D3DRTYPE_CUBETEXTURE", D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", FALSE
, TRUE
},
4823 IDirect3DTexture8
*texture
;
4824 IDirect3DCubeTexture8
*cube_texture
;
4825 IDirect3DSurface8
*surface
;
4826 D3DLOCKED_RECT locked_rect
;
4827 IDirect3DDevice8
*device
;
4828 unsigned int i
, j
, w
, h
;
4834 BOOL tex_pow2
, cube_pow2
;
4837 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4838 0, 0, 640, 480, 0, 0, 0, 0);
4839 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
4840 ok(!!d3d
, "Failed to create a D3D object.\n");
4841 if (!(device
= create_device(d3d
, window
, NULL
)))
4843 skip("Failed to create a D3D device, skipping tests.\n");
4844 IDirect3D8_Release(d3d
);
4845 DestroyWindow(window
);
4849 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
4850 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
4851 tex_pow2
= caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
;
4853 tex_pow2
= !(caps
.TextureCaps
& D3DPTEXTURECAPS_NONPOW2CONDITIONAL
);
4854 cube_pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP_POW2
);
4856 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
4858 BOOL tex_support
, cube_support
, surface_support
, format_known
;
4860 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
4861 0, D3DRTYPE_TEXTURE
, formats
[i
].fmt
);
4862 tex_support
= SUCCEEDED(hr
);
4863 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
4864 0, D3DRTYPE_CUBETEXTURE
, formats
[i
].fmt
);
4865 cube_support
= SUCCEEDED(hr
);
4866 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
4867 0, D3DRTYPE_SURFACE
, formats
[i
].fmt
);
4868 surface_support
= SUCCEEDED(hr
);
4870 /* Scratch pool in general allows texture creation even if the driver does
4871 * not support the format. If the format is an extension format that is not
4872 * known to the runtime, like ATI2N, some driver support is required for
4875 * It is also possible that Windows Vista and Windows 7 d3d8 runtimes know
4876 * about ATI2N. I cannot check this because all my Vista+ machines support
4877 * ATI2N in hardware, but none of my WinXP machines do. */
4878 format_known
= tex_support
|| cube_support
|| surface_support
;
4880 for (w
= 1; w
<= 8; w
++)
4882 for (h
= 1; h
<= 8; h
++)
4884 BOOL block_aligned
= TRUE
;
4887 if (w
& (formats
[i
].block_width
- 1) || h
& (formats
[i
].block_height
- 1))
4888 block_aligned
= FALSE
;
4890 size_is_pow2
= !(w
& (w
- 1) || h
& (h
- 1));
4892 for (j
= 0; j
< sizeof(create_tests
) / sizeof(*create_tests
); j
++)
4896 BOOL may_succeed
= FALSE
;
4897 IUnknown
**check_null
;
4899 if (!formats
[i
].core_fmt
)
4901 /* AMD warns against creating ATI2N textures smaller than
4902 * the block size because the runtime cannot calculate the
4903 * correct texture size. Generalize this for all extension
4905 if (w
< formats
[i
].block_width
|| h
< formats
[i
].block_height
)
4909 texture
= (IDirect3DTexture8
*)0xdeadbeef;
4910 cube_texture
= (IDirect3DCubeTexture8
*)0xdeadbeef;
4911 surface
= (IDirect3DSurface8
*)0xdeadbeef;
4913 switch (create_tests
[j
].rtype
)
4915 case D3DRTYPE_TEXTURE
:
4916 check_null
= (IUnknown
**)&texture
;
4917 hr
= IDirect3DDevice8_CreateTexture(device
, w
, h
, 1, 0,
4918 formats
[i
].fmt
, create_tests
[j
].pool
, &texture
);
4919 support
= tex_support
;
4923 case D3DRTYPE_CUBETEXTURE
:
4926 check_null
= (IUnknown
**)&cube_texture
;
4927 hr
= IDirect3DDevice8_CreateCubeTexture(device
, w
, 1, 0,
4928 formats
[i
].fmt
, create_tests
[j
].pool
, &cube_texture
);
4929 support
= cube_support
;
4933 case D3DRTYPE_SURFACE
:
4934 check_null
= (IUnknown
**)&surface
;
4935 hr
= IDirect3DDevice8_CreateImageSurface(device
, w
, h
,
4936 formats
[i
].fmt
, &surface
);
4937 support
= surface_support
;
4948 if (create_tests
[j
].need_driver_support
&& !support
)
4949 expect_hr
= D3DERR_INVALIDCALL
;
4950 else if (create_tests
[j
].need_runtime_support
&& !formats
[i
].core_fmt
&& !format_known
)
4951 expect_hr
= D3DERR_INVALIDCALL
;
4952 else if (formats
[i
].create_size_checked
&& !block_aligned
)
4953 expect_hr
= D3DERR_INVALIDCALL
;
4954 else if (pow2
&& !size_is_pow2
&& create_tests
[j
].need_driver_support
)
4955 expect_hr
= D3DERR_INVALIDCALL
;
4959 if (!formats
[i
].core_fmt
&& !format_known
&& FAILED(expect_hr
))
4962 /* Wine knows about ATI2N and happily creates a scratch resource even if GL
4963 * does not support it. Accept scratch creation of extension formats on
4964 * Windows as well if it occurs. We don't really care if e.g. a Windows 7
4965 * on an r200 GPU creates scratch ATI2N texture even though the card doesn't
4967 ok(hr
== expect_hr
|| ((SUCCEEDED(hr
) && may_succeed
)),
4968 "Got unexpected hr %#x for format %s, pool %s, type %s, size %ux%u.\n",
4969 hr
, formats
[i
].name
, create_tests
[j
].pool_name
, create_tests
[j
].type_name
, w
, h
);
4972 ok(*check_null
== NULL
, "Got object ptr %p, expected NULL.\n", *check_null
);
4974 IUnknown_Release(*check_null
);
4979 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
4980 D3DUSAGE_DYNAMIC
, D3DRTYPE_TEXTURE
, formats
[i
].fmt
);
4983 skip("Format %s not supported, skipping lockrect offset tests.\n", formats
[i
].name
);
4987 for (j
= 0; j
< (sizeof(pools
) / sizeof(*pools
)); ++j
)
4989 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1,
4990 pools
[j
].pool
== D3DPOOL_DEFAULT
? D3DUSAGE_DYNAMIC
: 0,
4991 formats
[i
].fmt
, pools
[j
].pool
, &texture
);
4992 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
4993 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &surface
);
4994 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
4995 IDirect3DTexture8_Release(texture
);
4997 if (formats
[i
].block_width
> 1)
4999 SetRect(&rect
, formats
[i
].block_width
>> 1, 0, formats
[i
].block_width
, formats
[i
].block_height
);
5000 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &rect
, 0);
5001 ok(FAILED(hr
) == !pools
[j
].success
|| broken(formats
[i
].broken
),
5002 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5003 SUCCEEDED(hr
) ? "succeeded" : "failed",
5004 pools
[j
].success
? "success" : "failure", formats
[i
].name
, pools
[j
].name
);
5007 hr
= IDirect3DSurface8_UnlockRect(surface
);
5008 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5011 SetRect(&rect
, 0, 0, formats
[i
].block_width
>> 1, formats
[i
].block_height
);
5012 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &rect
, 0);
5013 ok(FAILED(hr
) == !pools
[j
].success
|| broken(formats
[i
].broken
),
5014 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5015 SUCCEEDED(hr
) ? "succeeded" : "failed",
5016 pools
[j
].success
? "success" : "failure", formats
[i
].name
, pools
[j
].name
);
5019 hr
= IDirect3DSurface8_UnlockRect(surface
);
5020 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5024 if (formats
[i
].block_height
> 1)
5026 SetRect(&rect
, 0, formats
[i
].block_height
>> 1, formats
[i
].block_width
, formats
[i
].block_height
);
5027 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &rect
, 0);
5028 ok(FAILED(hr
) == !pools
[j
].success
|| broken(formats
[i
].broken
),
5029 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5030 SUCCEEDED(hr
) ? "succeeded" : "failed",
5031 pools
[j
].success
? "success" : "failure", formats
[i
].name
, pools
[j
].name
);
5034 hr
= IDirect3DSurface8_UnlockRect(surface
);
5035 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5038 SetRect(&rect
, 0, 0, formats
[i
].block_width
, formats
[i
].block_height
>> 1);
5039 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &rect
, 0);
5040 ok(FAILED(hr
) == !pools
[j
].success
|| broken(formats
[i
].broken
),
5041 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5042 SUCCEEDED(hr
) ? "succeeded" : "failed",
5043 pools
[j
].success
? "success" : "failure", formats
[i
].name
, pools
[j
].name
);
5046 hr
= IDirect3DSurface8_UnlockRect(surface
);
5047 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5051 SetRect(&rect
, 0, 0, formats
[i
].block_width
, formats
[i
].block_height
);
5052 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &rect
, 0);
5053 ok(hr
== D3D_OK
, "Got unexpected hr %#x for format %s, pool %s.\n", hr
, formats
[i
].name
, pools
[j
].name
);
5054 hr
= IDirect3DSurface8_UnlockRect(surface
);
5055 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5057 IDirect3DSurface8_Release(surface
);
5060 if (formats
[i
].block_width
== 1 && formats
[i
].block_height
== 1)
5062 if (!formats
[i
].core_fmt
)
5065 hr
= IDirect3DDevice8_CreateTexture(device
, formats
[i
].block_width
, formats
[i
].block_height
, 2,
5066 D3DUSAGE_DYNAMIC
, formats
[i
].fmt
, D3DPOOL_DEFAULT
, &texture
);
5067 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x, format %s.\n", hr
, formats
[i
].name
);
5069 hr
= IDirect3DTexture8_LockRect(texture
, 1, &locked_rect
, NULL
, 0);
5070 ok(SUCCEEDED(hr
), "Failed lock texture, hr %#x.\n", hr
);
5071 hr
= IDirect3DTexture8_UnlockRect(texture
, 1);
5072 ok(SUCCEEDED(hr
), "Failed lock texture, hr %#x.\n", hr
);
5076 rect
.right
= formats
[i
].block_width
== 1 ? 1 : formats
[i
].block_width
>> 1;
5077 rect
.bottom
= formats
[i
].block_height
== 1 ? 1 : formats
[i
].block_height
>> 1;
5078 hr
= IDirect3DTexture8_LockRect(texture
, 1, &locked_rect
, &rect
, 0);
5079 ok(SUCCEEDED(hr
), "Failed lock texture, hr %#x.\n", hr
);
5080 hr
= IDirect3DTexture8_UnlockRect(texture
, 1);
5081 ok(SUCCEEDED(hr
), "Failed lock texture, hr %#x.\n", hr
);
5083 rect
.right
= formats
[i
].block_width
;
5084 rect
.bottom
= formats
[i
].block_height
;
5085 hr
= IDirect3DTexture8_LockRect(texture
, 1, &locked_rect
, &rect
, 0);
5086 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5088 IDirect3DTexture8_UnlockRect(texture
, 1);
5090 IDirect3DTexture8_Release(texture
);
5093 refcount
= IDirect3DDevice8_Release(device
);
5094 ok(!refcount
, "Device has %u references left.\n", refcount
);
5095 IDirect3D8_Release(d3d
);
5096 DestroyWindow(window
);
5099 static void test_set_palette(void)
5101 IDirect3DDevice8
*device
;
5106 PALETTEENTRY pal
[256];
5110 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
5111 0, 0, 640, 480, 0, 0, 0, 0);
5112 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
5113 ok(!!d3d8
, "Failed to create a D3D object.\n");
5114 if (!(device
= create_device(d3d8
, window
, NULL
)))
5116 skip("Failed to create a D3D device, skipping tests.\n");
5117 IDirect3D8_Release(d3d8
);
5118 DestroyWindow(window
);
5122 for (i
= 0; i
< sizeof(pal
) / sizeof(*pal
); i
++)
5127 pal
[i
].peFlags
= 0xff;
5129 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 0, pal
);
5130 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
5132 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
5133 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
5134 for (i
= 0; i
< sizeof(pal
) / sizeof(*pal
); i
++)
5141 if (caps
.TextureCaps
& D3DPTEXTURECAPS_ALPHAPALETTE
)
5143 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 0, pal
);
5144 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
5148 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 0, pal
);
5149 ok(hr
== D3DERR_INVALIDCALL
, "SetPaletteEntries returned %#x, expected D3DERR_INVALIDCALL.\n", hr
);
5152 refcount
= IDirect3DDevice8_Release(device
);
5153 ok(!refcount
, "Device has %u references left.\n", refcount
);
5154 IDirect3D8_Release(d3d8
);
5155 DestroyWindow(window
);
5158 static void test_swvp_buffer(void)
5160 IDirect3DDevice8
*device
;
5166 IDirect3DVertexBuffer8
*buffer
;
5167 static const unsigned int bufsize
= 1024;
5168 D3DVERTEXBUFFER_DESC desc
;
5169 struct device_desc device_desc
;
5175 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
5176 0, 0, 640, 480, 0, 0, 0, 0);
5177 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
5178 ok(!!d3d8
, "Failed to create a D3D object.\n");
5180 device_desc
.device_window
= window
;
5181 device_desc
.width
= 640;
5182 device_desc
.height
= 480;
5183 device_desc
.flags
= CREATE_DEVICE_SWVP_ONLY
;
5184 if (!(device
= create_device(d3d8
, window
, &device_desc
)))
5186 skip("Failed to create a D3D device, skipping tests.\n");
5187 IDirect3D8_Release(d3d8
);
5188 DestroyWindow(window
);
5192 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, bufsize
* sizeof(*ptr
), D3DUSAGE_DYNAMIC
| D3DUSAGE_WRITEONLY
, 0,
5193 D3DPOOL_DEFAULT
, &buffer
);
5194 ok(SUCCEEDED(hr
), "Failed to create buffer, hr %#x.\n", hr
);
5195 hr
= IDirect3DVertexBuffer8_GetDesc(buffer
, &desc
);
5196 ok(SUCCEEDED(hr
), "Failed to get desc, hr %#x.\n", hr
);
5197 ok(desc
.Pool
== D3DPOOL_DEFAULT
, "Got pool %u, expected D3DPOOL_DEFAULT\n", desc
.Pool
);
5198 ok(desc
.Usage
== (D3DUSAGE_DYNAMIC
| D3DUSAGE_WRITEONLY
),
5199 "Got usage %u, expected D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY\n", desc
.Usage
);
5201 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, bufsize
* sizeof(*ptr
), (BYTE
**)&ptr
, D3DLOCK_DISCARD
);
5202 ok(SUCCEEDED(hr
), "Failed to lock buffer, hr %#x.\n", hr
);
5203 for (i
= 0; i
< bufsize
; i
++)
5205 ptr
[i
].x
= i
* 1.0f
;
5206 ptr
[i
].y
= i
* 2.0f
;
5207 ptr
[i
].z
= i
* 3.0f
;
5209 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
5210 ok(SUCCEEDED(hr
), "Failed to unlock buffer, hr %#x.\n", hr
);
5212 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
);
5213 ok(SUCCEEDED(hr
), "Failed to set fvf, hr %#x.\n", hr
);
5214 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, buffer
, sizeof(*ptr
));
5215 ok(SUCCEEDED(hr
), "Failed to set stream source, hr %#x.\n", hr
);
5216 hr
= IDirect3DDevice8_BeginScene(device
);
5217 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
5218 hr
= IDirect3DDevice8_DrawPrimitive(device
, D3DPT_TRIANGLELIST
, 0, 2);
5219 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
5220 hr
= IDirect3DDevice8_EndScene(device
);
5221 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
5223 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, bufsize
* sizeof(*ptr2
), (BYTE
**)&ptr2
, D3DLOCK_DISCARD
);
5224 ok(SUCCEEDED(hr
), "Failed to lock buffer, hr %#x.\n", hr
);
5225 ok(ptr
== ptr2
, "Lock returned two different pointers: %p, %p\n", ptr
, ptr2
);
5226 for (i
= 0; i
< bufsize
; i
++)
5228 if (ptr2
[i
].x
!= i
* 1.0f
|| ptr2
[i
].y
!= i
* 2.0f
|| ptr2
[i
].z
!= i
* 3.0f
)
5230 ok(FALSE
, "Vertex %u is %f,%f,%f, expected %f,%f,%f\n", i
,
5231 ptr2
[i
].x
, ptr2
[i
].y
, ptr2
[i
].z
, i
* 1.0f
, i
* 2.0f
, i
* 3.0f
);
5235 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
5236 ok(SUCCEEDED(hr
), "Failed to unlock buffer, hr %#x.\n", hr
);
5238 IDirect3DVertexBuffer8_Release(buffer
);
5239 refcount
= IDirect3DDevice8_Release(device
);
5240 ok(!refcount
, "Device has %u references left.\n", refcount
);
5241 IDirect3D8_Release(d3d8
);
5242 DestroyWindow(window
);
5245 static void test_npot_textures(void)
5247 IDirect3DDevice8
*device
= NULL
;
5253 IDirect3DTexture8
*texture
;
5254 IDirect3DCubeTexture8
*cube_texture
;
5255 IDirect3DVolumeTexture8
*volume_texture
;
5259 const char *pool_name
;
5264 { D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", D3DERR_INVALIDCALL
},
5265 { D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", D3DERR_INVALIDCALL
},
5266 { D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", D3DERR_INVALIDCALL
},
5267 { D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", D3D_OK
},
5269 unsigned int i
, levels
;
5270 BOOL tex_pow2
, cube_pow2
, vol_pow2
;
5272 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
5273 0, 0, 640, 480, 0, 0, 0, 0);
5274 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
5275 ok(!!d3d8
, "Failed to create a D3D object.\n");
5276 if (!(device
= create_device(d3d8
, window
, NULL
)))
5278 skip("Failed to create a D3D device, skipping tests.\n");
5282 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
5283 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
5284 tex_pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
);
5285 cube_pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP_POW2
);
5286 vol_pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP_POW2
);
5287 ok(cube_pow2
== tex_pow2
, "Cube texture and 2d texture pow2 restrictions mismatch.\n");
5288 ok(vol_pow2
== tex_pow2
, "Volume texture and 2d texture pow2 restrictions mismatch.\n");
5290 for (i
= 0; i
< sizeof(pools
) / sizeof(*pools
); i
++)
5292 for (levels
= 0; levels
<= 2; levels
++)
5296 hr
= IDirect3DDevice8_CreateTexture(device
, 10, 10, levels
, 0, D3DFMT_X8R8G8B8
,
5297 pools
[i
].pool
, &texture
);
5302 else if (caps
.TextureCaps
& D3DPTEXTURECAPS_NONPOW2CONDITIONAL
)
5307 expected
= pools
[i
].hr
;
5311 expected
= pools
[i
].hr
;
5313 ok(hr
== expected
, "CreateTexture(w=h=10, %s, levels=%u) returned hr %#x, expected %#x.\n",
5314 pools
[i
].pool_name
, levels
, hr
, expected
);
5317 IDirect3DTexture8_Release(texture
);
5320 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 3, 1, 0, D3DFMT_X8R8G8B8
,
5321 pools
[i
].pool
, &cube_texture
);
5324 ok(hr
== pools
[i
].hr
, "CreateCubeTexture(EdgeLength=3, %s) returned hr %#x, expected %#x.\n",
5325 pools
[i
].pool_name
, hr
, pools
[i
].hr
);
5329 ok(SUCCEEDED(hr
), "CreateCubeTexture(EdgeLength=3, %s) returned hr %#x, expected %#x.\n",
5330 pools
[i
].pool_name
, hr
, D3D_OK
);
5334 IDirect3DCubeTexture8_Release(cube_texture
);
5336 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 2, 2, 3, 1, 0, D3DFMT_X8R8G8B8
,
5337 pools
[i
].pool
, &volume_texture
);
5340 ok(hr
== pools
[i
].hr
, "CreateVolumeTextur(Depth=3, %s) returned hr %#x, expected %#x.\n",
5341 pools
[i
].pool_name
, hr
, pools
[i
].hr
);
5345 ok(SUCCEEDED(hr
), "CreateVolumeTextur(Depth=3, %s) returned hr %#x, expected %#x.\n",
5346 pools
[i
].pool_name
, hr
, D3D_OK
);
5350 IDirect3DVolumeTexture8_Release(volume_texture
);
5356 refcount
= IDirect3DDevice8_Release(device
);
5357 ok(!refcount
, "Device has %u references left.\n", refcount
);
5359 IDirect3D8_Release(d3d8
);
5360 DestroyWindow(window
);
5364 static void test_volume_locking(void)
5366 IDirect3DDevice8
*device
;
5370 IDirect3DVolumeTexture8
*texture
;
5372 D3DLOCKED_BOX locked_box
;
5379 HRESULT create_hr
, lock_hr
;
5383 { D3DPOOL_DEFAULT
, 0, D3D_OK
, D3DERR_INVALIDCALL
},
5384 { D3DPOOL_DEFAULT
, D3DUSAGE_DYNAMIC
, D3D_OK
, D3D_OK
},
5385 { D3DPOOL_SYSTEMMEM
, 0, D3D_OK
, D3D_OK
},
5386 { D3DPOOL_SYSTEMMEM
, D3DUSAGE_DYNAMIC
, D3D_OK
, D3D_OK
},
5387 { D3DPOOL_MANAGED
, 0, D3D_OK
, D3D_OK
},
5388 { D3DPOOL_MANAGED
, D3DUSAGE_DYNAMIC
, D3DERR_INVALIDCALL
, D3D_OK
},
5389 { D3DPOOL_SCRATCH
, 0, D3D_OK
, D3D_OK
},
5390 { D3DPOOL_SCRATCH
, D3DUSAGE_DYNAMIC
, D3DERR_INVALIDCALL
, D3D_OK
},
5393 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
5394 0, 0, 640, 480, 0, 0, 0, 0);
5395 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
5396 ok(!!d3d8
, "Failed to create a D3D object.\n");
5397 if (!(device
= create_device(d3d8
, window
, NULL
)))
5399 skip("Failed to create a D3D device, skipping tests.\n");
5400 IDirect3D8_Release(d3d8
);
5401 DestroyWindow(window
);
5405 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
5406 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
5407 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
))
5409 skip("Volume textures not supported, skipping test.\n");
5413 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
5415 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 4, 4, 4, 1, tests
[i
].usage
,
5416 D3DFMT_A8R8G8B8
, tests
[i
].pool
, &texture
);
5417 ok(hr
== tests
[i
].create_hr
, "Creating volume texture pool=%u, usage=%#x returned %#x, expected %#x.\n",
5418 tests
[i
].pool
, tests
[i
].usage
, hr
, tests
[i
].create_hr
);
5422 locked_box
.pBits
= (void *)0xdeadbeef;
5423 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, NULL
, 0);
5424 ok(hr
== tests
[i
].lock_hr
, "Lock returned %#x, expected %#x.\n", hr
, tests
[i
].lock_hr
);
5427 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
5428 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
5432 ok (locked_box
.pBits
== NULL
, "Failed lock set pBits = %p, expected NULL.\n", locked_box
.pBits
);
5434 IDirect3DVolumeTexture8_Release(texture
);
5438 refcount
= IDirect3DDevice8_Release(device
);
5439 ok(!refcount
, "Device has %u references left.\n", refcount
);
5440 IDirect3D8_Release(d3d8
);
5441 DestroyWindow(window
);
5444 static void test_update_volumetexture(void)
5446 IDirect3DDevice8
*device
;
5450 IDirect3DVolumeTexture8
*src
, *dst
;
5452 D3DLOCKED_BOX locked_box
;
5457 D3DPOOL src_pool
, dst_pool
;
5462 { D3DPOOL_DEFAULT
, D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
},
5463 { D3DPOOL_MANAGED
, D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
},
5464 { D3DPOOL_SYSTEMMEM
, D3DPOOL_DEFAULT
, D3D_OK
},
5465 { D3DPOOL_SCRATCH
, D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
},
5467 { D3DPOOL_DEFAULT
, D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
},
5468 { D3DPOOL_MANAGED
, D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
},
5469 { D3DPOOL_SYSTEMMEM
, D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
},
5470 { D3DPOOL_SCRATCH
, D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
},
5472 { D3DPOOL_DEFAULT
, D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
},
5473 { D3DPOOL_MANAGED
, D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
},
5474 { D3DPOOL_SYSTEMMEM
, D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
},
5475 { D3DPOOL_SCRATCH
, D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
},
5477 { D3DPOOL_DEFAULT
, D3DPOOL_SCRATCH
, D3DERR_INVALIDCALL
},
5478 { D3DPOOL_MANAGED
, D3DPOOL_SCRATCH
, D3DERR_INVALIDCALL
},
5479 { D3DPOOL_SYSTEMMEM
, D3DPOOL_SCRATCH
, D3DERR_INVALIDCALL
},
5480 { D3DPOOL_SCRATCH
, D3DPOOL_SCRATCH
, D3DERR_INVALIDCALL
},
5484 UINT src_size
, dst_size
;
5485 UINT src_lvl
, dst_lvl
;
5486 D3DFORMAT src_fmt
, dst_fmt
;
5490 { 8, 8, 0, 0, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
5491 { 8, 8, 4, 4, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
5492 { 8, 8, 2, 2, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
5493 { 8, 8, 1, 1, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
5494 { 8, 8, 4, 0, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
5495 { 8, 8, 1, 4, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
}, /* Different level count */
5496 { 4, 8, 1, 1, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
}, /* Different size */
5497 { 8, 8, 4, 4, D3DFMT_A8R8G8B8
, D3DFMT_X8R8G8B8
}, /* Different format */
5500 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
5501 0, 0, 640, 480, 0, 0, 0, 0);
5502 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
5503 ok(!!d3d8
, "Failed to create a D3D object.\n");
5504 if (!(device
= create_device(d3d8
, window
, NULL
)))
5506 skip("Failed to create a D3D device, skipping tests.\n");
5507 IDirect3D8_Release(d3d8
);
5508 DestroyWindow(window
);
5512 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
5513 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
5514 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
))
5516 skip("Volume textures not supported, skipping test.\n");
5520 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
5522 DWORD src_usage
= tests
[i
].src_pool
== D3DPOOL_DEFAULT
? D3DUSAGE_DYNAMIC
: 0;
5523 DWORD dst_usage
= tests
[i
].dst_pool
== D3DPOOL_DEFAULT
? D3DUSAGE_DYNAMIC
: 0;
5525 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 1, 1, 1, 1, src_usage
,
5526 D3DFMT_A8R8G8B8
, tests
[i
].src_pool
, &src
);
5527 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
5528 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 1, 1, 1, 1, dst_usage
,
5529 D3DFMT_A8R8G8B8
, tests
[i
].dst_pool
, &dst
);
5530 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
5532 hr
= IDirect3DVolumeTexture8_LockBox(src
, 0, &locked_box
, NULL
, 0);
5533 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
5534 *((DWORD
*)locked_box
.pBits
) = 0x11223344;
5535 hr
= IDirect3DVolumeTexture8_UnlockBox(src
, 0);
5536 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
5538 hr
= IDirect3DDevice8_UpdateTexture(device
, (IDirect3DBaseTexture8
*)src
, (IDirect3DBaseTexture8
*)dst
);
5539 ok(hr
== tests
[i
].hr
, "UpdateTexture returned %#x, expected %#x, src pool %x, dst pool %u.\n",
5540 hr
, tests
[i
].hr
, tests
[i
].src_pool
, tests
[i
].dst_pool
);
5544 DWORD content
= *((DWORD
*)locked_box
.pBits
);
5545 hr
= IDirect3DVolumeTexture8_LockBox(dst
, 0, &locked_box
, NULL
, 0);
5546 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
5547 ok(content
== 0x11223344, "Dest texture contained %#x, expected 0x11223344.\n", content
);
5548 hr
= IDirect3DVolumeTexture8_UnlockBox(dst
, 0);
5549 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
5551 IDirect3DVolumeTexture8_Release(src
);
5552 IDirect3DVolumeTexture8_Release(dst
);
5555 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_MIPVOLUMEMAP
))
5557 skip("Mipmapped volume maps not supported.\n");
5561 for (i
= 0; i
< sizeof(tests2
) / sizeof(*tests2
); i
++)
5563 hr
= IDirect3DDevice8_CreateVolumeTexture(device
,
5564 tests2
[i
].src_size
, tests2
[i
].src_size
, tests2
[i
].src_size
,
5565 tests2
[i
].src_lvl
, 0, tests2
[i
].src_fmt
, D3DPOOL_SYSTEMMEM
, &src
);
5566 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x, case %u.\n", hr
, i
);
5567 hr
= IDirect3DDevice8_CreateVolumeTexture(device
,
5568 tests2
[i
].dst_size
, tests2
[i
].dst_size
, tests2
[i
].dst_size
,
5569 tests2
[i
].dst_lvl
, 0, tests2
[i
].dst_fmt
, D3DPOOL_DEFAULT
, &dst
);
5570 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x, case %u.\n", hr
, i
);
5572 hr
= IDirect3DDevice8_UpdateTexture(device
, (IDirect3DBaseTexture8
*)src
, (IDirect3DBaseTexture8
*)dst
);
5574 todo_wine
ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x, case %u.\n", hr
, i
);
5576 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x, case %u.\n", hr
, i
);
5578 IDirect3DVolumeTexture8_Release(src
);
5579 IDirect3DVolumeTexture8_Release(dst
);
5582 /* As far as I can see, UpdateTexture on non-matching texture behaves like a memcpy. The raw data
5583 * stays the same in a format change, a 2x2x1 texture is copied into the first row of a 4x4x1 texture,
5584 * etc. I could not get it to segfault, but the nonexistent 5th pixel of a 2x2x1 texture is copied into
5585 * pixel 1x2x1 of a 4x4x1 texture, demonstrating a read beyond the texture's end. I suspect any bad
5586 * memory access is silently ignored by the runtime, in the kernel or on the GPU.
5588 * I'm not adding tests for this behavior until an application needs it. */
5591 refcount
= IDirect3DDevice8_Release(device
);
5592 ok(!refcount
, "Device has %u references left.\n", refcount
);
5593 IDirect3D8_Release(d3d8
);
5594 DestroyWindow(window
);
5597 static void test_create_rt_ds_fail(void)
5599 IDirect3DDevice8
*device
;
5604 IDirect3DSurface8
*surface
;
5606 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
5607 0, 0, 640, 480, 0, 0, 0, 0);
5608 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
5609 ok(!!d3d8
, "Failed to create a D3D object.\n");
5610 if (!(device
= create_device(d3d8
, window
, NULL
)))
5612 skip("Failed to create a D3D device, skipping tests.\n");
5613 IDirect3D8_Release(d3d8
);
5614 DestroyWindow(window
);
5618 /* Output pointer == NULL segfaults on Windows. */
5620 surface
= (IDirect3DSurface8
*)0xdeadbeef;
5621 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 4, 4, D3DFMT_D16
,
5622 D3DMULTISAMPLE_NONE
, FALSE
, &surface
);
5623 ok(hr
== D3DERR_INVALIDCALL
, "Creating a D16 render target returned hr %#x.\n", hr
);
5624 ok(surface
== NULL
, "Got pointer %p, expected NULL.\n", surface
);
5626 IDirect3DSurface8_Release(surface
);
5628 surface
= (IDirect3DSurface8
*)0xdeadbeef;
5629 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 4, 4, D3DFMT_A8R8G8B8
,
5630 D3DMULTISAMPLE_NONE
, &surface
);
5631 ok(hr
== D3DERR_INVALIDCALL
, "Creating a A8R8G8B8 depth stencil returned hr %#x.\n", hr
);
5632 ok(surface
== NULL
, "Got pointer %p, expected NULL.\n", surface
);
5634 IDirect3DSurface8_Release(surface
);
5636 refcount
= IDirect3DDevice8_Release(device
);
5637 ok(!refcount
, "Device has %u references left.\n", refcount
);
5638 IDirect3D8_Release(d3d8
);
5639 DestroyWindow(window
);
5642 static void test_volume_blocks(void)
5644 IDirect3DDevice8
*device
;
5650 IDirect3DVolumeTexture8
*texture
;
5651 unsigned int w
, h
, d
, i
, j
;
5656 unsigned int block_width
;
5657 unsigned int block_height
;
5658 unsigned int block_depth
;
5659 unsigned int block_size
;
5660 unsigned int broken
;
5661 BOOL create_size_checked
, core_fmt
;
5665 /* Scratch volumes enforce DXTn block locks, unlike their surface counterparts.
5666 * ATI2N and YUV blocks are not enforced on any tested card (r200, gtx 460). */
5667 {D3DFMT_DXT1
, "D3DFMT_DXT1", 4, 4, 1, 8, 0, TRUE
, TRUE
},
5668 {D3DFMT_DXT2
, "D3DFMT_DXT2", 4, 4, 1, 16, 0, TRUE
, TRUE
},
5669 {D3DFMT_DXT3
, "D3DFMT_DXT3", 4, 4, 1, 16, 0, TRUE
, TRUE
},
5670 {D3DFMT_DXT4
, "D3DFMT_DXT4", 4, 4, 1, 16, 0, TRUE
, TRUE
},
5671 {D3DFMT_DXT5
, "D3DFMT_DXT5", 4, 4, 1, 16, 0, TRUE
, TRUE
},
5672 {D3DFMT_DXT5
, "D3DFMT_DXT5", 4, 4, 1, 16, 0, TRUE
, TRUE
},
5673 /* ATI2N has 2x2 blocks on all AMD cards and Geforce 7 cards,
5674 * which doesn't match the format spec. On newer Nvidia cards
5675 * it has the correct 4x4 block size.
5676 * ATI1N volume textures are only supported by AMD GPUs right
5677 * now and locking offsets seem just wrong. */
5678 {MAKEFOURCC('A','T','I','1'), "ATI1N", 4, 4, 1, 8, 2, FALSE
, FALSE
},
5679 {MAKEFOURCC('A','T','I','2'), "ATI2N", 4, 4, 1, 16, 1, FALSE
, FALSE
},
5680 {D3DFMT_YUY2
, "D3DFMT_YUY2", 2, 1, 1, 4, 1, FALSE
, TRUE
},
5681 {D3DFMT_UYVY
, "D3DFMT_UYVY", 2, 1, 1, 4, 1, FALSE
, TRUE
},
5687 BOOL need_driver_support
, need_runtime_support
;
5691 {D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", TRUE
, FALSE
},
5692 {D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", FALSE
, TRUE
},
5693 {D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM",TRUE
, FALSE
},
5694 {D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
, FALSE
},
5698 unsigned int x
, y
, z
, x2
, y2
, z2
;
5712 D3DLOCKED_BOX locked_box
;
5714 INT expected_row_pitch
, expected_slice_pitch
;
5715 BOOL support
, support_2d
;
5717 unsigned int offset
, expected_offset
;
5719 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
5720 0, 0, 640, 480, 0, 0, 0, 0);
5721 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
5722 ok(!!d3d8
, "Failed to create a D3D object.\n");
5723 if (!(device
= create_device(d3d8
, window
, NULL
)))
5725 skip("Failed to create a D3D device, skipping tests.\n");
5726 IDirect3D8_Release(d3d8
);
5727 DestroyWindow(window
);
5730 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
5731 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
5732 pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP_POW2
);
5734 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
5736 hr
= IDirect3D8_CheckDeviceFormat(d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5737 0, D3DRTYPE_VOLUMETEXTURE
, formats
[i
].fmt
);
5738 support
= SUCCEEDED(hr
);
5739 hr
= IDirect3D8_CheckDeviceFormat(d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5740 0, D3DRTYPE_TEXTURE
, formats
[i
].fmt
);
5741 support_2d
= SUCCEEDED(hr
);
5743 /* Test creation restrictions */
5744 for (w
= 1; w
<= 8; w
++)
5746 for (h
= 1; h
<= 8; h
++)
5748 for (d
= 1; d
<= 8; d
++)
5752 BOOL block_aligned
= TRUE
;
5754 if (w
& (formats
[i
].block_width
- 1) || h
& (formats
[i
].block_height
- 1))
5755 block_aligned
= FALSE
;
5757 size_is_pow2
= !((w
& (w
- 1)) || (h
& (h
- 1)) || (d
& (d
- 1)));
5759 for (j
= 0; j
< sizeof(create_tests
) / sizeof(*create_tests
); j
++)
5761 BOOL may_succeed
= FALSE
;
5764 if (create_tests
[j
].need_runtime_support
&& !formats
[i
].core_fmt
&& !support
)
5765 expect_hr
= D3DERR_INVALIDCALL
;
5766 else if (formats
[i
].create_size_checked
&& !block_aligned
)
5767 expect_hr
= D3DERR_INVALIDCALL
;
5768 else if (pow2
&& !size_is_pow2
&& create_tests
[j
].need_driver_support
)
5769 expect_hr
= D3DERR_INVALIDCALL
;
5770 else if (create_tests
[j
].need_driver_support
&& !support
)
5773 expect_hr
= D3DERR_INVALIDCALL
;
5778 texture
= (IDirect3DVolumeTexture8
*)0xdeadbeef;
5779 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, w
, h
, d
, 1, 0,
5780 formats
[i
].fmt
, create_tests
[j
].pool
, &texture
);
5782 /* Wine knows about ATI2N and happily creates a scratch resource even if GL
5783 * does not support it. Accept scratch creation of extension formats on
5784 * Windows as well if it occurs. We don't really care if e.g. a Windows 7
5785 * on an r200 GPU creates scratch ATI2N texture even though the card doesn't
5787 if (!formats
[i
].core_fmt
&& !support
&& FAILED(expect_hr
))
5792 todo_wine
ok(hr
== expect_hr
|| ((SUCCEEDED(hr
) && may_succeed
)),
5793 "Got unexpected hr %#x for format %s, pool %s, size %ux%ux%u.\n",
5794 hr
, formats
[i
].name
, create_tests
[j
].name
, w
, h
, d
);
5798 ok(hr
== expect_hr
|| ((SUCCEEDED(hr
) && may_succeed
)),
5799 "Got unexpected hr %#x for format %s, pool %s, size %ux%ux%u.\n",
5800 hr
, formats
[i
].name
, create_tests
[j
].name
, w
, h
, d
);
5804 ok(texture
== NULL
, "Got texture ptr %p, expected NULL.\n", texture
);
5806 IDirect3DVolumeTexture8_Release(texture
);
5812 if (!support
&& !formats
[i
].core_fmt
)
5815 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 24, 8, 8, 1, 0,
5816 formats
[i
].fmt
, D3DPOOL_SCRATCH
, &texture
);
5817 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
5819 /* Test lockrect offset */
5820 for (j
= 0; j
< sizeof(offset_tests
) / sizeof(*offset_tests
); j
++)
5822 unsigned int bytes_per_pixel
;
5823 bytes_per_pixel
= formats
[i
].block_size
/ (formats
[i
].block_width
* formats
[i
].block_height
);
5825 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, NULL
, 0);
5826 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
5828 base
= locked_box
.pBits
;
5829 if (formats
[i
].broken
== 1)
5831 expected_row_pitch
= bytes_per_pixel
* 24;
5833 else if (formats
[i
].broken
== 2)
5835 expected_row_pitch
= 24;
5839 expected_row_pitch
= (24 /* tex width */ + formats
[i
].block_height
- 1) / formats
[i
].block_width
5840 * formats
[i
].block_size
;
5842 ok(locked_box
.RowPitch
== expected_row_pitch
, "Got unexpected row pitch %d for format %s, expected %d.\n",
5843 locked_box
.RowPitch
, formats
[i
].name
, expected_row_pitch
);
5845 if (formats
[i
].broken
)
5847 expected_slice_pitch
= expected_row_pitch
* 8;
5851 expected_slice_pitch
= (8 /* tex height */ + formats
[i
].block_depth
- 1) / formats
[i
].block_height
5852 * expected_row_pitch
;
5854 ok(locked_box
.SlicePitch
== expected_slice_pitch
,
5855 "Got unexpected slice pitch %d for format %s, expected %d.\n",
5856 locked_box
.SlicePitch
, formats
[i
].name
, expected_slice_pitch
);
5858 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
5859 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x, j %u.\n", hr
, j
);
5861 box
.Left
= offset_tests
[j
].x
;
5862 box
.Top
= offset_tests
[j
].y
;
5863 box
.Front
= offset_tests
[j
].z
;
5864 box
.Right
= offset_tests
[j
].x2
;
5865 box
.Bottom
= offset_tests
[j
].y2
;
5866 box
.Back
= offset_tests
[j
].z2
;
5867 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
5868 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x, j %u.\n", hr
, j
);
5870 offset
= (BYTE
*)locked_box
.pBits
- base
;
5871 if (formats
[i
].broken
== 1)
5873 expected_offset
= box
.Front
* expected_slice_pitch
5874 + box
.Top
* expected_row_pitch
5875 + box
.Left
* bytes_per_pixel
;
5877 else if (formats
[i
].broken
== 2)
5879 expected_offset
= box
.Front
* expected_slice_pitch
5880 + box
.Top
* expected_row_pitch
5885 expected_offset
= (box
.Front
/ formats
[i
].block_depth
) * expected_slice_pitch
5886 + (box
.Top
/ formats
[i
].block_height
) * expected_row_pitch
5887 + (box
.Left
/ formats
[i
].block_width
) * formats
[i
].block_size
;
5889 ok(offset
== expected_offset
, "Got unexpected offset %u for format %s, expected %u, box start %ux%ux%u.\n",
5890 offset
, formats
[i
].name
, expected_offset
, box
.Left
, box
.Top
, box
.Front
);
5892 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
5893 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
5896 /* Test partial block locks */
5899 if (formats
[i
].block_width
> 1)
5901 box
.Left
= formats
[i
].block_width
>> 1;
5903 box
.Right
= formats
[i
].block_width
;
5904 box
.Bottom
= formats
[i
].block_height
;
5905 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
5906 ok(FAILED(hr
) || broken(formats
[i
].broken
),
5907 "Partial block lock succeeded, expected failure, format %s.\n",
5911 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
5912 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
5917 box
.Right
= formats
[i
].block_width
>> 1;
5918 box
.Bottom
= formats
[i
].block_height
;
5919 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
5920 ok(FAILED(hr
) || broken(formats
[i
].broken
),
5921 "Partial block lock succeeded, expected failure, format %s.\n",
5925 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
5926 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
5930 if (formats
[i
].block_height
> 1)
5933 box
.Top
= formats
[i
].block_height
>> 1;
5934 box
.Right
= formats
[i
].block_width
;
5935 box
.Bottom
= formats
[i
].block_height
;
5936 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
5937 ok(FAILED(hr
) || broken(formats
[i
].broken
),
5938 "Partial block lock succeeded, expected failure, format %s.\n",
5942 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
5943 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
5948 box
.Right
= formats
[i
].block_width
;
5949 box
.Bottom
= formats
[i
].block_height
>> 1;
5950 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
5951 ok(FAILED(hr
) || broken(formats
[i
].broken
),
5952 "Partial block lock succeeded, expected failure, format %s.\n",
5956 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
5957 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
5961 /* Test full block lock */
5964 box
.Right
= formats
[i
].block_width
;
5965 box
.Bottom
= formats
[i
].block_height
;
5966 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
5967 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
5968 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
5969 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
5971 IDirect3DVolumeTexture8_Release(texture
);
5973 /* Test mipmap locks. Don't do this with ATI2N, AMD warns that the runtime
5974 * does not allocate surfaces smaller than the blocksize properly. */
5975 if ((formats
[i
].block_width
> 1 || formats
[i
].block_height
> 1) && formats
[i
].core_fmt
)
5977 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, formats
[i
].block_width
, formats
[i
].block_height
,
5978 2, 2, 0, formats
[i
].fmt
, D3DPOOL_SCRATCH
, &texture
);
5980 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 1, &locked_box
, NULL
, 0);
5981 ok(SUCCEEDED(hr
), "Failed to lock volume texture mipmap, hr %#x.\n", hr
);
5982 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 1);
5983 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
5985 box
.Left
= box
.Top
= box
.Front
= 0;
5986 box
.Right
= formats
[i
].block_width
== 1 ? 1 : formats
[i
].block_width
>> 1;
5987 box
.Bottom
= formats
[i
].block_height
== 1 ? 1 : formats
[i
].block_height
>> 1;
5989 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 1, &locked_box
, &box
, 0);
5990 ok(SUCCEEDED(hr
), "Failed to lock volume texture mipmap, hr %#x.\n", hr
);
5991 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 1);
5992 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
5994 box
.Right
= formats
[i
].block_width
;
5995 box
.Bottom
= formats
[i
].block_height
;
5996 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 1, &locked_box
, &box
, 0);
5997 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5999 IDirect3DVolumeTexture8_UnlockBox(texture
, 1);
6001 IDirect3DVolumeTexture8_Release(texture
);
6005 refcount
= IDirect3DDevice8_Release(device
);
6006 ok(!refcount
, "Device has %u references left.\n", refcount
);
6007 IDirect3D8_Release(d3d8
);
6008 DestroyWindow(window
);
6011 static void test_lockbox_invalid(void)
6020 {{0, 0, 2, 2, 0, 1}, D3D_OK
}, /* Valid */
6021 {{0, 0, 4, 4, 0, 1}, D3D_OK
}, /* Valid */
6022 {{0, 0, 0, 4, 0, 1}, D3DERR_INVALIDCALL
}, /* 0 height */
6023 {{0, 0, 4, 0, 0, 1}, D3DERR_INVALIDCALL
}, /* 0 width */
6024 {{0, 0, 4, 4, 1, 1}, D3DERR_INVALIDCALL
}, /* 0 depth */
6025 {{4, 0, 0, 4, 0, 1}, D3DERR_INVALIDCALL
}, /* left > right */
6026 {{0, 4, 4, 0, 0, 1}, D3DERR_INVALIDCALL
}, /* top > bottom */
6027 {{0, 0, 4, 4, 1, 0}, D3DERR_INVALIDCALL
}, /* back > front */
6028 {{0, 0, 8, 4, 0, 1}, D3DERR_INVALIDCALL
}, /* right > surface */
6029 {{0, 0, 4, 8, 0, 1}, D3DERR_INVALIDCALL
}, /* bottom > surface */
6030 {{0, 0, 4, 4, 0, 3}, D3DERR_INVALIDCALL
}, /* back > surface */
6031 {{8, 0, 16, 4, 0, 1}, D3DERR_INVALIDCALL
}, /* left > surface */
6032 {{0, 8, 4, 16, 0, 1}, D3DERR_INVALIDCALL
}, /* top > surface */
6033 {{0, 0, 4, 4, 2, 4}, D3DERR_INVALIDCALL
}, /* top > surface */
6035 static const D3DBOX test_boxt_2
= {2, 2, 4, 4, 0, 1};
6036 IDirect3DVolumeTexture8
*texture
= NULL
;
6037 D3DLOCKED_BOX locked_box
;
6038 IDirect3DDevice8
*device
;
6046 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6047 0, 0, 640, 480, 0, 0, 0, 0);
6048 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
6049 ok(!!d3d
, "Failed to create a D3D object.\n");
6050 if (!(device
= create_device(d3d
, window
, NULL
)))
6052 skip("Failed to create a D3D device, skipping tests.\n");
6053 IDirect3D8_Release(d3d
);
6054 DestroyWindow(window
);
6058 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 4, 4, 2, 1, 0,
6059 D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &texture
);
6060 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
6061 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, NULL
, 0);
6062 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
6063 base
= locked_box
.pBits
;
6064 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6065 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6067 for (i
= 0; i
< (sizeof(test_data
) / sizeof(*test_data
)); ++i
)
6069 unsigned int offset
, expected_offset
;
6070 const D3DBOX
*box
= &test_data
[i
].box
;
6072 locked_box
.pBits
= (BYTE
*)0xdeadbeef;
6073 locked_box
.RowPitch
= 0xdeadbeef;
6074 locked_box
.SlicePitch
= 0xdeadbeef;
6076 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, box
, 0);
6077 /* Unlike surfaces, volumes properly check the box even in Windows XP */
6078 ok(hr
== test_data
[i
].result
,
6079 "Got unexpected hr %#x with box [%u, %u, %u]->[%u, %u, %u], expected %#x.\n",
6080 hr
, box
->Left
, box
->Top
, box
->Front
, box
->Right
, box
->Bottom
, box
->Back
,
6081 test_data
[i
].result
);
6085 offset
= (BYTE
*)locked_box
.pBits
- base
;
6086 expected_offset
= box
->Front
* locked_box
.SlicePitch
+ box
->Top
* locked_box
.RowPitch
+ box
->Left
* 4;
6087 ok(offset
== expected_offset
,
6088 "Got unexpected offset %u (expected %u) for rect [%u, %u, %u]->[%u, %u, %u].\n",
6089 offset
, expected_offset
, box
->Left
, box
->Top
, box
->Front
, box
->Right
, box
->Bottom
, box
->Back
);
6091 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6092 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6095 /* locked_box = NULL throws an exception on Windows */
6096 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, NULL
, 0);
6097 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
6098 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, NULL
, 0);
6099 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
6100 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6101 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6102 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6103 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
6105 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &test_data
[0].box
, 0);
6106 ok(hr
== D3D_OK
, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
6107 hr
, test_data
[0].box
.Left
, test_data
[0].box
.Top
, test_data
[0].box
.Front
,
6108 test_data
[0].box
.Right
, test_data
[0].box
.Bottom
, test_data
[0].box
.Back
);
6109 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &test_data
[0].box
, 0);
6110 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
6111 hr
, test_data
[0].box
.Left
, test_data
[0].box
.Top
, test_data
[0].box
.Front
,
6112 test_data
[0].box
.Right
, test_data
[0].box
.Bottom
, test_data
[0].box
.Back
);
6113 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &test_boxt_2
, 0);
6114 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
6115 hr
, test_boxt_2
.Left
, test_boxt_2
.Top
, test_boxt_2
.Front
,
6116 test_boxt_2
.Right
, test_boxt_2
.Bottom
, test_boxt_2
.Back
);
6117 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6118 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6120 IDirect3DVolumeTexture8_Release(texture
);
6121 refcount
= IDirect3DDevice8_Release(device
);
6122 ok(!refcount
, "Device has %u references left.\n", refcount
);
6123 IDirect3D8_Release(d3d
);
6124 DestroyWindow(window
);
6127 static void test_pixel_format(void)
6129 HWND hwnd
, hwnd2
= NULL
;
6130 HDC hdc
, hdc2
= NULL
;
6132 int format
, test_format
;
6133 PIXELFORMATDESCRIPTOR pfd
;
6134 IDirect3D8
*d3d8
= NULL
;
6135 IDirect3DDevice8
*device
= NULL
;
6137 static const float point
[3] = {0.0, 0.0, 0.0};
6139 hwnd
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6140 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
6143 skip("Failed to create window\n");
6147 hwnd2
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6148 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
6153 skip("Failed to get DC\n");
6158 hdc2
= GetDC(hwnd2
);
6160 gl
= LoadLibraryA("opengl32.dll");
6161 ok(!!gl
, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
6163 format
= GetPixelFormat(hdc
);
6164 ok(format
== 0, "new window has pixel format %d\n", format
);
6166 ZeroMemory(&pfd
, sizeof(pfd
));
6167 pfd
.nSize
= sizeof(pfd
);
6169 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
6170 pfd
.iPixelType
= PFD_TYPE_RGBA
;
6171 pfd
.iLayerType
= PFD_MAIN_PLANE
;
6172 format
= ChoosePixelFormat(hdc
, &pfd
);
6175 skip("no pixel format available\n");
6179 if (!SetPixelFormat(hdc
, format
, &pfd
) || GetPixelFormat(hdc
) != format
)
6181 skip("failed to set pixel format\n");
6185 if (!hdc2
|| !SetPixelFormat(hdc2
, format
, &pfd
) || GetPixelFormat(hdc2
) != format
)
6187 skip("failed to set pixel format on second window\n");
6190 ReleaseDC(hwnd2
, hdc2
);
6195 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
6196 ok(!!d3d8
, "Failed to create a D3D object.\n");
6198 test_format
= GetPixelFormat(hdc
);
6199 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6201 if (!(device
= create_device(d3d8
, hwnd
, NULL
)))
6203 skip("Failed to create device\n");
6207 test_format
= GetPixelFormat(hdc
);
6208 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6210 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
);
6211 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
6213 test_format
= GetPixelFormat(hdc
);
6214 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6216 hr
= IDirect3DDevice8_BeginScene(device
);
6217 ok(SUCCEEDED(hr
), "BeginScene failed %#x\n", hr
);
6219 test_format
= GetPixelFormat(hdc
);
6220 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6222 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_POINTLIST
, 1, point
, 3 * sizeof(float));
6223 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6225 test_format
= GetPixelFormat(hdc
);
6226 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6228 hr
= IDirect3DDevice8_EndScene(device
);
6229 ok(SUCCEEDED(hr
), "EndScene failed %#x\n", hr
);
6231 test_format
= GetPixelFormat(hdc
);
6232 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6234 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
6235 ok(SUCCEEDED(hr
), "Present failed %#x\n", hr
);
6237 test_format
= GetPixelFormat(hdc
);
6238 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6242 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, hwnd2
, NULL
);
6243 ok(SUCCEEDED(hr
), "Present failed %#x\n", hr
);
6245 test_format
= GetPixelFormat(hdc
);
6246 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6248 test_format
= GetPixelFormat(hdc2
);
6249 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
6255 UINT refcount
= IDirect3DDevice8_Release(device
);
6256 ok(!refcount
, "Device has %u references left.\n", refcount
);
6258 if (d3d8
) IDirect3D8_Release(d3d8
);
6259 if (gl
) FreeLibrary(gl
);
6260 if (hdc
) ReleaseDC(hwnd
, hdc
);
6261 if (hdc2
) ReleaseDC(hwnd2
, hdc2
);
6262 if (hwnd
) DestroyWindow(hwnd
);
6263 if (hwnd2
) DestroyWindow(hwnd2
);
6266 static void test_begin_end_state_block(void)
6268 IDirect3DDevice8
*device
;
6275 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6276 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
6277 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
6278 ok(!!d3d
, "Failed to create a D3D object.\n");
6279 if (!(device
= create_device(d3d
, window
, NULL
)))
6281 skip("Failed to create a D3D device, skipping tests.\n");
6282 IDirect3D8_Release(d3d
);
6283 DestroyWindow(window
);
6287 /* Should succeed. */
6288 hr
= IDirect3DDevice8_BeginStateBlock(device
);
6289 ok(SUCCEEDED(hr
), "Failed to begin stateblock, hr %#x.\n", hr
);
6291 /* Calling BeginStateBlock() while recording should return
6292 * D3DERR_INVALIDCALL. */
6293 hr
= IDirect3DDevice8_BeginStateBlock(device
);
6294 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
6296 /* Should succeed. */
6297 stateblock
= 0xdeadbeef;
6298 hr
= IDirect3DDevice8_EndStateBlock(device
, &stateblock
);
6299 ok(SUCCEEDED(hr
), "Failed to end stateblock, hr %#x.\n", hr
);
6300 ok(!!stateblock
&& stateblock
!= 0xdeadbeef, "Got unexpected stateblock %#x.\n", stateblock
);
6301 IDirect3DDevice8_DeleteStateBlock(device
, stateblock
);
6303 /* Calling EndStateBlock() while not recording should return
6304 * D3DERR_INVALIDCALL. stateblock should not be touched. */
6305 stateblock
= 0xdeadbeef;
6306 hr
= IDirect3DDevice8_EndStateBlock(device
, &stateblock
);
6307 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
6308 ok(stateblock
== 0xdeadbeef, "Got unexpected stateblock %#x.\n", stateblock
);
6310 refcount
= IDirect3DDevice8_Release(device
);
6311 ok(!refcount
, "Device has %u references left.\n", refcount
);
6312 IDirect3D8_Release(d3d
);
6313 DestroyWindow(window
);
6316 static void test_shader_constant_apply(void)
6318 static const float vs_const
[] = {1.0f
, 2.0f
, 3.0f
, 4.0f
};
6319 static const float ps_const
[] = {5.0f
, 6.0f
, 7.0f
, 8.0f
};
6320 static const float initial
[] = {0.0f
, 0.0f
, 0.0f
, 0.0f
};
6321 DWORD vs_version
, ps_version
;
6322 IDirect3DDevice8
*device
;
6331 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6332 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
6333 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
6334 ok(!!d3d
, "Failed to create a D3D object.\n");
6335 if (!(device
= create_device(d3d
, window
, NULL
)))
6337 skip("Failed to create a D3D device, skipping tests.\n");
6338 IDirect3D8_Release(d3d
);
6339 DestroyWindow(window
);
6343 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
6344 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
6345 vs_version
= caps
.VertexShaderVersion
& 0xffff;
6346 ps_version
= caps
.PixelShaderVersion
& 0xffff;
6350 hr
= IDirect3DDevice8_SetVertexShaderConstant(device
, 0, initial
, 1);
6351 ok(SUCCEEDED(hr
), "Failed to set vertex shader constant, hr %#x.\n", hr
);
6352 hr
= IDirect3DDevice8_SetVertexShaderConstant(device
, 1, initial
, 1);
6353 ok(SUCCEEDED(hr
), "Failed to set vertex shader constant, hr %#x.\n", hr
);
6355 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 0, ret
, 1);
6356 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
6357 ok(!memcmp(ret
, initial
, sizeof(initial
)),
6358 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6359 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
6360 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 1, ret
, 1);
6361 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
6362 ok(!memcmp(ret
, initial
, sizeof(initial
)),
6363 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6364 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
6366 hr
= IDirect3DDevice8_SetVertexShaderConstant(device
, 0, vs_const
, 1);
6367 ok(SUCCEEDED(hr
), "Failed to set vertex shader constant, hr %#x.\n", hr
);
6371 hr
= IDirect3DDevice8_SetPixelShaderConstant(device
, 0, initial
, 1);
6372 ok(SUCCEEDED(hr
), "Failed to set pixel shader constant, hr %#x.\n", hr
);
6373 hr
= IDirect3DDevice8_SetPixelShaderConstant(device
, 1, initial
, 1);
6374 ok(SUCCEEDED(hr
), "Failed to set pixel shader constant, hr %#x.\n", hr
);
6376 hr
= IDirect3DDevice8_GetPixelShaderConstant(device
, 0, ret
, 1);
6377 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
6378 ok(!memcmp(ret
, initial
, sizeof(initial
)),
6379 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6380 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
6381 hr
= IDirect3DDevice8_GetPixelShaderConstant(device
, 1, ret
, 1);
6382 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
6383 ok(!memcmp(ret
, initial
, sizeof(initial
)),
6384 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6385 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
6387 hr
= IDirect3DDevice8_SetPixelShaderConstant(device
, 0, ps_const
, 1);
6388 ok(SUCCEEDED(hr
), "Failed to set pixel shader constant, hr %#x.\n", hr
);
6391 hr
= IDirect3DDevice8_BeginStateBlock(device
);
6392 ok(SUCCEEDED(hr
), "Failed to begin stateblock, hr %#x.\n", hr
);
6396 hr
= IDirect3DDevice8_SetVertexShaderConstant(device
, 1, vs_const
, 1);
6397 ok(SUCCEEDED(hr
), "Failed to set vertex shader constant, hr %#x.\n", hr
);
6401 hr
= IDirect3DDevice8_SetPixelShaderConstant(device
, 1, ps_const
, 1);
6402 ok(SUCCEEDED(hr
), "Failed to set pixel shader constant, hr %#x.\n", hr
);
6405 hr
= IDirect3DDevice8_EndStateBlock(device
, &stateblock
);
6406 ok(SUCCEEDED(hr
), "Failed to end stateblock, hr %#x.\n", hr
);
6410 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 0, ret
, 1);
6411 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
6412 ok(!memcmp(ret
, vs_const
, sizeof(vs_const
)),
6413 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6414 ret
[0], ret
[1], ret
[2], ret
[3], vs_const
[0], vs_const
[1], vs_const
[2], vs_const
[3]);
6415 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 1, ret
, 1);
6416 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
6417 ok(!memcmp(ret
, initial
, sizeof(initial
)),
6418 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6419 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
6423 hr
= IDirect3DDevice8_GetPixelShaderConstant(device
, 0, ret
, 1);
6424 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
6425 ok(!memcmp(ret
, ps_const
, sizeof(ps_const
)),
6426 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6427 ret
[0], ret
[1], ret
[2], ret
[3], ps_const
[0], ps_const
[1], ps_const
[2], ps_const
[3]);
6428 hr
= IDirect3DDevice8_GetPixelShaderConstant(device
, 1, ret
, 1);
6429 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
6430 ok(!memcmp(ret
, initial
, sizeof(initial
)),
6431 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6432 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
6435 /* Apply doesn't overwrite constants that aren't explicitly set on the
6436 * source stateblock. */
6437 hr
= IDirect3DDevice8_ApplyStateBlock(device
, stateblock
);
6438 ok(SUCCEEDED(hr
), "Failed to apply stateblock, hr %#x.\n", hr
);
6442 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 0, ret
, 1);
6443 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
6444 ok(!memcmp(ret
, vs_const
, sizeof(vs_const
)),
6445 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6446 ret
[0], ret
[1], ret
[2], ret
[3], vs_const
[0], vs_const
[1], vs_const
[2], vs_const
[3]);
6447 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 1, ret
, 1);
6448 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
6449 ok(!memcmp(ret
, vs_const
, sizeof(vs_const
)),
6450 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6451 ret
[0], ret
[1], ret
[2], ret
[3], vs_const
[0], vs_const
[1], vs_const
[2], vs_const
[3]);
6455 hr
= IDirect3DDevice8_GetPixelShaderConstant(device
, 0, ret
, 1);
6456 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
6457 ok(!memcmp(ret
, ps_const
, sizeof(ps_const
)),
6458 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6459 ret
[0], ret
[1], ret
[2], ret
[3], ps_const
[0], ps_const
[1], ps_const
[2], ps_const
[3]);
6460 hr
= IDirect3DDevice8_GetPixelShaderConstant(device
, 1, ret
, 1);
6461 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
6462 ok(!memcmp(ret
, ps_const
, sizeof(ps_const
)),
6463 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6464 ret
[0], ret
[1], ret
[2], ret
[3], ps_const
[0], ps_const
[1], ps_const
[2], ps_const
[3]);
6467 IDirect3DDevice8_DeleteStateBlock(device
, stateblock
);
6468 refcount
= IDirect3DDevice8_Release(device
);
6469 ok(!refcount
, "Device has %u references left.\n", refcount
);
6470 IDirect3D8_Release(d3d
);
6471 DestroyWindow(window
);
6474 static void test_resource_type(void)
6476 IDirect3DDevice8
*device
;
6477 IDirect3DSurface8
*surface
;
6478 IDirect3DTexture8
*texture
;
6479 IDirect3DCubeTexture8
*cube_texture
;
6480 IDirect3DVolume8
*volume
;
6481 IDirect3DVolumeTexture8
*volume_texture
;
6482 D3DSURFACE_DESC surface_desc
;
6483 D3DVOLUME_DESC volume_desc
;
6484 D3DRESOURCETYPE type
;
6491 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6492 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
6493 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
6494 ok(!!d3d
, "Failed to create a D3D object.\n");
6495 if (!(device
= create_device(d3d
, window
, NULL
)))
6497 skip("Failed to create a D3D device, skipping tests.\n");
6498 IDirect3D8_Release(d3d
);
6499 DestroyWindow(window
);
6503 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
6504 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
6506 hr
= IDirect3DDevice8_CreateImageSurface(device
, 4, 4, D3DFMT_X8R8G8B8
, &surface
);
6507 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6508 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
6509 ok(SUCCEEDED(hr
), "Failed to get surface description, hr %#x.\n", hr
);
6510 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
6512 IDirect3DSurface8_Release(surface
);
6514 hr
= IDirect3DDevice8_CreateTexture(device
, 2, 8, 4, 0, D3DFMT_X8R8G8B8
,
6515 D3DPOOL_SYSTEMMEM
, &texture
);
6516 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
6517 type
= IDirect3DTexture8_GetType(texture
);
6518 ok(type
== D3DRTYPE_TEXTURE
, "Expected type D3DRTYPE_TEXTURE, got %u.\n", type
);
6520 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &surface
);
6521 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
6522 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
6523 ok(SUCCEEDED(hr
), "Failed to get surface description, hr %#x.\n", hr
);
6524 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
6526 ok(surface_desc
.Width
== 2, "Expected width 2, got %u.\n", surface_desc
.Width
);
6527 ok(surface_desc
.Height
== 8, "Expected height 8, got %u.\n", surface_desc
.Height
);
6528 hr
= IDirect3DTexture8_GetLevelDesc(texture
, 0, &surface_desc
);
6529 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
6530 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
6532 ok(surface_desc
.Width
== 2, "Expected width 2, got %u.\n", surface_desc
.Width
);
6533 ok(surface_desc
.Height
== 8, "Expected height 8, got %u.\n", surface_desc
.Height
);
6534 IDirect3DSurface8_Release(surface
);
6536 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 2, &surface
);
6537 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
6538 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
6539 ok(SUCCEEDED(hr
), "Failed to get surface description, hr %#x.\n", hr
);
6540 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
6542 ok(surface_desc
.Width
== 1, "Expected width 1, got %u.\n", surface_desc
.Width
);
6543 ok(surface_desc
.Height
== 2, "Expected height 2, got %u.\n", surface_desc
.Height
);
6544 hr
= IDirect3DTexture8_GetLevelDesc(texture
, 2, &surface_desc
);
6545 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
6546 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
6548 ok(surface_desc
.Width
== 1, "Expected width 1, got %u.\n", surface_desc
.Width
);
6549 ok(surface_desc
.Height
== 2, "Expected height 2, got %u.\n", surface_desc
.Height
);
6550 IDirect3DSurface8_Release(surface
);
6551 IDirect3DTexture8_Release(texture
);
6553 if (caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
)
6555 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 1, 1, 0, D3DFMT_X8R8G8B8
,
6556 D3DPOOL_SYSTEMMEM
, &cube_texture
);
6557 ok(SUCCEEDED(hr
), "Failed to create cube texture, hr %#x.\n", hr
);
6558 type
= IDirect3DCubeTexture8_GetType(cube_texture
);
6559 ok(type
== D3DRTYPE_CUBETEXTURE
, "Expected type D3DRTYPE_CUBETEXTURE, got %u.\n", type
);
6561 hr
= IDirect3DCubeTexture8_GetCubeMapSurface(cube_texture
,
6562 D3DCUBEMAP_FACE_NEGATIVE_X
, 0, &surface
);
6563 ok(SUCCEEDED(hr
), "Failed to get cube map surface, hr %#x.\n", hr
);
6564 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
6565 ok(SUCCEEDED(hr
), "Failed to get surface description, hr %#x.\n", hr
);
6566 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
6568 hr
= IDirect3DCubeTexture8_GetLevelDesc(cube_texture
, 0, &surface_desc
);
6569 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
6570 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
6572 IDirect3DSurface8_Release(surface
);
6573 IDirect3DCubeTexture8_Release(cube_texture
);
6576 skip("Cube maps not supported.\n");
6578 if (caps
.TextureCaps
& D3DPTEXTURECAPS_MIPVOLUMEMAP
)
6580 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 2, 4, 8, 4, 0, D3DFMT_X8R8G8B8
,
6581 D3DPOOL_SYSTEMMEM
, &volume_texture
);
6582 type
= IDirect3DVolumeTexture8_GetType(volume_texture
);
6583 ok(type
== D3DRTYPE_VOLUMETEXTURE
, "Expected type D3DRTYPE_VOLUMETEXTURE, got %u.\n", type
);
6585 hr
= IDirect3DVolumeTexture8_GetVolumeLevel(volume_texture
, 0, &volume
);
6586 ok(SUCCEEDED(hr
), "Failed to get volume level, hr %#x.\n", hr
);
6587 /* IDirect3DVolume8 is not an IDirect3DResource8 and has no GetType method. */
6588 hr
= IDirect3DVolume8_GetDesc(volume
, &volume_desc
);
6589 ok(SUCCEEDED(hr
), "Failed to get volume description, hr %#x.\n", hr
);
6590 ok(volume_desc
.Type
== D3DRTYPE_VOLUME
, "Expected type D3DRTYPE_VOLUME, got %u.\n",
6592 ok(volume_desc
.Width
== 2, "Expected width 2, got %u.\n", volume_desc
.Width
);
6593 ok(volume_desc
.Height
== 4, "Expected height 4, got %u.\n", volume_desc
.Height
);
6594 ok(volume_desc
.Depth
== 8, "Expected depth 8, got %u.\n", volume_desc
.Depth
);
6595 hr
= IDirect3DVolumeTexture8_GetLevelDesc(volume_texture
, 0, &volume_desc
);
6596 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
6597 ok(volume_desc
.Type
== D3DRTYPE_VOLUME
, "Expected type D3DRTYPE_VOLUME, got %u.\n",
6599 ok(volume_desc
.Width
== 2, "Expected width 2, got %u.\n", volume_desc
.Width
);
6600 ok(volume_desc
.Height
== 4, "Expected height 4, got %u.\n", volume_desc
.Height
);
6601 ok(volume_desc
.Depth
== 8, "Expected depth 8, got %u.\n", volume_desc
.Depth
);
6602 IDirect3DVolume8_Release(volume
);
6604 hr
= IDirect3DVolumeTexture8_GetVolumeLevel(volume_texture
, 2, &volume
);
6605 ok(SUCCEEDED(hr
), "Failed to get volume level, hr %#x.\n", hr
);
6606 hr
= IDirect3DVolume8_GetDesc(volume
, &volume_desc
);
6607 ok(SUCCEEDED(hr
), "Failed to get volume description, hr %#x.\n", hr
);
6608 ok(volume_desc
.Type
== D3DRTYPE_VOLUME
, "Expected type D3DRTYPE_VOLUME, got %u.\n",
6610 ok(volume_desc
.Width
== 1, "Expected width 1, got %u.\n", volume_desc
.Width
);
6611 ok(volume_desc
.Height
== 1, "Expected height 1, got %u.\n", volume_desc
.Height
);
6612 ok(volume_desc
.Depth
== 2, "Expected depth 2, got %u.\n", volume_desc
.Depth
);
6613 hr
= IDirect3DVolumeTexture8_GetLevelDesc(volume_texture
, 2, &volume_desc
);
6614 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
6615 ok(volume_desc
.Type
== D3DRTYPE_VOLUME
, "Expected type D3DRTYPE_VOLUME, got %u.\n",
6617 ok(volume_desc
.Width
== 1, "Expected width 1, got %u.\n", volume_desc
.Width
);
6618 ok(volume_desc
.Height
== 1, "Expected height 1, got %u.\n", volume_desc
.Height
);
6619 ok(volume_desc
.Depth
== 2, "Expected depth 2, got %u.\n", volume_desc
.Depth
);
6620 IDirect3DVolume8_Release(volume
);
6621 IDirect3DVolumeTexture8_Release(volume_texture
);
6624 skip("Mipmapped volume maps not supported.\n");
6626 refcount
= IDirect3DDevice8_Release(device
);
6627 ok(!refcount
, "Device has %u references left.\n", refcount
);
6628 IDirect3D8_Release(d3d
);
6629 DestroyWindow(window
);
6632 static void test_mipmap_lock(void)
6634 IDirect3DDevice8
*device
;
6635 IDirect3DSurface8
*surface
, *surface2
, *surface_dst
, *surface_dst2
;
6636 IDirect3DTexture8
*texture
, *texture_dst
;
6641 D3DLOCKED_RECT locked_rect
;
6643 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6644 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
6645 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
6646 ok(!!d3d
, "Failed to create a D3D object.\n");
6647 if (!(device
= create_device(d3d
, window
, NULL
)))
6649 skip("Failed to create a D3D device, skipping tests.\n");
6650 IDirect3D8_Release(d3d
);
6651 DestroyWindow(window
);
6655 hr
= IDirect3DDevice8_CreateTexture(device
, 4, 4, 2, 0, D3DFMT_X8R8G8B8
,
6656 D3DPOOL_DEFAULT
, &texture_dst
);
6657 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
6658 hr
= IDirect3DTexture8_GetSurfaceLevel(texture_dst
, 0, &surface_dst
);
6659 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
6660 hr
= IDirect3DTexture8_GetSurfaceLevel(texture_dst
, 1, &surface_dst2
);
6661 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
6663 hr
= IDirect3DDevice8_CreateTexture(device
, 4, 4, 2, 0, D3DFMT_X8R8G8B8
,
6664 D3DPOOL_SYSTEMMEM
, &texture
);
6665 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
6666 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &surface
);
6667 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
6668 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 1, &surface2
);
6669 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
6671 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
6672 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
6673 hr
= IDirect3DSurface8_LockRect(surface2
, &locked_rect
, NULL
, 0);
6674 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
6675 hr
= IDirect3DSurface8_UnlockRect(surface
);
6676 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
6678 hr
= IDirect3DDevice8_CopyRects(device
, surface
, NULL
, 0, surface_dst
, NULL
);
6679 ok(SUCCEEDED(hr
), "Failed to update surface, hr %#x.\n", hr
);
6680 hr
= IDirect3DDevice8_CopyRects(device
, surface2
, NULL
, 0, surface_dst2
, NULL
);
6681 todo_wine
ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
6683 /* Apparently there's no validation on the container. */
6684 hr
= IDirect3DDevice8_UpdateTexture(device
, (IDirect3DBaseTexture8
*)texture
,
6685 (IDirect3DBaseTexture8
*)texture_dst
);
6686 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x.\n", hr
);
6688 hr
= IDirect3DSurface8_UnlockRect(surface2
);
6689 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
6691 IDirect3DSurface8_Release(surface_dst2
);
6692 IDirect3DSurface8_Release(surface_dst
);
6693 IDirect3DSurface8_Release(surface2
);
6694 IDirect3DSurface8_Release(surface
);
6695 IDirect3DTexture8_Release(texture_dst
);
6696 IDirect3DTexture8_Release(texture
);
6698 refcount
= IDirect3DDevice8_Release(device
);
6699 ok(!refcount
, "Device has %u references left.\n", refcount
);
6700 IDirect3D8_Release(d3d
);
6701 DestroyWindow(window
);
6704 static void test_writeonly_resource(void)
6707 IDirect3DDevice8
*device
;
6708 IDirect3DVertexBuffer8
*buffer
;
6719 {{-1.0f
, -1.0f
, 0.0f
}},
6720 {{-1.0f
, 1.0f
, 0.0f
}},
6721 {{ 1.0f
, -1.0f
, 0.0f
}},
6722 {{ 1.0f
, 1.0f
, 0.0f
}}
6725 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6726 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
6727 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
6728 ok(!!d3d
, "Failed to create a D3D object.\n");
6729 if (!(device
= create_device(d3d
, window
, NULL
)))
6731 skip("Failed to create a D3D device, skipping tests.\n");
6732 IDirect3D8_Release(d3d
);
6733 DestroyWindow(window
);
6737 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, sizeof(quad
),
6738 D3DUSAGE_DYNAMIC
| D3DUSAGE_WRITEONLY
, 0, D3DPOOL_DEFAULT
, &buffer
);
6739 ok(SUCCEEDED(hr
), "Failed to create buffer, hr %#x.\n", hr
);
6741 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, 0, &ptr
, D3DLOCK_DISCARD
);
6742 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
6743 memcpy(ptr
, quad
, sizeof(quad
));
6744 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
6745 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
6746 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, buffer
, sizeof(*quad
));
6747 ok(SUCCEEDED(hr
), "Failed to set stream source, hr %#x.\n", hr
);
6748 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
);
6749 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
6751 hr
= IDirect3DDevice8_BeginScene(device
);
6752 ok(SUCCEEDED(hr
), "Failed to begin scene %#x\n", hr
);
6753 hr
= IDirect3DDevice8_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 0, 2);
6754 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6755 hr
= IDirect3DDevice8_EndScene(device
);
6756 ok(SUCCEEDED(hr
), "Failed to end scene %#x\n", hr
);
6758 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, 0, &ptr
, 0);
6759 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
6760 ok (!memcmp(ptr
, quad
, sizeof(quad
)), "Got unexpected vertex buffer data.\n");
6761 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
6762 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
6764 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, 0, &ptr
, D3DLOCK_READONLY
);
6765 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
6766 ok (!memcmp(ptr
, quad
, sizeof(quad
)), "Got unexpected vertex buffer data.\n");
6767 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
6768 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
6770 refcount
= IDirect3DVertexBuffer8_Release(buffer
);
6771 ok(!refcount
, "Vertex buffer has %u references left.\n", refcount
);
6772 refcount
= IDirect3DDevice8_Release(device
);
6773 ok(!refcount
, "Device has %u references left.\n", refcount
);
6774 IDirect3D8_Release(d3d
);
6775 DestroyWindow(window
);
6778 static void test_lost_device(void)
6780 struct device_desc device_desc
;
6781 IDirect3DDevice8
*device
;
6788 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6789 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
6790 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
6791 ok(!!d3d
, "Failed to create a D3D object.\n");
6792 device_desc
.device_window
= window
;
6793 device_desc
.width
= registry_mode
.dmPelsWidth
;
6794 device_desc
.height
= registry_mode
.dmPelsHeight
;
6795 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
6796 if (!(device
= create_device(d3d
, window
, &device_desc
)))
6798 skip("Failed to create a D3D device, skipping tests.\n");
6802 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
6803 if (hr
== D3DERR_DEVICELOST
)
6805 win_skip("Broken TestCooperativeLevel(), skipping test.\n");
6806 IDirect3DDevice8_Release(device
);
6809 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
6810 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
6811 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
6813 ret
= SetForegroundWindow(GetDesktopWindow());
6814 ok(ret
, "Failed to set foreground window.\n");
6815 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
6816 ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
6817 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
6818 ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
6820 ret
= ShowWindow(window
, SW_RESTORE
);
6821 ok(ret
, "Failed to restore window.\n");
6822 ret
= SetForegroundWindow(window
);
6823 ok(ret
, "Failed to set foreground window.\n");
6824 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
6825 ok(hr
== D3DERR_DEVICENOTRESET
, "Got unexpected hr %#x.\n", hr
);
6826 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
6827 ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
6829 hr
= reset_device(device
, &device_desc
);
6830 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
6831 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
6832 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
6833 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
6834 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
6836 device_desc
.flags
= 0;
6837 hr
= reset_device(device
, &device_desc
);
6838 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
6839 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
6840 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
6841 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
6842 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
6844 ret
= SetForegroundWindow(GetDesktopWindow());
6845 ok(ret
, "Failed to set foreground window.\n");
6846 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
6847 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
6848 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
6849 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
6851 ret
= ShowWindow(window
, SW_RESTORE
);
6852 ok(ret
, "Failed to restore window.\n");
6853 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
6854 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
6855 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
6856 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
6858 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
6859 hr
= reset_device(device
, &device_desc
);
6860 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
6861 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
6862 todo_wine
ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
6863 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
6864 todo_wine
ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
6866 refcount
= IDirect3DDevice8_Release(device
);
6867 ok(!refcount
, "Device has %u references left.\n", refcount
);
6869 IDirect3D8_Release(d3d
);
6870 DestroyWindow(window
);
6873 static void test_resource_priority(void)
6875 IDirect3DDevice8
*device
;
6876 IDirect3DTexture8
*texture
;
6877 IDirect3DVertexBuffer8
*buffer
;
6886 BOOL can_set_priority
;
6890 {D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", FALSE
},
6891 {D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", FALSE
},
6892 {D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
},
6893 {D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", FALSE
}
6898 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6899 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
6900 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
6901 ok(!!d3d
, "Failed to create a D3D object.\n");
6902 if (!(device
= create_device(d3d
, window
, NULL
)))
6904 skip("Failed to create a D3D device, skipping tests.\n");
6905 IDirect3D8_Release(d3d
);
6906 DestroyWindow(window
);
6910 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); i
++)
6912 hr
= IDirect3DDevice8_CreateTexture(device
, 16, 16, 0, 0, D3DFMT_X8R8G8B8
,
6913 test_data
[i
].pool
, &texture
);
6914 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x, pool %s.\n", hr
, test_data
[i
].name
);
6916 priority
= IDirect3DTexture8_GetPriority(texture
);
6917 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
6918 priority
= IDirect3DTexture8_SetPriority(texture
, 1);
6919 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
6920 priority
= IDirect3DTexture8_GetPriority(texture
);
6921 if (test_data
[i
].can_set_priority
)
6923 ok(priority
== 1, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
6924 priority
= IDirect3DTexture8_SetPriority(texture
, 0);
6925 ok(priority
== 1, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
6928 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
6930 IDirect3DTexture8_Release(texture
);
6932 if (test_data
[i
].pool
!= D3DPOOL_SCRATCH
)
6934 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, 256, 0, 0,
6935 test_data
[i
].pool
, &buffer
);
6936 ok(SUCCEEDED(hr
), "Failed to create buffer, hr %#x, pool %s.\n", hr
, test_data
[i
].name
);
6938 priority
= IDirect3DVertexBuffer8_GetPriority(buffer
);
6939 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
6940 priority
= IDirect3DVertexBuffer8_SetPriority(buffer
, 1);
6941 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
6942 priority
= IDirect3DVertexBuffer8_GetPriority(buffer
);
6943 if (test_data
[i
].can_set_priority
)
6945 ok(priority
== 1, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
6946 priority
= IDirect3DVertexBuffer8_SetPriority(buffer
, 0);
6947 ok(priority
== 1, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
6950 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
6952 IDirect3DVertexBuffer8_Release(buffer
);
6956 refcount
= IDirect3DDevice8_Release(device
);
6957 ok(!refcount
, "Device has %u references left.\n", refcount
);
6958 IDirect3D8_Release(d3d
);
6959 DestroyWindow(window
);
6964 HMODULE d3d8_handle
= LoadLibraryA( "d3d8.dll" );
6967 DEVMODEW current_mode
;
6971 skip("Could not load d3d8.dll\n");
6975 memset(¤t_mode
, 0, sizeof(current_mode
));
6976 current_mode
.dmSize
= sizeof(current_mode
);
6977 ok(EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, ¤t_mode
), "Failed to get display mode.\n");
6978 registry_mode
.dmSize
= sizeof(registry_mode
);
6979 ok(EnumDisplaySettingsW(NULL
, ENUM_REGISTRY_SETTINGS
, ®istry_mode
), "Failed to get display mode.\n");
6980 if (current_mode
.dmPelsWidth
!= registry_mode
.dmPelsWidth
6981 || current_mode
.dmPelsHeight
!= registry_mode
.dmPelsHeight
)
6983 skip("Current mode does not match registry mode, skipping test.\n");
6987 wc
.lpfnWndProc
= DefWindowProcA
;
6988 wc
.lpszClassName
= "d3d8_test_wc";
6989 RegisterClassA(&wc
);
6991 ValidateVertexShader
= (void *)GetProcAddress(d3d8_handle
, "ValidateVertexShader");
6992 ValidatePixelShader
= (void *)GetProcAddress(d3d8_handle
, "ValidatePixelShader");
6994 if (!(d3d8
= Direct3DCreate8(D3D_SDK_VERSION
)))
6996 skip("could not create D3D8\n");
6999 IDirect3D8_Release(d3d8
);
7002 test_display_formats();
7003 test_display_modes();
7004 test_shader_versions();
7007 test_mipmap_levels();
7016 test_ApplyStateBlock();
7017 test_render_zero_triangles();
7018 test_depth_stencil_reset();
7020 test_wndproc_windowed();
7021 test_depth_stencil_size();
7022 test_window_style();
7023 test_unsupported_shaders();
7025 test_device_window_reset();
7026 test_reset_resources();
7028 test_set_rt_vp_scissor();
7031 test_volume_get_container();
7032 test_vb_lock_flags();
7033 test_texture_stage_states();
7034 test_cube_textures();
7035 test_image_surface_pool();
7036 test_surface_get_container();
7037 test_lockrect_invalid();
7038 test_private_data();
7039 test_surface_dimensions();
7040 test_surface_format_null();
7041 test_surface_double_unlock();
7042 test_surface_blocks();
7045 test_npot_textures();
7046 test_volume_locking();
7047 test_update_volumetexture();
7048 test_create_rt_ds_fail();
7049 test_volume_blocks();
7050 test_lockbox_invalid();
7051 test_pixel_format();
7052 test_begin_end_state_block();
7053 test_shader_constant_apply();
7054 test_resource_type();
7056 test_writeonly_resource();
7058 test_resource_priority();
7060 UnregisterClassA("d3d8_test_wc", GetModuleHandleA(NULL
));