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_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
41 static BOOL
color_match(D3DCOLOR c1
, D3DCOLOR c2
, BYTE max_diff
)
43 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
45 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
47 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
49 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
53 static DWORD
getPixelColor(IDirect3DDevice8
*device
, UINT x
, UINT y
)
56 IDirect3DSurface8
*surf
;
57 IDirect3DTexture8
*tex
;
59 D3DLOCKED_RECT lockedRect
;
60 RECT rectToLock
= {x
, y
, x
+1, y
+1};
62 hr
= IDirect3DDevice8_CreateTexture(device
, 640, 480, 1 /* Levels */, 0 /* usage */, D3DFMT_A8R8G8B8
, D3DPOOL_SYSTEMMEM
, &tex
);
63 if(FAILED(hr
) || !tex
) /* This is not a test */
65 trace("Can't create an offscreen plain surface to read the render target data, hr=%#08x\n", hr
);
68 hr
= IDirect3DTexture8_GetSurfaceLevel(tex
, 0, &surf
);
69 if(FAILED(hr
) || !tex
) /* This is not a test */
71 trace("Can't get surface from texture, hr=%#08x\n", hr
);
76 hr
= IDirect3DDevice8_GetFrontBuffer(device
, surf
);
79 trace("Can't read the front buffer data, hr=%#08x\n", hr
);
84 hr
= IDirect3DSurface8_LockRect(surf
, &lockedRect
, &rectToLock
, D3DLOCK_READONLY
);
87 trace("Can't lock the offscreen surface, hr=%#08x\n", hr
);
91 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
92 * really important for these tests
94 ret
= ((DWORD
*) lockedRect
.pBits
)[0] & 0x00ffffff;
95 hr
= IDirect3DSurface8_UnlockRect(surf
);
98 trace("Can't unlock the offscreen surface, hr=%#08x\n", hr
);
102 if(surf
) IDirect3DSurface8_Release(surf
);
103 if(tex
) IDirect3DTexture8_Release(tex
);
107 static IDirect3DDevice8
*init_d3d8(void)
109 IDirect3D8
* (__stdcall
* d3d8_create
)(UINT SDKVersion
) = 0;
110 IDirect3D8
*d3d8_ptr
= 0;
111 IDirect3DDevice8
*device_ptr
= 0;
112 D3DPRESENT_PARAMETERS present_parameters
;
115 d3d8_create
= (void *)GetProcAddress(d3d8_handle
, "Direct3DCreate8");
116 ok(d3d8_create
!= NULL
, "Failed to get address of Direct3DCreate8\n");
117 if (!d3d8_create
) return NULL
;
119 d3d8_ptr
= d3d8_create(D3D_SDK_VERSION
);
122 skip("could not create D3D8\n");
126 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
127 present_parameters
.Windowed
= FALSE
;
128 present_parameters
.hDeviceWindow
= create_window();
129 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
130 present_parameters
.BackBufferWidth
= 640;
131 present_parameters
.BackBufferHeight
= 480;
132 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
133 present_parameters
.EnableAutoDepthStencil
= TRUE
;
134 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D16
;
136 hr
= IDirect3D8_CreateDevice(d3d8_ptr
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, present_parameters
.hDeviceWindow
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device_ptr
);
137 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
|| broken(hr
== D3DERR_NOTAVAILABLE
), "IDirect3D_CreateDevice returned: %#08x\n", hr
);
155 static void lighting_test(IDirect3DDevice8
*device
)
158 DWORD fvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
159 DWORD nfvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_NORMAL
;
162 float mat
[16] = { 1.0f
, 0.0f
, 0.0f
, 0.0f
,
163 0.0f
, 1.0f
, 0.0f
, 0.0f
,
164 0.0f
, 0.0f
, 1.0f
, 0.0f
,
165 0.0f
, 0.0f
, 0.0f
, 1.0f
};
167 struct vertex unlitquad
[] =
169 {-1.0f
, -1.0f
, 0.1f
, 0xffff0000},
170 {-1.0f
, 0.0f
, 0.1f
, 0xffff0000},
171 { 0.0f
, 0.0f
, 0.1f
, 0xffff0000},
172 { 0.0f
, -1.0f
, 0.1f
, 0xffff0000},
174 struct vertex litquad
[] =
176 {-1.0f
, 0.0f
, 0.1f
, 0xff00ff00},
177 {-1.0f
, 1.0f
, 0.1f
, 0xff00ff00},
178 { 0.0f
, 1.0f
, 0.1f
, 0xff00ff00},
179 { 0.0f
, 0.0f
, 0.1f
, 0xff00ff00},
181 struct nvertex unlitnquad
[] =
183 { 0.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
184 { 0.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
185 { 1.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
186 { 1.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
188 struct nvertex litnquad
[] =
190 { 0.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
191 { 0.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
192 { 1.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
193 { 1.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
195 WORD Indices
[] = {0, 1, 2, 2, 3, 0};
197 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
198 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed with %#08x\n", hr
);
200 /* Setup some states that may cause issues */
201 hr
= IDirect3DDevice8_SetTransform(device
, D3DTS_WORLDMATRIX(0), (D3DMATRIX
*) mat
);
202 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTransform returned %#08x\n", hr
);
203 hr
= IDirect3DDevice8_SetTransform(device
, D3DTS_VIEW
, (D3DMATRIX
*)mat
);
204 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTransform returned %#08x\n", hr
);
205 hr
= IDirect3DDevice8_SetTransform(device
, D3DTS_PROJECTION
, (D3DMATRIX
*) mat
);
206 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTransform returned %#08x\n", hr
);
207 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_CLIPPING
, FALSE
);
208 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
209 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
210 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
211 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGENABLE
, FALSE
);
212 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
213 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_STENCILENABLE
, FALSE
);
214 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
215 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ALPHATESTENABLE
, FALSE
);
216 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
217 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, FALSE
);
218 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
219 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_CULLMODE
, D3DCULL_NONE
);
220 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed with %#08x\n", hr
);
221 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_COLORWRITEENABLE
, D3DCOLORWRITEENABLE_RED
| D3DCOLORWRITEENABLE_GREEN
| D3DCOLORWRITEENABLE_BLUE
);
222 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed with %#08x\n", hr
);
224 hr
= IDirect3DDevice8_SetVertexShader(device
, fvf
);
225 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
227 hr
= IDirect3DDevice8_BeginScene(device
);
228 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr
);
231 /* No lights are defined... That means, lit vertices should be entirely black */
232 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
233 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
234 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
235 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, unlitquad
, sizeof(unlitquad
[0]));
236 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr
);
238 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, TRUE
);
239 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
240 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
241 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, litquad
, sizeof(litquad
[0]));
242 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr
);
244 hr
= IDirect3DDevice8_SetVertexShader(device
, nfvf
);
245 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader failed with %#08x\n", hr
);
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
, unlitnquad
, sizeof(unlitnquad
[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
, litnquad
, sizeof(litnquad
[0]));
257 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr
);
259 IDirect3DDevice8_EndScene(device
);
260 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed with %#08x\n", hr
);
263 IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
265 color
= getPixelColor(device
, 160, 360); /* lower left quad - unlit without normals */
266 ok(color
== 0x00ff0000, "Unlit quad without normals has color %08x\n", color
);
267 color
= getPixelColor(device
, 160, 120); /* upper left quad - lit without normals */
268 ok(color
== 0x00000000, "Lit quad without normals has color %08x\n", color
);
269 color
= getPixelColor(device
, 480, 360); /* lower left quad - unlit width normals */
270 ok(color
== 0x000000ff, "Unlit quad width normals has color %08x\n", color
);
271 color
= getPixelColor(device
, 480, 120); /* upper left quad - lit width normals */
272 ok(color
== 0x00000000, "Lit quad width normals has color %08x\n", color
);
274 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
275 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
278 static void clear_test(IDirect3DDevice8
*device
)
280 /* Tests the correctness of clearing parameters */
286 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
287 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed with %#08x\n", hr
);
289 /* Positive x, negative y */
295 /* Positive x, positive y */
300 /* Clear 2 rectangles with one call. Shows that a positive value is returned, but the negative rectangle
301 * is ignored, the positive is still cleared afterwards
303 hr
= IDirect3DDevice8_Clear(device
, 2, rect
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
304 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed with %#08x\n", hr
);
306 /* negative x, negative y */
307 rect_negneg
.x1
= 640;
308 rect_negneg
.y1
= 240;
309 rect_negneg
.x2
= 320;
311 hr
= IDirect3DDevice8_Clear(device
, 1, &rect_negneg
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0, 0);
312 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed with %#08x\n", hr
);
314 IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
316 color
= getPixelColor(device
, 160, 360); /* lower left quad */
317 ok(color
== 0x00ffffff, "Clear rectangle 3(pos, neg) has color %08x\n", color
);
318 color
= getPixelColor(device
, 160, 120); /* upper left quad */
319 ok(color
== 0x00ff0000, "Clear rectangle 1(pos, pos) has color %08x\n", color
);
320 color
= getPixelColor(device
, 480, 360); /* lower right quad */
321 ok(color
== 0x00ffffff, "Clear rectangle 4(NULL) has color %08x\n", color
);
322 color
= getPixelColor(device
, 480, 120); /* upper right quad */
323 ok(color
== 0x00ffffff, "Clear rectangle 4(neg, neg) has color %08x\n", color
);
338 static void fog_test(IDirect3DDevice8
*device
)
342 float start
= 0.0, end
= 1.0;
344 /* Gets full z based fog with linear fog, no fog with specular color */
345 struct sVertex unstransformed_1
[] = {
346 {-1, -1, 0.1f
, 0xFFFF0000, 0xFF000000 },
347 {-1, 0, 0.1f
, 0xFFFF0000, 0xFF000000 },
348 { 0, 0, 0.1f
, 0xFFFF0000, 0xFF000000 },
349 { 0, -1, 0.1f
, 0xFFFF0000, 0xFF000000 },
351 /* Ok, I am too lazy to deal with transform matrices */
352 struct sVertex unstransformed_2
[] = {
353 {-1, 0, 1.0f
, 0xFFFF0000, 0xFF000000 },
354 {-1, 1, 1.0f
, 0xFFFF0000, 0xFF000000 },
355 { 0, 1, 1.0f
, 0xFFFF0000, 0xFF000000 },
356 { 0, 0, 1.0f
, 0xFFFF0000, 0xFF000000 },
358 /* Untransformed ones. Give them a different diffuse color to make the test look
359 * nicer. It also makes making sure that they are drawn correctly easier.
361 struct sVertexT transformed_1
[] = {
362 {320, 0, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
363 {640, 0, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
364 {640, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
365 {320, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
367 struct sVertexT transformed_2
[] = {
368 {320, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
369 {640, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
370 {640, 480, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
371 {320, 480, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
373 WORD Indices
[] = {0, 1, 2, 2, 3, 0};
375 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
376 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear returned %#08x\n", hr
);
378 /* Setup initial states: No lighting, fog on, fog color */
379 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
380 ok(hr
== D3D_OK
, "Turning off lighting returned %#08x\n", hr
);
381 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGENABLE
, TRUE
);
382 ok(hr
== D3D_OK
, "Turning on fog calculations returned %#08x\n", hr
);
383 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGCOLOR
, 0xFF00FF00 /* A nice green */);
384 ok(hr
== D3D_OK
, "Turning on fog calculations returned %#08x\n", hr
);
386 /* First test: Both table fog and vertex fog off */
387 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGTABLEMODE
, D3DFOG_NONE
);
388 ok(hr
== D3D_OK
, "Turning off table fog returned %#08x\n", hr
);
389 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, D3DFOG_NONE
);
390 ok(hr
== D3D_OK
, "Turning off table fog returned %#08x\n", hr
);
392 /* Start = 0, end = 1. Should be default, but set them */
393 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGSTART
, *((DWORD
*) &start
));
394 ok(hr
== D3D_OK
, "Setting fog start returned %#08x\n", hr
);
395 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGEND
, *((DWORD
*) &end
));
396 ok(hr
== D3D_OK
, "Setting fog start returned %#08x\n", hr
);
398 if(IDirect3DDevice8_BeginScene(device
) == D3D_OK
)
400 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
);
401 ok( hr
== D3D_OK
, "SetVertexShader returned %#08x\n", hr
);
402 /* Untransformed, vertex fog = NONE, table fog = NONE: Read the fog weighting from the specular color */
403 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
404 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, unstransformed_1
,
405 sizeof(unstransformed_1
[0]));
406 ok(hr
== D3D_OK
, "DrawIndexedPrimitiveUP returned %#08x\n", hr
);
408 /* That makes it use the Z value */
409 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, D3DFOG_LINEAR
);
410 ok(hr
== D3D_OK
, "Turning off table fog returned %#08x\n", hr
);
411 /* Untransformed, vertex fog != none (or table fog != none):
412 * Use the Z value as input into the equation
414 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
415 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, unstransformed_2
,
416 sizeof(unstransformed_1
[0]));
417 ok(hr
== D3D_OK
, "DrawIndexedPrimitiveUP returned %#08x\n", hr
);
419 /* transformed verts */
420 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
);
421 ok( hr
== D3D_OK
, "SetVertexShader returned %#08x\n", hr
);
422 /* Transformed, vertex fog != NONE, pixel fog == NONE: Use specular color alpha component */
423 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
424 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, transformed_1
,
425 sizeof(transformed_1
[0]));
426 ok(hr
== D3D_OK
, "DrawIndexedPrimitiveUP returned %#08x\n", hr
);
428 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGTABLEMODE
, D3DFOG_LINEAR
);
429 ok( hr
== D3D_OK
, "Setting fog table mode to D3DFOG_LINEAR returned %#08x\n", hr
);
430 /* Transformed, table fog != none, vertex anything: Use Z value as input to the fog
433 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
434 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, transformed_2
,
435 sizeof(transformed_2
[0]));
437 hr
= IDirect3DDevice8_EndScene(device
);
438 ok(hr
== D3D_OK
, "EndScene returned %#08x\n", hr
);
442 ok(FALSE
, "BeginScene failed\n");
445 IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
446 color
= getPixelColor(device
, 160, 360);
447 ok(color
== 0x00FF0000, "Untransformed vertex with no table or vertex fog has color %08x\n", color
);
448 color
= getPixelColor(device
, 160, 120);
449 ok(color
== 0x0000FF00, "Untransformed vertex with linear vertex fog has color %08x\n", color
);
450 color
= getPixelColor(device
, 480, 120);
451 ok(color
== 0x00FFFF00, "Transformed vertex with linear vertex fog has color %08x\n", color
);
452 color
= getPixelColor(device
, 480, 360);
453 ok(color
== 0x0000FF00, "Transformed vertex with linear table fog has color %08x\n", color
);
455 /* Turn off the fog master switch to avoid confusing other tests */
456 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGENABLE
, FALSE
);
457 ok(hr
== D3D_OK
, "Turning off fog calculations returned %#08x\n", hr
);
460 static void present_test(IDirect3DDevice8
*device
)
462 struct vertex quad
[] =
464 {-1.0f
, -1.0f
, 0.9f
, 0xffff0000},
465 {-1.0f
, 1.0f
, 0.9f
, 0xffff0000},
466 { 1.0f
, -1.0f
, 0.1f
, 0xffff0000},
467 { 1.0f
, 1.0f
, 0.1f
, 0xffff0000},
472 /* Does the Present clear the depth stencil? Clear the depth buffer with some value != 0,
473 * then call Present. Then clear the color buffer to make sure it has some defined content
474 * after the Present with D3DSWAPEFFECT_DISCARD. After that draw a plane that is somewhere cut
475 * by the depth value.
477 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffffff, 0.75, 0);
478 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear returned %08x\n", hr
);
479 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
480 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.4, 0);
482 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_TRUE
);
483 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %08x\n", hr
);
484 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_GREATER
);
485 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %08x\n", hr
);
486 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
487 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetFVF returned %08x\n", hr
);
489 hr
= IDirect3DDevice8_BeginScene(device
);
490 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed with %08x\n", hr
);
493 /* No lights are defined... That means, lit vertices should be entirely black */
494 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2 /*PrimCount */, quad
, sizeof(quad
[0]));
495 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %08x\n", hr
);
497 hr
= IDirect3DDevice8_EndScene(device
);
498 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed with %08x\n", hr
);
501 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_FALSE
);
502 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %08x\n", hr
);
504 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
505 ok(SUCCEEDED(hr
), "Present failed (%#08x)\n", hr
);
506 color
= getPixelColor(device
, 512, 240);
507 ok(color
== 0x00ffffff, "Present failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
508 color
= getPixelColor(device
, 64, 240);
509 ok(color
== 0x00ff0000, "Present failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
512 static void test_rcp_rsq(IDirect3DDevice8
*device
)
517 unsigned char c1
, c2
, c3
;
518 float constant
[4] = {1.0, 1.0, 1.0, 2.0};
520 static const float quad
[][3] = {
521 {-1.0f
, -1.0f
, 0.0f
},
523 { 1.0f
, -1.0f
, 0.0f
},
527 const DWORD rcp_test
[] = {
528 0xfffe0101, /* vs.1.1 */
530 0x0009fffe, 0x30303030, 0x30303030, /* Shaders have to have a minimal size. */
531 0x30303030, 0x30303030, 0x30303030, /* Add a filler comment. Usually D3DX8's*/
532 0x30303030, 0x30303030, 0x30303030, /* version comment makes the shader big */
533 0x00303030, /* enough to make windows happy */
535 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
536 0x00000006, 0xd00f0000, 0xa0e40000, /* rcp oD0, c0 */
540 const DWORD rsq_test
[] = {
541 0xfffe0101, /* vs.1.1 */
543 0x0009fffe, 0x30303030, 0x30303030, /* Shaders have to have a minimal size. */
544 0x30303030, 0x30303030, 0x30303030, /* Add a filler comment. Usually D3DX8's*/
545 0x30303030, 0x30303030, 0x30303030, /* version comment makes the shader big */
546 0x00303030, /* enough to make windows happy */
548 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
549 0x00000007, 0xd00f0000, 0xa0e40000, /* rsq oD0, c0 */
556 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
560 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff800080, 0.0, 0);
561 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed with %#08x\n", hr
);
563 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, rcp_test
, &shader
, 0);
564 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned with %#08x\n", hr
);
566 IDirect3DDevice8_SetVertexShader(device
, shader
);
567 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
568 IDirect3DDevice8_SetVertexShaderConstant(device
, 0, constant
, 1);
570 hr
= IDirect3DDevice8_BeginScene(device
);
571 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene returned %#08x\n", hr
);
574 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad
[0], 3 * sizeof(float));
575 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%#08x)\n", hr
);
576 hr
= IDirect3DDevice8_EndScene(device
);
577 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
580 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
581 ok(SUCCEEDED(hr
), "Present failed (%#08x)\n", hr
);
582 color
= getPixelColor(device
, 320, 240);
583 c1
= (color
& 0x00ff0000 )>> 16;
584 c2
= (color
& 0x0000ff00 )>> 8;
585 c3
= (color
& 0x000000ff )>> 0;
586 ok(c1
== c2
&& c2
== c3
, "Color components differ: c1 = %02x, c2 = %02x, c3 = %02x\n",
588 ok(c1
>= 0x7c && c1
<= 0x84, "Color component value is %02x\n", c1
);
590 IDirect3DDevice8_SetVertexShader(device
, 0);
591 IDirect3DDevice8_DeleteVertexShader(device
, shader
);
593 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff800080, 0.0, 0);
594 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed with %#08x\n", hr
);
596 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, rsq_test
, &shader
, 0);
597 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned with %#08x\n", hr
);
599 IDirect3DDevice8_SetVertexShader(device
, shader
);
600 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
601 IDirect3DDevice8_SetVertexShaderConstant(device
, 0, constant
, 1);
603 hr
= IDirect3DDevice8_BeginScene(device
);
604 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene returned %#08x\n", hr
);
607 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad
[0], 3 * sizeof(float));
608 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%#08x)\n", hr
);
609 hr
= IDirect3DDevice8_EndScene(device
);
610 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
613 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
614 ok(SUCCEEDED(hr
), "Present failed (%#08x)\n", hr
);
615 color
= getPixelColor(device
, 320, 240);
616 c1
= (color
& 0x00ff0000 )>> 16;
617 c2
= (color
& 0x0000ff00 )>> 8;
618 c3
= (color
& 0x000000ff )>> 0;
619 ok(c1
== c2
&& c2
== c3
, "Color components differ: c1 = %02x, c2 = %02x, c3 = %02x\n",
621 ok(c1
>= 0xb0 && c1
<= 0xb8, "Color component value is %02x\n", c1
);
623 IDirect3DDevice8_SetVertexShader(device
, 0);
624 IDirect3DDevice8_DeleteVertexShader(device
, shader
);
627 static void offscreen_test(IDirect3DDevice8
*device
)
630 IDirect3DTexture8
*offscreenTexture
= NULL
;
631 IDirect3DSurface8
*backbuffer
= NULL
, *offscreen
= NULL
, *depthstencil
= NULL
;
634 static const float quad
[][5] = {
635 {-0.5f
, -0.5f
, 0.1f
, 0.0f
, 0.0f
},
636 {-0.5f
, 0.5f
, 0.1f
, 0.0f
, 1.0f
},
637 { 0.5f
, -0.5f
, 0.1f
, 1.0f
, 0.0f
},
638 { 0.5f
, 0.5f
, 0.1f
, 1.0f
, 1.0f
},
641 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &depthstencil
);
642 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetDepthStencilSurface failed, hr = %#08x\n", hr
);
644 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
645 ok(hr
== D3D_OK
, "Clear failed, hr = %#08x\n", hr
);
647 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &offscreenTexture
);
648 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "Creating the offscreen render target failed, hr = %#08x\n", hr
);
649 if(!offscreenTexture
) {
650 trace("Failed to create an X8R8G8B8 offscreen texture, trying R5G6B5\n");
651 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
, D3DFMT_R5G6B5
, D3DPOOL_DEFAULT
, &offscreenTexture
);
652 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "Creating the offscreen render target failed, hr = %#08x\n", hr
);
653 if(!offscreenTexture
) {
654 skip("Cannot create an offscreen render target\n");
659 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
660 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %#08x\n", hr
);
665 hr
= IDirect3DTexture8_GetSurfaceLevel(offscreenTexture
, 0, &offscreen
);
666 ok(hr
== D3D_OK
, "Can't get offscreen surface, hr = %#08x\n", hr
);
671 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
672 ok(hr
== D3D_OK
, "SetVertexShader failed, hr = %#08x\n", hr
);
674 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
675 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %#08x\n", hr
);
676 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
677 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %#08x\n", hr
);
678 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_MINFILTER
, D3DTEXF_NONE
);
679 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MINFILTER failed (%#08x)\n", hr
);
680 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_MAGFILTER
, D3DTEXF_NONE
);
681 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MAGFILTER failed (%#08x)\n", hr
);
682 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
683 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %08x\n", hr
);
685 if(IDirect3DDevice8_BeginScene(device
) == D3D_OK
) {
686 hr
= IDirect3DDevice8_SetRenderTarget(device
, offscreen
, depthstencil
);
687 ok(hr
== D3D_OK
, "SetRenderTarget failed, hr = %#08x\n", hr
);
688 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
689 ok(hr
== D3D_OK
, "Clear failed, hr = %#08x\n", hr
);
691 /* Draw without textures - Should result in a white quad */
692 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(quad
[0]));
693 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
695 hr
= IDirect3DDevice8_SetRenderTarget(device
, backbuffer
, depthstencil
);
696 ok(hr
== D3D_OK
, "SetRenderTarget failed, hr = %#08x\n", hr
);
697 hr
= IDirect3DDevice8_SetTexture(device
, 0, (IDirect3DBaseTexture8
*) offscreenTexture
);
698 ok(hr
== D3D_OK
, "SetTexture failed, %08x\n", hr
);
700 /* This time with the texture */
701 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(quad
[0]));
702 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
704 IDirect3DDevice8_EndScene(device
);
707 IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
709 /* Center quad - should be white */
710 color
= getPixelColor(device
, 320, 240);
711 ok(color
== 0x00ffffff, "Offscreen failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
712 /* Some quad in the cleared part of the texture */
713 color
= getPixelColor(device
, 170, 240);
714 ok(color
== 0x00ff00ff, "Offscreen failed: Got color 0x%08x, expected 0x00ff00ff.\n", color
);
715 /* Part of the originally cleared back buffer */
716 color
= getPixelColor(device
, 10, 10);
717 ok(color
== 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
719 /* Lower left corner of the screen, where back buffer offscreen rendering draws the offscreen texture.
720 * It should be red, but the offscreen texture may leave some junk there. Not tested yet. Depending on
721 * the offscreen rendering mode this test would succeed or fail
723 color
= getPixelColor(device
, 10, 470);
724 ok(color
== 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
728 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
732 hr
= IDirect3DDevice8_SetRenderTarget(device
, backbuffer
, depthstencil
);
733 IDirect3DSurface8_Release(backbuffer
);
735 if(offscreenTexture
) {
736 IDirect3DTexture8_Release(offscreenTexture
);
739 IDirect3DSurface8_Release(offscreen
);
742 IDirect3DSurface8_Release(depthstencil
);
746 static void alpha_test(IDirect3DDevice8
*device
)
749 IDirect3DTexture8
*offscreenTexture
;
750 IDirect3DSurface8
*backbuffer
= NULL
, *offscreen
= NULL
, *depthstencil
= NULL
;
753 struct vertex quad1
[] =
755 {-1.0f
, -1.0f
, 0.1f
, 0x4000ff00},
756 {-1.0f
, 0.0f
, 0.1f
, 0x4000ff00},
757 { 1.0f
, -1.0f
, 0.1f
, 0x4000ff00},
758 { 1.0f
, 0.0f
, 0.1f
, 0x4000ff00},
760 struct vertex quad2
[] =
762 {-1.0f
, 0.0f
, 0.1f
, 0xc00000ff},
763 {-1.0f
, 1.0f
, 0.1f
, 0xc00000ff},
764 { 1.0f
, 0.0f
, 0.1f
, 0xc00000ff},
765 { 1.0f
, 1.0f
, 0.1f
, 0xc00000ff},
767 static const float composite_quad
[][5] = {
768 { 0.0f
, -1.0f
, 0.1f
, 0.0f
, 1.0f
},
769 { 0.0f
, 1.0f
, 0.1f
, 0.0f
, 0.0f
},
770 { 1.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
},
771 { 1.0f
, 1.0f
, 0.1f
, 1.0f
, 0.0f
},
774 /* Clear the render target with alpha = 0.5 */
775 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x80ff0000, 0.0, 0);
776 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
778 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &offscreenTexture
);
779 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "Creating the offscreen render target failed, hr = %#08x\n", hr
);
781 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &depthstencil
);
782 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetDepthStencilSurface failed, hr = %#08x\n", hr
);
784 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
785 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %#08x\n", hr
);
789 hr
= IDirect3DTexture8_GetSurfaceLevel(offscreenTexture
, 0, &offscreen
);
790 ok(hr
== D3D_OK
, "Can't get offscreen surface, hr = %#08x\n", hr
);
795 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
796 ok(hr
== D3D_OK
, "SetVertexShader failed, hr = %#08x\n", hr
);
798 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
799 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %#08x\n", hr
);
800 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
801 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %#08x\n", hr
);
802 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_MINFILTER
, D3DTEXF_NONE
);
803 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MINFILTER failed (%#08x)\n", hr
);
804 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_MAGFILTER
, D3DTEXF_NONE
);
805 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MAGFILTER failed (%#08x)\n", hr
);
806 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
807 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %08x\n", hr
);
809 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, TRUE
);
810 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
811 if(IDirect3DDevice8_BeginScene(device
) == D3D_OK
) {
813 /* Draw two quads, one with src alpha blending, one with dest alpha blending. */
814 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_SRCALPHA
);
815 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
816 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
817 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
818 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(quad1
[0]));
819 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
821 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_DESTALPHA
);
822 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
823 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVDESTALPHA
);
824 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
825 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(quad2
[0]));
826 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
828 /* Switch to the offscreen buffer, and redo the testing. The offscreen render target
829 * doesn't have an alpha channel. DESTALPHA and INVDESTALPHA "don't work" on render
830 * targets without alpha channel, they give essentially ZERO and ONE blend factors. */
831 hr
= IDirect3DDevice8_SetRenderTarget(device
, offscreen
, 0);
832 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %08x\n", hr
);
833 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x80ff0000, 0.0, 0);
834 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
836 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_SRCALPHA
);
837 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
838 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
839 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
840 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(quad1
[0]));
841 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
843 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_DESTALPHA
);
844 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
845 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVDESTALPHA
);
846 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
847 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(quad2
[0]));
848 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
850 hr
= IDirect3DDevice8_SetRenderTarget(device
, backbuffer
, depthstencil
);
851 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %08x\n", hr
);
853 /* Render the offscreen texture onto the frame buffer to be able to compare it regularly.
854 * Disable alpha blending for the final composition
856 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, FALSE
);
857 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
858 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
859 ok(hr
== D3D_OK
, "SetVertexShader failed, hr = %#08x\n", hr
);
861 hr
= IDirect3DDevice8_SetTexture(device
, 0, (IDirect3DBaseTexture8
*) offscreenTexture
);
862 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr
);
863 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, composite_quad
, sizeof(float) * 5);
864 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
865 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
866 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr
);
868 hr
= IDirect3DDevice8_EndScene(device
);
869 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndScene failed, hr = %08x\n", hr
);
872 IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
874 color
= getPixelColor(device
, 160, 360);
875 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0xbf, 0x40, 0x00), 1),
876 "SRCALPHA on frame buffer returned color %08x, expected 0x00bf4000\n", color
);
878 color
= getPixelColor(device
, 160, 120);
879 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x7f, 0x00, 0x80), 2),
880 "DSTALPHA on frame buffer returned color %08x, expected 0x007f0080\n", color
);
882 color
= getPixelColor(device
, 480, 360);
883 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0xbf, 0x40, 0x00), 1),
884 "SRCALPHA on texture returned color %08x, expected 0x00bf4000\n", color
);
886 color
= getPixelColor(device
, 480, 120);
887 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0xff), 1),
888 "DSTALPHA on texture returned color %08x, expected 0x000000ff\n", color
);
893 IDirect3DSurface8_Release(backbuffer
);
895 if(offscreenTexture
) {
896 IDirect3DTexture8_Release(offscreenTexture
);
899 IDirect3DSurface8_Release(offscreen
);
902 IDirect3DSurface8_Release(depthstencil
);
906 static void p8_texture_test(IDirect3DDevice8
*device
)
908 IDirect3D8
*d3d
= NULL
;
910 IDirect3DTexture8
*texture
= NULL
, *texture2
= NULL
;
913 DWORD color
, red
, green
, blue
;
914 PALETTEENTRY table
[256];
918 -1.0, 0, 0.1, 0.0, 0.0,
919 -1.0, 1.0, 0.1, 0.0, 1.0,
920 1.0, 0, 0.1, 1.0, 0.0,
921 1.0, 1.0, 0.1, 1.0, 1.0,
924 -1.0, -1.0, 0.1, 0.0, 0.0,
925 -1.0, 0, 0.1, 0.0, 1.0,
926 1.0, -1.0, 0.1, 1.0, 0.0,
927 1.0, 0, 0.1, 1.0, 1.0,
930 IDirect3DDevice8_GetDirect3D(device
, &d3d
);
932 if(IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
, 0,
933 D3DRTYPE_TEXTURE
, D3DFMT_P8
) != D3D_OK
) {
934 skip("D3DFMT_P8 textures not supported\n");
938 hr
= IDirect3DDevice8_CreateTexture(device
, 1, 1, 1, 0, D3DFMT_P8
,
939 D3DPOOL_MANAGED
, &texture2
);
940 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateTexture failed, hr = %08x\n", hr
);
942 skip("Failed to create D3DFMT_P8 texture\n");
946 memset(&lr
, 0, sizeof(lr
));
947 hr
= IDirect3DTexture8_LockRect(texture2
, 0, &lr
, NULL
, 0);
948 ok(hr
== D3D_OK
, "IDirect3DTexture8_LockRect failed, hr = %08x\n", hr
);
952 hr
= IDirect3DTexture8_UnlockRect(texture2
, 0);
953 ok(hr
== D3D_OK
, "IDirect3DTexture8_UnlockRect failed, hr = %08x\n", hr
);
955 hr
= IDirect3DDevice8_CreateTexture(device
, 1, 1, 1, 0, D3DFMT_P8
,
956 D3DPOOL_MANAGED
, &texture
);
957 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateTexture failed, hr = %08x\n", hr
);
959 skip("Failed to create D3DFMT_P8 texture\n");
963 memset(&lr
, 0, sizeof(lr
));
964 hr
= IDirect3DTexture8_LockRect(texture
, 0, &lr
, NULL
, 0);
965 ok(hr
== D3D_OK
, "IDirect3DTexture8_LockRect failed, hr = %08x\n", hr
);
969 hr
= IDirect3DTexture8_UnlockRect(texture
, 0);
970 ok(hr
== D3D_OK
, "IDirect3DTexture8_UnlockRect failed, hr = %08x\n", hr
);
972 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff000000, 0.0, 0);
973 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed, hr = %08x\n", hr
);
975 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, TRUE
);
976 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
978 /* The first part of the test should work both with and without D3DPTEXTURECAPS_ALPHAPALETTE;
979 alpha of every entry is set to 1.0, which MS says is required when there's no
980 D3DPTEXTURECAPS_ALPHAPALETTE capability */
981 for (i
= 0; i
< 256; i
++) {
982 table
[i
].peRed
= table
[i
].peGreen
= table
[i
].peBlue
= 0;
983 table
[i
].peFlags
= 0xff;
985 table
[1].peRed
= 0xff;
986 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 0, table
);
987 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr
);
990 table
[1].peBlue
= 0xff;
991 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 1, table
);
992 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr
);
994 hr
= IDirect3DDevice8_BeginScene(device
);
995 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed, hr = %08x\n", hr
);
997 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_SRCALPHA
);
998 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
999 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1000 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
1002 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
1003 ok(hr
== D3D_OK
, "SetVertexShader failed, hr = %#08x\n", hr
);
1005 hr
= IDirect3DDevice8_SetCurrentTexturePalette(device
, 0);
1006 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr
);
1008 hr
= IDirect3DDevice8_SetTexture(device
, 0, (IDirect3DBaseTexture8
*) texture2
);
1009 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr
);
1010 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
1011 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr
);
1013 hr
= IDirect3DDevice8_SetTexture(device
, 0, (IDirect3DBaseTexture8
*) texture
);
1014 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr
);
1015 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
1016 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr
);
1018 hr
= IDirect3DDevice8_SetCurrentTexturePalette(device
, 1);
1019 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr
);
1020 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, 5 * sizeof(float));
1021 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr
);
1023 hr
= IDirect3DDevice8_EndScene(device
);
1024 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed, hr = %08x\n", hr
);
1027 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
1028 ok(hr
== D3D_OK
, "IDirect3DDevice8_Present failed, hr = %08x\n", hr
);
1030 color
= getPixelColor(device
, 32, 32);
1031 red
= (color
& 0x00ff0000) >> 16;
1032 green
= (color
& 0x0000ff00) >> 8;
1033 blue
= (color
& 0x000000ff) >> 0;
1034 ok(red
== 0xff && blue
== 0 && green
== 0,
1035 "got color %08x, expected 0x00ff0000\n", color
);
1037 color
= getPixelColor(device
, 32, 320);
1038 red
= (color
& 0x00ff0000) >> 16;
1039 green
= (color
& 0x0000ff00) >> 8;
1040 blue
= (color
& 0x000000ff) >> 0;
1041 ok(red
== 0 && blue
== 0xff && green
== 0,
1042 "got color %08x, expected 0x000000ff\n", color
);
1044 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff000000, 0.0, 0);
1045 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed, hr = %08x\n", hr
);
1047 hr
= IDirect3DDevice8_BeginScene(device
);
1048 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed, hr = %08x\n", hr
);
1050 hr
= IDirect3DDevice8_SetTexture(device
, 0, (IDirect3DBaseTexture8
*) texture2
);
1051 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr
);
1053 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
1054 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr
);
1056 hr
= IDirect3DDevice8_EndScene(device
);
1057 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed, hr = %08x\n", hr
);
1060 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
1061 ok(hr
== D3D_OK
, "IDirect3DDevice8_Present failed, hr = %08x\n", hr
);
1063 color
= getPixelColor(device
, 32, 32);
1064 red
= (color
& 0x00ff0000) >> 16;
1065 green
= (color
& 0x0000ff00) >> 8;
1066 blue
= (color
& 0x000000ff) >> 0;
1067 ok(red
== 0 && blue
== 0xff && green
== 0,
1068 "got color %08x, expected 0x000000ff\n", color
);
1070 /* Test palettes with alpha */
1071 IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
1072 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_ALPHAPALETTE
)) {
1073 skip("no D3DPTEXTURECAPS_ALPHAPALETTE capability, tests with alpha in palette will be skipped\n");
1075 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff000000, 0.0, 0);
1076 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed, hr = %08x\n", hr
);
1078 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, TRUE
);
1079 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
1081 for (i
= 0; i
< 256; i
++) {
1082 table
[i
].peRed
= table
[i
].peGreen
= table
[i
].peBlue
= 0;
1083 table
[i
].peFlags
= 0xff;
1085 table
[1].peRed
= 0xff;
1086 table
[1].peFlags
= 0x80;
1087 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 0, table
);
1088 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr
);
1091 table
[1].peBlue
= 0xff;
1092 table
[1].peFlags
= 0x80;
1093 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 1, table
);
1094 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr
);
1096 hr
= IDirect3DDevice8_BeginScene(device
);
1097 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed, hr = %08x\n", hr
);
1099 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_SRCALPHA
);
1100 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
1101 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1102 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
1104 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
1105 ok(hr
== D3D_OK
, "SetVertexShader failed, hr = %#08x\n", hr
);
1107 hr
= IDirect3DDevice8_SetCurrentTexturePalette(device
, 0);
1108 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr
);
1110 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
1111 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr
);
1113 hr
= IDirect3DDevice8_SetCurrentTexturePalette(device
, 1);
1114 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr
);
1116 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, 5 * sizeof(float));
1117 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr
);
1119 hr
= IDirect3DDevice8_EndScene(device
);
1120 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed, hr = %08x\n", hr
);
1123 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
1124 ok(hr
== D3D_OK
, "IDirect3DDevice8_Present failed, hr = %08x\n", hr
);
1126 color
= getPixelColor(device
, 32, 32);
1127 red
= (color
& 0x00ff0000) >> 16;
1128 green
= (color
& 0x0000ff00) >> 8;
1129 blue
= (color
& 0x000000ff) >> 0;
1130 ok(red
>= 0x7e && red
<= 0x81 && blue
== 0 && green
== 0,
1131 "got color %08x, expected 0x00800000 or near\n", color
);
1133 color
= getPixelColor(device
, 32, 320);
1134 red
= (color
& 0x00ff0000) >> 16;
1135 green
= (color
& 0x0000ff00) >> 8;
1136 blue
= (color
& 0x000000ff) >> 0;
1137 ok(red
== 0 && blue
>= 0x7e && blue
<= 0x81 && green
== 0,
1138 "got color %08x, expected 0x00000080 or near\n", color
);
1141 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
1142 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr
);
1143 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, FALSE
);
1144 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
1147 if(texture
) IDirect3DTexture8_Release(texture
);
1148 if(texture2
) IDirect3DTexture8_Release(texture2
);
1149 IDirect3D8_Release(d3d
);
1152 static void texop_test(IDirect3DDevice8
*device
)
1154 IDirect3DTexture8
*texture
= NULL
;
1155 D3DLOCKED_RECT locked_rect
;
1161 static const struct {
1166 {-1.0f
, -1.0f
, 0.1f
, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), -1.0f
, -1.0f
},
1167 {-1.0f
, 1.0f
, 0.1f
, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), -1.0f
, 1.0f
},
1168 { 1.0f
, -1.0f
, 0.1f
, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), 1.0f
, -1.0f
},
1169 { 1.0f
, 1.0f
, 0.1f
, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), 1.0f
, 1.0f
}
1172 static const struct {
1178 {D3DTOP_SELECTARG1
, "SELECTARG1", D3DTEXOPCAPS_SELECTARG1
, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00)},
1179 {D3DTOP_SELECTARG2
, "SELECTARG2", D3DTEXOPCAPS_SELECTARG2
, D3DCOLOR_ARGB(0x00, 0x33, 0x33, 0x33)},
1180 {D3DTOP_MODULATE
, "MODULATE", D3DTEXOPCAPS_MODULATE
, D3DCOLOR_ARGB(0x00, 0x00, 0x33, 0x00)},
1181 {D3DTOP_MODULATE2X
, "MODULATE2X", D3DTEXOPCAPS_MODULATE2X
, D3DCOLOR_ARGB(0x00, 0x00, 0x66, 0x00)},
1182 {D3DTOP_MODULATE4X
, "MODULATE4X", D3DTEXOPCAPS_MODULATE4X
, D3DCOLOR_ARGB(0x00, 0x00, 0xcc, 0x00)},
1183 {D3DTOP_ADD
, "ADD", D3DTEXOPCAPS_ADD
, D3DCOLOR_ARGB(0x00, 0x33, 0xff, 0x33)},
1184 {D3DTOP_ADDSIGNED
, "ADDSIGNED", D3DTEXOPCAPS_ADDSIGNED
, D3DCOLOR_ARGB(0x00, 0x00, 0xb2, 0x00)},
1185 {D3DTOP_ADDSIGNED2X
, "ADDSIGNED2X", D3DTEXOPCAPS_ADDSIGNED2X
, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00)},
1186 {D3DTOP_SUBTRACT
, "SUBTRACT", D3DTEXOPCAPS_SUBTRACT
, D3DCOLOR_ARGB(0x00, 0x00, 0xcc, 0x00)},
1187 {D3DTOP_ADDSMOOTH
, "ADDSMOOTH", D3DTEXOPCAPS_ADDSMOOTH
, D3DCOLOR_ARGB(0x00, 0x33, 0xff, 0x33)},
1188 {D3DTOP_BLENDDIFFUSEALPHA
, "BLENDDIFFUSEALPHA", D3DTEXOPCAPS_BLENDDIFFUSEALPHA
, D3DCOLOR_ARGB(0x00, 0x22, 0x77, 0x22)},
1189 {D3DTOP_BLENDTEXTUREALPHA
, "BLENDTEXTUREALPHA", D3DTEXOPCAPS_BLENDTEXTUREALPHA
, D3DCOLOR_ARGB(0x00, 0x14, 0xad, 0x14)},
1190 {D3DTOP_BLENDFACTORALPHA
, "BLENDFACTORALPHA", D3DTEXOPCAPS_BLENDFACTORALPHA
, D3DCOLOR_ARGB(0x00, 0x07, 0xe4, 0x07)},
1191 {D3DTOP_BLENDTEXTUREALPHAPM
, "BLENDTEXTUREALPHAPM", D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
, D3DCOLOR_ARGB(0x00, 0x14, 0xff, 0x14)},
1192 {D3DTOP_BLENDCURRENTALPHA
, "BLENDCURRENTALPHA", D3DTEXOPCAPS_BLENDCURRENTALPHA
, D3DCOLOR_ARGB(0x00, 0x22, 0x77, 0x22)},
1193 {D3DTOP_MODULATEALPHA_ADDCOLOR
, "MODULATEALPHA_ADDCOLOR", D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
, D3DCOLOR_ARGB(0x00, 0x1f, 0xff, 0x1f)},
1194 {D3DTOP_MODULATECOLOR_ADDALPHA
, "MODULATECOLOR_ADDALPHA", D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
, D3DCOLOR_ARGB(0x00, 0x99, 0xcc, 0x99)},
1195 {D3DTOP_MODULATEINVALPHA_ADDCOLOR
, "MODULATEINVALPHA_ADDCOLOR", D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
, D3DCOLOR_ARGB(0x00, 0x14, 0xff, 0x14)},
1196 {D3DTOP_MODULATEINVCOLOR_ADDALPHA
, "MODULATEINVCOLOR_ADDALPHA", D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
, D3DCOLOR_ARGB(0x00, 0xcc, 0x99, 0xcc)},
1197 /* BUMPENVMAP & BUMPENVMAPLUMINANCE have their own tests */
1198 {D3DTOP_DOTPRODUCT3
, "DOTPRODUCT2", D3DTEXOPCAPS_DOTPRODUCT3
, D3DCOLOR_ARGB(0x00, 0x99, 0x99, 0x99)},
1199 {D3DTOP_MULTIPLYADD
, "MULTIPLYADD", D3DTEXOPCAPS_MULTIPLYADD
, D3DCOLOR_ARGB(0x00, 0xff, 0x33, 0x00)},
1200 {D3DTOP_LERP
, "LERP", D3DTEXOPCAPS_LERP
, D3DCOLOR_ARGB(0x00, 0x00, 0x33, 0x33)},
1203 memset(&caps
, 0, sizeof(caps
));
1204 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
1205 ok(SUCCEEDED(hr
), "GetDeviceCaps failed with 0x%08x\n", hr
);
1207 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_TEX0
);
1208 ok(SUCCEEDED(hr
), "SetVertexShader failed with 0x%08x\n", hr
);
1210 hr
= IDirect3DDevice8_CreateTexture(device
, 1, 1, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &texture
);
1211 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateTexture failed with 0x%08x\n", hr
);
1212 hr
= IDirect3DTexture8_LockRect(texture
, 0, &locked_rect
, NULL
, 0);
1213 ok(SUCCEEDED(hr
), "LockRect failed with 0x%08x\n", hr
);
1214 *((DWORD
*)locked_rect
.pBits
) = D3DCOLOR_ARGB(0x99, 0x00, 0xff, 0x00);
1215 hr
= IDirect3DTexture8_UnlockRect(texture
, 0);
1216 ok(SUCCEEDED(hr
), "LockRect failed with 0x%08x\n", hr
);
1217 hr
= IDirect3DDevice8_SetTexture(device
, 0, (IDirect3DBaseTexture8
*)texture
);
1218 ok(SUCCEEDED(hr
), "SetTexture failed with 0x%08x\n", hr
);
1220 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLORARG0
, D3DTA_DIFFUSE
);
1221 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
1222 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
1223 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
1224 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_TFACTOR
);
1225 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
1227 hr
= IDirect3DDevice8_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
1228 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
1230 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
1231 ok(SUCCEEDED(hr
), "SetRenderState failed with 0x%08x\n", hr
);
1232 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_TEXTUREFACTOR
, 0xdd333333);
1233 ok(SUCCEEDED(hr
), "SetRenderState failed with 0x%08x\n", hr
);
1234 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_COLORWRITEENABLE
, D3DCOLORWRITEENABLE_RED
| D3DCOLORWRITEENABLE_GREEN
| D3DCOLORWRITEENABLE_BLUE
| D3DCOLORWRITEENABLE_ALPHA
);
1235 ok(SUCCEEDED(hr
), "SetRenderState failed with 0x%08x\n", hr
);
1237 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x00000000, 1.0f
, 0);
1238 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Clear failed with 0x%08x\n", hr
);
1240 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
1242 if (!(caps
.TextureOpCaps
& test_data
[i
].caps_flag
))
1244 skip("tex operation %s not supported\n", test_data
[i
].name
);
1248 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, test_data
[i
].op
);
1249 ok(SUCCEEDED(hr
), "SetTextureStageState (%s) failed with 0x%08x\n", test_data
[i
].name
, hr
);
1251 hr
= IDirect3DDevice8_BeginScene(device
);
1252 ok(SUCCEEDED(hr
), "BeginScene failed with 0x%08x\n", hr
);
1254 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
1255 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed with 0x%08x\n", hr
);
1257 hr
= IDirect3DDevice8_EndScene(device
);
1258 ok(SUCCEEDED(hr
), "EndScene failed with 0x%08x\n", hr
);
1260 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
1261 ok(SUCCEEDED(hr
), "Present failed with 0x%08x\n", hr
);
1263 color
= getPixelColor(device
, 320, 240);
1264 ok(color_match(color
, test_data
[i
].result
, 3), "Operation %s returned color 0x%08x, expected 0x%08x\n",
1265 test_data
[i
].name
, color
, test_data
[i
].result
);
1268 if (texture
) IDirect3DTexture8_Release(texture
);
1273 IDirect3DDevice8
*device_ptr
;
1278 d3d8_handle
= LoadLibraryA("d3d8.dll");
1281 win_skip("Could not load d3d8.dll\n");
1285 device_ptr
= init_d3d8();
1288 win_skip("Could not initialize direct3d\n");
1292 IDirect3DDevice8_GetDeviceCaps(device_ptr
, &caps
);
1294 /* Check for the reliability of the returned data */
1295 hr
= IDirect3DDevice8_Clear(device_ptr
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
1298 skip("Clear failed, can't assure correctness of the test results\n");
1301 IDirect3DDevice8_Present(device_ptr
, NULL
, NULL
, NULL
, NULL
);
1303 color
= getPixelColor(device_ptr
, 1, 1);
1304 if(color
!=0x00ff0000)
1306 skip("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests\n", color
);
1310 hr
= IDirect3DDevice8_Clear(device_ptr
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ddee, 0.0, 0);
1313 skip("Clear failed, can't assure correctness of the test results\n");
1316 IDirect3DDevice8_Present(device_ptr
, NULL
, NULL
, NULL
, NULL
);
1318 color
= getPixelColor(device_ptr
, 639, 479);
1319 if(color
!= 0x0000ddee)
1321 skip("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests\n", color
);
1325 /* Now run the real test */
1326 lighting_test(device_ptr
);
1327 clear_test(device_ptr
);
1328 fog_test(device_ptr
);
1329 present_test(device_ptr
);
1330 offscreen_test(device_ptr
);
1331 alpha_test(device_ptr
);
1333 if (caps
.VertexShaderVersion
>= D3DVS_VERSION(1, 1))
1335 test_rcp_rsq(device_ptr
);
1339 skip("No vs.1.1 support\n");
1342 p8_texture_test(device_ptr
);
1343 texop_test(device_ptr
);
1347 D3DDEVICE_CREATION_PARAMETERS creation_parameters
;
1350 IDirect3DDevice8_GetCreationParameters(device_ptr
, &creation_parameters
);
1351 DestroyWindow(creation_parameters
.hFocusWindow
);
1352 refcount
= IDirect3DDevice8_Release(device_ptr
);
1353 ok(!refcount
, "Device has %u references left\n", refcount
);