msdaps: Implement the marshalling object.
[wine/hramrach.git] / dlls / d3d8 / tests / visual.c
blob0ea1bd289e19d9bdb8c50506b1a28aad155a0add
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_POPUP | WS_SYSMENU , 20, 20, 640, 480, 0, 0, 0, 0);
38 ShowWindow(ret, SW_SHOW);
39 return ret;
42 static BOOL color_match(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
44 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
45 c1 >>= 8; c2 >>= 8;
46 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
47 c1 >>= 8; c2 >>= 8;
48 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
49 c1 >>= 8; c2 >>= 8;
50 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
51 return TRUE;
54 static DWORD getPixelColor(IDirect3DDevice8 *device, UINT x, UINT y)
56 DWORD ret;
57 IDirect3DTexture8 *tex = NULL;
58 IDirect3DSurface8 *surf = NULL, *backbuf = NULL;
59 HRESULT hr;
60 D3DLOCKED_RECT lockedRect;
61 RECT rectToLock = {x, y, x+1, y+1};
63 hr = IDirect3DDevice8_CreateTexture(device, 640, 480, 1 /* Levels */, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &tex);
64 if(FAILED(hr) || !tex ) /* This is not a test */
66 trace("Can't create an offscreen plain surface to read the render target data, hr=%#08x\n", hr);
67 return 0xdeadbeef;
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);
73 ret = 0xdeadbeee;
74 goto out;
77 hr = IDirect3DDevice8_GetRenderTarget(device, &backbuf);
78 if(FAILED(hr))
80 trace("Can't get the render target, hr=%#08x\n", hr);
81 ret = 0xdeadbeed;
82 goto out;
84 hr = IDirect3DDevice8_CopyRects(device, backbuf, NULL, 0, surf, NULL);
85 if(FAILED(hr))
87 trace("Can't read the render target, hr=%#08x\n", hr);
88 ret = 0xdeadbeec;
89 goto out;
92 hr = IDirect3DSurface8_LockRect(surf, &lockedRect, &rectToLock, D3DLOCK_READONLY);
93 if(FAILED(hr))
95 trace("Can't lock the offscreen surface, hr=%#08x\n", hr);
96 ret = 0xdeadbeeb;
97 goto out;
99 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
100 * really important for these tests
102 ret = ((DWORD *) lockedRect.pBits)[0] & 0x00ffffff;
103 hr = IDirect3DSurface8_UnlockRect(surf);
104 if(FAILED(hr))
106 trace("Can't unlock the offscreen surface, hr=%#08x\n", hr);
109 out:
110 if(backbuf) IDirect3DSurface8_Release(backbuf);
111 if(surf) IDirect3DSurface8_Release(surf);
112 if(tex) IDirect3DTexture8_Release(tex);
113 return ret;
116 static IDirect3DDevice8 *init_d3d8(void)
118 IDirect3D8 * (__stdcall * d3d8_create)(UINT SDKVersion) = 0;
119 IDirect3D8 *d3d8_ptr = 0;
120 IDirect3DDevice8 *device_ptr = 0;
121 D3DPRESENT_PARAMETERS present_parameters;
122 HRESULT hr;
124 d3d8_create = (void *)GetProcAddress(d3d8_handle, "Direct3DCreate8");
125 ok(d3d8_create != NULL, "Failed to get address of Direct3DCreate8\n");
126 if (!d3d8_create) return NULL;
128 d3d8_ptr = d3d8_create(D3D_SDK_VERSION);
129 if (!d3d8_ptr)
131 skip("could not create D3D8\n");
132 return NULL;
135 ZeroMemory(&present_parameters, sizeof(present_parameters));
136 present_parameters.Windowed = TRUE;
137 present_parameters.hDeviceWindow = create_window();
138 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
139 present_parameters.BackBufferWidth = 640;
140 present_parameters.BackBufferHeight = 480;
141 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
142 present_parameters.EnableAutoDepthStencil = TRUE;
143 present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
145 hr = IDirect3D8_CreateDevice(d3d8_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
146 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL || broken(hr == D3DERR_NOTAVAILABLE), "IDirect3D_CreateDevice returned: %#08x\n", hr);
148 return device_ptr;
151 struct vertex
153 float x, y, z;
154 DWORD diffuse;
157 struct tvertex
159 float x, y, z, w;
160 DWORD diffuse;
163 struct nvertex
165 float x, y, z;
166 float nx, ny, nz;
167 DWORD diffuse;
170 static void lighting_test(IDirect3DDevice8 *device)
172 HRESULT hr;
173 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
174 DWORD nfvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_NORMAL;
175 DWORD color;
177 float mat[16] = { 1.0f, 0.0f, 0.0f, 0.0f,
178 0.0f, 1.0f, 0.0f, 0.0f,
179 0.0f, 0.0f, 1.0f, 0.0f,
180 0.0f, 0.0f, 0.0f, 1.0f };
182 struct vertex unlitquad[] =
184 {-1.0f, -1.0f, 0.1f, 0xffff0000},
185 {-1.0f, 0.0f, 0.1f, 0xffff0000},
186 { 0.0f, 0.0f, 0.1f, 0xffff0000},
187 { 0.0f, -1.0f, 0.1f, 0xffff0000},
189 struct vertex litquad[] =
191 {-1.0f, 0.0f, 0.1f, 0xff00ff00},
192 {-1.0f, 1.0f, 0.1f, 0xff00ff00},
193 { 0.0f, 1.0f, 0.1f, 0xff00ff00},
194 { 0.0f, 0.0f, 0.1f, 0xff00ff00},
196 struct nvertex unlitnquad[] =
198 { 0.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
199 { 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
200 { 1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
201 { 1.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
203 struct nvertex litnquad[] =
205 { 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
206 { 0.0f, 1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
207 { 1.0f, 1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
208 { 1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
210 WORD Indices[] = {0, 1, 2, 2, 3, 0};
212 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
213 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
215 /* Setup some states that may cause issues */
216 hr = IDirect3DDevice8_SetTransform(device, D3DTS_WORLDMATRIX(0), (D3DMATRIX *) mat);
217 ok(hr == D3D_OK, "IDirect3DDevice8_SetTransform returned %#08x\n", hr);
218 hr = IDirect3DDevice8_SetTransform(device, D3DTS_VIEW, (D3DMATRIX *)mat);
219 ok(hr == D3D_OK, "IDirect3DDevice8_SetTransform returned %#08x\n", hr);
220 hr = IDirect3DDevice8_SetTransform(device, D3DTS_PROJECTION, (D3DMATRIX *) mat);
221 ok(hr == D3D_OK, "IDirect3DDevice8_SetTransform returned %#08x\n", hr);
222 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_CLIPPING, FALSE);
223 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
224 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, FALSE);
225 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
226 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGENABLE, FALSE);
227 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
228 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_STENCILENABLE, FALSE);
229 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
230 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHATESTENABLE, FALSE);
231 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
232 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, FALSE);
233 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
234 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE);
235 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed with %#08x\n", hr);
236 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE);
237 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed with %#08x\n", hr);
239 hr = IDirect3DDevice8_SetVertexShader(device, fvf);
240 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
242 hr = IDirect3DDevice8_BeginScene(device);
243 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
244 if(hr == D3D_OK)
246 /* No lights are defined... That means, lit vertices should be entirely black */
247 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
248 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
249 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
250 2 /*PrimCount */, Indices, D3DFMT_INDEX16, unlitquad, sizeof(unlitquad[0]));
251 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr);
253 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, TRUE);
254 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
255 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
256 2 /*PrimCount */, Indices, D3DFMT_INDEX16, litquad, sizeof(litquad[0]));
257 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr);
259 hr = IDirect3DDevice8_SetVertexShader(device, nfvf);
260 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader failed with %#08x\n", hr);
262 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
263 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
264 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
265 2 /*PrimCount */, Indices, D3DFMT_INDEX16, unlitnquad, sizeof(unlitnquad[0]));
266 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr);
268 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, TRUE);
269 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
270 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
271 2 /*PrimCount */, Indices, D3DFMT_INDEX16, litnquad, sizeof(litnquad[0]));
272 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr);
274 IDirect3DDevice8_EndScene(device);
275 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
278 color = getPixelColor(device, 160, 360); /* lower left quad - unlit without normals */
279 ok(color == 0x00ff0000, "Unlit quad without normals has color %08x\n", color);
280 color = getPixelColor(device, 160, 120); /* upper left quad - lit without normals */
281 ok(color == 0x00000000, "Lit quad without normals has color %08x\n", color);
282 color = getPixelColor(device, 480, 360); /* lower left quad - unlit width normals */
283 ok(color == 0x000000ff, "Unlit quad width normals has color %08x\n", color);
284 color = getPixelColor(device, 480, 120); /* upper left quad - lit width normals */
285 ok(color == 0x00000000, "Lit quad width normals has color %08x\n", color);
287 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
289 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
290 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
293 static void clear_test(IDirect3DDevice8 *device)
295 /* Tests the correctness of clearing parameters */
296 HRESULT hr;
297 D3DRECT rect[2];
298 D3DRECT rect_negneg;
299 DWORD color;
301 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
302 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
304 /* Positive x, negative y */
305 rect[0].x1 = 0;
306 rect[0].y1 = 480;
307 rect[0].x2 = 320;
308 rect[0].y2 = 240;
310 /* Positive x, positive y */
311 rect[1].x1 = 0;
312 rect[1].y1 = 0;
313 rect[1].x2 = 320;
314 rect[1].y2 = 240;
315 /* Clear 2 rectangles with one call. Shows that a positive value is returned, but the negative rectangle
316 * is ignored, the positive is still cleared afterwards
318 hr = IDirect3DDevice8_Clear(device, 2, rect, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
319 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
321 /* negative x, negative y */
322 rect_negneg.x1 = 640;
323 rect_negneg.y1 = 240;
324 rect_negneg.x2 = 320;
325 rect_negneg.y2 = 0;
326 hr = IDirect3DDevice8_Clear(device, 1, &rect_negneg, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
327 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
329 color = getPixelColor(device, 160, 360); /* lower left quad */
330 ok(color == 0x00ffffff, "Clear rectangle 3(pos, neg) has color %08x\n", color);
331 color = getPixelColor(device, 160, 120); /* upper left quad */
332 ok(color == 0x00ff0000, "Clear rectangle 1(pos, pos) has color %08x\n", color);
333 color = getPixelColor(device, 480, 360); /* lower right quad */
334 ok(color == 0x00ffffff, "Clear rectangle 4(NULL) has color %08x\n", color);
335 color = getPixelColor(device, 480, 120); /* upper right quad */
336 ok(color == 0x00ffffff, "Clear rectangle 4(neg, neg) has color %08x\n", color);
338 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
341 struct sVertex {
342 float x, y, z;
343 DWORD diffuse;
344 DWORD specular;
347 struct sVertexT {
348 float x, y, z, rhw;
349 DWORD diffuse;
350 DWORD specular;
353 static void fog_test(IDirect3DDevice8 *device)
355 HRESULT hr;
356 DWORD color;
357 float start = 0.0, end = 1.0;
359 /* Gets full z based fog with linear fog, no fog with specular color */
360 struct sVertex unstransformed_1[] = {
361 {-1, -1, 0.1f, 0xFFFF0000, 0xFF000000 },
362 {-1, 0, 0.1f, 0xFFFF0000, 0xFF000000 },
363 { 0, 0, 0.1f, 0xFFFF0000, 0xFF000000 },
364 { 0, -1, 0.1f, 0xFFFF0000, 0xFF000000 },
366 /* Ok, I am too lazy to deal with transform matrices */
367 struct sVertex unstransformed_2[] = {
368 {-1, 0, 1.0f, 0xFFFF0000, 0xFF000000 },
369 {-1, 1, 1.0f, 0xFFFF0000, 0xFF000000 },
370 { 0, 1, 1.0f, 0xFFFF0000, 0xFF000000 },
371 { 0, 0, 1.0f, 0xFFFF0000, 0xFF000000 },
373 /* Untransformed ones. Give them a different diffuse color to make the test look
374 * nicer. It also makes making sure that they are drawn correctly easier.
376 struct sVertexT transformed_1[] = {
377 {320, 0, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
378 {640, 0, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
379 {640, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
380 {320, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
382 struct sVertexT transformed_2[] = {
383 {320, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
384 {640, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
385 {640, 480, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
386 {320, 480, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
388 WORD Indices[] = {0, 1, 2, 2, 3, 0};
390 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
391 ok(hr == D3D_OK, "IDirect3DDevice8_Clear returned %#08x\n", hr);
393 /* Setup initial states: No lighting, fog on, fog color */
394 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
395 ok(hr == D3D_OK, "Turning off lighting returned %#08x\n", hr);
396 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGENABLE, TRUE);
397 ok(hr == D3D_OK, "Turning on fog calculations returned %#08x\n", hr);
398 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGCOLOR, 0xFF00FF00 /* A nice green */);
399 ok(hr == D3D_OK, "Turning on fog calculations returned %#08x\n", hr);
401 /* First test: Both table fog and vertex fog off */
402 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_NONE);
403 ok(hr == D3D_OK, "Turning off table fog returned %#08x\n", hr);
404 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGVERTEXMODE, D3DFOG_NONE);
405 ok(hr == D3D_OK, "Turning off table fog returned %#08x\n", hr);
407 /* Start = 0, end = 1. Should be default, but set them */
408 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGSTART, *((DWORD *) &start));
409 ok(hr == D3D_OK, "Setting fog start returned %#08x\n", hr);
410 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGEND, *((DWORD *) &end));
411 ok(hr == D3D_OK, "Setting fog start returned %#08x\n", hr);
413 if(IDirect3DDevice8_BeginScene(device) == D3D_OK)
415 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
416 ok( hr == D3D_OK, "SetVertexShader returned %#08x\n", hr);
417 /* Untransformed, vertex fog = NONE, table fog = NONE: Read the fog weighting from the specular color */
418 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
419 2 /*PrimCount */, Indices, D3DFMT_INDEX16, unstransformed_1,
420 sizeof(unstransformed_1[0]));
421 ok(hr == D3D_OK, "DrawIndexedPrimitiveUP returned %#08x\n", hr);
423 /* That makes it use the Z value */
424 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR);
425 ok(hr == D3D_OK, "Turning off table fog returned %#08x\n", hr);
426 /* Untransformed, vertex fog != none (or table fog != none):
427 * Use the Z value as input into the equation
429 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
430 2 /*PrimCount */, Indices, D3DFMT_INDEX16, unstransformed_2,
431 sizeof(unstransformed_1[0]));
432 ok(hr == D3D_OK, "DrawIndexedPrimitiveUP returned %#08x\n", hr);
434 /* transformed verts */
435 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
436 ok( hr == D3D_OK, "SetVertexShader returned %#08x\n", hr);
437 /* Transformed, vertex fog != NONE, pixel fog == NONE: Use specular color alpha component */
438 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
439 2 /*PrimCount */, Indices, D3DFMT_INDEX16, transformed_1,
440 sizeof(transformed_1[0]));
441 ok(hr == D3D_OK, "DrawIndexedPrimitiveUP returned %#08x\n", hr);
443 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);
444 ok( hr == D3D_OK, "Setting fog table mode to D3DFOG_LINEAR returned %#08x\n", hr);
445 /* Transformed, table fog != none, vertex anything: Use Z value as input to the fog
446 * equation
448 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
449 2 /*PrimCount */, Indices, D3DFMT_INDEX16, transformed_2,
450 sizeof(transformed_2[0]));
451 ok(SUCCEEDED(hr), "IDirect3DDevice8_DrawIndexedPrimitiveUP returned %#x.\n", hr);
453 hr = IDirect3DDevice8_EndScene(device);
454 ok(hr == D3D_OK, "EndScene returned %#08x\n", hr);
456 else
458 ok(FALSE, "BeginScene failed\n");
461 color = getPixelColor(device, 160, 360);
462 ok(color == 0x00FF0000, "Untransformed vertex with no table or vertex fog has color %08x\n", color);
463 color = getPixelColor(device, 160, 120);
464 ok(color == 0x0000FF00, "Untransformed vertex with linear vertex fog has color %08x\n", color);
465 color = getPixelColor(device, 480, 120);
466 ok(color == 0x00FFFF00, "Transformed vertex with linear vertex fog has color %08x\n", color);
467 color = getPixelColor(device, 480, 360);
468 ok(color == 0x0000FF00, "Transformed vertex with linear table fog has color %08x\n", color);
470 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
472 /* Turn off the fog master switch to avoid confusing other tests */
473 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGENABLE, FALSE);
474 ok(hr == D3D_OK, "Turning off fog calculations returned %#08x\n", hr);
477 static void present_test(IDirect3DDevice8 *device)
479 struct vertex quad[] =
481 {-1.0f, -1.0f, 0.9f, 0xffff0000},
482 {-1.0f, 1.0f, 0.9f, 0xffff0000},
483 { 1.0f, -1.0f, 0.1f, 0xffff0000},
484 { 1.0f, 1.0f, 0.1f, 0xffff0000},
486 HRESULT hr;
487 DWORD color;
489 /* Does the Present clear the depth stencil? Clear the depth buffer with some value != 0,
490 * then call Present. Then clear the color buffer to make sure it has some defined content
491 * after the Present with D3DSWAPEFFECT_DISCARD. After that draw a plane that is somewhere cut
492 * by the depth value.
494 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 0.75, 0);
495 ok(hr == D3D_OK, "IDirect3DDevice8_Clear returned %08x\n", hr);
496 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
497 ok(SUCCEEDED(hr), "IDirect3DDevice8_Present returned %#x.\n", hr);
498 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.4, 0);
499 ok(SUCCEEDED(hr), "IDirect3DDevice8_Clear returned %#x.\n", hr);
501 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
502 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %08x\n", hr);
503 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_GREATER);
504 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %08x\n", hr);
505 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
506 ok(hr == D3D_OK, "IDirect3DDevice8_SetFVF returned %08x\n", hr);
508 hr = IDirect3DDevice8_BeginScene(device);
509 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %08x\n", hr);
510 if(hr == D3D_OK)
512 /* No lights are defined... That means, lit vertices should be entirely black */
513 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2 /*PrimCount */, quad, sizeof(quad[0]));
514 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %08x\n", hr);
516 hr = IDirect3DDevice8_EndScene(device);
517 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %08x\n", hr);
520 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
521 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %08x\n", hr);
523 color = getPixelColor(device, 512, 240);
524 ok(color == 0x00ffffff, "Present failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
525 color = getPixelColor(device, 64, 240);
526 ok(color == 0x00ff0000, "Present failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
528 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
529 ok(SUCCEEDED(hr), "Present failed (%#08x)\n", hr);
532 static void test_rcp_rsq(IDirect3DDevice8 *device)
534 HRESULT hr;
535 DWORD shader;
536 DWORD color;
537 unsigned char c1, c2, c3;
538 float constant[4] = {1.0, 1.0, 1.0, 2.0};
540 static const float quad[][3] = {
541 {-1.0f, -1.0f, 0.0f},
542 {-1.0f, 1.0f, 0.0f},
543 { 1.0f, -1.0f, 0.0f},
544 { 1.0f, 1.0f, 0.0f},
547 const DWORD rcp_test[] = {
548 0xfffe0101, /* vs.1.1 */
550 0x0009fffe, 0x30303030, 0x30303030, /* Shaders have to have a minimal size. */
551 0x30303030, 0x30303030, 0x30303030, /* Add a filler comment. Usually D3DX8's*/
552 0x30303030, 0x30303030, 0x30303030, /* version comment makes the shader big */
553 0x00303030, /* enough to make windows happy */
555 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
556 0x00000006, 0xd00f0000, 0xa0e40000, /* rcp oD0, c0 */
557 0x0000ffff /* END */
560 const DWORD rsq_test[] = {
561 0xfffe0101, /* vs.1.1 */
563 0x0009fffe, 0x30303030, 0x30303030, /* Shaders have to have a minimal size. */
564 0x30303030, 0x30303030, 0x30303030, /* Add a filler comment. Usually D3DX8's*/
565 0x30303030, 0x30303030, 0x30303030, /* version comment makes the shader big */
566 0x00303030, /* enough to make windows happy */
568 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
569 0x00000007, 0xd00f0000, 0xa0e40000, /* rsq oD0, c0 */
570 0x0000ffff /* END */
573 DWORD decl[] =
575 D3DVSD_STREAM(0),
576 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
577 D3DVSD_END()
580 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff800080, 0.0, 0);
581 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
583 hr = IDirect3DDevice8_CreateVertexShader(device, decl, rcp_test, &shader, 0);
584 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned with %#08x\n", hr);
586 IDirect3DDevice8_SetVertexShader(device, shader);
587 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
588 IDirect3DDevice8_SetVertexShaderConstant(device, 0, constant, 1);
590 hr = IDirect3DDevice8_BeginScene(device);
591 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene returned %#08x\n", hr);
592 if(SUCCEEDED(hr))
594 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], 3 * sizeof(float));
595 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%#08x)\n", hr);
596 hr = IDirect3DDevice8_EndScene(device);
597 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
600 color = getPixelColor(device, 320, 240);
601 c1 = (color & 0x00ff0000 )>> 16;
602 c2 = (color & 0x0000ff00 )>> 8;
603 c3 = (color & 0x000000ff )>> 0;
604 ok(c1 == c2 && c2 == c3, "Color components differ: c1 = %02x, c2 = %02x, c3 = %02x\n",
605 c1, c2, c3);
606 ok(c1 >= 0x7c && c1 <= 0x84, "Color component value is %02x\n", c1);
608 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
609 ok(SUCCEEDED(hr), "Present failed (%#08x)\n", hr);
611 IDirect3DDevice8_SetVertexShader(device, 0);
612 IDirect3DDevice8_DeleteVertexShader(device, shader);
614 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff800080, 0.0, 0);
615 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
617 hr = IDirect3DDevice8_CreateVertexShader(device, decl, rsq_test, &shader, 0);
618 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned with %#08x\n", hr);
620 IDirect3DDevice8_SetVertexShader(device, shader);
621 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
622 IDirect3DDevice8_SetVertexShaderConstant(device, 0, constant, 1);
624 hr = IDirect3DDevice8_BeginScene(device);
625 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene returned %#08x\n", hr);
626 if(SUCCEEDED(hr))
628 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], 3 * sizeof(float));
629 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%#08x)\n", hr);
630 hr = IDirect3DDevice8_EndScene(device);
631 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
634 color = getPixelColor(device, 320, 240);
635 c1 = (color & 0x00ff0000 )>> 16;
636 c2 = (color & 0x0000ff00 )>> 8;
637 c3 = (color & 0x000000ff )>> 0;
638 ok(c1 == c2 && c2 == c3, "Color components differ: c1 = %02x, c2 = %02x, c3 = %02x\n",
639 c1, c2, c3);
640 ok(c1 >= 0xb0 && c1 <= 0xb8, "Color component value is %02x\n", c1);
642 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
643 ok(SUCCEEDED(hr), "Present failed (%#08x)\n", hr);
645 IDirect3DDevice8_SetVertexShader(device, 0);
646 IDirect3DDevice8_DeleteVertexShader(device, shader);
649 static void offscreen_test(IDirect3DDevice8 *device)
651 HRESULT hr;
652 IDirect3DTexture8 *offscreenTexture = NULL;
653 IDirect3DSurface8 *backbuffer = NULL, *offscreen = NULL, *depthstencil = NULL;
654 DWORD color;
656 static const float quad[][5] = {
657 {-0.5f, -0.5f, 0.1f, 0.0f, 0.0f},
658 {-0.5f, 0.5f, 0.1f, 0.0f, 1.0f},
659 { 0.5f, -0.5f, 0.1f, 1.0f, 0.0f},
660 { 0.5f, 0.5f, 0.1f, 1.0f, 1.0f},
663 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &depthstencil);
664 ok(hr == D3D_OK, "IDirect3DDevice8_GetDepthStencilSurface failed, hr = %#08x\n", hr);
666 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
667 ok(hr == D3D_OK, "Clear failed, hr = %#08x\n", hr);
669 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &offscreenTexture);
670 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Creating the offscreen render target failed, hr = %#08x\n", hr);
671 if(!offscreenTexture) {
672 trace("Failed to create an X8R8G8B8 offscreen texture, trying R5G6B5\n");
673 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET, D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &offscreenTexture);
674 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Creating the offscreen render target failed, hr = %#08x\n", hr);
675 if(!offscreenTexture) {
676 skip("Cannot create an offscreen render target\n");
677 goto out;
681 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
682 ok(hr == D3D_OK, "Can't get back buffer, hr = %#08x\n", hr);
683 if(!backbuffer) {
684 goto out;
687 hr = IDirect3DTexture8_GetSurfaceLevel(offscreenTexture, 0, &offscreen);
688 ok(hr == D3D_OK, "Can't get offscreen surface, hr = %#08x\n", hr);
689 if(!offscreen) {
690 goto out;
693 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_TEX1);
694 ok(hr == D3D_OK, "SetVertexShader failed, hr = %#08x\n", hr);
696 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
697 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %#08x\n", hr);
698 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
699 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %#08x\n", hr);
700 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MINFILTER, D3DTEXF_NONE);
701 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MINFILTER failed (%#08x)\n", hr);
702 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MAGFILTER, D3DTEXF_NONE);
703 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MAGFILTER failed (%#08x)\n", hr);
704 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
705 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %08x\n", hr);
707 if(IDirect3DDevice8_BeginScene(device) == D3D_OK) {
708 hr = IDirect3DDevice8_SetRenderTarget(device, offscreen, depthstencil);
709 ok(hr == D3D_OK, "SetRenderTarget failed, hr = %#08x\n", hr);
710 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
711 ok(hr == D3D_OK, "Clear failed, hr = %#08x\n", hr);
713 /* Draw without textures - Should result in a white quad */
714 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
715 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
717 hr = IDirect3DDevice8_SetRenderTarget(device, backbuffer, depthstencil);
718 ok(hr == D3D_OK, "SetRenderTarget failed, hr = %#08x\n", hr);
719 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) offscreenTexture);
720 ok(hr == D3D_OK, "SetTexture failed, %08x\n", hr);
722 /* This time with the texture */
723 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
724 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
726 IDirect3DDevice8_EndScene(device);
729 /* Center quad - should be white */
730 color = getPixelColor(device, 320, 240);
731 ok(color == 0x00ffffff, "Offscreen failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
732 /* Some quad in the cleared part of the texture */
733 color = getPixelColor(device, 170, 240);
734 ok(color == 0x00ff00ff, "Offscreen failed: Got color 0x%08x, expected 0x00ff00ff.\n", color);
735 /* Part of the originally cleared back buffer */
736 color = getPixelColor(device, 10, 10);
737 ok(color == 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
738 if(0) {
739 /* Lower left corner of the screen, where back buffer offscreen rendering draws the offscreen texture.
740 * It should be red, but the offscreen texture may leave some junk there. Not tested yet. Depending on
741 * the offscreen rendering mode this test would succeed or fail
743 color = getPixelColor(device, 10, 470);
744 ok(color == 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
747 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
749 out:
750 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
751 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetTexture returned %#x.\n", hr);
753 /* restore things */
754 if(backbuffer) {
755 hr = IDirect3DDevice8_SetRenderTarget(device, backbuffer, depthstencil);
756 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetRenderTarget returned %#x.\n", hr);
757 IDirect3DSurface8_Release(backbuffer);
759 if(offscreenTexture) {
760 IDirect3DTexture8_Release(offscreenTexture);
762 if(offscreen) {
763 IDirect3DSurface8_Release(offscreen);
765 if(depthstencil) {
766 IDirect3DSurface8_Release(depthstencil);
770 static void alpha_test(IDirect3DDevice8 *device)
772 HRESULT hr;
773 IDirect3DTexture8 *offscreenTexture;
774 IDirect3DSurface8 *backbuffer = NULL, *offscreen = NULL, *depthstencil = NULL;
775 DWORD color;
777 struct vertex quad1[] =
779 {-1.0f, -1.0f, 0.1f, 0x4000ff00},
780 {-1.0f, 0.0f, 0.1f, 0x4000ff00},
781 { 1.0f, -1.0f, 0.1f, 0x4000ff00},
782 { 1.0f, 0.0f, 0.1f, 0x4000ff00},
784 struct vertex quad2[] =
786 {-1.0f, 0.0f, 0.1f, 0xc00000ff},
787 {-1.0f, 1.0f, 0.1f, 0xc00000ff},
788 { 1.0f, 0.0f, 0.1f, 0xc00000ff},
789 { 1.0f, 1.0f, 0.1f, 0xc00000ff},
791 static const float composite_quad[][5] = {
792 { 0.0f, -1.0f, 0.1f, 0.0f, 1.0f},
793 { 0.0f, 1.0f, 0.1f, 0.0f, 0.0f},
794 { 1.0f, -1.0f, 0.1f, 1.0f, 1.0f},
795 { 1.0f, 1.0f, 0.1f, 1.0f, 0.0f},
798 /* Clear the render target with alpha = 0.5 */
799 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x80ff0000, 0.0, 0);
800 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
802 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &offscreenTexture);
803 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Creating the offscreen render target failed, hr = %#08x\n", hr);
805 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &depthstencil);
806 ok(hr == D3D_OK, "IDirect3DDevice8_GetDepthStencilSurface failed, hr = %#08x\n", hr);
808 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
809 ok(hr == D3D_OK, "Can't get back buffer, hr = %#08x\n", hr);
810 if(!backbuffer) {
811 goto out;
813 hr = IDirect3DTexture8_GetSurfaceLevel(offscreenTexture, 0, &offscreen);
814 ok(hr == D3D_OK, "Can't get offscreen surface, hr = %#08x\n", hr);
815 if(!offscreen) {
816 goto out;
819 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
820 ok(hr == D3D_OK, "SetVertexShader failed, hr = %#08x\n", hr);
822 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
823 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %#08x\n", hr);
824 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
825 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %#08x\n", hr);
826 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MINFILTER, D3DTEXF_NONE);
827 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MINFILTER failed (%#08x)\n", hr);
828 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MAGFILTER, D3DTEXF_NONE);
829 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MAGFILTER failed (%#08x)\n", hr);
830 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
831 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %08x\n", hr);
833 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, TRUE);
834 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
835 if(IDirect3DDevice8_BeginScene(device) == D3D_OK) {
837 /* Draw two quads, one with src alpha blending, one with dest alpha blending. */
838 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
839 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
840 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
841 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
842 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(quad1[0]));
843 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
845 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_DESTALPHA);
846 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
847 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVDESTALPHA);
848 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
849 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(quad2[0]));
850 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
852 /* Switch to the offscreen buffer, and redo the testing. The offscreen render target
853 * doesn't have an alpha channel. DESTALPHA and INVDESTALPHA "don't work" on render
854 * targets without alpha channel, they give essentially ZERO and ONE blend factors. */
855 hr = IDirect3DDevice8_SetRenderTarget(device, offscreen, 0);
856 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
857 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x80ff0000, 0.0, 0);
858 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
860 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
861 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
862 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
863 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
864 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(quad1[0]));
865 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
867 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_DESTALPHA);
868 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
869 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVDESTALPHA);
870 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
871 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(quad2[0]));
872 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
874 hr = IDirect3DDevice8_SetRenderTarget(device, backbuffer, depthstencil);
875 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
877 /* Render the offscreen texture onto the frame buffer to be able to compare it regularly.
878 * Disable alpha blending for the final composition
880 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, FALSE);
881 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
882 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_TEX1);
883 ok(hr == D3D_OK, "SetVertexShader failed, hr = %#08x\n", hr);
885 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) offscreenTexture);
886 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
887 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, composite_quad, sizeof(float) * 5);
888 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
889 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
890 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
892 hr = IDirect3DDevice8_EndScene(device);
893 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed, hr = %08x\n", hr);
896 color = getPixelColor(device, 160, 360);
897 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xbf, 0x40, 0x00), 1),
898 "SRCALPHA on frame buffer returned color %08x, expected 0x00bf4000\n", color);
900 color = getPixelColor(device, 160, 120);
901 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x7f, 0x00, 0x80), 2),
902 "DSTALPHA on frame buffer returned color %08x, expected 0x007f0080\n", color);
904 color = getPixelColor(device, 480, 360);
905 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xbf, 0x40, 0x00), 1),
906 "SRCALPHA on texture returned color %08x, expected 0x00bf4000\n", color);
908 color = getPixelColor(device, 480, 120);
909 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0xff), 1),
910 "DSTALPHA on texture returned color %08x, expected 0x000000ff\n", color);
912 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
914 out:
915 /* restore things */
916 if(backbuffer) {
917 IDirect3DSurface8_Release(backbuffer);
919 if(offscreenTexture) {
920 IDirect3DTexture8_Release(offscreenTexture);
922 if(offscreen) {
923 IDirect3DSurface8_Release(offscreen);
925 if(depthstencil) {
926 IDirect3DSurface8_Release(depthstencil);
930 static void p8_texture_test(IDirect3DDevice8 *device)
932 IDirect3D8 *d3d = NULL;
933 HRESULT hr;
934 IDirect3DTexture8 *texture = NULL, *texture2 = NULL;
935 D3DLOCKED_RECT lr;
936 unsigned char *data;
937 DWORD color, red, green, blue;
938 PALETTEENTRY table[256];
939 D3DCAPS8 caps;
940 UINT i;
941 float quad[] = {
942 -1.0, 0, 0.1, 0.0, 0.0,
943 -1.0, 1.0, 0.1, 0.0, 1.0,
944 1.0, 0, 0.1, 1.0, 0.0,
945 1.0, 1.0, 0.1, 1.0, 1.0,
947 float quad2[] = {
948 -1.0, -1.0, 0.1, 0.0, 0.0,
949 -1.0, 0, 0.1, 0.0, 1.0,
950 1.0, -1.0, 0.1, 1.0, 0.0,
951 1.0, 0, 0.1, 1.0, 1.0,
954 IDirect3DDevice8_GetDirect3D(device, &d3d);
956 if(IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, 0,
957 D3DRTYPE_TEXTURE, D3DFMT_P8) != D3D_OK) {
958 skip("D3DFMT_P8 textures not supported\n");
959 goto out;
962 hr = IDirect3DDevice8_CreateTexture(device, 1, 1, 1, 0, D3DFMT_P8,
963 D3DPOOL_MANAGED, &texture2);
964 ok(hr == D3D_OK, "IDirect3DDevice8_CreateTexture failed, hr = %08x\n", hr);
965 if(!texture2) {
966 skip("Failed to create D3DFMT_P8 texture\n");
967 goto out;
970 memset(&lr, 0, sizeof(lr));
971 hr = IDirect3DTexture8_LockRect(texture2, 0, &lr, NULL, 0);
972 ok(hr == D3D_OK, "IDirect3DTexture8_LockRect failed, hr = %08x\n", hr);
973 data = lr.pBits;
974 *data = 1;
976 hr = IDirect3DTexture8_UnlockRect(texture2, 0);
977 ok(hr == D3D_OK, "IDirect3DTexture8_UnlockRect failed, hr = %08x\n", hr);
979 hr = IDirect3DDevice8_CreateTexture(device, 1, 1, 1, 0, D3DFMT_P8,
980 D3DPOOL_MANAGED, &texture);
981 ok(hr == D3D_OK, "IDirect3DDevice8_CreateTexture failed, hr = %08x\n", hr);
982 if(!texture) {
983 skip("Failed to create D3DFMT_P8 texture\n");
984 goto out;
987 memset(&lr, 0, sizeof(lr));
988 hr = IDirect3DTexture8_LockRect(texture, 0, &lr, NULL, 0);
989 ok(hr == D3D_OK, "IDirect3DTexture8_LockRect failed, hr = %08x\n", hr);
990 data = lr.pBits;
991 *data = 1;
993 hr = IDirect3DTexture8_UnlockRect(texture, 0);
994 ok(hr == D3D_OK, "IDirect3DTexture8_UnlockRect failed, hr = %08x\n", hr);
996 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff000000, 0.0, 0);
997 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed, hr = %08x\n", hr);
999 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, TRUE);
1000 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1002 /* The first part of the test should work both with and without D3DPTEXTURECAPS_ALPHAPALETTE;
1003 alpha of every entry is set to 1.0, which MS says is required when there's no
1004 D3DPTEXTURECAPS_ALPHAPALETTE capability */
1005 for (i = 0; i < 256; i++) {
1006 table[i].peRed = table[i].peGreen = table[i].peBlue = 0;
1007 table[i].peFlags = 0xff;
1009 table[1].peRed = 0xff;
1010 hr = IDirect3DDevice8_SetPaletteEntries(device, 0, table);
1011 ok(hr == D3D_OK, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr);
1013 table[1].peRed = 0;
1014 table[1].peBlue = 0xff;
1015 hr = IDirect3DDevice8_SetPaletteEntries(device, 1, table);
1016 ok(hr == D3D_OK, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr);
1018 hr = IDirect3DDevice8_BeginScene(device);
1019 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed, hr = %08x\n", hr);
1020 if(SUCCEEDED(hr)) {
1021 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
1022 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1023 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
1024 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1026 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_TEX1);
1027 ok(hr == D3D_OK, "SetVertexShader failed, hr = %#08x\n", hr);
1029 hr = IDirect3DDevice8_SetCurrentTexturePalette(device, 0);
1030 ok(hr == D3D_OK, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr);
1032 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) texture2);
1033 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
1034 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
1035 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1037 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) texture);
1038 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
1039 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
1040 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1042 hr = IDirect3DDevice8_SetCurrentTexturePalette(device, 1);
1043 ok(hr == D3D_OK, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr);
1044 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 5 * sizeof(float));
1045 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1047 hr = IDirect3DDevice8_EndScene(device);
1048 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed, hr = %08x\n", hr);
1051 color = getPixelColor(device, 32, 32);
1052 red = (color & 0x00ff0000) >> 16;
1053 green = (color & 0x0000ff00) >> 8;
1054 blue = (color & 0x000000ff) >> 0;
1055 ok(red == 0xff && blue == 0 && green == 0,
1056 "got color %08x, expected 0x00ff0000\n", color);
1058 color = getPixelColor(device, 32, 320);
1059 red = (color & 0x00ff0000) >> 16;
1060 green = (color & 0x0000ff00) >> 8;
1061 blue = (color & 0x000000ff) >> 0;
1062 ok(red == 0 && blue == 0xff && green == 0,
1063 "got color %08x, expected 0x000000ff\n", color);
1065 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1066 ok(hr == D3D_OK, "IDirect3DDevice8_Present failed, hr = %08x\n", hr);
1068 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff000000, 0.0, 0);
1069 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed, hr = %08x\n", hr);
1071 hr = IDirect3DDevice8_BeginScene(device);
1072 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed, hr = %08x\n", hr);
1073 if(SUCCEEDED(hr)) {
1074 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) texture2);
1075 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
1077 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
1078 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1080 hr = IDirect3DDevice8_EndScene(device);
1081 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed, hr = %08x\n", hr);
1085 color = getPixelColor(device, 32, 32);
1086 red = (color & 0x00ff0000) >> 16;
1087 green = (color & 0x0000ff00) >> 8;
1088 blue = (color & 0x000000ff) >> 0;
1089 ok(red == 0 && blue == 0xff && green == 0,
1090 "got color %08x, expected 0x000000ff\n", color);
1092 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1093 ok(hr == D3D_OK, "IDirect3DDevice8_Present failed, hr = %08x\n", hr);
1095 /* Test palettes with alpha */
1096 IDirect3DDevice8_GetDeviceCaps(device, &caps);
1097 if (!(caps.TextureCaps & D3DPTEXTURECAPS_ALPHAPALETTE)) {
1098 skip("no D3DPTEXTURECAPS_ALPHAPALETTE capability, tests with alpha in palette will be skipped\n");
1099 } else {
1100 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff000000, 0.0, 0);
1101 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed, hr = %08x\n", hr);
1103 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, TRUE);
1104 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1106 for (i = 0; i < 256; i++) {
1107 table[i].peRed = table[i].peGreen = table[i].peBlue = 0;
1108 table[i].peFlags = 0xff;
1110 table[1].peRed = 0xff;
1111 table[1].peFlags = 0x80;
1112 hr = IDirect3DDevice8_SetPaletteEntries(device, 0, table);
1113 ok(hr == D3D_OK, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr);
1115 table[1].peRed = 0;
1116 table[1].peBlue = 0xff;
1117 table[1].peFlags = 0x80;
1118 hr = IDirect3DDevice8_SetPaletteEntries(device, 1, table);
1119 ok(hr == D3D_OK, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr);
1121 hr = IDirect3DDevice8_BeginScene(device);
1122 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed, hr = %08x\n", hr);
1123 if(SUCCEEDED(hr)) {
1124 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
1125 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1126 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
1127 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1129 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_TEX1);
1130 ok(hr == D3D_OK, "SetVertexShader failed, hr = %#08x\n", hr);
1132 hr = IDirect3DDevice8_SetCurrentTexturePalette(device, 0);
1133 ok(hr == D3D_OK, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr);
1135 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
1136 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1138 hr = IDirect3DDevice8_SetCurrentTexturePalette(device, 1);
1139 ok(hr == D3D_OK, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr);
1141 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 5 * sizeof(float));
1142 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1144 hr = IDirect3DDevice8_EndScene(device);
1145 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed, hr = %08x\n", hr);
1148 color = getPixelColor(device, 32, 32);
1149 red = (color & 0x00ff0000) >> 16;
1150 green = (color & 0x0000ff00) >> 8;
1151 blue = (color & 0x000000ff) >> 0;
1152 ok(red >= 0x7e && red <= 0x81 && blue == 0 && green == 0,
1153 "got color %08x, expected 0x00800000 or near\n", color);
1155 color = getPixelColor(device, 32, 320);
1156 red = (color & 0x00ff0000) >> 16;
1157 green = (color & 0x0000ff00) >> 8;
1158 blue = (color & 0x000000ff) >> 0;
1159 ok(red == 0 && blue >= 0x7e && blue <= 0x81 && green == 0,
1160 "got color %08x, expected 0x00000080 or near\n", color);
1162 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1163 ok(hr == D3D_OK, "IDirect3DDevice8_Present failed, hr = %08x\n", hr);
1166 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
1167 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
1168 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, FALSE);
1169 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1171 out:
1172 if(texture) IDirect3DTexture8_Release(texture);
1173 if(texture2) IDirect3DTexture8_Release(texture2);
1174 IDirect3D8_Release(d3d);
1177 static void texop_test(IDirect3DDevice8 *device)
1179 IDirect3DTexture8 *texture = NULL;
1180 D3DLOCKED_RECT locked_rect;
1181 D3DCOLOR color;
1182 D3DCAPS8 caps;
1183 HRESULT hr;
1184 unsigned int i;
1186 static const struct {
1187 float x, y, z;
1188 D3DCOLOR diffuse;
1189 float s, t;
1190 } quad[] = {
1191 {-1.0f, -1.0f, 0.1f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), -1.0f, -1.0f},
1192 {-1.0f, 1.0f, 0.1f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), -1.0f, 1.0f},
1193 { 1.0f, -1.0f, 0.1f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), 1.0f, -1.0f},
1194 { 1.0f, 1.0f, 0.1f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), 1.0f, 1.0f}
1197 static const struct {
1198 D3DTEXTUREOP op;
1199 const char *name;
1200 DWORD caps_flag;
1201 D3DCOLOR result;
1202 } test_data[] = {
1203 {D3DTOP_SELECTARG1, "SELECTARG1", D3DTEXOPCAPS_SELECTARG1, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00)},
1204 {D3DTOP_SELECTARG2, "SELECTARG2", D3DTEXOPCAPS_SELECTARG2, D3DCOLOR_ARGB(0x00, 0x33, 0x33, 0x33)},
1205 {D3DTOP_MODULATE, "MODULATE", D3DTEXOPCAPS_MODULATE, D3DCOLOR_ARGB(0x00, 0x00, 0x33, 0x00)},
1206 {D3DTOP_MODULATE2X, "MODULATE2X", D3DTEXOPCAPS_MODULATE2X, D3DCOLOR_ARGB(0x00, 0x00, 0x66, 0x00)},
1207 {D3DTOP_MODULATE4X, "MODULATE4X", D3DTEXOPCAPS_MODULATE4X, D3DCOLOR_ARGB(0x00, 0x00, 0xcc, 0x00)},
1208 {D3DTOP_ADD, "ADD", D3DTEXOPCAPS_ADD, D3DCOLOR_ARGB(0x00, 0x33, 0xff, 0x33)},
1210 {D3DTOP_ADDSIGNED, "ADDSIGNED", D3DTEXOPCAPS_ADDSIGNED, D3DCOLOR_ARGB(0x00, 0x00, 0xb2, 0x00)},
1211 {D3DTOP_ADDSIGNED2X, "ADDSIGNED2X", D3DTEXOPCAPS_ADDSIGNED2X, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00)},
1213 {D3DTOP_SUBTRACT, "SUBTRACT", D3DTEXOPCAPS_SUBTRACT, D3DCOLOR_ARGB(0x00, 0x00, 0xcc, 0x00)},
1214 {D3DTOP_ADDSMOOTH, "ADDSMOOTH", D3DTEXOPCAPS_ADDSMOOTH, D3DCOLOR_ARGB(0x00, 0x33, 0xff, 0x33)},
1215 {D3DTOP_BLENDDIFFUSEALPHA, "BLENDDIFFUSEALPHA", D3DTEXOPCAPS_BLENDDIFFUSEALPHA, D3DCOLOR_ARGB(0x00, 0x22, 0x77, 0x22)},
1216 {D3DTOP_BLENDTEXTUREALPHA, "BLENDTEXTUREALPHA", D3DTEXOPCAPS_BLENDTEXTUREALPHA, D3DCOLOR_ARGB(0x00, 0x14, 0xad, 0x14)},
1217 {D3DTOP_BLENDFACTORALPHA, "BLENDFACTORALPHA", D3DTEXOPCAPS_BLENDFACTORALPHA, D3DCOLOR_ARGB(0x00, 0x07, 0xe4, 0x07)},
1218 {D3DTOP_BLENDTEXTUREALPHAPM, "BLENDTEXTUREALPHAPM", D3DTEXOPCAPS_BLENDTEXTUREALPHAPM, D3DCOLOR_ARGB(0x00, 0x14, 0xff, 0x14)},
1219 {D3DTOP_BLENDCURRENTALPHA, "BLENDCURRENTALPHA", D3DTEXOPCAPS_BLENDCURRENTALPHA, D3DCOLOR_ARGB(0x00, 0x22, 0x77, 0x22)},
1220 {D3DTOP_MODULATEALPHA_ADDCOLOR, "MODULATEALPHA_ADDCOLOR", D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR, D3DCOLOR_ARGB(0x00, 0x1f, 0xff, 0x1f)},
1221 {D3DTOP_MODULATECOLOR_ADDALPHA, "MODULATECOLOR_ADDALPHA", D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA, D3DCOLOR_ARGB(0x00, 0x99, 0xcc, 0x99)},
1222 {D3DTOP_MODULATEINVALPHA_ADDCOLOR, "MODULATEINVALPHA_ADDCOLOR", D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR, D3DCOLOR_ARGB(0x00, 0x14, 0xff, 0x14)},
1223 {D3DTOP_MODULATEINVCOLOR_ADDALPHA, "MODULATEINVCOLOR_ADDALPHA", D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA, D3DCOLOR_ARGB(0x00, 0xcc, 0x99, 0xcc)},
1224 /* BUMPENVMAP & BUMPENVMAPLUMINANCE have their own tests */
1225 {D3DTOP_DOTPRODUCT3, "DOTPRODUCT2", D3DTEXOPCAPS_DOTPRODUCT3, D3DCOLOR_ARGB(0x00, 0x99, 0x99, 0x99)},
1226 {D3DTOP_MULTIPLYADD, "MULTIPLYADD", D3DTEXOPCAPS_MULTIPLYADD, D3DCOLOR_ARGB(0x00, 0xff, 0x33, 0x00)},
1227 {D3DTOP_LERP, "LERP", D3DTEXOPCAPS_LERP, D3DCOLOR_ARGB(0x00, 0x00, 0x33, 0x33)},
1230 memset(&caps, 0, sizeof(caps));
1231 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
1232 ok(SUCCEEDED(hr), "GetDeviceCaps failed with 0x%08x\n", hr);
1234 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX0);
1235 ok(SUCCEEDED(hr), "SetVertexShader failed with 0x%08x\n", hr);
1237 hr = IDirect3DDevice8_CreateTexture(device, 1, 1, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture);
1238 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateTexture failed with 0x%08x\n", hr);
1239 hr = IDirect3DTexture8_LockRect(texture, 0, &locked_rect, NULL, 0);
1240 ok(SUCCEEDED(hr), "LockRect failed with 0x%08x\n", hr);
1241 *((DWORD *)locked_rect.pBits) = D3DCOLOR_ARGB(0x99, 0x00, 0xff, 0x00);
1242 hr = IDirect3DTexture8_UnlockRect(texture, 0);
1243 ok(SUCCEEDED(hr), "LockRect failed with 0x%08x\n", hr);
1244 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *)texture);
1245 ok(SUCCEEDED(hr), "SetTexture failed with 0x%08x\n", hr);
1247 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLORARG0, D3DTA_DIFFUSE);
1248 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
1249 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
1250 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
1251 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
1252 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
1254 hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
1255 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
1257 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
1258 ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
1259 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0xdd333333);
1260 ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
1261 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA);
1262 ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
1264 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
1265 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
1267 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
1269 if (!(caps.TextureOpCaps & test_data[i].caps_flag))
1271 skip("tex operation %s not supported\n", test_data[i].name);
1272 continue;
1275 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLOROP, test_data[i].op);
1276 ok(SUCCEEDED(hr), "SetTextureStageState (%s) failed with 0x%08x\n", test_data[i].name, hr);
1278 hr = IDirect3DDevice8_BeginScene(device);
1279 ok(SUCCEEDED(hr), "BeginScene failed with 0x%08x\n", hr);
1281 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
1282 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed with 0x%08x\n", hr);
1284 hr = IDirect3DDevice8_EndScene(device);
1285 ok(SUCCEEDED(hr), "EndScene failed with 0x%08x\n", hr);
1287 color = getPixelColor(device, 320, 240);
1288 ok(color_match(color, test_data[i].result, 3), "Operation %s returned color 0x%08x, expected 0x%08x\n",
1289 test_data[i].name, color, test_data[i].result);
1291 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1292 ok(SUCCEEDED(hr), "Present failed with 0x%08x\n", hr);
1294 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
1295 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
1298 if (texture) IDirect3DTexture8_Release(texture);
1301 /* This test tests depth clamping / clipping behaviour:
1302 * - When D3DRS_CLIPPING is disabled depth values are *clamped* to the
1303 * minimum/maximum z value.
1304 * - The viewport's MinZ/MaxZ is irrelevant for this.
1305 * - When D3DRS_CLIPPING is enabled depth values are clipped.
1306 * - Pretransformed vertices behave the same as regular vertices.
1308 static void depth_clamp_test(IDirect3DDevice8 *device)
1310 const struct tvertex quad1[] =
1312 { 0, 0, 5.0f, 1.0, 0xff002b7f},
1313 { 640, 0, 5.0f, 1.0, 0xff002b7f},
1314 { 0, 480, 5.0f, 1.0, 0xff002b7f},
1315 { 640, 480, 5.0f, 1.0, 0xff002b7f},
1317 const struct tvertex quad2[] =
1319 { 0, 300, 10.0f, 1.0, 0xfff9e814},
1320 { 640, 300, 10.0f, 1.0, 0xfff9e814},
1321 { 0, 360, 10.0f, 1.0, 0xfff9e814},
1322 { 640, 360, 10.0f, 1.0, 0xfff9e814},
1324 const struct vertex quad3[] =
1326 {-0.65, 0.55, 5.0f, 0xffffffff},
1327 {-0.35, 0.55, 5.0f, 0xffffffff},
1328 {-0.65, 0.15, 5.0f, 0xffffffff},
1329 {-0.35, 0.15, 5.0f, 0xffffffff},
1331 const struct vertex quad4[] =
1333 {-0.87, 0.83, 10.0f, 0xffffffff},
1334 {-0.65, 0.83, 10.0f, 0xffffffff},
1335 {-0.87, 0.55, 10.0f, 0xffffffff},
1336 {-0.65, 0.55, 10.0f, 0xffffffff},
1338 const struct vertex quad5[] =
1340 { -0.5, 0.5, 10.0f, 0xff14f914},
1341 { 0.5, 0.5, 10.0f, 0xff14f914},
1342 { -0.5, -0.5, 10.0f, 0xff14f914},
1343 { 0.5, -0.5, 10.0f, 0xff14f914},
1345 const struct tvertex quad6[] =
1347 { 0, 120, 10.0f, 1.0, 0xfff91414},
1348 { 640, 120, 10.0f, 1.0, 0xfff91414},
1349 { 0, 180, 10.0f, 1.0, 0xfff91414},
1350 { 640, 180, 10.0f, 1.0, 0xfff91414},
1353 D3DVIEWPORT8 vp;
1354 D3DCOLOR color;
1355 HRESULT hr;
1357 vp.X = 0;
1358 vp.Y = 0;
1359 vp.Width = 640;
1360 vp.Height = 480;
1361 vp.MinZ = 0.0;
1362 vp.MaxZ = 7.5;
1364 hr = IDirect3DDevice8_SetViewport(device, &vp);
1365 ok(SUCCEEDED(hr), "SetViewport failed, hr %#x.\n", hr);
1367 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0, 0);
1368 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
1370 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_CLIPPING, FALSE);
1371 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1372 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
1373 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1374 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
1375 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1376 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
1377 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1379 hr = IDirect3DDevice8_BeginScene(device);
1380 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
1382 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
1383 ok(SUCCEEDED(hr), "SetVertexSahder failed, hr %#x.\n", hr);
1385 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(*quad1));
1386 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
1387 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(*quad2));
1388 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
1390 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
1391 ok(SUCCEEDED(hr), "SetVertexShader failed, hr %#x.\n", hr);
1393 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, sizeof(*quad3));
1394 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
1395 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, sizeof(*quad4));
1396 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
1398 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_CLIPPING, TRUE);
1399 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1401 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad5, sizeof(*quad5));
1402 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
1404 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
1405 ok(SUCCEEDED(hr), "SetVertexShader failed, hr %#x.\n", hr);
1407 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad6, sizeof(*quad6));
1408 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
1410 hr = IDirect3DDevice8_EndScene(device);
1411 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
1413 color = getPixelColor(device, 75, 75);
1414 ok(color_match(color, 0x00ffffff, 1), "color 0x%08x.\n", color);
1415 color = getPixelColor(device, 150, 150);
1416 ok(color_match(color, 0x00ffffff, 1), "color 0x%08x.\n", color);
1417 color = getPixelColor(device, 320, 240);
1418 ok(color_match(color, 0x00002b7f, 1), "color 0x%08x.\n", color);
1419 color = getPixelColor(device, 320, 330);
1420 ok(color_match(color, 0x00f9e814, 1), "color 0x%08x.\n", color);
1421 color = getPixelColor(device, 320, 330);
1422 ok(color_match(color, 0x00f9e814, 1), "color 0x%08x.\n", color);
1424 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1425 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
1427 vp.MinZ = 0.0;
1428 vp.MaxZ = 1.0;
1429 hr = IDirect3DDevice8_SetViewport(device, &vp);
1430 ok(SUCCEEDED(hr), "SetViewport failed, hr %#x.\n", hr);
1433 START_TEST(visual)
1435 IDirect3DDevice8 *device_ptr;
1436 HRESULT hr;
1437 DWORD color;
1438 D3DCAPS8 caps;
1440 d3d8_handle = LoadLibraryA("d3d8.dll");
1441 if (!d3d8_handle)
1443 win_skip("Could not load d3d8.dll\n");
1444 return;
1447 device_ptr = init_d3d8();
1448 if (!device_ptr)
1450 win_skip("Could not initialize direct3d\n");
1451 return;
1454 IDirect3DDevice8_GetDeviceCaps(device_ptr, &caps);
1456 /* Check for the reliability of the returned data */
1457 hr = IDirect3DDevice8_Clear(device_ptr, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
1458 if(FAILED(hr))
1460 skip("Clear failed, can't assure correctness of the test results\n");
1461 goto cleanup;
1464 color = getPixelColor(device_ptr, 1, 1);
1465 if(color !=0x00ff0000)
1467 skip("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests\n", color);
1468 goto cleanup;
1470 IDirect3DDevice8_Present(device_ptr, NULL, NULL, NULL, NULL);
1472 hr = IDirect3DDevice8_Clear(device_ptr, 0, NULL, D3DCLEAR_TARGET, 0xff00ddee, 0.0, 0);
1473 if(FAILED(hr))
1475 skip("Clear failed, can't assure correctness of the test results\n");
1476 goto cleanup;
1479 color = getPixelColor(device_ptr, 639, 479);
1480 if(color != 0x0000ddee)
1482 skip("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests\n", color);
1483 goto cleanup;
1485 IDirect3DDevice8_Present(device_ptr, NULL, NULL, NULL, NULL);
1487 /* Now run the real test */
1488 depth_clamp_test(device_ptr);
1489 lighting_test(device_ptr);
1490 clear_test(device_ptr);
1491 fog_test(device_ptr);
1492 present_test(device_ptr);
1493 offscreen_test(device_ptr);
1494 alpha_test(device_ptr);
1496 if (caps.VertexShaderVersion >= D3DVS_VERSION(1, 1))
1498 test_rcp_rsq(device_ptr);
1500 else
1502 skip("No vs.1.1 support\n");
1505 p8_texture_test(device_ptr);
1506 texop_test(device_ptr);
1508 cleanup:
1509 if(device_ptr) {
1510 D3DDEVICE_CREATION_PARAMETERS creation_parameters;
1511 ULONG refcount;
1513 IDirect3DDevice8_GetCreationParameters(device_ptr, &creation_parameters);
1514 DestroyWindow(creation_parameters.hFocusWindow);
1515 refcount = IDirect3DDevice8_Release(device_ptr);
1516 ok(!refcount, "Device has %u references left\n", refcount);