2 * Copyright (C) 2007 Stefan Dösinger(for CodeWeavers)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 /* See comment in dlls/d3d9/tests/visual.c for general guidelines */
22 #include "wine/test.h"
27 IDirectDraw7
*DirectDraw
= NULL
;
28 IDirectDrawSurface7
*Surface
;
29 IDirect3D7
*Direct3D
= NULL
;
30 IDirect3DDevice7
*Direct3DDevice
= NULL
;
32 static HRESULT (WINAPI
*pDirectDrawCreateEx
)(LPGUID
,LPVOID
*,REFIID
,LPUNKNOWN
);
34 static BOOL
createObjects(void)
37 HMODULE hmod
= GetModuleHandleA("ddraw.dll");
42 if(!hmod
) return FALSE
;
43 pDirectDrawCreateEx
= (void*)GetProcAddress(hmod
, "DirectDrawCreateEx");
44 if(!pDirectDrawCreateEx
) return FALSE
;
46 hr
= pDirectDrawCreateEx(NULL
, (void **) &DirectDraw
, &IID_IDirectDraw7
, NULL
);
47 ok(hr
==DD_OK
|| hr
==DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreateEx returned: %x\n", hr
);
48 if(!DirectDraw
) goto err
;
50 wc
.lpfnWndProc
= &DefWindowProc
;
51 wc
.lpszClassName
= "d3d7_test_wc";
53 window
= CreateWindow("d3d7_test_wc", "d3d7_test", WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
55 hr
= IDirectDraw7_SetCooperativeLevel(DirectDraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
56 ok(hr
== DD_OK
, "IDirectDraw7_SetCooperativeLevel failed with %08x\n", hr
);
57 if(FAILED(hr
)) goto err
;
58 hr
= IDirectDraw7_SetDisplayMode(DirectDraw
, 640, 480, 32, 0, 0);
60 /* 24 bit is fine too */
61 hr
= IDirectDraw7_SetDisplayMode(DirectDraw
, 640, 480, 24, 0, 0);
64 ok(hr
== DD_OK
|| hr
== DDERR_UNSUPPORTED
, "IDirectDraw7_SetDisplayMode failed with %08x\n", hr
);
66 /* use trace, the caller calls skip() */
67 trace("SetDisplayMode failed\n");
71 hr
= IDirectDraw7_QueryInterface(DirectDraw
, &IID_IDirect3D7
, (void**) &Direct3D
);
72 if (hr
== E_NOINTERFACE
) goto err
;
73 ok(hr
==DD_OK
, "QueryInterface returned: %08x\n", hr
);
75 /* DirectDraw Flipping behavior doesn't seem that well-defined. The reference rasterizer behaves differently
76 * than hardware implementations. Request single buffering, that seems to work everywhere
78 memset(&ddsd
, 0, sizeof(ddsd
));
79 ddsd
.dwSize
= sizeof(ddsd
);
80 ddsd
.dwFlags
= DDSD_CAPS
;
81 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
;
82 ddsd
.dwBackBufferCount
= 1;
83 hr
= IDirectDraw7_CreateSurface(DirectDraw
, &ddsd
, &Surface
, NULL
);
84 ok(hr
==DD_OK
, "CreateSurface returned: %08x\n", hr
);
85 if(!Surface
) goto err
;
87 hr
= IDirect3D7_CreateDevice(Direct3D
, &IID_IDirect3DTnLHalDevice
, Surface
, &Direct3DDevice
);
90 trace("Creating a TnLHal Device failed, trying HAL\n");
91 hr
= IDirect3D7_CreateDevice(Direct3D
, &IID_IDirect3DHALDevice
, Surface
, &Direct3DDevice
);
94 trace("Creating a HAL device failed, trying Ref\n");
95 hr
= IDirect3D7_CreateDevice(Direct3D
, &IID_IDirect3DRefDevice
, Surface
, &Direct3DDevice
);
98 ok(hr
== D3D_OK
, "IDirect3D7_CreateDevice failed with %08x\n", hr
);
99 if(!Direct3DDevice
) goto err
;
103 if(DirectDraw
) IDirectDraw7_Release(DirectDraw
);
104 if(Surface
) IDirectDrawSurface7_Release(Surface
);
105 if(Direct3D
) IDirect3D7_Release(Direct3D
);
106 if(Direct3DDevice
) IDirect3DDevice7_Release(Direct3DDevice
);
107 if(window
) DestroyWindow(window
);
111 static void releaseObjects(void)
113 IDirect3DDevice7_Release(Direct3DDevice
);
114 IDirect3D7_Release(Direct3D
);
115 IDirectDrawSurface7_Release(Surface
);
116 IDirectDraw7_Release(DirectDraw
);
117 DestroyWindow(window
);
120 static DWORD
getPixelColor(IDirect3DDevice7
*device
, UINT x
, UINT y
)
125 RECT rectToLock
= {x
, y
, x
+1, y
+1};
126 IDirectDrawSurface7
*surf
= NULL
;
128 /* Some implementations seem to dislike direct locking on the front buffer. Thus copy the front buffer
129 * to an offscreen surface and lock it instead of the front buffer
131 memset(&ddsd
, 0, sizeof(ddsd
));
132 ddsd
.dwSize
= sizeof(ddsd
);
133 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
134 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
137 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
;
138 hr
= IDirectDraw7_CreateSurface(DirectDraw
, &ddsd
, &surf
, NULL
);
139 ok(hr
== DD_OK
, "IDirectDraw7_CreateSurface failed with %08x\n", hr
);
142 trace("cannot create helper surface\n");
146 memset(&ddsd
, 0, sizeof(ddsd
));
147 ddsd
.dwSize
= sizeof(ddsd
);
148 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
150 hr
= IDirectDrawSurface_BltFast(surf
, 0, 0, Surface
, NULL
, 0);
151 ok(hr
== DD_OK
, "IDirectDrawSurface7_BltFast returned %08x\n", hr
);
154 trace("Cannot blit\n");
159 hr
= IDirectDrawSurface7_Lock(surf
, &rectToLock
, &ddsd
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
162 trace("Can't lock the offscreen surface, hr=%08x\n", hr
);
167 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
168 * really important for these tests
170 ret
= ((DWORD
*) ddsd
.lpSurface
)[0] & 0x00ffffff;
171 hr
= IDirectDrawSurface7_Unlock(surf
, &rectToLock
);
174 trace("Can't unlock the offscreen surface, hr=%08x\n", hr
);
178 IDirectDrawSurface7_Release(surf
);
195 static void lighting_test(IDirect3DDevice7
*device
)
198 DWORD fvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
199 DWORD nfvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_NORMAL
;
202 float mat
[16] = { 1.0f
, 0.0f
, 0.0f
, 0.0f
,
203 0.0f
, 1.0f
, 0.0f
, 0.0f
,
204 0.0f
, 0.0f
, 1.0f
, 0.0f
,
205 0.0f
, 0.0f
, 0.0f
, 1.0f
};
207 struct vertex unlitquad
[] =
209 {-1.0f
, -1.0f
, 0.1f
, 0xffff0000},
210 {-1.0f
, 0.0f
, 0.1f
, 0xffff0000},
211 { 0.0f
, 0.0f
, 0.1f
, 0xffff0000},
212 { 0.0f
, -1.0f
, 0.1f
, 0xffff0000},
214 struct vertex litquad
[] =
216 {-1.0f
, 0.0f
, 0.1f
, 0xff00ff00},
217 {-1.0f
, 1.0f
, 0.1f
, 0xff00ff00},
218 { 0.0f
, 1.0f
, 0.1f
, 0xff00ff00},
219 { 0.0f
, 0.0f
, 0.1f
, 0xff00ff00},
221 struct nvertex unlitnquad
[] =
223 { 0.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
224 { 0.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
225 { 1.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
226 { 1.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
228 struct nvertex litnquad
[] =
230 { 0.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
231 { 0.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
232 { 1.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
233 { 1.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
235 WORD Indices
[] = {0, 1, 2, 2, 3, 0};
237 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
238 ok(hr
== D3D_OK
, "IDirect3DDevice7_Clear failed with %08x\n", hr
);
240 /* Setup some states that may cause issues */
241 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, (D3DMATRIX
*) mat
);
242 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetTransform returned %08x\n", hr
);
243 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, (D3DMATRIX
*)mat
);
244 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetTransform returned %08x\n", hr
);
245 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, (D3DMATRIX
*) mat
);
246 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetTransform returned %08x\n", hr
);
247 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
248 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
249 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
250 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
251 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
252 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
253 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_STENCILENABLE
, FALSE
);
254 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
255 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ALPHATESTENABLE
, FALSE
);
256 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
257 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
);
258 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
259 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
260 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed with %08x\n", hr
);
262 hr
= IDirect3DDevice7_BeginScene(device
);
263 ok(hr
== D3D_OK
, "IDirect3DDevice7_BeginScene failed with %08x\n", hr
);
266 /* No lights are defined... That means, lit vertices should be entirely black */
267 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
268 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
269 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, fvf
, unlitquad
, 4 /* NumVerts */,
270 Indices
, 6 /* Indexcount */, 0 /* flags */);
271 ok(hr
== D3D_OK
, "IDirect3DDevice7_DrawIndexedPrimitiveUP failed with %08x\n", hr
);
273 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
274 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
275 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, fvf
, litquad
, 4 /* NumVerts */,
276 Indices
, 6 /* Indexcount */, 0 /* flags */);
277 ok(hr
== D3D_OK
, "IDirect3DDevice7_DrawIndexedPrimitiveUP failed with %08x\n", hr
);
279 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
280 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
281 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, nfvf
, unlitnquad
, 4 /* NumVerts */,
282 Indices
, 6 /* Indexcount */, 0 /* flags */);
283 ok(hr
== D3D_OK
, "IDirect3DDevice7_DrawIndexedPrimitiveUP failed with %08x\n", hr
);
285 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
286 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
287 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, nfvf
, litnquad
, 4 /* NumVerts */,
288 Indices
, 6 /* Indexcount */, 0 /* flags */);
289 ok(hr
== D3D_OK
, "IDirect3DDevice7_DrawIndexedPrimitiveUP failed with %08x\n", hr
);
291 IDirect3DDevice7_EndScene(device
);
292 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndScene failed with %08x\n", hr
);
295 color
= getPixelColor(device
, 160, 360); /* lower left quad - unlit without normals */
296 ok(color
== 0x00ff0000, "Unlit quad without normals has color %08x\n", color
);
297 color
= getPixelColor(device
, 160, 120); /* upper left quad - lit without normals */
298 ok(color
== 0x00000000, "Lit quad without normals has color %08x\n", color
);
299 color
= getPixelColor(device
, 480, 360); /* lower left quad - unlit width normals */
300 ok(color
== 0x000000ff, "Unlit quad width normals has color %08x\n", color
);
301 color
= getPixelColor(device
, 480, 120); /* upper left quad - lit width normals */
302 ok(color
== 0x00000000, "Lit quad width normals has color %08x\n", color
);
304 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
305 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
308 static void clear_test(IDirect3DDevice7
*device
)
310 /* Tests the correctness of clearing parameters */
316 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
317 ok(hr
== D3D_OK
, "IDirect3DDevice7_Clear failed with %08x\n", hr
);
319 /* Positive x, negative y */
321 U2(rect
[0]).y1
= 480;
322 U3(rect
[0]).x2
= 320;
323 U4(rect
[0]).y2
= 240;
325 /* Positive x, positive y */
328 U3(rect
[1]).x2
= 320;
329 U4(rect
[1]).y2
= 240;
330 /* Clear 2 rectangles with one call. Shows that a positive value is returned, but the negative rectangle
331 * is ignored, the positive is still cleared afterwards
333 hr
= IDirect3DDevice7_Clear(device
, 2, rect
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
334 ok(hr
== D3D_OK
, "IDirect3DDevice7_Clear failed with %08x\n", hr
);
336 /* negative x, negative y */
337 U1(rect_negneg
).x1
= 640;
338 U2(rect_negneg
).y1
= 240;
339 U3(rect_negneg
).x2
= 320;
340 U4(rect_negneg
).y2
= 0;
341 hr
= IDirect3DDevice7_Clear(device
, 1, &rect_negneg
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0, 0);
342 ok(hr
== D3D_OK
, "IDirect3DDevice7_Clear failed with %08x\n", hr
);
344 color
= getPixelColor(device
, 160, 360); /* lower left quad */
345 ok(color
== 0x00ffffff, "Clear rectangle 3(pos, neg) has color %08x\n", color
);
346 color
= getPixelColor(device
, 160, 120); /* upper left quad */
347 ok(color
== 0x00ff0000, "Clear rectangle 1(pos, pos) has color %08x\n", color
);
348 color
= getPixelColor(device
, 480, 360); /* lower right quad */
349 ok(color
== 0x00ffffff, "Clear rectangle 4(NULL) has color %08x\n", color
);
350 color
= getPixelColor(device
, 480, 120); /* upper right quad */
351 ok(color
== 0x00ffffff, "Clear rectangle 4(neg, neg) has color %08x\n", color
);
366 static void fog_test(IDirect3DDevice7
*device
)
370 float start
= 0.0, end
= 1.0;
373 /* Gets full z based fog with linear fog, no fog with specular color */
374 struct sVertex unstransformed_1
[] = {
375 {-1, -1, 0.1f
, 0xFFFF0000, 0xFF000000 },
376 {-1, 0, 0.1f
, 0xFFFF0000, 0xFF000000 },
377 { 0, 0, 0.1f
, 0xFFFF0000, 0xFF000000 },
378 { 0, -1, 0.1f
, 0xFFFF0000, 0xFF000000 },
380 /* Ok, I am too lazy to deal with transform matrices */
381 struct sVertex unstransformed_2
[] = {
382 {-1, 0, 1.0f
, 0xFFFF0000, 0xFF000000 },
383 {-1, 1, 1.0f
, 0xFFFF0000, 0xFF000000 },
384 { 0, 1, 1.0f
, 0xFFFF0000, 0xFF000000 },
385 { 0, 0, 1.0f
, 0xFFFF0000, 0xFF000000 },
387 /* Untransformed ones. Give them a different diffuse color to make the test look
388 * nicer. It also makes making sure that they are drawn correctly easier.
390 struct sVertexT transformed_1
[] = {
391 {320, 0, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
392 {640, 0, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
393 {640, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
394 {320, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
396 struct sVertexT transformed_2
[] = {
397 {320, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
398 {640, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
399 {640, 480, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
400 {320, 480, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
402 WORD Indices
[] = {0, 1, 2, 2, 3, 0};
404 memset(&caps
, 0, sizeof(caps
));
405 hr
= IDirect3DDevice7_GetCaps(device
, &caps
);
406 ok(hr
== D3D_OK
, "IDirect3DDevice7_GetCaps returned %08x\n", hr
);
407 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
408 ok(hr
== D3D_OK
, "IDirect3DDevice7_Clear returned %08x\n", hr
);
410 /* Setup initial states: No lighting, fog on, fog color */
411 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
412 ok(hr
== D3D_OK
, "Turning off lighting returned %08x\n", hr
);
413 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, TRUE
);
414 ok(hr
== D3D_OK
, "Turning on fog calculations returned %08x\n", hr
);
415 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGCOLOR
, 0xFF00FF00 /* A nice green */);
416 ok(hr
== D3D_OK
, "Turning on fog calculations returned %08x\n", hr
);
418 /* First test: Both table fog and vertex fog off */
419 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, D3DFOG_NONE
);
420 ok(hr
== D3D_OK
, "Turning off table fog returned %08x\n", hr
);
421 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGVERTEXMODE
, D3DFOG_NONE
);
422 ok(hr
== D3D_OK
, "Turning off table fog returned %08x\n", hr
);
424 /* Start = 0, end = 1. Should be default, but set them */
425 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGSTART
, *((DWORD
*) &start
));
426 ok(hr
== D3D_OK
, "Setting fog start returned %08x\n", hr
);
427 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGEND
, *((DWORD
*) &end
));
428 ok(hr
== D3D_OK
, "Setting fog start returned %08x\n", hr
);
430 if(IDirect3DDevice7_BeginScene(device
) == D3D_OK
)
432 /* Untransformed, vertex fog = NONE, table fog = NONE: Read the fog weighting from the specular color */
433 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
,
434 unstransformed_1
, 4, Indices
, 6, 0);
435 ok(hr
== D3D_OK
, "DrawIndexedPrimitive returned %08x\n", hr
);
437 /* That makes it use the Z value */
438 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGVERTEXMODE
, D3DFOG_LINEAR
);
439 ok(hr
== D3D_OK
, "Turning off table fog returned %08x\n", hr
);
440 /* Untransformed, vertex fog != none (or table fog != none):
441 * Use the Z value as input into the equation
443 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
,
444 unstransformed_2
, 4, Indices
, 6, 0);
445 ok(hr
== D3D_OK
, "DrawIndexedPrimitive returned %08x\n", hr
);
447 /* transformed verts */
448 ok( hr
== D3D_OK
, "SetFVF returned %08x\n", hr
);
449 /* Transformed, vertex fog != NONE, pixel fog == NONE: Use specular color alpha component */
450 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
,
451 transformed_1
, 4, Indices
, 6, 0);
452 ok(hr
== D3D_OK
, "DrawIndexedPrimitive returned %08x\n", hr
);
454 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, D3DFOG_LINEAR
);
455 ok( hr
== D3D_OK
, "Setting fog table mode to D3DFOG_LINEAR returned %08x\n", hr
);
456 /* Transformed, table fog != none, vertex anything: Use Z value as input to the fog
459 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
,
460 transformed_2
, 4, Indices
, 6, 0);
461 ok(hr
== D3D_OK
, "DrawIndexedPrimitive returned %08x\n", hr
);
463 hr
= IDirect3DDevice7_EndScene(device
);
464 ok(hr
== D3D_OK
, "EndScene returned %08x\n", hr
);
468 ok(FALSE
, "BeginScene failed\n");
471 color
= getPixelColor(device
, 160, 360);
472 ok(color
== 0x00FF0000, "Untransformed vertex with no table or vertex fog has color %08x\n", color
);
473 color
= getPixelColor(device
, 160, 120);
474 ok(color
== 0x0000FF00, "Untransformed vertex with linear vertex fog has color %08x\n", color
);
475 color
= getPixelColor(device
, 480, 120);
476 ok(color
== 0x00FFFF00, "Transformed vertex with linear vertex fog has color %08x\n", color
);
477 if(caps
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_FOGTABLE
)
479 color
= getPixelColor(device
, 480, 360);
480 ok(color
== 0x0000FF00, "Transformed vertex with linear table fog has color %08x\n", color
);
484 /* Without fog table support the vertex fog is still applied, even though table fog is turned on.
485 * The settings above result in no fogging with vertex fog
487 color
= getPixelColor(device
, 480, 120);
488 ok(color
== 0x00FFFF00, "Transformed vertex with linear vertex fog has color %08x\n", color
);
489 trace("Info: Table fog not supported by this device\n");
492 /* Turn off the fog master switch to avoid confusing other tests */
493 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
494 ok(hr
== D3D_OK
, "Turning off fog calculations returned %08x\n", hr
);
497 static void offscreen_test(IDirect3DDevice7
*device
)
500 IDirectDrawSurface7
*backbuffer
= NULL
, *offscreen
= NULL
;
504 static const float quad
[][5] = {
505 {-0.5f
, -0.5f
, 0.1f
, 0.0f
, 0.0f
},
506 {-0.5f
, 0.5f
, 0.1f
, 0.0f
, 1.0f
},
507 { 0.5f
, -0.5f
, 0.1f
, 1.0f
, 0.0f
},
508 { 0.5f
, 0.5f
, 0.1f
, 1.0f
, 1.0f
},
511 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
512 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
514 memset(&ddsd
, 0, sizeof(ddsd
));
515 ddsd
.dwSize
= sizeof(ddsd
);
516 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
517 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
520 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_3DDEVICE
;
521 hr
= IDirectDraw7_CreateSurface(DirectDraw
, &ddsd
, &offscreen
, NULL
);
522 ok(hr
== D3D_OK
, "Creating the offscreen render target failed, hr = %08x\n", hr
);
527 hr
= IDirect3DDevice7_GetRenderTarget(device
, &backbuffer
);
528 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %08x\n", hr
);
533 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
534 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
535 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
536 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
537 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_MINFILTER
, D3DFILTER_NEAREST
);
538 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MINFILTER failed (0x%08x)\n", hr
);
539 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_MAGFILTER
, D3DFILTER_NEAREST
);
540 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr
);
541 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
542 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned hr = %08x\n", hr
);
544 if(IDirect3DDevice7_BeginScene(device
) == D3D_OK
) {
545 hr
= IDirect3DDevice7_SetRenderTarget(device
, offscreen
, 0);
546 ok(hr
== D3D_OK
, "SetRenderTarget failed, hr = %08x\n", hr
);
547 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
548 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
550 /* Draw without textures - Should resut in a white quad */
551 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEX1
, quad
, 4, 0);
552 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
554 hr
= IDirect3DDevice7_SetRenderTarget(device
, backbuffer
, 0);
555 ok(hr
== D3D_OK
, "SetRenderTarget failed, hr = %08x\n", hr
);
556 hr
= IDirect3DDevice7_SetTexture(device
, 0, offscreen
);
557 ok(hr
== D3D_OK
, "SetTexture failed, %08x\n", hr
);
559 /* This time with the texture */
560 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEX1
, quad
, 4, 0);
561 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
563 IDirect3DDevice7_EndScene(device
);
566 /* Center quad - should be white */
567 color
= getPixelColor(device
, 320, 240);
568 ok(color
== 0x00ffffff, "Offscreen failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
569 /* Some quad in the cleared part of the texture */
570 color
= getPixelColor(device
, 170, 240);
571 ok(color
== 0x00ff00ff, "Offscreen failed: Got color 0x%08x, expected 0x00ff00ff.\n", color
);
572 /* Part of the originally cleared back buffer */
573 color
= getPixelColor(device
, 10, 10);
574 ok(color
== 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
576 /* Lower left corner of the screen, where back buffer offscreen rendering draws the offscreen texture.
577 * It should be red, but the offscreen texture may leave some junk there. Not tested yet. Depending on
578 * the offscreen rendering mode this test would succeed or fail
580 color
= getPixelColor(device
, 10, 470);
581 ok(color
== 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
585 hr
= IDirect3DDevice7_SetTexture(device
, 0, NULL
);
589 hr
= IDirect3DDevice7_SetRenderTarget(device
, backbuffer
, 0);
590 IDirectDrawSurface7_Release(backbuffer
);
593 IDirectDrawSurface7_Release(offscreen
);
597 static void alpha_test(IDirect3DDevice7
*device
)
600 IDirectDrawSurface7
*backbuffer
= NULL
, *offscreen
= NULL
;
601 DWORD color
, red
, green
, blue
;
604 struct vertex quad1
[] =
606 {-1.0f
, -1.0f
, 0.1f
, 0x4000ff00},
607 {-1.0f
, 0.0f
, 0.1f
, 0x4000ff00},
608 { 1.0f
, -1.0f
, 0.1f
, 0x4000ff00},
609 { 1.0f
, 0.0f
, 0.1f
, 0x4000ff00},
611 struct vertex quad2
[] =
613 {-1.0f
, 0.0f
, 0.1f
, 0xc00000ff},
614 {-1.0f
, 1.0f
, 0.1f
, 0xc00000ff},
615 { 1.0f
, 0.0f
, 0.1f
, 0xc00000ff},
616 { 1.0f
, 1.0f
, 0.1f
, 0xc00000ff},
618 static const float composite_quad
[][5] = {
619 { 0.0f
, -1.0f
, 0.1f
, 0.0f
, 1.0f
},
620 { 0.0f
, 1.0f
, 0.1f
, 0.0f
, 0.0f
},
621 { 1.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
},
622 { 1.0f
, 1.0f
, 0.1f
, 1.0f
, 0.0f
},
625 /* Clear the render target with alpha = 0.5 */
626 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x80ff0000, 0.0, 0);
627 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
629 memset(&ddsd
, 0, sizeof(ddsd
));
630 ddsd
.dwSize
= sizeof(ddsd
);
631 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
634 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_3DDEVICE
;
635 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
636 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
637 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
638 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
639 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
640 U5(U4(ddsd
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
641 hr
= IDirectDraw7_CreateSurface(DirectDraw
, &ddsd
, &offscreen
, NULL
);
642 ok(hr
== D3D_OK
, "Creating the offscreen render target failed, hr = %08x\n", hr
);
646 hr
= IDirect3DDevice7_GetRenderTarget(device
, &backbuffer
);
647 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %08x\n", hr
);
652 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
653 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
654 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
655 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
656 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_MINFILTER
, D3DFILTER_NEAREST
);
657 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MINFILTER failed (0x%08x)\n", hr
);
658 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_MAGFILTER
, D3DFILTER_NEAREST
);
659 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr
);
661 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
662 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
663 if(IDirect3DDevice7_BeginScene(device
) == D3D_OK
) {
665 /* Draw two quads, one with src alpha blending, one with dest alpha blending. The
666 * SRCALPHA / INVSRCALPHA blend doesn't give any surprises. Colors are blended based on
669 * The DESTALPHA / INVDESTALPHA do not "work" on the regular buffer because there is no alpha.
670 * They give essentially ZERO and ONE blend factors
672 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
673 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
674 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
675 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
676 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad1
, 4, 0);
677 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
679 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_DESTALPHA
);
680 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
681 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVDESTALPHA
);
682 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
683 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad2
, 4, 0);
684 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
686 /* Switch to the offscreen buffer, and redo the testing. SRCALPHA and DESTALPHA. The offscreen buffer
687 * has a alpha channel on its own. Clear the offscreen buffer with alpha = 0.5 again, then draw the
688 * quads again. The SRCALPHA/INVSRCALPHA doesn't give any surprises, but the DESTALPHA/INVDESTALPHA
689 * blending works as supposed now - blend factor is 0.5 in both cases, not 0.75 as from the input
692 hr
= IDirect3DDevice7_SetRenderTarget(device
, offscreen
, 0);
693 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %08x\n", hr
);
694 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x80ff0000, 0.0, 0);
695 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
697 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
698 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
699 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
700 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
701 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad1
, 4, 0);
702 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
704 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_DESTALPHA
);
705 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
706 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVDESTALPHA
);
707 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
708 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad2
, 4, 0);
709 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
711 hr
= IDirect3DDevice7_SetRenderTarget(device
, backbuffer
, 0);
712 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %08x\n", hr
);
714 /* Render the offscreen texture onto the frame buffer to be able to compare it regularly.
715 * Disable alpha blending for the final composition
717 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
);
718 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
720 hr
= IDirect3DDevice7_SetTexture(device
, 0, offscreen
);
721 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetTexture failed, hr = %08x\n", hr
);
722 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEX1
, composite_quad
, 4, 0);
723 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
724 hr
= IDirect3DDevice7_SetTexture(device
, 0, NULL
);
725 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetTexture failed, hr = %08x\n", hr
);
727 hr
= IDirect3DDevice7_EndScene(device
);
728 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndScene failed, hr = %08x\n", hr
);
731 color
= getPixelColor(device
, 160, 360);
732 red
= (color
& 0x00ff0000) >> 16;
733 green
= (color
& 0x0000ff00) >> 8;
734 blue
= (color
& 0x000000ff);
735 ok(red
>= 0xbe && red
<= 0xc0 && green
>= 0x39 && green
<= 0x41 && blue
== 0x00,
736 "SRCALPHA on frame buffer returned color %08x, expected 0x00bf4000\n", color
);
738 color
= getPixelColor(device
, 160, 120);
739 red
= (color
& 0x00ff0000) >> 16;
740 green
= (color
& 0x0000ff00) >> 8;
741 blue
= (color
& 0x000000ff);
742 ok(red
== 0x00 && green
== 0x00 && blue
>= 0xfe && blue
<= 0xff ,
743 "DSTALPHA on frame buffer returned color %08x, expected 0x00ff0000\n", color
);
745 color
= getPixelColor(device
, 480, 360);
746 red
= (color
& 0x00ff0000) >> 16;
747 green
= (color
& 0x0000ff00) >> 8;
748 blue
= (color
& 0x000000ff);
749 ok(red
>= 0xbe && red
<= 0xc0 && green
>= 0x39 && green
<= 0x41 && blue
== 0x00,
750 "SRCALPHA on texture returned color %08x, expected bar\n", color
);
752 color
= getPixelColor(device
, 480, 120);
753 red
= (color
& 0x00ff0000) >> 16;
754 green
= (color
& 0x0000ff00) >> 8;
755 blue
= (color
& 0x000000ff);
756 ok(red
>= 0x7e && red
<= 0x81 && green
== 0x00 && blue
>= 0x7e && blue
<= 0x81,
757 "DSTALPHA on texture returned color %08x, expected foo\n", color
);
760 if(offscreen
) IDirectDrawSurface7_Release(offscreen
);
761 if(backbuffer
) IDirectDrawSurface7_Release(backbuffer
);
770 skip("Cannot initialize DirectDraw and Direct3D, skipping\n");
774 /* Check for the reliability of the returned data */
775 hr
= IDirect3DDevice7_Clear(Direct3DDevice
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
778 trace("Clear failed, can't assure correctness of the test results, skipping\n");
782 color
= getPixelColor(Direct3DDevice
, 1, 1);
783 if(color
!=0x00ff0000)
785 trace("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests, skipping\n", color
);
789 hr
= IDirect3DDevice7_Clear(Direct3DDevice
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ddee, 0.0, 0);
792 trace("Clear failed, can't assure correctness of the test results, skipping\n");
796 color
= getPixelColor(Direct3DDevice
, 639, 479);
797 if(color
!= 0x0000ddee)
799 trace("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests, skipping\n", color
);
803 /* Now run the tests */
804 lighting_test(Direct3DDevice
);
805 clear_test(Direct3DDevice
);
806 fog_test(Direct3DDevice
);
807 offscreen_test(Direct3DDevice
);
808 alpha_test(Direct3DDevice
);