d3d9/tests: Fix stream_test cases which do not use stream 0.
[wine.git] / dlls / d3d9 / tests / visual.c
blobf8860b763544b83abb5c1f69fa5386376524f360
1 /*
2 * Copyright 2005, 2007-2008 Henri Verbeet
3 * Copyright (C) 2007-2013 Stefan Dösinger(for CodeWeavers)
4 * Copyright (C) 2008 Jason Green(for TransGaming)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 /* This test framework allows limited testing of rendering results. Things are rendered, shown on
22 * the framebuffer, read back from there and compared to expected colors.
24 * However, neither d3d nor opengl is guaranteed to be pixel exact, and thus the capability of this test
25 * is rather limited. As a general guideline for adding tests, do not rely on corner pixels. Draw a big enough
26 * area which shows specific behavior(like a quad on the whole screen), and try to get resulting colors with
27 * all bits set or unset in all channels(like pure red, green, blue, white, black). Hopefully everything that
28 * causes visible results in games can be tested in a way that does not depend on pixel exactness
31 #include <math.h>
33 #define COBJMACROS
34 #include <d3d9.h>
35 #include "wine/test.h"
37 struct vec2
39 float x, y;
42 struct vec3
44 float x, y, z;
47 struct vec4
49 float x, y, z, w;
52 static HWND create_window(void)
54 HWND hwnd;
55 RECT rect;
57 SetRect(&rect, 0, 0, 640, 480);
58 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
59 hwnd = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
60 0, 0, rect.right - rect.left, rect.bottom - rect.top, 0, 0, 0, 0);
61 return hwnd;
64 static BOOL color_match(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
66 if (abs((int)(c1 & 0xff) - (int)(c2 & 0xff)) > max_diff) return FALSE;
67 c1 >>= 8; c2 >>= 8;
68 if (abs((int)(c1 & 0xff) - (int)(c2 & 0xff)) > max_diff) return FALSE;
69 c1 >>= 8; c2 >>= 8;
70 if (abs((int)(c1 & 0xff) - (int)(c2 & 0xff)) > max_diff) return FALSE;
71 c1 >>= 8; c2 >>= 8;
72 if (abs((int)(c1 & 0xff) - (int)(c2 & 0xff)) > max_diff) return FALSE;
73 return TRUE;
76 static BOOL adapter_is_warp(const D3DADAPTER_IDENTIFIER9 *identifier)
78 return !strcmp(identifier->Driver, "d3d10warp.dll");
81 /* Locks a given surface and returns the color at (x,y). It's the caller's
82 * responsibility to only pass in lockable surfaces and valid x,y coordinates */
83 static DWORD getPixelColorFromSurface(IDirect3DSurface9 *surface, UINT x, UINT y)
85 DWORD color;
86 HRESULT hr;
87 D3DSURFACE_DESC desc;
88 RECT rectToLock = {x, y, x+1, y+1};
89 D3DLOCKED_RECT lockedRect;
91 hr = IDirect3DSurface9_GetDesc(surface, &desc);
92 if(FAILED(hr)) /* This is not a test */
94 trace("Can't get the surface description, hr=%08x\n", hr);
95 return 0xdeadbeef;
98 hr = IDirect3DSurface9_LockRect(surface, &lockedRect, &rectToLock, D3DLOCK_READONLY);
99 if(FAILED(hr)) /* This is not a test */
101 trace("Can't lock the surface, hr=%08x\n", hr);
102 return 0xdeadbeef;
104 switch(desc.Format) {
105 case D3DFMT_A8R8G8B8:
107 color = ((DWORD *) lockedRect.pBits)[0];
108 break;
110 default:
111 trace("Error: unknown surface format: %d\n", desc.Format);
112 color = 0xdeadbeef;
113 break;
115 hr = IDirect3DSurface9_UnlockRect(surface);
116 if(FAILED(hr))
118 trace("Can't unlock the surface, hr=%08x\n", hr);
120 return color;
123 struct surface_readback
125 IDirect3DSurface9 *surface;
126 D3DLOCKED_RECT locked_rect;
129 static void get_rt_readback(IDirect3DSurface9 *surface, struct surface_readback *rb)
131 IDirect3DDevice9 *device;
132 D3DSURFACE_DESC desc;
133 HRESULT hr;
135 memset(rb, 0, sizeof(*rb));
136 hr = IDirect3DSurface9_GetDevice(surface, &device);
137 ok(SUCCEEDED(hr), "Failed to get device, hr %#x.\n", hr);
138 hr = IDirect3DSurface9_GetDesc(surface, &desc);
139 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
140 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, desc.Width, desc.Height,
141 desc.Format, D3DPOOL_SYSTEMMEM, &rb->surface, NULL);
142 if (FAILED(hr) || !rb->surface)
144 trace("Can't create an offscreen plain surface to read the render target data, hr %#x.\n", hr);
145 goto error;
148 hr = IDirect3DDevice9_GetRenderTargetData(device, surface, rb->surface);
149 if (FAILED(hr))
151 trace("Can't read the render target data, hr %#x.\n", hr);
152 goto error;
155 hr = IDirect3DSurface9_LockRect(rb->surface, &rb->locked_rect, NULL, D3DLOCK_READONLY);
156 if (FAILED(hr))
158 trace("Can't lock the offscreen surface, hr %#x.\n", hr);
159 goto error;
161 IDirect3DDevice9_Release(device);
163 return;
165 error:
166 if (rb->surface)
167 IDirect3DSurface9_Release(rb->surface);
168 rb->surface = NULL;
169 IDirect3DDevice9_Release(device);
172 static DWORD get_readback_color(struct surface_readback *rb, unsigned int x, unsigned int y)
174 return rb->locked_rect.pBits
175 ? ((DWORD *)rb->locked_rect.pBits)[y * rb->locked_rect.Pitch / sizeof(DWORD) + x] : 0xdeadbeef;
178 static void release_surface_readback(struct surface_readback *rb)
180 HRESULT hr;
182 if (!rb->surface)
183 return;
184 if (rb->locked_rect.pBits && FAILED(hr = IDirect3DSurface9_UnlockRect(rb->surface)))
185 trace("Can't unlock the offscreen surface, hr %#x.\n", hr);
186 IDirect3DSurface9_Release(rb->surface);
189 static DWORD getPixelColor(IDirect3DDevice9 *device, UINT x, UINT y)
191 DWORD ret;
192 IDirect3DSurface9 *rt;
193 struct surface_readback rb;
194 HRESULT hr;
196 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &rt);
197 if(FAILED(hr))
199 trace("Can't get the render target, hr %#x.\n", hr);
200 return 0xdeadbeed;
203 get_rt_readback(rt, &rb);
204 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
205 * really important for these tests
207 ret = get_readback_color(&rb, x, y) & 0x00ffffff;
208 release_surface_readback(&rb);
210 IDirect3DSurface9_Release(rt);
211 return ret;
214 static IDirect3DDevice9 *create_device(IDirect3D9 *d3d, HWND device_window, HWND focus_window, BOOL windowed)
216 D3DPRESENT_PARAMETERS present_parameters = {0};
217 IDirect3DDevice9 *device;
219 present_parameters.Windowed = windowed;
220 present_parameters.hDeviceWindow = device_window;
221 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
222 present_parameters.BackBufferWidth = 640;
223 present_parameters.BackBufferHeight = 480;
224 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
225 present_parameters.EnableAutoDepthStencil = TRUE;
226 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
228 if (SUCCEEDED(IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
229 D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device)))
230 return device;
232 return NULL;
235 static void cleanup_device(IDirect3DDevice9 *device)
237 if (device)
239 D3DPRESENT_PARAMETERS present_parameters;
240 IDirect3DSwapChain9 *swapchain;
241 ULONG ref;
243 IDirect3DDevice9_GetSwapChain(device, 0, &swapchain);
244 IDirect3DSwapChain9_GetPresentParameters(swapchain, &present_parameters);
245 IDirect3DSwapChain9_Release(swapchain);
246 ref = IDirect3DDevice9_Release(device);
247 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
248 DestroyWindow(present_parameters.hDeviceWindow);
252 static void test_sanity(void)
254 IDirect3DDevice9 *device;
255 IDirect3D9 *d3d;
256 D3DCOLOR color;
257 ULONG refcount;
258 HWND window;
259 HRESULT hr;
261 window = create_window();
262 d3d = Direct3DCreate9(D3D_SDK_VERSION);
263 ok(!!d3d, "Failed to create a D3D object.\n");
264 if (!(device = create_device(d3d, window, window, TRUE)))
266 skip("Failed to create a D3D device, skipping tests.\n");
267 goto done;
270 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 1.0f, 0);
271 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
272 color = getPixelColor(device, 1, 1);
273 ok(color == 0x00ff0000, "Got unexpected color 0x%08x.\n", color);
275 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
276 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
278 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ddee, 0.0, 0);
279 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
280 color = getPixelColor(device, 639, 479);
281 ok(color == 0x0000ddee, "Got unexpected color 0x%08x.\n", color);
283 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
284 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
286 refcount = IDirect3DDevice9_Release(device);
287 ok(!refcount, "Device has %u references left.\n", refcount);
288 done:
289 IDirect3D9_Release(d3d);
290 DestroyWindow(window);
293 static void lighting_test(void)
295 DWORD nfvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_NORMAL;
296 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
297 IDirect3DDevice9 *device;
298 D3DMATERIAL9 material;
299 IDirect3D9 *d3d;
300 D3DCOLOR color;
301 ULONG refcount;
302 HWND window;
303 HRESULT hr;
304 unsigned int i;
306 static const D3DMATRIX mat =
308 1.0f, 0.0f, 0.0f, 0.0f,
309 0.0f, 1.0f, 0.0f, 0.0f,
310 0.0f, 0.0f, 1.0f, 0.0f,
311 0.0f, 0.0f, 0.0f, 1.0f,
312 }}},
313 mat_singular =
315 1.0f, 0.0f, 1.0f, 0.0f,
316 0.0f, 1.0f, 0.0f, 0.0f,
317 1.0f, 0.0f, 1.0f, 0.0f,
318 0.0f, 0.0f, 0.5f, 1.0f,
319 }}},
320 mat_transf =
322 0.0f, 0.0f, 1.0f, 0.0f,
323 0.0f, 1.0f, 0.0f, 0.0f,
324 -1.0f, 0.0f, 0.0f, 0.0f,
325 10.f, 10.0f, 10.0f, 1.0f,
326 }}},
327 mat_nonaffine =
329 1.0f, 0.0f, 0.0f, 0.0f,
330 0.0f, 1.0f, 0.0f, 0.0f,
331 0.0f, 0.0f, 1.0f, -1.0f,
332 10.f, 10.0f, 10.0f, 0.0f,
333 }}};
334 static const struct
336 struct vec3 position;
337 DWORD diffuse;
339 unlitquad[] =
341 {{-1.0f, -1.0f, 0.1f}, 0xffff0000},
342 {{-1.0f, 0.0f, 0.1f}, 0xffff0000},
343 {{ 0.0f, 0.0f, 0.1f}, 0xffff0000},
344 {{ 0.0f, -1.0f, 0.1f}, 0xffff0000},
346 litquad[] =
348 {{-1.0f, 0.0f, 0.1f}, 0xff00ff00},
349 {{-1.0f, 1.0f, 0.1f}, 0xff00ff00},
350 {{ 0.0f, 1.0f, 0.1f}, 0xff00ff00},
351 {{ 0.0f, 0.0f, 0.1f}, 0xff00ff00},
353 lighting_test[] =
355 {{-1.0f, -1.0f, 0.1f}, 0x8000ff00},
356 {{ 1.0f, -1.0f, 0.1f}, 0x80000000},
357 {{-1.0f, 1.0f, 0.1f}, 0x8000ff00},
358 {{ 1.0f, 1.0f, 0.1f}, 0x80000000},
360 static const struct
362 struct vec3 position;
363 struct vec3 normal;
364 DWORD diffuse;
366 unlitnquad[] =
368 {{0.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
369 {{0.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
370 {{1.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
371 {{1.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
373 litnquad[] =
375 {{0.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
376 {{0.0f, 1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
377 {{1.0f, 1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
378 {{1.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
380 nquad[] =
382 {{-1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
383 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
384 {{ 1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
385 {{ 1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
387 rotatedquad[] =
389 {{-10.0f, -11.0f, 11.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
390 {{-10.0f, -9.0f, 11.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
391 {{-10.0f, -9.0f, 9.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
392 {{-10.0f, -11.0f, 9.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
394 translatedquad[] =
396 {{-11.0f, -11.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
397 {{-11.0f, -9.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
398 {{ -9.0f, -9.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
399 {{ -9.0f, -11.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
401 static const WORD indices[] = {0, 1, 2, 2, 3, 0};
402 static const struct
404 const D3DMATRIX *world_matrix;
405 const void *quad;
406 unsigned int size;
407 DWORD expected;
408 const char *message;
410 tests[] =
412 {&mat, nquad, sizeof(nquad[0]), 0x000000ff, "Lit quad with light"},
413 {&mat_singular, nquad, sizeof(nquad[0]), 0x000000ff, "Lit quad with singular world matrix"},
414 {&mat_transf, rotatedquad, sizeof(rotatedquad[0]), 0x000000ff, "Lit quad with transformation matrix"},
415 {&mat_nonaffine, translatedquad, sizeof(translatedquad[0]), 0x00000000, "Lit quad with non-affine matrix"},
418 window = create_window();
419 d3d = Direct3DCreate9(D3D_SDK_VERSION);
420 ok(!!d3d, "Failed to create a D3D object.\n");
421 if (!(device = create_device(d3d, window, window, TRUE)))
423 skip("Failed to create a D3D device, skipping tests.\n");
424 goto done;
427 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
428 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
430 hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLDMATRIX(0), &mat);
431 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform returned %08x\n", hr);
432 hr = IDirect3DDevice9_SetTransform(device, D3DTS_VIEW, &mat);
433 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform returned %08x\n", hr);
434 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &mat);
435 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform returned %08x\n", hr);
436 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, FALSE);
437 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
438 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
439 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
440 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGENABLE, FALSE);
441 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
442 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILENABLE, FALSE);
443 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
444 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE);
445 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with %08x\n", hr);
447 hr = IDirect3DDevice9_SetFVF(device, fvf);
448 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF returned %08x\n", hr);
450 hr = IDirect3DDevice9_BeginScene(device);
451 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
453 /* No lights are defined... That means, lit vertices should be entirely black */
454 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
455 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
456 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4,
457 2, indices, D3DFMT_INDEX16, unlitquad, sizeof(unlitquad[0]));
458 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
460 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, TRUE);
461 ok(SUCCEEDED(hr), "Failed to enable lighting, hr %#x.\n", hr);
462 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4,
463 2, indices, D3DFMT_INDEX16, litquad, sizeof(litquad[0]));
464 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
466 hr = IDirect3DDevice9_SetFVF(device, nfvf);
467 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
469 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
470 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
471 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4,
472 2, indices, D3DFMT_INDEX16, unlitnquad, sizeof(unlitnquad[0]));
473 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
475 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, TRUE);
476 ok(SUCCEEDED(hr), "Failed to enable lighting, hr %#x.\n", hr);
477 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4,
478 2, indices, D3DFMT_INDEX16, litnquad, sizeof(litnquad[0]));
479 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
481 hr = IDirect3DDevice9_EndScene(device);
482 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
484 color = getPixelColor(device, 160, 360); /* Lower left quad - unlit without normals */
485 ok(color == 0x00ff0000, "Unlit quad without normals has color 0x%08x, expected 0x00ff0000.\n", color);
486 color = getPixelColor(device, 160, 120); /* Upper left quad - lit without normals */
487 ok(color == 0x00000000, "Lit quad without normals has color 0x%08x, expected 0x00000000.\n", color);
488 color = getPixelColor(device, 480, 360); /* Lower left quad - unlit with normals */
489 ok(color == 0x000000ff, "Unlit quad with normals has color 0x%08x, expected 0x000000ff.\n", color);
490 color = getPixelColor(device, 480, 120); /* Upper left quad - lit with normals */
491 ok(color == 0x00000000, "Lit quad with normals has color 0x%08x, expected 0x00000000.\n", color);
493 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
495 hr = IDirect3DDevice9_LightEnable(device, 0, TRUE);
496 ok(SUCCEEDED(hr), "Failed to enable light 0, hr %#x.\n", hr);
498 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
500 hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLD, tests[i].world_matrix);
501 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
503 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
504 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
506 hr = IDirect3DDevice9_BeginScene(device);
507 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
509 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4,
510 2, indices, D3DFMT_INDEX16, tests[i].quad, tests[i].size);
511 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
513 hr = IDirect3DDevice9_EndScene(device);
514 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
516 color = getPixelColor(device, 320, 240);
517 ok(color == tests[i].expected, "%s has color 0x%08x.\n", tests[i].message, color);
520 hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLD, &mat);
521 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
522 hr = IDirect3DDevice9_LightEnable(device, 0, FALSE);
523 ok(SUCCEEDED(hr), "Failed to disable light 0, hr %#x.\n", hr);
525 memset(&material, 0, sizeof(material));
526 material.Diffuse.r = 0.0;
527 material.Diffuse.g = 0.0;
528 material.Diffuse.b = 0.0;
529 material.Diffuse.a = 1.0;
530 material.Ambient.r = 0.0;
531 material.Ambient.g = 0.0;
532 material.Ambient.b = 0.0;
533 material.Ambient.a = 0.0;
534 material.Specular.r = 0.0;
535 material.Specular.g = 0.0;
536 material.Specular.b = 0.0;
537 material.Specular.a = 0.0;
538 material.Emissive.r = 0.0;
539 material.Emissive.g = 0.0;
540 material.Emissive.b = 0.0;
541 material.Emissive.a = 0.0;
542 material.Power = 0.0;
543 hr = IDirect3DDevice9_SetMaterial(device, &material);
544 ok(hr == D3D_OK, "IDirect3DDevice9_SetMaterial returned %08x\n", hr);
546 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);
547 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
548 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL);
549 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
551 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
552 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState returned %08x\n", hr);
553 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE | D3DTA_ALPHAREPLICATE);
554 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState returned %08x\n", hr);
556 hr = IDirect3DDevice9_BeginScene(device);
557 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
559 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
560 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
561 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, lighting_test, sizeof(lighting_test[0]));
562 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
564 hr = IDirect3DDevice9_EndScene(device);
565 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
567 color = getPixelColor(device, 320, 240);
568 ok(color == 0x00ffffff, "Lit vertex alpha test returned color %08x, expected 0x00ffffff\n", color);
569 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
571 refcount = IDirect3DDevice9_Release(device);
572 ok(!refcount, "Device has %u references left.\n", refcount);
573 done:
574 IDirect3D9_Release(d3d);
575 DestroyWindow(window);
578 static void test_specular_lighting(void)
580 static const unsigned int vertices_side = 5;
581 const unsigned int indices_count = (vertices_side - 1) * (vertices_side - 1) * 2 * 3;
582 static const DWORD fvf = D3DFVF_XYZ | D3DFVF_NORMAL;
583 static const D3DMATRIX mat =
585 1.0f, 0.0f, 0.0f, 0.0f,
586 0.0f, 1.0f, 0.0f, 0.0f,
587 0.0f, 0.0f, 1.0f, 0.0f,
588 0.0f, 0.0f, 0.0f, 1.0f,
589 }}};
590 static const D3DLIGHT9 directional =
592 D3DLIGHT_DIRECTIONAL,
593 {0.0f, 0.0f, 0.0f, 0.0f},
594 {1.0f, 1.0f, 1.0f, 0.0f},
595 {0.0f, 0.0f, 0.0f, 0.0f},
596 {0.0f, 0.0f, 0.0f},
597 {0.0f, 0.0f, 1.0f},
599 point =
601 D3DLIGHT_POINT,
602 {0.0f, 0.0f, 0.0f, 0.0f},
603 {1.0f, 1.0f, 1.0f, 0.0f},
604 {0.0f, 0.0f, 0.0f, 0.0f},
605 {0.0f, 0.0f, 0.0f},
606 {0.0f, 0.0f, 0.0f},
607 100.0f,
608 0.0f,
609 0.0f, 0.0f, 1.0f,
611 spot =
613 D3DLIGHT_SPOT,
614 {0.0f, 0.0f, 0.0f, 0.0f},
615 {1.0f, 1.0f, 1.0f, 0.0f},
616 {0.0f, 0.0f, 0.0f, 0.0f},
617 {0.0f, 0.0f, 0.0f},
618 {0.0f, 0.0f, 1.0f},
619 100.0f,
620 1.0f,
621 0.0f, 0.0f, 1.0f,
622 M_PI / 12.0f, M_PI / 3.0f
624 /* The chosen range value makes the test fail when using a manhattan
625 * distance metric vs the correct euclidean distance. */
626 point_range =
628 D3DLIGHT_POINT,
629 {0.0f, 0.0f, 0.0f, 0.0f},
630 {1.0f, 1.0f, 1.0f, 0.0f},
631 {0.0f, 0.0f, 0.0f, 0.0f},
632 {0.0f, 0.0f, 0.0f},
633 {0.0f, 0.0f, 0.0f},
634 1.2f,
635 0.0f,
636 0.0f, 0.0f, 1.0f,
638 static const struct expected_color
640 unsigned int x, y;
641 D3DCOLOR color;
643 expected_directional[] =
645 {160, 120, 0x00ffffff},
646 {320, 120, 0x00ffffff},
647 {480, 120, 0x00ffffff},
648 {160, 240, 0x00ffffff},
649 {320, 240, 0x00ffffff},
650 {480, 240, 0x00ffffff},
651 {160, 360, 0x00ffffff},
652 {320, 360, 0x00ffffff},
653 {480, 360, 0x00ffffff},
655 expected_directional_local[] =
657 {160, 120, 0x003c3c3c},
658 {320, 120, 0x00717171},
659 {480, 120, 0x003c3c3c},
660 {160, 240, 0x00717171},
661 {320, 240, 0x00ffffff},
662 {480, 240, 0x00717171},
663 {160, 360, 0x003c3c3c},
664 {320, 360, 0x00717171},
665 {480, 360, 0x003c3c3c},
667 expected_point[] =
669 {160, 120, 0x00282828},
670 {320, 120, 0x005a5a5a},
671 {480, 120, 0x00282828},
672 {160, 240, 0x005a5a5a},
673 {320, 240, 0x00ffffff},
674 {480, 240, 0x005a5a5a},
675 {160, 360, 0x00282828},
676 {320, 360, 0x005a5a5a},
677 {480, 360, 0x00282828},
679 expected_point_local[] =
681 {160, 120, 0x00000000},
682 {320, 120, 0x00070707},
683 {480, 120, 0x00000000},
684 {160, 240, 0x00070707},
685 {320, 240, 0x00ffffff},
686 {480, 240, 0x00070707},
687 {160, 360, 0x00000000},
688 {320, 360, 0x00070707},
689 {480, 360, 0x00000000},
691 expected_spot[] =
693 {160, 120, 0x00000000},
694 {320, 120, 0x00141414},
695 {480, 120, 0x00000000},
696 {160, 240, 0x00141414},
697 {320, 240, 0x00ffffff},
698 {480, 240, 0x00141414},
699 {160, 360, 0x00000000},
700 {320, 360, 0x00141414},
701 {480, 360, 0x00000000},
703 expected_spot_local[] =
705 {160, 120, 0x00000000},
706 {320, 120, 0x00020202},
707 {480, 120, 0x00000000},
708 {160, 240, 0x00020202},
709 {320, 240, 0x00ffffff},
710 {480, 240, 0x00020202},
711 {160, 360, 0x00000000},
712 {320, 360, 0x00020202},
713 {480, 360, 0x00000000},
715 expected_point_range[] =
717 {160, 120, 0x00000000},
718 {320, 120, 0x005a5a5a},
719 {480, 120, 0x00000000},
720 {160, 240, 0x005a5a5a},
721 {320, 240, 0x00ffffff},
722 {480, 240, 0x005a5a5a},
723 {160, 360, 0x00000000},
724 {320, 360, 0x005a5a5a},
725 {480, 360, 0x00000000},
727 static const struct
729 const D3DLIGHT9 *light;
730 BOOL local_viewer;
731 const struct expected_color *expected;
732 unsigned int expected_count;
734 tests[] =
736 {&directional, FALSE, expected_directional,
737 sizeof(expected_directional) / sizeof(expected_directional[0])},
738 {&directional, TRUE, expected_directional_local,
739 sizeof(expected_directional_local) / sizeof(expected_directional_local[0])},
740 {&point, FALSE, expected_point,
741 sizeof(expected_point) / sizeof(expected_point[0])},
742 {&point, TRUE, expected_point_local,
743 sizeof(expected_point_local) / sizeof(expected_point_local[0])},
744 {&spot, FALSE, expected_spot,
745 sizeof(expected_spot) / sizeof(expected_spot[0])},
746 {&spot, TRUE, expected_spot_local,
747 sizeof(expected_spot_local) / sizeof(expected_spot_local[0])},
748 {&point_range, FALSE, expected_point_range,
749 sizeof(expected_point_range) / sizeof(expected_point_range[0])},
751 IDirect3DDevice9 *device;
752 D3DMATERIAL9 material;
753 IDirect3D9 *d3d;
754 D3DCOLOR color;
755 ULONG refcount;
756 HWND window;
757 HRESULT hr;
758 unsigned int i, j, x, y;
759 struct
761 struct vec3 position;
762 struct vec3 normal;
763 } *quad;
764 WORD *indices;
766 quad = HeapAlloc(GetProcessHeap(), 0, vertices_side * vertices_side * sizeof(*quad));
767 indices = HeapAlloc(GetProcessHeap(), 0, indices_count * sizeof(*indices));
768 for (i = 0, y = 0; y < vertices_side; ++y)
770 for (x = 0; x < vertices_side; ++x)
772 quad[i].position.x = x * 2.0f / (vertices_side - 1) - 1.0f;
773 quad[i].position.y = y * 2.0f / (vertices_side - 1) - 1.0f;
774 quad[i].position.z = 1.0f;
775 quad[i].normal.x = 0.0f;
776 quad[i].normal.y = 0.0f;
777 quad[i++].normal.z = -1.0f;
780 for (i = 0, y = 0; y < (vertices_side - 1); ++y)
782 for (x = 0; x < (vertices_side - 1); ++x)
784 indices[i++] = y * vertices_side + x + 1;
785 indices[i++] = y * vertices_side + x;
786 indices[i++] = (y + 1) * vertices_side + x;
787 indices[i++] = y * vertices_side + x + 1;
788 indices[i++] = (y + 1) * vertices_side + x;
789 indices[i++] = (y + 1) * vertices_side + x + 1;
793 window = create_window();
794 d3d = Direct3DCreate9(D3D_SDK_VERSION);
795 ok(!!d3d, "Failed to create a D3D object.\n");
796 if (!(device = create_device(d3d, window, window, TRUE)))
798 skip("Failed to create a D3D device, skipping tests.\n");
799 goto done;
802 hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLD, &mat);
803 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
804 hr = IDirect3DDevice9_SetTransform(device, D3DTS_VIEW, &mat);
805 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
806 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &mat);
807 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
808 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, FALSE);
809 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
810 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
811 ok(SUCCEEDED(hr), "Failed to disable z test, hr %#x.\n", hr);
812 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGENABLE, FALSE);
813 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
815 hr = IDirect3DDevice9_SetFVF(device, fvf);
816 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
818 memset(&material, 0, sizeof(material));
819 material.Specular.r = 1.0f;
820 material.Specular.g = 1.0f;
821 material.Specular.b = 1.0f;
822 material.Specular.a = 1.0f;
823 material.Power = 30.0f;
824 hr = IDirect3DDevice9_SetMaterial(device, &material);
825 ok(SUCCEEDED(hr), "Failed to set material, hr %#x.\n", hr);
827 hr = IDirect3DDevice9_LightEnable(device, 0, TRUE);
828 ok(SUCCEEDED(hr), "Failed to enable light 0, hr %#x.\n", hr);
829 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SPECULARENABLE, TRUE);
830 ok(SUCCEEDED(hr), "Failed to enable specular lighting, hr %#x.\n", hr);
832 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
834 hr = IDirect3DDevice9_SetLight(device, 0, tests[i].light);
835 ok(SUCCEEDED(hr), "Failed to set light parameters, hr %#x.\n", hr);
837 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LOCALVIEWER, tests[i].local_viewer);
838 ok(SUCCEEDED(hr), "Failed to set local viewer state, hr %#x.\n", hr);
840 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
841 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
843 hr = IDirect3DDevice9_BeginScene(device);
844 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
846 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST,
847 0, vertices_side * vertices_side, indices_count / 3, indices,
848 D3DFMT_INDEX16, quad, sizeof(quad[0]));
849 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
851 hr = IDirect3DDevice9_EndScene(device);
852 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
854 for (j = 0; j < tests[i].expected_count; ++j)
856 color = getPixelColor(device, tests[i].expected[j].x, tests[i].expected[j].y);
857 ok(color_match(color, tests[i].expected[j].color, 1),
858 "Expected color 0x%08x at location (%u, %u), got 0x%08x, case %u.\n",
859 tests[i].expected[j].color, tests[i].expected[j].x,
860 tests[i].expected[j].y, color, i);
864 refcount = IDirect3DDevice9_Release(device);
865 ok(!refcount, "Device has %u references left.\n", refcount);
866 done:
867 IDirect3D9_Release(d3d);
868 DestroyWindow(window);
869 HeapFree(GetProcessHeap(), 0, indices);
870 HeapFree(GetProcessHeap(), 0, quad);
873 static void clear_test(void)
875 static const D3DMATRIX mat =
877 1.0f, 0.0f, 0.0f, 0.0f,
878 0.0f, 1.0f, 0.0f, 0.0f,
879 0.0f, 0.0f, 1.0f, 0.0f,
880 0.0f, 0.0f, 0.0f, 1.0f,
881 }}};
882 static const struct
884 struct vec3 position;
885 DWORD diffuse;
887 quad[] =
889 {{-1.0f, -1.0f, 0.1f}, 0xff7f7f7f},
890 {{ 1.0f, -1.0f, 0.1f}, 0xff7f7f7f},
891 {{-1.0f, 1.0f, 0.1f}, 0xff7f7f7f},
892 {{ 1.0f, 1.0f, 0.1f}, 0xff7f7f7f},
894 IDirect3DSurface9 *surface0, *surface1, *backbuffer;
895 IDirect3DTexture9 *texture;
896 HRESULT hr;
897 D3DRECT rect[2];
898 D3DRECT rect_negneg;
899 DWORD color;
900 D3DVIEWPORT9 old_vp, vp;
901 RECT scissor;
902 DWORD oldColorWrite;
903 BOOL invalid_clear_failed = FALSE, srgb_supported;
904 IDirect3DDevice9 *device;
905 IDirect3D9 *d3d;
906 ULONG refcount;
907 HWND window;
909 window = create_window();
910 d3d = Direct3DCreate9(D3D_SDK_VERSION);
911 ok(!!d3d, "Failed to create a D3D object.\n");
912 if (!(device = create_device(d3d, window, window, TRUE)))
914 skip("Failed to create a D3D device, skipping tests.\n");
915 goto done;
918 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
919 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
921 /* Positive x, negative y */
922 rect[0].x1 = 0;
923 rect[0].y1 = 480;
924 rect[0].x2 = 320;
925 rect[0].y2 = 240;
927 /* Positive x, positive y */
928 rect[1].x1 = 0;
929 rect[1].y1 = 0;
930 rect[1].x2 = 320;
931 rect[1].y2 = 240;
932 /* Clear 2 rectangles with one call. The refrast returns an error in this case, every real driver tested so far
933 * returns D3D_OK, but ignores the rectangle silently
935 hr = IDirect3DDevice9_Clear(device, 2, rect, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
936 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_Clear failed with %08x\n", hr);
937 if(hr == D3DERR_INVALIDCALL) invalid_clear_failed = TRUE;
939 /* negative x, negative y */
940 rect_negneg.x1 = 640;
941 rect_negneg.y1 = 240;
942 rect_negneg.x2 = 320;
943 rect_negneg.y2 = 0;
944 hr = IDirect3DDevice9_Clear(device, 1, &rect_negneg, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
945 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_Clear failed with %08x\n", hr);
946 if(hr == D3DERR_INVALIDCALL) invalid_clear_failed = TRUE;
948 color = getPixelColor(device, 160, 360); /* lower left quad */
949 ok(color == 0x00ffffff, "Clear rectangle 3(pos, neg) has color %08x\n", color);
950 color = getPixelColor(device, 160, 120); /* upper left quad */
951 if(invalid_clear_failed) {
952 /* If the negative rectangle was refused, the other rectangles in the list shouldn't be cleared either */
953 ok(color == 0x00ffffff, "Clear rectangle 1(pos, pos) has color %08x\n", color);
954 } else {
955 /* If the negative rectangle was dropped silently, the correct ones are cleared */
956 ok(color == 0x00ff0000, "Clear rectangle 1(pos, pos) has color %08x\n", color);
958 color = getPixelColor(device, 480, 360); /* lower right quad */
959 ok(color == 0x00ffffff, "Clear rectangle 4(NULL) has color %08x\n", color);
960 color = getPixelColor(device, 480, 120); /* upper right quad */
961 ok(color == 0x00ffffff, "Clear rectangle 4(neg, neg) has color %08x\n", color);
963 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
965 /* Hack to work around a nvidia windows driver bug. The clear below is supposed to
966 * clear the red quad in the top left part of the render target. For some reason it
967 * doesn't work if the clear color is 0xffffffff on some versions of the Nvidia Windows
968 * driver(tested on 8.17.12.5896, Win7). A clear with a different color works around
969 * this bug and fixes the clear with the white color. Even 0xfeffffff works, but let's
970 * pick some obvious value
972 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xdeadbabe, 0.0, 0);
973 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
975 /* Test how the viewport affects clears */
976 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
977 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
978 hr = IDirect3DDevice9_GetViewport(device, &old_vp);
979 ok(hr == D3D_OK, "IDirect3DDevice9_GetViewport failed with %08x\n", hr);
981 vp.X = 160;
982 vp.Y = 120;
983 vp.Width = 160;
984 vp.Height = 120;
985 vp.MinZ = 0.0;
986 vp.MaxZ = 1.0;
987 hr = IDirect3DDevice9_SetViewport(device, &vp);
988 ok(hr == D3D_OK, "IDirect3DDevice9_SetViewport failed with %08x\n", hr);
989 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0, 0);
990 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
992 vp.X = 320;
993 vp.Y = 240;
994 vp.Width = 320;
995 vp.Height = 240;
996 vp.MinZ = 0.0;
997 vp.MaxZ = 1.0;
998 hr = IDirect3DDevice9_SetViewport(device, &vp);
999 ok(hr == D3D_OK, "IDirect3DDevice9_SetViewport failed with %08x\n", hr);
1000 rect[0].x1 = 160;
1001 rect[0].y1 = 120;
1002 rect[0].x2 = 480;
1003 rect[0].y2 = 360;
1004 hr = IDirect3DDevice9_Clear(device, 1, &rect[0], D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
1005 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
1007 hr = IDirect3DDevice9_SetViewport(device, &old_vp);
1008 ok(hr == D3D_OK, "IDirect3DDevice9_SetViewport failed with %08x\n", hr);
1010 color = getPixelColor(device, 158, 118);
1011 ok(color == 0x00ffffff, "(158,118) has color %08x\n", color);
1012 color = getPixelColor(device, 162, 118);
1013 ok(color == 0x00ffffff, "(162,118) has color %08x\n", color);
1014 color = getPixelColor(device, 158, 122);
1015 ok(color == 0x00ffffff, "(158,122) has color %08x\n", color);
1016 color = getPixelColor(device, 162, 122);
1017 ok(color == 0x000000ff, "(162,122) has color %08x\n", color);
1019 color = getPixelColor(device, 318, 238);
1020 ok(color == 0x000000ff, "(318,238) has color %08x\n", color);
1021 color = getPixelColor(device, 322, 238);
1022 ok(color == 0x00ffffff, "(322,328) has color %08x\n", color);
1023 color = getPixelColor(device, 318, 242);
1024 ok(color == 0x00ffffff, "(318,242) has color %08x\n", color);
1025 color = getPixelColor(device, 322, 242);
1026 ok(color == 0x0000ff00, "(322,242) has color %08x\n", color);
1028 color = getPixelColor(device, 478, 358);
1029 ok(color == 0x0000ff00, "(478,358 has color %08x\n", color);
1030 color = getPixelColor(device, 482, 358);
1031 ok(color == 0x00ffffff, "(482,358) has color %08x\n", color);
1032 color = getPixelColor(device, 478, 362);
1033 ok(color == 0x00ffffff, "(478,362) has color %08x\n", color);
1034 color = getPixelColor(device, 482, 362);
1035 ok(color == 0x00ffffff, "(482,362) has color %08x\n", color);
1037 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
1039 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
1040 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
1042 SetRect(&scissor, 160, 120, 480, 360);
1043 hr = IDirect3DDevice9_SetScissorRect(device, &scissor);
1044 ok(hr == D3D_OK, "IDirect3DDevice_SetScissorRect failed with %08x\n", hr);
1045 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SCISSORTESTENABLE, TRUE);
1046 ok(hr == D3D_OK, "IDirect3DDevice_SetScissorRect failed with %08x\n", hr);
1048 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
1049 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
1050 hr = IDirect3DDevice9_Clear(device, 1, &rect[1], D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
1051 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
1053 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SCISSORTESTENABLE, FALSE);
1054 ok(hr == D3D_OK, "IDirect3DDevice_SetScissorRect failed with %08x\n", hr);
1056 color = getPixelColor(device, 158, 118);
1057 ok(color == 0x00ffffff, "Pixel 158/118 has color %08x\n", color);
1058 color = getPixelColor(device, 162, 118);
1059 ok(color == 0x00ffffff, "Pixel 162/118 has color %08x\n", color);
1060 color = getPixelColor(device, 158, 122);
1061 ok(color == 0x00ffffff, "Pixel 158/122 has color %08x\n", color);
1062 color = getPixelColor(device, 162, 122);
1063 ok(color == 0x00ff0000, "Pixel 162/122 has color %08x\n", color);
1065 color = getPixelColor(device, 158, 358);
1066 ok(color == 0x00ffffff, "Pixel 158/358 has color %08x\n", color);
1067 color = getPixelColor(device, 162, 358);
1068 ok(color == 0x0000ff00, "Pixel 162/358 has color %08x\n", color);
1069 color = getPixelColor(device, 158, 358);
1070 ok(color == 0x00ffffff, "Pixel 158/358 has color %08x\n", color);
1071 color = getPixelColor(device, 162, 362);
1072 ok(color == 0x00ffffff, "Pixel 162/362 has color %08x\n", color);
1074 color = getPixelColor(device, 478, 118);
1075 ok(color == 0x00ffffff, "Pixel 158/118 has color %08x\n", color);
1076 color = getPixelColor(device, 478, 122);
1077 ok(color == 0x0000ff00, "Pixel 162/118 has color %08x\n", color);
1078 color = getPixelColor(device, 482, 122);
1079 ok(color == 0x00ffffff, "Pixel 158/122 has color %08x\n", color);
1080 color = getPixelColor(device, 482, 358);
1081 ok(color == 0x00ffffff, "Pixel 162/122 has color %08x\n", color);
1083 color = getPixelColor(device, 478, 358);
1084 ok(color == 0x0000ff00, "Pixel 478/358 has color %08x\n", color);
1085 color = getPixelColor(device, 478, 362);
1086 ok(color == 0x00ffffff, "Pixel 478/118 has color %08x\n", color);
1087 color = getPixelColor(device, 482, 358);
1088 ok(color == 0x00ffffff, "Pixel 482/122 has color %08x\n", color);
1089 color = getPixelColor(device, 482, 362);
1090 ok(color == 0x00ffffff, "Pixel 482/122 has color %08x\n", color);
1092 color = getPixelColor(device, 318, 238);
1093 ok(color == 0x00ff0000, "Pixel 318/238 has color %08x\n", color);
1094 color = getPixelColor(device, 318, 242);
1095 ok(color == 0x0000ff00, "Pixel 318/242 has color %08x\n", color);
1096 color = getPixelColor(device, 322, 238);
1097 ok(color == 0x0000ff00, "Pixel 322/238 has color %08x\n", color);
1098 color = getPixelColor(device, 322, 242);
1099 ok(color == 0x0000ff00, "Pixel 322/242 has color %08x\n", color);
1101 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
1103 hr = IDirect3DDevice9_GetRenderState(device, D3DRS_COLORWRITEENABLE, &oldColorWrite);
1104 ok(hr == D3D_OK, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr);
1105 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED);
1106 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with %08x\n", hr);
1108 /* Same nvidia windows driver trouble with white clears as earlier in the same test */
1109 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xdeadbeef, 0.0, 0);
1110 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
1112 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
1113 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
1115 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_COLORWRITEENABLE, oldColorWrite);
1116 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with %08x\n", hr);
1118 /* Colorwriteenable does not affect the clear */
1119 color = getPixelColor(device, 320, 240);
1120 ok(color == 0x00ffffff, "Color write protected clear returned color %08x\n", color);
1122 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
1124 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00ffffff, 0.0, 0);
1125 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear failed with %08x\n", hr);
1127 rect[0].x1 = 0;
1128 rect[0].y1 = 0;
1129 rect[0].x2 = 640;
1130 rect[0].y2 = 480;
1131 hr = IDirect3DDevice9_Clear(device, 0, rect, D3DCLEAR_TARGET, 0x00ff0000, 0.0, 0);
1132 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear failed with %08x\n", hr);
1134 color = getPixelColor(device, 320, 240);
1135 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0xff), 1),
1136 "Clear with count = 0, rect != NULL has color %08x\n", color);
1138 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
1140 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
1141 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear failed with %08x\n", hr);
1142 hr = IDirect3DDevice9_Clear(device, 1, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
1143 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear failed with %08x\n", hr);
1145 color = getPixelColor(device, 320, 240);
1146 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1),
1147 "Clear with count = 1, rect = NULL has color %08x\n", color);
1149 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
1151 /* Test D3DRS_SRGBWRITEENABLE interactions with clears. */
1152 srgb_supported = SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
1153 D3DUSAGE_QUERY_SRGBWRITE, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8));
1154 trace("sRGB writing to D3DFMT_A8R8G8B8 is %ssupported.\n", srgb_supported ? "" : "not ");
1155 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x7f7f7f7f, 0.0, 0);
1156 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
1158 color = getPixelColor(device, 320, 240);
1159 ok(color_match(color, 0x007f7f7f, 1), "Clear has color %08x.\n", color);
1161 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SRGBWRITEENABLE, TRUE);
1162 ok(SUCCEEDED(hr), "Failed to enable sRGB write, hr %#x.\n", hr);
1164 /* Draw something to make sure the SRGBWRITEENABLE setting is applied. */
1165 hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLD, &mat);
1166 ok(SUCCEEDED(hr), "Failed to set world matrix, hr %#x.\n", hr);
1167 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, FALSE);
1168 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
1169 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
1170 ok(SUCCEEDED(hr), "Failed to disable z test, hr %#x.\n", hr);
1171 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGENABLE, FALSE);
1172 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
1173 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILENABLE, FALSE);
1174 ok(SUCCEEDED(hr), "Failed to disable stencil test, hr %#x.\n", hr);
1175 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE);
1176 ok(SUCCEEDED(hr), "Failed to disable culling, hr %#x.\n", hr);
1177 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
1178 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
1179 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
1180 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
1181 hr = IDirect3DDevice9_BeginScene(device);
1182 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1183 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad));
1184 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1185 hr = IDirect3DDevice9_EndScene(device);
1186 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1188 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x7f7f7f7f, 0.0, 0);
1189 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
1191 color = getPixelColor(device, 320, 240);
1192 ok(color_match(color, 0x00bbbbbb, 1), "Clear has color %08x.\n", color);
1194 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SRGBWRITEENABLE, FALSE);
1195 ok(SUCCEEDED(hr), "Failed to disable sRGB write, hr %#x.\n", hr);
1197 /* Switching to a new render target seems to be enough to make Windows pick
1198 * up on the changed render state. */
1199 hr = IDirect3DDevice9_CreateTexture(device, 128, 128, 2, D3DUSAGE_RENDERTARGET,
1200 D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &texture, NULL);
1201 ok(SUCCEEDED(hr), "Failed to create the offscreen render target, hr %#x.\n", hr);
1202 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
1203 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
1204 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface0);
1205 ok(SUCCEEDED(hr), "Failed to get offscreen surface, hr %#x.\n", hr);
1206 hr = IDirect3DDevice9_SetRenderTarget(device, 0, surface0);
1207 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
1209 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x7f7f7f7f, 0.0, 0);
1210 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
1212 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
1213 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
1215 hr = IDirect3DDevice9_StretchRect(device, surface0, NULL, backbuffer, NULL, D3DTEXF_NONE);
1216 ok(SUCCEEDED(hr), "Failed to blit surface, hr %#x.\n", hr);
1218 color = getPixelColor(device, 64, 64);
1219 ok(color_match(color, 0x007f7f7f, 1), "Clear has color %08x.\n", color);
1221 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SRGBWRITEENABLE, TRUE);
1222 ok(SUCCEEDED(hr), "Failed to enable sRGB write, hr %#x.\n", hr);
1224 hr = IDirect3DDevice9_SetRenderTarget(device, 0, surface0);
1225 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
1227 hr = IDirect3DDevice9_BeginScene(device);
1228 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1229 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad));
1230 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1231 hr = IDirect3DDevice9_EndScene(device);
1232 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1234 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x7f7f7f7f, 0.0, 0);
1235 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
1237 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
1238 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
1240 hr = IDirect3DDevice9_StretchRect(device, surface0, NULL, backbuffer, NULL, D3DTEXF_NONE);
1241 ok(SUCCEEDED(hr), "Failed to blit surface, hr %#x.\n", hr);
1243 color = getPixelColor(device, 320, 240);
1244 ok(color_match(color, 0x00bbbbbb, 1), "Clear has color %08x.\n", color);
1246 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SRGBWRITEENABLE, FALSE);
1247 ok(SUCCEEDED(hr), "Failed to disable sRGB write, hr %#x.\n", hr);
1248 /* Switching to another surface of the same texture is also enough to make
1249 * the setting "stick". */
1250 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 1, &surface1);
1251 ok(SUCCEEDED(hr), "Failed to get offscreen surface, hr %#x.\n", hr);
1252 hr = IDirect3DDevice9_SetRenderTarget(device, 0, surface1);
1253 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
1255 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x7f7f7f7f, 0.0, 0);
1256 ok(SUCCEEDED(hr), "Failed to clear, hr %#x\n", hr);
1258 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
1259 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
1261 hr = IDirect3DDevice9_StretchRect(device, surface1, NULL, backbuffer, NULL, D3DTEXF_NONE);
1262 ok(SUCCEEDED(hr), "Failed to blit surface, hr %#x.\n", hr);
1264 color = getPixelColor(device, 320, 240);
1265 ok(color_match(color, 0x007f7f7f, 1), "Clear has color %08x.\n", color);
1267 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
1269 IDirect3DSurface9_Release(surface1);
1270 IDirect3DSurface9_Release(surface0);
1271 IDirect3DSurface9_Release(backbuffer);
1272 IDirect3DTexture9_Release(texture);
1273 refcount = IDirect3DDevice9_Release(device);
1274 ok(!refcount, "Device has %u references left.\n", refcount);
1275 done:
1276 IDirect3D9_Release(d3d);
1277 DestroyWindow(window);
1280 static void color_fill_test(void)
1282 IDirect3DSurface9 *surface;
1283 IDirect3DTexture9 *texture;
1284 D3DCOLOR fill_color, color;
1285 DWORD fill_a, expected_a;
1286 IDirect3DDevice9 *device;
1287 IDirect3D9 *d3d;
1288 ULONG refcount;
1289 HWND window;
1290 HRESULT hr;
1291 static const struct
1293 D3DPOOL pool;
1294 DWORD usage;
1295 HRESULT hr;
1297 resource_types[] =
1299 {D3DPOOL_DEFAULT, 0, D3DERR_INVALIDCALL},
1300 {D3DPOOL_DEFAULT, D3DUSAGE_DYNAMIC, D3DERR_INVALIDCALL},
1301 {D3DPOOL_DEFAULT, D3DUSAGE_RENDERTARGET, D3D_OK},
1302 {D3DPOOL_SYSTEMMEM, 0, D3DERR_INVALIDCALL},
1303 {D3DPOOL_MANAGED, 0, D3DERR_INVALIDCALL},
1304 {D3DPOOL_SCRATCH, 0, D3DERR_INVALIDCALL},
1306 static const struct
1308 D3DFORMAT format;
1309 const char *name;
1310 enum
1312 CHECK_FILL_VALUE = 0x1,
1313 BLOCKS = 0x2,
1314 } flags;
1315 DWORD fill_value;
1317 formats[] =
1319 {D3DFMT_A8R8G8B8, "D3DFMT_A8R8G8B8", CHECK_FILL_VALUE, 0xdeadbeef},
1320 /* D3DFMT_X8R8G8B8 either set X = A or X = 0, depending on the driver. */
1321 {D3DFMT_R5G6B5, "D3DFMT_R5G6B5", CHECK_FILL_VALUE, 0xadfdadfd},
1322 {D3DFMT_G16R16, "D3DFMT_G16R16", CHECK_FILL_VALUE, 0xbebeadad},
1323 /* Real hardware reliably fills the surface with the blue channel but
1324 * the testbot fills it with 0x00. Wine incorrectly uses the alpha
1325 * channel. Don't bother checking the result because P8 surfaces are
1326 * essentially useless in d3d9. */
1327 {D3DFMT_P8, "D3DFMT_P8", 0, 0xefefefef},
1328 /* Windows drivers produce different results for these formats.
1329 * No driver produces a YUV value that matches the input RGB
1330 * value, and no driver produces a proper DXT compression block.
1332 * Even the clear value 0 does not reliably produce a fill value
1333 * that will return vec4(0.0, 0.0, 0.0, 0.0) when sampled.
1335 * The YUV tests are disabled because they produce a driver-dependent
1336 * result on Wine.
1337 * {D3DFMT_YUY2, "D3DFMT_YUY2", BLOCKS, 0},
1338 * {D3DFMT_UYVY, "D3DFMT_UYVY", BLOCKS, 0}, */
1339 {D3DFMT_DXT1, "D3DFMT_DXT1", BLOCKS, 0x00000000},
1340 /* Vendor-specific formats like ATI2N are a non-issue here since they're not
1341 * supported as offscreen plain surfaces and do not support D3DUSAGE_RENDERTARGET
1342 * when created as texture. */
1344 unsigned int i;
1345 D3DLOCKED_RECT locked_rect;
1346 DWORD *surface_data;
1347 static const RECT rect = {4, 4, 8, 8}, rect2 = {5, 5, 7, 7};
1349 window = create_window();
1350 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1351 ok(!!d3d, "Failed to create a D3D object.\n");
1352 if (!(device = create_device(d3d, window, window, TRUE)))
1354 skip("Failed to create a D3D device, skipping tests.\n");
1355 goto done;
1358 /* Test ColorFill on a the backbuffer (should pass) */
1359 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &surface);
1360 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
1362 fill_color = 0x112233;
1363 hr = IDirect3DDevice9_ColorFill(device, surface, NULL, fill_color);
1364 ok(SUCCEEDED(hr), "Color fill failed, hr %#x.\n", hr);
1366 color = getPixelColor(device, 0, 0);
1367 ok(color == fill_color, "Expected color %08x, got %08x\n", fill_color, color);
1369 IDirect3DSurface9_Release(surface);
1371 /* Test ColorFill on a render target surface (should pass) */
1372 hr = IDirect3DDevice9_CreateRenderTarget(device, 32, 32, D3DFMT_A8R8G8B8,
1373 D3DMULTISAMPLE_NONE, 0, TRUE, &surface, NULL );
1374 ok(hr == D3D_OK, "Unable to create render target surface, hr = %08x\n", hr);
1376 fill_color = 0x445566;
1377 hr = IDirect3DDevice9_ColorFill(device, surface, NULL, fill_color);
1378 ok(SUCCEEDED(hr), "Color fill failed, hr %#x.\n", hr);
1380 color = getPixelColorFromSurface(surface, 0, 0);
1381 ok(color == fill_color, "Expected color %08x, got %08x\n", fill_color, color);
1383 IDirect3DSurface9_Release(surface);
1385 /* Test ColorFill on an offscreen plain surface in D3DPOOL_DEFAULT (should pass) */
1386 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 32, 32,
1387 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL);
1388 ok(hr == D3D_OK, "Unable to create offscreen plain surface, hr = %08x\n", hr);
1390 fill_color = 0x778899;
1391 hr = IDirect3DDevice9_ColorFill(device, surface, NULL, fill_color);
1392 ok(SUCCEEDED(hr), "Color fill failed, hr %#x.\n", hr);
1394 color = getPixelColorFromSurface(surface, 0, 0);
1395 ok(color == fill_color, "Expected color %08x, got %08x\n", fill_color, color);
1397 IDirect3DSurface9_Release(surface);
1399 /* Try ColorFill on an offscreen surface in sysmem (should fail) */
1400 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 32, 32,
1401 D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surface, NULL);
1402 ok(hr == D3D_OK, "Unable to create offscreen plain surface, hr = %08x\n", hr);
1404 hr = IDirect3DDevice9_ColorFill(device, surface, NULL, 0);
1405 ok(hr == D3DERR_INVALIDCALL, "ColorFill on offscreen sysmem surface failed with hr = %08x\n", hr);
1407 IDirect3DSurface9_Release(surface);
1409 hr = IDirect3DDevice9_CreateDepthStencilSurface(device, 32, 32, D3DFMT_D16,
1410 D3DMULTISAMPLE_NONE, 0, TRUE, &surface, NULL);
1411 ok(SUCCEEDED(hr), "Failed to create depth stencil surface, hr = %08x.\n", hr);
1413 hr = IDirect3DDevice9_ColorFill(device, surface, NULL, 0);
1414 ok(hr == D3DERR_INVALIDCALL, "ColorFill on a depth stencil surface returned hr = %08x.\n", hr);
1416 IDirect3DSurface9_Release(surface);
1418 for (i = 0; i < sizeof(resource_types) / sizeof(resource_types[0]); i++)
1420 texture = NULL;
1421 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, resource_types[i].usage,
1422 D3DFMT_A8R8G8B8, resource_types[i].pool, &texture, NULL);
1423 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x, i=%u.\n", hr, i);
1424 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
1425 ok(SUCCEEDED(hr), "Failed to get surface, hr %#x, i=%u.\n", hr, i);
1427 hr = IDirect3DDevice9_ColorFill(device, surface, NULL, fill_color);
1428 ok(hr == resource_types[i].hr, "Got unexpected hr %#x, expected %#x, i=%u.\n",
1429 hr, resource_types[i].hr, i);
1431 IDirect3DSurface9_Release(surface);
1432 IDirect3DTexture9_Release(texture);
1435 for (i = 0; i < sizeof(formats) / sizeof(formats[0]); i++)
1437 if (IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL,
1438 D3DFMT_X8R8G8B8, 0, D3DRTYPE_SURFACE, formats[i].format) != D3D_OK)
1440 skip("Offscreenplain %s surfaces not supported, skipping colorfill test\n", formats[i].name);
1441 continue;
1444 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 32, 32,
1445 formats[i].format, D3DPOOL_DEFAULT, &surface, NULL);
1446 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, fmt=%s.\n", hr, formats[i].name);
1448 hr = IDirect3DDevice9_ColorFill(device, surface, NULL, 0xdeadbeef);
1449 ok(SUCCEEDED(hr), "Failed to color fill, hr %#x, fmt=%s.\n", hr, formats[i].name);
1451 hr = IDirect3DDevice9_ColorFill(device, surface, &rect, 0xdeadbeef);
1452 ok(SUCCEEDED(hr), "Failed to color fill, hr %#x, fmt=%s.\n", hr, formats[i].name);
1454 if (SUCCEEDED(hr))
1456 hr = IDirect3DDevice9_ColorFill(device, surface, &rect2, 0xdeadbeef);
1457 if (formats[i].flags & BLOCKS)
1458 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, fmt=%s.\n", hr, formats[i].name);
1459 else
1460 ok(SUCCEEDED(hr), "Failed to color fill, hr %#x, fmt=%s.\n", hr, formats[i].name);
1463 if (formats[i].flags & CHECK_FILL_VALUE)
1465 hr = IDirect3DSurface9_LockRect(surface, &locked_rect, NULL, D3DLOCK_READONLY);
1466 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, fmt=%s.\n", hr, formats[i].name);
1467 surface_data = locked_rect.pBits;
1468 fill_a = (surface_data[0] & 0xff000000) >> 24;
1469 expected_a = (formats[i].fill_value & 0xff000000) >> 24;
1470 /* Windows drivers disagree on how to promote the 8 bit per channel
1471 * input argument to 16 bit for D3DFMT_G16R16. */
1472 ok(color_match(surface_data[0], formats[i].fill_value, 2) &&
1473 abs((expected_a) - (fill_a)) < 3,
1474 "Expected clear value 0x%08x, got 0x%08x, fmt=%s.\n",
1475 formats[i].fill_value, surface_data[0], formats[i].name);
1476 hr = IDirect3DSurface9_UnlockRect(surface);
1477 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, fmt=%s.\n", hr, formats[i].name);
1480 IDirect3DSurface9_Release(surface);
1483 refcount = IDirect3DDevice9_Release(device);
1484 ok(!refcount, "Device has %u references left.\n", refcount);
1485 done:
1486 IDirect3D9_Release(d3d);
1487 DestroyWindow(window);
1491 * c7 mova ARGB mov ARGB
1492 * -2.4 -2 0x00ffff00 -3 0x00ff0000
1493 * -1.6 -2 0x00ffff00 -2 0x00ffff00
1494 * -0.4 0 0x0000ffff -1 0x0000ff00
1495 * 0.4 0 0x0000ffff 0 0x0000ffff
1496 * 1.6 2 0x00ff00ff 1 0x000000ff
1497 * 2.4 2 0x00ff00ff 2 0x00ff00ff
1499 static void test_mova(void)
1501 IDirect3DVertexDeclaration9 *vertex_declaration;
1502 IDirect3DVertexShader9 *mova_shader;
1503 IDirect3DVertexShader9 *mov_shader;
1504 IDirect3DDevice9 *device;
1505 unsigned int i, j;
1506 IDirect3D9 *d3d;
1507 ULONG refcount;
1508 D3DCAPS9 caps;
1509 HWND window;
1510 HRESULT hr;
1512 static const DWORD mova_test[] =
1514 0xfffe0200, /* vs_2_0 */
1515 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
1516 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 1.0, 0.0, 0.0, 1.0 */
1517 0x05000051, 0xa00f0001, 0x3f800000, 0x3f800000, 0x00000000, 0x3f800000, /* def c1, 1.0, 1.0, 0.0, 1.0 */
1518 0x05000051, 0xa00f0002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, /* def c2, 0.0, 1.0, 0.0, 1.0 */
1519 0x05000051, 0xa00f0003, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c3, 0.0, 1.0, 1.0, 1.0 */
1520 0x05000051, 0xa00f0004, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, /* def c4, 0.0, 0.0, 1.0, 1.0 */
1521 0x05000051, 0xa00f0005, 0x3f800000, 0x00000000, 0x3f800000, 0x3f800000, /* def c5, 1.0, 0.0, 1.0, 1.0 */
1522 0x05000051, 0xa00f0006, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c6, 1.0, 1.0, 1.0, 1.0 */
1523 0x0200002e, 0xb0010000, 0xa0000007, /* mova a0.x, c7.x */
1524 0x03000001, 0xd00f0000, 0xa0e42003, 0xb0000000, /* mov oD0, c[a0.x + 3] */
1525 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
1526 0x0000ffff /* END */
1528 static const DWORD mov_test[] =
1530 0xfffe0101, /* vs_1_1 */
1531 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
1532 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 1.0, 0.0, 0.0, 1.0 */
1533 0x00000051, 0xa00f0001, 0x3f800000, 0x3f800000, 0x00000000, 0x3f800000, /* def c1, 1.0, 1.0, 0.0, 1.0 */
1534 0x00000051, 0xa00f0002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, /* def c2, 0.0, 1.0, 0.0, 1.0 */
1535 0x00000051, 0xa00f0003, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c3, 0.0, 1.0, 1.0, 1.0 */
1536 0x00000051, 0xa00f0004, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, /* def c4, 0.0, 0.0, 1.0, 1.0 */
1537 0x00000051, 0xa00f0005, 0x3f800000, 0x00000000, 0x3f800000, 0x3f800000, /* def c5, 1.0, 0.0, 1.0, 1.0 */
1538 0x00000051, 0xa00f0006, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c6, 1.0, 1.0, 1.0, 1.0 */
1539 0x00000001, 0xb0010000, 0xa0000007, /* mov a0.x, c7.x */
1540 0x00000001, 0xd00f0000, 0xa0e42003, /* mov oD0, c[a0.x + 3] */
1541 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
1542 0x0000ffff /* END */
1544 static const struct
1546 float in[4];
1547 DWORD out;
1549 test_data[2][6] =
1552 {{-2.4f, 0.0f, 0.0f, 0.0f}, 0x00ff0000},
1553 {{-1.6f, 0.0f, 0.0f, 0.0f}, 0x00ffff00},
1554 {{-0.4f, 0.0f, 0.0f, 0.0f}, 0x0000ff00},
1555 {{ 0.4f, 0.0f, 0.0f, 0.0f}, 0x0000ffff},
1556 {{ 1.6f, 0.0f, 0.0f, 0.0f}, 0x000000ff},
1557 {{ 2.4f, 0.0f, 0.0f, 0.0f}, 0x00ff00ff}
1560 {{-2.4f, 0.0f, 0.0f, 0.0f}, 0x00ffff00},
1561 {{-1.6f, 0.0f, 0.0f, 0.0f}, 0x00ffff00},
1562 {{-0.4f, 0.0f, 0.0f, 0.0f}, 0x0000ffff},
1563 {{ 0.4f, 0.0f, 0.0f, 0.0f}, 0x0000ffff},
1564 {{ 1.6f, 0.0f, 0.0f, 0.0f}, 0x00ff00ff},
1565 {{ 2.4f, 0.0f, 0.0f, 0.0f}, 0x00ff00ff}
1568 static const struct vec3 quad[] =
1570 {-1.0f, -1.0f, 0.0f},
1571 {-1.0f, 1.0f, 0.0f},
1572 { 1.0f, -1.0f, 0.0f},
1573 { 1.0f, 1.0f, 0.0f},
1575 static const D3DVERTEXELEMENT9 decl_elements[] =
1577 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
1578 D3DDECL_END()
1581 window = create_window();
1582 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1583 ok(!!d3d, "Failed to create a D3D object.\n");
1584 if (!(device = create_device(d3d, window, window, TRUE)))
1586 skip("Failed to create a D3D device, skipping tests.\n");
1587 goto done;
1590 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
1591 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
1592 if (caps.VertexShaderVersion < D3DVS_VERSION(2, 0))
1594 skip("No vs_2_0 support, skipping tests.\n");
1595 IDirect3DDevice9_Release(device);
1596 goto done;
1599 hr = IDirect3DDevice9_CreateVertexShader(device, mova_test, &mova_shader);
1600 ok(SUCCEEDED(hr), "CreateVertexShader failed (%08x)\n", hr);
1601 hr = IDirect3DDevice9_CreateVertexShader(device, mov_test, &mov_shader);
1602 ok(SUCCEEDED(hr), "CreateVertexShader failed (%08x)\n", hr);
1603 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &vertex_declaration);
1604 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (%08x)\n", hr);
1605 hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration);
1606 ok(SUCCEEDED(hr), "SetVertexDeclaration failed (%08x)\n", hr);
1608 hr = IDirect3DDevice9_SetVertexShader(device, mov_shader);
1609 ok(SUCCEEDED(hr), "SetVertexShader failed (%08x)\n", hr);
1610 for (j = 0; j < sizeof(test_data) / sizeof(*test_data); ++j)
1612 for (i = 0; i < sizeof(*test_data) / sizeof(**test_data); ++i)
1614 DWORD color;
1616 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 7, test_data[j][i].in, 1);
1617 ok(SUCCEEDED(hr), "SetVertexShaderConstantF failed (%08x)\n", hr);
1619 hr = IDirect3DDevice9_BeginScene(device);
1620 ok(SUCCEEDED(hr), "BeginScene failed (%08x)\n", hr);
1622 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
1623 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%08x)\n", hr);
1625 hr = IDirect3DDevice9_EndScene(device);
1626 ok(SUCCEEDED(hr), "EndScene failed (%08x)\n", hr);
1628 color = getPixelColor(device, 320, 240);
1629 ok(color == test_data[j][i].out, "Expected color %08x, got %08x (for input %f, instruction %s)\n",
1630 test_data[j][i].out, color, test_data[j][i].in[0], j == 0 ? "mov" : "mova");
1632 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
1633 ok(SUCCEEDED(hr), "Present failed (%08x)\n", hr);
1635 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0, 0.0f, 0);
1636 ok(SUCCEEDED(hr), "Clear failed (%08x)\n", hr);
1638 hr = IDirect3DDevice9_SetVertexShader(device, mova_shader);
1639 ok(SUCCEEDED(hr), "SetVertexShader failed (%08x)\n", hr);
1642 IDirect3DVertexDeclaration9_Release(vertex_declaration);
1643 IDirect3DVertexShader9_Release(mova_shader);
1644 IDirect3DVertexShader9_Release(mov_shader);
1645 refcount = IDirect3DDevice9_Release(device);
1646 ok(!refcount, "Device has %u references left.\n", refcount);
1647 done:
1648 IDirect3D9_Release(d3d);
1649 DestroyWindow(window);
1652 static void fog_test(void)
1654 float start = 0.0f, end = 1.0f;
1655 IDirect3DDevice9 *device;
1656 IDirect3D9 *d3d;
1657 D3DCOLOR color;
1658 ULONG refcount;
1659 D3DCAPS9 caps;
1660 HWND window;
1661 HRESULT hr;
1662 int i;
1664 /* Gets full z based fog with linear fog, no fog with specular color. */
1665 static const struct
1667 float x, y, z;
1668 D3DCOLOR diffuse;
1669 D3DCOLOR specular;
1671 untransformed_1[] =
1673 {-1.0f, -1.0f, 0.1f, 0xffff0000, 0xff000000},
1674 {-1.0f, 0.0f, 0.1f, 0xffff0000, 0xff000000},
1675 { 0.0f, 0.0f, 0.1f, 0xffff0000, 0xff000000},
1676 { 0.0f, -1.0f, 0.1f, 0xffff0000, 0xff000000},
1678 /* Ok, I am too lazy to deal with transform matrices. */
1679 untransformed_2[] =
1681 {-1.0f, 0.0f, 1.0f, 0xffff0000, 0xff000000},
1682 {-1.0f, 1.0f, 1.0f, 0xffff0000, 0xff000000},
1683 { 0.0f, 1.0f, 1.0f, 0xffff0000, 0xff000000},
1684 { 0.0f, 0.0f, 1.0f, 0xffff0000, 0xff000000},
1686 untransformed_3[] =
1688 {-1.0f, -1.0f, 0.5f, 0xffff0000, 0xff000000},
1689 {-1.0f, 1.0f, 0.5f, 0xffff0000, 0xff000000},
1690 { 1.0f, -1.0f, 0.5f, 0xffff0000, 0xff000000},
1691 { 1.0f, 1.0f, 0.5f, 0xffff0000, 0xff000000},
1693 far_quad1[] =
1695 {-1.0f, -1.0f, 0.5f, 0xffff0000, 0xff000000},
1696 {-1.0f, 0.0f, 0.5f, 0xffff0000, 0xff000000},
1697 { 0.0f, 0.0f, 0.5f, 0xffff0000, 0xff000000},
1698 { 0.0f, -1.0f, 0.5f, 0xffff0000, 0xff000000},
1700 far_quad2[] =
1702 {-1.0f, 0.0f, 1.5f, 0xffff0000, 0xff000000},
1703 {-1.0f, 1.0f, 1.5f, 0xffff0000, 0xff000000},
1704 { 0.0f, 1.0f, 1.5f, 0xffff0000, 0xff000000},
1705 { 0.0f, 0.0f, 1.5f, 0xffff0000, 0xff000000},
1707 /* Untransformed ones. Give them a different diffuse color to make the
1708 * test look nicer. It also makes making sure that they are drawn
1709 * correctly easier. */
1710 static const struct
1712 float x, y, z, rhw;
1713 D3DCOLOR diffuse;
1714 D3DCOLOR specular;
1716 transformed_1[] =
1718 {320.0f, 0.0f, 1.0f, 1.0f, 0xffffff00, 0xff000000},
1719 {640.0f, 0.0f, 1.0f, 1.0f, 0xffffff00, 0xff000000},
1720 {640.0f, 240.0f, 1.0f, 1.0f, 0xffffff00, 0xff000000},
1721 {320.0f, 240.0f, 1.0f, 1.0f, 0xffffff00, 0xff000000},
1723 transformed_2[] =
1725 {320.0f, 240.0f, 1.0f, 1.0f, 0xffffff00, 0xff000000},
1726 {640.0f, 240.0f, 1.0f, 1.0f, 0xffffff00, 0xff000000},
1727 {640.0f, 480.0f, 1.0f, 1.0f, 0xffffff00, 0xff000000},
1728 {320.0f, 480.0f, 1.0f, 1.0f, 0xffffff00, 0xff000000},
1730 static const struct
1732 struct vec3 position;
1733 DWORD diffuse;
1735 rev_fog_quads[] =
1737 {{-1.0f, -1.0f, 0.1f}, 0x000000ff},
1738 {{-1.0f, 0.0f, 0.1f}, 0x000000ff},
1739 {{ 0.0f, 0.0f, 0.1f}, 0x000000ff},
1740 {{ 0.0f, -1.0f, 0.1f}, 0x000000ff},
1742 {{ 0.0f, -1.0f, 0.9f}, 0x000000ff},
1743 {{ 0.0f, 0.0f, 0.9f}, 0x000000ff},
1744 {{ 1.0f, 0.0f, 0.9f}, 0x000000ff},
1745 {{ 1.0f, -1.0f, 0.9f}, 0x000000ff},
1747 {{ 0.0f, 0.0f, 0.4f}, 0x000000ff},
1748 {{ 0.0f, 1.0f, 0.4f}, 0x000000ff},
1749 {{ 1.0f, 1.0f, 0.4f}, 0x000000ff},
1750 {{ 1.0f, 0.0f, 0.4f}, 0x000000ff},
1752 {{-1.0f, 0.0f, 0.7f}, 0x000000ff},
1753 {{-1.0f, 1.0f, 0.7f}, 0x000000ff},
1754 {{ 0.0f, 1.0f, 0.7f}, 0x000000ff},
1755 {{ 0.0f, 0.0f, 0.7f}, 0x000000ff},
1757 static const D3DMATRIX ident_mat =
1759 1.0f, 0.0f, 0.0f, 0.0f,
1760 0.0f, 1.0f, 0.0f, 0.0f,
1761 0.0f, 0.0f, 1.0f, 0.0f,
1762 0.0f, 0.0f, 0.0f, 1.0f
1763 }}};
1764 static const D3DMATRIX world_mat1 =
1766 1.0f, 0.0f, 0.0f, 0.0f,
1767 0.0f, 1.0f, 0.0f, 0.0f,
1768 0.0f, 0.0f, 1.0f, 0.0f,
1769 0.0f, 0.0f, -0.5f, 1.0f
1770 }}};
1771 static const D3DMATRIX world_mat2 =
1773 1.0f, 0.0f, 0.0f, 0.0f,
1774 0.0f, 1.0f, 0.0f, 0.0f,
1775 0.0f, 0.0f, 1.0f, 0.0f,
1776 0.0f, 0.0f, 1.0f, 1.0f
1777 }}};
1778 static const D3DMATRIX proj_mat =
1780 1.0f, 0.0f, 0.0f, 0.0f,
1781 0.0f, 1.0f, 0.0f, 0.0f,
1782 0.0f, 0.0f, 1.0f, 0.0f,
1783 0.0f, 0.0f, -1.0f, 1.0f
1784 }}};
1785 static const WORD Indices[] = {0, 1, 2, 2, 3, 0};
1786 static const WORD Indices2[] =
1788 0, 1, 2, 2, 3, 0,
1789 4, 5, 6, 6, 7, 4,
1790 8, 9, 10, 10, 11, 8,
1791 12, 13, 14, 14, 15, 12,
1794 window = create_window();
1795 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1796 ok(!!d3d, "Failed to create a D3D object.\n");
1797 if (!(device = create_device(d3d, window, window, TRUE)))
1799 skip("Failed to create a D3D device, skipping tests.\n");
1800 goto done;
1803 memset(&caps, 0, sizeof(caps));
1804 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
1805 ok(hr == D3D_OK, "IDirect3DDevice9_GetDeviceCaps returned %08x\n", hr);
1806 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
1807 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
1809 /* Setup initial states: No lighting, fog on, fog color */
1810 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
1811 ok(SUCCEEDED(hr), "Failed to disable D3DRS_ZENABLE, hr %#x.\n", hr);
1812 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
1813 ok(hr == D3D_OK, "Turning off lighting returned %08x\n", hr);
1814 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGENABLE, TRUE);
1815 ok(hr == D3D_OK, "Turning on fog calculations returned %08x\n", hr);
1816 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGCOLOR, 0xff00ff00 /* A nice green */);
1817 ok(hr == D3D_OK, "Setting fog color returned %#08x\n", hr);
1818 /* Some of the tests seem to depend on the projection matrix explicitly
1819 * being set to an identity matrix, even though that's the default.
1820 * (AMD Radeon HD 6310, Windows 7) */
1821 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &ident_mat);
1822 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
1824 /* First test: Both table fog and vertex fog off */
1825 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_NONE);
1826 ok(hr == D3D_OK, "Turning off table fog returned %08x\n", hr);
1827 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGVERTEXMODE, D3DFOG_NONE);
1828 ok(hr == D3D_OK, "Turning off vertex fog returned %08x\n", hr);
1830 /* Start = 0, end = 1. Should be default, but set them */
1831 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGSTART, *((DWORD *) &start));
1832 ok(hr == D3D_OK, "Setting fog start returned %08x\n", hr);
1833 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGEND, *((DWORD *) &end));
1834 ok(hr == D3D_OK, "Setting fog end returned %08x\n", hr);
1836 hr = IDirect3DDevice9_BeginScene(device);
1837 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1839 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
1840 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
1842 /* Untransformed, vertex fog = NONE, table fog = NONE:
1843 * Read the fog weighting from the specular color. */
1844 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
1845 2 /* PrimCount */, Indices, D3DFMT_INDEX16, untransformed_1, sizeof(untransformed_1[0]));
1846 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1848 /* That makes it use the Z value */
1849 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR);
1850 ok(SUCCEEDED(hr), "Failed to set D3DFOG_LINEAR fog vertex mode, hr %#x.\n", hr);
1851 /* Untransformed, vertex fog != none (or table fog != none):
1852 * Use the Z value as input into the equation. */
1853 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
1854 2 /* PrimCount */, Indices, D3DFMT_INDEX16, untransformed_2, sizeof(untransformed_2[0]));
1855 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1857 /* transformed verts */
1858 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
1859 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
1860 /* Transformed, vertex fog != NONE, pixel fog == NONE:
1861 * Use specular color alpha component. */
1862 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
1863 2 /* PrimCount */, Indices, D3DFMT_INDEX16, transformed_1, sizeof(transformed_1[0]));
1864 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1866 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);
1867 ok(SUCCEEDED(hr), "Failed to set D3DFOG_LINEAR fog table mode, hr %#x.\n", hr);
1868 /* Transformed, table fog != none, vertex anything:
1869 * Use Z value as input to the fog equation. */
1870 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
1871 2 /* PrimCount */, Indices, D3DFMT_INDEX16, transformed_2, sizeof(transformed_2[0]));
1872 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1874 hr = IDirect3DDevice9_EndScene(device);
1875 ok(hr == D3D_OK, "EndScene returned %08x\n", hr);
1877 color = getPixelColor(device, 160, 360);
1878 ok(color == 0x00ff0000, "Untransformed vertex with no table or vertex fog has color %08x\n", color);
1879 color = getPixelColor(device, 160, 120);
1880 ok(color_match(color, 0x0000ff00, 1), "Untransformed vertex with linear vertex fog has color %08x\n", color);
1881 color = getPixelColor(device, 480, 120);
1882 ok(color == 0x00ffff00, "Transformed vertex with linear vertex fog has color %08x\n", color);
1883 if(caps.RasterCaps & D3DPRASTERCAPS_FOGTABLE)
1885 color = getPixelColor(device, 480, 360);
1886 ok(color_match(color, 0x0000ff00, 1), "Transformed vertex with linear table fog has color %08x\n", color);
1888 else
1890 /* Without fog table support the vertex fog is still applied, even though table fog is turned on.
1891 * The settings above result in no fogging with vertex fog
1893 color = getPixelColor(device, 480, 120);
1894 ok(color == 0x00ffff00, "Transformed vertex with linear vertex fog has color %08x\n", color);
1895 trace("Info: Table fog not supported by this device\n");
1897 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
1899 /* Now test the special case fogstart == fogend */
1900 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0, 0);
1901 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
1903 hr = IDirect3DDevice9_BeginScene(device);
1904 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1906 start = 512;
1907 end = 512;
1908 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGSTART, *((DWORD *)&start));
1909 ok(SUCCEEDED(hr), "Failed to set fog start, hr %#x.\n", hr);
1910 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGEND, *((DWORD *)&end));
1911 ok(SUCCEEDED(hr), "Failed to set fog end, hr %#x.\n", hr);
1913 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
1914 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
1915 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR);
1916 ok(SUCCEEDED(hr), "Failed to set D3DFOG_LINEAR fog vertex mode, hr %#x.\n", hr);
1917 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_NONE);
1918 ok(SUCCEEDED(hr), "Failed to set D3DFOG_NONE fog table mode, hr %#x.\n", hr);
1920 /* Untransformed vertex, z coord = 0.1, fogstart = 512, fogend = 512.
1921 * Would result in a completely fog-free primitive because start > zcoord,
1922 * but because start == end, the primitive is fully covered by fog. The
1923 * same happens to the 2nd untransformed quad with z = 1.0. The third
1924 * transformed quad remains unfogged because the fogcoords are read from
1925 * the specular color and has fixed fogstart and fogend. */
1926 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
1927 2 /* PrimCount */, Indices, D3DFMT_INDEX16, untransformed_1, sizeof(untransformed_1[0]));
1928 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1929 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
1930 2 /* PrimCount */, Indices, D3DFMT_INDEX16, untransformed_2, sizeof(untransformed_2[0]));
1931 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1933 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
1934 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
1935 /* Transformed, vertex fog != NONE, pixel fog == NONE:
1936 * Use specular color alpha component. */
1937 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
1938 2 /* PrimCount */, Indices, D3DFMT_INDEX16, transformed_1, sizeof(transformed_1[0]));
1939 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1941 hr = IDirect3DDevice9_EndScene(device);
1942 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1944 color = getPixelColor(device, 160, 360);
1945 ok(color_match(color, 0x0000ff00, 1), "Untransformed vertex with vertex fog and z = 0.1 has color %08x\n", color);
1946 color = getPixelColor(device, 160, 120);
1947 ok(color_match(color, 0x0000ff00, 1), "Untransformed vertex with vertex fog and z = 1.0 has color %08x\n", color);
1948 color = getPixelColor(device, 480, 120);
1949 ok(color == 0x00ffff00, "Transformed vertex with linear vertex fog has color %08x\n", color);
1950 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
1952 /* Test "reversed" fog without shaders. With shaders this fails on a few Windows D3D implementations,
1953 * but without shaders it seems to work everywhere
1955 end = 0.2;
1956 start = 0.8;
1957 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGSTART, *((DWORD *) &start));
1958 ok(hr == D3D_OK, "Setting fog start returned %08x\n", hr);
1959 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGEND, *((DWORD *) &end));
1960 ok(hr == D3D_OK, "Setting fog end returned %08x\n", hr);
1961 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
1962 ok( hr == D3D_OK, "IDirect3DDevice9_SetFVF returned %08x\n", hr);
1964 /* Test reversed fog without shaders. ATI cards have problems with reversed fog and shaders, so
1965 * it doesn't seem very important for games. ATI cards also have problems with reversed table fog,
1966 * so skip this for now
1968 for(i = 0; i < 1 /*2 - Table fog test disabled, fails on ATI */; i++) {
1969 const char *mode = (i ? "table" : "vertex");
1970 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
1971 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
1972 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGVERTEXMODE, i == 0 ? D3DFOG_LINEAR : D3DFOG_NONE);
1973 ok( hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
1974 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, i == 0 ? D3DFOG_NONE : D3DFOG_LINEAR);
1975 ok( hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
1976 hr = IDirect3DDevice9_BeginScene(device);
1977 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1978 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 16 /* NumVerts */,
1979 8 /* PrimCount */, Indices2, D3DFMT_INDEX16, rev_fog_quads, sizeof(rev_fog_quads[0]));
1980 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1981 hr = IDirect3DDevice9_EndScene(device);
1982 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1984 color = getPixelColor(device, 160, 360);
1985 ok(color_match(color, 0x0000ff00, 1),
1986 "Reversed %s fog: z=0.1 has color 0x%08x, expected 0x0000ff00 or 0x0000fe00\n", mode, color);
1988 color = getPixelColor(device, 160, 120);
1989 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0x2b, 0xd4), 2),
1990 "Reversed %s fog: z=0.7 has color 0x%08x\n", mode, color);
1992 color = getPixelColor(device, 480, 120);
1993 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xaa, 0x55), 2),
1994 "Reversed %s fog: z=0.4 has color 0x%08x\n", mode, color);
1996 color = getPixelColor(device, 480, 360);
1997 ok(color == 0x000000ff, "Reversed %s fog: z=0.9 has color 0x%08x, expected 0x000000ff\n", mode, color);
1999 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
2001 if(!(caps.RasterCaps & D3DPRASTERCAPS_FOGTABLE)) {
2002 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping reversed table fog test\n");
2003 break;
2007 if (caps.RasterCaps & D3DPRASTERCAPS_FOGTABLE)
2009 /* A simple fog + non-identity world matrix test */
2010 hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLDMATRIX(0), &world_mat1);
2011 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform returned %#08x\n", hr);
2013 start = 0.0;
2014 end = 1.0;
2015 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGSTART, *((DWORD *)&start));
2016 ok(hr == D3D_OK, "Setting fog start returned %08x\n", hr);
2017 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGEND, *((DWORD *)&end));
2018 ok(hr == D3D_OK, "Setting fog end returned %08x\n", hr);
2019 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);
2020 ok(hr == D3D_OK, "Setting fog table mode to D3DFOG_LINEAR returned %#08x\n", hr);
2021 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGVERTEXMODE, D3DFOG_NONE);
2022 ok(hr == D3D_OK, "Turning off vertex fog returned %#08x\n", hr);
2024 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
2025 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %#08x\n", hr);
2027 hr = IDirect3DDevice9_BeginScene(device);
2028 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
2030 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
2031 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
2033 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4,
2034 2, Indices, D3DFMT_INDEX16, far_quad1, sizeof(far_quad1[0]));
2035 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
2036 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4,
2037 2, Indices, D3DFMT_INDEX16, far_quad2, sizeof(far_quad2[0]));
2038 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
2040 hr = IDirect3DDevice9_EndScene(device);
2041 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
2043 color = getPixelColor(device, 160, 360);
2044 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x00), 4),
2045 "Unfogged quad has color %08x\n", color);
2046 color = getPixelColor(device, 160, 120);
2047 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1),
2048 "Fogged out quad has color %08x\n", color);
2050 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
2052 /* Test fog behavior with an orthogonal (but non-identity) projection matrix */
2053 hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLDMATRIX(0), &world_mat2);
2054 ok(hr == D3D_OK, "SetTransform returned %#08x\n", hr);
2055 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &proj_mat);
2056 ok(hr == D3D_OK, "SetTransform returned %#08x\n", hr);
2058 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
2059 ok(hr == D3D_OK, "Clear returned %#08x\n", hr);
2061 hr = IDirect3DDevice9_BeginScene(device);
2062 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
2064 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
2065 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
2067 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4,
2068 2, Indices, D3DFMT_INDEX16, untransformed_1, sizeof(untransformed_1[0]));
2069 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
2070 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4,
2071 2, Indices, D3DFMT_INDEX16, untransformed_2, sizeof(untransformed_2[0]));
2072 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
2074 hr = IDirect3DDevice9_EndScene(device);
2075 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
2077 color = getPixelColor(device, 160, 360);
2078 ok(color_match(color, 0x00e51900, 4), "Partially fogged quad has color %08x\n", color);
2079 color = getPixelColor(device, 160, 120);
2080 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1),
2081 "Fogged out quad has color %08x\n", color);
2083 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
2085 hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLDMATRIX(0), &ident_mat);
2086 ok(hr == D3D_OK, "SetTransform returned %#08x\n", hr);
2087 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &ident_mat);
2088 ok(hr == D3D_OK, "SetTransform returned %#08x\n", hr);
2090 else
2092 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests\n");
2095 /* Test RANGEFOG vs FOGTABLEMODE */
2096 if ((caps.RasterCaps & (D3DPRASTERCAPS_FOGTABLE | D3DPRASTERCAPS_FOGRANGE)) ==
2097 (D3DPRASTERCAPS_FOGTABLE | D3DPRASTERCAPS_FOGRANGE))
2099 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
2100 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear failed, hr %#x.\n", hr);
2101 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
2102 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetFVF failed, hr %#x.\n", hr);
2104 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_RANGEFOGENABLE, TRUE);
2105 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr);
2107 /* z=0.5, x = +/- 1.0, y = +/- 1.0. In case of z fog the fog coordinate is
2108 * 0.5. With range fog it is sqrt(x*x + y*y + z*z) = 1.5 for all vertices.
2109 * Note that the fog coordinate is interpolated linearly across the vertices,
2110 * so the different eye distance at the screen center should not matter. */
2111 start = 0.75f;
2112 end = 0.75001f;
2113 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGSTART, *((DWORD *) &start));
2114 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr);
2115 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGEND, *((DWORD *) &end));
2116 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr);
2118 /* Table fog: Range fog is not used */
2119 hr = IDirect3DDevice9_BeginScene(device);
2120 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
2122 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);
2123 ok(SUCCEEDED(hr), "Failed to set D3DFOG_LINEAR fog table mode, hr %#x.\n", hr);
2124 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2,
2125 untransformed_3, sizeof(*untransformed_3));
2126 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
2128 hr = IDirect3DDevice9_EndScene(device);
2129 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
2131 color = getPixelColor(device, 10, 10);
2132 ok(color == 0x00ff0000, "Rangefog with table fog returned color 0x%08x\n", color);
2133 color = getPixelColor(device, 630, 10);
2134 ok(color == 0x00ff0000, "Rangefog with table fog returned color 0x%08x\n", color);
2135 color = getPixelColor(device, 10, 470);
2136 ok(color == 0x00ff0000, "Rangefog with table fog returned color 0x%08x\n", color);
2137 color = getPixelColor(device, 630, 470);
2138 ok(color == 0x00ff0000, "Rangefog with table fog returned color 0x%08x\n", color);
2140 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
2141 ok(SUCCEEDED(hr), "IDirect3DDevice9_Present failed, hr %#x.\n", hr);
2143 /* Vertex fog: Rangefog is used */
2144 hr = IDirect3DDevice9_BeginScene(device);
2145 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
2147 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_NONE);
2148 ok(SUCCEEDED(hr), "Failed to set D3DFOG_NONE fog table mode, hr %#x.\n", hr);
2149 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR);
2150 ok(SUCCEEDED(hr), "Failed to set D3DFOG_LINEAR fog vertex mode, hr %#x.\n", hr);
2151 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2,
2152 untransformed_3, sizeof(*untransformed_3));
2153 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
2155 hr = IDirect3DDevice9_EndScene(device);
2156 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
2158 color = getPixelColor(device, 10, 10);
2159 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1),
2160 "Rangefog with vertex fog returned color 0x%08x\n", color);
2161 color = getPixelColor(device, 630, 10);
2162 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1),
2163 "Rangefog with vertex fog returned color 0x%08x\n", color);
2164 color = getPixelColor(device, 10, 470);
2165 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1),
2166 "Rangefog with vertex fog returned color 0x%08x\n", color);
2167 color = getPixelColor(device, 630, 470);
2168 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1),
2169 "Rangefog with vertex fog returned color 0x%08x\n", color);
2171 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
2172 ok(SUCCEEDED(hr), "IDirect3DDevice9_Present failed, hr %#x.\n", hr);
2174 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_RANGEFOGENABLE, FALSE);
2175 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr);
2177 else
2179 skip("Range fog or table fog not supported, skipping range fog tests\n");
2182 refcount = IDirect3DDevice9_Release(device);
2183 ok(!refcount, "Device has %u references left.\n", refcount);
2184 done:
2185 IDirect3D9_Release(d3d);
2186 DestroyWindow(window);
2189 /* This test verifies the behaviour of cube maps wrt. texture wrapping.
2190 * D3D cube map wrapping always behaves like GL_CLAMP_TO_EDGE,
2191 * regardless of the actual addressing mode set. The way this test works is
2192 * that we sample in one of the corners of the cubemap with filtering enabled,
2193 * and check the interpolated color. There are essentially two reasonable
2194 * things an implementation can do: Either pick one of the faces and
2195 * interpolate the edge texel with itself (i.e., clamp within the face), or
2196 * interpolate between the edge texels of the three involved faces. It should
2197 * never involve the border color or the other side (texcoord wrapping) of a
2198 * face in the interpolation. */
2199 static void test_cube_wrap(void)
2201 IDirect3DVertexDeclaration9 *vertex_declaration;
2202 IDirect3DSurface9 *face_surface, *surface;
2203 IDirect3DCubeTexture9 *texture;
2204 D3DLOCKED_RECT locked_rect;
2205 IDirect3DDevice9 *device;
2206 unsigned int x, y, face;
2207 IDirect3D9 *d3d;
2208 ULONG refcount;
2209 D3DCAPS9 caps;
2210 HWND window;
2211 HRESULT hr;
2213 static const float quad[][6] =
2215 {-1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f},
2216 {-1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f},
2217 { 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f},
2218 { 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f},
2220 static const D3DVERTEXELEMENT9 decl_elements[] =
2222 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
2223 {0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
2224 D3DDECL_END()
2226 static const struct
2228 D3DTEXTUREADDRESS mode;
2229 const char *name;
2231 address_modes[] =
2233 {D3DTADDRESS_WRAP, "D3DTADDRESS_WRAP"},
2234 {D3DTADDRESS_MIRROR, "D3DTADDRESS_MIRROR"},
2235 {D3DTADDRESS_CLAMP, "D3DTADDRESS_CLAMP"},
2236 {D3DTADDRESS_BORDER, "D3DTADDRESS_BORDER"},
2237 {D3DTADDRESS_MIRRORONCE, "D3DTADDRESS_MIRRORONCE"},
2240 window = create_window();
2241 d3d = Direct3DCreate9(D3D_SDK_VERSION);
2242 ok(!!d3d, "Failed to create a D3D object.\n");
2243 if (!(device = create_device(d3d, window, window, TRUE)))
2245 skip("Failed to create a D3D device, skipping tests.\n");
2246 goto done;
2249 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
2250 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
2251 if (!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP))
2253 skip("No cube texture support, skipping tests.\n");
2254 IDirect3DDevice9_Release(device);
2255 goto done;
2258 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &vertex_declaration);
2259 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (0x%08x)\n", hr);
2260 hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration);
2261 ok(SUCCEEDED(hr), "SetVertexDeclaration failed (0x%08x)\n", hr);
2263 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 128, 128,
2264 D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surface, NULL);
2265 ok(SUCCEEDED(hr), "CreateOffscreenPlainSurface failed (0x%08x)\n", hr);
2267 hr = IDirect3DDevice9_CreateCubeTexture(device, 128, 1, 0, D3DFMT_A8R8G8B8,
2268 D3DPOOL_DEFAULT, &texture, NULL);
2269 ok(SUCCEEDED(hr), "CreateCubeTexture failed (0x%08x)\n", hr);
2271 hr = IDirect3DSurface9_LockRect(surface, &locked_rect, NULL, 0);
2272 ok(SUCCEEDED(hr), "LockRect failed (0x%08x)\n", hr);
2274 for (y = 0; y < 128; ++y)
2276 DWORD *ptr = (DWORD *)(((BYTE *)locked_rect.pBits) + (y * locked_rect.Pitch));
2277 for (x = 0; x < 64; ++x)
2279 *ptr++ = 0xff0000ff;
2281 for (x = 64; x < 128; ++x)
2283 *ptr++ = 0xffff0000;
2287 hr = IDirect3DSurface9_UnlockRect(surface);
2288 ok(SUCCEEDED(hr), "UnlockRect failed (0x%08x)\n", hr);
2290 hr= IDirect3DCubeTexture9_GetCubeMapSurface(texture, 0, 0, &face_surface);
2291 ok(SUCCEEDED(hr), "GetCubeMapSurface failed (0x%08x)\n", hr);
2293 hr = IDirect3DDevice9_UpdateSurface(device, surface, NULL, face_surface, NULL);
2294 ok(SUCCEEDED(hr), "UpdateSurface failed (0x%08x)\n", hr);
2296 IDirect3DSurface9_Release(face_surface);
2298 hr = IDirect3DSurface9_LockRect(surface, &locked_rect, NULL, 0);
2299 ok(SUCCEEDED(hr), "LockRect failed (0x%08x)\n", hr);
2301 for (y = 0; y < 128; ++y)
2303 DWORD *ptr = (DWORD *)(((BYTE *)locked_rect.pBits) + (y * locked_rect.Pitch));
2304 for (x = 0; x < 64; ++x)
2306 *ptr++ = 0xffff0000;
2308 for (x = 64; x < 128; ++x)
2310 *ptr++ = 0xff0000ff;
2314 hr = IDirect3DSurface9_UnlockRect(surface);
2315 ok(SUCCEEDED(hr), "UnlockRect failed (0x%08x)\n", hr);
2317 /* Create cube faces */
2318 for (face = 1; face < 6; ++face)
2320 hr= IDirect3DCubeTexture9_GetCubeMapSurface(texture, face, 0, &face_surface);
2321 ok(SUCCEEDED(hr), "GetCubeMapSurface failed (0x%08x)\n", hr);
2323 hr = IDirect3DDevice9_UpdateSurface(device, surface, NULL, face_surface, NULL);
2324 ok(SUCCEEDED(hr), "UpdateSurface failed (0x%08x)\n", hr);
2326 IDirect3DSurface9_Release(face_surface);
2329 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
2330 ok(SUCCEEDED(hr), "SetTexture failed (0x%08x)\n", hr);
2332 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
2333 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_MINFILTER failed (0x%08x)\n", hr);
2334 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
2335 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr);
2336 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_BORDERCOLOR, 0xff00ff00);
2337 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_BORDERCOLOR failed (0x%08x)\n", hr);
2339 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
2340 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
2342 for (x = 0; x < (sizeof(address_modes) / sizeof(*address_modes)); ++x)
2344 DWORD color;
2346 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSU, address_modes[x].mode);
2347 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_ADDRESSU (%s) failed (0x%08x)\n", address_modes[x].name, hr);
2348 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSV, address_modes[x].mode);
2349 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_ADDRESSV (%s) failed (0x%08x)\n", address_modes[x].name, hr);
2351 hr = IDirect3DDevice9_BeginScene(device);
2352 ok(SUCCEEDED(hr), "BeginScene failed (0x%08x)\n", hr);
2354 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], sizeof(quad[0]));
2355 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (0x%08x)\n", hr);
2357 hr = IDirect3DDevice9_EndScene(device);
2358 ok(SUCCEEDED(hr), "EndScene failed (0x%08x)\n", hr);
2360 color = getPixelColor(device, 320, 240);
2361 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0xff), 1),
2362 "Got color 0x%08x for addressing mode %s, expected 0x000000ff.\n",
2363 color, address_modes[x].name);
2365 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
2366 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
2368 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0, 0.0f, 0);
2369 ok(SUCCEEDED(hr), "Clear failed (0x%08x)\n", hr);
2372 IDirect3DVertexDeclaration9_Release(vertex_declaration);
2373 IDirect3DCubeTexture9_Release(texture);
2374 IDirect3DSurface9_Release(surface);
2375 refcount = IDirect3DDevice9_Release(device);
2376 ok(!refcount, "Device has %u references left.\n", refcount);
2377 done:
2378 IDirect3D9_Release(d3d);
2379 DestroyWindow(window);
2382 static void offscreen_test(void)
2384 IDirect3DSurface9 *backbuffer, *offscreen;
2385 IDirect3DTexture9 *offscreenTexture;
2386 IDirect3DDevice9 *device;
2387 IDirect3D9 *d3d;
2388 D3DCOLOR color;
2389 ULONG refcount;
2390 HWND window;
2391 HRESULT hr;
2393 static const float quad[][5] =
2395 {-0.5f, -0.5f, 0.1f, 0.0f, 0.0f},
2396 {-0.5f, 0.5f, 0.1f, 0.0f, 1.0f},
2397 { 0.5f, -0.5f, 0.1f, 1.0f, 0.0f},
2398 { 0.5f, 0.5f, 0.1f, 1.0f, 1.0f},
2401 window = create_window();
2402 d3d = Direct3DCreate9(D3D_SDK_VERSION);
2403 ok(!!d3d, "Failed to create a D3D object.\n");
2404 if (!(device = create_device(d3d, window, window, TRUE)))
2406 skip("Failed to create a D3D device, skipping tests.\n");
2407 goto done;
2410 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 1.0f, 0);
2411 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
2413 hr = IDirect3DDevice9_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET,
2414 D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &offscreenTexture, NULL);
2415 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Creating the offscreen render target failed, hr = %08x\n", hr);
2416 if (!offscreenTexture)
2418 trace("Failed to create an X8R8G8B8 offscreen texture, trying R5G6B5.\n");
2419 hr = IDirect3DDevice9_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET,
2420 D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &offscreenTexture, NULL);
2421 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Creating the offscreen render target failed, hr = %08x\n", hr);
2422 if (!offscreenTexture)
2424 skip("Cannot create an offscreen render target.\n");
2425 IDirect3DDevice9_Release(device);
2426 goto done;
2430 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
2431 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
2433 hr = IDirect3DTexture9_GetSurfaceLevel(offscreenTexture, 0, &offscreen);
2434 ok(hr == D3D_OK, "Can't get offscreen surface, hr = %08x\n", hr);
2436 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
2437 ok(hr == D3D_OK, "SetFVF failed, hr = %08x\n", hr);
2439 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
2440 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
2441 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
2442 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
2443 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
2444 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_MINFILTER failed (0x%08x)\n", hr);
2445 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
2446 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr);
2447 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
2448 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
2450 hr = IDirect3DDevice9_BeginScene(device);
2451 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
2453 hr = IDirect3DDevice9_SetRenderTarget(device, 0, offscreen);
2454 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
2455 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 1.0f, 0);
2456 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
2458 /* Draw without textures - Should result in a white quad. */
2459 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
2460 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
2462 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
2463 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
2464 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)offscreenTexture);
2465 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
2467 /* This time with the texture. */
2468 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
2469 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
2471 hr = IDirect3DDevice9_EndScene(device);
2472 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
2474 /* Center quad - should be white */
2475 color = getPixelColor(device, 320, 240);
2476 ok(color == 0x00ffffff, "Offscreen failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
2477 /* Some quad in the cleared part of the texture */
2478 color = getPixelColor(device, 170, 240);
2479 ok(color == 0x00ff00ff, "Offscreen failed: Got color 0x%08x, expected 0x00ff00ff.\n", color);
2480 /* Part of the originally cleared back buffer */
2481 color = getPixelColor(device, 10, 10);
2482 ok(color == 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
2483 color = getPixelColor(device, 10, 470);
2484 ok(color == 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
2486 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
2488 IDirect3DSurface9_Release(backbuffer);
2489 IDirect3DTexture9_Release(offscreenTexture);
2490 IDirect3DSurface9_Release(offscreen);
2491 refcount = IDirect3DDevice9_Release(device);
2492 ok(!refcount, "Device has %u references left.\n", refcount);
2493 done:
2494 IDirect3D9_Release(d3d);
2495 DestroyWindow(window);
2498 /* This test tests fog in combination with shaders.
2499 * What's tested: linear fog (vertex and table) with pixel shader
2500 * linear table fog with non foggy vertex shader
2501 * vertex fog with foggy vertex shader, non-linear
2502 * fog with shader, non-linear fog with foggy shader,
2503 * linear table fog with foggy shader */
2504 static void fog_with_shader_test(void)
2506 IDirect3DVertexShader9 *vertex_shader[4] = {NULL, NULL, NULL, NULL};
2507 IDirect3DPixelShader9 *pixel_shader[3] = {NULL, NULL, NULL};
2508 IDirect3DVertexDeclaration9 *vertex_declaration = NULL;
2509 IDirect3DDevice9 *device;
2510 unsigned int i, j;
2511 IDirect3D9 *d3d;
2512 ULONG refcount;
2513 D3DCAPS9 caps;
2514 DWORD color;
2515 HWND window;
2516 HRESULT hr;
2517 union
2519 float f;
2520 DWORD i;
2521 } start, end;
2523 /* basic vertex shader without fog computation ("non foggy") */
2524 static const DWORD vertex_shader_code1[] =
2526 0xfffe0101, /* vs_1_1 */
2527 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
2528 0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
2529 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
2530 0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
2531 0x0000ffff
2533 /* basic vertex shader with reversed fog computation ("foggy") */
2534 static const DWORD vertex_shader_code2[] =
2536 0xfffe0101, /* vs_1_1 */
2537 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
2538 0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
2539 0x00000051, 0xa00f0000, 0xbfa00000, 0x00000000, 0xbf666666, 0x00000000, /* def c0, -1.25, 0.0, -0.9, 0.0 */
2540 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
2541 0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
2542 0x00000002, 0x800f0000, 0x90aa0000, 0xa0aa0000, /* add r0, v0.z, c0.z */
2543 0x00000005, 0xc00f0001, 0x80000000, 0xa0000000, /* mul oFog, r0.x, c0.x */
2544 0x0000ffff
2546 /* basic vertex shader with reversed fog computation ("foggy"), vs_2_0 */
2547 static const DWORD vertex_shader_code3[] =
2549 0xfffe0200, /* vs_2_0 */
2550 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
2551 0x0200001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
2552 0x05000051, 0xa00f0000, 0xbfa00000, 0x00000000, 0xbf666666, 0x00000000, /* def c0, -1.25, 0.0, -0.9, 0.0 */
2553 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
2554 0x02000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
2555 0x03000002, 0x800f0000, 0x90aa0000, 0xa0aa0000, /* add r0, v0.z, c0.z */
2556 0x03000005, 0xc00f0001, 0x80000000, 0xa0000000, /* mul oFog, r0.x, c0.x */
2557 0x0000ffff
2559 /* basic pixel shader */
2560 static const DWORD pixel_shader_code[] =
2562 0xffff0101, /* ps_1_1 */
2563 0x00000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
2564 0x0000ffff
2566 static const DWORD pixel_shader_code2[] =
2568 0xffff0200, /* ps_2_0 */
2569 0x0200001f, 0x80000000, 0x900f0000, /* dcl v0 */
2570 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
2571 0x0000ffff
2573 struct
2575 struct vec3 position;
2576 DWORD diffuse;
2578 quad[] =
2580 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
2581 {{-1.0f, 1.0f, 0.0f}, 0xffff0000},
2582 {{ 1.0f, -1.0f, 0.0f}, 0xffff0000},
2583 {{ 1.0f, 1.0f, 0.0f}, 0xffff0000},
2585 static const D3DVERTEXELEMENT9 decl_elements[] =
2587 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
2588 {0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
2589 D3DDECL_END()
2591 /* This reference data was collected on a nVidia GeForce 7600GS driver
2592 * version 84.19 DirectX version 9.0c on Windows XP. */
2593 static const struct test_data_t
2595 int vshader;
2596 int pshader;
2597 D3DFOGMODE vfog;
2598 D3DFOGMODE tfog;
2599 unsigned int color[11];
2601 test_data[] =
2603 /* only pixel shader: */
2604 {0, 1, D3DFOG_NONE, D3DFOG_LINEAR,
2605 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2606 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2607 {0, 1, D3DFOG_EXP, D3DFOG_LINEAR,
2608 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2609 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2610 {0, 1, D3DFOG_EXP2, D3DFOG_LINEAR,
2611 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2612 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2613 {0, 1, D3DFOG_LINEAR, D3DFOG_NONE,
2614 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2615 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2616 {0, 1, D3DFOG_LINEAR, D3DFOG_LINEAR,
2617 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2618 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2620 /* vertex shader */
2621 {1, 0, D3DFOG_NONE, D3DFOG_NONE,
2622 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
2623 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00}},
2624 {1, 0, D3DFOG_NONE, D3DFOG_LINEAR,
2625 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2626 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2627 {1, 0, D3DFOG_EXP, D3DFOG_LINEAR,
2628 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2629 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2631 {1, 0, D3DFOG_EXP2, D3DFOG_LINEAR,
2632 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2633 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2634 {1, 0, D3DFOG_LINEAR, D3DFOG_LINEAR,
2635 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2636 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2638 /* vertex shader and pixel shader */
2639 /* The next 4 tests would read the fog coord output, but it isn't available.
2640 * The result is a fully fogged quad, no matter what the Z coord is. This is on
2641 * a geforce 7400, 97.52 driver, Windows Vista, but probably hardware dependent.
2642 * These tests should be disabled if some other hardware behaves differently
2644 {1, 1, D3DFOG_NONE, D3DFOG_NONE,
2645 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
2646 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00}},
2647 {1, 1, D3DFOG_LINEAR, D3DFOG_NONE,
2648 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
2649 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00}},
2650 {1, 1, D3DFOG_EXP, D3DFOG_NONE,
2651 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
2652 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00}},
2653 {1, 1, D3DFOG_EXP2, D3DFOG_NONE,
2654 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
2655 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00}},
2657 /* These use the Z coordinate with linear table fog */
2658 {1, 1, D3DFOG_NONE, D3DFOG_LINEAR,
2659 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2660 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2661 {1, 1, D3DFOG_EXP, D3DFOG_LINEAR,
2662 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2663 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2664 {1, 1, D3DFOG_EXP2, D3DFOG_LINEAR,
2665 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2666 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2667 {1, 1, D3DFOG_LINEAR, D3DFOG_LINEAR,
2668 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2669 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2671 /* Non-linear table fog without fog coord */
2672 {1, 1, D3DFOG_NONE, D3DFOG_EXP,
2673 {0x00ff0000, 0x00e71800, 0x00d12e00, 0x00bd4200, 0x00ab5400, 0x009b6400,
2674 0x008d7200, 0x007f8000, 0x00738c00, 0x00689700, 0x005ea100}},
2675 {1, 1, D3DFOG_NONE, D3DFOG_EXP2,
2676 {0x00fd0200, 0x00f50200, 0x00f50a00, 0x00e91600, 0x00d92600, 0x00c73800,
2677 0x00b24d00, 0x009c6300, 0x00867900, 0x00728d00, 0x005ea100}},
2679 /* These tests fail on older Nvidia drivers */
2680 /* foggy vertex shader */
2681 {2, 0, D3DFOG_NONE, D3DFOG_NONE,
2682 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2683 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2684 {2, 0, D3DFOG_EXP, D3DFOG_NONE,
2685 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2686 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2687 {2, 0, D3DFOG_EXP2, D3DFOG_NONE,
2688 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2689 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2690 {2, 0, D3DFOG_LINEAR, D3DFOG_NONE,
2691 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2692 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2694 {3, 0, D3DFOG_NONE, D3DFOG_NONE,
2695 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2696 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2697 {3, 0, D3DFOG_EXP, D3DFOG_NONE,
2698 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2699 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2700 {3, 0, D3DFOG_EXP2, D3DFOG_NONE,
2701 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2702 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2703 {3, 0, D3DFOG_LINEAR, D3DFOG_NONE,
2704 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2705 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2707 /* foggy vertex shader and pixel shader. First 4 tests with vertex fog,
2708 * all using the fixed fog-coord linear fog
2710 /* vs_1_1 with ps_1_1 */
2711 {2, 1, D3DFOG_NONE, D3DFOG_NONE,
2712 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2713 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2714 {2, 1, D3DFOG_EXP, D3DFOG_NONE,
2715 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2716 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2717 {2, 1, D3DFOG_EXP2, D3DFOG_NONE,
2718 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2719 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2720 {2, 1, D3DFOG_LINEAR, D3DFOG_NONE,
2721 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2722 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2724 /* vs_2_0 with ps_1_1 */
2725 {3, 1, D3DFOG_NONE, D3DFOG_NONE,
2726 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2727 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2728 {3, 1, D3DFOG_EXP, D3DFOG_NONE,
2729 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2730 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2731 {3, 1, D3DFOG_EXP2, D3DFOG_NONE,
2732 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2733 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2734 {3, 1, D3DFOG_LINEAR, D3DFOG_NONE,
2735 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2736 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2738 /* vs_1_1 with ps_2_0 */
2739 {2, 2, D3DFOG_NONE, D3DFOG_NONE,
2740 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2741 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2742 {2, 2, D3DFOG_EXP, D3DFOG_NONE,
2743 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2744 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2745 {2, 2, D3DFOG_EXP2, D3DFOG_NONE,
2746 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2747 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2748 {2, 2, D3DFOG_LINEAR, D3DFOG_NONE,
2749 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2750 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2752 /* vs_2_0 with ps_2_0 */
2753 {3, 2, D3DFOG_NONE, D3DFOG_NONE,
2754 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2755 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2756 {3, 2, D3DFOG_EXP, D3DFOG_NONE,
2757 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2758 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2759 {3, 2, D3DFOG_EXP2, D3DFOG_NONE,
2760 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2761 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2762 {3, 2, D3DFOG_LINEAR, D3DFOG_NONE,
2763 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2764 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2766 /* These use table fog. Here the shader-provided fog coordinate is
2767 * ignored and the z coordinate used instead
2769 {2, 1, D3DFOG_NONE, D3DFOG_EXP,
2770 {0x00ff0000, 0x00e71800, 0x00d12e00, 0x00bd4200, 0x00ab5400, 0x009b6400,
2771 0x008d7200, 0x007f8000, 0x00738c00, 0x00689700, 0x005ea100}},
2772 {2, 1, D3DFOG_NONE, D3DFOG_EXP2,
2773 {0x00fd0200, 0x00f50200, 0x00f50a00, 0x00e91600, 0x00d92600, 0x00c73800,
2774 0x00b24d00, 0x009c6300, 0x00867900, 0x00728d00, 0x005ea100}},
2775 {2, 1, D3DFOG_NONE, D3DFOG_LINEAR,
2776 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2777 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2779 static const D3DMATRIX identity =
2781 1.0f, 0.0f, 0.0f, 0.0f,
2782 0.0f, 1.0f, 0.0f, 0.0f,
2783 0.0f, 0.0f, 1.0f, 0.0f,
2784 0.0f, 0.0f, 0.0f, 1.0f,
2785 }}};
2787 window = create_window();
2788 d3d = Direct3DCreate9(D3D_SDK_VERSION);
2789 ok(!!d3d, "Failed to create a D3D object.\n");
2790 if (!(device = create_device(d3d, window, window, TRUE)))
2792 skip("Failed to create a D3D device, skipping tests.\n");
2793 goto done;
2796 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
2797 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
2798 if (caps.VertexShaderVersion < D3DVS_VERSION(2, 0) || caps.PixelShaderVersion < D3DPS_VERSION(2, 0))
2800 skip("No shader model 2 support, skipping tests.\n");
2801 IDirect3DDevice9_Release(device);
2802 goto done;
2805 /* NOTE: Changing these values will not affect the tests with foggy vertex
2806 * shader, as the values are hardcoded in the shader. */
2807 start.f = 0.1f;
2808 end.f = 0.9f;
2810 /* Some of the tests seem to depend on the projection matrix explicitly
2811 * being set to an identity matrix, even though that's the default.
2812 * (AMD Radeon HD 6310, Windows 7) */
2813 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &identity);
2814 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
2816 hr = IDirect3DDevice9_CreateVertexShader(device, vertex_shader_code1, &vertex_shader[1]);
2817 ok(SUCCEEDED(hr), "CreateVertexShader failed (%08x)\n", hr);
2818 hr = IDirect3DDevice9_CreateVertexShader(device, vertex_shader_code2, &vertex_shader[2]);
2819 ok(SUCCEEDED(hr), "CreateVertexShader failed (%08x)\n", hr);
2820 hr = IDirect3DDevice9_CreateVertexShader(device, vertex_shader_code3, &vertex_shader[3]);
2821 ok(SUCCEEDED(hr), "CreateVertexShader failed (%08x)\n", hr);
2822 hr = IDirect3DDevice9_CreatePixelShader(device, pixel_shader_code, &pixel_shader[1]);
2823 ok(SUCCEEDED(hr), "CreatePixelShader failed (%08x)\n", hr);
2824 hr = IDirect3DDevice9_CreatePixelShader(device, pixel_shader_code2, &pixel_shader[2]);
2825 ok(SUCCEEDED(hr), "CreatePixelShader failed (%08x)\n", hr);
2826 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &vertex_declaration);
2827 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (%08x)\n", hr);
2829 /* Setup initial states: No lighting, fog on, fog color */
2830 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
2831 ok(hr == D3D_OK, "Turning off lighting failed (%08x)\n", hr);
2832 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGENABLE, TRUE);
2833 ok(hr == D3D_OK, "Turning on fog calculations failed (%08x)\n", hr);
2834 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGCOLOR, 0xff00ff00 /* A nice green */);
2835 ok(hr == D3D_OK, "Setting fog color failed (%08x)\n", hr);
2836 hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration);
2837 ok(SUCCEEDED(hr), "SetVertexDeclaration failed (%08x)\n", hr);
2839 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_NONE);
2840 ok(hr == D3D_OK, "Turning off table fog failed (%08x)\n", hr);
2841 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGVERTEXMODE, D3DFOG_NONE);
2842 ok(hr == D3D_OK, "Turning off vertex fog failed (%08x)\n", hr);
2844 /* Use fogtart = 0.1 and end = 0.9 to test behavior outside the fog transition phase, too*/
2845 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGSTART, start.i);
2846 ok(hr == D3D_OK, "Setting fog start failed (%08x)\n", hr);
2847 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGEND, end.i);
2848 ok(hr == D3D_OK, "Setting fog end failed (%08x)\n", hr);
2850 for (i = 0; i < sizeof(test_data)/sizeof(test_data[0]); i++)
2852 hr = IDirect3DDevice9_SetVertexShader(device, vertex_shader[test_data[i].vshader]);
2853 ok(SUCCEEDED(hr), "SetVertexShader failed (%08x)\n", hr);
2854 hr = IDirect3DDevice9_SetPixelShader(device, pixel_shader[test_data[i].pshader]);
2855 ok(SUCCEEDED(hr), "SetPixelShader failed (%08x)\n", hr);
2856 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGVERTEXMODE, test_data[i].vfog);
2857 ok( hr == D3D_OK, "Setting fog vertex mode to D3DFOG_LINEAR failed (%08x)\n", hr);
2858 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, test_data[i].tfog);
2859 ok( hr == D3D_OK, "Setting fog table mode to D3DFOG_LINEAR failed (%08x)\n", hr);
2861 for(j=0; j < 11; j++)
2863 /* Don't use the whole zrange to prevent rounding errors */
2864 quad[0].position.z = 0.001f + (float)j / 10.02f;
2865 quad[1].position.z = 0.001f + (float)j / 10.02f;
2866 quad[2].position.z = 0.001f + (float)j / 10.02f;
2867 quad[3].position.z = 0.001f + (float)j / 10.02f;
2869 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff00ff, 1.0f, 0);
2870 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed (%08x)\n", hr);
2872 hr = IDirect3DDevice9_BeginScene(device);
2873 ok( hr == D3D_OK, "BeginScene returned failed (%08x)\n", hr);
2875 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], sizeof(quad[0]));
2876 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%08x)\n", hr);
2878 hr = IDirect3DDevice9_EndScene(device);
2879 ok(hr == D3D_OK, "EndScene failed (%08x)\n", hr);
2881 /* As the red and green component are the result of blending use 5% tolerance on the expected value */
2882 color = getPixelColor(device, 128, 240);
2883 ok(color_match(color, test_data[i].color[j], 13),
2884 "fog vs%i ps%i fvm%i ftm%i %d: got color %08x, expected %08x +-5%%\n",
2885 test_data[i].vshader, test_data[i].pshader, test_data[i].vfog, test_data[i].tfog, j, color, test_data[i].color[j]);
2888 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
2890 IDirect3DVertexShader9_Release(vertex_shader[1]);
2891 IDirect3DVertexShader9_Release(vertex_shader[2]);
2892 IDirect3DVertexShader9_Release(vertex_shader[3]);
2893 IDirect3DPixelShader9_Release(pixel_shader[1]);
2894 IDirect3DPixelShader9_Release(pixel_shader[2]);
2895 IDirect3DVertexDeclaration9_Release(vertex_declaration);
2896 refcount = IDirect3DDevice9_Release(device);
2897 ok(!refcount, "Device has %u references left.\n", refcount);
2898 done:
2899 IDirect3D9_Release(d3d);
2900 DestroyWindow(window);
2903 static void generate_bumpmap_textures(IDirect3DDevice9 *device) {
2904 unsigned int i, x, y;
2905 HRESULT hr;
2906 IDirect3DTexture9 *texture[2] = {NULL, NULL};
2907 D3DLOCKED_RECT locked_rect;
2909 /* Generate the textures */
2910 for(i=0; i<2; i++)
2912 hr = IDirect3DDevice9_CreateTexture(device, 128, 128, 1, 0, i?D3DFMT_A8R8G8B8:D3DFMT_V8U8,
2913 D3DPOOL_MANAGED, &texture[i], NULL);
2914 ok(SUCCEEDED(hr), "CreateTexture failed (0x%08x)\n", hr);
2916 hr = IDirect3DTexture9_LockRect(texture[i], 0, &locked_rect, NULL, 0);
2917 ok(SUCCEEDED(hr), "LockRect failed (0x%08x)\n", hr);
2918 for (y = 0; y < 128; ++y)
2920 if(i)
2921 { /* Set up black texture with 2x2 texel white spot in the middle */
2922 DWORD *ptr = (DWORD *)(((BYTE *)locked_rect.pBits) + (y * locked_rect.Pitch));
2923 for (x = 0; x < 128; ++x)
2925 *ptr++ = D3DCOLOR_ARGB(0xff, x * 2, y * 2, 0);
2928 else
2929 { /* Set up a displacement map which points away from the center parallel to the closest axis.
2930 * (if multiplied with bumpenvmat)
2932 WORD *ptr = (WORD *)(((BYTE *)locked_rect.pBits) + (y * locked_rect.Pitch));
2933 for (x = 0; x < 128; ++x)
2935 if(abs(x-64)>abs(y-64))
2937 if(x < 64)
2938 *ptr++ = 0xc000;
2939 else
2940 *ptr++ = 0x4000;
2942 else
2944 if(y < 64)
2945 *ptr++ = 0x0040;
2946 else
2947 *ptr++ = 0x00c0;
2952 hr = IDirect3DTexture9_UnlockRect(texture[i], 0);
2953 ok(SUCCEEDED(hr), "UnlockRect failed (0x%08x)\n", hr);
2955 hr = IDirect3DDevice9_SetTexture(device, i, (IDirect3DBaseTexture9 *)texture[i]);
2956 ok(SUCCEEDED(hr), "SetTexture failed (0x%08x)\n", hr);
2958 /* Disable texture filtering */
2959 hr = IDirect3DDevice9_SetSamplerState(device, i, D3DSAMP_MINFILTER, D3DTEXF_POINT);
2960 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_MINFILTER failed (0x%08x)\n", hr);
2961 hr = IDirect3DDevice9_SetSamplerState(device, i, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
2962 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr);
2964 hr = IDirect3DDevice9_SetSamplerState(device, i, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
2965 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_ADDRESSU failed (0x%08x)\n", hr);
2966 hr = IDirect3DDevice9_SetSamplerState(device, i, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
2967 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_ADDRESSV failed (0x%08x)\n", hr);
2971 /* Test the behavior of the texbem instruction with normal 2D and projective
2972 * 2D textures. */
2973 static void texbem_test(void)
2975 IDirect3DVertexDeclaration9 *vertex_declaration = NULL;
2976 /* Use asymmetric matrix to test loading. */
2977 float bumpenvmat[4] = {0.0f, 0.5f, -0.5f, 0.0f};
2978 IDirect3DPixelShader9 *pixel_shader = NULL;
2979 IDirect3DTexture9 *texture1, *texture2;
2980 IDirect3DTexture9 *texture = NULL;
2981 D3DLOCKED_RECT locked_rect;
2982 IDirect3DDevice9 *device;
2983 IDirect3D9 *d3d;
2984 ULONG refcount;
2985 D3DCAPS9 caps;
2986 DWORD color;
2987 HWND window;
2988 HRESULT hr;
2989 int i;
2991 static const DWORD pixel_shader_code[] =
2993 0xffff0101, /* ps_1_1*/
2994 0x00000042, 0xb00f0000, /* tex t0*/
2995 0x00000043, 0xb00f0001, 0xb0e40000, /* texbem t1, t0*/
2996 0x00000001, 0x800f0000, 0xb0e40001, /* mov r0, t1*/
2997 0x0000ffff
2999 static const DWORD double_texbem_code[] =
3001 0xffff0103, /* ps_1_3 */
3002 0x00000042, 0xb00f0000, /* tex t0 */
3003 0x00000043, 0xb00f0001, 0xb0e40000, /* texbem t1, t0 */
3004 0x00000042, 0xb00f0002, /* tex t2 */
3005 0x00000043, 0xb00f0003, 0xb0e40002, /* texbem t3, t2 */
3006 0x00000002, 0x800f0000, 0xb0e40001, 0xb0e40003, /* add r0, t1, t3 */
3007 0x0000ffff /* end */
3009 static const float quad[][7] =
3011 {-1.0f, -1.0f, 0.1f, 0.0f, 0.0f, 0.0f, 0.0f},
3012 {-1.0f, 1.0f, 0.1f, 0.0f, 1.0f, 0.0f, 1.0f},
3013 { 1.0f, -1.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f},
3014 { 1.0f, 1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 1.0f},
3016 static const float quad_proj[][9] =
3018 {-1.0f, -1.0f, 0.1f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 128.0f},
3019 {-1.0f, 1.0f, 0.1f, 0.0f, 1.0f, 0.0f, 128.0f, 0.0f, 128.0f},
3020 { 1.0f, -1.0f, 0.1f, 1.0f, 0.0f, 128.0f, 0.0f, 0.0f, 128.0f},
3021 { 1.0f, 1.0f, 0.1f, 1.0f, 1.0f, 128.0f, 128.0f, 0.0f, 128.0f},
3023 static const float double_quad[] =
3025 -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.5f, 0.0f, 0.0f, 0.5f, 0.5f,
3026 -1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.5f, 0.0f, 0.0f, 0.5f, 0.5f,
3027 1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.5f, 0.0f, 0.0f, 0.5f, 0.5f,
3028 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.5f, 0.0f, 0.0f, 0.5f, 0.5f,
3030 static const D3DVERTEXELEMENT9 decl_elements[][4] =
3033 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
3034 {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
3035 {0, 20, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},
3036 D3DDECL_END()
3039 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
3040 {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
3041 {0, 20, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},
3042 D3DDECL_END()
3046 window = create_window();
3047 d3d = Direct3DCreate9(D3D_SDK_VERSION);
3048 ok(!!d3d, "Failed to create a D3D object.\n");
3049 if (!(device = create_device(d3d, window, window, TRUE)))
3051 skip("Failed to create a D3D device, skipping tests.\n");
3052 goto done;
3055 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
3056 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
3057 if (caps.PixelShaderVersion < D3DPS_VERSION(1, 1))
3059 skip("No ps_1_1 support, skipping tests.\n");
3060 IDirect3DDevice9_Release(device);
3061 goto done;
3064 generate_bumpmap_textures(device);
3066 IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_BUMPENVMAT00, *(LPDWORD)&bumpenvmat[0]);
3067 IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_BUMPENVMAT01, *(LPDWORD)&bumpenvmat[1]);
3068 IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_BUMPENVMAT10, *(LPDWORD)&bumpenvmat[2]);
3069 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_BUMPENVMAT11, *(LPDWORD)&bumpenvmat[3]);
3070 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
3072 hr = IDirect3DDevice9_SetVertexShader(device, NULL);
3073 ok(SUCCEEDED(hr), "SetVertexShader failed (%08x)\n", hr);
3075 for(i=0; i<2; i++)
3077 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
3078 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed (%08x)\n", hr);
3080 if(i)
3082 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT4|D3DTTFF_PROJECTED);
3083 ok(SUCCEEDED(hr), "SetTextureStageState D3DTSS_TEXTURETRANSFORMFLAGS failed (0x%08x)\n", hr);
3086 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements[i], &vertex_declaration);
3087 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (0x%08x)\n", hr);
3088 hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration);
3089 ok(SUCCEEDED(hr), "SetVertexDeclaration failed (0x%08x)\n", hr);
3091 hr = IDirect3DDevice9_CreatePixelShader(device, pixel_shader_code, &pixel_shader);
3092 ok(SUCCEEDED(hr), "CreatePixelShader failed (%08x)\n", hr);
3093 hr = IDirect3DDevice9_SetPixelShader(device, pixel_shader);
3094 ok(SUCCEEDED(hr), "SetPixelShader failed (%08x)\n", hr);
3096 hr = IDirect3DDevice9_BeginScene(device);
3097 ok(SUCCEEDED(hr), "BeginScene failed (0x%08x)\n", hr);
3099 if(!i)
3100 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], sizeof(quad[0]));
3101 else
3102 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad_proj[0], sizeof(quad_proj[0]));
3103 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (0x%08x)\n", hr);
3105 hr = IDirect3DDevice9_EndScene(device);
3106 ok(SUCCEEDED(hr), "EndScene failed (0x%08x)\n", hr);
3108 /* The Window 8 testbot (WARP) seems to use the transposed
3109 * D3DTSS_BUMPENVMAT matrix. */
3110 color = getPixelColor(device, 160, 240);
3111 ok(color_match(color, 0x007e8000, 4) || broken(color_match(color, 0x00007e00, 4)),
3112 "Got unexpected color 0x%08x.\n", color);
3113 color = getPixelColor(device, 480, 240);
3114 ok(color_match(color, 0x007e8000, 4) || broken(color_match(color, 0x00fe7e00, 4)),
3115 "Got unexpected color 0x%08x.\n", color);
3116 color = getPixelColor(device, 320, 120);
3117 ok(color_match(color, 0x007e8000, 4) || broken(color_match(color, 0x0080fe00, 4)),
3118 "Got unexpected color 0x%08x.\n", color);
3119 color = getPixelColor(device, 320, 360);
3120 ok(color_match(color, 0x007e8000, 4) || broken(color_match(color, 0x00800000, 4)),
3121 "Got unexpected color 0x%08x.\n", color);
3123 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
3124 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
3126 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
3127 ok(SUCCEEDED(hr), "SetPixelShader failed (%08x)\n", hr);
3128 IDirect3DPixelShader9_Release(pixel_shader);
3130 hr = IDirect3DDevice9_SetVertexDeclaration(device, NULL);
3131 ok(SUCCEEDED(hr), "SetVertexDeclaration failed (%08x)\n", hr);
3132 IDirect3DVertexDeclaration9_Release(vertex_declaration);
3135 /* clean up */
3136 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0, 0.0f, 0);
3137 ok(SUCCEEDED(hr), "Clear failed (0x%08x)\n", hr);
3139 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
3140 ok(SUCCEEDED(hr), "SetTextureStageState D3DTSS_TEXTURETRANSFORMFLAGS failed (0x%08x)\n", hr);
3142 for(i=0; i<2; i++)
3144 hr = IDirect3DDevice9_GetTexture(device, i, (IDirect3DBaseTexture9 **) &texture);
3145 ok(SUCCEEDED(hr), "IDirect3DDevice9_GetTexture failed (0x%08x)\n", hr);
3146 IDirect3DTexture9_Release(texture); /* For the GetTexture */
3147 hr = IDirect3DDevice9_SetTexture(device, i, NULL);
3148 ok(SUCCEEDED(hr), "SetTexture failed (0x%08x)\n", hr);
3149 IDirect3DTexture9_Release(texture);
3152 /* Test double texbem */
3153 hr = IDirect3DDevice9_CreateTexture(device, 1, 1, 1, 0, D3DFMT_V8U8, D3DPOOL_MANAGED, &texture, NULL);
3154 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateTexture failed (0x%08x)\n", hr);
3155 hr = IDirect3DDevice9_CreateTexture(device, 1, 1, 1, 0, D3DFMT_V8U8, D3DPOOL_MANAGED, &texture1, NULL);
3156 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateTexture failed (0x%08x)\n", hr);
3157 hr = IDirect3DDevice9_CreateTexture(device, 8, 8, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture2, NULL);
3158 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateTexture failed (0x%08x)\n", hr);
3159 hr = IDirect3DDevice9_CreatePixelShader(device, double_texbem_code, &pixel_shader);
3160 ok(SUCCEEDED(hr), "CreatePixelShader failed (%08x)\n", hr);
3162 hr = IDirect3DTexture9_LockRect(texture, 0, &locked_rect, NULL, 0);
3163 ok(SUCCEEDED(hr), "LockRect failed (0x%08x)\n", hr);
3164 ((signed char *) locked_rect.pBits)[0] = (-1.0 / 8.0) * 127;
3165 ((signed char *) locked_rect.pBits)[1] = ( 1.0 / 8.0) * 127;
3167 hr = IDirect3DTexture9_UnlockRect(texture, 0);
3168 ok(SUCCEEDED(hr), "LockRect failed (0x%08x)\n", hr);
3170 hr = IDirect3DTexture9_LockRect(texture1, 0, &locked_rect, NULL, 0);
3171 ok(SUCCEEDED(hr), "LockRect failed (0x%08x)\n", hr);
3172 ((signed char *) locked_rect.pBits)[0] = (-2.0 / 8.0) * 127;
3173 ((signed char *) locked_rect.pBits)[1] = (-4.0 / 8.0) * 127;
3174 hr = IDirect3DTexture9_UnlockRect(texture1, 0);
3175 ok(SUCCEEDED(hr), "LockRect failed (0x%08x)\n", hr);
3178 /* Some data without any meaning, just to have an 8x8 array to see which element is picked */
3179 #define tex 0x00ff0000
3180 #define tex1 0x0000ff00
3181 #define origin 0x000000ff
3182 static const DWORD pixel_data[] = {
3183 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
3184 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
3185 0x000000ff, tex1 , 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
3186 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
3187 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, origin, 0x000000ff, tex , 0x000000ff,
3188 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
3189 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
3190 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
3192 #undef tex1
3193 #undef tex2
3194 #undef origin
3196 hr = IDirect3DTexture9_LockRect(texture2, 0, &locked_rect, NULL, 0);
3197 ok(SUCCEEDED(hr), "LockRect failed (0x%08x)\n", hr);
3198 for(i = 0; i < 8; i++) {
3199 memcpy(((char *) locked_rect.pBits) + i * locked_rect.Pitch, pixel_data + 8 * i, 8 * sizeof(DWORD));
3201 hr = IDirect3DTexture9_UnlockRect(texture2, 0);
3202 ok(SUCCEEDED(hr), "LockRect failed (0x%08x)\n", hr);
3205 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) texture);
3206 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTexture failed (0x%08x)\n", hr);
3207 hr = IDirect3DDevice9_SetTexture(device, 1, (IDirect3DBaseTexture9 *) texture2);
3208 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTexture failed (0x%08x)\n", hr);
3209 hr = IDirect3DDevice9_SetTexture(device, 2, (IDirect3DBaseTexture9 *) texture1);
3210 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTexture failed (0x%08x)\n", hr);
3211 hr = IDirect3DDevice9_SetTexture(device, 3, (IDirect3DBaseTexture9 *) texture2);
3212 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTexture failed (0x%08x)\n", hr);
3213 hr = IDirect3DDevice9_SetPixelShader(device, pixel_shader);
3214 ok(SUCCEEDED(hr), "Direct3DDevice9_SetPixelShader failed (0x%08x)\n", hr);
3215 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX4);
3216 ok(SUCCEEDED(hr), "Direct3DDevice9_SetPixelShader failed (0x%08x)\n", hr);
3218 bumpenvmat[0] =-1.0; bumpenvmat[2] = 2.0;
3219 bumpenvmat[1] = 0.0; bumpenvmat[3] = 0.0;
3220 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_BUMPENVMAT00, *(LPDWORD)&bumpenvmat[0]);
3221 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr);
3222 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_BUMPENVMAT01, *(LPDWORD)&bumpenvmat[1]);
3223 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr);
3224 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_BUMPENVMAT10, *(LPDWORD)&bumpenvmat[2]);
3225 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr);
3226 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_BUMPENVMAT11, *(LPDWORD)&bumpenvmat[3]);
3227 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr);
3229 bumpenvmat[0] = 1.5; bumpenvmat[2] = 0.0;
3230 bumpenvmat[1] = 0.0; bumpenvmat[3] = 0.5;
3231 hr = IDirect3DDevice9_SetTextureStageState(device, 3, D3DTSS_BUMPENVMAT00, *(LPDWORD)&bumpenvmat[0]);
3232 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr);
3233 hr = IDirect3DDevice9_SetTextureStageState(device, 3, D3DTSS_BUMPENVMAT01, *(LPDWORD)&bumpenvmat[1]);
3234 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr);
3235 hr = IDirect3DDevice9_SetTextureStageState(device, 3, D3DTSS_BUMPENVMAT10, *(LPDWORD)&bumpenvmat[2]);
3236 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr);
3237 hr = IDirect3DDevice9_SetTextureStageState(device, 3, D3DTSS_BUMPENVMAT11, *(LPDWORD)&bumpenvmat[3]);
3238 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr);
3240 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
3241 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr);
3242 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
3243 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr);
3244 hr = IDirect3DDevice9_SetSamplerState(device, 1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
3245 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr);
3246 hr = IDirect3DDevice9_SetSamplerState(device, 1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
3247 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr);
3248 hr = IDirect3DDevice9_SetSamplerState(device, 2, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
3249 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr);
3250 hr = IDirect3DDevice9_SetSamplerState(device, 2, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
3251 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr);
3252 hr = IDirect3DDevice9_SetSamplerState(device, 3, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
3253 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr);
3254 hr = IDirect3DDevice9_SetSamplerState(device, 3, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
3255 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr);
3257 hr = IDirect3DDevice9_BeginScene(device);
3258 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3259 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, double_quad, sizeof(float) * 11);
3260 ok(SUCCEEDED(hr), "Failed to draw primitive, hr %#x.\n", hr);
3261 hr = IDirect3DDevice9_EndScene(device);
3262 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3263 /* The Window 8 testbot (WARP) seems to use the transposed
3264 * D3DTSS_BUMPENVMAT matrix. */
3265 color = getPixelColor(device, 320, 240);
3266 ok(color_match(color, 0x00ffff00, 1) || broken(color_match(color, 0x0000ffff, 1)),
3267 "Got unexpected color 0x%08x.\n", color);
3269 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
3270 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
3272 IDirect3DPixelShader9_Release(pixel_shader);
3273 IDirect3DTexture9_Release(texture);
3274 IDirect3DTexture9_Release(texture1);
3275 IDirect3DTexture9_Release(texture2);
3276 refcount = IDirect3DDevice9_Release(device);
3277 ok(!refcount, "Device has %u references left.\n", refcount);
3278 done:
3279 IDirect3D9_Release(d3d);
3280 DestroyWindow(window);
3283 static void z_range_test(void)
3285 IDirect3DVertexShader9 *shader;
3286 IDirect3DDevice9 *device;
3287 IDirect3D9 *d3d;
3288 ULONG refcount;
3289 D3DCAPS9 caps;
3290 DWORD color;
3291 HWND window;
3292 HRESULT hr;
3294 static const struct
3296 struct vec3 position;
3297 DWORD diffuse;
3299 quad[] =
3301 {{-1.0f, 0.0f, 1.1f}, 0xffff0000},
3302 {{-1.0f, 1.0f, 1.1f}, 0xffff0000},
3303 {{ 1.0f, 0.0f, -1.1f}, 0xffff0000},
3304 {{ 1.0f, 1.0f, -1.1f}, 0xffff0000},
3306 quad2[] =
3308 {{-1.0f, 0.0f, 1.1f}, 0xff0000ff},
3309 {{-1.0f, 1.0f, 1.1f}, 0xff0000ff},
3310 {{ 1.0f, 0.0f, -1.1f}, 0xff0000ff},
3311 {{ 1.0f, 1.0f, -1.1f}, 0xff0000ff},
3313 static const struct
3315 struct vec4 position;
3316 DWORD diffuse;
3318 quad3[] =
3320 {{640.0f, 240.0f, -1.1f, 1.0f}, 0xffffff00},
3321 {{640.0f, 480.0f, -1.1f, 1.0f}, 0xffffff00},
3322 {{ 0.0f, 240.0f, 1.1f, 1.0f}, 0xffffff00},
3323 {{ 0.0f, 480.0f, 1.1f, 1.0f}, 0xffffff00},
3325 quad4[] =
3327 {{640.0f, 240.0f, -1.1f, 1.0f}, 0xff00ff00},
3328 {{640.0f, 480.0f, -1.1f, 1.0f}, 0xff00ff00},
3329 {{ 0.0f, 240.0f, 1.1f, 1.0f}, 0xff00ff00},
3330 {{ 0.0f, 480.0f, 1.1f, 1.0f}, 0xff00ff00},
3332 static const DWORD shader_code[] =
3334 0xfffe0101, /* vs_1_1 */
3335 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
3336 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
3337 0x00000001, 0xd00f0000, 0xa0e40000, /* mov oD0, c0 */
3338 0x0000ffff /* end */
3340 static const float color_const_1[] = {1.0f, 0.0f, 0.0f, 1.0f};
3341 static const float color_const_2[] = {0.0f, 0.0f, 1.0f, 1.0f};
3343 window = create_window();
3344 d3d = Direct3DCreate9(D3D_SDK_VERSION);
3345 ok(!!d3d, "Failed to create a D3D object.\n");
3346 if (!(device = create_device(d3d, window, window, TRUE)))
3348 skip("Failed to create a D3D device, skipping tests.\n");
3349 goto done;
3352 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
3353 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
3355 /* Does the Present clear the depth stencil? Clear the depth buffer with some value != 0,
3356 * then call Present. Then clear the color buffer to make sure it has some defined content
3357 * after the Present with D3DSWAPEFFECT_DISCARD. After that draw a plane that is somewhere cut
3358 * by the depth value. */
3359 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 0.75f, 0);
3360 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
3361 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
3362 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
3363 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
3364 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
3366 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
3367 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3368 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, TRUE);
3369 ok(SUCCEEDED(hr), "Failed to enable clipping, hr %#x.\n", hr);
3370 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
3371 ok(SUCCEEDED(hr), "Failed to enable z test, hr %#x.\n", hr);
3372 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
3373 ok(SUCCEEDED(hr), "Failed to disable z writes, hr %#x.\n", hr);
3374 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_GREATER);
3375 ok(SUCCEEDED(hr), "Failed to set z function, hr %#x.\n", hr);
3376 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
3377 ok(SUCCEEDED(hr), "Failed set FVF, hr %#x.\n", hr);
3379 hr = IDirect3DDevice9_BeginScene(device);
3380 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3382 /* Test the untransformed vertex path */
3383 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
3384 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3385 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_LESS);
3386 ok(SUCCEEDED(hr), "Failed to set z function, hr %#x.\n", hr);
3387 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(quad2[0]));
3388 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3390 /* Test the transformed vertex path */
3391 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
3392 ok(SUCCEEDED(hr), "Failed set FVF, hr %#x.\n", hr);
3394 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, sizeof(quad4[0]));
3395 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3396 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_GREATER);
3397 ok(SUCCEEDED(hr), "Failed to set z function, hr %#x.\n", hr);
3398 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, sizeof(quad3[0]));
3399 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3401 hr = IDirect3DDevice9_EndScene(device);
3402 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3404 /* Do not test the exact corner pixels, but go pretty close to them */
3406 /* Clipped because z > 1.0 */
3407 color = getPixelColor(device, 28, 238);
3408 ok(color_match(color, 0x00ffffff, 0), "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
3409 color = getPixelColor(device, 28, 241);
3410 if (caps.PrimitiveMiscCaps & D3DPMISCCAPS_CLIPTLVERTS)
3411 ok(color_match(color, 0x00ffffff, 0), "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
3412 else
3413 ok(color_match(color, 0x00ffff00, 0), "Z range failed: Got color 0x%08x, expected 0x00ffff00.\n", color);
3415 /* Not clipped, > z buffer clear value(0.75).
3417 * On the r500 driver on Windows D3DCMP_GREATER and D3DCMP_GREATEREQUAL are broken for depth
3418 * values > 0.5. The range appears to be distorted, apparently an incoming value of ~0.875 is
3419 * equal to a stored depth buffer value of 0.5. */
3420 color = getPixelColor(device, 31, 238);
3421 ok(color_match(color, 0x00ff0000, 0), "Z range failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
3422 color = getPixelColor(device, 31, 241);
3423 ok(color_match(color, 0x00ffff00, 0), "Z range failed: Got color 0x%08x, expected 0x00ffff00.\n", color);
3424 color = getPixelColor(device, 100, 238);
3425 ok(color_match(color, 0x00ff0000, 0) || broken(color_match(color, 0x00ffffff, 0)),
3426 "Z range failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
3427 color = getPixelColor(device, 100, 241);
3428 ok(color_match(color, 0x00ffff00, 0) || broken(color_match(color, 0x00ffffff, 0)),
3429 "Z range failed: Got color 0x%08x, expected 0x00ffff00.\n", color);
3431 /* Not clipped, < z buffer clear value */
3432 color = getPixelColor(device, 104, 238);
3433 ok(color_match(color, 0x000000ff, 0), "Z range failed: Got color 0x%08x, expected 0x000000ff.\n", color);
3434 color = getPixelColor(device, 104, 241);
3435 ok(color_match(color, 0x0000ff00, 0), "Z range failed: Got color 0x%08x, expected 0x0000ff00.\n", color);
3436 color = getPixelColor(device, 318, 238);
3437 ok(color_match(color, 0x000000ff, 0), "Z range failed: Got color 0x%08x, expected 0x000000ff.\n", color);
3438 color = getPixelColor(device, 318, 241);
3439 ok(color_match(color, 0x0000ff00, 0), "Z range failed: Got color 0x%08x, expected 0x0000ff00.\n", color);
3441 /* Clipped because z < 0.0 */
3442 color = getPixelColor(device, 321, 238);
3443 ok(color_match(color, 0x00ffffff, 0), "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
3444 color = getPixelColor(device, 321, 241);
3445 if (caps.PrimitiveMiscCaps & D3DPMISCCAPS_CLIPTLVERTS)
3446 ok(color_match(color, 0x00ffffff, 0), "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
3447 else
3448 ok(color_match(color, 0x0000ff00, 0), "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
3450 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
3451 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
3453 /* Test the shader path */
3454 if (caps.VertexShaderVersion < D3DVS_VERSION(1, 1))
3456 skip("Vertex shaders not supported, skipping tests.\n");
3457 IDirect3DDevice9_Release(device);
3458 goto done;
3460 hr = IDirect3DDevice9_CreateVertexShader(device, shader_code, &shader);
3461 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
3463 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
3464 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
3466 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
3467 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
3468 hr = IDirect3DDevice9_SetVertexShader(device, shader);
3469 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
3471 hr = IDirect3DDevice9_BeginScene(device);
3472 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3474 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 0, color_const_1, 1);
3475 ok(SUCCEEDED(hr), "Failed to set vs constant 0, hr %#x.\n", hr);
3476 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
3477 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3479 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_LESS);
3480 ok(SUCCEEDED(hr), "Failed to set z function, hr %#x.\n", hr);
3481 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 0, color_const_2, 1);
3482 ok(SUCCEEDED(hr), "Failed to set vs constant 0, hr %#x.\n", hr);
3483 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(quad2[0]));
3484 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3486 hr = IDirect3DDevice9_EndScene(device);
3487 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3489 IDirect3DVertexShader9_Release(shader);
3491 /* Z < 1.0 */
3492 color = getPixelColor(device, 28, 238);
3493 ok(color_match(color, 0x00ffffff, 0), "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
3495 /* 1.0 < z < 0.75 */
3496 color = getPixelColor(device, 31, 238);
3497 ok(color_match(color, 0x00ff0000, 0), "Z range failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
3498 color = getPixelColor(device, 100, 238);
3499 ok(color_match(color, 0x00ff0000, 0) || broken(color_match(color, 0x00ffffff, 0)),
3500 "Z range failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
3502 /* 0.75 < z < 0.0 */
3503 color = getPixelColor(device, 104, 238);
3504 ok(color_match(color, 0x000000ff, 0), "Z range failed: Got color 0x%08x, expected 0x000000ff.\n", color);
3505 color = getPixelColor(device, 318, 238);
3506 ok(color_match(color, 0x000000ff, 0), "Z range failed: Got color 0x%08x, expected 0x000000ff.\n", color);
3508 /* 0.0 < z */
3509 color = getPixelColor(device, 321, 238);
3510 ok(color_match(color, 0x00ffffff, 0), "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
3512 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
3513 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
3515 refcount = IDirect3DDevice9_Release(device);
3516 ok(!refcount, "Device has %u references left.\n", refcount);
3517 done:
3518 IDirect3D9_Release(d3d);
3519 DestroyWindow(window);
3522 static void fill_surface(IDirect3DSurface9 *surface, DWORD color, DWORD flags)
3524 D3DSURFACE_DESC desc;
3525 D3DLOCKED_RECT l;
3526 HRESULT hr;
3527 unsigned int x, y;
3528 DWORD *mem;
3530 memset(&desc, 0, sizeof(desc));
3531 memset(&l, 0, sizeof(l));
3532 hr = IDirect3DSurface9_GetDesc(surface, &desc);
3533 ok(hr == D3D_OK, "IDirect3DSurface9_GetDesc failed with %08x\n", hr);
3534 hr = IDirect3DSurface9_LockRect(surface, &l, NULL, flags);
3535 ok(hr == D3D_OK, "IDirect3DSurface9_LockRect failed with %08x\n", hr);
3536 if(FAILED(hr)) return;
3538 for(y = 0; y < desc.Height; y++)
3540 mem = (DWORD *) ((BYTE *) l.pBits + y * l.Pitch);
3541 for(x = 0; x < l.Pitch / sizeof(DWORD); x++)
3543 mem[x] = color;
3546 hr = IDirect3DSurface9_UnlockRect(surface);
3547 ok(hr == D3D_OK, "IDirect3DSurface9_UnlockRect failed with %08x\n", hr);
3550 static void stretchrect_test(void)
3552 IDirect3DSurface9 *surf_tex_rt32, *surf_tex_rt64, *surf_tex_rt_dest64, *surf_tex_rt_dest640_480;
3553 IDirect3DSurface9 *surf_offscreen32, *surf_offscreen64, *surf_offscreen_dest64;
3554 IDirect3DTexture9 *tex_rt32, *tex_rt64, *tex_rt_dest64, *tex_rt_dest640_480;
3555 IDirect3DSurface9 *surf_tex32, *surf_tex64, *surf_tex_dest64;
3556 IDirect3DSurface9 *surf_rt32, *surf_rt64, *surf_rt_dest64;
3557 IDirect3DTexture9 *tex32, *tex64, *tex_dest64;
3558 IDirect3DSurface9 *surf_temp32, *surf_temp64;
3559 IDirect3DSurface9 *backbuffer;
3560 IDirect3DDevice9 *device;
3561 IDirect3D9 *d3d;
3562 D3DCOLOR color;
3563 ULONG refcount;
3564 HWND window;
3565 HRESULT hr;
3567 static const RECT src_rect = {0, 0, 640, 480};
3568 static const RECT src_rect_flipy = {0, 480, 640, 0};
3569 static const RECT dst_rect = {0, 0, 640, 480};
3570 static const RECT dst_rect_flipy = {0, 480, 640, 0};
3571 static const RECT src_rect64 = {0, 0, 64, 64};
3572 static const RECT src_rect64_flipy = {0, 64, 64, 0};
3573 static const RECT dst_rect64 = {0, 0, 64, 64};
3574 static const RECT dst_rect64_flipy = {0, 64, 64, 0};
3576 window = create_window();
3577 d3d = Direct3DCreate9(D3D_SDK_VERSION);
3578 ok(!!d3d, "Failed to create a D3D object.\n");
3579 if (!(device = create_device(d3d, window, window, TRUE)))
3581 skip("Failed to create a D3D device, skipping tests.\n");
3582 goto done;
3585 /* Create our temporary surfaces in system memory. */
3586 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 32, 32,
3587 D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surf_temp32, NULL);
3588 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3589 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 64, 64,
3590 D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surf_temp64, NULL);
3591 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3593 /* Create offscreen plain surfaces in D3DPOOL_DEFAULT. */
3594 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 32, 32,
3595 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf_offscreen32, NULL);
3596 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3597 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 64, 64,
3598 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf_offscreen64, NULL);
3599 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3600 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 64, 64,
3601 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf_offscreen_dest64, NULL);
3602 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3604 /* Create render target surfaces. */
3605 hr = IDirect3DDevice9_CreateRenderTarget(device, 32, 32,
3606 D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, TRUE, &surf_rt32, NULL );
3607 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
3608 hr = IDirect3DDevice9_CreateRenderTarget(device, 64, 64,
3609 D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, TRUE, &surf_rt64, NULL );
3610 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
3611 hr = IDirect3DDevice9_CreateRenderTarget(device, 64, 64,
3612 D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, TRUE, &surf_rt_dest64, NULL );
3613 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
3614 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
3615 ok(SUCCEEDED(hr), "Failed to get back buffer, hr %#x.\n", hr);
3617 /* Create render target textures. */
3618 hr = IDirect3DDevice9_CreateTexture(device, 32, 32, 1, D3DUSAGE_RENDERTARGET,
3619 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex_rt32, NULL);
3620 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
3621 hr = IDirect3DDevice9_CreateTexture(device, 64, 64, 1, D3DUSAGE_RENDERTARGET,
3622 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex_rt64, NULL);
3623 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
3624 hr = IDirect3DDevice9_CreateTexture(device, 64, 64, 1, D3DUSAGE_RENDERTARGET,
3625 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex_rt_dest64, NULL);
3626 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
3627 hr = IDirect3DDevice9_CreateTexture(device, 640, 480, 1, D3DUSAGE_RENDERTARGET,
3628 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex_rt_dest640_480, NULL);
3629 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
3630 hr = IDirect3DTexture9_GetSurfaceLevel(tex_rt32, 0, &surf_tex_rt32);
3631 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
3632 hr = IDirect3DTexture9_GetSurfaceLevel(tex_rt64, 0, &surf_tex_rt64);
3633 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
3634 hr = IDirect3DTexture9_GetSurfaceLevel(tex_rt_dest64, 0, &surf_tex_rt_dest64);
3635 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
3636 hr = IDirect3DTexture9_GetSurfaceLevel(tex_rt_dest640_480, 0, &surf_tex_rt_dest640_480);
3637 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
3639 /* Create regular textures in D3DPOOL_DEFAULT. */
3640 hr = IDirect3DDevice9_CreateTexture(device, 32, 32, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex32, NULL);
3641 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
3642 hr = IDirect3DDevice9_CreateTexture(device, 64, 64, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex64, NULL);
3643 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
3644 hr = IDirect3DDevice9_CreateTexture(device, 64, 64, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex_dest64, NULL);
3645 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
3646 hr = IDirect3DTexture9_GetSurfaceLevel(tex32, 0, &surf_tex32);
3647 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
3648 hr = IDirect3DTexture9_GetSurfaceLevel(tex64, 0, &surf_tex64);
3649 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
3650 hr = IDirect3DTexture9_GetSurfaceLevel(tex_dest64, 0, &surf_tex_dest64);
3651 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
3653 /**********************************************************************
3654 * Tests for when the source parameter is an offscreen plain surface. *
3655 **********************************************************************/
3657 /* Fill the offscreen 64x64 surface with green. */
3658 fill_surface(surf_offscreen64, 0xff00ff00, 0);
3660 /* offscreenplain ==> offscreenplain, same size. */
3661 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, NULL, surf_offscreen_dest64, NULL, D3DTEXF_NONE);
3662 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3663 color = getPixelColorFromSurface(surf_offscreen_dest64, 32, 32);
3664 ok(color == 0xff00ff00, "Got unexpected color 0x%08x.\n", color);
3665 /* Blit without scaling. */
3666 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, &src_rect64,
3667 surf_offscreen_dest64, &dst_rect64, D3DTEXF_NONE);
3668 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3669 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3670 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, &src_rect64_flipy,
3671 surf_offscreen_dest64, &dst_rect64, D3DTEXF_NONE);
3672 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3673 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3674 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, &src_rect64,
3675 surf_offscreen_dest64, &dst_rect64_flipy, D3DTEXF_NONE);
3676 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3678 /* offscreenplain ==> rendertarget texture, same size. */
3679 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, NULL, surf_tex_rt_dest64, NULL, D3DTEXF_NONE);
3680 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3681 /* We can't lock rendertarget textures, so copy to our temp surface first. */
3682 hr = IDirect3DDevice9_GetRenderTargetData(device, surf_tex_rt_dest64, surf_temp64);
3683 ok(SUCCEEDED(hr), "Failed to get render target data, hr %#x.\n", hr);
3684 color = getPixelColorFromSurface(surf_temp64, 32, 32);
3685 ok(color == 0xff00ff00, "Got unexpected color 0x%08x.\n", color);
3686 /* Blit without scaling. */
3687 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, &src_rect64,
3688 surf_tex_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3689 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3690 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3691 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, &src_rect64_flipy,
3692 surf_tex_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3693 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3694 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3695 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, &src_rect64,
3696 surf_tex_rt_dest64, &dst_rect64_flipy, D3DTEXF_NONE);
3697 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3699 /* offscreenplain ==> rendertarget surface, same size. */
3700 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, NULL, surf_rt_dest64, NULL, D3DTEXF_NONE);
3701 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3702 color = getPixelColorFromSurface(surf_rt_dest64, 32, 32);
3703 ok(color == 0xff00ff00, "Got unexpected color 0x%08x.\n", color);
3704 /* Blit without scaling. */
3705 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, &src_rect64,
3706 surf_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3707 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3708 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3709 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, &src_rect64_flipy,
3710 surf_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3711 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3712 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3713 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, &src_rect64,
3714 surf_rt_dest64, &dst_rect64_flipy, D3DTEXF_NONE);
3715 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3717 /* offscreenplain ==> texture, same size (should fail). */
3718 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, NULL, surf_tex_dest64, NULL, D3DTEXF_NONE);
3719 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3721 /* Fill the smaller offscreen surface with red. */
3722 fill_surface(surf_offscreen32, 0xffff0000, 0);
3724 /* offscreenplain ==> offscreenplain, scaling (should fail). */
3725 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen32, NULL, surf_offscreen64, NULL, D3DTEXF_NONE);
3726 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3728 /* offscreenplain ==> rendertarget texture, scaling. */
3729 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen32, NULL, surf_tex_rt_dest64, NULL, D3DTEXF_NONE);
3730 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3731 /* We can't lock rendertarget textures, so copy to our temp surface first. */
3732 hr = IDirect3DDevice9_GetRenderTargetData(device, surf_tex_rt_dest64, surf_temp64);
3733 ok(SUCCEEDED(hr), "Failed to get render target data, hr %#x.\n", hr);
3734 color = getPixelColorFromSurface(surf_temp64, 48, 48);
3735 ok(color == 0xffff0000, "Got unexpected color 0x%08x.\n", color);
3737 /* offscreenplain ==> rendertarget surface, scaling. */
3738 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen32, NULL, surf_rt_dest64, NULL, D3DTEXF_NONE);
3739 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3740 color = getPixelColorFromSurface(surf_rt_dest64, 48, 48);
3741 ok(color == 0xffff0000, "Got unexpected color 0x%08x.\n", color);
3743 /* offscreenplain ==> texture, scaling (should fail). */
3744 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen32, NULL, surf_tex_dest64, NULL, D3DTEXF_NONE);
3745 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3747 /*************************************************************
3748 * Tests for when the source parameter is a regular texture. *
3749 *************************************************************/
3751 /* Fill the surface of the regular texture with blue. */
3752 /* Can't fill the surf_tex directly because it's created in D3DPOOL_DEFAULT. */
3753 fill_surface(surf_temp64, 0xff0000ff, 0);
3754 hr = IDirect3DDevice9_UpdateSurface(device, surf_temp64, NULL, surf_tex64, NULL);
3755 ok(SUCCEEDED(hr), "Failed to update surface, hr %#x.\n", hr);
3757 /* texture ==> offscreenplain, same size. */
3758 hr = IDirect3DDevice9_StretchRect(device, surf_tex64, NULL, surf_offscreen64, NULL, D3DTEXF_NONE);
3759 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3761 /* texture ==> rendertarget texture, same size. */
3762 hr = IDirect3DDevice9_StretchRect(device, surf_tex64, NULL, surf_tex_rt_dest64, NULL, D3DTEXF_NONE);
3763 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3764 /* We can't lock rendertarget textures, so copy to our temp surface first. */
3765 hr = IDirect3DDevice9_GetRenderTargetData(device, surf_tex_rt_dest64, surf_temp64);
3766 ok(SUCCEEDED(hr), "Failed to get render target data, hr %#x.\n", hr);
3767 color = getPixelColorFromSurface(surf_temp64, 32, 32);
3768 ok(color == 0xff0000ff, "Got unexpected color 0x%08x.\n", color);
3769 /* Blit without scaling. */
3770 hr = IDirect3DDevice9_StretchRect(device, surf_tex64, &src_rect64,
3771 surf_tex_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3772 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3773 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3774 hr = IDirect3DDevice9_StretchRect(device, surf_tex64, &src_rect64_flipy,
3775 surf_tex_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3776 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3777 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3778 hr = IDirect3DDevice9_StretchRect(device, surf_tex64, &src_rect64,
3779 surf_tex_rt_dest64, &dst_rect64_flipy, D3DTEXF_NONE);
3780 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3782 /* texture ==> rendertarget surface, same size. */
3783 hr = IDirect3DDevice9_StretchRect(device, surf_tex64, NULL, surf_rt_dest64, NULL, D3DTEXF_NONE);
3784 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3785 color = getPixelColorFromSurface(surf_rt_dest64, 32, 32);
3786 ok(color == 0xff0000ff, "Got unexpected color 0x%08x.\n", color);
3787 /* Blit without scaling. */
3788 hr = IDirect3DDevice9_StretchRect(device, surf_tex64, &src_rect64,
3789 surf_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3790 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3791 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3792 hr = IDirect3DDevice9_StretchRect(device, surf_tex64, &src_rect64_flipy,
3793 surf_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3794 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3795 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3796 hr = IDirect3DDevice9_StretchRect(device, surf_tex64, &src_rect64,
3797 surf_rt_dest64, &dst_rect64_flipy, D3DTEXF_NONE);
3798 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3800 /* texture ==> texture, same size (should fail). */
3801 hr = IDirect3DDevice9_StretchRect(device, surf_tex64, NULL, surf_tex_dest64, NULL, D3DTEXF_NONE);
3802 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3804 /* Fill the surface of the smaller regular texture with red. */
3805 /* Can't fill the surf_tex directly because it's created in D3DPOOL_DEFAULT. */
3806 fill_surface(surf_temp32, 0xffff0000, 0);
3807 hr = IDirect3DDevice9_UpdateSurface(device, surf_temp32, NULL, surf_tex32, NULL);
3808 ok(SUCCEEDED(hr), "Failed to update surface, hr %#x.\n", hr);
3810 /* texture ==> offscreenplain, scaling (should fail). */
3811 hr = IDirect3DDevice9_StretchRect(device, surf_tex32, NULL, surf_offscreen64, NULL, D3DTEXF_NONE);
3812 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3814 /* texture ==> rendertarget texture, scaling. */
3815 hr = IDirect3DDevice9_StretchRect(device, surf_tex32, NULL, surf_tex_rt_dest64, NULL, D3DTEXF_NONE);
3816 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3817 /* We can't lock rendertarget textures, so copy to our temp surface first. */
3818 hr = IDirect3DDevice9_GetRenderTargetData(device, surf_tex_rt_dest64, surf_temp64);
3819 ok(SUCCEEDED(hr), "Failed to get render target data, hr %#x.\n", hr);
3820 color = getPixelColorFromSurface(surf_temp64, 48, 48);
3821 ok(color == 0xffff0000, "Got unexpected color 0x%08x.\n", color);
3823 /* texture ==> rendertarget surface, scaling. */
3824 hr = IDirect3DDevice9_StretchRect(device, surf_tex32, NULL, surf_rt_dest64, NULL, D3DTEXF_NONE);
3825 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3826 color = getPixelColorFromSurface(surf_rt_dest64, 48, 48);
3827 ok(color == 0xffff0000, "Got unexpected color 0x%08x.\n", color);
3829 /* texture ==> texture, scaling (should fail). */
3830 hr = IDirect3DDevice9_StretchRect(device, surf_tex32, NULL, surf_tex_dest64, NULL, D3DTEXF_NONE);
3831 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3833 /******************************************************************
3834 * Tests for when the source parameter is a rendertarget texture. *
3835 ******************************************************************/
3837 /* Fill the surface of the rendertarget texture with white. */
3838 /* Can't fill the surf_tex_rt directly because it's created in D3DPOOL_DEFAULT. */
3839 fill_surface(surf_temp64, 0xffffffff, 0);
3840 hr = IDirect3DDevice9_UpdateSurface(device, surf_temp64, NULL, surf_tex_rt64, NULL);
3841 ok(SUCCEEDED(hr), "Failed to update surface, hr %#x.\n", hr);
3843 /* rendertarget texture ==> offscreenplain, same size. */
3844 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt64, NULL, surf_offscreen64, NULL, D3DTEXF_NONE);
3845 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3847 /* rendertarget texture ==> rendertarget texture, same size. */
3848 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt64, NULL, surf_tex_rt_dest64, NULL, D3DTEXF_NONE);
3849 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3850 /* We can't lock rendertarget textures, so copy to our temp surface first. */
3851 hr = IDirect3DDevice9_GetRenderTargetData(device, surf_tex_rt_dest64, surf_temp64);
3852 ok(SUCCEEDED(hr), "Failed to get render target data, hr %#x.\n", hr);
3853 color = getPixelColorFromSurface(surf_temp64, 32, 32);
3854 ok(color == 0xffffffff, "Got unexpected color 0x%08x.\n", color);
3855 /* Blit without scaling. */
3856 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt64, &src_rect64,
3857 surf_tex_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3858 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3859 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3860 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt64, &src_rect64_flipy,
3861 surf_tex_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3862 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3863 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3864 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt64, &src_rect64,
3865 surf_tex_rt_dest64, &dst_rect64_flipy, D3DTEXF_NONE);
3866 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3868 /* rendertarget texture ==> rendertarget surface, same size. */
3869 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt64, NULL, surf_rt_dest64, NULL, D3DTEXF_NONE);
3870 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3871 color = getPixelColorFromSurface(surf_rt_dest64, 32, 32);
3872 ok(color == 0xffffffff, "Got unexpected color 0x%08x.\n", color);
3873 /* Blit without scaling. */
3874 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt64, &src_rect64,
3875 surf_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3876 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3877 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3878 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt64, &src_rect64_flipy,
3879 surf_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3880 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3881 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3882 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt64, &src_rect64,
3883 surf_rt_dest64, &dst_rect64_flipy, D3DTEXF_NONE);
3884 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3886 /* rendertarget texture ==> texture, same size (should fail). */
3887 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt64, NULL, surf_tex_dest64, NULL, D3DTEXF_NONE);
3888 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3890 /* Fill the surface of the smaller rendertarget texture with red. */
3891 /* Can't fill the surf_tex_rt directly because it's created in D3DPOOL_DEFAULT. */
3892 fill_surface(surf_temp32, 0xffff0000, 0);
3893 hr = IDirect3DDevice9_UpdateSurface(device, surf_temp32, NULL, surf_tex_rt32, NULL);
3894 ok(SUCCEEDED(hr), "Failed to update surface, hr %#x.\n", hr);
3896 /* rendertarget texture ==> offscreenplain, scaling (should fail). */
3897 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt32, NULL, surf_offscreen64, NULL, D3DTEXF_NONE);
3898 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3900 /* rendertarget texture ==> rendertarget texture, scaling. */
3901 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt32, NULL, surf_tex_rt_dest64, NULL, D3DTEXF_NONE);
3902 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3903 /* We can't lock rendertarget textures, so copy to our temp surface first. */
3904 hr = IDirect3DDevice9_GetRenderTargetData(device, surf_tex_rt_dest64, surf_temp64);
3905 ok(SUCCEEDED(hr), "Failed to get render target data, hr %#x.\n", hr);
3906 color = getPixelColorFromSurface(surf_temp64, 48, 48);
3907 ok(color == 0xffff0000, "Got unexpected color 0x%08x.\n", color);
3909 /* rendertarget texture ==> rendertarget surface, scaling. */
3910 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt32, NULL, surf_rt_dest64, NULL, D3DTEXF_NONE);
3911 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3912 color = getPixelColorFromSurface(surf_rt_dest64, 48, 48);
3913 ok(color == 0xffff0000, "Got unexpected color 0x%08x.\n", color);
3915 /* rendertarget texture ==> texture, scaling (should fail). */
3916 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt32, NULL, surf_tex_dest64, NULL, D3DTEXF_NONE);
3917 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3919 /******************************************************************
3920 * Tests for when the source parameter is a rendertarget surface. *
3921 ******************************************************************/
3923 /* Fill the surface of the rendertarget surface with black. */
3924 fill_surface(surf_rt64, 0xff000000, 0);
3926 /* rendertarget texture ==> offscreenplain, same size. */
3927 hr = IDirect3DDevice9_StretchRect(device, surf_rt64, NULL, surf_offscreen64, NULL, D3DTEXF_NONE);
3928 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3930 /* rendertarget surface ==> rendertarget texture, same size. */
3931 hr = IDirect3DDevice9_StretchRect(device, surf_rt64, NULL, surf_tex_rt_dest64, NULL, D3DTEXF_NONE);
3932 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3933 /* We can't lock rendertarget textures, so copy to our temp surface first. */
3934 hr = IDirect3DDevice9_GetRenderTargetData(device, surf_tex_rt_dest64, surf_temp64);
3935 ok(SUCCEEDED(hr), "Failed to get render target data, hr %#x.\n", hr);
3936 color = getPixelColorFromSurface(surf_temp64, 32, 32);
3937 ok(color == 0xff000000, "Got unexpected color 0x%08x.\n", color);
3938 /* Blit without scaling. */
3939 hr = IDirect3DDevice9_StretchRect(device, surf_rt64, &src_rect64,
3940 surf_tex_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3941 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3942 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3943 hr = IDirect3DDevice9_StretchRect(device, surf_rt64, &src_rect64_flipy,
3944 surf_tex_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3945 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3946 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3947 hr = IDirect3DDevice9_StretchRect(device, surf_rt64, &src_rect64,
3948 surf_tex_rt_dest64, &dst_rect64_flipy, D3DTEXF_NONE);
3949 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3951 /* rendertarget surface ==> rendertarget surface, same size. */
3952 hr = IDirect3DDevice9_StretchRect(device, surf_rt64, NULL, surf_rt_dest64, NULL, D3DTEXF_NONE);
3953 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3954 color = getPixelColorFromSurface(surf_rt_dest64, 32, 32);
3955 ok(color == 0xff000000, "Got unexpected color 0x%08x.\n", color);
3956 /* Blit without scaling. */
3957 hr = IDirect3DDevice9_StretchRect(device, surf_rt64, &src_rect64,
3958 surf_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3959 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3960 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3961 hr = IDirect3DDevice9_StretchRect(device, surf_rt64, &src_rect64_flipy,
3962 surf_rt_dest64, &dst_rect64_flipy, D3DTEXF_NONE);
3963 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3964 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3965 hr = IDirect3DDevice9_StretchRect(device, surf_rt64, &src_rect64,
3966 surf_rt_dest64, &dst_rect64_flipy, D3DTEXF_NONE);
3967 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3969 /* rendertarget surface ==> texture, same size (should fail). */
3970 hr = IDirect3DDevice9_StretchRect(device, surf_rt64, NULL, surf_tex_dest64, NULL, D3DTEXF_NONE);
3971 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3973 /* Fill the surface of the smaller rendertarget texture with red. */
3974 fill_surface(surf_rt32, 0xffff0000, 0);
3976 /* rendertarget surface ==> offscreenplain, scaling (should fail). */
3977 hr = IDirect3DDevice9_StretchRect(device, surf_rt32, NULL, surf_offscreen64, NULL, D3DTEXF_NONE);
3978 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3980 /* rendertarget surface ==> rendertarget texture, scaling. */
3981 hr = IDirect3DDevice9_StretchRect(device, surf_rt32, NULL, surf_tex_rt_dest64, NULL, D3DTEXF_NONE);
3982 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3983 /* We can't lock rendertarget textures, so copy to our temp surface first. */
3984 hr = IDirect3DDevice9_GetRenderTargetData(device, surf_tex_rt_dest64, surf_temp64);
3985 ok(SUCCEEDED(hr), "Failed to get render target data, hr %#x.\n", hr);
3986 color = getPixelColorFromSurface(surf_temp64, 48, 48);
3987 ok(color == 0xffff0000, "Got unexpected color 0x%08x.\n", color);
3989 /* rendertarget surface ==> rendertarget surface, scaling. */
3990 hr = IDirect3DDevice9_StretchRect(device, surf_rt32, NULL, surf_rt_dest64, NULL, D3DTEXF_NONE);
3991 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3992 color = getPixelColorFromSurface(surf_rt_dest64, 48, 48);
3993 ok(color == 0xffff0000, "Got unexpected color 0x%08x.\n", color);
3995 /* rendertarget surface ==> texture, scaling (should fail). */
3996 hr = IDirect3DDevice9_StretchRect(device, surf_rt32, NULL, surf_tex_dest64, NULL, D3DTEXF_NONE);
3997 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3999 /* backbuffer ==> surface tests (no scaling). */
4000 /* Blit with NULL rectangles. */
4001 hr = IDirect3DDevice9_StretchRect(device, backbuffer, NULL, surf_tex_rt_dest640_480, NULL, D3DTEXF_NONE);
4002 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
4003 /* Blit without scaling. */
4004 hr = IDirect3DDevice9_StretchRect(device, backbuffer, &src_rect,
4005 surf_tex_rt_dest640_480, &dst_rect, D3DTEXF_NONE);
4006 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
4007 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
4008 hr = IDirect3DDevice9_StretchRect(device, backbuffer, &src_rect_flipy,
4009 surf_tex_rt_dest640_480, &dst_rect, D3DTEXF_NONE);
4010 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
4011 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
4012 hr = IDirect3DDevice9_StretchRect(device, backbuffer, &src_rect,
4013 surf_tex_rt_dest640_480, &dst_rect_flipy, D3DTEXF_NONE);
4014 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
4016 /* TODO: Test format conversions. */
4018 IDirect3DSurface9_Release(backbuffer);
4019 IDirect3DSurface9_Release(surf_rt32);
4020 IDirect3DSurface9_Release(surf_rt64);
4021 IDirect3DSurface9_Release(surf_rt_dest64);
4022 IDirect3DSurface9_Release(surf_temp32);
4023 IDirect3DSurface9_Release(surf_temp64);
4024 IDirect3DSurface9_Release(surf_offscreen32);
4025 IDirect3DSurface9_Release(surf_offscreen64);
4026 IDirect3DSurface9_Release(surf_offscreen_dest64);
4027 IDirect3DSurface9_Release(surf_tex_rt32);
4028 IDirect3DTexture9_Release(tex_rt32);
4029 IDirect3DSurface9_Release(surf_tex_rt64);
4030 IDirect3DTexture9_Release(tex_rt64);
4031 IDirect3DSurface9_Release(surf_tex_rt_dest64);
4032 IDirect3DTexture9_Release(tex_rt_dest64);
4033 IDirect3DSurface9_Release(surf_tex_rt_dest640_480);
4034 IDirect3DTexture9_Release(tex_rt_dest640_480);
4035 IDirect3DSurface9_Release(surf_tex32);
4036 IDirect3DTexture9_Release(tex32);
4037 IDirect3DSurface9_Release(surf_tex64);
4038 IDirect3DTexture9_Release(tex64);
4039 IDirect3DSurface9_Release(surf_tex_dest64);
4040 IDirect3DTexture9_Release(tex_dest64);
4041 refcount = IDirect3DDevice9_Release(device);
4042 ok(!refcount, "Device has %u references left.\n", refcount);
4043 done:
4044 IDirect3D9_Release(d3d);
4045 DestroyWindow(window);
4048 static void maxmip_test(void)
4050 IDirect3DTexture9 *texture;
4051 IDirect3DSurface9 *surface;
4052 IDirect3DDevice9 *device;
4053 IDirect3D9 *d3d;
4054 D3DCOLOR color;
4055 ULONG refcount;
4056 D3DCAPS9 caps;
4057 HWND window;
4058 HRESULT hr;
4059 DWORD ret;
4061 static const struct
4063 struct
4065 float x, y, z;
4066 float s, t;
4068 v[4];
4070 quads[] =
4073 {-1.0, -1.0, 0.0, 0.0, 0.0},
4074 {-1.0, 0.0, 0.0, 0.0, 1.0},
4075 { 0.0, -1.0, 0.0, 1.0, 0.0},
4076 { 0.0, 0.0, 0.0, 1.0, 1.0},
4079 { 0.0, -1.0, 0.0, 0.0, 0.0},
4080 { 0.0, 0.0, 0.0, 0.0, 1.0},
4081 { 1.0, -1.0, 0.0, 1.0, 0.0},
4082 { 1.0, 0.0, 0.0, 1.0, 1.0},
4085 { 0.0, 0.0, 0.0, 0.0, 0.0},
4086 { 0.0, 1.0, 0.0, 0.0, 1.0},
4087 { 1.0, 0.0, 0.0, 1.0, 0.0},
4088 { 1.0, 1.0, 0.0, 1.0, 1.0},
4091 {-1.0, 0.0, 0.0, 0.0, 0.0},
4092 {-1.0, 1.0, 0.0, 0.0, 1.0},
4093 { 0.0, 0.0, 0.0, 1.0, 0.0},
4094 { 0.0, 1.0, 0.0, 1.0, 1.0},
4098 window = create_window();
4099 d3d = Direct3DCreate9(D3D_SDK_VERSION);
4100 ok(!!d3d, "Failed to create a D3D object.\n");
4101 if (!(device = create_device(d3d, window, window, TRUE)))
4103 skip("Failed to create a D3D device, skipping tests.\n");
4104 goto done;
4107 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
4108 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
4109 if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPMAP))
4111 skip("No mipmap support, skipping tests.\n");
4112 IDirect3DDevice9_Release(device);
4113 goto done;
4116 hr = IDirect3DDevice9_CreateTexture(device, 128, 128, 3, 0,
4117 D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture, NULL);
4118 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4120 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
4121 ok(SUCCEEDED(hr), "IDirect3DTexture9_GetSurfaceLevel returned %#x.\n", hr);
4122 fill_surface(surface, 0xffff0000, 0);
4123 IDirect3DSurface9_Release(surface);
4124 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 1, &surface);
4125 ok(SUCCEEDED(hr), "IDirect3DTexture9_GetSurfaceLevel returned %#x.\n", hr);
4126 fill_surface(surface, 0xff00ff00, 0);
4127 IDirect3DSurface9_Release(surface);
4128 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 2, &surface);
4129 ok(SUCCEEDED(hr), "IDirect3DTexture9_GetSurfaceLevel returned %#x.\n", hr);
4130 fill_surface(surface, 0xff0000ff, 0);
4131 IDirect3DSurface9_Release(surface);
4133 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) texture);
4134 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture failed with %08x\n", hr);
4135 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
4136 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
4138 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
4139 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
4140 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
4141 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState failed with %08x\n", hr);
4143 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 0.0, 0);
4144 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
4146 hr = IDirect3DDevice9_BeginScene(device);
4147 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4149 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 0);
4150 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
4151 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[0], sizeof(*quads->v));
4152 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4154 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 1);
4155 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
4156 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[1], sizeof(*quads->v));
4157 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4159 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 2);
4160 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
4161 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[2], sizeof(*quads->v));
4162 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4164 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 3);
4165 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
4166 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[3], sizeof(*quads->v));
4167 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4169 hr = IDirect3DDevice9_EndScene(device);
4170 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4172 /* With mipmapping disabled, the max mip level is ignored, only level 0 is used */
4173 color = getPixelColor(device, 160, 360);
4174 ok(color == 0x00ff0000, "MaxMip 0, no mipfilter has color 0x%08x.\n", color);
4175 color = getPixelColor(device, 480, 360);
4176 ok(color == 0x00ff0000, "MaxMip 1, no mipfilter has color 0x%08x.\n", color);
4177 color = getPixelColor(device, 480, 120);
4178 ok(color == 0x00ff0000, "MaxMip 2, no mipfilter has color 0x%08x.\n", color);
4179 color = getPixelColor(device, 160, 120);
4180 ok(color == 0x00ff0000, "MaxMip 3, no mipfilter has color 0x%08x.\n", color);
4181 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
4182 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
4184 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
4185 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState failed with %08x\n", hr);
4187 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 0.0, 0);
4188 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
4190 hr = IDirect3DDevice9_BeginScene(device);
4191 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4193 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 0);
4194 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
4195 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[0], sizeof(*quads->v));
4196 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4198 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 1);
4199 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
4200 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[1], sizeof(*quads->v));
4201 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4203 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 2);
4204 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
4205 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[2], sizeof(*quads->v));
4206 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4208 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 3);
4209 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
4210 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[3], sizeof(*quads->v));
4211 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4213 hr = IDirect3DDevice9_EndScene(device);
4214 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4216 /* Max Mip level 0-2 sample from the specified texture level, Max Mip
4217 * level 3 (> levels in texture) samples from the highest level in the
4218 * texture (level 2). */
4219 color = getPixelColor(device, 160, 360);
4220 ok(color == 0x00ff0000, "MaxMip 0, point mipfilter has color 0x%08x.\n", color);
4221 color = getPixelColor(device, 480, 360);
4222 ok(color == 0x0000ff00, "MaxMip 1, point mipfilter has color 0x%08x.\n", color);
4223 color = getPixelColor(device, 480, 120);
4224 ok(color == 0x000000ff, "MaxMip 2, point mipfilter has color 0x%08x.\n", color);
4225 color = getPixelColor(device, 160, 120);
4226 ok(color == 0x000000ff, "MaxMip 3, point mipfilter has color 0x%08x.\n", color);
4227 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
4228 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
4230 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 0.0, 0);
4231 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
4233 hr = IDirect3DDevice9_BeginScene(device);
4234 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4236 /* Mipmapping OFF, LOD level smaller than MAXMIPLEVEL. LOD level limits */
4237 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
4238 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
4239 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 0);
4240 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
4241 ret = IDirect3DTexture9_SetLOD(texture, 1);
4242 ok(ret == 0, "Got unexpected LOD %u.\n", ret);
4243 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[0], sizeof(*quads->v));
4244 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4246 /* Mipmapping ON, LOD level smaller than max mip level. LOD level limits */
4247 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
4248 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
4249 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 1);
4250 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
4251 ret = IDirect3DTexture9_SetLOD(texture, 2);
4252 ok(ret == 1, "Got unexpected LOD %u.\n", ret);
4253 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[1], sizeof(*quads->v));
4254 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4256 /* Mipmapping ON, LOD level bigger than max mip level. MAXMIPLEVEL limits */
4257 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 2);
4258 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
4259 ret = IDirect3DTexture9_SetLOD(texture, 1);
4260 ok(ret == 2, "Got unexpected LOD %u.\n", ret);
4261 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[2], sizeof(*quads->v));
4262 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4264 /* Mipmapping OFF, LOD level bigger than max mip level. LOD level limits */
4265 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
4266 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
4267 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 2);
4268 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
4269 ret = IDirect3DTexture9_SetLOD(texture, 1);
4270 ok(ret == 1, "Got unexpected LOD %u.\n", ret);
4271 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[3], sizeof(*quads->v));
4272 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4274 hr = IDirect3DDevice9_EndScene(device);
4275 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4277 /* Max Mip level 0-2 sample from the specified texture level, Max Mip
4278 * level 3 (> levels in texture) samples from the highest level in the
4279 * texture (level 2). */
4280 color = getPixelColor(device, 160, 360);
4281 ok(color == 0x0000ff00, "MaxMip 0, LOD 1, none mipfilter has color 0x%08x.\n", color);
4282 color = getPixelColor(device, 480, 360);
4283 ok(color == 0x000000ff, "MaxMip 1, LOD 2, point mipfilter has color 0x%08x.\n", color);
4284 color = getPixelColor(device, 480, 120);
4285 ok(color == 0x000000ff, "MaxMip 2, LOD 1, point mipfilter has color 0x%08x.\n", color);
4286 color = getPixelColor(device, 160, 120);
4287 ok(color == 0x0000ff00, "MaxMip 2, LOD 1, none mipfilter has color 0x%08x.\n", color);
4289 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
4290 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
4292 IDirect3DTexture9_Release(texture);
4293 refcount = IDirect3DDevice9_Release(device);
4294 ok(!refcount, "Device has %u references left.\n", refcount);
4295 done:
4296 IDirect3D9_Release(d3d);
4297 DestroyWindow(window);
4300 static void release_buffer_test(void)
4302 IDirect3DVertexBuffer9 *vb;
4303 IDirect3DIndexBuffer9 *ib;
4304 IDirect3DDevice9 *device;
4305 IDirect3D9 *d3d;
4306 D3DCOLOR color;
4307 ULONG refcount;
4308 HWND window;
4309 HRESULT hr;
4310 BYTE *data;
4311 LONG ref;
4313 static const short indices[] = {3, 4, 5};
4314 static const struct
4316 struct vec3 position;
4317 DWORD diffuse;
4319 quad[] =
4321 {{-1.0f, -1.0f, 0.1f}, 0xffff0000},
4322 {{-1.0f, 1.0f, 0.1f}, 0xffff0000},
4323 {{ 1.0f, 1.0f, 0.1f}, 0xffff0000},
4325 {{-1.0f, -1.0f, 0.1f}, 0xff00ff00},
4326 {{-1.0f, 1.0f, 0.1f}, 0xff00ff00},
4327 {{ 1.0f, 1.0f, 0.1f}, 0xff00ff00},
4330 window = create_window();
4331 d3d = Direct3DCreate9(D3D_SDK_VERSION);
4332 ok(!!d3d, "Failed to create a D3D object.\n");
4333 if (!(device = create_device(d3d, window, window, TRUE)))
4335 skip("Failed to create a D3D device, skipping tests.\n");
4336 goto done;
4339 /* Index and vertex buffers should always be creatable */
4340 hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(quad), 0,
4341 D3DFVF_XYZ | D3DFVF_DIFFUSE, D3DPOOL_MANAGED, &vb, NULL);
4342 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
4343 hr = IDirect3DVertexBuffer9_Lock(vb, 0, sizeof(quad), (void **) &data, 0);
4344 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr);
4345 memcpy(data, quad, sizeof(quad));
4346 hr = IDirect3DVertexBuffer9_Unlock(vb);
4347 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed with %08x\n", hr);
4349 hr = IDirect3DDevice9_CreateIndexBuffer(device, sizeof(indices), 0,
4350 D3DFMT_INDEX16, D3DPOOL_DEFAULT, &ib, NULL);
4351 ok(SUCCEEDED(hr), "Failed to create index buffer, hr %#x.\n", hr);
4352 hr = IDirect3DIndexBuffer9_Lock(ib, 0, sizeof(indices), (void **) &data, 0);
4353 ok(hr == D3D_OK, "IDirect3DIndexBuffer9_Lock failed with %08x\n", hr);
4354 memcpy(data, indices, sizeof(indices));
4355 hr = IDirect3DIndexBuffer9_Unlock(ib);
4356 ok(hr == D3D_OK, "IDirect3DIndexBuffer9_Unlock failed with %08x\n", hr);
4358 hr = IDirect3DDevice9_SetIndices(device, ib);
4359 ok(hr == D3D_OK, "IDirect3DDevice9_SetIndices failed with %08x\n", hr);
4360 hr = IDirect3DDevice9_SetStreamSource(device, 0, vb, 0, sizeof(quad[0]));
4361 ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSource failed with %08x\n", hr);
4362 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
4363 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
4364 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
4365 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
4367 /* Now destroy the bound index buffer and draw again */
4368 ref = IDirect3DIndexBuffer9_Release(ib);
4369 ok(ref == 0, "Index Buffer reference count is %08d\n", ref);
4371 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
4372 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
4374 hr = IDirect3DDevice9_BeginScene(device);
4375 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4376 /* Deliberately using minvertexindex = 0 and numVertices = 6 to prevent
4377 * D3D from making assumptions about the indices or vertices. */
4378 hr = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0, 3, 3, 0, 1);
4379 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4380 hr = IDirect3DDevice9_EndScene(device);
4381 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4383 color = getPixelColor(device, 160, 120);
4384 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1), "Got unexpected color 0x%08x.\n", color);
4385 color = getPixelColor(device, 480, 360);
4386 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0xff), 1), "Got unexpected color 0x%08x.\n", color);
4388 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
4389 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
4391 /* Index buffer was already destroyed as part of the test */
4392 IDirect3DVertexBuffer9_Release(vb);
4393 refcount = IDirect3DDevice9_Release(device);
4394 ok(!refcount, "Device has %u references left.\n", refcount);
4395 done:
4396 IDirect3D9_Release(d3d);
4397 DestroyWindow(window);
4400 static void float_texture_test(void)
4402 IDirect3DTexture9 *texture;
4403 IDirect3DDevice9 *device;
4404 D3DLOCKED_RECT lr;
4405 IDirect3D9 *d3d;
4406 ULONG refcount;
4407 float *data;
4408 DWORD color;
4409 HWND window;
4410 HRESULT hr;
4412 static const float quad[] =
4414 -1.0f, -1.0f, 0.1f, 0.0f, 0.0f,
4415 -1.0f, 1.0f, 0.1f, 0.0f, 1.0f,
4416 1.0f, -1.0f, 0.1f, 1.0f, 0.0f,
4417 1.0f, 1.0f, 0.1f, 1.0f, 1.0f,
4420 window = create_window();
4421 d3d = Direct3DCreate9(D3D_SDK_VERSION);
4422 ok(!!d3d, "Failed to create a D3D object.\n");
4423 if (!(device = create_device(d3d, window, window, TRUE)))
4425 skip("Failed to create a D3D device, skipping tests.\n");
4426 goto done;
4429 if (IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL,
4430 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, D3DFMT_R32F) != D3D_OK)
4432 skip("D3DFMT_R32F textures not supported\n");
4433 IDirect3DDevice9_Release(device);
4434 goto done;
4437 hr = IDirect3DDevice9_CreateTexture(device, 1, 1, 1, 0, D3DFMT_R32F, D3DPOOL_MANAGED, &texture, NULL);
4438 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4440 memset(&lr, 0, sizeof(lr));
4441 hr = IDirect3DTexture9_LockRect(texture, 0, &lr, NULL, 0);
4442 ok(hr == D3D_OK, "IDirect3DTexture9_LockRect failed with %08x\n", hr);
4443 data = lr.pBits;
4444 *data = 0.0;
4445 hr = IDirect3DTexture9_UnlockRect(texture, 0);
4446 ok(hr == D3D_OK, "IDirect3DTexture9_UnlockRect failed with %08x\n", hr);
4448 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
4449 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
4450 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
4451 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture failed with %08x\n", hr);
4453 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
4454 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
4456 hr = IDirect3DDevice9_BeginScene(device);
4457 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4458 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
4459 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
4460 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
4461 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4462 hr = IDirect3DDevice9_EndScene(device);
4463 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4465 color = getPixelColor(device, 240, 320);
4466 ok(color == 0x0000ffff, "R32F with value 0.0 has color %08x, expected 0x0000ffff\n", color);
4468 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
4469 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
4471 IDirect3DTexture9_Release(texture);
4472 refcount = IDirect3DDevice9_Release(device);
4473 ok(!refcount, "Device has %u references left.\n", refcount);
4474 done:
4475 IDirect3D9_Release(d3d);
4476 DestroyWindow(window);
4479 static void g16r16_texture_test(void)
4481 IDirect3DTexture9 *texture;
4482 IDirect3DDevice9 *device;
4483 D3DLOCKED_RECT lr;
4484 IDirect3D9 *d3d;
4485 ULONG refcount;
4486 DWORD *data;
4487 DWORD color;
4488 HWND window;
4489 HRESULT hr;
4491 static const float quad[] =
4493 -1.0f, -1.0f, 0.1f, 0.0f, 0.0f,
4494 -1.0f, 1.0f, 0.1f, 0.0f, 1.0f,
4495 1.0f, -1.0f, 0.1f, 1.0f, 0.0f,
4496 1.0f, 1.0f, 0.1f, 1.0f, 1.0f,
4499 window = create_window();
4500 d3d = Direct3DCreate9(D3D_SDK_VERSION);
4501 ok(!!d3d, "Failed to create a D3D object.\n");
4502 if (!(device = create_device(d3d, window, window, TRUE)))
4504 skip("Failed to create a D3D device, skipping tests.\n");
4505 goto done;
4508 if (IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL,
4509 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, D3DFMT_G16R16) != D3D_OK)
4511 skip("D3DFMT_G16R16 textures not supported\n");
4512 IDirect3DDevice9_Release(device);
4513 goto done;
4516 hr = IDirect3DDevice9_CreateTexture(device, 1, 1, 1, 0, D3DFMT_G16R16, D3DPOOL_MANAGED, &texture, NULL);
4517 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4519 memset(&lr, 0, sizeof(lr));
4520 hr = IDirect3DTexture9_LockRect(texture, 0, &lr, NULL, 0);
4521 ok(hr == D3D_OK, "IDirect3DTexture9_LockRect failed with %08x\n", hr);
4522 data = lr.pBits;
4523 *data = 0x0f00f000;
4524 hr = IDirect3DTexture9_UnlockRect(texture, 0);
4525 ok(hr == D3D_OK, "IDirect3DTexture9_UnlockRect failed with %08x\n", hr);
4527 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
4528 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
4529 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
4530 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture failed with %08x\n", hr);
4532 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
4533 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
4535 hr = IDirect3DDevice9_BeginScene(device);
4536 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4537 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
4538 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
4539 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
4540 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4541 hr = IDirect3DDevice9_EndScene(device);
4542 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4544 color = getPixelColor(device, 240, 320);
4545 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xf0, 0x0f, 0xff), 1),
4546 "D3DFMT_G16R16 with value 0x00ffff00 has color %08x, expected 0x00f00fff\n", color);
4548 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
4549 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
4551 IDirect3DTexture9_Release(texture);
4552 refcount = IDirect3DDevice9_Release(device);
4553 ok(!refcount, "Device has %u references left.\n", refcount);
4554 done:
4555 IDirect3D9_Release(d3d);
4556 DestroyWindow(window);
4559 static void check_rect(IDirect3DDevice9 *device, RECT r, const char *message)
4561 LONG x_coords[2][2] =
4563 {r.left - 1, r.left + 1},
4564 {r.right + 1, r.right - 1},
4566 LONG y_coords[2][2] =
4568 {r.top - 1, r.top + 1},
4569 {r.bottom + 1, r.bottom - 1}
4571 unsigned int i, j, x_side, y_side;
4573 for (i = 0; i < 2; ++i)
4575 for (j = 0; j < 2; ++j)
4577 for (x_side = 0; x_side < 2; ++x_side)
4579 for (y_side = 0; y_side < 2; ++y_side)
4581 unsigned int x = x_coords[i][x_side], y = y_coords[j][y_side];
4582 DWORD color;
4583 DWORD expected = (x_side == 1 && y_side == 1) ? 0x00ffffff : 0;
4585 color = getPixelColor(device, x, y);
4586 ok(color == expected, "%s: Pixel (%d, %d) has color %08x, expected %08x\n",
4587 message, x, y, color, expected);
4594 struct projected_textures_test_run
4596 const char *message;
4597 DWORD flags;
4598 IDirect3DVertexDeclaration9 *decl;
4599 BOOL vs, ps;
4600 RECT rect;
4603 static void projected_textures_test(IDirect3DDevice9 *device,
4604 struct projected_textures_test_run tests[4])
4606 unsigned int i;
4608 static const DWORD vertex_shader[] =
4610 0xfffe0101, /* vs_1_1 */
4611 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
4612 0x0000001f, 0x80000005, 0x900f0001, /* dcl_texcoord0 v1 */
4613 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
4614 0x00000001, 0xe00f0000, 0x90e40001, /* mov oT0, v1 */
4615 0x0000ffff /* end */
4617 static const DWORD pixel_shader[] =
4619 0xffff0103, /* ps_1_3 */
4620 0x00000042, 0xb00f0000, /* tex t0 */
4621 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
4622 0x0000ffff /* end */
4624 IDirect3DVertexShader9 *vs = NULL;
4625 IDirect3DPixelShader9 *ps = NULL;
4626 IDirect3D9 *d3d;
4627 D3DCAPS9 caps;
4628 HRESULT hr;
4630 IDirect3DDevice9_GetDirect3D(device, &d3d);
4631 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
4632 ok(SUCCEEDED(hr), "GetDeviceCaps failed (%08x)\n", hr);
4633 IDirect3D9_Release(d3d);
4635 if (caps.VertexShaderVersion >= D3DVS_VERSION(1, 1))
4637 hr = IDirect3DDevice9_CreateVertexShader(device, vertex_shader, &vs);
4638 ok(SUCCEEDED(hr), "CreateVertexShader failed (%08x)\n", hr);
4640 if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 3))
4642 hr = IDirect3DDevice9_CreatePixelShader(device, pixel_shader, &ps);
4643 ok(SUCCEEDED(hr), "CreatePixelShader failed (%08x)\n", hr);
4646 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff203040, 0.0f, 0);
4647 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
4649 hr = IDirect3DDevice9_BeginScene(device);
4650 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4652 for (i = 0; i < 4; ++i)
4654 DWORD value = 0xdeadbeef;
4655 static const float proj_quads[] =
4657 -1.0f, -1.0f, 0.1f, 0.0f, 0.0f, 4.0f, 6.0f,
4658 -1.0f, 0.0f, 0.1f, 0.0f, 4.0f, 4.0f, 6.0f,
4659 0.0f, -1.0f, 0.1f, 4.0f, 0.0f, 4.0f, 6.0f,
4660 0.0f, 0.0f, 0.1f, 4.0f, 4.0f, 4.0f, 6.0f,
4662 0.0f, -1.0f, 0.1f, 0.0f, 0.0f, 4.0f, 6.0f,
4663 0.0f, 0.0f, 0.1f, 0.0f, 4.0f, 4.0f, 6.0f,
4664 1.0f, -1.0f, 0.1f, 4.0f, 0.0f, 4.0f, 6.0f,
4665 1.0f, 0.0f, 0.1f, 4.0f, 4.0f, 4.0f, 6.0f,
4667 -1.0f, 0.0f, 0.1f, 0.0f, 0.0f, 4.0f, 6.0f,
4668 -1.0f, 1.0f, 0.1f, 0.0f, 4.0f, 4.0f, 6.0f,
4669 0.0f, 0.0f, 0.1f, 4.0f, 0.0f, 4.0f, 6.0f,
4670 0.0f, 1.0f, 0.1f, 4.0f, 4.0f, 4.0f, 6.0f,
4672 0.0f, 0.0f, 0.1f, 0.0f, 0.0f, 4.0f, 6.0f,
4673 0.0f, 1.0f, 0.1f, 0.0f, 4.0f, 4.0f, 6.0f,
4674 1.0f, 0.0f, 0.1f, 4.0f, 0.0f, 4.0f, 6.0f,
4675 1.0f, 1.0f, 0.1f, 4.0f, 4.0f, 4.0f, 6.0f,
4678 if (tests[i].vs)
4680 if (!vs)
4682 skip("Vertex shaders not supported, skipping\n");
4683 continue;
4685 hr = IDirect3DDevice9_SetVertexShader(device, vs);
4687 else
4688 hr = IDirect3DDevice9_SetVertexShader(device, NULL);
4689 ok(SUCCEEDED(hr), "SetVertexShader failed (%08x)\n", hr);
4690 if (tests[i].ps)
4692 if (!ps)
4694 skip("Pixel shaders not supported, skipping\n");
4695 continue;
4697 hr = IDirect3DDevice9_SetPixelShader(device, ps);
4699 else
4700 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
4701 ok(SUCCEEDED(hr), "SetPixelShader failed (%08x)\n", hr);
4703 hr = IDirect3DDevice9_SetVertexDeclaration(device, tests[i].decl);
4704 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexDeclaration failed with %08x\n", hr);
4706 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, tests[i].flags);
4707 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
4708 hr = IDirect3DDevice9_GetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, &value);
4709 ok(SUCCEEDED(hr) && value == tests[i].flags,
4710 "GetTextureStageState returned: hr %08x, value %08x.\n", hr, value);
4712 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2,
4713 &proj_quads[i * 4 * 7], 7 * sizeof(float));
4714 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%08x)\n", hr);
4717 hr = IDirect3DDevice9_EndScene(device);
4718 ok(hr == D3D_OK, "IDirect3DDevice9_EndScene failed with %08x\n", hr);
4720 hr = IDirect3DDevice9_SetVertexShader(device, NULL);
4721 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
4722 if (vs) IDirect3DVertexShader9_Release(vs);
4723 if (ps) IDirect3DPixelShader9_Release(ps);
4725 for (i = 0; i < 4; ++i)
4727 if ((!tests[i].vs || vs) && (!tests[i].ps || ps))
4728 check_rect(device, tests[i].rect, tests[i].message);
4731 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
4732 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
4735 static void texture_transform_flags_test(void)
4737 HRESULT hr;
4738 IDirect3D9 *d3d;
4739 D3DFORMAT fmt = D3DFMT_X8R8G8B8;
4740 D3DCAPS9 caps;
4741 IDirect3DTexture9 *texture = NULL;
4742 IDirect3DVolumeTexture9 *volume = NULL;
4743 IDirect3DDevice9 *device;
4744 unsigned int x, y, z;
4745 D3DLOCKED_RECT lr;
4746 D3DLOCKED_BOX lb;
4747 D3DCOLOR color;
4748 ULONG refcount;
4749 HWND window;
4750 UINT w, h;
4751 IDirect3DVertexDeclaration9 *decl, *decl2, *decl3, *decl4;
4753 static const D3DVERTEXELEMENT9 decl_elements[] = {
4754 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
4755 {0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
4756 D3DDECL_END()
4758 static const D3DVERTEXELEMENT9 decl_elements2[] = {
4759 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
4760 {0, 12, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
4761 D3DDECL_END()
4763 static const D3DVERTEXELEMENT9 decl_elements3[] = {
4764 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
4765 {0, 12, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
4766 D3DDECL_END()
4768 static const D3DVERTEXELEMENT9 decl_elements4[] = {
4769 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
4770 {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
4771 D3DDECL_END()
4773 static const unsigned char proj_texdata[] = {0x00, 0x00, 0x00, 0x00,
4774 0x00, 0xff, 0x00, 0x00,
4775 0x00, 0x00, 0x00, 0x00,
4776 0x00, 0x00, 0x00, 0x00};
4777 static const D3DMATRIX identity =
4779 1.0f, 0.0f, 0.0f, 0.0f,
4780 0.0f, 1.0f, 0.0f, 0.0f,
4781 0.0f, 0.0f, 1.0f, 0.0f,
4782 0.0f, 0.0f, 0.0f, 1.0f,
4783 }}};
4785 window = create_window();
4786 d3d = Direct3DCreate9(D3D_SDK_VERSION);
4787 ok(!!d3d, "Failed to create a D3D object.\n");
4788 if (!(device = create_device(d3d, window, window, TRUE)))
4790 skip("Failed to create a D3D device, skipping tests.\n");
4791 goto done;
4794 memset(&lr, 0, sizeof(lr));
4795 memset(&lb, 0, sizeof(lb));
4796 if (IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL,
4797 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16) == D3D_OK)
4798 fmt = D3DFMT_A16B16G16R16;
4800 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &decl);
4801 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
4802 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements2, &decl2);
4803 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
4804 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements3, &decl3);
4805 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
4806 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements4, &decl4);
4807 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
4808 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, FALSE);
4809 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState(D3DSAMP_SRGBTEXTURE) returned %08x\n", hr);
4810 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
4811 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState(D3DSAMP_MAGFILTER) returned %08x\n", hr);
4812 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
4813 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState(D3DSAMP_MINFILTER) returned %08x\n", hr);
4814 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
4815 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState(D3DSAMP_MIPFILTER) returned %08x\n", hr);
4816 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
4817 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState(D3DSAMP_ADDRESSU) returned %08x\n", hr);
4818 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
4819 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState(D3DSAMP_ADDRESSV) returned %08x\n", hr);
4820 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSW, D3DTADDRESS_CLAMP);
4821 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState(D3DSAMP_ADDRESSW) returned %08x\n", hr);
4822 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
4823 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState(D3DTSS_COLOROP) returned %08x\n", hr);
4824 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
4825 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState(D3DTSS_COLORARG1) returned %08x\n", hr);
4826 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
4827 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState(D3DRS_LIGHTING) returned %08x\n", hr);
4828 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
4829 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
4831 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
4832 ok(hr == D3D_OK, "IDirect3DDevice9_GetDeviceCaps returned %08x\n", hr);
4833 w = min(1024, caps.MaxTextureWidth);
4834 h = min(1024, caps.MaxTextureHeight);
4835 hr = IDirect3DDevice9_CreateTexture(device, w, h, 1,
4836 0, fmt, D3DPOOL_MANAGED, &texture, NULL);
4837 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture returned %08x\n", hr);
4838 if (!texture)
4840 skip("Failed to create the test texture.\n");
4841 IDirect3DDevice9_Release(device);
4842 goto done;
4845 /* Unfortunately there is no easy way to set up a texture coordinate passthrough
4846 * in d3d fixed function pipeline, so create a texture that has a gradient from 0.0 to
4847 * 1.0 in red and green for the x and y coords
4849 hr = IDirect3DTexture9_LockRect(texture, 0, &lr, NULL, 0);
4850 ok(hr == D3D_OK, "IDirect3DTexture9_LockRect returned %08x\n", hr);
4851 for(y = 0; y < h; y++) {
4852 for(x = 0; x < w; x++) {
4853 double r_f = (double) y / (double) h;
4854 double g_f = (double) x / (double) w;
4855 if(fmt == D3DFMT_A16B16G16R16) {
4856 unsigned short r, g;
4857 unsigned short *dst = (unsigned short *) (((char *) lr.pBits) + y * lr.Pitch + x * 8);
4858 r = (unsigned short) (r_f * 65536.0);
4859 g = (unsigned short) (g_f * 65536.0);
4860 dst[0] = r;
4861 dst[1] = g;
4862 dst[2] = 0;
4863 dst[3] = 65535;
4864 } else {
4865 unsigned char *dst = ((unsigned char *) lr.pBits) + y * lr.Pitch + x * 4;
4866 unsigned char r = (unsigned char) (r_f * 255.0);
4867 unsigned char g = (unsigned char) (g_f * 255.0);
4868 dst[0] = 0;
4869 dst[1] = g;
4870 dst[2] = r;
4871 dst[3] = 255;
4875 hr = IDirect3DTexture9_UnlockRect(texture, 0);
4876 ok(hr == D3D_OK, "IDirect3DTexture9_UnlockRect returned %08x\n", hr);
4877 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) texture);
4878 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture returned %08x\n", hr);
4880 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
4881 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
4882 hr = IDirect3DDevice9_BeginScene(device);
4883 ok(hr == D3D_OK, "IDirect3DDevice9_BeginScene failed with %08x\n", hr);
4884 if(SUCCEEDED(hr))
4886 static const float quad1[] =
4888 -1.0f, -1.0f, 0.1f, 1.0f, 1.0f,
4889 -1.0f, 0.0f, 0.1f, 1.0f, 1.0f,
4890 0.0f, -1.0f, 0.1f, 1.0f, 1.0f,
4891 0.0f, 0.0f, 0.1f, 1.0f, 1.0f,
4893 static const float quad2[] =
4895 -1.0f, 0.0f, 0.1f, 1.0f, 1.0f,
4896 -1.0f, 1.0f, 0.1f, 1.0f, 1.0f,
4897 0.0f, 0.0f, 0.1f, 1.0f, 1.0f,
4898 0.0f, 1.0f, 0.1f, 1.0f, 1.0f,
4900 static const float quad3[] =
4902 0.0f, 0.0f, 0.1f, 0.5f, 0.5f,
4903 0.0f, 1.0f, 0.1f, 0.5f, 0.5f,
4904 1.0f, 0.0f, 0.1f, 0.5f, 0.5f,
4905 1.0f, 1.0f, 0.1f, 0.5f, 0.5f,
4907 static const float quad4[] =
4909 320.0f, 480.0f, 0.1f, 1.0f, 0.0f, 1.0f,
4910 320.0f, 240.0f, 0.1f, 1.0f, 0.0f, 1.0f,
4911 640.0f, 480.0f, 0.1f, 1.0f, 0.0f, 1.0f,
4912 640.0f, 240.0f, 0.1f, 1.0f, 0.0f, 1.0f,
4914 D3DMATRIX mat =
4916 0.0f, 0.0f, 0.0f, 0.0f,
4917 0.0f, 0.0f, 0.0f, 0.0f,
4918 0.0f, 0.0f, 0.0f, 0.0f,
4919 0.0f, 0.0f, 0.0f, 0.0f,
4920 }}};
4922 /* What happens with the texture matrix if D3DTSS_TEXTURETRANSFORMFLAGS is disabled? */
4923 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &mat);
4924 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
4925 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, 5 * sizeof(float));
4926 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%08x)\n", hr);
4928 /* What happens with transforms enabled? */
4929 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
4930 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
4931 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 5 * sizeof(float));
4932 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%08x)\n", hr);
4934 /* What happens if 4 coords are used, but only 2 given ?*/
4935 U(mat).m[2][0] = 1.0f;
4936 U(mat).m[3][1] = 1.0f;
4937 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &mat);
4938 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
4939 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT4);
4940 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
4941 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, 5 * sizeof(float));
4942 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%08x)\n", hr);
4944 /* What happens with transformed geometry? This setup lead to 0/0 coords with untransformed
4945 * geometry. If the same applies to transformed vertices, the quad will be black, otherwise red,
4946 * due to the coords in the vertices. (turns out red, indeed)
4948 memset(&mat, 0, sizeof(mat));
4949 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &mat);
4950 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
4951 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZRHW | D3DFVF_TEX1);
4952 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
4953 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
4954 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
4955 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, 6 * sizeof(float));
4956 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%08x)\n", hr);
4958 hr = IDirect3DDevice9_EndScene(device);
4959 ok(hr == D3D_OK, "IDirect3DDevice9_EndScene failed with %08x\n", hr);
4961 color = getPixelColor(device, 160, 360);
4962 ok(color_match(color, 0x00ffff00, 1), "quad 1 has color %08x, expected 0x00ffff00\n", color);
4963 color = getPixelColor(device, 160, 120);
4964 ok(color == 0x00000000, "quad 2 has color %08x, expected 0x0000000\n", color);
4965 color = getPixelColor(device, 480, 120);
4966 ok(color_match(color, 0x0000ff00, 1), "quad 3 has color %08x, expected 0x0000ff00\n", color);
4967 color = getPixelColor(device, 480, 360);
4968 ok(color_match(color, 0x00ff0000, 1), "quad 4 has color %08x, expected 0x00ff0000\n", color);
4969 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
4970 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
4972 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0, 0);
4973 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
4975 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
4976 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
4977 hr = IDirect3DDevice9_BeginScene(device);
4978 ok(hr == D3D_OK, "IDirect3DDevice9_BeginScene failed with %08x\n", hr);
4979 if(SUCCEEDED(hr))
4981 static const float quad1[] =
4983 -1.0f, -1.0f, 0.1f, 0.8f, 0.2f,
4984 -1.0f, 0.0f, 0.1f, 0.8f, 0.2f,
4985 0.0f, -1.0f, 0.1f, 0.8f, 0.2f,
4986 0.0f, 0.0f, 0.1f, 0.8f, 0.2f,
4988 static const float quad2[] =
4990 -1.0f, 0.0f, 0.1f, 0.5f, 1.0f,
4991 -1.0f, 1.0f, 0.1f, 0.5f, 1.0f,
4992 0.0f, 0.0f, 0.1f, 0.5f, 1.0f,
4993 0.0f, 1.0f, 0.1f, 0.5f, 1.0f,
4995 static const float quad3[] =
4997 0.0f, 0.0f, 0.1f, 0.5f, 1.0f,
4998 0.0f, 1.0f, 0.1f, 0.5f, 1.0f,
4999 1.0f, 0.0f, 0.1f, 0.5f, 1.0f,
5000 1.0f, 1.0f, 0.1f, 0.5f, 1.0f,
5002 static const float quad4[] =
5004 0.0f, -1.0f, 0.1f, 0.8f, 0.2f,
5005 0.0f, 0.0f, 0.1f, 0.8f, 0.2f,
5006 1.0f, -1.0f, 0.1f, 0.8f, 0.2f,
5007 1.0f, 0.0f, 0.1f, 0.8f, 0.2f,
5009 D3DMATRIX mat =
5011 0.0f, 0.0f, 0.0f, 0.0f,
5012 0.0f, 0.0f, 0.0f, 0.0f,
5013 0.0f, 1.0f, 0.0f, 0.0f,
5014 0.0f, 0.0f, 0.0f, 0.0f,
5015 }}};
5017 /* What happens to the default 1 in the 3rd coordinate if it is disabled? */
5018 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &mat);
5019 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
5020 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
5021 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
5023 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, 5 * sizeof(float));
5024 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%08x)\n", hr);
5026 /* D3DTFF_COUNT1 does not work on Nvidia drivers. It behaves like D3DTTFF_DISABLE. On ATI drivers
5027 * it behaves like COUNT2 because normal textures require 2 coords. */
5028 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT1);
5029 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
5030 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, 5 * sizeof(float));
5031 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%08x)\n", hr);
5033 /* Just to be sure, the same as quad2 above */
5034 memset(&mat, 0, sizeof(mat));
5035 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &mat);
5036 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
5037 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
5038 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
5039 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 5 * sizeof(float));
5040 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%08x)\n", hr);
5042 /* Now, what happens to the 2nd coordinate(that is disabled in the matrix) if it is not
5043 * used? And what happens to the first? */
5044 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT1);
5045 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
5046 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, 5 * sizeof(float));
5047 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%08x)\n", hr);
5049 hr = IDirect3DDevice9_EndScene(device);
5050 ok(hr == D3D_OK, "IDirect3DDevice9_EndScene failed with %08x\n", hr);
5052 color = getPixelColor(device, 160, 360);
5053 ok(color_match(color, 0x00ff0000, 1), "quad 1 has color %08x, expected 0x00ff0000\n", color);
5054 color = getPixelColor(device, 160, 120);
5055 ok(color == 0x00000000, "quad 2 has color %08x, expected 0x0000000\n", color);
5056 color = getPixelColor(device, 480, 120);
5057 ok(color_match(color, 0x00ff8000, 1) || color == 0x00000000,
5058 "quad 3 has color %08x, expected 0x00ff8000\n", color);
5059 color = getPixelColor(device, 480, 360);
5060 ok(color_match(color, 0x0033cc00, 1) || color_match(color, 0x00ff0000, 1),
5061 "quad 4 has color %08x, expected 0x0033cc00\n", color);
5062 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
5063 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
5065 IDirect3DTexture9_Release(texture);
5067 /* Test projected textures, without any fancy matrices */
5068 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_L8, D3DPOOL_MANAGED, &texture, NULL);
5069 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture returned %08x\n", hr);
5070 if (SUCCEEDED(hr))
5072 struct projected_textures_test_run projected_tests_1[4] =
5075 "D3DTTFF_COUNT4 | D3DTTFF_PROJECTED - bottom left",
5076 D3DTTFF_COUNT4 | D3DTTFF_PROJECTED,
5077 decl3,
5078 FALSE, TRUE,
5079 {120, 300, 240, 390},
5082 "D3DTTFF_COUNT3 | D3DTTFF_PROJECTED - bottom right",
5083 D3DTTFF_COUNT3 | D3DTTFF_PROJECTED,
5084 decl3,
5085 FALSE, TRUE,
5086 {400, 360, 480, 420},
5088 /* Try with some invalid values */
5090 "0xffffffff (draws like COUNT4 | PROJECTED) - top left",
5091 0xffffffff,
5092 decl3,
5093 FALSE, TRUE,
5094 {120, 60, 240, 150}
5097 "D3DTTFF_COUNT3 | D3DTTFF_PROJECTED (draws non-projected) - top right",
5098 D3DTTFF_COUNT3 | D3DTTFF_PROJECTED,
5099 decl4,
5100 FALSE, TRUE,
5101 {340, 210, 360, 225},
5104 struct projected_textures_test_run projected_tests_2[4] =
5107 "D3DTTFF_PROJECTED (like COUNT4 | PROJECTED, texcoord has 4 components) - bottom left",
5108 D3DTTFF_PROJECTED,
5109 decl3,
5110 FALSE, TRUE,
5111 {120, 300, 240, 390},
5114 "D3DTTFF_PROJECTED (like COUNT3 | PROJECTED, texcoord has only 3 components) - bottom right",
5115 D3DTTFF_PROJECTED,
5116 decl,
5117 FALSE, TRUE,
5118 {400, 360, 480, 420},
5121 "0xffffffff (like COUNT3 | PROJECTED, texcoord has only 3 components) - top left",
5122 0xffffffff,
5123 decl,
5124 FALSE, TRUE,
5125 {80, 120, 160, 180},
5128 "D3DTTFF_COUNT1 (draws non-projected) - top right",
5129 D3DTTFF_COUNT1,
5130 decl4,
5131 FALSE, TRUE,
5132 {340, 210, 360, 225},
5135 struct projected_textures_test_run projected_tests_3[4] =
5138 "D3DTTFF_COUNT3 | D3DTTFF_PROJECTED (like COUNT4 | PROJECTED) - bottom left",
5139 D3DTTFF_PROJECTED,
5140 decl3,
5141 TRUE, FALSE,
5142 {120, 300, 240, 390},
5145 "D3DTTFF_COUNT3 | D3DTTFF_PROJECTED (like COUNT4 | PROJECTED) - bottom right",
5146 D3DTTFF_COUNT3 | D3DTTFF_PROJECTED,
5147 decl3,
5148 TRUE, TRUE,
5149 {440, 300, 560, 390},
5152 "0xffffffff (like COUNT4 | PROJECTED) - top left",
5153 0xffffffff,
5154 decl3,
5155 TRUE, TRUE,
5156 {120, 60, 240, 150},
5159 "D3DTTFF_PROJECTED (like COUNT4 | PROJECTED) - top right",
5160 D3DTTFF_PROJECTED,
5161 decl3,
5162 FALSE, FALSE,
5163 {440, 60, 560, 150},
5167 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &identity);
5168 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
5170 hr = IDirect3DTexture9_LockRect(texture, 0, &lr, NULL, 0);
5171 ok(hr == D3D_OK, "IDirect3DTexture9_LockRect failed with %08x\n", hr);
5172 for(x = 0; x < 4; x++) {
5173 memcpy(((BYTE *) lr.pBits) + lr.Pitch * x, proj_texdata + 4 * x, 4 * sizeof(proj_texdata[0]));
5175 hr = IDirect3DTexture9_UnlockRect(texture, 0);
5176 ok(hr == D3D_OK, "IDirect3DTexture9_UnlockRect failed with %08x\n", hr);
5177 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) texture);
5178 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture failed with %08x\n", hr);
5180 projected_textures_test(device, projected_tests_1);
5181 projected_textures_test(device, projected_tests_2);
5182 projected_textures_test(device, projected_tests_3);
5184 hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
5185 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture failed with %08x\n", hr);
5186 IDirect3DTexture9_Release(texture);
5189 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff203040, 0.0, 0);
5190 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
5191 /* Use a smaller volume texture than the biggest possible size for memory and performance reasons
5192 * Thus watch out if sampling from texels between 0 and 1.
5194 hr = IDirect3DDevice9_CreateVolumeTexture(device, 32, 32, 32, 1, 0, fmt, D3DPOOL_MANAGED, &volume, 0);
5195 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL,
5196 "IDirect3DDevice9_CreateVolumeTexture failed with %08x\n", hr);
5197 if(!volume) {
5198 skip("Failed to create a volume texture\n");
5199 goto out;
5202 hr = IDirect3DVolumeTexture9_LockBox(volume, 0, &lb, NULL, 0);
5203 ok(hr == D3D_OK, "IDirect3DVolumeTexture9_LockBox failed with %08x\n", hr);
5204 for(z = 0; z < 32; z++) {
5205 for(y = 0; y < 32; y++) {
5206 for(x = 0; x < 32; x++) {
5207 char size = (fmt == D3DFMT_A16B16G16R16 ? 8 : 4);
5208 void *mem = ((char *) lb.pBits) + y * lb.RowPitch + z * lb.SlicePitch + x * size;
5209 float r_f = (float) x / 31.0;
5210 float g_f = (float) y / 31.0;
5211 float b_f = (float) z / 31.0;
5213 if(fmt == D3DFMT_A16B16G16R16) {
5214 unsigned short *mem_s = mem;
5215 mem_s[0] = r_f * 65535.0;
5216 mem_s[1] = g_f * 65535.0;
5217 mem_s[2] = b_f * 65535.0;
5218 mem_s[3] = 65535;
5219 } else {
5220 unsigned char *mem_c = mem;
5221 mem_c[0] = b_f * 255.0;
5222 mem_c[1] = g_f * 255.0;
5223 mem_c[2] = r_f * 255.0;
5224 mem_c[3] = 255;
5229 hr = IDirect3DVolumeTexture9_UnlockBox(volume, 0);
5230 ok(hr == D3D_OK, "IDirect3DVolumeTexture9_UnlockBox failed with %08x\n", hr);
5232 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) volume);
5233 ok(hr == D3D_OK, "IDirect3DVolumeTexture9_UnlockBox failed with %08x\n", hr);
5235 hr = IDirect3DDevice9_BeginScene(device);
5236 ok(hr == D3D_OK, "IDirect3DDevice9_BeginScene failed with %08x\n", hr);
5237 if(SUCCEEDED(hr))
5239 static const float quad1[] =
5241 -1.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f,
5242 -1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f,
5243 0.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f,
5244 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f,
5246 static const float quad2[] =
5248 -1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f,
5249 -1.0f, 1.0f, 0.1f, 1.0f, 1.0f, 1.0f,
5250 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f,
5251 0.0f, 1.0f, 0.1f, 1.0f, 1.0f, 1.0f,
5253 static const float quad3[] =
5255 0.0f, 0.0f, 0.1f, 0.0f, 0.0f,
5256 0.0f, 1.0f, 0.1f, 0.0f, 0.0f,
5257 1.0f, 0.0f, 0.1f, 0.0f, 0.0f,
5258 1.0f, 1.0f, 0.1f, 0.0f, 0.0f,
5260 static const float quad4[] =
5262 0.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f,
5263 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f,
5264 1.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f,
5265 1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f,
5267 D3DMATRIX mat =
5269 1.0f, 0.0f, 0.0f, 0.0f,
5270 0.0f, 0.0f, 1.0f, 0.0f,
5271 0.0f, 1.0f, 0.0f, 0.0f,
5272 0.0f, 0.0f, 0.0f, 1.0f,
5273 }}};
5274 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl);
5275 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexDeclaration failed with %08x\n", hr);
5277 /* Draw a quad with all 3 coords enabled. Nothing fancy. v and w are swapped, but have the same
5278 * values
5280 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &mat);
5281 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
5282 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3);
5283 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
5284 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, 6 * sizeof(float));
5285 ok(hr == D3D_OK, "DrawPrimitiveUP failed (%08x)\n", hr);
5287 /* Now disable the w coordinate. Does that change the input, or the output. The coordinates
5288 * are swapped by the matrix. If it changes the input, the v coord will be missing(green),
5289 * otherwise the w will be missing(blue).
5290 * turns out that on nvidia cards the blue color is missing, so it is an output modification.
5291 * On ATI cards the COUNT2 is ignored, and it behaves in the same way as COUNT3. */
5292 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
5293 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
5294 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 6 * sizeof(float));
5295 ok(hr == D3D_OK, "DrawPrimitiveUP failed (%08x)\n", hr);
5297 /* default values? Set up the identity matrix, pass in 2 vertex coords, and enable 3 */
5298 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &identity);
5299 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
5300 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3);
5301 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
5302 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
5303 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
5304 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, 5 * sizeof(float));
5305 ok(hr == D3D_OK, "DrawPrimitiveUP failed (%08x)\n", hr);
5307 /* D3DTTFF_COUNT1. Set a NULL matrix, and count1, pass in all values as 1.0. Nvidia has count1 ==
5308 * disable. ATI extends it up to the amount of values needed for the volume texture
5310 memset(&mat, 0, sizeof(mat));
5311 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &mat);
5312 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
5313 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT1);
5314 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
5315 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl);
5316 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexDeclaration failed with %08x\n", hr);
5317 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, 6 * sizeof(float));
5318 ok(hr == D3D_OK, "DrawPrimitiveUP failed (%08x)\n", hr);
5320 hr = IDirect3DDevice9_EndScene(device);
5321 ok(hr == D3D_OK, "IDirect3DDevice9_EndScene failed with %08x\n", hr);
5324 color = getPixelColor(device, 160, 360);
5325 ok(color == 0x00ffffff, "quad 1 has color %08x, expected 0x00ffffff\n", color);
5326 color = getPixelColor(device, 160, 120);
5327 ok(color == 0x00ffff00 /* NV*/ || color == 0x00ffffff /* ATI */,
5328 "quad 2 has color %08x, expected 0x00ffff00\n", color);
5329 color = getPixelColor(device, 480, 120);
5330 ok(color == 0x000000ff, "quad 3 has color %08x, expected 0x000000ff\n", color);
5331 color = getPixelColor(device, 480, 360);
5332 ok(color == 0x00ffffff || color == 0x0000ff00, "quad 4 has color %08x, expected 0x00ffffff\n", color);
5334 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
5335 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
5337 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff303030, 0.0, 0);
5338 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
5339 hr = IDirect3DDevice9_BeginScene(device);
5340 ok(hr == D3D_OK, "IDirect3DDevice9_BeginScene failed with %08x\n", hr);
5341 if(SUCCEEDED(hr))
5343 static const float quad1[] =
5345 -1.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f,
5346 -1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f,
5347 0.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f,
5348 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f,
5350 static const float quad2[] =
5352 -1.0f, 0.0f, 0.1f,
5353 -1.0f, 1.0f, 0.1f,
5354 0.0f, 0.0f, 0.1f,
5355 0.0f, 1.0f, 0.1f,
5357 static const float quad3[] =
5359 0.0f, 0.0f, 0.1f, 1.0f,
5360 0.0f, 1.0f, 0.1f, 1.0f,
5361 1.0f, 0.0f, 0.1f, 1.0f,
5362 1.0f, 1.0f, 0.1f, 1.0f,
5364 static const D3DMATRIX mat =
5366 0.0f, 0.0f, 0.0f, 0.0f,
5367 0.0f, 0.0f, 0.0f, 0.0f,
5368 0.0f, 0.0f, 0.0f, 0.0f,
5369 0.0f, 1.0f, 0.0f, 0.0f,
5370 }}};
5371 static const D3DMATRIX mat2 =
5373 0.0f, 0.0f, 0.0f, 1.0f,
5374 1.0f, 0.0f, 0.0f, 0.0f,
5375 0.0f, 1.0f, 0.0f, 0.0f,
5376 0.0f, 0.0f, 1.0f, 0.0f,
5377 }}};
5378 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl);
5379 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexDeclaration failed with %08x\n", hr);
5381 /* Default values? 4 coords used, 3 passed. What happens to the 4th?
5382 * Use COUNT3 because newer Nvidia drivers return black when there are more (output) coords
5383 * than being used by the texture(volume tex -> 3). Again, as shown in earlier test the COUNTx
5384 * affects the post-transformation output, so COUNT3 plus the matrix above is OK for testing the
5385 * 4th *input* coordinate.
5387 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &mat);
5388 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
5389 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3);
5390 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
5391 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, 6 * sizeof(float));
5392 ok(hr == D3D_OK, "DrawPrimitiveUP failed (%08x)\n", hr);
5394 /* None passed */
5395 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &identity);
5396 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
5397 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
5398 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
5399 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 3 * sizeof(float));
5400 ok(hr == D3D_OK, "DrawPrimitiveUP failed (%08x)\n", hr);
5402 /* 4 used, 1 passed */
5403 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl2);
5404 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexDeclaration failed with %08x\n", hr);
5405 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &mat2);
5406 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
5407 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, 4 * sizeof(float));
5408 ok(hr == D3D_OK, "DrawPrimitiveUP failed (%08x)\n", hr);
5410 hr = IDirect3DDevice9_EndScene(device);
5411 ok(hr == D3D_OK, "IDirect3DDevice9_EndScene failed with %08x\n", hr);
5413 color = getPixelColor(device, 160, 360);
5414 ok(color == 0x0000ff00, "quad 1 has color %08x, expected 0x0000ff00\n", color);
5415 color = getPixelColor(device, 160, 120);
5416 ok(color == 0x00000000, "quad 2 has color %08x, expected 0x00000000\n", color);
5417 color = getPixelColor(device, 480, 120);
5418 ok(color == 0x00ff0000, "quad 3 has color %08x, expected 0x00ff0000\n", color);
5419 /* Quad4: unused */
5421 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
5422 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
5424 IDirect3DVolumeTexture9_Release(volume);
5426 out:
5427 IDirect3DVertexDeclaration9_Release(decl);
5428 IDirect3DVertexDeclaration9_Release(decl2);
5429 IDirect3DVertexDeclaration9_Release(decl3);
5430 IDirect3DVertexDeclaration9_Release(decl4);
5431 refcount = IDirect3DDevice9_Release(device);
5432 ok(!refcount, "Device has %u references left.\n", refcount);
5433 done:
5434 IDirect3D9_Release(d3d);
5435 DestroyWindow(window);
5438 static void texdepth_test(void)
5440 IDirect3DPixelShader9 *shader;
5441 IDirect3DDevice9 *device;
5442 IDirect3D9 *d3d;
5443 ULONG refcount;
5444 D3DCAPS9 caps;
5445 DWORD color;
5446 HWND window;
5447 HRESULT hr;
5449 static const float texdepth_test_data1[] = { 0.25f, 2.0f, 0.0f, 0.0f};
5450 static const float texdepth_test_data2[] = { 0.25f, 0.5f, 0.0f, 0.0f};
5451 static const float texdepth_test_data3[] = {-1.00f, 0.1f, 0.0f, 0.0f};
5452 static const float texdepth_test_data4[] = {-0.25f, -0.5f, 0.0f, 0.0f};
5453 static const float texdepth_test_data5[] = { 1.00f, -0.1f, 0.0f, 0.0f};
5454 static const float texdepth_test_data6[] = { 1.00f, 0.5f, 0.0f, 0.0f};
5455 static const float texdepth_test_data7[] = { 0.50f, 0.0f, 0.0f, 0.0f};
5456 static const DWORD shader_code[] =
5458 0xffff0104, /* ps_1_4 */
5459 0x00000051, 0xa00f0001, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, /* def c1, 0, 0, 1, 1 */
5460 0x00000001, 0x800f0005, 0xa0e40000, /* mov r5, c0 */
5461 0x0000fffd, /* phase */
5462 0x00000057, 0x800f0005, /* texdepth r5 */
5463 0x00000001, 0x800f0000, 0xa0e40001, /* mov r0, c1 */
5464 0x0000ffff /* end */
5466 static const float vertex[] =
5468 -1.0f, -1.0f, 0.0f,
5469 -1.0f, 1.0f, 0.0f,
5470 1.0f, -1.0f, 1.0f,
5471 1.0f, 1.0f, 1.0f,
5474 window = create_window();
5475 d3d = Direct3DCreate9(D3D_SDK_VERSION);
5476 ok(!!d3d, "Failed to create a D3D object.\n");
5477 if (!(device = create_device(d3d, window, window, TRUE)))
5479 skip("Failed to create a D3D device, skipping tests.\n");
5480 goto done;
5483 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
5484 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
5485 if (caps.PixelShaderVersion < D3DPS_VERSION(1, 4))
5487 skip("No ps_1_4 support, skipping tests.\n");
5488 IDirect3DDevice9_Release(device);
5489 goto done;
5492 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code, &shader);
5493 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
5495 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffff00, 0.0, 0);
5496 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
5497 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
5498 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
5499 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
5500 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
5501 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
5502 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
5503 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_ALWAYS);
5504 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
5505 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
5506 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetFVF returned %#x.\n", hr);
5508 /* Fill the depth buffer with a gradient */
5509 hr = IDirect3DDevice9_BeginScene(device);
5510 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5511 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, vertex, 3 * sizeof(float));
5512 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5513 hr = IDirect3DDevice9_EndScene(device);
5514 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5516 /* Now perform the actual tests. Same geometry, but with the shader */
5517 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_GREATER);
5518 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
5519 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
5520 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
5521 hr = IDirect3DDevice9_SetPixelShader(device, shader);
5522 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader failed (%08x)\n", hr);
5524 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 0, texdepth_test_data1, 1);
5525 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
5526 hr = IDirect3DDevice9_BeginScene(device);
5527 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5528 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, vertex, 3 * sizeof(float));
5529 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5530 hr = IDirect3DDevice9_EndScene(device);
5531 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5533 color = getPixelColor(device, 158, 240);
5534 ok(color == 0x000000ff, "Pixel 158(25%% - 2 pixel) has color %08x, expected 0x000000ff\n", color);
5535 color = getPixelColor(device, 162, 240);
5536 ok(color == 0x00ffffff, "Pixel 158(25%% + 2 pixel) has color %08x, expected 0x00ffffff\n", color);
5538 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
5539 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
5541 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 0.0, 0);
5542 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear returned %#x.\n", hr);
5544 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 0, texdepth_test_data2, 1);
5545 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
5546 hr = IDirect3DDevice9_BeginScene(device);
5547 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5548 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, vertex, 3 * sizeof(float));
5549 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5550 hr = IDirect3DDevice9_EndScene(device);
5551 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5553 color = getPixelColor(device, 318, 240);
5554 ok(color == 0x000000ff, "Pixel 318(50%% - 2 pixel) has color %08x, expected 0x000000ff\n", color);
5555 color = getPixelColor(device, 322, 240);
5556 ok(color == 0x00ffff00, "Pixel 322(50%% + 2 pixel) has color %08x, expected 0x00ffff00\n", color);
5558 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
5559 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
5561 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
5562 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear returned %#x.\n", hr);
5564 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 0, texdepth_test_data3, 1);
5565 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
5566 hr = IDirect3DDevice9_BeginScene(device);
5567 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5568 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, vertex, 3 * sizeof(float));
5569 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5570 hr = IDirect3DDevice9_EndScene(device);
5571 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5573 color = getPixelColor(device, 1, 240);
5574 ok(color == 0x00ff0000, "Pixel 1(0%% + 2 pixel) has color %08x, expected 0x00ff0000\n", color);
5576 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
5577 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
5579 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
5580 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear returned %#x.\n", hr);
5582 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 0, texdepth_test_data4, 1);
5583 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
5584 hr = IDirect3DDevice9_BeginScene(device);
5585 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5586 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, vertex, 3 * sizeof(float));
5587 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5588 hr = IDirect3DDevice9_EndScene(device);
5589 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5591 color = getPixelColor(device, 318, 240);
5592 ok(color == 0x000000ff, "Pixel 318(50%% - 2 pixel) has color %08x, expected 0x000000ff\n", color);
5593 color = getPixelColor(device, 322, 240);
5594 ok(color == 0x0000ff00, "Pixel 322(50%% + 2 pixel) has color %08x, expected 0x0000ff00\n", color);
5596 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
5597 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
5599 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 0.0, 0);
5600 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear returned %#x.\n", hr);
5602 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 0, texdepth_test_data5, 1);
5603 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
5604 hr = IDirect3DDevice9_BeginScene(device);
5605 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5606 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, vertex, 3 * sizeof(float));
5607 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5608 hr = IDirect3DDevice9_EndScene(device);
5609 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5611 color = getPixelColor(device, 1, 240);
5612 ok(color == 0x00ffff00, "Pixel 1(0%% + 2 pixel) has color %08x, expected 0x00ffff00\n", color);
5614 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
5615 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
5617 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
5618 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear returned %#x.\n", hr);
5620 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 0, texdepth_test_data6, 1);
5621 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
5622 hr = IDirect3DDevice9_BeginScene(device);
5623 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5624 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, vertex, 3 * sizeof(float));
5625 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5626 hr = IDirect3DDevice9_EndScene(device);
5627 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5629 color = getPixelColor(device, 638, 240);
5630 ok(color == 0x000000ff, "Pixel 638(100%% + 2 pixel) has color %08x, expected 0x000000ff\n", color);
5632 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
5633 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
5635 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
5636 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear returned %#x.\n", hr);
5638 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 0, texdepth_test_data7, 1);
5639 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
5640 hr = IDirect3DDevice9_BeginScene(device);
5641 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5642 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, vertex, 3 * sizeof(float));
5643 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5644 hr = IDirect3DDevice9_EndScene(device);
5645 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5647 color = getPixelColor(device, 638, 240);
5648 ok(color == 0x000000ff, "Pixel 638(100%% + 2 pixel) has color %08x, expected 0x000000ff\n", color);
5650 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
5651 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
5653 IDirect3DPixelShader9_Release(shader);
5654 refcount = IDirect3DDevice9_Release(device);
5655 ok(!refcount, "Device has %u references left.\n", refcount);
5656 done:
5657 IDirect3D9_Release(d3d);
5658 DestroyWindow(window);
5661 static void texkill_test(void)
5663 IDirect3DPixelShader9 *shader;
5664 IDirect3DDevice9 *device;
5665 IDirect3D9 *d3d;
5666 ULONG refcount;
5667 D3DCAPS9 caps;
5668 DWORD color;
5669 HWND window;
5670 HRESULT hr;
5672 static const float vertex[] =
5674 /* bottom top right left */
5675 -1.0f, -1.0f, 1.0f, -0.1f, 0.9f, 0.9f, -0.1f,
5676 -1.0f, 1.0f, 1.0f, -0.1f, 0.9f, -0.1f, 0.9f,
5677 1.0f, -1.0f, 0.0f, 0.9f, -0.1f, 0.9f, -0.1f,
5678 1.0f, 1.0f, 0.0f, 0.9f, -0.1f, -0.1f, 0.9f,
5680 static const DWORD shader_code_11[] =
5682 0xffff0101, /* ps_1_1 */
5683 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 1.0, 0.0, 0.0, 1.0 */
5684 0x00000041, 0xb00f0000, /* texkill t0 */
5685 0x00000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
5686 0x0000ffff /* end */
5688 static const DWORD shader_code_20[] =
5690 0xffff0200, /* ps_2_0 */
5691 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
5692 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, /* def c0, 0.0, 0.0, 1.0, 1.0 */
5693 0x01000041, 0xb00f0000, /* texkill t0 */
5694 0x02000001, 0x800f0800, 0xa0e40000, /* mov oC0, c0 */
5695 0x0000ffff /* end */
5698 window = create_window();
5699 d3d = Direct3DCreate9(D3D_SDK_VERSION);
5700 ok(!!d3d, "Failed to create a D3D object.\n");
5701 if (!(device = create_device(d3d, window, window, TRUE)))
5703 skip("Failed to create a D3D device, skipping tests.\n");
5704 goto done;
5707 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
5708 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
5709 if (caps.PixelShaderVersion < D3DPS_VERSION(1, 1))
5711 skip("No ps_1_1 support, skipping tests.\n");
5712 IDirect3DDevice9_Release(device);
5713 goto done;
5716 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 1.0f, 0);
5717 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
5718 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_11, &shader);
5719 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
5721 hr = IDirect3DDevice9_SetPixelShader(device, shader);
5722 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader returned %08x\n", hr);
5723 hr = IDirect3DDevice9_BeginScene(device);
5724 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5725 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEXCOORDSIZE4(0) | D3DFVF_TEX1);
5726 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
5727 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, vertex, 7 * sizeof(float));
5728 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5729 hr = IDirect3DDevice9_EndScene(device);
5730 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5732 color = getPixelColor(device, 63, 46);
5733 ok(color == 0x0000ff00, "Pixel 63/46 has color %08x, expected 0x0000ff00\n", color);
5734 color = getPixelColor(device, 66, 46);
5735 ok(color == 0x0000ff00, "Pixel 66/64 has color %08x, expected 0x0000ff00\n", color);
5736 color = getPixelColor(device, 63, 49);
5737 ok(color == 0x0000ff00, "Pixel 63/49 has color %08x, expected 0x0000ff00\n", color);
5738 color = getPixelColor(device, 66, 49);
5739 ok(color == 0x00ff0000, "Pixel 66/49 has color %08x, expected 0x00ff0000\n", color);
5741 color = getPixelColor(device, 578, 46);
5742 ok(color == 0x0000ff00, "Pixel 578/46 has color %08x, expected 0x0000ff00\n", color);
5743 color = getPixelColor(device, 575, 46);
5744 ok(color == 0x0000ff00, "Pixel 575/64 has color %08x, expected 0x0000ff00\n", color);
5745 color = getPixelColor(device, 578, 49);
5746 ok(color == 0x0000ff00, "Pixel 578/49 has color %08x, expected 0x0000ff00\n", color);
5747 color = getPixelColor(device, 575, 49);
5748 ok(color == 0x00ff0000, "Pixel 575/49 has color %08x, expected 0x00ff0000\n", color);
5750 color = getPixelColor(device, 63, 430);
5751 ok(color == 0x0000ff00, "Pixel 578/46 has color %08x, expected 0x0000ff00\n", color);
5752 color = getPixelColor(device, 63, 433);
5753 ok(color == 0x0000ff00, "Pixel 575/64 has color %08x, expected 0x0000ff00\n", color);
5754 color = getPixelColor(device, 66, 433);
5755 ok(color == 0x00ff0000, "Pixel 578/49 has color %08x, expected 0x00ff0000\n", color);
5756 color = getPixelColor(device, 66, 430);
5757 ok(color == 0x00ff0000, "Pixel 575/49 has color %08x, expected 0x00ff0000\n", color);
5759 color = getPixelColor(device, 578, 430);
5760 ok(color == 0x0000ff00, "Pixel 578/46 has color %08x, expected 0x0000ff00\n", color);
5761 color = getPixelColor(device, 578, 433);
5762 ok(color == 0x0000ff00, "Pixel 575/64 has color %08x, expected 0x0000ff00\n", color);
5763 color = getPixelColor(device, 575, 433);
5764 ok(color == 0x00ff0000, "Pixel 578/49 has color %08x, expected 0x00ff0000\n", color);
5765 color = getPixelColor(device, 575, 430);
5766 ok(color == 0x00ff0000, "Pixel 575/49 has color %08x, expected 0x00ff0000\n", color);
5768 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
5769 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
5771 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
5772 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader returned %08x\n", hr);
5773 IDirect3DPixelShader9_Release(shader);
5775 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 0.0, 0);
5776 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
5777 if (FAILED(IDirect3DDevice9_CreatePixelShader(device, shader_code_20, &shader)))
5779 skip("Failed to create 2.0 test shader, most likely not supported.\n");
5780 IDirect3DDevice9_Release(device);
5781 goto done;
5784 hr = IDirect3DDevice9_SetPixelShader(device, shader);
5785 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader returned %08x\n", hr);
5786 hr = IDirect3DDevice9_BeginScene(device);
5787 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5788 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, vertex, 7 * sizeof(float));
5789 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5790 hr = IDirect3DDevice9_EndScene(device);
5791 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5793 color = getPixelColor(device, 63, 46);
5794 ok(color == 0x00ffff00, "Pixel 63/46 has color %08x, expected 0x00ffff00\n", color);
5795 color = getPixelColor(device, 66, 46);
5796 ok(color == 0x00ffff00, "Pixel 66/64 has color %08x, expected 0x00ffff00\n", color);
5797 color = getPixelColor(device, 63, 49);
5798 ok(color == 0x00ffff00, "Pixel 63/49 has color %08x, expected 0x00ffff00\n", color);
5799 color = getPixelColor(device, 66, 49);
5800 ok(color == 0x000000ff, "Pixel 66/49 has color %08x, expected 0x000000ff\n", color);
5802 color = getPixelColor(device, 578, 46);
5803 ok(color == 0x00ffff00, "Pixel 578/46 has color %08x, expected 0x00ffff00\n", color);
5804 color = getPixelColor(device, 575, 46);
5805 ok(color == 0x00ffff00, "Pixel 575/64 has color %08x, expected 0x00ffff00\n", color);
5806 color = getPixelColor(device, 578, 49);
5807 ok(color == 0x00ffff00, "Pixel 578/49 has color %08x, expected 0x00ffff00\n", color);
5808 color = getPixelColor(device, 575, 49);
5809 ok(color == 0x000000ff, "Pixel 575/49 has color %08x, expected 0x000000ff\n", color);
5811 color = getPixelColor(device, 63, 430);
5812 ok(color == 0x00ffff00, "Pixel 578/46 has color %08x, expected 0x00ffff00\n", color);
5813 color = getPixelColor(device, 63, 433);
5814 ok(color == 0x00ffff00, "Pixel 575/64 has color %08x, expected 0x00ffff00\n", color);
5815 color = getPixelColor(device, 66, 433);
5816 ok(color == 0x00ffff00, "Pixel 578/49 has color %08x, expected 0x00ffff00\n", color);
5817 color = getPixelColor(device, 66, 430);
5818 ok(color == 0x000000ff, "Pixel 575/49 has color %08x, expected 0x000000ff\n", color);
5820 color = getPixelColor(device, 578, 430);
5821 ok(color == 0x00ffff00, "Pixel 578/46 has color %08x, expected 0x00ffff00\n", color);
5822 color = getPixelColor(device, 578, 433);
5823 ok(color == 0x00ffff00, "Pixel 575/64 has color %08x, expected 0x00ffff00\n", color);
5824 color = getPixelColor(device, 575, 433);
5825 ok(color == 0x00ffff00, "Pixel 578/49 has color %08x, expected 0x00ffff00\n", color);
5826 color = getPixelColor(device, 575, 430);
5827 ok(color == 0x000000ff, "Pixel 575/49 has color %08x, expected 0x000000ff\n", color);
5829 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
5830 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
5832 IDirect3DPixelShader9_Release(shader);
5833 refcount = IDirect3DDevice9_Release(device);
5834 ok(!refcount, "Device has %u references left.\n", refcount);
5835 done:
5836 IDirect3D9_Release(d3d);
5837 DestroyWindow(window);
5840 static void autogen_mipmap_test(void)
5842 IDirect3DTexture9 *texture = NULL;
5843 IDirect3DSurface9 *surface;
5844 IDirect3DDevice9 *device;
5845 unsigned int x, y;
5846 D3DLOCKED_RECT lr;
5847 IDirect3D9 *d3d;
5848 D3DCOLOR color;
5849 ULONG refcount;
5850 HWND window;
5851 HRESULT hr;
5853 static const RECT r1 = {256, 256, 512, 512};
5854 static const RECT r2 = {512, 256, 768, 512};
5855 static const RECT r3 = {256, 512, 512, 768};
5856 static const RECT r4 = {512, 512, 768, 768};
5857 static const float quad[] =
5859 -0.5f, -0.5f, 0.1f, 0.0f, 0.0f,
5860 -0.5f, 0.5f, 0.1f, 0.0f, 1.0f,
5861 0.5f, -0.5f, 0.1f, 1.0f, 0.0f,
5862 0.5f, 0.5f, 0.1f, 1.0f, 1.0f,
5865 window = create_window();
5866 d3d = Direct3DCreate9(D3D_SDK_VERSION);
5867 ok(!!d3d, "Failed to create a D3D object.\n");
5868 if (!(device = create_device(d3d, window, window, TRUE)))
5870 skip("Failed to create a D3D device, skipping tests.\n");
5871 goto done;
5874 if (IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL,
5875 D3DFMT_X8R8G8B8, D3DUSAGE_AUTOGENMIPMAP, D3DRTYPE_TEXTURE, D3DFMT_X8R8G8B8) != D3D_OK)
5877 skip("No autogenmipmap support.\n");
5878 IDirect3DDevice9_Release(device);
5879 goto done;
5882 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffff00, 1.0f, 0);
5883 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
5885 /* Make the mipmap big, so that a smaller mipmap is used
5887 hr = IDirect3DDevice9_CreateTexture(device, 1024, 1024, 0, D3DUSAGE_AUTOGENMIPMAP,
5888 D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &texture, 0);
5889 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture returned %08x\n", hr);
5891 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
5892 ok(hr == D3D_OK, "IDirect3DTexture9_GetSurfaceLevel returned %08x\n", hr);
5893 memset(&lr, 0, sizeof(lr));
5894 hr = IDirect3DSurface9_LockRect(surface, &lr, NULL, 0);
5895 ok(hr == D3D_OK, "IDirect3DSurface9_LockRect returned %08x\n", hr);
5896 for(y = 0; y < 1024; y++) {
5897 for(x = 0; x < 1024; x++) {
5898 DWORD *dst = (DWORD *) (((BYTE *) lr.pBits) + y * lr.Pitch + x * 4);
5899 POINT pt;
5901 pt.x = x;
5902 pt.y = y;
5903 if(PtInRect(&r1, pt)) {
5904 *dst = 0xffff0000;
5905 } else if(PtInRect(&r2, pt)) {
5906 *dst = 0xff00ff00;
5907 } else if(PtInRect(&r3, pt)) {
5908 *dst = 0xff0000ff;
5909 } else if(PtInRect(&r4, pt)) {
5910 *dst = 0xff000000;
5911 } else {
5912 *dst = 0xffffffff;
5916 hr = IDirect3DSurface9_UnlockRect(surface);
5917 ok(hr == D3D_OK, "IDirect3DSurface9_UnlockRect returned %08x\n", hr);
5918 IDirect3DSurface9_Release(surface);
5920 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) texture);
5921 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture returned %08x\n", hr);
5922 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
5923 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState failed with %08x\n", hr);
5924 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
5925 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
5927 hr = IDirect3DDevice9_BeginScene(device);
5928 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5929 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
5930 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
5931 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
5932 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5933 hr = IDirect3DDevice9_EndScene(device);
5934 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5935 IDirect3DTexture9_Release(texture);
5937 color = getPixelColor(device, 200, 200);
5938 ok(color == 0x00ffffff, "pixel 200/200 has color %08x, expected 0x00ffffff\n", color);
5939 color = getPixelColor(device, 280, 200);
5940 ok(color == 0x000000ff, "pixel 280/200 has color %08x, expected 0x000000ff\n", color);
5941 color = getPixelColor(device, 360, 200);
5942 ok(color == 0x00000000, "pixel 360/200 has color %08x, expected 0x00000000\n", color);
5943 color = getPixelColor(device, 440, 200);
5944 ok(color == 0x00ffffff, "pixel 440/200 has color %08x, expected 0x00ffffff\n", color);
5945 color = getPixelColor(device, 200, 270);
5946 ok(color == 0x00ffffff, "pixel 200/270 has color %08x, expected 0x00ffffff\n", color);
5947 color = getPixelColor(device, 280, 270);
5948 ok(color == 0x00ff0000, "pixel 280/270 has color %08x, expected 0x00ff0000\n", color);
5949 color = getPixelColor(device, 360, 270);
5950 ok(color == 0x0000ff00, "pixel 360/270 has color %08x, expected 0x0000ff00\n", color);
5951 color = getPixelColor(device, 440, 270);
5952 ok(color == 0x00ffffff, "pixel 440/200 has color %08x, expected 0x00ffffff\n", color);
5953 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
5954 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
5956 refcount = IDirect3DDevice9_Release(device);
5957 ok(!refcount, "Device has %u references left.\n", refcount);
5958 done:
5959 IDirect3D9_Release(d3d);
5960 DestroyWindow(window);
5963 static void test_constant_clamp_vs(void)
5965 IDirect3DVertexShader9 *shader_11, *shader_11_2, *shader_20, *shader_20_2;
5966 IDirect3DVertexDeclaration9 *decl;
5967 IDirect3DDevice9 *device;
5968 IDirect3D9 *d3d;
5969 D3DCOLOR color;
5970 ULONG refcount;
5971 D3DCAPS9 caps;
5972 HWND window;
5973 HRESULT hr;
5975 static const DWORD shader_code_11[] =
5977 0xfffe0101, /* vs_1_1 */
5978 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
5979 0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
5980 0x00000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
5981 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
5982 0x0000ffff /* end */
5984 static const DWORD shader_code_11_2[] =
5986 0xfffe0101, /* vs_1_1 */
5987 0x00000051, 0xa00f0001, 0x3fa00000, 0xbf000000, 0xbfc00000, 0x3f800000, /* dcl ... */
5988 0x00000051, 0xa00f0002, 0xbf000000, 0x3fa00000, 0x40000000, 0x3f800000, /* dcl ... */
5989 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
5990 0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
5991 0x00000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
5992 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
5993 0x0000ffff /* end */
5995 static const DWORD shader_code_20[] =
5997 0xfffe0200, /* vs_2_0 */
5998 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
5999 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
6000 0x03000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
6001 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
6002 0x0000ffff /* end */
6004 static const DWORD shader_code_20_2[] =
6006 0xfffe0200, /* vs_2_0 */
6007 0x05000051, 0xa00f0001, 0x3fa00000, 0xbf000000, 0xbfc00000, 0x3f800000,
6008 0x05000051, 0xa00f0002, 0xbf000000, 0x3fa00000, 0x40000000, 0x3f800000,
6009 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
6010 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
6011 0x03000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
6012 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
6013 0x0000ffff /* end */
6015 static const D3DVERTEXELEMENT9 decl_elements[] =
6017 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
6018 D3DDECL_END()
6020 static const float quad1[] =
6022 -1.0f, -1.0f, 0.1f,
6023 -1.0f, 0.0f, 0.1f,
6024 0.0f, -1.0f, 0.1f,
6025 0.0f, 0.0f, 0.1f,
6027 static const float quad2[] =
6029 0.0f, -1.0f, 0.1f,
6030 0.0f, 0.0f, 0.1f,
6031 1.0f, -1.0f, 0.1f,
6032 1.0f, 0.0f, 0.1f,
6034 static const float quad3[] =
6036 0.0f, 0.0f, 0.1f,
6037 0.0f, 1.0f, 0.1f,
6038 1.0f, 0.0f, 0.1f,
6039 1.0f, 1.0f, 0.1f,
6041 static const float quad4[] =
6043 -1.0f, 0.0f, 0.1f,
6044 -1.0f, 1.0f, 0.1f,
6045 0.0f, 0.0f, 0.1f,
6046 0.0f, 1.0f, 0.1f,
6048 static const float test_data_c1[4] = { 1.25f, -0.50f, -1.50f, 1.0f};
6049 static const float test_data_c2[4] = {-0.50f, 1.25f, 2.00f, 1.0f};
6051 window = create_window();
6052 d3d = Direct3DCreate9(D3D_SDK_VERSION);
6053 ok(!!d3d, "Failed to create a D3D object.\n");
6054 if (!(device = create_device(d3d, window, window, TRUE)))
6056 skip("Failed to create a D3D device, skipping tests.\n");
6057 goto done;
6060 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
6061 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
6062 if (caps.VertexShaderVersion < D3DVS_VERSION(1, 1))
6064 skip("No vs_1_1 support, skipping tests.\n");
6065 IDirect3DDevice9_Release(device);
6066 goto done;
6069 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ffff, 1.0f, 0);
6070 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
6072 hr = IDirect3DDevice9_CreateVertexShader(device, shader_code_11, &shader_11);
6073 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
6074 hr = IDirect3DDevice9_CreateVertexShader(device, shader_code_11_2, &shader_11_2);
6075 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
6076 hr = IDirect3DDevice9_CreateVertexShader(device, shader_code_20, &shader_20);
6077 if(FAILED(hr)) shader_20 = NULL;
6078 hr = IDirect3DDevice9_CreateVertexShader(device, shader_code_20_2, &shader_20_2);
6079 if(FAILED(hr)) shader_20_2 = NULL;
6080 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &decl);
6081 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
6083 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 1, test_data_c1, 1);
6084 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShaderConstantF returned %08x\n", hr);
6085 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 2, test_data_c2, 1);
6086 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShaderConstantF returned %08x\n", hr);
6087 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl);
6088 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexDeclaration returned %08x\n", hr);
6090 hr = IDirect3DDevice9_BeginScene(device);
6091 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6093 hr = IDirect3DDevice9_SetVertexShader(device, shader_11);
6094 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
6095 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, 3 * sizeof(float));
6096 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6098 hr = IDirect3DDevice9_SetVertexShader(device, shader_11_2);
6099 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
6100 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 3 * sizeof(float));
6101 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6103 if (shader_20)
6105 hr = IDirect3DDevice9_SetVertexShader(device, shader_20);
6106 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
6107 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, 3 * sizeof(float));
6108 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6111 if (shader_20_2)
6113 hr = IDirect3DDevice9_SetVertexShader(device, shader_20_2);
6114 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
6115 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, 3 * sizeof(float));
6116 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6119 hr = IDirect3DDevice9_EndScene(device);
6120 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6122 color = getPixelColor(device, 160, 360);
6123 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xbf, 0xbf, 0x80), 1),
6124 "quad 1 has color %08x, expected 0x00bfbf80\n", color);
6125 color = getPixelColor(device, 480, 360);
6126 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xbf, 0xbf, 0x80), 1),
6127 "quad 2 has color %08x, expected 0x00bfbf80\n", color);
6128 if(shader_20) {
6129 color = getPixelColor(device, 480, 120);
6130 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xbf, 0xbf, 0x80), 1),
6131 "quad 3 has color %08x, expected 0x00bfbf80\n", color);
6133 if(shader_20_2) {
6134 color = getPixelColor(device, 160, 120);
6135 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xbf, 0xbf, 0x80), 1),
6136 "quad 4 has color %08x, expected 0x00bfbf80\n", color);
6138 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
6139 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
6141 IDirect3DVertexDeclaration9_Release(decl);
6142 if(shader_20_2) IDirect3DVertexShader9_Release(shader_20_2);
6143 if(shader_20) IDirect3DVertexShader9_Release(shader_20);
6144 IDirect3DVertexShader9_Release(shader_11_2);
6145 IDirect3DVertexShader9_Release(shader_11);
6146 refcount = IDirect3DDevice9_Release(device);
6147 ok(!refcount, "Device has %u references left.\n", refcount);
6148 done:
6149 IDirect3D9_Release(d3d);
6150 DestroyWindow(window);
6153 static void constant_clamp_ps_test(void)
6155 IDirect3DPixelShader9 *shader_11, *shader_12, *shader_14, *shader_20;
6156 IDirect3DDevice9 *device;
6157 IDirect3D9 *d3d;
6158 ULONG refcount;
6159 D3DCAPS9 caps;
6160 DWORD color;
6161 HWND window;
6162 HRESULT hr;
6164 static const DWORD shader_code_11[] =
6166 0xffff0101, /* ps_1_1 */
6167 0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
6168 0x00000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
6169 0x0000ffff /* end */
6171 static const DWORD shader_code_12[] =
6173 0xffff0102, /* ps_1_2 */
6174 0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
6175 0x00000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
6176 0x0000ffff /* end */
6178 /* Skip 1.3 shaders because we have only 4 quads (ok, could make them
6179 * smaller if needed). 1.2 and 1.4 shaders behave the same, so it's
6180 * unlikely that 1.3 shaders are different. During development of this
6181 * test, 1.3 shaders were verified too. */
6182 static const DWORD shader_code_14[] =
6184 0xffff0104, /* ps_1_4 */
6185 /* Try to make one constant local. It gets clamped too, although the
6186 * binary contains the bigger numbers. */
6187 0x00000051, 0xa00f0002, 0xbf000000, 0x3fa00000, 0x40000000, 0x3f800000, /* def c2, -0.5, 1.25, 2, 1 */
6188 0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
6189 0x00000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
6190 0x0000ffff /* end */
6192 static const DWORD shader_code_20[] =
6194 0xffff0200, /* ps_2_0 */
6195 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
6196 0x03000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
6197 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
6198 0x0000ffff /* end */
6200 static const float quad1[] =
6202 -1.0f, -1.0f, 0.1f,
6203 -1.0f, 0.0f, 0.1f,
6204 0.0f, -1.0f, 0.1f,
6205 0.0f, 0.0f, 0.1f,
6207 static const float quad2[] =
6209 0.0f, -1.0f, 0.1f,
6210 0.0f, 0.0f, 0.1f,
6211 1.0f, -1.0f, 0.1f,
6212 1.0f, 0.0f, 0.1f,
6214 static const float quad3[] =
6216 0.0f, 0.0f, 0.1f,
6217 0.0f, 1.0f, 0.1f,
6218 1.0f, 0.0f, 0.1f,
6219 1.0f, 1.0f, 0.1f,
6221 static const float quad4[] =
6223 -1.0f, 0.0f, 0.1f,
6224 -1.0f, 1.0f, 0.1f,
6225 0.0f, 0.0f, 0.1f,
6226 0.0f, 1.0f, 0.1f,
6228 static const float test_data_c1[4] = { 1.25f, -0.50f, -1.50f, 1.0f};
6229 static const float test_data_c2[4] = {-0.50f, 1.25f, 2.00f, 1.0f};
6231 window = create_window();
6232 d3d = Direct3DCreate9(D3D_SDK_VERSION);
6233 ok(!!d3d, "Failed to create a D3D object.\n");
6234 if (!(device = create_device(d3d, window, window, TRUE)))
6236 skip("Failed to create a D3D device, skipping tests.\n");
6237 goto done;
6240 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
6241 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
6242 if (caps.PixelShaderVersion < D3DPS_VERSION(1, 4))
6244 skip("No ps_1_4 support, skipping tests.\n");
6245 IDirect3DDevice9_Release(device);
6246 goto done;
6249 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ffff, 1.0f, 0);
6250 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
6252 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_11, &shader_11);
6253 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6254 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_12, &shader_12);
6255 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6256 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_14, &shader_14);
6257 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6258 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_20, &shader_20);
6259 if(FAILED(hr)) shader_20 = NULL;
6261 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 1, test_data_c1, 1);
6262 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
6263 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 2, test_data_c2, 1);
6264 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
6265 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
6266 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF returned %08x\n", hr);
6268 hr = IDirect3DDevice9_BeginScene(device);
6269 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6271 hr = IDirect3DDevice9_SetPixelShader(device, shader_11);
6272 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6273 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, 3 * sizeof(float));
6274 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6276 hr = IDirect3DDevice9_SetPixelShader(device, shader_12);
6277 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6278 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 3 * sizeof(float));
6279 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6281 hr = IDirect3DDevice9_SetPixelShader(device, shader_14);
6282 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6283 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, 3 * sizeof(float));
6284 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6286 if (shader_20)
6288 hr = IDirect3DDevice9_SetPixelShader(device, shader_20);
6289 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6290 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, 3 * sizeof(float));
6291 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6294 hr = IDirect3DDevice9_EndScene(device);
6295 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6297 color = getPixelColor(device, 160, 360);
6298 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x80, 0x80, 0x00), 1),
6299 "quad 1 has color %08x, expected 0x00808000\n", color);
6300 color = getPixelColor(device, 480, 360);
6301 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x80, 0x80, 0x00), 1),
6302 "quad 2 has color %08x, expected 0x00808000\n", color);
6303 color = getPixelColor(device, 480, 120);
6304 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x80, 0x80, 0x00), 1),
6305 "quad 3 has color %08x, expected 0x00808000\n", color);
6306 if(shader_20) {
6307 color = getPixelColor(device, 160, 120);
6308 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xbf, 0xbf, 0x80), 1),
6309 "quad 4 has color %08x, expected 0x00bfbf80\n", color);
6311 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
6312 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
6314 if(shader_20) IDirect3DPixelShader9_Release(shader_20);
6315 IDirect3DPixelShader9_Release(shader_14);
6316 IDirect3DPixelShader9_Release(shader_12);
6317 IDirect3DPixelShader9_Release(shader_11);
6318 refcount = IDirect3DDevice9_Release(device);
6319 ok(!refcount, "Device has %u references left.\n", refcount);
6320 done:
6321 IDirect3D9_Release(d3d);
6322 DestroyWindow(window);
6325 static void dp2add_ps_test(void)
6327 IDirect3DPixelShader9 *shader_dp2add_sat;
6328 IDirect3DPixelShader9 *shader_dp2add;
6329 IDirect3DDevice9 *device;
6330 IDirect3D9 *d3d;
6331 ULONG refcount;
6332 D3DCAPS9 caps;
6333 DWORD color;
6334 HWND window;
6335 HRESULT hr;
6337 /* DP2ADD is defined as: (src0.r * src1.r) + (src0.g * src1.g) + src2.
6338 * One D3D restriction of all shader instructions except SINCOS is that no more than 2
6339 * source tokens can be constants. So, for this exercise, we move contents of c0 to
6340 * r0 first.
6341 * The result here for the r,g,b components should be roughly 0.5:
6342 * (0.5 * 0.5) + (0.5 * 0.5) + 0.0 = 0.5 */
6343 static const DWORD shader_code_dp2add[] = {
6344 0xffff0200, /* ps_2_0 */
6345 0x05000051, 0xa00f0000, 0x3f000000, 0x3f000000, 0x3f800000, 0x00000000, /* def c0, 0.5, 0.5, 1.0, 0 */
6347 0x02000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
6348 0x0400005a, 0x80070000, 0x80000000, 0x80000000, 0x80ff0000, /* dp2add r0.rgb, r0, r0, r0.a */
6350 0x02000001, 0x80080000, 0xa0aa0000, /* mov r0.a, c0.b */
6351 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
6352 0x0000ffff /* end */
6355 /* Test the _sat modifier, too. Result here should be:
6356 * DP2: (-0.5 * -0.5) + (-0.5 * -0.5) + 2.0 = 2.5
6357 * _SAT: ==> 1.0
6358 * ADD: (1.0 + -0.5) = 0.5
6360 static const DWORD shader_code_dp2add_sat[] = {
6361 0xffff0200, /* ps_2_0 */
6362 0x05000051, 0xa00f0000, 0xbf000000, 0xbf000000, 0x3f800000, 0x40000000, /* def c0, -0.5, -0.5, 1.0, 2.0 */
6364 0x02000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
6365 0x0400005a, 0x80170000, 0x80000000, 0x80000000, 0x80ff0000, /* dp2add_sat r0.rgb, r0, r0, r0.a */
6366 0x03000002, 0x80070000, 0x80e40000, 0xa0000000, /* add r0.rgb, r0, c0.r */
6368 0x02000001, 0x80080000, 0xa0aa0000, /* mov r0.a, c0.b */
6369 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
6370 0x0000ffff /* end */
6372 static const float quad[] =
6374 -1.0f, -1.0f, 0.1f,
6375 -1.0f, 1.0f, 0.1f,
6376 1.0f, -1.0f, 0.1f,
6377 1.0f, 1.0f, 0.1f,
6380 window = create_window();
6381 d3d = Direct3DCreate9(D3D_SDK_VERSION);
6382 ok(!!d3d, "Failed to create a D3D object.\n");
6383 if (!(device = create_device(d3d, window, window, TRUE)))
6385 skip("Failed to create a D3D device, skipping tests.\n");
6386 goto done;
6389 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
6390 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
6391 if (caps.PixelShaderVersion < D3DPS_VERSION(2, 0))
6393 skip("No ps_2_0 support, skipping tests.\n");
6394 IDirect3DDevice9_Release(device);
6395 goto done;
6398 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff000000, 1.0f, 0);
6399 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
6401 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_dp2add, &shader_dp2add);
6402 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6404 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_dp2add_sat, &shader_dp2add_sat);
6405 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6407 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
6408 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF returned %08x\n", hr);
6410 hr = IDirect3DDevice9_SetPixelShader(device, shader_dp2add);
6411 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6412 hr = IDirect3DDevice9_BeginScene(device);
6413 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6414 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 3 * sizeof(float));
6415 ok(SUCCEEDED(hr), "Failed to draw primitive, hr %#x.\n", hr);
6416 hr = IDirect3DDevice9_EndScene(device);
6417 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6419 color = getPixelColor(device, 360, 240);
6420 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x7f, 0x7f, 0x7f), 1), "Got unexpected color 0x%08x.\n", color);
6422 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
6423 ok(SUCCEEDED(hr), "Failed to present frame, hr %#x.\n", hr);
6424 IDirect3DPixelShader9_Release(shader_dp2add);
6426 hr = IDirect3DDevice9_SetPixelShader(device, shader_dp2add_sat);
6427 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6428 hr = IDirect3DDevice9_BeginScene(device);
6429 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6430 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 3 * sizeof(float));
6431 ok(SUCCEEDED(hr), "Failed to draw primitive, hr %#x.\n", hr);
6432 hr = IDirect3DDevice9_EndScene(device);
6433 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6435 color = getPixelColor(device, 360, 240);
6436 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x7f, 0x7f, 0x7f), 1), "Got unexpected color 0x%08x.\n", color);
6438 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
6439 ok(SUCCEEDED(hr), "Failed to present frame, hr %#x.\n", hr);
6440 IDirect3DPixelShader9_Release(shader_dp2add_sat);
6442 refcount = IDirect3DDevice9_Release(device);
6443 ok(!refcount, "Device has %u references left.\n", refcount);
6444 done:
6445 IDirect3D9_Release(d3d);
6446 DestroyWindow(window);
6449 static void cnd_test(void)
6451 IDirect3DPixelShader9 *shader_11_coissue_2, *shader_12_coissue_2, *shader_13_coissue_2, *shader_14_coissue_2;
6452 IDirect3DPixelShader9 *shader_11_coissue, *shader_12_coissue, *shader_13_coissue, *shader_14_coissue;
6453 IDirect3DPixelShader9 *shader_11, *shader_12, *shader_13, *shader_14;
6454 IDirect3DDevice9 *device;
6455 IDirect3D9 *d3d;
6456 ULONG refcount;
6457 D3DCAPS9 caps;
6458 HWND window;
6459 DWORD color;
6460 HRESULT hr;
6462 /* ps 1.x shaders are rather picky with writemasks and source swizzles.
6463 * The dp3 is used to copy r0.r to all components of r1, then copy r1.a to
6464 * r0.a. Essentially it does a mov r0.a, r0.r, which isn't allowed as-is
6465 * in 1.x pixel shaders. */
6466 static const DWORD shader_code_11[] =
6468 0xffff0101, /* ps_1_1 */
6469 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
6470 0x00000040, 0xb00f0000, /* texcoord t0 */
6471 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, ???(t0) */
6472 0x00000008, 0x800f0001, 0x80e40000, 0xa0e40000, /* dp3 r1, r0, c0 */
6473 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
6474 0x00000050, 0x800f0000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* cnd r0, r0.a, c1, c2 */
6475 0x0000ffff /* end */
6477 static const DWORD shader_code_12[] =
6479 0xffff0102, /* ps_1_2 */
6480 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
6481 0x00000040, 0xb00f0000, /* texcoord t0 */
6482 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
6483 0x00000008, 0x800f0001, 0x80e40000, 0xa0e40000, /* dp3 r1, r0, c0 */
6484 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
6485 0x00000050, 0x800f0000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* cnd r0, r0.a, c1, c2 */
6486 0x0000ffff /* end */
6488 static const DWORD shader_code_13[] =
6490 0xffff0103, /* ps_1_3 */
6491 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
6492 0x00000040, 0xb00f0000, /* texcoord t0 */
6493 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
6494 0x00000008, 0x800f0001, 0x80e40000, 0xa0e40000, /* dp3, r1, r0, c0 */
6495 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
6496 0x00000050, 0x800f0000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* cnd r0, r0.a, c1, c2 */
6497 0x0000ffff /* end */
6499 static const DWORD shader_code_14[] =
6501 0xffff0104, /* ps_1_3 */
6502 0x00000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0, 0, 0, 1 */
6503 0x00000040, 0x80070000, 0xb0e40000, /* texcrd r0, t0 */
6504 0x00000001, 0x80080000, 0xa0ff0000, /* mov r0.a, c0.a */
6505 0x00000050, 0x800f0000, 0x80e40000, 0xa0e40001, 0xa0e40002, /* cnd r0, r0, c1, c2 */
6506 0x0000ffff /* end */
6509 /* Special fun: The coissue flag on cnd: Apparently cnd always selects the 2nd source,
6510 * as if the src0 comparison against 0.5 always evaluates to true. The coissue flag isn't
6511 * set by the compiler, it was added manually after compilation. Note that the COISSUE
6512 * flag on a color(.xyz) operation is only allowed after an alpha operation. DirectX doesn't
6513 * have proper docs, but GL_ATI_fragment_shader explains the pairing of color and alpha ops
6514 * well enough.
6516 * The shader attempts to test the range [-1;1] against coissued cnd, which is a bit tricky.
6517 * The input from t0 is [0;1]. 0.5 is subtracted, then we have to multiply with 2. Since
6518 * constants are clamped to [-1;1], a 2.0 is constructed by adding c0.r(=1.0) to c0.r into r1.r,
6519 * then r1(2.0, 0.0, 0.0, 0.0) is passed to dp3(explained above).
6521 static const DWORD shader_code_11_coissue[] =
6523 0xffff0101, /* ps_1_1 */
6524 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
6525 0x00000051, 0xa00f0003, 0x3f000000, 0x3f000000, 0x3f000000, 0x00000000, /* def c3, 0.5, 0.5, 0.5, 0 */
6526 0x00000040, 0xb00f0000, /* texcoord t0 */
6527 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
6528 0x00000003, 0x800f0000, 0x80e40000, 0xa0e40003, /* sub r0, r0, c3 */
6529 0x00000002, 0x800f0001, 0xa0e40000, 0xa0e40000, /* add r1, c0, c0 */
6530 0x00000008, 0x800f0001, 0x80e40000, 0x80e40001, /* dp3 r1, r0, r1 */
6531 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
6532 0x40000050, 0x80070000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* +cnd r0.xyz, r0.a, c1, c2*/
6533 0x0000ffff /* end */
6535 static const DWORD shader_code_11_coissue_2[] =
6537 0xffff0101, /* ps_1_1 */
6538 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
6539 0x00000051, 0xa00f0003, 0x3f000000, 0x3f000000, 0x3f000000, 0x00000000, /* def c3, 0.5, 0.5, 0.5, 0 */
6540 0x00000040, 0xb00f0000, /* texcoord t0 */
6541 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
6542 0x00000003, 0x800f0000, 0x80e40000, 0xa0e40003, /* sub r0, r0, c3 */
6543 0x00000002, 0x800f0001, 0xa0e40000, 0xa0e40000, /* add r1, c0, c0 */
6544 0x00000008, 0x800f0001, 0x80e40000, 0x80e40001, /* dp3 r1, r0, r1 */
6545 0x00000001, 0x800f0000, 0x80e40001, /* mov r0, r1 */
6546 0x00000001, 0x80070000, 0x80ff0001, /* mov r0.xyz, r1.a */
6547 0x40000050, 0x80080000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* +cnd r0.a, r0.a, c1, c2 */
6548 0x00000001, 0x80070000, 0x80ff0000, /* mov r0.xyz, r0.a */
6549 0x0000ffff /* end */
6551 static const DWORD shader_code_12_coissue[] =
6553 0xffff0102, /* ps_1_2 */
6554 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
6555 0x00000051, 0xa00f0003, 0x3f000000, 0x3f000000, 0x3f000000, 0x00000000, /* def c3, 0.5, 0.5, 0.5, 0 */
6556 0x00000040, 0xb00f0000, /* texcoord t0 */
6557 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
6558 0x00000003, 0x800f0000, 0x80e40000, 0xa0e40003, /* sub r0, r0, c3 */
6559 0x00000002, 0x800f0001, 0xa0e40000, 0xa0e40000, /* add r1, c0, c0 */
6560 0x00000008, 0x800f0001, 0x80e40000, 0x80e40001, /* dp3 r1, r0, r1 */
6561 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
6562 0x40000050, 0x80070000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* +cnd r0.xyz, r0.a, c1, c2*/
6563 0x0000ffff /* end */
6565 static const DWORD shader_code_12_coissue_2[] =
6567 0xffff0102, /* ps_1_2 */
6568 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
6569 0x00000051, 0xa00f0003, 0x3f000000, 0x3f000000, 0x3f000000, 0x00000000, /* def c3, 0.5, 0.5, 0.5, 0 */
6570 0x00000040, 0xb00f0000, /* texcoord t0 */
6571 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
6572 0x00000003, 0x800f0000, 0x80e40000, 0xa0e40003, /* sub r0, r0, c3 */
6573 0x00000002, 0x800f0001, 0xa0e40000, 0xa0e40000, /* add r1, c0, c0 */
6574 0x00000008, 0x800f0001, 0x80e40000, 0x80e40001, /* dp3 r1, r0, r1 */
6575 0x00000001, 0x800f0000, 0x80e40001, /* mov r0, r1 */
6576 0x00000001, 0x80070000, 0x80ff0001, /* mov r0.xyz, r1.a */
6577 0x40000050, 0x80080000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* +cnd r0.a, r0.a, c1, c2 */
6578 0x00000001, 0x80070000, 0x80ff0000, /* mov r0.xyz, r0.a */
6579 0x0000ffff /* end */
6581 static const DWORD shader_code_13_coissue[] =
6583 0xffff0103, /* ps_1_3 */
6584 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
6585 0x00000051, 0xa00f0003, 0x3f000000, 0x3f000000, 0x3f000000, 0x00000000, /* def c3, 0.5, 0.5, 0.5, 0 */
6586 0x00000040, 0xb00f0000, /* texcoord t0 */
6587 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
6588 0x00000003, 0x800f0000, 0x80e40000, 0xa0e40003, /* sub r0, r0, c3 */
6589 0x00000002, 0x800f0001, 0xa0e40000, 0xa0e40000, /* add r1, c0, c0 */
6590 0x00000008, 0x800f0001, 0x80e40000, 0x80e40001, /* dp3 r1, r0, r1 */
6591 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
6592 0x40000050, 0x80070000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* +cnd r0.xyz, r0.a, c1, c2*/
6593 0x0000ffff /* end */
6595 static const DWORD shader_code_13_coissue_2[] =
6597 0xffff0103, /* ps_1_3 */
6598 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
6599 0x00000051, 0xa00f0003, 0x3f000000, 0x3f000000, 0x3f000000, 0x00000000, /* def c3, 0.5, 0.5, 0.5, 0 */
6600 0x00000040, 0xb00f0000, /* texcoord t0 */
6601 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
6602 0x00000003, 0x800f0000, 0x80e40000, 0xa0e40003, /* sub r0, r0, c3 */
6603 0x00000002, 0x800f0001, 0xa0e40000, 0xa0e40000, /* add r1, c0, c0 */
6604 0x00000008, 0x800f0001, 0x80e40000, 0x80e40001, /* dp3 r1, r0, r1 */
6605 0x00000001, 0x800f0000, 0x80e40001, /* mov r0, r1 */
6606 0x00000001, 0x80070000, 0x80ff0001, /* mov r0.xyz, r1.a */
6607 0x40000050, 0x80080000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* +cnd r0.a, r0.a, c1, c2 */
6608 0x00000001, 0x80070000, 0x80ff0000, /* mov r0.xyz, r0.a */
6609 0x0000ffff /* end */
6611 /* ps_1_4 does not have a different cnd behavior, just pass the [0;1]
6612 * texcrd result to cnd, it will compare against 0.5. */
6613 static const DWORD shader_code_14_coissue[] =
6615 0xffff0104, /* ps_1_4 */
6616 0x00000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0, 0, 0, 1 */
6617 0x00000040, 0x80070000, 0xb0e40000, /* texcrd r0.xyz, t0 */
6618 0x00000001, 0x80080000, 0xa0ff0000, /* mov r0.a, c0.a */
6619 0x40000050, 0x80070000, 0x80e40000, 0xa0e40001, 0xa0e40002, /* +cnd r0.xyz, r0, c1, c2 */
6620 0x0000ffff /* end */
6622 static const DWORD shader_code_14_coissue_2[] =
6624 0xffff0104, /* ps_1_4 */
6625 0x00000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0, 0, 0, 1 */
6626 0x00000040, 0x80070000, 0xb0e40000, /* texcrd r0.xyz, t0 */
6627 0x00000001, 0x80080000, 0x80000000, /* mov r0.a, r0.x */
6628 0x00000001, 0x80070001, 0xa0ff0000, /* mov r1.xyz, c0.a */
6629 0x40000050, 0x80080001, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* +cnd r1.a, r0.a, c1, c2 */
6630 0x00000001, 0x80070000, 0x80ff0001, /* mov r0.xyz, r1.a */
6631 0x00000001, 0x80080000, 0xa0ff0000, /* mov r0.a, c0.a */
6632 0x0000ffff /* end */
6634 static const float quad1[] =
6636 -1.0f, -1.0f, 0.1f, 0.0f, 0.0f, 1.0f,
6637 -1.0f, 0.0f, 0.1f, 0.0f, 1.0f, 0.0f,
6638 0.0f, -1.0f, 0.1f, 1.0f, 0.0f, 1.0f,
6639 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 0.0f,
6641 static const float quad2[] =
6643 0.0f, -1.0f, 0.1f, 0.0f, 0.0f, 1.0f,
6644 0.0f, 0.0f, 0.1f, 0.0f, 1.0f, 0.0f,
6645 1.0f, -1.0f, 0.1f, 1.0f, 0.0f, 1.0f,
6646 1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 0.0f,
6648 static const float quad3[] =
6650 0.0f, 0.0f, 0.1f, 0.0f, 0.0f, 1.0f,
6651 0.0f, 1.0f, 0.1f, 0.0f, 1.0f, 0.0f,
6652 1.0f, 0.0f, 0.1f, 1.0f, 0.0f, 1.0f,
6653 1.0f, 1.0f, 0.1f, 1.0f, 1.0f, 0.0f,
6655 static const float quad4[] =
6657 -1.0f, 0.0f, 0.1f, 0.0f, 0.0f, 1.0f,
6658 -1.0f, 1.0f, 0.1f, 0.0f, 1.0f, 0.0f,
6659 0.0f, 0.0f, 0.1f, 1.0f, 0.0f, 1.0f,
6660 0.0f, 1.0f, 0.1f, 1.0f, 1.0f, 0.0f,
6662 static const float test_data_c1[4] = {0.0f, 0.0f, 0.0f, 0.0f};
6663 static const float test_data_c2[4] = {1.0f, 1.0f, 1.0f, 1.0f};
6664 static const float test_data_c1_coi[4] = {0.0f, 1.0f, 0.0f, 0.0f};
6665 static const float test_data_c2_coi[4] = {1.0f, 0.0f, 1.0f, 1.0f};
6667 window = create_window();
6668 d3d = Direct3DCreate9(D3D_SDK_VERSION);
6669 ok(!!d3d, "Failed to create a D3D object.\n");
6670 if (!(device = create_device(d3d, window, window, TRUE)))
6672 skip("Failed to create a D3D device, skipping tests.\n");
6673 goto done;
6676 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
6677 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
6678 if (caps.PixelShaderVersion < D3DPS_VERSION(1, 4))
6680 skip("No ps_1_4 support, skipping tests.\n");
6681 IDirect3DDevice9_Release(device);
6682 goto done;
6685 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ffff, 1.0f, 0);
6686 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
6688 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_11, &shader_11);
6689 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6690 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_12, &shader_12);
6691 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6692 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_13, &shader_13);
6693 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6694 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_14, &shader_14);
6695 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6696 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_11_coissue, &shader_11_coissue);
6697 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6698 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_12_coissue, &shader_12_coissue);
6699 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6700 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_13_coissue, &shader_13_coissue);
6701 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6702 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_14_coissue, &shader_14_coissue);
6703 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6704 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_11_coissue_2, &shader_11_coissue_2);
6705 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6706 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_12_coissue_2, &shader_12_coissue_2);
6707 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6708 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_13_coissue_2, &shader_13_coissue_2);
6709 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6710 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_14_coissue_2, &shader_14_coissue_2);
6711 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6713 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 1, test_data_c1, 1);
6714 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
6715 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 2, test_data_c2, 1);
6716 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
6717 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
6718 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF returned %08x\n", hr);
6720 hr = IDirect3DDevice9_BeginScene(device);
6721 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6723 hr = IDirect3DDevice9_SetPixelShader(device, shader_11);
6724 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6725 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, 6 * sizeof(float));
6726 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6728 hr = IDirect3DDevice9_SetPixelShader(device, shader_12);
6729 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6730 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 6 * sizeof(float));
6731 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6733 hr = IDirect3DDevice9_SetPixelShader(device, shader_13);
6734 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6735 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, 6 * sizeof(float));
6736 ok(hr == D3D_OK, "DrawPrimitiveUP failed (%08x)\n", hr);
6738 hr = IDirect3DDevice9_SetPixelShader(device, shader_14);
6739 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6740 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, 6 * sizeof(float));
6741 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6743 hr = IDirect3DDevice9_EndScene(device);
6744 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6746 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
6747 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShader returned %08x\n", hr);
6749 /* This is the 1.4 test. Each component(r, g, b) is tested separately against 0.5 */
6750 color = getPixelColor(device, 158, 118);
6751 ok(color == 0x00ff00ff, "pixel 158, 118 has color %08x, expected 0x00ff00ff\n", color);
6752 color = getPixelColor(device, 162, 118);
6753 ok(color == 0x000000ff, "pixel 162, 118 has color %08x, expected 0x000000ff\n", color);
6754 color = getPixelColor(device, 158, 122);
6755 ok(color == 0x00ffffff, "pixel 162, 122 has color %08x, expected 0x00ffffff\n", color);
6756 color = getPixelColor(device, 162, 122);
6757 ok(color == 0x0000ffff, "pixel 162, 122 has color %08x, expected 0x0000ffff\n", color);
6759 /* 1.1 shader. All 3 components get set, based on the .w comparison */
6760 color = getPixelColor(device, 158, 358);
6761 ok(color == 0x00ffffff, "pixel 158, 358 has color %08x, expected 0x00ffffff\n", color);
6762 color = getPixelColor(device, 162, 358);
6763 ok(color_match(color, 0x00000000, 1), "pixel 162, 358 has color 0x%08x, expected 0x00000000.\n", color);
6764 color = getPixelColor(device, 158, 362);
6765 ok(color == 0x00ffffff, "pixel 158, 362 has color %08x, expected 0x00ffffff\n", color);
6766 color = getPixelColor(device, 162, 362);
6767 ok(color_match(color, 0x00000000, 1), "pixel 162, 362 has color 0x%08x, expected 0x00000000.\n", color);
6769 /* 1.2 shader */
6770 color = getPixelColor(device, 478, 358);
6771 ok(color == 0x00ffffff, "pixel 478, 358 has color %08x, expected 0x00ffffff\n", color);
6772 color = getPixelColor(device, 482, 358);
6773 ok(color_match(color, 0x00000000, 1), "pixel 482, 358 has color 0x%08x, expected 0x00000000.\n", color);
6774 color = getPixelColor(device, 478, 362);
6775 ok(color == 0x00ffffff, "pixel 478, 362 has color %08x, expected 0x00ffffff\n", color);
6776 color = getPixelColor(device, 482, 362);
6777 ok(color_match(color, 0x00000000, 1), "pixel 482, 362 has color 0x%08x, expected 0x00000000.\n", color);
6779 /* 1.3 shader */
6780 color = getPixelColor(device, 478, 118);
6781 ok(color == 0x00ffffff, "pixel 478, 118 has color %08x, expected 0x00ffffff\n", color);
6782 color = getPixelColor(device, 482, 118);
6783 ok(color_match(color, 0x00000000, 1), "pixel 482, 118 has color 0x%08x, expected 0x00000000.\n", color);
6784 color = getPixelColor(device, 478, 122);
6785 ok(color == 0x00ffffff, "pixel 478, 122 has color %08x, expected 0x00ffffff\n", color);
6786 color = getPixelColor(device, 482, 122);
6787 ok(color_match(color, 0x00000000, 1), "pixel 482, 122 has color 0x%08x, expected 0x00000000.\n", color);
6789 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
6790 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
6792 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ffff, 0.0, 0);
6793 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
6794 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 1, test_data_c1_coi, 1);
6795 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
6796 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 2, test_data_c2_coi, 1);
6797 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
6799 hr = IDirect3DDevice9_BeginScene(device);
6800 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6802 hr = IDirect3DDevice9_SetPixelShader(device, shader_11_coissue);
6803 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6804 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, 6 * sizeof(float));
6805 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6807 hr = IDirect3DDevice9_SetPixelShader(device, shader_12_coissue);
6808 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6809 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 6 * sizeof(float));
6810 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6812 hr = IDirect3DDevice9_SetPixelShader(device, shader_13_coissue);
6813 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6814 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, 6 * sizeof(float));
6815 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6817 hr = IDirect3DDevice9_SetPixelShader(device, shader_14_coissue);
6818 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6819 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, 6 * sizeof(float));
6820 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6822 hr = IDirect3DDevice9_EndScene(device);
6823 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6825 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
6826 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader returned %08x\n", hr);
6828 /* This is the 1.4 test. The coissue doesn't change the behavior here, but keep in mind
6829 * that we swapped the values in c1 and c2 to make the other tests return some color
6831 color = getPixelColor(device, 158, 118);
6832 ok(color == 0x00ffffff, "pixel 158, 118 has color %08x, expected 0x00ffffff\n", color);
6833 color = getPixelColor(device, 162, 118);
6834 ok(color == 0x0000ffff, "pixel 162, 118 has color %08x, expected 0x0000ffff\n", color);
6835 color = getPixelColor(device, 158, 122);
6836 ok(color == 0x00ff00ff, "pixel 162, 122 has color %08x, expected 0x00ff00ff\n", color);
6837 color = getPixelColor(device, 162, 122);
6838 ok(color == 0x000000ff, "pixel 162, 122 has color %08x, expected 0x000000ff\n", color);
6840 /* 1.1 shader. coissue flag changed the semantic of cnd, c1 is always selected
6841 * (The Win7 nvidia driver always selects c2)
6843 color = getPixelColor(device, 158, 358);
6844 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6845 "pixel 158, 358 has color %08x, expected 0x0000ff00\n", color);
6846 color = getPixelColor(device, 162, 358);
6847 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6848 "pixel 162, 358 has color %08x, expected 0x0000ff00\n", color);
6849 color = getPixelColor(device, 158, 362);
6850 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6851 "pixel 158, 362 has color %08x, expected 0x0000ff00\n", color);
6852 color = getPixelColor(device, 162, 362);
6853 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6854 "pixel 162, 362 has color %08x, expected 0x0000ff00\n", color);
6856 /* 1.2 shader */
6857 color = getPixelColor(device, 478, 358);
6858 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6859 "pixel 478, 358 has color %08x, expected 0x0000ff00\n", color);
6860 color = getPixelColor(device, 482, 358);
6861 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6862 "pixel 482, 358 has color %08x, expected 0x0000ff00\n", color);
6863 color = getPixelColor(device, 478, 362);
6864 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6865 "pixel 478, 362 has color %08x, expected 0x0000ff00\n", color);
6866 color = getPixelColor(device, 482, 362);
6867 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6868 "pixel 482, 362 has color %08x, expected 0x0000ff00\n", color);
6870 /* 1.3 shader */
6871 color = getPixelColor(device, 478, 118);
6872 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6873 "pixel 478, 118 has color %08x, expected 0x0000ff00\n", color);
6874 color = getPixelColor(device, 482, 118);
6875 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6876 "pixel 482, 118 has color %08x, expected 0x0000ff00\n", color);
6877 color = getPixelColor(device, 478, 122);
6878 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6879 "pixel 478, 122 has color %08x, expected 0x0000ff00\n", color);
6880 color = getPixelColor(device, 482, 122);
6881 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6882 "pixel 482, 122 has color %08x, expected 0x0000ff00\n", color);
6884 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
6885 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
6887 /* Retest with the coissue flag on the alpha instruction instead. This
6888 * works "as expected". The Windows 8 testbot (WARP) seems to handle this
6889 * the same as coissue on .rgb. */
6890 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ffff, 0.0, 0);
6891 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
6893 hr = IDirect3DDevice9_BeginScene(device);
6894 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6896 hr = IDirect3DDevice9_SetPixelShader(device, shader_11_coissue_2);
6897 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6898 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, 6 * sizeof(float));
6899 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6901 hr = IDirect3DDevice9_SetPixelShader(device, shader_12_coissue_2);
6902 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6903 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 6 * sizeof(float));
6904 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6906 hr = IDirect3DDevice9_SetPixelShader(device, shader_13_coissue_2);
6907 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6908 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, 6 * sizeof(float));
6909 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6911 hr = IDirect3DDevice9_SetPixelShader(device, shader_14_coissue_2);
6912 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6913 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, 6 * sizeof(float));
6914 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6916 hr = IDirect3DDevice9_EndScene(device);
6917 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6919 /* 1.4 shader */
6920 color = getPixelColor(device, 158, 118);
6921 ok(color == 0x00ffffff, "pixel 158, 118 has color %08x, expected 0x00ffffff\n", color);
6922 color = getPixelColor(device, 162, 118);
6923 ok(color == 0x00000000, "pixel 162, 118 has color %08x, expected 0x00000000\n", color);
6924 color = getPixelColor(device, 158, 122);
6925 ok(color == 0x00ffffff, "pixel 162, 122 has color %08x, expected 0x00ffffff\n", color);
6926 color = getPixelColor(device, 162, 122);
6927 ok(color == 0x00000000, "pixel 162, 122 has color %08x, expected 0x00000000\n", color);
6929 /* 1.1 shader */
6930 color = getPixelColor(device, 238, 358);
6931 ok(color_match(color, 0x00ffffff, 1) || broken(color_match(color, 0x00000000, 1)),
6932 "pixel 238, 358 has color %08x, expected 0x00ffffff\n", color);
6933 color = getPixelColor(device, 242, 358);
6934 ok(color_match(color, 0x00000000, 1),
6935 "pixel 242, 358 has color %08x, expected 0x00000000\n", color);
6936 color = getPixelColor(device, 238, 362);
6937 ok(color_match(color, 0x00ffffff, 1) || broken(color_match(color, 0x00000000, 1)),
6938 "pixel 238, 362 has color %08x, expected 0x00ffffff\n", color);
6939 color = getPixelColor(device, 242, 362);
6940 ok(color_match(color, 0x00000000, 1),
6941 "pixel 242, 362 has color %08x, expected 0x00000000\n", color);
6943 /* 1.2 shader */
6944 color = getPixelColor(device, 558, 358);
6945 ok(color_match(color, 0x00ffffff, 1) || broken(color_match(color, 0x00000000, 1)),
6946 "pixel 558, 358 has color %08x, expected 0x00ffffff\n", color);
6947 color = getPixelColor(device, 562, 358);
6948 ok(color_match(color, 0x00000000, 1),
6949 "pixel 562, 358 has color %08x, expected 0x00000000\n", color);
6950 color = getPixelColor(device, 558, 362);
6951 ok(color_match(color, 0x00ffffff, 1) || broken(color_match(color, 0x00000000, 1)),
6952 "pixel 558, 362 has color %08x, expected 0x00ffffff\n", color);
6953 color = getPixelColor(device, 562, 362);
6954 ok(color_match(color, 0x00000000, 1),
6955 "pixel 562, 362 has color %08x, expected 0x00000000\n", color);
6957 /* 1.3 shader */
6958 color = getPixelColor(device, 558, 118);
6959 ok(color_match(color, 0x00ffffff, 1) || broken(color_match(color, 0x00000000, 1)),
6960 "pixel 558, 118 has color %08x, expected 0x00ffffff\n", color);
6961 color = getPixelColor(device, 562, 118);
6962 ok(color_match(color, 0x00000000, 1),
6963 "pixel 562, 118 has color %08x, expected 0x00000000\n", color);
6964 color = getPixelColor(device, 558, 122);
6965 ok(color_match(color, 0x00ffffff, 1) || broken(color_match(color, 0x00000000, 1)),
6966 "pixel 558, 122 has color %08x, expected 0x00ffffff\n", color);
6967 color = getPixelColor(device, 562, 122);
6968 ok(color_match(color, 0x00000000, 1),
6969 "pixel 562, 122 has color %08x, expected 0x00000000\n", color);
6971 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
6972 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
6974 IDirect3DPixelShader9_Release(shader_14_coissue_2);
6975 IDirect3DPixelShader9_Release(shader_13_coissue_2);
6976 IDirect3DPixelShader9_Release(shader_12_coissue_2);
6977 IDirect3DPixelShader9_Release(shader_11_coissue_2);
6978 IDirect3DPixelShader9_Release(shader_14_coissue);
6979 IDirect3DPixelShader9_Release(shader_13_coissue);
6980 IDirect3DPixelShader9_Release(shader_12_coissue);
6981 IDirect3DPixelShader9_Release(shader_11_coissue);
6982 IDirect3DPixelShader9_Release(shader_14);
6983 IDirect3DPixelShader9_Release(shader_13);
6984 IDirect3DPixelShader9_Release(shader_12);
6985 IDirect3DPixelShader9_Release(shader_11);
6986 refcount = IDirect3DDevice9_Release(device);
6987 ok(!refcount, "Device has %u references left.\n", refcount);
6988 done:
6989 IDirect3D9_Release(d3d);
6990 DestroyWindow(window);
6993 static void nested_loop_test(void)
6995 IDirect3DVertexShader9 *vshader;
6996 IDirect3DPixelShader9 *shader;
6997 IDirect3DDevice9 *device;
6998 IDirect3D9 *d3d;
6999 ULONG refcount;
7000 D3DCAPS9 caps;
7001 DWORD color;
7002 HWND window;
7003 HRESULT hr;
7005 static const DWORD shader_code[] =
7007 0xffff0300, /* ps_3_0 */
7008 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0, 0, 0, 1 */
7009 0x05000051, 0xa00f0001, 0x3d000000, 0x00000000, 0x00000000, 0x00000000, /* def c1, 1/32, 0, 0, 0*/
7010 0x05000030, 0xf00f0000, 0x00000004, 0x00000000, 0x00000002, 0x00000000, /* defi i0, 4, 0, 2, 0 */
7011 0x02000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
7012 0x0200001b, 0xf0e40800, 0xf0e40000, /* loop aL, i0 */
7013 0x0200001b, 0xf0e40800, 0xf0e40000, /* loop aL, i0 */
7014 0x03000002, 0x800f0000, 0x80e40000, 0xa0e40001, /* add r0, r0, c1 */
7015 0x0000001d, /* endloop */
7016 0x0000001d, /* endloop */
7017 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
7018 0x0000ffff /* end */
7020 static const DWORD vshader_code[] =
7022 0xfffe0300, /* vs_3_0 */
7023 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7024 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
7025 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
7026 0x0000ffff /* end */
7028 static const float quad[] =
7030 -1.0f, -1.0f, 0.1f,
7031 -1.0f, 1.0f, 0.1f,
7032 1.0f, -1.0f, 0.1f,
7033 1.0f, 1.0f, 0.1f,
7036 window = create_window();
7037 d3d = Direct3DCreate9(D3D_SDK_VERSION);
7038 ok(!!d3d, "Failed to create a D3D object.\n");
7039 if (!(device = create_device(d3d, window, window, TRUE)))
7041 skip("Failed to create a D3D device, skipping tests.\n");
7042 goto done;
7045 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
7046 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
7047 if (caps.PixelShaderVersion < D3DPS_VERSION(3, 0) || caps.VertexShaderVersion < D3DVS_VERSION(3, 0))
7049 skip("No shader model 3 support, skipping tests.\n");
7050 IDirect3DDevice9_Release(device);
7051 goto done;
7054 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code, &shader);
7055 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader failed with %08x\n", hr);
7056 hr = IDirect3DDevice9_SetPixelShader(device, shader);
7057 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader failed with %08x\n", hr);
7058 hr = IDirect3DDevice9_CreateVertexShader(device, vshader_code, &vshader);
7059 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader failed with %08x\n", hr);
7060 hr = IDirect3DDevice9_SetVertexShader(device, vshader);
7061 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShader failed with %08x\n", hr);
7062 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
7063 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
7064 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x0000ff00, 1.0f, 0);
7065 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
7067 hr = IDirect3DDevice9_BeginScene(device);
7068 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
7069 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 3 * sizeof(float));
7070 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7071 hr = IDirect3DDevice9_EndScene(device);
7072 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
7074 color = getPixelColor(device, 360, 240);
7075 ok(color_match(color, 0x00800000, 1),
7076 "Nested loop test returned color 0x%08x, expected 0x00800000.\n", color);
7078 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
7079 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
7081 IDirect3DPixelShader9_Release(shader);
7082 IDirect3DVertexShader9_Release(vshader);
7083 refcount = IDirect3DDevice9_Release(device);
7084 ok(!refcount, "Device has %u references left.\n", refcount);
7085 done:
7086 IDirect3D9_Release(d3d);
7087 DestroyWindow(window);
7090 static void pretransformed_varying_test(void)
7092 /* dcl_position: fails to compile */
7093 static const DWORD blendweight_code[] =
7095 0xffff0300, /* ps_3_0 */
7096 0x0200001f, 0x80000001, 0x900f0000, /* dcl_blendweight, v0 */
7097 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7098 0x0000ffff /* end */
7100 static const DWORD blendindices_code[] =
7102 0xffff0300, /* ps_3_0 */
7103 0x0200001f, 0x80000002, 0x900f0000, /* dcl_blendindices, v0 */
7104 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7105 0x0000ffff /* end */
7107 static const DWORD normal_code[] =
7109 0xffff0300, /* ps_3_0 */
7110 0x0200001f, 0x80000003, 0x900f0000, /* dcl_normal, v0 */
7111 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7112 0x0000ffff /* end */
7114 /* psize: fails? */
7115 static const DWORD texcoord0_code[] =
7117 0xffff0300, /* ps_3_0 */
7118 0x0200001f, 0x80000005, 0x900f0000, /* dcl_texcoord0, v0 */
7119 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7120 0x0000ffff /* end */
7122 static const DWORD tangent_code[] =
7124 0xffff0300, /* ps_3_0 */
7125 0x0200001f, 0x80000006, 0x900f0000, /* dcl_tangent, v0 */
7126 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7127 0x0000ffff /* end */
7129 static const DWORD binormal_code[] =
7131 0xffff0300, /* ps_3_0 */
7132 0x0200001f, 0x80000007, 0x900f0000, /* dcl_binormal, v0 */
7133 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7134 0x0000ffff /* end */
7136 /* tessfactor: fails */
7137 /* positiont: fails */
7138 static const DWORD color_code[] =
7140 0xffff0300, /* ps_3_0 */
7141 0x0200001f, 0x8000000a, 0x900f0000, /* dcl_color0, v0 */
7142 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7143 0x0000ffff /* end */
7145 static const DWORD fog_code[] =
7147 0xffff0300, /* ps_3_0 */
7148 0x0200001f, 0x8000000b, 0x900f0000, /* dcl_fog, v0 */
7149 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7150 0x0000ffff /* end */
7152 static const DWORD depth_code[] =
7154 0xffff0300, /* ps_3_0 */
7155 0x0200001f, 0x8000000c, 0x900f0000, /* dcl_depth, v0 */
7156 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7157 0x0000ffff /* end */
7159 static const DWORD specular_code[] =
7161 0xffff0300, /* ps_3_0 */
7162 0x0200001f, 0x8001000a, 0x900f0000, /* dcl_color1, v0 */
7163 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7164 0x0000ffff /* end */
7166 /* sample: fails */
7167 static const DWORD texcoord1_code[] =
7169 0xffff0300, /* ps_3_0 */
7170 0x0200001f, 0x80010005, 0x900f0000, /* dcl_texcoord1, v0 */
7171 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7172 0x0000ffff /* end */
7174 static const DWORD texcoord1_alpha_code[] =
7176 0xffff0300, /* ps_3_0 */
7177 0x0200001f, 0x80010005, 0x900f0000, /* dcl_texcoord1, v0 */
7178 0x02000001, 0x800f0800, 0x90ff0000, /* mov oC0, v0.w */
7179 0x0000ffff /* end */
7182 static const struct
7184 const char *name;
7185 const DWORD *shader_code;
7186 DWORD color;
7187 BOOL todo;
7188 BOOL broken_warp;
7190 tests[] =
7192 {"blendweight", blendweight_code, 0x00191919, TRUE },
7193 {"blendindices", blendindices_code, 0x00333333, TRUE },
7194 {"normal", normal_code, 0x004c4c4c, TRUE },
7195 {"texcoord0", texcoord0_code, 0x00808c8c, FALSE},
7196 {"tangent", tangent_code, 0x00999999, TRUE },
7197 {"binormal", binormal_code, 0x00b2b2b2, TRUE },
7198 {"color", color_code, 0x00e6e6e6, FALSE},
7199 {"fog", fog_code, 0x00666666, TRUE },
7200 {"depth", depth_code, 0x00cccccc, TRUE },
7201 {"specular", specular_code, 0x004488ff, FALSE},
7202 {"texcoord1", texcoord1_code, 0x00000000, FALSE},
7203 {"texcoord1 alpha", texcoord1_alpha_code, 0x00000000, FALSE, TRUE},
7205 /* Declare a monster vertex type :-) */
7206 static const D3DVERTEXELEMENT9 decl_elements[] = {
7207 {0, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITIONT, 0},
7208 {0, 16, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0},
7209 {0, 32, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDINDICES, 0},
7210 {0, 48, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
7211 {0, 64, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_FOG, 0},
7212 {0, 80, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
7213 {0, 96, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0},
7214 {0, 112, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0},
7215 {0, 128, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_DEPTH, 0},
7216 {0, 144, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
7217 {0, 148, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 1},
7218 D3DDECL_END()
7221 static const struct
7223 float pos_x, pos_y, pos_z, rhw;
7224 float weight_1, weight_2, weight_3, weight_4;
7225 float index_1, index_2, index_3, index_4;
7226 float normal_1, normal_2, normal_3, normal_4;
7227 float fog_1, fog_2, fog_3, fog_4;
7228 float texcoord_1, texcoord_2, texcoord_3, texcoord_4;
7229 float tangent_1, tangent_2, tangent_3, tangent_4;
7230 float binormal_1, binormal_2, binormal_3, binormal_4;
7231 float depth_1, depth_2, depth_3, depth_4;
7232 D3DCOLOR diffuse;
7233 D3DCOLOR specular;
7235 data[] =
7238 0.0f, 0.0f, 0.1f, 1.0f,
7239 0.1f, 0.1f, 0.1f, 0.1f,
7240 0.2f, 0.2f, 0.2f, 0.2f,
7241 0.3f, 0.3f, 0.3f, 0.3f,
7242 0.4f, 0.4f, 0.4f, 0.4f,
7243 0.5f, 0.55f, 0.55f, 0.55f,
7244 0.6f, 0.6f, 0.6f, 0.7f,
7245 0.7f, 0.7f, 0.7f, 0.6f,
7246 0.8f, 0.8f, 0.8f, 0.8f,
7247 0xe6e6e6e6, /* 0.9 * 256 */
7248 0x224488ff, /* Nothing special */
7251 640.0f, 0.0f, 0.1f, 1.0f,
7252 0.1f, 0.1f, 0.1f, 0.1f,
7253 0.2f, 0.2f, 0.2f, 0.2f,
7254 0.3f, 0.3f, 0.3f, 0.3f,
7255 0.4f, 0.4f, 0.4f, 0.4f,
7256 0.5f, 0.55f, 0.55f, 0.55f,
7257 0.6f, 0.6f, 0.6f, 0.7f,
7258 0.7f, 0.7f, 0.7f, 0.6f,
7259 0.8f, 0.8f, 0.8f, 0.8f,
7260 0xe6e6e6e6, /* 0.9 * 256 */
7261 0x224488ff, /* Nothing special */
7264 0.0f, 480.0f, 0.1f, 1.0f,
7265 0.1f, 0.1f, 0.1f, 0.1f,
7266 0.2f, 0.2f, 0.2f, 0.2f,
7267 0.3f, 0.3f, 0.3f, 0.3f,
7268 0.4f, 0.4f, 0.4f, 0.4f,
7269 0.5f, 0.55f, 0.55f, 0.55f,
7270 0.6f, 0.6f, 0.6f, 0.7f,
7271 0.7f, 0.7f, 0.7f, 0.6f,
7272 0.8f, 0.8f, 0.8f, 0.8f,
7273 0xe6e6e6e6, /* 0.9 * 256 */
7274 0x224488ff, /* Nothing special */
7277 640.0f, 480.0f, 0.1f, 1.0f,
7278 0.1f, 0.1f, 0.1f, 0.1f,
7279 0.2f, 0.2f, 0.2f, 0.2f,
7280 0.3f, 0.3f, 0.3f, 0.3f,
7281 0.4f, 0.4f, 0.4f, 0.4f,
7282 0.5f, 0.55f, 0.55f, 0.55f,
7283 0.6f, 0.6f, 0.6f, 0.7f,
7284 0.7f, 0.7f, 0.7f, 0.6f,
7285 0.8f, 0.8f, 0.8f, 0.8f,
7286 0xe6e6e6e6, /* 0.9 * 256 */
7287 0x224488ff, /* Nothing special */
7290 D3DADAPTER_IDENTIFIER9 identifier;
7291 IDirect3DVertexDeclaration9 *decl;
7292 IDirect3DDevice9 *device;
7293 IDirect3D9 *d3d;
7294 unsigned int i;
7295 ULONG refcount;
7296 D3DCAPS9 caps;
7297 DWORD color;
7298 HWND window;
7299 HRESULT hr;
7300 BOOL warp;
7302 window = create_window();
7303 d3d = Direct3DCreate9(D3D_SDK_VERSION);
7304 ok(!!d3d, "Failed to create a D3D object.\n");
7305 if (!(device = create_device(d3d, window, window, TRUE)))
7307 skip("Failed to create a D3D device, skipping tests.\n");
7308 goto done;
7311 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
7312 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
7313 if (caps.PixelShaderVersion < D3DPS_VERSION(3, 0) || caps.VertexShaderVersion < D3DVS_VERSION(3, 0))
7315 skip("No shader model 3 support, skipping tests.\n");
7316 IDirect3DDevice9_Release(device);
7317 goto done;
7320 hr = IDirect3D9_GetAdapterIdentifier(d3d, D3DADAPTER_DEFAULT, 0, &identifier);
7321 ok(SUCCEEDED(hr), "Failed to get adapter identifier, hr %#x.\n", hr);
7322 warp = adapter_is_warp(&identifier);
7324 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &decl);
7325 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
7326 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl);
7327 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexDeclaration returned %08x\n", hr);
7329 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
7331 IDirect3DPixelShader9 *shader;
7333 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
7334 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
7336 hr = IDirect3DDevice9_CreatePixelShader(device, tests[i].shader_code, &shader);
7337 ok(SUCCEEDED(hr), "Failed to create pixel shader for test %s, hr %#x.\n", tests[i].name, hr);
7339 hr = IDirect3DDevice9_SetPixelShader(device, shader);
7340 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader returned %08x\n", hr);
7342 hr = IDirect3DDevice9_BeginScene(device);
7343 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
7344 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, data, sizeof(*data));
7345 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7346 hr = IDirect3DDevice9_EndScene(device);
7347 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
7349 /* This isn't a weekend's job to fix, ignore the problem for now.
7350 * Needs a replacement pipeline. */
7351 color = getPixelColor(device, 360, 240);
7352 if (tests[i].todo)
7353 todo_wine ok(color_match(color, tests[i].color, 1)
7354 || broken(color_match(color, 0x00000000, 1)
7355 && tests[i].shader_code == blendindices_code),
7356 "Test %s returned color 0x%08x, expected 0x%08x (todo).\n",
7357 tests[i].name, color, tests[i].color);
7358 else
7359 ok(color_match(color, tests[i].color, 1) || broken(warp && tests[i].broken_warp),
7360 "Test %s returned color 0x%08x, expected 0x%08x.\n",
7361 tests[i].name, color, tests[i].color);
7363 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
7364 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
7366 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
7367 ok(SUCCEEDED(hr), "Failed to set pixel shader for test %s, hr %#x.\n", tests[i].name, hr);
7368 IDirect3DPixelShader9_Release(shader);
7371 IDirect3DVertexDeclaration9_Release(decl);
7372 refcount = IDirect3DDevice9_Release(device);
7373 ok(!refcount, "Device has %u references left.\n", refcount);
7374 done:
7375 IDirect3D9_Release(d3d);
7376 DestroyWindow(window);
7379 static void test_compare_instructions(void)
7381 IDirect3DVertexShader9 *shader_slt_scalar;
7382 IDirect3DVertexShader9 *shader_sge_scalar;
7383 IDirect3DVertexShader9 *shader_slt_vec;
7384 IDirect3DVertexShader9 *shader_sge_vec;
7385 IDirect3DDevice9 *device;
7386 IDirect3D9 *d3d;
7387 D3DCOLOR color;
7388 ULONG refcount;
7389 D3DCAPS9 caps;
7390 HWND window;
7391 HRESULT hr;
7393 static const DWORD shader_sge_vec_code[] =
7395 0xfffe0101, /* vs_1_1 */
7396 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7397 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
7398 0x00000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
7399 0x0000000d, 0xd00f0000, 0x80e40000, 0xa0e40001, /* sge oD0, r0, c1 */
7400 0x0000ffff /* end */
7402 static const DWORD shader_slt_vec_code[] =
7404 0xfffe0101, /* vs_1_1 */
7405 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7406 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
7407 0x00000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
7408 0x0000000c, 0xd00f0000, 0x80e40000, 0xa0e40001, /* slt oD0, r0, c1 */
7409 0x0000ffff /* end */
7411 static const DWORD shader_sge_scalar_code[] =
7413 0xfffe0101, /* vs_1_1 */
7414 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7415 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
7416 0x00000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
7417 0x0000000d, 0xd0010000, 0x80000000, 0xa0550001, /* slt oD0.r, r0.r, c1.b */
7418 0x0000000d, 0xd0020000, 0x80550000, 0xa0aa0001, /* slt oD0.g, r0.g, c1.r */
7419 0x0000000d, 0xd0040000, 0x80aa0000, 0xa0000001, /* slt oD0.b, r0.b, c1.g */
7420 0x0000ffff /* end */
7422 static const DWORD shader_slt_scalar_code[] =
7424 0xfffe0101, /* vs_1_1 */
7425 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7426 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
7427 0x00000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
7428 0x0000000c, 0xd0010000, 0x80000000, 0xa0aa0001, /* slt oD0.r, r0.r, c1.b */
7429 0x0000000c, 0xd0020000, 0x80550000, 0xa0000001, /* slt oD0.g, r0.g, c1.r */
7430 0x0000000c, 0xd0040000, 0x80aa0000, 0xa0550001, /* slt oD0.b, r0.b, c1.g */
7431 0x0000ffff /* end */
7433 static const float quad1[] =
7435 -1.0f, -1.0f, 0.1f,
7436 -1.0f, 0.0f, 0.1f,
7437 0.0f, -1.0f, 0.1f,
7438 0.0f, 0.0f, 0.1f,
7440 static const float quad2[] =
7442 0.0f, -1.0f, 0.1f,
7443 0.0f, 0.0f, 0.1f,
7444 1.0f, -1.0f, 0.1f,
7445 1.0f, 0.0f, 0.1f,
7447 static const float quad3[] =
7449 -1.0f, 0.0f, 0.1f,
7450 -1.0f, 1.0f, 0.1f,
7451 0.0f, 0.0f, 0.1f,
7452 0.0f, 1.0f, 0.1f,
7454 static const float quad4[] =
7456 0.0f, 0.0f, 0.1f,
7457 0.0f, 1.0f, 0.1f,
7458 1.0f, 0.0f, 0.1f,
7459 1.0f, 1.0f, 0.1f,
7461 static const float const0[4] = {0.8f, 0.2f, 0.2f, 0.2f};
7462 static const float const1[4] = {0.2f, 0.8f, 0.2f, 0.2f};
7464 window = create_window();
7465 d3d = Direct3DCreate9(D3D_SDK_VERSION);
7466 ok(!!d3d, "Failed to create a D3D object.\n");
7467 if (!(device = create_device(d3d, window, window, TRUE)))
7469 skip("Failed to create a D3D device, skipping tests.\n");
7470 goto done;
7473 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
7474 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
7475 if (caps.VertexShaderVersion < D3DVS_VERSION(1, 1))
7477 skip("No vs_1_1 support, skipping tests.\n");
7478 IDirect3DDevice9_Release(device);
7479 goto done;
7482 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
7483 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear returned %#x.\n", hr);
7485 hr = IDirect3DDevice9_CreateVertexShader(device, shader_sge_vec_code, &shader_sge_vec);
7486 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
7487 hr = IDirect3DDevice9_CreateVertexShader(device, shader_slt_vec_code, &shader_slt_vec);
7488 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
7489 hr = IDirect3DDevice9_CreateVertexShader(device, shader_sge_scalar_code, &shader_sge_scalar);
7490 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
7491 hr = IDirect3DDevice9_CreateVertexShader(device, shader_slt_scalar_code, &shader_slt_scalar);
7492 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
7493 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 0, const0, 1);
7494 ok(SUCCEEDED(hr), "SetVertexShaderConstantF failed (%08x)\n", hr);
7495 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 1, const1, 1);
7496 ok(SUCCEEDED(hr), "SetVertexShaderConstantF failed (%08x)\n", hr);
7497 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
7498 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetFVF failed (%08x)\n", hr);
7500 hr = IDirect3DDevice9_BeginScene(device);
7501 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
7503 hr = IDirect3DDevice9_SetVertexShader(device, shader_sge_vec);
7504 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
7505 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(float) * 3);
7506 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7508 hr = IDirect3DDevice9_SetVertexShader(device, shader_slt_vec);
7509 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
7510 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(float) * 3);
7511 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7513 hr = IDirect3DDevice9_SetVertexShader(device, shader_sge_scalar);
7514 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
7515 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, sizeof(float) * 3);
7516 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7518 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 0, const0, 1);
7519 ok(SUCCEEDED(hr), "Failed to set vertex shader constant, hr %#x.\n", hr);
7521 hr = IDirect3DDevice9_SetVertexShader(device, shader_slt_scalar);
7522 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
7523 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, sizeof(float) * 3);
7524 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7526 hr = IDirect3DDevice9_EndScene(device);
7527 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
7529 color = getPixelColor(device, 160, 360);
7530 ok(color == 0x00ff00ff, "Compare test: Quad 1(sge vec) returned color 0x%08x, expected 0x00ff00ff\n", color);
7531 color = getPixelColor(device, 480, 360);
7532 ok(color == 0x0000ff00, "Compare test: Quad 2(slt vec) returned color 0x%08x, expected 0x0000ff00\n", color);
7533 color = getPixelColor(device, 160, 120);
7534 ok(color == 0x00ffffff, "Compare test: Quad 3(sge scalar) returned color 0x%08x, expected 0x00ffffff\n", color);
7535 color = getPixelColor(device, 480, 160);
7536 ok(color == 0x000000ff, "Compare test: Quad 4(slt scalar) returned color 0x%08x, expected 0x000000ff\n", color);
7538 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
7539 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
7541 IDirect3DVertexShader9_Release(shader_sge_vec);
7542 IDirect3DVertexShader9_Release(shader_slt_vec);
7543 IDirect3DVertexShader9_Release(shader_sge_scalar);
7544 IDirect3DVertexShader9_Release(shader_slt_scalar);
7545 refcount = IDirect3DDevice9_Release(device);
7546 ok(!refcount, "Device has %u references left.\n", refcount);
7547 done:
7548 IDirect3D9_Release(d3d);
7549 DestroyWindow(window);
7552 static void test_vshader_input(void)
7554 IDirect3DVertexDeclaration9 *decl_twotexcrd, *decl_onetexcrd, *decl_twotex_wrongidx, *decl_twotexcrd_rightorder;
7555 IDirect3DVertexDeclaration9 *decl_texcoord_color, *decl_color_color, *decl_color_ubyte, *decl_color_float;
7556 IDirect3DVertexDeclaration9 *decl_nocolor;
7557 IDirect3DVertexShader9 *swapped_shader, *texcoord_color_shader, *color_color_shader;
7558 D3DADAPTER_IDENTIFIER9 identifier;
7559 IDirect3DPixelShader9 *ps;
7560 IDirect3DDevice9 *device;
7561 IDirect3D9 *d3d;
7562 ULONG refcount;
7563 unsigned int i;
7564 D3DCAPS9 caps;
7565 DWORD color;
7566 HWND window;
7567 HRESULT hr;
7568 BOOL warp;
7570 static const DWORD swapped_shader_code_3[] =
7572 0xfffe0300, /* vs_3_0 */
7573 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
7574 0x0200001f, 0x8000000a, 0xe00f0001, /* dcl_color o1 */
7575 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7576 0x0200001f, 0x80000005, 0x900f0001, /* dcl_texcoord0 v1 */
7577 0x0200001f, 0x80010005, 0x900f0002, /* dcl_texcoord1 v2 */
7578 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
7579 0x02000001, 0x800f0001, 0x90e40001, /* mov r1, v1 */
7580 0x03000002, 0xe00f0001, 0x80e40001, 0x91e40002, /* sub o1, r1, v2 */
7581 0x0000ffff /* end */
7583 static const DWORD swapped_shader_code_1[] =
7585 0xfffe0101, /* vs_1_1 */
7586 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7587 0x0000001f, 0x80000005, 0x900f0001, /* dcl_texcoord0 v1 */
7588 0x0000001f, 0x80010005, 0x900f0002, /* dcl_texcoord1 v2 */
7589 0x00000001, 0xc00f0000, 0x90e40000, /* mov o0, v0 */
7590 0x00000001, 0x800f0001, 0x90e40001, /* mov r1, v1 */
7591 0x00000002, 0xd00f0000, 0x80e40001, 0x91e40002, /* sub o1, r1, v2 */
7592 0x0000ffff /* end */
7594 static const DWORD swapped_shader_code_2[] =
7596 0xfffe0200, /* vs_2_0 */
7597 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7598 0x0200001f, 0x80000005, 0x900f0001, /* dcl_texcoord0 v1 */
7599 0x0200001f, 0x80010005, 0x900f0002, /* dcl_texcoord1 v2 */
7600 0x02000001, 0xc00f0000, 0x90e40000, /* mov o0, v0 */
7601 0x02000001, 0x800f0001, 0x90e40001, /* mov r1, v1 */
7602 0x03000002, 0xd00f0000, 0x80e40001, 0x91e40002, /* sub o1, r1, v2 */
7603 0x0000ffff /* end */
7605 static const DWORD texcoord_color_shader_code_3[] =
7607 0xfffe0300, /* vs_3_0 */
7608 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
7609 0x0200001f, 0x8000000a, 0xe00f0001, /* dcl_color o1 */
7610 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7611 0x0200001f, 0x80000005, 0x900f0001, /* dcl_texcoord v1 */
7612 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
7613 0x02000001, 0xe00f0001, 0x90e40001, /* mov o1, v1 */
7614 0x0000ffff /* end */
7616 static const DWORD texcoord_color_shader_code_2[] =
7618 0xfffe0200, /* vs_2_0 */
7619 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7620 0x0200001f, 0x80000005, 0x900f0001, /* dcl_texcoord v1 */
7621 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
7622 0x02000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
7623 0x0000ffff /* end */
7625 static const DWORD texcoord_color_shader_code_1[] =
7627 0xfffe0101, /* vs_1_1 */
7628 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7629 0x0000001f, 0x80000005, 0x900f0001, /* dcl_texcoord v1 */
7630 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
7631 0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
7632 0x0000ffff /* end */
7634 static const DWORD color_color_shader_code_3[] =
7636 0xfffe0300, /* vs_3_0 */
7637 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
7638 0x0200001f, 0x8000000a, 0xe00f0001, /* dcl_color o1 */
7639 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7640 0x0200001f, 0x8000000a, 0x900f0001, /* dcl_color v1 */
7641 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
7642 0x03000005, 0xe00f0001, 0xa0e40000, 0x90e40001, /* mul o1, c0, v1 */
7643 0x0000ffff /* end */
7645 static const DWORD color_color_shader_code_2[] =
7647 0xfffe0200, /* vs_2_0 */
7648 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7649 0x0200001f, 0x8000000a, 0x900f0001, /* dcl_color v1 */
7650 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
7651 0x03000005, 0xd00f0000, 0xa0e40000, 0x90e40001, /* mul oD0, c0, v1 */
7652 0x0000ffff /* end */
7654 static const DWORD color_color_shader_code_1[] =
7656 0xfffe0101, /* vs_1_1 */
7657 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7658 0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color v1 */
7659 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
7660 0x00000005, 0xd00f0000, 0xa0e40000, 0x90e40001, /* mul oD0, c0, v1 */
7661 0x0000ffff /* end */
7663 static const DWORD ps3_code[] =
7665 0xffff0300, /* ps_3_0 */
7666 0x0200001f, 0x8000000a, 0x900f0000, /* dcl_color0 v0 */
7667 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7668 0x0000ffff /* end */
7670 static const float quad1[] =
7672 -1.0f, -1.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.5f, 0.0f,
7673 -1.0f, 0.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.5f, 0.0f,
7674 0.0f, -1.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.5f, 0.0f,
7675 0.0f, 0.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.5f, 0.0f,
7677 static const float quad2[] =
7679 0.0f, -1.0f, 0.1f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
7680 0.0f, 0.0f, 0.1f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
7681 1.0f, -1.0f, 0.1f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
7682 1.0f, 0.0f, 0.1f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
7684 static const float quad3[] =
7686 -1.0f, 0.0f, 0.1f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f,
7687 -1.0f, 1.0f, 0.1f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f,
7688 0.0f, 0.0f, 0.1f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
7689 0.0f, 1.0f, 0.1f, -1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f,
7691 static const float quad4[] =
7693 0.0f, 0.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.5f, 0.0f,
7694 0.0f, 1.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.5f, 0.0f,
7695 1.0f, 0.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.5f, 0.0f,
7696 1.0f, 1.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.5f, 0.0f,
7698 static const float quad1_modified[] =
7700 -1.0f, -1.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f,
7701 -1.0f, 0.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f,
7702 0.0f, -1.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
7703 0.0f, 0.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, -1.0f, -1.0f, -1.0f, 0.0f,
7705 static const float quad2_modified[] =
7707 0.0f, -1.0f, 0.1f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
7708 0.0f, 0.0f, 0.1f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
7709 1.0f, -1.0f, 0.1f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
7710 1.0f, 0.0f, 0.1f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
7712 static const struct
7714 struct vec3 position;
7715 DWORD diffuse;
7717 quad1_color[] =
7719 {{-1.0f, -1.0f, 0.1f}, 0x00ff8040},
7720 {{-1.0f, 0.0f, 0.1f}, 0x00ff8040},
7721 {{ 0.0f, -1.0f, 0.1f}, 0x00ff8040},
7722 {{ 0.0f, 0.0f, 0.1f}, 0x00ff8040},
7724 quad2_color[] =
7726 {{ 0.0f, -1.0f, 0.1f}, 0x00ff8040},
7727 {{ 0.0f, 0.0f, 0.1f}, 0x00ff8040},
7728 {{ 1.0f, -1.0f, 0.1f}, 0x00ff8040},
7729 {{ 1.0f, 0.0f, 0.1f}, 0x00ff8040},
7731 quad3_color[] =
7733 {{-1.0f, 0.0f, 0.1f}, 0x00ff8040},
7734 {{-1.0f, 1.0f, 0.1f}, 0x00ff8040},
7735 {{ 0.0f, 0.0f, 0.1f}, 0x00ff8040},
7736 {{ 0.0f, 1.0f, 0.1f}, 0x00ff8040},
7738 static const float quad4_color[] =
7740 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 0.0f, 0.0f,
7741 0.0f, 1.0f, 0.1f, 1.0f, 1.0f, 0.0f, 0.0f,
7742 1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 0.0f, 1.0f,
7743 1.0f, 1.0f, 0.1f, 1.0f, 1.0f, 0.0f, 1.0f,
7745 static const struct vec3 quad_nocolor[] =
7747 {-1.0f, -1.0f, 0.1f},
7748 {-1.0f, 1.0f, 0.1f},
7749 { 1.0f, -1.0f, 0.1f},
7750 { 1.0f, 1.0f, 0.1f},
7752 static const D3DVERTEXELEMENT9 decl_elements_twotexcrd[] =
7754 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7755 {0, 12, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
7756 {0, 28, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},
7757 D3DDECL_END()
7759 static const D3DVERTEXELEMENT9 decl_elements_twotexcrd_rightorder[] =
7761 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7762 {0, 12, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},
7763 {0, 28, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
7764 D3DDECL_END()
7766 static const D3DVERTEXELEMENT9 decl_elements_onetexcrd[] =
7768 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7769 {0, 12, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
7770 D3DDECL_END()
7772 static const D3DVERTEXELEMENT9 decl_elements_twotexcrd_wrongidx[] =
7774 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7775 {0, 12, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},
7776 {0, 28, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 2},
7777 D3DDECL_END()
7779 static const D3DVERTEXELEMENT9 decl_elements_texcoord_color[] =
7781 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7782 {0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
7783 D3DDECL_END()
7785 static const D3DVERTEXELEMENT9 decl_elements_color_color[] =
7787 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7788 {0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
7789 D3DDECL_END()
7791 static const D3DVERTEXELEMENT9 decl_elements_color_ubyte[] =
7793 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7794 {0, 12, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
7795 D3DDECL_END()
7797 static const D3DVERTEXELEMENT9 decl_elements_color_float[] =
7799 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7800 {0, 12, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
7801 D3DDECL_END()
7803 static const D3DVERTEXELEMENT9 decl_elements_nocolor[] =
7805 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7806 D3DDECL_END()
7808 static const float normalize[4] = {1.0f / 256.0f, 1.0f / 256.0f, 1.0f / 256.0f, 1.0f / 256.0f};
7809 static const float no_normalize[4] = {1.0f, 1.0f, 1.0f, 1.0f};
7811 window = create_window();
7812 d3d = Direct3DCreate9(D3D_SDK_VERSION);
7813 ok(!!d3d, "Failed to create a D3D object.\n");
7814 if (!(device = create_device(d3d, window, window, TRUE)))
7816 skip("Failed to create a D3D device, skipping tests.\n");
7817 goto done;
7820 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
7821 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
7822 if (caps.VertexShaderVersion < D3DVS_VERSION(3, 0))
7824 skip("No vs_3_0 support, skipping tests.\n");
7825 IDirect3DDevice9_Release(device);
7826 goto done;
7828 if (caps.PixelShaderVersion < D3DPS_VERSION(3, 0))
7830 skip("No ps_3_0 support, skipping tests.\n");
7831 IDirect3DDevice9_Release(device);
7832 goto done;
7835 hr = IDirect3D9_GetAdapterIdentifier(d3d, D3DADAPTER_DEFAULT, 0, &identifier);
7836 ok(SUCCEEDED(hr), "Failed to get adapter identifier, hr %#x.\n", hr);
7837 warp = adapter_is_warp(&identifier);
7839 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_twotexcrd, &decl_twotexcrd);
7840 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
7841 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_onetexcrd, &decl_onetexcrd);
7842 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
7843 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_twotexcrd_wrongidx, &decl_twotex_wrongidx);
7844 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
7845 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_twotexcrd_rightorder, &decl_twotexcrd_rightorder);
7846 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
7848 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_texcoord_color, &decl_texcoord_color);
7849 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
7850 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_color_color, &decl_color_color);
7851 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
7852 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_color_ubyte, &decl_color_ubyte);
7853 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
7854 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_color_float, &decl_color_float);
7855 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
7856 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_nocolor, &decl_nocolor);
7857 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
7859 hr = IDirect3DDevice9_CreatePixelShader(device, ps3_code, &ps);
7860 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
7862 for (i = 1; i <= 3; ++i)
7864 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 1.0f, 0);
7865 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear returned %#x.\n", hr);
7866 if(i == 3) {
7867 hr = IDirect3DDevice9_CreateVertexShader(device, swapped_shader_code_3, &swapped_shader);
7868 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
7869 hr = IDirect3DDevice9_SetPixelShader(device, ps);
7870 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader returned %08x\n", hr);
7871 } else if(i == 2){
7872 hr = IDirect3DDevice9_CreateVertexShader(device, swapped_shader_code_2, &swapped_shader);
7873 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
7874 } else if(i == 1) {
7875 hr = IDirect3DDevice9_CreateVertexShader(device, swapped_shader_code_1, &swapped_shader);
7876 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
7879 hr = IDirect3DDevice9_BeginScene(device);
7880 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
7882 hr = IDirect3DDevice9_SetVertexShader(device, swapped_shader);
7883 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
7885 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl_twotexcrd);
7886 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
7887 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(float) * 11);
7888 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7890 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl_onetexcrd);
7891 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
7892 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(float) * 11);
7893 if (i == 3 || i == 2)
7894 ok(SUCCEEDED(hr), "Failed to draw, i %u, hr %#x.\n", i, hr);
7895 else if (i == 1)
7896 /* Succeeds or fails, depending on SW or HW vertex processing. */
7897 ok(hr == D3DERR_INVALIDCALL || hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7899 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl_twotexcrd_rightorder);
7900 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
7901 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, sizeof(float) * 11);
7902 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7904 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl_twotex_wrongidx);
7905 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
7906 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, sizeof(float) * 11);
7907 if (i == 3 || i == 2)
7908 ok(SUCCEEDED(hr), "Failed to draw, i %u, hr %#x.\n", i, hr);
7909 else if (i == 1)
7910 ok(hr == D3DERR_INVALIDCALL || hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7912 hr = IDirect3DDevice9_EndScene(device);
7913 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
7915 if(i == 3 || i == 2) {
7916 color = getPixelColor(device, 160, 360);
7917 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x80), 1),
7918 "Input test: Quad 1(2crd) returned color 0x%08x, expected 0x00ffff80\n", color);
7920 /* The last value of the read but undefined stream is used, it is 0x00. The defined input is vec4(1, 0, 0, 0) */
7921 color = getPixelColor(device, 480, 360);
7922 /* On the Windows 8 testbot (WARP) the draw succeeds, but uses
7923 * mostly random data as input. */
7924 ok(color == 0x00ffff00 || color == 0x00ff0000 || broken(warp),
7925 "Got unexpected color 0x%08x for quad 2 (1crd).\n", color);
7926 color = getPixelColor(device, 160, 120);
7927 /* Same as above, accept both the last used value and 0.0 for the undefined streams */
7928 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x80), 1) || color == D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x00),
7929 "Input test: Quad 3(2crd-wrongidx) returned color 0x%08x, expected 0x00ff0080\n", color);
7931 color = getPixelColor(device, 480, 160);
7932 ok(color == 0x00000000, "Input test: Quad 4(2crd-rightorder) returned color 0x%08x, expected 0x00000000\n", color);
7933 } else if(i == 1) {
7934 color = getPixelColor(device, 160, 360);
7935 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x80), 1),
7936 "Input test: Quad 1(2crd) returned color 0x%08x, expected 0x00ffff80\n", color);
7937 color = getPixelColor(device, 480, 360);
7938 /* Accept the clear color as well in this case, since SW VP
7939 * returns an error. On the Windows 8 testbot (WARP) the draw
7940 * succeeds, but uses mostly random data as input. */
7941 ok(color == 0x00ffff00 || color == 0x00ff0000 || broken(warp),
7942 "Got unexpected color 0x%08x for quad 2 (1crd).\n", color);
7943 color = getPixelColor(device, 160, 120);
7944 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x80), 1) || color == D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x00),
7945 "Input test: Quad 3(2crd-wrongidx) returned color 0x%08x, expected 0x00ff0080\n", color);
7946 color = getPixelColor(device, 480, 160);
7947 ok(color == 0x00000000, "Input test: Quad 4(2crd-rightorder) returned color 0x%08x, expected 0x00000000\n", color);
7950 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
7951 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
7953 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff808080, 0.0, 0);
7954 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
7956 /* Now find out if the whole streams are re-read, or just the last
7957 * active value for the vertices is used. */
7958 hr = IDirect3DDevice9_BeginScene(device);
7959 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
7961 hr = IDirect3DDevice9_SetVertexShader(device, swapped_shader);
7962 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
7964 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl_twotexcrd);
7965 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
7966 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 3, quad1_modified, sizeof(float) * 11);
7967 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7969 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl_onetexcrd);
7970 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
7971 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2_modified, sizeof(float) * 11);
7972 if (i == 3 || i == 2)
7973 ok(SUCCEEDED(hr), "Failed to draw, i %u, hr %#x.\n", i, hr);
7974 else if (i == 1)
7975 /* Succeeds or fails, depending on SW or HW vertex processing. */
7976 ok(hr == D3DERR_INVALIDCALL || hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7978 hr = IDirect3DDevice9_EndScene(device);
7979 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
7981 color = getPixelColor(device, 480, 350);
7982 /* vs_1_1 may fail, accept the clear color. Some drivers also set the undefined streams to 0, accept that
7983 * as well.
7985 * NOTE: This test fails on the reference rasterizer. In the refrast, the 4 vertices have different colors,
7986 * i.e., the whole old stream is read, and not just the last used attribute. Some games require that this
7987 * does *not* happen, otherwise they can crash because of a read from a bad pointer, so do not accept the
7988 * refrast's result.
7990 * A test app for this behavior is Half Life 2 Episode 2 in dxlevel 95, and related games(Portal, TF2).
7992 ok(color == 0x000000ff || color == 0x00808080 || color == 0x00000000
7993 || broken(color_match(color, D3DCOLOR_ARGB(0x00, 0x0b, 0x75, 0x80), 1)),
7994 "Got unexpected color 0x%08x for quad 2 (different colors).\n", color);
7996 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
7997 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
7999 IDirect3DDevice9_SetVertexShader(device, NULL);
8000 IDirect3DDevice9_SetPixelShader(device, NULL);
8001 IDirect3DDevice9_SetVertexDeclaration(device, NULL);
8003 IDirect3DVertexShader9_Release(swapped_shader);
8006 for (i = 1; i <= 3; ++i)
8008 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
8009 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear returned %#x.\n", hr);
8010 if(i == 3) {
8011 hr = IDirect3DDevice9_CreateVertexShader(device, texcoord_color_shader_code_3, &texcoord_color_shader);
8012 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
8013 hr = IDirect3DDevice9_CreateVertexShader(device, color_color_shader_code_3, &color_color_shader);
8014 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
8015 hr = IDirect3DDevice9_SetPixelShader(device, ps);
8016 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader returned %08x\n", hr);
8017 } else if(i == 2){
8018 hr = IDirect3DDevice9_CreateVertexShader(device, texcoord_color_shader_code_2, &texcoord_color_shader);
8019 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
8020 hr = IDirect3DDevice9_CreateVertexShader(device, color_color_shader_code_2, &color_color_shader);
8021 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
8022 } else if(i == 1) {
8023 hr = IDirect3DDevice9_CreateVertexShader(device, texcoord_color_shader_code_1, &texcoord_color_shader);
8024 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
8025 hr = IDirect3DDevice9_CreateVertexShader(device, color_color_shader_code_1, &color_color_shader);
8026 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
8029 hr = IDirect3DDevice9_BeginScene(device);
8030 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8032 hr = IDirect3DDevice9_SetVertexShader(device, texcoord_color_shader);
8033 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
8034 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl_texcoord_color);
8035 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8036 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1_color, sizeof(quad1_color[0]));
8037 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8039 hr = IDirect3DDevice9_SetVertexShader(device, color_color_shader);
8040 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
8042 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 0, normalize, 1);
8043 ok(SUCCEEDED(hr), "Failed to set vertex shader constant, hr %#x.\n", hr);
8044 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl_color_ubyte);
8045 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8046 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2_color, sizeof(quad2_color[0]));
8047 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8049 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 0, no_normalize, 1);
8050 ok(SUCCEEDED(hr), "Failed to set vertex shader constant, hr %#x.\n", hr);
8051 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl_color_color);
8052 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8053 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3_color, sizeof(quad3_color[0]));
8054 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8056 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl_color_float);
8057 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8058 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4_color, sizeof(float) * 7);
8059 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8061 hr = IDirect3DDevice9_EndScene(device);
8062 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8064 color = getPixelColor(device, 160, 360);
8065 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xff, 0x80, 0x40), 1),
8066 "Input test: Quad 1(color-texcoord) returned color 0x%08x, expected 0x00ff8040\n", color);
8067 color = getPixelColor(device, 480, 360);
8068 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x40, 0x80, 0xff), 1),
8069 "Input test: Quad 2(color-ubyte) returned color 0x%08x, expected 0x004080ff\n", color);
8070 color = getPixelColor(device, 160, 120);
8071 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xff, 0x80, 0x40), 1),
8072 "Input test: Quad 3(color-color) returned color 0x%08x, expected 0x00ff8040\n", color);
8073 color = getPixelColor(device, 480, 160);
8074 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x00), 1),
8075 "Input test: Quad 4(color-float) returned color 0x%08x, expected 0x00ffff00\n", color);
8077 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
8078 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
8080 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl_nocolor);
8081 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8083 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
8084 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
8086 hr = IDirect3DDevice9_BeginScene(device);
8087 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8088 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad_nocolor, sizeof(quad_nocolor[0]));
8089 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8090 hr = IDirect3DDevice9_EndScene(device);
8091 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8093 color = getPixelColor(device, 160, 360);
8094 ok(color_match(color, 0x00000000, 1) || broken(warp),
8095 "Got unexpected color 0x%08x for no color attribute test.\n", color);
8097 IDirect3DDevice9_SetVertexShader(device, NULL);
8098 IDirect3DDevice9_SetVertexDeclaration(device, NULL);
8099 IDirect3DDevice9_SetPixelShader(device, NULL);
8101 IDirect3DVertexShader9_Release(texcoord_color_shader);
8102 IDirect3DVertexShader9_Release(color_color_shader);
8105 IDirect3DVertexDeclaration9_Release(decl_twotexcrd);
8106 IDirect3DVertexDeclaration9_Release(decl_onetexcrd);
8107 IDirect3DVertexDeclaration9_Release(decl_twotex_wrongidx);
8108 IDirect3DVertexDeclaration9_Release(decl_twotexcrd_rightorder);
8110 IDirect3DVertexDeclaration9_Release(decl_texcoord_color);
8111 IDirect3DVertexDeclaration9_Release(decl_color_color);
8112 IDirect3DVertexDeclaration9_Release(decl_color_ubyte);
8113 IDirect3DVertexDeclaration9_Release(decl_color_float);
8114 IDirect3DVertexDeclaration9_Release(decl_nocolor);
8116 IDirect3DPixelShader9_Release(ps);
8117 refcount = IDirect3DDevice9_Release(device);
8118 ok(!refcount, "Device has %u references left.\n", refcount);
8119 done:
8120 IDirect3D9_Release(d3d);
8121 DestroyWindow(window);
8124 static void srgbtexture_test(void)
8126 /* Fill a texture with 0x7f (~ .5), and then turn on the D3DSAMP_SRGBTEXTURE
8127 * texture stage state to render a quad using that texture. The resulting
8128 * color components should be 0x36 (~ 0.21), per this formula:
8129 * linear_color = ((srgb_color + 0.055) / 1.055) ^ 2.4
8130 * This is true where srgb_color > 0.04045. */
8131 struct IDirect3DTexture9 *texture;
8132 struct IDirect3DSurface9 *surface;
8133 IDirect3DDevice9 *device;
8134 IDirect3D9 *d3d;
8135 D3DCOLOR color;
8136 ULONG refcount;
8137 HWND window;
8138 HRESULT hr;
8140 static const float quad[] =
8142 -1.0f, -1.0f, 0.0f, 0.0f, 1.0f,
8143 -1.0f, 1.0f, 0.0f, 0.0f, 0.0f,
8144 1.0f, -1.0f, 0.0f, 1.0f, 1.0f,
8145 1.0f, 1.0f, 0.0f, 1.0f, 0.0f,
8148 window = create_window();
8149 d3d = Direct3DCreate9(D3D_SDK_VERSION);
8150 ok(!!d3d, "Failed to create a D3D object.\n");
8151 if (!(device = create_device(d3d, window, window, TRUE)))
8153 skip("Failed to create a D3D device, skipping tests.\n");
8154 goto done;
8157 if (IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL,
8158 D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_SRGBREAD, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8) != D3D_OK)
8160 skip("D3DFMT_A8R8G8B8 textures with SRGBREAD not supported.\n");
8161 IDirect3DDevice9_Release(device);
8162 goto done;
8165 hr = IDirect3DDevice9_CreateTexture(device, 16, 16, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture, NULL);
8166 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8167 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
8168 ok(hr == D3D_OK, "IDirect3DTexture9_GetSurfaceLevel failed with %08x\n", hr);
8170 fill_surface(surface, 0xff7f7f7f, 0);
8171 IDirect3DSurface9_Release(surface);
8173 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
8174 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
8175 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) texture);
8176 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture failed with %08x\n", hr);
8178 hr = IDirect3DDevice9_BeginScene(device);
8179 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8181 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, TRUE);
8182 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
8183 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
8184 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
8185 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
8186 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8188 hr = IDirect3DDevice9_EndScene(device);
8189 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8191 color = getPixelColor(device, 320, 240);
8192 ok(color_match(color, 0x00363636, 1), "sRGB quad has color 0x%08x, expected 0x00363636.\n", color);
8194 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
8195 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
8197 IDirect3DTexture9_Release(texture);
8198 refcount = IDirect3DDevice9_Release(device);
8199 ok(!refcount, "Device has %u references left.\n", refcount);
8200 done:
8201 IDirect3D9_Release(d3d);
8202 DestroyWindow(window);
8205 static void test_shademode(void)
8207 IDirect3DVertexBuffer9 *vb_strip;
8208 IDirect3DVertexBuffer9 *vb_list;
8209 IDirect3DVertexShader9 *vs;
8210 IDirect3DPixelShader9 *ps;
8211 IDirect3DDevice9 *device;
8212 DWORD color0, color1;
8213 void *data = NULL;
8214 IDirect3D9 *d3d;
8215 ULONG refcount;
8216 D3DCAPS9 caps;
8217 HWND window;
8218 HRESULT hr;
8219 UINT i;
8220 static const DWORD vs1_code[] =
8222 0xfffe0101, /* vs_1_1 */
8223 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
8224 0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
8225 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
8226 0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
8227 0x0000ffff
8229 static const DWORD vs2_code[] =
8231 0xfffe0200, /* vs_2_0 */
8232 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
8233 0x0200001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
8234 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
8235 0x02000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
8236 0x0000ffff
8238 static const DWORD vs3_code[] =
8240 0xfffe0300, /* vs_3_0 */
8241 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
8242 0x0200001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
8243 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
8244 0x0200001f, 0x8000000a, 0xe00f0001, /* dcl_color0 o1 */
8245 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
8246 0x02000001, 0xe00f0001, 0x90e40001, /* mov o1, v1 */
8247 0x0000ffff
8249 static const DWORD ps1_code[] =
8251 0xffff0101, /* ps_1_1 */
8252 0x00000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
8253 0x0000ffff
8255 static const DWORD ps2_code[] =
8257 0xffff0200, /* ps_2_0 */
8258 0x0200001f, 0x80000000, 0x900f0000, /* dcl v0 */
8259 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
8260 0x0000ffff
8262 static const DWORD ps3_code[] =
8264 0xffff0300, /* ps_3_0 */
8265 0x0200001f, 0x8000000a, 0x900f0000, /* dcl_color0 v0 */
8266 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
8267 0x0000ffff
8269 static const struct
8271 struct vec3 position;
8272 DWORD diffuse;
8274 quad_strip[] =
8276 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
8277 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
8278 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
8279 {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
8281 quad_list[] =
8283 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
8284 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
8285 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
8287 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
8288 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
8289 {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
8291 static const struct test_shader
8293 DWORD version;
8294 const DWORD *code;
8296 novs = {0, NULL},
8297 vs_1 = {D3DVS_VERSION(1, 1), vs1_code},
8298 vs_2 = {D3DVS_VERSION(2, 0), vs2_code},
8299 vs_3 = {D3DVS_VERSION(3, 0), vs3_code},
8300 nops = {0, NULL},
8301 ps_1 = {D3DPS_VERSION(1, 1), ps1_code},
8302 ps_2 = {D3DPS_VERSION(2, 0), ps2_code},
8303 ps_3 = {D3DPS_VERSION(3, 0), ps3_code};
8304 static const struct
8306 const struct test_shader *vs, *ps;
8307 DWORD primtype;
8308 DWORD shademode;
8309 DWORD color0, color1;
8310 BOOL todo;
8312 tests[] =
8314 {&novs, &nops, D3DPT_TRIANGLESTRIP, D3DSHADE_FLAT, 0x00ff0000, 0x0000ff00, FALSE},
8315 {&novs, &nops, D3DPT_TRIANGLESTRIP, D3DSHADE_PHONG, 0x000dca28, 0x000d45c7, FALSE},
8316 {&novs, &nops, D3DPT_TRIANGLESTRIP, D3DSHADE_GOURAUD, 0x000dca28, 0x000d45c7, FALSE},
8317 {&novs, &nops, D3DPT_TRIANGLESTRIP, D3DSHADE_PHONG, 0x000dca28, 0x000d45c7, FALSE},
8318 {&novs, &nops, D3DPT_TRIANGLELIST, D3DSHADE_FLAT, 0x00ff0000, 0x000000ff, FALSE},
8319 {&novs, &nops, D3DPT_TRIANGLELIST, D3DSHADE_GOURAUD, 0x000dca28, 0x000d45c7, FALSE},
8320 {&vs_1, &ps_1, D3DPT_TRIANGLESTRIP, D3DSHADE_FLAT, 0x00ff0000, 0x0000ff00, FALSE},
8321 {&vs_1, &ps_1, D3DPT_TRIANGLESTRIP, D3DSHADE_GOURAUD, 0x000dca28, 0x000d45c7, FALSE},
8322 {&vs_1, &ps_1, D3DPT_TRIANGLELIST, D3DSHADE_FLAT, 0x00ff0000, 0x000000ff, FALSE},
8323 {&vs_1, &ps_1, D3DPT_TRIANGLELIST, D3DSHADE_GOURAUD, 0x000dca28, 0x000d45c7, FALSE},
8324 {&novs, &ps_1, D3DPT_TRIANGLESTRIP, D3DSHADE_FLAT, 0x00ff0000, 0x0000ff00, FALSE},
8325 {&vs_1, &nops, D3DPT_TRIANGLESTRIP, D3DSHADE_FLAT, 0x00ff0000, 0x0000ff00, FALSE},
8326 {&vs_2, &ps_2, D3DPT_TRIANGLESTRIP, D3DSHADE_FLAT, 0x00ff0000, 0x0000ff00, FALSE},
8327 {&vs_2, &ps_2, D3DPT_TRIANGLESTRIP, D3DSHADE_GOURAUD, 0x000dca28, 0x000d45c7, FALSE},
8328 {&vs_3, &ps_3, D3DPT_TRIANGLESTRIP, D3DSHADE_FLAT, 0x00ff0000, 0x0000ff00, TRUE},
8329 {&vs_3, &ps_3, D3DPT_TRIANGLESTRIP, D3DSHADE_GOURAUD, 0x000dca28, 0x000d45c7, FALSE},
8332 window = create_window();
8333 d3d = Direct3DCreate9(D3D_SDK_VERSION);
8334 ok(!!d3d, "Failed to create a D3D object.\n");
8335 if (!(device = create_device(d3d, window, window, TRUE)))
8337 skip("Failed to create a D3D device, skipping tests.\n");
8338 goto done;
8341 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
8342 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
8343 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGENABLE, FALSE);
8344 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
8346 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
8347 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
8349 hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(quad_strip), 0, 0, D3DPOOL_MANAGED, &vb_strip, NULL);
8350 ok(hr == D3D_OK, "CreateVertexBuffer failed with %08x\n", hr);
8351 hr = IDirect3DVertexBuffer9_Lock(vb_strip, 0, sizeof(quad_strip), &data, 0);
8352 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr);
8353 memcpy(data, quad_strip, sizeof(quad_strip));
8354 hr = IDirect3DVertexBuffer9_Unlock(vb_strip);
8355 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed with %08x\n", hr);
8357 hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(quad_list), 0, 0, D3DPOOL_MANAGED, &vb_list, NULL);
8358 ok(hr == D3D_OK, "CreateVertexBuffer failed with %08x\n", hr);
8359 hr = IDirect3DVertexBuffer9_Lock(vb_list, 0, sizeof(quad_list), &data, 0);
8360 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr);
8361 memcpy(data, quad_list, sizeof(quad_list));
8362 hr = IDirect3DVertexBuffer9_Unlock(vb_list);
8363 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed with %08x\n", hr);
8365 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
8366 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
8368 /* Try it first with a TRIANGLESTRIP. Do it with different geometry because
8369 * the color fixups we have to do for FLAT shading will be dependent on that. */
8371 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
8373 if (tests[i].vs->version)
8375 if (caps.VertexShaderVersion >= tests[i].vs->version)
8377 hr = IDirect3DDevice9_CreateVertexShader(device, tests[i].vs->code, &vs);
8378 ok(hr == D3D_OK, "Failed to create vertex shader, hr %#x.\n", hr);
8379 hr = IDirect3DDevice9_SetVertexShader(device, vs);
8380 ok(hr == D3D_OK, "Failed to set vertex shader, hr %#x.\n", hr);
8382 else
8384 skip("Shader version unsupported, skipping some tests.\n");
8385 continue;
8388 else
8390 vs = NULL;
8392 if (tests[i].ps->version)
8394 if (caps.PixelShaderVersion >= tests[i].ps->version)
8396 hr = IDirect3DDevice9_CreatePixelShader(device, tests[i].ps->code, &ps);
8397 ok(hr == D3D_OK, "Failed to create pixel shader, hr %#x.\n", hr);
8398 hr = IDirect3DDevice9_SetPixelShader(device, ps);
8399 ok(hr == D3D_OK, "Failed to set pixel shader, hr %#x.\n", hr);
8401 else
8403 skip("Shader version unsupported, skipping some tests.\n");
8404 if (vs)
8406 IDirect3DDevice9_SetVertexShader(device, NULL);
8407 IDirect3DVertexShader9_Release(vs);
8409 continue;
8412 else
8414 ps = NULL;
8417 hr = IDirect3DDevice9_SetStreamSource(device, 0,
8418 tests[i].primtype == D3DPT_TRIANGLESTRIP ? vb_strip : vb_list, 0, sizeof(quad_strip[0]));
8419 ok(hr == D3D_OK, "Failed to set stream source, hr %#x.\n", hr);
8421 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
8422 ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
8424 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SHADEMODE, tests[i].shademode);
8425 ok(hr == D3D_OK, "Failed to set shade mode, hr %#x.\n", hr);
8427 hr = IDirect3DDevice9_BeginScene(device);
8428 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8429 hr = IDirect3DDevice9_DrawPrimitive(device, tests[i].primtype, 0, 2);
8430 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8431 hr = IDirect3DDevice9_EndScene(device);
8432 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8434 color0 = getPixelColor(device, 100, 100); /* Inside first triangle */
8435 color1 = getPixelColor(device, 500, 350); /* Inside second triangle */
8437 /* For D3DSHADE_FLAT it should take the color of the first vertex of
8438 * each triangle. This requires EXT_provoking_vertex or similar
8439 * functionality being available. */
8440 /* PHONG should be the same as GOURAUD, since no hardware implements
8441 * this. */
8442 todo_wine_if (tests[i].todo)
8444 ok(color_match(color0, tests[i].color0, 1), "Test %u shading has color0 %08x, expected %08x.\n",
8445 i, color0, tests[i].color0);
8446 ok(color_match(color1, tests[i].color1, 1), "Test %u shading has color1 %08x, expected %08x.\n",
8447 i, color1, tests[i].color1);
8449 IDirect3DDevice9_SetVertexShader(device, NULL);
8450 IDirect3DDevice9_SetPixelShader(device, NULL);
8452 if (ps)
8453 IDirect3DPixelShader9_Release(ps);
8454 if (vs)
8455 IDirect3DVertexShader9_Release(vs);
8458 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
8459 ok(hr == D3D_OK, "Failed to present, hr %#x.\n", hr);
8461 IDirect3DVertexBuffer9_Release(vb_strip);
8462 IDirect3DVertexBuffer9_Release(vb_list);
8463 refcount = IDirect3DDevice9_Release(device);
8464 ok(!refcount, "Device has %u references left.\n", refcount);
8465 done:
8466 IDirect3D9_Release(d3d);
8467 DestroyWindow(window);
8470 static void test_blend(void)
8472 IDirect3DSurface9 *backbuffer, *offscreen;
8473 IDirect3DTexture9 *offscreenTexture;
8474 IDirect3DDevice9 *device;
8475 IDirect3D9 *d3d;
8476 D3DCOLOR color;
8477 ULONG refcount;
8478 HWND window;
8479 HRESULT hr;
8481 static const struct
8483 struct vec3 position;
8484 DWORD diffuse;
8486 quad1[] =
8488 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
8489 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
8490 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
8491 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
8493 quad2[] =
8495 {{-1.0f, 0.0f, 0.1f}, 0xc00000ff},
8496 {{-1.0f, 1.0f, 0.1f}, 0xc00000ff},
8497 {{ 1.0f, 0.0f, 0.1f}, 0xc00000ff},
8498 {{ 1.0f, 1.0f, 0.1f}, 0xc00000ff},
8500 static const float composite_quad[][5] =
8502 { 0.0f, -1.0f, 0.1f, 0.0f, 1.0f},
8503 { 0.0f, 1.0f, 0.1f, 0.0f, 0.0f},
8504 { 1.0f, -1.0f, 0.1f, 1.0f, 1.0f},
8505 { 1.0f, 1.0f, 0.1f, 1.0f, 0.0f},
8508 window = create_window();
8509 d3d = Direct3DCreate9(D3D_SDK_VERSION);
8510 ok(!!d3d, "Failed to create a D3D object.\n");
8511 if (!(device = create_device(d3d, window, window, TRUE)))
8513 skip("Failed to create a D3D device, skipping tests.\n");
8514 goto done;
8517 /* Clear the render target with alpha = 0.5 */
8518 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x80ff0000, 1.0f, 0);
8519 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
8521 hr = IDirect3DDevice9_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET,
8522 D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &offscreenTexture, NULL);
8523 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8525 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
8526 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
8528 hr = IDirect3DTexture9_GetSurfaceLevel(offscreenTexture, 0, &offscreen);
8529 ok(hr == D3D_OK, "Can't get offscreen surface, hr = %08x\n", hr);
8531 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
8532 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed, hr = %#08x\n", hr);
8534 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
8535 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
8536 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
8537 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
8538 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
8539 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_MINFILTER failed (0x%08x)\n", hr);
8540 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
8541 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr);
8542 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
8543 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
8545 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHABLENDENABLE, TRUE);
8546 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed, hr = %08x\n", hr);
8547 hr = IDirect3DDevice9_BeginScene(device);
8548 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8550 /* Draw two quads, one with src alpha blending, one with dest alpha
8551 * blending. */
8552 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
8553 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8554 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
8555 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8556 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(quad1[0]));
8557 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8559 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_DESTALPHA);
8560 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8561 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVDESTALPHA);
8562 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8563 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(quad2[0]));
8564 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8566 /* Switch to the offscreen buffer, and redo the testing. The offscreen
8567 * render target doesn't have an alpha channel. DESTALPHA and INVDESTALPHA
8568 * "don't work" on render targets without alpha channel, they give
8569 * essentially ZERO and ONE blend factors. */
8570 hr = IDirect3DDevice9_SetRenderTarget(device, 0, offscreen);
8571 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
8572 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x80ff0000, 1.0f, 0);
8573 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
8575 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
8576 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8577 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
8578 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8579 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(quad1[0]));
8580 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8582 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_DESTALPHA);
8583 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8584 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVDESTALPHA);
8585 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8586 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(quad2[0]));
8587 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8589 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
8590 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
8592 /* Render the offscreen texture onto the frame buffer to be able to
8593 * compare it regularly. Disable alpha blending for the final
8594 * composition. */
8595 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHABLENDENABLE, FALSE);
8596 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8597 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
8598 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
8600 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) offscreenTexture);
8601 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
8602 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, composite_quad, sizeof(float) * 5);
8603 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8605 hr = IDirect3DDevice9_EndScene(device);
8606 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8608 color = getPixelColor(device, 160, 360);
8609 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xbf, 0x40, 0x00), 1),
8610 "SRCALPHA on frame buffer returned color %08x, expected 0x00bf4000\n", color);
8612 color = getPixelColor(device, 160, 120);
8613 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x7f, 0x00, 0x80), 2),
8614 "DSTALPHA on frame buffer returned color %08x, expected 0x007f0080\n", color);
8616 color = getPixelColor(device, 480, 360);
8617 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xbf, 0x40, 0x00), 1),
8618 "SRCALPHA on texture returned color %08x, expected 0x00bf4000\n", color);
8620 color = getPixelColor(device, 480, 120);
8621 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0xff), 1),
8622 "DSTALPHA on texture returned color %08x, expected 0x000000ff\n", color);
8624 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
8626 IDirect3DSurface9_Release(backbuffer);
8627 IDirect3DTexture9_Release(offscreenTexture);
8628 IDirect3DSurface9_Release(offscreen);
8629 refcount = IDirect3DDevice9_Release(device);
8630 ok(!refcount, "Device has %u references left.\n", refcount);
8631 done:
8632 IDirect3D9_Release(d3d);
8633 DestroyWindow(window);
8636 static void fixed_function_decl_test(void)
8638 IDirect3DVertexDeclaration9 *dcl_float = NULL, *dcl_short = NULL, *dcl_ubyte = NULL, *dcl_color = NULL;
8639 IDirect3DVertexDeclaration9 *dcl_color_2 = NULL, *dcl_ubyte_2 = NULL, *dcl_nocolor, *dcl_positiont;
8640 IDirect3DVertexBuffer9 *vb, *vb2;
8641 IDirect3DDevice9 *device;
8642 BOOL s_ok, ub_ok, f_ok;
8643 DWORD color, size, i;
8644 IDirect3D9 *d3d;
8645 ULONG refcount;
8646 D3DCAPS9 caps;
8647 HWND window;
8648 void *data;
8649 HRESULT hr;
8651 static const D3DVERTEXELEMENT9 decl_elements_d3dcolor[] = {
8652 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
8653 {0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
8654 D3DDECL_END()
8656 static const D3DVERTEXELEMENT9 decl_elements_d3dcolor_2streams[] = {
8657 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
8658 {1, 0, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
8659 D3DDECL_END()
8661 static const D3DVERTEXELEMENT9 decl_elements_ubyte4n[] = {
8662 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
8663 {0, 12, D3DDECLTYPE_UBYTE4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
8664 D3DDECL_END()
8666 static const D3DVERTEXELEMENT9 decl_elements_ubyte4n_2streams[] = {
8667 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
8668 {1, 0, D3DDECLTYPE_UBYTE4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
8669 D3DDECL_END()
8671 static const D3DVERTEXELEMENT9 decl_elements_short4[] = {
8672 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
8673 {0, 12, D3DDECLTYPE_USHORT4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
8674 D3DDECL_END()
8676 static const D3DVERTEXELEMENT9 decl_elements_float[] = {
8677 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
8678 {0, 12, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
8679 D3DDECL_END()
8681 static const D3DVERTEXELEMENT9 decl_elements_nocolor[] = {
8682 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
8683 D3DDECL_END()
8685 static const D3DVERTEXELEMENT9 decl_elements_positiont[] = {
8686 {0, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITIONT, 0},
8687 {0, 16, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
8688 D3DDECL_END()
8690 static const struct
8692 struct vec3 position;
8693 DWORD diffuse;
8695 quad1[] = /* D3DCOLOR */
8697 {{-1.0f, -1.0f, 0.1f}, 0x00ffff00},
8698 {{-1.0f, 0.0f, 0.1f}, 0x00ffff00},
8699 {{ 0.0f, -1.0f, 0.1f}, 0x00ffff00},
8700 {{ 0.0f, 0.0f, 0.1f}, 0x00ffff00},
8702 quad2[] = /* UBYTE4N */
8704 {{-1.0f, 0.0f, 0.1f}, 0x00ffff00},
8705 {{-1.0f, 1.0f, 0.1f}, 0x00ffff00},
8706 {{ 0.0f, 0.0f, 0.1f}, 0x00ffff00},
8707 {{ 0.0f, 1.0f, 0.1f}, 0x00ffff00},
8709 static const struct
8711 struct vec3 position;
8712 struct { unsigned short x, y, z, w; } color;
8714 quad3[] = /* USHORT4N */
8716 {{0.0f, -1.0f, 0.1f}, {0x0000, 0x0000, 0xffff, 0xffff}},
8717 {{0.0f, 0.0f, 0.1f}, {0x0000, 0x0000, 0xffff, 0xffff}},
8718 {{1.0f, -1.0f, 0.1f}, {0x0000, 0x0000, 0xffff, 0xffff}},
8719 {{1.0f, 0.0f, 0.1f}, {0x0000, 0x0000, 0xffff, 0xffff}},
8721 static const struct
8723 struct vec3 position;
8724 struct vec4 color;
8726 quad4[] =
8728 {{0.0f, 0.0f, 0.1f}, {1.0f, 0.0f, 0.0f, 0.0f}},
8729 {{0.0f, 1.0f, 0.1f}, {1.0f, 0.0f, 0.0f, 0.0f}},
8730 {{1.0f, 0.0f, 0.1f}, {1.0f, 0.0f, 0.0f, 0.0f}},
8731 {{1.0f, 1.0f, 0.1f}, {1.0f, 0.0f, 0.0f, 0.0f}},
8733 static const DWORD colors[] =
8735 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8736 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8737 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8738 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8739 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8740 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8741 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8742 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8743 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8744 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8745 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8746 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8747 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8748 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8749 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8750 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8752 static const float quads[] =
8754 -1.0f, -1.0f, 0.1f,
8755 -1.0f, 0.0f, 0.1f,
8756 0.0f, -1.0f, 0.1f,
8757 0.0f, 0.0f, 0.1f,
8759 0.0f, -1.0f, 0.1f,
8760 0.0f, 0.0f, 0.1f,
8761 1.0f, -1.0f, 0.1f,
8762 1.0f, 0.0f, 0.1f,
8764 0.0f, 0.0f, 0.1f,
8765 0.0f, 1.0f, 0.1f,
8766 1.0f, 0.0f, 0.1f,
8767 1.0f, 1.0f, 0.1f,
8769 -1.0f, 0.0f, 0.1f,
8770 -1.0f, 1.0f, 0.1f,
8771 0.0f, 0.0f, 0.1f,
8772 0.0f, 1.0f, 0.1f,
8774 static const struct
8776 struct vec4 position;
8777 DWORD diffuse;
8779 quad_transformed[] =
8781 {{ 90.0f, 110.0f, 0.1f, 2.0f}, 0x00ffff00},
8782 {{570.0f, 110.0f, 0.1f, 2.0f}, 0x00ffff00},
8783 {{ 90.0f, 300.0f, 0.1f, 2.0f}, 0x00ffff00},
8784 {{570.0f, 300.0f, 0.1f, 2.0f}, 0x00ffff00},
8787 window = create_window();
8788 d3d = Direct3DCreate9(D3D_SDK_VERSION);
8789 ok(!!d3d, "Failed to create a D3D object.\n");
8790 if (!(device = create_device(d3d, window, window, TRUE)))
8792 skip("Failed to create a D3D device, skipping tests.\n");
8793 goto done;
8796 memset(&caps, 0, sizeof(caps));
8797 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
8798 ok(hr == D3D_OK, "GetDeviceCaps failed, hr = %08x\n", hr);
8800 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
8801 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
8803 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_d3dcolor, &dcl_color);
8804 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (%08x)\n", hr);
8805 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_short4, &dcl_short);
8806 ok(SUCCEEDED(hr) || hr == E_FAIL, "CreateVertexDeclaration failed (%08x)\n", hr);
8807 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_float, &dcl_float);
8808 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (%08x)\n", hr);
8809 if(caps.DeclTypes & D3DDTCAPS_UBYTE4N) {
8810 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_ubyte4n_2streams, &dcl_ubyte_2);
8811 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (%08x)\n", hr);
8812 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_ubyte4n, &dcl_ubyte);
8813 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (%08x)\n", hr);
8814 } else {
8815 trace("D3DDTCAPS_UBYTE4N not supported\n");
8816 dcl_ubyte_2 = NULL;
8817 dcl_ubyte = NULL;
8819 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_d3dcolor_2streams, &dcl_color_2);
8820 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (%08x)\n", hr);
8821 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_nocolor, &dcl_nocolor);
8822 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (%08x)\n", hr);
8823 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_positiont, &dcl_positiont);
8824 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (%08x)\n", hr);
8826 size = max(sizeof(quad1), max(sizeof(quad2), max(sizeof(quad3), max(sizeof(quad4), sizeof(quads)))));
8827 hr = IDirect3DDevice9_CreateVertexBuffer(device, size,
8828 0, 0, D3DPOOL_MANAGED, &vb, NULL);
8829 ok(hr == D3D_OK, "CreateVertexBuffer failed with %08x\n", hr);
8831 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
8832 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
8834 hr = IDirect3DDevice9_BeginScene(device);
8835 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8837 f_ok = FALSE; s_ok = FALSE; ub_ok = FALSE;
8838 if (dcl_color)
8840 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_color);
8841 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8842 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(quad1[0]));
8843 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8846 /* Tests with non-standard fixed function types fail on the refrast. The
8847 * ATI driver partially accepts them, the NVIDIA driver accepts them all.
8848 * All those differences even though we're using software vertex
8849 * processing. Doh! */
8850 if (dcl_ubyte)
8852 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_ubyte);
8853 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8854 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(quad2[0]));
8855 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8856 ub_ok = SUCCEEDED(hr);
8859 if (dcl_short)
8861 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_short);
8862 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8863 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, sizeof(quad3[0]));
8864 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8865 s_ok = SUCCEEDED(hr);
8868 if (dcl_float)
8870 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_float);
8871 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8872 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, sizeof(quad4[0]));
8873 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8874 f_ok = SUCCEEDED(hr);
8877 hr = IDirect3DDevice9_EndScene(device);
8878 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8880 if(dcl_short) {
8881 color = getPixelColor(device, 480, 360);
8882 ok(color == 0x000000ff || !s_ok,
8883 "D3DDECLTYPE_USHORT4N returned color %08x, expected 0x000000ff\n", color);
8885 if(dcl_ubyte) {
8886 color = getPixelColor(device, 160, 120);
8887 ok(color == 0x0000ffff || !ub_ok,
8888 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x0000ffff\n", color);
8890 if(dcl_color) {
8891 color = getPixelColor(device, 160, 360);
8892 ok(color == 0x00ffff00,
8893 "D3DDECLTYPE_D3DCOLOR returned color %08x, expected 0x00ffff00\n", color);
8895 if(dcl_float) {
8896 color = getPixelColor(device, 480, 120);
8897 ok(color == 0x00ff0000 || !f_ok,
8898 "D3DDECLTYPE_FLOAT4 returned color %08x, expected 0x00ff0000\n", color);
8900 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
8902 /* The following test with vertex buffers doesn't serve to find out new
8903 * information from windows. It is a plain regression test because wined3d
8904 * uses different codepaths for attribute conversion with vertex buffers.
8905 * It makes sure that the vertex buffer one works, while the above tests
8906 * whether the immediate mode code works. */
8907 f_ok = FALSE; s_ok = FALSE; ub_ok = FALSE;
8908 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
8909 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
8910 hr = IDirect3DDevice9_BeginScene(device);
8911 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8913 if (dcl_color)
8915 hr = IDirect3DVertexBuffer9_Lock(vb, 0, sizeof(quad1), &data, 0);
8916 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8917 memcpy(data, quad1, sizeof(quad1));
8918 hr = IDirect3DVertexBuffer9_Unlock(vb);
8919 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8920 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_color);
8921 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8922 hr = IDirect3DDevice9_SetStreamSource(device, 0, vb, 0, sizeof(quad1[0]));
8923 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
8924 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 2);
8925 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8928 if (dcl_ubyte)
8930 hr = IDirect3DVertexBuffer9_Lock(vb, 0, sizeof(quad2), &data, 0);
8931 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8932 memcpy(data, quad2, sizeof(quad2));
8933 hr = IDirect3DVertexBuffer9_Unlock(vb);
8934 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8935 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_ubyte);
8936 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8937 hr = IDirect3DDevice9_SetStreamSource(device, 0, vb, 0, sizeof(quad2[0]));
8938 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
8939 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 2);
8940 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8941 ub_ok = SUCCEEDED(hr);
8944 if (dcl_short)
8946 hr = IDirect3DVertexBuffer9_Lock(vb, 0, sizeof(quad3), &data, 0);
8947 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8948 memcpy(data, quad3, sizeof(quad3));
8949 hr = IDirect3DVertexBuffer9_Unlock(vb);
8950 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8951 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_short);
8952 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8953 hr = IDirect3DDevice9_SetStreamSource(device, 0, vb, 0, sizeof(quad3[0]));
8954 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
8955 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 2);
8956 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8957 s_ok = SUCCEEDED(hr);
8960 if (dcl_float)
8962 hr = IDirect3DVertexBuffer9_Lock(vb, 0, sizeof(quad4), &data, 0);
8963 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8964 memcpy(data, quad4, sizeof(quad4));
8965 hr = IDirect3DVertexBuffer9_Unlock(vb);
8966 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8967 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_float);
8968 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8969 hr = IDirect3DDevice9_SetStreamSource(device, 0, vb, 0, sizeof(quad4[0]));
8970 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
8971 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 2);
8972 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8973 f_ok = SUCCEEDED(hr);
8976 hr = IDirect3DDevice9_EndScene(device);
8977 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8979 if(dcl_short) {
8980 color = getPixelColor(device, 480, 360);
8981 ok(color == 0x000000ff || !s_ok,
8982 "D3DDECLTYPE_USHORT4N returned color %08x, expected 0x000000ff\n", color);
8984 if(dcl_ubyte) {
8985 color = getPixelColor(device, 160, 120);
8986 ok(color == 0x0000ffff || !ub_ok,
8987 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x0000ffff\n", color);
8989 if(dcl_color) {
8990 color = getPixelColor(device, 160, 360);
8991 ok(color == 0x00ffff00,
8992 "D3DDECLTYPE_D3DCOLOR returned color %08x, expected 0x00ffff00\n", color);
8994 if(dcl_float) {
8995 color = getPixelColor(device, 480, 120);
8996 ok(color == 0x00ff0000 || !f_ok,
8997 "D3DDECLTYPE_FLOAT4 returned color %08x, expected 0x00ff0000\n", color);
8999 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
9001 /* Test with no diffuse color attribute. */
9002 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0, 0);
9003 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
9005 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_nocolor);
9006 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
9007 hr = IDirect3DDevice9_BeginScene(device);
9008 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9009 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quads, sizeof(float) * 3);
9010 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9011 hr = IDirect3DDevice9_EndScene(device);
9012 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9014 color = getPixelColor(device, 160, 360);
9015 ok(color == 0x00ffffff, "Got unexpected color 0x%08x in the no color attribute test.\n", color);
9017 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
9019 /* Test what happens with specular lighting enabled and no specular color attribute. */
9020 f_ok = FALSE; s_ok = FALSE; ub_ok = FALSE;
9021 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
9022 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
9023 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SPECULARENABLE, TRUE);
9024 ok(SUCCEEDED(hr), "Failed to enable specular lighting, hr %#x.\n", hr);
9025 hr = IDirect3DDevice9_BeginScene(device);
9026 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9028 if (dcl_color)
9030 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_color);
9031 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
9032 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(quad1[0]));
9033 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9035 if (dcl_ubyte)
9037 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_ubyte);
9038 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
9039 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(quad2[0]));
9040 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
9041 ub_ok = SUCCEEDED(hr);
9043 if (dcl_short)
9045 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_short);
9046 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
9047 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, sizeof(quad3[0]));
9048 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
9049 s_ok = SUCCEEDED(hr);
9051 if (dcl_float)
9053 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_float);
9054 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
9055 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, sizeof(quad4[0]));
9056 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
9057 f_ok = SUCCEEDED(hr);
9060 hr = IDirect3DDevice9_EndScene(device);
9061 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9062 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SPECULARENABLE, FALSE);
9063 ok(SUCCEEDED(hr), "Failed to disable specular lighting, hr %#x.\n", hr);
9065 if (dcl_short)
9067 color = getPixelColor(device, 480, 360);
9068 ok(color == 0x000000ff || !s_ok,
9069 "D3DDECLTYPE_USHORT4N returned color %08x, expected 0x000000ff.\n", color);
9071 if (dcl_ubyte)
9073 color = getPixelColor(device, 160, 120);
9074 ok(color == 0x0000ffff || !ub_ok,
9075 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x0000ffff.\n", color);
9077 if (dcl_color)
9079 color = getPixelColor(device, 160, 360);
9080 ok(color == 0x00ffff00,
9081 "D3DDECLTYPE_D3DCOLOR returned color %08x, expected 0x00ffff00.\n", color);
9083 if (dcl_float)
9085 color = getPixelColor(device, 480, 120);
9086 ok(color == 0x00ff0000 || !f_ok,
9087 "D3DDECLTYPE_FLOAT4 returned color %08x, expected 0x00ff0000.\n", color);
9089 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
9091 hr = IDirect3DVertexBuffer9_Lock(vb, 0, sizeof(quad_transformed), &data, 0);
9092 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr);
9093 memcpy(data, quad_transformed, sizeof(quad_transformed));
9094 hr = IDirect3DVertexBuffer9_Unlock(vb);
9095 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed (%08x)\n", hr);
9097 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_positiont);
9098 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexDeclaration failed with %08x\n", hr);
9100 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0, 0);
9101 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
9103 hr = IDirect3DDevice9_BeginScene(device);
9104 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9105 hr = IDirect3DDevice9_SetStreamSource(device, 0, vb, 0, sizeof(quad_transformed[0]));
9106 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
9107 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 2);
9108 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9109 hr = IDirect3DDevice9_EndScene(device);
9110 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9112 color = getPixelColor(device, 88, 108);
9113 ok(color == 0x000000ff,
9114 "pixel 88/108 has color %08x, expected 0x000000ff\n", color);
9115 color = getPixelColor(device, 92, 108);
9116 ok(color == 0x000000ff,
9117 "pixel 92/108 has color %08x, expected 0x000000ff\n", color);
9118 color = getPixelColor(device, 88, 112);
9119 ok(color == 0x000000ff,
9120 "pixel 88/112 has color %08x, expected 0x000000ff\n", color);
9121 color = getPixelColor(device, 92, 112);
9122 ok(color == 0x00ffff00,
9123 "pixel 92/112 has color %08x, expected 0x00ffff00\n", color);
9125 color = getPixelColor(device, 568, 108);
9126 ok(color == 0x000000ff,
9127 "pixel 568/108 has color %08x, expected 0x000000ff\n", color);
9128 color = getPixelColor(device, 572, 108);
9129 ok(color == 0x000000ff,
9130 "pixel 572/108 has color %08x, expected 0x000000ff\n", color);
9131 color = getPixelColor(device, 568, 112);
9132 ok(color == 0x00ffff00,
9133 "pixel 568/112 has color %08x, expected 0x00ffff00\n", color);
9134 color = getPixelColor(device, 572, 112);
9135 ok(color == 0x000000ff,
9136 "pixel 572/112 has color %08x, expected 0x000000ff\n", color);
9138 color = getPixelColor(device, 88, 298);
9139 ok(color == 0x000000ff,
9140 "pixel 88/298 has color %08x, expected 0x000000ff\n", color);
9141 color = getPixelColor(device, 92, 298);
9142 ok(color == 0x00ffff00,
9143 "pixel 92/298 has color %08x, expected 0x00ffff00\n", color);
9144 color = getPixelColor(device, 88, 302);
9145 ok(color == 0x000000ff,
9146 "pixel 88/302 has color %08x, expected 0x000000ff\n", color);
9147 color = getPixelColor(device, 92, 302);
9148 ok(color == 0x000000ff,
9149 "pixel 92/302 has color %08x, expected 0x000000ff\n", color);
9151 color = getPixelColor(device, 568, 298);
9152 ok(color == 0x00ffff00,
9153 "pixel 568/298 has color %08x, expected 0x00ffff00\n", color);
9154 color = getPixelColor(device, 572, 298);
9155 ok(color == 0x000000ff,
9156 "pixel 572/298 has color %08x, expected 0x000000ff\n", color);
9157 color = getPixelColor(device, 568, 302);
9158 ok(color == 0x000000ff,
9159 "pixel 568/302 has color %08x, expected 0x000000ff\n", color);
9160 color = getPixelColor(device, 572, 302);
9161 ok(color == 0x000000ff,
9162 "pixel 572/302 has color %08x, expected 0x000000ff\n", color);
9164 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
9166 /* This test is pointless without those two declarations: */
9167 if((!dcl_color_2) || (!dcl_ubyte_2)) {
9168 skip("color-ubyte switching test declarations aren't supported\n");
9169 goto out;
9172 hr = IDirect3DVertexBuffer9_Lock(vb, 0, sizeof(quads), &data, 0);
9173 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr);
9174 memcpy(data, quads, sizeof(quads));
9175 hr = IDirect3DVertexBuffer9_Unlock(vb);
9176 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed (%08x)\n", hr);
9177 hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(colors),
9178 0, 0, D3DPOOL_MANAGED, &vb2, NULL);
9179 ok(hr == D3D_OK, "CreateVertexBuffer failed with %08x\n", hr);
9180 hr = IDirect3DVertexBuffer9_Lock(vb2, 0, sizeof(colors), &data, 0);
9181 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr);
9182 memcpy(data, colors, sizeof(colors));
9183 hr = IDirect3DVertexBuffer9_Unlock(vb2);
9184 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed (%08x)\n", hr);
9186 for(i = 0; i < 2; i++) {
9187 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
9188 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
9190 hr = IDirect3DDevice9_SetStreamSource(device, 0, vb, 0, sizeof(float) * 3);
9191 ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSource failed with %08x\n", hr);
9192 if(i == 0) {
9193 hr = IDirect3DDevice9_SetStreamSource(device, 1, vb2, 0, sizeof(DWORD) * 4);
9194 } else {
9195 hr = IDirect3DDevice9_SetStreamSource(device, 1, vb2, 8, sizeof(DWORD) * 4);
9197 ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSource failed with %08x\n", hr);
9199 hr = IDirect3DDevice9_BeginScene(device);
9200 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9202 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_ubyte_2);
9203 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
9204 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 2);
9205 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
9206 ub_ok = SUCCEEDED(hr);
9208 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_color_2);
9209 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
9210 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 4, 2);
9211 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9213 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_ubyte_2);
9214 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
9215 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 8, 2);
9216 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
9217 ub_ok = (SUCCEEDED(hr) && ub_ok);
9219 hr = IDirect3DDevice9_EndScene(device);
9220 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9222 if(i == 0) {
9223 color = getPixelColor(device, 480, 360);
9224 ok(color == 0x00ff0000,
9225 "D3DDECLTYPE_D3DCOLOR returned color %08x, expected 0x00ff0000\n", color);
9226 color = getPixelColor(device, 160, 120);
9227 ok(color == 0x00ffffff,
9228 "Unused quad returned color %08x, expected 0x00ffffff\n", color);
9229 color = getPixelColor(device, 160, 360);
9230 ok(color == 0x000000ff || !ub_ok,
9231 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x000000ff\n", color);
9232 color = getPixelColor(device, 480, 120);
9233 ok(color == 0x000000ff || !ub_ok,
9234 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x000000ff\n", color);
9235 } else {
9236 color = getPixelColor(device, 480, 360);
9237 ok(color == 0x000000ff,
9238 "D3DDECLTYPE_D3DCOLOR returned color %08x, expected 0x000000ff\n", color);
9239 color = getPixelColor(device, 160, 120);
9240 ok(color == 0x00ffffff,
9241 "Unused quad returned color %08x, expected 0x00ffffff\n", color);
9242 color = getPixelColor(device, 160, 360);
9243 ok(color == 0x00ff0000 || !ub_ok,
9244 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x00ff0000\n", color);
9245 color = getPixelColor(device, 480, 120);
9246 ok(color == 0x00ff0000 || !ub_ok,
9247 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x00ff0000\n", color);
9249 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
9252 IDirect3DVertexBuffer9_Release(vb2);
9253 out:
9254 IDirect3DVertexBuffer9_Release(vb);
9255 if(dcl_float) IDirect3DVertexDeclaration9_Release(dcl_float);
9256 if(dcl_short) IDirect3DVertexDeclaration9_Release(dcl_short);
9257 if(dcl_ubyte) IDirect3DVertexDeclaration9_Release(dcl_ubyte);
9258 if(dcl_color) IDirect3DVertexDeclaration9_Release(dcl_color);
9259 if(dcl_color_2) IDirect3DVertexDeclaration9_Release(dcl_color_2);
9260 if(dcl_ubyte_2) IDirect3DVertexDeclaration9_Release(dcl_ubyte_2);
9261 IDirect3DVertexDeclaration9_Release(dcl_nocolor);
9262 IDirect3DVertexDeclaration9_Release(dcl_positiont);
9263 refcount = IDirect3DDevice9_Release(device);
9264 ok(!refcount, "Device has %u references left.\n", refcount);
9265 done:
9266 IDirect3D9_Release(d3d);
9267 DestroyWindow(window);
9270 static void test_vshader_float16(void)
9272 IDirect3DVertexDeclaration9 *vdecl = NULL;
9273 IDirect3DVertexBuffer9 *buffer = NULL;
9274 IDirect3DVertexShader9 *shader;
9275 IDirect3DDevice9 *device;
9276 IDirect3D9 *d3d;
9277 ULONG refcount;
9278 D3DCAPS9 caps;
9279 DWORD color;
9280 HWND window;
9281 void *data;
9282 HRESULT hr;
9284 static const D3DVERTEXELEMENT9 decl_elements[] =
9286 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
9287 {0, 12, D3DDECLTYPE_FLOAT16_4,D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
9288 D3DDECL_END()
9290 static const DWORD shader_code[] =
9292 0xfffe0101, /* vs_1_1 */
9293 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
9294 0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color v1 */
9295 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
9296 0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
9297 0x0000ffff,
9299 static const struct vertex_float16color
9301 float x, y, z;
9302 DWORD c1, c2;
9304 quad[] =
9306 { -1.0, -1.0, 0.1, 0x3c000000, 0x00000000 }, /* green */
9307 { -1.0, 0.0, 0.1, 0x3c000000, 0x00000000 },
9308 { 0.0, -1.0, 0.1, 0x3c000000, 0x00000000 },
9309 { 0.0, 0.0, 0.1, 0x3c000000, 0x00000000 },
9311 { 0.0, -1.0, 0.1, 0x00003c00, 0x00000000 }, /* red */
9312 { 0.0, 0.0, 0.1, 0x00003c00, 0x00000000 },
9313 { 1.0, -1.0, 0.1, 0x00003c00, 0x00000000 },
9314 { 1.0, 0.0, 0.1, 0x00003c00, 0x00000000 },
9316 { 0.0, 0.0, 0.1, 0x00000000, 0x00003c00 }, /* blue */
9317 { 0.0, 1.0, 0.1, 0x00000000, 0x00003c00 },
9318 { 1.0, 0.0, 0.1, 0x00000000, 0x00003c00 },
9319 { 1.0, 1.0, 0.1, 0x00000000, 0x00003c00 },
9321 { -1.0, 0.0, 0.1, 0x00000000, 0x3c000000 }, /* alpha */
9322 { -1.0, 1.0, 0.1, 0x00000000, 0x3c000000 },
9323 { 0.0, 0.0, 0.1, 0x00000000, 0x3c000000 },
9324 { 0.0, 1.0, 0.1, 0x00000000, 0x3c000000 },
9327 window = create_window();
9328 d3d = Direct3DCreate9(D3D_SDK_VERSION);
9329 ok(!!d3d, "Failed to create a D3D object.\n");
9330 if (!(device = create_device(d3d, window, window, TRUE)))
9332 skip("Failed to create a D3D device, skipping tests.\n");
9333 goto done;
9336 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
9337 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
9338 if (caps.VertexShaderVersion < D3DVS_VERSION(3, 0))
9340 skip("No vs_3_0 support, skipping tests.\n");
9341 IDirect3DDevice9_Release(device);
9342 goto done;
9345 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff102030, 1.0f, 0);
9346 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr);
9348 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &vdecl);
9349 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateVertexDeclaration failed hr=%08x\n", hr);
9350 hr = IDirect3DDevice9_CreateVertexShader(device, shader_code, &shader);
9351 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateVertexShader failed hr=%08x\n", hr);
9352 hr = IDirect3DDevice9_SetVertexShader(device, shader);
9353 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShader failed hr=%08x\n", hr);
9355 hr = IDirect3DDevice9_BeginScene(device);
9356 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9357 hr = IDirect3DDevice9_SetVertexDeclaration(device, vdecl);
9358 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
9359 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad + 0, sizeof(quad[0]));
9360 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9361 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad + 4, sizeof(quad[0]));
9362 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9363 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad + 8, sizeof(quad[0]));
9364 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9365 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad + 12, sizeof(quad[0]));
9366 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9367 hr = IDirect3DDevice9_EndScene(device);
9368 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9370 color = getPixelColor(device, 480, 360);
9371 ok(color == 0x00ff0000,
9372 "Input 0x00003c00, 0x00000000 returned color %08x, expected 0x00ff0000\n", color);
9373 color = getPixelColor(device, 160, 120);
9374 ok(color == 0x00000000,
9375 "Input 0x00000000, 0x3c000000 returned color %08x, expected 0x00000000\n", color);
9376 color = getPixelColor(device, 160, 360);
9377 ok(color == 0x0000ff00,
9378 "Input 0x3c000000, 0x00000000 returned color %08x, expected 0x0000ff00\n", color);
9379 color = getPixelColor(device, 480, 120);
9380 ok(color == 0x000000ff,
9381 "Input 0x00000000, 0x00003c00 returned color %08x, expected 0x000000ff\n", color);
9382 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
9384 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff102030, 0.0, 0);
9385 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr);
9387 hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(quad), 0, 0,
9388 D3DPOOL_MANAGED, &buffer, NULL);
9389 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexBuffer failed, hr=%08x\n", hr);
9390 hr = IDirect3DVertexBuffer9_Lock(buffer, 0, sizeof(quad), &data, 0);
9391 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed, hr=%08x\n", hr);
9392 memcpy(data, quad, sizeof(quad));
9393 hr = IDirect3DVertexBuffer9_Unlock(buffer);
9394 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed, hr=%08x\n", hr);
9395 hr = IDirect3DDevice9_SetStreamSource(device, 0, buffer, 0, sizeof(quad[0]));
9396 ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSource failed, hr=%08x\n", hr);
9398 hr = IDirect3DDevice9_BeginScene(device);
9399 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9400 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 2);
9401 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9402 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 4, 2);
9403 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9404 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 8, 2);
9405 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9406 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 12, 2);
9407 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9408 hr = IDirect3DDevice9_EndScene(device);
9409 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9411 color = getPixelColor(device, 480, 360);
9412 ok(color == 0x00ff0000,
9413 "Input 0x00003c00, 0x00000000 returned color %08x, expected 0x00ff0000\n", color);
9414 color = getPixelColor(device, 160, 120);
9415 ok(color == 0x00000000,
9416 "Input 0x00000000, 0x3c000000 returned color %08x, expected 0x00000000\n", color);
9417 color = getPixelColor(device, 160, 360);
9418 ok(color == 0x0000ff00,
9419 "Input 0x3c000000, 0x00000000 returned color %08x, expected 0x0000ff00\n", color);
9420 color = getPixelColor(device, 480, 120);
9421 ok(color == 0x000000ff,
9422 "Input 0x00000000, 0x00003c00 returned color %08x, expected 0x000000ff\n", color);
9423 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
9425 IDirect3DVertexDeclaration9_Release(vdecl);
9426 IDirect3DVertexShader9_Release(shader);
9427 IDirect3DVertexBuffer9_Release(buffer);
9428 refcount = IDirect3DDevice9_Release(device);
9429 ok(!refcount, "Device has %u references left.\n", refcount);
9430 done:
9431 IDirect3D9_Release(d3d);
9432 DestroyWindow(window);
9435 static void conditional_np2_repeat_test(void)
9437 IDirect3DTexture9 *texture;
9438 IDirect3DDevice9 *device;
9439 D3DLOCKED_RECT rect;
9440 unsigned int x, y;
9441 DWORD *dst, color;
9442 IDirect3D9 *d3d;
9443 ULONG refcount;
9444 D3DCAPS9 caps;
9445 HWND window;
9446 HRESULT hr;
9448 static const float quad[] =
9450 -1.0f, -1.0f, 0.1f, -0.2f, -0.2f,
9451 -1.0f, 1.0f, 0.1f, -0.2f, 1.2f,
9452 1.0f, -1.0f, 0.1f, 1.2f, -0.2f,
9453 1.0f, 1.0f, 0.1f, 1.2f, 1.2f,
9456 window = create_window();
9457 d3d = Direct3DCreate9(D3D_SDK_VERSION);
9458 ok(!!d3d, "Failed to create a D3D object.\n");
9459 if (!(device = create_device(d3d, window, window, TRUE)))
9461 skip("Failed to create a D3D device, skipping tests.\n");
9462 goto done;
9465 memset(&caps, 0, sizeof(caps));
9466 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
9467 ok(hr == D3D_OK, "IDirect3DDevice9_GetDeviceCaps failed hr=%08x\n", hr);
9468 if (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)
9470 /* NP2 conditional requires the POW2 flag. Check that while we're at it */
9471 ok(caps.TextureCaps & D3DPTEXTURECAPS_POW2,
9472 "Card has conditional NP2 support without power of two restriction set\n");
9474 else if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
9476 skip("No conditional NP2 support, skipping conditional NP2 tests\n");
9477 IDirect3DDevice9_Release(device);
9478 goto done;
9480 else
9482 skip("Card has unconditional NP2 support, skipping conditional NP2 tests\n");
9483 IDirect3DDevice9_Release(device);
9484 goto done;
9487 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff000000, 1.0f, 0);
9488 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr);
9490 hr = IDirect3DDevice9_CreateTexture(device, 10, 10, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &texture, NULL);
9491 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture failed hr=%08x\n", hr);
9493 memset(&rect, 0, sizeof(rect));
9494 hr = IDirect3DTexture9_LockRect(texture, 0, &rect, NULL, 0);
9495 ok(hr == D3D_OK, "IDirect3DTexture9_LockRect failed hr=%08x\n", hr);
9496 for(y = 0; y < 10; y++) {
9497 for(x = 0; x < 10; x++) {
9498 dst = (DWORD *) ((BYTE *) rect.pBits + y * rect.Pitch + x * sizeof(DWORD));
9499 if(x == 0 || x == 9 || y == 0 || y == 9) {
9500 *dst = 0x00ff0000;
9501 } else {
9502 *dst = 0x000000ff;
9506 hr = IDirect3DTexture9_UnlockRect(texture, 0);
9507 ok(hr == D3D_OK, "IDirect3DTexture9_UnlockRect failed hr=%08x\n", hr);
9509 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) texture);
9510 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture failed hr=%08x\n", hr);
9511 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
9512 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
9513 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
9514 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState failed hr=%08x\n", hr);
9515 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
9516 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState failed hr=%08x\n", hr);
9517 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
9518 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexDeclaration failed, hr=%08x\n", hr);
9520 hr = IDirect3DDevice9_BeginScene(device);
9521 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9522 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(float) * 5);
9523 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9524 hr = IDirect3DDevice9_EndScene(device);
9525 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9527 color = getPixelColor(device, 1, 1);
9528 ok(color == 0x00ff0000, "NP2: Pixel 1, 1 has color %08x, expected 0x00ff0000\n", color);
9529 color = getPixelColor(device, 639, 479);
9530 ok(color == 0x00ff0000, "NP2: Pixel 639, 479 has color %08x, expected 0x00ff0000\n", color);
9532 color = getPixelColor(device, 135, 101);
9533 ok(color == 0x00ff0000, "NP2: Pixel 135, 101 has color %08x, expected 0x00ff0000\n", color);
9534 color = getPixelColor(device, 140, 101);
9535 ok(color == 0x00ff0000, "NP2: Pixel 140, 101 has color %08x, expected 0x00ff0000\n", color);
9536 color = getPixelColor(device, 135, 105);
9537 ok(color == 0x00ff0000, "NP2: Pixel 135, 105 has color %08x, expected 0x00ff0000\n", color);
9538 color = getPixelColor(device, 140, 105);
9539 ok(color == 0x000000ff, "NP2: Pixel 140, 105 has color %08x, expected 0x000000ff\n", color);
9541 color = getPixelColor(device, 135, 376);
9542 ok(color == 0x00ff0000, "NP2: Pixel 135, 376 has color %08x, expected 0x00ff0000\n", color);
9543 color = getPixelColor(device, 140, 376);
9544 ok(color == 0x000000ff, "NP2: Pixel 140, 376 has color %08x, expected 0x000000ff\n", color);
9545 color = getPixelColor(device, 135, 379);
9546 ok(color == 0x00ff0000, "NP2: Pixel 135, 379 has color %08x, expected 0x00ff0000\n", color);
9547 color = getPixelColor(device, 140, 379);
9548 ok(color == 0x00ff0000, "NP2: Pixel 140, 379 has color %08x, expected 0x00ff0000\n", color);
9550 color = getPixelColor(device, 500, 101);
9551 ok(color == 0x00ff0000, "NP2: Pixel 500, 101 has color %08x, expected 0x00ff0000\n", color);
9552 color = getPixelColor(device, 504, 101);
9553 ok(color == 0x00ff0000, "NP2: Pixel 504, 101 has color %08x, expected 0x00ff0000\n", color);
9554 color = getPixelColor(device, 500, 105);
9555 ok(color == 0x000000ff, "NP2: Pixel 500, 105 has color %08x, expected 0x000000ff\n", color);
9556 color = getPixelColor(device, 504, 105);
9557 ok(color == 0x00ff0000, "NP2: Pixel 504, 105 has color %08x, expected 0x00ff0000\n", color);
9559 color = getPixelColor(device, 500, 376);
9560 ok(color == 0x000000ff, "NP2: Pixel 500, 376 has color %08x, expected 0x000000ff\n", color);
9561 color = getPixelColor(device, 504, 376);
9562 ok(color == 0x00ff0000, "NP2: Pixel 504, 376 has color %08x, expected 0x00ff0000\n", color);
9563 color = getPixelColor(device, 500, 380);
9564 ok(color == 0x00ff0000, "NP2: Pixel 500, 380 has color %08x, expected 0x00ff0000\n", color);
9565 color = getPixelColor(device, 504, 380);
9566 ok(color == 0x00ff0000, "NP2: Pixel 504, 380 has color %08x, expected 0x00ff0000\n", color);
9568 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
9570 IDirect3DTexture9_Release(texture);
9571 refcount = IDirect3DDevice9_Release(device);
9572 ok(!refcount, "Device has %u references left.\n", refcount);
9573 done:
9574 IDirect3D9_Release(d3d);
9575 DestroyWindow(window);
9578 static void vface_register_test(void)
9580 IDirect3DSurface9 *surface, *backbuffer;
9581 IDirect3DVertexShader9 *vshader;
9582 IDirect3DPixelShader9 *shader;
9583 IDirect3DTexture9 *texture;
9584 IDirect3DDevice9 *device;
9585 IDirect3D9 *d3d;
9586 ULONG refcount;
9587 D3DCAPS9 caps;
9588 DWORD color;
9589 HWND window;
9590 HRESULT hr;
9592 static const DWORD shader_code[] =
9594 0xffff0300, /* ps_3_0 */
9595 0x05000051, 0xa00f0000, 0x00000000, 0x3f800000, 0x00000000, 0x00000000, /* def c0, 0.0, 1.0, 0.0, 0.0 */
9596 0x05000051, 0xa00f0001, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c1, 1.0, 0.0, 0.0, 0.0 */
9597 0x0200001f, 0x80000000, 0x900f1001, /* dcl vFace */
9598 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
9599 0x04000058, 0x800f0000, 0x90e41001, 0xa0e40000, 0x80e40001, /* cmp r0, vFace, c0, r1 */
9600 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
9601 0x0000ffff /* END */
9603 static const DWORD vshader_code[] =
9605 0xfffe0300, /* vs_3_0 */
9606 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
9607 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
9608 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
9609 0x0000ffff /* end */
9611 static const float quad[] =
9613 -1.0f, -1.0f, 0.1f,
9614 1.0f, -1.0f, 0.1f,
9615 -1.0f, 0.0f, 0.1f,
9617 1.0f, -1.0f, 0.1f,
9618 1.0f, 0.0f, 0.1f,
9619 -1.0f, 0.0f, 0.1f,
9621 -1.0f, 0.0f, 0.1f,
9622 -1.0f, 1.0f, 0.1f,
9623 1.0f, 0.0f, 0.1f,
9625 1.0f, 0.0f, 0.1f,
9626 -1.0f, 1.0f, 0.1f,
9627 1.0f, 1.0f, 0.1f,
9629 static const float blit[] =
9631 0.0f, -1.0f, 0.1f, 0.0f, 0.0f,
9632 1.0f, -1.0f, 0.1f, 1.0f, 0.0f,
9633 0.0f, 1.0f, 0.1f, 0.0f, 1.0f,
9634 1.0f, 1.0f, 0.1f, 1.0f, 1.0f,
9637 window = create_window();
9638 d3d = Direct3DCreate9(D3D_SDK_VERSION);
9639 ok(!!d3d, "Failed to create a D3D object.\n");
9640 if (!(device = create_device(d3d, window, window, TRUE)))
9642 skip("Failed to create a D3D device, skipping tests.\n");
9643 goto done;
9646 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
9647 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
9648 if (caps.PixelShaderVersion < D3DPS_VERSION(3, 0) || caps.VertexShaderVersion < D3DVS_VERSION(3, 0))
9650 skip("No shader model 3 support, skipping tests.\n");
9651 IDirect3DDevice9_Release(device);
9652 goto done;
9655 hr = IDirect3DDevice9_CreateVertexShader(device, vshader_code, &vshader);
9656 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader failed hr=%08x\n", hr);
9657 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code, &shader);
9658 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader failed hr=%08x\n", hr);
9659 hr = IDirect3DDevice9_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &texture, NULL);
9660 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture failed hr=%08x\n", hr);
9661 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
9662 ok(hr == D3D_OK, "IDirect3DTexture9_GetSurfaceLevel failed hr=%08x\n", hr);
9663 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE);
9664 ok(SUCCEEDED(hr), "Failed to set cull mode, hr %#x.\n", hr);
9665 hr = IDirect3DDevice9_SetPixelShader(device, shader);
9666 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader failed hr=%08x\n", hr);
9667 hr = IDirect3DDevice9_SetVertexShader(device, vshader);
9668 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShader failed hr=%08x\n", hr);
9669 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
9670 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed hr=%08x\n", hr);
9671 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
9672 ok(hr == D3D_OK, "IDirect3DDevice9_GetBackBuffer failed hr=%08x\n", hr);
9674 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
9675 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr);
9677 hr = IDirect3DDevice9_BeginScene(device);
9678 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9680 /* First, draw to the texture and the back buffer to test both offscreen and onscreen cases */
9681 hr = IDirect3DDevice9_SetRenderTarget(device, 0, surface);
9682 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
9683 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0, 0);
9684 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
9685 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLELIST, 4, quad, sizeof(float) * 3);
9686 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9687 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
9688 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
9689 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLELIST, 4, quad, sizeof(float) * 3);
9690 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9692 /* Blit the texture onto the back buffer to make it visible */
9693 hr = IDirect3DDevice9_SetVertexShader(device, NULL);
9694 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
9695 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
9696 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
9697 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) texture);
9698 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
9699 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
9700 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
9701 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
9702 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
9703 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
9704 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
9705 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, blit, sizeof(float) * 5);
9706 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9708 hr = IDirect3DDevice9_EndScene(device);
9709 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9711 color = getPixelColor(device, 160, 360);
9712 ok(color == 0x00ff0000, "vFace: Onscreen rendered front facing quad has color 0x%08x, expected 0x00ff0000\n", color);
9713 color = getPixelColor(device, 160, 120);
9714 ok(color == 0x0000ff00, "vFace: Onscreen rendered back facing quad has color 0x%08x, expected 0x0000ff00\n", color);
9715 color = getPixelColor(device, 480, 360);
9716 ok(color == 0x0000ff00, "vFace: Offscreen rendered back facing quad has color 0x%08x, expected 0x0000ff00\n", color);
9717 color = getPixelColor(device, 480, 120);
9718 ok(color == 0x00ff0000, "vFace: Offscreen rendered front facing quad has color 0x%08x, expected 0x00ff0000\n", color);
9719 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
9720 ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
9722 IDirect3DPixelShader9_Release(shader);
9723 IDirect3DVertexShader9_Release(vshader);
9724 IDirect3DSurface9_Release(surface);
9725 IDirect3DSurface9_Release(backbuffer);
9726 IDirect3DTexture9_Release(texture);
9727 refcount = IDirect3DDevice9_Release(device);
9728 ok(!refcount, "Device has %u references left.\n", refcount);
9729 done:
9730 IDirect3D9_Release(d3d);
9731 DestroyWindow(window);
9734 static void fixed_function_bumpmap_test(void)
9736 IDirect3DVertexDeclaration9 *vertex_declaration;
9737 IDirect3DTexture9 *texture, *tex1, *tex2;
9738 D3DLOCKED_RECT locked_rect;
9739 IDirect3DDevice9 *device;
9740 BOOL L6V5U5_supported;
9741 float scale, offset;
9742 IDirect3D9 *d3d;
9743 unsigned int i;
9744 D3DCOLOR color;
9745 ULONG refcount;
9746 D3DCAPS9 caps;
9747 HWND window;
9748 HRESULT hr;
9750 static const float quad[][7] =
9752 {-1.0f, -1.0f, 0.1f, 0.0f, 0.0f, 0.0f, 0.0f},
9753 {-1.0f, 1.0f, 0.1f, 0.0f, 1.0f, 0.0f, 1.0f},
9754 { 1.0f, -1.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f},
9755 { 1.0f, 1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 1.0f},
9757 static const D3DVERTEXELEMENT9 decl_elements[] =
9759 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
9760 {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
9761 {0, 20, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},
9762 D3DDECL_END()
9764 /* use asymmetric matrix to test loading */
9765 static const float bumpenvmat[4] = {0.0f, 0.5f, -0.5f, 0.0f};
9767 window = create_window();
9768 d3d = Direct3DCreate9(D3D_SDK_VERSION);
9769 ok(!!d3d, "Failed to create a D3D object.\n");
9770 if (!(device = create_device(d3d, window, window, TRUE)))
9772 skip("Failed to create a D3D device, skipping tests.\n");
9773 goto done;
9776 memset(&caps, 0, sizeof(caps));
9777 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
9778 ok(hr == D3D_OK, "IDirect3DDevice9_GetDeviceCaps failed hr=%08x\n", hr);
9779 if (!(caps.TextureOpCaps & D3DTEXOPCAPS_BUMPENVMAP))
9781 skip("D3DTEXOPCAPS_BUMPENVMAP not set, skipping bumpmap tests\n");
9782 IDirect3DDevice9_Release(device);
9783 goto done;
9786 /* This check is disabled, some Windows drivers do not handle
9787 * D3DUSAGE_QUERY_LEGACYBUMPMAP properly. They report that it is not
9788 * supported, but after that bump mapping works properly. So just test if
9789 * the format is generally supported, and check the BUMPENVMAP flag. */
9790 L6V5U5_supported = SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL,
9791 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, D3DFMT_L6V5U5));
9792 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL,
9793 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, D3DFMT_V8U8)))
9795 skip("D3DFMT_V8U8 not supported for legacy bump mapping\n");
9796 IDirect3DDevice9_Release(device);
9797 return;
9800 /* Generate the textures */
9801 generate_bumpmap_textures(device);
9803 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_BUMPENVMAT00, *(LPDWORD)&bumpenvmat[0]);
9804 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9805 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_BUMPENVMAT01, *(LPDWORD)&bumpenvmat[1]);
9806 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9807 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_BUMPENVMAT10, *(LPDWORD)&bumpenvmat[2]);
9808 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9809 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_BUMPENVMAT11, *(LPDWORD)&bumpenvmat[3]);
9810 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9812 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_BUMPENVMAP);
9813 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9814 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
9815 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9816 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_CURRENT );
9817 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9819 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
9820 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9821 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
9822 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9823 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_CURRENT);
9824 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9826 hr = IDirect3DDevice9_SetTextureStageState(device, 2, D3DTSS_COLOROP, D3DTOP_DISABLE);
9827 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9829 hr = IDirect3DDevice9_SetVertexShader(device, NULL);
9830 ok(SUCCEEDED(hr), "SetVertexShader failed (%08x)\n", hr);
9832 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff00ff, 1.0f, 0);
9833 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed (%08x)\n", hr);
9835 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &vertex_declaration);
9836 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (0x%08x)\n", hr);
9837 hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration);
9838 ok(SUCCEEDED(hr), "SetVertexDeclaration failed (0x%08x)\n", hr);
9840 hr = IDirect3DDevice9_BeginScene(device);
9841 ok(SUCCEEDED(hr), "BeginScene failed (0x%08x)\n", hr);
9843 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], sizeof(quad[0]));
9844 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (0x%08x)\n", hr);
9846 hr = IDirect3DDevice9_EndScene(device);
9847 ok(SUCCEEDED(hr), "EndScene failed (0x%08x)\n", hr);
9849 color = getPixelColor(device, 240, 60);
9850 ok(color_match(color, 0x005ea000, 4), "Got unexpected color 0x%08x.\n", color);
9851 color = getPixelColor(device, 400, 60);
9852 ok(color_match(color, 0x009ea000, 4), "Got unexpected color 0x%08x.\n", color);
9853 color = getPixelColor(device, 80, 180);
9854 ok(color_match(color, 0x005ea000, 4), "Got unexpected color 0x%08x.\n", color);
9855 color = getPixelColor(device, 560, 180);
9856 ok(color_match(color, 0x009ea000, 4), "Got unexpected color 0x%08x.\n", color);
9857 color = getPixelColor(device, 80, 300);
9858 ok(color_match(color, 0x005e6000, 4), "Got unexpected color 0x%08x.\n", color);
9859 color = getPixelColor(device, 560, 300);
9860 ok(color_match(color, 0x009e6000, 4), "Got unexpected color 0x%08x.\n", color);
9861 color = getPixelColor(device, 240, 420);
9862 ok(color_match(color, 0x005e6000, 4), "Got unexpected color 0x%08x.\n", color);
9863 color = getPixelColor(device, 400, 420);
9864 ok(color_match(color, 0x009e6000, 4), "Got unexpected color 0x%08x.\n", color);
9865 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
9866 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
9868 for(i = 0; i < 2; i++) {
9869 hr = IDirect3DDevice9_GetTexture(device, i, (IDirect3DBaseTexture9 **) &texture);
9870 ok(SUCCEEDED(hr), "IDirect3DDevice9_GetTexture failed (0x%08x)\n", hr);
9871 IDirect3DTexture9_Release(texture); /* For the GetTexture */
9872 hr = IDirect3DDevice9_SetTexture(device, i, NULL);
9873 ok(SUCCEEDED(hr), "SetTexture failed (0x%08x)\n", hr);
9874 IDirect3DTexture9_Release(texture); /* To destroy it */
9877 if (!L6V5U5_supported || !(caps.TextureOpCaps & D3DTEXOPCAPS_BUMPENVMAPLUMINANCE))
9879 skip("L6V5U5 / D3DTOP_BUMPENVMAPLUMINANCE not supported, skipping tests.\n");
9880 IDirect3DVertexDeclaration9_Release(vertex_declaration);
9881 IDirect3DDevice9_Release(device);
9882 goto done;
9885 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
9886 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
9887 /* This test only tests the luminance part. The bumpmapping part was already tested above and
9888 * would only make this test more complicated
9890 hr = IDirect3DDevice9_CreateTexture(device, 1, 1, 1, 0, D3DFMT_L6V5U5, D3DPOOL_MANAGED, &tex1, NULL);
9891 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture failed, hr=%08x\n", hr);
9892 hr = IDirect3DDevice9_CreateTexture(device, 1, 1, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &tex2, NULL);
9893 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture failed, hr=%08x\n", hr);
9895 memset(&locked_rect, 0, sizeof(locked_rect));
9896 hr = IDirect3DTexture9_LockRect(tex1, 0, &locked_rect, NULL, 0);
9897 ok(SUCCEEDED(hr), "LockRect failed with 0x%08x\n", hr);
9898 *((DWORD *)locked_rect.pBits) = 0x4000; /* L = 0.25, V = 0.0, U = 0.0 */
9899 hr = IDirect3DTexture9_UnlockRect(tex1, 0);
9900 ok(SUCCEEDED(hr), "UnlockRect failed with 0x%08x\n", hr);
9902 memset(&locked_rect, 0, sizeof(locked_rect));
9903 hr = IDirect3DTexture9_LockRect(tex2, 0, &locked_rect, NULL, 0);
9904 ok(SUCCEEDED(hr), "LockRect failed with 0x%08x\n", hr);
9905 *((DWORD *)locked_rect.pBits) = 0x00ff80c0;
9906 hr = IDirect3DTexture9_UnlockRect(tex2, 0);
9907 ok(SUCCEEDED(hr), "UnlockRect failed with 0x%08x\n", hr);
9909 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) tex1);
9910 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTexture failed (%08x)\n", hr);
9911 hr = IDirect3DDevice9_SetTexture(device, 1, (IDirect3DBaseTexture9 *) tex2);
9912 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTexture failed (%08x)\n", hr);
9914 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_BUMPENVMAPLUMINANCE);
9915 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9916 scale = 2.0;
9917 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_BUMPENVLSCALE, *((DWORD *)&scale));
9918 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9919 offset = 0.1;
9920 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_BUMPENVLOFFSET, *((DWORD *)&offset));
9921 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9923 hr = IDirect3DDevice9_BeginScene(device);
9924 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9925 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], sizeof(quad[0]));
9926 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9927 hr = IDirect3DDevice9_EndScene(device);
9928 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9930 color = getPixelColor(device, 320, 240);
9931 /* red: 1.0 * (0.25 * 2.0 + 0.1) = 1.0 * 0.6 = 0.6 = 0x99
9932 * green: 0.5 * (0.25 * 2.0 + 0.1) = 0.5 * 0.6 = 0.3 = 0x4c
9933 * green: 0.75 * (0.25 * 2.0 + 0.1) = 0.75 * 0.6 = 0.45 = 0x72
9935 ok(color_match(color, 0x00994c72, 5), "bumpmap failed: Got color 0x%08x, expected 0x00994c72.\n", color);
9936 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
9937 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
9939 /* Check a result scale factor > 1.0 */
9940 scale = 10;
9941 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_BUMPENVLSCALE, *((DWORD *)&scale));
9942 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9943 offset = 10;
9944 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_BUMPENVLOFFSET, *((DWORD *)&offset));
9945 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9947 hr = IDirect3DDevice9_BeginScene(device);
9948 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9949 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], sizeof(quad[0]));
9950 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9951 hr = IDirect3DDevice9_EndScene(device);
9952 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9954 color = getPixelColor(device, 320, 240);
9955 ok(color_match(color, 0x00ff80c0, 1), "bumpmap failed: Got color 0x%08x, expected 0x00ff80c0.\n", color);
9956 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
9957 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
9959 /* Check clamping in the scale factor calculation */
9960 scale = 1000;
9961 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_BUMPENVLSCALE, *((DWORD *)&scale));
9962 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9963 offset = -1;
9964 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_BUMPENVLOFFSET, *((DWORD *)&offset));
9965 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9967 hr = IDirect3DDevice9_BeginScene(device);
9968 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9969 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], sizeof(quad[0]));
9970 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9971 hr = IDirect3DDevice9_EndScene(device);
9972 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9974 color = getPixelColor(device, 320, 240);
9975 ok(color_match(color, 0x00ff80c0, 1), "bumpmap failed: Got color 0x%08x, expected 0x00ff80c0.\n", color);
9976 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
9977 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
9979 IDirect3DTexture9_Release(tex1);
9980 IDirect3DTexture9_Release(tex2);
9981 IDirect3DVertexDeclaration9_Release(vertex_declaration);
9982 refcount = IDirect3DDevice9_Release(device);
9983 ok(!refcount, "Device has %u references left.\n", refcount);
9984 done:
9985 IDirect3D9_Release(d3d);
9986 DestroyWindow(window);
9989 static void stencil_cull_test(void)
9991 IDirect3DDevice9 *device;
9992 IDirect3D9 *d3d;
9993 ULONG refcount;
9994 D3DCAPS9 caps;
9995 HWND window;
9996 HRESULT hr;
9997 static const float quad1[] =
9999 -1.0, -1.0, 0.1,
10000 0.0, -1.0, 0.1,
10001 -1.0, 0.0, 0.1,
10002 0.0, 0.0, 0.1,
10004 static const float quad2[] =
10006 0.0, -1.0, 0.1,
10007 1.0, -1.0, 0.1,
10008 0.0, 0.0, 0.1,
10009 1.0, 0.0, 0.1,
10011 static const float quad3[] =
10013 0.0, 0.0, 0.1,
10014 1.0, 0.0, 0.1,
10015 0.0, 1.0, 0.1,
10016 1.0, 1.0, 0.1,
10018 static const float quad4[] =
10020 -1.0, 0.0, 0.1,
10021 0.0, 0.0, 0.1,
10022 -1.0, 1.0, 0.1,
10023 0.0, 1.0, 0.1,
10025 struct
10027 struct vec3 position;
10028 DWORD diffuse;
10030 painter[] =
10032 {{-1.0f, -1.0f, 0.0f}, 0x00000000},
10033 {{ 1.0f, -1.0f, 0.0f}, 0x00000000},
10034 {{-1.0f, 1.0f, 0.0f}, 0x00000000},
10035 {{ 1.0f, 1.0f, 0.0f}, 0x00000000},
10037 static const WORD indices_cw[] = {0, 1, 3};
10038 static const WORD indices_ccw[] = {0, 2, 3};
10039 unsigned int i;
10040 DWORD color;
10042 window = create_window();
10043 d3d = Direct3DCreate9(D3D_SDK_VERSION);
10044 ok(!!d3d, "Failed to create a D3D object.\n");
10045 if (!(device = create_device(d3d, window, window, TRUE)))
10047 skip("Cannot create a device with a D24S8 stencil buffer.\n");
10048 DestroyWindow(window);
10049 IDirect3D9_Release(d3d);
10050 return;
10052 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
10053 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
10054 if (!(caps.StencilCaps & D3DSTENCILCAPS_TWOSIDED))
10056 skip("No two sided stencil support\n");
10057 goto cleanup;
10060 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_STENCIL, 0x00ff0000, 0.0, 0x8);
10061 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
10062 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
10063 ok(SUCCEEDED(hr), "Failed to set FVF,hr %#x.\n", hr);
10065 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
10066 ok(hr == D3D_OK, "Failed to disable Z test, %#x.\n", hr);
10067 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
10068 ok(hr == D3D_OK, "Failed to disable lighting, %#x.\n", hr);
10069 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILFAIL, D3DSTENCILOP_INCR);
10070 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
10071 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILZFAIL, D3DSTENCILOP_DECR);
10072 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
10073 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE);
10074 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
10075 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILREF, 0x3);
10076 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
10078 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CCW_STENCILFAIL, D3DSTENCILOP_REPLACE);
10079 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
10080 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CCW_STENCILZFAIL, D3DSTENCILOP_DECR);
10081 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
10082 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CCW_STENCILPASS, D3DSTENCILOP_INCR);
10083 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
10085 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILENABLE, TRUE);
10086 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
10087 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TWOSIDEDSTENCILMODE, FALSE);
10088 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
10090 /* First pass: Fill the stencil buffer with some values... */
10091 hr = IDirect3DDevice9_BeginScene(device);
10092 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10094 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_CW);
10095 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10096 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
10097 1 /* PrimCount */, indices_cw, D3DFMT_INDEX16, quad1, sizeof(float) * 3);
10098 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10099 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
10100 1 /* PrimCount */, indices_ccw, D3DFMT_INDEX16, quad1, sizeof(float) * 3);
10101 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10103 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TWOSIDEDSTENCILMODE, TRUE);
10104 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10105 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE);
10106 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10107 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
10108 1 /* PrimCount */, indices_cw, D3DFMT_INDEX16, quad2, sizeof(float) * 3);
10109 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10110 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
10111 1 /* PrimCount */, indices_ccw, D3DFMT_INDEX16, quad2, sizeof(float) * 3);
10112 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10114 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_CW);
10115 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10116 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
10117 1 /* PrimCount */, indices_cw, D3DFMT_INDEX16, quad3, sizeof(float) * 3);
10118 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10119 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
10120 1 /* PrimCount */, indices_ccw, D3DFMT_INDEX16, quad3, sizeof(float) * 3);
10121 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10123 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_CCW);
10124 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10125 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
10126 1 /* PrimCount */, indices_cw, D3DFMT_INDEX16, quad4, sizeof(float) * 3);
10127 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10128 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
10129 1 /* PrimCount */, indices_ccw, D3DFMT_INDEX16, quad4, sizeof(float) * 3);
10130 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10132 hr = IDirect3DDevice9_EndScene(device);
10133 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10135 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP);
10136 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
10137 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
10138 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
10139 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);
10140 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
10141 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TWOSIDEDSTENCILMODE, FALSE);
10142 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
10143 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE);
10144 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
10145 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILFUNC, D3DCMP_EQUAL);
10146 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
10148 /* 2nd pass: Make the stencil values visible */
10149 hr = IDirect3DDevice9_BeginScene(device);
10150 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10151 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
10152 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
10153 for (i = 0; i < 16; ++i)
10155 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILREF, i);
10156 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10158 painter[0].diffuse = (i * 16); /* Creates shades of blue */
10159 painter[1].diffuse = (i * 16);
10160 painter[2].diffuse = (i * 16);
10161 painter[3].diffuse = (i * 16);
10162 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, painter, sizeof(painter[0]));
10163 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10165 hr = IDirect3DDevice9_EndScene(device);
10166 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10168 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILENABLE, FALSE);
10169 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
10171 color = getPixelColor(device, 160, 420);
10172 ok(color == 0x00000030, "CCW triangle, twoside FALSE, cull cw, replace, has color 0x%08x, expected 0x00000030\n", color);
10173 color = getPixelColor(device, 160, 300);
10174 ok(color == 0x00000080, "CW triangle, twoside FALSE, cull cw, culled, has color 0x%08x, expected 0x00000080\n", color);
10176 color = getPixelColor(device, 480, 420);
10177 ok(color == 0x00000090, "CCW triangle, twoside TRUE, cull off, incr, has color 0x%08x, expected 0x00000090\n", color);
10178 color = getPixelColor(device, 480, 300);
10179 ok(color == 0x00000030, "CW triangle, twoside TRUE, cull off, replace, has color 0x%08x, expected 0x00000030\n", color);
10181 color = getPixelColor(device, 160, 180);
10182 ok(color == 0x00000080, "CCW triangle, twoside TRUE, cull ccw, culled, has color 0x%08x, expected 0x00000080\n", color);
10183 color = getPixelColor(device, 160, 60);
10184 ok(color == 0x00000030, "CW triangle, twoside TRUE, cull ccw, replace, has color 0x%08x, expected 0x00000030\n", color);
10186 color = getPixelColor(device, 480, 180);
10187 ok(color == 0x00000090, "CCW triangle, twoside TRUE, cull cw, incr, has color 0x%08x, expected 0x00000090\n", color);
10188 color = getPixelColor(device, 480, 60);
10189 ok(color == 0x00000080, "CW triangle, twoside TRUE, cull cw, culled, has color 0x%08x, expected 0x00000080\n", color);
10191 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
10192 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
10194 cleanup:
10195 refcount = IDirect3DDevice9_Release(device);
10196 ok(!refcount, "Device has %u references left.\n", refcount);
10197 IDirect3D9_Release(d3d);
10198 DestroyWindow(window);
10201 static void test_fragment_coords(void)
10203 IDirect3DSurface9 *surface = NULL, *backbuffer;
10204 IDirect3DPixelShader9 *shader, *shader_frac;
10205 IDirect3DVertexShader9 *vshader;
10206 IDirect3DDevice9 *device;
10207 D3DLOCKED_RECT lr;
10208 IDirect3D9 *d3d;
10209 ULONG refcount;
10210 D3DCAPS9 caps;
10211 DWORD color;
10212 HWND window;
10213 HRESULT hr;
10214 DWORD *pos;
10216 static const DWORD shader_code[] =
10218 0xffff0300, /* ps_3_0 */
10219 0x0200001f, 0x80000000, 0x90031000, /* dcl vPos.xy */
10220 0x03000002, 0x80030000, 0x90541000, 0xa1fe0000, /* sub r0.xy, vPos.xy, c0.zw */
10221 0x02000001, 0x800f0001, 0xa0e40000, /* mov r1, c0 */
10222 0x02000001, 0x80080002, 0xa0550000, /* mov r2.a, c0.y */
10223 0x02000001, 0x80010002, 0xa0550000, /* mov r2.r, c0.y */
10224 0x04000058, 0x80020002, 0x80000000, 0x80000001, 0x80550001, /* cmp r2.g, r0.x, r1.x, r1.y */
10225 0x04000058, 0x80040002, 0x80550000, 0x80000001, 0x80550001, /* cmp r2.b, r0.y, r1.x, r1.y */
10226 0x02000001, 0x800f0800, 0x80e40002, /* mov oC0, r2 */
10227 0x0000ffff /* end */
10229 static const DWORD shader_frac_code[] =
10231 0xffff0300, /* ps_3_0 */
10232 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 0.0, 0.0, 0.0, 0.0 */
10233 0x0200001f, 0x80000000, 0x90031000, /* dcl vPos.xy */
10234 0x02000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
10235 0x02000013, 0x80030000, 0x90541000, /* frc r0.xy, vPos.xy */
10236 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
10237 0x0000ffff /* end */
10239 static const DWORD vshader_code[] =
10241 0xfffe0300, /* vs_3_0 */
10242 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
10243 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
10244 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
10245 0x0000ffff /* end */
10247 static const float quad[] =
10249 -1.0f, -1.0f, 0.1f, 0.0f, 0.0f,
10250 -1.0f, 1.0f, 0.1f, 0.0f, 1.0f,
10251 1.0f, -1.0f, 0.1f, 1.0f, 0.0f,
10252 1.0f, 1.0f, 0.1f, 1.0f, 1.0f,
10254 float constant[4] = {1.0, 0.0, 320, 240};
10256 window = create_window();
10257 d3d = Direct3DCreate9(D3D_SDK_VERSION);
10258 ok(!!d3d, "Failed to create a D3D object.\n");
10259 if (!(device = create_device(d3d, window, window, TRUE)))
10261 skip("Failed to create a D3D device, skipping tests.\n");
10262 goto done;
10265 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
10266 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
10267 if (caps.PixelShaderVersion < D3DPS_VERSION(3, 0) || caps.VertexShaderVersion < D3DVS_VERSION(3, 0))
10269 skip("No shader model 3 support, skipping tests.\n");
10270 IDirect3DDevice9_Release(device);
10271 goto done;
10274 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
10275 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr);
10276 hr = IDirect3DDevice9_CreateVertexShader(device, vshader_code, &vshader);
10277 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader failed hr=%08x\n", hr);
10278 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code, &shader);
10279 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader failed hr=%08x\n", hr);
10280 hr = IDirect3DDevice9_CreatePixelShader(device, shader_frac_code, &shader_frac);
10281 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader failed hr=%08x\n", hr);
10282 hr = IDirect3DDevice9_SetPixelShader(device, shader);
10283 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader failed hr=%08x\n", hr);
10284 hr = IDirect3DDevice9_SetVertexShader(device, vshader);
10285 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShader failed hr=%08x\n", hr);
10286 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
10287 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed hr=%08x\n", hr);
10288 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
10289 ok(hr == D3D_OK, "IDirect3DDevice9_GetBackBuffer failed hr=%08x\n", hr);
10291 hr = IDirect3DDevice9_BeginScene(device);
10292 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10293 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 0, constant, 1);
10294 ok(SUCCEEDED(hr), "Failed to set pixel shader constant, hr %#x.\n", hr);
10295 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(float) * 5);
10296 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10297 hr = IDirect3DDevice9_EndScene(device);
10298 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10300 /* This has to be pixel exact */
10301 color = getPixelColor(device, 319, 239);
10302 ok(color == 0x00000000, "vPos: Pixel 319,239 has color 0x%08x, expected 0x00000000\n", color);
10303 color = getPixelColor(device, 320, 239);
10304 ok(color == 0x0000ff00, "vPos: Pixel 320,239 has color 0x%08x, expected 0x0000ff00\n", color);
10305 color = getPixelColor(device, 319, 240);
10306 ok(color == 0x000000ff, "vPos: Pixel 319,240 has color 0x%08x, expected 0x000000ff\n", color);
10307 color = getPixelColor(device, 320, 240);
10308 ok(color == 0x0000ffff, "vPos: Pixel 320,240 has color 0x%08x, expected 0x0000ffff\n", color);
10309 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
10311 hr = IDirect3DDevice9_CreateRenderTarget(device, 32, 32, D3DFMT_X8R8G8B8, 0, 0, TRUE,
10312 &surface, NULL);
10313 ok(hr == D3D_OK, "IDirect3DDevice9_CreateRenderTarget failed hr=%08x\n", hr);
10314 hr = IDirect3DDevice9_BeginScene(device);
10315 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10316 constant[2] = 16; constant[3] = 16;
10317 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 0, constant, 1);
10318 ok(SUCCEEDED(hr), "Failed to set pixel shader constant, hr %#x.\n", hr);
10319 hr = IDirect3DDevice9_SetRenderTarget(device, 0, surface);
10320 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
10321 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(float) * 5);
10322 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10323 hr = IDirect3DDevice9_EndScene(device);
10324 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10326 hr = IDirect3DSurface9_LockRect(surface, &lr, NULL, D3DLOCK_READONLY);
10327 ok(hr == D3D_OK, "IDirect3DSurface9_LockRect failed, hr=%08x\n", hr);
10329 pos = (DWORD *) (((BYTE *) lr.pBits) + 14 * lr.Pitch + 14 * sizeof(DWORD));
10330 color = *pos & 0x00ffffff;
10331 ok(color == 0x00000000, "Pixel 14/14 has color 0x%08x, expected 0x00000000\n", color);
10332 pos = (DWORD *) (((BYTE *) lr.pBits) + 14 * lr.Pitch + 18 * sizeof(DWORD));
10333 color = *pos & 0x00ffffff;
10334 ok(color == 0x0000ff00, "Pixel 14/18 has color 0x%08x, expected 0x0000ff00\n", color);
10335 pos = (DWORD *) (((BYTE *) lr.pBits) + 18 * lr.Pitch + 14 * sizeof(DWORD));
10336 color = *pos & 0x00ffffff;
10337 ok(color == 0x000000ff, "Pixel 18/14 has color 0x%08x, expected 0x000000ff\n", color);
10338 pos = (DWORD *) (((BYTE *) lr.pBits) + 18 * lr.Pitch + 18 * sizeof(DWORD));
10339 color = *pos & 0x00ffffff;
10340 ok(color == 0x0000ffff, "Pixel 18/18 has color 0x%08x, expected 0x0000ffff\n", color);
10342 hr = IDirect3DSurface9_UnlockRect(surface);
10343 ok(hr == D3D_OK, "IDirect3DSurface9_UnlockRect failed, hr=%08x\n", hr);
10345 /* Test the fraction value of vPos. This is tested with the offscreen target and not the backbuffer to
10346 * have full control over the multisampling setting inside this test
10348 hr = IDirect3DDevice9_SetPixelShader(device, shader_frac);
10349 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader failed hr=%08x\n", hr);
10350 hr = IDirect3DDevice9_BeginScene(device);
10351 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10352 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0, 0);
10353 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
10354 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(float) * 5);
10355 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10356 hr = IDirect3DDevice9_EndScene(device);
10357 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10359 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
10360 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderTarget failed, hr=%08x\n", hr);
10362 hr = IDirect3DSurface9_LockRect(surface, &lr, NULL, D3DLOCK_READONLY);
10363 ok(hr == D3D_OK, "IDirect3DSurface9_LockRect failed, hr=%08x\n", hr);
10365 pos = (DWORD *) (((BYTE *) lr.pBits) + 14 * lr.Pitch + 14 * sizeof(DWORD));
10366 color = *pos & 0x00ffffff;
10367 ok(color == 0x00000000, "vPos fraction test has color 0x%08x, expected 0x00000000\n", color);
10369 hr = IDirect3DSurface9_UnlockRect(surface);
10370 ok(hr == D3D_OK, "IDirect3DSurface9_UnlockRect failed, hr=%08x\n", hr);
10372 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
10373 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader failed hr=%08x\n", hr);
10374 hr = IDirect3DDevice9_SetVertexShader(device, NULL);
10375 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShader failed hr=%08x\n", hr);
10376 IDirect3DPixelShader9_Release(shader);
10377 IDirect3DPixelShader9_Release(shader_frac);
10378 IDirect3DVertexShader9_Release(vshader);
10379 if(surface) IDirect3DSurface9_Release(surface);
10380 IDirect3DSurface9_Release(backbuffer);
10381 refcount = IDirect3DDevice9_Release(device);
10382 ok(!refcount, "Device has %u references left.\n", refcount);
10383 done:
10384 IDirect3D9_Release(d3d);
10385 DestroyWindow(window);
10388 static BOOL point_match(IDirect3DDevice9 *device, UINT x, UINT y, UINT r)
10390 D3DCOLOR color;
10392 color = D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0xff);
10393 if (!color_match(getPixelColor(device, x + r, y), color, 1)) return FALSE;
10394 if (!color_match(getPixelColor(device, x - r, y), color, 1)) return FALSE;
10395 if (!color_match(getPixelColor(device, x, y + r), color, 1)) return FALSE;
10396 if (!color_match(getPixelColor(device, x, y - r), color, 1)) return FALSE;
10398 ++r;
10399 color = D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0xff);
10400 if (!color_match(getPixelColor(device, x + r, y), color, 1)) return FALSE;
10401 if (!color_match(getPixelColor(device, x - r, y), color, 1)) return FALSE;
10402 if (!color_match(getPixelColor(device, x, y + r), color, 1)) return FALSE;
10403 if (!color_match(getPixelColor(device, x, y - r), color, 1)) return FALSE;
10405 return TRUE;
10408 static void test_pointsize(void)
10410 static const float a = 1.0f, b = 1.0f, c = 1.0f;
10411 float ptsize, ptsizemax_orig, ptsizemin_orig;
10412 IDirect3DSurface9 *rt, *backbuffer;
10413 IDirect3DTexture9 *tex1, *tex2;
10414 IDirect3DDevice9 *device;
10415 IDirect3DVertexShader9 *vs;
10416 IDirect3DPixelShader9 *ps;
10417 D3DLOCKED_RECT lr;
10418 IDirect3D9 *d3d;
10419 D3DCOLOR color;
10420 ULONG refcount;
10421 D3DCAPS9 caps;
10422 HWND window;
10423 HRESULT hr;
10424 unsigned int i, j;
10426 static const RECT rect = {0, 0, 128, 128};
10427 static const DWORD tex1_data[4] = {0x00ff0000, 0x00ff0000, 0x00000000, 0x00000000};
10428 static const DWORD tex2_data[4] = {0x00000000, 0x0000ff00, 0x00000000, 0x0000ff00};
10429 static const float vertices[] =
10431 64.0f, 64.0f, 0.1f,
10432 128.0f, 64.0f, 0.1f,
10433 192.0f, 64.0f, 0.1f,
10434 256.0f, 64.0f, 0.1f,
10435 320.0f, 64.0f, 0.1f,
10436 384.0f, 64.0f, 0.1f,
10437 448.0f, 64.0f, 0.1f,
10438 512.0f, 64.0f, 0.1f,
10440 static const struct
10442 float x, y, z;
10443 float point_size;
10445 vertex_pointsize = {64.0f, 64.0f, 0.1f, 48.0f},
10446 vertex_pointsize_scaled = {64.0f, 64.0f, 0.1f, 24.0f},
10447 vertex_pointsize_zero = {64.0f, 64.0f, 0.1f, 0.0f};
10448 /* Writing a texture coordinate from the shader is technically unnecessary, but is required
10449 * to make Windows AMD r500 drivers work. Without it, texture coordinates in the pixel
10450 * shaders are 0. */
10451 static const DWORD vshader_code[] =
10453 0xfffe0101, /* vs_1_1 */
10454 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
10455 0x00000005, 0x800f0000, 0x90000000, 0xa0e40000, /* mul r0, v0.x, c0 */
10456 0x00000004, 0x800f0000, 0x90550000, 0xa0e40001, 0x80e40000, /* mad r0, v0.y, c1, r0 */
10457 0x00000004, 0x800f0000, 0x90aa0000, 0xa0e40002, 0x80e40000, /* mad r0, v0.z, c2, r0 */
10458 0x00000004, 0xc00f0000, 0x90ff0000, 0xa0e40003, 0x80e40000, /* mad oPos, v0.w, c3, r0 */
10459 0x00000001, 0xe00f0000, 0x90e40000, /* mov oT0, v0 */
10460 0x00000001, 0xe00f0001, 0x90e40000, /* mov oT1, v0 */
10461 0x0000ffff
10463 static const DWORD vshader_psize_code[] =
10465 0xfffe0101, /* vs_1_1 */
10466 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
10467 0x0000001f, 0x80000004, 0x900f0001, /* dcl_psize v1 */
10468 0x00000005, 0x800f0000, 0x90000000, 0xa0e40000, /* mul r0, v0.x, c0 */
10469 0x00000004, 0x800f0000, 0x90550000, 0xa0e40001, 0x80e40000, /* mad r0, v0.y, c1, r0 */
10470 0x00000004, 0x800f0000, 0x90aa0000, 0xa0e40002, 0x80e40000, /* mad r0, v0.z, c2, r0 */
10471 0x00000004, 0xc00f0000, 0x90ff0000, 0xa0e40003, 0x80e40000, /* mad oPos, v0.w, c3, r0 */
10472 0x00000001, 0xc00f0002, 0x90000001, /* mov oPts, v1.x */
10473 0x00000001, 0xe00f0000, 0x90e40000, /* mov oT0, v0 */
10474 0x00000001, 0xe00f0001, 0x90e40000, /* mov oT1, v0 */
10475 0x0000ffff
10477 static const DWORD pshader_code[] =
10479 0xffff0101, /* ps_1_1 */
10480 0x00000042, 0xb00f0000, /* tex t0 */
10481 0x00000042, 0xb00f0001, /* tex t1 */
10482 0x00000002, 0x800f0000, 0xb0e40000, 0xb0e40001, /* add r0, t0, t1 */
10483 0x0000ffff
10485 static const DWORD pshader2_code[] =
10487 0xffff0200, /* ps_2_0 */
10488 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
10489 0x0200001f, 0x80000000, 0xb00f0001, /* dcl t1 */
10490 0x0200001f, 0x90000000, 0xa00f0800, /* dcl_2d s0 */
10491 0x0200001f, 0x90000000, 0xa00f0801, /* dcl_2d s1 */
10492 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texld r0, t0, s0 */
10493 0x03000042, 0x800f0001, 0xb0e40001, 0xa0e40801, /* texld r1, t1, s1 */
10494 0x03000002, 0x800f0000, 0x80e40000, 0x80e40001, /* add r0, r0, r1 */
10495 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
10496 0x0000ffff
10498 static const DWORD pshader2_zw_code[] =
10500 0xffff0200, /* ps_2_0 */
10501 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
10502 0x0200001f, 0x80000000, 0xb00f0001, /* dcl t1 */
10503 0x0200001f, 0x90000000, 0xa00f0800, /* dcl_2d s0 */
10504 0x0200001f, 0x90000000, 0xa00f0801, /* dcl_2d s1 */
10505 0x02000001, 0x80030000, 0xb01b0000, /* mov r0.xy, t0.wzyx */
10506 0x02000001, 0x80030001, 0xb01b0001, /* mov r1.xy, t1.wzyx */
10507 0x03000042, 0x800f0000, 0x80e40000, 0xa0e40800, /* texld r0, r0, s0 */
10508 0x03000042, 0x800f0001, 0x80e40001, 0xa0e40801, /* texld r1, r1, s1 */
10509 0x03000002, 0x800f0000, 0x80e40000, 0x80e40001, /* add r0, r0, r1 */
10510 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
10511 0x0000ffff
10513 static const DWORD vshader3_code[] =
10515 0xfffe0300, /* vs_3_0 */
10516 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
10517 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
10518 0x0200001f, 0x80000005, 0xe00f0001, /* dcl_texcoord0 o1 */
10519 0x0200001f, 0x80010005, 0xe00f0002, /* dcl_texcoord1 o2 */
10520 0x03000005, 0x800f0000, 0x90000000, 0xa0e40000, /* mul r0, v0.x, c0 */
10521 0x04000004, 0x800f0000, 0x90550000, 0xa0e40001, 0x80e40000, /* mad r0, v0.y, c1, r0 */
10522 0x04000004, 0x800f0000, 0x90aa0000, 0xa0e40002, 0x80e40000, /* mad r0, v0.z, c2, r0 */
10523 0x04000004, 0xe00f0000, 0x90ff0000, 0xa0e40003, 0x80e40000, /* mad o0, v0.w, c3, r0 */
10524 0x02000001, 0xe00f0001, 0x90000000, /* mov o1, v0.x */
10525 0x02000001, 0xe00f0002, 0x90000000, /* mov o2, v0.x */
10526 0x0000ffff
10528 static const DWORD vshader3_psize_code[] =
10530 0xfffe0300, /* vs_3_0 */
10531 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
10532 0x0200001f, 0x80000004, 0x90010001, /* dcl_psize v1.x */
10533 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
10534 0x0200001f, 0x80000004, 0xe00f0001, /* dcl_psize o1 */
10535 0x0200001f, 0x80000005, 0xe00f0002, /* dcl_texcoord0 o2 */
10536 0x0200001f, 0x80010005, 0xe00f0003, /* dcl_texcoord1 o3 */
10537 0x03000005, 0x800f0000, 0x90000000, 0xa0e40000, /* mul r0, v0.x, c0 */
10538 0x04000004, 0x800f0000, 0x90550000, 0xa0e40001, 0x80e40000, /* mad r0, v0.y, c1, r0 */
10539 0x04000004, 0x800f0000, 0x90aa0000, 0xa0e40002, 0x80e40000, /* mad r0, v0.z, c2, r0 */
10540 0x04000004, 0xe00f0000, 0x90ff0000, 0xa0e40003, 0x80e40000, /* mad o0, v0.w, c3, r0 */
10541 0x02000001, 0xe00f0001, 0x90000001, /* mov o1, v1.x */
10542 0x02000001, 0xe00f0002, 0x90000000, /* mov o2, v0.x */
10543 0x02000001, 0xe00f0003, 0x90000000, /* mov o3, v0.x */
10544 0x0000ffff
10546 static const DWORD pshader3_code[] =
10548 0xffff0300, /* ps_3_0 */
10549 0x0200001f, 0x80000005, 0x900f0000, /* dcl_texcoord0 v0 */
10550 0x0200001f, 0x80010005, 0x900f0001, /* dcl_texcoord1 v1 */
10551 0x0200001f, 0x90000000, 0xa00f0800, /* dcl_2d s0 */
10552 0x0200001f, 0x90000000, 0xa00f0801, /* dcl_2d s1 */
10553 0x03000042, 0x800f0000, 0x90e40000, 0xa0e40800, /* texld r0, v0, s0 */
10554 0x03000042, 0x800f0001, 0x90e40001, 0xa0e40801, /* texld r1, v1, s1 */
10555 0x03000002, 0x800f0800, 0x80e40000, 0x80e40001, /* add oC0, r0, r1 */
10556 0x0000ffff
10558 static const DWORD pshader3_zw_code[] =
10560 0xffff0300, /* ps_3_0 */
10561 0x0200001f, 0x80000005, 0x900f0000, /* dcl_texcoord0 v0 */
10562 0x0200001f, 0x80010005, 0x900f0001, /* dcl_texcoord1 v1 */
10563 0x0200001f, 0x90000000, 0xa00f0800, /* dcl_2d s0 */
10564 0x0200001f, 0x90000000, 0xa00f0801, /* dcl_2d s1 */
10565 0x03000042, 0x800f0000, 0x90fe0000, 0xa0e40800, /* texld r0, v0.zw, s0 */
10566 0x03000042, 0x800f0001, 0x90fe0001, 0xa0e40801, /* texld r1, v1.zw, s1 */
10567 0x03000002, 0x800f0800, 0x80e40000, 0x80e40001, /* add oC0, r0, r1 */
10568 0x0000ffff
10570 static const struct test_shader
10572 DWORD version;
10573 const DWORD *code;
10575 novs = {0, NULL},
10576 vs1 = {D3DVS_VERSION(1, 1), vshader_code},
10577 vs1_psize = {D3DVS_VERSION(1, 1), vshader_psize_code},
10578 vs3 = {D3DVS_VERSION(3, 0), vshader3_code},
10579 vs3_psize = {D3DVS_VERSION(3, 0), vshader3_psize_code},
10580 nops = {0, NULL},
10581 ps1 = {D3DPS_VERSION(1, 1), pshader_code},
10582 ps2 = {D3DPS_VERSION(2, 0), pshader2_code},
10583 ps2_zw = {D3DPS_VERSION(2, 0), pshader2_zw_code},
10584 ps3 = {D3DPS_VERSION(3, 0), pshader3_code},
10585 ps3_zw = {D3DPS_VERSION(3, 0), pshader3_zw_code};
10586 static const struct
10588 const struct test_shader *vs;
10589 const struct test_shader *ps;
10590 DWORD accepted_fvf;
10591 unsigned int nonscaled_size, scaled_size;
10592 BOOL gives_0_0_texcoord;
10593 BOOL allow_broken;
10595 test_setups[] =
10597 {&novs, &nops, D3DFVF_XYZ, 32, 45, FALSE, FALSE},
10598 {&vs1, &ps1, D3DFVF_XYZ, 32, 32, FALSE, FALSE},
10599 {&novs, &ps1, D3DFVF_XYZ, 32, 45, FALSE, FALSE},
10600 {&vs1, &nops, D3DFVF_XYZ, 32, 32, FALSE, FALSE},
10601 {&novs, &ps2, D3DFVF_XYZ, 32, 45, FALSE, TRUE},
10602 {&novs, &ps2_zw, D3DFVF_XYZ, 32, 45, TRUE, FALSE},
10603 {&vs1, &ps2, D3DFVF_XYZ, 32, 32, FALSE, TRUE},
10604 {&vs1, &ps2_zw, D3DFVF_XYZ, 32, 32, TRUE, FALSE},
10605 {&vs3, &ps3, D3DFVF_XYZ, 32, 32, FALSE, TRUE},
10606 {&vs3, &ps3_zw, D3DFVF_XYZ, 32, 32, TRUE, FALSE},
10607 {&novs, &nops, D3DFVF_XYZ | D3DFVF_PSIZE, 48, 33, FALSE, FALSE},
10608 {&vs1_psize, &ps1, D3DFVF_XYZ | D3DFVF_PSIZE, 48, 24, FALSE, FALSE},
10609 {&vs3_psize, &ps3, D3DFVF_XYZ | D3DFVF_PSIZE, 48, 24, FALSE, TRUE},
10611 static const struct
10613 BOOL zero_size;
10614 BOOL scale;
10615 BOOL override_min;
10616 DWORD fvf;
10617 const void *vertex_data;
10618 unsigned int vertex_size;
10620 tests[] =
10622 {FALSE, FALSE, FALSE, D3DFVF_XYZ, vertices, sizeof(float) * 3},
10623 {FALSE, TRUE, FALSE, D3DFVF_XYZ, vertices, sizeof(float) * 3},
10624 {FALSE, FALSE, TRUE, D3DFVF_XYZ, vertices, sizeof(float) * 3},
10625 {TRUE, FALSE, FALSE, D3DFVF_XYZ, vertices, sizeof(float) * 3},
10626 {FALSE, FALSE, FALSE, D3DFVF_XYZ | D3DFVF_PSIZE, &vertex_pointsize, sizeof(vertex_pointsize)},
10627 {FALSE, TRUE, FALSE, D3DFVF_XYZ | D3DFVF_PSIZE, &vertex_pointsize_scaled, sizeof(vertex_pointsize_scaled)},
10628 {FALSE, FALSE, TRUE, D3DFVF_XYZ | D3DFVF_PSIZE, &vertex_pointsize, sizeof(vertex_pointsize)},
10629 {TRUE, FALSE, FALSE, D3DFVF_XYZ | D3DFVF_PSIZE, &vertex_pointsize_zero, sizeof(vertex_pointsize_zero)},
10631 /* Transforms the coordinate system [-1.0;1.0]x[1.0;-1.0] to
10632 * [0.0;0.0]x[640.0;480.0]. Z is untouched. */
10633 D3DMATRIX matrix =
10635 2.0f / 640.0f, 0.0f, 0.0f, 0.0f,
10636 0.0f, -2.0f / 480.0f, 0.0f, 0.0f,
10637 0.0f, 0.0f, 1.0f, 0.0f,
10638 -1.0f, 1.0f, 0.0f, 1.0f,
10639 }}};
10641 window = create_window();
10642 d3d = Direct3DCreate9(D3D_SDK_VERSION);
10643 ok(!!d3d, "Failed to create a D3D object.\n");
10644 if (!(device = create_device(d3d, window, window, TRUE)))
10646 skip("Failed to create a D3D device, skipping tests.\n");
10647 goto done;
10650 memset(&caps, 0, sizeof(caps));
10651 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
10652 ok(hr == D3D_OK, "IDirect3DDevice9_GetDeviceCaps failed hr=%08x\n", hr);
10653 if(caps.MaxPointSize < 32.0) {
10654 skip("MaxPointSize < 32.0, skipping(MaxPointsize = %f)\n", caps.MaxPointSize);
10655 IDirect3DDevice9_Release(device);
10656 goto done;
10659 /* The r500 Windows driver needs a draw with regular texture coordinates at least once during the
10660 * device's lifetime, otherwise texture coordinate generation only works for texture 0. */
10661 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
10662 ok(SUCCEEDED(hr), "Failed to set FVF, hr=%#x.\n", hr);
10663 hr = IDirect3DDevice9_BeginScene(device);
10664 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10665 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, vertices, sizeof(float) * 5);
10666 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10667 hr = IDirect3DDevice9_EndScene(device);
10668 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10670 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
10671 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr);
10672 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
10673 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
10674 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &matrix);
10675 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed, hr=%08x\n", hr);
10676 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
10677 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed hr=%08x\n", hr);
10679 hr = IDirect3DDevice9_BeginScene(device);
10680 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10682 ptsize = 15.0f;
10683 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, *(DWORD *)&ptsize);
10684 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10685 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, &vertices[0], sizeof(float) * 3);
10686 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10688 ptsize = 31.0f;
10689 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, *(DWORD *)&ptsize);
10690 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10691 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, &vertices[3], sizeof(float) * 3);
10692 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10694 ptsize = 30.75f;
10695 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, *(DWORD *)&ptsize);
10696 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10697 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, &vertices[6], sizeof(float) * 3);
10698 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10700 if (caps.MaxPointSize >= 63.0f)
10702 ptsize = 63.0f;
10703 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, *(DWORD *)&ptsize);
10704 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10705 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, &vertices[9], sizeof(float) * 3);
10706 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10708 ptsize = 62.75f;
10709 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, *(DWORD *)&ptsize);
10710 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10711 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, &vertices[15], sizeof(float) * 3);
10712 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10715 ptsize = 1.0f;
10716 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, *(DWORD *)&ptsize);
10717 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10718 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, &vertices[12], sizeof(float) * 3);
10719 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10721 hr = IDirect3DDevice9_GetRenderState(device, D3DRS_POINTSIZE_MAX, (DWORD *)&ptsizemax_orig);
10722 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
10723 hr = IDirect3DDevice9_GetRenderState(device, D3DRS_POINTSIZE_MIN, (DWORD *)&ptsizemin_orig);
10724 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
10726 /* What happens if point scaling is disabled, and POINTSIZE_MAX < POINTSIZE? */
10727 ptsize = 15.0f;
10728 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, *(DWORD *)&ptsize);
10729 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10730 ptsize = 1.0f;
10731 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE_MAX, *(DWORD *)&ptsize);
10732 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10733 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, &vertices[18], sizeof(float) * 3);
10734 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10736 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE_MAX, *(DWORD *)&ptsizemax_orig);
10737 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10739 /* pointsize < pointsize_min < pointsize_max?
10740 * pointsize = 1.0, pointsize_min = 15.0, pointsize_max = default(usually 64.0) */
10741 ptsize = 1.0f;
10742 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, *(DWORD *)&ptsize);
10743 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10744 ptsize = 15.0f;
10745 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE_MIN, *(DWORD *)&ptsize);
10746 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10747 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, &vertices[21], sizeof(float) * 3);
10748 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10750 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE_MIN, *(DWORD *)&ptsizemin_orig);
10751 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10753 hr = IDirect3DDevice9_EndScene(device);
10754 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10756 ok(point_match(device, 64, 64, 7), "point_match(64, 64, 7) failed, expected point size 15.\n");
10757 ok(point_match(device, 128, 64, 15), "point_match(128, 64, 15) failed, expected point size 31.\n");
10758 ok(point_match(device, 192, 64, 15), "point_match(192, 64, 15) failed, expected point size 31.\n");
10760 if (caps.MaxPointSize >= 63.0)
10762 ok(point_match(device, 256, 64, 31), "point_match(256, 64, 31) failed, expected point size 63.\n");
10763 ok(point_match(device, 384, 64, 31), "point_match(384, 64, 31) failed, expected point size 63.\n");
10766 ok(point_match(device, 320, 64, 0), "point_match(320, 64, 0) failed, expected point size 1.\n");
10767 /* ptsize = 15, ptsize_max = 1 --> point has size 1 */
10768 ok(point_match(device, 448, 64, 0), "point_match(448, 64, 0) failed, expected point size 1.\n");
10769 /* ptsize = 1, ptsize_max = default(64), ptsize_min = 15 --> point has size 15 */
10770 ok(point_match(device, 512, 64, 7), "point_match(512, 64, 7) failed, expected point size 15.\n");
10772 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
10774 /* The following code tests point sprites with two textures, to see if each texture coordinate unit
10775 * generates texture coordinates for the point(result: Yes, it does)
10777 * However, not all GL implementations support point sprites(they need GL_ARB_point_sprite), but there
10778 * is no point sprite cap bit in d3d because native d3d software emulates point sprites. Until the
10779 * SW emulation is implemented in wined3d, this test will fail on GL drivers that does not support them.
10781 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
10782 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr);
10784 hr = IDirect3DDevice9_CreateTexture(device, 2, 2, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex1, NULL);
10785 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture failed hr=%08x\n", hr);
10786 hr = IDirect3DDevice9_CreateTexture(device, 2, 2, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex2, NULL);
10787 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture failed hr=%08x\n", hr);
10788 memset(&lr, 0, sizeof(lr));
10789 hr = IDirect3DTexture9_LockRect(tex1, 0, &lr, NULL, 0);
10790 ok(hr == D3D_OK, "IDirect3DTexture9_LockRect failed hr=%08x\n", hr);
10791 memcpy(lr.pBits, tex1_data, sizeof(tex1_data));
10792 hr = IDirect3DTexture9_UnlockRect(tex1, 0);
10793 ok(hr == D3D_OK, "IDirect3DTexture9_UnlockRect failed hr=%08x\n", hr);
10794 memset(&lr, 0, sizeof(lr));
10795 hr = IDirect3DTexture9_LockRect(tex2, 0, &lr, NULL, 0);
10796 ok(hr == D3D_OK, "IDirect3DTexture9_LockRect failed hr=%08x\n", hr);
10797 memcpy(lr.pBits, tex2_data, sizeof(tex2_data));
10798 hr = IDirect3DTexture9_UnlockRect(tex2, 0);
10799 ok(hr == D3D_OK, "IDirect3DTexture9_UnlockRect failed hr=%08x\n", hr);
10800 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) tex1);
10801 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture failed hr=%08x\n", hr);
10802 hr = IDirect3DDevice9_SetTexture(device, 1, (IDirect3DBaseTexture9 *) tex2);
10803 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture failed hr=%08x\n", hr);
10804 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
10805 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed hr=%08x\n", hr);
10806 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
10807 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed hr=%08x\n", hr);
10808 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_ADD);
10809 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed hr=%08x\n", hr);
10810 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
10811 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed hr=%08x\n", hr);
10812 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_CURRENT);
10813 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed hr=%08x\n", hr);
10815 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSPRITEENABLE, TRUE);
10816 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed hr=%08x\n", hr);
10817 ptsize = 32.0;
10818 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, *((DWORD *) (&ptsize)));
10819 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed, hr=%08x\n", hr);
10821 hr = IDirect3DDevice9_BeginScene(device);
10822 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10823 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, &vertices[0], sizeof(float) * 3);
10824 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10825 hr = IDirect3DDevice9_EndScene(device);
10826 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10828 color = getPixelColor(device, 64-4, 64-4);
10829 ok(color == 0x00ff0000, "pSprite: Pixel (64-4),(64-4) has color 0x%08x, expected 0x00ff0000\n", color);
10830 color = getPixelColor(device, 64-4, 64+4);
10831 ok(color == 0x00000000, "pSprite: Pixel (64-4),(64+4) has color 0x%08x, expected 0x00000000\n", color);
10832 color = getPixelColor(device, 64+4, 64+4);
10833 ok(color == 0x0000ff00, "pSprite: Pixel (64+4),(64+4) has color 0x%08x, expected 0x0000ff00\n", color);
10834 color = getPixelColor(device, 64+4, 64-4);
10835 ok(color == 0x00ffff00, "pSprite: Pixel (64+4),(64-4) has color 0x%08x, expected 0x00ffff00\n", color);
10836 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
10838 U(matrix).m[0][0] = 1.0f / 64.0f;
10839 U(matrix).m[1][1] = -1.0f / 64.0f;
10840 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &matrix);
10841 ok(SUCCEEDED(hr), "SetTransform failed, hr %#x.\n", hr);
10843 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &backbuffer);
10844 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
10846 hr = IDirect3DDevice9_CreateRenderTarget(device, 128, 128, D3DFMT_A8R8G8B8,
10847 D3DMULTISAMPLE_NONE, 0, TRUE, &rt, NULL );
10848 ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
10850 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSCALE_A, *(DWORD *)&a);
10851 ok(SUCCEEDED(hr), "Failed setting point scale attenuation coefficient, hr %#x.\n", hr);
10852 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSCALE_B, *(DWORD *)&b);
10853 ok(SUCCEEDED(hr), "Failed setting point scale attenuation coefficient, hr %#x.\n", hr);
10854 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSCALE_C, *(DWORD *)&c);
10855 ok(SUCCEEDED(hr), "Failed setting point scale attenuation coefficient, hr %#x.\n", hr);
10856 if (caps.VertexShaderVersion >= D3DVS_VERSION(1, 1))
10858 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 0, &S(U(matrix))._11, 4);
10859 ok(SUCCEEDED(hr), "Failed to set vertex shader constants, hr %#x.\n", hr);
10862 if (caps.MaxPointSize < 63.0f)
10864 skip("MaxPointSize %f < 63.0, skipping some tests.\n", caps.MaxPointSize);
10865 goto cleanup;
10868 for (i = 0; i < sizeof(test_setups) / sizeof(test_setups[0]); ++i)
10870 if (caps.VertexShaderVersion < test_setups[i].vs->version
10871 || caps.PixelShaderVersion < test_setups[i].ps->version)
10873 skip("Vertex / pixel shader version not supported, skipping test.\n");
10874 continue;
10876 if (test_setups[i].vs->code)
10878 hr = IDirect3DDevice9_CreateVertexShader(device, test_setups[i].vs->code, &vs);
10879 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x (case %u).\n", hr, i);
10881 else
10883 vs = NULL;
10885 if (test_setups[i].ps->code)
10887 hr = IDirect3DDevice9_CreatePixelShader(device, test_setups[i].ps->code, &ps);
10888 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x (case %u).\n", hr, i);
10890 else
10892 ps = NULL;
10895 hr = IDirect3DDevice9_SetVertexShader(device, vs);
10896 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
10897 hr = IDirect3DDevice9_SetPixelShader(device, ps);
10898 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
10900 for (j = 0; j < sizeof(tests) / sizeof(tests[0]); ++j)
10902 BOOL allow_broken = test_setups[i].allow_broken;
10903 unsigned int size = tests[j].override_min ? 63 : tests[j].zero_size ? 0 : tests[j].scale
10904 ? test_setups[i].scaled_size : test_setups[i].nonscaled_size;
10906 if (test_setups[i].accepted_fvf != tests[j].fvf)
10907 continue;
10909 ptsize = tests[j].zero_size ? 0.0f : 32.0f;
10910 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, *(DWORD *)&ptsize);
10911 ok(SUCCEEDED(hr), "Failed to set pointsize, hr %#x.\n", hr);
10913 ptsize = tests[j].override_min ? 63.0f : tests[j].zero_size ? 0.0f : ptsizemin_orig;
10914 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE_MIN, *(DWORD *)&ptsize);
10915 ok(SUCCEEDED(hr), "Failed to set minimum pointsize, hr %#x.\n", hr);
10917 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSCALEENABLE, tests[j].scale);
10918 ok(SUCCEEDED(hr), "Failed setting point scale state, hr %#x.\n", hr);
10920 hr = IDirect3DDevice9_SetFVF(device, tests[j].fvf);
10921 ok(SUCCEEDED(hr), "Failed setting FVF, hr %#x.\n", hr);
10923 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
10924 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
10925 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ffff, 1.0f, 0);
10926 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
10928 hr = IDirect3DDevice9_BeginScene(device);
10929 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10930 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1,
10931 tests[j].vertex_data, tests[j].vertex_size);
10932 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10933 hr = IDirect3DDevice9_EndScene(device);
10934 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10936 hr = IDirect3DDevice9_StretchRect(device, rt, &rect, backbuffer, &rect, D3DTEXF_NONE);
10937 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
10938 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
10939 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
10941 if (tests[j].zero_size)
10943 /* Technically 0 pointsize is undefined in OpenGL but in practice it seems like
10944 * it does the "useful" thing on all the drivers I tried. */
10945 /* On WARP it does draw some pixels, most of the time. */
10946 color = getPixelColor(device, 64, 64);
10947 ok(color_match(color, 0x0000ffff, 0)
10948 || broken(color_match(color, 0x00ff0000, 0))
10949 || broken(color_match(color, 0x00ffff00, 0))
10950 || broken(color_match(color, 0x00000000, 0))
10951 || broken(color_match(color, 0x0000ff00, 0)),
10952 "Got unexpected color 0x%08x (case %u, %u, size %u).\n", color, i, j, size);
10954 else
10956 struct surface_readback rb;
10958 get_rt_readback(backbuffer, &rb);
10959 /* On AMD apparently only the first texcoord is modified by the point coordinates
10960 * when using SM2/3 pixel shaders. */
10961 color = get_readback_color(&rb, 64 - size / 2 + 1, 64 - size / 2 + 1);
10962 ok(color_match(color, 0x00ff0000, 0),
10963 "Got unexpected color 0x%08x (case %u, %u, size %u).\n", color, i, j, size);
10964 color = get_readback_color(&rb, 64 + size / 2 - 1, 64 - size / 2 + 1);
10965 ok(color_match(color, test_setups[i].gives_0_0_texcoord ? 0x00ff0000 : 0x00ffff00, 0)
10966 || (allow_broken && broken(color_match(color, 0x00ff0000, 0))),
10967 "Got unexpected color 0x%08x (case %u, %u, size %u).\n", color, i, j, size);
10968 color = get_readback_color(&rb, 64 - size / 2 + 1, 64 + size / 2 - 1);
10969 ok(color_match(color, test_setups[i].gives_0_0_texcoord ? 0x00ff0000 : 0x00000000, 0),
10970 "Got unexpected color 0x%08x (case %u, %u, size %u).\n", color, i, j, size);
10971 color = get_readback_color(&rb, 64 + size / 2 - 1, 64 + size / 2 - 1);
10972 ok(color_match(color, test_setups[i].gives_0_0_texcoord ? 0x00ff0000 : 0x0000ff00, 0)
10973 || (allow_broken && broken(color_match(color, 0x00000000, 0))),
10974 "Got unexpected color 0x%08x (case %u, %u, size %u).\n", color, i, j, size);
10976 color = get_readback_color(&rb, 64 - size / 2 - 1, 64 - size / 2 - 1);
10977 ok(color_match(color, 0xff00ffff, 0),
10978 "Got unexpected color 0x%08x (case %u, %u, size %u).\n", color, i, j, size);
10979 color = get_readback_color(&rb, 64 + size / 2 + 1, 64 - size / 2 - 1);
10980 ok(color_match(color, 0xff00ffff, 0),
10981 "Got unexpected color 0x%08x (case %u, %u, size %u).\n", color, i, j, size);
10982 color = get_readback_color(&rb, 64 - size / 2 - 1, 64 + size / 2 + 1);
10983 ok(color_match(color, 0xff00ffff, 0),
10984 "Got unexpected color 0x%08x (case %u, %u, size %u).\n", color, i, j, size);
10985 color = get_readback_color(&rb, 64 + size / 2 + 1, 64 + size / 2 + 1);
10986 ok(color_match(color, 0xff00ffff, 0),
10987 "Got unexpected color 0x%08x (case %u, %u, size %u).\n", color, i, j, size);
10989 release_surface_readback(&rb);
10992 IDirect3DDevice9_SetVertexShader(device, NULL);
10993 IDirect3DDevice9_SetPixelShader(device, NULL);
10994 if (vs)
10995 IDirect3DVertexShader9_Release(vs);
10996 if (ps)
10997 IDirect3DVertexShader9_Release(ps);
11000 cleanup:
11001 IDirect3DSurface9_Release(backbuffer);
11002 IDirect3DSurface9_Release(rt);
11004 IDirect3DTexture9_Release(tex1);
11005 IDirect3DTexture9_Release(tex2);
11006 refcount = IDirect3DDevice9_Release(device);
11007 ok(!refcount, "Device has %u references left.\n", refcount);
11008 done:
11009 IDirect3D9_Release(d3d);
11010 DestroyWindow(window);
11013 static void multiple_rendertargets_test(void)
11015 IDirect3DSurface9 *surf1, *surf2, *backbuf, *readback;
11016 IDirect3DPixelShader9 *ps1, *ps2;
11017 IDirect3DTexture9 *tex1, *tex2;
11018 IDirect3DVertexShader9 *vs;
11019 IDirect3DDevice9 *device;
11020 IDirect3D9 *d3d;
11021 ULONG refcount;
11022 D3DCAPS9 caps;
11023 DWORD color;
11024 HWND window;
11025 HRESULT hr;
11026 UINT i, j;
11028 static const DWORD vshader_code[] =
11030 0xfffe0300, /* vs_3_0 */
11031 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
11032 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
11033 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
11034 0x0000ffff /* end */
11036 static const DWORD pshader_code1[] =
11038 0xffff0300, /* ps_3_0 */
11039 0x05000051, 0xa00f0000, 0x00000000, 0x3f800000, 0x00000000, 0x00000000, /* def c0, 0.0, 1.0, 0.0, 0.0 */
11040 0x02000001, 0x800f0800, 0xa0e40000, /* mov oC0, c0 */
11041 0x0000ffff /* end */
11043 static const DWORD pshader_code2[] =
11045 0xffff0300, /* ps_3_0 */
11046 0x05000051, 0xa00f0000, 0x00000000, 0x3f800000, 0x00000000, 0x00000000, /* def c0, 0.0, 1.0, 0.0, 0.0 */
11047 0x05000051, 0xa00f0001, 0x00000000, 0x00000000, 0x3f800000, 0x00000000, /* def c1, 0.0, 0.0, 1.0, 0.0 */
11048 0x02000001, 0x800f0800, 0xa0e40000, /* mov oC0, c0 */
11049 0x02000001, 0x800f0801, 0xa0e40001, /* mov oC1, c1 */
11050 0x0000ffff /* end */
11052 static const float quad[] =
11054 -1.0f, -1.0f, 0.1f,
11055 -1.0f, 1.0f, 0.1f,
11056 1.0f, -1.0f, 0.1f,
11057 1.0f, 1.0f, 0.1f,
11059 static const float texquad[] =
11061 -1.0f, -1.0f, 0.1f, 0.0f, 0.0f,
11062 -1.0f, 1.0f, 0.1f, 0.0f, 1.0f,
11063 0.0f, -1.0f, 0.1f, 1.0f, 0.0f,
11064 0.0f, 1.0f, 0.1f, 1.0f, 1.0f,
11066 0.0f, -1.0f, 0.1f, 0.0f, 0.0f,
11067 0.0f, 1.0f, 0.1f, 0.0f, 1.0f,
11068 1.0f, -1.0f, 0.1f, 1.0f, 0.0f,
11069 1.0f, 1.0f, 0.1f, 1.0f, 1.0f,
11072 window = create_window();
11073 d3d = Direct3DCreate9(D3D_SDK_VERSION);
11074 ok(!!d3d, "Failed to create a D3D object.\n");
11075 if (!(device = create_device(d3d, window, window, TRUE)))
11077 skip("Failed to create a D3D device, skipping tests.\n");
11078 goto done;
11081 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
11082 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
11083 if (caps.NumSimultaneousRTs < 2)
11085 skip("Only 1 simultaneous render target supported, skipping MRT test.\n");
11086 IDirect3DDevice9_Release(device);
11087 goto done;
11089 if (caps.PixelShaderVersion < D3DPS_VERSION(3, 0) || caps.VertexShaderVersion < D3DVS_VERSION(3, 0))
11091 skip("No shader model 3 support, skipping tests.\n");
11092 IDirect3DDevice9_Release(device);
11093 goto done;
11096 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 1.0f, 0);
11097 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr);
11099 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 16, 16,
11100 D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &readback, NULL);
11101 ok(SUCCEEDED(hr), "CreateOffscreenPlainSurface failed, hr %#x.\n", hr);
11103 hr = IDirect3DDevice9_CreateTexture(device, 16, 16, 1, D3DUSAGE_RENDERTARGET,
11104 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex1, NULL);
11105 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture failed, hr=%08x\n", hr);
11106 hr = IDirect3DDevice9_CreateTexture(device, 16, 16, 1, D3DUSAGE_RENDERTARGET,
11107 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex2, NULL);
11108 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture failed, hr=%08x\n", hr);
11109 hr = IDirect3DDevice9_CreateVertexShader(device, vshader_code, &vs);
11110 ok(SUCCEEDED(hr), "CreateVertexShader failed, hr %#x.\n", hr);
11111 hr = IDirect3DDevice9_CreatePixelShader(device, pshader_code1, &ps1);
11112 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11113 hr = IDirect3DDevice9_CreatePixelShader(device, pshader_code2, &ps2);
11114 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11116 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &backbuf);
11117 ok(hr == D3D_OK, "IDirect3DDevice9_GetRenderTarget failed, hr=%08x\n", hr);
11118 hr = IDirect3DTexture9_GetSurfaceLevel(tex1, 0, &surf1);
11119 ok(hr == D3D_OK, "IDirect3DTexture9_GetSurfaceLevel failed, hr=%08x\n", hr);
11120 hr = IDirect3DTexture9_GetSurfaceLevel(tex2, 0, &surf2);
11121 ok(hr == D3D_OK, "IDirect3DTexture9_GetSurfaceLevel failed, hr=%08x\n", hr);
11123 hr = IDirect3DDevice9_SetVertexShader(device, vs);
11124 ok(SUCCEEDED(hr), "SetVertexShader failed, hr %#x.\n", hr);
11125 hr = IDirect3DDevice9_SetRenderTarget(device, 0, surf1);
11126 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderTarget failed, hr=%08x\n", hr);
11127 hr = IDirect3DDevice9_SetRenderTarget(device, 1, surf2);
11128 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderTarget failed, hr=%08x\n", hr);
11129 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
11130 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed, hr=%08x\n", hr);
11132 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0f, 0);
11133 ok(SUCCEEDED(hr), "Clear failed, hr %#x,\n", hr);
11134 hr = IDirect3DDevice9_GetRenderTargetData(device, surf1, readback);
11135 ok(SUCCEEDED(hr), "GetRenderTargetData failed, hr %#x.\n", hr);
11136 color = getPixelColorFromSurface(readback, 8, 8);
11137 ok(color_match(color, D3DCOLOR_ARGB(0xff, 0x00, 0x00, 0xff), 0),
11138 "Expected color 0x000000ff, got 0x%08x.\n", color);
11139 hr = IDirect3DDevice9_GetRenderTargetData(device, surf2, readback);
11140 ok(SUCCEEDED(hr), "GetRenderTargetData failed, hr %#x.\n", hr);
11141 color = getPixelColorFromSurface(readback, 8, 8);
11142 ok(color_match(color, D3DCOLOR_ARGB(0xff, 0x00, 0x00, 0xff), 0),
11143 "Expected color 0x000000ff, got 0x%08x.\n", color);
11145 /* Render targets not written by the pixel shader should be unmodified. */
11146 hr = IDirect3DDevice9_SetPixelShader(device, ps1);
11147 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
11148 hr = IDirect3DDevice9_BeginScene(device);
11149 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
11150 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 3 * sizeof(float));
11151 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
11152 hr = IDirect3DDevice9_EndScene(device);
11153 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
11154 hr = IDirect3DDevice9_GetRenderTargetData(device, surf1, readback);
11155 ok(SUCCEEDED(hr), "GetRenderTargetData failed, hr %#x.\n", hr);
11156 color = getPixelColorFromSurface(readback, 8, 8);
11157 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 0),
11158 "Expected color 0xff00ff00, got 0x%08x.\n", color);
11159 hr = IDirect3DDevice9_GetRenderTargetData(device, surf2, readback);
11160 ok(SUCCEEDED(hr), "GetRenderTargetData failed, hr %#x.\n", hr);
11161 for (i = 6; i < 10; ++i)
11163 for (j = 6; j < 10; ++j)
11165 color = getPixelColorFromSurface(readback, j, i);
11166 ok(color_match(color, D3DCOLOR_ARGB(0xff, 0x00, 0x00, 0xff), 0),
11167 "Expected color 0xff0000ff, got 0x%08x at %u, %u.\n", color, j, i);
11171 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
11172 ok(SUCCEEDED(hr), "Clear failed, hr %#x,\n", hr);
11173 hr = IDirect3DDevice9_GetRenderTargetData(device, surf1, readback);
11174 ok(SUCCEEDED(hr), "GetRenderTargetData failed, hr %#x.\n", hr);
11175 color = getPixelColorFromSurface(readback, 8, 8);
11176 ok(color_match(color, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00), 0),
11177 "Expected color 0x0000ff00, got 0x%08x.\n", color);
11178 hr = IDirect3DDevice9_GetRenderTargetData(device, surf2, readback);
11179 ok(SUCCEEDED(hr), "GetRenderTargetData failed, hr %#x.\n", hr);
11180 color = getPixelColorFromSurface(readback, 8, 8);
11181 ok(color_match(color, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00), 0),
11182 "Expected color 0x0000ff00, got 0x%08x.\n", color);
11184 hr = IDirect3DDevice9_SetPixelShader(device, ps2);
11185 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
11187 hr = IDirect3DDevice9_BeginScene(device);
11188 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
11190 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 3 * sizeof(float));
11191 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11193 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
11194 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
11195 hr = IDirect3DDevice9_SetVertexShader(device, NULL);
11196 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
11197 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
11198 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
11199 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuf);
11200 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
11201 hr = IDirect3DDevice9_SetRenderTarget(device, 1, NULL);
11202 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
11203 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
11204 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
11206 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) tex1);
11207 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
11208 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &texquad[0], 5 * sizeof(float));
11209 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11211 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) tex2);
11212 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
11213 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &texquad[20], 5 * sizeof(float));
11214 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11216 hr = IDirect3DDevice9_EndScene(device);
11217 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
11219 color = getPixelColor(device, 160, 240);
11220 ok(color == 0x0000ff00, "Texture 1(output color 1) has color 0x%08x, expected 0x0000ff00\n", color);
11221 color = getPixelColor(device, 480, 240);
11222 ok(color == 0x000000ff, "Texture 2(output color 2) has color 0x%08x, expected 0x000000ff\n", color);
11223 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
11225 IDirect3DPixelShader9_Release(ps2);
11226 IDirect3DPixelShader9_Release(ps1);
11227 IDirect3DVertexShader9_Release(vs);
11228 IDirect3DTexture9_Release(tex1);
11229 IDirect3DTexture9_Release(tex2);
11230 IDirect3DSurface9_Release(surf1);
11231 IDirect3DSurface9_Release(surf2);
11232 IDirect3DSurface9_Release(backbuf);
11233 IDirect3DSurface9_Release(readback);
11234 refcount = IDirect3DDevice9_Release(device);
11235 ok(!refcount, "Device has %u references left.\n", refcount);
11236 done:
11237 IDirect3D9_Release(d3d);
11238 DestroyWindow(window);
11241 static void pixelshader_blending_test(void)
11243 IDirect3DSurface9 *backbuffer = NULL, *offscreen = NULL;
11244 IDirect3DTexture9 *offscreenTexture = NULL;
11245 IDirect3DDevice9 *device;
11246 IDirect3D9 *d3d;
11247 ULONG refcount;
11248 int fmt_index;
11249 DWORD color;
11250 HWND window;
11251 HRESULT hr;
11253 static const struct
11255 const char *fmtName;
11256 D3DFORMAT textureFormat;
11257 D3DCOLOR resultColorBlending;
11258 D3DCOLOR resultColorNoBlending;
11260 test_formats[] =
11262 {"D3DFMT_G16R16", D3DFMT_G16R16, 0x001820ff, 0x002010ff},
11263 {"D3DFMT_R16F", D3DFMT_R16F, 0x0018ffff, 0x0020ffff},
11264 {"D3DFMT_G16R16F", D3DFMT_G16R16F, 0x001820ff, 0x002010ff},
11265 {"D3DFMT_A16B16G16R16F", D3DFMT_A16B16G16R16F, 0x00182000, 0x00201000},
11266 {"D3DFMT_R32F", D3DFMT_R32F, 0x0018ffff, 0x0020ffff},
11267 {"D3DFMT_G32R32F", D3DFMT_G32R32F, 0x001820ff, 0x002010ff},
11268 {"D3DFMT_A32B32G32R32F", D3DFMT_A32B32G32R32F, 0x00182000, 0x00201000},
11269 {"D3DFMT_L8", D3DFMT_L8, 0x00181818, 0x00202020},
11271 static const float quad[][5] =
11273 {-0.5f, -0.5f, 0.1f, 0.0f, 0.0f},
11274 {-0.5f, 0.5f, 0.1f, 0.0f, 1.0f},
11275 { 0.5f, -0.5f, 0.1f, 1.0f, 0.0f},
11276 { 0.5f, 0.5f, 0.1f, 1.0f, 1.0f},
11278 static const struct
11280 struct vec3 position;
11281 DWORD diffuse;
11283 quad1[] =
11285 {{-1.0f, -1.0f, 0.1f}, 0x80103000},
11286 {{-1.0f, 1.0f, 0.1f}, 0x80103000},
11287 {{ 1.0f, -1.0f, 0.1f}, 0x80103000},
11288 {{ 1.0f, 1.0f, 0.1f}, 0x80103000},
11290 quad2[] =
11292 {{-1.0f, -1.0f, 0.1f}, 0x80201000},
11293 {{-1.0f, 1.0f, 0.1f}, 0x80201000},
11294 {{ 1.0f, -1.0f, 0.1f}, 0x80201000},
11295 {{ 1.0f, 1.0f, 0.1f}, 0x80201000},
11298 window = create_window();
11299 d3d = Direct3DCreate9(D3D_SDK_VERSION);
11300 ok(!!d3d, "Failed to create a D3D object.\n");
11301 if (!(device = create_device(d3d, window, window, TRUE)))
11303 skip("Failed to create a D3D device, skipping tests.\n");
11304 goto done;
11307 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
11308 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
11310 for (fmt_index = 0; fmt_index < sizeof(test_formats) / sizeof(*test_formats); ++fmt_index)
11312 D3DFORMAT fmt = test_formats[fmt_index].textureFormat;
11314 if (IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
11315 D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, fmt) != D3D_OK)
11317 skip("%s textures not supported as render targets.\n", test_formats[fmt_index].fmtName);
11318 continue;
11321 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
11322 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
11324 hr = IDirect3DDevice9_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET, fmt, D3DPOOL_DEFAULT, &offscreenTexture, NULL);
11325 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Creating the offscreen render target failed, hr = %08x\n", hr);
11326 if(!offscreenTexture) {
11327 continue;
11330 hr = IDirect3DTexture9_GetSurfaceLevel(offscreenTexture, 0, &offscreen);
11331 ok(hr == D3D_OK, "Can't get offscreen surface, hr = %08x\n", hr);
11332 if(!offscreen) {
11333 continue;
11336 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
11337 ok(hr == D3D_OK, "SetFVF failed, hr = %08x\n", hr);
11339 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
11340 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
11341 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
11342 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
11343 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
11344 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_MINFILTER failed (0x%08x)\n", hr);
11345 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
11346 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr);
11347 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
11348 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
11350 /* Below we will draw two quads with different colors and try to blend
11351 * them together. The result color is compared with the expected
11352 * outcome. */
11353 hr = IDirect3DDevice9_BeginScene(device);
11354 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
11356 hr = IDirect3DDevice9_SetRenderTarget(device, 0, offscreen);
11357 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
11358 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00ffffff, 1.0f, 0);
11359 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
11361 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHABLENDENABLE, TRUE);
11362 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
11364 /* Draw a quad using color 0x0010200. */
11365 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_ONE);
11366 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
11367 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_ZERO);
11368 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
11369 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(quad1[0]));
11370 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11372 /* Draw a quad using color 0x0020100. */
11373 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
11374 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
11375 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
11376 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
11377 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(quad2[0]));
11378 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11380 /* We don't want to blend the result on the backbuffer. */
11381 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHABLENDENABLE, FALSE);
11382 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
11384 /* Prepare rendering the 'blended' texture quad to the backbuffer. */
11385 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
11386 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
11387 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)offscreenTexture);
11388 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
11390 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
11391 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
11393 /* This time with the texture. */
11394 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
11395 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11397 hr = IDirect3DDevice9_EndScene(device);
11398 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
11400 if (IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
11401 D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, D3DRTYPE_TEXTURE, fmt) == D3D_OK)
11403 /* Compare the color of the center quad with our expectation. */
11404 color = getPixelColor(device, 320, 240);
11405 ok(color_match(color, test_formats[fmt_index].resultColorBlending, 1),
11406 "Offscreen failed for %s: Got color 0x%08x, expected 0x%08x.\n",
11407 test_formats[fmt_index].fmtName, color, test_formats[fmt_index].resultColorBlending);
11409 else
11411 /* No pixel shader blending is supported so expect garbage. The
11412 * type of 'garbage' depends on the driver version and OS. E.g. on
11413 * G16R16 ATI reports (on old r9600 drivers) 0x00ffffff and on
11414 * modern ones 0x002010ff which is also what NVIDIA reports. On
11415 * Vista NVIDIA seems to report 0x00ffffff on Geforce7 cards. */
11416 color = getPixelColor(device, 320, 240);
11417 ok((color == 0x00ffffff) || (color == test_formats[fmt_index].resultColorNoBlending),
11418 "Offscreen failed for %s: Got unexpected color 0x%08x, expected no color blending.\n",
11419 test_formats[fmt_index].fmtName, color);
11421 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
11423 IDirect3DDevice9_SetTexture(device, 0, NULL);
11424 if(offscreenTexture) {
11425 IDirect3DTexture9_Release(offscreenTexture);
11427 if(offscreen) {
11428 IDirect3DSurface9_Release(offscreen);
11432 IDirect3DSurface9_Release(backbuffer);
11433 refcount = IDirect3DDevice9_Release(device);
11434 ok(!refcount, "Device has %u references left.\n", refcount);
11435 done:
11436 IDirect3D9_Release(d3d);
11437 DestroyWindow(window);
11440 static void tssargtemp_test(void)
11442 IDirect3DDevice9 *device;
11443 IDirect3D9 *d3d;
11444 D3DCOLOR color;
11445 ULONG refcount;
11446 D3DCAPS9 caps;
11447 HWND window;
11448 HRESULT hr;
11450 static const struct
11452 struct vec3 position;
11453 DWORD diffuse;
11455 quad[] =
11457 {{-1.0f, -1.0f, 0.1f}, 0x00ff0000},
11458 {{-1.0f, 1.0f, 0.1f}, 0x00ff0000},
11459 {{ 1.0f, -1.0f, 0.1f}, 0x00ff0000},
11460 {{ 1.0f, 1.0f, 0.1f}, 0x00ff0000},
11463 window = create_window();
11464 d3d = Direct3DCreate9(D3D_SDK_VERSION);
11465 ok(!!d3d, "Failed to create a D3D object.\n");
11466 if (!(device = create_device(d3d, window, window, TRUE)))
11468 skip("Failed to create a D3D device, skipping tests.\n");
11469 goto done;
11472 memset(&caps, 0, sizeof(caps));
11473 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
11474 ok(hr == D3D_OK, "IDirect3DDevice9_GetDeviceCaps failed with %08x\n", hr);
11475 if(!(caps.PrimitiveMiscCaps & D3DPMISCCAPS_TSSARGTEMP)) {
11476 skip("D3DPMISCCAPS_TSSARGTEMP not supported\n");
11477 IDirect3DDevice9_Release(device);
11478 goto done;
11481 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff000000, 1.0f, 0);
11482 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
11484 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
11485 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
11486 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
11487 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
11489 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
11490 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
11491 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_TFACTOR);
11492 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
11493 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_RESULTARG, D3DTA_TEMP);
11494 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
11496 hr = IDirect3DDevice9_SetTextureStageState(device, 2, D3DTSS_COLOROP, D3DTOP_ADD);
11497 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
11498 hr = IDirect3DDevice9_SetTextureStageState(device, 2, D3DTSS_COLORARG1, D3DTA_CURRENT);
11499 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
11500 hr = IDirect3DDevice9_SetTextureStageState(device, 2, D3DTSS_COLORARG2, D3DTA_TEMP);
11501 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
11503 hr = IDirect3DDevice9_SetTextureStageState(device, 3, D3DTSS_COLOROP, D3DTOP_DISABLE);
11504 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
11506 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0x0000ff00);
11507 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed, hr = %08x\n", hr);
11508 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
11509 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
11510 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
11511 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed, hr = %08x\n", hr);
11513 hr = IDirect3DDevice9_BeginScene(device);
11514 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
11515 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
11516 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11517 hr = IDirect3DDevice9_EndScene(device);
11518 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
11520 color = getPixelColor(device, 320, 240);
11521 ok(color == 0x00ffff00, "TSSARGTEMP test returned color 0x%08x, expected 0x00ffff00\n", color);
11522 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
11524 refcount = IDirect3DDevice9_Release(device);
11525 ok(!refcount, "Device has %u references left.\n", refcount);
11526 done:
11527 IDirect3D9_Release(d3d);
11528 DestroyWindow(window);
11531 /* Drawing Indexed Geometry with instances*/
11532 static void stream_test(void)
11534 IDirect3DVertexDeclaration9 *pDecl = NULL;
11535 IDirect3DVertexShader9 *shader = NULL;
11536 IDirect3DVertexBuffer9 *vb3 = NULL;
11537 IDirect3DVertexBuffer9 *vb2 = NULL;
11538 IDirect3DVertexBuffer9 *vb = NULL;
11539 IDirect3DIndexBuffer9 *ib = NULL;
11540 IDirect3DDevice9 *device;
11541 IDirect3D9 *d3d;
11542 ULONG refcount;
11543 D3DCAPS9 caps;
11544 DWORD color;
11545 HWND window;
11546 unsigned i;
11547 HRESULT hr;
11548 BYTE *data;
11549 DWORD ind;
11551 static const struct testdata
11553 DWORD idxVertex; /* number of instances in the first stream */
11554 DWORD idxColor; /* number of instances in the second stream */
11555 DWORD idxInstance; /* should be 1 ?? */
11556 DWORD color1; /* color 1 instance */
11557 DWORD color2; /* color 2 instance */
11558 DWORD color3; /* color 3 instance */
11559 DWORD color4; /* color 4 instance */
11560 WORD strVertex; /* specify which stream to use 0-2*/
11561 WORD strColor;
11562 WORD strInstance;
11563 DWORD explicit_zero_freq;
11565 testcases[]=
11567 {4, 4, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0, 1, 2}, /* 0 */
11568 {3, 4, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ffffff, 0, 1, 2}, /* 1 */
11569 {2, 4, 1, 0x00ff0000, 0x00ff0000, 0x00ffffff, 0x00ffffff, 0, 1, 2}, /* 2 */
11570 {1, 4, 1, 0x00ff0000, 0x00ffffff, 0x00ffffff, 0x00ffffff, 0, 1, 2}, /* 3 */
11571 {4, 3, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0, 1, 2}, /* 4 */
11572 {4, 2, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0, 1, 2}, /* 5 */
11573 {4, 1, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0, 1, 2}, /* 6 */
11574 {4, 0, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0, 1, 2}, /* 7 */
11575 {3, 3, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ffffff, 0, 1, 2}, /* 8 */
11576 {4, 4, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 1, 0, 2}, /* 9 */
11577 {4, 4, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0, 2, 1}, /* 10 */
11578 {4, 4, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 2, 0, 1}, /* 11 */
11580 /* The number of instances is read from stream zero, even if stream zero is not
11581 * in use. Exact behavior of this corner case depends on the presence or absence
11582 * of D3DSTREAMSOURCE_INDEXEDDATA. r500 GPUs need D3DSTREAMSOURCE_INDEXEDDATA
11583 * to be present, otherwise they disable instancing and behave like in a non-
11584 * instanced draw. Nvidia drivers do not show different behavior with or without
11585 * D3DSTREAMSOURCE_INDEXEDDATA. Note however that setting the value to 0 is not
11586 * allowed by the d3d runtime.
11588 * The meaning of (D3DSTREAMSOURCE_INDEXEDDATA | 0) is driver dependent. r500
11589 * will fall back to non-instanced drawing. Geforce 7 will draw 1 instance.
11590 * Geforce 8+ will draw nothing. */
11591 {3, 4, 1, 0x00ff0000, 0x00ffffff, 0x00ffffff, 0x00ffffff, 2, 3, 1, 1}, /* 12 */
11592 {4, 3, 1, 0x00ff0000, 0x00ff0000, 0x00ffffff, 0x00ffffff, 2, 3, 1, 2}, /* 13 */
11593 {1, 3, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ffffff, 2, 3, 1, 3}, /* 14 */
11594 {0, 0, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 2, 3, 1, 4}, /* 15 */
11596 static const DWORD shader_code[] =
11598 0xfffe0101, /* vs_1_1 */
11599 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
11600 0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
11601 0x0000001f, 0x80000005, 0x900f0002, /* dcl_texcoord v2 */
11602 0x00000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
11603 0x00000002, 0xc00f0000, 0x80e40000, 0x90e40002, /* add oPos, r0, v2 */
11604 0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
11605 0x0000ffff
11607 /* Note that this set of coordinates and instancepos[] have an implicit
11608 * w = 1.0, which is added to w = 2.0, so the perspective divide divides
11609 * x, y and z by 2. */
11610 static const float quad[][3] =
11612 {-0.5f, -0.5f, 1.1f}, /*0 */
11613 {-0.5f, 0.5f, 1.1f}, /*1 */
11614 { 0.5f, -0.5f, 1.1f}, /*2 */
11615 { 0.5f, 0.5f, 1.1f}, /*3 */
11617 static const float vertcolor[][4] =
11619 {1.0f, 0.0f, 0.0f, 1.0f}, /*0 */
11620 {1.0f, 0.0f, 0.0f, 1.0f}, /*1 */
11621 {1.0f, 0.0f, 0.0f, 1.0f}, /*2 */
11622 {1.0f, 0.0f, 0.0f, 1.0f}, /*3 */
11624 /* 4 position for 4 instances */
11625 static const float instancepos[][3] =
11627 {-0.6f,-0.6f, 0.0f},
11628 { 0.6f,-0.6f, 0.0f},
11629 { 0.6f, 0.6f, 0.0f},
11630 {-0.6f, 0.6f, 0.0f},
11632 static const short indices[] = {0, 1, 2, 2, 1, 3};
11633 D3DVERTEXELEMENT9 decl[] =
11635 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
11636 {1, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
11637 {2, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
11638 D3DDECL_END()
11641 window = create_window();
11642 d3d = Direct3DCreate9(D3D_SDK_VERSION);
11643 ok(!!d3d, "Failed to create a D3D object.\n");
11644 if (!(device = create_device(d3d, window, window, TRUE)))
11646 skip("Failed to create a D3D device, skipping tests.\n");
11647 goto done;
11650 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
11651 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
11652 if (caps.VertexShaderVersion < D3DVS_VERSION(3, 0))
11654 skip("No vs_3_0 support, skipping tests.\n");
11655 IDirect3DDevice9_Release(device);
11656 goto done;
11659 /* set the default value because it isn't done in wine? */
11660 hr = IDirect3DDevice9_SetStreamSourceFreq(device, 1, 1);
11661 ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr);
11663 /* check for D3DSTREAMSOURCE_INDEXEDDATA at stream0 */
11664 hr = IDirect3DDevice9_SetStreamSourceFreq(device, 0, (D3DSTREAMSOURCE_INSTANCEDATA | 1));
11665 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr);
11667 /* check wrong cases */
11668 hr = IDirect3DDevice9_SetStreamSourceFreq(device, 1, 0);
11669 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr);
11670 hr = IDirect3DDevice9_GetStreamSourceFreq(device, 1, &ind);
11671 ok(hr == D3D_OK && ind == 1, "IDirect3DDevice9_GetStreamSourceFreq failed with %08x\n", hr);
11672 hr = IDirect3DDevice9_SetStreamSourceFreq(device, 1, 2);
11673 ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr);
11674 hr = IDirect3DDevice9_GetStreamSourceFreq(device, 1, &ind);
11675 ok(hr == D3D_OK && ind == 2, "IDirect3DDevice9_GetStreamSourceFreq failed with %08x\n", hr);
11676 hr = IDirect3DDevice9_SetStreamSourceFreq(device, 1, (D3DSTREAMSOURCE_INDEXEDDATA | 0));
11677 ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr);
11678 hr = IDirect3DDevice9_GetStreamSourceFreq(device, 1, &ind);
11679 ok(hr == D3D_OK && ind == (D3DSTREAMSOURCE_INDEXEDDATA | 0), "IDirect3DDevice9_GetStreamSourceFreq failed with %08x\n", hr);
11680 hr = IDirect3DDevice9_SetStreamSourceFreq(device, 1, (D3DSTREAMSOURCE_INSTANCEDATA | 0));
11681 ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr);
11682 hr = IDirect3DDevice9_GetStreamSourceFreq(device, 1, &ind);
11683 ok(hr == D3D_OK && ind == (0U | D3DSTREAMSOURCE_INSTANCEDATA), "IDirect3DDevice9_GetStreamSourceFreq failed with %08x\n", hr);
11684 hr = IDirect3DDevice9_SetStreamSourceFreq(device, 1, (D3DSTREAMSOURCE_INSTANCEDATA | D3DSTREAMSOURCE_INDEXEDDATA | 0));
11685 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr);
11686 hr = IDirect3DDevice9_GetStreamSourceFreq(device, 1, &ind);
11687 ok(hr == D3D_OK && ind == (0U | D3DSTREAMSOURCE_INSTANCEDATA), "IDirect3DDevice9_GetStreamSourceFreq failed with %08x\n", hr);
11689 /* set the default value back */
11690 hr = IDirect3DDevice9_SetStreamSourceFreq(device, 1, 1);
11691 ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr);
11693 /* create all VertexBuffers*/
11694 hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(quad), 0, 0, D3DPOOL_MANAGED, &vb, NULL);
11695 ok(hr == D3D_OK, "CreateVertexBuffer failed with %08x\n", hr);
11696 if(!vb) {
11697 skip("Failed to create a vertex buffer\n");
11698 IDirect3DDevice9_Release(device);
11699 goto done;
11701 hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(vertcolor), 0, 0, D3DPOOL_MANAGED, &vb2, NULL);
11702 ok(hr == D3D_OK, "CreateVertexBuffer failed with %08x\n", hr);
11703 if(!vb2) {
11704 skip("Failed to create a vertex buffer\n");
11705 goto out;
11707 hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(instancepos), 0, 0, D3DPOOL_MANAGED, &vb3, NULL);
11708 ok(hr == D3D_OK, "CreateVertexBuffer failed with %08x\n", hr);
11709 if(!vb3) {
11710 skip("Failed to create a vertex buffer\n");
11711 goto out;
11714 /* create IndexBuffer*/
11715 hr = IDirect3DDevice9_CreateIndexBuffer(device, sizeof(indices), 0, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &ib, NULL);
11716 ok(hr == D3D_OK, "IDirect3DDevice9_CreateIndexBuffer failed with %08x\n", hr);
11717 if(!ib) {
11718 skip("Failed to create an index buffer\n");
11719 goto out;
11722 /* copy all Buffers (Vertex + Index)*/
11723 hr = IDirect3DVertexBuffer9_Lock(vb, 0, sizeof(quad), (void **) &data, 0);
11724 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr);
11725 memcpy(data, quad, sizeof(quad));
11726 hr = IDirect3DVertexBuffer9_Unlock(vb);
11727 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed with %08x\n", hr);
11728 hr = IDirect3DVertexBuffer9_Lock(vb2, 0, sizeof(vertcolor), (void **) &data, 0);
11729 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr);
11730 memcpy(data, vertcolor, sizeof(vertcolor));
11731 hr = IDirect3DVertexBuffer9_Unlock(vb2);
11732 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed with %08x\n", hr);
11733 hr = IDirect3DVertexBuffer9_Lock(vb3, 0, sizeof(instancepos), (void **) &data, 0);
11734 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr);
11735 memcpy(data, instancepos, sizeof(instancepos));
11736 hr = IDirect3DVertexBuffer9_Unlock(vb3);
11737 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed with %08x\n", hr);
11738 hr = IDirect3DIndexBuffer9_Lock(ib, 0, sizeof(indices), (void **) &data, 0);
11739 ok(hr == D3D_OK, "IDirect3DIndexBuffer9_Lock failed with %08x\n", hr);
11740 memcpy(data, indices, sizeof(indices));
11741 hr = IDirect3DIndexBuffer9_Unlock(ib);
11742 ok(hr == D3D_OK, "IDirect3DIndexBuffer9_Unlock failed with %08x\n", hr);
11744 /* create VertexShader */
11745 hr = IDirect3DDevice9_CreateVertexShader(device, shader_code, &shader);
11746 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateVertexShader failed hr=%08x\n", hr);
11747 if(!shader) {
11748 skip("Failed to create a vertex shader.\n");
11749 goto out;
11752 hr = IDirect3DDevice9_SetVertexShader(device, shader);
11753 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShader failed hr=%08x\n", hr);
11755 hr = IDirect3DDevice9_SetIndices(device, ib);
11756 ok(hr == D3D_OK, "IDirect3DDevice9_SetIndices failed with %08x\n", hr);
11758 /* run all tests */
11759 for( i = 0; i < sizeof(testcases)/sizeof(testcases[0]); ++i)
11761 struct testdata act = testcases[i];
11762 decl[0].Stream = act.strVertex;
11763 decl[1].Stream = act.strColor;
11764 decl[2].Stream = act.strInstance;
11765 /* create VertexDeclarations */
11766 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl, &pDecl);
11767 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateVertexDeclaration failed hr=%08x (case %i)\n", hr, i);
11769 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
11770 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x (case %i)\n", hr, i);
11772 hr = IDirect3DDevice9_BeginScene(device);
11773 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
11775 hr = IDirect3DDevice9_SetVertexDeclaration(device, pDecl);
11776 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
11778 /* If stream 0 is unused, set the stream frequency regardless to show
11779 * that the number if instances is read from it. */
11780 if (act.strVertex && act.strColor && act.strInstance)
11782 hr = IDirect3DDevice9_SetStreamSourceFreq(device, 0,
11783 D3DSTREAMSOURCE_INDEXEDDATA | act.explicit_zero_freq);
11784 ok(SUCCEEDED(hr), "Failed to set stream source frequency, hr %#x.\n", hr);
11787 hr = IDirect3DDevice9_SetStreamSourceFreq(device, act.strVertex,
11788 (D3DSTREAMSOURCE_INDEXEDDATA | act.idxVertex));
11789 ok(SUCCEEDED(hr), "Failed to set stream source frequency, hr %#x.\n", hr);
11790 hr = IDirect3DDevice9_SetStreamSource(device, act.strVertex, vb, 0, sizeof(quad[0]));
11791 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
11793 hr = IDirect3DDevice9_SetStreamSourceFreq(device, act.strColor,
11794 (D3DSTREAMSOURCE_INDEXEDDATA | act.idxColor));
11795 ok(SUCCEEDED(hr), "Failed to set stream source frequency, hr %#x.\n", hr);
11796 hr = IDirect3DDevice9_SetStreamSource(device, act.strColor, vb2, 0, sizeof(vertcolor[0]));
11797 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
11799 hr = IDirect3DDevice9_SetStreamSourceFreq(device, act.strInstance,
11800 (D3DSTREAMSOURCE_INSTANCEDATA | act.idxInstance));
11801 ok(SUCCEEDED(hr), "Failed to set stream source frequency, hr %#x.\n", hr);
11802 hr = IDirect3DDevice9_SetStreamSource(device, act.strInstance, vb3, 0, sizeof(instancepos[0]));
11803 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
11805 hr = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2);
11806 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11807 hr = IDirect3DDevice9_EndScene(device);
11808 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
11810 /* set all StreamSource && StreamSourceFreq back to default */
11811 hr = IDirect3DDevice9_SetStreamSourceFreq(device, act.strVertex, 1);
11812 ok(SUCCEEDED(hr), "Failed to set stream source frequency, hr %#x.\n", hr);
11813 hr = IDirect3DDevice9_SetStreamSource(device, act.strVertex, NULL, 0, 0);
11814 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
11815 hr = IDirect3DDevice9_SetStreamSourceFreq(device, act.idxColor, 1);
11816 ok(SUCCEEDED(hr), "Failed to set stream source frequency, hr %#x.\n", hr);
11817 hr = IDirect3DDevice9_SetStreamSource(device, act.idxColor, NULL, 0, 0);
11818 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
11819 hr = IDirect3DDevice9_SetStreamSourceFreq(device, act.idxInstance, 1);
11820 ok(SUCCEEDED(hr), "Failed to set stream source frequency, hr %#x.\n", hr);
11821 hr = IDirect3DDevice9_SetStreamSource(device, act.idxInstance, NULL, 0, 0);
11822 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
11824 hr = IDirect3DVertexDeclaration9_Release(pDecl);
11825 ok(hr == D3D_OK, "IDirect3DVertexDeclaration9_Release failed with %08x (case %i)\n", hr, i);
11827 color = getPixelColor(device, 160, 360);
11828 ok(color == act.color1, "has color 0x%08x, expected 0x%08x (case %i)\n", color, act.color1, i);
11829 color = getPixelColor(device, 480, 360);
11830 ok(color == act.color2, "has color 0x%08x, expected 0x%08x (case %i)\n", color, act.color2, i);
11831 color = getPixelColor(device, 480, 120);
11832 ok(color == act.color3, "has color 0x%08x, expected 0x%08x (case %i)\n", color, act.color3, i);
11833 color = getPixelColor(device, 160, 120);
11834 ok(color == act.color4, "has color 0x%08x, expected 0x%08x (case %i)\n", color, act.color4, i);
11836 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
11837 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x (case %i)\n", hr, i);
11840 out:
11841 if(vb) IDirect3DVertexBuffer9_Release(vb);
11842 if(vb2)IDirect3DVertexBuffer9_Release(vb2);
11843 if(vb3)IDirect3DVertexBuffer9_Release(vb3);
11844 if(ib)IDirect3DIndexBuffer9_Release(ib);
11845 if(shader)IDirect3DVertexShader9_Release(shader);
11846 refcount = IDirect3DDevice9_Release(device);
11847 ok(!refcount, "Device has %u references left.\n", refcount);
11848 done:
11849 IDirect3D9_Release(d3d);
11850 DestroyWindow(window);
11853 static void np2_stretch_rect_test(void)
11855 IDirect3DSurface9 *src = NULL, *dst = NULL, *backbuffer = NULL;
11856 IDirect3DTexture9 *dsttex = NULL;
11857 IDirect3DDevice9 *device;
11858 IDirect3D9 *d3d;
11859 D3DCOLOR color;
11860 ULONG refcount;
11861 HWND window;
11862 HRESULT hr;
11864 static const D3DRECT r1 = {0, 0, 50, 50 };
11865 static const D3DRECT r2 = {50, 0, 100, 50 };
11866 static const D3DRECT r3 = {50, 50, 100, 100};
11867 static const D3DRECT r4 = {0, 50, 50, 100};
11868 static const float quad[] =
11870 -1.0f, -1.0f, 0.1f, 0.0f, 0.0f,
11871 -1.0f, 1.0f, 0.1f, 0.0f, 1.0f,
11872 1.0f, -1.0f, 0.1f, 1.0f, 0.0f,
11873 1.0f, 1.0f, 0.1f, 1.0f, 1.0f,
11876 window = create_window();
11877 d3d = Direct3DCreate9(D3D_SDK_VERSION);
11878 ok(!!d3d, "Failed to create a D3D object.\n");
11879 if (!(device = create_device(d3d, window, window, TRUE)))
11881 skip("Failed to create a D3D device, skipping tests.\n");
11882 goto done;
11885 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
11886 ok(hr == D3D_OK, "IDirect3DDevice9_GetBackBuffer failed with %08x\n", hr);
11888 hr = IDirect3DDevice9_CreateRenderTarget(device, 100, 100, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, TRUE, &src, NULL );
11889 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_CreateRenderTarget failed with %08x\n", hr);
11890 hr = IDirect3DDevice9_CreateTexture(device, 25, 25, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &dsttex, NULL);
11891 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_CreateTexture failed with %08x\n", hr);
11893 if(!src || !dsttex) {
11894 skip("One or more test resources could not be created\n");
11895 goto cleanup;
11898 hr = IDirect3DTexture9_GetSurfaceLevel(dsttex, 0, &dst);
11899 ok(hr == D3D_OK, "IDirect3DTexture9_GetSurfaceLevel failed with %08x\n", hr);
11901 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ffff, 1.0f, 0);
11902 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
11904 /* Clear the StretchRect destination for debugging */
11905 hr = IDirect3DDevice9_SetRenderTarget(device, 0, dst);
11906 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderTarget failed with %08x\n", hr);
11907 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
11908 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
11910 hr = IDirect3DDevice9_SetRenderTarget(device, 0, src);
11911 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderTarget failed with %08x\n", hr);
11913 hr = IDirect3DDevice9_Clear(device, 1, &r1, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
11914 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
11915 hr = IDirect3DDevice9_Clear(device, 1, &r2, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
11916 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
11917 hr = IDirect3DDevice9_Clear(device, 1, &r3, D3DCLEAR_TARGET, 0xff0000ff, 0.0, 0);
11918 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
11919 hr = IDirect3DDevice9_Clear(device, 1, &r4, D3DCLEAR_TARGET, 0xff000000, 0.0, 0);
11920 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
11922 /* Stretchrect before setting the render target back to the backbuffer. This will make Wine use
11923 * the target -> texture GL blit path
11925 hr = IDirect3DDevice9_StretchRect(device, src, NULL, dst, NULL, D3DTEXF_POINT);
11926 ok(hr == D3D_OK, "IDirect3DDevice9_StretchRect failed with %08x\n", hr);
11927 IDirect3DSurface9_Release(dst);
11929 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
11930 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderTarget failed with %08x\n", hr);
11932 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) dsttex);
11933 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture failed with %08x\n", hr);
11934 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
11935 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
11936 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
11937 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with %08x\n", hr);
11938 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
11939 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with %08x\n", hr);
11941 hr = IDirect3DDevice9_BeginScene(device);
11942 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
11943 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(float) * 5);
11944 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11945 hr = IDirect3DDevice9_EndScene(device);
11946 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
11948 color = getPixelColor(device, 160, 360);
11949 ok(color == 0x00ff0000, "stretchrect: Pixel 160,360 has color 0x%08x, expected 0x00ff0000\n", color);
11950 color = getPixelColor(device, 480, 360);
11951 ok(color == 0x0000ff00, "stretchrect: Pixel 480,360 has color 0x%08x, expected 0x0000ff00\n", color);
11952 color = getPixelColor(device, 480, 120);
11953 ok(color == 0x000000ff, "stretchrect: Pixel 480,120 has color 0x%08x, expected 0x000000ff\n", color);
11954 color = getPixelColor(device, 160, 120);
11955 ok(color == 0x00000000, "stretchrect: Pixel 160,120 has color 0x%08x, expected 0x00000000\n", color);
11956 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
11957 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
11959 cleanup:
11960 if(src) IDirect3DSurface9_Release(src);
11961 if(backbuffer) IDirect3DSurface9_Release(backbuffer);
11962 if(dsttex) IDirect3DTexture9_Release(dsttex);
11963 refcount = IDirect3DDevice9_Release(device);
11964 ok(!refcount, "Device has %u references left.\n", refcount);
11965 done:
11966 IDirect3D9_Release(d3d);
11967 DestroyWindow(window);
11970 static void texop_test(void)
11972 IDirect3DVertexDeclaration9 *vertex_declaration = NULL;
11973 IDirect3DTexture9 *texture = NULL;
11974 D3DLOCKED_RECT locked_rect;
11975 IDirect3DDevice9 *device;
11976 IDirect3D9 *d3d;
11977 D3DCOLOR color;
11978 ULONG refcount;
11979 D3DCAPS9 caps;
11980 HWND window;
11981 HRESULT hr;
11982 unsigned i;
11984 static const struct {
11985 float x, y, z;
11986 float s, t;
11987 D3DCOLOR diffuse;
11988 } quad[] = {
11989 {-1.0f, -1.0f, 0.1f, -1.0f, -1.0f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00)},
11990 {-1.0f, 1.0f, 0.1f, -1.0f, 1.0f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00)},
11991 { 1.0f, -1.0f, 0.1f, 1.0f, -1.0f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00)},
11992 { 1.0f, 1.0f, 0.1f, 1.0f, 1.0f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00)}
11995 static const D3DVERTEXELEMENT9 decl_elements[] = {
11996 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
11997 {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
11998 {0, 20, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
11999 D3DDECL_END()
12002 static const struct {
12003 D3DTEXTUREOP op;
12004 const char *name;
12005 DWORD caps_flag;
12006 D3DCOLOR result;
12007 } test_data[] = {
12008 {D3DTOP_SELECTARG1, "SELECTARG1", D3DTEXOPCAPS_SELECTARG1, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00)},
12009 {D3DTOP_SELECTARG2, "SELECTARG2", D3DTEXOPCAPS_SELECTARG2, D3DCOLOR_ARGB(0x00, 0x33, 0x33, 0x33)},
12010 {D3DTOP_MODULATE, "MODULATE", D3DTEXOPCAPS_MODULATE, D3DCOLOR_ARGB(0x00, 0x00, 0x33, 0x00)},
12011 {D3DTOP_MODULATE2X, "MODULATE2X", D3DTEXOPCAPS_MODULATE2X, D3DCOLOR_ARGB(0x00, 0x00, 0x66, 0x00)},
12012 {D3DTOP_MODULATE4X, "MODULATE4X", D3DTEXOPCAPS_MODULATE4X, D3DCOLOR_ARGB(0x00, 0x00, 0xcc, 0x00)},
12013 {D3DTOP_ADD, "ADD", D3DTEXOPCAPS_ADD, D3DCOLOR_ARGB(0x00, 0x33, 0xff, 0x33)},
12014 {D3DTOP_ADDSIGNED, "ADDSIGNED", D3DTEXOPCAPS_ADDSIGNED, D3DCOLOR_ARGB(0x00, 0x00, 0xb2, 0x00)},
12015 {D3DTOP_ADDSIGNED2X, "ADDSIGNED2X", D3DTEXOPCAPS_ADDSIGNED2X, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00)},
12016 {D3DTOP_SUBTRACT, "SUBTRACT", D3DTEXOPCAPS_SUBTRACT, D3DCOLOR_ARGB(0x00, 0x00, 0xcc, 0x00)},
12017 {D3DTOP_ADDSMOOTH, "ADDSMOOTH", D3DTEXOPCAPS_ADDSMOOTH, D3DCOLOR_ARGB(0x00, 0x33, 0xff, 0x33)},
12018 {D3DTOP_BLENDDIFFUSEALPHA, "BLENDDIFFUSEALPHA", D3DTEXOPCAPS_BLENDDIFFUSEALPHA, D3DCOLOR_ARGB(0x00, 0x22, 0x77, 0x22)},
12019 {D3DTOP_BLENDTEXTUREALPHA, "BLENDTEXTUREALPHA", D3DTEXOPCAPS_BLENDTEXTUREALPHA, D3DCOLOR_ARGB(0x00, 0x14, 0xad, 0x14)},
12020 {D3DTOP_BLENDFACTORALPHA, "BLENDFACTORALPHA", D3DTEXOPCAPS_BLENDFACTORALPHA, D3DCOLOR_ARGB(0x00, 0x07, 0xe4, 0x07)},
12021 {D3DTOP_BLENDTEXTUREALPHAPM, "BLENDTEXTUREALPHAPM", D3DTEXOPCAPS_BLENDTEXTUREALPHAPM, D3DCOLOR_ARGB(0x00, 0x14, 0xff, 0x14)},
12022 {D3DTOP_BLENDCURRENTALPHA, "BLENDCURRENTALPHA", D3DTEXOPCAPS_BLENDCURRENTALPHA, D3DCOLOR_ARGB(0x00, 0x22, 0x77, 0x22)},
12023 {D3DTOP_MODULATEALPHA_ADDCOLOR, "MODULATEALPHA_ADDCOLOR", D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR, D3DCOLOR_ARGB(0x00, 0x1f, 0xff, 0x1f)},
12024 {D3DTOP_MODULATECOLOR_ADDALPHA, "MODULATECOLOR_ADDALPHA", D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA, D3DCOLOR_ARGB(0x00, 0x99, 0xcc, 0x99)},
12025 {D3DTOP_MODULATEINVALPHA_ADDCOLOR, "MODULATEINVALPHA_ADDCOLOR", D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR, D3DCOLOR_ARGB(0x00, 0x14, 0xff, 0x14)},
12026 {D3DTOP_MODULATEINVCOLOR_ADDALPHA, "MODULATEINVCOLOR_ADDALPHA", D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA, D3DCOLOR_ARGB(0x00, 0xcc, 0x99, 0xcc)},
12027 /* BUMPENVMAP & BUMPENVMAPLUMINANCE have their own tests */
12028 {D3DTOP_DOTPRODUCT3, "DOTPRODUCT3", D3DTEXOPCAPS_DOTPRODUCT3, D3DCOLOR_ARGB(0x00, 0x99, 0x99, 0x99)},
12029 {D3DTOP_MULTIPLYADD, "MULTIPLYADD", D3DTEXOPCAPS_MULTIPLYADD, D3DCOLOR_ARGB(0x00, 0xff, 0x33, 0x00)},
12030 {D3DTOP_LERP, "LERP", D3DTEXOPCAPS_LERP, D3DCOLOR_ARGB(0x00, 0x00, 0x33, 0x33)},
12033 window = create_window();
12034 d3d = Direct3DCreate9(D3D_SDK_VERSION);
12035 ok(!!d3d, "Failed to create a D3D object.\n");
12036 if (!(device = create_device(d3d, window, window, TRUE)))
12038 skip("Failed to create a D3D device, skipping tests.\n");
12039 goto done;
12042 memset(&caps, 0, sizeof(caps));
12043 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
12044 ok(SUCCEEDED(hr), "GetDeviceCaps failed with 0x%08x\n", hr);
12046 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &vertex_declaration);
12047 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed with 0x%08x\n", hr);
12048 hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration);
12049 ok(SUCCEEDED(hr), "SetVertexDeclaration failed with 0x%08x\n", hr);
12051 hr = IDirect3DDevice9_CreateTexture(device, 1, 1, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture, NULL);
12052 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateTexture failed with 0x%08x\n", hr);
12053 hr = IDirect3DTexture9_LockRect(texture, 0, &locked_rect, NULL, 0);
12054 ok(SUCCEEDED(hr), "LockRect failed with 0x%08x\n", hr);
12055 *((DWORD *)locked_rect.pBits) = D3DCOLOR_ARGB(0x99, 0x00, 0xff, 0x00);
12056 hr = IDirect3DTexture9_UnlockRect(texture, 0);
12057 ok(SUCCEEDED(hr), "UnlockRect failed with 0x%08x\n", hr);
12058 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
12059 ok(SUCCEEDED(hr), "SetTexture failed with 0x%08x\n", hr);
12061 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG0, D3DTA_DIFFUSE);
12062 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
12063 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
12064 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
12065 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
12066 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
12068 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
12069 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
12071 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
12072 ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
12073 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0xdd333333);
12074 ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
12075 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA);
12076 ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
12078 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
12079 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
12081 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
12083 if (!(caps.TextureOpCaps & test_data[i].caps_flag))
12085 skip("tex operation %s not supported\n", test_data[i].name);
12086 continue;
12089 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, test_data[i].op);
12090 ok(SUCCEEDED(hr), "SetTextureStageState (%s) failed with 0x%08x\n", test_data[i].name, hr);
12092 hr = IDirect3DDevice9_BeginScene(device);
12093 ok(SUCCEEDED(hr), "BeginScene failed with 0x%08x\n", hr);
12095 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
12096 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed with 0x%08x\n", hr);
12098 hr = IDirect3DDevice9_EndScene(device);
12099 ok(SUCCEEDED(hr), "EndScene failed with 0x%08x\n", hr);
12101 color = getPixelColor(device, 320, 240);
12102 ok(color_match(color, test_data[i].result, 3), "Operation %s returned color 0x%08x, expected 0x%08x\n",
12103 test_data[i].name, color, test_data[i].result);
12105 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
12106 ok(SUCCEEDED(hr), "Present failed with 0x%08x\n", hr);
12109 IDirect3DTexture9_Release(texture);
12110 IDirect3DVertexDeclaration9_Release(vertex_declaration);
12111 refcount = IDirect3DDevice9_Release(device);
12112 ok(!refcount, "Device has %u references left.\n", refcount);
12113 done:
12114 IDirect3D9_Release(d3d);
12115 DestroyWindow(window);
12118 static void yuv_color_test(void)
12120 HRESULT hr;
12121 IDirect3DSurface9 *surface, *target;
12122 unsigned int i;
12123 D3DLOCKED_RECT lr;
12124 IDirect3D9 *d3d;
12125 D3DCOLOR color;
12126 D3DFORMAT skip_once = D3DFMT_UNKNOWN;
12127 IDirect3DDevice9 *device;
12128 D3DSURFACE_DESC desc;
12129 ULONG refcount;
12130 HWND window;
12132 static const struct
12134 DWORD in;
12135 D3DFORMAT format;
12136 const char *fmt_string;
12137 D3DCOLOR left, right;
12139 test_data[] =
12141 {0x00000000, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00008700, 0x00008700},
12142 {0xff000000, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00008700, 0x004bff1c},
12143 {0x00ff0000, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00b30000, 0x00b30000},
12144 {0x0000ff00, D3DFMT_UYVY, "D3DFMT_UYVY", 0x004bff1c, 0x00008700},
12145 {0x000000ff, D3DFMT_UYVY, "D3DFMT_UYVY", 0x000030e1, 0x000030e1},
12146 {0xffff0000, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00b30000, 0x00ffd01c},
12147 {0xff00ff00, D3DFMT_UYVY, "D3DFMT_UYVY", 0x004bff1c, 0x004bff1c},
12148 {0xff0000ff, D3DFMT_UYVY, "D3DFMT_UYVY", 0x000030e1, 0x004bffff},
12149 {0x00ffff00, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00ffd01c, 0x00b30000},
12150 {0x00ff00ff, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00b300e1, 0x00b300e1},
12151 {0x0000ffff, D3DFMT_UYVY, "D3DFMT_UYVY", 0x004bffff, 0x001030e1},
12152 {0xffffff00, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00ffd01c, 0x00ffd01c},
12153 {0xffff00ff, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00b300e1, 0x00ff79ff},
12154 {0xffffffff, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00ff79ff, 0x00ff79ff},
12155 {0x4cff4c54, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00ff0000, 0x00ff0000},
12156 {0x00800080, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00000000, 0x00000000},
12157 {0xff80ff80, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00ffffff, 0x00ffffff},
12158 {0x1c6b1cff, D3DFMT_UYVY, "D3DFMT_UYVY", 0x000000fd, 0x000000fd},
12160 {0x00000000, D3DFMT_YUY2, "D3DFMT_YUY2", 0x00008700, 0x00008700},
12161 {0xff000000, D3DFMT_YUY2, "D3DFMT_YUY2", 0x00b30000, 0x00b30000},
12162 {0x00ff0000, D3DFMT_YUY2, "D3DFMT_YUY2", 0x00008700, 0x004bff1c},
12163 {0x0000ff00, D3DFMT_YUY2, "D3DFMT_YUY2", 0x000030e1, 0x000030e1},
12164 {0x000000ff, D3DFMT_YUY2, "D3DFMT_YUY2", 0x004bff1c, 0x00008700},
12165 {0xffff0000, D3DFMT_YUY2, "D3DFMT_YUY2", 0x00b30000, 0x00ffd01c},
12166 {0xff00ff00, D3DFMT_YUY2, "D3DFMT_YUY2", 0x00b300e1, 0x00b300e1},
12167 {0xff0000ff, D3DFMT_YUY2, "D3DFMT_YUY2", 0x00ffd01c, 0x00b30000},
12168 {0x00ffff00, D3DFMT_YUY2, "D3DFMT_YUY2", 0x000030e1, 0x004bffff},
12169 {0x00ff00ff, D3DFMT_YUY2, "D3DFMT_YUY2", 0x004bff1c, 0x004bff1c},
12170 {0x0000ffff, D3DFMT_YUY2, "D3DFMT_YUY2", 0x004bffff, 0x000030e1},
12171 {0xffffff00, D3DFMT_YUY2, "D3DFMT_YUY2", 0x00b300e1, 0x00ff79ff},
12172 {0xffff00ff, D3DFMT_YUY2, "D3DFMT_YUY2", 0x00ffd01c, 0x00ffd01c},
12173 {0xffffffff, D3DFMT_YUY2, "D3DFMT_YUY2", 0x00ff79ff, 0x00ff79ff},
12174 {0x4cff4c54, D3DFMT_YUY2, "D3DFMT_YUY2", 0x000b8b00, 0x00b6ffa3},
12175 {0x00800080, D3DFMT_YUY2, "D3DFMT_YUY2", 0x0000ff00, 0x0000ff00},
12176 {0xff80ff80, D3DFMT_YUY2, "D3DFMT_YUY2", 0x00ff00ff, 0x00ff00ff},
12177 {0x1c6b1cff, D3DFMT_YUY2, "D3DFMT_YUY2", 0x006dff45, 0x0000d500},
12180 window = create_window();
12181 d3d = Direct3DCreate9(D3D_SDK_VERSION);
12182 ok(!!d3d, "Failed to create a D3D object.\n");
12183 if (!(device = create_device(d3d, window, window, TRUE)))
12185 skip("Failed to create a D3D device, skipping tests.\n");
12186 goto done;
12189 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &target);
12190 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
12191 hr = IDirect3DSurface9_GetDesc(target, &desc);
12192 ok(SUCCEEDED(hr), "Failed to get surface description, hr %#x.\n", hr);
12194 for (i = 0; i < sizeof(test_data) / sizeof(test_data[0]); i++)
12196 /* Some(all?) Windows drivers do not support YUV 3D textures, only 2D surfaces in StretchRect.
12197 * Thus use StretchRect to draw the YUV surface onto the screen instead of drawPrimitive. */
12198 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL,
12199 D3DFMT_X8R8G8B8, 0, D3DRTYPE_SURFACE, test_data[i].format)))
12201 if (skip_once != test_data[i].format)
12203 skip("%s is not supported.\n", test_data[i].fmt_string);
12204 skip_once = test_data[i].format;
12206 continue;
12208 if (FAILED(IDirect3D9_CheckDeviceFormatConversion(d3d, 0,
12209 D3DDEVTYPE_HAL, test_data[i].format, desc.Format)))
12211 if (skip_once != test_data[i].format)
12213 skip("Driver cannot blit %s surfaces.\n", test_data[i].fmt_string);
12214 skip_once = test_data[i].format;
12216 continue;
12219 /* A pixel is effectively 16 bit large, but two pixels are stored together, so the minimum size is 2x1.
12220 * However, Nvidia Windows drivers have problems with 2x1 YUY2/UYVY surfaces, so use a 4x1 surface and
12221 * fill the second block with dummy data. If the surface has a size of 2x1, those drivers ignore the
12222 * second luminance value, resulting in an incorrect color in the right pixel. */
12223 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 1, test_data[i].format,
12224 D3DPOOL_DEFAULT, &surface, NULL);
12225 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
12228 hr = IDirect3DSurface9_LockRect(surface, &lr, NULL, 0);
12229 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
12230 ((DWORD *)lr.pBits)[0] = test_data[i].in;
12231 ((DWORD *)lr.pBits)[1] = 0x00800080;
12232 hr = IDirect3DSurface9_UnlockRect(surface);
12233 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
12235 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0);
12236 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
12237 hr = IDirect3DDevice9_StretchRect(device, surface, NULL, target, NULL, D3DTEXF_POINT);
12238 ok(SUCCEEDED(hr), "Failed to draw surface onto backbuffer, hr %#x.\n", hr);
12240 /* Some Windows drivers (mostly Nvidia, but also some VM drivers) insist on doing linear filtering
12241 * although we asked for point filtering. Be careful when reading the results and use the pixel
12242 * centers. In the future we may want to add tests for the filtered pixels as well.
12244 * Unfortunately different implementations(Windows-Nvidia and Mac-AMD tested) interpret some colors
12245 * vastly differently, so we need a max diff of 18. */
12246 color = getPixelColor(device, 1, 240);
12247 ok(color_match(color, test_data[i].left, 18),
12248 "Input 0x%08x: Got color 0x%08x for pixel 1/1, expected 0x%08x, format %s.\n",
12249 test_data[i].in, color, test_data[i].left, test_data[i].fmt_string);
12250 color = getPixelColor(device, 318, 240);
12251 ok(color_match(color, test_data[i].right, 18),
12252 "Input 0x%08x: Got color 0x%08x for pixel 2/1, expected 0x%08x, format %s.\n",
12253 test_data[i].in, color, test_data[i].right, test_data[i].fmt_string);
12254 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
12255 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
12256 IDirect3DSurface9_Release(surface);
12259 IDirect3DSurface9_Release(target);
12260 refcount = IDirect3DDevice9_Release(device);
12261 ok(!refcount, "Device has %u references left.\n", refcount);
12262 done:
12263 IDirect3D9_Release(d3d);
12264 DestroyWindow(window);
12267 static void yuv_layout_test(void)
12269 HRESULT hr;
12270 IDirect3DSurface9 *surface, *target;
12271 unsigned int fmt, i, x, y;
12272 D3DFORMAT format;
12273 const char *fmt_string;
12274 D3DLOCKED_RECT lr;
12275 IDirect3D9 *d3d;
12276 D3DCOLOR color;
12277 DWORD ref_color;
12278 BYTE *buf, *chroma_buf, *u_buf, *v_buf;
12279 UINT width = 20, height = 16;
12280 IDirect3DDevice9 *device;
12281 ULONG refcount;
12282 D3DCAPS9 caps;
12283 D3DSURFACE_DESC desc;
12284 HWND window;
12286 static const struct
12288 DWORD color1, color2;
12289 DWORD rgb1, rgb2;
12291 test_data[] =
12293 { 0x000000, 0xffffff, 0x00008800, 0x00ff7dff },
12294 { 0xff0000, 0x00ffff, 0x004aff14, 0x00b800ee },
12295 { 0x00ff00, 0xff00ff, 0x000024ee, 0x00ffe114 },
12296 { 0x0000ff, 0xffff00, 0x00b80000, 0x004affff },
12297 { 0xffff00, 0x0000ff, 0x004affff, 0x00b80000 },
12298 { 0xff00ff, 0x00ff00, 0x00ffe114, 0x000024ee },
12299 { 0x00ffff, 0xff0000, 0x00b800ee, 0x004aff14 },
12300 { 0xffffff, 0x000000, 0x00ff7dff, 0x00008800 },
12303 static const struct
12305 D3DFORMAT format;
12306 const char *str;
12308 formats[] =
12310 { D3DFMT_UYVY, "D3DFMT_UYVY", },
12311 { D3DFMT_YUY2, "D3DFMT_YUY2", },
12312 { MAKEFOURCC('Y','V','1','2'), "D3DFMT_YV12", },
12313 { MAKEFOURCC('N','V','1','2'), "D3DFMT_NV12", },
12316 window = create_window();
12317 d3d = Direct3DCreate9(D3D_SDK_VERSION);
12318 ok(!!d3d, "Failed to create a D3D object.\n");
12319 if (!(device = create_device(d3d, window, window, TRUE)))
12321 skip("Failed to create a D3D device, skipping tests.\n");
12322 goto done;
12325 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
12326 ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
12327 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2
12328 && !(caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL))
12330 skip("No NP2 texture support, skipping YUV texture layout test.\n");
12331 IDirect3DDevice9_Release(device);
12332 goto done;
12335 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &target);
12336 ok(hr == D3D_OK, "IDirect3DDevice9_GetRenderTarget failed, hr = %#x.\n", hr);
12337 hr = IDirect3DSurface9_GetDesc(target, &desc);
12338 ok(SUCCEEDED(hr), "Failed to get surface description, hr %#x.\n", hr);
12340 for (fmt = 0; fmt < sizeof(formats) / sizeof(formats[0]); fmt++)
12342 format = formats[fmt].format;
12343 fmt_string = formats[fmt].str;
12345 /* Some (all?) Windows drivers do not support YUV 3D textures, only 2D surfaces in
12346 * StretchRect. Thus use StretchRect to draw the YUV surface onto the screen instead
12347 * of drawPrimitive. */
12348 if (IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, 0,
12349 D3DRTYPE_SURFACE, format) != D3D_OK)
12351 skip("%s is not supported.\n", fmt_string);
12352 continue;
12354 if (FAILED(IDirect3D9_CheckDeviceFormatConversion(d3d, 0,
12355 D3DDEVTYPE_HAL, format, desc.Format)))
12357 skip("Driver cannot blit %s surfaces.\n", fmt_string);
12358 continue;
12361 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, width, height, format, D3DPOOL_DEFAULT, &surface, NULL);
12362 ok(hr == D3D_OK, "IDirect3DDevice9_CreateOffscreenPlainSurface failed, hr = %#x.\n", hr);
12364 for (i = 0; i < sizeof(test_data) / sizeof(test_data[0]); i++)
12366 hr = IDirect3DSurface9_LockRect(surface, &lr, NULL, 0);
12367 ok(hr == D3D_OK, "IDirect3DSurface9_LockRect failed, hr = %#x.\n", hr);
12368 buf = lr.pBits;
12369 chroma_buf = buf + lr.Pitch * height;
12370 if (format == MAKEFOURCC('Y','V','1','2'))
12372 v_buf = chroma_buf;
12373 u_buf = chroma_buf + height / 2 * lr.Pitch/2;
12375 /* Draw the top left quarter of the screen with color1, the rest with color2 */
12376 for (y = 0; y < height; y++)
12378 for (x = 0; x < width; x += 2)
12380 DWORD color = (x < width / 2 && y < height / 2) ? test_data[i].color1 : test_data[i].color2;
12381 BYTE Y = (color >> 16) & 0xff;
12382 BYTE U = (color >> 8) & 0xff;
12383 BYTE V = (color >> 0) & 0xff;
12384 if (format == D3DFMT_UYVY)
12386 buf[y * lr.Pitch + 2 * x + 0] = U;
12387 buf[y * lr.Pitch + 2 * x + 1] = Y;
12388 buf[y * lr.Pitch + 2 * x + 2] = V;
12389 buf[y * lr.Pitch + 2 * x + 3] = Y;
12391 else if (format == D3DFMT_YUY2)
12393 buf[y * lr.Pitch + 2 * x + 0] = Y;
12394 buf[y * lr.Pitch + 2 * x + 1] = U;
12395 buf[y * lr.Pitch + 2 * x + 2] = Y;
12396 buf[y * lr.Pitch + 2 * x + 3] = V;
12398 else if (format == MAKEFOURCC('Y','V','1','2'))
12400 buf[y * lr.Pitch + x + 0] = Y;
12401 buf[y * lr.Pitch + x + 1] = Y;
12402 u_buf[(y / 2) * (lr.Pitch / 2) + (x / 2)] = U;
12403 v_buf[(y / 2) * (lr.Pitch / 2) + (x / 2)] = V;
12405 else if (format == MAKEFOURCC('N','V','1','2'))
12407 buf[y * lr.Pitch + x + 0] = Y;
12408 buf[y * lr.Pitch + x + 1] = Y;
12409 chroma_buf[(y / 2) * lr.Pitch + 2 * (x / 2) + 0] = U;
12410 chroma_buf[(y / 2) * lr.Pitch + 2 * (x / 2) + 1] = V;
12414 hr = IDirect3DSurface9_UnlockRect(surface);
12415 ok(hr == D3D_OK, "IDirect3DSurface9_UnlockRect failed, hr = %#x.\n", hr);
12417 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0);
12418 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %#x.\n", hr);
12419 hr = IDirect3DDevice9_StretchRect(device, surface, NULL, target, NULL, D3DTEXF_POINT);
12420 ok(hr == D3D_OK, "IDirect3DDevice9_StretchRect failed with %#x.\n", hr);
12422 /* Some Windows drivers (mostly Nvidia, but also some VM drivers) insist on doing linear filtering
12423 * although we asked for point filtering. To prevent running into precision problems, read at points
12424 * with some margin within each quadrant.
12426 * Unfortunately different implementations(Windows-Nvidia and Mac-AMD tested) interpret some colors
12427 * vastly differently, so we need a max diff of 18. */
12428 for (y = 0; y < 4; y++)
12430 for (x = 0; x < 4; x++)
12432 UINT xcoord = (1 + 2 * x) * 640 / 8;
12433 UINT ycoord = (1 + 2 * y) * 480 / 8;
12434 ref_color = (y < 2 && x < 2) ? test_data[i].rgb1 : test_data[i].rgb2;
12435 color = getPixelColor(device, xcoord, ycoord);
12436 ok(color_match(color, ref_color, 18),
12437 "Format %s: Got color %#x for pixel (%d/%d)/(%d/%d), pixel %d %d, expected %#x.\n",
12438 fmt_string, color, x, 4, y, 4, xcoord, ycoord, ref_color);
12441 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
12443 ok(SUCCEEDED(hr), "Present failed with %#x.\n", hr);
12445 IDirect3DSurface9_Release(surface);
12448 IDirect3DSurface9_Release(target);
12449 refcount = IDirect3DDevice9_Release(device);
12450 ok(!refcount, "Device has %u references left.\n", refcount);
12451 done:
12452 IDirect3D9_Release(d3d);
12453 DestroyWindow(window);
12456 static void texop_range_test(void)
12458 IDirect3DTexture9 *texture;
12459 D3DLOCKED_RECT locked_rect;
12460 IDirect3DDevice9 *device;
12461 IDirect3D9 *d3d;
12462 ULONG refcount;
12463 D3DCAPS9 caps;
12464 DWORD color;
12465 HWND window;
12466 HRESULT hr;
12468 static const struct
12470 float x, y, z;
12471 D3DCOLOR diffuse;
12473 quad[] =
12475 {-1.0f, -1.0f, 0.1f, D3DCOLOR_ARGB(0xff, 0xff, 0xff, 0xff)},
12476 {-1.0f, 1.0f, 0.1f, D3DCOLOR_ARGB(0xff, 0xff, 0xff, 0xff)},
12477 { 1.0f, -1.0f, 0.1f, D3DCOLOR_ARGB(0xff, 0xff, 0xff, 0xff)},
12478 { 1.0f, 1.0f, 0.1f, D3DCOLOR_ARGB(0xff, 0xff, 0xff, 0xff)}
12481 window = create_window();
12482 d3d = Direct3DCreate9(D3D_SDK_VERSION);
12483 ok(!!d3d, "Failed to create a D3D object.\n");
12484 if (!(device = create_device(d3d, window, window, TRUE)))
12486 skip("Failed to create a D3D device, skipping tests.\n");
12487 goto done;
12490 /* We need ADD and SUBTRACT operations */
12491 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
12492 ok(SUCCEEDED(hr), "GetDeviceCaps failed with 0x%08x\n", hr);
12493 if (!(caps.TextureOpCaps & D3DTEXOPCAPS_ADD))
12495 skip("D3DTOP_ADD is not supported, skipping value range test.\n");
12496 IDirect3DDevice9_Release(device);
12497 goto done;
12499 if (!(caps.TextureOpCaps & D3DTEXOPCAPS_SUBTRACT))
12501 skip("D3DTEXOPCAPS_SUBTRACT is not supported, skipping value range test.\n");
12502 IDirect3DDevice9_Release(device);
12503 goto done;
12506 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
12507 ok(SUCCEEDED(hr), "SetFVF failed with 0x%08x\n", hr);
12508 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
12509 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
12510 /* Stage 1: result = diffuse(=1.0) + diffuse
12511 * stage 2: result = result - tfactor(= 0.5)
12513 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0x80808080);
12514 ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
12515 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
12516 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
12517 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
12518 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
12519 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_ADD);
12520 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
12521 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_CURRENT);
12522 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
12523 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_TFACTOR);
12524 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
12525 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_SUBTRACT);
12526 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
12528 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
12529 ok(SUCCEEDED(hr), "Failed to clear device, hr %#x.\n\n", hr);
12530 hr = IDirect3DDevice9_BeginScene(device);
12531 ok(SUCCEEDED(hr), "BeginScene failed with 0x%08x\n", hr);
12532 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
12533 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed with 0x%08x\n", hr);
12534 hr = IDirect3DDevice9_EndScene(device);
12535 ok(SUCCEEDED(hr), "EndScene failed with 0x%08x\n", hr);
12537 color = getPixelColor(device, 320, 240);
12538 ok(color_match(color, 0x00808080, 1), "texop Range > 1.0 returned 0x%08x, expected 0x00808080\n",
12539 color);
12540 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
12541 ok(SUCCEEDED(hr), "Present failed with 0x%08x\n", hr);
12543 hr = IDirect3DDevice9_CreateTexture(device, 1, 1, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture, NULL);
12544 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateTexture failed with 0x%08x\n", hr);
12545 hr = IDirect3DTexture9_LockRect(texture, 0, &locked_rect, NULL, 0);
12546 ok(SUCCEEDED(hr), "LockRect failed with 0x%08x\n", hr);
12547 *((DWORD *)locked_rect.pBits) = D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00);
12548 hr = IDirect3DTexture9_UnlockRect(texture, 0);
12549 ok(SUCCEEDED(hr), "UnlockRect failed with 0x%08x\n", hr);
12550 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
12551 ok(SUCCEEDED(hr), "SetTexture failed with 0x%08x\n", hr);
12553 /* Stage 1: result = texture(=0.0) - tfactor(= 0.5)
12554 * stage 2: result = result + diffuse(1.0)
12556 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0x80808080);
12557 ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
12558 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
12559 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
12560 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
12561 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
12562 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SUBTRACT);
12563 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
12564 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_CURRENT);
12565 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
12566 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
12567 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
12568 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_ADD);
12569 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
12571 hr = IDirect3DDevice9_BeginScene(device);
12572 ok(SUCCEEDED(hr), "BeginScene failed with 0x%08x\n", hr);
12573 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
12574 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed with 0x%08x\n", hr);
12575 hr = IDirect3DDevice9_EndScene(device);
12576 ok(SUCCEEDED(hr), "EndScene failed with 0x%08x\n", hr);
12578 color = getPixelColor(device, 320, 240);
12579 ok(color_match(color, 0x00ffffff, 1), "texop Range < 0.0 returned 0x%08x, expected 0x00ffffff\n",
12580 color);
12581 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
12582 ok(SUCCEEDED(hr), "Present failed with 0x%08x\n", hr);
12584 IDirect3DTexture9_Release(texture);
12585 refcount = IDirect3DDevice9_Release(device);
12586 ok(!refcount, "Device has %u references left.\n", refcount);
12587 done:
12588 IDirect3D9_Release(d3d);
12589 DestroyWindow(window);
12592 static void alphareplicate_test(void)
12594 IDirect3DDevice9 *device;
12595 IDirect3D9 *d3d;
12596 ULONG refcount;
12597 DWORD color;
12598 HWND window;
12599 HRESULT hr;
12601 static const struct
12603 struct vec3 position;
12604 DWORD diffuse;
12606 quad[] =
12608 {{-1.0f, -1.0f, 0.1f}, 0x80ff00ff},
12609 {{-1.0f, 1.0f, 0.1f}, 0x80ff00ff},
12610 {{ 1.0f, -1.0f, 0.1f}, 0x80ff00ff},
12611 {{ 1.0f, 1.0f, 0.1f}, 0x80ff00ff},
12614 window = create_window();
12615 d3d = Direct3DCreate9(D3D_SDK_VERSION);
12616 ok(!!d3d, "Failed to create a D3D object.\n");
12617 if (!(device = create_device(d3d, window, window, TRUE)))
12619 skip("Failed to create a D3D device, skipping tests.\n");
12620 goto done;
12623 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
12624 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
12626 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
12627 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with 0x%08x\n", hr);
12629 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
12630 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr);
12631 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE | D3DTA_ALPHAREPLICATE);
12632 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr);
12634 hr = IDirect3DDevice9_BeginScene(device);
12635 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12636 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
12637 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12638 hr = IDirect3DDevice9_EndScene(device);
12639 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12641 color = getPixelColor(device, 320, 240);
12642 ok(color_match(color, 0x00808080, 1), "alphareplicate test 0x%08x, expected 0x00808080\n",
12643 color);
12644 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
12645 ok(SUCCEEDED(hr), "Present failed with 0x%08x\n", hr);
12647 refcount = IDirect3DDevice9_Release(device);
12648 ok(!refcount, "Device has %u references left.\n", refcount);
12649 done:
12650 IDirect3D9_Release(d3d);
12651 DestroyWindow(window);
12654 static void dp3_alpha_test(void)
12656 IDirect3DDevice9 *device;
12657 IDirect3D9 *d3d;
12658 ULONG refcount;
12659 D3DCAPS9 caps;
12660 DWORD color;
12661 HWND window;
12662 HRESULT hr;
12664 static const struct
12666 struct vec3 position;
12667 DWORD diffuse;
12669 quad[] =
12671 {{-1.0f, -1.0f, 0.1f}, 0x408080c0},
12672 {{-1.0f, 1.0f, 0.1f}, 0x408080c0},
12673 {{ 1.0f, -1.0f, 0.1f}, 0x408080c0},
12674 {{ 1.0f, 1.0f, 0.1f}, 0x408080c0},
12677 window = create_window();
12678 d3d = Direct3DCreate9(D3D_SDK_VERSION);
12679 ok(!!d3d, "Failed to create a D3D object.\n");
12680 if (!(device = create_device(d3d, window, window, TRUE)))
12682 skip("Failed to create a D3D device, skipping tests.\n");
12683 goto done;
12686 memset(&caps, 0, sizeof(caps));
12687 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
12688 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
12689 if (!(caps.TextureOpCaps & D3DTEXOPCAPS_DOTPRODUCT3))
12691 skip("D3DTOP_DOTPRODUCT3 not supported\n");
12692 IDirect3DDevice9_Release(device);
12693 goto done;
12696 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
12697 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
12699 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
12700 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with 0x%08x\n", hr);
12702 /* dp3_x4 r0, diffuse_bias, tfactor_bias
12703 * mov r0.a, diffuse.a
12704 * mov r0, r0.a
12706 * It turns out that the 2nd line is ignored, and the dp3 result written into r0.a instead
12707 * thus with input vec4(0.5, 0.5, 0.75, 0.25) and vec4(1.0, 1.0, 1.0, 1.0) the result is
12708 * (0.0 * 0.5 + 0.0 * 0.5 + 0.25 * 0.5) * 4 = 0.125 * 4 = 0.5, with a bunch of inprecision.
12710 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_DOTPRODUCT3);
12711 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr);
12712 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
12713 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr);
12714 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
12715 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr);
12716 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
12717 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr);
12718 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
12719 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr);
12720 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
12721 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr);
12722 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_CURRENT | D3DTA_ALPHAREPLICATE);
12723 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr);
12724 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
12725 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr);
12726 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0xffffffff);
12727 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr);
12728 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
12729 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
12731 hr = IDirect3DDevice9_BeginScene(device);
12732 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12733 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
12734 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12735 hr = IDirect3DDevice9_EndScene(device);
12736 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12738 color = getPixelColor(device, 320, 240);
12739 ok(color_match(color, 0x00808080, 4), "dp3 alpha test 0x%08x, expected 0x00808080\n",
12740 color);
12741 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
12742 ok(SUCCEEDED(hr), "IDirect3DDevice9_Present failed with 0x%08x\n", hr);
12744 refcount = IDirect3DDevice9_Release(device);
12745 ok(!refcount, "Device has %u references left.\n", refcount);
12746 done:
12747 IDirect3D9_Release(d3d);
12748 DestroyWindow(window);
12751 static void zwriteenable_test(void)
12753 IDirect3DDevice9 *device;
12754 IDirect3D9 *d3d;
12755 D3DCOLOR color;
12756 ULONG refcount;
12757 HWND window;
12758 HRESULT hr;
12760 static const struct
12762 struct vec3 position;
12763 DWORD diffuse;
12765 quad1[] =
12767 {{-1.0f, -1.0f, 0.1f}, 0x00ff0000},
12768 {{-1.0f, 1.0f, 0.1f}, 0x00ff0000},
12769 {{ 1.0f, -1.0f, 0.1f}, 0x00ff0000},
12770 {{ 1.0f, 1.0f, 0.1f}, 0x00ff0000},
12772 quad2[] =
12774 {{-1.0f, -1.0f, 0.9f}, 0x0000ff00},
12775 {{-1.0f, 1.0f, 0.9f}, 0x0000ff00},
12776 {{ 1.0f, -1.0f, 0.9f}, 0x0000ff00},
12777 {{ 1.0f, 1.0f, 0.9f}, 0x0000ff00},
12780 window = create_window();
12781 d3d = Direct3DCreate9(D3D_SDK_VERSION);
12782 ok(!!d3d, "Failed to create a D3D object.\n");
12783 if (!(device = create_device(d3d, window, window, TRUE)))
12785 skip("Failed to create a D3D device, skipping tests.\n");
12786 goto done;
12789 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x000000ff, 1.0f, 0);
12790 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
12792 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
12793 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with 0x%08x\n", hr);
12794 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
12795 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr);
12796 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
12797 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr);
12798 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
12799 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr);
12800 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
12801 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
12803 hr = IDirect3DDevice9_BeginScene(device);
12804 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12805 /* The Z buffer is filled with 1.0. Draw a red quad with z = 0.1,
12806 * zenable = D3DZB_FALSE, zwriteenable = TRUE. The red color is written
12807 * because the z test is disabled. The question is whether the z = 0.1
12808 * values are written into the Z buffer. After the draw, set
12809 * zenable = TRUE and draw a green quad at z = 0.9. If the values are
12810 * written, the z test will fail(0.9 > 0.1) and the red color remains. If
12811 * the values are not written, the z test succeeds(0.9 < 1.0) and the
12812 * green color is written. It turns out that the screen is green, so
12813 * zenable = D3DZB_FALSE and zwriteenable = TRUE does NOT write to the z
12814 * buffer. */
12815 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(*quad1));
12816 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12817 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
12818 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
12819 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(*quad2));
12820 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12821 hr = IDirect3DDevice9_EndScene(device);
12822 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12824 color = getPixelColor(device, 320, 240);
12825 ok(color_match(color, 0x0000ff00, 1), "zwriteenable test returned 0x%08x, expected 0x0000ff00\n",
12826 color);
12827 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
12828 ok(SUCCEEDED(hr), "IDirect3DDevice9_Present failed with 0x%08x\n", hr);
12830 refcount = IDirect3DDevice9_Release(device);
12831 ok(!refcount, "Device has %u references left.\n", refcount);
12832 done:
12833 IDirect3D9_Release(d3d);
12834 DestroyWindow(window);
12837 static void alphatest_test(void)
12839 #define ALPHATEST_PASSED 0x0000ff00
12840 #define ALPHATEST_FAILED 0x00ff0000
12841 IDirect3DDevice9 *device;
12842 unsigned int i, j;
12843 IDirect3D9 *d3d;
12844 D3DCOLOR color;
12845 ULONG refcount;
12846 D3DCAPS9 caps;
12847 HWND window;
12848 HRESULT hr;
12850 static const struct
12852 D3DCMPFUNC func;
12853 D3DCOLOR color_less;
12854 D3DCOLOR color_equal;
12855 D3DCOLOR color_greater;
12857 testdata[] =
12859 {D3DCMP_NEVER, ALPHATEST_FAILED, ALPHATEST_FAILED, ALPHATEST_FAILED},
12860 {D3DCMP_LESS, ALPHATEST_PASSED, ALPHATEST_FAILED, ALPHATEST_FAILED},
12861 {D3DCMP_EQUAL, ALPHATEST_FAILED, ALPHATEST_PASSED, ALPHATEST_FAILED},
12862 {D3DCMP_LESSEQUAL, ALPHATEST_PASSED, ALPHATEST_PASSED, ALPHATEST_FAILED},
12863 {D3DCMP_GREATER, ALPHATEST_FAILED, ALPHATEST_FAILED, ALPHATEST_PASSED},
12864 {D3DCMP_NOTEQUAL, ALPHATEST_PASSED, ALPHATEST_FAILED, ALPHATEST_PASSED},
12865 {D3DCMP_GREATEREQUAL, ALPHATEST_FAILED, ALPHATEST_PASSED, ALPHATEST_PASSED},
12866 {D3DCMP_ALWAYS, ALPHATEST_PASSED, ALPHATEST_PASSED, ALPHATEST_PASSED},
12868 static const struct
12870 struct vec3 position;
12871 DWORD diffuse;
12873 quad[] =
12875 {{-1.0f, -1.0f, 0.1f}, ALPHATEST_PASSED | 0x80000000},
12876 {{-1.0f, 1.0f, 0.1f}, ALPHATEST_PASSED | 0x80000000},
12877 {{ 1.0f, -1.0f, 0.1f}, ALPHATEST_PASSED | 0x80000000},
12878 {{ 1.0f, 1.0f, 0.1f}, ALPHATEST_PASSED | 0x80000000},
12881 window = create_window();
12882 d3d = Direct3DCreate9(D3D_SDK_VERSION);
12883 ok(!!d3d, "Failed to create a D3D object.\n");
12884 if (!(device = create_device(d3d, window, window, TRUE)))
12886 skip("Failed to create a D3D device, skipping tests.\n");
12887 goto done;
12890 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
12891 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
12893 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
12894 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
12895 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHATESTENABLE, TRUE);
12896 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr);
12897 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
12898 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with 0x%08x\n", hr);
12900 for (j = 0; j < 2; ++j)
12902 if (j == 1)
12904 /* Try a pixel shader instead of fixed function. The wined3d code
12905 * may emulate the alpha test either for performance reasons
12906 * (floating point RTs) or to work around driver bugs (GeForce
12907 * 7x00 cards on MacOS). There may be a different codepath for ffp
12908 * and shader in this case, and the test should cover both. */
12909 IDirect3DPixelShader9 *ps;
12910 static const DWORD shader_code[] =
12912 0xffff0101, /* ps_1_1 */
12913 0x00000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
12914 0x0000ffff /* end */
12916 memset(&caps, 0, sizeof(caps));
12917 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
12918 ok(hr == D3D_OK, "IDirect3DDevice9_GetDeviceCaps failed with 0x%08x\n", hr);
12919 if(caps.PixelShaderVersion < D3DPS_VERSION(1, 1)) {
12920 break;
12923 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code, &ps);
12924 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader failed with 0x%08x\n", hr);
12925 hr = IDirect3DDevice9_SetPixelShader(device, ps);
12926 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader failed with 0x%08x\n", hr);
12927 IDirect3DPixelShader9_Release(ps);
12930 for(i = 0; i < (sizeof(testdata)/sizeof(testdata[0])); i++) {
12931 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHAFUNC, testdata[i].func);
12932 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr);
12934 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, ALPHATEST_FAILED, 0.0, 0);
12935 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
12936 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHAREF, 0x90);
12937 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr);
12938 hr = IDirect3DDevice9_BeginScene(device);
12939 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12940 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
12941 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12942 hr = IDirect3DDevice9_EndScene(device);
12943 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12944 color = getPixelColor(device, 320, 240);
12945 ok(color_match(color, testdata[i].color_less, 1), "Alphatest failed. Got color 0x%08x, expected 0x%08x. alpha < ref, func %u\n",
12946 color, testdata[i].color_less, testdata[i].func);
12947 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
12948 ok(SUCCEEDED(hr), "IDirect3DDevice9_Present failed with 0x%08x\n", hr);
12950 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, ALPHATEST_FAILED, 0.0, 0);
12951 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
12952 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHAREF, 0x80);
12953 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr);
12954 hr = IDirect3DDevice9_BeginScene(device);
12955 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12956 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
12957 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12958 hr = IDirect3DDevice9_EndScene(device);
12959 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12960 color = getPixelColor(device, 320, 240);
12961 ok(color_match(color, testdata[i].color_equal, 1), "Alphatest failed. Got color 0x%08x, expected 0x%08x. alpha == ref, func %u\n",
12962 color, testdata[i].color_equal, testdata[i].func);
12963 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
12964 ok(SUCCEEDED(hr), "IDirect3DDevice9_Present failed with 0x%08x\n", hr);
12966 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, ALPHATEST_FAILED, 0.0, 0);
12967 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
12968 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHAREF, 0x70);
12969 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr);
12970 hr = IDirect3DDevice9_BeginScene(device);
12971 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12972 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
12973 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12974 hr = IDirect3DDevice9_EndScene(device);
12975 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12976 color = getPixelColor(device, 320, 240);
12977 ok(color_match(color, testdata[i].color_greater, 1), "Alphatest failed. Got color 0x%08x, expected 0x%08x. alpha > ref, func %u\n",
12978 color, testdata[i].color_greater, testdata[i].func);
12979 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
12980 ok(SUCCEEDED(hr), "IDirect3DDevice9_Present failed with 0x%08x\n", hr);
12984 refcount = IDirect3DDevice9_Release(device);
12985 ok(!refcount, "Device has %u references left.\n", refcount);
12986 done:
12987 IDirect3D9_Release(d3d);
12988 DestroyWindow(window);
12991 static void sincos_test(void)
12993 IDirect3DVertexShader9 *sin_shader, *cos_shader;
12994 IDirect3DDevice9 *device;
12995 struct vec3 data[1280];
12996 IDirect3D9 *d3d;
12997 unsigned int i;
12998 ULONG refcount;
12999 D3DCAPS9 caps;
13000 HWND window;
13001 HRESULT hr;
13003 static const DWORD sin_shader_code[] =
13005 0xfffe0200, /* vs_2_0 */
13006 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
13007 0x05000051, 0xa00f0002, 0x40490fdb, 0x3f800000, 0x00000000, 0x3f59999a, /* def c2, 3.14159, 1, 0, 0.85 */
13008 0x03000005, 0x80010001, 0x90000000, 0xa0000002, /* mul r1.x, v0.x, c2.x */
13009 0x04000025, 0x80020000, 0x80000001, 0xa0e40000, 0xa0e40001, /* sincos r0.y, r1.x, c0, c1 */
13010 0x02000001, 0xc00d0000, 0x90e40000, /* mov oPos.xzw, v0 */
13011 0x03000005, 0xc0020000, 0x80550000, 0xa0ff0002, /* mul oPos.y, r0.y, c2.w */
13012 0x02000001, 0xd00f0000, 0xa0a60002, /* mov oD0, c2.zyzz */
13013 0x0000ffff /* end */
13015 static const DWORD cos_shader_code[] =
13017 0xfffe0200, /* vs_2_0 */
13018 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
13019 0x05000051, 0xa00f0002, 0x40490fdb, 0x3f800000, 0x00000000, 0x3f59999a, /* def c2, 3.14159, 1, 0, 0.85 */
13020 0x03000005, 0x80010001, 0x90000000, 0xa0000002, /* mul r1.x, v0.x, c2.x */
13021 0x04000025, 0x80010000, 0x80000001, 0xa0e40000, 0xa0e40001, /* sincos r0.x, r1.x, c0, c1 */
13022 0x02000001, 0xc00d0000, 0x90e40000, /* mov oPos.xzw, v0 */
13023 0x03000005, 0xc0020000, 0x80000000, 0xa0ff0002, /* mul oPos.y, r0.x, c2.w */
13024 0x02000001, 0xd00f0000, 0xa0a90002, /* mov oD0, c2.yzzz */
13025 0x0000ffff /* end */
13027 static const float sincosc1[4] = {D3DSINCOSCONST1};
13028 static const float sincosc2[4] = {D3DSINCOSCONST2};
13030 window = create_window();
13031 d3d = Direct3DCreate9(D3D_SDK_VERSION);
13032 ok(!!d3d, "Failed to create a D3D object.\n");
13033 if (!(device = create_device(d3d, window, window, TRUE)))
13035 skip("Failed to create a D3D device, skipping tests.\n");
13036 goto done;
13039 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
13040 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
13041 if (caps.VertexShaderVersion < D3DVS_VERSION(2, 0))
13043 skip("No vs_2_0 support, skipping tests.\n");
13044 IDirect3DDevice9_Release(device);
13045 goto done;
13048 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
13049 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
13051 hr = IDirect3DDevice9_CreateVertexShader(device, sin_shader_code, &sin_shader);
13052 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
13053 hr = IDirect3DDevice9_CreateVertexShader(device, cos_shader_code, &cos_shader);
13054 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
13055 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
13056 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with 0x%08x\n", hr);
13057 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 0, sincosc1, 1);
13058 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShaderConstantF failed with 0x%08x\n", hr);
13059 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 1, sincosc2, 1);
13060 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShaderConstantF failed with 0x%08x\n", hr);
13062 /* Generate a point from -1 to 1 every 0.5 pixels */
13063 for(i = 0; i < 1280; i++) {
13064 data[i].x = (-640.0 + i) / 640.0;
13065 data[i].y = 0.0;
13066 data[i].z = 0.1;
13069 hr = IDirect3DDevice9_BeginScene(device);
13070 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
13072 hr = IDirect3DDevice9_SetVertexShader(device, sin_shader);
13073 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
13074 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1280, data, sizeof(*data));
13075 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
13077 hr = IDirect3DDevice9_SetVertexShader(device, cos_shader);
13078 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
13079 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1280, data, sizeof(*data));
13080 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
13082 hr = IDirect3DDevice9_EndScene(device);
13083 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
13085 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
13086 ok(SUCCEEDED(hr), "IDirect3DDevice9_Present returned %#x.\n", hr);
13087 /* TODO: Find a way to properly validate the lines. Precicion issues make this a kinda nasty task */
13089 IDirect3DVertexShader9_Release(sin_shader);
13090 IDirect3DVertexShader9_Release(cos_shader);
13091 refcount = IDirect3DDevice9_Release(device);
13092 ok(!refcount, "Device has %u references left.\n", refcount);
13093 done:
13094 IDirect3D9_Release(d3d);
13095 DestroyWindow(window);
13098 static void loop_index_test(void)
13100 IDirect3DVertexShader9 *shader;
13101 IDirect3DDevice9 *device;
13102 IDirect3D9 *d3d;
13103 float values[4];
13104 ULONG refcount;
13105 D3DCAPS9 caps;
13106 DWORD color;
13107 HWND window;
13108 HRESULT hr;
13110 static const DWORD shader_code[] =
13112 0xfffe0200, /* vs_2_0 */
13113 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
13114 0x02000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
13115 0x0200001b, 0xf0e40800, 0xf0e40000, /* loop aL, i0 */
13116 0x04000002, 0x800f0000, 0x80e40000, 0xa0e42001, 0xf0e40800, /* add r0, r0, c[aL + 1] */
13117 0x0000001d, /* endloop */
13118 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
13119 0x02000001, 0xd00f0000, 0x80e40000, /* mov oD0, r0 */
13120 0x0000ffff /* END */
13122 static const float quad[] =
13124 -1.0f, -1.0f, 0.1f,
13125 -1.0f, 1.0f, 0.1f,
13126 1.0f, -1.0f, 0.1f,
13127 1.0f, 1.0f, 0.1f,
13129 static const float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f};
13130 static const float one[4] = {1.0f, 1.0f, 1.0f, 1.0f};
13131 static const int i0[4] = {2, 10, -3, 0};
13133 window = create_window();
13134 d3d = Direct3DCreate9(D3D_SDK_VERSION);
13135 ok(!!d3d, "Failed to create a D3D object.\n");
13136 if (!(device = create_device(d3d, window, window, TRUE)))
13138 skip("Failed to create a D3D device, skipping tests.\n");
13139 goto done;
13142 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
13143 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
13144 if (caps.VertexShaderVersion < D3DVS_VERSION(2, 0))
13146 skip("No vs_2_0 support, skipping tests.\n");
13147 IDirect3DDevice9_Release(device);
13148 goto done;
13151 hr = IDirect3DDevice9_CreateVertexShader(device, shader_code, &shader);
13152 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader failed with %08x\n", hr);
13153 hr = IDirect3DDevice9_SetVertexShader(device, shader);
13154 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShader failed with %08x\n", hr);
13155 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
13156 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
13157 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff0000, 1.0f, 0);
13158 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
13160 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 0, zero, 1);
13161 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
13162 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 1, one, 1);
13163 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
13164 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 2, one, 1);
13165 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
13166 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 3, one, 1);
13167 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
13168 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 4, one, 1);
13169 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
13170 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 5, one, 1);
13171 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
13172 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 6, one, 1);
13173 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
13174 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 7, one, 1);
13175 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
13176 values[0] = 1.0;
13177 values[1] = 1.0;
13178 values[2] = 0.0;
13179 values[3] = 0.0;
13180 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 8, values, 1);
13181 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
13182 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 9, one, 1);
13183 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
13184 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 10, one, 1);
13185 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
13186 values[0] = -1.0;
13187 values[1] = 0.0;
13188 values[2] = 0.0;
13189 values[3] = 0.0;
13190 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 11, values, 1);
13191 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
13192 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 12, one, 1);
13193 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
13194 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 13, one, 1);
13195 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
13196 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 14, one, 1);
13197 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
13198 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 15, one, 1);
13199 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
13201 hr = IDirect3DDevice9_SetVertexShaderConstantI(device, 0, i0, 1);
13202 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantI returned %#x.\n", hr);
13204 hr = IDirect3DDevice9_BeginScene(device);
13205 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
13206 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 3 * sizeof(float));
13207 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
13208 hr = IDirect3DDevice9_EndScene(device);
13209 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
13210 color = getPixelColor(device, 320, 240);
13211 ok(color_match(color, 0x0000ff00, 1),
13212 "aL indexing test returned color 0x%08x, expected 0x0000ff00\n", color);
13213 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
13214 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
13216 IDirect3DVertexShader9_Release(shader);
13217 refcount = IDirect3DDevice9_Release(device);
13218 ok(!refcount, "Device has %u references left.\n", refcount);
13219 done:
13220 IDirect3D9_Release(d3d);
13221 DestroyWindow(window);
13224 static void sgn_test(void)
13226 IDirect3DVertexShader9 *shader;
13227 IDirect3DDevice9 *device;
13228 IDirect3D9 *d3d;
13229 ULONG refcount;
13230 D3DCAPS9 caps;
13231 DWORD color;
13232 HWND window;
13233 HRESULT hr;
13235 static const DWORD shader_code[] =
13237 0xfffe0200, /* vs_2_0 */
13238 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position o0 */
13239 0x05000051, 0xa00f0000, 0xbf000000, 0x00000000, 0x3f000000, 0x41400000, /* def c0, -0.5, 0.0, 0.5, 12.0 */
13240 0x05000051, 0xa00f0001, 0x3fc00000, 0x00000000, 0x00000000, 0x00000000, /* def c1, 1.5, 0.0, 0.0, 0.0 */
13241 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
13242 0x04000022, 0x800f0000, 0xa0e40000, 0x80e40001, 0x80e40002, /* sgn r0, c0, r1, r2 */
13243 0x03000002, 0xd00f0000, 0x80e40000, 0xa0e40001, /* add oD0, r0, c1 */
13244 0x0000ffff /* end */
13246 static const float quad[] =
13248 -1.0f, -1.0f, 0.1f,
13249 -1.0f, 1.0f, 0.1f,
13250 1.0f, -1.0f, 0.1f,
13251 1.0f, 1.0f, 0.1f,
13254 window = create_window();
13255 d3d = Direct3DCreate9(D3D_SDK_VERSION);
13256 ok(!!d3d, "Failed to create a D3D object.\n");
13257 if (!(device = create_device(d3d, window, window, TRUE)))
13259 skip("Failed to create a D3D device, skipping tests.\n");
13260 goto done;
13263 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
13264 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
13265 if (caps.VertexShaderVersion < D3DVS_VERSION(2, 0))
13267 skip("No vs_2_0 support, skipping tests.\n");
13268 IDirect3DDevice9_Release(device);
13269 goto done;
13272 hr = IDirect3DDevice9_CreateVertexShader(device, shader_code, &shader);
13273 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader failed with %08x\n", hr);
13274 hr = IDirect3DDevice9_SetVertexShader(device, shader);
13275 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShader failed with %08x\n", hr);
13276 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
13277 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
13278 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff0000, 1.0f, 0);
13279 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
13281 hr = IDirect3DDevice9_BeginScene(device);
13282 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
13283 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 3 * sizeof(float));
13284 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
13285 hr = IDirect3DDevice9_EndScene(device);
13286 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
13287 color = getPixelColor(device, 320, 240);
13288 ok(color_match(color, 0x008000ff, 1),
13289 "sgn test returned color 0x%08x, expected 0x008000ff\n", color);
13290 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
13291 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
13293 IDirect3DVertexShader9_Release(shader);
13294 refcount = IDirect3DDevice9_Release(device);
13295 ok(!refcount, "Device has %u references left.\n", refcount);
13296 done:
13297 IDirect3D9_Release(d3d);
13298 DestroyWindow(window);
13301 static void viewport_test(void)
13303 IDirect3DDevice9 *device;
13304 BOOL draw_failed = TRUE;
13305 D3DVIEWPORT9 vp;
13306 IDirect3D9 *d3d;
13307 ULONG refcount;
13308 DWORD color;
13309 HWND window;
13310 HRESULT hr;
13312 static const float quad[] =
13314 -0.5f, -0.5f, 0.1f,
13315 -0.5f, 0.5f, 0.1f,
13316 0.5f, -0.5f, 0.1f,
13317 0.5f, 0.5f, 0.1f,
13320 window = create_window();
13321 d3d = Direct3DCreate9(D3D_SDK_VERSION);
13322 ok(!!d3d, "Failed to create a D3D object.\n");
13323 if (!(device = create_device(d3d, window, window, TRUE)))
13325 skip("Failed to create a D3D device, skipping tests.\n");
13326 goto done;
13329 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff0000, 1.0f, 0);
13330 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
13332 /* Test a viewport with Width and Height bigger than the surface dimensions
13334 * TODO: Test Width < surface.width, but X + Width > surface.width
13335 * TODO: Test Width < surface.width, what happens with the height?
13337 * The expected behavior is that the viewport behaves like the "default"
13338 * viewport with X = Y = 0, Width = surface_width, Height = surface_height,
13339 * MinZ = 0.0, MaxZ = 1.0.
13341 * Starting with Windows 7 the behavior among driver versions is not
13342 * consistent. The SetViewport call is accepted on all drivers. Some
13343 * drivers(older nvidia ones) refuse to draw and return an error. Newer
13344 * nvidia drivers draw, but use the actual values in the viewport and only
13345 * display the upper left part on the surface.
13347 memset(&vp, 0, sizeof(vp));
13348 vp.X = 0;
13349 vp.Y = 0;
13350 vp.Width = 10000;
13351 vp.Height = 10000;
13352 vp.MinZ = 0.0;
13353 vp.MaxZ = 0.0;
13354 hr = IDirect3DDevice9_SetViewport(device, &vp);
13355 ok(hr == D3D_OK, "IDirect3DDevice9_SetViewport failed with %08x\n", hr);
13357 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
13358 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
13360 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
13361 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF returned %08x\n", hr);
13362 hr = IDirect3DDevice9_BeginScene(device);
13363 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
13364 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 3 * sizeof(float));
13365 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "Got unexpected hr %#x.\n", hr);
13366 draw_failed = FAILED(hr);
13367 hr = IDirect3DDevice9_EndScene(device);
13368 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
13370 if(!draw_failed)
13372 color = getPixelColor(device, 158, 118);
13373 ok(color == 0x00ff0000, "viewport test: (158,118) has color %08x\n", color);
13374 color = getPixelColor(device, 162, 118);
13375 ok(color == 0x00ff0000, "viewport test: (162,118) has color %08x\n", color);
13376 color = getPixelColor(device, 158, 122);
13377 ok(color == 0x00ff0000, "viewport test: (158,122) has color %08x\n", color);
13378 color = getPixelColor(device, 162, 122);
13379 ok(color == 0x00ffffff || broken(color == 0x00ff0000), "viewport test: (162,122) has color %08x\n", color);
13381 color = getPixelColor(device, 478, 358);
13382 ok(color == 0x00ffffff || broken(color == 0x00ff0000), "viewport test: (478,358 has color %08x\n", color);
13383 color = getPixelColor(device, 482, 358);
13384 ok(color == 0x00ff0000, "viewport test: (482,358) has color %08x\n", color);
13385 color = getPixelColor(device, 478, 362);
13386 ok(color == 0x00ff0000, "viewport test: (478,362) has color %08x\n", color);
13387 color = getPixelColor(device, 482, 362);
13388 ok(color == 0x00ff0000, "viewport test: (482,362) has color %08x\n", color);
13391 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
13392 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
13394 refcount = IDirect3DDevice9_Release(device);
13395 ok(!refcount, "Device has %u references left.\n", refcount);
13396 done:
13397 IDirect3D9_Release(d3d);
13398 DestroyWindow(window);
13401 /* This test tests depth clamping / clipping behaviour:
13402 * - With software vertex processing, depth values are clamped to the
13403 * minimum / maximum z value when D3DRS_CLIPPING is disabled, and clipped
13404 * when D3DRS_CLIPPING is enabled. Pretransformed vertices behave the
13405 * same as regular vertices here.
13406 * - With hardware vertex processing, D3DRS_CLIPPING seems to be ignored.
13407 * Normal vertices are always clipped. Pretransformed vertices are
13408 * clipped when D3DPMISCCAPS_CLIPTLVERTS is set, clamped when it isn't.
13409 * - The viewport's MinZ/MaxZ is irrelevant for this.
13411 static void depth_clamp_test(void)
13413 IDirect3DDevice9 *device;
13414 D3DVIEWPORT9 vp;
13415 IDirect3D9 *d3d;
13416 D3DCOLOR color;
13417 ULONG refcount;
13418 D3DCAPS9 caps;
13419 HWND window;
13420 HRESULT hr;
13422 static const struct
13424 struct vec4 position;
13425 DWORD diffuse;
13427 quad1[] =
13429 {{ 0.0f, 0.0f, 5.0f, 1.0f}, 0xff002b7f},
13430 {{640.0f, 0.0f, 5.0f, 1.0f}, 0xff002b7f},
13431 {{ 0.0f, 480.0f, 5.0f, 1.0f}, 0xff002b7f},
13432 {{640.0f, 480.0f, 5.0f, 1.0f}, 0xff002b7f},
13434 quad2[] =
13436 {{ 0.0f, 300.0f, 10.0f, 1.0f}, 0xfff9e814},
13437 {{640.0f, 300.0f, 10.0f, 1.0f}, 0xfff9e814},
13438 {{ 0.0f, 360.0f, 10.0f, 1.0f}, 0xfff9e814},
13439 {{640.0f, 360.0f, 10.0f, 1.0f}, 0xfff9e814},
13441 quad3[] =
13443 {{112.0f, 108.0f, 5.0f, 1.0f}, 0xffffffff},
13444 {{208.0f, 108.0f, 5.0f, 1.0f}, 0xffffffff},
13445 {{112.0f, 204.0f, 5.0f, 1.0f}, 0xffffffff},
13446 {{208.0f, 204.0f, 5.0f, 1.0f}, 0xffffffff},
13448 quad4[] =
13450 {{ 42.0f, 41.0f, 10.0f, 1.0f}, 0xffffffff},
13451 {{112.0f, 41.0f, 10.0f, 1.0f}, 0xffffffff},
13452 {{ 42.0f, 108.0f, 10.0f, 1.0f}, 0xffffffff},
13453 {{112.0f, 108.0f, 10.0f, 1.0f}, 0xffffffff},
13455 static const struct
13457 struct vec3 position;
13458 DWORD diffuse;
13460 quad5[] =
13462 {{-0.5f, 0.5f, 10.0f}, 0xff14f914},
13463 {{ 0.5f, 0.5f, 10.0f}, 0xff14f914},
13464 {{-0.5f, -0.5f, 10.0f}, 0xff14f914},
13465 {{ 0.5f, -0.5f, 10.0f}, 0xff14f914},
13467 quad6[] =
13469 {{-1.0f, 0.5f, 10.0f}, 0xfff91414},
13470 {{ 1.0f, 0.5f, 10.0f}, 0xfff91414},
13471 {{-1.0f, 0.25f, 10.0f}, 0xfff91414},
13472 {{ 1.0f, 0.25f, 10.0f}, 0xfff91414},
13475 window = create_window();
13476 d3d = Direct3DCreate9(D3D_SDK_VERSION);
13477 ok(!!d3d, "Failed to create a D3D object.\n");
13478 if (!(device = create_device(d3d, window, window, TRUE)))
13480 skip("Failed to create a D3D device, skipping tests.\n");
13481 goto done;
13484 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
13485 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
13487 vp.X = 0;
13488 vp.Y = 0;
13489 vp.Width = 640;
13490 vp.Height = 480;
13491 vp.MinZ = 0.0;
13492 vp.MaxZ = 7.5;
13494 hr = IDirect3DDevice9_SetViewport(device, &vp);
13495 if(FAILED(hr))
13497 /* Windows 7 rejects MaxZ > 1.0, Windows XP allows it. This doesn't break
13498 * the tests because the 7.5 is just intended to show that it doesn't have
13499 * any influence on the drawing or D3DRS_CLIPPING = FALSE. Set an accepted
13500 * viewport and continue.
13502 ok(broken(hr == D3DERR_INVALIDCALL), "D3D rejected maxZ > 1.0\n");
13503 vp.MaxZ = 1.0;
13504 hr = IDirect3DDevice9_SetViewport(device, &vp);
13506 ok(SUCCEEDED(hr), "SetViewport failed, hr %#x.\n", hr);
13508 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 1.0, 0);
13509 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
13511 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, FALSE);
13512 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13513 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
13514 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13515 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
13516 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13517 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
13518 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13520 hr = IDirect3DDevice9_BeginScene(device);
13521 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
13523 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
13524 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
13526 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(*quad1));
13527 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13528 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(*quad2));
13529 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13531 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, TRUE);
13532 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13534 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, sizeof(*quad3));
13535 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13536 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, sizeof(*quad4));
13537 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13539 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, FALSE);
13540 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13542 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
13543 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
13545 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad5, sizeof(*quad5));
13546 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13548 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, TRUE);
13549 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13551 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad6, sizeof(*quad6));
13552 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13554 hr = IDirect3DDevice9_EndScene(device);
13555 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
13557 if (caps.PrimitiveMiscCaps & D3DPMISCCAPS_CLIPTLVERTS)
13559 color = getPixelColor(device, 75, 75);
13560 ok(color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
13561 color = getPixelColor(device, 150, 150);
13562 ok(color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
13563 color = getPixelColor(device, 320, 240);
13564 ok(color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
13565 color = getPixelColor(device, 320, 330);
13566 ok(color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
13567 color = getPixelColor(device, 320, 330);
13568 ok(color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
13570 else
13572 color = getPixelColor(device, 75, 75);
13573 ok(color_match(color, 0x00ffffff, 1), "color 0x%08x.\n", color);
13574 color = getPixelColor(device, 150, 150);
13575 ok(color_match(color, 0x00ffffff, 1), "color 0x%08x.\n", color);
13576 color = getPixelColor(device, 320, 240);
13577 ok(color_match(color, 0x00002b7f, 1), "color 0x%08x.\n", color);
13578 color = getPixelColor(device, 320, 330);
13579 ok(color_match(color, 0x00f9e814, 1), "color 0x%08x.\n", color);
13580 color = getPixelColor(device, 320, 330);
13581 ok(color_match(color, 0x00f9e814, 1), "color 0x%08x.\n", color);
13584 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
13585 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
13587 refcount = IDirect3DDevice9_Release(device);
13588 ok(!refcount, "Device has %u references left.\n", refcount);
13589 done:
13590 IDirect3D9_Release(d3d);
13591 DestroyWindow(window);
13594 static void depth_bounds_test(void)
13596 static const struct
13598 struct vec4 position;
13599 DWORD diffuse;
13601 quad1[] =
13603 {{ 0.0f, 0.0f, 0.0f, 1.0f}, 0xfff9e814},
13604 {{640.0f, 0.0f, 0.0f, 1.0f}, 0xfff9e814},
13605 {{ 0.0f, 480.0f, 1.0f, 1.0f}, 0xfff9e814},
13606 {{640.0f, 480.0f, 1.0f, 1.0f}, 0xfff9e814},
13608 quad2[] =
13610 {{ 0.0f, 0.0f, 0.6f, 1.0f}, 0xff002b7f},
13611 {{640.0f, 0.0f, 0.6f, 1.0f}, 0xff002b7f},
13612 {{ 0.0f, 480.0f, 0.6f, 1.0f}, 0xff002b7f},
13613 {{640.0f, 480.0f, 0.6f, 1.0f}, 0xff002b7f},
13615 quad3[] =
13617 {{ 0.0f, 100.0f, 0.6f, 1.0f}, 0xfff91414},
13618 {{640.0f, 100.0f, 0.6f, 1.0f}, 0xfff91414},
13619 {{ 0.0f, 160.0f, 0.6f, 1.0f}, 0xfff91414},
13620 {{640.0f, 160.0f, 0.6f, 1.0f}, 0xfff91414},
13623 union {
13624 DWORD d;
13625 float f;
13626 } tmpvalue;
13628 IDirect3DSurface9 *offscreen_surface = NULL;
13629 IDirect3DDevice9 *device;
13630 IDirect3D9 *d3d;
13631 D3DCOLOR color;
13632 ULONG refcount;
13633 HWND window;
13634 HRESULT hr;
13636 window = create_window();
13637 d3d = Direct3DCreate9(D3D_SDK_VERSION);
13638 ok(!!d3d, "Failed to create a D3D object.\n");
13639 if (IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL,
13640 D3DFMT_X8R8G8B8, 0, D3DRTYPE_SURFACE, MAKEFOURCC('N','V','D','B')) != D3D_OK)
13642 skip("No NVDB (depth bounds test) support, skipping tests.\n");
13643 goto done;
13645 if (!(device = create_device(d3d, window, window, TRUE)))
13647 skip("Failed to create a D3D device, skipping tests.\n");
13648 goto done;
13651 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 32, 32,
13652 MAKEFOURCC('N','V','D','B'), D3DPOOL_DEFAULT, &offscreen_surface, NULL);
13653 ok(FAILED(hr), "Able to create surface, hr %#x.\n", hr);
13654 if (offscreen_surface) IDirect3DSurface9_Release(offscreen_surface);
13656 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0, 0);
13657 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
13659 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
13660 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13661 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, TRUE);
13662 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13663 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
13664 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13665 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_ALWAYS);
13666 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13669 hr = IDirect3DDevice9_BeginScene(device);
13670 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
13672 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
13673 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
13675 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(*quad1));
13676 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13678 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ADAPTIVETESS_X, MAKEFOURCC('N','V','D','B'));
13679 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13681 tmpvalue.f = 0.625;
13682 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ADAPTIVETESS_Z, tmpvalue.d);
13683 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13685 tmpvalue.f = 0.75;
13686 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ADAPTIVETESS_W, tmpvalue.d);
13687 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13689 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(*quad2));
13690 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13692 tmpvalue.f = 0.75;
13693 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ADAPTIVETESS_Z, tmpvalue.d);
13694 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13696 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, sizeof(*quad3));
13697 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13699 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ADAPTIVETESS_X, 0);
13700 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13702 hr = IDirect3DDevice9_EndScene(device);
13703 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
13705 color = getPixelColor(device, 150, 130);
13706 ok(color_match(color, 0x00f9e814, 1), "color 0x%08x.\n", color);
13707 color = getPixelColor(device, 150, 200);
13708 ok(color_match(color, 0x00f9e814, 1), "color 0x%08x.\n", color);
13709 color = getPixelColor(device, 150, 300-5);
13710 ok(color_match(color, 0x00f9e814, 1), "color 0x%08x.\n", color);
13711 color = getPixelColor(device, 150, 300+5);
13712 ok(color_match(color, 0x00002b7f, 1), "color 0x%08x.\n", color);/**/
13713 color = getPixelColor(device, 150, 330);
13714 ok(color_match(color, 0x00002b7f, 1), "color 0x%08x.\n", color);
13715 color = getPixelColor(device, 150, 360-5);
13716 ok(color_match(color, 0x00002b7f, 1), "color 0x%08x.\n", color);/**/
13717 color = getPixelColor(device, 150, 360+5);
13718 ok(color_match(color, 0x00f9e814, 1), "color 0x%08x.\n", color);
13720 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
13721 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
13722 refcount = IDirect3DDevice9_Release(device);
13723 ok(!refcount, "Device has %u references left.\n", refcount);
13724 done:
13725 IDirect3D9_Release(d3d);
13726 DestroyWindow(window);
13729 static void depth_buffer_test(void)
13731 static const struct
13733 struct vec3 position;
13734 DWORD diffuse;
13736 quad1[] =
13738 {{-1.0, 1.0, 0.33f}, 0xff00ff00},
13739 {{ 1.0, 1.0, 0.33f}, 0xff00ff00},
13740 {{-1.0, -1.0, 0.33f}, 0xff00ff00},
13741 {{ 1.0, -1.0, 0.33f}, 0xff00ff00},
13743 quad2[] =
13745 {{-1.0, 1.0, 0.50f}, 0xffff00ff},
13746 {{ 1.0, 1.0, 0.50f}, 0xffff00ff},
13747 {{-1.0, -1.0, 0.50f}, 0xffff00ff},
13748 {{ 1.0, -1.0, 0.50f}, 0xffff00ff},
13750 quad3[] =
13752 {{-1.0, 1.0, 0.66f}, 0xffff0000},
13753 {{ 1.0, 1.0, 0.66f}, 0xffff0000},
13754 {{-1.0, -1.0, 0.66f}, 0xffff0000},
13755 {{ 1.0, -1.0, 0.66f}, 0xffff0000},
13757 static const DWORD expected_colors[4][4] =
13759 {0x000000ff, 0x000000ff, 0x0000ff00, 0x00ff0000},
13760 {0x000000ff, 0x000000ff, 0x0000ff00, 0x00ff0000},
13761 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x00ff0000},
13762 {0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000},
13765 IDirect3DSurface9 *backbuffer, *rt1, *rt2, *rt3;
13766 IDirect3DDevice9 *device;
13767 unsigned int i, j;
13768 D3DVIEWPORT9 vp;
13769 IDirect3D9 *d3d;
13770 D3DCOLOR color;
13771 ULONG refcount;
13772 HWND window;
13773 HRESULT hr;
13775 window = create_window();
13776 d3d = Direct3DCreate9(D3D_SDK_VERSION);
13777 ok(!!d3d, "Failed to create a D3D object.\n");
13778 if (!(device = create_device(d3d, window, window, TRUE)))
13780 skip("Failed to create a D3D device, skipping tests.\n");
13781 goto done;
13784 vp.X = 0;
13785 vp.Y = 0;
13786 vp.Width = 640;
13787 vp.Height = 480;
13788 vp.MinZ = 0.0;
13789 vp.MaxZ = 1.0;
13791 hr = IDirect3DDevice9_SetViewport(device, &vp);
13792 ok(SUCCEEDED(hr), "SetViewport failed, hr %#x.\n", hr);
13794 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
13795 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13796 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
13797 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13798 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
13799 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13800 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
13801 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13802 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
13803 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
13805 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &backbuffer);
13806 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
13807 hr = IDirect3DDevice9_CreateRenderTarget(device, 320, 240, D3DFMT_A8R8G8B8,
13808 D3DMULTISAMPLE_NONE, 0, FALSE, &rt1, NULL);
13809 ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
13810 hr = IDirect3DDevice9_CreateRenderTarget(device, 480, 360, D3DFMT_A8R8G8B8,
13811 D3DMULTISAMPLE_NONE, 0, FALSE, &rt2, NULL);
13812 ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
13813 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
13814 D3DMULTISAMPLE_NONE, 0, FALSE, &rt3, NULL);
13815 ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
13817 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt3);
13818 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
13819 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 0.0f, 0);
13820 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
13822 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
13823 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
13824 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
13825 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
13827 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt1);
13828 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
13829 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 0.0f, 0);
13830 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
13832 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt2);
13833 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
13834 hr = IDirect3DDevice9_BeginScene(device);
13835 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
13836 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(*quad2));
13837 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13838 hr = IDirect3DDevice9_EndScene(device);
13839 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
13841 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
13842 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
13844 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
13845 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13847 hr = IDirect3DDevice9_BeginScene(device);
13848 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
13849 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(*quad1));
13850 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13851 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, sizeof(*quad3));
13852 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13853 hr = IDirect3DDevice9_EndScene(device);
13854 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
13856 for (i = 0; i < 4; ++i)
13858 for (j = 0; j < 4; ++j)
13860 unsigned int x = 80 * ((2 * j) + 1);
13861 unsigned int y = 60 * ((2 * i) + 1);
13862 color = getPixelColor(device, x, y);
13863 ok(color_match(color, expected_colors[i][j], 0),
13864 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors[i][j], x, y, color);
13868 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
13869 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
13871 IDirect3DSurface9_Release(backbuffer);
13872 IDirect3DSurface9_Release(rt3);
13873 IDirect3DSurface9_Release(rt2);
13874 IDirect3DSurface9_Release(rt1);
13875 refcount = IDirect3DDevice9_Release(device);
13876 ok(!refcount, "Device has %u references left.\n", refcount);
13877 done:
13878 IDirect3D9_Release(d3d);
13879 DestroyWindow(window);
13882 /* Test that partial depth copies work the way they're supposed to. The clear
13883 * on rt2 only needs a partial copy of the onscreen depth/stencil buffer, and
13884 * the following draw should only copy back the part that was modified. */
13885 static void depth_buffer2_test(void)
13887 static const struct
13889 struct vec3 position;
13890 DWORD diffuse;
13892 quad[] =
13894 {{-1.0f, 1.0f, 0.66f}, 0xffff0000},
13895 {{ 1.0f, 1.0f, 0.66f}, 0xffff0000},
13896 {{-1.0f, -1.0f, 0.66f}, 0xffff0000},
13897 {{ 1.0f, -1.0f, 0.66f}, 0xffff0000},
13900 IDirect3DSurface9 *backbuffer, *rt1, *rt2;
13901 IDirect3DDevice9 *device;
13902 unsigned int i, j;
13903 D3DVIEWPORT9 vp;
13904 IDirect3D9 *d3d;
13905 D3DCOLOR color;
13906 ULONG refcount;
13907 HWND window;
13908 HRESULT hr;
13910 window = create_window();
13911 d3d = Direct3DCreate9(D3D_SDK_VERSION);
13912 ok(!!d3d, "Failed to create a D3D object.\n");
13913 if (!(device = create_device(d3d, window, window, TRUE)))
13915 skip("Failed to create a D3D device, skipping tests.\n");
13916 goto done;
13919 vp.X = 0;
13920 vp.Y = 0;
13921 vp.Width = 640;
13922 vp.Height = 480;
13923 vp.MinZ = 0.0;
13924 vp.MaxZ = 1.0;
13926 hr = IDirect3DDevice9_SetViewport(device, &vp);
13927 ok(SUCCEEDED(hr), "SetViewport failed, hr %#x.\n", hr);
13929 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
13930 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13931 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
13932 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13933 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
13934 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13935 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
13936 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13937 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
13938 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
13940 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
13941 D3DMULTISAMPLE_NONE, 0, FALSE, &rt1, NULL);
13942 ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
13943 hr = IDirect3DDevice9_CreateRenderTarget(device, 480, 360, D3DFMT_A8R8G8B8,
13944 D3DMULTISAMPLE_NONE, 0, FALSE, &rt2, NULL);
13945 ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
13946 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &backbuffer);
13947 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
13949 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt1);
13950 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
13951 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
13952 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
13954 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
13955 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
13956 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 0.5f, 0);
13957 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
13959 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt2);
13960 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
13961 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 0.0f, 0);
13962 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
13964 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
13965 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
13967 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
13968 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13970 hr = IDirect3DDevice9_BeginScene(device);
13971 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
13972 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
13973 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13974 hr = IDirect3DDevice9_EndScene(device);
13975 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
13977 for (i = 0; i < 4; ++i)
13979 for (j = 0; j < 4; ++j)
13981 unsigned int x = 80 * ((2 * j) + 1);
13982 unsigned int y = 60 * ((2 * i) + 1);
13983 color = getPixelColor(device, x, y);
13984 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 0),
13985 "Expected color 0x0000ff00 at %u,%u, got 0x%08x.\n", x, y, color);
13989 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
13990 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
13992 IDirect3DSurface9_Release(backbuffer);
13993 IDirect3DSurface9_Release(rt2);
13994 IDirect3DSurface9_Release(rt1);
13995 refcount = IDirect3DDevice9_Release(device);
13996 ok(!refcount, "Device has %u references left.\n", refcount);
13997 done:
13998 IDirect3D9_Release(d3d);
13999 DestroyWindow(window);
14002 static void depth_blit_test(void)
14004 static const struct
14006 struct vec3 position;
14007 DWORD diffuse;
14009 quad1[] =
14011 {{-1.0f, 1.0f, 0.33f}, 0xff00ff00},
14012 {{ 1.0f, 1.0f, 0.33f}, 0xff00ff00},
14013 {{-1.0f, -1.0f, 0.33f}, 0xff00ff00},
14014 {{ 1.0f, -1.0f, 0.33f}, 0xff00ff00},
14016 quad2[] =
14018 {{-1.0f, 1.0f, 0.66f}, 0xff0000ff},
14019 {{ 1.0f, 1.0f, 0.66f}, 0xff0000ff},
14020 {{-1.0f, -1.0f, 0.66f}, 0xff0000ff},
14021 {{ 1.0f, -1.0f, 0.66f}, 0xff0000ff},
14023 static const DWORD expected_colors[4][4] =
14025 {0x000000ff, 0x000000ff, 0x0000ff00, 0x00ff0000},
14026 {0x000000ff, 0x000000ff, 0x0000ff00, 0x00ff0000},
14027 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x00ff0000},
14028 {0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000},
14031 IDirect3DSurface9 *backbuffer, *ds1, *ds2, *ds3;
14032 IDirect3DDevice9 *device;
14033 RECT src_rect, dst_rect;
14034 unsigned int i, j;
14035 D3DVIEWPORT9 vp;
14036 IDirect3D9 *d3d;
14037 D3DCOLOR color;
14038 ULONG refcount;
14039 HWND window;
14040 HRESULT hr;
14042 window = create_window();
14043 d3d = Direct3DCreate9(D3D_SDK_VERSION);
14044 ok(!!d3d, "Failed to create a D3D object.\n");
14045 if (!(device = create_device(d3d, window, window, TRUE)))
14047 skip("Failed to create a D3D device, skipping tests.\n");
14048 goto done;
14051 vp.X = 0;
14052 vp.Y = 0;
14053 vp.Width = 640;
14054 vp.Height = 480;
14055 vp.MinZ = 0.0;
14056 vp.MaxZ = 1.0;
14058 hr = IDirect3DDevice9_SetViewport(device, &vp);
14059 ok(SUCCEEDED(hr), "SetViewport failed, hr %#x.\n", hr);
14061 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &backbuffer);
14062 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
14063 hr = IDirect3DDevice9_GetDepthStencilSurface(device, &ds1);
14064 ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
14065 hr = IDirect3DDevice9_CreateDepthStencilSurface(device, 640, 480, D3DFMT_D24S8, 0, 0, FALSE, &ds2, NULL);
14066 ok(SUCCEEDED(hr), "CreateDepthStencilSurface failed, hr %#x.\n", hr);
14067 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds2);
14068 ok(SUCCEEDED(hr), "SetDepthStencilSurface failed, hr %#x.\n", hr);
14069 hr = IDirect3DDevice9_CreateDepthStencilSurface(device, 320, 240, D3DFMT_D24S8, 0, 0, FALSE, &ds3, NULL);
14070 ok(SUCCEEDED(hr), "CreateDepthStencilSurface failed, hr %#x.\n", hr);
14072 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
14073 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14074 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
14075 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14076 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
14077 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14078 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
14079 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
14081 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
14082 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
14083 SetRect(&dst_rect, 0, 0, 480, 360);
14084 hr = IDirect3DDevice9_Clear(device, 1, (D3DRECT *)&dst_rect, D3DCLEAR_ZBUFFER, 0, 0.5f, 0);
14085 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
14086 SetRect(&dst_rect, 0, 0, 320, 240);
14087 hr = IDirect3DDevice9_Clear(device, 1, (D3DRECT *)&dst_rect, D3DCLEAR_ZBUFFER, 0, 1.0f, 0);
14088 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
14090 /* Partial blit. */
14091 SetRect(&src_rect, 0, 0, 320, 240);
14092 SetRect(&dst_rect, 0, 0, 320, 240);
14093 hr = IDirect3DDevice9_StretchRect(device, ds2, &src_rect, ds1, &dst_rect, D3DTEXF_POINT);
14094 ok(hr == D3DERR_INVALIDCALL, "StretchRect returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
14095 /* Flipped. */
14096 SetRect(&src_rect, 0, 0, 640, 480);
14097 SetRect(&dst_rect, 0, 480, 640, 0);
14098 hr = IDirect3DDevice9_StretchRect(device, ds2, &src_rect, ds1, &dst_rect, D3DTEXF_POINT);
14099 ok(hr == D3DERR_INVALIDCALL, "StretchRect returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
14100 /* Full, explicit. */
14101 SetRect(&src_rect, 0, 0, 640, 480);
14102 SetRect(&dst_rect, 0, 0, 640, 480);
14103 hr = IDirect3DDevice9_StretchRect(device, ds2, &src_rect, ds1, &dst_rect, D3DTEXF_POINT);
14104 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
14105 /* Filtered blit. */
14106 hr = IDirect3DDevice9_StretchRect(device, ds2, NULL, ds1, NULL, D3DTEXF_LINEAR);
14107 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
14108 /* Depth -> color blit.*/
14109 hr = IDirect3DDevice9_StretchRect(device, ds2, NULL, backbuffer, NULL, D3DTEXF_POINT);
14110 ok(hr == D3DERR_INVALIDCALL, "StretchRect returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
14111 IDirect3DSurface9_Release(backbuffer);
14112 /* Full surface, different sizes */
14113 hr = IDirect3DDevice9_StretchRect(device, ds3, NULL, ds1, NULL, D3DTEXF_POINT);
14114 ok(hr == D3DERR_INVALIDCALL, "StretchRect returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
14115 hr = IDirect3DDevice9_StretchRect(device, ds1, NULL, ds3, NULL, D3DTEXF_POINT);
14116 ok(hr == D3DERR_INVALIDCALL, "StretchRect returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
14118 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds1);
14119 ok(SUCCEEDED(hr), "SetDepthStencilSurface failed, hr %#x.\n", hr);
14120 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, 0xffff0000, 1.0f, 0);
14121 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
14122 hr = IDirect3DDevice9_StretchRect(device, ds2, NULL, ds1, NULL, D3DTEXF_POINT);
14123 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
14125 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
14126 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14127 hr = IDirect3DDevice9_BeginScene(device);
14128 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
14129 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(*quad1));
14130 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
14131 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(*quad2));
14132 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
14133 hr = IDirect3DDevice9_EndScene(device);
14134 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
14136 for (i = 0; i < 4; ++i)
14138 for (j = 0; j < 4; ++j)
14140 unsigned int x = 80 * ((2 * j) + 1);
14141 unsigned int y = 60 * ((2 * i) + 1);
14142 color = getPixelColor(device, x, y);
14143 ok(color_match(color, expected_colors[i][j], 0),
14144 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors[i][j], x, y, color);
14148 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
14149 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
14151 IDirect3DSurface9_Release(ds3);
14152 IDirect3DSurface9_Release(ds2);
14153 IDirect3DSurface9_Release(ds1);
14154 refcount = IDirect3DDevice9_Release(device);
14155 ok(!refcount, "Device has %u references left.\n", refcount);
14156 done:
14157 IDirect3D9_Release(d3d);
14158 DestroyWindow(window);
14161 static void intz_test(void)
14163 static const DWORD ps_code[] =
14165 0xffff0200, /* ps_2_0 */
14166 0x0200001f, 0x90000000, 0xa00f0800, /* dcl_2d s0 */
14167 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
14168 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0.0, 0.0, 0.0, 1.0 */
14169 0x02000001, 0x800f0001, 0xa0e40000, /* mov r1, c0 */
14170 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texld r0, t0, s0 */
14171 0x03010042, 0x800f0001, 0xb0e40000, 0xa0e40800, /* texldp r1, t0, s0 */
14172 0x02000001, 0x80020000, 0x80000001, /* mov r0.y, r1.x */
14173 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
14174 0x0000ffff, /* end */
14176 struct
14178 float x, y, z;
14179 float s, t, p, q;
14181 quad[] =
14183 { -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.5f},
14184 { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.5f},
14185 { -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f},
14186 { 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.5f},
14188 half_quad_1[] =
14190 { -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.5f},
14191 { 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.5f},
14192 { -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f},
14193 { 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.5f},
14195 half_quad_2[] =
14197 { -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.5f},
14198 { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.5f},
14199 { -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f},
14200 { 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.5f},
14202 struct
14204 UINT x, y;
14205 D3DCOLOR color;
14207 expected_colors[] =
14209 { 80, 100, 0x20204020},
14210 {240, 100, 0x6060bf60},
14211 {400, 100, 0x9f9f409f},
14212 {560, 100, 0xdfdfbfdf},
14213 { 80, 450, 0x20204020},
14214 {240, 450, 0x6060bf60},
14215 {400, 450, 0x9f9f409f},
14216 {560, 450, 0xdfdfbfdf},
14219 IDirect3DSurface9 *original_rt, *rt;
14220 struct surface_readback rb;
14221 IDirect3DTexture9 *texture;
14222 IDirect3DPixelShader9 *ps;
14223 IDirect3DDevice9 *device;
14224 IDirect3DSurface9 *ds;
14225 IDirect3D9 *d3d;
14226 ULONG refcount;
14227 D3DCAPS9 caps;
14228 HWND window;
14229 HRESULT hr;
14230 UINT i;
14232 window = create_window();
14233 d3d = Direct3DCreate9(D3D_SDK_VERSION);
14234 ok(!!d3d, "Failed to create a D3D object.\n");
14235 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
14236 D3DFMT_X8R8G8B8, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, MAKEFOURCC('I','N','T','Z'))))
14238 skip("No INTZ support, skipping INTZ test.\n");
14239 goto done;
14241 if (!(device = create_device(d3d, window, window, TRUE)))
14243 skip("Failed to create a D3D device, skipping tests.\n");
14244 goto done;
14247 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
14248 ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
14249 if (caps.PixelShaderVersion < D3DPS_VERSION(2, 0))
14251 skip("No pixel shader 2.0 support, skipping INTZ test.\n");
14252 IDirect3DDevice9_Release(device);
14253 goto done;
14255 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
14257 skip("No unconditional NP2 texture support, skipping INTZ test.\n");
14258 IDirect3DDevice9_Release(device);
14259 goto done;
14262 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &original_rt);
14263 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
14265 hr = IDirect3DDevice9_CreateTexture(device, 640, 480, 1,
14266 D3DUSAGE_DEPTHSTENCIL, MAKEFOURCC('I','N','T','Z'), D3DPOOL_DEFAULT, &texture, NULL);
14267 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
14268 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
14269 D3DMULTISAMPLE_NONE, 0, FALSE, &rt, NULL);
14270 ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
14271 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code, &ps);
14272 ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
14274 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE4(0));
14275 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
14276 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
14277 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14278 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_ALWAYS);
14279 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14280 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
14281 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14282 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
14283 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14285 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
14286 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
14287 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
14288 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
14289 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
14290 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
14291 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
14292 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
14293 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
14294 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
14296 /* Render offscreen, using the INTZ texture as depth buffer */
14297 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &ds);
14298 ok(SUCCEEDED(hr), "GetSurfaceLevel failed, hr %#x.\n", hr);
14299 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
14300 ok(SUCCEEDED(hr), "SetDepthStencilSurface failed, hr %#x.\n", hr);
14301 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
14302 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
14303 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
14304 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
14306 /* Setup the depth/stencil surface. */
14307 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
14308 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
14310 hr = IDirect3DDevice9_BeginScene(device);
14311 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
14312 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
14313 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
14314 hr = IDirect3DDevice9_EndScene(device);
14315 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
14317 hr = IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
14318 ok(SUCCEEDED(hr), "SetDepthStencilSurface failed, hr %#x.\n", hr);
14319 IDirect3DSurface9_Release(ds);
14320 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
14321 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
14322 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
14323 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
14324 hr = IDirect3DDevice9_SetPixelShader(device, ps);
14325 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
14327 /* Read the depth values back. */
14328 hr = IDirect3DDevice9_BeginScene(device);
14329 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
14330 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
14331 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
14332 hr = IDirect3DDevice9_EndScene(device);
14333 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
14335 get_rt_readback(original_rt, &rb);
14336 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
14338 D3DCOLOR color = get_readback_color(&rb, expected_colors[i].x, expected_colors[i].y);
14339 ok(color_match(color, expected_colors[i].color, 1),
14340 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
14341 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
14343 release_surface_readback(&rb);
14345 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
14346 ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
14348 hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
14349 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
14350 IDirect3DTexture9_Release(texture);
14352 /* Render onscreen while using the INTZ texture as depth buffer */
14353 hr = IDirect3DDevice9_CreateTexture(device, 640, 480, 1,
14354 D3DUSAGE_DEPTHSTENCIL, MAKEFOURCC('I','N','T','Z'), D3DPOOL_DEFAULT, &texture, NULL);
14355 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &ds);
14356 ok(SUCCEEDED(hr), "GetSurfaceLevel failed, hr %#x.\n", hr);
14357 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
14358 ok(SUCCEEDED(hr), "SetDepthStencilSurface failed, hr %#x.\n", hr);
14359 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
14360 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
14362 /* Setup the depth/stencil surface. */
14363 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
14364 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
14366 hr = IDirect3DDevice9_BeginScene(device);
14367 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
14368 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
14369 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
14370 hr = IDirect3DDevice9_EndScene(device);
14371 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
14373 hr = IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
14374 ok(SUCCEEDED(hr), "SetDepthStencilSurface failed, hr %#x.\n", hr);
14375 IDirect3DSurface9_Release(ds);
14376 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
14377 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
14378 hr = IDirect3DDevice9_SetPixelShader(device, ps);
14379 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
14381 /* Read the depth values back. */
14382 hr = IDirect3DDevice9_BeginScene(device);
14383 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
14384 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
14385 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
14386 hr = IDirect3DDevice9_EndScene(device);
14387 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
14389 get_rt_readback(original_rt, &rb);
14390 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
14392 D3DCOLOR color = get_readback_color(&rb, expected_colors[i].x, expected_colors[i].y);
14393 ok(color_match(color, expected_colors[i].color, 1),
14394 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
14395 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
14397 release_surface_readback(&rb);
14399 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
14400 ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
14402 hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
14403 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
14404 IDirect3DTexture9_Release(texture);
14406 /* Render offscreen, then onscreen, and finally check the INTZ texture in both areas */
14407 hr = IDirect3DDevice9_CreateTexture(device, 640, 480, 1,
14408 D3DUSAGE_DEPTHSTENCIL, MAKEFOURCC('I','N','T','Z'), D3DPOOL_DEFAULT, &texture, NULL);
14409 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &ds);
14410 ok(SUCCEEDED(hr), "GetSurfaceLevel failed, hr %#x.\n", hr);
14412 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
14413 ok(SUCCEEDED(hr), "SetDepthStencilSurface failed, hr %#x.\n", hr);
14414 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
14415 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
14416 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
14417 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
14419 /* Setup the depth/stencil surface. */
14420 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
14421 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
14423 hr = IDirect3DDevice9_BeginScene(device);
14424 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
14425 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, half_quad_1, sizeof(*half_quad_1));
14426 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
14427 hr = IDirect3DDevice9_EndScene(device);
14428 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
14430 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
14431 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
14433 hr = IDirect3DDevice9_BeginScene(device);
14434 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
14435 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, half_quad_2, sizeof(*half_quad_2));
14436 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
14437 hr = IDirect3DDevice9_EndScene(device);
14438 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
14440 hr = IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
14441 ok(SUCCEEDED(hr), "SetDepthStencilSurface failed, hr %#x.\n", hr);
14442 IDirect3DSurface9_Release(ds);
14443 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
14444 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
14445 hr = IDirect3DDevice9_SetPixelShader(device, ps);
14446 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
14448 /* Read the depth values back. */
14449 hr = IDirect3DDevice9_BeginScene(device);
14450 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
14451 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
14452 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
14453 hr = IDirect3DDevice9_EndScene(device);
14454 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
14456 get_rt_readback(original_rt, &rb);
14457 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
14459 D3DCOLOR color = get_readback_color(&rb, expected_colors[i].x, expected_colors[i].y);
14460 ok(color_match(color, expected_colors[i].color, 1),
14461 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
14462 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
14464 release_surface_readback(&rb);
14466 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
14467 ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
14469 IDirect3DTexture9_Release(texture);
14470 IDirect3DPixelShader9_Release(ps);
14471 IDirect3DSurface9_Release(original_rt);
14472 IDirect3DSurface9_Release(rt);
14473 refcount = IDirect3DDevice9_Release(device);
14474 ok(!refcount, "Device has %u references left.\n", refcount);
14475 done:
14476 IDirect3D9_Release(d3d);
14477 DestroyWindow(window);
14480 static void shadow_test(void)
14482 static const DWORD ps_code[] =
14484 0xffff0200, /* ps_2_0 */
14485 0x0200001f, 0x90000000, 0xa00f0800, /* dcl_2d s0 */
14486 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
14487 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0.0, 0.0, 0.0, 1.0 */
14488 0x02000001, 0x800f0001, 0xa0e40000, /* mov r1, c0 */
14489 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texld r0, t0, s0 */
14490 0x03010042, 0x800f0001, 0xb0e40000, 0xa0e40800, /* texldp r1, t0, s0 */
14491 0x02000001, 0x80020000, 0x80000001, /* mov r0.y, r1.x */
14492 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
14493 0x0000ffff, /* end */
14495 struct
14497 D3DFORMAT format;
14498 const char *name;
14500 formats[] =
14502 {D3DFMT_D16_LOCKABLE, "D3DFMT_D16_LOCKABLE"},
14503 {D3DFMT_D32, "D3DFMT_D32"},
14504 {D3DFMT_D15S1, "D3DFMT_D15S1"},
14505 {D3DFMT_D24S8, "D3DFMT_D24S8"},
14506 {D3DFMT_D24X8, "D3DFMT_D24X8"},
14507 {D3DFMT_D24X4S4, "D3DFMT_D24X4S4"},
14508 {D3DFMT_D16, "D3DFMT_D16"},
14509 {D3DFMT_D32F_LOCKABLE, "D3DFMT_D32F_LOCKABLE"},
14510 {D3DFMT_D24FS8, "D3DFMT_D24FS8"},
14512 struct
14514 float x, y, z;
14515 float s, t, p, q;
14517 quad[] =
14519 { -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f},
14520 { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f},
14521 { -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
14522 { 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f},
14524 struct
14526 UINT x, y;
14527 D3DCOLOR color;
14529 expected_colors[] =
14531 {400, 60, 0x00000000},
14532 {560, 180, 0xffff00ff},
14533 {560, 300, 0xffff00ff},
14534 {400, 420, 0xffffffff},
14535 {240, 420, 0xffffffff},
14536 { 80, 300, 0x00000000},
14537 { 80, 180, 0x00000000},
14538 {240, 60, 0x00000000},
14541 IDirect3DSurface9 *original_ds, *original_rt, *rt;
14542 struct surface_readback rb;
14543 IDirect3DPixelShader9 *ps;
14544 IDirect3DDevice9 *device;
14545 IDirect3D9 *d3d;
14546 ULONG refcount;
14547 D3DCAPS9 caps;
14548 HWND window;
14549 HRESULT hr;
14550 UINT i;
14552 window = create_window();
14553 d3d = Direct3DCreate9(D3D_SDK_VERSION);
14554 ok(!!d3d, "Failed to create a D3D object.\n");
14555 if (!(device = create_device(d3d, window, window, TRUE)))
14557 skip("Failed to create a D3D device, skipping tests.\n");
14558 goto done;
14561 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
14562 ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
14563 if (caps.PixelShaderVersion < D3DPS_VERSION(2, 0))
14565 skip("No pixel shader 2.0 support, skipping shadow test.\n");
14566 IDirect3DDevice9_Release(device);
14567 goto done;
14570 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &original_rt);
14571 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
14572 hr = IDirect3DDevice9_GetDepthStencilSurface(device, &original_ds);
14573 ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
14575 hr = IDirect3DDevice9_CreateRenderTarget(device, 1024, 1024, D3DFMT_A8R8G8B8,
14576 D3DMULTISAMPLE_NONE, 0, FALSE, &rt, NULL);
14577 ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
14578 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code, &ps);
14579 ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
14581 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE4(0));
14582 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
14583 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
14584 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14585 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_ALWAYS);
14586 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14587 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
14588 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14589 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
14590 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14592 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
14593 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
14594 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
14595 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
14596 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
14597 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
14598 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
14599 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
14600 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
14601 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
14603 for (i = 0; i < sizeof(formats) / sizeof(*formats); ++i)
14605 D3DFORMAT format = formats[i].format;
14606 IDirect3DTexture9 *texture;
14607 IDirect3DSurface9 *ds;
14608 unsigned int j;
14610 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
14611 D3DFMT_X8R8G8B8, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, format)))
14612 continue;
14614 hr = IDirect3DDevice9_CreateTexture(device, 1024, 1024, 1,
14615 D3DUSAGE_DEPTHSTENCIL, format, D3DPOOL_DEFAULT, &texture, NULL);
14616 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
14618 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &ds);
14619 ok(SUCCEEDED(hr), "GetSurfaceLevel failed, hr %#x.\n", hr);
14621 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
14622 ok(SUCCEEDED(hr), "SetDepthStencilSurface failed, hr %#x.\n", hr);
14624 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
14625 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
14627 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
14628 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
14630 /* Setup the depth/stencil surface. */
14631 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
14632 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
14634 hr = IDirect3DDevice9_BeginScene(device);
14635 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
14636 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
14637 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
14638 hr = IDirect3DDevice9_EndScene(device);
14639 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
14641 hr = IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
14642 ok(SUCCEEDED(hr), "SetDepthStencilSurface failed, hr %#x.\n", hr);
14643 IDirect3DSurface9_Release(ds);
14645 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
14646 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
14648 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
14649 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
14651 hr = IDirect3DDevice9_SetPixelShader(device, ps);
14652 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
14654 /* Do the actual shadow mapping. */
14655 hr = IDirect3DDevice9_BeginScene(device);
14656 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
14657 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
14658 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
14659 hr = IDirect3DDevice9_EndScene(device);
14660 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
14662 hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
14663 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
14664 IDirect3DTexture9_Release(texture);
14666 get_rt_readback(original_rt, &rb);
14667 for (j = 0; j < sizeof(expected_colors) / sizeof(*expected_colors); ++j)
14669 D3DCOLOR color = get_readback_color(&rb, expected_colors[j].x, expected_colors[j].y);
14670 ok(color_match(color, expected_colors[j].color, 0),
14671 "Expected color 0x%08x at (%u, %u) for format %s, got 0x%08x.\n",
14672 expected_colors[j].color, expected_colors[j].x, expected_colors[j].y,
14673 formats[i].name, color);
14675 release_surface_readback(&rb);
14677 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
14678 ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
14681 IDirect3DPixelShader9_Release(ps);
14682 IDirect3DSurface9_Release(original_ds);
14683 IDirect3DSurface9_Release(original_rt);
14684 IDirect3DSurface9_Release(rt);
14685 refcount = IDirect3DDevice9_Release(device);
14686 ok(!refcount, "Device has %u references left.\n", refcount);
14687 done:
14688 IDirect3D9_Release(d3d);
14689 DestroyWindow(window);
14692 static void clip_planes(IDirect3DDevice9 *device, const char *test_name)
14694 static const struct
14696 struct vec3 position;
14697 DWORD diffuse;
14699 quad1[] =
14701 {{-1.0f, -1.0f, 0.0f}, 0xfff9e814},
14702 {{-1.0f, 1.0f, 0.0f}, 0xfff9e814},
14703 {{ 1.0f, -1.0f, 0.0f}, 0xfff9e814},
14704 {{ 1.0f, 1.0f, 0.0f}, 0xfff9e814},
14706 quad2[] =
14708 {{-1.0f, -1.0f, 0.0f}, 0xff002b7f},
14709 {{-1.0f, 1.0f, 0.0f}, 0xff002b7f},
14710 {{ 1.0f, -1.0f, 0.0f}, 0xff002b7f},
14711 {{ 1.0f, 1.0f, 0.0f}, 0xff002b7f},
14713 D3DCOLOR color;
14714 HRESULT hr;
14716 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 1.0, 0);
14717 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
14719 hr = IDirect3DDevice9_BeginScene(device);
14720 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
14722 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
14723 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
14725 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPLANEENABLE, 0);
14726 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14727 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(*quad1));
14728 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
14730 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPLANEENABLE, 0x1);
14731 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14732 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(*quad2));
14733 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
14735 hr = IDirect3DDevice9_EndScene(device);
14736 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
14738 color = getPixelColor(device, 1, 240);
14739 ok(color_match(color, 0x00002b7f, 1), "%s test: color 0x%08x.\n", test_name, color);
14740 color = getPixelColor(device, 638, 240);
14741 ok(color_match(color, 0x00002b7f, 1), "%s test: color 0x%08x.\n", test_name, color);
14743 color = getPixelColor(device, 1, 241);
14744 ok(color_match(color, 0x00f9e814, 1), "%s test: color 0x%08x.\n", test_name, color);
14745 color = getPixelColor(device, 638, 241);
14746 ok(color_match(color, 0x00f9e814, 1), "%s test: color 0x%08x.\n", test_name, color);
14749 static void clip_planes_test(void)
14751 IDirect3DSurface9 *offscreen_surface, *original_rt;
14752 IDirect3DTexture9 *offscreen = NULL;
14753 IDirect3DVertexShader9 *shader;
14754 IDirect3DDevice9 *device;
14755 IDirect3D9 *d3d;
14756 ULONG refcount;
14757 D3DCAPS9 caps;
14758 HWND window;
14759 HRESULT hr;
14761 static const float plane0[4] = {0.0f, 1.0f, 0.0f, 0.5f / 480.0f}; /* a quarter-pixel offset */
14762 static const DWORD shader_code[] =
14764 0xfffe0200, /* vs_2_0 */
14765 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
14766 0x0200001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
14767 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
14768 0x02000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
14769 0x0000ffff /* end */
14772 window = create_window();
14773 d3d = Direct3DCreate9(D3D_SDK_VERSION);
14774 ok(!!d3d, "Failed to create a D3D object.\n");
14775 if (!(device = create_device(d3d, window, window, TRUE)))
14777 skip("Failed to create a D3D device, skipping tests.\n");
14778 goto done;
14781 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
14782 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
14783 if (caps.VertexShaderVersion < D3DVS_VERSION(2, 0))
14785 skip("No vs_2_0 support, skipping tests.\n");
14786 IDirect3DDevice9_Release(device);
14787 goto done;
14790 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &original_rt);
14791 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
14793 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
14794 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14795 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
14796 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14797 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
14798 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14799 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, TRUE);
14800 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14802 hr = IDirect3DDevice9_SetVertexShader(device, NULL);
14803 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShader failed, hr=%08x\n", hr);
14804 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
14805 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader failed, hr=%08x\n", hr);
14807 IDirect3DDevice9_SetClipPlane(device, 0, plane0);
14809 clip_planes(device, "Onscreen FFP");
14811 hr = IDirect3DDevice9_CreateTexture(device, 640, 480, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &offscreen, NULL);
14812 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
14813 hr = IDirect3DTexture9_GetSurfaceLevel(offscreen, 0, &offscreen_surface);
14814 ok(SUCCEEDED(hr), "GetSurfaceLevel failed, hr %#x.\n", hr);
14815 hr = IDirect3DDevice9_SetRenderTarget(device, 0, offscreen_surface);
14816 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderTarget failed, hr=%08x\n", hr);
14818 clip_planes(device, "Offscreen FFP");
14820 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
14821 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
14823 hr = IDirect3DDevice9_CreateVertexShader(device, shader_code, &shader);
14824 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
14825 hr = IDirect3DDevice9_SetVertexShader(device, shader);
14826 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShader returned %08x\n", hr);
14828 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
14829 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderTarget failed, hr=%08x\n", hr);
14831 clip_planes(device, "Onscreen vertex shader");
14833 hr = IDirect3DDevice9_SetRenderTarget(device, 0, offscreen_surface);
14834 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderTarget failed, hr=%08x\n", hr);
14836 clip_planes(device, "Offscreen vertex shader");
14838 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
14839 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
14841 IDirect3DVertexShader9_Release(shader);
14842 IDirect3DSurface9_Release(original_rt);
14843 IDirect3DSurface9_Release(offscreen_surface);
14844 IDirect3DTexture9_Release(offscreen);
14845 refcount = IDirect3DDevice9_Release(device);
14846 ok(!refcount, "Device has %u references left.\n", refcount);
14847 done:
14848 IDirect3D9_Release(d3d);
14849 DestroyWindow(window);
14852 static void fp_special_test(void)
14854 /* Microsoft's assembler generates nan and inf with "1.#QNAN" and "1.#INF." respectively */
14855 static const DWORD vs_header[] =
14857 0xfffe0200, /* vs_2_0 */
14858 0x05000051, 0xa00f0000, 0x00000000, 0x3f000000, 0x3f800000, 0x40000000, /* def c0, 0.0, 0.5, 1.0, 2.0 */
14859 0x05000051, 0xa00f0001, 0x7fc00000, 0xff800000, 0x7f800000, 0x00000000, /* def c1, nan, -inf, inf, 0 */
14860 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
14861 0x0200001f, 0x80000005, 0x900f0001, /* dcl_texcoord0 v1 */
14864 static const DWORD vs_log[] = {0x0200000f, 0x80010000, 0x90000001}; /* log r0.x, v1.x */
14865 static const DWORD vs_pow[] =
14866 {0x03000020, 0x80010000, 0x90000001, 0x90000001}; /* pow r0.x, v1.x, v1.x */
14867 static const DWORD vs_nrm[] = {0x02000024, 0x80070000, 0x90000001}; /* nrm r0.xyz, v1.x */
14868 static const DWORD vs_rcp1[] = {0x02000006, 0x80010000, 0x90000001}; /* rcp r0.x, v1.x */
14869 static const DWORD vs_rcp2[] = {0x02000006, 0x80010000, 0x91000001}; /* rcp r0.x, -v1.x */
14870 static const DWORD vs_rsq1[] = {0x02000007, 0x80010000, 0x90000001}; /* rsq r0.x, v1.x */
14871 static const DWORD vs_rsq2[] = {0x02000007, 0x80010000, 0x91000001}; /* rsq r0.x, -v1.x */
14872 static const DWORD vs_lit[] = {0x02000010, 0x800f0000, 0x90000001, /* lit r0, v1.xxxx */
14873 0x02000001, 0x80010000, 0x80aa0000}; /* mov r0.x, v0.z */
14874 static const DWORD vs_def1[] = {0x02000001, 0x80010000, 0xa0000001}; /* mov r0.x, c1.x */
14875 static const DWORD vs_def2[] = {0x02000001, 0x80010000, 0xa0550001}; /* mov r0.x, c1.y */
14876 static const DWORD vs_def3[] = {0x02000001, 0x80010000, 0xa0aa0001}; /* mov r0.x, c1.z */
14878 static const DWORD vs_footer[] =
14880 0x03000005, 0x80020000, 0x80000000, 0xa0ff0000, /* mul r0.y, r0.x, c0.w */
14881 0x0300000d, 0x80040000, 0x80000000, 0x80550000, /* sge r0.z, r0.x, r0.y */
14882 0x0300000d, 0x80020000, 0x80e40000, 0x80000000, /* sge r0.y, r0, r0.x */
14883 0x03000005, 0x80040000, 0x80550000, 0x80e40000, /* mul r0.z, r0.y, r0 */
14884 0x0300000b, 0x80080000, 0x81aa0000, 0x80aa0000, /* max r0.w, -r0.z, r0.z */
14885 0x0300000c, 0x80020000, 0x80000000, 0x80000000, /* slt r0.y, r0.x, r0.x */
14886 0x03000002, 0x80040000, 0x80550000, 0x80550000, /* add r0.z, r0.y, r0.y */
14887 0x0300000c, 0x80020000, 0xa0000000, 0x80ff0000, /* slt r0.y, c0.x, r0.w */
14888 0x0300000b, 0x80080000, 0x81aa0000, 0x80aa0000, /* max r0.w, -r0.z, r0.z */
14889 0x03000002, 0x80040000, 0x81550000, 0xa0e40000, /* add r0.z, -r0.y, c0 */
14890 0x0300000c, 0x80080000, 0xa0000000, 0x80e40000, /* slt r0.w, c0.x, r0 */
14891 0x03000005, 0x80040000, 0x80ff0000, 0x80e40000, /* mul r0.z, r0.w, r0 */
14892 0x04000004, 0x80020000, 0x80aa0000, 0xa0e40000, 0x80e40000, /* mad r0.y, r0.z, c0, r0 */
14893 0x02000001, 0xe0030000, 0x80e40000, /* mov oT0.xy, r0 */
14894 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
14895 0x0000ffff, /* end */
14898 static const struct
14900 const char *name;
14901 const DWORD *ops;
14902 DWORD size;
14903 D3DCOLOR r500;
14904 D3DCOLOR r600;
14905 D3DCOLOR nv40;
14906 D3DCOLOR nv50;
14907 D3DCOLOR warp;
14909 vs_body[] =
14911 /* The basic ideas here are:
14912 * 2.0 * +/-INF == +/-INF
14913 * NAN != NAN
14915 * The vertex shader value is written to the red component, with 0.0
14916 * and +/-INF mapping to 0xff, and NAN to 0x7f. Anything else should
14917 * result in 0x00. The pixel shader value is written to the green
14918 * component, but here 0.0 also results in 0x00. The actual value is
14919 * written to the blue component.
14921 * There are considerable differences between graphics cards in how
14922 * these are handled, but pow and nrm never generate INF or NAN on
14923 * real hardware. */
14924 {"log", vs_log, sizeof(vs_log), 0x00000000, 0x00000000, 0x00ff0000, 0x00ff7f00, 0x00ff8000},
14925 {"pow", vs_pow, sizeof(vs_pow), 0x000000ff, 0x000000ff, 0x0000ff00, 0x000000ff, 0x00008000},
14926 {"nrm", vs_nrm, sizeof(vs_nrm), 0x00ff0000, 0x00ff0000, 0x0000ff00, 0x00ff0000, 0x00008000},
14927 {"rcp1", vs_rcp1, sizeof(vs_rcp1), 0x000000ff, 0x000000ff, 0x00ff00ff, 0x00ff7f00, 0x00ff8000},
14928 {"rcp2", vs_rcp2, sizeof(vs_rcp2), 0x000000ff, 0x00000000, 0x00ff0000, 0x00ff7f00, 0x00ff8000},
14929 {"rsq1", vs_rsq1, sizeof(vs_rsq1), 0x000000ff, 0x000000ff, 0x00ff00ff, 0x00ff7f00, 0x00ff8000},
14930 {"rsq2", vs_rsq2, sizeof(vs_rsq2), 0x000000ff, 0x000000ff, 0x00ff00ff, 0x00ff7f00, 0x00ff8000},
14931 {"lit", vs_lit, sizeof(vs_lit), 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000},
14932 {"def1", vs_def1, sizeof(vs_def1), 0x000000ff, 0x00007f00, 0x0000ff00, 0x00007f00, 0x00008000},
14933 {"def2", vs_def2, sizeof(vs_def2), 0x00ff0000, 0x00ff7f00, 0x00ff0000, 0x00ff7f00, 0x00ff8000},
14934 {"def3", vs_def3, sizeof(vs_def3), 0x00ff00ff, 0x00ff7f00, 0x00ff00ff, 0x00ff7f00, 0x00ff8000},
14937 static const DWORD ps_code[] =
14939 0xffff0200, /* ps_2_0 */
14940 0x05000051, 0xa00f0000, 0x00000000, 0x3f000000, 0x3f800000, 0x40000000, /* def c0, 0.0, 0.5, 1.0, 2.0 */
14941 0x0200001f, 0x80000000, 0xb0030000, /* dcl t0.xy */
14942 0x0300000b, 0x80010001, 0xb0e40000, 0xa0e40000, /* max r1.x, t0, c0 */
14943 0x0300000a, 0x80010000, 0xb0e40000, 0xa0e40000, /* min r0.x, t0, c0 */
14944 0x03000002, 0x80010000, 0x80e40000, 0x81e40001, /* add r0.x, r0, -r1 */
14945 0x04000004, 0x80010001, 0xb0e40000, 0xa0ff0000, 0xb1e40000, /* mad r1.x, t0, c0.w. -t0 */
14946 0x02000023, 0x80010002, 0x80e40001, /* abs r2.x, r1 */
14947 0x02000023, 0x80010000, 0x80e40000, /* abs r0.x, r0 */
14948 0x02000023, 0x80010001, 0xb0e40000, /* abs r1.x, t0 */
14949 0x04000058, 0x80010002, 0x81e40002, 0xa0aa0000, 0xa0e40000, /* cmp r2.x, -r2, c0.z, c0 */
14950 0x02000023, 0x80010002, 0x80e40002, /* abs r2.x, r2 */
14951 0x04000058, 0x80010001, 0x81e40001, 0xa0aa0000, 0xa0e40000, /* cmp r1.x, -r1, c0.z, c0 */
14952 0x02000023, 0x80010001, 0x80e40001, /* abs r1.x, r1 */
14953 0x04000058, 0x80010003, 0x81e40002, 0xa0aa0000, 0xa0e40000, /* cmp r3.x, -r2, c0.z, c0 */
14954 0x04000058, 0x80010002, 0x81e40001, 0xa0aa0000, 0xa0e40000, /* cmp r2.x, -r1, c0.z, c0 */
14955 0x04000058, 0x80010000, 0x81e40000, 0xa0550000, 0xa0e40000, /* cmp r0.x, -r0, c0.y, c0 */
14956 0x03000005, 0x80010002, 0x80e40002, 0x80e40003, /* mul r2.x, r2, r3 */
14957 0x04000058, 0x80010000, 0x81e40002, 0xa0aa0000, 0x80e40000, /* cmp r0.x, -r2, c0.z, r0 */
14958 0x04000058, 0x80020000, 0x81000001, 0x80000000, 0xa0000000, /* cmp r0.y, -r1.x, r0.x, c0.x */
14959 0x02000001, 0x80050000, 0xb0c90000, /* mov r0.xz, t0.yzxw */
14960 0x02000001, 0x80080000, 0xa0aa0000, /* mov r0.w, c0.z */
14961 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
14962 0x0000ffff, /* end */
14965 struct
14967 float x, y, z;
14968 float s;
14970 quad[] =
14972 { -1.0f, 1.0f, 0.0f, 0.0f},
14973 { 1.0f, 1.0f, 1.0f, 0.0f},
14974 { -1.0f, -1.0f, 0.0f, 0.0f},
14975 { 1.0f, -1.0f, 1.0f, 0.0f},
14978 IDirect3DPixelShader9 *ps;
14979 IDirect3DDevice9 *device;
14980 UINT body_size = 0;
14981 IDirect3D9 *d3d;
14982 DWORD *vs_code;
14983 ULONG refcount;
14984 D3DCAPS9 caps;
14985 HWND window;
14986 HRESULT hr;
14987 UINT i;
14989 window = create_window();
14990 d3d = Direct3DCreate9(D3D_SDK_VERSION);
14991 ok(!!d3d, "Failed to create a D3D object.\n");
14992 if (!(device = create_device(d3d, window, window, TRUE)))
14994 skip("Failed to create a D3D device, skipping tests.\n");
14995 goto done;
14998 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
14999 ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
15000 if (caps.PixelShaderVersion < D3DPS_VERSION(2, 0) || caps.VertexShaderVersion < D3DVS_VERSION(2, 0))
15002 skip("No shader model 2.0 support, skipping floating point specials test.\n");
15003 IDirect3DDevice9_Release(device);
15004 goto done;
15007 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE1(0));
15008 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
15010 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code, &ps);
15011 ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
15012 hr = IDirect3DDevice9_SetPixelShader(device, ps);
15013 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
15015 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
15016 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15018 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
15019 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
15021 for (i = 0; i < sizeof(vs_body) / sizeof(*vs_body); ++i)
15023 if (vs_body[i].size > body_size) body_size = vs_body[i].size;
15026 vs_code = HeapAlloc(GetProcessHeap(), 0, sizeof(vs_header) + body_size + sizeof(vs_footer));
15027 memcpy(vs_code, vs_header, sizeof(vs_header));
15029 for (i = 0; i < sizeof(vs_body) / sizeof(*vs_body); ++i)
15031 DWORD offset = sizeof(vs_header) / sizeof(*vs_header);
15032 IDirect3DVertexShader9 *vs;
15033 D3DCOLOR color;
15035 memcpy(vs_code + offset, vs_body[i].ops, vs_body[i].size);
15036 offset += vs_body[i].size / sizeof(*vs_body[i].ops);
15037 memcpy(vs_code + offset, vs_footer, sizeof(vs_footer));
15039 hr = IDirect3DDevice9_CreateVertexShader(device, vs_code, &vs);
15040 ok(SUCCEEDED(hr), "CreateVertexShader failed, hr %#x.\n", hr);
15041 hr = IDirect3DDevice9_SetVertexShader(device, vs);
15042 ok(SUCCEEDED(hr), "SetVertexShader failed, hr %#x.\n", hr);
15044 hr = IDirect3DDevice9_BeginScene(device);
15045 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
15046 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
15047 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
15048 hr = IDirect3DDevice9_EndScene(device);
15049 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
15051 color = getPixelColor(device, 320, 240);
15052 ok(color_match(color, vs_body[i].r500, 1)
15053 || color_match(color, vs_body[i].r600, 1)
15054 || color_match(color, vs_body[i].nv40, 1)
15055 || color_match(color, vs_body[i].nv50, 1)
15056 || broken(color_match(color, vs_body[i].warp, 1)),
15057 "Expected color 0x%08x, 0x%08x, 0x%08x or 0x%08x for instruction \"%s\", got 0x%08x.\n",
15058 vs_body[i].r500, vs_body[i].r600, vs_body[i].nv40, vs_body[i].nv50, vs_body[i].name, color);
15060 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
15061 ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
15063 hr = IDirect3DDevice9_SetVertexShader(device, NULL);
15064 ok(SUCCEEDED(hr), "SetVertexShader failed, hr %#x.\n", hr);
15065 IDirect3DVertexShader9_Release(vs);
15068 HeapFree(GetProcessHeap(), 0, vs_code);
15070 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
15071 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
15072 IDirect3DPixelShader9_Release(ps);
15073 refcount = IDirect3DDevice9_Release(device);
15074 ok(!refcount, "Device has %u references left.\n", refcount);
15075 done:
15076 IDirect3D9_Release(d3d);
15077 DestroyWindow(window);
15080 static void srgbwrite_format_test(void)
15082 IDirect3D9 *d3d;
15083 IDirect3DSurface9 *rt, *backbuffer;
15084 IDirect3DTexture9 *texture;
15085 IDirect3DDevice9 *device;
15086 ULONG refcount;
15087 HWND window;
15088 HRESULT hr;
15089 int i;
15090 DWORD color_rgb = 0x00808080, color_srgb = 0x00bcbcbc, color;
15091 static const struct
15093 D3DFORMAT fmt;
15094 const char *name;
15096 formats[] =
15098 { D3DFMT_R5G6B5, "D3DFMT_R5G6B5" },
15099 { D3DFMT_X8R8G8B8, "D3DFMT_X8R8G8B8" },
15100 { D3DFMT_A8R8G8B8, "D3DFMT_A8R8G8B8" },
15101 { D3DFMT_A16B16G16R16F, "D3DFMT_A16B16G16R16F" },
15102 { D3DFMT_A32B32G32R32F, "D3DFMT_A32B32G32R32F" },
15104 static const struct
15106 float x, y, z;
15107 float u, v;
15109 quad[] =
15111 {-1.0f, -1.0f, 0.1f, 0.0f, 0.0f},
15112 {-1.0f, 1.0f, 0.1f, 1.0f, 0.0f},
15113 { 1.0f, -1.0f, 0.1f, 0.0f, 1.0f},
15114 { 1.0f, 1.0f, 0.1f, 1.0f, 1.0f}
15117 window = create_window();
15118 d3d = Direct3DCreate9(D3D_SDK_VERSION);
15119 ok(!!d3d, "Failed to create a D3D object.\n");
15120 if (!(device = create_device(d3d, window, window, TRUE)))
15122 skip("Failed to create a D3D device, skipping tests.\n");
15123 goto done;
15126 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
15127 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
15128 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
15129 ok(SUCCEEDED(hr), "GetBackBuffer failed, hr %#x.\n", hr);
15130 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
15131 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
15132 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0x80808080);
15133 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15135 for(i = 0; i < (sizeof(formats) / sizeof(*formats)); i++)
15137 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
15138 D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, formats[i].fmt)))
15140 skip("Format %s not supported as render target, skipping test.\n",
15141 formats[i].name);
15142 continue;
15145 hr = IDirect3DDevice9_CreateTexture(device, 8, 8, 1, D3DUSAGE_RENDERTARGET,
15146 formats[i].fmt, D3DPOOL_DEFAULT, &texture, NULL);
15147 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
15148 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff0000, 1.0f, 0);
15149 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
15151 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &rt);
15152 ok(SUCCEEDED(hr), "GetSurfaceLevel failed, hr %#x.\n", hr);
15153 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
15154 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
15155 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x000000ff, 0.0f, 0);
15156 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
15158 hr = IDirect3DDevice9_BeginScene(device);
15159 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
15161 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SRGBWRITEENABLE, TRUE);
15162 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
15163 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
15164 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
15165 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
15166 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
15168 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SRGBWRITEENABLE, FALSE);
15169 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
15170 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
15171 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
15172 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) texture);
15173 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
15174 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
15175 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
15176 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
15177 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
15178 hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
15179 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
15181 hr = IDirect3DDevice9_EndScene(device);
15182 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
15184 IDirect3DSurface9_Release(rt);
15185 IDirect3DTexture9_Release(texture);
15187 color = getPixelColor(device, 360, 240);
15188 if(IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
15189 D3DUSAGE_QUERY_SRGBWRITE,
15190 D3DRTYPE_TEXTURE, formats[i].fmt) == D3D_OK)
15192 /* Big slop for R5G6B5 */
15193 ok(color_match(color, color_srgb, 5), "Format %s supports srgb, expected color 0x%08x, got 0x%08x\n",
15194 formats[i].name, color_srgb, color);
15196 else
15198 /* Big slop for R5G6B5 */
15199 ok(color_match(color, color_rgb, 5), "Format %s does not support srgb, expected color 0x%08x, got 0x%08x\n",
15200 formats[i].name, color_rgb, color);
15203 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
15204 ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
15207 IDirect3DSurface9_Release(backbuffer);
15208 refcount = IDirect3DDevice9_Release(device);
15209 ok(!refcount, "Device has %u references left.\n", refcount);
15210 done:
15211 IDirect3D9_Release(d3d);
15212 DestroyWindow(window);
15215 static void ds_size_test(void)
15217 IDirect3DSurface9 *ds, *rt, *old_rt, *old_ds, *readback;
15218 IDirect3DDevice9 *device;
15219 DWORD num_passes;
15220 IDirect3D9 *d3d;
15221 ULONG refcount;
15222 HWND window;
15223 HRESULT hr;
15225 static const struct
15227 float x, y, z;
15229 quad[] =
15231 {-1.0f, -1.0f, 0.0f},
15232 {-1.0f, 1.0f, 0.0f},
15233 { 1.0f, -1.0f, 0.0f},
15234 { 1.0f, 1.0f, 0.0f},
15237 window = create_window();
15238 d3d = Direct3DCreate9(D3D_SDK_VERSION);
15239 ok(!!d3d, "Failed to create a D3D object.\n");
15240 if (!(device = create_device(d3d, window, window, TRUE)))
15242 skip("Failed to create a D3D device, skipping tests.\n");
15243 goto done;
15246 hr = IDirect3DDevice9_CreateRenderTarget(device, 64, 64, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, FALSE, &rt, NULL);
15247 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateRenderTarget failed, hr %#x.\n", hr);
15248 hr = IDirect3DDevice9_CreateDepthStencilSurface(device, 32, 32, D3DFMT_D24X8, D3DMULTISAMPLE_NONE, 0, TRUE, &ds, NULL);
15249 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateDepthStencilSurface failed, hr %#x.\n", hr);
15250 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 64, 64, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &readback, NULL);
15251 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateOffscreenPlainSurface failed, hr %#x.\n", hr);
15253 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
15254 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
15256 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
15257 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr);
15258 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILENABLE, FALSE);
15259 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr);
15260 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
15261 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr);
15262 hr = IDirect3DDevice9_ValidateDevice(device, &num_passes);
15263 ok(SUCCEEDED(hr), "IDirect3DDevice9_ValidateDevice failed, hr %#x.\n", hr);
15264 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &old_rt);
15265 ok(SUCCEEDED(hr), "IDirect3DDevice9_GetRenderTarget failed, hr %#x.\n", hr);
15266 hr = IDirect3DDevice9_GetDepthStencilSurface(device, &old_ds);
15267 ok(SUCCEEDED(hr), "IDirect3DDevice9_GetDepthStencilSurface failed, hr %#x.\n", hr);
15268 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
15269 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderTarget failed, hr %#x.\n", hr);
15270 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
15271 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetDepthStencilSurface failed, hr %#x.\n", hr);
15272 hr = IDirect3DDevice9_ValidateDevice(device, &num_passes);
15273 ok(SUCCEEDED(hr), "IDirect3DDevice9_ValidateDevice failed, hr %#x.\n", hr);
15275 /* The D3DCLEAR_TARGET clear works. D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER returns OK,
15276 * but does not change the surface's contents. */
15277 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x000000FF, 0.0f, 0);
15278 ok(SUCCEEDED(hr), "Target clear failed, hr %#x.\n", hr);
15279 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0x00000000, 0.2f, 0);
15280 ok(SUCCEEDED(hr), "Z Buffer clear failed, hr %#x.\n", hr);
15281 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff0000, 0.5f, 0);
15282 ok(SUCCEEDED(hr), "Target and Z Buffer clear failed, hr %#x.\n", hr);
15284 /* Nvidia does not clear the surface(The color is still 0x000000ff), AMD does(the color is 0x00ff0000) */
15286 /* Turning on any depth-related state results in a ValidateDevice failure */
15287 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
15288 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr);
15289 hr = IDirect3DDevice9_ValidateDevice(device, &num_passes);
15290 ok(hr == D3DERR_CONFLICTINGRENDERSTATE || hr == D3D_OK, "IDirect3DDevice9_ValidateDevice returned %#x, expected "
15291 "D3DERR_CONFLICTINGRENDERSTATE.\n", hr);
15292 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
15293 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr);
15294 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
15295 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr);
15296 hr = IDirect3DDevice9_ValidateDevice(device, &num_passes);
15297 ok(hr == D3DERR_CONFLICTINGRENDERSTATE || hr == D3D_OK, "IDirect3DDevice9_ValidateDevice returned %#x, expected "
15298 "D3DERR_CONFLICTINGRENDERSTATE.\n", hr);
15300 /* Try to draw with the device in an invalid state. */
15301 hr = IDirect3DDevice9_BeginScene(device);
15302 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
15303 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
15304 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
15305 hr = IDirect3DDevice9_EndScene(device);
15306 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
15308 /* Don't check the resulting draw unless we find an app that needs it. On
15309 * NVIDIA ValidateDevice() returns CONFLICTINGRENDERSTATE, so the result
15310 * is undefined. On AMD D3D seems to assume the stored Z buffer value is
15311 * 0.0 for all pixels, even those that are covered by the depth buffer. */
15313 hr = IDirect3DDevice9_SetRenderTarget(device, 0, old_rt);
15314 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderTarget failed, hr %#x.\n", hr);
15315 hr = IDirect3DDevice9_SetDepthStencilSurface(device, old_ds);
15316 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetDepthStencilSurface failed, hr %#x.\n", hr);
15317 hr = IDirect3DDevice9_ValidateDevice(device, &num_passes);
15318 ok(SUCCEEDED(hr), "IDirect3DDevice9_ValidateDevice failed, hr %#x.\n", hr);
15320 IDirect3DSurface9_Release(readback);
15321 IDirect3DSurface9_Release(ds);
15322 IDirect3DSurface9_Release(rt);
15323 IDirect3DSurface9_Release(old_rt);
15324 IDirect3DSurface9_Release(old_ds);
15325 refcount = IDirect3DDevice9_Release(device);
15326 ok(!refcount, "Device has %u references left.\n", refcount);
15327 done:
15328 IDirect3D9_Release(d3d);
15329 DestroyWindow(window);
15332 static void unbound_sampler_test(void)
15334 IDirect3DPixelShader9 *ps, *ps_cube, *ps_volume;
15335 IDirect3DSurface9 *rt, *old_rt;
15336 IDirect3DDevice9 *device;
15337 IDirect3D9 *d3d;
15338 ULONG refcount;
15339 D3DCAPS9 caps;
15340 DWORD color;
15341 HWND window;
15342 HRESULT hr;
15344 static const DWORD ps_code[] =
15346 0xffff0200, /* ps_2_0 */
15347 0x0200001f, 0x90000000, 0xa00f0800, /* dcl_2d s0 */
15348 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
15349 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texld r0, t0, s0 */
15350 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
15351 0x0000ffff, /* end */
15353 static const DWORD ps_code_cube[] =
15355 0xffff0200, /* ps_2_0 */
15356 0x0200001f, 0x98000000, 0xa00f0800, /* dcl_cube s0 */
15357 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
15358 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texld r0, t0, s0 */
15359 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
15360 0x0000ffff, /* end */
15362 static const DWORD ps_code_volume[] =
15364 0xffff0200, /* ps_2_0 */
15365 0x0200001f, 0xa0000000, 0xa00f0800, /* dcl_volume s0 */
15366 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
15367 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texld r0, t0, s0 */
15368 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
15369 0x0000ffff, /* end */
15372 static const struct
15374 float x, y, z;
15375 float u, v;
15377 quad[] =
15379 {-1.0f, -1.0f, 0.1f, 0.0f, 0.0f},
15380 {-1.0f, 1.0f, 0.1f, 1.0f, 0.0f},
15381 { 1.0f, -1.0f, 0.1f, 0.0f, 1.0f},
15382 { 1.0f, 1.0f, 0.1f, 1.0f, 1.0f}
15385 window = create_window();
15386 d3d = Direct3DCreate9(D3D_SDK_VERSION);
15387 ok(!!d3d, "Failed to create a D3D object.\n");
15388 if (!(device = create_device(d3d, window, window, TRUE)))
15390 skip("Failed to create a D3D device, skipping tests.\n");
15391 goto done;
15394 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
15395 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
15396 if (caps.PixelShaderVersion < D3DPS_VERSION(2, 0))
15398 skip("No ps_2_0 support, skipping tests.\n");
15399 IDirect3DDevice9_Release(device);
15400 goto done;
15402 if (!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP) || !(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
15404 skip("No cube / volume texture support, skipping tests.\n");
15405 IDirect3DDevice9_Release(device);
15406 goto done;
15409 hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
15410 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStage failed, %#x.\n", hr);
15412 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code, &ps);
15413 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreatePixelShader failed, hr %#x.\n", hr);
15414 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code_cube, &ps_cube);
15415 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreatePixelShader failed, hr %#x.\n", hr);
15416 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code_volume, &ps_volume);
15417 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreatePixelShader failed, hr %#x.\n", hr);
15419 hr = IDirect3DDevice9_CreateRenderTarget(device, 64, 64, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, TRUE, &rt, NULL);
15420 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateRenderTarget failed, hr %#x.\n", hr);
15422 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &old_rt);
15423 ok(SUCCEEDED(hr), "IDirect3DDevice9_GetRenderTarget failed, hr %#x.\n", hr);
15425 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
15426 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderTarget failed, hr %#x.\n", hr);
15428 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1 );
15429 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetFVF failed, hr %#x.\n", hr);
15431 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x56ffffff, 1.0f, 0);
15432 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear failed, hr %#x.\n", hr);
15434 hr = IDirect3DDevice9_SetPixelShader(device, ps);
15435 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetPixelShader failed, hr %#x.\n", hr);
15437 hr = IDirect3DDevice9_BeginScene(device);
15438 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
15439 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
15440 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
15441 hr = IDirect3DDevice9_EndScene(device);
15442 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
15444 color = getPixelColorFromSurface(rt, 32, 32);
15445 ok(color == 0xff000000, "Unbound sampler color is %#x.\n", color);
15447 /* Now try with a cube texture */
15448 hr = IDirect3DDevice9_SetPixelShader(device, ps_cube);
15449 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetPixelShader failed, hr %#x.\n", hr);
15451 hr = IDirect3DDevice9_BeginScene(device);
15452 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
15453 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
15454 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
15455 hr = IDirect3DDevice9_EndScene(device);
15456 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
15458 color = getPixelColorFromSurface(rt, 32, 32);
15459 ok(color == 0xff000000, "Unbound sampler color is %#x.\n", color);
15461 /* And then with a volume texture */
15462 hr = IDirect3DDevice9_SetPixelShader(device, ps_volume);
15463 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetPixelShader failed, hr %#x.\n", hr);
15465 hr = IDirect3DDevice9_BeginScene(device);
15466 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
15467 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
15468 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
15469 hr = IDirect3DDevice9_EndScene(device);
15470 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
15472 color = getPixelColorFromSurface(rt, 32, 32);
15473 ok(color == 0xff000000, "Unbound sampler color is %#x.\n", color);
15475 IDirect3DSurface9_Release(rt);
15476 IDirect3DSurface9_Release(old_rt);
15477 IDirect3DPixelShader9_Release(ps);
15478 IDirect3DPixelShader9_Release(ps_cube);
15479 IDirect3DPixelShader9_Release(ps_volume);
15480 refcount = IDirect3DDevice9_Release(device);
15481 ok(!refcount, "Device has %u references left.\n", refcount);
15482 done:
15483 IDirect3D9_Release(d3d);
15484 DestroyWindow(window);
15487 static void update_surface_test(void)
15489 static const BYTE blocks[][8] =
15491 {0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00}, /* White */
15492 {0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00}, /* Red */
15493 {0xe0, 0xff, 0xe0, 0xff, 0x00, 0x00, 0x00, 0x00}, /* Yellow */
15494 {0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00}, /* Green */
15495 {0xff, 0x07, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00}, /* Cyan */
15496 {0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00}, /* Blue */
15497 {0x1f, 0xf8, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00}, /* Magenta */
15499 static const struct
15501 UINT x, y;
15502 D3DCOLOR color;
15504 expected_colors[] =
15506 { 18, 240, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0xff)},
15507 { 57, 240, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0xff)},
15508 {109, 240, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0xff)},
15509 {184, 240, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00)},
15510 {290, 240, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x00)},
15511 {440, 240, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x00)},
15512 {584, 240, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0xff)},
15514 static const struct
15516 float x, y, z, w;
15517 float u, v;
15519 tri[] =
15521 { 0.0f, 480.0f, 0.0f, 1.0f, 0.0f, 0.0f},
15522 { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
15523 {640.0f, 240.0f, 0.0f, 10.0f, 100.0f, 0.5f},
15525 static const RECT rect_2x2 = {0, 0, 2, 2};
15526 static const struct
15528 UINT src_level;
15529 UINT dst_level;
15530 const RECT *r;
15531 HRESULT hr;
15533 block_size_tests[] =
15535 {1, 0, NULL, D3D_OK},
15536 {0, 1, NULL, D3DERR_INVALIDCALL},
15537 {5, 4, NULL, D3DERR_INVALIDCALL},
15538 {4, 5, NULL, D3DERR_INVALIDCALL},
15539 {4, 5, &rect_2x2, D3DERR_INVALIDCALL},
15540 {5, 5, &rect_2x2, D3D_OK},
15543 IDirect3DSurface9 *src_surface, *dst_surface;
15544 IDirect3DTexture9 *src_tex, *dst_tex;
15545 IDirect3DDevice9 *device;
15546 IDirect3D9 *d3d;
15547 ULONG refcount;
15548 UINT count, i;
15549 HWND window;
15550 HRESULT hr;
15552 window = create_window();
15553 d3d = Direct3DCreate9(D3D_SDK_VERSION);
15554 ok(!!d3d, "Failed to create a D3D object.\n");
15555 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
15556 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT1)))
15558 skip("DXT1 not supported, skipping tests.\n");
15559 goto done;
15561 if (!(device = create_device(d3d, window, window, TRUE)))
15563 skip("Failed to create a D3D device, skipping tests.\n");
15564 goto done;
15567 hr = IDirect3DDevice9_CreateTexture(device, 64, 64, 0, 0, D3DFMT_DXT1, D3DPOOL_SYSTEMMEM, &src_tex, NULL);
15568 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15569 hr = IDirect3DDevice9_CreateTexture(device, 64, 64, 0, 0, D3DFMT_DXT1, D3DPOOL_DEFAULT, &dst_tex, NULL);
15570 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15572 count = IDirect3DTexture9_GetLevelCount(src_tex);
15573 ok(count == 7, "Got level count %u, expected 7.\n", count);
15575 for (i = 0; i < count; ++i)
15577 UINT row_count, block_count, x, y;
15578 D3DSURFACE_DESC desc;
15579 BYTE *row, *block;
15580 D3DLOCKED_RECT r;
15582 hr = IDirect3DTexture9_GetLevelDesc(src_tex, i, &desc);
15583 ok(SUCCEEDED(hr), "Failed to get level desc, hr %#x.\n", hr);
15585 hr = IDirect3DTexture9_LockRect(src_tex, i, &r, NULL, 0);
15586 ok(SUCCEEDED(hr), "Failed to lock texture, hr %#x.\n", hr);
15588 row_count = ((desc.Height + 3) & ~3) / 4;
15589 block_count = ((desc.Width + 3) & ~3) / 4;
15590 row = r.pBits;
15592 for (y = 0; y < row_count; ++y)
15594 block = row;
15595 for (x = 0; x < block_count; ++x)
15597 memcpy(block, blocks[i], sizeof(blocks[i]));
15598 block += sizeof(blocks[i]);
15600 row += r.Pitch;
15603 hr = IDirect3DTexture9_UnlockRect(src_tex, i);
15604 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr);
15607 for (i = 0; i < sizeof(block_size_tests) / sizeof(*block_size_tests); ++i)
15609 hr = IDirect3DTexture9_GetSurfaceLevel(src_tex, block_size_tests[i].src_level, &src_surface);
15610 ok(SUCCEEDED(hr), "Failed to get texture surface, hr %#x.\n", hr);
15611 hr = IDirect3DTexture9_GetSurfaceLevel(dst_tex, block_size_tests[i].dst_level, &dst_surface);
15612 ok(SUCCEEDED(hr), "Failed to get texture surface, hr %#x.\n", hr);
15614 hr = IDirect3DDevice9_UpdateSurface(device, src_surface, block_size_tests[i].r, dst_surface, NULL);
15615 ok(hr == block_size_tests[i].hr, "Update surface returned %#x for test %u, expected %#x.\n",
15616 hr, i, block_size_tests[i].hr);
15618 IDirect3DSurface9_Release(dst_surface);
15619 IDirect3DSurface9_Release(src_surface);
15622 for (i = 0; i < count; ++i)
15624 hr = IDirect3DTexture9_GetSurfaceLevel(src_tex, i, &src_surface);
15625 ok(SUCCEEDED(hr), "Failed to get texture surface, hr %#x.\n", hr);
15626 hr = IDirect3DTexture9_GetSurfaceLevel(dst_tex, i, &dst_surface);
15627 ok(SUCCEEDED(hr), "Failed to get texture surface, hr %#x.\n", hr);
15629 hr = IDirect3DDevice9_UpdateSurface(device, src_surface, NULL, dst_surface, NULL);
15630 ok(SUCCEEDED(hr), "Failed to update surface at level %u, hr %#x.\n", i, hr);
15632 IDirect3DSurface9_Release(dst_surface);
15633 IDirect3DSurface9_Release(src_surface);
15636 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
15637 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15638 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
15639 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
15640 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZRHW | D3DFVF_TEX1);
15641 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
15642 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)dst_tex);
15643 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
15644 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
15645 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
15646 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
15647 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
15649 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff000000, 0.0f, 0);
15650 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
15652 hr = IDirect3DDevice9_BeginScene(device);
15653 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
15654 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLELIST, 1, tri, sizeof(*tri));
15655 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
15656 hr = IDirect3DDevice9_EndScene(device);
15657 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
15659 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
15661 D3DCOLOR color = getPixelColor(device, expected_colors[i].x, expected_colors[i].y);
15662 ok(color_match(color, expected_colors[i].color, 0),
15663 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
15664 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
15667 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
15668 ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
15670 IDirect3DTexture9_Release(dst_tex);
15671 IDirect3DTexture9_Release(src_tex);
15672 refcount = IDirect3DDevice9_Release(device);
15673 ok(!refcount, "Device has %u references left.\n", refcount);
15674 done:
15675 IDirect3D9_Release(d3d);
15676 DestroyWindow(window);
15679 static void multisample_get_rtdata_test(void)
15681 IDirect3DSurface9 *original_ds, *original_rt, *rt, *readback;
15682 IDirect3DDevice9 *device;
15683 IDirect3D9 *d3d;
15684 ULONG refcount;
15685 HWND window;
15686 HRESULT hr;
15688 window = create_window();
15689 d3d = Direct3DCreate9(D3D_SDK_VERSION);
15690 ok(!!d3d, "Failed to create a D3D object.\n");
15691 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
15692 D3DFMT_A8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES, NULL)))
15694 skip("Multisampling not supported for D3DFMT_A8R8G8B8, skipping tests.\n");
15695 goto done;
15697 if (!(device = create_device(d3d, window, window, TRUE)))
15699 skip("Failed to create a D3D device, skipping tests.\n");
15700 goto done;
15703 hr = IDirect3DDevice9_CreateRenderTarget(device, 256, 256, D3DFMT_A8R8G8B8,
15704 D3DMULTISAMPLE_2_SAMPLES, 0, FALSE, &rt, NULL);
15705 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
15706 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8,
15707 D3DPOOL_SYSTEMMEM, &readback, NULL);
15708 ok(SUCCEEDED(hr), "Failed to create readback surface, hr %#x.\n", hr);
15710 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &original_rt);
15711 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
15712 hr = IDirect3DDevice9_GetDepthStencilSurface(device, &original_ds);
15713 ok(SUCCEEDED(hr), "Failed to get depth/stencil, hr %#x.\n", hr);
15715 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
15716 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
15717 hr = IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
15718 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
15720 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
15721 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
15722 hr = IDirect3DDevice9_GetRenderTargetData(device, rt, readback);
15723 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
15725 hr = IDirect3DDevice9_SetDepthStencilSurface(device, original_ds);
15726 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
15727 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
15728 ok(SUCCEEDED(hr), "Failed to restore original render target, hr %#x.\n", hr);
15730 IDirect3DSurface9_Release(original_ds);
15731 IDirect3DSurface9_Release(original_rt);
15732 IDirect3DSurface9_Release(readback);
15733 IDirect3DSurface9_Release(rt);
15734 refcount = IDirect3DDevice9_Release(device);
15735 ok(!refcount, "Device has %u references left.\n", refcount);
15736 done:
15737 IDirect3D9_Release(d3d);
15738 DestroyWindow(window);
15741 static void multisampled_depth_buffer_test(void)
15743 IDirect3DDevice9 *device = 0;
15744 IDirect3DSurface9 *original_rt, *rt, *readback, *ds, *original_ds;
15745 IDirect3D9 *d3d;
15746 D3DCAPS9 caps;
15747 HRESULT hr;
15748 D3DPRESENT_PARAMETERS present_parameters;
15749 unsigned int i;
15750 static const struct
15752 float x, y, z;
15753 D3DCOLOR color;
15755 quad_1[] =
15757 { -1.0f, 1.0f, 0.0f, 0xffff0000},
15758 { 1.0f, 1.0f, 1.0f, 0xffff0000},
15759 { -1.0f, -1.0f, 0.0f, 0xffff0000},
15760 { 1.0f, -1.0f, 1.0f, 0xffff0000},
15762 quad_2[] =
15764 { -1.0f, 1.0f, 1.0f, 0xff0000ff},
15765 { 1.0f, 1.0f, 0.0f, 0xff0000ff},
15766 { -1.0f, -1.0f, 1.0f, 0xff0000ff},
15767 { 1.0f, -1.0f, 0.0f, 0xff0000ff},
15769 static const struct
15771 UINT x, y;
15772 D3DCOLOR color;
15774 expected_colors[] =
15776 { 80, 100, D3DCOLOR_ARGB(0xff, 0xff, 0x00, 0x00)},
15777 {240, 100, D3DCOLOR_ARGB(0xff, 0xff, 0x00, 0x00)},
15778 {400, 100, D3DCOLOR_ARGB(0xff, 0x00, 0x00, 0xff)},
15779 {560, 100, D3DCOLOR_ARGB(0xff, 0x00, 0x00, 0xff)},
15780 { 80, 450, D3DCOLOR_ARGB(0xff, 0xff, 0x00, 0x00)},
15781 {240, 450, D3DCOLOR_ARGB(0xff, 0xff, 0x00, 0x00)},
15782 {400, 450, D3DCOLOR_ARGB(0xff, 0x00, 0x00, 0xff)},
15783 {560, 450, D3DCOLOR_ARGB(0xff, 0x00, 0x00, 0xff)},
15786 d3d = Direct3DCreate9(D3D_SDK_VERSION);
15787 ok(!!d3d, "Failed to create a D3D object.\n");
15789 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT,
15790 D3DDEVTYPE_HAL, D3DFMT_A8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES, NULL)))
15792 skip("Multisampling not supported for D3DFMT_A8R8G8B8, skipping multisampled depth buffer test.\n");
15793 IDirect3D9_Release(d3d);
15794 return;
15796 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT,
15797 D3DDEVTYPE_HAL, D3DFMT_D24S8, TRUE, D3DMULTISAMPLE_2_SAMPLES, NULL)))
15799 skip("Multisampling not supported for D3DFMT_D24S8, skipping multisampled depth buffer test.\n");
15800 IDirect3D9_Release(d3d);
15801 return;
15804 ZeroMemory(&present_parameters, sizeof(present_parameters));
15805 present_parameters.Windowed = TRUE;
15806 present_parameters.hDeviceWindow = create_window();
15807 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
15808 present_parameters.BackBufferWidth = 640;
15809 present_parameters.BackBufferHeight = 480;
15810 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
15811 present_parameters.EnableAutoDepthStencil = TRUE;
15812 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
15813 present_parameters.MultiSampleType = D3DMULTISAMPLE_2_SAMPLES;
15815 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
15816 present_parameters.hDeviceWindow, D3DCREATE_HARDWARE_VERTEXPROCESSING,
15817 &present_parameters, &device);
15818 ok(hr == D3D_OK, "Failed to create a device, hr %#x.\n", hr);
15820 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
15821 ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
15822 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
15824 skip("No unconditional NP2 texture support, skipping multisampled depth buffer test.\n");
15825 goto cleanup;
15828 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
15829 D3DMULTISAMPLE_2_SAMPLES, 0, FALSE, &rt, NULL);
15830 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
15831 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
15832 D3DMULTISAMPLE_NONE, 0, TRUE, &readback, NULL);
15833 ok(SUCCEEDED(hr), "Failed to create readback surface, hr %#x.\n", hr);
15835 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &original_rt);
15836 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
15837 hr = IDirect3DDevice9_GetDepthStencilSurface(device, &ds);
15838 ok(SUCCEEDED(hr), "Failed to get depth/stencil, hr %#x.\n", hr);
15840 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
15841 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15842 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
15843 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15844 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
15845 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15846 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
15847 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15848 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
15849 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
15851 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 1.0f, 0);
15852 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
15854 /* Render onscreen and then offscreen */
15855 hr = IDirect3DDevice9_BeginScene(device);
15856 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
15857 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad_1, sizeof(*quad_1));
15858 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
15859 hr = IDirect3DDevice9_EndScene(device);
15860 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
15862 hr = IDirect3DDevice9_StretchRect(device, original_rt, NULL, rt, NULL, D3DTEXF_POINT);
15863 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
15864 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
15865 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
15867 hr = IDirect3DDevice9_BeginScene(device);
15868 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
15869 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad_2, sizeof(*quad_2));
15870 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
15871 hr = IDirect3DDevice9_EndScene(device);
15872 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
15874 hr = IDirect3DDevice9_StretchRect(device, rt, NULL, readback, NULL, D3DTEXF_POINT);
15875 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
15877 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
15879 D3DCOLOR color = getPixelColorFromSurface(readback, expected_colors[i].x, expected_colors[i].y);
15880 ok(color_match(color, expected_colors[i].color, 1),
15881 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
15882 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
15885 hr = IDirect3DDevice9_StretchRect(device, rt, NULL, original_rt, NULL, D3DTEXF_POINT);
15886 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
15887 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
15888 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
15890 /* Render offscreen and then onscreen */
15891 hr = IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
15892 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
15893 IDirect3DSurface9_Release(ds);
15894 hr = IDirect3DDevice9_CreateDepthStencilSurface(device, 640, 480, D3DFMT_D24S8,
15895 D3DMULTISAMPLE_2_SAMPLES, 0, TRUE, &ds, NULL);
15896 ok(SUCCEEDED(hr), "Failed to create depth/stencil, hr %#x.\n", hr);
15897 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
15898 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
15900 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 1.0f, 0);
15901 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
15903 hr = IDirect3DDevice9_BeginScene(device);
15904 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
15905 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad_1, sizeof(*quad_1));
15906 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
15907 hr = IDirect3DDevice9_EndScene(device);
15908 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
15910 hr = IDirect3DDevice9_StretchRect(device, rt, NULL, original_rt, NULL, D3DTEXF_POINT);
15911 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
15912 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
15913 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
15915 hr = IDirect3DDevice9_BeginScene(device);
15916 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
15917 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad_2, sizeof(*quad_2));
15918 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
15919 hr = IDirect3DDevice9_EndScene(device);
15920 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
15922 hr = IDirect3DDevice9_StretchRect(device, original_rt, NULL, readback, NULL, D3DTEXF_POINT);
15923 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
15925 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
15927 D3DCOLOR color = getPixelColorFromSurface(readback, expected_colors[i].x, expected_colors[i].y);
15928 ok(color_match(color, expected_colors[i].color, 1),
15929 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
15930 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
15933 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
15934 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
15936 IDirect3DSurface9_Release(ds);
15937 IDirect3DSurface9_Release(readback);
15938 IDirect3DSurface9_Release(rt);
15939 IDirect3DSurface9_Release(original_rt);
15940 cleanup_device(device);
15942 ZeroMemory(&present_parameters, sizeof(present_parameters));
15943 present_parameters.Windowed = TRUE;
15944 present_parameters.hDeviceWindow = create_window();
15945 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
15946 present_parameters.BackBufferWidth = 640;
15947 present_parameters.BackBufferHeight = 480;
15948 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
15949 present_parameters.EnableAutoDepthStencil = TRUE;
15950 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
15951 present_parameters.MultiSampleType = D3DMULTISAMPLE_NONE;
15953 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
15954 present_parameters.hDeviceWindow, D3DCREATE_HARDWARE_VERTEXPROCESSING,
15955 &present_parameters, &device);
15956 ok(hr == D3D_OK, "Failed to create a device, hr %#x.\n", hr);
15958 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ffff, 1.0f, 0);
15959 ok(SUCCEEDED(hr), "Failed to clear depth buffer, hr %#x.\n", hr);
15961 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
15962 D3DMULTISAMPLE_2_SAMPLES, 0, FALSE, &rt, NULL);
15963 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
15964 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
15965 D3DMULTISAMPLE_NONE, 0, TRUE, &readback, NULL);
15966 ok(SUCCEEDED(hr), "Failed to create readback surface, hr %#x.\n", hr);
15967 hr = IDirect3DDevice9_CreateDepthStencilSurface(device, 640, 480, D3DFMT_D24S8,
15968 D3DMULTISAMPLE_2_SAMPLES, 0, FALSE, &ds, NULL);
15969 ok(SUCCEEDED(hr), "CreateDepthStencilSurface failed, hr %#x.\n", hr);
15971 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &original_rt);
15972 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
15973 hr = IDirect3DDevice9_GetDepthStencilSurface(device, &original_ds);
15974 ok(SUCCEEDED(hr), "Failed to get depth/stencil, hr %#x.\n", hr);
15975 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
15976 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
15977 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
15978 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
15980 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
15981 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15982 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
15983 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15984 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
15985 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15986 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
15987 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15988 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
15989 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
15991 /* Render to a multisampled offscreen frame buffer and then blit to
15992 * the onscreen (not multisampled) frame buffer. */
15993 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 1.0f, 0);
15994 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
15996 hr = IDirect3DDevice9_BeginScene(device);
15997 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
15998 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad_1, sizeof(*quad_1));
15999 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
16000 hr = IDirect3DDevice9_EndScene(device);
16001 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
16003 hr = IDirect3DDevice9_StretchRect(device, rt, NULL, original_rt, NULL, D3DTEXF_POINT);
16004 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
16005 hr = IDirect3DDevice9_StretchRect(device, ds, NULL, original_ds, NULL, D3DTEXF_POINT);
16006 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
16008 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
16009 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
16010 hr = IDirect3DDevice9_SetDepthStencilSurface(device, original_ds);
16011 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
16013 hr = IDirect3DDevice9_BeginScene(device);
16014 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
16015 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad_2, sizeof(*quad_2));
16016 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
16017 hr = IDirect3DDevice9_EndScene(device);
16018 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
16020 hr = IDirect3DDevice9_StretchRect(device, original_rt, NULL, readback, NULL, D3DTEXF_POINT);
16021 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
16023 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
16025 D3DCOLOR color = getPixelColorFromSurface(readback, expected_colors[i].x, expected_colors[i].y);
16026 ok(color_match(color, expected_colors[i].color, 1),
16027 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
16028 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
16031 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16032 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
16034 hr = IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
16035 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
16036 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
16037 ok(SUCCEEDED(hr), "Failed to restore original render target, hr %#x.\n", hr);
16039 IDirect3DSurface9_Release(original_ds);
16040 IDirect3DSurface9_Release(original_rt);
16041 IDirect3DSurface9_Release(ds);
16042 IDirect3DSurface9_Release(readback);
16043 IDirect3DSurface9_Release(rt);
16044 cleanup:
16045 cleanup_device(device);
16046 IDirect3D9_Release(d3d);
16049 static void resz_test(void)
16051 IDirect3DDevice9 *device = 0;
16052 IDirect3DSurface9 *rt, *original_rt, *ds, *readback, *intz_ds;
16053 D3DCAPS9 caps;
16054 HRESULT hr;
16055 D3DPRESENT_PARAMETERS present_parameters;
16056 unsigned int i;
16057 static const DWORD ps_code[] =
16059 0xffff0200, /* ps_2_0 */
16060 0x0200001f, 0x90000000, 0xa00f0800, /* dcl_2d s0 */
16061 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
16062 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0.0, 0.0, 0.0, 1.0 */
16063 0x02000001, 0x800f0001, 0xa0e40000, /* mov r1, c0 */
16064 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texld r0, t0, s0 */
16065 0x02000001, 0x80010001, 0x80e40000, /* mov r1.x, r0 */
16066 0x03010042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texldp r0, t0, s0 */
16067 0x02000001, 0x80020001, 0x80000000, /* mov r1.y, r0.x */
16068 0x02000001, 0x800f0800, 0x80e40001, /* mov oC0, r1 */
16069 0x0000ffff, /* end */
16071 struct
16073 float x, y, z;
16074 float s, t, p, q;
16076 quad[] =
16078 { -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.5f},
16079 { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.5f},
16080 { -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f},
16081 { 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.5f},
16083 struct
16085 UINT x, y;
16086 D3DCOLOR color;
16088 expected_colors[] =
16090 { 80, 100, D3DCOLOR_ARGB(0x00, 0x20, 0x40, 0x00)},
16091 {240, 100, D3DCOLOR_ARGB(0x00, 0x60, 0xbf, 0x00)},
16092 {400, 100, D3DCOLOR_ARGB(0x00, 0x9f, 0x40, 0x00)},
16093 {560, 100, D3DCOLOR_ARGB(0x00, 0xdf, 0xbf, 0x00)},
16094 { 80, 450, D3DCOLOR_ARGB(0x00, 0x20, 0x40, 0x00)},
16095 {240, 450, D3DCOLOR_ARGB(0x00, 0x60, 0xbf, 0x00)},
16096 {400, 450, D3DCOLOR_ARGB(0x00, 0x9f, 0x40, 0x00)},
16097 {560, 450, D3DCOLOR_ARGB(0x00, 0xdf, 0xbf, 0x00)},
16099 IDirect3DTexture9 *texture;
16100 IDirect3DPixelShader9 *ps;
16101 IDirect3D9 *d3d;
16102 DWORD value;
16104 d3d = Direct3DCreate9(D3D_SDK_VERSION);
16105 ok(!!d3d, "Failed to create a D3D object.\n");
16107 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT,
16108 D3DDEVTYPE_HAL, D3DFMT_A8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES, NULL)))
16110 skip("Multisampling not supported for D3DFMT_A8R8G8B8, skipping RESZ test.\n");
16111 IDirect3D9_Release(d3d);
16112 return;
16114 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT,
16115 D3DDEVTYPE_HAL, D3DFMT_D24S8, TRUE, D3DMULTISAMPLE_2_SAMPLES, NULL)))
16117 skip("Multisampling not supported for D3DFMT_D24S8, skipping RESZ test.\n");
16118 IDirect3D9_Release(d3d);
16119 return;
16122 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
16123 D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, MAKEFOURCC('I','N','T','Z'))))
16125 skip("No INTZ support, skipping RESZ test.\n");
16126 IDirect3D9_Release(d3d);
16127 return;
16130 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
16131 D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, MAKEFOURCC('R','E','S','Z'))))
16133 skip("No RESZ support, skipping RESZ test.\n");
16134 IDirect3D9_Release(d3d);
16135 return;
16138 ZeroMemory(&present_parameters, sizeof(present_parameters));
16139 present_parameters.Windowed = TRUE;
16140 present_parameters.hDeviceWindow = create_window();
16141 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
16142 present_parameters.BackBufferWidth = 640;
16143 present_parameters.BackBufferHeight = 480;
16144 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
16145 present_parameters.EnableAutoDepthStencil = FALSE;
16146 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
16147 present_parameters.MultiSampleType = D3DMULTISAMPLE_NONE;
16149 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
16150 present_parameters.hDeviceWindow, D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device);
16151 ok(hr == D3D_OK, "Failed to create a device, hr %#x.\n", hr);
16153 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
16154 ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
16155 if (caps.PixelShaderVersion < D3DPS_VERSION(2, 0))
16157 skip("No pixel shader 2.0 support, skipping INTZ test.\n");
16158 cleanup_device(device);
16159 IDirect3D9_Release(d3d);
16160 return;
16162 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
16164 skip("No unconditional NP2 texture support, skipping INTZ test.\n");
16165 cleanup_device(device);
16166 IDirect3D9_Release(d3d);
16167 return;
16170 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &original_rt);
16171 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
16173 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
16174 D3DMULTISAMPLE_2_SAMPLES, 0, FALSE, &rt, NULL);
16175 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
16176 hr = IDirect3DDevice9_CreateDepthStencilSurface(device, 640, 480, D3DFMT_D24S8,
16177 D3DMULTISAMPLE_2_SAMPLES, 0, TRUE, &ds, NULL);
16178 ok(SUCCEEDED(hr), "Failed to create depth/stencil, hr %#x.\n", hr);
16179 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
16180 D3DMULTISAMPLE_NONE, 0, TRUE, &readback, NULL);
16181 ok(SUCCEEDED(hr), "Failed to create readback surface, hr %#x.\n", hr);
16183 hr = IDirect3DDevice9_CreateTexture(device, 640, 480, 1,
16184 D3DUSAGE_DEPTHSTENCIL, MAKEFOURCC('I','N','T','Z'), D3DPOOL_DEFAULT, &texture, NULL);
16185 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
16186 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &intz_ds);
16187 ok(SUCCEEDED(hr), "GetSurfaceLevel failed, hr %#x.\n", hr);
16188 hr = IDirect3DDevice9_SetDepthStencilSurface(device, intz_ds);
16189 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
16190 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 1.0f, 0);
16191 ok(SUCCEEDED(hr), "Failed to clear depth/stencil, hr %#x.\n", hr);
16192 IDirect3DSurface9_Release(intz_ds);
16193 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code, &ps);
16194 ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
16196 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE4(0));
16197 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
16198 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
16199 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16200 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_ALWAYS);
16201 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16202 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
16203 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16204 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
16205 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16207 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
16208 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
16209 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
16210 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
16211 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
16212 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
16213 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
16214 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
16215 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
16216 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
16218 /* Render offscreen (multisampled), blit the depth buffer
16219 * into the INTZ texture and then check its contents */
16220 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
16221 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
16222 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
16223 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
16224 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 1.0f, 0);
16225 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
16227 hr = IDirect3DDevice9_BeginScene(device);
16228 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
16229 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
16230 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
16232 /* The destination depth texture has to be bound to sampler 0 */
16233 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
16234 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
16236 /* the ATI "spec" says you have to do a dummy draw to ensure correct commands ordering */
16237 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
16238 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16239 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
16240 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16241 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_COLORWRITEENABLE, 0);
16242 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16243 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
16244 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
16245 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, TRUE);
16246 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16247 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
16248 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16249 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_COLORWRITEENABLE, 0xf);
16250 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16252 /* The actual multisampled depth buffer resolve happens here */
16253 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, 0x7fa05000);
16254 ok(SUCCEEDED(hr), "SetRenderState (multisampled depth buffer resolve) failed, hr %#x.\n", hr);
16255 hr = IDirect3DDevice9_GetRenderState(device, D3DRS_POINTSIZE, &value);
16256 ok(SUCCEEDED(hr) && value == 0x7fa05000, "GetRenderState failed, hr %#x, value %#x.\n", hr, value);
16258 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
16259 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
16260 hr = IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
16261 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
16262 hr = IDirect3DDevice9_SetPixelShader(device, ps);
16263 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
16265 /* Read the depth values back */
16266 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
16267 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
16268 hr = IDirect3DDevice9_EndScene(device);
16269 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
16271 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
16273 D3DCOLOR color = getPixelColor(device, expected_colors[i].x, expected_colors[i].y);
16274 ok(color_match(color, expected_colors[i].color, 1),
16275 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
16276 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
16279 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16280 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
16282 IDirect3DSurface9_Release(ds);
16283 hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
16284 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
16285 IDirect3DTexture9_Release(texture);
16286 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
16287 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
16288 IDirect3DPixelShader9_Release(ps);
16289 IDirect3DSurface9_Release(readback);
16290 IDirect3DSurface9_Release(original_rt);
16291 IDirect3DSurface9_Release(rt);
16292 cleanup_device(device);
16294 ZeroMemory(&present_parameters, sizeof(present_parameters));
16295 present_parameters.Windowed = TRUE;
16296 present_parameters.hDeviceWindow = create_window();
16297 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
16298 present_parameters.BackBufferWidth = 640;
16299 present_parameters.BackBufferHeight = 480;
16300 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
16301 present_parameters.EnableAutoDepthStencil = TRUE;
16302 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
16303 present_parameters.MultiSampleType = D3DMULTISAMPLE_2_SAMPLES;
16305 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
16306 present_parameters.hDeviceWindow, D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device);
16307 ok(hr == D3D_OK, "Failed to create a device, hr %#x.\n", hr);
16309 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &original_rt);
16310 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
16311 hr = IDirect3DDevice9_GetDepthStencilSurface(device, &ds);
16312 ok(SUCCEEDED(hr), "Failed to get depth/stencil, hr %#x.\n", hr);
16313 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
16314 D3DMULTISAMPLE_NONE, 0, TRUE, &readback, NULL);
16315 ok(SUCCEEDED(hr), "Failed to create readback surface, hr %#x.\n", hr);
16316 hr = IDirect3DDevice9_CreateTexture(device, 640, 480, 1,
16317 D3DUSAGE_DEPTHSTENCIL, MAKEFOURCC('I','N','T','Z'), D3DPOOL_DEFAULT, &texture, NULL);
16318 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
16319 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &intz_ds);
16320 ok(SUCCEEDED(hr), "GetSurfaceLevel failed, hr %#x.\n", hr);
16321 hr = IDirect3DDevice9_SetRenderTarget(device, 0, readback);
16322 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
16323 hr = IDirect3DDevice9_SetDepthStencilSurface(device, intz_ds);
16324 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
16325 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 1.0f, 0);
16326 ok(SUCCEEDED(hr), "Failed to clear depth/stencil, hr %#x.\n", hr);
16327 IDirect3DSurface9_Release(intz_ds);
16328 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code, &ps);
16329 ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
16331 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE4(0));
16332 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
16333 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
16334 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16335 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_ALWAYS);
16336 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16337 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
16338 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16339 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
16340 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16342 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
16343 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
16344 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
16345 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
16346 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
16347 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
16348 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
16349 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
16350 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
16351 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
16353 /* Render onscreen, blit the depth buffer into the INTZ texture
16354 * and then check its contents */
16355 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
16356 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
16357 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
16358 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
16359 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 1.0f, 0);
16360 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
16362 hr = IDirect3DDevice9_BeginScene(device);
16363 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
16364 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
16365 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
16366 hr = IDirect3DDevice9_EndScene(device);
16367 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
16369 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
16370 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
16372 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
16373 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16374 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
16375 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16376 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_COLORWRITEENABLE, 0);
16377 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16378 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
16379 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
16380 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, TRUE);
16381 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16382 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
16383 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16384 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_COLORWRITEENABLE, 0xf);
16385 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16387 /* The actual multisampled depth buffer resolve happens here */
16388 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, 0x7fa05000);
16389 ok(SUCCEEDED(hr), "SetRenderState (multisampled depth buffer resolve) failed, hr %#x.\n", hr);
16390 hr = IDirect3DDevice9_GetRenderState(device, D3DRS_POINTSIZE, &value);
16391 ok(SUCCEEDED(hr) && value == 0x7fa05000, "GetRenderState failed, hr %#x, value %#x.\n", hr, value);
16393 hr = IDirect3DDevice9_SetRenderTarget(device, 0, readback);
16394 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
16395 hr = IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
16396 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
16397 hr = IDirect3DDevice9_SetPixelShader(device, ps);
16398 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
16400 /* Read the depth values back */
16401 hr = IDirect3DDevice9_BeginScene(device);
16402 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
16403 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
16404 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
16405 hr = IDirect3DDevice9_EndScene(device);
16406 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
16408 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
16410 D3DCOLOR color = getPixelColor(device, expected_colors[i].x, expected_colors[i].y);
16411 ok(color_match(color, expected_colors[i].color, 1),
16412 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
16413 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
16416 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16417 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
16420 /* Test edge cases - try with no texture at all */
16421 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
16422 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
16423 hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
16424 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
16425 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
16426 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
16427 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
16428 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
16430 hr = IDirect3DDevice9_BeginScene(device);
16431 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
16432 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
16433 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
16434 hr = IDirect3DDevice9_EndScene(device);
16435 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
16437 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, 0x7fa05000);
16438 ok(SUCCEEDED(hr), "SetRenderState (multisampled depth buffer resolve) failed, hr %#x.\n", hr);
16440 /* With a non-multisampled depth buffer */
16441 IDirect3DSurface9_Release(ds);
16442 hr = IDirect3DDevice9_CreateDepthStencilSurface(device, 640, 480, D3DFMT_D24S8,
16443 D3DMULTISAMPLE_NONE, 0, TRUE, &ds, NULL);
16444 ok(SUCCEEDED(hr), "Failed to create depth stencil surface, hr %#x.\n", hr);
16446 hr = IDirect3DDevice9_SetRenderTarget(device, 0, readback);
16447 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
16448 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
16449 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
16450 hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
16451 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
16453 hr = IDirect3DDevice9_BeginScene(device);
16454 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
16455 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
16456 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
16458 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
16459 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
16461 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
16462 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16463 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
16464 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16465 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_COLORWRITEENABLE, 0);
16466 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16467 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
16468 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
16469 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, TRUE);
16470 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16471 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
16472 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16473 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_COLORWRITEENABLE, 0xf);
16474 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
16475 hr = IDirect3DDevice9_EndScene(device);
16476 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
16478 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, 0x7fa05000);
16479 ok(SUCCEEDED(hr), "SetRenderState (multisampled depth buffer resolve) failed, hr %#x.\n", hr);
16481 hr = IDirect3DDevice9_SetPixelShader(device, ps);
16482 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
16484 /* Read the depth values back. */
16485 hr = IDirect3DDevice9_BeginScene(device);
16486 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
16487 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
16488 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
16489 hr = IDirect3DDevice9_EndScene(device);
16490 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
16492 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
16494 D3DCOLOR color = getPixelColor(device, expected_colors[i].x, expected_colors[i].y);
16495 ok(color_match(color, expected_colors[i].color, 1),
16496 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
16497 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
16500 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16501 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
16503 /* Without a current depth-stencil buffer set */
16504 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
16505 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
16506 hr = IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
16507 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
16509 hr = IDirect3DDevice9_BeginScene(device);
16510 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
16511 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
16512 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
16513 hr = IDirect3DDevice9_EndScene(device);
16514 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
16516 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, 0x7fa05000);
16517 ok(SUCCEEDED(hr), "SetRenderState (multisampled depth buffer resolve) failed, hr %#x.\n", hr);
16519 hr = IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
16520 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
16521 IDirect3DSurface9_Release(ds);
16522 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
16523 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
16524 hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
16525 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
16526 IDirect3DTexture9_Release(texture);
16527 IDirect3DPixelShader9_Release(ps);
16528 IDirect3DSurface9_Release(readback);
16529 IDirect3DSurface9_Release(original_rt);
16530 cleanup_device(device);
16531 IDirect3D9_Release(d3d);
16534 static void zenable_test(void)
16536 static const struct
16538 struct vec4 position;
16539 D3DCOLOR diffuse;
16541 tquad[] =
16543 {{ 0.0f, 480.0f, -0.5f, 1.0f}, 0xff00ff00},
16544 {{ 0.0f, 0.0f, -0.5f, 1.0f}, 0xff00ff00},
16545 {{640.0f, 480.0f, 1.5f, 1.0f}, 0xff00ff00},
16546 {{640.0f, 0.0f, 1.5f, 1.0f}, 0xff00ff00},
16548 IDirect3DDevice9 *device;
16549 IDirect3D9 *d3d;
16550 D3DCOLOR color;
16551 ULONG refcount;
16552 D3DCAPS9 caps;
16553 HWND window;
16554 HRESULT hr;
16555 UINT x, y;
16556 UINT i, j;
16557 UINT test;
16558 IDirect3DSurface9 *ds;
16560 window = create_window();
16561 d3d = Direct3DCreate9(D3D_SDK_VERSION);
16562 ok(!!d3d, "Failed to create a D3D object.\n");
16563 if (!(device = create_device(d3d, window, window, TRUE)))
16565 skip("Failed to create a D3D device, skipping tests.\n");
16566 goto done;
16569 hr = IDirect3DDevice9_GetDepthStencilSurface(device, &ds);
16570 ok(SUCCEEDED(hr), "Failed to get depth stencil surface, hr %#x.\n", hr);
16572 for (test = 0; test < 2; ++test)
16574 /* The Windows 8 testbot (WARP) appears to clip with
16575 * ZENABLE = D3DZB_TRUE and no depth buffer set. */
16576 static const D3DCOLOR expected_broken[] =
16578 0x00ff0000, 0x0000ff00, 0x0000ff00, 0x00ff0000,
16579 0x00ff0000, 0x0000ff00, 0x0000ff00, 0x00ff0000,
16580 0x00ff0000, 0x0000ff00, 0x0000ff00, 0x00ff0000,
16581 0x00ff0000, 0x0000ff00, 0x0000ff00, 0x00ff0000,
16584 if (!test)
16586 hr = IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
16587 ok(SUCCEEDED(hr), "Failed to set depth stencil surface, hr %#x.\n", hr);
16589 else
16591 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
16592 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
16593 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
16594 ok(SUCCEEDED(hr), "Failed to set depth stencil surface, hr %#x.\n", hr);
16595 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0x00000000, 0.0f, 0);
16596 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
16598 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
16599 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
16601 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
16602 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
16603 hr = IDirect3DDevice9_BeginScene(device);
16604 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
16605 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, tquad, sizeof(*tquad));
16606 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
16607 hr = IDirect3DDevice9_EndScene(device);
16608 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
16610 for (i = 0; i < 4; ++i)
16612 for (j = 0; j < 4; ++j)
16614 x = 80 * ((2 * j) + 1);
16615 y = 60 * ((2 * i) + 1);
16616 color = getPixelColor(device, x, y);
16617 ok(color_match(color, 0x0000ff00, 1)
16618 || broken(color_match(color, expected_broken[i * 4 + j], 1) && !test),
16619 "Expected color 0x0000ff00 at %u, %u, got 0x%08x, test %u.\n",
16620 x, y, color, test);
16624 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16625 ok(SUCCEEDED(hr), "Failed to present backbuffer, hr %#x.\n", hr);
16628 IDirect3DSurface9_Release(ds);
16630 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
16631 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
16633 if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 1)
16634 && caps.VertexShaderVersion >= D3DVS_VERSION(1, 1))
16636 static const DWORD vs_code[] =
16638 0xfffe0101, /* vs_1_1 */
16639 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
16640 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
16641 0x00000001, 0xd00f0000, 0x90e40000, /* mov oD0, v0 */
16642 0x0000ffff
16644 static const DWORD ps_code[] =
16646 0xffff0101, /* ps_1_1 */
16647 0x00000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
16648 0x0000ffff /* end */
16650 static const struct vec3 quad[] =
16652 {-1.0f, -1.0f, -0.5f},
16653 {-1.0f, 1.0f, -0.5f},
16654 { 1.0f, -1.0f, 1.5f},
16655 { 1.0f, 1.0f, 1.5f},
16657 static const D3DCOLOR expected[] =
16659 0x00ff0000, 0x0060df60, 0x009fdf9f, 0x00ff0000,
16660 0x00ff0000, 0x00609f60, 0x009f9f9f, 0x00ff0000,
16661 0x00ff0000, 0x00606060, 0x009f609f, 0x00ff0000,
16662 0x00ff0000, 0x00602060, 0x009f209f, 0x00ff0000,
16664 /* The Windows 8 testbot (WARP) appears to not clip z for regular
16665 * vertices either. */
16666 static const D3DCOLOR expected_broken[] =
16668 0x0020df20, 0x0060df60, 0x009fdf9f, 0x00dfdfdf,
16669 0x00209f20, 0x00609f60, 0x009f9f9f, 0x00df9fdf,
16670 0x00206020, 0x00606060, 0x009f609f, 0x00df60df,
16671 0x00202020, 0x00602060, 0x009f209f, 0x00df20df,
16674 IDirect3DVertexShader9 *vs;
16675 IDirect3DPixelShader9 *ps;
16677 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
16678 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
16679 hr = IDirect3DDevice9_CreateVertexShader(device, vs_code, &vs);
16680 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
16681 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code, &ps);
16682 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16683 hr = IDirect3DDevice9_SetVertexShader(device, vs);
16684 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
16685 hr = IDirect3DDevice9_SetPixelShader(device, ps);
16686 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
16688 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 0.0f, 0);
16689 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
16690 hr = IDirect3DDevice9_BeginScene(device);
16691 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
16692 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
16693 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
16694 hr = IDirect3DDevice9_EndScene(device);
16695 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
16697 for (i = 0; i < 4; ++i)
16699 for (j = 0; j < 4; ++j)
16701 x = 80 * ((2 * j) + 1);
16702 y = 60 * ((2 * i) + 1);
16703 color = getPixelColor(device, x, y);
16704 ok(color_match(color, expected[i * 4 + j], 1)
16705 || broken(color_match(color, expected_broken[i * 4 + j], 1)),
16706 "Expected color 0x%08x at %u, %u, got 0x%08x.\n", expected[i * 4 + j], x, y, color);
16710 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16711 ok(SUCCEEDED(hr), "Failed to present backbuffer, hr %#x.\n", hr);
16713 IDirect3DPixelShader9_Release(ps);
16714 IDirect3DVertexShader9_Release(vs);
16717 refcount = IDirect3DDevice9_Release(device);
16718 ok(!refcount, "Device has %u references left.\n", refcount);
16719 done:
16720 IDirect3D9_Release(d3d);
16721 DestroyWindow(window);
16724 static void fog_special_test(void)
16726 static const struct
16728 struct vec3 position;
16729 D3DCOLOR diffuse;
16731 quad[] =
16733 {{ -1.0f, -1.0f, 0.0f}, 0xff00ff00},
16734 {{ -1.0f, 1.0f, 0.0f}, 0xff00ff00},
16735 {{ 1.0f, -1.0f, 1.0f}, 0xff00ff00},
16736 {{ 1.0f, 1.0f, 1.0f}, 0xff00ff00}
16738 static const struct
16740 DWORD vertexmode, tablemode;
16741 BOOL vs, ps;
16742 D3DCOLOR color_left, color_right;
16744 tests[] =
16746 {D3DFOG_LINEAR, D3DFOG_NONE, FALSE, FALSE, 0x00ff0000, 0x00ff0000},
16747 {D3DFOG_LINEAR, D3DFOG_NONE, FALSE, TRUE, 0x00ff0000, 0x00ff0000},
16748 {D3DFOG_LINEAR, D3DFOG_NONE, TRUE, FALSE, 0x00ff0000, 0x00ff0000},
16749 {D3DFOG_LINEAR, D3DFOG_NONE, TRUE, TRUE, 0x00ff0000, 0x00ff0000},
16751 {D3DFOG_NONE, D3DFOG_LINEAR, FALSE, FALSE, 0x0000ff00, 0x00ff0000},
16752 {D3DFOG_NONE, D3DFOG_LINEAR, FALSE, TRUE, 0x0000ff00, 0x00ff0000},
16753 {D3DFOG_NONE, D3DFOG_LINEAR, TRUE, FALSE, 0x0000ff00, 0x00ff0000},
16754 {D3DFOG_NONE, D3DFOG_LINEAR, TRUE, TRUE, 0x0000ff00, 0x00ff0000},
16756 static const DWORD pixel_shader_code[] =
16758 0xffff0101, /* ps_1_1 */
16759 0x00000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
16760 0x0000ffff
16762 static const DWORD vertex_shader_code[] =
16764 0xfffe0101, /* vs_1_1 */
16765 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
16766 0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
16767 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
16768 0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
16769 0x0000ffff
16771 static const D3DMATRIX identity =
16773 1.0f, 0.0f, 0.0f, 0.0f,
16774 0.0f, 1.0f, 0.0f, 0.0f,
16775 0.0f, 0.0f, 1.0f, 0.0f,
16776 0.0f, 0.0f, 0.0f, 1.0f,
16777 }}};
16778 union
16780 float f;
16781 DWORD d;
16782 } conv;
16783 DWORD color;
16784 HRESULT hr;
16785 unsigned int i;
16786 IDirect3DPixelShader9 *ps;
16787 IDirect3DVertexShader9 *vs;
16788 IDirect3DDevice9 *device;
16789 IDirect3D9 *d3d;
16790 ULONG refcount;
16791 D3DCAPS9 caps;
16792 HWND window;
16794 window = create_window();
16795 d3d = Direct3DCreate9(D3D_SDK_VERSION);
16796 ok(!!d3d, "Failed to create a D3D object.\n");
16797 if (!(device = create_device(d3d, window, window, TRUE)))
16799 skip("Failed to create a D3D device, skipping tests.\n");
16800 goto done;
16803 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
16804 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
16805 if (caps.VertexShaderVersion >= D3DVS_VERSION(1, 1))
16807 hr = IDirect3DDevice9_CreateVertexShader(device, vertex_shader_code, &vs);
16808 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
16810 else
16812 skip("Vertex Shaders not supported, skipping some fog tests.\n");
16813 vs = NULL;
16815 if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 1))
16817 hr = IDirect3DDevice9_CreatePixelShader(device, pixel_shader_code, &ps);
16818 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16820 else
16822 skip("Pixel Shaders not supported, skipping some fog tests.\n");
16823 ps = NULL;
16826 /* The table fog tests seem to depend on the projection matrix explicitly
16827 * being set to an identity matrix, even though that's the default.
16828 * (AMD Radeon HD 6310, Windows 7) */
16829 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &identity);
16830 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
16832 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
16833 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
16834 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
16835 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
16836 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGENABLE, TRUE);
16837 ok(SUCCEEDED(hr), "Failed to enable fog, hr %#x.\n", hr);
16838 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGCOLOR, 0xffff0000);
16839 ok(SUCCEEDED(hr), "Failed to set fog color, hr %#x.\n", hr);
16841 conv.f = 0.5f;
16842 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGSTART, conv.d);
16843 ok(SUCCEEDED(hr), "Failed to set fog start, hr %#x.\n", hr);
16844 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGEND, conv.d);
16845 ok(SUCCEEDED(hr), "Failed to set fog end, hr %#x.\n", hr);
16847 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
16849 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
16850 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
16852 if (!tests[i].vs)
16854 hr = IDirect3DDevice9_SetVertexShader(device, NULL);
16855 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
16857 else if (vs)
16859 hr = IDirect3DDevice9_SetVertexShader(device, vs);
16860 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
16862 else
16864 continue;
16867 if (!tests[i].ps)
16869 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
16870 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
16872 else if (ps)
16874 hr = IDirect3DDevice9_SetPixelShader(device, ps);
16875 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
16877 else
16879 continue;
16882 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGVERTEXMODE, tests[i].vertexmode);
16883 ok(SUCCEEDED(hr), "Failed to set fogvertexmode, hr %#x.\n", hr);
16884 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, tests[i].tablemode);
16885 ok(SUCCEEDED(hr), "Failed to set fogtablemode, hr %#x.\n", hr);
16887 hr = IDirect3DDevice9_BeginScene(device);
16888 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
16889 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
16890 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
16891 hr = IDirect3DDevice9_EndScene(device);
16892 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
16894 color = getPixelColor(device, 310, 240);
16895 ok(color_match(color, tests[i].color_left, 1),
16896 "Expected left color 0x%08x, got 0x%08x, case %u.\n", tests[i].color_left, color, i);
16897 color = getPixelColor(device, 330, 240);
16898 ok(color_match(color, tests[i].color_right, 1),
16899 "Expected right color 0x%08x, got 0x%08x, case %u.\n", tests[i].color_right, color, i);
16901 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16902 ok(SUCCEEDED(hr), "Failed to present backbuffer, hr %#x.\n", hr);
16905 if (vs)
16906 IDirect3DVertexShader9_Release(vs);
16907 if (ps)
16908 IDirect3DPixelShader9_Release(ps);
16909 refcount = IDirect3DDevice9_Release(device);
16910 ok(!refcount, "Device has %u references left.\n", refcount);
16911 done:
16912 IDirect3D9_Release(d3d);
16913 DestroyWindow(window);
16916 static void volume_srgb_test(void)
16918 HRESULT hr;
16919 unsigned int i, j;
16920 IDirect3DVolumeTexture9 *tex1, *tex2;
16921 D3DPOOL pool;
16922 D3DLOCKED_BOX locked_box;
16923 IDirect3DDevice9 *device;
16924 IDirect3D9 *d3d;
16925 D3DCOLOR color;
16926 ULONG refcount;
16927 HWND window;
16929 static const struct
16931 BOOL srgb;
16932 DWORD color;
16934 tests[] =
16936 /* Try toggling on and off */
16937 { FALSE, 0x007f7f7f },
16938 { TRUE, 0x00363636 },
16939 { FALSE, 0x007f7f7f },
16941 static const struct
16943 struct vec3 pos;
16944 struct vec3 texcrd;
16946 quad[] =
16948 {{-1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, 0.0f}},
16949 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0f}},
16950 {{ 1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, 0.0f}},
16951 {{ 1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0f}},
16954 window = create_window();
16955 d3d = Direct3DCreate9(D3D_SDK_VERSION);
16956 ok(!!d3d, "Failed to create a D3D object.\n");
16957 if (IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
16958 D3DUSAGE_QUERY_SRGBREAD, D3DRTYPE_VOLUMETEXTURE, D3DFMT_A8R8G8B8) != D3D_OK)
16960 skip("D3DFMT_A8R8G8B8 volume textures with SRGBREAD not supported.\n");
16961 goto done;
16963 if (!(device = create_device(d3d, window, window, TRUE)))
16965 skip("Failed to create a D3D device, skipping tests.\n");
16966 goto done;
16969 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
16970 ok(SUCCEEDED(hr), "Failed to set color op 0, hr %#x.\n", hr);
16971 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
16972 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
16973 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
16974 ok(SUCCEEDED(hr), "Failed to set color op 0, hr %#x.\n", hr);
16975 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE3(0));
16976 ok(SUCCEEDED(hr), "Failed to set fvf, hr %#x.\n", hr);
16978 for (i = 0; i < 2; i++)
16980 if (!i)
16981 pool = D3DPOOL_SYSTEMMEM;
16982 else
16983 pool = D3DPOOL_MANAGED;
16985 hr = IDirect3DDevice9_CreateVolumeTexture(device, 1, 1, 1, 1, 0, D3DFMT_A8R8G8B8, pool, &tex1, NULL);
16986 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
16987 hr = IDirect3DVolumeTexture9_LockBox(tex1, 0, &locked_box, NULL, 0);
16988 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
16989 *((DWORD *)locked_box.pBits) = 0x7f7f7f7f;
16990 hr = IDirect3DVolumeTexture9_UnlockBox(tex1, 0);
16991 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
16993 if (!i)
16995 hr = IDirect3DDevice9_CreateVolumeTexture(device, 1, 1, 1, 1, 0,
16996 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex2, NULL);
16997 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
16998 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex1, (IDirect3DBaseTexture9 *)tex2);
16999 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
17000 IDirect3DVolumeTexture9_Release(tex1);
17002 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)tex2);
17003 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
17004 IDirect3DVolumeTexture9_Release(tex2);
17006 else
17008 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)tex1);
17009 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
17010 IDirect3DVolumeTexture9_Release(tex1);
17013 for (j = 0; j < sizeof(tests) / sizeof(*tests); j++)
17015 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, tests[j].srgb);
17016 ok(SUCCEEDED(hr), "Failed to set srgb state, hr %#x.\n", hr);
17018 hr = IDirect3DDevice9_BeginScene(device);
17019 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
17020 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
17021 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
17022 hr = IDirect3DDevice9_EndScene(device);
17023 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
17025 color = getPixelColor(device, 320, 240);
17026 ok(color_match(color, tests[j].color, 2),
17027 "Expected color 0x%08x, got 0x%08x, i = %u, j = %u.\n", tests[j].color, color, i, j);
17029 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17030 ok(SUCCEEDED(hr), "Failed to present backbuffer, hr %#x.\n", hr);
17034 refcount = IDirect3DDevice9_Release(device);
17035 ok(!refcount, "Device has %u references left.\n", refcount);
17036 done:
17037 IDirect3D9_Release(d3d);
17038 DestroyWindow(window);
17041 static void volume_dxt5_test(void)
17043 IDirect3DVolumeTexture9 *texture;
17044 IDirect3DDevice9 *device;
17045 D3DLOCKED_BOX box;
17046 IDirect3D9 *d3d;
17047 unsigned int i;
17048 ULONG refcount;
17049 DWORD color;
17050 HWND window;
17051 HRESULT hr;
17053 static const char texture_data[] =
17055 /* A 8x4x2 texture consisting of 4 4x4 blocks. The colors of the blocks are red, green, blue and white. */
17056 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
17057 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
17058 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
17059 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
17061 static const struct
17063 struct vec3 position;
17064 struct vec3 texcrd;
17066 quads[] =
17068 {{ -1.0f, -1.0f, 0.0f}, { 0.0f, 0.0f, 0.25f}},
17069 {{ -1.0f, 1.0f, 0.0f}, { 0.0f, 1.0f, 0.25f}},
17070 {{ 0.0f, -1.0f, 1.0f}, { 1.0f, 0.0f, 0.25f}},
17071 {{ 0.0f, 1.0f, 1.0f}, { 1.0f, 1.0f, 0.25f}},
17073 {{ 0.0f, -1.0f, 0.0f}, { 0.0f, 0.0f, 0.75f}},
17074 {{ 0.0f, 1.0f, 0.0f}, { 0.0f, 1.0f, 0.75f}},
17075 {{ 1.0f, -1.0f, 1.0f}, { 1.0f, 0.0f, 0.75f}},
17076 {{ 1.0f, 1.0f, 1.0f}, { 1.0f, 1.0f, 0.75f}},
17078 static const DWORD expected_colors[] = {0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff};
17080 window = create_window();
17081 d3d = Direct3DCreate9(D3D_SDK_VERSION);
17082 ok(!!d3d, "Failed to create a D3D object.\n");
17083 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
17084 D3DFMT_X8R8G8B8, 0, D3DRTYPE_VOLUMETEXTURE, D3DFMT_DXT5)))
17086 skip("DXT5 volume textures are not supported, skipping test.\n");
17087 goto done;
17089 if (!(device = create_device(d3d, window, window, TRUE)))
17091 skip("Failed to create a D3D device, skipping tests.\n");
17092 goto done;
17095 hr = IDirect3DDevice9_CreateVolumeTexture(device, 8, 4, 2, 1, 0, D3DFMT_DXT5,
17096 D3DPOOL_MANAGED, &texture, NULL);
17097 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
17099 hr = IDirect3DVolumeTexture9_LockBox(texture, 0, &box, NULL, 0);
17100 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
17101 memcpy(box.pBits, texture_data, sizeof(texture_data));
17102 hr = IDirect3DVolumeTexture9_UnlockBox(texture, 0);
17103 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
17105 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE3(0));
17106 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
17107 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
17108 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
17109 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
17110 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
17111 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
17112 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
17113 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
17114 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
17115 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
17116 ok(SUCCEEDED(hr), "Failed to set mag filter, hr %#x.\n", hr);
17118 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff00ff, 1.0f, 0);
17119 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
17120 hr = IDirect3DDevice9_BeginScene(device);
17121 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
17122 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[0], sizeof(*quads));
17123 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
17124 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[4], sizeof(*quads));
17125 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
17126 hr = IDirect3DDevice9_EndScene(device);
17127 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
17129 for (i = 0; i < 4; i++)
17131 color = getPixelColor(device, 80 + 160 * i, 240);
17132 ok (color_match(color, expected_colors[i], 1),
17133 "Expected color 0x%08x, got 0x%08x, case %u.\n", expected_colors[i], color, i);
17136 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17137 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17138 IDirect3DVolumeTexture9_Release(texture);
17139 refcount = IDirect3DDevice9_Release(device);
17140 ok(!refcount, "Device has %u references left.\n", refcount);
17141 done:
17142 IDirect3D9_Release(d3d);
17143 DestroyWindow(window);
17146 static void volume_v16u16_test(void)
17148 IDirect3DVolumeTexture9 *texture;
17149 IDirect3DPixelShader9 *shader;
17150 IDirect3DDevice9 *device;
17151 D3DLOCKED_BOX box;
17152 IDirect3D9 *d3d;
17153 unsigned int i;
17154 ULONG refcount;
17155 D3DCAPS9 caps;
17156 SHORT *texel;
17157 DWORD color;
17158 HWND window;
17159 HRESULT hr;
17161 static const struct
17163 struct vec3 position;
17164 struct vec3 texcrd;
17166 quads[] =
17168 {{ -1.0f, -1.0f, 0.0f}, { 0.0f, 0.0f, 0.25f}},
17169 {{ -1.0f, 1.0f, 0.0f}, { 0.0f, 1.0f, 0.25f}},
17170 {{ 0.0f, -1.0f, 1.0f}, { 1.0f, 0.0f, 0.25f}},
17171 {{ 0.0f, 1.0f, 1.0f}, { 1.0f, 1.0f, 0.25f}},
17173 {{ 0.0f, -1.0f, 0.0f}, { 0.0f, 0.0f, 0.75f}},
17174 {{ 0.0f, 1.0f, 0.0f}, { 0.0f, 1.0f, 0.75f}},
17175 {{ 1.0f, -1.0f, 1.0f}, { 1.0f, 0.0f, 0.75f}},
17176 {{ 1.0f, 1.0f, 1.0f}, { 1.0f, 1.0f, 0.75f}},
17178 static const DWORD shader_code[] =
17180 0xffff0101, /* ps_1_1 */
17181 0x00000051, 0xa00f0000, 0x3f000000, 0x3f000000, /* def c0, 0.5, 0.5, */
17182 0x3f000000, 0x3f000000, /* 0.5, 0.5 */
17183 0x00000042, 0xb00f0000, /* tex t0 */
17184 0x00000004, 0x800f0000, 0xb0e40000, 0xa0e40000, 0xa0e40000, /* mad r0, t0, c0, c0 */
17185 0x0000ffff /* end */
17188 window = create_window();
17189 d3d = Direct3DCreate9(D3D_SDK_VERSION);
17190 ok(!!d3d, "Failed to create a D3D object.\n");
17191 if (!(device = create_device(d3d, window, window, TRUE)))
17193 skip("Failed to create a D3D device, skipping tests.\n");
17194 goto done;
17197 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
17198 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
17199 if (caps.PixelShaderVersion < D3DPS_VERSION(1, 1))
17201 skip("No ps_1_1 support, skipping tests.\n");
17202 IDirect3DDevice9_Release(device);
17203 goto done;
17205 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
17206 D3DFMT_X8R8G8B8, 0, D3DRTYPE_VOLUMETEXTURE, D3DFMT_V16U16)))
17208 skip("Volume V16U16 textures are not supported, skipping test.\n");
17209 IDirect3DDevice9_Release(device);
17210 goto done;
17213 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE3(0));
17214 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
17215 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code, &shader);
17216 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17217 hr = IDirect3DDevice9_SetPixelShader(device, shader);
17218 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
17219 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
17220 ok(SUCCEEDED(hr), "Failed to set filter, hr %#x.\n", hr);
17222 for (i = 0; i < 2; i++)
17224 D3DPOOL pool;
17226 if (i)
17227 pool = D3DPOOL_SYSTEMMEM;
17228 else
17229 pool = D3DPOOL_MANAGED;
17231 hr = IDirect3DDevice9_CreateVolumeTexture(device, 1, 2, 2, 1, 0, D3DFMT_V16U16,
17232 pool, &texture, NULL);
17233 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
17235 hr = IDirect3DVolumeTexture9_LockBox(texture, 0, &box, NULL, 0);
17236 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
17238 texel = (SHORT *)((BYTE *)box.pBits + 0 * box.RowPitch + 0 * box.SlicePitch);
17239 texel[0] = 32767;
17240 texel[1] = 32767;
17241 texel = (SHORT *)((BYTE *)box.pBits + 1 * box.RowPitch + 0 * box.SlicePitch);
17242 texel[0] = -32768;
17243 texel[1] = 0;
17244 texel = (SHORT *)((BYTE *)box.pBits + 0 * box.RowPitch + 1 * box.SlicePitch);
17245 texel[0] = -16384;
17246 texel[1] = 16384;
17247 texel = (SHORT *)((BYTE *)box.pBits + 1 * box.RowPitch + 1 * box.SlicePitch);
17248 texel[0] = 0;
17249 texel[1] = 0;
17251 hr = IDirect3DVolumeTexture9_UnlockBox(texture, 0);
17252 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
17254 if (i)
17256 IDirect3DVolumeTexture9 *texture2;
17258 hr = IDirect3DDevice9_CreateVolumeTexture(device, 1, 2, 2, 1, 0, D3DFMT_V16U16,
17259 D3DPOOL_DEFAULT, &texture2, NULL);
17260 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
17262 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)texture,
17263 (IDirect3DBaseTexture9 *)texture2);
17264 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
17266 IDirect3DVolumeTexture9_Release(texture);
17267 texture = texture2;
17270 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) texture);
17271 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
17273 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff00ff, 1.0f, 0);
17274 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
17275 hr = IDirect3DDevice9_BeginScene(device);
17276 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
17277 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[0], sizeof(*quads));
17278 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
17279 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[4], sizeof(*quads));
17280 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
17281 hr = IDirect3DDevice9_EndScene(device);
17282 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
17284 color = getPixelColor(device, 120, 160);
17285 ok (color_match(color, 0x000080ff, 2),
17286 "Expected color 0x000080ff, got 0x%08x, V16U16 input -32768, 0.\n", color);
17287 color = getPixelColor(device, 120, 400);
17288 ok (color_match(color, 0x00ffffff, 2),
17289 "Expected color 0x00ffffff, got 0x%08x, V16U16 input 32767, 32767.\n", color);
17290 color = getPixelColor(device, 360, 160);
17291 ok (color_match(color, 0x007f7fff, 2),
17292 "Expected color 0x007f7fff, got 0x%08x, V16U16 input 0, 0.\n", color);
17293 color = getPixelColor(device, 360, 400);
17294 ok (color_match(color, 0x0040c0ff, 2),
17295 "Expected color 0x0040c0ff, got 0x%08x, V16U16 input -16384, 16384.\n", color);
17297 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17298 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17300 IDirect3DVolumeTexture9_Release(texture);
17303 IDirect3DPixelShader9_Release(shader);
17304 refcount = IDirect3DDevice9_Release(device);
17305 ok(!refcount, "Device has %u references left.\n", refcount);
17306 done:
17307 IDirect3D9_Release(d3d);
17308 DestroyWindow(window);
17311 static void add_dirty_rect_test_draw(IDirect3DDevice9 *device)
17313 HRESULT hr;
17314 static const struct
17316 struct vec3 position;
17317 struct vec2 texcoord;
17319 quad[] =
17321 {{-1.0, -1.0, 0.0}, {0.0, 0.0}},
17322 {{-1.0, 1.0, 0.0}, {0.0, 1.0}},
17323 {{ 1.0, -1.0, 0.0}, {1.0, 0.0}},
17324 {{ 1.0, 1.0, 0.0}, {1.0, 1.0}},
17327 hr = IDirect3DDevice9_BeginScene(device);
17328 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
17329 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad, sizeof(*quad));
17330 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
17331 hr = IDirect3DDevice9_EndScene(device);
17332 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
17335 static void add_dirty_rect_test(void)
17337 HRESULT hr;
17338 IDirect3DTexture9 *tex_dst1, *tex_dst2, *tex_src_red, *tex_src_green,
17339 *tex_managed, *tex_dynamic;
17340 IDirect3DSurface9 *surface_dst2, *surface_src_green, *surface_src_red,
17341 *surface_managed0, *surface_managed1, *surface_dynamic;
17342 IDirect3DDevice9 *device;
17343 IDirect3D9 *d3d;
17344 unsigned int i;
17345 ULONG refcount;
17346 DWORD *texel;
17347 HWND window;
17348 D3DLOCKED_RECT locked_rect;
17349 static const RECT part_rect = {96, 96, 160, 160};
17350 DWORD color;
17352 window = create_window();
17353 d3d = Direct3DCreate9(D3D_SDK_VERSION);
17354 ok(!!d3d, "Failed to create a D3D object.\n");
17355 if (!(device = create_device(d3d, window, window, TRUE)))
17357 skip("Failed to create a D3D device, skipping tests.\n");
17358 IDirect3D9_Release(d3d);
17359 DestroyWindow(window);
17360 return;
17363 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 1, 0, D3DFMT_X8R8G8B8,
17364 D3DPOOL_DEFAULT, &tex_dst1, NULL);
17365 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17366 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 1, 0, D3DFMT_X8R8G8B8,
17367 D3DPOOL_DEFAULT, &tex_dst2, NULL);
17368 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17369 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 1, 0, D3DFMT_X8R8G8B8,
17370 D3DPOOL_SYSTEMMEM, &tex_src_red, NULL);
17371 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17372 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 1, 0, D3DFMT_X8R8G8B8,
17373 D3DPOOL_SYSTEMMEM, &tex_src_green, NULL);
17374 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17375 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 2, 0, D3DFMT_X8R8G8B8,
17376 D3DPOOL_MANAGED, &tex_managed, NULL);
17377 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17378 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 1, D3DUSAGE_DYNAMIC,
17379 D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &tex_dynamic, NULL);
17380 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17382 hr = IDirect3DTexture9_GetSurfaceLevel(tex_dst2, 0, &surface_dst2);
17383 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
17384 hr = IDirect3DTexture9_GetSurfaceLevel(tex_src_green, 0, &surface_src_green);
17385 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
17386 hr = IDirect3DTexture9_GetSurfaceLevel(tex_src_red, 0, &surface_src_red);
17387 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
17388 hr = IDirect3DTexture9_GetSurfaceLevel(tex_managed, 0, &surface_managed0);
17389 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
17390 hr = IDirect3DTexture9_GetSurfaceLevel(tex_managed, 1, &surface_managed1);
17391 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
17392 hr = IDirect3DTexture9_GetSurfaceLevel(tex_dynamic, 0, &surface_dynamic);
17393 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
17395 fill_surface(surface_src_red, 0x00ff0000, 0);
17396 fill_surface(surface_src_green, 0x0000ff00, 0);
17398 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
17399 ok(SUCCEEDED(hr), "Failed to set fvf, hr %#x.\n", hr);
17400 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
17401 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
17402 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
17403 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
17404 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
17405 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
17407 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
17408 (IDirect3DBaseTexture9 *)tex_dst1);
17409 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
17411 /* The second UpdateTexture call writing to tex_dst2 is ignored because tex_src_green is not dirty. */
17412 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_red,
17413 (IDirect3DBaseTexture9 *)tex_dst2);
17414 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
17415 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
17416 (IDirect3DBaseTexture9 *)tex_dst2);
17417 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
17419 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)tex_dst1);
17420 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
17421 add_dirty_rect_test_draw(device);
17422 color = getPixelColor(device, 320, 240);
17423 ok(color_match(color, 0x0000ff00, 1),
17424 "Expected color 0x0000ff00, got 0x%08x.\n", color);
17425 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17426 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17428 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)tex_dst2);
17429 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
17430 add_dirty_rect_test_draw(device);
17431 color = getPixelColor(device, 320, 240);
17432 todo_wine ok(color_match(color, 0x00ff0000, 1),
17433 "Expected color 0x00ff0000, got 0x%08x.\n", color);
17434 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17435 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17437 /* AddDirtyRect on the destination is ignored. */
17438 hr = IDirect3DTexture9_AddDirtyRect(tex_dst2, &part_rect);
17439 ok(SUCCEEDED(hr), "Failed to add dirty rect, hr %#x.\n", hr);
17440 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
17441 (IDirect3DBaseTexture9 *)tex_dst2);
17442 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
17443 add_dirty_rect_test_draw(device);
17444 color = getPixelColor(device, 320, 240);
17445 todo_wine ok(color_match(color, 0x00ff0000, 1),
17446 "Expected color 0x00ff0000, got 0x%08x.\n", color);
17447 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17448 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17450 hr = IDirect3DTexture9_AddDirtyRect(tex_dst2, NULL);
17451 ok(SUCCEEDED(hr), "Failed to add dirty rect, hr %#x.\n", hr);
17452 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
17453 (IDirect3DBaseTexture9 *)tex_dst2);
17454 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
17455 add_dirty_rect_test_draw(device);
17456 color = getPixelColor(device, 320, 240);
17457 todo_wine ok(color_match(color, 0x00ff0000, 1),
17458 "Expected color 0x00ff0000, got 0x%08x.\n", color);
17459 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17460 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17462 /* AddDirtyRect on the source makes UpdateTexture work. Partial rectangle
17463 * tracking is supported. */
17464 hr = IDirect3DTexture9_AddDirtyRect(tex_src_green, &part_rect);
17465 ok(SUCCEEDED(hr), "Failed to add dirty rect, hr %#x.\n", hr);
17466 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
17467 (IDirect3DBaseTexture9 *)tex_dst2);
17468 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
17469 add_dirty_rect_test_draw(device);
17470 color = getPixelColor(device, 320, 240);
17471 ok(color_match(color, 0x0000ff00, 1),
17472 "Expected color 0x0000ff00, got 0x%08x.\n", color);
17473 color = getPixelColor(device, 1, 1);
17474 todo_wine ok(color_match(color, 0x00ff0000, 1),
17475 "Expected color 0x00ff0000, got 0x%08x.\n", color);
17476 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17477 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17479 hr = IDirect3DTexture9_AddDirtyRect(tex_src_green, NULL);
17480 ok(SUCCEEDED(hr), "Failed to add dirty rect, hr %#x.\n", hr);
17481 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
17482 (IDirect3DBaseTexture9 *)tex_dst2);
17483 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
17484 add_dirty_rect_test_draw(device);
17485 color = getPixelColor(device, 1, 1);
17486 ok(color_match(color, 0x0000ff00, 1),
17487 "Expected color 0x0000ff00, got 0x%08x.\n", color);
17489 /* Locks with NO_DIRTY_UPDATE are ignored. */
17490 fill_surface(surface_src_green, 0x00000080, D3DLOCK_NO_DIRTY_UPDATE);
17491 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
17492 (IDirect3DBaseTexture9 *)tex_dst2);
17493 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
17494 add_dirty_rect_test_draw(device);
17495 color = getPixelColor(device, 320, 240);
17496 todo_wine ok(color_match(color, 0x0000ff00, 1),
17497 "Expected color 0x0000ff00, got 0x%08x.\n", color);
17498 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17499 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17501 /* Readonly maps write to D3DPOOL_SYSTEMMEM, but don't record a dirty rectangle. */
17502 fill_surface(surface_src_green, 0x000000ff, D3DLOCK_READONLY);
17503 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
17504 (IDirect3DBaseTexture9 *)tex_dst2);
17505 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
17506 add_dirty_rect_test_draw(device);
17507 color = getPixelColor(device, 320, 240);
17508 todo_wine ok(color_match(color, 0x0000ff00, 1),
17509 "Expected color 0x0000ff00, got 0x%08x.\n", color);
17510 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17511 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17513 hr = IDirect3DTexture9_AddDirtyRect(tex_src_green, NULL);
17514 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
17515 (IDirect3DBaseTexture9 *)tex_dst2);
17516 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
17517 add_dirty_rect_test_draw(device);
17518 color = getPixelColor(device, 320, 240);
17519 ok(color_match(color, 0x000000ff, 1),
17520 "Expected color 0x000000ff, got 0x%08x.\n", color);
17521 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17522 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17524 /* Maps without either of these flags record a dirty rectangle. */
17525 fill_surface(surface_src_green, 0x00ffffff, 0);
17526 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
17527 (IDirect3DBaseTexture9 *)tex_dst2);
17528 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
17529 add_dirty_rect_test_draw(device);
17530 color = getPixelColor(device, 320, 240);
17531 ok(color_match(color, 0x00ffffff, 1),
17532 "Expected color 0x00ffffff, got 0x%08x.\n", color);
17533 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17534 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17536 /* Partial LockRect works just like a partial AddDirtyRect call. */
17537 hr = IDirect3DTexture9_LockRect(tex_src_green, 0, &locked_rect, &part_rect, 0);
17538 ok(SUCCEEDED(hr), "Failed to lock texture, hr %#x.\n", hr);
17539 texel = locked_rect.pBits;
17540 for (i = 0; i < 64; i++)
17541 texel[i] = 0x00ff00ff;
17542 for (i = 1; i < 64; i++)
17543 memcpy((BYTE *)locked_rect.pBits + i * locked_rect.Pitch, locked_rect.pBits, locked_rect.Pitch);
17544 hr = IDirect3DTexture9_UnlockRect(tex_src_green, 0);
17545 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr);
17546 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
17547 (IDirect3DBaseTexture9 *)tex_dst2);
17548 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
17549 add_dirty_rect_test_draw(device);
17550 color = getPixelColor(device, 320, 240);
17551 ok(color_match(color, 0x00ff00ff, 1),
17552 "Expected color 0x00ff00ff, got 0x%08x.\n", color);
17553 color = getPixelColor(device, 1, 1);
17554 ok(color_match(color, 0x00ffffff, 1),
17555 "Expected color 0x00ffffff, got 0x%08x.\n", color);
17556 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17557 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17559 fill_surface(surface_src_red, 0x00ff0000, 0);
17560 fill_surface(surface_src_green, 0x0000ff00, 0);
17562 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
17563 (IDirect3DBaseTexture9 *)tex_dst1);
17564 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
17565 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)tex_dst1);
17566 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
17567 add_dirty_rect_test_draw(device);
17568 color = getPixelColor(device, 320, 240);
17569 ok(color_match(color, 0x0000ff00, 1),
17570 "Expected color 0x0000ff00, got 0x%08x.\n", color);
17571 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17572 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17574 /* UpdateSurface ignores the missing dirty marker. */
17575 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_red,
17576 (IDirect3DBaseTexture9 *)tex_dst2);
17577 hr = IDirect3DDevice9_UpdateSurface(device, surface_src_green, NULL, surface_dst2, NULL);
17578 ok(SUCCEEDED(hr), "Failed to update surface, hr %#x.\n", hr);
17579 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)tex_dst2);
17580 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
17581 add_dirty_rect_test_draw(device);
17582 color = getPixelColor(device, 320, 240);
17583 ok(color_match(color, 0x0000ff00, 1),
17584 "Expected color 0x0000ff00, got 0x%08x.\n", color);
17585 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17586 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17588 /* Tests with managed textures. */
17589 fill_surface(surface_managed0, 0x00ff0000, 0);
17590 fill_surface(surface_managed1, 0x00ff0000, 0);
17591 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)tex_managed);
17592 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
17593 add_dirty_rect_test_draw(device);
17594 color = getPixelColor(device, 320, 240);
17595 ok(color_match(color, 0x00ff0000, 1),
17596 "Expected color 0x00ff0000, got 0x%08x.\n", color);
17597 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17598 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17599 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 1);
17600 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
17601 add_dirty_rect_test_draw(device);
17602 color = getPixelColor(device, 320, 240);
17603 ok(color_match(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
17604 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17605 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17607 /* Managed textures also honor D3DLOCK_NO_DIRTY_UPDATE. */
17608 fill_surface(surface_managed0, 0x0000ff00, D3DLOCK_NO_DIRTY_UPDATE);
17609 fill_surface(surface_managed1, 0x000000ff, D3DLOCK_NO_DIRTY_UPDATE);
17610 add_dirty_rect_test_draw(device);
17611 color = getPixelColor(device, 320, 240);
17612 ok(color_match(color, 0x00ff0000, 1),
17613 "Expected color 0x00ff0000, got 0x%08x.\n", color);
17614 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17615 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17616 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 0);
17617 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
17618 add_dirty_rect_test_draw(device);
17619 color = getPixelColor(device, 320, 240);
17620 ok(color_match(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
17621 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17622 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17624 /* AddDirtyRect uploads the new contents.
17625 * Side note, not tested in the test: Partial surface updates work, and two separate
17626 * dirty rectangles are tracked individually. Tested on Nvidia Kepler, other drivers
17627 * untested. */
17628 hr = IDirect3DTexture9_AddDirtyRect(tex_managed, NULL);
17629 ok(SUCCEEDED(hr), "Failed to add dirty rect, hr %#x.\n", hr);
17630 add_dirty_rect_test_draw(device);
17631 color = getPixelColor(device, 320, 240);
17632 ok(color_match(color, 0x0000ff00, 1),
17633 "Expected color 0x0000ff00, got 0x%08x.\n", color);
17634 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17635 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17636 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 1);
17637 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
17638 add_dirty_rect_test_draw(device);
17639 color = getPixelColor(device, 320, 240);
17640 ok(color_match(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
17641 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17642 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17644 /* So does EvictManagedResources. */
17645 fill_surface(surface_managed0, 0x00ffff00, D3DLOCK_NO_DIRTY_UPDATE);
17646 fill_surface(surface_managed1, 0x00ff00ff, D3DLOCK_NO_DIRTY_UPDATE);
17647 hr = IDirect3DDevice9_EvictManagedResources(device);
17648 ok(SUCCEEDED(hr), "Failed to evict managed resources, hr %#x.\n", hr);
17649 add_dirty_rect_test_draw(device);
17650 color = getPixelColor(device, 320, 240);
17651 ok(color_match(color, 0x00ff00ff, 1), "Got unexpected color 0x%08x.\n", color);
17652 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17653 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17654 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 0);
17655 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
17656 add_dirty_rect_test_draw(device);
17657 color = getPixelColor(device, 320, 240);
17658 ok(color_match(color, 0x00ffff00, 1), "Got unexpected color 0x%08x.\n", color);
17659 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17660 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17662 /* Tests with dynamic textures */
17663 fill_surface(surface_dynamic, 0x0000ffff, 0);
17664 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)tex_dynamic);
17665 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
17666 add_dirty_rect_test_draw(device);
17667 color = getPixelColor(device, 320, 240);
17668 ok(color_match(color, 0x0000ffff, 1),
17669 "Expected color 0x0000ffff, got 0x%08x.\n", color);
17670 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17671 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17673 /* Dynamic textures don't honor D3DLOCK_NO_DIRTY_UPDATE. */
17674 fill_surface(surface_dynamic, 0x00ffff00, D3DLOCK_NO_DIRTY_UPDATE);
17675 add_dirty_rect_test_draw(device);
17676 color = getPixelColor(device, 320, 240);
17677 ok(color_match(color, 0x00ffff00, 1),
17678 "Expected color 0x00ffff00, got 0x%08x.\n", color);
17679 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17680 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17682 /* AddDirtyRect on a locked texture is allowed. */
17683 hr = IDirect3DTexture9_LockRect(tex_src_red, 0, &locked_rect, NULL, 0);
17684 ok(SUCCEEDED(hr), "Failed to lock texture, hr %#x.\n", hr);
17685 hr = IDirect3DTexture9_AddDirtyRect(tex_src_red, NULL);
17686 ok(SUCCEEDED(hr), "Failed to add dirty rect, hr %#x.\n", hr);
17687 hr = IDirect3DTexture9_UnlockRect(tex_src_red, 0);
17688 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr);
17690 /* Redundant AddDirtyRect calls are ok. */
17691 hr = IDirect3DTexture9_AddDirtyRect(tex_managed, NULL);
17692 ok(SUCCEEDED(hr), "Failed to add dirty rect, hr %#x.\n", hr);
17693 hr = IDirect3DTexture9_AddDirtyRect(tex_managed, NULL);
17694 ok(SUCCEEDED(hr), "Failed to add dirty rect, hr %#x.\n", hr);
17696 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_DISABLE);
17697 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
17698 hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
17699 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
17700 IDirect3DSurface9_Release(surface_dst2);
17701 IDirect3DSurface9_Release(surface_managed1);
17702 IDirect3DSurface9_Release(surface_managed0);
17703 IDirect3DSurface9_Release(surface_src_red);
17704 IDirect3DSurface9_Release(surface_src_green);
17705 IDirect3DSurface9_Release(surface_dynamic);
17706 IDirect3DTexture9_Release(tex_src_red);
17707 IDirect3DTexture9_Release(tex_src_green);
17708 IDirect3DTexture9_Release(tex_dst1);
17709 IDirect3DTexture9_Release(tex_dst2);
17710 IDirect3DTexture9_Release(tex_managed);
17711 IDirect3DTexture9_Release(tex_dynamic);
17712 refcount = IDirect3DDevice9_Release(device);
17713 ok(!refcount, "Device has %u references left.\n", refcount);
17714 IDirect3D9_Release(d3d);
17715 DestroyWindow(window);
17718 static void test_per_stage_constant(void)
17720 IDirect3DDevice9 *device;
17721 IDirect3D9 *d3d;
17722 D3DCOLOR color;
17723 ULONG refcount;
17724 D3DCAPS9 caps;
17725 HWND window;
17726 HRESULT hr;
17728 static const struct
17730 struct vec3 position;
17731 D3DCOLOR diffuse;
17733 quad[] =
17735 {{-1.0f, -1.0f, 0.1f}, 0xffff0000},
17736 {{-1.0f, 1.0f, 0.1f}, 0xffff0000},
17737 {{ 1.0f, -1.0f, 0.1f}, 0xffff0000},
17738 {{ 1.0f, 1.0f, 0.1f}, 0xffff0000},
17741 window = create_window();
17742 d3d = Direct3DCreate9(D3D_SDK_VERSION);
17743 ok(!!d3d, "Failed to create a D3D object.\n");
17744 if (!(device = create_device(d3d, window, window, TRUE)))
17746 skip("Failed to create a D3D device, skipping tests.\n");
17747 goto done;
17750 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
17751 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
17752 if (!(caps.PrimitiveMiscCaps & D3DPMISCCAPS_PERSTAGECONSTANT))
17754 skip("Per-stage constants not supported, skipping tests.\n");
17755 IDirect3DDevice9_Release(device);
17756 goto done;
17759 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
17760 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
17761 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHABLENDENABLE, TRUE);
17762 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
17763 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
17764 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
17765 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
17766 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
17767 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
17768 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
17770 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_CONSTANT, 0x80a1b2c3);
17771 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
17772 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_CONSTANT);
17773 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
17774 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
17775 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
17777 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x000000ff, 1.0f, 0);
17778 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
17780 hr = IDirect3DDevice9_BeginScene(device);
17781 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
17782 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
17783 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
17784 hr = IDirect3DDevice9_EndScene(device);
17785 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
17787 color = getPixelColor(device, 320, 240);
17788 ok(color_match(color, 0x00a1b2c3, 1), "Got unexpected color 0x%08x.\n", color);
17789 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17790 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17792 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_CONSTANT | D3DTA_COMPLEMENT);
17793 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
17795 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x000000ff, 1.0f, 0);
17796 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
17798 hr = IDirect3DDevice9_BeginScene(device);
17799 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
17800 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
17801 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
17802 hr = IDirect3DDevice9_EndScene(device);
17803 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
17805 color = getPixelColor(device, 320, 240);
17806 ok(color_match(color, 0x005e4d3c, 1), "Got unexpected color 0x%08x.\n", color);
17807 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17808 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17810 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_CONSTANT | D3DTA_ALPHAREPLICATE);
17811 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
17813 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x000000ff, 1.0f, 0);
17814 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
17816 hr = IDirect3DDevice9_BeginScene(device);
17817 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
17818 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
17819 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
17820 hr = IDirect3DDevice9_EndScene(device);
17821 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
17823 color = getPixelColor(device, 320, 240);
17824 ok(color_match(color, 0x00808080, 1), "Got unexpected color 0x%08x.\n", color);
17825 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17826 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17828 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAARG1, D3DTA_CONSTANT);
17829 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
17830 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
17831 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
17832 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_CURRENT);
17833 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
17835 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x000000ff, 1.0f, 0);
17836 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
17838 hr = IDirect3DDevice9_BeginScene(device);
17839 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
17840 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
17841 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
17842 hr = IDirect3DDevice9_EndScene(device);
17843 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
17845 color = getPixelColor(device, 320, 240);
17846 ok(color_match(color, 0x0080007f, 1), "Got unexpected color 0x%08x.\n", color);
17847 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17848 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17850 refcount = IDirect3DDevice9_Release(device);
17851 ok(!refcount, "Device has %u references left.\n", refcount);
17852 done:
17853 IDirect3D9_Release(d3d);
17854 DestroyWindow(window);
17857 static void test_3dc_formats(void)
17859 static const char ati1n_data[] =
17861 /* A 4x4 texture with the color component at 50%. */
17862 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
17864 static const char ati2n_data[] =
17866 /* A 8x4 texture consisting of 2 4x4 blocks. The first block has 50% first color component,
17867 * 0% second component. Second block is the opposite. */
17868 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
17869 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
17871 static const struct
17873 struct vec3 position;
17874 struct vec2 texcoord;
17876 quads[] =
17878 {{-1.0f, -1.0f, 0.0f}, {0.0f, 0.0f}},
17879 {{-1.0f, 1.0f, 0.0f}, {0.0f, 1.0f}},
17880 {{ 0.0f, -1.0f, 1.0f}, {1.0f, 0.0f}},
17881 {{ 0.0f, 1.0f, 1.0f}, {1.0f, 1.0f}},
17883 {{ 0.0f, -1.0f, 0.0f}, {0.0f, 0.0f}},
17884 {{ 0.0f, 1.0f, 0.0f}, {0.0f, 1.0f}},
17885 {{ 1.0f, -1.0f, 1.0f}, {1.0f, 0.0f}},
17886 {{ 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f}},
17888 static const DWORD ati1n_fourcc = MAKEFOURCC('A','T','I','1');
17889 static const DWORD ati2n_fourcc = MAKEFOURCC('A','T','I','2');
17890 static const struct
17892 struct vec2 position;
17893 D3DCOLOR amd_r500;
17894 D3DCOLOR amd_r600;
17895 D3DCOLOR nvidia_old;
17896 D3DCOLOR nvidia_new;
17898 expected_colors[] =
17900 {{ 80, 240}, 0x007fffff, 0x003f3f3f, 0x007f7f7f, 0x007f0000},
17901 {{240, 240}, 0x007fffff, 0x003f3f3f, 0x007f7f7f, 0x007f0000},
17902 {{400, 240}, 0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff},
17903 {{560, 240}, 0x007f00ff, 0x007f00ff, 0x007f00ff, 0x007f00ff},
17905 IDirect3D9 *d3d;
17906 IDirect3DDevice9 *device;
17907 IDirect3DTexture9 *ati1n_texture, *ati2n_texture;
17908 D3DCAPS9 caps;
17909 D3DLOCKED_RECT rect;
17910 D3DCOLOR color;
17911 ULONG refcount;
17912 HWND window;
17913 HRESULT hr;
17914 unsigned int i;
17916 window = create_window();
17917 d3d = Direct3DCreate9(D3D_SDK_VERSION);
17918 ok(!!d3d, "Failed to create a D3D object.\n");
17919 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
17920 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, ati1n_fourcc)))
17922 skip("ATI1N textures are not supported, skipping test.\n");
17923 goto done;
17925 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
17926 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, ati2n_fourcc)))
17928 skip("ATI2N textures are not supported, skipping test.\n");
17929 goto done;
17931 if (!(device = create_device(d3d, window, window, TRUE)))
17933 skip("Failed to create a D3D device, skipping tests.\n");
17934 goto done;
17936 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
17937 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
17938 if (!(caps.PrimitiveMiscCaps & D3DPMISCCAPS_TSSARGTEMP))
17940 skip("D3DTA_TEMP not supported, skipping tests.\n");
17941 IDirect3DDevice9_Release(device);
17942 goto done;
17945 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, ati1n_fourcc,
17946 D3DPOOL_MANAGED, &ati1n_texture, NULL);
17947 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17949 hr = IDirect3DTexture9_LockRect(ati1n_texture, 0, &rect, NULL, 0);
17950 ok(SUCCEEDED(hr), "Failed to lock texture, hr %#x.\n", hr);
17951 memcpy(rect.pBits, ati1n_data, sizeof(ati1n_data));
17952 hr = IDirect3DTexture9_UnlockRect(ati1n_texture, 0);
17953 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr);
17955 hr = IDirect3DDevice9_CreateTexture(device, 8, 4, 1, 0, ati2n_fourcc,
17956 D3DPOOL_MANAGED, &ati2n_texture, NULL);
17957 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17959 hr = IDirect3DTexture9_LockRect(ati2n_texture, 0, &rect, NULL, 0);
17960 ok(SUCCEEDED(hr), "Failed to lock texture, hr %#x.\n", hr);
17961 memcpy(rect.pBits, ati2n_data, sizeof(ati2n_data));
17962 hr = IDirect3DTexture9_UnlockRect(ati2n_texture, 0);
17963 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr);
17965 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE2(0));
17966 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
17967 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA);
17968 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
17969 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
17970 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
17971 /* The temporary register is initialized to 0. */
17972 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TEMP);
17973 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
17974 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
17975 ok(SUCCEEDED(hr), "Failed to set alpha op, hr %#x.\n", hr);
17976 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
17977 ok(SUCCEEDED(hr), "Failed to set alpha arg, hr %#x.\n", hr);
17978 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
17979 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
17980 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
17981 ok(SUCCEEDED(hr), "Failed to set mag filter, hr %#x.\n", hr);
17983 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff00ff, 1.0f, 0);
17984 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
17985 hr = IDirect3DDevice9_BeginScene(device);
17986 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
17987 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)ati1n_texture);
17988 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
17989 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[0], sizeof(*quads));
17990 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
17991 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)ati2n_texture);
17992 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
17993 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[4], sizeof(*quads));
17994 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
17995 hr = IDirect3DDevice9_EndScene(device);
17996 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
17998 for (i = 0; i < 4; ++i)
18000 color = getPixelColor(device, expected_colors[i].position.x, expected_colors[i].position.y);
18001 ok (color_match(color, expected_colors[i].amd_r500, 1)
18002 || color_match(color, expected_colors[i].amd_r600, 1)
18003 || color_match(color, expected_colors[i].nvidia_old, 1)
18004 || color_match(color, expected_colors[i].nvidia_new, 1),
18005 "Got unexpected color 0x%08x, case %u.\n", color, i);
18008 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
18009 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
18010 IDirect3DTexture9_Release(ati2n_texture);
18011 IDirect3DTexture9_Release(ati1n_texture);
18012 refcount = IDirect3DDevice9_Release(device);
18013 ok(!refcount, "Device has %u references left.\n", refcount);
18015 done:
18016 IDirect3D9_Release(d3d);
18017 DestroyWindow(window);
18020 static void test_fog_interpolation(void)
18022 HRESULT hr;
18023 IDirect3DDevice9 *device;
18024 IDirect3D9 *d3d;
18025 ULONG refcount;
18026 HWND window;
18027 D3DCOLOR color;
18028 static const struct
18030 struct vec3 position;
18031 D3DCOLOR diffuse;
18032 D3DCOLOR specular;
18034 quad[] =
18036 {{-1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff000000},
18037 {{-1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff000000},
18038 {{ 1.0f, -1.0f, 1.0f}, 0xffff0000, 0x00000000},
18039 {{ 1.0f, 1.0f, 1.0f}, 0xffff0000, 0x00000000},
18041 union
18043 DWORD d;
18044 float f;
18045 } conv;
18046 unsigned int i;
18047 static const struct
18049 D3DFOGMODE vfog, tfog;
18050 D3DSHADEMODE shade;
18051 D3DCOLOR middle_color;
18052 BOOL todo;
18054 tests[] =
18056 {D3DFOG_NONE, D3DFOG_NONE, D3DSHADE_FLAT, 0x00007f80, FALSE},
18057 {D3DFOG_NONE, D3DFOG_NONE, D3DSHADE_GOURAUD, 0x00007f80, FALSE},
18058 {D3DFOG_EXP, D3DFOG_NONE, D3DSHADE_FLAT, 0x00007f80, TRUE},
18059 {D3DFOG_EXP, D3DFOG_NONE, D3DSHADE_GOURAUD, 0x00007f80, TRUE},
18060 {D3DFOG_NONE, D3DFOG_EXP, D3DSHADE_FLAT, 0x0000ea15, FALSE},
18061 {D3DFOG_NONE, D3DFOG_EXP, D3DSHADE_GOURAUD, 0x0000ea15, FALSE},
18062 {D3DFOG_EXP, D3DFOG_EXP, D3DSHADE_FLAT, 0x0000ea15, FALSE},
18063 {D3DFOG_EXP, D3DFOG_EXP, D3DSHADE_GOURAUD, 0x0000ea15, FALSE},
18065 static const D3DMATRIX ident_mat =
18067 1.0f, 0.0f, 0.0f, 0.0f,
18068 0.0f, 1.0f, 0.0f, 0.0f,
18069 0.0f, 0.0f, 1.0f, 0.0f,
18070 0.0f, 0.0f, 0.0f, 1.0f
18071 }}};
18072 D3DCAPS9 caps;
18074 window = create_window();
18075 d3d = Direct3DCreate9(D3D_SDK_VERSION);
18076 ok(!!d3d, "Failed to create a D3D object.\n");
18078 if (!(device = create_device(d3d, window, window, TRUE)))
18080 skip("Failed to create a D3D device, skipping tests.\n");
18081 IDirect3D9_Release(d3d);
18082 DestroyWindow(window);
18083 return;
18086 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
18087 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
18088 if (!(caps.RasterCaps & D3DPRASTERCAPS_FOGTABLE))
18089 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests\n");
18091 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
18092 ok(SUCCEEDED(hr), "Failed to set fvf, hr %#x.\n", hr);
18093 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
18094 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
18095 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
18096 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
18097 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGENABLE, TRUE);
18098 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
18099 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGCOLOR, 0x0000ff00);
18100 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
18101 conv.f = 5.0;
18102 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGDENSITY, conv.d);
18103 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
18105 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
18106 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
18107 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
18108 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
18109 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0x000000ff);
18110 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
18112 /* Some of the tests seem to depend on the projection matrix explicitly
18113 * being set to an identity matrix, even though that's the default.
18114 * (AMD Radeon X1600, AMD Radeon HD 6310, Windows 7). Without this,
18115 * the drivers seem to use a static z = 1.0 input for the fog equation.
18116 * The input value is independent of the actual z and w component of
18117 * the vertex position. */
18118 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &ident_mat);
18119 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
18121 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
18123 if(!(caps.RasterCaps & D3DPRASTERCAPS_FOGTABLE) && tests[i].tfog)
18124 continue;
18126 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00808080, 0.0f, 0);
18127 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
18129 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SHADEMODE, tests[i].shade);
18130 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
18131 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGVERTEXMODE, tests[i].vfog);
18132 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
18133 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, tests[i].tfog);
18134 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
18135 hr = IDirect3DDevice9_BeginScene(device);
18136 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
18137 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
18138 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
18139 hr = IDirect3DDevice9_EndScene(device);
18140 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
18142 color = getPixelColor(device, 0, 240);
18143 ok(color_match(color, 0x000000ff, 2), "Got unexpected color 0x%08x, case %u.\n", color, i);
18144 color = getPixelColor(device, 320, 240);
18145 todo_wine_if (tests[i].todo)
18146 ok(color_match(color, tests[i].middle_color, 2),
18147 "Got unexpected color 0x%08x, case %u.\n", color, i);
18148 color = getPixelColor(device, 639, 240);
18149 ok(color_match(color, 0x0000fd02, 2), "Got unexpected color 0x%08x, case %u.\n", color, i);
18150 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
18151 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
18154 refcount = IDirect3DDevice9_Release(device);
18155 ok(!refcount, "Device has %u references left.\n", refcount);
18156 IDirect3D9_Release(d3d);
18157 DestroyWindow(window);
18160 static void test_negative_fixedfunction_fog(void)
18162 HRESULT hr;
18163 IDirect3DDevice9 *device;
18164 IDirect3D9 *d3d;
18165 ULONG refcount;
18166 HWND window;
18167 D3DCOLOR color;
18168 static const struct
18170 struct vec3 position;
18171 D3DCOLOR diffuse;
18173 quad[] =
18175 {{-1.0f, -1.0f, -0.5f}, 0xffff0000},
18176 {{-1.0f, 1.0f, -0.5f}, 0xffff0000},
18177 {{ 1.0f, -1.0f, -0.5f}, 0xffff0000},
18178 {{ 1.0f, 1.0f, -0.5f}, 0xffff0000},
18180 static const struct
18182 struct vec4 position;
18183 D3DCOLOR diffuse;
18185 tquad[] =
18187 {{ 0.0f, 0.0f, -0.5f, 1.0f}, 0xffff0000},
18188 {{640.0f, 0.0f, -0.5f, 1.0f}, 0xffff0000},
18189 {{ 0.0f, 480.0f, -0.5f, 1.0f}, 0xffff0000},
18190 {{640.0f, 480.0f, -0.5f, 1.0f}, 0xffff0000},
18192 unsigned int i;
18193 static const D3DMATRIX zero =
18195 1.0f, 0.0f, 0.0f, 0.0f,
18196 0.0f, 1.0f, 0.0f, 0.0f,
18197 0.0f, 0.0f, 0.0f, 0.0f,
18198 0.0f, 0.0f, 0.0f, 1.0f
18199 }}};
18200 /* Needed to make AMD drivers happy. Yeah, it is not supposed to
18201 * have an effect on RHW draws. */
18202 static const D3DMATRIX identity =
18204 1.0f, 0.0f, 0.0f, 0.0f,
18205 0.0f, 1.0f, 0.0f, 0.0f,
18206 0.0f, 0.0f, 1.0f, 0.0f,
18207 0.0f, 0.0f, 0.0f, 1.0f
18208 }}};
18209 static const struct
18211 DWORD pos_type;
18212 const void *quad;
18213 size_t stride;
18214 const D3DMATRIX *matrix;
18215 union
18217 float f;
18218 DWORD d;
18219 } start, end;
18220 D3DFOGMODE vfog, tfog;
18221 DWORD color, color_broken, color_broken2;
18223 tests[] =
18225 /* Run the XYZRHW tests first. Depth clamping is broken after RHW draws on the testbot.
18227 * Geforce8+ GPUs on Windows abs() table fog, everything else does not. */
18228 {D3DFVF_XYZRHW, tquad, sizeof(*tquad), &identity, { 0.0f}, {1.0f},
18229 D3DFOG_NONE, D3DFOG_LINEAR, 0x00ff0000, 0x00808000, 0x00808000},
18230 /* r200 GPUs and presumably all d3d8 and older HW clamp the fog
18231 * parameters to 0.0 and 1.0 in the table fog case. */
18232 {D3DFVF_XYZRHW, tquad, sizeof(*tquad), &identity, {-1.0f}, {0.0f},
18233 D3DFOG_NONE, D3DFOG_LINEAR, 0x00808000, 0x00ff0000, 0x0000ff00},
18234 /* test_fog_interpolation shows that vertex fog evaluates the fog
18235 * equation in the vertex pipeline. Start = -1.0 && end = 0.0 shows
18236 * that the abs happens before the fog equation is evaluated.
18238 * Vertex fog abs() behavior is the same on all GPUs. */
18239 {D3DFVF_XYZ, quad, sizeof(*quad), &zero, { 0.0f}, {1.0f},
18240 D3DFOG_LINEAR, D3DFOG_NONE, 0x00808000, 0x00808000, 0x00808000},
18241 {D3DFVF_XYZ, quad, sizeof(*quad), &zero, {-1.0f}, {0.0f},
18242 D3DFOG_LINEAR, D3DFOG_NONE, 0x0000ff00, 0x0000ff00, 0x0000ff00},
18243 {D3DFVF_XYZ, quad, sizeof(*quad), &zero, { 0.0f}, {1.0f},
18244 D3DFOG_EXP, D3DFOG_NONE, 0x009b6400, 0x009b6400, 0x009b6400},
18246 D3DCAPS9 caps;
18248 window = create_window();
18249 d3d = Direct3DCreate9(D3D_SDK_VERSION);
18250 ok(!!d3d, "Failed to create a D3D object.\n");
18252 if (!(device = create_device(d3d, window, window, TRUE)))
18254 skip("Failed to create a D3D device, skipping tests.\n");
18255 IDirect3D9_Release(d3d);
18256 DestroyWindow(window);
18257 return;
18260 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
18261 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
18262 if (!(caps.RasterCaps & D3DPRASTERCAPS_FOGTABLE))
18263 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests.\n");
18265 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
18266 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
18267 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
18268 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
18269 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGENABLE, TRUE);
18270 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
18271 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGCOLOR, 0x0000ff00);
18272 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
18273 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, FALSE);
18274 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
18276 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
18278 if (!(caps.RasterCaps & D3DPRASTERCAPS_FOGTABLE) && tests[i].tfog)
18279 continue;
18281 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x000000ff, 0.0f, 0);
18282 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
18284 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, tests[i].matrix);
18285 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
18286 hr = IDirect3DDevice9_SetFVF(device, tests[i].pos_type | D3DFVF_DIFFUSE);
18287 ok(SUCCEEDED(hr), "Failed to set fvf, hr %#x.\n", hr);
18288 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGSTART, tests[i].start.d);
18289 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
18290 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGEND, tests[i].end.d);
18291 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
18292 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGVERTEXMODE, tests[i].vfog);
18293 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
18294 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, tests[i].tfog);
18295 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
18297 hr = IDirect3DDevice9_BeginScene(device);
18298 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
18299 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, tests[i].quad, tests[i].stride);
18300 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
18301 hr = IDirect3DDevice9_EndScene(device);
18302 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
18304 color = getPixelColor(device, 320, 240);
18305 ok(color_match(color, tests[i].color, 2) || broken(color_match(color, tests[i].color_broken, 2))
18306 || broken(color_match(color, tests[i].color_broken2, 2)),
18307 "Got unexpected color 0x%08x, case %u.\n", color, i);
18308 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
18309 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
18312 refcount = IDirect3DDevice9_Release(device);
18313 ok(!refcount, "Device has %u references left.\n", refcount);
18314 IDirect3D9_Release(d3d);
18315 DestroyWindow(window);
18318 static void test_position_index(void)
18320 static const D3DVERTEXELEMENT9 decl_elements[] =
18322 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
18323 {0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 1},
18324 D3DDECL_END()
18326 /* Declaring (and using) a position1 output semantic in a VS fails at draw time on AMD
18327 * but works on Nvidia.
18328 * MSDN is not consistent on this point. */
18329 static const DWORD vs_code[] =
18331 0xfffe0300, /* vs_3_0 */
18332 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position0 v0 */
18333 0x0200001f, 0x80010000, 0x900f0001, /* dcl_position1 v1 */
18334 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position0 o0 */
18335 0x0200001f, 0x80010000, 0xe00f0001, /* dcl_position1 o1 */
18336 0x0200001f, 0x80000005, 0xe00f0002, /* dcl_texcoord0 o2 */
18337 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
18338 0x02000001, 0xe00f0001, 0x90e40001, /* mov o1, v1 */
18339 0x02000001, 0xe00f0002, 0x90e40001, /* mov o2, v1 */
18340 0x0000ffff /* end */
18342 static const DWORD vs_code_2[] =
18344 0xfffe0300, /* vs_3_0 */
18345 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position0 v0 */
18346 0x0200001f, 0x80010000, 0x900f0001, /* dcl_position1 v1 */
18347 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position0 o0 */
18348 0x0200001f, 0x80000005, 0xe00f0002, /* dcl_texcoord0 o2 */
18349 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
18350 0x02000001, 0xe00f0002, 0x90e40001, /* mov o2, v1 */
18351 0x0000ffff /* end */
18353 static const DWORD ps_code[] =
18355 0xffff0300, /* ps_3_0 */
18356 0x0200001f, 0x80010000, 0x900f0000, /* dcl_position1 v0 */
18357 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
18358 0x0000ffff /* end */
18360 static const DWORD ps_code_2[] =
18362 0xffff0300, /* ps_3_0 */
18363 0x0200001f, 0x80000005, 0x900f0000, /* dcl_texcoord0 v0 */
18364 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
18365 0x0000ffff /* end */
18367 /* This one is considered invalid by the native shader assembler. */
18368 static const DWORD ps_code_bad[] =
18370 0xffff0300, /* ps_3_0 */
18371 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position0 v0 */
18372 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
18373 0x0000ffff /* end */
18375 static const struct
18377 struct vec3 position;
18378 struct vec3 position1;
18380 quad[] =
18382 {{-1.0f, -1.0f, 0.5f}, {1.0f, 0.0f, 0.0f}},
18383 {{-1.0f, 1.0f, 0.5f}, {1.0f, 0.0f, 0.0f}},
18384 {{ 1.0f, -1.0f, 0.5f}, {0.0f, 1.0f, 0.0f}},
18385 {{ 1.0f, 1.0f, 0.5f}, {0.0f, 1.0f, 0.0f}},
18387 static const struct
18389 struct vec2 position;
18390 D3DCOLOR expected_color;
18391 D3DCOLOR broken_color;
18393 expected_colors[] =
18395 {{ 80, 240}, 0x00df2000, 0x00ff00ff},
18396 {{240, 240}, 0x009f6000, 0x00ff00ff},
18397 {{400, 240}, 0x00609f00, 0x00ff00ff},
18398 {{560, 240}, 0x0020df00, 0x00ff00ff},
18400 IDirect3D9 *d3d;
18401 IDirect3DDevice9 *device;
18402 IDirect3DVertexDeclaration9 *vertex_declaration;
18403 IDirect3DVertexShader9 *vs, *vs2;
18404 IDirect3DPixelShader9 *ps, *ps2;
18405 D3DCAPS9 caps;
18406 D3DCOLOR color;
18407 ULONG refcount;
18408 HWND window;
18409 HRESULT hr;
18410 unsigned int i;
18412 window = create_window();
18413 d3d = Direct3DCreate9(D3D_SDK_VERSION);
18414 ok(!!d3d, "Failed to create a D3D object.\n");
18415 if (!(device = create_device(d3d, window, window, TRUE)))
18417 skip("Failed to create a D3D device, skipping tests.\n");
18418 goto done;
18421 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
18422 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
18423 if (caps.VertexShaderVersion < D3DVS_VERSION(3, 0)
18424 || caps.PixelShaderVersion < D3DPS_VERSION(3, 0))
18426 skip("Shader model 3.0 unsupported, skipping tests.\n");
18427 IDirect3DDevice9_Release(device);
18428 goto done;
18431 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &vertex_declaration);
18432 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed, hr %#x\n", hr);
18434 hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration);
18435 ok(SUCCEEDED(hr), "SetVertexDeclaration failed, hr %#x\n", hr);
18437 hr = IDirect3DDevice9_CreateVertexShader(device, vs_code, &vs);
18438 ok(SUCCEEDED(hr), "CreateVertexShader failed, hr %#x.\n", hr);
18439 hr = IDirect3DDevice9_CreateVertexShader(device, vs_code_2, &vs2);
18440 ok(SUCCEEDED(hr), "CreateVertexShader failed, hr %#x.\n", hr);
18442 hr = IDirect3DDevice9_SetVertexShader(device, vs);
18443 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
18445 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code_bad, &ps);
18446 ok(hr == D3DERR_INVALIDCALL, "CreatePixelShader returned hr %#x.\n", hr);
18448 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code, &ps);
18449 ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
18450 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code_2, &ps2);
18451 ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
18453 hr = IDirect3DDevice9_SetPixelShader(device, ps);
18454 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
18456 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff00ff, 1.0f, 0);
18457 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
18458 hr = IDirect3DDevice9_BeginScene(device);
18459 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
18460 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
18461 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
18462 hr = IDirect3DDevice9_EndScene(device);
18463 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
18465 for (i = 0; i < sizeof(expected_colors) / sizeof(expected_colors[0]); ++i)
18467 color = getPixelColor(device, expected_colors[i].position.x, expected_colors[i].position.y);
18468 ok (color_match(color, expected_colors[i].expected_color, 1)
18469 || broken(color_match(color, expected_colors[i].broken_color, 1)),
18470 "Got unexpected color 0x%08x, case %u.\n", color, i);
18473 hr = IDirect3DDevice9_SetPixelShader(device, ps2);
18474 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
18476 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff00ff, 1.0f, 0);
18477 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
18478 hr = IDirect3DDevice9_BeginScene(device);
18479 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
18480 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
18481 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
18482 hr = IDirect3DDevice9_EndScene(device);
18483 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
18485 for (i = 0; i < sizeof(expected_colors) / sizeof(expected_colors[0]); ++i)
18487 color = getPixelColor(device, expected_colors[i].position.x, expected_colors[i].position.y);
18488 ok (color_match(color, expected_colors[i].expected_color, 1)
18489 || broken(color_match(color, expected_colors[i].broken_color, 1)),
18490 "Got unexpected color 0x%08x, case %u.\n", color, i);
18493 hr = IDirect3DDevice9_SetVertexShader(device, vs2);
18494 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
18496 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff00ff, 1.0f, 0);
18497 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
18498 hr = IDirect3DDevice9_BeginScene(device);
18499 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
18500 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
18501 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
18502 hr = IDirect3DDevice9_EndScene(device);
18503 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
18505 for (i = 0; i < sizeof(expected_colors) / sizeof(expected_colors[0]); ++i)
18507 color = getPixelColor(device, expected_colors[i].position.x, expected_colors[i].position.y);
18508 ok (color_match(color, expected_colors[i].expected_color, 1),
18509 "Got unexpected color 0x%08x, case %u.\n", color, i);
18512 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
18513 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
18515 IDirect3DPixelShader9_Release(ps2);
18516 IDirect3DPixelShader9_Release(ps);
18517 IDirect3DVertexShader9_Release(vs2);
18518 IDirect3DVertexShader9_Release(vs);
18519 IDirect3DVertexDeclaration9_Release(vertex_declaration);
18520 refcount = IDirect3DDevice9_Release(device);
18521 ok(!refcount, "Device has %u references left.\n", refcount);
18523 done:
18524 IDirect3D9_Release(d3d);
18525 DestroyWindow(window);
18528 static void test_table_fog_zw(void)
18530 HRESULT hr;
18531 IDirect3DDevice9 *device;
18532 IDirect3D9 *d3d;
18533 ULONG refcount;
18534 HWND window;
18535 D3DCOLOR color;
18536 D3DCAPS9 caps;
18537 static struct
18539 struct vec4 position;
18540 D3DCOLOR diffuse;
18542 quad[] =
18544 {{ 0.0f, 0.0f, 0.0f, 0.0f}, 0xffff0000},
18545 {{640.0f, 0.0f, 0.0f, 0.0f}, 0xffff0000},
18546 {{ 0.0f, 480.0f, 0.0f, 0.0f}, 0xffff0000},
18547 {{640.0f, 480.0f, 0.0f, 0.0f}, 0xffff0000},
18549 static const D3DMATRIX identity =
18551 1.0f, 0.0f, 0.0f, 0.0f,
18552 0.0f, 1.0f, 0.0f, 0.0f,
18553 0.0f, 0.0f, 1.0f, 0.0f,
18554 0.0f, 0.0f, 0.0f, 1.0f
18555 }}};
18556 static const struct
18558 float z, w;
18559 D3DZBUFFERTYPE z_test;
18560 D3DCOLOR color;
18562 tests[] =
18564 {0.7f, 0.0f, D3DZB_TRUE, 0x004cb200},
18565 {0.7f, 0.0f, D3DZB_FALSE, 0x004cb200},
18566 {0.7f, 0.3f, D3DZB_TRUE, 0x004cb200},
18567 {0.7f, 0.3f, D3DZB_FALSE, 0x004cb200},
18568 {0.7f, 3.0f, D3DZB_TRUE, 0x004cb200},
18569 {0.7f, 3.0f, D3DZB_FALSE, 0x004cb200},
18570 {0.3f, 0.0f, D3DZB_TRUE, 0x00b24c00},
18571 {0.3f, 0.0f, D3DZB_FALSE, 0x00b24c00},
18573 unsigned int i;
18575 window = create_window();
18576 d3d = Direct3DCreate9(D3D_SDK_VERSION);
18577 ok(!!d3d, "Failed to create a D3D object.\n");
18579 if (!(device = create_device(d3d, window, window, TRUE)))
18581 skip("Failed to create a D3D device, skipping tests.\n");
18582 IDirect3D9_Release(d3d);
18583 DestroyWindow(window);
18584 return;
18587 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
18588 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
18589 if (!(caps.RasterCaps & D3DPRASTERCAPS_FOGTABLE))
18591 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping POSITIONT table fog test.\n");
18592 goto done;
18595 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
18596 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
18597 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGENABLE, TRUE);
18598 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
18599 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGCOLOR, 0x0000ff00);
18600 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
18601 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, FALSE);
18602 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
18603 /* Work around an AMD Windows driver bug. Needs a proj matrix applied redundantly. */
18604 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &identity);
18605 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
18606 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);
18607 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
18608 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
18609 ok(SUCCEEDED(hr), "Failed to set fvf, hr %#x.\n", hr);
18611 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
18613 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x000000ff, 1.0f, 0);
18614 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
18616 quad[0].position.z = tests[i].z;
18617 quad[1].position.z = tests[i].z;
18618 quad[2].position.z = tests[i].z;
18619 quad[3].position.z = tests[i].z;
18620 quad[0].position.w = tests[i].w;
18621 quad[1].position.w = tests[i].w;
18622 quad[2].position.w = tests[i].w;
18623 quad[3].position.w = tests[i].w;
18624 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, tests[i].z_test);
18625 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
18627 hr = IDirect3DDevice9_BeginScene(device);
18628 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
18629 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
18630 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
18631 hr = IDirect3DDevice9_EndScene(device);
18632 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
18634 color = getPixelColor(device, 320, 240);
18635 ok(color_match(color, tests[i].color, 2),
18636 "Got unexpected color 0x%08x, expected 0x%08x, case %u.\n", color, tests[i].color, i);
18637 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
18638 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
18641 done:
18642 refcount = IDirect3DDevice9_Release(device);
18643 ok(!refcount, "Device has %u references left.\n", refcount);
18644 IDirect3D9_Release(d3d);
18645 DestroyWindow(window);
18648 static void test_signed_formats(void)
18650 IDirect3DDevice9 *device;
18651 HWND window;
18652 HRESULT hr;
18653 unsigned int i, j, x, y;
18654 IDirect3DTexture9 *texture, *texture_sysmem;
18655 IDirect3DSurface9 *src_surface, *dst_surface;
18656 D3DLOCKED_RECT locked_rect;
18657 IDirect3DPixelShader9 *shader, *shader_alpha;
18658 IDirect3D9 *d3d;
18659 D3DCOLOR color;
18660 D3DCAPS9 caps;
18661 ULONG refcount;
18663 /* The input data was designed for D3DFMT_L6V5U5 and then transferred
18664 * to the other formats because L6V5U5 is the lowest precision format.
18665 * It tests the extreme values -1.0 (-16) and 1.0 (15) for U/V and
18666 * 0.0 (0) and 1.0 (63) for L, the neutral point 0 as well as -1 and 1.
18667 * Some other intermediate values are tested too. The input value -15
18668 * (min + 1) is tested as well. Unlike what OpenGL 4.4 says in section
18669 * 2.3.4.1, this value does not represent -1.0. In the interest of re-
18670 * using the expected output data the 8 bit and 16 bit values in V8U8
18671 * and V16U16 match (post-normalization) the 5 bit input values. Thus
18672 * -1, 1 and -127 are not tested in V8U8.
18674 * 8 bit specific values like -127 are tested in the Q channel of
18675 * D3DFMT_Q8W8V8U8. Here d3d seems to follow the rules from the GL
18676 * spec. AMD's r200 is broken though and returns a value < -1.0 for
18677 * -128. The difference between using -127 or -128 as the lowest
18678 * possible value gets lost in the slop of 1 though. */
18679 static const USHORT content_v8u8[4][4] =
18681 {0x0000, 0x7f7f, 0x8880, 0x0000},
18682 {0x0080, 0x8000, 0x7f00, 0x007f},
18683 {0x193b, 0xe8c8, 0x0808, 0xf8f8},
18684 {0x4444, 0xc0c0, 0xa066, 0x22e0},
18686 static const DWORD content_v16u16[4][4] =
18688 {0x00000000, 0x7fff7fff, 0x88008000, 0x00000000},
18689 {0x00008000, 0x80000000, 0x7fff0000, 0x00007fff},
18690 {0x19993bbb, 0xe800c800, 0x08880888, 0xf800f800},
18691 {0x44444444, 0xc000c000, 0xa0006666, 0x2222e000},
18693 static const DWORD content_q8w8v8u8[4][4] =
18695 {0x00000000, 0xff7f7f7f, 0x7f008880, 0x817f0000},
18696 {0x10000080, 0x20008000, 0x30007f00, 0x4000007f},
18697 {0x5020193b, 0x6028e8c8, 0x70020808, 0x807ff8f8},
18698 {0x90414444, 0xa000c0c0, 0x8261a066, 0x834922e0},
18700 static const DWORD content_x8l8v8u8[4][4] =
18702 {0x00000000, 0x00ff7f7f, 0x00008880, 0x00ff0000},
18703 {0x00000080, 0x00008000, 0x00007f00, 0x0000007f},
18704 {0x0041193b, 0x0051e8c8, 0x00040808, 0x00fff8f8},
18705 {0x00824444, 0x0000c0c0, 0x00c2a066, 0x009222e0},
18707 /* D3DFMT_L6V5U5 has poor precision on some GPUs. On a GeForce 7 the highest V and U value (15)
18708 * results in the output color 0xfb, which is 4 steps away from the correct value 0xff. It is
18709 * not the ~0xf0 you'd get if you blindly left-shifted the 5 bit value to form an 8 bit value
18710 * though.
18712 * There may also be an off-by-one bug involved: The value -7 should result in the output 0x47,
18713 * but ends up as 0x4d. Likewise, -3 becomes 0x6e instead of 0x67. Those values are close to
18714 * the proper results of -6 and -2.
18716 * On Wine the emulation with unsigned R5G6B5 has poor precision, e.g. the signed 0 becomes 16,
18717 * and ((16 / 31) - 0.5) * 2.0 is 0.032 instead of 0.000. The final output result we read back
18718 * is 0x84 instead of 0x80. */
18719 static const USHORT content_l6v5u5[4][4] =
18721 {0x0000, 0xfdef, 0x0230, 0xfc00},
18722 {0x0010, 0x0200, 0x01e0, 0x000f},
18723 {0x4067, 0x53b9, 0x0421, 0xffff},
18724 {0x8108, 0x0318, 0xc28c, 0x909c},
18726 static const struct
18728 D3DFORMAT format;
18729 const char *name;
18730 const void *content;
18731 SIZE_T pixel_size;
18732 BOOL blue, alpha;
18733 unsigned int slop, slop_broken, alpha_broken;
18735 formats[] =
18737 {D3DFMT_V8U8, "D3DFMT_V8U8", content_v8u8, sizeof(WORD), FALSE, FALSE, 1, 0, FALSE},
18738 {D3DFMT_V16U16, "D3DFMT_V16U16", content_v16u16, sizeof(DWORD), FALSE, FALSE, 1, 0, FALSE},
18739 {D3DFMT_Q8W8V8U8, "D3DFMT_Q8W8V8U8", content_q8w8v8u8, sizeof(DWORD), TRUE, TRUE, 1, 0, TRUE },
18740 {D3DFMT_X8L8V8U8, "D3DFMT_X8L8V8U8", content_x8l8v8u8, sizeof(DWORD), TRUE, FALSE, 1, 0, FALSE},
18741 {D3DFMT_L6V5U5, "D3DFMT_L6V5U5", content_l6v5u5, sizeof(WORD), TRUE, FALSE, 4, 7, FALSE},
18743 static const struct
18745 D3DPOOL pool;
18746 UINT width;
18747 RECT src_rect;
18748 POINT dst_point;
18750 tests[] =
18752 {D3DPOOL_SYSTEMMEM, 4, {1, 1, 2, 3}, {2, 0}},
18753 {D3DPOOL_SYSTEMMEM, 1, {0, 1, 1, 3}, {0, 0}},
18754 {D3DPOOL_MANAGED, 4, {1, 1, 2, 3}, {2, 0}},
18755 {D3DPOOL_MANAGED, 1, {0, 1, 1, 3}, {0, 0}},
18757 static const DWORD shader_code[] =
18759 0xffff0101, /* ps_1_1 */
18760 0x00000051, 0xa00f0000, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, /* def c0, 0.5, 0.5, 0,5, 0,5 */
18761 0x00000042, 0xb00f0000, /* tex t0 */
18762 0x00000004, 0x800f0000, 0xb0e40000, 0xa0e40000, 0xa0e40000, /* mad r0, t0, c0, c0 */
18763 0x0000ffff /* end */
18765 static const DWORD shader_code_alpha[] =
18767 /* The idea of this shader is to replicate the alpha value in .rg, and set
18768 * blue to 1.0 iff the alpha value is < -1.0 and 0.0 otherwise. */
18769 0xffff0101, /* ps_1_1 */
18770 0x00000051, 0xa00f0000, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, /* def c0, 0.5, 0.5, 0.5, 0.5 */
18771 0x00000051, 0xa00f0001, 0x3f800000, 0x3f800000, 0x00000000, 0x3f800000, /* def c1, 1.0, 1.0, 0.0, 1.0 */
18772 0x00000051, 0xa00f0002, 0x00000000, 0x00000000, 0x3f800000, 0x00000000, /* def c2, 0.0, 0.0, 1.0, 0.0 */
18773 0x00000042, 0xb00f0000, /* tex t0 */
18774 0x00000004, 0x80070000, 0xb0ff0000, 0xa0e40000, 0xa0e40000, /* mad r0.rgb, t0.a, c0, c0 */
18775 0x00000003, 0x80080000, 0xb1ff0000, 0xa0e40000, /* sub r0.a, -t0.a, c0 */
18776 0x00000050, 0x80080000, 0x80ff0000, 0xa0ff0001, 0xa0ff0002, /* cnd r0.a, r0.a, c1.a, c2.a */
18777 0x00000005, 0x80070001, 0xa0e40001, 0x80e40000, /* mul r1.rgb, c1, r0 */
18778 0x00000004, 0x80070000, 0x80ff0000, 0xa0e40002, 0x80e40001, /* mad r0.rgb, r0.a, c2, r1 */
18779 0x0000ffff /* end */
18781 static const struct
18783 struct vec3 position;
18784 struct vec2 texcrd;
18786 quad[] =
18788 /* Flip the y coordinate to make the input and
18789 * output arrays easier to compare. */
18790 {{ -1.0f, -1.0f, 0.0f}, { 0.0f, 1.0f}},
18791 {{ -1.0f, 1.0f, 0.0f}, { 0.0f, 0.0f}},
18792 {{ 1.0f, -1.0f, 0.0f}, { 1.0f, 1.0f}},
18793 {{ 1.0f, 1.0f, 0.0f}, { 1.0f, 0.0f}},
18795 static const D3DCOLOR expected_alpha[4][4] =
18797 {0x00808000, 0x007f7f00, 0x00ffff00, 0x00000000},
18798 {0x00909000, 0x00a0a000, 0x00b0b000, 0x00c0c000},
18799 {0x00d0d000, 0x00e0e000, 0x00f0f000, 0x00000000},
18800 {0x00101000, 0x00202000, 0x00010100, 0x00020200},
18802 static const BOOL alpha_broken[4][4] =
18804 {FALSE, FALSE, FALSE, FALSE},
18805 {FALSE, FALSE, FALSE, FALSE},
18806 {FALSE, FALSE, FALSE, TRUE },
18807 {FALSE, FALSE, FALSE, FALSE},
18809 static const D3DCOLOR expected_colors[4][4] =
18811 {0x00808080, 0x00fefeff, 0x00010780, 0x008080ff},
18812 {0x00018080, 0x00800180, 0x0080fe80, 0x00fe8080},
18813 {0x00ba98a0, 0x004767a8, 0x00888881, 0x007878ff},
18814 {0x00c3c3c0, 0x003f3f80, 0x00e51fe1, 0x005fa2c8},
18816 static const D3DCOLOR expected_colors2[4][4] =
18818 {0x00808080, 0x00fefeff, 0x00800180, 0x008080ff},
18819 {0x00018080, 0x00800180, 0x004767a8, 0x00fe8080},
18820 {0x00ba98a0, 0x004767a8, 0x00888881, 0x007878ff},
18821 {0x00c3c3c0, 0x003f3f80, 0x00e51fe1, 0x005fa2c8},
18823 static const D3DCOLOR expected_colors3[4] =
18825 0x00018080,
18826 0x00ba98a0,
18827 0x00ba98a0,
18828 0x00c3c3c0,
18830 D3DCOLOR expected_color;
18832 window = create_window();
18833 d3d = Direct3DCreate9(D3D_SDK_VERSION);
18834 ok(!!d3d, "Failed to create a D3D object.\n");
18836 if (!(device = create_device(d3d, window, window, TRUE)))
18838 skip("Failed to create a D3D device, skipping tests.\n");
18839 IDirect3D9_Release(d3d);
18840 DestroyWindow(window);
18841 return;
18844 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
18845 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
18847 if (caps.PixelShaderVersion < D3DPS_VERSION(1, 1))
18849 skip("Pixel shaders not supported, skipping converted format test.\n");
18850 goto done;
18853 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
18854 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
18855 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
18856 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
18857 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code, &shader);
18858 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18859 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_alpha, &shader_alpha);
18860 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18862 for (i = 0; i < sizeof(formats) / sizeof(*formats); i++)
18864 hr = IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
18865 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, formats[i].format);
18866 if (FAILED(hr))
18868 skip("Format %s not supported, skipping.\n", formats[i].name);
18869 continue;
18872 for (j = 0; j < sizeof(tests) / sizeof(*tests); j++)
18874 texture_sysmem = NULL;
18875 hr = IDirect3DDevice9_CreateTexture(device, tests[j].width, 4, 1, 0,
18876 formats[i].format, tests[j].pool, &texture, NULL);
18877 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18879 hr = IDirect3DTexture9_LockRect(texture, 0, &locked_rect, NULL, 0);
18880 ok(SUCCEEDED(hr), "Failed to lock texture, hr %#x.\n", hr);
18881 for (y = 0; y < 4; y++)
18883 memcpy((char *)locked_rect.pBits + y * locked_rect.Pitch,
18884 (char *)formats[i].content + y * 4 * formats[i].pixel_size,
18885 tests[j].width * formats[i].pixel_size);
18887 hr = IDirect3DTexture9_UnlockRect(texture, 0);
18888 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr);
18890 if (tests[j].pool == D3DPOOL_SYSTEMMEM)
18892 texture_sysmem = texture;
18893 hr = IDirect3DDevice9_CreateTexture(device, tests[j].width, 4, 1, 0,
18894 formats[i].format, D3DPOOL_DEFAULT, &texture, NULL);
18895 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18897 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)texture_sysmem,
18898 (IDirect3DBaseTexture9 *)texture);
18899 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
18902 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
18903 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
18904 hr = IDirect3DDevice9_SetPixelShader(device, shader_alpha);
18905 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
18907 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00330033, 0.0f, 0);
18908 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
18909 hr = IDirect3DDevice9_BeginScene(device);
18910 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
18911 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], sizeof(*quad));
18912 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
18913 hr = IDirect3DDevice9_EndScene(device);
18914 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
18916 for (y = 0; y < 4; y++)
18918 for (x = 0; x < tests[j].width; x++)
18920 BOOL r200_broken = formats[i].alpha_broken && alpha_broken[y][x];
18921 if (formats[i].alpha)
18922 expected_color = expected_alpha[y][x];
18923 else
18924 expected_color = 0x00ffff00;
18926 color = getPixelColor(device, 80 + 160 * x, 60 + 120 * y);
18927 ok(color_match(color, expected_color, 1) || broken(r200_broken),
18928 "Expected color 0x%08x, got 0x%08x, format %s, location %ux%u.\n",
18929 expected_color, color, formats[i].name, x, y);
18932 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
18933 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
18935 hr = IDirect3DDevice9_SetPixelShader(device, shader);
18936 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
18938 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00330033, 0.0f, 0);
18939 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
18940 hr = IDirect3DDevice9_BeginScene(device);
18941 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
18942 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], sizeof(*quad));
18943 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
18944 hr = IDirect3DDevice9_EndScene(device);
18945 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
18947 for (y = 0; y < 4; y++)
18949 for (x = 0; x < tests[j].width; x++)
18951 expected_color = expected_colors[y][x];
18952 if (!formats[i].blue)
18953 expected_color |= 0x000000ff;
18955 color = getPixelColor(device, 80 + 160 * x, 60 + 120 * y);
18956 ok(color_match(color, expected_color, formats[i].slop)
18957 || broken(color_match(color, expected_color, formats[i].slop_broken)),
18958 "Expected color 0x%08x, got 0x%08x, format %s, location %ux%u.\n",
18959 expected_color, color, formats[i].name, x, y);
18962 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
18963 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
18965 if (tests[j].pool != D3DPOOL_SYSTEMMEM)
18967 IDirect3DTexture9_Release(texture);
18968 continue;
18971 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &dst_surface);
18972 ok(SUCCEEDED(hr), "Failed to get surface, hr %#x.\n", hr);
18973 IDirect3DTexture9_GetSurfaceLevel(texture_sysmem, 0, &src_surface);
18974 ok(SUCCEEDED(hr), "Failed to get surface, hr %#x.\n", hr);
18976 hr = IDirect3DDevice9_UpdateSurface(device, src_surface,
18977 &tests[j].src_rect, dst_surface, &tests[j].dst_point);
18978 ok(SUCCEEDED(hr), "Failed to update surface, hr %#x.\n", hr);
18980 IDirect3DSurface9_Release(dst_surface);
18981 IDirect3DSurface9_Release(src_surface);
18983 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00003300, 0.0f, 0);
18984 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
18985 hr = IDirect3DDevice9_BeginScene(device);
18986 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
18987 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], sizeof(*quad));
18988 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
18989 hr = IDirect3DDevice9_EndScene(device);
18990 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
18992 for (y = 0; y < 4; y++)
18994 for (x = 0; x < tests[j].width; x++)
18996 if (tests[j].width == 4)
18997 expected_color = expected_colors2[y][x];
18998 else
18999 expected_color = expected_colors3[y];
19001 if (!formats[i].blue)
19002 expected_color |= 0x000000ff;
19004 color = getPixelColor(device, 80 + 160 * x, 60 + 120 * y);
19005 ok(color_match(color, expected_color, formats[i].slop)
19006 || broken(color_match(color, expected_color, formats[i].slop_broken)),
19007 "Expected color 0x%08x, got 0x%08x, format %s, location %ux%u.\n",
19008 expected_color, color, formats[i].name, x, y);
19011 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
19012 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
19014 IDirect3DTexture9_Release(texture_sysmem);
19015 IDirect3DTexture9_Release(texture);
19019 IDirect3DPixelShader9_Release(shader);
19020 IDirect3DPixelShader9_Release(shader_alpha);
19022 done:
19023 refcount = IDirect3DDevice9_Release(device);
19024 ok(!refcount, "Device has %u references left.\n", refcount);
19025 IDirect3D9_Release(d3d);
19026 DestroyWindow(window);
19029 static void test_multisample_mismatch(void)
19031 IDirect3DDevice9 *device;
19032 IDirect3D9 *d3d;
19033 HWND window;
19034 HRESULT hr;
19035 D3DCOLOR color;
19036 ULONG refcount;
19037 IDirect3DSurface9 *rt, *rt_multi, *ds;
19038 static const struct
19040 struct vec3 position;
19041 DWORD color;
19043 quad[] =
19045 {{ -1.0f, -1.0f, 0.0f}, 0x000000ff},
19046 {{ -1.0f, 1.0f, 0.0f}, 0x000000ff},
19047 {{ 1.0f, -1.0f, 1.0f}, 0x000000ff},
19048 {{ 1.0f, 1.0f, 1.0f}, 0x000000ff},
19051 window = create_window();
19052 d3d = Direct3DCreate9(D3D_SDK_VERSION);
19053 ok(!!d3d, "Failed to create a D3D object.\n");
19054 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
19055 D3DFMT_A8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES, NULL)))
19057 skip("Multisampling not supported for D3DFMT_A8R8G8B8, skipping multisample mismatch test.\n");
19058 IDirect3D9_Release(d3d);
19059 return;
19061 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
19062 D3DFMT_D24X8, TRUE, D3DMULTISAMPLE_2_SAMPLES, NULL)))
19064 skip("Multisampling not supported for D3DFMT_D24X8, skipping multisample mismatch test.\n");
19065 IDirect3D9_Release(d3d);
19066 return;
19069 if (!(device = create_device(d3d, window, window, TRUE)))
19071 skip("Failed to create a D3D device, skipping tests.\n");
19072 IDirect3D9_Release(d3d);
19073 DestroyWindow(window);
19074 return;
19077 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
19078 D3DMULTISAMPLE_2_SAMPLES, 0, FALSE, &rt_multi, NULL);
19079 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
19081 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0x00000000, 0.1f, 0);
19082 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
19084 hr = IDirect3DDevice9_GetDepthStencilSurface(device, &ds);
19085 ok(SUCCEEDED(hr), "Failed to set depth stencil, hr %#x.\n", hr);
19086 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &rt);
19087 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
19088 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt_multi);
19089 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
19091 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
19092 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
19093 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
19094 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
19096 /* Clear with incompatible buffers. Partial and combined clears. */
19097 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00ff0000, 0.0f, 0);
19098 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
19099 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0x00000000, 0.3f, 0);
19100 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
19101 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x0000ff00, 0.5f, 0);
19102 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
19104 /* The color buffer is reliably cleared on AMD and Nvidia GPUs. */
19105 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
19106 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
19107 hr = IDirect3DDevice9_StretchRect(device, rt_multi, NULL, rt, NULL, D3DTEXF_POINT);
19108 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
19109 color = getPixelColor(device, 320, 240);
19110 ok(color_match(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
19111 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
19112 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
19114 /* Check depth buffer values. AMD GPUs (r500 and evergreen tested) clear the depth buffer
19115 * like you'd expect in a correct framebuffer setup. Nvidia doesn't clear it, neither in
19116 * the Z only clear case nor in the combined clear case. */
19117 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
19118 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
19119 hr = IDirect3DDevice9_BeginScene(device);
19120 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
19121 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
19122 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
19123 hr = IDirect3DDevice9_EndScene(device);
19124 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
19125 color = getPixelColor(device, 62, 240);
19126 ok(color_match(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
19127 color = getPixelColor(device, 64, 240);
19128 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x000000ff, 1)),
19129 "Got unexpected color 0x%08x.\n", color);
19130 color = getPixelColor(device, 318, 240);
19131 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x000000ff, 1)),
19132 "Got unexpected color 0x%08x.\n", color);
19133 color = getPixelColor(device, 322, 240);
19134 ok(color_match(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
19135 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
19136 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
19138 /* Draw with incompatible buffers. AMD even performs Z testing, and the Z test
19139 * results appear to be correct for this simple draw. Nvidia doesn't draw unless
19140 * the depth test is disabled. Setting ZFUNC = ALWAYS doesn't make the geometry
19141 * show up either. Only test the ZENABLE = FALSE case for now. */
19142 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
19143 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
19144 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt_multi);
19145 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
19146 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00ff0000, 0.0f, 0);
19147 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
19148 hr = IDirect3DDevice9_BeginScene(device);
19149 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
19150 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
19151 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
19152 hr = IDirect3DDevice9_EndScene(device);
19153 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
19155 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
19156 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
19157 hr = IDirect3DDevice9_StretchRect(device, rt_multi, NULL, rt, NULL, D3DTEXF_POINT);
19158 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
19159 color = getPixelColor(device, 320, 240);
19160 ok(color_match(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
19161 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
19162 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
19164 IDirect3DSurface9_Release(ds);
19166 /* Test the reverse situation: Multisampled depth buffer, single sampled color buffer.
19167 * Color clears work as expected, AMD also clears the depth buffer, Nvidia does not. */
19168 hr = IDirect3DDevice9_CreateDepthStencilSurface(device, 640, 480, D3DFMT_D24X8,
19169 D3DMULTISAMPLE_2_SAMPLES, 0, FALSE, &ds, NULL);
19170 ok(SUCCEEDED(hr), "Failed to create depth/stencil, hr %#x.\n", hr);
19171 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
19172 ok(SUCCEEDED(hr), "Failed to set depth stencil surface, hr %#x.\n", hr);
19173 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt_multi);
19174 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
19175 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ffff00, 0.1f, 0);
19176 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
19178 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
19179 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
19180 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00ff0000, 0.0f, 0);
19181 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
19182 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0x00000000, 0.3f, 0);
19183 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
19184 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x0000ff00, 0.5f, 0);
19185 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
19187 color = getPixelColor(device, 320, 240);
19188 ok(color_match(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
19189 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
19190 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
19192 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt_multi);
19193 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
19194 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
19195 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
19196 hr = IDirect3DDevice9_BeginScene(device);
19197 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
19198 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
19199 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
19200 hr = IDirect3DDevice9_EndScene(device);
19201 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
19203 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
19204 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
19205 hr = IDirect3DDevice9_StretchRect(device, rt_multi, NULL, rt, NULL, D3DTEXF_POINT);
19206 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
19207 color = getPixelColor(device, 62, 240);
19208 ok(color_match(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
19209 color = getPixelColor(device, 318, 240);
19210 ok(color_match(color, 0x00ffff00, 1) || broken(color_match(color, 0x000000ff, 1)),
19211 "Got unexpected color 0x%08x.\n", color);
19212 color = getPixelColor(device, 322, 240);
19213 ok(color_match(color, 0x00ffff00, 1), "Got unexpected color 0x%08x.\n", color);
19214 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
19215 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
19217 /* Draw with a single sampled color buffer and a multisampled depth buffer. Again
19218 * AMD seems to perform correct Z testing, Nvidia doesn't draw unless the Z test
19219 * is disabled. Again only test the ZENABLE = FALSE case. */
19220 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00ff0000, 0.0f, 0);
19221 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
19222 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
19223 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
19224 hr = IDirect3DDevice9_BeginScene(device);
19225 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
19226 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
19227 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
19228 hr = IDirect3DDevice9_EndScene(device);
19229 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
19230 color = getPixelColor(device, 320, 240);
19231 ok(color_match(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
19232 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
19233 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
19235 IDirect3DSurface9_Release(rt);
19236 IDirect3DSurface9_Release(ds);
19237 IDirect3DSurface9_Release(rt_multi);
19239 refcount = IDirect3DDevice9_Release(device);
19240 ok(!refcount, "Device has %u references left.\n", refcount);
19241 IDirect3D9_Release(d3d);
19242 DestroyWindow(window);
19245 static void test_texcoordindex(void)
19247 static const D3DMATRIX mat =
19249 1.0f, 0.0f, 0.0f, 0.0f,
19250 0.0f, 0.0f, 0.0f, 0.0f,
19251 0.0f, 0.0f, 0.0f, 0.0f,
19252 0.0f, 0.0f, 0.0f, 0.0f,
19253 }}};
19254 static const struct
19256 struct vec3 pos;
19257 struct vec2 texcoord1;
19258 struct vec2 texcoord2;
19259 struct vec2 texcoord3;
19261 quad[] =
19263 {{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}, {0.0f, 0.0f}, {1.0f, 1.0f}},
19264 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 0.0f}},
19265 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}, {1.0f, 0.0f}, {0.0f, 1.0f}},
19266 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 0.0f}},
19268 IDirect3DDevice9 *device;
19269 IDirect3D9 *d3d9;
19270 HWND window;
19271 HRESULT hr;
19272 IDirect3DTexture9 *texture1, *texture2;
19273 D3DLOCKED_RECT locked_rect;
19274 ULONG refcount;
19275 D3DCOLOR color;
19276 DWORD *ptr;
19278 window = create_window();
19279 d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
19280 ok(!!d3d9, "Failed to create a D3D object.\n");
19281 if (!(device = create_device(d3d9, window, window, TRUE)))
19283 skip("Failed to create a D3D device, skipping tests.\n");
19284 IDirect3D9_Release(d3d9);
19285 DestroyWindow(window);
19286 return;
19289 hr = IDirect3DDevice9_CreateTexture(device, 2, 2, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture1, NULL);
19290 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19291 hr = IDirect3DDevice9_CreateTexture(device, 2, 2, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture2, NULL);
19292 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19294 hr = IDirect3DTexture9_LockRect(texture1, 0, &locked_rect, NULL, D3DLOCK_DISCARD);
19295 ok(SUCCEEDED(hr), "Failed to lock texture, hr %#x.\n", hr);
19296 ptr = locked_rect.pBits;
19297 ptr[0] = 0xff000000;
19298 ptr[1] = 0xff00ff00;
19299 ptr[2] = 0xff0000ff;
19300 ptr[3] = 0xff00ffff;
19301 hr = IDirect3DTexture9_UnlockRect(texture1, 0);
19302 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr);
19304 hr = IDirect3DTexture9_LockRect(texture2, 0, &locked_rect, NULL, D3DLOCK_DISCARD);
19305 ok(SUCCEEDED(hr), "Failed to lock texture, hr %#x.\n", hr);
19306 ptr = locked_rect.pBits;
19307 ptr[0] = 0xff000000;
19308 ptr[1] = 0xff0000ff;
19309 ptr[2] = 0xffff0000;
19310 ptr[3] = 0xffff00ff;
19311 hr = IDirect3DTexture9_UnlockRect(texture2, 0);
19312 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr);
19314 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture1);
19315 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
19316 hr = IDirect3DDevice9_SetTexture(device, 1, (IDirect3DBaseTexture9 *)texture2);
19317 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
19318 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX3);
19319 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
19320 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
19321 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
19322 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
19323 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
19324 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
19325 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
19326 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_ADD);
19327 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
19328 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
19329 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
19330 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_CURRENT);
19331 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
19332 hr = IDirect3DDevice9_SetTextureStageState(device, 2, D3DTSS_COLOROP, D3DTOP_DISABLE);
19333 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
19335 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXCOORDINDEX, 1);
19336 ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#x.\n", hr);
19337 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_TEXCOORDINDEX, 0);
19338 ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#x.\n", hr);
19340 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 1.0f, 0);
19341 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
19343 hr = IDirect3DDevice9_BeginScene(device);
19344 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
19345 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
19346 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
19347 hr = IDirect3DDevice9_EndScene(device);
19348 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
19350 color = getPixelColor(device, 160, 120);
19351 ok(color_match(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
19352 color = getPixelColor(device, 480, 120);
19353 ok(color_match(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
19354 color = getPixelColor(device, 160, 360);
19355 ok(color_match(color, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color);
19356 color = getPixelColor(device, 480, 360);
19357 ok(color_match(color, 0x00ffffff, 2), "Got unexpected color 0x%08x.\n", color);
19359 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
19360 ok(SUCCEEDED(hr), "Failed to set texture transform flags, hr %#x.\n", hr);
19361 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE1, &mat);
19362 ok(SUCCEEDED(hr), "Failed to set transformation matrix, hr %#x.\n", hr);
19364 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 1.0f, 0);
19365 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
19367 hr = IDirect3DDevice9_BeginScene(device);
19368 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
19369 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
19370 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
19371 hr = IDirect3DDevice9_EndScene(device);
19372 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
19374 color = getPixelColor(device, 160, 120);
19375 ok(color_match(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
19376 color = getPixelColor(device, 480, 120);
19377 ok(color_match(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
19378 color = getPixelColor(device, 160, 360);
19379 ok(color_match(color, 0x00000000, 2), "Got unexpected color 0x%08x.\n", color);
19380 color = getPixelColor(device, 480, 360);
19381 ok(color_match(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
19383 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
19384 ok(SUCCEEDED(hr), "Failed to set texture transform flags, hr %#x.\n", hr);
19385 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_TEXCOORDINDEX, 2);
19386 ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#x.\n", hr);
19388 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 1.0f, 0);
19389 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
19391 hr = IDirect3DDevice9_BeginScene(device);
19392 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
19393 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
19394 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
19395 hr = IDirect3DDevice9_EndScene(device);
19396 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
19398 color = getPixelColor(device, 160, 120);
19399 ok(color_match(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
19400 color = getPixelColor(device, 480, 120);
19401 ok(color_match(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
19402 color = getPixelColor(device, 160, 360);
19403 ok(color_match(color, 0x00ff00ff, 2), "Got unexpected color 0x%08x.\n", color);
19404 color = getPixelColor(device, 480, 360);
19405 ok(color_match(color, 0x00ffff00, 2), "Got unexpected color 0x%08x.\n", color);
19407 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
19408 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
19410 IDirect3DTexture9_Release(texture1);
19411 IDirect3DTexture9_Release(texture2);
19413 refcount = IDirect3DDevice9_Release(device);
19414 ok(!refcount, "Device has %u references left.\n", refcount);
19415 IDirect3D9_Release(d3d9);
19416 DestroyWindow(window);
19419 static void test_vertex_blending(void)
19421 IDirect3DVertexDeclaration9 *vertex_declaration;
19422 IDirect3DDevice9 *device;
19423 IDirect3D9 *d3d;
19424 D3DCAPS9 caps;
19425 D3DCOLOR color;
19426 ULONG refcount;
19427 HWND window;
19428 HRESULT hr;
19429 int i;
19431 static const D3DMATRIX view_mat =
19433 2.0f / 10.0f, 0.0f, 0.0f, 0.0f,
19434 0.0f, 2.0f / 10.0f, 0.0f, 0.0f,
19435 0.0f, 0.0f, 1.0f, 0.0f,
19436 0.0f, 0.0f, 0.0f, 1.0f
19437 }}},
19438 upper_left =
19440 1.0f, 0.0f, 0.0f, 0.0f,
19441 0.0f, 1.0f, 0.0f, 0.0f,
19442 0.0f, 0.0f, 1.0f, 0.0f,
19443 -4.0f, 4.0f, 0.0f, 1.0f
19444 }}},
19445 lower_left =
19447 1.0f, 0.0f, 0.0f, 0.0f,
19448 0.0f, 1.0f, 0.0f, 0.0f,
19449 0.0f, 0.0f, 1.0f, 0.0f,
19450 -4.0f, -4.0f, 0.0f, 1.0f
19451 }}},
19452 upper_right =
19454 1.0f, 0.0f, 0.0f, 0.0f,
19455 0.0f, 1.0f, 0.0f, 0.0f,
19456 0.0f, 0.0f, 1.0f, 0.0f,
19457 4.0f, 4.0f, 0.0f, 1.0f
19458 }}},
19459 lower_right =
19461 1.0f, 0.0f, 0.0f, 0.0f,
19462 0.0f, 1.0f, 0.0f, 0.0f,
19463 0.0f, 0.0f, 1.0f, 0.0f,
19464 4.0f, -4.0f, 0.0f, 1.0f
19465 }}};
19467 static const POINT quad_upper_right_points[] =
19469 {576, 48}, {-1, -1},
19471 quad_upper_right_empty_points[] =
19473 {64, 48}, {64, 432}, {576, 432}, {320, 240}, {-1, -1}
19475 quad_center_points[] =
19477 {320, 240}, {-1, -1}
19479 quad_center_empty_points[] =
19481 {64, 48}, {576, 48}, {64, 432}, {576, 432}, {-1, -1}
19483 quad_upper_center_points[] =
19485 {320, 48}, {-1, -1}
19487 quad_upper_center_empty_points[] =
19489 {320, 240}, {64, 48}, {576, 48}, {-1, -1}
19491 quad_fullscreen_points[] =
19493 {320, 48}, {320, 240}, {64, 48}, {576, 48}, {64, 432}, {576, 432}, {-1, -1}
19495 quad_fullscreen_empty_points[] =
19497 {-1, -1}
19500 static const struct
19502 DWORD fvf;
19503 D3DVERTEXELEMENT9 decl_elements[3];
19504 struct
19506 struct
19508 struct vec3 position;
19509 struct vec3 blendweights;
19511 vertex_data_float[4];
19512 struct
19514 struct vec3 position;
19515 D3DCOLOR blendweights;
19517 vertex_data_d3dcolor[4];
19518 } s;
19519 const POINT *quad_points;
19520 const POINT *empty_points;
19522 tests[] =
19524 /* upper right */
19526 D3DFVF_XYZB3,
19527 {{0}},
19528 {{{{-1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, 0.0f}},
19529 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0f}},
19530 {{ 1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, 0.0f}},
19531 {{ 1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0f}}}},
19532 quad_upper_right_points, quad_upper_right_empty_points
19534 /* center */
19536 D3DFVF_XYZB3,
19537 {{0}},
19538 {{{{-1.0f, -1.0f, 0.0f}, {0.25f, 0.25f, 0.25f}},
19539 {{-1.0f, 1.0f, 0.0f}, {0.25f, 0.25f, 0.25f}},
19540 {{ 1.0f, -1.0f, 0.0f}, {0.25f, 0.25f, 0.25f}},
19541 {{ 1.0f, 1.0f, 0.0f}, {0.25f, 0.25f, 0.25f}}}},
19542 quad_center_points, quad_center_empty_points
19544 /* upper center */
19546 D3DFVF_XYZB3,
19547 {{0}},
19548 {{{{-1.0f, -1.0f, 0.0f}, {0.5f, 0.0f, 0.0f}},
19549 {{-1.0f, 1.0f, 0.0f}, {0.5f, 0.0f, 0.0f}},
19550 {{ 1.0f, -1.0f, 0.0f}, {0.5f, 0.0f, 0.0f}},
19551 {{ 1.0f, 1.0f, 0.0f}, {0.5f, 0.0f, 0.0f}}}},
19552 quad_upper_center_points, quad_upper_center_empty_points
19554 /* full screen */
19556 D3DFVF_XYZB3,
19557 {{0}},
19558 {{{{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f, 0.0f}},
19559 {{-1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}},
19560 {{ 1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}},
19561 {{ 1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0f}}}},
19562 quad_fullscreen_points, quad_fullscreen_empty_points
19564 /* D3DCOLOR, full screen */
19568 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
19569 {0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0},
19570 D3DDECL_END()
19572 {{{{0}}},
19573 {{{-1.0f, -1.0f, 0.0f}, 0x0000ff00},
19574 {{-1.0f, 1.0f, 0.0f}, 0x00ff0000},
19575 {{ 1.0f, -1.0f, 0.0f}, 0x000000ff},
19576 {{ 1.0f, 1.0f, 0.0f}, 0x00000000}}},
19577 quad_fullscreen_points, quad_fullscreen_empty_points
19581 window = create_window();
19582 d3d = Direct3DCreate9(D3D_SDK_VERSION);
19583 ok(!!d3d, "Failed to create a D3D object.\n");
19584 if (!(device = create_device(d3d, window, window, TRUE)))
19586 skip("Failed to create a D3D device, skipping tests.\n");
19587 goto done;
19590 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
19591 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
19592 if (caps.MaxVertexBlendMatrices < 4)
19594 skip("Only %u vertex blend matrices supported, skipping tests.\n", caps.MaxVertexBlendMatrices);
19595 IDirect3DDevice9_Release(device);
19596 goto done;
19599 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
19600 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
19602 hr = IDirect3DDevice9_SetTransform(device, D3DTS_VIEW, &view_mat);
19603 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform returned %08x\n", hr);
19605 hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLDMATRIX(0), &upper_left);
19606 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform returned %08x\n", hr);
19607 hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLDMATRIX(1), &lower_left);
19608 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform returned %08x\n", hr);
19609 hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLDMATRIX(2), &lower_right);
19610 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform returned %08x\n", hr);
19611 hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLDMATRIX(3), &upper_right);
19612 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform returned %08x\n", hr);
19614 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_VERTEXBLEND, D3DVBF_3WEIGHTS);
19615 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed %08x\n", hr);
19617 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
19619 const POINT *point;
19621 if (tests[i].fvf)
19623 hr = IDirect3DDevice9_SetFVF(device, tests[i].fvf);
19624 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
19625 vertex_declaration = NULL;
19627 else
19629 hr = IDirect3DDevice9_CreateVertexDeclaration(device, tests[i].decl_elements, &vertex_declaration);
19630 ok(SUCCEEDED(hr), "Failed to create vertex declaration, hr %#x.\n", hr);
19631 hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration);
19632 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
19635 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff000000, 0.0, 0);
19636 ok(SUCCEEDED(hr), "Failed to clear %08x\n", hr);
19638 hr = IDirect3DDevice9_BeginScene(device);
19639 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
19641 if (tests[i].fvf)
19642 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2,
19643 tests[i].s.vertex_data_float, sizeof(*tests[i].s.vertex_data_float));
19644 else
19645 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2,
19646 tests[i].s.vertex_data_d3dcolor, sizeof(*tests[i].s.vertex_data_d3dcolor));
19647 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
19649 hr = IDirect3DDevice9_EndScene(device);
19650 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
19652 point = tests[i].quad_points;
19653 while (point->x != -1 && point->y != -1)
19655 color = getPixelColor(device, point->x, point->y);
19656 ok(color_match(color, 0x00ffffff, 1), "Expected quad at %dx%d.\n", point->x, point->y);
19657 ++point;
19660 point = tests[i].empty_points;
19661 while (point->x != -1 && point->y != -1)
19663 color = getPixelColor(device, point->x, point->y);
19664 ok(color_match(color, 0x00000000, 1), "Unexpected quad at %dx%d.\n", point->x, point->y);
19665 ++point;
19668 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
19669 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
19671 if (vertex_declaration)
19672 IDirect3DVertexDeclaration9_Release(vertex_declaration);
19675 refcount = IDirect3DDevice9_Release(device);
19676 ok(!refcount, "Device has %u references left.\n", refcount);
19678 done:
19679 IDirect3D9_Release(d3d);
19680 DestroyWindow(window);
19683 static void test_updatetexture(void)
19685 BOOL r32f_supported, ati2n_supported, do_visual_test;
19686 IDirect3DBaseTexture9 *src, *dst;
19687 unsigned int t, i, f, l, x, y, z;
19688 D3DLOCKED_RECT locked_rect;
19689 D3DLOCKED_BOX locked_box;
19690 IDirect3DDevice9 *device;
19691 IDirect3D9 *d3d9;
19692 ULONG refcount;
19693 D3DCOLOR color;
19694 D3DCAPS9 caps;
19695 HWND window;
19696 HRESULT hr;
19697 static const struct
19699 struct vec3 pos;
19700 struct vec2 texcoord;
19702 quad[] =
19704 {{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}},
19705 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
19706 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}},
19707 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
19709 static const struct
19711 struct vec3 pos;
19712 struct vec3 texcoord;
19714 quad_cube_tex[] =
19716 {{-1.0f, -1.0f, 0.0f}, {1.0f, -0.5f, 0.5f}},
19717 {{-1.0f, 1.0f, 0.0f}, {1.0f, 0.5f, 0.5f}},
19718 {{ 1.0f, -1.0f, 0.0f}, {1.0f, -0.5f, -0.5f}},
19719 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.5f, -0.5f}},
19721 static const struct
19723 UINT src_width, src_height;
19724 UINT dst_width, dst_height;
19725 UINT src_levels, dst_levels;
19726 D3DFORMAT src_format, dst_format;
19727 BOOL broken;
19729 tests[] =
19731 {8, 8, 8, 8, 0, 0, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, FALSE}, /* 0 */
19732 {8, 8, 8, 8, 4, 4, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, FALSE}, /* 1 */
19733 {8, 8, 8, 8, 2, 2, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, FALSE}, /* 2 */
19734 {8, 8, 8, 8, 1, 1, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, FALSE}, /* 3 */
19735 {8, 8, 8, 8, 4, 0, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, FALSE}, /* 4 */
19736 {8, 8, 2, 2, 4, 2, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, FALSE}, /* 5 */
19737 /* The WARP renderer doesn't handle these cases correctly. */
19738 {8, 8, 8, 8, 4, 2, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, TRUE}, /* 6 */
19739 {8, 8, 4, 4, 4, 2, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, TRUE}, /* 7 */
19740 /* Not clear what happens here on Windows, it doesn't make much sense
19741 * though (on Nvidia it seems to upload the 4x4 surface into the 7x7
19742 * one or something like that). */
19743 /* {8, 8, 7, 7, 4, 2, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, FALSE}, */
19744 {8, 8, 8, 8, 1, 4, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, FALSE}, /* 8 */
19745 {4, 4, 8, 8, 1, 1, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, FALSE}, /* 9 */
19746 /* This one causes weird behavior on Windows (it probably writes out
19747 * of the texture memory). */
19748 /* {8, 8, 4, 4, 1, 1, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, FALSE}, */
19749 {8, 4, 4, 2, 4, 2, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, FALSE}, /* 10 */
19750 {8, 4, 2, 4, 4, 2, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, FALSE}, /* 11 */
19751 {8, 8, 8, 8, 4, 4, D3DFMT_A8R8G8B8, D3DFMT_X8R8G8B8, FALSE}, /* 12 */
19752 {8, 8, 8, 8, 4, 4, D3DFMT_X8R8G8B8, D3DFMT_A8R8G8B8, FALSE}, /* 13 */
19753 /* The data is converted correctly on AMD, on Nvidia nothing happens
19754 * (it draws a black quad). */
19755 {8, 8, 8, 8, 4, 4, D3DFMT_A8R8G8B8, D3DFMT_R5G6B5, TRUE}, /* 14 */
19756 /* Here the data is converted on AMD, just copied and "reinterpreted" as
19757 * a 32 bit float on Nvidia (specifically the tested value becomes a
19758 * very small float number which we get as 0 in the test). */
19759 {8, 8, 8, 8, 4, 4, D3DFMT_A8R8G8B8, D3DFMT_R32F, TRUE}, /* 15 */
19760 /* This one doesn't seem to give the expected results on AMD. */
19761 /* {8, 8, 8, 8, 4, 4, D3DFMT_A8R8G8B8, D3DFMT_Q8W8V8U8, FALSE}, */
19762 {8, 8, 8, 8, 4, 4, MAKEFOURCC('A','T','I','2'), MAKEFOURCC('A','T','I','2'), FALSE}, /* 16 */
19763 {8, 8, 8, 8, 4, 2, MAKEFOURCC('A','T','I','2'), MAKEFOURCC('A','T','I','2'), FALSE}, /* 17 */
19764 {8, 8, 2, 2, 4, 2, MAKEFOURCC('A','T','I','2'), MAKEFOURCC('A','T','I','2'), FALSE}, /* 18 */
19766 static const struct
19768 D3DRESOURCETYPE type;
19769 DWORD fvf;
19770 const void *quad;
19771 unsigned int vertex_size;
19772 DWORD cap;
19773 const char *name;
19775 texture_types[] =
19777 {D3DRTYPE_TEXTURE, D3DFVF_XYZ | D3DFVF_TEX1,
19778 quad, sizeof(*quad), D3DPTEXTURECAPS_MIPMAP, "2D mipmapped"},
19780 {D3DRTYPE_CUBETEXTURE, D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE3(0),
19781 quad_cube_tex, sizeof(*quad_cube_tex), D3DPTEXTURECAPS_CUBEMAP, "Cube"},
19783 {D3DRTYPE_VOLUMETEXTURE, D3DFVF_XYZ | D3DFVF_TEX1,
19784 quad, sizeof(*quad), D3DPTEXTURECAPS_VOLUMEMAP, "Volume"}
19787 window = create_window();
19788 d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
19789 ok(!!d3d9, "Failed to create a D3D object.\n");
19790 if (!(device = create_device(d3d9, window, window, TRUE)))
19792 skip("Failed to create a D3D device, skipping tests.\n");
19793 IDirect3D9_Release(d3d9);
19794 DestroyWindow(window);
19795 return;
19798 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
19799 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
19801 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
19802 ok(SUCCEEDED(hr), "Failed to set texture filtering state, hr %#x.\n", hr);
19803 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
19804 ok(SUCCEEDED(hr), "Failed to set texture clamping state, hr %#x.\n", hr);
19805 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
19806 ok(SUCCEEDED(hr), "Failed to set texture clamping state, hr %#x.\n", hr);
19807 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSW, D3DTADDRESS_CLAMP);
19808 ok(SUCCEEDED(hr), "Failed to set texture clamping state, hr %#x.\n", hr);
19809 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
19810 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
19811 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
19812 ok(hr == D3D_OK, "Failed to set texture stage state, hr %#x.\n", hr);
19813 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
19814 ok(hr == D3D_OK, "Failed to set texture stage state, hr %#x.\n", hr);
19816 for (t = 0; t < sizeof(texture_types) / sizeof(*texture_types); ++t)
19818 if (!(caps.TextureCaps & texture_types[t].cap))
19820 skip("%s textures not supported, skipping some tests.\n", texture_types[t].name);
19821 continue;
19823 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
19824 D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_FILTER, texture_types[t].type, D3DFMT_A8R8G8B8)))
19826 skip("%s D3DFMT_A8R8G8B8 texture filtering is not supported, skipping some tests.\n",
19827 texture_types[t].name);
19828 continue;
19830 r32f_supported = TRUE;
19831 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
19832 D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_FILTER, texture_types[t].type, D3DFMT_R32F)))
19834 skip("%s R32F textures are not supported, skipping some tests.\n", texture_types[t].name);
19835 r32f_supported = FALSE;
19837 ati2n_supported = TRUE;
19838 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
19839 D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_FILTER, texture_types[t].type, MAKEFOURCC('A','T','I','2'))))
19841 skip("%s ATI2N textures are not supported, skipping some tests.\n", texture_types[t].name);
19842 ati2n_supported = FALSE;
19845 hr = IDirect3DDevice9_SetFVF(device, texture_types[t].fvf);
19846 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
19848 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
19850 if (tests[i].dst_format == D3DFMT_R32F && !r32f_supported)
19851 continue;
19852 if (tests[i].dst_format == MAKEFOURCC('A','T','I','2') && !ati2n_supported)
19853 continue;
19855 switch (texture_types[t].type)
19857 case D3DRTYPE_TEXTURE:
19858 hr = IDirect3DDevice9_CreateTexture(device,
19859 tests[i].src_width, tests[i].src_height,
19860 tests[i].src_levels, 0, tests[i].src_format, D3DPOOL_SYSTEMMEM,
19861 (IDirect3DTexture9 **)&src, NULL);
19862 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x, case %u, %u.\n", hr, t, i);
19863 hr = IDirect3DDevice9_CreateTexture(device,
19864 tests[i].dst_width, tests[i].dst_height,
19865 tests[i].dst_levels, 0, tests[i].dst_format, D3DPOOL_DEFAULT,
19866 (IDirect3DTexture9 **)&dst, NULL);
19867 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x, case %u, %u.\n", hr, t, i);
19868 break;
19869 case D3DRTYPE_CUBETEXTURE:
19870 hr = IDirect3DDevice9_CreateCubeTexture(device,
19871 tests[i].src_width,
19872 tests[i].src_levels, 0, tests[i].src_format, D3DPOOL_SYSTEMMEM,
19873 (IDirect3DCubeTexture9 **)&src, NULL);
19874 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x, case %u, %u.\n", hr, t, i);
19875 hr = IDirect3DDevice9_CreateCubeTexture(device,
19876 tests[i].dst_width,
19877 tests[i].dst_levels, 0, tests[i].dst_format, D3DPOOL_DEFAULT,
19878 (IDirect3DCubeTexture9 **)&dst, NULL);
19879 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x, case %u, %u.\n", hr, t, i);
19880 break;
19881 case D3DRTYPE_VOLUMETEXTURE:
19882 hr = IDirect3DDevice9_CreateVolumeTexture(device,
19883 tests[i].src_width, tests[i].src_height, tests[i].src_width,
19884 tests[i].src_levels, 0, tests[i].src_format, D3DPOOL_SYSTEMMEM,
19885 (IDirect3DVolumeTexture9 **)&src, NULL);
19886 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x, case %u, %u.\n", hr, t, i);
19887 hr = IDirect3DDevice9_CreateVolumeTexture(device,
19888 tests[i].dst_width, tests[i].dst_height, tests[i].dst_width,
19889 tests[i].dst_levels, 0, tests[i].dst_format, D3DPOOL_DEFAULT,
19890 (IDirect3DVolumeTexture9 **)&dst, NULL);
19891 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x, case %u, %u.\n", hr, t, i);
19892 break;
19893 default:
19894 trace("Unexpected resource type.\n");
19897 /* Skip the visual part of the test for ATI2N (laziness) and cases that
19898 * give a different (and unlikely to be useful) result. */
19899 do_visual_test = (tests[i].src_format == D3DFMT_A8R8G8B8 || tests[i].src_format == D3DFMT_X8R8G8B8)
19900 && tests[i].src_levels != 0
19901 && tests[i].src_width >= tests[i].dst_width && tests[i].src_height >= tests[i].dst_height
19902 && !(tests[i].src_width > tests[i].src_height && tests[i].dst_width < tests[i].dst_height);
19904 if (do_visual_test)
19906 DWORD *ptr = NULL;
19907 unsigned int width, height, depth, row_pitch = 0, slice_pitch = 0;
19909 for (f = 0; f < (texture_types[t].type == D3DRTYPE_CUBETEXTURE ? 6 : 1); ++f)
19911 width = tests[i].src_width;
19912 height = texture_types[t].type != D3DRTYPE_CUBETEXTURE ? tests[i].src_height : tests[i].src_width;
19913 depth = texture_types[t].type == D3DRTYPE_VOLUMETEXTURE ? width : 1;
19915 for (l = 0; l < tests[i].src_levels; ++l)
19917 switch (texture_types[t].type)
19919 case D3DRTYPE_TEXTURE:
19920 hr = IDirect3DTexture9_LockRect((IDirect3DTexture9 *)src,
19921 l, &locked_rect, NULL, 0);
19922 ptr = locked_rect.pBits;
19923 row_pitch = locked_rect.Pitch / sizeof(*ptr);
19924 break;
19925 case D3DRTYPE_CUBETEXTURE:
19926 hr = IDirect3DCubeTexture9_LockRect((IDirect3DCubeTexture9 *)src,
19927 f, l, &locked_rect, NULL, 0);
19928 ptr = locked_rect.pBits;
19929 row_pitch = locked_rect.Pitch / sizeof(*ptr);
19930 break;
19931 case D3DRTYPE_VOLUMETEXTURE:
19932 hr = IDirect3DVolumeTexture9_LockBox((IDirect3DVolumeTexture9 *)src,
19933 l, &locked_box, NULL, 0);
19934 ptr = locked_box.pBits;
19935 row_pitch = locked_box.RowPitch / sizeof(*ptr);
19936 slice_pitch = locked_box.SlicePitch / sizeof(*ptr);
19937 break;
19938 default:
19939 trace("Unexpected resource type.\n");
19941 ok(SUCCEEDED(hr), "Failed to lock texture, hr %#x.\n", hr);
19943 for (z = 0; z < depth; ++z)
19945 for (y = 0; y < height; ++y)
19947 for (x = 0; x < width; ++x)
19949 ptr[z * slice_pitch + y * row_pitch + x] = 0xff000000
19950 | (DWORD)(x / (width - 1.0f) * 255.0f) << 16
19951 | (DWORD)(y / (height - 1.0f) * 255.0f) << 8;
19956 switch (texture_types[t].type)
19958 case D3DRTYPE_TEXTURE:
19959 hr = IDirect3DTexture9_UnlockRect((IDirect3DTexture9 *)src, l);
19960 break;
19961 case D3DRTYPE_CUBETEXTURE:
19962 hr = IDirect3DCubeTexture9_UnlockRect((IDirect3DCubeTexture9 *)src, f, l);
19963 break;
19964 case D3DRTYPE_VOLUMETEXTURE:
19965 hr = IDirect3DVolumeTexture9_UnlockBox((IDirect3DVolumeTexture9 *)src, l);
19966 break;
19967 default:
19968 trace("Unexpected resource type.\n");
19970 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr);
19972 width >>= 1;
19973 if (!width)
19974 width = 1;
19975 height >>= 1;
19976 if (!height)
19977 height = 1;
19978 depth >>= 1;
19979 if (!depth)
19980 depth = 1;
19985 hr = IDirect3DDevice9_UpdateTexture(device, src, dst);
19986 if (FAILED(hr))
19988 todo_wine ok(SUCCEEDED(hr), "Failed to update texture, hr %#x, case %u, %u.\n", hr, t, i);
19989 IDirect3DBaseTexture9_Release(src);
19990 IDirect3DBaseTexture9_Release(dst);
19991 continue;
19993 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x, case %u, %u.\n", hr, t, i);
19995 if (do_visual_test)
19997 hr = IDirect3DDevice9_SetTexture(device, 0, dst);
19998 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
20000 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 1.0f, 0);
20001 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
20003 hr = IDirect3DDevice9_BeginScene(device);
20004 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
20005 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2,
20006 texture_types[t].quad, texture_types[t].vertex_size);
20007 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
20008 hr = IDirect3DDevice9_EndScene(device);
20009 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
20011 color = getPixelColor(device, 320, 240);
20012 ok (color_match(color, 0x007f7f00, 3) || broken(tests[i].broken)
20013 || broken(color == 0x00adbeef), /* WARP device often just breaks down. */
20014 "Got unexpected color 0x%08x, case %u, %u.\n", color, t, i);
20017 IDirect3DBaseTexture9_Release(src);
20018 IDirect3DBaseTexture9_Release(dst);
20021 refcount = IDirect3DDevice9_Release(device);
20022 ok(!refcount, "Device has %u references left.\n", refcount);
20023 IDirect3D9_Release(d3d9);
20024 DestroyWindow(window);
20027 static void test_depthbias(void)
20029 IDirect3DDevice9 *device;
20030 IDirect3D9 *d3d;
20031 IDirect3DSurface9 *ds;
20032 D3DCAPS9 caps;
20033 D3DCOLOR color;
20034 ULONG refcount;
20035 HWND window;
20036 HRESULT hr;
20037 unsigned int i;
20038 static const D3DFORMAT formats[] =
20040 D3DFMT_D16, D3DFMT_D24X8, D3DFMT_D32, D3DFMT_D24S8, MAKEFOURCC('I','N','T','Z'),
20042 /* The scaling factor detection function detects the wrong factor for
20043 * float formats on Nvidia, therefore the following tests are disabled.
20044 * The wined3d function detects 2^23 like for fixed point formats but
20045 * the test needs 2^22 to pass.
20047 * AMD GPUs need a different scaling factor for float depth buffers
20048 * (2^24) than fixed point (2^23), but the wined3d detection function
20049 * works there, producing the right result in the test.
20051 * D3DFMT_D32F_LOCKABLE, D3DFMT_D24FS8,
20055 static const struct
20057 struct vec3 position;
20059 quad[] =
20061 {{-1.0f, -1.0f, 0.0f}},
20062 {{-1.0f, 1.0f, 0.0f}},
20063 {{ 1.0f, -1.0f, 1.0f}},
20064 {{ 1.0f, 1.0f, 1.0f}},
20066 union
20068 float f;
20069 DWORD d;
20070 } conv;
20072 window = create_window();
20073 d3d = Direct3DCreate9(D3D_SDK_VERSION);
20074 ok(!!d3d, "Failed to create a D3D object.\n");
20075 if (!(device = create_device(d3d, window, window, TRUE)))
20077 skip("Failed to create a D3D device, skipping tests.\n");
20078 goto done;
20081 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
20082 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
20083 if (!(caps.RasterCaps & D3DPRASTERCAPS_DEPTHBIAS))
20085 IDirect3DDevice9_Release(device);
20086 skip("D3DPRASTERCAPS_DEPTHBIAS not supported.\n");
20087 goto done;
20090 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
20091 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
20092 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
20093 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
20094 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
20095 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
20096 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
20097 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
20098 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
20099 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
20101 for (i = 0; i < sizeof(formats) / sizeof(*formats); ++i)
20103 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
20104 D3DFMT_X8R8G8B8, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, formats[i])))
20106 skip("Depth format %u not supported, skipping.\n", formats[i]);
20107 continue;
20110 hr = IDirect3DDevice9_CreateDepthStencilSurface(device, 640, 480, formats[i],
20111 D3DMULTISAMPLE_NONE, 0, FALSE, &ds, NULL);
20112 ok(SUCCEEDED(hr), "Failed to create depth stencil surface, hr %#x.\n", hr);
20113 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
20114 ok(SUCCEEDED(hr), "Failed to set depth stencil surface, hr %#x.\n", hr);
20115 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 0.5f, 0);
20116 ok(SUCCEEDED(hr), "Failed to clear %08x\n", hr);
20118 hr = IDirect3DDevice9_BeginScene(device);
20119 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
20121 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0x00ff0000);
20122 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
20123 conv.f = -0.2f;
20124 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_DEPTHBIAS, conv.d);
20125 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
20126 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
20127 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
20129 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0x0000ff00);
20130 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
20131 conv.f = 0.0f;
20132 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_DEPTHBIAS, conv.d);
20133 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
20134 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
20135 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
20137 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0x000000ff);
20138 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
20139 conv.f = 0.2f;
20140 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_DEPTHBIAS, conv.d);
20141 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
20142 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
20143 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
20145 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0x00ffffff);
20146 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
20147 conv.f = 0.4f;
20148 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_DEPTHBIAS, conv.d);
20149 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
20150 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
20151 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
20153 color = getPixelColor(device, 61, 240);
20154 ok(color_match(color, 0x00ffffff, 1), "Got unexpected color %08x at x=62, format %u.\n", color, formats[i]);
20155 color = getPixelColor(device, 65, 240);
20157 /* The broken results are for the WARP driver on the testbot. It seems to initialize
20158 * a scaling factor based on the first depth format that is used. Other formats with
20159 * a different depth size then render incorrectly. */
20160 ok(color_match(color, 0x000000ff, 1) || broken(color_match(color, 0x00ffffff, 1)),
20161 "Got unexpected color %08x at x=64, format %u.\n", color, formats[i]);
20162 color = getPixelColor(device, 190, 240);
20163 ok(color_match(color, 0x000000ff, 1) || broken(color_match(color, 0x00ffffff, 1)),
20164 "Got unexpected color %08x at x=190, format %u.\n", color, formats[i]);
20166 color = getPixelColor(device, 194, 240);
20167 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ffffff, 1)),
20168 "Got unexpected color %08x at x=194, format %u.\n", color, formats[i]);
20169 color = getPixelColor(device, 318, 240);
20170 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ffffff, 1)),
20171 "Got unexpected color %08x at x=318, format %u.\n", color, formats[i]);
20173 color = getPixelColor(device, 322, 240);
20174 ok(color_match(color, 0x00ff0000, 1) || broken(color_match(color, 0x00000000, 1)),
20175 "Got unexpected color %08x at x=322, format %u.\n", color, formats[i]);
20176 color = getPixelColor(device, 446, 240);
20177 ok(color_match(color, 0x00ff0000, 1) || broken(color_match(color, 0x00000000, 1)),
20178 "Got unexpected color %08x at x=446, format %u.\n", color, formats[i]);
20180 color = getPixelColor(device, 450, 240);
20181 ok(color_match(color, 0x00000000, 1), "Got unexpected color %08x at x=446, format %u.\n", color, formats[i]);
20183 hr = IDirect3DDevice9_EndScene(device);
20184 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
20186 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
20187 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
20188 IDirect3DSurface9_Release(ds);
20191 refcount = IDirect3DDevice9_Release(device);
20192 ok(!refcount, "Device has %u references left.\n", refcount);
20194 done:
20195 IDirect3D9_Release(d3d);
20196 DestroyWindow(window);
20199 static void test_flip(void)
20201 IDirect3DDevice9 *device;
20202 IDirect3D9 *d3d;
20203 ULONG refcount;
20204 HWND window;
20205 HRESULT hr;
20206 IDirect3DSurface9 *back_buffers[3], *test_surface;
20207 unsigned int i;
20208 D3DCOLOR color;
20209 D3DPRESENT_PARAMETERS present_parameters = {0};
20211 window = create_window();
20212 d3d = Direct3DCreate9(D3D_SDK_VERSION);
20213 ok(!!d3d, "Failed to create a D3D object.\n");
20215 present_parameters.BackBufferWidth = 640;
20216 present_parameters.BackBufferHeight = 480;
20217 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
20218 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
20219 present_parameters.hDeviceWindow = window;
20220 present_parameters.Windowed = TRUE;
20221 present_parameters.BackBufferCount = 3;
20222 present_parameters.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
20223 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
20224 window, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
20225 if (!device)
20227 skip("Failed to create a D3D device, skipping tests.\n");
20228 IDirect3D9_Release(d3d);
20229 DestroyWindow(window);
20230 return;
20233 for (i = 0; i < sizeof(back_buffers) / sizeof(*back_buffers); ++i)
20235 hr = IDirect3DDevice9_GetBackBuffer(device, 0, i, D3DBACKBUFFER_TYPE_MONO, &back_buffers[i]);
20236 ok(SUCCEEDED(hr), "Failed to get back buffer, hr %#x.\n", hr);
20238 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &test_surface);
20239 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
20240 ok(test_surface == back_buffers[0], "Expected render target %p, got %p.\n", back_buffers[0], test_surface);
20241 IDirect3DSurface9_Release(test_surface);
20243 hr = IDirect3DDevice9_SetRenderTarget(device, 0, back_buffers[2]);
20244 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
20246 hr = IDirect3DDevice9_ColorFill(device, back_buffers[0], NULL, 0xffff0000);
20247 ok(SUCCEEDED(hr), "Failed to color fill, hr %#x.\n", hr);
20248 hr = IDirect3DDevice9_ColorFill(device, back_buffers[1], NULL, 0xff00ff00);
20249 ok(SUCCEEDED(hr), "Failed to color fill, hr %#x.\n", hr);
20250 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0f, 0);
20251 ok(SUCCEEDED(hr), "Failed to clear, hr %#x\n", hr);
20253 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
20254 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
20256 /* Render target is unmodified. */
20257 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &test_surface);
20258 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
20259 ok(test_surface == back_buffers[2], "Expected render target %p, got %p.\n", back_buffers[2], test_surface);
20260 IDirect3DSurface9_Release(test_surface);
20262 /* Backbuffer surface pointers are unmodified */
20263 for (i = 0; i < sizeof(back_buffers) / sizeof(*back_buffers); ++i)
20265 hr = IDirect3DDevice9_GetBackBuffer(device, 0, i, D3DBACKBUFFER_TYPE_MONO, &test_surface);
20266 ok(SUCCEEDED(hr), "Failed to get back buffer, hr %#x.\n", hr);
20267 ok(test_surface == back_buffers[i], "Expected back buffer %u = %p, got %p.\n",
20268 i, back_buffers[i], test_surface);
20269 IDirect3DSurface9_Release(test_surface);
20272 /* Contents were changed. */
20273 color = getPixelColorFromSurface(back_buffers[0], 1, 1);
20274 ok(color == 0xff00ff00, "Got unexpected color 0x%08x.\n", color);
20275 color = getPixelColorFromSurface(back_buffers[1], 1, 1);
20276 ok(color == 0xff0000ff, "Got unexpected color 0x%08x.\n", color);
20278 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff808080, 0.0f, 0);
20279 ok(SUCCEEDED(hr), "Failed to clear, hr %#x\n", hr);
20281 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
20282 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
20284 color = getPixelColorFromSurface(back_buffers[0], 1, 1);
20285 ok(color == 0xff0000ff, "Got unexpected color 0x%08x.\n", color);
20286 color = getPixelColorFromSurface(back_buffers[1], 1, 1);
20287 ok(color == 0xff808080, "Got unexpected color 0x%08x.\n", color);
20289 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
20290 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
20292 color = getPixelColorFromSurface(back_buffers[0], 1, 1);
20293 ok(color == 0xff808080, "Got unexpected color 0x%08x.\n", color);
20295 for (i = 0; i < sizeof(back_buffers) / sizeof(*back_buffers); ++i)
20296 IDirect3DSurface9_Release(back_buffers[i]);
20298 refcount = IDirect3DDevice9_Release(device);
20299 ok(!refcount, "Device has %u references left.\n", refcount);
20301 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
20302 D3DFMT_A8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES, NULL)))
20304 skip("Multisampling not supported for D3DFMT_A8R8G8B8, skipping multisample flip test.\n");
20305 goto done;
20308 present_parameters.BackBufferCount = 2;
20309 present_parameters.MultiSampleType = D3DMULTISAMPLE_2_SAMPLES;
20310 present_parameters.Flags = 0;
20311 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
20312 window, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
20314 for (i = 0; i < present_parameters.BackBufferCount; ++i)
20316 hr = IDirect3DDevice9_GetBackBuffer(device, 0, i, D3DBACKBUFFER_TYPE_MONO, &back_buffers[i]);
20317 ok(SUCCEEDED(hr), "Failed to get back buffer, hr %#x.\n", hr);
20320 hr = IDirect3DDevice9_SetRenderTarget(device, 0, back_buffers[1]);
20321 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
20322 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff808080, 0.0f, 0);
20323 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
20325 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
20326 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
20328 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
20329 D3DMULTISAMPLE_NONE, 0, TRUE, &test_surface, NULL);
20330 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
20331 hr = IDirect3DDevice9_StretchRect(device, back_buffers[0], NULL, test_surface, NULL, D3DTEXF_POINT);
20332 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
20334 color = getPixelColorFromSurface(test_surface, 1, 1);
20335 ok(color == 0xff808080, "Got unexpected color 0x%08x.\n", color);
20337 IDirect3DSurface9_Release(test_surface);
20338 for (i = 0; i < present_parameters.BackBufferCount; ++i)
20339 IDirect3DSurface9_Release(back_buffers[i]);
20341 refcount = IDirect3DDevice9_Release(device);
20342 ok(!refcount, "Device has %u references left.\n", refcount);
20344 done:
20345 IDirect3D9_Release(d3d);
20346 DestroyWindow(window);
20349 static void test_uninitialized_varyings(void)
20351 static const D3DMATRIX mat =
20353 1.0f, 0.0f, 0.0f, 0.0f,
20354 0.0f, 1.0f, 0.0f, 0.0f,
20355 0.0f, 0.0f, 1.0f, 0.0f,
20356 0.0f, 0.0f, 0.0f, 1.0f,
20357 }}};
20358 static const struct vec3 quad[] =
20360 {-1.0f, -1.0f, 0.1f},
20361 {-1.0f, 1.0f, 0.1f},
20362 { 1.0f, -1.0f, 0.1f},
20363 { 1.0f, 1.0f, 0.1f},
20365 static const DWORD vs1_code[] =
20367 0xfffe0101, /* vs_1_1 */
20368 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
20369 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
20370 0x0000ffff
20372 static const DWORD vs1_partial_code[] =
20374 0xfffe0101, /* vs_1_1 */
20375 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
20376 0x00000051, 0xa00f0000, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, /* def c0, 0.5, 0.5, 0.5, 0.5 */
20377 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
20378 0x00000001, 0xd0010000, 0xa0e40000, /* mov oD0.x, c0 */
20379 0x00000001, 0xd0010001, 0xa0e40000, /* mov oD1.x, c0 */
20380 0x00000001, 0xe0010000, 0xa0e40000, /* mov oT0.x, c0 */
20381 0x0000ffff
20383 static const DWORD vs2_code[] =
20385 0xfffe0200, /* vs_2_0 */
20386 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
20387 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
20388 0x0000ffff
20390 static const DWORD vs2_partial_code[] =
20392 0xfffe0200, /* vs_2_0 */
20393 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
20394 0x05000051, 0xa00f0000, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, /* def c0, 0.5, 0.5, 0.5, 0.5 */
20395 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
20396 0x02000001, 0xd0010000, 0xa0e40000, /* mov oD0.x, c0 */
20397 0x02000001, 0xd0010001, 0xa0e40000, /* mov oD1.x, c0 */
20398 0x02000001, 0xe0010000, 0xa0e40000, /* mov oT0.x, c0 */
20399 0x0000ffff
20401 static const DWORD vs3_code[] =
20403 0xfffe0300, /* vs_3_0 */
20404 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
20405 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
20406 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
20407 0x0000ffff
20409 static const DWORD vs3_partial_code[] =
20411 0xfffe0300, /* vs_3_0 */
20412 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
20413 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
20414 0x0200001f, 0x8000000a, 0xe00f0001, /* dcl_color0 o1 */
20415 0x0200001f, 0x8001000a, 0xe00f0002, /* dcl_color1 o2 */
20416 0x0200001f, 0x80000005, 0xe00f0003, /* dcl_texcoord0 o3 */
20417 0x05000051, 0xa00f0000, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, /* def c0, 0.5, 0.5, 0.5, 0.5 */
20418 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
20419 0x02000001, 0xe0010001, 0xa0e40000, /* mov o1.x, c0 */
20420 0x02000001, 0xe0010002, 0xa0e40000, /* mov o2.x, c0 */
20421 0x02000001, 0xe0010003, 0xa0e40000, /* mov o3.x, c0 */
20422 0x0000ffff
20424 static const DWORD ps1_diffuse_code[] =
20426 0xffff0101, /* ps_1_1 */
20427 0x00000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
20428 0x0000ffff
20430 static const DWORD ps1_specular_code[] =
20432 0xffff0101, /* ps_1_1 */
20433 0x00000001, 0x800f0000, 0x90e40001, /* mov r0, v1 */
20434 0x0000ffff
20436 static const DWORD ps1_texcoord_code[] =
20438 0xffff0101, /* ps_1_1 */
20439 0x00000040, 0xb00f0000, /* texcoord t0 */
20440 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
20441 0x0000ffff
20443 static const DWORD ps2_diffuse_code[] =
20445 0xffff0200, /* ps_2_0 */
20446 0x0200001f, 0x80000000, 0x900f0000, /* dcl v0 */
20447 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
20448 0x0000ffff
20450 static const DWORD ps2_specular_code[] =
20452 0xffff0200, /* ps_2_0 */
20453 0x0200001f, 0x80000000, 0x900f0001, /* dcl v1 */
20454 0x02000001, 0x800f0800, 0x90e40001, /* mov oC0, v1 */
20455 0x0000ffff
20457 static const DWORD ps2_texcoord_code[] =
20459 0xffff0200, /* ps_2_0 */
20460 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
20461 0x02000001, 0x800f0800, 0xb0e40000, /* mov oC0, t0 */
20462 0x0000ffff
20464 #if 0
20465 /* This has been left here for documentation purposes. It is referenced in disabled tests in the table below. */
20466 static const DWORD ps3_diffuse_code[] =
20468 0xffff0300, /* ps_3_0 */
20469 0x0200001f, 0x8000000a, 0x900f0000, /* dcl_color0 v0 */
20470 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
20471 0x0000ffff
20473 #endif
20474 static const DWORD ps3_specular_code[] =
20476 0xffff0300, /* ps_3_0 */
20477 0x0200001f, 0x8001000a, 0x900f0001, /* dcl_color1 v1 */
20478 0x02000001, 0x800f0800, 0x90e40001, /* mov oC0, v1 */
20479 0x0000ffff
20481 static const DWORD ps3_texcoord_code[] =
20483 0xffff0300, /* ps_3_0 */
20484 0x0200001f, 0x80000005, 0x900f0000, /* dcl_texcoord0 v0 */
20485 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
20486 0x0000ffff
20488 static const struct
20490 DWORD vs_version;
20491 const DWORD *vs;
20492 DWORD ps_version;
20493 const DWORD *ps;
20494 D3DCOLOR expected;
20495 BOOL allow_zero_alpha;
20496 BOOL partial;
20497 BOOL broken_warp;
20499 /* On AMD specular color is generally initialized to 0x00000000 and texcoords to 0xff000000
20500 * while on Nvidia it's the opposite. Just allow both.
20502 * Partially initialized varyings reliably handle the component that has been initialized.
20503 * The uninitialized components generally follow the rule above, with some exceptions on
20504 * radeon cards. r500 and r600 GPUs have been found to set uninitialized components to 0.0,
20505 * 0.5 and 1.0 without a sensible pattern. */
20506 tests[] =
20508 {D3DVS_VERSION(1, 1), vs1_code, 0, NULL, 0xffffffff},
20509 { 0, NULL, D3DPS_VERSION(1, 1), ps1_texcoord_code, 0xff000000, TRUE},
20510 { 0, NULL, D3DPS_VERSION(2, 0), ps2_texcoord_code, 0xff000000, TRUE},
20511 {D3DVS_VERSION(1, 1), vs1_code, D3DPS_VERSION(1, 1), ps1_diffuse_code, 0xffffffff},
20512 {D3DVS_VERSION(1, 1), vs1_code, D3DPS_VERSION(1, 1), ps1_specular_code, 0xff000000, TRUE, FALSE, TRUE},
20513 {D3DVS_VERSION(1, 1), vs1_code, D3DPS_VERSION(1, 1), ps1_texcoord_code, 0xff000000, TRUE},
20514 {D3DVS_VERSION(2, 0), vs2_code, D3DPS_VERSION(2, 0), ps2_diffuse_code, 0xffffffff},
20515 {D3DVS_VERSION(2, 0), vs2_code, D3DPS_VERSION(2, 0), ps2_specular_code, 0xff000000, TRUE, FALSE, TRUE},
20516 {D3DVS_VERSION(2, 0), vs2_code, D3DPS_VERSION(2, 0), ps2_texcoord_code, 0xff000000, TRUE},
20517 /* This test shows a lot of combinations of alpha and color that involve 1.0 and 0.0. Disable it.
20519 * AMD r500 sets alpha = 1.0, color = 0.0. Nvidia sets alpha = 1.0, color = 1.0. r600 Sets Alpha = 0.0,
20520 * color = 0.0. So far no combination with Alpha = 0.0, color = 1.0 has been found though.
20521 * {D3DVS_VERSION(3, 0), vs3_code, D3DPS_VERSION(3, 0), ps3_diffuse_code, 0xffffffff, FALSE, FALSE},
20523 * The same issues apply to the partially initialized COLOR0 varying, in addition to unreliable results
20524 * with partially initialized varyings in general.
20525 * {D3DVS_VERSION(3, 0), vs3_partial_code, D3DPS_VERSION(3, 0), ps3_diffuse_code, 0xff7fffff, TRUE, TRUE}, */
20526 {D3DVS_VERSION(3, 0), vs3_code, D3DPS_VERSION(3, 0), ps3_specular_code, 0xff000000, TRUE, FALSE, TRUE},
20527 {D3DVS_VERSION(3, 0), vs3_code, D3DPS_VERSION(3, 0), ps3_texcoord_code, 0xff000000, TRUE, FALSE, TRUE},
20528 {D3DVS_VERSION(1, 1), vs1_partial_code, 0, NULL, 0xff7fffff, FALSE, TRUE},
20529 {D3DVS_VERSION(1, 1), vs1_partial_code, D3DPS_VERSION(1, 1), ps1_diffuse_code, 0xff7fffff, FALSE, TRUE},
20530 {D3DVS_VERSION(1, 1), vs1_partial_code, D3DPS_VERSION(1, 1), ps1_specular_code, 0xff7f0000, TRUE, TRUE},
20531 {D3DVS_VERSION(1, 1), vs1_partial_code, D3DPS_VERSION(1, 1), ps1_texcoord_code, 0xff7f0000, TRUE, TRUE},
20532 {D3DVS_VERSION(2, 0), vs2_partial_code, D3DPS_VERSION(2, 0), ps2_diffuse_code, 0xff7fffff, FALSE, TRUE},
20533 {D3DVS_VERSION(2, 0), vs2_partial_code, D3DPS_VERSION(2, 0), ps2_specular_code, 0xff7f0000, TRUE, TRUE},
20534 {D3DVS_VERSION(2, 0), vs2_partial_code, D3DPS_VERSION(2, 0), ps2_texcoord_code, 0xff7f0000, TRUE, TRUE},
20535 {D3DVS_VERSION(3, 0), vs3_partial_code, D3DPS_VERSION(3, 0), ps3_specular_code, 0x007f0000, FALSE, TRUE},
20536 {D3DVS_VERSION(3, 0), vs3_partial_code, D3DPS_VERSION(3, 0), ps3_texcoord_code, 0xff7f0000, TRUE, TRUE},
20538 IDirect3DDevice9 *device;
20539 IDirect3D9 *d3d;
20540 HWND window;
20541 HRESULT hr;
20542 D3DADAPTER_IDENTIFIER9 identifier;
20543 IDirect3DSurface9 *backbuffer;
20544 struct surface_readback rb;
20545 IDirect3DVertexShader9 *vs;
20546 IDirect3DPixelShader9 *ps;
20547 unsigned int i;
20548 ULONG refcount;
20549 D3DCAPS9 caps;
20550 D3DCOLOR color;
20551 BOOL warp;
20553 window = create_window();
20554 d3d = Direct3DCreate9(D3D_SDK_VERSION);
20555 ok(!!d3d, "Failed to create a D3D object.\n");
20556 if (!(device = create_device(d3d, window, window, TRUE)))
20558 skip("Failed to create a D3D device, skipping tests.\n");
20559 IDirect3D9_Release(d3d);
20560 DestroyWindow(window);
20561 return;
20564 hr = IDirect3D9_GetAdapterIdentifier(d3d, D3DADAPTER_DEFAULT, 0, &identifier);
20565 ok(SUCCEEDED(hr), "Failed to get adapter identifier, hr %#x.\n", hr);
20566 warp = adapter_is_warp(&identifier);
20568 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
20569 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
20571 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &backbuffer);
20572 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
20574 hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLD, &mat);
20575 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
20576 hr = IDirect3DDevice9_SetTransform(device, D3DTS_VIEW, &mat);
20577 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
20578 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &mat);
20579 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
20580 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, FALSE);
20581 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
20582 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
20583 ok(SUCCEEDED(hr), "Failed to disable Z test, hr %#x.\n", hr);
20584 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGENABLE, FALSE);
20585 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
20586 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILENABLE, FALSE);
20587 ok(SUCCEEDED(hr), "Failed to disable stencil test, hr %#x.\n", hr);
20588 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE);
20589 ok(SUCCEEDED(hr), "Failed to disable culling, hr %#x.\n", hr);
20591 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
20592 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
20594 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
20596 if (caps.VertexShaderVersion < tests[i].vs_version
20597 || caps.PixelShaderVersion < tests[i].ps_version)
20599 skip("Vertex / pixel shader version not supported, skipping test %u.\n", i);
20600 continue;
20602 if (tests[i].vs)
20604 hr = IDirect3DDevice9_CreateVertexShader(device, tests[i].vs, &vs);
20605 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x (case %u).\n", hr, i);
20607 else
20609 vs = NULL;
20611 if (tests[i].ps)
20613 hr = IDirect3DDevice9_CreatePixelShader(device, tests[i].ps, &ps);
20614 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x (case %u).\n", hr, i);
20616 else
20618 ps = NULL;
20621 hr = IDirect3DDevice9_SetVertexShader(device, vs);
20622 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
20623 hr = IDirect3DDevice9_SetPixelShader(device, ps);
20624 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
20626 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
20627 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
20629 hr = IDirect3DDevice9_BeginScene(device);
20630 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
20632 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
20633 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
20635 hr = IDirect3DDevice9_EndScene(device);
20636 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
20638 get_rt_readback(backbuffer, &rb);
20639 color = get_readback_color(&rb, 320, 240);
20640 ok(color_match(color, tests[i].expected, 1)
20641 || (tests[i].allow_zero_alpha && color_match(color, tests[i].expected & 0x00ffffff, 1))
20642 || (broken(warp && tests[i].broken_warp))
20643 || broken(tests[i].partial && color_match(color & 0x00ff0000, tests[i].expected & 0x00ff0000, 1)),
20644 "Got unexpected color 0x%08x, case %u.\n", color, i);
20645 release_surface_readback(&rb);
20647 if (vs)
20648 IDirect3DVertexShader9_Release(vs);
20649 if (ps)
20650 IDirect3DVertexShader9_Release(ps);
20653 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
20654 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
20656 IDirect3DSurface9_Release(backbuffer);
20657 refcount = IDirect3DDevice9_Release(device);
20658 ok(!refcount, "Device has %u references left.\n", refcount);
20659 IDirect3D9_Release(d3d);
20660 DestroyWindow(window);
20663 static void test_multisample_init(void)
20665 IDirect3DDevice9 *device;
20666 IDirect3D9 *d3d;
20667 IDirect3DSurface9 *back, *multi;
20668 ULONG refcount;
20669 HWND window;
20670 HRESULT hr;
20671 D3DCOLOR color;
20672 unsigned int x, y;
20673 struct surface_readback rb;
20674 BOOL all_zero = TRUE;
20676 window = create_window();
20677 d3d = Direct3DCreate9(D3D_SDK_VERSION);
20678 ok(!!d3d, "Failed to create a D3D object.\n");
20680 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
20681 D3DFMT_A8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES, NULL)))
20683 skip("Multisampling not supported for D3DFMT_A8R8G8B8, skipping multisample init test.\n");
20684 goto done;
20687 if (!(device = create_device(d3d, window, window, TRUE)))
20689 skip("Failed to create a D3D device, skipping tests.\n");
20690 goto done;
20693 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &back);
20694 ok(SUCCEEDED(hr), "Failed to get back buffer, hr %#x.\n", hr);
20695 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
20696 D3DMULTISAMPLE_2_SAMPLES, 0, FALSE, &multi, NULL);
20697 ok(SUCCEEDED(hr), "Failed to create multisampled render target, hr %#x.\n", hr);
20699 hr = IDirect3DDevice9_StretchRect(device, multi, NULL, back, NULL, D3DTEXF_POINT);
20700 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
20702 get_rt_readback(back, &rb);
20703 for (y = 0; y < 480; ++y)
20705 for (x = 0; x < 640; x++)
20707 color = get_readback_color(&rb, x, y);
20708 if (!color_match(color, 0x00000000, 0))
20710 all_zero = FALSE;
20711 break;
20714 if (!all_zero)
20715 break;
20717 release_surface_readback(&rb);
20718 ok(all_zero, "Got unexpected color 0x%08x, position %ux%u.\n", color, x, y);
20720 IDirect3DSurface9_Release(multi);
20721 IDirect3DSurface9_Release(back);
20723 refcount = IDirect3DDevice9_Release(device);
20724 ok(!refcount, "Device has %u references left.\n", refcount);
20726 done:
20727 IDirect3D9_Release(d3d);
20728 DestroyWindow(window);
20731 static void test_texture_blending(void)
20733 #define STATE_END() {0xffffffff, 0xffffffff}
20734 #define IS_STATE_END(s) (s.name == 0xffffffff && s.value == 0xffffffff)
20736 IDirect3DTexture9 *texture_bumpmap, *texture_red;
20737 IDirect3DSurface9 *backbuffer;
20738 struct surface_readback rb;
20739 D3DLOCKED_RECT locked_rect;
20740 IDirect3DDevice9 *device;
20741 unsigned int i, j, k;
20742 IDirect3D9 *d3d;
20743 D3DCOLOR color;
20744 ULONG refcount;
20745 D3DCAPS9 caps;
20746 HWND window;
20747 HRESULT hr;
20749 static const struct
20751 struct vec3 position;
20752 DWORD diffuse;
20754 quad[] =
20756 {{-1.0f, -1.0f, 0.1f}, D3DCOLOR_ARGB(0x80, 0xff, 0xff, 0x02)},
20757 {{-1.0f, 1.0f, 0.1f}, D3DCOLOR_ARGB(0x80, 0xff, 0xff, 0x02)},
20758 {{ 1.0f, -1.0f, 0.1f}, D3DCOLOR_ARGB(0x80, 0xff, 0xff, 0x02)},
20759 {{ 1.0f, 1.0f, 0.1f}, D3DCOLOR_ARGB(0x80, 0xff, 0xff, 0x02)},
20762 static const float bumpenvmat[4] = {1.0f, 1.0f, 0.0f, 0.0f};
20764 struct texture_stage_state
20766 D3DTEXTURESTAGESTATETYPE name;
20767 DWORD value;
20770 struct texture_stage
20772 enum
20774 TEXTURE_INVALID,
20775 TEXTURE_NONE,
20776 TEXTURE_BUMPMAP,
20777 TEXTURE_RED,
20779 texture;
20780 struct texture_stage_state state[20];
20783 static const struct texture_stage default_stage_state =
20785 TEXTURE_NONE,
20787 {D3DTSS_COLOROP, D3DTOP_DISABLE},
20788 {D3DTSS_COLORARG1, D3DTA_TEXTURE},
20789 {D3DTSS_COLORARG2, D3DTA_CURRENT},
20790 {D3DTSS_ALPHAOP, D3DTOP_DISABLE},
20791 {D3DTSS_ALPHAARG1, D3DTA_TEXTURE},
20792 {D3DTSS_ALPHAARG2, D3DTA_CURRENT},
20793 {D3DTSS_BUMPENVMAT00, 0},
20794 {D3DTSS_BUMPENVMAT01, 0},
20795 {D3DTSS_BUMPENVMAT10, 0},
20796 {D3DTSS_BUMPENVMAT11, 0},
20797 {D3DTSS_BUMPENVLSCALE, 0},
20798 {D3DTSS_BUMPENVLOFFSET, 0},
20799 {D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE},
20800 {D3DTSS_COLORARG0, D3DTA_CURRENT},
20801 {D3DTSS_ALPHAARG0, D3DTA_CURRENT},
20802 {D3DTSS_RESULTARG, D3DTA_CURRENT},
20803 {D3DTSS_CONSTANT, 0},
20804 STATE_END(),
20808 const struct test
20810 DWORD tex_op_caps;
20811 D3DCOLOR expected_color;
20812 struct texture_stage stage[8];
20814 tests[] =
20817 D3DTEXOPCAPS_DISABLE,
20818 0x80ffff02,
20821 TEXTURE_NONE,
20823 STATE_END(),
20829 D3DTEXOPCAPS_DISABLE | D3DTEXOPCAPS_SELECTARG1,
20830 0x80ffff02,
20833 TEXTURE_NONE,
20835 {D3DTSS_COLOROP, D3DTOP_SELECTARG1},
20836 {D3DTSS_COLORARG1, D3DTA_CURRENT},
20837 STATE_END(),
20840 {TEXTURE_INVALID}
20844 D3DTEXOPCAPS_DISABLE | D3DTEXOPCAPS_SELECTARG1,
20845 0x80ffff02,
20848 TEXTURE_NONE,
20850 {D3DTSS_COLOROP, D3DTOP_SELECTARG1},
20851 {D3DTSS_COLORARG1, D3DTA_CURRENT},
20852 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
20853 {D3DTSS_ALPHAARG1, D3DTA_CURRENT},
20854 STATE_END(),
20860 D3DTEXOPCAPS_DISABLE | D3DTEXOPCAPS_SELECTARG1,
20861 0x80ffff02,
20864 TEXTURE_NONE,
20866 {D3DTSS_COLOROP, D3DTOP_SELECTARG1},
20867 {D3DTSS_COLORARG1, D3DTA_DIFFUSE},
20868 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
20869 {D3DTSS_ALPHAARG1, D3DTA_DIFFUSE},
20870 STATE_END(),
20876 D3DTEXOPCAPS_DISABLE | D3DTEXOPCAPS_SELECTARG1,
20877 0x00000000,
20880 TEXTURE_NONE,
20882 {D3DTSS_COLOROP, D3DTOP_SELECTARG1},
20883 {D3DTSS_COLORARG1, D3DTA_TEMP},
20884 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
20885 {D3DTSS_ALPHAARG1, D3DTA_TEMP},
20886 STATE_END(),
20892 D3DTEXOPCAPS_DISABLE | D3DTEXOPCAPS_SELECTARG1 | D3DTEXOPCAPS_SUBTRACT,
20893 0x80f0f000,
20896 TEXTURE_NONE,
20898 {D3DTSS_COLOROP, D3DTOP_SELECTARG1},
20899 {D3DTSS_COLORARG1, D3DTA_CURRENT},
20900 STATE_END(),
20904 TEXTURE_NONE,
20906 {D3DTSS_COLOROP, D3DTOP_SUBTRACT},
20907 {D3DTSS_COLORARG1, D3DTA_CURRENT},
20908 {D3DTSS_COLORARG2, D3DTA_CONSTANT},
20909 {D3DTSS_CONSTANT, 0x0f0f0f0f},
20910 STATE_END(),
20913 {TEXTURE_INVALID}
20917 D3DTEXOPCAPS_DISABLE | D3DTEXOPCAPS_SELECTARG1 | D3DTEXOPCAPS_SUBTRACT,
20918 0x71f0f000,
20921 TEXTURE_NONE,
20923 {D3DTSS_COLOROP, D3DTOP_SELECTARG1},
20924 {D3DTSS_COLORARG1, D3DTA_CURRENT},
20925 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
20926 {D3DTSS_ALPHAARG1, D3DTA_CURRENT},
20927 STATE_END(),
20931 TEXTURE_NONE,
20933 {D3DTSS_COLOROP, D3DTOP_SUBTRACT},
20934 {D3DTSS_COLORARG1, D3DTA_CURRENT},
20935 {D3DTSS_COLORARG2, D3DTA_CONSTANT},
20936 {D3DTSS_ALPHAOP, D3DTOP_SUBTRACT},
20937 {D3DTSS_ALPHAARG1, D3DTA_CURRENT},
20938 {D3DTSS_ALPHAARG2, D3DTA_CONSTANT},
20939 {D3DTSS_CONSTANT, 0x0f0f0f0f},
20940 STATE_END(),
20943 {TEXTURE_INVALID}
20948 D3DTEXOPCAPS_DISABLE | D3DTEXOPCAPS_SELECTARG1 | D3DTEXOPCAPS_BUMPENVMAP | D3DTEXOPCAPS_MODULATE,
20949 0x80ff0000,
20952 TEXTURE_BUMPMAP,
20954 {D3DTSS_COLOROP, D3DTOP_BUMPENVMAP},
20955 {D3DTSS_BUMPENVMAT00, *(DWORD *)&bumpenvmat[0]},
20956 {D3DTSS_BUMPENVMAT01, *(DWORD *)&bumpenvmat[1]},
20957 {D3DTSS_BUMPENVMAT10, *(DWORD *)&bumpenvmat[2]},
20958 {D3DTSS_BUMPENVMAT11, *(DWORD *)&bumpenvmat[3]},
20959 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
20960 {D3DTSS_ALPHAARG1, D3DTA_TEXTURE},
20961 STATE_END(),
20966 TEXTURE_RED,
20968 {D3DTSS_COLOROP, D3DTOP_MODULATE},
20969 STATE_END(),
20972 {TEXTURE_INVALID}
20976 D3DTEXOPCAPS_DISABLE | D3DTEXOPCAPS_SELECTARG1 | D3DTEXOPCAPS_BUMPENVMAP | D3DTEXOPCAPS_MODULATE,
20977 0x80ff0000,
20980 TEXTURE_BUMPMAP,
20982 {D3DTSS_COLOROP, D3DTOP_BUMPENVMAP},
20983 {D3DTSS_BUMPENVMAT00, *(DWORD *)&bumpenvmat[0]},
20984 {D3DTSS_BUMPENVMAT01, *(DWORD *)&bumpenvmat[1]},
20985 {D3DTSS_BUMPENVMAT10, *(DWORD *)&bumpenvmat[2]},
20986 {D3DTSS_BUMPENVMAT11, *(DWORD *)&bumpenvmat[3]},
20987 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
20988 {D3DTSS_ALPHAARG1, D3DTA_DIFFUSE},
20989 STATE_END(),
20993 TEXTURE_RED,
20995 {D3DTSS_COLOROP, D3DTOP_MODULATE},
20996 STATE_END(),
20999 {TEXTURE_INVALID}
21003 D3DTEXOPCAPS_DISABLE | D3DTEXOPCAPS_SELECTARG1 | D3DTEXOPCAPS_BUMPENVMAP | D3DTEXOPCAPS_MODULATE,
21004 0x80ff0000,
21007 TEXTURE_BUMPMAP,
21009 {D3DTSS_COLOROP, D3DTOP_BUMPENVMAP},
21010 {D3DTSS_BUMPENVMAT00, *(DWORD *)&bumpenvmat[0]},
21011 {D3DTSS_BUMPENVMAT01, *(DWORD *)&bumpenvmat[1]},
21012 {D3DTSS_BUMPENVMAT10, *(DWORD *)&bumpenvmat[2]},
21013 {D3DTSS_BUMPENVMAT11, *(DWORD *)&bumpenvmat[3]},
21014 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21015 {D3DTSS_ALPHAARG1, D3DTA_TEMP},
21016 STATE_END(),
21020 TEXTURE_RED,
21022 {D3DTSS_COLOROP, D3DTOP_MODULATE},
21023 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21024 {D3DTSS_ALPHAARG1, D3DTA_CURRENT},
21025 STATE_END(),
21028 {TEXTURE_INVALID}
21032 D3DTEXOPCAPS_DISABLE | D3DTEXOPCAPS_SELECTARG1 | D3DTEXOPCAPS_BUMPENVMAP | D3DTEXOPCAPS_MODULATE,
21033 0x00ff0000,
21036 TEXTURE_BUMPMAP,
21038 {D3DTSS_COLOROP, D3DTOP_BUMPENVMAP},
21039 {D3DTSS_BUMPENVMAT00, *(DWORD *)&bumpenvmat[0]},
21040 {D3DTSS_BUMPENVMAT01, *(DWORD *)&bumpenvmat[1]},
21041 {D3DTSS_BUMPENVMAT10, *(DWORD *)&bumpenvmat[2]},
21042 {D3DTSS_BUMPENVMAT11, *(DWORD *)&bumpenvmat[3]},
21043 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21044 {D3DTSS_ALPHAARG1, D3DTA_TEMP},
21045 STATE_END(),
21049 TEXTURE_RED,
21051 {D3DTSS_COLOROP, D3DTOP_MODULATE},
21052 {D3DTSS_COLORARG1, D3DTA_TEXTURE},
21053 {D3DTSS_COLORARG2, D3DTA_CURRENT},
21054 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21055 {D3DTSS_ALPHAARG1, D3DTA_TEMP},
21056 STATE_END(),
21059 {TEXTURE_INVALID}
21063 D3DTEXOPCAPS_DISABLE | D3DTEXOPCAPS_SELECTARG1 | D3DTEXOPCAPS_BUMPENVMAP | D3DTEXOPCAPS_MODULATE,
21064 0x80ff0000,
21067 TEXTURE_BUMPMAP,
21069 {D3DTSS_COLOROP, D3DTOP_BUMPENVMAP},
21070 {D3DTSS_BUMPENVMAT00, *(DWORD *)&bumpenvmat[0]},
21071 {D3DTSS_BUMPENVMAT01, *(DWORD *)&bumpenvmat[1]},
21072 {D3DTSS_BUMPENVMAT10, *(DWORD *)&bumpenvmat[2]},
21073 {D3DTSS_BUMPENVMAT11, *(DWORD *)&bumpenvmat[3]},
21074 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21075 {D3DTSS_ALPHAARG1, D3DTA_CURRENT},
21076 STATE_END(),
21080 TEXTURE_RED,
21082 {D3DTSS_COLOROP, D3DTOP_MODULATE},
21083 {D3DTSS_COLORARG1, D3DTA_TEXTURE},
21084 {D3DTSS_COLORARG2, D3DTA_CURRENT},
21085 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21086 {D3DTSS_ALPHAARG1, D3DTA_CURRENT},
21087 STATE_END(),
21090 {TEXTURE_INVALID}
21095 D3DTEXOPCAPS_DISABLE | D3DTEXOPCAPS_SELECTARG1 | D3DTEXOPCAPS_BUMPENVMAP | D3DTEXOPCAPS_MODULATE
21096 | D3DTEXOPCAPS_ADD,
21097 0x80ff0000,
21100 TEXTURE_BUMPMAP,
21102 {D3DTSS_COLOROP, D3DTOP_BUMPENVMAP},
21103 {D3DTSS_BUMPENVMAT00, *(DWORD *)&bumpenvmat[0]},
21104 {D3DTSS_BUMPENVMAT01, *(DWORD *)&bumpenvmat[1]},
21105 {D3DTSS_BUMPENVMAT10, *(DWORD *)&bumpenvmat[2]},
21106 {D3DTSS_BUMPENVMAT11, *(DWORD *)&bumpenvmat[3]},
21107 {D3DTSS_ALPHAOP, D3DTOP_ADD},
21108 {D3DTSS_ALPHAARG1, D3DTA_DIFFUSE},
21109 {D3DTSS_ALPHAARG2, D3DTA_CONSTANT},
21110 {D3DTSS_CONSTANT, 0x0fffffff},
21111 STATE_END(),
21115 TEXTURE_RED,
21117 {D3DTSS_COLOROP, D3DTOP_MODULATE},
21118 {D3DTSS_COLORARG1, D3DTA_TEXTURE},
21119 {D3DTSS_COLORARG2, D3DTA_CURRENT},
21120 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21121 {D3DTSS_ALPHAARG1, D3DTA_CURRENT},
21122 STATE_END(),
21125 {TEXTURE_INVALID}
21129 D3DTEXOPCAPS_DISABLE | D3DTEXOPCAPS_SELECTARG1 | D3DTEXOPCAPS_BUMPENVMAP | D3DTEXOPCAPS_MODULATE
21130 | D3DTEXOPCAPS_MODULATE2X,
21131 0x80ff0000,
21134 TEXTURE_BUMPMAP,
21136 {D3DTSS_COLOROP, D3DTOP_BUMPENVMAP},
21137 {D3DTSS_BUMPENVMAT00, *(DWORD *)&bumpenvmat[0]},
21138 {D3DTSS_BUMPENVMAT01, *(DWORD *)&bumpenvmat[1]},
21139 {D3DTSS_BUMPENVMAT10, *(DWORD *)&bumpenvmat[2]},
21140 {D3DTSS_BUMPENVMAT11, *(DWORD *)&bumpenvmat[3]},
21141 {D3DTSS_ALPHAOP, D3DTOP_MODULATE2X},
21142 {D3DTSS_ALPHAARG1, D3DTA_DIFFUSE},
21143 {D3DTSS_ALPHAARG2, D3DTA_CONSTANT},
21144 {D3DTSS_CONSTANT, 0x01ffffff},
21145 STATE_END(),
21149 TEXTURE_RED,
21151 {D3DTSS_COLOROP, D3DTOP_MODULATE},
21152 {D3DTSS_COLORARG1, D3DTA_TEXTURE},
21153 {D3DTSS_COLORARG2, D3DTA_CURRENT},
21154 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21155 {D3DTSS_ALPHAARG1, D3DTA_CURRENT},
21156 STATE_END(),
21159 {TEXTURE_INVALID}
21163 D3DTEXOPCAPS_DISABLE | D3DTEXOPCAPS_SELECTARG1 | D3DTEXOPCAPS_BUMPENVMAP | D3DTEXOPCAPS_MODULATE
21164 | D3DTEXOPCAPS_MODULATE2X,
21165 0x80ffff00,
21168 TEXTURE_BUMPMAP,
21170 {D3DTSS_COLOROP, D3DTOP_BUMPENVMAP},
21171 {D3DTSS_BUMPENVMAT00, *(DWORD *)&bumpenvmat[0]},
21172 {D3DTSS_BUMPENVMAT01, *(DWORD *)&bumpenvmat[1]},
21173 {D3DTSS_BUMPENVMAT10, *(DWORD *)&bumpenvmat[2]},
21174 {D3DTSS_BUMPENVMAT11, *(DWORD *)&bumpenvmat[3]},
21175 {D3DTSS_ALPHAOP, D3DTOP_MODULATE2X},
21176 {D3DTSS_ALPHAARG1, D3DTA_CURRENT},
21177 {D3DTSS_ALPHAARG2, D3DTA_CONSTANT},
21178 {D3DTSS_CONSTANT, 0x01ffffff},
21179 STATE_END(),
21183 TEXTURE_RED,
21185 {D3DTSS_COLOROP, D3DTOP_MODULATE},
21186 {D3DTSS_COLORARG1, D3DTA_CURRENT},
21187 {D3DTSS_COLORARG2, D3DTA_CURRENT},
21188 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21189 {D3DTSS_ALPHAARG1, D3DTA_CURRENT},
21190 {D3DTSS_ALPHAARG2, D3DTA_CONSTANT},
21191 {D3DTSS_ALPHAARG0, D3DTA_CONSTANT},
21192 STATE_END(),
21195 {TEXTURE_INVALID}
21199 D3DTEXOPCAPS_DISABLE | D3DTEXOPCAPS_SELECTARG1 | D3DTEXOPCAPS_BUMPENVMAP,
21200 0x01234567,
21203 TEXTURE_NONE,
21205 {D3DTSS_COLOROP, D3DTOP_SELECTARG1},
21206 {D3DTSS_COLORARG1, D3DTA_CONSTANT},
21207 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21208 {D3DTSS_ALPHAARG1, D3DTA_CONSTANT},
21209 {D3DTSS_RESULTARG, D3DTA_TEMP},
21210 {D3DTSS_CONSTANT, 0x01234567},
21211 STATE_END(),
21215 TEXTURE_BUMPMAP,
21217 {D3DTSS_COLOROP, D3DTOP_BUMPENVMAP},
21218 {D3DTSS_BUMPENVMAT00, *(DWORD *)&bumpenvmat[0]},
21219 {D3DTSS_BUMPENVMAT01, *(DWORD *)&bumpenvmat[1]},
21220 {D3DTSS_BUMPENVMAT10, *(DWORD *)&bumpenvmat[2]},
21221 {D3DTSS_BUMPENVMAT11, *(DWORD *)&bumpenvmat[3]},
21222 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21223 {D3DTSS_ALPHAARG1, D3DTA_TEMP},
21224 {D3DTSS_RESULTARG, D3DTA_TEMP},
21225 STATE_END(),
21229 TEXTURE_RED,
21231 {D3DTSS_COLOROP, D3DTOP_SELECTARG1},
21232 {D3DTSS_COLORARG1, D3DTA_TEXTURE},
21233 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21234 {D3DTSS_ALPHAARG1, D3DTA_TEXTURE},
21235 STATE_END(),
21239 TEXTURE_NONE,
21241 {D3DTSS_COLOROP, D3DTOP_SELECTARG1},
21242 {D3DTSS_COLORARG1, D3DTA_TEMP},
21243 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21244 {D3DTSS_ALPHAARG1, D3DTA_TEMP},
21245 STATE_END(),
21248 {TEXTURE_INVALID}
21252 D3DTEXOPCAPS_DISABLE | D3DTEXOPCAPS_SELECTARG1 | D3DTEXOPCAPS_BUMPENVMAP,
21253 0x00234567,
21256 TEXTURE_NONE,
21258 {D3DTSS_COLOROP, D3DTOP_SELECTARG1},
21259 {D3DTSS_COLORARG1, D3DTA_CONSTANT},
21260 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21261 {D3DTSS_ALPHAARG1, D3DTA_CONSTANT},
21262 {D3DTSS_RESULTARG, D3DTA_TEMP},
21263 {D3DTSS_CONSTANT, 0x01234567},
21264 STATE_END(),
21268 TEXTURE_BUMPMAP,
21270 {D3DTSS_COLOROP, D3DTOP_BUMPENVMAP},
21271 {D3DTSS_BUMPENVMAT00, *(DWORD *)&bumpenvmat[0]},
21272 {D3DTSS_BUMPENVMAT01, *(DWORD *)&bumpenvmat[1]},
21273 {D3DTSS_BUMPENVMAT10, *(DWORD *)&bumpenvmat[2]},
21274 {D3DTSS_BUMPENVMAT11, *(DWORD *)&bumpenvmat[3]},
21275 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21276 {D3DTSS_ALPHAARG1, D3DTA_TEMP},
21277 STATE_END(),
21281 TEXTURE_RED,
21283 {D3DTSS_COLOROP, D3DTOP_SELECTARG1},
21284 {D3DTSS_COLORARG1, D3DTA_TEXTURE},
21285 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21286 {D3DTSS_ALPHAARG1, D3DTA_TEXTURE},
21287 STATE_END(),
21291 TEXTURE_NONE,
21293 {D3DTSS_COLOROP, D3DTOP_SELECTARG1},
21294 {D3DTSS_COLORARG1, D3DTA_TEMP},
21295 STATE_END(),
21298 {TEXTURE_INVALID}
21302 D3DTEXOPCAPS_DISABLE | D3DTEXOPCAPS_SELECTARG1 | D3DTEXOPCAPS_BUMPENVMAP,
21303 0x01234567,
21306 TEXTURE_NONE,
21308 {D3DTSS_COLOROP, D3DTOP_SELECTARG1},
21309 {D3DTSS_COLORARG1, D3DTA_CONSTANT},
21310 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21311 {D3DTSS_ALPHAARG1, D3DTA_CONSTANT},
21312 {D3DTSS_RESULTARG, D3DTA_TEMP},
21313 {D3DTSS_CONSTANT, 0x01234567},
21314 STATE_END(),
21318 TEXTURE_BUMPMAP,
21320 {D3DTSS_COLOROP, D3DTOP_BUMPENVMAP},
21321 {D3DTSS_BUMPENVMAT00, *(DWORD *)&bumpenvmat[0]},
21322 {D3DTSS_BUMPENVMAT01, *(DWORD *)&bumpenvmat[1]},
21323 {D3DTSS_BUMPENVMAT10, *(DWORD *)&bumpenvmat[2]},
21324 {D3DTSS_BUMPENVMAT11, *(DWORD *)&bumpenvmat[3]},
21325 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21326 {D3DTSS_ALPHAARG1, D3DTA_TEMP},
21327 {D3DTSS_RESULTARG, D3DTA_TEMP},
21328 STATE_END(),
21332 TEXTURE_RED,
21334 {D3DTSS_COLOROP, D3DTOP_SELECTARG1},
21335 {D3DTSS_COLORARG1, D3DTA_TEXTURE},
21336 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21337 {D3DTSS_ALPHAARG1, D3DTA_TEXTURE},
21338 STATE_END(),
21342 TEXTURE_NONE,
21344 {D3DTSS_COLOROP, D3DTOP_SELECTARG1},
21345 {D3DTSS_COLORARG1, D3DTA_TEMP},
21346 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21347 {D3DTSS_ALPHAARG1, D3DTA_TEMP},
21348 STATE_END(),
21351 {TEXTURE_INVALID}
21355 D3DTEXOPCAPS_DISABLE | D3DTEXOPCAPS_SELECTARG1 | D3DTEXOPCAPS_BUMPENVMAP,
21356 0x01234567,
21359 TEXTURE_NONE,
21361 {D3DTSS_COLOROP, D3DTOP_SELECTARG1},
21362 {D3DTSS_COLORARG1, D3DTA_CONSTANT},
21363 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21364 {D3DTSS_ALPHAARG1, D3DTA_CONSTANT},
21365 {D3DTSS_RESULTARG, D3DTA_CURRENT},
21366 {D3DTSS_CONSTANT, 0x01234567},
21367 STATE_END(),
21371 TEXTURE_BUMPMAP,
21373 {D3DTSS_COLOROP, D3DTOP_BUMPENVMAP},
21374 {D3DTSS_BUMPENVMAT00, *(DWORD *)&bumpenvmat[0]},
21375 {D3DTSS_BUMPENVMAT01, *(DWORD *)&bumpenvmat[1]},
21376 {D3DTSS_BUMPENVMAT10, *(DWORD *)&bumpenvmat[2]},
21377 {D3DTSS_BUMPENVMAT11, *(DWORD *)&bumpenvmat[3]},
21378 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21379 {D3DTSS_ALPHAARG1, D3DTA_TEMP},
21380 {D3DTSS_RESULTARG, D3DTA_TEMP},
21381 STATE_END(),
21385 TEXTURE_RED,
21387 {D3DTSS_COLOROP, D3DTOP_SELECTARG1},
21388 {D3DTSS_COLORARG1, D3DTA_TEXTURE},
21389 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21390 {D3DTSS_ALPHAARG1, D3DTA_TEXTURE},
21391 {D3DTSS_RESULTARG, D3DTA_TEMP},
21392 STATE_END(),
21396 TEXTURE_NONE,
21398 {D3DTSS_COLOROP, D3DTOP_SELECTARG1},
21399 {D3DTSS_COLORARG1, D3DTA_CURRENT},
21400 {D3DTSS_ALPHAOP, D3DTOP_SELECTARG1},
21401 {D3DTSS_ALPHAARG1, D3DTA_CURRENT},
21402 {D3DTSS_RESULTARG, D3DTA_CURRENT},
21403 STATE_END(),
21406 {TEXTURE_INVALID}
21411 window = create_window();
21412 d3d = Direct3DCreate9(D3D_SDK_VERSION);
21413 ok(!!d3d, "Failed to create a D3D object.\n");
21414 if (!(device = create_device(d3d, window, window, TRUE)))
21416 skip("Failed to create a D3D device.\n");
21417 goto done;
21420 memset(&caps, 0, sizeof(caps));
21421 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
21422 ok(hr == D3D_OK, "IDirect3DDevice9_GetDeviceCaps failed hr %#x.\n", hr);
21424 if(!(caps.PrimitiveMiscCaps & D3DPMISCCAPS_TSSARGTEMP))
21426 skip("D3DPMISCCAPS_TSSARGTEMP not supported.\n");
21427 IDirect3DDevice9_Release(device);
21428 goto done;
21431 if (!(caps.PrimitiveMiscCaps & D3DPMISCCAPS_PERSTAGECONSTANT))
21433 skip("D3DPMISCCAPS_PERSTAGECONSTANT not supported.\n");
21434 IDirect3DDevice9_Release(device);
21435 goto done;
21438 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL,
21439 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, D3DFMT_V8U8)))
21441 skip("D3DFMT_V8U8 not supported for legacy bump mapping.\n");
21442 IDirect3DDevice9_Release(device);
21443 goto done;
21446 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
21447 ok(hr == D3D_OK, "Can't get back buffer, hr %#x.\n", hr);
21449 hr = IDirect3DDevice9_CreateTexture(device, 1, 1, 1, 0, D3DFMT_V8U8, D3DPOOL_MANAGED, &texture_bumpmap, NULL);
21450 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture failed, hr %#x.\n", hr);
21451 hr = IDirect3DDevice9_CreateTexture(device, 1, 1, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture_red, NULL);
21452 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture failed, hr %#x.\n", hr);
21454 memset(&locked_rect, 0, sizeof(locked_rect));
21455 hr = IDirect3DTexture9_LockRect(texture_bumpmap, 0, &locked_rect, NULL, 0);
21456 ok(SUCCEEDED(hr), "LockRect failed, hr %#x.\n", hr);
21457 *((WORD *)locked_rect.pBits) = 0xff00;
21458 hr = IDirect3DTexture9_UnlockRect(texture_bumpmap, 0);
21459 ok(SUCCEEDED(hr), "UnlockRect failed, hr %#x.\n", hr);
21461 memset(&locked_rect, 0, sizeof(locked_rect));
21462 hr = IDirect3DTexture9_LockRect(texture_red, 0, &locked_rect, NULL, 0);
21463 ok(SUCCEEDED(hr), "LockRect failed, hr %#x.\n", hr);
21464 *((DWORD *)locked_rect.pBits) = 0x00ff0000;
21465 hr = IDirect3DTexture9_UnlockRect(texture_red, 0);
21466 ok(SUCCEEDED(hr), "UnlockRect failed, hr %#x.\n", hr);
21468 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
21469 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
21470 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
21471 ok(hr == D3D_OK, "Failed to disable lighting, hr %#x.\n", hr);
21473 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
21475 const struct test *current_test = &tests[i];
21477 if ((caps.TextureOpCaps & current_test->tex_op_caps) != current_test->tex_op_caps)
21479 skip("Texture operations %#x not supported.\n", current_test->tex_op_caps);
21480 continue;
21483 for (j = 0; j < caps.MaxTextureBlendStages; ++j)
21485 IDirect3DTexture9 *current_texture = NULL;
21487 for (k = 0; !IS_STATE_END(default_stage_state.state[k]); ++k)
21489 hr = IDirect3DDevice9_SetTextureStageState(device, j,
21490 default_stage_state.state[k].name, default_stage_state.state[k].value);
21491 ok(SUCCEEDED(hr), "Test %u: SetTextureStageState failed, hr %#x.\n", i, hr);
21494 if (current_test->stage[j].texture != TEXTURE_INVALID)
21496 const struct texture_stage_state *current_state = current_test->stage[j].state;
21498 switch (current_test->stage[j].texture)
21500 case TEXTURE_RED:
21501 current_texture = texture_red;
21502 break;
21503 case TEXTURE_BUMPMAP:
21504 current_texture = texture_bumpmap;
21505 break;
21506 default:
21507 current_texture = NULL;
21508 break;
21511 for (k = 0; !IS_STATE_END(current_state[k]); ++k)
21513 hr = IDirect3DDevice9_SetTextureStageState(device, j,
21514 current_state[k].name, current_state[k].value);
21515 ok(SUCCEEDED(hr), "Test %u: SetTextureStageState failed, hr %#x.\n", i, hr);
21519 hr = IDirect3DDevice9_SetTexture(device, j, (IDirect3DBaseTexture9 *)current_texture);
21520 ok(SUCCEEDED(hr), "Test %u: SetTexture failed, hr %#x.\n", i, hr);
21523 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 1.0f, 0);
21524 ok(hr == D3D_OK, "Test %u: IDirect3DDevice9_Clear failed, hr %#x.\n", i, hr);
21526 hr = IDirect3DDevice9_BeginScene(device);
21527 ok(SUCCEEDED(hr), "Test %u: BeginScene failed, hr %#x.\n", i, hr);
21528 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], sizeof(quad[0]));
21529 ok(SUCCEEDED(hr), "Test %u: DrawPrimitiveUP failed, hr %#x.\n", i, hr);
21530 hr = IDirect3DDevice9_EndScene(device);
21531 ok(SUCCEEDED(hr), "Test %u: EndScene failed, hr %#x.\n", i, hr);
21533 get_rt_readback(backbuffer, &rb);
21534 color = get_readback_color(&rb, 320, 240);
21535 ok(color_match(color, current_test->expected_color, 1),
21536 "Test %u: Got color 0x%08x, expected 0x%08x.\n", i, color, current_test->expected_color);
21537 release_surface_readback(&rb);
21538 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
21539 ok(SUCCEEDED(hr), "Test %u: Present failed, hr %#x.\n", i, hr);
21542 IDirect3DTexture9_Release(texture_bumpmap);
21543 IDirect3DTexture9_Release(texture_red);
21544 IDirect3DSurface9_Release(backbuffer);
21545 refcount = IDirect3DDevice9_Release(device);
21546 ok(!refcount, "Device has %u references left.\n", refcount);
21547 done:
21548 IDirect3D9_Release(d3d);
21549 DestroyWindow(window);
21552 static void test_color_clamping(void)
21554 static const D3DMATRIX mat =
21556 1.0f, 0.0f, 0.0f, 0.0f,
21557 0.0f, 1.0f, 0.0f, 0.0f,
21558 0.0f, 0.0f, 1.0f, 0.0f,
21559 0.0f, 0.0f, 0.0f, 1.0f,
21560 }}};
21561 static const struct vec3 quad[] =
21563 {-1.0f, -1.0f, 0.1f},
21564 {-1.0f, 1.0f, 0.1f},
21565 { 1.0f, -1.0f, 0.1f},
21566 { 1.0f, 1.0f, 0.1f},
21568 static const DWORD vs1_code[] =
21570 0xfffe0101, /* vs_1_1 */
21571 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
21572 0x00000051, 0xa00f0000, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c0, 1.0, 1.0, 1.0, 1.0 */
21573 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
21574 0x00000002, 0xd00f0000, 0xa0e40000, 0xa0e40000, /* add oD0, c0, c0 */
21575 0x00000002, 0xd00f0001, 0xa0e40000, 0xa0e40000, /* add oD1, c0, c0 */
21576 0x0000ffff
21578 static const DWORD vs2_code[] =
21580 0xfffe0200, /* vs_2_0 */
21581 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
21582 0x05000051, 0xa00f0000, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c0, 1.0, 1.0, 1.0, 1.0 */
21583 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
21584 0x03000002, 0xd00f0000, 0xa0e40000, 0xa0e40000, /* add oD0, c0, c0 */
21585 0x03000002, 0xd00f0001, 0xa0e40000, 0xa0e40000, /* add oD1, c0, c0 */
21586 0x0000ffff
21588 static const DWORD vs3_code[] =
21590 0xfffe0300, /* vs_3_0 */
21591 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
21592 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
21593 0x0200001f, 0x8000000a, 0xe00f0001, /* dcl_color0 o1 */
21594 0x0200001f, 0x8001000a, 0xe00f0002, /* dcl_color1 o2 */
21595 0x05000051, 0xa00f0000, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c0, 1.0, 1.0, 1.0, 1.0 */
21596 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
21597 0x03000002, 0xe00f0001, 0xa0e40000, 0xa0e40000, /* add o1, c0, c0 */
21598 0x03000002, 0xe00f0002, 0xa0e40000, 0xa0e40000, /* add o2, c0, c0 */
21599 0x0000ffff
21601 static const DWORD ps1_code[] =
21603 0xffff0101, /* ps_1_1 */
21604 0x00000051, 0xa00f0000, 0x3e800000, 0x3e800000, 0x3e800000, 0x3e800000, /* def c0, 0.25, 0.25, 0.25, 0.25 */
21605 0x00000002, 0x800f0000, 0x90e40000, 0x90e40001, /* add r0, v0, v1 */
21606 0x00000005, 0x800f0000, 0x80e40000, 0xa0e40000, /* mul r0, r0, c0 */
21607 0x0000ffff
21609 static const DWORD ps2_code[] =
21611 0xffff0200, /* ps_2_0 */
21612 0x0200001f, 0x80000000, 0x900f0000, /* dcl v0 */
21613 0x0200001f, 0x80000000, 0x900f0001, /* dcl v1 */
21614 0x05000051, 0xa00f0000, 0x3e800000, 0x3e800000, 0x3e800000, 0x3e800000, /* def c0, 0.25, 0.25, 0.25, 0.25 */
21615 0x02000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
21616 0x03000002, 0x800f0000, 0x80e40000, 0x90e40001, /* add r0, r0, v1 */
21617 0x03000005, 0x800f0000, 0x80e40000, 0xa0e40000, /* mul r0, r0, c0 */
21618 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
21619 0x0000ffff
21621 static const DWORD ps3_code[] =
21623 0xffff0300, /* ps_3_0 */
21624 0x0200001f, 0x8000000a, 0x900f0000, /* dcl_color0 v0 */
21625 0x0200001f, 0x8001000a, 0x900f0001, /* dcl_color1 v1 */
21626 0x05000051, 0xa00f0000, 0x3e800000, 0x3e800000, 0x3e800000, 0x3e800000, /* def c0, 0.25, 0.25, 0.25, 0.25 */
21627 0x02000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
21628 0x03000002, 0x800f0000, 0x80e40000, 0x90e40001, /* add r0, r0, v1 */
21629 0x03000005, 0x800f0800, 0x80e40000, 0xa0e40000, /* mul oC0, r0, c0 */
21630 0x0000ffff
21632 static const struct
21634 DWORD vs_version;
21635 const DWORD *vs;
21636 DWORD ps_version;
21637 const DWORD *ps;
21638 D3DCOLOR expected, broken;
21640 tests[] =
21642 {0, NULL, 0, NULL, 0x00404040},
21643 {0, NULL, D3DPS_VERSION(1, 1), ps1_code, 0x00404040, 0x00808080},
21644 {D3DVS_VERSION(1, 1), vs1_code, 0, NULL, 0x00404040},
21645 {D3DVS_VERSION(1, 1), vs1_code, D3DPS_VERSION(1, 1), ps1_code, 0x007f7f7f},
21646 {D3DVS_VERSION(2, 0), vs2_code, D3DPS_VERSION(2, 0), ps2_code, 0x007f7f7f},
21647 {D3DVS_VERSION(3, 0), vs3_code, D3DPS_VERSION(3, 0), ps3_code, 0x00ffffff},
21649 IDirect3DVertexShader9 *vs;
21650 IDirect3DPixelShader9 *ps;
21651 IDirect3DDevice9 *device;
21652 IDirect3D9 *d3d9;
21653 unsigned int i;
21654 ULONG refcount;
21655 D3DCOLOR color;
21656 D3DCAPS9 caps;
21657 HWND window;
21658 HRESULT hr;
21660 window = create_window();
21661 d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
21662 ok(!!d3d9, "Failed to create a D3D object.\n");
21663 if (!(device = create_device(d3d9, window, window, TRUE)))
21665 skip("Failed to create a D3D device, skipping tests.\n");
21666 IDirect3D9_Release(d3d9);
21667 DestroyWindow(window);
21668 return;
21671 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
21672 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
21674 hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLD, &mat);
21675 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
21676 hr = IDirect3DDevice9_SetTransform(device, D3DTS_VIEW, &mat);
21677 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
21678 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &mat);
21679 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
21680 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, FALSE);
21681 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
21682 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
21683 ok(SUCCEEDED(hr), "Failed to disable Z test, hr %#x.\n", hr);
21684 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGENABLE, FALSE);
21685 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
21686 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILENABLE, FALSE);
21687 ok(SUCCEEDED(hr), "Failed to disable stencil test, hr %#x.\n", hr);
21688 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE);
21689 ok(SUCCEEDED(hr), "Failed to disable culling, hr %#x.\n", hr);
21690 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
21691 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
21693 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0xff404040);
21694 ok(SUCCEEDED(hr), "Failed to set texture factor, hr %#x.\n", hr);
21695 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_ADD);
21696 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
21697 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
21698 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
21699 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_SPECULAR);
21700 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
21701 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_MODULATE);
21702 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
21703 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_TFACTOR);
21704 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
21705 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_CURRENT);
21706 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
21708 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
21709 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
21711 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
21713 if (caps.VertexShaderVersion < tests[i].vs_version
21714 || caps.PixelShaderVersion < tests[i].ps_version)
21716 skip("Vertex / pixel shader version not supported, skipping test %u.\n", i);
21717 continue;
21719 if (tests[i].vs)
21721 hr = IDirect3DDevice9_CreateVertexShader(device, tests[i].vs, &vs);
21722 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x (case %u).\n", hr, i);
21724 else
21726 vs = NULL;
21728 if (tests[i].ps)
21730 hr = IDirect3DDevice9_CreatePixelShader(device, tests[i].ps, &ps);
21731 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x (case %u).\n", hr, i);
21733 else
21735 ps = NULL;
21738 hr = IDirect3DDevice9_SetVertexShader(device, vs);
21739 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
21740 hr = IDirect3DDevice9_SetPixelShader(device, ps);
21741 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
21743 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
21744 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
21746 hr = IDirect3DDevice9_BeginScene(device);
21747 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
21749 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
21750 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
21752 hr = IDirect3DDevice9_EndScene(device);
21753 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
21755 color = getPixelColor(device, 320, 240);
21756 ok(color_match(color, tests[i].expected, 1) || broken(color_match(color, tests[i].broken, 1)),
21757 "Got unexpected color 0x%08x, case %u.\n", color, i);
21759 if (vs)
21760 IDirect3DVertexShader9_Release(vs);
21761 if (ps)
21762 IDirect3DVertexShader9_Release(ps);
21765 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
21766 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
21768 refcount = IDirect3DDevice9_Release(device);
21769 ok(!refcount, "Device has %u references left.\n", refcount);
21770 IDirect3D9_Release(d3d9);
21771 DestroyWindow(window);
21774 static void test_line_antialiasing_blending(void)
21776 IDirect3DDevice9 *device;
21777 IDirect3D9 *d3d9;
21778 ULONG refcount;
21779 D3DCOLOR color;
21780 D3DCAPS9 caps;
21781 HWND window;
21782 HRESULT hr;
21784 static const struct
21786 struct vec3 position;
21787 DWORD diffuse;
21789 green_quad[] =
21791 {{-1.0f, -1.0f, 0.1f}, D3DCOLOR_ARGB(0x7f, 0x00, 0xff, 0x00)},
21792 {{-1.0f, 1.0f, 0.1f}, D3DCOLOR_ARGB(0x7f, 0x00, 0xff, 0x00)},
21793 {{ 1.0f, -1.0f, 0.1f}, D3DCOLOR_ARGB(0x7f, 0x00, 0xff, 0x00)},
21794 {{ 1.0f, 1.0f, 0.1f}, D3DCOLOR_ARGB(0x7f, 0x00, 0xff, 0x00)},
21796 static const struct
21798 struct vec3 position;
21799 DWORD diffuse;
21801 red_quad[] =
21803 {{-1.0f, -1.0f, 0.1f}, D3DCOLOR_ARGB(0xcc, 0xff, 0x00, 0x00)},
21804 {{-1.0f, 1.0f, 0.1f}, D3DCOLOR_ARGB(0xcc, 0xff, 0x00, 0x00)},
21805 {{ 1.0f, -1.0f, 0.1f}, D3DCOLOR_ARGB(0xcc, 0xff, 0x00, 0x00)},
21806 {{ 1.0f, 1.0f, 0.1f}, D3DCOLOR_ARGB(0xcc, 0xff, 0x00, 0x00)},
21809 window = create_window();
21810 d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
21811 ok(!!d3d9, "Failed to create a D3D object.\n");
21812 if (!(device = create_device(d3d9, window, window, TRUE)))
21814 skip("Failed to create a D3D device.\n");
21815 IDirect3D9_Release(d3d9);
21816 DestroyWindow(window);
21817 return;
21820 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
21821 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
21822 trace("Line antialiasing support: %#x.\n", caps.LineCaps & D3DLINECAPS_ANTIALIAS);
21824 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, FALSE);
21825 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
21826 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
21827 ok(SUCCEEDED(hr), "Failed to disable Z test, hr %#x.\n", hr);
21828 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
21829 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
21831 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHABLENDENABLE, TRUE);
21832 ok(SUCCEEDED(hr), "Failed to enable blending, hr %#x.\n", hr);
21833 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_BLENDOP, D3DBLENDOP_ADD);
21834 ok(SUCCEEDED(hr), "Failed to set blend op, hr %#x.\n", hr);
21835 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
21836 ok(SUCCEEDED(hr), "Failed to set src blend, hr %#x.\n", hr);
21837 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_DESTALPHA);
21838 ok(SUCCEEDED(hr), "Failed to set dest blend, hr %#x.\n", hr);
21840 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
21841 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
21842 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
21843 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
21844 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
21845 ok(SUCCEEDED(hr), "Failed to set alpha op, hr %#x.\n", hr);
21846 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
21847 ok(SUCCEEDED(hr), "Failed to set alpha arg, hr %#x.\n", hr);
21849 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
21850 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
21852 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xccff0000, 0.0f, 0);
21853 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
21854 hr = IDirect3DDevice9_BeginScene(device);
21855 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
21856 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, green_quad, sizeof(*green_quad));
21857 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
21858 hr = IDirect3DDevice9_EndScene(device);
21859 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
21860 color = getPixelColor(device, 320, 240);
21861 ok(color_match(color, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color);
21863 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x7f00ff00, 0.0f, 0);
21864 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
21865 hr = IDirect3DDevice9_BeginScene(device);
21866 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
21867 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, red_quad, sizeof(*red_quad));
21868 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
21869 hr = IDirect3DDevice9_EndScene(device);
21870 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
21871 color = getPixelColor(device, 320, 240);
21872 ok(color_match(color, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color);
21874 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHABLENDENABLE, FALSE);
21875 ok(SUCCEEDED(hr), "Failed to disable blending, hr %#x.\n", hr);
21877 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xccff0000, 0.0f, 0);
21878 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
21879 hr = IDirect3DDevice9_BeginScene(device);
21880 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
21881 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, green_quad, sizeof(*green_quad));
21882 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
21883 hr = IDirect3DDevice9_EndScene(device);
21884 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
21885 color = getPixelColor(device, 320, 240);
21886 ok(color_match(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
21888 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x7f00ff00, 0.0f, 0);
21889 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
21890 hr = IDirect3DDevice9_BeginScene(device);
21891 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
21892 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, red_quad, sizeof(*red_quad));
21893 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
21894 hr = IDirect3DDevice9_EndScene(device);
21895 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
21896 color = getPixelColor(device, 320, 240);
21897 ok(color_match(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
21899 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ANTIALIASEDLINEENABLE, TRUE);
21900 ok(SUCCEEDED(hr), "Failed to enable line antialiasing, hr %#x.\n", hr);
21902 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xccff0000, 0.0f, 0);
21903 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
21904 hr = IDirect3DDevice9_BeginScene(device);
21905 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
21906 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, green_quad, sizeof(*green_quad));
21907 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
21908 hr = IDirect3DDevice9_EndScene(device);
21909 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
21910 color = getPixelColor(device, 320, 240);
21911 ok(color_match(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
21913 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x7f00ff00, 0.0f, 0);
21914 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
21915 hr = IDirect3DDevice9_BeginScene(device);
21916 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
21917 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, red_quad, sizeof(*red_quad));
21918 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
21919 hr = IDirect3DDevice9_EndScene(device);
21920 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
21921 color = getPixelColor(device, 320, 240);
21922 ok(color_match(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
21924 refcount = IDirect3DDevice9_Release(device);
21925 ok(!refcount, "Device has %u references left.\n", refcount);
21926 IDirect3D9_Release(d3d9);
21927 DestroyWindow(window);
21930 static void test_dsy(void)
21932 static const DWORD vs_code[] =
21934 0xfffe0300, /* vs_3_0 */
21935 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
21936 0x0200001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
21937 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
21938 0x0200001f, 0x8000000a, 0xe00f0001, /* dcl_color0 o1 */
21939 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
21940 0x02000001, 0xe00f0001, 0x90e40001, /* mov o1, v1 */
21941 0x0000ffff
21943 static const DWORD ps_code[] =
21945 0xffff0300, /* ps_3_0 */
21946 0x0200001f, 0x8000000a, 0x900f0000, /* dcl_color0 v0 */
21947 0x05000051, 0xa00f0000, 0x43700000, 0x3f000000, 0x00000000, 0x00000000, /* def c0, 240.0, 0.5, 0.0, 0.0 */
21948 0x0200005c, 0x800f0000, 0x90e40000, /* dsy r0, v0 */
21949 0x03000005, 0x800f0000, 0x80e40000, 0xa0000000, /* mul r0, r0, c0.x */
21950 0x03000002, 0x800f0800, 0x80e40000, 0xa0550000, /* add oC0, r0, c0.y */
21951 0x0000ffff
21953 static const struct
21955 struct vec3 pos;
21956 D3DCOLOR color;
21958 quad[] =
21960 {{-1.0f, -1.0f, 0.1f}, 0x00ff0000},
21961 {{-1.0f, 1.0f, 0.1f}, 0x0000ff00},
21962 {{ 1.0f, -1.0f, 0.1f}, 0x00ff0000},
21963 {{ 1.0f, 1.0f, 0.1f}, 0x0000ff00},
21965 IDirect3DSurface9 *backbuffer, *rt;
21966 IDirect3DVertexShader9 *vs;
21967 IDirect3DPixelShader9 *ps;
21968 IDirect3DDevice9 *device;
21969 IDirect3D9 *d3d;
21970 ULONG refcount;
21971 D3DCAPS9 caps;
21972 DWORD color;
21973 HWND window;
21974 HRESULT hr;
21976 window = create_window();
21977 d3d = Direct3DCreate9(D3D_SDK_VERSION);
21978 ok(!!d3d, "Failed to create a D3D object.\n");
21979 if (!(device = create_device(d3d, window, window, TRUE)))
21981 skip("Failed to create a D3D device, skipping tests.\n");
21982 goto done;
21985 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
21986 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
21987 if (caps.PixelShaderVersion < D3DPS_VERSION(3, 0))
21989 skip("No ps_3_0 support, skipping dsy tests.\n");
21990 IDirect3DDevice9_Release(device);
21991 goto done;
21994 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
21995 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
21997 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
21998 D3DMULTISAMPLE_NONE, 0, FALSE, &rt, NULL);
21999 ok(SUCCEEDED(hr), "Failed to create offscreen render target, hr %#x.\n", hr);
22000 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
22001 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
22003 hr = IDirect3DDevice9_CreateVertexShader(device, vs_code, &vs);
22004 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
22005 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code, &ps);
22006 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22008 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
22009 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
22010 hr = IDirect3DDevice9_SetVertexShader(device, vs);
22011 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
22012 hr = IDirect3DDevice9_SetPixelShader(device, ps);
22013 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
22015 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff000000, 1.0f, 0);
22016 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
22017 hr = IDirect3DDevice9_BeginScene(device);
22018 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
22019 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
22020 ok(SUCCEEDED(hr), "Failed to draw primitive, hr %#x.\n", hr);
22021 hr = IDirect3DDevice9_EndScene(device);
22022 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
22024 color = getPixelColor(device, 360, 240);
22025 ok(color_match(color, 0x00ff007f, 1), "Got unexpected color 0x%08x.\n", color);
22027 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
22028 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
22030 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff000000, 1.0f, 0);
22031 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
22032 hr = IDirect3DDevice9_BeginScene(device);
22033 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
22034 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
22035 ok(SUCCEEDED(hr), "Failed to draw primitive, hr %#x.\n", hr);
22036 hr = IDirect3DDevice9_EndScene(device);
22037 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
22039 color = getPixelColor(device, 360, 240);
22040 ok(color_match(color, 0x00ff007f, 1), "Got unexpected color 0x%08x.\n", color);
22042 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
22043 ok(SUCCEEDED(hr), "Failed to present frame, hr %#x.\n", hr);
22045 IDirect3DSurface9_Release(rt);
22046 IDirect3DSurface9_Release(backbuffer);
22047 IDirect3DVertexShader9_Release(vs);
22048 IDirect3DPixelShader9_Release(ps);
22050 refcount = IDirect3DDevice9_Release(device);
22051 ok(!refcount, "Device has %u references left.\n", refcount);
22052 done:
22053 IDirect3D9_Release(d3d);
22054 DestroyWindow(window);
22057 static void test_evict_bound_resources(void)
22059 IDirect3DVertexBuffer9 *vb;
22060 IDirect3DIndexBuffer9 *ib;
22061 IDirect3DDevice9 *device;
22062 IDirect3D9 *d3d9;
22063 ULONG refcount;
22064 D3DCOLOR color;
22065 HWND window;
22066 void *data;
22067 HRESULT hr;
22069 static const struct
22071 struct vec3 position;
22072 DWORD diffuse;
22074 green_quad[] =
22076 {{-1.0f, -1.0f, 0.1f}, D3DCOLOR_ARGB(0x7f, 0x00, 0xff, 0x00)},
22077 {{-1.0f, 1.0f, 0.1f}, D3DCOLOR_ARGB(0x7f, 0x00, 0xff, 0x00)},
22078 {{ 1.0f, -1.0f, 0.1f}, D3DCOLOR_ARGB(0x7f, 0x00, 0xff, 0x00)},
22079 {{ 1.0f, 1.0f, 0.1f}, D3DCOLOR_ARGB(0x7f, 0x00, 0xff, 0x00)},
22081 static const unsigned short indices[] = {0, 1, 2, 3, 2, 1};
22083 window = create_window();
22084 d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
22085 ok(!!d3d9, "Failed to create a D3D object.\n");
22087 if (!(device = create_device(d3d9, window, window, TRUE)))
22089 skip("Failed to create a D3D device.\n");
22090 IDirect3D9_Release(d3d9);
22091 DestroyWindow(window);
22092 return;
22095 hr = IDirect3DDevice9_CreateIndexBuffer(device, sizeof(indices), 0,
22096 D3DFMT_INDEX16, D3DPOOL_MANAGED, &ib, NULL);
22097 ok(SUCCEEDED(hr), "Failed to create index buffer, hr %#x.\n", hr);
22099 hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(green_quad), 0,
22100 D3DFVF_XYZ | D3DFVF_DIFFUSE, D3DPOOL_MANAGED, &vb, NULL);
22101 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
22103 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, FALSE);
22104 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
22105 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
22106 ok(SUCCEEDED(hr), "Failed to disable Z test, hr %#x.\n", hr);
22107 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
22108 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
22110 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
22111 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
22113 hr = IDirect3DVertexBuffer9_Lock(vb, 0, sizeof(green_quad), &data, 0);
22114 ok(hr == D3D_OK, "Failed to lock vertex buffer, hr %#x.\n", hr);
22115 memcpy(data, green_quad, sizeof(green_quad));
22116 hr = IDirect3DVertexBuffer9_Unlock(vb);
22117 ok(hr == D3D_OK, "Failed to unlock vertex buffer, hr %#x.\n", hr);
22119 hr = IDirect3DIndexBuffer9_Lock(ib, 0, sizeof(indices), &data, 0);
22120 ok(hr == D3D_OK, "Failed to lock index buffer, hr %#x.\n", hr);
22121 memcpy(data, indices, sizeof(indices));
22122 hr = IDirect3DIndexBuffer9_Unlock(ib);
22123 ok(hr == D3D_OK, "Failed to unlock index buffer, hr %#x.\n", hr);
22125 hr = IDirect3DDevice9_SetIndices(device, ib);
22126 ok(hr == D3D_OK, "Failed to set index buffer, hr %#x.\n", hr);
22127 hr = IDirect3DDevice9_SetStreamSource(device, 0, vb, 0, sizeof(*green_quad));
22128 ok(hr == D3D_OK, "Failed to set stream source, hr %#x.\n", hr);
22130 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
22131 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
22132 hr = IDirect3DDevice9_BeginScene(device);
22133 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
22134 hr = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2);
22135 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
22136 hr = IDirect3DDevice9_EndScene(device);
22137 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
22138 color = getPixelColor(device, 320, 240);
22139 ok(color_match(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
22141 hr = IDirect3DDevice9_EvictManagedResources(device);
22142 ok(hr == D3D_OK, "Failed to evict managed resources, hr %#x.\n", hr);
22144 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
22145 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
22146 hr = IDirect3DDevice9_BeginScene(device);
22147 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
22148 hr = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2);
22149 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
22150 hr = IDirect3DDevice9_EndScene(device);
22151 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
22152 color = getPixelColor(device, 320, 240);
22153 ok(color_match(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
22155 IDirect3DIndexBuffer9_Release(ib);
22156 IDirect3DVertexBuffer9_Release(vb);
22157 refcount = IDirect3DDevice9_Release(device);
22158 ok(!refcount, "Device has %u references left.\n", refcount);
22159 IDirect3D9_Release(d3d9);
22160 DestroyWindow(window);
22163 /* This test shows that 0xffff is valid index in D3D9. */
22164 static void test_max_index16(void)
22166 static const struct vertex
22168 struct vec3 position;
22169 DWORD diffuse;
22171 green_quad[] =
22173 {{-1.0f, -1.0f, 0.1f}, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00)},
22174 {{-1.0f, 1.0f, 0.1f}, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00)},
22175 {{ 1.0f, -1.0f, 0.1f}, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00)},
22176 {{ 1.0f, 1.0f, 0.1f}, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00)},
22178 static const unsigned short indices[] = {0, 1, 2, 0xffff};
22179 static const unsigned int vertex_count = 0xffff + 1;
22181 D3DADAPTER_IDENTIFIER9 identifier;
22182 IDirect3DVertexBuffer9 *vb;
22183 IDirect3DIndexBuffer9 *ib;
22184 IDirect3DDevice9 *device;
22185 struct vertex *vb_data;
22186 IDirect3D9 *d3d9;
22187 ULONG refcount;
22188 D3DCOLOR color;
22189 D3DCAPS9 caps;
22190 HWND window;
22191 void *data;
22192 HRESULT hr;
22193 BOOL warp;
22195 window = create_window();
22196 d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
22197 ok(!!d3d9, "Failed to create a D3D object.\n");
22199 hr = IDirect3D9_GetAdapterIdentifier(d3d9, D3DADAPTER_DEFAULT, 0, &identifier);
22200 ok(SUCCEEDED(hr), "Failed to get adapter identifier, hr %#x.\n", hr);
22201 warp = adapter_is_warp(&identifier);
22203 if (!(device = create_device(d3d9, window, window, TRUE)))
22205 skip("Failed to create a D3D device.\n");
22206 IDirect3D9_Release(d3d9);
22207 DestroyWindow(window);
22208 return;
22211 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
22212 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
22213 if (caps.MaxVertexIndex < 0xffff)
22215 skip("Max vertex index is lower than 0xffff (%#x).\n", caps.MaxVertexIndex);
22216 IDirect3DDevice9_Release(device);
22217 IDirect3D9_Release(d3d9);
22218 DestroyWindow(window);
22219 return;
22222 hr = IDirect3DDevice9_CreateVertexBuffer(device, vertex_count * sizeof(*green_quad), 0,
22223 D3DFVF_XYZ | D3DFVF_DIFFUSE, D3DPOOL_MANAGED, &vb, NULL);
22224 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
22226 hr = IDirect3DDevice9_CreateIndexBuffer(device, sizeof(indices), 0,
22227 D3DFMT_INDEX16, D3DPOOL_MANAGED, &ib, NULL);
22228 ok(SUCCEEDED(hr), "Failed to create index buffer, hr %#x.\n", hr);
22230 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, FALSE);
22231 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
22232 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
22233 ok(SUCCEEDED(hr), "Failed to disable Z test, hr %#x.\n", hr);
22234 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
22235 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
22237 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
22238 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
22240 hr = IDirect3DVertexBuffer9_Lock(vb, 0, sizeof(green_quad), (void **)&vb_data, 0);
22241 ok(hr == D3D_OK, "Failed to lock vertex buffer, hr %#x.\n", hr);
22242 vb_data[0] = green_quad[0];
22243 vb_data[1] = green_quad[1];
22244 vb_data[2] = green_quad[2];
22245 vb_data[0xffff] = green_quad[3];
22246 hr = IDirect3DVertexBuffer9_Unlock(vb);
22247 ok(hr == D3D_OK, "Failed to unlock vertex buffer, hr %#x.\n", hr);
22249 hr = IDirect3DIndexBuffer9_Lock(ib, 0, sizeof(indices), &data, 0);
22250 ok(hr == D3D_OK, "Failed to lock index buffer, hr %#x.\n", hr);
22251 memcpy(data, indices, sizeof(indices));
22252 hr = IDirect3DIndexBuffer9_Unlock(ib);
22253 ok(hr == D3D_OK, "Failed to unlock index buffer, hr %#x.\n", hr);
22255 hr = IDirect3DDevice9_SetIndices(device, ib);
22256 ok(hr == D3D_OK, "Failed to set index buffer, hr %#x.\n", hr);
22257 hr = IDirect3DDevice9_SetStreamSource(device, 0, vb, 0, sizeof(struct vertex));
22258 ok(hr == D3D_OK, "Failed to set stream source, hr %#x.\n", hr);
22260 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
22261 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
22262 hr = IDirect3DDevice9_BeginScene(device);
22263 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
22264 hr = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 0, vertex_count, 0, 2);
22265 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
22266 hr = IDirect3DDevice9_EndScene(device);
22267 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
22268 color = getPixelColor(device, 20, 20);
22269 ok(color_match(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
22270 color = getPixelColor(device, 320, 240);
22271 ok(color_match(color, 0x0000ff00, 1) || broken(warp), "Got unexpected color 0x%08x.\n", color);
22272 color = getPixelColor(device, 620, 460);
22273 ok(color_match(color, 0x0000ff00, 1) || broken(warp), "Got unexpected color 0x%08x.\n", color);
22275 IDirect3DIndexBuffer9_Release(ib);
22276 IDirect3DVertexBuffer9_Release(vb);
22277 refcount = IDirect3DDevice9_Release(device);
22278 ok(!refcount, "Device has %u references left.\n", refcount);
22279 IDirect3D9_Release(d3d9);
22280 DestroyWindow(window);
22283 static void test_backbuffer_resize(void)
22285 D3DPRESENT_PARAMETERS present_parameters = {0};
22286 IDirect3DSurface9 *backbuffer;
22287 IDirect3DDevice9 *device;
22288 IDirect3D9 *d3d;
22289 D3DCOLOR color;
22290 ULONG refcount;
22291 HWND window;
22292 HRESULT hr;
22294 static const struct
22296 struct vec3 position;
22297 DWORD diffuse;
22299 quad[] =
22301 {{-1.0f, -1.0f, 0.1f}, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00)},
22302 {{-1.0f, 1.0f, 0.1f}, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00)},
22303 {{ 1.0f, -1.0f, 0.1f}, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00)},
22304 {{ 1.0f, 1.0f, 0.1f}, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00)},
22307 window = create_window();
22308 d3d = Direct3DCreate9(D3D_SDK_VERSION);
22309 ok(!!d3d, "Failed to create a D3D object.\n");
22310 if (!(device = create_device(d3d, window, window, TRUE)))
22312 skip("Failed to create a D3D device.\n");
22313 goto done;
22316 /* Wine d3d9 implementation had a bug which was triggered by a
22317 * SetRenderTarget() call with an unreferenced surface. */
22318 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
22319 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
22320 refcount = IDirect3DSurface9_Release(backbuffer);
22321 ok(!refcount, "Surface has %u references left.\n", refcount);
22322 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
22323 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
22324 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
22325 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
22327 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 1.0f, 0);
22328 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
22329 color = getPixelColor(device, 1, 1);
22330 ok(color == 0x00ff0000, "Got unexpected color 0x%08x.\n", color);
22332 present_parameters.BackBufferWidth = 800;
22333 present_parameters.BackBufferHeight = 600;
22334 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
22335 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
22336 present_parameters.hDeviceWindow = NULL;
22337 present_parameters.Windowed = TRUE;
22338 present_parameters.EnableAutoDepthStencil = TRUE;
22339 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
22340 hr = IDirect3DDevice9_Reset(device, &present_parameters);
22341 ok(SUCCEEDED(hr), "Failed to reset, hr %#x.\n", hr);
22343 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, FALSE);
22344 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
22345 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
22346 ok(SUCCEEDED(hr), "Failed to disable Z test, hr %#x.\n", hr);
22347 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
22348 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
22349 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
22350 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
22352 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
22353 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
22354 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
22355 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
22356 IDirect3DSurface9_Release(backbuffer);
22358 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 1.0f, 0);
22359 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
22360 color = getPixelColor(device, 1, 1);
22361 ok(color == 0x00ffff00, "Got unexpected color 0x%08x.\n", color);
22362 color = getPixelColor(device, 700, 500);
22363 ok(color == 0x00ffff00, "Got unexpected color 0x%08x.\n", color);
22365 hr = IDirect3DDevice9_BeginScene(device);
22366 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
22367 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
22368 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
22369 hr = IDirect3DDevice9_EndScene(device);
22370 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
22371 color = getPixelColor(device, 1, 1);
22372 ok(color == 0x0000ff00, "Got unexpected color 0x%08x.\n", color);
22373 color = getPixelColor(device, 700, 500);
22374 ok(color == 0x0000ff00, "Got unexpected color 0x%08x.\n", color);
22376 refcount = IDirect3DDevice9_Release(device);
22377 ok(!refcount, "Device has %u references left.\n", refcount);
22378 done:
22379 IDirect3D9_Release(d3d);
22380 DestroyWindow(window);
22383 static void test_drawindexedprimitiveup(void)
22385 static const struct vertex
22387 struct vec3 position;
22388 DWORD diffuse;
22390 quad[] =
22392 {{-1.0f, -1.0f, 0.1f}, 0xff00ff00},
22393 {{-1.0f, 1.0f, 0.1f}, 0xff0000ff},
22394 {{ 1.0f, -1.0f, 0.1f}, 0xffff0000},
22395 {{ 1.0f, 1.0f, 0.1f}, 0xff0000ff},
22397 {{-1.0f, -1.0f, 0.1f}, 0xff0000ff},
22398 {{-1.0f, 1.0f, 0.1f}, 0xff00ff00},
22399 {{ 1.0f, -1.0f, 0.1f}, 0xffff0000},
22400 {{ 1.0f, 1.0f, 0.1f}, 0xff00ff00},
22402 static const unsigned short indices[] = {0, 1, 2, 3, 4, 5, 6, 7};
22403 IDirect3DDevice9 *device;
22404 IDirect3D9 *d3d;
22405 ULONG refcount;
22406 D3DCOLOR color;
22407 HWND window;
22408 HRESULT hr;
22410 window = create_window();
22411 d3d = Direct3DCreate9(D3D_SDK_VERSION);
22412 ok(!!d3d, "Failed to create a D3D object.\n");
22414 if (!(device = create_device(d3d, window, window, TRUE)))
22416 skip("Failed to create a D3D device.\n");
22417 IDirect3D9_Release(d3d);
22418 DestroyWindow(window);
22419 return;
22422 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, FALSE);
22423 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
22424 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
22425 ok(SUCCEEDED(hr), "Failed to disable Z test, hr %#x.\n", hr);
22426 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
22427 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
22429 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
22430 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
22432 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
22433 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
22435 hr = IDirect3DDevice9_BeginScene(device);
22436 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
22437 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 4, 4, 2, indices + 4, D3DFMT_INDEX16, quad, sizeof(*quad));
22438 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
22439 hr = IDirect3DDevice9_EndScene(device);
22440 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
22442 color = getPixelColor(device, 160, 120);
22443 ok(color_match(color, 0x0040bf00, 1), "Got unexpected color 0x%08x.\n", color);
22444 color = getPixelColor(device, 480, 120);
22445 ok(color_match(color, 0x0040bf00, 1), "Got unexpected color 0x%08x.\n", color);
22446 color = getPixelColor(device, 160, 360);
22447 ok(color_match(color, 0x00404080, 1), "Got unexpected color 0x%08x.\n", color);
22448 color = getPixelColor(device, 480, 360);
22449 ok(color_match(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
22451 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
22452 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
22454 hr = IDirect3DDevice9_BeginScene(device);
22455 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
22456 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 0, 4, 2, indices, D3DFMT_INDEX16, quad, sizeof(*quad));
22457 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
22458 hr = IDirect3DDevice9_EndScene(device);
22459 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
22461 color = getPixelColor(device, 160, 120);
22462 ok(color_match(color, 0x004000bf, 1), "Got unexpected color 0x%08x.\n", color);
22463 color = getPixelColor(device, 480, 120);
22464 ok(color_match(color, 0x004000bf, 1), "Got unexpected color 0x%08x.\n", color);
22465 color = getPixelColor(device, 160, 360);
22466 ok(color_match(color, 0x00408040, 1), "Got unexpected color 0x%08x.\n", color);
22467 color = getPixelColor(device, 480, 360);
22468 ok(color_match(color, 0x00bf0040, 1), "Got unexpected color 0x%08x.\n", color);
22470 refcount = IDirect3DDevice9_Release(device);
22471 ok(!refcount, "Device has %u references left.\n", refcount);
22472 IDirect3D9_Release(d3d);
22473 DestroyWindow(window);
22476 static void test_vertex_texture(void)
22478 static const D3DVERTEXELEMENT9 decl_elements[] =
22480 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
22481 D3DDECL_END()
22483 static const struct vec3 quad[] =
22485 {-1.0f, -1.0f, 0.0f},
22486 {-1.0f, 1.0f, 0.0f},
22487 { 1.0f, -1.0f, 0.0f},
22488 { 1.0f, 1.0f, 0.0f},
22490 static const DWORD vs_code[] =
22492 0xfffe0300, /* vs_3_0 */
22493 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 0, 0, 0, 0 */
22494 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
22495 0x0200001f, 0x90000000, 0xa00f0800, /* dcl_2d s0 */
22496 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
22497 0x0200001f, 0x8000000a, 0xe00f0001, /* dcl_color o1 */
22498 0x0300005f, 0xe00f0001, 0xa0000000, 0xa0e40800, /* texldl o1, c0.x, s0 */
22499 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
22500 0x0000ffff, /* end */
22502 static const DWORD ps_code[] =
22504 0xffff0300, /* ps_3_0 */
22505 0x0200001f, 0x8000000a, 0x900f0000, /* dcl_color v0 */
22506 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
22507 0x0000ffff, /* end */
22509 static const DWORD texture_data[4] = {0x00ffff00, 0x00ffff00, 0x00ffff00, 0x00ffff00};
22510 IDirect3DVertexDeclaration9 *declaration;
22511 IDirect3DTexture9 *texture;
22512 IDirect3DVertexShader9 *vs;
22513 IDirect3DPixelShader9 *ps;
22514 IDirect3DDevice9 *device;
22515 D3DLOCKED_RECT lr;
22516 IDirect3D9 *d3d;
22517 D3DCOLOR color;
22518 ULONG refcount;
22519 D3DCAPS9 caps;
22520 HWND window;
22521 HRESULT hr;
22523 window = create_window();
22524 d3d = Direct3DCreate9(D3D_SDK_VERSION);
22525 ok(!!d3d, "Failed to create D3D object.\n");
22527 if (!(device = create_device(d3d, window, window, TRUE)))
22529 skip("Failed to create D3D device.\n");
22530 IDirect3D9_Release(d3d);
22531 DestroyWindow(window);
22532 return;
22535 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
22536 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
22537 if (caps.VertexShaderVersion < D3DVS_VERSION(3, 0) || caps.PixelShaderVersion < D3DPS_VERSION(3, 0))
22539 skip("SM3 is not supported.\n");
22540 goto done;
22542 if (!(caps.VertexTextureFilterCaps & D3DPTFILTERCAPS_MAGFPOINT)
22543 || !(caps.VertexTextureFilterCaps & D3DPTFILTERCAPS_MINFPOINT))
22545 skip("Vertex texture point filtering is not supported, caps %#x.\n", caps.VertexTextureFilterCaps);
22546 goto done;
22548 hr = IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
22549 D3DUSAGE_QUERY_VERTEXTEXTURE, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8);
22550 if (hr != D3D_OK)
22552 skip("No vertex texture fetch support for D3DFMT_A8R8G8B8, hr %#x.\n", hr);
22553 goto done;
22556 hr = IDirect3DDevice9_CreateTexture(device, 2, 2, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture, NULL);
22557 ok(hr == D3D_OK, "Failed to create texture, hr %#x.\n", hr);
22558 memset(&lr, 0, sizeof(lr));
22559 hr = IDirect3DTexture9_LockRect(texture, 0, &lr, NULL, 0);
22560 ok(hr == D3D_OK, "Failed to lock texture, hr %#x.\n", hr);
22561 memcpy(lr.pBits, texture_data, sizeof(texture_data));
22562 hr = IDirect3DTexture9_UnlockRect(texture, 0);
22563 ok(hr == D3D_OK, "Failed to unlock texture, hr %#x.\n", hr);
22565 hr = IDirect3DDevice9_SetTexture(device, D3DVERTEXTEXTURESAMPLER0, (IDirect3DBaseTexture9 *)texture);
22566 ok(hr == D3D_OK, "Failed to set texture, hr %#x.\n", hr);
22568 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &declaration);
22569 ok(SUCCEEDED(hr), "Failed to create vertex declaration, hr %#x.\n", hr);
22570 hr = IDirect3DDevice9_CreateVertexShader(device, vs_code, &vs);
22571 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
22572 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code, &ps);
22573 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22575 hr = IDirect3DDevice9_SetVertexDeclaration(device, declaration);
22576 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
22577 hr = IDirect3DDevice9_SetVertexShader(device, vs);
22578 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
22579 hr = IDirect3DDevice9_SetPixelShader(device, ps);
22580 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
22582 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
22583 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
22584 hr = IDirect3DDevice9_BeginScene(device);
22585 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
22586 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
22587 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
22588 hr = IDirect3DDevice9_EndScene(device);
22589 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
22590 color = getPixelColor(device, 160, 360);
22591 ok(color == texture_data[0], "Got unexpected color 0x%08x.\n", color);
22593 IDirect3DPixelShader9_Release(ps);
22594 IDirect3DVertexShader9_Release(vs);
22595 IDirect3DTexture9_Release(texture);
22596 IDirect3DVertexDeclaration9_Release(declaration);
22597 done:
22598 refcount = IDirect3DDevice9_Release(device);
22599 ok(!refcount, "Device has %u references left.\n", refcount);
22600 IDirect3D9_Release(d3d);
22601 DestroyWindow(window);
22604 START_TEST(visual)
22606 D3DADAPTER_IDENTIFIER9 identifier;
22607 IDirect3D9 *d3d;
22608 HRESULT hr;
22610 if (!(d3d = Direct3DCreate9(D3D_SDK_VERSION)))
22612 skip("could not create D3D9 object\n");
22613 return;
22616 memset(&identifier, 0, sizeof(identifier));
22617 hr = IDirect3D9_GetAdapterIdentifier(d3d, 0, 0, &identifier);
22618 ok(SUCCEEDED(hr), "Failed to get adapter identifier, hr %#x.\n", hr);
22619 trace("Driver string: \"%s\"\n", identifier.Driver);
22620 trace("Description string: \"%s\"\n", identifier.Description);
22621 /* Only Windows XP's default VGA driver should have an empty description */
22622 ok(identifier.Description[0] || broken(!strcmp(identifier.Driver, "vga.dll")), "Empty driver description.\n");
22623 trace("Device name string: \"%s\"\n", identifier.DeviceName);
22624 ok(identifier.DeviceName[0], "Empty device name.\n");
22625 trace("Driver version %d.%d.%d.%d\n",
22626 HIWORD(U(identifier.DriverVersion).HighPart), LOWORD(U(identifier.DriverVersion).HighPart),
22627 HIWORD(U(identifier.DriverVersion).LowPart), LOWORD(U(identifier.DriverVersion).LowPart));
22629 IDirect3D9_Release(d3d);
22631 test_sanity();
22632 depth_clamp_test();
22633 stretchrect_test();
22634 lighting_test();
22635 test_specular_lighting();
22636 clear_test();
22637 color_fill_test();
22638 fog_test();
22639 test_cube_wrap();
22640 z_range_test();
22641 maxmip_test();
22642 offscreen_test();
22643 ds_size_test();
22644 test_blend();
22645 test_shademode();
22646 srgbtexture_test();
22647 release_buffer_test();
22648 float_texture_test();
22649 g16r16_texture_test();
22650 pixelshader_blending_test();
22651 texture_transform_flags_test();
22652 autogen_mipmap_test();
22653 fixed_function_decl_test();
22654 conditional_np2_repeat_test();
22655 fixed_function_bumpmap_test();
22656 test_pointsize();
22657 tssargtemp_test();
22658 np2_stretch_rect_test();
22659 yuv_color_test();
22660 yuv_layout_test();
22661 zwriteenable_test();
22662 alphatest_test();
22663 viewport_test();
22664 test_constant_clamp_vs();
22665 test_compare_instructions();
22666 test_mova();
22667 loop_index_test();
22668 sincos_test();
22669 sgn_test();
22670 clip_planes_test();
22671 test_vshader_input();
22672 test_vshader_float16();
22673 stream_test();
22674 fog_with_shader_test();
22675 texbem_test();
22676 texdepth_test();
22677 texkill_test();
22678 volume_v16u16_test();
22679 constant_clamp_ps_test();
22680 cnd_test();
22681 dp2add_ps_test();
22682 unbound_sampler_test();
22683 nested_loop_test();
22684 pretransformed_varying_test();
22685 vface_register_test();
22686 test_fragment_coords();
22687 multiple_rendertargets_test();
22688 texop_test();
22689 texop_range_test();
22690 alphareplicate_test();
22691 dp3_alpha_test();
22692 depth_buffer_test();
22693 depth_buffer2_test();
22694 depth_blit_test();
22695 intz_test();
22696 shadow_test();
22697 fp_special_test();
22698 depth_bounds_test();
22699 srgbwrite_format_test();
22700 update_surface_test();
22701 multisample_get_rtdata_test();
22702 zenable_test();
22703 fog_special_test();
22704 volume_srgb_test();
22705 volume_dxt5_test();
22706 add_dirty_rect_test();
22707 multisampled_depth_buffer_test();
22708 resz_test();
22709 stencil_cull_test();
22710 test_per_stage_constant();
22711 test_3dc_formats();
22712 test_fog_interpolation();
22713 test_negative_fixedfunction_fog();
22714 test_position_index();
22715 test_table_fog_zw();
22716 test_signed_formats();
22717 test_multisample_mismatch();
22718 test_texcoordindex();
22719 test_vertex_blending();
22720 test_updatetexture();
22721 test_depthbias();
22722 test_flip();
22723 test_uninitialized_varyings();
22724 test_multisample_init();
22725 test_texture_blending();
22726 test_color_clamping();
22727 test_line_antialiasing_blending();
22728 test_dsy();
22729 test_evict_bound_resources();
22730 test_max_index16();
22731 test_backbuffer_resize();
22732 test_drawindexedprimitiveup();
22733 test_vertex_texture();