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
24 #define WINVER 0x0602 /* for CURSOR_SUPPRESSED */
28 #include "wine/test.h"
35 #define CREATE_DEVICE_FULLSCREEN 0x01
36 #define CREATE_DEVICE_FPU_PRESERVE 0x02
37 #define CREATE_DEVICE_SWVP_ONLY 0x04
47 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
48 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
50 static DEVMODEW registry_mode
;
52 static HRESULT (WINAPI
*ValidateVertexShader
)(DWORD
*, DWORD
*, DWORD
*, int, DWORD
*);
53 static HRESULT (WINAPI
*ValidatePixelShader
)(DWORD
*, DWORD
*, int, DWORD
*);
55 static BOOL (WINAPI
*pGetCursorInfo
)(PCURSORINFO
);
57 static const DWORD simple_vs
[] = {0xFFFE0101, /* vs_1_1 */
58 0x00000009, 0xC0010000, 0x90E40000, 0xA0E40000, /* dp4 oPos.x, v0, c0 */
59 0x00000009, 0xC0020000, 0x90E40000, 0xA0E40001, /* dp4 oPos.y, v0, c1 */
60 0x00000009, 0xC0040000, 0x90E40000, 0xA0E40002, /* dp4 oPos.z, v0, c2 */
61 0x00000009, 0xC0080000, 0x90E40000, 0xA0E40003, /* dp4 oPos.w, v0, c3 */
62 0x0000FFFF}; /* END */
63 static const DWORD simple_ps
[] = {0xFFFF0101, /* ps_1_1 */
64 0x00000051, 0xA00F0001, 0x3F800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
65 0x00000042, 0xB00F0000, /* tex t0 */
66 0x00000008, 0x800F0000, 0xA0E40001, 0xA0E40000, /* dp3 r0, c1, c0 */
67 0x00000005, 0x800F0000, 0x90E40000, 0x80E40000, /* mul r0, v0, r0 */
68 0x00000005, 0x800F0000, 0xB0E40000, 0x80E40000, /* mul r0, t0, r0 */
69 0x0000FFFF}; /* END */
71 static int get_refcount(IUnknown
*object
)
73 IUnknown_AddRef( object
);
74 return IUnknown_Release( object
);
77 /* try to make sure pending X events have been processed before continuing */
78 static void flush_events(void)
82 int min_timeout
= 100;
83 DWORD time
= GetTickCount() + diff
;
87 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
88 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
89 diff
= time
- GetTickCount();
93 static IDirect3DDevice8
*create_device(IDirect3D8
*d3d8
, HWND focus_window
, const struct device_desc
*desc
)
95 D3DPRESENT_PARAMETERS present_parameters
= {0};
96 IDirect3DDevice8
*device
;
97 DWORD behavior_flags
= D3DCREATE_HARDWARE_VERTEXPROCESSING
;
99 present_parameters
.BackBufferWidth
= 640;
100 present_parameters
.BackBufferHeight
= 480;
101 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
102 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
103 present_parameters
.hDeviceWindow
= focus_window
;
104 present_parameters
.Windowed
= TRUE
;
105 present_parameters
.EnableAutoDepthStencil
= TRUE
;
106 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
110 present_parameters
.BackBufferWidth
= desc
->width
;
111 present_parameters
.BackBufferHeight
= desc
->height
;
112 present_parameters
.hDeviceWindow
= desc
->device_window
;
113 present_parameters
.Windowed
= !(desc
->flags
& CREATE_DEVICE_FULLSCREEN
);
114 if (desc
->flags
& CREATE_DEVICE_SWVP_ONLY
)
115 behavior_flags
= D3DCREATE_SOFTWARE_VERTEXPROCESSING
;
116 if (desc
->flags
& CREATE_DEVICE_FPU_PRESERVE
)
117 behavior_flags
|= D3DCREATE_FPU_PRESERVE
;
120 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, focus_window
,
121 behavior_flags
, &present_parameters
, &device
)))
124 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D16
;
125 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, focus_window
,
126 behavior_flags
, &present_parameters
, &device
)))
129 if (desc
&& desc
->flags
& CREATE_DEVICE_SWVP_ONLY
)
131 behavior_flags
^= (D3DCREATE_HARDWARE_VERTEXPROCESSING
| D3DCREATE_SOFTWARE_VERTEXPROCESSING
);
133 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, focus_window
,
134 behavior_flags
, &present_parameters
, &device
)))
140 static HRESULT
reset_device(IDirect3DDevice8
*device
, const struct device_desc
*desc
)
142 D3DPRESENT_PARAMETERS present_parameters
= {0};
144 present_parameters
.BackBufferWidth
= 640;
145 present_parameters
.BackBufferHeight
= 480;
146 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
147 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
148 present_parameters
.hDeviceWindow
= NULL
;
149 present_parameters
.Windowed
= TRUE
;
150 present_parameters
.EnableAutoDepthStencil
= TRUE
;
151 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
155 present_parameters
.BackBufferWidth
= desc
->width
;
156 present_parameters
.BackBufferHeight
= desc
->height
;
157 present_parameters
.hDeviceWindow
= desc
->device_window
;
158 present_parameters
.Windowed
= !(desc
->flags
& CREATE_DEVICE_FULLSCREEN
);
161 return IDirect3DDevice8_Reset(device
, &present_parameters
);
164 #define CHECK_CALL(r,c,d,rc) \
166 int tmp1 = get_refcount( (IUnknown *)d ); \
168 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
170 trace("%s failed: %#08x\n", c, r); \
173 #define CHECK_RELEASE(obj,d,rc) \
175 int tmp1, rc_new = rc; \
176 IUnknown_Release( (IUnknown*)obj ); \
177 tmp1 = get_refcount( (IUnknown *)d ); \
178 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
181 #define CHECK_REFCOUNT(obj,rc) \
184 int count = get_refcount( (IUnknown *)obj ); \
185 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
188 #define CHECK_RELEASE_REFCOUNT(obj,rc) \
191 int count = IUnknown_Release( (IUnknown *)obj ); \
192 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
195 #define CHECK_ADDREF_REFCOUNT(obj,rc) \
198 int count = IUnknown_AddRef( (IUnknown *)obj ); \
199 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
202 #define CHECK_SURFACE_CONTAINER(obj,iid,expected) \
204 void *container_ptr = (void *)0x1337c0d3; \
205 hr = IDirect3DSurface8_GetContainer(obj, &iid, &container_ptr); \
206 ok(SUCCEEDED(hr) && container_ptr == expected, "GetContainer returned: hr %#08x, container_ptr %p. " \
207 "Expected hr %#08x, container_ptr %p\n", hr, container_ptr, S_OK, expected); \
208 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr); \
211 static void check_mipmap_levels(IDirect3DDevice8
*device
, UINT width
, UINT height
, UINT count
)
213 IDirect3DBaseTexture8
* texture
= NULL
;
214 HRESULT hr
= IDirect3DDevice8_CreateTexture( device
, width
, height
, 0, 0,
215 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, (IDirect3DTexture8
**) &texture
);
218 DWORD levels
= IDirect3DBaseTexture8_GetLevelCount(texture
);
219 ok(levels
== count
, "Invalid level count. Expected %d got %u\n", count
, levels
);
221 trace("CreateTexture failed: %#08x\n", hr
);
223 if (texture
) IDirect3DBaseTexture8_Release( texture
);
226 static void test_mipmap_levels(void)
228 IDirect3DDevice8
*device
;
233 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
234 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
235 ok(!!window
, "Failed to create a window.\n");
236 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
237 ok(!!d3d
, "Failed to create a D3D object.\n");
238 if (!(device
= create_device(d3d
, window
, NULL
)))
240 skip("Failed to create a 3D device, skipping test.\n");
244 check_mipmap_levels(device
, 32, 32, 6);
245 check_mipmap_levels(device
, 256, 1, 9);
246 check_mipmap_levels(device
, 1, 256, 9);
247 check_mipmap_levels(device
, 1, 1, 1);
249 refcount
= IDirect3DDevice8_Release(device
);
250 ok(!refcount
, "Device has %u references left.\n", refcount
);
252 IDirect3D8_Release(d3d
);
253 DestroyWindow(window
);
256 static void test_swapchain(void)
258 IDirect3DSwapChain8
*swapchain1
;
259 IDirect3DSwapChain8
*swapchain2
;
260 IDirect3DSwapChain8
*swapchain3
;
261 IDirect3DSurface8
*backbuffer
, *stereo_buffer
;
262 D3DPRESENT_PARAMETERS d3dpp
;
263 IDirect3DDevice8
*device
;
266 HWND window
, window2
;
268 struct device_desc device_desc
;
270 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
271 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
272 ok(!!window
, "Failed to create a window.\n");
273 window2
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
274 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
275 ok(!!window2
, "Failed to create a window.\n");
276 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
277 ok(!!d3d
, "Failed to create a D3D object.\n");
278 if (!(device
= create_device(d3d
, window
, NULL
)))
280 skip("Failed to create a 3D device, skipping test.\n");
284 backbuffer
= (void *)0xdeadbeef;
285 /* IDirect3DDevice8::GetBackBuffer crashes if a NULL output pointer is passed. */
286 hr
= IDirect3DDevice8_GetBackBuffer(device
, 1, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
287 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
288 ok(!backbuffer
, "The back buffer pointer is %p, expected NULL.\n", backbuffer
);
290 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
291 ok(SUCCEEDED(hr
), "Failed to get back buffer, hr %#x.\n", hr
);
292 IDirect3DSurface8_Release(backbuffer
);
294 /* The back buffer type value is ignored. */
295 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_LEFT
, &stereo_buffer
);
296 ok(SUCCEEDED(hr
), "Failed to get the back buffer, hr %#x.\n", hr
);
297 ok(stereo_buffer
== backbuffer
, "Expected left back buffer = %p, got %p.\n", backbuffer
, stereo_buffer
);
298 IDirect3DSurface8_Release(stereo_buffer
);
299 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_RIGHT
, &stereo_buffer
);
300 ok(SUCCEEDED(hr
), "Failed to get the back buffer, hr %#x.\n", hr
);
301 ok(stereo_buffer
== backbuffer
, "Expected right back buffer = %p, got %p.\n", backbuffer
, stereo_buffer
);
302 IDirect3DSurface8_Release(stereo_buffer
);
303 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, (D3DBACKBUFFER_TYPE
)0xdeadbeef, &stereo_buffer
);
304 ok(SUCCEEDED(hr
), "Failed to get the back buffer, hr %#x.\n", hr
);
305 ok(stereo_buffer
== backbuffer
, "Expected unknown buffer = %p, got %p.\n", backbuffer
, stereo_buffer
);
306 IDirect3DSurface8_Release(stereo_buffer
);
308 memset(&d3dpp
, 0, sizeof(d3dpp
));
309 d3dpp
.Windowed
= TRUE
;
310 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
311 d3dpp
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
313 /* Create a bunch of swapchains */
314 d3dpp
.BackBufferCount
= 0;
315 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain1
);
316 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%#08x)\n", hr
);
317 ok(d3dpp
.BackBufferCount
== 1, "The back buffer count in the presentparams struct is %d\n", d3dpp
.BackBufferCount
);
319 d3dpp
.BackBufferCount
= 1;
320 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain2
);
321 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%#08x)\n", hr
);
323 d3dpp
.BackBufferCount
= 2;
324 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain3
);
325 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%#08x)\n", hr
);
327 /* Swapchain 3, created with backbuffercount 2 */
328 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 0, 0, NULL
);
329 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
331 backbuffer
= (void *) 0xdeadbeef;
332 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 0, 0, &backbuffer
);
333 ok(SUCCEEDED(hr
), "Failed to get the 1st back buffer (%#08x)\n", hr
);
334 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
335 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
337 /* The back buffer type value is ignored. */
338 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 0, D3DBACKBUFFER_TYPE_LEFT
, &stereo_buffer
);
339 ok(SUCCEEDED(hr
), "Failed to get the back buffer, hr %#x.\n", hr
);
340 ok(stereo_buffer
== backbuffer
, "Expected left back buffer = %p, got %p.\n", backbuffer
, stereo_buffer
);
341 IDirect3DSurface8_Release(stereo_buffer
);
342 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 0, D3DBACKBUFFER_TYPE_RIGHT
, &stereo_buffer
);
343 ok(SUCCEEDED(hr
), "Failed to get the back buffer, hr %#x.\n", hr
);
344 ok(stereo_buffer
== backbuffer
, "Expected right back buffer = %p, got %p.\n", backbuffer
, stereo_buffer
);
345 IDirect3DSurface8_Release(stereo_buffer
);
346 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 0, (D3DBACKBUFFER_TYPE
)0xdeadbeef, &stereo_buffer
);
347 ok(SUCCEEDED(hr
), "Failed to get the back buffer, hr %#x.\n", hr
);
348 ok(stereo_buffer
== backbuffer
, "Expected unknown buffer = %p, got %p.\n", backbuffer
, stereo_buffer
);
349 IDirect3DSurface8_Release(stereo_buffer
);
351 backbuffer
= (void *) 0xdeadbeef;
352 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 1, 0, &backbuffer
);
353 ok(SUCCEEDED(hr
), "Failed to get the 2nd back buffer (%#08x)\n", hr
);
354 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
355 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
357 backbuffer
= (void *) 0xdeadbeef;
358 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 2, 0, &backbuffer
);
359 ok(hr
== D3DERR_INVALIDCALL
, "GetBackBuffer returned %#08x\n", hr
);
360 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
361 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
363 backbuffer
= (void *) 0xdeadbeef;
364 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 3, 0, &backbuffer
);
365 ok(FAILED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
366 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
367 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
370 /* Check the back buffers of the swapchains */
371 /* Swapchain 1, created with backbuffercount 0 */
372 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain1
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
373 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
374 ok(backbuffer
!= NULL
, "The back buffer is NULL (%#08x)\n", hr
);
375 if(backbuffer
) IDirect3DSurface8_Release(backbuffer
);
377 backbuffer
= (void *) 0xdeadbeef;
378 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain1
, 1, 0, &backbuffer
);
379 ok(FAILED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
380 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
381 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
383 /* Swapchain 2 - created with backbuffercount 1 */
384 backbuffer
= (void *) 0xdeadbeef;
385 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain2
, 0, 0, &backbuffer
);
386 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
387 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
388 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
390 backbuffer
= (void *) 0xdeadbeef;
391 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain2
, 1, 0, &backbuffer
);
392 ok(hr
== D3DERR_INVALIDCALL
, "GetBackBuffer returned %#08x\n", hr
);
393 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
394 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
396 backbuffer
= (void *) 0xdeadbeef;
397 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain2
, 2, 0, &backbuffer
);
398 ok(FAILED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
399 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
400 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
402 IDirect3DSwapChain8_Release(swapchain3
);
403 IDirect3DSwapChain8_Release(swapchain2
);
404 IDirect3DSwapChain8_Release(swapchain1
);
406 d3dpp
.Windowed
= FALSE
;
407 d3dpp
.hDeviceWindow
= window
;
408 d3dpp
.BackBufferCount
= 1;
409 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain1
);
410 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x\n", hr
);
411 d3dpp
.hDeviceWindow
= window2
;
412 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain1
);
413 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x\n", hr
);
415 device_desc
.width
= registry_mode
.dmPelsWidth
;
416 device_desc
.height
= registry_mode
.dmPelsHeight
;
417 device_desc
.device_window
= window
;
418 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
419 hr
= reset_device(device
, &device_desc
);
420 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
422 d3dpp
.hDeviceWindow
= window
;
423 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain1
);
424 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x\n", hr
);
425 d3dpp
.hDeviceWindow
= window2
;
426 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain1
);
427 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x\n", hr
);
428 d3dpp
.Windowed
= TRUE
;
429 d3dpp
.hDeviceWindow
= window
;
430 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain1
);
431 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x\n", hr
);
432 d3dpp
.hDeviceWindow
= window2
;
433 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain1
);
434 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x\n", hr
);
436 refcount
= IDirect3DDevice8_Release(device
);
437 ok(!refcount
, "Device has %u references left.\n", refcount
);
439 IDirect3D8_Release(d3d
);
440 DestroyWindow(window2
);
441 DestroyWindow(window
);
444 static void test_refcount(void)
446 IDirect3DVertexBuffer8
*pVertexBuffer
= NULL
;
447 IDirect3DIndexBuffer8
*pIndexBuffer
= NULL
;
448 DWORD dVertexShader
= -1;
449 DWORD dPixelShader
= -1;
450 IDirect3DCubeTexture8
*pCubeTexture
= NULL
;
451 IDirect3DTexture8
*pTexture
= NULL
;
452 IDirect3DVolumeTexture8
*pVolumeTexture
= NULL
;
453 IDirect3DVolume8
*pVolumeLevel
= NULL
;
454 IDirect3DSurface8
*pStencilSurface
= NULL
;
455 IDirect3DSurface8
*pImageSurface
= NULL
;
456 IDirect3DSurface8
*pRenderTarget
= NULL
;
457 IDirect3DSurface8
*pRenderTarget2
= NULL
;
458 IDirect3DSurface8
*pRenderTarget3
= NULL
;
459 IDirect3DSurface8
*pTextureLevel
= NULL
;
460 IDirect3DSurface8
*pBackBuffer
= NULL
;
461 DWORD dStateBlock
= -1;
462 IDirect3DSwapChain8
*pSwapChain
= NULL
;
464 D3DPRESENT_PARAMETERS d3dpp
;
465 IDirect3DDevice8
*device
= NULL
;
466 ULONG refcount
= 0, tmp
;
467 IDirect3D8
*d3d
, *d3d2
;
474 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
475 D3DVSD_REG(D3DVSDE_DIFFUSE
, D3DVSDT_D3DCOLOR
), /* D3DVSDE_DIFFUSE, Register v5 */
479 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
480 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
481 ok(!!window
, "Failed to create a window.\n");
482 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
483 ok(!!d3d
, "Failed to create a D3D object.\n");
485 CHECK_REFCOUNT(d3d
, 1);
487 if (!(device
= create_device(d3d
, window
, NULL
)))
489 skip("Failed to create a 3D device, skipping test.\n");
493 IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
495 refcount
= get_refcount((IUnknown
*)device
);
496 ok(refcount
== 1, "Invalid device RefCount %d\n", refcount
);
498 CHECK_REFCOUNT(d3d
, 2);
500 hr
= IDirect3DDevice8_GetDirect3D(device
, &d3d2
);
501 CHECK_CALL(hr
, "GetDirect3D", device
, refcount
);
503 ok(d3d2
== d3d
, "Expected IDirect3D8 pointers to be equal.\n");
504 CHECK_REFCOUNT(d3d
, 3);
505 CHECK_RELEASE_REFCOUNT(d3d
, 2);
508 * Check refcount of implicit surfaces. Findings:
509 * - the container is the device
510 * - they hold a reference to the device
511 * - they are created with a refcount of 0 (Get/Release returns original refcount)
512 * - they are not freed if refcount reaches 0.
513 * - the refcount is not forwarded to the container.
515 hr
= IDirect3DDevice8_GetRenderTarget(device
, &pRenderTarget
);
516 CHECK_CALL(hr
, "GetRenderTarget", device
, ++refcount
);
519 CHECK_SURFACE_CONTAINER(pRenderTarget
, IID_IDirect3DDevice8
, device
);
520 CHECK_REFCOUNT( pRenderTarget
, 1);
522 CHECK_ADDREF_REFCOUNT(pRenderTarget
, 2);
523 CHECK_REFCOUNT(device
, refcount
);
524 CHECK_RELEASE_REFCOUNT(pRenderTarget
, 1);
525 CHECK_REFCOUNT(device
, refcount
);
527 hr
= IDirect3DDevice8_GetRenderTarget(device
, &pRenderTarget
);
528 CHECK_CALL(hr
, "GetRenderTarget", device
, refcount
);
529 CHECK_REFCOUNT( pRenderTarget
, 2);
530 CHECK_RELEASE_REFCOUNT( pRenderTarget
, 1);
531 CHECK_RELEASE_REFCOUNT( pRenderTarget
, 0);
532 CHECK_REFCOUNT(device
, --refcount
);
534 /* The render target is released with the device, so AddRef with refcount=0 is fine here. */
535 CHECK_ADDREF_REFCOUNT(pRenderTarget
, 1);
536 CHECK_REFCOUNT(device
, ++refcount
);
537 CHECK_RELEASE_REFCOUNT(pRenderTarget
, 0);
538 CHECK_REFCOUNT(device
, --refcount
);
541 /* Render target and back buffer are identical. */
542 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, 0, &pBackBuffer
);
543 CHECK_CALL(hr
, "GetBackBuffer", device
, ++refcount
);
546 CHECK_RELEASE_REFCOUNT(pBackBuffer
, 0);
547 ok(pRenderTarget
== pBackBuffer
, "RenderTarget=%p and BackBuffer=%p should be the same.\n",
548 pRenderTarget
, pBackBuffer
);
551 CHECK_REFCOUNT(device
, --refcount
);
553 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &pStencilSurface
);
554 CHECK_CALL(hr
, "GetDepthStencilSurface", device
, ++refcount
);
557 CHECK_SURFACE_CONTAINER(pStencilSurface
, IID_IDirect3DDevice8
, device
);
558 CHECK_REFCOUNT( pStencilSurface
, 1);
560 CHECK_ADDREF_REFCOUNT(pStencilSurface
, 2);
561 CHECK_REFCOUNT(device
, refcount
);
562 CHECK_RELEASE_REFCOUNT(pStencilSurface
, 1);
563 CHECK_REFCOUNT(device
, refcount
);
565 CHECK_RELEASE_REFCOUNT( pStencilSurface
, 0);
566 CHECK_REFCOUNT(device
, --refcount
);
568 /* The stencil surface is released with the device, so AddRef with refcount=0 is fine here. */
569 CHECK_ADDREF_REFCOUNT(pStencilSurface
, 1);
570 CHECK_REFCOUNT(device
, ++refcount
);
571 CHECK_RELEASE_REFCOUNT(pStencilSurface
, 0);
572 CHECK_REFCOUNT(device
, --refcount
);
573 pStencilSurface
= NULL
;
577 hr
= IDirect3DDevice8_CreateIndexBuffer(device
, 16, 0, D3DFMT_INDEX32
, D3DPOOL_DEFAULT
, &pIndexBuffer
);
578 CHECK_CALL(hr
, "CreateIndexBuffer", device
, ++refcount
);
581 tmp
= get_refcount( (IUnknown
*)pIndexBuffer
);
583 hr
= IDirect3DDevice8_SetIndices(device
, pIndexBuffer
, 0);
584 CHECK_CALL( hr
, "SetIndices", pIndexBuffer
, tmp
);
585 hr
= IDirect3DDevice8_SetIndices(device
, NULL
, 0);
586 CHECK_CALL( hr
, "SetIndices", pIndexBuffer
, tmp
);
589 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, 16, 0, D3DFVF_XYZ
, D3DPOOL_DEFAULT
, &pVertexBuffer
);
590 CHECK_CALL(hr
, "CreateVertexBuffer", device
, ++refcount
);
593 IDirect3DVertexBuffer8
*pVBuf
= (void*)~0;
596 tmp
= get_refcount( (IUnknown
*)pVertexBuffer
);
598 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, pVertexBuffer
, 3 * sizeof(float));
599 CHECK_CALL( hr
, "SetStreamSource", pVertexBuffer
, tmp
);
600 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, NULL
, 0);
601 CHECK_CALL( hr
, "SetStreamSource", pVertexBuffer
, tmp
);
603 hr
= IDirect3DDevice8_GetStreamSource(device
, 0, &pVBuf
, &stride
);
604 ok(SUCCEEDED(hr
), "GetStreamSource did not succeed with NULL stream!\n");
605 ok(pVBuf
==NULL
, "pVBuf not NULL (%p)!\n", pVBuf
);
606 ok(stride
==3*sizeof(float), "stride not 3 floats (got %u)!\n", stride
);
610 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, simple_vs
, &dVertexShader
, 0);
611 CHECK_CALL(hr
, "CreateVertexShader", device
, refcount
);
612 if (caps
.PixelShaderVersion
>= D3DPS_VERSION(1, 0))
614 hr
= IDirect3DDevice8_CreatePixelShader(device
, simple_ps
, &dPixelShader
);
615 CHECK_CALL(hr
, "CreatePixelShader", device
, refcount
);
618 hr
= IDirect3DDevice8_CreateTexture(device
, 32, 32, 3, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pTexture
);
619 CHECK_CALL(hr
, "CreateTexture", device
, ++refcount
);
622 tmp
= get_refcount( (IUnknown
*)pTexture
);
624 /* SetTexture should not increase refcounts */
625 hr
= IDirect3DDevice8_SetTexture(device
, 0, (IDirect3DBaseTexture8
*) pTexture
);
626 CHECK_CALL( hr
, "SetTexture", pTexture
, tmp
);
627 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
628 CHECK_CALL( hr
, "SetTexture", pTexture
, tmp
);
630 /* This should not increment device refcount */
631 hr
= IDirect3DTexture8_GetSurfaceLevel( pTexture
, 1, &pTextureLevel
);
632 CHECK_CALL(hr
, "GetSurfaceLevel", device
, refcount
);
633 /* But should increment texture's refcount */
634 CHECK_REFCOUNT( pTexture
, tmp
+1 );
635 /* Because the texture and surface refcount are identical */
638 CHECK_REFCOUNT ( pTextureLevel
, tmp
+1 );
639 CHECK_ADDREF_REFCOUNT ( pTextureLevel
, tmp
+2 );
640 CHECK_REFCOUNT ( pTexture
, tmp
+2 );
641 CHECK_RELEASE_REFCOUNT( pTextureLevel
, tmp
+1 );
642 CHECK_REFCOUNT ( pTexture
, tmp
+1 );
643 CHECK_RELEASE_REFCOUNT( pTexture
, tmp
);
644 CHECK_REFCOUNT ( pTextureLevel
, tmp
);
647 if(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
)
649 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 32, 0, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pCubeTexture
);
650 CHECK_CALL(hr
, "CreateCubeTexture", device
, ++refcount
);
654 skip("Cube textures not supported\n");
656 if(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
)
658 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 32, 32, 2, 0, 0,
659 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pVolumeTexture
);
660 CHECK_CALL(hr
, "CreateVolumeTexture", device
, ++refcount
);
664 skip("Volume textures not supported\n");
669 tmp
= get_refcount( (IUnknown
*)pVolumeTexture
);
671 /* This should not increment device refcount */
672 hr
= IDirect3DVolumeTexture8_GetVolumeLevel(pVolumeTexture
, 0, &pVolumeLevel
);
673 CHECK_CALL(hr
, "GetVolumeLevel", device
, refcount
);
674 /* But should increment volume texture's refcount */
675 CHECK_REFCOUNT( pVolumeTexture
, tmp
+1 );
676 /* Because the volume texture and volume refcount are identical */
679 CHECK_REFCOUNT ( pVolumeLevel
, tmp
+1 );
680 CHECK_ADDREF_REFCOUNT ( pVolumeLevel
, tmp
+2 );
681 CHECK_REFCOUNT ( pVolumeTexture
, tmp
+2 );
682 CHECK_RELEASE_REFCOUNT( pVolumeLevel
, tmp
+1 );
683 CHECK_REFCOUNT ( pVolumeTexture
, tmp
+1 );
684 CHECK_RELEASE_REFCOUNT( pVolumeTexture
, tmp
);
685 CHECK_REFCOUNT ( pVolumeLevel
, tmp
);
689 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 32, 32,
690 D3DFMT_D16
, D3DMULTISAMPLE_NONE
, &pStencilSurface
);
691 CHECK_CALL(hr
, "CreateDepthStencilSurface", device
, ++refcount
);
692 CHECK_REFCOUNT( pStencilSurface
, 1);
693 hr
= IDirect3DDevice8_CreateImageSurface(device
, 32, 32,
694 D3DFMT_X8R8G8B8
, &pImageSurface
);
695 CHECK_CALL(hr
, "CreateImageSurface", device
, ++refcount
);
696 CHECK_REFCOUNT( pImageSurface
, 1);
697 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 32, 32,
698 D3DFMT_X8R8G8B8
, D3DMULTISAMPLE_NONE
, TRUE
, &pRenderTarget3
);
699 CHECK_CALL(hr
, "CreateRenderTarget", device
, ++refcount
);
700 CHECK_REFCOUNT( pRenderTarget3
, 1);
702 hr
= IDirect3DDevice8_CreateStateBlock(device
, D3DSBT_ALL
, &dStateBlock
);
703 CHECK_CALL(hr
, "CreateStateBlock", device
, refcount
);
705 memset(&d3dpp
, 0, sizeof(d3dpp
));
706 d3dpp
.Windowed
= TRUE
;
707 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
708 d3dpp
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
709 d3dpp
.EnableAutoDepthStencil
= TRUE
;
710 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
711 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &pSwapChain
);
712 CHECK_CALL(hr
, "CreateAdditionalSwapChain", device
, ++refcount
);
715 /* check implicit back buffer */
716 hr
= IDirect3DSwapChain8_GetBackBuffer(pSwapChain
, 0, 0, &pBackBuffer
);
717 CHECK_CALL(hr
, "GetBackBuffer", device
, ++refcount
);
718 CHECK_REFCOUNT( pSwapChain
, 1);
721 CHECK_SURFACE_CONTAINER(pBackBuffer
, IID_IDirect3DDevice8
, device
);
722 CHECK_REFCOUNT( pBackBuffer
, 1);
723 CHECK_RELEASE_REFCOUNT( pBackBuffer
, 0);
724 CHECK_REFCOUNT(device
, --refcount
);
726 /* The back buffer is released with the swapchain, so AddRef with refcount=0 is fine here. */
727 CHECK_ADDREF_REFCOUNT(pBackBuffer
, 1);
728 CHECK_REFCOUNT(device
, ++refcount
);
729 CHECK_RELEASE_REFCOUNT(pBackBuffer
, 0);
730 CHECK_REFCOUNT(device
, --refcount
);
733 CHECK_REFCOUNT( pSwapChain
, 1);
739 /* Vertex buffers can be locked multiple times */
740 hr
= IDirect3DVertexBuffer8_Lock(pVertexBuffer
, 0, 0, &data
, 0);
741 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr
);
742 hr
= IDirect3DVertexBuffer8_Lock(pVertexBuffer
, 0, 0, &data
, 0);
743 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr
);
744 hr
= IDirect3DVertexBuffer8_Unlock(pVertexBuffer
);
745 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr
);
746 hr
= IDirect3DVertexBuffer8_Unlock(pVertexBuffer
);
747 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr
);
750 /* The implicit render target is not freed if refcount reaches 0.
751 * Otherwise GetRenderTarget would re-allocate it and the pointer would change.*/
752 hr
= IDirect3DDevice8_GetRenderTarget(device
, &pRenderTarget2
);
753 CHECK_CALL(hr
, "GetRenderTarget", device
, ++refcount
);
756 CHECK_RELEASE_REFCOUNT(pRenderTarget2
, 0);
757 ok(pRenderTarget
== pRenderTarget2
, "RenderTarget=%p and RenderTarget2=%p should be the same.\n",
758 pRenderTarget
, pRenderTarget2
);
759 CHECK_REFCOUNT(device
, --refcount
);
760 pRenderTarget2
= NULL
;
762 pRenderTarget
= NULL
;
765 CHECK_RELEASE(device
, device
, --refcount
);
768 CHECK_RELEASE(pVertexBuffer
, device
, --refcount
);
769 CHECK_RELEASE(pIndexBuffer
, device
, --refcount
);
771 if (dVertexShader
!= ~0u)
772 IDirect3DDevice8_DeleteVertexShader(device
, dVertexShader
);
773 if (dPixelShader
!= ~0u)
774 IDirect3DDevice8_DeletePixelShader(device
, dPixelShader
);
776 CHECK_RELEASE(pTexture
, device
, --refcount
);
777 CHECK_RELEASE(pCubeTexture
, device
, --refcount
);
778 CHECK_RELEASE(pVolumeTexture
, device
, --refcount
);
780 CHECK_RELEASE(pStencilSurface
, device
, --refcount
);
781 CHECK_RELEASE(pImageSurface
, device
, --refcount
);
782 CHECK_RELEASE(pRenderTarget3
, device
, --refcount
);
784 if (dStateBlock
!= ~0u)
785 IDirect3DDevice8_DeleteStateBlock(device
, dStateBlock
);
786 /* This will destroy device - cannot check the refcount here */
788 CHECK_RELEASE_REFCOUNT(pSwapChain
, 0);
789 CHECK_RELEASE_REFCOUNT(d3d
, 0);
790 DestroyWindow(window
);
793 static void test_checkdevicemultisampletype(void)
799 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
800 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
801 ok(!!window
, "Failed to create a window.\n");
802 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
803 ok(!!d3d
, "Failed to create a D3D object.\n");
805 if (IDirect3D8_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
806 D3DFMT_X8R8G8B8
, TRUE
, D3DMULTISAMPLE_2_SAMPLES
) == D3DERR_NOTAVAILABLE
)
808 skip("Multisampling not supported for D3DFMT_X8R8G8B8, skipping test.\n");
812 hr
= IDirect3D8_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
813 D3DFMT_UNKNOWN
, TRUE
, D3DMULTISAMPLE_NONE
);
814 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
815 hr
= IDirect3D8_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
816 65536, TRUE
, D3DMULTISAMPLE_NONE
);
817 todo_wine
ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
819 hr
= IDirect3D8_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
820 D3DFMT_X8R8G8B8
, TRUE
, D3DMULTISAMPLE_NONE
);
821 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
822 hr
= IDirect3D8_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
823 D3DFMT_X8R8G8B8
, FALSE
, D3DMULTISAMPLE_NONE
);
824 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
826 hr
= IDirect3D8_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
827 D3DFMT_X8R8G8B8
, TRUE
, D3DMULTISAMPLE_2_SAMPLES
);
828 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
830 /* We assume D3DMULTISAMPLE_15_SAMPLES is never supported in practice. */
831 hr
= IDirect3D8_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
832 D3DFMT_X8R8G8B8
, TRUE
, D3DMULTISAMPLE_15_SAMPLES
);
833 ok(hr
== D3DERR_NOTAVAILABLE
, "Got unexpected hr %#x.\n", hr
);
835 hr
= IDirect3D8_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
836 D3DFMT_X8R8G8B8
, TRUE
, 65536);
837 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
839 hr
= IDirect3D8_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
840 D3DFMT_DXT5
, TRUE
, D3DMULTISAMPLE_2_SAMPLES
);
841 ok(hr
== D3DERR_NOTAVAILABLE
, "Got unexpected hr %#x.\n", hr
);
844 IDirect3D8_Release(d3d
);
845 DestroyWindow(window
);
848 static void test_cursor(void)
850 HMODULE user32_handle
= GetModuleHandleA("user32.dll");
851 IDirect3DSurface8
*cursor
= NULL
;
852 IDirect3DDevice8
*device
;
861 pGetCursorInfo
= (void *)GetProcAddress(user32_handle
, "GetCursorInfo");
864 win_skip("GetCursorInfo is not available\n");
868 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
869 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
870 ok(!!window
, "Failed to create a window.\n");
872 ret
= SetCursorPos(50, 50);
873 ok(ret
, "Failed to set cursor position.\n");
876 memset(&info
, 0, sizeof(info
));
877 info
.cbSize
= sizeof(info
);
878 ok(pGetCursorInfo(&info
), "GetCursorInfo failed\n");
881 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
882 ok(!!d3d
, "Failed to create a D3D object.\n");
883 if (!(device
= create_device(d3d
, window
, NULL
)))
885 skip("Failed to create a 3D device, skipping test.\n");
889 hr
= IDirect3DDevice8_CreateImageSurface(device
, 32, 32, D3DFMT_A8R8G8B8
, &cursor
);
890 ok(SUCCEEDED(hr
), "Failed to create cursor surface, hr %#x.\n", hr
);
892 /* Initially hidden */
893 ret
= IDirect3DDevice8_ShowCursor(device
, TRUE
);
894 ok(!ret
, "IDirect3DDevice8_ShowCursor returned %d\n", ret
);
896 /* Not enabled without a surface*/
897 ret
= IDirect3DDevice8_ShowCursor(device
, TRUE
);
898 ok(!ret
, "IDirect3DDevice8_ShowCursor returned %d\n", ret
);
901 hr
= IDirect3DDevice8_SetCursorProperties(device
, 0, 0, NULL
);
902 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr
);
904 hr
= IDirect3DDevice8_SetCursorProperties(device
, 0, 0, cursor
);
905 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr
);
907 IDirect3DSurface8_Release(cursor
);
909 memset(&info
, 0, sizeof(info
));
910 info
.cbSize
= sizeof(info
);
911 ok(pGetCursorInfo(&info
), "GetCursorInfo failed\n");
912 ok(info
.flags
& (CURSOR_SHOWING
|CURSOR_SUPPRESSED
), "The gdi cursor is hidden (%08x)\n", info
.flags
);
913 ok(info
.hCursor
== cur
, "The cursor handle is %p\n", info
.hCursor
); /* unchanged */
916 ret
= IDirect3DDevice8_ShowCursor(device
, TRUE
);
917 ok(!ret
, "IDirect3DDevice8_ShowCursor returned %d\n", ret
);
920 ret
= IDirect3DDevice8_ShowCursor(device
, TRUE
);
921 ok(ret
, "IDirect3DDevice8_ShowCursor returned %d\n", ret
);
923 memset(&info
, 0, sizeof(info
));
924 info
.cbSize
= sizeof(info
);
925 ok(pGetCursorInfo(&info
), "GetCursorInfo failed\n");
926 ok(info
.flags
& (CURSOR_SHOWING
|CURSOR_SUPPRESSED
), "The gdi cursor is hidden (%08x)\n", info
.flags
);
927 ok(info
.hCursor
!= cur
, "The cursor handle is %p\n", info
.hCursor
);
929 refcount
= IDirect3DDevice8_Release(device
);
930 ok(!refcount
, "Device has %u references left.\n", refcount
);
932 IDirect3D8_Release(d3d
);
933 DestroyWindow(window
);
936 static const POINT
*expect_pos
;
938 static LRESULT CALLBACK
test_cursor_proc(HWND window
, UINT message
, WPARAM wparam
, LPARAM lparam
)
940 if (message
== WM_MOUSEMOVE
)
942 if (expect_pos
&& expect_pos
->x
&& expect_pos
->y
)
944 POINT p
= {GET_X_LPARAM(lparam
), GET_Y_LPARAM(lparam
)};
946 ClientToScreen(window
, &p
);
947 if (expect_pos
->x
== p
.x
&& expect_pos
->y
== p
.y
)
952 return DefWindowProcA(window
, message
, wparam
, lparam
);
955 static void test_cursor_pos(void)
957 IDirect3DSurface8
*cursor
;
958 IDirect3DDevice8
*device
;
966 /* Note that we don't check for movement we're not supposed to receive.
967 * That's because it's hard to distinguish from the user accidentally
968 * moving the mouse. */
969 static const POINT points
[] =
982 wc
.lpfnWndProc
= test_cursor_proc
;
983 wc
.lpszClassName
= "d3d8_test_cursor_wc";
984 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
985 window
= CreateWindowA("d3d8_test_cursor_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
986 0, 0, 320, 240, NULL
, NULL
, NULL
, NULL
);
987 ShowWindow(window
, SW_SHOW
);
988 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
989 ok(!!d3d8
, "Failed to create a D3D object.\n");
991 if (!(device
= create_device(d3d8
, window
, NULL
)))
993 skip("Failed to create a D3D device, skipping tests.\n");
997 hr
= IDirect3DDevice8_CreateImageSurface(device
, 32, 32, D3DFMT_A8R8G8B8
, &cursor
);
998 ok(SUCCEEDED(hr
), "Failed to create cursor surface, hr %#x.\n", hr
);
999 hr
= IDirect3DDevice8_SetCursorProperties(device
, 0, 0, cursor
);
1000 ok(SUCCEEDED(hr
), "Failed to set cursor properties, hr %#x.\n", hr
);
1001 IDirect3DSurface8_Release(cursor
);
1002 ret
= IDirect3DDevice8_ShowCursor(device
, TRUE
);
1003 ok(!ret
, "Failed to show cursor, hr %#x.\n", ret
);
1006 expect_pos
= points
;
1008 ret
= SetCursorPos(50, 50);
1009 ok(ret
, "Failed to set cursor position.\n");
1012 IDirect3DDevice8_SetCursorPosition(device
, 75, 75, 0);
1014 /* SetCursorPosition() eats duplicates. */
1015 IDirect3DDevice8_SetCursorPosition(device
, 75, 75, 0);
1018 ret
= SetCursorPos(100, 100);
1019 ok(ret
, "Failed to set cursor position.\n");
1021 /* Even if the position was set with SetCursorPos(). */
1022 IDirect3DDevice8_SetCursorPosition(device
, 100, 100, 0);
1025 IDirect3DDevice8_SetCursorPosition(device
, 125, 125, 0);
1027 ret
= SetCursorPos(150, 150);
1028 ok(ret
, "Failed to set cursor position.\n");
1030 IDirect3DDevice8_SetCursorPosition(device
, 125, 125, 0);
1033 IDirect3DDevice8_SetCursorPosition(device
, 150, 150, 0);
1035 /* SetCursorPos() doesn't. */
1036 ret
= SetCursorPos(150, 150);
1037 ok(ret
, "Failed to set cursor position.\n");
1040 ok(!expect_pos
->x
&& !expect_pos
->y
, "Didn't receive MOUSEMOVE %u (%d, %d).\n",
1041 (unsigned)(expect_pos
- points
), expect_pos
->x
, expect_pos
->y
);
1043 refcount
= IDirect3DDevice8_Release(device
);
1044 ok(!refcount
, "Device has %u references left.\n", refcount
);
1046 DestroyWindow(window
);
1047 UnregisterClassA("d3d8_test_cursor_wc", GetModuleHandleA(NULL
));
1048 IDirect3D8_Release(d3d8
);
1051 static void test_states(void)
1053 IDirect3DDevice8
*device
;
1059 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
1060 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
1061 ok(!!window
, "Failed to create a window.\n");
1062 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
1063 ok(!!d3d
, "Failed to create a D3D object.\n");
1064 if (!(device
= create_device(d3d
, window
, NULL
)))
1066 skip("Failed to create a 3D device, skipping test.\n");
1070 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZVISIBLE
, TRUE
);
1071 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, TRUE) returned %#08x\n", hr
);
1072 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZVISIBLE
, FALSE
);
1073 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, FALSE) returned %#08x\n", hr
);
1075 refcount
= IDirect3DDevice8_Release(device
);
1076 ok(!refcount
, "Device has %u references left.\n", refcount
);
1078 IDirect3D8_Release(d3d
);
1079 DestroyWindow(window
);
1082 static void test_shader_versions(void)
1088 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
1089 ok(!!d3d
, "Failed to create a D3D object.\n");
1091 hr
= IDirect3D8_GetDeviceCaps(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, &caps
);
1092 ok(SUCCEEDED(hr
) || hr
== D3DERR_NOTAVAILABLE
, "Failed to get device caps, hr %#x.\n", hr
);
1093 IDirect3D8_Release(d3d
);
1096 skip("No Direct3D support, skipping test.\n");
1100 ok(caps
.VertexShaderVersion
<= D3DVS_VERSION(1,1),
1101 "Got unexpected VertexShaderVersion %#x.\n", caps
.VertexShaderVersion
);
1102 ok(caps
.PixelShaderVersion
<= D3DPS_VERSION(1,4),
1103 "Got unexpected PixelShaderVersion %#x.\n", caps
.PixelShaderVersion
);
1106 static void test_display_formats(void)
1108 D3DDEVTYPE device_type
= D3DDEVTYPE_HAL
;
1109 unsigned int backbuffer
, display
;
1110 unsigned int windowed
, i
;
1111 D3DDISPLAYMODE mode
;
1121 D3DFORMAT alpha_format
;
1127 {"D3DFMT_R5G6B5", D3DFMT_R5G6B5
, 0, TRUE
, TRUE
},
1128 {"D3DFMT_X1R5G5B5", D3DFMT_X1R5G5B5
, D3DFMT_A1R5G5B5
, TRUE
, TRUE
},
1129 {"D3DFMT_A1R5G5B5", D3DFMT_A1R5G5B5
, D3DFMT_A1R5G5B5
, FALSE
, FALSE
},
1130 {"D3DFMT_X8R8G8B8", D3DFMT_X8R8G8B8
, D3DFMT_A8R8G8B8
, TRUE
, TRUE
},
1131 {"D3DFMT_A8R8G8B8", D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
, FALSE
, FALSE
},
1132 {"D3DFMT_UNKNOWN", D3DFMT_UNKNOWN
, 0, FALSE
, FALSE
},
1135 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
1136 ok(!!d3d8
, "Failed to create a D3D object.\n");
1138 for (display
= 0; display
< sizeof(formats
) / sizeof(*formats
); ++display
)
1140 for (i
= 0, has_modes
= FALSE
; SUCCEEDED(IDirect3D8_EnumAdapterModes(d3d8
, D3DADAPTER_DEFAULT
, i
, &mode
)); ++i
)
1142 if (mode
.Format
== formats
[display
].format
)
1149 for (windowed
= 0; windowed
<= 1; ++windowed
)
1151 for (backbuffer
= 0; backbuffer
< sizeof(formats
) / sizeof(*formats
); ++backbuffer
)
1153 should_pass
= FALSE
;
1155 if (formats
[display
].display
&& (formats
[display
].windowed
|| !windowed
) && (has_modes
|| windowed
))
1157 D3DFORMAT backbuffer_format
;
1159 if (windowed
&& formats
[backbuffer
].format
== D3DFMT_UNKNOWN
)
1160 backbuffer_format
= formats
[display
].format
;
1162 backbuffer_format
= formats
[backbuffer
].format
;
1164 hr
= IDirect3D8_CheckDeviceFormat(d3d8
, D3DADAPTER_DEFAULT
, device_type
, formats
[display
].format
,
1165 D3DUSAGE_RENDERTARGET
, D3DRTYPE_SURFACE
, backbuffer_format
);
1166 should_pass
= (hr
== D3D_OK
) && (formats
[display
].format
== formats
[backbuffer
].format
1167 || (formats
[display
].alpha_format
1168 && formats
[display
].alpha_format
== formats
[backbuffer
].alpha_format
));
1171 hr
= IDirect3D8_CheckDeviceType(d3d8
, D3DADAPTER_DEFAULT
, device_type
,
1172 formats
[display
].format
, formats
[backbuffer
].format
, windowed
);
1173 ok(SUCCEEDED(hr
) == should_pass
|| broken(SUCCEEDED(hr
) && !has_modes
) /* Win8 64-bit */,
1174 "Got unexpected hr %#x for %s / %s, windowed %#x, should_pass %#x.\n",
1175 hr
, formats
[display
].name
, formats
[backbuffer
].name
, windowed
, should_pass
);
1180 IDirect3D8_Release(d3d8
);
1183 /* Test adapter display modes */
1184 static void test_display_modes(void)
1187 D3DDISPLAYMODE dmode
;
1191 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
1192 ok(!!d3d
, "Failed to create a D3D object.\n");
1194 max_modes
= IDirect3D8_GetAdapterModeCount(d3d
, D3DADAPTER_DEFAULT
);
1196 broken(max_modes
== 0), /* VMware */
1197 "GetAdapterModeCount(D3DADAPTER_DEFAULT) returned 0!\n");
1199 for (i
= 0; i
< max_modes
; ++i
)
1201 res
= IDirect3D8_EnumAdapterModes(d3d
, D3DADAPTER_DEFAULT
, i
, &dmode
);
1202 ok(res
==D3D_OK
, "EnumAdapterModes returned %#08x for mode %u!\n", res
, i
);
1206 ok(dmode
.Format
==D3DFMT_X8R8G8B8
|| dmode
.Format
==D3DFMT_R5G6B5
,
1207 "Unexpected display mode returned for mode %u: %#x\n", i
, dmode
.Format
);
1210 IDirect3D8_Release(d3d
);
1213 static void test_reset(void)
1215 UINT width
, orig_width
= GetSystemMetrics(SM_CXSCREEN
);
1216 UINT height
, orig_height
= GetSystemMetrics(SM_CYSCREEN
);
1217 IDirect3DDevice8
*device1
= NULL
;
1218 IDirect3DDevice8
*device2
= NULL
;
1219 struct device_desc device_desc
;
1220 D3DDISPLAYMODE d3ddm
, d3ddm2
;
1221 D3DSURFACE_DESC surface_desc
;
1222 D3DPRESENT_PARAMETERS d3dpp
;
1223 IDirect3DSurface8
*surface
;
1224 IDirect3DTexture8
*texture
;
1225 UINT adapter_mode_count
;
1226 D3DLOCKED_RECT lockrect
;
1227 UINT mode_count
= 0;
1238 static const DWORD decl
[] =
1241 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT4
),
1251 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
1252 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1253 ok(!!window
, "Failed to create a window.\n");
1254 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
1255 ok(!!d3d8
, "Failed to create a D3D object.\n");
1257 hr
= IDirect3D8_GetAdapterDisplayMode(d3d8
, D3DADAPTER_DEFAULT
, &d3ddm
);
1258 ok(SUCCEEDED(hr
), "GetAdapterDisplayMode failed, hr %#x.\n", hr
);
1259 adapter_mode_count
= IDirect3D8_GetAdapterModeCount(d3d8
, D3DADAPTER_DEFAULT
);
1260 modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(*modes
) * adapter_mode_count
);
1261 for (i
= 0; i
< adapter_mode_count
; ++i
)
1265 memset(&d3ddm2
, 0, sizeof(d3ddm2
));
1266 hr
= IDirect3D8_EnumAdapterModes(d3d8
, D3DADAPTER_DEFAULT
, i
, &d3ddm2
);
1267 ok(SUCCEEDED(hr
), "EnumAdapterModes failed, hr %#x.\n", hr
);
1269 if (d3ddm2
.Format
!= d3ddm
.Format
)
1272 for (j
= 0; j
< mode_count
; ++j
)
1274 if (modes
[j
].w
== d3ddm2
.Width
&& modes
[j
].h
== d3ddm2
.Height
)
1277 if (j
== mode_count
)
1279 modes
[j
].w
= d3ddm2
.Width
;
1280 modes
[j
].h
= d3ddm2
.Height
;
1284 /* We use them as invalid modes. */
1285 if ((d3ddm2
.Width
== 801 && d3ddm2
.Height
== 600)
1286 || (d3ddm2
.Width
== 32 && d3ddm2
.Height
== 32))
1288 skip("This system supports a screen resolution of %dx%d, not running mode tests.\n",
1289 d3ddm2
.Width
, d3ddm2
.Height
);
1296 skip("Less than 2 modes supported, skipping mode tests.\n");
1301 if (modes
[i
].w
== orig_width
&& modes
[i
].h
== orig_height
) ++i
;
1303 device_desc
.width
= modes
[i
].w
;
1304 device_desc
.height
= modes
[i
].h
;
1305 device_desc
.device_window
= window
;
1306 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
| CREATE_DEVICE_SWVP_ONLY
;
1307 if (!(device1
= create_device(d3d8
, window
, &device_desc
)))
1309 skip("Failed to create a D3D device, skipping tests.\n");
1312 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1313 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1315 hr
= IDirect3DDevice8_GetDeviceCaps(device1
, &caps
);
1316 ok(SUCCEEDED(hr
), "GetDeviceCaps failed, hr %#x.\n", hr
);
1318 width
= GetSystemMetrics(SM_CXSCREEN
);
1319 height
= GetSystemMetrics(SM_CYSCREEN
);
1320 ok(width
== modes
[i
].w
, "Screen width is %u, expected %u.\n", width
, modes
[i
].w
);
1321 ok(height
== modes
[i
].h
, "Screen height is %u, expected %u.\n", height
, modes
[i
].h
);
1323 hr
= IDirect3DDevice8_GetViewport(device1
, &vp
);
1324 ok(SUCCEEDED(hr
), "GetViewport failed, hr %#x.\n", hr
);
1327 ok(vp
.X
== 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp
.X
);
1328 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp
.Y
);
1329 ok(vp
.Width
== modes
[i
].w
, "D3DVIEWPORT->Width = %u, expected %u.\n", vp
.Width
, modes
[i
].w
);
1330 ok(vp
.Height
== modes
[i
].h
, "D3DVIEWPORT->Height = %u, expected %u.\n", vp
.Height
, modes
[i
].h
);
1331 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp
.MinZ
);
1332 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp
.MaxZ
);
1338 vp
.Width
= modes
[i
].w
/ 2;
1339 vp
.Height
= modes
[i
].h
/ 2;
1342 hr
= IDirect3DDevice8_SetViewport(device1
, &vp
);
1343 ok(SUCCEEDED(hr
), "SetViewport failed, hr %#x.\n", hr
);
1345 hr
= IDirect3DDevice8_GetRenderState(device1
, D3DRS_LIGHTING
, &value
);
1346 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1347 ok(!!value
, "Got unexpected value %#x for D3DRS_LIGHTING.\n", value
);
1348 hr
= IDirect3DDevice8_SetRenderState(device1
, D3DRS_LIGHTING
, FALSE
);
1349 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
1351 memset(&d3dpp
, 0, sizeof(d3dpp
));
1352 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1353 d3dpp
.Windowed
= FALSE
;
1354 d3dpp
.BackBufferWidth
= modes
[i
].w
;
1355 d3dpp
.BackBufferHeight
= modes
[i
].h
;
1356 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1357 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1358 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1359 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1360 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1362 hr
= IDirect3DDevice8_GetRenderState(device1
, D3DRS_LIGHTING
, &value
);
1363 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1364 ok(!!value
, "Got unexpected value %#x for D3DRS_LIGHTING.\n", value
);
1366 memset(&vp
, 0, sizeof(vp
));
1367 hr
= IDirect3DDevice8_GetViewport(device1
, &vp
);
1368 ok(SUCCEEDED(hr
), "GetViewport failed, hr %#x.\n", hr
);
1371 ok(vp
.X
== 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp
.X
);
1372 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp
.Y
);
1373 ok(vp
.Width
== modes
[i
].w
, "D3DVIEWPORT->Width = %u, expected %u.\n", vp
.Width
, modes
[i
].w
);
1374 ok(vp
.Height
== modes
[i
].h
, "D3DVIEWPORT->Height = %u, expected %u.\n", vp
.Height
, modes
[i
].h
);
1375 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp
.MinZ
);
1376 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp
.MaxZ
);
1379 width
= GetSystemMetrics(SM_CXSCREEN
);
1380 height
= GetSystemMetrics(SM_CYSCREEN
);
1381 ok(width
== modes
[i
].w
, "Screen width is %u, expected %u.\n", width
, modes
[i
].w
);
1382 ok(height
== modes
[i
].h
, "Screen height is %u, expected %u.\n", height
, modes
[i
].h
);
1384 hr
= IDirect3DDevice8_GetRenderTarget(device1
, &surface
);
1385 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
1386 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
1387 ok(hr
== D3D_OK
, "GetDesc failed, hr %#x.\n", hr
);
1388 ok(surface_desc
.Width
== modes
[i
].w
, "Back buffer width is %u, expected %u.\n",
1389 surface_desc
.Width
, modes
[i
].w
);
1390 ok(surface_desc
.Height
== modes
[i
].h
, "Back buffer height is %u, expected %u.\n",
1391 surface_desc
.Height
, modes
[i
].h
);
1392 IDirect3DSurface8_Release(surface
);
1394 memset(&d3dpp
, 0, sizeof(d3dpp
));
1395 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1396 d3dpp
.Windowed
= TRUE
;
1397 d3dpp
.BackBufferWidth
= 400;
1398 d3dpp
.BackBufferHeight
= 300;
1399 d3dpp
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
1400 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1401 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1402 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1403 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1405 memset(&vp
, 0, sizeof(vp
));
1406 hr
= IDirect3DDevice8_GetViewport(device1
, &vp
);
1407 ok(SUCCEEDED(hr
), "GetViewport failed, hr %#x.\n", hr
);
1410 ok(vp
.X
== 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp
.X
);
1411 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp
.Y
);
1412 ok(vp
.Width
== 400, "D3DVIEWPORT->Width = %u, expected 400.\n", vp
.Width
);
1413 ok(vp
.Height
== 300, "D3DVIEWPORT->Height = %u, expected 300.\n", vp
.Height
);
1414 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp
.MinZ
);
1415 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp
.MaxZ
);
1418 width
= GetSystemMetrics(SM_CXSCREEN
);
1419 height
= GetSystemMetrics(SM_CYSCREEN
);
1420 ok(width
== orig_width
, "Screen width is %u, expected %u.\n", width
, orig_width
);
1421 ok(height
== orig_height
, "Screen height is %u, expected %u.\n", height
, orig_height
);
1423 hr
= IDirect3DDevice8_GetRenderTarget(device1
, &surface
);
1424 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
1425 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
1426 ok(hr
== D3D_OK
, "GetDesc failed, hr %#x.\n", hr
);
1427 ok(surface_desc
.Width
== 400, "Back buffer width is %u, expected 400.\n",
1428 surface_desc
.Width
);
1429 ok(surface_desc
.Height
== 300, "Back buffer height is %u, expected 300.\n",
1430 surface_desc
.Height
);
1431 IDirect3DSurface8_Release(surface
);
1435 winrect
.right
= 200;
1436 winrect
.bottom
= 150;
1437 ok(AdjustWindowRect(&winrect
, WS_OVERLAPPEDWINDOW
, FALSE
), "AdjustWindowRect failed\n");
1438 ok(SetWindowPos(window
, NULL
, 0, 0,
1439 winrect
.right
-winrect
.left
,
1440 winrect
.bottom
-winrect
.top
,
1441 SWP_NOMOVE
|SWP_NOZORDER
),
1442 "SetWindowPos failed\n");
1444 memset(&d3dpp
, 0, sizeof(d3dpp
));
1445 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1446 d3dpp
.Windowed
= TRUE
;
1447 d3dpp
.BackBufferWidth
= 0;
1448 d3dpp
.BackBufferHeight
= 0;
1449 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1450 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1451 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1452 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1453 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1455 ok(!d3dpp
.BackBufferWidth
, "Got unexpected BackBufferWidth %u.\n", d3dpp
.BackBufferWidth
);
1456 ok(!d3dpp
.BackBufferHeight
, "Got unexpected BackBufferHeight %u.\n", d3dpp
.BackBufferHeight
);
1457 ok(d3dpp
.BackBufferFormat
== d3ddm
.Format
, "Got unexpected BackBufferFormat %#x, expected %#x.\n",
1458 d3dpp
.BackBufferFormat
, d3ddm
.Format
);
1459 ok(d3dpp
.BackBufferCount
== 1, "Got unexpected BackBufferCount %u.\n", d3dpp
.BackBufferCount
);
1460 ok(!d3dpp
.MultiSampleType
, "Got unexpected MultiSampleType %u.\n", d3dpp
.MultiSampleType
);
1461 ok(d3dpp
.SwapEffect
== D3DSWAPEFFECT_DISCARD
, "Got unexpected SwapEffect %#x.\n", d3dpp
.SwapEffect
);
1462 ok(!d3dpp
.hDeviceWindow
, "Got unexpected hDeviceWindow %p.\n", d3dpp
.hDeviceWindow
);
1463 ok(d3dpp
.Windowed
, "Got unexpected Windowed %#x.\n", d3dpp
.Windowed
);
1464 ok(!d3dpp
.EnableAutoDepthStencil
, "Got unexpected EnableAutoDepthStencil %#x.\n", d3dpp
.EnableAutoDepthStencil
);
1465 ok(!d3dpp
.AutoDepthStencilFormat
, "Got unexpected AutoDepthStencilFormat %#x.\n", d3dpp
.AutoDepthStencilFormat
);
1466 ok(!d3dpp
.Flags
, "Got unexpected Flags %#x.\n", d3dpp
.Flags
);
1467 ok(!d3dpp
.FullScreen_RefreshRateInHz
, "Got unexpected FullScreen_RefreshRateInHz %u.\n",
1468 d3dpp
.FullScreen_RefreshRateInHz
);
1469 ok(!d3dpp
.FullScreen_PresentationInterval
, "Got unexpected FullScreen_PresentationInterval %#x.\n",
1470 d3dpp
.FullScreen_PresentationInterval
);
1472 memset(&vp
, 0, sizeof(vp
));
1473 hr
= IDirect3DDevice8_GetViewport(device1
, &vp
);
1474 ok(SUCCEEDED(hr
), "GetViewport failed, hr %#x.\n", hr
);
1477 ok(vp
.X
== 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp
.X
);
1478 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp
.Y
);
1479 ok(vp
.Width
== 200, "D3DVIEWPORT->Width = %u, expected 200.\n", vp
.Width
);
1480 ok(vp
.Height
== 150, "D3DVIEWPORT->Height = %u, expected 150.\n", vp
.Height
);
1481 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp
.MinZ
);
1482 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp
.MaxZ
);
1485 hr
= IDirect3DDevice8_GetRenderTarget(device1
, &surface
);
1486 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
1487 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
1488 ok(hr
== D3D_OK
, "GetDesc failed, hr %#x.\n", hr
);
1489 ok(surface_desc
.Format
== d3ddm
.Format
, "Got unexpected Format %#x, expected %#x.\n",
1490 surface_desc
.Format
, d3ddm
.Format
);
1491 ok(!surface_desc
.MultiSampleType
, "Got unexpected MultiSampleType %u.\n", d3dpp
.MultiSampleType
);
1492 ok(surface_desc
.Width
== 200, "Back buffer width is %u, expected 200.\n", surface_desc
.Width
);
1493 ok(surface_desc
.Height
== 150, "Back buffer height is %u, expected 150.\n", surface_desc
.Height
);
1494 IDirect3DSurface8_Release(surface
);
1496 memset(&d3dpp
, 0, sizeof(d3dpp
));
1497 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1498 d3dpp
.Windowed
= TRUE
;
1499 d3dpp
.BackBufferWidth
= 400;
1500 d3dpp
.BackBufferHeight
= 300;
1501 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1503 /* Reset fails if there is a resource in the default pool. */
1504 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_DEFAULT
, &texture
);
1505 ok(SUCCEEDED(hr
), "CreateTexture 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 IDirect3DTexture8_Release(texture
);
1511 /* Reset again to get the device out of the lost state. */
1512 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1513 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1514 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1515 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1517 if (caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
)
1519 IDirect3DVolumeTexture8
*volume_texture
;
1521 hr
= IDirect3DDevice8_CreateVolumeTexture(device1
, 16, 16, 4, 1, 0,
1522 D3DFMT_R5G6B5
, D3DPOOL_DEFAULT
, &volume_texture
);
1523 ok(SUCCEEDED(hr
), "CreateVolumeTexture failed, hr %#x.\n", hr
);
1524 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1525 ok(hr
== D3DERR_DEVICELOST
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
1526 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1527 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n",
1528 hr
, D3DERR_DEVICENOTRESET
);
1529 IDirect3DVolumeTexture8_Release(volume_texture
);
1530 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1531 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1532 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1533 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1537 skip("Volume textures not supported.\n");
1540 /* Scratch, sysmem and managed pool resources are fine. */
1541 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_SCRATCH
, &texture
);
1542 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
1543 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1544 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1545 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1546 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1547 IDirect3DTexture8_Release(texture
);
1549 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_SYSTEMMEM
, &texture
);
1550 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
1551 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1552 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1553 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1554 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1555 IDirect3DTexture8_Release(texture
);
1557 /* The depth stencil should get reset to the auto depth stencil when present. */
1558 hr
= IDirect3DDevice8_SetRenderTarget(device1
, NULL
, NULL
);
1559 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
1561 hr
= IDirect3DDevice8_GetDepthStencilSurface(device1
, &surface
);
1562 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned %#x, expected %#x.\n", hr
, D3DERR_NOTFOUND
);
1563 ok(!surface
, "Depth / stencil buffer should be NULL.\n");
1565 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1566 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1567 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1568 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1570 hr
= IDirect3DDevice8_GetDepthStencilSurface(device1
, &surface
);
1571 ok(SUCCEEDED(hr
), "GetDepthStencilSurface failed, hr %#x.\n", hr
);
1572 ok(!!surface
, "Depth / stencil buffer should not be NULL.\n");
1573 if (surface
) IDirect3DSurface8_Release(surface
);
1575 d3dpp
.EnableAutoDepthStencil
= FALSE
;
1576 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1577 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1579 hr
= IDirect3DDevice8_GetDepthStencilSurface(device1
, &surface
);
1580 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned %#x, expected %#x.\n", hr
, D3DERR_NOTFOUND
);
1581 ok(!surface
, "Depth / stencil buffer should be NULL.\n");
1583 /* Will a sysmem or scratch resource survive while locked? */
1584 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_SYSTEMMEM
, &texture
);
1585 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
1586 hr
= IDirect3DTexture8_LockRect(texture
, 0, &lockrect
, NULL
, D3DLOCK_DISCARD
);
1587 ok(SUCCEEDED(hr
), "LockRect failed, hr %#x.\n", hr
);
1588 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1589 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1590 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1591 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1592 IDirect3DTexture8_UnlockRect(texture
, 0);
1593 IDirect3DTexture8_Release(texture
);
1595 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_SCRATCH
, &texture
);
1596 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
1597 hr
= IDirect3DTexture8_LockRect(texture
, 0, &lockrect
, NULL
, D3DLOCK_DISCARD
);
1598 ok(SUCCEEDED(hr
), "LockRect failed, hr %#x.\n", hr
);
1599 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1600 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1601 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1602 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1603 IDirect3DTexture8_UnlockRect(texture
, 0);
1604 IDirect3DTexture8_Release(texture
);
1606 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_MANAGED
, &texture
);
1607 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
1608 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1609 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1610 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1611 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1612 IDirect3DTexture8_Release(texture
);
1614 /* A reference held to an implicit surface causes failures as well. */
1615 hr
= IDirect3DDevice8_GetBackBuffer(device1
, 0, D3DBACKBUFFER_TYPE_MONO
, &surface
);
1616 ok(SUCCEEDED(hr
), "GetBackBuffer failed, hr %#x.\n", hr
);
1617 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1618 ok(hr
== D3DERR_DEVICELOST
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_DEVICELOST
);
1619 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1620 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n", hr
, D3DERR_DEVICENOTRESET
);
1621 IDirect3DSurface8_Release(surface
);
1622 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1623 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1624 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1625 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1627 /* Shaders are fine as well. */
1628 hr
= IDirect3DDevice8_CreateVertexShader(device1
, decl
, simple_vs
, &shader
, 0);
1629 ok(SUCCEEDED(hr
), "CreateVertexShader failed, hr %#x.\n", hr
);
1630 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1631 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1632 hr
= IDirect3DDevice8_DeleteVertexShader(device1
, shader
);
1633 ok(SUCCEEDED(hr
), "DeleteVertexShader failed, hr %#x.\n", hr
);
1635 /* Try setting invalid modes. */
1636 memset(&d3dpp
, 0, sizeof(d3dpp
));
1637 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1638 d3dpp
.Windowed
= FALSE
;
1639 d3dpp
.BackBufferWidth
= 32;
1640 d3dpp
.BackBufferHeight
= 32;
1641 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1642 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1643 ok(hr
== D3DERR_INVALIDCALL
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
1644 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1645 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n", hr
, D3DERR_DEVICENOTRESET
);
1647 memset(&d3dpp
, 0, sizeof(d3dpp
));
1648 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1649 d3dpp
.Windowed
= FALSE
;
1650 d3dpp
.BackBufferWidth
= 801;
1651 d3dpp
.BackBufferHeight
= 600;
1652 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1653 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1654 ok(hr
== D3DERR_INVALIDCALL
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
1655 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1656 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n", hr
, D3DERR_DEVICENOTRESET
);
1658 memset(&d3dpp
, 0, sizeof(d3dpp
));
1659 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1660 d3dpp
.Windowed
= FALSE
;
1661 d3dpp
.BackBufferWidth
= 0;
1662 d3dpp
.BackBufferHeight
= 0;
1663 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1664 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1665 ok(hr
== D3DERR_INVALIDCALL
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
1666 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1667 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n", hr
, D3DERR_DEVICENOTRESET
);
1669 hr
= IDirect3D8_GetAdapterDisplayMode(d3d8
, D3DADAPTER_DEFAULT
, &d3ddm
);
1670 ok(SUCCEEDED(hr
), "GetAdapterDisplayMode failed, hr %#x.\n", hr
);
1672 memset(&d3dpp
, 0, sizeof(d3dpp
));
1673 d3dpp
.Windowed
= TRUE
;
1674 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1675 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1676 d3dpp
.EnableAutoDepthStencil
= FALSE
;
1677 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1679 hr
= IDirect3D8_CreateDevice(d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
1680 window
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &device2
);
1683 skip("Failed to create device, hr %#x.\n", hr
);
1687 hr
= IDirect3DDevice8_TestCooperativeLevel(device2
);
1688 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1690 d3dpp
.Windowed
= TRUE
;
1691 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1692 d3dpp
.BackBufferWidth
= 400;
1693 d3dpp
.BackBufferHeight
= 300;
1694 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1695 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1696 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1698 hr
= IDirect3DDevice8_Reset(device2
, &d3dpp
);
1699 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1703 hr
= IDirect3DDevice8_GetDepthStencilSurface(device2
, &surface
);
1704 ok(SUCCEEDED(hr
), "GetDepthStencilSurface failed, hr %#x.\n", hr
);
1705 ok(!!surface
, "Depth / stencil buffer should not be NULL.\n");
1707 IDirect3DSurface8_Release(surface
);
1710 HeapFree(GetProcessHeap(), 0, modes
);
1712 IDirect3DDevice8_Release(device2
);
1714 IDirect3DDevice8_Release(device1
);
1715 IDirect3D8_Release(d3d8
);
1716 DestroyWindow(window
);
1719 static void test_scene(void)
1721 IDirect3DDevice8
*device
;
1727 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
1728 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
1729 ok(!!window
, "Failed to create a window.\n");
1730 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
1731 ok(!!d3d
, "Failed to create a D3D object.\n");
1732 if (!(device
= create_device(d3d
, window
, NULL
)))
1734 skip("Failed to create a 3D device, skipping test.\n");
1738 /* Test an EndScene without BeginScene. Should return an error */
1739 hr
= IDirect3DDevice8_EndScene(device
);
1740 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
1742 /* Test a normal BeginScene / EndScene pair, this should work */
1743 hr
= IDirect3DDevice8_BeginScene(device
);
1744 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr
);
1745 hr
= IDirect3DDevice8_EndScene(device
);
1746 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed with %#08x\n", hr
);
1748 /* Test another EndScene without having begun a new scene. Should return an error */
1749 hr
= IDirect3DDevice8_EndScene(device
);
1750 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
1752 /* Two nested BeginScene and EndScene calls */
1753 hr
= IDirect3DDevice8_BeginScene(device
);
1754 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr
);
1755 hr
= IDirect3DDevice8_BeginScene(device
);
1756 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_BeginScene returned %#08x\n", hr
);
1757 hr
= IDirect3DDevice8_EndScene(device
);
1758 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed with %#08x\n", hr
);
1759 hr
= IDirect3DDevice8_EndScene(device
);
1760 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
1762 /* StretchRect does not exit in Direct3D8, so no equivalent to the d3d9 stretchrect tests */
1764 refcount
= IDirect3DDevice8_Release(device
);
1765 ok(!refcount
, "Device has %u references left.\n", refcount
);
1767 IDirect3D8_Release(d3d
);
1768 DestroyWindow(window
);
1771 static void test_shader(void)
1773 DWORD hPixelShader
= 0, hVertexShader
= 0;
1774 DWORD hPixelShader2
= 0, hVertexShader2
= 0;
1777 DWORD fvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
1778 IDirect3DDevice8
*device
;
1786 static DWORD dwVertexDecl
[] =
1789 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
),
1792 DWORD decl_normal_float2
[] =
1795 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
1796 D3DVSD_REG(D3DVSDE_NORMAL
, D3DVSDT_FLOAT2
), /* D3DVSDE_NORMAL, Register v1 */
1799 DWORD decl_normal_float4
[] =
1802 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
1803 D3DVSD_REG(D3DVSDE_NORMAL
, D3DVSDT_FLOAT4
), /* D3DVSDE_NORMAL, Register v1 */
1806 DWORD decl_normal_d3dcolor
[] =
1809 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
1810 D3DVSD_REG(D3DVSDE_NORMAL
, D3DVSDT_D3DCOLOR
),/* D3DVSDE_NORMAL, Register v1 */
1813 const DWORD vertex_decl_size
= sizeof(dwVertexDecl
);
1814 const DWORD simple_vs_size
= sizeof(simple_vs
);
1815 const DWORD simple_ps_size
= sizeof(simple_ps
);
1817 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
1818 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
1819 ok(!!window
, "Failed to create a window.\n");
1820 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
1821 ok(!!d3d
, "Failed to create a D3D object.\n");
1822 if (!(device
= create_device(d3d
, window
, NULL
)))
1824 skip("Failed to create a 3D device, skipping test.\n");
1828 IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
1830 /* Test setting and retrieving a FVF */
1831 hr
= IDirect3DDevice8_SetVertexShader(device
, fvf
);
1832 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
1833 hr
= IDirect3DDevice8_GetVertexShader(device
, &hTempHandle
);
1834 ok(SUCCEEDED(hr
), "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
1835 ok(hTempHandle
== fvf
, "Vertex shader %#08x is set, expected %#08x\n", hTempHandle
, fvf
);
1837 /* First create a vertex shader */
1838 hr
= IDirect3DDevice8_SetVertexShader(device
, 0);
1839 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
1840 hr
= IDirect3DDevice8_CreateVertexShader(device
, dwVertexDecl
, simple_vs
, &hVertexShader
, 0);
1841 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1842 /* Msdn says that the new vertex shader is set immediately. This is wrong, apparently */
1843 hr
= IDirect3DDevice8_GetVertexShader(device
, &hTempHandle
);
1844 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
1845 ok(hTempHandle
== 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, 0);
1846 /* Assign the shader, then verify that GetVertexShader works */
1847 hr
= IDirect3DDevice8_SetVertexShader(device
, hVertexShader
);
1848 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
1849 hr
= IDirect3DDevice8_GetVertexShader(device
, &hTempHandle
);
1850 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
1851 ok(hTempHandle
== hVertexShader
, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, hVertexShader
);
1852 /* Verify that we can retrieve the declaration */
1853 hr
= IDirect3DDevice8_GetVertexShaderDeclaration(device
, hVertexShader
, NULL
, &data_size
);
1854 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr
);
1855 ok(data_size
== vertex_decl_size
, "Got data_size %u, expected %u\n", data_size
, vertex_decl_size
);
1856 data
= HeapAlloc(GetProcessHeap(), 0, vertex_decl_size
);
1858 hr
= IDirect3DDevice8_GetVertexShaderDeclaration(device
, hVertexShader
, data
, &data_size
);
1859 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_GetVertexShaderDeclaration returned (%#08x), "
1860 "expected D3DERR_INVALIDCALL\n", hr
);
1861 ok(data_size
== 1, "Got data_size %u, expected 1\n", data_size
);
1862 data_size
= vertex_decl_size
;
1863 hr
= IDirect3DDevice8_GetVertexShaderDeclaration(device
, hVertexShader
, data
, &data_size
);
1864 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr
);
1865 ok(data_size
== vertex_decl_size
, "Got data_size %u, expected %u\n", data_size
, vertex_decl_size
);
1866 ok(!memcmp(data
, dwVertexDecl
, vertex_decl_size
), "data not equal to shader declaration\n");
1867 HeapFree(GetProcessHeap(), 0, data
);
1868 /* Verify that we can retrieve the shader function */
1869 hr
= IDirect3DDevice8_GetVertexShaderFunction(device
, hVertexShader
, NULL
, &data_size
);
1870 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr
);
1871 ok(data_size
== simple_vs_size
, "Got data_size %u, expected %u\n", data_size
, simple_vs_size
);
1872 data
= HeapAlloc(GetProcessHeap(), 0, simple_vs_size
);
1874 hr
= IDirect3DDevice8_GetVertexShaderFunction(device
, hVertexShader
, data
, &data_size
);
1875 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_GetVertexShaderFunction returned (%#08x), "
1876 "expected D3DERR_INVALIDCALL\n", hr
);
1877 ok(data_size
== 1, "Got data_size %u, expected 1\n", data_size
);
1878 data_size
= simple_vs_size
;
1879 hr
= IDirect3DDevice8_GetVertexShaderFunction(device
, hVertexShader
, data
, &data_size
);
1880 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr
);
1881 ok(data_size
== simple_vs_size
, "Got data_size %u, expected %u\n", data_size
, simple_vs_size
);
1882 ok(!memcmp(data
, simple_vs
, simple_vs_size
), "data not equal to shader function\n");
1883 HeapFree(GetProcessHeap(), 0, data
);
1884 /* Delete the assigned shader. This is supposed to work */
1885 hr
= IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader
);
1886 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
1887 /* The shader should be unset now */
1888 hr
= IDirect3DDevice8_GetVertexShader(device
, &hTempHandle
);
1889 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
1890 ok(hTempHandle
== 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, 0);
1892 /* Test a broken declaration. 3DMark2001 tries to use normals with 2 components
1893 * First try the fixed function shader function, then a custom one
1895 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl_normal_float2
, 0, &hVertexShader
, 0);
1896 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1897 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl_normal_float4
, 0, &hVertexShader
, 0);
1898 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1899 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl_normal_d3dcolor
, 0, &hVertexShader
, 0);
1900 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1902 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl_normal_float2
, simple_vs
, &hVertexShader
, 0);
1903 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1904 IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader
);
1906 if (caps
.PixelShaderVersion
>= D3DPS_VERSION(1, 0))
1908 /* The same with a pixel shader */
1909 hr
= IDirect3DDevice8_CreatePixelShader(device
, simple_ps
, &hPixelShader
);
1910 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
1911 /* Msdn says that the new pixel shader is set immediately. This is wrong, apparently */
1912 hr
= IDirect3DDevice8_GetPixelShader(device
, &hTempHandle
);
1913 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
1914 ok(hTempHandle
== 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, 0);
1915 /* Assign the shader, then verify that GetPixelShader works */
1916 hr
= IDirect3DDevice8_SetPixelShader(device
, hPixelShader
);
1917 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr
);
1918 hr
= IDirect3DDevice8_GetPixelShader(device
, &hTempHandle
);
1919 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
1920 ok(hTempHandle
== hPixelShader
, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, hPixelShader
);
1921 /* Verify that we can retrieve the shader function */
1922 hr
= IDirect3DDevice8_GetPixelShaderFunction(device
, hPixelShader
, NULL
, &data_size
);
1923 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr
);
1924 ok(data_size
== simple_ps_size
, "Got data_size %u, expected %u\n", data_size
, simple_ps_size
);
1925 data
= HeapAlloc(GetProcessHeap(), 0, simple_ps_size
);
1927 hr
= IDirect3DDevice8_GetPixelShaderFunction(device
, hPixelShader
, data
, &data_size
);
1928 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_GetPixelShaderFunction returned (%#08x), "
1929 "expected D3DERR_INVALIDCALL\n", hr
);
1930 ok(data_size
== 1, "Got data_size %u, expected 1\n", data_size
);
1931 data_size
= simple_ps_size
;
1932 hr
= IDirect3DDevice8_GetPixelShaderFunction(device
, hPixelShader
, data
, &data_size
);
1933 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr
);
1934 ok(data_size
== simple_ps_size
, "Got data_size %u, expected %u\n", data_size
, simple_ps_size
);
1935 ok(!memcmp(data
, simple_ps
, simple_ps_size
), "data not equal to shader function\n");
1936 HeapFree(GetProcessHeap(), 0, data
);
1937 /* Delete the assigned shader. This is supposed to work */
1938 hr
= IDirect3DDevice8_DeletePixelShader(device
, hPixelShader
);
1939 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
1940 /* The shader should be unset now */
1941 hr
= IDirect3DDevice8_GetPixelShader(device
, &hTempHandle
);
1942 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
1943 ok(hTempHandle
== 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, 0);
1945 /* What happens if a non-bound shader is deleted? */
1946 hr
= IDirect3DDevice8_CreatePixelShader(device
, simple_ps
, &hPixelShader
);
1947 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
1948 hr
= IDirect3DDevice8_CreatePixelShader(device
, simple_ps
, &hPixelShader2
);
1949 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
1951 hr
= IDirect3DDevice8_SetPixelShader(device
, hPixelShader
);
1952 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr
);
1953 hr
= IDirect3DDevice8_DeletePixelShader(device
, hPixelShader2
);
1954 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
1955 hr
= IDirect3DDevice8_GetPixelShader(device
, &hTempHandle
);
1956 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
1957 ok(hTempHandle
== hPixelShader
, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, hPixelShader
);
1958 hr
= IDirect3DDevice8_DeletePixelShader(device
, hPixelShader
);
1959 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
1961 /* Check for double delete. */
1962 hr
= IDirect3DDevice8_DeletePixelShader(device
, hPixelShader2
);
1963 ok(hr
== D3DERR_INVALIDCALL
|| broken(hr
== D3D_OK
), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
1964 hr
= IDirect3DDevice8_DeletePixelShader(device
, hPixelShader
);
1965 ok(hr
== D3DERR_INVALIDCALL
|| broken(hr
== D3D_OK
), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
1969 skip("Pixel shaders not supported\n");
1972 /* What happens if a non-bound shader is deleted? */
1973 hr
= IDirect3DDevice8_CreateVertexShader(device
, dwVertexDecl
, NULL
, &hVertexShader
, 0);
1974 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1975 hr
= IDirect3DDevice8_CreateVertexShader(device
, dwVertexDecl
, NULL
, &hVertexShader2
, 0);
1976 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1978 hr
= IDirect3DDevice8_SetVertexShader(device
, hVertexShader
);
1979 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
1980 hr
= IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader2
);
1981 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
1982 hr
= IDirect3DDevice8_GetVertexShader(device
, &hTempHandle
);
1983 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
1984 ok(hTempHandle
== hVertexShader
, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, hVertexShader
);
1985 hr
= IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader
);
1986 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
1988 /* Check for double delete. */
1989 hr
= IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader2
);
1990 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
1991 hr
= IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader
);
1992 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
1994 refcount
= IDirect3DDevice8_Release(device
);
1995 ok(!refcount
, "Device has %u references left.\n", refcount
);
1997 IDirect3D8_Release(d3d
);
1998 DestroyWindow(window
);
2001 static void test_limits(void)
2003 IDirect3DTexture8
*texture
;
2004 IDirect3DDevice8
*device
;
2011 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
2012 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
2013 ok(!!window
, "Failed to create a window.\n");
2014 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
2015 ok(!!d3d
, "Failed to create a D3D object.\n");
2016 if (!(device
= create_device(d3d
, window
, NULL
)))
2018 skip("Failed to create a 3D device, skipping test.\n");
2022 hr
= IDirect3DDevice8_CreateTexture(device
, 16, 16, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &texture
);
2023 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateTexture failed with %#08x\n", hr
);
2025 /* There are 8 texture stages. We should be able to access all of them */
2026 for (i
= 0; i
< 8; ++i
)
2028 hr
= IDirect3DDevice8_SetTexture(device
, i
, (IDirect3DBaseTexture8
*)texture
);
2029 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i
, hr
);
2030 hr
= IDirect3DDevice8_SetTexture(device
, i
, NULL
);
2031 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i
, hr
);
2032 hr
= IDirect3DDevice8_SetTextureStageState(device
, i
, D3DTSS_COLOROP
, D3DTOP_ADD
);
2033 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %#08x\n", i
, hr
);
2036 /* Investigations show that accessing higher textures stage states does
2037 * not return an error either. Writing to too high texture stages
2038 * (approximately texture 40) causes memory corruption in windows, so
2039 * there is no bounds checking. */
2040 IDirect3DTexture8_Release(texture
);
2041 refcount
= IDirect3DDevice8_Release(device
);
2042 ok(!refcount
, "Device has %u references left.\n", refcount
);
2044 IDirect3D8_Release(d3d
);
2045 DestroyWindow(window
);
2048 static void test_lights(void)
2050 IDirect3DDevice8
*device
;
2059 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
2060 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
2061 ok(!!window
, "Failed to create a window.\n");
2062 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
2063 ok(!!d3d8
, "Failed to create a D3D object.\n");
2064 if (!(device
= create_device(d3d8
, window
, NULL
)))
2066 skip("Failed to create a 3D device, skipping test.\n");
2070 memset(&caps
, 0, sizeof(caps
));
2071 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
2072 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetDeviceCaps failed with %08x\n", hr
);
2074 for(i
= 1; i
<= caps
.MaxActiveLights
; i
++) {
2075 hr
= IDirect3DDevice8_LightEnable(device
, i
, TRUE
);
2076 ok(hr
== D3D_OK
, "Enabling light %u failed with %08x\n", i
, hr
);
2077 hr
= IDirect3DDevice8_GetLightEnable(device
, i
, &enabled
);
2078 ok(hr
== D3D_OK
|| broken(hr
== D3DERR_INVALIDCALL
),
2079 "GetLightEnable on light %u failed with %08x\n", i
, hr
);
2080 ok(enabled
, "Light %d is %s\n", i
, enabled
? "enabled" : "disabled");
2083 /* TODO: Test the rendering results in this situation */
2084 hr
= IDirect3DDevice8_LightEnable(device
, i
+ 1, TRUE
);
2085 ok(hr
== D3D_OK
, "Enabling one light more than supported returned %08x\n", hr
);
2086 hr
= IDirect3DDevice8_GetLightEnable(device
, i
+ 1, &enabled
);
2087 ok(hr
== D3D_OK
, "GetLightEnable on light %u failed with %08x\n", i
+ 1, hr
);
2088 ok(enabled
, "Light %d is %s\n", i
+ 1, enabled
? "enabled" : "disabled");
2089 hr
= IDirect3DDevice8_LightEnable(device
, i
+ 1, FALSE
);
2090 ok(hr
== D3D_OK
, "Disabling the additional returned %08x\n", hr
);
2092 for(i
= 1; i
<= caps
.MaxActiveLights
; i
++) {
2093 hr
= IDirect3DDevice8_LightEnable(device
, i
, FALSE
);
2094 ok(hr
== D3D_OK
, "Disabling light %u failed with %08x\n", i
, hr
);
2097 refcount
= IDirect3DDevice8_Release(device
);
2098 ok(!refcount
, "Device has %u references left.\n", refcount
);
2100 IDirect3D8_Release(d3d8
);
2101 DestroyWindow(window
);
2104 static void test_render_zero_triangles(void)
2106 IDirect3DDevice8
*device
;
2114 struct vec3 position
;
2120 {{0.0f
, -1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
2121 {{0.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
2122 {{1.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
2123 {{1.0f
, -1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
2126 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
2127 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
2128 ok(!!window
, "Failed to create a window.\n");
2129 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
2130 ok(!!d3d8
, "Failed to create a D3D object.\n");
2131 if (!(device
= create_device(d3d8
, window
, NULL
)))
2133 skip("Failed to create a 3D device, skipping test.\n");
2137 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
2138 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
2140 hr
= IDirect3DDevice8_BeginScene(device
);
2141 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
2142 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 0 /* NumVerts */,
2143 0 /* PrimCount */, NULL
, D3DFMT_INDEX16
, quad
, sizeof(quad
[0]));
2144 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
2145 hr
= IDirect3DDevice8_EndScene(device
);
2146 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
2148 IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
2150 refcount
= IDirect3DDevice8_Release(device
);
2151 ok(!refcount
, "Device has %u references left.\n", refcount
);
2153 IDirect3D8_Release(d3d8
);
2154 DestroyWindow(window
);
2157 static void test_depth_stencil_reset(void)
2159 D3DPRESENT_PARAMETERS present_parameters
;
2160 D3DDISPLAYMODE display_mode
;
2161 IDirect3DSurface8
*surface
, *orig_rt
;
2162 IDirect3DDevice8
*device
= NULL
;
2168 hwnd
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
2169 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
2170 ok(!!hwnd
, "Failed to create a window.\n");
2171 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
2172 ok(!!d3d8
, "Failed to create a D3D object.\n");
2174 IDirect3D8_GetAdapterDisplayMode(d3d8
, D3DADAPTER_DEFAULT
, &display_mode
);
2175 memset(&present_parameters
, 0, sizeof(present_parameters
));
2176 present_parameters
.Windowed
= TRUE
;
2177 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2178 present_parameters
.BackBufferFormat
= display_mode
.Format
;
2179 present_parameters
.EnableAutoDepthStencil
= TRUE
;
2180 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
2182 hr
= IDirect3D8_CreateDevice(d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
2183 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
2186 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr
);
2190 hr
= IDirect3DDevice8_GetRenderTarget(device
, &orig_rt
);
2191 ok(hr
== D3D_OK
, "GetRenderTarget failed with 0x%08x\n", hr
);
2193 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
2194 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed with %#x\n", hr
);
2196 hr
= IDirect3DDevice8_SetRenderTarget(device
, NULL
, NULL
);
2197 ok(hr
== D3D_OK
, "SetRenderTarget failed with 0x%08x\n", hr
);
2199 hr
= IDirect3DDevice8_GetRenderTarget(device
, &surface
);
2200 ok(hr
== D3D_OK
, "GetRenderTarget failed with 0x%08x\n", hr
);
2201 ok(surface
== orig_rt
, "Render target is %p, should be %p\n", surface
, orig_rt
);
2202 if (surface
) IDirect3DSurface8_Release(surface
);
2203 IDirect3DSurface8_Release(orig_rt
);
2205 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surface
);
2206 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr
);
2207 ok(surface
== NULL
, "Depth stencil should be NULL\n");
2209 present_parameters
.EnableAutoDepthStencil
= TRUE
;
2210 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
2211 hr
= IDirect3DDevice8_Reset(device
, &present_parameters
);
2212 ok(hr
== D3D_OK
, "Reset failed with 0x%08x\n", hr
);
2214 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surface
);
2215 ok(hr
== D3D_OK
, "GetDepthStencilSurface failed with 0x%08x\n", hr
);
2216 ok(surface
!= NULL
, "Depth stencil should not be NULL\n");
2217 if (surface
) IDirect3DSurface8_Release(surface
);
2219 present_parameters
.EnableAutoDepthStencil
= FALSE
;
2220 hr
= IDirect3DDevice8_Reset(device
, &present_parameters
);
2221 ok(hr
== D3D_OK
, "Reset failed with 0x%08x\n", hr
);
2223 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surface
);
2224 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr
);
2225 ok(surface
== NULL
, "Depth stencil should be NULL\n");
2227 refcount
= IDirect3DDevice8_Release(device
);
2228 ok(!refcount
, "Device has %u references left.\n", refcount
);
2231 IDirect3D8_GetAdapterDisplayMode( d3d8
, D3DADAPTER_DEFAULT
, &display_mode
);
2233 ZeroMemory( &present_parameters
, sizeof(present_parameters
) );
2234 present_parameters
.Windowed
= TRUE
;
2235 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2236 present_parameters
.BackBufferFormat
= display_mode
.Format
;
2237 present_parameters
.EnableAutoDepthStencil
= FALSE
;
2238 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
2240 hr
= IDirect3D8_CreateDevice( d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
2241 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
2245 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr
);
2249 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
2250 ok(hr
== D3D_OK
, "IDirect3DDevice8_TestCooperativeLevel after creation returned %#x\n", hr
);
2252 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2253 present_parameters
.Windowed
= TRUE
;
2254 present_parameters
.BackBufferWidth
= 400;
2255 present_parameters
.BackBufferHeight
= 300;
2256 present_parameters
.EnableAutoDepthStencil
= TRUE
;
2257 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
2259 hr
= IDirect3DDevice8_Reset(device
, &present_parameters
);
2260 ok(hr
== D3D_OK
, "IDirect3DDevice8_Reset failed with 0x%08x\n", hr
);
2262 if (FAILED(hr
)) goto cleanup
;
2264 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surface
);
2265 ok(hr
== D3D_OK
, "GetDepthStencilSurface failed with 0x%08x\n", hr
);
2266 ok(surface
!= NULL
, "Depth stencil should not be NULL\n");
2267 if (surface
) IDirect3DSurface8_Release(surface
);
2272 refcount
= IDirect3DDevice8_Release(device
);
2273 ok(!refcount
, "Device has %u references left.\n", refcount
);
2275 IDirect3D8_Release(d3d8
);
2276 DestroyWindow(hwnd
);
2279 static HWND filter_messages
;
2290 enum message_window window
;
2292 WPARAM expect_wparam
;
2295 static const struct message
*expect_messages
;
2296 static HWND device_window
, focus_window
;
2297 static LONG windowposchanged_received
, syscommand_received
;
2299 struct wndproc_thread_param
2302 HANDLE window_created
;
2303 HANDLE test_finished
;
2304 BOOL running_in_foreground
;
2307 static LRESULT CALLBACK
test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2309 if (filter_messages
&& filter_messages
== hwnd
)
2311 if (message
!= WM_DISPLAYCHANGE
&& message
!= WM_IME_NOTIFY
)
2312 todo_wine
ok(0, "Received unexpected message %#x for window %p.\n", message
, hwnd
);
2315 if (expect_messages
)
2319 switch (expect_messages
->window
)
2334 if (hwnd
== w
&& expect_messages
->message
== message
)
2336 if (expect_messages
->check_wparam
)
2337 ok(wparam
== expect_messages
->expect_wparam
,
2338 "Got unexpected wparam %lx for message %x, expected %lx.\n",
2339 wparam
, message
, expect_messages
->expect_wparam
);
2345 /* KDE randomly does something with the hidden window during the
2346 * mode change that sometimes generates a WM_WINDOWPOSCHANGING
2347 * message. A WM_WINDOWPOSCHANGED message is not generated, so
2348 * just flag WM_WINDOWPOSCHANGED as bad. */
2349 if (message
== WM_WINDOWPOSCHANGED
)
2350 InterlockedIncrement(&windowposchanged_received
);
2351 else if (message
== WM_SYSCOMMAND
)
2352 InterlockedIncrement(&syscommand_received
);
2354 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
2357 static DWORD WINAPI
wndproc_thread(void *param
)
2359 struct wndproc_thread_param
*p
= param
;
2363 p
->dummy_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2364 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, registry_mode
.dmPelsWidth
,
2365 registry_mode
.dmPelsHeight
, 0, 0, 0, 0);
2366 p
->running_in_foreground
= SetForegroundWindow(p
->dummy_window
);
2368 ret
= SetEvent(p
->window_created
);
2369 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
2375 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2376 res
= WaitForSingleObject(p
->test_finished
, 100);
2377 if (res
== WAIT_OBJECT_0
) break;
2378 if (res
!= WAIT_TIMEOUT
)
2380 ok(0, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
2385 DestroyWindow(p
->dummy_window
);
2390 static void test_wndproc(void)
2392 struct wndproc_thread_param thread_params
;
2393 struct device_desc device_desc
;
2394 IDirect3DDevice8
*device
;
2402 UINT i
, adapter_mode_count
;
2404 D3DDISPLAYMODE d3ddm
;
2405 DWORD d3d_width
= 0, d3d_height
= 0, user32_width
= 0, user32_height
= 0;
2410 static const struct message create_messages
[] =
2412 {WM_WINDOWPOSCHANGING
, FOCUS_WINDOW
, FALSE
, 0},
2413 /* Do not test wparam here. If device creation succeeds,
2414 * wparam is WA_ACTIVE. If device creation fails (testbot)
2415 * wparam is set to WA_INACTIVE on some Windows versions. */
2416 {WM_ACTIVATE
, FOCUS_WINDOW
, FALSE
, 0},
2417 {WM_SETFOCUS
, FOCUS_WINDOW
, FALSE
, 0},
2418 {WM_WINDOWPOSCHANGING
, DEVICE_WINDOW
, FALSE
, 0},
2419 {WM_MOVE
, DEVICE_WINDOW
, FALSE
, 0},
2420 {WM_SIZE
, DEVICE_WINDOW
, FALSE
, 0},
2423 static const struct message focus_loss_messages
[] =
2425 /* WM_ACTIVATE (wparam = WA_INACTIVE) is sent on Windows. It is
2426 * not reliable on X11 WMs. When the window focus follows the
2427 * mouse pointer the message is not sent.
2428 * {WM_ACTIVATE, FOCUS_WINDOW, TRUE, WA_INACTIVE}, */
2429 {WM_DISPLAYCHANGE
, DEVICE_WINDOW
, FALSE
, 0},
2430 /* WM_DISPLAYCHANGE is sent to the focus window too, but the order is
2431 * not deterministic. */
2432 {WM_WINDOWPOSCHANGING
, DEVICE_WINDOW
, FALSE
, 0},
2433 /* Windows sends WM_ACTIVATE to the device window, indicating that
2434 * SW_SHOWMINIMIZED is used instead of SW_MINIMIZE. Yet afterwards
2435 * the foreground and focus window are NULL. On Wine SW_SHOWMINIMIZED
2436 * leaves the device window active, breaking re-activation in the
2438 * {WM_ACTIVATE, DEVICE_WINDOW, TRUE, 0x200000 | WA_ACTIVE}, */
2439 {WM_WINDOWPOSCHANGED
, DEVICE_WINDOW
, FALSE
, 0},
2440 {WM_SIZE
, DEVICE_WINDOW
, TRUE
, SIZE_MINIMIZED
},
2441 {WM_ACTIVATEAPP
, FOCUS_WINDOW
, TRUE
, FALSE
},
2442 /* WM_ACTIVATEAPP is sent to the device window too, but the order is
2443 * not deterministic. It may be sent after the focus window handling
2447 static const struct message reactivate_messages
[] =
2449 {WM_WINDOWPOSCHANGING
, DEVICE_WINDOW
, FALSE
, 0},
2450 {WM_WINDOWPOSCHANGED
, DEVICE_WINDOW
, FALSE
, 0},
2451 {WM_MOVE
, DEVICE_WINDOW
, FALSE
, 0},
2452 {WM_ACTIVATEAPP
, FOCUS_WINDOW
, TRUE
, TRUE
},
2455 static const struct message focus_loss_messages_hidden
[] =
2457 {WM_DISPLAYCHANGE
, DEVICE_WINDOW
, FALSE
, 0},
2458 {WM_ACTIVATEAPP
, FOCUS_WINDOW
, TRUE
, FALSE
},
2461 static const struct message focus_loss_messages_filtered
[] =
2463 /* WM_ACTIVATE is delivered to the window proc because it is
2464 * generated by SetForegroundWindow before the d3d routine
2465 * starts it work. Don't check for it due to focus-follows-mouse
2467 {WM_DISPLAYCHANGE
, FOCUS_WINDOW
, FALSE
, 0},
2468 {WM_ACTIVATEAPP
, FOCUS_WINDOW
, TRUE
, FALSE
},
2471 static const struct message reactivate_messages_filtered
[] =
2473 {WM_ACTIVATEAPP
, FOCUS_WINDOW
, TRUE
, TRUE
},
2476 static const struct message sc_restore_messages
[] =
2478 /* WM_SYSCOMMAND is delivered only once, after d3d has already
2479 * processed it. Our wndproc has no way to prevent d3d from
2480 * handling the message. The second DefWindowProc call done by
2481 * our wndproc doesn't do any changes to the window because it
2482 * is already restored due to d3d's handling. */
2483 {WM_WINDOWPOSCHANGING
, FOCUS_WINDOW
, FALSE
, 0},
2484 {WM_WINDOWPOSCHANGED
, FOCUS_WINDOW
, FALSE
, 0},
2485 {WM_SIZE
, FOCUS_WINDOW
, TRUE
, SIZE_RESTORED
},
2486 {WM_SYSCOMMAND
, FOCUS_WINDOW
, TRUE
, SC_RESTORE
},
2489 static const struct message sc_minimize_messages
[] =
2491 {WM_SYSCOMMAND
, FOCUS_WINDOW
, TRUE
, SC_MINIMIZE
},
2492 {WM_WINDOWPOSCHANGING
, FOCUS_WINDOW
, FALSE
, 0},
2493 {WM_WINDOWPOSCHANGED
, FOCUS_WINDOW
, FALSE
, 0},
2494 {WM_MOVE
, FOCUS_WINDOW
, FALSE
, 0},
2495 {WM_SIZE
, FOCUS_WINDOW
, TRUE
, SIZE_MINIMIZED
},
2498 static const struct message sc_maximize_messages
[] =
2500 {WM_SYSCOMMAND
, FOCUS_WINDOW
, TRUE
, SC_MAXIMIZE
},
2501 {WM_WINDOWPOSCHANGING
, FOCUS_WINDOW
, FALSE
, 0},
2502 {WM_WINDOWPOSCHANGED
, FOCUS_WINDOW
, FALSE
, 0},
2503 {WM_MOVE
, FOCUS_WINDOW
, FALSE
, 0},
2504 {WM_SIZE
, FOCUS_WINDOW
, TRUE
, SIZE_MAXIMIZED
},
2508 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
2509 ok(!!d3d8
, "Failed to create a D3D object.\n");
2511 adapter_mode_count
= IDirect3D8_GetAdapterModeCount(d3d8
, D3DADAPTER_DEFAULT
);
2512 for (i
= 0; i
< adapter_mode_count
; ++i
)
2514 hr
= IDirect3D8_EnumAdapterModes(d3d8
, D3DADAPTER_DEFAULT
, i
, &d3ddm
);
2515 ok(SUCCEEDED(hr
), "Failed to enumerate display mode, hr %#x.\n", hr
);
2517 if (d3ddm
.Format
!= D3DFMT_X8R8G8B8
)
2519 if (d3ddm
.Width
== registry_mode
.dmPelsWidth
&& d3ddm
.Height
== registry_mode
.dmPelsHeight
)
2521 /* The r200 driver on Windows XP enumerates modes like 320x200 and 320x240 but
2522 * refuses to create a device at these sizes. */
2523 if (d3ddm
.Width
< 640 || d3ddm
.Height
< 480)
2528 user32_width
= d3ddm
.Width
;
2529 user32_height
= d3ddm
.Height
;
2533 /* Make sure the d3d mode is smaller in width or height and at most
2534 * equal in the other dimension than the mode passed to
2535 * ChangeDisplaySettings. Otherwise Windows shrinks the window to
2536 * the ChangeDisplaySettings parameters + 12. */
2537 if (d3ddm
.Width
== user32_width
&& d3ddm
.Height
== user32_height
)
2539 if (d3ddm
.Width
<= user32_width
&& d3ddm
.Height
<= user32_height
)
2541 d3d_width
= d3ddm
.Width
;
2542 d3d_height
= d3ddm
.Height
;
2545 if (user32_width
<= d3ddm
.Width
&& user32_height
<= d3ddm
.Height
)
2547 d3d_width
= user32_width
;
2548 d3d_height
= user32_height
;
2549 user32_width
= d3ddm
.Width
;
2550 user32_height
= d3ddm
.Height
;
2557 skip("Could not find adequate modes, skipping mode tests.\n");
2558 IDirect3D8_Release(d3d8
);
2562 wc
.lpfnWndProc
= test_proc
;
2563 wc
.lpszClassName
= "d3d8_test_wndproc_wc";
2564 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2566 thread_params
.window_created
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2567 ok(!!thread_params
.window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
2568 thread_params
.test_finished
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2569 ok(!!thread_params
.test_finished
, "CreateEvent failed, last error %#x.\n", GetLastError());
2571 memset(&devmode
, 0, sizeof(devmode
));
2572 devmode
.dmSize
= sizeof(devmode
);
2573 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2574 devmode
.dmPelsWidth
= user32_width
;
2575 devmode
.dmPelsHeight
= user32_height
;
2576 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2577 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2579 focus_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2580 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, user32_width
, user32_height
, 0, 0, 0, 0);
2581 device_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2582 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, user32_width
, user32_height
, 0, 0, 0, 0);
2583 thread
= CreateThread(NULL
, 0, wndproc_thread
, &thread_params
, 0, &tid
);
2584 ok(!!thread
, "Failed to create thread, last error %#x.\n", GetLastError());
2586 res
= WaitForSingleObject(thread_params
.window_created
, INFINITE
);
2587 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
2589 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2590 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2591 (LONG_PTR
)test_proc
, proc
);
2592 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2593 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2594 (LONG_PTR
)test_proc
, proc
);
2596 trace("device_window %p, focus_window %p, dummy_window %p.\n",
2597 device_window
, focus_window
, thread_params
.dummy_window
);
2600 ok(tmp
== device_window
, "Expected focus %p, got %p.\n", device_window
, tmp
);
2601 if (thread_params
.running_in_foreground
)
2603 tmp
= GetForegroundWindow();
2604 ok(tmp
== thread_params
.dummy_window
, "Expected foreground window %p, got %p.\n",
2605 thread_params
.dummy_window
, tmp
);
2608 skip("Not running in foreground, skip foreground window test\n");
2612 expect_messages
= create_messages
;
2614 device_desc
.device_window
= device_window
;
2615 device_desc
.width
= d3d_width
;
2616 device_desc
.height
= d3d_height
;
2617 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
2618 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
2620 skip("Failed to create a D3D device, skipping tests.\n");
2624 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2625 expect_messages
->message
, expect_messages
->window
);
2626 expect_messages
= NULL
;
2628 if (0) /* Disabled until we can make this work in a reliable way on Wine. */
2631 ok(tmp
== focus_window
, "Expected focus %p, got %p.\n", focus_window
, tmp
);
2632 tmp
= GetForegroundWindow();
2633 ok(tmp
== focus_window
, "Expected foreground window %p, got %p.\n", focus_window
, tmp
);
2635 SetForegroundWindow(focus_window
);
2638 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2639 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2640 (LONG_PTR
)test_proc
, proc
);
2642 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2643 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
2645 /* Change the mode while the device is in use and then drop focus. */
2646 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2647 devmode
.dmPelsWidth
= user32_width
;
2648 devmode
.dmPelsHeight
= user32_height
;
2649 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2650 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x, i=%u.\n", change_ret
, i
);
2652 /* Wine doesn't (yet) mark the device not reset when the mode is changed, thus the todo_wine.
2653 * But sometimes focus-follows-mouse WMs also temporarily drop window focus, which makes
2654 * mark the device lost, then not reset, causing the test to succeed for the wrong reason. */
2655 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
2656 if (hr
== D3DERR_DEVICENOTRESET
)
2657 ok(hr
== D3DERR_DEVICENOTRESET
, "Got unexpected hr %#x.\n", hr
);
2659 todo_wine
ok(hr
== D3DERR_DEVICENOTRESET
, "Got unexpected hr %#x.\n", hr
);
2661 expect_messages
= focus_loss_messages
;
2662 /* SetForegroundWindow is a poor replacement for the user pressing alt-tab or
2663 * manually changing the focus. It generates the same messages, but the task
2664 * bar still shows the previous foreground window as active, and the window has
2665 * an inactive titlebar if reactivated with SetForegroundWindow. Reactivating
2666 * the device is difficult, see below. */
2667 SetForegroundWindow(GetDesktopWindow());
2668 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2669 expect_messages
->message
, expect_messages
->window
);
2670 expect_messages
= NULL
;
2672 ok(tmp
!= device_window
, "The device window is active.\n");
2673 ok(tmp
!= focus_window
, "The focus window is active.\n");
2675 /* The Present call is necessary to make native realize the device is lost. */
2676 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
2677 ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
2678 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
2679 /* Focus-follows-mouse WMs prematurely reactivate our window. */
2680 if (hr
== D3DERR_DEVICENOTRESET
)
2681 todo_wine
ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
2683 ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
2685 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2686 ok(ret
, "Failed to get display mode.\n");
2687 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2688 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpect screen size %ux%u.\n",
2689 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2691 /* I have to minimize and restore the focus window, otherwise native d3d9 fails
2692 * device::reset with D3DERR_DEVICELOST. This does not happen when the window
2693 * restore is triggered by the user. */
2694 expect_messages
= reactivate_messages
;
2695 ShowWindow(focus_window
, SW_MINIMIZE
);
2696 ShowWindow(focus_window
, SW_RESTORE
);
2697 /* Set focus twice to make KDE and fvwm in focus-follows-mouse mode happy. */
2698 SetForegroundWindow(focus_window
);
2700 SetForegroundWindow(focus_window
);
2701 flush_events(); /* WM_WINDOWPOSCHANGING etc arrive after SetForegroundWindow returns. */
2702 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it, i=%u.\n",
2703 expect_messages
->message
, expect_messages
->window
, i
);
2704 expect_messages
= NULL
;
2706 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
2707 ok(hr
== D3DERR_DEVICENOTRESET
, "Got unexpected hr %#x.\n", hr
);
2709 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2710 ok(ret
, "Failed to get display mode.\n");
2711 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2712 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpect screen size %ux%u.\n",
2713 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2715 hr
= reset_device(device
, &device_desc
);
2716 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
2718 ShowWindow(device_window
, SW_HIDE
);
2721 expect_messages
= focus_loss_messages_hidden
;
2722 windowposchanged_received
= 0;
2723 SetForegroundWindow(GetDesktopWindow());
2724 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2725 expect_messages
->message
, expect_messages
->window
);
2726 ok(!windowposchanged_received
, "Received WM_WINDOWPOSCHANGED but did not expect it.\n");
2727 expect_messages
= NULL
;
2730 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2731 ok(ret
, "Failed to get display mode.\n");
2732 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
, "Got unexpect width %u.\n", devmode
.dmPelsWidth
);
2733 ok(devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpect height %u.\n", devmode
.dmPelsHeight
);
2735 /* SW_SHOWMINNOACTIVE is needed to make FVWM happy. SW_SHOWNOACTIVATE is needed to make windows
2736 * send SIZE_RESTORED after ShowWindow(SW_SHOWMINNOACTIVE). */
2737 ShowWindow(focus_window
, SW_SHOWNOACTIVATE
);
2738 ShowWindow(focus_window
, SW_SHOWMINNOACTIVE
);
2741 syscommand_received
= 0;
2742 expect_messages
= sc_restore_messages
;
2743 SendMessageA(focus_window
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
2744 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2745 expect_messages
->message
, expect_messages
->window
);
2746 ok(syscommand_received
== 1, "Got unexpected number of WM_SYSCOMMAND messages: %d.\n", syscommand_received
);
2747 expect_messages
= NULL
;
2750 expect_messages
= sc_minimize_messages
;
2751 SendMessageA(focus_window
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
2752 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2753 expect_messages
->message
, expect_messages
->window
);
2754 expect_messages
= NULL
;
2757 expect_messages
= sc_maximize_messages
;
2758 SendMessageA(focus_window
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
2759 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2760 expect_messages
->message
, expect_messages
->window
);
2761 expect_messages
= NULL
;
2764 SetForegroundWindow(GetDesktopWindow());
2765 ShowWindow(device_window
, SW_MINIMIZE
);
2766 ShowWindow(focus_window
, SW_MINIMIZE
);
2767 ShowWindow(focus_window
, SW_RESTORE
);
2768 SetForegroundWindow(focus_window
);
2771 /* Releasing a device in lost state breaks follow-up tests on native. */
2772 hr
= reset_device(device
, &device_desc
);
2773 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
2775 filter_messages
= focus_window
;
2776 ref
= IDirect3DDevice8_Release(device
);
2777 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2779 /* Fix up the mode until Wine's device release behavior is fixed. */
2780 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2781 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2783 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2784 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2785 (LONG_PTR
)test_proc
, proc
);
2787 /* Hide the device window. It prevents WM_ACTIVATEAPP messages from being sent
2788 * on native in the test below. It isn't needed anyways. Creating the third
2789 * device will show it again. */
2790 filter_messages
= NULL
;
2791 ShowWindow(device_window
, SW_HIDE
);
2792 /* Remove the maximized state from the SYSCOMMAND test while we're not
2793 * interfering with a device. */
2794 ShowWindow(focus_window
, SW_SHOWNORMAL
);
2795 filter_messages
= focus_window
;
2797 device_desc
.device_window
= focus_window
;
2798 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
2800 skip("Failed to create a D3D device, skipping tests.\n");
2804 filter_messages
= NULL
;
2806 expect_messages
= focus_loss_messages_filtered
;
2807 windowposchanged_received
= 0;
2808 SetForegroundWindow(GetDesktopWindow());
2809 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2810 expect_messages
->message
, expect_messages
->window
);
2811 ok(!windowposchanged_received
, "Received WM_WINDOWPOSCHANGED but did not expect it.\n");
2812 expect_messages
= NULL
;
2814 /* The window is iconic even though no message was sent. */
2815 ok(IsIconic(focus_window
), "The focus window is not iconic.\n");
2817 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
2818 ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
2820 syscommand_received
= 0;
2821 expect_messages
= sc_restore_messages
;
2822 SendMessageA(focus_window
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
2823 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2824 expect_messages
->message
, expect_messages
->window
);
2825 ok(syscommand_received
== 1, "Got unexpected number of WM_SYSCOMMAND messages: %d.\n", syscommand_received
);
2826 expect_messages
= NULL
;
2830 ShowWindow(focus_window
, SW_RESTORE
);
2833 expect_messages
= sc_minimize_messages
;
2834 SendMessageA(focus_window
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
2835 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2836 expect_messages
->message
, expect_messages
->window
);
2837 expect_messages
= NULL
;
2838 /* Needed to make the next test reliably send WM_SIZE(SIZE_MAXIMIZED). Without
2839 * this call it sends WM_SIZE(SIZE_RESTORED). */
2840 ShowWindow(focus_window
, SW_RESTORE
);
2843 expect_messages
= sc_maximize_messages
;
2844 SendMessageA(focus_window
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
2845 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2846 expect_messages
->message
, expect_messages
->window
);
2847 expect_messages
= NULL
;
2848 SetForegroundWindow(GetDesktopWindow());
2851 /* ShowWindow(SW_RESTORE); SetForegroundWindow(desktop); SetForegroundWindow(focus);
2852 * results in the second SetForegroundWindow call failing and the device not being
2853 * restored on native. Directly using ShowWindow(SW_RESTORE) works, but it means
2854 * we cannot test for the absence of WM_WINDOWPOSCHANGED messages. */
2855 expect_messages
= reactivate_messages_filtered
;
2856 ShowWindow(focus_window
, SW_RESTORE
);
2857 SetForegroundWindow(focus_window
);
2859 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it\n",
2860 expect_messages
->message
, expect_messages
->window
);
2861 expect_messages
= NULL
;
2863 filter_messages
= focus_window
;
2864 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
2865 ok(hr
== D3DERR_DEVICENOTRESET
, "Got unexpected hr %#x.\n", hr
);
2867 hr
= reset_device(device
, &device_desc
);
2868 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
2870 ref
= IDirect3DDevice8_Release(device
);
2871 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2873 device_desc
.device_window
= device_window
;
2874 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
2876 skip("Failed to create a D3D device, skipping tests.\n");
2880 proc
= SetWindowLongPtrA(focus_window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2881 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
2883 ref
= IDirect3DDevice8_Release(device
);
2884 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2886 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2887 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2888 (LONG_PTR
)DefWindowProcA
, proc
);
2891 filter_messages
= NULL
;
2892 IDirect3D8_Release(d3d8
);
2894 SetEvent(thread_params
.test_finished
);
2895 WaitForSingleObject(thread
, INFINITE
);
2896 CloseHandle(thread_params
.test_finished
);
2897 CloseHandle(thread_params
.window_created
);
2898 CloseHandle(thread
);
2900 DestroyWindow(device_window
);
2901 DestroyWindow(focus_window
);
2902 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL
));
2905 static void test_wndproc_windowed(void)
2907 struct wndproc_thread_param thread_params
;
2908 struct device_desc device_desc
;
2909 IDirect3DDevice8
*device
;
2919 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
2920 ok(!!d3d8
, "Failed to create a D3D object.\n");
2922 wc
.lpfnWndProc
= test_proc
;
2923 wc
.lpszClassName
= "d3d8_test_wndproc_wc";
2924 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2926 thread_params
.window_created
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2927 ok(!!thread_params
.window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
2928 thread_params
.test_finished
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2929 ok(!!thread_params
.test_finished
, "CreateEvent failed, last error %#x.\n", GetLastError());
2931 focus_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2932 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, registry_mode
.dmPelsWidth
,
2933 registry_mode
.dmPelsHeight
, 0, 0, 0, 0);
2934 device_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2935 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, registry_mode
.dmPelsWidth
,
2936 registry_mode
.dmPelsHeight
, 0, 0, 0, 0);
2937 thread
= CreateThread(NULL
, 0, wndproc_thread
, &thread_params
, 0, &tid
);
2938 ok(!!thread
, "Failed to create thread, last error %#x.\n", GetLastError());
2940 res
= WaitForSingleObject(thread_params
.window_created
, INFINITE
);
2941 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
2943 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2944 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2945 (LONG_PTR
)test_proc
, proc
);
2946 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2947 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2948 (LONG_PTR
)test_proc
, proc
);
2950 trace("device_window %p, focus_window %p, dummy_window %p.\n",
2951 device_window
, focus_window
, thread_params
.dummy_window
);
2954 ok(tmp
== device_window
, "Expected focus %p, got %p.\n", device_window
, tmp
);
2955 if (thread_params
.running_in_foreground
)
2957 tmp
= GetForegroundWindow();
2958 ok(tmp
== thread_params
.dummy_window
, "Expected foreground window %p, got %p.\n",
2959 thread_params
.dummy_window
, tmp
);
2962 skip("Not running in foreground, skip foreground window test\n");
2964 filter_messages
= focus_window
;
2966 device_desc
.device_window
= device_window
;
2967 device_desc
.width
= registry_mode
.dmPelsWidth
;
2968 device_desc
.height
= registry_mode
.dmPelsHeight
;
2969 device_desc
.flags
= 0;
2970 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
2972 skip("Failed to create a D3D device, skipping tests.\n");
2977 ok(tmp
== device_window
, "Expected focus %p, got %p.\n", device_window
, tmp
);
2978 tmp
= GetForegroundWindow();
2979 ok(tmp
== thread_params
.dummy_window
, "Expected foreground window %p, got %p.\n",
2980 thread_params
.dummy_window
, tmp
);
2982 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2983 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2984 (LONG_PTR
)test_proc
, proc
);
2986 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2987 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2988 (LONG_PTR
)test_proc
, proc
);
2990 filter_messages
= NULL
;
2992 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
2993 hr
= reset_device(device
, &device_desc
);
2994 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
2996 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2997 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2998 (LONG_PTR
)test_proc
, proc
);
3000 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3001 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
3003 device_desc
.flags
= 0;
3004 hr
= reset_device(device
, &device_desc
);
3005 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3007 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3008 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3009 (LONG_PTR
)test_proc
, proc
);
3011 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3012 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3013 (LONG_PTR
)test_proc
, proc
);
3015 filter_messages
= focus_window
;
3017 ref
= IDirect3DDevice8_Release(device
);
3018 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
3020 filter_messages
= device_window
;
3022 device_desc
.device_window
= focus_window
;
3023 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
3025 skip("Failed to create a D3D device, skipping tests.\n");
3029 filter_messages
= NULL
;
3031 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3032 hr
= reset_device(device
, &device_desc
);
3033 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3035 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3036 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3037 (LONG_PTR
)test_proc
, proc
);
3039 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3040 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
3042 device_desc
.flags
= 0;
3043 hr
= reset_device(device
, &device_desc
);
3044 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3046 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3047 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3048 (LONG_PTR
)test_proc
, proc
);
3050 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3051 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3052 (LONG_PTR
)test_proc
, proc
);
3054 filter_messages
= device_window
;
3056 ref
= IDirect3DDevice8_Release(device
);
3057 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
3059 device_desc
.device_window
= device_window
;
3060 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
3062 skip("Failed to create a D3D device, skipping tests.\n");
3066 filter_messages
= NULL
;
3068 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3069 hr
= reset_device(device
, &device_desc
);
3070 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3072 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3073 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3074 (LONG_PTR
)test_proc
, proc
);
3076 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3077 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
3079 device_desc
.flags
= 0;
3080 hr
= reset_device(device
, &device_desc
);
3081 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3083 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3084 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3085 (LONG_PTR
)test_proc
, proc
);
3087 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3088 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3089 (LONG_PTR
)test_proc
, proc
);
3091 filter_messages
= device_window
;
3093 ref
= IDirect3DDevice8_Release(device
);
3094 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
3097 filter_messages
= NULL
;
3098 IDirect3D8_Release(d3d8
);
3100 SetEvent(thread_params
.test_finished
);
3101 WaitForSingleObject(thread
, INFINITE
);
3102 CloseHandle(thread_params
.test_finished
);
3103 CloseHandle(thread_params
.window_created
);
3104 CloseHandle(thread
);
3106 DestroyWindow(device_window
);
3107 DestroyWindow(focus_window
);
3108 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL
));
3111 static inline void set_fpu_cw(WORD cw
)
3113 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3114 #define D3D8_TEST_SET_FPU_CW 1
3115 __asm__
volatile ("fnclex");
3116 __asm__
volatile ("fldcw %0" : : "m" (cw
));
3117 #elif defined(__i386__) && defined(_MSC_VER)
3118 #define D3D8_TEST_SET_FPU_CW 1
3124 static inline WORD
get_fpu_cw(void)
3127 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3128 #define D3D8_TEST_GET_FPU_CW 1
3129 __asm__
volatile ("fnstcw %0" : "=m" (cw
));
3130 #elif defined(__i386__) && defined(_MSC_VER)
3131 #define D3D8_TEST_GET_FPU_CW 1
3137 static WORD callback_cw
, callback_set_cw
;
3138 static DWORD callback_tid
;
3140 static HRESULT WINAPI
dummy_object_QueryInterface(IUnknown
*iface
, REFIID riid
, void **out
)
3143 return E_NOINTERFACE
;
3146 static ULONG WINAPI
dummy_object_AddRef(IUnknown
*iface
)
3148 callback_cw
= get_fpu_cw();
3149 set_fpu_cw(callback_set_cw
);
3150 callback_tid
= GetCurrentThreadId();
3154 static ULONG WINAPI
dummy_object_Release(IUnknown
*iface
)
3156 callback_cw
= get_fpu_cw();
3157 set_fpu_cw(callback_set_cw
);
3158 callback_tid
= GetCurrentThreadId();
3162 static const IUnknownVtbl dummy_object_vtbl
=
3164 dummy_object_QueryInterface
,
3165 dummy_object_AddRef
,
3166 dummy_object_Release
,
3169 static const GUID d3d8_private_data_test_guid
=
3174 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
3177 static void test_fpu_setup(void)
3179 #if defined(D3D8_TEST_SET_FPU_CW) && defined(D3D8_TEST_GET_FPU_CW)
3180 struct device_desc device_desc
;
3181 IDirect3DDevice8
*device
;
3182 D3DDISPLAYMODE d3ddm
;
3187 IDirect3DSurface8
*surface
;
3188 IUnknown dummy_object
= {&dummy_object_vtbl
};
3190 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_CAPTION
, 0, 0,
3191 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, 0, 0, 0, 0);
3192 ok(!!window
, "Failed to create a window.\n");
3193 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3194 ok(!!d3d8
, "Failed to create a D3D object.\n");
3196 hr
= IDirect3D8_GetAdapterDisplayMode(d3d8
, D3DADAPTER_DEFAULT
, &d3ddm
);
3197 ok(SUCCEEDED(hr
), "GetAdapterDisplayMode failed, hr %#x.\n", hr
);
3199 device_desc
.device_window
= window
;
3200 device_desc
.width
= 640;
3201 device_desc
.height
= 480;
3202 device_desc
.flags
= 0;
3206 ok(cw
== 0xf60, "cw is %#x, expected 0xf60.\n", cw
);
3208 if (!(device
= create_device(d3d8
, window
, &device_desc
)))
3210 skip("Failed to create a 3D device, skipping test.\n");
3216 ok(cw
== 0x7f, "cw is %#x, expected 0x7f.\n", cw
);
3218 hr
= IDirect3DDevice8_GetRenderTarget(device
, &surface
);
3219 ok(SUCCEEDED(hr
), "Failed to get render target surface, hr %#x.\n", hr
);
3221 callback_set_cw
= 0xf60;
3222 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
3223 &dummy_object
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
3224 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
3225 ok(callback_cw
== 0x7f, "Callback cw is %#x, expected 0x7f.\n", callback_cw
);
3226 ok(callback_tid
== GetCurrentThreadId(), "Got unexpected thread id.\n");
3228 ok(cw
== 0xf60, "cw is %#x, expected 0xf60.\n", cw
);
3231 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
3232 &dummy_object
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
3233 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
3234 ok(callback_cw
== 0xf60, "Callback cw is %#x, expected 0xf60.\n", callback_cw
);
3235 ok(callback_tid
== GetCurrentThreadId(), "Got unexpected thread id.\n");
3237 callback_set_cw
= 0x7f;
3240 IDirect3DSurface8_Release(surface
);
3243 IDirect3DDevice8_Release(device
);
3244 ok(callback_cw
== 0x7f, "Callback cw is %#x, expected 0x7f.\n", callback_cw
);
3245 ok(callback_tid
== GetCurrentThreadId(), "Got unexpected thread id.\n");
3248 ok(cw
== 0x7f, "cw is %#x, expected 0x7f.\n", cw
);
3251 ok(cw
== 0xf60, "cw is %#x, expected 0xf60.\n", cw
);
3253 device_desc
.flags
= CREATE_DEVICE_FPU_PRESERVE
;
3254 device
= create_device(d3d8
, window
, &device_desc
);
3255 ok(!!device
, "CreateDevice failed.\n");
3258 ok(cw
== 0xf60, "cw is %#x, expected 0xf60.\n", cw
);
3260 hr
= IDirect3DDevice8_GetRenderTarget(device
, &surface
);
3261 ok(SUCCEEDED(hr
), "Failed to get render target surface, hr %#x.\n", hr
);
3264 callback_set_cw
= 0x37f;
3265 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
3266 &dummy_object
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
3267 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
3268 ok(callback_cw
== 0xf60, "Callback cw is %#x, expected 0xf60.\n", callback_cw
);
3269 ok(callback_tid
== GetCurrentThreadId(), "Got unexpected thread id.\n");
3271 ok(cw
== 0x37f, "cw is %#x, expected 0x37f.\n", cw
);
3273 IDirect3DSurface8_Release(surface
);
3276 IDirect3DDevice8_Release(device
);
3277 ok(callback_cw
== 0x37f, "Callback cw is %#x, expected 0x37f.\n", callback_cw
);
3278 ok(callback_tid
== GetCurrentThreadId(), "Got unexpected thread id.\n");
3281 DestroyWindow(window
);
3282 IDirect3D8_Release(d3d8
);
3286 static void test_ApplyStateBlock(void)
3288 IDirect3DDevice8
*device
;
3292 DWORD received
, token
;
3294 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3295 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
3296 ok(!!window
, "Failed to create a window.\n");
3297 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3298 ok(!!d3d8
, "Failed to create a D3D object.\n");
3299 if (!(device
= create_device(d3d8
, window
, NULL
)))
3301 skip("Failed to create a 3D device, skipping test.\n");
3305 IDirect3DDevice8_BeginStateBlock(device
);
3306 IDirect3DDevice8_SetRenderState(device
, D3DRS_ZENABLE
, TRUE
);
3307 IDirect3DDevice8_EndStateBlock(device
, &token
);
3308 ok(token
, "Received zero stateblock handle.\n");
3309 IDirect3DDevice8_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
3311 hr
= IDirect3DDevice8_GetRenderState(device
, D3DRS_ZENABLE
, &received
);
3312 ok(hr
== D3D_OK
, "Expected D3D_OK, received %#x.\n", hr
);
3313 ok(!received
, "Expected = FALSE, received TRUE.\n");
3315 hr
= IDirect3DDevice8_ApplyStateBlock(device
, 0);
3316 ok(hr
== D3D_OK
, "Expected D3D_OK, received %#x.\n", hr
);
3317 hr
= IDirect3DDevice8_GetRenderState(device
, D3DRS_ZENABLE
, &received
);
3318 ok(hr
== D3D_OK
, "Expected D3D_OK, received %#x.\n", hr
);
3319 ok(!received
, "Expected FALSE, received TRUE.\n");
3321 hr
= IDirect3DDevice8_ApplyStateBlock(device
, token
);
3322 ok(hr
== D3D_OK
, "Expected D3D_OK, received %#x.\n", hr
);
3323 hr
= IDirect3DDevice8_GetRenderState(device
, D3DRS_ZENABLE
, &received
);
3324 ok(hr
== D3D_OK
, "Expected D3D_OK, received %#x.\n", hr
);
3325 ok(received
, "Expected TRUE, received FALSE.\n");
3327 IDirect3DDevice8_DeleteStateBlock(device
, token
);
3328 IDirect3DDevice8_Release(device
);
3330 IDirect3D8_Release(d3d8
);
3331 DestroyWindow(window
);
3334 static void test_depth_stencil_size(void)
3336 IDirect3DDevice8
*device
;
3337 IDirect3DSurface8
*ds
, *rt
, *ds_bigger
, *ds_bigger2
;
3338 IDirect3DSurface8
*surf
;
3343 hwnd
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3344 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
3345 ok(!!hwnd
, "Failed to create a window.\n");
3346 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3347 ok(!!d3d8
, "Failed to create a D3D object.\n");
3349 if (!(device
= create_device(d3d8
, hwnd
, NULL
)))
3351 skip("Failed to create a 3D device, skipping test.\n");
3355 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 64, 64, D3DFMT_A8R8G8B8
, D3DMULTISAMPLE_NONE
, FALSE
, &rt
);
3356 ok(SUCCEEDED(hr
), "IDirect3DDevice8_CreateRenderTarget failed, hr %#x.\n", hr
);
3357 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 32, 32, D3DFMT_D24X8
, D3DMULTISAMPLE_NONE
, &ds
);
3358 ok(SUCCEEDED(hr
), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr
);
3359 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 128, 128, D3DFMT_D24X8
, D3DMULTISAMPLE_NONE
, &ds_bigger
);
3360 ok(SUCCEEDED(hr
), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr
);
3361 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 128, 128, D3DFMT_D24X8
, D3DMULTISAMPLE_NONE
, &ds_bigger2
);
3362 ok(SUCCEEDED(hr
), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr
);
3364 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, ds
);
3365 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_SetRenderTarget returned %#x, expected D3DERR_INVALIDCALL.\n", hr
);
3366 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, ds_bigger
);
3367 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr
);
3369 /* try to set the small ds without changing the render target at the same time */
3370 hr
= IDirect3DDevice8_SetRenderTarget(device
, NULL
, ds
);
3371 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_SetRenderTarget returned %#x, expected D3DERR_INVALIDCALL.\n", hr
);
3372 hr
= IDirect3DDevice8_SetRenderTarget(device
, NULL
, ds_bigger2
);
3373 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr
);
3375 hr
= IDirect3DDevice8_GetRenderTarget(device
, &surf
);
3376 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetRenderTarget failed, hr %#x.\n", hr
);
3377 ok(surf
== rt
, "The render target is %p, expected %p\n", surf
, rt
);
3378 IDirect3DSurface8_Release(surf
);
3379 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surf
);
3380 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetDepthStencilSurface failed, hr %#x.\n", hr
);
3381 ok(surf
== ds_bigger2
, "The depth stencil is %p, expected %p\n", surf
, ds_bigger2
);
3382 IDirect3DSurface8_Release(surf
);
3384 hr
= IDirect3DDevice8_SetRenderTarget(device
, NULL
, NULL
);
3385 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr
);
3386 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surf
);
3387 ok(FAILED(hr
), "IDirect3DDevice8_GetDepthStencilSurface should have failed, hr %#x.\n", hr
);
3388 ok(surf
== NULL
, "The depth stencil is %p, expected NULL\n", surf
);
3389 if (surf
) IDirect3DSurface8_Release(surf
);
3391 IDirect3DSurface8_Release(rt
);
3392 IDirect3DSurface8_Release(ds
);
3393 IDirect3DSurface8_Release(ds_bigger
);
3394 IDirect3DSurface8_Release(ds_bigger2
);
3397 IDirect3D8_Release(d3d8
);
3398 DestroyWindow(hwnd
);
3401 static void test_window_style(void)
3403 RECT focus_rect
, fullscreen_rect
, r
;
3404 LONG device_style
, device_exstyle
;
3405 LONG focus_style
, focus_exstyle
;
3406 struct device_desc device_desc
;
3407 LONG style
, expected_style
;
3408 IDirect3DDevice8
*device
;
3414 focus_window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3415 0, 0, registry_mode
.dmPelsWidth
/ 2, registry_mode
.dmPelsHeight
/ 2, 0, 0, 0, 0);
3416 device_window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3417 0, 0, registry_mode
.dmPelsWidth
/ 2, registry_mode
.dmPelsHeight
/ 2, 0, 0, 0, 0);
3418 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3419 ok(!!d3d8
, "Failed to create a D3D object.\n");
3421 device_style
= GetWindowLongA(device_window
, GWL_STYLE
);
3422 device_exstyle
= GetWindowLongA(device_window
, GWL_EXSTYLE
);
3423 focus_style
= GetWindowLongA(focus_window
, GWL_STYLE
);
3424 focus_exstyle
= GetWindowLongA(focus_window
, GWL_EXSTYLE
);
3426 SetRect(&fullscreen_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
3427 GetWindowRect(focus_window
, &focus_rect
);
3429 device_desc
.device_window
= device_window
;
3430 device_desc
.width
= registry_mode
.dmPelsWidth
;
3431 device_desc
.height
= registry_mode
.dmPelsHeight
;
3432 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3433 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
3435 skip("Failed to create a D3D device, skipping tests.\n");
3439 style
= GetWindowLongA(device_window
, GWL_STYLE
);
3440 expected_style
= device_style
| WS_VISIBLE
;
3441 todo_wine
ok(style
== expected_style
, "Expected device window style %#x, got %#x.\n",
3442 expected_style
, style
);
3443 style
= GetWindowLongA(device_window
, GWL_EXSTYLE
);
3444 expected_style
= device_exstyle
| WS_EX_TOPMOST
;
3445 todo_wine
ok(style
== expected_style
, "Expected device window extended style %#x, got %#x.\n",
3446 expected_style
, style
);
3448 style
= GetWindowLongA(focus_window
, GWL_STYLE
);
3449 ok(style
== focus_style
, "Expected focus window style %#x, got %#x.\n",
3450 focus_style
, style
);
3451 style
= GetWindowLongA(focus_window
, GWL_EXSTYLE
);
3452 ok(style
== focus_exstyle
, "Expected focus window extended style %#x, got %#x.\n",
3453 focus_exstyle
, style
);
3455 GetWindowRect(device_window
, &r
);
3456 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3457 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
3458 r
.left
, r
.top
, r
.right
, r
.bottom
);
3459 GetClientRect(device_window
, &r
);
3460 todo_wine
ok(!EqualRect(&r
, &fullscreen_rect
), "Client rect and window rect are equal.\n");
3461 GetWindowRect(focus_window
, &r
);
3462 ok(EqualRect(&r
, &focus_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3463 focus_rect
.left
, focus_rect
.top
, focus_rect
.right
, focus_rect
.bottom
,
3464 r
.left
, r
.top
, r
.right
, r
.bottom
);
3466 device_desc
.flags
= 0;
3467 hr
= reset_device(device
, &device_desc
);
3468 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3470 style
= GetWindowLongA(device_window
, GWL_STYLE
);
3471 expected_style
= device_style
| WS_VISIBLE
;
3472 ok(style
== expected_style
, "Expected device window style %#x, got %#x.\n",
3473 expected_style
, style
);
3474 style
= GetWindowLongA(device_window
, GWL_EXSTYLE
);
3475 expected_style
= device_exstyle
| WS_EX_TOPMOST
;
3476 ok(style
== expected_style
, "Expected device window extended style %#x, got %#x.\n",
3477 expected_style
, style
);
3479 style
= GetWindowLongA(focus_window
, GWL_STYLE
);
3480 ok(style
== focus_style
, "Expected focus window style %#x, got %#x.\n",
3481 focus_style
, style
);
3482 style
= GetWindowLongA(focus_window
, GWL_EXSTYLE
);
3483 ok(style
== focus_exstyle
, "Expected focus window extended style %#x, got %#x.\n",
3484 focus_exstyle
, style
);
3486 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3487 hr
= reset_device(device
, &device_desc
);
3488 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3489 ret
= SetForegroundWindow(GetDesktopWindow());
3490 ok(ret
, "Failed to set foreground window.\n");
3492 style
= GetWindowLongA(device_window
, GWL_STYLE
);
3493 expected_style
= device_style
| WS_MINIMIZE
| WS_VISIBLE
;
3494 todo_wine
ok(style
== expected_style
, "Expected device window style %#x, got %#x.\n",
3495 expected_style
, style
);
3496 style
= GetWindowLongA(device_window
, GWL_EXSTYLE
);
3497 expected_style
= device_exstyle
| WS_EX_TOPMOST
;
3498 todo_wine
ok(style
== expected_style
, "Expected device window extended style %#x, got %#x.\n",
3499 expected_style
, style
);
3501 style
= GetWindowLongA(focus_window
, GWL_STYLE
);
3502 ok(style
== focus_style
, "Expected focus window style %#x, got %#x.\n",
3503 focus_style
, style
);
3504 style
= GetWindowLongA(focus_window
, GWL_EXSTYLE
);
3505 ok(style
== focus_exstyle
, "Expected focus window extended style %#x, got %#x.\n",
3506 focus_exstyle
, style
);
3508 /* Follow-up tests fail on native if the device is destroyed while lost. */
3509 ShowWindow(focus_window
, SW_MINIMIZE
);
3510 ShowWindow(focus_window
, SW_RESTORE
);
3511 ret
= SetForegroundWindow(focus_window
);
3512 ok(ret
, "Failed to set foreground window.\n");
3514 hr
= reset_device(device
, &device_desc
);
3515 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3517 ref
= IDirect3DDevice8_Release(device
);
3518 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
3521 IDirect3D8_Release(d3d8
);
3523 DestroyWindow(device_window
);
3524 DestroyWindow(focus_window
);
3527 static void test_unsupported_shaders(void)
3529 IDirect3DDevice8
*device
;
3537 static const DWORD vs_2_0
[] =
3539 0xfffe0200, /* vs_2_0 */
3540 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
3541 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
3542 0x03000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
3543 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
3544 0x0000ffff /* end */
3546 static const DWORD ps_2_0
[] =
3548 0xffff0200, /* ps_2_0 */
3549 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
3550 0x03000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
3551 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
3552 0x0000ffff /* end */
3557 def c255
, 1.0, 1.0, 1.0, 1.0
3561 static const DWORD vs_1_255
[] =
3564 0x0000001f, 0x80000000, 0x900f0000,
3565 0x00000051, 0xa00f00ff, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
3566 0x00000002, 0x800f0000, 0x90e40000, 0xa0e400ff,
3567 0x00000001, 0xc00f0000, 0x80e40000,
3573 def c256
, 1.0, 1.0, 1.0, 1.0
3577 static const DWORD vs_1_256
[] =
3580 0x0000001f, 0x80000000, 0x900f0000,
3581 0x00000051, 0xa00f0100, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
3582 0x00000002, 0x800f0000, 0x90e40000, 0xa0e40100,
3583 0x00000001, 0xc00f0000, 0x80e40000,
3587 static const DWORD decl
[] =
3590 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
),
3594 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3595 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
3596 ok(!!window
, "Failed to create a window.\n");
3597 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
3598 ok(!!d3d
, "Failed to create a D3D object.\n");
3599 if (!(device
= create_device(d3d
, window
, NULL
)))
3601 skip("Failed to create a D3D device, skipping tests.\n");
3602 IDirect3D8_Release(d3d
);
3603 DestroyWindow(window
);
3607 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, simple_ps
, &vs
, 0);
3608 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
3610 hr
= IDirect3DDevice8_CreatePixelShader(device
, simple_vs
, &ps
);
3611 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
3613 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, vs_2_0
, &vs
, 0);
3614 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
3616 hr
= IDirect3DDevice8_CreatePixelShader(device
, ps_2_0
, &ps
);
3617 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
3619 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
3620 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
3621 if (caps
.MaxVertexShaderConst
< 256)
3623 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, vs_1_255
, &vs
, 0);
3624 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3628 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, vs_1_255
, &vs
, 0);
3629 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3630 hr
= IDirect3DDevice8_DeleteVertexShader(device
, vs
);
3631 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
3632 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, vs_1_256
, &vs
, 0);
3633 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3636 refcount
= IDirect3DDevice8_Release(device
);
3637 ok(!refcount
, "Device has %u references left.\n", refcount
);
3638 IDirect3D8_Release(d3d
);
3639 DestroyWindow(window
);
3642 static void test_mode_change(void)
3644 RECT d3d_rect
, focus_rect
, r
;
3645 struct device_desc device_desc
;
3646 IDirect3DSurface8
*backbuffer
;
3647 IDirect3DDevice8
*device
;
3648 D3DSURFACE_DESC desc
;
3652 UINT adapter_mode_count
, i
;
3656 D3DDISPLAYMODE d3ddm
;
3657 DWORD d3d_width
= 0, d3d_height
= 0, user32_width
= 0, user32_height
= 0;
3659 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3660 ok(!!d3d8
, "Failed to create a D3D object.\n");
3662 adapter_mode_count
= IDirect3D8_GetAdapterModeCount(d3d8
, D3DADAPTER_DEFAULT
);
3663 for (i
= 0; i
< adapter_mode_count
; ++i
)
3665 hr
= IDirect3D8_EnumAdapterModes(d3d8
, D3DADAPTER_DEFAULT
, i
, &d3ddm
);
3666 ok(SUCCEEDED(hr
), "Failed to enumerate display mode, hr %#x.\n", hr
);
3668 if (d3ddm
.Format
!= D3DFMT_X8R8G8B8
)
3670 if (d3ddm
.Width
== registry_mode
.dmPelsWidth
&& d3ddm
.Height
== registry_mode
.dmPelsHeight
)
3672 /* The r200 driver on Windows XP enumerates modes like 320x200 and 320x240 but
3673 * refuses to create a device at these sizes. */
3674 if (d3ddm
.Width
< 640 || d3ddm
.Height
< 480)
3679 user32_width
= d3ddm
.Width
;
3680 user32_height
= d3ddm
.Height
;
3684 /* Make sure the d3d mode is smaller in width or height and at most
3685 * equal in the other dimension than the mode passed to
3686 * ChangeDisplaySettings. Otherwise Windows shrinks the window to
3687 * the ChangeDisplaySettings parameters + 12. */
3688 if (d3ddm
.Width
== user32_width
&& d3ddm
.Height
== user32_height
)
3690 if (d3ddm
.Width
<= user32_width
&& d3ddm
.Height
<= user32_height
)
3692 d3d_width
= d3ddm
.Width
;
3693 d3d_height
= d3ddm
.Height
;
3696 if (user32_width
<= d3ddm
.Width
&& user32_height
<= d3ddm
.Height
)
3698 d3d_width
= user32_width
;
3699 d3d_height
= user32_height
;
3700 user32_width
= d3ddm
.Width
;
3701 user32_height
= d3ddm
.Height
;
3708 skip("Could not find adequate modes, skipping mode tests.\n");
3709 IDirect3D8_Release(d3d8
);
3713 memset(&devmode
, 0, sizeof(devmode
));
3714 devmode
.dmSize
= sizeof(devmode
);
3715 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
3716 devmode
.dmPelsWidth
= user32_width
;
3717 devmode
.dmPelsHeight
= user32_height
;
3718 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
3719 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3721 /* Make the windows visible, otherwise device::release does not restore the mode if
3722 * the application is not in foreground like on the testbot. */
3723 focus_window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
3724 0, 0, user32_width
/ 2, user32_height
/ 2, 0, 0, 0, 0);
3725 device_window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
3726 0, 0, user32_width
/ 2, user32_height
/ 2, 0, 0, 0, 0);
3728 SetRect(&d3d_rect
, 0, 0, d3d_width
, d3d_height
);
3729 GetWindowRect(focus_window
, &focus_rect
);
3731 device_desc
.device_window
= device_window
;
3732 device_desc
.width
= d3d_width
;
3733 device_desc
.height
= d3d_height
;
3734 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3735 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
3737 skip("Failed to create a D3D device, skipping tests.\n");
3738 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
3739 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3743 devmode
.dmPelsWidth
= user32_width
;
3744 devmode
.dmPelsHeight
= user32_height
;
3745 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
3746 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3748 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3749 ok(ret
, "Failed to get display mode.\n");
3750 ok(devmode
.dmPelsWidth
== user32_width
&& devmode
.dmPelsHeight
== user32_height
,
3751 "Expected resolution %ux%u, got %ux%u.\n",
3752 user32_width
, user32_height
, devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
3754 GetWindowRect(device_window
, &r
);
3755 ok(EqualRect(&r
, &d3d_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3756 d3d_rect
.left
, d3d_rect
.top
, d3d_rect
.right
, d3d_rect
.bottom
,
3757 r
.left
, r
.top
, r
.right
, r
.bottom
);
3758 GetWindowRect(focus_window
, &r
);
3759 ok(EqualRect(&r
, &focus_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3760 focus_rect
.left
, focus_rect
.top
, focus_rect
.right
, focus_rect
.bottom
,
3761 r
.left
, r
.top
, r
.right
, r
.bottom
);
3763 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
3764 ok(SUCCEEDED(hr
), "Failed to get backbuffer, hr %#x.\n", hr
);
3765 hr
= IDirect3DSurface8_GetDesc(backbuffer
, &desc
);
3766 ok(SUCCEEDED(hr
), "Failed to get backbuffer desc, hr %#x.\n", hr
);
3767 ok(desc
.Width
== d3d_width
, "Got unexpected backbuffer width %u, expected %u.\n",
3768 desc
.Width
, d3d_width
);
3769 ok(desc
.Height
== d3d_height
, "Got unexpected backbuffer height %u, expected %u.\n",
3770 desc
.Height
, d3d_height
);
3771 IDirect3DSurface8_Release(backbuffer
);
3773 refcount
= IDirect3DDevice8_Release(device
);
3774 ok(!refcount
, "Device has %u references left.\n", refcount
);
3776 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3777 ok(ret
, "Failed to get display mode.\n");
3778 todo_wine
ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
3779 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
3780 "Expected resolution %ux%u, got %ux%u.\n",
3781 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
3783 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
3784 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3786 /* The mode restore also happens when the device was created at the original screen size. */
3788 device_desc
.device_window
= device_window
;
3789 device_desc
.width
= registry_mode
.dmPelsWidth
;
3790 device_desc
.height
= registry_mode
.dmPelsHeight
;
3791 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3792 ok(!!(device
= create_device(d3d8
, focus_window
, &device_desc
)), "Failed to create a D3D device.\n");
3794 devmode
.dmPelsWidth
= user32_width
;
3795 devmode
.dmPelsHeight
= user32_height
;
3796 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
3797 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3799 refcount
= IDirect3DDevice8_Release(device
);
3800 ok(!refcount
, "Device has %u references left.\n", refcount
);
3802 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3803 ok(ret
, "Failed to get display mode.\n");
3804 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
3805 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
3806 "Expected resolution %ux%u, got %ux%u.\n",
3807 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
3810 DestroyWindow(device_window
);
3811 DestroyWindow(focus_window
);
3812 IDirect3D8_Release(d3d8
);
3815 static void test_device_window_reset(void)
3817 RECT fullscreen_rect
, device_rect
, r
;
3818 struct device_desc device_desc
;
3819 IDirect3DDevice8
*device
;
3826 wc
.lpfnWndProc
= test_proc
;
3827 wc
.lpszClassName
= "d3d8_test_wndproc_wc";
3828 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
3830 focus_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3831 0, 0, registry_mode
.dmPelsWidth
/ 2, registry_mode
.dmPelsHeight
/ 2, 0, 0, 0, 0);
3832 device_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3833 0, 0, registry_mode
.dmPelsWidth
/ 2, registry_mode
.dmPelsHeight
/ 2, 0, 0, 0, 0);
3834 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3835 ok(!!d3d8
, "Failed to create a D3D object.\n");
3837 SetRect(&fullscreen_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
3838 GetWindowRect(device_window
, &device_rect
);
3840 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3841 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3842 (LONG_PTR
)test_proc
, proc
);
3843 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3844 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3845 (LONG_PTR
)test_proc
, proc
);
3847 device_desc
.device_window
= NULL
;
3848 device_desc
.width
= registry_mode
.dmPelsWidth
;
3849 device_desc
.height
= registry_mode
.dmPelsHeight
;
3850 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3851 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
3853 skip("Failed to create a D3D device, skipping tests.\n");
3857 GetWindowRect(focus_window
, &r
);
3858 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3859 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
3860 r
.left
, r
.top
, r
.right
, r
.bottom
);
3861 GetWindowRect(device_window
, &r
);
3862 ok(EqualRect(&r
, &device_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3863 device_rect
.left
, device_rect
.top
, device_rect
.right
, device_rect
.bottom
,
3864 r
.left
, r
.top
, r
.right
, r
.bottom
);
3866 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3867 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3868 (LONG_PTR
)test_proc
, proc
);
3869 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3870 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
3872 device_desc
.device_window
= device_window
;
3873 hr
= reset_device(device
, &device_desc
);
3874 ok(SUCCEEDED(hr
), "Failed to reset device.\n");
3876 GetWindowRect(focus_window
, &r
);
3877 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3878 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
3879 r
.left
, r
.top
, r
.right
, r
.bottom
);
3880 GetWindowRect(device_window
, &r
);
3881 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3882 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
3883 r
.left
, r
.top
, r
.right
, r
.bottom
);
3885 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3886 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3887 (LONG_PTR
)test_proc
, proc
);
3888 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3889 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
3891 ref
= IDirect3DDevice8_Release(device
);
3892 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
3895 IDirect3D8_Release(d3d8
);
3896 DestroyWindow(device_window
);
3897 DestroyWindow(focus_window
);
3898 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL
));
3901 static void depth_blit_test(void)
3903 IDirect3DDevice8
*device
= NULL
;
3904 IDirect3DSurface8
*backbuffer
, *ds1
, *ds2
, *ds3
;
3906 const POINT dst_point
= {0, 0};
3911 hwnd
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3912 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
3913 ok(!!hwnd
, "Failed to create a window.\n");
3914 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3915 ok(!!d3d8
, "Failed to create a D3D object.\n");
3917 if (!(device
= create_device(d3d8
, hwnd
, NULL
)))
3919 skip("Failed to create a D3D device, skipping tests.\n");
3923 hr
= IDirect3DDevice8_GetRenderTarget(device
, &backbuffer
);
3924 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
3925 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &ds1
);
3926 ok(SUCCEEDED(hr
), "GetDepthStencilSurface failed, hr %#x.\n", hr
);
3927 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 640, 480, D3DFMT_D24S8
, D3DMULTISAMPLE_NONE
, &ds2
);
3928 ok(SUCCEEDED(hr
), "CreateDepthStencilSurface failed, hr %#x.\n", hr
);
3929 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 640, 480, D3DFMT_D24S8
, D3DMULTISAMPLE_NONE
, &ds3
);
3930 ok(SUCCEEDED(hr
), "CreateDepthStencilSurface failed, hr %#x.\n", hr
);
3932 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0, 0.0f
, 0);
3933 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
3936 SetRect(&src_rect
, 0, 0, 320, 240);
3937 hr
= IDirect3DDevice8_CopyRects(device
, ds1
, &src_rect
, 1, ds2
, &dst_point
);
3938 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
3940 SetRect(&src_rect
, 0, 480, 640, 0);
3941 hr
= IDirect3DDevice8_CopyRects(device
, ds1
, &src_rect
, 1, ds2
, &dst_point
);
3942 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
3943 /* Full, explicit. */
3944 SetRect(&src_rect
, 0, 0, 640, 480);
3945 hr
= IDirect3DDevice8_CopyRects(device
, ds1
, &src_rect
, 1, ds2
, &dst_point
);
3946 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
3947 /* Depth -> color blit.*/
3948 hr
= IDirect3DDevice8_CopyRects(device
, ds1
, &src_rect
, 1, backbuffer
, &dst_point
);
3949 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
3950 /* Full, NULL rects, current depth stencil -> unbound depth stencil */
3951 hr
= IDirect3DDevice8_CopyRects(device
, ds1
, NULL
, 0, ds2
, NULL
);
3952 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
3953 /* Full, NULL rects, unbound depth stencil -> current depth stencil */
3954 hr
= IDirect3DDevice8_CopyRects(device
, ds2
, NULL
, 0, ds1
, NULL
);
3955 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
3956 /* Full, NULL rects, unbound depth stencil -> unbound depth stencil */
3957 hr
= IDirect3DDevice8_CopyRects(device
, ds2
, NULL
, 0, ds3
, NULL
);
3958 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
3960 IDirect3DSurface8_Release(backbuffer
);
3961 IDirect3DSurface8_Release(ds3
);
3962 IDirect3DSurface8_Release(ds2
);
3963 IDirect3DSurface8_Release(ds1
);
3966 if (device
) IDirect3DDevice8_Release(device
);
3967 IDirect3D8_Release(d3d8
);
3968 DestroyWindow(hwnd
);
3971 static void test_reset_resources(void)
3973 IDirect3DSurface8
*surface
, *rt
;
3974 IDirect3DTexture8
*texture
;
3975 IDirect3DDevice8
*device
;
3981 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3982 0, 0, 640, 480, 0, 0, 0, 0);
3983 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3984 ok(!!d3d8
, "Failed to create a D3D object.\n");
3986 if (!(device
= create_device(d3d8
, window
, NULL
)))
3988 skip("Failed to create a D3D device, skipping tests.\n");
3992 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 128, 128, D3DFMT_D24S8
,
3993 D3DMULTISAMPLE_NONE
, &surface
);
3994 ok(SUCCEEDED(hr
), "Failed to create depth/stencil surface, hr %#x.\n", hr
);
3996 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
,
3997 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &texture
);
3998 ok(SUCCEEDED(hr
), "Failed to create render target texture, hr %#x.\n", hr
);
3999 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &rt
);
4000 ok(SUCCEEDED(hr
), "Failed to get surface, hr %#x.\n", hr
);
4001 IDirect3DTexture8_Release(texture
);
4003 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, surface
);
4004 ok(SUCCEEDED(hr
), "Failed to set render target surface, hr %#x.\n", hr
);
4005 IDirect3DSurface8_Release(rt
);
4006 IDirect3DSurface8_Release(surface
);
4008 hr
= reset_device(device
, NULL
);
4009 ok(SUCCEEDED(hr
), "Failed to reset device.\n");
4011 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_MONO
, &rt
);
4012 ok(SUCCEEDED(hr
), "Failed to get back buffer, hr %#x.\n", hr
);
4013 hr
= IDirect3DDevice8_GetRenderTarget(device
, &surface
);
4014 ok(SUCCEEDED(hr
), "Failed to get render target surface, hr %#x.\n", hr
);
4015 ok(surface
== rt
, "Got unexpected surface %p for render target.\n", surface
);
4016 IDirect3DSurface8_Release(surface
);
4017 IDirect3DSurface8_Release(rt
);
4019 ref
= IDirect3DDevice8_Release(device
);
4020 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
4023 IDirect3D8_Release(d3d8
);
4024 DestroyWindow(window
);
4027 static void test_set_rt_vp_scissor(void)
4029 IDirect3DDevice8
*device
;
4030 IDirect3DSurface8
*rt
;
4038 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4039 0, 0, 640, 480, 0, 0, 0, 0);
4040 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4041 ok(!!d3d8
, "Failed to create a D3D object.\n");
4042 if (!(device
= create_device(d3d8
, window
, NULL
)))
4044 skip("Failed to create a D3D device, skipping tests.\n");
4045 IDirect3D8_Release(d3d8
);
4046 DestroyWindow(window
);
4050 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 128, 128, D3DFMT_A8R8G8B8
,
4051 D3DMULTISAMPLE_NONE
, FALSE
, &rt
);
4052 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
4054 hr
= IDirect3DDevice8_GetViewport(device
, &vp
);
4055 ok(SUCCEEDED(hr
), "Failed to get viewport, hr %#x.\n", hr
);
4056 ok(!vp
.X
, "Got unexpected vp.X %u.\n", vp
.X
);
4057 ok(!vp
.Y
, "Got unexpected vp.Y %u.\n", vp
.Y
);
4058 ok(vp
.Width
== 640, "Got unexpected vp.Width %u.\n", vp
.Width
);
4059 ok(vp
.Height
== 480, "Got unexpected vp.Height %u.\n", vp
.Height
);
4060 ok(vp
.MinZ
== 0.0f
, "Got unexpected vp.MinZ %.8e.\n", vp
.MinZ
);
4061 ok(vp
.MaxZ
== 1.0f
, "Got unexpected vp.MaxZ %.8e.\n", vp
.MaxZ
);
4063 hr
= IDirect3DDevice8_BeginStateBlock(device
);
4064 ok(SUCCEEDED(hr
), "Failed to begin stateblock, hr %#x.\n", hr
);
4066 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, NULL
);
4067 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
4069 hr
= IDirect3DDevice8_EndStateBlock(device
, &stateblock
);
4070 ok(SUCCEEDED(hr
), "Failed to end stateblock, hr %#x.\n", hr
);
4071 hr
= IDirect3DDevice8_DeleteStateBlock(device
, stateblock
);
4072 ok(SUCCEEDED(hr
), "Failed to delete stateblock, hr %#x.\n", hr
);
4074 hr
= IDirect3DDevice8_GetViewport(device
, &vp
);
4075 ok(SUCCEEDED(hr
), "Failed to get viewport, hr %#x.\n", hr
);
4076 ok(!vp
.X
, "Got unexpected vp.X %u.\n", vp
.X
);
4077 ok(!vp
.Y
, "Got unexpected vp.Y %u.\n", vp
.Y
);
4078 ok(vp
.Width
== 128, "Got unexpected vp.Width %u.\n", vp
.Width
);
4079 ok(vp
.Height
== 128, "Got unexpected vp.Height %u.\n", vp
.Height
);
4080 ok(vp
.MinZ
== 0.0f
, "Got unexpected vp.MinZ %.8e.\n", vp
.MinZ
);
4081 ok(vp
.MaxZ
== 1.0f
, "Got unexpected vp.MaxZ %.8e.\n", vp
.MaxZ
);
4083 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, NULL
);
4084 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
4092 hr
= IDirect3DDevice8_SetViewport(device
, &vp
);
4093 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
4095 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, NULL
);
4096 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
4098 hr
= IDirect3DDevice8_GetViewport(device
, &vp
);
4099 ok(SUCCEEDED(hr
), "Failed to get viewport, hr %#x.\n", hr
);
4100 ok(!vp
.X
, "Got unexpected vp.X %u.\n", vp
.X
);
4101 ok(!vp
.Y
, "Got unexpected vp.Y %u.\n", vp
.Y
);
4102 ok(vp
.Width
== 128, "Got unexpected vp.Width %u.\n", vp
.Width
);
4103 ok(vp
.Height
== 128, "Got unexpected vp.Height %u.\n", vp
.Height
);
4104 ok(vp
.MinZ
== 0.0f
, "Got unexpected vp.MinZ %.8e.\n", vp
.MinZ
);
4105 ok(vp
.MaxZ
== 1.0f
, "Got unexpected vp.MaxZ %.8e.\n", vp
.MaxZ
);
4107 IDirect3DSurface8_Release(rt
);
4108 refcount
= IDirect3DDevice8_Release(device
);
4109 ok(!refcount
, "Device has %u references left.\n", refcount
);
4110 IDirect3D8_Release(d3d8
);
4111 DestroyWindow(window
);
4114 static void test_validate_vs(void)
4118 0xfffe0101, /* vs_1_1 */
4119 0x00000009, 0xc0010000, 0x90e40000, 0xa0e40000, /* dp4 oPos.x, v0, c0 */
4120 0x00000009, 0xc0020000, 0x90e40000, 0xa0e40001, /* dp4 oPos.y, v0, c1 */
4121 0x00000009, 0xc0040000, 0x90e40000, 0xa0e40002, /* dp4 oPos.z, v0, c2 */
4122 0x00000009, 0xc0080000, 0x90e40000, 0xa0e40003, /* dp4 oPos.w, v0, c3 */
4123 0x0000ffff, /* end */
4127 hr
= ValidateVertexShader(0, 0, 0, 0, 0);
4128 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4129 hr
= ValidateVertexShader(0, 0, 0, 1, 0);
4130 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4131 hr
= ValidateVertexShader(vs
, 0, 0, 0, 0);
4132 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4134 hr
= ValidateVertexShader(vs
, 0, 0, 1, 0);
4135 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4136 /* Seems to do some version checking. */
4137 *vs
= 0xfffe0100; /* vs_1_0 */
4138 hr
= ValidateVertexShader(vs
, 0, 0, 0, 0);
4139 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4141 *vs
= 0xfffe0102; /* bogus version */
4142 hr
= ValidateVertexShader(vs
, 0, 0, 1, 0);
4143 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4144 /* I've seen that applications always pass the 2nd and 3rd parameter as 0.
4145 * Simple test with non-zero parameters. */
4146 *vs
= 0xfffe0101; /* vs_1_1 */
4147 hr
= ValidateVertexShader(vs
, vs
, 0, 1, 0);
4148 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4150 hr
= ValidateVertexShader(vs
, 0, vs
, 1, 0);
4151 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4152 /* I've seen the 4th parameter always passed as either 0 or 1, but passing
4153 * other values doesn't seem to hurt. */
4154 hr
= ValidateVertexShader(vs
, 0, 0, 12345, 0);
4155 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4156 /* What is the 5th parameter? The following seems to work ok. */
4157 hr
= ValidateVertexShader(vs
, 0, 0, 1, vs
);
4158 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4161 static void test_validate_ps(void)
4165 0xffff0101, /* ps_1_1 */
4166 0x00000051, 0xa00f0001, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
4167 0x00000042, 0xb00f0000, /* tex t0 */
4168 0x00000008, 0x800f0000, 0xa0e40001, 0xa0e40000, /* dp3 r0, c1, c0 */
4169 0x00000005, 0x800f0000, 0x90e40000, 0x80e40000, /* mul r0, v0, r0 */
4170 0x00000005, 0x800f0000, 0xb0e40000, 0x80e40000, /* mul r0, t0, r0 */
4171 0x0000ffff, /* end */
4175 hr
= ValidatePixelShader(0, 0, 0, 0);
4176 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4177 hr
= ValidatePixelShader(0, 0, 1, 0);
4178 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4179 hr
= ValidatePixelShader(ps
, 0, 0, 0);
4180 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4182 hr
= ValidatePixelShader(ps
, 0, 1, 0);
4183 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4184 /* Seems to do some version checking. */
4185 *ps
= 0xffff0105; /* bogus version */
4186 hr
= ValidatePixelShader(ps
, 0, 1, 0);
4187 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4188 /* I've seen that applications always pass the 2nd parameter as 0.
4189 * Simple test with a non-zero parameter. */
4190 *ps
= 0xffff0101; /* ps_1_1 */
4191 hr
= ValidatePixelShader(ps
, ps
, 1, 0);
4192 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4193 /* I've seen the 3rd parameter always passed as either 0 or 1, but passing
4194 * other values doesn't seem to hurt. */
4195 hr
= ValidatePixelShader(ps
, 0, 12345, 0);
4196 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4197 /* What is the 4th parameter? The following seems to work ok. */
4198 hr
= ValidatePixelShader(ps
, 0, 1, ps
);
4199 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4202 static void test_volume_get_container(void)
4204 IDirect3DVolumeTexture8
*texture
= NULL
;
4205 IDirect3DVolume8
*volume
= NULL
;
4206 IDirect3DDevice8
*device
;
4207 IUnknown
*container
;
4214 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4215 0, 0, 640, 480, 0, 0, 0, 0);
4216 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4217 ok(!!d3d8
, "Failed to create a D3D object.\n");
4218 if (!(device
= create_device(d3d8
, window
, NULL
)))
4220 skip("Failed to create a D3D device, skipping tests.\n");
4221 IDirect3D8_Release(d3d8
);
4222 DestroyWindow(window
);
4226 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
4227 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
4228 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
))
4230 skip("No volume texture support, skipping tests.\n");
4231 IDirect3DDevice8_Release(device
);
4232 IDirect3D8_Release(d3d8
);
4233 DestroyWindow(window
);
4237 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 128, 128, 128, 1, 0,
4238 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &texture
);
4239 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
4240 ok(!!texture
, "Got unexpected texture %p.\n", texture
);
4242 hr
= IDirect3DVolumeTexture8_GetVolumeLevel(texture
, 0, &volume
);
4243 ok(SUCCEEDED(hr
), "Failed to get volume level, hr %#x.\n", hr
);
4244 ok(!!volume
, "Got unexpected volume %p.\n", volume
);
4246 /* These should work... */
4248 hr
= IDirect3DVolume8_GetContainer(volume
, &IID_IUnknown
, (void **)&container
);
4249 ok(SUCCEEDED(hr
), "Failed to get volume container, hr %#x.\n", hr
);
4250 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4251 IUnknown_Release(container
);
4254 hr
= IDirect3DVolume8_GetContainer(volume
, &IID_IDirect3DResource8
, (void **)&container
);
4255 ok(SUCCEEDED(hr
), "Failed to get volume container, hr %#x.\n", hr
);
4256 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4257 IUnknown_Release(container
);
4260 hr
= IDirect3DVolume8_GetContainer(volume
, &IID_IDirect3DBaseTexture8
, (void **)&container
);
4261 ok(SUCCEEDED(hr
), "Failed to get volume container, hr %#x.\n", hr
);
4262 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4263 IUnknown_Release(container
);
4266 hr
= IDirect3DVolume8_GetContainer(volume
, &IID_IDirect3DVolumeTexture8
, (void **)&container
);
4267 ok(SUCCEEDED(hr
), "Failed to get volume container, hr %#x.\n", hr
);
4268 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4269 IUnknown_Release(container
);
4271 /* ...and this one shouldn't. This should return E_NOINTERFACE and set container to NULL. */
4272 hr
= IDirect3DVolume8_GetContainer(volume
, &IID_IDirect3DVolume8
, (void **)&container
);
4273 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
4274 ok(!container
, "Got unexpected container %p.\n", container
);
4276 IDirect3DVolume8_Release(volume
);
4277 IDirect3DVolumeTexture8_Release(texture
);
4278 refcount
= IDirect3DDevice8_Release(device
);
4279 ok(!refcount
, "Device has %u references left.\n", refcount
);
4280 IDirect3D8_Release(d3d8
);
4281 DestroyWindow(window
);
4284 static void test_vb_lock_flags(void)
4289 const char *debug_string
;
4294 {D3DLOCK_READONLY
, "D3DLOCK_READONLY", D3D_OK
},
4295 {D3DLOCK_DISCARD
, "D3DLOCK_DISCARD", D3D_OK
},
4296 {D3DLOCK_NOOVERWRITE
, "D3DLOCK_NOOVERWRITE", D3D_OK
},
4297 {D3DLOCK_NOOVERWRITE
| D3DLOCK_DISCARD
, "D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD", D3D_OK
},
4298 {D3DLOCK_NOOVERWRITE
| D3DLOCK_READONLY
, "D3DLOCK_NOOVERWRITE | D3DLOCK_READONLY", D3D_OK
},
4299 {D3DLOCK_READONLY
| D3DLOCK_DISCARD
, "D3DLOCK_READONLY | D3DLOCK_DISCARD", D3D_OK
},
4300 /* Completely bogus flags aren't an error. */
4301 {0xdeadbeef, "0xdeadbeef", D3D_OK
},
4303 IDirect3DVertexBuffer8
*buffer
;
4304 IDirect3DDevice8
*device
;
4312 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4313 0, 0, 640, 480, 0, 0, 0, 0);
4314 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4315 ok(!!d3d8
, "Failed to create a D3D object.\n");
4316 if (!(device
= create_device(d3d8
, window
, NULL
)))
4318 skip("Failed to create a D3D device, skipping tests.\n");
4319 IDirect3D8_Release(d3d8
);
4320 DestroyWindow(window
);
4324 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, 1024, D3DUSAGE_DYNAMIC
, 0, D3DPOOL_DEFAULT
, &buffer
);
4325 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
4327 for (i
= 0; i
< (sizeof(test_data
) / sizeof(*test_data
)); ++i
)
4329 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, 0, &data
, test_data
[i
].flags
);
4330 ok(hr
== test_data
[i
].result
, "Got unexpected hr %#x for %s.\n",
4331 hr
, test_data
[i
].debug_string
);
4334 ok(!!data
, "Got unexpected data %p.\n", data
);
4335 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
4336 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
4340 IDirect3DVertexBuffer8_Release(buffer
);
4341 refcount
= IDirect3DDevice8_Release(device
);
4342 ok(!refcount
, "Device has %u references left.\n", refcount
);
4343 IDirect3D8_Release(d3d8
);
4344 DestroyWindow(window
);
4347 /* Test the default texture stage state values */
4348 static void test_texture_stage_states(void)
4350 IDirect3DDevice8
*device
;
4359 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4360 0, 0, 640, 480, 0, 0, 0, 0);
4361 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4362 ok(!!d3d8
, "Failed to create a D3D object.\n");
4363 if (!(device
= create_device(d3d8
, window
, NULL
)))
4365 skip("Failed to create a D3D device, skipping tests.\n");
4366 IDirect3D8_Release(d3d8
);
4367 DestroyWindow(window
);
4371 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
4372 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
4374 for (i
= 0; i
< caps
.MaxTextureBlendStages
; ++i
)
4376 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_COLOROP
, &value
);
4377 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4378 ok(value
== (i
? D3DTOP_DISABLE
: D3DTOP_MODULATE
),
4379 "Got unexpected value %#x for D3DTSS_COLOROP, stage %u.\n", value
, i
);
4380 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_COLORARG1
, &value
);
4381 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4382 ok(value
== D3DTA_TEXTURE
, "Got unexpected value %#x for D3DTSS_COLORARG1, stage %u.\n", value
, i
);
4383 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_COLORARG2
, &value
);
4384 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4385 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_COLORARG2, stage %u.\n", value
, i
);
4386 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_ALPHAOP
, &value
);
4387 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4388 ok(value
== (i
? D3DTOP_DISABLE
: D3DTOP_SELECTARG1
),
4389 "Got unexpected value %#x for D3DTSS_ALPHAOP, stage %u.\n", value
, i
);
4390 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_ALPHAARG1
, &value
);
4391 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4392 ok(value
== D3DTA_TEXTURE
, "Got unexpected value %#x for D3DTSS_ALPHAARG1, stage %u.\n", value
, i
);
4393 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_ALPHAARG2
, &value
);
4394 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4395 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_ALPHAARG2, stage %u.\n", value
, i
);
4396 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVMAT00
, &value
);
4397 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4398 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVMAT00, stage %u.\n", value
, i
);
4399 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVMAT01
, &value
);
4400 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4401 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVMAT01, stage %u.\n", value
, i
);
4402 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVMAT10
, &value
);
4403 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4404 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVMAT10, stage %u.\n", value
, i
);
4405 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVMAT11
, &value
);
4406 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4407 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVMAT11, stage %u.\n", value
, i
);
4408 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_TEXCOORDINDEX
, &value
);
4409 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4410 ok(value
== i
, "Got unexpected value %#x for D3DTSS_TEXCOORDINDEX, stage %u.\n", value
, i
);
4411 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVLSCALE
, &value
);
4412 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4413 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVLSCALE, stage %u.\n", value
, i
);
4414 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVLOFFSET
, &value
);
4415 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4416 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVLOFFSET, stage %u.\n", value
, i
);
4417 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_TEXTURETRANSFORMFLAGS
, &value
);
4418 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4419 ok(value
== D3DTTFF_DISABLE
,
4420 "Got unexpected value %#x for D3DTSS_TEXTURETRANSFORMFLAGS, stage %u.\n", value
, i
);
4421 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_COLORARG0
, &value
);
4422 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4423 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_COLORARG0, stage %u.\n", value
, i
);
4424 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_ALPHAARG0
, &value
);
4425 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4426 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_ALPHAARG0, stage %u.\n", value
, i
);
4427 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_RESULTARG
, &value
);
4428 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4429 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_RESULTARG, stage %u.\n", value
, i
);
4432 refcount
= IDirect3DDevice8_Release(device
);
4433 ok(!refcount
, "Device has %u references left.\n", refcount
);
4434 IDirect3D8_Release(d3d8
);
4435 DestroyWindow(window
);
4438 static void test_cube_textures(void)
4440 IDirect3DCubeTexture8
*texture
;
4441 IDirect3DDevice8
*device
;
4448 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4449 0, 0, 640, 480, 0, 0, 0, 0);
4450 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4451 ok(!!d3d8
, "Failed to create a D3D object.\n");
4452 if (!(device
= create_device(d3d8
, window
, NULL
)))
4454 skip("Failed to create a D3D device, skipping tests.\n");
4455 IDirect3D8_Release(d3d8
);
4456 DestroyWindow(window
);
4460 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
4461 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
4463 if (caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
)
4465 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &texture
);
4466 ok(hr
== D3D_OK
, "Failed to create D3DPOOL_DEFAULT cube texture, hr %#x.\n", hr
);
4467 IDirect3DCubeTexture8_Release(texture
);
4468 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &texture
);
4469 ok(hr
== D3D_OK
, "Failed to create D3DPOOL_MANAGED cube texture, hr %#x.\n", hr
);
4470 IDirect3DCubeTexture8_Release(texture
);
4471 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_SYSTEMMEM
, &texture
);
4472 ok(hr
== D3D_OK
, "Failed to create D3DPOOL_SYSTEMMEM cube texture, hr %#x.\n", hr
);
4473 IDirect3DCubeTexture8_Release(texture
);
4477 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &texture
);
4478 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for D3DPOOL_DEFAULT cube texture.\n", hr
);
4479 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &texture
);
4480 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for D3DPOOL_MANAGED cube texture.\n", hr
);
4481 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_SYSTEMMEM
, &texture
);
4482 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for D3DPOOL_SYSTEMMEM cube texture.\n", hr
);
4484 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_SCRATCH
, &texture
);
4485 ok(hr
== D3D_OK
, "Failed to create D3DPOOL_SCRATCH cube texture, hr %#x.\n", hr
);
4486 IDirect3DCubeTexture8_Release(texture
);
4488 refcount
= IDirect3DDevice8_Release(device
);
4489 ok(!refcount
, "Device has %u references left.\n", refcount
);
4490 IDirect3D8_Release(d3d8
);
4491 DestroyWindow(window
);
4494 static void test_get_set_texture(void)
4496 const IDirect3DBaseTexture8Vtbl
*texture_vtbl
;
4497 IDirect3DBaseTexture8
*texture
;
4498 IDirect3DDevice8
*device
;
4504 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4505 0, 0, 640, 480, 0, 0, 0, 0);
4506 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
4507 ok(!!d3d
, "Failed to create a D3D object.\n");
4508 if (!(device
= create_device(d3d
, window
, NULL
)))
4510 skip("Failed to create a D3D device, skipping tests.\n");
4511 IDirect3D8_Release(d3d
);
4512 DestroyWindow(window
);
4516 texture
= (IDirect3DBaseTexture8
*)0xdeadbeef;
4517 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
4518 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4519 hr
= IDirect3DDevice8_GetTexture(device
, 0, &texture
);
4520 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4521 ok(!texture
, "Got unexpected texture %p.\n", texture
);
4523 hr
= IDirect3DDevice8_CreateTexture(device
, 16, 16, 1, 0, D3DFMT_A8R8G8B8
,
4524 D3DPOOL_MANAGED
, (IDirect3DTexture8
**)&texture
);
4525 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
4526 texture_vtbl
= texture
->lpVtbl
;
4527 texture
->lpVtbl
= (IDirect3DBaseTexture8Vtbl
*)0xdeadbeef;
4528 hr
= IDirect3DDevice8_SetTexture(device
, 0, texture
);
4529 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
4530 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
4531 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
4532 texture
->lpVtbl
= NULL
;
4533 hr
= IDirect3DDevice8_SetTexture(device
, 0, texture
);
4534 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
4535 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
4536 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
4537 texture
->lpVtbl
= texture_vtbl
;
4538 IDirect3DBaseTexture8_Release(texture
);
4540 refcount
= IDirect3DDevice8_Release(device
);
4541 ok(!refcount
, "Device has %u references left.\n", refcount
);
4542 IDirect3D8_Release(d3d
);
4543 DestroyWindow(window
);
4546 /* Test the behaviour of the IDirect3DDevice8::CreateImageSurface() method.
4548 * The expected behaviour (as documented in the original DX8 docs) is that the
4549 * call returns a surface in the SYSTEMMEM pool. Games like Max Payne 1 and 2
4550 * depend on this behaviour.
4552 * A short remark in the DX9 docs however states that the pool of the returned
4553 * surface object is D3DPOOL_SCRATCH. This is misinformation and would result
4554 * in screenshots not appearing in the savegame loading menu of both games
4555 * mentioned above (engine tries to display a texture from the scratch pool).
4557 * This test verifies that the behaviour described in the original d3d8 docs
4558 * is the correct one. For more information about this issue, see the MSDN:
4559 * d3d9 docs: "Converting to Direct3D 9"
4560 * d3d9 reference: "IDirect3DDevice9::CreateOffscreenPlainSurface"
4561 * d3d8 reference: "IDirect3DDevice8::CreateImageSurface" */
4562 static void test_image_surface_pool(void)
4564 IDirect3DSurface8
*surface
;
4565 IDirect3DDevice8
*device
;
4566 D3DSURFACE_DESC desc
;
4572 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4573 0, 0, 640, 480, 0, 0, 0, 0);
4574 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4575 ok(!!d3d8
, "Failed to create a D3D object.\n");
4576 if (!(device
= create_device(d3d8
, window
, NULL
)))
4578 skip("Failed to create a D3D device, skipping tests.\n");
4579 IDirect3D8_Release(d3d8
);
4580 DestroyWindow(window
);
4584 hr
= IDirect3DDevice8_CreateImageSurface(device
, 128, 128, D3DFMT_A8R8G8B8
, &surface
);
4585 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4586 hr
= IDirect3DSurface8_GetDesc(surface
, &desc
);
4587 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4588 ok(desc
.Pool
== D3DPOOL_SYSTEMMEM
, "Got unexpected pool %#x.\n", desc
.Pool
);
4589 IDirect3DSurface8_Release(surface
);
4591 refcount
= IDirect3DDevice8_Release(device
);
4592 ok(!refcount
, "Device has %u references left.\n", refcount
);
4593 IDirect3D8_Release(d3d8
);
4594 DestroyWindow(window
);
4597 static void test_surface_get_container(void)
4599 IDirect3DTexture8
*texture
= NULL
;
4600 IDirect3DSurface8
*surface
= NULL
;
4601 IDirect3DDevice8
*device
;
4602 IUnknown
*container
;
4608 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4609 0, 0, 640, 480, 0, 0, 0, 0);
4610 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4611 ok(!!d3d8
, "Failed to create a D3D object.\n");
4612 if (!(device
= create_device(d3d8
, window
, NULL
)))
4614 skip("Failed to create a D3D device, skipping tests.\n");
4615 IDirect3D8_Release(d3d8
);
4616 DestroyWindow(window
);
4620 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1, 0,
4621 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &texture
);
4622 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
4623 ok(!!texture
, "Got unexpected texture %p.\n", texture
);
4625 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &surface
);
4626 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
4627 ok(!!surface
, "Got unexpected surface %p.\n", surface
);
4629 /* These should work... */
4631 hr
= IDirect3DSurface8_GetContainer(surface
, &IID_IUnknown
, (void **)&container
);
4632 ok(SUCCEEDED(hr
), "Failed to get surface container, hr %#x.\n", hr
);
4633 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4634 IUnknown_Release(container
);
4637 hr
= IDirect3DSurface8_GetContainer(surface
, &IID_IDirect3DResource8
, (void **)&container
);
4638 ok(SUCCEEDED(hr
), "Failed to get surface container, hr %#x.\n", hr
);
4639 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4640 IUnknown_Release(container
);
4643 hr
= IDirect3DSurface8_GetContainer(surface
, &IID_IDirect3DBaseTexture8
, (void **)&container
);
4644 ok(SUCCEEDED(hr
), "Failed to get surface container, hr %#x.\n", hr
);
4645 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4646 IUnknown_Release(container
);
4649 hr
= IDirect3DSurface8_GetContainer(surface
, &IID_IDirect3DTexture8
, (void **)&container
);
4650 ok(SUCCEEDED(hr
), "Failed to get surface container, hr %#x.\n", hr
);
4651 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4652 IUnknown_Release(container
);
4654 /* ...and this one shouldn't. This should return E_NOINTERFACE and set container to NULL. */
4655 hr
= IDirect3DSurface8_GetContainer(surface
, &IID_IDirect3DSurface8
, (void **)&container
);
4656 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
4657 ok(!container
, "Got unexpected container %p.\n", container
);
4659 IDirect3DSurface8_Release(surface
);
4660 IDirect3DTexture8_Release(texture
);
4661 refcount
= IDirect3DDevice8_Release(device
);
4662 ok(!refcount
, "Device has %u references left.\n", refcount
);
4663 IDirect3D8_Release(d3d8
);
4664 DestroyWindow(window
);
4667 static void test_lockrect_invalid(void)
4669 static const RECT valid
[] =
4675 static const RECT invalid
[] =
4677 {60, 60, 60, 68}, /* 0 height */
4678 {60, 60, 68, 60}, /* 0 width */
4679 {68, 60, 60, 68}, /* left > right */
4680 {60, 68, 68, 60}, /* top > bottom */
4681 {-8, 60, 0, 68}, /* left < surface */
4682 {60, -8, 68, 0}, /* top < surface */
4683 {-16, 60, -8, 68}, /* right < surface */
4684 {60, -16, 68, -8}, /* bottom < surface */
4685 {60, 60, 136, 68}, /* right > surface */
4686 {60, 60, 68, 136}, /* bottom > surface */
4687 {136, 60, 144, 68}, /* left > surface */
4688 {60, 136, 68, 144}, /* top > surface */
4690 IDirect3DSurface8
*surface
;
4691 IDirect3DTexture8
*texture
;
4692 IDirect3DCubeTexture8
*cube_texture
;
4693 D3DLOCKED_RECT locked_rect
;
4694 IDirect3DDevice8
*device
;
4701 unsigned int offset
, expected_offset
;
4704 D3DRESOURCETYPE type
;
4707 BOOL validate
, clear
;
4711 {D3DRTYPE_SURFACE
, D3DPOOL_SCRATCH
, "scratch surface", TRUE
, TRUE
},
4712 {D3DRTYPE_TEXTURE
, D3DPOOL_MANAGED
, "managed texture", FALSE
, FALSE
},
4713 {D3DRTYPE_TEXTURE
, D3DPOOL_SYSTEMMEM
, "sysmem texture", FALSE
, FALSE
},
4714 {D3DRTYPE_TEXTURE
, D3DPOOL_SCRATCH
, "scratch texture", FALSE
, FALSE
},
4715 {D3DRTYPE_CUBETEXTURE
, D3DPOOL_MANAGED
, "default cube texture", TRUE
, TRUE
},
4716 {D3DRTYPE_CUBETEXTURE
, D3DPOOL_SYSTEMMEM
, "sysmem cube texture", TRUE
, TRUE
},
4717 {D3DRTYPE_CUBETEXTURE
, D3DPOOL_SCRATCH
, "scratch cube texture", TRUE
, TRUE
},
4720 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4721 0, 0, 640, 480, 0, 0, 0, 0);
4722 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4723 ok(!!d3d8
, "Failed to create a D3D object.\n");
4724 if (!(device
= create_device(d3d8
, window
, NULL
)))
4726 skip("Failed to create a D3D device, skipping tests.\n");
4727 IDirect3D8_Release(d3d8
);
4728 DestroyWindow(window
);
4732 for (r
= 0; r
< sizeof(resources
) / sizeof(*resources
); ++r
)
4735 cube_texture
= NULL
;
4736 switch (resources
[r
].type
)
4738 case D3DRTYPE_SURFACE
:
4739 hr
= IDirect3DDevice8_CreateImageSurface(device
, 128, 128, D3DFMT_A8R8G8B8
, &surface
);
4740 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4743 case D3DRTYPE_TEXTURE
:
4744 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1, 0, D3DFMT_A8R8G8B8
,
4745 resources
[r
].pool
, &texture
);
4746 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4747 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &surface
);
4748 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4751 case D3DRTYPE_CUBETEXTURE
:
4752 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 128, 1, 0, D3DFMT_A8R8G8B8
,
4753 resources
[r
].pool
, &cube_texture
);
4754 ok(SUCCEEDED(hr
), "Failed to create cube texture, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4755 hr
= IDirect3DCubeTexture8_GetCubeMapSurface(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0, &surface
);
4756 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4762 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
4763 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4764 base
= locked_rect
.pBits
;
4765 hr
= IDirect3DSurface8_UnlockRect(surface
);
4766 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4768 for (i
= 0; i
< (sizeof(valid
) / sizeof(*valid
)); ++i
)
4770 const RECT
*rect
= &valid
[i
];
4772 locked_rect
.pBits
= (BYTE
*)0xdeadbeef;
4773 locked_rect
.Pitch
= 0xdeadbeef;
4775 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, rect
, 0);
4776 ok(SUCCEEDED(hr
), "Failed to lock surface with rect [%d, %d]->[%d, %d], hr %#x, type %s.\n",
4777 rect
->left
, rect
->top
, rect
->right
, rect
->bottom
, hr
, resources
[r
].name
);
4779 offset
= (BYTE
*)locked_rect
.pBits
- base
;
4780 expected_offset
= rect
->top
* locked_rect
.Pitch
+ rect
->left
* 4;
4781 ok(offset
== expected_offset
,
4782 "Got unexpected offset %u (expected %u) for rect [%d, %d]->[%d, %d], type %s.\n",
4783 offset
, expected_offset
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
,
4786 hr
= IDirect3DSurface8_UnlockRect(surface
);
4787 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s\n", hr
, resources
[r
].name
);
4791 hr
= IDirect3DTexture8_LockRect(texture
, 0, &locked_rect
, rect
, 0);
4792 ok(SUCCEEDED(hr
), "Failed to lock surface with rect [%d, %d]->[%d, %d], hr %#x, type %s.\n",
4793 rect
->left
, rect
->top
, rect
->right
, rect
->bottom
, hr
, resources
[r
].name
);
4795 offset
= (BYTE
*)locked_rect
.pBits
- base
;
4796 ok(offset
== expected_offset
,
4797 "Got unexpected offset %u (expected %u) for rect [%d, %d]->[%d, %d], type %s.\n",
4798 offset
, expected_offset
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
,
4801 hr
= IDirect3DTexture8_UnlockRect(texture
, 0);
4802 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4806 hr
= IDirect3DCubeTexture8_LockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0, &locked_rect
, rect
, 0);
4807 ok(SUCCEEDED(hr
), "Failed to lock surface with rect [%d, %d]->[%d, %d], hr %#x, type %s.\n",
4808 rect
->left
, rect
->top
, rect
->right
, rect
->bottom
, hr
, resources
[r
].name
);
4810 offset
= (BYTE
*)locked_rect
.pBits
- base
;
4811 ok(offset
== expected_offset
,
4812 "Got unexpected offset %u (expected %u) for rect [%d, %d]->[%d, %d], type %s.\n",
4813 offset
, expected_offset
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
,
4816 hr
= IDirect3DCubeTexture8_UnlockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0);
4817 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4821 for (i
= 0; i
< (sizeof(invalid
) / sizeof(*invalid
)); ++i
)
4823 const RECT
*rect
= &invalid
[i
];
4825 locked_rect
.pBits
= (void *)0xdeadbeef;
4826 locked_rect
.Pitch
= 1;
4827 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, rect
, 0);
4828 if (resources
[r
].validate
)
4829 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d], type %s.\n",
4830 hr
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
, resources
[r
].name
);
4832 ok(SUCCEEDED(hr
), "Got unexpected hr %#x for rect [%d, %d]->[%d, %d], type %s.\n",
4833 hr
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
, resources
[r
].name
);
4837 offset
= (BYTE
*)locked_rect
.pBits
- base
;
4838 expected_offset
= rect
->top
* locked_rect
.Pitch
+ rect
->left
* 4;
4839 ok(offset
== expected_offset
,
4840 "Got unexpected offset %u (expected %u) for rect [%d, %d]->[%d, %d], type %s.\n",
4841 offset
, expected_offset
, rect
->left
, rect
->top
,
4842 rect
->right
, rect
->bottom
, resources
[r
].name
);
4844 hr
= IDirect3DSurface8_UnlockRect(surface
);
4845 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4849 ok(!locked_rect
.pBits
, "Got unexpected pBits %p, type %s.\n",
4850 locked_rect
.pBits
, resources
[r
].name
);
4851 ok(!locked_rect
.Pitch
, "Got unexpected Pitch %u, type %s.\n",
4852 locked_rect
.Pitch
, resources
[r
].name
);
4856 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
4857 ok(SUCCEEDED(hr
), "Failed to lock surface with rect NULL, hr %#x, type %s.\n",
4858 hr
, resources
[r
].name
);
4859 locked_rect
.pBits
= (void *)0xdeadbeef;
4860 locked_rect
.Pitch
= 1;
4861 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
4862 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
4863 if (resources
[r
].clear
)
4865 ok(!locked_rect
.pBits
, "Got unexpected pBits %p, type %s.\n",
4866 locked_rect
.pBits
, resources
[r
].name
);
4867 ok(!locked_rect
.Pitch
, "Got unexpected Pitch %u, type %s.\n",
4868 locked_rect
.Pitch
, resources
[r
].name
);
4872 ok(locked_rect
.pBits
== (void *)0xdeadbeef, "Got unexpected pBits %p, type %s.\n",
4873 locked_rect
.pBits
, resources
[r
].name
);
4874 ok(locked_rect
.Pitch
== 1, "Got unexpected Pitch %u, type %s.\n",
4875 locked_rect
.Pitch
, resources
[r
].name
);
4877 hr
= IDirect3DSurface8_UnlockRect(surface
);
4878 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4880 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &valid
[0], 0);
4881 ok(hr
== D3D_OK
, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d], type %s.\n",
4882 hr
, valid
[0].left
, valid
[0].top
, valid
[0].right
, valid
[0].bottom
, resources
[r
].name
);
4883 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &valid
[0], 0);
4884 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d], type %s.\n",
4885 hr
, valid
[0].left
, valid
[0].top
, valid
[0].right
, valid
[0].bottom
, resources
[r
].name
);
4886 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &valid
[1], 0);
4887 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d], type %s.\n",
4888 hr
, valid
[1].left
, valid
[1].top
, valid
[1].right
, valid
[1].bottom
, resources
[r
].name
);
4889 hr
= IDirect3DSurface8_UnlockRect(surface
);
4890 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4892 IDirect3DSurface8_Release(surface
);
4895 hr
= IDirect3DTexture8_LockRect(texture
, 0, &locked_rect
, NULL
, 0);
4896 ok(SUCCEEDED(hr
), "Failed to lock texture with rect NULL, hr %#x, type %s.\n",
4897 hr
, resources
[r
].name
);
4898 locked_rect
.pBits
= (void *)0xdeadbeef;
4899 locked_rect
.Pitch
= 1;
4900 hr
= IDirect3DTexture8_LockRect(texture
, 0, &locked_rect
, NULL
, 0);
4901 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
4902 ok(locked_rect
.pBits
== (void *)0xdeadbeef, "Got unexpected pBits %p, type %s.\n",
4903 locked_rect
.pBits
, resources
[r
].name
);
4904 ok(locked_rect
.Pitch
== 1, "Got unexpected Pitch %u, type %s.\n",
4905 locked_rect
.Pitch
, resources
[r
].name
);
4906 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
4907 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
4908 hr
= IDirect3DTexture8_UnlockRect(texture
, 0);
4909 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4911 hr
= IDirect3DTexture8_LockRect(texture
, 0, &locked_rect
, &valid
[0], 0);
4912 ok(hr
== D3D_OK
, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d], type %s.\n",
4913 hr
, valid
[0].left
, valid
[0].top
, valid
[0].right
, valid
[0].bottom
, resources
[r
].name
);
4914 hr
= IDirect3DTexture8_LockRect(texture
, 0, &locked_rect
, &valid
[0], 0);
4915 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d], type %s.\n",
4916 hr
, valid
[0].left
, valid
[0].top
, valid
[0].right
, valid
[0].bottom
, resources
[r
].name
);
4917 hr
= IDirect3DTexture8_LockRect(texture
, 0, &locked_rect
, &valid
[1], 0);
4918 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d], type %s.\n",
4919 hr
, valid
[1].left
, valid
[1].top
, valid
[1].right
, valid
[1].bottom
, resources
[r
].name
);
4920 hr
= IDirect3DTexture8_UnlockRect(texture
, 0);
4921 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4923 IDirect3DTexture8_Release(texture
);
4928 hr
= IDirect3DCubeTexture8_LockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0,
4929 &locked_rect
, NULL
, 0);
4930 ok(SUCCEEDED(hr
), "Failed to lock texture with rect NULL, hr %#x, type %s.\n",
4931 hr
, resources
[r
].name
);
4932 locked_rect
.pBits
= (void *)0xdeadbeef;
4933 locked_rect
.Pitch
= 1;
4934 hr
= IDirect3DCubeTexture8_LockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0,
4935 &locked_rect
, NULL
, 0);
4936 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
4937 ok(!locked_rect
.pBits
, "Got unexpected pBits %p, type %s.\n",
4938 locked_rect
.pBits
, resources
[r
].name
);
4939 ok(!locked_rect
.Pitch
, "Got unexpected Pitch %u, type %s.\n",
4940 locked_rect
.Pitch
, resources
[r
].name
);
4941 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
4942 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
4943 hr
= IDirect3DCubeTexture8_UnlockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0);
4944 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4946 hr
= IDirect3DCubeTexture8_LockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0,
4947 &locked_rect
, &valid
[0], 0);
4948 ok(hr
== D3D_OK
, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d], type %s.\n",
4949 hr
, valid
[0].left
, valid
[0].top
, valid
[0].right
, valid
[0].bottom
, resources
[r
].name
);
4950 hr
= IDirect3DCubeTexture8_LockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0,
4951 &locked_rect
, &valid
[0], 0);
4952 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d], type %s.\n",
4953 hr
, valid
[0].left
, valid
[0].top
, valid
[0].right
, valid
[0].bottom
, resources
[r
].name
);
4954 hr
= IDirect3DCubeTexture8_LockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0,
4955 &locked_rect
, &valid
[1], 0);
4956 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d], type %s.\n",
4957 hr
, valid
[1].left
, valid
[1].top
, valid
[1].right
, valid
[1].bottom
, resources
[r
].name
);
4958 hr
= IDirect3DCubeTexture8_UnlockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0);
4959 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4961 IDirect3DTexture8_Release(cube_texture
);
4965 refcount
= IDirect3DDevice8_Release(device
);
4966 ok(!refcount
, "Device has %u references left.\n", refcount
);
4967 IDirect3D8_Release(d3d8
);
4968 DestroyWindow(window
);
4971 static void test_private_data(void)
4973 ULONG refcount
, expected_refcount
;
4974 IDirect3DTexture8
*texture
;
4975 IDirect3DSurface8
*surface
, *surface2
;
4976 IDirect3DDevice8
*device
;
4982 DWORD data
[4] = {1, 2, 3, 4};
4983 static const GUID d3d8_private_data_test_guid2
=
4988 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
4991 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4992 0, 0, 640, 480, 0, 0, 0, 0);
4993 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4994 ok(!!d3d8
, "Failed to create a D3D object.\n");
4995 if (!(device
= create_device(d3d8
, window
, NULL
)))
4997 skip("Failed to create a D3D device, skipping tests.\n");
4998 IDirect3D8_Release(d3d8
);
4999 DestroyWindow(window
);
5003 hr
= IDirect3DDevice8_CreateImageSurface(device
, 4, 4, D3DFMT_A8R8G8B8
, &surface
);
5004 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5006 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
5007 device
, 0, D3DSPD_IUNKNOWN
);
5008 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5009 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
5010 device
, 5, D3DSPD_IUNKNOWN
);
5011 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5012 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
5013 device
, sizeof(IUnknown
*) * 2, D3DSPD_IUNKNOWN
);
5014 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5016 /* A failing SetPrivateData call does not clear the old data with the same tag. */
5017 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
, device
,
5018 sizeof(device
), D3DSPD_IUNKNOWN
);
5019 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
5020 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
, device
,
5021 sizeof(device
) * 2, D3DSPD_IUNKNOWN
);
5022 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5024 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, &ptr
, &size
);
5025 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
5026 IUnknown_Release(ptr
);
5027 hr
= IDirect3DSurface8_FreePrivateData(surface
, &d3d8_private_data_test_guid
);
5028 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
5030 refcount
= get_refcount((IUnknown
*)device
);
5031 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
5032 device
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
5033 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5034 expected_refcount
= refcount
+ 1;
5035 refcount
= get_refcount((IUnknown
*)device
);
5036 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5037 hr
= IDirect3DSurface8_FreePrivateData(surface
, &d3d8_private_data_test_guid
);
5038 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5039 expected_refcount
= refcount
- 1;
5040 refcount
= get_refcount((IUnknown
*)device
);
5041 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5043 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
5044 device
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
5045 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5046 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
5047 surface
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
5048 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5049 refcount
= get_refcount((IUnknown
*)device
);
5050 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5052 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
5053 device
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
5054 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5055 size
= 2 * sizeof(ptr
);
5056 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, &ptr
, &size
);
5057 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5058 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
5059 expected_refcount
= refcount
+ 2;
5060 refcount
= get_refcount((IUnknown
*)device
);
5061 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5062 ok(ptr
== (IUnknown
*)device
, "Got unexpected ptr %p, expected %p.\n", ptr
, device
);
5063 IUnknown_Release(ptr
);
5064 expected_refcount
--;
5066 ptr
= (IUnknown
*)0xdeadbeef;
5068 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, NULL
, &size
);
5069 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5070 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
5071 size
= 2 * sizeof(ptr
);
5072 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, NULL
, &size
);
5073 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5074 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
5075 refcount
= get_refcount((IUnknown
*)device
);
5076 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5078 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, &ptr
, &size
);
5079 ok(hr
== D3DERR_MOREDATA
, "Got unexpected hr %#x.\n", hr
);
5080 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
5081 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
5082 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid2
, NULL
, NULL
);
5083 ok(hr
== D3DERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5085 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid2
, &ptr
, &size
);
5086 ok(hr
== D3DERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5087 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
5088 ok(size
== 0xdeadbabe, "Got unexpected size %u.\n", size
);
5089 /* GetPrivateData with size = NULL causes an access violation on Windows if the
5090 * requested data exists. */
5092 /* Destroying the surface frees the held reference. */
5093 IDirect3DSurface8_Release(surface
);
5094 expected_refcount
= refcount
- 2;
5095 refcount
= get_refcount((IUnknown
*)device
);
5096 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5098 hr
= IDirect3DDevice8_CreateTexture(device
, 4, 4, 2, 0, D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &texture
);
5099 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
5100 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &surface
);
5101 ok(SUCCEEDED(hr
), "Failed to get texture level 0, hr %#x.\n", hr
);
5102 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 1, &surface2
);
5103 ok(SUCCEEDED(hr
), "Failed to get texture level 1, hr %#x.\n", hr
);
5105 hr
= IDirect3DTexture8_SetPrivateData(texture
, &d3d8_private_data_test_guid
, data
, sizeof(data
), 0);
5106 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
5108 memset(data
, 0, sizeof(data
));
5109 size
= sizeof(data
);
5110 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, data
, &size
);
5111 ok(hr
== D3DERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5112 hr
= IDirect3DTexture8_GetPrivateData(texture
, &d3d8_private_data_test_guid
, data
, &size
);
5113 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
5114 ok(data
[0] == 1 && data
[1] == 2 && data
[2] == 3 && data
[3] == 4,
5115 "Got unexpected private data: %u, %u, %u, %u.\n", data
[0], data
[1], data
[2], data
[3]);
5117 hr
= IDirect3DTexture8_FreePrivateData(texture
, &d3d8_private_data_test_guid
);
5118 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
5120 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
, data
, sizeof(data
), 0);
5121 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
5122 hr
= IDirect3DSurface8_GetPrivateData(surface2
, &d3d8_private_data_test_guid
, data
, &size
);
5123 ok(hr
== D3DERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5124 hr
= IDirect3DSurface8_FreePrivateData(surface
, &d3d8_private_data_test_guid
);
5125 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
5127 IDirect3DSurface8_Release(surface2
);
5128 IDirect3DSurface8_Release(surface
);
5129 IDirect3DTexture8_Release(texture
);
5131 refcount
= IDirect3DDevice8_Release(device
);
5132 ok(!refcount
, "Device has %u references left.\n", refcount
);
5133 IDirect3D8_Release(d3d8
);
5134 DestroyWindow(window
);
5137 static void test_surface_dimensions(void)
5139 IDirect3DSurface8
*surface
;
5140 IDirect3DDevice8
*device
;
5146 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
5147 0, 0, 640, 480, 0, 0, 0, 0);
5148 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
5149 ok(!!d3d8
, "Failed to create a D3D object.\n");
5150 if (!(device
= create_device(d3d8
, window
, NULL
)))
5152 skip("Failed to create a D3D device, skipping tests.\n");
5153 IDirect3D8_Release(d3d8
);
5154 DestroyWindow(window
);
5158 hr
= IDirect3DDevice8_CreateImageSurface(device
, 0, 1, D3DFMT_A8R8G8B8
, &surface
);
5159 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5160 hr
= IDirect3DDevice8_CreateImageSurface(device
, 1, 0, D3DFMT_A8R8G8B8
, &surface
);
5161 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5163 refcount
= IDirect3DDevice8_Release(device
);
5164 ok(!refcount
, "Device has %u references left.\n", refcount
);
5165 IDirect3D8_Release(d3d8
);
5166 DestroyWindow(window
);
5169 static void test_surface_format_null(void)
5171 static const D3DFORMAT D3DFMT_NULL
= MAKEFOURCC('N','U','L','L');
5172 IDirect3DTexture8
*texture
;
5173 IDirect3DSurface8
*surface
;
5174 IDirect3DSurface8
*rt
, *ds
;
5175 D3DLOCKED_RECT locked_rect
;
5176 IDirect3DDevice8
*device
;
5177 D3DSURFACE_DESC desc
;
5183 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
5184 ok(!!d3d
, "Failed to create a D3D object.\n");
5186 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5187 D3DUSAGE_RENDERTARGET
, D3DRTYPE_SURFACE
, D3DFMT_NULL
);
5190 skip("No D3DFMT_NULL support, skipping test.\n");
5191 IDirect3D8_Release(d3d
);
5195 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
5196 0, 0, 640, 480, 0, 0, 0, 0);
5197 if (!(device
= create_device(d3d
, window
, NULL
)))
5199 skip("Failed to create a D3D device, skipping tests.\n");
5200 IDirect3D8_Release(d3d
);
5201 DestroyWindow(window
);
5205 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5206 D3DUSAGE_RENDERTARGET
, D3DRTYPE_TEXTURE
, D3DFMT_NULL
);
5207 ok(hr
== D3D_OK
, "D3DFMT_NULL should be supported for render target textures, hr %#x.\n", hr
);
5209 hr
= IDirect3D8_CheckDepthStencilMatch(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5210 D3DFMT_NULL
, D3DFMT_D24S8
);
5211 ok(SUCCEEDED(hr
), "Depth stencil match failed for D3DFMT_NULL, hr %#x.\n", hr
);
5213 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 128, 128, D3DFMT_NULL
,
5214 D3DMULTISAMPLE_NONE
, TRUE
, &surface
);
5215 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
5217 hr
= IDirect3DDevice8_GetRenderTarget(device
, &rt
);
5218 ok(SUCCEEDED(hr
), "Failed to get original render target, hr %#x.\n", hr
);
5220 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &ds
);
5221 ok(SUCCEEDED(hr
), "Failed to get original depth/stencil, hr %#x.\n", hr
);
5223 hr
= IDirect3DDevice8_SetRenderTarget(device
, surface
, NULL
);
5224 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
5226 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00000000, 0.0f
, 0);
5227 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
5229 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, ds
);
5230 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
5232 IDirect3DSurface8_Release(rt
);
5233 IDirect3DSurface8_Release(ds
);
5235 hr
= IDirect3DSurface8_GetDesc(surface
, &desc
);
5236 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5237 ok(desc
.Width
== 128, "Expected width 128, got %u.\n", desc
.Width
);
5238 ok(desc
.Height
== 128, "Expected height 128, got %u.\n", desc
.Height
);
5240 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
5241 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5242 ok(locked_rect
.Pitch
, "Expected non-zero pitch, got %u.\n", locked_rect
.Pitch
);
5243 ok(!!locked_rect
.pBits
, "Expected non-NULL pBits, got %p.\n", locked_rect
.pBits
);
5245 hr
= IDirect3DSurface8_UnlockRect(surface
);
5246 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5248 IDirect3DSurface8_Release(surface
);
5250 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 0, D3DUSAGE_RENDERTARGET
,
5251 D3DFMT_NULL
, D3DPOOL_DEFAULT
, &texture
);
5252 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
5253 IDirect3DTexture8_Release(texture
);
5255 refcount
= IDirect3DDevice8_Release(device
);
5256 ok(!refcount
, "Device has %u references left.\n", refcount
);
5257 IDirect3D8_Release(d3d
);
5258 DestroyWindow(window
);
5261 static void test_surface_double_unlock(void)
5263 static const D3DPOOL pools
[] =
5268 IDirect3DSurface8
*surface
;
5269 IDirect3DDevice8
*device
;
5277 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
5278 0, 0, 640, 480, 0, 0, 0, 0);
5279 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
5280 ok(!!d3d
, "Failed to create a D3D object.\n");
5281 if (!(device
= create_device(d3d
, window
, NULL
)))
5283 skip("Failed to create a D3D device, skipping tests.\n");
5284 IDirect3D8_Release(d3d
);
5285 DestroyWindow(window
);
5289 for (i
= 0; i
< (sizeof(pools
) / sizeof(*pools
)); ++i
)
5293 case D3DPOOL_DEFAULT
:
5294 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5295 D3DUSAGE_RENDERTARGET
, D3DRTYPE_SURFACE
, D3DFMT_X8R8G8B8
);
5298 skip("D3DFMT_X8R8G8B8 render targets not supported, skipping double unlock DEFAULT pool test.\n");
5302 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 64, 64, D3DFMT_X8R8G8B8
,
5303 D3DMULTISAMPLE_NONE
, TRUE
, &surface
);
5304 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
5307 case D3DPOOL_SYSTEMMEM
:
5308 hr
= IDirect3DDevice8_CreateImageSurface(device
, 64, 64, D3DFMT_X8R8G8B8
, &surface
);
5309 ok(SUCCEEDED(hr
), "Failed to create image surface, hr %#x.\n", hr
);
5316 hr
= IDirect3DSurface8_UnlockRect(surface
);
5317 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, for surface in pool %#x.\n", hr
, pools
[i
]);
5318 hr
= IDirect3DSurface8_LockRect(surface
, &lr
, NULL
, 0);
5319 ok(SUCCEEDED(hr
), "Failed to lock surface in pool %#x, hr %#x.\n", pools
[i
], hr
);
5320 hr
= IDirect3DSurface8_UnlockRect(surface
);
5321 ok(SUCCEEDED(hr
), "Failed to unlock surface in pool %#x, hr %#x.\n", pools
[i
], hr
);
5322 hr
= IDirect3DSurface8_UnlockRect(surface
);
5323 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, for surface in pool %#x.\n", hr
, pools
[i
]);
5325 IDirect3DSurface8_Release(surface
);
5328 refcount
= IDirect3DDevice8_Release(device
);
5329 ok(!refcount
, "Device has %u references left.\n", refcount
);
5330 IDirect3D8_Release(d3d
);
5331 DestroyWindow(window
);
5334 static void test_surface_blocks(void)
5340 unsigned int block_width
;
5341 unsigned int block_height
;
5343 BOOL create_size_checked
, core_fmt
;
5347 {D3DFMT_DXT1
, "D3DFMT_DXT1", 4, 4, FALSE
, TRUE
, TRUE
},
5348 {D3DFMT_DXT2
, "D3DFMT_DXT2", 4, 4, FALSE
, TRUE
, TRUE
},
5349 {D3DFMT_DXT3
, "D3DFMT_DXT3", 4, 4, FALSE
, TRUE
, TRUE
},
5350 {D3DFMT_DXT4
, "D3DFMT_DXT4", 4, 4, FALSE
, TRUE
, TRUE
},
5351 {D3DFMT_DXT5
, "D3DFMT_DXT5", 4, 4, FALSE
, TRUE
, TRUE
},
5352 /* ATI1N and ATI2N have 2x2 blocks on all AMD cards and Geforce 7 cards,
5353 * which doesn't match the format spec. On newer Nvidia cards
5354 * they have the correct 4x4 block size */
5355 {MAKEFOURCC('A','T','I','1'), "ATI1N", 4, 4, TRUE
, FALSE
, FALSE
},
5356 {MAKEFOURCC('A','T','I','2'), "ATI2N", 4, 4, TRUE
, FALSE
, FALSE
},
5357 /* Windows drivers generally enforce block-aligned locks for
5358 * YUY2 and UYVY. The notable exception is the AMD r500 driver
5359 * in d3d8. The same driver checks the sizes in d3d9. */
5360 {D3DFMT_YUY2
, "D3DFMT_YUY2", 2, 1, TRUE
, FALSE
, TRUE
},
5361 {D3DFMT_UYVY
, "D3DFMT_UYVY", 2, 1, TRUE
, FALSE
, TRUE
},
5367 /* Don't check the return value, Nvidia returns D3DERR_INVALIDCALL for some formats
5368 * and E_INVALIDARG/DDERR_INVALIDPARAMS for others. */
5373 {D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", FALSE
},
5374 {D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", TRUE
},
5375 {D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM",TRUE
},
5376 {D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
},
5380 D3DRESOURCETYPE rtype
;
5381 const char *type_name
;
5383 const char *pool_name
;
5384 BOOL need_driver_support
, need_runtime_support
;
5388 /* D3d8 only supports sysmem surfaces, which are created via CreateImageSurface. Other tests confirm
5389 * that they are D3DPOOL_SYSTEMMEM surfaces, but their creation restriction behaves like the scratch
5391 {D3DRTYPE_SURFACE
, "D3DRTYPE_SURFACE", D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", FALSE
, TRUE
},
5393 {D3DRTYPE_TEXTURE
, "D3DRTYPE_TEXTURE", D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", TRUE
, FALSE
},
5394 {D3DRTYPE_TEXTURE
, "D3DRTYPE_TEXTURE", D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", TRUE
, FALSE
},
5395 {D3DRTYPE_TEXTURE
, "D3DRTYPE_TEXTURE", D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
, FALSE
},
5396 {D3DRTYPE_TEXTURE
, "D3DRTYPE_TEXTURE", D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", FALSE
, TRUE
},
5398 {D3DRTYPE_CUBETEXTURE
, "D3DRTYPE_CUBETEXTURE", D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", TRUE
, FALSE
},
5399 {D3DRTYPE_CUBETEXTURE
, "D3DRTYPE_CUBETEXTURE", D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", TRUE
, FALSE
},
5400 {D3DRTYPE_CUBETEXTURE
, "D3DRTYPE_CUBETEXTURE", D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
, FALSE
},
5401 {D3DRTYPE_CUBETEXTURE
, "D3DRTYPE_CUBETEXTURE", D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", FALSE
, TRUE
},
5403 IDirect3DTexture8
*texture
;
5404 IDirect3DCubeTexture8
*cube_texture
;
5405 IDirect3DSurface8
*surface
;
5406 D3DLOCKED_RECT locked_rect
;
5407 IDirect3DDevice8
*device
;
5408 unsigned int i
, j
, k
, w
, h
;
5414 BOOL tex_pow2
, cube_pow2
;
5416 static const RECT invalid
[] =
5418 {60, 60, 60, 68}, /* 0 height */
5419 {60, 60, 68, 60}, /* 0 width */
5420 {68, 60, 60, 68}, /* left > right */
5421 {60, 68, 68, 60}, /* top > bottom */
5422 {-8, 60, 0, 68}, /* left < surface */
5423 {60, -8, 68, 0}, /* top < surface */
5424 {-16, 60, -8, 68}, /* right < surface */
5425 {60, -16, 68, -8}, /* bottom < surface */
5426 {60, 60, 136, 68}, /* right > surface */
5427 {60, 60, 68, 136}, /* bottom > surface */
5428 {136, 60, 144, 68}, /* left > surface */
5429 {60, 136, 68, 144}, /* top > surface */
5432 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
5433 0, 0, 640, 480, 0, 0, 0, 0);
5434 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
5435 ok(!!d3d
, "Failed to create a D3D object.\n");
5436 if (!(device
= create_device(d3d
, window
, NULL
)))
5438 skip("Failed to create a D3D device, skipping tests.\n");
5439 IDirect3D8_Release(d3d
);
5440 DestroyWindow(window
);
5444 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
5445 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
5446 tex_pow2
= caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
;
5448 tex_pow2
= !(caps
.TextureCaps
& D3DPTEXTURECAPS_NONPOW2CONDITIONAL
);
5449 cube_pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP_POW2
);
5451 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
5453 BOOL tex_support
, cube_support
, surface_support
, format_known
;
5455 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5456 0, D3DRTYPE_TEXTURE
, formats
[i
].fmt
);
5457 tex_support
= SUCCEEDED(hr
);
5458 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5459 0, D3DRTYPE_CUBETEXTURE
, formats
[i
].fmt
);
5460 cube_support
= SUCCEEDED(hr
);
5461 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5462 0, D3DRTYPE_SURFACE
, formats
[i
].fmt
);
5463 surface_support
= SUCCEEDED(hr
);
5465 /* Scratch pool in general allows texture creation even if the driver does
5466 * not support the format. If the format is an extension format that is not
5467 * known to the runtime, like ATI2N, some driver support is required for
5470 * It is also possible that Windows Vista and Windows 7 d3d8 runtimes know
5471 * about ATI2N. I cannot check this because all my Vista+ machines support
5472 * ATI2N in hardware, but none of my WinXP machines do. */
5473 format_known
= tex_support
|| cube_support
|| surface_support
;
5475 for (w
= 1; w
<= 8; w
++)
5477 for (h
= 1; h
<= 8; h
++)
5479 BOOL block_aligned
= TRUE
;
5482 if (w
& (formats
[i
].block_width
- 1) || h
& (formats
[i
].block_height
- 1))
5483 block_aligned
= FALSE
;
5485 size_is_pow2
= !(w
& (w
- 1) || h
& (h
- 1));
5487 for (j
= 0; j
< sizeof(create_tests
) / sizeof(*create_tests
); j
++)
5491 BOOL may_succeed
= FALSE
;
5492 IUnknown
**check_null
;
5494 if (!formats
[i
].core_fmt
)
5496 /* AMD warns against creating ATI2N textures smaller than
5497 * the block size because the runtime cannot calculate the
5498 * correct texture size. Generalize this for all extension
5500 if (w
< formats
[i
].block_width
|| h
< formats
[i
].block_height
)
5504 texture
= (IDirect3DTexture8
*)0xdeadbeef;
5505 cube_texture
= (IDirect3DCubeTexture8
*)0xdeadbeef;
5506 surface
= (IDirect3DSurface8
*)0xdeadbeef;
5508 switch (create_tests
[j
].rtype
)
5510 case D3DRTYPE_TEXTURE
:
5511 check_null
= (IUnknown
**)&texture
;
5512 hr
= IDirect3DDevice8_CreateTexture(device
, w
, h
, 1, 0,
5513 formats
[i
].fmt
, create_tests
[j
].pool
, &texture
);
5514 support
= tex_support
;
5518 case D3DRTYPE_CUBETEXTURE
:
5521 check_null
= (IUnknown
**)&cube_texture
;
5522 hr
= IDirect3DDevice8_CreateCubeTexture(device
, w
, 1, 0,
5523 formats
[i
].fmt
, create_tests
[j
].pool
, &cube_texture
);
5524 support
= cube_support
;
5528 case D3DRTYPE_SURFACE
:
5529 check_null
= (IUnknown
**)&surface
;
5530 hr
= IDirect3DDevice8_CreateImageSurface(device
, w
, h
,
5531 formats
[i
].fmt
, &surface
);
5532 support
= surface_support
;
5543 if (create_tests
[j
].need_driver_support
&& !support
)
5544 expect_hr
= D3DERR_INVALIDCALL
;
5545 else if (create_tests
[j
].need_runtime_support
&& !formats
[i
].core_fmt
&& !format_known
)
5546 expect_hr
= D3DERR_INVALIDCALL
;
5547 else if (formats
[i
].create_size_checked
&& !block_aligned
)
5548 expect_hr
= D3DERR_INVALIDCALL
;
5549 else if (pow2
&& !size_is_pow2
&& create_tests
[j
].need_driver_support
)
5550 expect_hr
= D3DERR_INVALIDCALL
;
5554 if (!formats
[i
].core_fmt
&& !format_known
&& FAILED(expect_hr
))
5557 /* Wine knows about ATI2N and happily creates a scratch resource even if GL
5558 * does not support it. Accept scratch creation of extension formats on
5559 * Windows as well if it occurs. We don't really care if e.g. a Windows 7
5560 * on an r200 GPU creates scratch ATI2N texture even though the card doesn't
5562 ok(hr
== expect_hr
|| ((SUCCEEDED(hr
) && may_succeed
)),
5563 "Got unexpected hr %#x for format %s, pool %s, type %s, size %ux%u.\n",
5564 hr
, formats
[i
].name
, create_tests
[j
].pool_name
, create_tests
[j
].type_name
, w
, h
);
5567 ok(*check_null
== NULL
, "Got object ptr %p, expected NULL.\n", *check_null
);
5569 IUnknown_Release(*check_null
);
5574 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5575 D3DUSAGE_DYNAMIC
, D3DRTYPE_TEXTURE
, formats
[i
].fmt
);
5578 skip("Format %s not supported, skipping lockrect offset tests.\n", formats
[i
].name
);
5582 for (j
= 0; j
< (sizeof(pools
) / sizeof(*pools
)); ++j
)
5584 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1,
5585 pools
[j
].pool
== D3DPOOL_DEFAULT
? D3DUSAGE_DYNAMIC
: 0,
5586 formats
[i
].fmt
, pools
[j
].pool
, &texture
);
5587 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
5588 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &surface
);
5589 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
5590 IDirect3DTexture8_Release(texture
);
5592 if (formats
[i
].block_width
> 1)
5594 SetRect(&rect
, formats
[i
].block_width
>> 1, 0, formats
[i
].block_width
, formats
[i
].block_height
);
5595 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &rect
, 0);
5596 ok(FAILED(hr
) == !pools
[j
].success
|| broken(formats
[i
].broken
),
5597 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5598 SUCCEEDED(hr
) ? "succeeded" : "failed",
5599 pools
[j
].success
? "success" : "failure", formats
[i
].name
, pools
[j
].name
);
5602 hr
= IDirect3DSurface8_UnlockRect(surface
);
5603 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5606 SetRect(&rect
, 0, 0, formats
[i
].block_width
>> 1, formats
[i
].block_height
);
5607 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &rect
, 0);
5608 ok(FAILED(hr
) == !pools
[j
].success
|| broken(formats
[i
].broken
),
5609 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5610 SUCCEEDED(hr
) ? "succeeded" : "failed",
5611 pools
[j
].success
? "success" : "failure", formats
[i
].name
, pools
[j
].name
);
5614 hr
= IDirect3DSurface8_UnlockRect(surface
);
5615 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5619 if (formats
[i
].block_height
> 1)
5621 SetRect(&rect
, 0, formats
[i
].block_height
>> 1, formats
[i
].block_width
, formats
[i
].block_height
);
5622 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &rect
, 0);
5623 ok(FAILED(hr
) == !pools
[j
].success
|| broken(formats
[i
].broken
),
5624 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5625 SUCCEEDED(hr
) ? "succeeded" : "failed",
5626 pools
[j
].success
? "success" : "failure", formats
[i
].name
, pools
[j
].name
);
5629 hr
= IDirect3DSurface8_UnlockRect(surface
);
5630 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5633 SetRect(&rect
, 0, 0, formats
[i
].block_width
, formats
[i
].block_height
>> 1);
5634 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &rect
, 0);
5635 ok(FAILED(hr
) == !pools
[j
].success
|| broken(formats
[i
].broken
),
5636 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5637 SUCCEEDED(hr
) ? "succeeded" : "failed",
5638 pools
[j
].success
? "success" : "failure", formats
[i
].name
, pools
[j
].name
);
5641 hr
= IDirect3DSurface8_UnlockRect(surface
);
5642 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5646 for (k
= 0; k
< sizeof(invalid
) / sizeof(*invalid
); ++k
)
5648 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &invalid
[k
], 0);
5649 ok(FAILED(hr
) == !pools
[j
].success
, "Invalid lock %s(%#x), expected %s, format %s, pool %s, case %u.\n",
5650 SUCCEEDED(hr
) ? "succeeded" : "failed", hr
, pools
[j
].success
? "success" : "failure",
5651 formats
[i
].name
, pools
[j
].name
, k
);
5654 hr
= IDirect3DSurface8_UnlockRect(surface
);
5655 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5659 SetRect(&rect
, 0, 0, formats
[i
].block_width
, formats
[i
].block_height
);
5660 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &rect
, 0);
5661 ok(hr
== D3D_OK
, "Got unexpected hr %#x for format %s, pool %s.\n", hr
, formats
[i
].name
, pools
[j
].name
);
5662 hr
= IDirect3DSurface8_UnlockRect(surface
);
5663 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5665 IDirect3DSurface8_Release(surface
);
5668 if (formats
[i
].block_width
== 1 && formats
[i
].block_height
== 1)
5670 if (!formats
[i
].core_fmt
)
5673 hr
= IDirect3DDevice8_CreateTexture(device
, formats
[i
].block_width
, formats
[i
].block_height
, 2,
5674 D3DUSAGE_DYNAMIC
, formats
[i
].fmt
, D3DPOOL_DEFAULT
, &texture
);
5675 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x, format %s.\n", hr
, formats
[i
].name
);
5677 hr
= IDirect3DTexture8_LockRect(texture
, 1, &locked_rect
, NULL
, 0);
5678 ok(SUCCEEDED(hr
), "Failed lock texture, hr %#x.\n", hr
);
5679 hr
= IDirect3DTexture8_UnlockRect(texture
, 1);
5680 ok(SUCCEEDED(hr
), "Failed lock texture, hr %#x.\n", hr
);
5684 rect
.right
= formats
[i
].block_width
== 1 ? 1 : formats
[i
].block_width
>> 1;
5685 rect
.bottom
= formats
[i
].block_height
== 1 ? 1 : formats
[i
].block_height
>> 1;
5686 hr
= IDirect3DTexture8_LockRect(texture
, 1, &locked_rect
, &rect
, 0);
5687 ok(SUCCEEDED(hr
), "Failed lock texture, hr %#x.\n", hr
);
5688 hr
= IDirect3DTexture8_UnlockRect(texture
, 1);
5689 ok(SUCCEEDED(hr
), "Failed lock texture, hr %#x.\n", hr
);
5691 rect
.right
= formats
[i
].block_width
;
5692 rect
.bottom
= formats
[i
].block_height
;
5693 hr
= IDirect3DTexture8_LockRect(texture
, 1, &locked_rect
, &rect
, 0);
5694 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5696 IDirect3DTexture8_UnlockRect(texture
, 1);
5698 IDirect3DTexture8_Release(texture
);
5701 refcount
= IDirect3DDevice8_Release(device
);
5702 ok(!refcount
, "Device has %u references left.\n", refcount
);
5703 IDirect3D8_Release(d3d
);
5704 DestroyWindow(window
);
5707 static void test_set_palette(void)
5709 IDirect3DDevice8
*device
;
5714 PALETTEENTRY pal
[256];
5718 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
5719 0, 0, 640, 480, 0, 0, 0, 0);
5720 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
5721 ok(!!d3d8
, "Failed to create a D3D object.\n");
5722 if (!(device
= create_device(d3d8
, window
, NULL
)))
5724 skip("Failed to create a D3D device, skipping tests.\n");
5725 IDirect3D8_Release(d3d8
);
5726 DestroyWindow(window
);
5730 for (i
= 0; i
< sizeof(pal
) / sizeof(*pal
); i
++)
5735 pal
[i
].peFlags
= 0xff;
5737 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 0, pal
);
5738 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
5740 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
5741 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
5742 for (i
= 0; i
< sizeof(pal
) / sizeof(*pal
); i
++)
5749 if (caps
.TextureCaps
& D3DPTEXTURECAPS_ALPHAPALETTE
)
5751 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 0, pal
);
5752 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
5756 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 0, pal
);
5757 ok(hr
== D3DERR_INVALIDCALL
, "SetPaletteEntries returned %#x, expected D3DERR_INVALIDCALL.\n", hr
);
5760 refcount
= IDirect3DDevice8_Release(device
);
5761 ok(!refcount
, "Device has %u references left.\n", refcount
);
5762 IDirect3D8_Release(d3d8
);
5763 DestroyWindow(window
);
5766 static void test_swvp_buffer(void)
5768 IDirect3DDevice8
*device
;
5774 IDirect3DVertexBuffer8
*buffer
;
5775 static const unsigned int bufsize
= 1024;
5776 D3DVERTEXBUFFER_DESC desc
;
5777 struct device_desc device_desc
;
5783 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
5784 0, 0, 640, 480, 0, 0, 0, 0);
5785 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
5786 ok(!!d3d8
, "Failed to create a D3D object.\n");
5788 device_desc
.device_window
= window
;
5789 device_desc
.width
= 640;
5790 device_desc
.height
= 480;
5791 device_desc
.flags
= CREATE_DEVICE_SWVP_ONLY
;
5792 if (!(device
= create_device(d3d8
, window
, &device_desc
)))
5794 skip("Failed to create a D3D device, skipping tests.\n");
5795 IDirect3D8_Release(d3d8
);
5796 DestroyWindow(window
);
5800 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, bufsize
* sizeof(*ptr
), D3DUSAGE_DYNAMIC
| D3DUSAGE_WRITEONLY
, 0,
5801 D3DPOOL_DEFAULT
, &buffer
);
5802 ok(SUCCEEDED(hr
), "Failed to create buffer, hr %#x.\n", hr
);
5803 hr
= IDirect3DVertexBuffer8_GetDesc(buffer
, &desc
);
5804 ok(SUCCEEDED(hr
), "Failed to get desc, hr %#x.\n", hr
);
5805 ok(desc
.Pool
== D3DPOOL_DEFAULT
, "Got pool %u, expected D3DPOOL_DEFAULT\n", desc
.Pool
);
5806 ok(desc
.Usage
== (D3DUSAGE_DYNAMIC
| D3DUSAGE_WRITEONLY
),
5807 "Got usage %u, expected D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY\n", desc
.Usage
);
5809 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, bufsize
* sizeof(*ptr
), (BYTE
**)&ptr
, D3DLOCK_DISCARD
);
5810 ok(SUCCEEDED(hr
), "Failed to lock buffer, hr %#x.\n", hr
);
5811 for (i
= 0; i
< bufsize
; i
++)
5813 ptr
[i
].x
= i
* 1.0f
;
5814 ptr
[i
].y
= i
* 2.0f
;
5815 ptr
[i
].z
= i
* 3.0f
;
5817 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
5818 ok(SUCCEEDED(hr
), "Failed to unlock buffer, hr %#x.\n", hr
);
5820 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
);
5821 ok(SUCCEEDED(hr
), "Failed to set fvf, hr %#x.\n", hr
);
5822 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, buffer
, sizeof(*ptr
));
5823 ok(SUCCEEDED(hr
), "Failed to set stream source, hr %#x.\n", hr
);
5824 hr
= IDirect3DDevice8_BeginScene(device
);
5825 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
5826 hr
= IDirect3DDevice8_DrawPrimitive(device
, D3DPT_TRIANGLELIST
, 0, 2);
5827 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
5828 hr
= IDirect3DDevice8_EndScene(device
);
5829 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
5831 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, bufsize
* sizeof(*ptr2
), (BYTE
**)&ptr2
, D3DLOCK_DISCARD
);
5832 ok(SUCCEEDED(hr
), "Failed to lock buffer, hr %#x.\n", hr
);
5833 ok(ptr
== ptr2
, "Lock returned two different pointers: %p, %p\n", ptr
, ptr2
);
5834 for (i
= 0; i
< bufsize
; i
++)
5836 if (ptr2
[i
].x
!= i
* 1.0f
|| ptr2
[i
].y
!= i
* 2.0f
|| ptr2
[i
].z
!= i
* 3.0f
)
5838 ok(FALSE
, "Vertex %u is %f,%f,%f, expected %f,%f,%f\n", i
,
5839 ptr2
[i
].x
, ptr2
[i
].y
, ptr2
[i
].z
, i
* 1.0f
, i
* 2.0f
, i
* 3.0f
);
5843 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
5844 ok(SUCCEEDED(hr
), "Failed to unlock buffer, hr %#x.\n", hr
);
5846 IDirect3DVertexBuffer8_Release(buffer
);
5847 refcount
= IDirect3DDevice8_Release(device
);
5848 ok(!refcount
, "Device has %u references left.\n", refcount
);
5849 IDirect3D8_Release(d3d8
);
5850 DestroyWindow(window
);
5853 static void test_managed_buffer(void)
5855 static const unsigned int vertex_count
= 1024;
5856 IDirect3DVertexBuffer8
*buffer
;
5857 D3DVERTEXBUFFER_DESC desc
;
5858 IDirect3DDevice8
*device
;
5859 struct vec3
*ptr
, *ptr2
;
5866 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
5867 0, 0, 640, 480, 0, 0, 0, 0);
5868 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
5869 ok(!!d3d8
, "Failed to create a D3D object.\n");
5870 if (!(device
= create_device(d3d8
, window
, NULL
)))
5872 skip("Failed to create a D3D device, skipping tests.\n");
5873 IDirect3D8_Release(d3d8
);
5874 DestroyWindow(window
);
5878 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, vertex_count
* sizeof(*ptr
), 0, 0, D3DPOOL_MANAGED
, &buffer
);
5879 ok(SUCCEEDED(hr
), "Failed to create buffer, hr %#x.\n", hr
);
5880 hr
= IDirect3DVertexBuffer8_GetDesc(buffer
, &desc
);
5881 ok(SUCCEEDED(hr
), "Failed to get desc, hr %#x.\n", hr
);
5882 ok(desc
.Pool
== D3DPOOL_MANAGED
, "Got unexpected pool %#x.\n", desc
.Pool
);
5883 ok(!desc
.Usage
, "Got unexpected usage %#x.\n", desc
.Usage
);
5885 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, vertex_count
* sizeof(*ptr
), (BYTE
**)&ptr
, D3DLOCK_DISCARD
);
5886 ok(SUCCEEDED(hr
), "Failed to lock buffer, hr %#x.\n", hr
);
5887 for (i
= 0; i
< vertex_count
; ++i
)
5889 ptr
[i
].x
= i
* 1.0f
;
5890 ptr
[i
].y
= i
* 2.0f
;
5891 ptr
[i
].z
= i
* 3.0f
;
5893 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
5894 ok(SUCCEEDED(hr
), "Failed to unlock buffer, hr %#x.\n", hr
);
5896 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
);
5897 ok(SUCCEEDED(hr
), "Failed to set fvf, hr %#x.\n", hr
);
5898 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, buffer
, sizeof(*ptr
));
5899 ok(SUCCEEDED(hr
), "Failed to set stream source, hr %#x.\n", hr
);
5900 hr
= IDirect3DDevice8_BeginScene(device
);
5901 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
5902 hr
= IDirect3DDevice8_DrawPrimitive(device
, D3DPT_TRIANGLELIST
, 0, 2);
5903 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
5904 hr
= IDirect3DDevice8_EndScene(device
);
5905 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
5907 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, vertex_count
* sizeof(*ptr2
), (BYTE
**)&ptr2
, D3DLOCK_DISCARD
);
5908 ok(SUCCEEDED(hr
), "Failed to lock buffer, hr %#x.\n", hr
);
5909 ok(ptr2
== ptr
, "Got unexpected ptr2 %p, expected %p.\n", ptr2
, ptr
);
5910 for (i
= 0; i
< vertex_count
; ++i
)
5912 if (ptr2
[i
].x
!= i
* 1.0f
|| ptr2
[i
].y
!= i
* 2.0f
|| ptr2
[i
].z
!= i
* 3.0f
)
5914 ok(FALSE
, "Got unexpected vertex %u {%.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e}.\n",
5915 i
, ptr2
[i
].x
, ptr2
[i
].y
, ptr2
[i
].z
, i
* 1.0f
, i
* 2.0f
, i
* 3.0f
);
5919 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
5920 ok(SUCCEEDED(hr
), "Failed to unlock buffer, hr %#x.\n", hr
);
5922 IDirect3DVertexBuffer8_Release(buffer
);
5923 refcount
= IDirect3DDevice8_Release(device
);
5924 ok(!refcount
, "Device has %u references left.\n", refcount
);
5925 IDirect3D8_Release(d3d8
);
5926 DestroyWindow(window
);
5929 static void test_npot_textures(void)
5931 IDirect3DDevice8
*device
= NULL
;
5937 IDirect3DTexture8
*texture
;
5938 IDirect3DCubeTexture8
*cube_texture
;
5939 IDirect3DVolumeTexture8
*volume_texture
;
5943 const char *pool_name
;
5948 { D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", D3DERR_INVALIDCALL
},
5949 { D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", D3DERR_INVALIDCALL
},
5950 { D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", D3DERR_INVALIDCALL
},
5951 { D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", D3D_OK
},
5953 unsigned int i
, levels
;
5954 BOOL tex_pow2
, cube_pow2
, vol_pow2
;
5956 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
5957 0, 0, 640, 480, 0, 0, 0, 0);
5958 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
5959 ok(!!d3d8
, "Failed to create a D3D object.\n");
5960 if (!(device
= create_device(d3d8
, window
, NULL
)))
5962 skip("Failed to create a D3D device, skipping tests.\n");
5966 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
5967 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
5968 tex_pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
);
5969 cube_pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP_POW2
);
5970 vol_pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP_POW2
);
5971 ok(cube_pow2
== tex_pow2
, "Cube texture and 2d texture pow2 restrictions mismatch.\n");
5972 ok(vol_pow2
== tex_pow2
, "Volume texture and 2d texture pow2 restrictions mismatch.\n");
5974 for (i
= 0; i
< sizeof(pools
) / sizeof(*pools
); i
++)
5976 for (levels
= 0; levels
<= 2; levels
++)
5980 hr
= IDirect3DDevice8_CreateTexture(device
, 10, 10, levels
, 0, D3DFMT_X8R8G8B8
,
5981 pools
[i
].pool
, &texture
);
5986 else if (caps
.TextureCaps
& D3DPTEXTURECAPS_NONPOW2CONDITIONAL
)
5991 expected
= pools
[i
].hr
;
5995 expected
= pools
[i
].hr
;
5997 ok(hr
== expected
, "CreateTexture(w=h=10, %s, levels=%u) returned hr %#x, expected %#x.\n",
5998 pools
[i
].pool_name
, levels
, hr
, expected
);
6001 IDirect3DTexture8_Release(texture
);
6004 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 3, 1, 0, D3DFMT_X8R8G8B8
,
6005 pools
[i
].pool
, &cube_texture
);
6008 ok(hr
== pools
[i
].hr
, "CreateCubeTexture(EdgeLength=3, %s) returned hr %#x, expected %#x.\n",
6009 pools
[i
].pool_name
, hr
, pools
[i
].hr
);
6013 ok(SUCCEEDED(hr
), "CreateCubeTexture(EdgeLength=3, %s) returned hr %#x, expected %#x.\n",
6014 pools
[i
].pool_name
, hr
, D3D_OK
);
6018 IDirect3DCubeTexture8_Release(cube_texture
);
6020 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 2, 2, 3, 1, 0, D3DFMT_X8R8G8B8
,
6021 pools
[i
].pool
, &volume_texture
);
6024 ok(hr
== pools
[i
].hr
, "CreateVolumeTextur(Depth=3, %s) returned hr %#x, expected %#x.\n",
6025 pools
[i
].pool_name
, hr
, pools
[i
].hr
);
6029 ok(SUCCEEDED(hr
), "CreateVolumeTextur(Depth=3, %s) returned hr %#x, expected %#x.\n",
6030 pools
[i
].pool_name
, hr
, D3D_OK
);
6034 IDirect3DVolumeTexture8_Release(volume_texture
);
6040 refcount
= IDirect3DDevice8_Release(device
);
6041 ok(!refcount
, "Device has %u references left.\n", refcount
);
6043 IDirect3D8_Release(d3d8
);
6044 DestroyWindow(window
);
6048 static void test_volume_locking(void)
6050 IDirect3DDevice8
*device
;
6054 IDirect3DVolumeTexture8
*texture
;
6056 D3DLOCKED_BOX locked_box
;
6063 HRESULT create_hr
, lock_hr
;
6067 { D3DPOOL_DEFAULT
, 0, D3D_OK
, D3DERR_INVALIDCALL
},
6068 { D3DPOOL_DEFAULT
, D3DUSAGE_DYNAMIC
, D3D_OK
, D3D_OK
},
6069 { D3DPOOL_SYSTEMMEM
, 0, D3D_OK
, D3D_OK
},
6070 { D3DPOOL_SYSTEMMEM
, D3DUSAGE_DYNAMIC
, D3D_OK
, D3D_OK
},
6071 { D3DPOOL_MANAGED
, 0, D3D_OK
, D3D_OK
},
6072 { D3DPOOL_MANAGED
, D3DUSAGE_DYNAMIC
, D3DERR_INVALIDCALL
, D3D_OK
},
6073 { D3DPOOL_SCRATCH
, 0, D3D_OK
, D3D_OK
},
6074 { D3DPOOL_SCRATCH
, D3DUSAGE_DYNAMIC
, D3DERR_INVALIDCALL
, D3D_OK
},
6077 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6078 0, 0, 640, 480, 0, 0, 0, 0);
6079 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
6080 ok(!!d3d8
, "Failed to create a D3D object.\n");
6081 if (!(device
= create_device(d3d8
, window
, NULL
)))
6083 skip("Failed to create a D3D device, skipping tests.\n");
6084 IDirect3D8_Release(d3d8
);
6085 DestroyWindow(window
);
6089 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
6090 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6091 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
))
6093 skip("Volume textures not supported, skipping test.\n");
6097 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
6099 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 4, 4, 4, 1, tests
[i
].usage
,
6100 D3DFMT_A8R8G8B8
, tests
[i
].pool
, &texture
);
6101 ok(hr
== tests
[i
].create_hr
, "Creating volume texture pool=%u, usage=%#x returned %#x, expected %#x.\n",
6102 tests
[i
].pool
, tests
[i
].usage
, hr
, tests
[i
].create_hr
);
6106 locked_box
.pBits
= (void *)0xdeadbeef;
6107 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, NULL
, 0);
6108 ok(hr
== tests
[i
].lock_hr
, "Lock returned %#x, expected %#x.\n", hr
, tests
[i
].lock_hr
);
6111 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6112 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6116 ok (locked_box
.pBits
== NULL
, "Failed lock set pBits = %p, expected NULL.\n", locked_box
.pBits
);
6118 IDirect3DVolumeTexture8_Release(texture
);
6122 refcount
= IDirect3DDevice8_Release(device
);
6123 ok(!refcount
, "Device has %u references left.\n", refcount
);
6124 IDirect3D8_Release(d3d8
);
6125 DestroyWindow(window
);
6128 static void test_update_volumetexture(void)
6130 IDirect3DDevice8
*device
;
6134 IDirect3DVolumeTexture8
*src
, *dst
;
6136 D3DLOCKED_BOX locked_box
;
6141 D3DPOOL src_pool
, dst_pool
;
6146 { D3DPOOL_DEFAULT
, D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
},
6147 { D3DPOOL_MANAGED
, D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
},
6148 { D3DPOOL_SYSTEMMEM
, D3DPOOL_DEFAULT
, D3D_OK
},
6149 { D3DPOOL_SCRATCH
, D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
},
6151 { D3DPOOL_DEFAULT
, D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
},
6152 { D3DPOOL_MANAGED
, D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
},
6153 { D3DPOOL_SYSTEMMEM
, D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
},
6154 { D3DPOOL_SCRATCH
, D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
},
6156 { D3DPOOL_DEFAULT
, D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
},
6157 { D3DPOOL_MANAGED
, D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
},
6158 { D3DPOOL_SYSTEMMEM
, D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
},
6159 { D3DPOOL_SCRATCH
, D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
},
6161 { D3DPOOL_DEFAULT
, D3DPOOL_SCRATCH
, D3DERR_INVALIDCALL
},
6162 { D3DPOOL_MANAGED
, D3DPOOL_SCRATCH
, D3DERR_INVALIDCALL
},
6163 { D3DPOOL_SYSTEMMEM
, D3DPOOL_SCRATCH
, D3DERR_INVALIDCALL
},
6164 { D3DPOOL_SCRATCH
, D3DPOOL_SCRATCH
, D3DERR_INVALIDCALL
},
6168 UINT src_size
, dst_size
;
6169 UINT src_lvl
, dst_lvl
;
6170 D3DFORMAT src_fmt
, dst_fmt
;
6174 { 8, 8, 0, 0, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
6175 { 8, 8, 4, 4, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
6176 { 8, 8, 2, 2, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
6177 { 8, 8, 1, 1, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
6178 { 8, 8, 4, 0, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
6179 { 8, 8, 1, 4, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
}, /* Different level count */
6180 { 4, 8, 1, 1, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
}, /* Different size */
6181 { 8, 8, 4, 4, D3DFMT_A8R8G8B8
, D3DFMT_X8R8G8B8
}, /* Different format */
6184 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6185 0, 0, 640, 480, 0, 0, 0, 0);
6186 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
6187 ok(!!d3d8
, "Failed to create a D3D object.\n");
6188 if (!(device
= create_device(d3d8
, window
, NULL
)))
6190 skip("Failed to create a D3D device, skipping tests.\n");
6191 IDirect3D8_Release(d3d8
);
6192 DestroyWindow(window
);
6196 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
6197 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6198 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
))
6200 skip("Volume textures not supported, skipping test.\n");
6204 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
6206 DWORD src_usage
= tests
[i
].src_pool
== D3DPOOL_DEFAULT
? D3DUSAGE_DYNAMIC
: 0;
6207 DWORD dst_usage
= tests
[i
].dst_pool
== D3DPOOL_DEFAULT
? D3DUSAGE_DYNAMIC
: 0;
6209 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 1, 1, 1, 1, src_usage
,
6210 D3DFMT_A8R8G8B8
, tests
[i
].src_pool
, &src
);
6211 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
6212 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 1, 1, 1, 1, dst_usage
,
6213 D3DFMT_A8R8G8B8
, tests
[i
].dst_pool
, &dst
);
6214 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
6216 hr
= IDirect3DVolumeTexture8_LockBox(src
, 0, &locked_box
, NULL
, 0);
6217 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
6218 *((DWORD
*)locked_box
.pBits
) = 0x11223344;
6219 hr
= IDirect3DVolumeTexture8_UnlockBox(src
, 0);
6220 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6222 hr
= IDirect3DDevice8_UpdateTexture(device
, (IDirect3DBaseTexture8
*)src
, (IDirect3DBaseTexture8
*)dst
);
6223 ok(hr
== tests
[i
].hr
, "UpdateTexture returned %#x, expected %#x, src pool %x, dst pool %u.\n",
6224 hr
, tests
[i
].hr
, tests
[i
].src_pool
, tests
[i
].dst_pool
);
6228 DWORD content
= *((DWORD
*)locked_box
.pBits
);
6229 hr
= IDirect3DVolumeTexture8_LockBox(dst
, 0, &locked_box
, NULL
, 0);
6230 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
6231 ok(content
== 0x11223344, "Dest texture contained %#x, expected 0x11223344.\n", content
);
6232 hr
= IDirect3DVolumeTexture8_UnlockBox(dst
, 0);
6233 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6235 IDirect3DVolumeTexture8_Release(src
);
6236 IDirect3DVolumeTexture8_Release(dst
);
6239 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_MIPVOLUMEMAP
))
6241 skip("Mipmapped volume maps not supported.\n");
6245 for (i
= 0; i
< sizeof(tests2
) / sizeof(*tests2
); i
++)
6247 hr
= IDirect3DDevice8_CreateVolumeTexture(device
,
6248 tests2
[i
].src_size
, tests2
[i
].src_size
, tests2
[i
].src_size
,
6249 tests2
[i
].src_lvl
, 0, tests2
[i
].src_fmt
, D3DPOOL_SYSTEMMEM
, &src
);
6250 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x, case %u.\n", hr
, i
);
6251 hr
= IDirect3DDevice8_CreateVolumeTexture(device
,
6252 tests2
[i
].dst_size
, tests2
[i
].dst_size
, tests2
[i
].dst_size
,
6253 tests2
[i
].dst_lvl
, 0, tests2
[i
].dst_fmt
, D3DPOOL_DEFAULT
, &dst
);
6254 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x, case %u.\n", hr
, i
);
6256 hr
= IDirect3DDevice8_UpdateTexture(device
, (IDirect3DBaseTexture8
*)src
, (IDirect3DBaseTexture8
*)dst
);
6258 todo_wine
ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x, case %u.\n", hr
, i
);
6260 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x, case %u.\n", hr
, i
);
6262 IDirect3DVolumeTexture8_Release(src
);
6263 IDirect3DVolumeTexture8_Release(dst
);
6266 /* As far as I can see, UpdateTexture on non-matching texture behaves like a memcpy. The raw data
6267 * stays the same in a format change, a 2x2x1 texture is copied into the first row of a 4x4x1 texture,
6268 * etc. I could not get it to segfault, but the nonexistent 5th pixel of a 2x2x1 texture is copied into
6269 * pixel 1x2x1 of a 4x4x1 texture, demonstrating a read beyond the texture's end. I suspect any bad
6270 * memory access is silently ignored by the runtime, in the kernel or on the GPU.
6272 * I'm not adding tests for this behavior until an application needs it. */
6275 refcount
= IDirect3DDevice8_Release(device
);
6276 ok(!refcount
, "Device has %u references left.\n", refcount
);
6277 IDirect3D8_Release(d3d8
);
6278 DestroyWindow(window
);
6281 static void test_create_rt_ds_fail(void)
6283 IDirect3DDevice8
*device
;
6288 IDirect3DSurface8
*surface
;
6290 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6291 0, 0, 640, 480, 0, 0, 0, 0);
6292 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
6293 ok(!!d3d8
, "Failed to create a D3D object.\n");
6294 if (!(device
= create_device(d3d8
, window
, NULL
)))
6296 skip("Failed to create a D3D device, skipping tests.\n");
6297 IDirect3D8_Release(d3d8
);
6298 DestroyWindow(window
);
6302 /* Output pointer == NULL segfaults on Windows. */
6304 surface
= (IDirect3DSurface8
*)0xdeadbeef;
6305 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 4, 4, D3DFMT_D16
,
6306 D3DMULTISAMPLE_NONE
, FALSE
, &surface
);
6307 ok(hr
== D3DERR_INVALIDCALL
, "Creating a D16 render target returned hr %#x.\n", hr
);
6308 ok(surface
== NULL
, "Got pointer %p, expected NULL.\n", surface
);
6310 IDirect3DSurface8_Release(surface
);
6312 surface
= (IDirect3DSurface8
*)0xdeadbeef;
6313 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 4, 4, D3DFMT_A8R8G8B8
,
6314 D3DMULTISAMPLE_NONE
, &surface
);
6315 ok(hr
== D3DERR_INVALIDCALL
, "Creating a A8R8G8B8 depth stencil returned hr %#x.\n", hr
);
6316 ok(surface
== NULL
, "Got pointer %p, expected NULL.\n", surface
);
6318 IDirect3DSurface8_Release(surface
);
6320 refcount
= IDirect3DDevice8_Release(device
);
6321 ok(!refcount
, "Device has %u references left.\n", refcount
);
6322 IDirect3D8_Release(d3d8
);
6323 DestroyWindow(window
);
6326 static void test_volume_blocks(void)
6328 IDirect3DDevice8
*device
;
6334 IDirect3DVolumeTexture8
*texture
;
6335 unsigned int w
, h
, d
, i
, j
;
6340 unsigned int block_width
;
6341 unsigned int block_height
;
6342 unsigned int block_depth
;
6343 unsigned int block_size
;
6344 unsigned int broken
;
6345 BOOL create_size_checked
, core_fmt
;
6349 /* Scratch volumes enforce DXTn block locks, unlike their surface counterparts.
6350 * ATI2N and YUV blocks are not enforced on any tested card (r200, gtx 460). */
6351 {D3DFMT_DXT1
, "D3DFMT_DXT1", 4, 4, 1, 8, 0, TRUE
, TRUE
},
6352 {D3DFMT_DXT2
, "D3DFMT_DXT2", 4, 4, 1, 16, 0, TRUE
, TRUE
},
6353 {D3DFMT_DXT3
, "D3DFMT_DXT3", 4, 4, 1, 16, 0, TRUE
, TRUE
},
6354 {D3DFMT_DXT4
, "D3DFMT_DXT4", 4, 4, 1, 16, 0, TRUE
, TRUE
},
6355 {D3DFMT_DXT5
, "D3DFMT_DXT5", 4, 4, 1, 16, 0, TRUE
, TRUE
},
6356 {D3DFMT_DXT5
, "D3DFMT_DXT5", 4, 4, 1, 16, 0, TRUE
, TRUE
},
6357 /* ATI2N has 2x2 blocks on all AMD cards and Geforce 7 cards,
6358 * which doesn't match the format spec. On newer Nvidia cards
6359 * it has the correct 4x4 block size.
6360 * ATI1N volume textures are only supported by AMD GPUs right
6361 * now and locking offsets seem just wrong. */
6362 {MAKEFOURCC('A','T','I','1'), "ATI1N", 4, 4, 1, 8, 2, FALSE
, FALSE
},
6363 {MAKEFOURCC('A','T','I','2'), "ATI2N", 4, 4, 1, 16, 1, FALSE
, FALSE
},
6364 {D3DFMT_YUY2
, "D3DFMT_YUY2", 2, 1, 1, 4, 1, FALSE
, TRUE
},
6365 {D3DFMT_UYVY
, "D3DFMT_UYVY", 2, 1, 1, 4, 1, FALSE
, TRUE
},
6371 BOOL need_driver_support
, need_runtime_support
;
6375 {D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", TRUE
, FALSE
},
6376 {D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", FALSE
, TRUE
},
6377 {D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM",TRUE
, FALSE
},
6378 {D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
, FALSE
},
6382 unsigned int x
, y
, z
, x2
, y2
, z2
;
6396 D3DLOCKED_BOX locked_box
;
6398 INT expected_row_pitch
, expected_slice_pitch
;
6401 unsigned int offset
, expected_offset
;
6403 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6404 0, 0, 640, 480, 0, 0, 0, 0);
6405 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
6406 ok(!!d3d8
, "Failed to create a D3D object.\n");
6407 if (!(device
= create_device(d3d8
, window
, NULL
)))
6409 skip("Failed to create a D3D device, skipping tests.\n");
6410 IDirect3D8_Release(d3d8
);
6411 DestroyWindow(window
);
6414 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
6415 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6416 pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP_POW2
);
6418 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
6420 hr
= IDirect3D8_CheckDeviceFormat(d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
6421 0, D3DRTYPE_VOLUMETEXTURE
, formats
[i
].fmt
);
6422 support
= SUCCEEDED(hr
);
6424 /* Test creation restrictions */
6425 for (w
= 1; w
<= 8; w
++)
6427 for (h
= 1; h
<= 8; h
++)
6429 for (d
= 1; d
<= 8; d
++)
6433 BOOL block_aligned
= TRUE
;
6435 if (w
& (formats
[i
].block_width
- 1) || h
& (formats
[i
].block_height
- 1))
6436 block_aligned
= FALSE
;
6438 size_is_pow2
= !((w
& (w
- 1)) || (h
& (h
- 1)) || (d
& (d
- 1)));
6440 for (j
= 0; j
< sizeof(create_tests
) / sizeof(*create_tests
); j
++)
6442 BOOL may_succeed
= FALSE
;
6444 if (create_tests
[j
].need_runtime_support
&& !formats
[i
].core_fmt
&& !support
)
6445 expect_hr
= D3DERR_INVALIDCALL
;
6446 else if (formats
[i
].create_size_checked
&& !block_aligned
)
6447 expect_hr
= D3DERR_INVALIDCALL
;
6448 else if (pow2
&& !size_is_pow2
&& create_tests
[j
].need_driver_support
)
6449 expect_hr
= D3DERR_INVALIDCALL
;
6450 else if (create_tests
[j
].need_driver_support
&& !support
)
6451 expect_hr
= D3DERR_INVALIDCALL
;
6455 texture
= (IDirect3DVolumeTexture8
*)0xdeadbeef;
6456 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, w
, h
, d
, 1, 0,
6457 formats
[i
].fmt
, create_tests
[j
].pool
, &texture
);
6459 /* Wine knows about ATI2N and happily creates a scratch resource even if GL
6460 * does not support it. Accept scratch creation of extension formats on
6461 * Windows as well if it occurs. We don't really care if e.g. a Windows 7
6462 * on an r200 GPU creates scratch ATI2N texture even though the card doesn't
6464 if (!formats
[i
].core_fmt
&& !support
&& FAILED(expect_hr
))
6467 ok(hr
== expect_hr
|| ((SUCCEEDED(hr
) && may_succeed
)),
6468 "Got unexpected hr %#x for format %s, pool %s, size %ux%ux%u.\n",
6469 hr
, formats
[i
].name
, create_tests
[j
].name
, w
, h
, d
);
6472 ok(texture
== NULL
, "Got texture ptr %p, expected NULL.\n", texture
);
6474 IDirect3DVolumeTexture8_Release(texture
);
6480 if (!support
&& !formats
[i
].core_fmt
)
6483 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 24, 8, 8, 1, 0,
6484 formats
[i
].fmt
, D3DPOOL_SCRATCH
, &texture
);
6485 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
6487 /* Test lockrect offset */
6488 for (j
= 0; j
< sizeof(offset_tests
) / sizeof(*offset_tests
); j
++)
6490 unsigned int bytes_per_pixel
;
6491 bytes_per_pixel
= formats
[i
].block_size
/ (formats
[i
].block_width
* formats
[i
].block_height
);
6493 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, NULL
, 0);
6494 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6496 base
= locked_box
.pBits
;
6497 if (formats
[i
].broken
== 1)
6499 expected_row_pitch
= bytes_per_pixel
* 24;
6501 else if (formats
[i
].broken
== 2)
6503 expected_row_pitch
= 24;
6507 expected_row_pitch
= (24 /* tex width */ + formats
[i
].block_height
- 1) / formats
[i
].block_width
6508 * formats
[i
].block_size
;
6510 ok(locked_box
.RowPitch
== expected_row_pitch
, "Got unexpected row pitch %d for format %s, expected %d.\n",
6511 locked_box
.RowPitch
, formats
[i
].name
, expected_row_pitch
);
6513 if (formats
[i
].broken
)
6515 expected_slice_pitch
= expected_row_pitch
* 8;
6519 expected_slice_pitch
= (8 /* tex height */ + formats
[i
].block_depth
- 1) / formats
[i
].block_height
6520 * expected_row_pitch
;
6522 ok(locked_box
.SlicePitch
== expected_slice_pitch
,
6523 "Got unexpected slice pitch %d for format %s, expected %d.\n",
6524 locked_box
.SlicePitch
, formats
[i
].name
, expected_slice_pitch
);
6526 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6527 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x, j %u.\n", hr
, j
);
6529 box
.Left
= offset_tests
[j
].x
;
6530 box
.Top
= offset_tests
[j
].y
;
6531 box
.Front
= offset_tests
[j
].z
;
6532 box
.Right
= offset_tests
[j
].x2
;
6533 box
.Bottom
= offset_tests
[j
].y2
;
6534 box
.Back
= offset_tests
[j
].z2
;
6535 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
6536 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x, j %u.\n", hr
, j
);
6538 offset
= (BYTE
*)locked_box
.pBits
- base
;
6539 if (formats
[i
].broken
== 1)
6541 expected_offset
= box
.Front
* expected_slice_pitch
6542 + box
.Top
* expected_row_pitch
6543 + box
.Left
* bytes_per_pixel
;
6545 else if (formats
[i
].broken
== 2)
6547 expected_offset
= box
.Front
* expected_slice_pitch
6548 + box
.Top
* expected_row_pitch
6553 expected_offset
= (box
.Front
/ formats
[i
].block_depth
) * expected_slice_pitch
6554 + (box
.Top
/ formats
[i
].block_height
) * expected_row_pitch
6555 + (box
.Left
/ formats
[i
].block_width
) * formats
[i
].block_size
;
6557 ok(offset
== expected_offset
, "Got unexpected offset %u for format %s, expected %u, box start %ux%ux%u.\n",
6558 offset
, formats
[i
].name
, expected_offset
, box
.Left
, box
.Top
, box
.Front
);
6560 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6561 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6564 /* Test partial block locks */
6567 if (formats
[i
].block_width
> 1)
6569 box
.Left
= formats
[i
].block_width
>> 1;
6571 box
.Right
= formats
[i
].block_width
;
6572 box
.Bottom
= formats
[i
].block_height
;
6573 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
6574 ok(FAILED(hr
) || broken(formats
[i
].broken
),
6575 "Partial block lock succeeded, expected failure, format %s.\n",
6579 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6580 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6585 box
.Right
= formats
[i
].block_width
>> 1;
6586 box
.Bottom
= formats
[i
].block_height
;
6587 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
6588 ok(FAILED(hr
) || broken(formats
[i
].broken
),
6589 "Partial block lock succeeded, expected failure, format %s.\n",
6593 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6594 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6598 if (formats
[i
].block_height
> 1)
6601 box
.Top
= formats
[i
].block_height
>> 1;
6602 box
.Right
= formats
[i
].block_width
;
6603 box
.Bottom
= formats
[i
].block_height
;
6604 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
6605 ok(FAILED(hr
) || broken(formats
[i
].broken
),
6606 "Partial block lock succeeded, expected failure, format %s.\n",
6610 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6611 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6616 box
.Right
= formats
[i
].block_width
;
6617 box
.Bottom
= formats
[i
].block_height
>> 1;
6618 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
6619 ok(FAILED(hr
) || broken(formats
[i
].broken
),
6620 "Partial block lock succeeded, expected failure, format %s.\n",
6624 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6625 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6629 /* Test full block lock */
6632 box
.Right
= formats
[i
].block_width
;
6633 box
.Bottom
= formats
[i
].block_height
;
6634 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
6635 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
6636 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6637 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6639 IDirect3DVolumeTexture8_Release(texture
);
6641 /* Test mipmap locks. Don't do this with ATI2N, AMD warns that the runtime
6642 * does not allocate surfaces smaller than the blocksize properly. */
6643 if ((formats
[i
].block_width
> 1 || formats
[i
].block_height
> 1) && formats
[i
].core_fmt
)
6645 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, formats
[i
].block_width
, formats
[i
].block_height
,
6646 2, 2, 0, formats
[i
].fmt
, D3DPOOL_SCRATCH
, &texture
);
6648 ok(SUCCEEDED(hr
), "CreateVolumeTexture failed, hr %#x.\n", hr
);
6649 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 1, &locked_box
, NULL
, 0);
6650 ok(SUCCEEDED(hr
), "Failed to lock volume texture mipmap, hr %#x.\n", hr
);
6651 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 1);
6652 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6654 box
.Left
= box
.Top
= box
.Front
= 0;
6655 box
.Right
= formats
[i
].block_width
== 1 ? 1 : formats
[i
].block_width
>> 1;
6656 box
.Bottom
= formats
[i
].block_height
== 1 ? 1 : formats
[i
].block_height
>> 1;
6658 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 1, &locked_box
, &box
, 0);
6659 ok(SUCCEEDED(hr
), "Failed to lock volume texture mipmap, hr %#x.\n", hr
);
6660 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 1);
6661 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6663 box
.Right
= formats
[i
].block_width
;
6664 box
.Bottom
= formats
[i
].block_height
;
6665 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 1, &locked_box
, &box
, 0);
6666 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
6668 IDirect3DVolumeTexture8_UnlockBox(texture
, 1);
6670 IDirect3DVolumeTexture8_Release(texture
);
6674 refcount
= IDirect3DDevice8_Release(device
);
6675 ok(!refcount
, "Device has %u references left.\n", refcount
);
6676 IDirect3D8_Release(d3d8
);
6677 DestroyWindow(window
);
6680 static void test_lockbox_invalid(void)
6689 {{0, 0, 2, 2, 0, 1}, D3D_OK
}, /* Valid */
6690 {{0, 0, 4, 4, 0, 1}, D3D_OK
}, /* Valid */
6691 {{0, 0, 0, 4, 0, 1}, D3DERR_INVALIDCALL
}, /* 0 height */
6692 {{0, 0, 4, 0, 0, 1}, D3DERR_INVALIDCALL
}, /* 0 width */
6693 {{0, 0, 4, 4, 1, 1}, D3DERR_INVALIDCALL
}, /* 0 depth */
6694 {{4, 0, 0, 4, 0, 1}, D3DERR_INVALIDCALL
}, /* left > right */
6695 {{0, 4, 4, 0, 0, 1}, D3DERR_INVALIDCALL
}, /* top > bottom */
6696 {{0, 0, 4, 4, 1, 0}, D3DERR_INVALIDCALL
}, /* back > front */
6697 {{0, 0, 8, 4, 0, 1}, D3DERR_INVALIDCALL
}, /* right > surface */
6698 {{0, 0, 4, 8, 0, 1}, D3DERR_INVALIDCALL
}, /* bottom > surface */
6699 {{0, 0, 4, 4, 0, 3}, D3DERR_INVALIDCALL
}, /* back > surface */
6700 {{8, 0, 16, 4, 0, 1}, D3DERR_INVALIDCALL
}, /* left > surface */
6701 {{0, 8, 4, 16, 0, 1}, D3DERR_INVALIDCALL
}, /* top > surface */
6702 {{0, 0, 4, 4, 2, 4}, D3DERR_INVALIDCALL
}, /* top > surface */
6704 static const D3DBOX test_boxt_2
= {2, 2, 4, 4, 0, 1};
6705 IDirect3DVolumeTexture8
*texture
= NULL
;
6706 D3DLOCKED_BOX locked_box
;
6707 IDirect3DDevice8
*device
;
6715 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6716 0, 0, 640, 480, 0, 0, 0, 0);
6717 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
6718 ok(!!d3d
, "Failed to create a D3D object.\n");
6719 if (!(device
= create_device(d3d
, window
, NULL
)))
6721 skip("Failed to create a D3D device, skipping tests.\n");
6722 IDirect3D8_Release(d3d
);
6723 DestroyWindow(window
);
6727 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 4, 4, 2, 1, 0,
6728 D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &texture
);
6729 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
6730 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, NULL
, 0);
6731 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
6732 base
= locked_box
.pBits
;
6733 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6734 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6736 for (i
= 0; i
< (sizeof(test_data
) / sizeof(*test_data
)); ++i
)
6738 unsigned int offset
, expected_offset
;
6739 const D3DBOX
*box
= &test_data
[i
].box
;
6741 locked_box
.pBits
= (BYTE
*)0xdeadbeef;
6742 locked_box
.RowPitch
= 0xdeadbeef;
6743 locked_box
.SlicePitch
= 0xdeadbeef;
6745 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, box
, 0);
6746 /* Unlike surfaces, volumes properly check the box even in Windows XP */
6747 ok(hr
== test_data
[i
].result
,
6748 "Got unexpected hr %#x with box [%u, %u, %u]->[%u, %u, %u], expected %#x.\n",
6749 hr
, box
->Left
, box
->Top
, box
->Front
, box
->Right
, box
->Bottom
, box
->Back
,
6750 test_data
[i
].result
);
6754 offset
= (BYTE
*)locked_box
.pBits
- base
;
6755 expected_offset
= box
->Front
* locked_box
.SlicePitch
+ box
->Top
* locked_box
.RowPitch
+ box
->Left
* 4;
6756 ok(offset
== expected_offset
,
6757 "Got unexpected offset %u (expected %u) for rect [%u, %u, %u]->[%u, %u, %u].\n",
6758 offset
, expected_offset
, box
->Left
, box
->Top
, box
->Front
, box
->Right
, box
->Bottom
, box
->Back
);
6760 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6761 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6764 /* locked_box = NULL throws an exception on Windows */
6765 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, NULL
, 0);
6766 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
6767 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, NULL
, 0);
6768 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
6769 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6770 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6771 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6772 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
6774 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &test_data
[0].box
, 0);
6775 ok(hr
== D3D_OK
, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
6776 hr
, test_data
[0].box
.Left
, test_data
[0].box
.Top
, test_data
[0].box
.Front
,
6777 test_data
[0].box
.Right
, test_data
[0].box
.Bottom
, test_data
[0].box
.Back
);
6778 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &test_data
[0].box
, 0);
6779 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
6780 hr
, test_data
[0].box
.Left
, test_data
[0].box
.Top
, test_data
[0].box
.Front
,
6781 test_data
[0].box
.Right
, test_data
[0].box
.Bottom
, test_data
[0].box
.Back
);
6782 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &test_boxt_2
, 0);
6783 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
6784 hr
, test_boxt_2
.Left
, test_boxt_2
.Top
, test_boxt_2
.Front
,
6785 test_boxt_2
.Right
, test_boxt_2
.Bottom
, test_boxt_2
.Back
);
6786 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6787 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6789 IDirect3DVolumeTexture8_Release(texture
);
6790 refcount
= IDirect3DDevice8_Release(device
);
6791 ok(!refcount
, "Device has %u references left.\n", refcount
);
6792 IDirect3D8_Release(d3d
);
6793 DestroyWindow(window
);
6796 static void test_pixel_format(void)
6798 HWND hwnd
, hwnd2
= NULL
;
6799 HDC hdc
, hdc2
= NULL
;
6801 int format
, test_format
;
6802 PIXELFORMATDESCRIPTOR pfd
;
6803 IDirect3D8
*d3d8
= NULL
;
6804 IDirect3DDevice8
*device
= NULL
;
6806 static const float point
[3] = {0.0, 0.0, 0.0};
6808 hwnd
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6809 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
6812 skip("Failed to create window\n");
6816 hwnd2
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6817 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
6822 skip("Failed to get DC\n");
6827 hdc2
= GetDC(hwnd2
);
6829 gl
= LoadLibraryA("opengl32.dll");
6830 ok(!!gl
, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
6832 format
= GetPixelFormat(hdc
);
6833 ok(format
== 0, "new window has pixel format %d\n", format
);
6835 ZeroMemory(&pfd
, sizeof(pfd
));
6836 pfd
.nSize
= sizeof(pfd
);
6838 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
6839 pfd
.iPixelType
= PFD_TYPE_RGBA
;
6840 pfd
.iLayerType
= PFD_MAIN_PLANE
;
6841 format
= ChoosePixelFormat(hdc
, &pfd
);
6844 skip("no pixel format available\n");
6848 if (!SetPixelFormat(hdc
, format
, &pfd
) || GetPixelFormat(hdc
) != format
)
6850 skip("failed to set pixel format\n");
6854 if (!hdc2
|| !SetPixelFormat(hdc2
, format
, &pfd
) || GetPixelFormat(hdc2
) != format
)
6856 skip("failed to set pixel format on second window\n");
6859 ReleaseDC(hwnd2
, hdc2
);
6864 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
6865 ok(!!d3d8
, "Failed to create a D3D object.\n");
6867 test_format
= GetPixelFormat(hdc
);
6868 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6870 if (!(device
= create_device(d3d8
, hwnd
, NULL
)))
6872 skip("Failed to create device\n");
6876 test_format
= GetPixelFormat(hdc
);
6877 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6879 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
);
6880 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
6882 test_format
= GetPixelFormat(hdc
);
6883 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6885 hr
= IDirect3DDevice8_BeginScene(device
);
6886 ok(SUCCEEDED(hr
), "BeginScene failed %#x\n", hr
);
6888 test_format
= GetPixelFormat(hdc
);
6889 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6891 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_POINTLIST
, 1, point
, 3 * sizeof(float));
6892 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6894 test_format
= GetPixelFormat(hdc
);
6895 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6897 hr
= IDirect3DDevice8_EndScene(device
);
6898 ok(SUCCEEDED(hr
), "EndScene failed %#x\n", hr
);
6900 test_format
= GetPixelFormat(hdc
);
6901 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6903 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
6904 ok(SUCCEEDED(hr
), "Present failed %#x\n", hr
);
6906 test_format
= GetPixelFormat(hdc
);
6907 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6911 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, hwnd2
, NULL
);
6912 ok(SUCCEEDED(hr
), "Present failed %#x\n", hr
);
6914 test_format
= GetPixelFormat(hdc
);
6915 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6917 test_format
= GetPixelFormat(hdc2
);
6918 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
6924 UINT refcount
= IDirect3DDevice8_Release(device
);
6925 ok(!refcount
, "Device has %u references left.\n", refcount
);
6927 if (d3d8
) IDirect3D8_Release(d3d8
);
6928 if (gl
) FreeLibrary(gl
);
6929 if (hdc
) ReleaseDC(hwnd
, hdc
);
6930 if (hdc2
) ReleaseDC(hwnd2
, hdc2
);
6931 if (hwnd
) DestroyWindow(hwnd
);
6932 if (hwnd2
) DestroyWindow(hwnd2
);
6935 static void test_begin_end_state_block(void)
6937 IDirect3DDevice8
*device
;
6944 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6945 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
6946 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
6947 ok(!!d3d
, "Failed to create a D3D object.\n");
6948 if (!(device
= create_device(d3d
, window
, NULL
)))
6950 skip("Failed to create a D3D device, skipping tests.\n");
6951 IDirect3D8_Release(d3d
);
6952 DestroyWindow(window
);
6956 /* Should succeed. */
6957 hr
= IDirect3DDevice8_BeginStateBlock(device
);
6958 ok(SUCCEEDED(hr
), "Failed to begin stateblock, hr %#x.\n", hr
);
6960 /* Calling BeginStateBlock() while recording should return
6961 * D3DERR_INVALIDCALL. */
6962 hr
= IDirect3DDevice8_BeginStateBlock(device
);
6963 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
6965 /* Should succeed. */
6966 stateblock
= 0xdeadbeef;
6967 hr
= IDirect3DDevice8_EndStateBlock(device
, &stateblock
);
6968 ok(SUCCEEDED(hr
), "Failed to end stateblock, hr %#x.\n", hr
);
6969 ok(!!stateblock
&& stateblock
!= 0xdeadbeef, "Got unexpected stateblock %#x.\n", stateblock
);
6970 IDirect3DDevice8_DeleteStateBlock(device
, stateblock
);
6972 /* Calling EndStateBlock() while not recording should return
6973 * D3DERR_INVALIDCALL. stateblock should not be touched. */
6974 stateblock
= 0xdeadbeef;
6975 hr
= IDirect3DDevice8_EndStateBlock(device
, &stateblock
);
6976 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
6977 ok(stateblock
== 0xdeadbeef, "Got unexpected stateblock %#x.\n", stateblock
);
6979 refcount
= IDirect3DDevice8_Release(device
);
6980 ok(!refcount
, "Device has %u references left.\n", refcount
);
6981 IDirect3D8_Release(d3d
);
6982 DestroyWindow(window
);
6985 static void test_shader_constant_apply(void)
6987 static const float vs_const
[] = {1.0f
, 2.0f
, 3.0f
, 4.0f
};
6988 static const float ps_const
[] = {5.0f
, 6.0f
, 7.0f
, 8.0f
};
6989 static const float initial
[] = {0.0f
, 0.0f
, 0.0f
, 0.0f
};
6990 DWORD vs_version
, ps_version
;
6991 IDirect3DDevice8
*device
;
7000 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
7001 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
7002 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
7003 ok(!!d3d
, "Failed to create a D3D object.\n");
7004 if (!(device
= create_device(d3d
, window
, NULL
)))
7006 skip("Failed to create a D3D device, skipping tests.\n");
7007 IDirect3D8_Release(d3d
);
7008 DestroyWindow(window
);
7012 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
7013 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
7014 vs_version
= caps
.VertexShaderVersion
& 0xffff;
7015 ps_version
= caps
.PixelShaderVersion
& 0xffff;
7019 hr
= IDirect3DDevice8_SetVertexShaderConstant(device
, 0, initial
, 1);
7020 ok(SUCCEEDED(hr
), "Failed to set vertex shader constant, hr %#x.\n", hr
);
7021 hr
= IDirect3DDevice8_SetVertexShaderConstant(device
, 1, initial
, 1);
7022 ok(SUCCEEDED(hr
), "Failed to set vertex shader constant, hr %#x.\n", hr
);
7024 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 0, ret
, 1);
7025 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7026 ok(!memcmp(ret
, initial
, sizeof(initial
)),
7027 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7028 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
7029 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 1, ret
, 1);
7030 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7031 ok(!memcmp(ret
, initial
, sizeof(initial
)),
7032 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7033 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
7035 hr
= IDirect3DDevice8_SetVertexShaderConstant(device
, 0, vs_const
, 1);
7036 ok(SUCCEEDED(hr
), "Failed to set vertex shader constant, hr %#x.\n", hr
);
7040 hr
= IDirect3DDevice8_SetPixelShaderConstant(device
, 0, initial
, 1);
7041 ok(SUCCEEDED(hr
), "Failed to set pixel shader constant, hr %#x.\n", hr
);
7042 hr
= IDirect3DDevice8_SetPixelShaderConstant(device
, 1, initial
, 1);
7043 ok(SUCCEEDED(hr
), "Failed to set pixel shader constant, hr %#x.\n", hr
);
7045 hr
= IDirect3DDevice8_GetPixelShaderConstant(device
, 0, ret
, 1);
7046 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
7047 ok(!memcmp(ret
, initial
, sizeof(initial
)),
7048 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7049 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
7050 hr
= IDirect3DDevice8_GetPixelShaderConstant(device
, 1, ret
, 1);
7051 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
7052 ok(!memcmp(ret
, initial
, sizeof(initial
)),
7053 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7054 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
7056 hr
= IDirect3DDevice8_SetPixelShaderConstant(device
, 0, ps_const
, 1);
7057 ok(SUCCEEDED(hr
), "Failed to set pixel shader constant, hr %#x.\n", hr
);
7060 hr
= IDirect3DDevice8_BeginStateBlock(device
);
7061 ok(SUCCEEDED(hr
), "Failed to begin stateblock, hr %#x.\n", hr
);
7065 hr
= IDirect3DDevice8_SetVertexShaderConstant(device
, 1, vs_const
, 1);
7066 ok(SUCCEEDED(hr
), "Failed to set vertex shader constant, hr %#x.\n", hr
);
7070 hr
= IDirect3DDevice8_SetPixelShaderConstant(device
, 1, ps_const
, 1);
7071 ok(SUCCEEDED(hr
), "Failed to set pixel shader constant, hr %#x.\n", hr
);
7074 hr
= IDirect3DDevice8_EndStateBlock(device
, &stateblock
);
7075 ok(SUCCEEDED(hr
), "Failed to end stateblock, hr %#x.\n", hr
);
7079 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 0, ret
, 1);
7080 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7081 ok(!memcmp(ret
, vs_const
, sizeof(vs_const
)),
7082 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7083 ret
[0], ret
[1], ret
[2], ret
[3], vs_const
[0], vs_const
[1], vs_const
[2], vs_const
[3]);
7084 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 1, ret
, 1);
7085 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7086 ok(!memcmp(ret
, initial
, sizeof(initial
)),
7087 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7088 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
7092 hr
= IDirect3DDevice8_GetPixelShaderConstant(device
, 0, ret
, 1);
7093 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
7094 ok(!memcmp(ret
, ps_const
, sizeof(ps_const
)),
7095 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7096 ret
[0], ret
[1], ret
[2], ret
[3], ps_const
[0], ps_const
[1], ps_const
[2], ps_const
[3]);
7097 hr
= IDirect3DDevice8_GetPixelShaderConstant(device
, 1, ret
, 1);
7098 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
7099 ok(!memcmp(ret
, initial
, sizeof(initial
)),
7100 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7101 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
7104 /* Apply doesn't overwrite constants that aren't explicitly set on the
7105 * source stateblock. */
7106 hr
= IDirect3DDevice8_ApplyStateBlock(device
, stateblock
);
7107 ok(SUCCEEDED(hr
), "Failed to apply stateblock, hr %#x.\n", hr
);
7111 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 0, ret
, 1);
7112 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7113 ok(!memcmp(ret
, vs_const
, sizeof(vs_const
)),
7114 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7115 ret
[0], ret
[1], ret
[2], ret
[3], vs_const
[0], vs_const
[1], vs_const
[2], vs_const
[3]);
7116 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 1, ret
, 1);
7117 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7118 ok(!memcmp(ret
, vs_const
, sizeof(vs_const
)),
7119 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7120 ret
[0], ret
[1], ret
[2], ret
[3], vs_const
[0], vs_const
[1], vs_const
[2], vs_const
[3]);
7124 hr
= IDirect3DDevice8_GetPixelShaderConstant(device
, 0, ret
, 1);
7125 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
7126 ok(!memcmp(ret
, ps_const
, sizeof(ps_const
)),
7127 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7128 ret
[0], ret
[1], ret
[2], ret
[3], ps_const
[0], ps_const
[1], ps_const
[2], ps_const
[3]);
7129 hr
= IDirect3DDevice8_GetPixelShaderConstant(device
, 1, ret
, 1);
7130 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
7131 ok(!memcmp(ret
, ps_const
, sizeof(ps_const
)),
7132 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7133 ret
[0], ret
[1], ret
[2], ret
[3], ps_const
[0], ps_const
[1], ps_const
[2], ps_const
[3]);
7136 IDirect3DDevice8_DeleteStateBlock(device
, stateblock
);
7137 refcount
= IDirect3DDevice8_Release(device
);
7138 ok(!refcount
, "Device has %u references left.\n", refcount
);
7139 IDirect3D8_Release(d3d
);
7140 DestroyWindow(window
);
7143 static void test_resource_type(void)
7145 IDirect3DDevice8
*device
;
7146 IDirect3DSurface8
*surface
;
7147 IDirect3DTexture8
*texture
;
7148 IDirect3DCubeTexture8
*cube_texture
;
7149 IDirect3DVolume8
*volume
;
7150 IDirect3DVolumeTexture8
*volume_texture
;
7151 D3DSURFACE_DESC surface_desc
;
7152 D3DVOLUME_DESC volume_desc
;
7153 D3DRESOURCETYPE type
;
7160 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
7161 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
7162 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
7163 ok(!!d3d
, "Failed to create a D3D object.\n");
7164 if (!(device
= create_device(d3d
, window
, NULL
)))
7166 skip("Failed to create a D3D device, skipping tests.\n");
7167 IDirect3D8_Release(d3d
);
7168 DestroyWindow(window
);
7172 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
7173 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
7175 hr
= IDirect3DDevice8_CreateImageSurface(device
, 4, 4, D3DFMT_X8R8G8B8
, &surface
);
7176 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7177 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
7178 ok(SUCCEEDED(hr
), "Failed to get surface description, hr %#x.\n", hr
);
7179 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7181 IDirect3DSurface8_Release(surface
);
7183 hr
= IDirect3DDevice8_CreateTexture(device
, 2, 8, 4, 0, D3DFMT_X8R8G8B8
,
7184 D3DPOOL_SYSTEMMEM
, &texture
);
7185 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
7186 type
= IDirect3DTexture8_GetType(texture
);
7187 ok(type
== D3DRTYPE_TEXTURE
, "Expected type D3DRTYPE_TEXTURE, got %u.\n", type
);
7189 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &surface
);
7190 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7191 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
7192 ok(SUCCEEDED(hr
), "Failed to get surface description, hr %#x.\n", hr
);
7193 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7195 ok(surface_desc
.Width
== 2, "Expected width 2, got %u.\n", surface_desc
.Width
);
7196 ok(surface_desc
.Height
== 8, "Expected height 8, got %u.\n", surface_desc
.Height
);
7197 hr
= IDirect3DTexture8_GetLevelDesc(texture
, 0, &surface_desc
);
7198 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
7199 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7201 ok(surface_desc
.Width
== 2, "Expected width 2, got %u.\n", surface_desc
.Width
);
7202 ok(surface_desc
.Height
== 8, "Expected height 8, got %u.\n", surface_desc
.Height
);
7203 IDirect3DSurface8_Release(surface
);
7205 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 2, &surface
);
7206 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7207 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
7208 ok(SUCCEEDED(hr
), "Failed to get surface description, hr %#x.\n", hr
);
7209 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7211 ok(surface_desc
.Width
== 1, "Expected width 1, got %u.\n", surface_desc
.Width
);
7212 ok(surface_desc
.Height
== 2, "Expected height 2, got %u.\n", surface_desc
.Height
);
7213 hr
= IDirect3DTexture8_GetLevelDesc(texture
, 2, &surface_desc
);
7214 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
7215 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7217 ok(surface_desc
.Width
== 1, "Expected width 1, got %u.\n", surface_desc
.Width
);
7218 ok(surface_desc
.Height
== 2, "Expected height 2, got %u.\n", surface_desc
.Height
);
7219 IDirect3DSurface8_Release(surface
);
7220 IDirect3DTexture8_Release(texture
);
7222 if (caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
)
7224 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 1, 1, 0, D3DFMT_X8R8G8B8
,
7225 D3DPOOL_SYSTEMMEM
, &cube_texture
);
7226 ok(SUCCEEDED(hr
), "Failed to create cube texture, hr %#x.\n", hr
);
7227 type
= IDirect3DCubeTexture8_GetType(cube_texture
);
7228 ok(type
== D3DRTYPE_CUBETEXTURE
, "Expected type D3DRTYPE_CUBETEXTURE, got %u.\n", type
);
7230 hr
= IDirect3DCubeTexture8_GetCubeMapSurface(cube_texture
,
7231 D3DCUBEMAP_FACE_NEGATIVE_X
, 0, &surface
);
7232 ok(SUCCEEDED(hr
), "Failed to get cube map surface, hr %#x.\n", hr
);
7233 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
7234 ok(SUCCEEDED(hr
), "Failed to get surface description, hr %#x.\n", hr
);
7235 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7237 hr
= IDirect3DCubeTexture8_GetLevelDesc(cube_texture
, 0, &surface_desc
);
7238 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
7239 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7241 IDirect3DSurface8_Release(surface
);
7242 IDirect3DCubeTexture8_Release(cube_texture
);
7245 skip("Cube maps not supported.\n");
7247 if (caps
.TextureCaps
& D3DPTEXTURECAPS_MIPVOLUMEMAP
)
7249 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 2, 4, 8, 4, 0, D3DFMT_X8R8G8B8
,
7250 D3DPOOL_SYSTEMMEM
, &volume_texture
);
7251 ok(SUCCEEDED(hr
), "CreateVolumeTexture failed, hr %#x.\n", hr
);
7252 type
= IDirect3DVolumeTexture8_GetType(volume_texture
);
7253 ok(type
== D3DRTYPE_VOLUMETEXTURE
, "Expected type D3DRTYPE_VOLUMETEXTURE, got %u.\n", type
);
7255 hr
= IDirect3DVolumeTexture8_GetVolumeLevel(volume_texture
, 0, &volume
);
7256 ok(SUCCEEDED(hr
), "Failed to get volume level, hr %#x.\n", hr
);
7257 /* IDirect3DVolume8 is not an IDirect3DResource8 and has no GetType method. */
7258 hr
= IDirect3DVolume8_GetDesc(volume
, &volume_desc
);
7259 ok(SUCCEEDED(hr
), "Failed to get volume description, hr %#x.\n", hr
);
7260 ok(volume_desc
.Type
== D3DRTYPE_VOLUME
, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7262 ok(volume_desc
.Width
== 2, "Expected width 2, got %u.\n", volume_desc
.Width
);
7263 ok(volume_desc
.Height
== 4, "Expected height 4, got %u.\n", volume_desc
.Height
);
7264 ok(volume_desc
.Depth
== 8, "Expected depth 8, got %u.\n", volume_desc
.Depth
);
7265 hr
= IDirect3DVolumeTexture8_GetLevelDesc(volume_texture
, 0, &volume_desc
);
7266 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
7267 ok(volume_desc
.Type
== D3DRTYPE_VOLUME
, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7269 ok(volume_desc
.Width
== 2, "Expected width 2, got %u.\n", volume_desc
.Width
);
7270 ok(volume_desc
.Height
== 4, "Expected height 4, got %u.\n", volume_desc
.Height
);
7271 ok(volume_desc
.Depth
== 8, "Expected depth 8, got %u.\n", volume_desc
.Depth
);
7272 IDirect3DVolume8_Release(volume
);
7274 hr
= IDirect3DVolumeTexture8_GetVolumeLevel(volume_texture
, 2, &volume
);
7275 ok(SUCCEEDED(hr
), "Failed to get volume level, hr %#x.\n", hr
);
7276 hr
= IDirect3DVolume8_GetDesc(volume
, &volume_desc
);
7277 ok(SUCCEEDED(hr
), "Failed to get volume description, hr %#x.\n", hr
);
7278 ok(volume_desc
.Type
== D3DRTYPE_VOLUME
, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7280 ok(volume_desc
.Width
== 1, "Expected width 1, got %u.\n", volume_desc
.Width
);
7281 ok(volume_desc
.Height
== 1, "Expected height 1, got %u.\n", volume_desc
.Height
);
7282 ok(volume_desc
.Depth
== 2, "Expected depth 2, got %u.\n", volume_desc
.Depth
);
7283 hr
= IDirect3DVolumeTexture8_GetLevelDesc(volume_texture
, 2, &volume_desc
);
7284 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
7285 ok(volume_desc
.Type
== D3DRTYPE_VOLUME
, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7287 ok(volume_desc
.Width
== 1, "Expected width 1, got %u.\n", volume_desc
.Width
);
7288 ok(volume_desc
.Height
== 1, "Expected height 1, got %u.\n", volume_desc
.Height
);
7289 ok(volume_desc
.Depth
== 2, "Expected depth 2, got %u.\n", volume_desc
.Depth
);
7290 IDirect3DVolume8_Release(volume
);
7291 IDirect3DVolumeTexture8_Release(volume_texture
);
7294 skip("Mipmapped volume maps not supported.\n");
7296 refcount
= IDirect3DDevice8_Release(device
);
7297 ok(!refcount
, "Device has %u references left.\n", refcount
);
7298 IDirect3D8_Release(d3d
);
7299 DestroyWindow(window
);
7302 static void test_mipmap_lock(void)
7304 IDirect3DDevice8
*device
;
7305 IDirect3DSurface8
*surface
, *surface2
, *surface_dst
, *surface_dst2
;
7306 IDirect3DTexture8
*texture
, *texture_dst
;
7311 D3DLOCKED_RECT locked_rect
;
7313 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
7314 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
7315 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
7316 ok(!!d3d
, "Failed to create a D3D object.\n");
7317 if (!(device
= create_device(d3d
, window
, NULL
)))
7319 skip("Failed to create a D3D device, skipping tests.\n");
7320 IDirect3D8_Release(d3d
);
7321 DestroyWindow(window
);
7325 hr
= IDirect3DDevice8_CreateTexture(device
, 4, 4, 2, 0, D3DFMT_X8R8G8B8
,
7326 D3DPOOL_DEFAULT
, &texture_dst
);
7327 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
7328 hr
= IDirect3DTexture8_GetSurfaceLevel(texture_dst
, 0, &surface_dst
);
7329 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7330 hr
= IDirect3DTexture8_GetSurfaceLevel(texture_dst
, 1, &surface_dst2
);
7331 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7333 hr
= IDirect3DDevice8_CreateTexture(device
, 4, 4, 2, 0, D3DFMT_X8R8G8B8
,
7334 D3DPOOL_SYSTEMMEM
, &texture
);
7335 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
7336 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &surface
);
7337 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7338 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 1, &surface2
);
7339 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7341 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
7342 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
7343 hr
= IDirect3DSurface8_LockRect(surface2
, &locked_rect
, NULL
, 0);
7344 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
7345 hr
= IDirect3DSurface8_UnlockRect(surface
);
7346 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
7348 hr
= IDirect3DDevice8_CopyRects(device
, surface
, NULL
, 0, surface_dst
, NULL
);
7349 ok(SUCCEEDED(hr
), "Failed to update surface, hr %#x.\n", hr
);
7350 hr
= IDirect3DDevice8_CopyRects(device
, surface2
, NULL
, 0, surface_dst2
, NULL
);
7351 todo_wine
ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
7353 /* Apparently there's no validation on the container. */
7354 hr
= IDirect3DDevice8_UpdateTexture(device
, (IDirect3DBaseTexture8
*)texture
,
7355 (IDirect3DBaseTexture8
*)texture_dst
);
7356 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x.\n", hr
);
7358 hr
= IDirect3DSurface8_UnlockRect(surface2
);
7359 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
7361 IDirect3DSurface8_Release(surface_dst2
);
7362 IDirect3DSurface8_Release(surface_dst
);
7363 IDirect3DSurface8_Release(surface2
);
7364 IDirect3DSurface8_Release(surface
);
7365 IDirect3DTexture8_Release(texture_dst
);
7366 IDirect3DTexture8_Release(texture
);
7368 refcount
= IDirect3DDevice8_Release(device
);
7369 ok(!refcount
, "Device has %u references left.\n", refcount
);
7370 IDirect3D8_Release(d3d
);
7371 DestroyWindow(window
);
7374 static void test_writeonly_resource(void)
7377 IDirect3DDevice8
*device
;
7378 IDirect3DVertexBuffer8
*buffer
;
7389 {{-1.0f
, -1.0f
, 0.0f
}},
7390 {{-1.0f
, 1.0f
, 0.0f
}},
7391 {{ 1.0f
, -1.0f
, 0.0f
}},
7392 {{ 1.0f
, 1.0f
, 0.0f
}}
7395 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
7396 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
7397 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
7398 ok(!!d3d
, "Failed to create a D3D object.\n");
7399 if (!(device
= create_device(d3d
, window
, NULL
)))
7401 skip("Failed to create a D3D device, skipping tests.\n");
7402 IDirect3D8_Release(d3d
);
7403 DestroyWindow(window
);
7407 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, sizeof(quad
),
7408 D3DUSAGE_DYNAMIC
| D3DUSAGE_WRITEONLY
, 0, D3DPOOL_DEFAULT
, &buffer
);
7409 ok(SUCCEEDED(hr
), "Failed to create buffer, hr %#x.\n", hr
);
7411 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, 0, &ptr
, D3DLOCK_DISCARD
);
7412 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
7413 memcpy(ptr
, quad
, sizeof(quad
));
7414 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
7415 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
7416 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, buffer
, sizeof(*quad
));
7417 ok(SUCCEEDED(hr
), "Failed to set stream source, hr %#x.\n", hr
);
7418 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
);
7419 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
7421 hr
= IDirect3DDevice8_BeginScene(device
);
7422 ok(SUCCEEDED(hr
), "Failed to begin scene %#x\n", hr
);
7423 hr
= IDirect3DDevice8_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 0, 2);
7424 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7425 hr
= IDirect3DDevice8_EndScene(device
);
7426 ok(SUCCEEDED(hr
), "Failed to end scene %#x\n", hr
);
7428 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, 0, &ptr
, 0);
7429 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
7430 ok (!memcmp(ptr
, quad
, sizeof(quad
)), "Got unexpected vertex buffer data.\n");
7431 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
7432 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
7434 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, 0, &ptr
, D3DLOCK_READONLY
);
7435 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
7436 ok (!memcmp(ptr
, quad
, sizeof(quad
)), "Got unexpected vertex buffer data.\n");
7437 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
7438 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
7440 refcount
= IDirect3DVertexBuffer8_Release(buffer
);
7441 ok(!refcount
, "Vertex buffer has %u references left.\n", refcount
);
7442 refcount
= IDirect3DDevice8_Release(device
);
7443 ok(!refcount
, "Device has %u references left.\n", refcount
);
7444 IDirect3D8_Release(d3d
);
7445 DestroyWindow(window
);
7448 static void test_lost_device(void)
7450 struct device_desc device_desc
;
7451 IDirect3DDevice8
*device
;
7458 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
7459 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
7460 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
7461 ok(!!d3d
, "Failed to create a D3D object.\n");
7462 device_desc
.device_window
= window
;
7463 device_desc
.width
= registry_mode
.dmPelsWidth
;
7464 device_desc
.height
= registry_mode
.dmPelsHeight
;
7465 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
7466 if (!(device
= create_device(d3d
, window
, &device_desc
)))
7468 skip("Failed to create a D3D device, skipping tests.\n");
7472 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
7473 if (hr
== D3DERR_DEVICELOST
)
7475 win_skip("Broken TestCooperativeLevel(), skipping test.\n");
7476 IDirect3DDevice8_Release(device
);
7479 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7480 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
7481 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7483 ret
= SetForegroundWindow(GetDesktopWindow());
7484 ok(ret
, "Failed to set foreground window.\n");
7485 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
7486 ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
7487 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
7488 ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
7490 ret
= ShowWindow(window
, SW_RESTORE
);
7491 ok(ret
, "Failed to restore window.\n");
7492 ret
= SetForegroundWindow(window
);
7493 ok(ret
, "Failed to set foreground window.\n");
7494 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
7495 ok(hr
== D3DERR_DEVICENOTRESET
, "Got unexpected hr %#x.\n", hr
);
7496 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
7497 ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
7499 hr
= reset_device(device
, &device_desc
);
7500 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7501 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
7502 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7503 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
7504 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7506 device_desc
.flags
= 0;
7507 hr
= reset_device(device
, &device_desc
);
7508 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7509 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
7510 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7511 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
7512 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7514 ret
= SetForegroundWindow(GetDesktopWindow());
7515 ok(ret
, "Failed to set foreground window.\n");
7516 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
7517 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7518 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
7519 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7521 ret
= ShowWindow(window
, SW_RESTORE
);
7522 ok(ret
, "Failed to restore window.\n");
7523 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
7524 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7525 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
7526 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7528 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
7529 hr
= reset_device(device
, &device_desc
);
7530 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7531 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
7532 todo_wine
ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
7533 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
7534 todo_wine
ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
7536 ret
= SetForegroundWindow(GetDesktopWindow());
7537 ok(ret
, "Failed to set foreground window.\n");
7538 hr
= reset_device(device
, &device_desc
);
7539 ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
7540 ret
= ShowWindow(window
, SW_RESTORE
);
7541 ok(ret
, "Failed to restore window.\n");
7542 ret
= SetForegroundWindow(window
);
7543 ok(ret
, "Failed to set foreground window.\n");
7544 hr
= reset_device(device
, &device_desc
);
7545 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7547 refcount
= IDirect3DDevice8_Release(device
);
7548 ok(!refcount
, "Device has %u references left.\n", refcount
);
7550 IDirect3D8_Release(d3d
);
7551 DestroyWindow(window
);
7554 static void test_resource_priority(void)
7556 IDirect3DDevice8
*device
;
7557 IDirect3DTexture8
*texture
;
7558 IDirect3DVertexBuffer8
*buffer
;
7567 BOOL can_set_priority
;
7571 {D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", FALSE
},
7572 {D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", FALSE
},
7573 {D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
},
7574 {D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", FALSE
}
7579 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
7580 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
7581 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
7582 ok(!!d3d
, "Failed to create a D3D object.\n");
7583 if (!(device
= create_device(d3d
, window
, NULL
)))
7585 skip("Failed to create a D3D device, skipping tests.\n");
7586 IDirect3D8_Release(d3d
);
7587 DestroyWindow(window
);
7591 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); i
++)
7593 hr
= IDirect3DDevice8_CreateTexture(device
, 16, 16, 0, 0, D3DFMT_X8R8G8B8
,
7594 test_data
[i
].pool
, &texture
);
7595 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x, pool %s.\n", hr
, test_data
[i
].name
);
7597 priority
= IDirect3DTexture8_GetPriority(texture
);
7598 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
7599 priority
= IDirect3DTexture8_SetPriority(texture
, 1);
7600 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
7601 priority
= IDirect3DTexture8_GetPriority(texture
);
7602 if (test_data
[i
].can_set_priority
)
7604 ok(priority
== 1, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
7605 priority
= IDirect3DTexture8_SetPriority(texture
, 0);
7606 ok(priority
== 1, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
7609 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
7611 IDirect3DTexture8_Release(texture
);
7613 if (test_data
[i
].pool
!= D3DPOOL_SCRATCH
)
7615 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, 256, 0, 0,
7616 test_data
[i
].pool
, &buffer
);
7617 ok(SUCCEEDED(hr
), "Failed to create buffer, hr %#x, pool %s.\n", hr
, test_data
[i
].name
);
7619 priority
= IDirect3DVertexBuffer8_GetPriority(buffer
);
7620 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
7621 priority
= IDirect3DVertexBuffer8_SetPriority(buffer
, 1);
7622 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
7623 priority
= IDirect3DVertexBuffer8_GetPriority(buffer
);
7624 if (test_data
[i
].can_set_priority
)
7626 ok(priority
== 1, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
7627 priority
= IDirect3DVertexBuffer8_SetPriority(buffer
, 0);
7628 ok(priority
== 1, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
7631 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
7633 IDirect3DVertexBuffer8_Release(buffer
);
7637 refcount
= IDirect3DDevice8_Release(device
);
7638 ok(!refcount
, "Device has %u references left.\n", refcount
);
7639 IDirect3D8_Release(d3d
);
7640 DestroyWindow(window
);
7643 static void test_swapchain_parameters(void)
7645 IDirect3DDevice8
*device
;
7647 IDirect3DSurface8
*backbuffer
;
7651 D3DPRESENT_PARAMETERS present_parameters
, present_parameters_windowed
= {0};
7655 UINT backbuffer_count
;
7656 D3DSWAPEFFECT swap_effect
;
7661 /* Swap effect 0 is not allowed. */
7662 {TRUE
, 1, 0, D3DERR_INVALIDCALL
},
7663 {FALSE
, 1, 0, D3DERR_INVALIDCALL
},
7665 /* All (non-ex) swap effects are allowed in
7666 * windowed and fullscreen mode. */
7667 {TRUE
, 1, D3DSWAPEFFECT_DISCARD
, D3D_OK
},
7668 {TRUE
, 1, D3DSWAPEFFECT_FLIP
, D3D_OK
},
7669 {FALSE
, 1, D3DSWAPEFFECT_DISCARD
, D3D_OK
},
7670 {FALSE
, 1, D3DSWAPEFFECT_FLIP
, D3D_OK
},
7671 {FALSE
, 1, D3DSWAPEFFECT_COPY
, D3D_OK
},
7673 /* Only one backbuffer in copy mode. Reset allows it for
7675 {TRUE
, 0, D3DSWAPEFFECT_COPY
, D3D_OK
},
7676 {TRUE
, 1, D3DSWAPEFFECT_COPY
, D3D_OK
},
7677 {TRUE
, 2, D3DSWAPEFFECT_COPY
, D3DERR_INVALIDCALL
},
7678 {FALSE
, 2, D3DSWAPEFFECT_COPY
, D3DERR_INVALIDCALL
},
7679 {TRUE
, 0, D3DSWAPEFFECT_COPY_VSYNC
, D3D_OK
},
7680 {TRUE
, 1, D3DSWAPEFFECT_COPY_VSYNC
, D3D_OK
},
7681 {TRUE
, 2, D3DSWAPEFFECT_COPY_VSYNC
, D3DERR_INVALIDCALL
},
7682 {FALSE
, 2, D3DSWAPEFFECT_COPY_VSYNC
, D3DERR_INVALIDCALL
},
7684 /* Ok with the others, in fullscreen and windowed mode. */
7685 {TRUE
, 2, D3DSWAPEFFECT_DISCARD
, D3D_OK
},
7686 {TRUE
, 2, D3DSWAPEFFECT_FLIP
, D3D_OK
},
7687 {FALSE
, 2, D3DSWAPEFFECT_DISCARD
, D3D_OK
},
7688 {FALSE
, 2, D3DSWAPEFFECT_FLIP
, D3D_OK
},
7690 /* Invalid swapeffects. */
7691 {TRUE
, 1, D3DSWAPEFFECT_COPY_VSYNC
+ 1, D3DERR_INVALIDCALL
},
7692 {FALSE
, 1, D3DSWAPEFFECT_COPY_VSYNC
+ 1, D3DERR_INVALIDCALL
},
7694 /* 3 is the highest allowed backbuffer count. */
7695 {TRUE
, 3, D3DSWAPEFFECT_DISCARD
, D3D_OK
},
7696 {TRUE
, 4, D3DSWAPEFFECT_DISCARD
, D3DERR_INVALIDCALL
},
7697 {TRUE
, 4, D3DSWAPEFFECT_FLIP
, D3DERR_INVALIDCALL
},
7698 {FALSE
, 4, D3DSWAPEFFECT_DISCARD
, D3DERR_INVALIDCALL
},
7699 {FALSE
, 4, D3DSWAPEFFECT_FLIP
, D3DERR_INVALIDCALL
},
7702 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
7703 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
7704 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
7705 ok(!!d3d
, "Failed to create a D3D object.\n");
7706 if (!(device
= create_device(d3d
, window
, NULL
)))
7708 skip("Failed to create a D3D device, skipping tests.\n");
7709 IDirect3D8_Release(d3d
);
7710 DestroyWindow(window
);
7713 IDirect3DDevice8_Release(device
);
7715 present_parameters_windowed
.BackBufferWidth
= registry_mode
.dmPelsWidth
;
7716 present_parameters_windowed
.BackBufferHeight
= registry_mode
.dmPelsHeight
;
7717 present_parameters_windowed
.hDeviceWindow
= window
;
7718 present_parameters_windowed
.BackBufferFormat
= D3DFMT_X8R8G8B8
;
7719 present_parameters_windowed
.SwapEffect
= D3DSWAPEFFECT_COPY
;
7720 present_parameters_windowed
.Windowed
= TRUE
;
7721 present_parameters_windowed
.BackBufferCount
= 1;
7723 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
7725 UINT bb_count
= tests
[i
].backbuffer_count
? tests
[i
].backbuffer_count
: 1;
7727 memset(&present_parameters
, 0, sizeof(present_parameters
));
7728 present_parameters
.BackBufferWidth
= registry_mode
.dmPelsWidth
;
7729 present_parameters
.BackBufferHeight
= registry_mode
.dmPelsHeight
;
7730 present_parameters
.hDeviceWindow
= window
;
7731 present_parameters
.BackBufferFormat
= D3DFMT_X8R8G8B8
;
7733 present_parameters
.SwapEffect
= tests
[i
].swap_effect
;
7734 present_parameters
.Windowed
= tests
[i
].windowed
;
7735 present_parameters
.BackBufferCount
= tests
[i
].backbuffer_count
;
7737 hr
= IDirect3D8_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, window
,
7738 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
7739 ok(hr
== tests
[i
].hr
, "Expected hr %x, got %x, test %u.\n", tests
[i
].hr
, hr
, i
);
7742 for (j
= 0; j
< bb_count
; ++j
)
7744 hr
= IDirect3DDevice8_GetBackBuffer(device
, j
, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
7745 ok(SUCCEEDED(hr
), "Failed to get backbuffer %u, hr %#x, test %u.\n", j
, hr
, i
);
7746 IDirect3DSurface8_Release(backbuffer
);
7748 hr
= IDirect3DDevice8_GetBackBuffer(device
, j
, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
7749 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %x, test %u.\n", hr
, i
);
7751 IDirect3DDevice8_Release(device
);
7754 hr
= IDirect3D8_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, window
,
7755 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters_windowed
, &device
);
7756 ok(SUCCEEDED(hr
), "Failed to create device, hr %#x, test %u.\n", hr
, i
);
7758 memset(&present_parameters
, 0, sizeof(present_parameters
));
7759 present_parameters
.BackBufferWidth
= registry_mode
.dmPelsWidth
;
7760 present_parameters
.BackBufferHeight
= registry_mode
.dmPelsHeight
;
7761 present_parameters
.hDeviceWindow
= window
;
7762 present_parameters
.BackBufferFormat
= D3DFMT_X8R8G8B8
;
7764 present_parameters
.SwapEffect
= tests
[i
].swap_effect
;
7765 present_parameters
.Windowed
= tests
[i
].windowed
;
7766 present_parameters
.BackBufferCount
= tests
[i
].backbuffer_count
;
7768 hr
= IDirect3DDevice8_Reset(device
, &present_parameters
);
7769 ok(hr
== tests
[i
].hr
, "Expected hr %x, got %x, test %u.\n", tests
[i
].hr
, hr
, i
);
7773 hr
= IDirect3DDevice8_Reset(device
, &present_parameters_windowed
);
7774 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x, test %u.\n", hr
, i
);
7778 for (j
= 0; j
< bb_count
; ++j
)
7780 hr
= IDirect3DDevice8_GetBackBuffer(device
, j
, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
7782 todo_wine
ok(SUCCEEDED(hr
), "Failed to get backbuffer %u, hr %#x, test %u.\n", j
, hr
, i
);
7784 ok(SUCCEEDED(hr
), "Failed to get backbuffer %u, hr %#x, test %u.\n", j
, hr
, i
);
7786 IDirect3DSurface8_Release(backbuffer
);
7788 hr
= IDirect3DDevice8_GetBackBuffer(device
, j
, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
7789 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %x, test %u.\n", hr
, i
);
7791 IDirect3DDevice8_Release(device
);
7794 IDirect3D8_Release(d3d
);
7795 DestroyWindow(window
);
7800 HMODULE d3d8_handle
= LoadLibraryA( "d3d8.dll" );
7803 DEVMODEW current_mode
;
7807 skip("Could not load d3d8.dll\n");
7811 memset(¤t_mode
, 0, sizeof(current_mode
));
7812 current_mode
.dmSize
= sizeof(current_mode
);
7813 ok(EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, ¤t_mode
), "Failed to get display mode.\n");
7814 registry_mode
.dmSize
= sizeof(registry_mode
);
7815 ok(EnumDisplaySettingsW(NULL
, ENUM_REGISTRY_SETTINGS
, ®istry_mode
), "Failed to get display mode.\n");
7816 if (current_mode
.dmPelsWidth
!= registry_mode
.dmPelsWidth
7817 || current_mode
.dmPelsHeight
!= registry_mode
.dmPelsHeight
)
7819 skip("Current mode does not match registry mode, skipping test.\n");
7823 wc
.lpfnWndProc
= DefWindowProcA
;
7824 wc
.lpszClassName
= "d3d8_test_wc";
7825 RegisterClassA(&wc
);
7827 ValidateVertexShader
= (void *)GetProcAddress(d3d8_handle
, "ValidateVertexShader");
7828 ValidatePixelShader
= (void *)GetProcAddress(d3d8_handle
, "ValidatePixelShader");
7830 if (!(d3d8
= Direct3DCreate8(D3D_SDK_VERSION
)))
7832 skip("could not create D3D8\n");
7835 IDirect3D8_Release(d3d8
);
7838 test_display_formats();
7839 test_display_modes();
7840 test_shader_versions();
7843 test_mipmap_levels();
7844 test_checkdevicemultisampletype();
7853 test_ApplyStateBlock();
7854 test_render_zero_triangles();
7855 test_depth_stencil_reset();
7857 test_wndproc_windowed();
7858 test_depth_stencil_size();
7859 test_window_style();
7860 test_unsupported_shaders();
7862 test_device_window_reset();
7863 test_reset_resources();
7865 test_set_rt_vp_scissor();
7868 test_volume_get_container();
7869 test_vb_lock_flags();
7870 test_texture_stage_states();
7871 test_cube_textures();
7872 test_get_set_texture();
7873 test_image_surface_pool();
7874 test_surface_get_container();
7875 test_lockrect_invalid();
7876 test_private_data();
7877 test_surface_dimensions();
7878 test_surface_format_null();
7879 test_surface_double_unlock();
7880 test_surface_blocks();
7883 test_managed_buffer();
7884 test_npot_textures();
7885 test_volume_locking();
7886 test_update_volumetexture();
7887 test_create_rt_ds_fail();
7888 test_volume_blocks();
7889 test_lockbox_invalid();
7890 test_pixel_format();
7891 test_begin_end_state_block();
7892 test_shader_constant_apply();
7893 test_resource_type();
7895 test_writeonly_resource();
7897 test_resource_priority();
7898 test_swapchain_parameters();
7900 UnregisterClassA("d3d8_test_wc", GetModuleHandleA(NULL
));