msvcrt: Move btowc implementation to mbcs.c file.
[wine.git] / dlls / ddraw / tests / visual.c
blob4d6b198e3238dc3817385fa64adc9c6baca9eeb4
1 /*
2 * Copyright (C) 2007 Stefan Dösinger(for CodeWeavers)
3 * Copyright (C) 2008 Alexander Dorofeyev
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 /* See comment in dlls/d3d9/tests/visual.c for general guidelines */
22 #include "wine/test.h"
23 #include "ddraw.h"
24 #include "d3d.h"
26 struct vec3
28 float x, y, z;
31 struct vec4
33 float x, y, z, w;
36 static HWND window;
37 static IDirectDraw7 *DirectDraw;
38 static IDirectDrawSurface7 *Surface;
39 static IDirectDrawSurface7 *depth_buffer;
40 static IDirect3D7 *Direct3D;
41 static IDirect3DDevice7 *Direct3DDevice;
43 static BOOL refdevice = FALSE;
45 static HRESULT (WINAPI *pDirectDrawCreateEx)(GUID *driver_guid,
46 void **ddraw, REFIID interface_iid, IUnknown *outer);
48 static BOOL compare_uint(unsigned int x, unsigned int y, unsigned int max_diff)
50 unsigned int diff = x > y ? x - y : y - x;
52 return diff <= max_diff;
55 static BOOL color_match(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
57 return compare_uint(c1 & 0xff, c2 & 0xff, max_diff)
58 && compare_uint((c1 >> 8) & 0xff, (c2 >> 8) & 0xff, max_diff)
59 && compare_uint((c1 >> 16) & 0xff, (c2 >> 16) & 0xff, max_diff)
60 && compare_uint((c1 >> 24) & 0xff, (c2 >> 24) & 0xff, max_diff);
63 static HRESULT WINAPI enum_z_fmt(DDPIXELFORMAT *fmt, void *ctx)
65 DDPIXELFORMAT *zfmt = ctx;
67 if(U1(*fmt).dwZBufferBitDepth > U1(*zfmt).dwZBufferBitDepth)
69 *zfmt = *fmt;
71 return DDENUMRET_OK;
74 static HRESULT WINAPI enum_devtype_cb(char *desc_str, char *name, D3DDEVICEDESC7 *desc, void *ctx)
76 BOOL *hal_ok = ctx;
77 if (IsEqualGUID(&desc->deviceGUID, &IID_IDirect3DTnLHalDevice))
79 *hal_ok = TRUE;
80 return DDENUMRET_CANCEL;
82 return DDENUMRET_OK;
85 static BOOL createObjects(void)
87 HRESULT hr;
88 HMODULE hmod = GetModuleHandleA("ddraw.dll");
89 WNDCLASSA wc = {0};
90 DDSURFACEDESC2 ddsd;
91 DDPIXELFORMAT zfmt;
92 BOOL hal_ok = FALSE;
93 const GUID *devtype = &IID_IDirect3DHALDevice;
95 if(!hmod) return FALSE;
96 pDirectDrawCreateEx = (void*)GetProcAddress(hmod, "DirectDrawCreateEx");
97 if(!pDirectDrawCreateEx) return FALSE;
99 hr = pDirectDrawCreateEx(NULL, (void **) &DirectDraw, &IID_IDirectDraw7, NULL);
100 ok(hr==DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", hr);
101 if(!DirectDraw) goto err;
103 wc.lpfnWndProc = DefWindowProcA;
104 wc.lpszClassName = "d3d7_test_wc";
105 RegisterClassA(&wc);
106 window = CreateWindowA("d3d7_test_wc", "d3d7_test", WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION,
107 0, 0, 640, 480, 0, 0, 0, 0);
109 hr = IDirectDraw7_SetCooperativeLevel(DirectDraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
110 ok(hr == DD_OK, "IDirectDraw7_SetCooperativeLevel failed with %08x\n", hr);
111 if(FAILED(hr)) goto err;
112 hr = IDirectDraw7_SetDisplayMode(DirectDraw, 640, 480, 32, 0, 0);
113 if(FAILED(hr)) {
114 /* 24 bit is fine too */
115 hr = IDirectDraw7_SetDisplayMode(DirectDraw, 640, 480, 24, 0, 0);
118 ok(hr == DD_OK || hr == DDERR_UNSUPPORTED, "IDirectDraw7_SetDisplayMode failed with %08x\n", hr);
119 if(FAILED(hr)) {
120 /* use trace, the caller calls skip() */
121 trace("SetDisplayMode failed\n");
122 goto err;
125 hr = IDirectDraw7_QueryInterface(DirectDraw, &IID_IDirect3D7, (void**) &Direct3D);
126 if (hr == E_NOINTERFACE) goto err;
127 ok(hr==DD_OK, "QueryInterface returned: %08x\n", hr);
129 /* DirectDraw Flipping behavior doesn't seem that well-defined. The reference rasterizer behaves differently
130 * than hardware implementations. Request single buffering, that seems to work everywhere
132 memset(&ddsd, 0, sizeof(ddsd));
133 ddsd.dwSize = sizeof(ddsd);
134 ddsd.dwFlags = DDSD_CAPS;
135 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE;
136 U5(ddsd).dwBackBufferCount = 1;
137 hr = IDirectDraw7_CreateSurface(DirectDraw, &ddsd, &Surface, NULL);
138 if(FAILED(hr)) goto err;
140 hr = IDirect3D7_EnumDevices(Direct3D, enum_devtype_cb, &hal_ok);
141 ok(SUCCEEDED(hr), "Failed to enumerate devices, hr %#x.\n", hr);
142 if (hal_ok) devtype = &IID_IDirect3DTnLHalDevice;
144 memset(&zfmt, 0, sizeof(zfmt));
145 hr = IDirect3D7_EnumZBufferFormats(Direct3D, devtype, enum_z_fmt, &zfmt);
146 if (FAILED(hr)) goto err;
147 if (zfmt.dwSize == 0) goto err;
149 memset(&ddsd, 0, sizeof(ddsd));
150 ddsd.dwSize = sizeof(ddsd);
151 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
152 ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
153 U4(ddsd).ddpfPixelFormat = zfmt;
154 ddsd.dwWidth = 640;
155 ddsd.dwHeight = 480;
156 hr = IDirectDraw7_CreateSurface(DirectDraw, &ddsd, &depth_buffer, NULL);
157 ok(SUCCEEDED(hr), "CreateSurface failed, hr %#x.\n", hr);
158 if (FAILED(hr)) goto err;
160 hr = IDirectDrawSurface_AddAttachedSurface(Surface, depth_buffer);
161 ok(SUCCEEDED(hr), "AddAttachedSurface failed, hr %#x.\n", hr);
162 if (FAILED(hr)) goto err;
164 hr = IDirect3D7_CreateDevice(Direct3D, devtype, Surface, &Direct3DDevice);
165 if (FAILED(hr) || !Direct3DDevice) goto err;
166 return TRUE;
168 err:
169 if(DirectDraw) IDirectDraw7_Release(DirectDraw);
170 if (depth_buffer) IDirectDrawSurface7_Release(depth_buffer);
171 if(Surface) IDirectDrawSurface7_Release(Surface);
172 if(Direct3D) IDirect3D7_Release(Direct3D);
173 if(Direct3DDevice) IDirect3DDevice7_Release(Direct3DDevice);
174 if(window) DestroyWindow(window);
175 return FALSE;
178 static void releaseObjects(void)
180 IDirect3DDevice7_Release(Direct3DDevice);
181 IDirect3D7_Release(Direct3D);
182 IDirectDrawSurface7_Release(depth_buffer);
183 IDirectDrawSurface7_Release(Surface);
184 IDirectDraw7_Release(DirectDraw);
185 DestroyWindow(window);
188 static DWORD getPixelColor(IDirect3DDevice7 *device, UINT x, UINT y)
190 DWORD ret;
191 HRESULT hr;
192 DDSURFACEDESC2 ddsd;
193 RECT rectToLock = {x, y, x+1, y+1};
194 IDirectDrawSurface7 *surf = NULL;
196 /* Some implementations seem to dislike direct locking on the front buffer. Thus copy the front buffer
197 * to an offscreen surface and lock it instead of the front buffer
199 memset(&ddsd, 0, sizeof(ddsd));
200 ddsd.dwSize = sizeof(ddsd);
201 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
202 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
203 ddsd.dwWidth = 640;
204 ddsd.dwHeight = 480;
205 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
206 hr = IDirectDraw7_CreateSurface(DirectDraw, &ddsd, &surf, NULL);
207 ok(hr == DD_OK, "IDirectDraw7_CreateSurface failed with %08x\n", hr);
208 if(!surf)
210 trace("cannot create helper surface\n");
211 return 0xdeadbeef;
214 memset(&ddsd, 0, sizeof(ddsd));
215 ddsd.dwSize = sizeof(ddsd);
216 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
218 hr = IDirectDrawSurface_BltFast(surf, 0, 0, Surface, NULL, 0);
219 ok(hr == DD_OK, "IDirectDrawSurface7_BltFast returned %08x\n", hr);
220 if(FAILED(hr))
222 trace("Cannot blit\n");
223 ret = 0xdeadbee;
224 goto out;
227 hr = IDirectDrawSurface7_Lock(surf, &rectToLock, &ddsd, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
228 if(FAILED(hr))
230 trace("Can't lock the offscreen surface, hr=%08x\n", hr);
231 ret = 0xdeadbeec;
232 goto out;
235 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
236 * really important for these tests
238 ret = ((DWORD *) ddsd.lpSurface)[0] & 0x00ffffff;
239 hr = IDirectDrawSurface7_Unlock(surf, NULL);
240 if(FAILED(hr))
242 trace("Can't unlock the offscreen surface, hr=%08x\n", hr);
245 out:
246 IDirectDrawSurface7_Release(surf);
247 return ret;
250 static void set_viewport_size(IDirect3DDevice7 *device)
252 D3DVIEWPORT7 vp = {0};
253 DDSURFACEDESC2 ddsd;
254 HRESULT hr;
255 IDirectDrawSurface7 *target;
257 hr = IDirect3DDevice7_GetRenderTarget(device, &target);
258 ok(hr == D3D_OK, "IDirect3DDevice7_GetRenderTarget returned %08x\n", hr);
260 memset(&ddsd, 0, sizeof(ddsd));
261 ddsd.dwSize = sizeof(ddsd);
262 hr = IDirectDrawSurface7_GetSurfaceDesc(target, &ddsd);
263 ok(hr == D3D_OK, "IDirectDrawSurface7_GetSurfaceDesc returned %08x\n", hr);
264 IDirectDrawSurface7_Release(target);
266 vp.dwWidth = ddsd.dwWidth;
267 vp.dwHeight = ddsd.dwHeight;
268 hr = IDirect3DDevice7_SetViewport(device, &vp);
269 ok(hr == D3D_OK, "IDirect3DDevice7_SetViewport returned %08x\n", hr);
270 return;
273 static void fog_test(IDirect3DDevice7 *device)
275 HRESULT hr;
276 DWORD color;
277 float start = 0.0, end = 1.0;
278 D3DDEVICEDESC7 caps;
280 struct
282 struct vec3 position;
283 DWORD diffuse;
284 DWORD specular;
286 /* Gets full z based fog with linear fog, no fog with specular color */
287 untransformed_1[] =
289 {{-1.0f, -1.0f, 0.1f}, 0xffff0000, 0xff000000},
290 {{-1.0f, 0.0f, 0.1f}, 0xffff0000, 0xff000000},
291 {{ 0.0f, 0.0f, 0.1f}, 0xffff0000, 0xff000000},
292 {{ 0.0f, -1.0f, 0.1f}, 0xffff0000, 0xff000000},
294 /* Ok, I am too lazy to deal with transform matrices */
295 untransformed_2[] =
297 {{-1.0f, 0.0f, 1.0f}, 0xffff0000, 0xff000000},
298 {{-1.0f, 1.0f, 1.0f}, 0xffff0000, 0xff000000},
299 {{ 0.0f, 1.0f, 1.0f}, 0xffff0000, 0xff000000},
300 {{ 0.0f, 0.0f, 1.0f}, 0xffff0000, 0xff000000},
302 far_quad1[] =
304 {{-1.0f, -1.0f, 0.5f}, 0xffff0000, 0xff000000},
305 {{-1.0f, 0.0f, 0.5f}, 0xffff0000, 0xff000000},
306 {{ 0.0f, 0.0f, 0.5f}, 0xffff0000, 0xff000000},
307 {{ 0.0f, -1.0f, 0.5f}, 0xffff0000, 0xff000000},
309 far_quad2[] =
311 {{-1.0f, 0.0f, 1.5f}, 0xffff0000, 0xff000000},
312 {{-1.0f, 1.0f, 1.5f}, 0xffff0000, 0xff000000},
313 {{ 0.0f, 1.0f, 1.5f}, 0xffff0000, 0xff000000},
314 {{ 0.0f, 0.0f, 1.5f}, 0xffff0000, 0xff000000},
316 /* Untransformed ones. Give them a different diffuse color to make the
317 * test look nicer. It also helps making sure that they are drawn
318 * correctly. */
319 struct
321 struct vec4 position;
322 DWORD diffuse;
323 DWORD specular;
325 transformed_1[] =
327 {{320.0f, 0.0f, 1.0f, 1.0f}, 0xffffff00, 0xff000000},
328 {{640.0f, 0.0f, 1.0f, 1.0f}, 0xffffff00, 0xff000000},
329 {{640.0f, 240.0f, 1.0f, 1.0f}, 0xffffff00, 0xff000000},
330 {{320.0f, 240.0f, 1.0f, 1.0f}, 0xffffff00, 0xff000000},
332 transformed_2[] =
334 {{320.0f, 240.0f, 1.0f, 1.0f}, 0xffffff00, 0xff000000},
335 {{640.0f, 240.0f, 1.0f, 1.0f}, 0xffffff00, 0xff000000},
336 {{640.0f, 480.0f, 1.0f, 1.0f}, 0xffffff00, 0xff000000},
337 {{320.0f, 480.0f, 1.0f, 1.0f}, 0xffffff00, 0xff000000},
339 WORD Indices[] = {0, 1, 2, 2, 3, 0};
340 D3DMATRIX ident_mat =
342 1.0f, 0.0f, 0.0f, 0.0f,
343 0.0f, 1.0f, 0.0f, 0.0f,
344 0.0f, 0.0f, 1.0f, 0.0f,
345 0.0f, 0.0f, 0.0f, 1.0f,
347 D3DMATRIX world_mat1 =
349 1.0f, 0.0f, 0.0f, 0.0f,
350 0.0f, 1.0f, 0.0f, 0.0f,
351 0.0f, 0.0f, 1.0f, 0.0f,
352 0.0f, 0.0f, -0.5f, 1.0f,
354 D3DMATRIX world_mat2 =
356 1.0f, 0.0f, 0.0f, 0.0f,
357 0.0f, 1.0f, 0.0f, 0.0f,
358 0.0f, 0.0f, 1.0f, 0.0f,
359 0.0f, 0.0f, 1.0f, 1.0f,
361 D3DMATRIX proj_mat =
363 1.0f, 0.0f, 0.0f, 0.0f,
364 0.0f, 1.0f, 0.0f, 0.0f,
365 0.0f, 0.0f, 1.0f, 0.0f,
366 0.0f, 0.0f, -1.0f, 1.0f,
369 memset(&caps, 0, sizeof(caps));
370 hr = IDirect3DDevice7_GetCaps(device, &caps);
371 ok(hr == D3D_OK, "IDirect3DDevice7_GetCaps returned %08x\n", hr);
372 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
373 ok(hr == D3D_OK, "IDirect3DDevice7_Clear returned %08x\n", hr);
375 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
376 ok(SUCCEEDED(hr), "Failed to disable z test, hr %#x.\n", hr);
377 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
378 ok(SUCCEEDED(hr), "Failed to disable culling, hr %#x.\n", hr);
379 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
380 ok(hr == D3D_OK, "Turning off lighting returned %08x\n", hr);
381 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
382 ok(hr == D3D_OK, "Turning on fog calculations returned %08x\n", hr);
383 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0xFF00FF00 /* A nice green */);
384 ok(hr == D3D_OK, "Setting fog color returned %08x\n", hr);
386 /* First test: Both table fog and vertex fog off */
387 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, D3DFOG_NONE);
388 ok(hr == D3D_OK, "Turning off table fog returned %08x\n", hr);
389 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, D3DFOG_NONE);
390 ok(hr == D3D_OK, "Turning off vertex fog returned %08x\n", hr);
392 /* Start = 0, end = 1. Should be default, but set them */
393 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGSTART, *((DWORD *) &start));
394 ok(hr == D3D_OK, "Setting fog start returned %08x\n", hr);
395 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGEND, *((DWORD *) &end));
396 ok(hr == D3D_OK, "Setting fog end returned %08x\n", hr);
398 if(IDirect3DDevice7_BeginScene(device) == D3D_OK)
400 /* Untransformed, vertex fog = NONE, table fog = NONE: Read the fog weighting from the specular color */
401 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR,
402 untransformed_1, 4, Indices, 6, 0);
403 ok(hr == D3D_OK, "DrawIndexedPrimitive returned %08x\n", hr);
405 /* That makes it use the Z value */
406 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, D3DFOG_LINEAR);
407 ok(hr == D3D_OK, "Setting fog vertex mode to D3DFOG_LINEAR returned %08x\n", hr);
408 /* Untransformed, vertex fog != none (or table fog != none):
409 * Use the Z value as input into the equation
411 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR,
412 untransformed_2, 4, Indices, 6, 0);
413 ok(hr == D3D_OK, "DrawIndexedPrimitive returned %08x\n", hr);
415 /* Transformed, vertex fog != NONE, pixel fog == NONE: Use specular color alpha component */
416 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR,
417 transformed_1, 4, Indices, 6, 0);
418 ok(hr == D3D_OK, "DrawIndexedPrimitive returned %08x\n", hr);
420 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, D3DFOG_LINEAR);
421 ok( hr == D3D_OK, "Setting fog table mode to D3DFOG_LINEAR returned %08x\n", hr);
422 /* Transformed, table fog != none, vertex anything: Use Z value as input to the fog
423 * equation
425 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR,
426 transformed_2, 4, Indices, 6, 0);
427 ok(hr == D3D_OK, "DrawIndexedPrimitive returned %08x\n", hr);
429 hr = IDirect3DDevice7_EndScene(device);
430 ok(hr == D3D_OK, "EndScene returned %08x\n", hr);
432 else
434 ok(FALSE, "BeginScene failed\n");
437 color = getPixelColor(device, 160, 360);
438 ok(color_match(color, 0x00FF0000, 1), "Untransformed vertex with no table or vertex fog has color %08x\n", color);
439 color = getPixelColor(device, 160, 120);
440 ok(color_match(color, 0x0000FF00, 1), "Untransformed vertex with linear vertex fog has color %08x\n", color);
441 color = getPixelColor(device, 480, 120);
442 ok(color_match(color, 0x00FFFF00, 1), "Transformed vertex with linear vertex fog has color %08x\n", color);
443 if(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE)
445 color = getPixelColor(device, 480, 360);
446 ok(color_match(color, 0x0000FF00, 1), "Transformed vertex with linear table fog has color %08x\n", color);
448 else
450 /* Without fog table support the vertex fog is still applied, even though table fog is turned on.
451 * The settings above result in no fogging with vertex fog
453 color = getPixelColor(device, 480, 120);
454 ok(color == 0x00FFFF00, "Transformed vertex with linear vertex fog has color %08x\n", color);
455 trace("Info: Table fog not supported by this device\n");
458 if (caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE)
460 /* A simple fog + non-identity world matrix test */
461 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &world_mat1);
462 ok(hr == D3D_OK, "IDirect3DDevice7_SetTransform returned %#08x\n", hr);
464 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, D3DFOG_LINEAR);
465 ok(hr == D3D_OK, "Setting fog table mode to D3DFOG_LINEAR returned %#08x\n", hr);
466 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, D3DFOG_NONE);
467 ok(hr == D3D_OK, "Turning off vertex fog returned %#08x\n", hr);
469 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
470 ok(hr == D3D_OK, "IDirect3DDevice7_Clear returned %#08x\n", hr);
472 if (IDirect3DDevice7_BeginScene(device) == D3D_OK)
474 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST,
475 D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR, far_quad1, 4, Indices, 6, 0);
476 ok(hr == D3D_OK, "DrawIndexedPrimitive returned %#08x\n", hr);
478 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST,
479 D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR, far_quad2, 4, Indices, 6, 0);
480 ok(hr == D3D_OK, "DrawIndexedPrimitive returned %#08x\n", hr);
482 hr = IDirect3DDevice7_EndScene(device);
483 ok(hr == D3D_OK, "EndScene returned %#08x\n", hr);
485 else
487 ok(FALSE, "BeginScene failed\n");
490 color = getPixelColor(device, 160, 360);
491 ok(color_match(color, 0x00ff0000, 4), "Unfogged quad has color %08x\n", color);
492 color = getPixelColor(device, 160, 120);
493 ok(color_match(color, 0x0000ff00, 1), "Fogged out quad has color %08x\n", color);
495 /* Test fog behavior with an orthogonal (but not identity) projection matrix */
496 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &world_mat2);
497 ok(hr == D3D_OK, "SetTransform returned %#08x\n", hr);
498 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &proj_mat);
499 ok(hr == D3D_OK, "SetTransform returned %#08x\n", hr);
501 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
502 ok(hr == D3D_OK, "Clear returned %#08x\n", hr);
504 if (IDirect3DDevice7_BeginScene(device) == D3D_OK)
506 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST,
507 D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR, untransformed_1, 4, Indices, 6, 0);
508 ok(hr == D3D_OK, "DrawIndexedPrimitiveUP returned %#08x\n", hr);
510 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST,
511 D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR, untransformed_2, 4, Indices, 6, 0);
512 ok(hr == D3D_OK, "DrawIndexedPrimitiveUP returned %#08x\n", hr);
514 hr = IDirect3DDevice7_EndScene(device);
515 ok(hr == D3D_OK, "EndScene returned %#08x\n", hr);
517 else
519 ok(FALSE, "BeginScene failed\n");
522 color = getPixelColor(device, 160, 360);
523 ok(color_match(color, 0x00e51900, 4), "Partially fogged quad has color %08x\n", color);
524 color = getPixelColor(device, 160, 120);
525 ok(color_match(color, 0x0000ff00, 1), "Fogged out quad has color %08x\n", color);
527 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &ident_mat);
528 ok(hr == D3D_OK, "SetTransform returned %#08x\n", hr);
529 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &ident_mat);
530 ok(hr == D3D_OK, "SetTransform returned %#08x\n", hr);
532 else
534 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests\n");
537 /* Turn off the fog master switch to avoid confusing other tests */
538 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
539 ok(hr == D3D_OK, "Turning off fog calculations returned %08x\n", hr);
542 static void offscreen_test(IDirect3DDevice7 *device)
544 HRESULT hr;
545 IDirectDrawSurface7 *backbuffer = NULL, *offscreen = NULL;
546 DWORD color;
547 DDSURFACEDESC2 ddsd;
549 static float quad[][5] = {
550 {-0.5f, -0.5f, 0.1f, 0.0f, 0.0f},
551 {-0.5f, 0.5f, 0.1f, 0.0f, 1.0f},
552 { 0.5f, -0.5f, 0.1f, 1.0f, 0.0f},
553 { 0.5f, 0.5f, 0.1f, 1.0f, 1.0f},
556 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
557 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
559 memset(&ddsd, 0, sizeof(ddsd));
560 ddsd.dwSize = sizeof(ddsd);
561 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
562 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
563 ddsd.dwWidth = 128;
564 ddsd.dwHeight = 128;
565 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_3DDEVICE;
566 hr = IDirectDraw7_CreateSurface(DirectDraw, &ddsd, &offscreen, NULL);
567 ok(hr == D3D_OK, "Creating the offscreen render target failed, hr = %08x\n", hr);
568 if(!offscreen) {
569 goto out;
572 hr = IDirect3DDevice7_GetRenderTarget(device, &backbuffer);
573 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
574 if(!backbuffer) {
575 goto out;
578 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
579 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
580 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
581 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
582 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_MINFILTER, D3DFILTER_NEAREST);
583 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MINFILTER failed (0x%08x)\n", hr);
584 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_MAGFILTER, D3DFILTER_NEAREST);
585 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr);
586 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
587 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned hr = %08x\n", hr);
589 if (refdevice) {
590 win_skip("Tests would crash on W2K with a refdevice\n");
591 goto out;
594 if(IDirect3DDevice7_BeginScene(device) == D3D_OK) {
595 hr = IDirect3DDevice7_SetRenderTarget(device, offscreen, 0);
596 ok(hr == D3D_OK, "SetRenderTarget failed, hr = %08x\n", hr);
597 set_viewport_size(device);
598 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
599 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
601 /* Draw without textures - Should result in a white quad */
602 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEX1, quad, 4, 0);
603 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
605 hr = IDirect3DDevice7_SetRenderTarget(device, backbuffer, 0);
606 ok(hr == D3D_OK, "SetRenderTarget failed, hr = %08x\n", hr);
607 set_viewport_size(device);
609 hr = IDirect3DDevice7_SetTexture(device, 0, offscreen);
610 ok(hr == D3D_OK, "SetTexture failed, %08x\n", hr);
612 /* This time with the texture */
613 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEX1, quad, 4, 0);
614 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
616 IDirect3DDevice7_EndScene(device);
619 /* Center quad - should be white */
620 color = getPixelColor(device, 320, 240);
621 ok(color == 0x00ffffff, "Offscreen failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
622 /* Some quad in the cleared part of the texture */
623 color = getPixelColor(device, 170, 240);
624 ok(color == 0x00ff00ff, "Offscreen failed: Got color 0x%08x, expected 0x00ff00ff.\n", color);
625 /* Part of the originally cleared back buffer */
626 color = getPixelColor(device, 10, 10);
627 ok(color == 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
628 if(0) {
629 /* Lower left corner of the screen, where back buffer offscreen rendering draws the offscreen texture.
630 * It should be red, but the offscreen texture may leave some junk there. Not tested yet. Depending on
631 * the offscreen rendering mode this test would succeed or fail
633 color = getPixelColor(device, 10, 470);
634 ok(color == 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
637 out:
638 hr = IDirect3DDevice7_SetTexture(device, 0, NULL);
639 ok(SUCCEEDED(hr), "IDirect3DDevice7_SetTexture returned %#x.\n", hr);
641 /* restore things */
642 if(backbuffer) {
643 hr = IDirect3DDevice7_SetRenderTarget(device, backbuffer, 0);
644 ok(SUCCEEDED(hr), "IDirect3DDevice7_SetRenderTarget returned %#x.\n", hr);
645 IDirectDrawSurface7_Release(backbuffer);
647 if(offscreen) {
648 IDirectDrawSurface7_Release(offscreen);
652 static void test_blend(IDirect3DDevice7 *device)
654 HRESULT hr;
655 IDirectDrawSurface7 *backbuffer = NULL, *offscreen = NULL;
656 DWORD color, red, green, blue;
657 DDSURFACEDESC2 ddsd;
659 struct
661 struct vec3 position;
662 DWORD diffuse;
664 quad1[] =
666 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
667 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
668 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
669 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
671 quad2[] =
673 {{-1.0f, 0.0f, 0.1f}, 0xc00000ff},
674 {{-1.0f, 1.0f, 0.1f}, 0xc00000ff},
675 {{ 1.0f, 0.0f, 0.1f}, 0xc00000ff},
676 {{ 1.0f, 1.0f, 0.1f}, 0xc00000ff},
678 static float composite_quad[][5] = {
679 { 0.0f, -1.0f, 0.1f, 0.0f, 1.0f},
680 { 0.0f, 1.0f, 0.1f, 0.0f, 0.0f},
681 { 1.0f, -1.0f, 0.1f, 1.0f, 1.0f},
682 { 1.0f, 1.0f, 0.1f, 1.0f, 0.0f},
685 /* Clear the render target with alpha = 0.5 */
686 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x80ff0000, 0.0, 0);
687 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
689 memset(&ddsd, 0, sizeof(ddsd));
690 ddsd.dwSize = sizeof(ddsd);
691 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
692 ddsd.dwWidth = 128;
693 ddsd.dwHeight = 128;
694 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_3DDEVICE;
695 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
696 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
697 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
698 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
699 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
700 U5(U4(ddsd).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
701 hr = IDirectDraw7_CreateSurface(DirectDraw, &ddsd, &offscreen, NULL);
702 ok(hr == D3D_OK, "Creating the offscreen render target failed, hr = %08x\n", hr);
703 if(!offscreen) {
704 goto out;
706 hr = IDirect3DDevice7_GetRenderTarget(device, &backbuffer);
707 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
708 if(!backbuffer) {
709 goto out;
712 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
713 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
714 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
715 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
716 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_MINFILTER, D3DFILTER_NEAREST);
717 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MINFILTER failed (0x%08x)\n", hr);
718 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_MAGFILTER, D3DFILTER_NEAREST);
719 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr);
721 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
722 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
724 if (refdevice) {
725 win_skip("Tests would crash on W2K with a refdevice\n");
726 goto out;
729 if(IDirect3DDevice7_BeginScene(device) == D3D_OK) {
731 /* Draw two quads, one with src alpha blending, one with dest alpha blending. The
732 * SRCALPHA / INVSRCALPHA blend doesn't give any surprises. Colors are blended based on
733 * the input alpha
735 * The DESTALPHA / INVDESTALPHA do not "work" on the regular buffer because there is no alpha.
736 * They give essentially ZERO and ONE blend factors
738 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
739 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
740 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
741 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
742 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad1, 4, 0);
743 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
745 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_DESTALPHA);
746 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
747 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVDESTALPHA);
748 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
749 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad2, 4, 0);
750 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
752 /* Switch to the offscreen buffer, and redo the testing. SRCALPHA and DESTALPHA. The offscreen buffer
753 * has an alpha channel on its own. Clear the offscreen buffer with alpha = 0.5 again, then draw the
754 * quads again. The SRCALPHA/INVSRCALPHA doesn't give any surprises, but the DESTALPHA/INVDESTALPHA
755 * blending works as supposed now - blend factor is 0.5 in both cases, not 0.75 as from the input
756 * vertices
758 hr = IDirect3DDevice7_SetRenderTarget(device, offscreen, 0);
759 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderTarget failed, hr = %08x\n", hr);
760 set_viewport_size(device);
761 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x80ff0000, 0.0, 0);
762 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
764 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
765 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
766 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
767 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
768 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad1, 4, 0);
769 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
771 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_DESTALPHA);
772 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
773 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVDESTALPHA);
774 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
775 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad2, 4, 0);
776 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
778 hr = IDirect3DDevice7_SetRenderTarget(device, backbuffer, 0);
779 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderTarget failed, hr = %08x\n", hr);
780 set_viewport_size(device);
782 /* Render the offscreen texture onto the frame buffer to be able to compare it regularly.
783 * Disable alpha blending for the final composition
785 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
786 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
788 hr = IDirect3DDevice7_SetTexture(device, 0, offscreen);
789 ok(hr == D3D_OK, "IDirect3DDevice7_SetTexture failed, hr = %08x\n", hr);
790 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEX1, composite_quad, 4, 0);
791 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
792 hr = IDirect3DDevice7_SetTexture(device, 0, NULL);
793 ok(hr == D3D_OK, "IDirect3DDevice7_SetTexture failed, hr = %08x\n", hr);
795 hr = IDirect3DDevice7_EndScene(device);
796 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed, hr = %08x\n", hr);
799 color = getPixelColor(device, 160, 360);
800 red = (color & 0x00ff0000) >> 16;
801 green = (color & 0x0000ff00) >> 8;
802 blue = (color & 0x000000ff);
803 ok(red >= 0xbe && red <= 0xc0 && green >= 0x39 && green <= 0x41 && blue == 0x00,
804 "SRCALPHA on frame buffer returned color 0x%08x, expected 0x00bf4000\n", color);
806 color = getPixelColor(device, 160, 120);
807 red = (color & 0x00ff0000) >> 16;
808 green = (color & 0x0000ff00) >> 8;
809 blue = (color & 0x000000ff);
810 ok(red == 0x00 && green == 0x00 && blue >= 0xfe && blue <= 0xff ,
811 "DSTALPHA on frame buffer returned color 0x%08x, expected 0x000000ff\n", color);
813 color = getPixelColor(device, 480, 360);
814 red = (color & 0x00ff0000) >> 16;
815 green = (color & 0x0000ff00) >> 8;
816 blue = (color & 0x000000ff);
817 ok(red >= 0xbe && red <= 0xc0 && green >= 0x39 && green <= 0x41 && blue == 0x00,
818 "SRCALPHA on texture returned color 0x%08x, expected 0x00bf4000\n", color);
820 color = getPixelColor(device, 480, 120);
821 red = (color & 0x00ff0000) >> 16;
822 green = (color & 0x0000ff00) >> 8;
823 blue = (color & 0x000000ff);
824 ok(red >= 0x7e && red <= 0x81 && green == 0x00 && blue >= 0x7e && blue <= 0x81,
825 "DSTALPHA on texture returned color 0x%08x, expected 0x00800080\n", color);
827 out:
828 if(offscreen) IDirectDrawSurface7_Release(offscreen);
829 if(backbuffer) IDirectDrawSurface7_Release(backbuffer);
832 static void rhw_zero_test(IDirect3DDevice7 *device)
834 /* Test if it will render a quad correctly when vertex rhw = 0 */
835 HRESULT hr;
836 DWORD color;
838 struct {
839 float x, y, z;
840 float rhw;
841 DWORD diffuse;
842 } quad1[] =
844 {0, 100, 0, 0, 0xffffffff},
845 {0, 0, 0, 0, 0xffffffff},
846 {100, 100, 0, 0, 0xffffffff},
847 {100, 0, 0, 0, 0xffffffff},
850 /* Clear to black */
851 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0, 0.0, 0);
852 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
854 hr = IDirect3DDevice7_BeginScene(device);
855 ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed with %08x\n", hr);
857 if (SUCCEEDED(hr)) {
858 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, quad1, 4, 0);
859 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
861 hr = IDirect3DDevice7_EndScene(device);
862 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed, hr = %08x\n", hr);
865 color = getPixelColor(device, 5, 5);
866 ok(color == 0xffffff ||
867 broken(color == 0), /* VMware */
868 "Got color %08x, expected 00ffffff\n", color);
870 color = getPixelColor(device, 105, 105);
871 ok(color == 0, "Got color %08x, expected 00000000\n", color);
874 static DWORD D3D3_getPixelColor(IDirectDraw4 *DirectDraw, IDirectDrawSurface4 *Surface, UINT x, UINT y)
876 DWORD ret;
877 HRESULT hr;
878 DDSURFACEDESC2 ddsd;
879 RECT rectToLock = {x, y, x+1, y+1};
880 IDirectDrawSurface4 *surf = NULL;
882 /* Some implementations seem to dislike direct locking on the front buffer. Thus copy the front buffer
883 * to an offscreen surface and lock it instead of the front buffer
885 memset(&ddsd, 0, sizeof(ddsd));
886 ddsd.dwSize = sizeof(ddsd);
887 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
888 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
889 ddsd.dwWidth = 640;
890 ddsd.dwHeight = 480;
891 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
892 hr = IDirectDraw4_CreateSurface(DirectDraw, &ddsd, &surf, NULL);
893 ok(hr == DD_OK, "IDirectDraw4_CreateSurface failed with %08x\n", hr);
894 if(!surf)
896 trace("cannot create helper surface\n");
897 return 0xdeadbeef;
900 memset(&ddsd, 0, sizeof(ddsd));
901 ddsd.dwSize = sizeof(ddsd);
902 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
904 hr = IDirectDrawSurface4_BltFast(surf, 0, 0, Surface, NULL, 0);
905 ok(hr == DD_OK, "IDirectDrawSurface_BltFast returned %08x\n", hr);
906 if(FAILED(hr))
908 trace("Cannot blit\n");
909 ret = 0xdeadbee;
910 goto out;
913 hr = IDirectDrawSurface4_Lock(surf, &rectToLock, &ddsd, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
914 if(FAILED(hr))
916 trace("Can't lock the offscreen surface, hr=%08x\n", hr);
917 ret = 0xdeadbeec;
918 goto out;
921 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
922 * really important for these tests
924 ret = ((DWORD *) ddsd.lpSurface)[0] & 0x00ffffff;
925 hr = IDirectDrawSurface4_Unlock(surf, NULL);
926 if(FAILED(hr))
928 trace("Can't unlock the offscreen surface, hr=%08x\n", hr);
931 out:
932 IDirectDrawSurface4_Release(surf);
933 return ret;
936 static void D3D3_ViewportClearTest(void)
938 HRESULT hr;
939 IDirectDraw *DirectDraw1 = NULL;
940 IDirectDraw4 *DirectDraw4 = NULL;
941 IDirectDrawSurface4 *Primary = NULL;
942 IDirect3D3 *Direct3D3 = NULL;
943 IDirect3DViewport3 *Viewport3 = NULL;
944 IDirect3DViewport3 *SmallViewport3 = NULL;
945 IDirect3DDevice3 *Direct3DDevice3 = NULL;
946 WNDCLASSA wc = {0};
947 DDSURFACEDESC2 ddsd;
948 D3DVIEWPORT2 vp_data;
949 DWORD color, red, green, blue;
950 D3DRECT rect;
951 D3DMATRIX mat =
953 1.0f, 0.0f, 0.0f, 0.0f,
954 0.0f, 1.0f, 0.0f, 0.0f,
955 0.0f, 0.0f, 1.0f, 0.0f,
956 0.0f, 0.0f, 0.0f, 1.0f,
958 struct
960 struct vec3 position;
961 DWORD diffuse;
963 quad[] =
965 {{-1.0f, -1.0f, 0.1f}, 0xffffffff},
966 {{-1.0f, 1.0f, 0.1f}, 0xffffffff},
967 {{ 1.0f, 1.0f, 0.1f}, 0xffffffff},
968 {{ 1.0f, -1.0f, 0.1f}, 0xffffffff},
971 WORD Indices[] = {0, 1, 2, 2, 3, 0};
972 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
974 wc.lpfnWndProc = DefWindowProcA;
975 wc.lpszClassName = "D3D3_ViewportClearTest_wc";
976 RegisterClassA(&wc);
977 window = CreateWindowA("D3D3_ViewportClearTest_wc", "D3D3_ViewportClearTest",
978 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, 640, 480, 0, 0, 0, 0);
980 hr = DirectDrawCreate( NULL, &DirectDraw1, NULL );
981 ok(hr==DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreate returned: %x\n", hr);
982 if(FAILED(hr)) goto out;
984 hr = IDirectDraw_SetCooperativeLevel(DirectDraw1, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
985 ok(hr==DD_OK, "SetCooperativeLevel returned: %x\n", hr);
986 if(FAILED(hr)) goto out;
988 hr = IDirectDraw_SetDisplayMode(DirectDraw1, 640, 480, 32);
989 if(FAILED(hr)) {
990 /* 24 bit is fine too */
991 hr = IDirectDraw_SetDisplayMode(DirectDraw1, 640, 480, 24);
993 ok(hr==DD_OK || hr == DDERR_UNSUPPORTED, "SetDisplayMode returned: %x\n", hr);
994 if (FAILED(hr)) goto out;
996 hr = IDirectDraw_QueryInterface(DirectDraw1, &IID_IDirectDraw4, (void**)&DirectDraw4);
997 ok(hr==DD_OK, "QueryInterface returned: %08x\n", hr);
998 if(FAILED(hr)) goto out;
1000 memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
1001 ddsd.dwSize = sizeof(DDSURFACEDESC2);
1002 ddsd.dwFlags = DDSD_CAPS;
1003 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE;
1005 hr = IDirectDraw4_CreateSurface(DirectDraw4, &ddsd, &Primary, NULL);
1006 ok(hr==DD_OK, "IDirectDraw4_CreateSurface returned: %08x\n", hr);
1007 if(FAILED(hr)) goto out;
1009 hr = IDirectDraw4_QueryInterface(DirectDraw4, &IID_IDirect3D3, (void**)&Direct3D3);
1010 ok(hr==DD_OK, "IDirectDraw4_QueryInterface returned: %08x\n", hr);
1011 if(FAILED(hr)) goto out;
1013 hr = IDirect3D3_CreateDevice(Direct3D3, &IID_IDirect3DHALDevice, Primary, &Direct3DDevice3, NULL);
1014 if(FAILED(hr)) {
1015 trace("Creating a HAL device failed, trying Ref\n");
1016 hr = IDirect3D3_CreateDevice(Direct3D3, &IID_IDirect3DRefDevice, Primary, &Direct3DDevice3, NULL);
1018 ok(hr==D3D_OK, "Creating 3D device returned: %x\n", hr);
1019 if(FAILED(hr)) goto out;
1021 hr = IDirect3D3_CreateViewport(Direct3D3, &Viewport3, NULL);
1022 ok(hr==DD_OK, "IDirect3D3_CreateViewport returned: %08x\n", hr);
1023 if(FAILED(hr)) goto out;
1025 hr = IDirect3DDevice3_AddViewport(Direct3DDevice3, Viewport3);
1026 ok(hr==DD_OK, "IDirect3DDevice3_AddViewport returned: %08x\n", hr);
1028 memset(&vp_data, 0, sizeof(D3DVIEWPORT2));
1029 vp_data.dwSize = sizeof(D3DVIEWPORT2);
1030 vp_data.dwWidth = 640;
1031 vp_data.dwHeight = 480;
1032 vp_data.dvClipX = -1.0f;
1033 vp_data.dvClipWidth = 2.0f;
1034 vp_data.dvClipY = 1.0f;
1035 vp_data.dvClipHeight = 2.0f;
1036 vp_data.dvMaxZ = 1.0f;
1037 hr = IDirect3DViewport3_SetViewport2(Viewport3, &vp_data);
1038 ok(hr==DD_OK, "IDirect3DViewport3_SetViewport2 returned: %08x\n", hr);
1040 hr = IDirect3D3_CreateViewport(Direct3D3, &SmallViewport3, NULL);
1041 ok(hr==DD_OK, "IDirect3D3_CreateViewport returned: %08x\n", hr);
1042 if(FAILED(hr)) goto out;
1044 hr = IDirect3DDevice3_AddViewport(Direct3DDevice3, SmallViewport3);
1045 ok(hr==DD_OK, "IDirect3DDevice3_AddViewport returned: %08x\n", hr);
1047 memset(&vp_data, 0, sizeof(D3DVIEWPORT2));
1048 vp_data.dwSize = sizeof(D3DVIEWPORT2);
1049 vp_data.dwX = 400;
1050 vp_data.dwY = 100;
1051 vp_data.dwWidth = 100;
1052 vp_data.dwHeight = 100;
1053 vp_data.dvClipX = -1.0f;
1054 vp_data.dvClipWidth = 2.0f;
1055 vp_data.dvClipY = 1.0f;
1056 vp_data.dvClipHeight = 2.0f;
1057 vp_data.dvMaxZ = 1.0f;
1058 hr = IDirect3DViewport3_SetViewport2(SmallViewport3, &vp_data);
1059 ok(hr==DD_OK, "IDirect3DViewport3_SetViewport2 returned: %08x\n", hr);
1061 hr = IDirect3DDevice3_BeginScene(Direct3DDevice3);
1062 ok(hr == D3D_OK, "IDirect3DDevice3_BeginScene failed with %08x\n", hr);
1064 hr = IDirect3DDevice3_SetTransform(Direct3DDevice3, D3DTRANSFORMSTATE_WORLD, &mat);
1065 ok(hr == D3D_OK, "IDirect3DDevice3_SetTransform returned %08x\n", hr);
1066 hr = IDirect3DDevice3_SetTransform(Direct3DDevice3, D3DTRANSFORMSTATE_VIEW, &mat);
1067 ok(hr == D3D_OK, "IDirect3DDevice3_SetTransform returned %08x\n", hr);
1068 hr = IDirect3DDevice3_SetTransform(Direct3DDevice3, D3DTRANSFORMSTATE_PROJECTION, &mat);
1069 ok(hr == D3D_OK, "IDirect3DDevice3_SetTransform returned %08x\n", hr);
1070 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_CLIPPING, FALSE);
1071 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState returned %08x\n", hr);
1072 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_ZENABLE, FALSE);
1073 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState returned %08x\n", hr);
1074 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_FOGENABLE, FALSE);
1075 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState returned %08x\n", hr);
1076 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_STENCILENABLE, FALSE);
1077 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState returned %08x\n", hr);
1078 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_ALPHATESTENABLE, FALSE);
1079 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState returned %08x\n", hr);
1080 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
1081 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState returned %08x\n", hr);
1082 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
1083 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState failed with %08x\n", hr);
1084 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_LIGHTING, FALSE);
1085 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState returned %08x\n", hr);
1087 if (SUCCEEDED(hr)) {
1088 U1(rect).x1 = U2(rect).y1 = 0;
1089 U3(rect).x2 = 640;
1090 U4(rect).y2 = 480;
1092 hr = IDirect3DViewport3_Clear2(Viewport3, 1, &rect, D3DCLEAR_TARGET, 0x00ff00, 0.0f, 0);
1093 ok(hr == D3D_OK, "IDirect3DViewport3_Clear2 failed, hr = %08x\n", hr);
1095 hr = IDirect3DViewport3_Clear2(SmallViewport3, 1, &rect, D3DCLEAR_TARGET, 0xff0000, 0.0f, 0);
1096 ok(hr == D3D_OK, "IDirect3DViewport3_Clear2 failed, hr = %08x\n", hr);
1098 hr = IDirect3DDevice3_EndScene(Direct3DDevice3);
1099 ok(hr == D3D_OK, "IDirect3DDevice3_EndScene failed, hr = %08x\n", hr);
1102 color = D3D3_getPixelColor(DirectDraw4, Primary, 5, 5);
1103 red = (color & 0x00ff0000) >> 16;
1104 green = (color & 0x0000ff00) >> 8;
1105 blue = (color & 0x000000ff);
1106 ok(red == 0 && green == 0xff && blue == 0, "Got color %08x, expected 0000ff00\n", color);
1108 color = D3D3_getPixelColor(DirectDraw4, Primary, 405, 105);
1109 red = (color & 0x00ff0000) >> 16;
1110 green = (color & 0x0000ff00) >> 8;
1111 blue = (color & 0x000000ff);
1112 ok(red == 0xff && green == 0 && blue == 0, "Got color %08x, expected 00ff0000\n", color);
1114 /* Test that clearing viewport doesn't interfere with rendering to previously active viewport. */
1115 hr = IDirect3DDevice3_BeginScene(Direct3DDevice3);
1116 ok(hr == D3D_OK, "IDirect3DDevice3_BeginScene failed with %08x\n", hr);
1118 if (SUCCEEDED(hr)) {
1119 hr = IDirect3DDevice3_SetCurrentViewport(Direct3DDevice3, SmallViewport3);
1120 ok(hr == D3D_OK, "IDirect3DDevice3_SetCurrentViewport failed with %08x\n", hr);
1122 hr = IDirect3DViewport3_Clear2(Viewport3, 1, &rect, D3DCLEAR_TARGET, 0x000000, 0.0f, 0);
1123 ok(hr == D3D_OK, "IDirect3DViewport3_Clear2 failed, hr = %08x\n", hr);
1125 hr = IDirect3DDevice3_DrawIndexedPrimitive(Direct3DDevice3, D3DPT_TRIANGLELIST, fvf, quad, 4 /* NumVerts */,
1126 Indices, 6 /* Indexcount */, 0 /* flags */);
1127 ok(hr == D3D_OK, "IDirect3DDevice3_DrawIndexedPrimitive failed with %08x\n", hr);
1129 hr = IDirect3DDevice3_EndScene(Direct3DDevice3);
1130 ok(hr == D3D_OK, "IDirect3DDevice3_EndScene failed, hr = %08x\n", hr);
1133 color = D3D3_getPixelColor(DirectDraw4, Primary, 5, 5);
1134 red = (color & 0x00ff0000) >> 16;
1135 green = (color & 0x0000ff00) >> 8;
1136 blue = (color & 0x000000ff);
1137 ok(red == 0 && green == 0 && blue == 0, "Got color %08x, expected 00000000\n", color);
1139 color = D3D3_getPixelColor(DirectDraw4, Primary, 405, 105);
1140 red = (color & 0x00ff0000) >> 16;
1141 green = (color & 0x0000ff00) >> 8;
1142 blue = (color & 0x000000ff);
1143 ok(red == 0xff && green == 0xff && blue == 0xff, "Got color %08x, expected 00ffffff\n", color);
1145 out:
1147 if (SmallViewport3) IDirect3DViewport3_Release(SmallViewport3);
1148 if (Viewport3) IDirect3DViewport3_Release(Viewport3);
1149 if (Direct3DDevice3) IDirect3DDevice3_Release(Direct3DDevice3);
1150 if (Direct3D3) IDirect3D3_Release(Direct3D3);
1151 if (Primary) IDirectDrawSurface4_Release(Primary);
1152 if (DirectDraw1) IDirectDraw_Release(DirectDraw1);
1153 if (DirectDraw4) IDirectDraw4_Release(DirectDraw4);
1154 if(window) DestroyWindow(window);
1157 static COLORREF getPixelColor_GDI(IDirectDrawSurface *Surface, UINT x, UINT y)
1159 COLORREF clr = CLR_INVALID;
1160 HDC hdc;
1161 HRESULT hr;
1163 hr = IDirectDrawSurface_GetDC(Surface, &hdc);
1164 ok(hr==DD_OK, "IDirectDrawSurface_GetDC returned: %x\n", hr);
1166 if (SUCCEEDED(hr)) {
1167 clr = GetPixel(hdc, x, y);
1169 hr = IDirectDrawSurface_ReleaseDC(Surface, hdc);
1170 ok(hr==DD_OK, "IDirectDrawSurface_ReleaseDC returned: %x\n", hr);
1173 return clr;
1176 static void cubemap_test(IDirect3DDevice7 *device)
1178 IDirect3D7 *d3d;
1179 IDirectDraw7 *ddraw;
1180 IDirectDrawSurface7 *cubemap, *surface;
1181 D3DDEVICEDESC7 d3dcaps;
1182 HRESULT hr;
1183 DWORD color;
1184 DDSURFACEDESC2 ddsd;
1185 DDBLTFX DDBltFx;
1186 DDSCAPS2 caps;
1187 static float quad[] = {
1188 -1.0, -1.0, 0.1, 1.0, 0.0, 0.0, /* Lower left */
1189 0.0, -1.0, 0.1, 1.0, 0.0, 0.0,
1190 -1.0, 0.0, 0.1, 1.0, 0.0, 0.0,
1191 0.0, 0.0, 0.1, 1.0, 0.0, 0.0,
1193 0.0, -1.0, 0.1, 0.0, 1.0, 0.0, /* Lower right */
1194 1.0, -1.0, 0.1, 0.0, 1.0, 0.0,
1195 0.0, 0.0, 0.1, 0.0, 1.0, 0.0,
1196 1.0, 0.0, 0.1, 0.0, 1.0, 0.0,
1198 0.0, 0.0, 0.1, 0.0, 0.0, 1.0, /* upper right */
1199 1.0, 0.0, 0.1, 0.0, 0.0, 1.0,
1200 0.0, 1.0, 0.1, 0.0, 0.0, 1.0,
1201 1.0, 1.0, 0.1, 0.0, 0.0, 1.0,
1203 -1.0, 0.0, 0.1, -1.0, 0.0, 0.0, /* Upper left */
1204 0.0, 0.0, 0.1, -1.0, 0.0, 0.0,
1205 -1.0, 1.0, 0.1, -1.0, 0.0, 0.0,
1206 0.0, 1.0, 0.1, -1.0, 0.0, 0.0,
1209 memset(&DDBltFx, 0, sizeof(DDBltFx));
1210 DDBltFx.dwSize = sizeof(DDBltFx);
1212 memset(&d3dcaps, 0, sizeof(d3dcaps));
1213 hr = IDirect3DDevice7_GetCaps(device, &d3dcaps);
1214 ok(hr == D3D_OK, "IDirect3DDevice7_GetCaps returned %08x\n", hr);
1215 if(!(d3dcaps.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_CUBEMAP))
1217 skip("No cubemap support\n");
1218 return;
1221 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff000000, 0.0, 0);
1222 ok(hr == D3D_OK, "IDirect3DDevice7_Clear failed with %08x\n", hr);
1224 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1225 ok(hr == D3D_OK, "IDirect3DDevice7_GetDirect3D returned %08x\n", hr);
1226 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **) &ddraw);
1227 ok(hr == D3D_OK, "IDirect3D7_QueryInterface returned %08x\n", hr);
1228 IDirect3D7_Release(d3d);
1231 memset(&ddsd, 0, sizeof(ddsd));
1232 ddsd.dwSize = sizeof(ddsd);
1233 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1234 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
1235 ddsd.dwWidth = 16;
1236 ddsd.dwHeight = 16;
1237 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX;
1238 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_TEXTUREMANAGE;
1239 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
1240 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
1241 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00FF0000;
1242 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000FF00;
1243 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000FF;
1245 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &cubemap, NULL);
1246 ok(hr == DD_OK, "IDirectDraw7_CreateSurface returned %08x\n", hr);
1247 IDirectDraw7_Release(ddraw);
1249 /* Positive X */
1250 U5(DDBltFx).dwFillColor = 0x00ff0000;
1251 hr = IDirectDrawSurface7_Blt(cubemap, NULL, NULL, NULL, DDBLT_COLORFILL, &DDBltFx);
1252 ok(hr == DD_OK, "IDirectDrawSurface7_Blt returned %08x\n", hr);
1254 memset(&caps, 0, sizeof(caps));
1255 caps.dwCaps = DDSCAPS_TEXTURE;
1256 caps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX;
1257 hr = IDirectDrawSurface_GetAttachedSurface(cubemap, &caps, &surface);
1258 ok(hr == DD_OK, "IDirectDrawSurface7_Lock returned %08x\n", hr);
1259 U5(DDBltFx).dwFillColor = 0x0000ffff;
1260 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL, &DDBltFx);
1261 ok(hr == DD_OK, "IDirectDrawSurface7_Blt returned %08x\n", hr);
1263 caps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEZ;
1264 hr = IDirectDrawSurface_GetAttachedSurface(cubemap, &caps, &surface);
1265 ok(hr == DD_OK, "IDirectDrawSurface7_Lock returned %08x\n", hr);
1266 U5(DDBltFx).dwFillColor = 0x0000ff00;
1267 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL, &DDBltFx);
1268 ok(hr == DD_OK, "IDirectDrawSurface7_Blt returned %08x\n", hr);
1270 caps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEZ;
1271 hr = IDirectDrawSurface_GetAttachedSurface(cubemap, &caps, &surface);
1272 ok(hr == DD_OK, "IDirectDrawSurface7_Lock returned %08x\n", hr);
1273 U5(DDBltFx).dwFillColor = 0x000000ff;
1274 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL, &DDBltFx);
1275 ok(hr == DD_OK, "IDirectDrawSurface7_Blt returned %08x\n", hr);
1277 caps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEY;
1278 hr = IDirectDrawSurface_GetAttachedSurface(cubemap, &caps, &surface);
1279 ok(hr == DD_OK, "IDirectDrawSurface7_Lock returned %08x\n", hr);
1280 U5(DDBltFx).dwFillColor = 0x00ffff00;
1281 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL, &DDBltFx);
1282 ok(hr == DD_OK, "IDirectDrawSurface7_Blt returned %08x\n", hr);
1284 caps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEY;
1285 hr = IDirectDrawSurface_GetAttachedSurface(cubemap, &caps, &surface);
1286 ok(hr == DD_OK, "IDirectDrawSurface7_Lock returned %08x\n", hr);
1287 U5(DDBltFx).dwFillColor = 0x00ff00ff;
1288 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL, &DDBltFx);
1289 ok(hr == DD_OK, "IDirectDrawSurface7_Blt returned %08x\n", hr);
1291 hr = IDirect3DDevice7_SetTexture(device, 0, cubemap);
1292 ok(hr == DD_OK, "IDirect3DDevice7_SetTexture returned %08x\n", hr);
1293 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
1294 ok(hr == DD_OK, "IDirect3DDevice7_SetTextureStageState returned %08x\n", hr);
1295 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
1296 ok(hr == DD_OK, "IDirect3DDevice7_SetTextureStageState returned %08x\n", hr);
1298 hr = IDirect3DDevice7_BeginScene(device);
1299 ok(hr == DD_OK, "IDirect3DDevice7_BeginScene returned %08x\n", hr);
1300 if(SUCCEEDED(hr))
1302 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1, quad + 0 * 6, 4, 0);
1303 if (hr == DDERR_UNSUPPORTED || hr == DDERR_NODIRECTDRAWHW)
1305 /* VMware */
1306 win_skip("IDirect3DDevice7_DrawPrimitive is not completely implemented, colors won't be tested\n");
1307 hr = IDirect3DDevice7_EndScene(device);
1308 ok(hr == DD_OK, "IDirect3DDevice7_EndScene returned %08x\n", hr);
1309 goto out;
1311 ok(hr == DD_OK, "IDirect3DDevice7_DrawPrimitive returned %08x\n", hr);
1312 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1, quad + 4 * 6, 4, 0);
1313 ok(hr == DD_OK, "IDirect3DDevice7_DrawPrimitive returned %08x\n", hr);
1314 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1, quad + 8 * 6, 4, 0);
1315 ok(hr == DD_OK, "IDirect3DDevice7_DrawPrimitive returned %08x\n", hr);
1316 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1, quad + 12* 6, 4, 0);
1317 ok(hr == DD_OK, "IDirect3DDevice7_DrawPrimitive returned %08x\n", hr);
1319 hr = IDirect3DDevice7_EndScene(device);
1320 ok(hr == DD_OK, "IDirect3DDevice7_EndScene returned %08x\n", hr);
1322 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_DISABLE);
1323 ok(hr == DD_OK, "IDirect3DDevice7_SetTextureStageState returned %08x\n", hr);
1325 color = getPixelColor(device, 160, 360); /* lower left quad - positivex */
1326 ok(color == 0x00ff0000, "DDSCAPS2_CUBEMAP_POSITIVEX has color 0x%08x, expected 0x00ff0000\n", color);
1327 color = getPixelColor(device, 160, 120); /* upper left quad - negativex */
1328 ok(color == 0x0000ffff, "DDSCAPS2_CUBEMAP_NEGATIVEX has color 0x%08x, expected 0x0000ffff\n", color);
1329 color = getPixelColor(device, 480, 360); /* lower right quad - positivey */
1330 ok(color == 0x00ff00ff, "DDSCAPS2_CUBEMAP_POSITIVEY has color 0x%08x, expected 0x00ff00ff\n", color);
1331 color = getPixelColor(device, 480, 120); /* upper right quad - positivez */
1332 ok(color == 0x000000ff, "DDSCAPS2_CUBEMAP_POSITIVEZ has color 0x%08x, expected 0x000000ff\n", color);
1334 out:
1335 hr = IDirect3DDevice7_SetTexture(device, 0, NULL);
1336 ok(hr == DD_OK, "IDirect3DDevice7_SetTexture returned %08x\n", hr);
1337 IDirectDrawSurface7_Release(cubemap);
1340 /* This test tests depth clamping / clipping behaviour:
1341 * - With software vertex processing, depth values are clamped to the
1342 * minimum / maximum z value when D3DRS_CLIPPING is disabled, and clipped
1343 * when D3DRS_CLIPPING is enabled. Pretransformed vertices behave the
1344 * same as regular vertices here.
1345 * - With hardware vertex processing, D3DRS_CLIPPING seems to be ignored.
1346 * Normal vertices are always clipped. Pretransformed vertices are
1347 * clipped when D3DPMISCCAPS_CLIPTLVERTS is set, clamped when it isn't.
1348 * - The viewport's MinZ/MaxZ is irrelevant for this.
1350 static void depth_clamp_test(IDirect3DDevice7 *device)
1352 struct
1354 struct vec4 position;
1355 DWORD diffuse;
1357 quad1[] =
1359 {{ 0.0f, 0.0f, 5.0f, 1.0f}, 0xff002b7f},
1360 {{640.0f, 0.0f, 5.0f, 1.0f}, 0xff002b7f},
1361 {{ 0.0f, 480.0f, 5.0f, 1.0f}, 0xff002b7f},
1362 {{640.0f, 480.0f, 5.0f, 1.0f}, 0xff002b7f},
1364 quad2[] =
1366 {{ 0.0f, 300.0f, 10.0f, 1.0f}, 0xfff9e814},
1367 {{640.0f, 300.0f, 10.0f, 1.0f}, 0xfff9e814},
1368 {{ 0.0f, 360.0f, 10.0f, 1.0f}, 0xfff9e814},
1369 {{640.0f, 360.0f, 10.0f, 1.0f}, 0xfff9e814},
1371 quad3[] =
1373 {{112.0f, 108.0f, 5.0f, 1.0f}, 0xffffffff},
1374 {{208.0f, 108.0f, 5.0f, 1.0f}, 0xffffffff},
1375 {{112.0f, 204.0f, 5.0f, 1.0f}, 0xffffffff},
1376 {{208.0f, 204.0f, 5.0f, 1.0f}, 0xffffffff},
1378 quad4[] =
1380 {{ 42.0f, 41.0f, 10.0f, 1.0f}, 0xffffffff},
1381 {{112.0f, 41.0f, 10.0f, 1.0f}, 0xffffffff},
1382 {{ 42.0f, 108.0f, 10.0f, 1.0f}, 0xffffffff},
1383 {{112.0f, 108.0f, 10.0f, 1.0f}, 0xffffffff},
1385 struct
1387 struct vec3 position;
1388 DWORD diffuse;
1390 quad5[] =
1392 {{-0.5f, 0.5f, 10.0f}, 0xff14f914},
1393 {{ 0.5f, 0.5f, 10.0f}, 0xff14f914},
1394 {{-0.5f, -0.5f, 10.0f}, 0xff14f914},
1395 {{ 0.5f, -0.5f, 10.0f}, 0xff14f914},
1397 quad6[] =
1399 {{-1.0f, 0.5f, 10.0f}, 0xfff91414},
1400 {{ 1.0f, 0.5f, 10.0f}, 0xfff91414},
1401 {{-1.0f, 0.25f, 10.0f}, 0xfff91414},
1402 {{ 1.0f, 0.25f, 10.0f}, 0xfff91414},
1405 D3DVIEWPORT7 vp;
1406 D3DCOLOR color;
1407 HRESULT hr;
1409 vp.dwX = 0;
1410 vp.dwY = 0;
1411 vp.dwWidth = 640;
1412 vp.dwHeight = 480;
1413 vp.dvMinZ = 0.0;
1414 vp.dvMaxZ = 7.5;
1416 hr = IDirect3DDevice7_SetViewport(device, &vp);
1417 ok(SUCCEEDED(hr), "SetViewport failed, hr %#x.\n", hr);
1419 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 1.0, 0);
1420 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
1422 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
1423 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1424 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
1425 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1426 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZWRITEENABLE, TRUE);
1427 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1428 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL);
1429 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1431 hr = IDirect3DDevice7_BeginScene(device);
1432 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
1434 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, quad1, 4, 0);
1435 ok(SUCCEEDED(hr), "DrawPrimitive failed, hr %#x.\n", hr);
1436 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, quad2, 4, 0);
1437 ok(SUCCEEDED(hr), "DrawPrimitive failed, hr %#x.\n", hr);
1439 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, TRUE);
1440 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1442 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, quad3, 4, 0);
1443 ok(SUCCEEDED(hr), "DrawPrimitive failed, hr %#x.\n", hr);
1444 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, quad4, 4, 0);
1445 ok(SUCCEEDED(hr), "DrawPrimitive failed, hr %#x.\n", hr);
1447 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
1448 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1450 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad5, 4, 0);
1451 ok(SUCCEEDED(hr), "DrawPrimitive failed, hr %#x.\n", hr);
1453 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, TRUE);
1454 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1456 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad6, 4, 0);
1457 ok(SUCCEEDED(hr), "DrawPrimitive failed, hr %#x.\n", hr);
1459 hr = IDirect3DDevice7_EndScene(device);
1460 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
1462 color = getPixelColor(device, 75, 75);
1463 ok(color_match(color, 0x00ffffff, 1) || color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
1464 color = getPixelColor(device, 150, 150);
1465 ok(color_match(color, 0x00ffffff, 1) || color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
1466 color = getPixelColor(device, 320, 240);
1467 ok(color_match(color, 0x00002b7f, 1) || color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
1468 color = getPixelColor(device, 320, 330);
1469 ok(color_match(color, 0x00f9e814, 1) || color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
1470 color = getPixelColor(device, 320, 330);
1471 ok(color_match(color, 0x00f9e814, 1) || color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
1473 vp.dvMinZ = 0.0;
1474 vp.dvMaxZ = 1.0;
1475 hr = IDirect3DDevice7_SetViewport(device, &vp);
1476 ok(SUCCEEDED(hr), "SetViewport failed, hr %#x.\n", hr);
1479 static void DX1_BackBufferFlipTest(void)
1481 HRESULT hr;
1482 IDirectDraw *DirectDraw1 = NULL;
1483 IDirectDrawSurface *Primary = NULL;
1484 IDirectDrawSurface *Backbuffer = NULL;
1485 WNDCLASSA wc = {0};
1486 DDSURFACEDESC ddsd;
1487 DDBLTFX ddbltfx;
1488 COLORREF color;
1489 const DWORD white = 0xffffff;
1490 const DWORD red = 0xff0000;
1491 BOOL attached = FALSE;
1493 wc.lpfnWndProc = DefWindowProcA;
1494 wc.lpszClassName = "DX1_BackBufferFlipTest_wc";
1495 RegisterClassA(&wc);
1496 window = CreateWindowA("DX1_BackBufferFlipTest_wc", "DX1_BackBufferFlipTest",
1497 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, 640, 480, 0, 0, 0, 0);
1499 hr = DirectDrawCreate( NULL, &DirectDraw1, NULL );
1500 ok(hr==DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreate returned: %x\n", hr);
1501 if(FAILED(hr)) goto out;
1503 hr = IDirectDraw_SetCooperativeLevel(DirectDraw1, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1504 ok(hr==DD_OK, "SetCooperativeLevel returned: %x\n", hr);
1505 if(FAILED(hr)) goto out;
1507 hr = IDirectDraw_SetDisplayMode(DirectDraw1, 640, 480, 32);
1508 if(FAILED(hr)) {
1509 /* 24 bit is fine too */
1510 hr = IDirectDraw_SetDisplayMode(DirectDraw1, 640, 480, 24);
1512 ok(hr==DD_OK || hr == DDERR_UNSUPPORTED, "SetDisplayMode returned: %x\n", hr);
1513 if (FAILED(hr)) {
1514 goto out;
1517 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
1518 ddsd.dwSize = sizeof(DDSURFACEDESC);
1519 ddsd.dwFlags = DDSD_CAPS;
1520 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
1522 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &Primary, NULL);
1523 ok(hr==DD_OK, "IDirectDraw_CreateSurface returned: %08x\n", hr);
1525 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
1526 ddsd.dwSize = sizeof(DDSURFACEDESC);
1527 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
1528 ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
1529 ddsd.dwWidth = 640;
1530 ddsd.dwHeight = 480;
1531 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
1532 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
1533 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
1534 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1535 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1536 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x000000ff;
1538 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &Backbuffer, NULL);
1539 ok(hr==DD_OK, "IDirectDraw_CreateSurface returned: %08x\n", hr);
1540 if(FAILED(hr)) goto out;
1542 hr = IDirectDrawSurface_AddAttachedSurface(Primary, Backbuffer);
1543 todo_wine ok(hr == DD_OK || broken(hr == DDERR_CANNOTATTACHSURFACE),
1544 "Attaching a back buffer to a front buffer returned %08x\n", hr);
1545 if (FAILED(hr)) goto out;
1547 attached = TRUE;
1549 memset(&ddbltfx, 0, sizeof(ddbltfx));
1550 ddbltfx.dwSize = sizeof(ddbltfx);
1551 U5(ddbltfx).dwFillColor = red;
1552 hr = IDirectDrawSurface_Blt(Backbuffer, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1553 ok(hr == DD_OK, "IDirectDrawSurface_Blt returned: %x\n", hr);
1555 U5(ddbltfx).dwFillColor = white;
1556 hr = IDirectDrawSurface_Blt(Primary, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1557 ok(hr == DD_OK, "IDirectDrawSurface_Blt returned: %x\n", hr);
1559 /* Check it out */
1560 color = getPixelColor_GDI(Primary, 5, 5);
1561 ok(GetRValue(color) == 0xFF && GetGValue(color) == 0xFF && GetBValue(color) == 0xFF,
1562 "got R %02X G %02X B %02X, expected R FF G FF B FF\n",
1563 GetRValue(color), GetGValue(color), GetBValue(color));
1565 color = getPixelColor_GDI(Backbuffer, 5, 5);
1566 ok(GetRValue(color) == 0xFF && GetGValue(color) == 0 && GetBValue(color) == 0,
1567 "got R %02X G %02X B %02X, expected R FF G 00 B 00\n",
1568 GetRValue(color), GetGValue(color), GetBValue(color));
1570 hr = IDirectDrawSurface_Flip(Primary, NULL, DDFLIP_WAIT);
1571 todo_wine ok(hr == DD_OK, "IDirectDrawSurface_Flip returned 0x%08x\n", hr);
1573 if (hr == DD_OK)
1575 color = getPixelColor_GDI(Primary, 5, 5);
1576 ok(GetRValue(color) == 0xFF && GetGValue(color) == 0 && GetBValue(color) == 0,
1577 "got R %02X G %02X B %02X, expected R FF G 00 B 00\n",
1578 GetRValue(color), GetGValue(color), GetBValue(color));
1580 color = getPixelColor_GDI(Backbuffer, 5, 5);
1581 ok((GetRValue(color) == 0xFF && GetGValue(color) == 0xFF && GetBValue(color) == 0xFF) ||
1582 broken(GetRValue(color) == 0xFF && GetGValue(color) == 0 && GetBValue(color) == 0), /* broken driver */
1583 "got R %02X G %02X B %02X, expected R FF G FF B FF\n",
1584 GetRValue(color), GetGValue(color), GetBValue(color));
1587 out:
1589 if (Backbuffer)
1591 if (attached)
1592 IDirectDrawSurface_DeleteAttachedSurface(Primary, 0, Backbuffer);
1593 IDirectDrawSurface_Release(Backbuffer);
1595 if (Primary) IDirectDrawSurface_Release(Primary);
1596 if (DirectDraw1) IDirectDraw_Release(DirectDraw1);
1597 if (window) DestroyWindow(window);
1600 START_TEST(visual)
1602 HRESULT hr;
1603 DWORD color;
1604 if(!createObjects())
1606 skip("Cannot initialize DirectDraw and Direct3D, skipping\n");
1607 return;
1610 /* Check for the reliability of the returned data */
1611 hr = IDirect3DDevice7_Clear(Direct3DDevice, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
1612 if(FAILED(hr))
1614 skip("Clear failed, can't assure correctness of the test results, skipping\n");
1615 goto cleanup;
1618 color = getPixelColor(Direct3DDevice, 1, 1);
1619 if(color !=0x00ff0000)
1621 skip("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests, skipping\n", color);
1622 goto cleanup;
1625 hr = IDirect3DDevice7_Clear(Direct3DDevice, 0, NULL, D3DCLEAR_TARGET, 0xff00ddee, 0.0, 0);
1626 if(FAILED(hr))
1628 skip("Clear failed, can't assure correctness of the test results, skipping\n");
1629 goto cleanup;
1632 color = getPixelColor(Direct3DDevice, 639, 479);
1633 if(color != 0x0000ddee)
1635 skip("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests, skipping\n", color);
1636 goto cleanup;
1639 /* Now run the tests */
1640 depth_clamp_test(Direct3DDevice);
1641 fog_test(Direct3DDevice);
1642 offscreen_test(Direct3DDevice);
1643 test_blend(Direct3DDevice);
1644 rhw_zero_test(Direct3DDevice);
1645 cubemap_test(Direct3DDevice);
1647 releaseObjects(); /* release DX7 interfaces to test D3D1 */
1649 D3D3_ViewportClearTest();
1650 DX1_BackBufferFlipTest();
1652 return ;
1654 cleanup:
1655 releaseObjects();