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_POPUP | WS_SYSMENU , 20, 20, 640, 480, 0, 0, 0, 0);
38 ShowWindow(ret, SW_SHOW);
42 static BOOL color_match(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
44 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
46 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
48 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
50 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
54 static DWORD getPixelColor(IDirect3DDevice8 *device, UINT x, UINT y)
57 IDirect3DTexture8 *tex = NULL;
58 IDirect3DSurface8 *surf = NULL, *backbuf = NULL;
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);
69 hr = IDirect3DTexture8_GetSurfaceLevel(tex, 0, &surf);
70 if(FAILED(hr) || !tex ) /* This is not a test */
72 trace("Can't get surface from texture, hr=%#08x\n", hr);
77 hr = IDirect3DDevice8_GetRenderTarget(device, &backbuf);
80 trace("Can't get the render target, hr=%#08x\n", hr);
84 hr = IDirect3DDevice8_CopyRects(device, backbuf, NULL, 0, surf, NULL);
87 trace("Can't read the render target, hr=%#08x\n", hr);
92 hr = IDirect3DSurface8_LockRect(surf, &lockedRect, &rectToLock, D3DLOCK_READONLY);
95 trace("Can't lock the offscreen surface, hr=%#08x\n", hr);
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);
106 trace("Can't unlock the offscreen surface, hr=%#08x\n", hr);
110 if(backbuf) IDirect3DSurface8_Release(backbuf);
111 if(surf) IDirect3DSurface8_Release(surf);
112 if(tex) IDirect3DTexture8_Release(tex);
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;
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);
131 skip("could not create D3D8\n");
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_D24S8;
145 hr = IDirect3D8_CreateDevice(d3d8_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
146 present_parameters.hDeviceWindow, D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
147 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL || broken(hr == D3DERR_NOTAVAILABLE), "IDirect3D_CreateDevice returned: %#08x\n", hr);
171 static void lighting_test(IDirect3DDevice8 *device)
174 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
175 DWORD nfvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_NORMAL;
178 float mat[16] = { 1.0f, 0.0f, 0.0f, 0.0f,
179 0.0f, 1.0f, 0.0f, 0.0f,
180 0.0f, 0.0f, 1.0f, 0.0f,
181 0.0f, 0.0f, 0.0f, 1.0f };
183 struct vertex unlitquad[] =
185 {-1.0f, -1.0f, 0.1f, 0xffff0000},
186 {-1.0f, 0.0f, 0.1f, 0xffff0000},
187 { 0.0f, 0.0f, 0.1f, 0xffff0000},
188 { 0.0f, -1.0f, 0.1f, 0xffff0000},
190 struct vertex litquad[] =
192 {-1.0f, 0.0f, 0.1f, 0xff00ff00},
193 {-1.0f, 1.0f, 0.1f, 0xff00ff00},
194 { 0.0f, 1.0f, 0.1f, 0xff00ff00},
195 { 0.0f, 0.0f, 0.1f, 0xff00ff00},
197 struct nvertex unlitnquad[] =
199 { 0.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
200 { 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
201 { 1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
202 { 1.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
204 struct nvertex litnquad[] =
206 { 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
207 { 0.0f, 1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
208 { 1.0f, 1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
209 { 1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xffffff00},
211 WORD Indices[] = {0, 1, 2, 2, 3, 0};
213 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
214 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
216 /* Setup some states that may cause issues */
217 hr = IDirect3DDevice8_SetTransform(device, D3DTS_WORLDMATRIX(0), (D3DMATRIX *) mat);
218 ok(hr == D3D_OK, "IDirect3DDevice8_SetTransform returned %#08x\n", hr);
219 hr = IDirect3DDevice8_SetTransform(device, D3DTS_VIEW, (D3DMATRIX *)mat);
220 ok(hr == D3D_OK, "IDirect3DDevice8_SetTransform returned %#08x\n", hr);
221 hr = IDirect3DDevice8_SetTransform(device, D3DTS_PROJECTION, (D3DMATRIX *) mat);
222 ok(hr == D3D_OK, "IDirect3DDevice8_SetTransform returned %#08x\n", hr);
223 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_CLIPPING, FALSE);
224 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
225 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, FALSE);
226 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
227 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGENABLE, FALSE);
228 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
229 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_STENCILENABLE, FALSE);
230 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
231 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHATESTENABLE, FALSE);
232 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
233 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, FALSE);
234 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
235 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE);
236 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed with %#08x\n", hr);
237 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE);
238 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed with %#08x\n", hr);
240 hr = IDirect3DDevice8_SetVertexShader(device, fvf);
241 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
243 hr = IDirect3DDevice8_BeginScene(device);
244 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
247 /* No lights are defined... That means, lit vertices should be entirely black */
248 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
249 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
250 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
251 2 /*PrimCount */, Indices, D3DFMT_INDEX16, unlitquad, sizeof(unlitquad[0]));
252 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr);
254 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, TRUE);
255 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
256 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
257 2 /*PrimCount */, Indices, D3DFMT_INDEX16, litquad, sizeof(litquad[0]));
258 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr);
260 hr = IDirect3DDevice8_SetVertexShader(device, nfvf);
261 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader failed with %#08x\n", hr);
263 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
264 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
265 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
266 2 /*PrimCount */, Indices, D3DFMT_INDEX16, unlitnquad, sizeof(unlitnquad[0]));
267 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr);
269 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, TRUE);
270 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
271 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
272 2 /*PrimCount */, Indices, D3DFMT_INDEX16, litnquad, sizeof(litnquad[0]));
273 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr);
275 IDirect3DDevice8_EndScene(device);
276 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
279 color = getPixelColor(device, 160, 360); /* Lower left quad - unlit without normals */
280 ok(color == 0x00ff0000, "Unlit quad without normals has color 0x%08x, expected 0x00ff0000.\n", color);
281 color = getPixelColor(device, 160, 120); /* Upper left quad - lit without normals */
282 ok(color == 0x00000000, "Lit quad without normals has color 0x%08x, expected 0x00000000.\n", color);
283 color = getPixelColor(device, 480, 360); /* Lower right quad - unlit with normals */
284 ok(color == 0x000000ff, "Unlit quad with normals has color 0x%08x, expected 0x000000ff.\n", color);
285 color = getPixelColor(device, 480, 120); /* Upper right quad - lit with normals */
286 ok(color == 0x00000000, "Lit quad with normals has color 0x%08x, expected 0x00000000.\n", color);
288 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
290 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
291 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %#08x\n", hr);
294 static void clear_test(IDirect3DDevice8 *device)
296 /* Tests the correctness of clearing parameters */
302 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
303 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
305 /* Positive x, negative y */
311 /* Positive x, positive y */
316 /* Clear 2 rectangles with one call. Shows that a positive value is returned, but the negative rectangle
317 * is ignored, the positive is still cleared afterwards
319 hr = IDirect3DDevice8_Clear(device, 2, rect, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
320 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
322 /* negative x, negative y */
323 rect_negneg.x1 = 640;
324 rect_negneg.y1 = 240;
325 rect_negneg.x2 = 320;
327 hr = IDirect3DDevice8_Clear(device, 1, &rect_negneg, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
328 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
330 color = getPixelColor(device, 160, 360); /* lower left quad */
331 ok(color == 0x00ffffff, "Clear rectangle 3(pos, neg) has color %08x\n", color);
332 color = getPixelColor(device, 160, 120); /* upper left quad */
333 ok(color == 0x00ff0000, "Clear rectangle 1(pos, pos) has color %08x\n", color);
334 color = getPixelColor(device, 480, 360); /* lower right quad */
335 ok(color == 0x00ffffff, "Clear rectangle 4(NULL) has color %08x\n", color);
336 color = getPixelColor(device, 480, 120); /* upper right quad */
337 ok(color == 0x00ffffff, "Clear rectangle 4(neg, neg) has color %08x\n", color);
339 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
354 static void fog_test(IDirect3DDevice8 *device)
358 float start = 0.0, end = 1.0;
360 /* Gets full z based fog with linear fog, no fog with specular color */
361 struct sVertex untransformed_1[] = {
362 {-1, -1, 0.1f, 0xFFFF0000, 0xFF000000 },
363 {-1, 0, 0.1f, 0xFFFF0000, 0xFF000000 },
364 { 0, 0, 0.1f, 0xFFFF0000, 0xFF000000 },
365 { 0, -1, 0.1f, 0xFFFF0000, 0xFF000000 },
367 /* Ok, I am too lazy to deal with transform matrices */
368 struct sVertex untransformed_2[] = {
369 {-1, 0, 1.0f, 0xFFFF0000, 0xFF000000 },
370 {-1, 1, 1.0f, 0xFFFF0000, 0xFF000000 },
371 { 0, 1, 1.0f, 0xFFFF0000, 0xFF000000 },
372 { 0, 0, 1.0f, 0xFFFF0000, 0xFF000000 },
374 /* Untransformed ones. Give them a different diffuse color to make the test look
375 * nicer. It also makes making sure that they are drawn correctly easier.
377 struct sVertexT transformed_1[] = {
378 {320, 0, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
379 {640, 0, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
380 {640, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
381 {320, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
383 struct sVertexT transformed_2[] = {
384 {320, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
385 {640, 240, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
386 {640, 480, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
387 {320, 480, 1.0f, 1.0f, 0xFFFFFF00, 0xFF000000 },
389 WORD Indices[] = {0, 1, 2, 2, 3, 0};
392 float ident_mat[16] =
394 1.0f, 0.0f, 0.0f, 0.0f,
395 0.0f, 1.0f, 0.0f, 0.0f,
396 0.0f, 0.0f, 1.0f, 0.0f,
397 0.0f, 0.0f, 0.0f, 1.0f
399 float world_mat1[16] =
401 1.0f, 0.0f, 0.0f, 0.0f,
402 0.0f, 1.0f, 0.0f, 0.0f,
403 0.0f, 0.0f, 1.0f, 0.0f,
404 0.0f, 0.0f, -0.5f, 1.0f
406 float world_mat2[16] =
408 1.0f, 0.0f, 0.0f, 0.0f,
409 0.0f, 1.0f, 0.0f, 0.0f,
410 0.0f, 0.0f, 1.0f, 0.0f,
411 0.0f, 0.0f, 1.0f, 1.0f
415 1.0f, 0.0f, 0.0f, 0.0f,
416 0.0f, 1.0f, 0.0f, 0.0f,
417 0.0f, 0.0f, 1.0f, 0.0f,
418 0.0f, 0.0f, -1.0f, 1.0f
421 struct sVertex far_quad1[] =
423 {-1.0f, -1.0f, 0.5f, 0xffff0000, 0xff000000},
424 {-1.0f, 0.0f, 0.5f, 0xffff0000, 0xff000000},
425 { 0.0f, 0.0f, 0.5f, 0xffff0000, 0xff000000},
426 { 0.0f, -1.0f, 0.5f, 0xffff0000, 0xff000000},
428 struct sVertex far_quad2[] =
430 {-1.0f, 0.0f, 1.5f, 0xffff0000, 0xff000000},
431 {-1.0f, 1.0f, 1.5f, 0xffff0000, 0xff000000},
432 { 0.0f, 1.0f, 1.5f, 0xffff0000, 0xff000000},
433 { 0.0f, 0.0f, 1.5f, 0xffff0000, 0xff000000},
436 memset(&caps, 0, sizeof(caps));
437 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
438 ok(hr == D3D_OK, "IDirect3DDevice8_GetDeviceCaps returned %08x\n", hr);
440 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
441 ok(hr == D3D_OK, "IDirect3DDevice8_Clear returned %#08x\n", hr);
443 /* Setup initial states: No lighting, fog on, fog color */
444 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
445 ok(hr == D3D_OK, "Turning off lighting returned %#08x\n", hr);
446 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGENABLE, TRUE);
447 ok(hr == D3D_OK, "Turning on fog calculations returned %#08x\n", hr);
448 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGCOLOR, 0xFF00FF00 /* A nice green */);
449 ok(hr == D3D_OK, "Setting fog color returned %#08x\n", hr);
451 /* First test: Both table fog and vertex fog off */
452 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_NONE);
453 ok(hr == D3D_OK, "Turning off table fog returned %#08x\n", hr);
454 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGVERTEXMODE, D3DFOG_NONE);
455 ok(hr == D3D_OK, "Turning off vertex fog returned %#08x\n", hr);
457 /* Start = 0, end = 1. Should be default, but set them */
458 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGSTART, *((DWORD *) &start));
459 ok(hr == D3D_OK, "Setting fog start returned %#08x\n", hr);
460 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGEND, *((DWORD *) &end));
461 ok(hr == D3D_OK, "Setting fog start returned %#08x\n", hr);
463 if(IDirect3DDevice8_BeginScene(device) == D3D_OK)
465 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
466 ok( hr == D3D_OK, "SetVertexShader returned %#08x\n", hr);
467 /* Untransformed, vertex fog = NONE, table fog = NONE: Read the fog weighting from the specular color */
468 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
469 2 /*PrimCount */, Indices, D3DFMT_INDEX16, untransformed_1,
470 sizeof(untransformed_1[0]));
471 ok(hr == D3D_OK, "DrawIndexedPrimitiveUP returned %#08x\n", hr);
473 /* That makes it use the Z value */
474 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR);
475 ok(hr == D3D_OK, "Setting fog vertex mode to D3DFOG_LINEAR returned %#08x\n", hr);
476 /* Untransformed, vertex fog != none (or table fog != none):
477 * Use the Z value as input into the equation
479 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
480 2 /*PrimCount */, Indices, D3DFMT_INDEX16, untransformed_2,
481 sizeof(untransformed_2[0]));
482 ok(hr == D3D_OK, "DrawIndexedPrimitiveUP returned %#08x\n", hr);
484 /* transformed verts */
485 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
486 ok( hr == D3D_OK, "SetVertexShader returned %#08x\n", hr);
487 /* Transformed, vertex fog != NONE, pixel fog == NONE: Use specular color alpha component */
488 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
489 2 /*PrimCount */, Indices, D3DFMT_INDEX16, transformed_1,
490 sizeof(transformed_1[0]));
491 ok(hr == D3D_OK, "DrawIndexedPrimitiveUP returned %#08x\n", hr);
493 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);
494 ok( hr == D3D_OK, "Setting fog table mode to D3DFOG_LINEAR returned %#08x\n", hr);
495 /* Transformed, table fog != none, vertex anything: Use Z value as input to the fog
498 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
499 2 /*PrimCount */, Indices, D3DFMT_INDEX16, transformed_2,
500 sizeof(transformed_2[0]));
501 ok(SUCCEEDED(hr), "IDirect3DDevice8_DrawIndexedPrimitiveUP returned %#x.\n", hr);
503 hr = IDirect3DDevice8_EndScene(device);
504 ok(hr == D3D_OK, "EndScene returned %#08x\n", hr);
508 ok(FALSE, "BeginScene failed\n");
511 color = getPixelColor(device, 160, 360);
512 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xFF, 0x00, 0x00), 1),
513 "Untransformed vertex with no table or vertex fog has color %08x\n", color);
514 color = getPixelColor(device, 160, 120);
515 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xFF, 0x00), 1),
516 "Untransformed vertex with linear vertex fog has color %08x\n", color);
517 color = getPixelColor(device, 480, 120);
518 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xFF, 0xFF, 0x00), 1),
519 "Transformed vertex with linear vertex fog has color %08x\n", color);
520 color = getPixelColor(device, 480, 360);
521 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xFF, 0x00), 1),
522 "Transformed vertex with linear table fog has color %08x\n", color);
524 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
526 if (caps.RasterCaps & D3DPRASTERCAPS_FOGTABLE)
528 /* A simple fog + non-identity world matrix test */
529 hr = IDirect3DDevice8_SetTransform(device, D3DTS_WORLDMATRIX(0), (D3DMATRIX *) world_mat1);
530 ok(hr == D3D_OK, "IDirect3DDevice8_SetTransform returned %#08x\n", hr);
532 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);
533 ok(hr == D3D_OK, "Setting fog table mode to D3DFOG_LINEAR returned %#08x\n", hr);
534 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGVERTEXMODE, D3DFOG_NONE);
535 ok(hr == D3D_OK, "Turning off vertex fog returned %#08x\n", hr);
537 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
538 ok(hr == D3D_OK, "IDirect3DDevice8_Clear returned %#08x\n", hr);
540 if (IDirect3DDevice8_BeginScene(device) == D3D_OK)
542 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
543 ok(hr == D3D_OK, "SetVertexShader returned %#08x\n", hr);
545 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4,
546 2, Indices, D3DFMT_INDEX16, far_quad1, sizeof(far_quad1[0]));
547 ok(hr == D3D_OK, "DrawIndexedPrimitiveUP returned %#08x\n", hr);
549 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4,
550 2, Indices, D3DFMT_INDEX16, far_quad2, sizeof(far_quad2[0]));
551 ok(hr == D3D_OK, "DrawIndexedPrimitiveUP returned %#08x\n", hr);
553 hr = IDirect3DDevice8_EndScene(device);
554 ok(hr == D3D_OK, "EndScene returned %#08x\n", hr);
558 ok(FALSE, "BeginScene failed\n");
561 color = getPixelColor(device, 160, 360);
562 ok(color_match(color, 0x00ff0000, 4), "Unfogged quad has color %08x\n", color);
563 color = getPixelColor(device, 160, 120);
564 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1),
565 "Fogged out quad has color %08x\n", color);
567 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
569 /* Test fog behavior with an orthogonal (but not identity) projection matrix */
570 hr = IDirect3DDevice8_SetTransform(device, D3DTS_WORLDMATRIX(0), (D3DMATRIX *) world_mat2);
571 ok(hr == D3D_OK, "SetTransform returned %#08x\n", hr);
572 hr = IDirect3DDevice8_SetTransform(device, D3DTS_PROJECTION, (D3DMATRIX *) proj_mat);
573 ok(hr == D3D_OK, "SetTransform returned %#08x\n", hr);
575 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
576 ok(hr == D3D_OK, "Clear returned %#08x\n", hr);
578 if (IDirect3DDevice8_BeginScene(device) == D3D_OK)
580 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
581 ok(hr == D3D_OK, "SetVertexShader returned %#08x\n", hr);
583 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4,
584 2, Indices, D3DFMT_INDEX16, untransformed_1, sizeof(untransformed_1[0]));
585 ok(hr == D3D_OK, "DrawIndexedPrimitiveUP returned %#08x\n", hr);
587 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4,
588 2, Indices, D3DFMT_INDEX16, untransformed_2, sizeof(untransformed_2[0]));
589 ok(hr == D3D_OK, "DrawIndexedPrimitiveUP returned %#08x\n", hr);
591 hr = IDirect3DDevice8_EndScene(device);
592 ok(hr == D3D_OK, "EndScene returned %#08x\n", hr);
596 ok(FALSE, "BeginScene failed\n");
599 color = getPixelColor(device, 160, 360);
600 todo_wine ok(color_match(color, 0x00e51900, 4), "Partially fogged quad has color %08x\n", color);
601 color = getPixelColor(device, 160, 120);
602 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1),
603 "Fogged out quad has color %08x\n", color);
605 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
607 hr = IDirect3DDevice8_SetTransform(device, D3DTS_WORLDMATRIX(0), (D3DMATRIX *) ident_mat);
608 ok(hr == D3D_OK, "SetTransform returned %#08x\n", hr);
609 hr = IDirect3DDevice8_SetTransform(device, D3DTS_PROJECTION, (D3DMATRIX *) ident_mat);
610 ok(hr == D3D_OK, "SetTransform returned %#08x\n", hr);
614 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests\n");
617 /* Turn off the fog master switch to avoid confusing other tests */
618 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_FOGENABLE, FALSE);
619 ok(hr == D3D_OK, "Turning off fog calculations returned %#08x\n", hr);
622 static void present_test(IDirect3DDevice8 *device)
624 struct vertex quad[] =
626 {-1.0f, -1.0f, 0.9f, 0xffff0000},
627 {-1.0f, 1.0f, 0.9f, 0xffff0000},
628 { 1.0f, -1.0f, 0.1f, 0xffff0000},
629 { 1.0f, 1.0f, 0.1f, 0xffff0000},
634 /* Does the Present clear the depth stencil? Clear the depth buffer with some value != 0,
635 * then call Present. Then clear the color buffer to make sure it has some defined content
636 * after the Present with D3DSWAPEFFECT_DISCARD. After that draw a plane that is somewhere cut
637 * by the depth value.
639 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 0.75, 0);
640 ok(hr == D3D_OK, "IDirect3DDevice8_Clear returned %08x\n", hr);
641 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
642 ok(SUCCEEDED(hr), "IDirect3DDevice8_Present returned %#x.\n", hr);
643 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.4f, 0);
644 ok(SUCCEEDED(hr), "IDirect3DDevice8_Clear returned %#x.\n", hr);
646 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
647 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %08x\n", hr);
648 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_GREATER);
649 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %08x\n", hr);
650 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
651 ok(hr == D3D_OK, "IDirect3DDevice8_SetFVF returned %08x\n", hr);
653 hr = IDirect3DDevice8_BeginScene(device);
654 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %08x\n", hr);
657 /* No lights are defined... That means, lit vertices should be entirely black */
658 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2 /*PrimCount */, quad, sizeof(quad[0]));
659 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %08x\n", hr);
661 hr = IDirect3DDevice8_EndScene(device);
662 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %08x\n", hr);
665 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
666 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %08x\n", hr);
668 color = getPixelColor(device, 512, 240);
669 ok(color == 0x00ffffff, "Present failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
670 color = getPixelColor(device, 64, 240);
671 ok(color == 0x00ff0000, "Present failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
673 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
674 ok(SUCCEEDED(hr), "Present failed (%#08x)\n", hr);
677 static void test_rcp_rsq(IDirect3DDevice8 *device)
682 float constant[4] = {1.0, 1.0, 1.0, 2.0};
684 static const float quad[][3] = {
685 {-1.0f, -1.0f, 0.0f},
687 { 1.0f, -1.0f, 0.0f},
691 const DWORD rcp_test[] = {
692 0xfffe0101, /* vs.1.1 */
694 0x0009fffe, 0x30303030, 0x30303030, /* Shaders have to have a minimal size. */
695 0x30303030, 0x30303030, 0x30303030, /* Add a filler comment. Usually D3DX8's*/
696 0x30303030, 0x30303030, 0x30303030, /* version comment makes the shader big */
697 0x00303030, /* enough to make windows happy */
699 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
700 0x00000006, 0xd00f0000, 0xa0e40000, /* rcp oD0, c0 */
704 const DWORD rsq_test[] = {
705 0xfffe0101, /* vs.1.1 */
707 0x0009fffe, 0x30303030, 0x30303030, /* Shaders have to have a minimal size. */
708 0x30303030, 0x30303030, 0x30303030, /* Add a filler comment. Usually D3DX8's*/
709 0x30303030, 0x30303030, 0x30303030, /* version comment makes the shader big */
710 0x00303030, /* enough to make windows happy */
712 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
713 0x00000007, 0xd00f0000, 0xa0e40000, /* rsq oD0, c0 */
720 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
724 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff336699, 0.0f, 0);
725 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
727 hr = IDirect3DDevice8_CreateVertexShader(device, decl, rcp_test, &shader, 0);
728 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned with %#08x\n", hr);
730 IDirect3DDevice8_SetVertexShader(device, shader);
731 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
732 IDirect3DDevice8_SetVertexShaderConstant(device, 0, constant, 1);
734 hr = IDirect3DDevice8_BeginScene(device);
735 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene returned %#08x\n", hr);
738 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], 3 * sizeof(float));
739 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%#08x)\n", hr);
740 hr = IDirect3DDevice8_EndScene(device);
741 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
744 color = getPixelColor(device, 320, 240);
745 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x80, 0x80, 0x80), 4),
746 "RCP test returned color 0x%08x, expected 0x00808080.\n", color);
748 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
749 ok(SUCCEEDED(hr), "Present failed (%#08x)\n", hr);
751 IDirect3DDevice8_SetVertexShader(device, 0);
752 IDirect3DDevice8_DeleteVertexShader(device, shader);
754 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff996633, 0.0f, 0);
755 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed with %#08x\n", hr);
757 hr = IDirect3DDevice8_CreateVertexShader(device, decl, rsq_test, &shader, 0);
758 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned with %#08x\n", hr);
760 IDirect3DDevice8_SetVertexShader(device, shader);
761 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
762 IDirect3DDevice8_SetVertexShaderConstant(device, 0, constant, 1);
764 hr = IDirect3DDevice8_BeginScene(device);
765 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene returned %#08x\n", hr);
768 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], 3 * sizeof(float));
769 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%#08x)\n", hr);
770 hr = IDirect3DDevice8_EndScene(device);
771 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
774 color = getPixelColor(device, 320, 240);
775 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xb4, 0xb4, 0xb4), 4),
776 "RSQ test returned color 0x%08x, expected 0x00b4b4b4.\n", color);
778 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
779 ok(SUCCEEDED(hr), "Present failed (%#08x)\n", hr);
781 IDirect3DDevice8_SetVertexShader(device, 0);
782 IDirect3DDevice8_DeleteVertexShader(device, shader);
785 static void offscreen_test(IDirect3DDevice8 *device)
788 IDirect3DTexture8 *offscreenTexture = NULL;
789 IDirect3DSurface8 *backbuffer = NULL, *offscreen = NULL, *depthstencil = NULL;
792 static const float quad[][5] = {
793 {-0.5f, -0.5f, 0.1f, 0.0f, 0.0f},
794 {-0.5f, 0.5f, 0.1f, 0.0f, 1.0f},
795 { 0.5f, -0.5f, 0.1f, 1.0f, 0.0f},
796 { 0.5f, 0.5f, 0.1f, 1.0f, 1.0f},
799 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &depthstencil);
800 ok(hr == D3D_OK, "IDirect3DDevice8_GetDepthStencilSurface failed, hr = %#08x\n", hr);
802 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
803 ok(hr == D3D_OK, "Clear failed, hr = %#08x\n", hr);
805 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &offscreenTexture);
806 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Creating the offscreen render target failed, hr = %#08x\n", hr);
807 if(!offscreenTexture) {
808 trace("Failed to create an X8R8G8B8 offscreen texture, trying R5G6B5\n");
809 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET, D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &offscreenTexture);
810 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Creating the offscreen render target failed, hr = %#08x\n", hr);
811 if(!offscreenTexture) {
812 skip("Cannot create an offscreen render target\n");
817 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
818 ok(hr == D3D_OK, "Can't get back buffer, hr = %#08x\n", hr);
823 hr = IDirect3DTexture8_GetSurfaceLevel(offscreenTexture, 0, &offscreen);
824 ok(hr == D3D_OK, "Can't get offscreen surface, hr = %#08x\n", hr);
829 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_TEX1);
830 ok(hr == D3D_OK, "SetVertexShader failed, hr = %#08x\n", hr);
832 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
833 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %#08x\n", hr);
834 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
835 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %#08x\n", hr);
836 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MINFILTER, D3DTEXF_NONE);
837 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MINFILTER failed (%#08x)\n", hr);
838 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MAGFILTER, D3DTEXF_NONE);
839 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MAGFILTER failed (%#08x)\n", hr);
840 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
841 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %08x\n", hr);
843 if(IDirect3DDevice8_BeginScene(device) == D3D_OK) {
844 hr = IDirect3DDevice8_SetRenderTarget(device, offscreen, depthstencil);
845 ok(hr == D3D_OK, "SetRenderTarget failed, hr = %#08x\n", hr);
846 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
847 ok(hr == D3D_OK, "Clear failed, hr = %#08x\n", hr);
849 /* Draw without textures - Should result in a white quad */
850 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
851 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
853 hr = IDirect3DDevice8_SetRenderTarget(device, backbuffer, depthstencil);
854 ok(hr == D3D_OK, "SetRenderTarget failed, hr = %#08x\n", hr);
855 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) offscreenTexture);
856 ok(hr == D3D_OK, "SetTexture failed, %08x\n", hr);
858 /* This time with the texture */
859 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
860 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
862 IDirect3DDevice8_EndScene(device);
865 /* Center quad - should be white */
866 color = getPixelColor(device, 320, 240);
867 ok(color == 0x00ffffff, "Offscreen failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
868 /* Some quad in the cleared part of the texture */
869 color = getPixelColor(device, 170, 240);
870 ok(color == 0x00ff00ff, "Offscreen failed: Got color 0x%08x, expected 0x00ff00ff.\n", color);
871 /* Part of the originally cleared back buffer */
872 color = getPixelColor(device, 10, 10);
873 ok(color == 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
875 /* Lower left corner of the screen, where back buffer offscreen rendering draws the offscreen texture.
876 * It should be red, but the offscreen texture may leave some junk there. Not tested yet. Depending on
877 * the offscreen rendering mode this test would succeed or fail
879 color = getPixelColor(device, 10, 470);
880 ok(color == 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
883 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
886 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
887 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetTexture returned %#x.\n", hr);
891 hr = IDirect3DDevice8_SetRenderTarget(device, backbuffer, depthstencil);
892 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetRenderTarget returned %#x.\n", hr);
893 IDirect3DSurface8_Release(backbuffer);
895 if(offscreenTexture) {
896 IDirect3DTexture8_Release(offscreenTexture);
899 IDirect3DSurface8_Release(offscreen);
902 IDirect3DSurface8_Release(depthstencil);
906 static void alpha_test(IDirect3DDevice8 *device)
909 IDirect3DTexture8 *offscreenTexture;
910 IDirect3DSurface8 *backbuffer = NULL, *offscreen = NULL, *depthstencil = NULL;
913 struct vertex quad1[] =
915 {-1.0f, -1.0f, 0.1f, 0x4000ff00},
916 {-1.0f, 0.0f, 0.1f, 0x4000ff00},
917 { 1.0f, -1.0f, 0.1f, 0x4000ff00},
918 { 1.0f, 0.0f, 0.1f, 0x4000ff00},
920 struct vertex quad2[] =
922 {-1.0f, 0.0f, 0.1f, 0xc00000ff},
923 {-1.0f, 1.0f, 0.1f, 0xc00000ff},
924 { 1.0f, 0.0f, 0.1f, 0xc00000ff},
925 { 1.0f, 1.0f, 0.1f, 0xc00000ff},
927 static const float composite_quad[][5] = {
928 { 0.0f, -1.0f, 0.1f, 0.0f, 1.0f},
929 { 0.0f, 1.0f, 0.1f, 0.0f, 0.0f},
930 { 1.0f, -1.0f, 0.1f, 1.0f, 1.0f},
931 { 1.0f, 1.0f, 0.1f, 1.0f, 0.0f},
934 /* Clear the render target with alpha = 0.5 */
935 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x80ff0000, 0.0, 0);
936 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
938 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &offscreenTexture);
939 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Creating the offscreen render target failed, hr = %#08x\n", hr);
941 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &depthstencil);
942 ok(hr == D3D_OK, "IDirect3DDevice8_GetDepthStencilSurface failed, hr = %#08x\n", hr);
944 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
945 ok(hr == D3D_OK, "Can't get back buffer, hr = %#08x\n", hr);
949 hr = IDirect3DTexture8_GetSurfaceLevel(offscreenTexture, 0, &offscreen);
950 ok(hr == D3D_OK, "Can't get offscreen surface, hr = %#08x\n", hr);
955 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
956 ok(hr == D3D_OK, "SetVertexShader failed, hr = %#08x\n", hr);
958 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
959 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %#08x\n", hr);
960 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
961 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %#08x\n", hr);
962 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MINFILTER, D3DTEXF_NONE);
963 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MINFILTER failed (%#08x)\n", hr);
964 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MAGFILTER, D3DTEXF_NONE);
965 ok(SUCCEEDED(hr), "SetTextureStageState D3DSAMP_MAGFILTER failed (%#08x)\n", hr);
966 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
967 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState returned %08x\n", hr);
969 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, TRUE);
970 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
971 if(IDirect3DDevice8_BeginScene(device) == D3D_OK) {
973 /* Draw two quads, one with src alpha blending, one with dest alpha blending. */
974 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
975 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
976 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
977 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
978 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(quad1[0]));
979 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
981 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_DESTALPHA);
982 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
983 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVDESTALPHA);
984 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
985 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(quad2[0]));
986 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
988 /* Switch to the offscreen buffer, and redo the testing. The offscreen render target
989 * doesn't have an alpha channel. DESTALPHA and INVDESTALPHA "don't work" on render
990 * targets without alpha channel, they give essentially ZERO and ONE blend factors. */
991 hr = IDirect3DDevice8_SetRenderTarget(device, offscreen, 0);
992 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
993 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x80ff0000, 0.0, 0);
994 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
996 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
997 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
998 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
999 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1000 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(quad1[0]));
1001 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
1003 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_DESTALPHA);
1004 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1005 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVDESTALPHA);
1006 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1007 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(quad2[0]));
1008 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
1010 hr = IDirect3DDevice8_SetRenderTarget(device, backbuffer, depthstencil);
1011 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
1013 /* Render the offscreen texture onto the frame buffer to be able to compare it regularly.
1014 * Disable alpha blending for the final composition
1016 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, FALSE);
1017 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1018 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_TEX1);
1019 ok(hr == D3D_OK, "SetVertexShader failed, hr = %#08x\n", hr);
1021 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) offscreenTexture);
1022 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
1023 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, composite_quad, sizeof(float) * 5);
1024 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr = %#08x\n", hr);
1025 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
1026 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
1028 hr = IDirect3DDevice8_EndScene(device);
1029 ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed, hr = %08x\n", hr);
1032 color = getPixelColor(device, 160, 360);
1033 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xbf, 0x40, 0x00), 1),
1034 "SRCALPHA on frame buffer returned color %08x, expected 0x00bf4000\n", color);
1036 color = getPixelColor(device, 160, 120);
1037 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x7f, 0x00, 0x80), 2),
1038 "DSTALPHA on frame buffer returned color %08x, expected 0x007f0080\n", color);
1040 color = getPixelColor(device, 480, 360);
1041 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xbf, 0x40, 0x00), 1),
1042 "SRCALPHA on texture returned color %08x, expected 0x00bf4000\n", color);
1044 color = getPixelColor(device, 480, 120);
1045 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0xff), 1),
1046 "DSTALPHA on texture returned color %08x, expected 0x000000ff\n", color);
1048 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1051 /* restore things */
1053 IDirect3DSurface8_Release(backbuffer);
1055 if(offscreenTexture) {
1056 IDirect3DTexture8_Release(offscreenTexture);
1059 IDirect3DSurface8_Release(offscreen);
1062 IDirect3DSurface8_Release(depthstencil);
1066 static void p8_texture_test(IDirect3DDevice8 *device)
1068 IDirect3D8 *d3d = NULL;
1070 IDirect3DTexture8 *texture = NULL, *texture2 = NULL;
1072 unsigned char *data;
1073 DWORD color, red, green, blue;
1074 PALETTEENTRY table[256];
1078 -1.0f, 0.0f, 0.1f, 0.0f, 0.0f,
1079 -1.0f, 1.0f, 0.1f, 0.0f, 1.0f,
1080 1.0f, 0.0f, 0.1f, 1.0f, 0.0f,
1081 1.0f, 1.0f, 0.1f, 1.0f, 1.0f,
1084 -1.0f, -1.0f, 0.1f, 0.0f, 0.0f,
1085 -1.0f, 0.0f, 0.1f, 0.0f, 1.0f,
1086 1.0f, -1.0f, 0.1f, 1.0f, 0.0f,
1087 1.0f, 0.0f, 0.1f, 1.0f, 1.0f,
1090 IDirect3DDevice8_GetDirect3D(device, &d3d);
1092 if(IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, 0,
1093 D3DRTYPE_TEXTURE, D3DFMT_P8) != D3D_OK) {
1094 skip("D3DFMT_P8 textures not supported\n");
1098 hr = IDirect3DDevice8_CreateTexture(device, 1, 1, 1, 0, D3DFMT_P8,
1099 D3DPOOL_MANAGED, &texture2);
1100 ok(hr == D3D_OK, "IDirect3DDevice8_CreateTexture failed, hr = %08x\n", hr);
1102 skip("Failed to create D3DFMT_P8 texture\n");
1106 memset(&lr, 0, sizeof(lr));
1107 hr = IDirect3DTexture8_LockRect(texture2, 0, &lr, NULL, 0);
1108 ok(hr == D3D_OK, "IDirect3DTexture8_LockRect failed, hr = %08x\n", hr);
1112 hr = IDirect3DTexture8_UnlockRect(texture2, 0);
1113 ok(hr == D3D_OK, "IDirect3DTexture8_UnlockRect failed, hr = %08x\n", hr);
1115 hr = IDirect3DDevice8_CreateTexture(device, 1, 1, 1, 0, D3DFMT_P8,
1116 D3DPOOL_MANAGED, &texture);
1117 ok(hr == D3D_OK, "IDirect3DDevice8_CreateTexture failed, hr = %08x\n", hr);
1119 skip("Failed to create D3DFMT_P8 texture\n");
1123 memset(&lr, 0, sizeof(lr));
1124 hr = IDirect3DTexture8_LockRect(texture, 0, &lr, NULL, 0);
1125 ok(hr == D3D_OK, "IDirect3DTexture8_LockRect failed, hr = %08x\n", hr);
1129 hr = IDirect3DTexture8_UnlockRect(texture, 0);
1130 ok(hr == D3D_OK, "IDirect3DTexture8_UnlockRect failed, hr = %08x\n", hr);
1132 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff000000, 0.0, 0);
1133 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed, hr = %08x\n", hr);
1135 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, TRUE);
1136 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1138 /* The first part of the test should work both with and without D3DPTEXTURECAPS_ALPHAPALETTE;
1139 alpha of every entry is set to 1.0, which MS says is required when there's no
1140 D3DPTEXTURECAPS_ALPHAPALETTE capability */
1141 for (i = 0; i < 256; i++) {
1142 table[i].peRed = table[i].peGreen = table[i].peBlue = 0;
1143 table[i].peFlags = 0xff;
1145 table[1].peRed = 0xff;
1146 hr = IDirect3DDevice8_SetPaletteEntries(device, 0, table);
1147 ok(hr == D3D_OK, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr);
1150 table[1].peBlue = 0xff;
1151 hr = IDirect3DDevice8_SetPaletteEntries(device, 1, table);
1152 ok(hr == D3D_OK, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr);
1154 hr = IDirect3DDevice8_BeginScene(device);
1155 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed, hr = %08x\n", hr);
1157 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
1158 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1159 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
1160 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1162 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_TEX1);
1163 ok(hr == D3D_OK, "SetVertexShader failed, hr = %#08x\n", hr);
1165 hr = IDirect3DDevice8_SetCurrentTexturePalette(device, 0);
1166 ok(hr == D3D_OK, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr);
1168 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) texture2);
1169 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
1170 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
1171 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1173 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) texture);
1174 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
1175 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
1176 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1178 hr = IDirect3DDevice8_SetCurrentTexturePalette(device, 1);
1179 ok(hr == D3D_OK, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr);
1180 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 5 * sizeof(float));
1181 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1183 hr = IDirect3DDevice8_EndScene(device);
1184 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed, hr = %08x\n", hr);
1187 color = getPixelColor(device, 32, 32);
1188 red = (color & 0x00ff0000) >> 16;
1189 green = (color & 0x0000ff00) >> 8;
1190 blue = (color & 0x000000ff) >> 0;
1191 ok(red == 0xff && blue == 0 && green == 0,
1192 "got color %08x, expected 0x00ff0000\n", color);
1194 color = getPixelColor(device, 32, 320);
1195 red = (color & 0x00ff0000) >> 16;
1196 green = (color & 0x0000ff00) >> 8;
1197 blue = (color & 0x000000ff) >> 0;
1198 ok(red == 0 && blue == 0xff && green == 0,
1199 "got color %08x, expected 0x000000ff\n", color);
1201 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1202 ok(hr == D3D_OK, "IDirect3DDevice8_Present failed, hr = %08x\n", hr);
1204 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff000000, 0.0, 0);
1205 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed, hr = %08x\n", hr);
1207 hr = IDirect3DDevice8_BeginScene(device);
1208 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed, hr = %08x\n", hr);
1210 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) texture2);
1211 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
1213 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
1214 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1216 hr = IDirect3DDevice8_EndScene(device);
1217 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed, hr = %08x\n", hr);
1221 color = getPixelColor(device, 32, 32);
1222 red = (color & 0x00ff0000) >> 16;
1223 green = (color & 0x0000ff00) >> 8;
1224 blue = (color & 0x000000ff) >> 0;
1225 ok(red == 0 && blue == 0xff && green == 0,
1226 "got color %08x, expected 0x000000ff\n", color);
1228 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1229 ok(hr == D3D_OK, "IDirect3DDevice8_Present failed, hr = %08x\n", hr);
1231 /* Test palettes with alpha */
1232 IDirect3DDevice8_GetDeviceCaps(device, &caps);
1233 if (!(caps.TextureCaps & D3DPTEXTURECAPS_ALPHAPALETTE)) {
1234 skip("no D3DPTEXTURECAPS_ALPHAPALETTE capability, tests with alpha in palette will be skipped\n");
1236 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff000000, 0.0, 0);
1237 ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed, hr = %08x\n", hr);
1239 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, TRUE);
1240 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1242 for (i = 0; i < 256; i++) {
1243 table[i].peRed = table[i].peGreen = table[i].peBlue = 0;
1244 table[i].peFlags = 0xff;
1246 table[1].peRed = 0xff;
1247 table[1].peFlags = 0x80;
1248 hr = IDirect3DDevice8_SetPaletteEntries(device, 0, table);
1249 ok(hr == D3D_OK, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr);
1252 table[1].peBlue = 0xff;
1253 table[1].peFlags = 0x80;
1254 hr = IDirect3DDevice8_SetPaletteEntries(device, 1, table);
1255 ok(hr == D3D_OK, "IDirect3DDevice8_SetPaletteEntries failed, hr = %08x\n", hr);
1257 hr = IDirect3DDevice8_BeginScene(device);
1258 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed, hr = %08x\n", hr);
1260 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
1261 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1262 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
1263 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1265 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_TEX1);
1266 ok(hr == D3D_OK, "SetVertexShader failed, hr = %#08x\n", hr);
1268 hr = IDirect3DDevice8_SetCurrentTexturePalette(device, 0);
1269 ok(hr == D3D_OK, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr);
1271 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
1272 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1274 hr = IDirect3DDevice8_SetCurrentTexturePalette(device, 1);
1275 ok(hr == D3D_OK, "IDirect3DDevice8_SetCurrentTexturePalette failed, hr = %08x\n", hr);
1277 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 5 * sizeof(float));
1278 ok(hr == D3D_OK, "IDirect3DDevice8_DrawPrimitiveUP failed, hr = %08x\n", hr);
1280 hr = IDirect3DDevice8_EndScene(device);
1281 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed, hr = %08x\n", hr);
1284 color = getPixelColor(device, 32, 32);
1285 red = (color & 0x00ff0000) >> 16;
1286 green = (color & 0x0000ff00) >> 8;
1287 blue = (color & 0x000000ff) >> 0;
1288 ok(red >= 0x7e && red <= 0x81 && blue == 0 && green == 0,
1289 "got color %08x, expected 0x00800000 or near\n", color);
1291 color = getPixelColor(device, 32, 320);
1292 red = (color & 0x00ff0000) >> 16;
1293 green = (color & 0x0000ff00) >> 8;
1294 blue = (color & 0x000000ff) >> 0;
1295 ok(red == 0 && blue >= 0x7e && blue <= 0x81 && green == 0,
1296 "got color %08x, expected 0x00000080 or near\n", color);
1298 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1299 ok(hr == D3D_OK, "IDirect3DDevice8_Present failed, hr = %08x\n", hr);
1302 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
1303 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture failed, hr = %08x\n", hr);
1304 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ALPHABLENDENABLE, FALSE);
1305 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState failed, hr = %08x\n", hr);
1308 if(texture) IDirect3DTexture8_Release(texture);
1309 if(texture2) IDirect3DTexture8_Release(texture2);
1310 IDirect3D8_Release(d3d);
1313 static void texop_test(IDirect3DDevice8 *device)
1315 IDirect3DTexture8 *texture = NULL;
1316 D3DLOCKED_RECT locked_rect;
1322 static const struct {
1327 {-1.0f, -1.0f, 0.1f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), -1.0f, -1.0f},
1328 {-1.0f, 1.0f, 0.1f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), -1.0f, 1.0f},
1329 { 1.0f, -1.0f, 0.1f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), 1.0f, -1.0f},
1330 { 1.0f, 1.0f, 0.1f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00), 1.0f, 1.0f}
1333 static const struct {
1339 {D3DTOP_SELECTARG1, "SELECTARG1", D3DTEXOPCAPS_SELECTARG1, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00)},
1340 {D3DTOP_SELECTARG2, "SELECTARG2", D3DTEXOPCAPS_SELECTARG2, D3DCOLOR_ARGB(0x00, 0x33, 0x33, 0x33)},
1341 {D3DTOP_MODULATE, "MODULATE", D3DTEXOPCAPS_MODULATE, D3DCOLOR_ARGB(0x00, 0x00, 0x33, 0x00)},
1342 {D3DTOP_MODULATE2X, "MODULATE2X", D3DTEXOPCAPS_MODULATE2X, D3DCOLOR_ARGB(0x00, 0x00, 0x66, 0x00)},
1343 {D3DTOP_MODULATE4X, "MODULATE4X", D3DTEXOPCAPS_MODULATE4X, D3DCOLOR_ARGB(0x00, 0x00, 0xcc, 0x00)},
1344 {D3DTOP_ADD, "ADD", D3DTEXOPCAPS_ADD, D3DCOLOR_ARGB(0x00, 0x33, 0xff, 0x33)},
1346 {D3DTOP_ADDSIGNED, "ADDSIGNED", D3DTEXOPCAPS_ADDSIGNED, D3DCOLOR_ARGB(0x00, 0x00, 0xb2, 0x00)},
1347 {D3DTOP_ADDSIGNED2X, "ADDSIGNED2X", D3DTEXOPCAPS_ADDSIGNED2X, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00)},
1349 {D3DTOP_SUBTRACT, "SUBTRACT", D3DTEXOPCAPS_SUBTRACT, D3DCOLOR_ARGB(0x00, 0x00, 0xcc, 0x00)},
1350 {D3DTOP_ADDSMOOTH, "ADDSMOOTH", D3DTEXOPCAPS_ADDSMOOTH, D3DCOLOR_ARGB(0x00, 0x33, 0xff, 0x33)},
1351 {D3DTOP_BLENDDIFFUSEALPHA, "BLENDDIFFUSEALPHA", D3DTEXOPCAPS_BLENDDIFFUSEALPHA, D3DCOLOR_ARGB(0x00, 0x22, 0x77, 0x22)},
1352 {D3DTOP_BLENDTEXTUREALPHA, "BLENDTEXTUREALPHA", D3DTEXOPCAPS_BLENDTEXTUREALPHA, D3DCOLOR_ARGB(0x00, 0x14, 0xad, 0x14)},
1353 {D3DTOP_BLENDFACTORALPHA, "BLENDFACTORALPHA", D3DTEXOPCAPS_BLENDFACTORALPHA, D3DCOLOR_ARGB(0x00, 0x07, 0xe4, 0x07)},
1354 {D3DTOP_BLENDTEXTUREALPHAPM, "BLENDTEXTUREALPHAPM", D3DTEXOPCAPS_BLENDTEXTUREALPHAPM, D3DCOLOR_ARGB(0x00, 0x14, 0xff, 0x14)},
1355 {D3DTOP_BLENDCURRENTALPHA, "BLENDCURRENTALPHA", D3DTEXOPCAPS_BLENDCURRENTALPHA, D3DCOLOR_ARGB(0x00, 0x22, 0x77, 0x22)},
1356 {D3DTOP_MODULATEALPHA_ADDCOLOR, "MODULATEALPHA_ADDCOLOR", D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR, D3DCOLOR_ARGB(0x00, 0x1f, 0xff, 0x1f)},
1357 {D3DTOP_MODULATECOLOR_ADDALPHA, "MODULATECOLOR_ADDALPHA", D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA, D3DCOLOR_ARGB(0x00, 0x99, 0xcc, 0x99)},
1358 {D3DTOP_MODULATEINVALPHA_ADDCOLOR, "MODULATEINVALPHA_ADDCOLOR", D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR, D3DCOLOR_ARGB(0x00, 0x14, 0xff, 0x14)},
1359 {D3DTOP_MODULATEINVCOLOR_ADDALPHA, "MODULATEINVCOLOR_ADDALPHA", D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA, D3DCOLOR_ARGB(0x00, 0xcc, 0x99, 0xcc)},
1360 /* BUMPENVMAP & BUMPENVMAPLUMINANCE have their own tests */
1361 {D3DTOP_DOTPRODUCT3, "DOTPRODUCT2", D3DTEXOPCAPS_DOTPRODUCT3, D3DCOLOR_ARGB(0x00, 0x99, 0x99, 0x99)},
1362 {D3DTOP_MULTIPLYADD, "MULTIPLYADD", D3DTEXOPCAPS_MULTIPLYADD, D3DCOLOR_ARGB(0x00, 0xff, 0x33, 0x00)},
1363 {D3DTOP_LERP, "LERP", D3DTEXOPCAPS_LERP, D3DCOLOR_ARGB(0x00, 0x00, 0x33, 0x33)},
1366 memset(&caps, 0, sizeof(caps));
1367 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
1368 ok(SUCCEEDED(hr), "GetDeviceCaps failed with 0x%08x\n", hr);
1370 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX0);
1371 ok(SUCCEEDED(hr), "SetVertexShader failed with 0x%08x\n", hr);
1373 hr = IDirect3DDevice8_CreateTexture(device, 1, 1, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture);
1374 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateTexture failed with 0x%08x\n", hr);
1375 hr = IDirect3DTexture8_LockRect(texture, 0, &locked_rect, NULL, 0);
1376 ok(SUCCEEDED(hr), "LockRect failed with 0x%08x\n", hr);
1377 *((DWORD *)locked_rect.pBits) = D3DCOLOR_ARGB(0x99, 0x00, 0xff, 0x00);
1378 hr = IDirect3DTexture8_UnlockRect(texture, 0);
1379 ok(SUCCEEDED(hr), "LockRect failed with 0x%08x\n", hr);
1380 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *)texture);
1381 ok(SUCCEEDED(hr), "SetTexture failed with 0x%08x\n", hr);
1383 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLORARG0, D3DTA_DIFFUSE);
1384 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
1385 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
1386 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
1387 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
1388 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
1390 hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
1391 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
1393 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
1394 ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
1395 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0xdd333333);
1396 ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
1397 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA);
1398 ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
1400 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
1401 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
1403 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
1405 if (!(caps.TextureOpCaps & test_data[i].caps_flag))
1407 skip("tex operation %s not supported\n", test_data[i].name);
1411 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_COLOROP, test_data[i].op);
1412 ok(SUCCEEDED(hr), "SetTextureStageState (%s) failed with 0x%08x\n", test_data[i].name, hr);
1414 hr = IDirect3DDevice8_BeginScene(device);
1415 ok(SUCCEEDED(hr), "BeginScene failed with 0x%08x\n", hr);
1417 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
1418 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed with 0x%08x\n", hr);
1420 hr = IDirect3DDevice8_EndScene(device);
1421 ok(SUCCEEDED(hr), "EndScene failed with 0x%08x\n", hr);
1423 color = getPixelColor(device, 320, 240);
1424 ok(color_match(color, test_data[i].result, 3), "Operation %s returned color 0x%08x, expected 0x%08x\n",
1425 test_data[i].name, color, test_data[i].result);
1427 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1428 ok(SUCCEEDED(hr), "Present failed with 0x%08x\n", hr);
1430 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
1431 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
1434 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
1435 ok(SUCCEEDED(hr), "SetTexture failed with 0x%08x\n", hr);
1436 if (texture) IDirect3DTexture8_Release(texture);
1439 /* This test tests depth clamping / clipping behaviour:
1440 * - With software vertex processing, depth values are clamped to the
1441 * minimum / maximum z value when D3DRS_CLIPPING is disabled, and clipped
1442 * when D3DRS_CLIPPING is enabled. Pretransformed vertices behave the
1443 * same as regular vertices here.
1444 * - With hardware vertex processing, D3DRS_CLIPPING seems to be ignored.
1445 * Normal vertices are always clipped. Pretransformed vertices are
1446 * clipped when D3DPMISCCAPS_CLIPTLVERTS is set, clamped when it isn't.
1447 * - The viewport's MinZ/MaxZ is irrelevant for this.
1449 static void depth_clamp_test(IDirect3DDevice8 *device)
1451 const struct tvertex quad1[] =
1453 { 0.0f, 0.0f, 5.0f, 1.0f, 0xff002b7f},
1454 {640.0f, 0.0f, 5.0f, 1.0f, 0xff002b7f},
1455 { 0.0f, 480.0f, 5.0f, 1.0f, 0xff002b7f},
1456 {640.0f, 480.0f, 5.0f, 1.0f, 0xff002b7f},
1458 const struct tvertex quad2[] =
1460 { 0.0f, 300.0f, 10.0f, 1.0f, 0xfff9e814},
1461 {640.0f, 300.0f, 10.0f, 1.0f, 0xfff9e814},
1462 { 0.0f, 360.0f, 10.0f, 1.0f, 0xfff9e814},
1463 {640.0f, 360.0f, 10.0f, 1.0f, 0xfff9e814},
1465 const struct tvertex quad3[] =
1467 {112.0f, 108.0f, 5.0f, 1.0f, 0xffffffff},
1468 {208.0f, 108.0f, 5.0f, 1.0f, 0xffffffff},
1469 {112.0f, 204.0f, 5.0f, 1.0f, 0xffffffff},
1470 {208.0f, 204.0f, 5.0f, 1.0f, 0xffffffff},
1472 const struct tvertex quad4[] =
1474 { 42.0f, 41.0f, 10.0f, 1.0f, 0xffffffff},
1475 {112.0f, 41.0f, 10.0f, 1.0f, 0xffffffff},
1476 { 42.0f, 108.0f, 10.0f, 1.0f, 0xffffffff},
1477 {112.0f, 108.0f, 10.0f, 1.0f, 0xffffffff},
1479 const struct vertex quad5[] =
1481 { -0.5f, 0.5f, 10.0f, 0xff14f914},
1482 { 0.5f, 0.5f, 10.0f, 0xff14f914},
1483 { -0.5f, -0.5f, 10.0f, 0xff14f914},
1484 { 0.5f, -0.5f, 10.0f, 0xff14f914},
1486 const struct vertex quad6[] =
1488 { -1.0f, 0.5f, 10.0f, 0xfff91414},
1489 { 1.0f, 0.5f, 10.0f, 0xfff91414},
1490 { -1.0f, 0.25f, 10.0f, 0xfff91414},
1491 { 1.0f, 0.25f, 10.0f, 0xfff91414},
1506 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
1507 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
1509 hr = IDirect3DDevice8_SetViewport(device, &vp);
1510 ok(SUCCEEDED(hr), "SetViewport failed, hr %#x.\n", hr);
1512 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 1.0, 0);
1513 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
1515 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_CLIPPING, FALSE);
1516 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1517 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
1518 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1519 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
1520 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1521 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
1522 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1524 hr = IDirect3DDevice8_BeginScene(device);
1525 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
1527 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
1528 ok(SUCCEEDED(hr), "SetVertexSahder failed, hr %#x.\n", hr);
1530 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(*quad1));
1531 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
1532 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(*quad2));
1533 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
1535 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_CLIPPING, TRUE);
1536 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1538 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, sizeof(*quad3));
1539 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
1540 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, sizeof(*quad4));
1541 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
1543 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_CLIPPING, FALSE);
1544 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1545 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
1546 ok(SUCCEEDED(hr), "SetVertexShader failed, hr %#x.\n", hr);
1548 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad5, sizeof(*quad5));
1549 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
1551 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_CLIPPING, TRUE);
1552 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1554 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad6, sizeof(*quad6));
1555 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
1557 hr = IDirect3DDevice8_EndScene(device);
1558 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
1560 if (caps.PrimitiveMiscCaps & D3DPMISCCAPS_CLIPTLVERTS)
1562 color = getPixelColor(device, 75, 75);
1563 ok(color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
1564 color = getPixelColor(device, 150, 150);
1565 ok(color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
1566 color = getPixelColor(device, 320, 240);
1567 ok(color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
1568 color = getPixelColor(device, 320, 330);
1569 ok(color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
1570 color = getPixelColor(device, 320, 330);
1571 ok(color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
1575 color = getPixelColor(device, 75, 75);
1576 ok(color_match(color, 0x00ffffff, 1), "color 0x%08x.\n", color);
1577 color = getPixelColor(device, 150, 150);
1578 ok(color_match(color, 0x00ffffff, 1), "color 0x%08x.\n", color);
1579 color = getPixelColor(device, 320, 240);
1580 ok(color_match(color, 0x00002b7f, 1), "color 0x%08x.\n", color);
1581 color = getPixelColor(device, 320, 330);
1582 ok(color_match(color, 0x00f9e814, 1), "color 0x%08x.\n", color);
1583 color = getPixelColor(device, 320, 330);
1584 ok(color_match(color, 0x00f9e814, 1), "color 0x%08x.\n", color);
1587 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1588 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
1592 hr = IDirect3DDevice8_SetViewport(device, &vp);
1593 ok(SUCCEEDED(hr), "SetViewport failed, hr %#x.\n", hr);
1596 static void depth_buffer_test(IDirect3DDevice8 *device)
1598 static const struct vertex quad1[] =
1600 { -1.0, 1.0, 0.33f, 0xff00ff00},
1601 { 1.0, 1.0, 0.33f, 0xff00ff00},
1602 { -1.0, -1.0, 0.33f, 0xff00ff00},
1603 { 1.0, -1.0, 0.33f, 0xff00ff00},
1605 static const struct vertex quad2[] =
1607 { -1.0, 1.0, 0.50f, 0xffff00ff},
1608 { 1.0, 1.0, 0.50f, 0xffff00ff},
1609 { -1.0, -1.0, 0.50f, 0xffff00ff},
1610 { 1.0, -1.0, 0.50f, 0xffff00ff},
1612 static const struct vertex quad3[] =
1614 { -1.0, 1.0, 0.66f, 0xffff0000},
1615 { 1.0, 1.0, 0.66f, 0xffff0000},
1616 { -1.0, -1.0, 0.66f, 0xffff0000},
1617 { 1.0, -1.0, 0.66f, 0xffff0000},
1619 static const DWORD expected_colors[4][4] =
1621 {0x000000ff, 0x000000ff, 0x0000ff00, 0x00ff0000},
1622 {0x000000ff, 0x000000ff, 0x0000ff00, 0x00ff0000},
1623 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x00ff0000},
1624 {0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000},
1627 IDirect3DSurface8 *backbuffer, *rt1, *rt2, *rt3;
1628 IDirect3DSurface8 *depth_stencil;
1641 hr = IDirect3DDevice8_SetViewport(device, &vp);
1642 ok(SUCCEEDED(hr), "SetViewport failed, hr %#x.\n", hr);
1644 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
1645 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1646 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
1647 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1648 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
1649 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1650 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
1651 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1652 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
1653 ok(SUCCEEDED(hr), "SetVertexShader failed, hr %#x.\n", hr);
1655 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &depth_stencil);
1656 ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
1657 hr = IDirect3DDevice8_GetRenderTarget(device, &backbuffer);
1658 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
1659 hr = IDirect3DDevice8_CreateRenderTarget(device, 320, 240, D3DFMT_A8R8G8B8,
1660 D3DMULTISAMPLE_NONE, FALSE, &rt1);
1661 ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
1662 hr = IDirect3DDevice8_CreateRenderTarget(device, 480, 360, D3DFMT_A8R8G8B8,
1663 D3DMULTISAMPLE_NONE, FALSE, &rt2);
1664 ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
1665 hr = IDirect3DDevice8_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
1666 D3DMULTISAMPLE_NONE, FALSE, &rt3);
1667 ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
1669 hr = IDirect3DDevice8_SetRenderTarget(device, rt3, depth_stencil);
1670 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
1671 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 0.0f, 0);
1672 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
1674 hr = IDirect3DDevice8_SetRenderTarget(device, backbuffer, depth_stencil);
1675 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
1676 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
1677 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
1679 hr = IDirect3DDevice8_SetRenderTarget(device, rt1, depth_stencil);
1680 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
1681 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 0.0f, 0);
1682 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
1684 hr = IDirect3DDevice8_SetRenderTarget(device, rt2, depth_stencil);
1685 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
1686 hr = IDirect3DDevice8_BeginScene(device);
1687 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
1688 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(*quad2));
1689 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
1690 hr = IDirect3DDevice8_EndScene(device);
1691 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
1693 hr = IDirect3DDevice8_SetRenderTarget(device, backbuffer, depth_stencil);
1694 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
1695 IDirect3DSurface8_Release(depth_stencil);
1696 IDirect3DSurface8_Release(backbuffer);
1697 IDirect3DSurface8_Release(rt3);
1698 IDirect3DSurface8_Release(rt2);
1699 IDirect3DSurface8_Release(rt1);
1701 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
1702 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1704 hr = IDirect3DDevice8_BeginScene(device);
1705 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
1706 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(*quad1));
1707 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
1708 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, sizeof(*quad3));
1709 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
1710 hr = IDirect3DDevice8_EndScene(device);
1711 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
1713 for (i = 0; i < 4; ++i)
1715 for (j = 0; j < 4; ++j)
1717 unsigned int x = 80 * ((2 * j) + 1);
1718 unsigned int y = 60 * ((2 * i) + 1);
1719 color = getPixelColor(device, x, y);
1720 ok(color_match(color, expected_colors[i][j], 0),
1721 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors[i][j], x, y, color);
1725 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1726 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
1729 /* Test that partial depth copies work the way they're supposed to. The clear
1730 * on rt2 only needs a partial copy of the onscreen depth/stencil buffer, and
1731 * the following draw should only copy back the part that was modified. */
1732 static void depth_buffer2_test(IDirect3DDevice8 *device)
1734 static const struct vertex quad[] =
1736 { -1.0, 1.0, 0.66f, 0xffff0000},
1737 { 1.0, 1.0, 0.66f, 0xffff0000},
1738 { -1.0, -1.0, 0.66f, 0xffff0000},
1739 { 1.0, -1.0, 0.66f, 0xffff0000},
1742 IDirect3DSurface8 *backbuffer, *rt1, *rt2;
1743 IDirect3DSurface8 *depth_stencil;
1756 hr = IDirect3DDevice8_SetViewport(device, &vp);
1757 ok(SUCCEEDED(hr), "SetViewport failed, hr %#x.\n", hr);
1759 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
1760 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1761 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
1762 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1763 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
1764 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1765 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
1766 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1767 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
1768 ok(SUCCEEDED(hr), "SetVertexShader failed, hr %#x.\n", hr);
1770 hr = IDirect3DDevice8_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
1771 D3DMULTISAMPLE_NONE, FALSE, &rt1);
1772 ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
1773 hr = IDirect3DDevice8_CreateRenderTarget(device, 480, 360, D3DFMT_A8R8G8B8,
1774 D3DMULTISAMPLE_NONE, FALSE, &rt2);
1775 ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
1776 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &depth_stencil);
1777 ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
1778 hr = IDirect3DDevice8_GetRenderTarget(device, &backbuffer);
1779 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
1781 hr = IDirect3DDevice8_SetRenderTarget(device, rt1, depth_stencil);
1782 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
1783 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
1784 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
1786 hr = IDirect3DDevice8_SetRenderTarget(device, backbuffer, depth_stencil);
1787 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
1788 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 0.5f, 0);
1789 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
1791 hr = IDirect3DDevice8_SetRenderTarget(device, rt2, depth_stencil);
1792 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
1793 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 0.0f, 0);
1794 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
1796 hr = IDirect3DDevice8_SetRenderTarget(device, backbuffer, depth_stencil);
1797 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
1798 IDirect3DSurface8_Release(depth_stencil);
1799 IDirect3DSurface8_Release(backbuffer);
1800 IDirect3DSurface8_Release(rt2);
1801 IDirect3DSurface8_Release(rt1);
1803 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
1804 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1806 hr = IDirect3DDevice8_BeginScene(device);
1807 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
1808 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
1809 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
1810 hr = IDirect3DDevice8_EndScene(device);
1811 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
1813 for (i = 0; i < 4; ++i)
1815 for (j = 0; j < 4; ++j)
1817 unsigned int x = 80 * ((2 * j) + 1);
1818 unsigned int y = 60 * ((2 * i) + 1);
1819 color = getPixelColor(device, x, y);
1820 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 0),
1821 "Expected color 0x0000ff00 %u,%u, got 0x%08x.\n", x, y, color);
1825 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1826 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
1829 static void intz_test(IDirect3DDevice8 *device)
1831 static const DWORD ps_code[] =
1833 0xffff0101, /* ps_1_1 */
1834 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1.0, 0.0, 0.0, 0.0 */
1835 0x00000051, 0xa00f0001, 0x00000000, 0x3f800000, 0x00000000, 0x00000000, /* def c1, 0.0, 1.0, 0.0, 0.0 */
1836 0x00000051, 0xa00f0002, 0x00000000, 0x00000000, 0x3f800000, 0x00000000, /* def c2, 0.0, 0.0, 1.0, 0.0 */
1837 0x00000042, 0xb00f0000, /* tex t0 */
1838 0x00000042, 0xb00f0001, /* tex t1 */
1839 0x00000008, 0xb0070001, 0xa0e40000, 0xb0e40001, /* dp3 t1.xyz, c0, t1 */
1840 0x00000005, 0x80070000, 0xa0e40001, 0xb0e40001, /* mul r0.xyz, c1, t1 */
1841 0x00000004, 0x80070000, 0xa0e40000, 0xb0e40000, 0x80e40000, /* mad r0.xyz, c0, t0, r0 */
1842 0x40000001, 0x80080000, 0xa0aa0002, /* +mov r0.w, c2.z */
1843 0x0000ffff, /* end */
1849 float s1, t1, p1, q1;
1853 { -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.5f},
1854 { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.5f},
1855 { -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f},
1856 { 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.5f},
1860 { -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.5f},
1861 { 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.5f},
1862 { -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f},
1863 { 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.5f},
1867 { -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.5f},
1868 { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.5f},
1869 { -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f},
1870 { 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.5f},
1879 { 80, 100, D3DCOLOR_ARGB(0x00, 0x20, 0x40, 0x00)},
1880 {240, 100, D3DCOLOR_ARGB(0x00, 0x60, 0xbf, 0x00)},
1881 {400, 100, D3DCOLOR_ARGB(0x00, 0x9f, 0x40, 0x00)},
1882 {560, 100, D3DCOLOR_ARGB(0x00, 0xdf, 0xbf, 0x00)},
1883 { 80, 450, D3DCOLOR_ARGB(0x00, 0x20, 0x40, 0x00)},
1884 {240, 450, D3DCOLOR_ARGB(0x00, 0x60, 0xbf, 0x00)},
1885 {400, 450, D3DCOLOR_ARGB(0x00, 0x9f, 0x40, 0x00)},
1886 {560, 450, D3DCOLOR_ARGB(0x00, 0xdf, 0xbf, 0x00)},
1889 IDirect3DSurface8 *original_ds, *original_rt, *rt;
1890 IDirect3DTexture8 *texture;
1891 IDirect3DSurface8 *ds;
1898 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
1899 ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
1900 if (caps.PixelShaderVersion < D3DPS_VERSION(1, 1))
1902 skip("No pixel shader 1.1 support, skipping INTZ test.\n");
1905 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
1907 skip("No unconditional NP2 texture support, skipping INTZ test.\n");
1911 hr = IDirect3DDevice8_GetDirect3D(device, &d3d8);
1912 ok(SUCCEEDED(hr), "GetDirect3D failed, hr %#x.\n", hr);
1914 hr = IDirect3D8_CheckDeviceFormat(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
1915 D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, MAKEFOURCC('I','N','T','Z'));
1918 skip("No INTZ support, skipping INTZ test.\n");
1922 IDirect3D8_Release(d3d8);
1924 hr = IDirect3DDevice8_GetRenderTarget(device, &original_rt);
1925 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
1926 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &original_ds);
1927 ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
1929 hr = IDirect3DDevice8_CreateTexture(device, 640, 480, 1,
1930 D3DUSAGE_DEPTHSTENCIL, MAKEFOURCC('I','N','T','Z'), D3DPOOL_DEFAULT, &texture);
1931 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1932 hr = IDirect3DDevice8_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
1933 D3DMULTISAMPLE_NONE, FALSE, &rt);
1934 ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
1935 hr = IDirect3DDevice8_CreatePixelShader(device, ps_code, &ps);
1936 ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
1938 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_TEX2
1939 | D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEXCOORDSIZE4(1));
1940 ok(SUCCEEDED(hr), "SetVertexShader failed, hr %#x.\n", hr);
1941 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
1942 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1943 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_ALWAYS);
1944 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1945 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
1946 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1947 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
1948 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
1950 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MINFILTER, D3DTEXF_POINT);
1951 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
1952 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MIPFILTER, D3DTEXF_POINT);
1953 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
1954 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MAGFILTER, D3DTEXF_POINT);
1955 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
1956 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3);
1957 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
1959 hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);
1960 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
1961 hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);
1962 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
1963 hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_MAGFILTER, D3DTEXF_POINT);
1964 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
1965 hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_MINFILTER, D3DTEXF_POINT);
1966 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
1967 hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_MIPFILTER, D3DTEXF_POINT);
1968 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
1969 hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_TEXTURETRANSFORMFLAGS,
1970 D3DTTFF_COUNT4 | D3DTTFF_PROJECTED);
1971 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
1973 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &ds);
1974 ok(SUCCEEDED(hr), "GetSurfaceLevel failed, hr %#x.\n", hr);
1976 /* Render offscreen, using the INTZ texture as depth buffer */
1977 hr = IDirect3DDevice8_SetRenderTarget(device, rt, ds);
1978 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
1979 IDirect3DDevice8_SetPixelShader(device, 0);
1980 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
1982 /* Setup the depth/stencil surface. */
1983 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
1984 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
1986 hr = IDirect3DDevice8_BeginScene(device);
1987 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
1988 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
1989 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
1990 hr = IDirect3DDevice8_EndScene(device);
1991 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
1993 hr = IDirect3DDevice8_SetRenderTarget(device, original_rt, NULL);
1994 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
1995 IDirect3DSurface8_Release(ds);
1996 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *)texture);
1997 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
1998 hr = IDirect3DDevice8_SetTexture(device, 1, (IDirect3DBaseTexture8 *)texture);
1999 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
2000 hr = IDirect3DDevice8_SetPixelShader(device, ps);
2001 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
2003 /* Read the depth values back. */
2004 hr = IDirect3DDevice8_BeginScene(device);
2005 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
2006 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
2007 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
2008 hr = IDirect3DDevice8_EndScene(device);
2009 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
2011 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
2013 D3DCOLOR color = getPixelColor(device, expected_colors[i].x, expected_colors[i].y);
2014 ok(color_match(color, expected_colors[i].color, 1),
2015 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
2016 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
2019 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
2020 ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
2022 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
2023 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
2024 hr = IDirect3DDevice8_SetTexture(device, 1, NULL);
2025 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
2026 IDirect3DTexture8_Release(texture);
2028 /* Render onscreen while using the INTZ texture as depth buffer */
2029 hr = IDirect3DDevice8_CreateTexture(device, 640, 480, 1,
2030 D3DUSAGE_DEPTHSTENCIL, MAKEFOURCC('I','N','T','Z'), D3DPOOL_DEFAULT, &texture);
2031 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
2032 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &ds);
2033 ok(SUCCEEDED(hr), "GetSurfaceLevel failed, hr %#x.\n", hr);
2034 hr = IDirect3DDevice8_SetRenderTarget(device, original_rt, ds);
2035 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
2036 IDirect3DDevice8_SetPixelShader(device, 0);
2037 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
2039 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
2040 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
2042 hr = IDirect3DDevice8_BeginScene(device);
2043 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
2044 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
2045 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
2046 hr = IDirect3DDevice8_EndScene(device);
2047 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
2049 hr = IDirect3DDevice8_SetRenderTarget(device, original_rt, NULL);
2050 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
2051 IDirect3DSurface8_Release(ds);
2052 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *)texture);
2053 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
2054 hr = IDirect3DDevice8_SetTexture(device, 1, (IDirect3DBaseTexture8 *)texture);
2055 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
2056 hr = IDirect3DDevice8_SetPixelShader(device, ps);
2057 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
2059 /* Read the depth values back. */
2060 hr = IDirect3DDevice8_BeginScene(device);
2061 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
2062 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
2063 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
2064 hr = IDirect3DDevice8_EndScene(device);
2065 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
2067 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
2069 D3DCOLOR color = getPixelColor(device, expected_colors[i].x, expected_colors[i].y);
2070 ok(color_match(color, expected_colors[i].color, 1),
2071 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
2072 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
2075 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
2076 ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
2078 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
2079 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
2080 hr = IDirect3DDevice8_SetTexture(device, 1, NULL);
2081 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
2082 IDirect3DTexture8_Release(texture);
2084 /* Render offscreen, then onscreen, and finally check the INTZ texture in both areas */
2085 hr = IDirect3DDevice8_CreateTexture(device, 640, 480, 1,
2086 D3DUSAGE_DEPTHSTENCIL, MAKEFOURCC('I','N','T','Z'), D3DPOOL_DEFAULT, &texture);
2087 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
2088 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &ds);
2089 ok(SUCCEEDED(hr), "GetSurfaceLevel failed, hr %#x.\n", hr);
2090 hr = IDirect3DDevice8_SetRenderTarget(device, rt, ds);
2091 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
2092 IDirect3DDevice8_SetPixelShader(device, 0);
2093 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
2095 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
2096 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
2098 hr = IDirect3DDevice8_BeginScene(device);
2099 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
2100 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, half_quad_1, sizeof(*half_quad_1));
2101 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
2102 hr = IDirect3DDevice8_EndScene(device);
2103 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
2105 hr = IDirect3DDevice8_SetRenderTarget(device, original_rt, ds);
2106 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
2108 hr = IDirect3DDevice8_BeginScene(device);
2109 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
2110 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, half_quad_2, sizeof(*half_quad_2));
2111 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
2112 hr = IDirect3DDevice8_EndScene(device);
2113 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
2115 hr = IDirect3DDevice8_SetRenderTarget(device, original_rt, NULL);
2116 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
2117 IDirect3DSurface8_Release(ds);
2118 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *)texture);
2119 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
2120 hr = IDirect3DDevice8_SetTexture(device, 1, (IDirect3DBaseTexture8 *)texture);
2121 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
2122 hr = IDirect3DDevice8_SetPixelShader(device, ps);
2123 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
2125 /* Read the depth values back. */
2126 hr = IDirect3DDevice8_BeginScene(device);
2127 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
2128 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
2129 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
2130 hr = IDirect3DDevice8_EndScene(device);
2131 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
2133 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
2135 D3DCOLOR color = getPixelColor(device, expected_colors[i].x, expected_colors[i].y);
2136 ok(color_match(color, expected_colors[i].color, 1),
2137 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
2138 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
2141 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
2142 ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
2144 hr = IDirect3DDevice8_SetRenderTarget(device, original_rt, original_ds);
2145 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
2146 IDirect3DSurface8_Release(original_ds);
2147 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
2148 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
2149 hr = IDirect3DDevice8_SetTexture(device, 1, NULL);
2150 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
2151 IDirect3DTexture8_Release(texture);
2152 hr = IDirect3DDevice8_SetPixelShader(device, 0);
2153 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
2154 hr = IDirect3DDevice8_DeletePixelShader(device, ps);
2155 ok(SUCCEEDED(hr), "DeletePixelShader failed, hr %#x.\n", hr);
2157 IDirect3DSurface8_Release(original_rt);
2158 IDirect3DSurface8_Release(rt);
2161 static void shadow_test(IDirect3DDevice8 *device)
2163 static const DWORD ps_code[] =
2165 0xffff0101, /* ps_1_1 */
2166 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1.0, 0.0, 0.0, 0.0 */
2167 0x00000051, 0xa00f0001, 0x00000000, 0x3f800000, 0x00000000, 0x00000000, /* def c1, 0.0, 1.0, 0.0, 0.0 */
2168 0x00000051, 0xa00f0002, 0x00000000, 0x00000000, 0x3f800000, 0x00000000, /* def c2, 0.0, 0.0, 1.0, 0.0 */
2169 0x00000042, 0xb00f0000, /* tex t0 */
2170 0x00000042, 0xb00f0001, /* tex t1 */
2171 0x00000008, 0xb0070001, 0xa0e40000, 0xb0e40001, /* dp3 t1.xyz, c0, t1 */
2172 0x00000005, 0x80070000, 0xa0e40001, 0xb0e40001, /* mul r0.xyz, c1, t1 */
2173 0x00000004, 0x80070000, 0xa0e40000, 0xb0e40000, 0x80e40000, /* mad r0.xyz, c0, t0, r0 */
2174 0x40000001, 0x80080000, 0xa0aa0002, /* +mov r0.w, c2.z */
2175 0x0000ffff, /* end */
2184 {D3DFMT_D16_LOCKABLE, "D3DFMT_D16_LOCKABLE"},
2185 {D3DFMT_D32, "D3DFMT_D32"},
2186 {D3DFMT_D15S1, "D3DFMT_D15S1"},
2187 {D3DFMT_D24S8, "D3DFMT_D24S8"},
2188 {D3DFMT_D24X8, "D3DFMT_D24X8"},
2189 {D3DFMT_D24X4S4, "D3DFMT_D24X4S4"},
2190 {D3DFMT_D16, "D3DFMT_D16"},
2196 float s1, t1, p1, q1;
2200 { -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f},
2201 { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f},
2202 { -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
2203 { 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f},
2212 {400, 60, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00)},
2213 {560, 180, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x00)},
2214 {560, 300, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x00)},
2215 {400, 420, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x00)},
2216 {240, 420, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x00)},
2217 { 80, 300, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00)},
2218 { 80, 180, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00)},
2219 {240, 60, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00)},
2222 IDirect3DSurface8 *original_ds, *original_rt, *rt;
2229 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
2230 ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
2231 if (caps.PixelShaderVersion < D3DPS_VERSION(1, 1))
2233 skip("No pixel shader 1.1 support, skipping shadow test.\n");
2237 hr = IDirect3DDevice8_GetDirect3D(device, &d3d8);
2238 ok(SUCCEEDED(hr), "GetDirect3D failed, hr %#x.\n", hr);
2239 hr = IDirect3DDevice8_GetRenderTarget(device, &original_rt);
2240 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
2241 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &original_ds);
2242 ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
2244 hr = IDirect3DDevice8_CreateRenderTarget(device, 1024, 1024, D3DFMT_A8R8G8B8,
2245 D3DMULTISAMPLE_NONE, FALSE, &rt);
2246 ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
2247 hr = IDirect3DDevice8_CreatePixelShader(device, ps_code, &ps);
2248 ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
2250 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_TEX2
2251 | D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEXCOORDSIZE4(1));
2252 ok(SUCCEEDED(hr), "SetVertexShader failed, hr %#x.\n", hr);
2253 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
2254 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
2255 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_ALWAYS);
2256 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
2257 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
2258 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
2259 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
2260 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
2262 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MINFILTER, D3DTEXF_POINT);
2263 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
2264 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MIPFILTER, D3DTEXF_POINT);
2265 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
2266 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MAGFILTER, D3DTEXF_POINT);
2267 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
2268 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3);
2269 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
2271 hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);
2272 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
2273 hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);
2274 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
2275 hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_MAGFILTER, D3DTEXF_POINT);
2276 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
2277 hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_MINFILTER, D3DTEXF_POINT);
2278 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
2279 hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_MIPFILTER, D3DTEXF_POINT);
2280 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
2281 hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_TEXTURETRANSFORMFLAGS,
2282 D3DTTFF_COUNT4 | D3DTTFF_PROJECTED);
2283 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
2285 for (i = 0; i < sizeof(formats) / sizeof(*formats); ++i)
2287 D3DFORMAT format = formats[i].format;
2288 IDirect3DTexture8 *texture;
2289 IDirect3DSurface8 *ds;
2292 hr = IDirect3D8_CheckDeviceFormat(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
2293 D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, format);
2294 if (FAILED(hr)) continue;
2296 hr = IDirect3DDevice8_CreateTexture(device, 1024, 1024, 1,
2297 D3DUSAGE_DEPTHSTENCIL, format, D3DPOOL_DEFAULT, &texture);
2298 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
2300 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &ds);
2301 ok(SUCCEEDED(hr), "GetSurfaceLevel failed, hr %#x.\n", hr);
2303 hr = IDirect3DDevice8_SetRenderTarget(device, rt, ds);
2304 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
2306 IDirect3DDevice8_SetPixelShader(device, 0);
2307 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
2309 /* Setup the depth/stencil surface. */
2310 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
2311 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
2313 hr = IDirect3DDevice8_BeginScene(device);
2314 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
2315 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
2316 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
2317 hr = IDirect3DDevice8_EndScene(device);
2318 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
2320 hr = IDirect3DDevice8_SetRenderTarget(device, original_rt, NULL);
2321 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
2322 IDirect3DSurface8_Release(ds);
2324 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *)texture);
2325 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
2326 hr = IDirect3DDevice8_SetTexture(device, 1, (IDirect3DBaseTexture8 *)texture);
2327 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
2329 hr = IDirect3DDevice8_SetPixelShader(device, ps);
2330 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
2332 /* Do the actual shadow mapping. */
2333 hr = IDirect3DDevice8_BeginScene(device);
2334 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
2335 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
2336 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
2337 hr = IDirect3DDevice8_EndScene(device);
2338 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
2340 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
2341 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
2342 hr = IDirect3DDevice8_SetTexture(device, 1, NULL);
2343 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
2344 IDirect3DTexture8_Release(texture);
2346 for (j = 0; j < sizeof(expected_colors) / sizeof(*expected_colors); ++j)
2348 D3DCOLOR color = getPixelColor(device, expected_colors[j].x, expected_colors[j].y);
2349 ok(color_match(color, expected_colors[j].color, 0),
2350 "Expected color 0x%08x at (%u, %u) for format %s, got 0x%08x.\n",
2351 expected_colors[j].color, expected_colors[j].x, expected_colors[j].y,
2352 formats[i].name, color);
2355 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
2356 ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
2359 hr = IDirect3DDevice8_SetPixelShader(device, 0);
2360 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
2361 hr = IDirect3DDevice8_DeletePixelShader(device, ps);
2362 ok(SUCCEEDED(hr), "DeletePixelShader failed, hr %#x.\n", hr);
2364 hr = IDirect3DDevice8_SetRenderTarget(device, original_rt, original_ds);
2365 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
2366 IDirect3DSurface8_Release(original_ds);
2368 IDirect3DSurface8_Release(original_rt);
2369 IDirect3DSurface8_Release(rt);
2371 IDirect3D8_Release(d3d8);
2374 static void multisample_copy_rects_test(IDirect3DDevice8 *device)
2376 IDirect3DSurface8 *original_ds, *original_rt, *ds, *ds_plain, *rt, *readback;
2377 RECT src_rect = {64, 64, 128, 128};
2378 POINT dst_point = {96, 96};
2379 D3DLOCKED_RECT locked_rect;
2384 hr = IDirect3DDevice8_GetDirect3D(device, &d3d8);
2385 ok(SUCCEEDED(hr), "Failed to get d3d8 interface, hr %#x.\n", hr);
2386 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d8, D3DADAPTER_DEFAULT,
2387 D3DDEVTYPE_HAL, D3DFMT_A8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES);
2388 IDirect3D8_Release(d3d8);
2391 skip("Multisampling not supported for D3DFMT_A8R8G8B8, skipping multisampled CopyRects test.\n");
2395 hr = IDirect3DDevice8_CreateRenderTarget(device, 256, 256, D3DFMT_A8R8G8B8,
2396 D3DMULTISAMPLE_2_SAMPLES, FALSE, &rt);
2397 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
2398 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 256, 256, D3DFMT_D24S8,
2399 D3DMULTISAMPLE_2_SAMPLES, &ds);
2400 ok(SUCCEEDED(hr), "Failed to create depth stencil surface, hr %#x.\n", hr);
2401 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 256, 256, D3DFMT_D24S8,
2402 D3DMULTISAMPLE_NONE, &ds_plain);
2403 ok(SUCCEEDED(hr), "Failed to create depth stencil surface, hr %#x.\n", hr);
2404 hr = IDirect3DDevice8_CreateImageSurface(device, 256, 256, D3DFMT_A8R8G8B8, &readback);
2405 ok(SUCCEEDED(hr), "Failed to create readback surface, hr %#x.\n", hr);
2407 hr = IDirect3DDevice8_GetRenderTarget(device, &original_rt);
2408 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
2409 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &original_ds);
2410 ok(SUCCEEDED(hr), "Failed to get depth/stencil, hr %#x.\n", hr);
2412 hr = IDirect3DDevice8_SetRenderTarget(device, rt, ds);
2413 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
2415 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 1.0f, 0);
2416 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
2418 hr = IDirect3DDevice8_CopyRects(device, rt, NULL, 0, readback, NULL);
2419 ok(SUCCEEDED(hr), "Failed to read render target back, hr %#x.\n", hr);
2421 hr = IDirect3DDevice8_CopyRects(device, ds, NULL, 0, ds_plain, NULL);
2422 todo_wine ok(hr == D3DERR_INVALIDCALL, "Depth buffer copy, hr %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
2424 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
2425 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
2427 hr = IDirect3DDevice8_CopyRects(device, rt, &src_rect, 1, readback, &dst_point);
2428 ok(SUCCEEDED(hr), "Failed to read render target back, hr %#x.\n", hr);
2430 hr = IDirect3DSurface8_LockRect(readback, &locked_rect, NULL, D3DLOCK_READONLY);
2431 ok(SUCCEEDED(hr), "Failed to lock readback surface, hr %#x.\n", hr);
2433 color = *(DWORD *)((BYTE *)locked_rect.pBits + 31 * locked_rect.Pitch + 31 * 4);
2434 ok(color == 0xff00ff00, "Got unexpected color 0x%08x.\n", color);
2436 color = *(DWORD *)((BYTE *)locked_rect.pBits + 127 * locked_rect.Pitch + 127 * 4);
2437 ok(color == 0xffff0000, "Got unexpected color 0x%08x.\n", color);
2439 hr = IDirect3DSurface8_UnlockRect(readback);
2440 ok(SUCCEEDED(hr), "Failed to unlock readback surface, hr %#x.\n", hr);
2442 hr = IDirect3DDevice8_SetRenderTarget(device, original_rt, original_ds);
2443 ok(SUCCEEDED(hr), "Failed to restore original render target, hr %#x.\n", hr);
2445 IDirect3DSurface8_Release(original_ds);
2446 IDirect3DSurface8_Release(original_rt);
2447 IDirect3DSurface8_Release(readback);
2448 IDirect3DSurface8_Release(ds_plain);
2449 IDirect3DSurface8_Release(ds);
2450 IDirect3DSurface8_Release(rt);
2453 static void resz_test(IDirect3DDevice8 *device)
2455 IDirect3DSurface8 *rt, *original_rt, *ds, *original_ds, *intz_ds;
2460 static const DWORD ps_code[] =
2462 0xffff0101, /* ps_1_1 */
2463 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1.0, 0.0, 0.0, 0.0 */
2464 0x00000051, 0xa00f0001, 0x00000000, 0x3f800000, 0x00000000, 0x00000000, /* def c1, 0.0, 1.0, 0.0, 0.0 */
2465 0x00000051, 0xa00f0002, 0x00000000, 0x00000000, 0x3f800000, 0x00000000, /* def c2, 0.0, 0.0, 1.0, 0.0 */
2466 0x00000042, 0xb00f0000, /* tex t0 */
2467 0x00000042, 0xb00f0001, /* tex t1 */
2468 0x00000008, 0xb0070001, 0xa0e40000, 0xb0e40001, /* dp3 t1.xyz, c0, t1 */
2469 0x00000005, 0x80070000, 0xa0e40001, 0xb0e40001, /* mul r0.xyz, c1, t1 */
2470 0x00000004, 0x80070000, 0xa0e40000, 0xb0e40000, 0x80e40000, /* mad r0.xyz, c0, t0, r0 */
2471 0x40000001, 0x80080000, 0xa0aa0002, /* +mov r0.w, c2.z */
2472 0x0000ffff, /* end */
2478 float s1, t1, p1, q1;
2482 { -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.5f},
2483 { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.5f},
2484 { -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f},
2485 { 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.5f},
2494 { 80, 100, D3DCOLOR_ARGB(0x00, 0x20, 0x40, 0x00)},
2495 {240, 100, D3DCOLOR_ARGB(0x00, 0x60, 0xbf, 0x00)},
2496 {400, 100, D3DCOLOR_ARGB(0x00, 0x9f, 0x40, 0x00)},
2497 {560, 100, D3DCOLOR_ARGB(0x00, 0xdf, 0xbf, 0x00)},
2498 { 80, 450, D3DCOLOR_ARGB(0x00, 0x20, 0x40, 0x00)},
2499 {240, 450, D3DCOLOR_ARGB(0x00, 0x60, 0xbf, 0x00)},
2500 {400, 450, D3DCOLOR_ARGB(0x00, 0x9f, 0x40, 0x00)},
2501 {560, 450, D3DCOLOR_ARGB(0x00, 0xdf, 0xbf, 0x00)},
2503 IDirect3DTexture8 *texture;
2506 hr = IDirect3DDevice8_GetDirect3D(device, &d3d8);
2507 ok(SUCCEEDED(hr), "Failed to get d3d8 interface, hr %#x.\n", hr);
2508 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d8, D3DADAPTER_DEFAULT,
2509 D3DDEVTYPE_HAL, D3DFMT_A8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES);
2512 skip("Multisampling not supported for D3DFMT_A8R8G8B8, skipping RESZ test.\n");
2515 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d8, D3DADAPTER_DEFAULT,
2516 D3DDEVTYPE_HAL, D3DFMT_D24S8, TRUE, D3DMULTISAMPLE_2_SAMPLES);
2519 skip("Multisampling not supported for D3DFMT_D24S8, skipping RESZ test.\n");
2522 hr = IDirect3D8_CheckDeviceFormat(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
2523 D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, MAKEFOURCC('I','N','T','Z'));
2526 skip("No INTZ support, skipping RESZ test.\n");
2529 hr = IDirect3D8_CheckDeviceFormat(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
2530 D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, MAKEFOURCC('R','E','S','Z'));
2533 skip("No RESZ support, skipping RESZ test.\n");
2536 IDirect3D8_Release(d3d8);
2538 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
2539 ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
2540 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
2542 skip("No unconditional NP2 texture support, skipping INTZ test.\n");
2546 hr = IDirect3DDevice8_GetRenderTarget(device, &original_rt);
2547 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
2548 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &original_ds);
2549 ok(SUCCEEDED(hr), "Failed to get depth/stencil, hr %#x.\n", hr);
2551 hr = IDirect3DDevice8_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
2552 D3DMULTISAMPLE_2_SAMPLES, FALSE, &rt);
2553 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
2554 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 640, 480, D3DFMT_D24S8,
2555 D3DMULTISAMPLE_2_SAMPLES, &ds);
2557 hr = IDirect3DDevice8_CreateTexture(device, 640, 480, 1,
2558 D3DUSAGE_DEPTHSTENCIL, MAKEFOURCC('I','N','T','Z'), D3DPOOL_DEFAULT, &texture);
2559 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
2560 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &intz_ds);
2561 ok(SUCCEEDED(hr), "GetSurfaceLevel failed, hr %#x.\n", hr);
2563 hr = IDirect3DDevice8_SetRenderTarget(device, original_rt, intz_ds);
2564 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
2565 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ffff, 1.0f, 0);
2566 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
2568 hr = IDirect3DDevice8_SetRenderTarget(device, rt, ds);
2569 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
2570 IDirect3DSurface8_Release(intz_ds);
2571 hr = IDirect3DDevice8_CreatePixelShader(device, ps_code, &ps);
2572 ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
2574 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_TEX2
2575 | D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEXCOORDSIZE4(1));
2576 ok(SUCCEEDED(hr), "SetVertexShader failed, hr %#x.\n", hr);
2577 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
2578 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
2579 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_ALWAYS);
2580 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
2581 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
2582 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
2583 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
2584 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
2586 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MINFILTER, D3DTEXF_POINT);
2587 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
2588 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MIPFILTER, D3DTEXF_POINT);
2589 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
2590 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MAGFILTER, D3DTEXF_POINT);
2591 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
2592 hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3);
2593 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
2595 hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);
2596 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
2597 hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);
2598 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
2599 hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_MAGFILTER, D3DTEXF_POINT);
2600 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
2601 hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_MINFILTER, D3DTEXF_POINT);
2602 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
2603 hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_MIPFILTER, D3DTEXF_POINT);
2604 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
2605 hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_TEXTURETRANSFORMFLAGS,
2606 D3DTTFF_COUNT4 | D3DTTFF_PROJECTED);
2607 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
2609 /* Render offscreen (multisampled), blit the depth buffer into the INTZ texture and then check its contents. */
2610 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 1.0f, 0);
2611 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
2613 hr = IDirect3DDevice8_BeginScene(device);
2614 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
2615 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
2616 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
2618 /* The destination depth texture has to be bound to sampler 0 */
2619 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *)texture);
2620 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
2622 /* the ATI "spec" says you have to do a dummy draw to ensure correct commands ordering */
2623 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, FALSE);
2624 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
2625 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
2626 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
2627 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_COLORWRITEENABLE, 0);
2628 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
2629 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
2630 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
2631 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, TRUE);
2632 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
2633 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
2634 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
2635 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_COLORWRITEENABLE, 0xf);
2636 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
2638 /* The actual multisampled depth buffer resolve happens here */
2639 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_POINTSIZE, 0x7fa05000);
2640 ok(SUCCEEDED(hr), "SetRenderState (multisampled depth buffer resolve) failed, hr %#x.\n", hr);
2641 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_POINTSIZE, &value);
2642 ok(SUCCEEDED(hr) && value == 0x7fa05000, "GetRenderState failed, hr %#x, value %#x.\n", hr, value);
2644 hr = IDirect3DDevice8_SetRenderTarget(device, original_rt, NULL);
2645 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
2646 hr = IDirect3DDevice8_SetTexture(device, 1, (IDirect3DBaseTexture8 *)texture);
2647 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
2648 hr = IDirect3DDevice8_SetPixelShader(device, ps);
2649 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
2651 /* Read the depth values back. */
2652 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
2653 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
2654 hr = IDirect3DDevice8_EndScene(device);
2655 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
2657 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
2659 D3DCOLOR color = getPixelColor(device, expected_colors[i].x, expected_colors[i].y);
2660 ok(color_match(color, expected_colors[i].color, 1),
2661 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
2662 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
2665 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
2666 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
2668 /* Test edge cases - try with no texture at all */
2669 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
2670 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
2671 hr = IDirect3DDevice8_SetTexture(device, 1, NULL);
2672 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
2673 hr = IDirect3DDevice8_SetRenderTarget(device, rt, ds);
2674 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
2676 hr = IDirect3DDevice8_BeginScene(device);
2677 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
2678 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
2679 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
2680 hr = IDirect3DDevice8_EndScene(device);
2681 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
2683 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_POINTSIZE, 0x7fa05000);
2684 ok(SUCCEEDED(hr), "SetRenderState (multisampled depth buffer resolve) failed, hr %#x.\n", hr);
2686 /* With a non-multisampled depth buffer */
2687 IDirect3DSurface8_Release(ds);
2688 IDirect3DSurface8_Release(rt);
2689 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 640, 480, D3DFMT_D24S8,
2690 D3DMULTISAMPLE_NONE, &ds);
2692 hr = IDirect3DDevice8_SetRenderTarget(device, original_rt, ds);
2693 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
2694 hr = IDirect3DDevice8_SetPixelShader(device, 0);
2695 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
2697 hr = IDirect3DDevice8_BeginScene(device);
2698 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
2699 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
2700 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
2701 hr = IDirect3DDevice8_EndScene(device);
2702 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
2704 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *)texture);
2705 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
2707 hr = IDirect3DDevice8_BeginScene(device);
2708 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
2709 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, FALSE);
2710 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
2711 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
2712 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
2713 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_COLORWRITEENABLE, 0);
2714 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
2715 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
2716 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
2717 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, TRUE);
2718 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
2719 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
2720 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
2721 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_COLORWRITEENABLE, 0xf);
2722 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
2723 hr = IDirect3DDevice8_EndScene(device);
2724 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
2726 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_POINTSIZE, 0x7fa05000);
2727 ok(SUCCEEDED(hr), "SetRenderState (multisampled depth buffer resolve) failed, hr %#x.\n", hr);
2729 hr = IDirect3DDevice8_SetTexture(device, 1, (IDirect3DBaseTexture8 *)texture);
2730 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
2731 hr = IDirect3DDevice8_SetPixelShader(device, ps);
2732 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
2734 /* Read the depth values back. */
2735 hr = IDirect3DDevice8_BeginScene(device);
2736 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
2737 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
2738 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
2739 hr = IDirect3DDevice8_EndScene(device);
2740 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
2742 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
2744 D3DCOLOR color = getPixelColor(device, expected_colors[i].x, expected_colors[i].y);
2745 ok(color_match(color, expected_colors[i].color, 1),
2746 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
2747 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
2750 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
2751 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
2753 hr = IDirect3DDevice8_SetRenderTarget(device, original_rt, original_ds);
2754 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
2755 IDirect3DSurface8_Release(ds);
2756 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
2757 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
2758 hr = IDirect3DDevice8_SetTexture(device, 1, NULL);
2759 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
2760 IDirect3DTexture8_Release(texture);
2761 hr = IDirect3DDevice8_SetPixelShader(device, 0);
2762 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
2763 hr = IDirect3DDevice8_DeletePixelShader(device, ps);
2764 ok(SUCCEEDED(hr), "DeletePixelShader failed, hr %#x.\n", hr);
2765 IDirect3DSurface8_Release(original_ds);
2766 IDirect3DSurface8_Release(original_rt);
2771 IDirect3DDevice8 *device_ptr;
2776 d3d8_handle = LoadLibraryA("d3d8.dll");
2779 win_skip("Could not load d3d8.dll\n");
2783 device_ptr = init_d3d8();
2786 win_skip("Could not initialize direct3d\n");
2790 IDirect3DDevice8_GetDeviceCaps(device_ptr, &caps);
2792 /* Check for the reliability of the returned data */
2793 hr = IDirect3DDevice8_Clear(device_ptr, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
2796 skip("Clear failed, can't assure correctness of the test results\n");
2800 color = getPixelColor(device_ptr, 1, 1);
2801 if(color !=0x00ff0000)
2803 skip("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests\n", color);
2806 IDirect3DDevice8_Present(device_ptr, NULL, NULL, NULL, NULL);
2808 hr = IDirect3DDevice8_Clear(device_ptr, 0, NULL, D3DCLEAR_TARGET, 0xff00ddee, 0.0, 0);
2811 skip("Clear failed, can't assure correctness of the test results\n");
2815 color = getPixelColor(device_ptr, 639, 479);
2816 if(color != 0x0000ddee)
2818 skip("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests\n", color);
2821 IDirect3DDevice8_Present(device_ptr, NULL, NULL, NULL, NULL);
2823 /* Now run the real test */
2824 depth_clamp_test(device_ptr);
2825 lighting_test(device_ptr);
2826 clear_test(device_ptr);
2827 fog_test(device_ptr);
2828 present_test(device_ptr);
2829 offscreen_test(device_ptr);
2830 alpha_test(device_ptr);
2832 if (caps.VertexShaderVersion >= D3DVS_VERSION(1, 1))
2834 test_rcp_rsq(device_ptr);
2838 skip("No vs.1.1 support\n");
2841 p8_texture_test(device_ptr);
2842 texop_test(device_ptr);
2843 depth_buffer_test(device_ptr);
2844 depth_buffer2_test(device_ptr);
2845 intz_test(device_ptr);
2846 shadow_test(device_ptr);
2847 multisample_copy_rects_test(device_ptr);
2848 resz_test(device_ptr);
2852 D3DDEVICE_CREATION_PARAMETERS creation_parameters;
2855 IDirect3DDevice8_GetCreationParameters(device_ptr, &creation_parameters);
2856 DestroyWindow(creation_parameters.hFocusWindow);
2857 refcount = IDirect3DDevice8_Release(device_ptr);
2858 ok(!refcount, "Device has %u references left\n", refcount);