2 * Copyright (C) 2005 Henri Verbeet
3 * Copyright (C) 2007 Stefan Dösinger(for CodeWeavers)
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 /* See comment in dlls/d3d9/tests/visual.c for general guidelines */
24 #include "wine/test.h"
26 static HMODULE d3d8_handle = 0;
28 static HWND create_window(void)
32 wc.lpfnWndProc = DefWindowProc;
33 wc.lpszClassName = "d3d8_test_wc";
36 ret = CreateWindow("d3d8_test_wc", "d3d8_test",
37 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
41 static BOOL color_match(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
43 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
45 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
47 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
49 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
53 static DWORD getPixelColor(IDirect3DDevice8 *device, UINT x, UINT y)
56 IDirect3DSurface8 *surf;
57 IDirect3DTexture8 *tex;
59 D3DLOCKED_RECT lockedRect;
60 RECT rectToLock = {x, y, x+1, y+1};
62 hr = IDirect3DDevice8_CreateTexture(device, 640, 480, 1 /* Levels */, 0 /* usage */, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &tex);
63 if(FAILED(hr) || !tex ) /* This is not a test */
65 trace("Can't create an offscreen plain surface to read the render target data, hr=%#08x\n", hr);
68 hr = IDirect3DTexture8_GetSurfaceLevel(tex, 0, &surf);
69 if(FAILED(hr) || !tex ) /* This is not a test */
71 trace("Can't get surface from texture, hr=%#08x\n", hr);
76 hr = IDirect3DDevice8_GetFrontBuffer(device, surf);
79 trace("Can't read the front buffer data, hr=%#08x\n", hr);
84 hr = IDirect3DSurface8_LockRect(surf, &lockedRect, &rectToLock, D3DLOCK_READONLY);
87 trace("Can't lock the offscreen surface, hr=%#08x\n", hr);
91 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
92 * really important for these tests
94 ret = ((DWORD *) lockedRect.pBits)[0] & 0x00ffffff;
95 hr = IDirect3DSurface8_UnlockRect(surf);
98 trace("Can't unlock the offscreen surface, hr=%#08x\n", hr);
102 if(surf) IDirect3DSurface8_Release(surf);
103 if(tex) IDirect3DTexture8_Release(tex);
107 static IDirect3DDevice8 *init_d3d8(void)
109 IDirect3D8 * (__stdcall * d3d8_create)(UINT SDKVersion) = 0;
110 IDirect3D8 *d3d8_ptr = 0;
111 IDirect3DDevice8 *device_ptr = 0;
112 D3DPRESENT_PARAMETERS present_parameters;
115 d3d8_create = (void *)GetProcAddress(d3d8_handle, "Direct3DCreate8");
116 ok(d3d8_create != NULL, "Failed to get address of Direct3DCreate8\n");
117 if (!d3d8_create) return NULL;
119 d3d8_ptr = d3d8_create(D3D_SDK_VERSION);
122 skip("could not create D3D8\n");
126 ZeroMemory(&present_parameters, sizeof(present_parameters));
127 present_parameters.Windowed = FALSE;
128 present_parameters.hDeviceWindow = create_window();
129 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
130 present_parameters.BackBufferWidth = 640;
131 present_parameters.BackBufferHeight = 480;
132 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
133 present_parameters.EnableAutoDepthStencil = TRUE;
134 present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
136 hr = IDirect3D8_CreateDevice(d3d8_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
137 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL || broken(hr == D3DERR_NOTAVAILABLE), "IDirect3D_CreateDevice returned: %#08x\n", hr);
155 static void lighting_test(IDirect3DDevice8 *device)
158 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
159 DWORD nfvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_NORMAL;
162 float mat[16] = { 1.0f, 0.0f, 0.0f, 0.0f,
163 0.0f, 1.0f, 0.0f, 0.0f,
164 0.0f, 0.0f, 1.0f, 0.0f,
165 0.0f, 0.0f, 0.0f, 1.0f };
167 struct vertex unlitquad[] =
169 {-1.0f, -1.0f, 0.1f, 0xffff0000},
170 {-1.0f, 0.0f, 0.1f, 0xffff0000},
171 { 0.0f, 0.0f, 0.1f, 0xffff0000},
172 { 0.0f, -1.0f, 0.1f, 0xffff0000},
174 struct vertex litquad[] =
176 {-1.0f, 0.0f, 0.1f, 0xff00ff00},
177 {-1.0f, 1.0f, 0.1f, 0xff00ff00},
178 { 0.0f, 1.0f, 0.1f, 0xff00ff00},
179 { 0.0f, 0.0f, 0.1f, 0xff00ff00},
181 struct nvertex unlitnquad[] =
183 { 0.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
184 { 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
185 { 1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
186 { 1.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
188 struct nvertex litnquad[] =
190 { 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
191 { 0.0f, 1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
192 { 1.0f, 1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
193 { 1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
195 WORD Indices[] = {0, 1, 2, 2, 3, 0};
197 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
198 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
200 /* Setup some states that may cause issues */
201 hr = IDirect3DDevice8_SetTransform(device, D3DTS_WORLDMATRIX(0), (D3DMATRIX *) mat);
202 ok(hr == D3D_OK, "IDirect3DDevice8_SetTransform returned %#08x\n", hr);
203 hr = IDirect3DDevice8_SetTransform(device, D3DTS_VIEW, (D3DMATRIX *)mat);
204 ok(hr == D3D_OK, "IDirect3DDevice8_SetTransform returned %#08x\n", hr);
205 hr = IDirect3DDevice8_SetTransform(device, D3DTS_PROJECTION, (D3DMATRIX *) mat);
206 ok(hr == D3D_OK, "IDirect3DDevice8_SetTransform returned %#08x\n", hr);
207 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_CLIPPING, FALSE);
208 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
209 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, FALSE);
210 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
211 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGENABLE, FALSE);
212 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
213 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_STENCILENABLE, FALSE);
214 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
215 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHATESTENABLE, FALSE);
216 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
217 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, FALSE);
218 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
219 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE);
220 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed with %#08x\n", hr);
221 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE);
222 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed with %#08x\n", hr);
224 hr = IDirect3DDevice8_SetVertexShader(device, fvf);
225 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
227 hr = IDirect3DDevice8_BeginScene(device);
228 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
231 /* No lights are defined... That means, lit vertices should be entirely black */
232 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
233 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
234 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
235 2 /*PrimCount */, Indices, D3DFMT_INDEX16, unlitquad, sizeof(unlitquad[0]));
236 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr);
238 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, TRUE);
239 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
240 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
241 2 /*PrimCount */, Indices, D3DFMT_INDEX16, litquad, sizeof(litquad[0]));
242 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr);
244 hr = IDirect3DDevice8_SetVertexShader(device, nfvf);
245 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader failed with %#08x\n", hr);
247 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
248 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
249 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
250 2 /*PrimCount */, Indices, D3DFMT_INDEX16, unlitnquad, sizeof(unlitnquad[0]));
251 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr);
253 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, TRUE);
254 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
255 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
256 2 /*PrimCount */, Indices, D3DFMT_INDEX16, litnquad, sizeof(litnquad[0]));
257 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr);
259 IDirect3DDevice8_EndScene(device);
260 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
263 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
265 color = getPixelColor(device, 160, 360); /* lower left quad - unlit without normals */
266 ok(color == 0x00ff0000, "Unlit quad without normals has color %08x\n", color);
267 color = getPixelColor(device, 160, 120); /* upper left quad - lit without normals */
268 ok(color == 0x00000000, "Lit quad without normals has color %08x\n", color);
269 color = getPixelColor(device, 480, 360); /* lower left quad - unlit width normals */
270 ok(color == 0x000000ff, "Unlit quad width normals has color %08x\n", color);
271 color = getPixelColor(device, 480, 120); /* upper left quad - lit width normals */
272 ok(color == 0x00000000, "Lit quad width normals has color %08x\n", color);
274 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
275 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
278 static void clear_test(IDirect3DDevice8 *device)
280 /* Tests the correctness of clearing parameters */
286 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
287 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
289 /* Positive x, negative y */
295 /* Positive x, positive y */
300 /* Clear 2 rectangles with one call. Shows that a positive value is returned, but the negative rectangle
301 * is ignored, the positive is still cleared afterwards
303 hr = IDirect3DDevice8_Clear(device, 2, rect, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
304 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
306 /* negative x, negative y */
307 rect_negneg.x1 = 640;
308 rect_negneg.y1 = 240;
309 rect_negneg.x2 = 320;
311 hr = IDirect3DDevice8_Clear(device, 1, &rect_negneg, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
312 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
314 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
316 color = getPixelColor(device, 160, 360); /* lower left quad */
317 ok(color == 0x00ffffff, "Clear rectangle 3(pos, neg) has color %08x\n", color);
318 color = getPixelColor(device, 160, 120); /* upper left quad */
319 ok(color == 0x00ff0000, "Clear rectangle 1(pos, pos) has color %08x\n", color);
320 color = getPixelColor(device, 480, 360); /* lower right quad */
321 ok(color == 0x00ffffff, "Clear rectangle 4(NULL) has color %08x\n", color);
322 color = getPixelColor(device, 480, 120); /* upper right quad */
323 ok(color == 0x00ffffff, "Clear rectangle 4(neg, neg) has color %08x\n", color);
338 static void fog_test(IDirect3DDevice8 *device)
342 float start = 0.0, end = 1.0;
344 /* Gets full z based fog with linear fog, no fog with specular color */
345 struct sVertex unstransformed_1[] = {
346 {-1, -1, 0.1f, 0xFFFF0000, 0xFF000000 },
347 {-1, 0, 0.1f, 0xFFFF0000, 0xFF000000 },
348 { 0, 0, 0.1f, 0xFFFF0000, 0xFF000000 },
349 { 0, -1, 0.1f, 0xFFFF0000, 0xFF000000 },
351 /* Ok, I am too lazy to deal with transform matrices */
352 struct sVertex unstransformed_2[] = {
353 {-1, 0, 1.0f, 0xFFFF0000, 0xFF000000 },
354 {-1, 1, 1.0f, 0xFFFF0000, 0xFF000000 },
355 { 0, 1, 1.0f, 0xFFFF0000, 0xFF000000 },
356 { 0, 0, 1.0f, 0xFFFF0000, 0xFF000000 },
358 /* Untransformed ones. Give them a different diffuse color to make the test look
359 * nicer. It also makes making sure that they are drawn correctly easier.
361 struct sVertexT transformed_1[] = {
362 {320, 0, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
363 {640, 0, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
364 {640, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
365 {320, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
367 struct sVertexT transformed_2[] = {
368 {320, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
369 {640, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
370 {640, 480, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
371 {320, 480, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
373 WORD Indices[] = {0, 1, 2, 2, 3, 0};
375 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
376 ok(hr == D3D_OK, "IDirect3DDevice8_Clear returned %#08x\n", hr);
378 /* Setup initial states: No lighting, fog on, fog color */
379 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
380 ok(hr == D3D_OK, "Turning off lighting returned %#08x\n", hr);
381 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGENABLE, TRUE);
382 ok(hr == D3D_OK, "Turning on fog calculations returned %#08x\n", hr);
383 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGCOLOR, 0xFF00FF00 /* A nice green */);
384 ok(hr == D3D_OK, "Turning on fog calculations returned %#08x\n", hr);
386 /* First test: Both table fog and vertex fog off */
387 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_NONE);
388 ok(hr == D3D_OK, "Turning off table fog returned %#08x\n", hr);
389 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGVERTEXMODE, D3DFOG_NONE);
390 ok(hr == D3D_OK, "Turning off table fog returned %#08x\n", hr);
392 /* Start = 0, end = 1. Should be default, but set them */
393 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGSTART, *((DWORD *) &start));
394 ok(hr == D3D_OK, "Setting fog start returned %#08x\n", hr);
395 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGEND, *((DWORD *) &end));
396 ok(hr == D3D_OK, "Setting fog start returned %#08x\n", hr);
398 if(IDirect3DDevice8_BeginScene(device) == D3D_OK)
400 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
401 ok( hr == D3D_OK, "SetVertexShader returned %#08x\n", hr);
402 /* Untransformed, vertex fog = NONE, table fog = NONE: Read the fog weighting from the specular color */
403 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
404 2 /*PrimCount */, Indices, D3DFMT_INDEX16, unstransformed_1,
405 sizeof(unstransformed_1[0]));
406 ok(hr == D3D_OK, "DrawIndexedPrimitiveUP returned %#08x\n", hr);
408 /* That makes it use the Z value */
409 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR);
410 ok(hr == D3D_OK, "Turning off table fog returned %#08x\n", hr);
411 /* Untransformed, vertex fog != none (or table fog != none):
412 * Use the Z value as input into the equation
414 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
415 2 /*PrimCount */, Indices, D3DFMT_INDEX16, unstransformed_2,
416 sizeof(unstransformed_1[0]));
417 ok(hr == D3D_OK, "DrawIndexedPrimitiveUP returned %#08x\n", hr);
419 /* transformed verts */
420 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
421 ok( hr == D3D_OK, "SetVertexShader returned %#08x\n", hr);
422 /* Transformed, vertex fog != NONE, pixel fog == NONE: Use specular color alpha component */
423 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
424 2 /*PrimCount */, Indices, D3DFMT_INDEX16, transformed_1,
425 sizeof(transformed_1[0]));
426 ok(hr == D3D_OK, "DrawIndexedPrimitiveUP returned %#08x\n", hr);
428 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);
429 ok( hr == D3D_OK, "Setting fog table mode to D3DFOG_LINEAR returned %#08x\n", hr);
430 /* Transformed, table fog != none, vertex anything: Use Z value as input to the fog
433 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
434 2 /*PrimCount */, Indices, D3DFMT_INDEX16, transformed_2,
435 sizeof(transformed_2[0]));
436 ok(SUCCEEDED(hr), "IDirect3DDevice8_DrawIndexedPrimitiveUP returned %#x.\n", hr);
438 hr = IDirect3DDevice8_EndScene(device);
439 ok(hr == D3D_OK, "EndScene returned %#08x\n", hr);
443 ok(FALSE, "BeginScene failed\n");
446 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
447 color = getPixelColor(device, 160, 360);
448 ok(color == 0x00FF0000, "Untransformed vertex with no table or vertex fog has color %08x\n", color);
449 color = getPixelColor(device, 160, 120);
450 ok(color == 0x0000FF00, "Untransformed vertex with linear vertex fog has color %08x\n", color);
451 color = getPixelColor(device, 480, 120);
452 ok(color == 0x00FFFF00, "Transformed vertex with linear vertex fog has color %08x\n", color);
453 color = getPixelColor(device, 480, 360);
454 ok(color == 0x0000FF00, "Transformed vertex with linear table fog has color %08x\n", color);
456 /* Turn off the fog master switch to avoid confusing other tests */
457 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGENABLE, FALSE);
458 ok(hr == D3D_OK, "Turning off fog calculations returned %#08x\n", hr);
461 static void present_test(IDirect3DDevice8 *device)
463 struct vertex quad[] =
465 {-1.0f, -1.0f, 0.9f, 0xffff0000},
466 {-1.0f, 1.0f, 0.9f, 0xffff0000},
467 { 1.0f, -1.0f, 0.1f, 0xffff0000},
468 { 1.0f, 1.0f, 0.1f, 0xffff0000},
473 /* Does the Present clear the depth stencil? Clear the depth buffer with some value != 0,
474 * then call Present. Then clear the color buffer to make sure it has some defined content
475 * after the Present with D3DSWAPEFFECT_DISCARD. After that draw a plane that is somewhere cut
476 * by the depth value.
478 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 0.75, 0);
479 ok(hr == D3D_OK, "IDirect3DDevice8_Clear returned %08x\n", hr);
480 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
481 ok(SUCCEEDED(hr), "IDirect3DDevice8_Present returned %#x.\n", hr);
482 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.4, 0);
483 ok(SUCCEEDED(hr), "IDirect3DDevice8_Clear returned %#x.\n", hr);
485 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
486 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %08x\n", hr);
487 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_GREATER);
488 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %08x\n", hr);
489 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
490 ok(hr == D3D_OK, "IDirect3DDevice8_SetFVF returned %08x\n", hr);
492 hr = IDirect3DDevice8_BeginScene(device);
493 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %08x\n", hr);
496 /* No lights are defined... That means, lit vertices should be entirely black */
497 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2 /*PrimCount */, quad, sizeof(quad[0]));
498 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %08x\n", hr);
500 hr = IDirect3DDevice8_EndScene(device);
501 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %08x\n", hr);
504 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
505 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %08x\n", hr);
507 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
508 ok(SUCCEEDED(hr), "Present failed (%#08x)\n", hr);
509 color = getPixelColor(device, 512, 240);
510 ok(color == 0x00ffffff, "Present failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
511 color = getPixelColor(device, 64, 240);
512 ok(color == 0x00ff0000, "Present failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
515 static void test_rcp_rsq(IDirect3DDevice8 *device)
520 unsigned char c1, c2, c3;
521 float constant[4] = {1.0, 1.0, 1.0, 2.0};
523 static const float quad[][3] = {
524 {-1.0f, -1.0f, 0.0f},
526 { 1.0f, -1.0f, 0.0f},
530 const DWORD rcp_test[] = {
531 0xfffe0101, /* vs.1.1 */
533 0x0009fffe, 0x30303030, 0x30303030, /* Shaders have to have a minimal size. */
534 0x30303030, 0x30303030, 0x30303030, /* Add a filler comment. Usually D3DX8's*/
535 0x30303030, 0x30303030, 0x30303030, /* version comment makes the shader big */
536 0x00303030, /* enough to make windows happy */
538 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
539 0x00000006, 0xd00f0000, 0xa0e40000, /* rcp oD0, c0 */
543 const DWORD rsq_test[] = {
544 0xfffe0101, /* vs.1.1 */
546 0x0009fffe, 0x30303030, 0x30303030, /* Shaders have to have a minimal size. */
547 0x30303030, 0x30303030, 0x30303030, /* Add a filler comment. Usually D3DX8's*/
548 0x30303030, 0x30303030, 0x30303030, /* version comment makes the shader big */
549 0x00303030, /* enough to make windows happy */
551 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
552 0x00000007, 0xd00f0000, 0xa0e40000, /* rsq oD0, c0 */
559 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
563 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff800080, 0.0, 0);
564 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
566 hr = IDirect3DDevice8_CreateVertexShader(device, decl, rcp_test, &shader, 0);
567 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned with %#08x\n", hr);
569 IDirect3DDevice8_SetVertexShader(device, shader);
570 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
571 IDirect3DDevice8_SetVertexShaderConstant(device, 0, constant, 1);
573 hr = IDirect3DDevice8_BeginScene(device);
574 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene returned %#08x\n", hr);
577 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], 3 * sizeof(float));
578 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%#08x)\n", hr);
579 hr = IDirect3DDevice8_EndScene(device);
580 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
583 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
584 ok(SUCCEEDED(hr), "Present failed (%#08x)\n", hr);
585 color = getPixelColor(device, 320, 240);
586 c1 = (color & 0x00ff0000 )>> 16;
587 c2 = (color & 0x0000ff00 )>> 8;
588 c3 = (color & 0x000000ff )>> 0;
589 ok(c1 == c2 && c2 == c3, "Color components differ: c1 = %02x, c2 = %02x, c3 = %02x\n",
591 ok(c1 >= 0x7c && c1 <= 0x84, "Color component value is %02x\n", c1);
593 IDirect3DDevice8_SetVertexShader(device, 0);
594 IDirect3DDevice8_DeleteVertexShader(device, shader);
596 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff800080, 0.0, 0);
597 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
599 hr = IDirect3DDevice8_CreateVertexShader(device, decl, rsq_test, &shader, 0);
600 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned with %#08x\n", hr);
602 IDirect3DDevice8_SetVertexShader(device, shader);
603 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
604 IDirect3DDevice8_SetVertexShaderConstant(device, 0, constant, 1);
606 hr = IDirect3DDevice8_BeginScene(device);
607 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene returned %#08x\n", hr);
610 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], 3 * sizeof(float));
611 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%#08x)\n", hr);
612 hr = IDirect3DDevice8_EndScene(device);
613 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
616 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
617 ok(SUCCEEDED(hr), "Present failed (%#08x)\n", hr);
618 color = getPixelColor(device, 320, 240);
619 c1 = (color & 0x00ff0000 )>> 16;
620 c2 = (color & 0x0000ff00 )>> 8;
621 c3 = (color & 0x000000ff )>> 0;
622 ok(c1 == c2 && c2 == c3, "Color components differ: c1 = %02x, c2 = %02x, c3 = %02x\n",
624 ok(c1 >= 0xb0 && c1 <= 0xb8, "Color component value is %02x\n", c1);
626 IDirect3DDevice8_SetVertexShader(device, 0);
627 IDirect3DDevice8_DeleteVertexShader(device, shader);
630 static void offscreen_test(IDirect3DDevice8 *device)
633 IDirect3DTexture8 *offscreenTexture = NULL;
634 IDirect3DSurface8 *backbuffer = NULL, *offscreen = NULL, *depthstencil = NULL;
637 static const float quad[][5] = {
638 {-0.5f, -0.5f, 0.1f, 0.0f, 0.0f},
639 {-0.5f, 0.5f, 0.1f, 0.0f, 1.0f},
640 { 0.5f, -0.5f, 0.1f, 1.0f, 0.0f},
641 { 0.5f, 0.5f, 0.1f, 1.0f, 1.0f},
644 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &depthstencil);
645 ok(hr == D3D_OK, "IDirect3DDevice8_GetDepthStencilSurface failed, hr = %#08x\n", hr);
647 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
648 ok(hr == D3D_OK, "Clear failed, hr = %#08x\n", hr);
650 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &offscreenTexture);
651 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Creating the offscreen render target failed, hr = %#08x\n", hr);
652 if(!offscreenTexture) {
653 trace("Failed to create an X8R8G8B8 offscreen texture, trying R5G6B5\n");
654 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET, D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &offscreenTexture);
655 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Creating the offscreen render target failed, hr = %#08x\n", hr);
656 if(!offscreenTexture) {
657 skip("Cannot create an offscreen render target\n");
662 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
663 ok(hr == D3D_OK, "Can't get back buffer, hr = %#08x\n", hr);
668 hr = IDirect3DTexture8_GetSurfaceLevel(offscreenTexture, 0, &offscreen);
669 ok(hr == D3D_OK, "Can't get offscreen surface, hr = %#08x\n", hr);
674 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_TEX1);
675 ok(hr == D3D_OK, "SetVertexShader failed, hr = %#08x\n", hr);
677 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
678 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %#08x\n", hr);
679 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
680 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %#08x\n", hr);
681 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MINFILTER, D3DTEXF_NONE);
682 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MINFILTER failed (%#08x)\n", hr);
683 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MAGFILTER, D3DTEXF_NONE);
684 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MAGFILTER failed (%#08x)\n", hr);
685 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
686 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %08x\n", hr);
688 if(IDirect3DDevice8_BeginScene(device) == D3D_OK) {
689 hr = IDirect3DDevice8_SetRenderTarget(device, offscreen, depthstencil);
690 ok(hr == D3D_OK, "SetRenderTarget failed, hr = %#08x\n", hr);
691 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
692 ok(hr == D3D_OK, "Clear failed, hr = %#08x\n", hr);
694 /* Draw without textures - Should result in a white quad */
695 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
696 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
698 hr = IDirect3DDevice8_SetRenderTarget(device, backbuffer, depthstencil);
699 ok(hr == D3D_OK, "SetRenderTarget failed, hr = %#08x\n", hr);
700 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) offscreenTexture);
701 ok(hr == D3D_OK, "SetTexture failed, %08x\n", hr);
703 /* This time with the texture */
704 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
705 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
707 IDirect3DDevice8_EndScene(device);
710 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
712 /* Center quad - should be white */
713 color = getPixelColor(device, 320, 240);
714 ok(color == 0x00ffffff, "Offscreen failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
715 /* Some quad in the cleared part of the texture */
716 color = getPixelColor(device, 170, 240);
717 ok(color == 0x00ff00ff, "Offscreen failed: Got color 0x%08x, expected 0x00ff00ff.\n", color);
718 /* Part of the originally cleared back buffer */
719 color = getPixelColor(device, 10, 10);
720 ok(color == 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
722 /* Lower left corner of the screen, where back buffer offscreen rendering draws the offscreen texture.
723 * It should be red, but the offscreen texture may leave some junk there. Not tested yet. Depending on
724 * the offscreen rendering mode this test would succeed or fail
726 color = getPixelColor(device, 10, 470);
727 ok(color == 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
731 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
732 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetTexture returned %#x.\n", hr);
736 hr = IDirect3DDevice8_SetRenderTarget(device, backbuffer, depthstencil);
737 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetRenderTarget returned %#x.\n", hr);
738 IDirect3DSurface8_Release(backbuffer);
740 if(offscreenTexture) {
741 IDirect3DTexture8_Release(offscreenTexture);
744 IDirect3DSurface8_Release(offscreen);
747 IDirect3DSurface8_Release(depthstencil);
751 static void alpha_test(IDirect3DDevice8 *device)
754 IDirect3DTexture8 *offscreenTexture;
755 IDirect3DSurface8 *backbuffer = NULL, *offscreen = NULL, *depthstencil = NULL;
758 struct vertex quad1[] =
760 {-1.0f, -1.0f, 0.1f, 0x4000ff00},
761 {-1.0f, 0.0f, 0.1f, 0x4000ff00},
762 { 1.0f, -1.0f, 0.1f, 0x4000ff00},
763 { 1.0f, 0.0f, 0.1f, 0x4000ff00},
765 struct vertex quad2[] =
767 {-1.0f, 0.0f, 0.1f, 0xc00000ff},
768 {-1.0f, 1.0f, 0.1f, 0xc00000ff},
769 { 1.0f, 0.0f, 0.1f, 0xc00000ff},
770 { 1.0f, 1.0f, 0.1f, 0xc00000ff},
772 static const float composite_quad[][5] = {
773 { 0.0f, -1.0f, 0.1f, 0.0f, 1.0f},
774 { 0.0f, 1.0f, 0.1f, 0.0f, 0.0f},
775 { 1.0f, -1.0f, 0.1f, 1.0f, 1.0f},
776 { 1.0f, 1.0f, 0.1f, 1.0f, 0.0f},
779 /* Clear the render target with alpha = 0.5 */
780 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x80ff0000, 0.0, 0);
781 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
783 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &offscreenTexture);
784 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Creating the offscreen render target failed, hr = %#08x\n", hr);
786 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &depthstencil);
787 ok(hr == D3D_OK, "IDirect3DDevice8_GetDepthStencilSurface failed, hr = %#08x\n", hr);
789 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
790 ok(hr == D3D_OK, "Can't get back buffer, hr = %#08x\n", hr);
794 hr = IDirect3DTexture8_GetSurfaceLevel(offscreenTexture, 0, &offscreen);
795 ok(hr == D3D_OK, "Can't get offscreen surface, hr = %#08x\n", hr);
800 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
801 ok(hr == D3D_OK, "SetVertexShader failed, hr = %#08x\n", hr);
803 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
804 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %#08x\n", hr);
805 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
806 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %#08x\n", hr);
807 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MINFILTER, D3DTEXF_NONE);
808 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MINFILTER failed (%#08x)\n", hr);
809 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MAGFILTER, D3DTEXF_NONE);
810 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MAGFILTER failed (%#08x)\n", hr);
811 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
812 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %08x\n", hr);
814 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, TRUE);
815 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
816 if(IDirect3DDevice8_BeginScene(device) == D3D_OK) {
818 /* Draw two quads, one with src alpha blending, one with dest alpha blending. */
819 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
820 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
821 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
822 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
823 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(quad1[0]));
824 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
826 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_DESTALPHA);
827 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
828 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVDESTALPHA);
829 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
830 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(quad2[0]));
831 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
833 /* Switch to the offscreen buffer, and redo the testing. The offscreen render target
834 * doesn't have an alpha channel. DESTALPHA and INVDESTALPHA "don't work" on render
835 * targets without alpha channel, they give essentially ZERO and ONE blend factors. */
836 hr = IDirect3DDevice8_SetRenderTarget(device, offscreen, 0);
837 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
838 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x80ff0000, 0.0, 0);
839 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
841 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
842 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
843 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
844 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
845 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(quad1[0]));
846 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
848 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_DESTALPHA);
849 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
850 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVDESTALPHA);
851 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
852 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(quad2[0]));
853 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
855 hr = IDirect3DDevice8_SetRenderTarget(device, backbuffer, depthstencil);
856 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
858 /* Render the offscreen texture onto the frame buffer to be able to compare it regularly.
859 * Disable alpha blending for the final composition
861 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, FALSE);
862 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
863 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_TEX1);
864 ok(hr == D3D_OK, "SetVertexShader failed, hr = %#08x\n", hr);
866 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) offscreenTexture);
867 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
868 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, composite_quad, sizeof(float) * 5);
869 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
870 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
871 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
873 hr = IDirect3DDevice8_EndScene(device);
874 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed, hr = %08x\n", hr);
877 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
879 color = getPixelColor(device, 160, 360);
880 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xbf, 0x40, 0x00), 1),
881 "SRCALPHA on frame buffer returned color %08x, expected 0x00bf4000\n", color);
883 color = getPixelColor(device, 160, 120);
884 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x7f, 0x00, 0x80), 2),
885 "DSTALPHA on frame buffer returned color %08x, expected 0x007f0080\n", color);
887 color = getPixelColor(device, 480, 360);
888 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xbf, 0x40, 0x00), 1),
889 "SRCALPHA on texture returned color %08x, expected 0x00bf4000\n", color);
891 color = getPixelColor(device, 480, 120);
892 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0xff), 1),
893 "DSTALPHA on texture returned color %08x, expected 0x000000ff\n", color);
898 IDirect3DSurface8_Release(backbuffer);
900 if(offscreenTexture) {
901 IDirect3DTexture8_Release(offscreenTexture);
904 IDirect3DSurface8_Release(offscreen);
907 IDirect3DSurface8_Release(depthstencil);
911 static void p8_texture_test(IDirect3DDevice8 *device)
913 IDirect3D8 *d3d = NULL;
915 IDirect3DTexture8 *texture = NULL, *texture2 = NULL;
918 DWORD color, red, green, blue;
919 PALETTEENTRY table[256];
923 -1.0, 0, 0.1, 0.0, 0.0,
924 -1.0, 1.0, 0.1, 0.0, 1.0,
925 1.0, 0, 0.1, 1.0, 0.0,
926 1.0, 1.0, 0.1, 1.0, 1.0,
929 -1.0, -1.0, 0.1, 0.0, 0.0,
930 -1.0, 0, 0.1, 0.0, 1.0,
931 1.0, -1.0, 0.1, 1.0, 0.0,
932 1.0, 0, 0.1, 1.0, 1.0,
935 IDirect3DDevice8_GetDirect3D(device, &d3d);
937 if(IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, 0,
938 D3DRTYPE_TEXTURE, D3DFMT_P8) != D3D_OK) {
939 skip("D3DFMT_P8 textures not supported\n");
943 hr = IDirect3DDevice8_CreateTexture(device, 1, 1, 1, 0, D3DFMT_P8,
944 D3DPOOL_MANAGED, &texture2);
945 ok(hr == D3D_OK, "IDirect3DDevice8_CreateTexture failed, hr = %08x\n", hr);
947 skip("Failed to create D3DFMT_P8 texture\n");
951 memset(&lr, 0, sizeof(lr));
952 hr = IDirect3DTexture8_LockRect(texture2, 0, &lr, NULL, 0);
953 ok(hr == D3D_OK, "IDirect3DTexture8_LockRect failed, hr = %08x\n", hr);
957 hr = IDirect3DTexture8_UnlockRect(texture2, 0);
958 ok(hr == D3D_OK, "IDirect3DTexture8_UnlockRect failed, hr = %08x\n", hr);
960 hr = IDirect3DDevice8_CreateTexture(device, 1, 1, 1, 0, D3DFMT_P8,
961 D3DPOOL_MANAGED, &texture);
962 ok(hr == D3D_OK, "IDirect3DDevice8_CreateTexture failed, hr = %08x\n", hr);
964 skip("Failed to create D3DFMT_P8 texture\n");
968 memset(&lr, 0, sizeof(lr));
969 hr = IDirect3DTexture8_LockRect(texture, 0, &lr, NULL, 0);
970 ok(hr == D3D_OK, "IDirect3DTexture8_LockRect failed, hr = %08x\n", hr);
974 hr = IDirect3DTexture8_UnlockRect(texture, 0);
975 ok(hr == D3D_OK, "IDirect3DTexture8_UnlockRect failed, hr = %08x\n", hr);
977 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff000000, 0.0, 0);
978 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed, hr = %08x\n", hr);
980 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, TRUE);
981 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
983 /* The first part of the test should work both with and without D3DPTEXTURECAPS_ALPHAPALETTE;
984 alpha of every entry is set to 1.0, which MS says is required when there's no
985 D3DPTEXTURECAPS_ALPHAPALETTE capability */
986 for (i = 0; i < 256; i++) {
987 table[i].peRed = table[i].peGreen = table[i].peBlue = 0;
988 table[i].peFlags = 0xff;
990 table[1].peRed = 0xff;
991 hr = IDirect3DDevice8_SetPaletteEntries(device, 0, table);
992 ok(hr == D3D_OK, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr);
995 table[1].peBlue = 0xff;
996 hr = IDirect3DDevice8_SetPaletteEntries(device, 1, table);
997 ok(hr == D3D_OK, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr);
999 hr = IDirect3DDevice8_BeginScene(device);
1000 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed, hr = %08x\n", hr);
1002 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
1003 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1004 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
1005 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1007 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_TEX1);
1008 ok(hr == D3D_OK, "SetVertexShader failed, hr = %#08x\n", hr);
1010 hr = IDirect3DDevice8_SetCurrentTexturePalette(device, 0);
1011 ok(hr == D3D_OK, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr);
1013 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) texture2);
1014 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
1015 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
1016 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1018 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) texture);
1019 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
1020 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
1021 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1023 hr = IDirect3DDevice8_SetCurrentTexturePalette(device, 1);
1024 ok(hr == D3D_OK, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr);
1025 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 5 * sizeof(float));
1026 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1028 hr = IDirect3DDevice8_EndScene(device);
1029 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed, hr = %08x\n", hr);
1032 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1033 ok(hr == D3D_OK, "IDirect3DDevice8_Present failed, hr = %08x\n", hr);
1035 color = getPixelColor(device, 32, 32);
1036 red = (color & 0x00ff0000) >> 16;
1037 green = (color & 0x0000ff00) >> 8;
1038 blue = (color & 0x000000ff) >> 0;
1039 ok(red == 0xff && blue == 0 && green == 0,
1040 "got color %08x, expected 0x00ff0000\n", color);
1042 color = getPixelColor(device, 32, 320);
1043 red = (color & 0x00ff0000) >> 16;
1044 green = (color & 0x0000ff00) >> 8;
1045 blue = (color & 0x000000ff) >> 0;
1046 ok(red == 0 && blue == 0xff && green == 0,
1047 "got color %08x, expected 0x000000ff\n", color);
1049 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff000000, 0.0, 0);
1050 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed, hr = %08x\n", hr);
1052 hr = IDirect3DDevice8_BeginScene(device);
1053 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed, hr = %08x\n", hr);
1055 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) texture2);
1056 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
1058 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
1059 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1061 hr = IDirect3DDevice8_EndScene(device);
1062 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed, hr = %08x\n", hr);
1065 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1066 ok(hr == D3D_OK, "IDirect3DDevice8_Present failed, hr = %08x\n", hr);
1068 color = getPixelColor(device, 32, 32);
1069 red = (color & 0x00ff0000) >> 16;
1070 green = (color & 0x0000ff00) >> 8;
1071 blue = (color & 0x000000ff) >> 0;
1072 ok(red == 0 && blue == 0xff && green == 0,
1073 "got color %08x, expected 0x000000ff\n", color);
1075 /* Test palettes with alpha */
1076 IDirect3DDevice8_GetDeviceCaps(device, &caps);
1077 if (!(caps.TextureCaps & D3DPTEXTURECAPS_ALPHAPALETTE)) {
1078 skip("no D3DPTEXTURECAPS_ALPHAPALETTE capability, tests with alpha in palette will be skipped\n");
1080 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff000000, 0.0, 0);
1081 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed, hr = %08x\n", hr);
1083 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, TRUE);
1084 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1086 for (i = 0; i < 256; i++) {
1087 table[i].peRed = table[i].peGreen = table[i].peBlue = 0;
1088 table[i].peFlags = 0xff;
1090 table[1].peRed = 0xff;
1091 table[1].peFlags = 0x80;
1092 hr = IDirect3DDevice8_SetPaletteEntries(device, 0, table);
1093 ok(hr == D3D_OK, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr);
1096 table[1].peBlue = 0xff;
1097 table[1].peFlags = 0x80;
1098 hr = IDirect3DDevice8_SetPaletteEntries(device, 1, table);
1099 ok(hr == D3D_OK, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr);
1101 hr = IDirect3DDevice8_BeginScene(device);
1102 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed, hr = %08x\n", hr);
1104 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
1105 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1106 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
1107 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1109 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_TEX1);
1110 ok(hr == D3D_OK, "SetVertexShader failed, hr = %#08x\n", hr);
1112 hr = IDirect3DDevice8_SetCurrentTexturePalette(device, 0);
1113 ok(hr == D3D_OK, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr);
1115 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
1116 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1118 hr = IDirect3DDevice8_SetCurrentTexturePalette(device, 1);
1119 ok(hr == D3D_OK, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr);
1121 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 5 * sizeof(float));
1122 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1124 hr = IDirect3DDevice8_EndScene(device);
1125 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed, hr = %08x\n", hr);
1128 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1129 ok(hr == D3D_OK, "IDirect3DDevice8_Present failed, hr = %08x\n", hr);
1131 color = getPixelColor(device, 32, 32);
1132 red = (color & 0x00ff0000) >> 16;
1133 green = (color & 0x0000ff00) >> 8;
1134 blue = (color & 0x000000ff) >> 0;
1135 ok(red >= 0x7e && red <= 0x81 && blue == 0 && green == 0,
1136 "got color %08x, expected 0x00800000 or near\n", color);
1138 color = getPixelColor(device, 32, 320);
1139 red = (color & 0x00ff0000) >> 16;
1140 green = (color & 0x0000ff00) >> 8;
1141 blue = (color & 0x000000ff) >> 0;
1142 ok(red == 0 && blue >= 0x7e && blue <= 0x81 && green == 0,
1143 "got color %08x, expected 0x00000080 or near\n", color);
1146 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
1147 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
1148 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, FALSE);
1149 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1152 if(texture) IDirect3DTexture8_Release(texture);
1153 if(texture2) IDirect3DTexture8_Release(texture2);
1154 IDirect3D8_Release(d3d);
1157 static void texop_test(IDirect3DDevice8 *device)
1159 IDirect3DTexture8 *texture = NULL;
1160 D3DLOCKED_RECT locked_rect;
1166 static const struct {
1171 {-1.0f, -1.0f, 0.1f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), -1.0f, -1.0f},
1172 {-1.0f, 1.0f, 0.1f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), -1.0f, 1.0f},
1173 { 1.0f, -1.0f, 0.1f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), 1.0f, -1.0f},
1174 { 1.0f, 1.0f, 0.1f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), 1.0f, 1.0f}
1177 static const struct {
1183 {D3DTOP_SELECTARG1, "SELECTARG1", D3DTEXOPCAPS_SELECTARG1, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00)},
1184 {D3DTOP_SELECTARG2, "SELECTARG2", D3DTEXOPCAPS_SELECTARG2, D3DCOLOR_ARGB(0x00, 0x33, 0x33, 0x33)},
1185 {D3DTOP_MODULATE, "MODULATE", D3DTEXOPCAPS_MODULATE, D3DCOLOR_ARGB(0x00, 0x00, 0x33, 0x00)},
1186 {D3DTOP_MODULATE2X, "MODULATE2X", D3DTEXOPCAPS_MODULATE2X, D3DCOLOR_ARGB(0x00, 0x00, 0x66, 0x00)},
1187 {D3DTOP_MODULATE4X, "MODULATE4X", D3DTEXOPCAPS_MODULATE4X, D3DCOLOR_ARGB(0x00, 0x00, 0xcc, 0x00)},
1188 {D3DTOP_ADD, "ADD", D3DTEXOPCAPS_ADD, D3DCOLOR_ARGB(0x00, 0x33, 0xff, 0x33)},
1189 {D3DTOP_ADDSIGNED, "ADDSIGNED", D3DTEXOPCAPS_ADDSIGNED, D3DCOLOR_ARGB(0x00, 0x00, 0xb2, 0x00)},
1190 {D3DTOP_ADDSIGNED2X, "ADDSIGNED2X", D3DTEXOPCAPS_ADDSIGNED2X, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00)},
1191 {D3DTOP_SUBTRACT, "SUBTRACT", D3DTEXOPCAPS_SUBTRACT, D3DCOLOR_ARGB(0x00, 0x00, 0xcc, 0x00)},
1192 {D3DTOP_ADDSMOOTH, "ADDSMOOTH", D3DTEXOPCAPS_ADDSMOOTH, D3DCOLOR_ARGB(0x00, 0x33, 0xff, 0x33)},
1193 {D3DTOP_BLENDDIFFUSEALPHA, "BLENDDIFFUSEALPHA", D3DTEXOPCAPS_BLENDDIFFUSEALPHA, D3DCOLOR_ARGB(0x00, 0x22, 0x77, 0x22)},
1194 {D3DTOP_BLENDTEXTUREALPHA, "BLENDTEXTUREALPHA", D3DTEXOPCAPS_BLENDTEXTUREALPHA, D3DCOLOR_ARGB(0x00, 0x14, 0xad, 0x14)},
1195 {D3DTOP_BLENDFACTORALPHA, "BLENDFACTORALPHA", D3DTEXOPCAPS_BLENDFACTORALPHA, D3DCOLOR_ARGB(0x00, 0x07, 0xe4, 0x07)},
1196 {D3DTOP_BLENDTEXTUREALPHAPM, "BLENDTEXTUREALPHAPM", D3DTEXOPCAPS_BLENDTEXTUREALPHAPM, D3DCOLOR_ARGB(0x00, 0x14, 0xff, 0x14)},
1197 {D3DTOP_BLENDCURRENTALPHA, "BLENDCURRENTALPHA", D3DTEXOPCAPS_BLENDCURRENTALPHA, D3DCOLOR_ARGB(0x00, 0x22, 0x77, 0x22)},
1198 {D3DTOP_MODULATEALPHA_ADDCOLOR, "MODULATEALPHA_ADDCOLOR", D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR, D3DCOLOR_ARGB(0x00, 0x1f, 0xff, 0x1f)},
1199 {D3DTOP_MODULATECOLOR_ADDALPHA, "MODULATECOLOR_ADDALPHA", D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA, D3DCOLOR_ARGB(0x00, 0x99, 0xcc, 0x99)},
1200 {D3DTOP_MODULATEINVALPHA_ADDCOLOR, "MODULATEINVALPHA_ADDCOLOR", D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR, D3DCOLOR_ARGB(0x00, 0x14, 0xff, 0x14)},
1201 {D3DTOP_MODULATEINVCOLOR_ADDALPHA, "MODULATEINVCOLOR_ADDALPHA", D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA, D3DCOLOR_ARGB(0x00, 0xcc, 0x99, 0xcc)},
1202 /* BUMPENVMAP & BUMPENVMAPLUMINANCE have their own tests */
1203 {D3DTOP_DOTPRODUCT3, "DOTPRODUCT2", D3DTEXOPCAPS_DOTPRODUCT3, D3DCOLOR_ARGB(0x00, 0x99, 0x99, 0x99)},
1204 {D3DTOP_MULTIPLYADD, "MULTIPLYADD", D3DTEXOPCAPS_MULTIPLYADD, D3DCOLOR_ARGB(0x00, 0xff, 0x33, 0x00)},
1205 {D3DTOP_LERP, "LERP", D3DTEXOPCAPS_LERP, D3DCOLOR_ARGB(0x00, 0x00, 0x33, 0x33)},
1208 memset(&caps, 0, sizeof(caps));
1209 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
1210 ok(SUCCEEDED(hr), "GetDeviceCaps failed with 0x%08x\n", hr);
1212 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX0);
1213 ok(SUCCEEDED(hr), "SetVertexShader failed with 0x%08x\n", hr);
1215 hr = IDirect3DDevice8_CreateTexture(device, 1, 1, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture);
1216 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateTexture failed with 0x%08x\n", hr);
1217 hr = IDirect3DTexture8_LockRect(texture, 0, &locked_rect, NULL, 0);
1218 ok(SUCCEEDED(hr), "LockRect failed with 0x%08x\n", hr);
1219 *((DWORD *)locked_rect.pBits) = D3DCOLOR_ARGB(0x99, 0x00, 0xff, 0x00);
1220 hr = IDirect3DTexture8_UnlockRect(texture, 0);
1221 ok(SUCCEEDED(hr), "LockRect failed with 0x%08x\n", hr);
1222 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *)texture);
1223 ok(SUCCEEDED(hr), "SetTexture failed with 0x%08x\n", hr);
1225 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLORARG0, D3DTA_DIFFUSE);
1226 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
1227 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
1228 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
1229 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
1230 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
1232 hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
1233 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
1235 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
1236 ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
1237 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0xdd333333);
1238 ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
1239 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA);
1240 ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
1242 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
1243 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
1245 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
1247 if (!(caps.TextureOpCaps & test_data[i].caps_flag))
1249 skip("tex operation %s not supported\n", test_data[i].name);
1253 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLOROP, test_data[i].op);
1254 ok(SUCCEEDED(hr), "SetTextureStageState (%s) failed with 0x%08x\n", test_data[i].name, hr);
1256 hr = IDirect3DDevice8_BeginScene(device);
1257 ok(SUCCEEDED(hr), "BeginScene failed with 0x%08x\n", hr);
1259 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
1260 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed with 0x%08x\n", hr);
1262 hr = IDirect3DDevice8_EndScene(device);
1263 ok(SUCCEEDED(hr), "EndScene failed with 0x%08x\n", hr);
1265 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1266 ok(SUCCEEDED(hr), "Present failed with 0x%08x\n", hr);
1268 color = getPixelColor(device, 320, 240);
1269 ok(color_match(color, test_data[i].result, 3), "Operation %s returned color 0x%08x, expected 0x%08x\n",
1270 test_data[i].name, color, test_data[i].result);
1273 if (texture) IDirect3DTexture8_Release(texture);
1278 IDirect3DDevice8 *device_ptr;
1283 d3d8_handle = LoadLibraryA("d3d8.dll");
1286 win_skip("Could not load d3d8.dll\n");
1290 device_ptr = init_d3d8();
1293 win_skip("Could not initialize direct3d\n");
1297 IDirect3DDevice8_GetDeviceCaps(device_ptr, &caps);
1299 /* Check for the reliability of the returned data */
1300 hr = IDirect3DDevice8_Clear(device_ptr, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
1303 skip("Clear failed, can't assure correctness of the test results\n");
1306 IDirect3DDevice8_Present(device_ptr, NULL, NULL, NULL, NULL);
1308 color = getPixelColor(device_ptr, 1, 1);
1309 if(color !=0x00ff0000)
1311 skip("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests\n", color);
1315 hr = IDirect3DDevice8_Clear(device_ptr, 0, NULL, D3DCLEAR_TARGET, 0xff00ddee, 0.0, 0);
1318 skip("Clear failed, can't assure correctness of the test results\n");
1321 IDirect3DDevice8_Present(device_ptr, NULL, NULL, NULL, NULL);
1323 color = getPixelColor(device_ptr, 639, 479);
1324 if(color != 0x0000ddee)
1326 skip("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests\n", color);
1330 /* Now run the real test */
1331 lighting_test(device_ptr);
1332 clear_test(device_ptr);
1333 fog_test(device_ptr);
1334 present_test(device_ptr);
1335 offscreen_test(device_ptr);
1336 alpha_test(device_ptr);
1338 if (caps.VertexShaderVersion >= D3DVS_VERSION(1, 1))
1340 test_rcp_rsq(device_ptr);
1344 skip("No vs.1.1 support\n");
1347 p8_texture_test(device_ptr);
1348 texop_test(device_ptr);
1352 D3DDEVICE_CREATION_PARAMETERS creation_parameters;
1355 IDirect3DDevice8_GetCreationParameters(device_ptr, &creation_parameters);
1356 DestroyWindow(creation_parameters.hFocusWindow);
1357 refcount = IDirect3DDevice8_Release(device_ptr);
1358 ok(!refcount, "Device has %u references left\n", refcount);