2 * Copyright (C) 2005 Henri Verbeet
3 * Copyright (C) 2007 Stefan Dösinger(for CodeWeavers)
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 */
24 #include "wine/test.h"
26 static HMODULE d3d8_handle
= 0;
28 static HWND
create_window(void)
32 wc
.lpfnWndProc
= DefWindowProc
;
33 wc
.lpszClassName
= "d3d8_test_wc";
36 ret
= CreateWindow("d3d8_test_wc", "d3d8_test",
37 WS_POPUP
| WS_SYSMENU
, 20, 20, 640, 480, 0, 0, 0, 0);
38 ShowWindow(ret
, SW_SHOW
);
42 static BOOL
color_match(D3DCOLOR c1
, D3DCOLOR c2
, BYTE max_diff
)
44 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
46 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
48 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
50 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
54 static DWORD
getPixelColor(IDirect3DDevice8
*device
, UINT x
, UINT y
)
57 IDirect3DTexture8
*tex
= NULL
;
58 IDirect3DSurface8
*surf
= NULL
, *backbuf
= NULL
;
60 D3DLOCKED_RECT lockedRect
;
61 RECT rectToLock
= {x
, y
, x
+1, y
+1};
63 hr
= IDirect3DDevice8_CreateTexture(device
, 640, 480, 1 /* Levels */, 0, D3DFMT_A8R8G8B8
, D3DPOOL_SYSTEMMEM
, &tex
);
64 if(FAILED(hr
) || !tex
) /* This is not a test */
66 trace("Can't create an offscreen plain surface to read the render target data, hr=%#08x\n", hr
);
69 hr
= IDirect3DTexture8_GetSurfaceLevel(tex
, 0, &surf
);
70 if(FAILED(hr
) || !tex
) /* This is not a test */
72 trace("Can't get surface from texture, hr=%#08x\n", hr
);
77 hr
= IDirect3DDevice8_GetRenderTarget(device
, &backbuf
);
80 trace("Can't get the render target, hr=%#08x\n", hr
);
84 hr
= IDirect3DDevice8_CopyRects(device
, backbuf
, NULL
, 0, surf
, NULL
);
87 trace("Can't read the render target, hr=%#08x\n", hr
);
92 hr
= IDirect3DSurface8_LockRect(surf
, &lockedRect
, &rectToLock
, D3DLOCK_READONLY
);
95 trace("Can't lock the offscreen surface, hr=%#08x\n", hr
);
99 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
100 * really important for these tests
102 ret
= ((DWORD
*) lockedRect
.pBits
)[0] & 0x00ffffff;
103 hr
= IDirect3DSurface8_UnlockRect(surf
);
106 trace("Can't unlock the offscreen surface, hr=%#08x\n", hr
);
110 if(backbuf
) IDirect3DSurface8_Release(backbuf
);
111 if(surf
) IDirect3DSurface8_Release(surf
);
112 if(tex
) IDirect3DTexture8_Release(tex
);
116 static IDirect3DDevice8
*init_d3d8(void)
118 IDirect3D8
* (__stdcall
* d3d8_create
)(UINT SDKVersion
) = 0;
119 IDirect3D8
*d3d8_ptr
= 0;
120 IDirect3DDevice8
*device_ptr
= 0;
121 D3DPRESENT_PARAMETERS present_parameters
;
124 d3d8_create
= (void *)GetProcAddress(d3d8_handle
, "Direct3DCreate8");
125 ok(d3d8_create
!= NULL
, "Failed to get address of Direct3DCreate8\n");
126 if (!d3d8_create
) return NULL
;
128 d3d8_ptr
= d3d8_create(D3D_SDK_VERSION
);
131 skip("could not create D3D8\n");
135 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
136 present_parameters
.Windowed
= TRUE
;
137 present_parameters
.hDeviceWindow
= create_window();
138 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
139 present_parameters
.BackBufferWidth
= 640;
140 present_parameters
.BackBufferHeight
= 480;
141 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
142 present_parameters
.EnableAutoDepthStencil
= TRUE
;
143 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D16
;
145 hr
= IDirect3D8_CreateDevice(d3d8_ptr
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, present_parameters
.hDeviceWindow
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device_ptr
);
146 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
|| broken(hr
== D3DERR_NOTAVAILABLE
), "IDirect3D_CreateDevice returned: %#08x\n", hr
);
170 static void lighting_test(IDirect3DDevice8
*device
)
173 DWORD fvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
174 DWORD nfvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_NORMAL
;
177 float mat
[16] = { 1.0f
, 0.0f
, 0.0f
, 0.0f
,
178 0.0f
, 1.0f
, 0.0f
, 0.0f
,
179 0.0f
, 0.0f
, 1.0f
, 0.0f
,
180 0.0f
, 0.0f
, 0.0f
, 1.0f
};
182 struct vertex unlitquad
[] =
184 {-1.0f
, -1.0f
, 0.1f
, 0xffff0000},
185 {-1.0f
, 0.0f
, 0.1f
, 0xffff0000},
186 { 0.0f
, 0.0f
, 0.1f
, 0xffff0000},
187 { 0.0f
, -1.0f
, 0.1f
, 0xffff0000},
189 struct vertex litquad
[] =
191 {-1.0f
, 0.0f
, 0.1f
, 0xff00ff00},
192 {-1.0f
, 1.0f
, 0.1f
, 0xff00ff00},
193 { 0.0f
, 1.0f
, 0.1f
, 0xff00ff00},
194 { 0.0f
, 0.0f
, 0.1f
, 0xff00ff00},
196 struct nvertex unlitnquad
[] =
198 { 0.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
199 { 0.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
200 { 1.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
201 { 1.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
203 struct nvertex litnquad
[] =
205 { 0.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
206 { 0.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
207 { 1.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
208 { 1.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
210 WORD Indices
[] = {0, 1, 2, 2, 3, 0};
212 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
213 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed with %#08x\n", hr
);
215 /* Setup some states that may cause issues */
216 hr
= IDirect3DDevice8_SetTransform(device
, D3DTS_WORLDMATRIX(0), (D3DMATRIX
*) mat
);
217 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTransform returned %#08x\n", hr
);
218 hr
= IDirect3DDevice8_SetTransform(device
, D3DTS_VIEW
, (D3DMATRIX
*)mat
);
219 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTransform returned %#08x\n", hr
);
220 hr
= IDirect3DDevice8_SetTransform(device
, D3DTS_PROJECTION
, (D3DMATRIX
*) mat
);
221 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTransform returned %#08x\n", hr
);
222 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_CLIPPING
, FALSE
);
223 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
224 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
225 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
226 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGENABLE
, FALSE
);
227 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
228 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_STENCILENABLE
, FALSE
);
229 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
230 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ALPHATESTENABLE
, FALSE
);
231 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
232 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, FALSE
);
233 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
234 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_CULLMODE
, D3DCULL_NONE
);
235 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed with %#08x\n", hr
);
236 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_COLORWRITEENABLE
, D3DCOLORWRITEENABLE_RED
| D3DCOLORWRITEENABLE_GREEN
| D3DCOLORWRITEENABLE_BLUE
);
237 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed with %#08x\n", hr
);
239 hr
= IDirect3DDevice8_SetVertexShader(device
, fvf
);
240 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
242 hr
= IDirect3DDevice8_BeginScene(device
);
243 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr
);
246 /* No lights are defined... That means, lit vertices should be entirely black */
247 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
248 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
249 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
250 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, unlitquad
, sizeof(unlitquad
[0]));
251 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr
);
253 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, TRUE
);
254 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
255 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
256 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, litquad
, sizeof(litquad
[0]));
257 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr
);
259 hr
= IDirect3DDevice8_SetVertexShader(device
, nfvf
);
260 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader failed with %#08x\n", hr
);
262 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
263 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
264 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
265 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, unlitnquad
, sizeof(unlitnquad
[0]));
266 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr
);
268 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, TRUE
);
269 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
270 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
271 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, litnquad
, sizeof(litnquad
[0]));
272 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr
);
274 IDirect3DDevice8_EndScene(device
);
275 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed with %#08x\n", hr
);
278 color
= getPixelColor(device
, 160, 360); /* lower left quad - unlit without normals */
279 ok(color
== 0x00ff0000, "Unlit quad without normals has color %08x\n", color
);
280 color
= getPixelColor(device
, 160, 120); /* upper left quad - lit without normals */
281 ok(color
== 0x00000000, "Lit quad without normals has color %08x\n", color
);
282 color
= getPixelColor(device
, 480, 360); /* lower left quad - unlit width normals */
283 ok(color
== 0x000000ff, "Unlit quad width normals has color %08x\n", color
);
284 color
= getPixelColor(device
, 480, 120); /* upper left quad - lit width normals */
285 ok(color
== 0x00000000, "Lit quad width normals has color %08x\n", color
);
287 IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
289 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
290 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
293 static void clear_test(IDirect3DDevice8
*device
)
295 /* Tests the correctness of clearing parameters */
301 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
302 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed with %#08x\n", hr
);
304 /* Positive x, negative y */
310 /* Positive x, positive y */
315 /* Clear 2 rectangles with one call. Shows that a positive value is returned, but the negative rectangle
316 * is ignored, the positive is still cleared afterwards
318 hr
= IDirect3DDevice8_Clear(device
, 2, rect
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
319 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed with %#08x\n", hr
);
321 /* negative x, negative y */
322 rect_negneg
.x1
= 640;
323 rect_negneg
.y1
= 240;
324 rect_negneg
.x2
= 320;
326 hr
= IDirect3DDevice8_Clear(device
, 1, &rect_negneg
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0, 0);
327 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed with %#08x\n", hr
);
329 color
= getPixelColor(device
, 160, 360); /* lower left quad */
330 ok(color
== 0x00ffffff, "Clear rectangle 3(pos, neg) has color %08x\n", color
);
331 color
= getPixelColor(device
, 160, 120); /* upper left quad */
332 ok(color
== 0x00ff0000, "Clear rectangle 1(pos, pos) has color %08x\n", color
);
333 color
= getPixelColor(device
, 480, 360); /* lower right quad */
334 ok(color
== 0x00ffffff, "Clear rectangle 4(NULL) has color %08x\n", color
);
335 color
= getPixelColor(device
, 480, 120); /* upper right quad */
336 ok(color
== 0x00ffffff, "Clear rectangle 4(neg, neg) has color %08x\n", color
);
338 IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
353 static void fog_test(IDirect3DDevice8
*device
)
357 float start
= 0.0, end
= 1.0;
359 /* Gets full z based fog with linear fog, no fog with specular color */
360 struct sVertex unstransformed_1
[] = {
361 {-1, -1, 0.1f
, 0xFFFF0000, 0xFF000000 },
362 {-1, 0, 0.1f
, 0xFFFF0000, 0xFF000000 },
363 { 0, 0, 0.1f
, 0xFFFF0000, 0xFF000000 },
364 { 0, -1, 0.1f
, 0xFFFF0000, 0xFF000000 },
366 /* Ok, I am too lazy to deal with transform matrices */
367 struct sVertex unstransformed_2
[] = {
368 {-1, 0, 1.0f
, 0xFFFF0000, 0xFF000000 },
369 {-1, 1, 1.0f
, 0xFFFF0000, 0xFF000000 },
370 { 0, 1, 1.0f
, 0xFFFF0000, 0xFF000000 },
371 { 0, 0, 1.0f
, 0xFFFF0000, 0xFF000000 },
373 /* Untransformed ones. Give them a different diffuse color to make the test look
374 * nicer. It also makes making sure that they are drawn correctly easier.
376 struct sVertexT transformed_1
[] = {
377 {320, 0, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
378 {640, 0, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
379 {640, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
380 {320, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
382 struct sVertexT transformed_2
[] = {
383 {320, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
384 {640, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
385 {640, 480, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
386 {320, 480, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
388 WORD Indices
[] = {0, 1, 2, 2, 3, 0};
390 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
391 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear returned %#08x\n", hr
);
393 /* Setup initial states: No lighting, fog on, fog color */
394 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
395 ok(hr
== D3D_OK
, "Turning off lighting returned %#08x\n", hr
);
396 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGENABLE
, TRUE
);
397 ok(hr
== D3D_OK
, "Turning on fog calculations returned %#08x\n", hr
);
398 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGCOLOR
, 0xFF00FF00 /* A nice green */);
399 ok(hr
== D3D_OK
, "Turning on fog calculations returned %#08x\n", hr
);
401 /* First test: Both table fog and vertex fog off */
402 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGTABLEMODE
, D3DFOG_NONE
);
403 ok(hr
== D3D_OK
, "Turning off table fog returned %#08x\n", hr
);
404 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, D3DFOG_NONE
);
405 ok(hr
== D3D_OK
, "Turning off table fog returned %#08x\n", hr
);
407 /* Start = 0, end = 1. Should be default, but set them */
408 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGSTART
, *((DWORD
*) &start
));
409 ok(hr
== D3D_OK
, "Setting fog start returned %#08x\n", hr
);
410 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGEND
, *((DWORD
*) &end
));
411 ok(hr
== D3D_OK
, "Setting fog start returned %#08x\n", hr
);
413 if(IDirect3DDevice8_BeginScene(device
) == D3D_OK
)
415 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
);
416 ok( hr
== D3D_OK
, "SetVertexShader returned %#08x\n", hr
);
417 /* Untransformed, vertex fog = NONE, table fog = NONE: Read the fog weighting from the specular color */
418 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
419 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, unstransformed_1
,
420 sizeof(unstransformed_1
[0]));
421 ok(hr
== D3D_OK
, "DrawIndexedPrimitiveUP returned %#08x\n", hr
);
423 /* That makes it use the Z value */
424 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, D3DFOG_LINEAR
);
425 ok(hr
== D3D_OK
, "Turning off table fog returned %#08x\n", hr
);
426 /* Untransformed, vertex fog != none (or table fog != none):
427 * Use the Z value as input into the equation
429 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
430 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, unstransformed_2
,
431 sizeof(unstransformed_1
[0]));
432 ok(hr
== D3D_OK
, "DrawIndexedPrimitiveUP returned %#08x\n", hr
);
434 /* transformed verts */
435 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
);
436 ok( hr
== D3D_OK
, "SetVertexShader returned %#08x\n", hr
);
437 /* Transformed, vertex fog != NONE, pixel fog == NONE: Use specular color alpha component */
438 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
439 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, transformed_1
,
440 sizeof(transformed_1
[0]));
441 ok(hr
== D3D_OK
, "DrawIndexedPrimitiveUP returned %#08x\n", hr
);
443 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGTABLEMODE
, D3DFOG_LINEAR
);
444 ok( hr
== D3D_OK
, "Setting fog table mode to D3DFOG_LINEAR returned %#08x\n", hr
);
445 /* Transformed, table fog != none, vertex anything: Use Z value as input to the fog
448 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
449 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, transformed_2
,
450 sizeof(transformed_2
[0]));
451 ok(SUCCEEDED(hr
), "IDirect3DDevice8_DrawIndexedPrimitiveUP returned %#x.\n", hr
);
453 hr
= IDirect3DDevice8_EndScene(device
);
454 ok(hr
== D3D_OK
, "EndScene returned %#08x\n", hr
);
458 ok(FALSE
, "BeginScene failed\n");
461 color
= getPixelColor(device
, 160, 360);
462 ok(color
== 0x00FF0000, "Untransformed vertex with no table or vertex fog has color %08x\n", color
);
463 color
= getPixelColor(device
, 160, 120);
464 ok(color
== 0x0000FF00, "Untransformed vertex with linear vertex fog has color %08x\n", color
);
465 color
= getPixelColor(device
, 480, 120);
466 ok(color
== 0x00FFFF00, "Transformed vertex with linear vertex fog has color %08x\n", color
);
467 color
= getPixelColor(device
, 480, 360);
468 ok(color
== 0x0000FF00, "Transformed vertex with linear table fog has color %08x\n", color
);
470 IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
472 /* Turn off the fog master switch to avoid confusing other tests */
473 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGENABLE
, FALSE
);
474 ok(hr
== D3D_OK
, "Turning off fog calculations returned %#08x\n", hr
);
477 static void present_test(IDirect3DDevice8
*device
)
479 struct vertex quad
[] =
481 {-1.0f
, -1.0f
, 0.9f
, 0xffff0000},
482 {-1.0f
, 1.0f
, 0.9f
, 0xffff0000},
483 { 1.0f
, -1.0f
, 0.1f
, 0xffff0000},
484 { 1.0f
, 1.0f
, 0.1f
, 0xffff0000},
489 /* Does the Present clear the depth stencil? Clear the depth buffer with some value != 0,
490 * then call Present. Then clear the color buffer to make sure it has some defined content
491 * after the Present with D3DSWAPEFFECT_DISCARD. After that draw a plane that is somewhere cut
492 * by the depth value.
494 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffffff, 0.75, 0);
495 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear returned %08x\n", hr
);
496 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
497 ok(SUCCEEDED(hr
), "IDirect3DDevice8_Present returned %#x.\n", hr
);
498 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.4, 0);
499 ok(SUCCEEDED(hr
), "IDirect3DDevice8_Clear returned %#x.\n", hr
);
501 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_TRUE
);
502 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %08x\n", hr
);
503 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_GREATER
);
504 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %08x\n", hr
);
505 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
506 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetFVF returned %08x\n", hr
);
508 hr
= IDirect3DDevice8_BeginScene(device
);
509 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed with %08x\n", hr
);
512 /* No lights are defined... That means, lit vertices should be entirely black */
513 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2 /*PrimCount */, quad
, sizeof(quad
[0]));
514 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %08x\n", hr
);
516 hr
= IDirect3DDevice8_EndScene(device
);
517 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed with %08x\n", hr
);
520 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_FALSE
);
521 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %08x\n", hr
);
523 color
= getPixelColor(device
, 512, 240);
524 ok(color
== 0x00ffffff, "Present failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
525 color
= getPixelColor(device
, 64, 240);
526 ok(color
== 0x00ff0000, "Present failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
528 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
529 ok(SUCCEEDED(hr
), "Present failed (%#08x)\n", hr
);
532 static void test_rcp_rsq(IDirect3DDevice8
*device
)
537 float constant
[4] = {1.0, 1.0, 1.0, 2.0};
539 static const float quad
[][3] = {
540 {-1.0f
, -1.0f
, 0.0f
},
542 { 1.0f
, -1.0f
, 0.0f
},
546 const DWORD rcp_test
[] = {
547 0xfffe0101, /* vs.1.1 */
549 0x0009fffe, 0x30303030, 0x30303030, /* Shaders have to have a minimal size. */
550 0x30303030, 0x30303030, 0x30303030, /* Add a filler comment. Usually D3DX8's*/
551 0x30303030, 0x30303030, 0x30303030, /* version comment makes the shader big */
552 0x00303030, /* enough to make windows happy */
554 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
555 0x00000006, 0xd00f0000, 0xa0e40000, /* rcp oD0, c0 */
559 const DWORD rsq_test
[] = {
560 0xfffe0101, /* vs.1.1 */
562 0x0009fffe, 0x30303030, 0x30303030, /* Shaders have to have a minimal size. */
563 0x30303030, 0x30303030, 0x30303030, /* Add a filler comment. Usually D3DX8's*/
564 0x30303030, 0x30303030, 0x30303030, /* version comment makes the shader big */
565 0x00303030, /* enough to make windows happy */
567 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
568 0x00000007, 0xd00f0000, 0xa0e40000, /* rsq oD0, c0 */
575 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
579 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff336699, 0.0f
, 0);
580 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed with %#08x\n", hr
);
582 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, rcp_test
, &shader
, 0);
583 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned with %#08x\n", hr
);
585 IDirect3DDevice8_SetVertexShader(device
, shader
);
586 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
587 IDirect3DDevice8_SetVertexShaderConstant(device
, 0, constant
, 1);
589 hr
= IDirect3DDevice8_BeginScene(device
);
590 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene returned %#08x\n", hr
);
593 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad
[0], 3 * sizeof(float));
594 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%#08x)\n", hr
);
595 hr
= IDirect3DDevice8_EndScene(device
);
596 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
599 color
= getPixelColor(device
, 320, 240);
600 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x80, 0x80, 0x80), 4),
601 "RCP test returned color 0x%08x, expected 0x00808080.\n", color
);
603 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
604 ok(SUCCEEDED(hr
), "Present failed (%#08x)\n", hr
);
606 IDirect3DDevice8_SetVertexShader(device
, 0);
607 IDirect3DDevice8_DeleteVertexShader(device
, shader
);
609 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff996633, 0.0f
, 0);
610 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed with %#08x\n", hr
);
612 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, rsq_test
, &shader
, 0);
613 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned with %#08x\n", hr
);
615 IDirect3DDevice8_SetVertexShader(device
, shader
);
616 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
617 IDirect3DDevice8_SetVertexShaderConstant(device
, 0, constant
, 1);
619 hr
= IDirect3DDevice8_BeginScene(device
);
620 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene returned %#08x\n", hr
);
623 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad
[0], 3 * sizeof(float));
624 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%#08x)\n", hr
);
625 hr
= IDirect3DDevice8_EndScene(device
);
626 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
629 color
= getPixelColor(device
, 320, 240);
630 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0xb4, 0xb4, 0xb4), 4),
631 "RSQ test returned color 0x%08x, expected 0x00b4b4b4.\n", color
);
633 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
634 ok(SUCCEEDED(hr
), "Present failed (%#08x)\n", hr
);
636 IDirect3DDevice8_SetVertexShader(device
, 0);
637 IDirect3DDevice8_DeleteVertexShader(device
, shader
);
640 static void offscreen_test(IDirect3DDevice8
*device
)
643 IDirect3DTexture8
*offscreenTexture
= NULL
;
644 IDirect3DSurface8
*backbuffer
= NULL
, *offscreen
= NULL
, *depthstencil
= NULL
;
647 static const float quad
[][5] = {
648 {-0.5f
, -0.5f
, 0.1f
, 0.0f
, 0.0f
},
649 {-0.5f
, 0.5f
, 0.1f
, 0.0f
, 1.0f
},
650 { 0.5f
, -0.5f
, 0.1f
, 1.0f
, 0.0f
},
651 { 0.5f
, 0.5f
, 0.1f
, 1.0f
, 1.0f
},
654 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &depthstencil
);
655 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetDepthStencilSurface failed, hr = %#08x\n", hr
);
657 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
658 ok(hr
== D3D_OK
, "Clear failed, hr = %#08x\n", hr
);
660 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &offscreenTexture
);
661 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "Creating the offscreen render target failed, hr = %#08x\n", hr
);
662 if(!offscreenTexture
) {
663 trace("Failed to create an X8R8G8B8 offscreen texture, trying R5G6B5\n");
664 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
, D3DFMT_R5G6B5
, D3DPOOL_DEFAULT
, &offscreenTexture
);
665 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "Creating the offscreen render target failed, hr = %#08x\n", hr
);
666 if(!offscreenTexture
) {
667 skip("Cannot create an offscreen render target\n");
672 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
673 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %#08x\n", hr
);
678 hr
= IDirect3DTexture8_GetSurfaceLevel(offscreenTexture
, 0, &offscreen
);
679 ok(hr
== D3D_OK
, "Can't get offscreen surface, hr = %#08x\n", hr
);
684 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
685 ok(hr
== D3D_OK
, "SetVertexShader failed, hr = %#08x\n", hr
);
687 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
688 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %#08x\n", hr
);
689 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
690 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %#08x\n", hr
);
691 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_MINFILTER
, D3DTEXF_NONE
);
692 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MINFILTER failed (%#08x)\n", hr
);
693 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_MAGFILTER
, D3DTEXF_NONE
);
694 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MAGFILTER failed (%#08x)\n", hr
);
695 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
696 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %08x\n", hr
);
698 if(IDirect3DDevice8_BeginScene(device
) == D3D_OK
) {
699 hr
= IDirect3DDevice8_SetRenderTarget(device
, offscreen
, depthstencil
);
700 ok(hr
== D3D_OK
, "SetRenderTarget failed, hr = %#08x\n", hr
);
701 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
702 ok(hr
== D3D_OK
, "Clear failed, hr = %#08x\n", hr
);
704 /* Draw without textures - Should result in a white quad */
705 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(quad
[0]));
706 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
708 hr
= IDirect3DDevice8_SetRenderTarget(device
, backbuffer
, depthstencil
);
709 ok(hr
== D3D_OK
, "SetRenderTarget failed, hr = %#08x\n", hr
);
710 hr
= IDirect3DDevice8_SetTexture(device
, 0, (IDirect3DBaseTexture8
*) offscreenTexture
);
711 ok(hr
== D3D_OK
, "SetTexture failed, %08x\n", hr
);
713 /* This time with the texture */
714 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(quad
[0]));
715 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
717 IDirect3DDevice8_EndScene(device
);
720 /* Center quad - should be white */
721 color
= getPixelColor(device
, 320, 240);
722 ok(color
== 0x00ffffff, "Offscreen failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
723 /* Some quad in the cleared part of the texture */
724 color
= getPixelColor(device
, 170, 240);
725 ok(color
== 0x00ff00ff, "Offscreen failed: Got color 0x%08x, expected 0x00ff00ff.\n", color
);
726 /* Part of the originally cleared back buffer */
727 color
= getPixelColor(device
, 10, 10);
728 ok(color
== 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
730 /* Lower left corner of the screen, where back buffer offscreen rendering draws the offscreen texture.
731 * It should be red, but the offscreen texture may leave some junk there. Not tested yet. Depending on
732 * the offscreen rendering mode this test would succeed or fail
734 color
= getPixelColor(device
, 10, 470);
735 ok(color
== 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
738 IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
741 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
742 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetTexture returned %#x.\n", hr
);
746 hr
= IDirect3DDevice8_SetRenderTarget(device
, backbuffer
, depthstencil
);
747 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetRenderTarget returned %#x.\n", hr
);
748 IDirect3DSurface8_Release(backbuffer
);
750 if(offscreenTexture
) {
751 IDirect3DTexture8_Release(offscreenTexture
);
754 IDirect3DSurface8_Release(offscreen
);
757 IDirect3DSurface8_Release(depthstencil
);
761 static void alpha_test(IDirect3DDevice8
*device
)
764 IDirect3DTexture8
*offscreenTexture
;
765 IDirect3DSurface8
*backbuffer
= NULL
, *offscreen
= NULL
, *depthstencil
= NULL
;
768 struct vertex quad1
[] =
770 {-1.0f
, -1.0f
, 0.1f
, 0x4000ff00},
771 {-1.0f
, 0.0f
, 0.1f
, 0x4000ff00},
772 { 1.0f
, -1.0f
, 0.1f
, 0x4000ff00},
773 { 1.0f
, 0.0f
, 0.1f
, 0x4000ff00},
775 struct vertex quad2
[] =
777 {-1.0f
, 0.0f
, 0.1f
, 0xc00000ff},
778 {-1.0f
, 1.0f
, 0.1f
, 0xc00000ff},
779 { 1.0f
, 0.0f
, 0.1f
, 0xc00000ff},
780 { 1.0f
, 1.0f
, 0.1f
, 0xc00000ff},
782 static const float composite_quad
[][5] = {
783 { 0.0f
, -1.0f
, 0.1f
, 0.0f
, 1.0f
},
784 { 0.0f
, 1.0f
, 0.1f
, 0.0f
, 0.0f
},
785 { 1.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
},
786 { 1.0f
, 1.0f
, 0.1f
, 1.0f
, 0.0f
},
789 /* Clear the render target with alpha = 0.5 */
790 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x80ff0000, 0.0, 0);
791 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
793 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &offscreenTexture
);
794 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "Creating the offscreen render target failed, hr = %#08x\n", hr
);
796 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &depthstencil
);
797 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetDepthStencilSurface failed, hr = %#08x\n", hr
);
799 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
800 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %#08x\n", hr
);
804 hr
= IDirect3DTexture8_GetSurfaceLevel(offscreenTexture
, 0, &offscreen
);
805 ok(hr
== D3D_OK
, "Can't get offscreen surface, hr = %#08x\n", hr
);
810 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
811 ok(hr
== D3D_OK
, "SetVertexShader failed, hr = %#08x\n", hr
);
813 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
814 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %#08x\n", hr
);
815 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
816 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %#08x\n", hr
);
817 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_MINFILTER
, D3DTEXF_NONE
);
818 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MINFILTER failed (%#08x)\n", hr
);
819 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_MAGFILTER
, D3DTEXF_NONE
);
820 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MAGFILTER failed (%#08x)\n", hr
);
821 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
822 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %08x\n", hr
);
824 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, TRUE
);
825 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
826 if(IDirect3DDevice8_BeginScene(device
) == D3D_OK
) {
828 /* Draw two quads, one with src alpha blending, one with dest alpha blending. */
829 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_SRCALPHA
);
830 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
831 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
832 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
833 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(quad1
[0]));
834 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
836 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_DESTALPHA
);
837 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
838 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVDESTALPHA
);
839 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
840 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(quad2
[0]));
841 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
843 /* Switch to the offscreen buffer, and redo the testing. The offscreen render target
844 * doesn't have an alpha channel. DESTALPHA and INVDESTALPHA "don't work" on render
845 * targets without alpha channel, they give essentially ZERO and ONE blend factors. */
846 hr
= IDirect3DDevice8_SetRenderTarget(device
, offscreen
, 0);
847 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %08x\n", hr
);
848 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x80ff0000, 0.0, 0);
849 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
851 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_SRCALPHA
);
852 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
853 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
854 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
855 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(quad1
[0]));
856 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
858 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_DESTALPHA
);
859 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
860 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVDESTALPHA
);
861 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
862 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(quad2
[0]));
863 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
865 hr
= IDirect3DDevice8_SetRenderTarget(device
, backbuffer
, depthstencil
);
866 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %08x\n", hr
);
868 /* Render the offscreen texture onto the frame buffer to be able to compare it regularly.
869 * Disable alpha blending for the final composition
871 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, FALSE
);
872 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
873 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
874 ok(hr
== D3D_OK
, "SetVertexShader failed, hr = %#08x\n", hr
);
876 hr
= IDirect3DDevice8_SetTexture(device
, 0, (IDirect3DBaseTexture8
*) offscreenTexture
);
877 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr
);
878 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, composite_quad
, sizeof(float) * 5);
879 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
880 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
881 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr
);
883 hr
= IDirect3DDevice8_EndScene(device
);
884 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndScene failed, hr = %08x\n", hr
);
887 color
= getPixelColor(device
, 160, 360);
888 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0xbf, 0x40, 0x00), 1),
889 "SRCALPHA on frame buffer returned color %08x, expected 0x00bf4000\n", color
);
891 color
= getPixelColor(device
, 160, 120);
892 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x7f, 0x00, 0x80), 2),
893 "DSTALPHA on frame buffer returned color %08x, expected 0x007f0080\n", color
);
895 color
= getPixelColor(device
, 480, 360);
896 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0xbf, 0x40, 0x00), 1),
897 "SRCALPHA on texture returned color %08x, expected 0x00bf4000\n", color
);
899 color
= getPixelColor(device
, 480, 120);
900 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0xff), 1),
901 "DSTALPHA on texture returned color %08x, expected 0x000000ff\n", color
);
903 IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
908 IDirect3DSurface8_Release(backbuffer
);
910 if(offscreenTexture
) {
911 IDirect3DTexture8_Release(offscreenTexture
);
914 IDirect3DSurface8_Release(offscreen
);
917 IDirect3DSurface8_Release(depthstencil
);
921 static void p8_texture_test(IDirect3DDevice8
*device
)
923 IDirect3D8
*d3d
= NULL
;
925 IDirect3DTexture8
*texture
= NULL
, *texture2
= NULL
;
928 DWORD color
, red
, green
, blue
;
929 PALETTEENTRY table
[256];
933 -1.0, 0, 0.1, 0.0, 0.0,
934 -1.0, 1.0, 0.1, 0.0, 1.0,
935 1.0, 0, 0.1, 1.0, 0.0,
936 1.0, 1.0, 0.1, 1.0, 1.0,
939 -1.0, -1.0, 0.1, 0.0, 0.0,
940 -1.0, 0, 0.1, 0.0, 1.0,
941 1.0, -1.0, 0.1, 1.0, 0.0,
942 1.0, 0, 0.1, 1.0, 1.0,
945 IDirect3DDevice8_GetDirect3D(device
, &d3d
);
947 if(IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
, 0,
948 D3DRTYPE_TEXTURE
, D3DFMT_P8
) != D3D_OK
) {
949 skip("D3DFMT_P8 textures not supported\n");
953 hr
= IDirect3DDevice8_CreateTexture(device
, 1, 1, 1, 0, D3DFMT_P8
,
954 D3DPOOL_MANAGED
, &texture2
);
955 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateTexture failed, hr = %08x\n", hr
);
957 skip("Failed to create D3DFMT_P8 texture\n");
961 memset(&lr
, 0, sizeof(lr
));
962 hr
= IDirect3DTexture8_LockRect(texture2
, 0, &lr
, NULL
, 0);
963 ok(hr
== D3D_OK
, "IDirect3DTexture8_LockRect failed, hr = %08x\n", hr
);
967 hr
= IDirect3DTexture8_UnlockRect(texture2
, 0);
968 ok(hr
== D3D_OK
, "IDirect3DTexture8_UnlockRect failed, hr = %08x\n", hr
);
970 hr
= IDirect3DDevice8_CreateTexture(device
, 1, 1, 1, 0, D3DFMT_P8
,
971 D3DPOOL_MANAGED
, &texture
);
972 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateTexture failed, hr = %08x\n", hr
);
974 skip("Failed to create D3DFMT_P8 texture\n");
978 memset(&lr
, 0, sizeof(lr
));
979 hr
= IDirect3DTexture8_LockRect(texture
, 0, &lr
, NULL
, 0);
980 ok(hr
== D3D_OK
, "IDirect3DTexture8_LockRect failed, hr = %08x\n", hr
);
984 hr
= IDirect3DTexture8_UnlockRect(texture
, 0);
985 ok(hr
== D3D_OK
, "IDirect3DTexture8_UnlockRect failed, hr = %08x\n", hr
);
987 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff000000, 0.0, 0);
988 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed, hr = %08x\n", hr
);
990 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, TRUE
);
991 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
993 /* The first part of the test should work both with and without D3DPTEXTURECAPS_ALPHAPALETTE;
994 alpha of every entry is set to 1.0, which MS says is required when there's no
995 D3DPTEXTURECAPS_ALPHAPALETTE capability */
996 for (i
= 0; i
< 256; i
++) {
997 table
[i
].peRed
= table
[i
].peGreen
= table
[i
].peBlue
= 0;
998 table
[i
].peFlags
= 0xff;
1000 table
[1].peRed
= 0xff;
1001 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 0, table
);
1002 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr
);
1005 table
[1].peBlue
= 0xff;
1006 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 1, table
);
1007 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr
);
1009 hr
= IDirect3DDevice8_BeginScene(device
);
1010 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed, hr = %08x\n", hr
);
1012 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_SRCALPHA
);
1013 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
1014 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1015 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
1017 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
1018 ok(hr
== D3D_OK
, "SetVertexShader failed, hr = %#08x\n", hr
);
1020 hr
= IDirect3DDevice8_SetCurrentTexturePalette(device
, 0);
1021 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr
);
1023 hr
= IDirect3DDevice8_SetTexture(device
, 0, (IDirect3DBaseTexture8
*) texture2
);
1024 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr
);
1025 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
1026 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr
);
1028 hr
= IDirect3DDevice8_SetTexture(device
, 0, (IDirect3DBaseTexture8
*) texture
);
1029 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr
);
1030 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
1031 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr
);
1033 hr
= IDirect3DDevice8_SetCurrentTexturePalette(device
, 1);
1034 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr
);
1035 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, 5 * sizeof(float));
1036 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr
);
1038 hr
= IDirect3DDevice8_EndScene(device
);
1039 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed, hr = %08x\n", hr
);
1042 color
= getPixelColor(device
, 32, 32);
1043 red
= (color
& 0x00ff0000) >> 16;
1044 green
= (color
& 0x0000ff00) >> 8;
1045 blue
= (color
& 0x000000ff) >> 0;
1046 ok(red
== 0xff && blue
== 0 && green
== 0,
1047 "got color %08x, expected 0x00ff0000\n", color
);
1049 color
= getPixelColor(device
, 32, 320);
1050 red
= (color
& 0x00ff0000) >> 16;
1051 green
= (color
& 0x0000ff00) >> 8;
1052 blue
= (color
& 0x000000ff) >> 0;
1053 ok(red
== 0 && blue
== 0xff && green
== 0,
1054 "got color %08x, expected 0x000000ff\n", color
);
1056 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
1057 ok(hr
== D3D_OK
, "IDirect3DDevice8_Present failed, hr = %08x\n", hr
);
1059 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff000000, 0.0, 0);
1060 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed, hr = %08x\n", hr
);
1062 hr
= IDirect3DDevice8_BeginScene(device
);
1063 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed, hr = %08x\n", hr
);
1065 hr
= IDirect3DDevice8_SetTexture(device
, 0, (IDirect3DBaseTexture8
*) texture2
);
1066 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr
);
1068 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
1069 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr
);
1071 hr
= IDirect3DDevice8_EndScene(device
);
1072 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed, hr = %08x\n", hr
);
1076 color
= getPixelColor(device
, 32, 32);
1077 red
= (color
& 0x00ff0000) >> 16;
1078 green
= (color
& 0x0000ff00) >> 8;
1079 blue
= (color
& 0x000000ff) >> 0;
1080 ok(red
== 0 && blue
== 0xff && green
== 0,
1081 "got color %08x, expected 0x000000ff\n", color
);
1083 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
1084 ok(hr
== D3D_OK
, "IDirect3DDevice8_Present failed, hr = %08x\n", hr
);
1086 /* Test palettes with alpha */
1087 IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
1088 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_ALPHAPALETTE
)) {
1089 skip("no D3DPTEXTURECAPS_ALPHAPALETTE capability, tests with alpha in palette will be skipped\n");
1091 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff000000, 0.0, 0);
1092 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed, hr = %08x\n", hr
);
1094 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, TRUE
);
1095 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
1097 for (i
= 0; i
< 256; i
++) {
1098 table
[i
].peRed
= table
[i
].peGreen
= table
[i
].peBlue
= 0;
1099 table
[i
].peFlags
= 0xff;
1101 table
[1].peRed
= 0xff;
1102 table
[1].peFlags
= 0x80;
1103 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 0, table
);
1104 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr
);
1107 table
[1].peBlue
= 0xff;
1108 table
[1].peFlags
= 0x80;
1109 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 1, table
);
1110 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr
);
1112 hr
= IDirect3DDevice8_BeginScene(device
);
1113 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed, hr = %08x\n", hr
);
1115 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_SRCALPHA
);
1116 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
1117 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1118 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
1120 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
1121 ok(hr
== D3D_OK
, "SetVertexShader failed, hr = %#08x\n", hr
);
1123 hr
= IDirect3DDevice8_SetCurrentTexturePalette(device
, 0);
1124 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr
);
1126 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
1127 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr
);
1129 hr
= IDirect3DDevice8_SetCurrentTexturePalette(device
, 1);
1130 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr
);
1132 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, 5 * sizeof(float));
1133 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr
);
1135 hr
= IDirect3DDevice8_EndScene(device
);
1136 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed, hr = %08x\n", hr
);
1139 color
= getPixelColor(device
, 32, 32);
1140 red
= (color
& 0x00ff0000) >> 16;
1141 green
= (color
& 0x0000ff00) >> 8;
1142 blue
= (color
& 0x000000ff) >> 0;
1143 ok(red
>= 0x7e && red
<= 0x81 && blue
== 0 && green
== 0,
1144 "got color %08x, expected 0x00800000 or near\n", color
);
1146 color
= getPixelColor(device
, 32, 320);
1147 red
= (color
& 0x00ff0000) >> 16;
1148 green
= (color
& 0x0000ff00) >> 8;
1149 blue
= (color
& 0x000000ff) >> 0;
1150 ok(red
== 0 && blue
>= 0x7e && blue
<= 0x81 && green
== 0,
1151 "got color %08x, expected 0x00000080 or near\n", color
);
1153 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
1154 ok(hr
== D3D_OK
, "IDirect3DDevice8_Present failed, hr = %08x\n", hr
);
1157 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
1158 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr
);
1159 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, FALSE
);
1160 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
1163 if(texture
) IDirect3DTexture8_Release(texture
);
1164 if(texture2
) IDirect3DTexture8_Release(texture2
);
1165 IDirect3D8_Release(d3d
);
1168 static void texop_test(IDirect3DDevice8
*device
)
1170 IDirect3DTexture8
*texture
= NULL
;
1171 D3DLOCKED_RECT locked_rect
;
1177 static const struct {
1182 {-1.0f
, -1.0f
, 0.1f
, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), -1.0f
, -1.0f
},
1183 {-1.0f
, 1.0f
, 0.1f
, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), -1.0f
, 1.0f
},
1184 { 1.0f
, -1.0f
, 0.1f
, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), 1.0f
, -1.0f
},
1185 { 1.0f
, 1.0f
, 0.1f
, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), 1.0f
, 1.0f
}
1188 static const struct {
1194 {D3DTOP_SELECTARG1
, "SELECTARG1", D3DTEXOPCAPS_SELECTARG1
, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00)},
1195 {D3DTOP_SELECTARG2
, "SELECTARG2", D3DTEXOPCAPS_SELECTARG2
, D3DCOLOR_ARGB(0x00, 0x33, 0x33, 0x33)},
1196 {D3DTOP_MODULATE
, "MODULATE", D3DTEXOPCAPS_MODULATE
, D3DCOLOR_ARGB(0x00, 0x00, 0x33, 0x00)},
1197 {D3DTOP_MODULATE2X
, "MODULATE2X", D3DTEXOPCAPS_MODULATE2X
, D3DCOLOR_ARGB(0x00, 0x00, 0x66, 0x00)},
1198 {D3DTOP_MODULATE4X
, "MODULATE4X", D3DTEXOPCAPS_MODULATE4X
, D3DCOLOR_ARGB(0x00, 0x00, 0xcc, 0x00)},
1199 {D3DTOP_ADD
, "ADD", D3DTEXOPCAPS_ADD
, D3DCOLOR_ARGB(0x00, 0x33, 0xff, 0x33)},
1201 {D3DTOP_ADDSIGNED
, "ADDSIGNED", D3DTEXOPCAPS_ADDSIGNED
, D3DCOLOR_ARGB(0x00, 0x00, 0xb2, 0x00)},
1202 {D3DTOP_ADDSIGNED2X
, "ADDSIGNED2X", D3DTEXOPCAPS_ADDSIGNED2X
, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00)},
1204 {D3DTOP_SUBTRACT
, "SUBTRACT", D3DTEXOPCAPS_SUBTRACT
, D3DCOLOR_ARGB(0x00, 0x00, 0xcc, 0x00)},
1205 {D3DTOP_ADDSMOOTH
, "ADDSMOOTH", D3DTEXOPCAPS_ADDSMOOTH
, D3DCOLOR_ARGB(0x00, 0x33, 0xff, 0x33)},
1206 {D3DTOP_BLENDDIFFUSEALPHA
, "BLENDDIFFUSEALPHA", D3DTEXOPCAPS_BLENDDIFFUSEALPHA
, D3DCOLOR_ARGB(0x00, 0x22, 0x77, 0x22)},
1207 {D3DTOP_BLENDTEXTUREALPHA
, "BLENDTEXTUREALPHA", D3DTEXOPCAPS_BLENDTEXTUREALPHA
, D3DCOLOR_ARGB(0x00, 0x14, 0xad, 0x14)},
1208 {D3DTOP_BLENDFACTORALPHA
, "BLENDFACTORALPHA", D3DTEXOPCAPS_BLENDFACTORALPHA
, D3DCOLOR_ARGB(0x00, 0x07, 0xe4, 0x07)},
1209 {D3DTOP_BLENDTEXTUREALPHAPM
, "BLENDTEXTUREALPHAPM", D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
, D3DCOLOR_ARGB(0x00, 0x14, 0xff, 0x14)},
1210 {D3DTOP_BLENDCURRENTALPHA
, "BLENDCURRENTALPHA", D3DTEXOPCAPS_BLENDCURRENTALPHA
, D3DCOLOR_ARGB(0x00, 0x22, 0x77, 0x22)},
1211 {D3DTOP_MODULATEALPHA_ADDCOLOR
, "MODULATEALPHA_ADDCOLOR", D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
, D3DCOLOR_ARGB(0x00, 0x1f, 0xff, 0x1f)},
1212 {D3DTOP_MODULATECOLOR_ADDALPHA
, "MODULATECOLOR_ADDALPHA", D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
, D3DCOLOR_ARGB(0x00, 0x99, 0xcc, 0x99)},
1213 {D3DTOP_MODULATEINVALPHA_ADDCOLOR
, "MODULATEINVALPHA_ADDCOLOR", D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
, D3DCOLOR_ARGB(0x00, 0x14, 0xff, 0x14)},
1214 {D3DTOP_MODULATEINVCOLOR_ADDALPHA
, "MODULATEINVCOLOR_ADDALPHA", D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
, D3DCOLOR_ARGB(0x00, 0xcc, 0x99, 0xcc)},
1215 /* BUMPENVMAP & BUMPENVMAPLUMINANCE have their own tests */
1216 {D3DTOP_DOTPRODUCT3
, "DOTPRODUCT2", D3DTEXOPCAPS_DOTPRODUCT3
, D3DCOLOR_ARGB(0x00, 0x99, 0x99, 0x99)},
1217 {D3DTOP_MULTIPLYADD
, "MULTIPLYADD", D3DTEXOPCAPS_MULTIPLYADD
, D3DCOLOR_ARGB(0x00, 0xff, 0x33, 0x00)},
1218 {D3DTOP_LERP
, "LERP", D3DTEXOPCAPS_LERP
, D3DCOLOR_ARGB(0x00, 0x00, 0x33, 0x33)},
1221 memset(&caps
, 0, sizeof(caps
));
1222 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
1223 ok(SUCCEEDED(hr
), "GetDeviceCaps failed with 0x%08x\n", hr
);
1225 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_TEX0
);
1226 ok(SUCCEEDED(hr
), "SetVertexShader failed with 0x%08x\n", hr
);
1228 hr
= IDirect3DDevice8_CreateTexture(device
, 1, 1, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &texture
);
1229 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateTexture failed with 0x%08x\n", hr
);
1230 hr
= IDirect3DTexture8_LockRect(texture
, 0, &locked_rect
, NULL
, 0);
1231 ok(SUCCEEDED(hr
), "LockRect failed with 0x%08x\n", hr
);
1232 *((DWORD
*)locked_rect
.pBits
) = D3DCOLOR_ARGB(0x99, 0x00, 0xff, 0x00);
1233 hr
= IDirect3DTexture8_UnlockRect(texture
, 0);
1234 ok(SUCCEEDED(hr
), "LockRect failed with 0x%08x\n", hr
);
1235 hr
= IDirect3DDevice8_SetTexture(device
, 0, (IDirect3DBaseTexture8
*)texture
);
1236 ok(SUCCEEDED(hr
), "SetTexture failed with 0x%08x\n", hr
);
1238 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLORARG0
, D3DTA_DIFFUSE
);
1239 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
1240 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
1241 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
1242 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_TFACTOR
);
1243 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
1245 hr
= IDirect3DDevice8_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
1246 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
1248 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
1249 ok(SUCCEEDED(hr
), "SetRenderState failed with 0x%08x\n", hr
);
1250 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_TEXTUREFACTOR
, 0xdd333333);
1251 ok(SUCCEEDED(hr
), "SetRenderState failed with 0x%08x\n", hr
);
1252 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_COLORWRITEENABLE
, D3DCOLORWRITEENABLE_RED
| D3DCOLORWRITEENABLE_GREEN
| D3DCOLORWRITEENABLE_BLUE
| D3DCOLORWRITEENABLE_ALPHA
);
1253 ok(SUCCEEDED(hr
), "SetRenderState failed with 0x%08x\n", hr
);
1255 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x00000000, 1.0f
, 0);
1256 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Clear failed with 0x%08x\n", hr
);
1258 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
1260 if (!(caps
.TextureOpCaps
& test_data
[i
].caps_flag
))
1262 skip("tex operation %s not supported\n", test_data
[i
].name
);
1266 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, test_data
[i
].op
);
1267 ok(SUCCEEDED(hr
), "SetTextureStageState (%s) failed with 0x%08x\n", test_data
[i
].name
, hr
);
1269 hr
= IDirect3DDevice8_BeginScene(device
);
1270 ok(SUCCEEDED(hr
), "BeginScene failed with 0x%08x\n", hr
);
1272 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
1273 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed with 0x%08x\n", hr
);
1275 hr
= IDirect3DDevice8_EndScene(device
);
1276 ok(SUCCEEDED(hr
), "EndScene failed with 0x%08x\n", hr
);
1278 color
= getPixelColor(device
, 320, 240);
1279 ok(color_match(color
, test_data
[i
].result
, 3), "Operation %s returned color 0x%08x, expected 0x%08x\n",
1280 test_data
[i
].name
, color
, test_data
[i
].result
);
1282 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
1283 ok(SUCCEEDED(hr
), "Present failed with 0x%08x\n", hr
);
1285 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x00000000, 1.0f
, 0);
1286 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Clear failed with 0x%08x\n", hr
);
1289 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
1290 ok(SUCCEEDED(hr
), "SetTexture failed with 0x%08x\n", hr
);
1291 if (texture
) IDirect3DTexture8_Release(texture
);
1294 /* This test tests depth clamping / clipping behaviour:
1295 * - When D3DRS_CLIPPING is disabled depth values are *clamped* to the
1296 * minimum/maximum z value.
1297 * - The viewport's MinZ/MaxZ is irrelevant for this.
1298 * - When D3DRS_CLIPPING is enabled depth values are clipped.
1299 * - Pretransformed vertices behave the same as regular vertices.
1301 static void depth_clamp_test(IDirect3DDevice8
*device
)
1303 const struct tvertex quad1
[] =
1305 { 0, 0, 5.0f
, 1.0, 0xff002b7f},
1306 { 640, 0, 5.0f
, 1.0, 0xff002b7f},
1307 { 0, 480, 5.0f
, 1.0, 0xff002b7f},
1308 { 640, 480, 5.0f
, 1.0, 0xff002b7f},
1310 const struct tvertex quad2
[] =
1312 { 0, 300, 10.0f
, 1.0, 0xfff9e814},
1313 { 640, 300, 10.0f
, 1.0, 0xfff9e814},
1314 { 0, 360, 10.0f
, 1.0, 0xfff9e814},
1315 { 640, 360, 10.0f
, 1.0, 0xfff9e814},
1317 const struct vertex quad3
[] =
1319 {-0.65, 0.55, 5.0f
, 0xffffffff},
1320 {-0.35, 0.55, 5.0f
, 0xffffffff},
1321 {-0.65, 0.15, 5.0f
, 0xffffffff},
1322 {-0.35, 0.15, 5.0f
, 0xffffffff},
1324 const struct vertex quad4
[] =
1326 {-0.87, 0.83, 10.0f
, 0xffffffff},
1327 {-0.65, 0.83, 10.0f
, 0xffffffff},
1328 {-0.87, 0.55, 10.0f
, 0xffffffff},
1329 {-0.65, 0.55, 10.0f
, 0xffffffff},
1331 const struct vertex quad5
[] =
1333 { -0.5, 0.5, 10.0f
, 0xff14f914},
1334 { 0.5, 0.5, 10.0f
, 0xff14f914},
1335 { -0.5, -0.5, 10.0f
, 0xff14f914},
1336 { 0.5, -0.5, 10.0f
, 0xff14f914},
1338 const struct tvertex quad6
[] =
1340 { 0, 120, 10.0f
, 1.0, 0xfff91414},
1341 { 640, 120, 10.0f
, 1.0, 0xfff91414},
1342 { 0, 180, 10.0f
, 1.0, 0xfff91414},
1343 { 640, 180, 10.0f
, 1.0, 0xfff91414},
1357 hr
= IDirect3DDevice8_SetViewport(device
, &vp
);
1358 ok(SUCCEEDED(hr
), "SetViewport failed, hr %#x.\n", hr
);
1360 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffffff, 1.0, 0);
1361 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
1363 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_CLIPPING
, FALSE
);
1364 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
1365 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
1366 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
1367 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZWRITEENABLE
, TRUE
);
1368 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
1369 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_LESSEQUAL
);
1370 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
1372 hr
= IDirect3DDevice8_BeginScene(device
);
1373 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
1375 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
);
1376 ok(SUCCEEDED(hr
), "SetVertexSahder failed, hr %#x.\n", hr
);
1378 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(*quad1
));
1379 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
1380 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(*quad2
));
1381 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
1383 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
1384 ok(SUCCEEDED(hr
), "SetVertexShader failed, hr %#x.\n", hr
);
1386 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, sizeof(*quad3
));
1387 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
1388 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, sizeof(*quad4
));
1389 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
1391 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_CLIPPING
, TRUE
);
1392 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
1394 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad5
, sizeof(*quad5
));
1395 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
1397 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
);
1398 ok(SUCCEEDED(hr
), "SetVertexShader failed, hr %#x.\n", hr
);
1400 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad6
, sizeof(*quad6
));
1401 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
1403 hr
= IDirect3DDevice8_EndScene(device
);
1404 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
1406 color
= getPixelColor(device
, 75, 75);
1407 ok(color_match(color
, 0x00ffffff, 1), "color 0x%08x.\n", color
);
1408 color
= getPixelColor(device
, 150, 150);
1409 ok(color_match(color
, 0x00ffffff, 1), "color 0x%08x.\n", color
);
1410 color
= getPixelColor(device
, 320, 240);
1411 ok(color_match(color
, 0x00002b7f, 1), "color 0x%08x.\n", color
);
1412 color
= getPixelColor(device
, 320, 330);
1413 ok(color_match(color
, 0x00f9e814, 1), "color 0x%08x.\n", color
);
1414 color
= getPixelColor(device
, 320, 330);
1415 ok(color_match(color
, 0x00f9e814, 1), "color 0x%08x.\n", color
);
1417 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
1418 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
1422 hr
= IDirect3DDevice8_SetViewport(device
, &vp
);
1423 ok(SUCCEEDED(hr
), "SetViewport failed, hr %#x.\n", hr
);
1426 static void depth_buffer_test(IDirect3DDevice8
*device
)
1428 static const struct vertex quad1
[] =
1430 { -1.0, 1.0, 0.33f
, 0xff00ff00},
1431 { 1.0, 1.0, 0.33f
, 0xff00ff00},
1432 { -1.0, -1.0, 0.33f
, 0xff00ff00},
1433 { 1.0, -1.0, 0.33f
, 0xff00ff00},
1435 static const struct vertex quad2
[] =
1437 { -1.0, 1.0, 0.50f
, 0xffff00ff},
1438 { 1.0, 1.0, 0.50f
, 0xffff00ff},
1439 { -1.0, -1.0, 0.50f
, 0xffff00ff},
1440 { 1.0, -1.0, 0.50f
, 0xffff00ff},
1442 static const struct vertex quad3
[] =
1444 { -1.0, 1.0, 0.66f
, 0xffff0000},
1445 { 1.0, 1.0, 0.66f
, 0xffff0000},
1446 { -1.0, -1.0, 0.66f
, 0xffff0000},
1447 { 1.0, -1.0, 0.66f
, 0xffff0000},
1449 static const DWORD expected_colors
[4][4] =
1451 {0x000000ff, 0x000000ff, 0x0000ff00, 0x00ff0000},
1452 {0x000000ff, 0x000000ff, 0x0000ff00, 0x00ff0000},
1453 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x00ff0000},
1454 {0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000},
1457 IDirect3DSurface8
*backbuffer
, *rt1
, *rt2
, *rt3
;
1458 IDirect3DSurface8
*depth_stencil
;
1471 hr
= IDirect3DDevice8_SetViewport(device
, &vp
);
1472 ok(SUCCEEDED(hr
), "SetViewport failed, hr %#x.\n", hr
);
1474 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
1475 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
1476 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_TRUE
);
1477 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
1478 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZWRITEENABLE
, TRUE
);
1479 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
1480 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_LESSEQUAL
);
1481 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
1482 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
1483 ok(SUCCEEDED(hr
), "SetVertexShader failed, hr %#x.\n", hr
);
1485 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &depth_stencil
);
1486 ok(SUCCEEDED(hr
), "GetDepthStencilSurface failed, hr %#x.\n", hr
);
1487 hr
= IDirect3DDevice8_GetRenderTarget(device
, &backbuffer
);
1488 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
1489 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 320, 240, D3DFMT_A8R8G8B8
,
1490 D3DMULTISAMPLE_NONE
, FALSE
, &rt1
);
1491 ok(SUCCEEDED(hr
), "CreateRenderTarget failed, hr %#x.\n", hr
);
1492 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 480, 360, D3DFMT_A8R8G8B8
,
1493 D3DMULTISAMPLE_NONE
, FALSE
, &rt2
);
1494 ok(SUCCEEDED(hr
), "CreateRenderTarget failed, hr %#x.\n", hr
);
1495 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 640, 480, D3DFMT_A8R8G8B8
,
1496 D3DMULTISAMPLE_NONE
, FALSE
, &rt3
);
1497 ok(SUCCEEDED(hr
), "CreateRenderTarget failed, hr %#x.\n", hr
);
1499 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt3
, depth_stencil
);
1500 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
1501 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff0000ff, 0.0f
, 0);
1502 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
1504 hr
= IDirect3DDevice8_SetRenderTarget(device
, backbuffer
, depth_stencil
);
1505 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
1506 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff0000ff, 1.0f
, 0);
1507 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
1509 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt1
, depth_stencil
);
1510 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
1511 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffffff, 0.0f
, 0);
1512 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
1514 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt2
, depth_stencil
);
1515 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
1516 hr
= IDirect3DDevice8_BeginScene(device
);
1517 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
1518 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(*quad2
));
1519 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
1520 hr
= IDirect3DDevice8_EndScene(device
);
1521 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
1523 hr
= IDirect3DDevice8_SetRenderTarget(device
, backbuffer
, depth_stencil
);
1524 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
1525 IDirect3DSurface8_Release(depth_stencil
);
1526 IDirect3DSurface8_Release(backbuffer
);
1527 IDirect3DSurface8_Release(rt3
);
1528 IDirect3DSurface8_Release(rt2
);
1529 IDirect3DSurface8_Release(rt1
);
1531 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZWRITEENABLE
, FALSE
);
1532 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
1534 hr
= IDirect3DDevice8_BeginScene(device
);
1535 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
1536 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(*quad1
));
1537 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
1538 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, sizeof(*quad3
));
1539 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
1540 hr
= IDirect3DDevice8_EndScene(device
);
1541 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
1543 for (i
= 0; i
< 4; ++i
)
1545 for (j
= 0; j
< 4; ++j
)
1547 unsigned int x
= 80 * ((2 * j
) + 1);
1548 unsigned int y
= 60 * ((2 * i
) + 1);
1549 color
= getPixelColor(device
, x
, y
);
1550 ok(color_match(color
, expected_colors
[i
][j
], 0),
1551 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors
[i
][j
], x
, y
, color
);
1555 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
1556 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
1559 static void shadow_test(IDirect3DDevice8
*device
)
1561 static const DWORD ps_code
[] =
1563 0xffff0101, /* ps_1_1 */
1564 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1.0, 0.0, 0.0, 0.0 */
1565 0x00000051, 0xa00f0001, 0x00000000, 0x3f800000, 0x00000000, 0x00000000, /* def c1, 0.0, 1.0, 0.0, 0.0 */
1566 0x00000051, 0xa00f0002, 0x00000000, 0x00000000, 0x3f800000, 0x00000000, /* def c2, 0.0, 0.0, 1.0, 0.0 */
1567 0x00000042, 0xb00f0000, /* tex t0 */
1568 0x00000042, 0xb00f0001, /* tex t1 */
1569 0x00000008, 0xb0070001, 0xa0e40000, 0xb0e40001, /* dp3 t1.xyz, c0, t1 */
1570 0x00000005, 0x80070000, 0xa0e40001, 0xb0e40001, /* mul r0.xyz, c1, t1 */
1571 0x00000004, 0x80070000, 0xa0e40000, 0xb0e40000, 0x80e40000, /* mad r0.xyz, c0, t0, r0 */
1572 0x40000001, 0x80080000, 0xa0aa0002, /* +mov r0.w, c2.z */
1573 0x0000ffff, /* end */
1582 {D3DFMT_D16_LOCKABLE
, "D3DFMT_D16_LOCKABLE"},
1583 {D3DFMT_D32
, "D3DFMT_D32"},
1584 {D3DFMT_D15S1
, "D3DFMT_D15S1"},
1585 {D3DFMT_D24S8
, "D3DFMT_D24S8"},
1586 {D3DFMT_D24X8
, "D3DFMT_D24X8"},
1587 {D3DFMT_D24X4S4
, "D3DFMT_D24X4S4"},
1588 {D3DFMT_D16
, "D3DFMT_D16"},
1594 float s1
, t1
, p1
, q1
;
1598 { -1.0f
, 1.0f
, 0.0f
, 0.0f
, 1.0f
, 1.0f
, 0.0f
, 1.0f
, 1.0f
, 0.0f
},
1599 { 1.0f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 0.0f
},
1600 { -1.0f
, -1.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 1.0f
},
1601 { 1.0f
, -1.0f
, 1.0f
, 1.0f
, 0.0f
, 0.0f
, 1.0f
, 0.0f
, 0.0f
, 1.0f
},
1610 {400, 60, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00)},
1611 {560, 180, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x00)},
1612 {560, 300, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x00)},
1613 {400, 420, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x00)},
1614 {240, 420, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x00)},
1615 { 80, 300, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00)},
1616 { 80, 180, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00)},
1617 {240, 60, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00)},
1620 IDirect3DSurface8
*original_ds
, *original_rt
, *rt
;
1627 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
1628 ok(SUCCEEDED(hr
), "GetDeviceCaps failed, hr %#x.\n", hr
);
1629 if (caps
.PixelShaderVersion
< D3DPS_VERSION(1, 1))
1631 skip("No pixel shader 1.1 support, skipping shadow test.\n");
1635 hr
= IDirect3DDevice8_GetDirect3D(device
, &d3d8
);
1636 ok(SUCCEEDED(hr
), "GetDirect3D failed, hr %#x.\n", hr
);
1637 hr
= IDirect3DDevice8_GetRenderTarget(device
, &original_rt
);
1638 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
1639 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &original_ds
);
1640 ok(SUCCEEDED(hr
), "GetDepthStencilSurface failed, hr %#x.\n", hr
);
1642 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 1024, 1024, D3DFMT_A8R8G8B8
,
1643 D3DMULTISAMPLE_NONE
, FALSE
, &rt
);
1644 ok(SUCCEEDED(hr
), "CreateRenderTarget failed, hr %#x.\n", hr
);
1645 hr
= IDirect3DDevice8_CreatePixelShader(device
, ps_code
, &ps
);
1646 ok(SUCCEEDED(hr
), "CreatePixelShader failed, hr %#x.\n", hr
);
1648 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_TEX2
1649 | D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEXCOORDSIZE4(1));
1650 ok(SUCCEEDED(hr
), "SetVertexShader failed, hr %#x.\n", hr
);
1651 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_TRUE
);
1652 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
1653 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_ALWAYS
);
1654 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
1655 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZWRITEENABLE
, TRUE
);
1656 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
1657 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
1658 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
1660 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_MINFILTER
, D3DTEXF_POINT
);
1661 ok(SUCCEEDED(hr
), "SetTextureStageState failed, hr %#x.\n", hr
);
1662 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_MIPFILTER
, D3DTEXF_POINT
);
1663 ok(SUCCEEDED(hr
), "SetTextureStageState failed, hr %#x.\n", hr
);
1664 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_MAGFILTER
, D3DTEXF_POINT
);
1665 ok(SUCCEEDED(hr
), "SetTextureStageState failed, hr %#x.\n", hr
);
1666 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT3
);
1667 ok(SUCCEEDED(hr
), "SetTextureStageState failed, hr %#x.\n", hr
);
1669 hr
= IDirect3DDevice8_SetTextureStageState(device
, 1, D3DTSS_ADDRESSU
, D3DTADDRESS_WRAP
);
1670 ok(SUCCEEDED(hr
), "SetTextureStageState failed, hr %#x.\n", hr
);
1671 hr
= IDirect3DDevice8_SetTextureStageState(device
, 1, D3DTSS_ADDRESSV
, D3DTADDRESS_WRAP
);
1672 ok(SUCCEEDED(hr
), "SetTextureStageState failed, hr %#x.\n", hr
);
1673 hr
= IDirect3DDevice8_SetTextureStageState(device
, 1, D3DTSS_MAGFILTER
, D3DTEXF_POINT
);
1674 ok(SUCCEEDED(hr
), "SetTextureStageState failed, hr %#x.\n", hr
);
1675 hr
= IDirect3DDevice8_SetTextureStageState(device
, 1, D3DTSS_MINFILTER
, D3DTEXF_POINT
);
1676 ok(SUCCEEDED(hr
), "SetTextureStageState failed, hr %#x.\n", hr
);
1677 hr
= IDirect3DDevice8_SetTextureStageState(device
, 1, D3DTSS_MIPFILTER
, D3DTEXF_POINT
);
1678 ok(SUCCEEDED(hr
), "SetTextureStageState failed, hr %#x.\n", hr
);
1679 hr
= IDirect3DDevice8_SetTextureStageState(device
, 1, D3DTSS_TEXTURETRANSFORMFLAGS
,
1680 D3DTTFF_COUNT4
| D3DTTFF_PROJECTED
);
1681 ok(SUCCEEDED(hr
), "SetTextureStageState failed, hr %#x.\n", hr
);
1683 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); ++i
)
1685 D3DFORMAT format
= formats
[i
].format
;
1686 IDirect3DTexture8
*texture
;
1687 IDirect3DSurface8
*ds
;
1690 hr
= IDirect3D8_CheckDeviceFormat(d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
1691 D3DUSAGE_DEPTHSTENCIL
, D3DRTYPE_TEXTURE
, format
);
1692 if (FAILED(hr
)) continue;
1694 hr
= IDirect3DDevice8_CreateTexture(device
, 1024, 1024, 1,
1695 D3DUSAGE_DEPTHSTENCIL
, format
, D3DPOOL_DEFAULT
, &texture
);
1696 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
1698 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &ds
);
1699 ok(SUCCEEDED(hr
), "GetSurfaceLevel failed, hr %#x.\n", hr
);
1701 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, ds
);
1702 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
1704 IDirect3DDevice8_SetPixelShader(device
, 0);
1705 ok(SUCCEEDED(hr
), "SetPixelShader failed, hr %#x.\n", hr
);
1707 /* Setup the depth/stencil surface. */
1708 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0, 0.0f
, 0);
1709 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
1711 hr
= IDirect3DDevice8_BeginScene(device
);
1712 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
1713 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
1714 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
1715 hr
= IDirect3DDevice8_EndScene(device
);
1716 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
1718 hr
= IDirect3DDevice8_SetRenderTarget(device
, original_rt
, NULL
);
1719 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
1720 IDirect3DSurface8_Release(ds
);
1722 hr
= IDirect3DDevice8_SetTexture(device
, 0, (IDirect3DBaseTexture8
*)texture
);
1723 ok(SUCCEEDED(hr
), "SetTexture failed, hr %#x.\n", hr
);
1724 hr
= IDirect3DDevice8_SetTexture(device
, 1, (IDirect3DBaseTexture8
*)texture
);
1725 ok(SUCCEEDED(hr
), "SetTexture failed, hr %#x.\n", hr
);
1727 hr
= IDirect3DDevice8_SetPixelShader(device
, ps
);
1728 ok(SUCCEEDED(hr
), "SetPixelShader failed, hr %#x.\n", hr
);
1730 /* Do the actual shadow mapping. */
1731 hr
= IDirect3DDevice8_BeginScene(device
);
1732 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
1733 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
1734 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
1735 hr
= IDirect3DDevice8_EndScene(device
);
1736 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
1738 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
1739 ok(SUCCEEDED(hr
), "SetTexture failed, hr %#x.\n", hr
);
1740 hr
= IDirect3DDevice8_SetTexture(device
, 1, NULL
);
1741 ok(SUCCEEDED(hr
), "SetTexture failed, hr %#x.\n", hr
);
1742 IDirect3DTexture8_Release(texture
);
1744 for (j
= 0; j
< sizeof(expected_colors
) / sizeof(*expected_colors
); ++j
)
1746 D3DCOLOR color
= getPixelColor(device
, expected_colors
[j
].x
, expected_colors
[j
].y
);
1747 ok(color_match(color
, expected_colors
[j
].color
, 0),
1748 "Expected color 0x%08x at (%u, %u) for format %s, got 0x%08x.\n",
1749 expected_colors
[j
].color
, expected_colors
[j
].x
, expected_colors
[j
].y
,
1750 formats
[i
].name
, color
);
1753 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
1754 ok(SUCCEEDED(hr
), "Present failed, hr %#x.\n", hr
);
1757 hr
= IDirect3DDevice8_SetPixelShader(device
, 0);
1758 ok(SUCCEEDED(hr
), "SetPixelShader failed, hr %#x.\n", hr
);
1759 hr
= IDirect3DDevice8_DeletePixelShader(device
, ps
);
1760 ok(SUCCEEDED(hr
), "DeletePixelShader failed, hr %#x.\n", hr
);
1762 hr
= IDirect3DDevice8_SetRenderTarget(device
, original_rt
, original_ds
);
1763 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
1764 IDirect3DSurface8_Release(original_ds
);
1766 IDirect3DSurface8_Release(original_rt
);
1767 IDirect3DSurface8_Release(rt
);
1769 IDirect3D8_Release(d3d8
);
1774 IDirect3DDevice8
*device_ptr
;
1779 d3d8_handle
= LoadLibraryA("d3d8.dll");
1782 win_skip("Could not load d3d8.dll\n");
1786 device_ptr
= init_d3d8();
1789 win_skip("Could not initialize direct3d\n");
1793 IDirect3DDevice8_GetDeviceCaps(device_ptr
, &caps
);
1795 /* Check for the reliability of the returned data */
1796 hr
= IDirect3DDevice8_Clear(device_ptr
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
1799 skip("Clear failed, can't assure correctness of the test results\n");
1803 color
= getPixelColor(device_ptr
, 1, 1);
1804 if(color
!=0x00ff0000)
1806 skip("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests\n", color
);
1809 IDirect3DDevice8_Present(device_ptr
, NULL
, NULL
, NULL
, NULL
);
1811 hr
= IDirect3DDevice8_Clear(device_ptr
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ddee, 0.0, 0);
1814 skip("Clear failed, can't assure correctness of the test results\n");
1818 color
= getPixelColor(device_ptr
, 639, 479);
1819 if(color
!= 0x0000ddee)
1821 skip("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests\n", color
);
1824 IDirect3DDevice8_Present(device_ptr
, NULL
, NULL
, NULL
, NULL
);
1826 /* Now run the real test */
1827 depth_clamp_test(device_ptr
);
1828 lighting_test(device_ptr
);
1829 clear_test(device_ptr
);
1830 fog_test(device_ptr
);
1831 present_test(device_ptr
);
1832 offscreen_test(device_ptr
);
1833 alpha_test(device_ptr
);
1835 if (caps
.VertexShaderVersion
>= D3DVS_VERSION(1, 1))
1837 test_rcp_rsq(device_ptr
);
1841 skip("No vs.1.1 support\n");
1844 p8_texture_test(device_ptr
);
1845 texop_test(device_ptr
);
1846 depth_buffer_test(device_ptr
);
1847 shadow_test(device_ptr
);
1851 D3DDEVICE_CREATION_PARAMETERS creation_parameters
;
1854 IDirect3DDevice8_GetCreationParameters(device_ptr
, &creation_parameters
);
1855 DestroyWindow(creation_parameters
.hFocusWindow
);
1856 refcount
= IDirect3DDevice8_Release(device_ptr
);
1857 ok(!refcount
, "Device has %u references left\n", refcount
);