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_invalid_multisample(void)
850 IDirect3DDevice8
*device
;
851 IDirect3DSurface8
*rt
;
858 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
859 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
860 ok(!!window
, "Failed to create a window.\n");
861 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
862 ok(!!d3d
, "Failed to create a D3D object.\n");
864 if (!(device
= create_device(d3d
, window
, NULL
)))
866 skip("Failed to create a 3D device, skipping test.\n");
870 available
= SUCCEEDED(IDirect3D8_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
871 D3DFMT_X8R8G8B8
, TRUE
, D3DMULTISAMPLE_2_SAMPLES
));
873 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 128, 128,
874 D3DFMT_X8R8G8B8
, D3DMULTISAMPLE_2_SAMPLES
, FALSE
, &rt
);
877 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
878 IDirect3DSurface8_Release(rt
);
882 ok(hr
== D3DERR_NOTAVAILABLE
, "Got unexpected hr %#x.\n", hr
);
885 /* We assume D3DMULTISAMPLE_15_SAMPLES is never supported in practice. */
886 available
= SUCCEEDED(IDirect3D8_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
887 D3DFMT_X8R8G8B8
, TRUE
, D3DMULTISAMPLE_15_SAMPLES
));
888 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 128, 128,
889 D3DFMT_X8R8G8B8
, D3DMULTISAMPLE_15_SAMPLES
, FALSE
, &rt
);
892 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
893 IDirect3DSurface8_Release(rt
);
897 ok(hr
== D3DERR_NOTAVAILABLE
, "Got unexpected hr %#x.\n", hr
);
900 refcount
= IDirect3DDevice8_Release(device
);
901 ok(!refcount
, "Device has %u references left.\n", refcount
);
903 IDirect3D8_Release(d3d
);
904 DestroyWindow(window
);
907 static void test_cursor(void)
909 HMODULE user32_handle
= GetModuleHandleA("user32.dll");
910 IDirect3DSurface8
*cursor
= NULL
;
911 IDirect3DDevice8
*device
;
920 pGetCursorInfo
= (void *)GetProcAddress(user32_handle
, "GetCursorInfo");
923 win_skip("GetCursorInfo is not available\n");
927 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
928 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
929 ok(!!window
, "Failed to create a window.\n");
931 ret
= SetCursorPos(50, 50);
932 ok(ret
, "Failed to set cursor position.\n");
935 memset(&info
, 0, sizeof(info
));
936 info
.cbSize
= sizeof(info
);
937 ok(pGetCursorInfo(&info
), "GetCursorInfo failed\n");
940 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
941 ok(!!d3d
, "Failed to create a D3D object.\n");
942 if (!(device
= create_device(d3d
, window
, NULL
)))
944 skip("Failed to create a 3D device, skipping test.\n");
948 hr
= IDirect3DDevice8_CreateImageSurface(device
, 32, 32, D3DFMT_A8R8G8B8
, &cursor
);
949 ok(SUCCEEDED(hr
), "Failed to create cursor surface, hr %#x.\n", hr
);
951 /* Initially hidden */
952 ret
= IDirect3DDevice8_ShowCursor(device
, TRUE
);
953 ok(!ret
, "IDirect3DDevice8_ShowCursor returned %d\n", ret
);
955 /* Not enabled without a surface*/
956 ret
= IDirect3DDevice8_ShowCursor(device
, TRUE
);
957 ok(!ret
, "IDirect3DDevice8_ShowCursor returned %d\n", ret
);
960 hr
= IDirect3DDevice8_SetCursorProperties(device
, 0, 0, NULL
);
961 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr
);
963 hr
= IDirect3DDevice8_SetCursorProperties(device
, 0, 0, cursor
);
964 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr
);
966 IDirect3DSurface8_Release(cursor
);
968 memset(&info
, 0, sizeof(info
));
969 info
.cbSize
= sizeof(info
);
970 ok(pGetCursorInfo(&info
), "GetCursorInfo failed\n");
971 ok(info
.flags
& (CURSOR_SHOWING
|CURSOR_SUPPRESSED
), "The gdi cursor is hidden (%08x)\n", info
.flags
);
972 ok(info
.hCursor
== cur
, "The cursor handle is %p\n", info
.hCursor
); /* unchanged */
975 ret
= IDirect3DDevice8_ShowCursor(device
, TRUE
);
976 ok(!ret
, "IDirect3DDevice8_ShowCursor returned %d\n", ret
);
979 ret
= IDirect3DDevice8_ShowCursor(device
, TRUE
);
980 ok(ret
, "IDirect3DDevice8_ShowCursor returned %d\n", ret
);
982 memset(&info
, 0, sizeof(info
));
983 info
.cbSize
= sizeof(info
);
984 ok(pGetCursorInfo(&info
), "GetCursorInfo failed\n");
985 ok(info
.flags
& (CURSOR_SHOWING
|CURSOR_SUPPRESSED
), "The gdi cursor is hidden (%08x)\n", info
.flags
);
986 ok(info
.hCursor
!= cur
, "The cursor handle is %p\n", info
.hCursor
);
988 refcount
= IDirect3DDevice8_Release(device
);
989 ok(!refcount
, "Device has %u references left.\n", refcount
);
991 IDirect3D8_Release(d3d
);
992 DestroyWindow(window
);
995 static const POINT
*expect_pos
;
997 static LRESULT CALLBACK
test_cursor_proc(HWND window
, UINT message
, WPARAM wparam
, LPARAM lparam
)
999 if (message
== WM_MOUSEMOVE
)
1001 if (expect_pos
&& expect_pos
->x
&& expect_pos
->y
)
1003 POINT p
= {GET_X_LPARAM(lparam
), GET_Y_LPARAM(lparam
)};
1005 ClientToScreen(window
, &p
);
1006 if (expect_pos
->x
== p
.x
&& expect_pos
->y
== p
.y
)
1011 return DefWindowProcA(window
, message
, wparam
, lparam
);
1014 static void test_cursor_pos(void)
1016 IDirect3DSurface8
*cursor
;
1017 IDirect3DDevice8
*device
;
1025 /* Note that we don't check for movement we're not supposed to receive.
1026 * That's because it's hard to distinguish from the user accidentally
1027 * moving the mouse. */
1028 static const POINT points
[] =
1041 wc
.lpfnWndProc
= test_cursor_proc
;
1042 wc
.lpszClassName
= "d3d8_test_cursor_wc";
1043 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
1044 window
= CreateWindowA("d3d8_test_cursor_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
1045 0, 0, 320, 240, NULL
, NULL
, NULL
, NULL
);
1046 ShowWindow(window
, SW_SHOW
);
1047 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
1048 ok(!!d3d8
, "Failed to create a D3D object.\n");
1050 if (!(device
= create_device(d3d8
, window
, NULL
)))
1052 skip("Failed to create a D3D device, skipping tests.\n");
1056 hr
= IDirect3DDevice8_CreateImageSurface(device
, 32, 32, D3DFMT_A8R8G8B8
, &cursor
);
1057 ok(SUCCEEDED(hr
), "Failed to create cursor surface, hr %#x.\n", hr
);
1058 hr
= IDirect3DDevice8_SetCursorProperties(device
, 0, 0, cursor
);
1059 ok(SUCCEEDED(hr
), "Failed to set cursor properties, hr %#x.\n", hr
);
1060 IDirect3DSurface8_Release(cursor
);
1061 ret
= IDirect3DDevice8_ShowCursor(device
, TRUE
);
1062 ok(!ret
, "Failed to show cursor, hr %#x.\n", ret
);
1065 expect_pos
= points
;
1067 ret
= SetCursorPos(50, 50);
1068 ok(ret
, "Failed to set cursor position.\n");
1071 IDirect3DDevice8_SetCursorPosition(device
, 75, 75, 0);
1073 /* SetCursorPosition() eats duplicates. */
1074 IDirect3DDevice8_SetCursorPosition(device
, 75, 75, 0);
1077 ret
= SetCursorPos(100, 100);
1078 ok(ret
, "Failed to set cursor position.\n");
1080 /* Even if the position was set with SetCursorPos(). */
1081 IDirect3DDevice8_SetCursorPosition(device
, 100, 100, 0);
1084 IDirect3DDevice8_SetCursorPosition(device
, 125, 125, 0);
1086 ret
= SetCursorPos(150, 150);
1087 ok(ret
, "Failed to set cursor position.\n");
1089 IDirect3DDevice8_SetCursorPosition(device
, 125, 125, 0);
1092 IDirect3DDevice8_SetCursorPosition(device
, 150, 150, 0);
1094 /* SetCursorPos() doesn't. */
1095 ret
= SetCursorPos(150, 150);
1096 ok(ret
, "Failed to set cursor position.\n");
1099 ok(!expect_pos
->x
&& !expect_pos
->y
, "Didn't receive MOUSEMOVE %u (%d, %d).\n",
1100 (unsigned)(expect_pos
- points
), expect_pos
->x
, expect_pos
->y
);
1102 refcount
= IDirect3DDevice8_Release(device
);
1103 ok(!refcount
, "Device has %u references left.\n", refcount
);
1105 DestroyWindow(window
);
1106 UnregisterClassA("d3d8_test_cursor_wc", GetModuleHandleA(NULL
));
1107 IDirect3D8_Release(d3d8
);
1110 static void test_states(void)
1112 IDirect3DDevice8
*device
;
1118 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
1119 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
1120 ok(!!window
, "Failed to create a window.\n");
1121 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
1122 ok(!!d3d
, "Failed to create a D3D object.\n");
1123 if (!(device
= create_device(d3d
, window
, NULL
)))
1125 skip("Failed to create a 3D device, skipping test.\n");
1129 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZVISIBLE
, TRUE
);
1130 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, TRUE) returned %#08x\n", hr
);
1131 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZVISIBLE
, FALSE
);
1132 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, FALSE) returned %#08x\n", hr
);
1134 refcount
= IDirect3DDevice8_Release(device
);
1135 ok(!refcount
, "Device has %u references left.\n", refcount
);
1137 IDirect3D8_Release(d3d
);
1138 DestroyWindow(window
);
1141 static void test_shader_versions(void)
1147 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
1148 ok(!!d3d
, "Failed to create a D3D object.\n");
1150 hr
= IDirect3D8_GetDeviceCaps(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, &caps
);
1151 ok(SUCCEEDED(hr
) || hr
== D3DERR_NOTAVAILABLE
, "Failed to get device caps, hr %#x.\n", hr
);
1152 IDirect3D8_Release(d3d
);
1155 skip("No Direct3D support, skipping test.\n");
1159 ok(caps
.VertexShaderVersion
<= D3DVS_VERSION(1,1),
1160 "Got unexpected VertexShaderVersion %#x.\n", caps
.VertexShaderVersion
);
1161 ok(caps
.PixelShaderVersion
<= D3DPS_VERSION(1,4),
1162 "Got unexpected PixelShaderVersion %#x.\n", caps
.PixelShaderVersion
);
1165 static void test_display_formats(void)
1167 D3DDEVTYPE device_type
= D3DDEVTYPE_HAL
;
1168 unsigned int backbuffer
, display
;
1169 unsigned int windowed
, i
;
1170 D3DDISPLAYMODE mode
;
1180 D3DFORMAT alpha_format
;
1186 {"D3DFMT_R5G6B5", D3DFMT_R5G6B5
, 0, TRUE
, TRUE
},
1187 {"D3DFMT_X1R5G5B5", D3DFMT_X1R5G5B5
, D3DFMT_A1R5G5B5
, TRUE
, TRUE
},
1188 {"D3DFMT_A1R5G5B5", D3DFMT_A1R5G5B5
, D3DFMT_A1R5G5B5
, FALSE
, FALSE
},
1189 {"D3DFMT_X8R8G8B8", D3DFMT_X8R8G8B8
, D3DFMT_A8R8G8B8
, TRUE
, TRUE
},
1190 {"D3DFMT_A8R8G8B8", D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
, FALSE
, FALSE
},
1191 {"D3DFMT_UNKNOWN", D3DFMT_UNKNOWN
, 0, FALSE
, FALSE
},
1194 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
1195 ok(!!d3d8
, "Failed to create a D3D object.\n");
1197 for (display
= 0; display
< sizeof(formats
) / sizeof(*formats
); ++display
)
1199 for (i
= 0, has_modes
= FALSE
; SUCCEEDED(IDirect3D8_EnumAdapterModes(d3d8
, D3DADAPTER_DEFAULT
, i
, &mode
)); ++i
)
1201 if (mode
.Format
== formats
[display
].format
)
1208 for (windowed
= 0; windowed
<= 1; ++windowed
)
1210 for (backbuffer
= 0; backbuffer
< sizeof(formats
) / sizeof(*formats
); ++backbuffer
)
1212 should_pass
= FALSE
;
1214 if (formats
[display
].display
&& (formats
[display
].windowed
|| !windowed
) && (has_modes
|| windowed
))
1216 D3DFORMAT backbuffer_format
;
1218 if (windowed
&& formats
[backbuffer
].format
== D3DFMT_UNKNOWN
)
1219 backbuffer_format
= formats
[display
].format
;
1221 backbuffer_format
= formats
[backbuffer
].format
;
1223 hr
= IDirect3D8_CheckDeviceFormat(d3d8
, D3DADAPTER_DEFAULT
, device_type
, formats
[display
].format
,
1224 D3DUSAGE_RENDERTARGET
, D3DRTYPE_SURFACE
, backbuffer_format
);
1225 should_pass
= (hr
== D3D_OK
) && (formats
[display
].format
== formats
[backbuffer
].format
1226 || (formats
[display
].alpha_format
1227 && formats
[display
].alpha_format
== formats
[backbuffer
].alpha_format
));
1230 hr
= IDirect3D8_CheckDeviceType(d3d8
, D3DADAPTER_DEFAULT
, device_type
,
1231 formats
[display
].format
, formats
[backbuffer
].format
, windowed
);
1232 ok(SUCCEEDED(hr
) == should_pass
|| broken(SUCCEEDED(hr
) && !has_modes
) /* Win8 64-bit */,
1233 "Got unexpected hr %#x for %s / %s, windowed %#x, should_pass %#x.\n",
1234 hr
, formats
[display
].name
, formats
[backbuffer
].name
, windowed
, should_pass
);
1239 IDirect3D8_Release(d3d8
);
1242 /* Test adapter display modes */
1243 static void test_display_modes(void)
1246 D3DDISPLAYMODE dmode
;
1250 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
1251 ok(!!d3d
, "Failed to create a D3D object.\n");
1253 max_modes
= IDirect3D8_GetAdapterModeCount(d3d
, D3DADAPTER_DEFAULT
);
1255 broken(max_modes
== 0), /* VMware */
1256 "GetAdapterModeCount(D3DADAPTER_DEFAULT) returned 0!\n");
1258 for (i
= 0; i
< max_modes
; ++i
)
1260 res
= IDirect3D8_EnumAdapterModes(d3d
, D3DADAPTER_DEFAULT
, i
, &dmode
);
1261 ok(res
==D3D_OK
, "EnumAdapterModes returned %#08x for mode %u!\n", res
, i
);
1265 ok(dmode
.Format
==D3DFMT_X8R8G8B8
|| dmode
.Format
==D3DFMT_R5G6B5
,
1266 "Unexpected display mode returned for mode %u: %#x\n", i
, dmode
.Format
);
1269 IDirect3D8_Release(d3d
);
1272 static void test_reset(void)
1274 UINT width
, orig_width
= GetSystemMetrics(SM_CXSCREEN
);
1275 UINT height
, orig_height
= GetSystemMetrics(SM_CYSCREEN
);
1276 IDirect3DDevice8
*device1
= NULL
;
1277 IDirect3DDevice8
*device2
= NULL
;
1278 struct device_desc device_desc
;
1279 D3DDISPLAYMODE d3ddm
, d3ddm2
;
1280 D3DSURFACE_DESC surface_desc
;
1281 D3DPRESENT_PARAMETERS d3dpp
;
1282 IDirect3DSurface8
*surface
;
1283 IDirect3DTexture8
*texture
;
1284 UINT adapter_mode_count
;
1285 D3DLOCKED_RECT lockrect
;
1286 UINT mode_count
= 0;
1297 static const DWORD decl
[] =
1300 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT4
),
1310 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
1311 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1312 ok(!!window
, "Failed to create a window.\n");
1313 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
1314 ok(!!d3d8
, "Failed to create a D3D object.\n");
1316 hr
= IDirect3D8_GetAdapterDisplayMode(d3d8
, D3DADAPTER_DEFAULT
, &d3ddm
);
1317 ok(SUCCEEDED(hr
), "GetAdapterDisplayMode failed, hr %#x.\n", hr
);
1318 adapter_mode_count
= IDirect3D8_GetAdapterModeCount(d3d8
, D3DADAPTER_DEFAULT
);
1319 modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(*modes
) * adapter_mode_count
);
1320 for (i
= 0; i
< adapter_mode_count
; ++i
)
1324 memset(&d3ddm2
, 0, sizeof(d3ddm2
));
1325 hr
= IDirect3D8_EnumAdapterModes(d3d8
, D3DADAPTER_DEFAULT
, i
, &d3ddm2
);
1326 ok(SUCCEEDED(hr
), "EnumAdapterModes failed, hr %#x.\n", hr
);
1328 if (d3ddm2
.Format
!= d3ddm
.Format
)
1331 for (j
= 0; j
< mode_count
; ++j
)
1333 if (modes
[j
].w
== d3ddm2
.Width
&& modes
[j
].h
== d3ddm2
.Height
)
1336 if (j
== mode_count
)
1338 modes
[j
].w
= d3ddm2
.Width
;
1339 modes
[j
].h
= d3ddm2
.Height
;
1343 /* We use them as invalid modes. */
1344 if ((d3ddm2
.Width
== 801 && d3ddm2
.Height
== 600)
1345 || (d3ddm2
.Width
== 32 && d3ddm2
.Height
== 32))
1347 skip("This system supports a screen resolution of %dx%d, not running mode tests.\n",
1348 d3ddm2
.Width
, d3ddm2
.Height
);
1355 skip("Less than 2 modes supported, skipping mode tests.\n");
1360 if (modes
[i
].w
== orig_width
&& modes
[i
].h
== orig_height
) ++i
;
1362 device_desc
.width
= modes
[i
].w
;
1363 device_desc
.height
= modes
[i
].h
;
1364 device_desc
.device_window
= window
;
1365 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
| CREATE_DEVICE_SWVP_ONLY
;
1366 if (!(device1
= create_device(d3d8
, window
, &device_desc
)))
1368 skip("Failed to create a D3D device, skipping tests.\n");
1371 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1372 /* This skips the test on testbot Win 8 VMs. */
1373 if (hr
== D3DERR_DEVICELOST
)
1375 skip("Device is lost.\n");
1378 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1380 hr
= IDirect3DDevice8_GetDeviceCaps(device1
, &caps
);
1381 ok(SUCCEEDED(hr
), "GetDeviceCaps failed, hr %#x.\n", hr
);
1383 width
= GetSystemMetrics(SM_CXSCREEN
);
1384 height
= GetSystemMetrics(SM_CYSCREEN
);
1385 ok(width
== modes
[i
].w
, "Screen width is %u, expected %u.\n", width
, modes
[i
].w
);
1386 ok(height
== modes
[i
].h
, "Screen height is %u, expected %u.\n", height
, modes
[i
].h
);
1388 hr
= IDirect3DDevice8_GetViewport(device1
, &vp
);
1389 ok(SUCCEEDED(hr
), "GetViewport failed, hr %#x.\n", hr
);
1392 ok(vp
.X
== 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp
.X
);
1393 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp
.Y
);
1394 ok(vp
.Width
== modes
[i
].w
, "D3DVIEWPORT->Width = %u, expected %u.\n", vp
.Width
, modes
[i
].w
);
1395 ok(vp
.Height
== modes
[i
].h
, "D3DVIEWPORT->Height = %u, expected %u.\n", vp
.Height
, modes
[i
].h
);
1396 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp
.MinZ
);
1397 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp
.MaxZ
);
1403 vp
.Width
= modes
[i
].w
/ 2;
1404 vp
.Height
= modes
[i
].h
/ 2;
1407 hr
= IDirect3DDevice8_SetViewport(device1
, &vp
);
1408 ok(SUCCEEDED(hr
), "SetViewport failed, hr %#x.\n", hr
);
1410 hr
= IDirect3DDevice8_GetRenderState(device1
, D3DRS_LIGHTING
, &value
);
1411 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1412 ok(!!value
, "Got unexpected value %#x for D3DRS_LIGHTING.\n", value
);
1413 hr
= IDirect3DDevice8_SetRenderState(device1
, D3DRS_LIGHTING
, FALSE
);
1414 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
1416 memset(&d3dpp
, 0, sizeof(d3dpp
));
1417 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1418 d3dpp
.Windowed
= FALSE
;
1419 d3dpp
.BackBufferWidth
= modes
[i
].w
;
1420 d3dpp
.BackBufferHeight
= modes
[i
].h
;
1421 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1422 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1423 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1424 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1425 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1427 hr
= IDirect3DDevice8_GetRenderState(device1
, D3DRS_LIGHTING
, &value
);
1428 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1429 ok(!!value
, "Got unexpected value %#x for D3DRS_LIGHTING.\n", value
);
1431 memset(&vp
, 0, sizeof(vp
));
1432 hr
= IDirect3DDevice8_GetViewport(device1
, &vp
);
1433 ok(SUCCEEDED(hr
), "GetViewport failed, hr %#x.\n", hr
);
1436 ok(vp
.X
== 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp
.X
);
1437 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp
.Y
);
1438 ok(vp
.Width
== modes
[i
].w
, "D3DVIEWPORT->Width = %u, expected %u.\n", vp
.Width
, modes
[i
].w
);
1439 ok(vp
.Height
== modes
[i
].h
, "D3DVIEWPORT->Height = %u, expected %u.\n", vp
.Height
, modes
[i
].h
);
1440 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp
.MinZ
);
1441 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp
.MaxZ
);
1444 width
= GetSystemMetrics(SM_CXSCREEN
);
1445 height
= GetSystemMetrics(SM_CYSCREEN
);
1446 ok(width
== modes
[i
].w
, "Screen width is %u, expected %u.\n", width
, modes
[i
].w
);
1447 ok(height
== modes
[i
].h
, "Screen height is %u, expected %u.\n", height
, modes
[i
].h
);
1449 hr
= IDirect3DDevice8_GetRenderTarget(device1
, &surface
);
1450 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
1451 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
1452 ok(hr
== D3D_OK
, "GetDesc failed, hr %#x.\n", hr
);
1453 ok(surface_desc
.Width
== modes
[i
].w
, "Back buffer width is %u, expected %u.\n",
1454 surface_desc
.Width
, modes
[i
].w
);
1455 ok(surface_desc
.Height
== modes
[i
].h
, "Back buffer height is %u, expected %u.\n",
1456 surface_desc
.Height
, modes
[i
].h
);
1457 IDirect3DSurface8_Release(surface
);
1459 memset(&d3dpp
, 0, sizeof(d3dpp
));
1460 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1461 d3dpp
.Windowed
= TRUE
;
1462 d3dpp
.BackBufferWidth
= 400;
1463 d3dpp
.BackBufferHeight
= 300;
1464 d3dpp
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
1465 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1466 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1467 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1468 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1470 memset(&vp
, 0, sizeof(vp
));
1471 hr
= IDirect3DDevice8_GetViewport(device1
, &vp
);
1472 ok(SUCCEEDED(hr
), "GetViewport failed, hr %#x.\n", hr
);
1475 ok(vp
.X
== 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp
.X
);
1476 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp
.Y
);
1477 ok(vp
.Width
== 400, "D3DVIEWPORT->Width = %u, expected 400.\n", vp
.Width
);
1478 ok(vp
.Height
== 300, "D3DVIEWPORT->Height = %u, expected 300.\n", vp
.Height
);
1479 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp
.MinZ
);
1480 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp
.MaxZ
);
1483 width
= GetSystemMetrics(SM_CXSCREEN
);
1484 height
= GetSystemMetrics(SM_CYSCREEN
);
1485 ok(width
== orig_width
, "Screen width is %u, expected %u.\n", width
, orig_width
);
1486 ok(height
== orig_height
, "Screen height is %u, expected %u.\n", height
, orig_height
);
1488 hr
= IDirect3DDevice8_GetRenderTarget(device1
, &surface
);
1489 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
1490 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
1491 ok(hr
== D3D_OK
, "GetDesc failed, hr %#x.\n", hr
);
1492 ok(surface_desc
.Width
== 400, "Back buffer width is %u, expected 400.\n",
1493 surface_desc
.Width
);
1494 ok(surface_desc
.Height
== 300, "Back buffer height is %u, expected 300.\n",
1495 surface_desc
.Height
);
1496 IDirect3DSurface8_Release(surface
);
1500 winrect
.right
= 200;
1501 winrect
.bottom
= 150;
1502 ok(AdjustWindowRect(&winrect
, WS_OVERLAPPEDWINDOW
, FALSE
), "AdjustWindowRect failed\n");
1503 ok(SetWindowPos(window
, NULL
, 0, 0,
1504 winrect
.right
-winrect
.left
,
1505 winrect
.bottom
-winrect
.top
,
1506 SWP_NOMOVE
|SWP_NOZORDER
),
1507 "SetWindowPos failed\n");
1509 memset(&d3dpp
, 0, sizeof(d3dpp
));
1510 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1511 d3dpp
.Windowed
= TRUE
;
1512 d3dpp
.BackBufferWidth
= 0;
1513 d3dpp
.BackBufferHeight
= 0;
1514 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1515 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1516 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1517 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1518 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1520 ok(!d3dpp
.BackBufferWidth
, "Got unexpected BackBufferWidth %u.\n", d3dpp
.BackBufferWidth
);
1521 ok(!d3dpp
.BackBufferHeight
, "Got unexpected BackBufferHeight %u.\n", d3dpp
.BackBufferHeight
);
1522 ok(d3dpp
.BackBufferFormat
== d3ddm
.Format
, "Got unexpected BackBufferFormat %#x, expected %#x.\n",
1523 d3dpp
.BackBufferFormat
, d3ddm
.Format
);
1524 ok(d3dpp
.BackBufferCount
== 1, "Got unexpected BackBufferCount %u.\n", d3dpp
.BackBufferCount
);
1525 ok(!d3dpp
.MultiSampleType
, "Got unexpected MultiSampleType %u.\n", d3dpp
.MultiSampleType
);
1526 ok(d3dpp
.SwapEffect
== D3DSWAPEFFECT_DISCARD
, "Got unexpected SwapEffect %#x.\n", d3dpp
.SwapEffect
);
1527 ok(!d3dpp
.hDeviceWindow
, "Got unexpected hDeviceWindow %p.\n", d3dpp
.hDeviceWindow
);
1528 ok(d3dpp
.Windowed
, "Got unexpected Windowed %#x.\n", d3dpp
.Windowed
);
1529 ok(!d3dpp
.EnableAutoDepthStencil
, "Got unexpected EnableAutoDepthStencil %#x.\n", d3dpp
.EnableAutoDepthStencil
);
1530 ok(!d3dpp
.AutoDepthStencilFormat
, "Got unexpected AutoDepthStencilFormat %#x.\n", d3dpp
.AutoDepthStencilFormat
);
1531 ok(!d3dpp
.Flags
, "Got unexpected Flags %#x.\n", d3dpp
.Flags
);
1532 ok(!d3dpp
.FullScreen_RefreshRateInHz
, "Got unexpected FullScreen_RefreshRateInHz %u.\n",
1533 d3dpp
.FullScreen_RefreshRateInHz
);
1534 ok(!d3dpp
.FullScreen_PresentationInterval
, "Got unexpected FullScreen_PresentationInterval %#x.\n",
1535 d3dpp
.FullScreen_PresentationInterval
);
1537 memset(&vp
, 0, sizeof(vp
));
1538 hr
= IDirect3DDevice8_GetViewport(device1
, &vp
);
1539 ok(SUCCEEDED(hr
), "GetViewport failed, hr %#x.\n", hr
);
1542 ok(vp
.X
== 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp
.X
);
1543 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp
.Y
);
1544 ok(vp
.Width
== 200, "D3DVIEWPORT->Width = %u, expected 200.\n", vp
.Width
);
1545 ok(vp
.Height
== 150, "D3DVIEWPORT->Height = %u, expected 150.\n", vp
.Height
);
1546 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp
.MinZ
);
1547 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp
.MaxZ
);
1550 hr
= IDirect3DDevice8_GetRenderTarget(device1
, &surface
);
1551 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
1552 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
1553 ok(hr
== D3D_OK
, "GetDesc failed, hr %#x.\n", hr
);
1554 ok(surface_desc
.Format
== d3ddm
.Format
, "Got unexpected Format %#x, expected %#x.\n",
1555 surface_desc
.Format
, d3ddm
.Format
);
1556 ok(!surface_desc
.MultiSampleType
, "Got unexpected MultiSampleType %u.\n", d3dpp
.MultiSampleType
);
1557 ok(surface_desc
.Width
== 200, "Back buffer width is %u, expected 200.\n", surface_desc
.Width
);
1558 ok(surface_desc
.Height
== 150, "Back buffer height is %u, expected 150.\n", surface_desc
.Height
);
1559 IDirect3DSurface8_Release(surface
);
1561 memset(&d3dpp
, 0, sizeof(d3dpp
));
1562 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1563 d3dpp
.Windowed
= TRUE
;
1564 d3dpp
.BackBufferWidth
= 400;
1565 d3dpp
.BackBufferHeight
= 300;
1566 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1568 /* Reset fails if there is a resource in the default pool. */
1569 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_DEFAULT
, &texture
);
1570 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
1571 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1572 ok(hr
== D3DERR_DEVICELOST
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_DEVICELOST
);
1573 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1574 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n", hr
, D3DERR_DEVICENOTRESET
);
1575 IDirect3DTexture8_Release(texture
);
1576 /* Reset again to get the device out of the lost state. */
1577 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1578 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1579 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1580 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1582 if (caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
)
1584 IDirect3DVolumeTexture8
*volume_texture
;
1586 hr
= IDirect3DDevice8_CreateVolumeTexture(device1
, 16, 16, 4, 1, 0,
1587 D3DFMT_R5G6B5
, D3DPOOL_DEFAULT
, &volume_texture
);
1588 ok(SUCCEEDED(hr
), "CreateVolumeTexture failed, hr %#x.\n", hr
);
1589 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1590 ok(hr
== D3DERR_DEVICELOST
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
1591 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1592 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n",
1593 hr
, D3DERR_DEVICENOTRESET
);
1594 IDirect3DVolumeTexture8_Release(volume_texture
);
1595 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1596 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1597 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1598 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1602 skip("Volume textures not supported.\n");
1605 /* Scratch, sysmem and managed pool resources are fine. */
1606 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_SCRATCH
, &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 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_SYSTEMMEM
, &texture
);
1615 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
1616 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1617 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1618 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1619 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1620 IDirect3DTexture8_Release(texture
);
1622 /* The depth stencil should get reset to the auto depth stencil when present. */
1623 hr
= IDirect3DDevice8_SetRenderTarget(device1
, NULL
, NULL
);
1624 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
1626 hr
= IDirect3DDevice8_GetDepthStencilSurface(device1
, &surface
);
1627 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned %#x, expected %#x.\n", hr
, D3DERR_NOTFOUND
);
1628 ok(!surface
, "Depth / stencil buffer should be NULL.\n");
1630 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1631 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1632 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1633 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1635 hr
= IDirect3DDevice8_GetDepthStencilSurface(device1
, &surface
);
1636 ok(SUCCEEDED(hr
), "GetDepthStencilSurface failed, hr %#x.\n", hr
);
1637 ok(!!surface
, "Depth / stencil buffer should not be NULL.\n");
1638 if (surface
) IDirect3DSurface8_Release(surface
);
1640 d3dpp
.EnableAutoDepthStencil
= FALSE
;
1641 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1642 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1644 hr
= IDirect3DDevice8_GetDepthStencilSurface(device1
, &surface
);
1645 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned %#x, expected %#x.\n", hr
, D3DERR_NOTFOUND
);
1646 ok(!surface
, "Depth / stencil buffer should be NULL.\n");
1648 /* Will a sysmem or scratch resource survive while locked? */
1649 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_SYSTEMMEM
, &texture
);
1650 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
1651 hr
= IDirect3DTexture8_LockRect(texture
, 0, &lockrect
, NULL
, D3DLOCK_DISCARD
);
1652 ok(SUCCEEDED(hr
), "LockRect failed, hr %#x.\n", hr
);
1653 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1654 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1655 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1656 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1657 IDirect3DTexture8_UnlockRect(texture
, 0);
1658 IDirect3DTexture8_Release(texture
);
1660 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_SCRATCH
, &texture
);
1661 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
1662 hr
= IDirect3DTexture8_LockRect(texture
, 0, &lockrect
, NULL
, D3DLOCK_DISCARD
);
1663 ok(SUCCEEDED(hr
), "LockRect failed, hr %#x.\n", hr
);
1664 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1665 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1666 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1667 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1668 IDirect3DTexture8_UnlockRect(texture
, 0);
1669 IDirect3DTexture8_Release(texture
);
1671 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_MANAGED
, &texture
);
1672 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
1673 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1674 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1675 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1676 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1677 IDirect3DTexture8_Release(texture
);
1679 /* A reference held to an implicit surface causes failures as well. */
1680 hr
= IDirect3DDevice8_GetBackBuffer(device1
, 0, D3DBACKBUFFER_TYPE_MONO
, &surface
);
1681 ok(SUCCEEDED(hr
), "GetBackBuffer failed, hr %#x.\n", hr
);
1682 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1683 ok(hr
== D3DERR_DEVICELOST
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_DEVICELOST
);
1684 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1685 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n", hr
, D3DERR_DEVICENOTRESET
);
1686 IDirect3DSurface8_Release(surface
);
1687 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1688 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1689 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1690 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1692 /* Shaders are fine as well. */
1693 hr
= IDirect3DDevice8_CreateVertexShader(device1
, decl
, simple_vs
, &shader
, 0);
1694 ok(SUCCEEDED(hr
), "CreateVertexShader failed, hr %#x.\n", hr
);
1695 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1696 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1697 hr
= IDirect3DDevice8_DeleteVertexShader(device1
, shader
);
1698 ok(SUCCEEDED(hr
), "DeleteVertexShader failed, hr %#x.\n", hr
);
1700 /* Try setting invalid modes. */
1701 memset(&d3dpp
, 0, sizeof(d3dpp
));
1702 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1703 d3dpp
.Windowed
= FALSE
;
1704 d3dpp
.BackBufferWidth
= 32;
1705 d3dpp
.BackBufferHeight
= 32;
1706 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1707 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1708 ok(hr
== D3DERR_INVALIDCALL
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
1709 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1710 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n", hr
, D3DERR_DEVICENOTRESET
);
1712 memset(&d3dpp
, 0, sizeof(d3dpp
));
1713 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1714 d3dpp
.Windowed
= FALSE
;
1715 d3dpp
.BackBufferWidth
= 801;
1716 d3dpp
.BackBufferHeight
= 600;
1717 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1718 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1719 ok(hr
== D3DERR_INVALIDCALL
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
1720 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1721 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n", hr
, D3DERR_DEVICENOTRESET
);
1723 memset(&d3dpp
, 0, sizeof(d3dpp
));
1724 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1725 d3dpp
.Windowed
= FALSE
;
1726 d3dpp
.BackBufferWidth
= 0;
1727 d3dpp
.BackBufferHeight
= 0;
1728 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1729 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1730 ok(hr
== D3DERR_INVALIDCALL
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
1731 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1732 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n", hr
, D3DERR_DEVICENOTRESET
);
1734 hr
= IDirect3D8_GetAdapterDisplayMode(d3d8
, D3DADAPTER_DEFAULT
, &d3ddm
);
1735 ok(SUCCEEDED(hr
), "GetAdapterDisplayMode failed, hr %#x.\n", hr
);
1737 memset(&d3dpp
, 0, sizeof(d3dpp
));
1738 d3dpp
.Windowed
= TRUE
;
1739 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1740 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1741 d3dpp
.EnableAutoDepthStencil
= FALSE
;
1742 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1744 hr
= IDirect3D8_CreateDevice(d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
1745 window
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &device2
);
1748 skip("Failed to create device, hr %#x.\n", hr
);
1752 hr
= IDirect3DDevice8_TestCooperativeLevel(device2
);
1753 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1755 d3dpp
.Windowed
= TRUE
;
1756 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1757 d3dpp
.BackBufferWidth
= 400;
1758 d3dpp
.BackBufferHeight
= 300;
1759 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1760 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1761 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1763 hr
= IDirect3DDevice8_Reset(device2
, &d3dpp
);
1764 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1768 hr
= IDirect3DDevice8_GetDepthStencilSurface(device2
, &surface
);
1769 ok(SUCCEEDED(hr
), "GetDepthStencilSurface failed, hr %#x.\n", hr
);
1770 ok(!!surface
, "Depth / stencil buffer should not be NULL.\n");
1772 IDirect3DSurface8_Release(surface
);
1775 HeapFree(GetProcessHeap(), 0, modes
);
1777 IDirect3DDevice8_Release(device2
);
1779 IDirect3DDevice8_Release(device1
);
1780 IDirect3D8_Release(d3d8
);
1781 DestroyWindow(window
);
1784 static void test_scene(void)
1786 IDirect3DDevice8
*device
;
1792 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
1793 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
1794 ok(!!window
, "Failed to create a window.\n");
1795 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
1796 ok(!!d3d
, "Failed to create a D3D object.\n");
1797 if (!(device
= create_device(d3d
, window
, NULL
)))
1799 skip("Failed to create a 3D device, skipping test.\n");
1803 /* Test an EndScene without BeginScene. Should return an error */
1804 hr
= IDirect3DDevice8_EndScene(device
);
1805 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
1807 /* Test a normal BeginScene / EndScene pair, this should work */
1808 hr
= IDirect3DDevice8_BeginScene(device
);
1809 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr
);
1810 hr
= IDirect3DDevice8_EndScene(device
);
1811 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed with %#08x\n", hr
);
1813 /* Test another EndScene without having begun a new scene. Should return an error */
1814 hr
= IDirect3DDevice8_EndScene(device
);
1815 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
1817 /* Two nested BeginScene and EndScene calls */
1818 hr
= IDirect3DDevice8_BeginScene(device
);
1819 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr
);
1820 hr
= IDirect3DDevice8_BeginScene(device
);
1821 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_BeginScene returned %#08x\n", hr
);
1822 hr
= IDirect3DDevice8_EndScene(device
);
1823 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed with %#08x\n", hr
);
1824 hr
= IDirect3DDevice8_EndScene(device
);
1825 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
1827 /* StretchRect does not exit in Direct3D8, so no equivalent to the d3d9 stretchrect tests */
1829 refcount
= IDirect3DDevice8_Release(device
);
1830 ok(!refcount
, "Device has %u references left.\n", refcount
);
1832 IDirect3D8_Release(d3d
);
1833 DestroyWindow(window
);
1836 static void test_shader(void)
1838 DWORD hPixelShader
= 0, hVertexShader
= 0;
1839 DWORD hPixelShader2
= 0, hVertexShader2
= 0;
1842 DWORD fvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
1843 IDirect3DDevice8
*device
;
1851 static DWORD dwVertexDecl
[] =
1854 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
),
1857 DWORD decl_normal_float2
[] =
1860 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
1861 D3DVSD_REG(D3DVSDE_NORMAL
, D3DVSDT_FLOAT2
), /* D3DVSDE_NORMAL, Register v1 */
1864 DWORD decl_normal_float4
[] =
1867 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
1868 D3DVSD_REG(D3DVSDE_NORMAL
, D3DVSDT_FLOAT4
), /* D3DVSDE_NORMAL, Register v1 */
1871 DWORD decl_normal_d3dcolor
[] =
1874 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
1875 D3DVSD_REG(D3DVSDE_NORMAL
, D3DVSDT_D3DCOLOR
),/* D3DVSDE_NORMAL, Register v1 */
1878 const DWORD vertex_decl_size
= sizeof(dwVertexDecl
);
1879 const DWORD simple_vs_size
= sizeof(simple_vs
);
1880 const DWORD simple_ps_size
= sizeof(simple_ps
);
1882 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
1883 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
1884 ok(!!window
, "Failed to create a window.\n");
1885 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
1886 ok(!!d3d
, "Failed to create a D3D object.\n");
1887 if (!(device
= create_device(d3d
, window
, NULL
)))
1889 skip("Failed to create a 3D device, skipping test.\n");
1893 IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
1895 /* Test setting and retrieving a FVF */
1896 hr
= IDirect3DDevice8_SetVertexShader(device
, fvf
);
1897 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
1898 hr
= IDirect3DDevice8_GetVertexShader(device
, &hTempHandle
);
1899 ok(SUCCEEDED(hr
), "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
1900 ok(hTempHandle
== fvf
, "Vertex shader %#08x is set, expected %#08x\n", hTempHandle
, fvf
);
1902 /* First create a vertex shader */
1903 hr
= IDirect3DDevice8_SetVertexShader(device
, 0);
1904 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
1905 hr
= IDirect3DDevice8_CreateVertexShader(device
, dwVertexDecl
, simple_vs
, &hVertexShader
, 0);
1906 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1907 /* Msdn says that the new vertex shader is set immediately. This is wrong, apparently */
1908 hr
= IDirect3DDevice8_GetVertexShader(device
, &hTempHandle
);
1909 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
1910 ok(hTempHandle
== 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, 0);
1911 /* Assign the shader, then verify that GetVertexShader works */
1912 hr
= IDirect3DDevice8_SetVertexShader(device
, hVertexShader
);
1913 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
1914 hr
= IDirect3DDevice8_GetVertexShader(device
, &hTempHandle
);
1915 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
1916 ok(hTempHandle
== hVertexShader
, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, hVertexShader
);
1917 /* Verify that we can retrieve the declaration */
1918 hr
= IDirect3DDevice8_GetVertexShaderDeclaration(device
, hVertexShader
, NULL
, &data_size
);
1919 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr
);
1920 ok(data_size
== vertex_decl_size
, "Got data_size %u, expected %u\n", data_size
, vertex_decl_size
);
1921 data
= HeapAlloc(GetProcessHeap(), 0, vertex_decl_size
);
1923 hr
= IDirect3DDevice8_GetVertexShaderDeclaration(device
, hVertexShader
, data
, &data_size
);
1924 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_GetVertexShaderDeclaration returned (%#08x), "
1925 "expected D3DERR_INVALIDCALL\n", hr
);
1926 ok(data_size
== 1, "Got data_size %u, expected 1\n", data_size
);
1927 data_size
= vertex_decl_size
;
1928 hr
= IDirect3DDevice8_GetVertexShaderDeclaration(device
, hVertexShader
, data
, &data_size
);
1929 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr
);
1930 ok(data_size
== vertex_decl_size
, "Got data_size %u, expected %u\n", data_size
, vertex_decl_size
);
1931 ok(!memcmp(data
, dwVertexDecl
, vertex_decl_size
), "data not equal to shader declaration\n");
1932 HeapFree(GetProcessHeap(), 0, data
);
1933 /* Verify that we can retrieve the shader function */
1934 hr
= IDirect3DDevice8_GetVertexShaderFunction(device
, hVertexShader
, NULL
, &data_size
);
1935 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr
);
1936 ok(data_size
== simple_vs_size
, "Got data_size %u, expected %u\n", data_size
, simple_vs_size
);
1937 data
= HeapAlloc(GetProcessHeap(), 0, simple_vs_size
);
1939 hr
= IDirect3DDevice8_GetVertexShaderFunction(device
, hVertexShader
, data
, &data_size
);
1940 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_GetVertexShaderFunction returned (%#08x), "
1941 "expected D3DERR_INVALIDCALL\n", hr
);
1942 ok(data_size
== 1, "Got data_size %u, expected 1\n", data_size
);
1943 data_size
= simple_vs_size
;
1944 hr
= IDirect3DDevice8_GetVertexShaderFunction(device
, hVertexShader
, data
, &data_size
);
1945 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr
);
1946 ok(data_size
== simple_vs_size
, "Got data_size %u, expected %u\n", data_size
, simple_vs_size
);
1947 ok(!memcmp(data
, simple_vs
, simple_vs_size
), "data not equal to shader function\n");
1948 HeapFree(GetProcessHeap(), 0, data
);
1949 /* Delete the assigned shader. This is supposed to work */
1950 hr
= IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader
);
1951 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
1952 /* The shader should be unset now */
1953 hr
= IDirect3DDevice8_GetVertexShader(device
, &hTempHandle
);
1954 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
1955 ok(hTempHandle
== 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, 0);
1957 /* Test a broken declaration. 3DMark2001 tries to use normals with 2 components
1958 * First try the fixed function shader function, then a custom one
1960 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl_normal_float2
, 0, &hVertexShader
, 0);
1961 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1962 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl_normal_float4
, 0, &hVertexShader
, 0);
1963 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1964 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl_normal_d3dcolor
, 0, &hVertexShader
, 0);
1965 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1967 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl_normal_float2
, simple_vs
, &hVertexShader
, 0);
1968 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1969 IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader
);
1971 if (caps
.PixelShaderVersion
>= D3DPS_VERSION(1, 0))
1973 /* The same with a pixel shader */
1974 hr
= IDirect3DDevice8_CreatePixelShader(device
, simple_ps
, &hPixelShader
);
1975 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
1976 /* Msdn says that the new pixel shader is set immediately. This is wrong, apparently */
1977 hr
= IDirect3DDevice8_GetPixelShader(device
, &hTempHandle
);
1978 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
1979 ok(hTempHandle
== 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, 0);
1980 /* Assign the shader, then verify that GetPixelShader works */
1981 hr
= IDirect3DDevice8_SetPixelShader(device
, hPixelShader
);
1982 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr
);
1983 hr
= IDirect3DDevice8_GetPixelShader(device
, &hTempHandle
);
1984 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
1985 ok(hTempHandle
== hPixelShader
, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, hPixelShader
);
1986 /* Verify that we can retrieve the shader function */
1987 hr
= IDirect3DDevice8_GetPixelShaderFunction(device
, hPixelShader
, NULL
, &data_size
);
1988 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr
);
1989 ok(data_size
== simple_ps_size
, "Got data_size %u, expected %u\n", data_size
, simple_ps_size
);
1990 data
= HeapAlloc(GetProcessHeap(), 0, simple_ps_size
);
1992 hr
= IDirect3DDevice8_GetPixelShaderFunction(device
, hPixelShader
, data
, &data_size
);
1993 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_GetPixelShaderFunction returned (%#08x), "
1994 "expected D3DERR_INVALIDCALL\n", hr
);
1995 ok(data_size
== 1, "Got data_size %u, expected 1\n", data_size
);
1996 data_size
= simple_ps_size
;
1997 hr
= IDirect3DDevice8_GetPixelShaderFunction(device
, hPixelShader
, data
, &data_size
);
1998 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr
);
1999 ok(data_size
== simple_ps_size
, "Got data_size %u, expected %u\n", data_size
, simple_ps_size
);
2000 ok(!memcmp(data
, simple_ps
, simple_ps_size
), "data not equal to shader function\n");
2001 HeapFree(GetProcessHeap(), 0, data
);
2002 /* Delete the assigned shader. This is supposed to work */
2003 hr
= IDirect3DDevice8_DeletePixelShader(device
, hPixelShader
);
2004 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
2005 /* The shader should be unset now */
2006 hr
= IDirect3DDevice8_GetPixelShader(device
, &hTempHandle
);
2007 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
2008 ok(hTempHandle
== 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, 0);
2010 /* What happens if a non-bound shader is deleted? */
2011 hr
= IDirect3DDevice8_CreatePixelShader(device
, simple_ps
, &hPixelShader
);
2012 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
2013 hr
= IDirect3DDevice8_CreatePixelShader(device
, simple_ps
, &hPixelShader2
);
2014 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
2016 hr
= IDirect3DDevice8_SetPixelShader(device
, hPixelShader
);
2017 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr
);
2018 hr
= IDirect3DDevice8_DeletePixelShader(device
, hPixelShader2
);
2019 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
2020 hr
= IDirect3DDevice8_GetPixelShader(device
, &hTempHandle
);
2021 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
2022 ok(hTempHandle
== hPixelShader
, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, hPixelShader
);
2023 hr
= IDirect3DDevice8_DeletePixelShader(device
, hPixelShader
);
2024 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
2026 /* Check for double delete. */
2027 hr
= IDirect3DDevice8_DeletePixelShader(device
, hPixelShader2
);
2028 ok(hr
== D3DERR_INVALIDCALL
|| broken(hr
== D3D_OK
), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
2029 hr
= IDirect3DDevice8_DeletePixelShader(device
, hPixelShader
);
2030 ok(hr
== D3DERR_INVALIDCALL
|| broken(hr
== D3D_OK
), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
2034 skip("Pixel shaders not supported\n");
2037 /* What happens if a non-bound shader is deleted? */
2038 hr
= IDirect3DDevice8_CreateVertexShader(device
, dwVertexDecl
, NULL
, &hVertexShader
, 0);
2039 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
2040 hr
= IDirect3DDevice8_CreateVertexShader(device
, dwVertexDecl
, NULL
, &hVertexShader2
, 0);
2041 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
2043 hr
= IDirect3DDevice8_SetVertexShader(device
, hVertexShader
);
2044 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
2045 hr
= IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader2
);
2046 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
2047 hr
= IDirect3DDevice8_GetVertexShader(device
, &hTempHandle
);
2048 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
2049 ok(hTempHandle
== hVertexShader
, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, hVertexShader
);
2050 hr
= IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader
);
2051 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
2053 /* Check for double delete. */
2054 hr
= IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader2
);
2055 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
2056 hr
= IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader
);
2057 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
2059 refcount
= IDirect3DDevice8_Release(device
);
2060 ok(!refcount
, "Device has %u references left.\n", refcount
);
2062 IDirect3D8_Release(d3d
);
2063 DestroyWindow(window
);
2066 static void test_limits(void)
2068 IDirect3DTexture8
*texture
;
2069 IDirect3DDevice8
*device
;
2076 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
2077 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
2078 ok(!!window
, "Failed to create a window.\n");
2079 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
2080 ok(!!d3d
, "Failed to create a D3D object.\n");
2081 if (!(device
= create_device(d3d
, window
, NULL
)))
2083 skip("Failed to create a 3D device, skipping test.\n");
2087 hr
= IDirect3DDevice8_CreateTexture(device
, 16, 16, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &texture
);
2088 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateTexture failed with %#08x\n", hr
);
2090 /* There are 8 texture stages. We should be able to access all of them */
2091 for (i
= 0; i
< 8; ++i
)
2093 hr
= IDirect3DDevice8_SetTexture(device
, i
, (IDirect3DBaseTexture8
*)texture
);
2094 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i
, hr
);
2095 hr
= IDirect3DDevice8_SetTexture(device
, i
, NULL
);
2096 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i
, hr
);
2097 hr
= IDirect3DDevice8_SetTextureStageState(device
, i
, D3DTSS_COLOROP
, D3DTOP_ADD
);
2098 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %#08x\n", i
, hr
);
2101 /* Investigations show that accessing higher textures stage states does
2102 * not return an error either. Writing to too high texture stages
2103 * (approximately texture 40) causes memory corruption in windows, so
2104 * there is no bounds checking. */
2105 IDirect3DTexture8_Release(texture
);
2106 refcount
= IDirect3DDevice8_Release(device
);
2107 ok(!refcount
, "Device has %u references left.\n", refcount
);
2109 IDirect3D8_Release(d3d
);
2110 DestroyWindow(window
);
2113 static void test_lights(void)
2115 IDirect3DDevice8
*device
;
2124 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
2125 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
2126 ok(!!window
, "Failed to create a window.\n");
2127 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
2128 ok(!!d3d8
, "Failed to create a D3D object.\n");
2129 if (!(device
= create_device(d3d8
, window
, NULL
)))
2131 skip("Failed to create a 3D device, skipping test.\n");
2135 memset(&caps
, 0, sizeof(caps
));
2136 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
2137 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetDeviceCaps failed with %08x\n", hr
);
2139 for(i
= 1; i
<= caps
.MaxActiveLights
; i
++) {
2140 hr
= IDirect3DDevice8_LightEnable(device
, i
, TRUE
);
2141 ok(hr
== D3D_OK
, "Enabling light %u failed with %08x\n", i
, hr
);
2142 hr
= IDirect3DDevice8_GetLightEnable(device
, i
, &enabled
);
2143 ok(hr
== D3D_OK
|| broken(hr
== D3DERR_INVALIDCALL
),
2144 "GetLightEnable on light %u failed with %08x\n", i
, hr
);
2145 ok(enabled
, "Light %d is %s\n", i
, enabled
? "enabled" : "disabled");
2148 /* TODO: Test the rendering results in this situation */
2149 hr
= IDirect3DDevice8_LightEnable(device
, i
+ 1, TRUE
);
2150 ok(hr
== D3D_OK
, "Enabling one light more than supported returned %08x\n", hr
);
2151 hr
= IDirect3DDevice8_GetLightEnable(device
, i
+ 1, &enabled
);
2152 ok(hr
== D3D_OK
, "GetLightEnable on light %u failed with %08x\n", i
+ 1, hr
);
2153 ok(enabled
, "Light %d is %s\n", i
+ 1, enabled
? "enabled" : "disabled");
2154 hr
= IDirect3DDevice8_LightEnable(device
, i
+ 1, FALSE
);
2155 ok(hr
== D3D_OK
, "Disabling the additional returned %08x\n", hr
);
2157 for(i
= 1; i
<= caps
.MaxActiveLights
; i
++) {
2158 hr
= IDirect3DDevice8_LightEnable(device
, i
, FALSE
);
2159 ok(hr
== D3D_OK
, "Disabling light %u failed with %08x\n", i
, hr
);
2162 refcount
= IDirect3DDevice8_Release(device
);
2163 ok(!refcount
, "Device has %u references left.\n", refcount
);
2165 IDirect3D8_Release(d3d8
);
2166 DestroyWindow(window
);
2169 static void test_render_zero_triangles(void)
2171 IDirect3DDevice8
*device
;
2179 struct vec3 position
;
2185 {{0.0f
, -1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
2186 {{0.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
2187 {{1.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
2188 {{1.0f
, -1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
2191 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
2192 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
2193 ok(!!window
, "Failed to create a window.\n");
2194 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
2195 ok(!!d3d8
, "Failed to create a D3D object.\n");
2196 if (!(device
= create_device(d3d8
, window
, NULL
)))
2198 skip("Failed to create a 3D device, skipping test.\n");
2202 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
2203 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
2205 hr
= IDirect3DDevice8_BeginScene(device
);
2206 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
2207 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 0 /* NumVerts */,
2208 0 /* PrimCount */, NULL
, D3DFMT_INDEX16
, quad
, sizeof(quad
[0]));
2209 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
2210 hr
= IDirect3DDevice8_EndScene(device
);
2211 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
2213 IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
2215 refcount
= IDirect3DDevice8_Release(device
);
2216 ok(!refcount
, "Device has %u references left.\n", refcount
);
2218 IDirect3D8_Release(d3d8
);
2219 DestroyWindow(window
);
2222 static void test_depth_stencil_reset(void)
2224 D3DPRESENT_PARAMETERS present_parameters
;
2225 D3DDISPLAYMODE display_mode
;
2226 IDirect3DSurface8
*surface
, *orig_rt
;
2227 IDirect3DDevice8
*device
= NULL
;
2233 hwnd
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
2234 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
2235 ok(!!hwnd
, "Failed to create a window.\n");
2236 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
2237 ok(!!d3d8
, "Failed to create a D3D object.\n");
2239 IDirect3D8_GetAdapterDisplayMode(d3d8
, D3DADAPTER_DEFAULT
, &display_mode
);
2240 memset(&present_parameters
, 0, sizeof(present_parameters
));
2241 present_parameters
.Windowed
= TRUE
;
2242 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2243 present_parameters
.BackBufferFormat
= display_mode
.Format
;
2244 present_parameters
.EnableAutoDepthStencil
= TRUE
;
2245 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
2247 hr
= IDirect3D8_CreateDevice(d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
2248 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
2251 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr
);
2255 hr
= IDirect3DDevice8_GetRenderTarget(device
, &orig_rt
);
2256 ok(hr
== D3D_OK
, "GetRenderTarget failed with 0x%08x\n", hr
);
2258 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
2259 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed with %#x\n", hr
);
2261 hr
= IDirect3DDevice8_SetRenderTarget(device
, NULL
, NULL
);
2262 ok(hr
== D3D_OK
, "SetRenderTarget failed with 0x%08x\n", hr
);
2264 hr
= IDirect3DDevice8_GetRenderTarget(device
, &surface
);
2265 ok(hr
== D3D_OK
, "GetRenderTarget failed with 0x%08x\n", hr
);
2266 ok(surface
== orig_rt
, "Render target is %p, should be %p\n", surface
, orig_rt
);
2267 if (surface
) IDirect3DSurface8_Release(surface
);
2268 IDirect3DSurface8_Release(orig_rt
);
2270 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surface
);
2271 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr
);
2272 ok(surface
== NULL
, "Depth stencil should be NULL\n");
2274 present_parameters
.EnableAutoDepthStencil
= TRUE
;
2275 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
2276 hr
= IDirect3DDevice8_Reset(device
, &present_parameters
);
2277 ok(hr
== D3D_OK
, "Reset failed with 0x%08x\n", hr
);
2279 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surface
);
2280 ok(hr
== D3D_OK
, "GetDepthStencilSurface failed with 0x%08x\n", hr
);
2281 ok(surface
!= NULL
, "Depth stencil should not be NULL\n");
2282 if (surface
) IDirect3DSurface8_Release(surface
);
2284 present_parameters
.EnableAutoDepthStencil
= FALSE
;
2285 hr
= IDirect3DDevice8_Reset(device
, &present_parameters
);
2286 ok(hr
== D3D_OK
, "Reset failed with 0x%08x\n", hr
);
2288 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surface
);
2289 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr
);
2290 ok(surface
== NULL
, "Depth stencil should be NULL\n");
2292 refcount
= IDirect3DDevice8_Release(device
);
2293 ok(!refcount
, "Device has %u references left.\n", refcount
);
2296 IDirect3D8_GetAdapterDisplayMode( d3d8
, D3DADAPTER_DEFAULT
, &display_mode
);
2298 ZeroMemory( &present_parameters
, sizeof(present_parameters
) );
2299 present_parameters
.Windowed
= TRUE
;
2300 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2301 present_parameters
.BackBufferFormat
= display_mode
.Format
;
2302 present_parameters
.EnableAutoDepthStencil
= FALSE
;
2303 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
2305 hr
= IDirect3D8_CreateDevice( d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
2306 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
2310 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr
);
2314 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
2315 ok(hr
== D3D_OK
, "IDirect3DDevice8_TestCooperativeLevel after creation returned %#x\n", hr
);
2317 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2318 present_parameters
.Windowed
= TRUE
;
2319 present_parameters
.BackBufferWidth
= 400;
2320 present_parameters
.BackBufferHeight
= 300;
2321 present_parameters
.EnableAutoDepthStencil
= TRUE
;
2322 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
2324 hr
= IDirect3DDevice8_Reset(device
, &present_parameters
);
2325 ok(hr
== D3D_OK
, "IDirect3DDevice8_Reset failed with 0x%08x\n", hr
);
2327 if (FAILED(hr
)) goto cleanup
;
2329 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surface
);
2330 ok(hr
== D3D_OK
, "GetDepthStencilSurface failed with 0x%08x\n", hr
);
2331 ok(surface
!= NULL
, "Depth stencil should not be NULL\n");
2332 if (surface
) IDirect3DSurface8_Release(surface
);
2337 refcount
= IDirect3DDevice8_Release(device
);
2338 ok(!refcount
, "Device has %u references left.\n", refcount
);
2340 IDirect3D8_Release(d3d8
);
2341 DestroyWindow(hwnd
);
2344 static HWND filter_messages
;
2355 enum message_window window
;
2357 WPARAM expect_wparam
;
2360 static const struct message
*expect_messages
;
2361 static HWND device_window
, focus_window
;
2362 static LONG windowposchanged_received
, syscommand_received
;
2364 struct wndproc_thread_param
2367 HANDLE window_created
;
2368 HANDLE test_finished
;
2369 BOOL running_in_foreground
;
2372 static LRESULT CALLBACK
test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2374 if (filter_messages
&& filter_messages
== hwnd
)
2376 if (message
!= WM_DISPLAYCHANGE
&& message
!= WM_IME_NOTIFY
)
2377 todo_wine
ok(0, "Received unexpected message %#x for window %p.\n", message
, hwnd
);
2380 if (expect_messages
)
2384 switch (expect_messages
->window
)
2399 if (hwnd
== w
&& expect_messages
->message
== message
)
2401 if (expect_messages
->check_wparam
)
2402 ok(wparam
== expect_messages
->expect_wparam
,
2403 "Got unexpected wparam %lx for message %x, expected %lx.\n",
2404 wparam
, message
, expect_messages
->expect_wparam
);
2410 /* KDE randomly does something with the hidden window during the
2411 * mode change that sometimes generates a WM_WINDOWPOSCHANGING
2412 * message. A WM_WINDOWPOSCHANGED message is not generated, so
2413 * just flag WM_WINDOWPOSCHANGED as bad. */
2414 if (message
== WM_WINDOWPOSCHANGED
)
2415 InterlockedIncrement(&windowposchanged_received
);
2416 else if (message
== WM_SYSCOMMAND
)
2417 InterlockedIncrement(&syscommand_received
);
2419 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
2422 static DWORD WINAPI
wndproc_thread(void *param
)
2424 struct wndproc_thread_param
*p
= param
;
2428 p
->dummy_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2429 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, registry_mode
.dmPelsWidth
,
2430 registry_mode
.dmPelsHeight
, 0, 0, 0, 0);
2431 p
->running_in_foreground
= SetForegroundWindow(p
->dummy_window
);
2433 ret
= SetEvent(p
->window_created
);
2434 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
2440 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2441 res
= WaitForSingleObject(p
->test_finished
, 100);
2442 if (res
== WAIT_OBJECT_0
) break;
2443 if (res
!= WAIT_TIMEOUT
)
2445 ok(0, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
2450 DestroyWindow(p
->dummy_window
);
2455 static void test_wndproc(void)
2457 struct wndproc_thread_param thread_params
;
2458 struct device_desc device_desc
;
2459 IDirect3DDevice8
*device
;
2467 UINT i
, adapter_mode_count
;
2469 D3DDISPLAYMODE d3ddm
;
2470 DWORD d3d_width
= 0, d3d_height
= 0, user32_width
= 0, user32_height
= 0;
2475 static const struct message create_messages
[] =
2477 {WM_WINDOWPOSCHANGING
, FOCUS_WINDOW
, FALSE
, 0},
2478 /* Do not test wparam here. If device creation succeeds,
2479 * wparam is WA_ACTIVE. If device creation fails (testbot)
2480 * wparam is set to WA_INACTIVE on some Windows versions. */
2481 {WM_ACTIVATE
, FOCUS_WINDOW
, FALSE
, 0},
2482 {WM_SETFOCUS
, FOCUS_WINDOW
, FALSE
, 0},
2483 {WM_WINDOWPOSCHANGING
, DEVICE_WINDOW
, FALSE
, 0},
2484 {WM_MOVE
, DEVICE_WINDOW
, FALSE
, 0},
2485 {WM_SIZE
, DEVICE_WINDOW
, FALSE
, 0},
2488 static const struct message focus_loss_messages
[] =
2490 /* WM_ACTIVATE (wparam = WA_INACTIVE) is sent on Windows. It is
2491 * not reliable on X11 WMs. When the window focus follows the
2492 * mouse pointer the message is not sent.
2493 * {WM_ACTIVATE, FOCUS_WINDOW, TRUE, WA_INACTIVE}, */
2494 {WM_DISPLAYCHANGE
, DEVICE_WINDOW
, FALSE
, 0},
2495 /* WM_DISPLAYCHANGE is sent to the focus window too, but the order is
2496 * not deterministic. */
2497 {WM_WINDOWPOSCHANGING
, DEVICE_WINDOW
, FALSE
, 0},
2498 /* Windows sends WM_ACTIVATE to the device window, indicating that
2499 * SW_SHOWMINIMIZED is used instead of SW_MINIMIZE. Yet afterwards
2500 * the foreground and focus window are NULL. On Wine SW_SHOWMINIMIZED
2501 * leaves the device window active, breaking re-activation in the
2503 * {WM_ACTIVATE, DEVICE_WINDOW, TRUE, 0x200000 | WA_ACTIVE}, */
2504 {WM_WINDOWPOSCHANGED
, DEVICE_WINDOW
, FALSE
, 0},
2505 {WM_SIZE
, DEVICE_WINDOW
, TRUE
, SIZE_MINIMIZED
},
2506 {WM_ACTIVATEAPP
, FOCUS_WINDOW
, TRUE
, FALSE
},
2507 /* WM_ACTIVATEAPP is sent to the device window too, but the order is
2508 * not deterministic. It may be sent after the focus window handling
2512 static const struct message reactivate_messages
[] =
2514 {WM_WINDOWPOSCHANGING
, DEVICE_WINDOW
, FALSE
, 0},
2515 {WM_WINDOWPOSCHANGED
, DEVICE_WINDOW
, FALSE
, 0},
2516 {WM_MOVE
, DEVICE_WINDOW
, FALSE
, 0},
2517 {WM_ACTIVATEAPP
, FOCUS_WINDOW
, TRUE
, TRUE
},
2520 static const struct message focus_loss_messages_hidden
[] =
2522 {WM_DISPLAYCHANGE
, DEVICE_WINDOW
, FALSE
, 0},
2523 {WM_ACTIVATEAPP
, FOCUS_WINDOW
, TRUE
, FALSE
},
2526 static const struct message focus_loss_messages_filtered
[] =
2528 /* WM_ACTIVATE is delivered to the window proc because it is
2529 * generated by SetForegroundWindow before the d3d routine
2530 * starts it work. Don't check for it due to focus-follows-mouse
2532 {WM_DISPLAYCHANGE
, FOCUS_WINDOW
, FALSE
, 0},
2533 {WM_ACTIVATEAPP
, FOCUS_WINDOW
, TRUE
, FALSE
},
2536 static const struct message reactivate_messages_filtered
[] =
2538 {WM_ACTIVATEAPP
, FOCUS_WINDOW
, TRUE
, TRUE
},
2541 static const struct message sc_restore_messages
[] =
2543 /* WM_SYSCOMMAND is delivered only once, after d3d has already
2544 * processed it. Our wndproc has no way to prevent d3d from
2545 * handling the message. The second DefWindowProc call done by
2546 * our wndproc doesn't do any changes to the window because it
2547 * is already restored due to d3d's handling. */
2548 {WM_WINDOWPOSCHANGING
, FOCUS_WINDOW
, FALSE
, 0},
2549 {WM_WINDOWPOSCHANGED
, FOCUS_WINDOW
, FALSE
, 0},
2550 {WM_SIZE
, FOCUS_WINDOW
, TRUE
, SIZE_RESTORED
},
2551 {WM_SYSCOMMAND
, FOCUS_WINDOW
, TRUE
, SC_RESTORE
},
2554 static const struct message sc_minimize_messages
[] =
2556 {WM_SYSCOMMAND
, FOCUS_WINDOW
, TRUE
, SC_MINIMIZE
},
2557 {WM_WINDOWPOSCHANGING
, FOCUS_WINDOW
, FALSE
, 0},
2558 {WM_WINDOWPOSCHANGED
, FOCUS_WINDOW
, FALSE
, 0},
2559 {WM_MOVE
, FOCUS_WINDOW
, FALSE
, 0},
2560 {WM_SIZE
, FOCUS_WINDOW
, TRUE
, SIZE_MINIMIZED
},
2563 static const struct message sc_maximize_messages
[] =
2565 {WM_SYSCOMMAND
, FOCUS_WINDOW
, TRUE
, SC_MAXIMIZE
},
2566 {WM_WINDOWPOSCHANGING
, FOCUS_WINDOW
, FALSE
, 0},
2567 {WM_WINDOWPOSCHANGED
, FOCUS_WINDOW
, FALSE
, 0},
2568 {WM_MOVE
, FOCUS_WINDOW
, FALSE
, 0},
2569 {WM_SIZE
, FOCUS_WINDOW
, TRUE
, SIZE_MAXIMIZED
},
2573 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
2574 ok(!!d3d8
, "Failed to create a D3D object.\n");
2576 adapter_mode_count
= IDirect3D8_GetAdapterModeCount(d3d8
, D3DADAPTER_DEFAULT
);
2577 for (i
= 0; i
< adapter_mode_count
; ++i
)
2579 hr
= IDirect3D8_EnumAdapterModes(d3d8
, D3DADAPTER_DEFAULT
, i
, &d3ddm
);
2580 ok(SUCCEEDED(hr
), "Failed to enumerate display mode, hr %#x.\n", hr
);
2582 if (d3ddm
.Format
!= D3DFMT_X8R8G8B8
)
2584 if (d3ddm
.Width
== registry_mode
.dmPelsWidth
&& d3ddm
.Height
== registry_mode
.dmPelsHeight
)
2586 /* The r200 driver on Windows XP enumerates modes like 320x200 and 320x240 but
2587 * refuses to create a device at these sizes. */
2588 if (d3ddm
.Width
< 640 || d3ddm
.Height
< 480)
2593 user32_width
= d3ddm
.Width
;
2594 user32_height
= d3ddm
.Height
;
2598 /* Make sure the d3d mode is smaller in width or height and at most
2599 * equal in the other dimension than the mode passed to
2600 * ChangeDisplaySettings. Otherwise Windows shrinks the window to
2601 * the ChangeDisplaySettings parameters + 12. */
2602 if (d3ddm
.Width
== user32_width
&& d3ddm
.Height
== user32_height
)
2604 if (d3ddm
.Width
<= user32_width
&& d3ddm
.Height
<= user32_height
)
2606 d3d_width
= d3ddm
.Width
;
2607 d3d_height
= d3ddm
.Height
;
2610 if (user32_width
<= d3ddm
.Width
&& user32_height
<= d3ddm
.Height
)
2612 d3d_width
= user32_width
;
2613 d3d_height
= user32_height
;
2614 user32_width
= d3ddm
.Width
;
2615 user32_height
= d3ddm
.Height
;
2622 skip("Could not find adequate modes, skipping mode tests.\n");
2623 IDirect3D8_Release(d3d8
);
2627 wc
.lpfnWndProc
= test_proc
;
2628 wc
.lpszClassName
= "d3d8_test_wndproc_wc";
2629 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2631 thread_params
.window_created
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2632 ok(!!thread_params
.window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
2633 thread_params
.test_finished
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2634 ok(!!thread_params
.test_finished
, "CreateEvent failed, last error %#x.\n", GetLastError());
2636 memset(&devmode
, 0, sizeof(devmode
));
2637 devmode
.dmSize
= sizeof(devmode
);
2638 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2639 devmode
.dmPelsWidth
= user32_width
;
2640 devmode
.dmPelsHeight
= user32_height
;
2641 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2642 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2644 focus_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2645 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, user32_width
, user32_height
, 0, 0, 0, 0);
2646 device_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2647 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, user32_width
, user32_height
, 0, 0, 0, 0);
2648 thread
= CreateThread(NULL
, 0, wndproc_thread
, &thread_params
, 0, &tid
);
2649 ok(!!thread
, "Failed to create thread, last error %#x.\n", GetLastError());
2651 res
= WaitForSingleObject(thread_params
.window_created
, INFINITE
);
2652 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
2654 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2655 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2656 (LONG_PTR
)test_proc
, proc
);
2657 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2658 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2659 (LONG_PTR
)test_proc
, proc
);
2661 trace("device_window %p, focus_window %p, dummy_window %p.\n",
2662 device_window
, focus_window
, thread_params
.dummy_window
);
2665 ok(tmp
== device_window
, "Expected focus %p, got %p.\n", device_window
, tmp
);
2666 if (thread_params
.running_in_foreground
)
2668 tmp
= GetForegroundWindow();
2669 ok(tmp
== thread_params
.dummy_window
, "Expected foreground window %p, got %p.\n",
2670 thread_params
.dummy_window
, tmp
);
2673 skip("Not running in foreground, skip foreground window test\n");
2677 expect_messages
= create_messages
;
2679 device_desc
.device_window
= device_window
;
2680 device_desc
.width
= d3d_width
;
2681 device_desc
.height
= d3d_height
;
2682 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
2683 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
2685 skip("Failed to create a D3D device, skipping tests.\n");
2689 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2690 expect_messages
->message
, expect_messages
->window
);
2691 expect_messages
= NULL
;
2693 if (0) /* Disabled until we can make this work in a reliable way on Wine. */
2696 ok(tmp
== focus_window
, "Expected focus %p, got %p.\n", focus_window
, tmp
);
2697 tmp
= GetForegroundWindow();
2698 ok(tmp
== focus_window
, "Expected foreground window %p, got %p.\n", focus_window
, tmp
);
2700 SetForegroundWindow(focus_window
);
2703 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2704 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2705 (LONG_PTR
)test_proc
, proc
);
2707 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2708 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
2710 /* Change the mode while the device is in use and then drop focus. */
2711 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2712 devmode
.dmPelsWidth
= user32_width
;
2713 devmode
.dmPelsHeight
= user32_height
;
2714 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2715 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x, i=%u.\n", change_ret
, i
);
2717 /* Wine doesn't (yet) mark the device not reset when the mode is changed, thus the todo_wine.
2718 * But sometimes focus-follows-mouse WMs also temporarily drop window focus, which makes
2719 * mark the device lost, then not reset, causing the test to succeed for the wrong reason. */
2720 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
2721 todo_wine_if (hr
!= D3DERR_DEVICENOTRESET
)
2722 ok(hr
== D3DERR_DEVICENOTRESET
, "Got unexpected hr %#x.\n", hr
);
2724 expect_messages
= focus_loss_messages
;
2725 /* SetForegroundWindow is a poor replacement for the user pressing alt-tab or
2726 * manually changing the focus. It generates the same messages, but the task
2727 * bar still shows the previous foreground window as active, and the window has
2728 * an inactive titlebar if reactivated with SetForegroundWindow. Reactivating
2729 * the device is difficult, see below. */
2730 SetForegroundWindow(GetDesktopWindow());
2731 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2732 expect_messages
->message
, expect_messages
->window
);
2733 expect_messages
= NULL
;
2735 ok(tmp
!= device_window
, "The device window is active.\n");
2736 ok(tmp
!= focus_window
, "The focus window is active.\n");
2738 /* The Present call is necessary to make native realize the device is lost. */
2739 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
2740 ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
2741 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
2742 /* Focus-follows-mouse WMs prematurely reactivate our window. */
2743 todo_wine_if (hr
== D3DERR_DEVICENOTRESET
)
2744 ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
2746 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2747 ok(ret
, "Failed to get display mode.\n");
2748 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2749 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpect screen size %ux%u.\n",
2750 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2752 /* I have to minimize and restore the focus window, otherwise native d3d9 fails
2753 * device::reset with D3DERR_DEVICELOST. This does not happen when the window
2754 * restore is triggered by the user. */
2755 expect_messages
= reactivate_messages
;
2756 ShowWindow(focus_window
, SW_MINIMIZE
);
2757 ShowWindow(focus_window
, SW_RESTORE
);
2758 /* Set focus twice to make KDE and fvwm in focus-follows-mouse mode happy. */
2759 SetForegroundWindow(focus_window
);
2761 SetForegroundWindow(focus_window
);
2762 flush_events(); /* WM_WINDOWPOSCHANGING etc arrive after SetForegroundWindow returns. */
2763 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it, i=%u.\n",
2764 expect_messages
->message
, expect_messages
->window
, i
);
2765 expect_messages
= NULL
;
2767 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
2768 ok(hr
== D3DERR_DEVICENOTRESET
, "Got unexpected hr %#x.\n", hr
);
2770 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2771 ok(ret
, "Failed to get display mode.\n");
2772 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2773 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpect screen size %ux%u.\n",
2774 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2776 hr
= reset_device(device
, &device_desc
);
2777 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
2779 ShowWindow(device_window
, SW_HIDE
);
2782 expect_messages
= focus_loss_messages_hidden
;
2783 windowposchanged_received
= 0;
2784 SetForegroundWindow(GetDesktopWindow());
2785 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2786 expect_messages
->message
, expect_messages
->window
);
2787 ok(!windowposchanged_received
, "Received WM_WINDOWPOSCHANGED but did not expect it.\n");
2788 expect_messages
= NULL
;
2791 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2792 ok(ret
, "Failed to get display mode.\n");
2793 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
, "Got unexpect width %u.\n", devmode
.dmPelsWidth
);
2794 ok(devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpect height %u.\n", devmode
.dmPelsHeight
);
2796 /* SW_SHOWMINNOACTIVE is needed to make FVWM happy. SW_SHOWNOACTIVATE is needed to make windows
2797 * send SIZE_RESTORED after ShowWindow(SW_SHOWMINNOACTIVE). */
2798 ShowWindow(focus_window
, SW_SHOWNOACTIVATE
);
2799 ShowWindow(focus_window
, SW_SHOWMINNOACTIVE
);
2802 syscommand_received
= 0;
2803 expect_messages
= sc_restore_messages
;
2804 SendMessageA(focus_window
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
2805 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2806 expect_messages
->message
, expect_messages
->window
);
2807 ok(syscommand_received
== 1, "Got unexpected number of WM_SYSCOMMAND messages: %d.\n", syscommand_received
);
2808 expect_messages
= NULL
;
2811 expect_messages
= sc_minimize_messages
;
2812 SendMessageA(focus_window
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
2813 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2814 expect_messages
->message
, expect_messages
->window
);
2815 expect_messages
= NULL
;
2818 expect_messages
= sc_maximize_messages
;
2819 SendMessageA(focus_window
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
2820 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2821 expect_messages
->message
, expect_messages
->window
);
2822 expect_messages
= NULL
;
2825 SetForegroundWindow(GetDesktopWindow());
2826 ShowWindow(device_window
, SW_MINIMIZE
);
2827 ShowWindow(focus_window
, SW_MINIMIZE
);
2828 ShowWindow(focus_window
, SW_RESTORE
);
2829 SetForegroundWindow(focus_window
);
2832 /* Releasing a device in lost state breaks follow-up tests on native. */
2833 hr
= reset_device(device
, &device_desc
);
2834 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
2836 filter_messages
= focus_window
;
2837 ref
= IDirect3DDevice8_Release(device
);
2838 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2840 /* Fix up the mode until Wine's device release behavior is fixed. */
2841 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2842 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2844 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2845 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2846 (LONG_PTR
)test_proc
, proc
);
2848 /* Hide the device window. It prevents WM_ACTIVATEAPP messages from being sent
2849 * on native in the test below. It isn't needed anyways. Creating the third
2850 * device will show it again. */
2851 filter_messages
= NULL
;
2852 ShowWindow(device_window
, SW_HIDE
);
2853 /* Remove the maximized state from the SYSCOMMAND test while we're not
2854 * interfering with a device. */
2855 ShowWindow(focus_window
, SW_SHOWNORMAL
);
2856 filter_messages
= focus_window
;
2858 device_desc
.device_window
= focus_window
;
2859 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
2861 skip("Failed to create a D3D device, skipping tests.\n");
2865 filter_messages
= NULL
;
2867 expect_messages
= focus_loss_messages_filtered
;
2868 windowposchanged_received
= 0;
2869 SetForegroundWindow(GetDesktopWindow());
2870 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2871 expect_messages
->message
, expect_messages
->window
);
2872 ok(!windowposchanged_received
, "Received WM_WINDOWPOSCHANGED but did not expect it.\n");
2873 expect_messages
= NULL
;
2875 /* The window is iconic even though no message was sent. */
2876 ok(IsIconic(focus_window
), "The focus window is not iconic.\n");
2878 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
2879 ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
2881 syscommand_received
= 0;
2882 expect_messages
= sc_restore_messages
;
2883 SendMessageA(focus_window
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
2884 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2885 expect_messages
->message
, expect_messages
->window
);
2886 ok(syscommand_received
== 1, "Got unexpected number of WM_SYSCOMMAND messages: %d.\n", syscommand_received
);
2887 expect_messages
= NULL
;
2891 ShowWindow(focus_window
, SW_RESTORE
);
2894 expect_messages
= sc_minimize_messages
;
2895 SendMessageA(focus_window
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
2896 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2897 expect_messages
->message
, expect_messages
->window
);
2898 expect_messages
= NULL
;
2899 /* Needed to make the next test reliably send WM_SIZE(SIZE_MAXIMIZED). Without
2900 * this call it sends WM_SIZE(SIZE_RESTORED). */
2901 ShowWindow(focus_window
, SW_RESTORE
);
2904 expect_messages
= sc_maximize_messages
;
2905 SendMessageA(focus_window
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
2906 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
2907 expect_messages
->message
, expect_messages
->window
);
2908 expect_messages
= NULL
;
2909 SetForegroundWindow(GetDesktopWindow());
2912 /* ShowWindow(SW_RESTORE); SetForegroundWindow(desktop); SetForegroundWindow(focus);
2913 * results in the second SetForegroundWindow call failing and the device not being
2914 * restored on native. Directly using ShowWindow(SW_RESTORE) works, but it means
2915 * we cannot test for the absence of WM_WINDOWPOSCHANGED messages. */
2916 expect_messages
= reactivate_messages_filtered
;
2917 ShowWindow(focus_window
, SW_RESTORE
);
2918 SetForegroundWindow(focus_window
);
2920 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it\n",
2921 expect_messages
->message
, expect_messages
->window
);
2922 expect_messages
= NULL
;
2924 filter_messages
= focus_window
;
2925 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
2926 ok(hr
== D3DERR_DEVICENOTRESET
, "Got unexpected hr %#x.\n", hr
);
2928 hr
= reset_device(device
, &device_desc
);
2929 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
2931 ref
= IDirect3DDevice8_Release(device
);
2932 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2934 device_desc
.device_window
= device_window
;
2935 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
2937 skip("Failed to create a D3D device, skipping tests.\n");
2941 proc
= SetWindowLongPtrA(focus_window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2942 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
2944 ref
= IDirect3DDevice8_Release(device
);
2945 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
2947 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2948 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2949 (LONG_PTR
)DefWindowProcA
, proc
);
2952 filter_messages
= NULL
;
2953 IDirect3D8_Release(d3d8
);
2955 SetEvent(thread_params
.test_finished
);
2956 WaitForSingleObject(thread
, INFINITE
);
2957 CloseHandle(thread_params
.test_finished
);
2958 CloseHandle(thread_params
.window_created
);
2959 CloseHandle(thread
);
2961 DestroyWindow(device_window
);
2962 DestroyWindow(focus_window
);
2963 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL
));
2966 static void test_wndproc_windowed(void)
2968 struct wndproc_thread_param thread_params
;
2969 struct device_desc device_desc
;
2970 IDirect3DDevice8
*device
;
2980 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
2981 ok(!!d3d8
, "Failed to create a D3D object.\n");
2983 wc
.lpfnWndProc
= test_proc
;
2984 wc
.lpszClassName
= "d3d8_test_wndproc_wc";
2985 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2987 thread_params
.window_created
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2988 ok(!!thread_params
.window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
2989 thread_params
.test_finished
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2990 ok(!!thread_params
.test_finished
, "CreateEvent failed, last error %#x.\n", GetLastError());
2992 focus_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2993 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, registry_mode
.dmPelsWidth
,
2994 registry_mode
.dmPelsHeight
, 0, 0, 0, 0);
2995 device_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2996 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, registry_mode
.dmPelsWidth
,
2997 registry_mode
.dmPelsHeight
, 0, 0, 0, 0);
2998 thread
= CreateThread(NULL
, 0, wndproc_thread
, &thread_params
, 0, &tid
);
2999 ok(!!thread
, "Failed to create thread, last error %#x.\n", GetLastError());
3001 res
= WaitForSingleObject(thread_params
.window_created
, INFINITE
);
3002 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
3004 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3005 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3006 (LONG_PTR
)test_proc
, proc
);
3007 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3008 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3009 (LONG_PTR
)test_proc
, proc
);
3011 trace("device_window %p, focus_window %p, dummy_window %p.\n",
3012 device_window
, focus_window
, thread_params
.dummy_window
);
3015 ok(tmp
== device_window
, "Expected focus %p, got %p.\n", device_window
, tmp
);
3016 if (thread_params
.running_in_foreground
)
3018 tmp
= GetForegroundWindow();
3019 ok(tmp
== thread_params
.dummy_window
, "Expected foreground window %p, got %p.\n",
3020 thread_params
.dummy_window
, tmp
);
3023 skip("Not running in foreground, skip foreground window test\n");
3025 filter_messages
= focus_window
;
3027 device_desc
.device_window
= device_window
;
3028 device_desc
.width
= registry_mode
.dmPelsWidth
;
3029 device_desc
.height
= registry_mode
.dmPelsHeight
;
3030 device_desc
.flags
= 0;
3031 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
3033 skip("Failed to create a D3D device, skipping tests.\n");
3038 ok(tmp
== device_window
, "Expected focus %p, got %p.\n", device_window
, tmp
);
3039 tmp
= GetForegroundWindow();
3040 ok(tmp
== thread_params
.dummy_window
, "Expected foreground window %p, got %p.\n",
3041 thread_params
.dummy_window
, tmp
);
3043 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3044 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3045 (LONG_PTR
)test_proc
, proc
);
3047 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3048 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3049 (LONG_PTR
)test_proc
, proc
);
3051 filter_messages
= NULL
;
3053 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3054 hr
= reset_device(device
, &device_desc
);
3055 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3057 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3058 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3059 (LONG_PTR
)test_proc
, proc
);
3061 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3062 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
3064 device_desc
.flags
= 0;
3065 hr
= reset_device(device
, &device_desc
);
3066 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3068 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3069 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3070 (LONG_PTR
)test_proc
, proc
);
3072 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3073 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3074 (LONG_PTR
)test_proc
, proc
);
3076 filter_messages
= focus_window
;
3078 ref
= IDirect3DDevice8_Release(device
);
3079 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
3081 filter_messages
= device_window
;
3083 device_desc
.device_window
= focus_window
;
3084 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
3086 skip("Failed to create a D3D device, skipping tests.\n");
3090 filter_messages
= NULL
;
3092 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3093 hr
= reset_device(device
, &device_desc
);
3094 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3096 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3097 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3098 (LONG_PTR
)test_proc
, proc
);
3100 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3101 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
3103 device_desc
.flags
= 0;
3104 hr
= reset_device(device
, &device_desc
);
3105 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3107 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3108 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3109 (LONG_PTR
)test_proc
, proc
);
3111 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3112 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3113 (LONG_PTR
)test_proc
, proc
);
3115 filter_messages
= device_window
;
3117 ref
= IDirect3DDevice8_Release(device
);
3118 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
3120 device_desc
.device_window
= device_window
;
3121 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
3123 skip("Failed to create a D3D device, skipping tests.\n");
3127 filter_messages
= NULL
;
3129 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3130 hr
= reset_device(device
, &device_desc
);
3131 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3133 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3134 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3135 (LONG_PTR
)test_proc
, proc
);
3137 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3138 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
3140 device_desc
.flags
= 0;
3141 hr
= reset_device(device
, &device_desc
);
3142 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3144 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3145 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3146 (LONG_PTR
)test_proc
, proc
);
3148 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3149 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3150 (LONG_PTR
)test_proc
, proc
);
3152 filter_messages
= device_window
;
3154 ref
= IDirect3DDevice8_Release(device
);
3155 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
3158 filter_messages
= NULL
;
3159 IDirect3D8_Release(d3d8
);
3161 SetEvent(thread_params
.test_finished
);
3162 WaitForSingleObject(thread
, INFINITE
);
3163 CloseHandle(thread_params
.test_finished
);
3164 CloseHandle(thread_params
.window_created
);
3165 CloseHandle(thread
);
3167 DestroyWindow(device_window
);
3168 DestroyWindow(focus_window
);
3169 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL
));
3172 static inline void set_fpu_cw(WORD cw
)
3174 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3175 #define D3D8_TEST_SET_FPU_CW 1
3176 __asm__
volatile ("fnclex");
3177 __asm__
volatile ("fldcw %0" : : "m" (cw
));
3178 #elif defined(__i386__) && defined(_MSC_VER)
3179 #define D3D8_TEST_SET_FPU_CW 1
3185 static inline WORD
get_fpu_cw(void)
3188 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3189 #define D3D8_TEST_GET_FPU_CW 1
3190 __asm__
volatile ("fnstcw %0" : "=m" (cw
));
3191 #elif defined(__i386__) && defined(_MSC_VER)
3192 #define D3D8_TEST_GET_FPU_CW 1
3198 static WORD callback_cw
, callback_set_cw
;
3199 static DWORD callback_tid
;
3201 static HRESULT WINAPI
dummy_object_QueryInterface(IUnknown
*iface
, REFIID riid
, void **out
)
3204 return E_NOINTERFACE
;
3207 static ULONG WINAPI
dummy_object_AddRef(IUnknown
*iface
)
3209 callback_cw
= get_fpu_cw();
3210 set_fpu_cw(callback_set_cw
);
3211 callback_tid
= GetCurrentThreadId();
3215 static ULONG WINAPI
dummy_object_Release(IUnknown
*iface
)
3217 callback_cw
= get_fpu_cw();
3218 set_fpu_cw(callback_set_cw
);
3219 callback_tid
= GetCurrentThreadId();
3223 static const IUnknownVtbl dummy_object_vtbl
=
3225 dummy_object_QueryInterface
,
3226 dummy_object_AddRef
,
3227 dummy_object_Release
,
3230 static const GUID d3d8_private_data_test_guid
=
3235 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
3238 static void test_fpu_setup(void)
3240 #if defined(D3D8_TEST_SET_FPU_CW) && defined(D3D8_TEST_GET_FPU_CW)
3241 struct device_desc device_desc
;
3242 IDirect3DDevice8
*device
;
3243 D3DDISPLAYMODE d3ddm
;
3248 IDirect3DSurface8
*surface
;
3249 IUnknown dummy_object
= {&dummy_object_vtbl
};
3251 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_CAPTION
, 0, 0,
3252 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, 0, 0, 0, 0);
3253 ok(!!window
, "Failed to create a window.\n");
3254 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3255 ok(!!d3d8
, "Failed to create a D3D object.\n");
3257 hr
= IDirect3D8_GetAdapterDisplayMode(d3d8
, D3DADAPTER_DEFAULT
, &d3ddm
);
3258 ok(SUCCEEDED(hr
), "GetAdapterDisplayMode failed, hr %#x.\n", hr
);
3260 device_desc
.device_window
= window
;
3261 device_desc
.width
= 640;
3262 device_desc
.height
= 480;
3263 device_desc
.flags
= 0;
3267 ok(cw
== 0xf60, "cw is %#x, expected 0xf60.\n", cw
);
3269 if (!(device
= create_device(d3d8
, window
, &device_desc
)))
3271 skip("Failed to create a 3D device, skipping test.\n");
3277 ok(cw
== 0x7f, "cw is %#x, expected 0x7f.\n", cw
);
3279 hr
= IDirect3DDevice8_GetRenderTarget(device
, &surface
);
3280 ok(SUCCEEDED(hr
), "Failed to get render target surface, hr %#x.\n", hr
);
3282 callback_set_cw
= 0xf60;
3283 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
3284 &dummy_object
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
3285 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
3286 ok(callback_cw
== 0x7f, "Callback cw is %#x, expected 0x7f.\n", callback_cw
);
3287 ok(callback_tid
== GetCurrentThreadId(), "Got unexpected thread id.\n");
3289 ok(cw
== 0xf60, "cw is %#x, expected 0xf60.\n", cw
);
3292 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
3293 &dummy_object
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
3294 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
3295 ok(callback_cw
== 0xf60, "Callback cw is %#x, expected 0xf60.\n", callback_cw
);
3296 ok(callback_tid
== GetCurrentThreadId(), "Got unexpected thread id.\n");
3298 callback_set_cw
= 0x7f;
3301 IDirect3DSurface8_Release(surface
);
3304 IDirect3DDevice8_Release(device
);
3305 ok(callback_cw
== 0x7f, "Callback cw is %#x, expected 0x7f.\n", callback_cw
);
3306 ok(callback_tid
== GetCurrentThreadId(), "Got unexpected thread id.\n");
3309 ok(cw
== 0x7f, "cw is %#x, expected 0x7f.\n", cw
);
3312 ok(cw
== 0xf60, "cw is %#x, expected 0xf60.\n", cw
);
3314 device_desc
.flags
= CREATE_DEVICE_FPU_PRESERVE
;
3315 device
= create_device(d3d8
, window
, &device_desc
);
3316 ok(!!device
, "CreateDevice failed.\n");
3319 ok(cw
== 0xf60, "cw is %#x, expected 0xf60.\n", cw
);
3321 hr
= IDirect3DDevice8_GetRenderTarget(device
, &surface
);
3322 ok(SUCCEEDED(hr
), "Failed to get render target surface, hr %#x.\n", hr
);
3325 callback_set_cw
= 0x37f;
3326 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
3327 &dummy_object
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
3328 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
3329 ok(callback_cw
== 0xf60, "Callback cw is %#x, expected 0xf60.\n", callback_cw
);
3330 ok(callback_tid
== GetCurrentThreadId(), "Got unexpected thread id.\n");
3332 ok(cw
== 0x37f, "cw is %#x, expected 0x37f.\n", cw
);
3334 IDirect3DSurface8_Release(surface
);
3337 IDirect3DDevice8_Release(device
);
3338 ok(callback_cw
== 0x37f, "Callback cw is %#x, expected 0x37f.\n", callback_cw
);
3339 ok(callback_tid
== GetCurrentThreadId(), "Got unexpected thread id.\n");
3342 DestroyWindow(window
);
3343 IDirect3D8_Release(d3d8
);
3347 static void test_ApplyStateBlock(void)
3349 IDirect3DDevice8
*device
;
3353 DWORD received
, token
;
3355 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3356 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
3357 ok(!!window
, "Failed to create a window.\n");
3358 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3359 ok(!!d3d8
, "Failed to create a D3D object.\n");
3360 if (!(device
= create_device(d3d8
, window
, NULL
)))
3362 skip("Failed to create a 3D device, skipping test.\n");
3366 IDirect3DDevice8_BeginStateBlock(device
);
3367 IDirect3DDevice8_SetRenderState(device
, D3DRS_ZENABLE
, TRUE
);
3368 IDirect3DDevice8_EndStateBlock(device
, &token
);
3369 ok(token
, "Received zero stateblock handle.\n");
3370 IDirect3DDevice8_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
3372 hr
= IDirect3DDevice8_GetRenderState(device
, D3DRS_ZENABLE
, &received
);
3373 ok(hr
== D3D_OK
, "Expected D3D_OK, received %#x.\n", hr
);
3374 ok(!received
, "Expected = FALSE, received TRUE.\n");
3376 hr
= IDirect3DDevice8_ApplyStateBlock(device
, 0);
3377 ok(hr
== D3D_OK
, "Expected D3D_OK, received %#x.\n", hr
);
3378 hr
= IDirect3DDevice8_GetRenderState(device
, D3DRS_ZENABLE
, &received
);
3379 ok(hr
== D3D_OK
, "Expected D3D_OK, received %#x.\n", hr
);
3380 ok(!received
, "Expected FALSE, received TRUE.\n");
3382 hr
= IDirect3DDevice8_ApplyStateBlock(device
, token
);
3383 ok(hr
== D3D_OK
, "Expected D3D_OK, received %#x.\n", hr
);
3384 hr
= IDirect3DDevice8_GetRenderState(device
, D3DRS_ZENABLE
, &received
);
3385 ok(hr
== D3D_OK
, "Expected D3D_OK, received %#x.\n", hr
);
3386 ok(received
, "Expected TRUE, received FALSE.\n");
3388 IDirect3DDevice8_DeleteStateBlock(device
, token
);
3389 IDirect3DDevice8_Release(device
);
3391 IDirect3D8_Release(d3d8
);
3392 DestroyWindow(window
);
3395 static void test_depth_stencil_size(void)
3397 IDirect3DDevice8
*device
;
3398 IDirect3DSurface8
*ds
, *rt
, *ds_bigger
, *ds_bigger2
;
3399 IDirect3DSurface8
*surf
;
3404 hwnd
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3405 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
3406 ok(!!hwnd
, "Failed to create a window.\n");
3407 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3408 ok(!!d3d8
, "Failed to create a D3D object.\n");
3410 if (!(device
= create_device(d3d8
, hwnd
, NULL
)))
3412 skip("Failed to create a 3D device, skipping test.\n");
3416 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 64, 64, D3DFMT_A8R8G8B8
, D3DMULTISAMPLE_NONE
, FALSE
, &rt
);
3417 ok(SUCCEEDED(hr
), "IDirect3DDevice8_CreateRenderTarget failed, hr %#x.\n", hr
);
3418 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 32, 32, D3DFMT_D24X8
, D3DMULTISAMPLE_NONE
, &ds
);
3419 ok(SUCCEEDED(hr
), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr
);
3420 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 128, 128, D3DFMT_D24X8
, D3DMULTISAMPLE_NONE
, &ds_bigger
);
3421 ok(SUCCEEDED(hr
), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr
);
3422 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 128, 128, D3DFMT_D24X8
, D3DMULTISAMPLE_NONE
, &ds_bigger2
);
3423 ok(SUCCEEDED(hr
), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr
);
3425 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, ds
);
3426 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_SetRenderTarget returned %#x, expected D3DERR_INVALIDCALL.\n", hr
);
3427 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, ds_bigger
);
3428 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr
);
3430 /* try to set the small ds without changing the render target at the same time */
3431 hr
= IDirect3DDevice8_SetRenderTarget(device
, NULL
, ds
);
3432 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_SetRenderTarget returned %#x, expected D3DERR_INVALIDCALL.\n", hr
);
3433 hr
= IDirect3DDevice8_SetRenderTarget(device
, NULL
, ds_bigger2
);
3434 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr
);
3436 hr
= IDirect3DDevice8_GetRenderTarget(device
, &surf
);
3437 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetRenderTarget failed, hr %#x.\n", hr
);
3438 ok(surf
== rt
, "The render target is %p, expected %p\n", surf
, rt
);
3439 IDirect3DSurface8_Release(surf
);
3440 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surf
);
3441 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetDepthStencilSurface failed, hr %#x.\n", hr
);
3442 ok(surf
== ds_bigger2
, "The depth stencil is %p, expected %p\n", surf
, ds_bigger2
);
3443 IDirect3DSurface8_Release(surf
);
3445 hr
= IDirect3DDevice8_SetRenderTarget(device
, NULL
, NULL
);
3446 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr
);
3447 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surf
);
3448 ok(FAILED(hr
), "IDirect3DDevice8_GetDepthStencilSurface should have failed, hr %#x.\n", hr
);
3449 ok(surf
== NULL
, "The depth stencil is %p, expected NULL\n", surf
);
3450 if (surf
) IDirect3DSurface8_Release(surf
);
3452 IDirect3DSurface8_Release(rt
);
3453 IDirect3DSurface8_Release(ds
);
3454 IDirect3DSurface8_Release(ds_bigger
);
3455 IDirect3DSurface8_Release(ds_bigger2
);
3458 IDirect3D8_Release(d3d8
);
3459 DestroyWindow(hwnd
);
3462 static void test_window_style(void)
3464 RECT focus_rect
, fullscreen_rect
, r
;
3465 LONG device_style
, device_exstyle
;
3466 LONG focus_style
, focus_exstyle
;
3467 struct device_desc device_desc
;
3468 LONG style
, expected_style
;
3469 IDirect3DDevice8
*device
;
3475 focus_window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3476 0, 0, registry_mode
.dmPelsWidth
/ 2, registry_mode
.dmPelsHeight
/ 2, 0, 0, 0, 0);
3477 device_window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3478 0, 0, registry_mode
.dmPelsWidth
/ 2, registry_mode
.dmPelsHeight
/ 2, 0, 0, 0, 0);
3479 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3480 ok(!!d3d8
, "Failed to create a D3D object.\n");
3482 device_style
= GetWindowLongA(device_window
, GWL_STYLE
);
3483 device_exstyle
= GetWindowLongA(device_window
, GWL_EXSTYLE
);
3484 focus_style
= GetWindowLongA(focus_window
, GWL_STYLE
);
3485 focus_exstyle
= GetWindowLongA(focus_window
, GWL_EXSTYLE
);
3487 SetRect(&fullscreen_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
3488 GetWindowRect(focus_window
, &focus_rect
);
3490 device_desc
.device_window
= device_window
;
3491 device_desc
.width
= registry_mode
.dmPelsWidth
;
3492 device_desc
.height
= registry_mode
.dmPelsHeight
;
3493 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3494 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
3496 skip("Failed to create a D3D device, skipping tests.\n");
3500 style
= GetWindowLongA(device_window
, GWL_STYLE
);
3501 expected_style
= device_style
| WS_VISIBLE
;
3502 todo_wine
ok(style
== expected_style
, "Expected device window style %#x, got %#x.\n",
3503 expected_style
, style
);
3504 style
= GetWindowLongA(device_window
, GWL_EXSTYLE
);
3505 expected_style
= device_exstyle
| WS_EX_TOPMOST
;
3506 todo_wine
ok(style
== expected_style
, "Expected device window extended style %#x, got %#x.\n",
3507 expected_style
, style
);
3509 style
= GetWindowLongA(focus_window
, GWL_STYLE
);
3510 ok(style
== focus_style
, "Expected focus window style %#x, got %#x.\n",
3511 focus_style
, style
);
3512 style
= GetWindowLongA(focus_window
, GWL_EXSTYLE
);
3513 ok(style
== focus_exstyle
, "Expected focus window extended style %#x, got %#x.\n",
3514 focus_exstyle
, style
);
3516 GetWindowRect(device_window
, &r
);
3517 ok(EqualRect(&r
, &fullscreen_rect
), "Expected %s, got %s.\n",
3518 wine_dbgstr_rect(&fullscreen_rect
), wine_dbgstr_rect(&r
));
3519 GetClientRect(device_window
, &r
);
3520 todo_wine
ok(!EqualRect(&r
, &fullscreen_rect
), "Client rect and window rect are equal.\n");
3521 GetWindowRect(focus_window
, &r
);
3522 ok(EqualRect(&r
, &focus_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&focus_rect
),
3523 wine_dbgstr_rect(&r
));
3525 device_desc
.flags
= 0;
3526 hr
= reset_device(device
, &device_desc
);
3527 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3529 style
= GetWindowLongA(device_window
, GWL_STYLE
);
3530 expected_style
= device_style
| WS_VISIBLE
;
3531 ok(style
== expected_style
, "Expected device window style %#x, got %#x.\n",
3532 expected_style
, style
);
3533 style
= GetWindowLongA(device_window
, GWL_EXSTYLE
);
3534 expected_style
= device_exstyle
| WS_EX_TOPMOST
;
3535 ok(style
== expected_style
, "Expected device window extended style %#x, got %#x.\n",
3536 expected_style
, style
);
3538 style
= GetWindowLongA(focus_window
, GWL_STYLE
);
3539 ok(style
== focus_style
, "Expected focus window style %#x, got %#x.\n",
3540 focus_style
, style
);
3541 style
= GetWindowLongA(focus_window
, GWL_EXSTYLE
);
3542 ok(style
== focus_exstyle
, "Expected focus window extended style %#x, got %#x.\n",
3543 focus_exstyle
, style
);
3545 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3546 hr
= reset_device(device
, &device_desc
);
3547 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3548 ret
= SetForegroundWindow(GetDesktopWindow());
3549 ok(ret
, "Failed to set foreground window.\n");
3551 style
= GetWindowLongA(device_window
, GWL_STYLE
);
3552 expected_style
= device_style
| WS_MINIMIZE
| WS_VISIBLE
;
3553 todo_wine
ok(style
== expected_style
, "Expected device window style %#x, got %#x.\n",
3554 expected_style
, style
);
3555 style
= GetWindowLongA(device_window
, GWL_EXSTYLE
);
3556 expected_style
= device_exstyle
| WS_EX_TOPMOST
;
3557 todo_wine
ok(style
== expected_style
, "Expected device window extended style %#x, got %#x.\n",
3558 expected_style
, style
);
3560 style
= GetWindowLongA(focus_window
, GWL_STYLE
);
3561 ok(style
== focus_style
, "Expected focus window style %#x, got %#x.\n",
3562 focus_style
, style
);
3563 style
= GetWindowLongA(focus_window
, GWL_EXSTYLE
);
3564 ok(style
== focus_exstyle
, "Expected focus window extended style %#x, got %#x.\n",
3565 focus_exstyle
, style
);
3567 /* Follow-up tests fail on native if the device is destroyed while lost. */
3568 ShowWindow(focus_window
, SW_MINIMIZE
);
3569 ShowWindow(focus_window
, SW_RESTORE
);
3570 ret
= SetForegroundWindow(focus_window
);
3571 ok(ret
, "Failed to set foreground window.\n");
3573 hr
= reset_device(device
, &device_desc
);
3574 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3576 ref
= IDirect3DDevice8_Release(device
);
3577 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
3580 IDirect3D8_Release(d3d8
);
3582 DestroyWindow(device_window
);
3583 DestroyWindow(focus_window
);
3586 static void test_unsupported_shaders(void)
3588 IDirect3DDevice8
*device
;
3596 static const DWORD vs_2_0
[] =
3598 0xfffe0200, /* vs_2_0 */
3599 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
3600 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
3601 0x03000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
3602 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
3603 0x0000ffff /* end */
3605 static const DWORD ps_2_0
[] =
3607 0xffff0200, /* ps_2_0 */
3608 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
3609 0x03000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
3610 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
3611 0x0000ffff /* end */
3616 def c255
, 1.0, 1.0, 1.0, 1.0
3620 static const DWORD vs_1_255
[] =
3623 0x0000001f, 0x80000000, 0x900f0000,
3624 0x00000051, 0xa00f00ff, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
3625 0x00000002, 0x800f0000, 0x90e40000, 0xa0e400ff,
3626 0x00000001, 0xc00f0000, 0x80e40000,
3632 def c256
, 1.0, 1.0, 1.0, 1.0
3636 static const DWORD vs_1_256
[] =
3639 0x0000001f, 0x80000000, 0x900f0000,
3640 0x00000051, 0xa00f0100, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
3641 0x00000002, 0x800f0000, 0x90e40000, 0xa0e40100,
3642 0x00000001, 0xc00f0000, 0x80e40000,
3646 static const DWORD decl
[] =
3649 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
),
3653 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3654 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
3655 ok(!!window
, "Failed to create a window.\n");
3656 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
3657 ok(!!d3d
, "Failed to create a D3D object.\n");
3658 if (!(device
= create_device(d3d
, window
, NULL
)))
3660 skip("Failed to create a D3D device, skipping tests.\n");
3661 IDirect3D8_Release(d3d
);
3662 DestroyWindow(window
);
3666 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, simple_ps
, &vs
, 0);
3667 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
3669 hr
= IDirect3DDevice8_CreatePixelShader(device
, simple_vs
, &ps
);
3670 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
3672 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, vs_2_0
, &vs
, 0);
3673 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
3675 hr
= IDirect3DDevice8_CreatePixelShader(device
, ps_2_0
, &ps
);
3676 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
3678 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
3679 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
3680 if (caps
.MaxVertexShaderConst
< 256)
3682 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, vs_1_255
, &vs
, 0);
3683 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3687 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, vs_1_255
, &vs
, 0);
3688 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3689 hr
= IDirect3DDevice8_DeleteVertexShader(device
, vs
);
3690 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
3691 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, vs_1_256
, &vs
, 0);
3692 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3695 refcount
= IDirect3DDevice8_Release(device
);
3696 ok(!refcount
, "Device has %u references left.\n", refcount
);
3697 IDirect3D8_Release(d3d
);
3698 DestroyWindow(window
);
3701 static void test_mode_change(void)
3703 RECT d3d_rect
, focus_rect
, r
;
3704 struct device_desc device_desc
;
3705 IDirect3DSurface8
*backbuffer
;
3706 IDirect3DDevice8
*device
;
3707 D3DSURFACE_DESC desc
;
3711 UINT adapter_mode_count
, i
;
3715 D3DDISPLAYMODE d3ddm
;
3716 DWORD d3d_width
= 0, d3d_height
= 0, user32_width
= 0, user32_height
= 0;
3718 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3719 ok(!!d3d8
, "Failed to create a D3D object.\n");
3721 adapter_mode_count
= IDirect3D8_GetAdapterModeCount(d3d8
, D3DADAPTER_DEFAULT
);
3722 for (i
= 0; i
< adapter_mode_count
; ++i
)
3724 hr
= IDirect3D8_EnumAdapterModes(d3d8
, D3DADAPTER_DEFAULT
, i
, &d3ddm
);
3725 ok(SUCCEEDED(hr
), "Failed to enumerate display mode, hr %#x.\n", hr
);
3727 if (d3ddm
.Format
!= D3DFMT_X8R8G8B8
)
3729 if (d3ddm
.Width
== registry_mode
.dmPelsWidth
&& d3ddm
.Height
== registry_mode
.dmPelsHeight
)
3731 /* The r200 driver on Windows XP enumerates modes like 320x200 and 320x240 but
3732 * refuses to create a device at these sizes. */
3733 if (d3ddm
.Width
< 640 || d3ddm
.Height
< 480)
3738 user32_width
= d3ddm
.Width
;
3739 user32_height
= d3ddm
.Height
;
3743 /* Make sure the d3d mode is smaller in width or height and at most
3744 * equal in the other dimension than the mode passed to
3745 * ChangeDisplaySettings. Otherwise Windows shrinks the window to
3746 * the ChangeDisplaySettings parameters + 12. */
3747 if (d3ddm
.Width
== user32_width
&& d3ddm
.Height
== user32_height
)
3749 if (d3ddm
.Width
<= user32_width
&& d3ddm
.Height
<= user32_height
)
3751 d3d_width
= d3ddm
.Width
;
3752 d3d_height
= d3ddm
.Height
;
3755 if (user32_width
<= d3ddm
.Width
&& user32_height
<= d3ddm
.Height
)
3757 d3d_width
= user32_width
;
3758 d3d_height
= user32_height
;
3759 user32_width
= d3ddm
.Width
;
3760 user32_height
= d3ddm
.Height
;
3767 skip("Could not find adequate modes, skipping mode tests.\n");
3768 IDirect3D8_Release(d3d8
);
3772 memset(&devmode
, 0, sizeof(devmode
));
3773 devmode
.dmSize
= sizeof(devmode
);
3774 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
3775 devmode
.dmPelsWidth
= user32_width
;
3776 devmode
.dmPelsHeight
= user32_height
;
3777 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
3778 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3780 /* Make the windows visible, otherwise device::release does not restore the mode if
3781 * the application is not in foreground like on the testbot. */
3782 focus_window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
3783 0, 0, user32_width
/ 2, user32_height
/ 2, 0, 0, 0, 0);
3784 device_window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
3785 0, 0, user32_width
/ 2, user32_height
/ 2, 0, 0, 0, 0);
3787 SetRect(&d3d_rect
, 0, 0, d3d_width
, d3d_height
);
3788 GetWindowRect(focus_window
, &focus_rect
);
3790 device_desc
.device_window
= device_window
;
3791 device_desc
.width
= d3d_width
;
3792 device_desc
.height
= d3d_height
;
3793 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3794 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
3796 skip("Failed to create a D3D device, skipping tests.\n");
3797 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
3798 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3802 devmode
.dmPelsWidth
= user32_width
;
3803 devmode
.dmPelsHeight
= user32_height
;
3804 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
3805 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3807 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3808 ok(ret
, "Failed to get display mode.\n");
3809 ok(devmode
.dmPelsWidth
== user32_width
&& devmode
.dmPelsHeight
== user32_height
,
3810 "Expected resolution %ux%u, got %ux%u.\n",
3811 user32_width
, user32_height
, devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
3813 GetWindowRect(device_window
, &r
);
3814 ok(EqualRect(&r
, &d3d_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&d3d_rect
),
3815 wine_dbgstr_rect(&r
));
3816 GetWindowRect(focus_window
, &r
);
3817 ok(EqualRect(&r
, &focus_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&focus_rect
),
3818 wine_dbgstr_rect(&r
));
3820 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
3821 ok(SUCCEEDED(hr
), "Failed to get backbuffer, hr %#x.\n", hr
);
3822 hr
= IDirect3DSurface8_GetDesc(backbuffer
, &desc
);
3823 ok(SUCCEEDED(hr
), "Failed to get backbuffer desc, hr %#x.\n", hr
);
3824 ok(desc
.Width
== d3d_width
, "Got unexpected backbuffer width %u, expected %u.\n",
3825 desc
.Width
, d3d_width
);
3826 ok(desc
.Height
== d3d_height
, "Got unexpected backbuffer height %u, expected %u.\n",
3827 desc
.Height
, d3d_height
);
3828 IDirect3DSurface8_Release(backbuffer
);
3830 refcount
= IDirect3DDevice8_Release(device
);
3831 ok(!refcount
, "Device has %u references left.\n", refcount
);
3833 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3834 ok(ret
, "Failed to get display mode.\n");
3835 todo_wine
ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
3836 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
3837 "Expected resolution %ux%u, got %ux%u.\n",
3838 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
3840 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
3841 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3843 /* The mode restore also happens when the device was created at the original screen size. */
3845 device_desc
.device_window
= device_window
;
3846 device_desc
.width
= registry_mode
.dmPelsWidth
;
3847 device_desc
.height
= registry_mode
.dmPelsHeight
;
3848 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3849 ok(!!(device
= create_device(d3d8
, focus_window
, &device_desc
)), "Failed to create a D3D device.\n");
3851 devmode
.dmPelsWidth
= user32_width
;
3852 devmode
.dmPelsHeight
= user32_height
;
3853 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
3854 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3856 refcount
= IDirect3DDevice8_Release(device
);
3857 ok(!refcount
, "Device has %u references left.\n", refcount
);
3859 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3860 ok(ret
, "Failed to get display mode.\n");
3861 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
3862 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
3863 "Expected resolution %ux%u, got %ux%u.\n",
3864 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
3867 DestroyWindow(device_window
);
3868 DestroyWindow(focus_window
);
3869 IDirect3D8_Release(d3d8
);
3872 static void test_device_window_reset(void)
3874 RECT fullscreen_rect
, device_rect
, r
;
3875 struct device_desc device_desc
;
3876 IDirect3DDevice8
*device
;
3883 wc
.lpfnWndProc
= test_proc
;
3884 wc
.lpszClassName
= "d3d8_test_wndproc_wc";
3885 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
3887 focus_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3888 0, 0, registry_mode
.dmPelsWidth
/ 2, registry_mode
.dmPelsHeight
/ 2, 0, 0, 0, 0);
3889 device_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3890 0, 0, registry_mode
.dmPelsWidth
/ 2, registry_mode
.dmPelsHeight
/ 2, 0, 0, 0, 0);
3891 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3892 ok(!!d3d8
, "Failed to create a D3D object.\n");
3894 SetRect(&fullscreen_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
3895 GetWindowRect(device_window
, &device_rect
);
3897 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3898 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3899 (LONG_PTR
)test_proc
, proc
);
3900 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3901 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3902 (LONG_PTR
)test_proc
, proc
);
3904 device_desc
.device_window
= NULL
;
3905 device_desc
.width
= registry_mode
.dmPelsWidth
;
3906 device_desc
.height
= registry_mode
.dmPelsHeight
;
3907 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3908 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
3910 skip("Failed to create a D3D device, skipping tests.\n");
3914 GetWindowRect(focus_window
, &r
);
3915 ok(EqualRect(&r
, &fullscreen_rect
), "Expected %s, got %s.\n",
3916 wine_dbgstr_rect(&fullscreen_rect
), wine_dbgstr_rect(&r
));
3917 GetWindowRect(device_window
, &r
);
3918 ok(EqualRect(&r
, &device_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&device_rect
),
3919 wine_dbgstr_rect(&r
));
3921 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3922 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3923 (LONG_PTR
)test_proc
, proc
);
3924 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3925 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
3927 device_desc
.device_window
= device_window
;
3928 hr
= reset_device(device
, &device_desc
);
3929 ok(SUCCEEDED(hr
), "Failed to reset device.\n");
3931 GetWindowRect(focus_window
, &r
);
3932 ok(EqualRect(&r
, &fullscreen_rect
), "Expected %s, got %s.\n",
3933 wine_dbgstr_rect(&fullscreen_rect
), wine_dbgstr_rect(&r
));
3934 GetWindowRect(device_window
, &r
);
3935 ok(EqualRect(&r
, &fullscreen_rect
), "Expected %s, got %s.\n",
3936 wine_dbgstr_rect(&fullscreen_rect
), wine_dbgstr_rect(&r
));
3938 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3939 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3940 (LONG_PTR
)test_proc
, proc
);
3941 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3942 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
3944 ref
= IDirect3DDevice8_Release(device
);
3945 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
3948 IDirect3D8_Release(d3d8
);
3949 DestroyWindow(device_window
);
3950 DestroyWindow(focus_window
);
3951 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL
));
3954 static void depth_blit_test(void)
3956 IDirect3DDevice8
*device
= NULL
;
3957 IDirect3DSurface8
*backbuffer
, *ds1
, *ds2
, *ds3
;
3959 const POINT dst_point
= {0, 0};
3964 hwnd
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3965 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
3966 ok(!!hwnd
, "Failed to create a window.\n");
3967 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3968 ok(!!d3d8
, "Failed to create a D3D object.\n");
3970 if (!(device
= create_device(d3d8
, hwnd
, NULL
)))
3972 skip("Failed to create a D3D device, skipping tests.\n");
3976 hr
= IDirect3DDevice8_GetRenderTarget(device
, &backbuffer
);
3977 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
3978 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &ds1
);
3979 ok(SUCCEEDED(hr
), "GetDepthStencilSurface failed, hr %#x.\n", hr
);
3980 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 640, 480, D3DFMT_D24S8
, D3DMULTISAMPLE_NONE
, &ds2
);
3981 ok(SUCCEEDED(hr
), "CreateDepthStencilSurface failed, hr %#x.\n", hr
);
3982 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 640, 480, D3DFMT_D24S8
, D3DMULTISAMPLE_NONE
, &ds3
);
3983 ok(SUCCEEDED(hr
), "CreateDepthStencilSurface failed, hr %#x.\n", hr
);
3985 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0, 0.0f
, 0);
3986 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
3989 SetRect(&src_rect
, 0, 0, 320, 240);
3990 hr
= IDirect3DDevice8_CopyRects(device
, ds1
, &src_rect
, 1, ds2
, &dst_point
);
3991 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
3993 SetRect(&src_rect
, 0, 480, 640, 0);
3994 hr
= IDirect3DDevice8_CopyRects(device
, ds1
, &src_rect
, 1, ds2
, &dst_point
);
3995 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
3996 /* Full, explicit. */
3997 SetRect(&src_rect
, 0, 0, 640, 480);
3998 hr
= IDirect3DDevice8_CopyRects(device
, ds1
, &src_rect
, 1, ds2
, &dst_point
);
3999 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
4000 /* Depth -> color blit.*/
4001 hr
= IDirect3DDevice8_CopyRects(device
, ds1
, &src_rect
, 1, backbuffer
, &dst_point
);
4002 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
4003 /* Full, NULL rects, current depth stencil -> unbound depth stencil */
4004 hr
= IDirect3DDevice8_CopyRects(device
, ds1
, NULL
, 0, ds2
, NULL
);
4005 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
4006 /* Full, NULL rects, unbound depth stencil -> current depth stencil */
4007 hr
= IDirect3DDevice8_CopyRects(device
, ds2
, NULL
, 0, ds1
, NULL
);
4008 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
4009 /* Full, NULL rects, unbound depth stencil -> unbound depth stencil */
4010 hr
= IDirect3DDevice8_CopyRects(device
, ds2
, NULL
, 0, ds3
, NULL
);
4011 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
4013 IDirect3DSurface8_Release(backbuffer
);
4014 IDirect3DSurface8_Release(ds3
);
4015 IDirect3DSurface8_Release(ds2
);
4016 IDirect3DSurface8_Release(ds1
);
4019 if (device
) IDirect3DDevice8_Release(device
);
4020 IDirect3D8_Release(d3d8
);
4021 DestroyWindow(hwnd
);
4024 static void test_reset_resources(void)
4026 IDirect3DSurface8
*surface
, *rt
;
4027 IDirect3DTexture8
*texture
;
4028 IDirect3DDevice8
*device
;
4034 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4035 0, 0, 640, 480, 0, 0, 0, 0);
4036 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4037 ok(!!d3d8
, "Failed to create a D3D object.\n");
4039 if (!(device
= create_device(d3d8
, window
, NULL
)))
4041 skip("Failed to create a D3D device, skipping tests.\n");
4045 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 128, 128, D3DFMT_D24S8
,
4046 D3DMULTISAMPLE_NONE
, &surface
);
4047 ok(SUCCEEDED(hr
), "Failed to create depth/stencil surface, hr %#x.\n", hr
);
4049 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
,
4050 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &texture
);
4051 ok(SUCCEEDED(hr
), "Failed to create render target texture, hr %#x.\n", hr
);
4052 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &rt
);
4053 ok(SUCCEEDED(hr
), "Failed to get surface, hr %#x.\n", hr
);
4054 IDirect3DTexture8_Release(texture
);
4056 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, surface
);
4057 ok(SUCCEEDED(hr
), "Failed to set render target surface, hr %#x.\n", hr
);
4058 IDirect3DSurface8_Release(rt
);
4059 IDirect3DSurface8_Release(surface
);
4061 hr
= reset_device(device
, NULL
);
4062 ok(SUCCEEDED(hr
), "Failed to reset device.\n");
4064 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_MONO
, &rt
);
4065 ok(SUCCEEDED(hr
), "Failed to get back buffer, hr %#x.\n", hr
);
4066 hr
= IDirect3DDevice8_GetRenderTarget(device
, &surface
);
4067 ok(SUCCEEDED(hr
), "Failed to get render target surface, hr %#x.\n", hr
);
4068 ok(surface
== rt
, "Got unexpected surface %p for render target.\n", surface
);
4069 IDirect3DSurface8_Release(surface
);
4070 IDirect3DSurface8_Release(rt
);
4072 ref
= IDirect3DDevice8_Release(device
);
4073 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
4076 IDirect3D8_Release(d3d8
);
4077 DestroyWindow(window
);
4080 static void test_set_rt_vp_scissor(void)
4082 IDirect3DDevice8
*device
;
4083 IDirect3DSurface8
*rt
;
4091 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4092 0, 0, 640, 480, 0, 0, 0, 0);
4093 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4094 ok(!!d3d8
, "Failed to create a D3D object.\n");
4095 if (!(device
= create_device(d3d8
, window
, NULL
)))
4097 skip("Failed to create a D3D device, skipping tests.\n");
4098 IDirect3D8_Release(d3d8
);
4099 DestroyWindow(window
);
4103 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 128, 128, D3DFMT_A8R8G8B8
,
4104 D3DMULTISAMPLE_NONE
, FALSE
, &rt
);
4105 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
4107 hr
= IDirect3DDevice8_GetViewport(device
, &vp
);
4108 ok(SUCCEEDED(hr
), "Failed to get viewport, hr %#x.\n", hr
);
4109 ok(!vp
.X
, "Got unexpected vp.X %u.\n", vp
.X
);
4110 ok(!vp
.Y
, "Got unexpected vp.Y %u.\n", vp
.Y
);
4111 ok(vp
.Width
== 640, "Got unexpected vp.Width %u.\n", vp
.Width
);
4112 ok(vp
.Height
== 480, "Got unexpected vp.Height %u.\n", vp
.Height
);
4113 ok(vp
.MinZ
== 0.0f
, "Got unexpected vp.MinZ %.8e.\n", vp
.MinZ
);
4114 ok(vp
.MaxZ
== 1.0f
, "Got unexpected vp.MaxZ %.8e.\n", vp
.MaxZ
);
4116 hr
= IDirect3DDevice8_BeginStateBlock(device
);
4117 ok(SUCCEEDED(hr
), "Failed to begin stateblock, hr %#x.\n", hr
);
4119 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, NULL
);
4120 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
4122 hr
= IDirect3DDevice8_EndStateBlock(device
, &stateblock
);
4123 ok(SUCCEEDED(hr
), "Failed to end stateblock, hr %#x.\n", hr
);
4124 hr
= IDirect3DDevice8_DeleteStateBlock(device
, stateblock
);
4125 ok(SUCCEEDED(hr
), "Failed to delete stateblock, hr %#x.\n", hr
);
4127 hr
= IDirect3DDevice8_GetViewport(device
, &vp
);
4128 ok(SUCCEEDED(hr
), "Failed to get viewport, hr %#x.\n", hr
);
4129 ok(!vp
.X
, "Got unexpected vp.X %u.\n", vp
.X
);
4130 ok(!vp
.Y
, "Got unexpected vp.Y %u.\n", vp
.Y
);
4131 ok(vp
.Width
== 128, "Got unexpected vp.Width %u.\n", vp
.Width
);
4132 ok(vp
.Height
== 128, "Got unexpected vp.Height %u.\n", vp
.Height
);
4133 ok(vp
.MinZ
== 0.0f
, "Got unexpected vp.MinZ %.8e.\n", vp
.MinZ
);
4134 ok(vp
.MaxZ
== 1.0f
, "Got unexpected vp.MaxZ %.8e.\n", vp
.MaxZ
);
4136 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, NULL
);
4137 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
4145 hr
= IDirect3DDevice8_SetViewport(device
, &vp
);
4146 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
4148 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, NULL
);
4149 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
4151 hr
= IDirect3DDevice8_GetViewport(device
, &vp
);
4152 ok(SUCCEEDED(hr
), "Failed to get viewport, hr %#x.\n", hr
);
4153 ok(!vp
.X
, "Got unexpected vp.X %u.\n", vp
.X
);
4154 ok(!vp
.Y
, "Got unexpected vp.Y %u.\n", vp
.Y
);
4155 ok(vp
.Width
== 128, "Got unexpected vp.Width %u.\n", vp
.Width
);
4156 ok(vp
.Height
== 128, "Got unexpected vp.Height %u.\n", vp
.Height
);
4157 ok(vp
.MinZ
== 0.0f
, "Got unexpected vp.MinZ %.8e.\n", vp
.MinZ
);
4158 ok(vp
.MaxZ
== 1.0f
, "Got unexpected vp.MaxZ %.8e.\n", vp
.MaxZ
);
4160 IDirect3DSurface8_Release(rt
);
4161 refcount
= IDirect3DDevice8_Release(device
);
4162 ok(!refcount
, "Device has %u references left.\n", refcount
);
4163 IDirect3D8_Release(d3d8
);
4164 DestroyWindow(window
);
4167 static void test_validate_vs(void)
4171 0xfffe0101, /* vs_1_1 */
4172 0x00000009, 0xc0010000, 0x90e40000, 0xa0e40000, /* dp4 oPos.x, v0, c0 */
4173 0x00000009, 0xc0020000, 0x90e40000, 0xa0e40001, /* dp4 oPos.y, v0, c1 */
4174 0x00000009, 0xc0040000, 0x90e40000, 0xa0e40002, /* dp4 oPos.z, v0, c2 */
4175 0x00000009, 0xc0080000, 0x90e40000, 0xa0e40003, /* dp4 oPos.w, v0, c3 */
4176 0x0000ffff, /* end */
4180 hr
= ValidateVertexShader(0, 0, 0, 0, 0);
4181 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4182 hr
= ValidateVertexShader(0, 0, 0, 1, 0);
4183 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4184 hr
= ValidateVertexShader(vs
, 0, 0, 0, 0);
4185 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4187 hr
= ValidateVertexShader(vs
, 0, 0, 1, 0);
4188 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4189 /* Seems to do some version checking. */
4190 *vs
= 0xfffe0100; /* vs_1_0 */
4191 hr
= ValidateVertexShader(vs
, 0, 0, 0, 0);
4192 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4194 *vs
= 0xfffe0102; /* bogus version */
4195 hr
= ValidateVertexShader(vs
, 0, 0, 1, 0);
4196 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4197 /* I've seen that applications always pass the 2nd and 3rd parameter as 0.
4198 * Simple test with non-zero parameters. */
4199 *vs
= 0xfffe0101; /* vs_1_1 */
4200 hr
= ValidateVertexShader(vs
, vs
, 0, 1, 0);
4201 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4203 hr
= ValidateVertexShader(vs
, 0, vs
, 1, 0);
4204 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4205 /* I've seen the 4th parameter always passed as either 0 or 1, but passing
4206 * other values doesn't seem to hurt. */
4207 hr
= ValidateVertexShader(vs
, 0, 0, 12345, 0);
4208 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4209 /* What is the 5th parameter? The following seems to work ok. */
4210 hr
= ValidateVertexShader(vs
, 0, 0, 1, vs
);
4211 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4214 static void test_validate_ps(void)
4218 0xffff0101, /* ps_1_1 */
4219 0x00000051, 0xa00f0001, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
4220 0x00000042, 0xb00f0000, /* tex t0 */
4221 0x00000008, 0x800f0000, 0xa0e40001, 0xa0e40000, /* dp3 r0, c1, c0 */
4222 0x00000005, 0x800f0000, 0x90e40000, 0x80e40000, /* mul r0, v0, r0 */
4223 0x00000005, 0x800f0000, 0xb0e40000, 0x80e40000, /* mul r0, t0, r0 */
4224 0x0000ffff, /* end */
4228 hr
= ValidatePixelShader(0, 0, 0, 0);
4229 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4230 hr
= ValidatePixelShader(0, 0, 1, 0);
4231 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4232 hr
= ValidatePixelShader(ps
, 0, 0, 0);
4233 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4235 hr
= ValidatePixelShader(ps
, 0, 1, 0);
4236 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4237 /* Seems to do some version checking. */
4238 *ps
= 0xffff0105; /* bogus version */
4239 hr
= ValidatePixelShader(ps
, 0, 1, 0);
4240 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4241 /* I've seen that applications always pass the 2nd parameter as 0.
4242 * Simple test with a non-zero parameter. */
4243 *ps
= 0xffff0101; /* ps_1_1 */
4244 hr
= ValidatePixelShader(ps
, ps
, 1, 0);
4245 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4246 /* I've seen the 3rd parameter always passed as either 0 or 1, but passing
4247 * other values doesn't seem to hurt. */
4248 hr
= ValidatePixelShader(ps
, 0, 12345, 0);
4249 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4250 /* What is the 4th parameter? The following seems to work ok. */
4251 hr
= ValidatePixelShader(ps
, 0, 1, ps
);
4252 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4255 static void test_volume_get_container(void)
4257 IDirect3DVolumeTexture8
*texture
= NULL
;
4258 IDirect3DVolume8
*volume
= NULL
;
4259 IDirect3DDevice8
*device
;
4260 IUnknown
*container
;
4267 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4268 0, 0, 640, 480, 0, 0, 0, 0);
4269 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4270 ok(!!d3d8
, "Failed to create a D3D object.\n");
4271 if (!(device
= create_device(d3d8
, window
, NULL
)))
4273 skip("Failed to create a D3D device, skipping tests.\n");
4274 IDirect3D8_Release(d3d8
);
4275 DestroyWindow(window
);
4279 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
4280 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
4281 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
))
4283 skip("No volume texture support, skipping tests.\n");
4284 IDirect3DDevice8_Release(device
);
4285 IDirect3D8_Release(d3d8
);
4286 DestroyWindow(window
);
4290 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 128, 128, 128, 1, 0,
4291 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &texture
);
4292 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
4293 ok(!!texture
, "Got unexpected texture %p.\n", texture
);
4295 hr
= IDirect3DVolumeTexture8_GetVolumeLevel(texture
, 0, &volume
);
4296 ok(SUCCEEDED(hr
), "Failed to get volume level, hr %#x.\n", hr
);
4297 ok(!!volume
, "Got unexpected volume %p.\n", volume
);
4299 /* These should work... */
4301 hr
= IDirect3DVolume8_GetContainer(volume
, &IID_IUnknown
, (void **)&container
);
4302 ok(SUCCEEDED(hr
), "Failed to get volume container, hr %#x.\n", hr
);
4303 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4304 IUnknown_Release(container
);
4307 hr
= IDirect3DVolume8_GetContainer(volume
, &IID_IDirect3DResource8
, (void **)&container
);
4308 ok(SUCCEEDED(hr
), "Failed to get volume container, hr %#x.\n", hr
);
4309 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4310 IUnknown_Release(container
);
4313 hr
= IDirect3DVolume8_GetContainer(volume
, &IID_IDirect3DBaseTexture8
, (void **)&container
);
4314 ok(SUCCEEDED(hr
), "Failed to get volume container, hr %#x.\n", hr
);
4315 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4316 IUnknown_Release(container
);
4319 hr
= IDirect3DVolume8_GetContainer(volume
, &IID_IDirect3DVolumeTexture8
, (void **)&container
);
4320 ok(SUCCEEDED(hr
), "Failed to get volume container, hr %#x.\n", hr
);
4321 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4322 IUnknown_Release(container
);
4324 /* ...and this one shouldn't. This should return E_NOINTERFACE and set container to NULL. */
4325 hr
= IDirect3DVolume8_GetContainer(volume
, &IID_IDirect3DVolume8
, (void **)&container
);
4326 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
4327 ok(!container
, "Got unexpected container %p.\n", container
);
4329 IDirect3DVolume8_Release(volume
);
4330 IDirect3DVolumeTexture8_Release(texture
);
4331 refcount
= IDirect3DDevice8_Release(device
);
4332 ok(!refcount
, "Device has %u references left.\n", refcount
);
4333 IDirect3D8_Release(d3d8
);
4334 DestroyWindow(window
);
4337 static void test_vb_lock_flags(void)
4342 const char *debug_string
;
4347 {D3DLOCK_READONLY
, "D3DLOCK_READONLY", D3D_OK
},
4348 {D3DLOCK_DISCARD
, "D3DLOCK_DISCARD", D3D_OK
},
4349 {D3DLOCK_NOOVERWRITE
, "D3DLOCK_NOOVERWRITE", D3D_OK
},
4350 {D3DLOCK_NOOVERWRITE
| D3DLOCK_DISCARD
, "D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD", D3D_OK
},
4351 {D3DLOCK_NOOVERWRITE
| D3DLOCK_READONLY
, "D3DLOCK_NOOVERWRITE | D3DLOCK_READONLY", D3D_OK
},
4352 {D3DLOCK_READONLY
| D3DLOCK_DISCARD
, "D3DLOCK_READONLY | D3DLOCK_DISCARD", D3D_OK
},
4353 /* Completely bogus flags aren't an error. */
4354 {0xdeadbeef, "0xdeadbeef", D3D_OK
},
4356 IDirect3DVertexBuffer8
*buffer
;
4357 IDirect3DDevice8
*device
;
4365 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4366 0, 0, 640, 480, 0, 0, 0, 0);
4367 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4368 ok(!!d3d8
, "Failed to create a D3D object.\n");
4369 if (!(device
= create_device(d3d8
, window
, NULL
)))
4371 skip("Failed to create a D3D device, skipping tests.\n");
4372 IDirect3D8_Release(d3d8
);
4373 DestroyWindow(window
);
4377 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, 1024, D3DUSAGE_DYNAMIC
, 0, D3DPOOL_DEFAULT
, &buffer
);
4378 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
4380 for (i
= 0; i
< (sizeof(test_data
) / sizeof(*test_data
)); ++i
)
4382 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, 0, &data
, test_data
[i
].flags
);
4383 ok(hr
== test_data
[i
].result
, "Got unexpected hr %#x for %s.\n",
4384 hr
, test_data
[i
].debug_string
);
4387 ok(!!data
, "Got unexpected data %p.\n", data
);
4388 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
4389 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
4393 IDirect3DVertexBuffer8_Release(buffer
);
4394 refcount
= IDirect3DDevice8_Release(device
);
4395 ok(!refcount
, "Device has %u references left.\n", refcount
);
4396 IDirect3D8_Release(d3d8
);
4397 DestroyWindow(window
);
4400 /* Test the default texture stage state values */
4401 static void test_texture_stage_states(void)
4403 IDirect3DDevice8
*device
;
4412 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4413 0, 0, 640, 480, 0, 0, 0, 0);
4414 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4415 ok(!!d3d8
, "Failed to create a D3D object.\n");
4416 if (!(device
= create_device(d3d8
, window
, NULL
)))
4418 skip("Failed to create a D3D device, skipping tests.\n");
4419 IDirect3D8_Release(d3d8
);
4420 DestroyWindow(window
);
4424 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
4425 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
4427 for (i
= 0; i
< caps
.MaxTextureBlendStages
; ++i
)
4429 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_COLOROP
, &value
);
4430 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4431 ok(value
== (i
? D3DTOP_DISABLE
: D3DTOP_MODULATE
),
4432 "Got unexpected value %#x for D3DTSS_COLOROP, stage %u.\n", value
, i
);
4433 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_COLORARG1
, &value
);
4434 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4435 ok(value
== D3DTA_TEXTURE
, "Got unexpected value %#x for D3DTSS_COLORARG1, stage %u.\n", value
, i
);
4436 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_COLORARG2
, &value
);
4437 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4438 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_COLORARG2, stage %u.\n", value
, i
);
4439 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_ALPHAOP
, &value
);
4440 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4441 ok(value
== (i
? D3DTOP_DISABLE
: D3DTOP_SELECTARG1
),
4442 "Got unexpected value %#x for D3DTSS_ALPHAOP, stage %u.\n", value
, i
);
4443 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_ALPHAARG1
, &value
);
4444 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4445 ok(value
== D3DTA_TEXTURE
, "Got unexpected value %#x for D3DTSS_ALPHAARG1, stage %u.\n", value
, i
);
4446 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_ALPHAARG2
, &value
);
4447 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4448 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_ALPHAARG2, stage %u.\n", value
, i
);
4449 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVMAT00
, &value
);
4450 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4451 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVMAT00, stage %u.\n", value
, i
);
4452 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVMAT01
, &value
);
4453 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4454 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVMAT01, stage %u.\n", value
, i
);
4455 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVMAT10
, &value
);
4456 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4457 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVMAT10, stage %u.\n", value
, i
);
4458 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVMAT11
, &value
);
4459 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4460 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVMAT11, stage %u.\n", value
, i
);
4461 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_TEXCOORDINDEX
, &value
);
4462 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4463 ok(value
== i
, "Got unexpected value %#x for D3DTSS_TEXCOORDINDEX, stage %u.\n", value
, i
);
4464 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVLSCALE
, &value
);
4465 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4466 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVLSCALE, stage %u.\n", value
, i
);
4467 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVLOFFSET
, &value
);
4468 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4469 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVLOFFSET, stage %u.\n", value
, i
);
4470 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_TEXTURETRANSFORMFLAGS
, &value
);
4471 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4472 ok(value
== D3DTTFF_DISABLE
,
4473 "Got unexpected value %#x for D3DTSS_TEXTURETRANSFORMFLAGS, stage %u.\n", value
, i
);
4474 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_COLORARG0
, &value
);
4475 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4476 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_COLORARG0, stage %u.\n", value
, i
);
4477 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_ALPHAARG0
, &value
);
4478 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4479 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_ALPHAARG0, stage %u.\n", value
, i
);
4480 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_RESULTARG
, &value
);
4481 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4482 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_RESULTARG, stage %u.\n", value
, i
);
4485 refcount
= IDirect3DDevice8_Release(device
);
4486 ok(!refcount
, "Device has %u references left.\n", refcount
);
4487 IDirect3D8_Release(d3d8
);
4488 DestroyWindow(window
);
4491 static void test_cube_textures(void)
4493 IDirect3DCubeTexture8
*texture
;
4494 IDirect3DDevice8
*device
;
4501 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4502 0, 0, 640, 480, 0, 0, 0, 0);
4503 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4504 ok(!!d3d8
, "Failed to create a D3D object.\n");
4505 if (!(device
= create_device(d3d8
, window
, NULL
)))
4507 skip("Failed to create a D3D device, skipping tests.\n");
4508 IDirect3D8_Release(d3d8
);
4509 DestroyWindow(window
);
4513 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
4514 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
4516 if (caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
)
4518 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &texture
);
4519 ok(hr
== D3D_OK
, "Failed to create D3DPOOL_DEFAULT cube texture, hr %#x.\n", hr
);
4520 IDirect3DCubeTexture8_Release(texture
);
4521 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &texture
);
4522 ok(hr
== D3D_OK
, "Failed to create D3DPOOL_MANAGED cube texture, hr %#x.\n", hr
);
4523 IDirect3DCubeTexture8_Release(texture
);
4524 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_SYSTEMMEM
, &texture
);
4525 ok(hr
== D3D_OK
, "Failed to create D3DPOOL_SYSTEMMEM cube texture, hr %#x.\n", hr
);
4526 IDirect3DCubeTexture8_Release(texture
);
4530 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &texture
);
4531 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for D3DPOOL_DEFAULT cube texture.\n", hr
);
4532 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &texture
);
4533 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for D3DPOOL_MANAGED cube texture.\n", hr
);
4534 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_SYSTEMMEM
, &texture
);
4535 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for D3DPOOL_SYSTEMMEM cube texture.\n", hr
);
4537 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_SCRATCH
, &texture
);
4538 ok(hr
== D3D_OK
, "Failed to create D3DPOOL_SCRATCH cube texture, hr %#x.\n", hr
);
4539 IDirect3DCubeTexture8_Release(texture
);
4541 refcount
= IDirect3DDevice8_Release(device
);
4542 ok(!refcount
, "Device has %u references left.\n", refcount
);
4543 IDirect3D8_Release(d3d8
);
4544 DestroyWindow(window
);
4547 static void test_get_set_texture(void)
4549 const IDirect3DBaseTexture8Vtbl
*texture_vtbl
;
4550 IDirect3DBaseTexture8
*texture
;
4551 IDirect3DDevice8
*device
;
4557 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4558 0, 0, 640, 480, 0, 0, 0, 0);
4559 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
4560 ok(!!d3d
, "Failed to create a D3D object.\n");
4561 if (!(device
= create_device(d3d
, window
, NULL
)))
4563 skip("Failed to create a D3D device, skipping tests.\n");
4564 IDirect3D8_Release(d3d
);
4565 DestroyWindow(window
);
4569 texture
= (IDirect3DBaseTexture8
*)0xdeadbeef;
4570 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
4571 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4572 hr
= IDirect3DDevice8_GetTexture(device
, 0, &texture
);
4573 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4574 ok(!texture
, "Got unexpected texture %p.\n", texture
);
4576 hr
= IDirect3DDevice8_CreateTexture(device
, 16, 16, 1, 0, D3DFMT_A8R8G8B8
,
4577 D3DPOOL_MANAGED
, (IDirect3DTexture8
**)&texture
);
4578 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
4579 texture_vtbl
= texture
->lpVtbl
;
4580 texture
->lpVtbl
= (IDirect3DBaseTexture8Vtbl
*)0xdeadbeef;
4581 hr
= IDirect3DDevice8_SetTexture(device
, 0, texture
);
4582 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
4583 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
4584 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
4585 texture
->lpVtbl
= NULL
;
4586 hr
= IDirect3DDevice8_SetTexture(device
, 0, texture
);
4587 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
4588 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
4589 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
4590 texture
->lpVtbl
= texture_vtbl
;
4591 IDirect3DBaseTexture8_Release(texture
);
4593 refcount
= IDirect3DDevice8_Release(device
);
4594 ok(!refcount
, "Device has %u references left.\n", refcount
);
4595 IDirect3D8_Release(d3d
);
4596 DestroyWindow(window
);
4599 /* Test the behaviour of the IDirect3DDevice8::CreateImageSurface() method.
4601 * The expected behaviour (as documented in the original DX8 docs) is that the
4602 * call returns a surface in the SYSTEMMEM pool. Games like Max Payne 1 and 2
4603 * depend on this behaviour.
4605 * A short remark in the DX9 docs however states that the pool of the returned
4606 * surface object is D3DPOOL_SCRATCH. This is misinformation and would result
4607 * in screenshots not appearing in the savegame loading menu of both games
4608 * mentioned above (engine tries to display a texture from the scratch pool).
4610 * This test verifies that the behaviour described in the original d3d8 docs
4611 * is the correct one. For more information about this issue, see the MSDN:
4612 * d3d9 docs: "Converting to Direct3D 9"
4613 * d3d9 reference: "IDirect3DDevice9::CreateOffscreenPlainSurface"
4614 * d3d8 reference: "IDirect3DDevice8::CreateImageSurface" */
4615 static void test_image_surface_pool(void)
4617 IDirect3DSurface8
*surface
;
4618 IDirect3DDevice8
*device
;
4619 D3DSURFACE_DESC desc
;
4625 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4626 0, 0, 640, 480, 0, 0, 0, 0);
4627 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4628 ok(!!d3d8
, "Failed to create a D3D object.\n");
4629 if (!(device
= create_device(d3d8
, window
, NULL
)))
4631 skip("Failed to create a D3D device, skipping tests.\n");
4632 IDirect3D8_Release(d3d8
);
4633 DestroyWindow(window
);
4637 hr
= IDirect3DDevice8_CreateImageSurface(device
, 128, 128, D3DFMT_A8R8G8B8
, &surface
);
4638 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4639 hr
= IDirect3DSurface8_GetDesc(surface
, &desc
);
4640 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4641 ok(desc
.Pool
== D3DPOOL_SYSTEMMEM
, "Got unexpected pool %#x.\n", desc
.Pool
);
4642 IDirect3DSurface8_Release(surface
);
4644 refcount
= IDirect3DDevice8_Release(device
);
4645 ok(!refcount
, "Device has %u references left.\n", refcount
);
4646 IDirect3D8_Release(d3d8
);
4647 DestroyWindow(window
);
4650 static void test_surface_get_container(void)
4652 IDirect3DTexture8
*texture
= NULL
;
4653 IDirect3DSurface8
*surface
= NULL
;
4654 IDirect3DDevice8
*device
;
4655 IUnknown
*container
;
4661 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4662 0, 0, 640, 480, 0, 0, 0, 0);
4663 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4664 ok(!!d3d8
, "Failed to create a D3D object.\n");
4665 if (!(device
= create_device(d3d8
, window
, NULL
)))
4667 skip("Failed to create a D3D device, skipping tests.\n");
4668 IDirect3D8_Release(d3d8
);
4669 DestroyWindow(window
);
4673 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1, 0,
4674 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &texture
);
4675 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
4676 ok(!!texture
, "Got unexpected texture %p.\n", texture
);
4678 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &surface
);
4679 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
4680 ok(!!surface
, "Got unexpected surface %p.\n", surface
);
4682 /* These should work... */
4684 hr
= IDirect3DSurface8_GetContainer(surface
, &IID_IUnknown
, (void **)&container
);
4685 ok(SUCCEEDED(hr
), "Failed to get surface container, hr %#x.\n", hr
);
4686 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4687 IUnknown_Release(container
);
4690 hr
= IDirect3DSurface8_GetContainer(surface
, &IID_IDirect3DResource8
, (void **)&container
);
4691 ok(SUCCEEDED(hr
), "Failed to get surface container, hr %#x.\n", hr
);
4692 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4693 IUnknown_Release(container
);
4696 hr
= IDirect3DSurface8_GetContainer(surface
, &IID_IDirect3DBaseTexture8
, (void **)&container
);
4697 ok(SUCCEEDED(hr
), "Failed to get surface container, hr %#x.\n", hr
);
4698 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4699 IUnknown_Release(container
);
4702 hr
= IDirect3DSurface8_GetContainer(surface
, &IID_IDirect3DTexture8
, (void **)&container
);
4703 ok(SUCCEEDED(hr
), "Failed to get surface container, hr %#x.\n", hr
);
4704 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4705 IUnknown_Release(container
);
4707 /* ...and this one shouldn't. This should return E_NOINTERFACE and set container to NULL. */
4708 hr
= IDirect3DSurface8_GetContainer(surface
, &IID_IDirect3DSurface8
, (void **)&container
);
4709 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
4710 ok(!container
, "Got unexpected container %p.\n", container
);
4712 IDirect3DSurface8_Release(surface
);
4713 IDirect3DTexture8_Release(texture
);
4714 refcount
= IDirect3DDevice8_Release(device
);
4715 ok(!refcount
, "Device has %u references left.\n", refcount
);
4716 IDirect3D8_Release(d3d8
);
4717 DestroyWindow(window
);
4720 static void test_lockrect_invalid(void)
4722 static const RECT valid
[] =
4728 static const RECT invalid
[] =
4730 {60, 60, 60, 68}, /* 0 height */
4731 {60, 60, 68, 60}, /* 0 width */
4732 {68, 60, 60, 68}, /* left > right */
4733 {60, 68, 68, 60}, /* top > bottom */
4734 {-8, 60, 0, 68}, /* left < surface */
4735 {60, -8, 68, 0}, /* top < surface */
4736 {-16, 60, -8, 68}, /* right < surface */
4737 {60, -16, 68, -8}, /* bottom < surface */
4738 {60, 60, 136, 68}, /* right > surface */
4739 {60, 60, 68, 136}, /* bottom > surface */
4740 {136, 60, 144, 68}, /* left > surface */
4741 {60, 136, 68, 144}, /* top > surface */
4743 IDirect3DSurface8
*surface
;
4744 IDirect3DTexture8
*texture
;
4745 IDirect3DCubeTexture8
*cube_texture
;
4746 D3DLOCKED_RECT locked_rect
;
4747 IDirect3DDevice8
*device
;
4754 unsigned int offset
, expected_offset
;
4757 D3DRESOURCETYPE type
;
4760 BOOL validate
, clear
;
4764 {D3DRTYPE_SURFACE
, D3DPOOL_SCRATCH
, "scratch surface", TRUE
, TRUE
},
4765 {D3DRTYPE_TEXTURE
, D3DPOOL_MANAGED
, "managed texture", FALSE
, FALSE
},
4766 {D3DRTYPE_TEXTURE
, D3DPOOL_SYSTEMMEM
, "sysmem texture", FALSE
, FALSE
},
4767 {D3DRTYPE_TEXTURE
, D3DPOOL_SCRATCH
, "scratch texture", FALSE
, FALSE
},
4768 {D3DRTYPE_CUBETEXTURE
, D3DPOOL_MANAGED
, "default cube texture", TRUE
, TRUE
},
4769 {D3DRTYPE_CUBETEXTURE
, D3DPOOL_SYSTEMMEM
, "sysmem cube texture", TRUE
, TRUE
},
4770 {D3DRTYPE_CUBETEXTURE
, D3DPOOL_SCRATCH
, "scratch cube texture", TRUE
, TRUE
},
4773 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4774 0, 0, 640, 480, 0, 0, 0, 0);
4775 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4776 ok(!!d3d8
, "Failed to create a D3D object.\n");
4777 if (!(device
= create_device(d3d8
, window
, NULL
)))
4779 skip("Failed to create a D3D device, skipping tests.\n");
4780 IDirect3D8_Release(d3d8
);
4781 DestroyWindow(window
);
4785 for (r
= 0; r
< sizeof(resources
) / sizeof(*resources
); ++r
)
4788 cube_texture
= NULL
;
4789 switch (resources
[r
].type
)
4791 case D3DRTYPE_SURFACE
:
4792 hr
= IDirect3DDevice8_CreateImageSurface(device
, 128, 128, D3DFMT_A8R8G8B8
, &surface
);
4793 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4796 case D3DRTYPE_TEXTURE
:
4797 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1, 0, D3DFMT_A8R8G8B8
,
4798 resources
[r
].pool
, &texture
);
4799 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4800 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &surface
);
4801 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4804 case D3DRTYPE_CUBETEXTURE
:
4805 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 128, 1, 0, D3DFMT_A8R8G8B8
,
4806 resources
[r
].pool
, &cube_texture
);
4807 ok(SUCCEEDED(hr
), "Failed to create cube texture, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4808 hr
= IDirect3DCubeTexture8_GetCubeMapSurface(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0, &surface
);
4809 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4815 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
4816 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4817 base
= locked_rect
.pBits
;
4818 hr
= IDirect3DSurface8_UnlockRect(surface
);
4819 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4821 for (i
= 0; i
< (sizeof(valid
) / sizeof(*valid
)); ++i
)
4823 const RECT
*rect
= &valid
[i
];
4825 locked_rect
.pBits
= (BYTE
*)0xdeadbeef;
4826 locked_rect
.Pitch
= 0xdeadbeef;
4828 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, rect
, 0);
4829 ok(SUCCEEDED(hr
), "Failed to lock surface with rect %s, hr %#x, type %s.\n",
4830 wine_dbgstr_rect(rect
), hr
, resources
[r
].name
);
4832 offset
= (BYTE
*)locked_rect
.pBits
- base
;
4833 expected_offset
= rect
->top
* locked_rect
.Pitch
+ rect
->left
* 4;
4834 ok(offset
== expected_offset
,
4835 "Got unexpected offset %u (expected %u) for rect %s, type %s.\n",
4836 offset
, expected_offset
, wine_dbgstr_rect(rect
), resources
[r
].name
);
4838 hr
= IDirect3DSurface8_UnlockRect(surface
);
4839 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s\n", hr
, resources
[r
].name
);
4843 hr
= IDirect3DTexture8_LockRect(texture
, 0, &locked_rect
, rect
, 0);
4844 ok(SUCCEEDED(hr
), "Failed to lock surface with rect %s, hr %#x, type %s.\n",
4845 wine_dbgstr_rect(rect
), hr
, resources
[r
].name
);
4847 offset
= (BYTE
*)locked_rect
.pBits
- base
;
4848 ok(offset
== expected_offset
,
4849 "Got unexpected offset %u (expected %u) for rect %s, type %s.\n",
4850 offset
, expected_offset
, wine_dbgstr_rect(rect
), resources
[r
].name
);
4852 hr
= IDirect3DTexture8_UnlockRect(texture
, 0);
4853 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4857 hr
= IDirect3DCubeTexture8_LockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0, &locked_rect
, rect
, 0);
4858 ok(SUCCEEDED(hr
), "Failed to lock surface with rect %s, hr %#x, type %s.\n",
4859 wine_dbgstr_rect(rect
), hr
, resources
[r
].name
);
4861 offset
= (BYTE
*)locked_rect
.pBits
- base
;
4862 ok(offset
== expected_offset
,
4863 "Got unexpected offset %u (expected %u) for rect %s, type %s.\n",
4864 offset
, expected_offset
, wine_dbgstr_rect(rect
), resources
[r
].name
);
4866 hr
= IDirect3DCubeTexture8_UnlockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0);
4867 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4871 for (i
= 0; i
< (sizeof(invalid
) / sizeof(*invalid
)); ++i
)
4873 const RECT
*rect
= &invalid
[i
];
4875 locked_rect
.pBits
= (void *)0xdeadbeef;
4876 locked_rect
.Pitch
= 1;
4877 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, rect
, 0);
4878 if (resources
[r
].validate
)
4879 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect %s, type %s.\n",
4880 hr
, wine_dbgstr_rect(rect
), resources
[r
].name
);
4882 ok(SUCCEEDED(hr
), "Got unexpected hr %#x for rect %s, type %s.\n",
4883 hr
, wine_dbgstr_rect(rect
), resources
[r
].name
);
4887 offset
= (BYTE
*)locked_rect
.pBits
- base
;
4888 expected_offset
= rect
->top
* locked_rect
.Pitch
+ rect
->left
* 4;
4889 ok(offset
== expected_offset
,
4890 "Got unexpected offset %u (expected %u) for rect %s, type %s.\n",
4891 offset
, expected_offset
,wine_dbgstr_rect(rect
), resources
[r
].name
);
4893 hr
= IDirect3DSurface8_UnlockRect(surface
);
4894 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4898 ok(!locked_rect
.pBits
, "Got unexpected pBits %p, type %s.\n",
4899 locked_rect
.pBits
, resources
[r
].name
);
4900 ok(!locked_rect
.Pitch
, "Got unexpected Pitch %u, type %s.\n",
4901 locked_rect
.Pitch
, resources
[r
].name
);
4905 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
4906 ok(SUCCEEDED(hr
), "Failed to lock surface with rect NULL, hr %#x, type %s.\n",
4907 hr
, resources
[r
].name
);
4908 locked_rect
.pBits
= (void *)0xdeadbeef;
4909 locked_rect
.Pitch
= 1;
4910 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
4911 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
4912 if (resources
[r
].clear
)
4914 ok(!locked_rect
.pBits
, "Got unexpected pBits %p, type %s.\n",
4915 locked_rect
.pBits
, resources
[r
].name
);
4916 ok(!locked_rect
.Pitch
, "Got unexpected Pitch %u, type %s.\n",
4917 locked_rect
.Pitch
, resources
[r
].name
);
4921 ok(locked_rect
.pBits
== (void *)0xdeadbeef, "Got unexpected pBits %p, type %s.\n",
4922 locked_rect
.pBits
, resources
[r
].name
);
4923 ok(locked_rect
.Pitch
== 1, "Got unexpected Pitch %u, type %s.\n",
4924 locked_rect
.Pitch
, resources
[r
].name
);
4926 hr
= IDirect3DSurface8_UnlockRect(surface
);
4927 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4929 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &valid
[0], 0);
4930 ok(hr
== D3D_OK
, "Got unexpected hr %#x for rect %s, type %s.\n",
4931 hr
, wine_dbgstr_rect(&valid
[0]), resources
[r
].name
);
4932 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &valid
[0], 0);
4933 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect %s, type %s.\n",
4934 hr
, wine_dbgstr_rect(&valid
[0]), resources
[r
].name
);
4935 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &valid
[1], 0);
4936 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect %s, type %s.\n",
4937 hr
, wine_dbgstr_rect(&valid
[1]), resources
[r
].name
);
4938 hr
= IDirect3DSurface8_UnlockRect(surface
);
4939 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4941 IDirect3DSurface8_Release(surface
);
4944 hr
= IDirect3DTexture8_LockRect(texture
, 0, &locked_rect
, NULL
, 0);
4945 ok(SUCCEEDED(hr
), "Failed to lock texture with rect NULL, hr %#x, type %s.\n",
4946 hr
, resources
[r
].name
);
4947 locked_rect
.pBits
= (void *)0xdeadbeef;
4948 locked_rect
.Pitch
= 1;
4949 hr
= IDirect3DTexture8_LockRect(texture
, 0, &locked_rect
, NULL
, 0);
4950 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
4951 ok(locked_rect
.pBits
== (void *)0xdeadbeef, "Got unexpected pBits %p, type %s.\n",
4952 locked_rect
.pBits
, resources
[r
].name
);
4953 ok(locked_rect
.Pitch
== 1, "Got unexpected Pitch %u, type %s.\n",
4954 locked_rect
.Pitch
, resources
[r
].name
);
4955 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
4956 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
4957 hr
= IDirect3DTexture8_UnlockRect(texture
, 0);
4958 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4960 hr
= IDirect3DTexture8_LockRect(texture
, 0, &locked_rect
, &valid
[0], 0);
4961 ok(hr
== D3D_OK
, "Got unexpected hr %#x for rect %s, type %s.\n",
4962 hr
, wine_dbgstr_rect(&valid
[0]), resources
[r
].name
);
4963 hr
= IDirect3DTexture8_LockRect(texture
, 0, &locked_rect
, &valid
[0], 0);
4964 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect %s, type %s.\n",
4965 hr
, wine_dbgstr_rect(&valid
[0]), resources
[r
].name
);
4966 hr
= IDirect3DTexture8_LockRect(texture
, 0, &locked_rect
, &valid
[1], 0);
4967 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect %s, type %s.\n",
4968 hr
, wine_dbgstr_rect(&valid
[1]), resources
[r
].name
);
4969 hr
= IDirect3DTexture8_UnlockRect(texture
, 0);
4970 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4972 IDirect3DTexture8_Release(texture
);
4977 hr
= IDirect3DCubeTexture8_LockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0,
4978 &locked_rect
, NULL
, 0);
4979 ok(SUCCEEDED(hr
), "Failed to lock texture with rect NULL, hr %#x, type %s.\n",
4980 hr
, resources
[r
].name
);
4981 locked_rect
.pBits
= (void *)0xdeadbeef;
4982 locked_rect
.Pitch
= 1;
4983 hr
= IDirect3DCubeTexture8_LockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0,
4984 &locked_rect
, NULL
, 0);
4985 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
4986 ok(!locked_rect
.pBits
, "Got unexpected pBits %p, type %s.\n",
4987 locked_rect
.pBits
, resources
[r
].name
);
4988 ok(!locked_rect
.Pitch
, "Got unexpected Pitch %u, type %s.\n",
4989 locked_rect
.Pitch
, resources
[r
].name
);
4990 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
4991 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
4992 hr
= IDirect3DCubeTexture8_UnlockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0);
4993 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x, type %s.\n", hr
, resources
[r
].name
);
4995 hr
= IDirect3DCubeTexture8_LockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0,
4996 &locked_rect
, &valid
[0], 0);
4997 ok(hr
== D3D_OK
, "Got unexpected hr %#x for rect %s, type %s.\n",
4998 hr
, wine_dbgstr_rect(&valid
[0]), resources
[r
].name
);
4999 hr
= IDirect3DCubeTexture8_LockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0,
5000 &locked_rect
, &valid
[0], 0);
5001 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect %s, type %s.\n",
5002 hr
, wine_dbgstr_rect(&valid
[0]), resources
[r
].name
);
5003 hr
= IDirect3DCubeTexture8_LockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0,
5004 &locked_rect
, &valid
[1], 0);
5005 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect %s, type %s.\n",
5006 hr
, wine_dbgstr_rect(&valid
[1]), resources
[r
].name
);
5007 hr
= IDirect3DCubeTexture8_UnlockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0);
5008 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x, type %s.\n", hr
, resources
[r
].name
);
5010 IDirect3DTexture8_Release(cube_texture
);
5014 refcount
= IDirect3DDevice8_Release(device
);
5015 ok(!refcount
, "Device has %u references left.\n", refcount
);
5016 IDirect3D8_Release(d3d8
);
5017 DestroyWindow(window
);
5020 static void test_private_data(void)
5022 ULONG refcount
, expected_refcount
;
5023 IDirect3DTexture8
*texture
;
5024 IDirect3DSurface8
*surface
, *surface2
;
5025 IDirect3DDevice8
*device
;
5031 DWORD data
[4] = {1, 2, 3, 4};
5032 static const GUID d3d8_private_data_test_guid2
=
5037 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
5040 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
5041 0, 0, 640, 480, 0, 0, 0, 0);
5042 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
5043 ok(!!d3d8
, "Failed to create a D3D object.\n");
5044 if (!(device
= create_device(d3d8
, window
, NULL
)))
5046 skip("Failed to create a D3D device, skipping tests.\n");
5047 IDirect3D8_Release(d3d8
);
5048 DestroyWindow(window
);
5052 hr
= IDirect3DDevice8_CreateImageSurface(device
, 4, 4, D3DFMT_A8R8G8B8
, &surface
);
5053 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5055 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
5056 device
, 0, D3DSPD_IUNKNOWN
);
5057 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5058 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
5059 device
, 5, D3DSPD_IUNKNOWN
);
5060 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5061 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
5062 device
, sizeof(IUnknown
*) * 2, D3DSPD_IUNKNOWN
);
5063 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5065 /* A failing SetPrivateData call does not clear the old data with the same tag. */
5066 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
, device
,
5067 sizeof(device
), D3DSPD_IUNKNOWN
);
5068 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
5069 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
, device
,
5070 sizeof(device
) * 2, D3DSPD_IUNKNOWN
);
5071 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5073 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, &ptr
, &size
);
5074 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
5075 IUnknown_Release(ptr
);
5076 hr
= IDirect3DSurface8_FreePrivateData(surface
, &d3d8_private_data_test_guid
);
5077 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
5079 refcount
= get_refcount((IUnknown
*)device
);
5080 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
5081 device
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
5082 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5083 expected_refcount
= refcount
+ 1;
5084 refcount
= get_refcount((IUnknown
*)device
);
5085 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5086 hr
= IDirect3DSurface8_FreePrivateData(surface
, &d3d8_private_data_test_guid
);
5087 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5088 expected_refcount
= refcount
- 1;
5089 refcount
= get_refcount((IUnknown
*)device
);
5090 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5092 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
5093 device
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
5094 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5095 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
5096 surface
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
5097 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5098 refcount
= get_refcount((IUnknown
*)device
);
5099 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5101 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
5102 device
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
5103 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5104 size
= 2 * sizeof(ptr
);
5105 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, &ptr
, &size
);
5106 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5107 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
5108 expected_refcount
= refcount
+ 2;
5109 refcount
= get_refcount((IUnknown
*)device
);
5110 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5111 ok(ptr
== (IUnknown
*)device
, "Got unexpected ptr %p, expected %p.\n", ptr
, device
);
5112 IUnknown_Release(ptr
);
5113 expected_refcount
--;
5115 ptr
= (IUnknown
*)0xdeadbeef;
5117 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, NULL
, &size
);
5118 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5119 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
5120 size
= 2 * sizeof(ptr
);
5121 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, NULL
, &size
);
5122 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5123 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
5124 refcount
= get_refcount((IUnknown
*)device
);
5125 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5127 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, &ptr
, &size
);
5128 ok(hr
== D3DERR_MOREDATA
, "Got unexpected hr %#x.\n", hr
);
5129 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
5130 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
5131 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid2
, NULL
, NULL
);
5132 ok(hr
== D3DERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5134 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid2
, &ptr
, &size
);
5135 ok(hr
== D3DERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5136 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
5137 ok(size
== 0xdeadbabe, "Got unexpected size %u.\n", size
);
5138 /* GetPrivateData with size = NULL causes an access violation on Windows if the
5139 * requested data exists. */
5141 /* Destroying the surface frees the held reference. */
5142 IDirect3DSurface8_Release(surface
);
5143 expected_refcount
= refcount
- 2;
5144 refcount
= get_refcount((IUnknown
*)device
);
5145 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5147 hr
= IDirect3DDevice8_CreateTexture(device
, 4, 4, 2, 0, D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &texture
);
5148 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
5149 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &surface
);
5150 ok(SUCCEEDED(hr
), "Failed to get texture level 0, hr %#x.\n", hr
);
5151 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 1, &surface2
);
5152 ok(SUCCEEDED(hr
), "Failed to get texture level 1, hr %#x.\n", hr
);
5154 hr
= IDirect3DTexture8_SetPrivateData(texture
, &d3d8_private_data_test_guid
, data
, sizeof(data
), 0);
5155 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
5157 memset(data
, 0, sizeof(data
));
5158 size
= sizeof(data
);
5159 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, data
, &size
);
5160 ok(hr
== D3DERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5161 hr
= IDirect3DTexture8_GetPrivateData(texture
, &d3d8_private_data_test_guid
, data
, &size
);
5162 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
5163 ok(data
[0] == 1 && data
[1] == 2 && data
[2] == 3 && data
[3] == 4,
5164 "Got unexpected private data: %u, %u, %u, %u.\n", data
[0], data
[1], data
[2], data
[3]);
5166 hr
= IDirect3DTexture8_FreePrivateData(texture
, &d3d8_private_data_test_guid
);
5167 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
5169 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
, data
, sizeof(data
), 0);
5170 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
5171 hr
= IDirect3DSurface8_GetPrivateData(surface2
, &d3d8_private_data_test_guid
, data
, &size
);
5172 ok(hr
== D3DERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5173 hr
= IDirect3DSurface8_FreePrivateData(surface
, &d3d8_private_data_test_guid
);
5174 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
5176 IDirect3DSurface8_Release(surface2
);
5177 IDirect3DSurface8_Release(surface
);
5178 IDirect3DTexture8_Release(texture
);
5180 refcount
= IDirect3DDevice8_Release(device
);
5181 ok(!refcount
, "Device has %u references left.\n", refcount
);
5182 IDirect3D8_Release(d3d8
);
5183 DestroyWindow(window
);
5186 static void test_surface_dimensions(void)
5188 IDirect3DSurface8
*surface
;
5189 IDirect3DDevice8
*device
;
5195 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
5196 0, 0, 640, 480, 0, 0, 0, 0);
5197 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
5198 ok(!!d3d8
, "Failed to create a D3D object.\n");
5199 if (!(device
= create_device(d3d8
, window
, NULL
)))
5201 skip("Failed to create a D3D device, skipping tests.\n");
5202 IDirect3D8_Release(d3d8
);
5203 DestroyWindow(window
);
5207 hr
= IDirect3DDevice8_CreateImageSurface(device
, 0, 1, D3DFMT_A8R8G8B8
, &surface
);
5208 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5209 hr
= IDirect3DDevice8_CreateImageSurface(device
, 1, 0, D3DFMT_A8R8G8B8
, &surface
);
5210 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5212 refcount
= IDirect3DDevice8_Release(device
);
5213 ok(!refcount
, "Device has %u references left.\n", refcount
);
5214 IDirect3D8_Release(d3d8
);
5215 DestroyWindow(window
);
5218 static void test_surface_format_null(void)
5220 static const D3DFORMAT D3DFMT_NULL
= MAKEFOURCC('N','U','L','L');
5221 IDirect3DTexture8
*texture
;
5222 IDirect3DSurface8
*surface
;
5223 IDirect3DSurface8
*rt
, *ds
;
5224 D3DLOCKED_RECT locked_rect
;
5225 IDirect3DDevice8
*device
;
5226 D3DSURFACE_DESC desc
;
5232 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
5233 ok(!!d3d
, "Failed to create a D3D object.\n");
5235 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5236 D3DUSAGE_RENDERTARGET
, D3DRTYPE_SURFACE
, D3DFMT_NULL
);
5239 skip("No D3DFMT_NULL support, skipping test.\n");
5240 IDirect3D8_Release(d3d
);
5244 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
5245 0, 0, 640, 480, 0, 0, 0, 0);
5246 if (!(device
= create_device(d3d
, window
, NULL
)))
5248 skip("Failed to create a D3D device, skipping tests.\n");
5249 IDirect3D8_Release(d3d
);
5250 DestroyWindow(window
);
5254 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5255 D3DUSAGE_RENDERTARGET
, D3DRTYPE_TEXTURE
, D3DFMT_NULL
);
5256 ok(hr
== D3D_OK
, "D3DFMT_NULL should be supported for render target textures, hr %#x.\n", hr
);
5258 hr
= IDirect3D8_CheckDepthStencilMatch(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5259 D3DFMT_NULL
, D3DFMT_D24S8
);
5260 ok(SUCCEEDED(hr
), "Depth stencil match failed for D3DFMT_NULL, hr %#x.\n", hr
);
5262 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 128, 128, D3DFMT_NULL
,
5263 D3DMULTISAMPLE_NONE
, TRUE
, &surface
);
5264 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
5266 hr
= IDirect3DDevice8_GetRenderTarget(device
, &rt
);
5267 ok(SUCCEEDED(hr
), "Failed to get original render target, hr %#x.\n", hr
);
5269 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &ds
);
5270 ok(SUCCEEDED(hr
), "Failed to get original depth/stencil, hr %#x.\n", hr
);
5272 hr
= IDirect3DDevice8_SetRenderTarget(device
, surface
, NULL
);
5273 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
5275 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00000000, 0.0f
, 0);
5276 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
5278 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, ds
);
5279 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
5281 IDirect3DSurface8_Release(rt
);
5282 IDirect3DSurface8_Release(ds
);
5284 hr
= IDirect3DSurface8_GetDesc(surface
, &desc
);
5285 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5286 ok(desc
.Width
== 128, "Expected width 128, got %u.\n", desc
.Width
);
5287 ok(desc
.Height
== 128, "Expected height 128, got %u.\n", desc
.Height
);
5289 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
5290 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5291 ok(locked_rect
.Pitch
, "Expected non-zero pitch, got %u.\n", locked_rect
.Pitch
);
5292 ok(!!locked_rect
.pBits
, "Expected non-NULL pBits, got %p.\n", locked_rect
.pBits
);
5294 hr
= IDirect3DSurface8_UnlockRect(surface
);
5295 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5297 IDirect3DSurface8_Release(surface
);
5299 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 0, D3DUSAGE_RENDERTARGET
,
5300 D3DFMT_NULL
, D3DPOOL_DEFAULT
, &texture
);
5301 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
5302 IDirect3DTexture8_Release(texture
);
5304 refcount
= IDirect3DDevice8_Release(device
);
5305 ok(!refcount
, "Device has %u references left.\n", refcount
);
5306 IDirect3D8_Release(d3d
);
5307 DestroyWindow(window
);
5310 static void test_surface_double_unlock(void)
5312 static const D3DPOOL pools
[] =
5317 IDirect3DSurface8
*surface
;
5318 IDirect3DDevice8
*device
;
5326 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
5327 0, 0, 640, 480, 0, 0, 0, 0);
5328 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
5329 ok(!!d3d
, "Failed to create a D3D object.\n");
5330 if (!(device
= create_device(d3d
, window
, NULL
)))
5332 skip("Failed to create a D3D device, skipping tests.\n");
5333 IDirect3D8_Release(d3d
);
5334 DestroyWindow(window
);
5338 for (i
= 0; i
< (sizeof(pools
) / sizeof(*pools
)); ++i
)
5342 case D3DPOOL_DEFAULT
:
5343 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5344 D3DUSAGE_RENDERTARGET
, D3DRTYPE_SURFACE
, D3DFMT_X8R8G8B8
);
5347 skip("D3DFMT_X8R8G8B8 render targets not supported, skipping double unlock DEFAULT pool test.\n");
5351 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 64, 64, D3DFMT_X8R8G8B8
,
5352 D3DMULTISAMPLE_NONE
, TRUE
, &surface
);
5353 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
5356 case D3DPOOL_SYSTEMMEM
:
5357 hr
= IDirect3DDevice8_CreateImageSurface(device
, 64, 64, D3DFMT_X8R8G8B8
, &surface
);
5358 ok(SUCCEEDED(hr
), "Failed to create image surface, hr %#x.\n", hr
);
5365 hr
= IDirect3DSurface8_UnlockRect(surface
);
5366 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, for surface in pool %#x.\n", hr
, pools
[i
]);
5367 hr
= IDirect3DSurface8_LockRect(surface
, &lr
, NULL
, 0);
5368 ok(SUCCEEDED(hr
), "Failed to lock surface in pool %#x, hr %#x.\n", pools
[i
], hr
);
5369 hr
= IDirect3DSurface8_UnlockRect(surface
);
5370 ok(SUCCEEDED(hr
), "Failed to unlock surface in pool %#x, hr %#x.\n", pools
[i
], hr
);
5371 hr
= IDirect3DSurface8_UnlockRect(surface
);
5372 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, for surface in pool %#x.\n", hr
, pools
[i
]);
5374 IDirect3DSurface8_Release(surface
);
5377 refcount
= IDirect3DDevice8_Release(device
);
5378 ok(!refcount
, "Device has %u references left.\n", refcount
);
5379 IDirect3D8_Release(d3d
);
5380 DestroyWindow(window
);
5383 static void test_surface_blocks(void)
5389 unsigned int block_width
;
5390 unsigned int block_height
;
5392 BOOL create_size_checked
, core_fmt
;
5396 {D3DFMT_DXT1
, "D3DFMT_DXT1", 4, 4, FALSE
, TRUE
, TRUE
},
5397 {D3DFMT_DXT2
, "D3DFMT_DXT2", 4, 4, FALSE
, TRUE
, TRUE
},
5398 {D3DFMT_DXT3
, "D3DFMT_DXT3", 4, 4, FALSE
, TRUE
, TRUE
},
5399 {D3DFMT_DXT4
, "D3DFMT_DXT4", 4, 4, FALSE
, TRUE
, TRUE
},
5400 {D3DFMT_DXT5
, "D3DFMT_DXT5", 4, 4, FALSE
, TRUE
, TRUE
},
5401 /* ATI1N and ATI2N have 2x2 blocks on all AMD cards and Geforce 7 cards,
5402 * which doesn't match the format spec. On newer Nvidia cards
5403 * they have the correct 4x4 block size */
5404 {MAKEFOURCC('A','T','I','1'), "ATI1N", 4, 4, TRUE
, FALSE
, FALSE
},
5405 {MAKEFOURCC('A','T','I','2'), "ATI2N", 4, 4, TRUE
, FALSE
, FALSE
},
5406 /* Windows drivers generally enforce block-aligned locks for
5407 * YUY2 and UYVY. The notable exception is the AMD r500 driver
5408 * in d3d8. The same driver checks the sizes in d3d9. */
5409 {D3DFMT_YUY2
, "D3DFMT_YUY2", 2, 1, TRUE
, FALSE
, TRUE
},
5410 {D3DFMT_UYVY
, "D3DFMT_UYVY", 2, 1, TRUE
, FALSE
, TRUE
},
5416 /* Don't check the return value, Nvidia returns D3DERR_INVALIDCALL for some formats
5417 * and E_INVALIDARG/DDERR_INVALIDPARAMS for others. */
5422 {D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", FALSE
},
5423 {D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", TRUE
},
5424 {D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM",TRUE
},
5425 {D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
},
5429 D3DRESOURCETYPE rtype
;
5430 const char *type_name
;
5432 const char *pool_name
;
5433 BOOL need_driver_support
, need_runtime_support
;
5437 /* D3d8 only supports sysmem surfaces, which are created via CreateImageSurface. Other tests confirm
5438 * that they are D3DPOOL_SYSTEMMEM surfaces, but their creation restriction behaves like the scratch
5440 {D3DRTYPE_SURFACE
, "D3DRTYPE_SURFACE", D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", FALSE
, TRUE
},
5442 {D3DRTYPE_TEXTURE
, "D3DRTYPE_TEXTURE", D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", TRUE
, FALSE
},
5443 {D3DRTYPE_TEXTURE
, "D3DRTYPE_TEXTURE", D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", TRUE
, FALSE
},
5444 {D3DRTYPE_TEXTURE
, "D3DRTYPE_TEXTURE", D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
, FALSE
},
5445 {D3DRTYPE_TEXTURE
, "D3DRTYPE_TEXTURE", D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", FALSE
, TRUE
},
5447 {D3DRTYPE_CUBETEXTURE
, "D3DRTYPE_CUBETEXTURE", D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", TRUE
, FALSE
},
5448 {D3DRTYPE_CUBETEXTURE
, "D3DRTYPE_CUBETEXTURE", D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", TRUE
, FALSE
},
5449 {D3DRTYPE_CUBETEXTURE
, "D3DRTYPE_CUBETEXTURE", D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
, FALSE
},
5450 {D3DRTYPE_CUBETEXTURE
, "D3DRTYPE_CUBETEXTURE", D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", FALSE
, TRUE
},
5452 IDirect3DTexture8
*texture
;
5453 IDirect3DCubeTexture8
*cube_texture
;
5454 IDirect3DSurface8
*surface
;
5455 D3DLOCKED_RECT locked_rect
;
5456 IDirect3DDevice8
*device
;
5457 unsigned int i
, j
, k
, w
, h
;
5463 BOOL tex_pow2
, cube_pow2
;
5465 static const RECT invalid
[] =
5467 {60, 60, 60, 68}, /* 0 height */
5468 {60, 60, 68, 60}, /* 0 width */
5469 {68, 60, 60, 68}, /* left > right */
5470 {60, 68, 68, 60}, /* top > bottom */
5471 {-8, 60, 0, 68}, /* left < surface */
5472 {60, -8, 68, 0}, /* top < surface */
5473 {-16, 60, -8, 68}, /* right < surface */
5474 {60, -16, 68, -8}, /* bottom < surface */
5475 {60, 60, 136, 68}, /* right > surface */
5476 {60, 60, 68, 136}, /* bottom > surface */
5477 {136, 60, 144, 68}, /* left > surface */
5478 {60, 136, 68, 144}, /* top > surface */
5481 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
5482 0, 0, 640, 480, 0, 0, 0, 0);
5483 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
5484 ok(!!d3d
, "Failed to create a D3D object.\n");
5485 if (!(device
= create_device(d3d
, window
, NULL
)))
5487 skip("Failed to create a D3D device, skipping tests.\n");
5488 IDirect3D8_Release(d3d
);
5489 DestroyWindow(window
);
5493 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
5494 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
5495 tex_pow2
= caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
;
5497 tex_pow2
= !(caps
.TextureCaps
& D3DPTEXTURECAPS_NONPOW2CONDITIONAL
);
5498 cube_pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP_POW2
);
5500 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
5502 BOOL tex_support
, cube_support
, surface_support
, format_known
;
5504 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5505 0, D3DRTYPE_TEXTURE
, formats
[i
].fmt
);
5506 tex_support
= SUCCEEDED(hr
);
5507 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5508 0, D3DRTYPE_CUBETEXTURE
, formats
[i
].fmt
);
5509 cube_support
= SUCCEEDED(hr
);
5510 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5511 0, D3DRTYPE_SURFACE
, formats
[i
].fmt
);
5512 surface_support
= SUCCEEDED(hr
);
5514 /* Scratch pool in general allows texture creation even if the driver does
5515 * not support the format. If the format is an extension format that is not
5516 * known to the runtime, like ATI2N, some driver support is required for
5519 * It is also possible that Windows Vista and Windows 7 d3d8 runtimes know
5520 * about ATI2N. I cannot check this because all my Vista+ machines support
5521 * ATI2N in hardware, but none of my WinXP machines do. */
5522 format_known
= tex_support
|| cube_support
|| surface_support
;
5524 for (w
= 1; w
<= 8; w
++)
5526 for (h
= 1; h
<= 8; h
++)
5528 BOOL block_aligned
= TRUE
;
5531 if (w
& (formats
[i
].block_width
- 1) || h
& (formats
[i
].block_height
- 1))
5532 block_aligned
= FALSE
;
5534 size_is_pow2
= !(w
& (w
- 1) || h
& (h
- 1));
5536 for (j
= 0; j
< sizeof(create_tests
) / sizeof(*create_tests
); j
++)
5540 BOOL may_succeed
= FALSE
;
5541 IUnknown
**check_null
;
5543 if (!formats
[i
].core_fmt
)
5545 /* AMD warns against creating ATI2N textures smaller than
5546 * the block size because the runtime cannot calculate the
5547 * correct texture size. Generalize this for all extension
5549 if (w
< formats
[i
].block_width
|| h
< formats
[i
].block_height
)
5553 texture
= (IDirect3DTexture8
*)0xdeadbeef;
5554 cube_texture
= (IDirect3DCubeTexture8
*)0xdeadbeef;
5555 surface
= (IDirect3DSurface8
*)0xdeadbeef;
5557 switch (create_tests
[j
].rtype
)
5559 case D3DRTYPE_TEXTURE
:
5560 check_null
= (IUnknown
**)&texture
;
5561 hr
= IDirect3DDevice8_CreateTexture(device
, w
, h
, 1, 0,
5562 formats
[i
].fmt
, create_tests
[j
].pool
, &texture
);
5563 support
= tex_support
;
5567 case D3DRTYPE_CUBETEXTURE
:
5570 check_null
= (IUnknown
**)&cube_texture
;
5571 hr
= IDirect3DDevice8_CreateCubeTexture(device
, w
, 1, 0,
5572 formats
[i
].fmt
, create_tests
[j
].pool
, &cube_texture
);
5573 support
= cube_support
;
5577 case D3DRTYPE_SURFACE
:
5578 check_null
= (IUnknown
**)&surface
;
5579 hr
= IDirect3DDevice8_CreateImageSurface(device
, w
, h
,
5580 formats
[i
].fmt
, &surface
);
5581 support
= surface_support
;
5592 if (create_tests
[j
].need_driver_support
&& !support
)
5593 expect_hr
= D3DERR_INVALIDCALL
;
5594 else if (create_tests
[j
].need_runtime_support
&& !formats
[i
].core_fmt
&& !format_known
)
5595 expect_hr
= D3DERR_INVALIDCALL
;
5596 else if (formats
[i
].create_size_checked
&& !block_aligned
)
5597 expect_hr
= D3DERR_INVALIDCALL
;
5598 else if (pow2
&& !size_is_pow2
&& create_tests
[j
].need_driver_support
)
5599 expect_hr
= D3DERR_INVALIDCALL
;
5603 if (!formats
[i
].core_fmt
&& !format_known
&& FAILED(expect_hr
))
5606 /* Wine knows about ATI2N and happily creates a scratch resource even if GL
5607 * does not support it. Accept scratch creation of extension formats on
5608 * Windows as well if it occurs. We don't really care if e.g. a Windows 7
5609 * on an r200 GPU creates scratch ATI2N texture even though the card doesn't
5611 ok(hr
== expect_hr
|| ((SUCCEEDED(hr
) && may_succeed
)),
5612 "Got unexpected hr %#x for format %s, pool %s, type %s, size %ux%u.\n",
5613 hr
, formats
[i
].name
, create_tests
[j
].pool_name
, create_tests
[j
].type_name
, w
, h
);
5616 ok(*check_null
== NULL
, "Got object ptr %p, expected NULL.\n", *check_null
);
5618 IUnknown_Release(*check_null
);
5623 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5624 D3DUSAGE_DYNAMIC
, D3DRTYPE_TEXTURE
, formats
[i
].fmt
);
5627 skip("Format %s not supported, skipping lockrect offset tests.\n", formats
[i
].name
);
5631 for (j
= 0; j
< (sizeof(pools
) / sizeof(*pools
)); ++j
)
5633 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1,
5634 pools
[j
].pool
== D3DPOOL_DEFAULT
? D3DUSAGE_DYNAMIC
: 0,
5635 formats
[i
].fmt
, pools
[j
].pool
, &texture
);
5636 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
5637 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &surface
);
5638 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
5639 IDirect3DTexture8_Release(texture
);
5641 if (formats
[i
].block_width
> 1)
5643 SetRect(&rect
, formats
[i
].block_width
>> 1, 0, formats
[i
].block_width
, formats
[i
].block_height
);
5644 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &rect
, 0);
5645 ok(FAILED(hr
) == !pools
[j
].success
|| broken(formats
[i
].broken
),
5646 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5647 SUCCEEDED(hr
) ? "succeeded" : "failed",
5648 pools
[j
].success
? "success" : "failure", formats
[i
].name
, pools
[j
].name
);
5651 hr
= IDirect3DSurface8_UnlockRect(surface
);
5652 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5655 SetRect(&rect
, 0, 0, formats
[i
].block_width
>> 1, formats
[i
].block_height
);
5656 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &rect
, 0);
5657 ok(FAILED(hr
) == !pools
[j
].success
|| broken(formats
[i
].broken
),
5658 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5659 SUCCEEDED(hr
) ? "succeeded" : "failed",
5660 pools
[j
].success
? "success" : "failure", formats
[i
].name
, pools
[j
].name
);
5663 hr
= IDirect3DSurface8_UnlockRect(surface
);
5664 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5668 if (formats
[i
].block_height
> 1)
5670 SetRect(&rect
, 0, formats
[i
].block_height
>> 1, formats
[i
].block_width
, formats
[i
].block_height
);
5671 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &rect
, 0);
5672 ok(FAILED(hr
) == !pools
[j
].success
|| broken(formats
[i
].broken
),
5673 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5674 SUCCEEDED(hr
) ? "succeeded" : "failed",
5675 pools
[j
].success
? "success" : "failure", formats
[i
].name
, pools
[j
].name
);
5678 hr
= IDirect3DSurface8_UnlockRect(surface
);
5679 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5682 SetRect(&rect
, 0, 0, formats
[i
].block_width
, formats
[i
].block_height
>> 1);
5683 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &rect
, 0);
5684 ok(FAILED(hr
) == !pools
[j
].success
|| broken(formats
[i
].broken
),
5685 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5686 SUCCEEDED(hr
) ? "succeeded" : "failed",
5687 pools
[j
].success
? "success" : "failure", formats
[i
].name
, pools
[j
].name
);
5690 hr
= IDirect3DSurface8_UnlockRect(surface
);
5691 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5695 for (k
= 0; k
< sizeof(invalid
) / sizeof(*invalid
); ++k
)
5697 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &invalid
[k
], 0);
5698 ok(FAILED(hr
) == !pools
[j
].success
, "Invalid lock %s(%#x), expected %s, format %s, pool %s, case %u.\n",
5699 SUCCEEDED(hr
) ? "succeeded" : "failed", hr
, pools
[j
].success
? "success" : "failure",
5700 formats
[i
].name
, pools
[j
].name
, k
);
5703 hr
= IDirect3DSurface8_UnlockRect(surface
);
5704 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5708 SetRect(&rect
, 0, 0, formats
[i
].block_width
, formats
[i
].block_height
);
5709 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &rect
, 0);
5710 ok(hr
== D3D_OK
, "Got unexpected hr %#x for format %s, pool %s.\n", hr
, formats
[i
].name
, pools
[j
].name
);
5711 hr
= IDirect3DSurface8_UnlockRect(surface
);
5712 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5714 IDirect3DSurface8_Release(surface
);
5717 if (formats
[i
].block_width
== 1 && formats
[i
].block_height
== 1)
5719 if (!formats
[i
].core_fmt
)
5722 hr
= IDirect3DDevice8_CreateTexture(device
, formats
[i
].block_width
, formats
[i
].block_height
, 2,
5723 D3DUSAGE_DYNAMIC
, formats
[i
].fmt
, D3DPOOL_DEFAULT
, &texture
);
5724 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x, format %s.\n", hr
, formats
[i
].name
);
5726 hr
= IDirect3DTexture8_LockRect(texture
, 1, &locked_rect
, NULL
, 0);
5727 ok(SUCCEEDED(hr
), "Failed lock texture, hr %#x.\n", hr
);
5728 hr
= IDirect3DTexture8_UnlockRect(texture
, 1);
5729 ok(SUCCEEDED(hr
), "Failed lock texture, hr %#x.\n", hr
);
5733 rect
.right
= formats
[i
].block_width
== 1 ? 1 : formats
[i
].block_width
>> 1;
5734 rect
.bottom
= formats
[i
].block_height
== 1 ? 1 : formats
[i
].block_height
>> 1;
5735 hr
= IDirect3DTexture8_LockRect(texture
, 1, &locked_rect
, &rect
, 0);
5736 ok(SUCCEEDED(hr
), "Failed lock texture, hr %#x.\n", hr
);
5737 hr
= IDirect3DTexture8_UnlockRect(texture
, 1);
5738 ok(SUCCEEDED(hr
), "Failed lock texture, hr %#x.\n", hr
);
5740 rect
.right
= formats
[i
].block_width
;
5741 rect
.bottom
= formats
[i
].block_height
;
5742 hr
= IDirect3DTexture8_LockRect(texture
, 1, &locked_rect
, &rect
, 0);
5743 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5745 IDirect3DTexture8_UnlockRect(texture
, 1);
5747 IDirect3DTexture8_Release(texture
);
5750 refcount
= IDirect3DDevice8_Release(device
);
5751 ok(!refcount
, "Device has %u references left.\n", refcount
);
5752 IDirect3D8_Release(d3d
);
5753 DestroyWindow(window
);
5756 static void test_set_palette(void)
5758 IDirect3DDevice8
*device
;
5763 PALETTEENTRY pal
[256];
5767 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
5768 0, 0, 640, 480, 0, 0, 0, 0);
5769 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
5770 ok(!!d3d8
, "Failed to create a D3D object.\n");
5771 if (!(device
= create_device(d3d8
, window
, NULL
)))
5773 skip("Failed to create a D3D device, skipping tests.\n");
5774 IDirect3D8_Release(d3d8
);
5775 DestroyWindow(window
);
5779 for (i
= 0; i
< sizeof(pal
) / sizeof(*pal
); i
++)
5784 pal
[i
].peFlags
= 0xff;
5786 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 0, pal
);
5787 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
5789 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
5790 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
5791 for (i
= 0; i
< sizeof(pal
) / sizeof(*pal
); i
++)
5798 if (caps
.TextureCaps
& D3DPTEXTURECAPS_ALPHAPALETTE
)
5800 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 0, pal
);
5801 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
5805 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 0, pal
);
5806 ok(hr
== D3DERR_INVALIDCALL
, "SetPaletteEntries returned %#x, expected D3DERR_INVALIDCALL.\n", hr
);
5809 refcount
= IDirect3DDevice8_Release(device
);
5810 ok(!refcount
, "Device has %u references left.\n", refcount
);
5811 IDirect3D8_Release(d3d8
);
5812 DestroyWindow(window
);
5815 static void test_swvp_buffer(void)
5817 IDirect3DDevice8
*device
;
5823 IDirect3DVertexBuffer8
*buffer
;
5824 static const unsigned int bufsize
= 1024;
5825 D3DVERTEXBUFFER_DESC desc
;
5826 struct device_desc device_desc
;
5832 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
5833 0, 0, 640, 480, 0, 0, 0, 0);
5834 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
5835 ok(!!d3d8
, "Failed to create a D3D object.\n");
5837 device_desc
.device_window
= window
;
5838 device_desc
.width
= 640;
5839 device_desc
.height
= 480;
5840 device_desc
.flags
= CREATE_DEVICE_SWVP_ONLY
;
5841 if (!(device
= create_device(d3d8
, window
, &device_desc
)))
5843 skip("Failed to create a D3D device, skipping tests.\n");
5844 IDirect3D8_Release(d3d8
);
5845 DestroyWindow(window
);
5849 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, bufsize
* sizeof(*ptr
), D3DUSAGE_DYNAMIC
| D3DUSAGE_WRITEONLY
, 0,
5850 D3DPOOL_DEFAULT
, &buffer
);
5851 ok(SUCCEEDED(hr
), "Failed to create buffer, hr %#x.\n", hr
);
5852 hr
= IDirect3DVertexBuffer8_GetDesc(buffer
, &desc
);
5853 ok(SUCCEEDED(hr
), "Failed to get desc, hr %#x.\n", hr
);
5854 ok(desc
.Pool
== D3DPOOL_DEFAULT
, "Got pool %u, expected D3DPOOL_DEFAULT\n", desc
.Pool
);
5855 ok(desc
.Usage
== (D3DUSAGE_DYNAMIC
| D3DUSAGE_WRITEONLY
),
5856 "Got usage %u, expected D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY\n", desc
.Usage
);
5858 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, bufsize
* sizeof(*ptr
), (BYTE
**)&ptr
, D3DLOCK_DISCARD
);
5859 ok(SUCCEEDED(hr
), "Failed to lock buffer, hr %#x.\n", hr
);
5860 for (i
= 0; i
< bufsize
; i
++)
5862 ptr
[i
].x
= i
* 1.0f
;
5863 ptr
[i
].y
= i
* 2.0f
;
5864 ptr
[i
].z
= i
* 3.0f
;
5866 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
5867 ok(SUCCEEDED(hr
), "Failed to unlock buffer, hr %#x.\n", hr
);
5869 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
);
5870 ok(SUCCEEDED(hr
), "Failed to set fvf, hr %#x.\n", hr
);
5871 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, buffer
, sizeof(*ptr
));
5872 ok(SUCCEEDED(hr
), "Failed to set stream source, hr %#x.\n", hr
);
5873 hr
= IDirect3DDevice8_BeginScene(device
);
5874 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
5875 hr
= IDirect3DDevice8_DrawPrimitive(device
, D3DPT_TRIANGLELIST
, 0, 2);
5876 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
5877 hr
= IDirect3DDevice8_EndScene(device
);
5878 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
5880 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, bufsize
* sizeof(*ptr2
), (BYTE
**)&ptr2
, D3DLOCK_DISCARD
);
5881 ok(SUCCEEDED(hr
), "Failed to lock buffer, hr %#x.\n", hr
);
5882 ok(ptr
== ptr2
, "Lock returned two different pointers: %p, %p\n", ptr
, ptr2
);
5883 for (i
= 0; i
< bufsize
; i
++)
5885 if (ptr2
[i
].x
!= i
* 1.0f
|| ptr2
[i
].y
!= i
* 2.0f
|| ptr2
[i
].z
!= i
* 3.0f
)
5887 ok(FALSE
, "Vertex %u is %f,%f,%f, expected %f,%f,%f\n", i
,
5888 ptr2
[i
].x
, ptr2
[i
].y
, ptr2
[i
].z
, i
* 1.0f
, i
* 2.0f
, i
* 3.0f
);
5892 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
5893 ok(SUCCEEDED(hr
), "Failed to unlock buffer, hr %#x.\n", hr
);
5895 IDirect3DVertexBuffer8_Release(buffer
);
5896 refcount
= IDirect3DDevice8_Release(device
);
5897 ok(!refcount
, "Device has %u references left.\n", refcount
);
5898 IDirect3D8_Release(d3d8
);
5899 DestroyWindow(window
);
5902 static void test_managed_buffer(void)
5904 static const unsigned int vertex_count
= 1024;
5905 IDirect3DVertexBuffer8
*buffer
;
5906 D3DVERTEXBUFFER_DESC desc
;
5907 IDirect3DDevice8
*device
;
5908 struct vec3
*ptr
, *ptr2
;
5915 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
5916 0, 0, 640, 480, 0, 0, 0, 0);
5917 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
5918 ok(!!d3d8
, "Failed to create a D3D object.\n");
5919 if (!(device
= create_device(d3d8
, window
, NULL
)))
5921 skip("Failed to create a D3D device, skipping tests.\n");
5922 IDirect3D8_Release(d3d8
);
5923 DestroyWindow(window
);
5927 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, vertex_count
* sizeof(*ptr
), 0, 0, D3DPOOL_MANAGED
, &buffer
);
5928 ok(SUCCEEDED(hr
), "Failed to create buffer, hr %#x.\n", hr
);
5929 hr
= IDirect3DVertexBuffer8_GetDesc(buffer
, &desc
);
5930 ok(SUCCEEDED(hr
), "Failed to get desc, hr %#x.\n", hr
);
5931 ok(desc
.Pool
== D3DPOOL_MANAGED
, "Got unexpected pool %#x.\n", desc
.Pool
);
5932 ok(!desc
.Usage
, "Got unexpected usage %#x.\n", desc
.Usage
);
5934 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, vertex_count
* sizeof(*ptr
), (BYTE
**)&ptr
, D3DLOCK_DISCARD
);
5935 ok(SUCCEEDED(hr
), "Failed to lock buffer, hr %#x.\n", hr
);
5936 for (i
= 0; i
< vertex_count
; ++i
)
5938 ptr
[i
].x
= i
* 1.0f
;
5939 ptr
[i
].y
= i
* 2.0f
;
5940 ptr
[i
].z
= i
* 3.0f
;
5942 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
5943 ok(SUCCEEDED(hr
), "Failed to unlock buffer, hr %#x.\n", hr
);
5945 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
);
5946 ok(SUCCEEDED(hr
), "Failed to set fvf, hr %#x.\n", hr
);
5947 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, buffer
, sizeof(*ptr
));
5948 ok(SUCCEEDED(hr
), "Failed to set stream source, hr %#x.\n", hr
);
5949 hr
= IDirect3DDevice8_BeginScene(device
);
5950 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
5951 hr
= IDirect3DDevice8_DrawPrimitive(device
, D3DPT_TRIANGLELIST
, 0, 2);
5952 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
5953 hr
= IDirect3DDevice8_EndScene(device
);
5954 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
5956 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, vertex_count
* sizeof(*ptr2
), (BYTE
**)&ptr2
, D3DLOCK_DISCARD
);
5957 ok(SUCCEEDED(hr
), "Failed to lock buffer, hr %#x.\n", hr
);
5958 ok(ptr2
== ptr
, "Got unexpected ptr2 %p, expected %p.\n", ptr2
, ptr
);
5959 for (i
= 0; i
< vertex_count
; ++i
)
5961 if (ptr2
[i
].x
!= i
* 1.0f
|| ptr2
[i
].y
!= i
* 2.0f
|| ptr2
[i
].z
!= i
* 3.0f
)
5963 ok(FALSE
, "Got unexpected vertex %u {%.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e}.\n",
5964 i
, ptr2
[i
].x
, ptr2
[i
].y
, ptr2
[i
].z
, i
* 1.0f
, i
* 2.0f
, i
* 3.0f
);
5968 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
5969 ok(SUCCEEDED(hr
), "Failed to unlock buffer, hr %#x.\n", hr
);
5971 IDirect3DVertexBuffer8_Release(buffer
);
5972 refcount
= IDirect3DDevice8_Release(device
);
5973 ok(!refcount
, "Device has %u references left.\n", refcount
);
5974 IDirect3D8_Release(d3d8
);
5975 DestroyWindow(window
);
5978 static void test_npot_textures(void)
5980 IDirect3DDevice8
*device
= NULL
;
5986 IDirect3DTexture8
*texture
;
5987 IDirect3DCubeTexture8
*cube_texture
;
5988 IDirect3DVolumeTexture8
*volume_texture
;
5992 const char *pool_name
;
5997 { D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", D3DERR_INVALIDCALL
},
5998 { D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", D3DERR_INVALIDCALL
},
5999 { D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", D3DERR_INVALIDCALL
},
6000 { D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", D3D_OK
},
6002 unsigned int i
, levels
;
6003 BOOL tex_pow2
, cube_pow2
, vol_pow2
;
6005 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6006 0, 0, 640, 480, 0, 0, 0, 0);
6007 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
6008 ok(!!d3d8
, "Failed to create a D3D object.\n");
6009 if (!(device
= create_device(d3d8
, window
, NULL
)))
6011 skip("Failed to create a D3D device, skipping tests.\n");
6015 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
6016 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6017 tex_pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
);
6018 cube_pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP_POW2
);
6019 vol_pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP_POW2
);
6020 ok(cube_pow2
== tex_pow2
, "Cube texture and 2d texture pow2 restrictions mismatch.\n");
6021 ok(vol_pow2
== tex_pow2
, "Volume texture and 2d texture pow2 restrictions mismatch.\n");
6023 for (i
= 0; i
< sizeof(pools
) / sizeof(*pools
); i
++)
6025 for (levels
= 0; levels
<= 2; levels
++)
6029 hr
= IDirect3DDevice8_CreateTexture(device
, 10, 10, levels
, 0, D3DFMT_X8R8G8B8
,
6030 pools
[i
].pool
, &texture
);
6035 else if (caps
.TextureCaps
& D3DPTEXTURECAPS_NONPOW2CONDITIONAL
)
6040 expected
= pools
[i
].hr
;
6044 expected
= pools
[i
].hr
;
6046 ok(hr
== expected
, "CreateTexture(w=h=10, %s, levels=%u) returned hr %#x, expected %#x.\n",
6047 pools
[i
].pool_name
, levels
, hr
, expected
);
6050 IDirect3DTexture8_Release(texture
);
6053 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 3, 1, 0, D3DFMT_X8R8G8B8
,
6054 pools
[i
].pool
, &cube_texture
);
6057 ok(hr
== pools
[i
].hr
, "CreateCubeTexture(EdgeLength=3, %s) returned hr %#x, expected %#x.\n",
6058 pools
[i
].pool_name
, hr
, pools
[i
].hr
);
6062 ok(SUCCEEDED(hr
), "CreateCubeTexture(EdgeLength=3, %s) returned hr %#x, expected %#x.\n",
6063 pools
[i
].pool_name
, hr
, D3D_OK
);
6067 IDirect3DCubeTexture8_Release(cube_texture
);
6069 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 2, 2, 3, 1, 0, D3DFMT_X8R8G8B8
,
6070 pools
[i
].pool
, &volume_texture
);
6073 ok(hr
== pools
[i
].hr
, "CreateVolumeTextur(Depth=3, %s) returned hr %#x, expected %#x.\n",
6074 pools
[i
].pool_name
, hr
, pools
[i
].hr
);
6078 ok(SUCCEEDED(hr
), "CreateVolumeTextur(Depth=3, %s) returned hr %#x, expected %#x.\n",
6079 pools
[i
].pool_name
, hr
, D3D_OK
);
6083 IDirect3DVolumeTexture8_Release(volume_texture
);
6089 refcount
= IDirect3DDevice8_Release(device
);
6090 ok(!refcount
, "Device has %u references left.\n", refcount
);
6092 IDirect3D8_Release(d3d8
);
6093 DestroyWindow(window
);
6097 static void test_volume_locking(void)
6099 IDirect3DDevice8
*device
;
6103 IDirect3DVolumeTexture8
*texture
;
6105 D3DLOCKED_BOX locked_box
;
6112 HRESULT create_hr
, lock_hr
;
6116 { D3DPOOL_DEFAULT
, 0, D3D_OK
, D3DERR_INVALIDCALL
},
6117 { D3DPOOL_DEFAULT
, D3DUSAGE_DYNAMIC
, D3D_OK
, D3D_OK
},
6118 { D3DPOOL_SYSTEMMEM
, 0, D3D_OK
, D3D_OK
},
6119 { D3DPOOL_SYSTEMMEM
, D3DUSAGE_DYNAMIC
, D3D_OK
, D3D_OK
},
6120 { D3DPOOL_MANAGED
, 0, D3D_OK
, D3D_OK
},
6121 { D3DPOOL_MANAGED
, D3DUSAGE_DYNAMIC
, D3DERR_INVALIDCALL
, D3D_OK
},
6122 { D3DPOOL_SCRATCH
, 0, D3D_OK
, D3D_OK
},
6123 { D3DPOOL_SCRATCH
, D3DUSAGE_DYNAMIC
, D3DERR_INVALIDCALL
, D3D_OK
},
6126 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6127 0, 0, 640, 480, 0, 0, 0, 0);
6128 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
6129 ok(!!d3d8
, "Failed to create a D3D object.\n");
6130 if (!(device
= create_device(d3d8
, window
, NULL
)))
6132 skip("Failed to create a D3D device, skipping tests.\n");
6133 IDirect3D8_Release(d3d8
);
6134 DestroyWindow(window
);
6138 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
6139 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6140 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
))
6142 skip("Volume textures not supported, skipping test.\n");
6146 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
6148 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 4, 4, 4, 1, tests
[i
].usage
,
6149 D3DFMT_A8R8G8B8
, tests
[i
].pool
, &texture
);
6150 ok(hr
== tests
[i
].create_hr
, "Creating volume texture pool=%u, usage=%#x returned %#x, expected %#x.\n",
6151 tests
[i
].pool
, tests
[i
].usage
, hr
, tests
[i
].create_hr
);
6155 locked_box
.pBits
= (void *)0xdeadbeef;
6156 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, NULL
, 0);
6157 ok(hr
== tests
[i
].lock_hr
, "Lock returned %#x, expected %#x.\n", hr
, tests
[i
].lock_hr
);
6160 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6161 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6165 ok (locked_box
.pBits
== NULL
, "Failed lock set pBits = %p, expected NULL.\n", locked_box
.pBits
);
6167 IDirect3DVolumeTexture8_Release(texture
);
6171 refcount
= IDirect3DDevice8_Release(device
);
6172 ok(!refcount
, "Device has %u references left.\n", refcount
);
6173 IDirect3D8_Release(d3d8
);
6174 DestroyWindow(window
);
6177 static void test_update_volumetexture(void)
6179 IDirect3DDevice8
*device
;
6183 IDirect3DVolumeTexture8
*src
, *dst
;
6185 D3DLOCKED_BOX locked_box
;
6190 D3DPOOL src_pool
, dst_pool
;
6195 { D3DPOOL_DEFAULT
, D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
},
6196 { D3DPOOL_MANAGED
, D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
},
6197 { D3DPOOL_SYSTEMMEM
, D3DPOOL_DEFAULT
, D3D_OK
},
6198 { D3DPOOL_SCRATCH
, D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
},
6200 { D3DPOOL_DEFAULT
, D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
},
6201 { D3DPOOL_MANAGED
, D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
},
6202 { D3DPOOL_SYSTEMMEM
, D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
},
6203 { D3DPOOL_SCRATCH
, D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
},
6205 { D3DPOOL_DEFAULT
, D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
},
6206 { D3DPOOL_MANAGED
, D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
},
6207 { D3DPOOL_SYSTEMMEM
, D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
},
6208 { D3DPOOL_SCRATCH
, D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
},
6210 { D3DPOOL_DEFAULT
, D3DPOOL_SCRATCH
, D3DERR_INVALIDCALL
},
6211 { D3DPOOL_MANAGED
, D3DPOOL_SCRATCH
, D3DERR_INVALIDCALL
},
6212 { D3DPOOL_SYSTEMMEM
, D3DPOOL_SCRATCH
, D3DERR_INVALIDCALL
},
6213 { D3DPOOL_SCRATCH
, D3DPOOL_SCRATCH
, D3DERR_INVALIDCALL
},
6217 UINT src_size
, dst_size
;
6218 UINT src_lvl
, dst_lvl
;
6219 D3DFORMAT src_fmt
, dst_fmt
;
6223 { 8, 8, 0, 0, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
6224 { 8, 8, 4, 4, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
6225 { 8, 8, 2, 2, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
6226 { 8, 8, 1, 1, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
6227 { 8, 8, 4, 0, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
6228 { 8, 8, 1, 4, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
}, /* Different level count */
6229 { 4, 8, 1, 1, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
}, /* Different size */
6230 { 8, 8, 4, 4, D3DFMT_A8R8G8B8
, D3DFMT_X8R8G8B8
}, /* Different format */
6233 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6234 0, 0, 640, 480, 0, 0, 0, 0);
6235 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
6236 ok(!!d3d8
, "Failed to create a D3D object.\n");
6237 if (!(device
= create_device(d3d8
, window
, NULL
)))
6239 skip("Failed to create a D3D device, skipping tests.\n");
6240 IDirect3D8_Release(d3d8
);
6241 DestroyWindow(window
);
6245 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
6246 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6247 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
))
6249 skip("Volume textures not supported, skipping test.\n");
6253 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
6255 DWORD src_usage
= tests
[i
].src_pool
== D3DPOOL_DEFAULT
? D3DUSAGE_DYNAMIC
: 0;
6256 DWORD dst_usage
= tests
[i
].dst_pool
== D3DPOOL_DEFAULT
? D3DUSAGE_DYNAMIC
: 0;
6258 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 1, 1, 1, 1, src_usage
,
6259 D3DFMT_A8R8G8B8
, tests
[i
].src_pool
, &src
);
6260 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
6261 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 1, 1, 1, 1, dst_usage
,
6262 D3DFMT_A8R8G8B8
, tests
[i
].dst_pool
, &dst
);
6263 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
6265 hr
= IDirect3DVolumeTexture8_LockBox(src
, 0, &locked_box
, NULL
, 0);
6266 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
6267 *((DWORD
*)locked_box
.pBits
) = 0x11223344;
6268 hr
= IDirect3DVolumeTexture8_UnlockBox(src
, 0);
6269 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6271 hr
= IDirect3DDevice8_UpdateTexture(device
, (IDirect3DBaseTexture8
*)src
, (IDirect3DBaseTexture8
*)dst
);
6272 ok(hr
== tests
[i
].hr
, "UpdateTexture returned %#x, expected %#x, src pool %x, dst pool %u.\n",
6273 hr
, tests
[i
].hr
, tests
[i
].src_pool
, tests
[i
].dst_pool
);
6277 DWORD content
= *((DWORD
*)locked_box
.pBits
);
6278 hr
= IDirect3DVolumeTexture8_LockBox(dst
, 0, &locked_box
, NULL
, 0);
6279 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
6280 ok(content
== 0x11223344, "Dest texture contained %#x, expected 0x11223344.\n", content
);
6281 hr
= IDirect3DVolumeTexture8_UnlockBox(dst
, 0);
6282 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6284 IDirect3DVolumeTexture8_Release(src
);
6285 IDirect3DVolumeTexture8_Release(dst
);
6288 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_MIPVOLUMEMAP
))
6290 skip("Mipmapped volume maps not supported.\n");
6294 for (i
= 0; i
< sizeof(tests2
) / sizeof(*tests2
); i
++)
6296 hr
= IDirect3DDevice8_CreateVolumeTexture(device
,
6297 tests2
[i
].src_size
, tests2
[i
].src_size
, tests2
[i
].src_size
,
6298 tests2
[i
].src_lvl
, 0, tests2
[i
].src_fmt
, D3DPOOL_SYSTEMMEM
, &src
);
6299 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x, case %u.\n", hr
, i
);
6300 hr
= IDirect3DDevice8_CreateVolumeTexture(device
,
6301 tests2
[i
].dst_size
, tests2
[i
].dst_size
, tests2
[i
].dst_size
,
6302 tests2
[i
].dst_lvl
, 0, tests2
[i
].dst_fmt
, D3DPOOL_DEFAULT
, &dst
);
6303 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x, case %u.\n", hr
, i
);
6305 hr
= IDirect3DDevice8_UpdateTexture(device
, (IDirect3DBaseTexture8
*)src
, (IDirect3DBaseTexture8
*)dst
);
6306 todo_wine_if (FAILED(hr
))
6307 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x, case %u.\n", hr
, i
);
6309 IDirect3DVolumeTexture8_Release(src
);
6310 IDirect3DVolumeTexture8_Release(dst
);
6313 /* As far as I can see, UpdateTexture on non-matching texture behaves like a memcpy. The raw data
6314 * stays the same in a format change, a 2x2x1 texture is copied into the first row of a 4x4x1 texture,
6315 * etc. I could not get it to segfault, but the nonexistent 5th pixel of a 2x2x1 texture is copied into
6316 * pixel 1x2x1 of a 4x4x1 texture, demonstrating a read beyond the texture's end. I suspect any bad
6317 * memory access is silently ignored by the runtime, in the kernel or on the GPU.
6319 * I'm not adding tests for this behavior until an application needs it. */
6322 refcount
= IDirect3DDevice8_Release(device
);
6323 ok(!refcount
, "Device has %u references left.\n", refcount
);
6324 IDirect3D8_Release(d3d8
);
6325 DestroyWindow(window
);
6328 static void test_create_rt_ds_fail(void)
6330 IDirect3DDevice8
*device
;
6335 IDirect3DSurface8
*surface
;
6337 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6338 0, 0, 640, 480, 0, 0, 0, 0);
6339 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
6340 ok(!!d3d8
, "Failed to create a D3D object.\n");
6341 if (!(device
= create_device(d3d8
, window
, NULL
)))
6343 skip("Failed to create a D3D device, skipping tests.\n");
6344 IDirect3D8_Release(d3d8
);
6345 DestroyWindow(window
);
6349 /* Output pointer == NULL segfaults on Windows. */
6351 surface
= (IDirect3DSurface8
*)0xdeadbeef;
6352 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 4, 4, D3DFMT_D16
,
6353 D3DMULTISAMPLE_NONE
, FALSE
, &surface
);
6354 ok(hr
== D3DERR_INVALIDCALL
, "Creating a D16 render target returned hr %#x.\n", hr
);
6355 ok(surface
== NULL
, "Got pointer %p, expected NULL.\n", surface
);
6357 IDirect3DSurface8_Release(surface
);
6359 surface
= (IDirect3DSurface8
*)0xdeadbeef;
6360 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 4, 4, D3DFMT_A8R8G8B8
,
6361 D3DMULTISAMPLE_NONE
, &surface
);
6362 ok(hr
== D3DERR_INVALIDCALL
, "Creating a A8R8G8B8 depth stencil returned hr %#x.\n", hr
);
6363 ok(surface
== NULL
, "Got pointer %p, expected NULL.\n", surface
);
6365 IDirect3DSurface8_Release(surface
);
6367 refcount
= IDirect3DDevice8_Release(device
);
6368 ok(!refcount
, "Device has %u references left.\n", refcount
);
6369 IDirect3D8_Release(d3d8
);
6370 DestroyWindow(window
);
6373 static void test_volume_blocks(void)
6375 IDirect3DDevice8
*device
;
6381 IDirect3DVolumeTexture8
*texture
;
6382 unsigned int w
, h
, d
, i
, j
;
6387 unsigned int block_width
;
6388 unsigned int block_height
;
6389 unsigned int block_depth
;
6390 unsigned int block_size
;
6391 unsigned int broken
;
6392 BOOL create_size_checked
, core_fmt
;
6396 /* Scratch volumes enforce DXTn block locks, unlike their surface counterparts.
6397 * ATI2N and YUV blocks are not enforced on any tested card (r200, gtx 460). */
6398 {D3DFMT_DXT1
, "D3DFMT_DXT1", 4, 4, 1, 8, 0, TRUE
, TRUE
},
6399 {D3DFMT_DXT2
, "D3DFMT_DXT2", 4, 4, 1, 16, 0, TRUE
, TRUE
},
6400 {D3DFMT_DXT3
, "D3DFMT_DXT3", 4, 4, 1, 16, 0, TRUE
, TRUE
},
6401 {D3DFMT_DXT4
, "D3DFMT_DXT4", 4, 4, 1, 16, 0, TRUE
, TRUE
},
6402 {D3DFMT_DXT5
, "D3DFMT_DXT5", 4, 4, 1, 16, 0, TRUE
, TRUE
},
6403 {D3DFMT_DXT5
, "D3DFMT_DXT5", 4, 4, 1, 16, 0, TRUE
, TRUE
},
6404 /* ATI2N has 2x2 blocks on all AMD cards and Geforce 7 cards,
6405 * which doesn't match the format spec. On newer Nvidia cards
6406 * it has the correct 4x4 block size.
6407 * ATI1N volume textures are only supported by AMD GPUs right
6408 * now and locking offsets seem just wrong. */
6409 {MAKEFOURCC('A','T','I','1'), "ATI1N", 4, 4, 1, 8, 2, FALSE
, FALSE
},
6410 {MAKEFOURCC('A','T','I','2'), "ATI2N", 4, 4, 1, 16, 1, FALSE
, FALSE
},
6411 {D3DFMT_YUY2
, "D3DFMT_YUY2", 2, 1, 1, 4, 1, FALSE
, TRUE
},
6412 {D3DFMT_UYVY
, "D3DFMT_UYVY", 2, 1, 1, 4, 1, FALSE
, TRUE
},
6418 BOOL need_driver_support
, need_runtime_support
;
6422 {D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", TRUE
, FALSE
},
6423 {D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", FALSE
, TRUE
},
6424 {D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM",TRUE
, FALSE
},
6425 {D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
, FALSE
},
6429 unsigned int x
, y
, z
, x2
, y2
, z2
;
6443 D3DLOCKED_BOX locked_box
;
6445 INT expected_row_pitch
, expected_slice_pitch
;
6448 unsigned int offset
, expected_offset
;
6450 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6451 0, 0, 640, 480, 0, 0, 0, 0);
6452 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
6453 ok(!!d3d8
, "Failed to create a D3D object.\n");
6454 if (!(device
= create_device(d3d8
, window
, NULL
)))
6456 skip("Failed to create a D3D device, skipping tests.\n");
6457 IDirect3D8_Release(d3d8
);
6458 DestroyWindow(window
);
6461 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
6462 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6463 pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP_POW2
);
6465 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
6467 hr
= IDirect3D8_CheckDeviceFormat(d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
6468 0, D3DRTYPE_VOLUMETEXTURE
, formats
[i
].fmt
);
6469 support
= SUCCEEDED(hr
);
6471 /* Test creation restrictions */
6472 for (w
= 1; w
<= 8; w
++)
6474 for (h
= 1; h
<= 8; h
++)
6476 for (d
= 1; d
<= 8; d
++)
6480 BOOL block_aligned
= TRUE
;
6482 if (w
& (formats
[i
].block_width
- 1) || h
& (formats
[i
].block_height
- 1))
6483 block_aligned
= FALSE
;
6485 size_is_pow2
= !((w
& (w
- 1)) || (h
& (h
- 1)) || (d
& (d
- 1)));
6487 for (j
= 0; j
< sizeof(create_tests
) / sizeof(*create_tests
); j
++)
6489 BOOL may_succeed
= FALSE
;
6491 if (create_tests
[j
].need_runtime_support
&& !formats
[i
].core_fmt
&& !support
)
6492 expect_hr
= D3DERR_INVALIDCALL
;
6493 else if (formats
[i
].create_size_checked
&& !block_aligned
)
6494 expect_hr
= D3DERR_INVALIDCALL
;
6495 else if (pow2
&& !size_is_pow2
&& create_tests
[j
].need_driver_support
)
6496 expect_hr
= D3DERR_INVALIDCALL
;
6497 else if (create_tests
[j
].need_driver_support
&& !support
)
6498 expect_hr
= D3DERR_INVALIDCALL
;
6502 texture
= (IDirect3DVolumeTexture8
*)0xdeadbeef;
6503 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, w
, h
, d
, 1, 0,
6504 formats
[i
].fmt
, create_tests
[j
].pool
, &texture
);
6506 /* Wine knows about ATI2N and happily creates a scratch resource even if GL
6507 * does not support it. Accept scratch creation of extension formats on
6508 * Windows as well if it occurs. We don't really care if e.g. a Windows 7
6509 * on an r200 GPU creates scratch ATI2N texture even though the card doesn't
6511 if (!formats
[i
].core_fmt
&& !support
&& FAILED(expect_hr
))
6514 ok(hr
== expect_hr
|| ((SUCCEEDED(hr
) && may_succeed
)),
6515 "Got unexpected hr %#x for format %s, pool %s, size %ux%ux%u.\n",
6516 hr
, formats
[i
].name
, create_tests
[j
].name
, w
, h
, d
);
6519 ok(texture
== NULL
, "Got texture ptr %p, expected NULL.\n", texture
);
6521 IDirect3DVolumeTexture8_Release(texture
);
6527 if (!support
&& !formats
[i
].core_fmt
)
6530 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 24, 8, 8, 1, 0,
6531 formats
[i
].fmt
, D3DPOOL_SCRATCH
, &texture
);
6532 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
6534 /* Test lockrect offset */
6535 for (j
= 0; j
< sizeof(offset_tests
) / sizeof(*offset_tests
); j
++)
6537 unsigned int bytes_per_pixel
;
6538 bytes_per_pixel
= formats
[i
].block_size
/ (formats
[i
].block_width
* formats
[i
].block_height
);
6540 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, NULL
, 0);
6541 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6543 base
= locked_box
.pBits
;
6544 if (formats
[i
].broken
== 1)
6546 expected_row_pitch
= bytes_per_pixel
* 24;
6548 else if (formats
[i
].broken
== 2)
6550 expected_row_pitch
= 24;
6554 expected_row_pitch
= (24 /* tex width */ + formats
[i
].block_height
- 1) / formats
[i
].block_width
6555 * formats
[i
].block_size
;
6557 ok(locked_box
.RowPitch
== expected_row_pitch
, "Got unexpected row pitch %d for format %s, expected %d.\n",
6558 locked_box
.RowPitch
, formats
[i
].name
, expected_row_pitch
);
6560 if (formats
[i
].broken
)
6562 expected_slice_pitch
= expected_row_pitch
* 8;
6566 expected_slice_pitch
= (8 /* tex height */ + formats
[i
].block_depth
- 1) / formats
[i
].block_height
6567 * expected_row_pitch
;
6569 ok(locked_box
.SlicePitch
== expected_slice_pitch
,
6570 "Got unexpected slice pitch %d for format %s, expected %d.\n",
6571 locked_box
.SlicePitch
, formats
[i
].name
, expected_slice_pitch
);
6573 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6574 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x, j %u.\n", hr
, j
);
6576 box
.Left
= offset_tests
[j
].x
;
6577 box
.Top
= offset_tests
[j
].y
;
6578 box
.Front
= offset_tests
[j
].z
;
6579 box
.Right
= offset_tests
[j
].x2
;
6580 box
.Bottom
= offset_tests
[j
].y2
;
6581 box
.Back
= offset_tests
[j
].z2
;
6582 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
6583 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x, j %u.\n", hr
, j
);
6585 offset
= (BYTE
*)locked_box
.pBits
- base
;
6586 if (formats
[i
].broken
== 1)
6588 expected_offset
= box
.Front
* expected_slice_pitch
6589 + box
.Top
* expected_row_pitch
6590 + box
.Left
* bytes_per_pixel
;
6592 else if (formats
[i
].broken
== 2)
6594 expected_offset
= box
.Front
* expected_slice_pitch
6595 + box
.Top
* expected_row_pitch
6600 expected_offset
= (box
.Front
/ formats
[i
].block_depth
) * expected_slice_pitch
6601 + (box
.Top
/ formats
[i
].block_height
) * expected_row_pitch
6602 + (box
.Left
/ formats
[i
].block_width
) * formats
[i
].block_size
;
6604 ok(offset
== expected_offset
, "Got unexpected offset %u for format %s, expected %u, box start %ux%ux%u.\n",
6605 offset
, formats
[i
].name
, expected_offset
, box
.Left
, box
.Top
, box
.Front
);
6607 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6608 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6611 /* Test partial block locks */
6614 if (formats
[i
].block_width
> 1)
6616 box
.Left
= formats
[i
].block_width
>> 1;
6618 box
.Right
= formats
[i
].block_width
;
6619 box
.Bottom
= formats
[i
].block_height
;
6620 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
6621 ok(FAILED(hr
) || broken(formats
[i
].broken
),
6622 "Partial block lock succeeded, expected failure, format %s.\n",
6626 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6627 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6632 box
.Right
= formats
[i
].block_width
>> 1;
6633 box
.Bottom
= formats
[i
].block_height
;
6634 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
6635 ok(FAILED(hr
) || broken(formats
[i
].broken
),
6636 "Partial block lock succeeded, expected failure, format %s.\n",
6640 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6641 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6645 if (formats
[i
].block_height
> 1)
6648 box
.Top
= formats
[i
].block_height
>> 1;
6649 box
.Right
= formats
[i
].block_width
;
6650 box
.Bottom
= formats
[i
].block_height
;
6651 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
6652 ok(FAILED(hr
) || broken(formats
[i
].broken
),
6653 "Partial block lock succeeded, expected failure, format %s.\n",
6657 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6658 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
>> 1;
6665 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
6666 ok(FAILED(hr
) || broken(formats
[i
].broken
),
6667 "Partial block lock succeeded, expected failure, format %s.\n",
6671 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6672 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6676 /* Test full block lock */
6679 box
.Right
= formats
[i
].block_width
;
6680 box
.Bottom
= formats
[i
].block_height
;
6681 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
6682 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
6683 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6684 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6686 IDirect3DVolumeTexture8_Release(texture
);
6688 /* Test mipmap locks. Don't do this with ATI2N, AMD warns that the runtime
6689 * does not allocate surfaces smaller than the blocksize properly. */
6690 if ((formats
[i
].block_width
> 1 || formats
[i
].block_height
> 1) && formats
[i
].core_fmt
)
6692 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, formats
[i
].block_width
, formats
[i
].block_height
,
6693 2, 2, 0, formats
[i
].fmt
, D3DPOOL_SCRATCH
, &texture
);
6695 ok(SUCCEEDED(hr
), "CreateVolumeTexture failed, hr %#x.\n", hr
);
6696 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 1, &locked_box
, NULL
, 0);
6697 ok(SUCCEEDED(hr
), "Failed to lock volume texture mipmap, hr %#x.\n", hr
);
6698 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 1);
6699 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6701 box
.Left
= box
.Top
= box
.Front
= 0;
6702 box
.Right
= formats
[i
].block_width
== 1 ? 1 : formats
[i
].block_width
>> 1;
6703 box
.Bottom
= formats
[i
].block_height
== 1 ? 1 : formats
[i
].block_height
>> 1;
6705 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 1, &locked_box
, &box
, 0);
6706 ok(SUCCEEDED(hr
), "Failed to lock volume texture mipmap, hr %#x.\n", hr
);
6707 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 1);
6708 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6710 box
.Right
= formats
[i
].block_width
;
6711 box
.Bottom
= formats
[i
].block_height
;
6712 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 1, &locked_box
, &box
, 0);
6713 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
6715 IDirect3DVolumeTexture8_UnlockBox(texture
, 1);
6717 IDirect3DVolumeTexture8_Release(texture
);
6721 refcount
= IDirect3DDevice8_Release(device
);
6722 ok(!refcount
, "Device has %u references left.\n", refcount
);
6723 IDirect3D8_Release(d3d8
);
6724 DestroyWindow(window
);
6727 static void test_lockbox_invalid(void)
6736 {{0, 0, 2, 2, 0, 1}, D3D_OK
}, /* Valid */
6737 {{0, 0, 4, 4, 0, 1}, D3D_OK
}, /* Valid */
6738 {{0, 0, 0, 4, 0, 1}, D3DERR_INVALIDCALL
}, /* 0 height */
6739 {{0, 0, 4, 0, 0, 1}, D3DERR_INVALIDCALL
}, /* 0 width */
6740 {{0, 0, 4, 4, 1, 1}, D3DERR_INVALIDCALL
}, /* 0 depth */
6741 {{4, 0, 0, 4, 0, 1}, D3DERR_INVALIDCALL
}, /* left > right */
6742 {{0, 4, 4, 0, 0, 1}, D3DERR_INVALIDCALL
}, /* top > bottom */
6743 {{0, 0, 4, 4, 1, 0}, D3DERR_INVALIDCALL
}, /* back > front */
6744 {{0, 0, 8, 4, 0, 1}, D3DERR_INVALIDCALL
}, /* right > surface */
6745 {{0, 0, 4, 8, 0, 1}, D3DERR_INVALIDCALL
}, /* bottom > surface */
6746 {{0, 0, 4, 4, 0, 3}, D3DERR_INVALIDCALL
}, /* back > surface */
6747 {{8, 0, 16, 4, 0, 1}, D3DERR_INVALIDCALL
}, /* left > surface */
6748 {{0, 8, 4, 16, 0, 1}, D3DERR_INVALIDCALL
}, /* top > surface */
6749 {{0, 0, 4, 4, 2, 4}, D3DERR_INVALIDCALL
}, /* top > surface */
6751 static const D3DBOX test_boxt_2
= {2, 2, 4, 4, 0, 1};
6752 IDirect3DVolumeTexture8
*texture
= NULL
;
6753 D3DLOCKED_BOX locked_box
;
6754 IDirect3DDevice8
*device
;
6762 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6763 0, 0, 640, 480, 0, 0, 0, 0);
6764 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
6765 ok(!!d3d
, "Failed to create a D3D object.\n");
6766 if (!(device
= create_device(d3d
, window
, NULL
)))
6768 skip("Failed to create a D3D device, skipping tests.\n");
6769 IDirect3D8_Release(d3d
);
6770 DestroyWindow(window
);
6774 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 4, 4, 2, 1, 0,
6775 D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &texture
);
6776 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
6777 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, NULL
, 0);
6778 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
6779 base
= locked_box
.pBits
;
6780 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6781 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6783 for (i
= 0; i
< (sizeof(test_data
) / sizeof(*test_data
)); ++i
)
6785 unsigned int offset
, expected_offset
;
6786 const D3DBOX
*box
= &test_data
[i
].box
;
6788 locked_box
.pBits
= (BYTE
*)0xdeadbeef;
6789 locked_box
.RowPitch
= 0xdeadbeef;
6790 locked_box
.SlicePitch
= 0xdeadbeef;
6792 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, box
, 0);
6793 /* Unlike surfaces, volumes properly check the box even in Windows XP */
6794 ok(hr
== test_data
[i
].result
,
6795 "Got unexpected hr %#x with box [%u, %u, %u]->[%u, %u, %u], expected %#x.\n",
6796 hr
, box
->Left
, box
->Top
, box
->Front
, box
->Right
, box
->Bottom
, box
->Back
,
6797 test_data
[i
].result
);
6801 offset
= (BYTE
*)locked_box
.pBits
- base
;
6802 expected_offset
= box
->Front
* locked_box
.SlicePitch
+ box
->Top
* locked_box
.RowPitch
+ box
->Left
* 4;
6803 ok(offset
== expected_offset
,
6804 "Got unexpected offset %u (expected %u) for rect [%u, %u, %u]->[%u, %u, %u].\n",
6805 offset
, expected_offset
, box
->Left
, box
->Top
, box
->Front
, box
->Right
, box
->Bottom
, box
->Back
);
6807 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6808 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6811 /* locked_box = NULL throws an exception on Windows */
6812 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, NULL
, 0);
6813 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
6814 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, NULL
, 0);
6815 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
6816 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6817 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6818 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6819 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
6821 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &test_data
[0].box
, 0);
6822 ok(hr
== D3D_OK
, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
6823 hr
, test_data
[0].box
.Left
, test_data
[0].box
.Top
, test_data
[0].box
.Front
,
6824 test_data
[0].box
.Right
, test_data
[0].box
.Bottom
, test_data
[0].box
.Back
);
6825 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &test_data
[0].box
, 0);
6826 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
6827 hr
, test_data
[0].box
.Left
, test_data
[0].box
.Top
, test_data
[0].box
.Front
,
6828 test_data
[0].box
.Right
, test_data
[0].box
.Bottom
, test_data
[0].box
.Back
);
6829 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &test_boxt_2
, 0);
6830 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
6831 hr
, test_boxt_2
.Left
, test_boxt_2
.Top
, test_boxt_2
.Front
,
6832 test_boxt_2
.Right
, test_boxt_2
.Bottom
, test_boxt_2
.Back
);
6833 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6834 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6836 IDirect3DVolumeTexture8_Release(texture
);
6837 refcount
= IDirect3DDevice8_Release(device
);
6838 ok(!refcount
, "Device has %u references left.\n", refcount
);
6839 IDirect3D8_Release(d3d
);
6840 DestroyWindow(window
);
6843 static void test_pixel_format(void)
6845 HWND hwnd
, hwnd2
= NULL
;
6846 HDC hdc
, hdc2
= NULL
;
6848 int format
, test_format
;
6849 PIXELFORMATDESCRIPTOR pfd
;
6850 IDirect3D8
*d3d8
= NULL
;
6851 IDirect3DDevice8
*device
= NULL
;
6853 static const float point
[3] = {0.0, 0.0, 0.0};
6855 hwnd
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6856 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
6859 skip("Failed to create window\n");
6863 hwnd2
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6864 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
6869 skip("Failed to get DC\n");
6874 hdc2
= GetDC(hwnd2
);
6876 gl
= LoadLibraryA("opengl32.dll");
6877 ok(!!gl
, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
6879 format
= GetPixelFormat(hdc
);
6880 ok(format
== 0, "new window has pixel format %d\n", format
);
6882 ZeroMemory(&pfd
, sizeof(pfd
));
6883 pfd
.nSize
= sizeof(pfd
);
6885 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
6886 pfd
.iPixelType
= PFD_TYPE_RGBA
;
6887 pfd
.iLayerType
= PFD_MAIN_PLANE
;
6888 format
= ChoosePixelFormat(hdc
, &pfd
);
6891 skip("no pixel format available\n");
6895 if (!SetPixelFormat(hdc
, format
, &pfd
) || GetPixelFormat(hdc
) != format
)
6897 skip("failed to set pixel format\n");
6901 if (!hdc2
|| !SetPixelFormat(hdc2
, format
, &pfd
) || GetPixelFormat(hdc2
) != format
)
6903 skip("failed to set pixel format on second window\n");
6906 ReleaseDC(hwnd2
, hdc2
);
6911 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
6912 ok(!!d3d8
, "Failed to create a D3D object.\n");
6914 test_format
= GetPixelFormat(hdc
);
6915 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6917 if (!(device
= create_device(d3d8
, hwnd
, NULL
)))
6919 skip("Failed to create device\n");
6923 test_format
= GetPixelFormat(hdc
);
6924 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6926 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
);
6927 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
6929 test_format
= GetPixelFormat(hdc
);
6930 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6932 hr
= IDirect3DDevice8_BeginScene(device
);
6933 ok(SUCCEEDED(hr
), "BeginScene failed %#x\n", hr
);
6935 test_format
= GetPixelFormat(hdc
);
6936 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6938 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_POINTLIST
, 1, point
, 3 * sizeof(float));
6939 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6941 test_format
= GetPixelFormat(hdc
);
6942 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6944 hr
= IDirect3DDevice8_EndScene(device
);
6945 ok(SUCCEEDED(hr
), "EndScene failed %#x\n", hr
);
6947 test_format
= GetPixelFormat(hdc
);
6948 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6950 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
6951 ok(SUCCEEDED(hr
), "Present failed %#x\n", hr
);
6953 test_format
= GetPixelFormat(hdc
);
6954 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6958 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, hwnd2
, NULL
);
6959 ok(SUCCEEDED(hr
), "Present failed %#x\n", hr
);
6961 test_format
= GetPixelFormat(hdc
);
6962 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6964 test_format
= GetPixelFormat(hdc2
);
6965 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
6971 UINT refcount
= IDirect3DDevice8_Release(device
);
6972 ok(!refcount
, "Device has %u references left.\n", refcount
);
6974 if (d3d8
) IDirect3D8_Release(d3d8
);
6975 if (gl
) FreeLibrary(gl
);
6976 if (hdc
) ReleaseDC(hwnd
, hdc
);
6977 if (hdc2
) ReleaseDC(hwnd2
, hdc2
);
6978 if (hwnd
) DestroyWindow(hwnd
);
6979 if (hwnd2
) DestroyWindow(hwnd2
);
6982 static void test_begin_end_state_block(void)
6984 IDirect3DDevice8
*device
;
6991 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
6992 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
6993 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
6994 ok(!!d3d
, "Failed to create a D3D object.\n");
6995 if (!(device
= create_device(d3d
, window
, NULL
)))
6997 skip("Failed to create a D3D device, skipping tests.\n");
6998 IDirect3D8_Release(d3d
);
6999 DestroyWindow(window
);
7003 /* Should succeed. */
7004 hr
= IDirect3DDevice8_BeginStateBlock(device
);
7005 ok(SUCCEEDED(hr
), "Failed to begin stateblock, hr %#x.\n", hr
);
7007 /* Calling BeginStateBlock() while recording should return
7008 * D3DERR_INVALIDCALL. */
7009 hr
= IDirect3DDevice8_BeginStateBlock(device
);
7010 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
7012 /* Should succeed. */
7013 stateblock
= 0xdeadbeef;
7014 hr
= IDirect3DDevice8_EndStateBlock(device
, &stateblock
);
7015 ok(SUCCEEDED(hr
), "Failed to end stateblock, hr %#x.\n", hr
);
7016 ok(!!stateblock
&& stateblock
!= 0xdeadbeef, "Got unexpected stateblock %#x.\n", stateblock
);
7017 IDirect3DDevice8_DeleteStateBlock(device
, stateblock
);
7019 /* Calling EndStateBlock() while not recording should return
7020 * D3DERR_INVALIDCALL. stateblock should not be touched. */
7021 stateblock
= 0xdeadbeef;
7022 hr
= IDirect3DDevice8_EndStateBlock(device
, &stateblock
);
7023 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
7024 ok(stateblock
== 0xdeadbeef, "Got unexpected stateblock %#x.\n", stateblock
);
7026 refcount
= IDirect3DDevice8_Release(device
);
7027 ok(!refcount
, "Device has %u references left.\n", refcount
);
7028 IDirect3D8_Release(d3d
);
7029 DestroyWindow(window
);
7032 static void test_shader_constant_apply(void)
7034 static const float vs_const
[] = {1.0f
, 2.0f
, 3.0f
, 4.0f
};
7035 static const float ps_const
[] = {5.0f
, 6.0f
, 7.0f
, 8.0f
};
7036 static const float initial
[] = {0.0f
, 0.0f
, 0.0f
, 0.0f
};
7037 DWORD vs_version
, ps_version
;
7038 IDirect3DDevice8
*device
;
7047 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
7048 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
7049 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
7050 ok(!!d3d
, "Failed to create a D3D object.\n");
7051 if (!(device
= create_device(d3d
, window
, NULL
)))
7053 skip("Failed to create a D3D device, skipping tests.\n");
7054 IDirect3D8_Release(d3d
);
7055 DestroyWindow(window
);
7059 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
7060 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
7061 vs_version
= caps
.VertexShaderVersion
& 0xffff;
7062 ps_version
= caps
.PixelShaderVersion
& 0xffff;
7066 hr
= IDirect3DDevice8_SetVertexShaderConstant(device
, 0, initial
, 1);
7067 ok(SUCCEEDED(hr
), "Failed to set vertex shader constant, hr %#x.\n", hr
);
7068 hr
= IDirect3DDevice8_SetVertexShaderConstant(device
, 1, initial
, 1);
7069 ok(SUCCEEDED(hr
), "Failed to set vertex shader constant, hr %#x.\n", hr
);
7071 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 0, ret
, 1);
7072 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7073 ok(!memcmp(ret
, initial
, sizeof(initial
)),
7074 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7075 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
7076 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 1, ret
, 1);
7077 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7078 ok(!memcmp(ret
, initial
, sizeof(initial
)),
7079 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7080 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
7082 hr
= IDirect3DDevice8_SetVertexShaderConstant(device
, 0, vs_const
, 1);
7083 ok(SUCCEEDED(hr
), "Failed to set vertex shader constant, hr %#x.\n", hr
);
7087 hr
= IDirect3DDevice8_SetPixelShaderConstant(device
, 0, initial
, 1);
7088 ok(SUCCEEDED(hr
), "Failed to set pixel shader constant, hr %#x.\n", hr
);
7089 hr
= IDirect3DDevice8_SetPixelShaderConstant(device
, 1, initial
, 1);
7090 ok(SUCCEEDED(hr
), "Failed to set pixel shader constant, hr %#x.\n", hr
);
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
, initial
, sizeof(initial
)),
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], initial
[0], initial
[1], initial
[2], initial
[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]);
7103 hr
= IDirect3DDevice8_SetPixelShaderConstant(device
, 0, ps_const
, 1);
7104 ok(SUCCEEDED(hr
), "Failed to set pixel shader constant, hr %#x.\n", hr
);
7107 hr
= IDirect3DDevice8_BeginStateBlock(device
);
7108 ok(SUCCEEDED(hr
), "Failed to begin stateblock, hr %#x.\n", hr
);
7112 hr
= IDirect3DDevice8_SetVertexShaderConstant(device
, 1, vs_const
, 1);
7113 ok(SUCCEEDED(hr
), "Failed to set vertex shader constant, hr %#x.\n", hr
);
7117 hr
= IDirect3DDevice8_SetPixelShaderConstant(device
, 1, ps_const
, 1);
7118 ok(SUCCEEDED(hr
), "Failed to set pixel shader constant, hr %#x.\n", hr
);
7121 hr
= IDirect3DDevice8_EndStateBlock(device
, &stateblock
);
7122 ok(SUCCEEDED(hr
), "Failed to end stateblock, hr %#x.\n", hr
);
7126 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 0, ret
, 1);
7127 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7128 ok(!memcmp(ret
, vs_const
, sizeof(vs_const
)),
7129 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7130 ret
[0], ret
[1], ret
[2], ret
[3], vs_const
[0], vs_const
[1], vs_const
[2], vs_const
[3]);
7131 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 1, ret
, 1);
7132 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7133 ok(!memcmp(ret
, initial
, sizeof(initial
)),
7134 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7135 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
7139 hr
= IDirect3DDevice8_GetPixelShaderConstant(device
, 0, ret
, 1);
7140 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
7141 ok(!memcmp(ret
, ps_const
, sizeof(ps_const
)),
7142 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7143 ret
[0], ret
[1], ret
[2], ret
[3], ps_const
[0], ps_const
[1], ps_const
[2], ps_const
[3]);
7144 hr
= IDirect3DDevice8_GetPixelShaderConstant(device
, 1, ret
, 1);
7145 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
7146 ok(!memcmp(ret
, initial
, sizeof(initial
)),
7147 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7148 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
7151 /* Apply doesn't overwrite constants that aren't explicitly set on the
7152 * source stateblock. */
7153 hr
= IDirect3DDevice8_ApplyStateBlock(device
, stateblock
);
7154 ok(SUCCEEDED(hr
), "Failed to apply stateblock, hr %#x.\n", hr
);
7158 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 0, ret
, 1);
7159 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7160 ok(!memcmp(ret
, vs_const
, sizeof(vs_const
)),
7161 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7162 ret
[0], ret
[1], ret
[2], ret
[3], vs_const
[0], vs_const
[1], vs_const
[2], vs_const
[3]);
7163 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 1, ret
, 1);
7164 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7165 ok(!memcmp(ret
, vs_const
, sizeof(vs_const
)),
7166 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7167 ret
[0], ret
[1], ret
[2], ret
[3], vs_const
[0], vs_const
[1], vs_const
[2], vs_const
[3]);
7171 hr
= IDirect3DDevice8_GetPixelShaderConstant(device
, 0, ret
, 1);
7172 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
7173 ok(!memcmp(ret
, ps_const
, sizeof(ps_const
)),
7174 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7175 ret
[0], ret
[1], ret
[2], ret
[3], ps_const
[0], ps_const
[1], ps_const
[2], ps_const
[3]);
7176 hr
= IDirect3DDevice8_GetPixelShaderConstant(device
, 1, ret
, 1);
7177 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
7178 ok(!memcmp(ret
, ps_const
, sizeof(ps_const
)),
7179 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7180 ret
[0], ret
[1], ret
[2], ret
[3], ps_const
[0], ps_const
[1], ps_const
[2], ps_const
[3]);
7183 IDirect3DDevice8_DeleteStateBlock(device
, stateblock
);
7184 refcount
= IDirect3DDevice8_Release(device
);
7185 ok(!refcount
, "Device has %u references left.\n", refcount
);
7186 IDirect3D8_Release(d3d
);
7187 DestroyWindow(window
);
7190 static void test_resource_type(void)
7192 IDirect3DDevice8
*device
;
7193 IDirect3DSurface8
*surface
;
7194 IDirect3DTexture8
*texture
;
7195 IDirect3DCubeTexture8
*cube_texture
;
7196 IDirect3DVolume8
*volume
;
7197 IDirect3DVolumeTexture8
*volume_texture
;
7198 D3DSURFACE_DESC surface_desc
;
7199 D3DVOLUME_DESC volume_desc
;
7200 D3DRESOURCETYPE type
;
7207 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
7208 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
7209 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
7210 ok(!!d3d
, "Failed to create a D3D object.\n");
7211 if (!(device
= create_device(d3d
, window
, NULL
)))
7213 skip("Failed to create a D3D device, skipping tests.\n");
7214 IDirect3D8_Release(d3d
);
7215 DestroyWindow(window
);
7219 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
7220 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
7222 hr
= IDirect3DDevice8_CreateImageSurface(device
, 4, 4, D3DFMT_X8R8G8B8
, &surface
);
7223 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7224 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
7225 ok(SUCCEEDED(hr
), "Failed to get surface description, hr %#x.\n", hr
);
7226 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7228 IDirect3DSurface8_Release(surface
);
7230 hr
= IDirect3DDevice8_CreateTexture(device
, 2, 8, 4, 0, D3DFMT_X8R8G8B8
,
7231 D3DPOOL_SYSTEMMEM
, &texture
);
7232 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
7233 type
= IDirect3DTexture8_GetType(texture
);
7234 ok(type
== D3DRTYPE_TEXTURE
, "Expected type D3DRTYPE_TEXTURE, got %u.\n", type
);
7236 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &surface
);
7237 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7238 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
7239 ok(SUCCEEDED(hr
), "Failed to get surface description, hr %#x.\n", hr
);
7240 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7242 ok(surface_desc
.Width
== 2, "Expected width 2, got %u.\n", surface_desc
.Width
);
7243 ok(surface_desc
.Height
== 8, "Expected height 8, got %u.\n", surface_desc
.Height
);
7244 hr
= IDirect3DTexture8_GetLevelDesc(texture
, 0, &surface_desc
);
7245 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
7246 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7248 ok(surface_desc
.Width
== 2, "Expected width 2, got %u.\n", surface_desc
.Width
);
7249 ok(surface_desc
.Height
== 8, "Expected height 8, got %u.\n", surface_desc
.Height
);
7250 IDirect3DSurface8_Release(surface
);
7252 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 2, &surface
);
7253 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7254 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
7255 ok(SUCCEEDED(hr
), "Failed to get surface description, hr %#x.\n", hr
);
7256 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7258 ok(surface_desc
.Width
== 1, "Expected width 1, got %u.\n", surface_desc
.Width
);
7259 ok(surface_desc
.Height
== 2, "Expected height 2, got %u.\n", surface_desc
.Height
);
7260 hr
= IDirect3DTexture8_GetLevelDesc(texture
, 2, &surface_desc
);
7261 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
7262 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7264 ok(surface_desc
.Width
== 1, "Expected width 1, got %u.\n", surface_desc
.Width
);
7265 ok(surface_desc
.Height
== 2, "Expected height 2, got %u.\n", surface_desc
.Height
);
7266 IDirect3DSurface8_Release(surface
);
7267 IDirect3DTexture8_Release(texture
);
7269 if (caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
)
7271 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 1, 1, 0, D3DFMT_X8R8G8B8
,
7272 D3DPOOL_SYSTEMMEM
, &cube_texture
);
7273 ok(SUCCEEDED(hr
), "Failed to create cube texture, hr %#x.\n", hr
);
7274 type
= IDirect3DCubeTexture8_GetType(cube_texture
);
7275 ok(type
== D3DRTYPE_CUBETEXTURE
, "Expected type D3DRTYPE_CUBETEXTURE, got %u.\n", type
);
7277 hr
= IDirect3DCubeTexture8_GetCubeMapSurface(cube_texture
,
7278 D3DCUBEMAP_FACE_NEGATIVE_X
, 0, &surface
);
7279 ok(SUCCEEDED(hr
), "Failed to get cube map surface, hr %#x.\n", hr
);
7280 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
7281 ok(SUCCEEDED(hr
), "Failed to get surface description, hr %#x.\n", hr
);
7282 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7284 hr
= IDirect3DCubeTexture8_GetLevelDesc(cube_texture
, 0, &surface_desc
);
7285 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
7286 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7288 IDirect3DSurface8_Release(surface
);
7289 IDirect3DCubeTexture8_Release(cube_texture
);
7292 skip("Cube maps not supported.\n");
7294 if (caps
.TextureCaps
& D3DPTEXTURECAPS_MIPVOLUMEMAP
)
7296 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 2, 4, 8, 4, 0, D3DFMT_X8R8G8B8
,
7297 D3DPOOL_SYSTEMMEM
, &volume_texture
);
7298 ok(SUCCEEDED(hr
), "CreateVolumeTexture failed, hr %#x.\n", hr
);
7299 type
= IDirect3DVolumeTexture8_GetType(volume_texture
);
7300 ok(type
== D3DRTYPE_VOLUMETEXTURE
, "Expected type D3DRTYPE_VOLUMETEXTURE, got %u.\n", type
);
7302 hr
= IDirect3DVolumeTexture8_GetVolumeLevel(volume_texture
, 0, &volume
);
7303 ok(SUCCEEDED(hr
), "Failed to get volume level, hr %#x.\n", hr
);
7304 /* IDirect3DVolume8 is not an IDirect3DResource8 and has no GetType method. */
7305 hr
= IDirect3DVolume8_GetDesc(volume
, &volume_desc
);
7306 ok(SUCCEEDED(hr
), "Failed to get volume description, hr %#x.\n", hr
);
7307 ok(volume_desc
.Type
== D3DRTYPE_VOLUME
, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7309 ok(volume_desc
.Width
== 2, "Expected width 2, got %u.\n", volume_desc
.Width
);
7310 ok(volume_desc
.Height
== 4, "Expected height 4, got %u.\n", volume_desc
.Height
);
7311 ok(volume_desc
.Depth
== 8, "Expected depth 8, got %u.\n", volume_desc
.Depth
);
7312 hr
= IDirect3DVolumeTexture8_GetLevelDesc(volume_texture
, 0, &volume_desc
);
7313 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
7314 ok(volume_desc
.Type
== D3DRTYPE_VOLUME
, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7316 ok(volume_desc
.Width
== 2, "Expected width 2, got %u.\n", volume_desc
.Width
);
7317 ok(volume_desc
.Height
== 4, "Expected height 4, got %u.\n", volume_desc
.Height
);
7318 ok(volume_desc
.Depth
== 8, "Expected depth 8, got %u.\n", volume_desc
.Depth
);
7319 IDirect3DVolume8_Release(volume
);
7321 hr
= IDirect3DVolumeTexture8_GetVolumeLevel(volume_texture
, 2, &volume
);
7322 ok(SUCCEEDED(hr
), "Failed to get volume level, hr %#x.\n", hr
);
7323 hr
= IDirect3DVolume8_GetDesc(volume
, &volume_desc
);
7324 ok(SUCCEEDED(hr
), "Failed to get volume description, hr %#x.\n", hr
);
7325 ok(volume_desc
.Type
== D3DRTYPE_VOLUME
, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7327 ok(volume_desc
.Width
== 1, "Expected width 1, got %u.\n", volume_desc
.Width
);
7328 ok(volume_desc
.Height
== 1, "Expected height 1, got %u.\n", volume_desc
.Height
);
7329 ok(volume_desc
.Depth
== 2, "Expected depth 2, got %u.\n", volume_desc
.Depth
);
7330 hr
= IDirect3DVolumeTexture8_GetLevelDesc(volume_texture
, 2, &volume_desc
);
7331 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
7332 ok(volume_desc
.Type
== D3DRTYPE_VOLUME
, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7334 ok(volume_desc
.Width
== 1, "Expected width 1, got %u.\n", volume_desc
.Width
);
7335 ok(volume_desc
.Height
== 1, "Expected height 1, got %u.\n", volume_desc
.Height
);
7336 ok(volume_desc
.Depth
== 2, "Expected depth 2, got %u.\n", volume_desc
.Depth
);
7337 IDirect3DVolume8_Release(volume
);
7338 IDirect3DVolumeTexture8_Release(volume_texture
);
7341 skip("Mipmapped volume maps not supported.\n");
7343 refcount
= IDirect3DDevice8_Release(device
);
7344 ok(!refcount
, "Device has %u references left.\n", refcount
);
7345 IDirect3D8_Release(d3d
);
7346 DestroyWindow(window
);
7349 static void test_mipmap_lock(void)
7351 IDirect3DDevice8
*device
;
7352 IDirect3DSurface8
*surface
, *surface2
, *surface_dst
, *surface_dst2
;
7353 IDirect3DTexture8
*texture
, *texture_dst
;
7358 D3DLOCKED_RECT locked_rect
;
7360 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
7361 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
7362 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
7363 ok(!!d3d
, "Failed to create a D3D object.\n");
7364 if (!(device
= create_device(d3d
, window
, NULL
)))
7366 skip("Failed to create a D3D device, skipping tests.\n");
7367 IDirect3D8_Release(d3d
);
7368 DestroyWindow(window
);
7372 hr
= IDirect3DDevice8_CreateTexture(device
, 4, 4, 2, 0, D3DFMT_X8R8G8B8
,
7373 D3DPOOL_DEFAULT
, &texture_dst
);
7374 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
7375 hr
= IDirect3DTexture8_GetSurfaceLevel(texture_dst
, 0, &surface_dst
);
7376 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7377 hr
= IDirect3DTexture8_GetSurfaceLevel(texture_dst
, 1, &surface_dst2
);
7378 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7380 hr
= IDirect3DDevice8_CreateTexture(device
, 4, 4, 2, 0, D3DFMT_X8R8G8B8
,
7381 D3DPOOL_SYSTEMMEM
, &texture
);
7382 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
7383 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &surface
);
7384 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7385 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 1, &surface2
);
7386 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7388 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
7389 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
7390 hr
= IDirect3DSurface8_LockRect(surface2
, &locked_rect
, NULL
, 0);
7391 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
7392 hr
= IDirect3DSurface8_UnlockRect(surface
);
7393 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
7395 hr
= IDirect3DDevice8_CopyRects(device
, surface
, NULL
, 0, surface_dst
, NULL
);
7396 ok(SUCCEEDED(hr
), "Failed to update surface, hr %#x.\n", hr
);
7397 hr
= IDirect3DDevice8_CopyRects(device
, surface2
, NULL
, 0, surface_dst2
, NULL
);
7398 todo_wine
ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
7400 /* Apparently there's no validation on the container. */
7401 hr
= IDirect3DDevice8_UpdateTexture(device
, (IDirect3DBaseTexture8
*)texture
,
7402 (IDirect3DBaseTexture8
*)texture_dst
);
7403 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x.\n", hr
);
7405 hr
= IDirect3DSurface8_UnlockRect(surface2
);
7406 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
7408 IDirect3DSurface8_Release(surface_dst2
);
7409 IDirect3DSurface8_Release(surface_dst
);
7410 IDirect3DSurface8_Release(surface2
);
7411 IDirect3DSurface8_Release(surface
);
7412 IDirect3DTexture8_Release(texture_dst
);
7413 IDirect3DTexture8_Release(texture
);
7415 refcount
= IDirect3DDevice8_Release(device
);
7416 ok(!refcount
, "Device has %u references left.\n", refcount
);
7417 IDirect3D8_Release(d3d
);
7418 DestroyWindow(window
);
7421 static void test_writeonly_resource(void)
7424 IDirect3DDevice8
*device
;
7425 IDirect3DVertexBuffer8
*buffer
;
7436 {{-1.0f
, -1.0f
, 0.0f
}},
7437 {{-1.0f
, 1.0f
, 0.0f
}},
7438 {{ 1.0f
, -1.0f
, 0.0f
}},
7439 {{ 1.0f
, 1.0f
, 0.0f
}}
7442 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
7443 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
7444 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
7445 ok(!!d3d
, "Failed to create a D3D object.\n");
7446 if (!(device
= create_device(d3d
, window
, NULL
)))
7448 skip("Failed to create a D3D device, skipping tests.\n");
7449 IDirect3D8_Release(d3d
);
7450 DestroyWindow(window
);
7454 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, sizeof(quad
),
7455 D3DUSAGE_DYNAMIC
| D3DUSAGE_WRITEONLY
, 0, D3DPOOL_DEFAULT
, &buffer
);
7456 ok(SUCCEEDED(hr
), "Failed to create buffer, hr %#x.\n", hr
);
7458 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, 0, &ptr
, D3DLOCK_DISCARD
);
7459 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
7460 memcpy(ptr
, quad
, sizeof(quad
));
7461 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
7462 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
7463 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, buffer
, sizeof(*quad
));
7464 ok(SUCCEEDED(hr
), "Failed to set stream source, hr %#x.\n", hr
);
7465 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
);
7466 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
7468 hr
= IDirect3DDevice8_BeginScene(device
);
7469 ok(SUCCEEDED(hr
), "Failed to begin scene %#x\n", hr
);
7470 hr
= IDirect3DDevice8_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 0, 2);
7471 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7472 hr
= IDirect3DDevice8_EndScene(device
);
7473 ok(SUCCEEDED(hr
), "Failed to end scene %#x\n", hr
);
7475 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, 0, &ptr
, 0);
7476 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
7477 ok (!memcmp(ptr
, quad
, sizeof(quad
)), "Got unexpected vertex buffer data.\n");
7478 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
7479 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
7481 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, 0, &ptr
, D3DLOCK_READONLY
);
7482 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
7483 ok (!memcmp(ptr
, quad
, sizeof(quad
)), "Got unexpected vertex buffer data.\n");
7484 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
7485 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
7487 refcount
= IDirect3DVertexBuffer8_Release(buffer
);
7488 ok(!refcount
, "Vertex buffer has %u references left.\n", refcount
);
7489 refcount
= IDirect3DDevice8_Release(device
);
7490 ok(!refcount
, "Device has %u references left.\n", refcount
);
7491 IDirect3D8_Release(d3d
);
7492 DestroyWindow(window
);
7495 static void test_lost_device(void)
7497 struct device_desc device_desc
;
7498 IDirect3DDevice8
*device
;
7505 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
7506 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
7507 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
7508 ok(!!d3d
, "Failed to create a D3D object.\n");
7509 device_desc
.device_window
= window
;
7510 device_desc
.width
= registry_mode
.dmPelsWidth
;
7511 device_desc
.height
= registry_mode
.dmPelsHeight
;
7512 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
7513 if (!(device
= create_device(d3d
, window
, &device_desc
)))
7515 skip("Failed to create a D3D device, skipping tests.\n");
7519 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
7520 if (hr
== D3DERR_DEVICELOST
)
7522 win_skip("Broken TestCooperativeLevel(), skipping test.\n");
7523 IDirect3DDevice8_Release(device
);
7526 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7527 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
7528 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7530 ret
= SetForegroundWindow(GetDesktopWindow());
7531 ok(ret
, "Failed to set foreground window.\n");
7532 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
7533 ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
7534 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
7535 ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
7537 ret
= ShowWindow(window
, SW_RESTORE
);
7538 ok(ret
, "Failed to restore window.\n");
7539 ret
= SetForegroundWindow(window
);
7540 ok(ret
, "Failed to set foreground window.\n");
7541 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
7542 ok(hr
== D3DERR_DEVICENOTRESET
, "Got unexpected hr %#x.\n", hr
);
7543 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
7544 ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
7546 hr
= reset_device(device
, &device_desc
);
7547 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7548 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
7549 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7550 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
7551 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7553 device_desc
.flags
= 0;
7554 hr
= reset_device(device
, &device_desc
);
7555 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7556 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
7557 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7558 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
7559 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7561 ret
= SetForegroundWindow(GetDesktopWindow());
7562 ok(ret
, "Failed to set foreground window.\n");
7563 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
7564 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7565 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
7566 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7568 ret
= ShowWindow(window
, SW_RESTORE
);
7569 ok(ret
, "Failed to restore window.\n");
7570 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
7571 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7572 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
7573 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7575 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
7576 hr
= reset_device(device
, &device_desc
);
7577 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7578 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
7579 todo_wine
ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
7580 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
7581 todo_wine
ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
7583 ret
= SetForegroundWindow(GetDesktopWindow());
7584 ok(ret
, "Failed to set foreground window.\n");
7585 hr
= reset_device(device
, &device_desc
);
7586 ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
7587 ret
= ShowWindow(window
, SW_RESTORE
);
7588 ok(ret
, "Failed to restore window.\n");
7589 ret
= SetForegroundWindow(window
);
7590 ok(ret
, "Failed to set foreground window.\n");
7591 hr
= reset_device(device
, &device_desc
);
7592 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7594 refcount
= IDirect3DDevice8_Release(device
);
7595 ok(!refcount
, "Device has %u references left.\n", refcount
);
7597 IDirect3D8_Release(d3d
);
7598 DestroyWindow(window
);
7601 static void test_resource_priority(void)
7603 IDirect3DDevice8
*device
;
7604 IDirect3DTexture8
*texture
;
7605 IDirect3DVertexBuffer8
*buffer
;
7614 BOOL can_set_priority
;
7618 {D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", FALSE
},
7619 {D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", FALSE
},
7620 {D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
},
7621 {D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", FALSE
}
7626 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
7627 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
7628 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
7629 ok(!!d3d
, "Failed to create a D3D object.\n");
7630 if (!(device
= create_device(d3d
, window
, NULL
)))
7632 skip("Failed to create a D3D device, skipping tests.\n");
7633 IDirect3D8_Release(d3d
);
7634 DestroyWindow(window
);
7638 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); i
++)
7640 hr
= IDirect3DDevice8_CreateTexture(device
, 16, 16, 0, 0, D3DFMT_X8R8G8B8
,
7641 test_data
[i
].pool
, &texture
);
7642 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x, pool %s.\n", hr
, test_data
[i
].name
);
7644 priority
= IDirect3DTexture8_GetPriority(texture
);
7645 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
7646 priority
= IDirect3DTexture8_SetPriority(texture
, 1);
7647 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
7648 priority
= IDirect3DTexture8_GetPriority(texture
);
7649 if (test_data
[i
].can_set_priority
)
7651 ok(priority
== 1, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
7652 priority
= IDirect3DTexture8_SetPriority(texture
, 0);
7653 ok(priority
== 1, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
7656 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
7658 IDirect3DTexture8_Release(texture
);
7660 if (test_data
[i
].pool
!= D3DPOOL_SCRATCH
)
7662 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, 256, 0, 0,
7663 test_data
[i
].pool
, &buffer
);
7664 ok(SUCCEEDED(hr
), "Failed to create buffer, hr %#x, pool %s.\n", hr
, test_data
[i
].name
);
7666 priority
= IDirect3DVertexBuffer8_GetPriority(buffer
);
7667 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
7668 priority
= IDirect3DVertexBuffer8_SetPriority(buffer
, 1);
7669 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
7670 priority
= IDirect3DVertexBuffer8_GetPriority(buffer
);
7671 if (test_data
[i
].can_set_priority
)
7673 ok(priority
== 1, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
7674 priority
= IDirect3DVertexBuffer8_SetPriority(buffer
, 0);
7675 ok(priority
== 1, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
7678 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
7680 IDirect3DVertexBuffer8_Release(buffer
);
7684 refcount
= IDirect3DDevice8_Release(device
);
7685 ok(!refcount
, "Device has %u references left.\n", refcount
);
7686 IDirect3D8_Release(d3d
);
7687 DestroyWindow(window
);
7690 static void test_swapchain_parameters(void)
7692 IDirect3DDevice8
*device
;
7694 IDirect3DSurface8
*backbuffer
;
7698 D3DPRESENT_PARAMETERS present_parameters
, present_parameters_windowed
= {0};
7702 UINT backbuffer_count
;
7703 D3DSWAPEFFECT swap_effect
;
7708 /* Swap effect 0 is not allowed. */
7709 {TRUE
, 1, 0, D3DERR_INVALIDCALL
},
7710 {FALSE
, 1, 0, D3DERR_INVALIDCALL
},
7712 /* All (non-ex) swap effects are allowed in
7713 * windowed and fullscreen mode. */
7714 {TRUE
, 1, D3DSWAPEFFECT_DISCARD
, D3D_OK
},
7715 {TRUE
, 1, D3DSWAPEFFECT_FLIP
, D3D_OK
},
7716 {FALSE
, 1, D3DSWAPEFFECT_DISCARD
, D3D_OK
},
7717 {FALSE
, 1, D3DSWAPEFFECT_FLIP
, D3D_OK
},
7718 {FALSE
, 1, D3DSWAPEFFECT_COPY
, D3D_OK
},
7720 /* Only one backbuffer in copy mode. Reset allows it for
7722 {TRUE
, 0, D3DSWAPEFFECT_COPY
, D3D_OK
},
7723 {TRUE
, 1, D3DSWAPEFFECT_COPY
, D3D_OK
},
7724 {TRUE
, 2, D3DSWAPEFFECT_COPY
, D3DERR_INVALIDCALL
},
7725 {FALSE
, 2, D3DSWAPEFFECT_COPY
, D3DERR_INVALIDCALL
},
7726 {TRUE
, 0, D3DSWAPEFFECT_COPY_VSYNC
, D3D_OK
},
7727 {TRUE
, 1, D3DSWAPEFFECT_COPY_VSYNC
, D3D_OK
},
7728 {TRUE
, 2, D3DSWAPEFFECT_COPY_VSYNC
, D3DERR_INVALIDCALL
},
7729 {FALSE
, 2, D3DSWAPEFFECT_COPY_VSYNC
, D3DERR_INVALIDCALL
},
7731 /* Ok with the others, in fullscreen and windowed mode. */
7732 {TRUE
, 2, D3DSWAPEFFECT_DISCARD
, D3D_OK
},
7733 {TRUE
, 2, D3DSWAPEFFECT_FLIP
, D3D_OK
},
7734 {FALSE
, 2, D3DSWAPEFFECT_DISCARD
, D3D_OK
},
7735 {FALSE
, 2, D3DSWAPEFFECT_FLIP
, D3D_OK
},
7737 /* Invalid swapeffects. */
7738 {TRUE
, 1, D3DSWAPEFFECT_COPY_VSYNC
+ 1, D3DERR_INVALIDCALL
},
7739 {FALSE
, 1, D3DSWAPEFFECT_COPY_VSYNC
+ 1, D3DERR_INVALIDCALL
},
7741 /* 3 is the highest allowed backbuffer count. */
7742 {TRUE
, 3, D3DSWAPEFFECT_DISCARD
, D3D_OK
},
7743 {TRUE
, 4, D3DSWAPEFFECT_DISCARD
, D3DERR_INVALIDCALL
},
7744 {TRUE
, 4, D3DSWAPEFFECT_FLIP
, D3DERR_INVALIDCALL
},
7745 {FALSE
, 4, D3DSWAPEFFECT_DISCARD
, D3DERR_INVALIDCALL
},
7746 {FALSE
, 4, D3DSWAPEFFECT_FLIP
, D3DERR_INVALIDCALL
},
7749 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
7750 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
7751 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
7752 ok(!!d3d
, "Failed to create a D3D object.\n");
7753 if (!(device
= create_device(d3d
, window
, NULL
)))
7755 skip("Failed to create a D3D device, skipping tests.\n");
7756 IDirect3D8_Release(d3d
);
7757 DestroyWindow(window
);
7760 IDirect3DDevice8_Release(device
);
7762 present_parameters_windowed
.BackBufferWidth
= registry_mode
.dmPelsWidth
;
7763 present_parameters_windowed
.BackBufferHeight
= registry_mode
.dmPelsHeight
;
7764 present_parameters_windowed
.hDeviceWindow
= window
;
7765 present_parameters_windowed
.BackBufferFormat
= D3DFMT_X8R8G8B8
;
7766 present_parameters_windowed
.SwapEffect
= D3DSWAPEFFECT_COPY
;
7767 present_parameters_windowed
.Windowed
= TRUE
;
7768 present_parameters_windowed
.BackBufferCount
= 1;
7770 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
7772 UINT bb_count
= tests
[i
].backbuffer_count
? tests
[i
].backbuffer_count
: 1;
7774 memset(&present_parameters
, 0, sizeof(present_parameters
));
7775 present_parameters
.BackBufferWidth
= registry_mode
.dmPelsWidth
;
7776 present_parameters
.BackBufferHeight
= registry_mode
.dmPelsHeight
;
7777 present_parameters
.hDeviceWindow
= window
;
7778 present_parameters
.BackBufferFormat
= D3DFMT_X8R8G8B8
;
7780 present_parameters
.SwapEffect
= tests
[i
].swap_effect
;
7781 present_parameters
.Windowed
= tests
[i
].windowed
;
7782 present_parameters
.BackBufferCount
= tests
[i
].backbuffer_count
;
7784 hr
= IDirect3D8_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, window
,
7785 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
7786 ok(hr
== tests
[i
].hr
, "Expected hr %x, got %x, test %u.\n", tests
[i
].hr
, hr
, i
);
7789 for (j
= 0; j
< bb_count
; ++j
)
7791 hr
= IDirect3DDevice8_GetBackBuffer(device
, j
, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
7792 ok(SUCCEEDED(hr
), "Failed to get backbuffer %u, hr %#x, test %u.\n", j
, hr
, i
);
7793 IDirect3DSurface8_Release(backbuffer
);
7795 hr
= IDirect3DDevice8_GetBackBuffer(device
, j
, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
7796 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %x, test %u.\n", hr
, i
);
7798 IDirect3DDevice8_Release(device
);
7801 hr
= IDirect3D8_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, window
,
7802 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters_windowed
, &device
);
7803 ok(SUCCEEDED(hr
), "Failed to create device, hr %#x, test %u.\n", hr
, i
);
7805 memset(&present_parameters
, 0, sizeof(present_parameters
));
7806 present_parameters
.BackBufferWidth
= registry_mode
.dmPelsWidth
;
7807 present_parameters
.BackBufferHeight
= registry_mode
.dmPelsHeight
;
7808 present_parameters
.hDeviceWindow
= window
;
7809 present_parameters
.BackBufferFormat
= D3DFMT_X8R8G8B8
;
7811 present_parameters
.SwapEffect
= tests
[i
].swap_effect
;
7812 present_parameters
.Windowed
= tests
[i
].windowed
;
7813 present_parameters
.BackBufferCount
= tests
[i
].backbuffer_count
;
7815 hr
= IDirect3DDevice8_Reset(device
, &present_parameters
);
7816 ok(hr
== tests
[i
].hr
, "Expected hr %x, got %x, test %u.\n", tests
[i
].hr
, hr
, i
);
7820 hr
= IDirect3DDevice8_Reset(device
, &present_parameters_windowed
);
7821 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x, test %u.\n", hr
, i
);
7825 for (j
= 0; j
< bb_count
; ++j
)
7827 hr
= IDirect3DDevice8_GetBackBuffer(device
, j
, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
7829 ok(SUCCEEDED(hr
), "Failed to get backbuffer %u, hr %#x, test %u.\n", j
, hr
, i
);
7831 IDirect3DSurface8_Release(backbuffer
);
7833 hr
= IDirect3DDevice8_GetBackBuffer(device
, j
, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
7834 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %x, test %u.\n", hr
, i
);
7836 IDirect3DDevice8_Release(device
);
7839 IDirect3D8_Release(d3d
);
7840 DestroyWindow(window
);
7843 static void test_miptree_layout(void)
7845 unsigned int pool_idx
, format_idx
, base_dimension
, level_count
, offset
, i
, j
;
7846 IDirect3DCubeTexture8
*texture_cube
;
7847 IDirect3DTexture8
*texture_2d
;
7848 IDirect3DDevice8
*device
;
7849 D3DLOCKED_RECT map_desc
;
7864 {D3DFMT_A8R8G8B8
, "D3DFMT_A8R8G8B8"},
7865 {D3DFMT_A8
, "D3DFMT_A8"},
7866 {D3DFMT_L8
, "D3DFMT_L8"},
7875 {D3DPOOL_MANAGED
, "D3DPOOL_MANAGED"},
7876 {D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM"},
7877 {D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH"},
7880 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
7881 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
7882 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
7883 ok(!!d3d
, "Failed to create a D3D object.\n");
7884 if (!(device
= create_device(d3d
, window
, NULL
)))
7886 skip("Failed to create a D3D device, skipping tests.\n");
7890 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
7891 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7893 base_dimension
= 257;
7894 if (caps
.TextureCaps
& (D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_CUBEMAP_POW2
))
7896 skip("Using power of two base dimension.\n");
7897 base_dimension
= 256;
7900 for (format_idx
= 0; format_idx
< sizeof(formats
) / sizeof(*formats
); ++format_idx
)
7902 if (FAILED(hr
= IDirect3D8_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
7903 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_TEXTURE
, formats
[format_idx
].format
)))
7905 skip("%s textures not supported, skipping tests.\n", formats
[format_idx
].name
);
7909 for (pool_idx
= 0; pool_idx
< sizeof(pools
) / sizeof(*pools
); ++pool_idx
)
7911 hr
= IDirect3DDevice8_CreateTexture(device
, base_dimension
, base_dimension
, 0, 0,
7912 formats
[format_idx
].format
, pools
[pool_idx
].pool
, &texture_2d
);
7913 ok(SUCCEEDED(hr
), "Failed to create a %s %s texture, hr %#x.\n",
7914 pools
[pool_idx
].name
, formats
[format_idx
].name
, hr
);
7916 level_count
= IDirect3DTexture8_GetLevelCount(texture_2d
);
7917 for (i
= 0, offset
= 0; i
< level_count
; ++i
)
7919 hr
= IDirect3DTexture8_LockRect(texture_2d
, i
, &map_desc
, NULL
, 0);
7920 ok(SUCCEEDED(hr
), "%s, %s: Failed to lock level %u, hr %#x.\n",
7921 pools
[pool_idx
].name
, formats
[format_idx
].name
, i
, hr
);
7924 base
= map_desc
.pBits
;
7926 ok(map_desc
.pBits
== base
+ offset
,
7927 "%s, %s, level %u: Got unexpected pBits %p, expected %p.\n",
7928 pools
[pool_idx
].name
, formats
[format_idx
].name
, i
, map_desc
.pBits
, base
+ offset
);
7929 offset
+= (base_dimension
>> i
) * map_desc
.Pitch
;
7931 hr
= IDirect3DTexture8_UnlockRect(texture_2d
, i
);
7932 ok(SUCCEEDED(hr
), "%s, %s Failed to unlock level %u, hr %#x.\n",
7933 pools
[pool_idx
].name
, formats
[format_idx
].name
, i
, hr
);
7936 IDirect3DTexture8_Release(texture_2d
);
7939 if (FAILED(hr
= IDirect3D8_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
7940 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_CUBETEXTURE
, formats
[format_idx
].format
)))
7942 skip("%s cube textures not supported, skipping tests.\n", formats
[format_idx
].name
);
7946 for (pool_idx
= 0; pool_idx
< sizeof(pools
) / sizeof(*pools
); ++pool_idx
)
7948 hr
= IDirect3DDevice8_CreateCubeTexture(device
, base_dimension
, 0, 0,
7949 formats
[format_idx
].format
, pools
[pool_idx
].pool
, &texture_cube
);
7950 ok(SUCCEEDED(hr
), "Failed to create a %s %s cube texture, hr %#x.\n",
7951 pools
[pool_idx
].name
, formats
[format_idx
].name
, hr
);
7953 level_count
= IDirect3DCubeTexture8_GetLevelCount(texture_cube
);
7954 for (i
= 0, offset
= 0; i
< 6; ++i
)
7956 for (j
= 0; j
< level_count
; ++j
)
7958 hr
= IDirect3DCubeTexture8_LockRect(texture_cube
, i
, j
, &map_desc
, NULL
, 0);
7959 ok(SUCCEEDED(hr
), "%s, %s: Failed to lock face %u, level %u, hr %#x.\n",
7960 pools
[pool_idx
].name
, formats
[format_idx
].name
, i
, j
, hr
);
7963 base
= map_desc
.pBits
;
7965 ok(map_desc
.pBits
== base
+ offset
,
7966 "%s, %s, face %u, level %u: Got unexpected pBits %p, expected %p.\n",
7967 pools
[pool_idx
].name
, formats
[format_idx
].name
, i
, j
, map_desc
.pBits
, base
+ offset
);
7968 offset
+= (base_dimension
>> j
) * map_desc
.Pitch
;
7970 hr
= IDirect3DCubeTexture8_UnlockRect(texture_cube
, i
, j
);
7971 ok(SUCCEEDED(hr
), "%s, %s: Failed to unlock face %u, level %u, hr %#x.\n",
7972 pools
[pool_idx
].name
, formats
[format_idx
].name
, i
, j
, hr
);
7974 offset
= (offset
+ 15) & ~15;
7977 IDirect3DCubeTexture8_Release(texture_cube
);
7981 refcount
= IDirect3DDevice8_Release(device
);
7982 ok(!refcount
, "Device has %u references left.\n", refcount
);
7984 IDirect3D8_Release(d3d
);
7985 DestroyWindow(window
);
7990 HMODULE d3d8_handle
= LoadLibraryA( "d3d8.dll" );
7993 DEVMODEW current_mode
;
7997 skip("Could not load d3d8.dll\n");
8001 memset(¤t_mode
, 0, sizeof(current_mode
));
8002 current_mode
.dmSize
= sizeof(current_mode
);
8003 ok(EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, ¤t_mode
), "Failed to get display mode.\n");
8004 registry_mode
.dmSize
= sizeof(registry_mode
);
8005 ok(EnumDisplaySettingsW(NULL
, ENUM_REGISTRY_SETTINGS
, ®istry_mode
), "Failed to get display mode.\n");
8006 if (current_mode
.dmPelsWidth
!= registry_mode
.dmPelsWidth
8007 || current_mode
.dmPelsHeight
!= registry_mode
.dmPelsHeight
)
8009 skip("Current mode does not match registry mode, skipping test.\n");
8013 wc
.lpfnWndProc
= DefWindowProcA
;
8014 wc
.lpszClassName
= "d3d8_test_wc";
8015 RegisterClassA(&wc
);
8017 ValidateVertexShader
= (void *)GetProcAddress(d3d8_handle
, "ValidateVertexShader");
8018 ValidatePixelShader
= (void *)GetProcAddress(d3d8_handle
, "ValidatePixelShader");
8020 if (!(d3d8
= Direct3DCreate8(D3D_SDK_VERSION
)))
8022 skip("could not create D3D8\n");
8025 IDirect3D8_Release(d3d8
);
8028 test_display_formats();
8029 test_display_modes();
8030 test_shader_versions();
8033 test_mipmap_levels();
8034 test_checkdevicemultisampletype();
8035 test_invalid_multisample();
8044 test_ApplyStateBlock();
8045 test_render_zero_triangles();
8046 test_depth_stencil_reset();
8048 test_wndproc_windowed();
8049 test_depth_stencil_size();
8050 test_window_style();
8051 test_unsupported_shaders();
8053 test_device_window_reset();
8054 test_reset_resources();
8056 test_set_rt_vp_scissor();
8059 test_volume_get_container();
8060 test_vb_lock_flags();
8061 test_texture_stage_states();
8062 test_cube_textures();
8063 test_get_set_texture();
8064 test_image_surface_pool();
8065 test_surface_get_container();
8066 test_lockrect_invalid();
8067 test_private_data();
8068 test_surface_dimensions();
8069 test_surface_format_null();
8070 test_surface_double_unlock();
8071 test_surface_blocks();
8074 test_managed_buffer();
8075 test_npot_textures();
8076 test_volume_locking();
8077 test_update_volumetexture();
8078 test_create_rt_ds_fail();
8079 test_volume_blocks();
8080 test_lockbox_invalid();
8081 test_pixel_format();
8082 test_begin_end_state_block();
8083 test_shader_constant_apply();
8084 test_resource_type();
8086 test_writeonly_resource();
8088 test_resource_priority();
8089 test_swapchain_parameters();
8090 test_miptree_layout();
8092 UnregisterClassA("d3d8_test_wc", GetModuleHandleA(NULL
));