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 */
25 #include "wine/test.h"
27 static HMODULE d3d8_handle
= 0;
29 static HWND
create_window(void)
33 wc
.lpfnWndProc
= &DefWindowProc
;
34 wc
.lpszClassName
= "d3d8_test_wc";
37 ret
= CreateWindow("d3d8_test_wc", "d3d8_test",
38 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
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 IDirect3DSurface8
*surf
;
58 IDirect3DTexture8
*tex
;
60 D3DLOCKED_RECT lockedRect
;
61 RECT rectToLock
= {x
, y
, x
+1, y
+1};
63 hr
= IDirect3DDevice8_CreateTexture(device
, 640, 480, 1 /* Levels */, 0 /* usage */, 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_GetFrontBuffer(device
, surf
);
80 trace("Can't read the front buffer data, hr=%#08x\n", hr
);
85 hr
= IDirect3DSurface8_LockRect(surf
, &lockedRect
, &rectToLock
, D3DLOCK_READONLY
);
88 trace("Can't lock the offscreen surface, hr=%#08x\n", hr
);
92 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
93 * really important for these tests
95 ret
= ((DWORD
*) lockedRect
.pBits
)[0] & 0x00ffffff;
96 hr
= IDirect3DSurface8_UnlockRect(surf
);
99 trace("Can't unlock the offscreen surface, hr=%#08x\n", hr
);
103 if(surf
) IDirect3DSurface8_Release(surf
);
104 if(tex
) IDirect3DTexture8_Release(tex
);
108 static IDirect3DDevice8
*init_d3d8(void)
110 IDirect3D8
* (__stdcall
* d3d8_create
)(UINT SDKVersion
) = 0;
111 IDirect3D8
*d3d8_ptr
= 0;
112 IDirect3DDevice8
*device_ptr
= 0;
113 D3DPRESENT_PARAMETERS present_parameters
;
116 d3d8_create
= (void *)GetProcAddress(d3d8_handle
, "Direct3DCreate8");
117 ok(d3d8_create
!= NULL
, "Failed to get address of Direct3DCreate8\n");
118 if (!d3d8_create
) return NULL
;
120 d3d8_ptr
= d3d8_create(D3D_SDK_VERSION
);
121 ok(d3d8_ptr
!= NULL
, "Failed to create IDirect3D8 object\n");
122 if (!d3d8_ptr
) return NULL
;
124 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
125 present_parameters
.Windowed
= FALSE
;
126 present_parameters
.hDeviceWindow
= create_window();
127 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
128 present_parameters
.BackBufferWidth
= 640;
129 present_parameters
.BackBufferHeight
= 480;
130 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
131 present_parameters
.EnableAutoDepthStencil
= TRUE
;
132 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D16
;
134 hr
= IDirect3D8_CreateDevice(d3d8_ptr
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, present_parameters
.hDeviceWindow
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device_ptr
);
135 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "IDirect3D_CreateDevice returned: %#08x\n", hr
);
153 static void lighting_test(IDirect3DDevice8
*device
)
156 DWORD fvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
157 DWORD nfvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_NORMAL
;
160 float mat
[16] = { 1.0f
, 0.0f
, 0.0f
, 0.0f
,
161 0.0f
, 1.0f
, 0.0f
, 0.0f
,
162 0.0f
, 0.0f
, 1.0f
, 0.0f
,
163 0.0f
, 0.0f
, 0.0f
, 1.0f
};
165 struct vertex unlitquad
[] =
167 {-1.0f
, -1.0f
, 0.1f
, 0xffff0000},
168 {-1.0f
, 0.0f
, 0.1f
, 0xffff0000},
169 { 0.0f
, 0.0f
, 0.1f
, 0xffff0000},
170 { 0.0f
, -1.0f
, 0.1f
, 0xffff0000},
172 struct vertex litquad
[] =
174 {-1.0f
, 0.0f
, 0.1f
, 0xff00ff00},
175 {-1.0f
, 1.0f
, 0.1f
, 0xff00ff00},
176 { 0.0f
, 1.0f
, 0.1f
, 0xff00ff00},
177 { 0.0f
, 0.0f
, 0.1f
, 0xff00ff00},
179 struct nvertex unlitnquad
[] =
181 { 0.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
182 { 0.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
183 { 1.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
184 { 1.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
186 struct nvertex litnquad
[] =
188 { 0.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
189 { 0.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
190 { 1.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
191 { 1.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
193 WORD Indices
[] = {0, 1, 2, 2, 3, 0};
195 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
196 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed with %#08x\n", hr
);
198 /* Setup some states that may cause issues */
199 hr
= IDirect3DDevice8_SetTransform(device
, D3DTS_WORLDMATRIX(0), (D3DMATRIX
*) mat
);
200 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTransform returned %#08x\n", hr
);
201 hr
= IDirect3DDevice8_SetTransform(device
, D3DTS_VIEW
, (D3DMATRIX
*)mat
);
202 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTransform returned %#08x\n", hr
);
203 hr
= IDirect3DDevice8_SetTransform(device
, D3DTS_PROJECTION
, (D3DMATRIX
*) mat
);
204 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTransform returned %#08x\n", hr
);
205 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_CLIPPING
, FALSE
);
206 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
207 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
208 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
209 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGENABLE
, FALSE
);
210 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
211 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_STENCILENABLE
, FALSE
);
212 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
213 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ALPHATESTENABLE
, FALSE
);
214 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
215 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, FALSE
);
216 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
217 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_CULLMODE
, D3DCULL_NONE
);
218 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed with %#08x\n", hr
);
219 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_COLORWRITEENABLE
, D3DCOLORWRITEENABLE_RED
| D3DCOLORWRITEENABLE_GREEN
| D3DCOLORWRITEENABLE_BLUE
);
220 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed with %#08x\n", hr
);
222 hr
= IDirect3DDevice8_SetVertexShader(device
, fvf
);
223 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
225 hr
= IDirect3DDevice8_BeginScene(device
);
226 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr
);
229 /* No lights are defined... That means, lit vertices should be entirely black */
230 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
231 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
232 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
233 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, unlitquad
, sizeof(unlitquad
[0]));
234 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr
);
236 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, TRUE
);
237 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
238 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
239 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, litquad
, sizeof(litquad
[0]));
240 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr
);
242 hr
= IDirect3DDevice8_SetVertexShader(device
, nfvf
);
243 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader failed with %#08x\n", hr
);
245 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
246 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
247 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
248 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, unlitnquad
, sizeof(unlitnquad
[0]));
249 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr
);
251 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, TRUE
);
252 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
253 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
254 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, litnquad
, sizeof(litnquad
[0]));
255 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr
);
257 IDirect3DDevice8_EndScene(device
);
258 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed with %#08x\n", hr
);
261 IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
263 color
= getPixelColor(device
, 160, 360); /* lower left quad - unlit without normals */
264 ok(color
== 0x00ff0000, "Unlit quad without normals has color %08x\n", color
);
265 color
= getPixelColor(device
, 160, 120); /* upper left quad - lit without normals */
266 ok(color
== 0x00000000, "Lit quad without normals has color %08x\n", color
);
267 color
= getPixelColor(device
, 480, 360); /* lower left quad - unlit width normals */
268 ok(color
== 0x000000ff, "Unlit quad width normals has color %08x\n", color
);
269 color
= getPixelColor(device
, 480, 120); /* upper left quad - lit width normals */
270 ok(color
== 0x00000000, "Lit quad width normals has color %08x\n", color
);
272 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
273 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr
);
276 static void clear_test(IDirect3DDevice8
*device
)
278 /* Tests the correctness of clearing parameters */
284 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
285 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed with %#08x\n", hr
);
287 /* Positive x, negative y */
293 /* Positive x, positive y */
298 /* Clear 2 rectangles with one call. Shows that a positive value is returned, but the negative rectangle
299 * is ignored, the positive is still cleared afterwards
301 hr
= IDirect3DDevice8_Clear(device
, 2, rect
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
302 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed with %#08x\n", hr
);
304 /* negative x, negative y */
305 rect_negneg
.x1
= 640;
306 rect_negneg
.x1
= 240;
307 rect_negneg
.x2
= 320;
309 hr
= IDirect3DDevice8_Clear(device
, 1, &rect_negneg
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0, 0);
310 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed with %#08x\n", hr
);
312 IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
314 color
= getPixelColor(device
, 160, 360); /* lower left quad */
315 ok(color
== 0x00ffffff, "Clear rectangle 3(pos, neg) has color %08x\n", color
);
316 color
= getPixelColor(device
, 160, 120); /* upper left quad */
317 ok(color
== 0x00ff0000, "Clear rectangle 1(pos, pos) has color %08x\n", color
);
318 color
= getPixelColor(device
, 480, 360); /* lower right quad */
319 ok(color
== 0x00ffffff, "Clear rectangle 4(NULL) has color %08x\n", color
);
320 color
= getPixelColor(device
, 480, 120); /* upper right quad */
321 ok(color
== 0x00ffffff, "Clear rectangle 4(neg, neg) has color %08x\n", color
);
336 static void fog_test(IDirect3DDevice8
*device
)
340 float start
= 0.0, end
= 1.0;
342 /* Gets full z based fog with linear fog, no fog with specular color */
343 struct sVertex unstransformed_1
[] = {
344 {-1, -1, 0.1f
, 0xFFFF0000, 0xFF000000 },
345 {-1, 0, 0.1f
, 0xFFFF0000, 0xFF000000 },
346 { 0, 0, 0.1f
, 0xFFFF0000, 0xFF000000 },
347 { 0, -1, 0.1f
, 0xFFFF0000, 0xFF000000 },
349 /* Ok, I am too lazy to deal with transform matrices */
350 struct sVertex unstransformed_2
[] = {
351 {-1, 0, 1.0f
, 0xFFFF0000, 0xFF000000 },
352 {-1, 1, 1.0f
, 0xFFFF0000, 0xFF000000 },
353 { 0, 1, 1.0f
, 0xFFFF0000, 0xFF000000 },
354 { 0, 0, 1.0f
, 0xFFFF0000, 0xFF000000 },
356 /* Untransformed ones. Give them a different diffuse color to make the test look
357 * nicer. It also makes making sure that they are drawn correctly easier.
359 struct sVertexT transformed_1
[] = {
360 {320, 0, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
361 {640, 0, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
362 {640, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
363 {320, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
365 struct sVertexT transformed_2
[] = {
366 {320, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
367 {640, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
368 {640, 480, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
369 {320, 480, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
371 WORD Indices
[] = {0, 1, 2, 2, 3, 0};
373 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
374 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear returned %#08x\n", hr
);
376 /* Setup initial states: No lighting, fog on, fog color */
377 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
378 ok(hr
== D3D_OK
, "Turning off lighting returned %#08x\n", hr
);
379 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGENABLE
, TRUE
);
380 ok(hr
== D3D_OK
, "Turning on fog calculations returned %#08x\n", hr
);
381 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGCOLOR
, 0xFF00FF00 /* A nice green */);
382 ok(hr
== D3D_OK
, "Turning on fog calculations returned %#08x\n", hr
);
384 /* First test: Both table fog and vertex fog off */
385 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGTABLEMODE
, D3DFOG_NONE
);
386 ok(hr
== D3D_OK
, "Turning off table fog returned %#08x\n", hr
);
387 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, D3DFOG_NONE
);
388 ok(hr
== D3D_OK
, "Turning off table fog returned %#08x\n", hr
);
390 /* Start = 0, end = 1. Should be default, but set them */
391 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGSTART
, *((DWORD
*) &start
));
392 ok(hr
== D3D_OK
, "Setting fog start returned %#08x\n", hr
);
393 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGEND
, *((DWORD
*) &end
));
394 ok(hr
== D3D_OK
, "Setting fog start returned %#08x\n", hr
);
396 if(IDirect3DDevice8_BeginScene(device
) == D3D_OK
)
398 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
);
399 ok( hr
== D3D_OK
, "SetVertexShader returned %#08x\n", hr
);
400 /* Untransformed, vertex fog = NONE, table fog = NONE: Read the fog weighting from the specular color */
401 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
402 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, unstransformed_1
,
403 sizeof(unstransformed_1
[0]));
404 ok(hr
== D3D_OK
, "DrawIndexedPrimitiveUP returned %#08x\n", hr
);
406 /* That makes it use the Z value */
407 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, D3DFOG_LINEAR
);
408 ok(hr
== D3D_OK
, "Turning off table fog returned %#08x\n", hr
);
409 /* Untransformed, vertex fog != none (or table fog != none):
410 * Use the Z value as input into the equation
412 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
413 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, unstransformed_2
,
414 sizeof(unstransformed_1
[0]));
415 ok(hr
== D3D_OK
, "DrawIndexedPrimitiveUP returned %#08x\n", hr
);
417 /* transformed verts */
418 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
);
419 ok( hr
== D3D_OK
, "SetVertexShader returned %#08x\n", hr
);
420 /* Transformed, vertex fog != NONE, pixel fog == NONE: Use specular color alpha component */
421 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
422 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, transformed_1
,
423 sizeof(transformed_1
[0]));
424 ok(hr
== D3D_OK
, "DrawIndexedPrimitiveUP returned %#08x\n", hr
);
426 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGTABLEMODE
, D3DFOG_LINEAR
);
427 ok( hr
== D3D_OK
, "Setting fog table mode to D3DFOG_LINEAR returned %#08x\n", hr
);
428 /* Transformed, table fog != none, vertex anything: Use Z value as input to the fog
431 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
432 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, transformed_2
,
433 sizeof(transformed_2
[0]));
435 hr
= IDirect3DDevice8_EndScene(device
);
436 ok(hr
== D3D_OK
, "EndScene returned %#08x\n", hr
);
440 ok(FALSE
, "BeginScene failed\n");
443 IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
444 color
= getPixelColor(device
, 160, 360);
445 ok(color
== 0x00FF0000, "Untransformed vertex with no table or vertex fog has color %08x\n", color
);
446 color
= getPixelColor(device
, 160, 120);
447 ok(color
== 0x0000FF00, "Untransformed vertex with linear vertex fog has color %08x\n", color
);
448 color
= getPixelColor(device
, 480, 120);
449 ok(color
== 0x00FFFF00, "Transformed vertex with linear vertex fog has color %08x\n", color
);
450 color
= getPixelColor(device
, 480, 360);
451 ok(color
== 0x0000FF00, "Transformed vertex with linear table fog has color %08x\n", color
);
453 /* Turn off the fog master switch to avoid confusing other tests */
454 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_FOGENABLE
, FALSE
);
455 ok(hr
== D3D_OK
, "Turning off fog calculations returned %#08x\n", hr
);
458 static void present_test(IDirect3DDevice8
*device
)
460 struct vertex quad
[] =
462 {-1.0f
, -1.0f
, 0.9f
, 0xffff0000},
463 {-1.0f
, 1.0f
, 0.9f
, 0xffff0000},
464 { 1.0f
, -1.0f
, 0.1f
, 0xffff0000},
465 { 1.0f
, 1.0f
, 0.1f
, 0xffff0000},
470 /* Does the Present clear the depth stencil? Clear the depth buffer with some value != 0,
471 * then call Present. Then clear the color buffer to make sure it has some defined content
472 * after the Present with D3DSWAPEFFECT_DISCARD. After that draw a plane that is somewhere cut
473 * by the depth value.
475 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffffff, 0.75, 0);
476 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear returned %s\n", DXGetErrorString8(hr
));
477 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
478 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.4, 0);
480 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_TRUE
);
481 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %s\n", DXGetErrorString8(hr
));
482 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_GREATER
);
483 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %s\n", DXGetErrorString8(hr
));
484 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
485 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetFVF returned %s\n", DXGetErrorString8(hr
));
487 hr
= IDirect3DDevice8_BeginScene(device
);
488 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed with %s\n", DXGetErrorString8(hr
));
491 /* No lights are defined... That means, lit vertices should be entirely black */
492 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2 /*PrimCount */, quad
, sizeof(quad
[0]));
493 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %s\n", DXGetErrorString8(hr
));
495 hr
= IDirect3DDevice8_EndScene(device
);
496 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed with %s\n", DXGetErrorString8(hr
));
499 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_FALSE
);
500 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %s\n", DXGetErrorString8(hr
));
502 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
503 ok(SUCCEEDED(hr
), "Present failed (%#08x)\n", hr
);
504 color
= getPixelColor(device
, 512, 240);
505 ok(color
== 0x00ffffff, "Present failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
506 color
= getPixelColor(device
, 64, 240);
507 ok(color
== 0x00ff0000, "Present failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
510 static void test_rcp_rsq(IDirect3DDevice8
*device
)
515 unsigned char c1
, c2
, c3
;
516 float constant
[4] = {1.0, 1.0, 1.0, 2.0};
518 static const float quad
[][3] = {
519 {-1.0f
, -1.0f
, 0.0f
},
521 { 1.0f
, -1.0f
, 0.0f
},
525 const DWORD rcp_test
[] = {
526 0xfffe0101, /* vs.1.1 */
528 0x0009fffe, 0x30303030, 0x30303030, /* Shaders have to have a minimal size. */
529 0x30303030, 0x30303030, 0x30303030, /* Add a filler comment. Usually D3DX8's*/
530 0x30303030, 0x30303030, 0x30303030, /* version comment makes the shader big */
531 0x00303030, /* enough to make windows happy */
533 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
534 0x00000006, 0xd00f0000, 0xa0e40000, /* rcp oD0, c0 */
538 const DWORD rsq_test
[] = {
539 0xfffe0101, /* vs.1.1 */
541 0x0009fffe, 0x30303030, 0x30303030, /* Shaders have to have a minimal size. */
542 0x30303030, 0x30303030, 0x30303030, /* Add a filler comment. Usually D3DX8's*/
543 0x30303030, 0x30303030, 0x30303030, /* version comment makes the shader big */
544 0x00303030, /* enough to make windows happy */
546 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
547 0x00000007, 0xd00f0000, 0xa0e40000, /* rsq oD0, c0 */
554 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
558 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff800080, 0.0, 0);
559 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed with %#08x\n", hr
);
561 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, rcp_test
, &shader
, 0);
562 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned with %#08x\n", hr
);
564 IDirect3DDevice8_SetVertexShader(device
, shader
);
565 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
566 IDirect3DDevice8_SetVertexShaderConstant(device
, 0, constant
, 1);
568 hr
= IDirect3DDevice8_BeginScene(device
);
569 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene returned %#08x\n", hr
);
572 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad
[0], 3 * sizeof(float));
573 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%#08x)\n", hr
);
574 hr
= IDirect3DDevice8_EndScene(device
);
575 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
578 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
579 ok(SUCCEEDED(hr
), "Present failed (%#08x)\n", hr
);
580 color
= getPixelColor(device
, 320, 240);
581 c1
= (color
& 0x00ff0000 )>> 16;
582 c2
= (color
& 0x0000ff00 )>> 8;
583 c3
= (color
& 0x000000ff )>> 0;
584 ok(c1
== c2
&& c2
== c3
, "Color components differ: c1 = %02x, c2 = %02x, c3 = %02x\n",
586 ok(c1
>= 0x7c && c1
<= 0x84, "Color component value is %02x\n", c1
);
588 IDirect3DDevice8_SetVertexShader(device
, 0);
589 IDirect3DDevice8_DeleteVertexShader(device
, shader
);
591 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff800080, 0.0, 0);
592 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed with %#08x\n", hr
);
594 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, rsq_test
, &shader
, 0);
595 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned with %#08x\n", hr
);
597 IDirect3DDevice8_SetVertexShader(device
, shader
);
598 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
599 IDirect3DDevice8_SetVertexShaderConstant(device
, 0, constant
, 1);
601 hr
= IDirect3DDevice8_BeginScene(device
);
602 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene returned %#08x\n", hr
);
605 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad
[0], 3 * sizeof(float));
606 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%#08x)\n", hr
);
607 hr
= IDirect3DDevice8_EndScene(device
);
608 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
611 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
612 ok(SUCCEEDED(hr
), "Present failed (%#08x)\n", hr
);
613 color
= getPixelColor(device
, 320, 240);
614 c1
= (color
& 0x00ff0000 )>> 16;
615 c2
= (color
& 0x0000ff00 )>> 8;
616 c3
= (color
& 0x000000ff )>> 0;
617 ok(c1
== c2
&& c2
== c3
, "Color components differ: c1 = %02x, c2 = %02x, c3 = %02x\n",
619 ok(c1
>= 0xb0 && c1
<= 0xb8, "Color component value is %02x\n", c1
);
621 IDirect3DDevice8_SetVertexShader(device
, 0);
622 IDirect3DDevice8_DeleteVertexShader(device
, shader
);
625 static void offscreen_test(IDirect3DDevice8
*device
)
628 IDirect3DTexture8
*offscreenTexture
= NULL
;
629 IDirect3DSurface8
*backbuffer
= NULL
, *offscreen
= NULL
, *depthstencil
= NULL
;
632 static const float quad
[][5] = {
633 {-0.5f
, -0.5f
, 0.1f
, 0.0f
, 0.0f
},
634 {-0.5f
, 0.5f
, 0.1f
, 0.0f
, 1.0f
},
635 { 0.5f
, -0.5f
, 0.1f
, 1.0f
, 0.0f
},
636 { 0.5f
, 0.5f
, 0.1f
, 1.0f
, 1.0f
},
639 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &depthstencil
);
640 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetDepthStencilSurface failed, hr = %#08x\n", hr
);
642 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
643 ok(hr
== D3D_OK
, "Clear failed, hr = %#08x\n", hr
);
645 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &offscreenTexture
);
646 ok(hr
== D3D_OK
|| D3DERR_INVALIDCALL
, "Creating the offscreen render target failed, hr = %#08x\n", hr
);
647 if(!offscreenTexture
) {
648 trace("Failed to create an X8R8G8B8 offscreen texture, trying R5G6B5\n");
649 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
, D3DFMT_R5G6B5
, D3DPOOL_DEFAULT
, &offscreenTexture
);
650 ok(hr
== D3D_OK
|| D3DERR_INVALIDCALL
, "Creating the offscreen render target failed, hr = %#08x\n", hr
);
651 if(!offscreenTexture
) {
652 skip("Cannot create an offscreen render target\n");
657 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
658 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %#08x\n", hr
);
663 hr
= IDirect3DTexture8_GetSurfaceLevel(offscreenTexture
, 0, &offscreen
);
664 ok(hr
== D3D_OK
, "Can't get offscreen surface, hr = %#08x\n", hr
);
669 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
670 ok(hr
== D3D_OK
, "SetVertexShader failed, hr = %#08x\n", hr
);
672 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
673 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %#08x\n", hr
);
674 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
675 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %#08x\n", hr
);
676 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_MINFILTER
, D3DTEXF_NONE
);
677 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MINFILTER failed (%#08x)\n", hr
);
678 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_MAGFILTER
, D3DTEXF_NONE
);
679 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MAGFILTER failed (%#08x)\n", hr
);
680 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
681 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %s\n", DXGetErrorString8(hr
));
683 if(IDirect3DDevice8_BeginScene(device
) == D3D_OK
) {
684 hr
= IDirect3DDevice8_SetRenderTarget(device
, offscreen
, depthstencil
);
685 ok(hr
== D3D_OK
, "SetRenderTarget failed, hr = %#08x\n", hr
);
686 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
687 ok(hr
== D3D_OK
, "Clear failed, hr = %#08x\n", hr
);
689 /* Draw without textures - Should result in a white quad */
690 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(quad
[0]));
691 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
693 hr
= IDirect3DDevice8_SetRenderTarget(device
, backbuffer
, depthstencil
);
694 ok(hr
== D3D_OK
, "SetRenderTarget failed, hr = %#08x\n", hr
);
695 hr
= IDirect3DDevice8_SetTexture(device
, 0, (IDirect3DBaseTexture8
*) offscreenTexture
);
696 ok(hr
== D3D_OK
, "SetTexture failed, %s\n", DXGetErrorString8(hr
));
698 /* This time with the texture */
699 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(quad
[0]));
700 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
702 IDirect3DDevice8_EndScene(device
);
705 IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
707 /* Center quad - should be white */
708 color
= getPixelColor(device
, 320, 240);
709 ok(color
== 0x00ffffff, "Offscreen failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
710 /* Some quad in the cleared part of the texture */
711 color
= getPixelColor(device
, 170, 240);
712 ok(color
== 0x00ff00ff, "Offscreen failed: Got color 0x%08x, expected 0x00ff00ff.\n", color
);
713 /* Part of the originally cleared back buffer */
714 color
= getPixelColor(device
, 10, 10);
715 ok(color
== 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
717 /* Lower left corner of the screen, where back buffer offscreen rendering draws the offscreen texture.
718 * It should be red, but the offscreen texture may leave some junk there. Not tested yet. Depending on
719 * the offscreen rendering mode this test would succeed or fail
721 color
= getPixelColor(device
, 10, 470);
722 ok(color
== 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
726 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
730 hr
= IDirect3DDevice8_SetRenderTarget(device
, backbuffer
, depthstencil
);
731 IDirect3DSurface8_Release(backbuffer
);
733 if(offscreenTexture
) {
734 IDirect3DTexture8_Release(offscreenTexture
);
737 IDirect3DSurface8_Release(offscreen
);
740 IDirect3DSurface8_Release(depthstencil
);
744 static void alpha_test(IDirect3DDevice8
*device
)
747 IDirect3DTexture8
*offscreenTexture
;
748 IDirect3DSurface8
*backbuffer
= NULL
, *offscreen
= NULL
, *depthstencil
= NULL
;
749 DWORD color
, red
, green
, blue
;
751 struct vertex quad1
[] =
753 {-1.0f
, -1.0f
, 0.1f
, 0x4000ff00},
754 {-1.0f
, 0.0f
, 0.1f
, 0x4000ff00},
755 { 1.0f
, -1.0f
, 0.1f
, 0x4000ff00},
756 { 1.0f
, 0.0f
, 0.1f
, 0x4000ff00},
758 struct vertex quad2
[] =
760 {-1.0f
, 0.0f
, 0.1f
, 0xc00000ff},
761 {-1.0f
, 1.0f
, 0.1f
, 0xc00000ff},
762 { 1.0f
, 0.0f
, 0.1f
, 0xc00000ff},
763 { 1.0f
, 1.0f
, 0.1f
, 0xc00000ff},
765 static const float composite_quad
[][5] = {
766 { 0.0f
, -1.0f
, 0.1f
, 0.0f
, 1.0f
},
767 { 0.0f
, 1.0f
, 0.1f
, 0.0f
, 0.0f
},
768 { 1.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
},
769 { 1.0f
, 1.0f
, 0.1f
, 1.0f
, 0.0f
},
772 /* Clear the render target with alpha = 0.5 */
773 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x80ff0000, 0.0, 0);
774 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
776 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &offscreenTexture
);
777 ok(hr
== D3D_OK
|| D3DERR_INVALIDCALL
, "Creating the offscreen render target failed, hr = %#08x\n", hr
);
779 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &depthstencil
);
780 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetDepthStencilSurface failed, hr = %#08x\n", hr
);
782 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
783 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %#08x\n", hr
);
787 hr
= IDirect3DTexture8_GetSurfaceLevel(offscreenTexture
, 0, &offscreen
);
788 ok(hr
== D3D_OK
, "Can't get offscreen surface, hr = %#08x\n", hr
);
793 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
794 ok(hr
== D3D_OK
, "SetVertexShader failed, hr = %#08x\n", hr
);
796 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
797 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %#08x\n", hr
);
798 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
799 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %#08x\n", hr
);
800 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_MINFILTER
, D3DTEXF_NONE
);
801 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MINFILTER failed (%#08x)\n", hr
);
802 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_MAGFILTER
, D3DTEXF_NONE
);
803 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MAGFILTER failed (%#08x)\n", hr
);
804 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
805 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState returned %s\n", DXGetErrorString8(hr
));
807 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, TRUE
);
808 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
809 if(IDirect3DDevice8_BeginScene(device
) == D3D_OK
) {
811 /* Draw two quads, one with src alpha blending, one with dest alpha blending. */
812 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_SRCALPHA
);
813 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
814 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
815 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
816 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(quad1
[0]));
817 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
819 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_DESTALPHA
);
820 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
821 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVDESTALPHA
);
822 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
823 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(quad2
[0]));
824 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
826 /* Switch to the offscreen buffer, and redo the testing. The offscreen render target
827 * doesn't have an alpha channel. DESTALPHA and INVDESTALPHA "don't work" on render
828 * targets without alpha channel, they give essentially ZERO and ONE blend factors. */
829 hr
= IDirect3DDevice8_SetRenderTarget(device
, offscreen
, 0);
830 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %08x\n", hr
);
831 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x80ff0000, 0.0, 0);
832 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
834 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_SRCALPHA
);
835 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
836 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
837 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
838 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(quad1
[0]));
839 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
841 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_DESTALPHA
);
842 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
843 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVDESTALPHA
);
844 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
845 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(quad2
[0]));
846 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
848 hr
= IDirect3DDevice8_SetRenderTarget(device
, backbuffer
, depthstencil
);
849 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %08x\n", hr
);
851 /* Render the offscreen texture onto the frame buffer to be able to compare it regularly.
852 * Disable alpha blending for the final composition
854 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, FALSE
);
855 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
856 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
857 ok(hr
== D3D_OK
, "SetVertexShader failed, hr = %#08x\n", hr
);
859 hr
= IDirect3DDevice8_SetTexture(device
, 0, (IDirect3DBaseTexture8
*) offscreenTexture
);
860 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr
);
861 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, composite_quad
, sizeof(float) * 5);
862 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
863 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
864 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr
);
866 hr
= IDirect3DDevice8_EndScene(device
);
867 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndScene failed, hr = %08x\n", hr
);
870 IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
872 color
= getPixelColor(device
, 160, 360);
873 red
= (color
& 0x00ff0000) >> 16;
874 green
= (color
& 0x0000ff00) >> 8;
875 blue
= (color
& 0x000000ff);
876 ok(red
>= 0xbe && red
<= 0xc0 && green
>= 0x39 && green
<= 0x41 && blue
== 0x00,
877 "SRCALPHA on frame buffer returned color %08x, expected 0x00bf4000\n", color
);
879 color
= getPixelColor(device
, 160, 120);
880 red
= (color
& 0x00ff0000) >> 16;
881 green
= (color
& 0x0000ff00) >> 8;
882 blue
= (color
& 0x000000ff);
883 ok(red
>= 0x7e && red
<= 0x81 && green
== 0x00 && blue
>= 0x7e && blue
<= 0x81,
884 "DSTALPHA on frame buffer returned color %08x, expected 0x00ff0000\n", color
);
886 color
= getPixelColor(device
, 480, 360);
887 red
= (color
& 0x00ff0000) >> 16;
888 green
= (color
& 0x0000ff00) >> 8;
889 blue
= (color
& 0x000000ff);
890 ok(red
>= 0xbe && red
<= 0xc0 && green
>= 0x39 && green
<= 0x41 && blue
== 0x00,
891 "SRCALPHA on texture returned color %08x, expected bar\n", color
);
893 color
= getPixelColor(device
, 480, 120);
894 red
= (color
& 0x00ff0000) >> 16;
895 green
= (color
& 0x0000ff00) >> 8;
896 blue
= (color
& 0x000000ff);
897 ok(red
== 0x00 && green
== 0x00 && blue
>= 0xfe && blue
<= 0xff ,
898 "DSTALPHA on texture returned color %08x, expected foo\n", color
);
903 IDirect3DSurface8_Release(backbuffer
);
905 if(offscreenTexture
) {
906 IDirect3DTexture8_Release(offscreenTexture
);
909 IDirect3DSurface8_Release(offscreen
);
912 IDirect3DSurface8_Release(depthstencil
);
916 static void p8_texture_test(IDirect3DDevice8
*device
)
918 IDirect3D8
*d3d
= NULL
;
920 IDirect3DTexture8
*texture
= NULL
, *texture2
= NULL
;
923 DWORD color
, red
, green
, blue
;
924 PALETTEENTRY table
[256];
928 -1.0, 0, 0.1, 0.0, 0.0,
929 -1.0, 1.0, 0.1, 0.0, 1.0,
930 1.0, 0, 0.1, 1.0, 0.0,
931 1.0, 1.0, 0.1, 1.0, 1.0,
934 -1.0, -1.0, 0.1, 0.0, 0.0,
935 -1.0, 0, 0.1, 0.0, 1.0,
936 1.0, -1.0, 0.1, 1.0, 0.0,
937 1.0, 0, 0.1, 1.0, 1.0,
940 IDirect3DDevice8_GetDirect3D(device
, &d3d
);
942 if(IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
, 0,
943 D3DRTYPE_TEXTURE
, D3DFMT_P8
) != D3D_OK
) {
944 skip("D3DFMT_P8 textures not supported\n");
948 hr
= IDirect3DDevice8_CreateTexture(device
, 1, 1, 1, 0, D3DFMT_P8
,
949 D3DPOOL_MANAGED
, &texture2
);
950 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateTexture failed, hr = %08x\n", hr
);
952 skip("Failed to create D3DFMT_P8 texture\n");
956 memset(&lr
, 0, sizeof(lr
));
957 hr
= IDirect3DTexture8_LockRect(texture2
, 0, &lr
, NULL
, 0);
958 ok(hr
== D3D_OK
, "IDirect3DTexture8_LockRect failed, hr = %08x\n", hr
);
962 hr
= IDirect3DTexture8_UnlockRect(texture2
, 0);
963 ok(hr
== D3D_OK
, "IDirect3DTexture8_UnlockRect failed, hr = %08x\n", hr
);
965 hr
= IDirect3DDevice8_CreateTexture(device
, 1, 1, 1, 0, D3DFMT_P8
,
966 D3DPOOL_MANAGED
, &texture
);
967 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateTexture failed, hr = %08x\n", hr
);
969 skip("Failed to create D3DFMT_P8 texture\n");
973 memset(&lr
, 0, sizeof(lr
));
974 hr
= IDirect3DTexture8_LockRect(texture
, 0, &lr
, NULL
, 0);
975 ok(hr
== D3D_OK
, "IDirect3DTexture8_LockRect failed, hr = %08x\n", hr
);
979 hr
= IDirect3DTexture8_UnlockRect(texture
, 0);
980 ok(hr
== D3D_OK
, "IDirect3DTexture8_UnlockRect failed, hr = %08x\n", hr
);
982 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff000000, 0.0, 0);
983 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed, hr = %08x\n", hr
);
985 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, TRUE
);
986 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
988 /* The first part of the test should work both with and without D3DPTEXTURECAPS_ALPHAPALETTE;
989 alpha of every entry is set to 1.0, which MS says is required when there's no
990 D3DPTEXTURECAPS_ALPHAPALETTE capability */
991 for (i
= 0; i
< 256; i
++) {
992 table
[i
].peRed
= table
[i
].peGreen
= table
[i
].peBlue
= 0;
993 table
[i
].peFlags
= 0xff;
995 table
[1].peRed
= 0xff;
996 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 0, table
);
997 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr
);
1000 table
[1].peBlue
= 0xff;
1001 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 1, table
);
1002 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr
);
1004 hr
= IDirect3DDevice8_BeginScene(device
);
1005 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed, hr = %08x\n", hr
);
1007 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_SRCALPHA
);
1008 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
1009 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1010 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
1012 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
1013 ok(hr
== D3D_OK
, "SetVertexShader failed, hr = %#08x\n", hr
);
1015 hr
= IDirect3DDevice8_SetCurrentTexturePalette(device
, 0);
1016 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr
);
1018 hr
= IDirect3DDevice8_SetTexture(device
, 0, (IDirect3DBaseTexture8
*) texture2
);
1019 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr
);
1020 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
1021 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr
);
1023 hr
= IDirect3DDevice8_SetTexture(device
, 0, (IDirect3DBaseTexture8
*) texture
);
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_SetCurrentTexturePalette(device
, 1);
1029 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr
);
1030 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, 5 * sizeof(float));
1031 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr
);
1033 hr
= IDirect3DDevice8_EndScene(device
);
1034 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed, hr = %08x\n", hr
);
1037 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
1038 ok(hr
== D3D_OK
, "IDirect3DDevice8_Present failed, hr = %08x\n", hr
);
1040 color
= getPixelColor(device
, 32, 32);
1041 red
= (color
& 0x00ff0000) >> 16;
1042 green
= (color
& 0x0000ff00) >> 8;
1043 blue
= (color
& 0x000000ff) >> 0;
1044 ok(red
== 0xff && blue
== 0 && green
== 0,
1045 "got color %08x, expected 0x00ff0000\n", color
);
1047 color
= getPixelColor(device
, 32, 320);
1048 red
= (color
& 0x00ff0000) >> 16;
1049 green
= (color
& 0x0000ff00) >> 8;
1050 blue
= (color
& 0x000000ff) >> 0;
1051 ok(red
== 0 && blue
== 0xff && green
== 0,
1052 "got color %08x, expected 0x000000ff\n", color
);
1054 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff000000, 0.0, 0);
1055 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed, hr = %08x\n", hr
);
1057 hr
= IDirect3DDevice8_BeginScene(device
);
1058 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed, hr = %08x\n", hr
);
1060 hr
= IDirect3DDevice8_SetTexture(device
, 0, (IDirect3DBaseTexture8
*) texture2
);
1061 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr
);
1063 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
1064 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr
);
1066 hr
= IDirect3DDevice8_EndScene(device
);
1067 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed, hr = %08x\n", hr
);
1070 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
1071 ok(hr
== D3D_OK
, "IDirect3DDevice8_Present failed, hr = %08x\n", hr
);
1073 color
= getPixelColor(device
, 32, 32);
1074 red
= (color
& 0x00ff0000) >> 16;
1075 green
= (color
& 0x0000ff00) >> 8;
1076 blue
= (color
& 0x000000ff) >> 0;
1077 ok(red
== 0 && blue
== 0xff && green
== 0,
1078 "got color %08x, expected 0x000000ff\n", color
);
1080 /* Test palettes with alpha */
1081 IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
1082 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_ALPHAPALETTE
)) {
1083 skip("no D3DPTEXTURECAPS_ALPHAPALETTE capability, tests with alpha in palette will be skipped\n");
1085 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff000000, 0.0, 0);
1086 ok(hr
== D3D_OK
, "IDirect3DDevice8_Clear failed, hr = %08x\n", hr
);
1088 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, TRUE
);
1089 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
1091 for (i
= 0; i
< 256; i
++) {
1092 table
[i
].peRed
= table
[i
].peGreen
= table
[i
].peBlue
= 0;
1093 table
[i
].peFlags
= 0xff;
1095 table
[1].peRed
= 0xff;
1096 table
[1].peFlags
= 0x80;
1097 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 0, table
);
1098 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr
);
1101 table
[1].peBlue
= 0xff;
1102 table
[1].peFlags
= 0x80;
1103 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 1, table
);
1104 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr
);
1106 hr
= IDirect3DDevice8_BeginScene(device
);
1107 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed, hr = %08x\n", hr
);
1109 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_SRCALPHA
);
1110 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
1111 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1112 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
1114 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
1115 ok(hr
== D3D_OK
, "SetVertexShader failed, hr = %#08x\n", hr
);
1117 hr
= IDirect3DDevice8_SetCurrentTexturePalette(device
, 0);
1118 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr
);
1120 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
1121 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr
);
1123 hr
= IDirect3DDevice8_SetCurrentTexturePalette(device
, 1);
1124 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr
);
1126 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, 5 * sizeof(float));
1127 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr
);
1129 hr
= IDirect3DDevice8_EndScene(device
);
1130 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed, hr = %08x\n", hr
);
1133 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
1134 ok(hr
== D3D_OK
, "IDirect3DDevice8_Present failed, hr = %08x\n", hr
);
1136 color
= getPixelColor(device
, 32, 32);
1137 red
= (color
& 0x00ff0000) >> 16;
1138 green
= (color
& 0x0000ff00) >> 8;
1139 blue
= (color
& 0x000000ff) >> 0;
1140 ok(red
>= 0x7e && red
<= 0x81 && blue
== 0 && green
== 0,
1141 "got color %08x, expected 0x00800000 or near\n", color
);
1143 color
= getPixelColor(device
, 32, 320);
1144 red
= (color
& 0x00ff0000) >> 16;
1145 green
= (color
& 0x0000ff00) >> 8;
1146 blue
= (color
& 0x000000ff) >> 0;
1147 ok(red
== 0 && blue
>= 0x7e && blue
<= 0x81 && green
== 0,
1148 "got color %08x, expected 0x00000080 or near\n", color
);
1151 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
1152 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr
);
1153 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, FALSE
);
1154 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr
);
1157 if(texture
) IDirect3DTexture8_Release(texture
);
1158 if(texture2
) IDirect3DTexture8_Release(texture2
);
1159 IDirect3D8_Release(d3d
);
1162 static void texop_test(IDirect3DDevice8
*device
)
1164 IDirect3DTexture8
*texture
= NULL
;
1165 D3DLOCKED_RECT locked_rect
;
1171 static const struct {
1176 {-1.0f
, -1.0f
, 0.1f
, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), -1.0f
, -1.0f
},
1177 {-1.0f
, 1.0f
, 0.1f
, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), -1.0f
, 1.0f
},
1178 { 1.0f
, -1.0f
, 0.1f
, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), 1.0f
, -1.0f
},
1179 { 1.0f
, 1.0f
, 0.1f
, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), 1.0f
, 1.0f
}
1182 static const struct {
1188 {D3DTOP_SELECTARG1
, "SELECTARG1", D3DTEXOPCAPS_SELECTARG1
, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00)},
1189 {D3DTOP_SELECTARG2
, "SELECTARG2", D3DTEXOPCAPS_SELECTARG2
, D3DCOLOR_ARGB(0x00, 0x33, 0x33, 0x33)},
1190 {D3DTOP_MODULATE
, "MODULATE", D3DTEXOPCAPS_MODULATE
, D3DCOLOR_ARGB(0x00, 0x00, 0x33, 0x00)},
1191 {D3DTOP_MODULATE2X
, "MODULATE2X", D3DTEXOPCAPS_MODULATE2X
, D3DCOLOR_ARGB(0x00, 0x00, 0x66, 0x00)},
1192 {D3DTOP_MODULATE4X
, "MODULATE4X", D3DTEXOPCAPS_MODULATE4X
, D3DCOLOR_ARGB(0x00, 0x00, 0xcc, 0x00)},
1193 {D3DTOP_ADD
, "ADD", D3DTEXOPCAPS_ADD
, D3DCOLOR_ARGB(0x00, 0x33, 0xff, 0x33)},
1194 {D3DTOP_ADDSIGNED
, "ADDSIGNED", D3DTEXOPCAPS_ADDSIGNED
, D3DCOLOR_ARGB(0x00, 0x00, 0xb2, 0x00)},
1195 {D3DTOP_ADDSIGNED2X
, "ADDSIGNED2X", D3DTEXOPCAPS_ADDSIGNED2X
, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00)},
1196 {D3DTOP_SUBTRACT
, "SUBTRACT", D3DTEXOPCAPS_SUBTRACT
, D3DCOLOR_ARGB(0x00, 0x00, 0xcc, 0x00)},
1197 {D3DTOP_ADDSMOOTH
, "ADDSMOOTH", D3DTEXOPCAPS_ADDSMOOTH
, D3DCOLOR_ARGB(0x00, 0x33, 0xff, 0x33)},
1198 {D3DTOP_BLENDDIFFUSEALPHA
, "BLENDDIFFUSEALPHA", D3DTEXOPCAPS_BLENDDIFFUSEALPHA
, D3DCOLOR_ARGB(0x00, 0x22, 0x77, 0x22)},
1199 {D3DTOP_BLENDTEXTUREALPHA
, "BLENDTEXTUREALPHA", D3DTEXOPCAPS_BLENDTEXTUREALPHA
, D3DCOLOR_ARGB(0x00, 0x14, 0xad, 0x14)},
1200 {D3DTOP_BLENDFACTORALPHA
, "BLENDFACTORALPHA", D3DTEXOPCAPS_BLENDFACTORALPHA
, D3DCOLOR_ARGB(0x00, 0x07, 0xe4, 0x07)},
1201 {D3DTOP_BLENDTEXTUREALPHAPM
, "BLENDTEXTUREALPHAPM", D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
, D3DCOLOR_ARGB(0x00, 0x14, 0xff, 0x14)},
1202 {D3DTOP_BLENDCURRENTALPHA
, "BLENDCURRENTALPHA", D3DTEXOPCAPS_BLENDCURRENTALPHA
, D3DCOLOR_ARGB(0x00, 0x22, 0x77, 0x22)},
1203 {D3DTOP_MODULATEALPHA_ADDCOLOR
, "MODULATEALPHA_ADDCOLOR", D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
, D3DCOLOR_ARGB(0x00, 0x1f, 0xff, 0x1f)},
1204 {D3DTOP_MODULATECOLOR_ADDALPHA
, "MODULATECOLOR_ADDALPHA", D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
, D3DCOLOR_ARGB(0x00, 0x99, 0xcc, 0x99)},
1205 {D3DTOP_MODULATEINVALPHA_ADDCOLOR
, "MODULATEINVALPHA_ADDCOLOR", D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
, D3DCOLOR_ARGB(0x00, 0x14, 0xff, 0x14)},
1206 {D3DTOP_MODULATEINVCOLOR_ADDALPHA
, "MODULATEINVCOLOR_ADDALPHA", D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
, D3DCOLOR_ARGB(0x00, 0xcc, 0x99, 0xcc)},
1207 /* BUMPENVMAP & BUMPENVMAPLUMINANCE have their own tests */
1208 {D3DTOP_DOTPRODUCT3
, "DOTPRODUCT2", D3DTEXOPCAPS_DOTPRODUCT3
, D3DCOLOR_ARGB(0x00, 0x99, 0x99, 0x99)},
1209 {D3DTOP_MULTIPLYADD
, "MULTIPLYADD", D3DTEXOPCAPS_MULTIPLYADD
, D3DCOLOR_ARGB(0x00, 0xff, 0x33, 0x00)},
1210 {D3DTOP_LERP
, "LERP", D3DTEXOPCAPS_LERP
, D3DCOLOR_ARGB(0x00, 0x00, 0x33, 0x33)},
1213 memset(&caps
, 0, sizeof(caps
));
1214 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
1215 ok(SUCCEEDED(hr
), "GetDeviceCaps failed with 0x%08x (%s)\n", hr
, DXGetErrorString8(hr
));
1217 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_TEX0
);
1218 ok(SUCCEEDED(hr
), "SetVertexShader failed with 0x%08x (%s)\n", hr
, DXGetErrorString8(hr
));
1220 hr
= IDirect3DDevice8_CreateTexture(device
, 1, 1, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &texture
);
1221 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateTexture failed with 0x%08x (%s)\n", hr
, DXGetErrorString8(hr
));
1222 hr
= IDirect3DTexture8_LockRect(texture
, 0, &locked_rect
, NULL
, 0);
1223 ok(SUCCEEDED(hr
), "LockRect failed with 0x%08x (%s)\n", hr
, DXGetErrorString8(hr
));
1224 *((DWORD
*)locked_rect
.pBits
) = D3DCOLOR_ARGB(0x99, 0x00, 0xff, 0x00);
1225 hr
= IDirect3DTexture8_UnlockRect(texture
, 0);
1226 ok(SUCCEEDED(hr
), "LockRect failed with 0x%08x (%s)\n", hr
, DXGetErrorString8(hr
));
1227 hr
= IDirect3DDevice8_SetTexture(device
, 0, (IDirect3DBaseTexture8
*)texture
);
1228 ok(SUCCEEDED(hr
), "SetTexture failed with 0x%08x (%s)\n", hr
, DXGetErrorString8(hr
));
1230 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLORARG0
, D3DTA_DIFFUSE
);
1231 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x (%s)\n", hr
, DXGetErrorString8(hr
));
1232 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
1233 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x (%s)\n", hr
, DXGetErrorString8(hr
));
1234 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_TFACTOR
);
1235 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x (%s)\n", hr
, DXGetErrorString8(hr
));
1237 hr
= IDirect3DDevice8_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
1238 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x (%s)\n", hr
, DXGetErrorString8(hr
));
1240 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
1241 ok(SUCCEEDED(hr
), "SetRenderState failed with 0x%08x (%s)\n", hr
, DXGetErrorString8(hr
));
1242 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_TEXTUREFACTOR
, 0xdd333333);
1243 ok(SUCCEEDED(hr
), "SetRenderState failed with 0x%08x (%s)\n", hr
, DXGetErrorString8(hr
));
1244 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_COLORWRITEENABLE
, D3DCOLORWRITEENABLE_RED
| D3DCOLORWRITEENABLE_GREEN
| D3DCOLORWRITEENABLE_BLUE
| D3DCOLORWRITEENABLE_ALPHA
);
1245 ok(SUCCEEDED(hr
), "SetRenderState failed with 0x%08x (%s)\n", hr
, DXGetErrorString8(hr
));
1247 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x00000000, 1.0f
, 0);
1248 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Clear failed with 0x%08x (%s)\n", hr
, DXGetErrorString8(hr
));
1250 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
1252 if (!(caps
.TextureOpCaps
& test_data
[i
].caps_flag
))
1254 skip("tex operation %s not supported\n", test_data
[i
].name
);
1258 hr
= IDirect3DDevice8_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, test_data
[i
].op
);
1259 ok(SUCCEEDED(hr
), "SetTextureStageState (%s) failed with 0x%08x (%s)\n",
1260 test_data
[i
].name
, hr
, DXGetErrorString8(hr
));
1262 hr
= IDirect3DDevice8_BeginScene(device
);
1263 ok(SUCCEEDED(hr
), "BeginScene failed with 0x%08x (%s)\n", hr
, DXGetErrorString8(hr
));
1265 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
1266 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed with 0x%08x (%s)\n", hr
, DXGetErrorString8(hr
));
1268 hr
= IDirect3DDevice8_EndScene(device
);
1269 ok(SUCCEEDED(hr
), "EndScene failed with 0x%08x (%s)\n", hr
, DXGetErrorString8(hr
));
1271 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
1272 ok(SUCCEEDED(hr
), "Present failed with 0x%08x (%s)\n", hr
, DXGetErrorString8(hr
));
1274 color
= getPixelColor(device
, 320, 240);
1275 ok(color_match(color
, test_data
[i
].result
, 1), "Operation %s returned color 0x%08x, expected 0x%08x\n",
1276 test_data
[i
].name
, color
, test_data
[i
].result
);
1279 if (texture
) IDirect3DTexture8_Release(texture
);
1284 IDirect3DDevice8
*device_ptr
;
1289 d3d8_handle
= LoadLibraryA("d3d8.dll");
1292 skip("Could not load d3d8.dll\n");
1296 device_ptr
= init_d3d8();
1299 skip("Could not initialize direct3d\n");
1303 IDirect3DDevice8_GetDeviceCaps(device_ptr
, &caps
);
1305 /* Check for the reliability of the returned data */
1306 hr
= IDirect3DDevice8_Clear(device_ptr
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
1309 trace("Clear failed, can't assure correctness of the test results, skipping\n");
1312 IDirect3DDevice8_Present(device_ptr
, NULL
, NULL
, NULL
, NULL
);
1314 color
= getPixelColor(device_ptr
, 1, 1);
1315 if(color
!=0x00ff0000)
1317 trace("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests, skipping\n", color
);
1321 hr
= IDirect3DDevice8_Clear(device_ptr
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ddee, 0.0, 0);
1324 trace("Clear failed, can't assure correctness of the test results, skipping\n");
1327 IDirect3DDevice8_Present(device_ptr
, NULL
, NULL
, NULL
, NULL
);
1329 color
= getPixelColor(device_ptr
, 639, 479);
1330 if(color
!= 0x0000ddee)
1332 trace("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests, skipping\n", color
);
1336 /* Now run the real test */
1337 lighting_test(device_ptr
);
1338 clear_test(device_ptr
);
1339 fog_test(device_ptr
);
1340 present_test(device_ptr
);
1341 offscreen_test(device_ptr
);
1342 alpha_test(device_ptr
);
1344 if (caps
.VertexShaderVersion
>= D3DVS_VERSION(1, 1))
1346 test_rcp_rsq(device_ptr
);
1350 skip("No vs.1.1 support\n");
1353 p8_texture_test(device_ptr
);
1354 texop_test(device_ptr
);
1358 D3DDEVICE_CREATION_PARAMETERS creation_parameters
;
1359 IDirect3DDevice8_GetCreationParameters(device_ptr
, &creation_parameters
);
1360 IDirect3DDevice8_Release(device_ptr
);
1361 DestroyWindow(creation_parameters
.hFocusWindow
);