d3d9/tests: Add a test for POSITIONi shader input/outputs.
[wine.git] / dlls / d3d9 / tests / visual.c
blobe2b7b81d75f531e3919ec0661b642cfb4aa440a2
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 #define COBJMACROS
32 #include <d3d9.h>
33 #include "wine/test.h"
35 struct vec2
37 float x, y;
40 struct vec3
42 float x, y, z;
45 struct vec4
47 float x, y, z, w;
50 static HWND create_window(void)
52 WNDCLASSA wc = {0};
53 HWND ret;
54 wc.lpfnWndProc = DefWindowProcA;
55 wc.lpszClassName = "d3d9_test_wc";
56 RegisterClassA(&wc);
58 ret = CreateWindowA("d3d9_test_wc", "d3d9_test", WS_SYSMENU | WS_POPUP,
59 0, 0, 640, 480, 0, 0, 0, 0);
60 ShowWindow(ret, SW_SHOW);
61 return ret;
64 static BOOL color_match(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
66 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
67 c1 >>= 8; c2 >>= 8;
68 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
69 c1 >>= 8; c2 >>= 8;
70 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
71 c1 >>= 8; c2 >>= 8;
72 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
73 return TRUE;
76 /* Locks a given surface and returns the color at (x,y). It's the caller's
77 * responsibility to only pass in lockable surfaces and valid x,y coordinates */
78 static DWORD getPixelColorFromSurface(IDirect3DSurface9 *surface, UINT x, UINT y)
80 DWORD color;
81 HRESULT hr;
82 D3DSURFACE_DESC desc;
83 RECT rectToLock = {x, y, x+1, y+1};
84 D3DLOCKED_RECT lockedRect;
86 hr = IDirect3DSurface9_GetDesc(surface, &desc);
87 if(FAILED(hr)) /* This is not a test */
89 trace("Can't get the surface description, hr=%08x\n", hr);
90 return 0xdeadbeef;
93 hr = IDirect3DSurface9_LockRect(surface, &lockedRect, &rectToLock, D3DLOCK_READONLY);
94 if(FAILED(hr)) /* This is not a test */
96 trace("Can't lock the surface, hr=%08x\n", hr);
97 return 0xdeadbeef;
99 switch(desc.Format) {
100 case D3DFMT_A8R8G8B8:
102 color = ((DWORD *) lockedRect.pBits)[0] & 0xffffffff;
103 break;
105 default:
106 trace("Error: unknown surface format: %d\n", desc.Format);
107 color = 0xdeadbeef;
108 break;
110 hr = IDirect3DSurface9_UnlockRect(surface);
111 if(FAILED(hr))
113 trace("Can't unlock the surface, hr=%08x\n", hr);
115 return color;
118 static DWORD getPixelColor(IDirect3DDevice9 *device, UINT x, UINT y)
120 DWORD ret;
121 IDirect3DSurface9 *surf = NULL, *target = NULL;
122 HRESULT hr;
123 D3DLOCKED_RECT lockedRect;
124 RECT rectToLock = {x, y, x+1, y+1};
126 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 640, 480,
127 D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surf, NULL);
128 if (FAILED(hr) || !surf)
130 trace("Can't create an offscreen plain surface to read the render target data, hr=%08x\n", hr);
131 return 0xdeadbeef;
134 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &target);
135 if(FAILED(hr))
137 trace("Can't get the render target, hr=%08x\n", hr);
138 ret = 0xdeadbeed;
139 goto out;
142 hr = IDirect3DDevice9_GetRenderTargetData(device, target, surf);
143 if (FAILED(hr))
145 trace("Can't read the render target data, hr=%08x\n", hr);
146 ret = 0xdeadbeec;
147 goto out;
150 hr = IDirect3DSurface9_LockRect(surf, &lockedRect, &rectToLock, D3DLOCK_READONLY);
151 if(FAILED(hr))
153 trace("Can't lock the offscreen surface, hr=%08x\n", hr);
154 ret = 0xdeadbeeb;
155 goto out;
158 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
159 * really important for these tests
161 ret = ((DWORD *) lockedRect.pBits)[0] & 0x00ffffff;
162 hr = IDirect3DSurface9_UnlockRect(surf);
163 if(FAILED(hr))
165 trace("Can't unlock the offscreen surface, hr=%08x\n", hr);
168 out:
169 if(target) IDirect3DSurface9_Release(target);
170 if(surf) IDirect3DSurface9_Release(surf);
171 return ret;
174 static IDirect3DDevice9 *create_device(IDirect3D9 *d3d, HWND device_window, HWND focus_window, BOOL windowed)
176 D3DPRESENT_PARAMETERS present_parameters = {0};
177 IDirect3DDevice9 *device;
179 present_parameters.Windowed = windowed;
180 present_parameters.hDeviceWindow = device_window;
181 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
182 present_parameters.BackBufferWidth = 640;
183 present_parameters.BackBufferHeight = 480;
184 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
185 present_parameters.EnableAutoDepthStencil = TRUE;
186 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
188 if (SUCCEEDED(IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
189 D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device)))
190 return device;
192 return NULL;
195 static void cleanup_device(IDirect3DDevice9 *device)
197 if (device)
199 D3DPRESENT_PARAMETERS present_parameters;
200 IDirect3DSwapChain9 *swapchain;
201 ULONG ref;
203 IDirect3DDevice9_GetSwapChain(device, 0, &swapchain);
204 IDirect3DSwapChain9_GetPresentParameters(swapchain, &present_parameters);
205 IDirect3DSwapChain9_Release(swapchain);
206 ref = IDirect3DDevice9_Release(device);
207 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
208 DestroyWindow(present_parameters.hDeviceWindow);
212 static void test_sanity(void)
214 IDirect3DDevice9 *device;
215 IDirect3D9 *d3d;
216 D3DCOLOR color;
217 ULONG refcount;
218 HWND window;
219 HRESULT hr;
221 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
222 0, 0, 640, 480, NULL, NULL, NULL, NULL);
223 d3d = Direct3DCreate9(D3D_SDK_VERSION);
224 ok(!!d3d, "Failed to create a D3D object.\n");
225 if (!(device = create_device(d3d, window, window, TRUE)))
227 skip("Failed to create a D3D device, skipping tests.\n");
228 goto done;
231 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 1.0f, 0);
232 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
233 color = getPixelColor(device, 1, 1);
234 ok(color == 0x00ff0000, "Got unexpected color 0x%08x.\n", color);
236 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
237 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
239 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ddee, 0.0, 0);
240 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
241 color = getPixelColor(device, 639, 479);
242 ok(color == 0x0000ddee, "Got unexpected color 0x%08x.\n", color);
244 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
245 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
247 refcount = IDirect3DDevice9_Release(device);
248 ok(!refcount, "Device has %u references left.\n", refcount);
249 done:
250 IDirect3D9_Release(d3d);
251 DestroyWindow(window);
254 static void lighting_test(void)
256 DWORD nfvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_NORMAL;
257 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
258 IDirect3DDevice9 *device;
259 D3DMATERIAL9 material;
260 IDirect3D9 *d3d;
261 D3DCOLOR color;
262 ULONG refcount;
263 HWND window;
264 HRESULT hr;
266 static const D3DMATRIX mat =
268 1.0f, 0.0f, 0.0f, 0.0f,
269 0.0f, 1.0f, 0.0f, 0.0f,
270 0.0f, 0.0f, 1.0f, 0.0f,
271 0.0f, 0.0f, 0.0f, 1.0f,
272 }}};
273 static const struct
275 struct vec3 position;
276 DWORD diffuse;
278 unlitquad[] =
280 {{-1.0f, -1.0f, 0.1f}, 0xffff0000},
281 {{-1.0f, 0.0f, 0.1f}, 0xffff0000},
282 {{ 0.0f, 0.0f, 0.1f}, 0xffff0000},
283 {{ 0.0f, -1.0f, 0.1f}, 0xffff0000},
285 litquad[] =
287 {{-1.0f, 0.0f, 0.1f}, 0xff00ff00},
288 {{-1.0f, 1.0f, 0.1f}, 0xff00ff00},
289 {{ 0.0f, 1.0f, 0.1f}, 0xff00ff00},
290 {{ 0.0f, 0.0f, 0.1f}, 0xff00ff00},
292 lighting_test[] =
294 {{-1.0f, -1.0f, 0.1f}, 0x8000ff00},
295 {{ 1.0f, -1.0f, 0.1f}, 0x80000000},
296 {{-1.0f, 1.0f, 0.1f}, 0x8000ff00},
297 {{ 1.0f, 1.0f, 0.1f}, 0x80000000},
299 static const struct
301 struct vec3 position;
302 struct vec3 normal;
303 DWORD diffuse;
305 unlitnquad[] =
307 {{0.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
308 {{0.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
309 {{1.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
310 {{1.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
312 litnquad[] =
314 {{0.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
315 {{0.0f, 1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
316 {{1.0f, 1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
317 {{1.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
319 static const WORD Indices[] = {0, 1, 2, 2, 3, 0};
321 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
322 0, 0, 640, 480, NULL, NULL, NULL, NULL);
323 d3d = Direct3DCreate9(D3D_SDK_VERSION);
324 ok(!!d3d, "Failed to create a D3D object.\n");
325 if (!(device = create_device(d3d, window, window, TRUE)))
327 skip("Failed to create a D3D device, skipping tests.\n");
328 goto done;
331 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
332 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
334 /* Setup some states that may cause issues */
335 hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLDMATRIX(0), &mat);
336 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform returned %08x\n", hr);
337 hr = IDirect3DDevice9_SetTransform(device, D3DTS_VIEW, &mat);
338 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform returned %08x\n", hr);
339 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &mat);
340 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform returned %08x\n", hr);
341 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, FALSE);
342 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
343 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
344 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
345 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGENABLE, FALSE);
346 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
347 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILENABLE, FALSE);
348 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
349 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHATESTENABLE, FALSE);
350 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
351 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHABLENDENABLE, FALSE);
352 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
353 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SCISSORTESTENABLE, FALSE);
354 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
355 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE);
356 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with %08x\n", hr);
357 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE);
358 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with %08x\n", hr);
360 hr = IDirect3DDevice9_SetFVF(device, 0);
361 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF returned %08x\n", hr);
363 hr = IDirect3DDevice9_SetFVF(device, fvf);
364 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF returned %08x\n", hr);
366 hr = IDirect3DDevice9_BeginScene(device);
367 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
369 /* No lights are defined... That means, lit vertices should be entirely black */
370 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
371 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
372 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
373 2 /* PrimCount */, Indices, D3DFMT_INDEX16, unlitquad, sizeof(unlitquad[0]));
374 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
376 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, TRUE);
377 ok(SUCCEEDED(hr), "Failed to enable lighting, hr %#x.\n", hr);
378 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
379 2 /* PrimCount */, Indices, D3DFMT_INDEX16, litquad, sizeof(litquad[0]));
380 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
382 hr = IDirect3DDevice9_SetFVF(device, nfvf);
383 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
385 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
386 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
387 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
388 2 /* PrimCount */, Indices, D3DFMT_INDEX16, unlitnquad, sizeof(unlitnquad[0]));
389 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
391 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, TRUE);
392 ok(SUCCEEDED(hr), "Failed to enable lighting, hr %#x.\n", hr);
393 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
394 2 /* PrimCount */, Indices, D3DFMT_INDEX16, litnquad, sizeof(litnquad[0]));
395 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
397 hr = IDirect3DDevice9_EndScene(device);
398 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
400 color = getPixelColor(device, 160, 360); /* Lower left quad - unlit without normals */
401 ok(color == 0x00ff0000, "Unlit quad without normals has color 0x%08x, expected 0x00ff0000.\n", color);
402 color = getPixelColor(device, 160, 120); /* Upper left quad - lit without normals */
403 ok(color == 0x00000000, "Lit quad without normals has color 0x%08x, expected 0x00000000.\n", color);
404 color = getPixelColor(device, 480, 360); /* Lower left quad - unlit with normals */
405 ok(color == 0x000000ff, "Unlit quad with normals has color 0x%08x, expected 0x000000ff.\n", color);
406 color = getPixelColor(device, 480, 120); /* Upper left quad - lit with normals */
407 ok(color == 0x00000000, "Lit quad with normals has color 0x%08x, expected 0x00000000.\n", color);
409 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
411 memset(&material, 0, sizeof(material));
412 material.Diffuse.r = 0.0;
413 material.Diffuse.g = 0.0;
414 material.Diffuse.b = 0.0;
415 material.Diffuse.a = 1.0;
416 material.Ambient.r = 0.0;
417 material.Ambient.g = 0.0;
418 material.Ambient.b = 0.0;
419 material.Ambient.a = 0.0;
420 material.Specular.r = 0.0;
421 material.Specular.g = 0.0;
422 material.Specular.b = 0.0;
423 material.Specular.a = 0.0;
424 material.Emissive.r = 0.0;
425 material.Emissive.g = 0.0;
426 material.Emissive.b = 0.0;
427 material.Emissive.a = 0.0;
428 material.Power = 0.0;
429 hr = IDirect3DDevice9_SetMaterial(device, &material);
430 ok(hr == D3D_OK, "IDirect3DDevice9_SetMaterial returned %08x\n", hr);
432 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);
433 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
434 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL);
435 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
437 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
438 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState returned %08x\n", hr);
439 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE | D3DTA_ALPHAREPLICATE);
440 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState returned %08x\n", hr);
442 hr = IDirect3DDevice9_BeginScene(device);
443 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
445 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
446 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
447 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, lighting_test, sizeof(lighting_test[0]));
448 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
450 hr = IDirect3DDevice9_EndScene(device);
451 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
453 color = getPixelColor(device, 320, 240);
454 ok(color == 0x00ffffff, "Lit vertex alpha test returned color %08x, expected 0x00ffffff\n", color);
455 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
457 refcount = IDirect3DDevice9_Release(device);
458 ok(!refcount, "Device has %u references left.\n", refcount);
459 done:
460 IDirect3D9_Release(d3d);
461 DestroyWindow(window);
464 static void clear_test(void)
466 /* Tests the correctness of clearing parameters */
467 HRESULT hr;
468 D3DRECT rect[2];
469 D3DRECT rect_negneg;
470 DWORD color;
471 D3DVIEWPORT9 old_vp, vp;
472 RECT scissor;
473 DWORD oldColorWrite;
474 BOOL invalid_clear_failed = FALSE;
475 IDirect3DDevice9 *device;
476 IDirect3D9 *d3d;
477 ULONG refcount;
478 HWND window;
480 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
481 0, 0, 640, 480, NULL, NULL, NULL, NULL);
482 d3d = Direct3DCreate9(D3D_SDK_VERSION);
483 ok(!!d3d, "Failed to create a D3D object.\n");
484 if (!(device = create_device(d3d, window, window, TRUE)))
486 skip("Failed to create a D3D device, skipping tests.\n");
487 goto done;
490 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
491 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
493 /* Positive x, negative y */
494 rect[0].x1 = 0;
495 rect[0].y1 = 480;
496 rect[0].x2 = 320;
497 rect[0].y2 = 240;
499 /* Positive x, positive y */
500 rect[1].x1 = 0;
501 rect[1].y1 = 0;
502 rect[1].x2 = 320;
503 rect[1].y2 = 240;
504 /* Clear 2 rectangles with one call. The refrast returns an error in this case, every real driver tested so far
505 * returns D3D_OK, but ignores the rectangle silently
507 hr = IDirect3DDevice9_Clear(device, 2, rect, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
508 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_Clear failed with %08x\n", hr);
509 if(hr == D3DERR_INVALIDCALL) invalid_clear_failed = TRUE;
511 /* negative x, negative y */
512 rect_negneg.x1 = 640;
513 rect_negneg.y1 = 240;
514 rect_negneg.x2 = 320;
515 rect_negneg.y2 = 0;
516 hr = IDirect3DDevice9_Clear(device, 1, &rect_negneg, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
517 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_Clear failed with %08x\n", hr);
518 if(hr == D3DERR_INVALIDCALL) invalid_clear_failed = TRUE;
520 color = getPixelColor(device, 160, 360); /* lower left quad */
521 ok(color == 0x00ffffff, "Clear rectangle 3(pos, neg) has color %08x\n", color);
522 color = getPixelColor(device, 160, 120); /* upper left quad */
523 if(invalid_clear_failed) {
524 /* If the negative rectangle was refused, the other rectangles in the list shouldn't be cleared either */
525 ok(color == 0x00ffffff, "Clear rectangle 1(pos, pos) has color %08x\n", color);
526 } else {
527 /* If the negative rectangle was dropped silently, the correct ones are cleared */
528 ok(color == 0x00ff0000, "Clear rectangle 1(pos, pos) has color %08x\n", color);
530 color = getPixelColor(device, 480, 360); /* lower right quad */
531 ok(color == 0x00ffffff, "Clear rectangle 4(NULL) has color %08x\n", color);
532 color = getPixelColor(device, 480, 120); /* upper right quad */
533 ok(color == 0x00ffffff, "Clear rectangle 4(neg, neg) has color %08x\n", color);
535 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
537 /* Hack to work around a nvidia windows driver bug. The clear below is supposed to
538 * clear the red quad in the top left part of the render target. For some reason it
539 * doesn't work if the clear color is 0xffffffff on some versions of the Nvidia Windows
540 * driver(tested on 8.17.12.5896, Win7). A clear with a different color works around
541 * this bug and fixes the clear with the white color. Even 0xfeffffff works, but let's
542 * pick some obvious value
544 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xdeadbabe, 0.0, 0);
545 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
547 /* Test how the viewport affects clears */
548 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
549 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
550 hr = IDirect3DDevice9_GetViewport(device, &old_vp);
551 ok(hr == D3D_OK, "IDirect3DDevice9_GetViewport failed with %08x\n", hr);
553 vp.X = 160;
554 vp.Y = 120;
555 vp.Width = 160;
556 vp.Height = 120;
557 vp.MinZ = 0.0;
558 vp.MaxZ = 1.0;
559 hr = IDirect3DDevice9_SetViewport(device, &vp);
560 ok(hr == D3D_OK, "IDirect3DDevice9_SetViewport failed with %08x\n", hr);
561 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0, 0);
562 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
564 vp.X = 320;
565 vp.Y = 240;
566 vp.Width = 320;
567 vp.Height = 240;
568 vp.MinZ = 0.0;
569 vp.MaxZ = 1.0;
570 hr = IDirect3DDevice9_SetViewport(device, &vp);
571 ok(hr == D3D_OK, "IDirect3DDevice9_SetViewport failed with %08x\n", hr);
572 rect[0].x1 = 160;
573 rect[0].y1 = 120;
574 rect[0].x2 = 480;
575 rect[0].y2 = 360;
576 hr = IDirect3DDevice9_Clear(device, 1, &rect[0], D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
577 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
579 hr = IDirect3DDevice9_SetViewport(device, &old_vp);
580 ok(hr == D3D_OK, "IDirect3DDevice9_SetViewport failed with %08x\n", hr);
582 color = getPixelColor(device, 158, 118);
583 ok(color == 0x00ffffff, "(158,118) has color %08x\n", color);
584 color = getPixelColor(device, 162, 118);
585 ok(color == 0x00ffffff, "(162,118) has color %08x\n", color);
586 color = getPixelColor(device, 158, 122);
587 ok(color == 0x00ffffff, "(158,122) has color %08x\n", color);
588 color = getPixelColor(device, 162, 122);
589 ok(color == 0x000000ff, "(162,122) has color %08x\n", color);
591 color = getPixelColor(device, 318, 238);
592 ok(color == 0x000000ff, "(318,238) has color %08x\n", color);
593 color = getPixelColor(device, 322, 238);
594 ok(color == 0x00ffffff, "(322,328) has color %08x\n", color);
595 color = getPixelColor(device, 318, 242);
596 ok(color == 0x00ffffff, "(318,242) has color %08x\n", color);
597 color = getPixelColor(device, 322, 242);
598 ok(color == 0x0000ff00, "(322,242) has color %08x\n", color);
600 color = getPixelColor(device, 478, 358);
601 ok(color == 0x0000ff00, "(478,358 has color %08x\n", color);
602 color = getPixelColor(device, 482, 358);
603 ok(color == 0x00ffffff, "(482,358) has color %08x\n", color);
604 color = getPixelColor(device, 478, 362);
605 ok(color == 0x00ffffff, "(478,362) has color %08x\n", color);
606 color = getPixelColor(device, 482, 362);
607 ok(color == 0x00ffffff, "(482,362) has color %08x\n", color);
609 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
611 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
612 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
614 scissor.left = 160;
615 scissor.right = 480;
616 scissor.top = 120;
617 scissor.bottom = 360;
618 hr = IDirect3DDevice9_SetScissorRect(device, &scissor);
619 ok(hr == D3D_OK, "IDirect3DDevice_SetScissorRect failed with %08x\n", hr);
620 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SCISSORTESTENABLE, TRUE);
621 ok(hr == D3D_OK, "IDirect3DDevice_SetScissorRect failed with %08x\n", hr);
623 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
624 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
625 hr = IDirect3DDevice9_Clear(device, 1, &rect[1], D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
626 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
628 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SCISSORTESTENABLE, FALSE);
629 ok(hr == D3D_OK, "IDirect3DDevice_SetScissorRect failed with %08x\n", hr);
631 color = getPixelColor(device, 158, 118);
632 ok(color == 0x00ffffff, "Pixel 158/118 has color %08x\n", color);
633 color = getPixelColor(device, 162, 118);
634 ok(color == 0x00ffffff, "Pixel 162/118 has color %08x\n", color);
635 color = getPixelColor(device, 158, 122);
636 ok(color == 0x00ffffff, "Pixel 158/122 has color %08x\n", color);
637 color = getPixelColor(device, 162, 122);
638 ok(color == 0x00ff0000, "Pixel 162/122 has color %08x\n", color);
640 color = getPixelColor(device, 158, 358);
641 ok(color == 0x00ffffff, "Pixel 158/358 has color %08x\n", color);
642 color = getPixelColor(device, 162, 358);
643 ok(color == 0x0000ff00, "Pixel 162/358 has color %08x\n", color);
644 color = getPixelColor(device, 158, 358);
645 ok(color == 0x00ffffff, "Pixel 158/358 has color %08x\n", color);
646 color = getPixelColor(device, 162, 362);
647 ok(color == 0x00ffffff, "Pixel 162/362 has color %08x\n", color);
649 color = getPixelColor(device, 478, 118);
650 ok(color == 0x00ffffff, "Pixel 158/118 has color %08x\n", color);
651 color = getPixelColor(device, 478, 122);
652 ok(color == 0x0000ff00, "Pixel 162/118 has color %08x\n", color);
653 color = getPixelColor(device, 482, 122);
654 ok(color == 0x00ffffff, "Pixel 158/122 has color %08x\n", color);
655 color = getPixelColor(device, 482, 358);
656 ok(color == 0x00ffffff, "Pixel 162/122 has color %08x\n", color);
658 color = getPixelColor(device, 478, 358);
659 ok(color == 0x0000ff00, "Pixel 478/358 has color %08x\n", color);
660 color = getPixelColor(device, 478, 362);
661 ok(color == 0x00ffffff, "Pixel 478/118 has color %08x\n", color);
662 color = getPixelColor(device, 482, 358);
663 ok(color == 0x00ffffff, "Pixel 482/122 has color %08x\n", color);
664 color = getPixelColor(device, 482, 362);
665 ok(color == 0x00ffffff, "Pixel 482/122 has color %08x\n", color);
667 color = getPixelColor(device, 318, 238);
668 ok(color == 0x00ff0000, "Pixel 318/238 has color %08x\n", color);
669 color = getPixelColor(device, 318, 242);
670 ok(color == 0x0000ff00, "Pixel 318/242 has color %08x\n", color);
671 color = getPixelColor(device, 322, 238);
672 ok(color == 0x0000ff00, "Pixel 322/238 has color %08x\n", color);
673 color = getPixelColor(device, 322, 242);
674 ok(color == 0x0000ff00, "Pixel 322/242 has color %08x\n", color);
676 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
678 hr = IDirect3DDevice9_GetRenderState(device, D3DRS_COLORWRITEENABLE, &oldColorWrite);
679 ok(hr == D3D_OK, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr);
680 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED);
681 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with %08x\n", hr);
683 /* Same nvidia windows driver trouble with white clears as earlier in the same test */
684 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xdeadbeef, 0.0, 0);
685 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
687 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
688 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
690 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_COLORWRITEENABLE, oldColorWrite);
691 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with %08x\n", hr);
693 /* Colorwriteenable does not affect the clear */
694 color = getPixelColor(device, 320, 240);
695 ok(color == 0x00ffffff, "Color write protected clear returned color %08x\n", color);
697 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
699 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00ffffff, 0.0, 0);
700 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear failed with %08x\n", hr);
702 rect[0].x1 = 0;
703 rect[0].y1 = 0;
704 rect[0].x2 = 640;
705 rect[0].y2 = 480;
706 hr = IDirect3DDevice9_Clear(device, 0, rect, D3DCLEAR_TARGET, 0x00ff0000, 0.0, 0);
707 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear failed with %08x\n", hr);
709 color = getPixelColor(device, 320, 240);
710 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0xff), 1),
711 "Clear with count = 0, rect != NULL has color %08x\n", color);
713 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
715 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
716 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear failed with %08x\n", hr);
717 hr = IDirect3DDevice9_Clear(device, 1, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
718 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear failed with %08x\n", hr);
720 color = getPixelColor(device, 320, 240);
721 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1),
722 "Clear with count = 1, rect = NULL has color %08x\n", color);
724 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
726 refcount = IDirect3DDevice9_Release(device);
727 ok(!refcount, "Device has %u references left.\n", refcount);
728 done:
729 IDirect3D9_Release(d3d);
730 DestroyWindow(window);
733 static void color_fill_test(void)
735 IDirect3DSurface9 *offscreen_surface;
736 IDirect3DSurface9 *backbuffer;
737 IDirect3DSurface9 *rt_surface;
738 D3DCOLOR fill_color, color;
739 IDirect3DDevice9 *device;
740 IDirect3D9 *d3d;
741 ULONG refcount;
742 HWND window;
743 HRESULT hr;
745 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
746 0, 0, 640, 480, NULL, NULL, NULL, NULL);
747 d3d = Direct3DCreate9(D3D_SDK_VERSION);
748 ok(!!d3d, "Failed to create a D3D object.\n");
749 if (!(device = create_device(d3d, window, window, TRUE)))
751 skip("Failed to create a D3D device, skipping tests.\n");
752 goto done;
755 /* Test ColorFill on a the backbuffer (should pass) */
756 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
757 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
759 fill_color = 0x112233;
760 hr = IDirect3DDevice9_ColorFill(device, backbuffer, NULL, fill_color);
761 ok(SUCCEEDED(hr), "Color fill failed, hr %#x.\n", hr);
763 color = getPixelColor(device, 0, 0);
764 ok(color == fill_color, "Expected color %08x, got %08x\n", fill_color, color);
766 IDirect3DSurface9_Release(backbuffer);
768 /* Test ColorFill on a render target surface (should pass) */
769 hr = IDirect3DDevice9_CreateRenderTarget(device, 32, 32, D3DFMT_A8R8G8B8,
770 D3DMULTISAMPLE_NONE, 0, TRUE, &rt_surface, NULL );
771 ok(hr == D3D_OK, "Unable to create render target surface, hr = %08x\n", hr);
773 fill_color = 0x445566;
774 hr = IDirect3DDevice9_ColorFill(device, rt_surface, NULL, fill_color);
775 ok(SUCCEEDED(hr), "Color fill failed, hr %#x.\n", hr);
777 color = getPixelColorFromSurface(rt_surface, 0, 0);
778 ok(color == fill_color, "Expected color %08x, got %08x\n", fill_color, color);
780 IDirect3DSurface9_Release(rt_surface);
782 /* Test ColorFill on an offscreen plain surface in D3DPOOL_DEFAULT (should pass) */
783 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 32, 32,
784 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &offscreen_surface, NULL);
785 ok(hr == D3D_OK, "Unable to create offscreen plain surface, hr = %08x\n", hr);
787 fill_color = 0x778899;
788 hr = IDirect3DDevice9_ColorFill(device, offscreen_surface, NULL, fill_color);
789 ok(SUCCEEDED(hr), "Color fill failed, hr %#x.\n", hr);
791 color = getPixelColorFromSurface(offscreen_surface, 0, 0);
792 ok(color == fill_color, "Expected color %08x, got %08x\n", fill_color, color);
794 IDirect3DSurface9_Release(offscreen_surface);
796 /* Try ColorFill on an offscreen surface in sysmem (should fail) */
797 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 32, 32,
798 D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &offscreen_surface, NULL);
799 ok(hr == D3D_OK, "Unable to create offscreen plain surface, hr = %08x\n", hr);
801 hr = IDirect3DDevice9_ColorFill(device, offscreen_surface, NULL, 0);
802 ok(hr == D3DERR_INVALIDCALL, "ColorFill on offscreen sysmem surface failed with hr = %08x\n", hr);
804 IDirect3DSurface9_Release(offscreen_surface);
806 refcount = IDirect3DDevice9_Release(device);
807 ok(!refcount, "Device has %u references left.\n", refcount);
808 done:
809 IDirect3D9_Release(d3d);
810 DestroyWindow(window);
814 * c7 mova ARGB mov ARGB
815 * -2.4 -2 0x00ffff00 -3 0x00ff0000
816 * -1.6 -2 0x00ffff00 -2 0x00ffff00
817 * -0.4 0 0x0000ffff -1 0x0000ff00
818 * 0.4 0 0x0000ffff 0 0x0000ffff
819 * 1.6 2 0x00ff00ff 1 0x000000ff
820 * 2.4 2 0x00ff00ff 2 0x00ff00ff
822 static void test_mova(void)
824 IDirect3DVertexDeclaration9 *vertex_declaration;
825 IDirect3DVertexShader9 *mova_shader;
826 IDirect3DVertexShader9 *mov_shader;
827 IDirect3DDevice9 *device;
828 unsigned int i, j;
829 IDirect3D9 *d3d;
830 ULONG refcount;
831 D3DCAPS9 caps;
832 HWND window;
833 HRESULT hr;
835 static const DWORD mova_test[] =
837 0xfffe0200, /* vs_2_0 */
838 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
839 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 1.0, 0.0, 0.0, 1.0 */
840 0x05000051, 0xa00f0001, 0x3f800000, 0x3f800000, 0x00000000, 0x3f800000, /* def c1, 1.0, 1.0, 0.0, 1.0 */
841 0x05000051, 0xa00f0002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, /* def c2, 0.0, 1.0, 0.0, 1.0 */
842 0x05000051, 0xa00f0003, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c3, 0.0, 1.0, 1.0, 1.0 */
843 0x05000051, 0xa00f0004, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, /* def c4, 0.0, 0.0, 1.0, 1.0 */
844 0x05000051, 0xa00f0005, 0x3f800000, 0x00000000, 0x3f800000, 0x3f800000, /* def c5, 1.0, 0.0, 1.0, 1.0 */
845 0x05000051, 0xa00f0006, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c6, 1.0, 1.0, 1.0, 1.0 */
846 0x0200002e, 0xb0010000, 0xa0000007, /* mova a0.x, c7.x */
847 0x03000001, 0xd00f0000, 0xa0e42003, 0xb0000000, /* mov oD0, c[a0.x + 3] */
848 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
849 0x0000ffff /* END */
851 static const DWORD mov_test[] =
853 0xfffe0101, /* vs_1_1 */
854 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
855 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 1.0, 0.0, 0.0, 1.0 */
856 0x00000051, 0xa00f0001, 0x3f800000, 0x3f800000, 0x00000000, 0x3f800000, /* def c1, 1.0, 1.0, 0.0, 1.0 */
857 0x00000051, 0xa00f0002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, /* def c2, 0.0, 1.0, 0.0, 1.0 */
858 0x00000051, 0xa00f0003, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c3, 0.0, 1.0, 1.0, 1.0 */
859 0x00000051, 0xa00f0004, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, /* def c4, 0.0, 0.0, 1.0, 1.0 */
860 0x00000051, 0xa00f0005, 0x3f800000, 0x00000000, 0x3f800000, 0x3f800000, /* def c5, 1.0, 0.0, 1.0, 1.0 */
861 0x00000051, 0xa00f0006, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c6, 1.0, 1.0, 1.0, 1.0 */
862 0x00000001, 0xb0010000, 0xa0000007, /* mov a0.x, c7.x */
863 0x00000001, 0xd00f0000, 0xa0e42003, /* mov oD0, c[a0.x + 3] */
864 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
865 0x0000ffff /* END */
867 static const struct
869 float in[4];
870 DWORD out;
872 test_data[2][6] =
875 {{-2.4f, 0.0f, 0.0f, 0.0f}, 0x00ff0000},
876 {{-1.6f, 0.0f, 0.0f, 0.0f}, 0x00ffff00},
877 {{-0.4f, 0.0f, 0.0f, 0.0f}, 0x0000ff00},
878 {{ 0.4f, 0.0f, 0.0f, 0.0f}, 0x0000ffff},
879 {{ 1.6f, 0.0f, 0.0f, 0.0f}, 0x000000ff},
880 {{ 2.4f, 0.0f, 0.0f, 0.0f}, 0x00ff00ff}
883 {{-2.4f, 0.0f, 0.0f, 0.0f}, 0x00ffff00},
884 {{-1.6f, 0.0f, 0.0f, 0.0f}, 0x00ffff00},
885 {{-0.4f, 0.0f, 0.0f, 0.0f}, 0x0000ffff},
886 {{ 0.4f, 0.0f, 0.0f, 0.0f}, 0x0000ffff},
887 {{ 1.6f, 0.0f, 0.0f, 0.0f}, 0x00ff00ff},
888 {{ 2.4f, 0.0f, 0.0f, 0.0f}, 0x00ff00ff}
891 static const struct vec3 quad[] =
893 {-1.0f, -1.0f, 0.0f},
894 {-1.0f, 1.0f, 0.0f},
895 { 1.0f, -1.0f, 0.0f},
896 { 1.0f, 1.0f, 0.0f},
898 static const D3DVERTEXELEMENT9 decl_elements[] =
900 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
901 D3DDECL_END()
904 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
905 0, 0, 640, 480, NULL, NULL, NULL, NULL);
906 d3d = Direct3DCreate9(D3D_SDK_VERSION);
907 ok(!!d3d, "Failed to create a D3D object.\n");
908 if (!(device = create_device(d3d, window, window, TRUE)))
910 skip("Failed to create a D3D device, skipping tests.\n");
911 goto done;
914 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
915 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
916 if (caps.VertexShaderVersion < D3DVS_VERSION(2, 0))
918 skip("No vs_2_0 support, skipping tests.\n");
919 IDirect3DDevice9_Release(device);
920 goto done;
923 hr = IDirect3DDevice9_CreateVertexShader(device, mova_test, &mova_shader);
924 ok(SUCCEEDED(hr), "CreateVertexShader failed (%08x)\n", hr);
925 hr = IDirect3DDevice9_CreateVertexShader(device, mov_test, &mov_shader);
926 ok(SUCCEEDED(hr), "CreateVertexShader failed (%08x)\n", hr);
927 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &vertex_declaration);
928 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (%08x)\n", hr);
929 hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration);
930 ok(SUCCEEDED(hr), "SetVertexDeclaration failed (%08x)\n", hr);
932 hr = IDirect3DDevice9_SetVertexShader(device, mov_shader);
933 ok(SUCCEEDED(hr), "SetVertexShader failed (%08x)\n", hr);
934 for (j = 0; j < sizeof(test_data) / sizeof(*test_data); ++j)
936 for (i = 0; i < sizeof(*test_data) / sizeof(**test_data); ++i)
938 DWORD color;
940 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 7, test_data[j][i].in, 1);
941 ok(SUCCEEDED(hr), "SetVertexShaderConstantF failed (%08x)\n", hr);
943 hr = IDirect3DDevice9_BeginScene(device);
944 ok(SUCCEEDED(hr), "BeginScene failed (%08x)\n", hr);
946 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
947 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%08x)\n", hr);
949 hr = IDirect3DDevice9_EndScene(device);
950 ok(SUCCEEDED(hr), "EndScene failed (%08x)\n", hr);
952 color = getPixelColor(device, 320, 240);
953 ok(color == test_data[j][i].out, "Expected color %08x, got %08x (for input %f, instruction %s)\n",
954 test_data[j][i].out, color, test_data[j][i].in[0], j == 0 ? "mov" : "mova");
956 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
957 ok(SUCCEEDED(hr), "Present failed (%08x)\n", hr);
959 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0, 0.0f, 0);
960 ok(SUCCEEDED(hr), "Clear failed (%08x)\n", hr);
962 hr = IDirect3DDevice9_SetVertexShader(device, mova_shader);
963 ok(SUCCEEDED(hr), "SetVertexShader failed (%08x)\n", hr);
966 IDirect3DVertexDeclaration9_Release(vertex_declaration);
967 IDirect3DVertexShader9_Release(mova_shader);
968 IDirect3DVertexShader9_Release(mov_shader);
969 refcount = IDirect3DDevice9_Release(device);
970 ok(!refcount, "Device has %u references left.\n", refcount);
971 done:
972 IDirect3D9_Release(d3d);
973 DestroyWindow(window);
976 static void fog_test(void)
978 float start = 0.0f, end = 1.0f;
979 IDirect3DDevice9 *device;
980 IDirect3D9 *d3d;
981 D3DCOLOR color;
982 ULONG refcount;
983 D3DCAPS9 caps;
984 HWND window;
985 HRESULT hr;
986 int i;
988 /* Gets full z based fog with linear fog, no fog with specular color. */
989 static const struct
991 float x, y, z;
992 D3DCOLOR diffuse;
993 D3DCOLOR specular;
995 untransformed_1[] =
997 {-1.0f, -1.0f, 0.1f, 0xffff0000, 0xff000000},
998 {-1.0f, 0.0f, 0.1f, 0xffff0000, 0xff000000},
999 { 0.0f, 0.0f, 0.1f, 0xffff0000, 0xff000000},
1000 { 0.0f, -1.0f, 0.1f, 0xffff0000, 0xff000000},
1002 /* Ok, I am too lazy to deal with transform matrices. */
1003 untransformed_2[] =
1005 {-1.0f, 0.0f, 1.0f, 0xffff0000, 0xff000000},
1006 {-1.0f, 1.0f, 1.0f, 0xffff0000, 0xff000000},
1007 { 0.0f, 1.0f, 1.0f, 0xffff0000, 0xff000000},
1008 { 0.0f, 0.0f, 1.0f, 0xffff0000, 0xff000000},
1010 untransformed_3[] =
1012 {-1.0f, -1.0f, 0.4999f, 0xffff0000, 0xff000000},
1013 {-1.0f, 1.0f, 0.4999f, 0xffff0000, 0xff000000},
1014 { 1.0f, -1.0f, 0.4999f, 0xffff0000, 0xff000000},
1015 { 1.0f, 1.0f, 0.4999f, 0xffff0000, 0xff000000},
1017 far_quad1[] =
1019 {-1.0f, -1.0f, 0.5f, 0xffff0000, 0xff000000},
1020 {-1.0f, 0.0f, 0.5f, 0xffff0000, 0xff000000},
1021 { 0.0f, 0.0f, 0.5f, 0xffff0000, 0xff000000},
1022 { 0.0f, -1.0f, 0.5f, 0xffff0000, 0xff000000},
1024 far_quad2[] =
1026 {-1.0f, 0.0f, 1.5f, 0xffff0000, 0xff000000},
1027 {-1.0f, 1.0f, 1.5f, 0xffff0000, 0xff000000},
1028 { 0.0f, 1.0f, 1.5f, 0xffff0000, 0xff000000},
1029 { 0.0f, 0.0f, 1.5f, 0xffff0000, 0xff000000},
1031 /* Untransformed ones. Give them a different diffuse color to make the
1032 * test look nicer. It also makes making sure that they are drawn
1033 * correctly easier. */
1034 static const struct
1036 float x, y, z, rhw;
1037 D3DCOLOR diffuse;
1038 D3DCOLOR specular;
1040 transformed_1[] =
1042 {320.0f, 0.0f, 1.0f, 1.0f, 0xffffff00, 0xff000000},
1043 {640.0f, 0.0f, 1.0f, 1.0f, 0xffffff00, 0xff000000},
1044 {640.0f, 240.0f, 1.0f, 1.0f, 0xffffff00, 0xff000000},
1045 {320.0f, 240.0f, 1.0f, 1.0f, 0xffffff00, 0xff000000},
1047 transformed_2[] =
1049 {320.0f, 240.0f, 1.0f, 1.0f, 0xffffff00, 0xff000000},
1050 {640.0f, 240.0f, 1.0f, 1.0f, 0xffffff00, 0xff000000},
1051 {640.0f, 480.0f, 1.0f, 1.0f, 0xffffff00, 0xff000000},
1052 {320.0f, 480.0f, 1.0f, 1.0f, 0xffffff00, 0xff000000},
1054 static const struct
1056 struct vec3 position;
1057 DWORD diffuse;
1059 rev_fog_quads[] =
1061 {{-1.0f, -1.0f, 0.1f}, 0x000000ff},
1062 {{-1.0f, 0.0f, 0.1f}, 0x000000ff},
1063 {{ 0.0f, 0.0f, 0.1f}, 0x000000ff},
1064 {{ 0.0f, -1.0f, 0.1f}, 0x000000ff},
1066 {{ 0.0f, -1.0f, 0.9f}, 0x000000ff},
1067 {{ 0.0f, 0.0f, 0.9f}, 0x000000ff},
1068 {{ 1.0f, 0.0f, 0.9f}, 0x000000ff},
1069 {{ 1.0f, -1.0f, 0.9f}, 0x000000ff},
1071 {{ 0.0f, 0.0f, 0.4f}, 0x000000ff},
1072 {{ 0.0f, 1.0f, 0.4f}, 0x000000ff},
1073 {{ 1.0f, 1.0f, 0.4f}, 0x000000ff},
1074 {{ 1.0f, 0.0f, 0.4f}, 0x000000ff},
1076 {{-1.0f, 0.0f, 0.7f}, 0x000000ff},
1077 {{-1.0f, 1.0f, 0.7f}, 0x000000ff},
1078 {{ 0.0f, 1.0f, 0.7f}, 0x000000ff},
1079 {{ 0.0f, 0.0f, 0.7f}, 0x000000ff},
1081 static const D3DMATRIX ident_mat =
1083 1.0f, 0.0f, 0.0f, 0.0f,
1084 0.0f, 1.0f, 0.0f, 0.0f,
1085 0.0f, 0.0f, 1.0f, 0.0f,
1086 0.0f, 0.0f, 0.0f, 1.0f
1087 }}};
1088 static const D3DMATRIX world_mat1 =
1090 1.0f, 0.0f, 0.0f, 0.0f,
1091 0.0f, 1.0f, 0.0f, 0.0f,
1092 0.0f, 0.0f, 1.0f, 0.0f,
1093 0.0f, 0.0f, -0.5f, 1.0f
1094 }}};
1095 static const D3DMATRIX world_mat2 =
1097 1.0f, 0.0f, 0.0f, 0.0f,
1098 0.0f, 1.0f, 0.0f, 0.0f,
1099 0.0f, 0.0f, 1.0f, 0.0f,
1100 0.0f, 0.0f, 1.0f, 1.0f
1101 }}};
1102 static const D3DMATRIX proj_mat =
1104 1.0f, 0.0f, 0.0f, 0.0f,
1105 0.0f, 1.0f, 0.0f, 0.0f,
1106 0.0f, 0.0f, 1.0f, 0.0f,
1107 0.0f, 0.0f, -1.0f, 1.0f
1108 }}};
1109 static const WORD Indices[] = {0, 1, 2, 2, 3, 0};
1110 static const WORD Indices2[] =
1112 0, 1, 2, 2, 3, 0,
1113 4, 5, 6, 6, 7, 4,
1114 8, 9, 10, 10, 11, 8,
1115 12, 13, 14, 14, 15, 12,
1118 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1119 0, 0, 640, 480, NULL, NULL, NULL, NULL);
1120 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1121 ok(!!d3d, "Failed to create a D3D object.\n");
1122 if (!(device = create_device(d3d, window, window, TRUE)))
1124 skip("Failed to create a D3D device, skipping tests.\n");
1125 goto done;
1128 memset(&caps, 0, sizeof(caps));
1129 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
1130 ok(hr == D3D_OK, "IDirect3DDevice9_GetDeviceCaps returned %08x\n", hr);
1131 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
1132 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
1134 /* Setup initial states: No lighting, fog on, fog color */
1135 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
1136 ok(SUCCEEDED(hr), "Failed to disable D3DRS_ZENABLE, hr %#x.\n", hr);
1137 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
1138 ok(hr == D3D_OK, "Turning off lighting returned %08x\n", hr);
1139 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGENABLE, TRUE);
1140 ok(hr == D3D_OK, "Turning on fog calculations returned %08x\n", hr);
1141 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGCOLOR, 0xff00ff00 /* A nice green */);
1142 ok(hr == D3D_OK, "Setting fog color returned %#08x\n", hr);
1143 /* Some of the tests seem to depend on the projection matrix explicitly
1144 * being set to an identity matrix, even though that's the default.
1145 * (AMD Radeon HD 6310, Windows 7) */
1146 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &ident_mat);
1147 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
1149 /* First test: Both table fog and vertex fog off */
1150 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_NONE);
1151 ok(hr == D3D_OK, "Turning off table fog returned %08x\n", hr);
1152 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGVERTEXMODE, D3DFOG_NONE);
1153 ok(hr == D3D_OK, "Turning off vertex fog returned %08x\n", hr);
1155 /* Start = 0, end = 1. Should be default, but set them */
1156 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGSTART, *((DWORD *) &start));
1157 ok(hr == D3D_OK, "Setting fog start returned %08x\n", hr);
1158 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGEND, *((DWORD *) &end));
1159 ok(hr == D3D_OK, "Setting fog end returned %08x\n", hr);
1161 hr = IDirect3DDevice9_BeginScene(device);
1162 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1164 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
1165 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
1167 /* Untransformed, vertex fog = NONE, table fog = NONE:
1168 * Read the fog weighting from the specular color. */
1169 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
1170 2 /* PrimCount */, Indices, D3DFMT_INDEX16, untransformed_1, sizeof(untransformed_1[0]));
1171 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1173 /* That makes it use the Z value */
1174 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR);
1175 ok(SUCCEEDED(hr), "Failed to set D3DFOG_LINEAR fog vertex mode, hr %#x.\n", hr);
1176 /* Untransformed, vertex fog != none (or table fog != none):
1177 * Use the Z value as input into the equation. */
1178 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
1179 2 /* PrimCount */, Indices, D3DFMT_INDEX16, untransformed_2, sizeof(untransformed_2[0]));
1180 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1182 /* transformed verts */
1183 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
1184 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
1185 /* Transformed, vertex fog != NONE, pixel fog == NONE:
1186 * Use specular color alpha component. */
1187 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
1188 2 /* PrimCount */, Indices, D3DFMT_INDEX16, transformed_1, sizeof(transformed_1[0]));
1189 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1191 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);
1192 ok(SUCCEEDED(hr), "Failed to set D3DFOG_LINEAR fog table mode, hr %#x.\n", hr);
1193 /* Transformed, table fog != none, vertex anything:
1194 * Use Z value as input to the fog equation. */
1195 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
1196 2 /* PrimCount */, Indices, D3DFMT_INDEX16, transformed_2, sizeof(transformed_2[0]));
1197 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1199 hr = IDirect3DDevice9_EndScene(device);
1200 ok(hr == D3D_OK, "EndScene returned %08x\n", hr);
1202 color = getPixelColor(device, 160, 360);
1203 ok(color == 0x00ff0000, "Untransformed vertex with no table or vertex fog has color %08x\n", color);
1204 color = getPixelColor(device, 160, 120);
1205 ok(color_match(color, 0x0000ff00, 1), "Untransformed vertex with linear vertex fog has color %08x\n", color);
1206 color = getPixelColor(device, 480, 120);
1207 ok(color == 0x00ffff00, "Transformed vertex with linear vertex fog has color %08x\n", color);
1208 if(caps.RasterCaps & D3DPRASTERCAPS_FOGTABLE)
1210 color = getPixelColor(device, 480, 360);
1211 ok(color_match(color, 0x0000ff00, 1), "Transformed vertex with linear table fog has color %08x\n", color);
1213 else
1215 /* Without fog table support the vertex fog is still applied, even though table fog is turned on.
1216 * The settings above result in no fogging with vertex fog
1218 color = getPixelColor(device, 480, 120);
1219 ok(color == 0x00ffff00, "Transformed vertex with linear vertex fog has color %08x\n", color);
1220 trace("Info: Table fog not supported by this device\n");
1222 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
1224 /* Now test the special case fogstart == fogend */
1225 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0, 0);
1226 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
1228 hr = IDirect3DDevice9_BeginScene(device);
1229 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1231 start = 512;
1232 end = 512;
1233 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGSTART, *((DWORD *)&start));
1234 ok(SUCCEEDED(hr), "Failed to set fog start, hr %#x.\n", hr);
1235 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGEND, *((DWORD *)&end));
1236 ok(SUCCEEDED(hr), "Failed to set fog end, hr %#x.\n", hr);
1238 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
1239 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
1240 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR);
1241 ok(SUCCEEDED(hr), "Failed to set D3DFOG_LINEAR fog vertex mode, hr %#x.\n", hr);
1242 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_NONE);
1243 ok(SUCCEEDED(hr), "Failed to set D3DFOG_NONE fog table mode, hr %#x.\n", hr);
1245 /* Untransformed vertex, z coord = 0.1, fogstart = 512, fogend = 512.
1246 * Would result in a completely fog-free primitive because start > zcoord,
1247 * but because start == end, the primitive is fully covered by fog. The
1248 * same happens to the 2nd untransformed quad with z = 1.0. The third
1249 * transformed quad remains unfogged because the fogcoords are read from
1250 * the specular color and has fixed fogstart and fogend. */
1251 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
1252 2 /* PrimCount */, Indices, D3DFMT_INDEX16, untransformed_1, sizeof(untransformed_1[0]));
1253 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1254 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
1255 2 /* PrimCount */, Indices, D3DFMT_INDEX16, untransformed_2, sizeof(untransformed_2[0]));
1256 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1258 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
1259 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
1260 /* Transformed, vertex fog != NONE, pixel fog == NONE:
1261 * Use specular color alpha component. */
1262 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
1263 2 /* PrimCount */, Indices, D3DFMT_INDEX16, transformed_1, sizeof(transformed_1[0]));
1264 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1266 hr = IDirect3DDevice9_EndScene(device);
1267 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1269 color = getPixelColor(device, 160, 360);
1270 ok(color_match(color, 0x0000ff00, 1), "Untransformed vertex with vertex fog and z = 0.1 has color %08x\n", color);
1271 color = getPixelColor(device, 160, 120);
1272 ok(color_match(color, 0x0000ff00, 1), "Untransformed vertex with vertex fog and z = 1.0 has color %08x\n", color);
1273 color = getPixelColor(device, 480, 120);
1274 ok(color == 0x00ffff00, "Transformed vertex with linear vertex fog has color %08x\n", color);
1275 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
1277 /* Test "reversed" fog without shaders. With shaders this fails on a few Windows D3D implementations,
1278 * but without shaders it seems to work everywhere
1280 end = 0.2;
1281 start = 0.8;
1282 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGSTART, *((DWORD *) &start));
1283 ok(hr == D3D_OK, "Setting fog start returned %08x\n", hr);
1284 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGEND, *((DWORD *) &end));
1285 ok(hr == D3D_OK, "Setting fog end returned %08x\n", hr);
1286 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
1287 ok( hr == D3D_OK, "IDirect3DDevice9_SetFVF returned %08x\n", hr);
1289 /* Test reversed fog without shaders. ATI cards have problems with reversed fog and shaders, so
1290 * it doesn't seem very important for games. ATI cards also have problems with reversed table fog,
1291 * so skip this for now
1293 for(i = 0; i < 1 /*2 - Table fog test disabled, fails on ATI */; i++) {
1294 const char *mode = (i ? "table" : "vertex");
1295 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
1296 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
1297 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGVERTEXMODE, i == 0 ? D3DFOG_LINEAR : D3DFOG_NONE);
1298 ok( hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
1299 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, i == 0 ? D3DFOG_NONE : D3DFOG_LINEAR);
1300 ok( hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
1301 hr = IDirect3DDevice9_BeginScene(device);
1302 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1303 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 16 /* NumVerts */,
1304 8 /* PrimCount */, Indices2, D3DFMT_INDEX16, rev_fog_quads, sizeof(rev_fog_quads[0]));
1305 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1306 hr = IDirect3DDevice9_EndScene(device);
1307 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1309 color = getPixelColor(device, 160, 360);
1310 ok(color_match(color, 0x0000ff00, 1),
1311 "Reversed %s fog: z=0.1 has color 0x%08x, expected 0x0000ff00 or 0x0000fe00\n", mode, color);
1313 color = getPixelColor(device, 160, 120);
1314 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0x2b, 0xd4), 2),
1315 "Reversed %s fog: z=0.7 has color 0x%08x\n", mode, color);
1317 color = getPixelColor(device, 480, 120);
1318 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xaa, 0x55), 2),
1319 "Reversed %s fog: z=0.4 has color 0x%08x\n", mode, color);
1321 color = getPixelColor(device, 480, 360);
1322 ok(color == 0x000000ff, "Reversed %s fog: z=0.9 has color 0x%08x, expected 0x000000ff\n", mode, color);
1324 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
1326 if(!(caps.RasterCaps & D3DPRASTERCAPS_FOGTABLE)) {
1327 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping reversed table fog test\n");
1328 break;
1332 if (caps.RasterCaps & D3DPRASTERCAPS_FOGTABLE)
1334 /* A simple fog + non-identity world matrix test */
1335 hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLDMATRIX(0), &world_mat1);
1336 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform returned %#08x\n", hr);
1338 start = 0.0;
1339 end = 1.0;
1340 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGSTART, *((DWORD *)&start));
1341 ok(hr == D3D_OK, "Setting fog start returned %08x\n", hr);
1342 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGEND, *((DWORD *)&end));
1343 ok(hr == D3D_OK, "Setting fog end returned %08x\n", hr);
1344 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);
1345 ok(hr == D3D_OK, "Setting fog table mode to D3DFOG_LINEAR returned %#08x\n", hr);
1346 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGVERTEXMODE, D3DFOG_NONE);
1347 ok(hr == D3D_OK, "Turning off vertex fog returned %#08x\n", hr);
1349 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
1350 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %#08x\n", hr);
1352 hr = IDirect3DDevice9_BeginScene(device);
1353 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1355 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
1356 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
1358 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4,
1359 2, Indices, D3DFMT_INDEX16, far_quad1, sizeof(far_quad1[0]));
1360 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1361 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4,
1362 2, Indices, D3DFMT_INDEX16, far_quad2, sizeof(far_quad2[0]));
1363 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1365 hr = IDirect3DDevice9_EndScene(device);
1366 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1368 color = getPixelColor(device, 160, 360);
1369 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x00), 4),
1370 "Unfogged quad has color %08x\n", color);
1371 color = getPixelColor(device, 160, 120);
1372 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1),
1373 "Fogged out quad has color %08x\n", color);
1375 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
1377 /* Test fog behavior with an orthogonal (but non-identity) projection matrix */
1378 hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLDMATRIX(0), &world_mat2);
1379 ok(hr == D3D_OK, "SetTransform returned %#08x\n", hr);
1380 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &proj_mat);
1381 ok(hr == D3D_OK, "SetTransform returned %#08x\n", hr);
1383 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
1384 ok(hr == D3D_OK, "Clear returned %#08x\n", hr);
1386 hr = IDirect3DDevice9_BeginScene(device);
1387 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1389 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
1390 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
1392 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4,
1393 2, Indices, D3DFMT_INDEX16, untransformed_1, sizeof(untransformed_1[0]));
1394 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1395 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4,
1396 2, Indices, D3DFMT_INDEX16, untransformed_2, sizeof(untransformed_2[0]));
1397 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1399 hr = IDirect3DDevice9_EndScene(device);
1400 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1402 color = getPixelColor(device, 160, 360);
1403 ok(color_match(color, 0x00e51900, 4), "Partially fogged quad has color %08x\n", color);
1404 color = getPixelColor(device, 160, 120);
1405 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1),
1406 "Fogged out quad has color %08x\n", color);
1408 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
1410 hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLDMATRIX(0), &ident_mat);
1411 ok(hr == D3D_OK, "SetTransform returned %#08x\n", hr);
1412 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &ident_mat);
1413 ok(hr == D3D_OK, "SetTransform returned %#08x\n", hr);
1415 else
1417 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests\n");
1420 /* Test RANGEFOG vs FOGTABLEMODE */
1421 if ((caps.RasterCaps & (D3DPRASTERCAPS_FOGTABLE | D3DPRASTERCAPS_FOGRANGE)) ==
1422 (D3DPRASTERCAPS_FOGTABLE | D3DPRASTERCAPS_FOGRANGE))
1424 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
1425 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear failed, hr %#x.\n", hr);
1426 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
1427 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetFVF failed, hr %#x.\n", hr);
1429 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_RANGEFOGENABLE, TRUE);
1430 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr);
1432 /* z=0.4999, set the fogstart to 0.5 and fogend slightly higher. If range fog
1433 * is not used, the fog coordinate will be equal to fogstart and the quad not
1434 * fogged. If range fog is used the fog coordinate will be slightly higher and
1435 * the fog coordinate will be > fogend, so we get a fully fogged quad. The fog
1436 * is calculated per vertex and interpolated, so even the center of the screen
1437 * where the difference doesn't matter will be fogged, but check the corners in
1438 * case a d3d/gl implementation decides to calculate the fog factor per fragment */
1439 start = 0.5f;
1440 end = 0.50001f;
1441 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGSTART, *((DWORD *) &start));
1442 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr);
1443 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGEND, *((DWORD *) &end));
1444 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr);
1446 /* Table fog: Range fog is not used */
1447 hr = IDirect3DDevice9_BeginScene(device);
1448 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1450 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);
1451 ok(SUCCEEDED(hr), "Failed to set D3DFOG_LINEAR fog table mode, hr %#x.\n", hr);
1452 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2,
1453 untransformed_3, sizeof(*untransformed_3));
1454 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1456 hr = IDirect3DDevice9_EndScene(device);
1457 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1459 color = getPixelColor(device, 10, 10);
1460 ok(color == 0x00ff0000, "Rangefog with table fog returned color 0x%08x\n", color);
1461 color = getPixelColor(device, 630, 10);
1462 ok(color == 0x00ff0000, "Rangefog with table fog returned color 0x%08x\n", color);
1463 color = getPixelColor(device, 10, 470);
1464 ok(color == 0x00ff0000, "Rangefog with table fog returned color 0x%08x\n", color);
1465 color = getPixelColor(device, 630, 470);
1466 ok(color == 0x00ff0000, "Rangefog with table fog returned color 0x%08x\n", color);
1468 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
1469 ok(SUCCEEDED(hr), "IDirect3DDevice9_Present failed, hr %#x.\n", hr);
1471 /* Vertex fog: Rangefog is used */
1472 hr = IDirect3DDevice9_BeginScene(device);
1473 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1475 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_NONE);
1476 ok(SUCCEEDED(hr), "Failed to set D3DFOG_NONE fog table mode, hr %#x.\n", hr);
1477 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR);
1478 ok(SUCCEEDED(hr), "Failed to set D3DFOG_LINEAR fog vertex mode, hr %#x.\n", hr);
1479 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2,
1480 untransformed_3, sizeof(*untransformed_3));
1481 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1483 hr = IDirect3DDevice9_EndScene(device);
1484 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1486 color = getPixelColor(device, 10, 10);
1487 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1),
1488 "Rangefog with vertex fog returned color 0x%08x\n", color);
1489 color = getPixelColor(device, 630, 10);
1490 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1),
1491 "Rangefog with vertex fog returned color 0x%08x\n", color);
1492 color = getPixelColor(device, 10, 470);
1493 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1),
1494 "Rangefog with vertex fog returned color 0x%08x\n", color);
1495 color = getPixelColor(device, 630, 470);
1496 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1),
1497 "Rangefog with vertex fog returned color 0x%08x\n", color);
1499 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
1500 ok(SUCCEEDED(hr), "IDirect3DDevice9_Present failed, hr %#x.\n", hr);
1502 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_RANGEFOGENABLE, FALSE);
1503 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr);
1505 else
1507 skip("Range fog or table fog not supported, skipping range fog tests\n");
1510 refcount = IDirect3DDevice9_Release(device);
1511 ok(!refcount, "Device has %u references left.\n", refcount);
1512 done:
1513 IDirect3D9_Release(d3d);
1514 DestroyWindow(window);
1517 /* This test verifies the behaviour of cube maps wrt. texture wrapping.
1518 * D3D cube map wrapping always behaves like GL_CLAMP_TO_EDGE,
1519 * regardless of the actual addressing mode set. The way this test works is
1520 * that we sample in one of the corners of the cubemap with filtering enabled,
1521 * and check the interpolated color. There are essentially two reasonable
1522 * things an implementation can do: Either pick one of the faces and
1523 * interpolate the edge texel with itself (i.e., clamp within the face), or
1524 * interpolate between the edge texels of the three involved faces. It should
1525 * never involve the border color or the other side (texcoord wrapping) of a
1526 * face in the interpolation. */
1527 static void test_cube_wrap(void)
1529 IDirect3DVertexDeclaration9 *vertex_declaration;
1530 IDirect3DSurface9 *face_surface, *surface;
1531 IDirect3DCubeTexture9 *texture;
1532 D3DLOCKED_RECT locked_rect;
1533 IDirect3DDevice9 *device;
1534 unsigned int x, y, face;
1535 IDirect3D9 *d3d;
1536 ULONG refcount;
1537 D3DCAPS9 caps;
1538 HWND window;
1539 HRESULT hr;
1541 static const float quad[][6] =
1543 {-1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f},
1544 {-1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f},
1545 { 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f},
1546 { 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f},
1548 static const D3DVERTEXELEMENT9 decl_elements[] =
1550 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
1551 {0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
1552 D3DDECL_END()
1554 static const struct
1556 D3DTEXTUREADDRESS mode;
1557 const char *name;
1559 address_modes[] =
1561 {D3DTADDRESS_WRAP, "D3DTADDRESS_WRAP"},
1562 {D3DTADDRESS_MIRROR, "D3DTADDRESS_MIRROR"},
1563 {D3DTADDRESS_CLAMP, "D3DTADDRESS_CLAMP"},
1564 {D3DTADDRESS_BORDER, "D3DTADDRESS_BORDER"},
1565 {D3DTADDRESS_MIRRORONCE, "D3DTADDRESS_MIRRORONCE"},
1568 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1569 0, 0, 640, 480, NULL, NULL, NULL, NULL);
1570 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1571 ok(!!d3d, "Failed to create a D3D object.\n");
1572 if (!(device = create_device(d3d, window, window, TRUE)))
1574 skip("Failed to create a D3D device, skipping tests.\n");
1575 goto done;
1578 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
1579 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
1580 if (!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP))
1582 skip("No cube texture support, skipping tests.\n");
1583 IDirect3DDevice9_Release(device);
1584 goto done;
1587 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &vertex_declaration);
1588 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (0x%08x)\n", hr);
1589 hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration);
1590 ok(SUCCEEDED(hr), "SetVertexDeclaration failed (0x%08x)\n", hr);
1592 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 128, 128,
1593 D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surface, NULL);
1594 ok(SUCCEEDED(hr), "CreateOffscreenPlainSurface failed (0x%08x)\n", hr);
1596 hr = IDirect3DDevice9_CreateCubeTexture(device, 128, 1, 0, D3DFMT_A8R8G8B8,
1597 D3DPOOL_DEFAULT, &texture, NULL);
1598 ok(SUCCEEDED(hr), "CreateCubeTexture failed (0x%08x)\n", hr);
1600 hr = IDirect3DSurface9_LockRect(surface, &locked_rect, NULL, 0);
1601 ok(SUCCEEDED(hr), "LockRect failed (0x%08x)\n", hr);
1603 for (y = 0; y < 128; ++y)
1605 DWORD *ptr = (DWORD *)(((BYTE *)locked_rect.pBits) + (y * locked_rect.Pitch));
1606 for (x = 0; x < 64; ++x)
1608 *ptr++ = 0xff0000ff;
1610 for (x = 64; x < 128; ++x)
1612 *ptr++ = 0xffff0000;
1616 hr = IDirect3DSurface9_UnlockRect(surface);
1617 ok(SUCCEEDED(hr), "UnlockRect failed (0x%08x)\n", hr);
1619 hr= IDirect3DCubeTexture9_GetCubeMapSurface(texture, 0, 0, &face_surface);
1620 ok(SUCCEEDED(hr), "GetCubeMapSurface failed (0x%08x)\n", hr);
1622 hr = IDirect3DDevice9_UpdateSurface(device, surface, NULL, face_surface, NULL);
1623 ok(SUCCEEDED(hr), "UpdateSurface failed (0x%08x)\n", hr);
1625 IDirect3DSurface9_Release(face_surface);
1627 hr = IDirect3DSurface9_LockRect(surface, &locked_rect, NULL, 0);
1628 ok(SUCCEEDED(hr), "LockRect failed (0x%08x)\n", hr);
1630 for (y = 0; y < 128; ++y)
1632 DWORD *ptr = (DWORD *)(((BYTE *)locked_rect.pBits) + (y * locked_rect.Pitch));
1633 for (x = 0; x < 64; ++x)
1635 *ptr++ = 0xffff0000;
1637 for (x = 64; x < 128; ++x)
1639 *ptr++ = 0xff0000ff;
1643 hr = IDirect3DSurface9_UnlockRect(surface);
1644 ok(SUCCEEDED(hr), "UnlockRect failed (0x%08x)\n", hr);
1646 /* Create cube faces */
1647 for (face = 1; face < 6; ++face)
1649 hr= IDirect3DCubeTexture9_GetCubeMapSurface(texture, face, 0, &face_surface);
1650 ok(SUCCEEDED(hr), "GetCubeMapSurface failed (0x%08x)\n", hr);
1652 hr = IDirect3DDevice9_UpdateSurface(device, surface, NULL, face_surface, NULL);
1653 ok(SUCCEEDED(hr), "UpdateSurface failed (0x%08x)\n", hr);
1655 IDirect3DSurface9_Release(face_surface);
1658 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
1659 ok(SUCCEEDED(hr), "SetTexture failed (0x%08x)\n", hr);
1661 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
1662 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_MINFILTER failed (0x%08x)\n", hr);
1663 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
1664 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr);
1665 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_BORDERCOLOR, 0xff00ff00);
1666 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_BORDERCOLOR failed (0x%08x)\n", hr);
1668 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
1669 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
1671 for (x = 0; x < (sizeof(address_modes) / sizeof(*address_modes)); ++x)
1673 DWORD color;
1675 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSU, address_modes[x].mode);
1676 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_ADDRESSU (%s) failed (0x%08x)\n", address_modes[x].name, hr);
1677 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSV, address_modes[x].mode);
1678 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_ADDRESSV (%s) failed (0x%08x)\n", address_modes[x].name, hr);
1680 hr = IDirect3DDevice9_BeginScene(device);
1681 ok(SUCCEEDED(hr), "BeginScene failed (0x%08x)\n", hr);
1683 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], sizeof(quad[0]));
1684 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (0x%08x)\n", hr);
1686 hr = IDirect3DDevice9_EndScene(device);
1687 ok(SUCCEEDED(hr), "EndScene failed (0x%08x)\n", hr);
1689 color = getPixelColor(device, 320, 240);
1690 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0xff), 1),
1691 "Got color 0x%08x for addressing mode %s, expected 0x000000ff.\n",
1692 color, address_modes[x].name);
1694 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
1695 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
1697 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0, 0.0f, 0);
1698 ok(SUCCEEDED(hr), "Clear failed (0x%08x)\n", hr);
1701 IDirect3DVertexDeclaration9_Release(vertex_declaration);
1702 IDirect3DCubeTexture9_Release(texture);
1703 IDirect3DSurface9_Release(surface);
1704 refcount = IDirect3DDevice9_Release(device);
1705 ok(!refcount, "Device has %u references left.\n", refcount);
1706 done:
1707 IDirect3D9_Release(d3d);
1708 DestroyWindow(window);
1711 static void offscreen_test(void)
1713 IDirect3DSurface9 *backbuffer, *offscreen;
1714 IDirect3DTexture9 *offscreenTexture;
1715 IDirect3DDevice9 *device;
1716 IDirect3D9 *d3d;
1717 D3DCOLOR color;
1718 ULONG refcount;
1719 HWND window;
1720 HRESULT hr;
1722 static const float quad[][5] =
1724 {-0.5f, -0.5f, 0.1f, 0.0f, 0.0f},
1725 {-0.5f, 0.5f, 0.1f, 0.0f, 1.0f},
1726 { 0.5f, -0.5f, 0.1f, 1.0f, 0.0f},
1727 { 0.5f, 0.5f, 0.1f, 1.0f, 1.0f},
1730 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1731 0, 0, 640, 480, NULL, NULL, NULL, NULL);
1732 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1733 ok(!!d3d, "Failed to create a D3D object.\n");
1734 if (!(device = create_device(d3d, window, window, TRUE)))
1736 skip("Failed to create a D3D device, skipping tests.\n");
1737 goto done;
1740 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 1.0f, 0);
1741 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
1743 hr = IDirect3DDevice9_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET,
1744 D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &offscreenTexture, NULL);
1745 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Creating the offscreen render target failed, hr = %08x\n", hr);
1746 if (!offscreenTexture)
1748 trace("Failed to create an X8R8G8B8 offscreen texture, trying R5G6B5.\n");
1749 hr = IDirect3DDevice9_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET,
1750 D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &offscreenTexture, NULL);
1751 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Creating the offscreen render target failed, hr = %08x\n", hr);
1752 if (!offscreenTexture)
1754 skip("Cannot create an offscreen render target.\n");
1755 IDirect3DDevice9_Release(device);
1756 goto done;
1760 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
1761 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
1763 hr = IDirect3DTexture9_GetSurfaceLevel(offscreenTexture, 0, &offscreen);
1764 ok(hr == D3D_OK, "Can't get offscreen surface, hr = %08x\n", hr);
1766 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
1767 ok(hr == D3D_OK, "SetFVF failed, hr = %08x\n", hr);
1769 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
1770 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
1771 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
1772 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
1773 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
1774 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_MINFILTER failed (0x%08x)\n", hr);
1775 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
1776 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr);
1777 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
1778 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
1780 hr = IDirect3DDevice9_BeginScene(device);
1781 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1783 hr = IDirect3DDevice9_SetRenderTarget(device, 0, offscreen);
1784 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
1785 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 1.0f, 0);
1786 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
1788 /* Draw without textures - Should result in a white quad. */
1789 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
1790 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1792 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
1793 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
1794 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)offscreenTexture);
1795 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
1797 /* This time with the texture. */
1798 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
1799 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1801 hr = IDirect3DDevice9_EndScene(device);
1802 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1804 /* Center quad - should be white */
1805 color = getPixelColor(device, 320, 240);
1806 ok(color == 0x00ffffff, "Offscreen failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
1807 /* Some quad in the cleared part of the texture */
1808 color = getPixelColor(device, 170, 240);
1809 ok(color == 0x00ff00ff, "Offscreen failed: Got color 0x%08x, expected 0x00ff00ff.\n", color);
1810 /* Part of the originally cleared back buffer */
1811 color = getPixelColor(device, 10, 10);
1812 ok(color == 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
1813 color = getPixelColor(device, 10, 470);
1814 ok(color == 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
1816 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
1818 IDirect3DSurface9_Release(backbuffer);
1819 IDirect3DTexture9_Release(offscreenTexture);
1820 IDirect3DSurface9_Release(offscreen);
1821 refcount = IDirect3DDevice9_Release(device);
1822 ok(!refcount, "Device has %u references left.\n", refcount);
1823 done:
1824 IDirect3D9_Release(d3d);
1825 DestroyWindow(window);
1828 /* This test tests fog in combination with shaders.
1829 * What's tested: linear fog (vertex and table) with pixel shader
1830 * linear table fog with non foggy vertex shader
1831 * vertex fog with foggy vertex shader, non-linear
1832 * fog with shader, non-linear fog with foggy shader,
1833 * linear table fog with foggy shader */
1834 static void fog_with_shader_test(void)
1836 IDirect3DVertexShader9 *vertex_shader[4] = {NULL, NULL, NULL, NULL};
1837 IDirect3DPixelShader9 *pixel_shader[3] = {NULL, NULL, NULL};
1838 IDirect3DVertexDeclaration9 *vertex_declaration = NULL;
1839 IDirect3DDevice9 *device;
1840 unsigned int i, j;
1841 IDirect3D9 *d3d;
1842 ULONG refcount;
1843 D3DCAPS9 caps;
1844 DWORD color;
1845 HWND window;
1846 HRESULT hr;
1847 union
1849 float f;
1850 DWORD i;
1851 } start, end;
1853 /* basic vertex shader without fog computation ("non foggy") */
1854 static const DWORD vertex_shader_code1[] =
1856 0xfffe0101, /* vs_1_1 */
1857 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
1858 0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
1859 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
1860 0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
1861 0x0000ffff
1863 /* basic vertex shader with reversed fog computation ("foggy") */
1864 static const DWORD vertex_shader_code2[] =
1866 0xfffe0101, /* vs_1_1 */
1867 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
1868 0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
1869 0x00000051, 0xa00f0000, 0xbfa00000, 0x00000000, 0xbf666666, 0x00000000, /* def c0, -1.25, 0.0, -0.9, 0.0 */
1870 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
1871 0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
1872 0x00000002, 0x800f0000, 0x90aa0000, 0xa0aa0000, /* add r0, v0.z, c0.z */
1873 0x00000005, 0xc00f0001, 0x80000000, 0xa0000000, /* mul oFog, r0.x, c0.x */
1874 0x0000ffff
1876 /* basic vertex shader with reversed fog computation ("foggy"), vs_2_0 */
1877 static const DWORD vertex_shader_code3[] =
1879 0xfffe0200, /* vs_2_0 */
1880 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
1881 0x0200001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
1882 0x05000051, 0xa00f0000, 0xbfa00000, 0x00000000, 0xbf666666, 0x00000000, /* def c0, -1.25, 0.0, -0.9, 0.0 */
1883 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
1884 0x02000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
1885 0x03000002, 0x800f0000, 0x90aa0000, 0xa0aa0000, /* add r0, v0.z, c0.z */
1886 0x03000005, 0xc00f0001, 0x80000000, 0xa0000000, /* mul oFog, r0.x, c0.x */
1887 0x0000ffff
1889 /* basic pixel shader */
1890 static const DWORD pixel_shader_code[] =
1892 0xffff0101, /* ps_1_1 */
1893 0x00000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
1894 0x0000ffff
1896 static const DWORD pixel_shader_code2[] =
1898 0xffff0200, /* ps_2_0 */
1899 0x0200001f, 0x80000000, 0x900f0000, /* dcl v0 */
1900 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
1901 0x0000ffff
1903 struct
1905 struct vec3 position;
1906 DWORD diffuse;
1908 quad[] =
1910 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
1911 {{-1.0f, 1.0f, 0.0f}, 0xffff0000},
1912 {{ 1.0f, -1.0f, 0.0f}, 0xffff0000},
1913 {{ 1.0f, 1.0f, 0.0f}, 0xffff0000},
1915 static const D3DVERTEXELEMENT9 decl_elements[] =
1917 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
1918 {0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
1919 D3DDECL_END()
1921 /* This reference data was collected on a nVidia GeForce 7600GS driver
1922 * version 84.19 DirectX version 9.0c on Windows XP. */
1923 static const struct test_data_t
1925 int vshader;
1926 int pshader;
1927 D3DFOGMODE vfog;
1928 D3DFOGMODE tfog;
1929 unsigned int color[11];
1931 test_data[] =
1933 /* only pixel shader: */
1934 {0, 1, D3DFOG_NONE, D3DFOG_LINEAR,
1935 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
1936 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
1937 {0, 1, D3DFOG_EXP, D3DFOG_LINEAR,
1938 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
1939 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
1940 {0, 1, D3DFOG_EXP2, D3DFOG_LINEAR,
1941 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
1942 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
1943 {0, 1, D3DFOG_LINEAR, D3DFOG_NONE,
1944 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
1945 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
1946 {0, 1, D3DFOG_LINEAR, D3DFOG_LINEAR,
1947 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
1948 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
1950 /* vertex shader */
1951 {1, 0, D3DFOG_NONE, D3DFOG_NONE,
1952 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
1953 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00}},
1954 {1, 0, D3DFOG_NONE, D3DFOG_LINEAR,
1955 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
1956 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
1957 {1, 0, D3DFOG_EXP, D3DFOG_LINEAR,
1958 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
1959 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
1961 {1, 0, D3DFOG_EXP2, D3DFOG_LINEAR,
1962 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
1963 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
1964 {1, 0, D3DFOG_LINEAR, D3DFOG_LINEAR,
1965 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
1966 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
1968 /* vertex shader and pixel shader */
1969 /* The next 4 tests would read the fog coord output, but it isn't available.
1970 * The result is a fully fogged quad, no matter what the Z coord is. This is on
1971 * a geforce 7400, 97.52 driver, Windows Vista, but probably hardware dependent.
1972 * These tests should be disabled if some other hardware behaves differently
1974 {1, 1, D3DFOG_NONE, D3DFOG_NONE,
1975 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
1976 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00}},
1977 {1, 1, D3DFOG_LINEAR, D3DFOG_NONE,
1978 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
1979 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00}},
1980 {1, 1, D3DFOG_EXP, D3DFOG_NONE,
1981 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
1982 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00}},
1983 {1, 1, D3DFOG_EXP2, D3DFOG_NONE,
1984 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
1985 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00}},
1987 /* These use the Z coordinate with linear table fog */
1988 {1, 1, D3DFOG_NONE, D3DFOG_LINEAR,
1989 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
1990 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
1991 {1, 1, D3DFOG_EXP, D3DFOG_LINEAR,
1992 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
1993 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
1994 {1, 1, D3DFOG_EXP2, D3DFOG_LINEAR,
1995 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
1996 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
1997 {1, 1, D3DFOG_LINEAR, D3DFOG_LINEAR,
1998 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
1999 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2001 /* Non-linear table fog without fog coord */
2002 {1, 1, D3DFOG_NONE, D3DFOG_EXP,
2003 {0x00ff0000, 0x00e71800, 0x00d12e00, 0x00bd4200, 0x00ab5400, 0x009b6400,
2004 0x008d7200, 0x007f8000, 0x00738c00, 0x00689700, 0x005ea100}},
2005 {1, 1, D3DFOG_NONE, D3DFOG_EXP2,
2006 {0x00fd0200, 0x00f50200, 0x00f50a00, 0x00e91600, 0x00d92600, 0x00c73800,
2007 0x00b24d00, 0x009c6300, 0x00867900, 0x00728d00, 0x005ea100}},
2009 /* These tests fail on older Nvidia drivers */
2010 /* foggy vertex shader */
2011 {2, 0, D3DFOG_NONE, D3DFOG_NONE,
2012 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2013 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2014 {2, 0, D3DFOG_EXP, D3DFOG_NONE,
2015 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2016 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2017 {2, 0, D3DFOG_EXP2, D3DFOG_NONE,
2018 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2019 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2020 {2, 0, D3DFOG_LINEAR, D3DFOG_NONE,
2021 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2022 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2024 {3, 0, D3DFOG_NONE, D3DFOG_NONE,
2025 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2026 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2027 {3, 0, D3DFOG_EXP, D3DFOG_NONE,
2028 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2029 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2030 {3, 0, D3DFOG_EXP2, D3DFOG_NONE,
2031 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2032 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2033 {3, 0, D3DFOG_LINEAR, D3DFOG_NONE,
2034 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2035 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2037 /* foggy vertex shader and pixel shader. First 4 tests with vertex fog,
2038 * all using the fixed fog-coord linear fog
2040 /* vs_1_1 with ps_1_1 */
2041 {2, 1, D3DFOG_NONE, D3DFOG_NONE,
2042 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2043 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2044 {2, 1, D3DFOG_EXP, D3DFOG_NONE,
2045 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2046 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2047 {2, 1, D3DFOG_EXP2, D3DFOG_NONE,
2048 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2049 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2050 {2, 1, D3DFOG_LINEAR, D3DFOG_NONE,
2051 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2052 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2054 /* vs_2_0 with ps_1_1 */
2055 {3, 1, D3DFOG_NONE, D3DFOG_NONE,
2056 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2057 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2058 {3, 1, D3DFOG_EXP, D3DFOG_NONE,
2059 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2060 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2061 {3, 1, D3DFOG_EXP2, D3DFOG_NONE,
2062 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2063 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2064 {3, 1, D3DFOG_LINEAR, D3DFOG_NONE,
2065 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2066 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2068 /* vs_1_1 with ps_2_0 */
2069 {2, 2, D3DFOG_NONE, D3DFOG_NONE,
2070 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2071 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2072 {2, 2, D3DFOG_EXP, D3DFOG_NONE,
2073 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2074 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2075 {2, 2, D3DFOG_EXP2, D3DFOG_NONE,
2076 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2077 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2078 {2, 2, D3DFOG_LINEAR, D3DFOG_NONE,
2079 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2080 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2082 /* vs_2_0 with ps_2_0 */
2083 {3, 2, D3DFOG_NONE, D3DFOG_NONE,
2084 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2085 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2086 {3, 2, D3DFOG_EXP, D3DFOG_NONE,
2087 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2088 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2089 {3, 2, D3DFOG_EXP2, D3DFOG_NONE,
2090 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2091 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2092 {3, 2, D3DFOG_LINEAR, D3DFOG_NONE,
2093 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2094 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2096 /* These use table fog. Here the shader-provided fog coordinate is
2097 * ignored and the z coordinate used instead
2099 {2, 1, D3DFOG_NONE, D3DFOG_EXP,
2100 {0x00ff0000, 0x00e71800, 0x00d12e00, 0x00bd4200, 0x00ab5400, 0x009b6400,
2101 0x008d7200, 0x007f8000, 0x00738c00, 0x00689700, 0x005ea100}},
2102 {2, 1, D3DFOG_NONE, D3DFOG_EXP2,
2103 {0x00fd0200, 0x00f50200, 0x00f50a00, 0x00e91600, 0x00d92600, 0x00c73800,
2104 0x00b24d00, 0x009c6300, 0x00867900, 0x00728d00, 0x005ea100}},
2105 {2, 1, D3DFOG_NONE, D3DFOG_LINEAR,
2106 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2107 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2109 static const D3DMATRIX identity =
2111 1.0f, 0.0f, 0.0f, 0.0f,
2112 0.0f, 1.0f, 0.0f, 0.0f,
2113 0.0f, 0.0f, 1.0f, 0.0f,
2114 0.0f, 0.0f, 0.0f, 1.0f,
2115 }}};
2117 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
2118 0, 0, 640, 480, NULL, NULL, NULL, NULL);
2119 d3d = Direct3DCreate9(D3D_SDK_VERSION);
2120 ok(!!d3d, "Failed to create a D3D object.\n");
2121 if (!(device = create_device(d3d, window, window, TRUE)))
2123 skip("Failed to create a D3D device, skipping tests.\n");
2124 goto done;
2127 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
2128 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
2129 if (caps.VertexShaderVersion < D3DVS_VERSION(2, 0) || caps.PixelShaderVersion < D3DPS_VERSION(2, 0))
2131 skip("No shader model 2 support, skipping tests.\n");
2132 IDirect3DDevice9_Release(device);
2133 goto done;
2136 /* NOTE: Changing these values will not affect the tests with foggy vertex
2137 * shader, as the values are hardcoded in the shader. */
2138 start.f = 0.1f;
2139 end.f = 0.9f;
2141 /* Some of the tests seem to depend on the projection matrix explicitly
2142 * being set to an identity matrix, even though that's the default.
2143 * (AMD Radeon HD 6310, Windows 7) */
2144 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &identity);
2145 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
2147 hr = IDirect3DDevice9_CreateVertexShader(device, vertex_shader_code1, &vertex_shader[1]);
2148 ok(SUCCEEDED(hr), "CreateVertexShader failed (%08x)\n", hr);
2149 hr = IDirect3DDevice9_CreateVertexShader(device, vertex_shader_code2, &vertex_shader[2]);
2150 ok(SUCCEEDED(hr), "CreateVertexShader failed (%08x)\n", hr);
2151 hr = IDirect3DDevice9_CreateVertexShader(device, vertex_shader_code3, &vertex_shader[3]);
2152 ok(SUCCEEDED(hr), "CreateVertexShader failed (%08x)\n", hr);
2153 hr = IDirect3DDevice9_CreatePixelShader(device, pixel_shader_code, &pixel_shader[1]);
2154 ok(SUCCEEDED(hr), "CreatePixelShader failed (%08x)\n", hr);
2155 hr = IDirect3DDevice9_CreatePixelShader(device, pixel_shader_code2, &pixel_shader[2]);
2156 ok(SUCCEEDED(hr), "CreatePixelShader failed (%08x)\n", hr);
2157 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &vertex_declaration);
2158 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (%08x)\n", hr);
2160 /* Setup initial states: No lighting, fog on, fog color */
2161 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
2162 ok(hr == D3D_OK, "Turning off lighting failed (%08x)\n", hr);
2163 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGENABLE, TRUE);
2164 ok(hr == D3D_OK, "Turning on fog calculations failed (%08x)\n", hr);
2165 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGCOLOR, 0xff00ff00 /* A nice green */);
2166 ok(hr == D3D_OK, "Setting fog color failed (%08x)\n", hr);
2167 hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration);
2168 ok(SUCCEEDED(hr), "SetVertexDeclaration failed (%08x)\n", hr);
2170 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, D3DFOG_NONE);
2171 ok(hr == D3D_OK, "Turning off table fog failed (%08x)\n", hr);
2172 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGVERTEXMODE, D3DFOG_NONE);
2173 ok(hr == D3D_OK, "Turning off vertex fog failed (%08x)\n", hr);
2175 /* Use fogtart = 0.1 and end = 0.9 to test behavior outside the fog transition phase, too*/
2176 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGSTART, start.i);
2177 ok(hr == D3D_OK, "Setting fog start failed (%08x)\n", hr);
2178 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGEND, end.i);
2179 ok(hr == D3D_OK, "Setting fog end failed (%08x)\n", hr);
2181 for (i = 0; i < sizeof(test_data)/sizeof(test_data[0]); i++)
2183 hr = IDirect3DDevice9_SetVertexShader(device, vertex_shader[test_data[i].vshader]);
2184 ok(SUCCEEDED(hr), "SetVertexShader failed (%08x)\n", hr);
2185 hr = IDirect3DDevice9_SetPixelShader(device, pixel_shader[test_data[i].pshader]);
2186 ok(SUCCEEDED(hr), "SetPixelShader failed (%08x)\n", hr);
2187 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGVERTEXMODE, test_data[i].vfog);
2188 ok( hr == D3D_OK, "Setting fog vertex mode to D3DFOG_LINEAR failed (%08x)\n", hr);
2189 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, test_data[i].tfog);
2190 ok( hr == D3D_OK, "Setting fog table mode to D3DFOG_LINEAR failed (%08x)\n", hr);
2192 for(j=0; j < 11; j++)
2194 /* Don't use the whole zrange to prevent rounding errors */
2195 quad[0].position.z = 0.001f + (float)j / 10.02f;
2196 quad[1].position.z = 0.001f + (float)j / 10.02f;
2197 quad[2].position.z = 0.001f + (float)j / 10.02f;
2198 quad[3].position.z = 0.001f + (float)j / 10.02f;
2200 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff00ff, 1.0f, 0);
2201 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed (%08x)\n", hr);
2203 hr = IDirect3DDevice9_BeginScene(device);
2204 ok( hr == D3D_OK, "BeginScene returned failed (%08x)\n", hr);
2206 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], sizeof(quad[0]));
2207 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%08x)\n", hr);
2209 hr = IDirect3DDevice9_EndScene(device);
2210 ok(hr == D3D_OK, "EndScene failed (%08x)\n", hr);
2212 /* As the red and green component are the result of blending use 5% tolerance on the expected value */
2213 color = getPixelColor(device, 128, 240);
2214 ok(color_match(color, test_data[i].color[j], 13),
2215 "fog vs%i ps%i fvm%i ftm%i %d: got color %08x, expected %08x +-5%%\n",
2216 test_data[i].vshader, test_data[i].pshader, test_data[i].vfog, test_data[i].tfog, j, color, test_data[i].color[j]);
2218 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
2222 IDirect3DVertexShader9_Release(vertex_shader[1]);
2223 IDirect3DVertexShader9_Release(vertex_shader[2]);
2224 IDirect3DVertexShader9_Release(vertex_shader[3]);
2225 IDirect3DPixelShader9_Release(pixel_shader[1]);
2226 IDirect3DPixelShader9_Release(pixel_shader[2]);
2227 IDirect3DVertexDeclaration9_Release(vertex_declaration);
2228 refcount = IDirect3DDevice9_Release(device);
2229 ok(!refcount, "Device has %u references left.\n", refcount);
2230 done:
2231 IDirect3D9_Release(d3d);
2232 DestroyWindow(window);
2235 static void generate_bumpmap_textures(IDirect3DDevice9 *device) {
2236 unsigned int i, x, y;
2237 HRESULT hr;
2238 IDirect3DTexture9 *texture[2] = {NULL, NULL};
2239 D3DLOCKED_RECT locked_rect;
2241 /* Generate the textures */
2242 for(i=0; i<2; i++)
2244 hr = IDirect3DDevice9_CreateTexture(device, 128, 128, 1, 0, i?D3DFMT_A8R8G8B8:D3DFMT_V8U8,
2245 D3DPOOL_MANAGED, &texture[i], NULL);
2246 ok(SUCCEEDED(hr), "CreateTexture failed (0x%08x)\n", hr);
2248 hr = IDirect3DTexture9_LockRect(texture[i], 0, &locked_rect, NULL, 0);
2249 ok(SUCCEEDED(hr), "LockRect failed (0x%08x)\n", hr);
2250 for (y = 0; y < 128; ++y)
2252 if(i)
2253 { /* Set up black texture with 2x2 texel white spot in the middle */
2254 DWORD *ptr = (DWORD *)(((BYTE *)locked_rect.pBits) + (y * locked_rect.Pitch));
2255 for (x = 0; x < 128; ++x)
2257 *ptr++ = D3DCOLOR_ARGB(0xff, x * 2, y * 2, 0);
2260 else
2261 { /* Set up a displacement map which points away from the center parallel to the closest axis.
2262 * (if multiplied with bumpenvmat)
2264 WORD *ptr = (WORD *)(((BYTE *)locked_rect.pBits) + (y * locked_rect.Pitch));
2265 for (x = 0; x < 128; ++x)
2267 if(abs(x-64)>abs(y-64))
2269 if(x < 64)
2270 *ptr++ = 0xc000;
2271 else
2272 *ptr++ = 0x4000;
2274 else
2276 if(y < 64)
2277 *ptr++ = 0x0040;
2278 else
2279 *ptr++ = 0x00c0;
2284 hr = IDirect3DTexture9_UnlockRect(texture[i], 0);
2285 ok(SUCCEEDED(hr), "UnlockRect failed (0x%08x)\n", hr);
2287 hr = IDirect3DDevice9_SetTexture(device, i, (IDirect3DBaseTexture9 *)texture[i]);
2288 ok(SUCCEEDED(hr), "SetTexture failed (0x%08x)\n", hr);
2290 /* Disable texture filtering */
2291 hr = IDirect3DDevice9_SetSamplerState(device, i, D3DSAMP_MINFILTER, D3DTEXF_POINT);
2292 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_MINFILTER failed (0x%08x)\n", hr);
2293 hr = IDirect3DDevice9_SetSamplerState(device, i, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
2294 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr);
2296 hr = IDirect3DDevice9_SetSamplerState(device, i, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
2297 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_ADDRESSU failed (0x%08x)\n", hr);
2298 hr = IDirect3DDevice9_SetSamplerState(device, i, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
2299 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_ADDRESSV failed (0x%08x)\n", hr);
2303 /* Test the behavior of the texbem instruction with normal 2D and projective
2304 * 2D textures. */
2305 static void texbem_test(void)
2307 IDirect3DVertexDeclaration9 *vertex_declaration = NULL;
2308 /* Use asymmetric matrix to test loading. */
2309 float bumpenvmat[4] = {0.0f, 0.5f, -0.5f, 0.0f};
2310 IDirect3DPixelShader9 *pixel_shader = NULL;
2311 IDirect3DTexture9 *texture1, *texture2;
2312 IDirect3DTexture9 *texture = NULL;
2313 D3DLOCKED_RECT locked_rect;
2314 IDirect3DDevice9 *device;
2315 IDirect3D9 *d3d;
2316 ULONG refcount;
2317 D3DCAPS9 caps;
2318 DWORD color;
2319 HWND window;
2320 HRESULT hr;
2321 int i;
2323 static const DWORD pixel_shader_code[] =
2325 0xffff0101, /* ps_1_1*/
2326 0x00000042, 0xb00f0000, /* tex t0*/
2327 0x00000043, 0xb00f0001, 0xb0e40000, /* texbem t1, t0*/
2328 0x00000001, 0x800f0000, 0xb0e40001, /* mov r0, t1*/
2329 0x0000ffff
2331 static const DWORD double_texbem_code[] =
2333 0xffff0103, /* ps_1_3 */
2334 0x00000042, 0xb00f0000, /* tex t0 */
2335 0x00000043, 0xb00f0001, 0xb0e40000, /* texbem t1, t0 */
2336 0x00000042, 0xb00f0002, /* tex t2 */
2337 0x00000043, 0xb00f0003, 0xb0e40002, /* texbem t3, t2 */
2338 0x00000002, 0x800f0000, 0xb0e40001, 0xb0e40003, /* add r0, t1, t3 */
2339 0x0000ffff /* end */
2341 static const float quad[][7] =
2343 {-1.0f, -1.0f, 0.1f, 0.0f, 0.0f, 0.0f, 0.0f},
2344 {-1.0f, 1.0f, 0.1f, 0.0f, 1.0f, 0.0f, 1.0f},
2345 { 1.0f, -1.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f},
2346 { 1.0f, 1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 1.0f},
2348 static const float quad_proj[][9] =
2350 {-1.0f, -1.0f, 0.1f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 128.0f},
2351 {-1.0f, 1.0f, 0.1f, 0.0f, 1.0f, 0.0f, 128.0f, 0.0f, 128.0f},
2352 { 1.0f, -1.0f, 0.1f, 1.0f, 0.0f, 128.0f, 0.0f, 0.0f, 128.0f},
2353 { 1.0f, 1.0f, 0.1f, 1.0f, 1.0f, 128.0f, 128.0f, 0.0f, 128.0f},
2355 static const float double_quad[] =
2357 -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.5f, 0.0f, 0.0f, 0.5f, 0.5f,
2358 -1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.5f, 0.0f, 0.0f, 0.5f, 0.5f,
2359 1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.5f, 0.0f, 0.0f, 0.5f, 0.5f,
2360 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.5f, 0.0f, 0.0f, 0.5f, 0.5f,
2362 static const D3DVERTEXELEMENT9 decl_elements[][4] =
2365 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
2366 {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
2367 {0, 20, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},
2368 D3DDECL_END()
2371 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
2372 {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
2373 {0, 20, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},
2374 D3DDECL_END()
2378 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
2379 0, 0, 640, 480, NULL, NULL, NULL, NULL);
2380 d3d = Direct3DCreate9(D3D_SDK_VERSION);
2381 ok(!!d3d, "Failed to create a D3D object.\n");
2382 if (!(device = create_device(d3d, window, window, TRUE)))
2384 skip("Failed to create a D3D device, skipping tests.\n");
2385 goto done;
2388 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
2389 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
2390 if (caps.PixelShaderVersion < D3DPS_VERSION(1, 1))
2392 skip("No ps_1_1 support, skipping tests.\n");
2393 IDirect3DDevice9_Release(device);
2394 goto done;
2397 generate_bumpmap_textures(device);
2399 IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_BUMPENVMAT00, *(LPDWORD)&bumpenvmat[0]);
2400 IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_BUMPENVMAT01, *(LPDWORD)&bumpenvmat[1]);
2401 IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_BUMPENVMAT10, *(LPDWORD)&bumpenvmat[2]);
2402 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_BUMPENVMAT11, *(LPDWORD)&bumpenvmat[3]);
2403 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
2405 hr = IDirect3DDevice9_SetVertexShader(device, NULL);
2406 ok(SUCCEEDED(hr), "SetVertexShader failed (%08x)\n", hr);
2408 for(i=0; i<2; i++)
2410 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
2411 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed (%08x)\n", hr);
2413 if(i)
2415 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT4|D3DTTFF_PROJECTED);
2416 ok(SUCCEEDED(hr), "SetTextureStageState D3DTSS_TEXTURETRANSFORMFLAGS failed (0x%08x)\n", hr);
2419 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements[i], &vertex_declaration);
2420 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (0x%08x)\n", hr);
2421 hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration);
2422 ok(SUCCEEDED(hr), "SetVertexDeclaration failed (0x%08x)\n", hr);
2424 hr = IDirect3DDevice9_CreatePixelShader(device, pixel_shader_code, &pixel_shader);
2425 ok(SUCCEEDED(hr), "CreatePixelShader failed (%08x)\n", hr);
2426 hr = IDirect3DDevice9_SetPixelShader(device, pixel_shader);
2427 ok(SUCCEEDED(hr), "SetPixelShader failed (%08x)\n", hr);
2429 hr = IDirect3DDevice9_BeginScene(device);
2430 ok(SUCCEEDED(hr), "BeginScene failed (0x%08x)\n", hr);
2432 if(!i)
2433 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], sizeof(quad[0]));
2434 else
2435 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad_proj[0], sizeof(quad_proj[0]));
2436 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (0x%08x)\n", hr);
2438 hr = IDirect3DDevice9_EndScene(device);
2439 ok(SUCCEEDED(hr), "EndScene failed (0x%08x)\n", hr);
2441 /* The Window 8 testbot (WARP) seems to use the transposed
2442 * D3DTSS_BUMPENVMAT matrix. */
2443 color = getPixelColor(device, 160, 240);
2444 ok(color_match(color, 0x007e8000, 4) || broken(color_match(color, 0x00007e00, 4)),
2445 "Got unexpected color 0x%08x.\n", color);
2446 color = getPixelColor(device, 480, 240);
2447 ok(color_match(color, 0x007e8000, 4) || broken(color_match(color, 0x00fe7e00, 4)),
2448 "Got unexpected color 0x%08x.\n", color);
2449 color = getPixelColor(device, 320, 120);
2450 ok(color_match(color, 0x007e8000, 4) || broken(color_match(color, 0x0080fe00, 4)),
2451 "Got unexpected color 0x%08x.\n", color);
2452 color = getPixelColor(device, 320, 360);
2453 ok(color_match(color, 0x007e8000, 4) || broken(color_match(color, 0x00800000, 4)),
2454 "Got unexpected color 0x%08x.\n", color);
2456 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
2457 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
2459 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
2460 ok(SUCCEEDED(hr), "SetPixelShader failed (%08x)\n", hr);
2461 IDirect3DPixelShader9_Release(pixel_shader);
2463 hr = IDirect3DDevice9_SetVertexDeclaration(device, NULL);
2464 ok(SUCCEEDED(hr), "SetVertexDeclaration failed (%08x)\n", hr);
2465 IDirect3DVertexDeclaration9_Release(vertex_declaration);
2468 /* clean up */
2469 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0, 0.0f, 0);
2470 ok(SUCCEEDED(hr), "Clear failed (0x%08x)\n", hr);
2472 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
2473 ok(SUCCEEDED(hr), "SetTextureStageState D3DTSS_TEXTURETRANSFORMFLAGS failed (0x%08x)\n", hr);
2475 for(i=0; i<2; i++)
2477 hr = IDirect3DDevice9_GetTexture(device, i, (IDirect3DBaseTexture9 **) &texture);
2478 ok(SUCCEEDED(hr), "IDirect3DDevice9_GetTexture failed (0x%08x)\n", hr);
2479 IDirect3DTexture9_Release(texture); /* For the GetTexture */
2480 hr = IDirect3DDevice9_SetTexture(device, i, NULL);
2481 ok(SUCCEEDED(hr), "SetTexture failed (0x%08x)\n", hr);
2482 IDirect3DTexture9_Release(texture);
2485 /* Test double texbem */
2486 hr = IDirect3DDevice9_CreateTexture(device, 1, 1, 1, 0, D3DFMT_V8U8, D3DPOOL_MANAGED, &texture, NULL);
2487 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateTexture failed (0x%08x)\n", hr);
2488 hr = IDirect3DDevice9_CreateTexture(device, 1, 1, 1, 0, D3DFMT_V8U8, D3DPOOL_MANAGED, &texture1, NULL);
2489 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateTexture failed (0x%08x)\n", hr);
2490 hr = IDirect3DDevice9_CreateTexture(device, 8, 8, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture2, NULL);
2491 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateTexture failed (0x%08x)\n", hr);
2492 hr = IDirect3DDevice9_CreatePixelShader(device, double_texbem_code, &pixel_shader);
2493 ok(SUCCEEDED(hr), "CreatePixelShader failed (%08x)\n", hr);
2495 hr = IDirect3DTexture9_LockRect(texture, 0, &locked_rect, NULL, 0);
2496 ok(SUCCEEDED(hr), "LockRect failed (0x%08x)\n", hr);
2497 ((signed char *) locked_rect.pBits)[0] = (-1.0 / 8.0) * 127;
2498 ((signed char *) locked_rect.pBits)[1] = ( 1.0 / 8.0) * 127;
2500 hr = IDirect3DTexture9_UnlockRect(texture, 0);
2501 ok(SUCCEEDED(hr), "LockRect failed (0x%08x)\n", hr);
2503 hr = IDirect3DTexture9_LockRect(texture1, 0, &locked_rect, NULL, 0);
2504 ok(SUCCEEDED(hr), "LockRect failed (0x%08x)\n", hr);
2505 ((signed char *) locked_rect.pBits)[0] = (-2.0 / 8.0) * 127;
2506 ((signed char *) locked_rect.pBits)[1] = (-4.0 / 8.0) * 127;
2507 hr = IDirect3DTexture9_UnlockRect(texture1, 0);
2508 ok(SUCCEEDED(hr), "LockRect failed (0x%08x)\n", hr);
2511 /* Some data without any meaning, just to have an 8x8 array to see which element is picked */
2512 #define tex 0x00ff0000
2513 #define tex1 0x0000ff00
2514 #define origin 0x000000ff
2515 static const DWORD pixel_data[] = {
2516 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
2517 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
2518 0x000000ff, tex1 , 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
2519 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
2520 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, origin, 0x000000ff, tex , 0x000000ff,
2521 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
2522 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
2523 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
2525 #undef tex1
2526 #undef tex2
2527 #undef origin
2529 hr = IDirect3DTexture9_LockRect(texture2, 0, &locked_rect, NULL, 0);
2530 ok(SUCCEEDED(hr), "LockRect failed (0x%08x)\n", hr);
2531 for(i = 0; i < 8; i++) {
2532 memcpy(((char *) locked_rect.pBits) + i * locked_rect.Pitch, pixel_data + 8 * i, 8 * sizeof(DWORD));
2534 hr = IDirect3DTexture9_UnlockRect(texture2, 0);
2535 ok(SUCCEEDED(hr), "LockRect failed (0x%08x)\n", hr);
2538 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) texture);
2539 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTexture failed (0x%08x)\n", hr);
2540 hr = IDirect3DDevice9_SetTexture(device, 1, (IDirect3DBaseTexture9 *) texture2);
2541 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTexture failed (0x%08x)\n", hr);
2542 hr = IDirect3DDevice9_SetTexture(device, 2, (IDirect3DBaseTexture9 *) texture1);
2543 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTexture failed (0x%08x)\n", hr);
2544 hr = IDirect3DDevice9_SetTexture(device, 3, (IDirect3DBaseTexture9 *) texture2);
2545 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTexture failed (0x%08x)\n", hr);
2546 hr = IDirect3DDevice9_SetPixelShader(device, pixel_shader);
2547 ok(SUCCEEDED(hr), "Direct3DDevice9_SetPixelShader failed (0x%08x)\n", hr);
2548 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX4);
2549 ok(SUCCEEDED(hr), "Direct3DDevice9_SetPixelShader failed (0x%08x)\n", hr);
2551 bumpenvmat[0] =-1.0; bumpenvmat[2] = 2.0;
2552 bumpenvmat[1] = 0.0; bumpenvmat[3] = 0.0;
2553 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_BUMPENVMAT00, *(LPDWORD)&bumpenvmat[0]);
2554 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr);
2555 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_BUMPENVMAT01, *(LPDWORD)&bumpenvmat[1]);
2556 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr);
2557 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_BUMPENVMAT10, *(LPDWORD)&bumpenvmat[2]);
2558 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr);
2559 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_BUMPENVMAT11, *(LPDWORD)&bumpenvmat[3]);
2560 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr);
2562 bumpenvmat[0] = 1.5; bumpenvmat[2] = 0.0;
2563 bumpenvmat[1] = 0.0; bumpenvmat[3] = 0.5;
2564 hr = IDirect3DDevice9_SetTextureStageState(device, 3, D3DTSS_BUMPENVMAT00, *(LPDWORD)&bumpenvmat[0]);
2565 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr);
2566 hr = IDirect3DDevice9_SetTextureStageState(device, 3, D3DTSS_BUMPENVMAT01, *(LPDWORD)&bumpenvmat[1]);
2567 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr);
2568 hr = IDirect3DDevice9_SetTextureStageState(device, 3, D3DTSS_BUMPENVMAT10, *(LPDWORD)&bumpenvmat[2]);
2569 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr);
2570 hr = IDirect3DDevice9_SetTextureStageState(device, 3, D3DTSS_BUMPENVMAT11, *(LPDWORD)&bumpenvmat[3]);
2571 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr);
2573 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
2574 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr);
2575 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
2576 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr);
2577 hr = IDirect3DDevice9_SetSamplerState(device, 1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
2578 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr);
2579 hr = IDirect3DDevice9_SetSamplerState(device, 1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
2580 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr);
2581 hr = IDirect3DDevice9_SetSamplerState(device, 2, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
2582 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr);
2583 hr = IDirect3DDevice9_SetSamplerState(device, 2, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
2584 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr);
2585 hr = IDirect3DDevice9_SetSamplerState(device, 3, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
2586 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr);
2587 hr = IDirect3DDevice9_SetSamplerState(device, 3, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
2588 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr);
2590 hr = IDirect3DDevice9_BeginScene(device);
2591 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
2592 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, double_quad, sizeof(float) * 11);
2593 ok(SUCCEEDED(hr), "Failed to draw primitive, hr %#x.\n", hr);
2594 hr = IDirect3DDevice9_EndScene(device);
2595 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
2596 /* The Window 8 testbot (WARP) seems to use the transposed
2597 * D3DTSS_BUMPENVMAT matrix. */
2598 color = getPixelColor(device, 320, 240);
2599 ok(color_match(color, 0x00ffff00, 1) || broken(color_match(color, 0x0000ffff, 1)),
2600 "Got unexpected color 0x%08x.\n", color);
2602 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
2603 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
2605 IDirect3DPixelShader9_Release(pixel_shader);
2606 IDirect3DTexture9_Release(texture);
2607 IDirect3DTexture9_Release(texture1);
2608 IDirect3DTexture9_Release(texture2);
2609 refcount = IDirect3DDevice9_Release(device);
2610 ok(!refcount, "Device has %u references left.\n", refcount);
2611 done:
2612 IDirect3D9_Release(d3d);
2613 DestroyWindow(window);
2616 static void z_range_test(void)
2618 IDirect3DVertexShader9 *shader;
2619 IDirect3DDevice9 *device;
2620 IDirect3D9 *d3d;
2621 ULONG refcount;
2622 D3DCAPS9 caps;
2623 DWORD color;
2624 HWND window;
2625 HRESULT hr;
2627 static const struct
2629 struct vec3 position;
2630 DWORD diffuse;
2632 quad[] =
2634 {{-1.0f, 0.0f, 1.1f}, 0xffff0000},
2635 {{-1.0f, 1.0f, 1.1f}, 0xffff0000},
2636 {{ 1.0f, 0.0f, -1.1f}, 0xffff0000},
2637 {{ 1.0f, 1.0f, -1.1f}, 0xffff0000},
2639 quad2[] =
2641 {{-1.0f, 0.0f, 1.1f}, 0xff0000ff},
2642 {{-1.0f, 1.0f, 1.1f}, 0xff0000ff},
2643 {{ 1.0f, 0.0f, -1.1f}, 0xff0000ff},
2644 {{ 1.0f, 1.0f, -1.1f}, 0xff0000ff},
2646 static const struct
2648 struct vec4 position;
2649 DWORD diffuse;
2651 quad3[] =
2653 {{640.0f, 240.0f, -1.1f, 1.0f}, 0xffffff00},
2654 {{640.0f, 480.0f, -1.1f, 1.0f}, 0xffffff00},
2655 {{ 0.0f, 240.0f, 1.1f, 1.0f}, 0xffffff00},
2656 {{ 0.0f, 480.0f, 1.1f, 1.0f}, 0xffffff00},
2658 quad4[] =
2660 {{640.0f, 240.0f, -1.1f, 1.0f}, 0xff00ff00},
2661 {{640.0f, 480.0f, -1.1f, 1.0f}, 0xff00ff00},
2662 {{ 0.0f, 240.0f, 1.1f, 1.0f}, 0xff00ff00},
2663 {{ 0.0f, 480.0f, 1.1f, 1.0f}, 0xff00ff00},
2665 static const DWORD shader_code[] =
2667 0xfffe0101, /* vs_1_1 */
2668 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
2669 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
2670 0x00000001, 0xd00f0000, 0xa0e40000, /* mov oD0, c0 */
2671 0x0000ffff /* end */
2673 static const float color_const_1[] = {1.0f, 0.0f, 0.0f, 1.0f};
2674 static const float color_const_2[] = {0.0f, 0.0f, 1.0f, 1.0f};
2676 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
2677 0, 0, 640, 480, NULL, NULL, NULL, NULL);
2678 d3d = Direct3DCreate9(D3D_SDK_VERSION);
2679 ok(!!d3d, "Failed to create a D3D object.\n");
2680 if (!(device = create_device(d3d, window, window, TRUE)))
2682 skip("Failed to create a D3D device, skipping tests.\n");
2683 goto done;
2686 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
2687 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
2689 /* Does the Present clear the depth stencil? Clear the depth buffer with some value != 0,
2690 * then call Present. Then clear the color buffer to make sure it has some defined content
2691 * after the Present with D3DSWAPEFFECT_DISCARD. After that draw a plane that is somewhere cut
2692 * by the depth value. */
2693 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 0.75f, 0);
2694 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
2695 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
2696 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
2697 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
2698 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
2700 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
2701 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
2702 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, TRUE);
2703 ok(SUCCEEDED(hr), "Failed to enable clipping, hr %#x.\n", hr);
2704 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
2705 ok(SUCCEEDED(hr), "Failed to enable z test, hr %#x.\n", hr);
2706 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
2707 ok(SUCCEEDED(hr), "Failed to disable z writes, hr %#x.\n", hr);
2708 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_GREATER);
2709 ok(SUCCEEDED(hr), "Failed to set z function, hr %#x.\n", hr);
2710 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
2711 ok(SUCCEEDED(hr), "Failed set FVF, hr %#x.\n", hr);
2713 hr = IDirect3DDevice9_BeginScene(device);
2714 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
2716 /* Test the untransformed vertex path */
2717 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
2718 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
2719 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_LESS);
2720 ok(SUCCEEDED(hr), "Failed to set z function, hr %#x.\n", hr);
2721 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(quad2[0]));
2722 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
2724 /* Test the transformed vertex path */
2725 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
2726 ok(SUCCEEDED(hr), "Failed set FVF, hr %#x.\n", hr);
2728 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, sizeof(quad4[0]));
2729 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
2730 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_GREATER);
2731 ok(SUCCEEDED(hr), "Failed to set z function, hr %#x.\n", hr);
2732 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, sizeof(quad3[0]));
2733 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
2735 hr = IDirect3DDevice9_EndScene(device);
2736 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
2738 /* Do not test the exact corner pixels, but go pretty close to them */
2740 /* Clipped because z > 1.0 */
2741 color = getPixelColor(device, 28, 238);
2742 ok(color_match(color, 0x00ffffff, 0), "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
2743 color = getPixelColor(device, 28, 241);
2744 if (caps.PrimitiveMiscCaps & D3DPMISCCAPS_CLIPTLVERTS)
2745 ok(color_match(color, 0x00ffffff, 0), "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
2746 else
2747 ok(color_match(color, 0x00ffff00, 0), "Z range failed: Got color 0x%08x, expected 0x00ffff00.\n", color);
2749 /* Not clipped, > z buffer clear value(0.75).
2751 * On the r500 driver on Windows D3DCMP_GREATER and D3DCMP_GREATEREQUAL are broken for depth
2752 * values > 0.5. The range appears to be distorted, apparently an incoming value of ~0.875 is
2753 * equal to a stored depth buffer value of 0.5. */
2754 color = getPixelColor(device, 31, 238);
2755 ok(color_match(color, 0x00ff0000, 0), "Z range failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
2756 color = getPixelColor(device, 31, 241);
2757 ok(color_match(color, 0x00ffff00, 0), "Z range failed: Got color 0x%08x, expected 0x00ffff00.\n", color);
2758 color = getPixelColor(device, 100, 238);
2759 ok(color_match(color, 0x00ff0000, 0) || broken(color_match(color, 0x00ffffff, 0)),
2760 "Z range failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
2761 color = getPixelColor(device, 100, 241);
2762 ok(color_match(color, 0x00ffff00, 0) || broken(color_match(color, 0x00ffffff, 0)),
2763 "Z range failed: Got color 0x%08x, expected 0x00ffff00.\n", color);
2765 /* Not clipped, < z buffer clear value */
2766 color = getPixelColor(device, 104, 238);
2767 ok(color_match(color, 0x000000ff, 0), "Z range failed: Got color 0x%08x, expected 0x000000ff.\n", color);
2768 color = getPixelColor(device, 104, 241);
2769 ok(color_match(color, 0x0000ff00, 0), "Z range failed: Got color 0x%08x, expected 0x0000ff00.\n", color);
2770 color = getPixelColor(device, 318, 238);
2771 ok(color_match(color, 0x000000ff, 0), "Z range failed: Got color 0x%08x, expected 0x000000ff.\n", color);
2772 color = getPixelColor(device, 318, 241);
2773 ok(color_match(color, 0x0000ff00, 0), "Z range failed: Got color 0x%08x, expected 0x0000ff00.\n", color);
2775 /* Clipped because z < 0.0 */
2776 color = getPixelColor(device, 321, 238);
2777 ok(color_match(color, 0x00ffffff, 0), "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
2778 color = getPixelColor(device, 321, 241);
2779 if (caps.PrimitiveMiscCaps & D3DPMISCCAPS_CLIPTLVERTS)
2780 ok(color_match(color, 0x00ffffff, 0), "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
2781 else
2782 ok(color_match(color, 0x0000ff00, 0), "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
2784 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
2785 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
2787 /* Test the shader path */
2788 if (caps.VertexShaderVersion < D3DVS_VERSION(1, 1))
2790 skip("Vertex shaders not supported, skipping tests.\n");
2791 IDirect3DDevice9_Release(device);
2792 goto done;
2794 hr = IDirect3DDevice9_CreateVertexShader(device, shader_code, &shader);
2795 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
2797 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
2798 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
2800 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
2801 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
2802 hr = IDirect3DDevice9_SetVertexShader(device, shader);
2803 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
2805 hr = IDirect3DDevice9_BeginScene(device);
2806 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
2808 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 0, color_const_1, 1);
2809 ok(SUCCEEDED(hr), "Failed to set vs constant 0, hr %#x.\n", hr);
2810 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
2811 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
2813 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_LESS);
2814 ok(SUCCEEDED(hr), "Failed to set z function, hr %#x.\n", hr);
2815 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 0, color_const_2, 1);
2816 ok(SUCCEEDED(hr), "Failed to set vs constant 0, hr %#x.\n", hr);
2817 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(quad2[0]));
2818 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
2820 hr = IDirect3DDevice9_EndScene(device);
2821 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
2823 IDirect3DVertexShader9_Release(shader);
2825 /* Z < 1.0 */
2826 color = getPixelColor(device, 28, 238);
2827 ok(color_match(color, 0x00ffffff, 0), "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
2829 /* 1.0 < z < 0.75 */
2830 color = getPixelColor(device, 31, 238);
2831 ok(color_match(color, 0x00ff0000, 0), "Z range failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
2832 color = getPixelColor(device, 100, 238);
2833 ok(color_match(color, 0x00ff0000, 0) || broken(color_match(color, 0x00ffffff, 0)),
2834 "Z range failed: Got color 0x%08x, expected 0x00ff0000.\n", color);
2836 /* 0.75 < z < 0.0 */
2837 color = getPixelColor(device, 104, 238);
2838 ok(color_match(color, 0x000000ff, 0), "Z range failed: Got color 0x%08x, expected 0x000000ff.\n", color);
2839 color = getPixelColor(device, 318, 238);
2840 ok(color_match(color, 0x000000ff, 0), "Z range failed: Got color 0x%08x, expected 0x000000ff.\n", color);
2842 /* 0.0 < z */
2843 color = getPixelColor(device, 321, 238);
2844 ok(color_match(color, 0x00ffffff, 0), "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color);
2846 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
2847 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
2849 refcount = IDirect3DDevice9_Release(device);
2850 ok(!refcount, "Device has %u references left.\n", refcount);
2851 done:
2852 IDirect3D9_Release(d3d);
2853 DestroyWindow(window);
2856 static void fill_surface(IDirect3DSurface9 *surface, DWORD color, DWORD flags)
2858 D3DSURFACE_DESC desc;
2859 D3DLOCKED_RECT l;
2860 HRESULT hr;
2861 unsigned int x, y;
2862 DWORD *mem;
2864 memset(&desc, 0, sizeof(desc));
2865 memset(&l, 0, sizeof(l));
2866 hr = IDirect3DSurface9_GetDesc(surface, &desc);
2867 ok(hr == D3D_OK, "IDirect3DSurface9_GetDesc failed with %08x\n", hr);
2868 hr = IDirect3DSurface9_LockRect(surface, &l, NULL, flags);
2869 ok(hr == D3D_OK, "IDirect3DSurface9_LockRect failed with %08x\n", hr);
2870 if(FAILED(hr)) return;
2872 for(y = 0; y < desc.Height; y++)
2874 mem = (DWORD *) ((BYTE *) l.pBits + y * l.Pitch);
2875 for(x = 0; x < l.Pitch / sizeof(DWORD); x++)
2877 mem[x] = color;
2880 hr = IDirect3DSurface9_UnlockRect(surface);
2881 ok(hr == D3D_OK, "IDirect3DSurface9_UnlockRect failed with %08x\n", hr);
2884 static void stretchrect_test(void)
2886 IDirect3DSurface9 *surf_tex_rt32, *surf_tex_rt64, *surf_tex_rt_dest64, *surf_tex_rt_dest640_480;
2887 IDirect3DSurface9 *surf_offscreen32, *surf_offscreen64, *surf_offscreen_dest64;
2888 IDirect3DTexture9 *tex_rt32, *tex_rt64, *tex_rt_dest64, *tex_rt_dest640_480;
2889 IDirect3DSurface9 *surf_tex32, *surf_tex64, *surf_tex_dest64;
2890 IDirect3DSurface9 *surf_rt32, *surf_rt64, *surf_rt_dest64;
2891 IDirect3DTexture9 *tex32, *tex64, *tex_dest64;
2892 IDirect3DSurface9 *surf_temp32, *surf_temp64;
2893 IDirect3DSurface9 *backbuffer;
2894 IDirect3DDevice9 *device;
2895 IDirect3D9 *d3d;
2896 D3DCOLOR color;
2897 ULONG refcount;
2898 HWND window;
2899 HRESULT hr;
2901 static const RECT src_rect = {0, 0, 640, 480};
2902 static const RECT src_rect_flipy = {0, 480, 640, 0};
2903 static const RECT dst_rect = {0, 0, 640, 480};
2904 static const RECT dst_rect_flipy = {0, 480, 640, 0};
2905 static const RECT src_rect64 = {0, 0, 64, 64};
2906 static const RECT src_rect64_flipy = {0, 64, 64, 0};
2907 static const RECT dst_rect64 = {0, 0, 64, 64};
2908 static const RECT dst_rect64_flipy = {0, 64, 64, 0};
2910 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
2911 0, 0, 640, 480, NULL, NULL, NULL, NULL);
2912 d3d = Direct3DCreate9(D3D_SDK_VERSION);
2913 ok(!!d3d, "Failed to create a D3D object.\n");
2914 if (!(device = create_device(d3d, window, window, TRUE)))
2916 skip("Failed to create a D3D device, skipping tests.\n");
2917 goto done;
2920 /* Create our temporary surfaces in system memory. */
2921 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 32, 32,
2922 D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surf_temp32, NULL);
2923 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
2924 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 64, 64,
2925 D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surf_temp64, NULL);
2926 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
2928 /* Create offscreen plain surfaces in D3DPOOL_DEFAULT. */
2929 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 32, 32,
2930 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf_offscreen32, NULL);
2931 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
2932 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 64, 64,
2933 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf_offscreen64, NULL);
2934 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
2935 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 64, 64,
2936 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf_offscreen_dest64, NULL);
2937 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
2939 /* Create render target surfaces. */
2940 hr = IDirect3DDevice9_CreateRenderTarget(device, 32, 32,
2941 D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, TRUE, &surf_rt32, NULL );
2942 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
2943 hr = IDirect3DDevice9_CreateRenderTarget(device, 64, 64,
2944 D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, TRUE, &surf_rt64, NULL );
2945 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
2946 hr = IDirect3DDevice9_CreateRenderTarget(device, 64, 64,
2947 D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, TRUE, &surf_rt_dest64, NULL );
2948 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
2949 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
2950 ok(SUCCEEDED(hr), "Failed to get back buffer, hr %#x.\n", hr);
2952 /* Create render target textures. */
2953 hr = IDirect3DDevice9_CreateTexture(device, 32, 32, 1, D3DUSAGE_RENDERTARGET,
2954 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex_rt32, NULL);
2955 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
2956 hr = IDirect3DDevice9_CreateTexture(device, 64, 64, 1, D3DUSAGE_RENDERTARGET,
2957 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex_rt64, NULL);
2958 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
2959 hr = IDirect3DDevice9_CreateTexture(device, 64, 64, 1, D3DUSAGE_RENDERTARGET,
2960 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex_rt_dest64, NULL);
2961 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
2962 hr = IDirect3DDevice9_CreateTexture(device, 640, 480, 1, D3DUSAGE_RENDERTARGET,
2963 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex_rt_dest640_480, NULL);
2964 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
2965 hr = IDirect3DTexture9_GetSurfaceLevel(tex_rt32, 0, &surf_tex_rt32);
2966 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
2967 hr = IDirect3DTexture9_GetSurfaceLevel(tex_rt64, 0, &surf_tex_rt64);
2968 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
2969 hr = IDirect3DTexture9_GetSurfaceLevel(tex_rt_dest64, 0, &surf_tex_rt_dest64);
2970 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
2971 hr = IDirect3DTexture9_GetSurfaceLevel(tex_rt_dest640_480, 0, &surf_tex_rt_dest640_480);
2972 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
2974 /* Create regular textures in D3DPOOL_DEFAULT. */
2975 hr = IDirect3DDevice9_CreateTexture(device, 32, 32, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex32, NULL);
2976 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
2977 hr = IDirect3DDevice9_CreateTexture(device, 64, 64, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex64, NULL);
2978 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
2979 hr = IDirect3DDevice9_CreateTexture(device, 64, 64, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex_dest64, NULL);
2980 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
2981 hr = IDirect3DTexture9_GetSurfaceLevel(tex32, 0, &surf_tex32);
2982 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
2983 hr = IDirect3DTexture9_GetSurfaceLevel(tex64, 0, &surf_tex64);
2984 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
2985 hr = IDirect3DTexture9_GetSurfaceLevel(tex_dest64, 0, &surf_tex_dest64);
2986 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
2988 /**********************************************************************
2989 * Tests for when the source parameter is an offscreen plain surface. *
2990 **********************************************************************/
2992 /* Fill the offscreen 64x64 surface with green. */
2993 fill_surface(surf_offscreen64, 0xff00ff00, 0);
2995 /* offscreenplain ==> offscreenplain, same size. */
2996 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, NULL, surf_offscreen_dest64, NULL, D3DTEXF_NONE);
2997 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
2998 color = getPixelColorFromSurface(surf_offscreen_dest64, 32, 32);
2999 ok(color == 0xff00ff00, "Got unexpected color 0x%08x.\n", color);
3000 /* Blit without scaling. */
3001 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, &src_rect64,
3002 surf_offscreen_dest64, &dst_rect64, D3DTEXF_NONE);
3003 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3004 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3005 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, &src_rect64_flipy,
3006 surf_offscreen_dest64, &dst_rect64, D3DTEXF_NONE);
3007 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3008 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3009 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, &src_rect64,
3010 surf_offscreen_dest64, &dst_rect64_flipy, D3DTEXF_NONE);
3011 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3013 /* offscreenplain ==> rendertarget texture, same size. */
3014 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, NULL, surf_tex_rt_dest64, NULL, D3DTEXF_NONE);
3015 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3016 /* We can't lock rendertarget textures, so copy to our temp surface first. */
3017 hr = IDirect3DDevice9_GetRenderTargetData(device, surf_tex_rt_dest64, surf_temp64);
3018 ok(SUCCEEDED(hr), "Failed to get render target data, hr %#x.\n", hr);
3019 color = getPixelColorFromSurface(surf_temp64, 32, 32);
3020 ok(color == 0xff00ff00, "Got unexpected color 0x%08x.\n", color);
3021 /* Blit without scaling. */
3022 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, &src_rect64,
3023 surf_tex_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3024 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3025 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3026 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, &src_rect64_flipy,
3027 surf_tex_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3028 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3029 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3030 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, &src_rect64,
3031 surf_tex_rt_dest64, &dst_rect64_flipy, D3DTEXF_NONE);
3032 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3034 /* offscreenplain ==> rendertarget surface, same size. */
3035 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, NULL, surf_rt_dest64, NULL, D3DTEXF_NONE);
3036 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3037 color = getPixelColorFromSurface(surf_rt_dest64, 32, 32);
3038 ok(color == 0xff00ff00, "Got unexpected color 0x%08x.\n", color);
3039 /* Blit without scaling. */
3040 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, &src_rect64,
3041 surf_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3042 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3043 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3044 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, &src_rect64_flipy,
3045 surf_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3046 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3047 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3048 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, &src_rect64,
3049 surf_rt_dest64, &dst_rect64_flipy, D3DTEXF_NONE);
3050 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3052 /* offscreenplain ==> texture, same size (should fail). */
3053 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen64, NULL, surf_tex_dest64, NULL, D3DTEXF_NONE);
3054 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3056 /* Fill the smaller offscreen surface with red. */
3057 fill_surface(surf_offscreen32, 0xffff0000, 0);
3059 /* offscreenplain ==> offscreenplain, scaling (should fail). */
3060 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen32, NULL, surf_offscreen64, NULL, D3DTEXF_NONE);
3061 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3063 /* offscreenplain ==> rendertarget texture, scaling. */
3064 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen32, NULL, surf_tex_rt_dest64, NULL, D3DTEXF_NONE);
3065 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3066 /* We can't lock rendertarget textures, so copy to our temp surface first. */
3067 hr = IDirect3DDevice9_GetRenderTargetData(device, surf_tex_rt_dest64, surf_temp64);
3068 ok(SUCCEEDED(hr), "Failed to get render target data, hr %#x.\n", hr);
3069 color = getPixelColorFromSurface(surf_temp64, 48, 48);
3070 ok(color == 0xffff0000, "Got unexpected color 0x%08x.\n", color);
3072 /* offscreenplain ==> rendertarget surface, scaling. */
3073 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen32, NULL, surf_rt_dest64, NULL, D3DTEXF_NONE);
3074 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3075 color = getPixelColorFromSurface(surf_rt_dest64, 48, 48);
3076 ok(color == 0xffff0000, "Got unexpected color 0x%08x.\n", color);
3078 /* offscreenplain ==> texture, scaling (should fail). */
3079 hr = IDirect3DDevice9_StretchRect(device, surf_offscreen32, NULL, surf_tex_dest64, NULL, D3DTEXF_NONE);
3080 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3082 /*************************************************************
3083 * Tests for when the source parameter is a regular texture. *
3084 *************************************************************/
3086 /* Fill the surface of the regular texture with blue. */
3087 /* Can't fill the surf_tex directly because it's created in D3DPOOL_DEFAULT. */
3088 fill_surface(surf_temp64, 0xff0000ff, 0);
3089 hr = IDirect3DDevice9_UpdateSurface(device, surf_temp64, NULL, surf_tex64, NULL);
3090 ok(SUCCEEDED(hr), "Failed to update surface, hr %#x.\n", hr);
3092 /* texture ==> offscreenplain, same size. */
3093 hr = IDirect3DDevice9_StretchRect(device, surf_tex64, NULL, surf_offscreen64, NULL, D3DTEXF_NONE);
3094 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3096 /* texture ==> rendertarget texture, same size. */
3097 hr = IDirect3DDevice9_StretchRect(device, surf_tex64, NULL, surf_tex_rt_dest64, NULL, D3DTEXF_NONE);
3098 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3099 /* We can't lock rendertarget textures, so copy to our temp surface first. */
3100 hr = IDirect3DDevice9_GetRenderTargetData(device, surf_tex_rt_dest64, surf_temp64);
3101 ok(SUCCEEDED(hr), "Failed to get render target data, hr %#x.\n", hr);
3102 color = getPixelColorFromSurface(surf_temp64, 32, 32);
3103 ok(color == 0xff0000ff, "Got unexpected color 0x%08x.\n", color);
3104 /* Blit without scaling. */
3105 hr = IDirect3DDevice9_StretchRect(device, surf_tex64, &src_rect64,
3106 surf_tex_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3107 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3108 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3109 hr = IDirect3DDevice9_StretchRect(device, surf_tex64, &src_rect64_flipy,
3110 surf_tex_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3111 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3112 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3113 hr = IDirect3DDevice9_StretchRect(device, surf_tex64, &src_rect64,
3114 surf_tex_rt_dest64, &dst_rect64_flipy, D3DTEXF_NONE);
3115 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3117 /* texture ==> rendertarget surface, same size. */
3118 hr = IDirect3DDevice9_StretchRect(device, surf_tex64, NULL, surf_rt_dest64, NULL, D3DTEXF_NONE);
3119 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3120 color = getPixelColorFromSurface(surf_rt_dest64, 32, 32);
3121 ok(color == 0xff0000ff, "Got unexpected color 0x%08x.\n", color);
3122 /* Blit without scaling. */
3123 hr = IDirect3DDevice9_StretchRect(device, surf_tex64, &src_rect64,
3124 surf_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3125 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3126 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3127 hr = IDirect3DDevice9_StretchRect(device, surf_tex64, &src_rect64_flipy,
3128 surf_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3129 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3130 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3131 hr = IDirect3DDevice9_StretchRect(device, surf_tex64, &src_rect64,
3132 surf_rt_dest64, &dst_rect64_flipy, D3DTEXF_NONE);
3133 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3135 /* texture ==> texture, same size (should fail). */
3136 hr = IDirect3DDevice9_StretchRect(device, surf_tex64, NULL, surf_tex_dest64, NULL, D3DTEXF_NONE);
3137 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3139 /* Fill the surface of the smaller regular texture with red. */
3140 /* Can't fill the surf_tex directly because it's created in D3DPOOL_DEFAULT. */
3141 fill_surface(surf_temp32, 0xffff0000, 0);
3142 hr = IDirect3DDevice9_UpdateSurface(device, surf_temp32, NULL, surf_tex32, NULL);
3143 ok(SUCCEEDED(hr), "Failed to update surface, hr %#x.\n", hr);
3145 /* texture ==> offscreenplain, scaling (should fail). */
3146 hr = IDirect3DDevice9_StretchRect(device, surf_tex32, NULL, surf_offscreen64, NULL, D3DTEXF_NONE);
3147 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3149 /* texture ==> rendertarget texture, scaling. */
3150 hr = IDirect3DDevice9_StretchRect(device, surf_tex32, NULL, surf_tex_rt_dest64, NULL, D3DTEXF_NONE);
3151 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3152 /* We can't lock rendertarget textures, so copy to our temp surface first. */
3153 hr = IDirect3DDevice9_GetRenderTargetData(device, surf_tex_rt_dest64, surf_temp64);
3154 ok(SUCCEEDED(hr), "Failed to get render target data, hr %#x.\n", hr);
3155 color = getPixelColorFromSurface(surf_temp64, 48, 48);
3156 ok(color == 0xffff0000, "Got unexpected color 0x%08x.\n", color);
3158 /* texture ==> rendertarget surface, scaling. */
3159 hr = IDirect3DDevice9_StretchRect(device, surf_tex32, NULL, surf_rt_dest64, NULL, D3DTEXF_NONE);
3160 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3161 color = getPixelColorFromSurface(surf_rt_dest64, 48, 48);
3162 ok(color == 0xffff0000, "Got unexpected color 0x%08x.\n", color);
3164 /* texture ==> texture, scaling (should fail). */
3165 hr = IDirect3DDevice9_StretchRect(device, surf_tex32, NULL, surf_tex_dest64, NULL, D3DTEXF_NONE);
3166 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3168 /******************************************************************
3169 * Tests for when the source parameter is a rendertarget texture. *
3170 ******************************************************************/
3172 /* Fill the surface of the rendertarget texture with white. */
3173 /* Can't fill the surf_tex_rt directly because it's created in D3DPOOL_DEFAULT. */
3174 fill_surface(surf_temp64, 0xffffffff, 0);
3175 hr = IDirect3DDevice9_UpdateSurface(device, surf_temp64, NULL, surf_tex_rt64, NULL);
3176 ok(SUCCEEDED(hr), "Failed to update surface, hr %#x.\n", hr);
3178 /* rendertarget texture ==> offscreenplain, same size. */
3179 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt64, NULL, surf_offscreen64, NULL, D3DTEXF_NONE);
3180 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3182 /* rendertarget texture ==> rendertarget texture, same size. */
3183 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt64, NULL, surf_tex_rt_dest64, NULL, D3DTEXF_NONE);
3184 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3185 /* We can't lock rendertarget textures, so copy to our temp surface first. */
3186 hr = IDirect3DDevice9_GetRenderTargetData(device, surf_tex_rt_dest64, surf_temp64);
3187 ok(SUCCEEDED(hr), "Failed to get render target data, hr %#x.\n", hr);
3188 color = getPixelColorFromSurface(surf_temp64, 32, 32);
3189 ok(color == 0xffffffff, "Got unexpected color 0x%08x.\n", color);
3190 /* Blit without scaling. */
3191 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt64, &src_rect64,
3192 surf_tex_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3193 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3194 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3195 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt64, &src_rect64_flipy,
3196 surf_tex_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3197 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3198 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3199 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt64, &src_rect64,
3200 surf_tex_rt_dest64, &dst_rect64_flipy, D3DTEXF_NONE);
3201 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3203 /* rendertarget texture ==> rendertarget surface, same size. */
3204 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt64, NULL, surf_rt_dest64, NULL, D3DTEXF_NONE);
3205 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3206 color = getPixelColorFromSurface(surf_rt_dest64, 32, 32);
3207 ok(color == 0xffffffff, "Got unexpected color 0x%08x.\n", color);
3208 /* Blit without scaling. */
3209 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt64, &src_rect64,
3210 surf_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3211 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3212 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3213 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt64, &src_rect64_flipy,
3214 surf_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3215 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3216 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3217 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt64, &src_rect64,
3218 surf_rt_dest64, &dst_rect64_flipy, D3DTEXF_NONE);
3219 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3221 /* rendertarget texture ==> texture, same size (should fail). */
3222 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt64, NULL, surf_tex_dest64, NULL, D3DTEXF_NONE);
3223 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3225 /* Fill the surface of the smaller rendertarget texture with red. */
3226 /* Can't fill the surf_tex_rt directly because it's created in D3DPOOL_DEFAULT. */
3227 fill_surface(surf_temp32, 0xffff0000, 0);
3228 hr = IDirect3DDevice9_UpdateSurface(device, surf_temp32, NULL, surf_tex_rt32, NULL);
3229 ok(SUCCEEDED(hr), "Failed to update surface, hr %#x.\n", hr);
3231 /* rendertarget texture ==> offscreenplain, scaling (should fail). */
3232 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt32, NULL, surf_offscreen64, NULL, D3DTEXF_NONE);
3233 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3235 /* rendertarget texture ==> rendertarget texture, scaling. */
3236 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt32, NULL, surf_tex_rt_dest64, NULL, D3DTEXF_NONE);
3237 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3238 /* We can't lock rendertarget textures, so copy to our temp surface first. */
3239 hr = IDirect3DDevice9_GetRenderTargetData(device, surf_tex_rt_dest64, surf_temp64);
3240 ok(SUCCEEDED(hr), "Failed to get render target data, hr %#x.\n", hr);
3241 color = getPixelColorFromSurface(surf_temp64, 48, 48);
3242 ok(color == 0xffff0000, "Got unexpected color 0x%08x.\n", color);
3244 /* rendertarget texture ==> rendertarget surface, scaling. */
3245 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt32, NULL, surf_rt_dest64, NULL, D3DTEXF_NONE);
3246 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3247 color = getPixelColorFromSurface(surf_rt_dest64, 48, 48);
3248 ok(color == 0xffff0000, "Got unexpected color 0x%08x.\n", color);
3250 /* rendertarget texture ==> texture, scaling (should fail). */
3251 hr = IDirect3DDevice9_StretchRect(device, surf_tex_rt32, NULL, surf_tex_dest64, NULL, D3DTEXF_NONE);
3252 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3254 /******************************************************************
3255 * Tests for when the source parameter is a rendertarget surface. *
3256 ******************************************************************/
3258 /* Fill the surface of the rendertarget surface with black. */
3259 fill_surface(surf_rt64, 0xff000000, 0);
3261 /* rendertarget texture ==> offscreenplain, same size. */
3262 hr = IDirect3DDevice9_StretchRect(device, surf_rt64, NULL, surf_offscreen64, NULL, D3DTEXF_NONE);
3263 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3265 /* rendertarget surface ==> rendertarget texture, same size. */
3266 hr = IDirect3DDevice9_StretchRect(device, surf_rt64, NULL, surf_tex_rt_dest64, NULL, D3DTEXF_NONE);
3267 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3268 /* We can't lock rendertarget textures, so copy to our temp surface first. */
3269 hr = IDirect3DDevice9_GetRenderTargetData(device, surf_tex_rt_dest64, surf_temp64);
3270 ok(SUCCEEDED(hr), "Failed to get render target data, hr %#x.\n", hr);
3271 color = getPixelColorFromSurface(surf_temp64, 32, 32);
3272 ok(color == 0xff000000, "Got unexpected color 0x%08x.\n", color);
3273 /* Blit without scaling. */
3274 hr = IDirect3DDevice9_StretchRect(device, surf_rt64, &src_rect64,
3275 surf_tex_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3276 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3277 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3278 hr = IDirect3DDevice9_StretchRect(device, surf_rt64, &src_rect64_flipy,
3279 surf_tex_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3280 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3281 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3282 hr = IDirect3DDevice9_StretchRect(device, surf_rt64, &src_rect64,
3283 surf_tex_rt_dest64, &dst_rect64_flipy, D3DTEXF_NONE);
3284 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3286 /* rendertarget surface ==> rendertarget surface, same size. */
3287 hr = IDirect3DDevice9_StretchRect(device, surf_rt64, NULL, surf_rt_dest64, NULL, D3DTEXF_NONE);
3288 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3289 color = getPixelColorFromSurface(surf_rt_dest64, 32, 32);
3290 ok(color == 0xff000000, "Got unexpected color 0x%08x.\n", color);
3291 /* Blit without scaling. */
3292 hr = IDirect3DDevice9_StretchRect(device, surf_rt64, &src_rect64,
3293 surf_rt_dest64, &dst_rect64, D3DTEXF_NONE);
3294 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3295 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3296 hr = IDirect3DDevice9_StretchRect(device, surf_rt64, &src_rect64_flipy,
3297 surf_rt_dest64, &dst_rect64_flipy, D3DTEXF_NONE);
3298 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3299 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3300 hr = IDirect3DDevice9_StretchRect(device, surf_rt64, &src_rect64,
3301 surf_rt_dest64, &dst_rect64_flipy, D3DTEXF_NONE);
3302 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3304 /* rendertarget surface ==> texture, same size (should fail). */
3305 hr = IDirect3DDevice9_StretchRect(device, surf_rt64, NULL, surf_tex_dest64, NULL, D3DTEXF_NONE);
3306 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3308 /* Fill the surface of the smaller rendertarget texture with red. */
3309 fill_surface(surf_rt32, 0xffff0000, 0);
3311 /* rendertarget surface ==> offscreenplain, scaling (should fail). */
3312 hr = IDirect3DDevice9_StretchRect(device, surf_rt32, NULL, surf_offscreen64, NULL, D3DTEXF_NONE);
3313 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3315 /* rendertarget surface ==> rendertarget texture, scaling. */
3316 hr = IDirect3DDevice9_StretchRect(device, surf_rt32, NULL, surf_tex_rt_dest64, NULL, D3DTEXF_NONE);
3317 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3318 /* We can't lock rendertarget textures, so copy to our temp surface first. */
3319 hr = IDirect3DDevice9_GetRenderTargetData(device, surf_tex_rt_dest64, surf_temp64);
3320 ok(SUCCEEDED(hr), "Failed to get render target data, hr %#x.\n", hr);
3321 color = getPixelColorFromSurface(surf_temp64, 48, 48);
3322 ok(color == 0xffff0000, "Got unexpected color 0x%08x.\n", color);
3324 /* rendertarget surface ==> rendertarget surface, scaling. */
3325 hr = IDirect3DDevice9_StretchRect(device, surf_rt32, NULL, surf_rt_dest64, NULL, D3DTEXF_NONE);
3326 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3327 color = getPixelColorFromSurface(surf_rt_dest64, 48, 48);
3328 ok(color == 0xffff0000, "Got unexpected color 0x%08x.\n", color);
3330 /* rendertarget surface ==> texture, scaling (should fail). */
3331 hr = IDirect3DDevice9_StretchRect(device, surf_rt32, NULL, surf_tex_dest64, NULL, D3DTEXF_NONE);
3332 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3334 /* backbuffer ==> surface tests (no scaling). */
3335 /* Blit with NULL rectangles. */
3336 hr = IDirect3DDevice9_StretchRect(device, backbuffer, NULL, surf_tex_rt_dest640_480, NULL, D3DTEXF_NONE);
3337 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3338 /* Blit without scaling. */
3339 hr = IDirect3DDevice9_StretchRect(device, backbuffer, &src_rect,
3340 surf_tex_rt_dest640_480, &dst_rect, D3DTEXF_NONE);
3341 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3342 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3343 hr = IDirect3DDevice9_StretchRect(device, backbuffer, &src_rect_flipy,
3344 surf_tex_rt_dest640_480, &dst_rect, D3DTEXF_NONE);
3345 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3346 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3347 hr = IDirect3DDevice9_StretchRect(device, backbuffer, &src_rect,
3348 surf_tex_rt_dest640_480, &dst_rect_flipy, D3DTEXF_NONE);
3349 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3351 /* TODO: Test format conversions. */
3353 IDirect3DSurface9_Release(backbuffer);
3354 IDirect3DSurface9_Release(surf_rt32);
3355 IDirect3DSurface9_Release(surf_rt64);
3356 IDirect3DSurface9_Release(surf_rt_dest64);
3357 IDirect3DSurface9_Release(surf_temp32);
3358 IDirect3DSurface9_Release(surf_temp64);
3359 IDirect3DSurface9_Release(surf_offscreen32);
3360 IDirect3DSurface9_Release(surf_offscreen64);
3361 IDirect3DSurface9_Release(surf_offscreen_dest64);
3362 IDirect3DSurface9_Release(surf_tex_rt32);
3363 IDirect3DTexture9_Release(tex_rt32);
3364 IDirect3DSurface9_Release(surf_tex_rt64);
3365 IDirect3DTexture9_Release(tex_rt64);
3366 IDirect3DSurface9_Release(surf_tex_rt_dest64);
3367 IDirect3DTexture9_Release(tex_rt_dest64);
3368 IDirect3DSurface9_Release(surf_tex_rt_dest640_480);
3369 IDirect3DTexture9_Release(tex_rt_dest640_480);
3370 IDirect3DSurface9_Release(surf_tex32);
3371 IDirect3DTexture9_Release(tex32);
3372 IDirect3DSurface9_Release(surf_tex64);
3373 IDirect3DTexture9_Release(tex64);
3374 IDirect3DSurface9_Release(surf_tex_dest64);
3375 IDirect3DTexture9_Release(tex_dest64);
3376 refcount = IDirect3DDevice9_Release(device);
3377 ok(!refcount, "Device has %u references left.\n", refcount);
3378 done:
3379 IDirect3D9_Release(d3d);
3380 DestroyWindow(window);
3383 static void maxmip_test(void)
3385 IDirect3DTexture9 *texture;
3386 IDirect3DSurface9 *surface;
3387 IDirect3DDevice9 *device;
3388 IDirect3D9 *d3d;
3389 D3DCOLOR color;
3390 ULONG refcount;
3391 D3DCAPS9 caps;
3392 HWND window;
3393 HRESULT hr;
3394 DWORD ret;
3396 static const struct
3398 struct
3400 float x, y, z;
3401 float s, t;
3403 v[4];
3405 quads[] =
3408 {-1.0, -1.0, 0.0, 0.0, 0.0},
3409 {-1.0, 0.0, 0.0, 0.0, 1.0},
3410 { 0.0, -1.0, 0.0, 1.0, 0.0},
3411 { 0.0, 0.0, 0.0, 1.0, 1.0},
3414 { 0.0, -1.0, 0.0, 0.0, 0.0},
3415 { 0.0, 0.0, 0.0, 0.0, 1.0},
3416 { 1.0, -1.0, 0.0, 1.0, 0.0},
3417 { 1.0, 0.0, 0.0, 1.0, 1.0},
3420 { 0.0, 0.0, 0.0, 0.0, 0.0},
3421 { 0.0, 1.0, 0.0, 0.0, 1.0},
3422 { 1.0, 0.0, 0.0, 1.0, 0.0},
3423 { 1.0, 1.0, 0.0, 1.0, 1.0},
3426 {-1.0, 0.0, 0.0, 0.0, 0.0},
3427 {-1.0, 1.0, 0.0, 0.0, 1.0},
3428 { 0.0, 0.0, 0.0, 1.0, 0.0},
3429 { 0.0, 1.0, 0.0, 1.0, 1.0},
3433 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3434 0, 0, 640, 480, NULL, NULL, NULL, NULL);
3435 d3d = Direct3DCreate9(D3D_SDK_VERSION);
3436 ok(!!d3d, "Failed to create a D3D object.\n");
3437 if (!(device = create_device(d3d, window, window, TRUE)))
3439 skip("Failed to create a D3D device, skipping tests.\n");
3440 goto done;
3443 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
3444 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
3445 if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPMAP))
3447 skip("No mipmap support, skipping tests.\n");
3448 IDirect3DDevice9_Release(device);
3449 goto done;
3452 hr = IDirect3DDevice9_CreateTexture(device, 128, 128, 3, 0,
3453 D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture, NULL);
3454 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
3456 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
3457 ok(SUCCEEDED(hr), "IDirect3DTexture9_GetSurfaceLevel returned %#x.\n", hr);
3458 fill_surface(surface, 0xffff0000, 0);
3459 IDirect3DSurface9_Release(surface);
3460 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 1, &surface);
3461 ok(SUCCEEDED(hr), "IDirect3DTexture9_GetSurfaceLevel returned %#x.\n", hr);
3462 fill_surface(surface, 0xff00ff00, 0);
3463 IDirect3DSurface9_Release(surface);
3464 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 2, &surface);
3465 ok(SUCCEEDED(hr), "IDirect3DTexture9_GetSurfaceLevel returned %#x.\n", hr);
3466 fill_surface(surface, 0xff0000ff, 0);
3467 IDirect3DSurface9_Release(surface);
3469 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) texture);
3470 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture failed with %08x\n", hr);
3471 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
3472 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
3474 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
3475 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3476 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
3477 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState failed with %08x\n", hr);
3479 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 0.0, 0);
3480 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
3482 hr = IDirect3DDevice9_BeginScene(device);
3483 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3485 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 0);
3486 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
3487 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[0], sizeof(*quads->v));
3488 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3490 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 1);
3491 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
3492 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[1], sizeof(*quads->v));
3493 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3495 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 2);
3496 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
3497 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[2], sizeof(*quads->v));
3498 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3500 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 3);
3501 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
3502 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[3], sizeof(*quads->v));
3503 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3505 hr = IDirect3DDevice9_EndScene(device);
3506 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3508 /* With mipmapping disabled, the max mip level is ignored, only level 0 is used */
3509 color = getPixelColor(device, 160, 360);
3510 ok(color == 0x00ff0000, "MaxMip 0, no mipfilter has color 0x%08x.\n", color);
3511 color = getPixelColor(device, 480, 360);
3512 ok(color == 0x00ff0000, "MaxMip 1, no mipfilter has color 0x%08x.\n", color);
3513 color = getPixelColor(device, 480, 120);
3514 ok(color == 0x00ff0000, "MaxMip 2, no mipfilter has color 0x%08x.\n", color);
3515 color = getPixelColor(device, 160, 120);
3516 ok(color == 0x00ff0000, "MaxMip 3, no mipfilter has color 0x%08x.\n", color);
3517 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
3518 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
3520 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
3521 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState failed with %08x\n", hr);
3523 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 0.0, 0);
3524 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
3526 hr = IDirect3DDevice9_BeginScene(device);
3527 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3529 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 0);
3530 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
3531 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[0], sizeof(*quads->v));
3532 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3534 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 1);
3535 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
3536 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[1], sizeof(*quads->v));
3537 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3539 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 2);
3540 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
3541 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[2], sizeof(*quads->v));
3542 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3544 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 3);
3545 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
3546 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[3], sizeof(*quads->v));
3547 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3549 hr = IDirect3DDevice9_EndScene(device);
3550 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3552 /* Max Mip level 0-2 sample from the specified texture level, Max Mip
3553 * level 3 (> levels in texture) samples from the highest level in the
3554 * texture (level 2). */
3555 color = getPixelColor(device, 160, 360);
3556 ok(color == 0x00ff0000, "MaxMip 0, point mipfilter has color 0x%08x.\n", color);
3557 color = getPixelColor(device, 480, 360);
3558 ok(color == 0x0000ff00, "MaxMip 1, point mipfilter has color 0x%08x.\n", color);
3559 color = getPixelColor(device, 480, 120);
3560 ok(color == 0x000000ff, "MaxMip 2, point mipfilter has color 0x%08x.\n", color);
3561 color = getPixelColor(device, 160, 120);
3562 ok(color == 0x000000ff, "MaxMip 3, point mipfilter has color 0x%08x.\n", color);
3563 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
3564 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
3566 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 0.0, 0);
3567 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
3569 hr = IDirect3DDevice9_BeginScene(device);
3570 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3572 /* Mipmapping OFF, LOD level smaller than MAXMIPLEVEL. LOD level limits */
3573 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
3574 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
3575 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 0);
3576 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
3577 ret = IDirect3DTexture9_SetLOD(texture, 1);
3578 ok(ret == 0, "Got unexpected LOD %u.\n", ret);
3579 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[0], sizeof(*quads->v));
3580 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3582 /* Mipmapping ON, LOD level smaller than max mip level. LOD level limits */
3583 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
3584 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
3585 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 1);
3586 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
3587 ret = IDirect3DTexture9_SetLOD(texture, 2);
3588 ok(ret == 1, "Got unexpected LOD %u.\n", ret);
3589 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[1], sizeof(*quads->v));
3590 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3592 /* Mipmapping ON, LOD level bigger than max mip level. MAXMIPLEVEL limits */
3593 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 2);
3594 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
3595 ret = IDirect3DTexture9_SetLOD(texture, 1);
3596 ok(ret == 2, "Got unexpected LOD %u.\n", ret);
3597 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[2], sizeof(*quads->v));
3598 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3600 /* Mipmapping OFF, LOD level bigger than max mip level. LOD level limits */
3601 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
3602 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
3603 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAXMIPLEVEL, 2);
3604 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
3605 ret = IDirect3DTexture9_SetLOD(texture, 1);
3606 ok(ret == 1, "Got unexpected LOD %u.\n", ret);
3607 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[3], sizeof(*quads->v));
3608 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3610 hr = IDirect3DDevice9_EndScene(device);
3611 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3613 /* Max Mip level 0-2 sample from the specified texture level, Max Mip
3614 * level 3 (> levels in texture) samples from the highest level in the
3615 * texture (level 2). */
3616 color = getPixelColor(device, 160, 360);
3617 ok(color == 0x0000ff00, "MaxMip 0, LOD 1, none mipfilter has color 0x%08x.\n", color);
3618 color = getPixelColor(device, 480, 360);
3619 ok(color == 0x000000ff, "MaxMip 1, LOD 2, point mipfilter has color 0x%08x.\n", color);
3620 color = getPixelColor(device, 480, 120);
3621 ok(color == 0x000000ff, "MaxMip 2, LOD 1, point mipfilter has color 0x%08x.\n", color);
3622 color = getPixelColor(device, 160, 120);
3623 ok(color == 0x0000ff00, "MaxMip 2, LOD 1, none mipfilter has color 0x%08x.\n", color);
3625 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
3626 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
3628 IDirect3DTexture9_Release(texture);
3629 refcount = IDirect3DDevice9_Release(device);
3630 ok(!refcount, "Device has %u references left.\n", refcount);
3631 done:
3632 IDirect3D9_Release(d3d);
3633 DestroyWindow(window);
3636 static void release_buffer_test(void)
3638 IDirect3DVertexBuffer9 *vb;
3639 IDirect3DIndexBuffer9 *ib;
3640 IDirect3DDevice9 *device;
3641 IDirect3D9 *d3d;
3642 D3DCOLOR color;
3643 ULONG refcount;
3644 HWND window;
3645 HRESULT hr;
3646 BYTE *data;
3647 LONG ref;
3649 static const short indices[] = {3, 4, 5};
3650 static const struct
3652 struct vec3 position;
3653 DWORD diffuse;
3655 quad[] =
3657 {{-1.0f, -1.0f, 0.1f}, 0xffff0000},
3658 {{-1.0f, 1.0f, 0.1f}, 0xffff0000},
3659 {{ 1.0f, 1.0f, 0.1f}, 0xffff0000},
3661 {{-1.0f, -1.0f, 0.1f}, 0xff00ff00},
3662 {{-1.0f, 1.0f, 0.1f}, 0xff00ff00},
3663 {{ 1.0f, 1.0f, 0.1f}, 0xff00ff00},
3666 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3667 0, 0, 640, 480, NULL, NULL, NULL, NULL);
3668 d3d = Direct3DCreate9(D3D_SDK_VERSION);
3669 ok(!!d3d, "Failed to create a D3D object.\n");
3670 if (!(device = create_device(d3d, window, window, TRUE)))
3672 skip("Failed to create a D3D device, skipping tests.\n");
3673 goto done;
3676 /* Index and vertex buffers should always be creatable */
3677 hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(quad), 0,
3678 D3DFVF_XYZ | D3DFVF_DIFFUSE, D3DPOOL_MANAGED, &vb, NULL);
3679 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3680 hr = IDirect3DVertexBuffer9_Lock(vb, 0, sizeof(quad), (void **) &data, 0);
3681 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr);
3682 memcpy(data, quad, sizeof(quad));
3683 hr = IDirect3DVertexBuffer9_Unlock(vb);
3684 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed with %08x\n", hr);
3686 hr = IDirect3DDevice9_CreateIndexBuffer(device, sizeof(indices), 0,
3687 D3DFMT_INDEX16, D3DPOOL_DEFAULT, &ib, NULL);
3688 ok(SUCCEEDED(hr), "Failed to create index buffer, hr %#x.\n", hr);
3689 hr = IDirect3DIndexBuffer9_Lock(ib, 0, sizeof(indices), (void **) &data, 0);
3690 ok(hr == D3D_OK, "IDirect3DIndexBuffer9_Lock failed with %08x\n", hr);
3691 memcpy(data, indices, sizeof(indices));
3692 hr = IDirect3DIndexBuffer9_Unlock(ib);
3693 ok(hr == D3D_OK, "IDirect3DIndexBuffer9_Unlock failed with %08x\n", hr);
3695 hr = IDirect3DDevice9_SetIndices(device, ib);
3696 ok(hr == D3D_OK, "IDirect3DDevice9_SetIndices failed with %08x\n", hr);
3697 hr = IDirect3DDevice9_SetStreamSource(device, 0, vb, 0, sizeof(quad[0]));
3698 ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSource failed with %08x\n", hr);
3699 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
3700 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
3701 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
3702 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3704 /* Now destroy the bound index buffer and draw again */
3705 ref = IDirect3DIndexBuffer9_Release(ib);
3706 ok(ref == 0, "Index Buffer reference count is %08d\n", ref);
3708 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
3709 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
3711 hr = IDirect3DDevice9_BeginScene(device);
3712 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3713 /* Deliberately using minvertexindex = 0 and numVertices = 6 to prevent
3714 * D3D from making assumptions about the indices or vertices. */
3715 hr = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0, 3, 3, 0, 1);
3716 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3717 hr = IDirect3DDevice9_EndScene(device);
3718 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3720 color = getPixelColor(device, 160, 120);
3721 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1), "Got unexpected color 0x%08x.\n", color);
3722 color = getPixelColor(device, 480, 360);
3723 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0xff), 1), "Got unexpected color 0x%08x.\n", color);
3725 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
3726 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
3728 /* Index buffer was already destroyed as part of the test */
3729 IDirect3DVertexBuffer9_Release(vb);
3730 refcount = IDirect3DDevice9_Release(device);
3731 ok(!refcount, "Device has %u references left.\n", refcount);
3732 done:
3733 IDirect3D9_Release(d3d);
3734 DestroyWindow(window);
3737 static void float_texture_test(void)
3739 IDirect3DTexture9 *texture;
3740 IDirect3DDevice9 *device;
3741 D3DLOCKED_RECT lr;
3742 IDirect3D9 *d3d;
3743 ULONG refcount;
3744 float *data;
3745 DWORD color;
3746 HWND window;
3747 HRESULT hr;
3749 static const float quad[] =
3751 -1.0f, -1.0f, 0.1f, 0.0f, 0.0f,
3752 -1.0f, 1.0f, 0.1f, 0.0f, 1.0f,
3753 1.0f, -1.0f, 0.1f, 1.0f, 0.0f,
3754 1.0f, 1.0f, 0.1f, 1.0f, 1.0f,
3757 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3758 0, 0, 640, 480, NULL, NULL, NULL, NULL);
3759 d3d = Direct3DCreate9(D3D_SDK_VERSION);
3760 ok(!!d3d, "Failed to create a D3D object.\n");
3761 if (!(device = create_device(d3d, window, window, TRUE)))
3763 skip("Failed to create a D3D device, skipping tests.\n");
3764 goto done;
3767 if (IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL,
3768 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, D3DFMT_R32F) != D3D_OK)
3770 skip("D3DFMT_R32F textures not supported\n");
3771 IDirect3DDevice9_Release(device);
3772 goto done;
3775 hr = IDirect3DDevice9_CreateTexture(device, 1, 1, 1, 0, D3DFMT_R32F, D3DPOOL_MANAGED, &texture, NULL);
3776 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
3778 memset(&lr, 0, sizeof(lr));
3779 hr = IDirect3DTexture9_LockRect(texture, 0, &lr, NULL, 0);
3780 ok(hr == D3D_OK, "IDirect3DTexture9_LockRect failed with %08x\n", hr);
3781 data = lr.pBits;
3782 *data = 0.0;
3783 hr = IDirect3DTexture9_UnlockRect(texture, 0);
3784 ok(hr == D3D_OK, "IDirect3DTexture9_UnlockRect failed with %08x\n", hr);
3786 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
3787 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3788 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
3789 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture failed with %08x\n", hr);
3791 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
3792 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
3794 hr = IDirect3DDevice9_BeginScene(device);
3795 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3796 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
3797 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
3798 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
3799 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3800 hr = IDirect3DDevice9_EndScene(device);
3801 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3803 color = getPixelColor(device, 240, 320);
3804 ok(color == 0x0000ffff, "R32F with value 0.0 has color %08x, expected 0x0000ffff\n", color);
3806 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
3807 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
3809 IDirect3DTexture9_Release(texture);
3810 refcount = IDirect3DDevice9_Release(device);
3811 ok(!refcount, "Device has %u references left.\n", refcount);
3812 done:
3813 IDirect3D9_Release(d3d);
3814 DestroyWindow(window);
3817 static void g16r16_texture_test(void)
3819 IDirect3DTexture9 *texture;
3820 IDirect3DDevice9 *device;
3821 D3DLOCKED_RECT lr;
3822 IDirect3D9 *d3d;
3823 ULONG refcount;
3824 DWORD *data;
3825 DWORD color;
3826 HWND window;
3827 HRESULT hr;
3829 static const float quad[] =
3831 -1.0f, -1.0f, 0.1f, 0.0f, 0.0f,
3832 -1.0f, 1.0f, 0.1f, 0.0f, 1.0f,
3833 1.0f, -1.0f, 0.1f, 1.0f, 0.0f,
3834 1.0f, 1.0f, 0.1f, 1.0f, 1.0f,
3837 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3838 0, 0, 640, 480, NULL, NULL, NULL, NULL);
3839 d3d = Direct3DCreate9(D3D_SDK_VERSION);
3840 ok(!!d3d, "Failed to create a D3D object.\n");
3841 if (!(device = create_device(d3d, window, window, TRUE)))
3843 skip("Failed to create a D3D device, skipping tests.\n");
3844 goto done;
3847 if (IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL,
3848 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, D3DFMT_G16R16) != D3D_OK)
3850 skip("D3DFMT_G16R16 textures not supported\n");
3851 IDirect3DDevice9_Release(device);
3852 goto done;
3855 hr = IDirect3DDevice9_CreateTexture(device, 1, 1, 1, 0, D3DFMT_G16R16, D3DPOOL_MANAGED, &texture, NULL);
3856 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
3858 memset(&lr, 0, sizeof(lr));
3859 hr = IDirect3DTexture9_LockRect(texture, 0, &lr, NULL, 0);
3860 ok(hr == D3D_OK, "IDirect3DTexture9_LockRect failed with %08x\n", hr);
3861 data = lr.pBits;
3862 *data = 0x0f00f000;
3863 hr = IDirect3DTexture9_UnlockRect(texture, 0);
3864 ok(hr == D3D_OK, "IDirect3DTexture9_UnlockRect failed with %08x\n", hr);
3866 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
3867 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3868 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
3869 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture failed with %08x\n", hr);
3871 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
3872 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
3874 hr = IDirect3DDevice9_BeginScene(device);
3875 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3876 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
3877 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
3878 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
3879 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3880 hr = IDirect3DDevice9_EndScene(device);
3881 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3883 color = getPixelColor(device, 240, 320);
3884 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xf0, 0x0f, 0xff), 1),
3885 "D3DFMT_G16R16 with value 0x00ffff00 has color %08x, expected 0x00f00fff\n", color);
3887 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
3888 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
3890 IDirect3DTexture9_Release(texture);
3891 refcount = IDirect3DDevice9_Release(device);
3892 ok(!refcount, "Device has %u references left.\n", refcount);
3893 done:
3894 IDirect3D9_Release(d3d);
3895 DestroyWindow(window);
3898 static void check_rect(IDirect3DDevice9 *device, RECT r, const char *message)
3900 LONG x_coords[2][2] =
3902 {r.left - 1, r.left + 1},
3903 {r.right + 1, r.right - 1},
3905 LONG y_coords[2][2] =
3907 {r.top - 1, r.top + 1},
3908 {r.bottom + 1, r.bottom - 1}
3910 unsigned int i, j, x_side, y_side;
3912 for (i = 0; i < 2; ++i)
3914 for (j = 0; j < 2; ++j)
3916 for (x_side = 0; x_side < 2; ++x_side)
3918 for (y_side = 0; y_side < 2; ++y_side)
3920 unsigned int x = x_coords[i][x_side], y = y_coords[j][y_side];
3921 DWORD color;
3922 DWORD expected = (x_side == 1 && y_side == 1) ? 0x00ffffff : 0;
3924 color = getPixelColor(device, x, y);
3925 ok(color == expected, "%s: Pixel (%d, %d) has color %08x, expected %08x\n",
3926 message, x, y, color, expected);
3933 struct projected_textures_test_run
3935 const char *message;
3936 DWORD flags;
3937 IDirect3DVertexDeclaration9 *decl;
3938 BOOL vs, ps;
3939 RECT rect;
3942 static void projected_textures_test(IDirect3DDevice9 *device,
3943 struct projected_textures_test_run tests[4])
3945 unsigned int i;
3947 static const DWORD vertex_shader[] =
3949 0xfffe0101, /* vs_1_1 */
3950 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
3951 0x0000001f, 0x80000005, 0x900f0001, /* dcl_texcoord0 v1 */
3952 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
3953 0x00000001, 0xe00f0000, 0x90e40001, /* mov oT0, v1 */
3954 0x0000ffff /* end */
3956 static const DWORD pixel_shader[] =
3958 0xffff0103, /* ps_1_3 */
3959 0x00000042, 0xb00f0000, /* tex t0 */
3960 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
3961 0x0000ffff /* end */
3963 IDirect3DVertexShader9 *vs = NULL;
3964 IDirect3DPixelShader9 *ps = NULL;
3965 IDirect3D9 *d3d;
3966 D3DCAPS9 caps;
3967 HRESULT hr;
3969 IDirect3DDevice9_GetDirect3D(device, &d3d);
3970 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
3971 ok(SUCCEEDED(hr), "GetDeviceCaps failed (%08x)\n", hr);
3972 IDirect3D9_Release(d3d);
3974 if (caps.VertexShaderVersion >= D3DVS_VERSION(1, 1))
3976 hr = IDirect3DDevice9_CreateVertexShader(device, vertex_shader, &vs);
3977 ok(SUCCEEDED(hr), "CreateVertexShader failed (%08x)\n", hr);
3979 if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 3))
3981 hr = IDirect3DDevice9_CreatePixelShader(device, pixel_shader, &ps);
3982 ok(SUCCEEDED(hr), "CreatePixelShader failed (%08x)\n", hr);
3985 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff203040, 0.0f, 0);
3986 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
3988 hr = IDirect3DDevice9_BeginScene(device);
3989 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3991 for (i = 0; i < 4; ++i)
3993 DWORD value = 0xdeadbeef;
3994 static const float proj_quads[] =
3996 -1.0f, -1.0f, 0.1f, 0.0f, 0.0f, 4.0f, 6.0f,
3997 -1.0f, 0.0f, 0.1f, 0.0f, 4.0f, 4.0f, 6.0f,
3998 0.0f, -1.0f, 0.1f, 4.0f, 0.0f, 4.0f, 6.0f,
3999 0.0f, 0.0f, 0.1f, 4.0f, 4.0f, 4.0f, 6.0f,
4001 0.0f, -1.0f, 0.1f, 0.0f, 0.0f, 4.0f, 6.0f,
4002 0.0f, 0.0f, 0.1f, 0.0f, 4.0f, 4.0f, 6.0f,
4003 1.0f, -1.0f, 0.1f, 4.0f, 0.0f, 4.0f, 6.0f,
4004 1.0f, 0.0f, 0.1f, 4.0f, 4.0f, 4.0f, 6.0f,
4006 -1.0f, 0.0f, 0.1f, 0.0f, 0.0f, 4.0f, 6.0f,
4007 -1.0f, 1.0f, 0.1f, 0.0f, 4.0f, 4.0f, 6.0f,
4008 0.0f, 0.0f, 0.1f, 4.0f, 0.0f, 4.0f, 6.0f,
4009 0.0f, 1.0f, 0.1f, 4.0f, 4.0f, 4.0f, 6.0f,
4011 0.0f, 0.0f, 0.1f, 0.0f, 0.0f, 4.0f, 6.0f,
4012 0.0f, 1.0f, 0.1f, 0.0f, 4.0f, 4.0f, 6.0f,
4013 1.0f, 0.0f, 0.1f, 4.0f, 0.0f, 4.0f, 6.0f,
4014 1.0f, 1.0f, 0.1f, 4.0f, 4.0f, 4.0f, 6.0f,
4017 if (tests[i].vs)
4019 if (!vs)
4021 skip("Vertex shaders not supported, skipping\n");
4022 continue;
4024 hr = IDirect3DDevice9_SetVertexShader(device, vs);
4026 else
4027 hr = IDirect3DDevice9_SetVertexShader(device, NULL);
4028 ok(SUCCEEDED(hr), "SetVertexShader failed (%08x)\n", hr);
4029 if (tests[i].ps)
4031 if (!ps)
4033 skip("Pixel shaders not supported, skipping\n");
4034 continue;
4036 hr = IDirect3DDevice9_SetPixelShader(device, ps);
4038 else
4039 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
4040 ok(SUCCEEDED(hr), "SetPixelShader failed (%08x)\n", hr);
4042 hr = IDirect3DDevice9_SetVertexDeclaration(device, tests[i].decl);
4043 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexDeclaration failed with %08x\n", hr);
4045 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, tests[i].flags);
4046 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
4047 hr = IDirect3DDevice9_GetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, &value);
4048 ok(SUCCEEDED(hr) && value == tests[i].flags,
4049 "GetTextureStageState returned: hr %08x, value %08x.\n", hr, value);
4051 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2,
4052 &proj_quads[i * 4 * 7], 7 * sizeof(float));
4053 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%08x)\n", hr);
4056 hr = IDirect3DDevice9_EndScene(device);
4057 ok(hr == D3D_OK, "IDirect3DDevice9_EndScene failed with %08x\n", hr);
4059 hr = IDirect3DDevice9_SetVertexShader(device, NULL);
4060 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
4061 if (vs) IDirect3DVertexShader9_Release(vs);
4062 if (ps) IDirect3DPixelShader9_Release(ps);
4064 for (i = 0; i < 4; ++i)
4066 if ((!tests[i].vs || vs) && (!tests[i].ps || ps))
4067 check_rect(device, tests[i].rect, tests[i].message);
4070 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
4071 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
4074 static void texture_transform_flags_test(void)
4076 HRESULT hr;
4077 IDirect3D9 *d3d;
4078 D3DFORMAT fmt = D3DFMT_X8R8G8B8;
4079 D3DCAPS9 caps;
4080 IDirect3DTexture9 *texture = NULL;
4081 IDirect3DVolumeTexture9 *volume = NULL;
4082 IDirect3DDevice9 *device;
4083 unsigned int x, y, z;
4084 D3DLOCKED_RECT lr;
4085 D3DLOCKED_BOX lb;
4086 D3DCOLOR color;
4087 ULONG refcount;
4088 HWND window;
4089 UINT w, h;
4090 IDirect3DVertexDeclaration9 *decl, *decl2, *decl3, *decl4;
4092 static const D3DVERTEXELEMENT9 decl_elements[] = {
4093 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
4094 {0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
4095 D3DDECL_END()
4097 static const D3DVERTEXELEMENT9 decl_elements2[] = {
4098 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
4099 {0, 12, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
4100 D3DDECL_END()
4102 static const D3DVERTEXELEMENT9 decl_elements3[] = {
4103 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
4104 {0, 12, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
4105 D3DDECL_END()
4107 static const D3DVERTEXELEMENT9 decl_elements4[] = {
4108 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
4109 {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
4110 D3DDECL_END()
4112 static const unsigned char proj_texdata[] = {0x00, 0x00, 0x00, 0x00,
4113 0x00, 0xff, 0x00, 0x00,
4114 0x00, 0x00, 0x00, 0x00,
4115 0x00, 0x00, 0x00, 0x00};
4116 static const D3DMATRIX identity =
4118 1.0f, 0.0f, 0.0f, 0.0f,
4119 0.0f, 1.0f, 0.0f, 0.0f,
4120 0.0f, 0.0f, 1.0f, 0.0f,
4121 0.0f, 0.0f, 0.0f, 1.0f,
4122 }}};
4124 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4125 0, 0, 640, 480, NULL, NULL, NULL, NULL);
4126 d3d = Direct3DCreate9(D3D_SDK_VERSION);
4127 ok(!!d3d, "Failed to create a D3D object.\n");
4128 if (!(device = create_device(d3d, window, window, TRUE)))
4130 skip("Failed to create a D3D device, skipping tests.\n");
4131 goto done;
4134 memset(&lr, 0, sizeof(lr));
4135 memset(&lb, 0, sizeof(lb));
4136 if (IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL,
4137 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16) == D3D_OK)
4138 fmt = D3DFMT_A16B16G16R16;
4140 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &decl);
4141 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
4142 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements2, &decl2);
4143 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
4144 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements3, &decl3);
4145 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
4146 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements4, &decl4);
4147 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
4148 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, FALSE);
4149 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState(D3DSAMP_SRGBTEXTURE) returned %08x\n", hr);
4150 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
4151 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState(D3DSAMP_MAGFILTER) returned %08x\n", hr);
4152 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
4153 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState(D3DSAMP_MINFILTER) returned %08x\n", hr);
4154 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
4155 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState(D3DSAMP_MIPFILTER) returned %08x\n", hr);
4156 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
4157 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState(D3DSAMP_ADDRESSU) returned %08x\n", hr);
4158 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
4159 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState(D3DSAMP_ADDRESSV) returned %08x\n", hr);
4160 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSW, D3DTADDRESS_CLAMP);
4161 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState(D3DSAMP_ADDRESSW) returned %08x\n", hr);
4162 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
4163 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState(D3DTSS_COLOROP) returned %08x\n", hr);
4164 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
4165 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState(D3DTSS_COLORARG1) returned %08x\n", hr);
4166 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
4167 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState(D3DRS_LIGHTING) returned %08x\n", hr);
4168 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
4169 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
4171 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
4172 ok(hr == D3D_OK, "IDirect3DDevice9_GetDeviceCaps returned %08x\n", hr);
4173 w = min(1024, caps.MaxTextureWidth);
4174 h = min(1024, caps.MaxTextureHeight);
4175 hr = IDirect3DDevice9_CreateTexture(device, w, h, 1,
4176 0, fmt, D3DPOOL_MANAGED, &texture, NULL);
4177 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture returned %08x\n", hr);
4178 if (!texture)
4180 skip("Failed to create the test texture.\n");
4181 IDirect3DDevice9_Release(device);
4182 goto done;
4185 /* Unfortunately there is no easy way to set up a texture coordinate passthrough
4186 * in d3d fixed function pipeline, so create a texture that has a gradient from 0.0 to
4187 * 1.0 in red and green for the x and y coords
4189 hr = IDirect3DTexture9_LockRect(texture, 0, &lr, NULL, 0);
4190 ok(hr == D3D_OK, "IDirect3DTexture9_LockRect returned %08x\n", hr);
4191 for(y = 0; y < h; y++) {
4192 for(x = 0; x < w; x++) {
4193 double r_f = (double) y / (double) h;
4194 double g_f = (double) x / (double) w;
4195 if(fmt == D3DFMT_A16B16G16R16) {
4196 unsigned short r, g;
4197 unsigned short *dst = (unsigned short *) (((char *) lr.pBits) + y * lr.Pitch + x * 8);
4198 r = (unsigned short) (r_f * 65536.0);
4199 g = (unsigned short) (g_f * 65536.0);
4200 dst[0] = r;
4201 dst[1] = g;
4202 dst[2] = 0;
4203 dst[3] = 65535;
4204 } else {
4205 unsigned char *dst = ((unsigned char *) lr.pBits) + y * lr.Pitch + x * 4;
4206 unsigned char r = (unsigned char) (r_f * 255.0);
4207 unsigned char g = (unsigned char) (g_f * 255.0);
4208 dst[0] = 0;
4209 dst[1] = g;
4210 dst[2] = r;
4211 dst[3] = 255;
4215 hr = IDirect3DTexture9_UnlockRect(texture, 0);
4216 ok(hr == D3D_OK, "IDirect3DTexture9_UnlockRect returned %08x\n", hr);
4217 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) texture);
4218 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture returned %08x\n", hr);
4220 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
4221 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
4222 hr = IDirect3DDevice9_BeginScene(device);
4223 ok(hr == D3D_OK, "IDirect3DDevice9_BeginScene failed with %08x\n", hr);
4224 if(SUCCEEDED(hr))
4226 static const float quad1[] =
4228 -1.0f, -1.0f, 0.1f, 1.0f, 1.0f,
4229 -1.0f, 0.0f, 0.1f, 1.0f, 1.0f,
4230 0.0f, -1.0f, 0.1f, 1.0f, 1.0f,
4231 0.0f, 0.0f, 0.1f, 1.0f, 1.0f,
4233 static const float quad2[] =
4235 -1.0f, 0.0f, 0.1f, 1.0f, 1.0f,
4236 -1.0f, 1.0f, 0.1f, 1.0f, 1.0f,
4237 0.0f, 0.0f, 0.1f, 1.0f, 1.0f,
4238 0.0f, 1.0f, 0.1f, 1.0f, 1.0f,
4240 static const float quad3[] =
4242 0.0f, 0.0f, 0.1f, 0.5f, 0.5f,
4243 0.0f, 1.0f, 0.1f, 0.5f, 0.5f,
4244 1.0f, 0.0f, 0.1f, 0.5f, 0.5f,
4245 1.0f, 1.0f, 0.1f, 0.5f, 0.5f,
4247 static const float quad4[] =
4249 320.0f, 480.0f, 0.1f, 1.0f, 0.0f, 1.0f,
4250 320.0f, 240.0f, 0.1f, 1.0f, 0.0f, 1.0f,
4251 640.0f, 480.0f, 0.1f, 1.0f, 0.0f, 1.0f,
4252 640.0f, 240.0f, 0.1f, 1.0f, 0.0f, 1.0f,
4254 D3DMATRIX mat =
4256 0.0f, 0.0f, 0.0f, 0.0f,
4257 0.0f, 0.0f, 0.0f, 0.0f,
4258 0.0f, 0.0f, 0.0f, 0.0f,
4259 0.0f, 0.0f, 0.0f, 0.0f,
4260 }}};
4262 /* What happens with the texture matrix if D3DTSS_TEXTURETRANSFORMFLAGS is disabled? */
4263 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &mat);
4264 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
4265 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, 5 * sizeof(float));
4266 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%08x)\n", hr);
4268 /* What happens with transforms enabled? */
4269 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
4270 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
4271 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 5 * sizeof(float));
4272 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%08x)\n", hr);
4274 /* What happens if 4 coords are used, but only 2 given ?*/
4275 U(mat).m[2][0] = 1.0f;
4276 U(mat).m[3][1] = 1.0f;
4277 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &mat);
4278 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
4279 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT4);
4280 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
4281 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, 5 * sizeof(float));
4282 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%08x)\n", hr);
4284 /* What happens with transformed geometry? This setup lead to 0/0 coords with untransformed
4285 * geometry. If the same applies to transformed vertices, the quad will be black, otherwise red,
4286 * due to the coords in the vertices. (turns out red, indeed)
4288 memset(&mat, 0, sizeof(mat));
4289 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &mat);
4290 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
4291 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZRHW | D3DFVF_TEX1);
4292 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
4293 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
4294 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
4295 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, 6 * sizeof(float));
4296 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%08x)\n", hr);
4298 hr = IDirect3DDevice9_EndScene(device);
4299 ok(hr == D3D_OK, "IDirect3DDevice9_EndScene failed with %08x\n", hr);
4301 color = getPixelColor(device, 160, 360);
4302 ok(color_match(color, 0x00ffff00, 1), "quad 1 has color %08x, expected 0x00ffff00\n", color);
4303 color = getPixelColor(device, 160, 120);
4304 ok(color == 0x00000000, "quad 2 has color %08x, expected 0x0000000\n", color);
4305 color = getPixelColor(device, 480, 120);
4306 ok(color_match(color, 0x0000ff00, 1), "quad 3 has color %08x, expected 0x0000ff00\n", color);
4307 color = getPixelColor(device, 480, 360);
4308 ok(color_match(color, 0x00ff0000, 1), "quad 4 has color %08x, expected 0x00ff0000\n", color);
4309 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
4310 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
4312 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0, 0);
4313 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
4315 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
4316 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
4317 hr = IDirect3DDevice9_BeginScene(device);
4318 ok(hr == D3D_OK, "IDirect3DDevice9_BeginScene failed with %08x\n", hr);
4319 if(SUCCEEDED(hr))
4321 static const float quad1[] =
4323 -1.0f, -1.0f, 0.1f, 0.8f, 0.2f,
4324 -1.0f, 0.0f, 0.1f, 0.8f, 0.2f,
4325 0.0f, -1.0f, 0.1f, 0.8f, 0.2f,
4326 0.0f, 0.0f, 0.1f, 0.8f, 0.2f,
4328 static const float quad2[] =
4330 -1.0f, 0.0f, 0.1f, 0.5f, 1.0f,
4331 -1.0f, 1.0f, 0.1f, 0.5f, 1.0f,
4332 0.0f, 0.0f, 0.1f, 0.5f, 1.0f,
4333 0.0f, 1.0f, 0.1f, 0.5f, 1.0f,
4335 static const float quad3[] =
4337 0.0f, 0.0f, 0.1f, 0.5f, 1.0f,
4338 0.0f, 1.0f, 0.1f, 0.5f, 1.0f,
4339 1.0f, 0.0f, 0.1f, 0.5f, 1.0f,
4340 1.0f, 1.0f, 0.1f, 0.5f, 1.0f,
4342 static const float quad4[] =
4344 0.0f, -1.0f, 0.1f, 0.8f, 0.2f,
4345 0.0f, 0.0f, 0.1f, 0.8f, 0.2f,
4346 1.0f, -1.0f, 0.1f, 0.8f, 0.2f,
4347 1.0f, 0.0f, 0.1f, 0.8f, 0.2f,
4349 D3DMATRIX mat =
4351 0.0f, 0.0f, 0.0f, 0.0f,
4352 0.0f, 0.0f, 0.0f, 0.0f,
4353 0.0f, 1.0f, 0.0f, 0.0f,
4354 0.0f, 0.0f, 0.0f, 0.0f,
4355 }}};
4357 /* What happens to the default 1 in the 3rd coordinate if it is disabled? */
4358 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &mat);
4359 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
4360 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
4361 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
4363 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, 5 * sizeof(float));
4364 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%08x)\n", hr);
4366 /* D3DTFF_COUNT1 does not work on Nvidia drivers. It behaves like D3DTTFF_DISABLE. On ATI drivers
4367 * it behaves like COUNT2 because normal textures require 2 coords. */
4368 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT1);
4369 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
4370 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, 5 * sizeof(float));
4371 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%08x)\n", hr);
4373 /* Just to be sure, the same as quad2 above */
4374 memset(&mat, 0, sizeof(mat));
4375 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &mat);
4376 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
4377 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
4378 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
4379 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 5 * sizeof(float));
4380 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%08x)\n", hr);
4382 /* Now, what happens to the 2nd coordinate(that is disabled in the matrix) if it is not
4383 * used? And what happens to the first? */
4384 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT1);
4385 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
4386 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, 5 * sizeof(float));
4387 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (%08x)\n", hr);
4389 hr = IDirect3DDevice9_EndScene(device);
4390 ok(hr == D3D_OK, "IDirect3DDevice9_EndScene failed with %08x\n", hr);
4392 color = getPixelColor(device, 160, 360);
4393 ok(color_match(color, 0x00ff0000, 1), "quad 1 has color %08x, expected 0x00ff0000\n", color);
4394 color = getPixelColor(device, 160, 120);
4395 ok(color == 0x00000000, "quad 2 has color %08x, expected 0x0000000\n", color);
4396 color = getPixelColor(device, 480, 120);
4397 ok(color_match(color, 0x00ff8000, 1) || color == 0x00000000,
4398 "quad 3 has color %08x, expected 0x00ff8000\n", color);
4399 color = getPixelColor(device, 480, 360);
4400 ok(color_match(color, 0x0033cc00, 1) || color_match(color, 0x00ff0000, 1),
4401 "quad 4 has color %08x, expected 0x0033cc00\n", color);
4402 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
4403 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
4405 IDirect3DTexture9_Release(texture);
4407 /* Test projected textures, without any fancy matrices */
4408 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_L8, D3DPOOL_MANAGED, &texture, NULL);
4409 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture returned %08x\n", hr);
4410 if (SUCCEEDED(hr))
4412 struct projected_textures_test_run projected_tests_1[4] =
4415 "D3DTTFF_COUNT4 | D3DTTFF_PROJECTED - bottom left",
4416 D3DTTFF_COUNT4 | D3DTTFF_PROJECTED,
4417 decl3,
4418 FALSE, TRUE,
4419 {120, 300, 240, 390},
4422 "D3DTTFF_COUNT3 | D3DTTFF_PROJECTED - bottom right",
4423 D3DTTFF_COUNT3 | D3DTTFF_PROJECTED,
4424 decl3,
4425 FALSE, TRUE,
4426 {400, 360, 480, 420},
4428 /* Try with some invalid values */
4430 "0xffffffff (draws like COUNT4 | PROJECTED) - top left",
4431 0xffffffff,
4432 decl3,
4433 FALSE, TRUE,
4434 {120, 60, 240, 150}
4437 "D3DTTFF_COUNT3 | D3DTTFF_PROJECTED (draws non-projected) - top right",
4438 D3DTTFF_COUNT3 | D3DTTFF_PROJECTED,
4439 decl4,
4440 FALSE, TRUE,
4441 {340, 210, 360, 225},
4444 struct projected_textures_test_run projected_tests_2[4] =
4447 "D3DTTFF_PROJECTED (like COUNT4 | PROJECTED, texcoord has 4 components) - bottom left",
4448 D3DTTFF_PROJECTED,
4449 decl3,
4450 FALSE, TRUE,
4451 {120, 300, 240, 390},
4454 "D3DTTFF_PROJECTED (like COUNT3 | PROJECTED, texcoord has only 3 components) - bottom right",
4455 D3DTTFF_PROJECTED,
4456 decl,
4457 FALSE, TRUE,
4458 {400, 360, 480, 420},
4461 "0xffffffff (like COUNT3 | PROJECTED, texcoord has only 3 components) - top left",
4462 0xffffffff,
4463 decl,
4464 FALSE, TRUE,
4465 {80, 120, 160, 180},
4468 "D3DTTFF_COUNT1 (draws non-projected) - top right",
4469 D3DTTFF_COUNT1,
4470 decl4,
4471 FALSE, TRUE,
4472 {340, 210, 360, 225},
4475 struct projected_textures_test_run projected_tests_3[4] =
4478 "D3DTTFF_COUNT3 | D3DTTFF_PROJECTED (like COUNT4 | PROJECTED) - bottom left",
4479 D3DTTFF_PROJECTED,
4480 decl3,
4481 TRUE, FALSE,
4482 {120, 300, 240, 390},
4485 "D3DTTFF_COUNT3 | D3DTTFF_PROJECTED (like COUNT4 | PROJECTED) - bottom right",
4486 D3DTTFF_COUNT3 | D3DTTFF_PROJECTED,
4487 decl3,
4488 TRUE, TRUE,
4489 {440, 300, 560, 390},
4492 "0xffffffff (like COUNT4 | PROJECTED) - top left",
4493 0xffffffff,
4494 decl3,
4495 TRUE, TRUE,
4496 {120, 60, 240, 150},
4499 "D3DTTFF_PROJECTED (like COUNT4 | PROJECTED) - top right",
4500 D3DTTFF_PROJECTED,
4501 decl3,
4502 FALSE, FALSE,
4503 {440, 60, 560, 150},
4507 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &identity);
4508 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
4510 hr = IDirect3DTexture9_LockRect(texture, 0, &lr, NULL, 0);
4511 ok(hr == D3D_OK, "IDirect3DTexture9_LockRect failed with %08x\n", hr);
4512 for(x = 0; x < 4; x++) {
4513 memcpy(((BYTE *) lr.pBits) + lr.Pitch * x, proj_texdata + 4 * x, 4 * sizeof(proj_texdata[0]));
4515 hr = IDirect3DTexture9_UnlockRect(texture, 0);
4516 ok(hr == D3D_OK, "IDirect3DTexture9_UnlockRect failed with %08x\n", hr);
4517 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) texture);
4518 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture failed with %08x\n", hr);
4520 projected_textures_test(device, projected_tests_1);
4521 projected_textures_test(device, projected_tests_2);
4522 projected_textures_test(device, projected_tests_3);
4524 hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
4525 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture failed with %08x\n", hr);
4526 IDirect3DTexture9_Release(texture);
4529 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff203040, 0.0, 0);
4530 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
4531 /* Use a smaller volume texture than the biggest possible size for memory and performance reasons
4532 * Thus watch out if sampling from texels between 0 and 1.
4534 hr = IDirect3DDevice9_CreateVolumeTexture(device, 32, 32, 32, 1, 0, fmt, D3DPOOL_MANAGED, &volume, 0);
4535 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL,
4536 "IDirect3DDevice9_CreateVolumeTexture failed with %08x\n", hr);
4537 if(!volume) {
4538 skip("Failed to create a volume texture\n");
4539 goto out;
4542 hr = IDirect3DVolumeTexture9_LockBox(volume, 0, &lb, NULL, 0);
4543 ok(hr == D3D_OK, "IDirect3DVolumeTexture9_LockBox failed with %08x\n", hr);
4544 for(z = 0; z < 32; z++) {
4545 for(y = 0; y < 32; y++) {
4546 for(x = 0; x < 32; x++) {
4547 char size = (fmt == D3DFMT_A16B16G16R16 ? 8 : 4);
4548 void *mem = ((char *) lb.pBits) + y * lb.RowPitch + z * lb.SlicePitch + x * size;
4549 float r_f = (float) x / 31.0;
4550 float g_f = (float) y / 31.0;
4551 float b_f = (float) z / 31.0;
4553 if(fmt == D3DFMT_A16B16G16R16) {
4554 unsigned short *mem_s = mem;
4555 mem_s[0] = r_f * 65535.0;
4556 mem_s[1] = g_f * 65535.0;
4557 mem_s[2] = b_f * 65535.0;
4558 mem_s[3] = 65535;
4559 } else {
4560 unsigned char *mem_c = mem;
4561 mem_c[0] = b_f * 255.0;
4562 mem_c[1] = g_f * 255.0;
4563 mem_c[2] = r_f * 255.0;
4564 mem_c[3] = 255;
4569 hr = IDirect3DVolumeTexture9_UnlockBox(volume, 0);
4570 ok(hr == D3D_OK, "IDirect3DVolumeTexture9_UnlockBox failed with %08x\n", hr);
4572 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) volume);
4573 ok(hr == D3D_OK, "IDirect3DVolumeTexture9_UnlockBox failed with %08x\n", hr);
4575 hr = IDirect3DDevice9_BeginScene(device);
4576 ok(hr == D3D_OK, "IDirect3DDevice9_BeginScene failed with %08x\n", hr);
4577 if(SUCCEEDED(hr))
4579 static const float quad1[] =
4581 -1.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f,
4582 -1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f,
4583 0.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f,
4584 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f,
4586 static const float quad2[] =
4588 -1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f,
4589 -1.0f, 1.0f, 0.1f, 1.0f, 1.0f, 1.0f,
4590 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f,
4591 0.0f, 1.0f, 0.1f, 1.0f, 1.0f, 1.0f,
4593 static const float quad3[] =
4595 0.0f, 0.0f, 0.1f, 0.0f, 0.0f,
4596 0.0f, 1.0f, 0.1f, 0.0f, 0.0f,
4597 1.0f, 0.0f, 0.1f, 0.0f, 0.0f,
4598 1.0f, 1.0f, 0.1f, 0.0f, 0.0f,
4600 static const float quad4[] =
4602 0.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f,
4603 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f,
4604 1.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f,
4605 1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f,
4607 D3DMATRIX mat =
4609 1.0f, 0.0f, 0.0f, 0.0f,
4610 0.0f, 0.0f, 1.0f, 0.0f,
4611 0.0f, 1.0f, 0.0f, 0.0f,
4612 0.0f, 0.0f, 0.0f, 1.0f,
4613 }}};
4614 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl);
4615 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexDeclaration failed with %08x\n", hr);
4617 /* Draw a quad with all 3 coords enabled. Nothing fancy. v and w are swapped, but have the same
4618 * values
4620 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &mat);
4621 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
4622 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3);
4623 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
4624 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, 6 * sizeof(float));
4625 ok(hr == D3D_OK, "DrawPrimitiveUP failed (%08x)\n", hr);
4627 /* Now disable the w coordinate. Does that change the input, or the output. The coordinates
4628 * are swapped by the matrix. If it changes the input, the v coord will be missing(green),
4629 * otherwise the w will be missing(blue).
4630 * turns out that on nvidia cards the blue color is missing, so it is an output modification.
4631 * On ATI cards the COUNT2 is ignored, and it behaves in the same way as COUNT3. */
4632 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
4633 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
4634 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 6 * sizeof(float));
4635 ok(hr == D3D_OK, "DrawPrimitiveUP failed (%08x)\n", hr);
4637 /* default values? Set up the identity matrix, pass in 2 vertex coords, and enable 3 */
4638 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &identity);
4639 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
4640 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3);
4641 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
4642 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
4643 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
4644 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, 5 * sizeof(float));
4645 ok(hr == D3D_OK, "DrawPrimitiveUP failed (%08x)\n", hr);
4647 /* D3DTTFF_COUNT1. Set a NULL matrix, and count1, pass in all values as 1.0. Nvidia has count1 ==
4648 * disable. ATI extends it up to the amount of values needed for the volume texture
4650 memset(&mat, 0, sizeof(mat));
4651 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &mat);
4652 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
4653 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT1);
4654 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
4655 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl);
4656 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexDeclaration failed with %08x\n", hr);
4657 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, 6 * sizeof(float));
4658 ok(hr == D3D_OK, "DrawPrimitiveUP failed (%08x)\n", hr);
4660 hr = IDirect3DDevice9_EndScene(device);
4661 ok(hr == D3D_OK, "IDirect3DDevice9_EndScene failed with %08x\n", hr);
4664 color = getPixelColor(device, 160, 360);
4665 ok(color == 0x00ffffff, "quad 1 has color %08x, expected 0x00ffffff\n", color);
4666 color = getPixelColor(device, 160, 120);
4667 ok(color == 0x00ffff00 /* NV*/ || color == 0x00ffffff /* ATI */,
4668 "quad 2 has color %08x, expected 0x00ffff00\n", color);
4669 color = getPixelColor(device, 480, 120);
4670 ok(color == 0x000000ff, "quad 3 has color %08x, expected 0x000000ff\n", color);
4671 color = getPixelColor(device, 480, 360);
4672 ok(color == 0x00ffffff || color == 0x0000ff00, "quad 4 has color %08x, expected 0x00ffffff\n", color);
4674 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
4675 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
4677 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff303030, 0.0, 0);
4678 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
4679 hr = IDirect3DDevice9_BeginScene(device);
4680 ok(hr == D3D_OK, "IDirect3DDevice9_BeginScene failed with %08x\n", hr);
4681 if(SUCCEEDED(hr))
4683 static const float quad1[] =
4685 -1.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f,
4686 -1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f,
4687 0.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f,
4688 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f,
4690 static const float quad2[] =
4692 -1.0f, 0.0f, 0.1f,
4693 -1.0f, 1.0f, 0.1f,
4694 0.0f, 0.0f, 0.1f,
4695 0.0f, 1.0f, 0.1f,
4697 static const float quad3[] =
4699 0.0f, 0.0f, 0.1f, 1.0f,
4700 0.0f, 1.0f, 0.1f, 1.0f,
4701 1.0f, 0.0f, 0.1f, 1.0f,
4702 1.0f, 1.0f, 0.1f, 1.0f,
4704 static const D3DMATRIX mat =
4706 0.0f, 0.0f, 0.0f, 0.0f,
4707 0.0f, 0.0f, 0.0f, 0.0f,
4708 0.0f, 0.0f, 0.0f, 0.0f,
4709 0.0f, 1.0f, 0.0f, 0.0f,
4710 }}};
4711 static const D3DMATRIX mat2 =
4713 0.0f, 0.0f, 0.0f, 1.0f,
4714 1.0f, 0.0f, 0.0f, 0.0f,
4715 0.0f, 1.0f, 0.0f, 0.0f,
4716 0.0f, 0.0f, 1.0f, 0.0f,
4717 }}};
4718 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl);
4719 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexDeclaration failed with %08x\n", hr);
4721 /* Default values? 4 coords used, 3 passed. What happens to the 4th?
4722 * Use COUNT3 because newer Nvidia drivers return black when there are more (output) coords
4723 * than being used by the texture(volume tex -> 3). Again, as shown in earlier test the COUNTx
4724 * affects the post-transformation output, so COUNT3 plus the matrix above is OK for testing the
4725 * 4th *input* coordinate.
4727 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &mat);
4728 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
4729 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3);
4730 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr);
4731 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, 6 * sizeof(float));
4732 ok(hr == D3D_OK, "DrawPrimitiveUP failed (%08x)\n", hr);
4734 /* None passed */
4735 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &identity);
4736 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
4737 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
4738 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
4739 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 3 * sizeof(float));
4740 ok(hr == D3D_OK, "DrawPrimitiveUP failed (%08x)\n", hr);
4742 /* 4 used, 1 passed */
4743 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl2);
4744 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexDeclaration failed with %08x\n", hr);
4745 hr = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &mat2);
4746 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed with %08x\n", hr);
4747 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, 4 * sizeof(float));
4748 ok(hr == D3D_OK, "DrawPrimitiveUP failed (%08x)\n", hr);
4750 hr = IDirect3DDevice9_EndScene(device);
4751 ok(hr == D3D_OK, "IDirect3DDevice9_EndScene failed with %08x\n", hr);
4753 color = getPixelColor(device, 160, 360);
4754 ok(color == 0x0000ff00, "quad 1 has color %08x, expected 0x0000ff00\n", color);
4755 color = getPixelColor(device, 160, 120);
4756 ok(color == 0x00000000, "quad 2 has color %08x, expected 0x00000000\n", color);
4757 color = getPixelColor(device, 480, 120);
4758 ok(color == 0x00ff0000, "quad 3 has color %08x, expected 0x00ff0000\n", color);
4759 /* Quad4: unused */
4761 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
4762 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
4764 IDirect3DVolumeTexture9_Release(volume);
4766 out:
4767 IDirect3DVertexDeclaration9_Release(decl);
4768 IDirect3DVertexDeclaration9_Release(decl2);
4769 IDirect3DVertexDeclaration9_Release(decl3);
4770 IDirect3DVertexDeclaration9_Release(decl4);
4771 refcount = IDirect3DDevice9_Release(device);
4772 ok(!refcount, "Device has %u references left.\n", refcount);
4773 done:
4774 IDirect3D9_Release(d3d);
4775 DestroyWindow(window);
4778 static void texdepth_test(void)
4780 IDirect3DPixelShader9 *shader;
4781 IDirect3DDevice9 *device;
4782 IDirect3D9 *d3d;
4783 ULONG refcount;
4784 D3DCAPS9 caps;
4785 DWORD color;
4786 HWND window;
4787 HRESULT hr;
4789 static const float texdepth_test_data1[] = { 0.25f, 2.0f, 0.0f, 0.0f};
4790 static const float texdepth_test_data2[] = { 0.25f, 0.5f, 0.0f, 0.0f};
4791 static const float texdepth_test_data3[] = {-1.00f, 0.1f, 0.0f, 0.0f};
4792 static const float texdepth_test_data4[] = {-0.25f, -0.5f, 0.0f, 0.0f};
4793 static const float texdepth_test_data5[] = { 1.00f, -0.1f, 0.0f, 0.0f};
4794 static const float texdepth_test_data6[] = { 1.00f, 0.5f, 0.0f, 0.0f};
4795 static const float texdepth_test_data7[] = { 0.50f, 0.0f, 0.0f, 0.0f};
4796 static const DWORD shader_code[] =
4798 0xffff0104, /* ps_1_4 */
4799 0x00000051, 0xa00f0001, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, /* def c1, 0, 0, 1, 1 */
4800 0x00000001, 0x800f0005, 0xa0e40000, /* mov r5, c0 */
4801 0x0000fffd, /* phase */
4802 0x00000057, 0x800f0005, /* texdepth r5 */
4803 0x00000001, 0x800f0000, 0xa0e40001, /* mov r0, c1 */
4804 0x0000ffff /* end */
4806 static const float vertex[] =
4808 -1.0f, -1.0f, 0.0f,
4809 -1.0f, 1.0f, 0.0f,
4810 1.0f, -1.0f, 1.0f,
4811 1.0f, 1.0f, 1.0f,
4814 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4815 0, 0, 640, 480, NULL, NULL, NULL, NULL);
4816 d3d = Direct3DCreate9(D3D_SDK_VERSION);
4817 ok(!!d3d, "Failed to create a D3D object.\n");
4818 if (!(device = create_device(d3d, window, window, TRUE)))
4820 skip("Failed to create a D3D device, skipping tests.\n");
4821 goto done;
4824 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
4825 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
4826 if (caps.PixelShaderVersion < D3DPS_VERSION(1, 1))
4828 skip("No ps_1_1 support, skipping tests.\n");
4829 IDirect3DDevice9_Release(device);
4830 goto done;
4833 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code, &shader);
4834 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
4836 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffff00, 0.0, 0);
4837 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
4838 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
4839 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
4840 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
4841 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
4842 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
4843 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
4844 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_ALWAYS);
4845 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
4846 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
4847 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetFVF returned %#x.\n", hr);
4849 /* Fill the depth buffer with a gradient */
4850 hr = IDirect3DDevice9_BeginScene(device);
4851 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4852 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, vertex, 3 * sizeof(float));
4853 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4854 hr = IDirect3DDevice9_EndScene(device);
4855 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4857 /* Now perform the actual tests. Same geometry, but with the shader */
4858 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_GREATER);
4859 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
4860 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
4861 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
4862 hr = IDirect3DDevice9_SetPixelShader(device, shader);
4863 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader failed (%08x)\n", hr);
4865 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 0, texdepth_test_data1, 1);
4866 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
4867 hr = IDirect3DDevice9_BeginScene(device);
4868 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4869 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, vertex, 3 * sizeof(float));
4870 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4871 hr = IDirect3DDevice9_EndScene(device);
4872 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4874 color = getPixelColor(device, 158, 240);
4875 ok(color == 0x000000ff, "Pixel 158(25%% - 2 pixel) has color %08x, expected 0x000000ff\n", color);
4876 color = getPixelColor(device, 162, 240);
4877 ok(color == 0x00ffffff, "Pixel 158(25%% + 2 pixel) has color %08x, expected 0x00ffffff\n", color);
4879 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
4880 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
4882 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 0.0, 0);
4883 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear returned %#x.\n", hr);
4885 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 0, texdepth_test_data2, 1);
4886 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
4887 hr = IDirect3DDevice9_BeginScene(device);
4888 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4889 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, vertex, 3 * sizeof(float));
4890 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4891 hr = IDirect3DDevice9_EndScene(device);
4892 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4894 color = getPixelColor(device, 318, 240);
4895 ok(color == 0x000000ff, "Pixel 318(50%% - 2 pixel) has color %08x, expected 0x000000ff\n", color);
4896 color = getPixelColor(device, 322, 240);
4897 ok(color == 0x00ffff00, "Pixel 322(50%% + 2 pixel) has color %08x, expected 0x00ffff00\n", color);
4899 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
4900 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
4902 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
4903 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear returned %#x.\n", hr);
4905 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 0, texdepth_test_data3, 1);
4906 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
4907 hr = IDirect3DDevice9_BeginScene(device);
4908 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4909 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, vertex, 3 * sizeof(float));
4910 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4911 hr = IDirect3DDevice9_EndScene(device);
4912 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4914 color = getPixelColor(device, 1, 240);
4915 ok(color == 0x00ff0000, "Pixel 1(0%% + 2 pixel) has color %08x, expected 0x00ff0000\n", color);
4917 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
4918 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
4920 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
4921 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear returned %#x.\n", hr);
4923 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 0, texdepth_test_data4, 1);
4924 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
4925 hr = IDirect3DDevice9_BeginScene(device);
4926 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4927 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, vertex, 3 * sizeof(float));
4928 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4929 hr = IDirect3DDevice9_EndScene(device);
4930 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4932 color = getPixelColor(device, 318, 240);
4933 ok(color == 0x000000ff, "Pixel 318(50%% - 2 pixel) has color %08x, expected 0x000000ff\n", color);
4934 color = getPixelColor(device, 322, 240);
4935 ok(color == 0x0000ff00, "Pixel 322(50%% + 2 pixel) has color %08x, expected 0x0000ff00\n", color);
4937 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
4938 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
4940 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 0.0, 0);
4941 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear returned %#x.\n", hr);
4943 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 0, texdepth_test_data5, 1);
4944 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
4945 hr = IDirect3DDevice9_BeginScene(device);
4946 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4947 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, vertex, 3 * sizeof(float));
4948 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4949 hr = IDirect3DDevice9_EndScene(device);
4950 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4952 color = getPixelColor(device, 1, 240);
4953 ok(color == 0x00ffff00, "Pixel 1(0%% + 2 pixel) has color %08x, expected 0x00ffff00\n", color);
4955 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
4956 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
4958 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
4959 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear returned %#x.\n", hr);
4961 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 0, texdepth_test_data6, 1);
4962 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
4963 hr = IDirect3DDevice9_BeginScene(device);
4964 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4965 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, vertex, 3 * sizeof(float));
4966 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4967 hr = IDirect3DDevice9_EndScene(device);
4968 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4970 color = getPixelColor(device, 638, 240);
4971 ok(color == 0x000000ff, "Pixel 638(100%% + 2 pixel) has color %08x, expected 0x000000ff\n", color);
4973 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
4974 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
4976 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
4977 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear returned %#x.\n", hr);
4979 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 0, texdepth_test_data7, 1);
4980 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
4981 hr = IDirect3DDevice9_BeginScene(device);
4982 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4983 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, vertex, 3 * sizeof(float));
4984 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4985 hr = IDirect3DDevice9_EndScene(device);
4986 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4988 color = getPixelColor(device, 638, 240);
4989 ok(color == 0x000000ff, "Pixel 638(100%% + 2 pixel) has color %08x, expected 0x000000ff\n", color);
4991 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
4992 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
4994 IDirect3DPixelShader9_Release(shader);
4995 refcount = IDirect3DDevice9_Release(device);
4996 ok(!refcount, "Device has %u references left.\n", refcount);
4997 done:
4998 IDirect3D9_Release(d3d);
4999 DestroyWindow(window);
5002 static void texkill_test(void)
5004 IDirect3DPixelShader9 *shader;
5005 IDirect3DDevice9 *device;
5006 IDirect3D9 *d3d;
5007 ULONG refcount;
5008 D3DCAPS9 caps;
5009 DWORD color;
5010 HWND window;
5011 HRESULT hr;
5013 static const float vertex[] =
5015 /* bottom top right left */
5016 -1.0f, -1.0f, 1.0f, -0.1f, 0.9f, 0.9f, -0.1f,
5017 -1.0f, 1.0f, 1.0f, -0.1f, 0.9f, -0.1f, 0.9f,
5018 1.0f, -1.0f, 0.0f, 0.9f, -0.1f, 0.9f, -0.1f,
5019 1.0f, 1.0f, 0.0f, 0.9f, -0.1f, -0.1f, 0.9f,
5021 static const DWORD shader_code_11[] =
5023 0xffff0101, /* ps_1_1 */
5024 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 1.0, 0.0, 0.0, 1.0 */
5025 0x00000041, 0xb00f0000, /* texkill t0 */
5026 0x00000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
5027 0x0000ffff /* end */
5029 static const DWORD shader_code_20[] =
5031 0xffff0200, /* ps_2_0 */
5032 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
5033 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, /* def c0, 0.0, 0.0, 1.0, 1.0 */
5034 0x01000041, 0xb00f0000, /* texkill t0 */
5035 0x02000001, 0x800f0800, 0xa0e40000, /* mov oC0, c0 */
5036 0x0000ffff /* end */
5039 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5040 0, 0, 640, 480, NULL, NULL, NULL, NULL);
5041 d3d = Direct3DCreate9(D3D_SDK_VERSION);
5042 ok(!!d3d, "Failed to create a D3D object.\n");
5043 if (!(device = create_device(d3d, window, window, TRUE)))
5045 skip("Failed to create a D3D device, skipping tests.\n");
5046 goto done;
5049 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
5050 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
5051 if (caps.PixelShaderVersion < D3DPS_VERSION(1, 1))
5053 skip("No ps_1_1 support, skipping tests.\n");
5054 IDirect3DDevice9_Release(device);
5055 goto done;
5058 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 1.0f, 0);
5059 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
5060 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_11, &shader);
5061 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
5063 hr = IDirect3DDevice9_SetPixelShader(device, shader);
5064 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader returned %08x\n", hr);
5065 hr = IDirect3DDevice9_BeginScene(device);
5066 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5067 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEXCOORDSIZE4(0) | D3DFVF_TEX1);
5068 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
5069 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, vertex, 7 * sizeof(float));
5070 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5071 hr = IDirect3DDevice9_EndScene(device);
5072 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5074 color = getPixelColor(device, 63, 46);
5075 ok(color == 0x0000ff00, "Pixel 63/46 has color %08x, expected 0x0000ff00\n", color);
5076 color = getPixelColor(device, 66, 46);
5077 ok(color == 0x0000ff00, "Pixel 66/64 has color %08x, expected 0x0000ff00\n", color);
5078 color = getPixelColor(device, 63, 49);
5079 ok(color == 0x0000ff00, "Pixel 63/49 has color %08x, expected 0x0000ff00\n", color);
5080 color = getPixelColor(device, 66, 49);
5081 ok(color == 0x00ff0000, "Pixel 66/49 has color %08x, expected 0x00ff0000\n", color);
5083 color = getPixelColor(device, 578, 46);
5084 ok(color == 0x0000ff00, "Pixel 578/46 has color %08x, expected 0x0000ff00\n", color);
5085 color = getPixelColor(device, 575, 46);
5086 ok(color == 0x0000ff00, "Pixel 575/64 has color %08x, expected 0x0000ff00\n", color);
5087 color = getPixelColor(device, 578, 49);
5088 ok(color == 0x0000ff00, "Pixel 578/49 has color %08x, expected 0x0000ff00\n", color);
5089 color = getPixelColor(device, 575, 49);
5090 ok(color == 0x00ff0000, "Pixel 575/49 has color %08x, expected 0x00ff0000\n", color);
5092 color = getPixelColor(device, 63, 430);
5093 ok(color == 0x0000ff00, "Pixel 578/46 has color %08x, expected 0x0000ff00\n", color);
5094 color = getPixelColor(device, 63, 433);
5095 ok(color == 0x0000ff00, "Pixel 575/64 has color %08x, expected 0x0000ff00\n", color);
5096 color = getPixelColor(device, 66, 433);
5097 ok(color == 0x00ff0000, "Pixel 578/49 has color %08x, expected 0x00ff0000\n", color);
5098 color = getPixelColor(device, 66, 430);
5099 ok(color == 0x00ff0000, "Pixel 575/49 has color %08x, expected 0x00ff0000\n", color);
5101 color = getPixelColor(device, 578, 430);
5102 ok(color == 0x0000ff00, "Pixel 578/46 has color %08x, expected 0x0000ff00\n", color);
5103 color = getPixelColor(device, 578, 433);
5104 ok(color == 0x0000ff00, "Pixel 575/64 has color %08x, expected 0x0000ff00\n", color);
5105 color = getPixelColor(device, 575, 433);
5106 ok(color == 0x00ff0000, "Pixel 578/49 has color %08x, expected 0x00ff0000\n", color);
5107 color = getPixelColor(device, 575, 430);
5108 ok(color == 0x00ff0000, "Pixel 575/49 has color %08x, expected 0x00ff0000\n", color);
5110 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
5111 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
5113 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
5114 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader returned %08x\n", hr);
5115 IDirect3DPixelShader9_Release(shader);
5117 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 0.0, 0);
5118 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
5119 if (FAILED(IDirect3DDevice9_CreatePixelShader(device, shader_code_20, &shader)))
5121 skip("Failed to create 2.0 test shader, most likely not supported.\n");
5122 IDirect3DDevice9_Release(device);
5123 goto done;
5126 hr = IDirect3DDevice9_SetPixelShader(device, shader);
5127 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader returned %08x\n", hr);
5128 hr = IDirect3DDevice9_BeginScene(device);
5129 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5130 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, vertex, 7 * sizeof(float));
5131 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5132 hr = IDirect3DDevice9_EndScene(device);
5133 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5135 color = getPixelColor(device, 63, 46);
5136 ok(color == 0x00ffff00, "Pixel 63/46 has color %08x, expected 0x00ffff00\n", color);
5137 color = getPixelColor(device, 66, 46);
5138 ok(color == 0x00ffff00, "Pixel 66/64 has color %08x, expected 0x00ffff00\n", color);
5139 color = getPixelColor(device, 63, 49);
5140 ok(color == 0x00ffff00, "Pixel 63/49 has color %08x, expected 0x00ffff00\n", color);
5141 color = getPixelColor(device, 66, 49);
5142 ok(color == 0x000000ff, "Pixel 66/49 has color %08x, expected 0x000000ff\n", color);
5144 color = getPixelColor(device, 578, 46);
5145 ok(color == 0x00ffff00, "Pixel 578/46 has color %08x, expected 0x00ffff00\n", color);
5146 color = getPixelColor(device, 575, 46);
5147 ok(color == 0x00ffff00, "Pixel 575/64 has color %08x, expected 0x00ffff00\n", color);
5148 color = getPixelColor(device, 578, 49);
5149 ok(color == 0x00ffff00, "Pixel 578/49 has color %08x, expected 0x00ffff00\n", color);
5150 color = getPixelColor(device, 575, 49);
5151 ok(color == 0x000000ff, "Pixel 575/49 has color %08x, expected 0x000000ff\n", color);
5153 color = getPixelColor(device, 63, 430);
5154 ok(color == 0x00ffff00, "Pixel 578/46 has color %08x, expected 0x00ffff00\n", color);
5155 color = getPixelColor(device, 63, 433);
5156 ok(color == 0x00ffff00, "Pixel 575/64 has color %08x, expected 0x00ffff00\n", color);
5157 color = getPixelColor(device, 66, 433);
5158 ok(color == 0x00ffff00, "Pixel 578/49 has color %08x, expected 0x00ffff00\n", color);
5159 color = getPixelColor(device, 66, 430);
5160 ok(color == 0x000000ff, "Pixel 575/49 has color %08x, expected 0x000000ff\n", color);
5162 color = getPixelColor(device, 578, 430);
5163 ok(color == 0x00ffff00, "Pixel 578/46 has color %08x, expected 0x00ffff00\n", color);
5164 color = getPixelColor(device, 578, 433);
5165 ok(color == 0x00ffff00, "Pixel 575/64 has color %08x, expected 0x00ffff00\n", color);
5166 color = getPixelColor(device, 575, 433);
5167 ok(color == 0x00ffff00, "Pixel 578/49 has color %08x, expected 0x00ffff00\n", color);
5168 color = getPixelColor(device, 575, 430);
5169 ok(color == 0x000000ff, "Pixel 575/49 has color %08x, expected 0x000000ff\n", color);
5171 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
5172 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
5174 IDirect3DPixelShader9_Release(shader);
5175 refcount = IDirect3DDevice9_Release(device);
5176 ok(!refcount, "Device has %u references left.\n", refcount);
5177 done:
5178 IDirect3D9_Release(d3d);
5179 DestroyWindow(window);
5182 static void x8l8v8u8_test(void)
5184 IDirect3DPixelShader9 *shader2;
5185 IDirect3DPixelShader9 *shader;
5186 IDirect3DTexture9 *texture;
5187 IDirect3DDevice9 *device;
5188 D3DLOCKED_RECT lr;
5189 IDirect3D9 *d3d;
5190 ULONG refcount;
5191 D3DCAPS9 caps;
5192 DWORD color;
5193 HWND window;
5194 HRESULT hr;
5196 static const DWORD shader_code[] =
5198 0xffff0101, /* ps_1_1 */
5199 0x00000042, 0xb00f0000, /* tex t0 */
5200 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
5201 0x0000ffff /* end */
5203 static const DWORD shader_code2[] =
5205 0xffff0101, /* ps_1_1 */
5206 0x00000042, 0xb00f0000, /* tex t0 */
5207 0x00000001, 0x800f0000, 0xb0ff0000, /* mov r0, t0.w */
5208 0x0000ffff /* end */
5210 static const float quad[] =
5212 -1.0f, -1.0f, 0.1f, 0.5f, 0.5f,
5213 -1.0f, 1.0f, 0.1f, 0.5f, 0.5f,
5214 1.0f, -1.0f, 0.1f, 0.5f, 0.5f,
5215 1.0f, 1.0f, 0.1f, 0.5f, 0.5f,
5218 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5219 0, 0, 640, 480, NULL, NULL, NULL, NULL);
5220 d3d = Direct3DCreate9(D3D_SDK_VERSION);
5221 ok(!!d3d, "Failed to create a D3D object.\n");
5222 if (!(device = create_device(d3d, window, window, TRUE)))
5224 skip("Failed to create a D3D device, skipping tests.\n");
5225 goto done;
5228 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
5229 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
5230 if (caps.PixelShaderVersion < D3DPS_VERSION(1, 1))
5232 skip("No ps_1_1 support, skipping tests.\n");
5233 IDirect3DDevice9_Release(device);
5234 goto done;
5236 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL,
5237 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, D3DFMT_X8L8V8U8)))
5239 skip("No D3DFMT_X8L8V8U8 support, skipping tests.\n");
5240 IDirect3DDevice9_Release(device);
5241 goto done;
5244 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 1.0f, 0);
5245 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
5247 hr = IDirect3DDevice9_CreateTexture(device, 1, 1, 1, 0, D3DFMT_X8L8V8U8, D3DPOOL_MANAGED, &texture, NULL);
5248 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture failed (%08x)\n", hr);
5249 memset(&lr, 0, sizeof(lr));
5250 hr = IDirect3DTexture9_LockRect(texture, 0, &lr, NULL, 0);
5251 ok(hr == D3D_OK, "IDirect3DTexture9_LockRect failed (%08x)\n", hr);
5252 *((DWORD *) lr.pBits) = 0x11ca3141;
5253 hr = IDirect3DTexture9_UnlockRect(texture, 0);
5254 ok(hr == D3D_OK, "IDirect3DTexture9_UnlockRect failed (%08x)\n", hr);
5256 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code, &shader);
5257 ok(hr == D3D_OK, "IDirect3DDevice9_CreateShader failed (%08x)\n", hr);
5258 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code2, &shader2);
5259 ok(hr == D3D_OK, "IDirect3DDevice9_CreateShader failed (%08x)\n", hr);
5261 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
5262 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed (%08x)\n", hr);
5263 hr = IDirect3DDevice9_SetPixelShader(device, shader);
5264 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader failed (%08x)\n", hr);
5265 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) texture);
5266 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture failed (%08x)\n", hr);
5268 hr = IDirect3DDevice9_BeginScene(device);
5269 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5270 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
5271 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5272 hr = IDirect3DDevice9_EndScene(device);
5273 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5275 color = getPixelColor(device, 578, 430);
5276 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x82, 0x62, 0xca), 1),
5277 "D3DFMT_X8L8V8U8 = 0x112131ca returns color %08x, expected 0x008262ca\n", color);
5278 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
5279 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
5281 hr = IDirect3DDevice9_SetPixelShader(device, shader2);
5282 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader failed (%08x)\n", hr);
5283 hr = IDirect3DDevice9_BeginScene(device);
5284 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5285 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
5286 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5287 hr = IDirect3DDevice9_EndScene(device);
5288 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5290 color = getPixelColor(device, 578, 430);
5291 ok(color == 0x00ffffff, "w component of D3DFMT_X8L8V8U8 = 0x11ca3141 returns color %08x\n", color);
5292 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
5293 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
5295 IDirect3DPixelShader9_Release(shader);
5296 IDirect3DPixelShader9_Release(shader2);
5297 IDirect3DTexture9_Release(texture);
5298 refcount = IDirect3DDevice9_Release(device);
5299 ok(!refcount, "Device has %u references left.\n", refcount);
5300 done:
5301 IDirect3D9_Release(d3d);
5302 DestroyWindow(window);
5305 static void autogen_mipmap_test(void)
5307 IDirect3DTexture9 *texture = NULL;
5308 IDirect3DSurface9 *surface;
5309 IDirect3DDevice9 *device;
5310 unsigned int x, y;
5311 D3DLOCKED_RECT lr;
5312 IDirect3D9 *d3d;
5313 D3DCOLOR color;
5314 ULONG refcount;
5315 HWND window;
5316 HRESULT hr;
5318 static const RECT r1 = {256, 256, 512, 512};
5319 static const RECT r2 = {512, 256, 768, 512};
5320 static const RECT r3 = {256, 512, 512, 768};
5321 static const RECT r4 = {512, 512, 768, 768};
5322 static const float quad[] =
5324 -0.5f, -0.5f, 0.1f, 0.0f, 0.0f,
5325 -0.5f, 0.5f, 0.1f, 0.0f, 1.0f,
5326 0.5f, -0.5f, 0.1f, 1.0f, 0.0f,
5327 0.5f, 0.5f, 0.1f, 1.0f, 1.0f,
5330 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5331 0, 0, 640, 480, NULL, NULL, NULL, NULL);
5332 d3d = Direct3DCreate9(D3D_SDK_VERSION);
5333 ok(!!d3d, "Failed to create a D3D object.\n");
5334 if (!(device = create_device(d3d, window, window, TRUE)))
5336 skip("Failed to create a D3D device, skipping tests.\n");
5337 goto done;
5340 if (IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL,
5341 D3DFMT_X8R8G8B8, D3DUSAGE_AUTOGENMIPMAP, D3DRTYPE_TEXTURE, D3DFMT_X8R8G8B8) != D3D_OK)
5343 skip("No autogenmipmap support.\n");
5344 IDirect3DDevice9_Release(device);
5345 goto done;
5348 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffff00, 1.0f, 0);
5349 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
5351 /* Make the mipmap big, so that a smaller mipmap is used
5353 hr = IDirect3DDevice9_CreateTexture(device, 1024, 1024, 0, D3DUSAGE_AUTOGENMIPMAP,
5354 D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &texture, 0);
5355 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture returned %08x\n", hr);
5357 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
5358 ok(hr == D3D_OK, "IDirect3DTexture9_GetSurfaceLevel returned %08x\n", hr);
5359 memset(&lr, 0, sizeof(lr));
5360 hr = IDirect3DSurface9_LockRect(surface, &lr, NULL, 0);
5361 ok(hr == D3D_OK, "IDirect3DSurface9_LockRect returned %08x\n", hr);
5362 for(y = 0; y < 1024; y++) {
5363 for(x = 0; x < 1024; x++) {
5364 DWORD *dst = (DWORD *) (((BYTE *) lr.pBits) + y * lr.Pitch + x * 4);
5365 POINT pt;
5367 pt.x = x;
5368 pt.y = y;
5369 if(PtInRect(&r1, pt)) {
5370 *dst = 0xffff0000;
5371 } else if(PtInRect(&r2, pt)) {
5372 *dst = 0xff00ff00;
5373 } else if(PtInRect(&r3, pt)) {
5374 *dst = 0xff0000ff;
5375 } else if(PtInRect(&r4, pt)) {
5376 *dst = 0xff000000;
5377 } else {
5378 *dst = 0xffffffff;
5382 hr = IDirect3DSurface9_UnlockRect(surface);
5383 ok(hr == D3D_OK, "IDirect3DSurface9_UnlockRect returned %08x\n", hr);
5384 IDirect3DSurface9_Release(surface);
5386 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) texture);
5387 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture returned %08x\n", hr);
5388 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
5389 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState failed with %08x\n", hr);
5390 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
5391 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
5393 hr = IDirect3DDevice9_BeginScene(device);
5394 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5395 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
5396 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
5397 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
5398 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5399 hr = IDirect3DDevice9_EndScene(device);
5400 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5401 IDirect3DTexture9_Release(texture);
5403 color = getPixelColor(device, 200, 200);
5404 ok(color == 0x00ffffff, "pixel 200/200 has color %08x, expected 0x00ffffff\n", color);
5405 color = getPixelColor(device, 280, 200);
5406 ok(color == 0x000000ff, "pixel 280/200 has color %08x, expected 0x000000ff\n", color);
5407 color = getPixelColor(device, 360, 200);
5408 ok(color == 0x00000000, "pixel 360/200 has color %08x, expected 0x00000000\n", color);
5409 color = getPixelColor(device, 440, 200);
5410 ok(color == 0x00ffffff, "pixel 440/200 has color %08x, expected 0x00ffffff\n", color);
5411 color = getPixelColor(device, 200, 270);
5412 ok(color == 0x00ffffff, "pixel 200/270 has color %08x, expected 0x00ffffff\n", color);
5413 color = getPixelColor(device, 280, 270);
5414 ok(color == 0x00ff0000, "pixel 280/270 has color %08x, expected 0x00ff0000\n", color);
5415 color = getPixelColor(device, 360, 270);
5416 ok(color == 0x0000ff00, "pixel 360/270 has color %08x, expected 0x0000ff00\n", color);
5417 color = getPixelColor(device, 440, 270);
5418 ok(color == 0x00ffffff, "pixel 440/200 has color %08x, expected 0x00ffffff\n", color);
5419 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
5420 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
5422 refcount = IDirect3DDevice9_Release(device);
5423 ok(!refcount, "Device has %u references left.\n", refcount);
5424 done:
5425 IDirect3D9_Release(d3d);
5426 DestroyWindow(window);
5429 static void test_constant_clamp_vs(void)
5431 IDirect3DVertexShader9 *shader_11, *shader_11_2, *shader_20, *shader_20_2;
5432 IDirect3DVertexDeclaration9 *decl;
5433 IDirect3DDevice9 *device;
5434 IDirect3D9 *d3d;
5435 D3DCOLOR color;
5436 ULONG refcount;
5437 D3DCAPS9 caps;
5438 HWND window;
5439 HRESULT hr;
5441 static const DWORD shader_code_11[] =
5443 0xfffe0101, /* vs_1_1 */
5444 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
5445 0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
5446 0x00000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
5447 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
5448 0x0000ffff /* end */
5450 static const DWORD shader_code_11_2[] =
5452 0xfffe0101, /* vs_1_1 */
5453 0x00000051, 0xa00f0001, 0x3fa00000, 0xbf000000, 0xbfc00000, 0x3f800000, /* dcl ... */
5454 0x00000051, 0xa00f0002, 0xbf000000, 0x3fa00000, 0x40000000, 0x3f800000, /* dcl ... */
5455 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
5456 0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
5457 0x00000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
5458 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
5459 0x0000ffff /* end */
5461 static const DWORD shader_code_20[] =
5463 0xfffe0200, /* vs_2_0 */
5464 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
5465 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
5466 0x03000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
5467 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
5468 0x0000ffff /* end */
5470 static const DWORD shader_code_20_2[] =
5472 0xfffe0200, /* vs_2_0 */
5473 0x05000051, 0xa00f0001, 0x3fa00000, 0xbf000000, 0xbfc00000, 0x3f800000,
5474 0x05000051, 0xa00f0002, 0xbf000000, 0x3fa00000, 0x40000000, 0x3f800000,
5475 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
5476 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
5477 0x03000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
5478 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
5479 0x0000ffff /* end */
5481 static const D3DVERTEXELEMENT9 decl_elements[] =
5483 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
5484 D3DDECL_END()
5486 static const float quad1[] =
5488 -1.0f, -1.0f, 0.1f,
5489 -1.0f, 0.0f, 0.1f,
5490 0.0f, -1.0f, 0.1f,
5491 0.0f, 0.0f, 0.1f,
5493 static const float quad2[] =
5495 0.0f, -1.0f, 0.1f,
5496 0.0f, 0.0f, 0.1f,
5497 1.0f, -1.0f, 0.1f,
5498 1.0f, 0.0f, 0.1f,
5500 static const float quad3[] =
5502 0.0f, 0.0f, 0.1f,
5503 0.0f, 1.0f, 0.1f,
5504 1.0f, 0.0f, 0.1f,
5505 1.0f, 1.0f, 0.1f,
5507 static const float quad4[] =
5509 -1.0f, 0.0f, 0.1f,
5510 -1.0f, 1.0f, 0.1f,
5511 0.0f, 0.0f, 0.1f,
5512 0.0f, 1.0f, 0.1f,
5514 static const float test_data_c1[4] = { 1.25f, -0.50f, -1.50f, 1.0f};
5515 static const float test_data_c2[4] = {-0.50f, 1.25f, 2.00f, 1.0f};
5517 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5518 0, 0, 640, 480, NULL, NULL, NULL, NULL);
5519 d3d = Direct3DCreate9(D3D_SDK_VERSION);
5520 ok(!!d3d, "Failed to create a D3D object.\n");
5521 if (!(device = create_device(d3d, window, window, TRUE)))
5523 skip("Failed to create a D3D device, skipping tests.\n");
5524 goto done;
5527 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
5528 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
5529 if (caps.VertexShaderVersion < D3DVS_VERSION(1, 1))
5531 skip("No vs_1_1 support, skipping tests.\n");
5532 IDirect3DDevice9_Release(device);
5533 goto done;
5536 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ffff, 1.0f, 0);
5537 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
5539 hr = IDirect3DDevice9_CreateVertexShader(device, shader_code_11, &shader_11);
5540 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
5541 hr = IDirect3DDevice9_CreateVertexShader(device, shader_code_11_2, &shader_11_2);
5542 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
5543 hr = IDirect3DDevice9_CreateVertexShader(device, shader_code_20, &shader_20);
5544 if(FAILED(hr)) shader_20 = NULL;
5545 hr = IDirect3DDevice9_CreateVertexShader(device, shader_code_20_2, &shader_20_2);
5546 if(FAILED(hr)) shader_20_2 = NULL;
5547 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &decl);
5548 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
5550 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 1, test_data_c1, 1);
5551 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShaderConstantF returned %08x\n", hr);
5552 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 2, test_data_c2, 1);
5553 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShaderConstantF returned %08x\n", hr);
5554 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl);
5555 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexDeclaration returned %08x\n", hr);
5557 hr = IDirect3DDevice9_BeginScene(device);
5558 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5560 hr = IDirect3DDevice9_SetVertexShader(device, shader_11);
5561 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
5562 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, 3 * sizeof(float));
5563 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5565 hr = IDirect3DDevice9_SetVertexShader(device, shader_11_2);
5566 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
5567 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 3 * sizeof(float));
5568 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5570 if (shader_20)
5572 hr = IDirect3DDevice9_SetVertexShader(device, shader_20);
5573 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
5574 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, 3 * sizeof(float));
5575 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5578 if (shader_20_2)
5580 hr = IDirect3DDevice9_SetVertexShader(device, shader_20_2);
5581 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
5582 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, 3 * sizeof(float));
5583 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5586 hr = IDirect3DDevice9_EndScene(device);
5587 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5589 color = getPixelColor(device, 160, 360);
5590 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xbf, 0xbf, 0x80), 1),
5591 "quad 1 has color %08x, expected 0x00bfbf80\n", color);
5592 color = getPixelColor(device, 480, 360);
5593 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xbf, 0xbf, 0x80), 1),
5594 "quad 2 has color %08x, expected 0x00bfbf80\n", color);
5595 if(shader_20) {
5596 color = getPixelColor(device, 480, 120);
5597 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xbf, 0xbf, 0x80), 1),
5598 "quad 3 has color %08x, expected 0x00bfbf80\n", color);
5600 if(shader_20_2) {
5601 color = getPixelColor(device, 160, 120);
5602 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xbf, 0xbf, 0x80), 1),
5603 "quad 4 has color %08x, expected 0x00bfbf80\n", color);
5605 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
5606 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
5608 IDirect3DVertexDeclaration9_Release(decl);
5609 if(shader_20_2) IDirect3DVertexShader9_Release(shader_20_2);
5610 if(shader_20) IDirect3DVertexShader9_Release(shader_20);
5611 IDirect3DVertexShader9_Release(shader_11_2);
5612 IDirect3DVertexShader9_Release(shader_11);
5613 refcount = IDirect3DDevice9_Release(device);
5614 ok(!refcount, "Device has %u references left.\n", refcount);
5615 done:
5616 IDirect3D9_Release(d3d);
5617 DestroyWindow(window);
5620 static void constant_clamp_ps_test(void)
5622 IDirect3DPixelShader9 *shader_11, *shader_12, *shader_14, *shader_20;
5623 IDirect3DDevice9 *device;
5624 IDirect3D9 *d3d;
5625 ULONG refcount;
5626 D3DCAPS9 caps;
5627 DWORD color;
5628 HWND window;
5629 HRESULT hr;
5631 static const DWORD shader_code_11[] =
5633 0xffff0101, /* ps_1_1 */
5634 0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
5635 0x00000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
5636 0x0000ffff /* end */
5638 static const DWORD shader_code_12[] =
5640 0xffff0102, /* ps_1_2 */
5641 0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
5642 0x00000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
5643 0x0000ffff /* end */
5645 /* Skip 1.3 shaders because we have only 4 quads (ok, could make them
5646 * smaller if needed). 1.2 and 1.4 shaders behave the same, so it's
5647 * unlikely that 1.3 shaders are different. During development of this
5648 * test, 1.3 shaders were verified too. */
5649 static const DWORD shader_code_14[] =
5651 0xffff0104, /* ps_1_4 */
5652 /* Try to make one constant local. It gets clamped too, although the
5653 * binary contains the bigger numbers. */
5654 0x00000051, 0xa00f0002, 0xbf000000, 0x3fa00000, 0x40000000, 0x3f800000, /* def c2, -0.5, 1.25, 2, 1 */
5655 0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
5656 0x00000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
5657 0x0000ffff /* end */
5659 static const DWORD shader_code_20[] =
5661 0xffff0200, /* ps_2_0 */
5662 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
5663 0x03000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
5664 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
5665 0x0000ffff /* end */
5667 static const float quad1[] =
5669 -1.0f, -1.0f, 0.1f,
5670 -1.0f, 0.0f, 0.1f,
5671 0.0f, -1.0f, 0.1f,
5672 0.0f, 0.0f, 0.1f,
5674 static const float quad2[] =
5676 0.0f, -1.0f, 0.1f,
5677 0.0f, 0.0f, 0.1f,
5678 1.0f, -1.0f, 0.1f,
5679 1.0f, 0.0f, 0.1f,
5681 static const float quad3[] =
5683 0.0f, 0.0f, 0.1f,
5684 0.0f, 1.0f, 0.1f,
5685 1.0f, 0.0f, 0.1f,
5686 1.0f, 1.0f, 0.1f,
5688 static const float quad4[] =
5690 -1.0f, 0.0f, 0.1f,
5691 -1.0f, 1.0f, 0.1f,
5692 0.0f, 0.0f, 0.1f,
5693 0.0f, 1.0f, 0.1f,
5695 static const float test_data_c1[4] = { 1.25f, -0.50f, -1.50f, 1.0f};
5696 static const float test_data_c2[4] = {-0.50f, 1.25f, 2.00f, 1.0f};
5698 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5699 0, 0, 640, 480, NULL, NULL, NULL, NULL);
5700 d3d = Direct3DCreate9(D3D_SDK_VERSION);
5701 ok(!!d3d, "Failed to create a D3D object.\n");
5702 if (!(device = create_device(d3d, window, window, TRUE)))
5704 skip("Failed to create a D3D device, skipping tests.\n");
5705 goto done;
5708 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
5709 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
5710 if (caps.PixelShaderVersion < D3DPS_VERSION(1, 4))
5712 skip("No ps_1_4 support, skipping tests.\n");
5713 IDirect3DDevice9_Release(device);
5714 goto done;
5717 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ffff, 1.0f, 0);
5718 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
5720 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_11, &shader_11);
5721 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
5722 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_12, &shader_12);
5723 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
5724 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_14, &shader_14);
5725 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
5726 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_20, &shader_20);
5727 if(FAILED(hr)) shader_20 = NULL;
5729 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 1, test_data_c1, 1);
5730 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
5731 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 2, test_data_c2, 1);
5732 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
5733 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
5734 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF returned %08x\n", hr);
5736 hr = IDirect3DDevice9_BeginScene(device);
5737 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5739 hr = IDirect3DDevice9_SetPixelShader(device, shader_11);
5740 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
5741 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, 3 * sizeof(float));
5742 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5744 hr = IDirect3DDevice9_SetPixelShader(device, shader_12);
5745 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
5746 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 3 * sizeof(float));
5747 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5749 hr = IDirect3DDevice9_SetPixelShader(device, shader_14);
5750 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
5751 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, 3 * sizeof(float));
5752 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5754 if (shader_20)
5756 hr = IDirect3DDevice9_SetPixelShader(device, shader_20);
5757 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
5758 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, 3 * sizeof(float));
5759 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5762 hr = IDirect3DDevice9_EndScene(device);
5763 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5765 color = getPixelColor(device, 160, 360);
5766 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x80, 0x80, 0x00), 1),
5767 "quad 1 has color %08x, expected 0x00808000\n", color);
5768 color = getPixelColor(device, 480, 360);
5769 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x80, 0x80, 0x00), 1),
5770 "quad 2 has color %08x, expected 0x00808000\n", color);
5771 color = getPixelColor(device, 480, 120);
5772 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x80, 0x80, 0x00), 1),
5773 "quad 3 has color %08x, expected 0x00808000\n", color);
5774 if(shader_20) {
5775 color = getPixelColor(device, 160, 120);
5776 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xbf, 0xbf, 0x80), 1),
5777 "quad 4 has color %08x, expected 0x00bfbf80\n", color);
5779 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
5780 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
5782 if(shader_20) IDirect3DPixelShader9_Release(shader_20);
5783 IDirect3DPixelShader9_Release(shader_14);
5784 IDirect3DPixelShader9_Release(shader_12);
5785 IDirect3DPixelShader9_Release(shader_11);
5786 refcount = IDirect3DDevice9_Release(device);
5787 ok(!refcount, "Device has %u references left.\n", refcount);
5788 done:
5789 IDirect3D9_Release(d3d);
5790 DestroyWindow(window);
5793 static void dp2add_ps_test(void)
5795 IDirect3DPixelShader9 *shader_dp2add_sat;
5796 IDirect3DPixelShader9 *shader_dp2add;
5797 IDirect3DDevice9 *device;
5798 IDirect3D9 *d3d;
5799 ULONG refcount;
5800 D3DCAPS9 caps;
5801 DWORD color;
5802 HWND window;
5803 HRESULT hr;
5805 /* DP2ADD is defined as: (src0.r * src1.r) + (src0.g * src1.g) + src2.
5806 * One D3D restriction of all shader instructions except SINCOS is that no more than 2
5807 * source tokens can be constants. So, for this exercise, we move contents of c0 to
5808 * r0 first.
5809 * The result here for the r,g,b components should be roughly 0.5:
5810 * (0.5 * 0.5) + (0.5 * 0.5) + 0.0 = 0.5 */
5811 static const DWORD shader_code_dp2add[] = {
5812 0xffff0200, /* ps_2_0 */
5813 0x05000051, 0xa00f0000, 0x3f000000, 0x3f000000, 0x3f800000, 0x00000000, /* def c0, 0.5, 0.5, 1.0, 0 */
5815 0x02000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
5816 0x0400005a, 0x80070000, 0x80000000, 0x80000000, 0x80ff0000, /* dp2add r0.rgb, r0, r0, r0.a */
5818 0x02000001, 0x80080000, 0xa0aa0000, /* mov r0.a, c0.b */
5819 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
5820 0x0000ffff /* end */
5823 /* Test the _sat modifier, too. Result here should be:
5824 * DP2: (-0.5 * -0.5) + (-0.5 * -0.5) + 2.0 = 2.5
5825 * _SAT: ==> 1.0
5826 * ADD: (1.0 + -0.5) = 0.5
5828 static const DWORD shader_code_dp2add_sat[] = {
5829 0xffff0200, /* ps_2_0 */
5830 0x05000051, 0xa00f0000, 0xbf000000, 0xbf000000, 0x3f800000, 0x40000000, /* def c0, -0.5, -0.5, 1.0, 2.0 */
5832 0x02000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
5833 0x0400005a, 0x80170000, 0x80000000, 0x80000000, 0x80ff0000, /* dp2add_sat r0.rgb, r0, r0, r0.a */
5834 0x03000002, 0x80070000, 0x80e40000, 0xa0000000, /* add r0.rgb, r0, c0.r */
5836 0x02000001, 0x80080000, 0xa0aa0000, /* mov r0.a, c0.b */
5837 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
5838 0x0000ffff /* end */
5840 static const float quad[] =
5842 -1.0f, -1.0f, 0.1f,
5843 -1.0f, 1.0f, 0.1f,
5844 1.0f, -1.0f, 0.1f,
5845 1.0f, 1.0f, 0.1f,
5848 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5849 0, 0, 640, 480, NULL, NULL, NULL, NULL);
5850 d3d = Direct3DCreate9(D3D_SDK_VERSION);
5851 ok(!!d3d, "Failed to create a D3D object.\n");
5852 if (!(device = create_device(d3d, window, window, TRUE)))
5854 skip("Failed to create a D3D device, skipping tests.\n");
5855 goto done;
5858 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
5859 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
5860 if (caps.PixelShaderVersion < D3DPS_VERSION(2, 0))
5862 skip("No ps_2_0 support, skipping tests.\n");
5863 IDirect3DDevice9_Release(device);
5864 goto done;
5867 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff000000, 1.0f, 0);
5868 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
5870 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_dp2add, &shader_dp2add);
5871 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
5873 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_dp2add_sat, &shader_dp2add_sat);
5874 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
5876 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
5877 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF returned %08x\n", hr);
5879 hr = IDirect3DDevice9_SetPixelShader(device, shader_dp2add);
5880 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5881 hr = IDirect3DDevice9_BeginScene(device);
5882 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5883 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 3 * sizeof(float));
5884 ok(SUCCEEDED(hr), "Failed to draw primitive, hr %#x.\n", hr);
5885 hr = IDirect3DDevice9_EndScene(device);
5886 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5888 color = getPixelColor(device, 360, 240);
5889 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x7f, 0x7f, 0x7f), 1), "Got unexpected color 0x%08x.\n", color);
5891 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
5892 ok(SUCCEEDED(hr), "Failed to present frame, hr %#x.\n", hr);
5893 IDirect3DPixelShader9_Release(shader_dp2add);
5895 hr = IDirect3DDevice9_SetPixelShader(device, shader_dp2add_sat);
5896 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5897 hr = IDirect3DDevice9_BeginScene(device);
5898 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5899 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 3 * sizeof(float));
5900 ok(SUCCEEDED(hr), "Failed to draw primitive, hr %#x.\n", hr);
5901 hr = IDirect3DDevice9_EndScene(device);
5902 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5904 color = getPixelColor(device, 360, 240);
5905 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x7f, 0x7f, 0x7f), 1), "Got unexpected color 0x%08x.\n", color);
5907 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
5908 ok(SUCCEEDED(hr), "Failed to present frame, hr %#x.\n", hr);
5909 IDirect3DPixelShader9_Release(shader_dp2add_sat);
5911 refcount = IDirect3DDevice9_Release(device);
5912 ok(!refcount, "Device has %u references left.\n", refcount);
5913 done:
5914 IDirect3D9_Release(d3d);
5915 DestroyWindow(window);
5918 static void cnd_test(void)
5920 IDirect3DPixelShader9 *shader_11_coissue_2, *shader_12_coissue_2, *shader_13_coissue_2, *shader_14_coissue_2;
5921 IDirect3DPixelShader9 *shader_11_coissue, *shader_12_coissue, *shader_13_coissue, *shader_14_coissue;
5922 IDirect3DPixelShader9 *shader_11, *shader_12, *shader_13, *shader_14;
5923 IDirect3DDevice9 *device;
5924 IDirect3D9 *d3d;
5925 ULONG refcount;
5926 D3DCAPS9 caps;
5927 HWND window;
5928 DWORD color;
5929 HRESULT hr;
5931 /* ps 1.x shaders are rather picky with writemasks and source swizzles.
5932 * The dp3 is used to copy r0.r to all components of r1, then copy r1.a to
5933 * r0.a. Essentially it does a mov r0.a, r0.r, which isn't allowed as-is
5934 * in 1.x pixel shaders. */
5935 static const DWORD shader_code_11[] =
5937 0xffff0101, /* ps_1_1 */
5938 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
5939 0x00000040, 0xb00f0000, /* texcoord t0 */
5940 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, ???(t0) */
5941 0x00000008, 0x800f0001, 0x80e40000, 0xa0e40000, /* dp3 r1, r0, c0 */
5942 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
5943 0x00000050, 0x800f0000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* cnd r0, r0.a, c1, c2 */
5944 0x0000ffff /* end */
5946 static const DWORD shader_code_12[] =
5948 0xffff0102, /* ps_1_2 */
5949 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
5950 0x00000040, 0xb00f0000, /* texcoord t0 */
5951 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
5952 0x00000008, 0x800f0001, 0x80e40000, 0xa0e40000, /* dp3 r1, r0, c0 */
5953 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
5954 0x00000050, 0x800f0000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* cnd r0, r0.a, c1, c2 */
5955 0x0000ffff /* end */
5957 static const DWORD shader_code_13[] =
5959 0xffff0103, /* ps_1_3 */
5960 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
5961 0x00000040, 0xb00f0000, /* texcoord t0 */
5962 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
5963 0x00000008, 0x800f0001, 0x80e40000, 0xa0e40000, /* dp3, r1, r0, c0 */
5964 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
5965 0x00000050, 0x800f0000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* cnd r0, r0.a, c1, c2 */
5966 0x0000ffff /* end */
5968 static const DWORD shader_code_14[] =
5970 0xffff0104, /* ps_1_3 */
5971 0x00000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0, 0, 0, 1 */
5972 0x00000040, 0x80070000, 0xb0e40000, /* texcrd r0, t0 */
5973 0x00000001, 0x80080000, 0xa0ff0000, /* mov r0.a, c0.a */
5974 0x00000050, 0x800f0000, 0x80e40000, 0xa0e40001, 0xa0e40002, /* cnd r0, r0, c1, c2 */
5975 0x0000ffff /* end */
5978 /* Special fun: The coissue flag on cnd: Apparently cnd always selects the 2nd source,
5979 * as if the src0 comparison against 0.5 always evaluates to true. The coissue flag isn't
5980 * set by the compiler, it was added manually after compilation. Note that the COISSUE
5981 * flag on a color(.xyz) operation is only allowed after an alpha operation. DirectX doesn't
5982 * have proper docs, but GL_ATI_fragment_shader explains the pairing of color and alpha ops
5983 * well enough.
5985 * The shader attempts to test the range [-1;1] against coissued cnd, which is a bit tricky.
5986 * The input from t0 is [0;1]. 0.5 is subtracted, then we have to multiply with 2. Since
5987 * constants are clamped to [-1;1], a 2.0 is constructed by adding c0.r(=1.0) to c0.r into r1.r,
5988 * then r1(2.0, 0.0, 0.0, 0.0) is passed to dp3(explained above).
5990 static const DWORD shader_code_11_coissue[] =
5992 0xffff0101, /* ps_1_1 */
5993 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
5994 0x00000051, 0xa00f0003, 0x3f000000, 0x3f000000, 0x3f000000, 0x00000000, /* def c3, 0.5, 0.5, 0.5, 0 */
5995 0x00000040, 0xb00f0000, /* texcoord t0 */
5996 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
5997 0x00000003, 0x800f0000, 0x80e40000, 0xa0e40003, /* sub r0, r0, c3 */
5998 0x00000002, 0x800f0001, 0xa0e40000, 0xa0e40000, /* add r1, c0, c0 */
5999 0x00000008, 0x800f0001, 0x80e40000, 0x80e40001, /* dp3 r1, r0, r1 */
6000 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
6001 0x40000050, 0x80070000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* +cnd r0.xyz, r0.a, c1, c2*/
6002 0x0000ffff /* end */
6004 static const DWORD shader_code_11_coissue_2[] =
6006 0xffff0101, /* ps_1_1 */
6007 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
6008 0x00000051, 0xa00f0003, 0x3f000000, 0x3f000000, 0x3f000000, 0x00000000, /* def c3, 0.5, 0.5, 0.5, 0 */
6009 0x00000040, 0xb00f0000, /* texcoord t0 */
6010 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
6011 0x00000003, 0x800f0000, 0x80e40000, 0xa0e40003, /* sub r0, r0, c3 */
6012 0x00000002, 0x800f0001, 0xa0e40000, 0xa0e40000, /* add r1, c0, c0 */
6013 0x00000008, 0x800f0001, 0x80e40000, 0x80e40001, /* dp3 r1, r0, r1 */
6014 0x00000001, 0x800f0000, 0x80e40001, /* mov r0, r1 */
6015 0x00000001, 0x80070000, 0x80ff0001, /* mov r0.xyz, r1.a */
6016 0x40000050, 0x80080000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* +cnd r0.a, r0.a, c1, c2 */
6017 0x00000001, 0x80070000, 0x80ff0000, /* mov r0.xyz, r0.a */
6018 0x0000ffff /* end */
6020 static const DWORD shader_code_12_coissue[] =
6022 0xffff0102, /* ps_1_2 */
6023 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
6024 0x00000051, 0xa00f0003, 0x3f000000, 0x3f000000, 0x3f000000, 0x00000000, /* def c3, 0.5, 0.5, 0.5, 0 */
6025 0x00000040, 0xb00f0000, /* texcoord t0 */
6026 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
6027 0x00000003, 0x800f0000, 0x80e40000, 0xa0e40003, /* sub r0, r0, c3 */
6028 0x00000002, 0x800f0001, 0xa0e40000, 0xa0e40000, /* add r1, c0, c0 */
6029 0x00000008, 0x800f0001, 0x80e40000, 0x80e40001, /* dp3 r1, r0, r1 */
6030 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
6031 0x40000050, 0x80070000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* +cnd r0.xyz, r0.a, c1, c2*/
6032 0x0000ffff /* end */
6034 static const DWORD shader_code_12_coissue_2[] =
6036 0xffff0102, /* ps_1_2 */
6037 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
6038 0x00000051, 0xa00f0003, 0x3f000000, 0x3f000000, 0x3f000000, 0x00000000, /* def c3, 0.5, 0.5, 0.5, 0 */
6039 0x00000040, 0xb00f0000, /* texcoord t0 */
6040 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
6041 0x00000003, 0x800f0000, 0x80e40000, 0xa0e40003, /* sub r0, r0, c3 */
6042 0x00000002, 0x800f0001, 0xa0e40000, 0xa0e40000, /* add r1, c0, c0 */
6043 0x00000008, 0x800f0001, 0x80e40000, 0x80e40001, /* dp3 r1, r0, r1 */
6044 0x00000001, 0x800f0000, 0x80e40001, /* mov r0, r1 */
6045 0x00000001, 0x80070000, 0x80ff0001, /* mov r0.xyz, r1.a */
6046 0x40000050, 0x80080000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* +cnd r0.a, r0.a, c1, c2 */
6047 0x00000001, 0x80070000, 0x80ff0000, /* mov r0.xyz, r0.a */
6048 0x0000ffff /* end */
6050 static const DWORD shader_code_13_coissue[] =
6052 0xffff0103, /* ps_1_3 */
6053 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
6054 0x00000051, 0xa00f0003, 0x3f000000, 0x3f000000, 0x3f000000, 0x00000000, /* def c3, 0.5, 0.5, 0.5, 0 */
6055 0x00000040, 0xb00f0000, /* texcoord t0 */
6056 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
6057 0x00000003, 0x800f0000, 0x80e40000, 0xa0e40003, /* sub r0, r0, c3 */
6058 0x00000002, 0x800f0001, 0xa0e40000, 0xa0e40000, /* add r1, c0, c0 */
6059 0x00000008, 0x800f0001, 0x80e40000, 0x80e40001, /* dp3 r1, r0, r1 */
6060 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
6061 0x40000050, 0x80070000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* +cnd r0.xyz, r0.a, c1, c2*/
6062 0x0000ffff /* end */
6064 static const DWORD shader_code_13_coissue_2[] =
6066 0xffff0103, /* ps_1_3 */
6067 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
6068 0x00000051, 0xa00f0003, 0x3f000000, 0x3f000000, 0x3f000000, 0x00000000, /* def c3, 0.5, 0.5, 0.5, 0 */
6069 0x00000040, 0xb00f0000, /* texcoord t0 */
6070 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
6071 0x00000003, 0x800f0000, 0x80e40000, 0xa0e40003, /* sub r0, r0, c3 */
6072 0x00000002, 0x800f0001, 0xa0e40000, 0xa0e40000, /* add r1, c0, c0 */
6073 0x00000008, 0x800f0001, 0x80e40000, 0x80e40001, /* dp3 r1, r0, r1 */
6074 0x00000001, 0x800f0000, 0x80e40001, /* mov r0, r1 */
6075 0x00000001, 0x80070000, 0x80ff0001, /* mov r0.xyz, r1.a */
6076 0x40000050, 0x80080000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* +cnd r0.a, r0.a, c1, c2 */
6077 0x00000001, 0x80070000, 0x80ff0000, /* mov r0.xyz, r0.a */
6078 0x0000ffff /* end */
6080 /* ps_1_4 does not have a different cnd behavior, just pass the [0;1]
6081 * texcrd result to cnd, it will compare against 0.5. */
6082 static const DWORD shader_code_14_coissue[] =
6084 0xffff0104, /* ps_1_4 */
6085 0x00000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0, 0, 0, 1 */
6086 0x00000040, 0x80070000, 0xb0e40000, /* texcrd r0.xyz, t0 */
6087 0x00000001, 0x80080000, 0xa0ff0000, /* mov r0.a, c0.a */
6088 0x40000050, 0x80070000, 0x80e40000, 0xa0e40001, 0xa0e40002, /* +cnd r0.xyz, r0, c1, c2 */
6089 0x0000ffff /* end */
6091 static const DWORD shader_code_14_coissue_2[] =
6093 0xffff0104, /* ps_1_4 */
6094 0x00000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0, 0, 0, 1 */
6095 0x00000040, 0x80070000, 0xb0e40000, /* texcrd r0.xyz, t0 */
6096 0x00000001, 0x80080000, 0x80000000, /* mov r0.a, r0.x */
6097 0x00000001, 0x80070001, 0xa0ff0000, /* mov r1.xyz, c0.a */
6098 0x40000050, 0x80080001, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* +cnd r1.a, r0.a, c1, c2 */
6099 0x00000001, 0x80070000, 0x80ff0001, /* mov r0.xyz, r1.a */
6100 0x00000001, 0x80080000, 0xa0ff0000, /* mov r0.a, c0.a */
6101 0x0000ffff /* end */
6103 static const float quad1[] =
6105 -1.0f, -1.0f, 0.1f, 0.0f, 0.0f, 1.0f,
6106 -1.0f, 0.0f, 0.1f, 0.0f, 1.0f, 0.0f,
6107 0.0f, -1.0f, 0.1f, 1.0f, 0.0f, 1.0f,
6108 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 0.0f,
6110 static const float quad2[] =
6112 0.0f, -1.0f, 0.1f, 0.0f, 0.0f, 1.0f,
6113 0.0f, 0.0f, 0.1f, 0.0f, 1.0f, 0.0f,
6114 1.0f, -1.0f, 0.1f, 1.0f, 0.0f, 1.0f,
6115 1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 0.0f,
6117 static const float quad3[] =
6119 0.0f, 0.0f, 0.1f, 0.0f, 0.0f, 1.0f,
6120 0.0f, 1.0f, 0.1f, 0.0f, 1.0f, 0.0f,
6121 1.0f, 0.0f, 0.1f, 1.0f, 0.0f, 1.0f,
6122 1.0f, 1.0f, 0.1f, 1.0f, 1.0f, 0.0f,
6124 static const float quad4[] =
6126 -1.0f, 0.0f, 0.1f, 0.0f, 0.0f, 1.0f,
6127 -1.0f, 1.0f, 0.1f, 0.0f, 1.0f, 0.0f,
6128 0.0f, 0.0f, 0.1f, 1.0f, 0.0f, 1.0f,
6129 0.0f, 1.0f, 0.1f, 1.0f, 1.0f, 0.0f,
6131 static const float test_data_c1[4] = {0.0f, 0.0f, 0.0f, 0.0f};
6132 static const float test_data_c2[4] = {1.0f, 1.0f, 1.0f, 1.0f};
6133 static const float test_data_c1_coi[4] = {0.0f, 1.0f, 0.0f, 0.0f};
6134 static const float test_data_c2_coi[4] = {1.0f, 0.0f, 1.0f, 1.0f};
6136 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6137 0, 0, 640, 480, NULL, NULL, NULL, NULL);
6138 d3d = Direct3DCreate9(D3D_SDK_VERSION);
6139 ok(!!d3d, "Failed to create a D3D object.\n");
6140 if (!(device = create_device(d3d, window, window, TRUE)))
6142 skip("Failed to create a D3D device, skipping tests.\n");
6143 goto done;
6146 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
6147 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
6148 if (caps.PixelShaderVersion < D3DPS_VERSION(1, 4))
6150 skip("No ps_1_4 support, skipping tests.\n");
6151 IDirect3DDevice9_Release(device);
6152 goto done;
6155 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ffff, 1.0f, 0);
6156 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
6158 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_11, &shader_11);
6159 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6160 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_12, &shader_12);
6161 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6162 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_13, &shader_13);
6163 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6164 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_14, &shader_14);
6165 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6166 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_11_coissue, &shader_11_coissue);
6167 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6168 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_12_coissue, &shader_12_coissue);
6169 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6170 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_13_coissue, &shader_13_coissue);
6171 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6172 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_14_coissue, &shader_14_coissue);
6173 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6174 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_11_coissue_2, &shader_11_coissue_2);
6175 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6176 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_12_coissue_2, &shader_12_coissue_2);
6177 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6178 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_13_coissue_2, &shader_13_coissue_2);
6179 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6180 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code_14_coissue_2, &shader_14_coissue_2);
6181 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
6183 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 1, test_data_c1, 1);
6184 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
6185 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 2, test_data_c2, 1);
6186 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
6187 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
6188 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF returned %08x\n", hr);
6190 hr = IDirect3DDevice9_BeginScene(device);
6191 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6193 hr = IDirect3DDevice9_SetPixelShader(device, shader_11);
6194 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6195 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, 6 * sizeof(float));
6196 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6198 hr = IDirect3DDevice9_SetPixelShader(device, shader_12);
6199 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6200 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 6 * sizeof(float));
6201 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6203 hr = IDirect3DDevice9_SetPixelShader(device, shader_13);
6204 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6205 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, 6 * sizeof(float));
6206 ok(hr == D3D_OK, "DrawPrimitiveUP failed (%08x)\n", hr);
6208 hr = IDirect3DDevice9_SetPixelShader(device, shader_14);
6209 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6210 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, 6 * sizeof(float));
6211 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6213 hr = IDirect3DDevice9_EndScene(device);
6214 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6216 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
6217 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShader returned %08x\n", hr);
6219 /* This is the 1.4 test. Each component(r, g, b) is tested separately against 0.5 */
6220 color = getPixelColor(device, 158, 118);
6221 ok(color == 0x00ff00ff, "pixel 158, 118 has color %08x, expected 0x00ff00ff\n", color);
6222 color = getPixelColor(device, 162, 118);
6223 ok(color == 0x000000ff, "pixel 162, 118 has color %08x, expected 0x000000ff\n", color);
6224 color = getPixelColor(device, 158, 122);
6225 ok(color == 0x00ffffff, "pixel 162, 122 has color %08x, expected 0x00ffffff\n", color);
6226 color = getPixelColor(device, 162, 122);
6227 ok(color == 0x0000ffff, "pixel 162, 122 has color %08x, expected 0x0000ffff\n", color);
6229 /* 1.1 shader. All 3 components get set, based on the .w comparison */
6230 color = getPixelColor(device, 158, 358);
6231 ok(color == 0x00ffffff, "pixel 158, 358 has color %08x, expected 0x00ffffff\n", color);
6232 color = getPixelColor(device, 162, 358);
6233 ok(color_match(color, 0x00000000, 1), "pixel 162, 358 has color 0x%08x, expected 0x00000000.\n", color);
6234 color = getPixelColor(device, 158, 362);
6235 ok(color == 0x00ffffff, "pixel 158, 362 has color %08x, expected 0x00ffffff\n", color);
6236 color = getPixelColor(device, 162, 362);
6237 ok(color_match(color, 0x00000000, 1), "pixel 162, 362 has color 0x%08x, expected 0x00000000.\n", color);
6239 /* 1.2 shader */
6240 color = getPixelColor(device, 478, 358);
6241 ok(color == 0x00ffffff, "pixel 478, 358 has color %08x, expected 0x00ffffff\n", color);
6242 color = getPixelColor(device, 482, 358);
6243 ok(color_match(color, 0x00000000, 1), "pixel 482, 358 has color 0x%08x, expected 0x00000000.\n", color);
6244 color = getPixelColor(device, 478, 362);
6245 ok(color == 0x00ffffff, "pixel 478, 362 has color %08x, expected 0x00ffffff\n", color);
6246 color = getPixelColor(device, 482, 362);
6247 ok(color_match(color, 0x00000000, 1), "pixel 482, 362 has color 0x%08x, expected 0x00000000.\n", color);
6249 /* 1.3 shader */
6250 color = getPixelColor(device, 478, 118);
6251 ok(color == 0x00ffffff, "pixel 478, 118 has color %08x, expected 0x00ffffff\n", color);
6252 color = getPixelColor(device, 482, 118);
6253 ok(color_match(color, 0x00000000, 1), "pixel 482, 118 has color 0x%08x, expected 0x00000000.\n", color);
6254 color = getPixelColor(device, 478, 122);
6255 ok(color == 0x00ffffff, "pixel 478, 122 has color %08x, expected 0x00ffffff\n", color);
6256 color = getPixelColor(device, 482, 122);
6257 ok(color_match(color, 0x00000000, 1), "pixel 482, 122 has color 0x%08x, expected 0x00000000.\n", color);
6259 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
6260 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
6262 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ffff, 0.0, 0);
6263 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
6264 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 1, test_data_c1_coi, 1);
6265 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
6266 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 2, test_data_c2_coi, 1);
6267 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr);
6269 hr = IDirect3DDevice9_BeginScene(device);
6270 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6272 hr = IDirect3DDevice9_SetPixelShader(device, shader_11_coissue);
6273 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6274 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, 6 * sizeof(float));
6275 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6277 hr = IDirect3DDevice9_SetPixelShader(device, shader_12_coissue);
6278 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6279 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 6 * sizeof(float));
6280 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6282 hr = IDirect3DDevice9_SetPixelShader(device, shader_13_coissue);
6283 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6284 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, 6 * sizeof(float));
6285 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6287 hr = IDirect3DDevice9_SetPixelShader(device, shader_14_coissue);
6288 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6289 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, 6 * sizeof(float));
6290 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6292 hr = IDirect3DDevice9_EndScene(device);
6293 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6295 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
6296 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader returned %08x\n", hr);
6298 /* This is the 1.4 test. The coissue doesn't change the behavior here, but keep in mind
6299 * that we swapped the values in c1 and c2 to make the other tests return some color
6301 color = getPixelColor(device, 158, 118);
6302 ok(color == 0x00ffffff, "pixel 158, 118 has color %08x, expected 0x00ffffff\n", color);
6303 color = getPixelColor(device, 162, 118);
6304 ok(color == 0x0000ffff, "pixel 162, 118 has color %08x, expected 0x0000ffff\n", color);
6305 color = getPixelColor(device, 158, 122);
6306 ok(color == 0x00ff00ff, "pixel 162, 122 has color %08x, expected 0x00ff00ff\n", color);
6307 color = getPixelColor(device, 162, 122);
6308 ok(color == 0x000000ff, "pixel 162, 122 has color %08x, expected 0x000000ff\n", color);
6310 /* 1.1 shader. coissue flag changed the semantic of cnd, c1 is always selected
6311 * (The Win7 nvidia driver always selects c2)
6313 color = getPixelColor(device, 158, 358);
6314 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6315 "pixel 158, 358 has color %08x, expected 0x0000ff00\n", color);
6316 color = getPixelColor(device, 162, 358);
6317 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6318 "pixel 162, 358 has color %08x, expected 0x0000ff00\n", color);
6319 color = getPixelColor(device, 158, 362);
6320 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6321 "pixel 158, 362 has color %08x, expected 0x0000ff00\n", color);
6322 color = getPixelColor(device, 162, 362);
6323 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6324 "pixel 162, 362 has color %08x, expected 0x0000ff00\n", color);
6326 /* 1.2 shader */
6327 color = getPixelColor(device, 478, 358);
6328 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6329 "pixel 478, 358 has color %08x, expected 0x0000ff00\n", color);
6330 color = getPixelColor(device, 482, 358);
6331 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6332 "pixel 482, 358 has color %08x, expected 0x0000ff00\n", color);
6333 color = getPixelColor(device, 478, 362);
6334 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6335 "pixel 478, 362 has color %08x, expected 0x0000ff00\n", color);
6336 color = getPixelColor(device, 482, 362);
6337 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6338 "pixel 482, 362 has color %08x, expected 0x0000ff00\n", color);
6340 /* 1.3 shader */
6341 color = getPixelColor(device, 478, 118);
6342 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6343 "pixel 478, 118 has color %08x, expected 0x0000ff00\n", color);
6344 color = getPixelColor(device, 482, 118);
6345 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6346 "pixel 482, 118 has color %08x, expected 0x0000ff00\n", color);
6347 color = getPixelColor(device, 478, 122);
6348 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6349 "pixel 478, 122 has color %08x, expected 0x0000ff00\n", color);
6350 color = getPixelColor(device, 482, 122);
6351 ok(color_match(color, 0x0000ff00, 1) || broken(color_match(color, 0x00ff00ff, 1)),
6352 "pixel 482, 122 has color %08x, expected 0x0000ff00\n", color);
6354 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
6355 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
6357 /* Retest with the coissue flag on the alpha instruction instead. This
6358 * works "as expected". The Windows 8 testbot (WARP) seems to handle this
6359 * the same as coissue on .rgb. */
6360 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ffff, 0.0, 0);
6361 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
6363 hr = IDirect3DDevice9_BeginScene(device);
6364 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6366 hr = IDirect3DDevice9_SetPixelShader(device, shader_11_coissue_2);
6367 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6368 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, 6 * sizeof(float));
6369 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6371 hr = IDirect3DDevice9_SetPixelShader(device, shader_12_coissue_2);
6372 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6373 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, 6 * sizeof(float));
6374 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6376 hr = IDirect3DDevice9_SetPixelShader(device, shader_13_coissue_2);
6377 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6378 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, 6 * sizeof(float));
6379 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6381 hr = IDirect3DDevice9_SetPixelShader(device, shader_14_coissue_2);
6382 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
6383 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, 6 * sizeof(float));
6384 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6386 hr = IDirect3DDevice9_EndScene(device);
6387 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6389 /* 1.4 shader */
6390 color = getPixelColor(device, 158, 118);
6391 ok(color == 0x00ffffff, "pixel 158, 118 has color %08x, expected 0x00ffffff\n", color);
6392 color = getPixelColor(device, 162, 118);
6393 ok(color == 0x00000000, "pixel 162, 118 has color %08x, expected 0x00000000\n", color);
6394 color = getPixelColor(device, 158, 122);
6395 ok(color == 0x00ffffff, "pixel 162, 122 has color %08x, expected 0x00ffffff\n", color);
6396 color = getPixelColor(device, 162, 122);
6397 ok(color == 0x00000000, "pixel 162, 122 has color %08x, expected 0x00000000\n", color);
6399 /* 1.1 shader */
6400 color = getPixelColor(device, 238, 358);
6401 ok(color_match(color, 0x00ffffff, 1) || broken(color_match(color, 0x00000000, 1)),
6402 "pixel 238, 358 has color %08x, expected 0x00ffffff\n", color);
6403 color = getPixelColor(device, 242, 358);
6404 ok(color_match(color, 0x00000000, 1),
6405 "pixel 242, 358 has color %08x, expected 0x00000000\n", color);
6406 color = getPixelColor(device, 238, 362);
6407 ok(color_match(color, 0x00ffffff, 1) || broken(color_match(color, 0x00000000, 1)),
6408 "pixel 238, 362 has color %08x, expected 0x00ffffff\n", color);
6409 color = getPixelColor(device, 242, 362);
6410 ok(color_match(color, 0x00000000, 1),
6411 "pixel 242, 362 has color %08x, expected 0x00000000\n", color);
6413 /* 1.2 shader */
6414 color = getPixelColor(device, 558, 358);
6415 ok(color_match(color, 0x00ffffff, 1) || broken(color_match(color, 0x00000000, 1)),
6416 "pixel 558, 358 has color %08x, expected 0x00ffffff\n", color);
6417 color = getPixelColor(device, 562, 358);
6418 ok(color_match(color, 0x00000000, 1),
6419 "pixel 562, 358 has color %08x, expected 0x00000000\n", color);
6420 color = getPixelColor(device, 558, 362);
6421 ok(color_match(color, 0x00ffffff, 1) || broken(color_match(color, 0x00000000, 1)),
6422 "pixel 558, 362 has color %08x, expected 0x00ffffff\n", color);
6423 color = getPixelColor(device, 562, 362);
6424 ok(color_match(color, 0x00000000, 1),
6425 "pixel 562, 362 has color %08x, expected 0x00000000\n", color);
6427 /* 1.3 shader */
6428 color = getPixelColor(device, 558, 118);
6429 ok(color_match(color, 0x00ffffff, 1) || broken(color_match(color, 0x00000000, 1)),
6430 "pixel 558, 118 has color %08x, expected 0x00ffffff\n", color);
6431 color = getPixelColor(device, 562, 118);
6432 ok(color_match(color, 0x00000000, 1),
6433 "pixel 562, 118 has color %08x, expected 0x00000000\n", color);
6434 color = getPixelColor(device, 558, 122);
6435 ok(color_match(color, 0x00ffffff, 1) || broken(color_match(color, 0x00000000, 1)),
6436 "pixel 558, 122 has color %08x, expected 0x00ffffff\n", color);
6437 color = getPixelColor(device, 562, 122);
6438 ok(color_match(color, 0x00000000, 1),
6439 "pixel 562, 122 has color %08x, expected 0x00000000\n", color);
6441 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
6442 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
6444 IDirect3DPixelShader9_Release(shader_14_coissue_2);
6445 IDirect3DPixelShader9_Release(shader_13_coissue_2);
6446 IDirect3DPixelShader9_Release(shader_12_coissue_2);
6447 IDirect3DPixelShader9_Release(shader_11_coissue_2);
6448 IDirect3DPixelShader9_Release(shader_14_coissue);
6449 IDirect3DPixelShader9_Release(shader_13_coissue);
6450 IDirect3DPixelShader9_Release(shader_12_coissue);
6451 IDirect3DPixelShader9_Release(shader_11_coissue);
6452 IDirect3DPixelShader9_Release(shader_14);
6453 IDirect3DPixelShader9_Release(shader_13);
6454 IDirect3DPixelShader9_Release(shader_12);
6455 IDirect3DPixelShader9_Release(shader_11);
6456 refcount = IDirect3DDevice9_Release(device);
6457 ok(!refcount, "Device has %u references left.\n", refcount);
6458 done:
6459 IDirect3D9_Release(d3d);
6460 DestroyWindow(window);
6463 static void nested_loop_test(void)
6465 IDirect3DVertexShader9 *vshader;
6466 IDirect3DPixelShader9 *shader;
6467 IDirect3DDevice9 *device;
6468 IDirect3D9 *d3d;
6469 ULONG refcount;
6470 D3DCAPS9 caps;
6471 DWORD color;
6472 HWND window;
6473 HRESULT hr;
6475 static const DWORD shader_code[] =
6477 0xffff0300, /* ps_3_0 */
6478 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0, 0, 0, 1 */
6479 0x05000051, 0xa00f0001, 0x3d000000, 0x00000000, 0x00000000, 0x00000000, /* def c1, 1/32, 0, 0, 0*/
6480 0x05000030, 0xf00f0000, 0x00000004, 0x00000000, 0x00000002, 0x00000000, /* defi i0, 4, 0, 2, 0 */
6481 0x02000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
6482 0x0200001b, 0xf0e40800, 0xf0e40000, /* loop aL, i0 */
6483 0x0200001b, 0xf0e40800, 0xf0e40000, /* loop aL, i0 */
6484 0x03000002, 0x800f0000, 0x80e40000, 0xa0e40001, /* add r0, r0, c1 */
6485 0x0000001d, /* endloop */
6486 0x0000001d, /* endloop */
6487 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
6488 0x0000ffff /* end */
6490 static const DWORD vshader_code[] =
6492 0xfffe0300, /* vs_3_0 */
6493 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
6494 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
6495 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
6496 0x0000ffff /* end */
6498 static const float quad[] =
6500 -1.0f, -1.0f, 0.1f,
6501 -1.0f, 1.0f, 0.1f,
6502 1.0f, -1.0f, 0.1f,
6503 1.0f, 1.0f, 0.1f,
6506 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6507 0, 0, 640, 480, NULL, NULL, NULL, NULL);
6508 d3d = Direct3DCreate9(D3D_SDK_VERSION);
6509 ok(!!d3d, "Failed to create a D3D object.\n");
6510 if (!(device = create_device(d3d, window, window, TRUE)))
6512 skip("Failed to create a D3D device, skipping tests.\n");
6513 goto done;
6516 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
6517 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
6518 if (caps.PixelShaderVersion < D3DPS_VERSION(3, 0) || caps.VertexShaderVersion < D3DVS_VERSION(3, 0))
6520 skip("No shader model 3 support, skipping tests.\n");
6521 IDirect3DDevice9_Release(device);
6522 goto done;
6525 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code, &shader);
6526 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader failed with %08x\n", hr);
6527 hr = IDirect3DDevice9_SetPixelShader(device, shader);
6528 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader failed with %08x\n", hr);
6529 hr = IDirect3DDevice9_CreateVertexShader(device, vshader_code, &vshader);
6530 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader failed with %08x\n", hr);
6531 hr = IDirect3DDevice9_SetVertexShader(device, vshader);
6532 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShader failed with %08x\n", hr);
6533 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
6534 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
6535 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x0000ff00, 1.0f, 0);
6536 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
6538 hr = IDirect3DDevice9_BeginScene(device);
6539 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6540 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 3 * sizeof(float));
6541 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6542 hr = IDirect3DDevice9_EndScene(device);
6543 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6545 color = getPixelColor(device, 360, 240);
6546 ok(color_match(color, 0x00800000, 1),
6547 "Nested loop test returned color 0x%08x, expected 0x00800000.\n", color);
6549 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
6550 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
6552 IDirect3DPixelShader9_Release(shader);
6553 IDirect3DVertexShader9_Release(vshader);
6554 refcount = IDirect3DDevice9_Release(device);
6555 ok(!refcount, "Device has %u references left.\n", refcount);
6556 done:
6557 IDirect3D9_Release(d3d);
6558 DestroyWindow(window);
6561 static void pretransformed_varying_test(void)
6563 /* dcl_position: fails to compile */
6564 static const DWORD blendweight_code[] =
6566 0xffff0300, /* ps_3_0 */
6567 0x0200001f, 0x80000001, 0x900f0000, /* dcl_blendweight, v0 */
6568 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
6569 0x0000ffff /* end */
6571 static const DWORD blendindices_code[] =
6573 0xffff0300, /* ps_3_0 */
6574 0x0200001f, 0x80000002, 0x900f0000, /* dcl_blendindices, v0 */
6575 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
6576 0x0000ffff /* end */
6578 static const DWORD normal_code[] =
6580 0xffff0300, /* ps_3_0 */
6581 0x0200001f, 0x80000003, 0x900f0000, /* dcl_normal, v0 */
6582 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
6583 0x0000ffff /* end */
6585 /* psize: fails? */
6586 static const DWORD texcoord0_code[] =
6588 0xffff0300, /* ps_3_0 */
6589 0x0200001f, 0x80000005, 0x900f0000, /* dcl_texcoord0, v0 */
6590 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
6591 0x0000ffff /* end */
6593 static const DWORD tangent_code[] =
6595 0xffff0300, /* ps_3_0 */
6596 0x0200001f, 0x80000006, 0x900f0000, /* dcl_tangent, v0 */
6597 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
6598 0x0000ffff /* end */
6600 static const DWORD binormal_code[] =
6602 0xffff0300, /* ps_3_0 */
6603 0x0200001f, 0x80000007, 0x900f0000, /* dcl_binormal, v0 */
6604 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
6605 0x0000ffff /* end */
6607 /* tessfactor: fails */
6608 /* positiont: fails */
6609 static const DWORD color_code[] =
6611 0xffff0300, /* ps_3_0 */
6612 0x0200001f, 0x8000000a, 0x900f0000, /* dcl_color0, v0 */
6613 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
6614 0x0000ffff /* end */
6616 static const DWORD fog_code[] =
6618 0xffff0300, /* ps_3_0 */
6619 0x0200001f, 0x8000000b, 0x900f0000, /* dcl_fog, v0 */
6620 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
6621 0x0000ffff /* end */
6623 static const DWORD depth_code[] =
6625 0xffff0300, /* ps_3_0 */
6626 0x0200001f, 0x8000000c, 0x900f0000, /* dcl_depth, v0 */
6627 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
6628 0x0000ffff /* end */
6630 static const DWORD specular_code[] =
6632 0xffff0300, /* ps_3_0 */
6633 0x0200001f, 0x8001000a, 0x900f0000, /* dcl_color1, v0 */
6634 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
6635 0x0000ffff /* end */
6637 /* sample: fails */
6639 static const struct
6641 const char *name;
6642 const DWORD *shader_code;
6643 DWORD color;
6644 BOOL todo;
6646 tests[] =
6648 {"blendweight", blendweight_code, 0x00191919, TRUE },
6649 {"blendindices", blendindices_code, 0x00333333, TRUE },
6650 {"normal", normal_code, 0x004c4c4c, TRUE },
6651 {"texcoord0", texcoord0_code, 0x00808c8c, FALSE},
6652 {"tangent", tangent_code, 0x00999999, TRUE },
6653 {"binormal", binormal_code, 0x00b2b2b2, TRUE },
6654 {"color", color_code, 0x00e6e6e6, FALSE},
6655 {"fog", fog_code, 0x00666666, TRUE },
6656 {"depth", depth_code, 0x00cccccc, TRUE },
6657 {"specular", specular_code, 0x004488ff, FALSE},
6659 /* Declare a monster vertex type :-) */
6660 static const D3DVERTEXELEMENT9 decl_elements[] = {
6661 {0, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITIONT, 0},
6662 {0, 16, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0},
6663 {0, 32, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDINDICES, 0},
6664 {0, 48, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
6665 {0, 64, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_FOG, 0},
6666 {0, 80, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
6667 {0, 96, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0},
6668 {0, 112, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0},
6669 {0, 128, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_DEPTH, 0},
6670 {0, 144, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
6671 {0, 148, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 1},
6672 D3DDECL_END()
6675 static const struct
6677 float pos_x, pos_y, pos_z, rhw;
6678 float weight_1, weight_2, weight_3, weight_4;
6679 float index_1, index_2, index_3, index_4;
6680 float normal_1, normal_2, normal_3, normal_4;
6681 float fog_1, fog_2, fog_3, fog_4;
6682 float texcoord_1, texcoord_2, texcoord_3, texcoord_4;
6683 float tangent_1, tangent_2, tangent_3, tangent_4;
6684 float binormal_1, binormal_2, binormal_3, binormal_4;
6685 float depth_1, depth_2, depth_3, depth_4;
6686 D3DCOLOR diffuse;
6687 D3DCOLOR specular;
6689 data[] =
6692 0.0f, 0.0f, 0.1f, 1.0f,
6693 0.1f, 0.1f, 0.1f, 0.1f,
6694 0.2f, 0.2f, 0.2f, 0.2f,
6695 0.3f, 0.3f, 0.3f, 0.3f,
6696 0.4f, 0.4f, 0.4f, 0.4f,
6697 0.5f, 0.55f, 0.55f, 0.55f,
6698 0.6f, 0.6f, 0.6f, 0.7f,
6699 0.7f, 0.7f, 0.7f, 0.6f,
6700 0.8f, 0.8f, 0.8f, 0.8f,
6701 0xe6e6e6e6, /* 0.9 * 256 */
6702 0x224488ff, /* Nothing special */
6705 640.0f, 0.0f, 0.1f, 1.0f,
6706 0.1f, 0.1f, 0.1f, 0.1f,
6707 0.2f, 0.2f, 0.2f, 0.2f,
6708 0.3f, 0.3f, 0.3f, 0.3f,
6709 0.4f, 0.4f, 0.4f, 0.4f,
6710 0.5f, 0.55f, 0.55f, 0.55f,
6711 0.6f, 0.6f, 0.6f, 0.7f,
6712 0.7f, 0.7f, 0.7f, 0.6f,
6713 0.8f, 0.8f, 0.8f, 0.8f,
6714 0xe6e6e6e6, /* 0.9 * 256 */
6715 0x224488ff, /* Nothing special */
6718 0.0f, 480.0f, 0.1f, 1.0f,
6719 0.1f, 0.1f, 0.1f, 0.1f,
6720 0.2f, 0.2f, 0.2f, 0.2f,
6721 0.3f, 0.3f, 0.3f, 0.3f,
6722 0.4f, 0.4f, 0.4f, 0.4f,
6723 0.5f, 0.55f, 0.55f, 0.55f,
6724 0.6f, 0.6f, 0.6f, 0.7f,
6725 0.7f, 0.7f, 0.7f, 0.6f,
6726 0.8f, 0.8f, 0.8f, 0.8f,
6727 0xe6e6e6e6, /* 0.9 * 256 */
6728 0x224488ff, /* Nothing special */
6731 640.0f, 480.0f, 0.1f, 1.0f,
6732 0.1f, 0.1f, 0.1f, 0.1f,
6733 0.2f, 0.2f, 0.2f, 0.2f,
6734 0.3f, 0.3f, 0.3f, 0.3f,
6735 0.4f, 0.4f, 0.4f, 0.4f,
6736 0.5f, 0.55f, 0.55f, 0.55f,
6737 0.6f, 0.6f, 0.6f, 0.7f,
6738 0.7f, 0.7f, 0.7f, 0.6f,
6739 0.8f, 0.8f, 0.8f, 0.8f,
6740 0xe6e6e6e6, /* 0.9 * 256 */
6741 0x224488ff, /* Nothing special */
6744 IDirect3DVertexDeclaration9 *decl;
6745 IDirect3DDevice9 *device;
6746 IDirect3D9 *d3d;
6747 unsigned int i;
6748 ULONG refcount;
6749 D3DCAPS9 caps;
6750 DWORD color;
6751 HWND window;
6752 HRESULT hr;
6754 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6755 0, 0, 640, 480, NULL, NULL, NULL, NULL);
6756 d3d = Direct3DCreate9(D3D_SDK_VERSION);
6757 ok(!!d3d, "Failed to create a D3D object.\n");
6758 if (!(device = create_device(d3d, window, window, TRUE)))
6760 skip("Failed to create a D3D device, skipping tests.\n");
6761 goto done;
6764 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
6765 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
6766 if (caps.PixelShaderVersion < D3DPS_VERSION(3, 0) || caps.VertexShaderVersion < D3DVS_VERSION(3, 0))
6768 skip("No shader model 3 support, skipping tests.\n");
6769 IDirect3DDevice9_Release(device);
6770 goto done;
6773 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &decl);
6774 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
6775 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl);
6776 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexDeclaration returned %08x\n", hr);
6778 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
6780 IDirect3DPixelShader9 *shader;
6782 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
6783 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
6785 hr = IDirect3DDevice9_CreatePixelShader(device, tests[i].shader_code, &shader);
6786 ok(SUCCEEDED(hr), "Failed to create pixel shader for test %s, hr %#x.\n", tests[i].name, hr);
6788 hr = IDirect3DDevice9_SetPixelShader(device, shader);
6789 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader returned %08x\n", hr);
6791 hr = IDirect3DDevice9_BeginScene(device);
6792 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6793 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, data, sizeof(*data));
6794 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6795 hr = IDirect3DDevice9_EndScene(device);
6796 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6798 /* This isn't a weekend's job to fix, ignore the problem for now.
6799 * Needs a replacement pipeline. */
6800 color = getPixelColor(device, 360, 240);
6801 if (tests[i].todo)
6802 todo_wine ok(color_match(color, tests[i].color, 1)
6803 || broken(color_match(color, 0x00000000, 1)
6804 && tests[i].shader_code == blendindices_code),
6805 "Test %s returned color 0x%08x, expected 0x%08x (todo).\n",
6806 tests[i].name, color, tests[i].color);
6807 else
6808 ok(color_match(color, tests[i].color, 1),
6809 "Test %s returned color 0x%08x, expected 0x%08x.\n",
6810 tests[i].name, color, tests[i].color);
6812 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
6813 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
6815 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
6816 ok(SUCCEEDED(hr), "Failed to set pixel shader for test %s, hr %#x.\n", tests[i].name, hr);
6817 IDirect3DPixelShader9_Release(shader);
6820 IDirect3DVertexDeclaration9_Release(decl);
6821 refcount = IDirect3DDevice9_Release(device);
6822 ok(!refcount, "Device has %u references left.\n", refcount);
6823 done:
6824 IDirect3D9_Release(d3d);
6825 DestroyWindow(window);
6828 static void test_compare_instructions(void)
6830 IDirect3DVertexShader9 *shader_slt_scalar;
6831 IDirect3DVertexShader9 *shader_sge_scalar;
6832 IDirect3DVertexShader9 *shader_slt_vec;
6833 IDirect3DVertexShader9 *shader_sge_vec;
6834 IDirect3DDevice9 *device;
6835 IDirect3D9 *d3d;
6836 D3DCOLOR color;
6837 ULONG refcount;
6838 D3DCAPS9 caps;
6839 HWND window;
6840 HRESULT hr;
6842 static const DWORD shader_sge_vec_code[] =
6844 0xfffe0101, /* vs_1_1 */
6845 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
6846 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
6847 0x00000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
6848 0x0000000d, 0xd00f0000, 0x80e40000, 0xa0e40001, /* sge oD0, r0, c1 */
6849 0x0000ffff /* end */
6851 static const DWORD shader_slt_vec_code[] =
6853 0xfffe0101, /* vs_1_1 */
6854 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
6855 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
6856 0x00000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
6857 0x0000000c, 0xd00f0000, 0x80e40000, 0xa0e40001, /* slt oD0, r0, c1 */
6858 0x0000ffff /* end */
6860 static const DWORD shader_sge_scalar_code[] =
6862 0xfffe0101, /* vs_1_1 */
6863 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
6864 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
6865 0x00000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
6866 0x0000000d, 0xd0010000, 0x80000000, 0xa0550001, /* slt oD0.r, r0.r, c1.b */
6867 0x0000000d, 0xd0020000, 0x80550000, 0xa0aa0001, /* slt oD0.g, r0.g, c1.r */
6868 0x0000000d, 0xd0040000, 0x80aa0000, 0xa0000001, /* slt oD0.b, r0.b, c1.g */
6869 0x0000ffff /* end */
6871 static const DWORD shader_slt_scalar_code[] =
6873 0xfffe0101, /* vs_1_1 */
6874 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
6875 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
6876 0x00000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
6877 0x0000000c, 0xd0010000, 0x80000000, 0xa0aa0001, /* slt oD0.r, r0.r, c1.b */
6878 0x0000000c, 0xd0020000, 0x80550000, 0xa0000001, /* slt oD0.g, r0.g, c1.r */
6879 0x0000000c, 0xd0040000, 0x80aa0000, 0xa0550001, /* slt oD0.b, r0.b, c1.g */
6880 0x0000ffff /* end */
6882 static const float quad1[] =
6884 -1.0f, -1.0f, 0.1f,
6885 -1.0f, 0.0f, 0.1f,
6886 0.0f, -1.0f, 0.1f,
6887 0.0f, 0.0f, 0.1f,
6889 static const float quad2[] =
6891 0.0f, -1.0f, 0.1f,
6892 0.0f, 0.0f, 0.1f,
6893 1.0f, -1.0f, 0.1f,
6894 1.0f, 0.0f, 0.1f,
6896 static const float quad3[] =
6898 -1.0f, 0.0f, 0.1f,
6899 -1.0f, 1.0f, 0.1f,
6900 0.0f, 0.0f, 0.1f,
6901 0.0f, 1.0f, 0.1f,
6903 static const float quad4[] =
6905 0.0f, 0.0f, 0.1f,
6906 0.0f, 1.0f, 0.1f,
6907 1.0f, 0.0f, 0.1f,
6908 1.0f, 1.0f, 0.1f,
6910 static const float const0[4] = {0.8f, 0.2f, 0.2f, 0.2f};
6911 static const float const1[4] = {0.2f, 0.8f, 0.2f, 0.2f};
6913 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6914 0, 0, 640, 480, NULL, NULL, NULL, NULL);
6915 d3d = Direct3DCreate9(D3D_SDK_VERSION);
6916 ok(!!d3d, "Failed to create a D3D object.\n");
6917 if (!(device = create_device(d3d, window, window, TRUE)))
6919 skip("Failed to create a D3D device, skipping tests.\n");
6920 goto done;
6923 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
6924 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
6925 if (caps.VertexShaderVersion < D3DVS_VERSION(1, 1))
6927 skip("No vs_1_1 support, skipping tests.\n");
6928 IDirect3DDevice9_Release(device);
6929 goto done;
6932 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
6933 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear returned %#x.\n", hr);
6935 hr = IDirect3DDevice9_CreateVertexShader(device, shader_sge_vec_code, &shader_sge_vec);
6936 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
6937 hr = IDirect3DDevice9_CreateVertexShader(device, shader_slt_vec_code, &shader_slt_vec);
6938 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
6939 hr = IDirect3DDevice9_CreateVertexShader(device, shader_sge_scalar_code, &shader_sge_scalar);
6940 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
6941 hr = IDirect3DDevice9_CreateVertexShader(device, shader_slt_scalar_code, &shader_slt_scalar);
6942 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
6943 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 0, const0, 1);
6944 ok(SUCCEEDED(hr), "SetVertexShaderConstantF failed (%08x)\n", hr);
6945 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 1, const1, 1);
6946 ok(SUCCEEDED(hr), "SetVertexShaderConstantF failed (%08x)\n", hr);
6947 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
6948 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetFVF failed (%08x)\n", hr);
6950 hr = IDirect3DDevice9_BeginScene(device);
6951 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6953 hr = IDirect3DDevice9_SetVertexShader(device, shader_sge_vec);
6954 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
6955 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(float) * 3);
6956 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6958 hr = IDirect3DDevice9_SetVertexShader(device, shader_slt_vec);
6959 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
6960 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(float) * 3);
6961 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6963 hr = IDirect3DDevice9_SetVertexShader(device, shader_sge_scalar);
6964 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
6965 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, sizeof(float) * 3);
6966 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6968 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 0, const0, 1);
6969 ok(SUCCEEDED(hr), "Failed to set vertex shader constant, hr %#x.\n", hr);
6971 hr = IDirect3DDevice9_SetVertexShader(device, shader_slt_scalar);
6972 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
6973 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, sizeof(float) * 3);
6974 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6976 hr = IDirect3DDevice9_EndScene(device);
6977 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6979 color = getPixelColor(device, 160, 360);
6980 ok(color == 0x00ff00ff, "Compare test: Quad 1(sge vec) returned color 0x%08x, expected 0x00ff00ff\n", color);
6981 color = getPixelColor(device, 480, 360);
6982 ok(color == 0x0000ff00, "Compare test: Quad 2(slt vec) returned color 0x%08x, expected 0x0000ff00\n", color);
6983 color = getPixelColor(device, 160, 120);
6984 ok(color == 0x00ffffff, "Compare test: Quad 3(sge scalar) returned color 0x%08x, expected 0x00ffffff\n", color);
6985 color = getPixelColor(device, 480, 160);
6986 ok(color == 0x000000ff, "Compare test: Quad 4(slt scalar) returned color 0x%08x, expected 0x000000ff\n", color);
6988 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
6989 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
6991 IDirect3DVertexShader9_Release(shader_sge_vec);
6992 IDirect3DVertexShader9_Release(shader_slt_vec);
6993 IDirect3DVertexShader9_Release(shader_sge_scalar);
6994 IDirect3DVertexShader9_Release(shader_slt_scalar);
6995 refcount = IDirect3DDevice9_Release(device);
6996 ok(!refcount, "Device has %u references left.\n", refcount);
6997 done:
6998 IDirect3D9_Release(d3d);
6999 DestroyWindow(window);
7002 static void test_vshader_input(void)
7004 IDirect3DVertexDeclaration9 *decl_twotexcrd, *decl_onetexcrd, *decl_twotex_wrongidx, *decl_twotexcrd_rightorder;
7005 IDirect3DVertexDeclaration9 *decl_texcoord_color, *decl_color_color, *decl_color_ubyte, *decl_color_float;
7006 IDirect3DVertexShader9 *swapped_shader, *texcoord_color_shader, *color_color_shader;
7007 D3DADAPTER_IDENTIFIER9 identifier;
7008 IDirect3DPixelShader9 *ps;
7009 IDirect3DDevice9 *device;
7010 IDirect3D9 *d3d;
7011 ULONG refcount;
7012 unsigned int i;
7013 D3DCAPS9 caps;
7014 DWORD color;
7015 HWND window;
7016 HRESULT hr;
7017 BOOL warp;
7019 static const DWORD swapped_shader_code_3[] =
7021 0xfffe0300, /* vs_3_0 */
7022 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
7023 0x0200001f, 0x8000000a, 0xe00f0001, /* dcl_color o1 */
7024 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7025 0x0200001f, 0x80000005, 0x900f0001, /* dcl_texcoord0 v1 */
7026 0x0200001f, 0x80010005, 0x900f0002, /* dcl_texcoord1 v2 */
7027 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
7028 0x02000001, 0x800f0001, 0x90e40001, /* mov r1, v1 */
7029 0x03000002, 0xe00f0001, 0x80e40001, 0x91e40002, /* sub o1, r1, v2 */
7030 0x0000ffff /* end */
7032 static const DWORD swapped_shader_code_1[] =
7034 0xfffe0101, /* vs_1_1 */
7035 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7036 0x0000001f, 0x80000005, 0x900f0001, /* dcl_texcoord0 v1 */
7037 0x0000001f, 0x80010005, 0x900f0002, /* dcl_texcoord1 v2 */
7038 0x00000001, 0xc00f0000, 0x90e40000, /* mov o0, v0 */
7039 0x00000001, 0x800f0001, 0x90e40001, /* mov r1, v1 */
7040 0x00000002, 0xd00f0000, 0x80e40001, 0x91e40002, /* sub o1, r1, v2 */
7041 0x0000ffff /* end */
7043 static const DWORD swapped_shader_code_2[] =
7045 0xfffe0200, /* vs_2_0 */
7046 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7047 0x0200001f, 0x80000005, 0x900f0001, /* dcl_texcoord0 v1 */
7048 0x0200001f, 0x80010005, 0x900f0002, /* dcl_texcoord1 v2 */
7049 0x02000001, 0xc00f0000, 0x90e40000, /* mov o0, v0 */
7050 0x02000001, 0x800f0001, 0x90e40001, /* mov r1, v1 */
7051 0x03000002, 0xd00f0000, 0x80e40001, 0x91e40002, /* sub o1, r1, v2 */
7052 0x0000ffff /* end */
7054 static const DWORD texcoord_color_shader_code_3[] =
7056 0xfffe0300, /* vs_3_0 */
7057 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
7058 0x0200001f, 0x8000000a, 0xe00f0001, /* dcl_color o1 */
7059 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7060 0x0200001f, 0x80000005, 0x900f0001, /* dcl_texcoord v1 */
7061 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
7062 0x02000001, 0xe00f0001, 0x90e40001, /* mov o1, v1 */
7063 0x0000ffff /* end */
7065 static const DWORD texcoord_color_shader_code_2[] =
7067 0xfffe0200, /* vs_2_0 */
7068 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7069 0x0200001f, 0x80000005, 0x900f0001, /* dcl_texcoord v1 */
7070 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
7071 0x02000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
7072 0x0000ffff /* end */
7074 static const DWORD texcoord_color_shader_code_1[] =
7076 0xfffe0101, /* vs_1_1 */
7077 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7078 0x0000001f, 0x80000005, 0x900f0001, /* dcl_texcoord v1 */
7079 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
7080 0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
7081 0x0000ffff /* end */
7083 static const DWORD color_color_shader_code_3[] =
7085 0xfffe0300, /* vs_3_0 */
7086 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
7087 0x0200001f, 0x8000000a, 0xe00f0001, /* dcl_color o1 */
7088 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7089 0x0200001f, 0x8000000a, 0x900f0001, /* dcl_color v1 */
7090 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
7091 0x03000005, 0xe00f0001, 0xa0e40000, 0x90e40001, /* mul o1, c0, v1 */
7092 0x0000ffff /* end */
7094 static const DWORD color_color_shader_code_2[] =
7096 0xfffe0200, /* vs_2_0 */
7097 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7098 0x0200001f, 0x8000000a, 0x900f0001, /* dcl_color v1 */
7099 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
7100 0x03000005, 0xd00f0000, 0xa0e40000, 0x90e40001, /* mul oD0, c0, v1 */
7101 0x0000ffff /* end */
7103 static const DWORD color_color_shader_code_1[] =
7105 0xfffe0101, /* vs_1_1 */
7106 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7107 0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color v1 */
7108 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
7109 0x00000005, 0xd00f0000, 0xa0e40000, 0x90e40001, /* mul oD0, c0, v1 */
7110 0x0000ffff /* end */
7112 static const DWORD ps3_code[] =
7114 0xffff0300, /* ps_3_0 */
7115 0x0200001f, 0x8000000a, 0x900f0000, /* dcl_color0 v0 */
7116 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7117 0x0000ffff /* end */
7119 static const float quad1[] =
7121 -1.0f, -1.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.5f, 0.0f,
7122 -1.0f, 0.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.5f, 0.0f,
7123 0.0f, -1.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.5f, 0.0f,
7124 0.0f, 0.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.5f, 0.0f,
7126 static const float quad2[] =
7128 0.0f, -1.0f, 0.1f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
7129 0.0f, 0.0f, 0.1f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
7130 1.0f, -1.0f, 0.1f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
7131 1.0f, 0.0f, 0.1f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
7133 static const float quad3[] =
7135 -1.0f, 0.0f, 0.1f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f,
7136 -1.0f, 1.0f, 0.1f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f,
7137 0.0f, 0.0f, 0.1f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
7138 0.0f, 1.0f, 0.1f, -1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f,
7140 static const float quad4[] =
7142 0.0f, 0.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.5f, 0.0f,
7143 0.0f, 1.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.5f, 0.0f,
7144 1.0f, 0.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.5f, 0.0f,
7145 1.0f, 1.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.5f, 0.0f,
7147 static const float quad1_modified[] =
7149 -1.0f, -1.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f,
7150 -1.0f, 0.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f,
7151 0.0f, -1.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
7152 0.0f, 0.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f, -1.0f, -1.0f, -1.0f, 0.0f,
7154 static const float quad2_modified[] =
7156 0.0f, -1.0f, 0.1f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
7157 0.0f, 0.0f, 0.1f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
7158 1.0f, -1.0f, 0.1f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
7159 1.0f, 0.0f, 0.1f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
7161 static const struct
7163 struct vec3 position;
7164 DWORD diffuse;
7166 quad1_color[] =
7168 {{-1.0f, -1.0f, 0.1f}, 0x00ff8040},
7169 {{-1.0f, 0.0f, 0.1f}, 0x00ff8040},
7170 {{ 0.0f, -1.0f, 0.1f}, 0x00ff8040},
7171 {{ 0.0f, 0.0f, 0.1f}, 0x00ff8040},
7173 quad2_color[] =
7175 {{ 0.0f, -1.0f, 0.1f}, 0x00ff8040},
7176 {{ 0.0f, 0.0f, 0.1f}, 0x00ff8040},
7177 {{ 1.0f, -1.0f, 0.1f}, 0x00ff8040},
7178 {{ 1.0f, 0.0f, 0.1f}, 0x00ff8040},
7180 quad3_color[] =
7182 {{-1.0f, 0.0f, 0.1f}, 0x00ff8040},
7183 {{-1.0f, 1.0f, 0.1f}, 0x00ff8040},
7184 {{ 0.0f, 0.0f, 0.1f}, 0x00ff8040},
7185 {{ 0.0f, 1.0f, 0.1f}, 0x00ff8040},
7187 static const float quad4_color[] =
7189 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 0.0f, 0.0f,
7190 0.0f, 1.0f, 0.1f, 1.0f, 1.0f, 0.0f, 0.0f,
7191 1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 0.0f, 1.0f,
7192 1.0f, 1.0f, 0.1f, 1.0f, 1.0f, 0.0f, 1.0f,
7194 static const D3DVERTEXELEMENT9 decl_elements_twotexcrd[] =
7196 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7197 {0, 12, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
7198 {0, 28, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},
7199 D3DDECL_END()
7201 static const D3DVERTEXELEMENT9 decl_elements_twotexcrd_rightorder[] =
7203 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7204 {0, 12, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},
7205 {0, 28, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
7206 D3DDECL_END()
7208 static const D3DVERTEXELEMENT9 decl_elements_onetexcrd[] =
7210 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7211 {0, 12, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
7212 D3DDECL_END()
7214 static const D3DVERTEXELEMENT9 decl_elements_twotexcrd_wrongidx[] =
7216 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7217 {0, 12, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},
7218 {0, 28, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 2},
7219 D3DDECL_END()
7221 static const D3DVERTEXELEMENT9 decl_elements_texcoord_color[] =
7223 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7224 {0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
7225 D3DDECL_END()
7227 static const D3DVERTEXELEMENT9 decl_elements_color_color[] =
7229 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7230 {0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
7231 D3DDECL_END()
7233 static const D3DVERTEXELEMENT9 decl_elements_color_ubyte[] =
7235 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7236 {0, 12, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
7237 D3DDECL_END()
7239 static const D3DVERTEXELEMENT9 decl_elements_color_float[] =
7241 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7242 {0, 12, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
7243 D3DDECL_END()
7245 static const float normalize[4] = {1.0f / 256.0f, 1.0f / 256.0f, 1.0f / 256.0f, 1.0f / 256.0f};
7246 static const float no_normalize[4] = {1.0f, 1.0f, 1.0f, 1.0f};
7248 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7249 0, 0, 640, 480, NULL, NULL, NULL, NULL);
7250 d3d = Direct3DCreate9(D3D_SDK_VERSION);
7251 ok(!!d3d, "Failed to create a D3D object.\n");
7252 if (!(device = create_device(d3d, window, window, TRUE)))
7254 skip("Failed to create a D3D device, skipping tests.\n");
7255 goto done;
7258 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
7259 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
7260 if (caps.VertexShaderVersion < D3DVS_VERSION(3, 0))
7262 skip("No vs_3_0 support, skipping tests.\n");
7263 IDirect3DDevice9_Release(device);
7264 goto done;
7267 hr = IDirect3D9_GetAdapterIdentifier(d3d, D3DADAPTER_DEFAULT, 0, &identifier);
7268 ok(SUCCEEDED(hr), "Failed to get adapter identifier, hr %#x.\n", hr);
7269 warp = !strcmp(identifier.Description, "Microsoft Basic Render Driver");
7271 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_twotexcrd, &decl_twotexcrd);
7272 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
7273 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_onetexcrd, &decl_onetexcrd);
7274 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
7275 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_twotexcrd_wrongidx, &decl_twotex_wrongidx);
7276 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
7277 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_twotexcrd_rightorder, &decl_twotexcrd_rightorder);
7278 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
7280 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_texcoord_color, &decl_texcoord_color);
7281 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
7282 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_color_color, &decl_color_color);
7283 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
7284 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_color_ubyte, &decl_color_ubyte);
7285 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
7286 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_color_float, &decl_color_float);
7287 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr);
7289 hr = IDirect3DDevice9_CreatePixelShader(device, ps3_code, &ps);
7290 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr);
7292 for (i = 1; i <= 3; ++i)
7294 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 1.0f, 0);
7295 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear returned %#x.\n", hr);
7296 if(i == 3) {
7297 hr = IDirect3DDevice9_CreateVertexShader(device, swapped_shader_code_3, &swapped_shader);
7298 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
7299 hr = IDirect3DDevice9_SetPixelShader(device, ps);
7300 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader returned %08x\n", hr);
7301 } else if(i == 2){
7302 hr = IDirect3DDevice9_CreateVertexShader(device, swapped_shader_code_2, &swapped_shader);
7303 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
7304 } else if(i == 1) {
7305 hr = IDirect3DDevice9_CreateVertexShader(device, swapped_shader_code_1, &swapped_shader);
7306 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
7309 hr = IDirect3DDevice9_BeginScene(device);
7310 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
7312 hr = IDirect3DDevice9_SetVertexShader(device, swapped_shader);
7313 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
7315 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl_twotexcrd);
7316 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
7317 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(float) * 11);
7318 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7320 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl_onetexcrd);
7321 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
7322 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(float) * 11);
7323 if (i == 3 || i == 2)
7324 ok(SUCCEEDED(hr), "Failed to draw, i %u, hr %#x.\n", i, hr);
7325 else if (i == 1)
7326 /* Succeeds or fails, depending on SW or HW vertex processing. */
7327 ok(hr == D3DERR_INVALIDCALL || hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7329 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl_twotexcrd_rightorder);
7330 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
7331 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, sizeof(float) * 11);
7332 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7334 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl_twotex_wrongidx);
7335 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
7336 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, sizeof(float) * 11);
7337 if (i == 3 || i == 2)
7338 ok(SUCCEEDED(hr), "Failed to draw, i %u, hr %#x.\n", i, hr);
7339 else if (i == 1)
7340 ok(hr == D3DERR_INVALIDCALL || hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7342 hr = IDirect3DDevice9_EndScene(device);
7343 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
7345 if(i == 3 || i == 2) {
7346 color = getPixelColor(device, 160, 360);
7347 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x80), 1),
7348 "Input test: Quad 1(2crd) returned color 0x%08x, expected 0x00ffff80\n", color);
7350 /* The last value of the read but undefined stream is used, it is 0x00. The defined input is vec4(1, 0, 0, 0) */
7351 color = getPixelColor(device, 480, 360);
7352 /* On the Windows 8 testbot (WARP) the draw succeeds, but uses
7353 * mostly random data as input. */
7354 ok(color == 0x00ffff00 || color == 0x00ff0000 || broken(warp),
7355 "Got unexpected color 0x%08x for quad 2 (1crd).\n", color);
7356 color = getPixelColor(device, 160, 120);
7357 /* Same as above, accept both the last used value and 0.0 for the undefined streams */
7358 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x80), 1) || color == D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x00),
7359 "Input test: Quad 3(2crd-wrongidx) returned color 0x%08x, expected 0x00ff0080\n", color);
7361 color = getPixelColor(device, 480, 160);
7362 ok(color == 0x00000000, "Input test: Quad 4(2crd-rightorder) returned color 0x%08x, expected 0x00000000\n", color);
7363 } else if(i == 1) {
7364 color = getPixelColor(device, 160, 360);
7365 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x80), 1),
7366 "Input test: Quad 1(2crd) returned color 0x%08x, expected 0x00ffff80\n", color);
7367 color = getPixelColor(device, 480, 360);
7368 /* Accept the clear color as well in this case, since SW VP
7369 * returns an error. On the Windows 8 testbot (WARP) the draw
7370 * succeeds, but uses mostly random data as input. */
7371 ok(color == 0x00ffff00 || color == 0x00ff0000 || broken(warp),
7372 "Got unexpected color 0x%08x for quad 2 (1crd).\n", color);
7373 color = getPixelColor(device, 160, 120);
7374 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x80), 1) || color == D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x00),
7375 "Input test: Quad 3(2crd-wrongidx) returned color 0x%08x, expected 0x00ff0080\n", color);
7376 color = getPixelColor(device, 480, 160);
7377 ok(color == 0x00000000, "Input test: Quad 4(2crd-rightorder) returned color 0x%08x, expected 0x00000000\n", color);
7380 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
7381 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
7383 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff808080, 0.0, 0);
7384 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
7386 /* Now find out if the whole streams are re-read, or just the last
7387 * active value for the vertices is used. */
7388 hr = IDirect3DDevice9_BeginScene(device);
7389 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
7391 hr = IDirect3DDevice9_SetVertexShader(device, swapped_shader);
7392 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
7394 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl_twotexcrd);
7395 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
7396 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 3, quad1_modified, sizeof(float) * 11);
7397 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7399 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl_onetexcrd);
7400 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
7401 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2_modified, sizeof(float) * 11);
7402 if (i == 3 || i == 2)
7403 ok(SUCCEEDED(hr), "Failed to draw, i %u, hr %#x.\n", i, hr);
7404 else if (i == 1)
7405 /* Succeeds or fails, depending on SW or HW vertex processing. */
7406 ok(hr == D3DERR_INVALIDCALL || hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7408 hr = IDirect3DDevice9_EndScene(device);
7409 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
7411 color = getPixelColor(device, 480, 350);
7412 /* vs_1_1 may fail, accept the clear color. Some drivers also set the undefined streams to 0, accept that
7413 * as well.
7415 * NOTE: This test fails on the reference rasterizer. In the refrast, the 4 vertices have different colors,
7416 * i.e., the whole old stream is read, and not just the last used attribute. Some games require that this
7417 * does *not* happen, otherwise they can crash because of a read from a bad pointer, so do not accept the
7418 * refrast's result.
7420 * A test app for this behavior is Half Life 2 Episode 2 in dxlevel 95, and related games(Portal, TF2).
7422 ok(color == 0x000000ff || color == 0x00808080 || color == 0x00000000
7423 || broken(color_match(color, D3DCOLOR_ARGB(0x00, 0x0b, 0x75, 0x80), 1)),
7424 "Got unexpected color 0x%08x for quad 2 (different colors).\n", color);
7426 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
7427 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
7429 IDirect3DDevice9_SetVertexShader(device, NULL);
7430 IDirect3DDevice9_SetPixelShader(device, NULL);
7431 IDirect3DDevice9_SetVertexDeclaration(device, NULL);
7433 IDirect3DVertexShader9_Release(swapped_shader);
7436 for (i = 1; i <= 3; ++i)
7438 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
7439 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear returned %#x.\n", hr);
7440 if(i == 3) {
7441 hr = IDirect3DDevice9_CreateVertexShader(device, texcoord_color_shader_code_3, &texcoord_color_shader);
7442 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
7443 hr = IDirect3DDevice9_CreateVertexShader(device, color_color_shader_code_3, &color_color_shader);
7444 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
7445 hr = IDirect3DDevice9_SetPixelShader(device, ps);
7446 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader returned %08x\n", hr);
7447 } else if(i == 2){
7448 hr = IDirect3DDevice9_CreateVertexShader(device, texcoord_color_shader_code_2, &texcoord_color_shader);
7449 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
7450 hr = IDirect3DDevice9_CreateVertexShader(device, color_color_shader_code_2, &color_color_shader);
7451 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
7452 } else if(i == 1) {
7453 hr = IDirect3DDevice9_CreateVertexShader(device, texcoord_color_shader_code_1, &texcoord_color_shader);
7454 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
7455 hr = IDirect3DDevice9_CreateVertexShader(device, color_color_shader_code_1, &color_color_shader);
7456 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
7459 hr = IDirect3DDevice9_BeginScene(device);
7460 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
7462 hr = IDirect3DDevice9_SetVertexShader(device, texcoord_color_shader);
7463 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
7464 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl_texcoord_color);
7465 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
7466 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1_color, sizeof(quad1_color[0]));
7467 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7469 hr = IDirect3DDevice9_SetVertexShader(device, color_color_shader);
7470 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
7472 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 0, normalize, 1);
7473 ok(SUCCEEDED(hr), "Failed to set vertex shader constant, hr %#x.\n", hr);
7474 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl_color_ubyte);
7475 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
7476 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2_color, sizeof(quad2_color[0]));
7477 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7479 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 0, no_normalize, 1);
7480 ok(SUCCEEDED(hr), "Failed to set vertex shader constant, hr %#x.\n", hr);
7481 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl_color_color);
7482 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
7483 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3_color, sizeof(quad3_color[0]));
7484 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7486 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl_color_float);
7487 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
7488 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4_color, sizeof(float) * 7);
7489 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7491 hr = IDirect3DDevice9_EndScene(device);
7492 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
7494 IDirect3DDevice9_SetVertexShader(device, NULL);
7495 IDirect3DDevice9_SetVertexDeclaration(device, NULL);
7496 IDirect3DDevice9_SetPixelShader(device, NULL);
7498 color = getPixelColor(device, 160, 360);
7499 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xff, 0x80, 0x40), 1),
7500 "Input test: Quad 1(color-texcoord) returned color 0x%08x, expected 0x00ff8040\n", color);
7501 color = getPixelColor(device, 480, 360);
7502 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x40, 0x80, 0xff), 1),
7503 "Input test: Quad 2(color-ubyte) returned color 0x%08x, expected 0x004080ff\n", color);
7504 color = getPixelColor(device, 160, 120);
7505 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xff, 0x80, 0x40), 1),
7506 "Input test: Quad 3(color-color) returned color 0x%08x, expected 0x00ff8040\n", color);
7507 color = getPixelColor(device, 480, 160);
7508 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x00), 1),
7509 "Input test: Quad 4(color-float) returned color 0x%08x, expected 0x00ffff00\n", color);
7511 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
7512 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
7514 IDirect3DVertexShader9_Release(texcoord_color_shader);
7515 IDirect3DVertexShader9_Release(color_color_shader);
7518 IDirect3DVertexDeclaration9_Release(decl_twotexcrd);
7519 IDirect3DVertexDeclaration9_Release(decl_onetexcrd);
7520 IDirect3DVertexDeclaration9_Release(decl_twotex_wrongidx);
7521 IDirect3DVertexDeclaration9_Release(decl_twotexcrd_rightorder);
7523 IDirect3DVertexDeclaration9_Release(decl_texcoord_color);
7524 IDirect3DVertexDeclaration9_Release(decl_color_color);
7525 IDirect3DVertexDeclaration9_Release(decl_color_ubyte);
7526 IDirect3DVertexDeclaration9_Release(decl_color_float);
7528 IDirect3DPixelShader9_Release(ps);
7529 refcount = IDirect3DDevice9_Release(device);
7530 ok(!refcount, "Device has %u references left.\n", refcount);
7531 done:
7532 IDirect3D9_Release(d3d);
7533 DestroyWindow(window);
7536 static void srgbtexture_test(void)
7538 /* Fill a texture with 0x7f (~ .5), and then turn on the D3DSAMP_SRGBTEXTURE
7539 * texture stage state to render a quad using that texture. The resulting
7540 * color components should be 0x36 (~ 0.21), per this formula:
7541 * linear_color = ((srgb_color + 0.055) / 1.055) ^ 2.4
7542 * This is true where srgb_color > 0.04045. */
7543 struct IDirect3DTexture9 *texture;
7544 struct IDirect3DSurface9 *surface;
7545 IDirect3DDevice9 *device;
7546 IDirect3D9 *d3d;
7547 D3DCOLOR color;
7548 ULONG refcount;
7549 HWND window;
7550 HRESULT hr;
7552 static const float quad[] =
7554 -1.0f, -1.0f, 0.0f, 0.0f, 1.0f,
7555 -1.0f, 1.0f, 0.0f, 0.0f, 0.0f,
7556 1.0f, -1.0f, 0.0f, 1.0f, 1.0f,
7557 1.0f, 1.0f, 0.0f, 1.0f, 0.0f,
7560 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7561 0, 0, 640, 480, NULL, NULL, NULL, NULL);
7562 d3d = Direct3DCreate9(D3D_SDK_VERSION);
7563 ok(!!d3d, "Failed to create a D3D object.\n");
7564 if (!(device = create_device(d3d, window, window, TRUE)))
7566 skip("Failed to create a D3D device, skipping tests.\n");
7567 goto done;
7570 if (IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL,
7571 D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_SRGBREAD, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8) != D3D_OK)
7573 skip("D3DFMT_A8R8G8B8 textures with SRGBREAD not supported.\n");
7574 IDirect3DDevice9_Release(device);
7575 goto done;
7578 hr = IDirect3DDevice9_CreateTexture(device, 16, 16, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture, NULL);
7579 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7580 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
7581 ok(hr == D3D_OK, "IDirect3DTexture9_GetSurfaceLevel failed with %08x\n", hr);
7583 fill_surface(surface, 0xff7f7f7f, 0);
7584 IDirect3DSurface9_Release(surface);
7586 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
7587 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
7588 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) texture);
7589 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture failed with %08x\n", hr);
7591 hr = IDirect3DDevice9_BeginScene(device);
7592 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
7594 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, TRUE);
7595 ok(SUCCEEDED(hr), "Failed to set sampler state, hr %#x.\n", hr);
7596 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
7597 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
7598 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
7599 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7601 hr = IDirect3DDevice9_EndScene(device);
7602 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
7604 color = getPixelColor(device, 320, 240);
7605 ok(color_match(color, 0x00363636, 1), "sRGB quad has color 0x%08x, expected 0x00363636.\n", color);
7607 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
7608 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
7610 IDirect3DTexture9_Release(texture);
7611 refcount = IDirect3DDevice9_Release(device);
7612 ok(!refcount, "Device has %u references left.\n", refcount);
7613 done:
7614 IDirect3D9_Release(d3d);
7615 DestroyWindow(window);
7618 static void shademode_test(void)
7620 /* Render a quad and try all of the different fixed function shading models. */
7621 DWORD color0_gouraud = 0, color1_gouraud = 0;
7622 DWORD primtype = D3DPT_TRIANGLESTRIP;
7623 IDirect3DVertexBuffer9 *vb_strip;
7624 IDirect3DVertexBuffer9 *vb_list;
7625 DWORD shademode = D3DSHADE_FLAT;
7626 IDirect3DDevice9 *device;
7627 DWORD color0, color1;
7628 void *data = NULL;
7629 IDirect3D9 *d3d;
7630 ULONG refcount;
7631 HWND window;
7632 HRESULT hr;
7633 UINT i, j;
7635 static const struct
7637 struct vec3 position;
7638 DWORD diffuse;
7640 quad_strip[] =
7642 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
7643 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
7644 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
7645 {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
7647 quad_list[] =
7649 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
7650 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
7651 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
7653 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
7654 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
7655 {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
7658 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7659 0, 0, 640, 480, NULL, NULL, NULL, NULL);
7660 d3d = Direct3DCreate9(D3D_SDK_VERSION);
7661 ok(!!d3d, "Failed to create a D3D object.\n");
7662 if (!(device = create_device(d3d, window, window, TRUE)))
7664 skip("Failed to create a D3D device, skipping tests.\n");
7665 goto done;
7668 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
7669 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
7671 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
7672 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
7674 hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(quad_strip), 0, 0, D3DPOOL_MANAGED, &vb_strip, NULL);
7675 ok(hr == D3D_OK, "CreateVertexBuffer failed with %08x\n", hr);
7676 hr = IDirect3DVertexBuffer9_Lock(vb_strip, 0, sizeof(quad_strip), &data, 0);
7677 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr);
7678 memcpy(data, quad_strip, sizeof(quad_strip));
7679 hr = IDirect3DVertexBuffer9_Unlock(vb_strip);
7680 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed with %08x\n", hr);
7682 hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(quad_list), 0, 0, D3DPOOL_MANAGED, &vb_list, NULL);
7683 ok(hr == D3D_OK, "CreateVertexBuffer failed with %08x\n", hr);
7684 hr = IDirect3DVertexBuffer9_Lock(vb_list, 0, sizeof(quad_list), &data, 0);
7685 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr);
7686 memcpy(data, quad_list, sizeof(quad_list));
7687 hr = IDirect3DVertexBuffer9_Unlock(vb_list);
7688 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed with %08x\n", hr);
7690 /* Try it first with a TRIANGLESTRIP. Do it with different geometry because
7691 * the color fixups we have to do for FLAT shading will be dependent on that. */
7692 hr = IDirect3DDevice9_SetStreamSource(device, 0, vb_strip, 0, sizeof(quad_strip[0]));
7693 ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSource failed with %08x\n", hr);
7695 /* First loop uses a TRIANGLESTRIP geometry, 2nd uses a TRIANGLELIST */
7696 for (j=0; j<2; j++) {
7698 /* Inner loop just changes the D3DRS_SHADEMODE */
7699 for (i=0; i<3; i++) {
7700 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
7701 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
7703 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SHADEMODE, shademode);
7704 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
7706 hr = IDirect3DDevice9_BeginScene(device);
7707 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
7708 hr = IDirect3DDevice9_DrawPrimitive(device, primtype, 0, 2);
7709 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7710 hr = IDirect3DDevice9_EndScene(device);
7711 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
7713 /* Sample two spots from the output */
7714 color0 = getPixelColor(device, 100, 100); /* Inside first triangle */
7715 color1 = getPixelColor(device, 500, 350); /* Inside second triangle */
7716 switch(shademode) {
7717 case D3DSHADE_FLAT:
7718 /* Should take the color of the first vertex of each triangle */
7719 if (0)
7721 /* This test depends on EXT_provoking_vertex being
7722 * available. This extension is currently (20090810)
7723 * not common enough to let the test fail if it isn't
7724 * present. */
7725 ok(color0 == 0x00ff0000, "FLAT shading has color0 %08x, expected 0x00ff0000\n", color0);
7726 ok(color1 == 0x0000ff00, "FLAT shading has color1 %08x, expected 0x0000ff00\n", color1);
7728 shademode = D3DSHADE_GOURAUD;
7729 break;
7730 case D3DSHADE_GOURAUD:
7731 /* Should be an interpolated blend */
7733 ok(color_match(color0, D3DCOLOR_ARGB(0x00, 0x0d, 0xca, 0x28), 2),
7734 "GOURAUD shading has color0 %08x, expected 0x00dca28\n", color0);
7735 ok(color_match(color1, D3DCOLOR_ARGB(0x00, 0x0d, 0x45, 0xc7), 2),
7736 "GOURAUD shading has color1 %08x, expected 0x000d45c7\n", color1);
7738 color0_gouraud = color0;
7739 color1_gouraud = color1;
7741 shademode = D3DSHADE_PHONG;
7742 break;
7743 case D3DSHADE_PHONG:
7744 /* Should be the same as GOURAUD, since no hardware implements this */
7745 ok(color_match(color0, D3DCOLOR_ARGB(0x00, 0x0d, 0xca, 0x28), 2),
7746 "PHONG shading has color0 %08x, expected 0x000dca28\n", color0);
7747 ok(color_match(color1, D3DCOLOR_ARGB(0x00, 0x0d, 0x45, 0xc7), 2),
7748 "PHONG shading has color1 %08x, expected 0x000d45c7\n", color1);
7750 ok(color0 == color0_gouraud, "difference between GOURAUD and PHONG shading detected: %08x %08x\n",
7751 color0_gouraud, color0);
7752 ok(color1 == color1_gouraud, "difference between GOURAUD and PHONG shading detected: %08x %08x\n",
7753 color1_gouraud, color1);
7754 break;
7758 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
7759 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
7761 /* Now, do it all over again with a TRIANGLELIST */
7762 hr = IDirect3DDevice9_SetStreamSource(device, 0, vb_list, 0, sizeof(quad_list[0]));
7763 ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSource failed with %08x\n", hr);
7764 primtype = D3DPT_TRIANGLELIST;
7765 shademode = D3DSHADE_FLAT;
7768 IDirect3DVertexBuffer9_Release(vb_strip);
7769 IDirect3DVertexBuffer9_Release(vb_list);
7770 refcount = IDirect3DDevice9_Release(device);
7771 ok(!refcount, "Device has %u references left.\n", refcount);
7772 done:
7773 IDirect3D9_Release(d3d);
7774 DestroyWindow(window);
7777 static void test_blend(void)
7779 IDirect3DSurface9 *backbuffer, *offscreen;
7780 IDirect3DTexture9 *offscreenTexture;
7781 IDirect3DDevice9 *device;
7782 IDirect3D9 *d3d;
7783 D3DCOLOR color;
7784 ULONG refcount;
7785 HWND window;
7786 HRESULT hr;
7788 static const struct
7790 struct vec3 position;
7791 DWORD diffuse;
7793 quad1[] =
7795 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
7796 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
7797 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
7798 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
7800 quad2[] =
7802 {{-1.0f, 0.0f, 0.1f}, 0xc00000ff},
7803 {{-1.0f, 1.0f, 0.1f}, 0xc00000ff},
7804 {{ 1.0f, 0.0f, 0.1f}, 0xc00000ff},
7805 {{ 1.0f, 1.0f, 0.1f}, 0xc00000ff},
7807 static const float composite_quad[][5] =
7809 { 0.0f, -1.0f, 0.1f, 0.0f, 1.0f},
7810 { 0.0f, 1.0f, 0.1f, 0.0f, 0.0f},
7811 { 1.0f, -1.0f, 0.1f, 1.0f, 1.0f},
7812 { 1.0f, 1.0f, 0.1f, 1.0f, 0.0f},
7815 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7816 0, 0, 640, 480, NULL, NULL, NULL, NULL);
7817 d3d = Direct3DCreate9(D3D_SDK_VERSION);
7818 ok(!!d3d, "Failed to create a D3D object.\n");
7819 if (!(device = create_device(d3d, window, window, TRUE)))
7821 skip("Failed to create a D3D device, skipping tests.\n");
7822 goto done;
7825 /* Clear the render target with alpha = 0.5 */
7826 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x80ff0000, 1.0f, 0);
7827 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
7829 hr = IDirect3DDevice9_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET,
7830 D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &offscreenTexture, NULL);
7831 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7833 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
7834 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
7836 hr = IDirect3DTexture9_GetSurfaceLevel(offscreenTexture, 0, &offscreen);
7837 ok(hr == D3D_OK, "Can't get offscreen surface, hr = %08x\n", hr);
7839 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
7840 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed, hr = %#08x\n", hr);
7842 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
7843 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
7844 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
7845 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
7846 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
7847 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_MINFILTER failed (0x%08x)\n", hr);
7848 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
7849 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr);
7850 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
7851 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
7853 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHABLENDENABLE, TRUE);
7854 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed, hr = %08x\n", hr);
7855 hr = IDirect3DDevice9_BeginScene(device);
7856 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
7858 /* Draw two quads, one with src alpha blending, one with dest alpha
7859 * blending. */
7860 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
7861 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
7862 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
7863 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
7864 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(quad1[0]));
7865 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7867 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_DESTALPHA);
7868 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
7869 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVDESTALPHA);
7870 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
7871 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(quad2[0]));
7872 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7874 /* Switch to the offscreen buffer, and redo the testing. The offscreen
7875 * render target doesn't have an alpha channel. DESTALPHA and INVDESTALPHA
7876 * "don't work" on render targets without alpha channel, they give
7877 * essentially ZERO and ONE blend factors. */
7878 hr = IDirect3DDevice9_SetRenderTarget(device, 0, offscreen);
7879 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
7880 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x80ff0000, 1.0f, 0);
7881 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
7883 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
7884 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
7885 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
7886 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
7887 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(quad1[0]));
7888 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7890 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_DESTALPHA);
7891 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
7892 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVDESTALPHA);
7893 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
7894 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(quad2[0]));
7895 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7897 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
7898 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
7900 /* Render the offscreen texture onto the frame buffer to be able to
7901 * compare it regularly. Disable alpha blending for the final
7902 * composition. */
7903 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHABLENDENABLE, FALSE);
7904 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
7905 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
7906 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
7908 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) offscreenTexture);
7909 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
7910 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, composite_quad, sizeof(float) * 5);
7911 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7913 hr = IDirect3DDevice9_EndScene(device);
7914 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
7916 color = getPixelColor(device, 160, 360);
7917 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xbf, 0x40, 0x00), 1),
7918 "SRCALPHA on frame buffer returned color %08x, expected 0x00bf4000\n", color);
7920 color = getPixelColor(device, 160, 120);
7921 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x7f, 0x00, 0x80), 2),
7922 "DSTALPHA on frame buffer returned color %08x, expected 0x007f0080\n", color);
7924 color = getPixelColor(device, 480, 360);
7925 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xbf, 0x40, 0x00), 1),
7926 "SRCALPHA on texture returned color %08x, expected 0x00bf4000\n", color);
7928 color = getPixelColor(device, 480, 120);
7929 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0xff), 1),
7930 "DSTALPHA on texture returned color %08x, expected 0x000000ff\n", color);
7932 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
7934 IDirect3DSurface9_Release(backbuffer);
7935 IDirect3DTexture9_Release(offscreenTexture);
7936 IDirect3DSurface9_Release(offscreen);
7937 refcount = IDirect3DDevice9_Release(device);
7938 ok(!refcount, "Device has %u references left.\n", refcount);
7939 done:
7940 IDirect3D9_Release(d3d);
7941 DestroyWindow(window);
7944 static void fixed_function_decl_test(void)
7946 IDirect3DVertexDeclaration9 *dcl_float = NULL, *dcl_short = NULL, *dcl_ubyte = NULL, *dcl_color = NULL;
7947 IDirect3DVertexDeclaration9 *dcl_color_2 = NULL, *dcl_ubyte_2 = NULL, *dcl_positiont;
7948 IDirect3DVertexBuffer9 *vb, *vb2;
7949 IDirect3DDevice9 *device;
7950 BOOL s_ok, ub_ok, f_ok;
7951 DWORD color, size, i;
7952 IDirect3D9 *d3d;
7953 ULONG refcount;
7954 D3DCAPS9 caps;
7955 HWND window;
7956 void *data;
7957 HRESULT hr;
7959 static const D3DVERTEXELEMENT9 decl_elements_d3dcolor[] = {
7960 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7961 {0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
7962 D3DDECL_END()
7964 static const D3DVERTEXELEMENT9 decl_elements_d3dcolor_2streams[] = {
7965 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7966 {1, 0, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
7967 D3DDECL_END()
7969 static const D3DVERTEXELEMENT9 decl_elements_ubyte4n[] = {
7970 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7971 {0, 12, D3DDECLTYPE_UBYTE4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
7972 D3DDECL_END()
7974 static const D3DVERTEXELEMENT9 decl_elements_ubyte4n_2streams[] = {
7975 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7976 {1, 0, D3DDECLTYPE_UBYTE4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
7977 D3DDECL_END()
7979 static const D3DVERTEXELEMENT9 decl_elements_short4[] = {
7980 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7981 {0, 12, D3DDECLTYPE_USHORT4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
7982 D3DDECL_END()
7984 static const D3DVERTEXELEMENT9 decl_elements_float[] = {
7985 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7986 {0, 12, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
7987 D3DDECL_END()
7989 static const D3DVERTEXELEMENT9 decl_elements_positiont[] = {
7990 {0, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITIONT, 0},
7991 {0, 16, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
7992 D3DDECL_END()
7994 static const struct
7996 struct vec3 position;
7997 DWORD diffuse;
7999 quad1[] = /* D3DCOLOR */
8001 {{-1.0f, -1.0f, 0.1f}, 0x00ffff00},
8002 {{-1.0f, 0.0f, 0.1f}, 0x00ffff00},
8003 {{ 0.0f, -1.0f, 0.1f}, 0x00ffff00},
8004 {{ 0.0f, 0.0f, 0.1f}, 0x00ffff00},
8006 quad2[] = /* UBYTE4N */
8008 {{-1.0f, 0.0f, 0.1f}, 0x00ffff00},
8009 {{-1.0f, 1.0f, 0.1f}, 0x00ffff00},
8010 {{ 0.0f, 0.0f, 0.1f}, 0x00ffff00},
8011 {{ 0.0f, 1.0f, 0.1f}, 0x00ffff00},
8013 static const struct
8015 struct vec3 position;
8016 struct { unsigned short x, y, z, w; } color;
8018 quad3[] = /* USHORT4N */
8020 {{0.0f, -1.0f, 0.1f}, {0x0000, 0x0000, 0xffff, 0xffff}},
8021 {{0.0f, 0.0f, 0.1f}, {0x0000, 0x0000, 0xffff, 0xffff}},
8022 {{1.0f, -1.0f, 0.1f}, {0x0000, 0x0000, 0xffff, 0xffff}},
8023 {{1.0f, 0.0f, 0.1f}, {0x0000, 0x0000, 0xffff, 0xffff}},
8025 static const struct
8027 struct vec3 position;
8028 struct vec4 color;
8030 quad4[] =
8032 {{0.0f, 0.0f, 0.1f}, {1.0f, 0.0f, 0.0f, 0.0f}},
8033 {{0.0f, 1.0f, 0.1f}, {1.0f, 0.0f, 0.0f, 0.0f}},
8034 {{1.0f, 0.0f, 0.1f}, {1.0f, 0.0f, 0.0f, 0.0f}},
8035 {{1.0f, 1.0f, 0.1f}, {1.0f, 0.0f, 0.0f, 0.0f}},
8037 static const DWORD colors[] =
8039 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8040 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8041 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8042 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8043 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8044 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8045 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8046 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8047 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8048 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8049 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8050 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8051 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8052 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8053 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8054 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
8056 static const float quads[] =
8058 -1.0f, -1.0f, 0.1f,
8059 -1.0f, 0.0f, 0.1f,
8060 0.0f, -1.0f, 0.1f,
8061 0.0f, 0.0f, 0.1f,
8063 0.0f, -1.0f, 0.1f,
8064 0.0f, 0.0f, 0.1f,
8065 1.0f, -1.0f, 0.1f,
8066 1.0f, 0.0f, 0.1f,
8068 0.0f, 0.0f, 0.1f,
8069 0.0f, 1.0f, 0.1f,
8070 1.0f, 0.0f, 0.1f,
8071 1.0f, 1.0f, 0.1f,
8073 -1.0f, 0.0f, 0.1f,
8074 -1.0f, 1.0f, 0.1f,
8075 0.0f, 0.0f, 0.1f,
8076 0.0f, 1.0f, 0.1f,
8078 static const struct
8080 struct vec4 position;
8081 DWORD diffuse;
8083 quad_transformed[] =
8085 {{ 90.0f, 110.0f, 0.1f, 2.0f}, 0x00ffff00},
8086 {{570.0f, 110.0f, 0.1f, 2.0f}, 0x00ffff00},
8087 {{ 90.0f, 300.0f, 0.1f, 2.0f}, 0x00ffff00},
8088 {{570.0f, 300.0f, 0.1f, 2.0f}, 0x00ffff00},
8091 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8092 0, 0, 640, 480, NULL, NULL, NULL, NULL);
8093 d3d = Direct3DCreate9(D3D_SDK_VERSION);
8094 ok(!!d3d, "Failed to create a D3D object.\n");
8095 if (!(device = create_device(d3d, window, window, TRUE)))
8097 skip("Failed to create a D3D device, skipping tests.\n");
8098 goto done;
8101 memset(&caps, 0, sizeof(caps));
8102 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
8103 ok(hr == D3D_OK, "GetDeviceCaps failed, hr = %08x\n", hr);
8105 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
8106 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
8108 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_d3dcolor, &dcl_color);
8109 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (%08x)\n", hr);
8110 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_short4, &dcl_short);
8111 ok(SUCCEEDED(hr) || hr == E_FAIL, "CreateVertexDeclaration failed (%08x)\n", hr);
8112 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_float, &dcl_float);
8113 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (%08x)\n", hr);
8114 if(caps.DeclTypes & D3DDTCAPS_UBYTE4N) {
8115 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_ubyte4n_2streams, &dcl_ubyte_2);
8116 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (%08x)\n", hr);
8117 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_ubyte4n, &dcl_ubyte);
8118 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (%08x)\n", hr);
8119 } else {
8120 trace("D3DDTCAPS_UBYTE4N not supported\n");
8121 dcl_ubyte_2 = NULL;
8122 dcl_ubyte = NULL;
8124 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_d3dcolor_2streams, &dcl_color_2);
8125 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (%08x)\n", hr);
8126 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements_positiont, &dcl_positiont);
8127 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (%08x)\n", hr);
8129 size = max(sizeof(quad1), max(sizeof(quad2), max(sizeof(quad3), max(sizeof(quad4), sizeof(quads)))));
8130 hr = IDirect3DDevice9_CreateVertexBuffer(device, size,
8131 0, 0, D3DPOOL_MANAGED, &vb, NULL);
8132 ok(hr == D3D_OK, "CreateVertexBuffer failed with %08x\n", hr);
8134 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
8135 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
8137 hr = IDirect3DDevice9_BeginScene(device);
8138 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8140 f_ok = FALSE; s_ok = FALSE; ub_ok = FALSE;
8141 if (dcl_color)
8143 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_color);
8144 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8145 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(quad1[0]));
8146 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8149 /* Tests with non-standard fixed function types fail on the refrast. The
8150 * ATI driver partially accepts them, the NVIDIA driver accepts them all.
8151 * All those differences even though we're using software vertex
8152 * processing. Doh! */
8153 if (dcl_ubyte)
8155 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_ubyte);
8156 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8157 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(quad2[0]));
8158 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8159 ub_ok = SUCCEEDED(hr);
8162 if (dcl_short)
8164 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_short);
8165 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8166 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, sizeof(quad3[0]));
8167 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8168 s_ok = SUCCEEDED(hr);
8171 if (dcl_float)
8173 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_float);
8174 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8175 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, sizeof(quad4[0]));
8176 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8177 f_ok = SUCCEEDED(hr);
8180 hr = IDirect3DDevice9_EndScene(device);
8181 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8183 if(dcl_short) {
8184 color = getPixelColor(device, 480, 360);
8185 ok(color == 0x000000ff || !s_ok,
8186 "D3DDECLTYPE_USHORT4N returned color %08x, expected 0x000000ff\n", color);
8188 if(dcl_ubyte) {
8189 color = getPixelColor(device, 160, 120);
8190 ok(color == 0x0000ffff || !ub_ok,
8191 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x0000ffff\n", color);
8193 if(dcl_color) {
8194 color = getPixelColor(device, 160, 360);
8195 ok(color == 0x00ffff00,
8196 "D3DDECLTYPE_D3DCOLOR returned color %08x, expected 0x00ffff00\n", color);
8198 if(dcl_float) {
8199 color = getPixelColor(device, 480, 120);
8200 ok(color == 0x00ff0000 || !f_ok,
8201 "D3DDECLTYPE_FLOAT4 returned color %08x, expected 0x00ff0000\n", color);
8203 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
8205 /* The following test with vertex buffers doesn't serve to find out new
8206 * information from windows. It is a plain regression test because wined3d
8207 * uses different codepaths for attribute conversion with vertex buffers.
8208 * It makes sure that the vertex buffer one works, while the above tests
8209 * whether the immediate mode code works. */
8210 f_ok = FALSE; s_ok = FALSE; ub_ok = FALSE;
8211 hr = IDirect3DDevice9_BeginScene(device);
8212 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8214 if (dcl_color)
8216 hr = IDirect3DVertexBuffer9_Lock(vb, 0, sizeof(quad1), &data, 0);
8217 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8218 memcpy(data, quad1, sizeof(quad1));
8219 hr = IDirect3DVertexBuffer9_Unlock(vb);
8220 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8221 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_color);
8222 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8223 hr = IDirect3DDevice9_SetStreamSource(device, 0, vb, 0, sizeof(quad1[0]));
8224 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
8225 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 2);
8226 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8229 if (dcl_ubyte)
8231 hr = IDirect3DVertexBuffer9_Lock(vb, 0, sizeof(quad2), &data, 0);
8232 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8233 memcpy(data, quad2, sizeof(quad2));
8234 hr = IDirect3DVertexBuffer9_Unlock(vb);
8235 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8236 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_ubyte);
8237 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8238 hr = IDirect3DDevice9_SetStreamSource(device, 0, vb, 0, sizeof(quad2[0]));
8239 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
8240 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 2);
8241 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8242 ub_ok = SUCCEEDED(hr);
8245 if (dcl_short)
8247 hr = IDirect3DVertexBuffer9_Lock(vb, 0, sizeof(quad3), &data, 0);
8248 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8249 memcpy(data, quad3, sizeof(quad3));
8250 hr = IDirect3DVertexBuffer9_Unlock(vb);
8251 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8252 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_short);
8253 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8254 hr = IDirect3DDevice9_SetStreamSource(device, 0, vb, 0, sizeof(quad3[0]));
8255 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
8256 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 2);
8257 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8258 s_ok = SUCCEEDED(hr);
8261 if (dcl_float)
8263 hr = IDirect3DVertexBuffer9_Lock(vb, 0, sizeof(quad4), &data, 0);
8264 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8265 memcpy(data, quad4, sizeof(quad4));
8266 hr = IDirect3DVertexBuffer9_Unlock(vb);
8267 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8268 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_float);
8269 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8270 hr = IDirect3DDevice9_SetStreamSource(device, 0, vb, 0, sizeof(quad4[0]));
8271 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
8272 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 2);
8273 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8274 f_ok = SUCCEEDED(hr);
8277 hr = IDirect3DDevice9_EndScene(device);
8278 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8280 hr = IDirect3DDevice9_SetStreamSource(device, 0, NULL, 0, 0);
8281 ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSource failed with %08x\n", hr);
8282 hr = IDirect3DDevice9_SetVertexDeclaration(device, NULL);
8283 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexDeclaration failed (%08x)\n", hr);
8285 if(dcl_short) {
8286 color = getPixelColor(device, 480, 360);
8287 ok(color == 0x000000ff || !s_ok,
8288 "D3DDECLTYPE_USHORT4N returned color %08x, expected 0x000000ff\n", color);
8290 if(dcl_ubyte) {
8291 color = getPixelColor(device, 160, 120);
8292 ok(color == 0x0000ffff || !ub_ok,
8293 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x0000ffff\n", color);
8295 if(dcl_color) {
8296 color = getPixelColor(device, 160, 360);
8297 ok(color == 0x00ffff00,
8298 "D3DDECLTYPE_D3DCOLOR returned color %08x, expected 0x00ffff00\n", color);
8300 if(dcl_float) {
8301 color = getPixelColor(device, 480, 120);
8302 ok(color == 0x00ff0000 || !f_ok,
8303 "D3DDECLTYPE_FLOAT4 returned color %08x, expected 0x00ff0000\n", color);
8305 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
8307 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0, 0);
8308 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
8310 hr = IDirect3DVertexBuffer9_Lock(vb, 0, sizeof(quad_transformed), &data, 0);
8311 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr);
8312 memcpy(data, quad_transformed, sizeof(quad_transformed));
8313 hr = IDirect3DVertexBuffer9_Unlock(vb);
8314 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed (%08x)\n", hr);
8316 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_positiont);
8317 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexDeclaration failed with %08x\n", hr);
8319 hr = IDirect3DDevice9_BeginScene(device);
8320 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8321 hr = IDirect3DDevice9_SetStreamSource(device, 0, vb, 0, sizeof(quad_transformed[0]));
8322 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
8323 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 2);
8324 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8325 hr = IDirect3DDevice9_EndScene(device);
8326 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8328 color = getPixelColor(device, 88, 108);
8329 ok(color == 0x000000ff,
8330 "pixel 88/108 has color %08x, expected 0x000000ff\n", color);
8331 color = getPixelColor(device, 92, 108);
8332 ok(color == 0x000000ff,
8333 "pixel 92/108 has color %08x, expected 0x000000ff\n", color);
8334 color = getPixelColor(device, 88, 112);
8335 ok(color == 0x000000ff,
8336 "pixel 88/112 has color %08x, expected 0x000000ff\n", color);
8337 color = getPixelColor(device, 92, 112);
8338 ok(color == 0x00ffff00,
8339 "pixel 92/112 has color %08x, expected 0x00ffff00\n", color);
8341 color = getPixelColor(device, 568, 108);
8342 ok(color == 0x000000ff,
8343 "pixel 568/108 has color %08x, expected 0x000000ff\n", color);
8344 color = getPixelColor(device, 572, 108);
8345 ok(color == 0x000000ff,
8346 "pixel 572/108 has color %08x, expected 0x000000ff\n", color);
8347 color = getPixelColor(device, 568, 112);
8348 ok(color == 0x00ffff00,
8349 "pixel 568/112 has color %08x, expected 0x00ffff00\n", color);
8350 color = getPixelColor(device, 572, 112);
8351 ok(color == 0x000000ff,
8352 "pixel 572/112 has color %08x, expected 0x000000ff\n", color);
8354 color = getPixelColor(device, 88, 298);
8355 ok(color == 0x000000ff,
8356 "pixel 88/298 has color %08x, expected 0x000000ff\n", color);
8357 color = getPixelColor(device, 92, 298);
8358 ok(color == 0x00ffff00,
8359 "pixel 92/298 has color %08x, expected 0x00ffff00\n", color);
8360 color = getPixelColor(device, 88, 302);
8361 ok(color == 0x000000ff,
8362 "pixel 88/302 has color %08x, expected 0x000000ff\n", color);
8363 color = getPixelColor(device, 92, 302);
8364 ok(color == 0x000000ff,
8365 "pixel 92/302 has color %08x, expected 0x000000ff\n", color);
8367 color = getPixelColor(device, 568, 298);
8368 ok(color == 0x00ffff00,
8369 "pixel 568/298 has color %08x, expected 0x00ffff00\n", color);
8370 color = getPixelColor(device, 572, 298);
8371 ok(color == 0x000000ff,
8372 "pixel 572/298 has color %08x, expected 0x000000ff\n", color);
8373 color = getPixelColor(device, 568, 302);
8374 ok(color == 0x000000ff,
8375 "pixel 568/302 has color %08x, expected 0x000000ff\n", color);
8376 color = getPixelColor(device, 572, 302);
8377 ok(color == 0x000000ff,
8378 "pixel 572/302 has color %08x, expected 0x000000ff\n", color);
8380 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
8382 /* This test is pointless without those two declarations: */
8383 if((!dcl_color_2) || (!dcl_ubyte_2)) {
8384 skip("color-ubyte switching test declarations aren't supported\n");
8385 goto out;
8388 hr = IDirect3DVertexBuffer9_Lock(vb, 0, sizeof(quads), &data, 0);
8389 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr);
8390 memcpy(data, quads, sizeof(quads));
8391 hr = IDirect3DVertexBuffer9_Unlock(vb);
8392 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed (%08x)\n", hr);
8393 hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(colors),
8394 0, 0, D3DPOOL_MANAGED, &vb2, NULL);
8395 ok(hr == D3D_OK, "CreateVertexBuffer failed with %08x\n", hr);
8396 hr = IDirect3DVertexBuffer9_Lock(vb2, 0, sizeof(colors), &data, 0);
8397 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr);
8398 memcpy(data, colors, sizeof(colors));
8399 hr = IDirect3DVertexBuffer9_Unlock(vb2);
8400 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed (%08x)\n", hr);
8402 for(i = 0; i < 2; i++) {
8403 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
8404 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
8406 hr = IDirect3DDevice9_SetStreamSource(device, 0, vb, 0, sizeof(float) * 3);
8407 ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSource failed with %08x\n", hr);
8408 if(i == 0) {
8409 hr = IDirect3DDevice9_SetStreamSource(device, 1, vb2, 0, sizeof(DWORD) * 4);
8410 } else {
8411 hr = IDirect3DDevice9_SetStreamSource(device, 1, vb2, 8, sizeof(DWORD) * 4);
8413 ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSource failed with %08x\n", hr);
8415 hr = IDirect3DDevice9_BeginScene(device);
8416 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8418 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_ubyte_2);
8419 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8420 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 2);
8421 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8422 ub_ok = SUCCEEDED(hr);
8424 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_color_2);
8425 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8426 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 4, 2);
8427 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8429 hr = IDirect3DDevice9_SetVertexDeclaration(device, dcl_ubyte_2);
8430 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8431 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 8, 2);
8432 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8433 ub_ok = (SUCCEEDED(hr) && ub_ok);
8435 hr = IDirect3DDevice9_EndScene(device);
8436 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8438 if(i == 0) {
8439 color = getPixelColor(device, 480, 360);
8440 ok(color == 0x00ff0000,
8441 "D3DDECLTYPE_D3DCOLOR returned color %08x, expected 0x00ff0000\n", color);
8442 color = getPixelColor(device, 160, 120);
8443 ok(color == 0x00ffffff,
8444 "Unused quad returned color %08x, expected 0x00ffffff\n", color);
8445 color = getPixelColor(device, 160, 360);
8446 ok(color == 0x000000ff || !ub_ok,
8447 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x000000ff\n", color);
8448 color = getPixelColor(device, 480, 120);
8449 ok(color == 0x000000ff || !ub_ok,
8450 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x000000ff\n", color);
8451 } else {
8452 color = getPixelColor(device, 480, 360);
8453 ok(color == 0x000000ff,
8454 "D3DDECLTYPE_D3DCOLOR returned color %08x, expected 0x000000ff\n", color);
8455 color = getPixelColor(device, 160, 120);
8456 ok(color == 0x00ffffff,
8457 "Unused quad returned color %08x, expected 0x00ffffff\n", color);
8458 color = getPixelColor(device, 160, 360);
8459 ok(color == 0x00ff0000 || !ub_ok,
8460 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x00ff0000\n", color);
8461 color = getPixelColor(device, 480, 120);
8462 ok(color == 0x00ff0000 || !ub_ok,
8463 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x00ff0000\n", color);
8465 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
8468 IDirect3DVertexBuffer9_Release(vb2);
8469 out:
8470 IDirect3DVertexBuffer9_Release(vb);
8471 if(dcl_float) IDirect3DVertexDeclaration9_Release(dcl_float);
8472 if(dcl_short) IDirect3DVertexDeclaration9_Release(dcl_short);
8473 if(dcl_ubyte) IDirect3DVertexDeclaration9_Release(dcl_ubyte);
8474 if(dcl_color) IDirect3DVertexDeclaration9_Release(dcl_color);
8475 if(dcl_color_2) IDirect3DVertexDeclaration9_Release(dcl_color_2);
8476 if(dcl_ubyte_2) IDirect3DVertexDeclaration9_Release(dcl_ubyte_2);
8477 if(dcl_positiont) IDirect3DVertexDeclaration9_Release(dcl_positiont);
8478 refcount = IDirect3DDevice9_Release(device);
8479 ok(!refcount, "Device has %u references left.\n", refcount);
8480 done:
8481 IDirect3D9_Release(d3d);
8482 DestroyWindow(window);
8485 static void test_vshader_float16(void)
8487 IDirect3DVertexDeclaration9 *vdecl = NULL;
8488 IDirect3DVertexBuffer9 *buffer = NULL;
8489 IDirect3DVertexShader9 *shader;
8490 IDirect3DDevice9 *device;
8491 IDirect3D9 *d3d;
8492 ULONG refcount;
8493 D3DCAPS9 caps;
8494 DWORD color;
8495 HWND window;
8496 void *data;
8497 HRESULT hr;
8499 static const D3DVERTEXELEMENT9 decl_elements[] =
8501 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
8502 {0, 12, D3DDECLTYPE_FLOAT16_4,D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
8503 D3DDECL_END()
8505 static const DWORD shader_code[] =
8507 0xfffe0101, /* vs_1_1 */
8508 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
8509 0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color v1 */
8510 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
8511 0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
8512 0x0000ffff,
8514 static const struct vertex_float16color
8516 float x, y, z;
8517 DWORD c1, c2;
8519 quad[] =
8521 { -1.0, -1.0, 0.1, 0x3c000000, 0x00000000 }, /* green */
8522 { -1.0, 0.0, 0.1, 0x3c000000, 0x00000000 },
8523 { 0.0, -1.0, 0.1, 0x3c000000, 0x00000000 },
8524 { 0.0, 0.0, 0.1, 0x3c000000, 0x00000000 },
8526 { 0.0, -1.0, 0.1, 0x00003c00, 0x00000000 }, /* red */
8527 { 0.0, 0.0, 0.1, 0x00003c00, 0x00000000 },
8528 { 1.0, -1.0, 0.1, 0x00003c00, 0x00000000 },
8529 { 1.0, 0.0, 0.1, 0x00003c00, 0x00000000 },
8531 { 0.0, 0.0, 0.1, 0x00000000, 0x00003c00 }, /* blue */
8532 { 0.0, 1.0, 0.1, 0x00000000, 0x00003c00 },
8533 { 1.0, 0.0, 0.1, 0x00000000, 0x00003c00 },
8534 { 1.0, 1.0, 0.1, 0x00000000, 0x00003c00 },
8536 { -1.0, 0.0, 0.1, 0x00000000, 0x3c000000 }, /* alpha */
8537 { -1.0, 1.0, 0.1, 0x00000000, 0x3c000000 },
8538 { 0.0, 0.0, 0.1, 0x00000000, 0x3c000000 },
8539 { 0.0, 1.0, 0.1, 0x00000000, 0x3c000000 },
8542 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8543 0, 0, 640, 480, NULL, NULL, NULL, NULL);
8544 d3d = Direct3DCreate9(D3D_SDK_VERSION);
8545 ok(!!d3d, "Failed to create a D3D object.\n");
8546 if (!(device = create_device(d3d, window, window, TRUE)))
8548 skip("Failed to create a D3D device, skipping tests.\n");
8549 goto done;
8552 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
8553 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
8554 if (caps.VertexShaderVersion < D3DVS_VERSION(3, 0))
8556 skip("No vs_3_0 support, skipping tests.\n");
8557 IDirect3DDevice9_Release(device);
8558 goto done;
8561 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff102030, 1.0f, 0);
8562 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr);
8564 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &vdecl);
8565 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateVertexDeclaration failed hr=%08x\n", hr);
8566 hr = IDirect3DDevice9_CreateVertexShader(device, shader_code, &shader);
8567 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateVertexShader failed hr=%08x\n", hr);
8568 hr = IDirect3DDevice9_SetVertexShader(device, shader);
8569 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShader failed hr=%08x\n", hr);
8571 hr = IDirect3DDevice9_BeginScene(device);
8572 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8573 hr = IDirect3DDevice9_SetVertexDeclaration(device, vdecl);
8574 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
8575 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad + 0, sizeof(quad[0]));
8576 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8577 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad + 4, sizeof(quad[0]));
8578 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8579 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad + 8, sizeof(quad[0]));
8580 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8581 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad + 12, sizeof(quad[0]));
8582 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8583 hr = IDirect3DDevice9_EndScene(device);
8584 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8586 color = getPixelColor(device, 480, 360);
8587 ok(color == 0x00ff0000,
8588 "Input 0x00003c00, 0x00000000 returned color %08x, expected 0x00ff0000\n", color);
8589 color = getPixelColor(device, 160, 120);
8590 ok(color == 0x00000000,
8591 "Input 0x00000000, 0x3c000000 returned color %08x, expected 0x00000000\n", color);
8592 color = getPixelColor(device, 160, 360);
8593 ok(color == 0x0000ff00,
8594 "Input 0x3c000000, 0x00000000 returned color %08x, expected 0x0000ff00\n", color);
8595 color = getPixelColor(device, 480, 120);
8596 ok(color == 0x000000ff,
8597 "Input 0x00000000, 0x00003c00 returned color %08x, expected 0x000000ff\n", color);
8598 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
8600 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff102030, 0.0, 0);
8601 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr);
8603 hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(quad), 0, 0,
8604 D3DPOOL_MANAGED, &buffer, NULL);
8605 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexBuffer failed, hr=%08x\n", hr);
8606 hr = IDirect3DVertexBuffer9_Lock(buffer, 0, sizeof(quad), &data, 0);
8607 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed, hr=%08x\n", hr);
8608 memcpy(data, quad, sizeof(quad));
8609 hr = IDirect3DVertexBuffer9_Unlock(buffer);
8610 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed, hr=%08x\n", hr);
8611 hr = IDirect3DDevice9_SetStreamSource(device, 0, buffer, 0, sizeof(quad[0]));
8612 ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSource failed, hr=%08x\n", hr);
8614 hr = IDirect3DDevice9_BeginScene(device);
8615 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8616 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 2);
8617 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8618 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 4, 2);
8619 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8620 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 8, 2);
8621 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8622 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 12, 2);
8623 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8624 hr = IDirect3DDevice9_EndScene(device);
8625 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8627 color = getPixelColor(device, 480, 360);
8628 ok(color == 0x00ff0000,
8629 "Input 0x00003c00, 0x00000000 returned color %08x, expected 0x00ff0000\n", color);
8630 color = getPixelColor(device, 160, 120);
8631 ok(color == 0x00000000,
8632 "Input 0x00000000, 0x3c000000 returned color %08x, expected 0x00000000\n", color);
8633 color = getPixelColor(device, 160, 360);
8634 ok(color == 0x0000ff00,
8635 "Input 0x3c000000, 0x00000000 returned color %08x, expected 0x0000ff00\n", color);
8636 color = getPixelColor(device, 480, 120);
8637 ok(color == 0x000000ff,
8638 "Input 0x00000000, 0x00003c00 returned color %08x, expected 0x000000ff\n", color);
8639 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
8641 IDirect3DVertexDeclaration9_Release(vdecl);
8642 IDirect3DVertexShader9_Release(shader);
8643 IDirect3DVertexBuffer9_Release(buffer);
8644 refcount = IDirect3DDevice9_Release(device);
8645 ok(!refcount, "Device has %u references left.\n", refcount);
8646 done:
8647 IDirect3D9_Release(d3d);
8648 DestroyWindow(window);
8651 static void conditional_np2_repeat_test(void)
8653 IDirect3DTexture9 *texture;
8654 IDirect3DDevice9 *device;
8655 D3DLOCKED_RECT rect;
8656 unsigned int x, y;
8657 DWORD *dst, color;
8658 IDirect3D9 *d3d;
8659 ULONG refcount;
8660 D3DCAPS9 caps;
8661 HWND window;
8662 HRESULT hr;
8664 static const float quad[] =
8666 -1.0f, -1.0f, 0.1f, -0.2f, -0.2f,
8667 -1.0f, 1.0f, 0.1f, -0.2f, 1.2f,
8668 1.0f, -1.0f, 0.1f, 1.2f, -0.2f,
8669 1.0f, 1.0f, 0.1f, 1.2f, 1.2f,
8672 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8673 0, 0, 640, 480, NULL, NULL, NULL, NULL);
8674 d3d = Direct3DCreate9(D3D_SDK_VERSION);
8675 ok(!!d3d, "Failed to create a D3D object.\n");
8676 if (!(device = create_device(d3d, window, window, TRUE)))
8678 skip("Failed to create a D3D device, skipping tests.\n");
8679 goto done;
8682 memset(&caps, 0, sizeof(caps));
8683 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
8684 ok(hr == D3D_OK, "IDirect3DDevice9_GetDeviceCaps failed hr=%08x\n", hr);
8685 if (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)
8687 /* NP2 conditional requires the POW2 flag. Check that while we're at it */
8688 ok(caps.TextureCaps & D3DPTEXTURECAPS_POW2,
8689 "Card has conditional NP2 support without power of two restriction set\n");
8691 else if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
8693 skip("No conditional NP2 support, skipping conditional NP2 tests\n");
8694 IDirect3DDevice9_Release(device);
8695 goto done;
8697 else
8699 skip("Card has unconditional NP2 support, skipping conditional NP2 tests\n");
8700 IDirect3DDevice9_Release(device);
8701 goto done;
8704 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff000000, 1.0f, 0);
8705 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr);
8707 hr = IDirect3DDevice9_CreateTexture(device, 10, 10, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &texture, NULL);
8708 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture failed hr=%08x\n", hr);
8710 memset(&rect, 0, sizeof(rect));
8711 hr = IDirect3DTexture9_LockRect(texture, 0, &rect, NULL, 0);
8712 ok(hr == D3D_OK, "IDirect3DTexture9_LockRect failed hr=%08x\n", hr);
8713 for(y = 0; y < 10; y++) {
8714 for(x = 0; x < 10; x++) {
8715 dst = (DWORD *) ((BYTE *) rect.pBits + y * rect.Pitch + x * sizeof(DWORD));
8716 if(x == 0 || x == 9 || y == 0 || y == 9) {
8717 *dst = 0x00ff0000;
8718 } else {
8719 *dst = 0x000000ff;
8723 hr = IDirect3DTexture9_UnlockRect(texture, 0);
8724 ok(hr == D3D_OK, "IDirect3DTexture9_UnlockRect failed hr=%08x\n", hr);
8726 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) texture);
8727 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture failed hr=%08x\n", hr);
8728 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
8729 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
8730 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
8731 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState failed hr=%08x\n", hr);
8732 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
8733 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState failed hr=%08x\n", hr);
8734 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
8735 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexDeclaration failed, hr=%08x\n", hr);
8737 hr = IDirect3DDevice9_BeginScene(device);
8738 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8739 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(float) * 5);
8740 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8741 hr = IDirect3DDevice9_EndScene(device);
8742 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8744 color = getPixelColor(device, 1, 1);
8745 ok(color == 0x00ff0000, "NP2: Pixel 1, 1 has color %08x, expected 0x00ff0000\n", color);
8746 color = getPixelColor(device, 639, 479);
8747 ok(color == 0x00ff0000, "NP2: Pixel 639, 479 has color %08x, expected 0x00ff0000\n", color);
8749 color = getPixelColor(device, 135, 101);
8750 ok(color == 0x00ff0000, "NP2: Pixel 135, 101 has color %08x, expected 0x00ff0000\n", color);
8751 color = getPixelColor(device, 140, 101);
8752 ok(color == 0x00ff0000, "NP2: Pixel 140, 101 has color %08x, expected 0x00ff0000\n", color);
8753 color = getPixelColor(device, 135, 105);
8754 ok(color == 0x00ff0000, "NP2: Pixel 135, 105 has color %08x, expected 0x00ff0000\n", color);
8755 color = getPixelColor(device, 140, 105);
8756 ok(color == 0x000000ff, "NP2: Pixel 140, 105 has color %08x, expected 0x000000ff\n", color);
8758 color = getPixelColor(device, 135, 376);
8759 ok(color == 0x00ff0000, "NP2: Pixel 135, 376 has color %08x, expected 0x00ff0000\n", color);
8760 color = getPixelColor(device, 140, 376);
8761 ok(color == 0x000000ff, "NP2: Pixel 140, 376 has color %08x, expected 0x000000ff\n", color);
8762 color = getPixelColor(device, 135, 379);
8763 ok(color == 0x00ff0000, "NP2: Pixel 135, 379 has color %08x, expected 0x00ff0000\n", color);
8764 color = getPixelColor(device, 140, 379);
8765 ok(color == 0x00ff0000, "NP2: Pixel 140, 379 has color %08x, expected 0x00ff0000\n", color);
8767 color = getPixelColor(device, 500, 101);
8768 ok(color == 0x00ff0000, "NP2: Pixel 500, 101 has color %08x, expected 0x00ff0000\n", color);
8769 color = getPixelColor(device, 504, 101);
8770 ok(color == 0x00ff0000, "NP2: Pixel 504, 101 has color %08x, expected 0x00ff0000\n", color);
8771 color = getPixelColor(device, 500, 105);
8772 ok(color == 0x000000ff, "NP2: Pixel 500, 105 has color %08x, expected 0x000000ff\n", color);
8773 color = getPixelColor(device, 504, 105);
8774 ok(color == 0x00ff0000, "NP2: Pixel 504, 105 has color %08x, expected 0x00ff0000\n", color);
8776 color = getPixelColor(device, 500, 376);
8777 ok(color == 0x000000ff, "NP2: Pixel 500, 376 has color %08x, expected 0x000000ff\n", color);
8778 color = getPixelColor(device, 504, 376);
8779 ok(color == 0x00ff0000, "NP2: Pixel 504, 376 has color %08x, expected 0x00ff0000\n", color);
8780 color = getPixelColor(device, 500, 380);
8781 ok(color == 0x00ff0000, "NP2: Pixel 500, 380 has color %08x, expected 0x00ff0000\n", color);
8782 color = getPixelColor(device, 504, 380);
8783 ok(color == 0x00ff0000, "NP2: Pixel 504, 380 has color %08x, expected 0x00ff0000\n", color);
8785 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
8787 IDirect3DTexture9_Release(texture);
8788 refcount = IDirect3DDevice9_Release(device);
8789 ok(!refcount, "Device has %u references left.\n", refcount);
8790 done:
8791 IDirect3D9_Release(d3d);
8792 DestroyWindow(window);
8795 static void vface_register_test(void)
8797 IDirect3DSurface9 *surface, *backbuffer;
8798 IDirect3DVertexShader9 *vshader;
8799 IDirect3DPixelShader9 *shader;
8800 IDirect3DTexture9 *texture;
8801 IDirect3DDevice9 *device;
8802 IDirect3D9 *d3d;
8803 ULONG refcount;
8804 D3DCAPS9 caps;
8805 DWORD color;
8806 HWND window;
8807 HRESULT hr;
8809 static const DWORD shader_code[] =
8811 0xffff0300, /* ps_3_0 */
8812 0x05000051, 0xa00f0000, 0x00000000, 0x3f800000, 0x00000000, 0x00000000, /* def c0, 0.0, 1.0, 0.0, 0.0 */
8813 0x05000051, 0xa00f0001, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c1, 1.0, 0.0, 0.0, 0.0 */
8814 0x0200001f, 0x80000000, 0x900f1001, /* dcl vFace */
8815 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
8816 0x04000058, 0x800f0000, 0x90e41001, 0xa0e40000, 0x80e40001, /* cmp r0, vFace, c0, r1 */
8817 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
8818 0x0000ffff /* END */
8820 static const DWORD vshader_code[] =
8822 0xfffe0300, /* vs_3_0 */
8823 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
8824 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
8825 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
8826 0x0000ffff /* end */
8828 static const float quad[] =
8830 -1.0f, -1.0f, 0.1f,
8831 1.0f, -1.0f, 0.1f,
8832 -1.0f, 0.0f, 0.1f,
8834 1.0f, -1.0f, 0.1f,
8835 1.0f, 0.0f, 0.1f,
8836 -1.0f, 0.0f, 0.1f,
8838 -1.0f, 0.0f, 0.1f,
8839 -1.0f, 1.0f, 0.1f,
8840 1.0f, 0.0f, 0.1f,
8842 1.0f, 0.0f, 0.1f,
8843 -1.0f, 1.0f, 0.1f,
8844 1.0f, 1.0f, 0.1f,
8846 static const float blit[] =
8848 0.0f, -1.0f, 0.1f, 0.0f, 0.0f,
8849 1.0f, -1.0f, 0.1f, 1.0f, 0.0f,
8850 0.0f, 1.0f, 0.1f, 0.0f, 1.0f,
8851 1.0f, 1.0f, 0.1f, 1.0f, 1.0f,
8854 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8855 0, 0, 640, 480, NULL, NULL, NULL, NULL);
8856 d3d = Direct3DCreate9(D3D_SDK_VERSION);
8857 ok(!!d3d, "Failed to create a D3D object.\n");
8858 if (!(device = create_device(d3d, window, window, TRUE)))
8860 skip("Failed to create a D3D device, skipping tests.\n");
8861 goto done;
8864 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
8865 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
8866 if (caps.PixelShaderVersion < D3DPS_VERSION(3, 0) || caps.VertexShaderVersion < D3DVS_VERSION(3, 0))
8868 skip("No shader model 3 support, skipping tests.\n");
8869 IDirect3DDevice9_Release(device);
8870 goto done;
8873 hr = IDirect3DDevice9_CreateVertexShader(device, vshader_code, &vshader);
8874 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader failed hr=%08x\n", hr);
8875 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code, &shader);
8876 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader failed hr=%08x\n", hr);
8877 hr = IDirect3DDevice9_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &texture, NULL);
8878 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture failed hr=%08x\n", hr);
8879 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
8880 ok(hr == D3D_OK, "IDirect3DTexture9_GetSurfaceLevel failed hr=%08x\n", hr);
8881 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE);
8882 ok(SUCCEEDED(hr), "Failed to set cull mode, hr %#x.\n", hr);
8883 hr = IDirect3DDevice9_SetPixelShader(device, shader);
8884 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader failed hr=%08x\n", hr);
8885 hr = IDirect3DDevice9_SetVertexShader(device, vshader);
8886 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShader failed hr=%08x\n", hr);
8887 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
8888 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed hr=%08x\n", hr);
8889 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
8890 ok(hr == D3D_OK, "IDirect3DDevice9_GetBackBuffer failed hr=%08x\n", hr);
8892 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
8893 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr);
8895 hr = IDirect3DDevice9_BeginScene(device);
8896 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8898 /* First, draw to the texture and the back buffer to test both offscreen and onscreen cases */
8899 hr = IDirect3DDevice9_SetRenderTarget(device, 0, surface);
8900 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
8901 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0, 0);
8902 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
8903 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLELIST, 4, quad, sizeof(float) * 3);
8904 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8905 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
8906 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
8907 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLELIST, 4, quad, sizeof(float) * 3);
8908 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8910 /* Blit the texture onto the back buffer to make it visible */
8911 hr = IDirect3DDevice9_SetVertexShader(device, NULL);
8912 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
8913 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
8914 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
8915 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) texture);
8916 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
8917 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
8918 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
8919 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
8920 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
8921 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
8922 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
8923 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, blit, sizeof(float) * 5);
8924 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8926 hr = IDirect3DDevice9_EndScene(device);
8927 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8929 color = getPixelColor(device, 160, 360);
8930 ok(color == 0x00ff0000, "vFace: Onscreen rendered front facing quad has color 0x%08x, expected 0x00ff0000\n", color);
8931 color = getPixelColor(device, 160, 120);
8932 ok(color == 0x0000ff00, "vFace: Onscreen rendered back facing quad has color 0x%08x, expected 0x0000ff00\n", color);
8933 color = getPixelColor(device, 480, 360);
8934 ok(color == 0x0000ff00, "vFace: Offscreen rendered back facing quad has color 0x%08x, expected 0x0000ff00\n", color);
8935 color = getPixelColor(device, 480, 120);
8936 ok(color == 0x00ff0000, "vFace: Offscreen rendered front facing quad has color 0x%08x, expected 0x00ff0000\n", color);
8937 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
8938 ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
8940 IDirect3DPixelShader9_Release(shader);
8941 IDirect3DVertexShader9_Release(vshader);
8942 IDirect3DSurface9_Release(surface);
8943 IDirect3DSurface9_Release(backbuffer);
8944 IDirect3DTexture9_Release(texture);
8945 refcount = IDirect3DDevice9_Release(device);
8946 ok(!refcount, "Device has %u references left.\n", refcount);
8947 done:
8948 IDirect3D9_Release(d3d);
8949 DestroyWindow(window);
8952 static void fixed_function_bumpmap_test(void)
8954 IDirect3DVertexDeclaration9 *vertex_declaration;
8955 IDirect3DTexture9 *texture, *tex1, *tex2;
8956 D3DLOCKED_RECT locked_rect;
8957 IDirect3DDevice9 *device;
8958 BOOL L6V5U5_supported;
8959 float scale, offset;
8960 IDirect3D9 *d3d;
8961 unsigned int i;
8962 D3DCOLOR color;
8963 ULONG refcount;
8964 D3DCAPS9 caps;
8965 HWND window;
8966 HRESULT hr;
8968 static const float quad[][7] =
8970 {-1.0f, -1.0f, 0.1f, 0.0f, 0.0f, 0.0f, 0.0f},
8971 {-1.0f, 1.0f, 0.1f, 0.0f, 1.0f, 0.0f, 1.0f},
8972 { 1.0f, -1.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f},
8973 { 1.0f, 1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 1.0f},
8975 static const D3DVERTEXELEMENT9 decl_elements[] =
8977 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
8978 {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
8979 {0, 20, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},
8980 D3DDECL_END()
8982 /* use asymmetric matrix to test loading */
8983 static const float bumpenvmat[4] = {0.0f, 0.5f, -0.5f, 0.0f};
8985 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8986 0, 0, 640, 480, NULL, NULL, NULL, NULL);
8987 d3d = Direct3DCreate9(D3D_SDK_VERSION);
8988 ok(!!d3d, "Failed to create a D3D object.\n");
8989 if (!(device = create_device(d3d, window, window, TRUE)))
8991 skip("Failed to create a D3D device, skipping tests.\n");
8992 goto done;
8995 memset(&caps, 0, sizeof(caps));
8996 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
8997 ok(hr == D3D_OK, "IDirect3DDevice9_GetDeviceCaps failed hr=%08x\n", hr);
8998 if (!(caps.TextureOpCaps & D3DTEXOPCAPS_BUMPENVMAP))
9000 skip("D3DTEXOPCAPS_BUMPENVMAP not set, skipping bumpmap tests\n");
9001 IDirect3DDevice9_Release(device);
9002 goto done;
9005 /* This check is disabled, some Windows drivers do not handle
9006 * D3DUSAGE_QUERY_LEGACYBUMPMAP properly. They report that it is not
9007 * supported, but after that bump mapping works properly. So just test if
9008 * the format is generally supported, and check the BUMPENVMAP flag. */
9009 L6V5U5_supported = SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL,
9010 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, D3DFMT_L6V5U5));
9011 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL,
9012 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, D3DFMT_V8U8)))
9014 skip("D3DFMT_V8U8 not supported for legacy bump mapping\n");
9015 IDirect3DDevice9_Release(device);
9016 return;
9019 /* Generate the textures */
9020 generate_bumpmap_textures(device);
9022 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_BUMPENVMAT00, *(LPDWORD)&bumpenvmat[0]);
9023 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9024 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_BUMPENVMAT01, *(LPDWORD)&bumpenvmat[1]);
9025 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9026 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_BUMPENVMAT10, *(LPDWORD)&bumpenvmat[2]);
9027 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9028 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_BUMPENVMAT11, *(LPDWORD)&bumpenvmat[3]);
9029 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9031 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_BUMPENVMAP);
9032 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9033 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
9034 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9035 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_CURRENT );
9036 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9038 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
9039 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9040 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
9041 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9042 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_CURRENT);
9043 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9045 hr = IDirect3DDevice9_SetTextureStageState(device, 2, D3DTSS_COLOROP, D3DTOP_DISABLE);
9046 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9048 hr = IDirect3DDevice9_SetVertexShader(device, NULL);
9049 ok(SUCCEEDED(hr), "SetVertexShader failed (%08x)\n", hr);
9051 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff00ff, 1.0f, 0);
9052 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed (%08x)\n", hr);
9054 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &vertex_declaration);
9055 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (0x%08x)\n", hr);
9056 hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration);
9057 ok(SUCCEEDED(hr), "SetVertexDeclaration failed (0x%08x)\n", hr);
9059 hr = IDirect3DDevice9_BeginScene(device);
9060 ok(SUCCEEDED(hr), "BeginScene failed (0x%08x)\n", hr);
9062 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], sizeof(quad[0]));
9063 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed (0x%08x)\n", hr);
9065 hr = IDirect3DDevice9_EndScene(device);
9066 ok(SUCCEEDED(hr), "EndScene failed (0x%08x)\n", hr);
9068 color = getPixelColor(device, 240, 60);
9069 ok(color_match(color, 0x005ea000, 4), "Got unexpected color 0x%08x.\n", color);
9070 color = getPixelColor(device, 400, 60);
9071 ok(color_match(color, 0x009ea000, 4), "Got unexpected color 0x%08x.\n", color);
9072 color = getPixelColor(device, 80, 180);
9073 ok(color_match(color, 0x005ea000, 4), "Got unexpected color 0x%08x.\n", color);
9074 color = getPixelColor(device, 560, 180);
9075 ok(color_match(color, 0x009ea000, 4), "Got unexpected color 0x%08x.\n", color);
9076 color = getPixelColor(device, 80, 300);
9077 ok(color_match(color, 0x005e6000, 4), "Got unexpected color 0x%08x.\n", color);
9078 color = getPixelColor(device, 560, 300);
9079 ok(color_match(color, 0x009e6000, 4), "Got unexpected color 0x%08x.\n", color);
9080 color = getPixelColor(device, 240, 420);
9081 ok(color_match(color, 0x005e6000, 4), "Got unexpected color 0x%08x.\n", color);
9082 color = getPixelColor(device, 400, 420);
9083 ok(color_match(color, 0x009e6000, 4), "Got unexpected color 0x%08x.\n", color);
9084 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
9085 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
9087 for(i = 0; i < 2; i++) {
9088 hr = IDirect3DDevice9_GetTexture(device, i, (IDirect3DBaseTexture9 **) &texture);
9089 ok(SUCCEEDED(hr), "IDirect3DDevice9_GetTexture failed (0x%08x)\n", hr);
9090 IDirect3DTexture9_Release(texture); /* For the GetTexture */
9091 hr = IDirect3DDevice9_SetTexture(device, i, NULL);
9092 ok(SUCCEEDED(hr), "SetTexture failed (0x%08x)\n", hr);
9093 IDirect3DTexture9_Release(texture); /* To destroy it */
9096 if (!L6V5U5_supported || !(caps.TextureOpCaps & D3DTEXOPCAPS_BUMPENVMAPLUMINANCE))
9098 skip("L6V5U5 / D3DTOP_BUMPENVMAPLUMINANCE not supported, skipping tests.\n");
9099 IDirect3DVertexDeclaration9_Release(vertex_declaration);
9100 IDirect3DDevice9_Release(device);
9101 goto done;
9104 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
9105 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
9106 /* This test only tests the luminance part. The bumpmapping part was already tested above and
9107 * would only make this test more complicated
9109 hr = IDirect3DDevice9_CreateTexture(device, 1, 1, 1, 0, D3DFMT_L6V5U5, D3DPOOL_MANAGED, &tex1, NULL);
9110 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture failed, hr=%08x\n", hr);
9111 hr = IDirect3DDevice9_CreateTexture(device, 1, 1, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &tex2, NULL);
9112 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture failed, hr=%08x\n", hr);
9114 memset(&locked_rect, 0, sizeof(locked_rect));
9115 hr = IDirect3DTexture9_LockRect(tex1, 0, &locked_rect, NULL, 0);
9116 ok(SUCCEEDED(hr), "LockRect failed with 0x%08x\n", hr);
9117 *((DWORD *)locked_rect.pBits) = 0x4000; /* L = 0.25, V = 0.0, U = 0.0 */
9118 hr = IDirect3DTexture9_UnlockRect(tex1, 0);
9119 ok(SUCCEEDED(hr), "UnlockRect failed with 0x%08x\n", hr);
9121 memset(&locked_rect, 0, sizeof(locked_rect));
9122 hr = IDirect3DTexture9_LockRect(tex2, 0, &locked_rect, NULL, 0);
9123 ok(SUCCEEDED(hr), "LockRect failed with 0x%08x\n", hr);
9124 *((DWORD *)locked_rect.pBits) = 0x00ff80c0;
9125 hr = IDirect3DTexture9_UnlockRect(tex2, 0);
9126 ok(SUCCEEDED(hr), "UnlockRect failed with 0x%08x\n", hr);
9128 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) tex1);
9129 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTexture failed (%08x)\n", hr);
9130 hr = IDirect3DDevice9_SetTexture(device, 1, (IDirect3DBaseTexture9 *) tex2);
9131 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTexture failed (%08x)\n", hr);
9133 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_BUMPENVMAPLUMINANCE);
9134 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9135 scale = 2.0;
9136 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_BUMPENVLSCALE, *((DWORD *)&scale));
9137 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9138 offset = 0.1;
9139 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_BUMPENVLOFFSET, *((DWORD *)&offset));
9140 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9142 hr = IDirect3DDevice9_BeginScene(device);
9143 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9144 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], sizeof(quad[0]));
9145 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9146 hr = IDirect3DDevice9_EndScene(device);
9147 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9149 color = getPixelColor(device, 320, 240);
9150 /* red: 1.0 * (0.25 * 2.0 + 0.1) = 1.0 * 0.6 = 0.6 = 0x99
9151 * green: 0.5 * (0.25 * 2.0 + 0.1) = 0.5 * 0.6 = 0.3 = 0x4c
9152 * green: 0.75 * (0.25 * 2.0 + 0.1) = 0.75 * 0.6 = 0.45 = 0x72
9154 ok(color_match(color, 0x00994c72, 5), "bumpmap failed: Got color 0x%08x, expected 0x00994c72.\n", color);
9155 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
9156 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
9158 /* Check a result scale factor > 1.0 */
9159 scale = 10;
9160 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_BUMPENVLSCALE, *((DWORD *)&scale));
9161 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9162 offset = 10;
9163 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_BUMPENVLOFFSET, *((DWORD *)&offset));
9164 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9166 hr = IDirect3DDevice9_BeginScene(device);
9167 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9168 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], sizeof(quad[0]));
9169 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9170 hr = IDirect3DDevice9_EndScene(device);
9171 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9173 color = getPixelColor(device, 320, 240);
9174 ok(color_match(color, 0x00ff80c0, 1), "bumpmap failed: Got color 0x%08x, expected 0x00ff80c0.\n", color);
9175 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
9176 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
9178 /* Check clamping in the scale factor calculation */
9179 scale = 1000;
9180 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_BUMPENVLSCALE, *((DWORD *)&scale));
9181 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9182 offset = -1;
9183 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_BUMPENVLOFFSET, *((DWORD *)&offset));
9184 ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr);
9186 hr = IDirect3DDevice9_BeginScene(device);
9187 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9188 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], sizeof(quad[0]));
9189 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9190 hr = IDirect3DDevice9_EndScene(device);
9191 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9193 color = getPixelColor(device, 320, 240);
9194 ok(color_match(color, 0x00ff80c0, 1), "bumpmap failed: Got color 0x%08x, expected 0x00ff80c0.\n", color);
9195 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
9196 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
9198 IDirect3DTexture9_Release(tex1);
9199 IDirect3DTexture9_Release(tex2);
9200 IDirect3DVertexDeclaration9_Release(vertex_declaration);
9201 refcount = IDirect3DDevice9_Release(device);
9202 ok(!refcount, "Device has %u references left.\n", refcount);
9203 done:
9204 IDirect3D9_Release(d3d);
9205 DestroyWindow(window);
9208 static void stencil_cull_test(void)
9210 IDirect3DDevice9 *device;
9211 IDirect3D9 *d3d;
9212 ULONG refcount;
9213 D3DCAPS9 caps;
9214 HWND window;
9215 HRESULT hr;
9216 static const float quad1[] =
9218 -1.0, -1.0, 0.1,
9219 0.0, -1.0, 0.1,
9220 -1.0, 0.0, 0.1,
9221 0.0, 0.0, 0.1,
9223 static const float quad2[] =
9225 0.0, -1.0, 0.1,
9226 1.0, -1.0, 0.1,
9227 0.0, 0.0, 0.1,
9228 1.0, 0.0, 0.1,
9230 static const float quad3[] =
9232 0.0, 0.0, 0.1,
9233 1.0, 0.0, 0.1,
9234 0.0, 1.0, 0.1,
9235 1.0, 1.0, 0.1,
9237 static const float quad4[] =
9239 -1.0, 0.0, 0.1,
9240 0.0, 0.0, 0.1,
9241 -1.0, 1.0, 0.1,
9242 0.0, 1.0, 0.1,
9244 struct
9246 struct vec3 position;
9247 DWORD diffuse;
9249 painter[] =
9251 {{-1.0f, -1.0f, 0.0f}, 0x00000000},
9252 {{ 1.0f, -1.0f, 0.0f}, 0x00000000},
9253 {{-1.0f, 1.0f, 0.0f}, 0x00000000},
9254 {{ 1.0f, 1.0f, 0.0f}, 0x00000000},
9256 static const WORD indices_cw[] = {0, 1, 3};
9257 static const WORD indices_ccw[] = {0, 2, 3};
9258 unsigned int i;
9259 DWORD color;
9261 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9262 0, 0, 640, 480, NULL, NULL, NULL, NULL);
9263 d3d = Direct3DCreate9(D3D_SDK_VERSION);
9264 ok(!!d3d, "Failed to create a D3D object.\n");
9265 if (!(device = create_device(d3d, window, window, TRUE)))
9267 skip("Cannot create a device with a D24S8 stencil buffer.\n");
9268 DestroyWindow(window);
9269 IDirect3D9_Release(d3d);
9270 return;
9272 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
9273 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
9274 if (!(caps.StencilCaps & D3DSTENCILCAPS_TWOSIDED))
9276 skip("No two sided stencil support\n");
9277 goto cleanup;
9280 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_STENCIL, 0x00ff0000, 0.0, 0x8);
9281 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
9282 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
9283 ok(SUCCEEDED(hr), "Failed to set FVF,hr %#x.\n", hr);
9285 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
9286 ok(hr == D3D_OK, "Failed to disable Z test, %#x.\n", hr);
9287 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
9288 ok(hr == D3D_OK, "Failed to disable lighting, %#x.\n", hr);
9289 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILFAIL, D3DSTENCILOP_INCR);
9290 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
9291 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILZFAIL, D3DSTENCILOP_DECR);
9292 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
9293 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE);
9294 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
9295 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILREF, 0x3);
9296 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
9298 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CCW_STENCILFAIL, D3DSTENCILOP_REPLACE);
9299 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
9300 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CCW_STENCILZFAIL, D3DSTENCILOP_DECR);
9301 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
9302 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CCW_STENCILPASS, D3DSTENCILOP_INCR);
9303 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
9305 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILENABLE, TRUE);
9306 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
9307 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TWOSIDEDSTENCILMODE, FALSE);
9308 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
9310 /* First pass: Fill the stencil buffer with some values... */
9311 hr = IDirect3DDevice9_BeginScene(device);
9312 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9314 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_CW);
9315 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9316 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
9317 1 /* PrimCount */, indices_cw, D3DFMT_INDEX16, quad1, sizeof(float) * 3);
9318 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9319 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
9320 1 /* PrimCount */, indices_ccw, D3DFMT_INDEX16, quad1, sizeof(float) * 3);
9321 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9323 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TWOSIDEDSTENCILMODE, TRUE);
9324 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9325 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE);
9326 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9327 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
9328 1 /* PrimCount */, indices_cw, D3DFMT_INDEX16, quad2, sizeof(float) * 3);
9329 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9330 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
9331 1 /* PrimCount */, indices_ccw, D3DFMT_INDEX16, quad2, sizeof(float) * 3);
9332 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9334 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_CW);
9335 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9336 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
9337 1 /* PrimCount */, indices_cw, D3DFMT_INDEX16, quad3, sizeof(float) * 3);
9338 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9339 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
9340 1 /* PrimCount */, indices_ccw, D3DFMT_INDEX16, quad3, sizeof(float) * 3);
9341 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9343 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_CCW);
9344 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9345 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
9346 1 /* PrimCount */, indices_cw, D3DFMT_INDEX16, quad4, sizeof(float) * 3);
9347 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9348 hr = IDirect3DDevice9_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 4 /* NumVerts */,
9349 1 /* PrimCount */, indices_ccw, D3DFMT_INDEX16, quad4, sizeof(float) * 3);
9350 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9352 hr = IDirect3DDevice9_EndScene(device);
9353 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9355 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP);
9356 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
9357 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
9358 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
9359 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);
9360 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
9361 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TWOSIDEDSTENCILMODE, FALSE);
9362 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
9363 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE);
9364 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
9365 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILFUNC, D3DCMP_EQUAL);
9366 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
9368 /* 2nd pass: Make the stencil values visible */
9369 hr = IDirect3DDevice9_BeginScene(device);
9370 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9371 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
9372 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
9373 for (i = 0; i < 16; ++i)
9375 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILREF, i);
9376 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9378 painter[0].diffuse = (i * 16); /* Creates shades of blue */
9379 painter[1].diffuse = (i * 16);
9380 painter[2].diffuse = (i * 16);
9381 painter[3].diffuse = (i * 16);
9382 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, painter, sizeof(painter[0]));
9383 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9385 hr = IDirect3DDevice9_EndScene(device);
9386 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9388 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILENABLE, FALSE);
9389 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
9391 color = getPixelColor(device, 160, 420);
9392 ok(color == 0x00000030, "CCW triangle, twoside FALSE, cull cw, replace, has color 0x%08x, expected 0x00000030\n", color);
9393 color = getPixelColor(device, 160, 300);
9394 ok(color == 0x00000080, "CW triangle, twoside FALSE, cull cw, culled, has color 0x%08x, expected 0x00000080\n", color);
9396 color = getPixelColor(device, 480, 420);
9397 ok(color == 0x00000090, "CCW triangle, twoside TRUE, cull off, incr, has color 0x%08x, expected 0x00000090\n", color);
9398 color = getPixelColor(device, 480, 300);
9399 ok(color == 0x00000030, "CW triangle, twoside TRUE, cull off, replace, has color 0x%08x, expected 0x00000030\n", color);
9401 color = getPixelColor(device, 160, 180);
9402 ok(color == 0x00000080, "CCW triangle, twoside TRUE, cull ccw, culled, has color 0x%08x, expected 0x00000080\n", color);
9403 color = getPixelColor(device, 160, 60);
9404 ok(color == 0x00000030, "CW triangle, twoside TRUE, cull ccw, replace, has color 0x%08x, expected 0x00000030\n", color);
9406 color = getPixelColor(device, 480, 180);
9407 ok(color == 0x00000090, "CCW triangle, twoside TRUE, cull cw, incr, has color 0x%08x, expected 0x00000090\n", color);
9408 color = getPixelColor(device, 480, 60);
9409 ok(color == 0x00000080, "CW triangle, twoside TRUE, cull cw, culled, has color 0x%08x, expected 0x00000080\n", color);
9411 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
9412 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
9414 cleanup:
9415 refcount = IDirect3DDevice9_Release(device);
9416 ok(!refcount, "Device has %u references left.\n", refcount);
9417 IDirect3D9_Release(d3d);
9418 DestroyWindow(window);
9421 static void vpos_register_test(void)
9423 IDirect3DSurface9 *surface = NULL, *backbuffer;
9424 IDirect3DPixelShader9 *shader, *shader_frac;
9425 IDirect3DVertexShader9 *vshader;
9426 IDirect3DDevice9 *device;
9427 D3DLOCKED_RECT lr;
9428 IDirect3D9 *d3d;
9429 ULONG refcount;
9430 D3DCAPS9 caps;
9431 DWORD color;
9432 HWND window;
9433 HRESULT hr;
9434 DWORD *pos;
9436 static const DWORD shader_code[] =
9438 0xffff0300, /* ps_3_0 */
9439 0x0200001f, 0x80000000, 0x90031000, /* dcl vPos.xy */
9440 0x03000002, 0x80030000, 0x90541000, 0xa1fe0000, /* sub r0.xy, vPos.xy, c0.zw */
9441 0x02000001, 0x800f0001, 0xa0e40000, /* mov r1, c0 */
9442 0x02000001, 0x80080002, 0xa0550000, /* mov r2.a, c0.y */
9443 0x02000001, 0x80010002, 0xa0550000, /* mov r2.r, c0.y */
9444 0x04000058, 0x80020002, 0x80000000, 0x80000001, 0x80550001, /* cmp r2.g, r0.x, r1.x, r1.y */
9445 0x04000058, 0x80040002, 0x80550000, 0x80000001, 0x80550001, /* cmp r2.b, r0.y, r1.x, r1.y */
9446 0x02000001, 0x800f0800, 0x80e40002, /* mov oC0, r2 */
9447 0x0000ffff /* end */
9449 static const DWORD shader_frac_code[] =
9451 0xffff0300, /* ps_3_0 */
9452 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 0.0, 0.0, 0.0, 0.0 */
9453 0x0200001f, 0x80000000, 0x90031000, /* dcl vPos.xy */
9454 0x02000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
9455 0x02000013, 0x80030000, 0x90541000, /* frc r0.xy, vPos.xy */
9456 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
9457 0x0000ffff /* end */
9459 static const DWORD vshader_code[] =
9461 0xfffe0300, /* vs_3_0 */
9462 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
9463 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
9464 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
9465 0x0000ffff /* end */
9467 static const float quad[] =
9469 -1.0f, -1.0f, 0.1f, 0.0f, 0.0f,
9470 -1.0f, 1.0f, 0.1f, 0.0f, 1.0f,
9471 1.0f, -1.0f, 0.1f, 1.0f, 0.0f,
9472 1.0f, 1.0f, 0.1f, 1.0f, 1.0f,
9474 float constant[4] = {1.0, 0.0, 320, 240};
9476 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9477 0, 0, 640, 480, NULL, NULL, NULL, NULL);
9478 d3d = Direct3DCreate9(D3D_SDK_VERSION);
9479 ok(!!d3d, "Failed to create a D3D object.\n");
9480 if (!(device = create_device(d3d, window, window, TRUE)))
9482 skip("Failed to create a D3D device, skipping tests.\n");
9483 goto done;
9486 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
9487 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
9488 if (caps.PixelShaderVersion < D3DPS_VERSION(3, 0) || caps.VertexShaderVersion < D3DVS_VERSION(3, 0))
9490 skip("No shader model 3 support, skipping tests.\n");
9491 IDirect3DDevice9_Release(device);
9492 goto done;
9495 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
9496 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr);
9497 hr = IDirect3DDevice9_CreateVertexShader(device, vshader_code, &vshader);
9498 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader failed hr=%08x\n", hr);
9499 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code, &shader);
9500 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader failed hr=%08x\n", hr);
9501 hr = IDirect3DDevice9_CreatePixelShader(device, shader_frac_code, &shader_frac);
9502 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader failed hr=%08x\n", hr);
9503 hr = IDirect3DDevice9_SetPixelShader(device, shader);
9504 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader failed hr=%08x\n", hr);
9505 hr = IDirect3DDevice9_SetVertexShader(device, vshader);
9506 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShader failed hr=%08x\n", hr);
9507 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
9508 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed hr=%08x\n", hr);
9509 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
9510 ok(hr == D3D_OK, "IDirect3DDevice9_GetBackBuffer failed hr=%08x\n", hr);
9512 hr = IDirect3DDevice9_BeginScene(device);
9513 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9514 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 0, constant, 1);
9515 ok(SUCCEEDED(hr), "Failed to set pixel shader constant, hr %#x.\n", hr);
9516 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(float) * 5);
9517 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9518 hr = IDirect3DDevice9_EndScene(device);
9519 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9521 /* This has to be pixel exact */
9522 color = getPixelColor(device, 319, 239);
9523 ok(color == 0x00000000, "vPos: Pixel 319,239 has color 0x%08x, expected 0x00000000\n", color);
9524 color = getPixelColor(device, 320, 239);
9525 ok(color == 0x0000ff00, "vPos: Pixel 320,239 has color 0x%08x, expected 0x0000ff00\n", color);
9526 color = getPixelColor(device, 319, 240);
9527 ok(color == 0x000000ff, "vPos: Pixel 319,240 has color 0x%08x, expected 0x000000ff\n", color);
9528 color = getPixelColor(device, 320, 240);
9529 ok(color == 0x0000ffff, "vPos: Pixel 320,240 has color 0x%08x, expected 0x0000ffff\n", color);
9530 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
9532 hr = IDirect3DDevice9_CreateRenderTarget(device, 32, 32, D3DFMT_X8R8G8B8, 0, 0, TRUE,
9533 &surface, NULL);
9534 ok(hr == D3D_OK, "IDirect3DDevice9_CreateRenderTarget failed hr=%08x\n", hr);
9535 hr = IDirect3DDevice9_BeginScene(device);
9536 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9537 constant[2] = 16; constant[3] = 16;
9538 hr = IDirect3DDevice9_SetPixelShaderConstantF(device, 0, constant, 1);
9539 ok(SUCCEEDED(hr), "Failed to set pixel shader constant, hr %#x.\n", hr);
9540 hr = IDirect3DDevice9_SetRenderTarget(device, 0, surface);
9541 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
9542 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(float) * 5);
9543 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9544 hr = IDirect3DDevice9_EndScene(device);
9545 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9547 hr = IDirect3DSurface9_LockRect(surface, &lr, NULL, D3DLOCK_READONLY);
9548 ok(hr == D3D_OK, "IDirect3DSurface9_LockRect failed, hr=%08x\n", hr);
9550 pos = (DWORD *) (((BYTE *) lr.pBits) + 14 * lr.Pitch + 14 * sizeof(DWORD));
9551 color = *pos & 0x00ffffff;
9552 ok(color == 0x00000000, "Pixel 14/14 has color 0x%08x, expected 0x00000000\n", color);
9553 pos = (DWORD *) (((BYTE *) lr.pBits) + 14 * lr.Pitch + 18 * sizeof(DWORD));
9554 color = *pos & 0x00ffffff;
9555 ok(color == 0x0000ff00, "Pixel 14/18 has color 0x%08x, expected 0x0000ff00\n", color);
9556 pos = (DWORD *) (((BYTE *) lr.pBits) + 18 * lr.Pitch + 14 * sizeof(DWORD));
9557 color = *pos & 0x00ffffff;
9558 ok(color == 0x000000ff, "Pixel 18/14 has color 0x%08x, expected 0x000000ff\n", color);
9559 pos = (DWORD *) (((BYTE *) lr.pBits) + 18 * lr.Pitch + 18 * sizeof(DWORD));
9560 color = *pos & 0x00ffffff;
9561 ok(color == 0x0000ffff, "Pixel 18/18 has color 0x%08x, expected 0x0000ffff\n", color);
9563 hr = IDirect3DSurface9_UnlockRect(surface);
9564 ok(hr == D3D_OK, "IDirect3DSurface9_UnlockRect failed, hr=%08x\n", hr);
9566 /* Test the fraction value of vPos. This is tested with the offscreen target and not the backbuffer to
9567 * have full control over the multisampling setting inside this test
9569 hr = IDirect3DDevice9_SetPixelShader(device, shader_frac);
9570 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader failed hr=%08x\n", hr);
9571 hr = IDirect3DDevice9_BeginScene(device);
9572 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9573 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0, 0);
9574 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
9575 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(float) * 5);
9576 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9577 hr = IDirect3DDevice9_EndScene(device);
9578 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9580 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
9581 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderTarget failed, hr=%08x\n", hr);
9583 hr = IDirect3DSurface9_LockRect(surface, &lr, NULL, D3DLOCK_READONLY);
9584 ok(hr == D3D_OK, "IDirect3DSurface9_LockRect failed, hr=%08x\n", hr);
9586 pos = (DWORD *) (((BYTE *) lr.pBits) + 14 * lr.Pitch + 14 * sizeof(DWORD));
9587 color = *pos & 0x00ffffff;
9588 ok(color == 0x00000000, "vPos fraction test has color 0x%08x, expected 0x00000000\n", color);
9590 hr = IDirect3DSurface9_UnlockRect(surface);
9591 ok(hr == D3D_OK, "IDirect3DSurface9_UnlockRect failed, hr=%08x\n", hr);
9593 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
9594 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader failed hr=%08x\n", hr);
9595 hr = IDirect3DDevice9_SetVertexShader(device, NULL);
9596 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShader failed hr=%08x\n", hr);
9597 IDirect3DPixelShader9_Release(shader);
9598 IDirect3DPixelShader9_Release(shader_frac);
9599 IDirect3DVertexShader9_Release(vshader);
9600 if(surface) IDirect3DSurface9_Release(surface);
9601 IDirect3DSurface9_Release(backbuffer);
9602 refcount = IDirect3DDevice9_Release(device);
9603 ok(!refcount, "Device has %u references left.\n", refcount);
9604 done:
9605 IDirect3D9_Release(d3d);
9606 DestroyWindow(window);
9609 static BOOL point_match(IDirect3DDevice9 *device, UINT x, UINT y, UINT r)
9611 D3DCOLOR color;
9613 color = D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0xff);
9614 if (!color_match(getPixelColor(device, x + r, y), color, 1)) return FALSE;
9615 if (!color_match(getPixelColor(device, x - r, y), color, 1)) return FALSE;
9616 if (!color_match(getPixelColor(device, x, y + r), color, 1)) return FALSE;
9617 if (!color_match(getPixelColor(device, x, y - r), color, 1)) return FALSE;
9619 ++r;
9620 color = D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0xff);
9621 if (!color_match(getPixelColor(device, x + r, y), color, 1)) return FALSE;
9622 if (!color_match(getPixelColor(device, x - r, y), color, 1)) return FALSE;
9623 if (!color_match(getPixelColor(device, x, y + r), color, 1)) return FALSE;
9624 if (!color_match(getPixelColor(device, x, y - r), color, 1)) return FALSE;
9626 return TRUE;
9629 static void pointsize_test(void)
9631 float ptsize, ptsizemax_orig, ptsizemin_orig;
9632 IDirect3DSurface9 *rt, *backbuffer;
9633 IDirect3DTexture9 *tex1, *tex2;
9634 IDirect3DDevice9 *device;
9635 D3DLOCKED_RECT lr;
9636 IDirect3D9 *d3d;
9637 D3DCOLOR color;
9638 ULONG refcount;
9639 D3DCAPS9 caps;
9640 HWND window;
9641 HRESULT hr;
9643 static const RECT rect = {0, 0, 128, 128};
9644 static const DWORD tex1_data[4] = {0x00ff0000, 0x00ff0000, 0x00000000, 0x00000000};
9645 static const DWORD tex2_data[4] = {0x00000000, 0x0000ff00, 0x00000000, 0x0000ff00};
9646 static const float vertices[] =
9648 64.0f, 64.0f, 0.1f,
9649 128.0f, 64.0f, 0.1f,
9650 192.0f, 64.0f, 0.1f,
9651 256.0f, 64.0f, 0.1f,
9652 320.0f, 64.0f, 0.1f,
9653 384.0f, 64.0f, 0.1f,
9654 448.0f, 64.0f, 0.1f,
9655 512.0f, 64.0f, 0.1f,
9657 /* Transforms the coordinate system [-1.0;1.0]x[-1.0;1.0] to
9658 * [0.0;0.0]x[640.0;480.0]. Z is untouched. */
9659 D3DMATRIX matrix =
9661 2.0f / 640.0f, 0.0f, 0.0f, 0.0f,
9662 0.0f, -2.0 / 480.0f, 0.0f, 0.0f,
9663 0.0f, 0.0f, 1.0f, 0.0f,
9664 -1.0f, 1.0f, 0.0f, 1.0f,
9665 }}};
9667 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9668 0, 0, 640, 480, NULL, NULL, NULL, NULL);
9669 d3d = Direct3DCreate9(D3D_SDK_VERSION);
9670 ok(!!d3d, "Failed to create a D3D object.\n");
9671 if (!(device = create_device(d3d, window, window, TRUE)))
9673 skip("Failed to create a D3D device, skipping tests.\n");
9674 goto done;
9677 memset(&caps, 0, sizeof(caps));
9678 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
9679 ok(hr == D3D_OK, "IDirect3DDevice9_GetDeviceCaps failed hr=%08x\n", hr);
9680 if(caps.MaxPointSize < 32.0) {
9681 skip("MaxPointSize < 32.0, skipping(MaxPointsize = %f)\n", caps.MaxPointSize);
9682 IDirect3DDevice9_Release(device);
9683 goto done;
9686 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
9687 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr);
9688 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
9689 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
9690 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &matrix);
9691 ok(hr == D3D_OK, "IDirect3DDevice9_SetTransform failed, hr=%08x\n", hr);
9692 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
9693 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed hr=%08x\n", hr);
9695 hr = IDirect3DDevice9_BeginScene(device);
9696 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9698 ptsize = 15.0f;
9699 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, *(DWORD *)&ptsize);
9700 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9701 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, &vertices[0], sizeof(float) * 3);
9702 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9704 ptsize = 31.0f;
9705 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, *(DWORD *)&ptsize);
9706 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9707 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, &vertices[3], sizeof(float) * 3);
9708 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9710 ptsize = 30.75f;
9711 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, *(DWORD *)&ptsize);
9712 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9713 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, &vertices[6], sizeof(float) * 3);
9714 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9716 if (caps.MaxPointSize >= 63.0f)
9718 ptsize = 63.0f;
9719 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, *(DWORD *)&ptsize);
9720 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9721 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, &vertices[9], sizeof(float) * 3);
9722 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9724 ptsize = 62.75f;
9725 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, *(DWORD *)&ptsize);
9726 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9727 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, &vertices[15], sizeof(float) * 3);
9728 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9731 ptsize = 1.0f;
9732 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, *(DWORD *)&ptsize);
9733 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9734 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, &vertices[12], sizeof(float) * 3);
9735 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9737 hr = IDirect3DDevice9_GetRenderState(device, D3DRS_POINTSIZE_MAX, (DWORD *)&ptsizemax_orig);
9738 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
9739 hr = IDirect3DDevice9_GetRenderState(device, D3DRS_POINTSIZE_MIN, (DWORD *)&ptsizemin_orig);
9740 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
9742 /* What happens if point scaling is disabled, and POINTSIZE_MAX < POINTSIZE? */
9743 ptsize = 15.0f;
9744 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, *(DWORD *)&ptsize);
9745 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9746 ptsize = 1.0f;
9747 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE_MAX, *(DWORD *)&ptsize);
9748 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9749 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, &vertices[18], sizeof(float) * 3);
9750 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9752 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE_MAX, *(DWORD *)&ptsizemax_orig);
9753 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9755 /* pointsize < pointsize_min < pointsize_max?
9756 * pointsize = 1.0, pointsize_min = 15.0, pointsize_max = default(usually 64.0) */
9757 ptsize = 1.0f;
9758 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, *(DWORD *)&ptsize);
9759 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9760 ptsize = 15.0f;
9761 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE_MIN, *(DWORD *)&ptsize);
9762 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9763 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, &vertices[21], sizeof(float) * 3);
9764 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9766 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE_MIN, *(DWORD *)&ptsizemin_orig);
9767 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9769 hr = IDirect3DDevice9_EndScene(device);
9770 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9772 ok(point_match(device, 64, 64, 7), "point_match(64, 64, 7) failed, expected point size 15.\n");
9773 ok(point_match(device, 128, 64, 15), "point_match(128, 64, 15) failed, expected point size 31.\n");
9774 ok(point_match(device, 192, 64, 15), "point_match(192, 64, 15) failed, expected point size 31.\n");
9776 if (caps.MaxPointSize >= 63.0)
9778 ok(point_match(device, 256, 64, 31), "point_match(256, 64, 31) failed, expected point size 63.\n");
9779 ok(point_match(device, 384, 64, 31), "point_match(384, 64, 31) failed, expected point size 63.\n");
9782 ok(point_match(device, 320, 64, 0), "point_match(320, 64, 0) failed, expected point size 1.\n");
9783 /* ptsize = 15, ptsize_max = 1 --> point has size 1 */
9784 ok(point_match(device, 448, 64, 0), "point_match(448, 64, 0) failed, expected point size 1.\n");
9785 /* ptsize = 1, ptsize_max = default(64), ptsize_min = 15 --> point has size 15 */
9786 ok(point_match(device, 512, 64, 7), "point_match(512, 64, 7) failed, expected point size 15.\n");
9788 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
9790 /* The following code tests point sprites with two textures, to see if each texture coordinate unit
9791 * generates texture coordinates for the point(result: Yes, it does)
9793 * However, not all GL implementations support point sprites(they need GL_ARB_point_sprite), but there
9794 * is no point sprite cap bit in d3d because native d3d software emulates point sprites. Until the
9795 * SW emulation is implemented in wined3d, this test will fail on GL drivers that does not support them.
9797 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
9798 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr);
9800 hr = IDirect3DDevice9_CreateTexture(device, 2, 2, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex1, NULL);
9801 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture failed hr=%08x\n", hr);
9802 hr = IDirect3DDevice9_CreateTexture(device, 2, 2, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex2, NULL);
9803 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture failed hr=%08x\n", hr);
9804 memset(&lr, 0, sizeof(lr));
9805 hr = IDirect3DTexture9_LockRect(tex1, 0, &lr, NULL, 0);
9806 ok(hr == D3D_OK, "IDirect3DTexture9_LockRect failed hr=%08x\n", hr);
9807 memcpy(lr.pBits, tex1_data, sizeof(tex1_data));
9808 hr = IDirect3DTexture9_UnlockRect(tex1, 0);
9809 ok(hr == D3D_OK, "IDirect3DTexture9_UnlockRect failed hr=%08x\n", hr);
9810 memset(&lr, 0, sizeof(lr));
9811 hr = IDirect3DTexture9_LockRect(tex2, 0, &lr, NULL, 0);
9812 ok(hr == D3D_OK, "IDirect3DTexture9_LockRect failed hr=%08x\n", hr);
9813 memcpy(lr.pBits, tex2_data, sizeof(tex2_data));
9814 hr = IDirect3DTexture9_UnlockRect(tex2, 0);
9815 ok(hr == D3D_OK, "IDirect3DTexture9_UnlockRect failed hr=%08x\n", hr);
9816 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) tex1);
9817 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture failed hr=%08x\n", hr);
9818 hr = IDirect3DDevice9_SetTexture(device, 1, (IDirect3DBaseTexture9 *) tex2);
9819 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture failed hr=%08x\n", hr);
9820 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
9821 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed hr=%08x\n", hr);
9822 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
9823 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed hr=%08x\n", hr);
9824 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_ADD);
9825 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed hr=%08x\n", hr);
9826 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
9827 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed hr=%08x\n", hr);
9828 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_CURRENT);
9829 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed hr=%08x\n", hr);
9831 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSPRITEENABLE, TRUE);
9832 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed hr=%08x\n", hr);
9833 ptsize = 32.0;
9834 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, *((DWORD *) (&ptsize)));
9835 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed, hr=%08x\n", hr);
9837 hr = IDirect3DDevice9_BeginScene(device);
9838 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9839 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, &vertices[0], sizeof(float) * 3);
9840 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9841 hr = IDirect3DDevice9_EndScene(device);
9842 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9844 color = getPixelColor(device, 64-4, 64-4);
9845 ok(color == 0x00ff0000, "pSprite: Pixel (64-4),(64-4) has color 0x%08x, expected 0x00ff0000\n", color);
9846 color = getPixelColor(device, 64-4, 64+4);
9847 ok(color == 0x00000000, "pSprite: Pixel (64-4),(64+4) has color 0x%08x, expected 0x00000000\n", color);
9848 color = getPixelColor(device, 64+4, 64+4);
9849 ok(color == 0x0000ff00, "pSprite: Pixel (64+4),(64+4) has color 0x%08x, expected 0x0000ff00\n", color);
9850 color = getPixelColor(device, 64+4, 64-4);
9851 ok(color == 0x00ffff00, "pSprite: Pixel (64+4),(64-4) has color 0x%08x, expected 0x00ffff00\n", color);
9852 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
9854 U(matrix).m[0][0] = 1.0f / 64.0f;
9855 U(matrix).m[1][1] = -1.0f / 64.0f;
9856 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &matrix);
9857 ok(SUCCEEDED(hr), "SetTransform failed, hr %#x.\n", hr);
9859 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &backbuffer);
9860 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
9862 hr = IDirect3DDevice9_CreateRenderTarget(device, 128, 128, D3DFMT_A8R8G8B8,
9863 D3DMULTISAMPLE_NONE, 0, TRUE, &rt, NULL );
9864 ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
9866 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
9867 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
9868 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ffff, 1.0f, 0);
9869 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
9871 hr = IDirect3DDevice9_BeginScene(device);
9872 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
9873 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, &vertices[0], sizeof(float) * 3);
9874 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
9875 hr = IDirect3DDevice9_EndScene(device);
9876 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
9878 hr = IDirect3DDevice9_StretchRect(device, rt, &rect, backbuffer, &rect, D3DTEXF_NONE);
9879 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
9880 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
9881 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
9882 IDirect3DSurface9_Release(backbuffer);
9883 IDirect3DSurface9_Release(rt);
9885 color = getPixelColor(device, 64-4, 64-4);
9886 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x00), 0),
9887 "Expected color 0x00ff0000, got 0x%08x.\n", color);
9888 color = getPixelColor(device, 64+4, 64-4);
9889 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x00), 0),
9890 "Expected color 0x00ffff00, got 0x%08x.\n", color);
9891 color = getPixelColor(device, 64-4, 64+4);
9892 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00), 0),
9893 "Expected color 0x00000000, got 0x%08x.\n", color);
9894 color = getPixelColor(device, 64+4, 64+4);
9895 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 0),
9896 "Expected color 0x0000ff00, got 0x%08x.\n", color);
9898 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
9899 ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
9901 IDirect3DTexture9_Release(tex1);
9902 IDirect3DTexture9_Release(tex2);
9903 refcount = IDirect3DDevice9_Release(device);
9904 ok(!refcount, "Device has %u references left.\n", refcount);
9905 done:
9906 IDirect3D9_Release(d3d);
9907 DestroyWindow(window);
9910 static void multiple_rendertargets_test(void)
9912 IDirect3DSurface9 *surf1, *surf2, *backbuf, *readback;
9913 IDirect3DPixelShader9 *ps1, *ps2;
9914 IDirect3DTexture9 *tex1, *tex2;
9915 IDirect3DVertexShader9 *vs;
9916 IDirect3DDevice9 *device;
9917 IDirect3D9 *d3d;
9918 ULONG refcount;
9919 D3DCAPS9 caps;
9920 DWORD color;
9921 HWND window;
9922 HRESULT hr;
9923 UINT i, j;
9925 static const DWORD vshader_code[] =
9927 0xfffe0300, /* vs_3_0 */
9928 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
9929 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
9930 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
9931 0x0000ffff /* end */
9933 static const DWORD pshader_code1[] =
9935 0xffff0300, /* ps_3_0 */
9936 0x05000051, 0xa00f0000, 0x00000000, 0x3f800000, 0x00000000, 0x00000000, /* def c0, 0.0, 1.0, 0.0, 0.0 */
9937 0x02000001, 0x800f0800, 0xa0e40000, /* mov oC0, c0 */
9938 0x0000ffff /* end */
9940 static const DWORD pshader_code2[] =
9942 0xffff0300, /* ps_3_0 */
9943 0x05000051, 0xa00f0000, 0x00000000, 0x3f800000, 0x00000000, 0x00000000, /* def c0, 0.0, 1.0, 0.0, 0.0 */
9944 0x05000051, 0xa00f0001, 0x00000000, 0x00000000, 0x3f800000, 0x00000000, /* def c1, 0.0, 0.0, 1.0, 0.0 */
9945 0x02000001, 0x800f0800, 0xa0e40000, /* mov oC0, c0 */
9946 0x02000001, 0x800f0801, 0xa0e40001, /* mov oC1, c1 */
9947 0x0000ffff /* end */
9949 static const float quad[] =
9951 -1.0f, -1.0f, 0.1f,
9952 -1.0f, 1.0f, 0.1f,
9953 1.0f, -1.0f, 0.1f,
9954 1.0f, 1.0f, 0.1f,
9956 static const float texquad[] =
9958 -1.0f, -1.0f, 0.1f, 0.0f, 0.0f,
9959 -1.0f, 1.0f, 0.1f, 0.0f, 1.0f,
9960 0.0f, -1.0f, 0.1f, 1.0f, 0.0f,
9961 0.0f, 1.0f, 0.1f, 1.0f, 1.0f,
9963 0.0f, -1.0f, 0.1f, 0.0f, 0.0f,
9964 0.0f, 1.0f, 0.1f, 0.0f, 1.0f,
9965 1.0f, -1.0f, 0.1f, 1.0f, 0.0f,
9966 1.0f, 1.0f, 0.1f, 1.0f, 1.0f,
9969 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9970 0, 0, 640, 480, NULL, NULL, NULL, NULL);
9971 d3d = Direct3DCreate9(D3D_SDK_VERSION);
9972 ok(!!d3d, "Failed to create a D3D object.\n");
9973 if (!(device = create_device(d3d, window, window, TRUE)))
9975 skip("Failed to create a D3D device, skipping tests.\n");
9976 goto done;
9979 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
9980 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
9981 if (caps.NumSimultaneousRTs < 2)
9983 skip("Only 1 simultaneous render target supported, skipping MRT test.\n");
9984 IDirect3DDevice9_Release(device);
9985 goto done;
9987 if (caps.PixelShaderVersion < D3DPS_VERSION(3, 0) || caps.VertexShaderVersion < D3DVS_VERSION(3, 0))
9989 skip("No shader model 3 support, skipping tests.\n");
9990 IDirect3DDevice9_Release(device);
9991 goto done;
9994 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 1.0f, 0);
9995 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr);
9997 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 16, 16,
9998 D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &readback, NULL);
9999 ok(SUCCEEDED(hr), "CreateOffscreenPlainSurface failed, hr %#x.\n", hr);
10001 hr = IDirect3DDevice9_CreateTexture(device, 16, 16, 1, D3DUSAGE_RENDERTARGET,
10002 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex1, NULL);
10003 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture failed, hr=%08x\n", hr);
10004 hr = IDirect3DDevice9_CreateTexture(device, 16, 16, 1, D3DUSAGE_RENDERTARGET,
10005 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex2, NULL);
10006 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture failed, hr=%08x\n", hr);
10007 hr = IDirect3DDevice9_CreateVertexShader(device, vshader_code, &vs);
10008 ok(SUCCEEDED(hr), "CreateVertexShader failed, hr %#x.\n", hr);
10009 hr = IDirect3DDevice9_CreatePixelShader(device, pshader_code1, &ps1);
10010 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10011 hr = IDirect3DDevice9_CreatePixelShader(device, pshader_code2, &ps2);
10012 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10014 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &backbuf);
10015 ok(hr == D3D_OK, "IDirect3DDevice9_GetRenderTarget failed, hr=%08x\n", hr);
10016 hr = IDirect3DTexture9_GetSurfaceLevel(tex1, 0, &surf1);
10017 ok(hr == D3D_OK, "IDirect3DTexture9_GetSurfaceLevel failed, hr=%08x\n", hr);
10018 hr = IDirect3DTexture9_GetSurfaceLevel(tex2, 0, &surf2);
10019 ok(hr == D3D_OK, "IDirect3DTexture9_GetSurfaceLevel failed, hr=%08x\n", hr);
10021 hr = IDirect3DDevice9_SetVertexShader(device, vs);
10022 ok(SUCCEEDED(hr), "SetVertexShader failed, hr %#x.\n", hr);
10023 hr = IDirect3DDevice9_SetRenderTarget(device, 0, surf1);
10024 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderTarget failed, hr=%08x\n", hr);
10025 hr = IDirect3DDevice9_SetRenderTarget(device, 1, surf2);
10026 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderTarget failed, hr=%08x\n", hr);
10027 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
10028 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed, hr=%08x\n", hr);
10030 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0f, 0);
10031 ok(SUCCEEDED(hr), "Clear failed, hr %#x,\n", hr);
10032 hr = IDirect3DDevice9_GetRenderTargetData(device, surf1, readback);
10033 ok(SUCCEEDED(hr), "GetRenderTargetData failed, hr %#x.\n", hr);
10034 color = getPixelColorFromSurface(readback, 8, 8);
10035 ok(color_match(color, D3DCOLOR_ARGB(0xff, 0x00, 0x00, 0xff), 0),
10036 "Expected color 0x000000ff, got 0x%08x.\n", color);
10037 hr = IDirect3DDevice9_GetRenderTargetData(device, surf2, readback);
10038 ok(SUCCEEDED(hr), "GetRenderTargetData failed, hr %#x.\n", hr);
10039 color = getPixelColorFromSurface(readback, 8, 8);
10040 ok(color_match(color, D3DCOLOR_ARGB(0xff, 0x00, 0x00, 0xff), 0),
10041 "Expected color 0x000000ff, got 0x%08x.\n", color);
10043 /* Render targets not written by the pixel shader should be unmodified. */
10044 hr = IDirect3DDevice9_SetPixelShader(device, ps1);
10045 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
10046 hr = IDirect3DDevice9_BeginScene(device);
10047 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
10048 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 3 * sizeof(float));
10049 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
10050 hr = IDirect3DDevice9_EndScene(device);
10051 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
10052 hr = IDirect3DDevice9_GetRenderTargetData(device, surf1, readback);
10053 ok(SUCCEEDED(hr), "GetRenderTargetData failed, hr %#x.\n", hr);
10054 color = getPixelColorFromSurface(readback, 8, 8);
10055 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 0),
10056 "Expected color 0xff00ff00, got 0x%08x.\n", color);
10057 hr = IDirect3DDevice9_GetRenderTargetData(device, surf2, readback);
10058 ok(SUCCEEDED(hr), "GetRenderTargetData failed, hr %#x.\n", hr);
10059 for (i = 6; i < 10; ++i)
10061 for (j = 6; j < 10; ++j)
10063 color = getPixelColorFromSurface(readback, j, i);
10064 ok(color_match(color, D3DCOLOR_ARGB(0xff, 0x00, 0x00, 0xff), 0),
10065 "Expected color 0xff0000ff, got 0x%08x at %u, %u.\n", color, j, i);
10069 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
10070 ok(SUCCEEDED(hr), "Clear failed, hr %#x,\n", hr);
10071 hr = IDirect3DDevice9_GetRenderTargetData(device, surf1, readback);
10072 ok(SUCCEEDED(hr), "GetRenderTargetData failed, hr %#x.\n", hr);
10073 color = getPixelColorFromSurface(readback, 8, 8);
10074 ok(color_match(color, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00), 0),
10075 "Expected color 0x0000ff00, got 0x%08x.\n", color);
10076 hr = IDirect3DDevice9_GetRenderTargetData(device, surf2, readback);
10077 ok(SUCCEEDED(hr), "GetRenderTargetData failed, hr %#x.\n", hr);
10078 color = getPixelColorFromSurface(readback, 8, 8);
10079 ok(color_match(color, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00), 0),
10080 "Expected color 0x0000ff00, got 0x%08x.\n", color);
10082 hr = IDirect3DDevice9_SetPixelShader(device, ps2);
10083 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
10085 hr = IDirect3DDevice9_BeginScene(device);
10086 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10088 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 3 * sizeof(float));
10089 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10091 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
10092 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10093 hr = IDirect3DDevice9_SetVertexShader(device, NULL);
10094 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
10095 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
10096 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
10097 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuf);
10098 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
10099 hr = IDirect3DDevice9_SetRenderTarget(device, 1, NULL);
10100 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
10101 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
10102 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
10104 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) tex1);
10105 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
10106 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &texquad[0], 5 * sizeof(float));
10107 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10109 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) tex2);
10110 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
10111 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &texquad[20], 5 * sizeof(float));
10112 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10114 hr = IDirect3DDevice9_EndScene(device);
10115 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10117 color = getPixelColor(device, 160, 240);
10118 ok(color == 0x0000ff00, "Texture 1(output color 1) has color 0x%08x, expected 0x0000ff00\n", color);
10119 color = getPixelColor(device, 480, 240);
10120 ok(color == 0x000000ff, "Texture 2(output color 2) has color 0x%08x, expected 0x000000ff\n", color);
10121 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
10123 IDirect3DPixelShader9_Release(ps2);
10124 IDirect3DPixelShader9_Release(ps1);
10125 IDirect3DVertexShader9_Release(vs);
10126 IDirect3DTexture9_Release(tex1);
10127 IDirect3DTexture9_Release(tex2);
10128 IDirect3DSurface9_Release(surf1);
10129 IDirect3DSurface9_Release(surf2);
10130 IDirect3DSurface9_Release(backbuf);
10131 IDirect3DSurface9_Release(readback);
10132 refcount = IDirect3DDevice9_Release(device);
10133 ok(!refcount, "Device has %u references left.\n", refcount);
10134 done:
10135 IDirect3D9_Release(d3d);
10136 DestroyWindow(window);
10139 static void pixelshader_blending_test(void)
10141 IDirect3DSurface9 *backbuffer = NULL, *offscreen = NULL;
10142 IDirect3DTexture9 *offscreenTexture = NULL;
10143 IDirect3DDevice9 *device;
10144 IDirect3D9 *d3d;
10145 ULONG refcount;
10146 int fmt_index;
10147 DWORD color;
10148 HWND window;
10149 HRESULT hr;
10151 static const struct
10153 const char *fmtName;
10154 D3DFORMAT textureFormat;
10155 D3DCOLOR resultColorBlending;
10156 D3DCOLOR resultColorNoBlending;
10158 test_formats[] =
10160 {"D3DFMT_G16R16", D3DFMT_G16R16, 0x001818ff, 0x002010ff},
10161 {"D3DFMT_R16F", D3DFMT_R16F, 0x0018ffff, 0x0020ffff},
10162 {"D3DFMT_G16R16F", D3DFMT_G16R16F, 0x001818ff, 0x002010ff},
10163 {"D3DFMT_A16B16G16R16F", D3DFMT_A16B16G16R16F, 0x00181800, 0x00201000},
10164 {"D3DFMT_R32F", D3DFMT_R32F, 0x0018ffff, 0x0020ffff},
10165 {"D3DFMT_G32R32F", D3DFMT_G32R32F, 0x001818ff, 0x002010ff},
10166 {"D3DFMT_A32B32G32R32F", D3DFMT_A32B32G32R32F, 0x00181800, 0x00201000},
10168 static const float quad[][5] =
10170 {-0.5f, -0.5f, 0.1f, 0.0f, 0.0f},
10171 {-0.5f, 0.5f, 0.1f, 0.0f, 1.0f},
10172 { 0.5f, -0.5f, 0.1f, 1.0f, 0.0f},
10173 { 0.5f, 0.5f, 0.1f, 1.0f, 1.0f},
10175 static const struct
10177 struct vec3 position;
10178 DWORD diffuse;
10180 /* Quad with R=0x10, G=0x20 */
10181 quad1[] =
10183 {{-1.0f, -1.0f, 0.1f}, 0x80102000},
10184 {{-1.0f, 1.0f, 0.1f}, 0x80102000},
10185 {{ 1.0f, -1.0f, 0.1f}, 0x80102000},
10186 {{ 1.0f, 1.0f, 0.1f}, 0x80102000},
10188 /* Quad with R=0x20, G=0x10 */
10189 quad2[] =
10191 {{-1.0f, -1.0f, 0.1f}, 0x80201000},
10192 {{-1.0f, 1.0f, 0.1f}, 0x80201000},
10193 {{ 1.0f, -1.0f, 0.1f}, 0x80201000},
10194 {{ 1.0f, 1.0f, 0.1f}, 0x80201000},
10197 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10198 0, 0, 640, 480, NULL, NULL, NULL, NULL);
10199 d3d = Direct3DCreate9(D3D_SDK_VERSION);
10200 ok(!!d3d, "Failed to create a D3D object.\n");
10201 if (!(device = create_device(d3d, window, window, TRUE)))
10203 skip("Failed to create a D3D device, skipping tests.\n");
10204 goto done;
10207 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
10208 ok(hr == D3D_OK, "Can't get back buffer, hr = %08x\n", hr);
10210 for (fmt_index = 0; fmt_index < sizeof(test_formats) / sizeof(*test_formats); ++fmt_index)
10212 D3DFORMAT fmt = test_formats[fmt_index].textureFormat;
10214 if (IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
10215 D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, fmt) != D3D_OK)
10217 skip("%s textures not supported as render targets.\n", test_formats[fmt_index].fmtName);
10218 continue;
10221 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
10222 ok(hr == D3D_OK, "Clear failed, hr = %08x\n", hr);
10224 hr = IDirect3DDevice9_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET, fmt, D3DPOOL_DEFAULT, &offscreenTexture, NULL);
10225 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "Creating the offscreen render target failed, hr = %08x\n", hr);
10226 if(!offscreenTexture) {
10227 continue;
10230 hr = IDirect3DTexture9_GetSurfaceLevel(offscreenTexture, 0, &offscreen);
10231 ok(hr == D3D_OK, "Can't get offscreen surface, hr = %08x\n", hr);
10232 if(!offscreen) {
10233 continue;
10236 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
10237 ok(hr == D3D_OK, "SetFVF failed, hr = %08x\n", hr);
10239 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
10240 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
10241 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
10242 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
10243 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
10244 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_MINFILTER failed (0x%08x)\n", hr);
10245 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
10246 ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr);
10247 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
10248 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
10250 /* Below we will draw two quads with different colors and try to blend
10251 * them together. The result color is compared with the expected
10252 * outcome. */
10253 hr = IDirect3DDevice9_BeginScene(device);
10254 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10256 hr = IDirect3DDevice9_SetRenderTarget(device, 0, offscreen);
10257 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
10258 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00ffffff, 1.0f, 0);
10259 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
10261 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHABLENDENABLE, TRUE);
10262 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10264 /* Draw a quad using color 0x0010200. */
10265 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_ONE);
10266 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10267 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_ZERO);
10268 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10269 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(quad1[0]));
10270 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10272 /* Draw a quad using color 0x0020100. */
10273 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
10274 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10275 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
10276 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10277 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(quad2[0]));
10278 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10280 /* We don't want to blend the result on the backbuffer. */
10281 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHABLENDENABLE, FALSE);
10282 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
10284 /* Prepare rendering the 'blended' texture quad to the backbuffer. */
10285 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
10286 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
10287 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)offscreenTexture);
10288 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
10290 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
10291 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
10293 /* This time with the texture. */
10294 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
10295 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 if (IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
10301 D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, D3DRTYPE_TEXTURE, fmt) == D3D_OK)
10303 /* Compare the color of the center quad with our expectation. */
10304 color = getPixelColor(device, 320, 240);
10305 ok(color_match(color, test_formats[fmt_index].resultColorBlending, 1),
10306 "Offscreen failed for %s: Got color 0x%08x, expected 0x%08x.\n",
10307 test_formats[fmt_index].fmtName, color, test_formats[fmt_index].resultColorBlending);
10309 else
10311 /* No pixel shader blending is supported so expect garbage. The
10312 * type of 'garbage' depends on the driver version and OS. E.g. on
10313 * G16R16 ATI reports (on old r9600 drivers) 0x00ffffff and on
10314 * modern ones 0x002010ff which is also what NVIDIA reports. On
10315 * Vista NVIDIA seems to report 0x00ffffff on Geforce7 cards. */
10316 color = getPixelColor(device, 320, 240);
10317 ok((color == 0x00ffffff) || (color == test_formats[fmt_index].resultColorNoBlending),
10318 "Offscreen failed for %s: Got unexpected color 0x%08x, expected no color blending.\n",
10319 test_formats[fmt_index].fmtName, color);
10321 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
10323 IDirect3DDevice9_SetTexture(device, 0, NULL);
10324 if(offscreenTexture) {
10325 IDirect3DTexture9_Release(offscreenTexture);
10327 if(offscreen) {
10328 IDirect3DSurface9_Release(offscreen);
10332 IDirect3DSurface9_Release(backbuffer);
10333 refcount = IDirect3DDevice9_Release(device);
10334 ok(!refcount, "Device has %u references left.\n", refcount);
10335 done:
10336 IDirect3D9_Release(d3d);
10337 DestroyWindow(window);
10340 static void tssargtemp_test(void)
10342 IDirect3DDevice9 *device;
10343 IDirect3D9 *d3d;
10344 D3DCOLOR color;
10345 ULONG refcount;
10346 D3DCAPS9 caps;
10347 HWND window;
10348 HRESULT hr;
10350 static const struct
10352 struct vec3 position;
10353 DWORD diffuse;
10355 quad[] =
10357 {{-1.0f, -1.0f, 0.1f}, 0x00ff0000},
10358 {{-1.0f, 1.0f, 0.1f}, 0x00ff0000},
10359 {{ 1.0f, -1.0f, 0.1f}, 0x00ff0000},
10360 {{ 1.0f, 1.0f, 0.1f}, 0x00ff0000},
10363 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10364 0, 0, 640, 480, NULL, NULL, NULL, NULL);
10365 d3d = Direct3DCreate9(D3D_SDK_VERSION);
10366 ok(!!d3d, "Failed to create a D3D object.\n");
10367 if (!(device = create_device(d3d, window, window, TRUE)))
10369 skip("Failed to create a D3D device, skipping tests.\n");
10370 goto done;
10373 memset(&caps, 0, sizeof(caps));
10374 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
10375 ok(hr == D3D_OK, "IDirect3DDevice9_GetDeviceCaps failed with %08x\n", hr);
10376 if(!(caps.PrimitiveMiscCaps & D3DPMISCCAPS_TSSARGTEMP)) {
10377 skip("D3DPMISCCAPS_TSSARGTEMP not supported\n");
10378 IDirect3DDevice9_Release(device);
10379 goto done;
10382 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff000000, 1.0f, 0);
10383 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
10385 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
10386 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
10387 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
10388 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
10390 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
10391 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
10392 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_TFACTOR);
10393 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
10394 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_RESULTARG, D3DTA_TEMP);
10395 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
10397 hr = IDirect3DDevice9_SetTextureStageState(device, 2, D3DTSS_COLOROP, D3DTOP_ADD);
10398 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
10399 hr = IDirect3DDevice9_SetTextureStageState(device, 2, D3DTSS_COLORARG1, D3DTA_CURRENT);
10400 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
10401 hr = IDirect3DDevice9_SetTextureStageState(device, 2, D3DTSS_COLORARG2, D3DTA_TEMP);
10402 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
10404 hr = IDirect3DDevice9_SetTextureStageState(device, 3, D3DTSS_COLOROP, D3DTOP_DISABLE);
10405 ok(hr == D3D_OK, "SetTextureStageState failed, hr = %08x\n", hr);
10407 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0x0000ff00);
10408 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed, hr = %08x\n", hr);
10409 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
10410 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
10411 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
10412 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed, hr = %08x\n", hr);
10414 hr = IDirect3DDevice9_BeginScene(device);
10415 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10416 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
10417 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10418 hr = IDirect3DDevice9_EndScene(device);
10419 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10421 color = getPixelColor(device, 320, 240);
10422 ok(color == 0x00ffff00, "TSSARGTEMP test returned color 0x%08x, expected 0x00ffff00\n", color);
10423 IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
10425 refcount = IDirect3DDevice9_Release(device);
10426 ok(!refcount, "Device has %u references left.\n", refcount);
10427 done:
10428 IDirect3D9_Release(d3d);
10429 DestroyWindow(window);
10432 /* Drawing Indexed Geometry with instances*/
10433 static void stream_test(void)
10435 IDirect3DVertexDeclaration9 *pDecl = NULL;
10436 IDirect3DVertexShader9 *shader = NULL;
10437 IDirect3DVertexBuffer9 *vb3 = NULL;
10438 IDirect3DVertexBuffer9 *vb2 = NULL;
10439 IDirect3DVertexBuffer9 *vb = NULL;
10440 IDirect3DIndexBuffer9 *ib = NULL;
10441 IDirect3DDevice9 *device;
10442 IDirect3D9 *d3d;
10443 ULONG refcount;
10444 D3DCAPS9 caps;
10445 DWORD color;
10446 HWND window;
10447 unsigned i;
10448 HRESULT hr;
10449 BYTE *data;
10450 DWORD ind;
10452 static const struct testdata
10454 DWORD idxVertex; /* number of instances in the first stream */
10455 DWORD idxColor; /* number of instances in the second stream */
10456 DWORD idxInstance; /* should be 1 ?? */
10457 DWORD color1; /* color 1 instance */
10458 DWORD color2; /* color 2 instance */
10459 DWORD color3; /* color 3 instance */
10460 DWORD color4; /* color 4 instance */
10461 WORD strVertex; /* specify which stream to use 0-2*/
10462 WORD strColor;
10463 WORD strInstance;
10465 testcases[]=
10467 {4, 4, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0, 1, 2}, /* 0 */
10468 {3, 4, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ffffff, 0, 1, 2}, /* 1 */
10469 {2, 4, 1, 0x00ff0000, 0x00ff0000, 0x00ffffff, 0x00ffffff, 0, 1, 2}, /* 2 */
10470 {1, 4, 1, 0x00ff0000, 0x00ffffff, 0x00ffffff, 0x00ffffff, 0, 1, 2}, /* 3 */
10471 {4, 3, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0, 1, 2}, /* 4 */
10472 {4, 2, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0, 1, 2}, /* 5 */
10473 {4, 1, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0, 1, 2}, /* 6 */
10474 {4, 0, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0, 1, 2}, /* 7 */
10475 {3, 3, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ffffff, 0, 1, 2}, /* 8 */
10476 {4, 4, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 1, 0, 2}, /* 9 */
10477 {4, 4, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0, 2, 1}, /* 10 */
10478 {4, 4, 1, 0x00ff0000, 0x00ffffff, 0x00ffffff, 0x00ffffff, 2, 3, 1}, /* 11 */
10479 {4, 4, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 2, 0, 1}, /* 12 */
10480 {4, 4, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 1, 2, 3}, /* 13 */
10481 #if 0
10482 /* This draws one instance on some machines, no instance on others. */
10483 {0, 4, 1, 0x00ff0000, 0x00ffffff, 0x00ffffff, 0x00ffffff, 0, 1, 2}, /* 14 */
10484 /* This case is handled in a stand alone test,
10485 * SetStreamSourceFreq(0, (D3DSTREAMSOURCE_INSTANCEDATA | 1)) has to
10486 * return D3DERR_INVALIDCALL. */
10487 {4, 4, 1, 0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff, 2, 1, 0}, /* 15 */
10488 #endif
10490 static const DWORD shader_code[] =
10492 0xfffe0101, /* vs_1_1 */
10493 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
10494 0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
10495 0x0000001f, 0x80000005, 0x900f0002, /* dcl_texcoord v2 */
10496 0x00000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
10497 0x00000002, 0xc00f0000, 0x80e40000, 0x90e40002, /* add oPos, r0, v2 */
10498 0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
10499 0x0000ffff
10501 static const float quad[][3] =
10503 {-0.5f, -0.5f, 1.1f}, /*0 */
10504 {-0.5f, 0.5f, 1.1f}, /*1 */
10505 { 0.5f, -0.5f, 1.1f}, /*2 */
10506 { 0.5f, 0.5f, 1.1f}, /*3 */
10508 static const float vertcolor[][4] =
10510 {1.0f, 0.0f, 0.0f, 1.0f}, /*0 */
10511 {1.0f, 0.0f, 0.0f, 1.0f}, /*1 */
10512 {1.0f, 0.0f, 0.0f, 1.0f}, /*2 */
10513 {1.0f, 0.0f, 0.0f, 1.0f}, /*3 */
10515 /* 4 position for 4 instances */
10516 static const float instancepos[][3] =
10518 {-0.6f,-0.6f, 0.0f},
10519 { 0.6f,-0.6f, 0.0f},
10520 { 0.6f, 0.6f, 0.0f},
10521 {-0.6f, 0.6f, 0.0f},
10523 static const short indices[] = {0, 1, 2, 2, 1, 3};
10524 D3DVERTEXELEMENT9 decl[] =
10526 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
10527 {1, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
10528 {2, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
10529 D3DDECL_END()
10532 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10533 0, 0, 640, 480, NULL, NULL, NULL, NULL);
10534 d3d = Direct3DCreate9(D3D_SDK_VERSION);
10535 ok(!!d3d, "Failed to create a D3D object.\n");
10536 if (!(device = create_device(d3d, window, window, TRUE)))
10538 skip("Failed to create a D3D device, skipping tests.\n");
10539 goto done;
10542 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
10543 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
10544 if (caps.VertexShaderVersion < D3DVS_VERSION(3, 0))
10546 skip("No vs_3_0 support, skipping tests.\n");
10547 IDirect3DDevice9_Release(device);
10548 goto done;
10551 /* set the default value because it isn't done in wine? */
10552 hr = IDirect3DDevice9_SetStreamSourceFreq(device, 1, 1);
10553 ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr);
10555 /* check for D3DSTREAMSOURCE_INDEXEDDATA at stream0 */
10556 hr = IDirect3DDevice9_SetStreamSourceFreq(device, 0, (D3DSTREAMSOURCE_INSTANCEDATA | 1));
10557 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr);
10559 /* check wrong cases */
10560 hr = IDirect3DDevice9_SetStreamSourceFreq(device, 1, 0);
10561 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr);
10562 hr = IDirect3DDevice9_GetStreamSourceFreq(device, 1, &ind);
10563 ok(hr == D3D_OK && ind == 1, "IDirect3DDevice9_GetStreamSourceFreq failed with %08x\n", hr);
10564 hr = IDirect3DDevice9_SetStreamSourceFreq(device, 1, 2);
10565 ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr);
10566 hr = IDirect3DDevice9_GetStreamSourceFreq(device, 1, &ind);
10567 ok(hr == D3D_OK && ind == 2, "IDirect3DDevice9_GetStreamSourceFreq failed with %08x\n", hr);
10568 hr = IDirect3DDevice9_SetStreamSourceFreq(device, 1, (D3DSTREAMSOURCE_INDEXEDDATA | 0));
10569 ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr);
10570 hr = IDirect3DDevice9_GetStreamSourceFreq(device, 1, &ind);
10571 ok(hr == D3D_OK && ind == (D3DSTREAMSOURCE_INDEXEDDATA | 0), "IDirect3DDevice9_GetStreamSourceFreq failed with %08x\n", hr);
10572 hr = IDirect3DDevice9_SetStreamSourceFreq(device, 1, (D3DSTREAMSOURCE_INSTANCEDATA | 0));
10573 ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr);
10574 hr = IDirect3DDevice9_GetStreamSourceFreq(device, 1, &ind);
10575 ok(hr == D3D_OK && ind == (0U | D3DSTREAMSOURCE_INSTANCEDATA), "IDirect3DDevice9_GetStreamSourceFreq failed with %08x\n", hr);
10576 hr = IDirect3DDevice9_SetStreamSourceFreq(device, 1, (D3DSTREAMSOURCE_INSTANCEDATA | D3DSTREAMSOURCE_INDEXEDDATA | 0));
10577 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr);
10578 hr = IDirect3DDevice9_GetStreamSourceFreq(device, 1, &ind);
10579 ok(hr == D3D_OK && ind == (0U | D3DSTREAMSOURCE_INSTANCEDATA), "IDirect3DDevice9_GetStreamSourceFreq failed with %08x\n", hr);
10581 /* set the default value back */
10582 hr = IDirect3DDevice9_SetStreamSourceFreq(device, 1, 1);
10583 ok(hr == D3D_OK, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr);
10585 /* create all VertexBuffers*/
10586 hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(quad), 0, 0, D3DPOOL_MANAGED, &vb, NULL);
10587 ok(hr == D3D_OK, "CreateVertexBuffer failed with %08x\n", hr);
10588 if(!vb) {
10589 skip("Failed to create a vertex buffer\n");
10590 IDirect3DDevice9_Release(device);
10591 goto done;
10593 hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(vertcolor), 0, 0, D3DPOOL_MANAGED, &vb2, NULL);
10594 ok(hr == D3D_OK, "CreateVertexBuffer failed with %08x\n", hr);
10595 if(!vb2) {
10596 skip("Failed to create a vertex buffer\n");
10597 goto out;
10599 hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(instancepos), 0, 0, D3DPOOL_MANAGED, &vb3, NULL);
10600 ok(hr == D3D_OK, "CreateVertexBuffer failed with %08x\n", hr);
10601 if(!vb3) {
10602 skip("Failed to create a vertex buffer\n");
10603 goto out;
10606 /* create IndexBuffer*/
10607 hr = IDirect3DDevice9_CreateIndexBuffer(device, sizeof(indices), 0, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &ib, NULL);
10608 ok(hr == D3D_OK, "IDirect3DDevice9_CreateIndexBuffer failed with %08x\n", hr);
10609 if(!ib) {
10610 skip("Failed to create an index buffer\n");
10611 goto out;
10614 /* copy all Buffers (Vertex + Index)*/
10615 hr = IDirect3DVertexBuffer9_Lock(vb, 0, sizeof(quad), (void **) &data, 0);
10616 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr);
10617 memcpy(data, quad, sizeof(quad));
10618 hr = IDirect3DVertexBuffer9_Unlock(vb);
10619 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed with %08x\n", hr);
10620 hr = IDirect3DVertexBuffer9_Lock(vb2, 0, sizeof(vertcolor), (void **) &data, 0);
10621 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr);
10622 memcpy(data, vertcolor, sizeof(vertcolor));
10623 hr = IDirect3DVertexBuffer9_Unlock(vb2);
10624 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed with %08x\n", hr);
10625 hr = IDirect3DVertexBuffer9_Lock(vb3, 0, sizeof(instancepos), (void **) &data, 0);
10626 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr);
10627 memcpy(data, instancepos, sizeof(instancepos));
10628 hr = IDirect3DVertexBuffer9_Unlock(vb3);
10629 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed with %08x\n", hr);
10630 hr = IDirect3DIndexBuffer9_Lock(ib, 0, sizeof(indices), (void **) &data, 0);
10631 ok(hr == D3D_OK, "IDirect3DIndexBuffer9_Lock failed with %08x\n", hr);
10632 memcpy(data, indices, sizeof(indices));
10633 hr = IDirect3DIndexBuffer9_Unlock(ib);
10634 ok(hr == D3D_OK, "IDirect3DIndexBuffer9_Unlock failed with %08x\n", hr);
10636 /* create VertexShader */
10637 hr = IDirect3DDevice9_CreateVertexShader(device, shader_code, &shader);
10638 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateVertexShader failed hr=%08x\n", hr);
10639 if(!shader) {
10640 skip("Failed to create a vetex shader\n");
10641 goto out;
10644 hr = IDirect3DDevice9_SetVertexShader(device, shader);
10645 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShader failed hr=%08x\n", hr);
10647 hr = IDirect3DDevice9_SetIndices(device, ib);
10648 ok(hr == D3D_OK, "IDirect3DDevice9_SetIndices failed with %08x\n", hr);
10650 /* run all tests */
10651 for( i = 0; i < sizeof(testcases)/sizeof(testcases[0]); ++i)
10653 struct testdata act = testcases[i];
10654 decl[0].Stream = act.strVertex;
10655 decl[1].Stream = act.strColor;
10656 decl[2].Stream = act.strInstance;
10657 /* create VertexDeclarations */
10658 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl, &pDecl);
10659 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateVertexDeclaration failed hr=%08x (case %i)\n", hr, i);
10661 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
10662 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x (case %i)\n", hr, i);
10664 hr = IDirect3DDevice9_BeginScene(device);
10665 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10667 hr = IDirect3DDevice9_SetVertexDeclaration(device, pDecl);
10668 ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr);
10670 hr = IDirect3DDevice9_SetStreamSourceFreq(device, act.strVertex,
10671 (D3DSTREAMSOURCE_INDEXEDDATA | act.idxVertex));
10672 ok(SUCCEEDED(hr), "Failed to set stream source frequency, hr %#x.\n", hr);
10673 hr = IDirect3DDevice9_SetStreamSource(device, act.strVertex, vb, 0, sizeof(quad[0]));
10674 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
10676 hr = IDirect3DDevice9_SetStreamSourceFreq(device, act.strColor,
10677 (D3DSTREAMSOURCE_INDEXEDDATA | act.idxColor));
10678 ok(SUCCEEDED(hr), "Failed to set stream source frequency, hr %#x.\n", hr);
10679 hr = IDirect3DDevice9_SetStreamSource(device, act.strColor, vb2, 0, sizeof(vertcolor[0]));
10680 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
10682 hr = IDirect3DDevice9_SetStreamSourceFreq(device, act.strInstance,
10683 (D3DSTREAMSOURCE_INSTANCEDATA | act.idxInstance));
10684 ok(SUCCEEDED(hr), "Failed to set stream source frequency, hr %#x.\n", hr);
10685 hr = IDirect3DDevice9_SetStreamSource(device, act.strInstance, vb3, 0, sizeof(instancepos[0]));
10686 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
10688 hr = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2);
10689 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10690 hr = IDirect3DDevice9_EndScene(device);
10691 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10693 /* set all StreamSource && StreamSourceFreq back to default */
10694 hr = IDirect3DDevice9_SetStreamSourceFreq(device, act.strVertex, 1);
10695 ok(SUCCEEDED(hr), "Failed to set stream source frequency, hr %#x.\n", hr);
10696 hr = IDirect3DDevice9_SetStreamSource(device, act.strVertex, NULL, 0, 0);
10697 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
10698 hr = IDirect3DDevice9_SetStreamSourceFreq(device, act.idxColor, 1);
10699 ok(SUCCEEDED(hr), "Failed to set stream source frequency, hr %#x.\n", hr);
10700 hr = IDirect3DDevice9_SetStreamSource(device, act.idxColor, NULL, 0, 0);
10701 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
10702 hr = IDirect3DDevice9_SetStreamSourceFreq(device, act.idxInstance, 1);
10703 ok(SUCCEEDED(hr), "Failed to set stream source frequency, hr %#x.\n", hr);
10704 hr = IDirect3DDevice9_SetStreamSource(device, act.idxInstance, NULL, 0, 0);
10705 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
10707 hr = IDirect3DVertexDeclaration9_Release(pDecl);
10708 ok(hr == D3D_OK, "IDirect3DVertexDeclaration9_Release failed with %08x (case %i)\n", hr, i);
10710 color = getPixelColor(device, 160, 360);
10711 ok(color == act.color1, "has color 0x%08x, expected 0x%08x (case %i)\n", color, act.color1, i);
10712 color = getPixelColor(device, 480, 360);
10713 ok(color == act.color2, "has color 0x%08x, expected 0x%08x (case %i)\n", color, act.color2, i);
10714 color = getPixelColor(device, 480, 120);
10715 ok(color == act.color3, "has color 0x%08x, expected 0x%08x (case %i)\n", color, act.color3, i);
10716 color = getPixelColor(device, 160, 120);
10717 ok(color == act.color4, "has color 0x%08x, expected 0x%08x (case %i)\n", color, act.color4, i);
10719 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
10720 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x (case %i)\n", hr, i);
10723 out:
10724 if(vb) IDirect3DVertexBuffer9_Release(vb);
10725 if(vb2)IDirect3DVertexBuffer9_Release(vb2);
10726 if(vb3)IDirect3DVertexBuffer9_Release(vb3);
10727 if(ib)IDirect3DIndexBuffer9_Release(ib);
10728 if(shader)IDirect3DVertexShader9_Release(shader);
10729 refcount = IDirect3DDevice9_Release(device);
10730 ok(!refcount, "Device has %u references left.\n", refcount);
10731 done:
10732 IDirect3D9_Release(d3d);
10733 DestroyWindow(window);
10736 static void np2_stretch_rect_test(void)
10738 IDirect3DSurface9 *src = NULL, *dst = NULL, *backbuffer = NULL;
10739 IDirect3DTexture9 *dsttex = NULL;
10740 IDirect3DDevice9 *device;
10741 IDirect3D9 *d3d;
10742 D3DCOLOR color;
10743 ULONG refcount;
10744 HWND window;
10745 HRESULT hr;
10747 static const D3DRECT r1 = {0, 0, 50, 50 };
10748 static const D3DRECT r2 = {50, 0, 100, 50 };
10749 static const D3DRECT r3 = {50, 50, 100, 100};
10750 static const D3DRECT r4 = {0, 50, 50, 100};
10751 static const float quad[] =
10753 -1.0f, -1.0f, 0.1f, 0.0f, 0.0f,
10754 -1.0f, 1.0f, 0.1f, 0.0f, 1.0f,
10755 1.0f, -1.0f, 0.1f, 1.0f, 0.0f,
10756 1.0f, 1.0f, 0.1f, 1.0f, 1.0f,
10759 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10760 0, 0, 640, 480, NULL, NULL, NULL, NULL);
10761 d3d = Direct3DCreate9(D3D_SDK_VERSION);
10762 ok(!!d3d, "Failed to create a D3D object.\n");
10763 if (!(device = create_device(d3d, window, window, TRUE)))
10765 skip("Failed to create a D3D device, skipping tests.\n");
10766 goto done;
10769 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
10770 ok(hr == D3D_OK, "IDirect3DDevice9_GetBackBuffer failed with %08x\n", hr);
10772 hr = IDirect3DDevice9_CreateRenderTarget(device, 100, 100, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, TRUE, &src, NULL );
10773 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_CreateRenderTarget failed with %08x\n", hr);
10774 hr = IDirect3DDevice9_CreateTexture(device, 25, 25, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &dsttex, NULL);
10775 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_CreateTexture failed with %08x\n", hr);
10777 if(!src || !dsttex) {
10778 skip("One or more test resources could not be created\n");
10779 goto cleanup;
10782 hr = IDirect3DTexture9_GetSurfaceLevel(dsttex, 0, &dst);
10783 ok(hr == D3D_OK, "IDirect3DTexture9_GetSurfaceLevel failed with %08x\n", hr);
10785 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ffff, 1.0f, 0);
10786 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
10788 /* Clear the StretchRect destination for debugging */
10789 hr = IDirect3DDevice9_SetRenderTarget(device, 0, dst);
10790 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderTarget failed with %08x\n", hr);
10791 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0);
10792 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
10794 hr = IDirect3DDevice9_SetRenderTarget(device, 0, src);
10795 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderTarget failed with %08x\n", hr);
10797 hr = IDirect3DDevice9_Clear(device, 1, &r1, D3DCLEAR_TARGET, 0xffff0000, 0.0, 0);
10798 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
10799 hr = IDirect3DDevice9_Clear(device, 1, &r2, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
10800 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
10801 hr = IDirect3DDevice9_Clear(device, 1, &r3, D3DCLEAR_TARGET, 0xff0000ff, 0.0, 0);
10802 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
10803 hr = IDirect3DDevice9_Clear(device, 1, &r4, D3DCLEAR_TARGET, 0xff000000, 0.0, 0);
10804 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
10806 /* Stretchrect before setting the render target back to the backbuffer. This will make Wine use
10807 * the target -> texture GL blit path
10809 hr = IDirect3DDevice9_StretchRect(device, src, NULL, dst, NULL, D3DTEXF_POINT);
10810 ok(hr == D3D_OK, "IDirect3DDevice9_StretchRect failed with %08x\n", hr);
10811 IDirect3DSurface9_Release(dst);
10813 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
10814 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderTarget failed with %08x\n", hr);
10816 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) dsttex);
10817 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture failed with %08x\n", hr);
10818 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
10819 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
10820 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
10821 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with %08x\n", hr);
10822 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
10823 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with %08x\n", hr);
10825 hr = IDirect3DDevice9_BeginScene(device);
10826 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10827 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(float) * 5);
10828 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10829 hr = IDirect3DDevice9_EndScene(device);
10830 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10832 color = getPixelColor(device, 160, 360);
10833 ok(color == 0x00ff0000, "stretchrect: Pixel 160,360 has color 0x%08x, expected 0x00ff0000\n", color);
10834 color = getPixelColor(device, 480, 360);
10835 ok(color == 0x0000ff00, "stretchrect: Pixel 480,360 has color 0x%08x, expected 0x0000ff00\n", color);
10836 color = getPixelColor(device, 480, 120);
10837 ok(color == 0x000000ff, "stretchrect: Pixel 480,120 has color 0x%08x, expected 0x000000ff\n", color);
10838 color = getPixelColor(device, 160, 120);
10839 ok(color == 0x00000000, "stretchrect: Pixel 160,120 has color 0x%08x, expected 0x00000000\n", color);
10840 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
10841 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
10843 cleanup:
10844 if(src) IDirect3DSurface9_Release(src);
10845 if(backbuffer) IDirect3DSurface9_Release(backbuffer);
10846 if(dsttex) IDirect3DTexture9_Release(dsttex);
10847 refcount = IDirect3DDevice9_Release(device);
10848 ok(!refcount, "Device has %u references left.\n", refcount);
10849 done:
10850 IDirect3D9_Release(d3d);
10851 DestroyWindow(window);
10854 static void texop_test(void)
10856 IDirect3DVertexDeclaration9 *vertex_declaration = NULL;
10857 IDirect3DTexture9 *texture = NULL;
10858 D3DLOCKED_RECT locked_rect;
10859 IDirect3DDevice9 *device;
10860 IDirect3D9 *d3d;
10861 D3DCOLOR color;
10862 ULONG refcount;
10863 D3DCAPS9 caps;
10864 HWND window;
10865 HRESULT hr;
10866 unsigned i;
10868 static const struct {
10869 float x, y, z;
10870 float s, t;
10871 D3DCOLOR diffuse;
10872 } quad[] = {
10873 {-1.0f, -1.0f, 0.1f, -1.0f, -1.0f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00)},
10874 {-1.0f, 1.0f, 0.1f, -1.0f, 1.0f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00)},
10875 { 1.0f, -1.0f, 0.1f, 1.0f, -1.0f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00)},
10876 { 1.0f, 1.0f, 0.1f, 1.0f, 1.0f, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00)}
10879 static const D3DVERTEXELEMENT9 decl_elements[] = {
10880 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
10881 {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
10882 {0, 20, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
10883 D3DDECL_END()
10886 static const struct {
10887 D3DTEXTUREOP op;
10888 const char *name;
10889 DWORD caps_flag;
10890 D3DCOLOR result;
10891 } test_data[] = {
10892 {D3DTOP_SELECTARG1, "SELECTARG1", D3DTEXOPCAPS_SELECTARG1, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00)},
10893 {D3DTOP_SELECTARG2, "SELECTARG2", D3DTEXOPCAPS_SELECTARG2, D3DCOLOR_ARGB(0x00, 0x33, 0x33, 0x33)},
10894 {D3DTOP_MODULATE, "MODULATE", D3DTEXOPCAPS_MODULATE, D3DCOLOR_ARGB(0x00, 0x00, 0x33, 0x00)},
10895 {D3DTOP_MODULATE2X, "MODULATE2X", D3DTEXOPCAPS_MODULATE2X, D3DCOLOR_ARGB(0x00, 0x00, 0x66, 0x00)},
10896 {D3DTOP_MODULATE4X, "MODULATE4X", D3DTEXOPCAPS_MODULATE4X, D3DCOLOR_ARGB(0x00, 0x00, 0xcc, 0x00)},
10897 {D3DTOP_ADD, "ADD", D3DTEXOPCAPS_ADD, D3DCOLOR_ARGB(0x00, 0x33, 0xff, 0x33)},
10898 {D3DTOP_ADDSIGNED, "ADDSIGNED", D3DTEXOPCAPS_ADDSIGNED, D3DCOLOR_ARGB(0x00, 0x00, 0xb2, 0x00)},
10899 {D3DTOP_ADDSIGNED2X, "ADDSIGNED2X", D3DTEXOPCAPS_ADDSIGNED2X, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00)},
10900 {D3DTOP_SUBTRACT, "SUBTRACT", D3DTEXOPCAPS_SUBTRACT, D3DCOLOR_ARGB(0x00, 0x00, 0xcc, 0x00)},
10901 {D3DTOP_ADDSMOOTH, "ADDSMOOTH", D3DTEXOPCAPS_ADDSMOOTH, D3DCOLOR_ARGB(0x00, 0x33, 0xff, 0x33)},
10902 {D3DTOP_BLENDDIFFUSEALPHA, "BLENDDIFFUSEALPHA", D3DTEXOPCAPS_BLENDDIFFUSEALPHA, D3DCOLOR_ARGB(0x00, 0x22, 0x77, 0x22)},
10903 {D3DTOP_BLENDTEXTUREALPHA, "BLENDTEXTUREALPHA", D3DTEXOPCAPS_BLENDTEXTUREALPHA, D3DCOLOR_ARGB(0x00, 0x14, 0xad, 0x14)},
10904 {D3DTOP_BLENDFACTORALPHA, "BLENDFACTORALPHA", D3DTEXOPCAPS_BLENDFACTORALPHA, D3DCOLOR_ARGB(0x00, 0x07, 0xe4, 0x07)},
10905 {D3DTOP_BLENDTEXTUREALPHAPM, "BLENDTEXTUREALPHAPM", D3DTEXOPCAPS_BLENDTEXTUREALPHAPM, D3DCOLOR_ARGB(0x00, 0x14, 0xff, 0x14)},
10906 {D3DTOP_BLENDCURRENTALPHA, "BLENDCURRENTALPHA", D3DTEXOPCAPS_BLENDCURRENTALPHA, D3DCOLOR_ARGB(0x00, 0x22, 0x77, 0x22)},
10907 {D3DTOP_MODULATEALPHA_ADDCOLOR, "MODULATEALPHA_ADDCOLOR", D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR, D3DCOLOR_ARGB(0x00, 0x1f, 0xff, 0x1f)},
10908 {D3DTOP_MODULATECOLOR_ADDALPHA, "MODULATECOLOR_ADDALPHA", D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA, D3DCOLOR_ARGB(0x00, 0x99, 0xcc, 0x99)},
10909 {D3DTOP_MODULATEINVALPHA_ADDCOLOR, "MODULATEINVALPHA_ADDCOLOR", D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR, D3DCOLOR_ARGB(0x00, 0x14, 0xff, 0x14)},
10910 {D3DTOP_MODULATEINVCOLOR_ADDALPHA, "MODULATEINVCOLOR_ADDALPHA", D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA, D3DCOLOR_ARGB(0x00, 0xcc, 0x99, 0xcc)},
10911 /* BUMPENVMAP & BUMPENVMAPLUMINANCE have their own tests */
10912 {D3DTOP_DOTPRODUCT3, "DOTPRODUCT3", D3DTEXOPCAPS_DOTPRODUCT3, D3DCOLOR_ARGB(0x00, 0x99, 0x99, 0x99)},
10913 {D3DTOP_MULTIPLYADD, "MULTIPLYADD", D3DTEXOPCAPS_MULTIPLYADD, D3DCOLOR_ARGB(0x00, 0xff, 0x33, 0x00)},
10914 {D3DTOP_LERP, "LERP", D3DTEXOPCAPS_LERP, D3DCOLOR_ARGB(0x00, 0x00, 0x33, 0x33)},
10917 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10918 0, 0, 640, 480, NULL, NULL, NULL, NULL);
10919 d3d = Direct3DCreate9(D3D_SDK_VERSION);
10920 ok(!!d3d, "Failed to create a D3D object.\n");
10921 if (!(device = create_device(d3d, window, window, TRUE)))
10923 skip("Failed to create a D3D device, skipping tests.\n");
10924 goto done;
10927 memset(&caps, 0, sizeof(caps));
10928 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
10929 ok(SUCCEEDED(hr), "GetDeviceCaps failed with 0x%08x\n", hr);
10931 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &vertex_declaration);
10932 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed with 0x%08x\n", hr);
10933 hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration);
10934 ok(SUCCEEDED(hr), "SetVertexDeclaration failed with 0x%08x\n", hr);
10936 hr = IDirect3DDevice9_CreateTexture(device, 1, 1, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture, NULL);
10937 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateTexture failed with 0x%08x\n", hr);
10938 hr = IDirect3DTexture9_LockRect(texture, 0, &locked_rect, NULL, 0);
10939 ok(SUCCEEDED(hr), "LockRect failed with 0x%08x\n", hr);
10940 *((DWORD *)locked_rect.pBits) = D3DCOLOR_ARGB(0x99, 0x00, 0xff, 0x00);
10941 hr = IDirect3DTexture9_UnlockRect(texture, 0);
10942 ok(SUCCEEDED(hr), "UnlockRect failed with 0x%08x\n", hr);
10943 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
10944 ok(SUCCEEDED(hr), "SetTexture failed with 0x%08x\n", hr);
10946 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG0, D3DTA_DIFFUSE);
10947 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
10948 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
10949 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
10950 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
10951 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
10953 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
10954 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
10956 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
10957 ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
10958 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0xdd333333);
10959 ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
10960 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA);
10961 ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
10963 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
10964 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
10966 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
10968 if (!(caps.TextureOpCaps & test_data[i].caps_flag))
10970 skip("tex operation %s not supported\n", test_data[i].name);
10971 continue;
10974 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, test_data[i].op);
10975 ok(SUCCEEDED(hr), "SetTextureStageState (%s) failed with 0x%08x\n", test_data[i].name, hr);
10977 hr = IDirect3DDevice9_BeginScene(device);
10978 ok(SUCCEEDED(hr), "BeginScene failed with 0x%08x\n", hr);
10980 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
10981 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed with 0x%08x\n", hr);
10983 hr = IDirect3DDevice9_EndScene(device);
10984 ok(SUCCEEDED(hr), "EndScene failed with 0x%08x\n", hr);
10986 color = getPixelColor(device, 320, 240);
10987 ok(color_match(color, test_data[i].result, 3), "Operation %s returned color 0x%08x, expected 0x%08x\n",
10988 test_data[i].name, color, test_data[i].result);
10990 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
10991 ok(SUCCEEDED(hr), "Present failed with 0x%08x\n", hr);
10994 IDirect3DTexture9_Release(texture);
10995 IDirect3DVertexDeclaration9_Release(vertex_declaration);
10996 refcount = IDirect3DDevice9_Release(device);
10997 ok(!refcount, "Device has %u references left.\n", refcount);
10998 done:
10999 IDirect3D9_Release(d3d);
11000 DestroyWindow(window);
11003 static void yuv_color_test(void)
11005 HRESULT hr;
11006 IDirect3DSurface9 *surface, *target;
11007 unsigned int i;
11008 D3DLOCKED_RECT lr;
11009 IDirect3D9 *d3d;
11010 D3DCOLOR color;
11011 D3DFORMAT skip_once = D3DFMT_UNKNOWN;
11012 IDirect3DDevice9 *device;
11013 D3DSURFACE_DESC desc;
11014 ULONG refcount;
11015 HWND window;
11017 static const struct
11019 DWORD in;
11020 D3DFORMAT format;
11021 const char *fmt_string;
11022 D3DCOLOR left, right;
11024 test_data[] =
11026 {0x00000000, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00008700, 0x00008700},
11027 {0xff000000, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00008700, 0x004bff1c},
11028 {0x00ff0000, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00b30000, 0x00b30000},
11029 {0x0000ff00, D3DFMT_UYVY, "D3DFMT_UYVY", 0x004bff1c, 0x00008700},
11030 {0x000000ff, D3DFMT_UYVY, "D3DFMT_UYVY", 0x000030e1, 0x000030e1},
11031 {0xffff0000, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00b30000, 0x00ffd01c},
11032 {0xff00ff00, D3DFMT_UYVY, "D3DFMT_UYVY", 0x004bff1c, 0x004bff1c},
11033 {0xff0000ff, D3DFMT_UYVY, "D3DFMT_UYVY", 0x000030e1, 0x004bffff},
11034 {0x00ffff00, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00ffd01c, 0x00b30000},
11035 {0x00ff00ff, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00b300e1, 0x00b300e1},
11036 {0x0000ffff, D3DFMT_UYVY, "D3DFMT_UYVY", 0x004bffff, 0x001030e1},
11037 {0xffffff00, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00ffd01c, 0x00ffd01c},
11038 {0xffff00ff, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00b300e1, 0x00ff79ff},
11039 {0xffffffff, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00ff79ff, 0x00ff79ff},
11040 {0x4cff4c54, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00ff0000, 0x00ff0000},
11041 {0x00800080, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00000000, 0x00000000},
11042 {0xff80ff80, D3DFMT_UYVY, "D3DFMT_UYVY", 0x00ffffff, 0x00ffffff},
11043 {0x1c6b1cff, D3DFMT_UYVY, "D3DFMT_UYVY", 0x000000fd, 0x000000fd},
11045 {0x00000000, D3DFMT_YUY2, "D3DFMT_YUY2", 0x00008700, 0x00008700},
11046 {0xff000000, D3DFMT_YUY2, "D3DFMT_YUY2", 0x00b30000, 0x00b30000},
11047 {0x00ff0000, D3DFMT_YUY2, "D3DFMT_YUY2", 0x00008700, 0x004bff1c},
11048 {0x0000ff00, D3DFMT_YUY2, "D3DFMT_YUY2", 0x000030e1, 0x000030e1},
11049 {0x000000ff, D3DFMT_YUY2, "D3DFMT_YUY2", 0x004bff1c, 0x00008700},
11050 {0xffff0000, D3DFMT_YUY2, "D3DFMT_YUY2", 0x00b30000, 0x00ffd01c},
11051 {0xff00ff00, D3DFMT_YUY2, "D3DFMT_YUY2", 0x00b300e1, 0x00b300e1},
11052 {0xff0000ff, D3DFMT_YUY2, "D3DFMT_YUY2", 0x00ffd01c, 0x00b30000},
11053 {0x00ffff00, D3DFMT_YUY2, "D3DFMT_YUY2", 0x000030e1, 0x004bffff},
11054 {0x00ff00ff, D3DFMT_YUY2, "D3DFMT_YUY2", 0x004bff1c, 0x004bff1c},
11055 {0x0000ffff, D3DFMT_YUY2, "D3DFMT_YUY2", 0x004bffff, 0x000030e1},
11056 {0xffffff00, D3DFMT_YUY2, "D3DFMT_YUY2", 0x00b300e1, 0x00ff79ff},
11057 {0xffff00ff, D3DFMT_YUY2, "D3DFMT_YUY2", 0x00ffd01c, 0x00ffd01c},
11058 {0xffffffff, D3DFMT_YUY2, "D3DFMT_YUY2", 0x00ff79ff, 0x00ff79ff},
11059 {0x4cff4c54, D3DFMT_YUY2, "D3DFMT_YUY2", 0x000b8b00, 0x00b6ffa3},
11060 {0x00800080, D3DFMT_YUY2, "D3DFMT_YUY2", 0x0000ff00, 0x0000ff00},
11061 {0xff80ff80, D3DFMT_YUY2, "D3DFMT_YUY2", 0x00ff00ff, 0x00ff00ff},
11062 {0x1c6b1cff, D3DFMT_YUY2, "D3DFMT_YUY2", 0x006dff45, 0x0000d500},
11065 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11066 0, 0, 640, 480, NULL, NULL, NULL, NULL);
11067 d3d = Direct3DCreate9(D3D_SDK_VERSION);
11068 ok(!!d3d, "Failed to create a D3D object.\n");
11069 if (!(device = create_device(d3d, window, window, TRUE)))
11071 skip("Failed to create a D3D device, skipping tests.\n");
11072 goto done;
11075 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &target);
11076 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
11077 hr = IDirect3DSurface9_GetDesc(target, &desc);
11078 ok(SUCCEEDED(hr), "Failed to get surface description, hr %#x.\n", hr);
11080 for (i = 0; i < sizeof(test_data) / sizeof(test_data[0]); i++)
11082 /* Some(all?) Windows drivers do not support YUV 3D textures, only 2D surfaces in StretchRect.
11083 * Thus use StretchRect to draw the YUV surface onto the screen instead of drawPrimitive. */
11084 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL,
11085 D3DFMT_X8R8G8B8, 0, D3DRTYPE_SURFACE, test_data[i].format)))
11087 if (skip_once != test_data[i].format)
11089 skip("%s is not supported.\n", test_data[i].fmt_string);
11090 skip_once = test_data[i].format;
11092 continue;
11094 if (FAILED(IDirect3D9_CheckDeviceFormatConversion(d3d, 0,
11095 D3DDEVTYPE_HAL, test_data[i].format, desc.Format)))
11097 if (skip_once != test_data[i].format)
11099 skip("Driver cannot blit %s surfaces.\n", test_data[i].fmt_string);
11100 skip_once = test_data[i].format;
11102 continue;
11105 /* A pixel is effectively 16 bit large, but two pixels are stored together, so the minimum size is 2x1.
11106 * However, Nvidia Windows drivers have problems with 2x1 YUY2/UYVY surfaces, so use a 4x1 surface and
11107 * fill the second block with dummy data. If the surface has a size of 2x1, those drivers ignore the
11108 * second luminance value, resulting in an incorrect color in the right pixel. */
11109 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 1, test_data[i].format,
11110 D3DPOOL_DEFAULT, &surface, NULL);
11111 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
11114 hr = IDirect3DSurface9_LockRect(surface, &lr, NULL, 0);
11115 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
11116 ((DWORD *)lr.pBits)[0] = test_data[i].in;
11117 ((DWORD *)lr.pBits)[1] = 0x00800080;
11118 hr = IDirect3DSurface9_UnlockRect(surface);
11119 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
11121 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0);
11122 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
11123 hr = IDirect3DDevice9_StretchRect(device, surface, NULL, target, NULL, D3DTEXF_POINT);
11124 ok(SUCCEEDED(hr), "Failed to draw surface onto backbuffer, hr %#x.\n", hr);
11126 /* Some Windows drivers (mostly Nvidia, but also some VM drivers) insist on doing linear filtering
11127 * although we asked for point filtering. Be careful when reading the results and use the pixel
11128 * centers. In the future we may want to add tests for the filtered pixels as well.
11130 * Unfortunately different implementations(Windows-Nvidia and Mac-AMD tested) interpret some colors
11131 * vastly differently, so we need a max diff of 18. */
11132 color = getPixelColor(device, 1, 240);
11133 ok(color_match(color, test_data[i].left, 18),
11134 "Input 0x%08x: Got color 0x%08x for pixel 1/1, expected 0x%08x, format %s.\n",
11135 test_data[i].in, color, test_data[i].left, test_data[i].fmt_string);
11136 color = getPixelColor(device, 318, 240);
11137 ok(color_match(color, test_data[i].right, 18),
11138 "Input 0x%08x: Got color 0x%08x for pixel 2/1, expected 0x%08x, format %s.\n",
11139 test_data[i].in, color, test_data[i].right, test_data[i].fmt_string);
11140 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
11141 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
11142 IDirect3DSurface9_Release(surface);
11145 IDirect3DSurface9_Release(target);
11146 refcount = IDirect3DDevice9_Release(device);
11147 ok(!refcount, "Device has %u references left.\n", refcount);
11148 done:
11149 IDirect3D9_Release(d3d);
11150 DestroyWindow(window);
11153 static void yuv_layout_test(void)
11155 HRESULT hr;
11156 IDirect3DSurface9 *surface, *target;
11157 unsigned int fmt, i, x, y;
11158 D3DFORMAT format;
11159 const char *fmt_string;
11160 D3DLOCKED_RECT lr;
11161 IDirect3D9 *d3d;
11162 D3DCOLOR color;
11163 DWORD ref_color;
11164 BYTE *buf, *chroma_buf, *u_buf, *v_buf;
11165 UINT width = 20, height = 16;
11166 IDirect3DDevice9 *device;
11167 ULONG refcount;
11168 D3DCAPS9 caps;
11169 D3DSURFACE_DESC desc;
11170 HWND window;
11172 static const struct
11174 DWORD color1, color2;
11175 DWORD rgb1, rgb2;
11177 test_data[] =
11179 { 0x000000, 0xffffff, 0x00008800, 0x00ff7dff },
11180 { 0xff0000, 0x00ffff, 0x004aff14, 0x00b800ee },
11181 { 0x00ff00, 0xff00ff, 0x000024ee, 0x00ffe114 },
11182 { 0x0000ff, 0xffff00, 0x00b80000, 0x004affff },
11183 { 0xffff00, 0x0000ff, 0x004affff, 0x00b80000 },
11184 { 0xff00ff, 0x00ff00, 0x00ffe114, 0x000024ee },
11185 { 0x00ffff, 0xff0000, 0x00b800ee, 0x004aff14 },
11186 { 0xffffff, 0x000000, 0x00ff7dff, 0x00008800 },
11189 static const struct
11191 D3DFORMAT format;
11192 const char *str;
11194 formats[] =
11196 { D3DFMT_UYVY, "D3DFMT_UYVY", },
11197 { D3DFMT_YUY2, "D3DFMT_YUY2", },
11198 { MAKEFOURCC('Y','V','1','2'), "D3DFMT_YV12", },
11199 { MAKEFOURCC('N','V','1','2'), "D3DFMT_NV12", },
11202 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11203 0, 0, 640, 480, NULL, NULL, NULL, NULL);
11204 d3d = Direct3DCreate9(D3D_SDK_VERSION);
11205 ok(!!d3d, "Failed to create a D3D object.\n");
11206 if (!(device = create_device(d3d, window, window, TRUE)))
11208 skip("Failed to create a D3D device, skipping tests.\n");
11209 goto done;
11212 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
11213 ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
11214 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2
11215 && !(caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL))
11217 skip("No NP2 texture support, skipping YUV texture layout test.\n");
11218 IDirect3DDevice9_Release(device);
11219 goto done;
11222 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &target);
11223 ok(hr == D3D_OK, "IDirect3DDevice9_GetRenderTarget failed, hr = %#x.\n", hr);
11224 hr = IDirect3DSurface9_GetDesc(target, &desc);
11225 ok(SUCCEEDED(hr), "Failed to get surface description, hr %#x.\n", hr);
11227 for (fmt = 0; fmt < sizeof(formats) / sizeof(formats[0]); fmt++)
11229 format = formats[fmt].format;
11230 fmt_string = formats[fmt].str;
11232 /* Some (all?) Windows drivers do not support YUV 3D textures, only 2D surfaces in
11233 * StretchRect. Thus use StretchRect to draw the YUV surface onto the screen instead
11234 * of drawPrimitive. */
11235 if (IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, 0,
11236 D3DRTYPE_SURFACE, format) != D3D_OK)
11238 skip("%s is not supported.\n", fmt_string);
11239 continue;
11241 if (FAILED(IDirect3D9_CheckDeviceFormatConversion(d3d, 0,
11242 D3DDEVTYPE_HAL, format, desc.Format)))
11244 skip("Driver cannot blit %s surfaces.\n", fmt_string);
11245 continue;
11248 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, width, height, format, D3DPOOL_DEFAULT, &surface, NULL);
11249 ok(hr == D3D_OK, "IDirect3DDevice9_CreateOffscreenPlainSurface failed, hr = %#x.\n", hr);
11251 for (i = 0; i < sizeof(test_data) / sizeof(test_data[0]); i++)
11253 hr = IDirect3DSurface9_LockRect(surface, &lr, NULL, 0);
11254 ok(hr == D3D_OK, "IDirect3DSurface9_LockRect failed, hr = %#x.\n", hr);
11255 buf = lr.pBits;
11256 chroma_buf = buf + lr.Pitch * height;
11257 if (format == MAKEFOURCC('Y','V','1','2'))
11259 v_buf = chroma_buf;
11260 u_buf = chroma_buf + height / 2 * lr.Pitch/2;
11262 /* Draw the top left quarter of the screen with color1, the rest with color2 */
11263 for (y = 0; y < height; y++)
11265 for (x = 0; x < width; x += 2)
11267 DWORD color = (x < width / 2 && y < height / 2) ? test_data[i].color1 : test_data[i].color2;
11268 BYTE Y = (color >> 16) & 0xff;
11269 BYTE U = (color >> 8) & 0xff;
11270 BYTE V = (color >> 0) & 0xff;
11271 if (format == D3DFMT_UYVY)
11273 buf[y * lr.Pitch + 2 * x + 0] = U;
11274 buf[y * lr.Pitch + 2 * x + 1] = Y;
11275 buf[y * lr.Pitch + 2 * x + 2] = V;
11276 buf[y * lr.Pitch + 2 * x + 3] = Y;
11278 else if (format == D3DFMT_YUY2)
11280 buf[y * lr.Pitch + 2 * x + 0] = Y;
11281 buf[y * lr.Pitch + 2 * x + 1] = U;
11282 buf[y * lr.Pitch + 2 * x + 2] = Y;
11283 buf[y * lr.Pitch + 2 * x + 3] = V;
11285 else if (format == MAKEFOURCC('Y','V','1','2'))
11287 buf[y * lr.Pitch + x + 0] = Y;
11288 buf[y * lr.Pitch + x + 1] = Y;
11289 u_buf[(y / 2) * (lr.Pitch / 2) + (x / 2)] = U;
11290 v_buf[(y / 2) * (lr.Pitch / 2) + (x / 2)] = V;
11292 else if (format == MAKEFOURCC('N','V','1','2'))
11294 buf[y * lr.Pitch + x + 0] = Y;
11295 buf[y * lr.Pitch + x + 1] = Y;
11296 chroma_buf[(y / 2) * lr.Pitch + 2 * (x / 2) + 0] = U;
11297 chroma_buf[(y / 2) * lr.Pitch + 2 * (x / 2) + 1] = V;
11301 hr = IDirect3DSurface9_UnlockRect(surface);
11302 ok(hr == D3D_OK, "IDirect3DSurface9_UnlockRect failed, hr = %#x.\n", hr);
11304 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0);
11305 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %#x.\n", hr);
11306 hr = IDirect3DDevice9_StretchRect(device, surface, NULL, target, NULL, D3DTEXF_POINT);
11307 ok(hr == D3D_OK, "IDirect3DDevice9_StretchRect failed with %#x.\n", hr);
11309 /* Some Windows drivers (mostly Nvidia, but also some VM drivers) insist on doing linear filtering
11310 * although we asked for point filtering. To prevent running into precision problems, read at points
11311 * with some margin within each quadrant.
11313 * Unfortunately different implementations(Windows-Nvidia and Mac-AMD tested) interpret some colors
11314 * vastly differently, so we need a max diff of 18. */
11315 for (y = 0; y < 4; y++)
11317 for (x = 0; x < 4; x++)
11319 UINT xcoord = (1 + 2 * x) * 640 / 8;
11320 UINT ycoord = (1 + 2 * y) * 480 / 8;
11321 ref_color = (y < 2 && x < 2) ? test_data[i].rgb1 : test_data[i].rgb2;
11322 color = getPixelColor(device, xcoord, ycoord);
11323 ok(color_match(color, ref_color, 18),
11324 "Format %s: Got color %#x for pixel (%d/%d)/(%d/%d), pixel %d %d, expected %#x.\n",
11325 fmt_string, color, x, 4, y, 4, xcoord, ycoord, ref_color);
11328 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
11330 ok(SUCCEEDED(hr), "Present failed with %#x.\n", hr);
11332 IDirect3DSurface9_Release(surface);
11335 IDirect3DSurface9_Release(target);
11336 refcount = IDirect3DDevice9_Release(device);
11337 ok(!refcount, "Device has %u references left.\n", refcount);
11338 done:
11339 IDirect3D9_Release(d3d);
11340 DestroyWindow(window);
11343 static void texop_range_test(void)
11345 IDirect3DTexture9 *texture;
11346 D3DLOCKED_RECT locked_rect;
11347 IDirect3DDevice9 *device;
11348 IDirect3D9 *d3d;
11349 ULONG refcount;
11350 D3DCAPS9 caps;
11351 DWORD color;
11352 HWND window;
11353 HRESULT hr;
11355 static const struct
11357 float x, y, z;
11358 D3DCOLOR diffuse;
11360 quad[] =
11362 {-1.0f, -1.0f, 0.1f, D3DCOLOR_ARGB(0xff, 0xff, 0xff, 0xff)},
11363 {-1.0f, 1.0f, 0.1f, D3DCOLOR_ARGB(0xff, 0xff, 0xff, 0xff)},
11364 { 1.0f, -1.0f, 0.1f, D3DCOLOR_ARGB(0xff, 0xff, 0xff, 0xff)},
11365 { 1.0f, 1.0f, 0.1f, D3DCOLOR_ARGB(0xff, 0xff, 0xff, 0xff)}
11368 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11369 0, 0, 640, 480, NULL, NULL, NULL, NULL);
11370 d3d = Direct3DCreate9(D3D_SDK_VERSION);
11371 ok(!!d3d, "Failed to create a D3D object.\n");
11372 if (!(device = create_device(d3d, window, window, TRUE)))
11374 skip("Failed to create a D3D device, skipping tests.\n");
11375 goto done;
11378 /* We need ADD and SUBTRACT operations */
11379 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
11380 ok(SUCCEEDED(hr), "GetDeviceCaps failed with 0x%08x\n", hr);
11381 if (!(caps.TextureOpCaps & D3DTEXOPCAPS_ADD))
11383 skip("D3DTOP_ADD is not supported, skipping value range test.\n");
11384 IDirect3DDevice9_Release(device);
11385 goto done;
11387 if (!(caps.TextureOpCaps & D3DTEXOPCAPS_SUBTRACT))
11389 skip("D3DTEXOPCAPS_SUBTRACT is not supported, skipping value range test.\n");
11390 IDirect3DDevice9_Release(device);
11391 goto done;
11394 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
11395 ok(SUCCEEDED(hr), "SetFVF failed with 0x%08x\n", hr);
11396 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
11397 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
11398 /* Stage 1: result = diffuse(=1.0) + diffuse
11399 * stage 2: result = result - tfactor(= 0.5)
11401 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0x80808080);
11402 ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
11403 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
11404 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
11405 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
11406 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
11407 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_ADD);
11408 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
11409 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_CURRENT);
11410 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
11411 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_TFACTOR);
11412 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
11413 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_SUBTRACT);
11414 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
11416 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
11417 ok(SUCCEEDED(hr), "Failed to clear device, hr %#x.\n\n", hr);
11418 hr = IDirect3DDevice9_BeginScene(device);
11419 ok(SUCCEEDED(hr), "BeginScene failed with 0x%08x\n", hr);
11420 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
11421 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed with 0x%08x\n", hr);
11422 hr = IDirect3DDevice9_EndScene(device);
11423 ok(SUCCEEDED(hr), "EndScene failed with 0x%08x\n", hr);
11425 color = getPixelColor(device, 320, 240);
11426 ok(color_match(color, 0x00808080, 1), "texop Range > 1.0 returned 0x%08x, expected 0x00808080\n",
11427 color);
11428 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
11429 ok(SUCCEEDED(hr), "Present failed with 0x%08x\n", hr);
11431 hr = IDirect3DDevice9_CreateTexture(device, 1, 1, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture, NULL);
11432 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateTexture failed with 0x%08x\n", hr);
11433 hr = IDirect3DTexture9_LockRect(texture, 0, &locked_rect, NULL, 0);
11434 ok(SUCCEEDED(hr), "LockRect failed with 0x%08x\n", hr);
11435 *((DWORD *)locked_rect.pBits) = D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00);
11436 hr = IDirect3DTexture9_UnlockRect(texture, 0);
11437 ok(SUCCEEDED(hr), "UnlockRect failed with 0x%08x\n", hr);
11438 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
11439 ok(SUCCEEDED(hr), "SetTexture failed with 0x%08x\n", hr);
11441 /* Stage 1: result = texture(=0.0) - tfactor(= 0.5)
11442 * stage 2: result = result + diffuse(1.0)
11444 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0x80808080);
11445 ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
11446 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
11447 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
11448 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
11449 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
11450 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SUBTRACT);
11451 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
11452 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_CURRENT);
11453 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
11454 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
11455 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
11456 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_ADD);
11457 ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
11459 hr = IDirect3DDevice9_BeginScene(device);
11460 ok(SUCCEEDED(hr), "BeginScene failed with 0x%08x\n", hr);
11461 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
11462 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed with 0x%08x\n", hr);
11463 hr = IDirect3DDevice9_EndScene(device);
11464 ok(SUCCEEDED(hr), "EndScene failed with 0x%08x\n", hr);
11466 color = getPixelColor(device, 320, 240);
11467 ok(color_match(color, 0x00ffffff, 1), "texop Range < 0.0 returned 0x%08x, expected 0x00ffffff\n",
11468 color);
11469 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
11470 ok(SUCCEEDED(hr), "Present failed with 0x%08x\n", hr);
11472 IDirect3DTexture9_Release(texture);
11473 refcount = IDirect3DDevice9_Release(device);
11474 ok(!refcount, "Device has %u references left.\n", refcount);
11475 done:
11476 IDirect3D9_Release(d3d);
11477 DestroyWindow(window);
11480 static void alphareplicate_test(void)
11482 IDirect3DDevice9 *device;
11483 IDirect3D9 *d3d;
11484 ULONG refcount;
11485 DWORD color;
11486 HWND window;
11487 HRESULT hr;
11489 static const struct
11491 struct vec3 position;
11492 DWORD diffuse;
11494 quad[] =
11496 {{-1.0f, -1.0f, 0.1f}, 0x80ff00ff},
11497 {{-1.0f, 1.0f, 0.1f}, 0x80ff00ff},
11498 {{ 1.0f, -1.0f, 0.1f}, 0x80ff00ff},
11499 {{ 1.0f, 1.0f, 0.1f}, 0x80ff00ff},
11502 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11503 0, 0, 640, 480, NULL, NULL, NULL, NULL);
11504 d3d = Direct3DCreate9(D3D_SDK_VERSION);
11505 ok(!!d3d, "Failed to create a D3D object.\n");
11506 if (!(device = create_device(d3d, window, window, TRUE)))
11508 skip("Failed to create a D3D device, skipping tests.\n");
11509 goto done;
11512 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
11513 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
11515 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
11516 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with 0x%08x\n", hr);
11518 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
11519 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr);
11520 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE | D3DTA_ALPHAREPLICATE);
11521 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr);
11523 hr = IDirect3DDevice9_BeginScene(device);
11524 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
11525 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
11526 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11527 hr = IDirect3DDevice9_EndScene(device);
11528 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
11530 color = getPixelColor(device, 320, 240);
11531 ok(color_match(color, 0x00808080, 1), "alphareplicate test 0x%08x, expected 0x00808080\n",
11532 color);
11533 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
11534 ok(SUCCEEDED(hr), "Present failed with 0x%08x\n", hr);
11536 refcount = IDirect3DDevice9_Release(device);
11537 ok(!refcount, "Device has %u references left.\n", refcount);
11538 done:
11539 IDirect3D9_Release(d3d);
11540 DestroyWindow(window);
11543 static void dp3_alpha_test(void)
11545 IDirect3DDevice9 *device;
11546 IDirect3D9 *d3d;
11547 ULONG refcount;
11548 D3DCAPS9 caps;
11549 DWORD color;
11550 HWND window;
11551 HRESULT hr;
11553 static const struct
11555 struct vec3 position;
11556 DWORD diffuse;
11558 quad[] =
11560 {{-1.0f, -1.0f, 0.1f}, 0x408080c0},
11561 {{-1.0f, 1.0f, 0.1f}, 0x408080c0},
11562 {{ 1.0f, -1.0f, 0.1f}, 0x408080c0},
11563 {{ 1.0f, 1.0f, 0.1f}, 0x408080c0},
11566 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11567 0, 0, 640, 480, NULL, NULL, NULL, NULL);
11568 d3d = Direct3DCreate9(D3D_SDK_VERSION);
11569 ok(!!d3d, "Failed to create a D3D object.\n");
11570 if (!(device = create_device(d3d, window, window, TRUE)))
11572 skip("Failed to create a D3D device, skipping tests.\n");
11573 goto done;
11576 memset(&caps, 0, sizeof(caps));
11577 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
11578 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
11579 if (!(caps.TextureOpCaps & D3DTEXOPCAPS_DOTPRODUCT3))
11581 skip("D3DTOP_DOTPRODUCT3 not supported\n");
11582 IDirect3DDevice9_Release(device);
11583 goto done;
11586 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
11587 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
11589 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
11590 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with 0x%08x\n", hr);
11592 /* dp3_x4 r0, diffuse_bias, tfactor_bias
11593 * mov r0.a, diffuse.a
11594 * mov r0, r0.a
11596 * It turns out that the 2nd line is ignored, and the dp3 result written into r0.a instead
11597 * 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
11598 * (0.0 * 0.5 + 0.0 * 0.5 + 0.25 * 0.5) * 4 = 0.125 * 4 = 0.5, with a bunch of inprecision.
11600 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_DOTPRODUCT3);
11601 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr);
11602 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
11603 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr);
11604 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
11605 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr);
11606 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
11607 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr);
11608 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
11609 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr);
11610 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
11611 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr);
11612 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_CURRENT | D3DTA_ALPHAREPLICATE);
11613 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr);
11614 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
11615 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr);
11616 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0xffffffff);
11617 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr);
11618 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
11619 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
11621 hr = IDirect3DDevice9_BeginScene(device);
11622 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
11623 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
11624 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11625 hr = IDirect3DDevice9_EndScene(device);
11626 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
11628 color = getPixelColor(device, 320, 240);
11629 ok(color_match(color, 0x00808080, 4), "dp3 alpha test 0x%08x, expected 0x00808080\n",
11630 color);
11631 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
11632 ok(SUCCEEDED(hr), "IDirect3DDevice9_Present failed with 0x%08x\n", hr);
11634 refcount = IDirect3DDevice9_Release(device);
11635 ok(!refcount, "Device has %u references left.\n", refcount);
11636 done:
11637 IDirect3D9_Release(d3d);
11638 DestroyWindow(window);
11641 static void zwriteenable_test(void)
11643 IDirect3DDevice9 *device;
11644 IDirect3D9 *d3d;
11645 D3DCOLOR color;
11646 ULONG refcount;
11647 HWND window;
11648 HRESULT hr;
11650 static const struct
11652 struct vec3 position;
11653 DWORD diffuse;
11655 quad1[] =
11657 {{-1.0f, -1.0f, 0.1f}, 0x00ff0000},
11658 {{-1.0f, 1.0f, 0.1f}, 0x00ff0000},
11659 {{ 1.0f, -1.0f, 0.1f}, 0x00ff0000},
11660 {{ 1.0f, 1.0f, 0.1f}, 0x00ff0000},
11662 quad2[] =
11664 {{-1.0f, -1.0f, 0.9f}, 0x0000ff00},
11665 {{-1.0f, 1.0f, 0.9f}, 0x0000ff00},
11666 {{ 1.0f, -1.0f, 0.9f}, 0x0000ff00},
11667 {{ 1.0f, 1.0f, 0.9f}, 0x0000ff00},
11670 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11671 0, 0, 640, 480, NULL, NULL, NULL, NULL);
11672 d3d = Direct3DCreate9(D3D_SDK_VERSION);
11673 ok(!!d3d, "Failed to create a D3D object.\n");
11674 if (!(device = create_device(d3d, window, window, TRUE)))
11676 skip("Failed to create a D3D device, skipping tests.\n");
11677 goto done;
11680 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x000000ff, 1.0f, 0);
11681 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
11683 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
11684 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with 0x%08x\n", hr);
11685 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
11686 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr);
11687 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
11688 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr);
11689 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
11690 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr);
11691 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
11692 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
11694 hr = IDirect3DDevice9_BeginScene(device);
11695 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
11696 /* The Z buffer is filled with 1.0. Draw a red quad with z = 0.1,
11697 * zenable = D3DZB_FALSE, zwriteenable = TRUE. The red color is written
11698 * because the z test is disabled. The question is whether the z = 0.1
11699 * values are written into the Z buffer. After the draw, set
11700 * zenable = TRUE and draw a green quad at z = 0.9. If the values are
11701 * written, the z test will fail(0.9 > 0.1) and the red color remains. If
11702 * the values are not written, the z test succeeds(0.9 < 1.0) and the
11703 * green color is written. It turns out that the screen is green, so
11704 * zenable = D3DZB_FALSE and zwriteenable = TRUE does NOT write to the z
11705 * buffer. */
11706 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(*quad1));
11707 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11708 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
11709 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
11710 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(*quad2));
11711 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11712 hr = IDirect3DDevice9_EndScene(device);
11713 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
11715 color = getPixelColor(device, 320, 240);
11716 ok(color_match(color, 0x0000ff00, 1), "zwriteenable test returned 0x%08x, expected 0x0000ff00\n",
11717 color);
11718 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
11719 ok(SUCCEEDED(hr), "IDirect3DDevice9_Present failed with 0x%08x\n", hr);
11721 refcount = IDirect3DDevice9_Release(device);
11722 ok(!refcount, "Device has %u references left.\n", refcount);
11723 done:
11724 IDirect3D9_Release(d3d);
11725 DestroyWindow(window);
11728 static void alphatest_test(void)
11730 #define ALPHATEST_PASSED 0x0000ff00
11731 #define ALPHATEST_FAILED 0x00ff0000
11732 IDirect3DDevice9 *device;
11733 unsigned int i, j;
11734 IDirect3D9 *d3d;
11735 D3DCOLOR color;
11736 ULONG refcount;
11737 D3DCAPS9 caps;
11738 HWND window;
11739 HRESULT hr;
11741 static const struct
11743 D3DCMPFUNC func;
11744 D3DCOLOR color_less;
11745 D3DCOLOR color_equal;
11746 D3DCOLOR color_greater;
11748 testdata[] =
11750 {D3DCMP_NEVER, ALPHATEST_FAILED, ALPHATEST_FAILED, ALPHATEST_FAILED},
11751 {D3DCMP_LESS, ALPHATEST_PASSED, ALPHATEST_FAILED, ALPHATEST_FAILED},
11752 {D3DCMP_EQUAL, ALPHATEST_FAILED, ALPHATEST_PASSED, ALPHATEST_FAILED},
11753 {D3DCMP_LESSEQUAL, ALPHATEST_PASSED, ALPHATEST_PASSED, ALPHATEST_FAILED},
11754 {D3DCMP_GREATER, ALPHATEST_FAILED, ALPHATEST_FAILED, ALPHATEST_PASSED},
11755 {D3DCMP_NOTEQUAL, ALPHATEST_PASSED, ALPHATEST_FAILED, ALPHATEST_PASSED},
11756 {D3DCMP_GREATEREQUAL, ALPHATEST_FAILED, ALPHATEST_PASSED, ALPHATEST_PASSED},
11757 {D3DCMP_ALWAYS, ALPHATEST_PASSED, ALPHATEST_PASSED, ALPHATEST_PASSED},
11759 static const struct
11761 struct vec3 position;
11762 DWORD diffuse;
11764 quad[] =
11766 {{-1.0f, -1.0f, 0.1f}, ALPHATEST_PASSED | 0x80000000},
11767 {{-1.0f, 1.0f, 0.1f}, ALPHATEST_PASSED | 0x80000000},
11768 {{ 1.0f, -1.0f, 0.1f}, ALPHATEST_PASSED | 0x80000000},
11769 {{ 1.0f, 1.0f, 0.1f}, ALPHATEST_PASSED | 0x80000000},
11772 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11773 0, 0, 640, 480, NULL, NULL, NULL, NULL);
11774 d3d = Direct3DCreate9(D3D_SDK_VERSION);
11775 ok(!!d3d, "Failed to create a D3D object.\n");
11776 if (!(device = create_device(d3d, window, window, TRUE)))
11778 skip("Failed to create a D3D device, skipping tests.\n");
11779 goto done;
11782 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
11783 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
11785 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
11786 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
11787 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHATESTENABLE, TRUE);
11788 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr);
11789 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
11790 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with 0x%08x\n", hr);
11792 for (j = 0; j < 2; ++j)
11794 if (j == 1)
11796 /* Try a pixel shader instead of fixed function. The wined3d code
11797 * may emulate the alpha test either for performance reasons
11798 * (floating point RTs) or to work around driver bugs (GeForce
11799 * 7x00 cards on MacOS). There may be a different codepath for ffp
11800 * and shader in this case, and the test should cover both. */
11801 IDirect3DPixelShader9 *ps;
11802 static const DWORD shader_code[] =
11804 0xffff0101, /* ps_1_1 */
11805 0x00000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
11806 0x0000ffff /* end */
11808 memset(&caps, 0, sizeof(caps));
11809 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
11810 ok(hr == D3D_OK, "IDirect3DDevice9_GetDeviceCaps failed with 0x%08x\n", hr);
11811 if(caps.PixelShaderVersion < D3DPS_VERSION(1, 1)) {
11812 break;
11815 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code, &ps);
11816 ok(hr == D3D_OK, "IDirect3DDevice9_CreatePixelShader failed with 0x%08x\n", hr);
11817 hr = IDirect3DDevice9_SetPixelShader(device, ps);
11818 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader failed with 0x%08x\n", hr);
11819 IDirect3DPixelShader9_Release(ps);
11822 for(i = 0; i < (sizeof(testdata)/sizeof(testdata[0])); i++) {
11823 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHAFUNC, testdata[i].func);
11824 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr);
11826 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, ALPHATEST_FAILED, 0.0, 0);
11827 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
11828 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHAREF, 0x90);
11829 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr);
11830 hr = IDirect3DDevice9_BeginScene(device);
11831 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
11832 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
11833 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11834 hr = IDirect3DDevice9_EndScene(device);
11835 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
11836 color = getPixelColor(device, 320, 240);
11837 ok(color_match(color, testdata[i].color_less, 1), "Alphatest failed. Got color 0x%08x, expected 0x%08x. alpha < ref, func %u\n",
11838 color, testdata[i].color_less, testdata[i].func);
11839 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
11840 ok(SUCCEEDED(hr), "IDirect3DDevice9_Present failed with 0x%08x\n", hr);
11842 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, ALPHATEST_FAILED, 0.0, 0);
11843 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
11844 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHAREF, 0x80);
11845 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr);
11846 hr = IDirect3DDevice9_BeginScene(device);
11847 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
11848 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
11849 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11850 hr = IDirect3DDevice9_EndScene(device);
11851 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
11852 color = getPixelColor(device, 320, 240);
11853 ok(color_match(color, testdata[i].color_equal, 1), "Alphatest failed. Got color 0x%08x, expected 0x%08x. alpha == ref, func %u\n",
11854 color, testdata[i].color_equal, testdata[i].func);
11855 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
11856 ok(SUCCEEDED(hr), "IDirect3DDevice9_Present failed with 0x%08x\n", hr);
11858 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, ALPHATEST_FAILED, 0.0, 0);
11859 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
11860 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHAREF, 0x70);
11861 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr);
11862 hr = IDirect3DDevice9_BeginScene(device);
11863 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
11864 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
11865 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11866 hr = IDirect3DDevice9_EndScene(device);
11867 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
11868 color = getPixelColor(device, 320, 240);
11869 ok(color_match(color, testdata[i].color_greater, 1), "Alphatest failed. Got color 0x%08x, expected 0x%08x. alpha > ref, func %u\n",
11870 color, testdata[i].color_greater, testdata[i].func);
11871 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
11872 ok(SUCCEEDED(hr), "IDirect3DDevice9_Present failed with 0x%08x\n", hr);
11876 refcount = IDirect3DDevice9_Release(device);
11877 ok(!refcount, "Device has %u references left.\n", refcount);
11878 done:
11879 IDirect3D9_Release(d3d);
11880 DestroyWindow(window);
11883 static void sincos_test(void)
11885 IDirect3DVertexShader9 *sin_shader, *cos_shader;
11886 IDirect3DDevice9 *device;
11887 struct vec3 data[1280];
11888 IDirect3D9 *d3d;
11889 unsigned int i;
11890 ULONG refcount;
11891 D3DCAPS9 caps;
11892 HWND window;
11893 HRESULT hr;
11895 static const DWORD sin_shader_code[] =
11897 0xfffe0200, /* vs_2_0 */
11898 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
11899 0x05000051, 0xa00f0002, 0x40490fdb, 0x3f800000, 0x00000000, 0x3f59999a, /* def c2, 3.14159, 1, 0, 0.85 */
11900 0x03000005, 0x80010001, 0x90000000, 0xa0000002, /* mul r1.x, v0.x, c2.x */
11901 0x04000025, 0x80020000, 0x80000001, 0xa0e40000, 0xa0e40001, /* sincos r0.y, r1.x, c0, c1 */
11902 0x02000001, 0xc00d0000, 0x90e40000, /* mov oPos.xzw, v0 */
11903 0x03000005, 0xc0020000, 0x80550000, 0xa0ff0002, /* mul oPos.y, r0.y, c2.w */
11904 0x02000001, 0xd00f0000, 0xa0a60002, /* mov oD0, c2.zyzz */
11905 0x0000ffff /* end */
11907 static const DWORD cos_shader_code[] =
11909 0xfffe0200, /* vs_2_0 */
11910 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
11911 0x05000051, 0xa00f0002, 0x40490fdb, 0x3f800000, 0x00000000, 0x3f59999a, /* def c2, 3.14159, 1, 0, 0.85 */
11912 0x03000005, 0x80010001, 0x90000000, 0xa0000002, /* mul r1.x, v0.x, c2.x */
11913 0x04000025, 0x80010000, 0x80000001, 0xa0e40000, 0xa0e40001, /* sincos r0.x, r1.x, c0, c1 */
11914 0x02000001, 0xc00d0000, 0x90e40000, /* mov oPos.xzw, v0 */
11915 0x03000005, 0xc0020000, 0x80000000, 0xa0ff0002, /* mul oPos.y, r0.x, c2.w */
11916 0x02000001, 0xd00f0000, 0xa0a90002, /* mov oD0, c2.yzzz */
11917 0x0000ffff /* end */
11919 static const float sincosc1[4] = {D3DSINCOSCONST1};
11920 static const float sincosc2[4] = {D3DSINCOSCONST2};
11922 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11923 0, 0, 640, 480, NULL, NULL, NULL, NULL);
11924 d3d = Direct3DCreate9(D3D_SDK_VERSION);
11925 ok(!!d3d, "Failed to create a D3D object.\n");
11926 if (!(device = create_device(d3d, window, window, TRUE)))
11928 skip("Failed to create a D3D device, skipping tests.\n");
11929 goto done;
11932 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
11933 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
11934 if (caps.VertexShaderVersion < D3DVS_VERSION(2, 0))
11936 skip("No vs_2_0 support, skipping tests.\n");
11937 IDirect3DDevice9_Release(device);
11938 goto done;
11941 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
11942 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
11944 hr = IDirect3DDevice9_CreateVertexShader(device, sin_shader_code, &sin_shader);
11945 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
11946 hr = IDirect3DDevice9_CreateVertexShader(device, cos_shader_code, &cos_shader);
11947 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr);
11948 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
11949 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with 0x%08x\n", hr);
11950 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 0, sincosc1, 1);
11951 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShaderConstantF failed with 0x%08x\n", hr);
11952 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 1, sincosc2, 1);
11953 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShaderConstantF failed with 0x%08x\n", hr);
11955 /* Generate a point from -1 to 1 every 0.5 pixels */
11956 for(i = 0; i < 1280; i++) {
11957 data[i].x = (-640.0 + i) / 640.0;
11958 data[i].y = 0.0;
11959 data[i].z = 0.1;
11962 hr = IDirect3DDevice9_BeginScene(device);
11963 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
11965 hr = IDirect3DDevice9_SetVertexShader(device, sin_shader);
11966 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
11967 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1280, data, sizeof(*data));
11968 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11970 hr = IDirect3DDevice9_SetVertexShader(device, cos_shader);
11971 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
11972 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1280, data, sizeof(*data));
11973 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
11975 hr = IDirect3DDevice9_EndScene(device);
11976 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
11978 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
11979 ok(SUCCEEDED(hr), "IDirect3DDevice9_Present returned %#x.\n", hr);
11980 /* TODO: Find a way to properly validate the lines. Precicion issues make this a kinda nasty task */
11982 IDirect3DVertexShader9_Release(sin_shader);
11983 IDirect3DVertexShader9_Release(cos_shader);
11984 refcount = IDirect3DDevice9_Release(device);
11985 ok(!refcount, "Device has %u references left.\n", refcount);
11986 done:
11987 IDirect3D9_Release(d3d);
11988 DestroyWindow(window);
11991 static void loop_index_test(void)
11993 IDirect3DVertexShader9 *shader;
11994 IDirect3DDevice9 *device;
11995 IDirect3D9 *d3d;
11996 float values[4];
11997 ULONG refcount;
11998 D3DCAPS9 caps;
11999 DWORD color;
12000 HWND window;
12001 HRESULT hr;
12003 static const DWORD shader_code[] =
12005 0xfffe0200, /* vs_2_0 */
12006 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
12007 0x02000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
12008 0x0200001b, 0xf0e40800, 0xf0e40000, /* loop aL, i0 */
12009 0x04000002, 0x800f0000, 0x80e40000, 0xa0e42001, 0xf0e40800, /* add r0, r0, c[aL + 1] */
12010 0x0000001d, /* endloop */
12011 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
12012 0x02000001, 0xd00f0000, 0x80e40000, /* mov oD0, r0 */
12013 0x0000ffff /* END */
12015 static const float quad[] =
12017 -1.0f, -1.0f, 0.1f,
12018 -1.0f, 1.0f, 0.1f,
12019 1.0f, -1.0f, 0.1f,
12020 1.0f, 1.0f, 0.1f,
12022 static const float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f};
12023 static const float one[4] = {1.0f, 1.0f, 1.0f, 1.0f};
12024 static const int i0[4] = {2, 10, -3, 0};
12026 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
12027 0, 0, 640, 480, NULL, NULL, NULL, NULL);
12028 d3d = Direct3DCreate9(D3D_SDK_VERSION);
12029 ok(!!d3d, "Failed to create a D3D object.\n");
12030 if (!(device = create_device(d3d, window, window, TRUE)))
12032 skip("Failed to create a D3D device, skipping tests.\n");
12033 goto done;
12036 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
12037 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
12038 if (caps.VertexShaderVersion < D3DVS_VERSION(2, 0))
12040 skip("No vs_2_0 support, skipping tests.\n");
12041 IDirect3DDevice9_Release(device);
12042 goto done;
12045 hr = IDirect3DDevice9_CreateVertexShader(device, shader_code, &shader);
12046 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader failed with %08x\n", hr);
12047 hr = IDirect3DDevice9_SetVertexShader(device, shader);
12048 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShader failed with %08x\n", hr);
12049 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
12050 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
12051 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff0000, 1.0f, 0);
12052 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
12054 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 0, zero, 1);
12055 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
12056 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 1, one, 1);
12057 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
12058 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 2, one, 1);
12059 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
12060 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 3, one, 1);
12061 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
12062 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 4, one, 1);
12063 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
12064 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 5, one, 1);
12065 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
12066 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 6, one, 1);
12067 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
12068 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 7, one, 1);
12069 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
12070 values[0] = 1.0;
12071 values[1] = 1.0;
12072 values[2] = 0.0;
12073 values[3] = 0.0;
12074 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 8, values, 1);
12075 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
12076 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 9, one, 1);
12077 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
12078 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 10, one, 1);
12079 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
12080 values[0] = -1.0;
12081 values[1] = 0.0;
12082 values[2] = 0.0;
12083 values[3] = 0.0;
12084 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 11, values, 1);
12085 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
12086 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 12, one, 1);
12087 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
12088 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 13, one, 1);
12089 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
12090 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 14, one, 1);
12091 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
12092 hr = IDirect3DDevice9_SetVertexShaderConstantF(device, 15, one, 1);
12093 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr);
12095 hr = IDirect3DDevice9_SetVertexShaderConstantI(device, 0, i0, 1);
12096 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShaderConstantI returned %#x.\n", hr);
12098 hr = IDirect3DDevice9_BeginScene(device);
12099 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 3 * sizeof(float));
12100 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12101 hr = IDirect3DDevice9_EndScene(device);
12102 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12103 color = getPixelColor(device, 320, 240);
12104 ok(color_match(color, 0x0000ff00, 1),
12105 "aL indexing test returned color 0x%08x, expected 0x0000ff00\n", color);
12106 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
12107 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
12109 IDirect3DVertexShader9_Release(shader);
12110 refcount = IDirect3DDevice9_Release(device);
12111 ok(!refcount, "Device has %u references left.\n", refcount);
12112 done:
12113 IDirect3D9_Release(d3d);
12114 DestroyWindow(window);
12117 static void sgn_test(void)
12119 IDirect3DVertexShader9 *shader;
12120 IDirect3DDevice9 *device;
12121 IDirect3D9 *d3d;
12122 ULONG refcount;
12123 D3DCAPS9 caps;
12124 DWORD color;
12125 HWND window;
12126 HRESULT hr;
12128 static const DWORD shader_code[] =
12130 0xfffe0200, /* vs_2_0 */
12131 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position o0 */
12132 0x05000051, 0xa00f0000, 0xbf000000, 0x00000000, 0x3f000000, 0x41400000, /* def c0, -0.5, 0.0, 0.5, 12.0 */
12133 0x05000051, 0xa00f0001, 0x3fc00000, 0x00000000, 0x00000000, 0x00000000, /* def c1, 1.5, 0.0, 0.0, 0.0 */
12134 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
12135 0x04000022, 0x800f0000, 0xa0e40000, 0x80e40001, 0x80e40002, /* sgn r0, c0, r1, r2 */
12136 0x03000002, 0xd00f0000, 0x80e40000, 0xa0e40001, /* add oD0, r0, c1 */
12137 0x0000ffff /* end */
12139 static const float quad[] =
12141 -1.0f, -1.0f, 0.1f,
12142 -1.0f, 1.0f, 0.1f,
12143 1.0f, -1.0f, 0.1f,
12144 1.0f, 1.0f, 0.1f,
12147 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
12148 0, 0, 640, 480, NULL, NULL, NULL, NULL);
12149 d3d = Direct3DCreate9(D3D_SDK_VERSION);
12150 ok(!!d3d, "Failed to create a D3D object.\n");
12151 if (!(device = create_device(d3d, window, window, TRUE)))
12153 skip("Failed to create a D3D device, skipping tests.\n");
12154 goto done;
12157 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
12158 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
12159 if (caps.VertexShaderVersion < D3DVS_VERSION(2, 0))
12161 skip("No vs_2_0 support, skipping tests.\n");
12162 IDirect3DDevice9_Release(device);
12163 goto done;
12166 hr = IDirect3DDevice9_CreateVertexShader(device, shader_code, &shader);
12167 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader failed with %08x\n", hr);
12168 hr = IDirect3DDevice9_SetVertexShader(device, shader);
12169 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShader failed with %08x\n", hr);
12170 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
12171 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF failed with %08x\n", hr);
12172 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff0000, 1.0f, 0);
12173 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
12175 hr = IDirect3DDevice9_BeginScene(device);
12176 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12177 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 3 * sizeof(float));
12178 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
12179 hr = IDirect3DDevice9_EndScene(device);
12180 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12181 color = getPixelColor(device, 320, 240);
12182 ok(color_match(color, 0x008000ff, 1),
12183 "sgn test returned color 0x%08x, expected 0x008000ff\n", color);
12184 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
12185 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
12187 IDirect3DVertexShader9_Release(shader);
12188 refcount = IDirect3DDevice9_Release(device);
12189 ok(!refcount, "Device has %u references left.\n", refcount);
12190 done:
12191 IDirect3D9_Release(d3d);
12192 DestroyWindow(window);
12195 static void viewport_test(void)
12197 IDirect3DDevice9 *device;
12198 BOOL draw_failed = TRUE;
12199 D3DVIEWPORT9 vp;
12200 IDirect3D9 *d3d;
12201 ULONG refcount;
12202 DWORD color;
12203 HWND window;
12204 HRESULT hr;
12206 static const float quad[] =
12208 -0.5f, -0.5f, 0.1f,
12209 -0.5f, 0.5f, 0.1f,
12210 0.5f, -0.5f, 0.1f,
12211 0.5f, 0.5f, 0.1f,
12214 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
12215 0, 0, 640, 480, NULL, NULL, NULL, NULL);
12216 d3d = Direct3DCreate9(D3D_SDK_VERSION);
12217 ok(!!d3d, "Failed to create a D3D object.\n");
12218 if (!(device = create_device(d3d, window, window, TRUE)))
12220 skip("Failed to create a D3D device, skipping tests.\n");
12221 goto done;
12224 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff0000, 1.0f, 0);
12225 ok(hr == D3D_OK, "IDirect3DDevice9_Clear returned %08x\n", hr);
12227 /* Test a viewport with Width and Height bigger than the surface dimensions
12229 * TODO: Test Width < surface.width, but X + Width > surface.width
12230 * TODO: Test Width < surface.width, what happens with the height?
12232 * The expected behavior is that the viewport behaves like the "default"
12233 * viewport with X = Y = 0, Width = surface_width, Height = surface_height,
12234 * MinZ = 0.0, MaxZ = 1.0.
12236 * Starting with Windows 7 the behavior among driver versions is not
12237 * consistent. The SetViewport call is accepted on all drivers. Some
12238 * drivers(older nvidia ones) refuse to draw and return an error. Newer
12239 * nvidia drivers draw, but use the actual values in the viewport and only
12240 * display the upper left part on the surface.
12242 memset(&vp, 0, sizeof(vp));
12243 vp.X = 0;
12244 vp.Y = 0;
12245 vp.Width = 10000;
12246 vp.Height = 10000;
12247 vp.MinZ = 0.0;
12248 vp.MaxZ = 0.0;
12249 hr = IDirect3DDevice9_SetViewport(device, &vp);
12250 ok(hr == D3D_OK, "IDirect3DDevice9_SetViewport failed with %08x\n", hr);
12252 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
12253 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
12255 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
12256 ok(hr == D3D_OK, "IDirect3DDevice9_SetFVF returned %08x\n", hr);
12257 hr = IDirect3DDevice9_BeginScene(device);
12258 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
12259 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 3 * sizeof(float));
12260 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "Got unexpected hr %#x.\n", hr);
12261 draw_failed = FAILED(hr);
12262 hr = IDirect3DDevice9_EndScene(device);
12263 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
12265 if(!draw_failed)
12267 color = getPixelColor(device, 158, 118);
12268 ok(color == 0x00ff0000, "viewport test: (158,118) has color %08x\n", color);
12269 color = getPixelColor(device, 162, 118);
12270 ok(color == 0x00ff0000, "viewport test: (162,118) has color %08x\n", color);
12271 color = getPixelColor(device, 158, 122);
12272 ok(color == 0x00ff0000, "viewport test: (158,122) has color %08x\n", color);
12273 color = getPixelColor(device, 162, 122);
12274 ok(color == 0x00ffffff || broken(color == 0x00ff0000), "viewport test: (162,122) has color %08x\n", color);
12276 color = getPixelColor(device, 478, 358);
12277 ok(color == 0x00ffffff || broken(color == 0x00ff0000), "viewport test: (478,358 has color %08x\n", color);
12278 color = getPixelColor(device, 482, 358);
12279 ok(color == 0x00ff0000, "viewport test: (482,358) has color %08x\n", color);
12280 color = getPixelColor(device, 478, 362);
12281 ok(color == 0x00ff0000, "viewport test: (478,362) has color %08x\n", color);
12282 color = getPixelColor(device, 482, 362);
12283 ok(color == 0x00ff0000, "viewport test: (482,362) has color %08x\n", color);
12286 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
12287 ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %08x\n", hr);
12289 refcount = IDirect3DDevice9_Release(device);
12290 ok(!refcount, "Device has %u references left.\n", refcount);
12291 done:
12292 IDirect3D9_Release(d3d);
12293 DestroyWindow(window);
12296 /* This test tests depth clamping / clipping behaviour:
12297 * - With software vertex processing, depth values are clamped to the
12298 * minimum / maximum z value when D3DRS_CLIPPING is disabled, and clipped
12299 * when D3DRS_CLIPPING is enabled. Pretransformed vertices behave the
12300 * same as regular vertices here.
12301 * - With hardware vertex processing, D3DRS_CLIPPING seems to be ignored.
12302 * Normal vertices are always clipped. Pretransformed vertices are
12303 * clipped when D3DPMISCCAPS_CLIPTLVERTS is set, clamped when it isn't.
12304 * - The viewport's MinZ/MaxZ is irrelevant for this.
12306 static void depth_clamp_test(void)
12308 IDirect3DDevice9 *device;
12309 D3DVIEWPORT9 vp;
12310 IDirect3D9 *d3d;
12311 D3DCOLOR color;
12312 ULONG refcount;
12313 D3DCAPS9 caps;
12314 HWND window;
12315 HRESULT hr;
12317 static const struct
12319 struct vec4 position;
12320 DWORD diffuse;
12322 quad1[] =
12324 {{ 0.0f, 0.0f, 5.0f, 1.0f}, 0xff002b7f},
12325 {{640.0f, 0.0f, 5.0f, 1.0f}, 0xff002b7f},
12326 {{ 0.0f, 480.0f, 5.0f, 1.0f}, 0xff002b7f},
12327 {{640.0f, 480.0f, 5.0f, 1.0f}, 0xff002b7f},
12329 quad2[] =
12331 {{ 0.0f, 300.0f, 10.0f, 1.0f}, 0xfff9e814},
12332 {{640.0f, 300.0f, 10.0f, 1.0f}, 0xfff9e814},
12333 {{ 0.0f, 360.0f, 10.0f, 1.0f}, 0xfff9e814},
12334 {{640.0f, 360.0f, 10.0f, 1.0f}, 0xfff9e814},
12336 quad3[] =
12338 {{112.0f, 108.0f, 5.0f, 1.0f}, 0xffffffff},
12339 {{208.0f, 108.0f, 5.0f, 1.0f}, 0xffffffff},
12340 {{112.0f, 204.0f, 5.0f, 1.0f}, 0xffffffff},
12341 {{208.0f, 204.0f, 5.0f, 1.0f}, 0xffffffff},
12343 quad4[] =
12345 {{ 42.0f, 41.0f, 10.0f, 1.0f}, 0xffffffff},
12346 {{112.0f, 41.0f, 10.0f, 1.0f}, 0xffffffff},
12347 {{ 42.0f, 108.0f, 10.0f, 1.0f}, 0xffffffff},
12348 {{112.0f, 108.0f, 10.0f, 1.0f}, 0xffffffff},
12350 static const struct
12352 struct vec3 position;
12353 DWORD diffuse;
12355 quad5[] =
12357 {{-0.5f, 0.5f, 10.0f}, 0xff14f914},
12358 {{ 0.5f, 0.5f, 10.0f}, 0xff14f914},
12359 {{-0.5f, -0.5f, 10.0f}, 0xff14f914},
12360 {{ 0.5f, -0.5f, 10.0f}, 0xff14f914},
12362 quad6[] =
12364 {{-1.0f, 0.5f, 10.0f}, 0xfff91414},
12365 {{ 1.0f, 0.5f, 10.0f}, 0xfff91414},
12366 {{-1.0f, 0.25f, 10.0f}, 0xfff91414},
12367 {{ 1.0f, 0.25f, 10.0f}, 0xfff91414},
12370 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
12371 0, 0, 640, 480, NULL, NULL, NULL, NULL);
12372 d3d = Direct3DCreate9(D3D_SDK_VERSION);
12373 ok(!!d3d, "Failed to create a D3D object.\n");
12374 if (!(device = create_device(d3d, window, window, TRUE)))
12376 skip("Failed to create a D3D device, skipping tests.\n");
12377 goto done;
12380 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
12381 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
12383 vp.X = 0;
12384 vp.Y = 0;
12385 vp.Width = 640;
12386 vp.Height = 480;
12387 vp.MinZ = 0.0;
12388 vp.MaxZ = 7.5;
12390 hr = IDirect3DDevice9_SetViewport(device, &vp);
12391 if(FAILED(hr))
12393 /* Windows 7 rejects MaxZ > 1.0, Windows XP allows it. This doesn't break
12394 * the tests because the 7.5 is just intended to show that it doesn't have
12395 * any influence on the drawing or D3DRS_CLIPPING = FALSE. Set an accepted
12396 * viewport and continue.
12398 ok(broken(hr == D3DERR_INVALIDCALL), "D3D rejected maxZ > 1.0\n");
12399 vp.MaxZ = 1.0;
12400 hr = IDirect3DDevice9_SetViewport(device, &vp);
12402 ok(SUCCEEDED(hr), "SetViewport failed, hr %#x.\n", hr);
12404 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 1.0, 0);
12405 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
12407 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, FALSE);
12408 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12409 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
12410 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12411 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
12412 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12413 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
12414 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12416 hr = IDirect3DDevice9_BeginScene(device);
12417 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
12419 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
12420 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
12422 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(*quad1));
12423 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
12424 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(*quad2));
12425 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
12427 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, TRUE);
12428 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12430 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, sizeof(*quad3));
12431 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
12432 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad4, sizeof(*quad4));
12433 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
12435 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, FALSE);
12436 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12438 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
12439 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
12441 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad5, sizeof(*quad5));
12442 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
12444 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, TRUE);
12445 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12447 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad6, sizeof(*quad6));
12448 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
12450 hr = IDirect3DDevice9_EndScene(device);
12451 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
12453 if (caps.PrimitiveMiscCaps & D3DPMISCCAPS_CLIPTLVERTS)
12455 color = getPixelColor(device, 75, 75);
12456 ok(color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
12457 color = getPixelColor(device, 150, 150);
12458 ok(color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
12459 color = getPixelColor(device, 320, 240);
12460 ok(color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
12461 color = getPixelColor(device, 320, 330);
12462 ok(color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
12463 color = getPixelColor(device, 320, 330);
12464 ok(color_match(color, 0x0000ff00, 1), "color 0x%08x.\n", color);
12466 else
12468 color = getPixelColor(device, 75, 75);
12469 ok(color_match(color, 0x00ffffff, 1), "color 0x%08x.\n", color);
12470 color = getPixelColor(device, 150, 150);
12471 ok(color_match(color, 0x00ffffff, 1), "color 0x%08x.\n", color);
12472 color = getPixelColor(device, 320, 240);
12473 ok(color_match(color, 0x00002b7f, 1), "color 0x%08x.\n", color);
12474 color = getPixelColor(device, 320, 330);
12475 ok(color_match(color, 0x00f9e814, 1), "color 0x%08x.\n", color);
12476 color = getPixelColor(device, 320, 330);
12477 ok(color_match(color, 0x00f9e814, 1), "color 0x%08x.\n", color);
12480 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
12481 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
12483 refcount = IDirect3DDevice9_Release(device);
12484 ok(!refcount, "Device has %u references left.\n", refcount);
12485 done:
12486 IDirect3D9_Release(d3d);
12487 DestroyWindow(window);
12490 static void depth_bounds_test(void)
12492 static const struct
12494 struct vec4 position;
12495 DWORD diffuse;
12497 quad1[] =
12499 {{ 0.0f, 0.0f, 0.0f, 1.0f}, 0xfff9e814},
12500 {{640.0f, 0.0f, 0.0f, 1.0f}, 0xfff9e814},
12501 {{ 0.0f, 480.0f, 1.0f, 1.0f}, 0xfff9e814},
12502 {{640.0f, 480.0f, 1.0f, 1.0f}, 0xfff9e814},
12504 quad2[] =
12506 {{ 0.0f, 0.0f, 0.6f, 1.0f}, 0xff002b7f},
12507 {{640.0f, 0.0f, 0.6f, 1.0f}, 0xff002b7f},
12508 {{ 0.0f, 480.0f, 0.6f, 1.0f}, 0xff002b7f},
12509 {{640.0f, 480.0f, 0.6f, 1.0f}, 0xff002b7f},
12511 quad3[] =
12513 {{ 0.0f, 100.0f, 0.6f, 1.0f}, 0xfff91414},
12514 {{640.0f, 100.0f, 0.6f, 1.0f}, 0xfff91414},
12515 {{ 0.0f, 160.0f, 0.6f, 1.0f}, 0xfff91414},
12516 {{640.0f, 160.0f, 0.6f, 1.0f}, 0xfff91414},
12519 union {
12520 DWORD d;
12521 float f;
12522 } tmpvalue;
12524 IDirect3DSurface9 *offscreen_surface = NULL;
12525 IDirect3DDevice9 *device;
12526 IDirect3D9 *d3d;
12527 D3DCOLOR color;
12528 ULONG refcount;
12529 HWND window;
12530 HRESULT hr;
12532 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
12533 0, 0, 640, 480, NULL, NULL, NULL, NULL);
12534 d3d = Direct3DCreate9(D3D_SDK_VERSION);
12535 ok(!!d3d, "Failed to create a D3D object.\n");
12536 if (IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL,
12537 D3DFMT_X8R8G8B8, 0, D3DRTYPE_SURFACE, MAKEFOURCC('N','V','D','B')) != D3D_OK)
12539 skip("No NVDB (depth bounds test) support, skipping tests.\n");
12540 goto done;
12542 if (!(device = create_device(d3d, window, window, TRUE)))
12544 skip("Failed to create a D3D device, skipping tests.\n");
12545 goto done;
12548 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 32, 32,
12549 MAKEFOURCC('N','V','D','B'), D3DPOOL_DEFAULT, &offscreen_surface, NULL);
12550 ok(FAILED(hr), "Able to create surface, hr %#x.\n", hr);
12551 if (offscreen_surface) IDirect3DSurface9_Release(offscreen_surface);
12553 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0, 0);
12554 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
12556 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
12557 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12558 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, TRUE);
12559 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12560 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
12561 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12562 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_ALWAYS);
12563 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12566 hr = IDirect3DDevice9_BeginScene(device);
12567 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
12569 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
12570 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
12572 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(*quad1));
12573 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
12575 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ADAPTIVETESS_X, MAKEFOURCC('N','V','D','B'));
12576 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12578 tmpvalue.f = 0.625;
12579 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ADAPTIVETESS_Z, tmpvalue.d);
12580 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12582 tmpvalue.f = 0.75;
12583 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ADAPTIVETESS_W, tmpvalue.d);
12584 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12586 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(*quad2));
12587 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
12589 tmpvalue.f = 0.75;
12590 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ADAPTIVETESS_Z, tmpvalue.d);
12591 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12593 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, sizeof(*quad3));
12594 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
12596 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ADAPTIVETESS_X, 0);
12597 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12599 hr = IDirect3DDevice9_EndScene(device);
12600 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
12602 color = getPixelColor(device, 150, 130);
12603 ok(color_match(color, 0x00f9e814, 1), "color 0x%08x.\n", color);
12604 color = getPixelColor(device, 150, 200);
12605 ok(color_match(color, 0x00f9e814, 1), "color 0x%08x.\n", color);
12606 color = getPixelColor(device, 150, 300-5);
12607 ok(color_match(color, 0x00f9e814, 1), "color 0x%08x.\n", color);
12608 color = getPixelColor(device, 150, 300+5);
12609 ok(color_match(color, 0x00002b7f, 1), "color 0x%08x.\n", color);/**/
12610 color = getPixelColor(device, 150, 330);
12611 ok(color_match(color, 0x00002b7f, 1), "color 0x%08x.\n", color);
12612 color = getPixelColor(device, 150, 360-5);
12613 ok(color_match(color, 0x00002b7f, 1), "color 0x%08x.\n", color);/**/
12614 color = getPixelColor(device, 150, 360+5);
12615 ok(color_match(color, 0x00f9e814, 1), "color 0x%08x.\n", color);
12617 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
12618 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
12619 refcount = IDirect3DDevice9_Release(device);
12620 ok(!refcount, "Device has %u references left.\n", refcount);
12621 done:
12622 IDirect3D9_Release(d3d);
12623 DestroyWindow(window);
12626 static void depth_buffer_test(void)
12628 static const struct
12630 struct vec3 position;
12631 DWORD diffuse;
12633 quad1[] =
12635 {{-1.0, 1.0, 0.33f}, 0xff00ff00},
12636 {{ 1.0, 1.0, 0.33f}, 0xff00ff00},
12637 {{-1.0, -1.0, 0.33f}, 0xff00ff00},
12638 {{ 1.0, -1.0, 0.33f}, 0xff00ff00},
12640 quad2[] =
12642 {{-1.0, 1.0, 0.50f}, 0xffff00ff},
12643 {{ 1.0, 1.0, 0.50f}, 0xffff00ff},
12644 {{-1.0, -1.0, 0.50f}, 0xffff00ff},
12645 {{ 1.0, -1.0, 0.50f}, 0xffff00ff},
12647 quad3[] =
12649 {{-1.0, 1.0, 0.66f}, 0xffff0000},
12650 {{ 1.0, 1.0, 0.66f}, 0xffff0000},
12651 {{-1.0, -1.0, 0.66f}, 0xffff0000},
12652 {{ 1.0, -1.0, 0.66f}, 0xffff0000},
12654 static const DWORD expected_colors[4][4] =
12656 {0x000000ff, 0x000000ff, 0x0000ff00, 0x00ff0000},
12657 {0x000000ff, 0x000000ff, 0x0000ff00, 0x00ff0000},
12658 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x00ff0000},
12659 {0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000},
12662 IDirect3DSurface9 *backbuffer, *rt1, *rt2, *rt3;
12663 IDirect3DDevice9 *device;
12664 unsigned int i, j;
12665 D3DVIEWPORT9 vp;
12666 IDirect3D9 *d3d;
12667 D3DCOLOR color;
12668 ULONG refcount;
12669 HWND window;
12670 HRESULT hr;
12672 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
12673 0, 0, 640, 480, NULL, NULL, NULL, NULL);
12674 d3d = Direct3DCreate9(D3D_SDK_VERSION);
12675 ok(!!d3d, "Failed to create a D3D object.\n");
12676 if (!(device = create_device(d3d, window, window, TRUE)))
12678 skip("Failed to create a D3D device, skipping tests.\n");
12679 goto done;
12682 vp.X = 0;
12683 vp.Y = 0;
12684 vp.Width = 640;
12685 vp.Height = 480;
12686 vp.MinZ = 0.0;
12687 vp.MaxZ = 1.0;
12689 hr = IDirect3DDevice9_SetViewport(device, &vp);
12690 ok(SUCCEEDED(hr), "SetViewport failed, hr %#x.\n", hr);
12692 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
12693 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12694 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
12695 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12696 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
12697 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12698 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
12699 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12700 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
12701 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
12703 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &backbuffer);
12704 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
12705 hr = IDirect3DDevice9_CreateRenderTarget(device, 320, 240, D3DFMT_A8R8G8B8,
12706 D3DMULTISAMPLE_NONE, 0, FALSE, &rt1, NULL);
12707 ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
12708 hr = IDirect3DDevice9_CreateRenderTarget(device, 480, 360, D3DFMT_A8R8G8B8,
12709 D3DMULTISAMPLE_NONE, 0, FALSE, &rt2, NULL);
12710 ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
12711 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
12712 D3DMULTISAMPLE_NONE, 0, FALSE, &rt3, NULL);
12713 ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
12715 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt3);
12716 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
12717 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 0.0f, 0);
12718 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
12720 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
12721 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
12722 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
12723 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
12725 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt1);
12726 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
12727 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 0.0f, 0);
12728 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
12730 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt2);
12731 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
12732 hr = IDirect3DDevice9_BeginScene(device);
12733 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
12734 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(*quad2));
12735 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
12736 hr = IDirect3DDevice9_EndScene(device);
12737 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
12739 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
12740 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
12742 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
12743 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12745 hr = IDirect3DDevice9_BeginScene(device);
12746 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
12747 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(*quad1));
12748 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
12749 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad3, sizeof(*quad3));
12750 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
12751 hr = IDirect3DDevice9_EndScene(device);
12752 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
12754 for (i = 0; i < 4; ++i)
12756 for (j = 0; j < 4; ++j)
12758 unsigned int x = 80 * ((2 * j) + 1);
12759 unsigned int y = 60 * ((2 * i) + 1);
12760 color = getPixelColor(device, x, y);
12761 ok(color_match(color, expected_colors[i][j], 0),
12762 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors[i][j], x, y, color);
12766 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
12767 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
12769 IDirect3DSurface9_Release(backbuffer);
12770 IDirect3DSurface9_Release(rt3);
12771 IDirect3DSurface9_Release(rt2);
12772 IDirect3DSurface9_Release(rt1);
12773 refcount = IDirect3DDevice9_Release(device);
12774 ok(!refcount, "Device has %u references left.\n", refcount);
12775 done:
12776 IDirect3D9_Release(d3d);
12777 DestroyWindow(window);
12780 /* Test that partial depth copies work the way they're supposed to. The clear
12781 * on rt2 only needs a partial copy of the onscreen depth/stencil buffer, and
12782 * the following draw should only copy back the part that was modified. */
12783 static void depth_buffer2_test(void)
12785 static const struct
12787 struct vec3 position;
12788 DWORD diffuse;
12790 quad[] =
12792 {{-1.0f, 1.0f, 0.66f}, 0xffff0000},
12793 {{ 1.0f, 1.0f, 0.66f}, 0xffff0000},
12794 {{-1.0f, -1.0f, 0.66f}, 0xffff0000},
12795 {{ 1.0f, -1.0f, 0.66f}, 0xffff0000},
12798 IDirect3DSurface9 *backbuffer, *rt1, *rt2;
12799 IDirect3DDevice9 *device;
12800 unsigned int i, j;
12801 D3DVIEWPORT9 vp;
12802 IDirect3D9 *d3d;
12803 D3DCOLOR color;
12804 ULONG refcount;
12805 HWND window;
12806 HRESULT hr;
12808 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
12809 0, 0, 640, 480, NULL, NULL, NULL, NULL);
12810 d3d = Direct3DCreate9(D3D_SDK_VERSION);
12811 ok(!!d3d, "Failed to create a D3D object.\n");
12812 if (!(device = create_device(d3d, window, window, TRUE)))
12814 skip("Failed to create a D3D device, skipping tests.\n");
12815 goto done;
12818 vp.X = 0;
12819 vp.Y = 0;
12820 vp.Width = 640;
12821 vp.Height = 480;
12822 vp.MinZ = 0.0;
12823 vp.MaxZ = 1.0;
12825 hr = IDirect3DDevice9_SetViewport(device, &vp);
12826 ok(SUCCEEDED(hr), "SetViewport failed, hr %#x.\n", hr);
12828 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
12829 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12830 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
12831 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12832 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
12833 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12834 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
12835 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12836 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
12837 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
12839 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
12840 D3DMULTISAMPLE_NONE, 0, FALSE, &rt1, NULL);
12841 ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
12842 hr = IDirect3DDevice9_CreateRenderTarget(device, 480, 360, D3DFMT_A8R8G8B8,
12843 D3DMULTISAMPLE_NONE, 0, FALSE, &rt2, NULL);
12844 ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
12845 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &backbuffer);
12846 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
12848 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt1);
12849 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
12850 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
12851 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
12853 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
12854 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
12855 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 0.5f, 0);
12856 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
12858 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt2);
12859 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
12860 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 0.0f, 0);
12861 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
12863 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
12864 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
12866 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
12867 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12869 hr = IDirect3DDevice9_BeginScene(device);
12870 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
12871 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
12872 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
12873 hr = IDirect3DDevice9_EndScene(device);
12874 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
12876 for (i = 0; i < 4; ++i)
12878 for (j = 0; j < 4; ++j)
12880 unsigned int x = 80 * ((2 * j) + 1);
12881 unsigned int y = 60 * ((2 * i) + 1);
12882 color = getPixelColor(device, x, y);
12883 ok(color_match(color, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 0),
12884 "Expected color 0x0000ff00 at %u,%u, got 0x%08x.\n", x, y, color);
12888 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
12889 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
12891 IDirect3DSurface9_Release(backbuffer);
12892 IDirect3DSurface9_Release(rt2);
12893 IDirect3DSurface9_Release(rt1);
12894 refcount = IDirect3DDevice9_Release(device);
12895 ok(!refcount, "Device has %u references left.\n", refcount);
12896 done:
12897 IDirect3D9_Release(d3d);
12898 DestroyWindow(window);
12901 static void depth_blit_test(void)
12903 static const struct
12905 struct vec3 position;
12906 DWORD diffuse;
12908 quad1[] =
12910 {{-1.0f, 1.0f, 0.33f}, 0xff00ff00},
12911 {{ 1.0f, 1.0f, 0.33f}, 0xff00ff00},
12912 {{-1.0f, -1.0f, 0.33f}, 0xff00ff00},
12913 {{ 1.0f, -1.0f, 0.33f}, 0xff00ff00},
12915 quad2[] =
12917 {{-1.0f, 1.0f, 0.66f}, 0xff0000ff},
12918 {{ 1.0f, 1.0f, 0.66f}, 0xff0000ff},
12919 {{-1.0f, -1.0f, 0.66f}, 0xff0000ff},
12920 {{ 1.0f, -1.0f, 0.66f}, 0xff0000ff},
12922 static const DWORD expected_colors[4][4] =
12924 {0x000000ff, 0x000000ff, 0x0000ff00, 0x00ff0000},
12925 {0x000000ff, 0x000000ff, 0x0000ff00, 0x00ff0000},
12926 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x00ff0000},
12927 {0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000},
12930 IDirect3DSurface9 *backbuffer, *ds1, *ds2, *ds3;
12931 IDirect3DDevice9 *device;
12932 RECT src_rect, dst_rect;
12933 unsigned int i, j;
12934 D3DVIEWPORT9 vp;
12935 IDirect3D9 *d3d;
12936 D3DCOLOR color;
12937 ULONG refcount;
12938 HWND window;
12939 HRESULT hr;
12941 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
12942 0, 0, 640, 480, NULL, NULL, NULL, NULL);
12943 d3d = Direct3DCreate9(D3D_SDK_VERSION);
12944 ok(!!d3d, "Failed to create a D3D object.\n");
12945 if (!(device = create_device(d3d, window, window, TRUE)))
12947 skip("Failed to create a D3D device, skipping tests.\n");
12948 goto done;
12951 vp.X = 0;
12952 vp.Y = 0;
12953 vp.Width = 640;
12954 vp.Height = 480;
12955 vp.MinZ = 0.0;
12956 vp.MaxZ = 1.0;
12958 hr = IDirect3DDevice9_SetViewport(device, &vp);
12959 ok(SUCCEEDED(hr), "SetViewport failed, hr %#x.\n", hr);
12961 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &backbuffer);
12962 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
12963 hr = IDirect3DDevice9_GetDepthStencilSurface(device, &ds1);
12964 ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
12965 hr = IDirect3DDevice9_CreateDepthStencilSurface(device, 640, 480, D3DFMT_D24S8, 0, 0, FALSE, &ds2, NULL);
12966 ok(SUCCEEDED(hr), "CreateDepthStencilSurface failed, hr %#x.\n", hr);
12967 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds2);
12968 ok(SUCCEEDED(hr), "SetDepthStencilSurface failed, hr %#x.\n", hr);
12969 hr = IDirect3DDevice9_CreateDepthStencilSurface(device, 320, 240, D3DFMT_D24S8, 0, 0, FALSE, &ds3, NULL);
12970 ok(SUCCEEDED(hr), "CreateDepthStencilSurface failed, hr %#x.\n", hr);
12972 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
12973 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12974 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
12975 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12976 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
12977 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
12978 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
12979 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
12981 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
12982 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
12983 SetRect(&dst_rect, 0, 0, 480, 360);
12984 hr = IDirect3DDevice9_Clear(device, 1, (D3DRECT *)&dst_rect, D3DCLEAR_ZBUFFER, 0, 0.5f, 0);
12985 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
12986 SetRect(&dst_rect, 0, 0, 320, 240);
12987 hr = IDirect3DDevice9_Clear(device, 1, (D3DRECT *)&dst_rect, D3DCLEAR_ZBUFFER, 0, 1.0f, 0);
12988 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
12990 /* Partial blit. */
12991 SetRect(&src_rect, 0, 0, 320, 240);
12992 SetRect(&dst_rect, 0, 0, 320, 240);
12993 hr = IDirect3DDevice9_StretchRect(device, ds2, &src_rect, ds1, &dst_rect, D3DTEXF_POINT);
12994 ok(hr == D3DERR_INVALIDCALL, "StretchRect returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
12995 /* Flipped. */
12996 SetRect(&src_rect, 0, 0, 640, 480);
12997 SetRect(&dst_rect, 0, 480, 640, 0);
12998 hr = IDirect3DDevice9_StretchRect(device, ds2, &src_rect, ds1, &dst_rect, D3DTEXF_POINT);
12999 ok(hr == D3DERR_INVALIDCALL, "StretchRect returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
13000 /* Full, explicit. */
13001 SetRect(&src_rect, 0, 0, 640, 480);
13002 SetRect(&dst_rect, 0, 0, 640, 480);
13003 hr = IDirect3DDevice9_StretchRect(device, ds2, &src_rect, ds1, &dst_rect, D3DTEXF_POINT);
13004 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
13005 /* Filtered blit. */
13006 hr = IDirect3DDevice9_StretchRect(device, ds2, NULL, ds1, NULL, D3DTEXF_LINEAR);
13007 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
13008 /* Depth -> color blit.*/
13009 hr = IDirect3DDevice9_StretchRect(device, ds2, NULL, backbuffer, NULL, D3DTEXF_POINT);
13010 ok(hr == D3DERR_INVALIDCALL, "StretchRect returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
13011 IDirect3DSurface9_Release(backbuffer);
13012 /* Full surface, different sizes */
13013 hr = IDirect3DDevice9_StretchRect(device, ds3, NULL, ds1, NULL, D3DTEXF_POINT);
13014 ok(hr == D3DERR_INVALIDCALL, "StretchRect returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
13015 hr = IDirect3DDevice9_StretchRect(device, ds1, NULL, ds3, NULL, D3DTEXF_POINT);
13016 ok(hr == D3DERR_INVALIDCALL, "StretchRect returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
13018 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds1);
13019 ok(SUCCEEDED(hr), "SetDepthStencilSurface failed, hr %#x.\n", hr);
13020 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, 0xffff0000, 1.0f, 0);
13021 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
13022 hr = IDirect3DDevice9_StretchRect(device, ds2, NULL, ds1, NULL, D3DTEXF_POINT);
13023 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
13025 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
13026 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13027 hr = IDirect3DDevice9_BeginScene(device);
13028 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
13029 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(*quad1));
13030 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13031 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(*quad2));
13032 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13033 hr = IDirect3DDevice9_EndScene(device);
13034 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
13036 for (i = 0; i < 4; ++i)
13038 for (j = 0; j < 4; ++j)
13040 unsigned int x = 80 * ((2 * j) + 1);
13041 unsigned int y = 60 * ((2 * i) + 1);
13042 color = getPixelColor(device, x, y);
13043 ok(color_match(color, expected_colors[i][j], 0),
13044 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors[i][j], x, y, color);
13048 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
13049 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
13051 IDirect3DSurface9_Release(ds3);
13052 IDirect3DSurface9_Release(ds2);
13053 IDirect3DSurface9_Release(ds1);
13054 refcount = IDirect3DDevice9_Release(device);
13055 ok(!refcount, "Device has %u references left.\n", refcount);
13056 done:
13057 IDirect3D9_Release(d3d);
13058 DestroyWindow(window);
13061 static void intz_test(void)
13063 static const DWORD ps_code[] =
13065 0xffff0200, /* ps_2_0 */
13066 0x0200001f, 0x90000000, 0xa00f0800, /* dcl_2d s0 */
13067 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
13068 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0.0, 0.0, 0.0, 1.0 */
13069 0x02000001, 0x800f0001, 0xa0e40000, /* mov r1, c0 */
13070 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texld r0, t0, s0 */
13071 0x02000001, 0x80010001, 0x80e40000, /* mov r1.x, r0 */
13072 0x03010042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texldp r0, t0, s0 */
13073 0x02000001, 0x80020001, 0x80000000, /* mov r1.y, r0.x */
13074 0x02000001, 0x800f0800, 0x80e40001, /* mov oC0, r1 */
13075 0x0000ffff, /* end */
13077 struct
13079 float x, y, z;
13080 float s, t, p, q;
13082 quad[] =
13084 { -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.5f},
13085 { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.5f},
13086 { -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f},
13087 { 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.5f},
13089 half_quad_1[] =
13091 { -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.5f},
13092 { 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.5f},
13093 { -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f},
13094 { 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.5f},
13096 half_quad_2[] =
13098 { -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.5f},
13099 { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.5f},
13100 { -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f},
13101 { 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.5f},
13103 struct
13105 UINT x, y;
13106 D3DCOLOR color;
13108 expected_colors[] =
13110 { 80, 100, D3DCOLOR_ARGB(0x00, 0x20, 0x40, 0x00)},
13111 {240, 100, D3DCOLOR_ARGB(0x00, 0x60, 0xbf, 0x00)},
13112 {400, 100, D3DCOLOR_ARGB(0x00, 0x9f, 0x40, 0x00)},
13113 {560, 100, D3DCOLOR_ARGB(0x00, 0xdf, 0xbf, 0x00)},
13114 { 80, 450, D3DCOLOR_ARGB(0x00, 0x20, 0x40, 0x00)},
13115 {240, 450, D3DCOLOR_ARGB(0x00, 0x60, 0xbf, 0x00)},
13116 {400, 450, D3DCOLOR_ARGB(0x00, 0x9f, 0x40, 0x00)},
13117 {560, 450, D3DCOLOR_ARGB(0x00, 0xdf, 0xbf, 0x00)},
13120 IDirect3DSurface9 *original_rt, *rt;
13121 IDirect3DTexture9 *texture;
13122 IDirect3DPixelShader9 *ps;
13123 IDirect3DDevice9 *device;
13124 IDirect3DSurface9 *ds;
13125 IDirect3D9 *d3d;
13126 ULONG refcount;
13127 D3DCAPS9 caps;
13128 HWND window;
13129 HRESULT hr;
13130 UINT i;
13132 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
13133 0, 0, 640, 480, NULL, NULL, NULL, NULL);
13134 d3d = Direct3DCreate9(D3D_SDK_VERSION);
13135 ok(!!d3d, "Failed to create a D3D object.\n");
13136 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
13137 D3DFMT_X8R8G8B8, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, MAKEFOURCC('I','N','T','Z'))))
13139 skip("No INTZ support, skipping INTZ test.\n");
13140 goto done;
13142 if (!(device = create_device(d3d, window, window, TRUE)))
13144 skip("Failed to create a D3D device, skipping tests.\n");
13145 goto done;
13148 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
13149 ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
13150 if (caps.PixelShaderVersion < D3DPS_VERSION(2, 0))
13152 skip("No pixel shader 2.0 support, skipping INTZ test.\n");
13153 IDirect3DDevice9_Release(device);
13154 goto done;
13156 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
13158 skip("No unconditional NP2 texture support, skipping INTZ test.\n");
13159 IDirect3DDevice9_Release(device);
13160 goto done;
13163 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &original_rt);
13164 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
13166 hr = IDirect3DDevice9_CreateTexture(device, 640, 480, 1,
13167 D3DUSAGE_DEPTHSTENCIL, MAKEFOURCC('I','N','T','Z'), D3DPOOL_DEFAULT, &texture, NULL);
13168 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
13169 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
13170 D3DMULTISAMPLE_NONE, 0, FALSE, &rt, NULL);
13171 ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
13172 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code, &ps);
13173 ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
13175 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE4(0));
13176 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
13177 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
13178 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13179 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_ALWAYS);
13180 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13181 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
13182 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13183 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
13184 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13186 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
13187 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
13188 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
13189 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
13190 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
13191 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
13192 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
13193 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
13194 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
13195 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
13197 /* Render offscreen, using the INTZ texture as depth buffer */
13198 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &ds);
13199 ok(SUCCEEDED(hr), "GetSurfaceLevel failed, hr %#x.\n", hr);
13200 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
13201 ok(SUCCEEDED(hr), "SetDepthStencilSurface failed, hr %#x.\n", hr);
13202 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
13203 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
13204 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
13205 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
13207 /* Setup the depth/stencil surface. */
13208 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
13209 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
13211 hr = IDirect3DDevice9_BeginScene(device);
13212 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
13213 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
13214 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13215 hr = IDirect3DDevice9_EndScene(device);
13216 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
13218 hr = IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
13219 ok(SUCCEEDED(hr), "SetDepthStencilSurface failed, hr %#x.\n", hr);
13220 IDirect3DSurface9_Release(ds);
13221 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
13222 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
13223 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
13224 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
13225 hr = IDirect3DDevice9_SetPixelShader(device, ps);
13226 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
13228 /* Read the depth values back. */
13229 hr = IDirect3DDevice9_BeginScene(device);
13230 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
13231 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
13232 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13233 hr = IDirect3DDevice9_EndScene(device);
13234 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
13236 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
13238 D3DCOLOR color = getPixelColor(device, expected_colors[i].x, expected_colors[i].y);
13239 ok(color_match(color, expected_colors[i].color, 1),
13240 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
13241 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
13244 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
13245 ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
13247 hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
13248 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
13249 IDirect3DTexture9_Release(texture);
13251 /* Render onscreen while using the INTZ texture as depth buffer */
13252 hr = IDirect3DDevice9_CreateTexture(device, 640, 480, 1,
13253 D3DUSAGE_DEPTHSTENCIL, MAKEFOURCC('I','N','T','Z'), D3DPOOL_DEFAULT, &texture, NULL);
13254 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &ds);
13255 ok(SUCCEEDED(hr), "GetSurfaceLevel failed, hr %#x.\n", hr);
13256 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
13257 ok(SUCCEEDED(hr), "SetDepthStencilSurface failed, hr %#x.\n", hr);
13258 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
13259 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
13261 /* Setup the depth/stencil surface. */
13262 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
13263 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
13265 hr = IDirect3DDevice9_BeginScene(device);
13266 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
13267 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
13268 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13269 hr = IDirect3DDevice9_EndScene(device);
13270 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
13272 hr = IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
13273 ok(SUCCEEDED(hr), "SetDepthStencilSurface failed, hr %#x.\n", hr);
13274 IDirect3DSurface9_Release(ds);
13275 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
13276 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
13277 hr = IDirect3DDevice9_SetPixelShader(device, ps);
13278 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
13280 /* Read the depth values back. */
13281 hr = IDirect3DDevice9_BeginScene(device);
13282 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
13283 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
13284 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13285 hr = IDirect3DDevice9_EndScene(device);
13286 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
13288 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
13290 D3DCOLOR color = getPixelColor(device, expected_colors[i].x, expected_colors[i].y);
13291 ok(color_match(color, expected_colors[i].color, 1),
13292 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
13293 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
13296 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
13297 ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
13299 hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
13300 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
13301 IDirect3DTexture9_Release(texture);
13303 /* Render offscreen, then onscreen, and finally check the INTZ texture in both areas */
13304 hr = IDirect3DDevice9_CreateTexture(device, 640, 480, 1,
13305 D3DUSAGE_DEPTHSTENCIL, MAKEFOURCC('I','N','T','Z'), D3DPOOL_DEFAULT, &texture, NULL);
13306 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &ds);
13307 ok(SUCCEEDED(hr), "GetSurfaceLevel failed, hr %#x.\n", hr);
13309 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
13310 ok(SUCCEEDED(hr), "SetDepthStencilSurface failed, hr %#x.\n", hr);
13311 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
13312 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
13313 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
13314 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
13316 /* Setup the depth/stencil surface. */
13317 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
13318 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
13320 hr = IDirect3DDevice9_BeginScene(device);
13321 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
13322 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, half_quad_1, sizeof(*half_quad_1));
13323 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13324 hr = IDirect3DDevice9_EndScene(device);
13325 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
13327 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
13328 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
13330 hr = IDirect3DDevice9_BeginScene(device);
13331 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
13332 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, half_quad_2, sizeof(*half_quad_2));
13333 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13334 hr = IDirect3DDevice9_EndScene(device);
13335 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
13337 hr = IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
13338 ok(SUCCEEDED(hr), "SetDepthStencilSurface failed, hr %#x.\n", hr);
13339 IDirect3DSurface9_Release(ds);
13340 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
13341 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
13342 hr = IDirect3DDevice9_SetPixelShader(device, ps);
13343 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
13345 /* Read the depth values back. */
13346 hr = IDirect3DDevice9_BeginScene(device);
13347 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
13348 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
13349 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13350 hr = IDirect3DDevice9_EndScene(device);
13351 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
13353 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
13355 D3DCOLOR color = getPixelColor(device, expected_colors[i].x, expected_colors[i].y);
13356 ok(color_match(color, expected_colors[i].color, 1),
13357 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
13358 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
13361 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
13362 ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
13364 IDirect3DTexture9_Release(texture);
13365 IDirect3DPixelShader9_Release(ps);
13366 IDirect3DSurface9_Release(original_rt);
13367 IDirect3DSurface9_Release(rt);
13368 refcount = IDirect3DDevice9_Release(device);
13369 ok(!refcount, "Device has %u references left.\n", refcount);
13370 done:
13371 IDirect3D9_Release(d3d);
13372 DestroyWindow(window);
13375 static void shadow_test(void)
13377 static const DWORD ps_code[] =
13379 0xffff0200, /* ps_2_0 */
13380 0x0200001f, 0x90000000, 0xa00f0800, /* dcl_2d s0 */
13381 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
13382 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0.0, 0.0, 0.0, 1.0 */
13383 0x02000001, 0x800f0001, 0xa0e40000, /* mov r1, c0 */
13384 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texld r0, t0, s0 */
13385 0x02000001, 0x80010001, 0x80e40000, /* mov r1.x, r0 */
13386 0x03010042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texldp r0, t0, s0 */
13387 0x02000001, 0x80020001, 0x80000000, /* mov r1.y, r0.x */
13388 0x02000001, 0x800f0800, 0x80e40001, /* mov 0C0, r1 */
13389 0x0000ffff, /* end */
13391 struct
13393 D3DFORMAT format;
13394 const char *name;
13396 formats[] =
13398 {D3DFMT_D16_LOCKABLE, "D3DFMT_D16_LOCKABLE"},
13399 {D3DFMT_D32, "D3DFMT_D32"},
13400 {D3DFMT_D15S1, "D3DFMT_D15S1"},
13401 {D3DFMT_D24S8, "D3DFMT_D24S8"},
13402 {D3DFMT_D24X8, "D3DFMT_D24X8"},
13403 {D3DFMT_D24X4S4, "D3DFMT_D24X4S4"},
13404 {D3DFMT_D16, "D3DFMT_D16"},
13405 {D3DFMT_D32F_LOCKABLE, "D3DFMT_D32F_LOCKABLE"},
13406 {D3DFMT_D24FS8, "D3DFMT_D24FS8"},
13408 struct
13410 float x, y, z;
13411 float s, t, p, q;
13413 quad[] =
13415 { -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f},
13416 { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f},
13417 { -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
13418 { 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f},
13420 struct
13422 UINT x, y;
13423 D3DCOLOR color;
13425 expected_colors[] =
13427 {400, 60, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00)},
13428 {560, 180, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x00)},
13429 {560, 300, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x00)},
13430 {400, 420, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x00)},
13431 {240, 420, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x00)},
13432 { 80, 300, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00)},
13433 { 80, 180, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00)},
13434 {240, 60, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00)},
13437 IDirect3DSurface9 *original_ds, *original_rt, *rt;
13438 IDirect3DPixelShader9 *ps;
13439 IDirect3DDevice9 *device;
13440 IDirect3D9 *d3d;
13441 ULONG refcount;
13442 D3DCAPS9 caps;
13443 HWND window;
13444 HRESULT hr;
13445 UINT i;
13447 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
13448 0, 0, 640, 480, NULL, NULL, NULL, NULL);
13449 d3d = Direct3DCreate9(D3D_SDK_VERSION);
13450 ok(!!d3d, "Failed to create a D3D object.\n");
13451 if (!(device = create_device(d3d, window, window, TRUE)))
13453 skip("Failed to create a D3D device, skipping tests.\n");
13454 goto done;
13457 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
13458 ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
13459 if (caps.PixelShaderVersion < D3DPS_VERSION(2, 0))
13461 skip("No pixel shader 2.0 support, skipping shadow test.\n");
13462 IDirect3DDevice9_Release(device);
13463 goto done;
13466 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &original_rt);
13467 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
13468 hr = IDirect3DDevice9_GetDepthStencilSurface(device, &original_ds);
13469 ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
13471 hr = IDirect3DDevice9_CreateRenderTarget(device, 1024, 1024, D3DFMT_A8R8G8B8,
13472 D3DMULTISAMPLE_NONE, 0, FALSE, &rt, NULL);
13473 ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
13474 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code, &ps);
13475 ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
13477 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE4(0));
13478 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
13479 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
13480 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13481 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_ALWAYS);
13482 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13483 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
13484 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13485 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
13486 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13488 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
13489 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
13490 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
13491 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
13492 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
13493 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
13494 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
13495 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
13496 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
13497 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
13499 for (i = 0; i < sizeof(formats) / sizeof(*formats); ++i)
13501 D3DFORMAT format = formats[i].format;
13502 IDirect3DTexture9 *texture;
13503 IDirect3DSurface9 *ds;
13504 unsigned int j;
13506 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
13507 D3DFMT_X8R8G8B8, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, format)))
13508 continue;
13510 hr = IDirect3DDevice9_CreateTexture(device, 1024, 1024, 1,
13511 D3DUSAGE_DEPTHSTENCIL, format, D3DPOOL_DEFAULT, &texture, NULL);
13512 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
13514 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &ds);
13515 ok(SUCCEEDED(hr), "GetSurfaceLevel failed, hr %#x.\n", hr);
13517 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
13518 ok(SUCCEEDED(hr), "SetDepthStencilSurface failed, hr %#x.\n", hr);
13520 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
13521 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
13523 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
13524 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
13526 /* Setup the depth/stencil surface. */
13527 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
13528 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
13530 hr = IDirect3DDevice9_BeginScene(device);
13531 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
13532 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
13533 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13534 hr = IDirect3DDevice9_EndScene(device);
13535 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
13537 hr = IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
13538 ok(SUCCEEDED(hr), "SetDepthStencilSurface failed, hr %#x.\n", hr);
13539 IDirect3DSurface9_Release(ds);
13541 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
13542 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
13544 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
13545 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
13547 hr = IDirect3DDevice9_SetPixelShader(device, ps);
13548 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
13550 /* Do the actual shadow mapping. */
13551 hr = IDirect3DDevice9_BeginScene(device);
13552 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
13553 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
13554 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13555 hr = IDirect3DDevice9_EndScene(device);
13556 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
13558 hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
13559 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
13560 IDirect3DTexture9_Release(texture);
13562 for (j = 0; j < sizeof(expected_colors) / sizeof(*expected_colors); ++j)
13564 D3DCOLOR color = getPixelColor(device, expected_colors[j].x, expected_colors[j].y);
13565 ok(color_match(color, expected_colors[j].color, 0),
13566 "Expected color 0x%08x at (%u, %u) for format %s, got 0x%08x.\n",
13567 expected_colors[j].color, expected_colors[j].x, expected_colors[j].y,
13568 formats[i].name, color);
13571 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
13572 ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
13575 IDirect3DPixelShader9_Release(ps);
13576 IDirect3DSurface9_Release(original_ds);
13577 IDirect3DSurface9_Release(original_rt);
13578 IDirect3DSurface9_Release(rt);
13579 refcount = IDirect3DDevice9_Release(device);
13580 ok(!refcount, "Device has %u references left.\n", refcount);
13581 done:
13582 IDirect3D9_Release(d3d);
13583 DestroyWindow(window);
13586 static void clip_planes(IDirect3DDevice9 *device, const char *test_name)
13588 static const struct
13590 struct vec3 position;
13591 DWORD diffuse;
13593 quad1[] =
13595 {{-1.0f, -1.0f, 0.0f}, 0xfff9e814},
13596 {{-1.0f, 1.0f, 0.0f}, 0xfff9e814},
13597 {{ 1.0f, -1.0f, 0.0f}, 0xfff9e814},
13598 {{ 1.0f, 1.0f, 0.0f}, 0xfff9e814},
13600 quad2[] =
13602 {{-1.0f, -1.0f, 0.0f}, 0xff002b7f},
13603 {{-1.0f, 1.0f, 0.0f}, 0xff002b7f},
13604 {{ 1.0f, -1.0f, 0.0f}, 0xff002b7f},
13605 {{ 1.0f, 1.0f, 0.0f}, 0xff002b7f},
13607 D3DCOLOR color;
13608 HRESULT hr;
13610 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 1.0, 0);
13611 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
13613 hr = IDirect3DDevice9_BeginScene(device);
13614 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
13616 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
13617 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
13619 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPLANEENABLE, 0);
13620 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13621 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad1, sizeof(*quad1));
13622 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13624 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPLANEENABLE, 0x1);
13625 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13626 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad2, sizeof(*quad2));
13627 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13629 hr = IDirect3DDevice9_EndScene(device);
13630 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
13632 color = getPixelColor(device, 1, 240);
13633 ok(color_match(color, 0x00002b7f, 1), "%s test: color 0x%08x.\n", test_name, color);
13634 color = getPixelColor(device, 638, 240);
13635 ok(color_match(color, 0x00002b7f, 1), "%s test: color 0x%08x.\n", test_name, color);
13637 color = getPixelColor(device, 1, 241);
13638 ok(color_match(color, 0x00f9e814, 1), "%s test: color 0x%08x.\n", test_name, color);
13639 color = getPixelColor(device, 638, 241);
13640 ok(color_match(color, 0x00f9e814, 1), "%s test: color 0x%08x.\n", test_name, color);
13643 static void clip_planes_test(void)
13645 IDirect3DSurface9 *offscreen_surface, *original_rt;
13646 IDirect3DTexture9 *offscreen = NULL;
13647 IDirect3DVertexShader9 *shader;
13648 IDirect3DDevice9 *device;
13649 IDirect3D9 *d3d;
13650 ULONG refcount;
13651 D3DCAPS9 caps;
13652 HWND window;
13653 HRESULT hr;
13655 static const float plane0[4] = {0.0f, 1.0f, 0.0f, 0.5f / 480.0f}; /* a quarter-pixel offset */
13656 static const DWORD shader_code[] =
13658 0xfffe0200, /* vs_2_0 */
13659 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
13660 0x0200001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
13661 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
13662 0x02000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
13663 0x0000ffff /* end */
13666 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
13667 0, 0, 640, 480, NULL, NULL, NULL, NULL);
13668 d3d = Direct3DCreate9(D3D_SDK_VERSION);
13669 ok(!!d3d, "Failed to create a D3D object.\n");
13670 if (!(device = create_device(d3d, window, window, TRUE)))
13672 skip("Failed to create a D3D device, skipping tests.\n");
13673 goto done;
13676 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
13677 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
13678 if (caps.VertexShaderVersion < D3DVS_VERSION(2, 0))
13680 skip("No vs_2_0 support, skipping tests.\n");
13681 IDirect3DDevice9_Release(device);
13682 goto done;
13685 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &original_rt);
13686 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
13688 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
13689 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13690 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
13691 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13692 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
13693 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13694 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, TRUE);
13695 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13697 hr = IDirect3DDevice9_SetVertexShader(device, NULL);
13698 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShader failed, hr=%08x\n", hr);
13699 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
13700 ok(hr == D3D_OK, "IDirect3DDevice9_SetPixelShader failed, hr=%08x\n", hr);
13702 IDirect3DDevice9_SetClipPlane(device, 0, plane0);
13704 clip_planes(device, "Onscreen FFP");
13706 hr = IDirect3DDevice9_CreateTexture(device, 640, 480, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &offscreen, NULL);
13707 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
13708 hr = IDirect3DTexture9_GetSurfaceLevel(offscreen, 0, &offscreen_surface);
13709 ok(SUCCEEDED(hr), "GetSurfaceLevel failed, hr %#x.\n", hr);
13710 hr = IDirect3DDevice9_SetRenderTarget(device, 0, offscreen_surface);
13711 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderTarget failed, hr=%08x\n", hr);
13713 clip_planes(device, "Offscreen FFP");
13715 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
13716 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
13718 hr = IDirect3DDevice9_CreateVertexShader(device, shader_code, &shader);
13719 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
13720 hr = IDirect3DDevice9_SetVertexShader(device, shader);
13721 ok(hr == D3D_OK, "IDirect3DDevice9_SetVertexShader returned %08x\n", hr);
13723 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
13724 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderTarget failed, hr=%08x\n", hr);
13726 clip_planes(device, "Onscreen vertex shader");
13728 hr = IDirect3DDevice9_SetRenderTarget(device, 0, offscreen_surface);
13729 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderTarget failed, hr=%08x\n", hr);
13731 clip_planes(device, "Offscreen vertex shader");
13733 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
13734 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
13736 IDirect3DVertexShader9_Release(shader);
13737 IDirect3DSurface9_Release(original_rt);
13738 IDirect3DSurface9_Release(offscreen_surface);
13739 IDirect3DTexture9_Release(offscreen);
13740 refcount = IDirect3DDevice9_Release(device);
13741 ok(!refcount, "Device has %u references left.\n", refcount);
13742 done:
13743 IDirect3D9_Release(d3d);
13744 DestroyWindow(window);
13747 static void fp_special_test(void)
13749 /* Microsoft's assembler generates nan and inf with "1.#QNAN" and "1.#INF." respectively */
13750 static const DWORD vs_header[] =
13752 0xfffe0200, /* vs_2_0 */
13753 0x05000051, 0xa00f0000, 0x00000000, 0x3f000000, 0x3f800000, 0x40000000, /* def c0, 0.0, 0.5, 1.0, 2.0 */
13754 0x05000051, 0xa00f0001, 0x7fc00000, 0xff800000, 0x7f800000, 0x00000000, /* def c1, nan, -inf, inf, 0 */
13755 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
13756 0x0200001f, 0x80000005, 0x900f0001, /* dcl_texcoord0 v1 */
13759 static const DWORD vs_log[] = {0x0200000f, 0x80010000, 0x90000001}; /* log r0.x, v1.x */
13760 static const DWORD vs_pow[] =
13761 {0x03000020, 0x80010000, 0x90000001, 0x90000001}; /* pow r0.x, v1.x, v1.x */
13762 static const DWORD vs_nrm[] = {0x02000024, 0x80070000, 0x90000001}; /* nrm r0.xyz, v1.x */
13763 static const DWORD vs_rcp1[] = {0x02000006, 0x80010000, 0x90000001}; /* rcp r0.x, v1.x */
13764 static const DWORD vs_rcp2[] = {0x02000006, 0x80010000, 0x91000001}; /* rcp r0.x, -v1.x */
13765 static const DWORD vs_rsq1[] = {0x02000007, 0x80010000, 0x90000001}; /* rsq r0.x, v1.x */
13766 static const DWORD vs_rsq2[] = {0x02000007, 0x80010000, 0x91000001}; /* rsq r0.x, -v1.x */
13767 static const DWORD vs_lit[] = {0x02000010, 0x800f0000, 0x90000001, /* lit r0, v1.xxxx */
13768 0x02000001, 0x80010000, 0x80aa0000}; /* mov r0.x, v0.z */
13769 static const DWORD vs_def1[] = {0x02000001, 0x80010000, 0xa0000001}; /* mov r0.x, c1.x */
13770 static const DWORD vs_def2[] = {0x02000001, 0x80010000, 0xa0550001}; /* mov r0.x, c1.y */
13771 static const DWORD vs_def3[] = {0x02000001, 0x80010000, 0xa0aa0001}; /* mov r0.x, c1.z */
13773 static const DWORD vs_footer[] =
13775 0x03000005, 0x80020000, 0x80000000, 0xa0ff0000, /* mul r0.y, r0.x, c0.w */
13776 0x0300000d, 0x80040000, 0x80000000, 0x80550000, /* sge r0.z, r0.x, r0.y */
13777 0x0300000d, 0x80020000, 0x80e40000, 0x80000000, /* sge r0.y, r0, r0.x */
13778 0x03000005, 0x80040000, 0x80550000, 0x80e40000, /* mul r0.z, r0.y, r0 */
13779 0x0300000b, 0x80080000, 0x81aa0000, 0x80aa0000, /* max r0.w, -r0.z, r0.z */
13780 0x0300000c, 0x80020000, 0x80000000, 0x80000000, /* slt r0.y, r0.x, r0.x */
13781 0x03000002, 0x80040000, 0x80550000, 0x80550000, /* add r0.z, r0.y, r0.y */
13782 0x0300000c, 0x80020000, 0xa0000000, 0x80ff0000, /* slt r0.y, c0.x, r0.w */
13783 0x0300000b, 0x80080000, 0x81aa0000, 0x80aa0000, /* max r0.w, -r0.z, r0.z */
13784 0x03000002, 0x80040000, 0x81550000, 0xa0e40000, /* add r0.z, -r0.y, c0 */
13785 0x0300000c, 0x80080000, 0xa0000000, 0x80e40000, /* slt r0.w, c0.x, r0 */
13786 0x03000005, 0x80040000, 0x80ff0000, 0x80e40000, /* mul r0.z, r0.w, r0 */
13787 0x04000004, 0x80020000, 0x80aa0000, 0xa0e40000, 0x80e40000, /* mad r0.y, r0.z, c0, r0 */
13788 0x02000001, 0xe0030000, 0x80e40000, /* mov oT0.xy, r0 */
13789 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
13790 0x0000ffff, /* end */
13793 static const struct
13795 const char *name;
13796 const DWORD *ops;
13797 DWORD size;
13798 D3DCOLOR r500;
13799 D3DCOLOR r600;
13800 D3DCOLOR nv40;
13801 D3DCOLOR nv50;
13802 D3DCOLOR warp;
13804 vs_body[] =
13806 /* The basic ideas here are:
13807 * 2.0 * +/-INF == +/-INF
13808 * NAN != NAN
13810 * The vertex shader value is written to the red component, with 0.0
13811 * and +/-INF mapping to 0xff, and NAN to 0x7f. Anything else should
13812 * result in 0x00. The pixel shader value is written to the green
13813 * component, but here 0.0 also results in 0x00. The actual value is
13814 * written to the blue component.
13816 * There are considerable differences between graphics cards in how
13817 * these are handled, but pow and nrm never generate INF or NAN on
13818 * real hardware. */
13819 {"log", vs_log, sizeof(vs_log), 0x00000000, 0x00000000, 0x00ff0000, 0x00ff7f00, 0x00ff8000},
13820 {"pow", vs_pow, sizeof(vs_pow), 0x000000ff, 0x000000ff, 0x0000ff00, 0x000000ff, 0x00008000},
13821 {"nrm", vs_nrm, sizeof(vs_nrm), 0x00ff0000, 0x00ff0000, 0x0000ff00, 0x00ff0000, 0x00008000},
13822 {"rcp1", vs_rcp1, sizeof(vs_rcp1), 0x000000ff, 0x000000ff, 0x00ff00ff, 0x00ff7f00, 0x00ff8000},
13823 {"rcp2", vs_rcp2, sizeof(vs_rcp2), 0x000000ff, 0x00000000, 0x00ff0000, 0x00ff7f00, 0x00ff8000},
13824 {"rsq1", vs_rsq1, sizeof(vs_rsq1), 0x000000ff, 0x000000ff, 0x00ff00ff, 0x00ff7f00, 0x00ff8000},
13825 {"rsq2", vs_rsq2, sizeof(vs_rsq2), 0x000000ff, 0x000000ff, 0x00ff00ff, 0x00ff7f00, 0x00ff8000},
13826 {"lit", vs_lit, sizeof(vs_lit), 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000},
13827 {"def1", vs_def1, sizeof(vs_def1), 0x000000ff, 0x00007f00, 0x0000ff00, 0x00007f00, 0x00008000},
13828 {"def2", vs_def2, sizeof(vs_def2), 0x00ff0000, 0x00ff7f00, 0x00ff0000, 0x00ff7f00, 0x00ff8000},
13829 {"def3", vs_def3, sizeof(vs_def3), 0x00ff00ff, 0x00ff7f00, 0x00ff00ff, 0x00ff7f00, 0x00ff8000},
13832 static const DWORD ps_code[] =
13834 0xffff0200, /* ps_2_0 */
13835 0x05000051, 0xa00f0000, 0x00000000, 0x3f000000, 0x3f800000, 0x40000000, /* def c0, 0.0, 0.5, 1.0, 2.0 */
13836 0x0200001f, 0x80000000, 0xb0030000, /* dcl t0.xy */
13837 0x0300000b, 0x80010001, 0xb0e40000, 0xa0e40000, /* max r1.x, t0, c0 */
13838 0x0300000a, 0x80010000, 0xb0e40000, 0xa0e40000, /* min r0.x, t0, c0 */
13839 0x03000002, 0x80010000, 0x80e40000, 0x81e40001, /* add r0.x, r0, -r1 */
13840 0x04000004, 0x80010001, 0xb0e40000, 0xa0ff0000, 0xb1e40000, /* mad r1.x, t0, c0.w. -t0 */
13841 0x02000023, 0x80010002, 0x80e40001, /* abs r2.x, r1 */
13842 0x02000023, 0x80010000, 0x80e40000, /* abs r0.x, r0 */
13843 0x02000023, 0x80010001, 0xb0e40000, /* abs r1.x, t0 */
13844 0x04000058, 0x80010002, 0x81e40002, 0xa0aa0000, 0xa0e40000, /* cmp r2.x, -r2, c0.z, c0 */
13845 0x02000023, 0x80010002, 0x80e40002, /* abs r2.x, r2 */
13846 0x04000058, 0x80010001, 0x81e40001, 0xa0aa0000, 0xa0e40000, /* cmp r1.x, -r1, c0.z, c0 */
13847 0x02000023, 0x80010001, 0x80e40001, /* abs r1.x, r1 */
13848 0x04000058, 0x80010003, 0x81e40002, 0xa0aa0000, 0xa0e40000, /* cmp r3.x, -r2, c0.z, c0 */
13849 0x04000058, 0x80010002, 0x81e40001, 0xa0aa0000, 0xa0e40000, /* cmp r2.x, -r1, c0.z, c0 */
13850 0x04000058, 0x80010000, 0x81e40000, 0xa0550000, 0xa0e40000, /* cmp r0.x, -r0, c0.y, c0 */
13851 0x03000005, 0x80010002, 0x80e40002, 0x80e40003, /* mul r2.x, r2, r3 */
13852 0x04000058, 0x80010000, 0x81e40002, 0xa0aa0000, 0x80e40000, /* cmp r0.x, -r2, c0.z, r0 */
13853 0x04000058, 0x80020000, 0x81000001, 0x80000000, 0xa0000000, /* cmp r0.y, -r1.x, r0.x, c0.x */
13854 0x02000001, 0x80050000, 0xb0c90000, /* mov r0.xz, t0.yzxw */
13855 0x02000001, 0x80080000, 0xa0aa0000, /* mov r0.w, c0.z */
13856 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
13857 0x0000ffff, /* end */
13860 struct
13862 float x, y, z;
13863 float s;
13865 quad[] =
13867 { -1.0f, 1.0f, 0.0f, 0.0f},
13868 { 1.0f, 1.0f, 1.0f, 0.0f},
13869 { -1.0f, -1.0f, 0.0f, 0.0f},
13870 { 1.0f, -1.0f, 1.0f, 0.0f},
13873 IDirect3DPixelShader9 *ps;
13874 IDirect3DDevice9 *device;
13875 UINT body_size = 0;
13876 IDirect3D9 *d3d;
13877 DWORD *vs_code;
13878 ULONG refcount;
13879 D3DCAPS9 caps;
13880 HWND window;
13881 HRESULT hr;
13882 UINT i;
13884 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
13885 0, 0, 640, 480, NULL, NULL, NULL, NULL);
13886 d3d = Direct3DCreate9(D3D_SDK_VERSION);
13887 ok(!!d3d, "Failed to create a D3D object.\n");
13888 if (!(device = create_device(d3d, window, window, TRUE)))
13890 skip("Failed to create a D3D device, skipping tests.\n");
13891 goto done;
13894 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
13895 ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
13896 if (caps.PixelShaderVersion < D3DPS_VERSION(2, 0) || caps.VertexShaderVersion < D3DVS_VERSION(2, 0))
13898 skip("No shader model 2.0 support, skipping floating point specials test.\n");
13899 IDirect3DDevice9_Release(device);
13900 goto done;
13903 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE1(0));
13904 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
13906 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code, &ps);
13907 ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
13908 hr = IDirect3DDevice9_SetPixelShader(device, ps);
13909 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
13911 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
13912 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
13914 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
13915 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
13917 for (i = 0; i < sizeof(vs_body) / sizeof(*vs_body); ++i)
13919 if (vs_body[i].size > body_size) body_size = vs_body[i].size;
13922 vs_code = HeapAlloc(GetProcessHeap(), 0, sizeof(vs_header) + body_size + sizeof(vs_footer));
13923 memcpy(vs_code, vs_header, sizeof(vs_header));
13925 for (i = 0; i < sizeof(vs_body) / sizeof(*vs_body); ++i)
13927 DWORD offset = sizeof(vs_header) / sizeof(*vs_header);
13928 IDirect3DVertexShader9 *vs;
13929 D3DCOLOR color;
13931 memcpy(vs_code + offset, vs_body[i].ops, vs_body[i].size);
13932 offset += vs_body[i].size / sizeof(*vs_body[i].ops);
13933 memcpy(vs_code + offset, vs_footer, sizeof(vs_footer));
13935 hr = IDirect3DDevice9_CreateVertexShader(device, vs_code, &vs);
13936 ok(SUCCEEDED(hr), "CreateVertexShader failed, hr %#x.\n", hr);
13937 hr = IDirect3DDevice9_SetVertexShader(device, vs);
13938 ok(SUCCEEDED(hr), "SetVertexShader failed, hr %#x.\n", hr);
13940 hr = IDirect3DDevice9_BeginScene(device);
13941 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
13942 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
13943 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
13944 hr = IDirect3DDevice9_EndScene(device);
13945 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
13947 color = getPixelColor(device, 320, 240);
13948 ok(color_match(color, vs_body[i].r500, 1)
13949 || color_match(color, vs_body[i].r600, 1)
13950 || color_match(color, vs_body[i].nv40, 1)
13951 || color_match(color, vs_body[i].nv50, 1)
13952 || broken(color_match(color, vs_body[i].warp, 1)),
13953 "Expected color 0x%08x, 0x%08x, 0x%08x or 0x%08x for instruction \"%s\", got 0x%08x.\n",
13954 vs_body[i].r500, vs_body[i].r600, vs_body[i].nv40, vs_body[i].nv50, vs_body[i].name, color);
13956 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
13957 ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
13959 hr = IDirect3DDevice9_SetVertexShader(device, NULL);
13960 ok(SUCCEEDED(hr), "SetVertexShader failed, hr %#x.\n", hr);
13961 IDirect3DVertexShader9_Release(vs);
13964 HeapFree(GetProcessHeap(), 0, vs_code);
13966 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
13967 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
13968 IDirect3DPixelShader9_Release(ps);
13969 refcount = IDirect3DDevice9_Release(device);
13970 ok(!refcount, "Device has %u references left.\n", refcount);
13971 done:
13972 IDirect3D9_Release(d3d);
13973 DestroyWindow(window);
13976 static void srgbwrite_format_test(void)
13978 IDirect3D9 *d3d;
13979 IDirect3DSurface9 *rt, *backbuffer;
13980 IDirect3DTexture9 *texture;
13981 IDirect3DDevice9 *device;
13982 ULONG refcount;
13983 HWND window;
13984 HRESULT hr;
13985 int i;
13986 DWORD color_rgb = 0x00808080, color_srgb = 0x00bcbcbc, color;
13987 static const struct
13989 D3DFORMAT fmt;
13990 const char *name;
13992 formats[] =
13994 { D3DFMT_R5G6B5, "D3DFMT_R5G6B5" },
13995 { D3DFMT_X8R8G8B8, "D3DFMT_X8R8G8B8" },
13996 { D3DFMT_A8R8G8B8, "D3DFMT_A8R8G8B8" },
13997 { D3DFMT_A16B16G16R16F, "D3DFMT_A16B16G16R16F" },
13998 { D3DFMT_A32B32G32R32F, "D3DFMT_A32B32G32R32F" },
14000 static const struct
14002 float x, y, z;
14003 float u, v;
14005 quad[] =
14007 {-1.0f, -1.0f, 0.1f, 0.0f, 0.0f},
14008 {-1.0f, 1.0f, 0.1f, 1.0f, 0.0f},
14009 { 1.0f, -1.0f, 0.1f, 0.0f, 1.0f},
14010 { 1.0f, 1.0f, 0.1f, 1.0f, 1.0f}
14013 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
14014 0, 0, 640, 480, NULL, NULL, NULL, NULL);
14015 d3d = Direct3DCreate9(D3D_SDK_VERSION);
14016 ok(!!d3d, "Failed to create a D3D object.\n");
14017 if (!(device = create_device(d3d, window, window, TRUE)))
14019 skip("Failed to create a D3D device, skipping tests.\n");
14020 goto done;
14023 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
14024 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
14025 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
14026 ok(SUCCEEDED(hr), "GetBackBuffer failed, hr %#x.\n", hr);
14027 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
14028 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
14029 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0x80808080);
14030 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14032 for(i = 0; i < (sizeof(formats) / sizeof(*formats)); i++)
14034 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
14035 D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, formats[i].fmt)))
14037 skip("Format %s not supported as render target, skipping test.\n",
14038 formats[i].name);
14039 continue;
14042 hr = IDirect3DDevice9_CreateTexture(device, 8, 8, 1, D3DUSAGE_RENDERTARGET,
14043 formats[i].fmt, D3DPOOL_DEFAULT, &texture, NULL);
14044 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
14045 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff0000, 1.0f, 0);
14046 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
14048 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &rt);
14049 ok(SUCCEEDED(hr), "GetSurfaceLevel failed, hr %#x.\n", hr);
14050 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
14051 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
14052 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x000000ff, 0.0f, 0);
14053 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
14055 hr = IDirect3DDevice9_BeginScene(device);
14056 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
14058 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SRGBWRITEENABLE, TRUE);
14059 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
14060 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
14061 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
14062 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
14063 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
14065 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SRGBWRITEENABLE, FALSE);
14066 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
14067 hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
14068 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
14069 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) texture);
14070 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
14071 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
14072 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
14073 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
14074 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
14075 hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
14076 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
14078 hr = IDirect3DDevice9_EndScene(device);
14079 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
14081 IDirect3DSurface9_Release(rt);
14082 IDirect3DTexture9_Release(texture);
14084 color = getPixelColor(device, 360, 240);
14085 if(IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
14086 D3DUSAGE_QUERY_SRGBWRITE,
14087 D3DRTYPE_TEXTURE, formats[i].fmt) == D3D_OK)
14089 /* Big slop for R5G6B5 */
14090 ok(color_match(color, color_srgb, 5), "Format %s supports srgb, expected color 0x%08x, got 0x%08x\n",
14091 formats[i].name, color_srgb, color);
14093 else
14095 /* Big slop for R5G6B5 */
14096 ok(color_match(color, color_rgb, 5), "Format %s does not support srgb, expected color 0x%08x, got 0x%08x\n",
14097 formats[i].name, color_rgb, color);
14100 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
14101 ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
14104 IDirect3DSurface9_Release(backbuffer);
14105 refcount = IDirect3DDevice9_Release(device);
14106 ok(!refcount, "Device has %u references left.\n", refcount);
14107 done:
14108 IDirect3D9_Release(d3d);
14109 DestroyWindow(window);
14112 static void ds_size_test(void)
14114 IDirect3DSurface9 *ds, *rt, *old_rt, *old_ds, *readback;
14115 IDirect3DDevice9 *device;
14116 DWORD num_passes;
14117 IDirect3D9 *d3d;
14118 ULONG refcount;
14119 HWND window;
14120 HRESULT hr;
14122 static const struct
14124 float x, y, z;
14126 quad[] =
14128 {-1.0f, -1.0f, 0.0f},
14129 {-1.0f, 1.0f, 0.0f},
14130 { 1.0f, -1.0f, 0.0f},
14131 { 1.0f, 1.0f, 0.0f},
14134 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
14135 0, 0, 640, 480, NULL, NULL, NULL, NULL);
14136 d3d = Direct3DCreate9(D3D_SDK_VERSION);
14137 ok(!!d3d, "Failed to create a D3D object.\n");
14138 if (!(device = create_device(d3d, window, window, TRUE)))
14140 skip("Failed to create a D3D device, skipping tests.\n");
14141 goto done;
14144 hr = IDirect3DDevice9_CreateRenderTarget(device, 64, 64, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, FALSE, &rt, NULL);
14145 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateRenderTarget failed, hr %#x.\n", hr);
14146 hr = IDirect3DDevice9_CreateDepthStencilSurface(device, 32, 32, D3DFMT_D24X8, D3DMULTISAMPLE_NONE, 0, TRUE, &ds, NULL);
14147 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateDepthStencilSurface failed, hr %#x.\n", hr);
14148 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 64, 64, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &readback, NULL);
14149 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateOffscreenPlainSurface failed, hr %#x.\n", hr);
14151 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
14152 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
14154 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
14155 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr);
14156 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_STENCILENABLE, FALSE);
14157 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr);
14158 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
14159 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr);
14160 hr = IDirect3DDevice9_ValidateDevice(device, &num_passes);
14161 ok(SUCCEEDED(hr), "IDirect3DDevice9_ValidateDevice failed, hr %#x.\n", hr);
14162 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &old_rt);
14163 ok(SUCCEEDED(hr), "IDirect3DDevice9_GetRenderTarget failed, hr %#x.\n", hr);
14164 hr = IDirect3DDevice9_GetDepthStencilSurface(device, &old_ds);
14165 ok(SUCCEEDED(hr), "IDirect3DDevice9_GetDepthStencilSurface failed, hr %#x.\n", hr);
14166 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
14167 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderTarget failed, hr %#x.\n", hr);
14168 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
14169 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetDepthStencilSurface failed, hr %#x.\n", hr);
14170 hr = IDirect3DDevice9_ValidateDevice(device, &num_passes);
14171 ok(SUCCEEDED(hr), "IDirect3DDevice9_ValidateDevice failed, hr %#x.\n", hr);
14173 /* The D3DCLEAR_TARGET clear works. D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER returns OK,
14174 * but does not change the surface's contents. */
14175 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x000000FF, 0.0f, 0);
14176 ok(SUCCEEDED(hr), "Target clear failed, hr %#x.\n", hr);
14177 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0x00000000, 0.2f, 0);
14178 ok(SUCCEEDED(hr), "Z Buffer clear failed, hr %#x.\n", hr);
14179 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff0000, 0.5f, 0);
14180 ok(SUCCEEDED(hr), "Target and Z Buffer clear failed, hr %#x.\n", hr);
14182 /* Nvidia does not clear the surface(The color is still 0x000000ff), AMD does(the color is 0x00ff0000) */
14184 /* Turning on any depth-related state results in a ValidateDevice failure */
14185 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
14186 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr);
14187 hr = IDirect3DDevice9_ValidateDevice(device, &num_passes);
14188 ok(hr == D3DERR_CONFLICTINGRENDERSTATE || hr == D3D_OK, "IDirect3DDevice9_ValidateDevice returned %#x, expected "
14189 "D3DERR_CONFLICTINGRENDERSTATE.\n", hr);
14190 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
14191 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr);
14192 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
14193 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr);
14194 hr = IDirect3DDevice9_ValidateDevice(device, &num_passes);
14195 ok(hr == D3DERR_CONFLICTINGRENDERSTATE || hr == D3D_OK, "IDirect3DDevice9_ValidateDevice returned %#x, expected "
14196 "D3DERR_CONFLICTINGRENDERSTATE.\n", hr);
14198 /* Try to draw with the device in an invalid state. */
14199 hr = IDirect3DDevice9_BeginScene(device);
14200 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
14201 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
14202 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
14203 hr = IDirect3DDevice9_EndScene(device);
14204 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
14206 /* Don't check the resulting draw unless we find an app that needs it. On
14207 * NVIDIA ValidateDevice() returns CONFLICTINGRENDERSTATE, so the result
14208 * is undefined. On AMD D3D seems to assume the stored Z buffer value is
14209 * 0.0 for all pixels, even those that are covered by the depth buffer. */
14211 hr = IDirect3DDevice9_SetRenderTarget(device, 0, old_rt);
14212 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderTarget failed, hr %#x.\n", hr);
14213 hr = IDirect3DDevice9_SetDepthStencilSurface(device, old_ds);
14214 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetDepthStencilSurface failed, hr %#x.\n", hr);
14215 hr = IDirect3DDevice9_ValidateDevice(device, &num_passes);
14216 ok(SUCCEEDED(hr), "IDirect3DDevice9_ValidateDevice failed, hr %#x.\n", hr);
14218 IDirect3DSurface9_Release(readback);
14219 IDirect3DSurface9_Release(ds);
14220 IDirect3DSurface9_Release(rt);
14221 IDirect3DSurface9_Release(old_rt);
14222 IDirect3DSurface9_Release(old_ds);
14223 refcount = IDirect3DDevice9_Release(device);
14224 ok(!refcount, "Device has %u references left.\n", refcount);
14225 done:
14226 IDirect3D9_Release(d3d);
14227 DestroyWindow(window);
14230 static void unbound_sampler_test(void)
14232 IDirect3DPixelShader9 *ps, *ps_cube, *ps_volume;
14233 IDirect3DSurface9 *rt, *old_rt;
14234 IDirect3DDevice9 *device;
14235 IDirect3D9 *d3d;
14236 ULONG refcount;
14237 D3DCAPS9 caps;
14238 DWORD color;
14239 HWND window;
14240 HRESULT hr;
14242 static const DWORD ps_code[] =
14244 0xffff0200, /* ps_2_0 */
14245 0x0200001f, 0x90000000, 0xa00f0800, /* dcl_2d s0 */
14246 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
14247 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texld r0, t0, s0 */
14248 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
14249 0x0000ffff, /* end */
14251 static const DWORD ps_code_cube[] =
14253 0xffff0200, /* ps_2_0 */
14254 0x0200001f, 0x98000000, 0xa00f0800, /* dcl_cube s0 */
14255 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
14256 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texld r0, t0, s0 */
14257 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
14258 0x0000ffff, /* end */
14260 static const DWORD ps_code_volume[] =
14262 0xffff0200, /* ps_2_0 */
14263 0x0200001f, 0xa0000000, 0xa00f0800, /* dcl_volume s0 */
14264 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
14265 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texld r0, t0, s0 */
14266 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
14267 0x0000ffff, /* end */
14270 static const struct
14272 float x, y, z;
14273 float u, v;
14275 quad[] =
14277 {-1.0f, -1.0f, 0.1f, 0.0f, 0.0f},
14278 {-1.0f, 1.0f, 0.1f, 1.0f, 0.0f},
14279 { 1.0f, -1.0f, 0.1f, 0.0f, 1.0f},
14280 { 1.0f, 1.0f, 0.1f, 1.0f, 1.0f}
14283 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
14284 0, 0, 640, 480, NULL, NULL, NULL, NULL);
14285 d3d = Direct3DCreate9(D3D_SDK_VERSION);
14286 ok(!!d3d, "Failed to create a D3D object.\n");
14287 if (!(device = create_device(d3d, window, window, TRUE)))
14289 skip("Failed to create a D3D device, skipping tests.\n");
14290 goto done;
14293 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
14294 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
14295 if (caps.PixelShaderVersion < D3DPS_VERSION(2, 0))
14297 skip("No ps_2_0 support, skipping tests.\n");
14298 IDirect3DDevice9_Release(device);
14299 goto done;
14301 if (!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP) || !(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
14303 skip("No cube / volume texture support, skipping tests.\n");
14304 IDirect3DDevice9_Release(device);
14305 goto done;
14308 hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
14309 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetTextureStage failed, %#x.\n", hr);
14311 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code, &ps);
14312 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreatePixelShader failed, hr %#x.\n", hr);
14313 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code_cube, &ps_cube);
14314 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreatePixelShader failed, hr %#x.\n", hr);
14315 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code_volume, &ps_volume);
14316 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreatePixelShader failed, hr %#x.\n", hr);
14318 hr = IDirect3DDevice9_CreateRenderTarget(device, 64, 64, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, TRUE, &rt, NULL);
14319 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateRenderTarget failed, hr %#x.\n", hr);
14321 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &old_rt);
14322 ok(SUCCEEDED(hr), "IDirect3DDevice9_GetRenderTarget failed, hr %#x.\n", hr);
14324 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
14325 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderTarget failed, hr %#x.\n", hr);
14327 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1 );
14328 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetFVF failed, hr %#x.\n", hr);
14330 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x56ffffff, 1.0f, 0);
14331 ok(SUCCEEDED(hr), "IDirect3DDevice9_Clear failed, hr %#x.\n", hr);
14333 hr = IDirect3DDevice9_SetPixelShader(device, ps);
14334 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetPixelShader failed, hr %#x.\n", hr);
14336 hr = IDirect3DDevice9_BeginScene(device);
14337 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
14338 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
14339 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
14340 hr = IDirect3DDevice9_EndScene(device);
14341 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
14343 color = getPixelColorFromSurface(rt, 32, 32);
14344 ok(color == 0xff000000, "Unbound sampler color is %#x.\n", color);
14346 /* Now try with a cube texture */
14347 hr = IDirect3DDevice9_SetPixelShader(device, ps_cube);
14348 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetPixelShader failed, hr %#x.\n", hr);
14350 hr = IDirect3DDevice9_BeginScene(device);
14351 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
14352 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
14353 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
14354 hr = IDirect3DDevice9_EndScene(device);
14355 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
14357 color = getPixelColorFromSurface(rt, 32, 32);
14358 ok(color == 0xff000000, "Unbound sampler color is %#x.\n", color);
14360 /* And then with a volume texture */
14361 hr = IDirect3DDevice9_SetPixelShader(device, ps_volume);
14362 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetPixelShader failed, hr %#x.\n", hr);
14364 hr = IDirect3DDevice9_BeginScene(device);
14365 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
14366 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
14367 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
14368 hr = IDirect3DDevice9_EndScene(device);
14369 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
14371 color = getPixelColorFromSurface(rt, 32, 32);
14372 ok(color == 0xff000000, "Unbound sampler color is %#x.\n", color);
14374 IDirect3DSurface9_Release(rt);
14375 IDirect3DSurface9_Release(old_rt);
14376 IDirect3DPixelShader9_Release(ps);
14377 IDirect3DPixelShader9_Release(ps_cube);
14378 IDirect3DPixelShader9_Release(ps_volume);
14379 refcount = IDirect3DDevice9_Release(device);
14380 ok(!refcount, "Device has %u references left.\n", refcount);
14381 done:
14382 IDirect3D9_Release(d3d);
14383 DestroyWindow(window);
14386 static void update_surface_test(void)
14388 static const BYTE blocks[][8] =
14390 {0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00}, /* White */
14391 {0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00}, /* Red */
14392 {0xe0, 0xff, 0xe0, 0xff, 0x00, 0x00, 0x00, 0x00}, /* Yellow */
14393 {0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00}, /* Green */
14394 {0xff, 0x07, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00}, /* Cyan */
14395 {0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00}, /* Blue */
14396 {0x1f, 0xf8, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00}, /* Magenta */
14398 static const struct
14400 UINT x, y;
14401 D3DCOLOR color;
14403 expected_colors[] =
14405 { 18, 240, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0xff)},
14406 { 57, 240, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0xff)},
14407 {109, 240, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0xff)},
14408 {184, 240, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00)},
14409 {290, 240, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x00)},
14410 {440, 240, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x00)},
14411 {584, 240, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0xff)},
14413 static const struct
14415 float x, y, z, w;
14416 float u, v;
14418 tri[] =
14420 { 0.0f, 480.0f, 0.0f, 1.0f, 0.0f, 0.0f},
14421 { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
14422 {640.0f, 240.0f, 0.0f, 10.0f, 100.0f, 0.5f},
14424 static const RECT rect_2x2 = {0, 0, 2, 2};
14425 static const struct
14427 UINT src_level;
14428 UINT dst_level;
14429 const RECT *r;
14430 HRESULT hr;
14432 block_size_tests[] =
14434 {1, 0, NULL, D3D_OK},
14435 {0, 1, NULL, D3DERR_INVALIDCALL},
14436 {5, 4, NULL, D3DERR_INVALIDCALL},
14437 {4, 5, NULL, D3DERR_INVALIDCALL},
14438 {4, 5, &rect_2x2, D3DERR_INVALIDCALL},
14439 {5, 5, &rect_2x2, D3D_OK},
14442 IDirect3DSurface9 *src_surface, *dst_surface;
14443 IDirect3DTexture9 *src_tex, *dst_tex;
14444 IDirect3DDevice9 *device;
14445 IDirect3D9 *d3d;
14446 ULONG refcount;
14447 UINT count, i;
14448 HWND window;
14449 HRESULT hr;
14451 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
14452 0, 0, 640, 480, NULL, NULL, NULL, NULL);
14453 d3d = Direct3DCreate9(D3D_SDK_VERSION);
14454 ok(!!d3d, "Failed to create a D3D object.\n");
14455 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
14456 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT1)))
14458 skip("DXT1 not supported, skipping tests.\n");
14459 goto done;
14461 if (!(device = create_device(d3d, window, window, TRUE)))
14463 skip("Failed to create a D3D device, skipping tests.\n");
14464 goto done;
14467 hr = IDirect3DDevice9_CreateTexture(device, 64, 64, 0, 0, D3DFMT_DXT1, D3DPOOL_SYSTEMMEM, &src_tex, NULL);
14468 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14469 hr = IDirect3DDevice9_CreateTexture(device, 64, 64, 0, 0, D3DFMT_DXT1, D3DPOOL_DEFAULT, &dst_tex, NULL);
14470 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14472 count = IDirect3DTexture9_GetLevelCount(src_tex);
14473 ok(count == 7, "Got level count %u, expected 7.\n", count);
14475 for (i = 0; i < count; ++i)
14477 UINT row_count, block_count, x, y;
14478 D3DSURFACE_DESC desc;
14479 BYTE *row, *block;
14480 D3DLOCKED_RECT r;
14482 hr = IDirect3DTexture9_GetLevelDesc(src_tex, i, &desc);
14483 ok(SUCCEEDED(hr), "Failed to get level desc, hr %#x.\n", hr);
14485 hr = IDirect3DTexture9_LockRect(src_tex, i, &r, NULL, 0);
14486 ok(SUCCEEDED(hr), "Failed to lock texture, hr %#x.\n", hr);
14488 row_count = ((desc.Height + 3) & ~3) / 4;
14489 block_count = ((desc.Width + 3) & ~3) / 4;
14490 row = r.pBits;
14492 for (y = 0; y < row_count; ++y)
14494 block = row;
14495 for (x = 0; x < block_count; ++x)
14497 memcpy(block, blocks[i], sizeof(blocks[i]));
14498 block += sizeof(blocks[i]);
14500 row += r.Pitch;
14503 hr = IDirect3DTexture9_UnlockRect(src_tex, i);
14504 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr);
14507 for (i = 0; i < sizeof(block_size_tests) / sizeof(*block_size_tests); ++i)
14509 hr = IDirect3DTexture9_GetSurfaceLevel(src_tex, block_size_tests[i].src_level, &src_surface);
14510 ok(SUCCEEDED(hr), "Failed to get texture surface, hr %#x.\n", hr);
14511 hr = IDirect3DTexture9_GetSurfaceLevel(dst_tex, block_size_tests[i].dst_level, &dst_surface);
14512 ok(SUCCEEDED(hr), "Failed to get texture surface, hr %#x.\n", hr);
14514 hr = IDirect3DDevice9_UpdateSurface(device, src_surface, block_size_tests[i].r, dst_surface, NULL);
14515 ok(hr == block_size_tests[i].hr, "Update surface returned %#x for test %u, expected %#x.\n",
14516 hr, i, block_size_tests[i].hr);
14518 IDirect3DSurface9_Release(dst_surface);
14519 IDirect3DSurface9_Release(src_surface);
14522 for (i = 0; i < count; ++i)
14524 hr = IDirect3DTexture9_GetSurfaceLevel(src_tex, i, &src_surface);
14525 ok(SUCCEEDED(hr), "Failed to get texture surface, hr %#x.\n", hr);
14526 hr = IDirect3DTexture9_GetSurfaceLevel(dst_tex, i, &dst_surface);
14527 ok(SUCCEEDED(hr), "Failed to get texture surface, hr %#x.\n", hr);
14529 hr = IDirect3DDevice9_UpdateSurface(device, src_surface, NULL, dst_surface, NULL);
14530 ok(SUCCEEDED(hr), "Failed to update surface at level %u, hr %#x.\n", i, hr);
14532 IDirect3DSurface9_Release(dst_surface);
14533 IDirect3DSurface9_Release(src_surface);
14536 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
14537 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14538 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
14539 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
14540 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZRHW | D3DFVF_TEX1);
14541 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
14542 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)dst_tex);
14543 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
14544 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
14545 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
14546 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
14547 ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
14549 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff000000, 0.0f, 0);
14550 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
14552 hr = IDirect3DDevice9_BeginScene(device);
14553 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
14554 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLELIST, 1, tri, sizeof(*tri));
14555 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
14556 hr = IDirect3DDevice9_EndScene(device);
14557 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
14559 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
14561 D3DCOLOR color = getPixelColor(device, expected_colors[i].x, expected_colors[i].y);
14562 ok(color_match(color, expected_colors[i].color, 0),
14563 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
14564 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
14567 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
14568 ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
14570 IDirect3DTexture9_Release(dst_tex);
14571 IDirect3DTexture9_Release(src_tex);
14572 refcount = IDirect3DDevice9_Release(device);
14573 ok(!refcount, "Device has %u references left.\n", refcount);
14574 done:
14575 IDirect3D9_Release(d3d);
14576 DestroyWindow(window);
14579 static void multisample_get_rtdata_test(void)
14581 IDirect3DSurface9 *original_ds, *original_rt, *rt, *readback;
14582 IDirect3DDevice9 *device;
14583 IDirect3D9 *d3d;
14584 ULONG refcount;
14585 HWND window;
14586 HRESULT hr;
14588 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
14589 0, 0, 640, 480, NULL, NULL, NULL, NULL);
14590 d3d = Direct3DCreate9(D3D_SDK_VERSION);
14591 ok(!!d3d, "Failed to create a D3D object.\n");
14592 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
14593 D3DFMT_A8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES, NULL)))
14595 skip("Multisampling not supported for D3DFMT_A8R8G8B8, skipping tests.\n");
14596 goto done;
14598 if (!(device = create_device(d3d, window, window, TRUE)))
14600 skip("Failed to create a D3D device, skipping tests.\n");
14601 goto done;
14604 hr = IDirect3DDevice9_CreateRenderTarget(device, 256, 256, D3DFMT_A8R8G8B8,
14605 D3DMULTISAMPLE_2_SAMPLES, 0, FALSE, &rt, NULL);
14606 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
14607 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8,
14608 D3DPOOL_SYSTEMMEM, &readback, NULL);
14609 ok(SUCCEEDED(hr), "Failed to create readback surface, hr %#x.\n", hr);
14611 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &original_rt);
14612 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
14613 hr = IDirect3DDevice9_GetDepthStencilSurface(device, &original_ds);
14614 ok(SUCCEEDED(hr), "Failed to get depth/stencil, hr %#x.\n", hr);
14616 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
14617 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
14618 hr = IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
14619 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
14621 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0, 0);
14622 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
14623 hr = IDirect3DDevice9_GetRenderTargetData(device, rt, readback);
14624 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
14626 hr = IDirect3DDevice9_SetDepthStencilSurface(device, original_ds);
14627 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
14628 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
14629 ok(SUCCEEDED(hr), "Failed to restore original render target, hr %#x.\n", hr);
14631 IDirect3DSurface9_Release(original_ds);
14632 IDirect3DSurface9_Release(original_rt);
14633 IDirect3DSurface9_Release(readback);
14634 IDirect3DSurface9_Release(rt);
14635 refcount = IDirect3DDevice9_Release(device);
14636 ok(!refcount, "Device has %u references left.\n", refcount);
14637 done:
14638 IDirect3D9_Release(d3d);
14639 DestroyWindow(window);
14642 static void multisampled_depth_buffer_test(void)
14644 IDirect3DDevice9 *device = 0;
14645 IDirect3DSurface9 *original_rt, *rt, *readback, *ds, *original_ds;
14646 IDirect3D9 *d3d;
14647 D3DCAPS9 caps;
14648 HRESULT hr;
14649 D3DPRESENT_PARAMETERS present_parameters;
14650 unsigned int i;
14651 static const struct
14653 float x, y, z;
14654 D3DCOLOR color;
14656 quad_1[] =
14658 { -1.0f, 1.0f, 0.0f, 0xffff0000},
14659 { 1.0f, 1.0f, 1.0f, 0xffff0000},
14660 { -1.0f, -1.0f, 0.0f, 0xffff0000},
14661 { 1.0f, -1.0f, 1.0f, 0xffff0000},
14663 quad_2[] =
14665 { -1.0f, 1.0f, 1.0f, 0xff0000ff},
14666 { 1.0f, 1.0f, 0.0f, 0xff0000ff},
14667 { -1.0f, -1.0f, 1.0f, 0xff0000ff},
14668 { 1.0f, -1.0f, 0.0f, 0xff0000ff},
14670 static const struct
14672 UINT x, y;
14673 D3DCOLOR color;
14675 expected_colors[] =
14677 { 80, 100, D3DCOLOR_ARGB(0xff, 0xff, 0x00, 0x00)},
14678 {240, 100, D3DCOLOR_ARGB(0xff, 0xff, 0x00, 0x00)},
14679 {400, 100, D3DCOLOR_ARGB(0xff, 0x00, 0x00, 0xff)},
14680 {560, 100, D3DCOLOR_ARGB(0xff, 0x00, 0x00, 0xff)},
14681 { 80, 450, D3DCOLOR_ARGB(0xff, 0xff, 0x00, 0x00)},
14682 {240, 450, D3DCOLOR_ARGB(0xff, 0xff, 0x00, 0x00)},
14683 {400, 450, D3DCOLOR_ARGB(0xff, 0x00, 0x00, 0xff)},
14684 {560, 450, D3DCOLOR_ARGB(0xff, 0x00, 0x00, 0xff)},
14687 d3d = Direct3DCreate9(D3D_SDK_VERSION);
14688 ok(!!d3d, "Failed to create a D3D object.\n");
14690 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT,
14691 D3DDEVTYPE_HAL, D3DFMT_A8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES, NULL)))
14693 skip("Multisampling not supported for D3DFMT_A8R8G8B8, skipping multisampled depth buffer test.\n");
14694 IDirect3D9_Release(d3d);
14695 return;
14697 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT,
14698 D3DDEVTYPE_HAL, D3DFMT_D24S8, TRUE, D3DMULTISAMPLE_2_SAMPLES, NULL)))
14700 skip("Multisampling not supported for D3DFMT_D24S8, skipping multisampled depth buffer test.\n");
14701 IDirect3D9_Release(d3d);
14702 return;
14705 ZeroMemory(&present_parameters, sizeof(present_parameters));
14706 present_parameters.Windowed = TRUE;
14707 present_parameters.hDeviceWindow = create_window();
14708 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
14709 present_parameters.BackBufferWidth = 640;
14710 present_parameters.BackBufferHeight = 480;
14711 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
14712 present_parameters.EnableAutoDepthStencil = TRUE;
14713 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
14714 present_parameters.MultiSampleType = D3DMULTISAMPLE_2_SAMPLES;
14716 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
14717 present_parameters.hDeviceWindow, D3DCREATE_HARDWARE_VERTEXPROCESSING,
14718 &present_parameters, &device);
14719 ok(hr == D3D_OK, "Failed to create a device, hr %#x.\n", hr);
14721 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
14722 ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
14723 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
14725 skip("No unconditional NP2 texture support, skipping multisampled depth buffer test.\n");
14726 goto cleanup;
14729 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
14730 D3DMULTISAMPLE_2_SAMPLES, 0, FALSE, &rt, NULL);
14731 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
14732 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
14733 D3DMULTISAMPLE_NONE, 0, TRUE, &readback, NULL);
14734 ok(SUCCEEDED(hr), "Failed to create readback surface, hr %#x.\n", hr);
14736 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &original_rt);
14737 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
14738 hr = IDirect3DDevice9_GetDepthStencilSurface(device, &ds);
14739 ok(SUCCEEDED(hr), "Failed to get depth/stencil, hr %#x.\n", hr);
14741 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
14742 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14743 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
14744 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14745 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
14746 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14747 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
14748 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14749 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
14750 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
14752 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 1.0f, 0);
14753 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
14755 /* Render onscreen and then offscreen */
14756 hr = IDirect3DDevice9_BeginScene(device);
14757 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
14758 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad_1, sizeof(*quad_1));
14759 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
14760 hr = IDirect3DDevice9_EndScene(device);
14761 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
14763 hr = IDirect3DDevice9_StretchRect(device, original_rt, NULL, rt, NULL, D3DTEXF_POINT);
14764 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
14765 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
14766 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
14768 hr = IDirect3DDevice9_BeginScene(device);
14769 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
14770 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad_2, sizeof(*quad_2));
14771 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
14772 hr = IDirect3DDevice9_EndScene(device);
14773 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
14775 hr = IDirect3DDevice9_StretchRect(device, rt, NULL, readback, NULL, D3DTEXF_POINT);
14776 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
14778 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
14780 D3DCOLOR color = getPixelColorFromSurface(readback, expected_colors[i].x, expected_colors[i].y);
14781 ok(color_match(color, expected_colors[i].color, 1),
14782 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
14783 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
14786 hr = IDirect3DDevice9_StretchRect(device, rt, NULL, original_rt, NULL, D3DTEXF_POINT);
14787 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
14788 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
14789 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
14791 /* Render offscreen and then onscreen */
14792 hr = IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
14793 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
14794 IDirect3DSurface9_Release(ds);
14795 hr = IDirect3DDevice9_CreateDepthStencilSurface(device, 640, 480, D3DFMT_D24S8,
14796 D3DMULTISAMPLE_2_SAMPLES, 0, TRUE, &ds, NULL);
14797 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
14798 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
14800 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 1.0f, 0);
14801 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
14803 hr = IDirect3DDevice9_BeginScene(device);
14804 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
14805 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad_1, sizeof(*quad_1));
14806 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
14807 hr = IDirect3DDevice9_EndScene(device);
14808 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
14810 hr = IDirect3DDevice9_StretchRect(device, rt, NULL, original_rt, NULL, D3DTEXF_POINT);
14811 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
14812 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
14813 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
14815 hr = IDirect3DDevice9_BeginScene(device);
14816 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
14817 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad_2, sizeof(*quad_2));
14818 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
14819 hr = IDirect3DDevice9_EndScene(device);
14820 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
14822 hr = IDirect3DDevice9_StretchRect(device, original_rt, NULL, readback, NULL, D3DTEXF_POINT);
14823 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
14825 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
14827 D3DCOLOR color = getPixelColorFromSurface(readback, expected_colors[i].x, expected_colors[i].y);
14828 ok(color_match(color, expected_colors[i].color, 1),
14829 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
14830 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
14833 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
14834 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
14836 IDirect3DSurface9_Release(ds);
14837 IDirect3DSurface9_Release(readback);
14838 IDirect3DSurface9_Release(rt);
14839 IDirect3DSurface9_Release(original_rt);
14840 cleanup_device(device);
14842 ZeroMemory(&present_parameters, sizeof(present_parameters));
14843 present_parameters.Windowed = TRUE;
14844 present_parameters.hDeviceWindow = create_window();
14845 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
14846 present_parameters.BackBufferWidth = 640;
14847 present_parameters.BackBufferHeight = 480;
14848 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
14849 present_parameters.EnableAutoDepthStencil = TRUE;
14850 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
14851 present_parameters.MultiSampleType = D3DMULTISAMPLE_NONE;
14853 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
14854 present_parameters.hDeviceWindow, D3DCREATE_HARDWARE_VERTEXPROCESSING,
14855 &present_parameters, &device);
14856 ok(hr == D3D_OK, "Failed to create a device, hr %#x.\n", hr);
14858 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ffff, 1.0f, 0);
14859 ok(SUCCEEDED(hr), "Failed to clear depth buffer, hr %#x.\n", hr);
14861 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
14862 D3DMULTISAMPLE_2_SAMPLES, 0, FALSE, &rt, NULL);
14863 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
14864 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
14865 D3DMULTISAMPLE_NONE, 0, TRUE, &readback, NULL);
14866 ok(SUCCEEDED(hr), "Failed to create readback surface, hr %#x.\n", hr);
14867 hr = IDirect3DDevice9_CreateDepthStencilSurface(device, 640, 480, D3DFMT_D24S8,
14868 D3DMULTISAMPLE_2_SAMPLES, 0, FALSE, &ds, NULL);
14869 ok(SUCCEEDED(hr), "CreateDepthStencilSurface failed, hr %#x.\n", hr);
14871 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &original_rt);
14872 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
14873 hr = IDirect3DDevice9_GetDepthStencilSurface(device, &original_ds);
14874 ok(SUCCEEDED(hr), "Failed to get depth/stencil, hr %#x.\n", hr);
14875 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
14876 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
14877 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
14878 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
14880 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
14881 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14882 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
14883 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14884 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
14885 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14886 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
14887 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
14888 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
14889 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
14891 /* Render to a multisampled offscreen frame buffer and then blit to
14892 * the onscreen (not multisampled) frame buffer. */
14893 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 1.0f, 0);
14894 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
14896 hr = IDirect3DDevice9_BeginScene(device);
14897 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
14898 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad_1, sizeof(*quad_1));
14899 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
14900 hr = IDirect3DDevice9_EndScene(device);
14901 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
14903 hr = IDirect3DDevice9_StretchRect(device, rt, NULL, original_rt, NULL, D3DTEXF_POINT);
14904 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
14905 hr = IDirect3DDevice9_StretchRect(device, ds, NULL, original_ds, NULL, D3DTEXF_POINT);
14906 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
14908 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
14909 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
14910 hr = IDirect3DDevice9_SetDepthStencilSurface(device, original_ds);
14911 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
14913 hr = IDirect3DDevice9_BeginScene(device);
14914 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
14915 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad_2, sizeof(*quad_2));
14916 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
14917 hr = IDirect3DDevice9_EndScene(device);
14918 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
14920 hr = IDirect3DDevice9_StretchRect(device, original_rt, NULL, readback, NULL, D3DTEXF_POINT);
14921 ok(SUCCEEDED(hr), "StretchRect failed, hr %#x.\n", hr);
14923 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
14925 D3DCOLOR color = getPixelColorFromSurface(readback, expected_colors[i].x, expected_colors[i].y);
14926 ok(color_match(color, expected_colors[i].color, 1),
14927 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
14928 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
14931 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
14932 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
14934 hr = IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
14935 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
14936 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
14937 ok(SUCCEEDED(hr), "Failed to restore original render target, hr %#x.\n", hr);
14939 IDirect3DSurface9_Release(original_ds);
14940 IDirect3DSurface9_Release(original_rt);
14941 IDirect3DSurface9_Release(ds);
14942 IDirect3DSurface9_Release(readback);
14943 IDirect3DSurface9_Release(rt);
14944 cleanup:
14945 cleanup_device(device);
14946 IDirect3D9_Release(d3d);
14949 static void resz_test(void)
14951 IDirect3DDevice9 *device = 0;
14952 IDirect3DSurface9 *rt, *original_rt, *ds, *readback, *intz_ds;
14953 D3DCAPS9 caps;
14954 HRESULT hr;
14955 D3DPRESENT_PARAMETERS present_parameters;
14956 unsigned int i;
14957 static const DWORD ps_code[] =
14959 0xffff0200, /* ps_2_0 */
14960 0x0200001f, 0x90000000, 0xa00f0800, /* dcl_2d s0 */
14961 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
14962 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0.0, 0.0, 0.0, 1.0 */
14963 0x02000001, 0x800f0001, 0xa0e40000, /* mov r1, c0 */
14964 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texld r0, t0, s0 */
14965 0x02000001, 0x80010001, 0x80e40000, /* mov r1.x, r0 */
14966 0x03010042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texldp r0, t0, s0 */
14967 0x02000001, 0x80020001, 0x80000000, /* mov r1.y, r0.x */
14968 0x02000001, 0x800f0800, 0x80e40001, /* mov oC0, r1 */
14969 0x0000ffff, /* end */
14971 struct
14973 float x, y, z;
14974 float s, t, p, q;
14976 quad[] =
14978 { -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.5f},
14979 { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.5f},
14980 { -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f},
14981 { 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.5f},
14983 struct
14985 UINT x, y;
14986 D3DCOLOR color;
14988 expected_colors[] =
14990 { 80, 100, D3DCOLOR_ARGB(0x00, 0x20, 0x40, 0x00)},
14991 {240, 100, D3DCOLOR_ARGB(0x00, 0x60, 0xbf, 0x00)},
14992 {400, 100, D3DCOLOR_ARGB(0x00, 0x9f, 0x40, 0x00)},
14993 {560, 100, D3DCOLOR_ARGB(0x00, 0xdf, 0xbf, 0x00)},
14994 { 80, 450, D3DCOLOR_ARGB(0x00, 0x20, 0x40, 0x00)},
14995 {240, 450, D3DCOLOR_ARGB(0x00, 0x60, 0xbf, 0x00)},
14996 {400, 450, D3DCOLOR_ARGB(0x00, 0x9f, 0x40, 0x00)},
14997 {560, 450, D3DCOLOR_ARGB(0x00, 0xdf, 0xbf, 0x00)},
14999 IDirect3DTexture9 *texture;
15000 IDirect3DPixelShader9 *ps;
15001 IDirect3D9 *d3d;
15002 DWORD value;
15004 d3d = Direct3DCreate9(D3D_SDK_VERSION);
15005 ok(!!d3d, "Failed to create a D3D object.\n");
15007 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT,
15008 D3DDEVTYPE_HAL, D3DFMT_A8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES, NULL)))
15010 skip("Multisampling not supported for D3DFMT_A8R8G8B8, skipping RESZ test.\n");
15011 IDirect3D9_Release(d3d);
15012 return;
15014 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT,
15015 D3DDEVTYPE_HAL, D3DFMT_D24S8, TRUE, D3DMULTISAMPLE_2_SAMPLES, NULL)))
15017 skip("Multisampling not supported for D3DFMT_D24S8, skipping RESZ test.\n");
15018 IDirect3D9_Release(d3d);
15019 return;
15022 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
15023 D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, MAKEFOURCC('I','N','T','Z'))))
15025 skip("No INTZ support, skipping RESZ test.\n");
15026 IDirect3D9_Release(d3d);
15027 return;
15030 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
15031 D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, MAKEFOURCC('R','E','S','Z'))))
15033 skip("No RESZ support, skipping RESZ test.\n");
15034 IDirect3D9_Release(d3d);
15035 return;
15038 ZeroMemory(&present_parameters, sizeof(present_parameters));
15039 present_parameters.Windowed = TRUE;
15040 present_parameters.hDeviceWindow = create_window();
15041 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
15042 present_parameters.BackBufferWidth = 640;
15043 present_parameters.BackBufferHeight = 480;
15044 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
15045 present_parameters.EnableAutoDepthStencil = FALSE;
15046 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
15047 present_parameters.MultiSampleType = D3DMULTISAMPLE_NONE;
15049 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
15050 present_parameters.hDeviceWindow, D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device);
15051 ok(hr == D3D_OK, "Failed to create a device, hr %#x.\n", hr);
15053 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
15054 ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
15055 if (caps.PixelShaderVersion < D3DPS_VERSION(2, 0))
15057 skip("No pixel shader 2.0 support, skipping INTZ test.\n");
15058 cleanup_device(device);
15059 IDirect3D9_Release(d3d);
15060 return;
15062 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
15064 skip("No unconditional NP2 texture support, skipping INTZ test.\n");
15065 cleanup_device(device);
15066 IDirect3D9_Release(d3d);
15067 return;
15070 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &original_rt);
15071 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
15073 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
15074 D3DMULTISAMPLE_2_SAMPLES, 0, FALSE, &rt, NULL);
15075 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
15076 hr = IDirect3DDevice9_CreateDepthStencilSurface(device, 640, 480, D3DFMT_D24S8,
15077 D3DMULTISAMPLE_2_SAMPLES, 0, TRUE, &ds, NULL);
15078 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
15079 D3DMULTISAMPLE_NONE, 0, TRUE, &readback, NULL);
15080 ok(SUCCEEDED(hr), "Failed to create readback surface, hr %#x.\n", hr);
15082 hr = IDirect3DDevice9_CreateTexture(device, 640, 480, 1,
15083 D3DUSAGE_DEPTHSTENCIL, MAKEFOURCC('I','N','T','Z'), D3DPOOL_DEFAULT, &texture, NULL);
15084 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
15085 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &intz_ds);
15086 ok(SUCCEEDED(hr), "GetSurfaceLevel failed, hr %#x.\n", hr);
15087 hr = IDirect3DDevice9_SetDepthStencilSurface(device, intz_ds);
15088 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
15089 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 1.0f, 0);
15090 ok(SUCCEEDED(hr), "Failed to clear depth/stencil, hr %#x.\n", hr);
15091 IDirect3DSurface9_Release(intz_ds);
15092 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code, &ps);
15093 ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
15095 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE4(0));
15096 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
15097 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
15098 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15099 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_ALWAYS);
15100 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15101 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
15102 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15103 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
15104 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15106 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
15107 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
15108 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
15109 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
15110 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
15111 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
15112 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
15113 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
15114 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
15115 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
15117 /* Render offscreen (multisampled), blit the depth buffer
15118 * into the INTZ texture and then check its contents */
15119 hr = IDirect3DDevice9_SetRenderTarget(device, 0, rt);
15120 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
15121 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
15122 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
15123 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 1.0f, 0);
15124 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
15126 hr = IDirect3DDevice9_BeginScene(device);
15127 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
15128 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
15129 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
15131 /* The destination depth texture has to be bound to sampler 0 */
15132 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
15133 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
15135 /* the ATI "spec" says you have to do a dummy draw to ensure correct commands ordering */
15136 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
15137 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15138 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
15139 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15140 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_COLORWRITEENABLE, 0);
15141 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15142 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
15143 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
15144 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, TRUE);
15145 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15146 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
15147 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15148 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_COLORWRITEENABLE, 0xf);
15149 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15151 /* The actual multisampled depth buffer resolve happens here */
15152 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, 0x7fa05000);
15153 ok(SUCCEEDED(hr), "SetRenderState (multisampled depth buffer resolve) failed, hr %#x.\n", hr);
15154 hr = IDirect3DDevice9_GetRenderState(device, D3DRS_POINTSIZE, &value);
15155 ok(SUCCEEDED(hr) && value == 0x7fa05000, "GetRenderState failed, hr %#x, value %#x.\n", hr, value);
15157 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
15158 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
15159 hr = IDirect3DDevice9_SetPixelShader(device, ps);
15160 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
15162 /* Read the depth values back */
15163 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
15164 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
15165 hr = IDirect3DDevice9_EndScene(device);
15166 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
15168 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
15170 D3DCOLOR color = getPixelColor(device, expected_colors[i].x, expected_colors[i].y);
15171 ok(color_match(color, expected_colors[i].color, 1),
15172 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
15173 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
15176 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
15177 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
15179 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
15180 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
15181 hr = IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
15182 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
15183 IDirect3DSurface9_Release(ds);
15184 hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
15185 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
15186 IDirect3DTexture9_Release(texture);
15187 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
15188 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
15189 IDirect3DPixelShader9_Release(ps);
15190 IDirect3DSurface9_Release(readback);
15191 IDirect3DSurface9_Release(original_rt);
15192 IDirect3DSurface9_Release(rt);
15193 cleanup_device(device);
15196 ZeroMemory(&present_parameters, sizeof(present_parameters));
15197 present_parameters.Windowed = TRUE;
15198 present_parameters.hDeviceWindow = create_window();
15199 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
15200 present_parameters.BackBufferWidth = 640;
15201 present_parameters.BackBufferHeight = 480;
15202 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
15203 present_parameters.EnableAutoDepthStencil = TRUE;
15204 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
15205 present_parameters.MultiSampleType = D3DMULTISAMPLE_2_SAMPLES;
15207 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
15208 present_parameters.hDeviceWindow, D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device);
15209 ok(hr == D3D_OK, "Failed to create a device, hr %#x.\n", hr);
15211 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &original_rt);
15212 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
15213 hr = IDirect3DDevice9_GetDepthStencilSurface(device, &ds);
15214 ok(SUCCEEDED(hr), "Failed to get depth/stencil, hr %#x.\n", hr);
15215 hr = IDirect3DDevice9_CreateRenderTarget(device, 640, 480, D3DFMT_A8R8G8B8,
15216 D3DMULTISAMPLE_NONE, 0, TRUE, &readback, NULL);
15217 ok(SUCCEEDED(hr), "Failed to create readback surface, hr %#x.\n", hr);
15218 hr = IDirect3DDevice9_CreateTexture(device, 640, 480, 1,
15219 D3DUSAGE_DEPTHSTENCIL, MAKEFOURCC('I','N','T','Z'), D3DPOOL_DEFAULT, &texture, NULL);
15220 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
15221 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &intz_ds);
15222 ok(SUCCEEDED(hr), "GetSurfaceLevel failed, hr %#x.\n", hr);
15223 hr = IDirect3DDevice9_SetRenderTarget(device, 0, readback);
15224 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
15225 hr = IDirect3DDevice9_SetDepthStencilSurface(device, intz_ds);
15226 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
15227 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 1.0f, 0);
15228 ok(SUCCEEDED(hr), "Failed to clear depth/stencil, hr %#x.\n", hr);
15229 IDirect3DSurface9_Release(intz_ds);
15230 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code, &ps);
15231 ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
15233 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE4(0));
15234 ok(SUCCEEDED(hr), "SetFVF failed, hr %#x.\n", hr);
15235 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
15236 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15237 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_ALWAYS);
15238 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15239 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
15240 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15241 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
15242 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15244 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
15245 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
15246 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
15247 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
15248 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
15249 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
15250 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
15251 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
15252 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
15253 ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
15255 /* Render onscreen, blit the depth buffer into the INTZ texture
15256 * and then check its contents */
15257 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
15258 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
15259 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
15260 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
15261 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 1.0f, 0);
15262 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
15264 hr = IDirect3DDevice9_BeginScene(device);
15265 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
15266 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
15267 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
15268 hr = IDirect3DDevice9_EndScene(device);
15269 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
15271 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
15272 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
15274 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
15275 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15276 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
15277 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15278 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_COLORWRITEENABLE, 0);
15279 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15280 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
15281 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
15282 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, TRUE);
15283 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15284 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
15285 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15286 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_COLORWRITEENABLE, 0xf);
15287 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15289 /* The actual multisampled depth buffer resolve happens here */
15290 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, 0x7fa05000);
15291 ok(SUCCEEDED(hr), "SetRenderState (multisampled depth buffer resolve) failed, hr %#x.\n", hr);
15292 hr = IDirect3DDevice9_GetRenderState(device, D3DRS_POINTSIZE, &value);
15293 ok(SUCCEEDED(hr) && value == 0x7fa05000, "GetRenderState failed, hr %#x, value %#x.\n", hr, value);
15295 hr = IDirect3DDevice9_SetRenderTarget(device, 0, readback);
15296 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
15297 hr = IDirect3DDevice9_SetPixelShader(device, ps);
15298 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
15300 /* Read the depth values back */
15301 hr = IDirect3DDevice9_BeginScene(device);
15302 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
15303 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
15304 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
15305 hr = IDirect3DDevice9_EndScene(device);
15306 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
15308 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
15310 D3DCOLOR color = getPixelColor(device, expected_colors[i].x, expected_colors[i].y);
15311 ok(color_match(color, expected_colors[i].color, 1),
15312 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
15313 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
15316 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
15317 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
15320 /* Test edge cases - try with no texture at all */
15321 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
15322 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
15323 hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
15324 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
15326 hr = IDirect3DDevice9_BeginScene(device);
15327 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
15328 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
15329 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
15330 hr = IDirect3DDevice9_EndScene(device);
15331 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
15333 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, 0x7fa05000);
15334 ok(SUCCEEDED(hr), "SetRenderState (multisampled depth buffer resolve) failed, hr %#x.\n", hr);
15336 /* With a non-multisampled depth buffer */
15337 IDirect3DSurface9_Release(ds);
15338 hr = IDirect3DDevice9_CreateDepthStencilSurface(device, 640, 480, D3DFMT_D24S8,
15339 D3DMULTISAMPLE_NONE, 0, TRUE, &ds, NULL);
15341 hr = IDirect3DDevice9_SetRenderTarget(device, 0, readback);
15342 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
15343 hr = IDirect3DDevice9_SetDepthStencilSurface(device, ds);
15344 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
15345 hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
15346 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
15348 hr = IDirect3DDevice9_BeginScene(device);
15349 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
15350 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
15351 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
15353 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
15354 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
15356 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
15357 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15358 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, FALSE);
15359 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15360 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_COLORWRITEENABLE, 0);
15361 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15362 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
15363 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
15364 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, TRUE);
15365 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15366 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
15367 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15368 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_COLORWRITEENABLE, 0xf);
15369 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
15370 hr = IDirect3DDevice9_EndScene(device);
15371 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
15373 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, 0x7fa05000);
15374 ok(SUCCEEDED(hr), "SetRenderState (multisampled depth buffer resolve) failed, hr %#x.\n", hr);
15376 hr = IDirect3DDevice9_SetPixelShader(device, ps);
15377 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
15379 /* Read the depth values back. */
15380 hr = IDirect3DDevice9_BeginScene(device);
15381 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
15382 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
15383 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
15384 hr = IDirect3DDevice9_EndScene(device);
15385 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
15387 for (i = 0; i < sizeof(expected_colors) / sizeof(*expected_colors); ++i)
15389 D3DCOLOR color = getPixelColor(device, expected_colors[i].x, expected_colors[i].y);
15390 ok(color_match(color, expected_colors[i].color, 1),
15391 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
15392 expected_colors[i].color, expected_colors[i].x, expected_colors[i].y, color);
15395 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
15396 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
15398 /* Without a current depth-stencil buffer set */
15399 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
15400 ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
15401 hr = IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
15402 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
15404 hr = IDirect3DDevice9_BeginScene(device);
15405 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
15406 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
15407 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
15408 hr = IDirect3DDevice9_EndScene(device);
15409 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
15411 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_POINTSIZE, 0x7fa05000);
15412 ok(SUCCEEDED(hr), "SetRenderState (multisampled depth buffer resolve) failed, hr %#x.\n", hr);
15414 hr = IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
15415 ok(SUCCEEDED(hr), "Failed to set depth/stencil, hr %#x.\n", hr);
15416 IDirect3DSurface9_Release(ds);
15417 hr = IDirect3DDevice9_SetRenderTarget(device, 0, original_rt);
15418 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
15419 hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
15420 ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
15421 IDirect3DTexture9_Release(texture);
15422 IDirect3DPixelShader9_Release(ps);
15423 IDirect3DSurface9_Release(readback);
15424 IDirect3DSurface9_Release(original_rt);
15425 cleanup_device(device);
15426 IDirect3D9_Release(d3d);
15429 static void zenable_test(void)
15431 static const struct
15433 struct vec4 position;
15434 D3DCOLOR diffuse;
15436 tquad[] =
15438 {{ 0.0f, 480.0f, -0.5f, 1.0f}, 0xff00ff00},
15439 {{ 0.0f, 0.0f, -0.5f, 1.0f}, 0xff00ff00},
15440 {{640.0f, 480.0f, 1.5f, 1.0f}, 0xff00ff00},
15441 {{640.0f, 0.0f, 1.5f, 1.0f}, 0xff00ff00},
15443 IDirect3DDevice9 *device;
15444 IDirect3D9 *d3d;
15445 D3DCOLOR color;
15446 ULONG refcount;
15447 D3DCAPS9 caps;
15448 HWND window;
15449 HRESULT hr;
15450 UINT x, y;
15451 UINT i, j;
15453 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
15454 0, 0, 640, 480, NULL, NULL, NULL, NULL);
15455 d3d = Direct3DCreate9(D3D_SDK_VERSION);
15456 ok(!!d3d, "Failed to create a D3D object.\n");
15457 if (!(device = create_device(d3d, window, window, TRUE)))
15459 skip("Failed to create a D3D device, skipping tests.\n");
15460 goto done;
15463 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
15464 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
15465 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
15466 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
15468 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 0.0f, 0);
15469 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
15470 hr = IDirect3DDevice9_BeginScene(device);
15471 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
15472 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, tquad, sizeof(*tquad));
15473 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
15474 hr = IDirect3DDevice9_EndScene(device);
15475 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
15477 for (i = 0; i < 4; ++i)
15479 for (j = 0; j < 4; ++j)
15481 x = 80 * ((2 * j) + 1);
15482 y = 60 * ((2 * i) + 1);
15483 color = getPixelColor(device, x, y);
15484 ok(color_match(color, 0x0000ff00, 1),
15485 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x, y, color);
15489 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
15490 ok(SUCCEEDED(hr), "Failed to present backbuffer, hr %#x.\n", hr);
15492 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
15493 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
15495 if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 1)
15496 && caps.VertexShaderVersion >= D3DVS_VERSION(1, 1))
15498 static const DWORD vs_code[] =
15500 0xfffe0101, /* vs_1_1 */
15501 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
15502 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
15503 0x00000001, 0xd00f0000, 0x90e40000, /* mov oD0, v0 */
15504 0x0000ffff
15506 static const DWORD ps_code[] =
15508 0xffff0101, /* ps_1_1 */
15509 0x00000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
15510 0x0000ffff /* end */
15512 static const struct vec3 quad[] =
15514 {-1.0f, -1.0f, -0.5f},
15515 {-1.0f, 1.0f, -0.5f},
15516 { 1.0f, -1.0f, 1.5f},
15517 { 1.0f, 1.0f, 1.5f},
15519 static const D3DCOLOR expected[] =
15521 0x00ff0000, 0x0060df60, 0x009fdf9f, 0x00ff0000,
15522 0x00ff0000, 0x00609f60, 0x009f9f9f, 0x00ff0000,
15523 0x00ff0000, 0x00606060, 0x009f609f, 0x00ff0000,
15524 0x00ff0000, 0x00602060, 0x009f209f, 0x00ff0000,
15526 /* The Windows 8 testbot (WARP) appears to not clip z for regular
15527 * vertices either. */
15528 static const D3DCOLOR expected_broken[] =
15530 0x0020df20, 0x0060df60, 0x009fdf9f, 0x00dfdfdf,
15531 0x00209f20, 0x00609f60, 0x009f9f9f, 0x00df9fdf,
15532 0x00206020, 0x00606060, 0x009f609f, 0x00df60df,
15533 0x00202020, 0x00602060, 0x009f209f, 0x00df20df,
15536 IDirect3DVertexShader9 *vs;
15537 IDirect3DPixelShader9 *ps;
15539 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
15540 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
15541 hr = IDirect3DDevice9_CreateVertexShader(device, vs_code, &vs);
15542 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
15543 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code, &ps);
15544 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15545 hr = IDirect3DDevice9_SetVertexShader(device, vs);
15546 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
15547 hr = IDirect3DDevice9_SetPixelShader(device, ps);
15548 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
15550 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 0.0f, 0);
15551 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
15552 hr = IDirect3DDevice9_BeginScene(device);
15553 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
15554 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
15555 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
15556 hr = IDirect3DDevice9_EndScene(device);
15557 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
15559 for (i = 0; i < 4; ++i)
15561 for (j = 0; j < 4; ++j)
15563 x = 80 * ((2 * j) + 1);
15564 y = 60 * ((2 * i) + 1);
15565 color = getPixelColor(device, x, y);
15566 ok(color_match(color, expected[i * 4 + j], 1)
15567 || broken(color_match(color, expected_broken[i * 4 + j], 1)),
15568 "Expected color 0x%08x at %u, %u, got 0x%08x.\n", expected[i * 4 + j], x, y, color);
15572 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
15573 ok(SUCCEEDED(hr), "Failed to present backbuffer, hr %#x.\n", hr);
15575 IDirect3DPixelShader9_Release(ps);
15576 IDirect3DVertexShader9_Release(vs);
15579 refcount = IDirect3DDevice9_Release(device);
15580 ok(!refcount, "Device has %u references left.\n", refcount);
15581 done:
15582 IDirect3D9_Release(d3d);
15583 DestroyWindow(window);
15586 static void fog_special_test(void)
15588 static const struct
15590 struct vec3 position;
15591 D3DCOLOR diffuse;
15593 quad[] =
15595 {{ -1.0f, -1.0f, 0.0f}, 0xff00ff00},
15596 {{ -1.0f, 1.0f, 0.0f}, 0xff00ff00},
15597 {{ 1.0f, -1.0f, 1.0f}, 0xff00ff00},
15598 {{ 1.0f, 1.0f, 1.0f}, 0xff00ff00}
15600 static const struct
15602 DWORD vertexmode, tablemode;
15603 BOOL vs, ps;
15604 D3DCOLOR color_left, color_right;
15606 tests[] =
15608 {D3DFOG_LINEAR, D3DFOG_NONE, FALSE, FALSE, 0x00ff0000, 0x00ff0000},
15609 {D3DFOG_LINEAR, D3DFOG_NONE, FALSE, TRUE, 0x00ff0000, 0x00ff0000},
15610 {D3DFOG_LINEAR, D3DFOG_NONE, TRUE, FALSE, 0x00ff0000, 0x00ff0000},
15611 {D3DFOG_LINEAR, D3DFOG_NONE, TRUE, TRUE, 0x00ff0000, 0x00ff0000},
15613 {D3DFOG_NONE, D3DFOG_LINEAR, FALSE, FALSE, 0x0000ff00, 0x00ff0000},
15614 {D3DFOG_NONE, D3DFOG_LINEAR, FALSE, TRUE, 0x0000ff00, 0x00ff0000},
15615 {D3DFOG_NONE, D3DFOG_LINEAR, TRUE, FALSE, 0x0000ff00, 0x00ff0000},
15616 {D3DFOG_NONE, D3DFOG_LINEAR, TRUE, TRUE, 0x0000ff00, 0x00ff0000},
15618 static const DWORD pixel_shader_code[] =
15620 0xffff0101, /* ps_1_1 */
15621 0x00000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
15622 0x0000ffff
15624 static const DWORD vertex_shader_code[] =
15626 0xfffe0101, /* vs_1_1 */
15627 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
15628 0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
15629 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
15630 0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
15631 0x0000ffff
15633 static const D3DMATRIX identity =
15635 1.0f, 0.0f, 0.0f, 0.0f,
15636 0.0f, 1.0f, 0.0f, 0.0f,
15637 0.0f, 0.0f, 1.0f, 0.0f,
15638 0.0f, 0.0f, 0.0f, 1.0f,
15639 }}};
15640 union
15642 float f;
15643 DWORD d;
15644 } conv;
15645 DWORD color;
15646 HRESULT hr;
15647 unsigned int i;
15648 IDirect3DPixelShader9 *ps;
15649 IDirect3DVertexShader9 *vs;
15650 IDirect3DDevice9 *device;
15651 IDirect3D9 *d3d;
15652 ULONG refcount;
15653 D3DCAPS9 caps;
15654 HWND window;
15656 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
15657 0, 0, 640, 480, NULL, NULL, NULL, NULL);
15658 d3d = Direct3DCreate9(D3D_SDK_VERSION);
15659 ok(!!d3d, "Failed to create a D3D object.\n");
15660 if (!(device = create_device(d3d, window, window, TRUE)))
15662 skip("Failed to create a D3D device, skipping tests.\n");
15663 goto done;
15666 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
15667 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
15668 if (caps.VertexShaderVersion >= D3DVS_VERSION(1, 1))
15670 hr = IDirect3DDevice9_CreateVertexShader(device, vertex_shader_code, &vs);
15671 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
15673 else
15675 skip("Vertex Shaders not supported, skipping some fog tests.\n");
15676 vs = NULL;
15678 if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 1))
15680 hr = IDirect3DDevice9_CreatePixelShader(device, pixel_shader_code, &ps);
15681 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15683 else
15685 skip("Pixel Shaders not supported, skipping some fog tests.\n");
15686 ps = NULL;
15689 /* The table fog tests seem to depend on the projection matrix explicitly
15690 * being set to an identity matrix, even though that's the default.
15691 * (AMD Radeon HD 6310, Windows 7) */
15692 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &identity);
15693 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
15695 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
15696 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
15697 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
15698 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
15699 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGENABLE, TRUE);
15700 ok(SUCCEEDED(hr), "Failed to enable fog, hr %#x.\n", hr);
15701 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGCOLOR, 0xffff0000);
15702 ok(SUCCEEDED(hr), "Failed to set fog color, hr %#x.\n", hr);
15704 conv.f = 0.5f;
15705 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGSTART, conv.d);
15706 ok(SUCCEEDED(hr), "Failed to set fog start, hr %#x.\n", hr);
15707 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGEND, conv.d);
15708 ok(SUCCEEDED(hr), "Failed to set fog end, hr %#x.\n", hr);
15710 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
15712 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
15713 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
15715 if (!tests[i].vs)
15717 hr = IDirect3DDevice9_SetVertexShader(device, NULL);
15718 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
15720 else if (vs)
15722 hr = IDirect3DDevice9_SetVertexShader(device, vs);
15723 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
15725 else
15727 continue;
15730 if (!tests[i].ps)
15732 hr = IDirect3DDevice9_SetPixelShader(device, NULL);
15733 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
15735 else if (ps)
15737 hr = IDirect3DDevice9_SetPixelShader(device, ps);
15738 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
15740 else
15742 continue;
15745 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGVERTEXMODE, tests[i].vertexmode);
15746 ok(SUCCEEDED(hr), "Failed to set fogvertexmode, hr %#x.\n", hr);
15747 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, tests[i].tablemode);
15748 ok(SUCCEEDED(hr), "Failed to set fogtablemode, hr %#x.\n", hr);
15750 hr = IDirect3DDevice9_BeginScene(device);
15751 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
15752 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
15753 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
15754 hr = IDirect3DDevice9_EndScene(device);
15755 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
15757 color = getPixelColor(device, 310, 240);
15758 ok(color_match(color, tests[i].color_left, 1),
15759 "Expected left color 0x%08x, got 0x%08x, case %u.\n", tests[i].color_left, color, i);
15760 color = getPixelColor(device, 330, 240);
15761 ok(color_match(color, tests[i].color_right, 1),
15762 "Expected right color 0x%08x, got 0x%08x, case %u.\n", tests[i].color_right, color, i);
15764 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
15765 ok(SUCCEEDED(hr), "Failed to present backbuffer, hr %#x.\n", hr);
15768 if (vs)
15769 IDirect3DVertexShader9_Release(vs);
15770 if (ps)
15771 IDirect3DPixelShader9_Release(ps);
15772 refcount = IDirect3DDevice9_Release(device);
15773 ok(!refcount, "Device has %u references left.\n", refcount);
15774 done:
15775 IDirect3D9_Release(d3d);
15776 DestroyWindow(window);
15779 static void volume_srgb_test(void)
15781 HRESULT hr;
15782 unsigned int i, j;
15783 IDirect3DVolumeTexture9 *tex1, *tex2;
15784 D3DPOOL pool;
15785 D3DLOCKED_BOX locked_box;
15786 IDirect3DDevice9 *device;
15787 IDirect3D9 *d3d;
15788 D3DCOLOR color;
15789 ULONG refcount;
15790 HWND window;
15792 static const struct
15794 BOOL srgb;
15795 DWORD color;
15797 tests[] =
15799 /* Try toggling on and off */
15800 { FALSE, 0x007f7f7f },
15801 { TRUE, 0x00363636 },
15802 { FALSE, 0x007f7f7f },
15804 static const struct
15806 struct vec3 pos;
15807 struct vec3 texcrd;
15809 quad[] =
15811 {{-1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, 0.0f}},
15812 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0f}},
15813 {{ 1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, 0.0f}},
15814 {{ 1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0f}},
15817 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
15818 0, 0, 640, 480, NULL, NULL, NULL, NULL);
15819 d3d = Direct3DCreate9(D3D_SDK_VERSION);
15820 ok(!!d3d, "Failed to create a D3D object.\n");
15821 if (IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
15822 D3DUSAGE_QUERY_SRGBREAD, D3DRTYPE_VOLUMETEXTURE, D3DFMT_A8R8G8B8) != D3D_OK)
15824 skip("D3DFMT_A8R8G8B8 volume textures with SRGBREAD not supported.\n");
15825 goto done;
15827 if (!(device = create_device(d3d, window, window, TRUE)))
15829 skip("Failed to create a D3D device, skipping tests.\n");
15830 goto done;
15833 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
15834 ok(SUCCEEDED(hr), "Failed to set color op 0, hr %#x.\n", hr);
15835 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
15836 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
15837 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
15838 ok(SUCCEEDED(hr), "Failed to set color op 0, hr %#x.\n", hr);
15839 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE3(0));
15840 ok(SUCCEEDED(hr), "Failed to set fvf, hr %#x.\n", hr);
15842 for (i = 0; i < 2; i++)
15844 if (!i)
15845 pool = D3DPOOL_SYSTEMMEM;
15846 else
15847 pool = D3DPOOL_MANAGED;
15849 hr = IDirect3DDevice9_CreateVolumeTexture(device, 1, 1, 1, 1, 0, D3DFMT_A8R8G8B8, pool, &tex1, NULL);
15850 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
15851 hr = IDirect3DVolumeTexture9_LockBox(tex1, 0, &locked_box, NULL, 0);
15852 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
15853 *((DWORD *)locked_box.pBits) = 0x7f7f7f7f;
15854 hr = IDirect3DVolumeTexture9_UnlockBox(tex1, 0);
15855 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
15857 if (!i)
15859 hr = IDirect3DDevice9_CreateVolumeTexture(device, 1, 1, 1, 1, 0,
15860 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex2, NULL);
15861 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
15862 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex1, (IDirect3DBaseTexture9 *)tex2);
15863 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
15864 IDirect3DVolumeTexture9_Release(tex1);
15866 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)tex2);
15867 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
15868 IDirect3DVolumeTexture9_Release(tex2);
15870 else
15872 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)tex1);
15873 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
15874 IDirect3DVolumeTexture9_Release(tex1);
15877 for (j = 0; j < sizeof(tests) / sizeof(*tests); j++)
15879 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_SRGBTEXTURE, tests[j].srgb);
15880 ok(SUCCEEDED(hr), "Failed to set srgb state, hr %#x.\n", hr);
15882 hr = IDirect3DDevice9_BeginScene(device);
15883 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
15884 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
15885 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
15886 hr = IDirect3DDevice9_EndScene(device);
15887 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
15889 color = getPixelColor(device, 320, 240);
15890 ok(color_match(color, tests[j].color, 2),
15891 "Expected color 0x%08x, got 0x%08x, i = %u, j = %u.\n", tests[j].color, color, i, j);
15893 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
15894 ok(SUCCEEDED(hr), "Failed to present backbuffer, hr %#x.\n", hr);
15898 refcount = IDirect3DDevice9_Release(device);
15899 ok(!refcount, "Device has %u references left.\n", refcount);
15900 done:
15901 IDirect3D9_Release(d3d);
15902 DestroyWindow(window);
15905 static void volume_dxt5_test(void)
15907 IDirect3DVolumeTexture9 *texture;
15908 IDirect3DDevice9 *device;
15909 D3DLOCKED_BOX box;
15910 IDirect3D9 *d3d;
15911 unsigned int i;
15912 ULONG refcount;
15913 DWORD color;
15914 HWND window;
15915 HRESULT hr;
15917 static const char texture_data[] =
15919 /* A 8x4x2 texture consisting of 4 4x4 blocks. The colors of the blocks are red, green, blue and white. */
15920 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
15921 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
15922 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
15923 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
15925 static const struct
15927 struct vec3 position;
15928 struct vec3 texcrd;
15930 quads[] =
15932 {{ -1.0f, -1.0f, 0.0f}, { 0.0f, 0.0f, 0.25f}},
15933 {{ -1.0f, 1.0f, 0.0f}, { 0.0f, 1.0f, 0.25f}},
15934 {{ 0.0f, -1.0f, 1.0f}, { 1.0f, 0.0f, 0.25f}},
15935 {{ 0.0f, 1.0f, 1.0f}, { 1.0f, 1.0f, 0.25f}},
15937 {{ 0.0f, -1.0f, 0.0f}, { 0.0f, 0.0f, 0.75f}},
15938 {{ 0.0f, 1.0f, 0.0f}, { 0.0f, 1.0f, 0.75f}},
15939 {{ 1.0f, -1.0f, 1.0f}, { 1.0f, 0.0f, 0.75f}},
15940 {{ 1.0f, 1.0f, 1.0f}, { 1.0f, 1.0f, 0.75f}},
15942 static const DWORD expected_colors[] = {0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff};
15944 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
15945 0, 0, 640, 480, NULL, NULL, NULL, NULL);
15946 d3d = Direct3DCreate9(D3D_SDK_VERSION);
15947 ok(!!d3d, "Failed to create a D3D object.\n");
15948 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
15949 D3DFMT_X8R8G8B8, 0, D3DRTYPE_VOLUMETEXTURE, D3DFMT_DXT5)))
15951 skip("DXT5 volume textures are not supported, skipping test.\n");
15952 goto done;
15954 if (!(device = create_device(d3d, window, window, TRUE)))
15956 skip("Failed to create a D3D device, skipping tests.\n");
15957 goto done;
15960 hr = IDirect3DDevice9_CreateVolumeTexture(device, 8, 4, 2, 1, 0, D3DFMT_DXT5,
15961 D3DPOOL_MANAGED, &texture, NULL);
15962 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
15964 hr = IDirect3DVolumeTexture9_LockBox(texture, 0, &box, NULL, 0);
15965 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
15966 memcpy(box.pBits, texture_data, sizeof(texture_data));
15967 hr = IDirect3DVolumeTexture9_UnlockBox(texture, 0);
15968 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
15970 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE3(0));
15971 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
15972 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
15973 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
15974 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
15975 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
15976 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
15977 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
15978 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
15979 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
15980 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
15981 ok(SUCCEEDED(hr), "Failed to set mag filter, hr %#x.\n", hr);
15983 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff00ff, 1.0f, 0);
15984 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
15985 hr = IDirect3DDevice9_BeginScene(device);
15986 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
15987 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[0], sizeof(*quads));
15988 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
15989 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[4], sizeof(*quads));
15990 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
15991 hr = IDirect3DDevice9_EndScene(device);
15992 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
15994 for (i = 0; i < 4; i++)
15996 color = getPixelColor(device, 80 + 160 * i, 240);
15997 ok (color_match(color, expected_colors[i], 1),
15998 "Expected color 0x%08x, got 0x%08x, case %u.\n", expected_colors[i], color, i);
16001 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16002 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16003 IDirect3DVolumeTexture9_Release(texture);
16004 refcount = IDirect3DDevice9_Release(device);
16005 ok(!refcount, "Device has %u references left.\n", refcount);
16006 done:
16007 IDirect3D9_Release(d3d);
16008 DestroyWindow(window);
16011 static void volume_v16u16_test(void)
16013 IDirect3DVolumeTexture9 *texture;
16014 IDirect3DPixelShader9 *shader;
16015 IDirect3DDevice9 *device;
16016 D3DLOCKED_BOX box;
16017 IDirect3D9 *d3d;
16018 unsigned int i;
16019 ULONG refcount;
16020 D3DCAPS9 caps;
16021 SHORT *texel;
16022 DWORD color;
16023 HWND window;
16024 HRESULT hr;
16026 static const struct
16028 struct vec3 position;
16029 struct vec3 texcrd;
16031 quads[] =
16033 {{ -1.0f, -1.0f, 0.0f}, { 0.0f, 0.0f, 0.25f}},
16034 {{ -1.0f, 1.0f, 0.0f}, { 0.0f, 1.0f, 0.25f}},
16035 {{ 0.0f, -1.0f, 1.0f}, { 1.0f, 0.0f, 0.25f}},
16036 {{ 0.0f, 1.0f, 1.0f}, { 1.0f, 1.0f, 0.25f}},
16038 {{ 0.0f, -1.0f, 0.0f}, { 0.0f, 0.0f, 0.75f}},
16039 {{ 0.0f, 1.0f, 0.0f}, { 0.0f, 1.0f, 0.75f}},
16040 {{ 1.0f, -1.0f, 1.0f}, { 1.0f, 0.0f, 0.75f}},
16041 {{ 1.0f, 1.0f, 1.0f}, { 1.0f, 1.0f, 0.75f}},
16043 static const DWORD shader_code[] =
16045 0xffff0101, /* ps_1_1 */
16046 0x00000051, 0xa00f0000, 0x3f000000, 0x3f000000, /* def c0, 0.5, 0.5, */
16047 0x3f000000, 0x3f000000, /* 0.5, 0.5 */
16048 0x00000042, 0xb00f0000, /* tex t0 */
16049 0x00000004, 0x800f0000, 0xb0e40000, 0xa0e40000, 0xa0e40000, /* mad r0, t0, c0, c0 */
16050 0x0000ffff /* end */
16053 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
16054 0, 0, 640, 480, NULL, NULL, NULL, NULL);
16055 d3d = Direct3DCreate9(D3D_SDK_VERSION);
16056 ok(!!d3d, "Failed to create a D3D object.\n");
16057 if (!(device = create_device(d3d, window, window, TRUE)))
16059 skip("Failed to create a D3D device, skipping tests.\n");
16060 goto done;
16063 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
16064 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
16065 if (caps.PixelShaderVersion < D3DPS_VERSION(1, 1))
16067 skip("No ps_1_1 support, skipping tests.\n");
16068 IDirect3DDevice9_Release(device);
16069 goto done;
16071 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
16072 D3DFMT_X8R8G8B8, 0, D3DRTYPE_VOLUMETEXTURE, D3DFMT_V16U16)))
16074 skip("Volume V16U16 textures are not supported, skipping test.\n");
16075 IDirect3DDevice9_Release(device);
16076 goto done;
16079 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE3(0));
16080 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
16081 hr = IDirect3DDevice9_CreatePixelShader(device, shader_code, &shader);
16082 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16083 hr = IDirect3DDevice9_SetPixelShader(device, shader);
16084 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
16085 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
16086 ok(SUCCEEDED(hr), "Failed to set filter, hr %#x.\n", hr);
16088 for (i = 0; i < 2; i++)
16090 D3DPOOL pool;
16092 if (i)
16093 pool = D3DPOOL_SYSTEMMEM;
16094 else
16095 pool = D3DPOOL_MANAGED;
16097 hr = IDirect3DDevice9_CreateVolumeTexture(device, 1, 2, 2, 1, 0, D3DFMT_V16U16,
16098 pool, &texture, NULL);
16099 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
16101 hr = IDirect3DVolumeTexture9_LockBox(texture, 0, &box, NULL, 0);
16102 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
16104 texel = (SHORT *)((BYTE *)box.pBits + 0 * box.RowPitch + 0 * box.SlicePitch);
16105 texel[0] = 32767;
16106 texel[1] = 32767;
16107 texel = (SHORT *)((BYTE *)box.pBits + 1 * box.RowPitch + 0 * box.SlicePitch);
16108 texel[0] = -32768;
16109 texel[1] = 0;
16110 texel = (SHORT *)((BYTE *)box.pBits + 0 * box.RowPitch + 1 * box.SlicePitch);
16111 texel[0] = -16384;
16112 texel[1] = 16384;
16113 texel = (SHORT *)((BYTE *)box.pBits + 1 * box.RowPitch + 1 * box.SlicePitch);
16114 texel[0] = 0;
16115 texel[1] = 0;
16117 hr = IDirect3DVolumeTexture9_UnlockBox(texture, 0);
16118 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
16120 if (i)
16122 IDirect3DVolumeTexture9 *texture2;
16124 hr = IDirect3DDevice9_CreateVolumeTexture(device, 1, 2, 2, 1, 0, D3DFMT_V16U16,
16125 D3DPOOL_DEFAULT, &texture2, NULL);
16126 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
16128 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)texture,
16129 (IDirect3DBaseTexture9 *)texture2);
16130 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
16132 IDirect3DVolumeTexture9_Release(texture);
16133 texture = texture2;
16136 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *) texture);
16137 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
16139 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff00ff, 1.0f, 0);
16140 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
16141 hr = IDirect3DDevice9_BeginScene(device);
16142 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
16143 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[0], sizeof(*quads));
16144 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
16145 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[4], sizeof(*quads));
16146 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
16147 hr = IDirect3DDevice9_EndScene(device);
16148 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
16150 color = getPixelColor(device, 120, 160);
16151 ok (color_match(color, 0x000080ff, 2),
16152 "Expected color 0x000080ff, got 0x%08x, V16U16 input -32768, 0.\n", color);
16153 color = getPixelColor(device, 120, 400);
16154 ok (color_match(color, 0x00ffffff, 2),
16155 "Expected color 0x00ffffff, got 0x%08x, V16U16 input 32767, 32767.\n", color);
16156 color = getPixelColor(device, 360, 160);
16157 ok (color_match(color, 0x007f7fff, 2),
16158 "Expected color 0x007f7fff, got 0x%08x, V16U16 input 0, 0.\n", color);
16159 color = getPixelColor(device, 360, 400);
16160 ok (color_match(color, 0x0040c0ff, 2),
16161 "Expected color 0x0040c0ff, got 0x%08x, V16U16 input -16384, 16384.\n", color);
16163 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16164 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16166 IDirect3DVolumeTexture9_Release(texture);
16169 IDirect3DPixelShader9_Release(shader);
16170 refcount = IDirect3DDevice9_Release(device);
16171 ok(!refcount, "Device has %u references left.\n", refcount);
16172 done:
16173 IDirect3D9_Release(d3d);
16174 DestroyWindow(window);
16177 static void add_dirty_rect_test_draw(IDirect3DDevice9 *device)
16179 HRESULT hr;
16180 static const struct
16182 struct vec3 position;
16183 struct vec2 texcoord;
16185 quad[] =
16187 {{-1.0, -1.0, 0.0}, {0.0, 0.0}},
16188 {{-1.0, 1.0, 0.0}, {0.0, 1.0}},
16189 {{ 1.0, -1.0, 0.0}, {1.0, 0.0}},
16190 {{ 1.0, 1.0, 0.0}, {1.0, 1.0}},
16193 hr = IDirect3DDevice9_BeginScene(device);
16194 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
16195 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad, sizeof(*quad));
16196 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
16197 hr = IDirect3DDevice9_EndScene(device);
16198 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
16201 static void add_dirty_rect_test(void)
16203 HRESULT hr;
16204 IDirect3DTexture9 *tex_dst1, *tex_dst2, *tex_src_red, *tex_src_green, *tex_managed;
16205 IDirect3DSurface9 *surface_dst2, *surface_src_green, *surface_src_red, *surface_managed;
16206 IDirect3DDevice9 *device;
16207 IDirect3D9 *d3d;
16208 unsigned int i;
16209 ULONG refcount;
16210 DWORD *texel;
16211 HWND window;
16212 D3DLOCKED_RECT locked_rect;
16213 static const RECT part_rect = {96, 96, 160, 160};
16214 DWORD color;
16216 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
16217 0, 0, 640, 480, NULL, NULL, NULL, NULL);
16218 d3d = Direct3DCreate9(D3D_SDK_VERSION);
16219 ok(!!d3d, "Failed to create a D3D object.\n");
16220 if (!(device = create_device(d3d, window, window, TRUE)))
16222 skip("Failed to create a D3D device, skipping tests.\n");
16223 IDirect3D9_Release(d3d);
16224 DestroyWindow(window);
16225 return;
16228 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 1, 0, D3DFMT_X8R8G8B8,
16229 D3DPOOL_DEFAULT, &tex_dst1, NULL);
16230 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16231 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 1, 0, D3DFMT_X8R8G8B8,
16232 D3DPOOL_DEFAULT, &tex_dst2, NULL);
16233 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16234 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 1, 0, D3DFMT_X8R8G8B8,
16235 D3DPOOL_SYSTEMMEM, &tex_src_red, NULL);
16236 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16237 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 1, 0, D3DFMT_X8R8G8B8,
16238 D3DPOOL_SYSTEMMEM, &tex_src_green, NULL);
16239 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16240 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 1, 0, D3DFMT_X8R8G8B8,
16241 D3DPOOL_MANAGED, &tex_managed, NULL);
16242 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16244 hr = IDirect3DTexture9_GetSurfaceLevel(tex_dst2, 0, &surface_dst2);
16245 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
16246 hr = IDirect3DTexture9_GetSurfaceLevel(tex_src_green, 0, &surface_src_green);
16247 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
16248 hr = IDirect3DTexture9_GetSurfaceLevel(tex_src_red, 0, &surface_src_red);
16249 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
16250 hr = IDirect3DTexture9_GetSurfaceLevel(tex_managed, 0, &surface_managed);
16251 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
16253 fill_surface(surface_src_red, 0x00ff0000, 0);
16254 fill_surface(surface_src_green, 0x0000ff00, 0);
16256 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
16257 ok(SUCCEEDED(hr), "Failed to set fvf, hr %#x.\n", hr);
16258 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
16259 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
16260 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
16261 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
16263 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
16264 (IDirect3DBaseTexture9 *)tex_dst1);
16265 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
16267 /* The second UpdateTexture call writing to tex_dst2 is ignored because tex_src_green is not dirty. */
16268 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_red,
16269 (IDirect3DBaseTexture9 *)tex_dst2);
16270 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
16271 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
16272 (IDirect3DBaseTexture9 *)tex_dst2);
16273 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
16275 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)tex_dst1);
16276 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
16277 add_dirty_rect_test_draw(device);
16278 color = getPixelColor(device, 320, 240);
16279 ok(color_match(color, 0x0000ff00, 1),
16280 "Expected color 0x0000ff00, got 0x%08x.\n", color);
16281 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16282 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16284 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)tex_dst2);
16285 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
16286 add_dirty_rect_test_draw(device);
16287 color = getPixelColor(device, 320, 240);
16288 todo_wine ok(color_match(color, 0x00ff0000, 1),
16289 "Expected color 0x00ff0000, got 0x%08x.\n", color);
16290 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16291 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16293 /* AddDirtyRect on the destination is ignored. */
16294 hr = IDirect3DTexture9_AddDirtyRect(tex_dst2, &part_rect);
16295 ok(SUCCEEDED(hr), "Failed to add dirty rect, hr %#x.\n", hr);
16296 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
16297 (IDirect3DBaseTexture9 *)tex_dst2);
16298 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
16299 add_dirty_rect_test_draw(device);
16300 color = getPixelColor(device, 320, 240);
16301 todo_wine ok(color_match(color, 0x00ff0000, 1),
16302 "Expected color 0x00ff0000, got 0x%08x.\n", color);
16303 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16304 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16306 hr = IDirect3DTexture9_AddDirtyRect(tex_dst2, NULL);
16307 ok(SUCCEEDED(hr), "Failed to add dirty rect, hr %#x.\n", hr);
16308 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
16309 (IDirect3DBaseTexture9 *)tex_dst2);
16310 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
16311 add_dirty_rect_test_draw(device);
16312 color = getPixelColor(device, 320, 240);
16313 todo_wine ok(color_match(color, 0x00ff0000, 1),
16314 "Expected color 0x00ff0000, got 0x%08x.\n", color);
16315 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16316 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16318 /* AddDirtyRect on the source makes UpdateTexture work. Partial rectangle
16319 * tracking is supported. */
16320 hr = IDirect3DTexture9_AddDirtyRect(tex_src_green, &part_rect);
16321 ok(SUCCEEDED(hr), "Failed to add dirty rect, hr %#x.\n", hr);
16322 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
16323 (IDirect3DBaseTexture9 *)tex_dst2);
16324 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
16325 add_dirty_rect_test_draw(device);
16326 color = getPixelColor(device, 320, 240);
16327 ok(color_match(color, 0x0000ff00, 1),
16328 "Expected color 0x0000ff00, got 0x%08x.\n", color);
16329 color = getPixelColor(device, 1, 1);
16330 todo_wine ok(color_match(color, 0x00ff0000, 1),
16331 "Expected color 0x00ff0000, got 0x%08x.\n", color);
16332 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16333 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16335 hr = IDirect3DTexture9_AddDirtyRect(tex_src_green, NULL);
16336 ok(SUCCEEDED(hr), "Failed to add dirty rect, hr %#x.\n", hr);
16337 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
16338 (IDirect3DBaseTexture9 *)tex_dst2);
16339 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
16340 add_dirty_rect_test_draw(device);
16341 color = getPixelColor(device, 1, 1);
16342 ok(color_match(color, 0x0000ff00, 1),
16343 "Expected color 0x0000ff00, got 0x%08x.\n", color);
16345 /* Locks with NO_DIRTY_UPDATE are ignored. */
16346 fill_surface(surface_src_green, 0x00000080, D3DLOCK_NO_DIRTY_UPDATE);
16347 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
16348 (IDirect3DBaseTexture9 *)tex_dst2);
16349 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
16350 add_dirty_rect_test_draw(device);
16351 color = getPixelColor(device, 320, 240);
16352 todo_wine ok(color_match(color, 0x0000ff00, 1),
16353 "Expected color 0x0000ff00, got 0x%08x.\n", color);
16354 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16355 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16357 /* Readonly maps write to D3DPOOL_SYSTEMMEM, but don't record a dirty rectangle. */
16358 fill_surface(surface_src_green, 0x000000ff, D3DLOCK_READONLY);
16359 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
16360 (IDirect3DBaseTexture9 *)tex_dst2);
16361 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
16362 add_dirty_rect_test_draw(device);
16363 color = getPixelColor(device, 320, 240);
16364 todo_wine ok(color_match(color, 0x0000ff00, 1),
16365 "Expected color 0x0000ff00, got 0x%08x.\n", color);
16366 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16367 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16369 hr = IDirect3DTexture9_AddDirtyRect(tex_src_green, NULL);
16370 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
16371 (IDirect3DBaseTexture9 *)tex_dst2);
16372 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
16373 add_dirty_rect_test_draw(device);
16374 color = getPixelColor(device, 320, 240);
16375 ok(color_match(color, 0x000000ff, 1),
16376 "Expected color 0x000000ff, got 0x%08x.\n", color);
16377 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16378 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16380 /* Maps without either of these flags record a dirty rectangle. */
16381 fill_surface(surface_src_green, 0x00ffffff, 0);
16382 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
16383 (IDirect3DBaseTexture9 *)tex_dst2);
16384 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
16385 add_dirty_rect_test_draw(device);
16386 color = getPixelColor(device, 320, 240);
16387 ok(color_match(color, 0x00ffffff, 1),
16388 "Expected color 0x00ffffff, got 0x%08x.\n", color);
16389 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16390 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16392 /* Partial LockRect works just like a partial AddDirtyRect call. */
16393 hr = IDirect3DTexture9_LockRect(tex_src_green, 0, &locked_rect, &part_rect, 0);
16394 ok(SUCCEEDED(hr), "Failed to lock texture, hr %#x.\n", hr);
16395 texel = locked_rect.pBits;
16396 for (i = 0; i < 64; i++)
16397 texel[i] = 0x00ff00ff;
16398 for (i = 1; i < 64; i++)
16399 memcpy((BYTE *)locked_rect.pBits + i * locked_rect.Pitch, locked_rect.pBits, locked_rect.Pitch);
16400 hr = IDirect3DTexture9_UnlockRect(tex_src_green, 0);
16401 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr);
16402 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
16403 (IDirect3DBaseTexture9 *)tex_dst2);
16404 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
16405 add_dirty_rect_test_draw(device);
16406 color = getPixelColor(device, 320, 240);
16407 ok(color_match(color, 0x00ff00ff, 1),
16408 "Expected color 0x00ff00ff, got 0x%08x.\n", color);
16409 color = getPixelColor(device, 1, 1);
16410 ok(color_match(color, 0x00ffffff, 1),
16411 "Expected color 0x00ffffff, got 0x%08x.\n", color);
16412 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16413 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16415 fill_surface(surface_src_red, 0x00ff0000, 0);
16416 fill_surface(surface_src_green, 0x0000ff00, 0);
16418 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_green,
16419 (IDirect3DBaseTexture9 *)tex_dst1);
16420 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
16421 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)tex_dst1);
16422 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
16423 add_dirty_rect_test_draw(device);
16424 color = getPixelColor(device, 320, 240);
16425 ok(color_match(color, 0x0000ff00, 1),
16426 "Expected color 0x0000ff00, got 0x%08x.\n", color);
16427 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16428 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16430 /* UpdateSurface ignores the missing dirty marker. */
16431 hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)tex_src_red,
16432 (IDirect3DBaseTexture9 *)tex_dst2);
16433 hr = IDirect3DDevice9_UpdateSurface(device, surface_src_green, NULL, surface_dst2, NULL);
16434 ok(SUCCEEDED(hr), "Failed to update surface, hr %#x.\n", hr);
16435 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)tex_dst2);
16436 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
16437 add_dirty_rect_test_draw(device);
16438 color = getPixelColor(device, 320, 240);
16439 ok(color_match(color, 0x0000ff00, 1),
16440 "Expected color 0x0000ff00, got 0x%08x.\n", color);
16441 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16442 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16444 fill_surface(surface_managed, 0x00ff0000, 0);
16445 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)tex_managed);
16446 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
16447 add_dirty_rect_test_draw(device);
16448 color = getPixelColor(device, 320, 240);
16449 ok(color_match(color, 0x00ff0000, 1),
16450 "Expected color 0x00ff0000, got 0x%08x.\n", color);
16451 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16452 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16454 /* Managed textures also honor D3DLOCK_NO_DIRTY_UPDATE. */
16455 fill_surface(surface_managed, 0x0000ff00, D3DLOCK_NO_DIRTY_UPDATE);
16456 add_dirty_rect_test_draw(device);
16457 color = getPixelColor(device, 320, 240);
16458 ok(color_match(color, 0x00ff0000, 1),
16459 "Expected color 0x00ff0000, got 0x%08x.\n", color);
16460 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16461 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16463 /* AddDirtyRect uploads the new contents.
16464 * Side note, not tested in the test: Partial surface updates work, and two separate
16465 * dirty rectangles are tracked individually. Tested on Nvidia Kepler, other drivers
16466 * untested. */
16467 hr = IDirect3DTexture9_AddDirtyRect(tex_managed, NULL);
16468 ok(SUCCEEDED(hr), "Failed to add dirty rect, hr %#x.\n", hr);
16469 add_dirty_rect_test_draw(device);
16470 color = getPixelColor(device, 320, 240);
16471 ok(color_match(color, 0x0000ff00, 1),
16472 "Expected color 0x0000ff00, got 0x%08x.\n", color);
16473 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16474 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16476 /* So does EvictManagedResources. */
16477 fill_surface(surface_managed, 0x000000ff, D3DLOCK_NO_DIRTY_UPDATE);
16478 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr);
16479 hr = IDirect3DDevice9_EvictManagedResources(device);
16480 ok(SUCCEEDED(hr), "Failed to evict managed resources, hr %#x.\n", hr);
16481 add_dirty_rect_test_draw(device);
16482 color = getPixelColor(device, 320, 240);
16483 ok(color_match(color, 0x000000ff, 1),
16484 "Expected color 0x000000ff, got 0x%08x.\n", color);
16485 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16486 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16488 /* AddDirtyRect on a locked texture is allowed. */
16489 hr = IDirect3DTexture9_LockRect(tex_src_red, 0, &locked_rect, NULL, 0);
16490 ok(SUCCEEDED(hr), "Failed to lock texture, hr %#x.\n", hr);
16491 hr = IDirect3DTexture9_AddDirtyRect(tex_src_red, NULL);
16492 ok(SUCCEEDED(hr), "Failed to add dirty rect, hr %#x.\n", hr);
16493 hr = IDirect3DTexture9_UnlockRect(tex_src_red, 0);
16494 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr);
16496 /* Redundant AddDirtyRect calls are ok. */
16497 hr = IDirect3DTexture9_AddDirtyRect(tex_managed, NULL);
16498 ok(SUCCEEDED(hr), "Failed to add dirty rect, hr %#x.\n", hr);
16499 hr = IDirect3DTexture9_AddDirtyRect(tex_managed, NULL);
16500 ok(SUCCEEDED(hr), "Failed to add dirty rect, hr %#x.\n", hr);
16502 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_DISABLE);
16503 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
16504 hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
16505 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
16506 IDirect3DSurface9_Release(surface_dst2);
16507 IDirect3DSurface9_Release(surface_managed);
16508 IDirect3DSurface9_Release(surface_src_red);
16509 IDirect3DSurface9_Release(surface_src_green);
16510 IDirect3DTexture9_Release(tex_src_red);
16511 IDirect3DTexture9_Release(tex_src_green);
16512 IDirect3DTexture9_Release(tex_dst1);
16513 IDirect3DTexture9_Release(tex_dst2);
16514 IDirect3DTexture9_Release(tex_managed);
16515 refcount = IDirect3DDevice9_Release(device);
16516 ok(!refcount, "Device has %u references left.\n", refcount);
16517 IDirect3D9_Release(d3d);
16518 DestroyWindow(window);
16521 static void test_per_stage_constant(void)
16523 IDirect3DDevice9 *device;
16524 IDirect3D9 *d3d;
16525 D3DCOLOR color;
16526 ULONG refcount;
16527 D3DCAPS9 caps;
16528 HWND window;
16529 HRESULT hr;
16531 static const struct
16533 struct vec3 position;
16534 D3DCOLOR diffuse;
16536 quad[] =
16538 {{-1.0f, -1.0f, 0.1f}, 0xffff0000},
16539 {{-1.0f, 1.0f, 0.1f}, 0xffff0000},
16540 {{ 1.0f, -1.0f, 0.1f}, 0xffff0000},
16541 {{ 1.0f, 1.0f, 0.1f}, 0xffff0000},
16544 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
16545 0, 0, 640, 480, NULL, NULL, NULL, NULL);
16546 d3d = Direct3DCreate9(D3D_SDK_VERSION);
16547 ok(!!d3d, "Failed to create a D3D object.\n");
16548 if (!(device = create_device(d3d, window, window, TRUE)))
16550 skip("Failed to create a D3D device, skipping tests.\n");
16551 goto done;
16554 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
16555 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
16556 if (!(caps.PrimitiveMiscCaps & D3DPMISCCAPS_PERSTAGECONSTANT))
16558 skip("Per-stage constants not supported, skipping tests.\n");
16559 IDirect3DDevice9_Release(device);
16560 goto done;
16563 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
16564 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
16565 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ALPHABLENDENABLE, TRUE);
16566 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
16567 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
16568 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
16569 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
16570 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
16571 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
16572 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
16574 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_CONSTANT, 0x80a1b2c3);
16575 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
16576 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_CONSTANT);
16577 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
16578 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
16579 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
16581 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x000000ff, 1.0f, 0);
16582 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
16584 hr = IDirect3DDevice9_BeginScene(device);
16585 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
16586 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
16587 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
16588 hr = IDirect3DDevice9_EndScene(device);
16589 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
16591 color = getPixelColor(device, 320, 240);
16592 ok(color_match(color, 0x00a1b2c3, 1), "Got unexpected color 0x%08x.\n", color);
16593 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16594 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16596 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_CONSTANT | D3DTA_COMPLEMENT);
16597 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
16599 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x000000ff, 1.0f, 0);
16600 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
16602 hr = IDirect3DDevice9_BeginScene(device);
16603 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
16604 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
16605 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
16606 hr = IDirect3DDevice9_EndScene(device);
16607 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
16609 color = getPixelColor(device, 320, 240);
16610 ok(color_match(color, 0x005e4d3c, 1), "Got unexpected color 0x%08x.\n", color);
16611 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16612 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16614 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_CONSTANT | D3DTA_ALPHAREPLICATE);
16615 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
16617 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x000000ff, 1.0f, 0);
16618 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
16620 hr = IDirect3DDevice9_BeginScene(device);
16621 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
16622 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
16623 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
16624 hr = IDirect3DDevice9_EndScene(device);
16625 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
16627 color = getPixelColor(device, 320, 240);
16628 ok(color_match(color, 0x00808080, 1), "Got unexpected color 0x%08x.\n", color);
16629 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16630 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16632 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAARG1, D3DTA_CONSTANT);
16633 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
16634 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
16635 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
16636 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_CURRENT);
16637 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
16639 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x000000ff, 1.0f, 0);
16640 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
16642 hr = IDirect3DDevice9_BeginScene(device);
16643 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
16644 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
16645 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
16646 hr = IDirect3DDevice9_EndScene(device);
16647 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
16649 color = getPixelColor(device, 320, 240);
16650 ok(color_match(color, 0x0080007f, 1), "Got unexpected color 0x%08x.\n", color);
16651 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16652 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16654 refcount = IDirect3DDevice9_Release(device);
16655 ok(!refcount, "Device has %u references left.\n", refcount);
16656 done:
16657 IDirect3D9_Release(d3d);
16658 DestroyWindow(window);
16661 static void test_3dc_formats(void)
16663 static const char ati1n_data[] =
16665 /* A 4x4 texture with the color component at 50%. */
16666 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
16668 static const char ati2n_data[] =
16670 /* A 8x4 texture consisting of 2 4x4 blocks. The first block has 50% first color component,
16671 * 0% second component. Second block is the opposite. */
16672 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
16673 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
16675 static const struct
16677 struct vec3 position;
16678 struct vec2 texcoord;
16680 quads[] =
16682 {{-1.0f, -1.0f, 0.0f}, {0.0f, 0.0f}},
16683 {{-1.0f, 1.0f, 0.0f}, {0.0f, 1.0f}},
16684 {{ 0.0f, -1.0f, 1.0f}, {1.0f, 0.0f}},
16685 {{ 0.0f, 1.0f, 1.0f}, {1.0f, 1.0f}},
16687 {{ 0.0f, -1.0f, 0.0f}, {0.0f, 0.0f}},
16688 {{ 0.0f, 1.0f, 0.0f}, {0.0f, 1.0f}},
16689 {{ 1.0f, -1.0f, 1.0f}, {1.0f, 0.0f}},
16690 {{ 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f}},
16692 static const DWORD ati1n_fourcc = MAKEFOURCC('A','T','I','1');
16693 static const DWORD ati2n_fourcc = MAKEFOURCC('A','T','I','2');
16694 static const struct
16696 struct vec2 position;
16697 D3DCOLOR amd;
16698 D3DCOLOR nvidia;
16700 expected_colors[] =
16702 {{ 80, 240}, 0x003f3f3f, 0x007f0000},
16703 {{240, 240}, 0x003f3f3f, 0x007f0000},
16704 {{400, 240}, 0x00007fff, 0x00007fff},
16705 {{560, 240}, 0x007f00ff, 0x007f00ff},
16707 IDirect3D9 *d3d;
16708 IDirect3DDevice9 *device;
16709 IDirect3DTexture9 *ati1n_texture, *ati2n_texture;
16710 D3DCAPS9 caps;
16711 D3DLOCKED_RECT rect;
16712 D3DCOLOR color;
16713 ULONG refcount;
16714 HWND window;
16715 HRESULT hr;
16716 unsigned int i;
16718 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
16719 0, 0, 640, 480, NULL, NULL, NULL, NULL);
16720 d3d = Direct3DCreate9(D3D_SDK_VERSION);
16721 ok(!!d3d, "Failed to create a D3D object.\n");
16722 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
16723 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, ati1n_fourcc)))
16725 skip("ATI1N textures are not supported, skipping test.\n");
16726 goto done;
16728 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
16729 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, ati2n_fourcc)))
16731 skip("ATI2N textures are not supported, skipping test.\n");
16732 goto done;
16734 if (!(device = create_device(d3d, window, window, TRUE)))
16736 skip("Failed to create a D3D device, skipping tests.\n");
16737 goto done;
16739 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
16740 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
16741 if (!(caps.PrimitiveMiscCaps & D3DPMISCCAPS_TSSARGTEMP))
16743 skip("D3DTA_TEMP not supported, skipping tests.\n");
16744 IDirect3DDevice9_Release(device);
16745 goto done;
16748 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, ati1n_fourcc,
16749 D3DPOOL_MANAGED, &ati1n_texture, NULL);
16750 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16752 hr = IDirect3DTexture9_LockRect(ati1n_texture, 0, &rect, NULL, 0);
16753 ok(SUCCEEDED(hr), "Failed to lock texture, hr %#x.\n", hr);
16754 memcpy(rect.pBits, ati1n_data, sizeof(ati1n_data));
16755 hr = IDirect3DTexture9_UnlockRect(ati1n_texture, 0);
16756 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr);
16758 hr = IDirect3DDevice9_CreateTexture(device, 8, 4, 1, 0, ati2n_fourcc,
16759 D3DPOOL_MANAGED, &ati2n_texture, NULL);
16760 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16762 hr = IDirect3DTexture9_LockRect(ati2n_texture, 0, &rect, NULL, 0);
16763 ok(SUCCEEDED(hr), "Failed to lock texture, hr %#x.\n", hr);
16764 memcpy(rect.pBits, ati2n_data, sizeof(ati2n_data));
16765 hr = IDirect3DTexture9_UnlockRect(ati2n_texture, 0);
16766 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr);
16768 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE2(0));
16769 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
16770 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA);
16771 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
16772 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
16773 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
16774 /* The temporary register is initialized to 0. */
16775 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TEMP);
16776 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
16777 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
16778 ok(SUCCEEDED(hr), "Failed to set alpha op, hr %#x.\n", hr);
16779 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
16780 ok(SUCCEEDED(hr), "Failed to set alpha arg, hr %#x.\n", hr);
16781 hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
16782 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
16783 hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
16784 ok(SUCCEEDED(hr), "Failed to set mag filter, hr %#x.\n", hr);
16786 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff00ff, 1.0f, 0);
16787 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
16788 hr = IDirect3DDevice9_BeginScene(device);
16789 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
16790 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)ati1n_texture);
16791 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
16792 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[0], sizeof(*quads));
16793 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
16794 hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)ati2n_texture);
16795 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
16796 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quads[4], sizeof(*quads));
16797 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
16798 hr = IDirect3DDevice9_EndScene(device);
16799 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
16801 for (i = 0; i < 4; ++i)
16803 color = getPixelColor(device, expected_colors[i].position.x, expected_colors[i].position.y);
16804 ok (color_match(color, expected_colors[i].amd, 1) || color_match(color, expected_colors[i].nvidia, 1),
16805 "Expected color 0x%08x or 0x%08x, got 0x%08x, case %u.\n",
16806 expected_colors[i].amd, expected_colors[i].nvidia, color, i);
16809 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16810 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16811 IDirect3DTexture9_Release(ati2n_texture);
16812 IDirect3DTexture9_Release(ati1n_texture);
16813 refcount = IDirect3DDevice9_Release(device);
16814 ok(!refcount, "Device has %u references left.\n", refcount);
16816 done:
16817 IDirect3D9_Release(d3d);
16818 DestroyWindow(window);
16821 static void test_fog_interpolation(void)
16823 HRESULT hr;
16824 IDirect3DDevice9 *device;
16825 IDirect3D9 *d3d;
16826 ULONG refcount;
16827 HWND window;
16828 D3DCOLOR color;
16829 static const struct
16831 struct vec3 position;
16832 D3DCOLOR diffuse;
16833 D3DCOLOR specular;
16835 quad[] =
16837 {{-1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff000000},
16838 {{-1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff000000},
16839 {{ 1.0f, -1.0f, 1.0f}, 0xffff0000, 0x00000000},
16840 {{ 1.0f, 1.0f, 1.0f}, 0xffff0000, 0x00000000},
16842 union
16844 DWORD d;
16845 float f;
16846 } conv;
16847 unsigned int i;
16848 static const struct
16850 D3DFOGMODE vfog, tfog;
16851 D3DSHADEMODE shade;
16852 D3DCOLOR middle_color;
16853 BOOL todo;
16855 tests[] =
16857 {D3DFOG_NONE, D3DFOG_NONE, D3DSHADE_FLAT, 0x00007f80, FALSE},
16858 {D3DFOG_NONE, D3DFOG_NONE, D3DSHADE_GOURAUD, 0x00007f80, FALSE},
16859 {D3DFOG_EXP, D3DFOG_NONE, D3DSHADE_FLAT, 0x00007f80, TRUE},
16860 {D3DFOG_EXP, D3DFOG_NONE, D3DSHADE_GOURAUD, 0x00007f80, TRUE},
16861 {D3DFOG_NONE, D3DFOG_EXP, D3DSHADE_FLAT, 0x0000ea15, FALSE},
16862 {D3DFOG_NONE, D3DFOG_EXP, D3DSHADE_GOURAUD, 0x0000ea15, FALSE},
16863 {D3DFOG_EXP, D3DFOG_EXP, D3DSHADE_FLAT, 0x0000ea15, FALSE},
16864 {D3DFOG_EXP, D3DFOG_EXP, D3DSHADE_GOURAUD, 0x0000ea15, FALSE},
16866 static const D3DMATRIX ident_mat =
16868 1.0f, 0.0f, 0.0f, 0.0f,
16869 0.0f, 1.0f, 0.0f, 0.0f,
16870 0.0f, 0.0f, 1.0f, 0.0f,
16871 0.0f, 0.0f, 0.0f, 1.0f
16872 }}};
16873 D3DCAPS9 caps;
16875 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
16876 0, 0, 640, 480, NULL, NULL, NULL, NULL);
16877 d3d = Direct3DCreate9(D3D_SDK_VERSION);
16878 ok(!!d3d, "Failed to create a D3D object.\n");
16880 if (!(device = create_device(d3d, window, window, TRUE)))
16882 skip("Failed to create a D3D device, skipping tests.\n");
16883 IDirect3D9_Release(d3d);
16884 DestroyWindow(window);
16885 return;
16888 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
16889 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
16890 if (!(caps.RasterCaps & D3DPRASTERCAPS_FOGTABLE))
16891 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests\n");
16893 hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR);
16894 ok(SUCCEEDED(hr), "Failed to set fvf, hr %#x.\n", hr);
16895 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
16896 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
16897 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE);
16898 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
16899 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGENABLE, TRUE);
16900 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
16901 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGCOLOR, 0x0000ff00);
16902 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
16903 conv.f = 5.0;
16904 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGDENSITY, conv.d);
16905 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
16907 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
16908 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
16909 hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
16910 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
16911 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0x000000ff);
16912 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
16914 /* Some of the tests seem to depend on the projection matrix explicitly
16915 * being set to an identity matrix, even though that's the default.
16916 * (AMD Radeon X1600, AMD Radeon HD 6310, Windows 7). Without this,
16917 * the drivers seem to use a static z = 1.0 input for the fog equation.
16918 * The input value is independent of the actual z and w component of
16919 * the vertex position. */
16920 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &ident_mat);
16921 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
16923 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
16925 if(!(caps.RasterCaps & D3DPRASTERCAPS_FOGTABLE) && tests[i].tfog)
16926 continue;
16928 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00808080, 0.0f, 0);
16929 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
16931 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SHADEMODE, tests[i].shade);
16932 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
16933 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGVERTEXMODE, tests[i].vfog);
16934 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
16935 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, tests[i].tfog);
16936 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
16937 hr = IDirect3DDevice9_BeginScene(device);
16938 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
16939 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
16940 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
16941 hr = IDirect3DDevice9_EndScene(device);
16942 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
16944 color = getPixelColor(device, 0, 240);
16945 ok(color_match(color, 0x000000ff, 2), "Got unexpected color 0x%08x, case %u.\n", color, i);
16946 color = getPixelColor(device, 320, 240);
16947 if (tests[i].todo)
16948 todo_wine ok(color_match(color, tests[i].middle_color, 2),
16949 "Got unexpected color 0x%08x, case %u.\n", color, i);
16950 else
16951 ok(color_match(color, tests[i].middle_color, 2),
16952 "Got unexpected color 0x%08x, case %u.\n", color, i);
16953 color = getPixelColor(device, 639, 240);
16954 ok(color_match(color, 0x0000fd02, 2), "Got unexpected color 0x%08x, case %u.\n", color, i);
16955 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
16956 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
16959 refcount = IDirect3DDevice9_Release(device);
16960 ok(!refcount, "Device has %u references left.\n", refcount);
16961 IDirect3D9_Release(d3d);
16962 DestroyWindow(window);
16965 static void test_negative_fixedfunction_fog(void)
16967 HRESULT hr;
16968 IDirect3DDevice9 *device;
16969 IDirect3D9 *d3d;
16970 ULONG refcount;
16971 HWND window;
16972 D3DCOLOR color;
16973 static const struct
16975 struct vec3 position;
16976 D3DCOLOR diffuse;
16978 quad[] =
16980 {{-1.0f, -1.0f, -0.5f}, 0xffff0000},
16981 {{-1.0f, 1.0f, -0.5f}, 0xffff0000},
16982 {{ 1.0f, -1.0f, -0.5f}, 0xffff0000},
16983 {{ 1.0f, 1.0f, -0.5f}, 0xffff0000},
16985 static const struct
16987 struct vec4 position;
16988 D3DCOLOR diffuse;
16990 tquad[] =
16992 {{ 0.0f, 0.0f, -0.5f, 1.0f}, 0xffff0000},
16993 {{640.0f, 0.0f, -0.5f, 1.0f}, 0xffff0000},
16994 {{ 0.0f, 480.0f, -0.5f, 1.0f}, 0xffff0000},
16995 {{640.0f, 480.0f, -0.5f, 1.0f}, 0xffff0000},
16997 unsigned int i;
16998 static const D3DMATRIX zero =
17000 1.0f, 0.0f, 0.0f, 0.0f,
17001 0.0f, 1.0f, 0.0f, 0.0f,
17002 0.0f, 0.0f, 0.0f, 0.0f,
17003 0.0f, 0.0f, 0.0f, 1.0f
17004 }}};
17005 /* Needed to make AMD drivers happy. Yeah, it is not supposed to
17006 * have an effect on RHW draws. */
17007 static const D3DMATRIX identity =
17009 1.0f, 0.0f, 0.0f, 0.0f,
17010 0.0f, 1.0f, 0.0f, 0.0f,
17011 0.0f, 0.0f, 1.0f, 0.0f,
17012 0.0f, 0.0f, 0.0f, 1.0f
17013 }}};
17014 static const struct
17016 DWORD pos_type;
17017 const void *quad;
17018 size_t stride;
17019 const D3DMATRIX *matrix;
17020 union
17022 float f;
17023 DWORD d;
17024 } start, end;
17025 D3DFOGMODE vfog, tfog;
17026 DWORD color, color_broken;
17028 tests[] =
17030 /* Run the XYZRHW tests first. Depth clamping is broken after RHW draws on the testbot. */
17031 {D3DFVF_XYZRHW, tquad, sizeof(*tquad), &identity, { 0.0f}, {1.0f},
17032 D3DFOG_NONE, D3DFOG_LINEAR, 0x00ff0000, 0x00ff0000},
17033 /* r200 GPUs and presumably all d3d8 and older HW clamp the fog
17034 * parameters to 0.0 and 1.0 in the table fog case. */
17035 {D3DFVF_XYZRHW, tquad, sizeof(*tquad), &identity, {-1.0f}, {0.0f},
17036 D3DFOG_NONE, D3DFOG_LINEAR, 0x00808000, 0x00ff0000},
17037 /* test_fog_interpolation shows that vertex fog evaluates the fog
17038 * equation in the vertex pipeline. Start = -1.0 && end = 0.0 shows
17039 * that the abs happens before the fog equation is evaluated. */
17040 {D3DFVF_XYZ, quad, sizeof(*quad), &zero, { 0.0f}, {1.0f},
17041 D3DFOG_LINEAR, D3DFOG_NONE, 0x00808000, 0x00808000},
17042 {D3DFVF_XYZ, quad, sizeof(*quad), &zero, {-1.0f}, {0.0f},
17043 D3DFOG_LINEAR, D3DFOG_NONE, 0x0000ff00, 0x0000ff00},
17044 {D3DFVF_XYZ, quad, sizeof(*quad), &zero, { 0.0f}, {1.0f},
17045 D3DFOG_EXP, D3DFOG_NONE, 0x009b6400, 0x009b6400},
17047 D3DCAPS9 caps;
17049 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
17050 0, 0, 640, 480, NULL, NULL, NULL, NULL);
17051 d3d = Direct3DCreate9(D3D_SDK_VERSION);
17052 ok(!!d3d, "Failed to create a D3D object.\n");
17054 if (!(device = create_device(d3d, window, window, TRUE)))
17056 skip("Failed to create a D3D device, skipping tests.\n");
17057 IDirect3D9_Release(d3d);
17058 DestroyWindow(window);
17059 return;
17062 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
17063 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
17064 if (!(caps.RasterCaps & D3DPRASTERCAPS_FOGTABLE))
17065 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests.\n");
17067 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
17068 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
17069 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
17070 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
17071 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGENABLE, TRUE);
17072 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
17073 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGCOLOR, 0x0000ff00);
17074 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
17075 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, FALSE);
17076 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
17078 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
17080 if (!(caps.RasterCaps & D3DPRASTERCAPS_FOGTABLE) && tests[i].tfog)
17081 continue;
17083 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x000000ff, 0.0f, 0);
17084 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
17086 hr = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, tests[i].matrix);
17087 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
17088 hr = IDirect3DDevice9_SetFVF(device, tests[i].pos_type | D3DFVF_DIFFUSE);
17089 ok(SUCCEEDED(hr), "Failed to set fvf, hr %#x.\n", hr);
17090 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGSTART, tests[i].start.d);
17091 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
17092 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGEND, tests[i].end.d);
17093 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
17094 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGVERTEXMODE, tests[i].vfog);
17095 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
17096 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_FOGTABLEMODE, tests[i].tfog);
17097 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
17099 hr = IDirect3DDevice9_BeginScene(device);
17100 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
17101 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, tests[i].quad, tests[i].stride);
17102 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
17103 hr = IDirect3DDevice9_EndScene(device);
17104 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
17106 color = getPixelColor(device, 320, 240);
17107 ok(color_match(color, tests[i].color, 2) || broken(color_match(color, tests[i].color_broken, 2)),
17108 "Got unexpected color 0x%08x, case %u.\n", color, i);
17109 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17110 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17113 refcount = IDirect3DDevice9_Release(device);
17114 ok(!refcount, "Device has %u references left.\n", refcount);
17115 IDirect3D9_Release(d3d);
17116 DestroyWindow(window);
17119 static void test_position_index(void)
17121 static const D3DVERTEXELEMENT9 decl_elements[] =
17123 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
17124 {0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 1},
17125 D3DDECL_END()
17127 /* Declaring (and using) a position1 output semantic in a VS fails at draw time on AMD
17128 * but works on Nvidia.
17129 * MSDN is not consistent on this point. */
17130 static const DWORD vs_code[] =
17132 0xfffe0300, /* vs_3_0 */
17133 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position0 v0 */
17134 0x0200001f, 0x80010000, 0x900f0001, /* dcl_position1 v1 */
17135 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position0 o0 */
17136 0x0200001f, 0x80010000, 0xe00f0001, /* dcl_position1 o1 */
17137 0x0200001f, 0x80000005, 0xe00f0002, /* dcl_texcoord0 o2 */
17138 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
17139 0x02000001, 0xe00f0001, 0x90e40001, /* mov o1, v1 */
17140 0x02000001, 0xe00f0002, 0x90e40001, /* mov o2, v1 */
17141 0x0000ffff /* end */
17143 static const DWORD vs_code_2[] =
17145 0xfffe0300, /* vs_3_0 */
17146 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position0 v0 */
17147 0x0200001f, 0x80010000, 0x900f0001, /* dcl_position1 v1 */
17148 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position0 o0 */
17149 0x0200001f, 0x80000005, 0xe00f0002, /* dcl_texcoord0 o2 */
17150 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
17151 0x02000001, 0xe00f0002, 0x90e40001, /* mov o2, v1 */
17152 0x0000ffff /* end */
17154 static const DWORD ps_code[] =
17156 0xffff0300, /* ps_3_0 */
17157 0x0200001f, 0x80010000, 0x900f0000, /* dcl_position1 v0 */
17158 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
17159 0x0000ffff /* end */
17161 static const DWORD ps_code_2[] =
17163 0xffff0300, /* ps_3_0 */
17164 0x0200001f, 0x80000005, 0x900f0000, /* dcl_texcoord0 v0 */
17165 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
17166 0x0000ffff /* end */
17168 /* This one is considered invalid by the native shader assembler. */
17169 static const DWORD ps_code_bad[] =
17171 0xffff0300, /* ps_3_0 */
17172 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position0 v0 */
17173 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
17174 0x0000ffff /* end */
17176 static const struct
17178 struct vec3 position;
17179 struct vec3 position1;
17181 quad[] =
17183 {{-1.0f, -1.0f, 0.5f}, {1.0f, 0.0f, 0.0f}},
17184 {{-1.0f, 1.0f, 0.5f}, {1.0f, 0.0f, 0.0f}},
17185 {{ 1.0f, -1.0f, 0.5f}, {0.0f, 1.0f, 0.0f}},
17186 {{ 1.0f, 1.0f, 0.5f}, {0.0f, 1.0f, 0.0f}},
17188 static const struct
17190 struct vec2 position;
17191 D3DCOLOR expected_color;
17192 D3DCOLOR broken_color;
17194 expected_colors[] =
17196 {{ 80, 240}, 0x00df2000, 0x00ff00ff},
17197 {{240, 240}, 0x009f6000, 0x00ff00ff},
17198 {{400, 240}, 0x00609f00, 0x00ff00ff},
17199 {{560, 240}, 0x0020df00, 0x00ff00ff},
17201 IDirect3D9 *d3d;
17202 IDirect3DDevice9 *device;
17203 IDirect3DVertexDeclaration9 *vertex_declaration;
17204 IDirect3DVertexShader9 *vs, *vs2;
17205 IDirect3DPixelShader9 *ps, *ps2;
17206 D3DCAPS9 caps;
17207 D3DCOLOR color;
17208 ULONG refcount;
17209 HWND window;
17210 HRESULT hr;
17211 unsigned int i;
17213 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
17214 0, 0, 640, 480, NULL, NULL, NULL, NULL);
17215 d3d = Direct3DCreate9(D3D_SDK_VERSION);
17216 ok(!!d3d, "Failed to create a D3D object.\n");
17217 if (!(device = create_device(d3d, window, window, TRUE)))
17219 skip("Failed to create a D3D device, skipping tests.\n");
17220 goto done;
17223 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
17224 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
17225 if (caps.VertexShaderVersion < D3DVS_VERSION(3, 0)
17226 || caps.PixelShaderVersion < D3DPS_VERSION(3, 0))
17228 skip("Shader model 3.0 unsupported, skipping tests.\n");
17229 IDirect3DDevice9_Release(device);
17230 goto done;
17233 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &vertex_declaration);
17234 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed, hr %#x\n", hr);
17236 hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration);
17237 ok(SUCCEEDED(hr), "SetVertexDeclaration failed, hr %#x\n", hr);
17239 hr = IDirect3DDevice9_CreateVertexShader(device, vs_code, &vs);
17240 ok(SUCCEEDED(hr), "CreateVertexShader failed, hr %#x.\n", hr);
17241 hr = IDirect3DDevice9_CreateVertexShader(device, vs_code_2, &vs2);
17242 ok(SUCCEEDED(hr), "CreateVertexShader failed, hr %#x.\n", hr);
17244 hr = IDirect3DDevice9_SetVertexShader(device, vs);
17245 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
17247 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code_bad, &ps);
17248 ok(hr == D3DERR_INVALIDCALL, "CreatePixelShader returned hr %#x.\n", hr);
17250 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code, &ps);
17251 ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
17252 hr = IDirect3DDevice9_CreatePixelShader(device, ps_code_2, &ps2);
17253 ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
17255 hr = IDirect3DDevice9_SetPixelShader(device, ps);
17256 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
17258 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff00ff, 1.0f, 0);
17259 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
17260 hr = IDirect3DDevice9_BeginScene(device);
17261 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
17262 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
17263 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
17264 hr = IDirect3DDevice9_EndScene(device);
17265 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
17267 for (i = 0; i < sizeof(expected_colors) / sizeof(expected_colors[0]); ++i)
17269 color = getPixelColor(device, expected_colors[i].position.x, expected_colors[i].position.y);
17270 ok (color_match(color, expected_colors[i].expected_color, 1)
17271 || broken(color_match(color, expected_colors[i].broken_color, 1)),
17272 "Got unexpected color 0x%08x, case %u.\n", color, i);
17275 hr = IDirect3DDevice9_SetPixelShader(device, ps2);
17276 ok(SUCCEEDED(hr), "Failed to set pixel shader, hr %#x.\n", hr);
17278 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff00ff, 1.0f, 0);
17279 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
17280 hr = IDirect3DDevice9_BeginScene(device);
17281 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
17282 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
17283 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
17284 hr = IDirect3DDevice9_EndScene(device);
17285 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
17287 for (i = 0; i < sizeof(expected_colors) / sizeof(expected_colors[0]); ++i)
17289 color = getPixelColor(device, expected_colors[i].position.x, expected_colors[i].position.y);
17290 ok (color_match(color, expected_colors[i].expected_color, 1)
17291 || broken(color_match(color, expected_colors[i].broken_color, 1)),
17292 "Got unexpected color 0x%08x, case %u.\n", color, i);
17295 hr = IDirect3DDevice9_SetVertexShader(device, vs2);
17296 ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
17298 hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ff00ff, 1.0f, 0);
17299 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
17300 hr = IDirect3DDevice9_BeginScene(device);
17301 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
17302 hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
17303 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
17304 hr = IDirect3DDevice9_EndScene(device);
17305 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
17307 for (i = 0; i < sizeof(expected_colors) / sizeof(expected_colors[0]); ++i)
17309 color = getPixelColor(device, expected_colors[i].position.x, expected_colors[i].position.y);
17310 ok (color_match(color, expected_colors[i].expected_color, 1),
17311 "Got unexpected color 0x%08x, case %u.\n", color, i);
17314 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
17315 ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
17317 IDirect3DPixelShader9_Release(ps2);
17318 IDirect3DPixelShader9_Release(ps);
17319 IDirect3DVertexShader9_Release(vs2);
17320 IDirect3DVertexShader9_Release(vs);
17321 IDirect3DVertexDeclaration9_Release(vertex_declaration);
17322 refcount = IDirect3DDevice9_Release(device);
17323 ok(!refcount, "Device has %u references left.\n", refcount);
17325 done:
17326 IDirect3D9_Release(d3d);
17327 DestroyWindow(window);
17330 START_TEST(visual)
17332 D3DADAPTER_IDENTIFIER9 identifier;
17333 IDirect3D9 *d3d;
17334 HRESULT hr;
17336 if (!(d3d = Direct3DCreate9(D3D_SDK_VERSION)))
17338 skip("could not create D3D9 object\n");
17339 return;
17342 memset(&identifier, 0, sizeof(identifier));
17343 hr = IDirect3D9_GetAdapterIdentifier(d3d, 0, 0, &identifier);
17344 ok(SUCCEEDED(hr), "Failed to get adapter identifier, hr %#x.\n", hr);
17345 trace("Driver string: \"%s\"\n", identifier.Driver);
17346 trace("Description string: \"%s\"\n", identifier.Description);
17347 /* Only Windows XP's default VGA driver should have an empty description */
17348 ok(identifier.Description[0] || broken(!strcmp(identifier.Driver, "vga.dll")), "Empty driver description.\n");
17349 trace("Device name string: \"%s\"\n", identifier.DeviceName);
17350 ok(identifier.DeviceName[0], "Empty device name.\n");
17351 trace("Driver version %d.%d.%d.%d\n",
17352 HIWORD(U(identifier.DriverVersion).HighPart), LOWORD(U(identifier.DriverVersion).HighPart),
17353 HIWORD(U(identifier.DriverVersion).LowPart), LOWORD(U(identifier.DriverVersion).LowPart));
17355 IDirect3D9_Release(d3d);
17357 test_sanity();
17358 depth_clamp_test();
17359 stretchrect_test();
17360 lighting_test();
17361 clear_test();
17362 color_fill_test();
17363 fog_test();
17364 test_cube_wrap();
17365 z_range_test();
17366 maxmip_test();
17367 offscreen_test();
17368 ds_size_test();
17369 test_blend();
17370 shademode_test();
17371 srgbtexture_test();
17372 release_buffer_test();
17373 float_texture_test();
17374 g16r16_texture_test();
17375 pixelshader_blending_test();
17376 texture_transform_flags_test();
17377 autogen_mipmap_test();
17378 fixed_function_decl_test();
17379 conditional_np2_repeat_test();
17380 fixed_function_bumpmap_test();
17381 pointsize_test();
17382 tssargtemp_test();
17383 np2_stretch_rect_test();
17384 yuv_color_test();
17385 yuv_layout_test();
17386 zwriteenable_test();
17387 alphatest_test();
17388 viewport_test();
17389 test_constant_clamp_vs();
17390 test_compare_instructions();
17391 test_mova();
17392 loop_index_test();
17393 sincos_test();
17394 sgn_test();
17395 clip_planes_test();
17396 test_vshader_input();
17397 test_vshader_float16();
17398 stream_test();
17399 fog_with_shader_test();
17400 texbem_test();
17401 texdepth_test();
17402 texkill_test();
17403 x8l8v8u8_test();
17404 volume_v16u16_test();
17405 constant_clamp_ps_test();
17406 cnd_test();
17407 dp2add_ps_test();
17408 unbound_sampler_test();
17409 nested_loop_test();
17410 pretransformed_varying_test();
17411 vface_register_test();
17412 vpos_register_test();
17413 multiple_rendertargets_test();
17414 texop_test();
17415 texop_range_test();
17416 alphareplicate_test();
17417 dp3_alpha_test();
17418 depth_buffer_test();
17419 depth_buffer2_test();
17420 depth_blit_test();
17421 intz_test();
17422 shadow_test();
17423 fp_special_test();
17424 depth_bounds_test();
17425 srgbwrite_format_test();
17426 update_surface_test();
17427 multisample_get_rtdata_test();
17428 zenable_test();
17429 fog_special_test();
17430 volume_srgb_test();
17431 volume_dxt5_test();
17432 add_dirty_rect_test();
17433 multisampled_depth_buffer_test();
17434 resz_test();
17435 stencil_cull_test();
17436 test_per_stage_constant();
17437 test_3dc_formats();
17438 test_fog_interpolation();
17439 test_negative_fixedfunction_fog();
17440 test_position_index();