push a6a7df41ae272b3b1bf5fcfb544267c1e96afa99
[wine/hacks.git] / dlls / ddraw / tests / visual.c
blob12f11c9e50add7c2eaf9eeb38a8ff4434115ee27
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 <assert.h>
23 #include "wine/test.h"
24 #include "ddraw.h"
25 #include "d3d.h"
27 HWND window;
28 IDirectDraw7 *DirectDraw = NULL;
29 IDirectDrawSurface7 *Surface;
30 IDirect3D7 *Direct3D = NULL;
31 IDirect3DDevice7 *Direct3DDevice = NULL;
33 IDirectDraw *DirectDraw1 = NULL;
34 IDirectDrawSurface *Surface1 = NULL;
35 IDirect3D *Direct3D1 = NULL;
36 IDirect3DDevice *Direct3DDevice1 = NULL;
37 IDirect3DExecuteBuffer *ExecuteBuffer = NULL;
38 IDirect3DViewport *Viewport = NULL;
40 static HRESULT (WINAPI *pDirectDrawCreateEx)(LPGUID,LPVOID*,REFIID,LPUNKNOWN);
42 static BOOL createObjects(void)
44 HRESULT hr;
45 HMODULE hmod = GetModuleHandleA("ddraw.dll");
46 WNDCLASS wc = {0};
47 DDSURFACEDESC2 ddsd;
50 if(!hmod) return FALSE;
51 pDirectDrawCreateEx = (void*)GetProcAddress(hmod, "DirectDrawCreateEx");
52 if(!pDirectDrawCreateEx) return FALSE;
54 hr = pDirectDrawCreateEx(NULL, (void **) &DirectDraw, &IID_IDirectDraw7, NULL);
55 ok(hr==DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", hr);
56 if(!DirectDraw) goto err;
58 wc.lpfnWndProc = DefWindowProc;
59 wc.lpszClassName = "d3d7_test_wc";
60 RegisterClass(&wc);
61 window = CreateWindow("d3d7_test_wc", "d3d7_test", WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
63 hr = IDirectDraw7_SetCooperativeLevel(DirectDraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
64 ok(hr == DD_OK, "IDirectDraw7_SetCooperativeLevel failed with %08x\n", hr);
65 if(FAILED(hr)) goto err;
66 hr = IDirectDraw7_SetDisplayMode(DirectDraw, 640, 480, 32, 0, 0);
67 if(FAILED(hr)) {
68 /* 24 bit is fine too */
69 hr = IDirectDraw7_SetDisplayMode(DirectDraw, 640, 480, 24, 0, 0);
72 ok(hr == DD_OK || hr == DDERR_UNSUPPORTED, "IDirectDraw7_SetDisplayMode failed with %08x\n", hr);
73 if(FAILED(hr)) {
74 /* use trace, the caller calls skip() */
75 trace("SetDisplayMode failed\n");
76 goto err;
79 hr = IDirectDraw7_QueryInterface(DirectDraw, &IID_IDirect3D7, (void**) &Direct3D);
80 if (hr == E_NOINTERFACE) goto err;
81 ok(hr==DD_OK, "QueryInterface returned: %08x\n", hr);
83 /* DirectDraw Flipping behavior doesn't seem that well-defined. The reference rasterizer behaves differently
84 * than hardware implementations. Request single buffering, that seems to work everywhere
86 memset(&ddsd, 0, sizeof(ddsd));
87 ddsd.dwSize = sizeof(ddsd);
88 ddsd.dwFlags = DDSD_CAPS;
89 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE;
90 ddsd.dwBackBufferCount = 1;
91 hr = IDirectDraw7_CreateSurface(DirectDraw, &ddsd, &Surface, NULL);
92 ok(hr==DD_OK, "CreateSurface returned: %08x\n", hr);
93 if(!Surface) goto err;
95 hr = IDirect3D7_CreateDevice(Direct3D, &IID_IDirect3DTnLHalDevice, Surface, &Direct3DDevice);
96 if(FAILED(hr))
98 trace("Creating a TnLHal Device failed, trying HAL\n");
99 hr = IDirect3D7_CreateDevice(Direct3D, &IID_IDirect3DHALDevice, Surface, &Direct3DDevice);
100 if(FAILED(hr))
102 trace("Creating a HAL device failed, trying Ref\n");
103 hr = IDirect3D7_CreateDevice(Direct3D, &IID_IDirect3DRefDevice, Surface, &Direct3DDevice);
106 if(!Direct3DDevice) goto err;
107 return TRUE;
109 err:
110 if(DirectDraw) IDirectDraw7_Release(DirectDraw);
111 if(Surface) IDirectDrawSurface7_Release(Surface);
112 if(Direct3D) IDirect3D7_Release(Direct3D);
113 if(Direct3DDevice) IDirect3DDevice7_Release(Direct3DDevice);
114 if(window) DestroyWindow(window);
115 return FALSE;
118 static void releaseObjects(void)
120 IDirect3DDevice7_Release(Direct3DDevice);
121 IDirect3D7_Release(Direct3D);
122 IDirectDrawSurface7_Release(Surface);
123 IDirectDraw7_Release(DirectDraw);
124 DestroyWindow(window);
127 static DWORD getPixelColor(IDirect3DDevice7 *device, UINT x, UINT y)
129 DWORD ret;
130 HRESULT hr;
131 DDSURFACEDESC2 ddsd;
132 RECT rectToLock = {x, y, x+1, y+1};
133 IDirectDrawSurface7 *surf = NULL;
135 /* Some implementations seem to dislike direct locking on the front buffer. Thus copy the front buffer
136 * to an offscreen surface and lock it instead of the front buffer
138 memset(&ddsd, 0, sizeof(ddsd));
139 ddsd.dwSize = sizeof(ddsd);
140 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
141 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
142 ddsd.dwWidth = 640;
143 ddsd.dwHeight = 480;
144 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
145 hr = IDirectDraw7_CreateSurface(DirectDraw, &ddsd, &surf, NULL);
146 ok(hr == DD_OK, "IDirectDraw7_CreateSurface failed with %08x\n", hr);
147 if(!surf)
149 trace("cannot create helper surface\n");
150 return 0xdeadbeef;
153 memset(&ddsd, 0, sizeof(ddsd));
154 ddsd.dwSize = sizeof(ddsd);
155 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
157 hr = IDirectDrawSurface_BltFast(surf, 0, 0, Surface, NULL, 0);
158 ok(hr == DD_OK, "IDirectDrawSurface7_BltFast returned %08x\n", hr);
159 if(FAILED(hr))
161 trace("Cannot blit\n");
162 ret = 0xdeadbee;
163 goto out;
166 hr = IDirectDrawSurface7_Lock(surf, &rectToLock, &ddsd, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
167 if(FAILED(hr))
169 trace("Can't lock the offscreen surface, hr=%08x\n", hr);
170 ret = 0xdeadbeec;
171 goto out;
174 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
175 * really important for these tests
177 ret = ((DWORD *) ddsd.lpSurface)[0] & 0x00ffffff;
178 hr = IDirectDrawSurface7_Unlock(surf, NULL);
179 if(FAILED(hr))
181 trace("Can't unlock the offscreen surface, hr=%08x\n", hr);
184 out:
185 IDirectDrawSurface7_Release(surf);
186 return ret;
189 struct vertex
191 float x, y, z;
192 DWORD diffuse;
195 struct nvertex
197 float x, y, z;
198 float nx, ny, nz;
199 DWORD diffuse;
202 static void lighting_test(IDirect3DDevice7 *device)
204 HRESULT hr;
205 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
206 DWORD nfvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_NORMAL;
207 DWORD color;
209 float mat[16] = { 1.0f, 0.0f, 0.0f, 0.0f,
210 0.0f, 1.0f, 0.0f, 0.0f,
211 0.0f, 0.0f, 1.0f, 0.0f,
212 0.0f, 0.0f, 0.0f, 1.0f };
214 struct vertex unlitquad[] =
216 {-1.0f, -1.0f, 0.1f, 0xffff0000},
217 {-1.0f, 0.0f, 0.1f, 0xffff0000},
218 { 0.0f, 0.0f, 0.1f, 0xffff0000},
219 { 0.0f, -1.0f, 0.1f, 0xffff0000},
221 struct vertex litquad[] =
223 {-1.0f, 0.0f, 0.1f, 0xff00ff00},
224 {-1.0f, 1.0f, 0.1f, 0xff00ff00},
225 { 0.0f, 1.0f, 0.1f, 0xff00ff00},
226 { 0.0f, 0.0f, 0.1f, 0xff00ff00},
228 struct nvertex unlitnquad[] =
230 { 0.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
231 { 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
232 { 1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
233 { 1.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
235 struct nvertex litnquad[] =
237 { 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
238 { 0.0f, 1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
239 { 1.0f, 1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
240 { 1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
242 WORD Indices[] = {0, 1, 2, 2, 3, 0};
244 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
245 ok(hr == D3D_OK, "IDirect3DDevice7_Clear failed with %08x\n", hr);
247 /* Setup some states that may cause issues */
248 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, (D3DMATRIX *) mat);
249 ok(hr == D3D_OK, "IDirect3DDevice7_SetTransform returned %08x\n", hr);
250 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, (D3DMATRIX *)mat);
251 ok(hr == D3D_OK, "IDirect3DDevice7_SetTransform returned %08x\n", hr);
252 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, (D3DMATRIX *) mat);
253 ok(hr == D3D_OK, "IDirect3DDevice7_SetTransform returned %08x\n", hr);
254 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
255 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned %08x\n", hr);
256 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
257 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned %08x\n", hr);
258 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
259 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned %08x\n", hr);
260 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_STENCILENABLE, FALSE);
261 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned %08x\n", hr);
262 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHATESTENABLE, FALSE);
263 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned %08x\n", hr);
264 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
265 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned %08x\n", hr);
266 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
267 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed with %08x\n", hr);
269 hr = IDirect3DDevice7_BeginScene(device);
270 ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed with %08x\n", hr);
271 if(hr == D3D_OK)
273 /* No lights are defined... That means, lit vertices should be entirely black */
274 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
275 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned %08x\n", hr);
276 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, fvf, unlitquad, 4 /* NumVerts */,
277 Indices, 6 /* Indexcount */, 0 /* flags */);
278 ok(hr == D3D_OK, "IDirect3DDevice7_DrawIndexedPrimitiveUP failed with %08x\n", hr);
280 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, TRUE);
281 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned %08x\n", hr);
282 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, fvf, litquad, 4 /* NumVerts */,
283 Indices, 6 /* Indexcount */, 0 /* flags */);
284 ok(hr == D3D_OK, "IDirect3DDevice7_DrawIndexedPrimitiveUP failed with %08x\n", hr);
286 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
287 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned %08x\n", hr);
288 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, unlitnquad, 4 /* NumVerts */,
289 Indices, 6 /* Indexcount */, 0 /* flags */);
290 ok(hr == D3D_OK, "IDirect3DDevice7_DrawIndexedPrimitiveUP failed with %08x\n", hr);
292 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, TRUE);
293 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned %08x\n", hr);
294 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, litnquad, 4 /* NumVerts */,
295 Indices, 6 /* Indexcount */, 0 /* flags */);
296 ok(hr == D3D_OK, "IDirect3DDevice7_DrawIndexedPrimitiveUP failed with %08x\n", hr);
298 IDirect3DDevice7_EndScene(device);
299 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed with %08x\n", hr);
302 color = getPixelColor(device, 160, 360); /* lower left quad - unlit without normals */
303 ok(color == 0x00ff0000, "Unlit quad without normals has color %08x\n", color);
304 color = getPixelColor(device, 160, 120); /* upper left quad - lit without normals */
305 ok(color == 0x00000000, "Lit quad without normals has color %08x\n", color);
306 color = getPixelColor(device, 480, 360); /* lower left quad - unlit width normals */
307 ok(color == 0x000000ff, "Unlit quad width normals has color %08x\n", color);
308 color = getPixelColor(device, 480, 120); /* upper left quad - lit width normals */
309 ok(color == 0x00000000, "Lit quad width normals has color %08x\n", color);
311 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
312 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned %08x\n", hr);
315 static void clear_test(IDirect3DDevice7 *device)
317 /* Tests the correctness of clearing parameters */
318 HRESULT hr;
319 D3DRECT rect[2];
320 D3DRECT rect_negneg;
321 DWORD color;
323 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
324 ok(hr == D3D_OK, "IDirect3DDevice7_Clear failed with %08x\n", hr);
326 /* Positive x, negative y */
327 U1(rect[0]).x1 = 0;
328 U2(rect[0]).y1 = 480;
329 U3(rect[0]).x2 = 320;
330 U4(rect[0]).y2 = 240;
332 /* Positive x, positive y */
333 U1(rect[1]).x1 = 0;
334 U2(rect[1]).y1 = 0;
335 U3(rect[1]).x2 = 320;
336 U4(rect[1]).y2 = 240;
337 /* Clear 2 rectangles with one call. Shows that a positive value is returned, but the negative rectangle
338 * is ignored, the positive is still cleared afterwards
340 hr = IDirect3DDevice7_Clear(device, 2, rect, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
341 ok(hr == D3D_OK, "IDirect3DDevice7_Clear failed with %08x\n", hr);
343 /* negative x, negative y */
344 U1(rect_negneg).x1 = 640;
345 U2(rect_negneg).y1 = 240;
346 U3(rect_negneg).x2 = 320;
347 U4(rect_negneg).y2 = 0;
348 hr = IDirect3DDevice7_Clear(device, 1, &rect_negneg, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
349 ok(hr == D3D_OK, "IDirect3DDevice7_Clear failed with %08x\n", hr);
351 color = getPixelColor(device, 160, 360); /* lower left quad */
352 ok(color == 0x00ffffff, "Clear rectangle 3(pos, neg) has color %08x\n", color);
353 color = getPixelColor(device, 160, 120); /* upper left quad */
354 ok(color == 0x00ff0000, "Clear rectangle 1(pos, pos) has color %08x\n", color);
355 color = getPixelColor(device, 480, 360); /* lower right quad */
356 ok(color == 0x00ffffff, "Clear rectangle 4(NULL) has color %08x\n", color);
357 color = getPixelColor(device, 480, 120); /* upper right quad */
358 ok(color == 0x00ffffff, "Clear rectangle 4(neg, neg) has color %08x\n", color);
361 struct sVertex {
362 float x, y, z;
363 DWORD diffuse;
364 DWORD specular;
367 struct sVertexT {
368 float x, y, z, rhw;
369 DWORD diffuse;
370 DWORD specular;
373 static void fog_test(IDirect3DDevice7 *device)
375 HRESULT hr;
376 DWORD color;
377 float start = 0.0, end = 1.0;
378 D3DDEVICEDESC7 caps;
380 /* Gets full z based fog with linear fog, no fog with specular color */
381 struct sVertex unstransformed_1[] = {
382 {-1, -1, 0.1f, 0xFFFF0000, 0xFF000000 },
383 {-1, 0, 0.1f, 0xFFFF0000, 0xFF000000 },
384 { 0, 0, 0.1f, 0xFFFF0000, 0xFF000000 },
385 { 0, -1, 0.1f, 0xFFFF0000, 0xFF000000 },
387 /* Ok, I am too lazy to deal with transform matrices */
388 struct sVertex unstransformed_2[] = {
389 {-1, 0, 1.0f, 0xFFFF0000, 0xFF000000 },
390 {-1, 1, 1.0f, 0xFFFF0000, 0xFF000000 },
391 { 0, 1, 1.0f, 0xFFFF0000, 0xFF000000 },
392 { 0, 0, 1.0f, 0xFFFF0000, 0xFF000000 },
394 /* Untransformed ones. Give them a different diffuse color to make the test look
395 * nicer. It also makes making sure that they are drawn correctly easier.
397 struct sVertexT transformed_1[] = {
398 {320, 0, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
399 {640, 0, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
400 {640, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
401 {320, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
403 struct sVertexT transformed_2[] = {
404 {320, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
405 {640, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
406 {640, 480, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
407 {320, 480, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
409 WORD Indices[] = {0, 1, 2, 2, 3, 0};
411 memset(&caps, 0, sizeof(caps));
412 hr = IDirect3DDevice7_GetCaps(device, &caps);
413 ok(hr == D3D_OK, "IDirect3DDevice7_GetCaps returned %08x\n", hr);
414 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
415 ok(hr == D3D_OK, "IDirect3DDevice7_Clear returned %08x\n", hr);
417 /* Setup initial states: No lighting, fog on, fog color */
418 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
419 ok(hr == D3D_OK, "Turning off lighting returned %08x\n", hr);
420 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
421 ok(hr == D3D_OK, "Turning on fog calculations returned %08x\n", hr);
422 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0xFF00FF00 /* A nice green */);
423 ok(hr == D3D_OK, "Turning on fog calculations returned %08x\n", hr);
425 /* First test: Both table fog and vertex fog off */
426 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, D3DFOG_NONE);
427 ok(hr == D3D_OK, "Turning off table fog returned %08x\n", hr);
428 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, D3DFOG_NONE);
429 ok(hr == D3D_OK, "Turning off table fog returned %08x\n", hr);
431 /* Start = 0, end = 1. Should be default, but set them */
432 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGSTART, *((DWORD *) &start));
433 ok(hr == D3D_OK, "Setting fog start returned %08x\n", hr);
434 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGEND, *((DWORD *) &end));
435 ok(hr == D3D_OK, "Setting fog start returned %08x\n", hr);
437 if(IDirect3DDevice7_BeginScene(device) == D3D_OK)
439 /* Untransformed, vertex fog = NONE, table fog = NONE: Read the fog weighting from the specular color */
440 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR,
441 unstransformed_1, 4, Indices, 6, 0);
442 ok(hr == D3D_OK, "DrawIndexedPrimitive returned %08x\n", hr);
444 /* That makes it use the Z value */
445 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, D3DFOG_LINEAR);
446 ok(hr == D3D_OK, "Turning off table fog returned %08x\n", hr);
447 /* Untransformed, vertex fog != none (or table fog != none):
448 * Use the Z value as input into the equation
450 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR,
451 unstransformed_2, 4, Indices, 6, 0);
452 ok(hr == D3D_OK, "DrawIndexedPrimitive returned %08x\n", hr);
454 /* transformed verts */
455 ok( hr == D3D_OK, "SetFVF returned %08x\n", hr);
456 /* Transformed, vertex fog != NONE, pixel fog == NONE: Use specular color alpha component */
457 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR,
458 transformed_1, 4, Indices, 6, 0);
459 ok(hr == D3D_OK, "DrawIndexedPrimitive returned %08x\n", hr);
461 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, D3DFOG_LINEAR);
462 ok( hr == D3D_OK, "Setting fog table mode to D3DFOG_LINEAR returned %08x\n", hr);
463 /* Transformed, table fog != none, vertex anything: Use Z value as input to the fog
464 * equation
466 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR,
467 transformed_2, 4, Indices, 6, 0);
468 ok(hr == D3D_OK, "DrawIndexedPrimitive returned %08x\n", hr);
470 hr = IDirect3DDevice7_EndScene(device);
471 ok(hr == D3D_OK, "EndScene returned %08x\n", hr);
473 else
475 ok(FALSE, "BeginScene failed\n");
478 color = getPixelColor(device, 160, 360);
479 ok(color == 0x00FF0000, "Untransformed vertex with no table or vertex fog has color %08x\n", color);
480 color = getPixelColor(device, 160, 120);
481 ok(color == 0x0000FF00, "Untransformed vertex with linear vertex fog has color %08x\n", color);
482 color = getPixelColor(device, 480, 120);
483 ok(color == 0x00FFFF00, "Transformed vertex with linear vertex fog has color %08x\n", color);
484 if(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE)
486 color = getPixelColor(device, 480, 360);
487 ok(color == 0x0000FF00, "Transformed vertex with linear table fog has color %08x\n", color);
489 else
491 /* Without fog table support the vertex fog is still applied, even though table fog is turned on.
492 * The settings above result in no fogging with vertex fog
494 color = getPixelColor(device, 480, 120);
495 ok(color == 0x00FFFF00, "Transformed vertex with linear vertex fog has color %08x\n", color);
496 trace("Info: Table fog not supported by this device\n");
499 /* Turn off the fog master switch to avoid confusing other tests */
500 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
501 ok(hr == D3D_OK, "Turning off fog calculations returned %08x\n", hr);
504 static void offscreen_test(IDirect3DDevice7 *device)
506 HRESULT hr;
507 IDirectDrawSurface7 *backbuffer = NULL, *offscreen = NULL;
508 DWORD color;
509 DDSURFACEDESC2 ddsd;
511 static const float quad[][5] = {
512 {-0.5f, -0.5f, 0.1f, 0.0f, 0.0f},
513 {-0.5f, 0.5f, 0.1f, 0.0f, 1.0f},
514 { 0.5f, -0.5f, 0.1f, 1.0f, 0.0f},
515 { 0.5f, 0.5f, 0.1f, 1.0f, 1.0f},
518 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
519 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
521 memset(&ddsd, 0, sizeof(ddsd));
522 ddsd.dwSize = sizeof(ddsd);
523 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
524 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
525 ddsd.dwWidth = 128;
526 ddsd.dwHeight = 128;
527 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_3DDEVICE;
528 hr = IDirectDraw7_CreateSurface(DirectDraw, &ddsd, &offscreen, NULL);
529 ok(hr == D3D_OK, "Creating the offscreen render target failed, hr = %08x\n", hr);
530 if(!offscreen) {
531 goto out;
534 hr = IDirect3DDevice7_GetRenderTarget(device, &backbuffer);
535 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
536 if(!backbuffer) {
537 goto out;
540 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
541 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
542 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
543 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
544 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_MINFILTER, D3DFILTER_NEAREST);
545 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MINFILTER failed (0x%08x)\n", hr);
546 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_MAGFILTER, D3DFILTER_NEAREST);
547 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr);
548 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
549 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState returned hr = %08x\n", hr);
551 if(IDirect3DDevice7_BeginScene(device) == D3D_OK) {
552 hr = IDirect3DDevice7_SetRenderTarget(device, offscreen, 0);
553 ok(hr == D3D_OK, "SetRenderTarget failed, hr = %08x\n", hr);
554 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
555 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
557 /* Draw without textures - Should result in a white quad */
558 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEX1, quad, 4, 0);
559 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
561 hr = IDirect3DDevice7_SetRenderTarget(device, backbuffer, 0);
562 ok(hr == D3D_OK, "SetRenderTarget failed, hr = %08x\n", hr);
563 hr = IDirect3DDevice7_SetTexture(device, 0, offscreen);
564 ok(hr == D3D_OK, "SetTexture failed, %08x\n", hr);
566 /* This time with the texture */
567 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEX1, quad, 4, 0);
568 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
570 IDirect3DDevice7_EndScene(device);
573 /* Center quad - should be white */
574 color = getPixelColor(device, 320, 240);
575 ok(color == 0x00ffffff, "Offscreen failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
576 /* Some quad in the cleared part of the texture */
577 color = getPixelColor(device, 170, 240);
578 ok(color == 0x00ff00ff, "Offscreen failed: Got color 0x%08x, expected 0x00ff00ff.\n", color);
579 /* Part of the originally cleared back buffer */
580 color = getPixelColor(device, 10, 10);
581 ok(color == 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
582 if(0) {
583 /* Lower left corner of the screen, where back buffer offscreen rendering draws the offscreen texture.
584 * It should be red, but the offscreen texture may leave some junk there. Not tested yet. Depending on
585 * the offscreen rendering mode this test would succeed or fail
587 color = getPixelColor(device, 10, 470);
588 ok(color == 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
591 out:
592 hr = IDirect3DDevice7_SetTexture(device, 0, NULL);
594 /* restore things */
595 if(backbuffer) {
596 hr = IDirect3DDevice7_SetRenderTarget(device, backbuffer, 0);
597 IDirectDrawSurface7_Release(backbuffer);
599 if(offscreen) {
600 IDirectDrawSurface7_Release(offscreen);
604 static void alpha_test(IDirect3DDevice7 *device)
606 HRESULT hr;
607 IDirectDrawSurface7 *backbuffer = NULL, *offscreen = NULL;
608 DWORD color, red, green, blue;
609 DDSURFACEDESC2 ddsd;
611 struct vertex quad1[] =
613 {-1.0f, -1.0f, 0.1f, 0x4000ff00},
614 {-1.0f, 0.0f, 0.1f, 0x4000ff00},
615 { 1.0f, -1.0f, 0.1f, 0x4000ff00},
616 { 1.0f, 0.0f, 0.1f, 0x4000ff00},
618 struct vertex quad2[] =
620 {-1.0f, 0.0f, 0.1f, 0xc00000ff},
621 {-1.0f, 1.0f, 0.1f, 0xc00000ff},
622 { 1.0f, 0.0f, 0.1f, 0xc00000ff},
623 { 1.0f, 1.0f, 0.1f, 0xc00000ff},
625 static const float composite_quad[][5] = {
626 { 0.0f, -1.0f, 0.1f, 0.0f, 1.0f},
627 { 0.0f, 1.0f, 0.1f, 0.0f, 0.0f},
628 { 1.0f, -1.0f, 0.1f, 1.0f, 1.0f},
629 { 1.0f, 1.0f, 0.1f, 1.0f, 0.0f},
632 /* Clear the render target with alpha = 0.5 */
633 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x80ff0000, 0.0, 0);
634 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
636 memset(&ddsd, 0, sizeof(ddsd));
637 ddsd.dwSize = sizeof(ddsd);
638 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
639 ddsd.dwWidth = 128;
640 ddsd.dwHeight = 128;
641 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_3DDEVICE;
642 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
643 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
644 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
645 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
646 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
647 U5(U4(ddsd).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
648 hr = IDirectDraw7_CreateSurface(DirectDraw, &ddsd, &offscreen, NULL);
649 ok(hr == D3D_OK, "Creating the offscreen render target failed, hr = %08x\n", hr);
650 if(!offscreen) {
651 goto out;
653 hr = IDirect3DDevice7_GetRenderTarget(device, &backbuffer);
654 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
655 if(!backbuffer) {
656 goto out;
659 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
660 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
661 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
662 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
663 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_MINFILTER, D3DFILTER_NEAREST);
664 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MINFILTER failed (0x%08x)\n", hr);
665 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_MAGFILTER, D3DFILTER_NEAREST);
666 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr);
668 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
669 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
670 if(IDirect3DDevice7_BeginScene(device) == D3D_OK) {
672 /* Draw two quads, one with src alpha blending, one with dest alpha blending. The
673 * SRCALPHA / INVSRCALPHA blend doesn't give any surprises. Colors are blended based on
674 * the input alpha
676 * The DESTALPHA / INVDESTALPHA do not "work" on the regular buffer because there is no alpha.
677 * They give essentially ZERO and ONE blend factors
679 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
680 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
681 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
682 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
683 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad1, 4, 0);
684 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
686 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_DESTALPHA);
687 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
688 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVDESTALPHA);
689 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
690 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad2, 4, 0);
691 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
693 /* Switch to the offscreen buffer, and redo the testing. SRCALPHA and DESTALPHA. The offscreen buffer
694 * has a alpha channel on its own. Clear the offscreen buffer with alpha = 0.5 again, then draw the
695 * quads again. The SRCALPHA/INVSRCALPHA doesn't give any surprises, but the DESTALPHA/INVDESTALPHA
696 * blending works as supposed now - blend factor is 0.5 in both cases, not 0.75 as from the input
697 * vertices
699 hr = IDirect3DDevice7_SetRenderTarget(device, offscreen, 0);
700 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
701 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x80ff0000, 0.0, 0);
702 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
704 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
705 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
706 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
707 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
708 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad1, 4, 0);
709 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
711 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_DESTALPHA);
712 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
713 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVDESTALPHA);
714 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
715 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad2, 4, 0);
716 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
718 hr = IDirect3DDevice7_SetRenderTarget(device, backbuffer, 0);
719 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
721 /* Render the offscreen texture onto the frame buffer to be able to compare it regularly.
722 * Disable alpha blending for the final composition
724 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
725 ok(hr == D3D_OK, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr);
727 hr = IDirect3DDevice7_SetTexture(device, 0, offscreen);
728 ok(hr == D3D_OK, "IDirect3DDevice7_SetTexture failed, hr = %08x\n", hr);
729 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEX1, composite_quad, 4, 0);
730 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
731 hr = IDirect3DDevice7_SetTexture(device, 0, NULL);
732 ok(hr == D3D_OK, "IDirect3DDevice7_SetTexture failed, hr = %08x\n", hr);
734 hr = IDirect3DDevice7_EndScene(device);
735 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed, hr = %08x\n", hr);
738 color = getPixelColor(device, 160, 360);
739 red = (color & 0x00ff0000) >> 16;
740 green = (color & 0x0000ff00) >> 8;
741 blue = (color & 0x000000ff);
742 ok(red >= 0xbe && red <= 0xc0 && green >= 0x39 && green <= 0x41 && blue == 0x00,
743 "SRCALPHA on frame buffer returned color %08x, expected 0x00bf4000\n", color);
745 color = getPixelColor(device, 160, 120);
746 red = (color & 0x00ff0000) >> 16;
747 green = (color & 0x0000ff00) >> 8;
748 blue = (color & 0x000000ff);
749 ok(red == 0x00 && green == 0x00 && blue >= 0xfe && blue <= 0xff ,
750 "DSTALPHA on frame buffer returned color %08x, expected 0x00ff0000\n", color);
752 color = getPixelColor(device, 480, 360);
753 red = (color & 0x00ff0000) >> 16;
754 green = (color & 0x0000ff00) >> 8;
755 blue = (color & 0x000000ff);
756 ok(red >= 0xbe && red <= 0xc0 && green >= 0x39 && green <= 0x41 && blue == 0x00,
757 "SRCALPHA on texture returned color %08x, expected bar\n", color);
759 color = getPixelColor(device, 480, 120);
760 red = (color & 0x00ff0000) >> 16;
761 green = (color & 0x0000ff00) >> 8;
762 blue = (color & 0x000000ff);
763 ok(red >= 0x7e && red <= 0x81 && green == 0x00 && blue >= 0x7e && blue <= 0x81,
764 "DSTALPHA on texture returned color %08x, expected foo\n", color);
766 out:
767 if(offscreen) IDirectDrawSurface7_Release(offscreen);
768 if(backbuffer) IDirectDrawSurface7_Release(backbuffer);
771 static void rhw_zero_test(IDirect3DDevice7 *device)
773 /* Test if it will render a quad correctly when vertex rhw = 0 */
774 HRESULT hr;
775 DWORD color;
777 struct {
778 float x, y, z;
779 float rhw;
780 DWORD diffuse;
781 } quad1[] =
783 {0, 100, 0, 0, 0xffffffff},
784 {0, 0, 0, 0, 0xffffffff},
785 {100, 100, 0, 0, 0xffffffff},
786 {100, 0, 0, 0, 0xffffffff},
789 /* Clear to black */
790 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0, 0.0, 0);
791 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
793 hr = IDirect3DDevice7_BeginScene(device);
794 ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed with %08x\n", hr);
796 if (SUCCEEDED(hr)) {
797 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, quad1, 4, 0);
798 ok(hr == D3D_OK, "DrawPrimitive failed, hr = %08x\n", hr);
800 hr = IDirect3DDevice7_EndScene(device);
801 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed, hr = %08x\n", hr);
804 color = getPixelColor(device, 5, 5);
805 ok(color == 0xffffff, "Got color %08x, expected 00ffffff\n", color);
807 color = getPixelColor(device, 105, 105);
808 ok(color == 0, "Got color %08x, expected 00000000\n", color);
811 static BOOL D3D1_createObjects(void)
813 WNDCLASS wc = {0};
814 HRESULT hr;
815 DDSURFACEDESC ddsd;
816 D3DEXECUTEBUFFERDESC exdesc;
817 D3DVIEWPORT vp_data;
819 /* An IDirect3DDevice cannot be queryInterfaced from an IDirect3DDevice7 on windows */
820 hr = DirectDrawCreate(NULL, &DirectDraw1, NULL);
822 ok(hr==DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreate returned: %x\n", hr);
823 if (FAILED(hr)) {
824 return FALSE;
827 wc.lpfnWndProc = DefWindowProc;
828 wc.lpszClassName = "texturemapblend_test_wc";
829 RegisterClass(&wc);
830 window = CreateWindow("texturemapblend_test_wc", "texturemapblend_test", WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
832 hr = IDirectDraw_SetCooperativeLevel(DirectDraw1, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
833 ok(hr==DD_OK, "SetCooperativeLevel returned: %x\n", hr);
834 if(FAILED(hr)) {
835 return FALSE;
838 hr = IDirectDraw_SetDisplayMode(DirectDraw1, 640, 480, 32);
839 if(FAILED(hr)) {
840 /* 24 bit is fine too */
841 hr = IDirectDraw_SetDisplayMode(DirectDraw1, 640, 480, 24);
843 ok(hr==DD_OK || hr == DDERR_UNSUPPORTED, "SetDisplayMode returned: %x\n", hr);
844 if (FAILED(hr)) {
845 return FALSE;
848 hr = IDirectDraw_QueryInterface(DirectDraw1, &IID_IDirect3D, (void**) &Direct3D1);
849 ok(hr==DD_OK, "QueryInterface returned: %x\n", hr);
850 if (FAILED(hr)) {
851 return FALSE;
854 memset(&ddsd, 0, sizeof(ddsd));
855 ddsd.dwSize = sizeof(ddsd);
856 ddsd.dwFlags = DDSD_CAPS;
857 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE;
858 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &Surface1, NULL);
859 ok(hr==DD_OK, "CreateSurface returned: %x\n", hr);
860 if (FAILED(hr)) {
861 return FALSE;
864 hr = IDirectDrawSurface_QueryInterface(Surface1, &IID_IDirect3DHALDevice, (void **) &Direct3DDevice1);
865 if(FAILED(hr)) {
866 trace("Creating a HAL device failed, trying Ref\n");
867 hr = IDirectDrawSurface_QueryInterface(Surface1, &IID_IDirect3DRefDevice, (void **) &Direct3DDevice1);
869 ok(hr==D3D_OK, "Creating 3D device returned: %x\n", hr);
870 if(FAILED(hr)) {
871 return FALSE;
874 hr = IDirect3D_CreateViewport(Direct3D1, &Viewport, NULL);
875 ok(hr == D3D_OK, "IDirect3D_CreateViewport failed: %08x\n", hr);
876 if (FAILED(hr)) {
877 return FALSE;
880 hr = IDirect3DViewport_Initialize(Viewport, Direct3D1);
881 ok(hr == D3D_OK || hr == DDERR_ALREADYINITIALIZED, "IDirect3DViewport_Initialize returned %08x\n", hr);
882 hr = IDirect3DDevice_AddViewport(Direct3DDevice1, Viewport);
883 ok(hr == D3D_OK, "IDirect3DDevice_AddViewport returned %08x\n", hr);
884 vp_data.dwSize = sizeof(vp_data);
885 vp_data.dwX = 0;
886 vp_data.dwY = 0;
887 vp_data.dwWidth = 640;
888 vp_data.dwHeight = 480;
889 vp_data.dvScaleX = 1;
890 vp_data.dvScaleY = 1;
891 vp_data.dvMaxX = 640;
892 vp_data.dvMaxY = 480;
893 vp_data.dvMinZ = 0;
894 vp_data.dvMaxZ = 1;
895 hr = IDirect3DViewport_SetViewport(Viewport, &vp_data);
896 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
898 memset(&exdesc, 0, sizeof(D3DEXECUTEBUFFERDESC));
899 exdesc.dwSize = sizeof(D3DEXECUTEBUFFERDESC);
900 exdesc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
901 exdesc.dwBufferSize = 512;
902 exdesc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
903 hr = IDirect3DDevice_CreateExecuteBuffer(Direct3DDevice1, &exdesc, &ExecuteBuffer, NULL);
904 ok(hr == D3D_OK, "IDirect3DDevice_CreateExecuteBuffer failed with %08x\n", hr);
905 if (FAILED(hr)) {
906 return FALSE;
909 return TRUE;
912 static void D3D1_releaseObjects(void)
914 if(ExecuteBuffer) IDirect3DExecuteBuffer_Release(ExecuteBuffer);
915 if(Surface1) IDirectDrawSurface_Release(Surface1);
916 if(Viewport) IDirect3DViewport_Release(Viewport);
917 if(Direct3DDevice1) IDirect3DDevice_Release(Direct3DDevice1);
918 if(Direct3D1) IDirect3D_Release(Direct3D1);
919 if(DirectDraw1) IDirectDraw_Release(DirectDraw1);
920 if(window) DestroyWindow(window);
923 static DWORD D3D1_getPixelColor(IDirectDraw *DirectDraw1, IDirectDrawSurface *Surface, UINT x, UINT y)
925 DWORD ret;
926 HRESULT hr;
927 DDSURFACEDESC ddsd;
928 RECT rectToLock = {x, y, x+1, y+1};
929 IDirectDrawSurface *surf = NULL;
931 /* Some implementations seem to dislike direct locking on the front buffer. Thus copy the front buffer
932 * to an offscreen surface and lock it instead of the front buffer
934 memset(&ddsd, 0, sizeof(ddsd));
935 ddsd.dwSize = sizeof(ddsd);
936 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
937 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
938 ddsd.dwWidth = 640;
939 ddsd.dwHeight = 480;
940 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
941 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &surf, NULL);
942 ok(hr == DD_OK, "IDirectDraw_CreateSurface failed with %08x\n", hr);
943 if(!surf)
945 trace("cannot create helper surface\n");
946 return 0xdeadbeef;
949 memset(&ddsd, 0, sizeof(ddsd));
950 ddsd.dwSize = sizeof(ddsd);
951 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
953 hr = IDirectDrawSurface_BltFast(surf, 0, 0, Surface, NULL, 0);
954 ok(hr == DD_OK, "IDirectDrawSurface_BltFast returned %08x\n", hr);
955 if(FAILED(hr))
957 trace("Cannot blit\n");
958 ret = 0xdeadbee;
959 goto out;
962 hr = IDirectDrawSurface_Lock(surf, &rectToLock, &ddsd, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
963 if(FAILED(hr))
965 trace("Can't lock the offscreen surface, hr=%08x\n", hr);
966 ret = 0xdeadbeec;
967 goto out;
970 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
971 * really important for these tests
973 ret = ((DWORD *) ddsd.lpSurface)[0] & 0x00ffffff;
974 hr = IDirectDrawSurface_Unlock(surf, NULL);
975 if(FAILED(hr))
977 trace("Can't unlock the offscreen surface, hr=%08x\n", hr);
980 out:
981 IDirectDrawSurface_Release(surf);
982 return ret;
985 #define EXEBUF_START_RENDER_STATES(count, ptr) do {\
986 ((D3DINSTRUCTION*)(ptr))->bOpcode = D3DOP_STATERENDER;\
987 ((D3DINSTRUCTION*)(ptr))->bSize = sizeof(D3DSTATE);\
988 ((D3DINSTRUCTION*)(ptr))->wCount = count;\
989 ptr = ((D3DINSTRUCTION*)(ptr))+1; } while (0)
991 #define EXEBUF_PUT_RENDER_STATE(state, value, ptr) do {\
992 U1(*((D3DSTATE*)(ptr))).drstRenderStateType = state; \
993 U2(*((D3DSTATE*)(ptr))).dwArg[0] = value; \
994 ptr = ((D3DSTATE*)(ptr))+1; } while (0)
996 #define EXEBUF_PUT_PROCESSVERTICES(nvertices, ptr) do {\
997 ((D3DINSTRUCTION*)(ptr))->bOpcode = D3DOP_PROCESSVERTICES;\
998 ((D3DINSTRUCTION*)(ptr))->bSize = sizeof(D3DPROCESSVERTICES);\
999 ((D3DINSTRUCTION*)(ptr))->wCount = 1;\
1000 ptr = ((D3DINSTRUCTION*)(ptr))+1;\
1001 ((D3DPROCESSVERTICES*)(ptr))->dwFlags = D3DPROCESSVERTICES_COPY;\
1002 ((D3DPROCESSVERTICES*)(ptr))->wStart = 0;\
1003 ((D3DPROCESSVERTICES*)(ptr))->wDest = 0;\
1004 ((D3DPROCESSVERTICES*)(ptr))->dwCount = nvertices;\
1005 ((D3DPROCESSVERTICES*)(ptr))->dwReserved = 0;\
1006 ptr = ((D3DPROCESSVERTICES*)(ptr))+1; } while (0)
1008 #define EXEBUF_END(ptr) do {\
1009 ((D3DINSTRUCTION*)(ptr))->bOpcode = D3DOP_EXIT;\
1010 ((D3DINSTRUCTION*)(ptr))->bSize = 0;\
1011 ((D3DINSTRUCTION*)(ptr))->wCount = 0;\
1012 ptr = ((D3DINSTRUCTION*)(ptr))+1; } while (0)
1014 #define EXEBUF_PUT_QUAD(base_idx, ptr) do {\
1015 ((D3DINSTRUCTION*)(ptr))->bOpcode = D3DOP_TRIANGLE;\
1016 ((D3DINSTRUCTION*)(ptr))->bSize = sizeof(D3DTRIANGLE);\
1017 ((D3DINSTRUCTION*)(ptr))->wCount = 2;\
1018 ptr = ((D3DINSTRUCTION*)(ptr))+1;\
1019 U1(*((D3DTRIANGLE*)(ptr))).v1 = base_idx;\
1020 U2(*((D3DTRIANGLE*)(ptr))).v2 = (base_idx) + 1; \
1021 U3(*((D3DTRIANGLE*)(ptr))).v3 = (base_idx) + 3; \
1022 ((D3DTRIANGLE*)(ptr))->wFlags = 0;\
1023 ptr = ((D3DTRIANGLE*)ptr)+1;\
1024 U1(*((D3DTRIANGLE*)(ptr))).v1 = (base_idx) + 1; \
1025 U2(*((D3DTRIANGLE*)(ptr))).v2 = (base_idx) + 2; \
1026 U3(*((D3DTRIANGLE*)(ptr))).v3 = (base_idx) + 3; \
1027 ((D3DTRIANGLE*)(ptr))->wFlags = 0;\
1028 ptr = ((D3DTRIANGLE*)(ptr))+1;\
1029 } while (0)
1031 HRESULT CALLBACK TextureFormatEnumCallback(LPDDSURFACEDESC lpDDSD, LPVOID lpContext)
1033 if (lpDDSD->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8) {
1034 *(BOOL*)lpContext = TRUE;
1037 return DDENUMRET_OK;
1040 static void D3D1_TextureMapBlendTest(void)
1042 HRESULT hr;
1043 DDSURFACEDESC ddsd;
1044 D3DEXECUTEBUFFERDESC exdesc;
1045 D3DEXECUTEDATA exdata;
1046 DDBLTFX ddbltfx;
1047 RECT rect = { 0, 0, 64, 128 };
1048 DWORD color, red, blue, green;
1049 void *exe_buffer_ptr;
1050 DWORD exe_length;
1051 D3DTEXTUREHANDLE htex;
1052 DDCOLORKEY clrKey;
1053 IDirectDrawSurface *TexSurface = NULL;
1054 IDirect3DTexture *Texture = NULL;
1055 IDirectDrawPalette *Palette = NULL;
1056 PALETTEENTRY table1[256];
1057 BOOL p8_textures_supported = FALSE;
1059 struct {
1060 float x, y, z;
1061 float rhw;
1062 DWORD diffuse;
1063 DWORD specular;
1064 float tu, tv;
1065 } test1_quads[] =
1067 {0.0f, 0.0f, 0.0f, 1.0f, 0xffffffff, 0, 0.0f, 0.0f},
1068 {640.0f, 0.0f, 0.0f, 1.0f, 0xffffffff, 0, 1.0f, 0.0f},
1069 {640.0f, 240.0f, 0.0f, 1.0f, 0xffffffff, 0, 1.0f, 1.0f},
1070 {0.0f, 240.0f, 0.0f, 1.0f, 0xffffffff, 0, 0.0f, 1.0f},
1071 {0.0f, 240.0f, 0.0f, 1.0f, 0x80ffffff, 0, 0.0f, 0.0f},
1072 {640.0f, 240.0f, 0.0f, 1.0f, 0x80ffffff, 0, 1.0f, 0.0f},
1073 {640.0f, 480.0f, 0.0f, 1.0f, 0x80ffffff, 0, 1.0f, 1.0f},
1074 {0.0f, 480.0f, 0.0f, 1.0f, 0x80ffffff, 0, 0.0f, 1.0f}
1075 }, test2_quads[] =
1077 {0.0f, 0.0f, 0.0f, 1.0f, 0x00ff0080, 0, 0.0f, 0.0f},
1078 {640.0f, 0.0f, 0.0f, 1.0f, 0x00ff0080, 0, 1.0f, 0.0f},
1079 {640.0f, 240.0f, 0.0f, 1.0f, 0x00ff0080, 0, 1.0f, 1.0f},
1080 {0.0f, 240.0f, 0.0f, 1.0f, 0x00ff0080, 0, 0.0f, 1.0f},
1081 {0.0f, 240.0f, 0.0f, 1.0f, 0x008000ff, 0, 0.0f, 0.0f},
1082 {640.0f, 240.0f, 0.0f, 1.0f, 0x008000ff, 0, 1.0f, 0.0f},
1083 {640.0f, 480.0f, 0.0f, 1.0f, 0x008000ff, 0, 1.0f, 1.0f},
1084 {0.0f, 480.0f, 0.0f, 1.0f, 0x008000ff, 0, 0.0f, 1.0f}
1087 /* 1) Test alpha with DDPF_ALPHAPIXELS texture - should be taken from texture alpha channel*/
1088 memset (&ddsd, 0, sizeof (ddsd));
1089 ddsd.dwSize = sizeof (ddsd);
1090 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
1091 ddsd.dwHeight = 128;
1092 ddsd.dwWidth = 128;
1093 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1094 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
1095 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
1096 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
1097 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1098 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1099 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x000000ff;
1100 U5(ddsd.ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
1101 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &TexSurface, NULL);
1102 ok(hr==D3D_OK, "CreateSurface returned: %x\n", hr);
1103 if (FAILED(hr)) {
1104 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1105 goto out;
1108 hr = IDirectDrawSurface_QueryInterface(TexSurface, &IID_IDirect3DTexture,
1109 (void *)&Texture);
1110 ok(hr==D3D_OK, "IDirectDrawSurface_QueryInterface returned: %x\n", hr);
1111 if (FAILED(hr)) {
1112 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1113 goto out;
1116 memset(&ddbltfx, 0, sizeof(ddbltfx));
1117 ddbltfx.dwSize = sizeof(ddbltfx);
1118 U5(ddbltfx).dwFillColor = 0;
1119 hr = IDirectDrawSurface_Blt(Surface1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1120 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1122 U5(ddbltfx).dwFillColor = 0xff0000ff;
1123 hr = IDirectDrawSurface_Blt(TexSurface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1124 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1125 U5(ddbltfx).dwFillColor = 0x800000ff;
1126 hr = IDirectDrawSurface_Blt(TexSurface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1127 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1129 memset(&exdesc, 0, sizeof(D3DEXECUTEBUFFERDESC));
1130 exdesc.dwSize = sizeof(D3DEXECUTEBUFFERDESC);
1131 hr = IDirect3DExecuteBuffer_Lock(ExecuteBuffer, &exdesc);
1132 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr);
1133 if (FAILED(hr)) {
1134 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1135 goto out;
1138 memcpy(exdesc.lpData, test1_quads, sizeof(test1_quads));
1140 exe_buffer_ptr = 256 + (char*)exdesc.lpData;
1142 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr);
1144 EXEBUF_START_RENDER_STATES(12, exe_buffer_ptr);
1145 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE, exe_buffer_ptr);
1146 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ZENABLE, FALSE, exe_buffer_ptr);
1147 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_FOGENABLE, FALSE, exe_buffer_ptr);
1148 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_SPECULARENABLE, FALSE, exe_buffer_ptr);
1149 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREMAG, D3DFILTER_NEAREST, exe_buffer_ptr);
1150 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREMIN, D3DFILTER_NEAREST, exe_buffer_ptr);
1151 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_FILLMODE , D3DFILL_SOLID, exe_buffer_ptr);
1152 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA, exe_buffer_ptr);
1153 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA, exe_buffer_ptr);
1154 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE, exe_buffer_ptr);
1155 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATE, exe_buffer_ptr);
1156 hr = IDirect3DTexture_GetHandle(Texture, Direct3DDevice1, &htex);
1157 ok(hr == D3D_OK, "IDirect3DTexture_GetHandle failed with %08x\n", hr);
1158 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE, htex, exe_buffer_ptr);
1160 EXEBUF_PUT_QUAD(0, exe_buffer_ptr);
1161 EXEBUF_PUT_QUAD(4, exe_buffer_ptr);
1163 EXEBUF_END(exe_buffer_ptr);
1165 exe_length = ((char*)exe_buffer_ptr - (char*)exdesc.lpData) - 256;
1167 hr = IDirect3DExecuteBuffer_Unlock(ExecuteBuffer);
1168 if (FAILED(hr)) {
1169 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr);
1172 memset(&exdata, 0, sizeof(D3DEXECUTEDATA));
1173 exdata.dwSize = sizeof(D3DEXECUTEDATA);
1174 exdata.dwVertexCount = 8;
1175 exdata.dwInstructionOffset = 256;
1176 exdata.dwInstructionLength = exe_length;
1177 hr = IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer, &exdata);
1178 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr);
1180 hr = IDirect3DDevice_BeginScene(Direct3DDevice1);
1181 ok(hr == D3D_OK, "IDirect3DDevice3_BeginScene failed with %08x\n", hr);
1183 if (SUCCEEDED(hr)) {
1184 hr = IDirect3DDevice_Execute(Direct3DDevice1, ExecuteBuffer, Viewport, D3DEXECUTE_UNCLIPPED);
1185 ok(hr == D3D_OK, "IDirect3DDevice_Execute failed, hr = %08x\n", hr);
1186 hr = IDirect3DDevice_EndScene(Direct3DDevice1);
1187 ok(hr == D3D_OK, "IDirect3DDevice3_EndScene failed, hr = %08x\n", hr);
1190 color = D3D1_getPixelColor(DirectDraw1, Surface1, 5, 5);
1191 red = (color & 0x00ff0000) >> 16;
1192 green = (color & 0x0000ff00) >> 8;
1193 blue = (color & 0x000000ff);
1194 ok(red == 0 && green == 0 && blue >= 0x7e && blue <= 0x82, "Got color %08x, expected 00000080 or near\n", color);
1196 color = D3D1_getPixelColor(DirectDraw1, Surface1, 400, 5);
1197 red = (color & 0x00ff0000) >> 16;
1198 green = (color & 0x0000ff00) >> 8;
1199 blue = (color & 0x000000ff);
1200 ok(red == 0 && green == 0 && blue == 0xff, "Got color %08x, expected 000000ff or near\n", color);
1202 color = D3D1_getPixelColor(DirectDraw1, Surface1, 5, 245);
1203 red = (color & 0x00ff0000) >> 16;
1204 green = (color & 0x0000ff00) >> 8;
1205 blue = (color & 0x000000ff);
1206 ok(red == 0 && green == 0 && blue >= 0x7e && blue <= 0x82, "Got color %08x, expected 00000080 or near\n", color);
1208 color = D3D1_getPixelColor(DirectDraw1, Surface1, 400, 245);
1209 red = (color & 0x00ff0000) >> 16;
1210 green = (color & 0x0000ff00) >> 8;
1211 blue = (color & 0x000000ff);
1212 ok(red == 0 && green == 0 && blue == 0xff, "Got color %08x, expected 000000ff or near\n", color);
1214 /* 2) Test alpha with texture that has no alpha channel - alpha should be taken from diffuse color */
1215 if(Texture) IDirect3DTexture_Release(Texture);
1216 Texture = NULL;
1217 if(TexSurface) IDirectDrawSurface_Release(TexSurface);
1218 TexSurface = NULL;
1220 memset (&ddsd, 0, sizeof (ddsd));
1221 ddsd.dwSize = sizeof (ddsd);
1222 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
1223 ddsd.dwHeight = 128;
1224 ddsd.dwWidth = 128;
1225 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1226 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
1227 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
1228 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
1229 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1230 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1231 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x000000ff;
1233 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &TexSurface, NULL);
1234 ok(hr==D3D_OK, "CreateSurface returned: %x\n", hr);
1235 if (FAILED(hr)) {
1236 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1237 goto out;
1240 hr = IDirectDrawSurface_QueryInterface(TexSurface, &IID_IDirect3DTexture,
1241 (void *)&Texture);
1242 ok(hr==D3D_OK, "IDirectDrawSurface_QueryInterface returned: %x\n", hr);
1243 if (FAILED(hr)) {
1244 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1245 goto out;
1248 memset(&ddbltfx, 0, sizeof(ddbltfx));
1249 ddbltfx.dwSize = sizeof(ddbltfx);
1250 U5(ddbltfx).dwFillColor = 0;
1251 hr = IDirectDrawSurface_Blt(Surface1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1252 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1254 U5(ddbltfx).dwFillColor = 0xff0000ff;
1255 hr = IDirectDrawSurface_Blt(TexSurface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1256 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1257 U5(ddbltfx).dwFillColor = 0x800000ff;
1258 hr = IDirectDrawSurface_Blt(TexSurface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1259 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1261 memset(&exdesc, 0, sizeof(D3DEXECUTEBUFFERDESC));
1262 exdesc.dwSize = sizeof(D3DEXECUTEBUFFERDESC);
1263 hr = IDirect3DExecuteBuffer_Lock(ExecuteBuffer, &exdesc);
1264 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr);
1265 if (FAILED(hr)) {
1266 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1267 goto out;
1270 memcpy(exdesc.lpData, test1_quads, sizeof(test1_quads));
1272 exe_buffer_ptr = 256 + (char*)exdesc.lpData;
1274 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr);
1276 EXEBUF_START_RENDER_STATES(1, exe_buffer_ptr);
1277 hr = IDirect3DTexture_GetHandle(Texture, Direct3DDevice1, &htex);
1278 ok(hr == D3D_OK, "IDirect3DTexture_GetHandle failed with %08x\n", hr);
1279 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE, htex, exe_buffer_ptr);
1281 EXEBUF_PUT_QUAD(0, exe_buffer_ptr);
1282 EXEBUF_PUT_QUAD(4, exe_buffer_ptr);
1284 EXEBUF_END(exe_buffer_ptr);
1286 exe_length = ((char*)exe_buffer_ptr - (char*)exdesc.lpData) - 256;
1288 hr = IDirect3DExecuteBuffer_Unlock(ExecuteBuffer);
1289 if (FAILED(hr)) {
1290 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr);
1293 memset(&exdata, 0, sizeof(D3DEXECUTEDATA));
1294 exdata.dwSize = sizeof(D3DEXECUTEDATA);
1295 exdata.dwVertexCount = 8;
1296 exdata.dwInstructionOffset = 256;
1297 exdata.dwInstructionLength = exe_length;
1298 hr = IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer, &exdata);
1299 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr);
1301 hr = IDirect3DDevice_BeginScene(Direct3DDevice1);
1302 ok(hr == D3D_OK, "IDirect3DDevice3_BeginScene failed with %08x\n", hr);
1304 if (SUCCEEDED(hr)) {
1305 hr = IDirect3DDevice_Execute(Direct3DDevice1, ExecuteBuffer, Viewport, D3DEXECUTE_UNCLIPPED);
1306 ok(hr == D3D_OK, "IDirect3DDevice_Execute failed, hr = %08x\n", hr);
1307 hr = IDirect3DDevice_EndScene(Direct3DDevice1);
1308 ok(hr == D3D_OK, "IDirect3DDevice3_EndScene failed, hr = %08x\n", hr);
1311 color = D3D1_getPixelColor(DirectDraw1, Surface1, 5, 5);
1312 red = (color & 0x00ff0000) >> 16;
1313 green = (color & 0x0000ff00) >> 8;
1314 blue = (color & 0x000000ff);
1315 ok(red == 0 && green == 0 && blue == 0xff, "Got color %08x, expected 000000ff or near\n", color);
1317 color = D3D1_getPixelColor(DirectDraw1, Surface1, 400, 5);
1318 red = (color & 0x00ff0000) >> 16;
1319 green = (color & 0x0000ff00) >> 8;
1320 blue = (color & 0x000000ff);
1321 ok(red == 0 && green == 0 && blue == 0xff, "Got color %08x, expected 000000ff or near\n", color);
1323 color = D3D1_getPixelColor(DirectDraw1, Surface1, 5, 245);
1324 red = (color & 0x00ff0000) >> 16;
1325 green = (color & 0x0000ff00) >> 8;
1326 blue = (color & 0x000000ff);
1327 ok(red == 0 && green == 0 && blue >= 0x7e && blue <= 0x82, "Got color %08x, expected 00000080 or near\n", color);
1329 color = D3D1_getPixelColor(DirectDraw1, Surface1, 400, 245);
1330 red = (color & 0x00ff0000) >> 16;
1331 green = (color & 0x0000ff00) >> 8;
1332 blue = (color & 0x000000ff);
1333 ok(red == 0 && green == 0 && blue >= 0x7e && blue <= 0x82, "Got color %08x, expected 00000080 or near\n", color);
1335 /* 3) Test RGB - should multiply color components from diffuse color and texture */
1336 if(Texture) IDirect3DTexture_Release(Texture);
1337 Texture = NULL;
1338 if(TexSurface) IDirectDrawSurface_Release(TexSurface);
1339 TexSurface = NULL;
1341 memset (&ddsd, 0, sizeof (ddsd));
1342 ddsd.dwSize = sizeof (ddsd);
1343 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
1344 ddsd.dwHeight = 128;
1345 ddsd.dwWidth = 128;
1346 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1347 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
1348 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
1349 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
1350 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1351 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1352 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x000000ff;
1353 U5(ddsd.ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
1354 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &TexSurface, NULL);
1355 ok(hr==D3D_OK, "CreateSurface returned: %x\n", hr);
1356 if (FAILED(hr)) {
1357 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1358 goto out;
1361 hr = IDirectDrawSurface_QueryInterface(TexSurface, &IID_IDirect3DTexture,
1362 (void *)&Texture);
1363 ok(hr==D3D_OK, "IDirectDrawSurface_QueryInterface returned: %x\n", hr);
1364 if (FAILED(hr)) {
1365 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1366 goto out;
1369 memset(&ddbltfx, 0, sizeof(ddbltfx));
1370 ddbltfx.dwSize = sizeof(ddbltfx);
1371 U5(ddbltfx).dwFillColor = 0;
1372 hr = IDirectDrawSurface_Blt(Surface1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1373 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1375 U5(ddbltfx).dwFillColor = 0x00ffffff;
1376 hr = IDirectDrawSurface_Blt(TexSurface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1377 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1378 U5(ddbltfx).dwFillColor = 0x00ffff80;
1379 hr = IDirectDrawSurface_Blt(TexSurface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1380 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1382 memset(&exdesc, 0, sizeof(D3DEXECUTEBUFFERDESC));
1383 exdesc.dwSize = sizeof(D3DEXECUTEBUFFERDESC);
1384 hr = IDirect3DExecuteBuffer_Lock(ExecuteBuffer, &exdesc);
1385 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr);
1386 if (FAILED(hr)) {
1387 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1388 goto out;
1391 memcpy(exdesc.lpData, test2_quads, sizeof(test2_quads));
1393 exe_buffer_ptr = 256 + (char*)exdesc.lpData;
1395 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr);
1397 EXEBUF_START_RENDER_STATES(2, exe_buffer_ptr);
1398 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE, exe_buffer_ptr);
1399 hr = IDirect3DTexture_GetHandle(Texture, Direct3DDevice1, &htex);
1400 ok(hr == D3D_OK, "IDirect3DTexture_GetHandle failed with %08x\n", hr);
1401 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE, htex, exe_buffer_ptr);
1403 EXEBUF_PUT_QUAD(0, exe_buffer_ptr);
1404 EXEBUF_PUT_QUAD(4, exe_buffer_ptr);
1406 EXEBUF_END(exe_buffer_ptr);
1408 exe_length = ((char*)exe_buffer_ptr - (char*)exdesc.lpData) - 256;
1410 hr = IDirect3DExecuteBuffer_Unlock(ExecuteBuffer);
1411 if (FAILED(hr)) {
1412 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr);
1415 memset(&exdata, 0, sizeof(D3DEXECUTEDATA));
1416 exdata.dwSize = sizeof(D3DEXECUTEDATA);
1417 exdata.dwVertexCount = 8;
1418 exdata.dwInstructionOffset = 256;
1419 exdata.dwInstructionLength = exe_length;
1420 hr = IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer, &exdata);
1421 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr);
1423 hr = IDirect3DDevice_BeginScene(Direct3DDevice1);
1424 ok(hr == D3D_OK, "IDirect3DDevice3_BeginScene failed with %08x\n", hr);
1426 if (SUCCEEDED(hr)) {
1427 hr = IDirect3DDevice_Execute(Direct3DDevice1, ExecuteBuffer, Viewport, D3DEXECUTE_UNCLIPPED);
1428 ok(hr == D3D_OK, "IDirect3DDevice_Execute failed, hr = %08x\n", hr);
1429 hr = IDirect3DDevice_EndScene(Direct3DDevice1);
1430 ok(hr == D3D_OK, "IDirect3DDevice3_EndScene failed, hr = %08x\n", hr);
1433 color = D3D1_getPixelColor(DirectDraw1, Surface1, 5, 5);
1434 red = (color & 0x00ff0000) >> 16;
1435 green = (color & 0x0000ff00) >> 8;
1436 blue = (color & 0x000000ff);
1437 ok(red == 0xff && green == 0 && blue >= 0x3e && blue <= 0x42, "Got color %08x, expected 00ff0040 or near\n", color);
1439 color = D3D1_getPixelColor(DirectDraw1, Surface1, 400, 5);
1440 red = (color & 0x00ff0000) >> 16;
1441 green = (color & 0x0000ff00) >> 8;
1442 blue = (color & 0x000000ff);
1443 ok(red == 0xff && green == 0 && blue == 0x80, "Got color %08x, expected 00ff0080 or near\n", color);
1445 color = D3D1_getPixelColor(DirectDraw1, Surface1, 5, 245);
1446 red = (color & 0x00ff0000) >> 16;
1447 green = (color & 0x0000ff00) >> 8;
1448 blue = (color & 0x000000ff);
1449 ok(red >= 0x7e && red <= 0x82 && green == 0 && blue == 0x80, "Got color %08x, expected 00800080 or near\n", color);
1451 color = D3D1_getPixelColor(DirectDraw1, Surface1, 400, 245);
1452 red = (color & 0x00ff0000) >> 16;
1453 green = (color & 0x0000ff00) >> 8;
1454 blue = (color & 0x000000ff);
1455 ok(red >= 0x7e && red <= 0x82 && green == 0 && blue == 0xff, "Got color %08x, expected 008000ff or near\n", color);
1457 /* 4) Test alpha again, now with color keyed texture (colorkey emulation in wine can interfere) */
1458 if(Texture) IDirect3DTexture_Release(Texture);
1459 Texture = NULL;
1460 if(TexSurface) IDirectDrawSurface_Release(TexSurface);
1461 TexSurface = NULL;
1463 memset (&ddsd, 0, sizeof (ddsd));
1464 ddsd.dwSize = sizeof (ddsd);
1465 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
1466 ddsd.dwHeight = 128;
1467 ddsd.dwWidth = 128;
1468 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1469 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
1470 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
1471 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 16;
1472 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xf800;
1473 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x07e0;
1474 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x001f;
1476 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &TexSurface, NULL);
1477 ok(hr==D3D_OK, "CreateSurface returned: %x\n", hr);
1478 if (FAILED(hr)) {
1479 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1480 goto out;
1483 hr = IDirectDrawSurface_QueryInterface(TexSurface, &IID_IDirect3DTexture,
1484 (void *)&Texture);
1485 ok(hr==D3D_OK, "IDirectDrawSurface_QueryInterface returned: %x\n", hr);
1486 if (FAILED(hr)) {
1487 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1488 goto out;
1491 memset(&ddbltfx, 0, sizeof(ddbltfx));
1492 ddbltfx.dwSize = sizeof(ddbltfx);
1493 U5(ddbltfx).dwFillColor = 0;
1494 hr = IDirectDrawSurface_Blt(Surface1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1495 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1496 U5(ddbltfx).dwFillColor = 0xf800;
1497 hr = IDirectDrawSurface_Blt(TexSurface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1498 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1499 U5(ddbltfx).dwFillColor = 0x001f;
1500 hr = IDirectDrawSurface_Blt(TexSurface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1501 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1503 clrKey.dwColorSpaceLowValue = 0x001f;
1504 clrKey.dwColorSpaceHighValue = 0x001f;
1505 hr = IDirectDrawSurface_SetColorKey(TexSurface, DDCKEY_SRCBLT, &clrKey);
1506 ok(hr==D3D_OK, "IDirectDrawSurfac_SetColorKey returned: %x\n", hr);
1508 memset(&exdesc, 0, sizeof(D3DEXECUTEBUFFERDESC));
1509 exdesc.dwSize = sizeof(D3DEXECUTEBUFFERDESC);
1510 hr = IDirect3DExecuteBuffer_Lock(ExecuteBuffer, &exdesc);
1511 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr);
1512 if (FAILED(hr)) {
1513 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1514 goto out;
1517 memcpy(exdesc.lpData, test1_quads, sizeof(test1_quads));
1519 exe_buffer_ptr = 256 + (char*)exdesc.lpData;
1521 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr);
1523 EXEBUF_START_RENDER_STATES(2, exe_buffer_ptr);
1524 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE, exe_buffer_ptr);
1525 hr = IDirect3DTexture_GetHandle(Texture, Direct3DDevice1, &htex);
1526 ok(hr == D3D_OK, "IDirect3DTexture_GetHandle failed with %08x\n", hr);
1527 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE, htex, exe_buffer_ptr);
1529 EXEBUF_PUT_QUAD(0, exe_buffer_ptr);
1530 EXEBUF_PUT_QUAD(4, exe_buffer_ptr);
1532 EXEBUF_END(exe_buffer_ptr);
1534 exe_length = ((char*)exe_buffer_ptr - (char*)exdesc.lpData) - 256;
1536 hr = IDirect3DExecuteBuffer_Unlock(ExecuteBuffer);
1537 if (FAILED(hr)) {
1538 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr);
1541 memset(&exdata, 0, sizeof(D3DEXECUTEDATA));
1542 exdata.dwSize = sizeof(D3DEXECUTEDATA);
1543 exdata.dwVertexCount = 8;
1544 exdata.dwInstructionOffset = 256;
1545 exdata.dwInstructionLength = exe_length;
1546 hr = IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer, &exdata);
1547 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr);
1549 hr = IDirect3DDevice_BeginScene(Direct3DDevice1);
1550 ok(hr == D3D_OK, "IDirect3DDevice3_BeginScene failed with %08x\n", hr);
1552 if (SUCCEEDED(hr)) {
1553 hr = IDirect3DDevice_Execute(Direct3DDevice1, ExecuteBuffer, Viewport, D3DEXECUTE_UNCLIPPED);
1554 ok(hr == D3D_OK, "IDirect3DDevice_Execute failed, hr = %08x\n", hr);
1555 hr = IDirect3DDevice_EndScene(Direct3DDevice1);
1556 ok(hr == D3D_OK, "IDirect3DDevice3_EndScene failed, hr = %08x\n", hr);
1559 color = D3D1_getPixelColor(DirectDraw1, Surface1, 5, 5);
1560 ok(color == 0, "Got color %08x, expected 00000000\n", color);
1562 color = D3D1_getPixelColor(DirectDraw1, Surface1, 400, 5);
1563 red = (color & 0x00ff0000) >> 16;
1564 green = (color & 0x0000ff00) >> 8;
1565 blue = (color & 0x000000ff);
1566 ok(red == 0xff && green == 0 && blue == 0, "Got color %08x, expected 00ff0000 or near\n", color);
1568 color = D3D1_getPixelColor(DirectDraw1, Surface1, 5, 245);
1569 ok(color == 0, "Got color %08x, expected 00000000\n", color);
1571 color = D3D1_getPixelColor(DirectDraw1, Surface1, 400, 245);
1572 red = (color & 0x00ff0000) >> 16;
1573 green = (color & 0x0000ff00) >> 8;
1574 blue = (color & 0x000000ff);
1575 ok(red >= 0x7e && red <= 0x82 && green == 0 && blue == 0, "Got color %08x, expected 00800000 or near\n", color);
1577 /* 5) Test alpha again, now with color keyed P8 texture */
1578 if(Texture) IDirect3DTexture_Release(Texture);
1579 Texture = NULL;
1580 if(TexSurface) IDirectDrawSurface_Release(TexSurface);
1581 TexSurface = NULL;
1583 hr = IDirect3DDevice_EnumTextureFormats(Direct3DDevice1, TextureFormatEnumCallback,
1584 &p8_textures_supported);
1585 ok(hr == DD_OK, "IDirect3DDevice_EnumTextureFormats returned %08x\n", hr);
1587 if (!p8_textures_supported) {
1588 skip("device has no P8 texture support, skipping test\n");
1589 } else {
1590 memset (&ddsd, 0, sizeof (ddsd));
1591 ddsd.dwSize = sizeof (ddsd);
1592 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
1593 ddsd.dwHeight = 128;
1594 ddsd.dwWidth = 128;
1595 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1596 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
1597 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED8;
1598 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 8;
1600 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &TexSurface, NULL);
1601 ok(hr==D3D_OK, "CreateSurface returned: %x\n", hr);
1602 if (FAILED(hr)) {
1603 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1604 goto out;
1607 memset(table1, 0, sizeof(table1));
1608 table1[0].peBlue = 0xff;
1609 table1[1].peRed = 0xff;
1611 hr = IDirectDraw_CreatePalette(DirectDraw1, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, table1, &Palette, NULL);
1612 ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
1613 if (FAILED(hr)) {
1614 skip("IDirectDraw_CreatePalette failed; skipping further tests\n");
1615 goto out;
1618 hr = IDirectDrawSurface_SetPalette(TexSurface, Palette);
1619 ok(hr==D3D_OK, "IDirectDrawSurface_SetPalette returned: %x\n", hr);
1621 hr = IDirectDrawSurface_QueryInterface(TexSurface, &IID_IDirect3DTexture,
1622 (void *)&Texture);
1623 ok(hr==D3D_OK, "IDirectDrawSurface_QueryInterface returned: %x\n", hr);
1624 if (FAILED(hr)) {
1625 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1626 goto out;
1629 memset(&ddbltfx, 0, sizeof(ddbltfx));
1630 ddbltfx.dwSize = sizeof(ddbltfx);
1631 U5(ddbltfx).dwFillColor = 0;
1632 hr = IDirectDrawSurface_Blt(Surface1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1633 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1634 U5(ddbltfx).dwFillColor = 0;
1635 hr = IDirectDrawSurface_Blt(TexSurface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1636 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1637 U5(ddbltfx).dwFillColor = 1;
1638 hr = IDirectDrawSurface_Blt(TexSurface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
1639 ok(hr == D3D_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
1641 clrKey.dwColorSpaceLowValue = 1;
1642 clrKey.dwColorSpaceHighValue = 1;
1643 hr = IDirectDrawSurface_SetColorKey(TexSurface, DDCKEY_SRCBLT, &clrKey);
1644 ok(hr==D3D_OK, "IDirectDrawSurfac_SetColorKey returned: %x\n", hr);
1646 memset(&exdesc, 0, sizeof(D3DEXECUTEBUFFERDESC));
1647 exdesc.dwSize = sizeof(D3DEXECUTEBUFFERDESC);
1648 hr = IDirect3DExecuteBuffer_Lock(ExecuteBuffer, &exdesc);
1649 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr);
1650 if (FAILED(hr)) {
1651 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1652 goto out;
1655 memcpy(exdesc.lpData, test1_quads, sizeof(test1_quads));
1657 exe_buffer_ptr = 256 + (char*)exdesc.lpData;
1659 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr);
1661 EXEBUF_START_RENDER_STATES(2, exe_buffer_ptr);
1662 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE, exe_buffer_ptr);
1663 hr = IDirect3DTexture_GetHandle(Texture, Direct3DDevice1, &htex);
1664 ok(hr == D3D_OK, "IDirect3DTexture_GetHandle failed with %08x\n", hr);
1665 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE, htex, exe_buffer_ptr);
1667 EXEBUF_PUT_QUAD(0, exe_buffer_ptr);
1668 EXEBUF_PUT_QUAD(4, exe_buffer_ptr);
1670 EXEBUF_END(exe_buffer_ptr);
1672 exe_length = ((char*)exe_buffer_ptr - (char*)exdesc.lpData) - 256;
1674 hr = IDirect3DExecuteBuffer_Unlock(ExecuteBuffer);
1675 if (FAILED(hr)) {
1676 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr);
1679 memset(&exdata, 0, sizeof(D3DEXECUTEDATA));
1680 exdata.dwSize = sizeof(D3DEXECUTEDATA);
1681 exdata.dwVertexCount = 8;
1682 exdata.dwInstructionOffset = 256;
1683 exdata.dwInstructionLength = exe_length;
1684 hr = IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer, &exdata);
1685 ok(hr == D3D_OK, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr);
1687 hr = IDirect3DDevice_BeginScene(Direct3DDevice1);
1688 ok(hr == D3D_OK, "IDirect3DDevice3_BeginScene failed with %08x\n", hr);
1690 if (SUCCEEDED(hr)) {
1691 hr = IDirect3DDevice_Execute(Direct3DDevice1, ExecuteBuffer, Viewport, D3DEXECUTE_UNCLIPPED);
1692 ok(hr == D3D_OK, "IDirect3DDevice_Execute failed, hr = %08x\n", hr);
1693 hr = IDirect3DDevice_EndScene(Direct3DDevice1);
1694 ok(hr == D3D_OK, "IDirect3DDevice3_EndScene failed, hr = %08x\n", hr);
1697 color = D3D1_getPixelColor(DirectDraw1, Surface1, 5, 5);
1698 ok(color == 0, "Got color %08x, expected 00000000\n", color);
1700 color = D3D1_getPixelColor(DirectDraw1, Surface1, 400, 5);
1701 red = (color & 0x00ff0000) >> 16;
1702 green = (color & 0x0000ff00) >> 8;
1703 blue = (color & 0x000000ff);
1704 ok(red == 0 && green == 0 && blue == 0xff, "Got color %08x, expected 000000ff or near\n", color);
1706 color = D3D1_getPixelColor(DirectDraw1, Surface1, 5, 245);
1707 ok(color == 0, "Got color %08x, expected 00000000\n", color);
1709 color = D3D1_getPixelColor(DirectDraw1, Surface1, 400, 245);
1710 red = (color & 0x00ff0000) >> 16;
1711 green = (color & 0x0000ff00) >> 8;
1712 blue = (color & 0x000000ff);
1713 ok(red == 0 && green == 0 && blue >= 0x7e && blue <= 0x82, "Got color %08x, expected 00000080 or near\n", color);
1716 out:
1718 if (Palette) IDirectDrawPalette_Release(Palette);
1719 if (TexSurface) IDirectDrawSurface_Release(TexSurface);
1720 if (Texture) IDirect3DTexture_Release(Texture);
1723 static void D3D1_ViewportClearTest(void)
1725 HRESULT hr;
1726 IDirect3DMaterial *bgMaterial = NULL;
1727 D3DMATERIAL mat;
1728 D3DMATERIALHANDLE hMat;
1729 D3DVIEWPORT vp_data;
1730 IDirect3DViewport *Viewport2 = NULL;
1731 DWORD color, red, green, blue;
1733 hr = IDirect3D_CreateMaterial(Direct3D1, &bgMaterial, NULL);
1734 ok(hr == D3D_OK, "IDirect3D_CreateMaterial failed: %08x\n", hr);
1735 if (FAILED(hr)) {
1736 goto out;
1739 hr = IDirect3D_CreateViewport(Direct3D1, &Viewport2, NULL);
1740 ok(hr == D3D_OK, "IDirect3D_CreateViewport failed: %08x\n", hr);
1741 if (FAILED(hr)) {
1742 goto out;
1745 hr = IDirect3DViewport_Initialize(Viewport2, Direct3D1);
1746 ok(hr == D3D_OK || hr == DDERR_ALREADYINITIALIZED, "IDirect3DViewport_Initialize returned %08x\n", hr);
1747 hr = IDirect3DDevice_AddViewport(Direct3DDevice1, Viewport2);
1748 ok(hr == D3D_OK, "IDirect3DDevice_AddViewport returned %08x\n", hr);
1749 vp_data.dwSize = sizeof(vp_data);
1750 vp_data.dwX = 200;
1751 vp_data.dwY = 200;
1752 vp_data.dwWidth = 100;
1753 vp_data.dwHeight = 100;
1754 vp_data.dvScaleX = 1;
1755 vp_data.dvScaleY = 1;
1756 vp_data.dvMaxX = 100;
1757 vp_data.dvMaxY = 100;
1758 vp_data.dvMinZ = 0;
1759 vp_data.dvMaxZ = 1;
1760 hr = IDirect3DViewport_SetViewport(Viewport2, &vp_data);
1761 ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1763 memset(&mat, 0, sizeof(mat));
1764 mat.dwSize = sizeof(mat);
1765 U1(U(mat).diffuse).r = 1.0f;
1766 hr = IDirect3DMaterial_SetMaterial(bgMaterial, &mat);
1767 ok(hr == D3D_OK, "IDirect3DMaterial_SetMaterial failed: %08x\n", hr);
1769 hr = IDirect3DMaterial_GetHandle(bgMaterial, Direct3DDevice1, &hMat);
1770 ok(hr == D3D_OK, "IDirect3DMaterial_GetHandle failed: %08x\n", hr);
1772 hr = IDirect3DViewport_SetBackground(Viewport, hMat);
1773 ok(hr == D3D_OK, "IDirect3DViewport_SetBackground failed: %08x\n", hr);
1774 hr = IDirect3DViewport_SetBackground(Viewport2, hMat);
1775 ok(hr == D3D_OK, "IDirect3DViewport_SetBackground failed: %08x\n", hr);
1777 hr = IDirect3DDevice_BeginScene(Direct3DDevice1);
1778 ok(hr == D3D_OK, "IDirect3DDevice3_BeginScene failed with %08x\n", hr);
1780 if (SUCCEEDED(hr)) {
1781 D3DRECT rect;
1783 U1(rect).x1 = U2(rect).y1 = 0;
1784 U3(rect).x2 = 640;
1785 U4(rect).y2 = 480;
1787 hr = IDirect3DViewport_Clear(Viewport, 1, &rect, D3DCLEAR_TARGET);
1788 ok(hr == D3D_OK, "IDirect3DViewport_Clear failed: %08x\n", hr);
1790 memset(&mat, 0, sizeof(mat));
1791 mat.dwSize = sizeof(mat);
1792 U3(U(mat).diffuse).b = 1.0f;
1793 hr = IDirect3DMaterial_SetMaterial(bgMaterial, &mat);
1794 ok(hr == D3D_OK, "IDirect3DMaterial_SetMaterial failed: %08x\n", hr);
1796 hr = IDirect3DViewport_Clear(Viewport2, 1, &rect, D3DCLEAR_TARGET);
1797 ok(hr == D3D_OK, "IDirect3DViewport_Clear failed: %08x\n", hr);
1799 hr = IDirect3DDevice_EndScene(Direct3DDevice1);
1800 ok(hr == D3D_OK, "IDirect3DDevice3_EndScene failed, hr = %08x\n", hr);
1803 color = D3D1_getPixelColor(DirectDraw1, Surface1, 5, 5);
1804 red = (color & 0x00ff0000) >> 16;
1805 green = (color & 0x0000ff00) >> 8;
1806 blue = (color & 0x000000ff);
1807 ok(red == 0xff && green == 0 && blue == 0, "Got color %08x, expected 00ff0000\n", color);
1809 color = D3D1_getPixelColor(DirectDraw1, Surface1, 205, 205);
1810 red = (color & 0x00ff0000) >> 16;
1811 green = (color & 0x0000ff00) >> 8;
1812 blue = (color & 0x000000ff);
1813 ok(red == 0 && green == 0 && blue == 0xff, "Got color %08x, expected 000000ff\n", color);
1815 out:
1817 if (bgMaterial) IDirect3DMaterial_Release(bgMaterial);
1818 if (Viewport2) IDirect3DViewport_Release(Viewport2);
1821 static DWORD D3D3_getPixelColor(IDirectDraw4 *DirectDraw, IDirectDrawSurface4 *Surface, UINT x, UINT y)
1823 DWORD ret;
1824 HRESULT hr;
1825 DDSURFACEDESC2 ddsd;
1826 RECT rectToLock = {x, y, x+1, y+1};
1827 IDirectDrawSurface4 *surf = NULL;
1829 /* Some implementations seem to dislike direct locking on the front buffer. Thus copy the front buffer
1830 * to an offscreen surface and lock it instead of the front buffer
1832 memset(&ddsd, 0, sizeof(ddsd));
1833 ddsd.dwSize = sizeof(ddsd);
1834 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1835 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
1836 ddsd.dwWidth = 640;
1837 ddsd.dwHeight = 480;
1838 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
1839 hr = IDirectDraw4_CreateSurface(DirectDraw, &ddsd, &surf, NULL);
1840 ok(hr == DD_OK, "IDirectDraw_CreateSurface failed with %08x\n", hr);
1841 if(!surf)
1843 trace("cannot create helper surface\n");
1844 return 0xdeadbeef;
1847 memset(&ddsd, 0, sizeof(ddsd));
1848 ddsd.dwSize = sizeof(ddsd);
1849 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
1851 hr = IDirectDrawSurface4_BltFast(surf, 0, 0, Surface, NULL, 0);
1852 ok(hr == DD_OK, "IDirectDrawSurface_BltFast returned %08x\n", hr);
1853 if(FAILED(hr))
1855 trace("Cannot blit\n");
1856 ret = 0xdeadbee;
1857 goto out;
1860 hr = IDirectDrawSurface4_Lock(surf, &rectToLock, &ddsd, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
1861 if(FAILED(hr))
1863 trace("Can't lock the offscreen surface, hr=%08x\n", hr);
1864 ret = 0xdeadbeec;
1865 goto out;
1868 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
1869 * really important for these tests
1871 ret = ((DWORD *) ddsd.lpSurface)[0] & 0x00ffffff;
1872 hr = IDirectDrawSurface4_Unlock(surf, NULL);
1873 if(FAILED(hr))
1875 trace("Can't unlock the offscreen surface, hr=%08x\n", hr);
1878 out:
1879 IDirectDrawSurface4_Release(surf);
1880 return ret;
1883 static void D3D3_ViewportClearTest(void)
1885 HRESULT hr;
1886 IDirectDraw *DirectDraw1 = NULL;
1887 IDirectDraw4 *DirectDraw4 = NULL;
1888 IDirectDrawSurface4 *Primary = NULL;
1889 IDirect3D3 *Direct3D3 = NULL;
1890 IDirect3DViewport3 *Viewport3 = NULL;
1891 IDirect3DViewport3 *SmallViewport3 = NULL;
1892 IDirect3DDevice3 *Direct3DDevice3 = NULL;
1893 WNDCLASS wc = {0};
1894 DDSURFACEDESC2 ddsd;
1895 D3DVIEWPORT2 vp_data;
1896 DWORD color, red, green, blue;
1897 D3DRECT rect;
1898 float mat[16] = { 1.0f, 0.0f, 0.0f, 0.0f,
1899 0.0f, 1.0f, 0.0f, 0.0f,
1900 0.0f, 0.0f, 1.0f, 0.0f,
1901 0.0f, 0.0f, 0.0f, 1.0f };
1902 struct vertex quad[] =
1904 {-1.0f, -1.0f, 0.1f, 0xffffffff},
1905 {-1.0f, 1.0f, 0.1f, 0xffffffff},
1906 { 1.0f, 1.0f, 0.1f, 0xffffffff},
1907 { 1.0f, -1.0f, 0.1f, 0xffffffff},
1910 WORD Indices[] = {0, 1, 2, 2, 3, 0};
1911 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
1913 wc.lpfnWndProc = DefWindowProc;
1914 wc.lpszClassName = "D3D3_ViewportClearTest_wc";
1915 RegisterClass(&wc);
1916 window = CreateWindow("D3D3_ViewportClearTest_wc", "D3D3_ViewportClearTest",
1917 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
1919 hr = DirectDrawCreate( NULL, &DirectDraw1, NULL );
1920 ok(hr==DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreate returned: %x\n", hr);
1921 if(FAILED(hr)) goto out;
1923 hr = IDirectDraw_SetCooperativeLevel(DirectDraw1, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1924 ok(hr==DD_OK, "SetCooperativeLevel returned: %x\n", hr);
1925 if(FAILED(hr)) goto out;
1927 hr = IDirectDraw_SetDisplayMode(DirectDraw1, 640, 480, 32);
1928 if(FAILED(hr)) {
1929 /* 24 bit is fine too */
1930 hr = IDirectDraw_SetDisplayMode(DirectDraw1, 640, 480, 24);
1932 ok(hr==DD_OK || hr == DDERR_UNSUPPORTED, "SetDisplayMode returned: %x\n", hr);
1933 if (FAILED(hr)) goto out;
1935 hr = IDirectDraw_QueryInterface(DirectDraw1, &IID_IDirectDraw4, (void**)&DirectDraw4);
1936 ok(hr==DD_OK, "QueryInterface returned: %08x\n", hr);
1937 if(FAILED(hr)) goto out;
1939 memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
1940 ddsd.dwSize = sizeof(DDSURFACEDESC2);
1941 ddsd.dwFlags = DDSD_CAPS;
1942 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE;
1944 hr = IDirectDraw_CreateSurface(DirectDraw4, &ddsd, &Primary, NULL);
1945 ok(hr==DD_OK, "IDirectDraw_CreateSurface returned: %08x\n", hr);
1946 if(FAILED(hr)) goto out;
1948 hr = IDirectDraw4_QueryInterface(DirectDraw4, &IID_IDirect3D3, (void**)&Direct3D3);
1949 ok(hr==DD_OK, "IDirectDraw4_QueryInterface returned: %08x\n", hr);
1950 if(FAILED(hr)) goto out;
1952 hr = IDirect3D3_CreateDevice(Direct3D3, &IID_IDirect3DHALDevice, Primary, &Direct3DDevice3, NULL);
1953 if(FAILED(hr)) {
1954 trace("Creating a HAL device failed, trying Ref\n");
1955 hr = IDirect3D3_CreateDevice(Direct3D3, &IID_IDirect3DRefDevice, Primary, &Direct3DDevice3, NULL);
1957 ok(hr==D3D_OK, "Creating 3D device returned: %x\n", hr);
1958 if(FAILED(hr)) goto out;
1960 hr = IDirect3D3_CreateViewport(Direct3D3, &Viewport3, NULL);
1961 ok(hr==DD_OK, "IDirect3D3_CreateViewport returned: %08x\n", hr);
1962 if(FAILED(hr)) goto out;
1964 hr = IDirect3DDevice3_AddViewport(Direct3DDevice3, Viewport3);
1965 ok(hr==DD_OK, "IDirect3DDevice3_AddViewport returned: %08x\n", hr);
1967 memset(&vp_data, 0, sizeof(D3DVIEWPORT2));
1968 vp_data.dwSize = sizeof(D3DVIEWPORT2);
1969 vp_data.dwWidth = 640;
1970 vp_data.dwHeight = 480;
1971 vp_data.dvClipX = -1.0f;
1972 vp_data.dvClipWidth = 2.0f;
1973 vp_data.dvClipY = 1.0f;
1974 vp_data.dvClipHeight = 2.0f;
1975 vp_data.dvMaxZ = 1.0f;
1976 hr = IDirect3DViewport3_SetViewport2(Viewport3, &vp_data);
1977 ok(hr==DD_OK, "IDirect3DViewport3_SetViewport2 returned: %08x\n", hr);
1979 hr = IDirect3D3_CreateViewport(Direct3D3, &SmallViewport3, NULL);
1980 ok(hr==DD_OK, "IDirect3D3_CreateViewport returned: %08x\n", hr);
1981 if(FAILED(hr)) goto out;
1983 hr = IDirect3DDevice3_AddViewport(Direct3DDevice3, SmallViewport3);
1984 ok(hr==DD_OK, "IDirect3DDevice3_AddViewport returned: %08x\n", hr);
1986 memset(&vp_data, 0, sizeof(D3DVIEWPORT2));
1987 vp_data.dwSize = sizeof(D3DVIEWPORT2);
1988 vp_data.dwX = 400;
1989 vp_data.dwY = 100;
1990 vp_data.dwWidth = 100;
1991 vp_data.dwHeight = 100;
1992 vp_data.dvClipX = -1.0f;
1993 vp_data.dvClipWidth = 2.0f;
1994 vp_data.dvClipY = 1.0f;
1995 vp_data.dvClipHeight = 2.0f;
1996 vp_data.dvMaxZ = 1.0f;
1997 hr = IDirect3DViewport3_SetViewport2(SmallViewport3, &vp_data);
1998 ok(hr==DD_OK, "IDirect3DViewport3_SetViewport2 returned: %08x\n", hr);
2000 hr = IDirect3DDevice3_BeginScene(Direct3DDevice3);
2001 ok(hr == D3D_OK, "IDirect3DDevice3_BeginScene failed with %08x\n", hr);
2003 hr = IDirect3DDevice3_SetTransform(Direct3DDevice3, D3DTRANSFORMSTATE_WORLD, (D3DMATRIX *) mat);
2004 ok(hr == D3D_OK, "IDirect3DDevice3_SetTransform returned %08x\n", hr);
2005 hr = IDirect3DDevice3_SetTransform(Direct3DDevice3, D3DTRANSFORMSTATE_VIEW, (D3DMATRIX *)mat);
2006 ok(hr == D3D_OK, "IDirect3DDevice3_SetTransform returned %08x\n", hr);
2007 hr = IDirect3DDevice3_SetTransform(Direct3DDevice3, D3DTRANSFORMSTATE_PROJECTION, (D3DMATRIX *) mat);
2008 ok(hr == D3D_OK, "IDirect3DDevice3_SetTransform returned %08x\n", hr);
2009 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_CLIPPING, FALSE);
2010 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState returned %08x\n", hr);
2011 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_ZENABLE, FALSE);
2012 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState returned %08x\n", hr);
2013 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_FOGENABLE, FALSE);
2014 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState returned %08x\n", hr);
2015 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_STENCILENABLE, FALSE);
2016 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState returned %08x\n", hr);
2017 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_ALPHATESTENABLE, FALSE);
2018 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState returned %08x\n", hr);
2019 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
2020 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState returned %08x\n", hr);
2021 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
2022 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState failed with %08x\n", hr);
2023 hr = IDirect3DDevice3_SetRenderState(Direct3DDevice3, D3DRENDERSTATE_LIGHTING, FALSE);
2024 ok(hr == D3D_OK, "IDirect3DDevice3_SetRenderState returned %08x\n", hr);
2026 if (SUCCEEDED(hr)) {
2027 U1(rect).x1 = U2(rect).y1 = 0;
2028 U3(rect).x2 = 640;
2029 U4(rect).y2 = 480;
2031 hr = IDirect3DViewport3_Clear2(Viewport3, 1, &rect, D3DCLEAR_TARGET, 0x00ff00, 0.0f, 0);
2032 ok(hr == D3D_OK, "IDirect3DViewport3_Clear2 failed, hr = %08x\n", hr);
2034 hr = IDirect3DViewport3_Clear2(SmallViewport3, 1, &rect, D3DCLEAR_TARGET, 0xff0000, 0.0f, 0);
2035 ok(hr == D3D_OK, "IDirect3DViewport3_Clear2 failed, hr = %08x\n", hr);
2037 hr = IDirect3DDevice3_EndScene(Direct3DDevice3);
2038 ok(hr == D3D_OK, "IDirect3DDevice3_EndScene failed, hr = %08x\n", hr);
2041 color = D3D3_getPixelColor(DirectDraw4, Primary, 5, 5);
2042 red = (color & 0x00ff0000) >> 16;
2043 green = (color & 0x0000ff00) >> 8;
2044 blue = (color & 0x000000ff);
2045 ok(red == 0 && green == 0xff && blue == 0, "Got color %08x, expected 0000ff00\n", color);
2047 color = D3D3_getPixelColor(DirectDraw4, Primary, 405, 105);
2048 red = (color & 0x00ff0000) >> 16;
2049 green = (color & 0x0000ff00) >> 8;
2050 blue = (color & 0x000000ff);
2051 ok(red == 0xff && green == 0 && blue == 0, "Got color %08x, expected 00ff0000\n", color);
2053 /* Test that clearing viewport doesn't interfere with rendering to previously active viewport. */
2054 hr = IDirect3DDevice3_BeginScene(Direct3DDevice3);
2055 ok(hr == D3D_OK, "IDirect3DDevice3_BeginScene failed with %08x\n", hr);
2057 if (SUCCEEDED(hr)) {
2058 hr = IDirect3DDevice3_SetCurrentViewport(Direct3DDevice3, SmallViewport3);
2059 ok(hr == D3D_OK, "IDirect3DDevice3_SetCurrentViewport failed with %08x\n", hr);
2061 hr = IDirect3DViewport3_Clear2(Viewport3, 1, &rect, D3DCLEAR_TARGET, 0x000000, 0.0f, 0);
2062 ok(hr == D3D_OK, "IDirect3DViewport3_Clear2 failed, hr = %08x\n", hr);
2064 hr = IDirect3DDevice3_DrawIndexedPrimitive(Direct3DDevice3, D3DPT_TRIANGLELIST, fvf, quad, 4 /* NumVerts */,
2065 Indices, 6 /* Indexcount */, 0 /* flags */);
2066 ok(hr == D3D_OK, "IDirect3DDevice3_DrawIndexedPrimitive failed with %08x\n", hr);
2068 hr = IDirect3DDevice3_EndScene(Direct3DDevice3);
2069 ok(hr == D3D_OK, "IDirect3DDevice3_EndScene failed, hr = %08x\n", hr);
2072 color = D3D3_getPixelColor(DirectDraw4, Primary, 5, 5);
2073 red = (color & 0x00ff0000) >> 16;
2074 green = (color & 0x0000ff00) >> 8;
2075 blue = (color & 0x000000ff);
2076 ok(red == 0 && green == 0 && blue == 0, "Got color %08x, expected 00000000\n", color);
2078 color = D3D3_getPixelColor(DirectDraw4, Primary, 405, 105);
2079 red = (color & 0x00ff0000) >> 16;
2080 green = (color & 0x0000ff00) >> 8;
2081 blue = (color & 0x000000ff);
2082 ok(red == 0xff && green == 0xff && blue == 0xff, "Got color %08x, expected 00ffffff\n", color);
2084 out:
2086 if (SmallViewport3) IDirect3DViewport3_Release(SmallViewport3);
2087 if (Viewport3) IDirect3DViewport3_Release(Viewport3);
2088 if (Direct3DDevice3) IDirect3DDevice3_Release(Direct3DDevice3);
2089 if (Direct3D3) IDirect3D3_Release(Direct3D3);
2090 if (Primary) IDirectDrawSurface4_Release(Primary);
2091 if (DirectDraw1) IDirectDraw_Release(DirectDraw1);
2092 if (DirectDraw4) IDirectDraw4_Release(DirectDraw4);
2093 if(window) DestroyWindow(window);
2096 static void p8_surface_fill_rect(IDirectDrawSurface *dest, UINT x, UINT y, UINT w, UINT h, BYTE colorindex)
2098 DDSURFACEDESC ddsd;
2099 HRESULT hr;
2100 UINT i, i1;
2101 BYTE *p;
2103 memset(&ddsd, 0, sizeof(ddsd));
2104 ddsd.dwSize = sizeof(ddsd);
2106 hr = IDirectDrawSurface_Lock(dest, NULL, &ddsd, DDLOCK_WRITEONLY | DDLOCK_WAIT, NULL);
2107 ok(hr==DD_OK, "IDirectDrawSurface_Lock returned: %x\n", hr);
2109 p = (BYTE *)ddsd.lpSurface + U1(ddsd).lPitch * y + x;
2111 for (i = 0; i < h; i++) {
2112 for (i1 = 0; i1 < w; i1++) {
2113 p[i1] = colorindex;
2115 p += U1(ddsd).lPitch;
2118 hr = IDirectDrawSurface_Unlock(dest, NULL);
2119 ok(hr==DD_OK, "IDirectDrawSurface_UnLock returned: %x\n", hr);
2122 static COLORREF getPixelColor_GDI(IDirectDrawSurface *Surface, UINT x, UINT y)
2124 COLORREF clr = CLR_INVALID;
2125 HDC hdc;
2126 HRESULT hr;
2128 hr = IDirectDrawSurface_GetDC(Surface, &hdc);
2129 ok(hr==DD_OK, "IDirectDrawSurface_GetDC returned: %x\n", hr);
2131 if (SUCCEEDED(hr)) {
2132 clr = GetPixel(hdc, x, y);
2134 hr = IDirectDrawSurface_ReleaseDC(Surface, hdc);
2135 ok(hr==DD_OK, "IDirectDrawSurface_ReleaseDC returned: %x\n", hr);
2138 return clr;
2141 static BOOL colortables_check_equality(PALETTEENTRY table1[256], RGBQUAD table2[256])
2143 int i;
2145 for (i = 0; i < 256; i++) {
2146 if (table1[i].peRed != table2[i].rgbRed || table1[i].peGreen != table2[i].rgbGreen ||
2147 table1[i].peBlue != table2[i].rgbBlue) return FALSE;
2150 return TRUE;
2153 static void p8_primary_test()
2155 /* Test 8bit mode used by games like StarCraft, C&C Red Alert I etc */
2156 DDSURFACEDESC ddsd;
2157 HDC hdc;
2158 HRESULT hr;
2159 PALETTEENTRY entries[256];
2160 RGBQUAD coltable[256];
2161 UINT i, i1, i2;
2162 IDirectDrawPalette *ddprimpal = NULL;
2163 IDirectDrawSurface *offscreen = NULL;
2164 WNDCLASS wc = {0};
2165 DDBLTFX ddbltfx;
2166 COLORREF color;
2167 RECT rect;
2168 DDCOLORKEY clrKey;
2169 unsigned differences;
2171 /* An IDirect3DDevice cannot be queryInterfaced from an IDirect3DDevice7 on windows */
2172 hr = DirectDrawCreate(NULL, &DirectDraw1, NULL);
2174 ok(hr==DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreate returned: %x\n", hr);
2175 if (FAILED(hr)) {
2176 goto out;
2179 wc.lpfnWndProc = DefWindowProc;
2180 wc.lpszClassName = "p8_primary_test_wc";
2181 RegisterClass(&wc);
2182 window = CreateWindow("p8_primary_test_wc", "p8_primary_test", WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
2184 hr = IDirectDraw_SetCooperativeLevel(DirectDraw1, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2185 ok(hr==DD_OK, "SetCooperativeLevel returned: %x\n", hr);
2186 if(FAILED(hr)) {
2187 goto out;
2190 hr = IDirectDraw_SetDisplayMode(DirectDraw1, 640, 480, 8);
2191 ok(hr==DD_OK || hr == DDERR_UNSUPPORTED, "SetDisplayMode returned: %x\n", hr);
2192 if (FAILED(hr)) {
2193 goto out;
2196 memset(&ddsd, 0, sizeof(ddsd));
2197 ddsd.dwSize = sizeof(ddsd);
2198 ddsd.dwFlags = DDSD_CAPS;
2199 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2200 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &Surface1, NULL);
2201 ok(hr==DD_OK, "CreateSurface returned: %x\n", hr);
2202 if (FAILED(hr)) {
2203 goto out;
2206 memset(entries, 0, sizeof(entries));
2207 entries[0].peRed = 0xff;
2208 entries[1].peGreen = 0xff;
2209 entries[2].peBlue = 0xff;
2211 hr = IDirectDraw_CreatePalette(DirectDraw1, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, entries, &ddprimpal, NULL);
2212 ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
2213 if (FAILED(hr)) {
2214 skip("IDirectDraw_CreatePalette failed; skipping further tests\n");
2215 goto out;
2218 hr = IDirectDrawSurface_SetPalette(Surface1, ddprimpal);
2219 ok(hr==DD_OK, "IDirectDrawSurface_SetPalette returned: %x\n", hr);
2221 p8_surface_fill_rect(Surface1, 0, 0, 640, 480, 2);
2223 color = getPixelColor_GDI(Surface1, 10, 10);
2224 ok(GetRValue(color) == 0 && GetGValue(color) == 0 && GetBValue(color) == 0xFF,
2225 "got R %02X G %02X B %02X, expected R 00 G 00 B FF\n",
2226 GetRValue(color), GetGValue(color), GetBValue(color));
2228 memset(&ddbltfx, 0, sizeof(ddbltfx));
2229 ddbltfx.dwSize = sizeof(ddbltfx);
2230 U5(ddbltfx).dwFillColor = 0;
2231 hr = IDirectDrawSurface_Blt(Surface1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
2232 ok(hr == DD_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
2234 color = getPixelColor_GDI(Surface1, 10, 10);
2235 ok(GetRValue(color) == 0xFF && GetGValue(color) == 0 && GetBValue(color) == 0,
2236 "got R %02X G %02X B %02X, expected R FF G 00 B 00\n",
2237 GetRValue(color), GetGValue(color), GetBValue(color));
2239 memset(&ddbltfx, 0, sizeof(ddbltfx));
2240 ddbltfx.dwSize = sizeof(ddbltfx);
2241 U5(ddbltfx).dwFillColor = 1;
2242 hr = IDirectDrawSurface_Blt(Surface1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
2243 ok(hr == DD_OK, "IDirectDrawSurface_Blt failed with %08x\n", hr);
2245 color = getPixelColor_GDI(Surface1, 10, 10);
2246 ok(GetRValue(color) == 0 && GetGValue(color) == 0xFF && GetBValue(color) == 0,
2247 "got R %02X G %02X B %02X, expected R 00 G FF B 00\n",
2248 GetRValue(color), GetGValue(color), GetBValue(color));
2250 memset (&ddsd, 0, sizeof (ddsd));
2251 ddsd.dwSize = sizeof (ddsd);
2252 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
2253 ddsd.dwWidth = 16;
2254 ddsd.dwHeight = 16;
2255 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;
2256 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
2257 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED8;
2258 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 8;
2259 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &offscreen, NULL);
2260 ok(hr == DD_OK, "IDirectDraw_CreateSurface returned %08x\n", hr);
2261 if (FAILED(hr)) goto out;
2263 memset(entries, 0, sizeof(entries));
2264 for (i = 0; i < 256; i++) {
2265 entries[i].peBlue = i;
2267 hr = IDirectDrawPalette_SetEntries(ddprimpal, 0, 0, 256, entries);
2268 ok(hr == DD_OK, "IDirectDrawPalette_SetEntries failed with %08x\n", hr);
2270 hr = IDirectDrawSurface_GetDC(offscreen, &hdc);
2271 ok(hr==DD_OK, "IDirectDrawSurface_GetDC returned: %x\n", hr);
2272 i = GetDIBColorTable(hdc, 0, 256, coltable);
2273 ok(i == 256, "GetDIBColorTable returned %u, last error: %x\n", i, GetLastError());
2274 hr = IDirectDrawSurface_ReleaseDC(offscreen, hdc);
2275 ok(hr==DD_OK, "IDirectDrawSurface_ReleaseDC returned: %x\n", hr);
2277 ok(colortables_check_equality(entries, coltable), "unexpected colortable on offscreen surface\n");
2279 p8_surface_fill_rect(offscreen, 0, 0, 16, 16, 2);
2281 memset(entries, 0, sizeof(entries));
2282 entries[0].peRed = 0xff;
2283 entries[1].peGreen = 0xff;
2284 entries[2].peBlue = 0xff;
2285 entries[3].peRed = 0x80;
2286 hr = IDirectDrawPalette_SetEntries(ddprimpal, 0, 0, 256, entries);
2287 ok(hr == DD_OK, "IDirectDrawPalette_SetEntries failed with %08x\n", hr);
2289 hr = IDirectDrawSurface_BltFast(Surface1, 0, 0, offscreen, NULL, 0);
2290 ok(hr==DD_OK, "IDirectDrawSurface_BltFast returned: %x\n", hr);
2292 color = getPixelColor_GDI(Surface1, 1, 1);
2293 ok(GetRValue(color) == 0 && GetGValue(color) == 0x00 && GetBValue(color) == 0xFF,
2294 "got R %02X G %02X B %02X, expected R 00 G 00 B FF\n",
2295 GetRValue(color), GetGValue(color), GetBValue(color));
2297 /* Color keyed blit. */
2298 p8_surface_fill_rect(offscreen, 0, 0, 8, 8, 3);
2299 clrKey.dwColorSpaceLowValue = 3;
2300 clrKey.dwColorSpaceHighValue = 3;
2301 hr = IDirectDrawSurface_SetColorKey(offscreen, DDCKEY_SRCBLT, &clrKey);
2302 ok(hr==D3D_OK, "IDirectDrawSurfac_SetColorKey returned: %x\n", hr);
2304 hr = IDirectDrawSurface_BltFast(Surface1, 100, 100, offscreen, NULL, DDBLTFAST_SRCCOLORKEY);
2305 ok(hr==DD_OK, "IDirectDrawSurface_BltFast returned: %x\n", hr);
2307 color = getPixelColor_GDI(Surface1, 105, 105);
2308 ok(GetRValue(color) == 0 && GetGValue(color) == 0xFF && GetBValue(color) == 0,
2309 "got R %02X G %02X B %02X, expected R 00 G FF B 00\n",
2310 GetRValue(color), GetGValue(color), GetBValue(color));
2312 color = getPixelColor_GDI(Surface1, 112, 112);
2313 ok(GetRValue(color) == 0 && GetGValue(color) == 0x00 && GetBValue(color) == 0xFF,
2314 "got R %02X G %02X B %02X, expected R 00 G 00 B FF\n",
2315 GetRValue(color), GetGValue(color), GetBValue(color));
2317 rect.left = 100;
2318 rect.top = 200;
2319 rect.right = 116;
2320 rect.bottom = 216;
2322 memset(&ddbltfx, 0, sizeof(ddbltfx));
2323 ddbltfx.dwSize = sizeof(ddbltfx);
2324 ddbltfx.ddckSrcColorkey.dwColorSpaceLowValue = ddbltfx.ddckSrcColorkey.dwColorSpaceHighValue = 2;
2325 hr = IDirectDrawSurface_Blt(Surface1, &rect, offscreen, NULL,
2326 DDBLT_WAIT | DDBLT_KEYSRC | DDBLT_KEYSRCOVERRIDE, &ddbltfx);
2327 ok(hr==DDERR_INVALIDPARAMS, "IDirectDrawSurface_Blt returned: %x\n", hr);
2328 hr = IDirectDrawSurface_Blt(Surface1, &rect, offscreen, NULL,
2329 DDBLT_WAIT | DDBLT_KEYSRCOVERRIDE, &ddbltfx);
2330 ok(hr==DD_OK, "IDirectDrawSurface_Blt returned: %x\n", hr);
2332 color = getPixelColor_GDI(Surface1, 105, 205);
2333 ok(GetRValue(color) == 0x80 && GetGValue(color) == 0 && GetBValue(color) == 0,
2334 "got R %02X G %02X B %02X, expected R 80 G 00 B 00\n",
2335 GetRValue(color), GetGValue(color), GetBValue(color));
2337 color = getPixelColor_GDI(Surface1, 112, 212);
2338 ok(GetRValue(color) == 0 && GetGValue(color) == 0xFF && GetBValue(color) == 0,
2339 "got R %02X G %02X B %02X, expected R 00 G FF B 00\n",
2340 GetRValue(color), GetGValue(color), GetBValue(color));
2342 /* Test blitting and locking patterns that are likely to trigger bugs in opengl renderer (p8
2343 surface conversion and uploading/downloading to/from opengl texture). Similar patterns (
2344 blitting front buffer areas to/from an offscreen surface mixed with locking) are used by C&C
2345 Red Alert I. */
2346 IDirectDrawSurface_Release(offscreen);
2348 memset (&ddsd, 0, sizeof (ddsd));
2349 ddsd.dwSize = sizeof (ddsd);
2350 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
2351 ddsd.dwWidth = 640;
2352 ddsd.dwHeight = 480;
2353 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
2354 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
2355 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED8;
2356 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 8;
2357 hr = IDirectDraw_CreateSurface(DirectDraw1, &ddsd, &offscreen, NULL);
2358 ok(hr == DD_OK, "IDirectDraw_CreateSurface returned %08x\n", hr);
2360 if (FAILED(hr)) goto out;
2362 /* Test two times, first time front buffer has a palette and second time front buffer
2363 has no palette; the latter is somewhat contrived example, but an app could set
2364 front buffer palette later. */
2365 for (i2 = 0; i2 < 2; i2++) {
2366 if (i2 == 1) {
2367 hr = IDirectDrawSurface_SetPalette(Surface1, NULL);
2368 ok(hr==DD_OK, "IDirectDrawSurface_SetPalette returned: %x\n", hr);
2371 memset(&ddsd, 0, sizeof(ddsd));
2372 ddsd.dwSize = sizeof(ddsd);
2373 hr = IDirectDrawSurface_Lock(Surface1, NULL, &ddsd, DDLOCK_WAIT, NULL);
2374 ok(hr==DD_OK, "IDirectDrawSurface_Lock returned: %x\n", hr);
2376 for (i = 0; i < 256; i++) {
2377 unsigned x = (i % 128) * 4;
2378 unsigned y = (i / 128) * 4;
2379 BYTE *p = (BYTE *)ddsd.lpSurface + U1(ddsd).lPitch * y + x;
2381 for (i1 = 0; i1 < 4; i1++) {
2382 p[0] = p[1] = p[2] = p[3] = i;
2383 p += U1(ddsd).lPitch;
2387 hr = IDirectDrawSurface_Unlock(Surface1, NULL);
2388 ok(hr==DD_OK, "IDirectDrawSurface_UnLock returned: %x\n", hr);
2390 hr = IDirectDrawSurface_BltFast(offscreen, 0, 0, Surface1, NULL, 0);
2391 ok(hr==DD_OK, "IDirectDrawSurface_BltFast returned: %x\n", hr);
2393 /* This ensures offscreen surface contents will be downloaded to system memory. */
2394 memset(&ddsd, 0, sizeof(ddsd));
2395 ddsd.dwSize = sizeof(ddsd);
2396 hr = IDirectDrawSurface_Lock(offscreen, NULL, &ddsd, DDLOCK_WAIT, NULL);
2397 ok(hr==DD_OK, "IDirectDrawSurface_Lock returned: %x\n", hr);
2398 hr = IDirectDrawSurface_Unlock(offscreen, NULL);
2399 ok(hr==DD_OK, "IDirectDrawSurface_UnLock returned: %x\n", hr);
2401 /* Offscreen surface data will have to be converted and uploaded to texture. */
2402 rect.left = 0;
2403 rect.top = 0;
2404 rect.right = 16;
2405 rect.bottom = 16;
2406 hr = IDirectDrawSurface_BltFast(offscreen, 600, 400, Surface1, &rect, 0);
2407 ok(hr==DD_OK, "IDirectDrawSurface_BltFast returned: %x\n", hr);
2409 /* This ensures offscreen surface contents will be downloaded to system memory. */
2410 memset(&ddsd, 0, sizeof(ddsd));
2411 ddsd.dwSize = sizeof(ddsd);
2412 hr = IDirectDrawSurface_Lock(offscreen, NULL, &ddsd, DDLOCK_WAIT, NULL);
2413 ok(hr==DD_OK, "IDirectDrawSurface_Lock returned: %x\n", hr);
2414 hr = IDirectDrawSurface_Unlock(offscreen, NULL);
2415 ok(hr==DD_OK, "IDirectDrawSurface_UnLock returned: %x\n", hr);
2417 hr = IDirectDrawSurface_BltFast(Surface1, 0, 0, offscreen, NULL, 0);
2418 ok(hr==DD_OK, "IDirectDrawSurface_BltFast returned: %x\n", hr);
2420 memset(&ddsd, 0, sizeof(ddsd));
2421 ddsd.dwSize = sizeof(ddsd);
2422 hr = IDirectDrawSurface_Lock(Surface1, NULL, &ddsd, DDLOCK_WAIT, NULL);
2423 ok(hr==DD_OK, "IDirectDrawSurface_Lock returned: %x\n", hr);
2425 differences = 0;
2427 for (i = 0; i < 256; i++) {
2428 unsigned x = (i % 128) * 4 + 1;
2429 unsigned y = (i / 128) * 4 + 1;
2430 BYTE *p = (BYTE *)ddsd.lpSurface + U1(ddsd).lPitch * y + x;
2432 if (*p != i) differences++;
2435 hr = IDirectDrawSurface_Unlock(Surface1, NULL);
2436 ok(hr==DD_OK, "IDirectDrawSurface_UnLock returned: %x\n", hr);
2438 ok(differences == 0, i2 == 0 ? "Pass 1. Unexpected front buffer contents after blit (%u differences)\n" :
2439 "Pass 2 (with NULL front buffer palette). Unexpected front buffer contents after blit (%u differences)\n",
2440 differences);
2443 out:
2445 if(ddprimpal) IDirectDrawPalette_Release(ddprimpal);
2446 if(offscreen) IDirectDrawSurface_Release(offscreen);
2447 if(Surface1) IDirectDrawSurface_Release(Surface1);
2448 if(DirectDraw1) IDirectDraw_Release(DirectDraw1);
2449 if(window) DestroyWindow(window);
2452 static void cubemap_test(IDirect3DDevice7 *device)
2454 IDirect3D7 *d3d;
2455 IDirectDraw7 *ddraw;
2456 IDirectDrawSurface7 *cubemap, *surface;
2457 D3DDEVICEDESC7 d3dcaps;
2458 HRESULT hr;
2459 DWORD color;
2460 DDSURFACEDESC2 ddsd;
2461 DDBLTFX DDBltFx;
2462 DDSCAPS2 caps;
2463 static float quad[] = {
2464 -1.0, -1.0, 0.1, 1.0, 0.0, 0.0, /* Lower left */
2465 0.0, -1.0, 0.1, 1.0, 0.0, 0.0,
2466 -1.0, 0.0, 0.1, 1.0, 0.0, 0.0,
2467 0.0, 0.0, 0.1, 1.0, 0.0, 0.0,
2469 0.0, -1.0, 0.1, 0.0, 1.0, 0.0, /* Lower right */
2470 1.0, -1.0, 0.1, 0.0, 1.0, 0.0,
2471 0.0, 0.0, 0.1, 0.0, 1.0, 0.0,
2472 1.0, 0.0, 0.1, 0.0, 1.0, 0.0,
2474 0.0, 0.0, 0.1, 0.0, 0.0, 1.0, /* upper right */
2475 1.0, 0.0, 0.1, 0.0, 0.0, 1.0,
2476 0.0, 1.0, 0.1, 0.0, 0.0, 1.0,
2477 1.0, 1.0, 0.1, 0.0, 0.0, 1.0,
2479 -1.0, 0.0, 0.1, -1.0, 0.0, 0.0, /* Upper left */
2480 0.0, 0.0, 0.1, -1.0, 0.0, 0.0,
2481 -1.0, 1.0, 0.1, -1.0, 0.0, 0.0,
2482 0.0, 1.0, 0.1, -1.0, 0.0, 0.0,
2485 memset(&DDBltFx, 0, sizeof(DDBltFx));
2486 DDBltFx.dwSize = sizeof(DDBltFx);
2488 memset(&d3dcaps, 0, sizeof(d3dcaps));
2489 hr = IDirect3DDevice7_GetCaps(device, &d3dcaps);
2490 ok(hr == D3D_OK, "IDirect3DDevice7_GetCaps returned %08x\n", hr);
2491 if(!(d3dcaps.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_CUBEMAP))
2493 skip("No cubemap support\n");
2494 return;
2497 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff000000, 0.0, 0);
2498 ok(hr == D3D_OK, "IDirect3DDevice7_Clear failed with %08x\n", hr);
2500 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
2501 ok(hr == D3D_OK, "IDirect3DDevice7_GetDirect3D returned %08x\n", hr);
2502 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **) &ddraw);
2503 ok(hr == D3D_OK, "IDirect3D7_QueryInterface returned %08x\n", hr);
2504 IDirect3D7_Release(d3d);
2507 memset(&ddsd, 0, sizeof(ddsd));
2508 ddsd.dwSize = sizeof(ddsd);
2509 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
2510 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
2511 ddsd.dwWidth = 16;
2512 ddsd.dwHeight = 16;
2513 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX;
2514 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_TEXTUREMANAGE;
2515 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
2516 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
2517 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00FF0000;
2518 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000FF00;
2519 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000FF;
2521 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &cubemap, NULL);
2522 ok(hr == DD_OK, "IDirectDraw7_CreateSurface returned %08x\n", hr);
2523 IDirectDraw7_Release(ddraw);
2525 /* Positive X */
2526 U5(DDBltFx).dwFillColor = 0x00ff0000;
2527 hr = IDirectDrawSurface7_Blt(cubemap, NULL, NULL, NULL, DDBLT_COLORFILL, &DDBltFx);
2528 ok(hr == DD_OK, "IDirectDrawSurface7_Blt returned %08x\n", hr);
2530 memset(&caps, 0, sizeof(caps));
2531 caps.dwCaps = DDSCAPS_TEXTURE;
2532 caps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX;
2533 hr = IDirectDrawSurface_GetAttachedSurface(cubemap, &caps, &surface);
2534 ok(hr == DD_OK, "IDirectDrawSurface7_Lock returned %08x\n", hr);
2535 U5(DDBltFx).dwFillColor = 0x0000ffff;
2536 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL, &DDBltFx);
2537 ok(hr == DD_OK, "IDirectDrawSurface7_Blt returned %08x\n", hr);
2539 caps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEZ;
2540 hr = IDirectDrawSurface_GetAttachedSurface(cubemap, &caps, &surface);
2541 ok(hr == DD_OK, "IDirectDrawSurface7_Lock returned %08x\n", hr);
2542 U5(DDBltFx).dwFillColor = 0x0000ff00;
2543 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL, &DDBltFx);
2544 ok(hr == DD_OK, "IDirectDrawSurface7_Blt returned %08x\n", hr);
2546 caps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEZ;
2547 hr = IDirectDrawSurface_GetAttachedSurface(cubemap, &caps, &surface);
2548 ok(hr == DD_OK, "IDirectDrawSurface7_Lock returned %08x\n", hr);
2549 U5(DDBltFx).dwFillColor = 0x000000ff;
2550 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL, &DDBltFx);
2551 ok(hr == DD_OK, "IDirectDrawSurface7_Blt returned %08x\n", hr);
2553 caps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEY;
2554 hr = IDirectDrawSurface_GetAttachedSurface(cubemap, &caps, &surface);
2555 ok(hr == DD_OK, "IDirectDrawSurface7_Lock returned %08x\n", hr);
2556 U5(DDBltFx).dwFillColor = 0x00ffff00;
2557 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL, &DDBltFx);
2558 ok(hr == DD_OK, "IDirectDrawSurface7_Blt returned %08x\n", hr);
2560 caps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEY;
2561 hr = IDirectDrawSurface_GetAttachedSurface(cubemap, &caps, &surface);
2562 ok(hr == DD_OK, "IDirectDrawSurface7_Lock returned %08x\n", hr);
2563 U5(DDBltFx).dwFillColor = 0x00ff00ff;
2564 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL, &DDBltFx);
2565 ok(hr == DD_OK, "IDirectDrawSurface7_Blt returned %08x\n", hr);
2567 hr = IDirect3DDevice7_SetTexture(device, 0, cubemap);
2568 ok(hr == DD_OK, "IDirect3DDevice7_SetTexture returned %08x\n", hr);
2569 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
2570 ok(hr == DD_OK, "IDirect3DDevice7_SetTextureStageState returned %08x\n", hr);
2571 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
2572 ok(hr == DD_OK, "IDirect3DDevice7_SetTextureStageState returned %08x\n", hr);
2574 hr = IDirect3DDevice7_BeginScene(device);
2575 ok(hr == DD_OK, "IDirect3DDevice7_BeginScene returned %08x\n", hr);
2576 if(SUCCEEDED(hr))
2578 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1, quad + 0 * 6, 4, 0);
2579 ok(hr == DD_OK, "IDirect3DDevice7_DrawPrimitive returned %08x\n", hr);
2580 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1, quad + 4 * 6, 4, 0);
2581 ok(hr == DD_OK, "IDirect3DDevice7_DrawPrimitive returned %08x\n", hr);
2582 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1, quad + 8 * 6, 4, 0);
2583 ok(hr == DD_OK, "IDirect3DDevice7_DrawPrimitive returned %08x\n", hr);
2584 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1, quad + 12* 6, 4, 0);
2585 ok(hr == DD_OK, "IDirect3DDevice7_DrawPrimitive returned %08x\n", hr);
2587 hr = IDirect3DDevice7_EndScene(device);
2588 ok(hr == DD_OK, "IDirect3DDevice7_EndScene returned %08x\n", hr);
2590 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_DISABLE);
2591 ok(hr == DD_OK, "IDirect3DDevice7_SetTextureStageState returned %08x\n", hr);
2593 color = getPixelColor(device, 160, 360); /* lower left quad - positivex */
2594 ok(color == 0x00ff0000, "DDSCAPS2_CUBEMAP_POSITIVEX has color 0x%08x, expected 0x00ff0000\n", color);
2595 color = getPixelColor(device, 160, 120); /* upper left quad - negativex */
2596 ok(color == 0x0000ffff, "DDSCAPS2_CUBEMAP_NEGATIVEX has color 0x%08x, expected 0x0000ffff\n", color);
2597 color = getPixelColor(device, 480, 360); /* lower right quad - positivey */
2598 ok(color == 0x00ff00ff, "DDSCAPS2_CUBEMAP_POSITIVEY has color 0x%08x, expected 0x00ff00ff\n", color);
2599 color = getPixelColor(device, 480, 120); /* upper right quad - positivez */
2600 ok(color == 0x000000ff, "DDSCAPS2_CUBEMAP_POSITIVEZ has color 0x%08x, expected 0x000000ff\n", color);
2601 hr = IDirect3DDevice7_SetTexture(device, 0, NULL);
2602 ok(hr == DD_OK, "IDirect3DDevice7_SetTexture returned %08x\n", hr);
2603 IDirectDrawSurface7_Release(cubemap);
2606 START_TEST(visual)
2608 HRESULT hr;
2609 DWORD color;
2610 if(!createObjects())
2612 skip("Cannot initialize DirectDraw and Direct3D, skipping\n");
2613 return;
2616 /* Check for the reliability of the returned data */
2617 hr = IDirect3DDevice7_Clear(Direct3DDevice, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
2618 if(FAILED(hr))
2620 trace("Clear failed, can't assure correctness of the test results, skipping\n");
2621 goto cleanup;
2624 color = getPixelColor(Direct3DDevice, 1, 1);
2625 if(color !=0x00ff0000)
2627 trace("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests, skipping\n", color);
2628 goto cleanup;
2631 hr = IDirect3DDevice7_Clear(Direct3DDevice, 0, NULL, D3DCLEAR_TARGET, 0xff00ddee, 0.0, 0);
2632 if(FAILED(hr))
2634 trace("Clear failed, can't assure correctness of the test results, skipping\n");
2635 goto cleanup;
2638 color = getPixelColor(Direct3DDevice, 639, 479);
2639 if(color != 0x0000ddee)
2641 trace("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests, skipping\n", color);
2642 goto cleanup;
2645 /* Now run the tests */
2646 lighting_test(Direct3DDevice);
2647 clear_test(Direct3DDevice);
2648 fog_test(Direct3DDevice);
2649 offscreen_test(Direct3DDevice);
2650 alpha_test(Direct3DDevice);
2651 rhw_zero_test(Direct3DDevice);
2652 cubemap_test(Direct3DDevice);
2654 releaseObjects(); /* release DX7 interfaces to test D3D1 */
2656 if(!D3D1_createObjects()) {
2657 skip("Cannot initialize D3D1, skipping\n");
2659 else {
2660 D3D1_TextureMapBlendTest();
2661 D3D1_ViewportClearTest();
2663 D3D1_releaseObjects();
2665 D3D3_ViewportClearTest();
2666 p8_primary_test();
2668 return ;
2670 cleanup:
2671 releaseObjects();