2 * Copyright 2011 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
19 #include "wine/test.h"
33 static BOOL compare_float(float f, float g, unsigned int ulps)
43 if (abs(x - y) > ulps)
49 static BOOL compare_vec4(struct vec4 *vec, float x, float y, float z, float w, unsigned int ulps)
51 return compare_float(vec->x, x, ulps)
52 && compare_float(vec->y, y, ulps)
53 && compare_float(vec->z, z, ulps)
54 && compare_float(vec->w, w, ulps);
57 static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
59 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
61 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
63 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
65 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
69 static D3DCOLOR get_surface_color(IDirectDrawSurface4 *surface, UINT x, UINT y)
71 RECT rect = {x, y, x + 1, y + 1};
72 DDSURFACEDESC2 surface_desc;
76 memset(&surface_desc, 0, sizeof(surface_desc));
77 surface_desc.dwSize = sizeof(surface_desc);
79 hr = IDirectDrawSurface4_Lock(surface, &rect, &surface_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
80 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
84 color = *((DWORD *)surface_desc.lpSurface) & 0x00ffffff;
86 hr = IDirectDrawSurface4_Unlock(surface, &rect);
87 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
92 static HRESULT CALLBACK enum_z_fmt(DDPIXELFORMAT *format, void *ctx)
94 DDPIXELFORMAT *z_fmt = ctx;
96 if (U1(*format).dwZBufferBitDepth > U1(*z_fmt).dwZBufferBitDepth)
102 static IDirectDraw4 *create_ddraw(void)
104 IDirectDraw4 *ddraw4;
108 if (FAILED(DirectDrawCreate(NULL, &ddraw1, NULL)))
111 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirectDraw4, (void **)&ddraw4);
112 IDirectDraw_Release(ddraw1);
119 static IDirect3DDevice3 *create_device(HWND window, DWORD coop_level)
121 IDirectDrawSurface4 *surface, *ds;
122 IDirect3DDevice3 *device = NULL;
123 DDSURFACEDESC2 surface_desc;
124 IDirectDraw4 *ddraw4;
129 if (!(ddraw4 = create_ddraw()))
132 hr = IDirectDraw4_SetCooperativeLevel(ddraw4, window, coop_level);
133 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
135 memset(&surface_desc, 0, sizeof(surface_desc));
136 surface_desc.dwSize = sizeof(surface_desc);
137 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
138 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
139 surface_desc.dwWidth = 640;
140 surface_desc.dwHeight = 480;
142 hr = IDirectDraw4_CreateSurface(ddraw4, &surface_desc, &surface, NULL);
143 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
145 if (coop_level & DDSCL_NORMAL)
147 IDirectDrawClipper *clipper;
149 hr = IDirectDraw4_CreateClipper(ddraw4, 0, &clipper, NULL);
150 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
151 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
152 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
153 hr = IDirectDrawSurface4_SetClipper(surface, clipper);
154 ok(SUCCEEDED(hr), "Failed to set surface clipper, hr %#x.\n", hr);
155 IDirectDrawClipper_Release(clipper);
158 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirect3D3, (void **)&d3d3);
159 IDirectDraw4_Release(ddraw4);
162 IDirectDrawSurface4_Release(surface);
166 memset(&z_fmt, 0, sizeof(z_fmt));
167 hr = IDirect3D3_EnumZBufferFormats(d3d3, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
168 if (FAILED(hr) || !z_fmt.dwSize)
170 IDirect3D3_Release(d3d3);
171 IDirectDrawSurface4_Release(surface);
175 memset(&surface_desc, 0, sizeof(surface_desc));
176 surface_desc.dwSize = sizeof(surface_desc);
177 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
178 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
179 U4(surface_desc).ddpfPixelFormat = z_fmt;
180 surface_desc.dwWidth = 640;
181 surface_desc.dwHeight = 480;
182 hr = IDirectDraw4_CreateSurface(ddraw4, &surface_desc, &ds, NULL);
183 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
186 IDirect3D3_Release(d3d3);
187 IDirectDrawSurface4_Release(surface);
191 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
192 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
193 IDirectDrawSurface4_Release(ds);
196 IDirect3D3_Release(d3d3);
197 IDirectDrawSurface4_Release(surface);
201 hr = IDirect3D3_CreateDevice(d3d3, &IID_IDirect3DHALDevice, surface, &device, NULL);
202 IDirect3D3_Release(d3d3);
203 IDirectDrawSurface4_Release(surface);
210 static void test_process_vertices(void)
212 IDirect3DVertexBuffer *src_vb, *dst_vb;
213 IDirect3DViewport3 *viewport;
214 D3DVERTEXBUFFERDESC vb_desc;
215 IDirect3DDevice3 *device;
216 struct vec3 *src_data;
217 struct vec4 *dst_data;
224 static D3DMATRIX identity =
226 1.0f, 0.0f, 0.0f, 0.0f,
227 0.0f, 1.0f, 0.0f, 0.0f,
228 0.0f, 0.0f, 1.0f, 0.0f,
229 0.0f, 0.0f, 0.0f, 1.0f,
231 static D3DMATRIX projection =
233 1.0f, 0.0f, 0.0f, 0.0f,
234 0.0f, 1.0f, 0.0f, 0.0f,
235 0.0f, 0.0f, 1.0f, 0.0f,
236 6.0f, 7.0f, 8.0f, 1.0f,
239 window = CreateWindowA("static", "d3d7_test", WS_OVERLAPPEDWINDOW,
240 0, 0, 640, 480, 0, 0, 0, 0);
241 if (!(device = create_device(window, DDSCL_NORMAL)))
243 skip("Failed to create a 3D device, skipping test.\n");
244 DestroyWindow(window);
248 hr = IDirect3DDevice3_GetDirect3D(device, &d3d3);
249 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#x.\n", hr);
251 memset(&vb_desc, 0, sizeof(vb_desc));
252 vb_desc.dwSize = sizeof(vb_desc);
253 vb_desc.dwFVF = D3DFVF_XYZ;
254 vb_desc.dwNumVertices = 3;
255 hr = IDirect3D3_CreateVertexBuffer(d3d3, &vb_desc, &src_vb, 0, NULL);
256 ok(SUCCEEDED(hr), "Failed to create source vertex buffer, hr %#x.\n", hr);
258 hr = IDirect3DVertexBuffer_Lock(src_vb, DDLOCK_WRITEONLY, (void **)&src_data, NULL);
259 ok(SUCCEEDED(hr), "Failed to lock source vertex buffer, hr %#x.\n", hr);
260 src_data[0].x = -1.0f;
261 src_data[0].y = -1.0f;
262 src_data[0].z = -1.0f;
263 src_data[1].x = 0.0f;
264 src_data[1].y = 0.0f;
265 src_data[1].z = 0.0f;
266 src_data[2].x = 1.0f;
267 src_data[2].y = 1.0f;
268 src_data[2].z = 1.0f;
269 hr = IDirect3DVertexBuffer_Unlock(src_vb);
270 ok(SUCCEEDED(hr), "Failed to unlock source vertex buffer, hr %#x.\n", hr);
272 memset(&vb_desc, 0, sizeof(vb_desc));
273 vb_desc.dwSize = sizeof(vb_desc);
274 vb_desc.dwFVF = D3DFVF_XYZRHW;
275 vb_desc.dwNumVertices = 3;
276 hr = IDirect3D3_CreateVertexBuffer(d3d3, &vb_desc, &dst_vb, 0, NULL);
277 ok(SUCCEEDED(hr), "Failed to create destination vertex buffer, hr %#x.\n", hr);
279 hr = IDirect3D3_CreateViewport(d3d3, &viewport, NULL);
280 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
281 hr = IDirect3DDevice3_AddViewport(device, viewport);
282 ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
283 vp2.dwSize = sizeof(vp2);
290 vp2.dvClipWidth = 4.0f;
291 vp2.dvClipHeight = 5.0f;
294 hr = IDirect3DViewport3_SetViewport2(viewport, &vp2);
295 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
296 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
297 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
299 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &identity);
300 ok(SUCCEEDED(hr), "Failed to set world transformation, hr %#x.\n", hr);
301 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &identity);
302 ok(SUCCEEDED(hr), "Failed to set view transformation, hr %#x.\n", hr);
303 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &identity);
304 ok(SUCCEEDED(hr), "Failed to set projection transformation, hr %#x.\n", hr);
306 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM, 0, 3, src_vb, 0, device, 0);
307 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
309 hr = IDirect3DVertexBuffer_Lock(dst_vb, DDLOCK_READONLY, (void **)&dst_data, NULL);
310 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
311 ok(compare_vec4(&dst_data[0], -6.500e+1f, +1.800e+2f, +2.000e-1f, +1.000e+0f, 4096),
312 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
313 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
314 ok(compare_vec4(&dst_data[1], -4.000e+1f, +1.400e+2f, +4.000e-1f, +1.000e+0f, 4096),
315 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
316 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
317 ok(compare_vec4(&dst_data[2], -1.500e+1f, +1.000e+2f, +6.000e-1f, +1.000e+0f, 4096),
318 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
319 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
320 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
321 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
323 hr = IDirect3DDevice3_MultiplyTransform(device, D3DTRANSFORMSTATE_PROJECTION, &projection);
324 ok(SUCCEEDED(hr), "Failed to set projection transformation, hr %#x.\n", hr);
326 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM, 0, 3, src_vb, 0, device, 0);
327 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
329 hr = IDirect3DVertexBuffer_Lock(dst_vb, DDLOCK_READONLY, (void **)&dst_data, NULL);
330 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
331 ok(compare_vec4(&dst_data[0], +8.500e+1f, -1.000e+2f, +1.800e+0f, +1.000e+0f, 4096),
332 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
333 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
334 ok(compare_vec4(&dst_data[1], +1.100e+2f, -1.400e+2f, +2.000e+0f, +1.000e+0f, 4096),
335 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
336 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
337 ok(compare_vec4(&dst_data[2], +1.350e+2f, -1.800e+2f, +2.200e+0f, +1.000e+0f, 4096),
338 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
339 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
340 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
341 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
343 vp2.dwSize = sizeof(vp2);
350 vp2.dvClipWidth = 2.0f;
351 vp2.dvClipHeight = 4.0f;
354 hr = IDirect3DViewport3_SetViewport2(viewport, &vp2);
355 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
357 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM, 0, 3, src_vb, 0, device, 0);
358 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
360 hr = IDirect3DVertexBuffer_Lock(dst_vb, DDLOCK_READONLY, (void **)&dst_data, NULL);
361 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
362 ok(compare_vec4(&dst_data[0], +7.500e+1f, +4.000e+1f, -8.000e-1f, +1.000e+0f, 4096),
363 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
364 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
365 ok(compare_vec4(&dst_data[1], +1.200e+2f, +2.000e+1f, -1.000e+0f, +1.000e+0f, 4096),
366 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
367 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
368 ok(compare_vec4(&dst_data[2], +1.650e+2f, +0.000e+0f, -1.200e+0f, +1.000e+0f, 4096),
369 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
370 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
371 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
372 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
374 vp1.dwSize = sizeof(vp1);
385 hr = IDirect3DViewport3_SetViewport(viewport, &vp1);
386 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
388 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM, 0, 3, src_vb, 0, device, 0);
389 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
391 hr = IDirect3DVertexBuffer_Lock(dst_vb, DDLOCK_READONLY, (void **)&dst_data, NULL);
392 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
393 ok(compare_vec4(&dst_data[0], +1.100e+2f, +6.800e+1f, +7.000e+0f, +1.000e+0f, 4096),
394 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
395 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
396 ok(compare_vec4(&dst_data[1], +1.170e+2f, +6.600e+1f, +8.000e+0f, +1.000e+0f, 4096),
397 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
398 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
399 ok(compare_vec4(&dst_data[2], +1.240e+2f, +6.400e+1f, +9.000e+0f, +1.000e+0f, 4096),
400 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
401 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
402 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
403 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
405 hr = IDirect3DDevice3_DeleteViewport(device, viewport);
406 ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
408 IDirect3DVertexBuffer_Release(dst_vb);
409 IDirect3DVertexBuffer_Release(src_vb);
410 IDirect3DViewport3_Release(viewport);
411 IDirect3D3_Release(d3d3);
412 IDirect3DDevice3_Release(device);
413 DestroyWindow(window);
416 static void test_coop_level_create_device_window(void)
418 HWND focus_window, device_window;
422 focus_window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
423 0, 0, 640, 480, 0, 0, 0, 0);
424 if (!(ddraw = create_ddraw()))
426 skip("Failed to create a ddraw object, skipping test.\n");
427 DestroyWindow(focus_window);
431 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
432 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
433 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
434 ok(!device_window, "Unexpected device window found.\n");
435 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW);
436 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
437 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
438 ok(!device_window, "Unexpected device window found.\n");
439 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL);
440 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
441 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
442 ok(!device_window, "Unexpected device window found.\n");
443 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL | DDSCL_FULLSCREEN);
444 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
445 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
446 ok(!device_window, "Unexpected device window found.\n");
447 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
448 ok(hr == DDERR_NOFOCUSWINDOW || broken(hr == DDERR_INVALIDPARAMS), "Got unexpected hr %#x.\n", hr);
449 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
450 ok(!device_window, "Unexpected device window found.\n");
452 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
453 if (broken(hr == DDERR_INVALIDPARAMS))
455 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
456 IDirectDraw4_Release(ddraw);
457 DestroyWindow(focus_window);
461 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
462 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
463 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
464 ok(!device_window, "Unexpected device window found.\n");
465 hr = IDirectDraw4_SetCooperativeLevel(ddraw, focus_window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
466 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
467 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
468 ok(!device_window, "Unexpected device window found.\n");
470 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
471 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
472 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
473 ok(!device_window, "Unexpected device window found.\n");
474 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_SETFOCUSWINDOW
475 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
476 ok(hr == DDERR_NOHWND, "Got unexpected hr %#x.\n", hr);
477 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
478 ok(!!device_window, "Device window not found.\n");
480 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
481 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
482 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
483 ok(!device_window, "Unexpected device window found.\n");
484 hr = IDirectDraw4_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW
485 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
486 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
487 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
488 ok(!!device_window, "Device window not found.\n");
490 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
491 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
492 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
493 ok(!device_window, "Unexpected device window found.\n");
494 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
495 ok(hr == DDERR_NOFOCUSWINDOW, "Got unexpected hr %#x.\n", hr);
496 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
497 ok(!device_window, "Unexpected device window found.\n");
498 hr = IDirectDraw4_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW);
499 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
500 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
501 ok(!device_window, "Unexpected device window found.\n");
502 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
503 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
504 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
505 ok(!!device_window, "Device window not found.\n");
507 IDirectDraw4_Release(ddraw);
508 DestroyWindow(focus_window);
511 static void test_clipper_blt(void)
513 IDirectDrawSurface4 *src_surface, *dst_surface;
514 RECT client_rect, src_rect, *rect;
515 IDirectDrawClipper *clipper;
516 DDSURFACEDESC2 surface_desc;
517 unsigned int i, j, x, y;
528 static const DWORD src_data[] =
530 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
531 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
532 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
534 static const D3DCOLOR expected1[] =
536 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
537 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
538 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
539 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
541 static const D3DCOLOR expected2[] =
543 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
544 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
545 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
546 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
549 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
550 10, 10, 640, 480, 0, 0, 0, 0);
551 ShowWindow(window, SW_SHOW);
552 if (!(ddraw = create_ddraw()))
554 skip("Failed to create a ddraw object, skipping test.\n");
555 DestroyWindow(window);
559 ret = GetClientRect(window, &client_rect);
560 ok(ret, "Failed to get client rect.\n");
561 ret = MapWindowPoints(window, NULL, (POINT *)&client_rect, 2);
562 ok(ret, "Failed to map client rect.\n");
564 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
565 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
567 hr = IDirectDraw4_CreateClipper(ddraw, 0, &clipper, NULL);
568 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
569 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
570 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
571 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
572 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
573 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
574 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
575 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
576 hr = IDirectDrawClipper_GetClipList(clipper, NULL, rgn_data, &ret);
577 ok(SUCCEEDED(hr), "Failed to get clip list, hr %#x.\n", hr);
578 ok(rgn_data->rdh.dwSize == sizeof(rgn_data->rdh), "Got unexpected structure size %#x.\n", rgn_data->rdh.dwSize);
579 ok(rgn_data->rdh.iType == RDH_RECTANGLES, "Got unexpected type %#x.\n", rgn_data->rdh.iType);
580 ok(rgn_data->rdh.nCount == 1, "Got unexpected count %u.\n", rgn_data->rdh.nCount);
581 ok(rgn_data->rdh.nRgnSize == 16, "Got unexpected region size %u.\n", rgn_data->rdh.nRgnSize);
582 ok(EqualRect(&rgn_data->rdh.rcBound, &client_rect),
583 "Got unexpected bounding rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
584 rgn_data->rdh.rcBound.left, rgn_data->rdh.rcBound.top,
585 rgn_data->rdh.rcBound.right, rgn_data->rdh.rcBound.bottom,
586 client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
587 rect = (RECT *)&rgn_data->Buffer[0];
588 ok(EqualRect(rect, &client_rect),
589 "Got unexpected clip rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
590 rect->left, rect->top, rect->right, rect->bottom,
591 client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
592 HeapFree(GetProcessHeap(), 0, rgn_data);
594 r1 = CreateRectRgn(0, 0, 320, 240);
595 ok(!!r1, "Failed to create region.\n");
596 r2 = CreateRectRgn(320, 240, 640, 480);
597 ok(!!r2, "Failed to create region.\n");
598 CombineRgn(r1, r1, r2, RGN_OR);
599 ret = GetRegionData(r1, 0, NULL);
600 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
601 ret = GetRegionData(r1, ret, rgn_data);
602 ok(!!ret, "Failed to get region data.\n");
607 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
608 ok(hr == DDERR_CLIPPERISUSINGHWND, "Got unexpected hr %#x.\n", hr);
609 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
610 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
611 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
612 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
614 HeapFree(GetProcessHeap(), 0, rgn_data);
616 memset(&surface_desc, 0, sizeof(surface_desc));
617 surface_desc.dwSize = sizeof(surface_desc);
618 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
619 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
620 surface_desc.dwWidth = 640;
621 surface_desc.dwHeight = 480;
622 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
623 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
624 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
625 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
626 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
627 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
629 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &src_surface, NULL);
630 ok(SUCCEEDED(hr), "Failed to create source surface, hr %#x.\n", hr);
631 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL);
632 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
634 memset(&fx, 0, sizeof(fx));
635 fx.dwSize = sizeof(fx);
636 hr = IDirectDrawSurface4_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
637 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
638 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
639 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
641 hr = IDirectDrawSurface4_Lock(src_surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
642 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
643 ok(U1(surface_desc).lPitch == 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc).lPitch);
644 ptr = surface_desc.lpSurface;
645 memcpy(&ptr[ 0], &src_data[ 0], 6 * sizeof(DWORD));
646 memcpy(&ptr[ 640], &src_data[ 6], 6 * sizeof(DWORD));
647 memcpy(&ptr[1280], &src_data[12], 6 * sizeof(DWORD));
648 hr = IDirectDrawSurface4_Unlock(src_surface, NULL);
649 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
651 hr = IDirectDrawSurface4_SetClipper(dst_surface, clipper);
652 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
654 SetRect(&src_rect, 1, 1, 5, 2);
655 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, src_surface, &src_rect, DDBLT_WAIT, NULL);
656 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
657 for (i = 0; i < 4; ++i)
659 for (j = 0; j < 4; ++j)
661 x = 80 * ((2 * j) + 1);
662 y = 60 * ((2 * i) + 1);
663 color = get_surface_color(dst_surface, x, y);
664 ok(compare_color(color, expected1[i * 4 + j], 1),
665 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1[i * 4 + j], x, y, color);
669 U5(fx).dwFillColor = 0xff0000ff;
670 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
671 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
672 for (i = 0; i < 4; ++i)
674 for (j = 0; j < 4; ++j)
676 x = 80 * ((2 * j) + 1);
677 y = 60 * ((2 * i) + 1);
678 color = get_surface_color(dst_surface, x, y);
679 ok(compare_color(color, expected2[i * 4 + j], 1),
680 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2[i * 4 + j], x, y, color);
684 hr = IDirectDrawSurface4_BltFast(dst_surface, 0, 0, src_surface, NULL, DDBLTFAST_WAIT);
685 ok(hr == DDERR_BLTFASTCANTCLIP, "Got unexpected hr %#x.\n", hr);
687 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
688 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
689 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
690 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
691 DestroyWindow(window);
692 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
693 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
694 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
695 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
696 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
697 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
698 hr = IDirectDrawClipper_SetClipList(clipper, NULL, 0);
699 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
700 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
701 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
702 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
703 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
705 IDirectDrawSurface4_Release(dst_surface);
706 IDirectDrawSurface4_Release(src_surface);
707 IDirectDrawClipper_Release(clipper);
708 IDirectDraw4_Release(ddraw);
711 static void test_coop_level_d3d_state(void)
713 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
714 IDirectDrawSurface4 *rt, *surface;
715 IDirect3DViewport3 *viewport;
716 IDirect3DDevice3 *device;
725 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
726 0, 0, 640, 480, 0, 0, 0, 0);
727 if (!(device = create_device(window, DDSCL_NORMAL)))
729 skip("Failed to create D3D device, skipping test.\n");
730 DestroyWindow(window);
734 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
735 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
737 hr = IDirect3D3_CreateViewport(d3d, &viewport, NULL);
738 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
739 hr = IDirect3DDevice3_AddViewport(device, viewport);
740 ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
741 memset(&vp, 0, sizeof(vp));
742 vp.dwSize = sizeof(vp);
749 vp.dvClipWidth = 2.0f;
750 vp.dvClipHeight = 2.0f;
753 hr = IDirect3DViewport3_SetViewport2(viewport, &vp);
754 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
756 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
757 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
758 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
759 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
760 ok(!!value, "Got unexpected z-enable state %#x.\n", value);
761 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
762 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
763 ok(!value, "Got unexpected alpha blend enable state %#x.\n", value);
764 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
765 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
766 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
767 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
768 color = get_surface_color(rt, 320, 240);
769 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
771 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
772 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
773 IDirect3D3_Release(d3d);
774 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
775 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
776 hr = IDirectDrawSurface4_IsLost(rt);
777 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
778 hr = IDirectDraw4_RestoreAllSurfaces(ddraw);
779 ok(SUCCEEDED(hr), "Failed to restore surfaces, hr %#x.\n", hr);
780 IDirectDraw4_Release(ddraw);
782 hr = IDirect3DDevice3_GetRenderTarget(device, &surface);
783 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
784 ok(surface == rt, "Got unexpected surface %p.\n", surface);
785 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
786 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
787 ok(!!value, "Got unexpected z-enable state %#x.\n", value);
788 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
789 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
790 ok(!!value, "Got unexpected alpha blend enable state %#x.\n", value);
791 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
792 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
793 color = get_surface_color(rt, 320, 240);
794 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
796 hr = IDirect3DDevice3_DeleteViewport(device, viewport);
797 ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
798 IDirect3DViewport3_Release(viewport);
799 IDirectDrawSurface4_Release(surface);
800 IDirectDrawSurface4_Release(rt);
801 IDirect3DDevice3_Release(device);
802 DestroyWindow(window);
805 static void test_surface_interface_mismatch(void)
807 IDirectDraw4 *ddraw = NULL;
808 IDirect3D3 *d3d = NULL;
809 IDirectDrawSurface4 *surface = NULL, *ds;
810 IDirectDrawSurface3 *surface3 = NULL;
811 IDirect3DDevice3 *device = NULL;
812 IDirect3DViewport3 *viewport = NULL;
813 DDSURFACEDESC2 surface_desc;
819 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
821 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
822 0, 0, 640, 480, 0, 0, 0, 0);
824 if (!(ddraw = create_ddraw()))
826 skip("Failed to create a ddraw object, skipping test.\n");
830 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
831 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
833 memset(&surface_desc, 0, sizeof(surface_desc));
834 surface_desc.dwSize = sizeof(surface_desc);
835 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
836 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
837 surface_desc.dwWidth = 640;
838 surface_desc.dwHeight = 480;
840 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
841 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
843 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirectDrawSurface3, (void **)&surface3);
844 ok(SUCCEEDED(hr), "Failed to QI IDirectDrawSurface3, hr %#x.\n", hr);
846 hr = IDirectDraw4_QueryInterface(ddraw, &IID_IDirect3D3, (void **)&d3d);
849 skip("Failed to get the IDirect3D7 interface, skipping test.\n");
853 memset(&z_fmt, 0, sizeof(z_fmt));
854 hr = IDirect3D3_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
855 if (FAILED(hr) || !z_fmt.dwSize)
857 skip("No depth buffer formats available, skipping test.\n");
861 memset(&surface_desc, 0, sizeof(surface_desc));
862 surface_desc.dwSize = sizeof(surface_desc);
863 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
864 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
865 U4(surface_desc).ddpfPixelFormat = z_fmt;
866 surface_desc.dwWidth = 640;
867 surface_desc.dwHeight = 480;
868 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &ds, NULL);
869 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
873 /* Using a different surface interface version still works */
874 hr = IDirectDrawSurface3_AddAttachedSurface(surface3, (IDirectDrawSurface3 *)ds);
875 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
876 IDirectDrawSurface4_Release(ds);
881 hr = IDirect3D3_CreateDevice(d3d, &IID_IDirect3DHALDevice, (IDirectDrawSurface4 *)surface3, &device, NULL);
882 ok(SUCCEEDED(hr), "Failed to create d3d device.\n");
886 hr = IDirect3D3_CreateViewport(d3d, &viewport, NULL);
887 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
888 hr = IDirect3DDevice3_AddViewport(device, viewport);
889 ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
890 memset(&vp, 0, sizeof(vp));
891 vp.dwSize = sizeof(vp);
898 vp.dvClipWidth = 2.0f;
899 vp.dvClipHeight = 2.0f;
902 hr = IDirect3DViewport3_SetViewport2(viewport, &vp);
903 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
905 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
906 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
907 color = get_surface_color(surface, 320, 240);
908 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
913 IDirect3DDevice2_DeleteViewport(device, viewport);
914 IDirect3DViewport2_Release(viewport);
916 if (surface3) IDirectDrawSurface3_Release(surface3);
917 if (surface) IDirectDrawSurface4_Release(surface);
918 if (device) IDirect3DDevice3_Release(device);
919 if (d3d) IDirect3D3_Release(d3d);
920 if (ddraw) IDirectDraw4_Release(ddraw);
921 DestroyWindow(window);
926 test_process_vertices();
927 test_coop_level_create_device_window();
929 test_coop_level_d3d_state();
930 test_surface_interface_mismatch();