2 * Copyright 2011-2012 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "wine/test.h"
39 struct create_window_thread_param
42 HANDLE window_created
;
43 HANDLE destroy_window
;
47 static BOOL
compare_float(float f
, float g
, unsigned int ulps
)
57 if (abs(x
- y
) > ulps
)
63 static BOOL
compare_vec4(struct vec4
*vec
, float x
, float y
, float z
, float w
, unsigned int ulps
)
65 return compare_float(vec
->x
, x
, ulps
)
66 && compare_float(vec
->y
, y
, ulps
)
67 && compare_float(vec
->z
, z
, ulps
)
68 && compare_float(vec
->w
, w
, ulps
);
71 static BOOL
compare_color(D3DCOLOR c1
, D3DCOLOR c2
, BYTE max_diff
)
73 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
75 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
77 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
79 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
83 static DWORD WINAPI
create_window_thread_proc(void *param
)
85 struct create_window_thread_param
*p
= param
;
89 p
->window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
90 0, 0, 640, 480, 0, 0, 0, 0);
91 ret
= SetEvent(p
->window_created
);
92 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
98 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
99 DispatchMessage(&msg
);
100 res
= WaitForSingleObject(p
->destroy_window
, 100);
101 if (res
== WAIT_OBJECT_0
)
103 if (res
!= WAIT_TIMEOUT
)
105 ok(0, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
110 DestroyWindow(p
->window
);
115 static void create_window_thread(struct create_window_thread_param
*p
)
119 p
->window_created
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
120 ok(!!p
->window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
121 p
->destroy_window
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
122 ok(!!p
->destroy_window
, "CreateEvent failed, last error %#x.\n", GetLastError());
123 p
->thread
= CreateThread(NULL
, 0, create_window_thread_proc
, p
, 0, &tid
);
124 ok(!!p
->thread
, "Failed to create thread, last error %#x.\n", GetLastError());
125 res
= WaitForSingleObject(p
->window_created
, INFINITE
);
126 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
129 static void destroy_window_thread(struct create_window_thread_param
*p
)
131 SetEvent(p
->destroy_window
);
132 WaitForSingleObject(p
->thread
, INFINITE
);
133 CloseHandle(p
->destroy_window
);
134 CloseHandle(p
->window_created
);
135 CloseHandle(p
->thread
);
138 static IDirectDrawSurface4
*get_depth_stencil(IDirect3DDevice3
*device
)
140 IDirectDrawSurface4
*rt
, *ret
;
141 DDSCAPS2 caps
= {DDSCAPS_ZBUFFER
, 0, 0, 0};
144 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
145 ok(SUCCEEDED(hr
), "Failed to get the render target, hr %#x.\n", hr
);
146 hr
= IDirectDrawSurface4_GetAttachedSurface(rt
, &caps
, &ret
);
147 ok(SUCCEEDED(hr
) || hr
== DDERR_NOTFOUND
, "Failed to get the z buffer, hr %#x.\n", hr
);
148 IDirectDrawSurface4_Release(rt
);
152 static D3DCOLOR
get_surface_color(IDirectDrawSurface4
*surface
, UINT x
, UINT y
)
154 RECT rect
= {x
, y
, x
+ 1, y
+ 1};
155 DDSURFACEDESC2 surface_desc
;
159 memset(&surface_desc
, 0, sizeof(surface_desc
));
160 surface_desc
.dwSize
= sizeof(surface_desc
);
162 hr
= IDirectDrawSurface4_Lock(surface
, &rect
, &surface_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
163 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
167 color
= *((DWORD
*)surface_desc
.lpSurface
) & 0x00ffffff;
169 hr
= IDirectDrawSurface4_Unlock(surface
, &rect
);
170 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
175 static HRESULT CALLBACK
enum_z_fmt(DDPIXELFORMAT
*format
, void *ctx
)
177 DDPIXELFORMAT
*z_fmt
= ctx
;
179 if (U1(*format
).dwZBufferBitDepth
> U1(*z_fmt
).dwZBufferBitDepth
)
185 static IDirectDraw4
*create_ddraw(void)
187 IDirectDraw4
*ddraw4
;
191 if (FAILED(DirectDrawCreate(NULL
, &ddraw1
, NULL
)))
194 hr
= IDirectDraw_QueryInterface(ddraw1
, &IID_IDirectDraw4
, (void **)&ddraw4
);
195 IDirectDraw_Release(ddraw1
);
202 static IDirect3DDevice3
*create_device(HWND window
, DWORD coop_level
)
204 IDirectDrawSurface4
*surface
, *ds
;
205 IDirect3DDevice3
*device
= NULL
;
206 DDSURFACEDESC2 surface_desc
;
207 IDirectDraw4
*ddraw4
;
212 if (!(ddraw4
= create_ddraw()))
215 hr
= IDirectDraw4_SetCooperativeLevel(ddraw4
, window
, coop_level
);
216 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
218 memset(&surface_desc
, 0, sizeof(surface_desc
));
219 surface_desc
.dwSize
= sizeof(surface_desc
);
220 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
221 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
222 surface_desc
.dwWidth
= 640;
223 surface_desc
.dwHeight
= 480;
225 hr
= IDirectDraw4_CreateSurface(ddraw4
, &surface_desc
, &surface
, NULL
);
226 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
228 if (coop_level
& DDSCL_NORMAL
)
230 IDirectDrawClipper
*clipper
;
232 hr
= IDirectDraw4_CreateClipper(ddraw4
, 0, &clipper
, NULL
);
233 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
234 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
235 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
236 hr
= IDirectDrawSurface4_SetClipper(surface
, clipper
);
237 ok(SUCCEEDED(hr
), "Failed to set surface clipper, hr %#x.\n", hr
);
238 IDirectDrawClipper_Release(clipper
);
241 hr
= IDirectDraw4_QueryInterface(ddraw4
, &IID_IDirect3D3
, (void **)&d3d3
);
242 IDirectDraw4_Release(ddraw4
);
245 IDirectDrawSurface4_Release(surface
);
249 memset(&z_fmt
, 0, sizeof(z_fmt
));
250 hr
= IDirect3D3_EnumZBufferFormats(d3d3
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
251 if (FAILED(hr
) || !z_fmt
.dwSize
)
253 IDirect3D3_Release(d3d3
);
254 IDirectDrawSurface4_Release(surface
);
258 memset(&surface_desc
, 0, sizeof(surface_desc
));
259 surface_desc
.dwSize
= sizeof(surface_desc
);
260 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
261 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
262 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
263 surface_desc
.dwWidth
= 640;
264 surface_desc
.dwHeight
= 480;
265 hr
= IDirectDraw4_CreateSurface(ddraw4
, &surface_desc
, &ds
, NULL
);
266 ok(SUCCEEDED(hr
), "Failed to create depth buffer, hr %#x.\n", hr
);
269 IDirect3D3_Release(d3d3
);
270 IDirectDrawSurface4_Release(surface
);
274 hr
= IDirectDrawSurface_AddAttachedSurface(surface
, ds
);
275 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
276 IDirectDrawSurface4_Release(ds
);
279 IDirect3D3_Release(d3d3
);
280 IDirectDrawSurface4_Release(surface
);
284 hr
= IDirect3D3_CreateDevice(d3d3
, &IID_IDirect3DHALDevice
, surface
, &device
, NULL
);
285 IDirect3D3_Release(d3d3
);
286 IDirectDrawSurface4_Release(surface
);
293 static IDirect3DViewport3
*create_viewport(IDirect3DDevice3
*device
, UINT x
, UINT y
, UINT w
, UINT h
)
295 IDirect3DViewport3
*viewport
;
300 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
301 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
302 hr
= IDirect3D3_CreateViewport(d3d
, &viewport
, NULL
);
303 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
304 hr
= IDirect3DDevice3_AddViewport(device
, viewport
);
305 ok(SUCCEEDED(hr
), "Failed to add viewport, hr %#x.\n", hr
);
306 memset(&vp
, 0, sizeof(vp
));
307 vp
.dwSize
= sizeof(vp
);
314 vp
.dvClipWidth
= 2.0f
;
315 vp
.dvClipHeight
= 2.0f
;
318 hr
= IDirect3DViewport3_SetViewport2(viewport
, &vp
);
319 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
320 IDirect3D3_Release(d3d
);
325 static void destroy_viewport(IDirect3DDevice3
*device
, IDirect3DViewport3
*viewport
)
329 hr
= IDirect3DDevice3_DeleteViewport(device
, viewport
);
330 ok(SUCCEEDED(hr
), "Failed to delete viewport, hr %#x.\n", hr
);
331 IDirect3DViewport3_Release(viewport
);
334 static void test_process_vertices(void)
336 IDirect3DVertexBuffer
*src_vb
, *dst_vb
;
337 IDirect3DViewport3
*viewport
;
338 D3DVERTEXBUFFERDESC vb_desc
;
339 IDirect3DDevice3
*device
;
340 struct vec3
*src_data
;
341 struct vec4
*dst_data
;
348 static D3DMATRIX identity
=
350 1.0f
, 0.0f
, 0.0f
, 0.0f
,
351 0.0f
, 1.0f
, 0.0f
, 0.0f
,
352 0.0f
, 0.0f
, 1.0f
, 0.0f
,
353 0.0f
, 0.0f
, 0.0f
, 1.0f
,
355 static D3DMATRIX projection
=
357 1.0f
, 0.0f
, 0.0f
, 0.0f
,
358 0.0f
, 1.0f
, 0.0f
, 0.0f
,
359 0.0f
, 0.0f
, 1.0f
, 0.0f
,
360 6.0f
, 7.0f
, 8.0f
, 1.0f
,
363 window
= CreateWindowA("static", "d3d7_test", WS_OVERLAPPEDWINDOW
,
364 0, 0, 640, 480, 0, 0, 0, 0);
365 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
367 skip("Failed to create a 3D device, skipping test.\n");
368 DestroyWindow(window
);
372 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d3
);
373 ok(SUCCEEDED(hr
), "Failed to get Direct3D3 interface, hr %#x.\n", hr
);
375 memset(&vb_desc
, 0, sizeof(vb_desc
));
376 vb_desc
.dwSize
= sizeof(vb_desc
);
377 vb_desc
.dwFVF
= D3DFVF_XYZ
;
378 vb_desc
.dwNumVertices
= 3;
379 hr
= IDirect3D3_CreateVertexBuffer(d3d3
, &vb_desc
, &src_vb
, 0, NULL
);
380 ok(SUCCEEDED(hr
), "Failed to create source vertex buffer, hr %#x.\n", hr
);
382 hr
= IDirect3DVertexBuffer_Lock(src_vb
, DDLOCK_WRITEONLY
, (void **)&src_data
, NULL
);
383 ok(SUCCEEDED(hr
), "Failed to lock source vertex buffer, hr %#x.\n", hr
);
384 src_data
[0].x
= -1.0f
;
385 src_data
[0].y
= -1.0f
;
386 src_data
[0].z
= -1.0f
;
387 src_data
[1].x
= 0.0f
;
388 src_data
[1].y
= 0.0f
;
389 src_data
[1].z
= 0.0f
;
390 src_data
[2].x
= 1.0f
;
391 src_data
[2].y
= 1.0f
;
392 src_data
[2].z
= 1.0f
;
393 hr
= IDirect3DVertexBuffer_Unlock(src_vb
);
394 ok(SUCCEEDED(hr
), "Failed to unlock source vertex buffer, hr %#x.\n", hr
);
396 memset(&vb_desc
, 0, sizeof(vb_desc
));
397 vb_desc
.dwSize
= sizeof(vb_desc
);
398 vb_desc
.dwFVF
= D3DFVF_XYZRHW
;
399 vb_desc
.dwNumVertices
= 3;
400 hr
= IDirect3D3_CreateVertexBuffer(d3d3
, &vb_desc
, &dst_vb
, 0, NULL
);
401 ok(SUCCEEDED(hr
), "Failed to create destination vertex buffer, hr %#x.\n", hr
);
403 hr
= IDirect3D3_CreateViewport(d3d3
, &viewport
, NULL
);
404 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
405 hr
= IDirect3DDevice3_AddViewport(device
, viewport
);
406 ok(SUCCEEDED(hr
), "Failed to add viewport, hr %#x.\n", hr
);
407 vp2
.dwSize
= sizeof(vp2
);
414 vp2
.dvClipWidth
= 4.0f
;
415 vp2
.dvClipHeight
= 5.0f
;
418 hr
= IDirect3DViewport3_SetViewport2(viewport
, &vp2
);
419 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
420 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
421 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
423 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &identity
);
424 ok(SUCCEEDED(hr
), "Failed to set world transformation, hr %#x.\n", hr
);
425 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &identity
);
426 ok(SUCCEEDED(hr
), "Failed to set view transformation, hr %#x.\n", hr
);
427 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &identity
);
428 ok(SUCCEEDED(hr
), "Failed to set projection transformation, hr %#x.\n", hr
);
430 hr
= IDirect3DVertexBuffer_ProcessVertices(dst_vb
, D3DVOP_TRANSFORM
, 0, 3, src_vb
, 0, device
, 0);
431 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
433 hr
= IDirect3DVertexBuffer_Lock(dst_vb
, DDLOCK_READONLY
, (void **)&dst_data
, NULL
);
434 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
435 ok(compare_vec4(&dst_data
[0], -6.500e+1f
, +1.800e+2f
, +2.000e-1f
, +1.000e+0f
, 4096),
436 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
437 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
438 ok(compare_vec4(&dst_data
[1], -4.000e+1f
, +1.400e+2f
, +4.000e-1f
, +1.000e+0f
, 4096),
439 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
440 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
441 ok(compare_vec4(&dst_data
[2], -1.500e+1f
, +1.000e+2f
, +6.000e-1f
, +1.000e+0f
, 4096),
442 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
443 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
444 hr
= IDirect3DVertexBuffer_Unlock(dst_vb
);
445 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
447 hr
= IDirect3DDevice3_MultiplyTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &projection
);
448 ok(SUCCEEDED(hr
), "Failed to set projection transformation, hr %#x.\n", hr
);
450 hr
= IDirect3DVertexBuffer_ProcessVertices(dst_vb
, D3DVOP_TRANSFORM
, 0, 3, src_vb
, 0, device
, 0);
451 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
453 hr
= IDirect3DVertexBuffer_Lock(dst_vb
, DDLOCK_READONLY
, (void **)&dst_data
, NULL
);
454 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
455 ok(compare_vec4(&dst_data
[0], +8.500e+1f
, -1.000e+2f
, +1.800e+0f
, +1.000e+0f
, 4096),
456 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
457 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
458 ok(compare_vec4(&dst_data
[1], +1.100e+2f
, -1.400e+2f
, +2.000e+0f
, +1.000e+0f
, 4096),
459 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
460 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
461 ok(compare_vec4(&dst_data
[2], +1.350e+2f
, -1.800e+2f
, +2.200e+0f
, +1.000e+0f
, 4096),
462 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
463 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
464 hr
= IDirect3DVertexBuffer_Unlock(dst_vb
);
465 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
467 vp2
.dwSize
= sizeof(vp2
);
474 vp2
.dvClipWidth
= 2.0f
;
475 vp2
.dvClipHeight
= 4.0f
;
478 hr
= IDirect3DViewport3_SetViewport2(viewport
, &vp2
);
479 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
481 hr
= IDirect3DVertexBuffer_ProcessVertices(dst_vb
, D3DVOP_TRANSFORM
, 0, 3, src_vb
, 0, device
, 0);
482 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
484 hr
= IDirect3DVertexBuffer_Lock(dst_vb
, DDLOCK_READONLY
, (void **)&dst_data
, NULL
);
485 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
486 ok(compare_vec4(&dst_data
[0], +7.500e+1f
, +4.000e+1f
, -8.000e-1f
, +1.000e+0f
, 4096),
487 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
488 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
489 ok(compare_vec4(&dst_data
[1], +1.200e+2f
, +2.000e+1f
, -1.000e+0f
, +1.000e+0f
, 4096),
490 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
491 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
492 ok(compare_vec4(&dst_data
[2], +1.650e+2f
, +0.000e+0f
, -1.200e+0f
, +1.000e+0f
, 4096),
493 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
494 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
495 hr
= IDirect3DVertexBuffer_Unlock(dst_vb
);
496 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
498 vp1
.dwSize
= sizeof(vp1
);
509 hr
= IDirect3DViewport3_SetViewport(viewport
, &vp1
);
510 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
512 hr
= IDirect3DVertexBuffer_ProcessVertices(dst_vb
, D3DVOP_TRANSFORM
, 0, 3, src_vb
, 0, device
, 0);
513 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
515 hr
= IDirect3DVertexBuffer_Lock(dst_vb
, DDLOCK_READONLY
, (void **)&dst_data
, NULL
);
516 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
517 ok(compare_vec4(&dst_data
[0], +1.100e+2f
, +6.800e+1f
, +7.000e+0f
, +1.000e+0f
, 4096),
518 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
519 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
520 ok(compare_vec4(&dst_data
[1], +1.170e+2f
, +6.600e+1f
, +8.000e+0f
, +1.000e+0f
, 4096),
521 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
522 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
523 ok(compare_vec4(&dst_data
[2], +1.240e+2f
, +6.400e+1f
, +9.000e+0f
, +1.000e+0f
, 4096),
524 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
525 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
526 hr
= IDirect3DVertexBuffer_Unlock(dst_vb
);
527 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
529 hr
= IDirect3DDevice3_DeleteViewport(device
, viewport
);
530 ok(SUCCEEDED(hr
), "Failed to delete viewport, hr %#x.\n", hr
);
532 IDirect3DVertexBuffer_Release(dst_vb
);
533 IDirect3DVertexBuffer_Release(src_vb
);
534 IDirect3DViewport3_Release(viewport
);
535 IDirect3D3_Release(d3d3
);
536 IDirect3DDevice3_Release(device
);
537 DestroyWindow(window
);
540 static void test_coop_level_create_device_window(void)
542 HWND focus_window
, device_window
;
546 focus_window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
547 0, 0, 640, 480, 0, 0, 0, 0);
548 if (!(ddraw
= create_ddraw()))
550 skip("Failed to create a ddraw object, skipping test.\n");
551 DestroyWindow(focus_window
);
555 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
556 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
557 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
558 ok(!device_window
, "Unexpected device window found.\n");
559 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
);
560 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
561 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
562 ok(!device_window
, "Unexpected device window found.\n");
563 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
);
564 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
565 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
566 ok(!device_window
, "Unexpected device window found.\n");
567 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
568 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
569 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
570 ok(!device_window
, "Unexpected device window found.\n");
571 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
572 ok(hr
== DDERR_NOFOCUSWINDOW
|| broken(hr
== DDERR_INVALIDPARAMS
), "Got unexpected hr %#x.\n", hr
);
573 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
574 ok(!device_window
, "Unexpected device window found.\n");
576 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
577 if (broken(hr
== DDERR_INVALIDPARAMS
))
579 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
580 IDirectDraw4_Release(ddraw
);
581 DestroyWindow(focus_window
);
585 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
586 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
587 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
588 ok(!device_window
, "Unexpected device window found.\n");
589 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
590 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
591 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
592 ok(!device_window
, "Unexpected device window found.\n");
594 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
595 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
596 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
597 ok(!device_window
, "Unexpected device window found.\n");
598 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_SETFOCUSWINDOW
599 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
600 ok(hr
== DDERR_NOHWND
, "Got unexpected hr %#x.\n", hr
);
601 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
602 ok(!!device_window
, "Device window not found.\n");
604 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
605 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
606 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
607 ok(!device_window
, "Unexpected device window found.\n");
608 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
609 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
610 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
611 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
612 ok(!!device_window
, "Device window not found.\n");
614 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
615 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
616 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
617 ok(!device_window
, "Unexpected device window found.\n");
618 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
619 ok(hr
== DDERR_NOFOCUSWINDOW
, "Got unexpected hr %#x.\n", hr
);
620 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
621 ok(!device_window
, "Unexpected device window found.\n");
622 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
);
623 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
624 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
625 ok(!device_window
, "Unexpected device window found.\n");
626 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
627 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
628 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
629 ok(!!device_window
, "Device window not found.\n");
631 IDirectDraw4_Release(ddraw
);
632 DestroyWindow(focus_window
);
635 static void test_clipper_blt(void)
637 IDirectDrawSurface4
*src_surface
, *dst_surface
;
638 RECT client_rect
, src_rect
, *rect
;
639 IDirectDrawClipper
*clipper
;
640 DDSURFACEDESC2 surface_desc
;
641 unsigned int i
, j
, x
, y
;
652 static const DWORD src_data
[] =
654 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
655 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
656 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
658 static const D3DCOLOR expected1
[] =
660 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
661 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
662 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
663 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
665 static const D3DCOLOR expected2
[] =
667 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
668 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
669 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
670 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
673 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
674 10, 10, 640, 480, 0, 0, 0, 0);
675 ShowWindow(window
, SW_SHOW
);
676 if (!(ddraw
= create_ddraw()))
678 skip("Failed to create a ddraw object, skipping test.\n");
679 DestroyWindow(window
);
683 ret
= GetClientRect(window
, &client_rect
);
684 ok(ret
, "Failed to get client rect.\n");
685 ret
= MapWindowPoints(window
, NULL
, (POINT
*)&client_rect
, 2);
686 ok(ret
, "Failed to map client rect.\n");
688 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
689 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
691 hr
= IDirectDraw4_CreateClipper(ddraw
, 0, &clipper
, NULL
);
692 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
693 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
694 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
695 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
696 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
697 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
698 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
699 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
700 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, rgn_data
, &ret
);
701 ok(SUCCEEDED(hr
), "Failed to get clip list, hr %#x.\n", hr
);
702 ok(rgn_data
->rdh
.dwSize
== sizeof(rgn_data
->rdh
), "Got unexpected structure size %#x.\n", rgn_data
->rdh
.dwSize
);
703 ok(rgn_data
->rdh
.iType
== RDH_RECTANGLES
, "Got unexpected type %#x.\n", rgn_data
->rdh
.iType
);
704 ok(rgn_data
->rdh
.nCount
== 1, "Got unexpected count %u.\n", rgn_data
->rdh
.nCount
);
705 ok(rgn_data
->rdh
.nRgnSize
== 16, "Got unexpected region size %u.\n", rgn_data
->rdh
.nRgnSize
);
706 ok(EqualRect(&rgn_data
->rdh
.rcBound
, &client_rect
),
707 "Got unexpected bounding rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
708 rgn_data
->rdh
.rcBound
.left
, rgn_data
->rdh
.rcBound
.top
,
709 rgn_data
->rdh
.rcBound
.right
, rgn_data
->rdh
.rcBound
.bottom
,
710 client_rect
.left
, client_rect
.top
, client_rect
.right
, client_rect
.bottom
);
711 rect
= (RECT
*)&rgn_data
->Buffer
[0];
712 ok(EqualRect(rect
, &client_rect
),
713 "Got unexpected clip rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
714 rect
->left
, rect
->top
, rect
->right
, rect
->bottom
,
715 client_rect
.left
, client_rect
.top
, client_rect
.right
, client_rect
.bottom
);
716 HeapFree(GetProcessHeap(), 0, rgn_data
);
718 r1
= CreateRectRgn(0, 0, 320, 240);
719 ok(!!r1
, "Failed to create region.\n");
720 r2
= CreateRectRgn(320, 240, 640, 480);
721 ok(!!r2
, "Failed to create region.\n");
722 CombineRgn(r1
, r1
, r2
, RGN_OR
);
723 ret
= GetRegionData(r1
, 0, NULL
);
724 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
725 ret
= GetRegionData(r1
, ret
, rgn_data
);
726 ok(!!ret
, "Failed to get region data.\n");
731 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
732 ok(hr
== DDERR_CLIPPERISUSINGHWND
, "Got unexpected hr %#x.\n", hr
);
733 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
734 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
735 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
736 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
738 HeapFree(GetProcessHeap(), 0, rgn_data
);
740 memset(&surface_desc
, 0, sizeof(surface_desc
));
741 surface_desc
.dwSize
= sizeof(surface_desc
);
742 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
743 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
744 surface_desc
.dwWidth
= 640;
745 surface_desc
.dwHeight
= 480;
746 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
747 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
748 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
749 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
750 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
751 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
753 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &src_surface
, NULL
);
754 ok(SUCCEEDED(hr
), "Failed to create source surface, hr %#x.\n", hr
);
755 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &dst_surface
, NULL
);
756 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
758 memset(&fx
, 0, sizeof(fx
));
759 fx
.dwSize
= sizeof(fx
);
760 hr
= IDirectDrawSurface4_Blt(src_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
761 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
762 hr
= IDirectDrawSurface4_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
763 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
765 hr
= IDirectDrawSurface4_Lock(src_surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
766 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
767 ok(U1(surface_desc
).lPitch
== 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc
).lPitch
);
768 ptr
= surface_desc
.lpSurface
;
769 memcpy(&ptr
[ 0], &src_data
[ 0], 6 * sizeof(DWORD
));
770 memcpy(&ptr
[ 640], &src_data
[ 6], 6 * sizeof(DWORD
));
771 memcpy(&ptr
[1280], &src_data
[12], 6 * sizeof(DWORD
));
772 hr
= IDirectDrawSurface4_Unlock(src_surface
, NULL
);
773 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
775 hr
= IDirectDrawSurface4_SetClipper(dst_surface
, clipper
);
776 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
778 SetRect(&src_rect
, 1, 1, 5, 2);
779 hr
= IDirectDrawSurface4_Blt(dst_surface
, NULL
, src_surface
, &src_rect
, DDBLT_WAIT
, NULL
);
780 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
781 for (i
= 0; i
< 4; ++i
)
783 for (j
= 0; j
< 4; ++j
)
785 x
= 80 * ((2 * j
) + 1);
786 y
= 60 * ((2 * i
) + 1);
787 color
= get_surface_color(dst_surface
, x
, y
);
788 ok(compare_color(color
, expected1
[i
* 4 + j
], 1),
789 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1
[i
* 4 + j
], x
, y
, color
);
793 U5(fx
).dwFillColor
= 0xff0000ff;
794 hr
= IDirectDrawSurface4_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
795 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
796 for (i
= 0; i
< 4; ++i
)
798 for (j
= 0; j
< 4; ++j
)
800 x
= 80 * ((2 * j
) + 1);
801 y
= 60 * ((2 * i
) + 1);
802 color
= get_surface_color(dst_surface
, x
, y
);
803 ok(compare_color(color
, expected2
[i
* 4 + j
], 1),
804 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2
[i
* 4 + j
], x
, y
, color
);
808 hr
= IDirectDrawSurface4_BltFast(dst_surface
, 0, 0, src_surface
, NULL
, DDBLTFAST_WAIT
);
809 ok(hr
== DDERR_BLTFASTCANTCLIP
, "Got unexpected hr %#x.\n", hr
);
811 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
812 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
813 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
814 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
815 DestroyWindow(window
);
816 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
817 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
818 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
819 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
820 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
821 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
822 hr
= IDirectDrawClipper_SetClipList(clipper
, NULL
, 0);
823 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
824 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
825 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
826 hr
= IDirectDrawSurface4_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
827 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
829 IDirectDrawSurface4_Release(dst_surface
);
830 IDirectDrawSurface4_Release(src_surface
);
831 IDirectDrawClipper_Release(clipper
);
832 IDirectDraw4_Release(ddraw
);
835 static void test_coop_level_d3d_state(void)
837 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
838 IDirectDrawSurface4
*rt
, *surface
;
839 IDirect3DViewport3
*viewport
;
840 IDirect3DDevice3
*device
;
848 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
849 0, 0, 640, 480, 0, 0, 0, 0);
850 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
852 skip("Failed to create D3D device, skipping test.\n");
853 DestroyWindow(window
);
857 viewport
= create_viewport(device
, 0, 0, 640, 480);
859 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
860 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
861 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
862 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
863 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
864 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
865 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
866 ok(!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
867 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
868 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
869 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffff0000, 0.0f
, 0);
870 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
871 color
= get_surface_color(rt
, 320, 240);
872 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
874 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
875 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
876 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
877 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
878 IDirect3D3_Release(d3d
);
879 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
880 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
881 hr
= IDirectDrawSurface4_IsLost(rt
);
882 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
883 hr
= IDirectDraw4_RestoreAllSurfaces(ddraw
);
884 ok(SUCCEEDED(hr
), "Failed to restore surfaces, hr %#x.\n", hr
);
885 IDirectDraw4_Release(ddraw
);
887 hr
= IDirect3DDevice3_GetRenderTarget(device
, &surface
);
888 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
889 ok(surface
== rt
, "Got unexpected surface %p.\n", surface
);
890 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
891 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
892 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
893 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
894 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
895 ok(!!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
896 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0f
, 0);
897 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
898 color
= get_surface_color(rt
, 320, 240);
899 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
901 destroy_viewport(device
, viewport
);
902 IDirectDrawSurface4_Release(surface
);
903 IDirectDrawSurface4_Release(rt
);
904 IDirect3DDevice3_Release(device
);
905 DestroyWindow(window
);
908 static void test_surface_interface_mismatch(void)
910 IDirectDraw4
*ddraw
= NULL
;
911 IDirect3D3
*d3d
= NULL
;
912 IDirectDrawSurface4
*surface
= NULL
, *ds
;
913 IDirectDrawSurface3
*surface3
= NULL
;
914 IDirect3DDevice3
*device
= NULL
;
915 IDirect3DViewport3
*viewport
= NULL
;
916 DDSURFACEDESC2 surface_desc
;
922 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
924 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
925 0, 0, 640, 480, 0, 0, 0, 0);
927 if (!(ddraw
= create_ddraw()))
929 skip("Failed to create a ddraw object, skipping test.\n");
933 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
934 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
936 memset(&surface_desc
, 0, sizeof(surface_desc
));
937 surface_desc
.dwSize
= sizeof(surface_desc
);
938 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
939 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
940 surface_desc
.dwWidth
= 640;
941 surface_desc
.dwHeight
= 480;
943 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
944 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
946 hr
= IDirectDrawSurface4_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
947 ok(SUCCEEDED(hr
), "Failed to QI IDirectDrawSurface3, hr %#x.\n", hr
);
949 hr
= IDirectDraw4_QueryInterface(ddraw
, &IID_IDirect3D3
, (void **)&d3d
);
952 skip("Failed to get the IDirect3D7 interface, skipping test.\n");
956 memset(&z_fmt
, 0, sizeof(z_fmt
));
957 hr
= IDirect3D3_EnumZBufferFormats(d3d
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
958 if (FAILED(hr
) || !z_fmt
.dwSize
)
960 skip("No depth buffer formats available, skipping test.\n");
964 memset(&surface_desc
, 0, sizeof(surface_desc
));
965 surface_desc
.dwSize
= sizeof(surface_desc
);
966 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
967 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
968 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
969 surface_desc
.dwWidth
= 640;
970 surface_desc
.dwHeight
= 480;
971 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
);
972 ok(SUCCEEDED(hr
), "Failed to create depth buffer, hr %#x.\n", hr
);
976 /* Using a different surface interface version still works */
977 hr
= IDirectDrawSurface3_AddAttachedSurface(surface3
, (IDirectDrawSurface3
*)ds
);
978 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
979 refcount
= IDirectDrawSurface4_Release(ds
);
980 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
985 hr
= IDirect3D3_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, (IDirectDrawSurface4
*)surface3
, &device
, NULL
);
986 ok(SUCCEEDED(hr
), "Failed to create d3d device.\n");
990 viewport
= create_viewport(device
, 0, 0, 640, 480);
992 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffff0000, 0.0f
, 0);
993 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
994 color
= get_surface_color(surface
, 320, 240);
995 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
999 destroy_viewport(device
, viewport
);
1000 if (surface3
) IDirectDrawSurface3_Release(surface3
);
1001 if (surface
) IDirectDrawSurface4_Release(surface
);
1002 if (device
) IDirect3DDevice3_Release(device
);
1003 if (d3d
) IDirect3D3_Release(d3d
);
1004 if (ddraw
) IDirectDraw4_Release(ddraw
);
1005 DestroyWindow(window
);
1008 static void test_coop_level_threaded(void)
1010 struct create_window_thread_param p
;
1011 IDirectDraw4
*ddraw
;
1014 if (!(ddraw
= create_ddraw()))
1016 skip("Failed to create a ddraw object, skipping test.\n");
1019 create_window_thread(&p
);
1021 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, p
.window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1022 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1024 IDirectDraw4_Release(ddraw
);
1025 destroy_window_thread(&p
);
1028 static void test_depth_blit(void)
1037 { -1.0, 1.0, 0.50f
, 0xff00ff00},
1038 { 1.0, 1.0, 0.50f
, 0xff00ff00},
1039 { -1.0, -1.0, 0.50f
, 0xff00ff00},
1040 { 1.0, -1.0, 0.50f
, 0xff00ff00},
1042 static const D3DCOLOR expected_colors
[4][4] =
1044 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1045 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1046 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1047 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1049 DDSURFACEDESC2 ddsd_new
, ddsd_existing
;
1051 IDirect3DDevice3
*device
;
1052 IDirectDrawSurface4
*ds1
, *ds2
, *ds3
, *rt
;
1053 IDirect3DViewport3
*viewport
;
1054 RECT src_rect
, dst_rect
;
1059 IDirectDraw4
*ddraw
;
1064 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1065 0, 0, 640, 480, 0, 0, 0, 0);
1066 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1068 skip("Failed to create D3D device, skipping test.\n");
1069 DestroyWindow(window
);
1073 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
1074 ok(SUCCEEDED(hr
), "Failed to get Direct3D3 interface, hr %#x.\n", hr
);
1075 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
1076 ok(SUCCEEDED(hr
), "Failed to get DirectDraw4 interface, hr %#x.\n", hr
);
1077 IDirect3D3_Release(d3d
);
1079 ds1
= get_depth_stencil(device
);
1081 memset(&ddsd_new
, 0, sizeof(ddsd_new
));
1082 ddsd_new
.dwSize
= sizeof(ddsd_new
);
1083 memset(&ddsd_existing
, 0, sizeof(ddsd_existing
));
1084 ddsd_existing
.dwSize
= sizeof(ddsd_existing
);
1085 hr
= IDirectDrawSurface4_GetSurfaceDesc(ds1
, &ddsd_existing
);
1086 ddsd_new
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
1087 ddsd_new
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
1088 ddsd_new
.dwWidth
= ddsd_existing
.dwWidth
;
1089 ddsd_new
.dwHeight
= ddsd_existing
.dwHeight
;
1090 U4(ddsd_new
).ddpfPixelFormat
= U4(ddsd_existing
).ddpfPixelFormat
;
1091 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd_new
, &ds2
, NULL
);
1092 ok(SUCCEEDED(hr
), "Failed to create a surface, hr %#x.\n", hr
);
1093 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd_new
, &ds3
, NULL
);
1094 ok(SUCCEEDED(hr
), "Failed to create a surface, hr %#x.\n", hr
);
1095 IDirectDraw4_Release(ddraw
);
1097 viewport
= create_viewport(device
, 0, 0, ddsd_existing
.dwWidth
, ddsd_existing
.dwHeight
);
1098 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
1099 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
1101 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_TRUE
);
1102 ok(SUCCEEDED(hr
), "Failed to enable z testing, hr %#x.\n", hr
);
1103 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZFUNC
, D3DCMP_LESSEQUAL
);
1104 ok(SUCCEEDED(hr
), "Failed to set the z function, hr %#x.\n", hr
);
1105 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
1106 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
1108 U1(d3drect
).x1
= U2(d3drect
).y1
= 0;
1109 U3(d3drect
).x2
= ddsd_existing
.dwWidth
; U4(d3drect
).y2
= ddsd_existing
.dwHeight
;
1110 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &d3drect
, D3DCLEAR_ZBUFFER
, 0, 0.0f
, 0);
1111 ok(SUCCEEDED(hr
), "Failed to clear the z buffer, hr %#x.\n", hr
);
1114 SetRect(&src_rect
, 0, 0, 320, 240);
1115 SetRect(&dst_rect
, 0, 0, 320, 240);
1116 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1117 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1118 /* Different locations. */
1119 SetRect(&src_rect
, 0, 0, 320, 240);
1120 SetRect(&dst_rect
, 320, 240, 640, 480);
1121 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1122 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1124 SetRect(&src_rect
, 0, 0, 320, 240);
1125 SetRect(&dst_rect
, 0, 0, 640, 480);
1126 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1127 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1129 SetRect(&src_rect
, 0, 480, 640, 0);
1130 SetRect(&dst_rect
, 0, 0, 640, 480);
1131 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1132 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1133 SetRect(&src_rect
, 0, 0, 640, 480);
1134 SetRect(&dst_rect
, 0, 480, 640, 0);
1135 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1136 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1137 /* Full, explicit. */
1138 SetRect(&src_rect
, 0, 0, 640, 480);
1139 SetRect(&dst_rect
, 0, 0, 640, 480);
1140 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1141 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1142 /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
1144 /* Depth blit inside a BeginScene / EndScene pair */
1145 hr
= IDirect3DDevice3_BeginScene(device
);
1146 ok(SUCCEEDED(hr
), "Failed to start a scene, hr %#x.\n", hr
);
1147 /* From the current depth stencil */
1148 hr
= IDirectDrawSurface4_Blt(ds2
, NULL
, ds1
, NULL
, DDBLT_WAIT
, NULL
);
1149 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1150 /* To the current depth stencil */
1151 hr
= IDirectDrawSurface4_Blt(ds1
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1152 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1153 /* Between unbound surfaces */
1154 hr
= IDirectDrawSurface4_Blt(ds3
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1155 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1156 hr
= IDirect3DDevice3_EndScene(device
);
1157 ok(SUCCEEDED(hr
), "Failed to end a scene, hr %#x.\n", hr
);
1159 /* Avoid changing the depth stencil, it doesn't work properly on Windows.
1160 * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
1161 * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
1162 * a reliable result(z = 0.0) */
1163 memset(&fx
, 0, sizeof(fx
));
1164 fx
.dwSize
= sizeof(fx
);
1165 hr
= IDirectDrawSurface4_Blt(ds2
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
1166 ok(SUCCEEDED(hr
), "Failed to clear the source z buffer, hr %#x.\n", hr
);
1168 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &d3drect
, D3DCLEAR_ZBUFFER
| D3DCLEAR_TARGET
, 0xffff0000, 1.0f
, 0);
1169 ok(SUCCEEDED(hr
), "Failed to clear the color and z buffers, hr %#x.\n", hr
);
1170 SetRect(&dst_rect
, 0, 0, 320, 240);
1171 hr
= IDirectDrawSurface4_Blt(ds1
, &dst_rect
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1172 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1173 IDirectDrawSurface4_Release(ds3
);
1174 IDirectDrawSurface4_Release(ds2
);
1175 IDirectDrawSurface4_Release(ds1
);
1177 hr
= IDirect3DDevice3_BeginScene(device
);
1178 ok(SUCCEEDED(hr
), "Failed to start a scene, hr %#x.\n", hr
);
1179 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
,
1181 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1182 hr
= IDirect3DDevice3_EndScene(device
);
1183 ok(SUCCEEDED(hr
), "Failed to end a scene, hr %#x.\n", hr
);
1185 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
1186 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1187 for (i
= 0; i
< 4; ++i
)
1189 for (j
= 0; j
< 4; ++j
)
1191 unsigned int x
= 80 * ((2 * j
) + 1);
1192 unsigned int y
= 60 * ((2 * i
) + 1);
1193 color
= get_surface_color(rt
, x
, y
);
1194 ok(compare_color(color
, expected_colors
[i
][j
], 1),
1195 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors
[i
][j
], x
, y
, color
);
1198 IDirectDrawSurface4_Release(rt
);
1200 destroy_viewport(device
, viewport
);
1201 IDirect3DDevice3_Release(device
);
1202 DestroyWindow(window
);
1205 static void test_texture_load_ckey(void)
1207 IDirectDraw4
*ddraw
;
1208 IDirectDrawSurface4
*src
;
1209 IDirectDrawSurface4
*dst
;
1210 IDirect3DTexture2
*src_tex
;
1211 IDirect3DTexture2
*dst_tex
;
1212 DDSURFACEDESC2 ddsd
;
1216 if (!(ddraw
= create_ddraw()))
1218 skip("Failed to create ddraw object, skipping test.\n");
1221 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
1222 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1224 memset(&ddsd
, 0, sizeof(ddsd
));
1225 ddsd
.dwSize
= sizeof(ddsd
);
1226 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
1227 ddsd
.dwHeight
= 128;
1229 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
;
1230 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &src
, NULL
);
1231 ok(SUCCEEDED(hr
), "Failed to create source texture, hr %#x.\n", hr
);
1232 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1233 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &dst
, NULL
);
1234 ok(SUCCEEDED(hr
), "Failed to create destination texture, hr %#x.\n", hr
);
1236 hr
= IDirectDrawSurface4_QueryInterface(src
, &IID_IDirect3DTexture2
, (void **)&src_tex
);
1237 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
, "Failed to get Direct3DTexture2 interface, hr %#x.\n", hr
);
1240 /* 64 bit ddraw does not support d3d */
1241 skip("Could not get Direct3DTexture2 interface, skipping texture::Load color keying tests.\n");
1242 IDirectDrawSurface4_Release(dst
);
1243 IDirectDrawSurface4_Release(src
);
1244 IDirectDraw4_Release(ddraw
);
1247 hr
= IDirectDrawSurface4_QueryInterface(dst
, &IID_IDirect3DTexture2
, (void **)&dst_tex
);
1248 ok(SUCCEEDED(hr
), "Failed to get Direct3DTexture2 interface, hr %#x.\n", hr
);
1250 /* No surface has a color key */
1251 hr
= IDirect3DTexture2_Load(dst_tex
, src_tex
);
1252 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1253 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0xdeadbeef;
1254 hr
= IDirectDrawSurface4_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1255 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1256 ok(ckey
.dwColorSpaceLowValue
== 0xdeadbeef, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1257 ok(ckey
.dwColorSpaceHighValue
== 0xdeadbeef, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1259 /* Source surface has a color key */
1260 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x0000ff00;
1261 hr
= IDirectDrawSurface4_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1262 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1263 hr
= IDirect3DTexture2_Load(dst_tex
, src_tex
);
1264 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1265 hr
= IDirectDrawSurface4_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1266 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1267 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1268 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1270 /* Both surfaces have a color key: Dest ckey is overwritten */
1271 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x000000ff;
1272 hr
= IDirectDrawSurface4_SetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1273 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1274 hr
= IDirect3DTexture2_Load(dst_tex
, src_tex
);
1275 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1276 hr
= IDirectDrawSurface4_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1277 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1278 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1279 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1281 /* Only the destination has a color key: It is not deleted */
1282 hr
= IDirectDrawSurface4_SetColorKey(src
, DDCKEY_SRCBLT
, NULL
);
1283 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1284 hr
= IDirectDrawSurface4_GetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1285 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1286 hr
= IDirect3DTexture2_Load(dst_tex
, src_tex
);
1287 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1288 hr
= IDirectDrawSurface4_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1289 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1290 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1291 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1293 IDirect3DTexture2_Release(dst_tex
);
1294 IDirect3DTexture2_Release(src_tex
);
1295 IDirectDrawSurface4_Release(dst
);
1296 IDirectDrawSurface4_Release(src
);
1297 IDirectDraw4_Release(ddraw
);
1300 static ULONG
get_refcount(IUnknown
*test_iface
)
1302 IUnknown_AddRef(test_iface
);
1303 return IUnknown_Release(test_iface
);
1306 static void test_viewport_interfaces(void)
1308 IDirectDraw4
*ddraw
;
1310 HRESULT hr
, old_d3d_ref
;
1312 IDirect3DViewport
*viewport
;
1313 IDirect3DViewport2
*viewport2
;
1314 IDirect3DViewport3
*viewport3
;
1315 IDirectDrawGammaControl
*gamma
;
1318 if (!(ddraw
= create_ddraw()))
1320 skip("Failed to create ddraw object, skipping test.\n");
1323 hr
= IDirectDraw4_QueryInterface(ddraw
, &IID_IDirect3D3
, (void **)&d3d
);
1324 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
, "Failed to get d3d interface, hr %#x.\n", hr
);
1327 skip("Direct3D not available, skipping tests\n");
1328 IDirectDraw4_Release(ddraw
);
1331 old_d3d_ref
= get_refcount((IUnknown
*)d3d
);
1333 hr
= IDirect3D3_CreateViewport(d3d
, &viewport3
, NULL
);
1334 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
1335 ref
= get_refcount((IUnknown
*)viewport3
);
1336 ok(ref
== 1, "Initial IDirect3DViewport3 refcount is %u\n", ref
);
1337 ref
= get_refcount((IUnknown
*)d3d
);
1338 ok(ref
== old_d3d_ref
, "IDirect3D3 refcount is %u\n", ref
);
1340 gamma
= (IDirectDrawGammaControl
*)0xdeadbeef;
1341 hr
= IDirect3DViewport2_QueryInterface(viewport3
, &IID_IDirectDrawGammaControl
, (void **)&gamma
);
1342 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
1343 ok(gamma
== NULL
, "Interface not set to NULL by failed QI call: %p\n", gamma
);
1344 if (SUCCEEDED(hr
)) IDirectDrawGammaControl_Release(gamma
);
1345 /* NULL iid: Segfaults */
1347 hr
= IDirect3DViewport3_QueryInterface(viewport3
, &IID_IDirect3DViewport
, (void **)&viewport
);
1348 ok(SUCCEEDED(hr
), "Failed to QI IDirect3DViewport, hr %#x.\n", hr
);
1351 ref
= get_refcount((IUnknown
*)viewport
);
1352 ok(ref
== 2, "IDirect3DViewport refcount is %u\n", ref
);
1353 ref
= get_refcount((IUnknown
*)viewport3
);
1354 ok(ref
== 2, "IDirect3DViewport3 refcount is %u\n", ref
);
1355 IDirect3DViewport_Release(viewport
);
1359 hr
= IDirect3DViewport3_QueryInterface(viewport3
, &IID_IDirect3DViewport3
, (void **)&viewport2
);
1360 ok(SUCCEEDED(hr
), "Failed to QI IDirect3DViewport3, hr %#x.\n", hr
);
1363 ref
= get_refcount((IUnknown
*)viewport2
);
1364 ok(ref
== 2, "IDirect3DViewport2 refcount is %u\n", ref
);
1365 ref
= get_refcount((IUnknown
*)viewport3
);
1366 ok(ref
== 2, "IDirect3DViewport3 refcount is %u\n", ref
);
1367 IDirect3DViewport3_Release(viewport2
);
1370 hr
= IDirect3DViewport3_QueryInterface(viewport3
, &IID_IUnknown
, (void **)&unknown
);
1371 ok(SUCCEEDED(hr
), "Failed to QI IUnknown, hr %#x.\n", hr
);
1374 ref
= get_refcount((IUnknown
*)viewport3
);
1375 ok(ref
== 2, "IDirect3DViewport3 refcount is %u\n", ref
);
1376 ref
= get_refcount(unknown
);
1377 ok(ref
== 2, "IUnknown refcount is %u\n", ref
);
1378 IUnknown_Release(unknown
);
1381 IDirect3DViewport3_Release(viewport3
);
1382 IDirect3D3_Release(d3d
);
1383 IDirectDraw4_Release(ddraw
);
1386 static void test_zenable(void)
1388 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1391 struct vec4 position
;
1396 {{ 0.0f
, 480.0f
, -0.5f
, 1.0f
}, 0xff00ff00},
1397 {{ 0.0f
, 0.0f
, -0.5f
, 1.0f
}, 0xff00ff00},
1398 {{640.0f
, 480.0f
, 1.5f
, 1.0f
}, 0xff00ff00},
1399 {{640.0f
, 0.0f
, 1.5f
, 1.0f
}, 0xff00ff00},
1401 IDirect3DViewport3
*viewport
;
1402 IDirect3DDevice3
*device
;
1403 IDirectDrawSurface4
*rt
;
1410 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1411 0, 0, 640, 480, 0, 0, 0, 0);
1412 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1414 skip("Failed to create D3D device, skipping test.\n");
1415 DestroyWindow(window
);
1419 viewport
= create_viewport(device
, 0, 0, 640, 480);
1420 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
1421 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1423 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
1424 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
1426 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffff0000, 0.0f
, 0);
1427 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1428 hr
= IDirect3DDevice3_BeginScene(device
);
1429 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1430 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, tquad
, 4, 0);
1431 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1432 hr
= IDirect3DDevice3_EndScene(device
);
1433 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1435 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
1436 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1437 for (i
= 0; i
< 4; ++i
)
1439 for (j
= 0; j
< 4; ++j
)
1441 x
= 80 * ((2 * j
) + 1);
1442 y
= 60 * ((2 * i
) + 1);
1443 color
= get_surface_color(rt
, x
, y
);
1444 ok(compare_color(color
, 0x0000ff00, 1),
1445 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x
, y
, color
);
1448 IDirectDrawSurface4_Release(rt
);
1450 destroy_viewport(device
, viewport
);
1451 IDirect3DDevice3_Release(device
);
1452 DestroyWindow(window
);
1455 static void test_ck_rgba(void)
1457 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1460 struct vec4 position
;
1461 struct vec2 texcoord
;
1465 {{ 0.0f
, 480.0f
, 0.25f
, 1.0f
}, {0.0f
, 0.0f
}},
1466 {{ 0.0f
, 0.0f
, 0.25f
, 1.0f
}, {0.0f
, 1.0f
}},
1467 {{640.0f
, 480.0f
, 0.25f
, 1.0f
}, {1.0f
, 0.0f
}},
1468 {{640.0f
, 0.0f
, 0.25f
, 1.0f
}, {1.0f
, 1.0f
}},
1469 {{ 0.0f
, 480.0f
, 0.75f
, 1.0f
}, {0.0f
, 0.0f
}},
1470 {{ 0.0f
, 0.0f
, 0.75f
, 1.0f
}, {0.0f
, 1.0f
}},
1471 {{640.0f
, 480.0f
, 0.75f
, 1.0f
}, {1.0f
, 0.0f
}},
1472 {{640.0f
, 0.0f
, 0.75f
, 1.0f
}, {1.0f
, 1.0f
}},
1476 D3DCOLOR fill_color
;
1484 {0xff00ff00, TRUE
, TRUE
, 0x00ff0000, 0x000000ff},
1485 {0xff00ff00, TRUE
, FALSE
, 0x00ff0000, 0x000000ff},
1486 {0xff00ff00, FALSE
, TRUE
, 0x0000ff00, 0x0000ff00},
1487 {0xff00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00},
1488 {0x7f00ff00, TRUE
, TRUE
, 0x00807f00, 0x00807f00},
1489 {0x7f00ff00, TRUE
, FALSE
, 0x0000ff00, 0x0000ff00},
1490 {0x7f00ff00, FALSE
, TRUE
, 0x00807f00, 0x00807f00},
1491 {0x7f00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00},
1494 IDirectDrawSurface4
*surface
;
1495 IDirect3DViewport3
*viewport
;
1496 DDSURFACEDESC2 surface_desc
;
1497 IDirect3DTexture2
*texture
;
1498 IDirect3DDevice3
*device
;
1499 IDirectDrawSurface4
*rt
;
1500 IDirectDraw4
*ddraw
;
1508 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1509 0, 0, 640, 480, 0, 0, 0, 0);
1510 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1512 skip("Failed to create D3D device, skipping test.\n");
1513 DestroyWindow(window
);
1517 viewport
= create_viewport(device
, 0, 0, 640, 480);
1518 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
1519 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1521 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
1522 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1523 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
1524 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
1525 IDirect3D3_Release(d3d
);
1527 memset(&surface_desc
, 0, sizeof(surface_desc
));
1528 surface_desc
.dwSize
= sizeof(surface_desc
);
1529 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1530 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1531 surface_desc
.dwWidth
= 256;
1532 surface_desc
.dwHeight
= 256;
1533 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
1534 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
1535 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
1536 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1537 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1538 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1539 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
1540 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0xff00ff00;
1541 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0xff00ff00;
1542 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1543 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
1544 hr
= IDirectDrawSurface4_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
1545 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
1547 hr
= IDirect3DDevice3_SetTexture(device
, 0, texture
);
1548 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
1549 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
1550 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1551 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1552 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1554 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
1555 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1557 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
1559 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, tests
[i
].color_key
);
1560 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
1561 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, tests
[i
].blend
);
1562 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1564 memset(&fx
, 0, sizeof(fx
));
1565 fx
.dwSize
= sizeof(fx
);
1566 U5(fx
).dwFillColor
= tests
[i
].fill_color
;
1567 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1568 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1570 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
,
1571 D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffff0000, 1.0f
, 0);
1572 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1573 hr
= IDirect3DDevice3_BeginScene(device
);
1574 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1575 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[0], 4, 0);
1576 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1577 hr
= IDirect3DDevice3_EndScene(device
);
1578 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1580 color
= get_surface_color(rt
, 320, 240);
1582 todo_wine
ok(compare_color(color
, tests
[i
].result1
, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1583 tests
[i
].result1
, i
, color
);
1585 ok(compare_color(color
, tests
[i
].result1
, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1586 tests
[i
].result1
, i
, color
);
1588 U5(fx
).dwFillColor
= 0xff0000ff;
1589 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1590 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1592 hr
= IDirect3DDevice3_BeginScene(device
);
1593 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1594 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[4], 4, 0);
1595 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1596 hr
= IDirect3DDevice3_EndScene(device
);
1597 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1599 /* This tests that fragments that are masked out by the color key are
1600 * discarded, instead of just fully transparent. */
1601 color
= get_surface_color(rt
, 320, 240);
1603 todo_wine
ok(compare_color(color
, tests
[i
].result2
, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1604 tests
[i
].result2
, i
, color
);
1606 ok(compare_color(color
, tests
[i
].result2
, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1607 tests
[i
].result2
, i
, color
);
1610 IDirectDrawSurface4_Release(rt
);
1611 IDirect3DTexture2_Release(texture
);
1612 IDirectDrawSurface4_Release(surface
);
1613 destroy_viewport(device
, viewport
);
1614 IDirectDraw4_Release(ddraw
);
1615 IDirect3DDevice3_Release(device
);
1616 DestroyWindow(window
);
1622 REFIID refcount_iid
;
1626 static void test_qi(const char *test_name
, IUnknown
*base_iface
,
1627 REFIID refcount_iid
, const struct qi_test
*tests
, UINT entry_count
)
1629 ULONG refcount
, expected_refcount
;
1630 IUnknown
*iface1
, *iface2
;
1634 for (i
= 0; i
< entry_count
; ++i
)
1636 hr
= IUnknown_QueryInterface(base_iface
, tests
[i
].iid
, (void **)&iface1
);
1637 ok(hr
== tests
[i
].hr
, "Got hr %#x for test \"%s\" %u.\n", hr
, test_name
, i
);
1640 for (j
= 0; j
< entry_count
; ++j
)
1642 hr
= IUnknown_QueryInterface(iface1
, tests
[j
].iid
, (void **)&iface2
);
1643 ok(hr
== tests
[j
].hr
, "Got hr %#x for test \"%s\" %u, %u.\n", hr
, test_name
, i
, j
);
1646 expected_refcount
= 0;
1647 if (IsEqualGUID(refcount_iid
, tests
[j
].refcount_iid
))
1648 ++expected_refcount
;
1649 if (IsEqualGUID(tests
[i
].refcount_iid
, tests
[j
].refcount_iid
))
1650 ++expected_refcount
;
1651 refcount
= IUnknown_Release(iface2
);
1652 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
1653 refcount
, test_name
, i
, j
, expected_refcount
);
1657 expected_refcount
= 0;
1658 if (IsEqualGUID(refcount_iid
, tests
[i
].refcount_iid
))
1659 ++expected_refcount
;
1660 refcount
= IUnknown_Release(iface1
);
1661 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, expected %u.\n",
1662 refcount
, test_name
, i
, expected_refcount
);
1667 static void test_surface_qi(void)
1669 static const struct qi_test tests
[] =
1671 {&IID_IDirect3DTexture2
, &IID_IDirectDrawSurface4
, S_OK
},
1672 {&IID_IDirect3DTexture
, &IID_IDirectDrawSurface4
, S_OK
},
1673 {&IID_IDirectDrawGammaControl
, &IID_IDirectDrawGammaControl
, S_OK
},
1674 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
1675 {&IID_IDirectDrawSurface7
, &IID_IDirectDrawSurface7
, S_OK
},
1676 {&IID_IDirectDrawSurface4
, &IID_IDirectDrawSurface4
, S_OK
},
1677 {&IID_IDirectDrawSurface3
, &IID_IDirectDrawSurface3
, S_OK
},
1678 {&IID_IDirectDrawSurface2
, &IID_IDirectDrawSurface2
, S_OK
},
1679 {&IID_IDirectDrawSurface
, &IID_IDirectDrawSurface
, S_OK
},
1680 {&IID_IDirect3DDevice7
, NULL
, E_INVALIDARG
},
1681 {&IID_IDirect3DDevice3
, NULL
, E_INVALIDARG
},
1682 {&IID_IDirect3DDevice2
, NULL
, E_INVALIDARG
},
1683 {&IID_IDirect3DDevice
, NULL
, E_INVALIDARG
},
1684 {&IID_IDirect3D7
, NULL
, E_INVALIDARG
},
1685 {&IID_IDirect3D3
, NULL
, E_INVALIDARG
},
1686 {&IID_IDirect3D2
, NULL
, E_INVALIDARG
},
1687 {&IID_IDirect3D
, NULL
, E_INVALIDARG
},
1688 {&IID_IDirectDraw7
, NULL
, E_INVALIDARG
},
1689 {&IID_IDirectDraw4
, NULL
, E_INVALIDARG
},
1690 {&IID_IDirectDraw3
, NULL
, E_INVALIDARG
},
1691 {&IID_IDirectDraw2
, NULL
, E_INVALIDARG
},
1692 {&IID_IDirectDraw
, NULL
, E_INVALIDARG
},
1693 {&IID_IDirect3DLight
, NULL
, E_INVALIDARG
},
1694 {&IID_IDirect3DMaterial
, NULL
, E_INVALIDARG
},
1695 {&IID_IDirect3DMaterial2
, NULL
, E_INVALIDARG
},
1696 {&IID_IDirect3DMaterial3
, NULL
, E_INVALIDARG
},
1697 {&IID_IDirect3DExecuteBuffer
, NULL
, E_INVALIDARG
},
1698 {&IID_IDirect3DViewport
, NULL
, E_INVALIDARG
},
1699 {&IID_IDirect3DViewport2
, NULL
, E_INVALIDARG
},
1700 {&IID_IDirect3DViewport3
, NULL
, E_INVALIDARG
},
1701 {&IID_IDirect3DVertexBuffer
, NULL
, E_INVALIDARG
},
1702 {&IID_IDirect3DVertexBuffer7
, NULL
, E_INVALIDARG
},
1703 {&IID_IDirectDrawPalette
, NULL
, E_INVALIDARG
},
1704 {&IID_IDirectDrawClipper
, NULL
, E_INVALIDARG
},
1705 {&IID_IUnknown
, &IID_IDirectDrawSurface
, S_OK
},
1708 IDirectDrawSurface4
*surface
;
1709 DDSURFACEDESC2 surface_desc
;
1710 IDirect3DDevice3
*device
;
1711 IDirectDraw4
*ddraw
;
1715 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
1717 win_skip("DirectDrawCreateEx not available, skipping test.\n");
1721 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1722 0, 0, 640, 480, 0, 0, 0, 0);
1723 /* Try to create a D3D device to see if the ddraw implementation supports
1724 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
1725 * doesn't support e.g. the IDirect3DTexture interfaces. */
1726 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1728 skip("Failed to create D3D device, skipping test.\n");
1729 DestroyWindow(window
);
1732 IDirect3DDevice_Release(device
);
1733 if (!(ddraw
= create_ddraw()))
1735 skip("Failed to create a ddraw object, skipping test.\n");
1736 DestroyWindow(window
);
1739 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
1740 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1742 memset(&surface_desc
, 0, sizeof(surface_desc
));
1743 surface_desc
.dwSize
= sizeof(surface_desc
);
1744 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1745 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1746 surface_desc
.dwWidth
= 512;
1747 surface_desc
.dwHeight
= 512;
1748 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1749 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1751 test_qi("surface_qi", (IUnknown
*)surface
, &IID_IDirectDrawSurface4
, tests
, sizeof(tests
) / sizeof(*tests
));
1753 IDirectDrawSurface4_Release(surface
);
1754 IDirectDraw4_Release(ddraw
);
1755 DestroyWindow(window
);
1760 test_process_vertices();
1761 test_coop_level_create_device_window();
1763 test_coop_level_d3d_state();
1764 test_surface_interface_mismatch();
1765 test_coop_level_threaded();
1767 test_texture_load_ckey();
1768 test_viewport_interfaces();