direct3d: Remove misspelled constants as they exist correctly spelled.
[wine] / dlls / d3d8 / tests / visual.c
1 /*
2  * Copyright (C) 2005 Henri Verbeet
3  * Copyright (C) 2007 Stefan Dösinger(for CodeWeavers)
4  *
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.
9  *
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.
14  *
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
18  */
19
20 /* See comment in dlls/d3d9/tests/visual.c for general guidelines */
21
22 #define COBJMACROS
23 #include <d3d8.h>
24 #include <dxerr8.h>
25 #include "wine/test.h"
26
27 static HMODULE d3d8_handle = 0;
28
29 static HWND create_window(void)
30 {
31     WNDCLASS wc = {0};
32     HWND ret;
33     wc.lpfnWndProc = &DefWindowProc;
34     wc.lpszClassName = "d3d8_test_wc";
35     RegisterClass(&wc);
36
37     ret = CreateWindow("d3d8_test_wc", "d3d8_test",
38                         WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
39     return ret;
40 }
41
42 static DWORD getPixelColor(IDirect3DDevice8 *device, UINT x, UINT y)
43 {
44     DWORD ret;
45     IDirect3DSurface8 *surf;
46     IDirect3DTexture8 *tex;
47     HRESULT hr;
48     D3DLOCKED_RECT lockedRect;
49     RECT rectToLock = {x, y, x+1, y+1};
50
51     hr = IDirect3DDevice8_CreateTexture(device, 640, 480, 1 /* Levels */, 0 /* usage */, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &tex);
52     if(FAILED(hr) || !tex )  /* This is not a test */
53     {
54         trace("Can't create an offscreen plain surface to read the render target data, hr=%s\n", DXGetErrorString8(hr));
55         return 0xdeadbeef;
56     }
57     hr = IDirect3DTexture8_GetSurfaceLevel(tex, 0, &surf);
58     if(FAILED(hr) || !tex )  /* This is not a test */
59     {
60         trace("Can't get surface from texture, hr=%s\n", DXGetErrorString8(hr));
61         ret = 0xdeadbeee;
62         goto out;
63     }
64
65     hr = IDirect3DDevice8_GetFrontBuffer(device, surf);
66     if(FAILED(hr))
67     {
68         trace("Can't read the front buffer data, hr=%s\n", DXGetErrorString8(hr));
69         ret = 0xdeadbeed;
70         goto out;
71     }
72
73     hr = IDirect3DSurface8_LockRect(surf, &lockedRect, &rectToLock, D3DLOCK_READONLY);
74     if(FAILED(hr))
75     {
76         trace("Can't lock the offscreen surface, hr=%s\n", DXGetErrorString8(hr));
77         ret = 0xdeadbeec;
78         goto out;
79     }
80     /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
81      * really important for these tests
82      */
83     ret = ((DWORD *) lockedRect.pBits)[0] & 0x00ffffff;
84     hr = IDirect3DSurface8_UnlockRect(surf);
85     if(FAILED(hr))
86     {
87         trace("Can't unlock the offscreen surface, hr=%s\n", DXGetErrorString8(hr));
88     }
89
90 out:
91     if(surf) IDirect3DSurface8_Release(surf);
92     if(tex) IDirect3DTexture8_Release(tex);
93     return ret;
94 }
95
96 static IDirect3DDevice8 *init_d3d8(void)
97 {
98     IDirect3D8 * (__stdcall * d3d8_create)(UINT SDKVersion) = 0;
99     IDirect3D8 *d3d8_ptr = 0;
100     IDirect3DDevice8 *device_ptr = 0;
101     D3DPRESENT_PARAMETERS present_parameters;
102     HRESULT hr;
103
104     d3d8_create = (void *)GetProcAddress(d3d8_handle, "Direct3DCreate8");
105     ok(d3d8_create != NULL, "Failed to get address of Direct3DCreate8\n");
106     if (!d3d8_create) return NULL;
107
108     d3d8_ptr = d3d8_create(D3D_SDK_VERSION);
109     ok(d3d8_ptr != NULL, "Failed to create IDirect3D8 object\n");
110     if (!d3d8_ptr) return NULL;
111
112     ZeroMemory(&present_parameters, sizeof(present_parameters));
113     present_parameters.Windowed = FALSE;
114     present_parameters.hDeviceWindow = create_window();
115     present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
116     present_parameters.BackBufferWidth = 640;
117     present_parameters.BackBufferHeight = 480;
118     present_parameters.BackBufferFormat = D3DFMT_X8R8G8B8;
119
120     hr = IDirect3D8_CreateDevice(d3d8_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
121     ok(hr == D3D_OK, "IDirect3D_CreateDevice returned: %s\n", DXGetErrorString8(hr));
122
123     return device_ptr;
124 }
125
126 struct vertex
127 {
128     float x, y, z;
129     DWORD diffuse;
130 };
131
132 struct nvertex
133 {
134     float x, y, z;
135     float nx, ny, nz;
136     DWORD diffuse;
137 };
138
139 static void lighting_test(IDirect3DDevice8 *device)
140 {
141     HRESULT hr;
142     DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
143     DWORD nfvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_NORMAL;
144     DWORD color;
145
146     float mat[16] = { 1.0, 0.0, 0.0, 0.0,
147                       0.0, 1.0, 0.0, 0.0,
148                       0.0, 0.0, 1.0, 0.0,
149                       0.0, 0.0, 0.0, 1.0 };
150
151     struct vertex unlitquad[] =
152     {
153         {-1.0,  -1.0,    0.1,                           0xffff0000},
154         {-1.0,   0.0,    0.1,                           0xffff0000},
155         { 0.0,   0.0,    0.1,                           0xffff0000},
156         { 0.0,  -1.0,    0.1,                           0xffff0000},
157     };
158     struct vertex litquad[] =
159     {
160         {-1.0,   0.0,    0.1,                           0xff00ff00},
161         {-1.0,   1.0,    0.1,                           0xff00ff00},
162         { 0.0,   1.0,    0.1,                           0xff00ff00},
163         { 0.0,   0.0,    0.1,                           0xff00ff00},
164     };
165     struct nvertex unlitnquad[] =
166     {
167         { 0.0,  -1.0,    0.1,   1.0,    1.0,    1.0,    0xff0000ff},
168         { 0.0,   0.0,    0.1,   1.0,    1.0,    1.0,    0xff0000ff},
169         { 1.0,   0.0,    0.1,   1.0,    1.0,    1.0,    0xff0000ff},
170         { 1.0,  -1.0,    0.1,   1.0,    1.0,    1.0,    0xff0000ff},
171     };
172     struct nvertex litnquad[] =
173     {
174         { 0.0,   0.0,    0.1,   1.0,    1.0,    1.0,    0xffffff00},
175         { 0.0,   1.0,    0.1,   1.0,    1.0,    1.0,    0xffffff00},
176         { 1.0,   1.0,    0.1,   1.0,    1.0,    1.0,    0xffffff00},
177         { 1.0,   0.0,    0.1,   1.0,    1.0,    1.0,    0xffffff00},
178     };
179     WORD Indices[] = {0, 1, 2, 2, 3, 0};
180
181     hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
182     ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %s\n", DXGetErrorString8(hr));
183
184     /* Setup some states that may cause issues */
185     hr = IDirect3DDevice8_SetTransform(device, D3DTS_WORLDMATRIX(0), (D3DMATRIX *) mat);
186     ok(hr == D3D_OK, "IDirect3DDevice8_SetTransform returned %s\n", DXGetErrorString8(hr));
187     hr = IDirect3DDevice8_SetTransform(device, D3DTS_VIEW, (D3DMATRIX *)mat);
188     ok(hr == D3D_OK, "IDirect3DDevice8_SetTransform returned %s\n", DXGetErrorString8(hr));
189     hr = IDirect3DDevice8_SetTransform(device, D3DTS_PROJECTION, (D3DMATRIX *) mat);
190     ok(hr == D3D_OK, "IDirect3DDevice8_SetTransform returned %s\n", DXGetErrorString8(hr));
191     hr = IDirect3DDevice8_SetRenderState(device, D3DRS_CLIPPING, FALSE);
192     ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %s\n", DXGetErrorString8(hr));
193     hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, FALSE);
194     ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %s\n", DXGetErrorString8(hr));
195     hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGENABLE, FALSE);
196     ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %s\n", DXGetErrorString8(hr));
197     hr = IDirect3DDevice8_SetRenderState(device, D3DRS_STENCILENABLE, FALSE);
198     ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %s\n", DXGetErrorString8(hr));
199     hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHATESTENABLE, FALSE);
200     ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %s\n", DXGetErrorString8(hr));
201     hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, FALSE);
202     ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %s\n", DXGetErrorString8(hr));
203     hr = IDirect3DDevice8_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE);
204     ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed with %s\n", DXGetErrorString8(hr));
205     hr = IDirect3DDevice8_SetRenderState(device, D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE);
206     ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed with %s\n", DXGetErrorString8(hr));
207
208     hr = IDirect3DDevice8_SetVertexShader(device, fvf);
209     ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %s\n", DXGetErrorString8(hr));
210
211     hr = IDirect3DDevice8_BeginScene(device);
212     ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %s\n", DXGetErrorString8(hr));
213     if(hr == D3D_OK)
214     {
215         /* No lights are defined... That means, lit vertices should be entirely black */
216         hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
217         ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %s\n", DXGetErrorString8(hr));
218         hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
219                                                     2 /*PrimCount */, Indices, D3DFMT_INDEX16, unlitquad, sizeof(unlitquad[0]));
220         ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %s\n", DXGetErrorString8(hr));
221
222         hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, TRUE);
223         ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %s\n", DXGetErrorString8(hr));
224         hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
225                                                     2 /*PrimCount */, Indices, D3DFMT_INDEX16, litquad, sizeof(litquad[0]));
226         ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %s\n", DXGetErrorString8(hr));
227
228         hr = IDirect3DDevice8_SetVertexShader(device, nfvf);
229         ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader failed with %s\n", DXGetErrorString8(hr));
230
231         hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
232         ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %s\n", DXGetErrorString8(hr));
233         hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
234                                                     2 /*PrimCount */, Indices, D3DFMT_INDEX16, unlitnquad, sizeof(unlitnquad[0]));
235         ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %s\n", DXGetErrorString8(hr));
236
237         hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, TRUE);
238         ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %s\n", DXGetErrorString8(hr));
239         hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
240                                                     2 /*PrimCount */, Indices, D3DFMT_INDEX16, litnquad, sizeof(litnquad[0]));
241         ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %s\n", DXGetErrorString8(hr));
242
243         IDirect3DDevice8_EndScene(device);
244         ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %s\n", DXGetErrorString8(hr));
245     }
246
247     IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
248
249     color = getPixelColor(device, 160, 360); /* lower left quad - unlit without normals */
250     ok(color == 0x00ff0000, "Unlit quad without normals has color %08x\n", color);
251     color = getPixelColor(device, 160, 120); /* upper left quad - lit without normals */
252     ok(color == 0x00000000, "Lit quad without normals has color %08x\n", color);
253     color = getPixelColor(device, 480, 360); /* lower left quad - unlit width normals */
254     ok(color == 0x000000ff, "Unlit quad width normals has color %08x\n", color);
255     color = getPixelColor(device, 480, 120); /* upper left quad - lit width normals */
256     ok(color == 0x00000000, "Lit quad width normals has color %08x\n", color);
257
258     hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
259     ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %s\n", DXGetErrorString8(hr));
260 }
261
262 static void clear_test(IDirect3DDevice8 *device)
263 {
264     /* Tests the correctness of clearing parameters */
265     HRESULT hr;
266     D3DRECT rect[2];
267     D3DRECT rect_negneg;
268     DWORD color;
269
270     hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
271     ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %s\n", DXGetErrorString8(hr));
272
273     /* Positive x, negative y */
274     rect[0].x1 = 0;
275     rect[0].y1 = 480;
276     rect[0].x2 = 320;
277     rect[0].y2 = 240;
278
279     /* Positive x, positive y */
280     rect[1].x1 = 0;
281     rect[1].y1 = 0;
282     rect[1].x2 = 320;
283     rect[1].y2 = 240;
284     /* Clear 2 rectangles with one call. Shows that a positive value is returned, but the negative rectangle
285      * is ignored, the positive is still cleared afterwards
286      */
287     hr = IDirect3DDevice8_Clear(device, 2, rect, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
288     ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %s\n", DXGetErrorString8(hr));
289
290     /* negative x, negative y */
291     rect_negneg.x1 = 640;
292     rect_negneg.x1 = 240;
293     rect_negneg.x2 = 320;
294     rect_negneg.y2 = 0;
295     hr = IDirect3DDevice8_Clear(device, 1, &rect_negneg, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
296     ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %s\n", DXGetErrorString8(hr));
297
298     IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
299
300     color = getPixelColor(device, 160, 360); /* lower left quad */
301     ok(color == 0x00ffffff, "Clear rectangle 3(pos, neg) has color %08x\n", color);
302     color = getPixelColor(device, 160, 120); /* upper left quad */
303     ok(color == 0x00ff0000, "Clear rectangle 1(pos, pos) has color %08x\n", color);
304     color = getPixelColor(device, 480, 360); /* lower right quad  */
305     ok(color == 0x00ffffff, "Clear rectangle 4(NULL) has color %08x\n", color);
306     color = getPixelColor(device, 480, 120); /* upper right quad */
307     ok(color == 0x00ffffff, "Clear rectangle 4(neg, neg) has color %08x\n", color);
308 }
309
310 struct sVertex {
311     float x, y, z;
312     DWORD diffuse;
313     DWORD specular;
314 };
315
316 struct sVertexT {
317     float x, y, z, rhw;
318     DWORD diffuse;
319     DWORD specular;
320 };
321
322 static void fog_test(IDirect3DDevice8 *device)
323 {
324     HRESULT hr;
325     DWORD color;
326     float start = 0.0, end = 1.0;
327
328     /* Gets full z based fog with linear fog, no fog with specular color */
329     struct sVertex unstransformed_1[] = {
330         {-1,    -1,   0.1,          0xFFFF0000,     0xFF000000  },
331         {-1,     0,   0.1,          0xFFFF0000,     0xFF000000  },
332         { 0,     0,   0.1,          0xFFFF0000,     0xFF000000  },
333         { 0,    -1,   0.1,          0xFFFF0000,     0xFF000000  },
334     };
335     /* Ok, I am too lazy to deal with transform matrices */
336     struct sVertex unstransformed_2[] = {
337         {-1,     0,   1.0,          0xFFFF0000,     0xFF000000  },
338         {-1,     1,   1.0,          0xFFFF0000,     0xFF000000  },
339         { 0,     1,   1.0,          0xFFFF0000,     0xFF000000  },
340         { 0,     0,   1.0,          0xFFFF0000,     0xFF000000  },
341     };
342     /* Untransformed ones. Give them a different diffuse color to make the test look
343      * nicer. It also makes making sure that they are drawn correctly easier.
344      */
345     struct sVertexT transformed_1[] = {
346         {320,    0,   1.0,  1.0,    0xFFFFFF00,     0xFF000000  },
347         {640,    0,   1.0,  1.0,    0xFFFFFF00,     0xFF000000  },
348         {640,  240,   1.0,  1.0,    0xFFFFFF00,     0xFF000000  },
349         {320,  240,   1.0,  1.0,    0xFFFFFF00,     0xFF000000  },
350     };
351     struct sVertexT transformed_2[] = {
352         {320,  240,   1.0,  1.0,    0xFFFFFF00,     0xFF000000  },
353         {640,  240,   1.0,  1.0,    0xFFFFFF00,     0xFF000000  },
354         {640,  480,   1.0,  1.0,    0xFFFFFF00,     0xFF000000  },
355         {320,  480,   1.0,  1.0,    0xFFFFFF00,     0xFF000000  },
356     };
357     WORD Indices[] = {0, 1, 2, 2, 3, 0};
358
359     hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
360     ok(hr == D3D_OK, "IDirect3DDevice8_Clear returned %s\n", DXGetErrorString8(hr));
361
362     /* Setup initial states: No lighting, fog on, fog color */
363     hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
364     ok(hr == D3D_OK, "Turning off lighting returned %s\n", DXGetErrorString8(hr));
365     hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGENABLE, TRUE);
366     ok(hr == D3D_OK, "Turning on fog calculations returned %s\n", DXGetErrorString8(hr));
367     hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGCOLOR, 0xFF00FF00 /* A nice green */);
368     ok(hr == D3D_OK, "Turning on fog calculations returned %s\n", DXGetErrorString8(hr));
369
370     /* First test: Both table fog and vertex fog off */
371     hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_NONE);
372     ok(hr == D3D_OK, "Turning off table fog returned %s\n", DXGetErrorString8(hr));
373     hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGVERTEXMODE, D3DFOG_NONE);
374     ok(hr == D3D_OK, "Turning off table fog returned %s\n", DXGetErrorString8(hr));
375
376     /* Start = 0, end = 1. Should be default, but set them */
377     hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGSTART, *((DWORD *) &start));
378     ok(hr == D3D_OK, "Setting fog start returned %s\n", DXGetErrorString8(hr));
379     hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGEND, *((DWORD *) &end));
380     ok(hr == D3D_OK, "Setting fog start returned %s\n", DXGetErrorString8(hr));
381
382     if(IDirect3DDevice8_BeginScene(device) == D3D_OK)
383     {
384         hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
385         ok( hr == D3D_OK, "SetVertexShader returned %s\n", DXGetErrorString8(hr));
386         /* Untransformed, vertex fog = NONE, table fog = NONE: Read the fog weighting from the specular color */
387         hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
388                                                      2 /*PrimCount */, Indices, D3DFMT_INDEX16, unstransformed_1,
389                                                      sizeof(unstransformed_1[0]));
390         ok(hr == D3D_OK, "DrawIndexedPrimitiveUP returned %s\n", DXGetErrorString8(hr));
391
392         /* That makes it use the Z value */
393         hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR);
394         ok(hr == D3D_OK, "Turning off table fog returned %s\n", DXGetErrorString8(hr));
395         /* Untransformed, vertex fog != none (or table fog != none):
396          * Use the Z value as input into the equation
397          */
398         hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
399                                                      2 /*PrimCount */, Indices, D3DFMT_INDEX16, unstransformed_2,
400                                                      sizeof(unstransformed_1[0]));
401         ok(hr == D3D_OK, "DrawIndexedPrimitiveUP returned %s\n", DXGetErrorString8(hr));
402
403         /* transformed verts */
404         hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
405         ok( hr == D3D_OK, "SetVertexShader returned %s\n", DXGetErrorString8(hr));
406         /* Transformed, vertex fog != NONE, pixel fog == NONE: Use specular color alpha component */
407         hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
408                                                      2 /*PrimCount */, Indices, D3DFMT_INDEX16, transformed_1,
409                                                      sizeof(transformed_1[0]));
410         ok(hr == D3D_OK, "DrawIndexedPrimitiveUP returned %s\n", DXGetErrorString8(hr));
411
412         hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);
413         ok( hr == D3D_OK, "Setting fog table mode to D3DFOG_LINEAR returned %s\n", DXGetErrorString8(hr));
414         /* Transformed, table fog != none, vertex anything: Use Z value as input to the fog
415          * equation
416          */
417         hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
418                                                      2 /*PrimCount */, Indices, D3DFMT_INDEX16, transformed_2,
419                                                      sizeof(transformed_2[0]));
420
421         hr = IDirect3DDevice8_EndScene(device);
422         ok(hr == D3D_OK, "EndScene returned %s\n", DXGetErrorString8(hr));
423     }
424     else
425     {
426         ok(FALSE, "BeginScene failed\n");
427     }
428
429     IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
430     color = getPixelColor(device, 160, 360);
431     ok(color == 0x00FF0000, "Untransformed vertex with no table or vertex fog has color %08x\n", color);
432     color = getPixelColor(device, 160, 120);
433     ok(color == 0x0000FF00, "Untransformed vertex with linear vertex fog has color %08x\n", color);
434     color = getPixelColor(device, 480, 120);
435     ok(color == 0x00FFFF00, "Transformed vertex with linear vertex fog has color %08x\n", color);
436     color = getPixelColor(device, 480, 360);
437     ok(color == 0x0000FF00, "Transformed vertex with linear table fog has color %08x\n", color);
438
439     /* Turn off the fog master switch to avoid confusing other tests */
440     hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGENABLE, FALSE);
441     ok(hr == D3D_OK, "Turning off fog calculations returned %s\n", DXGetErrorString8(hr));
442 }
443
444 START_TEST(visual)
445 {
446     IDirect3DDevice8 *device_ptr;
447     HRESULT hr;
448     DWORD color;
449
450     d3d8_handle = LoadLibraryA("d3d8.dll");
451     if (!d3d8_handle)
452     {
453         skip("Could not load d3d8.dll\n");
454         return;
455     }
456
457     device_ptr = init_d3d8();
458     if (!device_ptr) return;
459
460     /* Check for the reliability of the returned data */
461     hr = IDirect3DDevice8_Clear(device_ptr, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
462     if(FAILED(hr))
463     {
464         trace("Clear failed, can't assure correctness of the test results, skipping\n");
465         goto cleanup;
466     }
467     IDirect3DDevice8_Present(device_ptr, NULL, NULL, NULL, NULL);
468
469     color = getPixelColor(device_ptr, 1, 1);
470     if(color !=0x00ff0000)
471     {
472         trace("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests, skipping\n", color);
473         goto cleanup;
474     }
475
476     hr = IDirect3DDevice8_Clear(device_ptr, 0, NULL, D3DCLEAR_TARGET, 0xff00ddee, 0.0, 0);
477     if(FAILED(hr))
478     {
479         trace("Clear failed, can't assure correctness of the test results, skipping\n");
480         goto cleanup;
481     }
482     IDirect3DDevice8_Present(device_ptr, NULL, NULL, NULL, NULL);
483
484     color = getPixelColor(device_ptr, 639, 479);
485     if(color != 0x0000ddee)
486     {
487         trace("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests, skipping\n", color);
488         goto cleanup;
489     }
490
491     /* Now run the real test */
492     lighting_test(device_ptr);
493     clear_test(device_ptr);
494     fog_test(device_ptr);
495
496 cleanup:
497     if(device_ptr) IDirect3DDevice8_Release(device_ptr);
498 }