ddraw/tests: Properly declare matrices.
[wine.git] / dlls / ddraw / tests / visual.c
blob7aaf7cd3aca682258862be4b338bafaf741b1b77
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 static HWND window;
27 static IDirectDraw7 *DirectDraw;
28 static IDirectDrawSurface7 *Surface;
29 static IDirectDrawSurface7 *depth_buffer;
30 static IDirect3D7 *Direct3D;
31 static IDirect3DDevice7 *Direct3DDevice;
33 static IDirectDraw *DirectDraw1;
34 static IDirectDrawSurface *Surface1;
35 static IDirect3D *Direct3D1;
36 static IDirect3DDevice *Direct3DDevice1;
37 static IDirect3DExecuteBuffer *ExecuteBuffer;
38 static IDirect3DViewport *Viewport;
40 static BOOL refdevice = FALSE;
42 static HRESULT (WINAPI *pDirectDrawCreateEx)(GUID *driver_guid,
43 void **ddraw, REFIID interface_iid, IUnknown *outer);
45 static BOOL color_match(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
47 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
48 c1 >>= 8; c2 >>= 8;
49 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
50 c1 >>= 8; c2 >>= 8;
51 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
52 c1 >>= 8; c2 >>= 8;
53 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
54 return TRUE;
57 static HRESULT WINAPI enum_z_fmt(DDPIXELFORMAT *fmt, void *ctx)
59 DDPIXELFORMAT *zfmt = ctx;
61 if(U1(*fmt).dwZBufferBitDepth > U1(*zfmt).dwZBufferBitDepth)
63 *zfmt = *fmt;
65 return DDENUMRET_OK;
68 static HRESULT WINAPI enum_devtype_cb(char *desc_str, char *name, D3DDEVICEDESC7 *desc, void *ctx)
70 BOOL *hal_ok = ctx;
71 if (IsEqualGUID(&desc->deviceGUID, &IID_IDirect3DTnLHalDevice))
73 *hal_ok = TRUE;
74 return DDENUMRET_CANCEL;
76 return DDENUMRET_OK;
79 static BOOL createObjects(void)
81 HRESULT hr;
82 HMODULE hmod = GetModuleHandleA("ddraw.dll");
83 WNDCLASSA wc = {0};
84 DDSURFACEDESC2 ddsd;
85 DDPIXELFORMAT zfmt;
86 BOOL hal_ok = FALSE;
87 const GUID *devtype = &IID_IDirect3DHALDevice;
89 if(!hmod) return FALSE;
90 pDirectDrawCreateEx = (void*)GetProcAddress(hmod, "DirectDrawCreateEx");
91 if(!pDirectDrawCreateEx) return FALSE;
93 hr = pDirectDrawCreateEx(NULL, (void **) &DirectDraw, &IID_IDirectDraw7, NULL);
94 ok(hr==DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", hr);
95 if(!DirectDraw) goto err;
97 wc.lpfnWndProc = DefWindowProcA;
98 wc.lpszClassName = "d3d7_test_wc";
99 RegisterClassA(&wc);
100 window = CreateWindowA("d3d7_test_wc", "d3d7_test", WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION,
101 0, 0, 640, 480, 0, 0, 0, 0);
103 hr = IDirectDraw7_SetCooperativeLevel(DirectDraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
104 ok(hr == DD_OK, "IDirectDraw7_SetCooperativeLevel failed with %08x\n", hr);
105 if(FAILED(hr)) goto err;
106 hr = IDirectDraw7_SetDisplayMode(DirectDraw, 640, 480, 32, 0, 0);
107 if(FAILED(hr)) {
108 /* 24 bit is fine too */
109 hr = IDirectDraw7_SetDisplayMode(DirectDraw, 640, 480, 24, 0, 0);
112 ok(hr == DD_OK || hr == DDERR_UNSUPPORTED, "IDirectDraw7_SetDisplayMode failed with %08x\n", hr);
113 if(FAILED(hr)) {
114 /* use trace, the caller calls skip() */
115 trace("SetDisplayMode failed\n");
116 goto err;
119 hr = IDirectDraw7_QueryInterface(DirectDraw, &IID_IDirect3D7, (void**) &Direct3D);
120 if (hr == E_NOINTERFACE) goto err;
121 ok(hr==DD_OK, "QueryInterface returned: %08x\n", hr);
123 /* DirectDraw Flipping behavior doesn't seem that well-defined. The reference rasterizer behaves differently
124 * than hardware implementations. Request single buffering, that seems to work everywhere
126 memset(&ddsd, 0, sizeof(ddsd));
127 ddsd.dwSize = sizeof(ddsd);
128 ddsd.dwFlags = DDSD_CAPS;
129 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE;
130 ddsd.dwBackBufferCount = 1;
131 hr = IDirectDraw7_CreateSurface(DirectDraw, &ddsd, &Surface, NULL);
132 if(FAILED(hr)) goto err;
134 hr = IDirect3D7_EnumDevices(Direct3D, enum_devtype_cb, &hal_ok);
135 ok(SUCCEEDED(hr), "Failed to enumerate devices, hr %#x.\n", hr);
136 if (hal_ok) devtype = &IID_IDirect3DTnLHalDevice;
138 memset(&zfmt, 0, sizeof(zfmt));
139 hr = IDirect3D7_EnumZBufferFormats(Direct3D, devtype, enum_z_fmt, &zfmt);
140 if (FAILED(hr)) goto err;
141 if (zfmt.dwSize == 0) goto err;
143 memset(&ddsd, 0, sizeof(ddsd));
144 ddsd.dwSize = sizeof(ddsd);
145 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
146 ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
147 U4(ddsd).ddpfPixelFormat = zfmt;
148 ddsd.dwWidth = 640;
149 ddsd.dwHeight = 480;
150 hr = IDirectDraw7_CreateSurface(DirectDraw, &ddsd, &depth_buffer, NULL);
151 ok(SUCCEEDED(hr), "CreateSurface failed, hr %#x.\n", hr);
152 if (FAILED(hr)) goto err;
154 hr = IDirectDrawSurface_AddAttachedSurface(Surface, depth_buffer);
155 ok(SUCCEEDED(hr), "AddAttachedSurface failed, hr %#x.\n", hr);
156 if (FAILED(hr)) goto err;
158 hr = IDirect3D7_CreateDevice(Direct3D, devtype, Surface, &Direct3DDevice);
159 if (FAILED(hr) || !Direct3DDevice) goto err;
160 return TRUE;
162 err:
163 if(DirectDraw) IDirectDraw7_Release(DirectDraw);
164 if (depth_buffer) IDirectDrawSurface7_Release(depth_buffer);
165 if(Surface) IDirectDrawSurface7_Release(Surface);
166 if(Direct3D) IDirect3D7_Release(Direct3D);
167 if(Direct3DDevice) IDirect3DDevice7_Release(Direct3DDevice);
168 if(window) DestroyWindow(window);
169 return FALSE;
172 static void releaseObjects(void)
174 IDirect3DDevice7_Release(Direct3DDevice);
175 IDirect3D7_Release(Direct3D);
176 IDirectDrawSurface7_Release(depth_buffer);
177 IDirectDrawSurface7_Release(Surface);
178 IDirectDraw7_Release(DirectDraw);
179 DestroyWindow(window);
182 static DWORD getPixelColor(IDirect3DDevice7 *device, UINT x, UINT y)
184 DWORD ret;
185 HRESULT hr;
186 DDSURFACEDESC2 ddsd;
187 RECT rectToLock = {x, y, x+1, y+1};
188 IDirectDrawSurface7 *surf = NULL;
190 /* Some implementations seem to dislike direct locking on the front buffer. Thus copy the front buffer
191 * to an offscreen surface and lock it instead of the front buffer
193 memset(&ddsd, 0, sizeof(ddsd));
194 ddsd.dwSize = sizeof(ddsd);
195 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
196 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
197 ddsd.dwWidth = 640;
198 ddsd.dwHeight = 480;
199 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
200 hr = IDirectDraw7_CreateSurface(DirectDraw, &ddsd, &surf, NULL);
201 ok(hr == DD_OK, "IDirectDraw7_CreateSurface failed with %08x\n", hr);
202 if(!surf)
204 trace("cannot create helper surface\n");
205 return 0xdeadbeef;
208 memset(&ddsd, 0, sizeof(ddsd));
209 ddsd.dwSize = sizeof(ddsd);
210 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
212 hr = IDirectDrawSurface_BltFast(surf, 0, 0, Surface, NULL, 0);
213 ok(hr == DD_OK, "IDirectDrawSurface7_BltFast returned %08x\n", hr);
214 if(FAILED(hr))
216 trace("Cannot blit\n");
217 ret = 0xdeadbee;
218 goto out;
221 hr = IDirectDrawSurface7_Lock(surf, &rectToLock, &ddsd, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
222 if(FAILED(hr))
224 trace("Can't lock the offscreen surface, hr=%08x\n", hr);
225 ret = 0xdeadbeec;
226 goto out;
229 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
230 * really important for these tests
232 ret = ((DWORD *) ddsd.lpSurface)[0] & 0x00ffffff;
233 hr = IDirectDrawSurface7_Unlock(surf, NULL);
234 if(FAILED(hr))
236 trace("Can't unlock the offscreen surface, hr=%08x\n", hr);
239 out:
240 IDirectDrawSurface7_Release(surf);
241 return ret;
244 static void set_viewport_size(IDirect3DDevice7 *device)
246 D3DVIEWPORT7 vp = {0};
247 DDSURFACEDESC2 ddsd;
248 HRESULT hr;
249 IDirectDrawSurface7 *target;
251 hr = IDirect3DDevice7_GetRenderTarget(device, &target);
252 ok(hr == D3D_OK, "IDirect3DDevice7_GetRenderTarget returned %08x\n", hr);
254 memset(&ddsd, 0, sizeof(ddsd));
255 ddsd.dwSize = sizeof(ddsd);
256 hr = IDirectDrawSurface7_GetSurfaceDesc(target, &ddsd);
257 ok(hr == D3D_OK, "IDirectDrawSurface7_GetSurfaceDesc returned %08x\n", hr);
258 IDirectDrawSurface7_Release(target);
260 vp.dwWidth = ddsd.dwWidth;
261 vp.dwHeight = ddsd.dwHeight;
262 hr = IDirect3DDevice7_SetViewport(device, &vp);
263 ok(hr == D3D_OK, "IDirect3DDevice7_SetViewport returned %08x\n", hr);
264 return;
267 struct vertex
269 float x, y, z;
270 DWORD diffuse;
273 struct tvertex
275 float x, y, z, w;
276 DWORD diffuse;
279 struct nvertex
281 float x, y, z;
282 float nx, ny, nz;
283 DWORD diffuse;
286 static void lighting_test(IDirect3DDevice7 *device)
288 HRESULT hr;
289 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
290 DWORD nfvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_NORMAL;
291 DWORD color;
293 D3DMATRIX mat =
295 1.0f, 0.0f, 0.0f, 0.0f,
296 0.0f, 1.0f, 0.0f, 0.0f,
297 0.0f, 0.0f, 1.0f, 0.0f,
298 0.0f, 0.0f, 0.0f, 1.0f,
300 struct vertex unlitquad[] =
302 {-1.0f, -1.0f, 0.1f, 0xffff0000},
303 {-1.0f, 0.0f, 0.1f, 0xffff0000},
304 { 0.0f, 0.0f, 0.1f, 0xffff0000},
305 { 0.0f, -1.0f, 0.1f, 0xffff0000},
307 struct vertex litquad[] =
309 {-1.0f, 0.0f, 0.1f, 0xff00ff00},
310 {-1.0f, 1.0f, 0.1f, 0xff00ff00},
311 { 0.0f, 1.0f, 0.1f, 0xff00ff00},
312 { 0.0f, 0.0f, 0.1f, 0xff00ff00},
314 struct nvertex unlitnquad[] =
316 { 0.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
317 { 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
318 { 1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
319 { 1.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
321 struct nvertex litnquad[] =
323 { 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
324 { 0.0f, 1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
325 { 1.0f, 1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
326 { 1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
328 WORD Indices[] = {0, 1, 2, 2, 3, 0};
330 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
331 ok(hr == D3D_OK, "IDirect3DDevice7_Clear failed with %08x\n", hr);
333 /* Setup some states that may cause issues */
334 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
335 ok(hr == D3D_OK, "IDirect3DDevice7_SetTransform returned %08x\n", hr);
336 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
337 ok(hr == D3D_OK, "IDirect3DDevice7_SetTransform returned %08x\n", hr);
338 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
339 ok(hr == D3D_OK, "IDirect3DDevice7_SetTransform returned %08x\n", hr);
340 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
341 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned %08x\n", hr);
342 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
343 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned %08x\n", hr);
344 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
345 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned %08x\n", hr);
346 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_STENCILENABLE, FALSE);
347 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned %08x\n", hr);
348 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHATESTENABLE, FALSE);
349 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned %08x\n", hr);
350 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
351 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned %08x\n", hr);
352 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
353 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed with %08x\n", hr);
355 hr = IDirect3DDevice7_BeginScene(device);
356 ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed with %08x\n", hr);
357 if(hr == D3D_OK)
359 /* No lights are defined... That means, lit vertices should be entirely black */
360 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
361 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned %08x\n", hr);
362 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, fvf, unlitquad, 4 /* NumVerts */,
363 Indices, 6 /* Indexcount */, 0 /* flags */);
364 ok(hr == D3D_OK, "IDirect3DDevice7_DrawIndexedPrimitiveUP failed with %08x\n", hr);
366 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, TRUE);
367 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned %08x\n", hr);
368 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, fvf, litquad, 4 /* NumVerts */,
369 Indices, 6 /* Indexcount */, 0 /* flags */);
370 ok(hr == D3D_OK, "IDirect3DDevice7_DrawIndexedPrimitiveUP failed with %08x\n", hr);
372 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
373 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned %08x\n", hr);
374 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, unlitnquad, 4 /* NumVerts */,
375 Indices, 6 /* Indexcount */, 0 /* flags */);
376 ok(hr == D3D_OK, "IDirect3DDevice7_DrawIndexedPrimitiveUP failed with %08x\n", hr);
378 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, TRUE);
379 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned %08x\n", hr);
380 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, litnquad, 4 /* NumVerts */,
381 Indices, 6 /* Indexcount */, 0 /* flags */);
382 ok(hr == D3D_OK, "IDirect3DDevice7_DrawIndexedPrimitiveUP failed with %08x\n", hr);
384 hr = IDirect3DDevice7_EndScene(device);
385 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed with %08x\n", hr);
388 color = getPixelColor(device, 160, 360); /* Lower left quad - unlit without normals */
389 ok(color == 0x00ff0000, "Unlit quad without normals has color 0x%08x, expected 0x00ff0000.\n", color);
390 color = getPixelColor(device, 160, 120); /* Upper left quad - lit without normals */
391 ok(color == 0x00000000, "Lit quad without normals has color 0x%08x, expected 0x00000000.\n", color);
392 color = getPixelColor(device, 480, 360); /* Lower right quad - unlit with normals */
393 ok(color == 0x000000ff, "Unlit quad with normals has color 0x%08x, expected 0x000000ff.\n", color);
394 color = getPixelColor(device, 480, 120); /* Upper right quad - lit with normals */
395 ok(color == 0x00000000, "Lit quad with normals has color 0x%08x, expected 0x00000000.\n", color);
397 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
398 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned %08x\n", hr);
401 static void clear_test(IDirect3DDevice7 *device)
403 /* Tests the correctness of clearing parameters */
404 HRESULT hr;
405 D3DRECT rect[2];
406 D3DRECT rect_negneg;
407 DWORD color;
409 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
410 ok(hr == D3D_OK, "IDirect3DDevice7_Clear failed with %08x\n", hr);
412 /* Positive x, negative y */
413 U1(rect[0]).x1 = 0;
414 U2(rect[0]).y1 = 480;
415 U3(rect[0]).x2 = 320;
416 U4(rect[0]).y2 = 240;
418 /* Positive x, positive y */
419 U1(rect[1]).x1 = 0;
420 U2(rect[1]).y1 = 0;
421 U3(rect[1]).x2 = 320;
422 U4(rect[1]).y2 = 240;
423 /* Clear 2 rectangles with one call. Shows that a positive value is returned, but the negative rectangle
424 * is ignored, the positive is still cleared afterwards
426 hr = IDirect3DDevice7_Clear(device, 2, rect, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
427 ok(hr == D3D_OK, "IDirect3DDevice7_Clear failed with %08x\n", hr);
429 /* negative x, negative y */
430 U1(rect_negneg).x1 = 640;
431 U2(rect_negneg).y1 = 240;
432 U3(rect_negneg).x2 = 320;
433 U4(rect_negneg).y2 = 0;
434 hr = IDirect3DDevice7_Clear(device, 1, &rect_negneg, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
435 ok(hr == D3D_OK, "IDirect3DDevice7_Clear failed with %08x\n", hr);
437 color = getPixelColor(device, 160, 360); /* lower left quad */
438 ok(color == 0x00ffffff, "Clear rectangle 3(pos, neg) has color %08x\n", color);
439 color = getPixelColor(device, 160, 120); /* upper left quad */
440 ok(color == 0x00ff0000, "Clear rectangle 1(pos, pos) has color %08x\n", color);
441 color = getPixelColor(device, 480, 360); /* lower right quad */
442 ok(color == 0x00ffffff, "Clear rectangle 4(NULL) has color %08x\n", color);
443 color = getPixelColor(device, 480, 120); /* upper right quad */
444 ok(color == 0x00ffffff, "Clear rectangle 4(neg, neg) has color %08x\n", color);
447 struct sVertex {
448 float x, y, z;
449 DWORD diffuse;
450 DWORD specular;
453 struct sVertexT {
454 float x, y, z, rhw;
455 DWORD diffuse;
456 DWORD specular;
459 static void fog_test(IDirect3DDevice7 *device)
461 HRESULT hr;
462 DWORD color;
463 float start = 0.0, end = 1.0;
464 D3DDEVICEDESC7 caps;
466 /* Gets full z based fog with linear fog, no fog with specular color */
467 struct sVertex untransformed_1[] = {
468 {-1, -1, 0.1f, 0xFFFF0000, 0xFF000000 },
469 {-1, 0, 0.1f, 0xFFFF0000, 0xFF000000 },
470 { 0, 0, 0.1f, 0xFFFF0000, 0xFF000000 },
471 { 0, -1, 0.1f, 0xFFFF0000, 0xFF000000 },
473 /* Ok, I am too lazy to deal with transform matrices */
474 struct sVertex untransformed_2[] = {
475 {-1, 0, 1.0f, 0xFFFF0000, 0xFF000000 },
476 {-1, 1, 1.0f, 0xFFFF0000, 0xFF000000 },
477 { 0, 1, 1.0f, 0xFFFF0000, 0xFF000000 },
478 { 0, 0, 1.0f, 0xFFFF0000, 0xFF000000 },
480 /* Untransformed ones. Give them a different diffuse color to make the test look
481 * nicer. It also makes making sure that they are drawn correctly easier.
483 struct sVertexT transformed_1[] = {
484 {320, 0, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
485 {640, 0, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
486 {640, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
487 {320, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
489 struct sVertexT transformed_2[] = {
490 {320, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
491 {640, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
492 {640, 480, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
493 {320, 480, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
495 WORD Indices[] = {0, 1, 2, 2, 3, 0};
496 D3DMATRIX ident_mat =
498 1.0f, 0.0f, 0.0f, 0.0f,
499 0.0f, 1.0f, 0.0f, 0.0f,
500 0.0f, 0.0f, 1.0f, 0.0f,
501 0.0f, 0.0f, 0.0f, 1.0f,
503 D3DMATRIX world_mat1 =
505 1.0f, 0.0f, 0.0f, 0.0f,
506 0.0f, 1.0f, 0.0f, 0.0f,
507 0.0f, 0.0f, 1.0f, 0.0f,
508 0.0f, 0.0f, -0.5f, 1.0f,
510 D3DMATRIX world_mat2 =
512 1.0f, 0.0f, 0.0f, 0.0f,
513 0.0f, 1.0f, 0.0f, 0.0f,
514 0.0f, 0.0f, 1.0f, 0.0f,
515 0.0f, 0.0f, 1.0f, 1.0f,
517 D3DMATRIX proj_mat =
519 1.0f, 0.0f, 0.0f, 0.0f,
520 0.0f, 1.0f, 0.0f, 0.0f,
521 0.0f, 0.0f, 1.0f, 0.0f,
522 0.0f, 0.0f, -1.0f, 1.0f,
524 struct sVertex far_quad1[] =
526 {-1.0f, -1.0f, 0.5f, 0xffff0000, 0xff000000},
527 {-1.0f, 0.0f, 0.5f, 0xffff0000, 0xff000000},
528 { 0.0f, 0.0f, 0.5f, 0xffff0000, 0xff000000},
529 { 0.0f, -1.0f, 0.5f, 0xffff0000, 0xff000000},
531 struct sVertex far_quad2[] =
533 {-1.0f, 0.0f, 1.5f, 0xffff0000, 0xff000000},
534 {-1.0f, 1.0f, 1.5f, 0xffff0000, 0xff000000},
535 { 0.0f, 1.0f, 1.5f, 0xffff0000, 0xff000000},
536 { 0.0f, 0.0f, 1.5f, 0xffff0000, 0xff000000},
539 memset(&caps, 0, sizeof(caps));
540 hr = IDirect3DDevice7_GetCaps(device, &caps);
541 ok(hr == D3D_OK, "IDirect3DDevice7_GetCaps returned %08x\n", hr);
542 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
543 ok(hr == D3D_OK, "IDirect3DDevice7_Clear returned %08x\n", hr);
545 /* Setup initial states: No lighting, fog on, fog color */
546 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
547 ok(hr == D3D_OK, "Turning off lighting returned %08x\n", hr);
548 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
549 ok(hr == D3D_OK, "Turning on fog calculations returned %08x\n", hr);
550 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0xFF00FF00 /* A nice green */);
551 ok(hr == D3D_OK, "Setting fog color returned %08x\n", hr);
553 /* First test: Both table fog and vertex fog off */
554 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, D3DFOG_NONE);
555 ok(hr == D3D_OK, "Turning off table fog returned %08x\n", hr);
556 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, D3DFOG_NONE);
557 ok(hr == D3D_OK, "Turning off vertex fog returned %08x\n", hr);
559 /* Start = 0, end = 1. Should be default, but set them */
560 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGSTART, *((DWORD *) &start));
561 ok(hr == D3D_OK, "Setting fog start returned %08x\n", hr);
562 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGEND, *((DWORD *) &end));
563 ok(hr == D3D_OK, "Setting fog end returned %08x\n", hr);
565 if(IDirect3DDevice7_BeginScene(device) == D3D_OK)
567 /* Untransformed, vertex fog = NONE, table fog = NONE: Read the fog weighting from the specular color */
568 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR,
569 untransformed_1, 4, Indices, 6, 0);
570 ok(hr == D3D_OK, "DrawIndexedPrimitive returned %08x\n", hr);
572 /* That makes it use the Z value */
573 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, D3DFOG_LINEAR);
574 ok(hr == D3D_OK, "Setting fog vertex mode to D3DFOG_LINEAR returned %08x\n", hr);
575 /* Untransformed, vertex fog != none (or table fog != none):
576 * Use the Z value as input into the equation
578 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR,
579 untransformed_2, 4, Indices, 6, 0);
580 ok(hr == D3D_OK, "DrawIndexedPrimitive returned %08x\n", hr);
582 /* Transformed, vertex fog != NONE, pixel fog == NONE: Use specular color alpha component */
583 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR,
584 transformed_1, 4, Indices, 6, 0);
585 ok(hr == D3D_OK, "DrawIndexedPrimitive returned %08x\n", hr);
587 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, D3DFOG_LINEAR);
588 ok( hr == D3D_OK, "Setting fog table mode to D3DFOG_LINEAR returned %08x\n", hr);
589 /* Transformed, table fog != none, vertex anything: Use Z value as input to the fog
590 * equation
592 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR,
593 transformed_2, 4, Indices, 6, 0);
594 ok(hr == D3D_OK, "DrawIndexedPrimitive returned %08x\n", hr);
596 hr = IDirect3DDevice7_EndScene(device);
597 ok(hr == D3D_OK, "EndScene returned %08x\n", hr);
599 else
601 ok(FALSE, "BeginScene failed\n");
604 color = getPixelColor(device, 160, 360);
605 ok(color_match(color, 0x00FF0000, 1), "Untransformed vertex with no table or vertex fog has color %08x\n", color);
606 color = getPixelColor(device, 160, 120);
607 ok(color_match(color, 0x0000FF00, 1), "Untransformed vertex with linear vertex fog has color %08x\n", color);
608 color = getPixelColor(device, 480, 120);
609 ok(color_match(color, 0x00FFFF00, 1), "Transformed vertex with linear vertex fog has color %08x\n", color);
610 if(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE)
612 color = getPixelColor(device, 480, 360);
613 ok(color_match(color, 0x0000FF00, 1), "Transformed vertex with linear table fog has color %08x\n", color);
615 else
617 /* Without fog table support the vertex fog is still applied, even though table fog is turned on.
618 * The settings above result in no fogging with vertex fog
620 color = getPixelColor(device, 480, 120);
621 ok(color == 0x00FFFF00, "Transformed vertex with linear vertex fog has color %08x\n", color);
622 trace("Info: Table fog not supported by this device\n");
625 if (caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE)
627 /* A simple fog + non-identity world matrix test */
628 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &world_mat1);
629 ok(hr == D3D_OK, "IDirect3DDevice7_SetTransform returned %#08x\n", hr);
631 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, D3DFOG_LINEAR);
632 ok(hr == D3D_OK, "Setting fog table mode to D3DFOG_LINEAR returned %#08x\n", hr);
633 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, D3DFOG_NONE);
634 ok(hr == D3D_OK, "Turning off vertex fog returned %#08x\n", hr);
636 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
637 ok(hr == D3D_OK, "IDirect3DDevice7_Clear returned %#08x\n", hr);
639 if (IDirect3DDevice7_BeginScene(device) == D3D_OK)
641 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST,
642 D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR, far_quad1, 4, Indices, 6, 0);
643 ok(hr == D3D_OK, "DrawIndexedPrimitive returned %#08x\n", hr);
645 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST,
646 D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR, far_quad2, 4, Indices, 6, 0);
647 ok(hr == D3D_OK, "DrawIndexedPrimitive returned %#08x\n", hr);
649 hr = IDirect3DDevice7_EndScene(device);
650 ok(hr == D3D_OK, "EndScene returned %#08x\n", hr);
652 else
654 ok(FALSE, "BeginScene failed\n");
657 color = getPixelColor(device, 160, 360);
658 ok(color_match(color, 0x00ff0000, 4), "Unfogged quad has color %08x\n", color);
659 color = getPixelColor(device, 160, 120);
660 ok(color_match(color, 0x0000ff00, 1), "Fogged out quad has color %08x\n", color);
662 /* Test fog behavior with an orthogonal (but not identity) projection matrix */
663 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &world_mat2);
664 ok(hr == D3D_OK, "SetTransform returned %#08x\n", hr);
665 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &proj_mat);
666 ok(hr == D3D_OK, "SetTransform returned %#08x\n", hr);
668 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
669 ok(hr == D3D_OK, "Clear returned %#08x\n", hr);
671 if (IDirect3DDevice7_BeginScene(device) == D3D_OK)
673 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST,
674 D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR, untransformed_1, 4, Indices, 6, 0);
675 ok(hr == D3D_OK, "DrawIndexedPrimitiveUP returned %#08x\n", hr);
677 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST,
678 D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR, untransformed_2, 4, Indices, 6, 0);
679 ok(hr == D3D_OK, "DrawIndexedPrimitiveUP returned %#08x\n", hr);
681 hr = IDirect3DDevice7_EndScene(device);
682 ok(hr == D3D_OK, "EndScene returned %#08x\n", hr);
684 else
686 ok(FALSE, "BeginScene failed\n");
689 color = getPixelColor(device, 160, 360);
690 ok(color_match(color, 0x00e51900, 4), "Partially fogged quad has color %08x\n", color);
691 color = getPixelColor(device, 160, 120);
692 ok(color_match(color, 0x0000ff00, 1), "Fogged out quad has color %08x\n", color);
694 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &ident_mat);
695 ok(hr == D3D_OK, "SetTransform returned %#08x\n", hr);
696 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &ident_mat);
697 ok(hr == D3D_OK, "SetTransform returned %#08x\n", hr);
699 else
701 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests\n");
704 /* Turn off the fog master switch to avoid confusing other tests */
705 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
706 ok(hr == D3D_OK, "Turning off fog calculations returned %08x\n", hr);
709 static void blt_test(IDirect3DDevice7 *device)
711 IDirectDrawSurface7 *backbuffer = NULL, *offscreen = NULL;
712 DDSURFACEDESC2 ddsd;
713 HRESULT hr;
715 memset(&ddsd, 0, sizeof(ddsd));
716 ddsd.dwSize = sizeof(ddsd);
717 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
718 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
719 ddsd.dwWidth = 640;
720 ddsd.dwHeight = 480;
721 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_3DDEVICE;
722 hr = IDirectDraw7_CreateSurface(DirectDraw, &ddsd, &offscreen, NULL);
723 ok(hr == D3D_OK, "Creating the offscreen render target failed, hr = %08x\n", hr);
725 /* Offscreen blits with the same source as destination */
726 if(SUCCEEDED(hr))
728 RECT src_rect, dst_rect;
730 /* Blit the whole surface to itself */
731 hr = IDirectDrawSurface_Blt(offscreen, NULL, offscreen, NULL, 0, NULL);
732 ok(hr == DD_OK, "IDirectDrawSurface7_Blt returned %08x\n", hr);
734 /* Overlapped blit */
735 dst_rect.left = 0; dst_rect.right = 480;
736 dst_rect.top = 0; dst_rect.bottom = 480;
737 src_rect.left = 160; src_rect.right = 640;
738 src_rect.top = 0; src_rect.bottom = 480;
739 hr = IDirectDrawSurface_Blt(offscreen, &dst_rect, offscreen, &src_rect, 0, NULL);
740 ok(hr == DD_OK, "IDirectDrawSurface7_Blt returned %08x\n", hr);
742 /* Overlapped blit, flip-y through source rectangle (not allowed) */
743 dst_rect.left = 0; dst_rect.right = 480;
744 dst_rect.top = 0; dst_rect.bottom = 480;
745 src_rect.left = 160; src_rect.right = 640;
746 src_rect.top = 480; src_rect.bottom = 0;
747 hr = IDirectDrawSurface_Blt(offscreen, &dst_rect, offscreen, &src_rect, 0, NULL);
748 ok(hr == DDERR_INVALIDRECT, "IDirectDrawSurface7_Blt returned %08x\n", hr);
750 /* Overlapped blit, with shrinking in x */
751 dst_rect.left = 0; dst_rect.right = 480;
752 dst_rect.top = 0; dst_rect.bottom = 480;
753 src_rect.left = 160; src_rect.right = 480;
754 src_rect.top = 0; src_rect.bottom = 480;
755 hr = IDirectDrawSurface_Blt(offscreen, &dst_rect, offscreen, &src_rect, 0, NULL);
756 ok(hr == DD_OK, "IDirectDrawSurface7_Blt returned %08x\n", hr);
759 hr = IDirect3DDevice7_GetRenderTarget(device, &backbuffer);
760 ok(hr == D3D_OK, "Unable to obtain a surface pointer to the backbuffer, hr = %08x\n", hr);
762 /* backbuffer ==> texture blits */
763 if(SUCCEEDED(hr) && offscreen)
765 RECT src_rect, dst_rect;
767 /* backbuffer ==> texture, src_rect=NULL, dst_rect=NULL, no scaling */
768 hr = IDirectDrawSurface_Blt(offscreen, NULL, backbuffer, NULL, 0, NULL);
769 ok(hr == DD_OK, "fullscreen Blt from backbuffer => texture failed with hr = %08x\n", hr);
771 /* backbuffer ==> texture, full surface blits, no scaling */
772 dst_rect.left = 0; dst_rect.right = 640;
773 dst_rect.top = 0; dst_rect.bottom = 480;
774 src_rect.left = 0; src_rect.right = 640;
775 src_rect.top = 0; src_rect.bottom = 480;
776 hr = IDirectDrawSurface_Blt(offscreen, &dst_rect, backbuffer, &src_rect, 0, NULL);
777 ok(hr == DD_OK, "fullscreen Blt from backbuffer => texture failed with hr = %08x\n", hr);
779 /* backbuffer ==> texture, flip in y-direction through source rectangle, no scaling (allowed) */
780 dst_rect.left = 0; dst_rect.right = 640;
781 dst_rect.top = 480; dst_rect.top = 0;
782 src_rect.left = 0; src_rect.right = 640;
783 src_rect.top = 0; src_rect.bottom = 480;
784 hr = IDirectDrawSurface_Blt(offscreen, &dst_rect, backbuffer, &src_rect, 0, NULL);
785 ok(hr == DD_OK, "backbuffer => texture flip-y src_rect failed with hr = %08x\n", hr);
787 /* backbuffer ==> texture, flip in x-direction through source rectangle, no scaling (not allowed) */
788 dst_rect.left = 640; dst_rect.right = 0;
789 dst_rect.top = 0; dst_rect.top = 480;
790 src_rect.left = 0; src_rect.right = 640;
791 src_rect.top = 0; src_rect.bottom = 480;
792 hr = IDirectDrawSurface_Blt(offscreen, &dst_rect, backbuffer, &src_rect, 0, NULL);
793 ok(hr == DDERR_INVALIDRECT, "backbuffer => texture flip-x src_rect failed with hr = %08x\n", hr);
795 /* backbuffer ==> texture, flip in y-direction through destination rectangle (not allowed) */
796 dst_rect.left = 0; dst_rect.right = 640;
797 dst_rect.top = 0; dst_rect.top = 480;
798 src_rect.left = 0; src_rect.right = 640;
799 src_rect.top = 480; src_rect.bottom = 0;
800 hr = IDirectDrawSurface_Blt(offscreen, &dst_rect, backbuffer, &src_rect, 0, NULL);
801 ok(hr == DDERR_INVALIDRECT, "backbuffer => texture flip-y dst_rect failed with hr = %08x\n", hr);
803 /* backbuffer ==> texture, flip in x-direction through destination rectangle, no scaling (not allowed) */
804 dst_rect.left = 0; dst_rect.right = 640;
805 dst_rect.top = 0; dst_rect.top = 480;
806 src_rect.left = 640; src_rect.right = 0;
807 src_rect.top = 0; src_rect.bottom = 480;
808 hr = IDirectDrawSurface_Blt(offscreen, &dst_rect, backbuffer, &src_rect, 0, NULL);
809 ok(hr == DDERR_INVALIDRECT, "backbuffer => texture flip-x dst_rect failed with hr = %08x\n", hr);
812 if(offscreen) IDirectDrawSurface7_Release(offscreen);
813 if(backbuffer) IDirectDrawSurface7_Release(backbuffer);
816 static void offscreen_test(IDirect3DDevice7 *device)
818 HRESULT hr;
819 IDirectDrawSurface7 *backbuffer = NULL, *offscreen = NULL;
820 DWORD color;
821 DDSURFACEDESC2 ddsd;
823 static float quad[][5] = {
824 {-0.5f, -0.5f, 0.1f, 0.0f, 0.0f},
825 {-0.5f, 0.5f, 0.1f, 0.0f, 1.0f},
826 { 0.5f, -0.5f, 0.1f, 1.0f, 0.0f},
827 { 0.5f, 0.5f, 0.1f, 1.0f, 1.0f},
830 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
831 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
833 memset(&ddsd, 0, sizeof(ddsd));
834 ddsd.dwSize = sizeof(ddsd);
835 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
836 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
837 ddsd.dwWidth = 128;
838 ddsd.dwHeight = 128;
839 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_3DDEVICE;
840 hr = IDirectDraw7_CreateSurface(DirectDraw, &ddsd, &offscreen, NULL);
841 ok(hr == D3D_OK, "Creating the offscreen render target failed, hr = %08x\n", hr);
842 if(!offscreen) {
843 goto out;
846 hr = IDirect3DDevice7_GetRenderTarget(device, &backbuffer);
847 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
848 if(!backbuffer) {
849 goto out;
852 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
853 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
854 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
855 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
856 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_MINFILTER, D3DFILTER_NEAREST);
857 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MINFILTER failed (0x%08x)\n", hr);
858 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_MAGFILTER, D3DFILTER_NEAREST);
859 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr);
860 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
861 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned hr = %08x\n", hr);
863 if (refdevice) {
864 win_skip("Tests would crash on W2K with a refdevice\n");
865 goto out;
868 if(IDirect3DDevice7_BeginScene(device) == D3D_OK) {
869 hr = IDirect3DDevice7_SetRenderTarget(device, offscreen, 0);
870 ok(hr == D3D_OK, "SetRenderTarget failed, hr = %08x\n", hr);
871 set_viewport_size(device);
872 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
873 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
875 /* Draw without textures - Should result in a white quad */
876 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEX1, quad, 4, 0);
877 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
879 hr = IDirect3DDevice7_SetRenderTarget(device, backbuffer, 0);
880 ok(hr == D3D_OK, "SetRenderTarget failed, hr = %08x\n", hr);
881 set_viewport_size(device);
883 hr = IDirect3DDevice7_SetTexture(device, 0, offscreen);
884 ok(hr == D3D_OK, "SetTexture failed, %08x\n", hr);
886 /* This time with the texture */
887 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEX1, quad, 4, 0);
888 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
890 IDirect3DDevice7_EndScene(device);
893 /* Center quad - should be white */
894 color = getPixelColor(device, 320, 240);
895 ok(color == 0x00ffffff, "Offscreen failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
896 /* Some quad in the cleared part of the texture */
897 color = getPixelColor(device, 170, 240);
898 ok(color == 0x00ff00ff, "Offscreen failed: Got color 0x%08x, expected 0x00ff00ff.\n", color);
899 /* Part of the originally cleared back buffer */
900 color = getPixelColor(device, 10, 10);
901 ok(color == 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
902 if(0) {
903 /* Lower left corner of the screen, where back buffer offscreen rendering draws the offscreen texture.
904 * It should be red, but the offscreen texture may leave some junk there. Not tested yet. Depending on
905 * the offscreen rendering mode this test would succeed or fail
907 color = getPixelColor(device, 10, 470);
908 ok(color == 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
911 out:
912 hr = IDirect3DDevice7_SetTexture(device, 0, NULL);
913 ok(SUCCEEDED(hr), "IDirect3DDevice7_SetTexture returned %#x.\n", hr);
915 /* restore things */
916 if(backbuffer) {
917 hr = IDirect3DDevice7_SetRenderTarget(device, backbuffer, 0);
918 ok(SUCCEEDED(hr), "IDirect3DDevice7_SetRenderTarget returned %#x.\n", hr);
919 IDirectDrawSurface7_Release(backbuffer);
921 if(offscreen) {
922 IDirectDrawSurface7_Release(offscreen);
926 static void alpha_test(IDirect3DDevice7 *device)
928 HRESULT hr;
929 IDirectDrawSurface7 *backbuffer = NULL, *offscreen = NULL;
930 DWORD color, red, green, blue;
931 DDSURFACEDESC2 ddsd;
933 struct vertex quad1[] =
935 {-1.0f, -1.0f, 0.1f, 0x4000ff00},
936 {-1.0f, 0.0f, 0.1f, 0x4000ff00},
937 { 1.0f, -1.0f, 0.1f, 0x4000ff00},
938 { 1.0f, 0.0f, 0.1f, 0x4000ff00},
940 struct vertex quad2[] =
942 {-1.0f, 0.0f, 0.1f, 0xc00000ff},
943 {-1.0f, 1.0f, 0.1f, 0xc00000ff},
944 { 1.0f, 0.0f, 0.1f, 0xc00000ff},
945 { 1.0f, 1.0f, 0.1f, 0xc00000ff},
947 static float composite_quad[][5] = {
948 { 0.0f, -1.0f, 0.1f, 0.0f, 1.0f},
949 { 0.0f, 1.0f, 0.1f, 0.0f, 0.0f},
950 { 1.0f, -1.0f, 0.1f, 1.0f, 1.0f},
951 { 1.0f, 1.0f, 0.1f, 1.0f, 0.0f},
954 /* Clear the render target with alpha = 0.5 */
955 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x80ff0000, 0.0, 0);
956 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
958 memset(&ddsd, 0, sizeof(ddsd));
959 ddsd.dwSize = sizeof(ddsd);
960 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
961 ddsd.dwWidth = 128;
962 ddsd.dwHeight = 128;
963 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_3DDEVICE;
964 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
965 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
966 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
967 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
968 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
969 U5(U4(ddsd).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
970 hr = IDirectDraw7_CreateSurface(DirectDraw, &ddsd, &offscreen, NULL);
971 ok(hr == D3D_OK, "Creating the offscreen render target failed, hr = %08x\n", hr);
972 if(!offscreen) {
973 goto out;
975 hr = IDirect3DDevice7_GetRenderTarget(device, &backbuffer);
976 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
977 if(!backbuffer) {
978 goto out;
981 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
982 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
983 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
984 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
985 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_MINFILTER, D3DFILTER_NEAREST);
986 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MINFILTER failed (0x%08x)\n", hr);
987 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_MAGFILTER, D3DFILTER_NEAREST);
988 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr);
990 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
991 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
993 if (refdevice) {
994 win_skip("Tests would crash on W2K with a refdevice\n");
995 goto out;
998 if(IDirect3DDevice7_BeginScene(device) == D3D_OK) {
1000 /* Draw two quads, one with src alpha blending, one with dest alpha blending. The
1001 * SRCALPHA / INVSRCALPHA blend doesn't give any surprises. Colors are blended based on
1002 * the input alpha
1004 * The DESTALPHA / INVDESTALPHA do not "work" on the regular buffer because there is no alpha.
1005 * They give essentially ZERO and ONE blend factors
1007 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
1008 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
1009 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
1010 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
1011 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad1, 4, 0);
1012 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
1014 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_DESTALPHA);
1015 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
1016 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVDESTALPHA);
1017 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
1018 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad2, 4, 0);
1019 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
1021 /* Switch to the offscreen buffer, and redo the testing. SRCALPHA and DESTALPHA. The offscreen buffer
1022 * has an alpha channel on its own. Clear the offscreen buffer with alpha = 0.5 again, then draw the
1023 * quads again. The SRCALPHA/INVSRCALPHA doesn't give any surprises, but the DESTALPHA/INVDESTALPHA
1024 * blending works as supposed now - blend factor is 0.5 in both cases, not 0.75 as from the input
1025 * vertices
1027 hr = IDirect3DDevice7_SetRenderTarget(device, offscreen, 0);
1028 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderTarget failed, hr = %08x\n", hr);
1029 set_viewport_size(device);
1030 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x80ff0000, 0.0, 0);
1031 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
1033 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
1034 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
1035 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
1036 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
1037 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad1, 4, 0);
1038 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
1040 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_DESTALPHA);
1041 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
1042 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVDESTALPHA);
1043 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
1044 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad2, 4, 0);
1045 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
1047 hr = IDirect3DDevice7_SetRenderTarget(device, backbuffer, 0);
1048 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderTarget failed, hr = %08x\n", hr);
1049 set_viewport_size(device);
1051 /* Render the offscreen texture onto the frame buffer to be able to compare it regularly.
1052 * Disable alpha blending for the final composition
1054 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
1055 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
1057 hr = IDirect3DDevice7_SetTexture(device, 0, offscreen);
1058 ok(hr == D3D_OK, "IDirect3DDevice7_SetTexture failed, hr = %08x\n", hr);
1059 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEX1, composite_quad, 4, 0);
1060 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
1061 hr = IDirect3DDevice7_SetTexture(device, 0, NULL);
1062 ok(hr == D3D_OK, "IDirect3DDevice7_SetTexture failed, hr = %08x\n", hr);
1064 hr = IDirect3DDevice7_EndScene(device);
1065 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed, hr = %08x\n", hr);
1068 color = getPixelColor(device, 160, 360);
1069 red = (color & 0x00ff0000) >> 16;
1070 green = (color & 0x0000ff00) >> 8;
1071 blue = (color & 0x000000ff);
1072 ok(red >= 0xbe && red <= 0xc0 && green >= 0x39 && green <= 0x41 && blue == 0x00,
1073 "SRCALPHA on frame buffer returned color 0x%08x, expected 0x00bf4000\n", color);
1075 color = getPixelColor(device, 160, 120);
1076 red = (color & 0x00ff0000) >> 16;
1077 green = (color & 0x0000ff00) >> 8;
1078 blue = (color & 0x000000ff);
1079 ok(red == 0x00 && green == 0x00 && blue >= 0xfe && blue <= 0xff ,
1080 "DSTALPHA on frame buffer returned color 0x%08x, expected 0x000000ff\n", color);
1082 color = getPixelColor(device, 480, 360);
1083 red = (color & 0x00ff0000) >> 16;
1084 green = (color & 0x0000ff00) >> 8;
1085 blue = (color & 0x000000ff);
1086 ok(red >= 0xbe && red <= 0xc0 && green >= 0x39 && green <= 0x41 && blue == 0x00,
1087 "SRCALPHA on texture returned color 0x%08x, expected 0x00bf4000\n", color);
1089 color = getPixelColor(device, 480, 120);
1090 red = (color & 0x00ff0000) >> 16;
1091 green = (color & 0x0000ff00) >> 8;
1092 blue = (color & 0x000000ff);
1093 ok(red >= 0x7e && red <= 0x81 && green == 0x00 && blue >= 0x7e && blue <= 0x81,
1094 "DSTALPHA on texture returned color 0x%08x, expected 0x00800080\n", color);
1096 out:
1097 if(offscreen) IDirectDrawSurface7_Release(offscreen);
1098 if(backbuffer) IDirectDrawSurface7_Release(backbuffer);
1101 static void rhw_zero_test(IDirect3DDevice7 *device)
1103 /* Test if it will render a quad correctly when vertex rhw = 0 */
1104 HRESULT hr;
1105 DWORD color;
1107 struct {
1108 float x, y, z;
1109 float rhw;
1110 DWORD diffuse;
1111 } quad1[] =
1113 {0, 100, 0, 0, 0xffffffff},
1114 {0, 0, 0, 0, 0xffffffff},
1115 {100, 100, 0, 0, 0xffffffff},
1116 {100, 0, 0, 0, 0xffffffff},
1119 /* Clear to black */
1120 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0, 0.0, 0);
1121 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
1123 hr = IDirect3DDevice7_BeginScene(device);
1124 ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed with %08x\n", hr);
1126 if (SUCCEEDED(hr)) {
1127 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, quad1, 4, 0);
1128 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
1130 hr = IDirect3DDevice7_EndScene(device);
1131 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed, hr = %08x\n", hr);
1134 color = getPixelColor(device, 5, 5);
1135 ok(color == 0xffffff ||
1136 broken(color == 0), /* VMware */
1137 "Got color %08x, expected 00ffffff\n", color);
1139 color = getPixelColor(device, 105, 105);
1140 ok(color == 0, "Got color %08x, expected 00000000\n", color);
1143 static BOOL D3D1_createObjects(void)
1145 WNDCLASSA wc = {0};
1146 HRESULT hr;
1147 DDSURFACEDESC ddsd;
1148 D3DEXECUTEBUFFERDESC exdesc;
1149 D3DVIEWPORT vp_data;
1151 /* An IDirect3DDevice cannot be queryInterfaced from an IDirect3DDevice7 on windows */
1152 hr = DirectDrawCreate(NULL, &DirectDraw1, NULL);
1154 ok(hr==DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreate returned: %x\n", hr);
1155 if (FAILED(hr)) {
1156 return FALSE;
1159 wc.lpfnWndProc = DefWindowProcA;
1160 wc.lpszClassName = "texturemapblend_test_wc";
1161 RegisterClassA(&wc);
1162 window = CreateWindowA("texturemapblend_test_wc", "texturemapblend_test",
1163 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, 640, 480, 0, 0, 0, 0);
1165 hr = IDirectDraw_SetCooperativeLevel(DirectDraw1, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1166 ok(hr==DD_OK, "SetCooperativeLevel returned: %x\n", hr);
1167 if(FAILED(hr)) {
1168 return FALSE;
1171 hr = IDirectDraw_SetDisplayMode(DirectDraw1, 640, 480, 32);
1172 if(FAILED(hr)) {
1173 /* 24 bit is fine too */
1174 hr = IDirectDraw_SetDisplayMode(DirectDraw1, 640, 480, 24);
1176 ok(hr==DD_OK || hr == DDERR_UNSUPPORTED, "SetDisplayMode returned: %x\n", hr);
1177 if (FAILED(hr)) {
1178 return FALSE;
1181 hr = IDirectDraw_QueryInterface(DirectDraw1, &IID_IDirect3D, (void**) &Direct3D1);
1182 ok(hr==DD_OK, "QueryInterface returned: %x\n", hr);
1183 if (FAILED(hr)) {
1184 return FALSE;
1187 memset(&ddsd, 0, sizeof(ddsd));
1188 ddsd.dwSize = sizeof(ddsd);
1189 ddsd.dwFlags = DDSD_CAPS;
1190 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE;
1191 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &Surface1, NULL);
1192 ok(hr==DD_OK, "CreateSurface returned: %x\n", hr);
1193 if (FAILED(hr)) {
1194 return FALSE;
1197 hr = IDirectDrawSurface_QueryInterface(Surface1, &IID_IDirect3DHALDevice, (void **) &Direct3DDevice1);
1198 if(FAILED(hr)) {
1199 trace("Creating a HAL device failed, trying Ref\n");
1200 hr = IDirectDrawSurface_QueryInterface(Surface1, &IID_IDirect3DRefDevice, (void **) &Direct3DDevice1);
1202 ok(hr==D3D_OK, "Creating 3D device returned: %x\n", hr);
1203 if(FAILED(hr)) {
1204 return FALSE;
1207 hr = IDirect3D_CreateViewport(Direct3D1, &Viewport, NULL);
1208 ok(hr == D3D_OK, "IDirect3D_CreateViewport failed: %08x\n", hr);
1209 if (FAILED(hr)) {
1210 return FALSE;
1213 hr = IDirect3DViewport_Initialize(Viewport, Direct3D1);
1214 ok(hr == D3D_OK || hr == DDERR_ALREADYINITIALIZED, "IDirect3DViewport_Initialize returned %08x\n", hr);
1215 hr = IDirect3DDevice_AddViewport(Direct3DDevice1, Viewport);
1216 ok(hr == D3D_OK, "IDirect3DDevice_AddViewport returned %08x\n", hr);
1217 vp_data.dwSize = sizeof(vp_data);
1218 vp_data.dwX = 0;
1219 vp_data.dwY = 0;
1220 vp_data.dwWidth = 640;
1221 vp_data.dwHeight = 480;
1222 vp_data.dvScaleX = 1;
1223 vp_data.dvScaleY = 1;
1224 vp_data.dvMaxX = 640;
1225 vp_data.dvMaxY = 480;
1226 vp_data.dvMinZ = 0;
1227 vp_data.dvMaxZ = 1;
1228 hr = IDirect3DViewport_SetViewport(Viewport, &vp_data);
1229 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1231 memset(&exdesc, 0, sizeof(D3DEXECUTEBUFFERDESC));
1232 exdesc.dwSize = sizeof(D3DEXECUTEBUFFERDESC);
1233 exdesc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
1234 exdesc.dwBufferSize = 512;
1235 exdesc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
1236 hr = IDirect3DDevice_CreateExecuteBuffer(Direct3DDevice1, &exdesc, &ExecuteBuffer, NULL);
1237 ok(hr == D3D_OK, "IDirect3DDevice_CreateExecuteBuffer failed with %08x\n", hr);
1238 if (FAILED(hr)) {
1239 return FALSE;
1242 return TRUE;
1245 static void D3D1_releaseObjects(void)
1247 if(ExecuteBuffer) IDirect3DExecuteBuffer_Release(ExecuteBuffer);
1248 if(Surface1) IDirectDrawSurface_Release(Surface1);
1249 if(Viewport) IDirect3DViewport_Release(Viewport);
1250 if(Direct3DDevice1) IDirect3DDevice_Release(Direct3DDevice1);
1251 if(Direct3D1) IDirect3D_Release(Direct3D1);
1252 if(DirectDraw1) IDirectDraw_Release(DirectDraw1);
1253 if(window) DestroyWindow(window);
1256 static DWORD D3D1_getPixelColor(IDirectDraw *DirectDraw1, IDirectDrawSurface *Surface, UINT x, UINT y)
1258 DWORD ret;
1259 HRESULT hr;
1260 DDSURFACEDESC ddsd;
1261 RECT rectToLock = {x, y, x+1, y+1};
1262 IDirectDrawSurface *surf = NULL;
1264 /* Some implementations seem to dislike direct locking on the front buffer. Thus copy the front buffer
1265 * to an offscreen surface and lock it instead of the front buffer
1267 memset(&ddsd, 0, sizeof(ddsd));
1268 ddsd.dwSize = sizeof(ddsd);
1269 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
1270 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
1271 ddsd.dwWidth = 640;
1272 ddsd.dwHeight = 480;
1273 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
1274 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &surf, NULL);
1275 ok(hr == DD_OK, "IDirectDraw_CreateSurface failed with %08x\n", hr);
1276 if(!surf)
1278 trace("cannot create helper surface\n");
1279 return 0xdeadbeef;
1282 memset(&ddsd, 0, sizeof(ddsd));
1283 ddsd.dwSize = sizeof(ddsd);
1284 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
1286 hr = IDirectDrawSurface_BltFast(surf, 0, 0, Surface, NULL, 0);
1287 ok(hr == DD_OK, "IDirectDrawSurface_BltFast returned %08x\n", hr);
1288 if(FAILED(hr))
1290 trace("Cannot blit\n");
1291 ret = 0xdeadbee;
1292 goto out;
1295 hr = IDirectDrawSurface_Lock(surf, &rectToLock, &ddsd, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
1296 if(FAILED(hr))
1298 trace("Can't lock the offscreen surface, hr=%08x\n", hr);
1299 ret = 0xdeadbeec;
1300 goto out;
1303 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
1304 * really important for these tests
1306 ret = ((DWORD *) ddsd.lpSurface)[0] & 0x00ffffff;
1307 hr = IDirectDrawSurface_Unlock(surf, NULL);
1308 if(FAILED(hr))
1310 trace("Can't unlock the offscreen surface, hr=%08x\n", hr);
1313 out:
1314 IDirectDrawSurface_Release(surf);
1315 return ret;
1318 #define EXEBUF_START_RENDER_STATES(count, ptr) do {\
1319 ((D3DINSTRUCTION*)(ptr))->bOpcode = D3DOP_STATERENDER;\
1320 ((D3DINSTRUCTION*)(ptr))->bSize = sizeof(D3DSTATE);\
1321 ((D3DINSTRUCTION*)(ptr))->wCount = count;\
1322 ptr = ((D3DINSTRUCTION*)(ptr))+1; } while (0)
1324 #define EXEBUF_PUT_RENDER_STATE(state, value, ptr) do {\
1325 U1(*((D3DSTATE*)(ptr))).drstRenderStateType = state; \
1326 U2(*((D3DSTATE*)(ptr))).dwArg[0] = value; \
1327 ptr = ((D3DSTATE*)(ptr))+1; } while (0)
1329 #define EXEBUF_PUT_PROCESSVERTICES(nvertices, ptr) do {\
1330 ((D3DINSTRUCTION*)(ptr))->bOpcode = D3DOP_PROCESSVERTICES;\
1331 ((D3DINSTRUCTION*)(ptr))->bSize = sizeof(D3DPROCESSVERTICES);\
1332 ((D3DINSTRUCTION*)(ptr))->wCount = 1;\
1333 ptr = ((D3DINSTRUCTION*)(ptr))+1;\
1334 ((D3DPROCESSVERTICES*)(ptr))->dwFlags = D3DPROCESSVERTICES_COPY;\
1335 ((D3DPROCESSVERTICES*)(ptr))->wStart = 0;\
1336 ((D3DPROCESSVERTICES*)(ptr))->wDest = 0;\
1337 ((D3DPROCESSVERTICES*)(ptr))->dwCount = nvertices;\
1338 ((D3DPROCESSVERTICES*)(ptr))->dwReserved = 0;\
1339 ptr = ((D3DPROCESSVERTICES*)(ptr))+1; } while (0)
1341 #define EXEBUF_END(ptr) do {\
1342 ((D3DINSTRUCTION*)(ptr))->bOpcode = D3DOP_EXIT;\
1343 ((D3DINSTRUCTION*)(ptr))->bSize = 0;\
1344 ((D3DINSTRUCTION*)(ptr))->wCount = 0;\
1345 ptr = ((D3DINSTRUCTION*)(ptr))+1; } while (0)
1347 #define EXEBUF_PUT_QUAD(base_idx, ptr) do {\
1348 ((D3DINSTRUCTION*)(ptr))->bOpcode = D3DOP_TRIANGLE;\
1349 ((D3DINSTRUCTION*)(ptr))->bSize = sizeof(D3DTRIANGLE);\
1350 ((D3DINSTRUCTION*)(ptr))->wCount = 2;\
1351 ptr = ((D3DINSTRUCTION*)(ptr))+1;\
1352 U1(*((D3DTRIANGLE*)(ptr))).v1 = base_idx;\
1353 U2(*((D3DTRIANGLE*)(ptr))).v2 = (base_idx) + 1; \
1354 U3(*((D3DTRIANGLE*)(ptr))).v3 = (base_idx) + 3; \
1355 ((D3DTRIANGLE*)(ptr))->wFlags = 0;\
1356 ptr = ((D3DTRIANGLE*)ptr)+1;\
1357 U1(*((D3DTRIANGLE*)(ptr))).v1 = (base_idx) + 1; \
1358 U2(*((D3DTRIANGLE*)(ptr))).v2 = (base_idx) + 2; \
1359 U3(*((D3DTRIANGLE*)(ptr))).v3 = (base_idx) + 3; \
1360 ((D3DTRIANGLE*)(ptr))->wFlags = 0;\
1361 ptr = ((D3DTRIANGLE*)(ptr))+1;\
1362 } while (0)
1364 static HRESULT CALLBACK TextureFormatEnumCallback(DDSURFACEDESC *lpDDSD, void *lpContext)
1366 if (lpDDSD->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8) {
1367 *(BOOL*)lpContext = TRUE;
1370 return DDENUMRET_OK;
1373 static void D3D1_TextureMapBlendTest(void)
1375 HRESULT hr;
1376 DDSURFACEDESC ddsd;
1377 D3DEXECUTEBUFFERDESC exdesc;
1378 D3DEXECUTEDATA exdata;
1379 DDBLTFX ddbltfx;
1380 RECT rect = { 0, 0, 64, 128 };
1381 DWORD color, red, blue, green;
1382 void *exe_buffer_ptr;
1383 DWORD exe_length;
1384 D3DTEXTUREHANDLE htex;
1385 DDCOLORKEY clrKey;
1386 IDirectDrawSurface *TexSurface = NULL;
1387 IDirect3DTexture *Texture = NULL;
1388 IDirectDrawPalette *Palette = NULL;
1389 PALETTEENTRY table1[256];
1390 BOOL p8_textures_supported = FALSE;
1392 struct {
1393 float x, y, z;
1394 float rhw;
1395 DWORD diffuse;
1396 DWORD specular;
1397 float tu, tv;
1398 } test1_quads[] =
1400 {0.0f, 0.0f, 0.0f, 1.0f, 0xffffffff, 0, 0.0f, 0.0f},
1401 {640.0f, 0.0f, 0.0f, 1.0f, 0xffffffff, 0, 1.0f, 0.0f},
1402 {640.0f, 240.0f, 0.0f, 1.0f, 0xffffffff, 0, 1.0f, 1.0f},
1403 {0.0f, 240.0f, 0.0f, 1.0f, 0xffffffff, 0, 0.0f, 1.0f},
1404 {0.0f, 240.0f, 0.0f, 1.0f, 0x80ffffff, 0, 0.0f, 0.0f},
1405 {640.0f, 240.0f, 0.0f, 1.0f, 0x80ffffff, 0, 1.0f, 0.0f},
1406 {640.0f, 480.0f, 0.0f, 1.0f, 0x80ffffff, 0, 1.0f, 1.0f},
1407 {0.0f, 480.0f, 0.0f, 1.0f, 0x80ffffff, 0, 0.0f, 1.0f}
1408 }, test2_quads[] =
1410 {0.0f, 0.0f, 0.0f, 1.0f, 0x00ff0080, 0, 0.0f, 0.0f},
1411 {640.0f, 0.0f, 0.0f, 1.0f, 0x00ff0080, 0, 1.0f, 0.0f},
1412 {640.0f, 240.0f, 0.0f, 1.0f, 0x00ff0080, 0, 1.0f, 1.0f},
1413 {0.0f, 240.0f, 0.0f, 1.0f, 0x00ff0080, 0, 0.0f, 1.0f},
1414 {0.0f, 240.0f, 0.0f, 1.0f, 0x008000ff, 0, 0.0f, 0.0f},
1415 {640.0f, 240.0f, 0.0f, 1.0f, 0x008000ff, 0, 1.0f, 0.0f},
1416 {640.0f, 480.0f, 0.0f, 1.0f, 0x008000ff, 0, 1.0f, 1.0f},
1417 {0.0f, 480.0f, 0.0f, 1.0f, 0x008000ff, 0, 0.0f, 1.0f}
1420 /* 1) Test alpha with DDPF_ALPHAPIXELS texture - should be taken from texture alpha channel*/
1421 memset (&ddsd, 0, sizeof (ddsd));
1422 ddsd.dwSize = sizeof (ddsd);
1423 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
1424 ddsd.dwHeight = 128;
1425 ddsd.dwWidth = 128;
1426 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1427 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
1428 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
1429 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
1430 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1431 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1432 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x000000ff;
1433 U5(ddsd.ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
1434 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &TexSurface, NULL);
1435 ok(hr==D3D_OK, "CreateSurface returned: %x\n", hr);
1436 if (FAILED(hr)) {
1437 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1438 goto out;
1441 hr = IDirectDrawSurface_QueryInterface(TexSurface, &IID_IDirect3DTexture,
1442 (void *)&Texture);
1443 ok(hr==D3D_OK, "IDirectDrawSurface_QueryInterface returned: %x\n", hr);
1444 if (FAILED(hr)) {
1445 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1446 goto out;
1449 memset(&ddbltfx, 0, sizeof(ddbltfx));
1450 ddbltfx.dwSize = sizeof(ddbltfx);
1451 U5(ddbltfx).dwFillColor = 0;
1452 hr = IDirectDrawSurface_Blt(Surface1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1453 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1455 U5(ddbltfx).dwFillColor = 0xff0000ff;
1456 hr = IDirectDrawSurface_Blt(TexSurface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1457 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1458 U5(ddbltfx).dwFillColor = 0x800000ff;
1459 hr = IDirectDrawSurface_Blt(TexSurface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1460 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1462 memset(&exdesc, 0, sizeof(D3DEXECUTEBUFFERDESC));
1463 exdesc.dwSize = sizeof(D3DEXECUTEBUFFERDESC);
1464 hr = IDirect3DExecuteBuffer_Lock(ExecuteBuffer, &exdesc);
1465 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr);
1466 if (FAILED(hr)) {
1467 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1468 goto out;
1471 memcpy(exdesc.lpData, test1_quads, sizeof(test1_quads));
1473 exe_buffer_ptr = sizeof(test1_quads) + (char*)exdesc.lpData;
1475 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr);
1477 EXEBUF_START_RENDER_STATES(12, exe_buffer_ptr);
1478 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE, exe_buffer_ptr);
1479 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ZENABLE, FALSE, exe_buffer_ptr);
1480 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_FOGENABLE, FALSE, exe_buffer_ptr);
1481 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_SPECULARENABLE, FALSE, exe_buffer_ptr);
1482 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREMAG, D3DFILTER_NEAREST, exe_buffer_ptr);
1483 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREMIN, D3DFILTER_NEAREST, exe_buffer_ptr);
1484 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_FILLMODE , D3DFILL_SOLID, exe_buffer_ptr);
1485 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA, exe_buffer_ptr);
1486 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA, exe_buffer_ptr);
1487 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE, exe_buffer_ptr);
1488 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATE, exe_buffer_ptr);
1489 hr = IDirect3DTexture_GetHandle(Texture, Direct3DDevice1, &htex);
1490 ok(hr == D3D_OK, "IDirect3DTexture_GetHandle failed with %08x\n", hr);
1491 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE, htex, exe_buffer_ptr);
1493 EXEBUF_PUT_QUAD(0, exe_buffer_ptr);
1494 EXEBUF_PUT_QUAD(4, exe_buffer_ptr);
1496 EXEBUF_END(exe_buffer_ptr);
1498 exe_length = ((char*)exe_buffer_ptr - (char*)exdesc.lpData) - sizeof(test1_quads);
1500 hr = IDirect3DExecuteBuffer_Unlock(ExecuteBuffer);
1501 if (FAILED(hr)) {
1502 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr);
1505 memset(&exdata, 0, sizeof(exdata));
1506 exdata.dwSize = sizeof(exdata);
1507 exdata.dwVertexCount = 8;
1508 exdata.dwInstructionOffset = sizeof(test1_quads);
1509 exdata.dwInstructionLength = exe_length;
1510 hr = IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer, &exdata);
1511 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr);
1513 hr = IDirect3DDevice_BeginScene(Direct3DDevice1);
1514 ok(hr == D3D_OK, "IDirect3DDevice_BeginScene failed with %08x\n", hr);
1516 if (SUCCEEDED(hr)) {
1517 hr = IDirect3DDevice_Execute(Direct3DDevice1, ExecuteBuffer, Viewport, D3DEXECUTE_UNCLIPPED);
1518 ok(hr == D3D_OK, "IDirect3DDevice_Execute failed, hr = %08x\n", hr);
1519 hr = IDirect3DDevice_EndScene(Direct3DDevice1);
1520 ok(hr == D3D_OK, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr);
1523 color = D3D1_getPixelColor(DirectDraw1, Surface1, 5, 5);
1524 red = (color & 0x00ff0000) >> 16;
1525 green = (color & 0x0000ff00) >> 8;
1526 blue = (color & 0x000000ff);
1527 ok(red == 0 && green == 0 && blue >= 0x7e && blue <= 0x82, "Got color %08x, expected 00000080 or near\n", color);
1529 color = D3D1_getPixelColor(DirectDraw1, Surface1, 400, 5);
1530 red = (color & 0x00ff0000) >> 16;
1531 green = (color & 0x0000ff00) >> 8;
1532 blue = (color & 0x000000ff);
1533 ok(red == 0 && green == 0 && blue == 0xff, "Got color %08x, expected 000000ff or near\n", color);
1535 color = D3D1_getPixelColor(DirectDraw1, Surface1, 5, 245);
1536 red = (color & 0x00ff0000) >> 16;
1537 green = (color & 0x0000ff00) >> 8;
1538 blue = (color & 0x000000ff);
1539 ok(red == 0 && green == 0 && blue >= 0x7e && blue <= 0x82, "Got color %08x, expected 00000080 or near\n", color);
1541 color = D3D1_getPixelColor(DirectDraw1, Surface1, 400, 245);
1542 red = (color & 0x00ff0000) >> 16;
1543 green = (color & 0x0000ff00) >> 8;
1544 blue = (color & 0x000000ff);
1545 ok(red == 0 && green == 0 && blue == 0xff, "Got color %08x, expected 000000ff or near\n", color);
1547 /* 2) Test alpha with texture that has no alpha channel - alpha should be taken from diffuse color */
1548 if(Texture) IDirect3DTexture_Release(Texture);
1549 Texture = NULL;
1550 if(TexSurface) IDirectDrawSurface_Release(TexSurface);
1551 TexSurface = NULL;
1553 memset (&ddsd, 0, sizeof (ddsd));
1554 ddsd.dwSize = sizeof (ddsd);
1555 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
1556 ddsd.dwHeight = 128;
1557 ddsd.dwWidth = 128;
1558 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1559 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
1560 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
1561 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
1562 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1563 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1564 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x000000ff;
1566 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &TexSurface, NULL);
1567 ok(hr==D3D_OK, "CreateSurface returned: %x\n", hr);
1568 if (FAILED(hr)) {
1569 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1570 goto out;
1573 hr = IDirectDrawSurface_QueryInterface(TexSurface, &IID_IDirect3DTexture,
1574 (void *)&Texture);
1575 ok(hr==D3D_OK, "IDirectDrawSurface_QueryInterface returned: %x\n", hr);
1576 if (FAILED(hr)) {
1577 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1578 goto out;
1581 memset(&ddbltfx, 0, sizeof(ddbltfx));
1582 ddbltfx.dwSize = sizeof(ddbltfx);
1583 U5(ddbltfx).dwFillColor = 0;
1584 hr = IDirectDrawSurface_Blt(Surface1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1585 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1587 U5(ddbltfx).dwFillColor = 0xff0000ff;
1588 hr = IDirectDrawSurface_Blt(TexSurface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1589 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1590 U5(ddbltfx).dwFillColor = 0x800000ff;
1591 hr = IDirectDrawSurface_Blt(TexSurface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1592 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1594 memset(&exdesc, 0, sizeof(D3DEXECUTEBUFFERDESC));
1595 exdesc.dwSize = sizeof(D3DEXECUTEBUFFERDESC);
1596 hr = IDirect3DExecuteBuffer_Lock(ExecuteBuffer, &exdesc);
1597 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr);
1598 if (FAILED(hr)) {
1599 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1600 goto out;
1603 memcpy(exdesc.lpData, test1_quads, sizeof(test1_quads));
1605 exe_buffer_ptr = sizeof(test1_quads) + (char*)exdesc.lpData;
1607 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr);
1609 EXEBUF_START_RENDER_STATES(1, exe_buffer_ptr);
1610 hr = IDirect3DTexture_GetHandle(Texture, Direct3DDevice1, &htex);
1611 ok(hr == D3D_OK, "IDirect3DTexture_GetHandle failed with %08x\n", hr);
1612 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE, htex, exe_buffer_ptr);
1614 EXEBUF_PUT_QUAD(0, exe_buffer_ptr);
1615 EXEBUF_PUT_QUAD(4, exe_buffer_ptr);
1617 EXEBUF_END(exe_buffer_ptr);
1619 exe_length = ((char*)exe_buffer_ptr - (char*)exdesc.lpData) - sizeof(test1_quads);
1621 hr = IDirect3DExecuteBuffer_Unlock(ExecuteBuffer);
1622 if (FAILED(hr)) {
1623 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr);
1626 memset(&exdata, 0, sizeof(exdata));
1627 exdata.dwSize = sizeof(exdata);
1628 exdata.dwVertexCount = 8;
1629 exdata.dwInstructionOffset = sizeof(test1_quads);
1630 exdata.dwInstructionLength = exe_length;
1631 hr = IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer, &exdata);
1632 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr);
1634 hr = IDirect3DDevice_BeginScene(Direct3DDevice1);
1635 ok(hr == D3D_OK, "IDirect3DDevice_BeginScene failed with %08x\n", hr);
1637 if (SUCCEEDED(hr)) {
1638 hr = IDirect3DDevice_Execute(Direct3DDevice1, ExecuteBuffer, Viewport, D3DEXECUTE_UNCLIPPED);
1639 ok(hr == D3D_OK, "IDirect3DDevice_Execute failed, hr = %08x\n", hr);
1640 hr = IDirect3DDevice_EndScene(Direct3DDevice1);
1641 ok(hr == D3D_OK, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr);
1644 color = D3D1_getPixelColor(DirectDraw1, Surface1, 5, 5);
1645 red = (color & 0x00ff0000) >> 16;
1646 green = (color & 0x0000ff00) >> 8;
1647 blue = (color & 0x000000ff);
1648 ok(red == 0 && green == 0 && blue == 0xff, "Got color %08x, expected 000000ff or near\n", color);
1650 color = D3D1_getPixelColor(DirectDraw1, Surface1, 400, 5);
1651 red = (color & 0x00ff0000) >> 16;
1652 green = (color & 0x0000ff00) >> 8;
1653 blue = (color & 0x000000ff);
1654 ok(red == 0 && green == 0 && blue == 0xff, "Got color %08x, expected 000000ff or near\n", color);
1656 color = D3D1_getPixelColor(DirectDraw1, Surface1, 5, 245);
1657 red = (color & 0x00ff0000) >> 16;
1658 green = (color & 0x0000ff00) >> 8;
1659 blue = (color & 0x000000ff);
1660 ok(red == 0 && green == 0 && blue >= 0x7e && blue <= 0x82, "Got color %08x, expected 00000080 or near\n", color);
1662 color = D3D1_getPixelColor(DirectDraw1, Surface1, 400, 245);
1663 red = (color & 0x00ff0000) >> 16;
1664 green = (color & 0x0000ff00) >> 8;
1665 blue = (color & 0x000000ff);
1666 ok(red == 0 && green == 0 && blue >= 0x7e && blue <= 0x82, "Got color %08x, expected 00000080 or near\n", color);
1668 /* 3) Test RGB - should multiply color components from diffuse color and texture */
1669 if(Texture) IDirect3DTexture_Release(Texture);
1670 Texture = NULL;
1671 if(TexSurface) IDirectDrawSurface_Release(TexSurface);
1672 TexSurface = NULL;
1674 memset (&ddsd, 0, sizeof (ddsd));
1675 ddsd.dwSize = sizeof (ddsd);
1676 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
1677 ddsd.dwHeight = 128;
1678 ddsd.dwWidth = 128;
1679 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1680 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
1681 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
1682 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
1683 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1684 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1685 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x000000ff;
1686 U5(ddsd.ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
1687 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &TexSurface, NULL);
1688 ok(hr==D3D_OK, "CreateSurface returned: %x\n", hr);
1689 if (FAILED(hr)) {
1690 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1691 goto out;
1694 hr = IDirectDrawSurface_QueryInterface(TexSurface, &IID_IDirect3DTexture,
1695 (void *)&Texture);
1696 ok(hr==D3D_OK, "IDirectDrawSurface_QueryInterface returned: %x\n", hr);
1697 if (FAILED(hr)) {
1698 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1699 goto out;
1702 memset(&ddbltfx, 0, sizeof(ddbltfx));
1703 ddbltfx.dwSize = sizeof(ddbltfx);
1704 U5(ddbltfx).dwFillColor = 0;
1705 hr = IDirectDrawSurface_Blt(Surface1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1706 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1708 U5(ddbltfx).dwFillColor = 0x00ffffff;
1709 hr = IDirectDrawSurface_Blt(TexSurface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1710 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1711 U5(ddbltfx).dwFillColor = 0x00ffff80;
1712 hr = IDirectDrawSurface_Blt(TexSurface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1713 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1715 memset(&exdesc, 0, sizeof(D3DEXECUTEBUFFERDESC));
1716 exdesc.dwSize = sizeof(D3DEXECUTEBUFFERDESC);
1717 hr = IDirect3DExecuteBuffer_Lock(ExecuteBuffer, &exdesc);
1718 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr);
1719 if (FAILED(hr)) {
1720 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1721 goto out;
1724 memcpy(exdesc.lpData, test2_quads, sizeof(test2_quads));
1726 exe_buffer_ptr = sizeof(test2_quads) + (char*)exdesc.lpData;
1728 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr);
1730 EXEBUF_START_RENDER_STATES(2, exe_buffer_ptr);
1731 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE, exe_buffer_ptr);
1732 hr = IDirect3DTexture_GetHandle(Texture, Direct3DDevice1, &htex);
1733 ok(hr == D3D_OK, "IDirect3DTexture_GetHandle failed with %08x\n", hr);
1734 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE, htex, exe_buffer_ptr);
1736 EXEBUF_PUT_QUAD(0, exe_buffer_ptr);
1737 EXEBUF_PUT_QUAD(4, exe_buffer_ptr);
1739 EXEBUF_END(exe_buffer_ptr);
1741 exe_length = ((char*)exe_buffer_ptr - (char*)exdesc.lpData) - sizeof(test2_quads);
1743 hr = IDirect3DExecuteBuffer_Unlock(ExecuteBuffer);
1744 if (FAILED(hr)) {
1745 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr);
1748 memset(&exdata, 0, sizeof(exdata));
1749 exdata.dwSize = sizeof(exdata);
1750 exdata.dwVertexCount = 8;
1751 exdata.dwInstructionOffset = sizeof(test2_quads);
1752 exdata.dwInstructionLength = exe_length;
1753 hr = IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer, &exdata);
1754 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr);
1756 hr = IDirect3DDevice_BeginScene(Direct3DDevice1);
1757 ok(hr == D3D_OK, "IDirect3DDevice_BeginScene failed with %08x\n", hr);
1759 if (SUCCEEDED(hr)) {
1760 hr = IDirect3DDevice_Execute(Direct3DDevice1, ExecuteBuffer, Viewport, D3DEXECUTE_UNCLIPPED);
1761 ok(hr == D3D_OK, "IDirect3DDevice_Execute failed, hr = %08x\n", hr);
1762 hr = IDirect3DDevice_EndScene(Direct3DDevice1);
1763 ok(hr == D3D_OK, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr);
1766 color = D3D1_getPixelColor(DirectDraw1, Surface1, 5, 5);
1767 red = (color & 0x00ff0000) >> 16;
1768 green = (color & 0x0000ff00) >> 8;
1769 blue = (color & 0x000000ff);
1770 ok(red == 0xff && green == 0 && blue >= 0x3e && blue <= 0x42, "Got color %08x, expected 00ff0040 or near\n", color);
1772 color = D3D1_getPixelColor(DirectDraw1, Surface1, 400, 5);
1773 red = (color & 0x00ff0000) >> 16;
1774 green = (color & 0x0000ff00) >> 8;
1775 blue = (color & 0x000000ff);
1776 ok(red == 0xff && green == 0 && blue == 0x80, "Got color %08x, expected 00ff0080 or near\n", color);
1778 color = D3D1_getPixelColor(DirectDraw1, Surface1, 5, 245);
1779 red = (color & 0x00ff0000) >> 16;
1780 green = (color & 0x0000ff00) >> 8;
1781 blue = (color & 0x000000ff);
1782 ok(red >= 0x7e && red <= 0x82 && green == 0 && blue == 0x80, "Got color %08x, expected 00800080 or near\n", color);
1784 color = D3D1_getPixelColor(DirectDraw1, Surface1, 400, 245);
1785 red = (color & 0x00ff0000) >> 16;
1786 green = (color & 0x0000ff00) >> 8;
1787 blue = (color & 0x000000ff);
1788 ok(red >= 0x7e && red <= 0x82 && green == 0 && blue == 0xff, "Got color %08x, expected 008000ff or near\n", color);
1790 /* 4) Test alpha again, now with color keyed texture (colorkey emulation in wine can interfere) */
1791 if(Texture) IDirect3DTexture_Release(Texture);
1792 Texture = NULL;
1793 if(TexSurface) IDirectDrawSurface_Release(TexSurface);
1794 TexSurface = NULL;
1796 memset (&ddsd, 0, sizeof (ddsd));
1797 ddsd.dwSize = sizeof (ddsd);
1798 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
1799 ddsd.dwHeight = 128;
1800 ddsd.dwWidth = 128;
1801 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1802 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
1803 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
1804 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 16;
1805 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xf800;
1806 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x07e0;
1807 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x001f;
1809 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &TexSurface, NULL);
1810 ok(hr==D3D_OK, "CreateSurface returned: %x\n", hr);
1811 if (FAILED(hr)) {
1812 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1813 goto out;
1816 hr = IDirectDrawSurface_QueryInterface(TexSurface, &IID_IDirect3DTexture,
1817 (void *)&Texture);
1818 ok(hr==D3D_OK, "IDirectDrawSurface_QueryInterface returned: %x\n", hr);
1819 if (FAILED(hr)) {
1820 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1821 goto out;
1824 memset(&ddbltfx, 0, sizeof(ddbltfx));
1825 ddbltfx.dwSize = sizeof(ddbltfx);
1826 U5(ddbltfx).dwFillColor = 0;
1827 hr = IDirectDrawSurface_Blt(Surface1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1828 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1829 U5(ddbltfx).dwFillColor = 0xf800;
1830 hr = IDirectDrawSurface_Blt(TexSurface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1831 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1832 U5(ddbltfx).dwFillColor = 0x001f;
1833 hr = IDirectDrawSurface_Blt(TexSurface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1834 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1836 clrKey.dwColorSpaceLowValue = 0x001f;
1837 clrKey.dwColorSpaceHighValue = 0x001f;
1838 hr = IDirectDrawSurface_SetColorKey(TexSurface, DDCKEY_SRCBLT, &clrKey);
1839 ok(hr==D3D_OK, "IDirectDrawSurfac_SetColorKey returned: %x\n", hr);
1841 memset(&exdesc, 0, sizeof(D3DEXECUTEBUFFERDESC));
1842 exdesc.dwSize = sizeof(D3DEXECUTEBUFFERDESC);
1843 hr = IDirect3DExecuteBuffer_Lock(ExecuteBuffer, &exdesc);
1844 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr);
1845 if (FAILED(hr)) {
1846 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1847 goto out;
1850 memcpy(exdesc.lpData, test1_quads, sizeof(test1_quads));
1852 exe_buffer_ptr = sizeof(test1_quads) + (char*)exdesc.lpData;
1854 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr);
1856 EXEBUF_START_RENDER_STATES(2, exe_buffer_ptr);
1857 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE, exe_buffer_ptr);
1858 hr = IDirect3DTexture_GetHandle(Texture, Direct3DDevice1, &htex);
1859 ok(hr == D3D_OK, "IDirect3DTexture_GetHandle failed with %08x\n", hr);
1860 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE, htex, exe_buffer_ptr);
1862 EXEBUF_PUT_QUAD(0, exe_buffer_ptr);
1863 EXEBUF_PUT_QUAD(4, exe_buffer_ptr);
1865 EXEBUF_END(exe_buffer_ptr);
1867 exe_length = ((char*)exe_buffer_ptr - (char*)exdesc.lpData) - sizeof(test1_quads);
1869 hr = IDirect3DExecuteBuffer_Unlock(ExecuteBuffer);
1870 if (FAILED(hr)) {
1871 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr);
1874 memset(&exdata, 0, sizeof(exdata));
1875 exdata.dwSize = sizeof(exdata);
1876 exdata.dwVertexCount = 8;
1877 exdata.dwInstructionOffset = sizeof(test1_quads);
1878 exdata.dwInstructionLength = exe_length;
1879 hr = IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer, &exdata);
1880 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr);
1882 hr = IDirect3DDevice_BeginScene(Direct3DDevice1);
1883 ok(hr == D3D_OK, "IDirect3DDevice_BeginScene failed with %08x\n", hr);
1885 if (SUCCEEDED(hr)) {
1886 hr = IDirect3DDevice_Execute(Direct3DDevice1, ExecuteBuffer, Viewport, D3DEXECUTE_UNCLIPPED);
1887 ok(hr == D3D_OK, "IDirect3DDevice_Execute failed, hr = %08x\n", hr);
1888 hr = IDirect3DDevice_EndScene(Direct3DDevice1);
1889 ok(hr == D3D_OK, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr);
1892 color = D3D1_getPixelColor(DirectDraw1, Surface1, 5, 5);
1893 ok(color == 0, "Got color %08x, expected 00000000\n", color);
1895 color = D3D1_getPixelColor(DirectDraw1, Surface1, 400, 5);
1896 red = (color & 0x00ff0000) >> 16;
1897 green = (color & 0x0000ff00) >> 8;
1898 blue = (color & 0x000000ff);
1899 ok(red == 0xff && green == 0 && blue == 0, "Got color %08x, expected 00ff0000 or near\n", color);
1901 color = D3D1_getPixelColor(DirectDraw1, Surface1, 5, 245);
1902 ok(color == 0, "Got color %08x, expected 00000000\n", color);
1904 color = D3D1_getPixelColor(DirectDraw1, Surface1, 400, 245);
1905 red = (color & 0x00ff0000) >> 16;
1906 green = (color & 0x0000ff00) >> 8;
1907 blue = (color & 0x000000ff);
1908 ok(red >= 0x7e && red <= 0x82 && green == 0 && blue == 0, "Got color %08x, expected 00800000 or near\n", color);
1910 /* 5) Test alpha again, now with color keyed P8 texture */
1911 if(Texture) IDirect3DTexture_Release(Texture);
1912 Texture = NULL;
1913 if(TexSurface) IDirectDrawSurface_Release(TexSurface);
1914 TexSurface = NULL;
1916 hr = IDirect3DDevice_EnumTextureFormats(Direct3DDevice1, TextureFormatEnumCallback,
1917 &p8_textures_supported);
1918 ok(hr == DD_OK, "IDirect3DDevice_EnumTextureFormats returned %08x\n", hr);
1920 if (!p8_textures_supported) {
1921 skip("device has no P8 texture support, skipping test\n");
1922 } else {
1923 memset (&ddsd, 0, sizeof (ddsd));
1924 ddsd.dwSize = sizeof (ddsd);
1925 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
1926 ddsd.dwHeight = 128;
1927 ddsd.dwWidth = 128;
1928 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1929 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
1930 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED8;
1931 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 8;
1933 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &TexSurface, NULL);
1934 ok(hr==D3D_OK, "CreateSurface returned: %x\n", hr);
1935 if (FAILED(hr)) {
1936 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1937 goto out;
1940 memset(table1, 0, sizeof(table1));
1941 table1[0].peBlue = 0xff;
1942 table1[1].peRed = 0xff;
1944 hr = IDirectDraw_CreatePalette(DirectDraw1, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, table1, &Palette, NULL);
1945 ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
1946 if (FAILED(hr)) {
1947 skip("IDirectDraw_CreatePalette failed; skipping further tests\n");
1948 goto out;
1951 hr = IDirectDrawSurface_SetPalette(TexSurface, Palette);
1952 ok(hr==D3D_OK, "IDirectDrawSurface_SetPalette returned: %x\n", hr);
1954 hr = IDirectDrawSurface_QueryInterface(TexSurface, &IID_IDirect3DTexture,
1955 (void *)&Texture);
1956 ok(hr==D3D_OK, "IDirectDrawSurface_QueryInterface returned: %x\n", hr);
1957 if (FAILED(hr)) {
1958 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1959 goto out;
1962 memset(&ddbltfx, 0, sizeof(ddbltfx));
1963 ddbltfx.dwSize = sizeof(ddbltfx);
1964 U5(ddbltfx).dwFillColor = 0;
1965 hr = IDirectDrawSurface_Blt(Surface1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1966 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1967 U5(ddbltfx).dwFillColor = 0;
1968 hr = IDirectDrawSurface_Blt(TexSurface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1969 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1970 U5(ddbltfx).dwFillColor = 1;
1971 hr = IDirectDrawSurface_Blt(TexSurface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1972 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1974 clrKey.dwColorSpaceLowValue = 1;
1975 clrKey.dwColorSpaceHighValue = 1;
1976 hr = IDirectDrawSurface_SetColorKey(TexSurface, DDCKEY_SRCBLT, &clrKey);
1977 ok(hr==D3D_OK, "IDirectDrawSurfac_SetColorKey returned: %x\n", hr);
1979 memset(&exdesc, 0, sizeof(D3DEXECUTEBUFFERDESC));
1980 exdesc.dwSize = sizeof(D3DEXECUTEBUFFERDESC);
1981 hr = IDirect3DExecuteBuffer_Lock(ExecuteBuffer, &exdesc);
1982 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr);
1983 if (FAILED(hr)) {
1984 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1985 goto out;
1988 memcpy(exdesc.lpData, test1_quads, sizeof(test1_quads));
1990 exe_buffer_ptr = sizeof(test1_quads) + (char*)exdesc.lpData;
1992 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr);
1994 EXEBUF_START_RENDER_STATES(2, exe_buffer_ptr);
1995 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE, exe_buffer_ptr);
1996 hr = IDirect3DTexture_GetHandle(Texture, Direct3DDevice1, &htex);
1997 ok(hr == D3D_OK, "IDirect3DTexture_GetHandle failed with %08x\n", hr);
1998 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE, htex, exe_buffer_ptr);
2000 EXEBUF_PUT_QUAD(0, exe_buffer_ptr);
2001 EXEBUF_PUT_QUAD(4, exe_buffer_ptr);
2003 EXEBUF_END(exe_buffer_ptr);
2005 exe_length = ((char*)exe_buffer_ptr - (char*)exdesc.lpData) - sizeof(test1_quads);
2007 hr = IDirect3DExecuteBuffer_Unlock(ExecuteBuffer);
2008 if (FAILED(hr)) {
2009 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr);
2012 memset(&exdata, 0, sizeof(exdata));
2013 exdata.dwSize = sizeof(exdata);
2014 exdata.dwVertexCount = 8;
2015 exdata.dwInstructionOffset = sizeof(test1_quads);
2016 exdata.dwInstructionLength = exe_length;
2017 hr = IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer, &exdata);
2018 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr);
2020 hr = IDirect3DDevice_BeginScene(Direct3DDevice1);
2021 ok(hr == D3D_OK, "IDirect3DDevice_BeginScene failed with %08x\n", hr);
2023 if (SUCCEEDED(hr)) {
2024 hr = IDirect3DDevice_Execute(Direct3DDevice1, ExecuteBuffer, Viewport, D3DEXECUTE_UNCLIPPED);
2025 ok(hr == D3D_OK, "IDirect3DDevice_Execute failed, hr = %08x\n", hr);
2026 hr = IDirect3DDevice_EndScene(Direct3DDevice1);
2027 ok(hr == D3D_OK, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr);
2030 color = D3D1_getPixelColor(DirectDraw1, Surface1, 5, 5);
2031 ok(color == 0, "Got color %08x, expected 00000000\n", color);
2033 color = D3D1_getPixelColor(DirectDraw1, Surface1, 400, 5);
2034 red = (color & 0x00ff0000) >> 16;
2035 green = (color & 0x0000ff00) >> 8;
2036 blue = (color & 0x000000ff);
2037 ok(red == 0 && green == 0 && blue == 0xff, "Got color %08x, expected 000000ff or near\n", color);
2039 color = D3D1_getPixelColor(DirectDraw1, Surface1, 5, 245);
2040 ok(color == 0, "Got color %08x, expected 00000000\n", color);
2042 color = D3D1_getPixelColor(DirectDraw1, Surface1, 400, 245);
2043 red = (color & 0x00ff0000) >> 16;
2044 green = (color & 0x0000ff00) >> 8;
2045 blue = (color & 0x000000ff);
2046 ok(red == 0 && green == 0 && blue >= 0x7e && blue <= 0x82, "Got color %08x, expected 00000080 or near\n", color);
2049 out:
2051 if (Palette) IDirectDrawPalette_Release(Palette);
2052 if (TexSurface) IDirectDrawSurface_Release(TexSurface);
2053 if (Texture) IDirect3DTexture_Release(Texture);
2056 static void D3D1_ViewportClearTest(void)
2058 HRESULT hr;
2059 IDirect3DMaterial *bgMaterial = NULL;
2060 D3DMATERIAL mat;
2061 D3DMATERIALHANDLE hMat;
2062 D3DVIEWPORT vp_data;
2063 IDirect3DViewport *Viewport2 = NULL;
2064 DWORD color, red, green, blue;
2066 hr = IDirect3D_CreateMaterial(Direct3D1, &bgMaterial, NULL);
2067 ok(hr == D3D_OK, "IDirect3D_CreateMaterial failed: %08x\n", hr);
2068 if (FAILED(hr)) {
2069 goto out;
2072 hr = IDirect3D_CreateViewport(Direct3D1, &Viewport2, NULL);
2073 ok(hr == D3D_OK, "IDirect3D_CreateViewport failed: %08x\n", hr);
2074 if (FAILED(hr)) {
2075 goto out;
2078 hr = IDirect3DViewport_Initialize(Viewport2, Direct3D1);
2079 ok(hr == D3D_OK || hr == DDERR_ALREADYINITIALIZED, "IDirect3DViewport_Initialize returned %08x\n", hr);
2080 hr = IDirect3DDevice_AddViewport(Direct3DDevice1, Viewport2);
2081 ok(hr == D3D_OK, "IDirect3DDevice_AddViewport returned %08x\n", hr);
2082 vp_data.dwSize = sizeof(vp_data);
2083 vp_data.dwX = 200;
2084 vp_data.dwY = 200;
2085 vp_data.dwWidth = 100;
2086 vp_data.dwHeight = 100;
2087 vp_data.dvScaleX = 1;
2088 vp_data.dvScaleY = 1;
2089 vp_data.dvMaxX = 100;
2090 vp_data.dvMaxY = 100;
2091 vp_data.dvMinZ = 0;
2092 vp_data.dvMaxZ = 1;
2093 hr = IDirect3DViewport_SetViewport(Viewport2, &vp_data);
2094 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
2096 memset(&mat, 0, sizeof(mat));
2097 mat.dwSize = sizeof(mat);
2098 U1(U(mat).diffuse).r = 1.0f;
2099 hr = IDirect3DMaterial_SetMaterial(bgMaterial, &mat);
2100 ok(hr == D3D_OK, "IDirect3DMaterial_SetMaterial failed: %08x\n", hr);
2102 hr = IDirect3DMaterial_GetHandle(bgMaterial, Direct3DDevice1, &hMat);
2103 ok(hr == D3D_OK, "IDirect3DMaterial_GetHandle failed: %08x\n", hr);
2105 hr = IDirect3DViewport_SetBackground(Viewport, hMat);
2106 ok(hr == D3D_OK, "IDirect3DViewport_SetBackground failed: %08x\n", hr);
2107 hr = IDirect3DViewport_SetBackground(Viewport2, hMat);
2108 ok(hr == D3D_OK, "IDirect3DViewport_SetBackground failed: %08x\n", hr);
2110 hr = IDirect3DDevice_BeginScene(Direct3DDevice1);
2111 ok(hr == D3D_OK, "IDirect3DDevice_BeginScene failed with %08x\n", hr);
2113 if (SUCCEEDED(hr)) {
2114 D3DRECT rect;
2116 U1(rect).x1 = U2(rect).y1 = 0;
2117 U3(rect).x2 = 640;
2118 U4(rect).y2 = 480;
2120 hr = IDirect3DViewport_Clear(Viewport, 1, &rect, D3DCLEAR_TARGET);
2121 ok(hr == D3D_OK, "IDirect3DViewport_Clear failed: %08x\n", hr);
2123 memset(&mat, 0, sizeof(mat));
2124 mat.dwSize = sizeof(mat);
2125 U3(U(mat).diffuse).b = 1.0f;
2126 hr = IDirect3DMaterial_SetMaterial(bgMaterial, &mat);
2127 ok(hr == D3D_OK, "IDirect3DMaterial_SetMaterial failed: %08x\n", hr);
2129 hr = IDirect3DViewport_Clear(Viewport2, 1, &rect, D3DCLEAR_TARGET);
2130 ok(hr == D3D_OK, "IDirect3DViewport_Clear failed: %08x\n", hr);
2132 hr = IDirect3DDevice_EndScene(Direct3DDevice1);
2133 ok(hr == D3D_OK, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr);
2136 color = D3D1_getPixelColor(DirectDraw1, Surface1, 5, 5);
2137 red = (color & 0x00ff0000) >> 16;
2138 green = (color & 0x0000ff00) >> 8;
2139 blue = (color & 0x000000ff);
2140 ok((red == 0xff && green == 0 && blue == 0) ||
2141 broken(red == 0 && green == 0 && blue == 0xff), /* VMware and some native boxes */
2142 "Got color %08x, expected 00ff0000\n", color);
2144 color = D3D1_getPixelColor(DirectDraw1, Surface1, 205, 205);
2145 red = (color & 0x00ff0000) >> 16;
2146 green = (color & 0x0000ff00) >> 8;
2147 blue = (color & 0x000000ff);
2148 ok(red == 0 && green == 0 && blue == 0xff, "Got color %08x, expected 000000ff\n", color);
2150 out:
2152 if (bgMaterial) IDirect3DMaterial_Release(bgMaterial);
2153 if (Viewport2) IDirect3DViewport_Release(Viewport2);
2156 static DWORD D3D3_getPixelColor(IDirectDraw4 *DirectDraw, IDirectDrawSurface4 *Surface, UINT x, UINT y)
2158 DWORD ret;
2159 HRESULT hr;
2160 DDSURFACEDESC2 ddsd;
2161 RECT rectToLock = {x, y, x+1, y+1};
2162 IDirectDrawSurface4 *surf = NULL;
2164 /* Some implementations seem to dislike direct locking on the front buffer. Thus copy the front buffer
2165 * to an offscreen surface and lock it instead of the front buffer
2167 memset(&ddsd, 0, sizeof(ddsd));
2168 ddsd.dwSize = sizeof(ddsd);
2169 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
2170 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
2171 ddsd.dwWidth = 640;
2172 ddsd.dwHeight = 480;
2173 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
2174 hr = IDirectDraw4_CreateSurface(DirectDraw, &ddsd, &surf, NULL);
2175 ok(hr == DD_OK, "IDirectDraw_CreateSurface failed with %08x\n", hr);
2176 if(!surf)
2178 trace("cannot create helper surface\n");
2179 return 0xdeadbeef;
2182 memset(&ddsd, 0, sizeof(ddsd));
2183 ddsd.dwSize = sizeof(ddsd);
2184 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
2186 hr = IDirectDrawSurface4_BltFast(surf, 0, 0, Surface, NULL, 0);
2187 ok(hr == DD_OK, "IDirectDrawSurface_BltFast returned %08x\n", hr);
2188 if(FAILED(hr))
2190 trace("Cannot blit\n");
2191 ret = 0xdeadbee;
2192 goto out;
2195 hr = IDirectDrawSurface4_Lock(surf, &rectToLock, &ddsd, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
2196 if(FAILED(hr))
2198 trace("Can't lock the offscreen surface, hr=%08x\n", hr);
2199 ret = 0xdeadbeec;
2200 goto out;
2203 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
2204 * really important for these tests
2206 ret = ((DWORD *) ddsd.lpSurface)[0] & 0x00ffffff;
2207 hr = IDirectDrawSurface4_Unlock(surf, NULL);
2208 if(FAILED(hr))
2210 trace("Can't unlock the offscreen surface, hr=%08x\n", hr);
2213 out:
2214 IDirectDrawSurface4_Release(surf);
2215 return ret;
2218 static void D3D3_ViewportClearTest(void)
2220 HRESULT hr;
2221 IDirectDraw *DirectDraw1 = NULL;
2222 IDirectDraw4 *DirectDraw4 = NULL;
2223 IDirectDrawSurface4 *Primary = NULL;
2224 IDirect3D3 *Direct3D3 = NULL;
2225 IDirect3DViewport3 *Viewport3 = NULL;
2226 IDirect3DViewport3 *SmallViewport3 = NULL;
2227 IDirect3DDevice3 *Direct3DDevice3 = NULL;
2228 WNDCLASSA wc = {0};
2229 DDSURFACEDESC2 ddsd;
2230 D3DVIEWPORT2 vp_data;
2231 DWORD color, red, green, blue;
2232 D3DRECT rect;
2233 D3DMATRIX mat =
2235 1.0f, 0.0f, 0.0f, 0.0f,
2236 0.0f, 1.0f, 0.0f, 0.0f,
2237 0.0f, 0.0f, 1.0f, 0.0f,
2238 0.0f, 0.0f, 0.0f, 1.0f,
2240 struct vertex quad[] =
2242 {-1.0f, -1.0f, 0.1f, 0xffffffff},
2243 {-1.0f, 1.0f, 0.1f, 0xffffffff},
2244 { 1.0f, 1.0f, 0.1f, 0xffffffff},
2245 { 1.0f, -1.0f, 0.1f, 0xffffffff},
2248 WORD Indices[] = {0, 1, 2, 2, 3, 0};
2249 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
2251 wc.lpfnWndProc = DefWindowProcA;
2252 wc.lpszClassName = "D3D3_ViewportClearTest_wc";
2253 RegisterClassA(&wc);
2254 window = CreateWindowA("D3D3_ViewportClearTest_wc", "D3D3_ViewportClearTest",
2255 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, 640, 480, 0, 0, 0, 0);
2257 hr = DirectDrawCreate( NULL, &DirectDraw1, NULL );
2258 ok(hr==DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreate returned: %x\n", hr);
2259 if(FAILED(hr)) goto out;
2261 hr = IDirectDraw_SetCooperativeLevel(DirectDraw1, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2262 ok(hr==DD_OK, "SetCooperativeLevel returned: %x\n", hr);
2263 if(FAILED(hr)) goto out;
2265 hr = IDirectDraw_SetDisplayMode(DirectDraw1, 640, 480, 32);
2266 if(FAILED(hr)) {
2267 /* 24 bit is fine too */
2268 hr = IDirectDraw_SetDisplayMode(DirectDraw1, 640, 480, 24);
2270 ok(hr==DD_OK || hr == DDERR_UNSUPPORTED, "SetDisplayMode returned: %x\n", hr);
2271 if (FAILED(hr)) goto out;
2273 hr = IDirectDraw_QueryInterface(DirectDraw1, &IID_IDirectDraw4, (void**)&DirectDraw4);
2274 ok(hr==DD_OK, "QueryInterface returned: %08x\n", hr);
2275 if(FAILED(hr)) goto out;
2277 memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
2278 ddsd.dwSize = sizeof(DDSURFACEDESC2);
2279 ddsd.dwFlags = DDSD_CAPS;
2280 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE;
2282 hr = IDirectDraw_CreateSurface(DirectDraw4, &ddsd, &Primary, NULL);
2283 ok(hr==DD_OK, "IDirectDraw_CreateSurface returned: %08x\n", hr);
2284 if(FAILED(hr)) goto out;
2286 hr = IDirectDraw4_QueryInterface(DirectDraw4, &IID_IDirect3D3, (void**)&Direct3D3);
2287 ok(hr==DD_OK, "IDirectDraw4_QueryInterface returned: %08x\n", hr);
2288 if(FAILED(hr)) goto out;
2290 hr = IDirect3D3_CreateDevice(Direct3D3, &IID_IDirect3DHALDevice, Primary, &Direct3DDevice3, NULL);
2291 if(FAILED(hr)) {
2292 trace("Creating a HAL device failed, trying Ref\n");
2293 hr = IDirect3D3_CreateDevice(Direct3D3, &IID_IDirect3DRefDevice, Primary, &Direct3DDevice3, NULL);
2295 ok(hr==D3D_OK, "Creating 3D device returned: %x\n", hr);
2296 if(FAILED(hr)) goto out;
2298 hr = IDirect3D3_CreateViewport(Direct3D3, &Viewport3, NULL);
2299 ok(hr==DD_OK, "IDirect3D3_CreateViewport returned: %08x\n", hr);
2300 if(FAILED(hr)) goto out;
2302 hr = IDirect3DDevice3_AddViewport(Direct3DDevice3, Viewport3);
2303 ok(hr==DD_OK, "IDirect3DDevice3_AddViewport returned: %08x\n", hr);
2305 memset(&vp_data, 0, sizeof(D3DVIEWPORT2));
2306 vp_data.dwSize = sizeof(D3DVIEWPORT2);
2307 vp_data.dwWidth = 640;
2308 vp_data.dwHeight = 480;
2309 vp_data.dvClipX = -1.0f;
2310 vp_data.dvClipWidth = 2.0f;
2311 vp_data.dvClipY = 1.0f;
2312 vp_data.dvClipHeight = 2.0f;
2313 vp_data.dvMaxZ = 1.0f;
2314 hr = IDirect3DViewport3_SetViewport2(Viewport3, &vp_data);
2315 ok(hr==DD_OK, "IDirect3DViewport3_SetViewport2 returned: %08x\n", hr);
2317 hr = IDirect3D3_CreateViewport(Direct3D3, &SmallViewport3, NULL);
2318 ok(hr==DD_OK, "IDirect3D3_CreateViewport returned: %08x\n", hr);
2319 if(FAILED(hr)) goto out;
2321 hr = IDirect3DDevice3_AddViewport(Direct3DDevice3, SmallViewport3);
2322 ok(hr==DD_OK, "IDirect3DDevice3_AddViewport returned: %08x\n", hr);
2324 memset(&vp_data, 0, sizeof(D3DVIEWPORT2));
2325 vp_data.dwSize = sizeof(D3DVIEWPORT2);
2326 vp_data.dwX = 400;
2327 vp_data.dwY = 100;
2328 vp_data.dwWidth = 100;
2329 vp_data.dwHeight = 100;
2330 vp_data.dvClipX = -1.0f;
2331 vp_data.dvClipWidth = 2.0f;
2332 vp_data.dvClipY = 1.0f;
2333 vp_data.dvClipHeight = 2.0f;
2334 vp_data.dvMaxZ = 1.0f;
2335 hr = IDirect3DViewport3_SetViewport2(SmallViewport3, &vp_data);
2336 ok(hr==DD_OK, "IDirect3DViewport3_SetViewport2 returned: %08x\n", hr);
2338 hr = IDirect3DDevice3_BeginScene(Direct3DDevice3);
2339 ok(hr == D3D_OK, "IDirect3DDevice3_BeginScene failed with %08x\n", hr);
2341 hr = IDirect3DDevice3_SetTransform(Direct3DDevice3, D3DTRANSFORMSTATE_WORLD, &mat);
2342 ok(hr == D3D_OK, "IDirect3DDevice3_SetTransform returned %08x\n", hr);
2343 hr = IDirect3DDevice3_SetTransform(Direct3DDevice3, D3DTRANSFORMSTATE_VIEW, &mat);
2344 ok(hr == D3D_OK, "IDirect3DDevice3_SetTransform returned %08x\n", hr);
2345 hr = IDirect3DDevice3_SetTransform(Direct3DDevice3, D3DTRANSFORMSTATE_PROJECTION, &mat);
2346 ok(hr == D3D_OK, "IDirect3DDevice3_SetTransform returned %08x\n", hr);
2347 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_CLIPPING, FALSE);
2348 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState returned %08x\n", hr);
2349 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_ZENABLE, FALSE);
2350 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState returned %08x\n", hr);
2351 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_FOGENABLE, FALSE);
2352 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState returned %08x\n", hr);
2353 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_STENCILENABLE, FALSE);
2354 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState returned %08x\n", hr);
2355 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_ALPHATESTENABLE, FALSE);
2356 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState returned %08x\n", hr);
2357 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
2358 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState returned %08x\n", hr);
2359 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
2360 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState failed with %08x\n", hr);
2361 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_LIGHTING, FALSE);
2362 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState returned %08x\n", hr);
2364 if (SUCCEEDED(hr)) {
2365 U1(rect).x1 = U2(rect).y1 = 0;
2366 U3(rect).x2 = 640;
2367 U4(rect).y2 = 480;
2369 hr = IDirect3DViewport3_Clear2(Viewport3, 1, &rect, D3DCLEAR_TARGET, 0x00ff00, 0.0f, 0);
2370 ok(hr == D3D_OK, "IDirect3DViewport3_Clear2 failed, hr = %08x\n", hr);
2372 hr = IDirect3DViewport3_Clear2(SmallViewport3, 1, &rect, D3DCLEAR_TARGET, 0xff0000, 0.0f, 0);
2373 ok(hr == D3D_OK, "IDirect3DViewport3_Clear2 failed, hr = %08x\n", hr);
2375 hr = IDirect3DDevice3_EndScene(Direct3DDevice3);
2376 ok(hr == D3D_OK, "IDirect3DDevice3_EndScene failed, hr = %08x\n", hr);
2379 color = D3D3_getPixelColor(DirectDraw4, Primary, 5, 5);
2380 red = (color & 0x00ff0000) >> 16;
2381 green = (color & 0x0000ff00) >> 8;
2382 blue = (color & 0x000000ff);
2383 ok(red == 0 && green == 0xff && blue == 0, "Got color %08x, expected 0000ff00\n", color);
2385 color = D3D3_getPixelColor(DirectDraw4, Primary, 405, 105);
2386 red = (color & 0x00ff0000) >> 16;
2387 green = (color & 0x0000ff00) >> 8;
2388 blue = (color & 0x000000ff);
2389 ok(red == 0xff && green == 0 && blue == 0, "Got color %08x, expected 00ff0000\n", color);
2391 /* Test that clearing viewport doesn't interfere with rendering to previously active viewport. */
2392 hr = IDirect3DDevice3_BeginScene(Direct3DDevice3);
2393 ok(hr == D3D_OK, "IDirect3DDevice3_BeginScene failed with %08x\n", hr);
2395 if (SUCCEEDED(hr)) {
2396 hr = IDirect3DDevice3_SetCurrentViewport(Direct3DDevice3, SmallViewport3);
2397 ok(hr == D3D_OK, "IDirect3DDevice3_SetCurrentViewport failed with %08x\n", hr);
2399 hr = IDirect3DViewport3_Clear2(Viewport3, 1, &rect, D3DCLEAR_TARGET, 0x000000, 0.0f, 0);
2400 ok(hr == D3D_OK, "IDirect3DViewport3_Clear2 failed, hr = %08x\n", hr);
2402 hr = IDirect3DDevice3_DrawIndexedPrimitive(Direct3DDevice3, D3DPT_TRIANGLELIST, fvf, quad, 4 /* NumVerts */,
2403 Indices, 6 /* Indexcount */, 0 /* flags */);
2404 ok(hr == D3D_OK, "IDirect3DDevice3_DrawIndexedPrimitive failed with %08x\n", hr);
2406 hr = IDirect3DDevice3_EndScene(Direct3DDevice3);
2407 ok(hr == D3D_OK, "IDirect3DDevice3_EndScene failed, hr = %08x\n", hr);
2410 color = D3D3_getPixelColor(DirectDraw4, Primary, 5, 5);
2411 red = (color & 0x00ff0000) >> 16;
2412 green = (color & 0x0000ff00) >> 8;
2413 blue = (color & 0x000000ff);
2414 ok(red == 0 && green == 0 && blue == 0, "Got color %08x, expected 00000000\n", color);
2416 color = D3D3_getPixelColor(DirectDraw4, Primary, 405, 105);
2417 red = (color & 0x00ff0000) >> 16;
2418 green = (color & 0x0000ff00) >> 8;
2419 blue = (color & 0x000000ff);
2420 ok(red == 0xff && green == 0xff && blue == 0xff, "Got color %08x, expected 00ffffff\n", color);
2422 out:
2424 if (SmallViewport3) IDirect3DViewport3_Release(SmallViewport3);
2425 if (Viewport3) IDirect3DViewport3_Release(Viewport3);
2426 if (Direct3DDevice3) IDirect3DDevice3_Release(Direct3DDevice3);
2427 if (Direct3D3) IDirect3D3_Release(Direct3D3);
2428 if (Primary) IDirectDrawSurface4_Release(Primary);
2429 if (DirectDraw1) IDirectDraw_Release(DirectDraw1);
2430 if (DirectDraw4) IDirectDraw4_Release(DirectDraw4);
2431 if(window) DestroyWindow(window);
2434 static void p8_surface_fill_rect(IDirectDrawSurface *dest, UINT x, UINT y, UINT w, UINT h, BYTE colorindex)
2436 DDSURFACEDESC ddsd;
2437 HRESULT hr;
2438 UINT i, i1;
2439 BYTE *p;
2441 memset(&ddsd, 0, sizeof(ddsd));
2442 ddsd.dwSize = sizeof(ddsd);
2444 hr = IDirectDrawSurface_Lock(dest, NULL, &ddsd, DDLOCK_WRITEONLY | DDLOCK_WAIT, NULL);
2445 ok(hr==DD_OK, "IDirectDrawSurface_Lock returned: %x\n", hr);
2447 p = (BYTE *)ddsd.lpSurface + U1(ddsd).lPitch * y + x;
2449 for (i = 0; i < h; i++) {
2450 for (i1 = 0; i1 < w; i1++) {
2451 p[i1] = colorindex;
2453 p += U1(ddsd).lPitch;
2456 hr = IDirectDrawSurface_Unlock(dest, NULL);
2457 ok(hr==DD_OK, "IDirectDrawSurface_UnLock returned: %x\n", hr);
2460 static COLORREF getPixelColor_GDI(IDirectDrawSurface *Surface, UINT x, UINT y)
2462 COLORREF clr = CLR_INVALID;
2463 HDC hdc;
2464 HRESULT hr;
2466 hr = IDirectDrawSurface_GetDC(Surface, &hdc);
2467 ok(hr==DD_OK, "IDirectDrawSurface_GetDC returned: %x\n", hr);
2469 if (SUCCEEDED(hr)) {
2470 clr = GetPixel(hdc, x, y);
2472 hr = IDirectDrawSurface_ReleaseDC(Surface, hdc);
2473 ok(hr==DD_OK, "IDirectDrawSurface_ReleaseDC returned: %x\n", hr);
2476 return clr;
2479 static BOOL colortables_check_equality(PALETTEENTRY table1[256], RGBQUAD table2[256])
2481 int i;
2483 for (i = 0; i < 256; i++) {
2484 if (table1[i].peRed != table2[i].rgbRed || table1[i].peGreen != table2[i].rgbGreen ||
2485 table1[i].peBlue != table2[i].rgbBlue) return FALSE;
2488 return TRUE;
2491 static void p8_primary_test(void)
2493 /* Test 8bit mode used by games like StarCraft, C&C Red Alert I etc */
2494 DDSURFACEDESC ddsd;
2495 HDC hdc;
2496 HRESULT hr;
2497 PALETTEENTRY entries[256];
2498 RGBQUAD coltable[256];
2499 UINT i, i1, i2;
2500 IDirectDrawPalette *ddprimpal = NULL;
2501 IDirectDrawSurface *offscreen = NULL;
2502 WNDCLASSA wc = {0};
2503 DDBLTFX ddbltfx;
2504 COLORREF color;
2505 RECT rect;
2506 DDCOLORKEY clrKey;
2507 unsigned differences;
2509 /* An IDirect3DDevice cannot be queryInterfaced from an IDirect3DDevice7 on windows */
2510 hr = DirectDrawCreate(NULL, &DirectDraw1, NULL);
2512 ok(hr==DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreate returned: %x\n", hr);
2513 if (FAILED(hr)) {
2514 goto out;
2517 wc.lpfnWndProc = DefWindowProcA;
2518 wc.lpszClassName = "p8_primary_test_wc";
2519 RegisterClassA(&wc);
2520 window = CreateWindowA("p8_primary_test_wc", "p8_primary_test",
2521 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, 640, 480, 0, 0, 0, 0);
2523 hr = IDirectDraw_SetCooperativeLevel(DirectDraw1, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2524 ok(hr==DD_OK, "SetCooperativeLevel returned: %x\n", hr);
2525 if(FAILED(hr)) {
2526 goto out;
2529 hr = IDirectDraw_SetDisplayMode(DirectDraw1, 640, 480, 8);
2530 ok(hr==DD_OK || hr == DDERR_UNSUPPORTED, "SetDisplayMode returned: %x\n", hr);
2531 if (FAILED(hr)) {
2532 goto out;
2535 memset(&ddsd, 0, sizeof(ddsd));
2536 ddsd.dwSize = sizeof(ddsd);
2537 ddsd.dwFlags = DDSD_CAPS;
2538 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2539 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &Surface1, NULL);
2540 ok(hr==DD_OK, "CreateSurface returned: %x\n", hr);
2541 if (FAILED(hr)) {
2542 goto out;
2545 memset(entries, 0, sizeof(entries));
2546 entries[0].peRed = 0xff;
2547 entries[1].peGreen = 0xff;
2548 entries[2].peBlue = 0xff;
2550 hr = IDirectDraw_CreatePalette(DirectDraw1, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, entries, &ddprimpal, NULL);
2551 ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
2552 if (FAILED(hr)) {
2553 skip("IDirectDraw_CreatePalette failed; skipping further tests\n");
2554 goto out;
2557 hr = IDirectDrawSurface_SetPalette(Surface1, ddprimpal);
2558 ok(hr==DD_OK, "IDirectDrawSurface_SetPalette returned: %x\n", hr);
2560 p8_surface_fill_rect(Surface1, 0, 0, 640, 480, 2);
2562 color = getPixelColor_GDI(Surface1, 10, 10);
2563 ok(GetRValue(color) == 0 && GetGValue(color) == 0 && GetBValue(color) == 0xFF,
2564 "got R %02X G %02X B %02X, expected R 00 G 00 B FF\n",
2565 GetRValue(color), GetGValue(color), GetBValue(color));
2567 memset(&ddbltfx, 0, sizeof(ddbltfx));
2568 ddbltfx.dwSize = sizeof(ddbltfx);
2569 U5(ddbltfx).dwFillColor = 0;
2570 hr = IDirectDrawSurface_Blt(Surface1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
2571 ok(hr == DD_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
2573 color = getPixelColor_GDI(Surface1, 10, 10);
2574 ok(GetRValue(color) == 0xFF && GetGValue(color) == 0 && GetBValue(color) == 0,
2575 "got R %02X G %02X B %02X, expected R FF G 00 B 00\n",
2576 GetRValue(color), GetGValue(color), GetBValue(color));
2578 memset(&ddbltfx, 0, sizeof(ddbltfx));
2579 ddbltfx.dwSize = sizeof(ddbltfx);
2580 U5(ddbltfx).dwFillColor = 1;
2581 hr = IDirectDrawSurface_Blt(Surface1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
2582 ok(hr == DD_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
2584 color = getPixelColor_GDI(Surface1, 10, 10);
2585 ok(GetRValue(color) == 0 && GetGValue(color) == 0xFF && GetBValue(color) == 0,
2586 "got R %02X G %02X B %02X, expected R 00 G FF B 00\n",
2587 GetRValue(color), GetGValue(color), GetBValue(color));
2589 memset (&ddsd, 0, sizeof (ddsd));
2590 ddsd.dwSize = sizeof (ddsd);
2591 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
2592 ddsd.dwWidth = 16;
2593 ddsd.dwHeight = 16;
2594 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;
2595 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
2596 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED8;
2597 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 8;
2598 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &offscreen, NULL);
2599 ok(hr == DD_OK ||
2600 broken(hr == DDERR_INVALIDPIXELFORMAT) || /* VMware */
2601 broken(hr == DDERR_NODIRECTDRAWHW), /* VMware */
2602 "IDirectDraw_CreateSurface returned %08x\n", hr);
2603 if (FAILED(hr)) goto out;
2605 memset(entries, 0, sizeof(entries));
2606 for (i = 0; i < 256; i++) {
2607 entries[i].peBlue = i;
2609 hr = IDirectDrawPalette_SetEntries(ddprimpal, 0, 0, 256, entries);
2610 ok(hr == DD_OK, "IDirectDrawPalette_SetEntries failed with %08x\n", hr);
2612 hr = IDirectDrawSurface_GetDC(offscreen, &hdc);
2613 ok(hr==DD_OK, "IDirectDrawSurface_GetDC returned: %x\n", hr);
2614 i = GetDIBColorTable(hdc, 0, 256, coltable);
2615 ok(i == 256, "GetDIBColorTable returned %u, last error: %x\n", i, GetLastError());
2616 hr = IDirectDrawSurface_ReleaseDC(offscreen, hdc);
2617 ok(hr==DD_OK, "IDirectDrawSurface_ReleaseDC returned: %x\n", hr);
2619 ok(colortables_check_equality(entries, coltable), "unexpected colortable on offscreen surface\n");
2621 p8_surface_fill_rect(offscreen, 0, 0, 16, 16, 2);
2623 memset(entries, 0, sizeof(entries));
2624 entries[0].peRed = 0xff;
2625 entries[1].peGreen = 0xff;
2626 entries[2].peBlue = 0xff;
2627 entries[3].peRed = 0x80;
2628 hr = IDirectDrawPalette_SetEntries(ddprimpal, 0, 0, 256, entries);
2629 ok(hr == DD_OK, "IDirectDrawPalette_SetEntries failed with %08x\n", hr);
2631 hr = IDirectDrawSurface_BltFast(Surface1, 0, 0, offscreen, NULL, 0);
2632 ok(hr==DD_OK, "IDirectDrawSurface_BltFast returned: %x\n", hr);
2634 color = getPixelColor_GDI(Surface1, 1, 1);
2635 ok(GetRValue(color) == 0 && GetGValue(color) == 0x00 && GetBValue(color) == 0xFF,
2636 "got R %02X G %02X B %02X, expected R 00 G 00 B FF\n",
2637 GetRValue(color), GetGValue(color), GetBValue(color));
2639 /* Color keyed blit. */
2640 p8_surface_fill_rect(offscreen, 0, 0, 8, 8, 3);
2641 clrKey.dwColorSpaceLowValue = 3;
2642 clrKey.dwColorSpaceHighValue = 3;
2643 hr = IDirectDrawSurface_SetColorKey(offscreen, DDCKEY_SRCBLT, &clrKey);
2644 ok(hr==D3D_OK, "IDirectDrawSurfac_SetColorKey returned: %x\n", hr);
2646 hr = IDirectDrawSurface_BltFast(Surface1, 100, 100, offscreen, NULL, DDBLTFAST_SRCCOLORKEY);
2647 ok(hr==DD_OK, "IDirectDrawSurface_BltFast returned: %x\n", hr);
2649 color = getPixelColor_GDI(Surface1, 105, 105);
2650 ok(GetRValue(color) == 0 && GetGValue(color) == 0xFF && GetBValue(color) == 0,
2651 "got R %02X G %02X B %02X, expected R 00 G FF B 00\n",
2652 GetRValue(color), GetGValue(color), GetBValue(color));
2654 color = getPixelColor_GDI(Surface1, 112, 112);
2655 ok(GetRValue(color) == 0 && GetGValue(color) == 0x00 && GetBValue(color) == 0xFF,
2656 "got R %02X G %02X B %02X, expected R 00 G 00 B FF\n",
2657 GetRValue(color), GetGValue(color), GetBValue(color));
2659 rect.left = 100;
2660 rect.top = 200;
2661 rect.right = 116;
2662 rect.bottom = 216;
2664 memset(&ddbltfx, 0, sizeof(ddbltfx));
2665 ddbltfx.dwSize = sizeof(ddbltfx);
2666 ddbltfx.ddckSrcColorkey.dwColorSpaceLowValue = ddbltfx.ddckSrcColorkey.dwColorSpaceHighValue = 2;
2667 hr = IDirectDrawSurface_Blt(Surface1, &rect, offscreen, NULL,
2668 DDBLT_WAIT | DDBLT_KEYSRC | DDBLT_KEYSRCOVERRIDE, &ddbltfx);
2669 ok(hr==DDERR_INVALIDPARAMS, "IDirectDrawSurface_Blt returned: %x\n", hr);
2670 hr = IDirectDrawSurface_Blt(Surface1, &rect, offscreen, NULL,
2671 DDBLT_WAIT | DDBLT_KEYSRCOVERRIDE, &ddbltfx);
2672 ok(hr==DD_OK, "IDirectDrawSurface_Blt returned: %x\n", hr);
2674 color = getPixelColor_GDI(Surface1, 105, 205);
2675 ok(GetRValue(color) == 0x80 && GetGValue(color) == 0 && GetBValue(color) == 0,
2676 "got R %02X G %02X B %02X, expected R 80 G 00 B 00\n",
2677 GetRValue(color), GetGValue(color), GetBValue(color));
2679 color = getPixelColor_GDI(Surface1, 112, 212);
2680 ok(GetRValue(color) == 0 && GetGValue(color) == 0xFF && GetBValue(color) == 0,
2681 "got R %02X G %02X B %02X, expected R 00 G FF B 00\n",
2682 GetRValue(color), GetGValue(color), GetBValue(color));
2684 /* Test blitting and locking patterns that are likely to trigger bugs in opengl renderer (p8
2685 surface conversion and uploading/downloading to/from opengl texture). Similar patterns (
2686 blitting front buffer areas to/from an offscreen surface mixed with locking) are used by C&C
2687 Red Alert I. */
2688 IDirectDrawSurface_Release(offscreen);
2690 memset (&ddsd, 0, sizeof (ddsd));
2691 ddsd.dwSize = sizeof (ddsd);
2692 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
2693 ddsd.dwWidth = 640;
2694 ddsd.dwHeight = 480;
2695 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
2696 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
2697 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED8;
2698 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 8;
2699 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &offscreen, NULL);
2700 ok(hr == DD_OK, "IDirectDraw_CreateSurface returned %08x\n", hr);
2702 if (FAILED(hr)) goto out;
2704 /* Test two times, first time front buffer has a palette and second time front buffer
2705 has no palette; the latter is somewhat contrived example, but an app could set
2706 front buffer palette later. */
2707 for (i2 = 0; i2 < 2; i2++) {
2708 if (i2 == 1) {
2709 hr = IDirectDrawSurface_SetPalette(Surface1, NULL);
2710 ok(hr==DD_OK, "IDirectDrawSurface_SetPalette returned: %x\n", hr);
2713 memset(&ddsd, 0, sizeof(ddsd));
2714 ddsd.dwSize = sizeof(ddsd);
2715 hr = IDirectDrawSurface_Lock(Surface1, NULL, &ddsd, DDLOCK_WAIT, NULL);
2716 ok(hr==DD_OK, "IDirectDrawSurface_Lock returned: %x\n", hr);
2718 for (i = 0; i < 256; i++) {
2719 unsigned x = (i % 128) * 4;
2720 unsigned y = (i / 128) * 4;
2721 BYTE *p = (BYTE *)ddsd.lpSurface + U1(ddsd).lPitch * y + x;
2723 for (i1 = 0; i1 < 4; i1++) {
2724 p[0] = p[1] = p[2] = p[3] = i;
2725 p += U1(ddsd).lPitch;
2729 hr = IDirectDrawSurface_Unlock(Surface1, NULL);
2730 ok(hr==DD_OK, "IDirectDrawSurface_UnLock returned: %x\n", hr);
2732 hr = IDirectDrawSurface_BltFast(offscreen, 0, 0, Surface1, NULL, 0);
2733 ok(hr==DD_OK, "IDirectDrawSurface_BltFast returned: %x\n", hr);
2735 /* This ensures offscreen surface contents will be downloaded to system memory. */
2736 memset(&ddsd, 0, sizeof(ddsd));
2737 ddsd.dwSize = sizeof(ddsd);
2738 hr = IDirectDrawSurface_Lock(offscreen, NULL, &ddsd, DDLOCK_WAIT, NULL);
2739 ok(hr==DD_OK, "IDirectDrawSurface_Lock returned: %x\n", hr);
2740 hr = IDirectDrawSurface_Unlock(offscreen, NULL);
2741 ok(hr==DD_OK, "IDirectDrawSurface_UnLock returned: %x\n", hr);
2743 /* Offscreen surface data will have to be converted and uploaded to texture. */
2744 rect.left = 0;
2745 rect.top = 0;
2746 rect.right = 16;
2747 rect.bottom = 16;
2748 hr = IDirectDrawSurface_BltFast(offscreen, 600, 400, Surface1, &rect, 0);
2749 ok(hr==DD_OK, "IDirectDrawSurface_BltFast returned: %x\n", hr);
2751 /* This ensures offscreen surface contents will be downloaded to system memory. */
2752 memset(&ddsd, 0, sizeof(ddsd));
2753 ddsd.dwSize = sizeof(ddsd);
2754 hr = IDirectDrawSurface_Lock(offscreen, NULL, &ddsd, DDLOCK_WAIT, NULL);
2755 ok(hr==DD_OK, "IDirectDrawSurface_Lock returned: %x\n", hr);
2756 hr = IDirectDrawSurface_Unlock(offscreen, NULL);
2757 ok(hr==DD_OK, "IDirectDrawSurface_UnLock returned: %x\n", hr);
2759 hr = IDirectDrawSurface_BltFast(Surface1, 0, 0, offscreen, NULL, 0);
2760 ok(hr==DD_OK, "IDirectDrawSurface_BltFast returned: %x\n", hr);
2762 memset(&ddsd, 0, sizeof(ddsd));
2763 ddsd.dwSize = sizeof(ddsd);
2764 hr = IDirectDrawSurface_Lock(Surface1, NULL, &ddsd, DDLOCK_WAIT, NULL);
2765 ok(hr==DD_OK, "IDirectDrawSurface_Lock returned: %x\n", hr);
2767 differences = 0;
2769 for (i = 0; i < 256; i++) {
2770 unsigned x = (i % 128) * 4 + 1;
2771 unsigned y = (i / 128) * 4 + 1;
2772 BYTE *p = (BYTE *)ddsd.lpSurface + U1(ddsd).lPitch * y + x;
2774 if (*p != i) differences++;
2777 hr = IDirectDrawSurface_Unlock(Surface1, NULL);
2778 ok(hr==DD_OK, "IDirectDrawSurface_UnLock returned: %x\n", hr);
2780 ok(differences == 0, i2 == 0 ? "Pass 1. Unexpected front buffer contents after blit (%u differences)\n" :
2781 "Pass 2 (with NULL front buffer palette). Unexpected front buffer contents after blit (%u differences)\n",
2782 differences);
2785 out:
2787 if(ddprimpal) IDirectDrawPalette_Release(ddprimpal);
2788 if(offscreen) IDirectDrawSurface_Release(offscreen);
2789 if(Surface1) IDirectDrawSurface_Release(Surface1);
2790 if(DirectDraw1) IDirectDraw_Release(DirectDraw1);
2791 if(window) DestroyWindow(window);
2794 static void cubemap_test(IDirect3DDevice7 *device)
2796 IDirect3D7 *d3d;
2797 IDirectDraw7 *ddraw;
2798 IDirectDrawSurface7 *cubemap, *surface;
2799 D3DDEVICEDESC7 d3dcaps;
2800 HRESULT hr;
2801 DWORD color;
2802 DDSURFACEDESC2 ddsd;
2803 DDBLTFX DDBltFx;
2804 DDSCAPS2 caps;
2805 static float quad[] = {
2806 -1.0, -1.0, 0.1, 1.0, 0.0, 0.0, /* Lower left */
2807 0.0, -1.0, 0.1, 1.0, 0.0, 0.0,
2808 -1.0, 0.0, 0.1, 1.0, 0.0, 0.0,
2809 0.0, 0.0, 0.1, 1.0, 0.0, 0.0,
2811 0.0, -1.0, 0.1, 0.0, 1.0, 0.0, /* Lower right */
2812 1.0, -1.0, 0.1, 0.0, 1.0, 0.0,
2813 0.0, 0.0, 0.1, 0.0, 1.0, 0.0,
2814 1.0, 0.0, 0.1, 0.0, 1.0, 0.0,
2816 0.0, 0.0, 0.1, 0.0, 0.0, 1.0, /* upper right */
2817 1.0, 0.0, 0.1, 0.0, 0.0, 1.0,
2818 0.0, 1.0, 0.1, 0.0, 0.0, 1.0,
2819 1.0, 1.0, 0.1, 0.0, 0.0, 1.0,
2821 -1.0, 0.0, 0.1, -1.0, 0.0, 0.0, /* Upper left */
2822 0.0, 0.0, 0.1, -1.0, 0.0, 0.0,
2823 -1.0, 1.0, 0.1, -1.0, 0.0, 0.0,
2824 0.0, 1.0, 0.1, -1.0, 0.0, 0.0,
2827 memset(&DDBltFx, 0, sizeof(DDBltFx));
2828 DDBltFx.dwSize = sizeof(DDBltFx);
2830 memset(&d3dcaps, 0, sizeof(d3dcaps));
2831 hr = IDirect3DDevice7_GetCaps(device, &d3dcaps);
2832 ok(hr == D3D_OK, "IDirect3DDevice7_GetCaps returned %08x\n", hr);
2833 if(!(d3dcaps.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_CUBEMAP))
2835 skip("No cubemap support\n");
2836 return;
2839 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff000000, 0.0, 0);
2840 ok(hr == D3D_OK, "IDirect3DDevice7_Clear failed with %08x\n", hr);
2842 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
2843 ok(hr == D3D_OK, "IDirect3DDevice7_GetDirect3D returned %08x\n", hr);
2844 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **) &ddraw);
2845 ok(hr == D3D_OK, "IDirect3D7_QueryInterface returned %08x\n", hr);
2846 IDirect3D7_Release(d3d);
2849 memset(&ddsd, 0, sizeof(ddsd));
2850 ddsd.dwSize = sizeof(ddsd);
2851 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
2852 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
2853 ddsd.dwWidth = 16;
2854 ddsd.dwHeight = 16;
2855 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX;
2856 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_TEXTUREMANAGE;
2857 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
2858 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
2859 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00FF0000;
2860 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000FF00;
2861 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000FF;
2863 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &cubemap, NULL);
2864 ok(hr == DD_OK, "IDirectDraw7_CreateSurface returned %08x\n", hr);
2865 IDirectDraw7_Release(ddraw);
2867 /* Positive X */
2868 U5(DDBltFx).dwFillColor = 0x00ff0000;
2869 hr = IDirectDrawSurface7_Blt(cubemap, NULL, NULL, NULL, DDBLT_COLORFILL, &DDBltFx);
2870 ok(hr == DD_OK, "IDirectDrawSurface7_Blt returned %08x\n", hr);
2872 memset(&caps, 0, sizeof(caps));
2873 caps.dwCaps = DDSCAPS_TEXTURE;
2874 caps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX;
2875 hr = IDirectDrawSurface_GetAttachedSurface(cubemap, &caps, &surface);
2876 ok(hr == DD_OK, "IDirectDrawSurface7_Lock returned %08x\n", hr);
2877 U5(DDBltFx).dwFillColor = 0x0000ffff;
2878 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL, &DDBltFx);
2879 ok(hr == DD_OK, "IDirectDrawSurface7_Blt returned %08x\n", hr);
2881 caps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEZ;
2882 hr = IDirectDrawSurface_GetAttachedSurface(cubemap, &caps, &surface);
2883 ok(hr == DD_OK, "IDirectDrawSurface7_Lock returned %08x\n", hr);
2884 U5(DDBltFx).dwFillColor = 0x0000ff00;
2885 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL, &DDBltFx);
2886 ok(hr == DD_OK, "IDirectDrawSurface7_Blt returned %08x\n", hr);
2888 caps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEZ;
2889 hr = IDirectDrawSurface_GetAttachedSurface(cubemap, &caps, &surface);
2890 ok(hr == DD_OK, "IDirectDrawSurface7_Lock returned %08x\n", hr);
2891 U5(DDBltFx).dwFillColor = 0x000000ff;
2892 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL, &DDBltFx);
2893 ok(hr == DD_OK, "IDirectDrawSurface7_Blt returned %08x\n", hr);
2895 caps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEY;
2896 hr = IDirectDrawSurface_GetAttachedSurface(cubemap, &caps, &surface);
2897 ok(hr == DD_OK, "IDirectDrawSurface7_Lock returned %08x\n", hr);
2898 U5(DDBltFx).dwFillColor = 0x00ffff00;
2899 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL, &DDBltFx);
2900 ok(hr == DD_OK, "IDirectDrawSurface7_Blt returned %08x\n", hr);
2902 caps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEY;
2903 hr = IDirectDrawSurface_GetAttachedSurface(cubemap, &caps, &surface);
2904 ok(hr == DD_OK, "IDirectDrawSurface7_Lock returned %08x\n", hr);
2905 U5(DDBltFx).dwFillColor = 0x00ff00ff;
2906 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL, &DDBltFx);
2907 ok(hr == DD_OK, "IDirectDrawSurface7_Blt returned %08x\n", hr);
2909 hr = IDirect3DDevice7_SetTexture(device, 0, cubemap);
2910 ok(hr == DD_OK, "IDirect3DDevice7_SetTexture returned %08x\n", hr);
2911 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
2912 ok(hr == DD_OK, "IDirect3DDevice7_SetTextureStageState returned %08x\n", hr);
2913 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
2914 ok(hr == DD_OK, "IDirect3DDevice7_SetTextureStageState returned %08x\n", hr);
2916 hr = IDirect3DDevice7_BeginScene(device);
2917 ok(hr == DD_OK, "IDirect3DDevice7_BeginScene returned %08x\n", hr);
2918 if(SUCCEEDED(hr))
2920 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1, quad + 0 * 6, 4, 0);
2921 if (hr == DDERR_UNSUPPORTED || hr == DDERR_NODIRECTDRAWHW)
2923 /* VMware */
2924 win_skip("IDirect3DDevice7_DrawPrimitive is not completely implemented, colors won't be tested\n");
2925 hr = IDirect3DDevice7_EndScene(device);
2926 ok(hr == DD_OK, "IDirect3DDevice7_EndScene returned %08x\n", hr);
2927 goto out;
2929 ok(hr == DD_OK, "IDirect3DDevice7_DrawPrimitive returned %08x\n", hr);
2930 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1, quad + 4 * 6, 4, 0);
2931 ok(hr == DD_OK, "IDirect3DDevice7_DrawPrimitive returned %08x\n", hr);
2932 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1, quad + 8 * 6, 4, 0);
2933 ok(hr == DD_OK, "IDirect3DDevice7_DrawPrimitive returned %08x\n", hr);
2934 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1, quad + 12* 6, 4, 0);
2935 ok(hr == DD_OK, "IDirect3DDevice7_DrawPrimitive returned %08x\n", hr);
2937 hr = IDirect3DDevice7_EndScene(device);
2938 ok(hr == DD_OK, "IDirect3DDevice7_EndScene returned %08x\n", hr);
2940 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_DISABLE);
2941 ok(hr == DD_OK, "IDirect3DDevice7_SetTextureStageState returned %08x\n", hr);
2943 color = getPixelColor(device, 160, 360); /* lower left quad - positivex */
2944 ok(color == 0x00ff0000, "DDSCAPS2_CUBEMAP_POSITIVEX has color 0x%08x, expected 0x00ff0000\n", color);
2945 color = getPixelColor(device, 160, 120); /* upper left quad - negativex */
2946 ok(color == 0x0000ffff, "DDSCAPS2_CUBEMAP_NEGATIVEX has color 0x%08x, expected 0x0000ffff\n", color);
2947 color = getPixelColor(device, 480, 360); /* lower right quad - positivey */
2948 ok(color == 0x00ff00ff, "DDSCAPS2_CUBEMAP_POSITIVEY has color 0x%08x, expected 0x00ff00ff\n", color);
2949 color = getPixelColor(device, 480, 120); /* upper right quad - positivez */
2950 ok(color == 0x000000ff, "DDSCAPS2_CUBEMAP_POSITIVEZ has color 0x%08x, expected 0x000000ff\n", color);
2952 out:
2953 hr = IDirect3DDevice7_SetTexture(device, 0, NULL);
2954 ok(hr == DD_OK, "IDirect3DDevice7_SetTexture returned %08x\n", hr);
2955 IDirectDrawSurface7_Release(cubemap);
2958 /* This test tests depth clamping / clipping behaviour:
2959 * - With software vertex processing, depth values are clamped to the
2960 * minimum / maximum z value when D3DRS_CLIPPING is disabled, and clipped
2961 * when D3DRS_CLIPPING is enabled. Pretransformed vertices behave the
2962 * same as regular vertices here.
2963 * - With hardware vertex processing, D3DRS_CLIPPING seems to be ignored.
2964 * Normal vertices are always clipped. Pretransformed vertices are
2965 * clipped when D3DPMISCCAPS_CLIPTLVERTS is set, clamped when it isn't.
2966 * - The viewport's MinZ/MaxZ is irrelevant for this.
2968 static void depth_clamp_test(IDirect3DDevice7 *device)
2970 struct tvertex quad1[] =
2972 { 0.0f, 0.0f, 5.0f, 1.0f, 0xff002b7f},
2973 {640.0f, 0.0f, 5.0f, 1.0f, 0xff002b7f},
2974 { 0.0f, 480.0f, 5.0f, 1.0f, 0xff002b7f},
2975 {640.0f, 480.0f, 5.0f, 1.0f, 0xff002b7f},
2977 struct tvertex quad2[] =
2979 { 0.0f, 300.0f, 10.0f, 1.0f, 0xfff9e814},
2980 {640.0f, 300.0f, 10.0f, 1.0f, 0xfff9e814},
2981 { 0.0f, 360.0f, 10.0f, 1.0f, 0xfff9e814},
2982 {640.0f, 360.0f, 10.0f, 1.0f, 0xfff9e814},
2984 struct tvertex quad3[] =
2986 {112.0f, 108.0f, 5.0f, 1.0f, 0xffffffff},
2987 {208.0f, 108.0f, 5.0f, 1.0f, 0xffffffff},
2988 {112.0f, 204.0f, 5.0f, 1.0f, 0xffffffff},
2989 {208.0f, 204.0f, 5.0f, 1.0f, 0xffffffff},
2991 struct tvertex quad4[] =
2993 { 42.0f, 41.0f, 10.0f, 1.0f, 0xffffffff},
2994 {112.0f, 41.0f, 10.0f, 1.0f, 0xffffffff},
2995 { 42.0f, 108.0f, 10.0f, 1.0f, 0xffffffff},
2996 {112.0f, 108.0f, 10.0f, 1.0f, 0xffffffff},
2998 struct vertex quad5[] =
3000 { -0.5f, 0.5f, 10.0f, 0xff14f914},
3001 { 0.5f, 0.5f, 10.0f, 0xff14f914},
3002 { -0.5f, -0.5f, 10.0f, 0xff14f914},
3003 { 0.5f, -0.5f, 10.0f, 0xff14f914},
3005 struct vertex quad6[] =
3007 { -1.0f, 0.5f, 10.0f, 0xfff91414},
3008 { 1.0f, 0.5f, 10.0f, 0xfff91414},
3009 { -1.0f, 0.25f, 10.0f, 0xfff91414},
3010 { 1.0f, 0.25f, 10.0f, 0xfff91414},
3013 D3DVIEWPORT7 vp;
3014 D3DCOLOR color;
3015 HRESULT hr;
3017 vp.dwX = 0;
3018 vp.dwY = 0;
3019 vp.dwWidth = 640;
3020 vp.dwHeight = 480;
3021 vp.dvMinZ = 0.0;
3022 vp.dvMaxZ = 7.5;
3024 hr = IDirect3DDevice7_SetViewport(device, &vp);
3025 ok(SUCCEEDED(hr), "SetViewport failed, hr %#x.\n", hr);
3027 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 1.0, 0);
3028 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
3030 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
3031 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
3032 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
3033 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
3034 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZWRITEENABLE, TRUE);
3035 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
3036 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL);
3037 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
3039 hr = IDirect3DDevice7_BeginScene(device);
3040 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
3042 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, quad1, 4, 0);
3043 ok(SUCCEEDED(hr), "DrawPrimitive failed, hr %#x.\n", hr);
3044 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, quad2, 4, 0);
3045 ok(SUCCEEDED(hr), "DrawPrimitive failed, hr %#x.\n", hr);
3047 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, TRUE);
3048 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
3050 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, quad3, 4, 0);
3051 ok(SUCCEEDED(hr), "DrawPrimitive failed, hr %#x.\n", hr);
3052 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, quad4, 4, 0);
3053 ok(SUCCEEDED(hr), "DrawPrimitive failed, hr %#x.\n", hr);
3055 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
3056 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
3058 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad5, 4, 0);
3059 ok(SUCCEEDED(hr), "DrawPrimitive failed, hr %#x.\n", hr);
3061 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, TRUE);
3062 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
3064 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad6, 4, 0);
3065 ok(SUCCEEDED(hr), "DrawPrimitive failed, hr %#x.\n", hr);
3067 hr = IDirect3DDevice7_EndScene(device);
3068 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
3070 color = getPixelColor(device, 75, 75);
3071 ok(color_match(color, 0x00ffffff, 1) || color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
3072 color = getPixelColor(device, 150, 150);
3073 ok(color_match(color, 0x00ffffff, 1) || color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
3074 color = getPixelColor(device, 320, 240);
3075 ok(color_match(color, 0x00002b7f, 1) || color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
3076 color = getPixelColor(device, 320, 330);
3077 ok(color_match(color, 0x00f9e814, 1) || color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
3078 color = getPixelColor(device, 320, 330);
3079 ok(color_match(color, 0x00f9e814, 1) || color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
3081 vp.dvMinZ = 0.0;
3082 vp.dvMaxZ = 1.0;
3083 hr = IDirect3DDevice7_SetViewport(device, &vp);
3084 ok(SUCCEEDED(hr), "SetViewport failed, hr %#x.\n", hr);
3087 static void DX1_BackBufferFlipTest(void)
3089 HRESULT hr;
3090 IDirectDraw *DirectDraw1 = NULL;
3091 IDirectDrawSurface *Primary = NULL;
3092 IDirectDrawSurface *Backbuffer = NULL;
3093 WNDCLASSA wc = {0};
3094 DDSURFACEDESC ddsd;
3095 DDBLTFX ddbltfx;
3096 COLORREF color;
3097 const DWORD white = 0xffffff;
3098 const DWORD red = 0xff0000;
3099 BOOL attached = FALSE;
3101 wc.lpfnWndProc = DefWindowProcA;
3102 wc.lpszClassName = "DX1_BackBufferFlipTest_wc";
3103 RegisterClassA(&wc);
3104 window = CreateWindowA("DX1_BackBufferFlipTest_wc", "DX1_BackBufferFlipTest",
3105 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, 640, 480, 0, 0, 0, 0);
3107 hr = DirectDrawCreate( NULL, &DirectDraw1, NULL );
3108 ok(hr==DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreate returned: %x\n", hr);
3109 if(FAILED(hr)) goto out;
3111 hr = IDirectDraw_SetCooperativeLevel(DirectDraw1, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3112 ok(hr==DD_OK, "SetCooperativeLevel returned: %x\n", hr);
3113 if(FAILED(hr)) goto out;
3115 hr = IDirectDraw_SetDisplayMode(DirectDraw1, 640, 480, 32);
3116 if(FAILED(hr)) {
3117 /* 24 bit is fine too */
3118 hr = IDirectDraw_SetDisplayMode(DirectDraw1, 640, 480, 24);
3120 ok(hr==DD_OK || hr == DDERR_UNSUPPORTED, "SetDisplayMode returned: %x\n", hr);
3121 if (FAILED(hr)) {
3122 goto out;
3125 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
3126 ddsd.dwSize = sizeof(DDSURFACEDESC);
3127 ddsd.dwFlags = DDSD_CAPS;
3128 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3130 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &Primary, NULL);
3131 ok(hr==DD_OK, "IDirectDraw_CreateSurface returned: %08x\n", hr);
3133 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
3134 ddsd.dwSize = sizeof(DDSURFACEDESC);
3135 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
3136 ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
3137 ddsd.dwWidth = 640;
3138 ddsd.dwHeight = 480;
3139 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
3140 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
3141 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
3142 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
3143 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
3144 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x000000ff;
3146 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &Backbuffer, NULL);
3147 ok(hr==DD_OK, "IDirectDraw_CreateSurface returned: %08x\n", hr);
3148 if(FAILED(hr)) goto out;
3150 hr = IDirectDrawSurface_AddAttachedSurface(Primary, Backbuffer);
3151 todo_wine ok(hr == DD_OK || broken(hr == DDERR_CANNOTATTACHSURFACE),
3152 "Attaching a back buffer to a front buffer returned %08x\n", hr);
3153 if (FAILED(hr)) goto out;
3155 attached = TRUE;
3157 memset(&ddbltfx, 0, sizeof(ddbltfx));
3158 ddbltfx.dwSize = sizeof(ddbltfx);
3159 U5(ddbltfx).dwFillColor = red;
3160 hr = IDirectDrawSurface_Blt(Backbuffer, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
3161 ok(hr == DD_OK, "IDirectDrawSurface_Blt returned: %x\n", hr);
3163 U5(ddbltfx).dwFillColor = white;
3164 hr = IDirectDrawSurface_Blt(Primary, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
3165 ok(hr == DD_OK, "IDirectDrawSurface_Blt returned: %x\n", hr);
3167 /* Check it out */
3168 color = getPixelColor_GDI(Primary, 5, 5);
3169 ok(GetRValue(color) == 0xFF && GetGValue(color) == 0xFF && GetBValue(color) == 0xFF,
3170 "got R %02X G %02X B %02X, expected R FF G FF B FF\n",
3171 GetRValue(color), GetGValue(color), GetBValue(color));
3173 color = getPixelColor_GDI(Backbuffer, 5, 5);
3174 ok(GetRValue(color) == 0xFF && GetGValue(color) == 0 && GetBValue(color) == 0,
3175 "got R %02X G %02X B %02X, expected R FF G 00 B 00\n",
3176 GetRValue(color), GetGValue(color), GetBValue(color));
3178 hr = IDirectDrawSurface_Flip(Primary, NULL, DDFLIP_WAIT);
3179 todo_wine ok(hr == DD_OK, "IDirectDrawSurface_Flip returned 0x%08x\n", hr);
3181 if (hr == DD_OK)
3183 color = getPixelColor_GDI(Primary, 5, 5);
3184 ok(GetRValue(color) == 0xFF && GetGValue(color) == 0 && GetBValue(color) == 0,
3185 "got R %02X G %02X B %02X, expected R FF G 00 B 00\n",
3186 GetRValue(color), GetGValue(color), GetBValue(color));
3188 color = getPixelColor_GDI(Backbuffer, 5, 5);
3189 ok((GetRValue(color) == 0xFF && GetGValue(color) == 0xFF && GetBValue(color) == 0xFF) ||
3190 broken(GetRValue(color) == 0xFF && GetGValue(color) == 0 && GetBValue(color) == 0), /* broken driver */
3191 "got R %02X G %02X B %02X, expected R FF G FF B FF\n",
3192 GetRValue(color), GetGValue(color), GetBValue(color));
3195 out:
3197 if (Backbuffer)
3199 if (attached)
3200 IDirectDrawSurface_DeleteAttachedSurface(Primary, 0, Backbuffer);
3201 IDirectDrawSurface_Release(Backbuffer);
3203 if (Primary) IDirectDrawSurface_Release(Primary);
3204 if (DirectDraw1) IDirectDraw_Release(DirectDraw1);
3205 if (window) DestroyWindow(window);
3208 START_TEST(visual)
3210 HRESULT hr;
3211 DWORD color;
3212 if(!createObjects())
3214 skip("Cannot initialize DirectDraw and Direct3D, skipping\n");
3215 return;
3218 /* Check for the reliability of the returned data */
3219 hr = IDirect3DDevice7_Clear(Direct3DDevice, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
3220 if(FAILED(hr))
3222 skip("Clear failed, can't assure correctness of the test results, skipping\n");
3223 goto cleanup;
3226 color = getPixelColor(Direct3DDevice, 1, 1);
3227 if(color !=0x00ff0000)
3229 skip("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests, skipping\n", color);
3230 goto cleanup;
3233 hr = IDirect3DDevice7_Clear(Direct3DDevice, 0, NULL, D3DCLEAR_TARGET, 0xff00ddee, 0.0, 0);
3234 if(FAILED(hr))
3236 skip("Clear failed, can't assure correctness of the test results, skipping\n");
3237 goto cleanup;
3240 color = getPixelColor(Direct3DDevice, 639, 479);
3241 if(color != 0x0000ddee)
3243 skip("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests, skipping\n", color);
3244 goto cleanup;
3247 /* Now run the tests */
3248 blt_test(Direct3DDevice);
3249 depth_clamp_test(Direct3DDevice);
3250 lighting_test(Direct3DDevice);
3251 clear_test(Direct3DDevice);
3252 fog_test(Direct3DDevice);
3253 offscreen_test(Direct3DDevice);
3254 alpha_test(Direct3DDevice);
3255 rhw_zero_test(Direct3DDevice);
3256 cubemap_test(Direct3DDevice);
3258 releaseObjects(); /* release DX7 interfaces to test D3D1 */
3260 if(!D3D1_createObjects()) {
3261 skip("Cannot initialize D3D1, skipping\n");
3263 else {
3264 D3D1_TextureMapBlendTest();
3265 D3D1_ViewportClearTest();
3267 D3D1_releaseObjects();
3269 D3D3_ViewportClearTest();
3270 p8_primary_test();
3271 DX1_BackBufferFlipTest();
3273 return ;
3275 cleanup:
3276 releaseObjects();