push a6a7df41ae272b3b1bf5fcfb544267c1e96afa99
[wine/hacks.git] / dlls / d3d8 / tests / visual.c
blobefead14d6db96ac63d818321ac743c14f8480fe8
1 /*
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 */
22 #define COBJMACROS
23 #include <d3d8.h>
24 #include "wine/test.h"
26 static HMODULE d3d8_handle = 0;
28 static HWND create_window(void)
30 WNDCLASS wc = {0};
31 HWND ret;
32 wc.lpfnWndProc = DefWindowProc;
33 wc.lpszClassName = "d3d8_test_wc";
34 RegisterClass(&wc);
36 ret = CreateWindow("d3d8_test_wc", "d3d8_test",
37 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
38 return ret;
41 static BOOL color_match(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
43 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
44 c1 >>= 8; c2 >>= 8;
45 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
46 c1 >>= 8; c2 >>= 8;
47 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
48 c1 >>= 8; c2 >>= 8;
49 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
50 return TRUE;
53 static DWORD getPixelColor(IDirect3DDevice8 *device, UINT x, UINT y)
55 DWORD ret;
56 IDirect3DSurface8 *surf;
57 IDirect3DTexture8 *tex;
58 HRESULT hr;
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);
66 return 0xdeadbeef;
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);
72 ret = 0xdeadbeee;
73 goto out;
76 hr = IDirect3DDevice8_GetFrontBuffer(device, surf);
77 if(FAILED(hr))
79 trace("Can't read the front buffer data, hr=%#08x\n", hr);
80 ret = 0xdeadbeed;
81 goto out;
84 hr = IDirect3DSurface8_LockRect(surf, &lockedRect, &rectToLock, D3DLOCK_READONLY);
85 if(FAILED(hr))
87 trace("Can't lock the offscreen surface, hr=%#08x\n", hr);
88 ret = 0xdeadbeec;
89 goto out;
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);
96 if(FAILED(hr))
98 trace("Can't unlock the offscreen surface, hr=%#08x\n", hr);
101 out:
102 if(surf) IDirect3DSurface8_Release(surf);
103 if(tex) IDirect3DTexture8_Release(tex);
104 return ret;
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;
113 HRESULT hr;
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);
120 ok(d3d8_ptr != NULL, "Failed to create IDirect3D8 object\n");
121 if (!d3d8_ptr) return NULL;
123 ZeroMemory(&present_parameters, sizeof(present_parameters));
124 present_parameters.Windowed = FALSE;
125 present_parameters.hDeviceWindow = create_window();
126 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
127 present_parameters.BackBufferWidth = 640;
128 present_parameters.BackBufferHeight = 480;
129 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
130 present_parameters.EnableAutoDepthStencil = TRUE;
131 present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
133 hr = IDirect3D8_CreateDevice(d3d8_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
134 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "IDirect3D_CreateDevice returned: %#08x\n", hr);
136 return device_ptr;
139 struct vertex
141 float x, y, z;
142 DWORD diffuse;
145 struct nvertex
147 float x, y, z;
148 float nx, ny, nz;
149 DWORD diffuse;
152 static void lighting_test(IDirect3DDevice8 *device)
154 HRESULT hr;
155 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
156 DWORD nfvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_NORMAL;
157 DWORD color;
159 float mat[16] = { 1.0f, 0.0f, 0.0f, 0.0f,
160 0.0f, 1.0f, 0.0f, 0.0f,
161 0.0f, 0.0f, 1.0f, 0.0f,
162 0.0f, 0.0f, 0.0f, 1.0f };
164 struct vertex unlitquad[] =
166 {-1.0f, -1.0f, 0.1f, 0xffff0000},
167 {-1.0f, 0.0f, 0.1f, 0xffff0000},
168 { 0.0f, 0.0f, 0.1f, 0xffff0000},
169 { 0.0f, -1.0f, 0.1f, 0xffff0000},
171 struct vertex litquad[] =
173 {-1.0f, 0.0f, 0.1f, 0xff00ff00},
174 {-1.0f, 1.0f, 0.1f, 0xff00ff00},
175 { 0.0f, 1.0f, 0.1f, 0xff00ff00},
176 { 0.0f, 0.0f, 0.1f, 0xff00ff00},
178 struct nvertex unlitnquad[] =
180 { 0.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
181 { 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
182 { 1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
183 { 1.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
185 struct nvertex litnquad[] =
187 { 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
188 { 0.0f, 1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
189 { 1.0f, 1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
190 { 1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
192 WORD Indices[] = {0, 1, 2, 2, 3, 0};
194 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
195 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
197 /* Setup some states that may cause issues */
198 hr = IDirect3DDevice8_SetTransform(device, D3DTS_WORLDMATRIX(0), (D3DMATRIX *) mat);
199 ok(hr == D3D_OK, "IDirect3DDevice8_SetTransform returned %#08x\n", hr);
200 hr = IDirect3DDevice8_SetTransform(device, D3DTS_VIEW, (D3DMATRIX *)mat);
201 ok(hr == D3D_OK, "IDirect3DDevice8_SetTransform returned %#08x\n", hr);
202 hr = IDirect3DDevice8_SetTransform(device, D3DTS_PROJECTION, (D3DMATRIX *) mat);
203 ok(hr == D3D_OK, "IDirect3DDevice8_SetTransform returned %#08x\n", hr);
204 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_CLIPPING, FALSE);
205 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
206 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, FALSE);
207 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
208 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGENABLE, FALSE);
209 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
210 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_STENCILENABLE, FALSE);
211 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
212 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHATESTENABLE, FALSE);
213 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
214 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, FALSE);
215 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
216 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE);
217 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed with %#08x\n", hr);
218 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE);
219 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed with %#08x\n", hr);
221 hr = IDirect3DDevice8_SetVertexShader(device, fvf);
222 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
224 hr = IDirect3DDevice8_BeginScene(device);
225 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
226 if(hr == D3D_OK)
228 /* No lights are defined... That means, lit vertices should be entirely black */
229 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
230 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
231 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
232 2 /*PrimCount */, Indices, D3DFMT_INDEX16, unlitquad, sizeof(unlitquad[0]));
233 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr);
235 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, TRUE);
236 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
237 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
238 2 /*PrimCount */, Indices, D3DFMT_INDEX16, litquad, sizeof(litquad[0]));
239 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr);
241 hr = IDirect3DDevice8_SetVertexShader(device, nfvf);
242 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader failed with %#08x\n", hr);
244 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
245 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
246 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
247 2 /*PrimCount */, Indices, D3DFMT_INDEX16, unlitnquad, sizeof(unlitnquad[0]));
248 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr);
250 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, TRUE);
251 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
252 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
253 2 /*PrimCount */, Indices, D3DFMT_INDEX16, litnquad, sizeof(litnquad[0]));
254 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr);
256 IDirect3DDevice8_EndScene(device);
257 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
260 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
262 color = getPixelColor(device, 160, 360); /* lower left quad - unlit without normals */
263 ok(color == 0x00ff0000, "Unlit quad without normals has color %08x\n", color);
264 color = getPixelColor(device, 160, 120); /* upper left quad - lit without normals */
265 ok(color == 0x00000000, "Lit quad without normals has color %08x\n", color);
266 color = getPixelColor(device, 480, 360); /* lower left quad - unlit width normals */
267 ok(color == 0x000000ff, "Unlit quad width normals has color %08x\n", color);
268 color = getPixelColor(device, 480, 120); /* upper left quad - lit width normals */
269 ok(color == 0x00000000, "Lit quad width normals has color %08x\n", color);
271 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
272 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
275 static void clear_test(IDirect3DDevice8 *device)
277 /* Tests the correctness of clearing parameters */
278 HRESULT hr;
279 D3DRECT rect[2];
280 D3DRECT rect_negneg;
281 DWORD color;
283 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
284 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
286 /* Positive x, negative y */
287 rect[0].x1 = 0;
288 rect[0].y1 = 480;
289 rect[0].x2 = 320;
290 rect[0].y2 = 240;
292 /* Positive x, positive y */
293 rect[1].x1 = 0;
294 rect[1].y1 = 0;
295 rect[1].x2 = 320;
296 rect[1].y2 = 240;
297 /* Clear 2 rectangles with one call. Shows that a positive value is returned, but the negative rectangle
298 * is ignored, the positive is still cleared afterwards
300 hr = IDirect3DDevice8_Clear(device, 2, rect, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
301 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
303 /* negative x, negative y */
304 rect_negneg.x1 = 640;
305 rect_negneg.y1 = 240;
306 rect_negneg.x2 = 320;
307 rect_negneg.y2 = 0;
308 hr = IDirect3DDevice8_Clear(device, 1, &rect_negneg, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
309 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
311 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
313 color = getPixelColor(device, 160, 360); /* lower left quad */
314 ok(color == 0x00ffffff, "Clear rectangle 3(pos, neg) has color %08x\n", color);
315 color = getPixelColor(device, 160, 120); /* upper left quad */
316 ok(color == 0x00ff0000, "Clear rectangle 1(pos, pos) has color %08x\n", color);
317 color = getPixelColor(device, 480, 360); /* lower right quad */
318 ok(color == 0x00ffffff, "Clear rectangle 4(NULL) has color %08x\n", color);
319 color = getPixelColor(device, 480, 120); /* upper right quad */
320 ok(color == 0x00ffffff, "Clear rectangle 4(neg, neg) has color %08x\n", color);
323 struct sVertex {
324 float x, y, z;
325 DWORD diffuse;
326 DWORD specular;
329 struct sVertexT {
330 float x, y, z, rhw;
331 DWORD diffuse;
332 DWORD specular;
335 static void fog_test(IDirect3DDevice8 *device)
337 HRESULT hr;
338 DWORD color;
339 float start = 0.0, end = 1.0;
341 /* Gets full z based fog with linear fog, no fog with specular color */
342 struct sVertex unstransformed_1[] = {
343 {-1, -1, 0.1f, 0xFFFF0000, 0xFF000000 },
344 {-1, 0, 0.1f, 0xFFFF0000, 0xFF000000 },
345 { 0, 0, 0.1f, 0xFFFF0000, 0xFF000000 },
346 { 0, -1, 0.1f, 0xFFFF0000, 0xFF000000 },
348 /* Ok, I am too lazy to deal with transform matrices */
349 struct sVertex unstransformed_2[] = {
350 {-1, 0, 1.0f, 0xFFFF0000, 0xFF000000 },
351 {-1, 1, 1.0f, 0xFFFF0000, 0xFF000000 },
352 { 0, 1, 1.0f, 0xFFFF0000, 0xFF000000 },
353 { 0, 0, 1.0f, 0xFFFF0000, 0xFF000000 },
355 /* Untransformed ones. Give them a different diffuse color to make the test look
356 * nicer. It also makes making sure that they are drawn correctly easier.
358 struct sVertexT transformed_1[] = {
359 {320, 0, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
360 {640, 0, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
361 {640, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
362 {320, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
364 struct sVertexT transformed_2[] = {
365 {320, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
366 {640, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
367 {640, 480, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
368 {320, 480, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
370 WORD Indices[] = {0, 1, 2, 2, 3, 0};
372 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
373 ok(hr == D3D_OK, "IDirect3DDevice8_Clear returned %#08x\n", hr);
375 /* Setup initial states: No lighting, fog on, fog color */
376 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
377 ok(hr == D3D_OK, "Turning off lighting returned %#08x\n", hr);
378 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGENABLE, TRUE);
379 ok(hr == D3D_OK, "Turning on fog calculations returned %#08x\n", hr);
380 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGCOLOR, 0xFF00FF00 /* A nice green */);
381 ok(hr == D3D_OK, "Turning on fog calculations returned %#08x\n", hr);
383 /* First test: Both table fog and vertex fog off */
384 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_NONE);
385 ok(hr == D3D_OK, "Turning off table fog returned %#08x\n", hr);
386 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGVERTEXMODE, D3DFOG_NONE);
387 ok(hr == D3D_OK, "Turning off table fog returned %#08x\n", hr);
389 /* Start = 0, end = 1. Should be default, but set them */
390 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGSTART, *((DWORD *) &start));
391 ok(hr == D3D_OK, "Setting fog start returned %#08x\n", hr);
392 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGEND, *((DWORD *) &end));
393 ok(hr == D3D_OK, "Setting fog start returned %#08x\n", hr);
395 if(IDirect3DDevice8_BeginScene(device) == D3D_OK)
397 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
398 ok( hr == D3D_OK, "SetVertexShader returned %#08x\n", hr);
399 /* Untransformed, vertex fog = NONE, table fog = NONE: Read the fog weighting from the specular color */
400 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
401 2 /*PrimCount */, Indices, D3DFMT_INDEX16, unstransformed_1,
402 sizeof(unstransformed_1[0]));
403 ok(hr == D3D_OK, "DrawIndexedPrimitiveUP returned %#08x\n", hr);
405 /* That makes it use the Z value */
406 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR);
407 ok(hr == D3D_OK, "Turning off table fog returned %#08x\n", hr);
408 /* Untransformed, vertex fog != none (or table fog != none):
409 * Use the Z value as input into the equation
411 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
412 2 /*PrimCount */, Indices, D3DFMT_INDEX16, unstransformed_2,
413 sizeof(unstransformed_1[0]));
414 ok(hr == D3D_OK, "DrawIndexedPrimitiveUP returned %#08x\n", hr);
416 /* transformed verts */
417 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
418 ok( hr == D3D_OK, "SetVertexShader returned %#08x\n", hr);
419 /* Transformed, vertex fog != NONE, pixel fog == NONE: Use specular color alpha component */
420 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
421 2 /*PrimCount */, Indices, D3DFMT_INDEX16, transformed_1,
422 sizeof(transformed_1[0]));
423 ok(hr == D3D_OK, "DrawIndexedPrimitiveUP returned %#08x\n", hr);
425 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);
426 ok( hr == D3D_OK, "Setting fog table mode to D3DFOG_LINEAR returned %#08x\n", hr);
427 /* Transformed, table fog != none, vertex anything: Use Z value as input to the fog
428 * equation
430 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
431 2 /*PrimCount */, Indices, D3DFMT_INDEX16, transformed_2,
432 sizeof(transformed_2[0]));
434 hr = IDirect3DDevice8_EndScene(device);
435 ok(hr == D3D_OK, "EndScene returned %#08x\n", hr);
437 else
439 ok(FALSE, "BeginScene failed\n");
442 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
443 color = getPixelColor(device, 160, 360);
444 ok(color == 0x00FF0000, "Untransformed vertex with no table or vertex fog has color %08x\n", color);
445 color = getPixelColor(device, 160, 120);
446 ok(color == 0x0000FF00, "Untransformed vertex with linear vertex fog has color %08x\n", color);
447 color = getPixelColor(device, 480, 120);
448 ok(color == 0x00FFFF00, "Transformed vertex with linear vertex fog has color %08x\n", color);
449 color = getPixelColor(device, 480, 360);
450 ok(color == 0x0000FF00, "Transformed vertex with linear table fog has color %08x\n", color);
452 /* Turn off the fog master switch to avoid confusing other tests */
453 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGENABLE, FALSE);
454 ok(hr == D3D_OK, "Turning off fog calculations returned %#08x\n", hr);
457 static void present_test(IDirect3DDevice8 *device)
459 struct vertex quad[] =
461 {-1.0f, -1.0f, 0.9f, 0xffff0000},
462 {-1.0f, 1.0f, 0.9f, 0xffff0000},
463 { 1.0f, -1.0f, 0.1f, 0xffff0000},
464 { 1.0f, 1.0f, 0.1f, 0xffff0000},
466 HRESULT hr;
467 DWORD color;
469 /* Does the Present clear the depth stencil? Clear the depth buffer with some value != 0,
470 * then call Present. Then clear the color buffer to make sure it has some defined content
471 * after the Present with D3DSWAPEFFECT_DISCARD. After that draw a plane that is somewhere cut
472 * by the depth value.
474 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 0.75, 0);
475 ok(hr == D3D_OK, "IDirect3DDevice8_Clear returned %08x\n", hr);
476 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
477 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.4, 0);
479 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
480 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %08x\n", hr);
481 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_GREATER);
482 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %08x\n", hr);
483 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
484 ok(hr == D3D_OK, "IDirect3DDevice8_SetFVF returned %08x\n", hr);
486 hr = IDirect3DDevice8_BeginScene(device);
487 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %08x\n", hr);
488 if(hr == D3D_OK)
490 /* No lights are defined... That means, lit vertices should be entirely black */
491 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2 /*PrimCount */, quad, sizeof(quad[0]));
492 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %08x\n", hr);
494 hr = IDirect3DDevice8_EndScene(device);
495 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %08x\n", hr);
498 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
499 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %08x\n", hr);
501 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
502 ok(SUCCEEDED(hr), "Present failed (%#08x)\n", hr);
503 color = getPixelColor(device, 512, 240);
504 ok(color == 0x00ffffff, "Present failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
505 color = getPixelColor(device, 64, 240);
506 ok(color == 0x00ff0000, "Present failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
509 static void test_rcp_rsq(IDirect3DDevice8 *device)
511 HRESULT hr;
512 DWORD shader;
513 DWORD color;
514 unsigned char c1, c2, c3;
515 float constant[4] = {1.0, 1.0, 1.0, 2.0};
517 static const float quad[][3] = {
518 {-1.0f, -1.0f, 0.0f},
519 {-1.0f, 1.0f, 0.0f},
520 { 1.0f, -1.0f, 0.0f},
521 { 1.0f, 1.0f, 0.0f},
524 const DWORD rcp_test[] = {
525 0xfffe0101, /* vs.1.1 */
527 0x0009fffe, 0x30303030, 0x30303030, /* Shaders have to have a minimal size. */
528 0x30303030, 0x30303030, 0x30303030, /* Add a filler comment. Usually D3DX8's*/
529 0x30303030, 0x30303030, 0x30303030, /* version comment makes the shader big */
530 0x00303030, /* enough to make windows happy */
532 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
533 0x00000006, 0xd00f0000, 0xa0e40000, /* rcp oD0, c0 */
534 0x0000ffff /* END */
537 const DWORD rsq_test[] = {
538 0xfffe0101, /* vs.1.1 */
540 0x0009fffe, 0x30303030, 0x30303030, /* Shaders have to have a minimal size. */
541 0x30303030, 0x30303030, 0x30303030, /* Add a filler comment. Usually D3DX8's*/
542 0x30303030, 0x30303030, 0x30303030, /* version comment makes the shader big */
543 0x00303030, /* enough to make windows happy */
545 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
546 0x00000007, 0xd00f0000, 0xa0e40000, /* rsq oD0, c0 */
547 0x0000ffff /* END */
550 DWORD decl[] =
552 D3DVSD_STREAM(0),
553 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
554 D3DVSD_END()
557 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff800080, 0.0, 0);
558 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
560 hr = IDirect3DDevice8_CreateVertexShader(device, decl, rcp_test, &shader, 0);
561 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned with %#08x\n", hr);
563 IDirect3DDevice8_SetVertexShader(device, shader);
564 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
565 IDirect3DDevice8_SetVertexShaderConstant(device, 0, constant, 1);
567 hr = IDirect3DDevice8_BeginScene(device);
568 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene returned %#08x\n", hr);
569 if(SUCCEEDED(hr))
571 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], 3 * sizeof(float));
572 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%#08x)\n", hr);
573 hr = IDirect3DDevice8_EndScene(device);
574 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
577 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
578 ok(SUCCEEDED(hr), "Present failed (%#08x)\n", hr);
579 color = getPixelColor(device, 320, 240);
580 c1 = (color & 0x00ff0000 )>> 16;
581 c2 = (color & 0x0000ff00 )>> 8;
582 c3 = (color & 0x000000ff )>> 0;
583 ok(c1 == c2 && c2 == c3, "Color components differ: c1 = %02x, c2 = %02x, c3 = %02x\n",
584 c1, c2, c3);
585 ok(c1 >= 0x7c && c1 <= 0x84, "Color component value is %02x\n", c1);
587 IDirect3DDevice8_SetVertexShader(device, 0);
588 IDirect3DDevice8_DeleteVertexShader(device, shader);
590 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff800080, 0.0, 0);
591 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
593 hr = IDirect3DDevice8_CreateVertexShader(device, decl, rsq_test, &shader, 0);
594 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned with %#08x\n", hr);
596 IDirect3DDevice8_SetVertexShader(device, shader);
597 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
598 IDirect3DDevice8_SetVertexShaderConstant(device, 0, constant, 1);
600 hr = IDirect3DDevice8_BeginScene(device);
601 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene returned %#08x\n", hr);
602 if(SUCCEEDED(hr))
604 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], 3 * sizeof(float));
605 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%#08x)\n", hr);
606 hr = IDirect3DDevice8_EndScene(device);
607 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
610 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
611 ok(SUCCEEDED(hr), "Present failed (%#08x)\n", hr);
612 color = getPixelColor(device, 320, 240);
613 c1 = (color & 0x00ff0000 )>> 16;
614 c2 = (color & 0x0000ff00 )>> 8;
615 c3 = (color & 0x000000ff )>> 0;
616 ok(c1 == c2 && c2 == c3, "Color components differ: c1 = %02x, c2 = %02x, c3 = %02x\n",
617 c1, c2, c3);
618 ok(c1 >= 0xb0 && c1 <= 0xb8, "Color component value is %02x\n", c1);
620 IDirect3DDevice8_SetVertexShader(device, 0);
621 IDirect3DDevice8_DeleteVertexShader(device, shader);
624 static void offscreen_test(IDirect3DDevice8 *device)
626 HRESULT hr;
627 IDirect3DTexture8 *offscreenTexture = NULL;
628 IDirect3DSurface8 *backbuffer = NULL, *offscreen = NULL, *depthstencil = NULL;
629 DWORD color;
631 static const float quad[][5] = {
632 {-0.5f, -0.5f, 0.1f, 0.0f, 0.0f},
633 {-0.5f, 0.5f, 0.1f, 0.0f, 1.0f},
634 { 0.5f, -0.5f, 0.1f, 1.0f, 0.0f},
635 { 0.5f, 0.5f, 0.1f, 1.0f, 1.0f},
638 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &depthstencil);
639 ok(hr == D3D_OK, "IDirect3DDevice8_GetDepthStencilSurface failed, hr = %#08x\n", hr);
641 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
642 ok(hr == D3D_OK, "Clear failed, hr = %#08x\n", hr);
644 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &offscreenTexture);
645 ok(hr == D3D_OK || D3DERR_INVALIDCALL, "Creating the offscreen render target failed, hr = %#08x\n", hr);
646 if(!offscreenTexture) {
647 trace("Failed to create an X8R8G8B8 offscreen texture, trying R5G6B5\n");
648 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET, D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &offscreenTexture);
649 ok(hr == D3D_OK || D3DERR_INVALIDCALL, "Creating the offscreen render target failed, hr = %#08x\n", hr);
650 if(!offscreenTexture) {
651 skip("Cannot create an offscreen render target\n");
652 goto out;
656 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
657 ok(hr == D3D_OK, "Can't get back buffer, hr = %#08x\n", hr);
658 if(!backbuffer) {
659 goto out;
662 hr = IDirect3DTexture8_GetSurfaceLevel(offscreenTexture, 0, &offscreen);
663 ok(hr == D3D_OK, "Can't get offscreen surface, hr = %#08x\n", hr);
664 if(!offscreen) {
665 goto out;
668 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_TEX1);
669 ok(hr == D3D_OK, "SetVertexShader failed, hr = %#08x\n", hr);
671 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
672 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %#08x\n", hr);
673 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
674 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %#08x\n", hr);
675 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MINFILTER, D3DTEXF_NONE);
676 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MINFILTER failed (%#08x)\n", hr);
677 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MAGFILTER, D3DTEXF_NONE);
678 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MAGFILTER failed (%#08x)\n", hr);
679 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
680 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %08x\n", hr);
682 if(IDirect3DDevice8_BeginScene(device) == D3D_OK) {
683 hr = IDirect3DDevice8_SetRenderTarget(device, offscreen, depthstencil);
684 ok(hr == D3D_OK, "SetRenderTarget failed, hr = %#08x\n", hr);
685 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
686 ok(hr == D3D_OK, "Clear failed, hr = %#08x\n", hr);
688 /* Draw without textures - Should result in a white quad */
689 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
690 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
692 hr = IDirect3DDevice8_SetRenderTarget(device, backbuffer, depthstencil);
693 ok(hr == D3D_OK, "SetRenderTarget failed, hr = %#08x\n", hr);
694 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) offscreenTexture);
695 ok(hr == D3D_OK, "SetTexture failed, %08x\n", hr);
697 /* This time with the texture */
698 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
699 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
701 IDirect3DDevice8_EndScene(device);
704 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
706 /* Center quad - should be white */
707 color = getPixelColor(device, 320, 240);
708 ok(color == 0x00ffffff, "Offscreen failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
709 /* Some quad in the cleared part of the texture */
710 color = getPixelColor(device, 170, 240);
711 ok(color == 0x00ff00ff, "Offscreen failed: Got color 0x%08x, expected 0x00ff00ff.\n", color);
712 /* Part of the originally cleared back buffer */
713 color = getPixelColor(device, 10, 10);
714 ok(color == 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
715 if(0) {
716 /* Lower left corner of the screen, where back buffer offscreen rendering draws the offscreen texture.
717 * It should be red, but the offscreen texture may leave some junk there. Not tested yet. Depending on
718 * the offscreen rendering mode this test would succeed or fail
720 color = getPixelColor(device, 10, 470);
721 ok(color == 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
724 out:
725 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
727 /* restore things */
728 if(backbuffer) {
729 hr = IDirect3DDevice8_SetRenderTarget(device, backbuffer, depthstencil);
730 IDirect3DSurface8_Release(backbuffer);
732 if(offscreenTexture) {
733 IDirect3DTexture8_Release(offscreenTexture);
735 if(offscreen) {
736 IDirect3DSurface8_Release(offscreen);
738 if(depthstencil) {
739 IDirect3DSurface8_Release(depthstencil);
743 static void alpha_test(IDirect3DDevice8 *device)
745 HRESULT hr;
746 IDirect3DTexture8 *offscreenTexture;
747 IDirect3DSurface8 *backbuffer = NULL, *offscreen = NULL, *depthstencil = NULL;
748 DWORD color;
750 struct vertex quad1[] =
752 {-1.0f, -1.0f, 0.1f, 0x4000ff00},
753 {-1.0f, 0.0f, 0.1f, 0x4000ff00},
754 { 1.0f, -1.0f, 0.1f, 0x4000ff00},
755 { 1.0f, 0.0f, 0.1f, 0x4000ff00},
757 struct vertex quad2[] =
759 {-1.0f, 0.0f, 0.1f, 0xc00000ff},
760 {-1.0f, 1.0f, 0.1f, 0xc00000ff},
761 { 1.0f, 0.0f, 0.1f, 0xc00000ff},
762 { 1.0f, 1.0f, 0.1f, 0xc00000ff},
764 static const float composite_quad[][5] = {
765 { 0.0f, -1.0f, 0.1f, 0.0f, 1.0f},
766 { 0.0f, 1.0f, 0.1f, 0.0f, 0.0f},
767 { 1.0f, -1.0f, 0.1f, 1.0f, 1.0f},
768 { 1.0f, 1.0f, 0.1f, 1.0f, 0.0f},
771 /* Clear the render target with alpha = 0.5 */
772 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x80ff0000, 0.0, 0);
773 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
775 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &offscreenTexture);
776 ok(hr == D3D_OK || D3DERR_INVALIDCALL, "Creating the offscreen render target failed, hr = %#08x\n", hr);
778 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &depthstencil);
779 ok(hr == D3D_OK, "IDirect3DDevice8_GetDepthStencilSurface failed, hr = %#08x\n", hr);
781 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
782 ok(hr == D3D_OK, "Can't get back buffer, hr = %#08x\n", hr);
783 if(!backbuffer) {
784 goto out;
786 hr = IDirect3DTexture8_GetSurfaceLevel(offscreenTexture, 0, &offscreen);
787 ok(hr == D3D_OK, "Can't get offscreen surface, hr = %#08x\n", hr);
788 if(!offscreen) {
789 goto out;
792 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
793 ok(hr == D3D_OK, "SetVertexShader failed, hr = %#08x\n", hr);
795 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
796 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %#08x\n", hr);
797 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
798 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %#08x\n", hr);
799 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MINFILTER, D3DTEXF_NONE);
800 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MINFILTER failed (%#08x)\n", hr);
801 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MAGFILTER, D3DTEXF_NONE);
802 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MAGFILTER failed (%#08x)\n", hr);
803 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
804 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %08x\n", hr);
806 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, TRUE);
807 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
808 if(IDirect3DDevice8_BeginScene(device) == D3D_OK) {
810 /* Draw two quads, one with src alpha blending, one with dest alpha blending. */
811 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
812 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
813 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
814 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
815 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(quad1[0]));
816 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
818 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_DESTALPHA);
819 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
820 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVDESTALPHA);
821 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
822 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(quad2[0]));
823 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
825 /* Switch to the offscreen buffer, and redo the testing. The offscreen render target
826 * doesn't have an alpha channel. DESTALPHA and INVDESTALPHA "don't work" on render
827 * targets without alpha channel, they give essentially ZERO and ONE blend factors. */
828 hr = IDirect3DDevice8_SetRenderTarget(device, offscreen, 0);
829 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
830 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x80ff0000, 0.0, 0);
831 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
833 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
834 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
835 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
836 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
837 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(quad1[0]));
838 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
840 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_DESTALPHA);
841 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
842 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVDESTALPHA);
843 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
844 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(quad2[0]));
845 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
847 hr = IDirect3DDevice8_SetRenderTarget(device, backbuffer, depthstencil);
848 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
850 /* Render the offscreen texture onto the frame buffer to be able to compare it regularly.
851 * Disable alpha blending for the final composition
853 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, FALSE);
854 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
855 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_TEX1);
856 ok(hr == D3D_OK, "SetVertexShader failed, hr = %#08x\n", hr);
858 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) offscreenTexture);
859 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
860 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, composite_quad, sizeof(float) * 5);
861 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
862 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
863 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
865 hr = IDirect3DDevice8_EndScene(device);
866 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed, hr = %08x\n", hr);
869 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
871 color = getPixelColor(device, 160, 360);
872 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xbf, 0x40, 0x00), 1),
873 "SRCALPHA on frame buffer returned color %08x, expected 0x00bf4000\n", color);
875 color = getPixelColor(device, 160, 120);
876 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x7f, 0x00, 0x80), 2),
877 "DSTALPHA on frame buffer returned color %08x, expected 0x007f0080\n", color);
879 color = getPixelColor(device, 480, 360);
880 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xbf, 0x40, 0x00), 1),
881 "SRCALPHA on texture returned color %08x, expected 0x00bf4000\n", color);
883 color = getPixelColor(device, 480, 120);
884 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0xff), 1),
885 "DSTALPHA on texture returned color %08x, expected 0x000000ff\n", color);
887 out:
888 /* restore things */
889 if(backbuffer) {
890 IDirect3DSurface8_Release(backbuffer);
892 if(offscreenTexture) {
893 IDirect3DTexture8_Release(offscreenTexture);
895 if(offscreen) {
896 IDirect3DSurface8_Release(offscreen);
898 if(depthstencil) {
899 IDirect3DSurface8_Release(depthstencil);
903 static void p8_texture_test(IDirect3DDevice8 *device)
905 IDirect3D8 *d3d = NULL;
906 HRESULT hr;
907 IDirect3DTexture8 *texture = NULL, *texture2 = NULL;
908 D3DLOCKED_RECT lr;
909 unsigned char *data;
910 DWORD color, red, green, blue;
911 PALETTEENTRY table[256];
912 D3DCAPS8 caps;
913 UINT i;
914 float quad[] = {
915 -1.0, 0, 0.1, 0.0, 0.0,
916 -1.0, 1.0, 0.1, 0.0, 1.0,
917 1.0, 0, 0.1, 1.0, 0.0,
918 1.0, 1.0, 0.1, 1.0, 1.0,
920 float quad2[] = {
921 -1.0, -1.0, 0.1, 0.0, 0.0,
922 -1.0, 0, 0.1, 0.0, 1.0,
923 1.0, -1.0, 0.1, 1.0, 0.0,
924 1.0, 0, 0.1, 1.0, 1.0,
927 IDirect3DDevice8_GetDirect3D(device, &d3d);
929 if(IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, 0,
930 D3DRTYPE_TEXTURE, D3DFMT_P8) != D3D_OK) {
931 skip("D3DFMT_P8 textures not supported\n");
932 goto out;
935 hr = IDirect3DDevice8_CreateTexture(device, 1, 1, 1, 0, D3DFMT_P8,
936 D3DPOOL_MANAGED, &texture2);
937 ok(hr == D3D_OK, "IDirect3DDevice8_CreateTexture failed, hr = %08x\n", hr);
938 if(!texture2) {
939 skip("Failed to create D3DFMT_P8 texture\n");
940 goto out;
943 memset(&lr, 0, sizeof(lr));
944 hr = IDirect3DTexture8_LockRect(texture2, 0, &lr, NULL, 0);
945 ok(hr == D3D_OK, "IDirect3DTexture8_LockRect failed, hr = %08x\n", hr);
946 data = lr.pBits;
947 *data = 1;
949 hr = IDirect3DTexture8_UnlockRect(texture2, 0);
950 ok(hr == D3D_OK, "IDirect3DTexture8_UnlockRect failed, hr = %08x\n", hr);
952 hr = IDirect3DDevice8_CreateTexture(device, 1, 1, 1, 0, D3DFMT_P8,
953 D3DPOOL_MANAGED, &texture);
954 ok(hr == D3D_OK, "IDirect3DDevice8_CreateTexture failed, hr = %08x\n", hr);
955 if(!texture) {
956 skip("Failed to create D3DFMT_P8 texture\n");
957 goto out;
960 memset(&lr, 0, sizeof(lr));
961 hr = IDirect3DTexture8_LockRect(texture, 0, &lr, NULL, 0);
962 ok(hr == D3D_OK, "IDirect3DTexture8_LockRect failed, hr = %08x\n", hr);
963 data = lr.pBits;
964 *data = 1;
966 hr = IDirect3DTexture8_UnlockRect(texture, 0);
967 ok(hr == D3D_OK, "IDirect3DTexture8_UnlockRect failed, hr = %08x\n", hr);
969 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff000000, 0.0, 0);
970 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed, hr = %08x\n", hr);
972 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, TRUE);
973 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
975 /* The first part of the test should work both with and without D3DPTEXTURECAPS_ALPHAPALETTE;
976 alpha of every entry is set to 1.0, which MS says is required when there's no
977 D3DPTEXTURECAPS_ALPHAPALETTE capability */
978 for (i = 0; i < 256; i++) {
979 table[i].peRed = table[i].peGreen = table[i].peBlue = 0;
980 table[i].peFlags = 0xff;
982 table[1].peRed = 0xff;
983 hr = IDirect3DDevice8_SetPaletteEntries(device, 0, table);
984 ok(hr == D3D_OK, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr);
986 table[1].peRed = 0;
987 table[1].peBlue = 0xff;
988 hr = IDirect3DDevice8_SetPaletteEntries(device, 1, table);
989 ok(hr == D3D_OK, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr);
991 hr = IDirect3DDevice8_BeginScene(device);
992 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed, hr = %08x\n", hr);
993 if(SUCCEEDED(hr)) {
994 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
995 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
996 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
997 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
999 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_TEX1);
1000 ok(hr == D3D_OK, "SetVertexShader failed, hr = %#08x\n", hr);
1002 hr = IDirect3DDevice8_SetCurrentTexturePalette(device, 0);
1003 ok(hr == D3D_OK, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr);
1005 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) texture2);
1006 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
1007 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
1008 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1010 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) texture);
1011 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
1012 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
1013 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1015 hr = IDirect3DDevice8_SetCurrentTexturePalette(device, 1);
1016 ok(hr == D3D_OK, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr);
1017 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 5 * sizeof(float));
1018 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1020 hr = IDirect3DDevice8_EndScene(device);
1021 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed, hr = %08x\n", hr);
1024 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1025 ok(hr == D3D_OK, "IDirect3DDevice8_Present failed, hr = %08x\n", hr);
1027 color = getPixelColor(device, 32, 32);
1028 red = (color & 0x00ff0000) >> 16;
1029 green = (color & 0x0000ff00) >> 8;
1030 blue = (color & 0x000000ff) >> 0;
1031 ok(red == 0xff && blue == 0 && green == 0,
1032 "got color %08x, expected 0x00ff0000\n", color);
1034 color = getPixelColor(device, 32, 320);
1035 red = (color & 0x00ff0000) >> 16;
1036 green = (color & 0x0000ff00) >> 8;
1037 blue = (color & 0x000000ff) >> 0;
1038 ok(red == 0 && blue == 0xff && green == 0,
1039 "got color %08x, expected 0x000000ff\n", color);
1041 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff000000, 0.0, 0);
1042 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed, hr = %08x\n", hr);
1044 hr = IDirect3DDevice8_BeginScene(device);
1045 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed, hr = %08x\n", hr);
1046 if(SUCCEEDED(hr)) {
1047 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) texture2);
1048 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
1050 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
1051 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1053 hr = IDirect3DDevice8_EndScene(device);
1054 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed, hr = %08x\n", hr);
1057 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1058 ok(hr == D3D_OK, "IDirect3DDevice8_Present failed, hr = %08x\n", hr);
1060 color = getPixelColor(device, 32, 32);
1061 red = (color & 0x00ff0000) >> 16;
1062 green = (color & 0x0000ff00) >> 8;
1063 blue = (color & 0x000000ff) >> 0;
1064 ok(red == 0 && blue == 0xff && green == 0,
1065 "got color %08x, expected 0x000000ff\n", color);
1067 /* Test palettes with alpha */
1068 IDirect3DDevice8_GetDeviceCaps(device, &caps);
1069 if (!(caps.TextureCaps & D3DPTEXTURECAPS_ALPHAPALETTE)) {
1070 skip("no D3DPTEXTURECAPS_ALPHAPALETTE capability, tests with alpha in palette will be skipped\n");
1071 } else {
1072 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff000000, 0.0, 0);
1073 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed, hr = %08x\n", hr);
1075 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, TRUE);
1076 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1078 for (i = 0; i < 256; i++) {
1079 table[i].peRed = table[i].peGreen = table[i].peBlue = 0;
1080 table[i].peFlags = 0xff;
1082 table[1].peRed = 0xff;
1083 table[1].peFlags = 0x80;
1084 hr = IDirect3DDevice8_SetPaletteEntries(device, 0, table);
1085 ok(hr == D3D_OK, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr);
1087 table[1].peRed = 0;
1088 table[1].peBlue = 0xff;
1089 table[1].peFlags = 0x80;
1090 hr = IDirect3DDevice8_SetPaletteEntries(device, 1, table);
1091 ok(hr == D3D_OK, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr);
1093 hr = IDirect3DDevice8_BeginScene(device);
1094 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed, hr = %08x\n", hr);
1095 if(SUCCEEDED(hr)) {
1096 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
1097 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1098 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
1099 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1101 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_TEX1);
1102 ok(hr == D3D_OK, "SetVertexShader failed, hr = %#08x\n", hr);
1104 hr = IDirect3DDevice8_SetCurrentTexturePalette(device, 0);
1105 ok(hr == D3D_OK, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr);
1107 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
1108 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1110 hr = IDirect3DDevice8_SetCurrentTexturePalette(device, 1);
1111 ok(hr == D3D_OK, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr);
1113 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 5 * sizeof(float));
1114 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1116 hr = IDirect3DDevice8_EndScene(device);
1117 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed, hr = %08x\n", hr);
1120 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1121 ok(hr == D3D_OK, "IDirect3DDevice8_Present failed, hr = %08x\n", hr);
1123 color = getPixelColor(device, 32, 32);
1124 red = (color & 0x00ff0000) >> 16;
1125 green = (color & 0x0000ff00) >> 8;
1126 blue = (color & 0x000000ff) >> 0;
1127 ok(red >= 0x7e && red <= 0x81 && blue == 0 && green == 0,
1128 "got color %08x, expected 0x00800000 or near\n", color);
1130 color = getPixelColor(device, 32, 320);
1131 red = (color & 0x00ff0000) >> 16;
1132 green = (color & 0x0000ff00) >> 8;
1133 blue = (color & 0x000000ff) >> 0;
1134 ok(red == 0 && blue >= 0x7e && blue <= 0x81 && green == 0,
1135 "got color %08x, expected 0x00000080 or near\n", color);
1138 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
1139 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
1140 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, FALSE);
1141 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1143 out:
1144 if(texture) IDirect3DTexture8_Release(texture);
1145 if(texture2) IDirect3DTexture8_Release(texture2);
1146 IDirect3D8_Release(d3d);
1149 static void texop_test(IDirect3DDevice8 *device)
1151 IDirect3DTexture8 *texture = NULL;
1152 D3DLOCKED_RECT locked_rect;
1153 D3DCOLOR color;
1154 D3DCAPS8 caps;
1155 HRESULT hr;
1156 int i;
1158 static const struct {
1159 float x, y, z;
1160 D3DCOLOR diffuse;
1161 float s, t;
1162 } quad[] = {
1163 {-1.0f, -1.0f, 0.1f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), -1.0f, -1.0f},
1164 {-1.0f, 1.0f, 0.1f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), -1.0f, 1.0f},
1165 { 1.0f, -1.0f, 0.1f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), 1.0f, -1.0f},
1166 { 1.0f, 1.0f, 0.1f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), 1.0f, 1.0f}
1169 static const struct {
1170 D3DTEXTUREOP op;
1171 const char *name;
1172 DWORD caps_flag;
1173 D3DCOLOR result;
1174 } test_data[] = {
1175 {D3DTOP_SELECTARG1, "SELECTARG1", D3DTEXOPCAPS_SELECTARG1, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00)},
1176 {D3DTOP_SELECTARG2, "SELECTARG2", D3DTEXOPCAPS_SELECTARG2, D3DCOLOR_ARGB(0x00, 0x33, 0x33, 0x33)},
1177 {D3DTOP_MODULATE, "MODULATE", D3DTEXOPCAPS_MODULATE, D3DCOLOR_ARGB(0x00, 0x00, 0x33, 0x00)},
1178 {D3DTOP_MODULATE2X, "MODULATE2X", D3DTEXOPCAPS_MODULATE2X, D3DCOLOR_ARGB(0x00, 0x00, 0x66, 0x00)},
1179 {D3DTOP_MODULATE4X, "MODULATE4X", D3DTEXOPCAPS_MODULATE4X, D3DCOLOR_ARGB(0x00, 0x00, 0xcc, 0x00)},
1180 {D3DTOP_ADD, "ADD", D3DTEXOPCAPS_ADD, D3DCOLOR_ARGB(0x00, 0x33, 0xff, 0x33)},
1181 {D3DTOP_ADDSIGNED, "ADDSIGNED", D3DTEXOPCAPS_ADDSIGNED, D3DCOLOR_ARGB(0x00, 0x00, 0xb2, 0x00)},
1182 {D3DTOP_ADDSIGNED2X, "ADDSIGNED2X", D3DTEXOPCAPS_ADDSIGNED2X, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00)},
1183 {D3DTOP_SUBTRACT, "SUBTRACT", D3DTEXOPCAPS_SUBTRACT, D3DCOLOR_ARGB(0x00, 0x00, 0xcc, 0x00)},
1184 {D3DTOP_ADDSMOOTH, "ADDSMOOTH", D3DTEXOPCAPS_ADDSMOOTH, D3DCOLOR_ARGB(0x00, 0x33, 0xff, 0x33)},
1185 {D3DTOP_BLENDDIFFUSEALPHA, "BLENDDIFFUSEALPHA", D3DTEXOPCAPS_BLENDDIFFUSEALPHA, D3DCOLOR_ARGB(0x00, 0x22, 0x77, 0x22)},
1186 {D3DTOP_BLENDTEXTUREALPHA, "BLENDTEXTUREALPHA", D3DTEXOPCAPS_BLENDTEXTUREALPHA, D3DCOLOR_ARGB(0x00, 0x14, 0xad, 0x14)},
1187 {D3DTOP_BLENDFACTORALPHA, "BLENDFACTORALPHA", D3DTEXOPCAPS_BLENDFACTORALPHA, D3DCOLOR_ARGB(0x00, 0x07, 0xe4, 0x07)},
1188 {D3DTOP_BLENDTEXTUREALPHAPM, "BLENDTEXTUREALPHAPM", D3DTEXOPCAPS_BLENDTEXTUREALPHAPM, D3DCOLOR_ARGB(0x00, 0x14, 0xff, 0x14)},
1189 {D3DTOP_BLENDCURRENTALPHA, "BLENDCURRENTALPHA", D3DTEXOPCAPS_BLENDCURRENTALPHA, D3DCOLOR_ARGB(0x00, 0x22, 0x77, 0x22)},
1190 {D3DTOP_MODULATEALPHA_ADDCOLOR, "MODULATEALPHA_ADDCOLOR", D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR, D3DCOLOR_ARGB(0x00, 0x1f, 0xff, 0x1f)},
1191 {D3DTOP_MODULATECOLOR_ADDALPHA, "MODULATECOLOR_ADDALPHA", D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA, D3DCOLOR_ARGB(0x00, 0x99, 0xcc, 0x99)},
1192 {D3DTOP_MODULATEINVALPHA_ADDCOLOR, "MODULATEINVALPHA_ADDCOLOR", D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR, D3DCOLOR_ARGB(0x00, 0x14, 0xff, 0x14)},
1193 {D3DTOP_MODULATEINVCOLOR_ADDALPHA, "MODULATEINVCOLOR_ADDALPHA", D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA, D3DCOLOR_ARGB(0x00, 0xcc, 0x99, 0xcc)},
1194 /* BUMPENVMAP & BUMPENVMAPLUMINANCE have their own tests */
1195 {D3DTOP_DOTPRODUCT3, "DOTPRODUCT2", D3DTEXOPCAPS_DOTPRODUCT3, D3DCOLOR_ARGB(0x00, 0x99, 0x99, 0x99)},
1196 {D3DTOP_MULTIPLYADD, "MULTIPLYADD", D3DTEXOPCAPS_MULTIPLYADD, D3DCOLOR_ARGB(0x00, 0xff, 0x33, 0x00)},
1197 {D3DTOP_LERP, "LERP", D3DTEXOPCAPS_LERP, D3DCOLOR_ARGB(0x00, 0x00, 0x33, 0x33)},
1200 memset(&caps, 0, sizeof(caps));
1201 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
1202 ok(SUCCEEDED(hr), "GetDeviceCaps failed with 0x%08x\n", hr);
1204 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX0);
1205 ok(SUCCEEDED(hr), "SetVertexShader failed with 0x%08x\n", hr);
1207 hr = IDirect3DDevice8_CreateTexture(device, 1, 1, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture);
1208 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateTexture failed with 0x%08x\n", hr);
1209 hr = IDirect3DTexture8_LockRect(texture, 0, &locked_rect, NULL, 0);
1210 ok(SUCCEEDED(hr), "LockRect failed with 0x%08x\n", hr);
1211 *((DWORD *)locked_rect.pBits) = D3DCOLOR_ARGB(0x99, 0x00, 0xff, 0x00);
1212 hr = IDirect3DTexture8_UnlockRect(texture, 0);
1213 ok(SUCCEEDED(hr), "LockRect failed with 0x%08x\n", hr);
1214 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *)texture);
1215 ok(SUCCEEDED(hr), "SetTexture failed with 0x%08x\n", hr);
1217 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLORARG0, D3DTA_DIFFUSE);
1218 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
1219 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
1220 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
1221 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
1222 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
1224 hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
1225 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
1227 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
1228 ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
1229 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0xdd333333);
1230 ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
1231 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA);
1232 ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
1234 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
1235 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
1237 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
1239 if (!(caps.TextureOpCaps & test_data[i].caps_flag))
1241 skip("tex operation %s not supported\n", test_data[i].name);
1242 continue;
1245 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLOROP, test_data[i].op);
1246 ok(SUCCEEDED(hr), "SetTextureStageState (%s) failed with 0x%08x\n", test_data[i].name, hr);
1248 hr = IDirect3DDevice8_BeginScene(device);
1249 ok(SUCCEEDED(hr), "BeginScene failed with 0x%08x\n", hr);
1251 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
1252 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed with 0x%08x\n", hr);
1254 hr = IDirect3DDevice8_EndScene(device);
1255 ok(SUCCEEDED(hr), "EndScene failed with 0x%08x\n", hr);
1257 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1258 ok(SUCCEEDED(hr), "Present failed with 0x%08x\n", hr);
1260 color = getPixelColor(device, 320, 240);
1261 ok(color_match(color, test_data[i].result, 3), "Operation %s returned color 0x%08x, expected 0x%08x\n",
1262 test_data[i].name, color, test_data[i].result);
1265 if (texture) IDirect3DTexture8_Release(texture);
1268 START_TEST(visual)
1270 IDirect3DDevice8 *device_ptr;
1271 HRESULT hr;
1272 DWORD color;
1273 D3DCAPS8 caps;
1275 d3d8_handle = LoadLibraryA("d3d8.dll");
1276 if (!d3d8_handle)
1278 skip("Could not load d3d8.dll\n");
1279 return;
1282 device_ptr = init_d3d8();
1283 if (!device_ptr)
1285 skip("Could not initialize direct3d\n");
1286 return;
1289 IDirect3DDevice8_GetDeviceCaps(device_ptr, &caps);
1291 /* Check for the reliability of the returned data */
1292 hr = IDirect3DDevice8_Clear(device_ptr, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
1293 if(FAILED(hr))
1295 trace("Clear failed, can't assure correctness of the test results, skipping\n");
1296 goto cleanup;
1298 IDirect3DDevice8_Present(device_ptr, NULL, NULL, NULL, NULL);
1300 color = getPixelColor(device_ptr, 1, 1);
1301 if(color !=0x00ff0000)
1303 trace("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests, skipping\n", color);
1304 goto cleanup;
1307 hr = IDirect3DDevice8_Clear(device_ptr, 0, NULL, D3DCLEAR_TARGET, 0xff00ddee, 0.0, 0);
1308 if(FAILED(hr))
1310 trace("Clear failed, can't assure correctness of the test results, skipping\n");
1311 goto cleanup;
1313 IDirect3DDevice8_Present(device_ptr, NULL, NULL, NULL, NULL);
1315 color = getPixelColor(device_ptr, 639, 479);
1316 if(color != 0x0000ddee)
1318 trace("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests, skipping\n", color);
1319 goto cleanup;
1322 /* Now run the real test */
1323 lighting_test(device_ptr);
1324 clear_test(device_ptr);
1325 fog_test(device_ptr);
1326 present_test(device_ptr);
1327 offscreen_test(device_ptr);
1328 alpha_test(device_ptr);
1330 if (caps.VertexShaderVersion >= D3DVS_VERSION(1, 1))
1332 test_rcp_rsq(device_ptr);
1334 else
1336 skip("No vs.1.1 support\n");
1339 p8_texture_test(device_ptr);
1340 texop_test(device_ptr);
1342 cleanup:
1343 if(device_ptr) {
1344 D3DDEVICE_CREATION_PARAMETERS creation_parameters;
1345 IDirect3DDevice8_GetCreationParameters(device_ptr, &creation_parameters);
1346 IDirect3DDevice8_Release(device_ptr);
1347 DestroyWindow(creation_parameters.hFocusWindow);