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
35 #include "wine/test.h"
52 static HWND
create_window(void)
57 SetRect(&rect
, 0, 0, 640, 480);
58 AdjustWindowRect(&rect
, WS_OVERLAPPEDWINDOW
| WS_VISIBLE
, FALSE
);
59 hwnd
= CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
60 0, 0, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 0, 0, 0, 0);
64 static BOOL
color_match(D3DCOLOR c1
, D3DCOLOR c2
, BYTE max_diff
)
66 if (abs((int)(c1
& 0xff) - (int)(c2
& 0xff)) > max_diff
) return FALSE
;
68 if (abs((int)(c1
& 0xff) - (int)(c2
& 0xff)) > max_diff
) return FALSE
;
70 if (abs((int)(c1
& 0xff) - (int)(c2
& 0xff)) > max_diff
) return FALSE
;
72 if (abs((int)(c1
& 0xff) - (int)(c2
& 0xff)) > max_diff
) return FALSE
;
76 static BOOL
adapter_is_warp(const D3DADAPTER_IDENTIFIER9
*identifier
)
78 return !strcmp(identifier
->Driver
, "d3d10warp.dll");
81 /* Locks a given surface and returns the color at (x,y). It's the caller's
82 * responsibility to only pass in lockable surfaces and valid x,y coordinates */
83 static DWORD
getPixelColorFromSurface(IDirect3DSurface9
*surface
, UINT x
, UINT y
)
88 RECT rectToLock
= {x
, y
, x
+1, y
+1};
89 D3DLOCKED_RECT lockedRect
;
91 hr
= IDirect3DSurface9_GetDesc(surface
, &desc
);
92 if(FAILED(hr
)) /* This is not a test */
94 trace("Can't get the surface description, hr=%08x\n", hr
);
98 hr
= IDirect3DSurface9_LockRect(surface
, &lockedRect
, &rectToLock
, D3DLOCK_READONLY
);
99 if(FAILED(hr
)) /* This is not a test */
101 trace("Can't lock the surface, hr=%08x\n", hr
);
104 switch(desc
.Format
) {
105 case D3DFMT_A8R8G8B8
:
107 color
= ((DWORD
*) lockedRect
.pBits
)[0];
111 trace("Error: unknown surface format: %d\n", desc
.Format
);
115 hr
= IDirect3DSurface9_UnlockRect(surface
);
118 trace("Can't unlock the surface, hr=%08x\n", hr
);
123 struct surface_readback
125 IDirect3DSurface9
*surface
;
126 D3DLOCKED_RECT locked_rect
;
129 static void get_rt_readback(IDirect3DSurface9
*surface
, struct surface_readback
*rb
)
131 IDirect3DDevice9
*device
;
132 D3DSURFACE_DESC desc
;
135 memset(rb
, 0, sizeof(*rb
));
136 hr
= IDirect3DSurface9_GetDevice(surface
, &device
);
137 ok(SUCCEEDED(hr
), "Failed to get device, hr %#x.\n", hr
);
138 hr
= IDirect3DSurface9_GetDesc(surface
, &desc
);
139 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
140 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, desc
.Width
, desc
.Height
,
141 desc
.Format
, D3DPOOL_SYSTEMMEM
, &rb
->surface
, NULL
);
142 if (FAILED(hr
) || !rb
->surface
)
144 trace("Can't create an offscreen plain surface to read the render target data, hr %#x.\n", hr
);
148 hr
= IDirect3DDevice9_GetRenderTargetData(device
, surface
, rb
->surface
);
151 trace("Can't read the render target data, hr %#x.\n", hr
);
155 hr
= IDirect3DSurface9_LockRect(rb
->surface
, &rb
->locked_rect
, NULL
, D3DLOCK_READONLY
);
158 trace("Can't lock the offscreen surface, hr %#x.\n", hr
);
161 IDirect3DDevice9_Release(device
);
167 IDirect3DSurface9_Release(rb
->surface
);
169 IDirect3DDevice9_Release(device
);
172 static DWORD
get_readback_color(struct surface_readback
*rb
, unsigned int x
, unsigned int y
)
174 return rb
->locked_rect
.pBits
175 ? ((DWORD
*)rb
->locked_rect
.pBits
)[y
* rb
->locked_rect
.Pitch
/ sizeof(DWORD
) + x
] : 0xdeadbeef;
178 static void release_surface_readback(struct surface_readback
*rb
)
184 if (rb
->locked_rect
.pBits
&& FAILED(hr
= IDirect3DSurface9_UnlockRect(rb
->surface
)))
185 trace("Can't unlock the offscreen surface, hr %#x.\n", hr
);
186 IDirect3DSurface9_Release(rb
->surface
);
189 static DWORD
getPixelColor(IDirect3DDevice9
*device
, UINT x
, UINT y
)
192 IDirect3DSurface9
*rt
;
193 struct surface_readback rb
;
196 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &rt
);
199 trace("Can't get the render target, hr %#x.\n", hr
);
203 get_rt_readback(rt
, &rb
);
204 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
205 * really important for these tests
207 ret
= get_readback_color(&rb
, x
, y
) & 0x00ffffff;
208 release_surface_readback(&rb
);
210 IDirect3DSurface9_Release(rt
);
214 #define check_rt_color(a, b) check_rt_color_(__LINE__, a, b)
215 static void check_rt_color_(unsigned int line
, IDirect3DSurface9
*rt
, D3DCOLOR expected_color
)
217 struct surface_readback rb
;
218 D3DSURFACE_DESC desc
;
223 hr
= IDirect3DSurface9_GetDesc(rt
, &desc
);
224 ok_(__FILE__
, line
)(hr
== S_OK
, "Failed to get surface desc, hr %#x.\n", hr
);
226 get_rt_readback(rt
, &rb
);
227 for (y
= 0; y
< desc
.Height
; ++y
)
229 for (x
= 0; x
< desc
.Width
; ++x
)
231 color
= get_readback_color(&rb
, x
, y
) & 0x00ffffff;
232 if (color
!= expected_color
)
235 if (color
!= expected_color
)
238 release_surface_readback(&rb
);
239 ok_(__FILE__
, line
)(color
== 0x000000ff, "Got unexpected color 0x%08x.\n", color
);
242 static IDirect3DDevice9
*create_device(IDirect3D9
*d3d
, HWND device_window
, HWND focus_window
, BOOL windowed
)
244 D3DPRESENT_PARAMETERS present_parameters
= {0};
245 IDirect3DDevice9
*device
;
247 present_parameters
.Windowed
= windowed
;
248 present_parameters
.hDeviceWindow
= device_window
;
249 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
250 present_parameters
.BackBufferWidth
= 640;
251 present_parameters
.BackBufferHeight
= 480;
252 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
253 present_parameters
.EnableAutoDepthStencil
= TRUE
;
254 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
256 if (SUCCEEDED(IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, focus_window
,
257 D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device
)))
263 static void cleanup_device(IDirect3DDevice9
*device
)
267 D3DPRESENT_PARAMETERS present_parameters
;
268 IDirect3DSwapChain9
*swapchain
;
271 IDirect3DDevice9_GetSwapChain(device
, 0, &swapchain
);
272 IDirect3DSwapChain9_GetPresentParameters(swapchain
, &present_parameters
);
273 IDirect3DSwapChain9_Release(swapchain
);
274 ref
= IDirect3DDevice9_Release(device
);
275 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
276 DestroyWindow(present_parameters
.hDeviceWindow
);
280 static void test_sanity(void)
282 IDirect3DDevice9
*device
;
289 window
= create_window();
290 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
291 ok(!!d3d
, "Failed to create a D3D object.\n");
292 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
294 skip("Failed to create a D3D device, skipping tests.\n");
298 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 1.0f
, 0);
299 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
300 color
= getPixelColor(device
, 1, 1);
301 ok(color
== 0x00ff0000, "Got unexpected color 0x%08x.\n", color
);
303 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
304 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
306 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ddee, 0.0, 0);
307 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
308 color
= getPixelColor(device
, 639, 479);
309 ok(color
== 0x0000ddee, "Got unexpected color 0x%08x.\n", color
);
311 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
312 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
314 refcount
= IDirect3DDevice9_Release(device
);
315 ok(!refcount
, "Device has %u references left.\n", refcount
);
317 IDirect3D9_Release(d3d
);
318 DestroyWindow(window
);
321 static void lighting_test(void)
323 DWORD nfvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_NORMAL
;
324 DWORD fvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
325 IDirect3DDevice9
*device
;
326 D3DMATERIAL9 material
;
334 static const D3DMATRIX mat
=
336 1.0f
, 0.0f
, 0.0f
, 0.0f
,
337 0.0f
, 1.0f
, 0.0f
, 0.0f
,
338 0.0f
, 0.0f
, 1.0f
, 0.0f
,
339 0.0f
, 0.0f
, 0.0f
, 1.0f
,
343 1.0f
, 0.0f
, 1.0f
, 0.0f
,
344 0.0f
, 1.0f
, 0.0f
, 0.0f
,
345 1.0f
, 0.0f
, 1.0f
, 0.0f
,
346 0.0f
, 0.0f
, 0.5f
, 1.0f
,
350 0.0f
, 0.0f
, 1.0f
, 0.0f
,
351 0.0f
, 1.0f
, 0.0f
, 0.0f
,
352 -1.0f
, 0.0f
, 0.0f
, 0.0f
,
353 10.f
, 10.0f
, 10.0f
, 1.0f
,
357 1.0f
, 0.0f
, 0.0f
, 0.0f
,
358 0.0f
, 1.0f
, 0.0f
, 0.0f
,
359 0.0f
, 0.0f
, 1.0f
, -1.0f
,
360 10.f
, 10.0f
, 10.0f
, 0.0f
,
364 struct vec3 position
;
369 {{-1.0f
, -1.0f
, 0.1f
}, 0xffff0000},
370 {{-1.0f
, 0.0f
, 0.1f
}, 0xffff0000},
371 {{ 0.0f
, 0.0f
, 0.1f
}, 0xffff0000},
372 {{ 0.0f
, -1.0f
, 0.1f
}, 0xffff0000},
376 {{-1.0f
, 0.0f
, 0.1f
}, 0xff00ff00},
377 {{-1.0f
, 1.0f
, 0.1f
}, 0xff00ff00},
378 {{ 0.0f
, 1.0f
, 0.1f
}, 0xff00ff00},
379 {{ 0.0f
, 0.0f
, 0.1f
}, 0xff00ff00},
383 {{-1.0f
, -1.0f
, 0.1f
}, 0x8000ff00},
384 {{ 1.0f
, -1.0f
, 0.1f
}, 0x80000000},
385 {{-1.0f
, 1.0f
, 0.1f
}, 0x8000ff00},
386 {{ 1.0f
, 1.0f
, 0.1f
}, 0x80000000},
390 struct vec3 position
;
396 {{0.0f
, -1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
397 {{0.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
398 {{1.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
399 {{1.0f
, -1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
403 {{0.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
404 {{0.0f
, 1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
405 {{1.0f
, 1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
406 {{1.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
410 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
411 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
412 {{ 1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
413 {{ 1.0f
, -1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
417 {{-10.0f
, -11.0f
, 11.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
418 {{-10.0f
, -9.0f
, 11.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
419 {{-10.0f
, -9.0f
, 9.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
420 {{-10.0f
, -11.0f
, 9.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
424 {{-11.0f
, -11.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
425 {{-11.0f
, -9.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
426 {{ -9.0f
, -9.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
427 {{ -9.0f
, -11.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
429 static const WORD indices
[] = {0, 1, 2, 2, 3, 0};
432 const D3DMATRIX
*world_matrix
;
440 {&mat
, nquad
, sizeof(nquad
[0]), 0x000000ff, "Lit quad with light"},
441 {&mat_singular
, nquad
, sizeof(nquad
[0]), 0x000000ff, "Lit quad with singular world matrix"},
442 {&mat_transf
, rotatedquad
, sizeof(rotatedquad
[0]), 0x000000ff, "Lit quad with transformation matrix"},
443 {&mat_nonaffine
, translatedquad
, sizeof(translatedquad
[0]), 0x00000000, "Lit quad with non-affine matrix"},
446 window
= create_window();
447 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
448 ok(!!d3d
, "Failed to create a D3D object.\n");
449 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
451 skip("Failed to create a D3D device, skipping tests.\n");
455 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
456 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
458 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_WORLDMATRIX(0), &mat
);
459 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform returned %08x\n", hr
);
460 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_VIEW
, &mat
);
461 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform returned %08x\n", hr
);
462 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_PROJECTION
, &mat
);
463 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform returned %08x\n", hr
);
464 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CLIPPING
, FALSE
);
465 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
466 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
467 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
468 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGENABLE
, FALSE
);
469 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
470 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILENABLE
, FALSE
);
471 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
472 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CULLMODE
, D3DCULL_NONE
);
473 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed with %08x\n", hr
);
475 hr
= IDirect3DDevice9_SetFVF(device
, fvf
);
476 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF returned %08x\n", hr
);
478 hr
= IDirect3DDevice9_BeginScene(device
);
479 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
481 /* No lights are defined... That means, lit vertices should be entirely black */
482 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
483 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
484 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0, 4,
485 2, indices
, D3DFMT_INDEX16
, unlitquad
, sizeof(unlitquad
[0]));
486 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
488 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, TRUE
);
489 ok(SUCCEEDED(hr
), "Failed to enable lighting, hr %#x.\n", hr
);
490 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0, 4,
491 2, indices
, D3DFMT_INDEX16
, litquad
, sizeof(litquad
[0]));
492 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
494 hr
= IDirect3DDevice9_SetFVF(device
, nfvf
);
495 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
497 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
498 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
499 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0, 4,
500 2, indices
, D3DFMT_INDEX16
, unlitnquad
, sizeof(unlitnquad
[0]));
501 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
503 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, TRUE
);
504 ok(SUCCEEDED(hr
), "Failed to enable lighting, hr %#x.\n", hr
);
505 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0, 4,
506 2, indices
, D3DFMT_INDEX16
, litnquad
, sizeof(litnquad
[0]));
507 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
509 hr
= IDirect3DDevice9_EndScene(device
);
510 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
512 color
= getPixelColor(device
, 160, 360); /* Lower left quad - unlit without normals */
513 ok(color
== 0x00ff0000, "Unlit quad without normals has color 0x%08x, expected 0x00ff0000.\n", color
);
514 color
= getPixelColor(device
, 160, 120); /* Upper left quad - lit without normals */
515 ok(color
== 0x00000000, "Lit quad without normals has color 0x%08x, expected 0x00000000.\n", color
);
516 color
= getPixelColor(device
, 480, 360); /* Lower left quad - unlit with normals */
517 ok(color
== 0x000000ff, "Unlit quad with normals has color 0x%08x, expected 0x000000ff.\n", color
);
518 color
= getPixelColor(device
, 480, 120); /* Upper left quad - lit with normals */
519 ok(color
== 0x00000000, "Lit quad with normals has color 0x%08x, expected 0x00000000.\n", color
);
521 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
523 hr
= IDirect3DDevice9_LightEnable(device
, 0, TRUE
);
524 ok(SUCCEEDED(hr
), "Failed to enable light 0, hr %#x.\n", hr
);
526 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
528 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_WORLD
, tests
[i
].world_matrix
);
529 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
531 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
532 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
534 hr
= IDirect3DDevice9_BeginScene(device
);
535 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
537 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0, 4,
538 2, indices
, D3DFMT_INDEX16
, tests
[i
].quad
, tests
[i
].size
);
539 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
541 hr
= IDirect3DDevice9_EndScene(device
);
542 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
544 color
= getPixelColor(device
, 320, 240);
545 ok(color
== tests
[i
].expected
, "%s has color 0x%08x.\n", tests
[i
].message
, color
);
548 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_WORLD
, &mat
);
549 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
550 hr
= IDirect3DDevice9_LightEnable(device
, 0, FALSE
);
551 ok(SUCCEEDED(hr
), "Failed to disable light 0, hr %#x.\n", hr
);
553 memset(&material
, 0, sizeof(material
));
554 material
.Diffuse
.r
= 0.0;
555 material
.Diffuse
.g
= 0.0;
556 material
.Diffuse
.b
= 0.0;
557 material
.Diffuse
.a
= 1.0;
558 material
.Ambient
.r
= 0.0;
559 material
.Ambient
.g
= 0.0;
560 material
.Ambient
.b
= 0.0;
561 material
.Ambient
.a
= 0.0;
562 material
.Specular
.r
= 0.0;
563 material
.Specular
.g
= 0.0;
564 material
.Specular
.b
= 0.0;
565 material
.Specular
.a
= 0.0;
566 material
.Emissive
.r
= 0.0;
567 material
.Emissive
.g
= 0.0;
568 material
.Emissive
.b
= 0.0;
569 material
.Emissive
.a
= 0.0;
570 material
.Power
= 0.0;
571 hr
= IDirect3DDevice9_SetMaterial(device
, &material
);
572 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetMaterial returned %08x\n", hr
);
574 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_DIFFUSEMATERIALSOURCE
, D3DMCS_MATERIAL
);
575 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
576 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SPECULARMATERIALSOURCE
, D3DMCS_MATERIAL
);
577 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
579 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
580 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState returned %08x\n", hr
);
581 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_DIFFUSE
| D3DTA_ALPHAREPLICATE
);
582 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState returned %08x\n", hr
);
584 hr
= IDirect3DDevice9_BeginScene(device
);
585 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
587 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
588 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
589 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, lighting_test
, sizeof(lighting_test
[0]));
590 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
592 hr
= IDirect3DDevice9_EndScene(device
);
593 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
595 color
= getPixelColor(device
, 320, 240);
596 ok(color
== 0x00ffffff, "Lit vertex alpha test returned color %08x, expected 0x00ffffff\n", color
);
597 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
599 refcount
= IDirect3DDevice9_Release(device
);
600 ok(!refcount
, "Device has %u references left.\n", refcount
);
602 IDirect3D9_Release(d3d
);
603 DestroyWindow(window
);
606 static void test_specular_lighting(void)
608 static const unsigned int vertices_side
= 5;
609 const unsigned int indices_count
= (vertices_side
- 1) * (vertices_side
- 1) * 2 * 3;
610 static const DWORD fvf
= D3DFVF_XYZ
| D3DFVF_NORMAL
;
611 static const D3DMATRIX mat
=
613 1.0f
, 0.0f
, 0.0f
, 0.0f
,
614 0.0f
, 1.0f
, 0.0f
, 0.0f
,
615 0.0f
, 0.0f
, 1.0f
, 0.0f
,
616 0.0f
, 0.0f
, 0.0f
, 1.0f
,
618 static const D3DLIGHT9 directional
=
620 D3DLIGHT_DIRECTIONAL
,
621 {0.0f
, 0.0f
, 0.0f
, 0.0f
},
622 {1.0f
, 1.0f
, 1.0f
, 0.0f
},
623 {0.0f
, 0.0f
, 0.0f
, 0.0f
},
630 {0.0f
, 0.0f
, 0.0f
, 0.0f
},
631 {1.0f
, 1.0f
, 1.0f
, 0.0f
},
632 {0.0f
, 0.0f
, 0.0f
, 0.0f
},
642 {0.0f
, 0.0f
, 0.0f
, 0.0f
},
643 {1.0f
, 1.0f
, 1.0f
, 0.0f
},
644 {0.0f
, 0.0f
, 0.0f
, 0.0f
},
650 M_PI
/ 12.0f
, M_PI
/ 3.0f
652 /* The chosen range value makes the test fail when using a manhattan
653 * distance metric vs the correct euclidean distance. */
657 {0.0f
, 0.0f
, 0.0f
, 0.0f
},
658 {1.0f
, 1.0f
, 1.0f
, 0.0f
},
659 {0.0f
, 0.0f
, 0.0f
, 0.0f
},
669 {0.0f
, 0.0f
, 0.0f
, 0.0f
},
670 {1.0f
, 1.0f
, 1.0f
, 0.0f
},
671 {0.0f
, 0.0f
, 0.0f
, 0.0f
},
678 static const struct expected_color
683 expected_directional
[] =
685 {160, 120, 0x00ffffff},
686 {320, 120, 0x00ffffff},
687 {480, 120, 0x00ffffff},
688 {160, 240, 0x00ffffff},
689 {320, 240, 0x00ffffff},
690 {480, 240, 0x00ffffff},
691 {160, 360, 0x00ffffff},
692 {320, 360, 0x00ffffff},
693 {480, 360, 0x00ffffff},
695 expected_directional_local
[] =
697 {160, 120, 0x003c3c3c},
698 {320, 120, 0x00717171},
699 {480, 120, 0x003c3c3c},
700 {160, 240, 0x00717171},
701 {320, 240, 0x00ffffff},
702 {480, 240, 0x00717171},
703 {160, 360, 0x003c3c3c},
704 {320, 360, 0x00717171},
705 {480, 360, 0x003c3c3c},
709 {160, 120, 0x00282828},
710 {320, 120, 0x005a5a5a},
711 {480, 120, 0x00282828},
712 {160, 240, 0x005a5a5a},
713 {320, 240, 0x00ffffff},
714 {480, 240, 0x005a5a5a},
715 {160, 360, 0x00282828},
716 {320, 360, 0x005a5a5a},
717 {480, 360, 0x00282828},
719 expected_point_local
[] =
721 {160, 120, 0x00000000},
722 {320, 120, 0x00070707},
723 {480, 120, 0x00000000},
724 {160, 240, 0x00070707},
725 {320, 240, 0x00ffffff},
726 {480, 240, 0x00070707},
727 {160, 360, 0x00000000},
728 {320, 360, 0x00070707},
729 {480, 360, 0x00000000},
733 {160, 120, 0x00000000},
734 {320, 120, 0x00141414},
735 {480, 120, 0x00000000},
736 {160, 240, 0x00141414},
737 {320, 240, 0x00ffffff},
738 {480, 240, 0x00141414},
739 {160, 360, 0x00000000},
740 {320, 360, 0x00141414},
741 {480, 360, 0x00000000},
743 expected_spot_local
[] =
745 {160, 120, 0x00000000},
746 {320, 120, 0x00020202},
747 {480, 120, 0x00000000},
748 {160, 240, 0x00020202},
749 {320, 240, 0x00ffffff},
750 {480, 240, 0x00020202},
751 {160, 360, 0x00000000},
752 {320, 360, 0x00020202},
753 {480, 360, 0x00000000},
755 expected_point_range
[] =
757 {160, 120, 0x00000000},
758 {320, 120, 0x005a5a5a},
759 {480, 120, 0x00000000},
760 {160, 240, 0x005a5a5a},
761 {320, 240, 0x00ffffff},
762 {480, 240, 0x005a5a5a},
763 {160, 360, 0x00000000},
764 {320, 360, 0x005a5a5a},
765 {480, 360, 0x00000000},
767 expected_point_side
[] =
769 {160, 120, 0x00000000},
770 {320, 120, 0x00000000},
771 {480, 120, 0x00000000},
772 {160, 240, 0x00000000},
773 {320, 240, 0x00000000},
774 {480, 240, 0x00000000},
775 {160, 360, 0x00000000},
776 {320, 360, 0x00000000},
777 {480, 360, 0x00000000},
781 const D3DLIGHT9
*light
;
783 float specular_power
;
784 const struct expected_color
*expected
;
785 unsigned int expected_count
;
789 {&directional
, FALSE
, 30.0f
, expected_directional
, ARRAY_SIZE(expected_directional
)},
790 {&directional
, TRUE
, 30.0f
, expected_directional_local
, ARRAY_SIZE(expected_directional_local
)},
791 {&point
, FALSE
, 30.0f
, expected_point
, ARRAY_SIZE(expected_point
)},
792 {&point
, TRUE
, 30.0f
, expected_point_local
, ARRAY_SIZE(expected_point_local
)},
793 {&spot
, FALSE
, 30.0f
, expected_spot
, ARRAY_SIZE(expected_spot
)},
794 {&spot
, TRUE
, 30.0f
, expected_spot_local
, ARRAY_SIZE(expected_spot_local
)},
795 {&point_range
, FALSE
, 30.0f
, expected_point_range
, ARRAY_SIZE(expected_point_range
)},
796 {&point_side
, TRUE
, 0.0f
, expected_point_side
, ARRAY_SIZE(expected_point_side
)},
798 IDirect3DDevice9
*device
;
799 D3DMATERIAL9 material
;
805 unsigned int i
, j
, x
, y
;
808 struct vec3 position
;
813 quad
= HeapAlloc(GetProcessHeap(), 0, vertices_side
* vertices_side
* sizeof(*quad
));
814 indices
= HeapAlloc(GetProcessHeap(), 0, indices_count
* sizeof(*indices
));
815 for (i
= 0, y
= 0; y
< vertices_side
; ++y
)
817 for (x
= 0; x
< vertices_side
; ++x
)
819 quad
[i
].position
.x
= x
* 2.0f
/ (vertices_side
- 1) - 1.0f
;
820 quad
[i
].position
.y
= y
* 2.0f
/ (vertices_side
- 1) - 1.0f
;
821 quad
[i
].position
.z
= 1.0f
;
822 quad
[i
].normal
.x
= 0.0f
;
823 quad
[i
].normal
.y
= 0.0f
;
824 quad
[i
++].normal
.z
= -1.0f
;
827 for (i
= 0, y
= 0; y
< (vertices_side
- 1); ++y
)
829 for (x
= 0; x
< (vertices_side
- 1); ++x
)
831 indices
[i
++] = y
* vertices_side
+ x
+ 1;
832 indices
[i
++] = y
* vertices_side
+ x
;
833 indices
[i
++] = (y
+ 1) * vertices_side
+ x
;
834 indices
[i
++] = y
* vertices_side
+ x
+ 1;
835 indices
[i
++] = (y
+ 1) * vertices_side
+ x
;
836 indices
[i
++] = (y
+ 1) * vertices_side
+ x
+ 1;
840 window
= create_window();
841 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
842 ok(!!d3d
, "Failed to create a D3D object.\n");
843 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
845 skip("Failed to create a D3D device, skipping tests.\n");
849 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_WORLD
, &mat
);
850 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
851 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_VIEW
, &mat
);
852 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
853 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_PROJECTION
, &mat
);
854 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
855 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CLIPPING
, FALSE
);
856 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
857 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
858 ok(SUCCEEDED(hr
), "Failed to disable z test, hr %#x.\n", hr
);
859 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGENABLE
, FALSE
);
860 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
862 hr
= IDirect3DDevice9_SetFVF(device
, fvf
);
863 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
865 hr
= IDirect3DDevice9_LightEnable(device
, 0, TRUE
);
866 ok(SUCCEEDED(hr
), "Failed to enable light 0, hr %#x.\n", hr
);
867 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SPECULARENABLE
, TRUE
);
868 ok(SUCCEEDED(hr
), "Failed to enable specular lighting, hr %#x.\n", hr
);
870 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
872 hr
= IDirect3DDevice9_SetLight(device
, 0, tests
[i
].light
);
873 ok(SUCCEEDED(hr
), "Failed to set light parameters, hr %#x.\n", hr
);
875 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LOCALVIEWER
, tests
[i
].local_viewer
);
876 ok(SUCCEEDED(hr
), "Failed to set local viewer state, hr %#x.\n", hr
);
878 memset(&material
, 0, sizeof(material
));
879 material
.Specular
.r
= 1.0f
;
880 material
.Specular
.g
= 1.0f
;
881 material
.Specular
.b
= 1.0f
;
882 material
.Specular
.a
= 1.0f
;
883 material
.Power
= tests
[i
].specular_power
;
884 hr
= IDirect3DDevice9_SetMaterial(device
, &material
);
885 ok(SUCCEEDED(hr
), "Failed to set material, hr %#x.\n", hr
);
887 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0, 0);
888 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
890 hr
= IDirect3DDevice9_BeginScene(device
);
891 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
893 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
,
894 0, vertices_side
* vertices_side
, indices_count
/ 3, indices
,
895 D3DFMT_INDEX16
, quad
, sizeof(quad
[0]));
896 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
898 hr
= IDirect3DDevice9_EndScene(device
);
899 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
901 for (j
= 0; j
< tests
[i
].expected_count
; ++j
)
903 color
= getPixelColor(device
, tests
[i
].expected
[j
].x
, tests
[i
].expected
[j
].y
);
904 ok(color_match(color
, tests
[i
].expected
[j
].color
, 1),
905 "Expected color 0x%08x at location (%u, %u), got 0x%08x, case %u.\n",
906 tests
[i
].expected
[j
].color
, tests
[i
].expected
[j
].x
,
907 tests
[i
].expected
[j
].y
, color
, i
);
911 refcount
= IDirect3DDevice9_Release(device
);
912 ok(!refcount
, "Device has %u references left.\n", refcount
);
914 IDirect3D9_Release(d3d
);
915 DestroyWindow(window
);
916 HeapFree(GetProcessHeap(), 0, indices
);
917 HeapFree(GetProcessHeap(), 0, quad
);
920 static void clear_test(void)
922 static const D3DMATRIX mat
=
924 1.0f
, 0.0f
, 0.0f
, 0.0f
,
925 0.0f
, 1.0f
, 0.0f
, 0.0f
,
926 0.0f
, 0.0f
, 1.0f
, 0.0f
,
927 0.0f
, 0.0f
, 0.0f
, 1.0f
,
931 struct vec3 position
;
936 {{-1.0f
, -1.0f
, 0.1f
}, 0xff7f7f7f},
937 {{ 1.0f
, -1.0f
, 0.1f
}, 0xff7f7f7f},
938 {{-1.0f
, 1.0f
, 0.1f
}, 0xff7f7f7f},
939 {{ 1.0f
, 1.0f
, 0.1f
}, 0xff7f7f7f},
941 IDirect3DSurface9
*surface0
, *surface1
, *backbuffer
;
942 IDirect3DTexture9
*texture
;
947 D3DVIEWPORT9 old_vp
, vp
;
950 BOOL invalid_clear_failed
= FALSE
, srgb_supported
;
951 IDirect3DDevice9
*device
;
956 window
= create_window();
957 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
958 ok(!!d3d
, "Failed to create a D3D object.\n");
959 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
961 skip("Failed to create a D3D device, skipping tests.\n");
965 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
966 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
968 /* Positive x, negative y */
974 /* Positive x, positive y */
979 /* Clear 2 rectangles with one call. The refrast returns an error in this case, every real driver tested so far
980 * returns D3D_OK, but ignores the rectangle silently
982 hr
= IDirect3DDevice9_Clear(device
, 2, rect
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
983 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
984 if(hr
== D3DERR_INVALIDCALL
) invalid_clear_failed
= TRUE
;
986 /* negative x, negative y */
987 rect_negneg
.x1
= 640;
988 rect_negneg
.y1
= 240;
989 rect_negneg
.x2
= 320;
991 hr
= IDirect3DDevice9_Clear(device
, 1, &rect_negneg
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0, 0);
992 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
993 if(hr
== D3DERR_INVALIDCALL
) invalid_clear_failed
= TRUE
;
995 color
= getPixelColor(device
, 160, 360); /* lower left quad */
996 ok(color
== 0x00ffffff, "Clear rectangle 3(pos, neg) has color %08x\n", color
);
997 color
= getPixelColor(device
, 160, 120); /* upper left quad */
998 if(invalid_clear_failed
) {
999 /* If the negative rectangle was refused, the other rectangles in the list shouldn't be cleared either */
1000 ok(color
== 0x00ffffff, "Clear rectangle 1(pos, pos) has color %08x\n", color
);
1002 /* If the negative rectangle was dropped silently, the correct ones are cleared */
1003 ok(color
== 0x00ff0000, "Clear rectangle 1(pos, pos) has color %08x\n", color
);
1005 color
= getPixelColor(device
, 480, 360); /* lower right quad */
1006 ok(color
== 0x00ffffff, "Clear rectangle 4(NULL) has color %08x\n", color
);
1007 color
= getPixelColor(device
, 480, 120); /* upper right quad */
1008 ok(color
== 0x00ffffff, "Clear rectangle 4(neg, neg) has color %08x\n", color
);
1010 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
1012 /* Hack to work around a nvidia windows driver bug. The clear below is supposed to
1013 * clear the red quad in the top left part of the render target. For some reason it
1014 * doesn't work if the clear color is 0xffffffff on some versions of the Nvidia Windows
1015 * driver(tested on 8.17.12.5896, Win7). A clear with a different color works around
1016 * this bug and fixes the clear with the white color. Even 0xfeffffff works, but let's
1017 * pick some obvious value
1019 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xdeadbabe, 0.0, 0);
1020 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1022 /* Test how the viewport affects clears */
1023 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
1024 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1025 hr
= IDirect3DDevice9_GetViewport(device
, &old_vp
);
1026 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetViewport failed with %08x\n", hr
);
1034 hr
= IDirect3DDevice9_SetViewport(device
, &vp
);
1035 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetViewport failed with %08x\n", hr
);
1036 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff0000ff, 0.0, 0);
1037 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1045 hr
= IDirect3DDevice9_SetViewport(device
, &vp
);
1046 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetViewport failed with %08x\n", hr
);
1051 hr
= IDirect3DDevice9_Clear(device
, 1, &rect
[0], D3DCLEAR_TARGET
, 0xff00ff00, 0.0, 0);
1052 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1054 hr
= IDirect3DDevice9_SetViewport(device
, &old_vp
);
1055 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetViewport failed with %08x\n", hr
);
1057 color
= getPixelColor(device
, 158, 118);
1058 ok(color
== 0x00ffffff, "(158,118) has color %08x\n", color
);
1059 color
= getPixelColor(device
, 162, 118);
1060 ok(color
== 0x00ffffff, "(162,118) has color %08x\n", color
);
1061 color
= getPixelColor(device
, 158, 122);
1062 ok(color
== 0x00ffffff, "(158,122) has color %08x\n", color
);
1063 color
= getPixelColor(device
, 162, 122);
1064 ok(color
== 0x000000ff, "(162,122) has color %08x\n", color
);
1066 color
= getPixelColor(device
, 318, 238);
1067 ok(color
== 0x000000ff, "(318,238) has color %08x\n", color
);
1068 color
= getPixelColor(device
, 322, 238);
1069 ok(color
== 0x00ffffff, "(322,328) has color %08x\n", color
);
1070 color
= getPixelColor(device
, 318, 242);
1071 ok(color
== 0x00ffffff, "(318,242) has color %08x\n", color
);
1072 color
= getPixelColor(device
, 322, 242);
1073 ok(color
== 0x0000ff00, "(322,242) has color %08x\n", color
);
1075 color
= getPixelColor(device
, 478, 358);
1076 ok(color
== 0x0000ff00, "(478,358 has color %08x\n", color
);
1077 color
= getPixelColor(device
, 482, 358);
1078 ok(color
== 0x00ffffff, "(482,358) has color %08x\n", color
);
1079 color
= getPixelColor(device
, 478, 362);
1080 ok(color
== 0x00ffffff, "(478,362) has color %08x\n", color
);
1081 color
= getPixelColor(device
, 482, 362);
1082 ok(color
== 0x00ffffff, "(482,362) has color %08x\n", color
);
1084 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
1086 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
1087 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1089 SetRect(&scissor
, 160, 120, 480, 360);
1090 hr
= IDirect3DDevice9_SetScissorRect(device
, &scissor
);
1091 ok(hr
== D3D_OK
, "IDirect3DDevice_SetScissorRect failed with %08x\n", hr
);
1092 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SCISSORTESTENABLE
, TRUE
);
1093 ok(hr
== D3D_OK
, "IDirect3DDevice_SetScissorRect failed with %08x\n", hr
);
1095 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0, 0);
1096 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1097 hr
= IDirect3DDevice9_Clear(device
, 1, &rect
[1], D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
1098 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1100 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SCISSORTESTENABLE
, FALSE
);
1101 ok(hr
== D3D_OK
, "IDirect3DDevice_SetScissorRect failed with %08x\n", hr
);
1103 color
= getPixelColor(device
, 158, 118);
1104 ok(color
== 0x00ffffff, "Pixel 158/118 has color %08x\n", color
);
1105 color
= getPixelColor(device
, 162, 118);
1106 ok(color
== 0x00ffffff, "Pixel 162/118 has color %08x\n", color
);
1107 color
= getPixelColor(device
, 158, 122);
1108 ok(color
== 0x00ffffff, "Pixel 158/122 has color %08x\n", color
);
1109 color
= getPixelColor(device
, 162, 122);
1110 ok(color
== 0x00ff0000, "Pixel 162/122 has color %08x\n", color
);
1112 color
= getPixelColor(device
, 158, 358);
1113 ok(color
== 0x00ffffff, "Pixel 158/358 has color %08x\n", color
);
1114 color
= getPixelColor(device
, 162, 358);
1115 ok(color
== 0x0000ff00, "Pixel 162/358 has color %08x\n", color
);
1116 color
= getPixelColor(device
, 158, 358);
1117 ok(color
== 0x00ffffff, "Pixel 158/358 has color %08x\n", color
);
1118 color
= getPixelColor(device
, 162, 362);
1119 ok(color
== 0x00ffffff, "Pixel 162/362 has color %08x\n", color
);
1121 color
= getPixelColor(device
, 478, 118);
1122 ok(color
== 0x00ffffff, "Pixel 158/118 has color %08x\n", color
);
1123 color
= getPixelColor(device
, 478, 122);
1124 ok(color
== 0x0000ff00, "Pixel 162/118 has color %08x\n", color
);
1125 color
= getPixelColor(device
, 482, 122);
1126 ok(color
== 0x00ffffff, "Pixel 158/122 has color %08x\n", color
);
1127 color
= getPixelColor(device
, 482, 358);
1128 ok(color
== 0x00ffffff, "Pixel 162/122 has color %08x\n", color
);
1130 color
= getPixelColor(device
, 478, 358);
1131 ok(color
== 0x0000ff00, "Pixel 478/358 has color %08x\n", color
);
1132 color
= getPixelColor(device
, 478, 362);
1133 ok(color
== 0x00ffffff, "Pixel 478/118 has color %08x\n", color
);
1134 color
= getPixelColor(device
, 482, 358);
1135 ok(color
== 0x00ffffff, "Pixel 482/122 has color %08x\n", color
);
1136 color
= getPixelColor(device
, 482, 362);
1137 ok(color
== 0x00ffffff, "Pixel 482/122 has color %08x\n", color
);
1139 color
= getPixelColor(device
, 318, 238);
1140 ok(color
== 0x00ff0000, "Pixel 318/238 has color %08x\n", color
);
1141 color
= getPixelColor(device
, 318, 242);
1142 ok(color
== 0x0000ff00, "Pixel 318/242 has color %08x\n", color
);
1143 color
= getPixelColor(device
, 322, 238);
1144 ok(color
== 0x0000ff00, "Pixel 322/238 has color %08x\n", color
);
1145 color
= getPixelColor(device
, 322, 242);
1146 ok(color
== 0x0000ff00, "Pixel 322/242 has color %08x\n", color
);
1148 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
1150 hr
= IDirect3DDevice9_GetRenderState(device
, D3DRS_COLORWRITEENABLE
, &oldColorWrite
);
1151 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr
);
1152 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_COLORWRITEENABLE
, D3DCOLORWRITEENABLE_RED
);
1153 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed with %08x\n", hr
);
1155 /* Same nvidia windows driver trouble with white clears as earlier in the same test */
1156 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xdeadbeef, 0.0, 0);
1157 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1159 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
1160 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1162 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_COLORWRITEENABLE
, oldColorWrite
);
1163 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed with %08x\n", hr
);
1165 /* Colorwriteenable does not affect the clear */
1166 color
= getPixelColor(device
, 320, 240);
1167 ok(color
== 0x00ffffff, "Color write protected clear returned color %08x\n", color
);
1169 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
1171 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00ffffff, 0.0, 0);
1172 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1178 hr
= IDirect3DDevice9_Clear(device
, 0, rect
, D3DCLEAR_TARGET
, 0x00ff0000, 0.0, 0);
1179 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1181 color
= getPixelColor(device
, 320, 240);
1182 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0xff), 1),
1183 "Clear with count = 0, rect != NULL has color %08x\n", color
);
1185 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
1187 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
1188 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1189 hr
= IDirect3DDevice9_Clear(device
, 1, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0, 0);
1190 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1192 color
= getPixelColor(device
, 320, 240);
1193 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1),
1194 "Clear with count = 1, rect = NULL has color %08x\n", color
);
1196 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
1198 /* Test D3DRS_SRGBWRITEENABLE interactions with clears. */
1199 srgb_supported
= SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
1200 D3DUSAGE_QUERY_SRGBWRITE
, D3DRTYPE_TEXTURE
, D3DFMT_A8R8G8B8
));
1201 trace("sRGB writing to D3DFMT_A8R8G8B8 is %ssupported.\n", srgb_supported
? "" : "not ");
1202 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x7f7f7f7f, 0.0, 0);
1203 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
1205 color
= getPixelColor(device
, 320, 240);
1206 ok(color_match(color
, 0x007f7f7f, 1), "Clear has color %08x.\n", color
);
1208 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SRGBWRITEENABLE
, TRUE
);
1209 ok(SUCCEEDED(hr
), "Failed to enable sRGB write, hr %#x.\n", hr
);
1211 /* Draw something to make sure the SRGBWRITEENABLE setting is applied. */
1212 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_WORLD
, &mat
);
1213 ok(SUCCEEDED(hr
), "Failed to set world matrix, hr %#x.\n", hr
);
1214 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CLIPPING
, FALSE
);
1215 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
1216 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
1217 ok(SUCCEEDED(hr
), "Failed to disable z test, hr %#x.\n", hr
);
1218 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGENABLE
, FALSE
);
1219 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
1220 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILENABLE
, FALSE
);
1221 ok(SUCCEEDED(hr
), "Failed to disable stencil test, hr %#x.\n", hr
);
1222 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CULLMODE
, D3DCULL_NONE
);
1223 ok(SUCCEEDED(hr
), "Failed to disable culling, hr %#x.\n", hr
);
1224 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
1225 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
1226 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
1227 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
1228 hr
= IDirect3DDevice9_BeginScene(device
);
1229 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1230 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(quad
));
1231 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1232 hr
= IDirect3DDevice9_EndScene(device
);
1233 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1235 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x7f7f7f7f, 0.0, 0);
1236 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
1238 color
= getPixelColor(device
, 320, 240);
1239 ok(color_match(color
, 0x00bbbbbb, 1), "Clear has color %08x.\n", color
);
1241 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SRGBWRITEENABLE
, FALSE
);
1242 ok(SUCCEEDED(hr
), "Failed to disable sRGB write, hr %#x.\n", hr
);
1244 /* Switching to a new render target seems to be enough to make Windows pick
1245 * up on the changed render state. */
1246 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 2, D3DUSAGE_RENDERTARGET
,
1247 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &texture
, NULL
);
1248 ok(SUCCEEDED(hr
), "Failed to create the offscreen render target, hr %#x.\n", hr
);
1249 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
1250 ok(SUCCEEDED(hr
), "Failed to get backbuffer, hr %#x.\n", hr
);
1251 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface0
);
1252 ok(SUCCEEDED(hr
), "Failed to get offscreen surface, hr %#x.\n", hr
);
1253 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, surface0
);
1254 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
1256 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x7f7f7f7f, 0.0, 0);
1257 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
1259 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
1260 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
1262 hr
= IDirect3DDevice9_StretchRect(device
, surface0
, NULL
, backbuffer
, NULL
, D3DTEXF_NONE
);
1263 ok(SUCCEEDED(hr
), "Failed to blit surface, hr %#x.\n", hr
);
1265 color
= getPixelColor(device
, 64, 64);
1266 ok(color_match(color
, 0x007f7f7f, 1), "Clear has color %08x.\n", color
);
1268 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SRGBWRITEENABLE
, TRUE
);
1269 ok(SUCCEEDED(hr
), "Failed to enable sRGB write, hr %#x.\n", hr
);
1271 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, surface0
);
1272 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
1274 hr
= IDirect3DDevice9_BeginScene(device
);
1275 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1276 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(quad
));
1277 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1278 hr
= IDirect3DDevice9_EndScene(device
);
1279 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1281 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x7f7f7f7f, 0.0, 0);
1282 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
1284 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
1285 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
1287 hr
= IDirect3DDevice9_StretchRect(device
, surface0
, NULL
, backbuffer
, NULL
, D3DTEXF_NONE
);
1288 ok(SUCCEEDED(hr
), "Failed to blit surface, hr %#x.\n", hr
);
1290 color
= getPixelColor(device
, 320, 240);
1291 ok(color_match(color
, 0x00bbbbbb, 1), "Clear has color %08x.\n", color
);
1293 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SRGBWRITEENABLE
, FALSE
);
1294 ok(SUCCEEDED(hr
), "Failed to disable sRGB write, hr %#x.\n", hr
);
1295 /* Switching to another surface of the same texture is also enough to make
1296 * the setting "stick". */
1297 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 1, &surface1
);
1298 ok(SUCCEEDED(hr
), "Failed to get offscreen surface, hr %#x.\n", hr
);
1299 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, surface1
);
1300 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
1302 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x7f7f7f7f, 0.0, 0);
1303 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x\n", hr
);
1305 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
1306 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
1308 hr
= IDirect3DDevice9_StretchRect(device
, surface1
, NULL
, backbuffer
, NULL
, D3DTEXF_NONE
);
1309 ok(SUCCEEDED(hr
), "Failed to blit surface, hr %#x.\n", hr
);
1311 color
= getPixelColor(device
, 320, 240);
1312 ok(color_match(color
, 0x007f7f7f, 1), "Clear has color %08x.\n", color
);
1314 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
1316 IDirect3DSurface9_Release(surface1
);
1317 IDirect3DSurface9_Release(surface0
);
1318 IDirect3DSurface9_Release(backbuffer
);
1319 IDirect3DTexture9_Release(texture
);
1320 refcount
= IDirect3DDevice9_Release(device
);
1321 ok(!refcount
, "Device has %u references left.\n", refcount
);
1323 IDirect3D9_Release(d3d
);
1324 DestroyWindow(window
);
1327 static void color_fill_test(void)
1329 IDirect3DSurface9
*surface
;
1330 IDirect3DTexture9
*texture
;
1331 D3DCOLOR fill_color
, color
;
1332 DWORD fill_a
, expected_a
;
1333 IDirect3DDevice9
*device
;
1346 {D3DPOOL_DEFAULT
, 0, D3DERR_INVALIDCALL
},
1347 {D3DPOOL_DEFAULT
, D3DUSAGE_DYNAMIC
, D3DERR_INVALIDCALL
},
1348 {D3DPOOL_DEFAULT
, D3DUSAGE_RENDERTARGET
, D3D_OK
},
1349 {D3DPOOL_SYSTEMMEM
, 0, D3DERR_INVALIDCALL
},
1350 {D3DPOOL_MANAGED
, 0, D3DERR_INVALIDCALL
},
1351 {D3DPOOL_SCRATCH
, 0, D3DERR_INVALIDCALL
},
1359 CHECK_FILL_VALUE
= 0x1,
1366 {D3DFMT_A8R8G8B8
, "D3DFMT_A8R8G8B8", CHECK_FILL_VALUE
, 0xdeadbeef},
1367 /* D3DFMT_X8R8G8B8 either set X = A or X = 0, depending on the driver. */
1368 {D3DFMT_R5G6B5
, "D3DFMT_R5G6B5", CHECK_FILL_VALUE
, 0xadfdadfd},
1369 {D3DFMT_G16R16
, "D3DFMT_G16R16", CHECK_FILL_VALUE
, 0xbebeadad},
1370 /* Real hardware reliably fills the surface with the blue channel but
1371 * the testbot fills it with 0x00. Wine incorrectly uses the alpha
1372 * channel. Don't bother checking the result because P8 surfaces are
1373 * essentially useless in d3d9. */
1374 {D3DFMT_P8
, "D3DFMT_P8", 0, 0xefefefef},
1375 /* Windows drivers produce different results for these formats.
1376 * No driver produces a YUV value that matches the input RGB
1377 * value, and no driver produces a proper DXT compression block.
1379 * Even the clear value 0 does not reliably produce a fill value
1380 * that will return vec4(0.0, 0.0, 0.0, 0.0) when sampled.
1382 * The YUV tests are disabled because they produce a driver-dependent
1384 * {D3DFMT_YUY2, "D3DFMT_YUY2", BLOCKS, 0},
1385 * {D3DFMT_UYVY, "D3DFMT_UYVY", BLOCKS, 0}, */
1386 {D3DFMT_DXT1
, "D3DFMT_DXT1", BLOCKS
, 0x00000000},
1387 /* Vendor-specific formats like ATI2N are a non-issue here since they're not
1388 * supported as offscreen plain surfaces and do not support D3DUSAGE_RENDERTARGET
1389 * when created as texture. */
1392 D3DLOCKED_RECT locked_rect
;
1393 DWORD
*surface_data
;
1394 static const RECT rect
= {4, 4, 8, 8}, rect2
= {5, 5, 7, 7};
1396 window
= create_window();
1397 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
1398 ok(!!d3d
, "Failed to create a D3D object.\n");
1399 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
1401 skip("Failed to create a D3D device, skipping tests.\n");
1405 /* Test ColorFill on a the backbuffer (should pass) */
1406 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &surface
);
1407 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %08x\n", hr
);
1409 fill_color
= 0x112233;
1410 hr
= IDirect3DDevice9_ColorFill(device
, surface
, NULL
, fill_color
);
1411 ok(SUCCEEDED(hr
), "Color fill failed, hr %#x.\n", hr
);
1413 color
= getPixelColor(device
, 0, 0);
1414 ok(color
== fill_color
, "Expected color %08x, got %08x\n", fill_color
, color
);
1416 IDirect3DSurface9_Release(surface
);
1418 /* Test ColorFill on a render target surface (should pass) */
1419 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 32, 32, D3DFMT_A8R8G8B8
,
1420 D3DMULTISAMPLE_NONE
, 0, TRUE
, &surface
, NULL
);
1421 ok(hr
== D3D_OK
, "Unable to create render target surface, hr = %08x\n", hr
);
1423 fill_color
= 0x445566;
1424 hr
= IDirect3DDevice9_ColorFill(device
, surface
, NULL
, fill_color
);
1425 ok(SUCCEEDED(hr
), "Color fill failed, hr %#x.\n", hr
);
1427 color
= getPixelColorFromSurface(surface
, 0, 0);
1428 ok(color
== fill_color
, "Expected color %08x, got %08x\n", fill_color
, color
);
1430 IDirect3DSurface9_Release(surface
);
1432 /* Test ColorFill on an offscreen plain surface in D3DPOOL_DEFAULT (should pass) */
1433 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 32, 32,
1434 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &surface
, NULL
);
1435 ok(hr
== D3D_OK
, "Unable to create offscreen plain surface, hr = %08x\n", hr
);
1437 fill_color
= 0x778899;
1438 hr
= IDirect3DDevice9_ColorFill(device
, surface
, NULL
, fill_color
);
1439 ok(SUCCEEDED(hr
), "Color fill failed, hr %#x.\n", hr
);
1441 color
= getPixelColorFromSurface(surface
, 0, 0);
1442 ok(color
== fill_color
, "Expected color %08x, got %08x\n", fill_color
, color
);
1444 IDirect3DSurface9_Release(surface
);
1446 /* Try ColorFill on an offscreen surface in sysmem (should fail) */
1447 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 32, 32,
1448 D3DFMT_A8R8G8B8
, D3DPOOL_SYSTEMMEM
, &surface
, NULL
);
1449 ok(hr
== D3D_OK
, "Unable to create offscreen plain surface, hr = %08x\n", hr
);
1451 hr
= IDirect3DDevice9_ColorFill(device
, surface
, NULL
, 0);
1452 ok(hr
== D3DERR_INVALIDCALL
, "ColorFill on offscreen sysmem surface failed with hr = %08x\n", hr
);
1454 IDirect3DSurface9_Release(surface
);
1456 hr
= IDirect3DDevice9_CreateDepthStencilSurface(device
, 32, 32, D3DFMT_D16
,
1457 D3DMULTISAMPLE_NONE
, 0, TRUE
, &surface
, NULL
);
1458 ok(SUCCEEDED(hr
), "Failed to create depth stencil surface, hr = %08x.\n", hr
);
1460 hr
= IDirect3DDevice9_ColorFill(device
, surface
, NULL
, 0);
1461 ok(hr
== D3DERR_INVALIDCALL
, "ColorFill on a depth stencil surface returned hr = %08x.\n", hr
);
1463 IDirect3DSurface9_Release(surface
);
1465 for (i
= 0; i
< ARRAY_SIZE(resource_types
); i
++)
1468 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, resource_types
[i
].usage
,
1469 D3DFMT_A8R8G8B8
, resource_types
[i
].pool
, &texture
, NULL
);
1470 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x, i=%u.\n", hr
, i
);
1471 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1472 ok(SUCCEEDED(hr
), "Failed to get surface, hr %#x, i=%u.\n", hr
, i
);
1474 hr
= IDirect3DDevice9_ColorFill(device
, surface
, NULL
, fill_color
);
1475 ok(hr
== resource_types
[i
].hr
, "Got unexpected hr %#x, expected %#x, i=%u.\n",
1476 hr
, resource_types
[i
].hr
, i
);
1478 IDirect3DSurface9_Release(surface
);
1479 IDirect3DTexture9_Release(texture
);
1482 for (i
= 0; i
< ARRAY_SIZE(formats
); i
++)
1484 if (IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
,
1485 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_SURFACE
, formats
[i
].format
) != D3D_OK
)
1487 skip("Offscreenplain %s surfaces not supported, skipping colorfill test\n", formats
[i
].name
);
1491 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 32, 32,
1492 formats
[i
].format
, D3DPOOL_DEFAULT
, &surface
, NULL
);
1493 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, fmt=%s.\n", hr
, formats
[i
].name
);
1495 hr
= IDirect3DDevice9_ColorFill(device
, surface
, NULL
, 0xdeadbeef);
1496 ok(SUCCEEDED(hr
), "Failed to color fill, hr %#x, fmt=%s.\n", hr
, formats
[i
].name
);
1498 hr
= IDirect3DDevice9_ColorFill(device
, surface
, &rect
, 0xdeadbeef);
1499 ok(SUCCEEDED(hr
), "Failed to color fill, hr %#x, fmt=%s.\n", hr
, formats
[i
].name
);
1503 hr
= IDirect3DDevice9_ColorFill(device
, surface
, &rect2
, 0xdeadbeef);
1504 if (formats
[i
].flags
& BLOCKS
)
1505 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, fmt=%s.\n", hr
, formats
[i
].name
);
1507 ok(SUCCEEDED(hr
), "Failed to color fill, hr %#x, fmt=%s.\n", hr
, formats
[i
].name
);
1510 if (formats
[i
].flags
& CHECK_FILL_VALUE
)
1512 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, NULL
, D3DLOCK_READONLY
);
1513 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, fmt=%s.\n", hr
, formats
[i
].name
);
1514 surface_data
= locked_rect
.pBits
;
1515 fill_a
= (surface_data
[0] & 0xff000000) >> 24;
1516 expected_a
= (formats
[i
].fill_value
& 0xff000000) >> 24;
1517 /* Windows drivers disagree on how to promote the 8 bit per channel
1518 * input argument to 16 bit for D3DFMT_G16R16. */
1519 ok(color_match(surface_data
[0], formats
[i
].fill_value
, 2) &&
1520 abs((expected_a
) - (fill_a
)) < 3,
1521 "Expected clear value 0x%08x, got 0x%08x, fmt=%s.\n",
1522 formats
[i
].fill_value
, surface_data
[0], formats
[i
].name
);
1523 hr
= IDirect3DSurface9_UnlockRect(surface
);
1524 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, fmt=%s.\n", hr
, formats
[i
].name
);
1527 IDirect3DSurface9_Release(surface
);
1530 refcount
= IDirect3DDevice9_Release(device
);
1531 ok(!refcount
, "Device has %u references left.\n", refcount
);
1533 IDirect3D9_Release(d3d
);
1534 DestroyWindow(window
);
1538 * c7 mova ARGB mov ARGB
1539 * -2.4 -2 0x00ffff00 -3 0x00ff0000
1540 * -1.6 -2 0x00ffff00 -2 0x00ffff00
1541 * -0.4 0 0x0000ffff -1 0x0000ff00
1542 * 0.4 0 0x0000ffff 0 0x0000ffff
1543 * 1.6 2 0x00ff00ff 1 0x000000ff
1544 * 2.4 2 0x00ff00ff 2 0x00ff00ff
1546 static void test_mova(void)
1548 IDirect3DVertexDeclaration9
*vertex_declaration
;
1549 IDirect3DVertexShader9
*mova_shader
;
1550 IDirect3DVertexShader9
*mov_shader
;
1551 IDirect3DDevice9
*device
;
1559 static const DWORD mova_test
[] =
1561 0xfffe0200, /* vs_2_0 */
1562 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
1563 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 1.0, 0.0, 0.0, 1.0 */
1564 0x05000051, 0xa00f0001, 0x3f800000, 0x3f800000, 0x00000000, 0x3f800000, /* def c1, 1.0, 1.0, 0.0, 1.0 */
1565 0x05000051, 0xa00f0002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, /* def c2, 0.0, 1.0, 0.0, 1.0 */
1566 0x05000051, 0xa00f0003, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c3, 0.0, 1.0, 1.0, 1.0 */
1567 0x05000051, 0xa00f0004, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, /* def c4, 0.0, 0.0, 1.0, 1.0 */
1568 0x05000051, 0xa00f0005, 0x3f800000, 0x00000000, 0x3f800000, 0x3f800000, /* def c5, 1.0, 0.0, 1.0, 1.0 */
1569 0x05000051, 0xa00f0006, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c6, 1.0, 1.0, 1.0, 1.0 */
1570 0x0200002e, 0xb0010000, 0xa0000007, /* mova a0.x, c7.x */
1571 0x03000001, 0xd00f0000, 0xa0e42003, 0xb0000000, /* mov oD0, c[a0.x + 3] */
1572 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
1573 0x0000ffff /* END */
1575 static const DWORD mov_test
[] =
1577 0xfffe0101, /* vs_1_1 */
1578 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
1579 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 1.0, 0.0, 0.0, 1.0 */
1580 0x00000051, 0xa00f0001, 0x3f800000, 0x3f800000, 0x00000000, 0x3f800000, /* def c1, 1.0, 1.0, 0.0, 1.0 */
1581 0x00000051, 0xa00f0002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, /* def c2, 0.0, 1.0, 0.0, 1.0 */
1582 0x00000051, 0xa00f0003, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c3, 0.0, 1.0, 1.0, 1.0 */
1583 0x00000051, 0xa00f0004, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, /* def c4, 0.0, 0.0, 1.0, 1.0 */
1584 0x00000051, 0xa00f0005, 0x3f800000, 0x00000000, 0x3f800000, 0x3f800000, /* def c5, 1.0, 0.0, 1.0, 1.0 */
1585 0x00000051, 0xa00f0006, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c6, 1.0, 1.0, 1.0, 1.0 */
1586 0x00000001, 0xb0010000, 0xa0000007, /* mov a0.x, c7.x */
1587 0x00000001, 0xd00f0000, 0xa0e42003, /* mov oD0, c[a0.x + 3] */
1588 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
1589 0x0000ffff /* END */
1599 {{-2.4f
, 0.0f
, 0.0f
, 0.0f
}, 0x00ff0000},
1600 {{-1.6f
, 0.0f
, 0.0f
, 0.0f
}, 0x00ffff00},
1601 {{-0.4f
, 0.0f
, 0.0f
, 0.0f
}, 0x0000ff00},
1602 {{ 0.4f
, 0.0f
, 0.0f
, 0.0f
}, 0x0000ffff},
1603 {{ 1.6f
, 0.0f
, 0.0f
, 0.0f
}, 0x000000ff},
1604 {{ 2.4f
, 0.0f
, 0.0f
, 0.0f
}, 0x00ff00ff}
1607 {{-2.4f
, 0.0f
, 0.0f
, 0.0f
}, 0x00ffff00},
1608 {{-1.6f
, 0.0f
, 0.0f
, 0.0f
}, 0x00ffff00},
1609 {{-0.4f
, 0.0f
, 0.0f
, 0.0f
}, 0x0000ffff},
1610 {{ 0.4f
, 0.0f
, 0.0f
, 0.0f
}, 0x0000ffff},
1611 {{ 1.6f
, 0.0f
, 0.0f
, 0.0f
}, 0x00ff00ff},
1612 {{ 2.4f
, 0.0f
, 0.0f
, 0.0f
}, 0x00ff00ff}
1615 static const struct vec3 quad
[] =
1617 {-1.0f
, -1.0f
, 0.0f
},
1618 {-1.0f
, 1.0f
, 0.0f
},
1619 { 1.0f
, -1.0f
, 0.0f
},
1620 { 1.0f
, 1.0f
, 0.0f
},
1622 static const D3DVERTEXELEMENT9 decl_elements
[] =
1624 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
1628 window
= create_window();
1629 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
1630 ok(!!d3d
, "Failed to create a D3D object.\n");
1631 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
1633 skip("Failed to create a D3D device, skipping tests.\n");
1637 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
1638 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
1639 if (caps
.VertexShaderVersion
< D3DVS_VERSION(2, 0))
1641 skip("No vs_2_0 support, skipping tests.\n");
1642 IDirect3DDevice9_Release(device
);
1646 hr
= IDirect3DDevice9_CreateVertexShader(device
, mova_test
, &mova_shader
);
1647 ok(SUCCEEDED(hr
), "CreateVertexShader failed (%08x)\n", hr
);
1648 hr
= IDirect3DDevice9_CreateVertexShader(device
, mov_test
, &mov_shader
);
1649 ok(SUCCEEDED(hr
), "CreateVertexShader failed (%08x)\n", hr
);
1650 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &vertex_declaration
);
1651 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (%08x)\n", hr
);
1652 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, vertex_declaration
);
1653 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed (%08x)\n", hr
);
1655 hr
= IDirect3DDevice9_SetVertexShader(device
, mov_shader
);
1656 ok(SUCCEEDED(hr
), "SetVertexShader failed (%08x)\n", hr
);
1657 for (j
= 0; j
< ARRAY_SIZE(test_data
); ++j
)
1659 for (i
= 0; i
< ARRAY_SIZE(*test_data
); ++i
)
1663 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 7, test_data
[j
][i
].in
, 1);
1664 ok(SUCCEEDED(hr
), "SetVertexShaderConstantF failed (%08x)\n", hr
);
1666 hr
= IDirect3DDevice9_BeginScene(device
);
1667 ok(SUCCEEDED(hr
), "BeginScene failed (%08x)\n", hr
);
1669 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
1670 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
1672 hr
= IDirect3DDevice9_EndScene(device
);
1673 ok(SUCCEEDED(hr
), "EndScene failed (%08x)\n", hr
);
1675 color
= getPixelColor(device
, 320, 240);
1676 ok(color
== test_data
[j
][i
].out
, "Expected color %08x, got %08x (for input %f, instruction %s)\n",
1677 test_data
[j
][i
].out
, color
, test_data
[j
][i
].in
[0], j
== 0 ? "mov" : "mova");
1679 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
1680 ok(SUCCEEDED(hr
), "Present failed (%08x)\n", hr
);
1682 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0, 0.0f
, 0);
1683 ok(SUCCEEDED(hr
), "Clear failed (%08x)\n", hr
);
1685 hr
= IDirect3DDevice9_SetVertexShader(device
, mova_shader
);
1686 ok(SUCCEEDED(hr
), "SetVertexShader failed (%08x)\n", hr
);
1689 IDirect3DVertexDeclaration9_Release(vertex_declaration
);
1690 IDirect3DVertexShader9_Release(mova_shader
);
1691 IDirect3DVertexShader9_Release(mov_shader
);
1692 refcount
= IDirect3DDevice9_Release(device
);
1693 ok(!refcount
, "Device has %u references left.\n", refcount
);
1695 IDirect3D9_Release(d3d
);
1696 DestroyWindow(window
);
1699 static void fog_test(void)
1701 float start
= 0.0f
, end
= 1.0f
;
1702 IDirect3DDevice9
*device
;
1711 /* Gets full z based fog with linear fog, no fog with specular color. */
1720 {-1.0f
, -1.0f
, 0.1f
, 0xffff0000, 0xff000000},
1721 {-1.0f
, 0.0f
, 0.1f
, 0xffff0000, 0xff000000},
1722 { 0.0f
, 0.0f
, 0.1f
, 0xffff0000, 0xff000000},
1723 { 0.0f
, -1.0f
, 0.1f
, 0xffff0000, 0xff000000},
1725 /* Ok, I am too lazy to deal with transform matrices. */
1728 {-1.0f
, 0.0f
, 1.0f
, 0xffff0000, 0xff000000},
1729 {-1.0f
, 1.0f
, 1.0f
, 0xffff0000, 0xff000000},
1730 { 0.0f
, 1.0f
, 1.0f
, 0xffff0000, 0xff000000},
1731 { 0.0f
, 0.0f
, 1.0f
, 0xffff0000, 0xff000000},
1735 {-1.0f
, -1.0f
, 0.5f
, 0xffff0000, 0xff000000},
1736 {-1.0f
, 1.0f
, 0.5f
, 0xffff0000, 0xff000000},
1737 { 1.0f
, -1.0f
, 0.5f
, 0xffff0000, 0xff000000},
1738 { 1.0f
, 1.0f
, 0.5f
, 0xffff0000, 0xff000000},
1742 {-1.0f
, -1.0f
, 0.5f
, 0xffff0000, 0xff000000},
1743 {-1.0f
, 0.0f
, 0.5f
, 0xffff0000, 0xff000000},
1744 { 0.0f
, 0.0f
, 0.5f
, 0xffff0000, 0xff000000},
1745 { 0.0f
, -1.0f
, 0.5f
, 0xffff0000, 0xff000000},
1749 {-1.0f
, 0.0f
, 1.5f
, 0xffff0000, 0xff000000},
1750 {-1.0f
, 1.0f
, 1.5f
, 0xffff0000, 0xff000000},
1751 { 0.0f
, 1.0f
, 1.5f
, 0xffff0000, 0xff000000},
1752 { 0.0f
, 0.0f
, 1.5f
, 0xffff0000, 0xff000000},
1754 /* Untransformed ones. Give them a different diffuse color to make the
1755 * test look nicer. It also makes making sure that they are drawn
1756 * correctly easier. */
1765 {320.0f
, 0.0f
, 1.0f
, 1.0f
, 0xffffff00, 0xff000000},
1766 {640.0f
, 0.0f
, 1.0f
, 1.0f
, 0xffffff00, 0xff000000},
1767 {640.0f
, 240.0f
, 1.0f
, 1.0f
, 0xffffff00, 0xff000000},
1768 {320.0f
, 240.0f
, 1.0f
, 1.0f
, 0xffffff00, 0xff000000},
1772 {320.0f
, 240.0f
, 1.0f
, 1.0f
, 0xffffff00, 0xff000000},
1773 {640.0f
, 240.0f
, 1.0f
, 1.0f
, 0xffffff00, 0xff000000},
1774 {640.0f
, 480.0f
, 1.0f
, 1.0f
, 0xffffff00, 0xff000000},
1775 {320.0f
, 480.0f
, 1.0f
, 1.0f
, 0xffffff00, 0xff000000},
1779 struct vec3 position
;
1784 {{-1.0f
, -1.0f
, 0.1f
}, 0x000000ff},
1785 {{-1.0f
, 0.0f
, 0.1f
}, 0x000000ff},
1786 {{ 0.0f
, 0.0f
, 0.1f
}, 0x000000ff},
1787 {{ 0.0f
, -1.0f
, 0.1f
}, 0x000000ff},
1789 {{ 0.0f
, -1.0f
, 0.9f
}, 0x000000ff},
1790 {{ 0.0f
, 0.0f
, 0.9f
}, 0x000000ff},
1791 {{ 1.0f
, 0.0f
, 0.9f
}, 0x000000ff},
1792 {{ 1.0f
, -1.0f
, 0.9f
}, 0x000000ff},
1794 {{ 0.0f
, 0.0f
, 0.4f
}, 0x000000ff},
1795 {{ 0.0f
, 1.0f
, 0.4f
}, 0x000000ff},
1796 {{ 1.0f
, 1.0f
, 0.4f
}, 0x000000ff},
1797 {{ 1.0f
, 0.0f
, 0.4f
}, 0x000000ff},
1799 {{-1.0f
, 0.0f
, 0.7f
}, 0x000000ff},
1800 {{-1.0f
, 1.0f
, 0.7f
}, 0x000000ff},
1801 {{ 0.0f
, 1.0f
, 0.7f
}, 0x000000ff},
1802 {{ 0.0f
, 0.0f
, 0.7f
}, 0x000000ff},
1804 static const D3DMATRIX ident_mat
=
1806 1.0f
, 0.0f
, 0.0f
, 0.0f
,
1807 0.0f
, 1.0f
, 0.0f
, 0.0f
,
1808 0.0f
, 0.0f
, 1.0f
, 0.0f
,
1809 0.0f
, 0.0f
, 0.0f
, 1.0f
1811 static const D3DMATRIX world_mat1
=
1813 1.0f
, 0.0f
, 0.0f
, 0.0f
,
1814 0.0f
, 1.0f
, 0.0f
, 0.0f
,
1815 0.0f
, 0.0f
, 1.0f
, 0.0f
,
1816 0.0f
, 0.0f
, -0.5f
, 1.0f
1818 static const D3DMATRIX world_mat2
=
1820 1.0f
, 0.0f
, 0.0f
, 0.0f
,
1821 0.0f
, 1.0f
, 0.0f
, 0.0f
,
1822 0.0f
, 0.0f
, 1.0f
, 0.0f
,
1823 0.0f
, 0.0f
, 1.0f
, 1.0f
1825 static const D3DMATRIX proj_mat
=
1827 1.0f
, 0.0f
, 0.0f
, 0.0f
,
1828 0.0f
, 1.0f
, 0.0f
, 0.0f
,
1829 0.0f
, 0.0f
, 1.0f
, 0.0f
,
1830 0.0f
, 0.0f
, -1.0f
, 1.0f
1832 static const WORD Indices
[] = {0, 1, 2, 2, 3, 0};
1833 static const WORD Indices2
[] =
1837 8, 9, 10, 10, 11, 8,
1838 12, 13, 14, 14, 15, 12,
1841 window
= create_window();
1842 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
1843 ok(!!d3d
, "Failed to create a D3D object.\n");
1844 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
1846 skip("Failed to create a D3D device, skipping tests.\n");
1850 memset(&caps
, 0, sizeof(caps
));
1851 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
1852 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetDeviceCaps returned %08x\n", hr
);
1853 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
1854 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
1856 /* Setup initial states: No lighting, fog on, fog color */
1857 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
1858 ok(SUCCEEDED(hr
), "Failed to disable D3DRS_ZENABLE, hr %#x.\n", hr
);
1859 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
1860 ok(hr
== D3D_OK
, "Turning off lighting returned %08x\n", hr
);
1861 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGENABLE
, TRUE
);
1862 ok(hr
== D3D_OK
, "Turning on fog calculations returned %08x\n", hr
);
1863 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGCOLOR
, 0xff00ff00 /* A nice green */);
1864 ok(hr
== D3D_OK
, "Setting fog color returned %#08x\n", hr
);
1865 /* Some of the tests seem to depend on the projection matrix explicitly
1866 * being set to an identity matrix, even though that's the default.
1867 * (AMD Radeon HD 6310, Windows 7) */
1868 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_PROJECTION
, &ident_mat
);
1869 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
1871 /* First test: Both table fog and vertex fog off */
1872 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGTABLEMODE
, D3DFOG_NONE
);
1873 ok(hr
== D3D_OK
, "Turning off table fog returned %08x\n", hr
);
1874 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, D3DFOG_NONE
);
1875 ok(hr
== D3D_OK
, "Turning off vertex fog returned %08x\n", hr
);
1877 /* Start = 0, end = 1. Should be default, but set them */
1878 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGSTART
, *((DWORD
*) &start
));
1879 ok(hr
== D3D_OK
, "Setting fog start returned %08x\n", hr
);
1880 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGEND
, *((DWORD
*) &end
));
1881 ok(hr
== D3D_OK
, "Setting fog end returned %08x\n", hr
);
1883 hr
= IDirect3DDevice9_BeginScene(device
);
1884 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1886 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
);
1887 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
1889 /* Untransformed, vertex fog = NONE, table fog = NONE:
1890 * Read the fog weighting from the specular color. */
1891 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
1892 2 /* PrimCount */, Indices
, D3DFMT_INDEX16
, untransformed_1
, sizeof(untransformed_1
[0]));
1893 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1895 /* That makes it use the Z value */
1896 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, D3DFOG_LINEAR
);
1897 ok(SUCCEEDED(hr
), "Failed to set D3DFOG_LINEAR fog vertex mode, hr %#x.\n", hr
);
1898 /* Untransformed, vertex fog != none (or table fog != none):
1899 * Use the Z value as input into the equation. */
1900 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
1901 2 /* PrimCount */, Indices
, D3DFMT_INDEX16
, untransformed_2
, sizeof(untransformed_2
[0]));
1902 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1904 /* transformed verts */
1905 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
);
1906 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
1907 /* Transformed, vertex fog != NONE, pixel fog == NONE:
1908 * Use specular color alpha component. */
1909 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
1910 2 /* PrimCount */, Indices
, D3DFMT_INDEX16
, transformed_1
, sizeof(transformed_1
[0]));
1911 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1913 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGTABLEMODE
, D3DFOG_LINEAR
);
1914 ok(SUCCEEDED(hr
), "Failed to set D3DFOG_LINEAR fog table mode, hr %#x.\n", hr
);
1915 /* Transformed, table fog != none, vertex anything:
1916 * Use Z value as input to the fog equation. */
1917 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
1918 2 /* PrimCount */, Indices
, D3DFMT_INDEX16
, transformed_2
, sizeof(transformed_2
[0]));
1919 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1921 hr
= IDirect3DDevice9_EndScene(device
);
1922 ok(hr
== D3D_OK
, "EndScene returned %08x\n", hr
);
1924 color
= getPixelColor(device
, 160, 360);
1925 ok(color
== 0x00ff0000, "Untransformed vertex with no table or vertex fog has color %08x\n", color
);
1926 color
= getPixelColor(device
, 160, 120);
1927 ok(color_match(color
, 0x0000ff00, 1), "Untransformed vertex with linear vertex fog has color %08x\n", color
);
1928 color
= getPixelColor(device
, 480, 120);
1929 ok(color
== 0x00ffff00, "Transformed vertex with linear vertex fog has color %08x\n", color
);
1930 if(caps
.RasterCaps
& D3DPRASTERCAPS_FOGTABLE
)
1932 color
= getPixelColor(device
, 480, 360);
1933 ok(color_match(color
, 0x0000ff00, 1), "Transformed vertex with linear table fog has color %08x\n", color
);
1937 /* Without fog table support the vertex fog is still applied, even though table fog is turned on.
1938 * The settings above result in no fogging with vertex fog
1940 color
= getPixelColor(device
, 480, 120);
1941 ok(color
== 0x00ffff00, "Transformed vertex with linear vertex fog has color %08x\n", color
);
1942 trace("Info: Table fog not supported by this device\n");
1944 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
1946 /* Now test the special case fogstart == fogend */
1947 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff0000ff, 0.0, 0);
1948 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
1950 hr
= IDirect3DDevice9_BeginScene(device
);
1951 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1955 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGSTART
, *((DWORD
*)&start
));
1956 ok(SUCCEEDED(hr
), "Failed to set fog start, hr %#x.\n", hr
);
1957 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGEND
, *((DWORD
*)&end
));
1958 ok(SUCCEEDED(hr
), "Failed to set fog end, hr %#x.\n", hr
);
1960 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
);
1961 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
1962 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, D3DFOG_LINEAR
);
1963 ok(SUCCEEDED(hr
), "Failed to set D3DFOG_LINEAR fog vertex mode, hr %#x.\n", hr
);
1964 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGTABLEMODE
, D3DFOG_NONE
);
1965 ok(SUCCEEDED(hr
), "Failed to set D3DFOG_NONE fog table mode, hr %#x.\n", hr
);
1967 /* Untransformed vertex, z coord = 0.1, fogstart = 512, fogend = 512.
1968 * Would result in a completely fog-free primitive because start > zcoord,
1969 * but because start == end, the primitive is fully covered by fog. The
1970 * same happens to the 2nd untransformed quad with z = 1.0. The third
1971 * transformed quad remains unfogged because the fogcoords are read from
1972 * the specular color and has fixed fogstart and fogend. */
1973 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
1974 2 /* PrimCount */, Indices
, D3DFMT_INDEX16
, untransformed_1
, sizeof(untransformed_1
[0]));
1975 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1976 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
1977 2 /* PrimCount */, Indices
, D3DFMT_INDEX16
, untransformed_2
, sizeof(untransformed_2
[0]));
1978 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1980 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
);
1981 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
1982 /* Transformed, vertex fog != NONE, pixel fog == NONE:
1983 * Use specular color alpha component. */
1984 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
1985 2 /* PrimCount */, Indices
, D3DFMT_INDEX16
, transformed_1
, sizeof(transformed_1
[0]));
1986 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1988 hr
= IDirect3DDevice9_EndScene(device
);
1989 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1991 color
= getPixelColor(device
, 160, 360);
1992 ok(color_match(color
, 0x0000ff00, 1), "Untransformed vertex with vertex fog and z = 0.1 has color %08x\n", color
);
1993 color
= getPixelColor(device
, 160, 120);
1994 ok(color_match(color
, 0x0000ff00, 1), "Untransformed vertex with vertex fog and z = 1.0 has color %08x\n", color
);
1995 color
= getPixelColor(device
, 480, 120);
1996 ok(color
== 0x00ffff00, "Transformed vertex with linear vertex fog has color %08x\n", color
);
1997 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
1999 /* Test "reversed" fog without shaders. With shaders this fails on a few Windows D3D implementations,
2000 * but without shaders it seems to work everywhere
2004 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGSTART
, *((DWORD
*) &start
));
2005 ok(hr
== D3D_OK
, "Setting fog start returned %08x\n", hr
);
2006 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGEND
, *((DWORD
*) &end
));
2007 ok(hr
== D3D_OK
, "Setting fog end returned %08x\n", hr
);
2008 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
2009 ok( hr
== D3D_OK
, "IDirect3DDevice9_SetFVF returned %08x\n", hr
);
2011 /* Test reversed fog without shaders. ATI cards have problems with reversed fog and shaders, so
2012 * it doesn't seem very important for games. ATI cards also have problems with reversed table fog,
2013 * so skip this for now
2015 for(i
= 0; i
< 1 /*2 - Table fog test disabled, fails on ATI */; i
++) {
2016 const char *mode
= (i
? "table" : "vertex");
2017 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
2018 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
2019 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, i
== 0 ? D3DFOG_LINEAR
: D3DFOG_NONE
);
2020 ok( hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
2021 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGTABLEMODE
, i
== 0 ? D3DFOG_NONE
: D3DFOG_LINEAR
);
2022 ok( hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
2023 hr
= IDirect3DDevice9_BeginScene(device
);
2024 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
2025 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 16 /* NumVerts */,
2026 8 /* PrimCount */, Indices2
, D3DFMT_INDEX16
, rev_fog_quads
, sizeof(rev_fog_quads
[0]));
2027 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
2028 hr
= IDirect3DDevice9_EndScene(device
);
2029 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
2031 color
= getPixelColor(device
, 160, 360);
2032 ok(color_match(color
, 0x0000ff00, 1),
2033 "Reversed %s fog: z=0.1 has color 0x%08x, expected 0x0000ff00 or 0x0000fe00\n", mode
, color
);
2035 color
= getPixelColor(device
, 160, 120);
2036 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x00, 0x2b, 0xd4), 2),
2037 "Reversed %s fog: z=0.7 has color 0x%08x\n", mode
, color
);
2039 color
= getPixelColor(device
, 480, 120);
2040 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x00, 0xaa, 0x55), 2),
2041 "Reversed %s fog: z=0.4 has color 0x%08x\n", mode
, color
);
2043 color
= getPixelColor(device
, 480, 360);
2044 ok(color
== 0x000000ff, "Reversed %s fog: z=0.9 has color 0x%08x, expected 0x000000ff\n", mode
, color
);
2046 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
2048 if(!(caps
.RasterCaps
& D3DPRASTERCAPS_FOGTABLE
)) {
2049 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping reversed table fog test\n");
2054 if (caps
.RasterCaps
& D3DPRASTERCAPS_FOGTABLE
)
2056 /* A simple fog + non-identity world matrix test */
2057 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_WORLDMATRIX(0), &world_mat1
);
2058 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform returned %#08x\n", hr
);
2062 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGSTART
, *((DWORD
*)&start
));
2063 ok(hr
== D3D_OK
, "Setting fog start returned %08x\n", hr
);
2064 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGEND
, *((DWORD
*)&end
));
2065 ok(hr
== D3D_OK
, "Setting fog end returned %08x\n", hr
);
2066 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGTABLEMODE
, D3DFOG_LINEAR
);
2067 ok(hr
== D3D_OK
, "Setting fog table mode to D3DFOG_LINEAR returned %#08x\n", hr
);
2068 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, D3DFOG_NONE
);
2069 ok(hr
== D3D_OK
, "Turning off vertex fog returned %#08x\n", hr
);
2071 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
2072 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %#08x\n", hr
);
2074 hr
= IDirect3DDevice9_BeginScene(device
);
2075 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
2077 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
);
2078 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
2080 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0, 4,
2081 2, Indices
, D3DFMT_INDEX16
, far_quad1
, sizeof(far_quad1
[0]));
2082 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
2083 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0, 4,
2084 2, Indices
, D3DFMT_INDEX16
, far_quad2
, sizeof(far_quad2
[0]));
2085 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
2087 hr
= IDirect3DDevice9_EndScene(device
);
2088 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
2090 color
= getPixelColor(device
, 160, 360);
2091 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x00), 4),
2092 "Unfogged quad has color %08x\n", color
);
2093 color
= getPixelColor(device
, 160, 120);
2094 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1),
2095 "Fogged out quad has color %08x\n", color
);
2097 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
2099 /* Test fog behavior with an orthogonal (but non-identity) projection matrix */
2100 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_WORLDMATRIX(0), &world_mat2
);
2101 ok(hr
== D3D_OK
, "SetTransform returned %#08x\n", hr
);
2102 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_PROJECTION
, &proj_mat
);
2103 ok(hr
== D3D_OK
, "SetTransform returned %#08x\n", hr
);
2105 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
2106 ok(hr
== D3D_OK
, "Clear returned %#08x\n", hr
);
2108 hr
= IDirect3DDevice9_BeginScene(device
);
2109 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
2111 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
);
2112 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
2114 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0, 4,
2115 2, Indices
, D3DFMT_INDEX16
, untransformed_1
, sizeof(untransformed_1
[0]));
2116 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
2117 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0, 4,
2118 2, Indices
, D3DFMT_INDEX16
, untransformed_2
, sizeof(untransformed_2
[0]));
2119 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
2121 hr
= IDirect3DDevice9_EndScene(device
);
2122 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
2124 color
= getPixelColor(device
, 160, 360);
2125 ok(color_match(color
, 0x00e51900, 4), "Partially fogged quad has color %08x\n", color
);
2126 color
= getPixelColor(device
, 160, 120);
2127 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1),
2128 "Fogged out quad has color %08x\n", color
);
2130 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
2132 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_WORLDMATRIX(0), &ident_mat
);
2133 ok(hr
== D3D_OK
, "SetTransform returned %#08x\n", hr
);
2134 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_PROJECTION
, &ident_mat
);
2135 ok(hr
== D3D_OK
, "SetTransform returned %#08x\n", hr
);
2139 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests\n");
2142 /* Test RANGEFOG vs FOGTABLEMODE */
2143 if ((caps
.RasterCaps
& (D3DPRASTERCAPS_FOGTABLE
| D3DPRASTERCAPS_FOGRANGE
)) ==
2144 (D3DPRASTERCAPS_FOGTABLE
| D3DPRASTERCAPS_FOGRANGE
))
2146 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
2147 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Clear failed, hr %#x.\n", hr
);
2148 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
);
2149 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetFVF failed, hr %#x.\n", hr
);
2151 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_RANGEFOGENABLE
, TRUE
);
2152 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr
);
2154 /* z=0.5, x = +/- 1.0, y = +/- 1.0. In case of z fog the fog coordinate is
2155 * 0.5. With range fog it is sqrt(x*x + y*y + z*z) = 1.5 for all vertices.
2156 * Note that the fog coordinate is interpolated linearly across the vertices,
2157 * so the different eye distance at the screen center should not matter. */
2160 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGSTART
, *((DWORD
*) &start
));
2161 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr
);
2162 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGEND
, *((DWORD
*) &end
));
2163 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr
);
2165 /* Table fog: Range fog is not used */
2166 hr
= IDirect3DDevice9_BeginScene(device
);
2167 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
2169 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGTABLEMODE
, D3DFOG_LINEAR
);
2170 ok(SUCCEEDED(hr
), "Failed to set D3DFOG_LINEAR fog table mode, hr %#x.\n", hr
);
2171 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2,
2172 untransformed_3
, sizeof(*untransformed_3
));
2173 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
2175 hr
= IDirect3DDevice9_EndScene(device
);
2176 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
2178 color
= getPixelColor(device
, 10, 10);
2179 ok(color
== 0x00ff0000, "Rangefog with table fog returned color 0x%08x\n", color
);
2180 color
= getPixelColor(device
, 630, 10);
2181 ok(color
== 0x00ff0000, "Rangefog with table fog returned color 0x%08x\n", color
);
2182 color
= getPixelColor(device
, 10, 470);
2183 ok(color
== 0x00ff0000, "Rangefog with table fog returned color 0x%08x\n", color
);
2184 color
= getPixelColor(device
, 630, 470);
2185 ok(color
== 0x00ff0000, "Rangefog with table fog returned color 0x%08x\n", color
);
2187 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
2188 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Present failed, hr %#x.\n", hr
);
2190 /* Vertex fog: Rangefog is used */
2191 hr
= IDirect3DDevice9_BeginScene(device
);
2192 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
2194 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGTABLEMODE
, D3DFOG_NONE
);
2195 ok(SUCCEEDED(hr
), "Failed to set D3DFOG_NONE fog table mode, hr %#x.\n", hr
);
2196 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, D3DFOG_LINEAR
);
2197 ok(SUCCEEDED(hr
), "Failed to set D3DFOG_LINEAR fog vertex mode, hr %#x.\n", hr
);
2198 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2,
2199 untransformed_3
, sizeof(*untransformed_3
));
2200 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
2202 hr
= IDirect3DDevice9_EndScene(device
);
2203 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
2205 color
= getPixelColor(device
, 10, 10);
2206 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1),
2207 "Rangefog with vertex fog returned color 0x%08x\n", color
);
2208 color
= getPixelColor(device
, 630, 10);
2209 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1),
2210 "Rangefog with vertex fog returned color 0x%08x\n", color
);
2211 color
= getPixelColor(device
, 10, 470);
2212 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1),
2213 "Rangefog with vertex fog returned color 0x%08x\n", color
);
2214 color
= getPixelColor(device
, 630, 470);
2215 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1),
2216 "Rangefog with vertex fog returned color 0x%08x\n", color
);
2218 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
2219 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Present failed, hr %#x.\n", hr
);
2221 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_RANGEFOGENABLE
, FALSE
);
2222 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr
);
2226 skip("Range fog or table fog not supported, skipping range fog tests\n");
2229 refcount
= IDirect3DDevice9_Release(device
);
2230 ok(!refcount
, "Device has %u references left.\n", refcount
);
2232 IDirect3D9_Release(d3d
);
2233 DestroyWindow(window
);
2236 /* This test verifies the behaviour of cube maps wrt. texture wrapping.
2237 * D3D cube map wrapping always behaves like GL_CLAMP_TO_EDGE,
2238 * regardless of the actual addressing mode set. The way this test works is
2239 * that we sample in one of the corners of the cubemap with filtering enabled,
2240 * and check the interpolated color. There are essentially two reasonable
2241 * things an implementation can do: Either pick one of the faces and
2242 * interpolate the edge texel with itself (i.e., clamp within the face), or
2243 * interpolate between the edge texels of the three involved faces. It should
2244 * never involve the border color or the other side (texcoord wrapping) of a
2245 * face in the interpolation. */
2246 static void test_cube_wrap(void)
2248 IDirect3DVertexDeclaration9
*vertex_declaration
;
2249 IDirect3DSurface9
*face_surface
, *surface
;
2250 IDirect3DCubeTexture9
*texture
;
2251 D3DLOCKED_RECT locked_rect
;
2252 IDirect3DDevice9
*device
;
2253 unsigned int x
, y
, face
;
2260 static const float quad
[][6] =
2262 {-1.0f
, -1.0f
, 0.0f
, 1.0f
, 1.0f
, 1.0f
},
2263 {-1.0f
, 1.0f
, 0.0f
, 1.0f
, 1.0f
, 1.0f
},
2264 { 1.0f
, -1.0f
, 0.0f
, 1.0f
, 1.0f
, 1.0f
},
2265 { 1.0f
, 1.0f
, 0.0f
, 1.0f
, 1.0f
, 1.0f
},
2267 static const D3DVERTEXELEMENT9 decl_elements
[] =
2269 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
2270 {0, 12, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
2275 D3DTEXTUREADDRESS mode
;
2280 {D3DTADDRESS_WRAP
, "D3DTADDRESS_WRAP"},
2281 {D3DTADDRESS_MIRROR
, "D3DTADDRESS_MIRROR"},
2282 {D3DTADDRESS_CLAMP
, "D3DTADDRESS_CLAMP"},
2283 {D3DTADDRESS_BORDER
, "D3DTADDRESS_BORDER"},
2284 {D3DTADDRESS_MIRRORONCE
, "D3DTADDRESS_MIRRORONCE"},
2287 window
= create_window();
2288 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
2289 ok(!!d3d
, "Failed to create a D3D object.\n");
2290 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
2292 skip("Failed to create a D3D device, skipping tests.\n");
2296 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
2297 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
2298 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
))
2300 skip("No cube texture support, skipping tests.\n");
2301 IDirect3DDevice9_Release(device
);
2305 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &vertex_declaration
);
2306 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (0x%08x)\n", hr
);
2307 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, vertex_declaration
);
2308 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed (0x%08x)\n", hr
);
2310 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 128, 128,
2311 D3DFMT_A8R8G8B8
, D3DPOOL_SYSTEMMEM
, &surface
, NULL
);
2312 ok(SUCCEEDED(hr
), "CreateOffscreenPlainSurface failed (0x%08x)\n", hr
);
2314 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 128, 1, 0, D3DFMT_A8R8G8B8
,
2315 D3DPOOL_DEFAULT
, &texture
, NULL
);
2316 ok(SUCCEEDED(hr
), "CreateCubeTexture failed (0x%08x)\n", hr
);
2318 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, NULL
, 0);
2319 ok(SUCCEEDED(hr
), "LockRect failed (0x%08x)\n", hr
);
2321 for (y
= 0; y
< 128; ++y
)
2323 DWORD
*ptr
= (DWORD
*)(((BYTE
*)locked_rect
.pBits
) + (y
* locked_rect
.Pitch
));
2324 for (x
= 0; x
< 64; ++x
)
2326 *ptr
++ = 0xff0000ff;
2328 for (x
= 64; x
< 128; ++x
)
2330 *ptr
++ = 0xffff0000;
2334 hr
= IDirect3DSurface9_UnlockRect(surface
);
2335 ok(SUCCEEDED(hr
), "UnlockRect failed (0x%08x)\n", hr
);
2337 hr
= IDirect3DCubeTexture9_GetCubeMapSurface(texture
, 0, 0, &face_surface
);
2338 ok(SUCCEEDED(hr
), "GetCubeMapSurface failed (0x%08x)\n", hr
);
2340 hr
= IDirect3DDevice9_UpdateSurface(device
, surface
, NULL
, face_surface
, NULL
);
2341 ok(SUCCEEDED(hr
), "UpdateSurface failed (0x%08x)\n", hr
);
2343 IDirect3DSurface9_Release(face_surface
);
2345 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, NULL
, 0);
2346 ok(SUCCEEDED(hr
), "LockRect failed (0x%08x)\n", hr
);
2348 for (y
= 0; y
< 128; ++y
)
2350 DWORD
*ptr
= (DWORD
*)(((BYTE
*)locked_rect
.pBits
) + (y
* locked_rect
.Pitch
));
2351 for (x
= 0; x
< 64; ++x
)
2353 *ptr
++ = 0xffff0000;
2355 for (x
= 64; x
< 128; ++x
)
2357 *ptr
++ = 0xff0000ff;
2361 hr
= IDirect3DSurface9_UnlockRect(surface
);
2362 ok(SUCCEEDED(hr
), "UnlockRect failed (0x%08x)\n", hr
);
2364 /* Create cube faces */
2365 for (face
= 1; face
< 6; ++face
)
2367 hr
= IDirect3DCubeTexture9_GetCubeMapSurface(texture
, face
, 0, &face_surface
);
2368 ok(SUCCEEDED(hr
), "GetCubeMapSurface failed (0x%08x)\n", hr
);
2370 hr
= IDirect3DDevice9_UpdateSurface(device
, surface
, NULL
, face_surface
, NULL
);
2371 ok(SUCCEEDED(hr
), "UpdateSurface failed (0x%08x)\n", hr
);
2373 IDirect3DSurface9_Release(face_surface
);
2376 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)texture
);
2377 ok(SUCCEEDED(hr
), "SetTexture failed (0x%08x)\n", hr
);
2379 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MINFILTER
, D3DTEXF_LINEAR
);
2380 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_MINFILTER failed (0x%08x)\n", hr
);
2381 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAGFILTER
, D3DTEXF_LINEAR
);
2382 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr
);
2383 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_BORDERCOLOR
, 0xff00ff00);
2384 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_BORDERCOLOR failed (0x%08x)\n", hr
);
2386 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
2387 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
2389 for (x
= 0; x
< ARRAY_SIZE(address_modes
); ++x
)
2393 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSU
, address_modes
[x
].mode
);
2394 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_ADDRESSU (%s) failed (0x%08x)\n", address_modes
[x
].name
, hr
);
2395 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSV
, address_modes
[x
].mode
);
2396 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_ADDRESSV (%s) failed (0x%08x)\n", address_modes
[x
].name
, hr
);
2398 hr
= IDirect3DDevice9_BeginScene(device
);
2399 ok(SUCCEEDED(hr
), "BeginScene failed (0x%08x)\n", hr
);
2401 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad
[0], sizeof(quad
[0]));
2402 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (0x%08x)\n", hr
);
2404 hr
= IDirect3DDevice9_EndScene(device
);
2405 ok(SUCCEEDED(hr
), "EndScene failed (0x%08x)\n", hr
);
2407 color
= getPixelColor(device
, 320, 240);
2408 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0xff), 1),
2409 "Got color 0x%08x for addressing mode %s, expected 0x000000ff.\n",
2410 color
, address_modes
[x
].name
);
2412 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
2413 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
2415 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0, 0.0f
, 0);
2416 ok(SUCCEEDED(hr
), "Clear failed (0x%08x)\n", hr
);
2419 IDirect3DVertexDeclaration9_Release(vertex_declaration
);
2420 IDirect3DCubeTexture9_Release(texture
);
2421 IDirect3DSurface9_Release(surface
);
2422 refcount
= IDirect3DDevice9_Release(device
);
2423 ok(!refcount
, "Device has %u references left.\n", refcount
);
2425 IDirect3D9_Release(d3d
);
2426 DestroyWindow(window
);
2429 static void offscreen_test(void)
2431 IDirect3DSurface9
*backbuffer
, *offscreen
;
2432 IDirect3DTexture9
*offscreenTexture
;
2433 IDirect3DDevice9
*device
;
2440 static const float quad
[][5] =
2442 {-0.5f
, -0.5f
, 0.1f
, 0.0f
, 0.0f
},
2443 {-0.5f
, 0.5f
, 0.1f
, 0.0f
, 1.0f
},
2444 { 0.5f
, -0.5f
, 0.1f
, 1.0f
, 0.0f
},
2445 { 0.5f
, 0.5f
, 0.1f
, 1.0f
, 1.0f
},
2448 window
= create_window();
2449 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
2450 ok(!!d3d
, "Failed to create a D3D object.\n");
2451 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
2453 skip("Failed to create a D3D device, skipping tests.\n");
2457 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffff0000, 1.0f
, 0);
2458 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
2460 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
,
2461 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &offscreenTexture
, NULL
);
2462 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "Creating the offscreen render target failed, hr = %08x\n", hr
);
2463 if (!offscreenTexture
)
2465 trace("Failed to create an X8R8G8B8 offscreen texture, trying R5G6B5.\n");
2466 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
,
2467 D3DFMT_R5G6B5
, D3DPOOL_DEFAULT
, &offscreenTexture
, NULL
);
2468 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "Creating the offscreen render target failed, hr = %08x\n", hr
);
2469 if (!offscreenTexture
)
2471 skip("Cannot create an offscreen render target.\n");
2472 IDirect3DDevice9_Release(device
);
2477 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
2478 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %08x\n", hr
);
2480 hr
= IDirect3DTexture9_GetSurfaceLevel(offscreenTexture
, 0, &offscreen
);
2481 ok(hr
== D3D_OK
, "Can't get offscreen surface, hr = %08x\n", hr
);
2483 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
2484 ok(hr
== D3D_OK
, "SetFVF failed, hr = %08x\n", hr
);
2486 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
2487 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
2488 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
2489 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
2490 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MINFILTER
, D3DTEXF_POINT
);
2491 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_MINFILTER failed (0x%08x)\n", hr
);
2492 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAGFILTER
, D3DTEXF_POINT
);
2493 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr
);
2494 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
2495 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
2497 hr
= IDirect3DDevice9_BeginScene(device
);
2498 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
2500 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, offscreen
);
2501 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
2502 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 1.0f
, 0);
2503 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
2505 /* Draw without textures - Should result in a white quad. */
2506 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(quad
[0]));
2507 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
2509 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
2510 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
2511 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)offscreenTexture
);
2512 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
2514 /* This time with the texture. */
2515 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(quad
[0]));
2516 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
2518 hr
= IDirect3DDevice9_EndScene(device
);
2519 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
2521 /* Center quad - should be white */
2522 color
= getPixelColor(device
, 320, 240);
2523 ok(color
== 0x00ffffff, "Offscreen failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
2524 /* Some quad in the cleared part of the texture */
2525 color
= getPixelColor(device
, 170, 240);
2526 ok(color
== 0x00ff00ff, "Offscreen failed: Got color 0x%08x, expected 0x00ff00ff.\n", color
);
2527 /* Part of the originally cleared back buffer */
2528 color
= getPixelColor(device
, 10, 10);
2529 ok(color
== 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
2530 color
= getPixelColor(device
, 10, 470);
2531 ok(color
== 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
2533 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
2535 IDirect3DSurface9_Release(backbuffer
);
2536 IDirect3DTexture9_Release(offscreenTexture
);
2537 IDirect3DSurface9_Release(offscreen
);
2538 refcount
= IDirect3DDevice9_Release(device
);
2539 ok(!refcount
, "Device has %u references left.\n", refcount
);
2541 IDirect3D9_Release(d3d
);
2542 DestroyWindow(window
);
2545 /* This test tests fog in combination with shaders.
2546 * What's tested: linear fog (vertex and table) with pixel shader
2547 * linear table fog with non foggy vertex shader
2548 * vertex fog with foggy vertex shader, non-linear
2549 * fog with shader, non-linear fog with foggy shader,
2550 * linear table fog with foggy shader */
2551 static void fog_with_shader_test(void)
2553 IDirect3DVertexShader9
*vertex_shader
[4] = {NULL
, NULL
, NULL
, NULL
};
2554 IDirect3DPixelShader9
*pixel_shader
[3] = {NULL
, NULL
, NULL
};
2555 IDirect3DVertexDeclaration9
*vertex_declaration
= NULL
;
2556 IDirect3DDevice9
*device
;
2570 /* basic vertex shader without fog computation ("non foggy") */
2571 static const DWORD vertex_shader_code1
[] =
2573 0xfffe0101, /* vs_1_1 */
2574 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
2575 0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
2576 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
2577 0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
2580 /* basic vertex shader with reversed fog computation ("foggy") */
2581 static const DWORD vertex_shader_code2
[] =
2583 0xfffe0101, /* vs_1_1 */
2584 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
2585 0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
2586 0x00000051, 0xa00f0000, 0xbfa00000, 0x00000000, 0xbf666666, 0x00000000, /* def c0, -1.25, 0.0, -0.9, 0.0 */
2587 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
2588 0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
2589 0x00000002, 0x800f0000, 0x90aa0000, 0xa0aa0000, /* add r0, v0.z, c0.z */
2590 0x00000005, 0xc00f0001, 0x80000000, 0xa0000000, /* mul oFog, r0.x, c0.x */
2593 /* basic vertex shader with reversed fog computation ("foggy"), vs_2_0 */
2594 static const DWORD vertex_shader_code3
[] =
2596 0xfffe0200, /* vs_2_0 */
2597 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
2598 0x0200001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
2599 0x05000051, 0xa00f0000, 0xbfa00000, 0x00000000, 0xbf666666, 0x00000000, /* def c0, -1.25, 0.0, -0.9, 0.0 */
2600 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
2601 0x02000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
2602 0x03000002, 0x800f0000, 0x90aa0000, 0xa0aa0000, /* add r0, v0.z, c0.z */
2603 0x03000005, 0xc00f0001, 0x80000000, 0xa0000000, /* mul oFog, r0.x, c0.x */
2606 /* basic pixel shader */
2607 static const DWORD pixel_shader_code
[] =
2609 0xffff0101, /* ps_1_1 */
2610 0x00000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
2613 static const DWORD pixel_shader_code2
[] =
2615 0xffff0200, /* ps_2_0 */
2616 0x0200001f, 0x80000000, 0x900f0000, /* dcl v0 */
2617 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
2622 struct vec3 position
;
2627 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
2628 {{-1.0f
, 1.0f
, 0.0f
}, 0xffff0000},
2629 {{ 1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
2630 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffff0000},
2632 static const D3DVERTEXELEMENT9 decl_elements
[] =
2634 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
2635 {0, 12, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
2638 /* This reference data was collected on a nVidia GeForce 7600GS driver
2639 * version 84.19 DirectX version 9.0c on Windows XP. */
2640 static const struct test_data_t
2646 unsigned int color
[11];
2650 /* only pixel shader: */
2651 {0, 1, D3DFOG_NONE
, D3DFOG_LINEAR
,
2652 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2653 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2654 {0, 1, D3DFOG_EXP
, D3DFOG_LINEAR
,
2655 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2656 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2657 {0, 1, D3DFOG_EXP2
, D3DFOG_LINEAR
,
2658 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2659 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2660 {0, 1, D3DFOG_LINEAR
, D3DFOG_NONE
,
2661 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2662 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2663 {0, 1, D3DFOG_LINEAR
, D3DFOG_LINEAR
,
2664 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2665 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2668 {1, 0, D3DFOG_NONE
, D3DFOG_NONE
,
2669 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
2670 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00}},
2671 {1, 0, D3DFOG_NONE
, D3DFOG_LINEAR
,
2672 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2673 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2674 {1, 0, D3DFOG_EXP
, D3DFOG_LINEAR
,
2675 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2676 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2678 {1, 0, D3DFOG_EXP2
, D3DFOG_LINEAR
,
2679 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2680 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2681 {1, 0, D3DFOG_LINEAR
, D3DFOG_LINEAR
,
2682 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2683 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2685 /* vertex shader and pixel shader */
2686 /* The next 4 tests would read the fog coord output, but it isn't available.
2687 * The result is a fully fogged quad, no matter what the Z coord is. This is on
2688 * a geforce 7400, 97.52 driver, Windows Vista, but probably hardware dependent.
2689 * These tests should be disabled if some other hardware behaves differently
2691 {1, 1, D3DFOG_NONE
, D3DFOG_NONE
,
2692 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
2693 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00}},
2694 {1, 1, D3DFOG_LINEAR
, D3DFOG_NONE
,
2695 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
2696 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00}},
2697 {1, 1, D3DFOG_EXP
, D3DFOG_NONE
,
2698 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
2699 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00}},
2700 {1, 1, D3DFOG_EXP2
, D3DFOG_NONE
,
2701 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
2702 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00}},
2704 /* These use the Z coordinate with linear table fog */
2705 {1, 1, D3DFOG_NONE
, D3DFOG_LINEAR
,
2706 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2707 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2708 {1, 1, D3DFOG_EXP
, D3DFOG_LINEAR
,
2709 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2710 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2711 {1, 1, D3DFOG_EXP2
, D3DFOG_LINEAR
,
2712 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2713 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2714 {1, 1, D3DFOG_LINEAR
, D3DFOG_LINEAR
,
2715 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2716 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2718 /* Non-linear table fog without fog coord */
2719 {1, 1, D3DFOG_NONE
, D3DFOG_EXP
,
2720 {0x00ff0000, 0x00e71800, 0x00d12e00, 0x00bd4200, 0x00ab5400, 0x009b6400,
2721 0x008d7200, 0x007f8000, 0x00738c00, 0x00689700, 0x005ea100}},
2722 {1, 1, D3DFOG_NONE
, D3DFOG_EXP2
,
2723 {0x00fd0200, 0x00f50200, 0x00f50a00, 0x00e91600, 0x00d92600, 0x00c73800,
2724 0x00b24d00, 0x009c6300, 0x00867900, 0x00728d00, 0x005ea100}},
2726 /* These tests fail on older Nvidia drivers */
2727 /* foggy vertex shader */
2728 {2, 0, D3DFOG_NONE
, D3DFOG_NONE
,
2729 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2730 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2731 {2, 0, D3DFOG_EXP
, D3DFOG_NONE
,
2732 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2733 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2734 {2, 0, D3DFOG_EXP2
, D3DFOG_NONE
,
2735 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2736 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2737 {2, 0, D3DFOG_LINEAR
, D3DFOG_NONE
,
2738 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2739 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2741 {3, 0, D3DFOG_NONE
, D3DFOG_NONE
,
2742 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2743 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2744 {3, 0, D3DFOG_EXP
, D3DFOG_NONE
,
2745 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2746 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2747 {3, 0, D3DFOG_EXP2
, D3DFOG_NONE
,
2748 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2749 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2750 {3, 0, D3DFOG_LINEAR
, D3DFOG_NONE
,
2751 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2752 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2754 /* foggy vertex shader and pixel shader. First 4 tests with vertex fog,
2755 * all using the fixed fog-coord linear fog
2757 /* vs_1_1 with ps_1_1 */
2758 {2, 1, D3DFOG_NONE
, D3DFOG_NONE
,
2759 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2760 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2761 {2, 1, D3DFOG_EXP
, D3DFOG_NONE
,
2762 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2763 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2764 {2, 1, D3DFOG_EXP2
, D3DFOG_NONE
,
2765 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2766 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2767 {2, 1, D3DFOG_LINEAR
, D3DFOG_NONE
,
2768 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2769 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2771 /* vs_2_0 with ps_1_1 */
2772 {3, 1, D3DFOG_NONE
, D3DFOG_NONE
,
2773 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2774 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2775 {3, 1, D3DFOG_EXP
, D3DFOG_NONE
,
2776 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2777 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2778 {3, 1, D3DFOG_EXP2
, D3DFOG_NONE
,
2779 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2780 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2781 {3, 1, D3DFOG_LINEAR
, D3DFOG_NONE
,
2782 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2783 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2785 /* vs_1_1 with ps_2_0 */
2786 {2, 2, D3DFOG_NONE
, D3DFOG_NONE
,
2787 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2788 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2789 {2, 2, D3DFOG_EXP
, D3DFOG_NONE
,
2790 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2791 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2792 {2, 2, D3DFOG_EXP2
, D3DFOG_NONE
,
2793 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2794 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2795 {2, 2, D3DFOG_LINEAR
, D3DFOG_NONE
,
2796 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2797 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2799 /* vs_2_0 with ps_2_0 */
2800 {3, 2, D3DFOG_NONE
, D3DFOG_NONE
,
2801 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2802 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2803 {3, 2, D3DFOG_EXP
, D3DFOG_NONE
,
2804 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2805 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2806 {3, 2, D3DFOG_EXP2
, D3DFOG_NONE
,
2807 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2808 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2809 {3, 2, D3DFOG_LINEAR
, D3DFOG_NONE
,
2810 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
2811 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
2813 /* These use table fog. Here the shader-provided fog coordinate is
2814 * ignored and the z coordinate used instead
2816 {2, 1, D3DFOG_NONE
, D3DFOG_EXP
,
2817 {0x00ff0000, 0x00e71800, 0x00d12e00, 0x00bd4200, 0x00ab5400, 0x009b6400,
2818 0x008d7200, 0x007f8000, 0x00738c00, 0x00689700, 0x005ea100}},
2819 {2, 1, D3DFOG_NONE
, D3DFOG_EXP2
,
2820 {0x00fd0200, 0x00f50200, 0x00f50a00, 0x00e91600, 0x00d92600, 0x00c73800,
2821 0x00b24d00, 0x009c6300, 0x00867900, 0x00728d00, 0x005ea100}},
2822 {2, 1, D3DFOG_NONE
, D3DFOG_LINEAR
,
2823 {0x00ff0000, 0x00ff0000, 0x00df2000, 0x00bf4000, 0x009f6000, 0x007f8000,
2824 0x005fa000, 0x0040bf00, 0x0020df00, 0x0000ff00, 0x0000ff00}},
2826 static const D3DMATRIX identity
=
2828 1.0f
, 0.0f
, 0.0f
, 0.0f
,
2829 0.0f
, 1.0f
, 0.0f
, 0.0f
,
2830 0.0f
, 0.0f
, 1.0f
, 0.0f
,
2831 0.0f
, 0.0f
, 0.0f
, 1.0f
,
2834 window
= create_window();
2835 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
2836 ok(!!d3d
, "Failed to create a D3D object.\n");
2837 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
2839 skip("Failed to create a D3D device, skipping tests.\n");
2843 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
2844 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
2845 if (caps
.VertexShaderVersion
< D3DVS_VERSION(2, 0) || caps
.PixelShaderVersion
< D3DPS_VERSION(2, 0))
2847 skip("No shader model 2 support, skipping tests.\n");
2848 IDirect3DDevice9_Release(device
);
2852 /* NOTE: Changing these values will not affect the tests with foggy vertex
2853 * shader, as the values are hardcoded in the shader. */
2857 /* Some of the tests seem to depend on the projection matrix explicitly
2858 * being set to an identity matrix, even though that's the default.
2859 * (AMD Radeon HD 6310, Windows 7) */
2860 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_PROJECTION
, &identity
);
2861 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
2863 hr
= IDirect3DDevice9_CreateVertexShader(device
, vertex_shader_code1
, &vertex_shader
[1]);
2864 ok(SUCCEEDED(hr
), "CreateVertexShader failed (%08x)\n", hr
);
2865 hr
= IDirect3DDevice9_CreateVertexShader(device
, vertex_shader_code2
, &vertex_shader
[2]);
2866 ok(SUCCEEDED(hr
), "CreateVertexShader failed (%08x)\n", hr
);
2867 hr
= IDirect3DDevice9_CreateVertexShader(device
, vertex_shader_code3
, &vertex_shader
[3]);
2868 ok(SUCCEEDED(hr
), "CreateVertexShader failed (%08x)\n", hr
);
2869 hr
= IDirect3DDevice9_CreatePixelShader(device
, pixel_shader_code
, &pixel_shader
[1]);
2870 ok(SUCCEEDED(hr
), "CreatePixelShader failed (%08x)\n", hr
);
2871 hr
= IDirect3DDevice9_CreatePixelShader(device
, pixel_shader_code2
, &pixel_shader
[2]);
2872 ok(SUCCEEDED(hr
), "CreatePixelShader failed (%08x)\n", hr
);
2873 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &vertex_declaration
);
2874 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (%08x)\n", hr
);
2876 /* Setup initial states: No lighting, fog on, fog color */
2877 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
2878 ok(hr
== D3D_OK
, "Turning off lighting failed (%08x)\n", hr
);
2879 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGENABLE
, TRUE
);
2880 ok(hr
== D3D_OK
, "Turning on fog calculations failed (%08x)\n", hr
);
2881 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGCOLOR
, 0xff00ff00 /* A nice green */);
2882 ok(hr
== D3D_OK
, "Setting fog color failed (%08x)\n", hr
);
2883 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, vertex_declaration
);
2884 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed (%08x)\n", hr
);
2886 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGTABLEMODE
, D3DFOG_NONE
);
2887 ok(hr
== D3D_OK
, "Turning off table fog failed (%08x)\n", hr
);
2888 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, D3DFOG_NONE
);
2889 ok(hr
== D3D_OK
, "Turning off vertex fog failed (%08x)\n", hr
);
2891 /* Use fogtart = 0.1 and end = 0.9 to test behavior outside the fog transition phase, too*/
2892 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGSTART
, start
.i
);
2893 ok(hr
== D3D_OK
, "Setting fog start failed (%08x)\n", hr
);
2894 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGEND
, end
.i
);
2895 ok(hr
== D3D_OK
, "Setting fog end failed (%08x)\n", hr
);
2897 for (i
= 0; i
< ARRAY_SIZE(test_data
); i
++)
2899 hr
= IDirect3DDevice9_SetVertexShader(device
, vertex_shader
[test_data
[i
].vshader
]);
2900 ok(SUCCEEDED(hr
), "SetVertexShader failed (%08x)\n", hr
);
2901 hr
= IDirect3DDevice9_SetPixelShader(device
, pixel_shader
[test_data
[i
].pshader
]);
2902 ok(SUCCEEDED(hr
), "SetPixelShader failed (%08x)\n", hr
);
2903 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, test_data
[i
].vfog
);
2904 ok( hr
== D3D_OK
, "Setting fog vertex mode to D3DFOG_LINEAR failed (%08x)\n", hr
);
2905 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGTABLEMODE
, test_data
[i
].tfog
);
2906 ok( hr
== D3D_OK
, "Setting fog table mode to D3DFOG_LINEAR failed (%08x)\n", hr
);
2908 for(j
=0; j
< 11; j
++)
2910 /* Don't use the whole zrange to prevent rounding errors */
2911 quad
[0].position
.z
= 0.001f
+ (float)j
/ 10.02f
;
2912 quad
[1].position
.z
= 0.001f
+ (float)j
/ 10.02f
;
2913 quad
[2].position
.z
= 0.001f
+ (float)j
/ 10.02f
;
2914 quad
[3].position
.z
= 0.001f
+ (float)j
/ 10.02f
;
2916 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffff00ff, 1.0f
, 0);
2917 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed (%08x)\n", hr
);
2919 hr
= IDirect3DDevice9_BeginScene(device
);
2920 ok( hr
== D3D_OK
, "BeginScene returned failed (%08x)\n", hr
);
2922 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad
[0], sizeof(quad
[0]));
2923 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
2925 hr
= IDirect3DDevice9_EndScene(device
);
2926 ok(hr
== D3D_OK
, "EndScene failed (%08x)\n", hr
);
2928 /* As the red and green component are the result of blending use 5% tolerance on the expected value */
2929 color
= getPixelColor(device
, 128, 240);
2930 ok(color_match(color
, test_data
[i
].color
[j
], 13),
2931 "fog vs%i ps%i fvm%i ftm%i %d: got color %08x, expected %08x +-5%%\n",
2932 test_data
[i
].vshader
, test_data
[i
].pshader
, test_data
[i
].vfog
, test_data
[i
].tfog
, j
, color
, test_data
[i
].color
[j
]);
2935 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
2937 IDirect3DVertexShader9_Release(vertex_shader
[1]);
2938 IDirect3DVertexShader9_Release(vertex_shader
[2]);
2939 IDirect3DVertexShader9_Release(vertex_shader
[3]);
2940 IDirect3DPixelShader9_Release(pixel_shader
[1]);
2941 IDirect3DPixelShader9_Release(pixel_shader
[2]);
2942 IDirect3DVertexDeclaration9_Release(vertex_declaration
);
2943 refcount
= IDirect3DDevice9_Release(device
);
2944 ok(!refcount
, "Device has %u references left.\n", refcount
);
2946 IDirect3D9_Release(d3d
);
2947 DestroyWindow(window
);
2950 static void generate_bumpmap_textures(IDirect3DDevice9
*device
) {
2951 unsigned int i
, x
, y
;
2953 IDirect3DTexture9
*texture
[2] = {NULL
, NULL
};
2954 D3DLOCKED_RECT locked_rect
;
2956 /* Generate the textures */
2959 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 1, 0, i
?D3DFMT_A8R8G8B8
:D3DFMT_V8U8
,
2960 D3DPOOL_MANAGED
, &texture
[i
], NULL
);
2961 ok(SUCCEEDED(hr
), "CreateTexture failed (0x%08x)\n", hr
);
2963 hr
= IDirect3DTexture9_LockRect(texture
[i
], 0, &locked_rect
, NULL
, 0);
2964 ok(SUCCEEDED(hr
), "LockRect failed (0x%08x)\n", hr
);
2965 for (y
= 0; y
< 128; ++y
)
2968 { /* Set up black texture with 2x2 texel white spot in the middle */
2969 DWORD
*ptr
= (DWORD
*)(((BYTE
*)locked_rect
.pBits
) + (y
* locked_rect
.Pitch
));
2970 for (x
= 0; x
< 128; ++x
)
2972 *ptr
++ = D3DCOLOR_ARGB(0xff, x
* 2, y
* 2, 0);
2976 { /* Set up a displacement map which points away from the center parallel to the closest axis.
2977 * (if multiplied with bumpenvmat)
2979 WORD
*ptr
= (WORD
*)(((BYTE
*)locked_rect
.pBits
) + (y
* locked_rect
.Pitch
));
2980 for (x
= 0; x
< 128; ++x
)
2982 if(abs(x
-64)>abs(y
-64))
2999 hr
= IDirect3DTexture9_UnlockRect(texture
[i
], 0);
3000 ok(SUCCEEDED(hr
), "UnlockRect failed (0x%08x)\n", hr
);
3002 hr
= IDirect3DDevice9_SetTexture(device
, i
, (IDirect3DBaseTexture9
*)texture
[i
]);
3003 ok(SUCCEEDED(hr
), "SetTexture failed (0x%08x)\n", hr
);
3005 /* Disable texture filtering */
3006 hr
= IDirect3DDevice9_SetSamplerState(device
, i
, D3DSAMP_MINFILTER
, D3DTEXF_POINT
);
3007 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_MINFILTER failed (0x%08x)\n", hr
);
3008 hr
= IDirect3DDevice9_SetSamplerState(device
, i
, D3DSAMP_MAGFILTER
, D3DTEXF_POINT
);
3009 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr
);
3011 hr
= IDirect3DDevice9_SetSamplerState(device
, i
, D3DSAMP_ADDRESSU
, D3DTADDRESS_CLAMP
);
3012 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_ADDRESSU failed (0x%08x)\n", hr
);
3013 hr
= IDirect3DDevice9_SetSamplerState(device
, i
, D3DSAMP_ADDRESSV
, D3DTADDRESS_CLAMP
);
3014 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_ADDRESSV failed (0x%08x)\n", hr
);
3018 /* Test the behavior of the texbem instruction with normal 2D and projective
3020 static void texbem_test(void)
3022 IDirect3DVertexDeclaration9
*vertex_declaration
= NULL
;
3023 /* Use asymmetric matrix to test loading. */
3024 float bumpenvmat
[4] = {0.0f
, 0.5f
, -0.5f
, 0.0f
};
3025 IDirect3DPixelShader9
*pixel_shader
= NULL
;
3026 IDirect3DTexture9
*texture1
, *texture2
;
3027 IDirect3DTexture9
*texture
= NULL
;
3028 D3DLOCKED_RECT locked_rect
;
3029 IDirect3DDevice9
*device
;
3038 static const DWORD pixel_shader_code
[] =
3040 0xffff0101, /* ps_1_1*/
3041 0x00000042, 0xb00f0000, /* tex t0*/
3042 0x00000043, 0xb00f0001, 0xb0e40000, /* texbem t1, t0*/
3043 0x00000001, 0x800f0000, 0xb0e40001, /* mov r0, t1*/
3046 static const DWORD double_texbem_code
[] =
3048 0xffff0103, /* ps_1_3 */
3049 0x00000042, 0xb00f0000, /* tex t0 */
3050 0x00000043, 0xb00f0001, 0xb0e40000, /* texbem t1, t0 */
3051 0x00000042, 0xb00f0002, /* tex t2 */
3052 0x00000043, 0xb00f0003, 0xb0e40002, /* texbem t3, t2 */
3053 0x00000002, 0x800f0000, 0xb0e40001, 0xb0e40003, /* add r0, t1, t3 */
3054 0x0000ffff /* end */
3056 static const float quad
[][7] =
3058 {-1.0f
, -1.0f
, 0.1f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
},
3059 {-1.0f
, 1.0f
, 0.1f
, 0.0f
, 1.0f
, 0.0f
, 1.0f
},
3060 { 1.0f
, -1.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
, 0.0f
},
3061 { 1.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
},
3063 static const float quad_proj
[][9] =
3065 {-1.0f
, -1.0f
, 0.1f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 128.0f
},
3066 {-1.0f
, 1.0f
, 0.1f
, 0.0f
, 1.0f
, 0.0f
, 128.0f
, 0.0f
, 128.0f
},
3067 { 1.0f
, -1.0f
, 0.1f
, 1.0f
, 0.0f
, 128.0f
, 0.0f
, 0.0f
, 128.0f
},
3068 { 1.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
, 128.0f
, 128.0f
, 0.0f
, 128.0f
},
3070 static const float double_quad
[] =
3072 -1.0f
, -1.0f
, 0.0f
, 0.0f
, 0.0f
, 0.5f
, 0.5f
, 0.0f
, 0.0f
, 0.5f
, 0.5f
,
3073 -1.0f
, 1.0f
, 0.0f
, 0.0f
, 0.0f
, 0.5f
, 0.5f
, 0.0f
, 0.0f
, 0.5f
, 0.5f
,
3074 1.0f
, -1.0f
, 0.0f
, 0.0f
, 0.0f
, 0.5f
, 0.5f
, 0.0f
, 0.0f
, 0.5f
, 0.5f
,
3075 1.0f
, 1.0f
, 0.0f
, 0.0f
, 0.0f
, 0.5f
, 0.5f
, 0.0f
, 0.0f
, 0.5f
, 0.5f
,
3077 static const D3DVERTEXELEMENT9 decl_elements
[][4] =
3080 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
3081 {0, 12, D3DDECLTYPE_FLOAT2
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
3082 {0, 20, D3DDECLTYPE_FLOAT2
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 1},
3086 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
3087 {0, 12, D3DDECLTYPE_FLOAT2
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
3088 {0, 20, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 1},
3093 window
= create_window();
3094 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
3095 ok(!!d3d
, "Failed to create a D3D object.\n");
3096 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
3098 skip("Failed to create a D3D device, skipping tests.\n");
3102 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
3103 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
3104 if (caps
.PixelShaderVersion
< D3DPS_VERSION(1, 1))
3106 skip("No ps_1_1 support, skipping tests.\n");
3107 IDirect3DDevice9_Release(device
);
3111 generate_bumpmap_textures(device
);
3113 IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_BUMPENVMAT00
, *(LPDWORD
)&bumpenvmat
[0]);
3114 IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_BUMPENVMAT01
, *(LPDWORD
)&bumpenvmat
[1]);
3115 IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_BUMPENVMAT10
, *(LPDWORD
)&bumpenvmat
[2]);
3116 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_BUMPENVMAT11
, *(LPDWORD
)&bumpenvmat
[3]);
3117 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
3119 hr
= IDirect3DDevice9_SetVertexShader(device
, NULL
);
3120 ok(SUCCEEDED(hr
), "SetVertexShader failed (%08x)\n", hr
);
3124 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff0000ff, 1.0f
, 0);
3125 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed (%08x)\n", hr
);
3129 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT4
|D3DTTFF_PROJECTED
);
3130 ok(SUCCEEDED(hr
), "SetTextureStageState D3DTSS_TEXTURETRANSFORMFLAGS failed (0x%08x)\n", hr
);
3133 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
[i
], &vertex_declaration
);
3134 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (0x%08x)\n", hr
);
3135 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, vertex_declaration
);
3136 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed (0x%08x)\n", hr
);
3138 hr
= IDirect3DDevice9_CreatePixelShader(device
, pixel_shader_code
, &pixel_shader
);
3139 ok(SUCCEEDED(hr
), "CreatePixelShader failed (%08x)\n", hr
);
3140 hr
= IDirect3DDevice9_SetPixelShader(device
, pixel_shader
);
3141 ok(SUCCEEDED(hr
), "SetPixelShader failed (%08x)\n", hr
);
3143 hr
= IDirect3DDevice9_BeginScene(device
);
3144 ok(SUCCEEDED(hr
), "BeginScene failed (0x%08x)\n", hr
);
3147 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad
[0], sizeof(quad
[0]));
3149 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad_proj
[0], sizeof(quad_proj
[0]));
3150 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (0x%08x)\n", hr
);
3152 hr
= IDirect3DDevice9_EndScene(device
);
3153 ok(SUCCEEDED(hr
), "EndScene failed (0x%08x)\n", hr
);
3155 /* The Window 8 testbot (WARP) seems to use the transposed
3156 * D3DTSS_BUMPENVMAT matrix. */
3157 color
= getPixelColor(device
, 160, 240);
3158 ok(color_match(color
, 0x007e8000, 4) || broken(color_match(color
, 0x00007e00, 4)),
3159 "Got unexpected color 0x%08x.\n", color
);
3160 color
= getPixelColor(device
, 480, 240);
3161 ok(color_match(color
, 0x007e8000, 4) || broken(color_match(color
, 0x00fe7e00, 4)),
3162 "Got unexpected color 0x%08x.\n", color
);
3163 color
= getPixelColor(device
, 320, 120);
3164 ok(color_match(color
, 0x007e8000, 4) || broken(color_match(color
, 0x0080fe00, 4)),
3165 "Got unexpected color 0x%08x.\n", color
);
3166 color
= getPixelColor(device
, 320, 360);
3167 ok(color_match(color
, 0x007e8000, 4) || broken(color_match(color
, 0x00800000, 4)),
3168 "Got unexpected color 0x%08x.\n", color
);
3170 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
3171 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
3173 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
3174 ok(SUCCEEDED(hr
), "SetPixelShader failed (%08x)\n", hr
);
3175 IDirect3DPixelShader9_Release(pixel_shader
);
3177 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
3178 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed (%08x)\n", hr
);
3179 IDirect3DVertexDeclaration9_Release(vertex_declaration
);
3183 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0, 0.0f
, 0);
3184 ok(SUCCEEDED(hr
), "Clear failed (0x%08x)\n", hr
);
3186 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT2
);
3187 ok(SUCCEEDED(hr
), "SetTextureStageState D3DTSS_TEXTURETRANSFORMFLAGS failed (0x%08x)\n", hr
);
3191 hr
= IDirect3DDevice9_GetTexture(device
, i
, (IDirect3DBaseTexture9
**) &texture
);
3192 ok(SUCCEEDED(hr
), "IDirect3DDevice9_GetTexture failed (0x%08x)\n", hr
);
3193 IDirect3DTexture9_Release(texture
); /* For the GetTexture */
3194 hr
= IDirect3DDevice9_SetTexture(device
, i
, NULL
);
3195 ok(SUCCEEDED(hr
), "SetTexture failed (0x%08x)\n", hr
);
3196 IDirect3DTexture9_Release(texture
);
3199 /* Test double texbem */
3200 hr
= IDirect3DDevice9_CreateTexture(device
, 1, 1, 1, 0, D3DFMT_V8U8
, D3DPOOL_MANAGED
, &texture
, NULL
);
3201 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateTexture failed (0x%08x)\n", hr
);
3202 hr
= IDirect3DDevice9_CreateTexture(device
, 1, 1, 1, 0, D3DFMT_V8U8
, D3DPOOL_MANAGED
, &texture1
, NULL
);
3203 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateTexture failed (0x%08x)\n", hr
);
3204 hr
= IDirect3DDevice9_CreateTexture(device
, 8, 8, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &texture2
, NULL
);
3205 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateTexture failed (0x%08x)\n", hr
);
3206 hr
= IDirect3DDevice9_CreatePixelShader(device
, double_texbem_code
, &pixel_shader
);
3207 ok(SUCCEEDED(hr
), "CreatePixelShader failed (%08x)\n", hr
);
3209 hr
= IDirect3DTexture9_LockRect(texture
, 0, &locked_rect
, NULL
, 0);
3210 ok(SUCCEEDED(hr
), "LockRect failed (0x%08x)\n", hr
);
3211 ((signed char *) locked_rect
.pBits
)[0] = (-1.0 / 8.0) * 127;
3212 ((signed char *) locked_rect
.pBits
)[1] = ( 1.0 / 8.0) * 127;
3214 hr
= IDirect3DTexture9_UnlockRect(texture
, 0);
3215 ok(SUCCEEDED(hr
), "LockRect failed (0x%08x)\n", hr
);
3217 hr
= IDirect3DTexture9_LockRect(texture1
, 0, &locked_rect
, NULL
, 0);
3218 ok(SUCCEEDED(hr
), "LockRect failed (0x%08x)\n", hr
);
3219 ((signed char *) locked_rect
.pBits
)[0] = (-2.0 / 8.0) * 127;
3220 ((signed char *) locked_rect
.pBits
)[1] = (-4.0 / 8.0) * 127;
3221 hr
= IDirect3DTexture9_UnlockRect(texture1
, 0);
3222 ok(SUCCEEDED(hr
), "LockRect failed (0x%08x)\n", hr
);
3225 /* Some data without any meaning, just to have an 8x8 array to see which element is picked */
3226 #define tex 0x00ff0000
3227 #define tex1 0x0000ff00
3228 #define origin 0x000000ff
3229 static const DWORD pixel_data
[] = {
3230 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
3231 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
3232 0x000000ff, tex1
, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
3233 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
3234 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, origin
, 0x000000ff, tex
, 0x000000ff,
3235 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
3236 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
3237 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff,
3243 hr
= IDirect3DTexture9_LockRect(texture2
, 0, &locked_rect
, NULL
, 0);
3244 ok(SUCCEEDED(hr
), "LockRect failed (0x%08x)\n", hr
);
3245 for(i
= 0; i
< 8; i
++) {
3246 memcpy(((char *) locked_rect
.pBits
) + i
* locked_rect
.Pitch
, pixel_data
+ 8 * i
, 8 * sizeof(DWORD
));
3248 hr
= IDirect3DTexture9_UnlockRect(texture2
, 0);
3249 ok(SUCCEEDED(hr
), "LockRect failed (0x%08x)\n", hr
);
3252 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) texture
);
3253 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTexture failed (0x%08x)\n", hr
);
3254 hr
= IDirect3DDevice9_SetTexture(device
, 1, (IDirect3DBaseTexture9
*) texture2
);
3255 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTexture failed (0x%08x)\n", hr
);
3256 hr
= IDirect3DDevice9_SetTexture(device
, 2, (IDirect3DBaseTexture9
*) texture1
);
3257 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTexture failed (0x%08x)\n", hr
);
3258 hr
= IDirect3DDevice9_SetTexture(device
, 3, (IDirect3DBaseTexture9
*) texture2
);
3259 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTexture failed (0x%08x)\n", hr
);
3260 hr
= IDirect3DDevice9_SetPixelShader(device
, pixel_shader
);
3261 ok(SUCCEEDED(hr
), "Direct3DDevice9_SetPixelShader failed (0x%08x)\n", hr
);
3262 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX4
);
3263 ok(SUCCEEDED(hr
), "Direct3DDevice9_SetPixelShader failed (0x%08x)\n", hr
);
3265 bumpenvmat
[0] =-1.0; bumpenvmat
[2] = 2.0;
3266 bumpenvmat
[1] = 0.0; bumpenvmat
[3] = 0.0;
3267 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_BUMPENVMAT00
, *(LPDWORD
)&bumpenvmat
[0]);
3268 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr
);
3269 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_BUMPENVMAT01
, *(LPDWORD
)&bumpenvmat
[1]);
3270 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr
);
3271 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_BUMPENVMAT10
, *(LPDWORD
)&bumpenvmat
[2]);
3272 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr
);
3273 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_BUMPENVMAT11
, *(LPDWORD
)&bumpenvmat
[3]);
3274 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr
);
3276 bumpenvmat
[0] = 1.5; bumpenvmat
[2] = 0.0;
3277 bumpenvmat
[1] = 0.0; bumpenvmat
[3] = 0.5;
3278 hr
= IDirect3DDevice9_SetTextureStageState(device
, 3, D3DTSS_BUMPENVMAT00
, *(LPDWORD
)&bumpenvmat
[0]);
3279 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr
);
3280 hr
= IDirect3DDevice9_SetTextureStageState(device
, 3, D3DTSS_BUMPENVMAT01
, *(LPDWORD
)&bumpenvmat
[1]);
3281 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr
);
3282 hr
= IDirect3DDevice9_SetTextureStageState(device
, 3, D3DTSS_BUMPENVMAT10
, *(LPDWORD
)&bumpenvmat
[2]);
3283 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr
);
3284 hr
= IDirect3DDevice9_SetTextureStageState(device
, 3, D3DTSS_BUMPENVMAT11
, *(LPDWORD
)&bumpenvmat
[3]);
3285 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState returned %#x.\n", hr
);
3287 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSU
, D3DTADDRESS_CLAMP
);
3288 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr
);
3289 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSV
, D3DTADDRESS_CLAMP
);
3290 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr
);
3291 hr
= IDirect3DDevice9_SetSamplerState(device
, 1, D3DSAMP_ADDRESSU
, D3DTADDRESS_CLAMP
);
3292 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr
);
3293 hr
= IDirect3DDevice9_SetSamplerState(device
, 1, D3DSAMP_ADDRESSV
, D3DTADDRESS_CLAMP
);
3294 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr
);
3295 hr
= IDirect3DDevice9_SetSamplerState(device
, 2, D3DSAMP_ADDRESSU
, D3DTADDRESS_CLAMP
);
3296 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr
);
3297 hr
= IDirect3DDevice9_SetSamplerState(device
, 2, D3DSAMP_ADDRESSV
, D3DTADDRESS_CLAMP
);
3298 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr
);
3299 hr
= IDirect3DDevice9_SetSamplerState(device
, 3, D3DSAMP_ADDRESSU
, D3DTADDRESS_CLAMP
);
3300 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr
);
3301 hr
= IDirect3DDevice9_SetSamplerState(device
, 3, D3DSAMP_ADDRESSV
, D3DTADDRESS_CLAMP
);
3302 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetSamplerState returned %#x.\n", hr
);
3304 hr
= IDirect3DDevice9_BeginScene(device
);
3305 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3306 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, double_quad
, sizeof(float) * 11);
3307 ok(SUCCEEDED(hr
), "Failed to draw primitive, hr %#x.\n", hr
);
3308 hr
= IDirect3DDevice9_EndScene(device
);
3309 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3310 /* The Window 8 testbot (WARP) seems to use the transposed
3311 * D3DTSS_BUMPENVMAT matrix. */
3312 color
= getPixelColor(device
, 320, 240);
3313 ok(color_match(color
, 0x00ffff00, 1) || broken(color_match(color
, 0x0000ffff, 1)),
3314 "Got unexpected color 0x%08x.\n", color
);
3316 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
3317 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
3319 IDirect3DPixelShader9_Release(pixel_shader
);
3320 IDirect3DTexture9_Release(texture
);
3321 IDirect3DTexture9_Release(texture1
);
3322 IDirect3DTexture9_Release(texture2
);
3323 refcount
= IDirect3DDevice9_Release(device
);
3324 ok(!refcount
, "Device has %u references left.\n", refcount
);
3326 IDirect3D9_Release(d3d
);
3327 DestroyWindow(window
);
3330 static void z_range_test(void)
3332 IDirect3DVertexShader9
*shader
;
3333 IDirect3DDevice9
*device
;
3343 struct vec3 position
;
3348 {{-1.0f
, 0.0f
, 1.1f
}, 0xffff0000},
3349 {{-1.0f
, 1.0f
, 1.1f
}, 0xffff0000},
3350 {{ 1.0f
, 0.0f
, -1.1f
}, 0xffff0000},
3351 {{ 1.0f
, 1.0f
, -1.1f
}, 0xffff0000},
3355 {{-1.0f
, 0.0f
, 1.1f
}, 0xff0000ff},
3356 {{-1.0f
, 1.0f
, 1.1f
}, 0xff0000ff},
3357 {{ 1.0f
, 0.0f
, -1.1f
}, 0xff0000ff},
3358 {{ 1.0f
, 1.0f
, -1.1f
}, 0xff0000ff},
3362 struct vec4 position
;
3367 {{640.0f
, 240.0f
, -1.1f
, 1.0f
}, 0xffffff00},
3368 {{640.0f
, 480.0f
, -1.1f
, 1.0f
}, 0xffffff00},
3369 {{ 0.0f
, 240.0f
, 1.1f
, 1.0f
}, 0xffffff00},
3370 {{ 0.0f
, 480.0f
, 1.1f
, 1.0f
}, 0xffffff00},
3374 {{640.0f
, 240.0f
, -1.1f
, 1.0f
}, 0xff00ff00},
3375 {{640.0f
, 480.0f
, -1.1f
, 1.0f
}, 0xff00ff00},
3376 {{ 0.0f
, 240.0f
, 1.1f
, 1.0f
}, 0xff00ff00},
3377 {{ 0.0f
, 480.0f
, 1.1f
, 1.0f
}, 0xff00ff00},
3379 static const DWORD shader_code
[] =
3381 0xfffe0101, /* vs_1_1 */
3382 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
3383 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
3384 0x00000001, 0xd00f0000, 0xa0e40000, /* mov oD0, c0 */
3385 0x0000ffff /* end */
3387 static const float color_const_1
[] = {1.0f
, 0.0f
, 0.0f
, 1.0f
};
3388 static const float color_const_2
[] = {0.0f
, 0.0f
, 1.0f
, 1.0f
};
3390 window
= create_window();
3391 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
3392 ok(!!d3d
, "Failed to create a D3D object.\n");
3393 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
3395 skip("Failed to create a D3D device, skipping tests.\n");
3399 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
3400 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
3402 /* Does the Present clear the depth stencil? Clear the depth buffer with some value != 0,
3403 * then call Present. Then clear the color buffer to make sure it has some defined content
3404 * after the Present with D3DSWAPEFFECT_DISCARD. After that draw a plane that is somewhere cut
3405 * by the depth value. */
3406 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffffff, 0.75f
, 0);
3407 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
3408 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
3409 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
3410 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
3411 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
3413 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
3414 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
3415 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CLIPPING
, TRUE
);
3416 ok(SUCCEEDED(hr
), "Failed to enable clipping, hr %#x.\n", hr
);
3417 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_TRUE
);
3418 ok(SUCCEEDED(hr
), "Failed to enable z test, hr %#x.\n", hr
);
3419 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, FALSE
);
3420 ok(SUCCEEDED(hr
), "Failed to disable z writes, hr %#x.\n", hr
);
3421 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_GREATER
);
3422 ok(SUCCEEDED(hr
), "Failed to set z function, hr %#x.\n", hr
);
3423 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
3424 ok(SUCCEEDED(hr
), "Failed set FVF, hr %#x.\n", hr
);
3426 hr
= IDirect3DDevice9_BeginScene(device
);
3427 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3429 /* Test the untransformed vertex path */
3430 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(quad
[0]));
3431 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3432 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_LESS
);
3433 ok(SUCCEEDED(hr
), "Failed to set z function, hr %#x.\n", hr
);
3434 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(quad2
[0]));
3435 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3437 /* Test the transformed vertex path */
3438 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
);
3439 ok(SUCCEEDED(hr
), "Failed set FVF, hr %#x.\n", hr
);
3441 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, sizeof(quad4
[0]));
3442 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3443 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_GREATER
);
3444 ok(SUCCEEDED(hr
), "Failed to set z function, hr %#x.\n", hr
);
3445 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, sizeof(quad3
[0]));
3446 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3448 hr
= IDirect3DDevice9_EndScene(device
);
3449 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3451 /* Do not test the exact corner pixels, but go pretty close to them */
3453 /* Clipped because z > 1.0 */
3454 color
= getPixelColor(device
, 28, 238);
3455 ok(color_match(color
, 0x00ffffff, 0), "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
3456 color
= getPixelColor(device
, 28, 241);
3457 if (caps
.PrimitiveMiscCaps
& D3DPMISCCAPS_CLIPTLVERTS
)
3458 ok(color_match(color
, 0x00ffffff, 0), "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
3460 ok(color_match(color
, 0x00ffff00, 0), "Z range failed: Got color 0x%08x, expected 0x00ffff00.\n", color
);
3462 /* Not clipped, > z buffer clear value(0.75).
3464 * On the r500 driver on Windows D3DCMP_GREATER and D3DCMP_GREATEREQUAL are broken for depth
3465 * values > 0.5. The range appears to be distorted, apparently an incoming value of ~0.875 is
3466 * equal to a stored depth buffer value of 0.5. */
3467 color
= getPixelColor(device
, 31, 238);
3468 ok(color_match(color
, 0x00ff0000, 0), "Z range failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
3469 color
= getPixelColor(device
, 31, 241);
3470 ok(color_match(color
, 0x00ffff00, 0), "Z range failed: Got color 0x%08x, expected 0x00ffff00.\n", color
);
3471 color
= getPixelColor(device
, 100, 238);
3472 ok(color_match(color
, 0x00ff0000, 0) || broken(color_match(color
, 0x00ffffff, 0)),
3473 "Z range failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
3474 color
= getPixelColor(device
, 100, 241);
3475 ok(color_match(color
, 0x00ffff00, 0) || broken(color_match(color
, 0x00ffffff, 0)),
3476 "Z range failed: Got color 0x%08x, expected 0x00ffff00.\n", color
);
3478 /* Not clipped, < z buffer clear value */
3479 color
= getPixelColor(device
, 104, 238);
3480 ok(color_match(color
, 0x000000ff, 0), "Z range failed: Got color 0x%08x, expected 0x000000ff.\n", color
);
3481 color
= getPixelColor(device
, 104, 241);
3482 ok(color_match(color
, 0x0000ff00, 0), "Z range failed: Got color 0x%08x, expected 0x0000ff00.\n", color
);
3483 color
= getPixelColor(device
, 318, 238);
3484 ok(color_match(color
, 0x000000ff, 0), "Z range failed: Got color 0x%08x, expected 0x000000ff.\n", color
);
3485 color
= getPixelColor(device
, 318, 241);
3486 ok(color_match(color
, 0x0000ff00, 0), "Z range failed: Got color 0x%08x, expected 0x0000ff00.\n", color
);
3488 /* Clipped because z < 0.0 */
3489 color
= getPixelColor(device
, 321, 238);
3490 ok(color_match(color
, 0x00ffffff, 0), "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
3491 color
= getPixelColor(device
, 321, 241);
3492 if (caps
.PrimitiveMiscCaps
& D3DPMISCCAPS_CLIPTLVERTS
)
3493 ok(color_match(color
, 0x00ffffff, 0), "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
3495 ok(color_match(color
, 0x0000ff00, 0), "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
3497 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
3498 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
3500 /* Test the shader path */
3501 if (caps
.VertexShaderVersion
< D3DVS_VERSION(1, 1))
3503 skip("Vertex shaders not supported, skipping tests.\n");
3504 IDirect3DDevice9_Release(device
);
3507 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_code
, &shader
);
3508 ok(SUCCEEDED(hr
), "Failed to create vertex shader, hr %#x.\n", hr
);
3510 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
3511 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
3513 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
3514 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
3515 hr
= IDirect3DDevice9_SetVertexShader(device
, shader
);
3516 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
3518 hr
= IDirect3DDevice9_BeginScene(device
);
3519 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3521 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 0, color_const_1
, 1);
3522 ok(SUCCEEDED(hr
), "Failed to set vs constant 0, hr %#x.\n", hr
);
3523 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(quad
[0]));
3524 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3526 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_LESS
);
3527 ok(SUCCEEDED(hr
), "Failed to set z function, hr %#x.\n", hr
);
3528 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 0, color_const_2
, 1);
3529 ok(SUCCEEDED(hr
), "Failed to set vs constant 0, hr %#x.\n", hr
);
3530 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(quad2
[0]));
3531 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3533 hr
= IDirect3DDevice9_EndScene(device
);
3534 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3536 IDirect3DVertexShader9_Release(shader
);
3539 color
= getPixelColor(device
, 28, 238);
3540 ok(color_match(color
, 0x00ffffff, 0), "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
3542 /* 1.0 < z < 0.75 */
3543 color
= getPixelColor(device
, 31, 238);
3544 ok(color_match(color
, 0x00ff0000, 0), "Z range failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
3545 color
= getPixelColor(device
, 100, 238);
3546 ok(color_match(color
, 0x00ff0000, 0) || broken(color_match(color
, 0x00ffffff, 0)),
3547 "Z range failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
3549 /* 0.75 < z < 0.0 */
3550 color
= getPixelColor(device
, 104, 238);
3551 ok(color_match(color
, 0x000000ff, 0), "Z range failed: Got color 0x%08x, expected 0x000000ff.\n", color
);
3552 color
= getPixelColor(device
, 318, 238);
3553 ok(color_match(color
, 0x000000ff, 0), "Z range failed: Got color 0x%08x, expected 0x000000ff.\n", color
);
3556 color
= getPixelColor(device
, 321, 238);
3557 ok(color_match(color
, 0x00ffffff, 0), "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
3559 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
3560 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
3562 refcount
= IDirect3DDevice9_Release(device
);
3563 ok(!refcount
, "Device has %u references left.\n", refcount
);
3565 IDirect3D9_Release(d3d
);
3566 DestroyWindow(window
);
3569 static void fill_surface(IDirect3DSurface9
*surface
, DWORD color
, DWORD flags
)
3571 D3DSURFACE_DESC desc
;
3577 memset(&desc
, 0, sizeof(desc
));
3578 memset(&l
, 0, sizeof(l
));
3579 hr
= IDirect3DSurface9_GetDesc(surface
, &desc
);
3580 ok(hr
== D3D_OK
, "IDirect3DSurface9_GetDesc failed with %08x\n", hr
);
3581 hr
= IDirect3DSurface9_LockRect(surface
, &l
, NULL
, flags
);
3582 ok(hr
== D3D_OK
, "IDirect3DSurface9_LockRect failed with %08x\n", hr
);
3583 if(FAILED(hr
)) return;
3585 for(y
= 0; y
< desc
.Height
; y
++)
3587 mem
= (DWORD
*) ((BYTE
*) l
.pBits
+ y
* l
.Pitch
);
3588 for(x
= 0; x
< l
.Pitch
/ sizeof(DWORD
); x
++)
3593 hr
= IDirect3DSurface9_UnlockRect(surface
);
3594 ok(hr
== D3D_OK
, "IDirect3DSurface9_UnlockRect failed with %08x\n", hr
);
3597 static void stretchrect_test(void)
3599 IDirect3DSurface9
*surf_tex_rt32
, *surf_tex_rt64
, *surf_tex_rt_dest64
, *surf_tex_rt_dest640_480
;
3600 IDirect3DSurface9
*surf_offscreen32
, *surf_offscreen64
, *surf_offscreen_dest64
;
3601 IDirect3DTexture9
*tex_rt32
, *tex_rt64
, *tex_rt_dest64
, *tex_rt_dest640_480
;
3602 IDirect3DSurface9
*surf_tex32
, *surf_tex64
, *surf_tex_dest64
;
3603 IDirect3DSurface9
*surf_rt32
, *surf_rt64
, *surf_rt_dest64
;
3604 IDirect3DTexture9
*tex32
, *tex64
, *tex_dest64
;
3605 IDirect3DSurface9
*surf_temp32
, *surf_temp64
;
3606 IDirect3DSurface9
*backbuffer
;
3607 IDirect3DDevice9
*device
;
3614 static const RECT src_rect
= {0, 0, 640, 480};
3615 static const RECT src_rect_flipy
= {0, 480, 640, 0};
3616 static const RECT dst_rect
= {0, 0, 640, 480};
3617 static const RECT dst_rect_flipy
= {0, 480, 640, 0};
3618 static const RECT src_rect64
= {0, 0, 64, 64};
3619 static const RECT src_rect64_flipy
= {0, 64, 64, 0};
3620 static const RECT dst_rect64
= {0, 0, 64, 64};
3621 static const RECT dst_rect64_flipy
= {0, 64, 64, 0};
3623 window
= create_window();
3624 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
3625 ok(!!d3d
, "Failed to create a D3D object.\n");
3626 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
3628 skip("Failed to create a D3D device, skipping tests.\n");
3632 /* Create our temporary surfaces in system memory. */
3633 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 32, 32,
3634 D3DFMT_A8R8G8B8
, D3DPOOL_SYSTEMMEM
, &surf_temp32
, NULL
);
3635 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
3636 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 64, 64,
3637 D3DFMT_A8R8G8B8
, D3DPOOL_SYSTEMMEM
, &surf_temp64
, NULL
);
3638 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
3640 /* Create offscreen plain surfaces in D3DPOOL_DEFAULT. */
3641 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 32, 32,
3642 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &surf_offscreen32
, NULL
);
3643 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
3644 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 64, 64,
3645 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &surf_offscreen64
, NULL
);
3646 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
3647 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 64, 64,
3648 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &surf_offscreen_dest64
, NULL
);
3649 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
3651 /* Create render target surfaces. */
3652 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 32, 32,
3653 D3DFMT_A8R8G8B8
, D3DMULTISAMPLE_NONE
, 0, TRUE
, &surf_rt32
, NULL
);
3654 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
3655 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 64, 64,
3656 D3DFMT_A8R8G8B8
, D3DMULTISAMPLE_NONE
, 0, TRUE
, &surf_rt64
, NULL
);
3657 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
3658 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 64, 64,
3659 D3DFMT_A8R8G8B8
, D3DMULTISAMPLE_NONE
, 0, TRUE
, &surf_rt_dest64
, NULL
);
3660 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
3661 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
3662 ok(SUCCEEDED(hr
), "Failed to get back buffer, hr %#x.\n", hr
);
3664 /* Create render target textures. */
3665 hr
= IDirect3DDevice9_CreateTexture(device
, 32, 32, 1, D3DUSAGE_RENDERTARGET
,
3666 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex_rt32
, NULL
);
3667 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
3668 hr
= IDirect3DDevice9_CreateTexture(device
, 64, 64, 1, D3DUSAGE_RENDERTARGET
,
3669 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex_rt64
, NULL
);
3670 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
3671 hr
= IDirect3DDevice9_CreateTexture(device
, 64, 64, 1, D3DUSAGE_RENDERTARGET
,
3672 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex_rt_dest64
, NULL
);
3673 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
3674 hr
= IDirect3DDevice9_CreateTexture(device
, 640, 480, 1, D3DUSAGE_RENDERTARGET
,
3675 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex_rt_dest640_480
, NULL
);
3676 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
3677 hr
= IDirect3DTexture9_GetSurfaceLevel(tex_rt32
, 0, &surf_tex_rt32
);
3678 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
3679 hr
= IDirect3DTexture9_GetSurfaceLevel(tex_rt64
, 0, &surf_tex_rt64
);
3680 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
3681 hr
= IDirect3DTexture9_GetSurfaceLevel(tex_rt_dest64
, 0, &surf_tex_rt_dest64
);
3682 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
3683 hr
= IDirect3DTexture9_GetSurfaceLevel(tex_rt_dest640_480
, 0, &surf_tex_rt_dest640_480
);
3684 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
3686 /* Create regular textures in D3DPOOL_DEFAULT. */
3687 hr
= IDirect3DDevice9_CreateTexture(device
, 32, 32, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex32
, NULL
);
3688 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
3689 hr
= IDirect3DDevice9_CreateTexture(device
, 64, 64, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex64
, NULL
);
3690 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
3691 hr
= IDirect3DDevice9_CreateTexture(device
, 64, 64, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex_dest64
, NULL
);
3692 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
3693 hr
= IDirect3DTexture9_GetSurfaceLevel(tex32
, 0, &surf_tex32
);
3694 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
3695 hr
= IDirect3DTexture9_GetSurfaceLevel(tex64
, 0, &surf_tex64
);
3696 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
3697 hr
= IDirect3DTexture9_GetSurfaceLevel(tex_dest64
, 0, &surf_tex_dest64
);
3698 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
3700 /**********************************************************************
3701 * Tests for when the source parameter is an offscreen plain surface. *
3702 **********************************************************************/
3704 /* Fill the offscreen 64x64 surface with green. */
3705 fill_surface(surf_offscreen64
, 0xff00ff00, 0);
3707 /* offscreenplain ==> offscreenplain, same size. */
3708 hr
= IDirect3DDevice9_StretchRect(device
, surf_offscreen64
, NULL
, surf_offscreen_dest64
, NULL
, D3DTEXF_NONE
);
3709 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3710 color
= getPixelColorFromSurface(surf_offscreen_dest64
, 32, 32);
3711 ok(color
== 0xff00ff00, "Got unexpected color 0x%08x.\n", color
);
3712 /* Blit without scaling. */
3713 hr
= IDirect3DDevice9_StretchRect(device
, surf_offscreen64
, &src_rect64
,
3714 surf_offscreen_dest64
, &dst_rect64
, D3DTEXF_NONE
);
3715 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3716 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3717 hr
= IDirect3DDevice9_StretchRect(device
, surf_offscreen64
, &src_rect64_flipy
,
3718 surf_offscreen_dest64
, &dst_rect64
, D3DTEXF_NONE
);
3719 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3720 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3721 hr
= IDirect3DDevice9_StretchRect(device
, surf_offscreen64
, &src_rect64
,
3722 surf_offscreen_dest64
, &dst_rect64_flipy
, D3DTEXF_NONE
);
3723 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3725 /* offscreenplain ==> rendertarget texture, same size. */
3726 hr
= IDirect3DDevice9_StretchRect(device
, surf_offscreen64
, NULL
, surf_tex_rt_dest64
, NULL
, D3DTEXF_NONE
);
3727 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3728 /* We can't lock rendertarget textures, so copy to our temp surface first. */
3729 hr
= IDirect3DDevice9_GetRenderTargetData(device
, surf_tex_rt_dest64
, surf_temp64
);
3730 ok(SUCCEEDED(hr
), "Failed to get render target data, hr %#x.\n", hr
);
3731 color
= getPixelColorFromSurface(surf_temp64
, 32, 32);
3732 ok(color
== 0xff00ff00, "Got unexpected color 0x%08x.\n", color
);
3733 /* Blit without scaling. */
3734 hr
= IDirect3DDevice9_StretchRect(device
, surf_offscreen64
, &src_rect64
,
3735 surf_tex_rt_dest64
, &dst_rect64
, D3DTEXF_NONE
);
3736 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3737 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3738 hr
= IDirect3DDevice9_StretchRect(device
, surf_offscreen64
, &src_rect64_flipy
,
3739 surf_tex_rt_dest64
, &dst_rect64
, D3DTEXF_NONE
);
3740 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3741 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3742 hr
= IDirect3DDevice9_StretchRect(device
, surf_offscreen64
, &src_rect64
,
3743 surf_tex_rt_dest64
, &dst_rect64_flipy
, D3DTEXF_NONE
);
3744 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3746 /* offscreenplain ==> rendertarget surface, same size. */
3747 hr
= IDirect3DDevice9_StretchRect(device
, surf_offscreen64
, NULL
, surf_rt_dest64
, NULL
, D3DTEXF_NONE
);
3748 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3749 color
= getPixelColorFromSurface(surf_rt_dest64
, 32, 32);
3750 ok(color
== 0xff00ff00, "Got unexpected color 0x%08x.\n", color
);
3751 /* Blit without scaling. */
3752 hr
= IDirect3DDevice9_StretchRect(device
, surf_offscreen64
, &src_rect64
,
3753 surf_rt_dest64
, &dst_rect64
, D3DTEXF_NONE
);
3754 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3755 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3756 hr
= IDirect3DDevice9_StretchRect(device
, surf_offscreen64
, &src_rect64_flipy
,
3757 surf_rt_dest64
, &dst_rect64
, D3DTEXF_NONE
);
3758 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3759 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3760 hr
= IDirect3DDevice9_StretchRect(device
, surf_offscreen64
, &src_rect64
,
3761 surf_rt_dest64
, &dst_rect64_flipy
, D3DTEXF_NONE
);
3762 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3764 /* offscreenplain ==> texture, same size (should fail). */
3765 hr
= IDirect3DDevice9_StretchRect(device
, surf_offscreen64
, NULL
, surf_tex_dest64
, NULL
, D3DTEXF_NONE
);
3766 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3768 /* Fill the smaller offscreen surface with red. */
3769 fill_surface(surf_offscreen32
, 0xffff0000, 0);
3771 /* offscreenplain ==> offscreenplain, scaling (should fail). */
3772 hr
= IDirect3DDevice9_StretchRect(device
, surf_offscreen32
, NULL
, surf_offscreen64
, NULL
, D3DTEXF_NONE
);
3773 todo_wine
ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3775 /* offscreenplain ==> rendertarget texture, scaling. */
3776 hr
= IDirect3DDevice9_StretchRect(device
, surf_offscreen32
, NULL
, surf_tex_rt_dest64
, NULL
, D3DTEXF_NONE
);
3777 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3778 /* We can't lock rendertarget textures, so copy to our temp surface first. */
3779 hr
= IDirect3DDevice9_GetRenderTargetData(device
, surf_tex_rt_dest64
, surf_temp64
);
3780 ok(SUCCEEDED(hr
), "Failed to get render target data, hr %#x.\n", hr
);
3781 color
= getPixelColorFromSurface(surf_temp64
, 48, 48);
3782 ok(color
== 0xffff0000, "Got unexpected color 0x%08x.\n", color
);
3784 /* offscreenplain ==> rendertarget surface, scaling. */
3785 hr
= IDirect3DDevice9_StretchRect(device
, surf_offscreen32
, NULL
, surf_rt_dest64
, NULL
, D3DTEXF_NONE
);
3786 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3787 color
= getPixelColorFromSurface(surf_rt_dest64
, 48, 48);
3788 ok(color
== 0xffff0000, "Got unexpected color 0x%08x.\n", color
);
3790 /* offscreenplain ==> texture, scaling (should fail). */
3791 hr
= IDirect3DDevice9_StretchRect(device
, surf_offscreen32
, NULL
, surf_tex_dest64
, NULL
, D3DTEXF_NONE
);
3792 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3794 /*************************************************************
3795 * Tests for when the source parameter is a regular texture. *
3796 *************************************************************/
3798 /* Fill the surface of the regular texture with blue. */
3799 /* Can't fill the surf_tex directly because it's created in D3DPOOL_DEFAULT. */
3800 fill_surface(surf_temp64
, 0xff0000ff, 0);
3801 hr
= IDirect3DDevice9_UpdateSurface(device
, surf_temp64
, NULL
, surf_tex64
, NULL
);
3802 ok(SUCCEEDED(hr
), "Failed to update surface, hr %#x.\n", hr
);
3804 /* texture ==> offscreenplain, same size. */
3805 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex64
, NULL
, surf_offscreen64
, NULL
, D3DTEXF_NONE
);
3806 todo_wine
ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3808 /* texture ==> rendertarget texture, same size. */
3809 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex64
, NULL
, surf_tex_rt_dest64
, NULL
, D3DTEXF_NONE
);
3810 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3811 /* We can't lock rendertarget textures, so copy to our temp surface first. */
3812 hr
= IDirect3DDevice9_GetRenderTargetData(device
, surf_tex_rt_dest64
, surf_temp64
);
3813 ok(SUCCEEDED(hr
), "Failed to get render target data, hr %#x.\n", hr
);
3814 color
= getPixelColorFromSurface(surf_temp64
, 32, 32);
3815 ok(color
== 0xff0000ff, "Got unexpected color 0x%08x.\n", color
);
3816 /* Blit without scaling. */
3817 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex64
, &src_rect64
,
3818 surf_tex_rt_dest64
, &dst_rect64
, D3DTEXF_NONE
);
3819 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3820 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3821 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex64
, &src_rect64_flipy
,
3822 surf_tex_rt_dest64
, &dst_rect64
, D3DTEXF_NONE
);
3823 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3824 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3825 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex64
, &src_rect64
,
3826 surf_tex_rt_dest64
, &dst_rect64_flipy
, D3DTEXF_NONE
);
3827 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3829 /* texture ==> rendertarget surface, same size. */
3830 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex64
, NULL
, surf_rt_dest64
, NULL
, D3DTEXF_NONE
);
3831 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3832 color
= getPixelColorFromSurface(surf_rt_dest64
, 32, 32);
3833 ok(color
== 0xff0000ff, "Got unexpected color 0x%08x.\n", color
);
3834 /* Blit without scaling. */
3835 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex64
, &src_rect64
,
3836 surf_rt_dest64
, &dst_rect64
, D3DTEXF_NONE
);
3837 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3838 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3839 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex64
, &src_rect64_flipy
,
3840 surf_rt_dest64
, &dst_rect64
, D3DTEXF_NONE
);
3841 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3842 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3843 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex64
, &src_rect64
,
3844 surf_rt_dest64
, &dst_rect64_flipy
, D3DTEXF_NONE
);
3845 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3847 /* texture ==> texture, same size (should fail). */
3848 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex64
, NULL
, surf_tex_dest64
, NULL
, D3DTEXF_NONE
);
3849 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3851 /* Fill the surface of the smaller regular texture with red. */
3852 /* Can't fill the surf_tex directly because it's created in D3DPOOL_DEFAULT. */
3853 fill_surface(surf_temp32
, 0xffff0000, 0);
3854 hr
= IDirect3DDevice9_UpdateSurface(device
, surf_temp32
, NULL
, surf_tex32
, NULL
);
3855 ok(SUCCEEDED(hr
), "Failed to update surface, hr %#x.\n", hr
);
3857 /* texture ==> offscreenplain, scaling (should fail). */
3858 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex32
, NULL
, surf_offscreen64
, NULL
, D3DTEXF_NONE
);
3859 todo_wine
ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3861 /* texture ==> rendertarget texture, scaling. */
3862 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex32
, NULL
, surf_tex_rt_dest64
, NULL
, D3DTEXF_NONE
);
3863 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3864 /* We can't lock rendertarget textures, so copy to our temp surface first. */
3865 hr
= IDirect3DDevice9_GetRenderTargetData(device
, surf_tex_rt_dest64
, surf_temp64
);
3866 ok(SUCCEEDED(hr
), "Failed to get render target data, hr %#x.\n", hr
);
3867 color
= getPixelColorFromSurface(surf_temp64
, 48, 48);
3868 ok(color
== 0xffff0000, "Got unexpected color 0x%08x.\n", color
);
3870 /* texture ==> rendertarget surface, scaling. */
3871 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex32
, NULL
, surf_rt_dest64
, NULL
, D3DTEXF_NONE
);
3872 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3873 color
= getPixelColorFromSurface(surf_rt_dest64
, 48, 48);
3874 ok(color
== 0xffff0000, "Got unexpected color 0x%08x.\n", color
);
3876 /* texture ==> texture, scaling (should fail). */
3877 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex32
, NULL
, surf_tex_dest64
, NULL
, D3DTEXF_NONE
);
3878 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3880 /******************************************************************
3881 * Tests for when the source parameter is a rendertarget texture. *
3882 ******************************************************************/
3884 /* Fill the surface of the rendertarget texture with white. */
3885 /* Can't fill the surf_tex_rt directly because it's created in D3DPOOL_DEFAULT. */
3886 fill_surface(surf_temp64
, 0xffffffff, 0);
3887 hr
= IDirect3DDevice9_UpdateSurface(device
, surf_temp64
, NULL
, surf_tex_rt64
, NULL
);
3888 ok(SUCCEEDED(hr
), "Failed to update surface, hr %#x.\n", hr
);
3890 /* rendertarget texture ==> offscreenplain, same size. */
3891 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex_rt64
, NULL
, surf_offscreen64
, NULL
, D3DTEXF_NONE
);
3892 todo_wine
ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3894 /* rendertarget texture ==> rendertarget texture, same size. */
3895 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex_rt64
, NULL
, surf_tex_rt_dest64
, NULL
, D3DTEXF_NONE
);
3896 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3897 /* We can't lock rendertarget textures, so copy to our temp surface first. */
3898 hr
= IDirect3DDevice9_GetRenderTargetData(device
, surf_tex_rt_dest64
, surf_temp64
);
3899 ok(SUCCEEDED(hr
), "Failed to get render target data, hr %#x.\n", hr
);
3900 color
= getPixelColorFromSurface(surf_temp64
, 32, 32);
3901 ok(color
== 0xffffffff, "Got unexpected color 0x%08x.\n", color
);
3902 /* Blit without scaling. */
3903 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex_rt64
, &src_rect64
,
3904 surf_tex_rt_dest64
, &dst_rect64
, D3DTEXF_NONE
);
3905 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3906 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3907 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex_rt64
, &src_rect64_flipy
,
3908 surf_tex_rt_dest64
, &dst_rect64
, D3DTEXF_NONE
);
3909 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3910 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3911 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex_rt64
, &src_rect64
,
3912 surf_tex_rt_dest64
, &dst_rect64_flipy
, D3DTEXF_NONE
);
3913 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3915 /* rendertarget texture ==> rendertarget surface, same size. */
3916 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex_rt64
, NULL
, surf_rt_dest64
, NULL
, D3DTEXF_NONE
);
3917 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3918 color
= getPixelColorFromSurface(surf_rt_dest64
, 32, 32);
3919 ok(color
== 0xffffffff, "Got unexpected color 0x%08x.\n", color
);
3920 /* Blit without scaling. */
3921 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex_rt64
, &src_rect64
,
3922 surf_rt_dest64
, &dst_rect64
, D3DTEXF_NONE
);
3923 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3924 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3925 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex_rt64
, &src_rect64_flipy
,
3926 surf_rt_dest64
, &dst_rect64
, D3DTEXF_NONE
);
3927 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3928 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3929 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex_rt64
, &src_rect64
,
3930 surf_rt_dest64
, &dst_rect64_flipy
, D3DTEXF_NONE
);
3931 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3933 /* rendertarget texture ==> texture, same size (should fail). */
3934 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex_rt64
, NULL
, surf_tex_dest64
, NULL
, D3DTEXF_NONE
);
3935 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3937 /* Fill the surface of the smaller rendertarget texture with red. */
3938 /* Can't fill the surf_tex_rt directly because it's created in D3DPOOL_DEFAULT. */
3939 fill_surface(surf_temp32
, 0xffff0000, 0);
3940 hr
= IDirect3DDevice9_UpdateSurface(device
, surf_temp32
, NULL
, surf_tex_rt32
, NULL
);
3941 ok(SUCCEEDED(hr
), "Failed to update surface, hr %#x.\n", hr
);
3943 /* rendertarget texture ==> offscreenplain, scaling (should fail). */
3944 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex_rt32
, NULL
, surf_offscreen64
, NULL
, D3DTEXF_NONE
);
3945 todo_wine
ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3947 /* rendertarget texture ==> rendertarget texture, scaling. */
3948 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex_rt32
, NULL
, surf_tex_rt_dest64
, NULL
, D3DTEXF_NONE
);
3949 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3950 /* We can't lock rendertarget textures, so copy to our temp surface first. */
3951 hr
= IDirect3DDevice9_GetRenderTargetData(device
, surf_tex_rt_dest64
, surf_temp64
);
3952 ok(SUCCEEDED(hr
), "Failed to get render target data, hr %#x.\n", hr
);
3953 color
= getPixelColorFromSurface(surf_temp64
, 48, 48);
3954 ok(color
== 0xffff0000, "Got unexpected color 0x%08x.\n", color
);
3956 /* rendertarget texture ==> rendertarget surface, scaling. */
3957 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex_rt32
, NULL
, surf_rt_dest64
, NULL
, D3DTEXF_NONE
);
3958 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3959 color
= getPixelColorFromSurface(surf_rt_dest64
, 48, 48);
3960 ok(color
== 0xffff0000, "Got unexpected color 0x%08x.\n", color
);
3962 /* rendertarget texture ==> texture, scaling (should fail). */
3963 hr
= IDirect3DDevice9_StretchRect(device
, surf_tex_rt32
, NULL
, surf_tex_dest64
, NULL
, D3DTEXF_NONE
);
3964 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3966 /******************************************************************
3967 * Tests for when the source parameter is a rendertarget surface. *
3968 ******************************************************************/
3970 /* Fill the surface of the rendertarget surface with black. */
3971 fill_surface(surf_rt64
, 0xff000000, 0);
3973 /* rendertarget texture ==> offscreenplain, same size. */
3974 hr
= IDirect3DDevice9_StretchRect(device
, surf_rt64
, NULL
, surf_offscreen64
, NULL
, D3DTEXF_NONE
);
3975 todo_wine
ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3977 /* rendertarget surface ==> rendertarget texture, same size. */
3978 hr
= IDirect3DDevice9_StretchRect(device
, surf_rt64
, NULL
, surf_tex_rt_dest64
, NULL
, D3DTEXF_NONE
);
3979 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3980 /* We can't lock rendertarget textures, so copy to our temp surface first. */
3981 hr
= IDirect3DDevice9_GetRenderTargetData(device
, surf_tex_rt_dest64
, surf_temp64
);
3982 ok(SUCCEEDED(hr
), "Failed to get render target data, hr %#x.\n", hr
);
3983 color
= getPixelColorFromSurface(surf_temp64
, 32, 32);
3984 ok(color
== 0xff000000, "Got unexpected color 0x%08x.\n", color
);
3985 /* Blit without scaling. */
3986 hr
= IDirect3DDevice9_StretchRect(device
, surf_rt64
, &src_rect64
,
3987 surf_tex_rt_dest64
, &dst_rect64
, D3DTEXF_NONE
);
3988 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
3989 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
3990 hr
= IDirect3DDevice9_StretchRect(device
, surf_rt64
, &src_rect64_flipy
,
3991 surf_tex_rt_dest64
, &dst_rect64
, D3DTEXF_NONE
);
3992 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3993 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
3994 hr
= IDirect3DDevice9_StretchRect(device
, surf_rt64
, &src_rect64
,
3995 surf_tex_rt_dest64
, &dst_rect64_flipy
, D3DTEXF_NONE
);
3996 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
3998 /* rendertarget surface ==> rendertarget surface, same size. */
3999 hr
= IDirect3DDevice9_StretchRect(device
, surf_rt64
, NULL
, surf_rt_dest64
, NULL
, D3DTEXF_NONE
);
4000 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4001 color
= getPixelColorFromSurface(surf_rt_dest64
, 32, 32);
4002 ok(color
== 0xff000000, "Got unexpected color 0x%08x.\n", color
);
4003 /* Blit without scaling. */
4004 hr
= IDirect3DDevice9_StretchRect(device
, surf_rt64
, &src_rect64
,
4005 surf_rt_dest64
, &dst_rect64
, D3DTEXF_NONE
);
4006 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4007 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
4008 hr
= IDirect3DDevice9_StretchRect(device
, surf_rt64
, &src_rect64_flipy
,
4009 surf_rt_dest64
, &dst_rect64_flipy
, D3DTEXF_NONE
);
4010 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4011 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
4012 hr
= IDirect3DDevice9_StretchRect(device
, surf_rt64
, &src_rect64
,
4013 surf_rt_dest64
, &dst_rect64_flipy
, D3DTEXF_NONE
);
4014 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4016 /* rendertarget surface ==> texture, same size (should fail). */
4017 hr
= IDirect3DDevice9_StretchRect(device
, surf_rt64
, NULL
, surf_tex_dest64
, NULL
, D3DTEXF_NONE
);
4018 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4020 /* Fill the surface of the smaller rendertarget texture with red. */
4021 fill_surface(surf_rt32
, 0xffff0000, 0);
4023 /* rendertarget surface ==> offscreenplain, scaling (should fail). */
4024 hr
= IDirect3DDevice9_StretchRect(device
, surf_rt32
, NULL
, surf_offscreen64
, NULL
, D3DTEXF_NONE
);
4025 todo_wine
ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4027 /* rendertarget surface ==> rendertarget texture, scaling. */
4028 hr
= IDirect3DDevice9_StretchRect(device
, surf_rt32
, NULL
, surf_tex_rt_dest64
, NULL
, D3DTEXF_NONE
);
4029 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4030 /* We can't lock rendertarget textures, so copy to our temp surface first. */
4031 hr
= IDirect3DDevice9_GetRenderTargetData(device
, surf_tex_rt_dest64
, surf_temp64
);
4032 ok(SUCCEEDED(hr
), "Failed to get render target data, hr %#x.\n", hr
);
4033 color
= getPixelColorFromSurface(surf_temp64
, 48, 48);
4034 ok(color
== 0xffff0000, "Got unexpected color 0x%08x.\n", color
);
4036 /* rendertarget surface ==> rendertarget surface, scaling. */
4037 hr
= IDirect3DDevice9_StretchRect(device
, surf_rt32
, NULL
, surf_rt_dest64
, NULL
, D3DTEXF_NONE
);
4038 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4039 color
= getPixelColorFromSurface(surf_rt_dest64
, 48, 48);
4040 ok(color
== 0xffff0000, "Got unexpected color 0x%08x.\n", color
);
4042 /* rendertarget surface ==> texture, scaling (should fail). */
4043 hr
= IDirect3DDevice9_StretchRect(device
, surf_rt32
, NULL
, surf_tex_dest64
, NULL
, D3DTEXF_NONE
);
4044 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4046 /* backbuffer ==> surface tests (no scaling). */
4047 /* Blit with NULL rectangles. */
4048 hr
= IDirect3DDevice9_StretchRect(device
, backbuffer
, NULL
, surf_tex_rt_dest640_480
, NULL
, D3DTEXF_NONE
);
4049 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4050 /* Blit without scaling. */
4051 hr
= IDirect3DDevice9_StretchRect(device
, backbuffer
, &src_rect
,
4052 surf_tex_rt_dest640_480
, &dst_rect
, D3DTEXF_NONE
);
4053 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4054 /* Flipping in y-direction through src_rect, no scaling (not allowed). */
4055 hr
= IDirect3DDevice9_StretchRect(device
, backbuffer
, &src_rect_flipy
,
4056 surf_tex_rt_dest640_480
, &dst_rect
, D3DTEXF_NONE
);
4057 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4058 /* Flipping in y-direction through dst_rect, no scaling (not allowed). */
4059 hr
= IDirect3DDevice9_StretchRect(device
, backbuffer
, &src_rect
,
4060 surf_tex_rt_dest640_480
, &dst_rect_flipy
, D3DTEXF_NONE
);
4061 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4063 /* TODO: Test format conversions. */
4065 IDirect3DSurface9_Release(backbuffer
);
4066 IDirect3DSurface9_Release(surf_rt32
);
4067 IDirect3DSurface9_Release(surf_rt64
);
4068 IDirect3DSurface9_Release(surf_rt_dest64
);
4069 IDirect3DSurface9_Release(surf_temp32
);
4070 IDirect3DSurface9_Release(surf_temp64
);
4071 IDirect3DSurface9_Release(surf_offscreen32
);
4072 IDirect3DSurface9_Release(surf_offscreen64
);
4073 IDirect3DSurface9_Release(surf_offscreen_dest64
);
4074 IDirect3DSurface9_Release(surf_tex_rt32
);
4075 IDirect3DTexture9_Release(tex_rt32
);
4076 IDirect3DSurface9_Release(surf_tex_rt64
);
4077 IDirect3DTexture9_Release(tex_rt64
);
4078 IDirect3DSurface9_Release(surf_tex_rt_dest64
);
4079 IDirect3DTexture9_Release(tex_rt_dest64
);
4080 IDirect3DSurface9_Release(surf_tex_rt_dest640_480
);
4081 IDirect3DTexture9_Release(tex_rt_dest640_480
);
4082 IDirect3DSurface9_Release(surf_tex32
);
4083 IDirect3DTexture9_Release(tex32
);
4084 IDirect3DSurface9_Release(surf_tex64
);
4085 IDirect3DTexture9_Release(tex64
);
4086 IDirect3DSurface9_Release(surf_tex_dest64
);
4087 IDirect3DTexture9_Release(tex_dest64
);
4088 refcount
= IDirect3DDevice9_Release(device
);
4089 ok(!refcount
, "Device has %u references left.\n", refcount
);
4091 IDirect3D9_Release(d3d
);
4092 DestroyWindow(window
);
4095 static void test_multisample_stretch_rect(void)
4097 static const D3DTEXTUREFILTERTYPE filters
[] =
4103 IDirect3DSurface9
*rt
, *ms_rt
, *rt_r5g6b5
;
4104 struct surface_readback rb
;
4105 IDirect3DDevice9
*device
;
4106 DWORD quality_levels
;
4115 window
= create_window();
4116 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
4117 ok(!!d3d
, "Failed to create a D3D object.\n");
4119 if (IDirect3D9_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
4120 D3DFMT_A8R8G8B8
, TRUE
, D3DMULTISAMPLE_2_SAMPLES
, &quality_levels
) == D3DERR_NOTAVAILABLE
)
4122 skip("Multisampling not supported for D3DFMT_A8R8G8B8.\n");
4123 IDirect3D9_Release(d3d
);
4124 DestroyWindow(window
);
4128 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
4130 skip("Failed to create a 3D device.\n");
4131 IDirect3D9_Release(d3d
);
4132 DestroyWindow(window
);
4136 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 128, 128,
4137 D3DFMT_A8R8G8B8
, D3DMULTISAMPLE_NONE
, 0, FALSE
, &rt
, NULL
);
4138 ok(hr
== S_OK
, "Failed to create render target, hr %#x.\n", hr
);
4139 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 128, 128,
4140 D3DFMT_A8R8G8B8
, D3DMULTISAMPLE_2_SAMPLES
, quality_levels
- 1, FALSE
, &ms_rt
, NULL
);
4141 ok(hr
== S_OK
, "Failed to create render target, hr %#x.\n", hr
);
4143 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, ms_rt
);
4144 ok(hr
== D3D_OK
, "Failed to set render target, hr %#x.\n", hr
);
4145 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00ff00ff, 0.0f
, 0);
4146 ok(hr
== D3D_OK
, "Failed to clear, hr %#x.\n", hr
);
4148 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt
);
4149 ok(hr
== D3D_OK
, "Failed to set render target, hr %#x.\n", hr
);
4151 for (i
= 0; i
< ARRAY_SIZE(filters
); ++i
)
4153 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
4154 ok(hr
== D3D_OK
, "Test %u: Failed to clear, hr %#x.\n", i
, hr
);
4155 hr
= IDirect3DDevice9_StretchRect(device
, ms_rt
, NULL
, rt
, NULL
, filters
[i
]);
4156 ok(hr
== S_OK
, "Test %u: Failed to stretch rect, hr %#x.\n", i
, hr
);
4157 color
= getPixelColor(device
, 64, 64);
4158 ok(color
== 0x00ff00ff, "Test %u: Got color 0x%08x.\n", i
, color
);
4162 SetRect(&rect
, 0, 0, 64, 64);
4163 for (i
= 0; i
< ARRAY_SIZE(filters
); ++i
)
4165 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
4166 ok(hr
== D3D_OK
, "Test %u: Failed to clear, hr %#x.\n", i
, hr
);
4167 hr
= IDirect3DDevice9_StretchRect(device
, ms_rt
, NULL
, rt
, &rect
, filters
[i
]);
4168 ok(hr
== S_OK
, "Test %u: Failed to stretch rect, hr %#x.\n", i
, hr
);
4169 get_rt_readback(rt
, &rb
);
4170 color
= get_readback_color(&rb
, 32, 32);
4171 ok(color
== 0x00ff00ff, "Test %u: Got color 0x%08x.\n", i
, color
);
4172 color
= get_readback_color(&rb
, 64, 64);
4173 ok(color
== 0xffffffff, "Test %u: Got color 0x%08x.\n", i
, color
);
4174 color
= get_readback_color(&rb
, 96, 96);
4175 ok(color
== 0xffffffff, "Test %u: Got color 0x%08x.\n", i
, color
);
4176 release_surface_readback(&rb
);
4178 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
4179 ok(hr
== D3D_OK
, "Test %u: Failed to clear, hr %#x.\n", i
, hr
);
4180 hr
= IDirect3DDevice9_StretchRect(device
, ms_rt
, &rect
, rt
, NULL
, filters
[i
]);
4181 ok(hr
== S_OK
, "Test %u: Failed to stretch rect, hr %#x.\n", i
, hr
);
4182 get_rt_readback(rt
, &rb
);
4183 color
= get_readback_color(&rb
, 32, 32);
4184 ok(color
== 0x00ff00ff, "Test %u: Got color 0x%08x.\n", i
, color
);
4185 color
= get_readback_color(&rb
, 64, 64);
4186 ok(color
== 0x00ff00ff, "Test %u: Got color 0x%08x.\n", i
, color
);
4187 color
= get_readback_color(&rb
, 96, 96);
4188 ok(color
== 0x00ff00ff, "Test %u: Got color 0x%08x.\n", i
, color
);
4189 release_surface_readback(&rb
);
4192 /* Format conversion */
4193 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 128, 128,
4194 D3DFMT_R5G6B5
, D3DMULTISAMPLE_NONE
, 0, FALSE
, &rt_r5g6b5
, NULL
);
4197 skip("Failed to create D3DFMT_R5G6B5 render target.\n");
4201 for (i
= 0; i
< ARRAY_SIZE(filters
); ++i
)
4203 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
4204 ok(hr
== D3D_OK
, "Test %u: Failed to clear, hr %#x.\n", i
, hr
);
4205 hr
= IDirect3DDevice9_StretchRect(device
, ms_rt
, NULL
, rt_r5g6b5
, NULL
, filters
[i
]);
4206 ok(hr
== S_OK
, "Test %u: Failed to stretch rect, hr %#x.\n", i
, hr
);
4207 hr
= IDirect3DDevice9_StretchRect(device
, rt_r5g6b5
, NULL
, rt
, NULL
, filters
[i
]);
4208 ok(hr
== S_OK
, "Test %u: Failed to stretch rect, hr %#x.\n", i
, hr
);
4209 color
= getPixelColor(device
, 64, 64);
4210 ok(color
== 0x00ff00ff, "Test %u: Got color 0x%08x.\n", i
, color
);
4213 IDirect3DSurface9_Release(rt_r5g6b5
);
4216 IDirect3DSurface9_Release(ms_rt
);
4217 IDirect3DSurface9_Release(rt
);
4218 refcount
= IDirect3DDevice9_Release(device
);
4219 ok(!refcount
, "Device has %u references left.\n", refcount
);
4220 IDirect3D9_Release(d3d
);
4221 DestroyWindow(window
);
4224 static void maxmip_test(void)
4226 IDirect3DTexture9
*texture
;
4227 IDirect3DSurface9
*surface
;
4228 IDirect3DDevice9
*device
;
4249 {-1.0, -1.0, 0.0, 0.0, 0.0},
4250 {-1.0, 0.0, 0.0, 0.0, 1.0},
4251 { 0.0, -1.0, 0.0, 1.0, 0.0},
4252 { 0.0, 0.0, 0.0, 1.0, 1.0},
4255 { 0.0, -1.0, 0.0, 0.0, 0.0},
4256 { 0.0, 0.0, 0.0, 0.0, 1.0},
4257 { 1.0, -1.0, 0.0, 1.0, 0.0},
4258 { 1.0, 0.0, 0.0, 1.0, 1.0},
4261 { 0.0, 0.0, 0.0, 0.0, 0.0},
4262 { 0.0, 1.0, 0.0, 0.0, 1.0},
4263 { 1.0, 0.0, 0.0, 1.0, 0.0},
4264 { 1.0, 1.0, 0.0, 1.0, 1.0},
4267 {-1.0, 0.0, 0.0, 0.0, 0.0},
4268 {-1.0, 1.0, 0.0, 0.0, 1.0},
4269 { 0.0, 0.0, 0.0, 1.0, 0.0},
4270 { 0.0, 1.0, 0.0, 1.0, 1.0},
4274 window
= create_window();
4275 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
4276 ok(!!d3d
, "Failed to create a D3D object.\n");
4277 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
4279 skip("Failed to create a D3D device, skipping tests.\n");
4283 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
4284 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
4285 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_MIPMAP
))
4287 skip("No mipmap support, skipping tests.\n");
4288 IDirect3DDevice9_Release(device
);
4292 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 3, 0,
4293 D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &texture
, NULL
);
4294 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
4296 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
4297 ok(SUCCEEDED(hr
), "IDirect3DTexture9_GetSurfaceLevel returned %#x.\n", hr
);
4298 fill_surface(surface
, 0xffff0000, 0);
4299 IDirect3DSurface9_Release(surface
);
4300 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 1, &surface
);
4301 ok(SUCCEEDED(hr
), "IDirect3DTexture9_GetSurfaceLevel returned %#x.\n", hr
);
4302 fill_surface(surface
, 0xff00ff00, 0);
4303 IDirect3DSurface9_Release(surface
);
4304 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 2, &surface
);
4305 ok(SUCCEEDED(hr
), "IDirect3DTexture9_GetSurfaceLevel returned %#x.\n", hr
);
4306 fill_surface(surface
, 0xff0000ff, 0);
4307 IDirect3DSurface9_Release(surface
);
4309 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) texture
);
4310 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture failed with %08x\n", hr
);
4311 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
4312 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with %08x\n", hr
);
4314 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
4315 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
4316 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MIPFILTER
, D3DTEXF_NONE
);
4317 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState failed with %08x\n", hr
);
4319 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffffff, 0.0, 0);
4320 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
4322 hr
= IDirect3DDevice9_BeginScene(device
);
4323 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
4325 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 0);
4326 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
4327 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[0], sizeof(*quads
->v
));
4328 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4330 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 1);
4331 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
4332 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[1], sizeof(*quads
->v
));
4333 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4335 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 2);
4336 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
4337 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[2], sizeof(*quads
->v
));
4338 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4340 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 3);
4341 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
4342 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[3], sizeof(*quads
->v
));
4343 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4345 hr
= IDirect3DDevice9_EndScene(device
);
4346 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
4348 /* With mipmapping disabled, the max mip level is ignored, only level 0 is used */
4349 color
= getPixelColor(device
, 160, 360);
4350 ok(color
== 0x00ff0000, "MaxMip 0, no mipfilter has color 0x%08x.\n", color
);
4351 color
= getPixelColor(device
, 480, 360);
4352 ok(color
== 0x00ff0000, "MaxMip 1, no mipfilter has color 0x%08x.\n", color
);
4353 color
= getPixelColor(device
, 480, 120);
4354 ok(color
== 0x00ff0000, "MaxMip 2, no mipfilter has color 0x%08x.\n", color
);
4355 color
= getPixelColor(device
, 160, 120);
4356 ok(color
== 0x00ff0000, "MaxMip 3, no mipfilter has color 0x%08x.\n", color
);
4357 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
4358 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
4360 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MIPFILTER
, D3DTEXF_POINT
);
4361 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState failed with %08x\n", hr
);
4363 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffffff, 0.0, 0);
4364 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
4366 hr
= IDirect3DDevice9_BeginScene(device
);
4367 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
4369 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 0);
4370 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
4371 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[0], sizeof(*quads
->v
));
4372 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4374 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 1);
4375 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
4376 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[1], sizeof(*quads
->v
));
4377 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4379 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 2);
4380 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
4381 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[2], sizeof(*quads
->v
));
4382 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4384 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 3);
4385 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
4386 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[3], sizeof(*quads
->v
));
4387 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4389 hr
= IDirect3DDevice9_EndScene(device
);
4390 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
4392 /* Max Mip level 0-2 sample from the specified texture level, Max Mip
4393 * level 3 (> levels in texture) samples from the highest level in the
4394 * texture (level 2). */
4395 color
= getPixelColor(device
, 160, 360);
4396 ok(color
== 0x00ff0000, "MaxMip 0, point mipfilter has color 0x%08x.\n", color
);
4397 color
= getPixelColor(device
, 480, 360);
4398 ok(color
== 0x0000ff00, "MaxMip 1, point mipfilter has color 0x%08x.\n", color
);
4399 color
= getPixelColor(device
, 480, 120);
4400 ok(color
== 0x000000ff, "MaxMip 2, point mipfilter has color 0x%08x.\n", color
);
4401 color
= getPixelColor(device
, 160, 120);
4402 ok(color
== 0x000000ff, "MaxMip 3, point mipfilter has color 0x%08x.\n", color
);
4403 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
4404 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
4406 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffffff, 0.0, 0);
4407 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
4409 hr
= IDirect3DDevice9_BeginScene(device
);
4410 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
4412 /* Mipmapping OFF, LOD level smaller than MAXMIPLEVEL. LOD level limits */
4413 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MIPFILTER
, D3DTEXF_NONE
);
4414 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
4415 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 0);
4416 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
4417 ret
= IDirect3DTexture9_SetLOD(texture
, 1);
4418 ok(ret
== 0, "Got unexpected LOD %u.\n", ret
);
4419 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[0], sizeof(*quads
->v
));
4420 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4422 /* Mipmapping ON, LOD level smaller than max mip level. LOD level limits */
4423 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MIPFILTER
, D3DTEXF_POINT
);
4424 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
4425 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 1);
4426 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
4427 ret
= IDirect3DTexture9_SetLOD(texture
, 2);
4428 ok(ret
== 1, "Got unexpected LOD %u.\n", ret
);
4429 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[1], sizeof(*quads
->v
));
4430 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4432 /* Mipmapping ON, LOD level bigger than max mip level. MAXMIPLEVEL limits */
4433 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 2);
4434 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
4435 ret
= IDirect3DTexture9_SetLOD(texture
, 1);
4436 ok(ret
== 2, "Got unexpected LOD %u.\n", ret
);
4437 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[2], sizeof(*quads
->v
));
4438 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4440 /* Mipmapping OFF, LOD level bigger than max mip level. LOD level limits */
4441 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MIPFILTER
, D3DTEXF_NONE
);
4442 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
4443 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 2);
4444 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
4445 ret
= IDirect3DTexture9_SetLOD(texture
, 1);
4446 ok(ret
== 1, "Got unexpected LOD %u.\n", ret
);
4447 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[3], sizeof(*quads
->v
));
4448 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4450 hr
= IDirect3DDevice9_EndScene(device
);
4451 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
4453 /* Max Mip level 0-2 sample from the specified texture level, Max Mip
4454 * level 3 (> levels in texture) samples from the highest level in the
4455 * texture (level 2). */
4456 color
= getPixelColor(device
, 160, 360);
4457 ok(color
== 0x0000ff00, "MaxMip 0, LOD 1, none mipfilter has color 0x%08x.\n", color
);
4458 color
= getPixelColor(device
, 480, 360);
4459 ok(color
== 0x000000ff, "MaxMip 1, LOD 2, point mipfilter has color 0x%08x.\n", color
);
4460 color
= getPixelColor(device
, 480, 120);
4461 ok(color
== 0x000000ff, "MaxMip 2, LOD 1, point mipfilter has color 0x%08x.\n", color
);
4462 color
= getPixelColor(device
, 160, 120);
4463 ok(color
== 0x0000ff00, "MaxMip 2, LOD 1, none mipfilter has color 0x%08x.\n", color
);
4465 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
4466 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
4468 IDirect3DTexture9_Release(texture
);
4469 refcount
= IDirect3DDevice9_Release(device
);
4470 ok(!refcount
, "Device has %u references left.\n", refcount
);
4472 IDirect3D9_Release(d3d
);
4473 DestroyWindow(window
);
4476 static void release_buffer_test(void)
4478 IDirect3DVertexBuffer9
*vb
;
4479 IDirect3DIndexBuffer9
*ib
;
4480 IDirect3DDevice9
*device
;
4489 static const short indices
[] = {3, 4, 5};
4492 struct vec3 position
;
4497 {{-1.0f
, -1.0f
, 0.1f
}, 0xffff0000},
4498 {{-1.0f
, 1.0f
, 0.1f
}, 0xffff0000},
4499 {{ 1.0f
, 1.0f
, 0.1f
}, 0xffff0000},
4501 {{-1.0f
, -1.0f
, 0.1f
}, 0xff00ff00},
4502 {{-1.0f
, 1.0f
, 0.1f
}, 0xff00ff00},
4503 {{ 1.0f
, 1.0f
, 0.1f
}, 0xff00ff00},
4506 window
= create_window();
4507 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
4508 ok(!!d3d
, "Failed to create a D3D object.\n");
4509 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
4511 skip("Failed to create a D3D device, skipping tests.\n");
4515 /* Index and vertex buffers should always be creatable */
4516 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, sizeof(quad
), 0,
4517 D3DFVF_XYZ
| D3DFVF_DIFFUSE
, D3DPOOL_MANAGED
, &vb
, NULL
);
4518 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
4519 hr
= IDirect3DVertexBuffer9_Lock(vb
, 0, sizeof(quad
), (void **) &data
, 0);
4520 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr
);
4521 memcpy(data
, quad
, sizeof(quad
));
4522 hr
= IDirect3DVertexBuffer9_Unlock(vb
);
4523 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Unlock failed with %08x\n", hr
);
4525 hr
= IDirect3DDevice9_CreateIndexBuffer(device
, sizeof(indices
), 0,
4526 D3DFMT_INDEX16
, D3DPOOL_DEFAULT
, &ib
, NULL
);
4527 ok(SUCCEEDED(hr
), "Failed to create index buffer, hr %#x.\n", hr
);
4528 hr
= IDirect3DIndexBuffer9_Lock(ib
, 0, sizeof(indices
), (void **) &data
, 0);
4529 ok(hr
== D3D_OK
, "IDirect3DIndexBuffer9_Lock failed with %08x\n", hr
);
4530 memcpy(data
, indices
, sizeof(indices
));
4531 hr
= IDirect3DIndexBuffer9_Unlock(ib
);
4532 ok(hr
== D3D_OK
, "IDirect3DIndexBuffer9_Unlock failed with %08x\n", hr
);
4534 hr
= IDirect3DDevice9_SetIndices(device
, ib
);
4535 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetIndices failed with %08x\n", hr
);
4536 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vb
, 0, sizeof(quad
[0]));
4537 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetStreamSource failed with %08x\n", hr
);
4538 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
4539 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with %08x\n", hr
);
4540 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
4541 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
4543 /* Now destroy the bound index buffer and draw again */
4544 ref
= IDirect3DIndexBuffer9_Release(ib
);
4545 ok(ref
== 0, "Index Buffer reference count is %08d\n", ref
);
4547 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff0000ff, 1.0f
, 0);
4548 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
4550 hr
= IDirect3DDevice9_BeginScene(device
);
4551 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
4552 /* Deliberately using minvertexindex = 0 and numVertices = 6 to prevent
4553 * D3D from making assumptions about the indices or vertices. */
4554 hr
= IDirect3DDevice9_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, 0, 3, 3, 0, 1);
4555 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4556 hr
= IDirect3DDevice9_EndScene(device
);
4557 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
4559 color
= getPixelColor(device
, 160, 120);
4560 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 1), "Got unexpected color 0x%08x.\n", color
);
4561 color
= getPixelColor(device
, 480, 360);
4562 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0xff), 1), "Got unexpected color 0x%08x.\n", color
);
4564 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
4565 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
4567 /* Index buffer was already destroyed as part of the test */
4568 IDirect3DVertexBuffer9_Release(vb
);
4569 refcount
= IDirect3DDevice9_Release(device
);
4570 ok(!refcount
, "Device has %u references left.\n", refcount
);
4572 IDirect3D9_Release(d3d
);
4573 DestroyWindow(window
);
4576 static void float_texture_test(void)
4578 IDirect3DTexture9
*texture
;
4579 IDirect3DDevice9
*device
;
4588 static const float quad
[] =
4590 -1.0f
, -1.0f
, 0.1f
, 0.0f
, 0.0f
,
4591 -1.0f
, 1.0f
, 0.1f
, 0.0f
, 1.0f
,
4592 1.0f
, -1.0f
, 0.1f
, 1.0f
, 0.0f
,
4593 1.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
,
4596 window
= create_window();
4597 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
4598 ok(!!d3d
, "Failed to create a D3D object.\n");
4599 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
4601 skip("Failed to create a D3D device, skipping tests.\n");
4605 if (IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
,
4606 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_TEXTURE
, D3DFMT_R32F
) != D3D_OK
)
4608 skip("D3DFMT_R32F textures not supported\n");
4609 IDirect3DDevice9_Release(device
);
4613 hr
= IDirect3DDevice9_CreateTexture(device
, 1, 1, 1, 0, D3DFMT_R32F
, D3DPOOL_MANAGED
, &texture
, NULL
);
4614 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
4616 memset(&lr
, 0, sizeof(lr
));
4617 hr
= IDirect3DTexture9_LockRect(texture
, 0, &lr
, NULL
, 0);
4618 ok(hr
== D3D_OK
, "IDirect3DTexture9_LockRect failed with %08x\n", hr
);
4621 hr
= IDirect3DTexture9_UnlockRect(texture
, 0);
4622 ok(hr
== D3D_OK
, "IDirect3DTexture9_UnlockRect failed with %08x\n", hr
);
4624 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
4625 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
4626 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)texture
);
4627 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture failed with %08x\n", hr
);
4629 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff0000ff, 1.0f
, 0);
4630 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
4632 hr
= IDirect3DDevice9_BeginScene(device
);
4633 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
4634 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
4635 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
4636 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
4637 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4638 hr
= IDirect3DDevice9_EndScene(device
);
4639 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
4641 color
= getPixelColor(device
, 240, 320);
4642 ok(color
== 0x0000ffff, "R32F with value 0.0 has color %08x, expected 0x0000ffff\n", color
);
4644 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
4645 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
4647 IDirect3DTexture9_Release(texture
);
4648 refcount
= IDirect3DDevice9_Release(device
);
4649 ok(!refcount
, "Device has %u references left.\n", refcount
);
4651 IDirect3D9_Release(d3d
);
4652 DestroyWindow(window
);
4655 static void g16r16_texture_test(void)
4657 IDirect3DTexture9
*texture
;
4658 IDirect3DDevice9
*device
;
4667 static const float quad
[] =
4669 -1.0f
, -1.0f
, 0.1f
, 0.0f
, 0.0f
,
4670 -1.0f
, 1.0f
, 0.1f
, 0.0f
, 1.0f
,
4671 1.0f
, -1.0f
, 0.1f
, 1.0f
, 0.0f
,
4672 1.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
,
4675 window
= create_window();
4676 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
4677 ok(!!d3d
, "Failed to create a D3D object.\n");
4678 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
4680 skip("Failed to create a D3D device, skipping tests.\n");
4684 if (IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
,
4685 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_TEXTURE
, D3DFMT_G16R16
) != D3D_OK
)
4687 skip("D3DFMT_G16R16 textures not supported\n");
4688 IDirect3DDevice9_Release(device
);
4692 hr
= IDirect3DDevice9_CreateTexture(device
, 1, 1, 1, 0, D3DFMT_G16R16
, D3DPOOL_MANAGED
, &texture
, NULL
);
4693 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
4695 memset(&lr
, 0, sizeof(lr
));
4696 hr
= IDirect3DTexture9_LockRect(texture
, 0, &lr
, NULL
, 0);
4697 ok(hr
== D3D_OK
, "IDirect3DTexture9_LockRect failed with %08x\n", hr
);
4700 hr
= IDirect3DTexture9_UnlockRect(texture
, 0);
4701 ok(hr
== D3D_OK
, "IDirect3DTexture9_UnlockRect failed with %08x\n", hr
);
4703 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
4704 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
4705 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)texture
);
4706 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture failed with %08x\n", hr
);
4708 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff0000ff, 1.0f
, 0);
4709 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
4711 hr
= IDirect3DDevice9_BeginScene(device
);
4712 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
4713 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
4714 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
4715 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
4716 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4717 hr
= IDirect3DDevice9_EndScene(device
);
4718 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
4720 color
= getPixelColor(device
, 240, 320);
4721 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0xf0, 0x0f, 0xff), 1),
4722 "D3DFMT_G16R16 with value 0x00ffff00 has color %08x, expected 0x00f00fff\n", color
);
4724 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
4725 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
4727 IDirect3DTexture9_Release(texture
);
4728 refcount
= IDirect3DDevice9_Release(device
);
4729 ok(!refcount
, "Device has %u references left.\n", refcount
);
4731 IDirect3D9_Release(d3d
);
4732 DestroyWindow(window
);
4735 static void check_rect(struct surface_readback
*rb
, RECT r
, const char *message
)
4737 LONG x_coords
[2][2] =
4739 {r
.left
- 1, r
.left
+ 1},
4740 {r
.right
+ 1, r
.right
- 1},
4742 LONG y_coords
[2][2] =
4744 {r
.top
- 1, r
.top
+ 1},
4745 {r
.bottom
+ 1, r
.bottom
- 1}
4747 unsigned int i
, j
, x_side
, y_side
;
4751 if (r
.left
< 0 && r
.top
< 0 && r
.right
< 0 && r
.bottom
< 0)
4753 BOOL all_match
= TRUE
;
4755 for (y
= 0; y
< 480; ++y
)
4757 for (x
= 0; x
< 640; ++x
)
4759 color
= get_readback_color(rb
, x
, y
);
4760 if (color
!= 0xff000000)
4769 ok(all_match
, "%s: pixel (%d, %d) has color %08x.\n", message
, x
, y
, color
);
4773 for (i
= 0; i
< 2; ++i
)
4775 for (j
= 0; j
< 2; ++j
)
4777 for (x_side
= 0; x_side
< 2; ++x_side
)
4779 for (y_side
= 0; y_side
< 2; ++y_side
)
4781 DWORD expected
= (x_side
== 1 && y_side
== 1) ? 0xffffffff : 0xff000000;
4783 x
= x_coords
[i
][x_side
];
4784 y
= y_coords
[j
][y_side
];
4785 if (x
< 0 || x
>= 640 || y
< 0 || y
>= 480)
4787 color
= get_readback_color(rb
, x
, y
);
4788 ok(color
== expected
, "%s: pixel (%d, %d) has color %08x, expected %08x.\n",
4789 message
, x
, y
, color
, expected
);
4796 struct projected_textures_test_run
4798 const char *message
;
4800 IDirect3DVertexDeclaration9
*decl
;
4805 static void projected_textures_test(IDirect3DDevice9
*device
,
4806 struct projected_textures_test_run tests
[4])
4810 static const DWORD vertex_shader
[] =
4812 0xfffe0101, /* vs_1_1 */
4813 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
4814 0x0000001f, 0x80000005, 0x900f0001, /* dcl_texcoord0 v1 */
4815 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
4816 0x00000001, 0xe00f0000, 0x90e40001, /* mov oT0, v1 */
4817 0x0000ffff /* end */
4819 static const DWORD pixel_shader
[] =
4821 0xffff0103, /* ps_1_3 */
4822 0x00000042, 0xb00f0000, /* tex t0 */
4823 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
4824 0x0000ffff /* end */
4826 IDirect3DVertexShader9
*vs
= NULL
;
4827 IDirect3DPixelShader9
*ps
= NULL
;
4831 IDirect3DSurface9
*backbuffer
;
4832 struct surface_readback rb
;
4834 IDirect3DDevice9_GetDirect3D(device
, &d3d
);
4835 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
4836 ok(SUCCEEDED(hr
), "GetDeviceCaps failed (%08x)\n", hr
);
4837 IDirect3D9_Release(d3d
);
4839 if (caps
.VertexShaderVersion
>= D3DVS_VERSION(1, 1))
4841 hr
= IDirect3DDevice9_CreateVertexShader(device
, vertex_shader
, &vs
);
4842 ok(SUCCEEDED(hr
), "CreateVertexShader failed (%08x)\n", hr
);
4844 if (caps
.PixelShaderVersion
>= D3DPS_VERSION(1, 3))
4846 hr
= IDirect3DDevice9_CreatePixelShader(device
, pixel_shader
, &ps
);
4847 ok(SUCCEEDED(hr
), "CreatePixelShader failed (%08x)\n", hr
);
4850 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
4851 ok(SUCCEEDED(hr
), "Failed to get back buffer, hr %#x.\n", hr
);
4853 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff203040, 0.0f
, 0);
4854 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
4856 hr
= IDirect3DDevice9_BeginScene(device
);
4857 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
4859 for (i
= 0; i
< 4; ++i
)
4861 DWORD value
= 0xdeadbeef;
4862 static const float proj_quads
[] =
4864 -1.0f
, -1.0f
, 0.1f
, 0.0f
, 0.0f
, 4.0f
, 6.0f
,
4865 -1.0f
, 0.0f
, 0.1f
, 0.0f
, 4.0f
, 4.0f
, 6.0f
,
4866 0.0f
, -1.0f
, 0.1f
, 4.0f
, 0.0f
, 4.0f
, 6.0f
,
4867 0.0f
, 0.0f
, 0.1f
, 4.0f
, 4.0f
, 4.0f
, 6.0f
,
4869 0.0f
, -1.0f
, 0.1f
, 0.0f
, 0.0f
, 4.0f
, 6.0f
,
4870 0.0f
, 0.0f
, 0.1f
, 0.0f
, 4.0f
, 4.0f
, 6.0f
,
4871 1.0f
, -1.0f
, 0.1f
, 4.0f
, 0.0f
, 4.0f
, 6.0f
,
4872 1.0f
, 0.0f
, 0.1f
, 4.0f
, 4.0f
, 4.0f
, 6.0f
,
4874 -1.0f
, 0.0f
, 0.1f
, 0.0f
, 0.0f
, 4.0f
, 6.0f
,
4875 -1.0f
, 1.0f
, 0.1f
, 0.0f
, 4.0f
, 4.0f
, 6.0f
,
4876 0.0f
, 0.0f
, 0.1f
, 4.0f
, 0.0f
, 4.0f
, 6.0f
,
4877 0.0f
, 1.0f
, 0.1f
, 4.0f
, 4.0f
, 4.0f
, 6.0f
,
4879 0.0f
, 0.0f
, 0.1f
, 0.0f
, 0.0f
, 4.0f
, 6.0f
,
4880 0.0f
, 1.0f
, 0.1f
, 0.0f
, 4.0f
, 4.0f
, 6.0f
,
4881 1.0f
, 0.0f
, 0.1f
, 4.0f
, 0.0f
, 4.0f
, 6.0f
,
4882 1.0f
, 1.0f
, 0.1f
, 4.0f
, 4.0f
, 4.0f
, 6.0f
,
4889 skip("Vertex shaders not supported, skipping\n");
4892 hr
= IDirect3DDevice9_SetVertexShader(device
, vs
);
4895 hr
= IDirect3DDevice9_SetVertexShader(device
, NULL
);
4896 ok(SUCCEEDED(hr
), "SetVertexShader failed (%08x)\n", hr
);
4901 skip("Pixel shaders not supported, skipping\n");
4904 hr
= IDirect3DDevice9_SetPixelShader(device
, ps
);
4907 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
4908 ok(SUCCEEDED(hr
), "SetPixelShader failed (%08x)\n", hr
);
4910 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, tests
[i
].decl
);
4911 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed with %08x\n", hr
);
4913 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, tests
[i
].flags
);
4914 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
4915 hr
= IDirect3DDevice9_GetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, &value
);
4916 ok(SUCCEEDED(hr
) && value
== tests
[i
].flags
,
4917 "GetTextureStageState returned: hr %08x, value %08x.\n", hr
, value
);
4919 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2,
4920 &proj_quads
[i
* 4 * 7], 7 * sizeof(float));
4921 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
4924 hr
= IDirect3DDevice9_EndScene(device
);
4925 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %08x\n", hr
);
4927 hr
= IDirect3DDevice9_SetVertexShader(device
, NULL
);
4928 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
4929 if (vs
) IDirect3DVertexShader9_Release(vs
);
4930 if (ps
) IDirect3DPixelShader9_Release(ps
);
4932 get_rt_readback(backbuffer
, &rb
);
4933 for (i
= 0; i
< 4; ++i
)
4935 if ((!tests
[i
].vs
|| vs
) && (!tests
[i
].ps
|| ps
))
4936 check_rect(&rb
, tests
[i
].rect
, tests
[i
].message
);
4938 release_surface_readback(&rb
);
4939 IDirect3DSurface9_Release(backbuffer
);
4942 static void texture_transform_flags_test(void)
4946 D3DFORMAT fmt
= D3DFMT_X8R8G8B8
;
4948 IDirect3DTexture9
*texture
= NULL
;
4949 IDirect3DVolumeTexture9
*volume
= NULL
;
4950 IDirect3DDevice9
*device
;
4951 unsigned int x
, y
, z
;
4958 IDirect3DVertexDeclaration9
*decl
, *decl2
, *decl3
, *decl4
;
4960 static const D3DVERTEXELEMENT9 decl_elements
[] = {
4961 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
4962 {0, 12, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
4965 static const D3DVERTEXELEMENT9 decl_elements2
[] = {
4966 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
4967 {0, 12, D3DDECLTYPE_FLOAT1
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
4970 static const D3DVERTEXELEMENT9 decl_elements3
[] = {
4971 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
4972 {0, 12, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
4975 static const D3DVERTEXELEMENT9 decl_elements4
[] = {
4976 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
4977 {0, 12, D3DDECLTYPE_FLOAT2
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
4980 static const unsigned char proj_texdata
[] = {0x00, 0x00, 0x00, 0x00,
4981 0x00, 0xff, 0x00, 0x00,
4982 0x00, 0x00, 0x00, 0x00,
4983 0x00, 0x00, 0x00, 0x00};
4984 static const D3DMATRIX identity
=
4986 1.0f
, 0.0f
, 0.0f
, 0.0f
,
4987 0.0f
, 1.0f
, 0.0f
, 0.0f
,
4988 0.0f
, 0.0f
, 1.0f
, 0.0f
,
4989 0.0f
, 0.0f
, 0.0f
, 1.0f
,
4992 window
= create_window();
4993 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
4994 ok(!!d3d
, "Failed to create a D3D object.\n");
4995 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
4997 skip("Failed to create a D3D device, skipping tests.\n");
5001 memset(&lr
, 0, sizeof(lr
));
5002 memset(&lb
, 0, sizeof(lb
));
5003 if (IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
,
5004 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_TEXTURE
, D3DFMT_A16B16G16R16
) == D3D_OK
)
5005 fmt
= D3DFMT_A16B16G16R16
;
5007 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &decl
);
5008 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr
);
5009 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements2
, &decl2
);
5010 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr
);
5011 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements3
, &decl3
);
5012 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr
);
5013 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements4
, &decl4
);
5014 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr
);
5015 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_SRGBTEXTURE
, FALSE
);
5016 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState(D3DSAMP_SRGBTEXTURE) returned %08x\n", hr
);
5017 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAGFILTER
, D3DTEXF_POINT
);
5018 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState(D3DSAMP_MAGFILTER) returned %08x\n", hr
);
5019 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MINFILTER
, D3DTEXF_POINT
);
5020 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState(D3DSAMP_MINFILTER) returned %08x\n", hr
);
5021 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MIPFILTER
, D3DTEXF_NONE
);
5022 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState(D3DSAMP_MIPFILTER) returned %08x\n", hr
);
5023 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSU
, D3DTADDRESS_CLAMP
);
5024 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState(D3DSAMP_ADDRESSU) returned %08x\n", hr
);
5025 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSV
, D3DTADDRESS_CLAMP
);
5026 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState(D3DSAMP_ADDRESSV) returned %08x\n", hr
);
5027 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSW
, D3DTADDRESS_CLAMP
);
5028 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState(D3DSAMP_ADDRESSW) returned %08x\n", hr
);
5029 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
5030 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState(D3DTSS_COLOROP) returned %08x\n", hr
);
5031 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
5032 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState(D3DTSS_COLORARG1) returned %08x\n", hr
);
5033 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
5034 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState(D3DRS_LIGHTING) returned %08x\n", hr
);
5035 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff0000ff, 1.0f
, 0);
5036 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
5038 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
5039 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetDeviceCaps returned %08x\n", hr
);
5040 w
= min(1024, caps
.MaxTextureWidth
);
5041 h
= min(1024, caps
.MaxTextureHeight
);
5042 hr
= IDirect3DDevice9_CreateTexture(device
, w
, h
, 1,
5043 0, fmt
, D3DPOOL_MANAGED
, &texture
, NULL
);
5044 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture returned %08x\n", hr
);
5047 skip("Failed to create the test texture.\n");
5048 IDirect3DDevice9_Release(device
);
5052 /* Unfortunately there is no easy way to set up a texture coordinate passthrough
5053 * in d3d fixed function pipeline, so create a texture that has a gradient from 0.0 to
5054 * 1.0 in red and green for the x and y coords
5056 hr
= IDirect3DTexture9_LockRect(texture
, 0, &lr
, NULL
, 0);
5057 ok(hr
== D3D_OK
, "IDirect3DTexture9_LockRect returned %08x\n", hr
);
5058 for(y
= 0; y
< h
; y
++) {
5059 for(x
= 0; x
< w
; x
++) {
5060 double r_f
= (double) y
/ (double) h
;
5061 double g_f
= (double) x
/ (double) w
;
5062 if(fmt
== D3DFMT_A16B16G16R16
) {
5063 unsigned short r
, g
;
5064 unsigned short *dst
= (unsigned short *) (((char *) lr
.pBits
) + y
* lr
.Pitch
+ x
* 8);
5065 r
= (unsigned short) (r_f
* 65536.0);
5066 g
= (unsigned short) (g_f
* 65536.0);
5072 unsigned char *dst
= ((unsigned char *) lr
.pBits
) + y
* lr
.Pitch
+ x
* 4;
5073 unsigned char r
= (unsigned char) (r_f
* 255.0);
5074 unsigned char g
= (unsigned char) (g_f
* 255.0);
5082 hr
= IDirect3DTexture9_UnlockRect(texture
, 0);
5083 ok(hr
== D3D_OK
, "IDirect3DTexture9_UnlockRect returned %08x\n", hr
);
5084 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) texture
);
5085 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture returned %08x\n", hr
);
5087 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
5088 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with %08x\n", hr
);
5089 hr
= IDirect3DDevice9_BeginScene(device
);
5090 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %08x\n", hr
);
5093 static const float quad1
[] =
5095 -1.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
,
5096 -1.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
,
5097 0.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
,
5098 0.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
,
5100 static const float quad2
[] =
5102 -1.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
,
5103 -1.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
,
5104 0.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
,
5105 0.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
,
5107 static const float quad3
[] =
5109 0.0f
, 0.0f
, 0.1f
, 0.5f
, 0.5f
,
5110 0.0f
, 1.0f
, 0.1f
, 0.5f
, 0.5f
,
5111 1.0f
, 0.0f
, 0.1f
, 0.5f
, 0.5f
,
5112 1.0f
, 1.0f
, 0.1f
, 0.5f
, 0.5f
,
5114 static const float quad4
[] =
5116 320.0f
, 480.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
,
5117 320.0f
, 240.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
,
5118 640.0f
, 480.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
,
5119 640.0f
, 240.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
,
5123 0.0f
, 0.0f
, 0.0f
, 0.0f
,
5124 0.0f
, 0.0f
, 0.0f
, 0.0f
,
5125 0.0f
, 0.0f
, 0.0f
, 0.0f
,
5126 0.0f
, 0.0f
, 0.0f
, 0.0f
,
5129 /* What happens with the texture matrix if D3DTSS_TEXTURETRANSFORMFLAGS is disabled? */
5130 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, &mat
);
5131 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %08x\n", hr
);
5132 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, 5 * sizeof(float));
5133 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
5135 /* What happens with transforms enabled? */
5136 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT2
);
5137 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
5138 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, 5 * sizeof(float));
5139 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
5141 /* What happens if 4 coords are used, but only 2 given ?*/
5142 U(mat
).m
[2][0] = 1.0f
;
5143 U(mat
).m
[3][1] = 1.0f
;
5144 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, &mat
);
5145 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %08x\n", hr
);
5146 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT4
);
5147 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
5148 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, 5 * sizeof(float));
5149 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
5151 /* What happens with transformed geometry? This setup lead to 0/0 coords with untransformed
5152 * geometry. If the same applies to transformed vertices, the quad will be black, otherwise red,
5153 * due to the coords in the vertices. (turns out red, indeed)
5155 memset(&mat
, 0, sizeof(mat
));
5156 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, &mat
);
5157 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %08x\n", hr
);
5158 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZRHW
| D3DFVF_TEX1
);
5159 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetFVF failed with %08x\n", hr
);
5160 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT2
);
5161 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
5162 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, 6 * sizeof(float));
5163 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
5165 hr
= IDirect3DDevice9_EndScene(device
);
5166 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %08x\n", hr
);
5168 color
= getPixelColor(device
, 160, 360);
5169 ok(color_match(color
, 0x00ffff00, 1), "quad 1 has color %08x, expected 0x00ffff00\n", color
);
5170 color
= getPixelColor(device
, 160, 120);
5171 ok(color
== 0x00000000, "quad 2 has color %08x, expected 0x0000000\n", color
);
5172 color
= getPixelColor(device
, 480, 120);
5173 ok(color_match(color
, 0x0000ff00, 1), "quad 3 has color %08x, expected 0x0000ff00\n", color
);
5174 color
= getPixelColor(device
, 480, 360);
5175 ok(color_match(color
, 0x00ff0000, 1), "quad 4 has color %08x, expected 0x00ff0000\n", color
);
5176 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
5177 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
5179 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff0000ff, 0.0, 0);
5180 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
5182 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
5183 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with %08x\n", hr
);
5184 hr
= IDirect3DDevice9_BeginScene(device
);
5185 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %08x\n", hr
);
5188 static const float quad1
[] =
5190 -1.0f
, -1.0f
, 0.1f
, 0.8f
, 0.2f
,
5191 -1.0f
, 0.0f
, 0.1f
, 0.8f
, 0.2f
,
5192 0.0f
, -1.0f
, 0.1f
, 0.8f
, 0.2f
,
5193 0.0f
, 0.0f
, 0.1f
, 0.8f
, 0.2f
,
5195 static const float quad2
[] =
5197 -1.0f
, 0.0f
, 0.1f
, 0.5f
, 1.0f
,
5198 -1.0f
, 1.0f
, 0.1f
, 0.5f
, 1.0f
,
5199 0.0f
, 0.0f
, 0.1f
, 0.5f
, 1.0f
,
5200 0.0f
, 1.0f
, 0.1f
, 0.5f
, 1.0f
,
5202 static const float quad3
[] =
5204 0.0f
, 0.0f
, 0.1f
, 0.5f
, 1.0f
,
5205 0.0f
, 1.0f
, 0.1f
, 0.5f
, 1.0f
,
5206 1.0f
, 0.0f
, 0.1f
, 0.5f
, 1.0f
,
5207 1.0f
, 1.0f
, 0.1f
, 0.5f
, 1.0f
,
5209 static const float quad4
[] =
5211 0.0f
, -1.0f
, 0.1f
, 0.8f
, 0.2f
,
5212 0.0f
, 0.0f
, 0.1f
, 0.8f
, 0.2f
,
5213 1.0f
, -1.0f
, 0.1f
, 0.8f
, 0.2f
,
5214 1.0f
, 0.0f
, 0.1f
, 0.8f
, 0.2f
,
5218 0.0f
, 0.0f
, 0.0f
, 0.0f
,
5219 0.0f
, 0.0f
, 0.0f
, 0.0f
,
5220 0.0f
, 1.0f
, 0.0f
, 0.0f
,
5221 0.0f
, 0.0f
, 0.0f
, 0.0f
,
5224 /* What happens to the default 1 in the 3rd coordinate if it is disabled? */
5225 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, &mat
);
5226 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %08x\n", hr
);
5227 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT2
);
5228 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
5230 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, 5 * sizeof(float));
5231 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
5233 /* D3DTFF_COUNT1 does not work on Nvidia drivers. It behaves like D3DTTFF_DISABLE. On ATI drivers
5234 * it behaves like COUNT2 because normal textures require 2 coords. */
5235 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT1
);
5236 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
5237 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, 5 * sizeof(float));
5238 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
5240 /* Just to be sure, the same as quad2 above */
5241 memset(&mat
, 0, sizeof(mat
));
5242 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, &mat
);
5243 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %08x\n", hr
);
5244 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT2
);
5245 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
5246 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, 5 * sizeof(float));
5247 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
5249 /* Now, what happens to the 2nd coordinate(that is disabled in the matrix) if it is not
5250 * used? And what happens to the first? */
5251 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT1
);
5252 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
5253 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, 5 * sizeof(float));
5254 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
5256 hr
= IDirect3DDevice9_EndScene(device
);
5257 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %08x\n", hr
);
5259 color
= getPixelColor(device
, 160, 360);
5260 ok(color_match(color
, 0x00ff0000, 1), "quad 1 has color %08x, expected 0x00ff0000\n", color
);
5261 color
= getPixelColor(device
, 160, 120);
5262 ok(color
== 0x00000000, "quad 2 has color %08x, expected 0x0000000\n", color
);
5263 color
= getPixelColor(device
, 480, 120);
5264 ok(color_match(color
, 0x00ff8000, 1) || color
== 0x00000000,
5265 "quad 3 has color %08x, expected 0x00ff8000\n", color
);
5266 color
= getPixelColor(device
, 480, 360);
5267 ok(color_match(color
, 0x0033cc00, 1) || color_match(color
, 0x00ff0000, 1),
5268 "quad 4 has color %08x, expected 0x0033cc00\n", color
);
5269 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
5270 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
5272 IDirect3DTexture9_Release(texture
);
5274 /* Test projected textures, without any fancy matrices */
5275 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_L8
, D3DPOOL_MANAGED
, &texture
, NULL
);
5276 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture returned %08x\n", hr
);
5279 struct projected_textures_test_run projected_tests_1
[4] =
5282 "D3DTTFF_COUNT4 | D3DTTFF_PROJECTED - bottom left",
5283 D3DTTFF_COUNT4
| D3DTTFF_PROJECTED
,
5286 {120, 300, 240, 390},
5289 "D3DTTFF_COUNT3 | D3DTTFF_PROJECTED - bottom right",
5290 D3DTTFF_COUNT3
| D3DTTFF_PROJECTED
,
5293 {400, 360, 480, 420},
5295 /* Try with some invalid values */
5297 "0xffffffff (draws like COUNT4 | PROJECTED) - top left",
5304 "D3DTTFF_COUNT3 | D3DTTFF_PROJECTED (draws non-projected) - top right",
5305 D3DTTFF_COUNT3
| D3DTTFF_PROJECTED
,
5308 {340, 210, 360, 225},
5311 struct projected_textures_test_run projected_tests_2
[4] =
5314 "D3DTTFF_PROJECTED (like COUNT4 | PROJECTED, texcoord has 4 components) - bottom left",
5318 {120, 300, 240, 390},
5321 "D3DTTFF_PROJECTED (like COUNT3 | PROJECTED, texcoord has only 3 components) - bottom right",
5325 {400, 360, 480, 420},
5328 "0xffffffff (like COUNT3 | PROJECTED, texcoord has only 3 components) - top left",
5332 {80, 120, 160, 180},
5335 "D3DTTFF_COUNT1 (draws non-projected) - top right",
5339 {340, 210, 360, 225},
5342 struct projected_textures_test_run projected_tests_3
[4] =
5345 "D3DTTFF_COUNT3 | D3DTTFF_PROJECTED (like COUNT4 | PROJECTED) - bottom left",
5349 {120, 300, 240, 390},
5352 "D3DTTFF_COUNT3 | D3DTTFF_PROJECTED (like COUNT4 | PROJECTED) - bottom right",
5353 D3DTTFF_COUNT3
| D3DTTFF_PROJECTED
,
5356 {440, 300, 560, 390},
5359 "0xffffffff (like COUNT4 | PROJECTED) - top left",
5363 {120, 60, 240, 150},
5366 "D3DTTFF_PROJECTED (like COUNT4 | PROJECTED) - top right",
5370 {440, 60, 560, 150},
5374 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, &identity
);
5375 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %08x\n", hr
);
5377 hr
= IDirect3DTexture9_LockRect(texture
, 0, &lr
, NULL
, 0);
5378 ok(hr
== D3D_OK
, "IDirect3DTexture9_LockRect failed with %08x\n", hr
);
5379 for(x
= 0; x
< 4; x
++) {
5380 memcpy(((BYTE
*) lr
.pBits
) + lr
.Pitch
* x
, proj_texdata
+ 4 * x
, 4 * sizeof(proj_texdata
[0]));
5382 hr
= IDirect3DTexture9_UnlockRect(texture
, 0);
5383 ok(hr
== D3D_OK
, "IDirect3DTexture9_UnlockRect failed with %08x\n", hr
);
5384 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) texture
);
5385 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture failed with %08x\n", hr
);
5387 projected_textures_test(device
, projected_tests_1
);
5388 projected_textures_test(device
, projected_tests_2
);
5389 projected_textures_test(device
, projected_tests_3
);
5391 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
5392 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture failed with %08x\n", hr
);
5393 IDirect3DTexture9_Release(texture
);
5396 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff203040, 0.0, 0);
5397 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
5398 /* Use a smaller volume texture than the biggest possible size for memory and performance reasons
5399 * Thus watch out if sampling from texels between 0 and 1.
5401 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 32, 32, 32, 1, 0, fmt
, D3DPOOL_MANAGED
, &volume
, 0);
5402 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
,
5403 "IDirect3DDevice9_CreateVolumeTexture failed with %08x\n", hr
);
5405 skip("Failed to create a volume texture\n");
5409 hr
= IDirect3DVolumeTexture9_LockBox(volume
, 0, &lb
, NULL
, 0);
5410 ok(hr
== D3D_OK
, "IDirect3DVolumeTexture9_LockBox failed with %08x\n", hr
);
5411 for(z
= 0; z
< 32; z
++) {
5412 for(y
= 0; y
< 32; y
++) {
5413 for(x
= 0; x
< 32; x
++) {
5414 char size
= (fmt
== D3DFMT_A16B16G16R16
? 8 : 4);
5415 void *mem
= ((char *) lb
.pBits
) + y
* lb
.RowPitch
+ z
* lb
.SlicePitch
+ x
* size
;
5416 float r_f
= (float) x
/ 31.0;
5417 float g_f
= (float) y
/ 31.0;
5418 float b_f
= (float) z
/ 31.0;
5420 if(fmt
== D3DFMT_A16B16G16R16
) {
5421 unsigned short *mem_s
= mem
;
5422 mem_s
[0] = r_f
* 65535.0;
5423 mem_s
[1] = g_f
* 65535.0;
5424 mem_s
[2] = b_f
* 65535.0;
5427 unsigned char *mem_c
= mem
;
5428 mem_c
[0] = b_f
* 255.0;
5429 mem_c
[1] = g_f
* 255.0;
5430 mem_c
[2] = r_f
* 255.0;
5436 hr
= IDirect3DVolumeTexture9_UnlockBox(volume
, 0);
5437 ok(hr
== D3D_OK
, "IDirect3DVolumeTexture9_UnlockBox failed with %08x\n", hr
);
5439 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) volume
);
5440 ok(hr
== D3D_OK
, "IDirect3DVolumeTexture9_UnlockBox failed with %08x\n", hr
);
5442 hr
= IDirect3DDevice9_BeginScene(device
);
5443 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %08x\n", hr
);
5446 static const float quad1
[] =
5448 -1.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
,
5449 -1.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
,
5450 0.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
,
5451 0.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
,
5453 static const float quad2
[] =
5455 -1.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
,
5456 -1.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
,
5457 0.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
,
5458 0.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
,
5460 static const float quad3
[] =
5462 0.0f
, 0.0f
, 0.1f
, 0.0f
, 0.0f
,
5463 0.0f
, 1.0f
, 0.1f
, 0.0f
, 0.0f
,
5464 1.0f
, 0.0f
, 0.1f
, 0.0f
, 0.0f
,
5465 1.0f
, 1.0f
, 0.1f
, 0.0f
, 0.0f
,
5467 static const float quad4
[] =
5469 0.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
,
5470 0.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
,
5471 1.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
,
5472 1.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
,
5476 1.0f
, 0.0f
, 0.0f
, 0.0f
,
5477 0.0f
, 0.0f
, 1.0f
, 0.0f
,
5478 0.0f
, 1.0f
, 0.0f
, 0.0f
,
5479 0.0f
, 0.0f
, 0.0f
, 1.0f
,
5481 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl
);
5482 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed with %08x\n", hr
);
5484 /* Draw a quad with all 3 coords enabled. Nothing fancy. v and w are swapped, but have the same
5487 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, &mat
);
5488 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %08x\n", hr
);
5489 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT3
);
5490 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
5491 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, 6 * sizeof(float));
5492 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
5494 /* Now disable the w coordinate. Does that change the input, or the output. The coordinates
5495 * are swapped by the matrix. If it changes the input, the v coord will be missing(green),
5496 * otherwise the w will be missing(blue).
5497 * turns out that on nvidia cards the blue color is missing, so it is an output modification.
5498 * On ATI cards the COUNT2 is ignored, and it behaves in the same way as COUNT3. */
5499 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT2
);
5500 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
5501 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, 6 * sizeof(float));
5502 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
5504 /* default values? Set up the identity matrix, pass in 2 vertex coords, and enable 3 */
5505 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, &identity
);
5506 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %08x\n", hr
);
5507 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT3
);
5508 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
5509 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
5510 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with %08x\n", hr
);
5511 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, 5 * sizeof(float));
5512 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
5514 /* D3DTTFF_COUNT1. Set a NULL matrix, and count1, pass in all values as 1.0. Nvidia has count1 ==
5515 * disable. ATI extends it up to the amount of values needed for the volume texture
5517 memset(&mat
, 0, sizeof(mat
));
5518 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, &mat
);
5519 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %08x\n", hr
);
5520 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT1
);
5521 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
5522 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl
);
5523 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed with %08x\n", hr
);
5524 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, 6 * sizeof(float));
5525 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
5527 hr
= IDirect3DDevice9_EndScene(device
);
5528 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %08x\n", hr
);
5531 color
= getPixelColor(device
, 160, 360);
5532 ok(color
== 0x00ffffff, "quad 1 has color %08x, expected 0x00ffffff\n", color
);
5533 color
= getPixelColor(device
, 160, 120);
5534 ok(color
== 0x00ffff00 /* NV*/ || color
== 0x00ffffff /* ATI */,
5535 "quad 2 has color %08x, expected 0x00ffff00\n", color
);
5536 color
= getPixelColor(device
, 480, 120);
5537 ok(color
== 0x000000ff, "quad 3 has color %08x, expected 0x000000ff\n", color
);
5538 color
= getPixelColor(device
, 480, 360);
5539 ok(color
== 0x00ffffff || color
== 0x0000ff00, "quad 4 has color %08x, expected 0x00ffffff\n", color
);
5541 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
5542 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
5544 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff303030, 0.0, 0);
5545 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
5546 hr
= IDirect3DDevice9_BeginScene(device
);
5547 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %08x\n", hr
);
5550 static const float quad1
[] =
5552 -1.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
,
5553 -1.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
,
5554 0.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
,
5555 0.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
,
5557 static const float quad2
[] =
5564 static const float quad3
[] =
5566 0.0f
, 0.0f
, 0.1f
, 1.0f
,
5567 0.0f
, 1.0f
, 0.1f
, 1.0f
,
5568 1.0f
, 0.0f
, 0.1f
, 1.0f
,
5569 1.0f
, 1.0f
, 0.1f
, 1.0f
,
5571 static const D3DMATRIX mat
=
5573 0.0f
, 0.0f
, 0.0f
, 0.0f
,
5574 0.0f
, 0.0f
, 0.0f
, 0.0f
,
5575 0.0f
, 0.0f
, 0.0f
, 0.0f
,
5576 0.0f
, 1.0f
, 0.0f
, 0.0f
,
5578 static const D3DMATRIX mat2
=
5580 0.0f
, 0.0f
, 0.0f
, 1.0f
,
5581 1.0f
, 0.0f
, 0.0f
, 0.0f
,
5582 0.0f
, 1.0f
, 0.0f
, 0.0f
,
5583 0.0f
, 0.0f
, 1.0f
, 0.0f
,
5585 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl
);
5586 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed with %08x\n", hr
);
5588 /* Default values? 4 coords used, 3 passed. What happens to the 4th?
5589 * Use COUNT3 because newer Nvidia drivers return black when there are more (output) coords
5590 * than being used by the texture(volume tex -> 3). Again, as shown in earlier test the COUNTx
5591 * affects the post-transformation output, so COUNT3 plus the matrix above is OK for testing the
5592 * 4th *input* coordinate.
5594 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, &mat
);
5595 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %08x\n", hr
);
5596 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT3
);
5597 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
5598 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, 6 * sizeof(float));
5599 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
5602 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, &identity
);
5603 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %08x\n", hr
);
5604 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
5605 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with %08x\n", hr
);
5606 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, 3 * sizeof(float));
5607 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
5609 /* 4 used, 1 passed */
5610 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl2
);
5611 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed with %08x\n", hr
);
5612 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, &mat2
);
5613 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %08x\n", hr
);
5614 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, 4 * sizeof(float));
5615 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
5617 hr
= IDirect3DDevice9_EndScene(device
);
5618 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %08x\n", hr
);
5620 color
= getPixelColor(device
, 160, 360);
5621 ok(color
== 0x0000ff00, "quad 1 has color %08x, expected 0x0000ff00\n", color
);
5622 color
= getPixelColor(device
, 160, 120);
5623 ok(color
== 0x00000000, "quad 2 has color %08x, expected 0x00000000\n", color
);
5624 color
= getPixelColor(device
, 480, 120);
5625 ok(color
== 0x00ff0000, "quad 3 has color %08x, expected 0x00ff0000\n", color
);
5628 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
5629 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
5631 IDirect3DVolumeTexture9_Release(volume
);
5634 IDirect3DVertexDeclaration9_Release(decl
);
5635 IDirect3DVertexDeclaration9_Release(decl2
);
5636 IDirect3DVertexDeclaration9_Release(decl3
);
5637 IDirect3DVertexDeclaration9_Release(decl4
);
5638 refcount
= IDirect3DDevice9_Release(device
);
5639 ok(!refcount
, "Device has %u references left.\n", refcount
);
5641 IDirect3D9_Release(d3d
);
5642 DestroyWindow(window
);
5645 static void texdepth_test(void)
5647 IDirect3DPixelShader9
*shader
;
5648 IDirect3DDevice9
*device
;
5656 static const float texdepth_test_data1
[] = { 0.25f
, 2.0f
, 0.0f
, 0.0f
};
5657 static const float texdepth_test_data2
[] = { 0.25f
, 0.5f
, 0.0f
, 0.0f
};
5658 static const float texdepth_test_data3
[] = {-1.00f
, 0.1f
, 0.0f
, 0.0f
};
5659 static const float texdepth_test_data4
[] = {-0.25f
, -0.5f
, 0.0f
, 0.0f
};
5660 static const float texdepth_test_data5
[] = { 1.00f
, -0.1f
, 0.0f
, 0.0f
};
5661 static const float texdepth_test_data6
[] = { 1.00f
, 0.5f
, 0.0f
, 0.0f
};
5662 static const float texdepth_test_data7
[] = { 0.50f
, 0.0f
, 0.0f
, 0.0f
};
5663 static const DWORD shader_code
[] =
5665 0xffff0104, /* ps_1_4 */
5666 0x00000051, 0xa00f0001, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, /* def c1, 0, 0, 1, 1 */
5667 0x00000001, 0x800f0005, 0xa0e40000, /* mov r5, c0 */
5668 0x0000fffd, /* phase */
5669 0x00000057, 0x800f0005, /* texdepth r5 */
5670 0x00000001, 0x800f0000, 0xa0e40001, /* mov r0, c1 */
5671 0x0000ffff /* end */
5673 static const float vertex
[] =
5681 window
= create_window();
5682 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
5683 ok(!!d3d
, "Failed to create a D3D object.\n");
5684 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
5686 skip("Failed to create a D3D device, skipping tests.\n");
5690 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
5691 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
5692 if (caps
.PixelShaderVersion
< D3DPS_VERSION(1, 4))
5694 skip("No ps_1_4 support, skipping tests.\n");
5695 IDirect3DDevice9_Release(device
);
5699 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code
, &shader
);
5700 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr
);
5702 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffff00, 0.0, 0);
5703 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
5704 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
5705 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
5706 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_TRUE
);
5707 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
5708 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, TRUE
);
5709 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
5710 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_ALWAYS
);
5711 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
5712 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
5713 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetFVF returned %#x.\n", hr
);
5715 /* Fill the depth buffer with a gradient */
5716 hr
= IDirect3DDevice9_BeginScene(device
);
5717 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
5718 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, vertex
, 3 * sizeof(float));
5719 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
5720 hr
= IDirect3DDevice9_EndScene(device
);
5721 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
5723 /* Now perform the actual tests. Same geometry, but with the shader */
5724 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_GREATER
);
5725 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
5726 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, FALSE
);
5727 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
5728 hr
= IDirect3DDevice9_SetPixelShader(device
, shader
);
5729 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader failed (%08x)\n", hr
);
5731 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 0, texdepth_test_data1
, 1);
5732 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr
);
5733 hr
= IDirect3DDevice9_BeginScene(device
);
5734 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
5735 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, vertex
, 3 * sizeof(float));
5736 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
5737 hr
= IDirect3DDevice9_EndScene(device
);
5738 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
5740 color
= getPixelColor(device
, 158, 240);
5741 ok(color
== 0x000000ff, "Pixel 158(25%% - 2 pixel) has color %08x, expected 0x000000ff\n", color
);
5742 color
= getPixelColor(device
, 162, 240);
5743 ok(color
== 0x00ffffff, "Pixel 158(25%% + 2 pixel) has color %08x, expected 0x00ffffff\n", color
);
5745 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
5746 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
5748 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffff00, 0.0, 0);
5749 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Clear returned %#x.\n", hr
);
5751 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 0, texdepth_test_data2
, 1);
5752 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr
);
5753 hr
= IDirect3DDevice9_BeginScene(device
);
5754 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
5755 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, vertex
, 3 * sizeof(float));
5756 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
5757 hr
= IDirect3DDevice9_EndScene(device
);
5758 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
5760 color
= getPixelColor(device
, 318, 240);
5761 ok(color
== 0x000000ff, "Pixel 318(50%% - 2 pixel) has color %08x, expected 0x000000ff\n", color
);
5762 color
= getPixelColor(device
, 322, 240);
5763 ok(color
== 0x00ffff00, "Pixel 322(50%% + 2 pixel) has color %08x, expected 0x00ffff00\n", color
);
5765 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
5766 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
5768 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
5769 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Clear returned %#x.\n", hr
);
5771 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 0, texdepth_test_data3
, 1);
5772 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr
);
5773 hr
= IDirect3DDevice9_BeginScene(device
);
5774 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
5775 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, vertex
, 3 * sizeof(float));
5776 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
5777 hr
= IDirect3DDevice9_EndScene(device
);
5778 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
5780 color
= getPixelColor(device
, 1, 240);
5781 ok(color
== 0x00ff0000, "Pixel 1(0%% + 2 pixel) has color %08x, expected 0x00ff0000\n", color
);
5783 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
5784 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
5786 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0, 0);
5787 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Clear returned %#x.\n", hr
);
5789 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 0, texdepth_test_data4
, 1);
5790 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr
);
5791 hr
= IDirect3DDevice9_BeginScene(device
);
5792 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
5793 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, vertex
, 3 * sizeof(float));
5794 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
5795 hr
= IDirect3DDevice9_EndScene(device
);
5796 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
5798 color
= getPixelColor(device
, 318, 240);
5799 ok(color
== 0x000000ff, "Pixel 318(50%% - 2 pixel) has color %08x, expected 0x000000ff\n", color
);
5800 color
= getPixelColor(device
, 322, 240);
5801 ok(color
== 0x0000ff00, "Pixel 322(50%% + 2 pixel) has color %08x, expected 0x0000ff00\n", color
);
5803 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
5804 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
5806 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffff00, 0.0, 0);
5807 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Clear returned %#x.\n", hr
);
5809 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 0, texdepth_test_data5
, 1);
5810 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr
);
5811 hr
= IDirect3DDevice9_BeginScene(device
);
5812 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
5813 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, vertex
, 3 * sizeof(float));
5814 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
5815 hr
= IDirect3DDevice9_EndScene(device
);
5816 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
5818 color
= getPixelColor(device
, 1, 240);
5819 ok(color
== 0x00ffff00, "Pixel 1(0%% + 2 pixel) has color %08x, expected 0x00ffff00\n", color
);
5821 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
5822 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
5824 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0, 0);
5825 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Clear returned %#x.\n", hr
);
5827 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 0, texdepth_test_data6
, 1);
5828 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr
);
5829 hr
= IDirect3DDevice9_BeginScene(device
);
5830 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
5831 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, vertex
, 3 * sizeof(float));
5832 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
5833 hr
= IDirect3DDevice9_EndScene(device
);
5834 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
5836 color
= getPixelColor(device
, 638, 240);
5837 ok(color
== 0x000000ff, "Pixel 638(100%% + 2 pixel) has color %08x, expected 0x000000ff\n", color
);
5839 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
5840 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
5842 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
5843 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Clear returned %#x.\n", hr
);
5845 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 0, texdepth_test_data7
, 1);
5846 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr
);
5847 hr
= IDirect3DDevice9_BeginScene(device
);
5848 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
5849 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, vertex
, 3 * sizeof(float));
5850 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
5851 hr
= IDirect3DDevice9_EndScene(device
);
5852 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
5854 color
= getPixelColor(device
, 638, 240);
5855 ok(color
== 0x000000ff, "Pixel 638(100%% + 2 pixel) has color %08x, expected 0x000000ff\n", color
);
5857 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
5858 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
5860 IDirect3DPixelShader9_Release(shader
);
5861 refcount
= IDirect3DDevice9_Release(device
);
5862 ok(!refcount
, "Device has %u references left.\n", refcount
);
5864 IDirect3D9_Release(d3d
);
5865 DestroyWindow(window
);
5868 static void texkill_test(void)
5870 IDirect3DPixelShader9
*shader
;
5871 IDirect3DDevice9
*device
;
5879 static const float vertex
[] =
5881 /* bottom top right left */
5882 -1.0f
, -1.0f
, 1.0f
, -0.1f
, 0.9f
, 0.9f
, -0.1f
,
5883 -1.0f
, 1.0f
, 1.0f
, -0.1f
, 0.9f
, -0.1f
, 0.9f
,
5884 1.0f
, -1.0f
, 0.0f
, 0.9f
, -0.1f
, 0.9f
, -0.1f
,
5885 1.0f
, 1.0f
, 0.0f
, 0.9f
, -0.1f
, -0.1f
, 0.9f
,
5887 static const DWORD shader_code_11
[] =
5889 0xffff0101, /* ps_1_1 */
5890 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 1.0, 0.0, 0.0, 1.0 */
5891 0x00000041, 0xb00f0000, /* texkill t0 */
5892 0x00000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
5893 0x0000ffff /* end */
5895 static const DWORD shader_code_20
[] =
5897 0xffff0200, /* ps_2_0 */
5898 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
5899 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, /* def c0, 0.0, 0.0, 1.0, 1.0 */
5900 0x01000041, 0xb00f0000, /* texkill t0 */
5901 0x02000001, 0x800f0800, 0xa0e40000, /* mov oC0, c0 */
5902 0x0000ffff /* end */
5905 window
= create_window();
5906 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
5907 ok(!!d3d
, "Failed to create a D3D object.\n");
5908 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
5910 skip("Failed to create a D3D device, skipping tests.\n");
5914 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
5915 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
5916 if (caps
.PixelShaderVersion
< D3DPS_VERSION(1, 1))
5918 skip("No ps_1_1 support, skipping tests.\n");
5919 IDirect3DDevice9_Release(device
);
5923 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff00ff00, 1.0f
, 0);
5924 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr
);
5925 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_11
, &shader
);
5926 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr
);
5928 hr
= IDirect3DDevice9_SetPixelShader(device
, shader
);
5929 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %08x\n", hr
);
5930 hr
= IDirect3DDevice9_BeginScene(device
);
5931 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
5932 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEXCOORDSIZE4(0) | D3DFVF_TEX1
);
5933 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
5934 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, vertex
, 7 * sizeof(float));
5935 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
5936 hr
= IDirect3DDevice9_EndScene(device
);
5937 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
5939 color
= getPixelColor(device
, 63, 46);
5940 ok(color
== 0x0000ff00, "Pixel 63/46 has color %08x, expected 0x0000ff00\n", color
);
5941 color
= getPixelColor(device
, 66, 46);
5942 ok(color
== 0x0000ff00, "Pixel 66/64 has color %08x, expected 0x0000ff00\n", color
);
5943 color
= getPixelColor(device
, 63, 49);
5944 ok(color
== 0x0000ff00, "Pixel 63/49 has color %08x, expected 0x0000ff00\n", color
);
5945 color
= getPixelColor(device
, 66, 49);
5946 ok(color
== 0x00ff0000, "Pixel 66/49 has color %08x, expected 0x00ff0000\n", color
);
5948 color
= getPixelColor(device
, 578, 46);
5949 ok(color
== 0x0000ff00, "Pixel 578/46 has color %08x, expected 0x0000ff00\n", color
);
5950 color
= getPixelColor(device
, 575, 46);
5951 ok(color
== 0x0000ff00, "Pixel 575/64 has color %08x, expected 0x0000ff00\n", color
);
5952 color
= getPixelColor(device
, 578, 49);
5953 ok(color
== 0x0000ff00, "Pixel 578/49 has color %08x, expected 0x0000ff00\n", color
);
5954 color
= getPixelColor(device
, 575, 49);
5955 ok(color
== 0x00ff0000, "Pixel 575/49 has color %08x, expected 0x00ff0000\n", color
);
5957 color
= getPixelColor(device
, 63, 430);
5958 ok(color
== 0x0000ff00, "Pixel 578/46 has color %08x, expected 0x0000ff00\n", color
);
5959 color
= getPixelColor(device
, 63, 433);
5960 ok(color
== 0x0000ff00, "Pixel 575/64 has color %08x, expected 0x0000ff00\n", color
);
5961 color
= getPixelColor(device
, 66, 433);
5962 ok(color
== 0x00ff0000, "Pixel 578/49 has color %08x, expected 0x00ff0000\n", color
);
5963 color
= getPixelColor(device
, 66, 430);
5964 ok(color
== 0x00ff0000, "Pixel 575/49 has color %08x, expected 0x00ff0000\n", color
);
5966 color
= getPixelColor(device
, 578, 430);
5967 ok(color
== 0x0000ff00, "Pixel 578/46 has color %08x, expected 0x0000ff00\n", color
);
5968 color
= getPixelColor(device
, 578, 433);
5969 ok(color
== 0x0000ff00, "Pixel 575/64 has color %08x, expected 0x0000ff00\n", color
);
5970 color
= getPixelColor(device
, 575, 433);
5971 ok(color
== 0x00ff0000, "Pixel 578/49 has color %08x, expected 0x00ff0000\n", color
);
5972 color
= getPixelColor(device
, 575, 430);
5973 ok(color
== 0x00ff0000, "Pixel 575/49 has color %08x, expected 0x00ff0000\n", color
);
5975 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
5976 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
5978 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
5979 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %08x\n", hr
);
5980 IDirect3DPixelShader9_Release(shader
);
5982 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffff00, 0.0, 0);
5983 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr
);
5984 if (FAILED(IDirect3DDevice9_CreatePixelShader(device
, shader_code_20
, &shader
)))
5986 skip("Failed to create 2.0 test shader, most likely not supported.\n");
5987 IDirect3DDevice9_Release(device
);
5991 hr
= IDirect3DDevice9_SetPixelShader(device
, shader
);
5992 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %08x\n", hr
);
5993 hr
= IDirect3DDevice9_BeginScene(device
);
5994 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
5995 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, vertex
, 7 * sizeof(float));
5996 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
5997 hr
= IDirect3DDevice9_EndScene(device
);
5998 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6000 color
= getPixelColor(device
, 63, 46);
6001 ok(color
== 0x00ffff00, "Pixel 63/46 has color %08x, expected 0x00ffff00\n", color
);
6002 color
= getPixelColor(device
, 66, 46);
6003 ok(color
== 0x00ffff00, "Pixel 66/64 has color %08x, expected 0x00ffff00\n", color
);
6004 color
= getPixelColor(device
, 63, 49);
6005 ok(color
== 0x00ffff00, "Pixel 63/49 has color %08x, expected 0x00ffff00\n", color
);
6006 color
= getPixelColor(device
, 66, 49);
6007 ok(color
== 0x000000ff, "Pixel 66/49 has color %08x, expected 0x000000ff\n", color
);
6009 color
= getPixelColor(device
, 578, 46);
6010 ok(color
== 0x00ffff00, "Pixel 578/46 has color %08x, expected 0x00ffff00\n", color
);
6011 color
= getPixelColor(device
, 575, 46);
6012 ok(color
== 0x00ffff00, "Pixel 575/64 has color %08x, expected 0x00ffff00\n", color
);
6013 color
= getPixelColor(device
, 578, 49);
6014 ok(color
== 0x00ffff00, "Pixel 578/49 has color %08x, expected 0x00ffff00\n", color
);
6015 color
= getPixelColor(device
, 575, 49);
6016 ok(color
== 0x000000ff, "Pixel 575/49 has color %08x, expected 0x000000ff\n", color
);
6018 color
= getPixelColor(device
, 63, 430);
6019 ok(color
== 0x00ffff00, "Pixel 578/46 has color %08x, expected 0x00ffff00\n", color
);
6020 color
= getPixelColor(device
, 63, 433);
6021 ok(color
== 0x00ffff00, "Pixel 575/64 has color %08x, expected 0x00ffff00\n", color
);
6022 color
= getPixelColor(device
, 66, 433);
6023 ok(color
== 0x00ffff00, "Pixel 578/49 has color %08x, expected 0x00ffff00\n", color
);
6024 color
= getPixelColor(device
, 66, 430);
6025 ok(color
== 0x000000ff, "Pixel 575/49 has color %08x, expected 0x000000ff\n", color
);
6027 color
= getPixelColor(device
, 578, 430);
6028 ok(color
== 0x00ffff00, "Pixel 578/46 has color %08x, expected 0x00ffff00\n", color
);
6029 color
= getPixelColor(device
, 578, 433);
6030 ok(color
== 0x00ffff00, "Pixel 575/64 has color %08x, expected 0x00ffff00\n", color
);
6031 color
= getPixelColor(device
, 575, 433);
6032 ok(color
== 0x00ffff00, "Pixel 578/49 has color %08x, expected 0x00ffff00\n", color
);
6033 color
= getPixelColor(device
, 575, 430);
6034 ok(color
== 0x000000ff, "Pixel 575/49 has color %08x, expected 0x000000ff\n", color
);
6036 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
6037 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
6039 IDirect3DPixelShader9_Release(shader
);
6040 refcount
= IDirect3DDevice9_Release(device
);
6041 ok(!refcount
, "Device has %u references left.\n", refcount
);
6043 IDirect3D9_Release(d3d
);
6044 DestroyWindow(window
);
6047 static void test_generate_mipmap(void)
6049 static const RECT r1
= {256, 256, 512, 512};
6050 static const RECT r2
= {512, 256, 768, 512};
6051 static const RECT r3
= {256, 512, 512, 768};
6052 static const RECT r4
= {512, 512, 768, 768};
6053 static const float quad
[] =
6055 -0.5f
, -0.5f
, 0.1f
, 0.0f
, 0.0f
,
6056 -0.5f
, 0.5f
, 0.1f
, 0.0f
, 1.0f
,
6057 0.5f
, -0.5f
, 0.1f
, 1.0f
, 0.0f
,
6058 0.5f
, 0.5f
, 0.1f
, 1.0f
, 1.0f
,
6060 IDirect3DTexture9
*texture
, *texture2
;
6061 IDirect3DSurface9
*surface
, *surface2
;
6062 IDirect3DDevice9
*device
;
6071 window
= create_window();
6072 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
6073 ok(!!d3d
, "Failed to create a D3D object.\n");
6074 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
6076 skip("Failed to create a D3D device, skipping tests.\n");
6080 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffff00, 1.0f
, 0);
6081 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
6083 /* Make the texture big enough that a mipmap level > 0 is used. */
6084 hr
= IDirect3DDevice9_CreateTexture(device
, 1024, 1024, 0, D3DUSAGE_RENDERTARGET
,
6085 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &texture
, 0);
6086 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
6088 hr
= IDirect3DDevice9_CreateTexture(device
, 1024, 1024, 0, 0,
6089 D3DFMT_X8R8G8B8
, D3DPOOL_SYSTEMMEM
, &texture2
, 0);
6090 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
6092 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
6093 ok(SUCCEEDED(hr
), "Failed to get surface, hr %#x.\n", hr
);
6094 hr
= IDirect3DTexture9_GetSurfaceLevel(texture2
, 0, &surface2
);
6095 ok(SUCCEEDED(hr
), "Failed to get surface, hr %#x.\n", hr
);
6096 hr
= IDirect3DSurface9_LockRect(surface2
, &lr
, NULL
, 0);
6097 ok(SUCCEEDED(hr
), "Failed to map surface, hr %#x.\n", hr
);
6098 for (y
= 0; y
< 1024; ++y
)
6100 for(x
= 0; x
< 1024; ++x
)
6102 DWORD
*dst
= (DWORD
*)((BYTE
*)lr
.pBits
+ y
* lr
.Pitch
+ x
* 4);
6107 if (PtInRect(&r1
, pt
))
6109 else if (PtInRect(&r2
, pt
))
6111 else if (PtInRect(&r3
, pt
))
6113 else if (PtInRect(&r4
, pt
))
6119 hr
= IDirect3DSurface9_UnlockRect(surface2
);
6120 ok(SUCCEEDED(hr
), "Failed to unmap surface, hr %#x.\n", hr
);
6122 hr
= IDirect3DDevice9_UpdateSurface(device
, surface2
, NULL
, surface
, NULL
);
6123 ok(SUCCEEDED(hr
), "Failed to update surface, hr %#x.\n", hr
);
6125 IDirect3DSurface9_Release(surface2
);
6126 IDirect3DSurface9_Release(surface
);
6127 IDirect3DTexture9_Release(texture2
);
6129 hr
= IDirect3DTexture9_SetAutoGenFilterType(texture
, D3DTEXF_LINEAR
);
6130 ok(SUCCEEDED(hr
), "Failed to set mipmap autogen filter type, hr %#x.\n", hr
);
6132 IDirect3DTexture9_GenerateMipSubLevels(texture
);
6134 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)texture
);
6135 ok(SUCCEEDED(hr
), "Failed to set texture, hr %x.\n", hr
);
6136 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MIPFILTER
, D3DTEXF_POINT
);
6137 ok(SUCCEEDED(hr
), "Failed to set mipmap filtering, hr %#x.\n", hr
);
6138 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
6139 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
6141 hr
= IDirect3DDevice9_BeginScene(device
);
6142 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6143 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
6144 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
6145 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
6146 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6147 hr
= IDirect3DDevice9_EndScene(device
);
6148 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6149 IDirect3DTexture9_Release(texture
);
6151 color
= getPixelColor(device
, 200, 200);
6152 ok(!color
, "Unexpected color 0x%08x.\n", color
);
6153 color
= getPixelColor(device
, 280, 200);
6154 ok(!color
, "Unexpected color 0x%08x.\n", color
);
6155 color
= getPixelColor(device
, 360, 200);
6156 ok(!color
, "Unexpected color 0x%08x.\n", color
);
6157 color
= getPixelColor(device
, 440, 200);
6158 ok(!color
, "Unexpected color 0x%08x.\n", color
);
6159 color
= getPixelColor(device
, 200, 270);
6160 ok(!color
, "Unexpected color 0x%08x.\n", color
);
6161 color
= getPixelColor(device
, 280, 270);
6162 ok(!color
, "Unexpected color 0x%08x.\n", color
);
6163 color
= getPixelColor(device
, 360, 270);
6164 ok(!color
, "Unexpected color 0x%08x.\n", color
);
6165 color
= getPixelColor(device
, 440, 270);
6166 ok(!color
, "Unexpected color 0x%08x.\n", color
);
6167 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
6168 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
6170 refcount
= IDirect3DDevice9_Release(device
);
6171 ok(!refcount
, "Device has %u references left.\n", refcount
);
6173 IDirect3D9_Release(d3d
);
6174 DestroyWindow(window
);
6177 static void test_mipmap_autogen(void)
6179 IDirect3DSurface9
*surface
, *surface2
, *surface3
, *backbuffer
;
6180 IDirect3DTexture9
*texture
, *texture2
, *texture3
;
6181 IDirect3DCubeTexture9
*cube_texture
;
6182 IDirect3DDevice9
*device
;
6183 unsigned int i
, x
, y
;
6192 static const RECT r1
= {256, 256, 512, 512};
6193 static const RECT r2
= {512, 256, 768, 512};
6194 static const RECT r3
= {256, 512, 512, 768};
6195 static const RECT r4
= {512, 512, 768, 768};
6196 static const float quad
[] =
6198 -0.5f
, -0.5f
, 0.1f
, 0.0f
, 0.0f
,
6199 -0.5f
, 0.5f
, 0.1f
, 0.0f
, 1.0f
,
6200 0.5f
, -0.5f
, 0.1f
, 1.0f
, 0.0f
,
6201 0.5f
, 0.5f
, 0.1f
, 1.0f
, 1.0f
,
6204 window
= create_window();
6205 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
6206 ok(!!d3d
, "Failed to create a D3D object.\n");
6207 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
6209 skip("Failed to create a D3D device, skipping tests.\n");
6213 if (IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
,
6214 D3DFMT_X8R8G8B8
, D3DUSAGE_AUTOGENMIPMAP
, D3DRTYPE_TEXTURE
, D3DFMT_X8R8G8B8
) != D3D_OK
)
6216 skip("No autogenmipmap support.\n");
6217 IDirect3DDevice9_Release(device
);
6221 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
6222 ok(SUCCEEDED(hr
), "Failed to get back buffer, hr %#x.\n", hr
);
6224 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffff00, 1.0f
, 0);
6225 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
6227 /* Make the texture big enough that a mipmap level > 0 is used. */
6228 hr
= IDirect3DDevice9_CreateTexture(device
, 1024, 1024, 0, D3DUSAGE_AUTOGENMIPMAP
,
6229 D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &texture
, 0);
6230 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture returned %08x\n", hr
);
6232 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
6233 ok(hr
== D3D_OK
, "IDirect3DTexture9_GetSurfaceLevel returned %08x\n", hr
);
6234 memset(&lr
, 0, sizeof(lr
));
6235 hr
= IDirect3DSurface9_LockRect(surface
, &lr
, NULL
, 0);
6236 ok(hr
== D3D_OK
, "IDirect3DSurface9_LockRect returned %08x\n", hr
);
6237 for(y
= 0; y
< 1024; y
++) {
6238 for(x
= 0; x
< 1024; x
++) {
6239 DWORD
*dst
= (DWORD
*) (((BYTE
*) lr
.pBits
) + y
* lr
.Pitch
+ x
* 4);
6244 if(PtInRect(&r1
, pt
)) {
6246 } else if(PtInRect(&r2
, pt
)) {
6248 } else if(PtInRect(&r3
, pt
)) {
6250 } else if(PtInRect(&r4
, pt
)) {
6257 hr
= IDirect3DSurface9_UnlockRect(surface
);
6258 ok(hr
== D3D_OK
, "IDirect3DSurface9_UnlockRect returned %08x\n", hr
);
6259 IDirect3DSurface9_Release(surface
);
6261 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) texture
);
6262 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture returned %08x\n", hr
);
6263 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MIPFILTER
, D3DTEXF_POINT
);
6264 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState failed with %08x\n", hr
);
6265 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
6266 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
6268 hr
= IDirect3DDevice9_BeginScene(device
);
6269 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6270 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
6271 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
6272 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
6273 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6274 hr
= IDirect3DDevice9_EndScene(device
);
6275 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6276 IDirect3DTexture9_Release(texture
);
6278 color
= getPixelColor(device
, 200, 200);
6279 ok(color
== 0x00ffffff, "pixel 200/200 has color %08x, expected 0x00ffffff\n", color
);
6280 color
= getPixelColor(device
, 280, 200);
6281 ok(color
== 0x000000ff, "pixel 280/200 has color %08x, expected 0x000000ff\n", color
);
6282 color
= getPixelColor(device
, 360, 200);
6283 ok(color
== 0x00000000, "pixel 360/200 has color %08x, expected 0x00000000\n", color
);
6284 color
= getPixelColor(device
, 440, 200);
6285 ok(color
== 0x00ffffff, "pixel 440/200 has color %08x, expected 0x00ffffff\n", color
);
6286 color
= getPixelColor(device
, 200, 270);
6287 ok(color
== 0x00ffffff, "pixel 200/270 has color %08x, expected 0x00ffffff\n", color
);
6288 color
= getPixelColor(device
, 280, 270);
6289 ok(color
== 0x00ff0000, "pixel 280/270 has color %08x, expected 0x00ff0000\n", color
);
6290 color
= getPixelColor(device
, 360, 270);
6291 ok(color
== 0x0000ff00, "pixel 360/270 has color %08x, expected 0x0000ff00\n", color
);
6292 color
= getPixelColor(device
, 440, 270);
6293 ok(color
== 0x00ffffff, "pixel 440/270 has color %08x, expected 0x00ffffff\n", color
);
6294 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
6295 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
6297 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
6298 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
6299 if (!(caps
.DevCaps2
& D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES
))
6301 skip("Blitting from textures is not supported.\n");
6302 IDirect3DSurface9_Release(backbuffer
);
6303 IDirect3DDevice9_Release(device
);
6306 hr
= IDirect3DDevice9_CreateTexture(device
, 1024, 1024, 1, 0,
6307 D3DFMT_X8R8G8B8
, D3DPOOL_SYSTEMMEM
, &texture
, 0);
6308 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
6309 hr
= IDirect3DDevice9_CreateTexture(device
, 1024, 1024, 0, D3DUSAGE_AUTOGENMIPMAP
,
6310 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &texture2
, 0);
6311 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
6312 hr
= IDirect3DDevice9_CreateTexture(device
, 1024, 1024, 0, D3DUSAGE_AUTOGENMIPMAP
| D3DUSAGE_RENDERTARGET
,
6313 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &texture3
, 0);
6314 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
6316 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
6317 ok(SUCCEEDED(hr
), "Failed to get surface, hr %#x.\n", hr
);
6318 memset(&lr
, 0, sizeof(lr
));
6319 hr
= IDirect3DSurface9_LockRect(surface
, &lr
, NULL
, 0);
6320 ok(SUCCEEDED(hr
), "Failed to map surface, hr %#x.\n", hr
);
6321 for (y
= 0; y
< 1024; ++y
)
6323 for (x
= 0; x
< 1024; ++x
)
6325 DWORD
*dst
= (DWORD
*)((BYTE
*)lr
.pBits
+ y
* lr
.Pitch
+ x
* 4);
6330 if (PtInRect(&r1
, pt
))
6332 else if (PtInRect(&r2
, pt
))
6334 else if (PtInRect(&r3
, pt
))
6336 else if (PtInRect(&r4
, pt
))
6342 hr
= IDirect3DSurface9_UnlockRect(surface
);
6343 ok(SUCCEEDED(hr
), "Failed to unmap surface, hr %#x.\n", hr
);
6344 IDirect3DSurface9_Release(surface
);
6346 hr
= IDirect3DDevice9_UpdateTexture(device
, (IDirect3DBaseTexture9
*)texture
,
6347 (IDirect3DBaseTexture9
*)texture2
);
6348 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x.\n", hr
);
6350 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)texture2
);
6351 ok(SUCCEEDED(hr
), "Failed to set texture, hr %x.\n", hr
);
6353 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffff00, 1.0f
, 0);
6354 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
6356 hr
= IDirect3DDevice9_BeginScene(device
);
6357 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6358 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
6359 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6360 hr
= IDirect3DDevice9_EndScene(device
);
6361 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6363 color
= getPixelColor(device
, 200, 200);
6364 ok(color
== 0x00ffffff, "Unexpected color 0x%08x.\n", color
);
6365 color
= getPixelColor(device
, 280, 200);
6366 ok(color
== 0x000000ff, "Unexpected color 0x%08x.\n", color
);
6367 color
= getPixelColor(device
, 360, 200);
6368 ok(color
== 0x00000000, "Unexpected color 0x%08x.\n", color
);
6369 color
= getPixelColor(device
, 440, 200);
6370 ok(color
== 0x00ffffff, "Unexpected color 0x%08x.\n", color
);
6371 color
= getPixelColor(device
, 200, 270);
6372 ok(color
== 0x00ffffff, "Unexpected color 0x%08x.\n", color
);
6373 color
= getPixelColor(device
, 280, 270);
6374 ok(color
== 0x00ff0000, "Unexpected color 0x%08x.\n", color
);
6375 color
= getPixelColor(device
, 360, 270);
6376 ok(color
== 0x0000ff00, "Unexpected color 0x%08x.\n", color
);
6377 color
= getPixelColor(device
, 440, 270);
6378 ok(color
== 0x00ffffff, "Unexpected color 0x%08x.\n", color
);
6380 hr
= IDirect3DTexture9_GetSurfaceLevel(texture2
, 0, &surface2
);
6381 ok(SUCCEEDED(hr
), "Failed to get surface, hr %#x.\n", hr
);
6382 hr
= IDirect3DTexture9_GetSurfaceLevel(texture3
, 0, &surface3
);
6383 ok(SUCCEEDED(hr
), "Failed to get surface, hr %#x.\n", hr
);
6384 hr
= IDirect3DDevice9_StretchRect(device
, surface2
, NULL
, surface3
, NULL
, D3DTEXF_POINT
);
6385 ok(SUCCEEDED(hr
), "Failed to blit texture, hr %#x.\n", hr
);
6387 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)texture3
);
6388 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
6390 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffff00, 1.0f
, 0);
6391 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
6393 hr
= IDirect3DDevice9_BeginScene(device
);
6394 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6395 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
6396 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6397 hr
= IDirect3DDevice9_EndScene(device
);
6398 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6400 color
= getPixelColor(device
, 200, 200);
6401 ok(color
== 0x00ffffff, "Unexpected color 0x%08x.\n", color
);
6402 color
= getPixelColor(device
, 280, 200);
6403 ok(color
== 0x000000ff, "Unexpected color 0x%08x.\n", color
);
6404 color
= getPixelColor(device
, 360, 200);
6405 ok(color
== 0x00000000, "Unexpected color 0x%08x.\n", color
);
6406 color
= getPixelColor(device
, 440, 200);
6407 ok(color
== 0x00ffffff, "Unexpected color 0x%08x.\n", color
);
6408 color
= getPixelColor(device
, 200, 270);
6409 ok(color
== 0x00ffffff, "Unexpected color 0x%08x.\n", color
);
6410 color
= getPixelColor(device
, 280, 270);
6411 ok(color
== 0x00ff0000, "Unexpected color 0x%08x.\n", color
);
6412 color
= getPixelColor(device
, 360, 270);
6413 ok(color
== 0x0000ff00, "Unexpected color 0x%08x.\n", color
);
6414 color
= getPixelColor(device
, 440, 270);
6415 ok(color
== 0x00ffffff, "Unexpected color 0x%08x.\n", color
);
6417 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, surface3
);
6418 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
6420 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ffff, 1.0f
, 0);
6421 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
6423 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
6424 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
6426 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffff00, 1.0f
, 0);
6427 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
6429 hr
= IDirect3DDevice9_BeginScene(device
);
6430 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6431 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
6432 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6433 hr
= IDirect3DDevice9_EndScene(device
);
6434 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6436 color
= getPixelColor(device
, 200, 200);
6437 ok(color
== 0x0000ffff, "Unexpected color 0x%08x.\n", color
);
6439 IDirect3DSurface9_Release(surface3
);
6440 IDirect3DSurface9_Release(surface2
);
6441 IDirect3DTexture9_Release(texture3
);
6442 IDirect3DTexture9_Release(texture2
);
6443 IDirect3DTexture9_Release(texture
);
6445 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
))
6447 skip("No cube textures support.\n");
6448 IDirect3DSurface9_Release(backbuffer
);
6449 IDirect3DDevice9_Release(device
);
6452 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 1024, 0, D3DUSAGE_AUTOGENMIPMAP
,
6453 D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &cube_texture
, 0);
6454 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
6455 for (i
= 0; i
< 6; ++i
)
6457 hr
= IDirect3DCubeTexture9_LockRect(cube_texture
, i
, 0, &lr
, NULL
, 0);
6458 ok(SUCCEEDED(hr
), "Failed to map texture, hr %#x.\n", hr
);
6460 for (y
= 0; y
< 1024; ++y
)
6462 for (x
= 0; x
< 1024; ++x
)
6464 DWORD
*dst
= (DWORD
*)((BYTE
*)lr
.pBits
+ y
* lr
.Pitch
+ x
* 4);
6469 if (PtInRect(&r1
, pt
))
6471 else if (PtInRect(&r2
, pt
))
6473 else if (PtInRect(&r3
, pt
))
6475 else if (PtInRect(&r4
, pt
))
6481 hr
= IDirect3DCubeTexture9_UnlockRect(cube_texture
, i
, 0);
6482 ok(SUCCEEDED(hr
), "Failed to unmap texture, hr %#x.\n", hr
);
6485 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)cube_texture
);
6486 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
6488 hr
= IDirect3DDevice9_BeginScene(device
);
6489 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6490 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
6491 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
6492 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
6493 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6494 hr
= IDirect3DDevice9_EndScene(device
);
6495 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6496 IDirect3DCubeTexture9_Release(cube_texture
);
6498 color
= getPixelColor(device
, 200, 200);
6499 ok(color
== 0x00000000, "Unexpected color 0x%08x.\n", color
);
6500 color
= getPixelColor(device
, 280, 200);
6501 ok(color
== 0x00ffffff, "Unexpected color 0x%08x.\n", color
);
6502 color
= getPixelColor(device
, 360, 200);
6503 ok(color
== 0x00ffffff, "Unexpected color 0x%08x.\n", color
);
6504 color
= getPixelColor(device
, 440, 200);
6505 ok(color
== 0x00ffffff, "Unexpected color 0x%08x.\n", color
);
6506 color
= getPixelColor(device
, 200, 270);
6507 ok(color
== 0x00000000, "Unexpected color 0x%08x.\n", color
);
6508 color
= getPixelColor(device
, 280, 270);
6509 ok(color
== 0x00ffffff, "Unexpected color 0x%08x.\n", color
);
6510 color
= getPixelColor(device
, 360, 270);
6511 ok(color
== 0x00ffffff, "Unexpected color 0x%08x.\n", color
);
6512 color
= getPixelColor(device
, 440, 270);
6513 ok(color
== 0x0000ff00, "Unexpected color 0x%08x.\n", color
);
6515 /* Test format not supporting D3DUSAGE_AUTOGENMIPMAP. */
6516 hr
= IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
,
6517 D3DFMT_X8R8G8B8
, D3DUSAGE_AUTOGENMIPMAP
, D3DRTYPE_TEXTURE
, D3DFMT_A1R5G5B5
);
6518 if (hr
!= D3DOK_NOAUTOGEN
)
6520 skip("D3DFMT_A1R5G5B5 support is not D3DOK_NOAUTOGEN (%#x).\n", hr
);
6524 hr
= IDirect3DDevice9_CreateTexture(device
, 1024, 1024, 0, D3DUSAGE_AUTOGENMIPMAP
,
6525 D3DFMT_A1R5G5B5
, D3DPOOL_MANAGED
, &texture
, 0);
6526 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
6528 hr
= IDirect3DTexture9_LockRect(texture
, 0, &lr
, NULL
, 0);
6529 ok(SUCCEEDED(hr
), "Failed to map texture, hr %#x.\n", hr
);
6530 for (y
= 0; y
< 1024; ++y
)
6532 for (x
= 0; x
< 1024; ++x
)
6534 WORD
*dst
= (WORD
*)(((BYTE
*)lr
.pBits
) + y
* lr
.Pitch
+ x
* 2);
6539 if (PtInRect(&r1
, pt
))
6541 else if (PtInRect(&r2
, pt
))
6543 else if (PtInRect(&r3
, pt
))
6545 else if (PtInRect(&r4
, pt
))
6551 hr
= IDirect3DTexture9_UnlockRect(texture
, 0);
6552 ok(SUCCEEDED(hr
), "Failed to unmap texture, hr %#x.\n", hr
);
6554 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)texture
);
6555 ok(SUCCEEDED(hr
), "Failed to set texture, %#x.\n", hr
);
6557 hr
= IDirect3DDevice9_BeginScene(device
);
6558 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6559 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
6560 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6561 hr
= IDirect3DDevice9_EndScene(device
);
6562 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6563 IDirect3DTexture9_Release(texture
);
6565 color
= getPixelColor(device
, 200, 200);
6566 ok(color
== 0x00ffffff, "Unexpected color 0x%08x.\n", color
);
6567 color
= getPixelColor(device
, 280, 200);
6568 ok(color
== 0x000000ff, "Unexpected color 0x%08x.\n", color
);
6569 color
= getPixelColor(device
, 360, 200);
6570 ok(color
== 0x00000000, "Unexpected color 0x%08x.\n", color
);
6571 color
= getPixelColor(device
, 440, 200);
6572 ok(color
== 0x00ffffff, "Unexpected color 0x%08x.\n", color
);
6573 color
= getPixelColor(device
, 200, 270);
6574 ok(color
== 0x00ffffff, "Unexpected color 0x%08x.\n", color
);
6575 color
= getPixelColor(device
, 280, 270);
6576 ok(color
== 0x00ff0000, "Unexpected color 0x%08x.\n", color
);
6577 color
= getPixelColor(device
, 360, 270);
6578 ok(color
== 0x0000ff00, "Unexpected color 0x%08x.\n", color
);
6579 color
= getPixelColor(device
, 440, 270);
6580 ok(color
== 0x00ffffff, "Unexpected color 0x%08x.\n", color
);
6581 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
6582 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
6585 IDirect3DSurface9_Release(backbuffer
);
6587 refcount
= IDirect3DDevice9_Release(device
);
6588 ok(!refcount
, "Device has %u references left.\n", refcount
);
6590 IDirect3D9_Release(d3d
);
6591 DestroyWindow(window
);
6594 static void test_constant_clamp_vs(void)
6596 IDirect3DVertexShader9
*shader_11
, *shader_11_2
, *shader_20
, *shader_20_2
;
6597 IDirect3DVertexDeclaration9
*decl
;
6598 IDirect3DDevice9
*device
;
6606 static const DWORD shader_code_11
[] =
6608 0xfffe0101, /* vs_1_1 */
6609 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
6610 0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
6611 0x00000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
6612 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
6613 0x0000ffff /* end */
6615 static const DWORD shader_code_11_2
[] =
6617 0xfffe0101, /* vs_1_1 */
6618 0x00000051, 0xa00f0001, 0x3fa00000, 0xbf000000, 0xbfc00000, 0x3f800000, /* dcl ... */
6619 0x00000051, 0xa00f0002, 0xbf000000, 0x3fa00000, 0x40000000, 0x3f800000, /* dcl ... */
6620 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
6621 0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
6622 0x00000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
6623 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
6624 0x0000ffff /* end */
6626 static const DWORD shader_code_20
[] =
6628 0xfffe0200, /* vs_2_0 */
6629 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
6630 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
6631 0x03000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
6632 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
6633 0x0000ffff /* end */
6635 static const DWORD shader_code_20_2
[] =
6637 0xfffe0200, /* vs_2_0 */
6638 0x05000051, 0xa00f0001, 0x3fa00000, 0xbf000000, 0xbfc00000, 0x3f800000,
6639 0x05000051, 0xa00f0002, 0xbf000000, 0x3fa00000, 0x40000000, 0x3f800000,
6640 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
6641 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
6642 0x03000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
6643 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
6644 0x0000ffff /* end */
6646 static const D3DVERTEXELEMENT9 decl_elements
[] =
6648 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
6651 static const float quad1
[] =
6658 static const float quad2
[] =
6665 static const float quad3
[] =
6672 static const float quad4
[] =
6679 static const float test_data_c1
[4] = { 1.25f
, -0.50f
, -1.50f
, 1.0f
};
6680 static const float test_data_c2
[4] = {-0.50f
, 1.25f
, 2.00f
, 1.0f
};
6682 window
= create_window();
6683 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
6684 ok(!!d3d
, "Failed to create a D3D object.\n");
6685 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
6687 skip("Failed to create a D3D device, skipping tests.\n");
6691 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
6692 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
6693 if (caps
.VertexShaderVersion
< D3DVS_VERSION(1, 1))
6695 skip("No vs_1_1 support, skipping tests.\n");
6696 IDirect3DDevice9_Release(device
);
6700 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff00ffff, 1.0f
, 0);
6701 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
6703 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_code_11
, &shader_11
);
6704 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr
);
6705 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_code_11_2
, &shader_11_2
);
6706 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr
);
6707 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_code_20
, &shader_20
);
6708 if(FAILED(hr
)) shader_20
= NULL
;
6709 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_code_20_2
, &shader_20_2
);
6710 if(FAILED(hr
)) shader_20_2
= NULL
;
6711 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &decl
);
6712 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr
);
6714 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 1, test_data_c1
, 1);
6715 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShaderConstantF returned %08x\n", hr
);
6716 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 2, test_data_c2
, 1);
6717 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShaderConstantF returned %08x\n", hr
);
6718 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl
);
6719 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration returned %08x\n", hr
);
6721 hr
= IDirect3DDevice9_BeginScene(device
);
6722 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6724 hr
= IDirect3DDevice9_SetVertexShader(device
, shader_11
);
6725 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
6726 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, 3 * sizeof(float));
6727 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6729 hr
= IDirect3DDevice9_SetVertexShader(device
, shader_11_2
);
6730 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
6731 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, 3 * sizeof(float));
6732 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6736 hr
= IDirect3DDevice9_SetVertexShader(device
, shader_20
);
6737 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
6738 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, 3 * sizeof(float));
6739 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6744 hr
= IDirect3DDevice9_SetVertexShader(device
, shader_20_2
);
6745 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
6746 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, 3 * sizeof(float));
6747 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6750 hr
= IDirect3DDevice9_EndScene(device
);
6751 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6753 color
= getPixelColor(device
, 160, 360);
6754 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0xbf, 0xbf, 0x80), 1),
6755 "quad 1 has color %08x, expected 0x00bfbf80\n", color
);
6756 color
= getPixelColor(device
, 480, 360);
6757 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0xbf, 0xbf, 0x80), 1),
6758 "quad 2 has color %08x, expected 0x00bfbf80\n", color
);
6760 color
= getPixelColor(device
, 480, 120);
6761 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0xbf, 0xbf, 0x80), 1),
6762 "quad 3 has color %08x, expected 0x00bfbf80\n", color
);
6765 color
= getPixelColor(device
, 160, 120);
6766 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0xbf, 0xbf, 0x80), 1),
6767 "quad 4 has color %08x, expected 0x00bfbf80\n", color
);
6769 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
6770 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
6772 IDirect3DVertexDeclaration9_Release(decl
);
6773 if(shader_20_2
) IDirect3DVertexShader9_Release(shader_20_2
);
6774 if(shader_20
) IDirect3DVertexShader9_Release(shader_20
);
6775 IDirect3DVertexShader9_Release(shader_11_2
);
6776 IDirect3DVertexShader9_Release(shader_11
);
6777 refcount
= IDirect3DDevice9_Release(device
);
6778 ok(!refcount
, "Device has %u references left.\n", refcount
);
6780 IDirect3D9_Release(d3d
);
6781 DestroyWindow(window
);
6784 static void constant_clamp_ps_test(void)
6786 IDirect3DPixelShader9
*shader_11
, *shader_12
, *shader_14
, *shader_20
;
6787 IDirect3DDevice9
*device
;
6795 static const DWORD shader_code_11
[] =
6797 0xffff0101, /* ps_1_1 */
6798 0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
6799 0x00000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
6800 0x0000ffff /* end */
6802 static const DWORD shader_code_12
[] =
6804 0xffff0102, /* ps_1_2 */
6805 0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
6806 0x00000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
6807 0x0000ffff /* end */
6809 /* Skip 1.3 shaders because we have only 4 quads (ok, could make them
6810 * smaller if needed). 1.2 and 1.4 shaders behave the same, so it's
6811 * unlikely that 1.3 shaders are different. During development of this
6812 * test, 1.3 shaders were verified too. */
6813 static const DWORD shader_code_14
[] =
6815 0xffff0104, /* ps_1_4 */
6816 /* Try to make one constant local. It gets clamped too, although the
6817 * binary contains the bigger numbers. */
6818 0x00000051, 0xa00f0002, 0xbf000000, 0x3fa00000, 0x40000000, 0x3f800000, /* def c2, -0.5, 1.25, 2, 1 */
6819 0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
6820 0x00000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
6821 0x0000ffff /* end */
6823 static const DWORD shader_code_20
[] =
6825 0xffff0200, /* ps_2_0 */
6826 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
6827 0x03000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
6828 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
6829 0x0000ffff /* end */
6831 static const float quad1
[] =
6838 static const float quad2
[] =
6845 static const float quad3
[] =
6852 static const float quad4
[] =
6859 static const float test_data_c1
[4] = { 1.25f
, -0.50f
, -1.50f
, 1.0f
};
6860 static const float test_data_c2
[4] = {-0.50f
, 1.25f
, 2.00f
, 1.0f
};
6862 window
= create_window();
6863 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
6864 ok(!!d3d
, "Failed to create a D3D object.\n");
6865 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
6867 skip("Failed to create a D3D device, skipping tests.\n");
6871 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
6872 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
6873 if (caps
.PixelShaderVersion
< D3DPS_VERSION(1, 4))
6875 skip("No ps_1_4 support, skipping tests.\n");
6876 IDirect3DDevice9_Release(device
);
6880 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff00ffff, 1.0f
, 0);
6881 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
6883 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_11
, &shader_11
);
6884 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr
);
6885 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_12
, &shader_12
);
6886 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr
);
6887 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_14
, &shader_14
);
6888 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr
);
6889 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_20
, &shader_20
);
6890 if(FAILED(hr
)) shader_20
= NULL
;
6892 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 1, test_data_c1
, 1);
6893 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr
);
6894 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 2, test_data_c2
, 1);
6895 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr
);
6896 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
6897 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF returned %08x\n", hr
);
6899 hr
= IDirect3DDevice9_BeginScene(device
);
6900 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6902 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_11
);
6903 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
6904 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, 3 * sizeof(float));
6905 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6907 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_12
);
6908 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
6909 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, 3 * sizeof(float));
6910 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6912 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_14
);
6913 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
6914 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, 3 * sizeof(float));
6915 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6919 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_20
);
6920 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
6921 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, 3 * sizeof(float));
6922 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6925 hr
= IDirect3DDevice9_EndScene(device
);
6926 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6928 color
= getPixelColor(device
, 160, 360);
6929 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x80, 0x80, 0x00), 1),
6930 "quad 1 has color %08x, expected 0x00808000\n", color
);
6931 color
= getPixelColor(device
, 480, 360);
6932 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x80, 0x80, 0x00), 1),
6933 "quad 2 has color %08x, expected 0x00808000\n", color
);
6934 color
= getPixelColor(device
, 480, 120);
6935 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x80, 0x80, 0x00), 1),
6936 "quad 3 has color %08x, expected 0x00808000\n", color
);
6938 color
= getPixelColor(device
, 160, 120);
6939 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0xbf, 0xbf, 0x80), 1),
6940 "quad 4 has color %08x, expected 0x00bfbf80\n", color
);
6942 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
6943 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
6945 if(shader_20
) IDirect3DPixelShader9_Release(shader_20
);
6946 IDirect3DPixelShader9_Release(shader_14
);
6947 IDirect3DPixelShader9_Release(shader_12
);
6948 IDirect3DPixelShader9_Release(shader_11
);
6949 refcount
= IDirect3DDevice9_Release(device
);
6950 ok(!refcount
, "Device has %u references left.\n", refcount
);
6952 IDirect3D9_Release(d3d
);
6953 DestroyWindow(window
);
6956 static void dp2add_ps_test(void)
6958 IDirect3DPixelShader9
*shader_dp2add_sat
;
6959 IDirect3DPixelShader9
*shader_dp2add
;
6960 IDirect3DDevice9
*device
;
6968 /* DP2ADD is defined as: (src0.r * src1.r) + (src0.g * src1.g) + src2.
6969 * One D3D restriction of all shader instructions except SINCOS is that no more than 2
6970 * source tokens can be constants. So, for this exercise, we move contents of c0 to
6972 * The result here for the r,g,b components should be roughly 0.5:
6973 * (0.5 * 0.5) + (0.5 * 0.5) + 0.0 = 0.5 */
6974 static const DWORD shader_code_dp2add
[] = {
6975 0xffff0200, /* ps_2_0 */
6976 0x05000051, 0xa00f0000, 0x3f000000, 0x3f000000, 0x3f800000, 0x00000000, /* def c0, 0.5, 0.5, 1.0, 0 */
6978 0x02000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
6979 0x0400005a, 0x80070000, 0x80000000, 0x80000000, 0x80ff0000, /* dp2add r0.rgb, r0, r0, r0.a */
6981 0x02000001, 0x80080000, 0xa0aa0000, /* mov r0.a, c0.b */
6982 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
6983 0x0000ffff /* end */
6986 /* Test the _sat modifier, too. Result here should be:
6987 * DP2: (-0.5 * -0.5) + (-0.5 * -0.5) + 2.0 = 2.5
6989 * ADD: (1.0 + -0.5) = 0.5
6991 static const DWORD shader_code_dp2add_sat
[] = {
6992 0xffff0200, /* ps_2_0 */
6993 0x05000051, 0xa00f0000, 0xbf000000, 0xbf000000, 0x3f800000, 0x40000000, /* def c0, -0.5, -0.5, 1.0, 2.0 */
6995 0x02000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
6996 0x0400005a, 0x80170000, 0x80000000, 0x80000000, 0x80ff0000, /* dp2add_sat r0.rgb, r0, r0, r0.a */
6997 0x03000002, 0x80070000, 0x80e40000, 0xa0000000, /* add r0.rgb, r0, c0.r */
6999 0x02000001, 0x80080000, 0xa0aa0000, /* mov r0.a, c0.b */
7000 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
7001 0x0000ffff /* end */
7003 static const float quad
[] =
7011 window
= create_window();
7012 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
7013 ok(!!d3d
, "Failed to create a D3D object.\n");
7014 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
7016 skip("Failed to create a D3D device, skipping tests.\n");
7020 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
7021 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
7022 if (caps
.PixelShaderVersion
< D3DPS_VERSION(2, 0))
7024 skip("No ps_2_0 support, skipping tests.\n");
7025 IDirect3DDevice9_Release(device
);
7029 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff000000, 1.0f
, 0);
7030 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
7032 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_dp2add
, &shader_dp2add
);
7033 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr
);
7035 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_dp2add_sat
, &shader_dp2add_sat
);
7036 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr
);
7038 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
7039 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF returned %08x\n", hr
);
7041 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_dp2add
);
7042 ok(SUCCEEDED(hr
), "Failed to create pixel shader, hr %#x.\n", hr
);
7043 hr
= IDirect3DDevice9_BeginScene(device
);
7044 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7045 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 3 * sizeof(float));
7046 ok(SUCCEEDED(hr
), "Failed to draw primitive, hr %#x.\n", hr
);
7047 hr
= IDirect3DDevice9_EndScene(device
);
7048 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7050 color
= getPixelColor(device
, 360, 240);
7051 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x7f, 0x7f, 0x7f), 1), "Got unexpected color 0x%08x.\n", color
);
7053 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
7054 ok(SUCCEEDED(hr
), "Failed to present frame, hr %#x.\n", hr
);
7055 IDirect3DPixelShader9_Release(shader_dp2add
);
7057 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_dp2add_sat
);
7058 ok(SUCCEEDED(hr
), "Failed to create pixel shader, hr %#x.\n", hr
);
7059 hr
= IDirect3DDevice9_BeginScene(device
);
7060 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7061 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 3 * sizeof(float));
7062 ok(SUCCEEDED(hr
), "Failed to draw primitive, hr %#x.\n", hr
);
7063 hr
= IDirect3DDevice9_EndScene(device
);
7064 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7066 color
= getPixelColor(device
, 360, 240);
7067 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x7f, 0x7f, 0x7f), 1), "Got unexpected color 0x%08x.\n", color
);
7069 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
7070 ok(SUCCEEDED(hr
), "Failed to present frame, hr %#x.\n", hr
);
7071 IDirect3DPixelShader9_Release(shader_dp2add_sat
);
7073 refcount
= IDirect3DDevice9_Release(device
);
7074 ok(!refcount
, "Device has %u references left.\n", refcount
);
7076 IDirect3D9_Release(d3d
);
7077 DestroyWindow(window
);
7080 static void cnd_test(void)
7082 IDirect3DPixelShader9
*shader_11_coissue_2
, *shader_12_coissue_2
, *shader_13_coissue_2
, *shader_14_coissue_2
;
7083 IDirect3DPixelShader9
*shader_11_coissue
, *shader_12_coissue
, *shader_13_coissue
, *shader_14_coissue
;
7084 IDirect3DPixelShader9
*shader_11
, *shader_12
, *shader_13
, *shader_14
;
7085 IDirect3DDevice9
*device
;
7093 /* ps 1.x shaders are rather picky with writemasks and source swizzles.
7094 * The dp3 is used to copy r0.r to all components of r1, then copy r1.a to
7095 * r0.a. Essentially it does a mov r0.a, r0.r, which isn't allowed as-is
7096 * in 1.x pixel shaders. */
7097 static const DWORD shader_code_11
[] =
7099 0xffff0101, /* ps_1_1 */
7100 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
7101 0x00000040, 0xb00f0000, /* texcoord t0 */
7102 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, ???(t0) */
7103 0x00000008, 0x800f0001, 0x80e40000, 0xa0e40000, /* dp3 r1, r0, c0 */
7104 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
7105 0x00000050, 0x800f0000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* cnd r0, r0.a, c1, c2 */
7106 0x0000ffff /* end */
7108 static const DWORD shader_code_12
[] =
7110 0xffff0102, /* ps_1_2 */
7111 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
7112 0x00000040, 0xb00f0000, /* texcoord t0 */
7113 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
7114 0x00000008, 0x800f0001, 0x80e40000, 0xa0e40000, /* dp3 r1, r0, c0 */
7115 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
7116 0x00000050, 0x800f0000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* cnd r0, r0.a, c1, c2 */
7117 0x0000ffff /* end */
7119 static const DWORD shader_code_13
[] =
7121 0xffff0103, /* ps_1_3 */
7122 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
7123 0x00000040, 0xb00f0000, /* texcoord t0 */
7124 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
7125 0x00000008, 0x800f0001, 0x80e40000, 0xa0e40000, /* dp3, r1, r0, c0 */
7126 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
7127 0x00000050, 0x800f0000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* cnd r0, r0.a, c1, c2 */
7128 0x0000ffff /* end */
7130 static const DWORD shader_code_14
[] =
7132 0xffff0104, /* ps_1_3 */
7133 0x00000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0, 0, 0, 1 */
7134 0x00000040, 0x80070000, 0xb0e40000, /* texcrd r0, t0 */
7135 0x00000001, 0x80080000, 0xa0ff0000, /* mov r0.a, c0.a */
7136 0x00000050, 0x800f0000, 0x80e40000, 0xa0e40001, 0xa0e40002, /* cnd r0, r0, c1, c2 */
7137 0x0000ffff /* end */
7140 /* Special fun: The coissue flag on cnd: Apparently cnd always selects the 2nd source,
7141 * as if the src0 comparison against 0.5 always evaluates to true. The coissue flag isn't
7142 * set by the compiler, it was added manually after compilation. Note that the COISSUE
7143 * flag on a color(.xyz) operation is only allowed after an alpha operation. DirectX doesn't
7144 * have proper docs, but GL_ATI_fragment_shader explains the pairing of color and alpha ops
7147 * The shader attempts to test the range [-1;1] against coissued cnd, which is a bit tricky.
7148 * The input from t0 is [0;1]. 0.5 is subtracted, then we have to multiply with 2. Since
7149 * constants are clamped to [-1;1], a 2.0 is constructed by adding c0.r(=1.0) to c0.r into r1.r,
7150 * then r1(2.0, 0.0, 0.0, 0.0) is passed to dp3(explained above).
7152 static const DWORD shader_code_11_coissue
[] =
7154 0xffff0101, /* ps_1_1 */
7155 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
7156 0x00000051, 0xa00f0003, 0x3f000000, 0x3f000000, 0x3f000000, 0x00000000, /* def c3, 0.5, 0.5, 0.5, 0 */
7157 0x00000040, 0xb00f0000, /* texcoord t0 */
7158 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
7159 0x00000003, 0x800f0000, 0x80e40000, 0xa0e40003, /* sub r0, r0, c3 */
7160 0x00000002, 0x800f0001, 0xa0e40000, 0xa0e40000, /* add r1, c0, c0 */
7161 0x00000008, 0x800f0001, 0x80e40000, 0x80e40001, /* dp3 r1, r0, r1 */
7162 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
7163 0x40000050, 0x80070000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* +cnd r0.xyz, r0.a, c1, c2*/
7164 0x0000ffff /* end */
7166 static const DWORD shader_code_11_coissue_2
[] =
7168 0xffff0101, /* ps_1_1 */
7169 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
7170 0x00000051, 0xa00f0003, 0x3f000000, 0x3f000000, 0x3f000000, 0x00000000, /* def c3, 0.5, 0.5, 0.5, 0 */
7171 0x00000040, 0xb00f0000, /* texcoord t0 */
7172 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
7173 0x00000003, 0x800f0000, 0x80e40000, 0xa0e40003, /* sub r0, r0, c3 */
7174 0x00000002, 0x800f0001, 0xa0e40000, 0xa0e40000, /* add r1, c0, c0 */
7175 0x00000008, 0x800f0001, 0x80e40000, 0x80e40001, /* dp3 r1, r0, r1 */
7176 0x00000001, 0x800f0000, 0x80e40001, /* mov r0, r1 */
7177 0x00000001, 0x80070000, 0x80ff0001, /* mov r0.xyz, r1.a */
7178 0x40000050, 0x80080000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* +cnd r0.a, r0.a, c1, c2 */
7179 0x00000001, 0x80070000, 0x80ff0000, /* mov r0.xyz, r0.a */
7180 0x0000ffff /* end */
7182 static const DWORD shader_code_12_coissue
[] =
7184 0xffff0102, /* ps_1_2 */
7185 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
7186 0x00000051, 0xa00f0003, 0x3f000000, 0x3f000000, 0x3f000000, 0x00000000, /* def c3, 0.5, 0.5, 0.5, 0 */
7187 0x00000040, 0xb00f0000, /* texcoord t0 */
7188 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
7189 0x00000003, 0x800f0000, 0x80e40000, 0xa0e40003, /* sub r0, r0, c3 */
7190 0x00000002, 0x800f0001, 0xa0e40000, 0xa0e40000, /* add r1, c0, c0 */
7191 0x00000008, 0x800f0001, 0x80e40000, 0x80e40001, /* dp3 r1, r0, r1 */
7192 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
7193 0x40000050, 0x80070000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* +cnd r0.xyz, r0.a, c1, c2*/
7194 0x0000ffff /* end */
7196 static const DWORD shader_code_12_coissue_2
[] =
7198 0xffff0102, /* ps_1_2 */
7199 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
7200 0x00000051, 0xa00f0003, 0x3f000000, 0x3f000000, 0x3f000000, 0x00000000, /* def c3, 0.5, 0.5, 0.5, 0 */
7201 0x00000040, 0xb00f0000, /* texcoord t0 */
7202 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
7203 0x00000003, 0x800f0000, 0x80e40000, 0xa0e40003, /* sub r0, r0, c3 */
7204 0x00000002, 0x800f0001, 0xa0e40000, 0xa0e40000, /* add r1, c0, c0 */
7205 0x00000008, 0x800f0001, 0x80e40000, 0x80e40001, /* dp3 r1, r0, r1 */
7206 0x00000001, 0x800f0000, 0x80e40001, /* mov r0, r1 */
7207 0x00000001, 0x80070000, 0x80ff0001, /* mov r0.xyz, r1.a */
7208 0x40000050, 0x80080000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* +cnd r0.a, r0.a, c1, c2 */
7209 0x00000001, 0x80070000, 0x80ff0000, /* mov r0.xyz, r0.a */
7210 0x0000ffff /* end */
7212 static const DWORD shader_code_13_coissue
[] =
7214 0xffff0103, /* ps_1_3 */
7215 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
7216 0x00000051, 0xa00f0003, 0x3f000000, 0x3f000000, 0x3f000000, 0x00000000, /* def c3, 0.5, 0.5, 0.5, 0 */
7217 0x00000040, 0xb00f0000, /* texcoord t0 */
7218 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
7219 0x00000003, 0x800f0000, 0x80e40000, 0xa0e40003, /* sub r0, r0, c3 */
7220 0x00000002, 0x800f0001, 0xa0e40000, 0xa0e40000, /* add r1, c0, c0 */
7221 0x00000008, 0x800f0001, 0x80e40000, 0x80e40001, /* dp3 r1, r0, r1 */
7222 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
7223 0x40000050, 0x80070000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* +cnd r0.xyz, r0.a, c1, c2*/
7224 0x0000ffff /* end */
7226 static const DWORD shader_code_13_coissue_2
[] =
7228 0xffff0103, /* ps_1_3 */
7229 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
7230 0x00000051, 0xa00f0003, 0x3f000000, 0x3f000000, 0x3f000000, 0x00000000, /* def c3, 0.5, 0.5, 0.5, 0 */
7231 0x00000040, 0xb00f0000, /* texcoord t0 */
7232 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
7233 0x00000003, 0x800f0000, 0x80e40000, 0xa0e40003, /* sub r0, r0, c3 */
7234 0x00000002, 0x800f0001, 0xa0e40000, 0xa0e40000, /* add r1, c0, c0 */
7235 0x00000008, 0x800f0001, 0x80e40000, 0x80e40001, /* dp3 r1, r0, r1 */
7236 0x00000001, 0x800f0000, 0x80e40001, /* mov r0, r1 */
7237 0x00000001, 0x80070000, 0x80ff0001, /* mov r0.xyz, r1.a */
7238 0x40000050, 0x80080000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* +cnd r0.a, r0.a, c1, c2 */
7239 0x00000001, 0x80070000, 0x80ff0000, /* mov r0.xyz, r0.a */
7240 0x0000ffff /* end */
7242 /* ps_1_4 does not have a different cnd behavior, just pass the [0;1]
7243 * texcrd result to cnd, it will compare against 0.5. */
7244 static const DWORD shader_code_14_coissue
[] =
7246 0xffff0104, /* ps_1_4 */
7247 0x00000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0, 0, 0, 1 */
7248 0x00000040, 0x80070000, 0xb0e40000, /* texcrd r0.xyz, t0 */
7249 0x00000001, 0x80080000, 0xa0ff0000, /* mov r0.a, c0.a */
7250 0x40000050, 0x80070000, 0x80e40000, 0xa0e40001, 0xa0e40002, /* +cnd r0.xyz, r0, c1, c2 */
7251 0x0000ffff /* end */
7253 static const DWORD shader_code_14_coissue_2
[] =
7255 0xffff0104, /* ps_1_4 */
7256 0x00000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0, 0, 0, 1 */
7257 0x00000040, 0x80070000, 0xb0e40000, /* texcrd r0.xyz, t0 */
7258 0x00000001, 0x80080000, 0x80000000, /* mov r0.a, r0.x */
7259 0x00000001, 0x80070001, 0xa0ff0000, /* mov r1.xyz, c0.a */
7260 0x40000050, 0x80080001, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* +cnd r1.a, r0.a, c1, c2 */
7261 0x00000001, 0x80070000, 0x80ff0001, /* mov r0.xyz, r1.a */
7262 0x00000001, 0x80080000, 0xa0ff0000, /* mov r0.a, c0.a */
7263 0x0000ffff /* end */
7265 static const float quad1
[] =
7267 -1.0f
, -1.0f
, 0.1f
, 0.0f
, 0.0f
, 1.0f
,
7268 -1.0f
, 0.0f
, 0.1f
, 0.0f
, 1.0f
, 0.0f
,
7269 0.0f
, -1.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
,
7270 0.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 0.0f
,
7272 static const float quad2
[] =
7274 0.0f
, -1.0f
, 0.1f
, 0.0f
, 0.0f
, 1.0f
,
7275 0.0f
, 0.0f
, 0.1f
, 0.0f
, 1.0f
, 0.0f
,
7276 1.0f
, -1.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
,
7277 1.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 0.0f
,
7279 static const float quad3
[] =
7281 0.0f
, 0.0f
, 0.1f
, 0.0f
, 0.0f
, 1.0f
,
7282 0.0f
, 1.0f
, 0.1f
, 0.0f
, 1.0f
, 0.0f
,
7283 1.0f
, 0.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
,
7284 1.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
, 0.0f
,
7286 static const float quad4
[] =
7288 -1.0f
, 0.0f
, 0.1f
, 0.0f
, 0.0f
, 1.0f
,
7289 -1.0f
, 1.0f
, 0.1f
, 0.0f
, 1.0f
, 0.0f
,
7290 0.0f
, 0.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
,
7291 0.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
, 0.0f
,
7293 static const float test_data_c1
[4] = {0.0f
, 0.0f
, 0.0f
, 0.0f
};
7294 static const float test_data_c2
[4] = {1.0f
, 1.0f
, 1.0f
, 1.0f
};
7295 static const float test_data_c1_coi
[4] = {0.0f
, 1.0f
, 0.0f
, 0.0f
};
7296 static const float test_data_c2_coi
[4] = {1.0f
, 0.0f
, 1.0f
, 1.0f
};
7298 window
= create_window();
7299 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
7300 ok(!!d3d
, "Failed to create a D3D object.\n");
7301 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
7303 skip("Failed to create a D3D device, skipping tests.\n");
7307 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
7308 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
7309 if (caps
.PixelShaderVersion
< D3DPS_VERSION(1, 4))
7311 skip("No ps_1_4 support, skipping tests.\n");
7312 IDirect3DDevice9_Release(device
);
7316 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff00ffff, 1.0f
, 0);
7317 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
7319 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_11
, &shader_11
);
7320 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr
);
7321 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_12
, &shader_12
);
7322 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr
);
7323 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_13
, &shader_13
);
7324 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr
);
7325 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_14
, &shader_14
);
7326 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr
);
7327 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_11_coissue
, &shader_11_coissue
);
7328 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr
);
7329 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_12_coissue
, &shader_12_coissue
);
7330 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr
);
7331 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_13_coissue
, &shader_13_coissue
);
7332 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr
);
7333 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_14_coissue
, &shader_14_coissue
);
7334 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr
);
7335 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_11_coissue_2
, &shader_11_coissue_2
);
7336 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr
);
7337 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_12_coissue_2
, &shader_12_coissue_2
);
7338 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr
);
7339 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_13_coissue_2
, &shader_13_coissue_2
);
7340 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr
);
7341 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_14_coissue_2
, &shader_14_coissue_2
);
7342 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr
);
7344 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 1, test_data_c1
, 1);
7345 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr
);
7346 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 2, test_data_c2
, 1);
7347 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr
);
7348 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
7349 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF returned %08x\n", hr
);
7351 hr
= IDirect3DDevice9_BeginScene(device
);
7352 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7354 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_11
);
7355 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
7356 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, 6 * sizeof(float));
7357 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7359 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_12
);
7360 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
7361 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, 6 * sizeof(float));
7362 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7364 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_13
);
7365 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
7366 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, 6 * sizeof(float));
7367 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
7369 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_14
);
7370 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
7371 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, 6 * sizeof(float));
7372 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7374 hr
= IDirect3DDevice9_EndScene(device
);
7375 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7377 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
7378 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %08x\n", hr
);
7380 /* This is the 1.4 test. Each component(r, g, b) is tested separately against 0.5 */
7381 color
= getPixelColor(device
, 158, 118);
7382 ok(color
== 0x00ff00ff, "pixel 158, 118 has color %08x, expected 0x00ff00ff\n", color
);
7383 color
= getPixelColor(device
, 162, 118);
7384 ok(color
== 0x000000ff, "pixel 162, 118 has color %08x, expected 0x000000ff\n", color
);
7385 color
= getPixelColor(device
, 158, 122);
7386 ok(color
== 0x00ffffff, "pixel 162, 122 has color %08x, expected 0x00ffffff\n", color
);
7387 color
= getPixelColor(device
, 162, 122);
7388 ok(color
== 0x0000ffff, "pixel 162, 122 has color %08x, expected 0x0000ffff\n", color
);
7390 /* 1.1 shader. All 3 components get set, based on the .w comparison */
7391 color
= getPixelColor(device
, 158, 358);
7392 ok(color
== 0x00ffffff, "pixel 158, 358 has color %08x, expected 0x00ffffff\n", color
);
7393 color
= getPixelColor(device
, 162, 358);
7394 ok(color_match(color
, 0x00000000, 1), "pixel 162, 358 has color 0x%08x, expected 0x00000000.\n", color
);
7395 color
= getPixelColor(device
, 158, 362);
7396 ok(color
== 0x00ffffff, "pixel 158, 362 has color %08x, expected 0x00ffffff\n", color
);
7397 color
= getPixelColor(device
, 162, 362);
7398 ok(color_match(color
, 0x00000000, 1), "pixel 162, 362 has color 0x%08x, expected 0x00000000.\n", color
);
7401 color
= getPixelColor(device
, 478, 358);
7402 ok(color
== 0x00ffffff, "pixel 478, 358 has color %08x, expected 0x00ffffff\n", color
);
7403 color
= getPixelColor(device
, 482, 358);
7404 ok(color_match(color
, 0x00000000, 1), "pixel 482, 358 has color 0x%08x, expected 0x00000000.\n", color
);
7405 color
= getPixelColor(device
, 478, 362);
7406 ok(color
== 0x00ffffff, "pixel 478, 362 has color %08x, expected 0x00ffffff\n", color
);
7407 color
= getPixelColor(device
, 482, 362);
7408 ok(color_match(color
, 0x00000000, 1), "pixel 482, 362 has color 0x%08x, expected 0x00000000.\n", color
);
7411 color
= getPixelColor(device
, 478, 118);
7412 ok(color
== 0x00ffffff, "pixel 478, 118 has color %08x, expected 0x00ffffff\n", color
);
7413 color
= getPixelColor(device
, 482, 118);
7414 ok(color_match(color
, 0x00000000, 1), "pixel 482, 118 has color 0x%08x, expected 0x00000000.\n", color
);
7415 color
= getPixelColor(device
, 478, 122);
7416 ok(color
== 0x00ffffff, "pixel 478, 122 has color %08x, expected 0x00ffffff\n", color
);
7417 color
= getPixelColor(device
, 482, 122);
7418 ok(color_match(color
, 0x00000000, 1), "pixel 482, 122 has color 0x%08x, expected 0x00000000.\n", color
);
7420 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
7421 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
7423 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ffff, 0.0, 0);
7424 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
7425 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 1, test_data_c1_coi
, 1);
7426 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr
);
7427 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 2, test_data_c2_coi
, 1);
7428 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %08x\n", hr
);
7430 hr
= IDirect3DDevice9_BeginScene(device
);
7431 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7433 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_11_coissue
);
7434 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
7435 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, 6 * sizeof(float));
7436 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7438 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_12_coissue
);
7439 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
7440 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, 6 * sizeof(float));
7441 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7443 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_13_coissue
);
7444 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
7445 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, 6 * sizeof(float));
7446 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7448 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_14_coissue
);
7449 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
7450 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, 6 * sizeof(float));
7451 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7453 hr
= IDirect3DDevice9_EndScene(device
);
7454 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7456 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
7457 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %08x\n", hr
);
7459 /* This is the 1.4 test. The coissue doesn't change the behavior here, but keep in mind
7460 * that we swapped the values in c1 and c2 to make the other tests return some color
7462 color
= getPixelColor(device
, 158, 118);
7463 ok(color
== 0x00ffffff, "pixel 158, 118 has color %08x, expected 0x00ffffff\n", color
);
7464 color
= getPixelColor(device
, 162, 118);
7465 ok(color
== 0x0000ffff, "pixel 162, 118 has color %08x, expected 0x0000ffff\n", color
);
7466 color
= getPixelColor(device
, 158, 122);
7467 ok(color
== 0x00ff00ff, "pixel 162, 122 has color %08x, expected 0x00ff00ff\n", color
);
7468 color
= getPixelColor(device
, 162, 122);
7469 ok(color
== 0x000000ff, "pixel 162, 122 has color %08x, expected 0x000000ff\n", color
);
7471 /* 1.1 shader. coissue flag changed the semantic of cnd, c1 is always selected
7472 * (The Win7 nvidia driver always selects c2)
7474 color
= getPixelColor(device
, 158, 358);
7475 ok(color_match(color
, 0x0000ff00, 1) || broken(color_match(color
, 0x00ff00ff, 1)),
7476 "pixel 158, 358 has color %08x, expected 0x0000ff00\n", color
);
7477 color
= getPixelColor(device
, 162, 358);
7478 ok(color_match(color
, 0x0000ff00, 1) || broken(color_match(color
, 0x00ff00ff, 1)),
7479 "pixel 162, 358 has color %08x, expected 0x0000ff00\n", color
);
7480 color
= getPixelColor(device
, 158, 362);
7481 ok(color_match(color
, 0x0000ff00, 1) || broken(color_match(color
, 0x00ff00ff, 1)),
7482 "pixel 158, 362 has color %08x, expected 0x0000ff00\n", color
);
7483 color
= getPixelColor(device
, 162, 362);
7484 ok(color_match(color
, 0x0000ff00, 1) || broken(color_match(color
, 0x00ff00ff, 1)),
7485 "pixel 162, 362 has color %08x, expected 0x0000ff00\n", color
);
7488 color
= getPixelColor(device
, 478, 358);
7489 ok(color_match(color
, 0x0000ff00, 1) || broken(color_match(color
, 0x00ff00ff, 1)),
7490 "pixel 478, 358 has color %08x, expected 0x0000ff00\n", color
);
7491 color
= getPixelColor(device
, 482, 358);
7492 ok(color_match(color
, 0x0000ff00, 1) || broken(color_match(color
, 0x00ff00ff, 1)),
7493 "pixel 482, 358 has color %08x, expected 0x0000ff00\n", color
);
7494 color
= getPixelColor(device
, 478, 362);
7495 ok(color_match(color
, 0x0000ff00, 1) || broken(color_match(color
, 0x00ff00ff, 1)),
7496 "pixel 478, 362 has color %08x, expected 0x0000ff00\n", color
);
7497 color
= getPixelColor(device
, 482, 362);
7498 ok(color_match(color
, 0x0000ff00, 1) || broken(color_match(color
, 0x00ff00ff, 1)),
7499 "pixel 482, 362 has color %08x, expected 0x0000ff00\n", color
);
7502 color
= getPixelColor(device
, 478, 118);
7503 ok(color_match(color
, 0x0000ff00, 1) || broken(color_match(color
, 0x00ff00ff, 1)),
7504 "pixel 478, 118 has color %08x, expected 0x0000ff00\n", color
);
7505 color
= getPixelColor(device
, 482, 118);
7506 ok(color_match(color
, 0x0000ff00, 1) || broken(color_match(color
, 0x00ff00ff, 1)),
7507 "pixel 482, 118 has color %08x, expected 0x0000ff00\n", color
);
7508 color
= getPixelColor(device
, 478, 122);
7509 ok(color_match(color
, 0x0000ff00, 1) || broken(color_match(color
, 0x00ff00ff, 1)),
7510 "pixel 478, 122 has color %08x, expected 0x0000ff00\n", color
);
7511 color
= getPixelColor(device
, 482, 122);
7512 ok(color_match(color
, 0x0000ff00, 1) || broken(color_match(color
, 0x00ff00ff, 1)),
7513 "pixel 482, 122 has color %08x, expected 0x0000ff00\n", color
);
7515 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
7516 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
7518 /* Retest with the coissue flag on the alpha instruction instead. This
7519 * works "as expected". The Windows 8 testbot (WARP) seems to handle this
7520 * the same as coissue on .rgb. */
7521 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ffff, 0.0, 0);
7522 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
7524 hr
= IDirect3DDevice9_BeginScene(device
);
7525 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7527 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_11_coissue_2
);
7528 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
7529 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, 6 * sizeof(float));
7530 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7532 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_12_coissue_2
);
7533 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
7534 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, 6 * sizeof(float));
7535 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7537 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_13_coissue_2
);
7538 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
7539 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, 6 * sizeof(float));
7540 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7542 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_14_coissue_2
);
7543 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
7544 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, 6 * sizeof(float));
7545 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7547 hr
= IDirect3DDevice9_EndScene(device
);
7548 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7551 color
= getPixelColor(device
, 158, 118);
7552 ok(color
== 0x00ffffff, "pixel 158, 118 has color %08x, expected 0x00ffffff\n", color
);
7553 color
= getPixelColor(device
, 162, 118);
7554 ok(color
== 0x00000000, "pixel 162, 118 has color %08x, expected 0x00000000\n", color
);
7555 color
= getPixelColor(device
, 158, 122);
7556 ok(color
== 0x00ffffff, "pixel 162, 122 has color %08x, expected 0x00ffffff\n", color
);
7557 color
= getPixelColor(device
, 162, 122);
7558 ok(color
== 0x00000000, "pixel 162, 122 has color %08x, expected 0x00000000\n", color
);
7561 color
= getPixelColor(device
, 238, 358);
7562 ok(color_match(color
, 0x00ffffff, 1) || broken(color_match(color
, 0x00000000, 1)),
7563 "pixel 238, 358 has color %08x, expected 0x00ffffff\n", color
);
7564 color
= getPixelColor(device
, 242, 358);
7565 ok(color_match(color
, 0x00000000, 1),
7566 "pixel 242, 358 has color %08x, expected 0x00000000\n", color
);
7567 color
= getPixelColor(device
, 238, 362);
7568 ok(color_match(color
, 0x00ffffff, 1) || broken(color_match(color
, 0x00000000, 1)),
7569 "pixel 238, 362 has color %08x, expected 0x00ffffff\n", color
);
7570 color
= getPixelColor(device
, 242, 362);
7571 ok(color_match(color
, 0x00000000, 1),
7572 "pixel 242, 362 has color %08x, expected 0x00000000\n", color
);
7575 color
= getPixelColor(device
, 558, 358);
7576 ok(color_match(color
, 0x00ffffff, 1) || broken(color_match(color
, 0x00000000, 1)),
7577 "pixel 558, 358 has color %08x, expected 0x00ffffff\n", color
);
7578 color
= getPixelColor(device
, 562, 358);
7579 ok(color_match(color
, 0x00000000, 1),
7580 "pixel 562, 358 has color %08x, expected 0x00000000\n", color
);
7581 color
= getPixelColor(device
, 558, 362);
7582 ok(color_match(color
, 0x00ffffff, 1) || broken(color_match(color
, 0x00000000, 1)),
7583 "pixel 558, 362 has color %08x, expected 0x00ffffff\n", color
);
7584 color
= getPixelColor(device
, 562, 362);
7585 ok(color_match(color
, 0x00000000, 1),
7586 "pixel 562, 362 has color %08x, expected 0x00000000\n", color
);
7589 color
= getPixelColor(device
, 558, 118);
7590 ok(color_match(color
, 0x00ffffff, 1) || broken(color_match(color
, 0x00000000, 1)),
7591 "pixel 558, 118 has color %08x, expected 0x00ffffff\n", color
);
7592 color
= getPixelColor(device
, 562, 118);
7593 ok(color_match(color
, 0x00000000, 1),
7594 "pixel 562, 118 has color %08x, expected 0x00000000\n", color
);
7595 color
= getPixelColor(device
, 558, 122);
7596 ok(color_match(color
, 0x00ffffff, 1) || broken(color_match(color
, 0x00000000, 1)),
7597 "pixel 558, 122 has color %08x, expected 0x00ffffff\n", color
);
7598 color
= getPixelColor(device
, 562, 122);
7599 ok(color_match(color
, 0x00000000, 1),
7600 "pixel 562, 122 has color %08x, expected 0x00000000\n", color
);
7602 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
7603 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
7605 IDirect3DPixelShader9_Release(shader_14_coissue_2
);
7606 IDirect3DPixelShader9_Release(shader_13_coissue_2
);
7607 IDirect3DPixelShader9_Release(shader_12_coissue_2
);
7608 IDirect3DPixelShader9_Release(shader_11_coissue_2
);
7609 IDirect3DPixelShader9_Release(shader_14_coissue
);
7610 IDirect3DPixelShader9_Release(shader_13_coissue
);
7611 IDirect3DPixelShader9_Release(shader_12_coissue
);
7612 IDirect3DPixelShader9_Release(shader_11_coissue
);
7613 IDirect3DPixelShader9_Release(shader_14
);
7614 IDirect3DPixelShader9_Release(shader_13
);
7615 IDirect3DPixelShader9_Release(shader_12
);
7616 IDirect3DPixelShader9_Release(shader_11
);
7617 refcount
= IDirect3DDevice9_Release(device
);
7618 ok(!refcount
, "Device has %u references left.\n", refcount
);
7620 IDirect3D9_Release(d3d
);
7621 DestroyWindow(window
);
7624 static void nested_loop_test(void)
7626 IDirect3DVertexShader9
*vshader
;
7627 IDirect3DPixelShader9
*shader
;
7628 IDirect3DDevice9
*device
;
7636 static const DWORD shader_code
[] =
7638 0xffff0300, /* ps_3_0 */
7639 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0, 0, 0, 1 */
7640 0x05000051, 0xa00f0001, 0x3d000000, 0x00000000, 0x00000000, 0x00000000, /* def c1, 1/32, 0, 0, 0*/
7641 0x05000030, 0xf00f0000, 0x00000004, 0x00000000, 0x00000002, 0x00000000, /* defi i0, 4, 0, 2, 0 */
7642 0x02000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
7643 0x0200001b, 0xf0e40800, 0xf0e40000, /* loop aL, i0 */
7644 0x0200001b, 0xf0e40800, 0xf0e40000, /* loop aL, i0 */
7645 0x03000002, 0x800f0000, 0x80e40000, 0xa0e40001, /* add r0, r0, c1 */
7646 0x0000001d, /* endloop */
7647 0x0000001d, /* endloop */
7648 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
7649 0x0000ffff /* end */
7651 static const DWORD vshader_code
[] =
7653 0xfffe0300, /* vs_3_0 */
7654 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
7655 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
7656 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
7657 0x0000ffff /* end */
7659 static const float quad
[] =
7667 window
= create_window();
7668 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
7669 ok(!!d3d
, "Failed to create a D3D object.\n");
7670 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
7672 skip("Failed to create a D3D device, skipping tests.\n");
7676 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
7677 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
7678 if (caps
.PixelShaderVersion
< D3DPS_VERSION(3, 0) || caps
.VertexShaderVersion
< D3DVS_VERSION(3, 0))
7680 skip("No shader model 3 support, skipping tests.\n");
7681 IDirect3DDevice9_Release(device
);
7685 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code
, &shader
);
7686 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader failed with %08x\n", hr
);
7687 hr
= IDirect3DDevice9_SetPixelShader(device
, shader
);
7688 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader failed with %08x\n", hr
);
7689 hr
= IDirect3DDevice9_CreateVertexShader(device
, vshader_code
, &vshader
);
7690 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader failed with %08x\n", hr
);
7691 hr
= IDirect3DDevice9_SetVertexShader(device
, vshader
);
7692 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader failed with %08x\n", hr
);
7693 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
7694 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with %08x\n", hr
);
7695 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x0000ff00, 1.0f
, 0);
7696 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
7698 hr
= IDirect3DDevice9_BeginScene(device
);
7699 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7700 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 3 * sizeof(float));
7701 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7702 hr
= IDirect3DDevice9_EndScene(device
);
7703 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7705 color
= getPixelColor(device
, 360, 240);
7706 ok(color_match(color
, 0x00800000, 1),
7707 "Nested loop test returned color 0x%08x, expected 0x00800000.\n", color
);
7709 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
7710 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
7712 IDirect3DPixelShader9_Release(shader
);
7713 IDirect3DVertexShader9_Release(vshader
);
7714 refcount
= IDirect3DDevice9_Release(device
);
7715 ok(!refcount
, "Device has %u references left.\n", refcount
);
7717 IDirect3D9_Release(d3d
);
7718 DestroyWindow(window
);
7721 static void pretransformed_varying_test(void)
7723 /* dcl_position: fails to compile */
7724 static const DWORD blendweight_code
[] =
7726 0xffff0300, /* ps_3_0 */
7727 0x0200001f, 0x80000001, 0x900f0000, /* dcl_blendweight, v0 */
7728 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7729 0x0000ffff /* end */
7731 static const DWORD blendindices_code
[] =
7733 0xffff0300, /* ps_3_0 */
7734 0x0200001f, 0x80000002, 0x900f0000, /* dcl_blendindices, v0 */
7735 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7736 0x0000ffff /* end */
7738 static const DWORD normal_code
[] =
7740 0xffff0300, /* ps_3_0 */
7741 0x0200001f, 0x80000003, 0x900f0000, /* dcl_normal, v0 */
7742 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7743 0x0000ffff /* end */
7746 static const DWORD texcoord0_code
[] =
7748 0xffff0300, /* ps_3_0 */
7749 0x0200001f, 0x80000005, 0x900f0000, /* dcl_texcoord0, v0 */
7750 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7751 0x0000ffff /* end */
7753 static const DWORD tangent_code
[] =
7755 0xffff0300, /* ps_3_0 */
7756 0x0200001f, 0x80000006, 0x900f0000, /* dcl_tangent, v0 */
7757 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7758 0x0000ffff /* end */
7760 static const DWORD binormal_code
[] =
7762 0xffff0300, /* ps_3_0 */
7763 0x0200001f, 0x80000007, 0x900f0000, /* dcl_binormal, v0 */
7764 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7765 0x0000ffff /* end */
7767 /* tessfactor: fails */
7768 /* positiont: fails */
7769 static const DWORD color_code
[] =
7771 0xffff0300, /* ps_3_0 */
7772 0x0200001f, 0x8000000a, 0x900f0000, /* dcl_color0, v0 */
7773 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7774 0x0000ffff /* end */
7776 static const DWORD fog_code
[] =
7778 0xffff0300, /* ps_3_0 */
7779 0x0200001f, 0x8000000b, 0x900f0000, /* dcl_fog, v0 */
7780 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7781 0x0000ffff /* end */
7783 static const DWORD depth_code
[] =
7785 0xffff0300, /* ps_3_0 */
7786 0x0200001f, 0x8000000c, 0x900f0000, /* dcl_depth, v0 */
7787 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7788 0x0000ffff /* end */
7790 static const DWORD specular_code
[] =
7792 0xffff0300, /* ps_3_0 */
7793 0x0200001f, 0x8001000a, 0x900f0000, /* dcl_color1, v0 */
7794 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7795 0x0000ffff /* end */
7798 static const DWORD texcoord1_code
[] =
7800 0xffff0300, /* ps_3_0 */
7801 0x0200001f, 0x80010005, 0x900f0000, /* dcl_texcoord1, v0 */
7802 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
7803 0x0000ffff /* end */
7805 static const DWORD texcoord1_alpha_code
[] =
7807 0xffff0300, /* ps_3_0 */
7808 0x0200001f, 0x80010005, 0x900f0000, /* dcl_texcoord1, v0 */
7809 0x02000001, 0x800f0800, 0x90ff0000, /* mov oC0, v0.w */
7810 0x0000ffff /* end */
7816 const DWORD
*shader_code
;
7824 {"blendweight", blendweight_code
, 0x00191919, TRUE
},
7825 {"blendindices", blendindices_code
, 0x00333333, TRUE
},
7826 {"normal", normal_code
, 0x004c4c4c, TRUE
},
7827 {"texcoord0", texcoord0_code
, 0x00808c8c, FALSE
},
7828 {"tangent", tangent_code
, 0x00999999, TRUE
},
7829 {"binormal", binormal_code
, 0x00b2b2b2, TRUE
},
7830 {"color", color_code
, 0x00e6e6e6, FALSE
},
7831 {"fog", fog_code
, 0x00666666, TRUE
},
7832 {"depth", depth_code
, 0x00cccccc, TRUE
},
7833 {"specular", specular_code
, 0x004488ff, FALSE
},
7834 {"texcoord1", texcoord1_code
, 0x00000000, FALSE
},
7835 /* texcoord .w is 1.0 on r500 and WARP. See also test_uninitialized_varyings(). */
7836 {"texcoord1 alpha", texcoord1_alpha_code
, 0x00000000, FALSE
, TRUE
, 0x00ffffff},
7838 /* Declare a monster vertex type :-) */
7839 static const D3DVERTEXELEMENT9 decl_elements
[] = {
7840 {0, 0, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITIONT
, 0},
7841 {0, 16, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_BLENDWEIGHT
, 0},
7842 {0, 32, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_BLENDINDICES
, 0},
7843 {0, 48, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_NORMAL
, 0},
7844 {0, 64, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_FOG
, 0},
7845 {0, 80, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
7846 {0, 96, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TANGENT
, 0},
7847 {0, 112, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_BINORMAL
, 0},
7848 {0, 128, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_DEPTH
, 0},
7849 {0, 144, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
7850 {0, 148, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 1},
7856 float pos_x
, pos_y
, pos_z
, rhw
;
7857 float weight_1
, weight_2
, weight_3
, weight_4
;
7858 float index_1
, index_2
, index_3
, index_4
;
7859 float normal_1
, normal_2
, normal_3
, normal_4
;
7860 float fog_1
, fog_2
, fog_3
, fog_4
;
7861 float texcoord_1
, texcoord_2
, texcoord_3
, texcoord_4
;
7862 float tangent_1
, tangent_2
, tangent_3
, tangent_4
;
7863 float binormal_1
, binormal_2
, binormal_3
, binormal_4
;
7864 float depth_1
, depth_2
, depth_3
, depth_4
;
7871 0.0f
, 0.0f
, 0.1f
, 1.0f
,
7872 0.1f
, 0.1f
, 0.1f
, 0.1f
,
7873 0.2f
, 0.2f
, 0.2f
, 0.2f
,
7874 0.3f
, 0.3f
, 0.3f
, 0.3f
,
7875 0.4f
, 0.4f
, 0.4f
, 0.4f
,
7876 0.5f
, 0.55f
, 0.55f
, 0.55f
,
7877 0.6f
, 0.6f
, 0.6f
, 0.7f
,
7878 0.7f
, 0.7f
, 0.7f
, 0.6f
,
7879 0.8f
, 0.8f
, 0.8f
, 0.8f
,
7880 0xe6e6e6e6, /* 0.9 * 256 */
7881 0x224488ff, /* Nothing special */
7884 640.0f
, 0.0f
, 0.1f
, 1.0f
,
7885 0.1f
, 0.1f
, 0.1f
, 0.1f
,
7886 0.2f
, 0.2f
, 0.2f
, 0.2f
,
7887 0.3f
, 0.3f
, 0.3f
, 0.3f
,
7888 0.4f
, 0.4f
, 0.4f
, 0.4f
,
7889 0.5f
, 0.55f
, 0.55f
, 0.55f
,
7890 0.6f
, 0.6f
, 0.6f
, 0.7f
,
7891 0.7f
, 0.7f
, 0.7f
, 0.6f
,
7892 0.8f
, 0.8f
, 0.8f
, 0.8f
,
7893 0xe6e6e6e6, /* 0.9 * 256 */
7894 0x224488ff, /* Nothing special */
7897 0.0f
, 480.0f
, 0.1f
, 1.0f
,
7898 0.1f
, 0.1f
, 0.1f
, 0.1f
,
7899 0.2f
, 0.2f
, 0.2f
, 0.2f
,
7900 0.3f
, 0.3f
, 0.3f
, 0.3f
,
7901 0.4f
, 0.4f
, 0.4f
, 0.4f
,
7902 0.5f
, 0.55f
, 0.55f
, 0.55f
,
7903 0.6f
, 0.6f
, 0.6f
, 0.7f
,
7904 0.7f
, 0.7f
, 0.7f
, 0.6f
,
7905 0.8f
, 0.8f
, 0.8f
, 0.8f
,
7906 0xe6e6e6e6, /* 0.9 * 256 */
7907 0x224488ff, /* Nothing special */
7910 640.0f
, 480.0f
, 0.1f
, 1.0f
,
7911 0.1f
, 0.1f
, 0.1f
, 0.1f
,
7912 0.2f
, 0.2f
, 0.2f
, 0.2f
,
7913 0.3f
, 0.3f
, 0.3f
, 0.3f
,
7914 0.4f
, 0.4f
, 0.4f
, 0.4f
,
7915 0.5f
, 0.55f
, 0.55f
, 0.55f
,
7916 0.6f
, 0.6f
, 0.6f
, 0.7f
,
7917 0.7f
, 0.7f
, 0.7f
, 0.6f
,
7918 0.8f
, 0.8f
, 0.8f
, 0.8f
,
7919 0xe6e6e6e6, /* 0.9 * 256 */
7920 0x224488ff, /* Nothing special */
7923 IDirect3DVertexDeclaration9
*decl
;
7924 IDirect3DDevice9
*device
;
7933 window
= create_window();
7934 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
7935 ok(!!d3d
, "Failed to create a D3D object.\n");
7936 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
7938 skip("Failed to create a D3D device, skipping tests.\n");
7942 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
7943 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
7944 if (caps
.PixelShaderVersion
< D3DPS_VERSION(3, 0) || caps
.VertexShaderVersion
< D3DVS_VERSION(3, 0))
7946 skip("No shader model 3 support, skipping tests.\n");
7947 IDirect3DDevice9_Release(device
);
7951 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &decl
);
7952 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr
);
7953 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl
);
7954 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration returned %08x\n", hr
);
7956 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
7958 IDirect3DPixelShader9
*shader
;
7960 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffffff, 1.0f
, 0);
7961 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
7963 hr
= IDirect3DDevice9_CreatePixelShader(device
, tests
[i
].shader_code
, &shader
);
7964 ok(SUCCEEDED(hr
), "Failed to create pixel shader for test %s, hr %#x.\n", tests
[i
].name
, hr
);
7966 hr
= IDirect3DDevice9_SetPixelShader(device
, shader
);
7967 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %08x\n", hr
);
7969 hr
= IDirect3DDevice9_BeginScene(device
);
7970 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7971 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, data
, sizeof(*data
));
7972 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7973 hr
= IDirect3DDevice9_EndScene(device
);
7974 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7976 /* This isn't a weekend's job to fix, ignore the problem for now.
7977 * Needs a replacement pipeline. */
7978 color
= getPixelColor(device
, 360, 240);
7980 todo_wine
ok(color_match(color
, tests
[i
].color
, 1)
7981 || broken(color_match(color
, 0x00000000, 1)
7982 && tests
[i
].shader_code
== blendindices_code
),
7983 "Test %s returned color 0x%08x, expected 0x%08x (todo).\n",
7984 tests
[i
].name
, color
, tests
[i
].color
);
7986 ok(color_match(color
, tests
[i
].color
, 1)
7987 || broken(color_match(color
, tests
[i
].broken_color
, 1) && tests
[i
].broken
),
7988 "Test %s returned color 0x%08x, expected 0x%08x.\n",
7989 tests
[i
].name
, color
, tests
[i
].color
);
7991 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
7992 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
7994 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
7995 ok(SUCCEEDED(hr
), "Failed to set pixel shader for test %s, hr %#x.\n", tests
[i
].name
, hr
);
7996 IDirect3DPixelShader9_Release(shader
);
7999 IDirect3DVertexDeclaration9_Release(decl
);
8000 refcount
= IDirect3DDevice9_Release(device
);
8001 ok(!refcount
, "Device has %u references left.\n", refcount
);
8003 IDirect3D9_Release(d3d
);
8004 DestroyWindow(window
);
8007 static void test_compare_instructions(void)
8009 IDirect3DVertexShader9
*shader_slt_scalar
;
8010 IDirect3DVertexShader9
*shader_sge_scalar
;
8011 IDirect3DVertexShader9
*shader_slt_vec
;
8012 IDirect3DVertexShader9
*shader_sge_vec
;
8013 IDirect3DDevice9
*device
;
8021 static const DWORD shader_sge_vec_code
[] =
8023 0xfffe0101, /* vs_1_1 */
8024 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
8025 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
8026 0x00000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
8027 0x0000000d, 0xd00f0000, 0x80e40000, 0xa0e40001, /* sge oD0, r0, c1 */
8028 0x0000ffff /* end */
8030 static const DWORD shader_slt_vec_code
[] =
8032 0xfffe0101, /* vs_1_1 */
8033 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
8034 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
8035 0x00000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
8036 0x0000000c, 0xd00f0000, 0x80e40000, 0xa0e40001, /* slt oD0, r0, c1 */
8037 0x0000ffff /* end */
8039 static const DWORD shader_sge_scalar_code
[] =
8041 0xfffe0101, /* vs_1_1 */
8042 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
8043 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
8044 0x00000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
8045 0x0000000d, 0xd0010000, 0x80000000, 0xa0550001, /* slt oD0.r, r0.r, c1.b */
8046 0x0000000d, 0xd0020000, 0x80550000, 0xa0aa0001, /* slt oD0.g, r0.g, c1.r */
8047 0x0000000d, 0xd0040000, 0x80aa0000, 0xa0000001, /* slt oD0.b, r0.b, c1.g */
8048 0x0000ffff /* end */
8050 static const DWORD shader_slt_scalar_code
[] =
8052 0xfffe0101, /* vs_1_1 */
8053 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
8054 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
8055 0x00000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
8056 0x0000000c, 0xd0010000, 0x80000000, 0xa0aa0001, /* slt oD0.r, r0.r, c1.b */
8057 0x0000000c, 0xd0020000, 0x80550000, 0xa0000001, /* slt oD0.g, r0.g, c1.r */
8058 0x0000000c, 0xd0040000, 0x80aa0000, 0xa0550001, /* slt oD0.b, r0.b, c1.g */
8059 0x0000ffff /* end */
8061 static const float quad1
[] =
8068 static const float quad2
[] =
8075 static const float quad3
[] =
8082 static const float quad4
[] =
8089 static const float const0
[4] = {0.8f
, 0.2f
, 0.2f
, 0.2f
};
8090 static const float const1
[4] = {0.2f
, 0.8f
, 0.2f
, 0.2f
};
8092 window
= create_window();
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");
8101 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
8102 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
8103 if (caps
.VertexShaderVersion
< D3DVS_VERSION(1, 1))
8105 skip("No vs_1_1 support, skipping tests.\n");
8106 IDirect3DDevice9_Release(device
);
8110 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffffff, 1.0f
, 0);
8111 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Clear returned %#x.\n", hr
);
8113 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_sge_vec_code
, &shader_sge_vec
);
8114 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr
);
8115 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_slt_vec_code
, &shader_slt_vec
);
8116 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr
);
8117 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_sge_scalar_code
, &shader_sge_scalar
);
8118 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr
);
8119 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_slt_scalar_code
, &shader_slt_scalar
);
8120 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr
);
8121 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 0, const0
, 1);
8122 ok(SUCCEEDED(hr
), "SetVertexShaderConstantF failed (%08x)\n", hr
);
8123 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 1, const1
, 1);
8124 ok(SUCCEEDED(hr
), "SetVertexShaderConstantF failed (%08x)\n", hr
);
8125 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
8126 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetFVF failed (%08x)\n", hr
);
8128 hr
= IDirect3DDevice9_BeginScene(device
);
8129 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8131 hr
= IDirect3DDevice9_SetVertexShader(device
, shader_sge_vec
);
8132 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
8133 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(float) * 3);
8134 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8136 hr
= IDirect3DDevice9_SetVertexShader(device
, shader_slt_vec
);
8137 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
8138 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(float) * 3);
8139 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8141 hr
= IDirect3DDevice9_SetVertexShader(device
, shader_sge_scalar
);
8142 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
8143 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, sizeof(float) * 3);
8144 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8146 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 0, const0
, 1);
8147 ok(SUCCEEDED(hr
), "Failed to set vertex shader constant, hr %#x.\n", hr
);
8149 hr
= IDirect3DDevice9_SetVertexShader(device
, shader_slt_scalar
);
8150 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
8151 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, sizeof(float) * 3);
8152 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8154 hr
= IDirect3DDevice9_EndScene(device
);
8155 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8157 color
= getPixelColor(device
, 160, 360);
8158 ok(color
== 0x00ff00ff, "Compare test: Quad 1(sge vec) returned color 0x%08x, expected 0x00ff00ff\n", color
);
8159 color
= getPixelColor(device
, 480, 360);
8160 ok(color
== 0x0000ff00, "Compare test: Quad 2(slt vec) returned color 0x%08x, expected 0x0000ff00\n", color
);
8161 color
= getPixelColor(device
, 160, 120);
8162 ok(color
== 0x00ffffff, "Compare test: Quad 3(sge scalar) returned color 0x%08x, expected 0x00ffffff\n", color
);
8163 color
= getPixelColor(device
, 480, 160);
8164 ok(color
== 0x000000ff, "Compare test: Quad 4(slt scalar) returned color 0x%08x, expected 0x000000ff\n", color
);
8166 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
8167 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
8169 IDirect3DVertexShader9_Release(shader_sge_vec
);
8170 IDirect3DVertexShader9_Release(shader_slt_vec
);
8171 IDirect3DVertexShader9_Release(shader_sge_scalar
);
8172 IDirect3DVertexShader9_Release(shader_slt_scalar
);
8173 refcount
= IDirect3DDevice9_Release(device
);
8174 ok(!refcount
, "Device has %u references left.\n", refcount
);
8176 IDirect3D9_Release(d3d
);
8177 DestroyWindow(window
);
8180 static void test_vshader_input(void)
8182 IDirect3DVertexDeclaration9
*decl_twotexcrd
, *decl_onetexcrd
, *decl_twotex_wrongidx
, *decl_twotexcrd_rightorder
;
8183 IDirect3DVertexDeclaration9
*decl_texcoord_color
, *decl_color_color
, *decl_color_ubyte
, *decl_color_float
;
8184 IDirect3DVertexDeclaration9
*decl_nocolor
;
8185 IDirect3DVertexShader9
*swapped_shader
, *texcoord_color_shader
, *color_color_shader
;
8186 D3DADAPTER_IDENTIFIER9 identifier
;
8187 IDirect3DPixelShader9
*ps
;
8188 IDirect3DDevice9
*device
;
8198 static const DWORD swapped_shader_code_3
[] =
8200 0xfffe0300, /* vs_3_0 */
8201 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
8202 0x0200001f, 0x8000000a, 0xe00f0001, /* dcl_color o1 */
8203 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
8204 0x0200001f, 0x80000005, 0x900f0001, /* dcl_texcoord0 v1 */
8205 0x0200001f, 0x80010005, 0x900f0002, /* dcl_texcoord1 v2 */
8206 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
8207 0x02000001, 0x800f0001, 0x90e40001, /* mov r1, v1 */
8208 0x03000002, 0xe00f0001, 0x80e40001, 0x91e40002, /* sub o1, r1, v2 */
8209 0x0000ffff /* end */
8211 static const DWORD swapped_shader_code_1
[] =
8213 0xfffe0101, /* vs_1_1 */
8214 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
8215 0x0000001f, 0x80000005, 0x900f0001, /* dcl_texcoord0 v1 */
8216 0x0000001f, 0x80010005, 0x900f0002, /* dcl_texcoord1 v2 */
8217 0x00000001, 0xc00f0000, 0x90e40000, /* mov o0, v0 */
8218 0x00000001, 0x800f0001, 0x90e40001, /* mov r1, v1 */
8219 0x00000002, 0xd00f0000, 0x80e40001, 0x91e40002, /* sub o1, r1, v2 */
8220 0x0000ffff /* end */
8222 static const DWORD swapped_shader_code_2
[] =
8224 0xfffe0200, /* vs_2_0 */
8225 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
8226 0x0200001f, 0x80000005, 0x900f0001, /* dcl_texcoord0 v1 */
8227 0x0200001f, 0x80010005, 0x900f0002, /* dcl_texcoord1 v2 */
8228 0x02000001, 0xc00f0000, 0x90e40000, /* mov o0, v0 */
8229 0x02000001, 0x800f0001, 0x90e40001, /* mov r1, v1 */
8230 0x03000002, 0xd00f0000, 0x80e40001, 0x91e40002, /* sub o1, r1, v2 */
8231 0x0000ffff /* end */
8233 static const DWORD texcoord_color_shader_code_3
[] =
8235 0xfffe0300, /* vs_3_0 */
8236 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
8237 0x0200001f, 0x8000000a, 0xe00f0001, /* dcl_color o1 */
8238 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
8239 0x0200001f, 0x80000005, 0x900f0001, /* dcl_texcoord v1 */
8240 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
8241 0x02000001, 0xe00f0001, 0x90e40001, /* mov o1, v1 */
8242 0x0000ffff /* end */
8244 static const DWORD texcoord_color_shader_code_2
[] =
8246 0xfffe0200, /* vs_2_0 */
8247 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
8248 0x0200001f, 0x80000005, 0x900f0001, /* dcl_texcoord v1 */
8249 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
8250 0x02000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
8251 0x0000ffff /* end */
8253 static const DWORD texcoord_color_shader_code_1
[] =
8255 0xfffe0101, /* vs_1_1 */
8256 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
8257 0x0000001f, 0x80000005, 0x900f0001, /* dcl_texcoord v1 */
8258 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
8259 0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
8260 0x0000ffff /* end */
8262 static const DWORD color_color_shader_code_3
[] =
8264 0xfffe0300, /* vs_3_0 */
8265 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
8266 0x0200001f, 0x8000000a, 0xe00f0001, /* dcl_color o1 */
8267 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
8268 0x0200001f, 0x8000000a, 0x900f0001, /* dcl_color v1 */
8269 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
8270 0x03000005, 0xe00f0001, 0xa0e40000, 0x90e40001, /* mul o1, c0, v1 */
8271 0x0000ffff /* end */
8273 static const DWORD color_color_shader_code_2
[] =
8275 0xfffe0200, /* vs_2_0 */
8276 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
8277 0x0200001f, 0x8000000a, 0x900f0001, /* dcl_color v1 */
8278 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
8279 0x03000005, 0xd00f0000, 0xa0e40000, 0x90e40001, /* mul oD0, c0, v1 */
8280 0x0000ffff /* end */
8282 static const DWORD color_color_shader_code_1
[] =
8284 0xfffe0101, /* vs_1_1 */
8285 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
8286 0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color v1 */
8287 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
8288 0x00000005, 0xd00f0000, 0xa0e40000, 0x90e40001, /* mul oD0, c0, v1 */
8289 0x0000ffff /* end */
8291 static const DWORD ps3_code
[] =
8293 0xffff0300, /* ps_3_0 */
8294 0x0200001f, 0x8000000a, 0x900f0000, /* dcl_color0 v0 */
8295 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
8296 0x0000ffff /* end */
8298 static const float quad1
[] =
8300 -1.0f
, -1.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
, 0.0f
, 0.0f
, -1.0f
, 0.5f
, 0.0f
,
8301 -1.0f
, 0.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
, 0.0f
, 0.0f
, -1.0f
, 0.5f
, 0.0f
,
8302 0.0f
, -1.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
, 0.0f
, 0.0f
, -1.0f
, 0.5f
, 0.0f
,
8303 0.0f
, 0.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
, 0.0f
, 0.0f
, -1.0f
, 0.5f
, 0.0f
,
8305 static const float quad2
[] =
8307 0.0f
, -1.0f
, 0.1f
, 1.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
,
8308 0.0f
, 0.0f
, 0.1f
, 1.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
,
8309 1.0f
, -1.0f
, 0.1f
, 1.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
,
8310 1.0f
, 0.0f
, 0.1f
, 1.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
,
8312 static const float quad3
[] =
8314 -1.0f
, 0.0f
, 0.1f
, -1.0f
, 0.0f
, 0.0f
, 0.0f
, 1.0f
, -1.0f
, 0.0f
, 0.0f
,
8315 -1.0f
, 1.0f
, 0.1f
, -1.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -1.0f
, 1.0f
, 0.0f
,
8316 0.0f
, 0.0f
, 0.1f
, -1.0f
, 0.0f
, 0.0f
, 0.0f
, 1.0f
, 0.0f
, 0.0f
, 0.0f
,
8317 0.0f
, 1.0f
, 0.1f
, -1.0f
, 0.0f
, 0.0f
, 0.0f
, -1.0f
, 0.0f
, 0.0f
, 0.0f
,
8319 static const float quad4
[] =
8321 0.0f
, 0.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
, 0.0f
, 0.0f
, -1.0f
, 0.5f
, 0.0f
,
8322 0.0f
, 1.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
, 0.0f
, 0.0f
, -1.0f
, 0.5f
, 0.0f
,
8323 1.0f
, 0.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
, 0.0f
, 0.0f
, -1.0f
, 0.5f
, 0.0f
,
8324 1.0f
, 1.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
, 0.0f
, 0.0f
, -1.0f
, 0.5f
, 0.0f
,
8326 static const float quad1_modified
[] =
8328 -1.0f
, -1.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
, 0.0f
, -1.0f
, 0.0f
, 0.0f
, 0.0f
,
8329 -1.0f
, 0.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
, 0.0f
, 0.0f
, 0.0f
, -1.0f
, 0.0f
,
8330 0.0f
, -1.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
, 0.0f
, 0.0f
, -1.0f
, 0.0f
, 0.0f
,
8331 0.0f
, 0.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
, 0.0f
, -1.0f
, -1.0f
, -1.0f
, 0.0f
,
8333 static const float quad2_modified
[] =
8335 0.0f
, -1.0f
, 0.1f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
,
8336 0.0f
, 0.0f
, 0.1f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
,
8337 1.0f
, -1.0f
, 0.1f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
,
8338 1.0f
, 0.0f
, 0.1f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
,
8342 struct vec3 position
;
8347 {{-1.0f
, -1.0f
, 0.1f
}, 0x00ff8040},
8348 {{-1.0f
, 0.0f
, 0.1f
}, 0x00ff8040},
8349 {{ 0.0f
, -1.0f
, 0.1f
}, 0x00ff8040},
8350 {{ 0.0f
, 0.0f
, 0.1f
}, 0x00ff8040},
8354 {{ 0.0f
, -1.0f
, 0.1f
}, 0x00ff8040},
8355 {{ 0.0f
, 0.0f
, 0.1f
}, 0x00ff8040},
8356 {{ 1.0f
, -1.0f
, 0.1f
}, 0x00ff8040},
8357 {{ 1.0f
, 0.0f
, 0.1f
}, 0x00ff8040},
8361 {{-1.0f
, 0.0f
, 0.1f
}, 0x00ff8040},
8362 {{-1.0f
, 1.0f
, 0.1f
}, 0x00ff8040},
8363 {{ 0.0f
, 0.0f
, 0.1f
}, 0x00ff8040},
8364 {{ 0.0f
, 1.0f
, 0.1f
}, 0x00ff8040},
8366 static const float quad4_color
[] =
8368 0.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 0.0f
, 0.0f
,
8369 0.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
, 0.0f
, 0.0f
,
8370 1.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 0.0f
, 1.0f
,
8371 1.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
, 0.0f
, 1.0f
,
8373 static const struct vec3 quad_nocolor
[] =
8375 {-1.0f
, -1.0f
, 0.1f
},
8376 {-1.0f
, 1.0f
, 0.1f
},
8377 { 1.0f
, -1.0f
, 0.1f
},
8378 { 1.0f
, 1.0f
, 0.1f
},
8380 static const D3DVERTEXELEMENT9 decl_elements_twotexcrd
[] =
8382 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
8383 {0, 12, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
8384 {0, 28, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 1},
8387 static const D3DVERTEXELEMENT9 decl_elements_twotexcrd_rightorder
[] =
8389 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
8390 {0, 12, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 1},
8391 {0, 28, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
8394 static const D3DVERTEXELEMENT9 decl_elements_onetexcrd
[] =
8396 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
8397 {0, 12, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
8400 static const D3DVERTEXELEMENT9 decl_elements_twotexcrd_wrongidx
[] =
8402 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
8403 {0, 12, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 1},
8404 {0, 28, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 2},
8407 static const D3DVERTEXELEMENT9 decl_elements_texcoord_color
[] =
8409 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
8410 {0, 12, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
8413 static const D3DVERTEXELEMENT9 decl_elements_color_color
[] =
8415 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
8416 {0, 12, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
8419 static const D3DVERTEXELEMENT9 decl_elements_color_ubyte
[] =
8421 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
8422 {0, 12, D3DDECLTYPE_UBYTE4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
8425 static const D3DVERTEXELEMENT9 decl_elements_color_float
[] =
8427 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
8428 {0, 12, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
8431 static const D3DVERTEXELEMENT9 decl_elements_nocolor
[] =
8433 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
8436 static const float normalize
[4] = {1.0f
/ 256.0f
, 1.0f
/ 256.0f
, 1.0f
/ 256.0f
, 1.0f
/ 256.0f
};
8437 static const float no_normalize
[4] = {1.0f
, 1.0f
, 1.0f
, 1.0f
};
8439 window
= create_window();
8440 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
8441 ok(!!d3d
, "Failed to create a D3D object.\n");
8442 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
8444 skip("Failed to create a D3D device, skipping tests.\n");
8448 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
8449 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
8450 if (caps
.VertexShaderVersion
< D3DVS_VERSION(3, 0))
8452 skip("No vs_3_0 support, skipping tests.\n");
8453 IDirect3DDevice9_Release(device
);
8456 if (caps
.PixelShaderVersion
< D3DPS_VERSION(3, 0))
8458 skip("No ps_3_0 support, skipping tests.\n");
8459 IDirect3DDevice9_Release(device
);
8463 hr
= IDirect3D9_GetAdapterIdentifier(d3d
, D3DADAPTER_DEFAULT
, 0, &identifier
);
8464 ok(SUCCEEDED(hr
), "Failed to get adapter identifier, hr %#x.\n", hr
);
8465 warp
= adapter_is_warp(&identifier
);
8467 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_twotexcrd
, &decl_twotexcrd
);
8468 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr
);
8469 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_onetexcrd
, &decl_onetexcrd
);
8470 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr
);
8471 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_twotexcrd_wrongidx
, &decl_twotex_wrongidx
);
8472 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr
);
8473 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_twotexcrd_rightorder
, &decl_twotexcrd_rightorder
);
8474 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr
);
8476 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_texcoord_color
, &decl_texcoord_color
);
8477 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr
);
8478 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_color_color
, &decl_color_color
);
8479 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr
);
8480 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_color_ubyte
, &decl_color_ubyte
);
8481 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr
);
8482 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_color_float
, &decl_color_float
);
8483 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr
);
8484 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_nocolor
, &decl_nocolor
);
8485 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %08x\n", hr
);
8487 hr
= IDirect3DDevice9_CreatePixelShader(device
, ps3_code
, &ps
);
8488 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %08x\n", hr
);
8490 for (i
= 1; i
<= 3; ++i
)
8492 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffff0000, 1.0f
, 0);
8493 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Clear returned %#x.\n", hr
);
8495 hr
= IDirect3DDevice9_CreateVertexShader(device
, swapped_shader_code_3
, &swapped_shader
);
8496 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr
);
8497 hr
= IDirect3DDevice9_SetPixelShader(device
, ps
);
8498 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %08x\n", hr
);
8500 hr
= IDirect3DDevice9_CreateVertexShader(device
, swapped_shader_code_2
, &swapped_shader
);
8501 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr
);
8503 hr
= IDirect3DDevice9_CreateVertexShader(device
, swapped_shader_code_1
, &swapped_shader
);
8504 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr
);
8507 hr
= IDirect3DDevice9_BeginScene(device
);
8508 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8510 hr
= IDirect3DDevice9_SetVertexShader(device
, swapped_shader
);
8511 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
8513 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl_twotexcrd
);
8514 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
8515 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(float) * 11);
8516 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8518 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl_onetexcrd
);
8519 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
8520 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(float) * 11);
8521 if (i
== 3 || i
== 2)
8522 ok(SUCCEEDED(hr
), "Failed to draw, i %u, hr %#x.\n", i
, hr
);
8524 /* Succeeds or fails, depending on SW or HW vertex processing. */
8525 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
8527 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl_twotexcrd_rightorder
);
8528 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
8529 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, sizeof(float) * 11);
8530 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8532 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl_twotex_wrongidx
);
8533 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
8534 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, sizeof(float) * 11);
8535 if (i
== 3 || i
== 2)
8536 ok(SUCCEEDED(hr
), "Failed to draw, i %u, hr %#x.\n", i
, hr
);
8538 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
8540 hr
= IDirect3DDevice9_EndScene(device
);
8541 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8543 if(i
== 3 || i
== 2) {
8544 color
= getPixelColor(device
, 160, 360);
8545 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x80), 1),
8546 "Input test: Quad 1(2crd) returned color 0x%08x, expected 0x00ffff80\n", color
);
8548 /* The last value of the read but undefined stream is used, it is 0x00. The defined input is vec4(1, 0, 0, 0) */
8549 color
= getPixelColor(device
, 480, 360);
8550 /* On the Windows 8 testbot (WARP) the draw succeeds, but uses
8551 * mostly random data as input. */
8552 ok(color
== 0x00ffff00 || color
== 0x00ff0000 || broken(warp
),
8553 "Got unexpected color 0x%08x for quad 2 (1crd).\n", color
);
8554 color
= getPixelColor(device
, 160, 120);
8555 /* Same as above, accept both the last used value and 0.0 for the undefined streams */
8556 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x80), 1) || color
== D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x00),
8557 "Input test: Quad 3(2crd-wrongidx) returned color 0x%08x, expected 0x00ff0080\n", color
);
8559 color
= getPixelColor(device
, 480, 160);
8560 ok(color
== 0x00000000, "Input test: Quad 4(2crd-rightorder) returned color 0x%08x, expected 0x00000000\n", color
);
8562 color
= getPixelColor(device
, 160, 360);
8563 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x80), 1),
8564 "Input test: Quad 1(2crd) returned color 0x%08x, expected 0x00ffff80\n", color
);
8565 color
= getPixelColor(device
, 480, 360);
8566 /* Accept the clear color as well in this case, since SW VP
8567 * returns an error. On the Windows 8 testbot (WARP) the draw
8568 * succeeds, but uses mostly random data as input. */
8569 ok(color
== 0x00ffff00 || color
== 0x00ff0000 || broken(warp
),
8570 "Got unexpected color 0x%08x for quad 2 (1crd).\n", color
);
8571 color
= getPixelColor(device
, 160, 120);
8572 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x80), 1) || color
== D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x00),
8573 "Input test: Quad 3(2crd-wrongidx) returned color 0x%08x, expected 0x00ff0080\n", color
);
8574 color
= getPixelColor(device
, 480, 160);
8575 ok(color
== 0x00000000, "Input test: Quad 4(2crd-rightorder) returned color 0x%08x, expected 0x00000000\n", color
);
8578 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
8579 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
8581 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff808080, 0.0, 0);
8582 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
8584 /* Now find out if the whole streams are re-read, or just the last
8585 * active value for the vertices is used. */
8586 hr
= IDirect3DDevice9_BeginScene(device
);
8587 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8589 hr
= IDirect3DDevice9_SetVertexShader(device
, swapped_shader
);
8590 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
8592 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl_twotexcrd
);
8593 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
8594 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_POINTLIST
, 3, quad1_modified
, sizeof(float) * 11);
8595 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8597 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl_onetexcrd
);
8598 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
8599 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2_modified
, sizeof(float) * 11);
8600 if (i
== 3 || i
== 2)
8601 ok(SUCCEEDED(hr
), "Failed to draw, i %u, hr %#x.\n", i
, hr
);
8603 /* Succeeds or fails, depending on SW or HW vertex processing. */
8604 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
8606 hr
= IDirect3DDevice9_EndScene(device
);
8607 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8609 color
= getPixelColor(device
, 480, 350);
8610 /* vs_1_1 may fail, accept the clear color. Some drivers also set the undefined streams to 0, accept that
8613 * NOTE: This test fails on the reference rasterizer. In the refrast, the 4 vertices have different colors,
8614 * i.e., the whole old stream is read, and not just the last used attribute. Some games require that this
8615 * does *not* happen, otherwise they can crash because of a read from a bad pointer, so do not accept the
8618 * A test app for this behavior is Half Life 2 Episode 2 in dxlevel 95, and related games(Portal, TF2).
8620 ok(color
== 0x000000ff || color
== 0x00808080 || color
== 0x00000000
8621 || broken(color_match(color
, D3DCOLOR_ARGB(0x00, 0x0b, 0x75, 0x80), 1)),
8622 "Got unexpected color 0x%08x for quad 2 (different colors).\n", color
);
8624 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
8625 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
8627 IDirect3DDevice9_SetVertexShader(device
, NULL
);
8628 IDirect3DDevice9_SetPixelShader(device
, NULL
);
8629 IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
8631 IDirect3DVertexShader9_Release(swapped_shader
);
8634 for (i
= 1; i
<= 3; ++i
)
8636 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff0000ff, 1.0f
, 0);
8637 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Clear returned %#x.\n", hr
);
8639 hr
= IDirect3DDevice9_CreateVertexShader(device
, texcoord_color_shader_code_3
, &texcoord_color_shader
);
8640 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr
);
8641 hr
= IDirect3DDevice9_CreateVertexShader(device
, color_color_shader_code_3
, &color_color_shader
);
8642 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr
);
8643 hr
= IDirect3DDevice9_SetPixelShader(device
, ps
);
8644 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %08x\n", hr
);
8646 hr
= IDirect3DDevice9_CreateVertexShader(device
, texcoord_color_shader_code_2
, &texcoord_color_shader
);
8647 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr
);
8648 hr
= IDirect3DDevice9_CreateVertexShader(device
, color_color_shader_code_2
, &color_color_shader
);
8649 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr
);
8651 hr
= IDirect3DDevice9_CreateVertexShader(device
, texcoord_color_shader_code_1
, &texcoord_color_shader
);
8652 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr
);
8653 hr
= IDirect3DDevice9_CreateVertexShader(device
, color_color_shader_code_1
, &color_color_shader
);
8654 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr
);
8657 hr
= IDirect3DDevice9_BeginScene(device
);
8658 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8660 hr
= IDirect3DDevice9_SetVertexShader(device
, texcoord_color_shader
);
8661 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
8662 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl_texcoord_color
);
8663 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
8664 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1_color
, sizeof(quad1_color
[0]));
8665 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8667 hr
= IDirect3DDevice9_SetVertexShader(device
, color_color_shader
);
8668 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
8670 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 0, normalize
, 1);
8671 ok(SUCCEEDED(hr
), "Failed to set vertex shader constant, hr %#x.\n", hr
);
8672 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl_color_ubyte
);
8673 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
8674 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2_color
, sizeof(quad2_color
[0]));
8675 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8677 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 0, no_normalize
, 1);
8678 ok(SUCCEEDED(hr
), "Failed to set vertex shader constant, hr %#x.\n", hr
);
8679 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl_color_color
);
8680 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
8681 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3_color
, sizeof(quad3_color
[0]));
8682 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8684 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl_color_float
);
8685 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
8686 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4_color
, sizeof(float) * 7);
8687 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8689 hr
= IDirect3DDevice9_EndScene(device
);
8690 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8692 color
= getPixelColor(device
, 160, 360);
8693 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0xff, 0x80, 0x40), 1),
8694 "Input test: Quad 1(color-texcoord) returned color 0x%08x, expected 0x00ff8040\n", color
);
8695 color
= getPixelColor(device
, 480, 360);
8696 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x40, 0x80, 0xff), 1),
8697 "Input test: Quad 2(color-ubyte) returned color 0x%08x, expected 0x004080ff\n", color
);
8698 color
= getPixelColor(device
, 160, 120);
8699 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0xff, 0x80, 0x40), 1),
8700 "Input test: Quad 3(color-color) returned color 0x%08x, expected 0x00ff8040\n", color
);
8701 color
= getPixelColor(device
, 480, 160);
8702 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x00), 1),
8703 "Input test: Quad 4(color-float) returned color 0x%08x, expected 0x00ffff00\n", color
);
8705 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
8706 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
8708 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl_nocolor
);
8709 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
8711 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff0000ff, 1.0f
, 0);
8712 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
8714 hr
= IDirect3DDevice9_BeginScene(device
);
8715 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8716 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad_nocolor
, sizeof(quad_nocolor
[0]));
8717 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8718 hr
= IDirect3DDevice9_EndScene(device
);
8719 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8721 /* WARP and r500 return a color from a previous draw. In case of WARP it is random, although most of the
8722 * time it is the color of the last draw, which happens to be the one with quad4_color above. AMD's r500
8723 * uses the last D3DCOLOR attribute, which is the one from quad3_color.
8725 * Newer AMD cards and Nvidia return zero. */
8726 color
= getPixelColor(device
, 160, 360);
8727 ok(color_match(color
, 0x00000000, 1) || broken(color_match(color
, 0x00ff8040, 1)) || broken(warp
),
8728 "Got unexpected color 0x%08x for no color attribute test.\n", color
);
8730 IDirect3DDevice9_SetVertexShader(device
, NULL
);
8731 IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
8732 IDirect3DDevice9_SetPixelShader(device
, NULL
);
8734 IDirect3DVertexShader9_Release(texcoord_color_shader
);
8735 IDirect3DVertexShader9_Release(color_color_shader
);
8738 IDirect3DVertexDeclaration9_Release(decl_twotexcrd
);
8739 IDirect3DVertexDeclaration9_Release(decl_onetexcrd
);
8740 IDirect3DVertexDeclaration9_Release(decl_twotex_wrongidx
);
8741 IDirect3DVertexDeclaration9_Release(decl_twotexcrd_rightorder
);
8743 IDirect3DVertexDeclaration9_Release(decl_texcoord_color
);
8744 IDirect3DVertexDeclaration9_Release(decl_color_color
);
8745 IDirect3DVertexDeclaration9_Release(decl_color_ubyte
);
8746 IDirect3DVertexDeclaration9_Release(decl_color_float
);
8747 IDirect3DVertexDeclaration9_Release(decl_nocolor
);
8749 IDirect3DPixelShader9_Release(ps
);
8750 refcount
= IDirect3DDevice9_Release(device
);
8751 ok(!refcount
, "Device has %u references left.\n", refcount
);
8753 IDirect3D9_Release(d3d
);
8754 DestroyWindow(window
);
8757 static void srgbtexture_test(void)
8759 /* Fill a texture with 0x7f (~ .5), and then turn on the D3DSAMP_SRGBTEXTURE
8760 * texture stage state to render a quad using that texture. The resulting
8761 * color components should be 0x36 (~ 0.21), per this formula:
8762 * linear_color = ((srgb_color + 0.055) / 1.055) ^ 2.4
8763 * This is true where srgb_color > 0.04045. */
8764 struct IDirect3DTexture9
*texture
;
8765 struct IDirect3DSurface9
*surface
;
8766 IDirect3DDevice9
*device
;
8773 static const float quad
[] =
8775 -1.0f
, -1.0f
, 0.0f
, 0.0f
, 1.0f
,
8776 -1.0f
, 1.0f
, 0.0f
, 0.0f
, 0.0f
,
8777 1.0f
, -1.0f
, 0.0f
, 1.0f
, 1.0f
,
8778 1.0f
, 1.0f
, 0.0f
, 1.0f
, 0.0f
,
8781 window
= create_window();
8782 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
8783 ok(!!d3d
, "Failed to create a D3D object.\n");
8784 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
8786 skip("Failed to create a D3D device, skipping tests.\n");
8790 if (IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
,
8791 D3DFMT_X8R8G8B8
, D3DUSAGE_QUERY_SRGBREAD
, D3DRTYPE_TEXTURE
, D3DFMT_A8R8G8B8
) != D3D_OK
)
8793 skip("D3DFMT_A8R8G8B8 textures with SRGBREAD not supported.\n");
8794 IDirect3DDevice9_Release(device
);
8798 hr
= IDirect3DDevice9_CreateTexture(device
, 16, 16, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &texture
, NULL
);
8799 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
8800 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
8801 ok(hr
== D3D_OK
, "IDirect3DTexture9_GetSurfaceLevel failed with %08x\n", hr
);
8803 fill_surface(surface
, 0xff7f7f7f, 0);
8804 IDirect3DSurface9_Release(surface
);
8806 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
8807 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
8808 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) texture
);
8809 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture failed with %08x\n", hr
);
8811 hr
= IDirect3DDevice9_BeginScene(device
);
8812 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8814 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_SRGBTEXTURE
, TRUE
);
8815 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
8816 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
8817 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
8818 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
8819 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8821 hr
= IDirect3DDevice9_EndScene(device
);
8822 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8824 color
= getPixelColor(device
, 320, 240);
8825 ok(color_match(color
, 0x00363636, 1), "sRGB quad has color 0x%08x, expected 0x00363636.\n", color
);
8827 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
8828 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
8830 IDirect3DTexture9_Release(texture
);
8831 refcount
= IDirect3DDevice9_Release(device
);
8832 ok(!refcount
, "Device has %u references left.\n", refcount
);
8834 IDirect3D9_Release(d3d
);
8835 DestroyWindow(window
);
8838 static void test_shademode(void)
8840 IDirect3DVertexBuffer9
*vb_strip
;
8841 IDirect3DVertexBuffer9
*vb_list
;
8842 IDirect3DVertexShader9
*vs
;
8843 IDirect3DPixelShader9
*ps
;
8844 IDirect3DDevice9
*device
;
8845 DWORD color0
, color1
;
8853 static const DWORD vs1_code
[] =
8855 0xfffe0101, /* vs_1_1 */
8856 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
8857 0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
8858 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
8859 0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
8862 static const DWORD vs2_code
[] =
8864 0xfffe0200, /* vs_2_0 */
8865 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
8866 0x0200001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
8867 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
8868 0x02000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
8871 static const DWORD vs3_code
[] =
8873 0xfffe0300, /* vs_3_0 */
8874 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
8875 0x0200001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
8876 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
8877 0x0200001f, 0x8000000a, 0xe00f0001, /* dcl_color0 o1 */
8878 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
8879 0x02000001, 0xe00f0001, 0x90e40001, /* mov o1, v1 */
8882 static const DWORD ps1_code
[] =
8884 0xffff0101, /* ps_1_1 */
8885 0x00000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
8888 static const DWORD ps2_code
[] =
8890 0xffff0200, /* ps_2_0 */
8891 0x0200001f, 0x80000000, 0x900f0000, /* dcl v0 */
8892 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
8895 static const DWORD ps3_code
[] =
8897 0xffff0300, /* ps_3_0 */
8898 0x0200001f, 0x8000000a, 0x900f0000, /* dcl_color0 v0 */
8899 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
8904 struct vec3 position
;
8909 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
8910 {{-1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
8911 {{ 1.0f
, -1.0f
, 0.0f
}, 0xff0000ff},
8912 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffffffff},
8916 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
8917 {{-1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
8918 {{ 1.0f
, -1.0f
, 0.0f
}, 0xff0000ff},
8920 {{ 1.0f
, -1.0f
, 0.0f
}, 0xff0000ff},
8921 {{-1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
8922 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffffffff},
8924 static const struct test_shader
8930 vs_1
= {D3DVS_VERSION(1, 1), vs1_code
},
8931 vs_2
= {D3DVS_VERSION(2, 0), vs2_code
},
8932 vs_3
= {D3DVS_VERSION(3, 0), vs3_code
},
8934 ps_1
= {D3DPS_VERSION(1, 1), ps1_code
},
8935 ps_2
= {D3DPS_VERSION(2, 0), ps2_code
},
8936 ps_3
= {D3DPS_VERSION(3, 0), ps3_code
};
8939 const struct test_shader
*vs
, *ps
;
8942 DWORD color0
, color1
;
8947 {&novs
, &nops
, D3DPT_TRIANGLESTRIP
, D3DSHADE_FLAT
, 0x00ff0000, 0x0000ff00, FALSE
},
8948 {&novs
, &nops
, D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7, FALSE
},
8949 {&novs
, &nops
, D3DPT_TRIANGLESTRIP
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7, FALSE
},
8950 {&novs
, &nops
, D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7, FALSE
},
8951 {&novs
, &nops
, D3DPT_TRIANGLELIST
, D3DSHADE_FLAT
, 0x00ff0000, 0x000000ff, FALSE
},
8952 {&novs
, &nops
, D3DPT_TRIANGLELIST
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7, FALSE
},
8953 {&vs_1
, &ps_1
, D3DPT_TRIANGLESTRIP
, D3DSHADE_FLAT
, 0x00ff0000, 0x0000ff00, FALSE
},
8954 {&vs_1
, &ps_1
, D3DPT_TRIANGLESTRIP
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7, FALSE
},
8955 {&vs_1
, &ps_1
, D3DPT_TRIANGLELIST
, D3DSHADE_FLAT
, 0x00ff0000, 0x000000ff, FALSE
},
8956 {&vs_1
, &ps_1
, D3DPT_TRIANGLELIST
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7, FALSE
},
8957 {&novs
, &ps_1
, D3DPT_TRIANGLESTRIP
, D3DSHADE_FLAT
, 0x00ff0000, 0x0000ff00, FALSE
},
8958 {&vs_1
, &nops
, D3DPT_TRIANGLESTRIP
, D3DSHADE_FLAT
, 0x00ff0000, 0x0000ff00, FALSE
},
8959 {&vs_2
, &ps_2
, D3DPT_TRIANGLESTRIP
, D3DSHADE_FLAT
, 0x00ff0000, 0x0000ff00, FALSE
},
8960 {&vs_2
, &ps_2
, D3DPT_TRIANGLESTRIP
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7, FALSE
},
8961 {&vs_3
, &ps_3
, D3DPT_TRIANGLESTRIP
, D3DSHADE_FLAT
, 0x00ff0000, 0x0000ff00, TRUE
},
8962 {&vs_3
, &ps_3
, D3DPT_TRIANGLESTRIP
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7, FALSE
},
8965 window
= create_window();
8966 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
8967 ok(!!d3d
, "Failed to create a D3D object.\n");
8968 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
8970 skip("Failed to create a D3D device, skipping tests.\n");
8974 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
8975 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
8976 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGENABLE
, FALSE
);
8977 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
8979 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
8980 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with %08x\n", hr
);
8982 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, sizeof(quad_strip
), 0, 0, D3DPOOL_MANAGED
, &vb_strip
, NULL
);
8983 ok(hr
== D3D_OK
, "CreateVertexBuffer failed with %08x\n", hr
);
8984 hr
= IDirect3DVertexBuffer9_Lock(vb_strip
, 0, sizeof(quad_strip
), &data
, 0);
8985 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr
);
8986 memcpy(data
, quad_strip
, sizeof(quad_strip
));
8987 hr
= IDirect3DVertexBuffer9_Unlock(vb_strip
);
8988 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Unlock failed with %08x\n", hr
);
8990 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, sizeof(quad_list
), 0, 0, D3DPOOL_MANAGED
, &vb_list
, NULL
);
8991 ok(hr
== D3D_OK
, "CreateVertexBuffer failed with %08x\n", hr
);
8992 hr
= IDirect3DVertexBuffer9_Lock(vb_list
, 0, sizeof(quad_list
), &data
, 0);
8993 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr
);
8994 memcpy(data
, quad_list
, sizeof(quad_list
));
8995 hr
= IDirect3DVertexBuffer9_Unlock(vb_list
);
8996 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Unlock failed with %08x\n", hr
);
8998 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
8999 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
9001 /* Try it first with a TRIANGLESTRIP. Do it with different geometry because
9002 * the color fixups we have to do for FLAT shading will be dependent on that. */
9004 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
9006 if (tests
[i
].vs
->version
)
9008 if (caps
.VertexShaderVersion
>= tests
[i
].vs
->version
)
9010 hr
= IDirect3DDevice9_CreateVertexShader(device
, tests
[i
].vs
->code
, &vs
);
9011 ok(hr
== D3D_OK
, "Failed to create vertex shader, hr %#x.\n", hr
);
9012 hr
= IDirect3DDevice9_SetVertexShader(device
, vs
);
9013 ok(hr
== D3D_OK
, "Failed to set vertex shader, hr %#x.\n", hr
);
9017 skip("Shader version unsupported, skipping some tests.\n");
9025 if (tests
[i
].ps
->version
)
9027 if (caps
.PixelShaderVersion
>= tests
[i
].ps
->version
)
9029 hr
= IDirect3DDevice9_CreatePixelShader(device
, tests
[i
].ps
->code
, &ps
);
9030 ok(hr
== D3D_OK
, "Failed to create pixel shader, hr %#x.\n", hr
);
9031 hr
= IDirect3DDevice9_SetPixelShader(device
, ps
);
9032 ok(hr
== D3D_OK
, "Failed to set pixel shader, hr %#x.\n", hr
);
9036 skip("Shader version unsupported, skipping some tests.\n");
9039 IDirect3DDevice9_SetVertexShader(device
, NULL
);
9040 IDirect3DVertexShader9_Release(vs
);
9050 hr
= IDirect3DDevice9_SetStreamSource(device
, 0,
9051 tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? vb_strip
: vb_list
, 0, sizeof(quad_strip
[0]));
9052 ok(hr
== D3D_OK
, "Failed to set stream source, hr %#x.\n", hr
);
9054 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
9055 ok(hr
== D3D_OK
, "Failed to clear, hr %#x.\n", hr
);
9057 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SHADEMODE
, tests
[i
].shademode
);
9058 ok(hr
== D3D_OK
, "Failed to set shade mode, hr %#x.\n", hr
);
9060 hr
= IDirect3DDevice9_BeginScene(device
);
9061 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9062 hr
= IDirect3DDevice9_DrawPrimitive(device
, tests
[i
].primtype
, 0, 2);
9063 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9064 hr
= IDirect3DDevice9_EndScene(device
);
9065 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9067 color0
= getPixelColor(device
, 100, 100); /* Inside first triangle */
9068 color1
= getPixelColor(device
, 500, 350); /* Inside second triangle */
9070 /* For D3DSHADE_FLAT it should take the color of the first vertex of
9071 * each triangle. This requires EXT_provoking_vertex or similar
9072 * functionality being available. */
9073 /* PHONG should be the same as GOURAUD, since no hardware implements
9075 todo_wine_if (tests
[i
].todo
)
9077 ok(color_match(color0
, tests
[i
].color0
, 1), "Test %u shading has color0 %08x, expected %08x.\n",
9078 i
, color0
, tests
[i
].color0
);
9079 ok(color_match(color1
, tests
[i
].color1
, 1), "Test %u shading has color1 %08x, expected %08x.\n",
9080 i
, color1
, tests
[i
].color1
);
9082 IDirect3DDevice9_SetVertexShader(device
, NULL
);
9083 IDirect3DDevice9_SetPixelShader(device
, NULL
);
9086 IDirect3DPixelShader9_Release(ps
);
9088 IDirect3DVertexShader9_Release(vs
);
9091 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
9092 ok(hr
== D3D_OK
, "Failed to present, hr %#x.\n", hr
);
9094 IDirect3DVertexBuffer9_Release(vb_strip
);
9095 IDirect3DVertexBuffer9_Release(vb_list
);
9096 refcount
= IDirect3DDevice9_Release(device
);
9097 ok(!refcount
, "Device has %u references left.\n", refcount
);
9099 IDirect3D9_Release(d3d
);
9100 DestroyWindow(window
);
9103 static void test_blend(void)
9105 IDirect3DSurface9
*backbuffer
, *offscreen
;
9106 IDirect3DTexture9
*offscreenTexture
;
9107 IDirect3DDevice9
*device
;
9116 struct vec3 position
;
9121 {{-1.0f
, -1.0f
, 0.1f
}, 0x4000ff00},
9122 {{-1.0f
, 0.0f
, 0.1f
}, 0x4000ff00},
9123 {{ 1.0f
, -1.0f
, 0.1f
}, 0x4000ff00},
9124 {{ 1.0f
, 0.0f
, 0.1f
}, 0x4000ff00},
9128 {{-1.0f
, 0.0f
, 0.1f
}, 0xc00000ff},
9129 {{-1.0f
, 1.0f
, 0.1f
}, 0xc00000ff},
9130 {{ 1.0f
, 0.0f
, 0.1f
}, 0xc00000ff},
9131 {{ 1.0f
, 1.0f
, 0.1f
}, 0xc00000ff},
9133 static const float composite_quad
[][5] =
9135 { 0.0f
, -1.0f
, 0.1f
, 0.0f
, 1.0f
},
9136 { 0.0f
, 1.0f
, 0.1f
, 0.0f
, 0.0f
},
9137 { 1.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
},
9138 { 1.0f
, 1.0f
, 0.1f
, 1.0f
, 0.0f
},
9141 window
= create_window();
9142 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
9143 ok(!!d3d
, "Failed to create a D3D object.\n");
9144 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
9146 skip("Failed to create a D3D device, skipping tests.\n");
9150 /* Clear the render target with alpha = 0.5 */
9151 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x80ff0000, 1.0f
, 0);
9152 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
9154 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
,
9155 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &offscreenTexture
, NULL
);
9156 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
9158 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
9159 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %08x\n", hr
);
9161 hr
= IDirect3DTexture9_GetSurfaceLevel(offscreenTexture
, 0, &offscreen
);
9162 ok(hr
== D3D_OK
, "Can't get offscreen surface, hr = %08x\n", hr
);
9164 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
9165 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed, hr = %#08x\n", hr
);
9167 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
9168 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
9169 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
9170 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
9171 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MINFILTER
, D3DTEXF_POINT
);
9172 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_MINFILTER failed (0x%08x)\n", hr
);
9173 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAGFILTER
, D3DTEXF_POINT
);
9174 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr
);
9175 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
9176 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
9178 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, TRUE
);
9179 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed, hr = %08x\n", hr
);
9180 hr
= IDirect3DDevice9_BeginScene(device
);
9181 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9183 /* Draw two quads, one with src alpha blending, one with dest alpha
9185 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_SRCALPHA
);
9186 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9187 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
9188 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9189 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(quad1
[0]));
9190 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9192 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_DESTALPHA
);
9193 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9194 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVDESTALPHA
);
9195 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9196 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(quad2
[0]));
9197 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9199 /* Switch to the offscreen buffer, and redo the testing. The offscreen
9200 * render target doesn't have an alpha channel. DESTALPHA and INVDESTALPHA
9201 * "don't work" on render targets without alpha channel, they give
9202 * essentially ZERO and ONE blend factors. */
9203 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, offscreen
);
9204 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
9205 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x80ff0000, 1.0f
, 0);
9206 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9208 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_SRCALPHA
);
9209 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9210 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
9211 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9212 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(quad1
[0]));
9213 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9215 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_DESTALPHA
);
9216 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9217 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVDESTALPHA
);
9218 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9219 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(quad2
[0]));
9220 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9222 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
9223 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
9225 /* Render the offscreen texture onto the frame buffer to be able to
9226 * compare it regularly. Disable alpha blending for the final
9228 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, FALSE
);
9229 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9230 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
9231 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
9233 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) offscreenTexture
);
9234 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
9235 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, composite_quad
, sizeof(float) * 5);
9236 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9238 hr
= IDirect3DDevice9_EndScene(device
);
9239 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9241 color
= getPixelColor(device
, 160, 360);
9242 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0xbf, 0x40, 0x00), 1),
9243 "SRCALPHA on frame buffer returned color %08x, expected 0x00bf4000\n", color
);
9245 color
= getPixelColor(device
, 160, 120);
9246 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x7f, 0x00, 0x80), 2),
9247 "DSTALPHA on frame buffer returned color %08x, expected 0x007f0080\n", color
);
9249 color
= getPixelColor(device
, 480, 360);
9250 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0xbf, 0x40, 0x00), 1),
9251 "SRCALPHA on texture returned color %08x, expected 0x00bf4000\n", color
);
9253 color
= getPixelColor(device
, 480, 120);
9254 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0xff), 1),
9255 "DSTALPHA on texture returned color %08x, expected 0x000000ff\n", color
);
9257 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
9259 IDirect3DSurface9_Release(backbuffer
);
9260 IDirect3DTexture9_Release(offscreenTexture
);
9261 IDirect3DSurface9_Release(offscreen
);
9262 refcount
= IDirect3DDevice9_Release(device
);
9263 ok(!refcount
, "Device has %u references left.\n", refcount
);
9265 IDirect3D9_Release(d3d
);
9266 DestroyWindow(window
);
9269 static void fixed_function_decl_test(void)
9271 IDirect3DVertexDeclaration9
*dcl_float
= NULL
, *dcl_short
= NULL
, *dcl_ubyte
= NULL
, *dcl_color
= NULL
;
9272 IDirect3DVertexDeclaration9
*dcl_color_2
= NULL
, *dcl_ubyte_2
= NULL
, *dcl_nocolor
, *dcl_positiont
;
9273 IDirect3DVertexBuffer9
*vb
, *vb2
;
9274 IDirect3DDevice9
*device
;
9275 BOOL s_ok
, ub_ok
, f_ok
;
9276 DWORD color
, size
, i
;
9284 static const D3DVERTEXELEMENT9 decl_elements_d3dcolor
[] = {
9285 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
9286 {0, 12, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
9289 static const D3DVERTEXELEMENT9 decl_elements_d3dcolor_2streams
[] = {
9290 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
9291 {1, 0, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
9294 static const D3DVERTEXELEMENT9 decl_elements_ubyte4n
[] = {
9295 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
9296 {0, 12, D3DDECLTYPE_UBYTE4N
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
9299 static const D3DVERTEXELEMENT9 decl_elements_ubyte4n_2streams
[] = {
9300 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
9301 {1, 0, D3DDECLTYPE_UBYTE4N
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
9304 static const D3DVERTEXELEMENT9 decl_elements_short4
[] = {
9305 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
9306 {0, 12, D3DDECLTYPE_USHORT4N
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
9309 static const D3DVERTEXELEMENT9 decl_elements_float
[] = {
9310 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
9311 {0, 12, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
9314 static const D3DVERTEXELEMENT9 decl_elements_nocolor
[] = {
9315 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
9318 static const D3DVERTEXELEMENT9 decl_elements_positiont
[] = {
9319 {0, 0, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITIONT
, 0},
9320 {0, 16, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
9325 struct vec3 position
;
9328 quad1
[] = /* D3DCOLOR */
9330 {{-1.0f
, -1.0f
, 0.1f
}, 0x00ffff00},
9331 {{-1.0f
, 0.0f
, 0.1f
}, 0x00ffff00},
9332 {{ 0.0f
, -1.0f
, 0.1f
}, 0x00ffff00},
9333 {{ 0.0f
, 0.0f
, 0.1f
}, 0x00ffff00},
9335 quad2
[] = /* UBYTE4N */
9337 {{-1.0f
, 0.0f
, 0.1f
}, 0x00ffff00},
9338 {{-1.0f
, 1.0f
, 0.1f
}, 0x00ffff00},
9339 {{ 0.0f
, 0.0f
, 0.1f
}, 0x00ffff00},
9340 {{ 0.0f
, 1.0f
, 0.1f
}, 0x00ffff00},
9344 struct vec3 position
;
9345 struct { unsigned short x
, y
, z
, w
; } color
;
9347 quad3
[] = /* USHORT4N */
9349 {{0.0f
, -1.0f
, 0.1f
}, {0x0000, 0x0000, 0xffff, 0xffff}},
9350 {{0.0f
, 0.0f
, 0.1f
}, {0x0000, 0x0000, 0xffff, 0xffff}},
9351 {{1.0f
, -1.0f
, 0.1f
}, {0x0000, 0x0000, 0xffff, 0xffff}},
9352 {{1.0f
, 0.0f
, 0.1f
}, {0x0000, 0x0000, 0xffff, 0xffff}},
9356 struct vec3 position
;
9361 {{0.0f
, 0.0f
, 0.1f
}, {1.0f
, 0.0f
, 0.0f
, 0.0f
}},
9362 {{0.0f
, 1.0f
, 0.1f
}, {1.0f
, 0.0f
, 0.0f
, 0.0f
}},
9363 {{1.0f
, 0.0f
, 0.1f
}, {1.0f
, 0.0f
, 0.0f
, 0.0f
}},
9364 {{1.0f
, 1.0f
, 0.1f
}, {1.0f
, 0.0f
, 0.0f
, 0.0f
}},
9366 static const DWORD colors
[] =
9368 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
9369 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
9370 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
9371 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
9372 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
9373 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
9374 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
9375 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
9376 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
9377 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
9378 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
9379 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
9380 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
9381 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
9382 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
9383 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
9385 static const float quads
[] =
9409 struct vec4 position
;
9412 quad_transformed
[] =
9414 {{ 90.0f
, 110.0f
, 0.1f
, 2.0f
}, 0x00ffff00},
9415 {{570.0f
, 110.0f
, 0.1f
, 2.0f
}, 0x00ffff00},
9416 {{ 90.0f
, 300.0f
, 0.1f
, 2.0f
}, 0x00ffff00},
9417 {{570.0f
, 300.0f
, 0.1f
, 2.0f
}, 0x00ffff00},
9420 window
= create_window();
9421 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
9422 ok(!!d3d
, "Failed to create a D3D object.\n");
9423 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
9425 skip("Failed to create a D3D device, skipping tests.\n");
9429 memset(&caps
, 0, sizeof(caps
));
9430 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
9431 ok(hr
== D3D_OK
, "GetDeviceCaps failed, hr = %08x\n", hr
);
9433 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffffff, 1.0f
, 0);
9434 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
9436 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_d3dcolor
, &dcl_color
);
9437 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (%08x)\n", hr
);
9438 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_short4
, &dcl_short
);
9439 ok(SUCCEEDED(hr
) || hr
== E_FAIL
, "CreateVertexDeclaration failed (%08x)\n", hr
);
9440 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_float
, &dcl_float
);
9441 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (%08x)\n", hr
);
9442 if(caps
.DeclTypes
& D3DDTCAPS_UBYTE4N
) {
9443 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_ubyte4n_2streams
, &dcl_ubyte_2
);
9444 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (%08x)\n", hr
);
9445 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_ubyte4n
, &dcl_ubyte
);
9446 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (%08x)\n", hr
);
9448 trace("D3DDTCAPS_UBYTE4N not supported\n");
9452 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_d3dcolor_2streams
, &dcl_color_2
);
9453 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (%08x)\n", hr
);
9454 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_nocolor
, &dcl_nocolor
);
9455 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (%08x)\n", hr
);
9456 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_positiont
, &dcl_positiont
);
9457 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (%08x)\n", hr
);
9459 size
= max(sizeof(quad1
), max(sizeof(quad2
), max(sizeof(quad3
), max(sizeof(quad4
), sizeof(quads
)))));
9460 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, size
,
9461 0, 0, D3DPOOL_MANAGED
, &vb
, NULL
);
9462 ok(hr
== D3D_OK
, "CreateVertexBuffer failed with %08x\n", hr
);
9464 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
9465 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
9467 hr
= IDirect3DDevice9_BeginScene(device
);
9468 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9470 f_ok
= FALSE
; s_ok
= FALSE
; ub_ok
= FALSE
;
9473 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_color
);
9474 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
9475 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(quad1
[0]));
9476 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9479 /* Tests with non-standard fixed function types fail on the refrast. The
9480 * ATI driver partially accepts them, the NVIDIA driver accepts them all.
9481 * All those differences even though we're using software vertex
9482 * processing. Doh! */
9485 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_ubyte
);
9486 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
9487 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(quad2
[0]));
9488 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
9489 ub_ok
= SUCCEEDED(hr
);
9494 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_short
);
9495 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
9496 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, sizeof(quad3
[0]));
9497 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
9498 s_ok
= SUCCEEDED(hr
);
9503 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_float
);
9504 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
9505 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, sizeof(quad4
[0]));
9506 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
9507 f_ok
= SUCCEEDED(hr
);
9510 hr
= IDirect3DDevice9_EndScene(device
);
9511 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9514 color
= getPixelColor(device
, 480, 360);
9515 ok(color
== 0x000000ff || !s_ok
,
9516 "D3DDECLTYPE_USHORT4N returned color %08x, expected 0x000000ff\n", color
);
9519 color
= getPixelColor(device
, 160, 120);
9520 ok(color
== 0x0000ffff || !ub_ok
,
9521 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x0000ffff\n", color
);
9524 color
= getPixelColor(device
, 160, 360);
9525 ok(color
== 0x00ffff00,
9526 "D3DDECLTYPE_D3DCOLOR returned color %08x, expected 0x00ffff00\n", color
);
9529 color
= getPixelColor(device
, 480, 120);
9530 ok(color
== 0x00ff0000 || !f_ok
,
9531 "D3DDECLTYPE_FLOAT4 returned color %08x, expected 0x00ff0000\n", color
);
9533 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
9535 /* The following test with vertex buffers doesn't serve to find out new
9536 * information from windows. It is a plain regression test because wined3d
9537 * uses different codepaths for attribute conversion with vertex buffers.
9538 * It makes sure that the vertex buffer one works, while the above tests
9539 * whether the immediate mode code works. */
9540 f_ok
= FALSE
; s_ok
= FALSE
; ub_ok
= FALSE
;
9541 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffffff, 1.0f
, 0);
9542 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9543 hr
= IDirect3DDevice9_BeginScene(device
);
9544 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9548 hr
= IDirect3DVertexBuffer9_Lock(vb
, 0, sizeof(quad1
), &data
, 0);
9549 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
9550 memcpy(data
, quad1
, sizeof(quad1
));
9551 hr
= IDirect3DVertexBuffer9_Unlock(vb
);
9552 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
9553 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_color
);
9554 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
9555 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vb
, 0, sizeof(quad1
[0]));
9556 ok(SUCCEEDED(hr
), "Failed to set stream source, hr %#x.\n", hr
);
9557 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 0, 2);
9558 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9563 hr
= IDirect3DVertexBuffer9_Lock(vb
, 0, sizeof(quad2
), &data
, 0);
9564 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
9565 memcpy(data
, quad2
, sizeof(quad2
));
9566 hr
= IDirect3DVertexBuffer9_Unlock(vb
);
9567 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
9568 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_ubyte
);
9569 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
9570 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vb
, 0, sizeof(quad2
[0]));
9571 ok(SUCCEEDED(hr
), "Failed to set stream source, hr %#x.\n", hr
);
9572 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 0, 2);
9573 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
9574 ub_ok
= SUCCEEDED(hr
);
9579 hr
= IDirect3DVertexBuffer9_Lock(vb
, 0, sizeof(quad3
), &data
, 0);
9580 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
9581 memcpy(data
, quad3
, sizeof(quad3
));
9582 hr
= IDirect3DVertexBuffer9_Unlock(vb
);
9583 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
9584 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_short
);
9585 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
9586 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vb
, 0, sizeof(quad3
[0]));
9587 ok(SUCCEEDED(hr
), "Failed to set stream source, hr %#x.\n", hr
);
9588 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 0, 2);
9589 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
9590 s_ok
= SUCCEEDED(hr
);
9595 hr
= IDirect3DVertexBuffer9_Lock(vb
, 0, sizeof(quad4
), &data
, 0);
9596 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
9597 memcpy(data
, quad4
, sizeof(quad4
));
9598 hr
= IDirect3DVertexBuffer9_Unlock(vb
);
9599 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
9600 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_float
);
9601 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
9602 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vb
, 0, sizeof(quad4
[0]));
9603 ok(SUCCEEDED(hr
), "Failed to set stream source, hr %#x.\n", hr
);
9604 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 0, 2);
9605 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
9606 f_ok
= SUCCEEDED(hr
);
9609 hr
= IDirect3DDevice9_EndScene(device
);
9610 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9613 color
= getPixelColor(device
, 480, 360);
9614 ok(color
== 0x000000ff || !s_ok
,
9615 "D3DDECLTYPE_USHORT4N returned color %08x, expected 0x000000ff\n", color
);
9618 color
= getPixelColor(device
, 160, 120);
9619 ok(color
== 0x0000ffff || !ub_ok
,
9620 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x0000ffff\n", color
);
9623 color
= getPixelColor(device
, 160, 360);
9624 ok(color
== 0x00ffff00,
9625 "D3DDECLTYPE_D3DCOLOR returned color %08x, expected 0x00ffff00\n", color
);
9628 color
= getPixelColor(device
, 480, 120);
9629 ok(color
== 0x00ff0000 || !f_ok
,
9630 "D3DDECLTYPE_FLOAT4 returned color %08x, expected 0x00ff0000\n", color
);
9632 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
9634 /* Test with no diffuse color attribute. */
9635 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff0000ff, 0.0, 0);
9636 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9638 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_nocolor
);
9639 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
9640 hr
= IDirect3DDevice9_BeginScene(device
);
9641 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9642 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quads
, sizeof(float) * 3);
9643 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9644 hr
= IDirect3DDevice9_EndScene(device
);
9645 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9647 color
= getPixelColor(device
, 160, 360);
9648 ok(color
== 0x00ffffff, "Got unexpected color 0x%08x in the no color attribute test.\n", color
);
9650 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
9652 /* Test what happens with specular lighting enabled and no specular color attribute. */
9653 f_ok
= FALSE
; s_ok
= FALSE
; ub_ok
= FALSE
;
9654 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffffff, 1.0f
, 0);
9655 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9656 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SPECULARENABLE
, TRUE
);
9657 ok(SUCCEEDED(hr
), "Failed to enable specular lighting, hr %#x.\n", hr
);
9658 hr
= IDirect3DDevice9_BeginScene(device
);
9659 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9663 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_color
);
9664 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
9665 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(quad1
[0]));
9666 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9670 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_ubyte
);
9671 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
9672 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(quad2
[0]));
9673 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
9674 ub_ok
= SUCCEEDED(hr
);
9678 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_short
);
9679 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
9680 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, sizeof(quad3
[0]));
9681 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
9682 s_ok
= SUCCEEDED(hr
);
9686 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_float
);
9687 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
9688 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, sizeof(quad4
[0]));
9689 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
9690 f_ok
= SUCCEEDED(hr
);
9693 hr
= IDirect3DDevice9_EndScene(device
);
9694 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9695 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SPECULARENABLE
, FALSE
);
9696 ok(SUCCEEDED(hr
), "Failed to disable specular lighting, hr %#x.\n", hr
);
9700 color
= getPixelColor(device
, 480, 360);
9701 ok(color
== 0x000000ff || !s_ok
,
9702 "D3DDECLTYPE_USHORT4N returned color %08x, expected 0x000000ff.\n", color
);
9706 color
= getPixelColor(device
, 160, 120);
9707 ok(color
== 0x0000ffff || !ub_ok
,
9708 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x0000ffff.\n", color
);
9712 color
= getPixelColor(device
, 160, 360);
9713 ok(color
== 0x00ffff00,
9714 "D3DDECLTYPE_D3DCOLOR returned color %08x, expected 0x00ffff00.\n", color
);
9718 color
= getPixelColor(device
, 480, 120);
9719 ok(color
== 0x00ff0000 || !f_ok
,
9720 "D3DDECLTYPE_FLOAT4 returned color %08x, expected 0x00ff0000.\n", color
);
9722 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
9724 hr
= IDirect3DVertexBuffer9_Lock(vb
, 0, sizeof(quad_transformed
), &data
, 0);
9725 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr
);
9726 memcpy(data
, quad_transformed
, sizeof(quad_transformed
));
9727 hr
= IDirect3DVertexBuffer9_Unlock(vb
);
9728 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Unlock failed (%08x)\n", hr
);
9730 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_positiont
);
9731 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed with %08x\n", hr
);
9733 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff0000ff, 0.0, 0);
9734 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
9736 hr
= IDirect3DDevice9_BeginScene(device
);
9737 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9738 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vb
, 0, sizeof(quad_transformed
[0]));
9739 ok(SUCCEEDED(hr
), "Failed to set stream source, hr %#x.\n", hr
);
9740 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 0, 2);
9741 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9742 hr
= IDirect3DDevice9_EndScene(device
);
9743 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9745 color
= getPixelColor(device
, 88, 108);
9746 ok(color
== 0x000000ff,
9747 "pixel 88/108 has color %08x, expected 0x000000ff\n", color
);
9748 color
= getPixelColor(device
, 92, 108);
9749 ok(color
== 0x000000ff,
9750 "pixel 92/108 has color %08x, expected 0x000000ff\n", color
);
9751 color
= getPixelColor(device
, 88, 112);
9752 ok(color
== 0x000000ff,
9753 "pixel 88/112 has color %08x, expected 0x000000ff\n", color
);
9754 color
= getPixelColor(device
, 92, 112);
9755 ok(color
== 0x00ffff00,
9756 "pixel 92/112 has color %08x, expected 0x00ffff00\n", color
);
9758 color
= getPixelColor(device
, 568, 108);
9759 ok(color
== 0x000000ff,
9760 "pixel 568/108 has color %08x, expected 0x000000ff\n", color
);
9761 color
= getPixelColor(device
, 572, 108);
9762 ok(color
== 0x000000ff,
9763 "pixel 572/108 has color %08x, expected 0x000000ff\n", color
);
9764 color
= getPixelColor(device
, 568, 112);
9765 ok(color
== 0x00ffff00,
9766 "pixel 568/112 has color %08x, expected 0x00ffff00\n", color
);
9767 color
= getPixelColor(device
, 572, 112);
9768 ok(color
== 0x000000ff,
9769 "pixel 572/112 has color %08x, expected 0x000000ff\n", color
);
9771 color
= getPixelColor(device
, 88, 298);
9772 ok(color
== 0x000000ff,
9773 "pixel 88/298 has color %08x, expected 0x000000ff\n", color
);
9774 color
= getPixelColor(device
, 92, 298);
9775 ok(color
== 0x00ffff00,
9776 "pixel 92/298 has color %08x, expected 0x00ffff00\n", color
);
9777 color
= getPixelColor(device
, 88, 302);
9778 ok(color
== 0x000000ff,
9779 "pixel 88/302 has color %08x, expected 0x000000ff\n", color
);
9780 color
= getPixelColor(device
, 92, 302);
9781 ok(color
== 0x000000ff,
9782 "pixel 92/302 has color %08x, expected 0x000000ff\n", color
);
9784 color
= getPixelColor(device
, 568, 298);
9785 ok(color
== 0x00ffff00,
9786 "pixel 568/298 has color %08x, expected 0x00ffff00\n", color
);
9787 color
= getPixelColor(device
, 572, 298);
9788 ok(color
== 0x000000ff,
9789 "pixel 572/298 has color %08x, expected 0x000000ff\n", color
);
9790 color
= getPixelColor(device
, 568, 302);
9791 ok(color
== 0x000000ff,
9792 "pixel 568/302 has color %08x, expected 0x000000ff\n", color
);
9793 color
= getPixelColor(device
, 572, 302);
9794 ok(color
== 0x000000ff,
9795 "pixel 572/302 has color %08x, expected 0x000000ff\n", color
);
9797 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
9799 /* This test is pointless without those two declarations: */
9800 if((!dcl_color_2
) || (!dcl_ubyte_2
)) {
9801 skip("color-ubyte switching test declarations aren't supported\n");
9805 hr
= IDirect3DVertexBuffer9_Lock(vb
, 0, sizeof(quads
), &data
, 0);
9806 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr
);
9807 memcpy(data
, quads
, sizeof(quads
));
9808 hr
= IDirect3DVertexBuffer9_Unlock(vb
);
9809 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Unlock failed (%08x)\n", hr
);
9810 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, sizeof(colors
),
9811 0, 0, D3DPOOL_MANAGED
, &vb2
, NULL
);
9812 ok(hr
== D3D_OK
, "CreateVertexBuffer failed with %08x\n", hr
);
9813 hr
= IDirect3DVertexBuffer9_Lock(vb2
, 0, sizeof(colors
), &data
, 0);
9814 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr
);
9815 memcpy(data
, colors
, sizeof(colors
));
9816 hr
= IDirect3DVertexBuffer9_Unlock(vb2
);
9817 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Unlock failed (%08x)\n", hr
);
9819 for(i
= 0; i
< 2; i
++) {
9820 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
9821 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
9823 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vb
, 0, sizeof(float) * 3);
9824 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetStreamSource failed with %08x\n", hr
);
9826 hr
= IDirect3DDevice9_SetStreamSource(device
, 1, vb2
, 0, sizeof(DWORD
) * 4);
9828 hr
= IDirect3DDevice9_SetStreamSource(device
, 1, vb2
, 8, sizeof(DWORD
) * 4);
9830 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetStreamSource failed with %08x\n", hr
);
9832 hr
= IDirect3DDevice9_BeginScene(device
);
9833 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9835 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_ubyte_2
);
9836 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
9837 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 0, 2);
9838 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
9839 ub_ok
= SUCCEEDED(hr
);
9841 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_color_2
);
9842 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
9843 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 4, 2);
9844 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9846 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_ubyte_2
);
9847 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
9848 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 8, 2);
9849 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
9850 ub_ok
= (SUCCEEDED(hr
) && ub_ok
);
9852 hr
= IDirect3DDevice9_EndScene(device
);
9853 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9856 color
= getPixelColor(device
, 480, 360);
9857 ok(color
== 0x00ff0000,
9858 "D3DDECLTYPE_D3DCOLOR returned color %08x, expected 0x00ff0000\n", color
);
9859 color
= getPixelColor(device
, 160, 120);
9860 ok(color
== 0x00ffffff,
9861 "Unused quad returned color %08x, expected 0x00ffffff\n", color
);
9862 color
= getPixelColor(device
, 160, 360);
9863 ok(color
== 0x000000ff || !ub_ok
,
9864 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x000000ff\n", color
);
9865 color
= getPixelColor(device
, 480, 120);
9866 ok(color
== 0x000000ff || !ub_ok
,
9867 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x000000ff\n", color
);
9869 color
= getPixelColor(device
, 480, 360);
9870 ok(color
== 0x000000ff,
9871 "D3DDECLTYPE_D3DCOLOR returned color %08x, expected 0x000000ff\n", color
);
9872 color
= getPixelColor(device
, 160, 120);
9873 ok(color
== 0x00ffffff,
9874 "Unused quad returned color %08x, expected 0x00ffffff\n", color
);
9875 color
= getPixelColor(device
, 160, 360);
9876 ok(color
== 0x00ff0000 || !ub_ok
,
9877 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x00ff0000\n", color
);
9878 color
= getPixelColor(device
, 480, 120);
9879 ok(color
== 0x00ff0000 || !ub_ok
,
9880 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x00ff0000\n", color
);
9882 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
9885 IDirect3DVertexBuffer9_Release(vb2
);
9887 IDirect3DVertexBuffer9_Release(vb
);
9888 if(dcl_float
) IDirect3DVertexDeclaration9_Release(dcl_float
);
9889 if(dcl_short
) IDirect3DVertexDeclaration9_Release(dcl_short
);
9890 if(dcl_ubyte
) IDirect3DVertexDeclaration9_Release(dcl_ubyte
);
9891 if(dcl_color
) IDirect3DVertexDeclaration9_Release(dcl_color
);
9892 if(dcl_color_2
) IDirect3DVertexDeclaration9_Release(dcl_color_2
);
9893 if(dcl_ubyte_2
) IDirect3DVertexDeclaration9_Release(dcl_ubyte_2
);
9894 IDirect3DVertexDeclaration9_Release(dcl_nocolor
);
9895 IDirect3DVertexDeclaration9_Release(dcl_positiont
);
9896 refcount
= IDirect3DDevice9_Release(device
);
9897 ok(!refcount
, "Device has %u references left.\n", refcount
);
9899 IDirect3D9_Release(d3d
);
9900 DestroyWindow(window
);
9903 static void test_vshader_float16(void)
9905 IDirect3DVertexDeclaration9
*vdecl
= NULL
;
9906 IDirect3DVertexBuffer9
*buffer
= NULL
;
9907 IDirect3DVertexShader9
*shader
;
9908 IDirect3DDevice9
*device
;
9917 static const D3DVERTEXELEMENT9 decl_elements
[] =
9919 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
9920 {0, 12, D3DDECLTYPE_FLOAT16_4
,D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
9923 static const DWORD shader_code
[] =
9925 0xfffe0101, /* vs_1_1 */
9926 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
9927 0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color v1 */
9928 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
9929 0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
9932 static const struct vertex_float16color
9939 { -1.0, -1.0, 0.1, 0x3c000000, 0x00000000 }, /* green */
9940 { -1.0, 0.0, 0.1, 0x3c000000, 0x00000000 },
9941 { 0.0, -1.0, 0.1, 0x3c000000, 0x00000000 },
9942 { 0.0, 0.0, 0.1, 0x3c000000, 0x00000000 },
9944 { 0.0, -1.0, 0.1, 0x00003c00, 0x00000000 }, /* red */
9945 { 0.0, 0.0, 0.1, 0x00003c00, 0x00000000 },
9946 { 1.0, -1.0, 0.1, 0x00003c00, 0x00000000 },
9947 { 1.0, 0.0, 0.1, 0x00003c00, 0x00000000 },
9949 { 0.0, 0.0, 0.1, 0x00000000, 0x00003c00 }, /* blue */
9950 { 0.0, 1.0, 0.1, 0x00000000, 0x00003c00 },
9951 { 1.0, 0.0, 0.1, 0x00000000, 0x00003c00 },
9952 { 1.0, 1.0, 0.1, 0x00000000, 0x00003c00 },
9954 { -1.0, 0.0, 0.1, 0x00000000, 0x3c000000 }, /* alpha */
9955 { -1.0, 1.0, 0.1, 0x00000000, 0x3c000000 },
9956 { 0.0, 0.0, 0.1, 0x00000000, 0x3c000000 },
9957 { 0.0, 1.0, 0.1, 0x00000000, 0x3c000000 },
9960 window
= create_window();
9961 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
9962 ok(!!d3d
, "Failed to create a D3D object.\n");
9963 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
9965 skip("Failed to create a D3D device, skipping tests.\n");
9969 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
9970 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
9971 if (caps
.VertexShaderVersion
< D3DVS_VERSION(3, 0))
9973 skip("No vs_3_0 support, skipping tests.\n");
9974 IDirect3DDevice9_Release(device
);
9978 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff102030, 1.0f
, 0);
9979 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr
);
9981 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &vdecl
);
9982 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateVertexDeclaration failed hr=%08x\n", hr
);
9983 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_code
, &shader
);
9984 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateVertexShader failed hr=%08x\n", hr
);
9985 hr
= IDirect3DDevice9_SetVertexShader(device
, shader
);
9986 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShader failed hr=%08x\n", hr
);
9988 hr
= IDirect3DDevice9_BeginScene(device
);
9989 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9990 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, vdecl
);
9991 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
9992 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
+ 0, sizeof(quad
[0]));
9993 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9994 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
+ 4, sizeof(quad
[0]));
9995 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9996 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
+ 8, sizeof(quad
[0]));
9997 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9998 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
+ 12, sizeof(quad
[0]));
9999 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10000 hr
= IDirect3DDevice9_EndScene(device
);
10001 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10003 color
= getPixelColor(device
, 480, 360);
10004 ok(color
== 0x00ff0000,
10005 "Input 0x00003c00, 0x00000000 returned color %08x, expected 0x00ff0000\n", color
);
10006 color
= getPixelColor(device
, 160, 120);
10007 ok(color
== 0x00000000,
10008 "Input 0x00000000, 0x3c000000 returned color %08x, expected 0x00000000\n", color
);
10009 color
= getPixelColor(device
, 160, 360);
10010 ok(color
== 0x0000ff00,
10011 "Input 0x3c000000, 0x00000000 returned color %08x, expected 0x0000ff00\n", color
);
10012 color
= getPixelColor(device
, 480, 120);
10013 ok(color
== 0x000000ff,
10014 "Input 0x00000000, 0x00003c00 returned color %08x, expected 0x000000ff\n", color
);
10015 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
10017 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff102030, 0.0, 0);
10018 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr
);
10020 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, sizeof(quad
), 0, 0,
10021 D3DPOOL_MANAGED
, &buffer
, NULL
);
10022 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexBuffer failed, hr=%08x\n", hr
);
10023 hr
= IDirect3DVertexBuffer9_Lock(buffer
, 0, sizeof(quad
), &data
, 0);
10024 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Lock failed, hr=%08x\n", hr
);
10025 memcpy(data
, quad
, sizeof(quad
));
10026 hr
= IDirect3DVertexBuffer9_Unlock(buffer
);
10027 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Unlock failed, hr=%08x\n", hr
);
10028 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, buffer
, 0, sizeof(quad
[0]));
10029 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetStreamSource failed, hr=%08x\n", hr
);
10031 hr
= IDirect3DDevice9_BeginScene(device
);
10032 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10033 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 0, 2);
10034 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10035 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 4, 2);
10036 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10037 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 8, 2);
10038 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10039 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 12, 2);
10040 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10041 hr
= IDirect3DDevice9_EndScene(device
);
10042 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10044 color
= getPixelColor(device
, 480, 360);
10045 ok(color
== 0x00ff0000,
10046 "Input 0x00003c00, 0x00000000 returned color %08x, expected 0x00ff0000\n", color
);
10047 color
= getPixelColor(device
, 160, 120);
10048 ok(color
== 0x00000000,
10049 "Input 0x00000000, 0x3c000000 returned color %08x, expected 0x00000000\n", color
);
10050 color
= getPixelColor(device
, 160, 360);
10051 ok(color
== 0x0000ff00,
10052 "Input 0x3c000000, 0x00000000 returned color %08x, expected 0x0000ff00\n", color
);
10053 color
= getPixelColor(device
, 480, 120);
10054 ok(color
== 0x000000ff,
10055 "Input 0x00000000, 0x00003c00 returned color %08x, expected 0x000000ff\n", color
);
10056 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
10058 IDirect3DVertexDeclaration9_Release(vdecl
);
10059 IDirect3DVertexShader9_Release(shader
);
10060 IDirect3DVertexBuffer9_Release(buffer
);
10061 refcount
= IDirect3DDevice9_Release(device
);
10062 ok(!refcount
, "Device has %u references left.\n", refcount
);
10064 IDirect3D9_Release(d3d
);
10065 DestroyWindow(window
);
10068 static void conditional_np2_repeat_test(void)
10070 IDirect3DTexture9
*texture
;
10071 IDirect3DDevice9
*device
;
10072 D3DLOCKED_RECT rect
;
10081 static const float quad
[] =
10083 -1.0f
, -1.0f
, 0.1f
, -0.2f
, -0.2f
,
10084 -1.0f
, 1.0f
, 0.1f
, -0.2f
, 1.2f
,
10085 1.0f
, -1.0f
, 0.1f
, 1.2f
, -0.2f
,
10086 1.0f
, 1.0f
, 0.1f
, 1.2f
, 1.2f
,
10089 window
= create_window();
10090 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
10091 ok(!!d3d
, "Failed to create a D3D object.\n");
10092 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
10094 skip("Failed to create a D3D device, skipping tests.\n");
10098 memset(&caps
, 0, sizeof(caps
));
10099 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
10100 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetDeviceCaps failed hr=%08x\n", hr
);
10101 if (caps
.TextureCaps
& D3DPTEXTURECAPS_NONPOW2CONDITIONAL
)
10103 /* NP2 conditional requires the POW2 flag. Check that while we're at it */
10104 ok(caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
,
10105 "Card has conditional NP2 support without power of two restriction set\n");
10107 else if (caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
)
10109 skip("No conditional NP2 support, skipping conditional NP2 tests\n");
10110 IDirect3DDevice9_Release(device
);
10115 skip("Card has unconditional NP2 support, skipping conditional NP2 tests\n");
10116 IDirect3DDevice9_Release(device
);
10120 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff000000, 1.0f
, 0);
10121 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr
);
10123 hr
= IDirect3DDevice9_CreateTexture(device
, 10, 10, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &texture
, NULL
);
10124 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture failed hr=%08x\n", hr
);
10126 memset(&rect
, 0, sizeof(rect
));
10127 hr
= IDirect3DTexture9_LockRect(texture
, 0, &rect
, NULL
, 0);
10128 ok(hr
== D3D_OK
, "IDirect3DTexture9_LockRect failed hr=%08x\n", hr
);
10129 for(y
= 0; y
< 10; y
++) {
10130 for(x
= 0; x
< 10; x
++) {
10131 dst
= (DWORD
*) ((BYTE
*) rect
.pBits
+ y
* rect
.Pitch
+ x
* sizeof(DWORD
));
10132 if(x
== 0 || x
== 9 || y
== 0 || y
== 9) {
10139 hr
= IDirect3DTexture9_UnlockRect(texture
, 0);
10140 ok(hr
== D3D_OK
, "IDirect3DTexture9_UnlockRect failed hr=%08x\n", hr
);
10142 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) texture
);
10143 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture failed hr=%08x\n", hr
);
10144 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
10145 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
10146 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSU
, D3DTADDRESS_WRAP
);
10147 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState failed hr=%08x\n", hr
);
10148 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSV
, D3DTADDRESS_WRAP
);
10149 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState failed hr=%08x\n", hr
);
10150 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
10151 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed, hr=%08x\n", hr
);
10153 hr
= IDirect3DDevice9_BeginScene(device
);
10154 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10155 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(float) * 5);
10156 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10157 hr
= IDirect3DDevice9_EndScene(device
);
10158 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10160 color
= getPixelColor(device
, 1, 1);
10161 ok(color
== 0x00ff0000, "NP2: Pixel 1, 1 has color %08x, expected 0x00ff0000\n", color
);
10162 color
= getPixelColor(device
, 639, 479);
10163 ok(color
== 0x00ff0000, "NP2: Pixel 639, 479 has color %08x, expected 0x00ff0000\n", color
);
10165 color
= getPixelColor(device
, 135, 101);
10166 ok(color
== 0x00ff0000, "NP2: Pixel 135, 101 has color %08x, expected 0x00ff0000\n", color
);
10167 color
= getPixelColor(device
, 140, 101);
10168 ok(color
== 0x00ff0000, "NP2: Pixel 140, 101 has color %08x, expected 0x00ff0000\n", color
);
10169 color
= getPixelColor(device
, 135, 105);
10170 ok(color
== 0x00ff0000, "NP2: Pixel 135, 105 has color %08x, expected 0x00ff0000\n", color
);
10171 color
= getPixelColor(device
, 140, 105);
10172 ok(color
== 0x000000ff, "NP2: Pixel 140, 105 has color %08x, expected 0x000000ff\n", color
);
10174 color
= getPixelColor(device
, 135, 376);
10175 ok(color
== 0x00ff0000, "NP2: Pixel 135, 376 has color %08x, expected 0x00ff0000\n", color
);
10176 color
= getPixelColor(device
, 140, 376);
10177 ok(color
== 0x000000ff, "NP2: Pixel 140, 376 has color %08x, expected 0x000000ff\n", color
);
10178 color
= getPixelColor(device
, 135, 379);
10179 ok(color
== 0x00ff0000, "NP2: Pixel 135, 379 has color %08x, expected 0x00ff0000\n", color
);
10180 color
= getPixelColor(device
, 140, 379);
10181 ok(color
== 0x00ff0000, "NP2: Pixel 140, 379 has color %08x, expected 0x00ff0000\n", color
);
10183 color
= getPixelColor(device
, 500, 101);
10184 ok(color
== 0x00ff0000, "NP2: Pixel 500, 101 has color %08x, expected 0x00ff0000\n", color
);
10185 color
= getPixelColor(device
, 504, 101);
10186 ok(color
== 0x00ff0000, "NP2: Pixel 504, 101 has color %08x, expected 0x00ff0000\n", color
);
10187 color
= getPixelColor(device
, 500, 105);
10188 ok(color
== 0x000000ff, "NP2: Pixel 500, 105 has color %08x, expected 0x000000ff\n", color
);
10189 color
= getPixelColor(device
, 504, 105);
10190 ok(color
== 0x00ff0000, "NP2: Pixel 504, 105 has color %08x, expected 0x00ff0000\n", color
);
10192 color
= getPixelColor(device
, 500, 376);
10193 ok(color
== 0x000000ff, "NP2: Pixel 500, 376 has color %08x, expected 0x000000ff\n", color
);
10194 color
= getPixelColor(device
, 504, 376);
10195 ok(color
== 0x00ff0000, "NP2: Pixel 504, 376 has color %08x, expected 0x00ff0000\n", color
);
10196 color
= getPixelColor(device
, 500, 380);
10197 ok(color
== 0x00ff0000, "NP2: Pixel 500, 380 has color %08x, expected 0x00ff0000\n", color
);
10198 color
= getPixelColor(device
, 504, 380);
10199 ok(color
== 0x00ff0000, "NP2: Pixel 504, 380 has color %08x, expected 0x00ff0000\n", color
);
10201 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
10203 IDirect3DTexture9_Release(texture
);
10204 refcount
= IDirect3DDevice9_Release(device
);
10205 ok(!refcount
, "Device has %u references left.\n", refcount
);
10207 IDirect3D9_Release(d3d
);
10208 DestroyWindow(window
);
10211 static void vface_register_test(void)
10213 IDirect3DSurface9
*surface
, *backbuffer
;
10214 IDirect3DVertexShader9
*vshader
;
10215 IDirect3DPixelShader9
*shader
;
10216 IDirect3DTexture9
*texture
;
10217 IDirect3DDevice9
*device
;
10225 static const DWORD shader_code
[] =
10227 0xffff0300, /* ps_3_0 */
10228 0x05000051, 0xa00f0000, 0x00000000, 0x3f800000, 0x00000000, 0x00000000, /* def c0, 0.0, 1.0, 0.0, 0.0 */
10229 0x05000051, 0xa00f0001, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c1, 1.0, 0.0, 0.0, 0.0 */
10230 0x0200001f, 0x80000000, 0x900f1001, /* dcl vFace */
10231 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
10232 0x04000058, 0x800f0000, 0x90e41001, 0xa0e40000, 0x80e40001, /* cmp r0, vFace, c0, r1 */
10233 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
10234 0x0000ffff /* END */
10236 static const DWORD vshader_code
[] =
10238 0xfffe0300, /* vs_3_0 */
10239 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
10240 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
10241 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
10242 0x0000ffff /* end */
10244 static const float quad
[] =
10246 -1.0f
, -1.0f
, 0.1f
,
10262 static const float blit
[] =
10264 0.0f
, -1.0f
, 0.1f
, 0.0f
, 0.0f
,
10265 1.0f
, -1.0f
, 0.1f
, 1.0f
, 0.0f
,
10266 0.0f
, 1.0f
, 0.1f
, 0.0f
, 1.0f
,
10267 1.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
,
10270 window
= create_window();
10271 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
10272 ok(!!d3d
, "Failed to create a D3D object.\n");
10273 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
10275 skip("Failed to create a D3D device, skipping tests.\n");
10279 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
10280 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
10281 if (caps
.PixelShaderVersion
< D3DPS_VERSION(3, 0) || caps
.VertexShaderVersion
< D3DVS_VERSION(3, 0))
10283 skip("No shader model 3 support, skipping tests.\n");
10284 IDirect3DDevice9_Release(device
);
10288 hr
= IDirect3DDevice9_CreateVertexShader(device
, vshader_code
, &vshader
);
10289 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader failed hr=%08x\n", hr
);
10290 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code
, &shader
);
10291 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader failed hr=%08x\n", hr
);
10292 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &texture
, NULL
);
10293 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture failed hr=%08x\n", hr
);
10294 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
10295 ok(hr
== D3D_OK
, "IDirect3DTexture9_GetSurfaceLevel failed hr=%08x\n", hr
);
10296 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CULLMODE
, D3DCULL_NONE
);
10297 ok(SUCCEEDED(hr
), "Failed to set cull mode, hr %#x.\n", hr
);
10298 hr
= IDirect3DDevice9_SetPixelShader(device
, shader
);
10299 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader failed hr=%08x\n", hr
);
10300 hr
= IDirect3DDevice9_SetVertexShader(device
, vshader
);
10301 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader failed hr=%08x\n", hr
);
10302 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
10303 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed hr=%08x\n", hr
);
10304 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
10305 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetBackBuffer failed hr=%08x\n", hr
);
10307 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff0000ff, 1.0f
, 0);
10308 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr
);
10310 hr
= IDirect3DDevice9_BeginScene(device
);
10311 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10313 /* First, draw to the texture and the back buffer to test both offscreen and onscreen cases */
10314 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, surface
);
10315 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
10316 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff0000ff, 0.0, 0);
10317 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
10318 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 4, quad
, sizeof(float) * 3);
10319 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10320 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
10321 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
10322 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 4, quad
, sizeof(float) * 3);
10323 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10325 /* Blit the texture onto the back buffer to make it visible */
10326 hr
= IDirect3DDevice9_SetVertexShader(device
, NULL
);
10327 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
10328 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
10329 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
10330 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) texture
);
10331 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
10332 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
10333 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
10334 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
10335 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
10336 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
10337 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
10338 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, blit
, sizeof(float) * 5);
10339 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10341 hr
= IDirect3DDevice9_EndScene(device
);
10342 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10344 color
= getPixelColor(device
, 160, 360);
10345 ok(color
== 0x00ff0000, "vFace: Onscreen rendered front facing quad has color 0x%08x, expected 0x00ff0000\n", color
);
10346 color
= getPixelColor(device
, 160, 120);
10347 ok(color
== 0x0000ff00, "vFace: Onscreen rendered back facing quad has color 0x%08x, expected 0x0000ff00\n", color
);
10348 color
= getPixelColor(device
, 480, 360);
10349 ok(color
== 0x0000ff00, "vFace: Offscreen rendered back facing quad has color 0x%08x, expected 0x0000ff00\n", color
);
10350 color
= getPixelColor(device
, 480, 120);
10351 ok(color
== 0x00ff0000, "vFace: Offscreen rendered front facing quad has color 0x%08x, expected 0x00ff0000\n", color
);
10352 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
10353 ok(SUCCEEDED(hr
), "Present failed, hr %#x.\n", hr
);
10355 IDirect3DPixelShader9_Release(shader
);
10356 IDirect3DVertexShader9_Release(vshader
);
10357 IDirect3DSurface9_Release(surface
);
10358 IDirect3DSurface9_Release(backbuffer
);
10359 IDirect3DTexture9_Release(texture
);
10360 refcount
= IDirect3DDevice9_Release(device
);
10361 ok(!refcount
, "Device has %u references left.\n", refcount
);
10363 IDirect3D9_Release(d3d
);
10364 DestroyWindow(window
);
10367 static void fixed_function_bumpmap_test(void)
10369 IDirect3DVertexDeclaration9
*vertex_declaration
;
10370 IDirect3DTexture9
*texture
, *tex1
, *tex2
;
10371 D3DLOCKED_RECT locked_rect
;
10372 IDirect3DDevice9
*device
;
10373 BOOL L6V5U5_supported
;
10374 float scale
, offset
;
10383 static const float quad
[][7] =
10385 {-1.0f
, -1.0f
, 0.1f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
},
10386 {-1.0f
, 1.0f
, 0.1f
, 0.0f
, 1.0f
, 0.0f
, 1.0f
},
10387 { 1.0f
, -1.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
, 0.0f
},
10388 { 1.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
},
10390 static const D3DVERTEXELEMENT9 decl_elements
[] =
10392 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
10393 {0, 12, D3DDECLTYPE_FLOAT2
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
10394 {0, 20, D3DDECLTYPE_FLOAT2
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 1},
10397 /* use asymmetric matrix to test loading */
10398 static const float bumpenvmat
[4] = {0.0f
, 0.5f
, -0.5f
, 0.0f
};
10400 window
= create_window();
10401 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
10402 ok(!!d3d
, "Failed to create a D3D object.\n");
10403 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
10405 skip("Failed to create a D3D device, skipping tests.\n");
10409 memset(&caps
, 0, sizeof(caps
));
10410 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
10411 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetDeviceCaps failed hr=%08x\n", hr
);
10412 if (!(caps
.TextureOpCaps
& D3DTEXOPCAPS_BUMPENVMAP
))
10414 skip("D3DTEXOPCAPS_BUMPENVMAP not set, skipping bumpmap tests\n");
10415 IDirect3DDevice9_Release(device
);
10419 /* This check is disabled, some Windows drivers do not handle
10420 * D3DUSAGE_QUERY_LEGACYBUMPMAP properly. They report that it is not
10421 * supported, but after that bump mapping works properly. So just test if
10422 * the format is generally supported, and check the BUMPENVMAP flag. */
10423 L6V5U5_supported
= SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
,
10424 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_TEXTURE
, D3DFMT_L6V5U5
));
10425 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
,
10426 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_TEXTURE
, D3DFMT_V8U8
)))
10428 skip("D3DFMT_V8U8 not supported for legacy bump mapping\n");
10429 IDirect3DDevice9_Release(device
);
10433 /* Generate the textures */
10434 generate_bumpmap_textures(device
);
10436 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_BUMPENVMAT00
, *(LPDWORD
)&bumpenvmat
[0]);
10437 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
10438 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_BUMPENVMAT01
, *(LPDWORD
)&bumpenvmat
[1]);
10439 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
10440 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_BUMPENVMAT10
, *(LPDWORD
)&bumpenvmat
[2]);
10441 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
10442 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_BUMPENVMAT11
, *(LPDWORD
)&bumpenvmat
[3]);
10443 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
10445 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_BUMPENVMAP
);
10446 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
10447 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
10448 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
10449 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_CURRENT
);
10450 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
10452 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
10453 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
10454 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
10455 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
10456 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLORARG2
, D3DTA_CURRENT
);
10457 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
10459 hr
= IDirect3DDevice9_SetTextureStageState(device
, 2, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
10460 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
10462 hr
= IDirect3DDevice9_SetVertexShader(device
, NULL
);
10463 ok(SUCCEEDED(hr
), "SetVertexShader failed (%08x)\n", hr
);
10465 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffff00ff, 1.0f
, 0);
10466 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed (%08x)\n", hr
);
10468 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &vertex_declaration
);
10469 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (0x%08x)\n", hr
);
10470 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, vertex_declaration
);
10471 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed (0x%08x)\n", hr
);
10473 hr
= IDirect3DDevice9_BeginScene(device
);
10474 ok(SUCCEEDED(hr
), "BeginScene failed (0x%08x)\n", hr
);
10476 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad
[0], sizeof(quad
[0]));
10477 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (0x%08x)\n", hr
);
10479 hr
= IDirect3DDevice9_EndScene(device
);
10480 ok(SUCCEEDED(hr
), "EndScene failed (0x%08x)\n", hr
);
10482 color
= getPixelColor(device
, 240, 60);
10483 ok(color_match(color
, 0x005ea000, 4), "Got unexpected color 0x%08x.\n", color
);
10484 color
= getPixelColor(device
, 400, 60);
10485 ok(color_match(color
, 0x009ea000, 4), "Got unexpected color 0x%08x.\n", color
);
10486 color
= getPixelColor(device
, 80, 180);
10487 ok(color_match(color
, 0x005ea000, 4), "Got unexpected color 0x%08x.\n", color
);
10488 color
= getPixelColor(device
, 560, 180);
10489 ok(color_match(color
, 0x009ea000, 4), "Got unexpected color 0x%08x.\n", color
);
10490 color
= getPixelColor(device
, 80, 300);
10491 ok(color_match(color
, 0x005e6000, 4), "Got unexpected color 0x%08x.\n", color
);
10492 color
= getPixelColor(device
, 560, 300);
10493 ok(color_match(color
, 0x009e6000, 4), "Got unexpected color 0x%08x.\n", color
);
10494 color
= getPixelColor(device
, 240, 420);
10495 ok(color_match(color
, 0x005e6000, 4), "Got unexpected color 0x%08x.\n", color
);
10496 color
= getPixelColor(device
, 400, 420);
10497 ok(color_match(color
, 0x009e6000, 4), "Got unexpected color 0x%08x.\n", color
);
10498 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
10499 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
10501 for(i
= 0; i
< 2; i
++) {
10502 hr
= IDirect3DDevice9_GetTexture(device
, i
, (IDirect3DBaseTexture9
**) &texture
);
10503 ok(SUCCEEDED(hr
), "IDirect3DDevice9_GetTexture failed (0x%08x)\n", hr
);
10504 IDirect3DTexture9_Release(texture
); /* For the GetTexture */
10505 hr
= IDirect3DDevice9_SetTexture(device
, i
, NULL
);
10506 ok(SUCCEEDED(hr
), "SetTexture failed (0x%08x)\n", hr
);
10507 IDirect3DTexture9_Release(texture
); /* To destroy it */
10510 if (!L6V5U5_supported
|| !(caps
.TextureOpCaps
& D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
))
10512 skip("L6V5U5 / D3DTOP_BUMPENVMAPLUMINANCE not supported, skipping tests.\n");
10513 IDirect3DVertexDeclaration9_Release(vertex_declaration
);
10514 IDirect3DDevice9_Release(device
);
10518 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x00000000, 1.0f
, 0);
10519 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
10520 /* This test only tests the luminance part. The bumpmapping part was already tested above and
10521 * would only make this test more complicated
10523 hr
= IDirect3DDevice9_CreateTexture(device
, 1, 1, 1, 0, D3DFMT_L6V5U5
, D3DPOOL_MANAGED
, &tex1
, NULL
);
10524 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture failed, hr=%08x\n", hr
);
10525 hr
= IDirect3DDevice9_CreateTexture(device
, 1, 1, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &tex2
, NULL
);
10526 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture failed, hr=%08x\n", hr
);
10528 memset(&locked_rect
, 0, sizeof(locked_rect
));
10529 hr
= IDirect3DTexture9_LockRect(tex1
, 0, &locked_rect
, NULL
, 0);
10530 ok(SUCCEEDED(hr
), "LockRect failed with 0x%08x\n", hr
);
10531 *((DWORD
*)locked_rect
.pBits
) = 0x4000; /* L = 0.25, V = 0.0, U = 0.0 */
10532 hr
= IDirect3DTexture9_UnlockRect(tex1
, 0);
10533 ok(SUCCEEDED(hr
), "UnlockRect failed with 0x%08x\n", hr
);
10535 memset(&locked_rect
, 0, sizeof(locked_rect
));
10536 hr
= IDirect3DTexture9_LockRect(tex2
, 0, &locked_rect
, NULL
, 0);
10537 ok(SUCCEEDED(hr
), "LockRect failed with 0x%08x\n", hr
);
10538 *((DWORD
*)locked_rect
.pBits
) = 0x00ff80c0;
10539 hr
= IDirect3DTexture9_UnlockRect(tex2
, 0);
10540 ok(SUCCEEDED(hr
), "UnlockRect failed with 0x%08x\n", hr
);
10542 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) tex1
);
10543 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTexture failed (%08x)\n", hr
);
10544 hr
= IDirect3DDevice9_SetTexture(device
, 1, (IDirect3DBaseTexture9
*) tex2
);
10545 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTexture failed (%08x)\n", hr
);
10547 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_BUMPENVMAPLUMINANCE
);
10548 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
10550 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_BUMPENVLSCALE
, *((DWORD
*)&scale
));
10551 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
10553 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_BUMPENVLOFFSET
, *((DWORD
*)&offset
));
10554 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
10556 hr
= IDirect3DDevice9_BeginScene(device
);
10557 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10558 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad
[0], sizeof(quad
[0]));
10559 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10560 hr
= IDirect3DDevice9_EndScene(device
);
10561 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10563 color
= getPixelColor(device
, 320, 240);
10564 /* red: 1.0 * (0.25 * 2.0 + 0.1) = 1.0 * 0.6 = 0.6 = 0x99
10565 * green: 0.5 * (0.25 * 2.0 + 0.1) = 0.5 * 0.6 = 0.3 = 0x4c
10566 * green: 0.75 * (0.25 * 2.0 + 0.1) = 0.75 * 0.6 = 0.45 = 0x72
10568 ok(color_match(color
, 0x00994c72, 5), "bumpmap failed: Got color 0x%08x, expected 0x00994c72.\n", color
);
10569 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
10570 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
10572 /* Check a result scale factor > 1.0 */
10574 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_BUMPENVLSCALE
, *((DWORD
*)&scale
));
10575 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
10577 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_BUMPENVLOFFSET
, *((DWORD
*)&offset
));
10578 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
10580 hr
= IDirect3DDevice9_BeginScene(device
);
10581 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10582 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad
[0], sizeof(quad
[0]));
10583 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10584 hr
= IDirect3DDevice9_EndScene(device
);
10585 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10587 color
= getPixelColor(device
, 320, 240);
10588 ok(color_match(color
, 0x00ff80c0, 1), "bumpmap failed: Got color 0x%08x, expected 0x00ff80c0.\n", color
);
10589 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
10590 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
10592 /* Check clamping in the scale factor calculation */
10594 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_BUMPENVLSCALE
, *((DWORD
*)&scale
));
10595 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
10597 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_BUMPENVLOFFSET
, *((DWORD
*)&offset
));
10598 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
10600 hr
= IDirect3DDevice9_BeginScene(device
);
10601 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10602 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad
[0], sizeof(quad
[0]));
10603 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10604 hr
= IDirect3DDevice9_EndScene(device
);
10605 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10607 color
= getPixelColor(device
, 320, 240);
10608 ok(color_match(color
, 0x00ff80c0, 1), "bumpmap failed: Got color 0x%08x, expected 0x00ff80c0.\n", color
);
10609 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
10610 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
10612 IDirect3DTexture9_Release(tex1
);
10613 IDirect3DTexture9_Release(tex2
);
10614 IDirect3DVertexDeclaration9_Release(vertex_declaration
);
10615 refcount
= IDirect3DDevice9_Release(device
);
10616 ok(!refcount
, "Device has %u references left.\n", refcount
);
10618 IDirect3D9_Release(d3d
);
10619 DestroyWindow(window
);
10622 static void stencil_cull_test(void)
10624 IDirect3DDevice9
*device
;
10630 static const float quad1
[] =
10637 static const float quad2
[] =
10644 static const float quad3
[] =
10651 static const float quad4
[] =
10660 struct vec3 position
;
10665 {{-1.0f
, -1.0f
, 0.0f
}, 0x00000000},
10666 {{ 1.0f
, -1.0f
, 0.0f
}, 0x00000000},
10667 {{-1.0f
, 1.0f
, 0.0f
}, 0x00000000},
10668 {{ 1.0f
, 1.0f
, 0.0f
}, 0x00000000},
10670 static const WORD indices_cw
[] = {0, 1, 3};
10671 static const WORD indices_ccw
[] = {0, 2, 3};
10675 window
= create_window();
10676 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
10677 ok(!!d3d
, "Failed to create a D3D object.\n");
10678 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
10680 skip("Cannot create a device with a D24S8 stencil buffer.\n");
10681 DestroyWindow(window
);
10682 IDirect3D9_Release(d3d
);
10685 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
10686 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
10687 if (!(caps
.StencilCaps
& D3DSTENCILCAPS_TWOSIDED
))
10689 skip("No two sided stencil support\n");
10693 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_STENCIL
, 0x00ff0000, 0.0, 0x8);
10694 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
10695 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
10696 ok(SUCCEEDED(hr
), "Failed to set FVF,hr %#x.\n", hr
);
10698 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_FALSE
);
10699 ok(hr
== D3D_OK
, "Failed to disable Z test, %#x.\n", hr
);
10700 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
10701 ok(hr
== D3D_OK
, "Failed to disable lighting, %#x.\n", hr
);
10702 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILFAIL
, D3DSTENCILOP_INCR
);
10703 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
10704 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILZFAIL
, D3DSTENCILOP_DECR
);
10705 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
10706 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILPASS
, D3DSTENCILOP_REPLACE
);
10707 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
10708 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILREF
, 0x3);
10709 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
10711 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CCW_STENCILFAIL
, D3DSTENCILOP_REPLACE
);
10712 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
10713 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CCW_STENCILZFAIL
, D3DSTENCILOP_DECR
);
10714 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
10715 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CCW_STENCILPASS
, D3DSTENCILOP_INCR
);
10716 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
10718 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILENABLE
, TRUE
);
10719 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
10720 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_TWOSIDEDSTENCILMODE
, FALSE
);
10721 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
10723 /* First pass: Fill the stencil buffer with some values... */
10724 hr
= IDirect3DDevice9_BeginScene(device
);
10725 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10727 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CULLMODE
, D3DCULL_CW
);
10728 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
10729 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
10730 1 /* PrimCount */, indices_cw
, D3DFMT_INDEX16
, quad1
, sizeof(float) * 3);
10731 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10732 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
10733 1 /* PrimCount */, indices_ccw
, D3DFMT_INDEX16
, quad1
, sizeof(float) * 3);
10734 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10736 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_TWOSIDEDSTENCILMODE
, TRUE
);
10737 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
10738 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CULLMODE
, D3DCULL_NONE
);
10739 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
10740 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
10741 1 /* PrimCount */, indices_cw
, D3DFMT_INDEX16
, quad2
, sizeof(float) * 3);
10742 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10743 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
10744 1 /* PrimCount */, indices_ccw
, D3DFMT_INDEX16
, quad2
, sizeof(float) * 3);
10745 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10747 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CULLMODE
, D3DCULL_CW
);
10748 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
10749 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
10750 1 /* PrimCount */, indices_cw
, D3DFMT_INDEX16
, quad3
, sizeof(float) * 3);
10751 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10752 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
10753 1 /* PrimCount */, indices_ccw
, D3DFMT_INDEX16
, quad3
, sizeof(float) * 3);
10754 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10756 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CULLMODE
, D3DCULL_CCW
);
10757 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
10758 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
10759 1 /* PrimCount */, indices_cw
, D3DFMT_INDEX16
, quad4
, sizeof(float) * 3);
10760 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10761 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
10762 1 /* PrimCount */, indices_ccw
, D3DFMT_INDEX16
, quad4
, sizeof(float) * 3);
10763 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10765 hr
= IDirect3DDevice9_EndScene(device
);
10766 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10768 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILZFAIL
, D3DSTENCILOP_KEEP
);
10769 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
10770 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILPASS
, D3DSTENCILOP_KEEP
);
10771 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
10772 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILFAIL
, D3DSTENCILOP_KEEP
);
10773 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
10774 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_TWOSIDEDSTENCILMODE
, FALSE
);
10775 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
10776 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CULLMODE
, D3DCULL_NONE
);
10777 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
10778 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILFUNC
, D3DCMP_EQUAL
);
10779 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
10781 /* 2nd pass: Make the stencil values visible */
10782 hr
= IDirect3DDevice9_BeginScene(device
);
10783 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10784 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
10785 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
10786 for (i
= 0; i
< 16; ++i
)
10788 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILREF
, i
);
10789 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
10791 painter
[0].diffuse
= (i
* 16); /* Creates shades of blue */
10792 painter
[1].diffuse
= (i
* 16);
10793 painter
[2].diffuse
= (i
* 16);
10794 painter
[3].diffuse
= (i
* 16);
10795 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, painter
, sizeof(painter
[0]));
10796 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10798 hr
= IDirect3DDevice9_EndScene(device
);
10799 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10801 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILENABLE
, FALSE
);
10802 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
10804 color
= getPixelColor(device
, 160, 420);
10805 ok(color
== 0x00000030, "CCW triangle, twoside FALSE, cull cw, replace, has color 0x%08x, expected 0x00000030\n", color
);
10806 color
= getPixelColor(device
, 160, 300);
10807 ok(color
== 0x00000080, "CW triangle, twoside FALSE, cull cw, culled, has color 0x%08x, expected 0x00000080\n", color
);
10809 color
= getPixelColor(device
, 480, 420);
10810 ok(color
== 0x00000090, "CCW triangle, twoside TRUE, cull off, incr, has color 0x%08x, expected 0x00000090\n", color
);
10811 color
= getPixelColor(device
, 480, 300);
10812 ok(color
== 0x00000030, "CW triangle, twoside TRUE, cull off, replace, has color 0x%08x, expected 0x00000030\n", color
);
10814 color
= getPixelColor(device
, 160, 180);
10815 ok(color
== 0x00000080, "CCW triangle, twoside TRUE, cull ccw, culled, has color 0x%08x, expected 0x00000080\n", color
);
10816 color
= getPixelColor(device
, 160, 60);
10817 ok(color
== 0x00000030, "CW triangle, twoside TRUE, cull ccw, replace, has color 0x%08x, expected 0x00000030\n", color
);
10819 color
= getPixelColor(device
, 480, 180);
10820 ok(color
== 0x00000090, "CCW triangle, twoside TRUE, cull cw, incr, has color 0x%08x, expected 0x00000090\n", color
);
10821 color
= getPixelColor(device
, 480, 60);
10822 ok(color
== 0x00000080, "CW triangle, twoside TRUE, cull cw, culled, has color 0x%08x, expected 0x00000080\n", color
);
10824 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
10825 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
10828 refcount
= IDirect3DDevice9_Release(device
);
10829 ok(!refcount
, "Device has %u references left.\n", refcount
);
10830 IDirect3D9_Release(d3d
);
10831 DestroyWindow(window
);
10834 static void test_fragment_coords(void)
10836 IDirect3DSurface9
*surface
= NULL
, *backbuffer
;
10837 IDirect3DPixelShader9
*shader
, *shader_frac
;
10838 IDirect3DVertexShader9
*vshader
;
10839 IDirect3DDevice9
*device
;
10849 static const DWORD shader_code
[] =
10851 0xffff0300, /* ps_3_0 */
10852 0x0200001f, 0x80000000, 0x90031000, /* dcl vPos.xy */
10853 0x03000002, 0x80030000, 0x90541000, 0xa1fe0000, /* sub r0.xy, vPos.xy, c0.zw */
10854 0x02000001, 0x800f0001, 0xa0e40000, /* mov r1, c0 */
10855 0x02000001, 0x80080002, 0xa0550000, /* mov r2.a, c0.y */
10856 0x02000001, 0x80010002, 0xa0550000, /* mov r2.r, c0.y */
10857 0x04000058, 0x80020002, 0x80000000, 0x80000001, 0x80550001, /* cmp r2.g, r0.x, r1.x, r1.y */
10858 0x04000058, 0x80040002, 0x80550000, 0x80000001, 0x80550001, /* cmp r2.b, r0.y, r1.x, r1.y */
10859 0x02000001, 0x800f0800, 0x80e40002, /* mov oC0, r2 */
10860 0x0000ffff /* end */
10862 static const DWORD shader_frac_code
[] =
10864 0xffff0300, /* ps_3_0 */
10865 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 0.0, 0.0, 0.0, 0.0 */
10866 0x0200001f, 0x80000000, 0x90031000, /* dcl vPos.xy */
10867 0x02000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
10868 0x02000013, 0x80030000, 0x90541000, /* frc r0.xy, vPos.xy */
10869 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
10870 0x0000ffff /* end */
10872 static const DWORD vshader_code
[] =
10874 0xfffe0300, /* vs_3_0 */
10875 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
10876 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
10877 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
10878 0x0000ffff /* end */
10880 static const float quad
[] =
10882 -1.0f
, -1.0f
, 0.1f
, 0.0f
, 0.0f
,
10883 -1.0f
, 1.0f
, 0.1f
, 0.0f
, 1.0f
,
10884 1.0f
, -1.0f
, 0.1f
, 1.0f
, 0.0f
,
10885 1.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
,
10887 float constant
[4] = {1.0, 0.0, 320, 240};
10889 window
= create_window();
10890 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
10891 ok(!!d3d
, "Failed to create a D3D object.\n");
10892 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
10894 skip("Failed to create a D3D device, skipping tests.\n");
10898 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
10899 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
10900 if (caps
.PixelShaderVersion
< D3DPS_VERSION(3, 0) || caps
.VertexShaderVersion
< D3DVS_VERSION(3, 0))
10902 skip("No shader model 3 support, skipping tests.\n");
10903 IDirect3DDevice9_Release(device
);
10907 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff0000ff, 1.0f
, 0);
10908 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr
);
10909 hr
= IDirect3DDevice9_CreateVertexShader(device
, vshader_code
, &vshader
);
10910 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader failed hr=%08x\n", hr
);
10911 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code
, &shader
);
10912 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader failed hr=%08x\n", hr
);
10913 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_frac_code
, &shader_frac
);
10914 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader failed hr=%08x\n", hr
);
10915 hr
= IDirect3DDevice9_SetPixelShader(device
, shader
);
10916 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader failed hr=%08x\n", hr
);
10917 hr
= IDirect3DDevice9_SetVertexShader(device
, vshader
);
10918 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader failed hr=%08x\n", hr
);
10919 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
10920 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed hr=%08x\n", hr
);
10921 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
10922 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetBackBuffer failed hr=%08x\n", hr
);
10924 hr
= IDirect3DDevice9_BeginScene(device
);
10925 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10926 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 0, constant
, 1);
10927 ok(SUCCEEDED(hr
), "Failed to set pixel shader constant, hr %#x.\n", hr
);
10928 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(float) * 5);
10929 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10930 hr
= IDirect3DDevice9_EndScene(device
);
10931 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10933 /* This has to be pixel exact */
10934 color
= getPixelColor(device
, 319, 239);
10935 ok(color
== 0x00000000, "vPos: Pixel 319,239 has color 0x%08x, expected 0x00000000\n", color
);
10936 color
= getPixelColor(device
, 320, 239);
10937 ok(color
== 0x0000ff00, "vPos: Pixel 320,239 has color 0x%08x, expected 0x0000ff00\n", color
);
10938 color
= getPixelColor(device
, 319, 240);
10939 ok(color
== 0x000000ff, "vPos: Pixel 319,240 has color 0x%08x, expected 0x000000ff\n", color
);
10940 color
= getPixelColor(device
, 320, 240);
10941 ok(color
== 0x0000ffff, "vPos: Pixel 320,240 has color 0x%08x, expected 0x0000ffff\n", color
);
10942 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
10944 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 32, 32, D3DFMT_X8R8G8B8
, 0, 0, TRUE
,
10946 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateRenderTarget failed hr=%08x\n", hr
);
10947 hr
= IDirect3DDevice9_BeginScene(device
);
10948 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10949 constant
[2] = 16; constant
[3] = 16;
10950 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 0, constant
, 1);
10951 ok(SUCCEEDED(hr
), "Failed to set pixel shader constant, hr %#x.\n", hr
);
10952 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, surface
);
10953 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
10954 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(float) * 5);
10955 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10956 hr
= IDirect3DDevice9_EndScene(device
);
10957 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10959 hr
= IDirect3DSurface9_LockRect(surface
, &lr
, NULL
, D3DLOCK_READONLY
);
10960 ok(hr
== D3D_OK
, "IDirect3DSurface9_LockRect failed, hr=%08x\n", hr
);
10962 pos
= (DWORD
*) (((BYTE
*) lr
.pBits
) + 14 * lr
.Pitch
+ 14 * sizeof(DWORD
));
10963 color
= *pos
& 0x00ffffff;
10964 ok(color
== 0x00000000, "Pixel 14/14 has color 0x%08x, expected 0x00000000\n", color
);
10965 pos
= (DWORD
*) (((BYTE
*) lr
.pBits
) + 14 * lr
.Pitch
+ 18 * sizeof(DWORD
));
10966 color
= *pos
& 0x00ffffff;
10967 ok(color
== 0x0000ff00, "Pixel 14/18 has color 0x%08x, expected 0x0000ff00\n", color
);
10968 pos
= (DWORD
*) (((BYTE
*) lr
.pBits
) + 18 * lr
.Pitch
+ 14 * sizeof(DWORD
));
10969 color
= *pos
& 0x00ffffff;
10970 ok(color
== 0x000000ff, "Pixel 18/14 has color 0x%08x, expected 0x000000ff\n", color
);
10971 pos
= (DWORD
*) (((BYTE
*) lr
.pBits
) + 18 * lr
.Pitch
+ 18 * sizeof(DWORD
));
10972 color
= *pos
& 0x00ffffff;
10973 ok(color
== 0x0000ffff, "Pixel 18/18 has color 0x%08x, expected 0x0000ffff\n", color
);
10975 hr
= IDirect3DSurface9_UnlockRect(surface
);
10976 ok(hr
== D3D_OK
, "IDirect3DSurface9_UnlockRect failed, hr=%08x\n", hr
);
10978 /* Test the fraction value of vPos. This is tested with the offscreen target and not the backbuffer to
10979 * have full control over the multisampling setting inside this test
10981 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_frac
);
10982 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader failed hr=%08x\n", hr
);
10983 hr
= IDirect3DDevice9_BeginScene(device
);
10984 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10985 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff0000ff, 0.0, 0);
10986 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
10987 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(float) * 5);
10988 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10989 hr
= IDirect3DDevice9_EndScene(device
);
10990 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10992 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
10993 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderTarget failed, hr=%08x\n", hr
);
10995 hr
= IDirect3DSurface9_LockRect(surface
, &lr
, NULL
, D3DLOCK_READONLY
);
10996 ok(hr
== D3D_OK
, "IDirect3DSurface9_LockRect failed, hr=%08x\n", hr
);
10998 pos
= (DWORD
*) (((BYTE
*) lr
.pBits
) + 14 * lr
.Pitch
+ 14 * sizeof(DWORD
));
10999 color
= *pos
& 0x00ffffff;
11000 ok(color
== 0x00000000, "vPos fraction test has color 0x%08x, expected 0x00000000\n", color
);
11002 hr
= IDirect3DSurface9_UnlockRect(surface
);
11003 ok(hr
== D3D_OK
, "IDirect3DSurface9_UnlockRect failed, hr=%08x\n", hr
);
11005 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
11006 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader failed hr=%08x\n", hr
);
11007 hr
= IDirect3DDevice9_SetVertexShader(device
, NULL
);
11008 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader failed hr=%08x\n", hr
);
11009 IDirect3DPixelShader9_Release(shader
);
11010 IDirect3DPixelShader9_Release(shader_frac
);
11011 IDirect3DVertexShader9_Release(vshader
);
11012 if(surface
) IDirect3DSurface9_Release(surface
);
11013 IDirect3DSurface9_Release(backbuffer
);
11014 refcount
= IDirect3DDevice9_Release(device
);
11015 ok(!refcount
, "Device has %u references left.\n", refcount
);
11017 IDirect3D9_Release(d3d
);
11018 DestroyWindow(window
);
11021 static BOOL
point_match(IDirect3DDevice9
*device
, UINT x
, UINT y
, UINT r
)
11025 color
= D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0xff);
11026 if (!color_match(getPixelColor(device
, x
+ r
, y
), color
, 1)) return FALSE
;
11027 if (!color_match(getPixelColor(device
, x
- r
, y
), color
, 1)) return FALSE
;
11028 if (!color_match(getPixelColor(device
, x
, y
+ r
), color
, 1)) return FALSE
;
11029 if (!color_match(getPixelColor(device
, x
, y
- r
), color
, 1)) return FALSE
;
11032 color
= D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0xff);
11033 if (!color_match(getPixelColor(device
, x
+ r
, y
), color
, 1)) return FALSE
;
11034 if (!color_match(getPixelColor(device
, x
- r
, y
), color
, 1)) return FALSE
;
11035 if (!color_match(getPixelColor(device
, x
, y
+ r
), color
, 1)) return FALSE
;
11036 if (!color_match(getPixelColor(device
, x
, y
- r
), color
, 1)) return FALSE
;
11041 static void test_pointsize(void)
11043 static const float a
= 1.0f
, b
= 1.0f
, c
= 1.0f
;
11044 float ptsize
, ptsizemax_orig
, ptsizemin_orig
;
11045 IDirect3DSurface9
*rt
, *backbuffer
;
11046 IDirect3DTexture9
*tex1
, *tex2
;
11047 IDirect3DDevice9
*device
;
11048 IDirect3DVertexShader9
*vs
;
11049 IDirect3DPixelShader9
*ps
;
11059 static const RECT rect
= {0, 0, 128, 128};
11060 static const DWORD tex1_data
[4] = {0x00ff0000, 0x00ff0000, 0x00000000, 0x00000000};
11061 static const DWORD tex2_data
[4] = {0x00000000, 0x0000ff00, 0x00000000, 0x0000ff00};
11062 static const float vertices
[] =
11064 64.0f
, 64.0f
, 0.1f
,
11065 128.0f
, 64.0f
, 0.1f
,
11066 192.0f
, 64.0f
, 0.1f
,
11067 256.0f
, 64.0f
, 0.1f
,
11068 320.0f
, 64.0f
, 0.1f
,
11069 384.0f
, 64.0f
, 0.1f
,
11070 448.0f
, 64.0f
, 0.1f
,
11071 512.0f
, 64.0f
, 0.1f
,
11073 static const struct
11078 vertex_pointsize
= {64.0f
, 64.0f
, 0.1f
, 48.0f
},
11079 vertex_pointsize_scaled
= {64.0f
, 64.0f
, 0.1f
, 24.0f
},
11080 vertex_pointsize_zero
= {64.0f
, 64.0f
, 0.1f
, 0.0f
};
11081 /* Writing a texture coordinate from the shader is technically unnecessary, but is required
11082 * to make Windows AMD r500 drivers work. Without it, texture coordinates in the pixel
11083 * shaders are 0. */
11084 static const DWORD vshader_code
[] =
11086 0xfffe0101, /* vs_1_1 */
11087 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
11088 0x00000005, 0x800f0000, 0x90000000, 0xa0e40000, /* mul r0, v0.x, c0 */
11089 0x00000004, 0x800f0000, 0x90550000, 0xa0e40001, 0x80e40000, /* mad r0, v0.y, c1, r0 */
11090 0x00000004, 0x800f0000, 0x90aa0000, 0xa0e40002, 0x80e40000, /* mad r0, v0.z, c2, r0 */
11091 0x00000004, 0xc00f0000, 0x90ff0000, 0xa0e40003, 0x80e40000, /* mad oPos, v0.w, c3, r0 */
11092 0x00000001, 0xe00f0000, 0x90e40000, /* mov oT0, v0 */
11093 0x00000001, 0xe00f0001, 0x90e40000, /* mov oT1, v0 */
11096 static const DWORD vshader_psize_code
[] =
11098 0xfffe0101, /* vs_1_1 */
11099 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
11100 0x0000001f, 0x80000004, 0x900f0001, /* dcl_psize v1 */
11101 0x00000005, 0x800f0000, 0x90000000, 0xa0e40000, /* mul r0, v0.x, c0 */
11102 0x00000004, 0x800f0000, 0x90550000, 0xa0e40001, 0x80e40000, /* mad r0, v0.y, c1, r0 */
11103 0x00000004, 0x800f0000, 0x90aa0000, 0xa0e40002, 0x80e40000, /* mad r0, v0.z, c2, r0 */
11104 0x00000004, 0xc00f0000, 0x90ff0000, 0xa0e40003, 0x80e40000, /* mad oPos, v0.w, c3, r0 */
11105 0x00000001, 0xc00f0002, 0x90000001, /* mov oPts, v1.x */
11106 0x00000001, 0xe00f0000, 0x90e40000, /* mov oT0, v0 */
11107 0x00000001, 0xe00f0001, 0x90e40000, /* mov oT1, v0 */
11110 static const DWORD pshader_code
[] =
11112 0xffff0101, /* ps_1_1 */
11113 0x00000042, 0xb00f0000, /* tex t0 */
11114 0x00000042, 0xb00f0001, /* tex t1 */
11115 0x00000002, 0x800f0000, 0xb0e40000, 0xb0e40001, /* add r0, t0, t1 */
11118 static const DWORD pshader2_code
[] =
11120 0xffff0200, /* ps_2_0 */
11121 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
11122 0x0200001f, 0x80000000, 0xb00f0001, /* dcl t1 */
11123 0x0200001f, 0x90000000, 0xa00f0800, /* dcl_2d s0 */
11124 0x0200001f, 0x90000000, 0xa00f0801, /* dcl_2d s1 */
11125 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texld r0, t0, s0 */
11126 0x03000042, 0x800f0001, 0xb0e40001, 0xa0e40801, /* texld r1, t1, s1 */
11127 0x03000002, 0x800f0000, 0x80e40000, 0x80e40001, /* add r0, r0, r1 */
11128 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
11131 static const DWORD pshader2_zw_code
[] =
11133 0xffff0200, /* ps_2_0 */
11134 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
11135 0x0200001f, 0x80000000, 0xb00f0001, /* dcl t1 */
11136 0x0200001f, 0x90000000, 0xa00f0800, /* dcl_2d s0 */
11137 0x0200001f, 0x90000000, 0xa00f0801, /* dcl_2d s1 */
11138 0x02000001, 0x80030000, 0xb01b0000, /* mov r0.xy, t0.wzyx */
11139 0x02000001, 0x80030001, 0xb01b0001, /* mov r1.xy, t1.wzyx */
11140 0x03000042, 0x800f0000, 0x80e40000, 0xa0e40800, /* texld r0, r0, s0 */
11141 0x03000042, 0x800f0001, 0x80e40001, 0xa0e40801, /* texld r1, r1, s1 */
11142 0x03000002, 0x800f0000, 0x80e40000, 0x80e40001, /* add r0, r0, r1 */
11143 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
11146 static const DWORD vshader3_code
[] =
11148 0xfffe0300, /* vs_3_0 */
11149 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
11150 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
11151 0x0200001f, 0x80000005, 0xe00f0001, /* dcl_texcoord0 o1 */
11152 0x0200001f, 0x80010005, 0xe00f0002, /* dcl_texcoord1 o2 */
11153 0x03000005, 0x800f0000, 0x90000000, 0xa0e40000, /* mul r0, v0.x, c0 */
11154 0x04000004, 0x800f0000, 0x90550000, 0xa0e40001, 0x80e40000, /* mad r0, v0.y, c1, r0 */
11155 0x04000004, 0x800f0000, 0x90aa0000, 0xa0e40002, 0x80e40000, /* mad r0, v0.z, c2, r0 */
11156 0x04000004, 0xe00f0000, 0x90ff0000, 0xa0e40003, 0x80e40000, /* mad o0, v0.w, c3, r0 */
11157 0x02000001, 0xe00f0001, 0x90000000, /* mov o1, v0.x */
11158 0x02000001, 0xe00f0002, 0x90000000, /* mov o2, v0.x */
11161 static const DWORD vshader3_psize_code
[] =
11163 0xfffe0300, /* vs_3_0 */
11164 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
11165 0x0200001f, 0x80000004, 0x90010001, /* dcl_psize v1.x */
11166 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
11167 0x0200001f, 0x80000004, 0xe00f0001, /* dcl_psize o1 */
11168 0x0200001f, 0x80000005, 0xe00f0002, /* dcl_texcoord0 o2 */
11169 0x0200001f, 0x80010005, 0xe00f0003, /* dcl_texcoord1 o3 */
11170 0x03000005, 0x800f0000, 0x90000000, 0xa0e40000, /* mul r0, v0.x, c0 */
11171 0x04000004, 0x800f0000, 0x90550000, 0xa0e40001, 0x80e40000, /* mad r0, v0.y, c1, r0 */
11172 0x04000004, 0x800f0000, 0x90aa0000, 0xa0e40002, 0x80e40000, /* mad r0, v0.z, c2, r0 */
11173 0x04000004, 0xe00f0000, 0x90ff0000, 0xa0e40003, 0x80e40000, /* mad o0, v0.w, c3, r0 */
11174 0x02000001, 0xe00f0001, 0x90000001, /* mov o1, v1.x */
11175 0x02000001, 0xe00f0002, 0x90000000, /* mov o2, v0.x */
11176 0x02000001, 0xe00f0003, 0x90000000, /* mov o3, v0.x */
11179 static const DWORD pshader3_code
[] =
11181 0xffff0300, /* ps_3_0 */
11182 0x0200001f, 0x80000005, 0x900f0000, /* dcl_texcoord0 v0 */
11183 0x0200001f, 0x80010005, 0x900f0001, /* dcl_texcoord1 v1 */
11184 0x0200001f, 0x90000000, 0xa00f0800, /* dcl_2d s0 */
11185 0x0200001f, 0x90000000, 0xa00f0801, /* dcl_2d s1 */
11186 0x03000042, 0x800f0000, 0x90e40000, 0xa0e40800, /* texld r0, v0, s0 */
11187 0x03000042, 0x800f0001, 0x90e40001, 0xa0e40801, /* texld r1, v1, s1 */
11188 0x03000002, 0x800f0800, 0x80e40000, 0x80e40001, /* add oC0, r0, r1 */
11191 static const DWORD pshader3_zw_code
[] =
11193 0xffff0300, /* ps_3_0 */
11194 0x0200001f, 0x80000005, 0x900f0000, /* dcl_texcoord0 v0 */
11195 0x0200001f, 0x80010005, 0x900f0001, /* dcl_texcoord1 v1 */
11196 0x0200001f, 0x90000000, 0xa00f0800, /* dcl_2d s0 */
11197 0x0200001f, 0x90000000, 0xa00f0801, /* dcl_2d s1 */
11198 0x03000042, 0x800f0000, 0x90fe0000, 0xa0e40800, /* texld r0, v0.zw, s0 */
11199 0x03000042, 0x800f0001, 0x90fe0001, 0xa0e40801, /* texld r1, v1.zw, s1 */
11200 0x03000002, 0x800f0800, 0x80e40000, 0x80e40001, /* add oC0, r0, r1 */
11203 static const struct test_shader
11209 vs1
= {D3DVS_VERSION(1, 1), vshader_code
},
11210 vs1_psize
= {D3DVS_VERSION(1, 1), vshader_psize_code
},
11211 vs3
= {D3DVS_VERSION(3, 0), vshader3_code
},
11212 vs3_psize
= {D3DVS_VERSION(3, 0), vshader3_psize_code
},
11214 ps1
= {D3DPS_VERSION(1, 1), pshader_code
},
11215 ps2
= {D3DPS_VERSION(2, 0), pshader2_code
},
11216 ps2_zw
= {D3DPS_VERSION(2, 0), pshader2_zw_code
},
11217 ps3
= {D3DPS_VERSION(3, 0), pshader3_code
},
11218 ps3_zw
= {D3DPS_VERSION(3, 0), pshader3_zw_code
};
11219 static const struct
11221 const struct test_shader
*vs
;
11222 const struct test_shader
*ps
;
11223 DWORD accepted_fvf
;
11224 unsigned int nonscaled_size
, scaled_size
;
11225 BOOL gives_0_0_texcoord
;
11230 {&novs
, &nops
, D3DFVF_XYZ
, 32, 45, FALSE
, FALSE
},
11231 {&vs1
, &ps1
, D3DFVF_XYZ
, 32, 32, FALSE
, FALSE
},
11232 {&novs
, &ps1
, D3DFVF_XYZ
, 32, 45, FALSE
, FALSE
},
11233 {&vs1
, &nops
, D3DFVF_XYZ
, 32, 32, FALSE
, FALSE
},
11234 {&novs
, &ps2
, D3DFVF_XYZ
, 32, 45, FALSE
, TRUE
},
11235 {&novs
, &ps2_zw
, D3DFVF_XYZ
, 32, 45, TRUE
, FALSE
},
11236 {&vs1
, &ps2
, D3DFVF_XYZ
, 32, 32, FALSE
, TRUE
},
11237 {&vs1
, &ps2_zw
, D3DFVF_XYZ
, 32, 32, TRUE
, FALSE
},
11238 {&vs3
, &ps3
, D3DFVF_XYZ
, 32, 32, FALSE
, TRUE
},
11239 {&vs3
, &ps3_zw
, D3DFVF_XYZ
, 32, 32, TRUE
, FALSE
},
11240 {&novs
, &nops
, D3DFVF_XYZ
| D3DFVF_PSIZE
, 48, 33, FALSE
, FALSE
},
11241 {&vs1_psize
, &ps1
, D3DFVF_XYZ
| D3DFVF_PSIZE
, 48, 24, FALSE
, FALSE
},
11242 {&vs3_psize
, &ps3
, D3DFVF_XYZ
| D3DFVF_PSIZE
, 48, 24, FALSE
, TRUE
},
11244 static const struct
11250 const void *vertex_data
;
11251 unsigned int vertex_size
;
11255 {FALSE
, FALSE
, FALSE
, D3DFVF_XYZ
, vertices
, sizeof(float) * 3},
11256 {FALSE
, TRUE
, FALSE
, D3DFVF_XYZ
, vertices
, sizeof(float) * 3},
11257 {FALSE
, FALSE
, TRUE
, D3DFVF_XYZ
, vertices
, sizeof(float) * 3},
11258 {TRUE
, FALSE
, FALSE
, D3DFVF_XYZ
, vertices
, sizeof(float) * 3},
11259 {FALSE
, FALSE
, FALSE
, D3DFVF_XYZ
| D3DFVF_PSIZE
, &vertex_pointsize
, sizeof(vertex_pointsize
)},
11260 {FALSE
, TRUE
, FALSE
, D3DFVF_XYZ
| D3DFVF_PSIZE
, &vertex_pointsize_scaled
, sizeof(vertex_pointsize_scaled
)},
11261 {FALSE
, FALSE
, TRUE
, D3DFVF_XYZ
| D3DFVF_PSIZE
, &vertex_pointsize
, sizeof(vertex_pointsize
)},
11262 {TRUE
, FALSE
, FALSE
, D3DFVF_XYZ
| D3DFVF_PSIZE
, &vertex_pointsize_zero
, sizeof(vertex_pointsize_zero
)},
11264 /* Transforms the coordinate system [-1.0;1.0]x[1.0;-1.0] to
11265 * [0.0;0.0]x[640.0;480.0]. Z is untouched. */
11268 2.0f
/ 640.0f
, 0.0f
, 0.0f
, 0.0f
,
11269 0.0f
, -2.0f
/ 480.0f
, 0.0f
, 0.0f
,
11270 0.0f
, 0.0f
, 1.0f
, 0.0f
,
11271 -1.0f
, 1.0f
, 0.0f
, 1.0f
,
11274 window
= create_window();
11275 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
11276 ok(!!d3d
, "Failed to create a D3D object.\n");
11277 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
11279 skip("Failed to create a D3D device, skipping tests.\n");
11283 memset(&caps
, 0, sizeof(caps
));
11284 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
11285 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetDeviceCaps failed hr=%08x\n", hr
);
11286 if(caps
.MaxPointSize
< 32.0) {
11287 skip("MaxPointSize < 32.0, skipping(MaxPointsize = %f)\n", caps
.MaxPointSize
);
11288 IDirect3DDevice9_Release(device
);
11292 /* The r500 Windows driver needs a draw with regular texture coordinates at least once during the
11293 * device's lifetime, otherwise texture coordinate generation only works for texture 0. */
11294 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
11295 ok(SUCCEEDED(hr
), "Failed to set FVF, hr=%#x.\n", hr
);
11296 hr
= IDirect3DDevice9_BeginScene(device
);
11297 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
11298 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_POINTLIST
, 1, vertices
, sizeof(float) * 5);
11299 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11300 hr
= IDirect3DDevice9_EndScene(device
);
11301 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
11303 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff0000ff, 1.0f
, 0);
11304 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr
);
11305 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
11306 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
11307 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_PROJECTION
, &matrix
);
11308 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed, hr=%08x\n", hr
);
11309 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
11310 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed hr=%08x\n", hr
);
11312 hr
= IDirect3DDevice9_BeginScene(device
);
11313 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
11316 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSIZE
, *(DWORD
*)&ptsize
);
11317 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
11318 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_POINTLIST
, 1, &vertices
[0], sizeof(float) * 3);
11319 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11322 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSIZE
, *(DWORD
*)&ptsize
);
11323 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
11324 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_POINTLIST
, 1, &vertices
[3], sizeof(float) * 3);
11325 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11328 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSIZE
, *(DWORD
*)&ptsize
);
11329 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
11330 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_POINTLIST
, 1, &vertices
[6], sizeof(float) * 3);
11331 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11333 if (caps
.MaxPointSize
>= 63.0f
)
11336 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSIZE
, *(DWORD
*)&ptsize
);
11337 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
11338 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_POINTLIST
, 1, &vertices
[9], sizeof(float) * 3);
11339 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11342 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSIZE
, *(DWORD
*)&ptsize
);
11343 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
11344 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_POINTLIST
, 1, &vertices
[15], sizeof(float) * 3);
11345 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11349 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSIZE
, *(DWORD
*)&ptsize
);
11350 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
11351 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_POINTLIST
, 1, &vertices
[12], sizeof(float) * 3);
11352 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11354 hr
= IDirect3DDevice9_GetRenderState(device
, D3DRS_POINTSIZE_MAX
, (DWORD
*)&ptsizemax_orig
);
11355 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
11356 hr
= IDirect3DDevice9_GetRenderState(device
, D3DRS_POINTSIZE_MIN
, (DWORD
*)&ptsizemin_orig
);
11357 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
11359 /* What happens if point scaling is disabled, and POINTSIZE_MAX < POINTSIZE? */
11361 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSIZE
, *(DWORD
*)&ptsize
);
11362 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
11364 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSIZE_MAX
, *(DWORD
*)&ptsize
);
11365 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
11366 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_POINTLIST
, 1, &vertices
[18], sizeof(float) * 3);
11367 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11369 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSIZE_MAX
, *(DWORD
*)&ptsizemax_orig
);
11370 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
11372 /* pointsize < pointsize_min < pointsize_max?
11373 * pointsize = 1.0, pointsize_min = 15.0, pointsize_max = default(usually 64.0) */
11375 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSIZE
, *(DWORD
*)&ptsize
);
11376 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
11378 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSIZE_MIN
, *(DWORD
*)&ptsize
);
11379 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
11380 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_POINTLIST
, 1, &vertices
[21], sizeof(float) * 3);
11381 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11383 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSIZE_MIN
, *(DWORD
*)&ptsizemin_orig
);
11384 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
11386 hr
= IDirect3DDevice9_EndScene(device
);
11387 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
11389 ok(point_match(device
, 64, 64, 7), "point_match(64, 64, 7) failed, expected point size 15.\n");
11390 ok(point_match(device
, 128, 64, 15), "point_match(128, 64, 15) failed, expected point size 31.\n");
11391 ok(point_match(device
, 192, 64, 15), "point_match(192, 64, 15) failed, expected point size 31.\n");
11393 if (caps
.MaxPointSize
>= 63.0)
11395 ok(point_match(device
, 256, 64, 31), "point_match(256, 64, 31) failed, expected point size 63.\n");
11396 ok(point_match(device
, 384, 64, 31), "point_match(384, 64, 31) failed, expected point size 63.\n");
11399 ok(point_match(device
, 320, 64, 0), "point_match(320, 64, 0) failed, expected point size 1.\n");
11400 /* ptsize = 15, ptsize_max = 1 --> point has size 1 */
11401 ok(point_match(device
, 448, 64, 0), "point_match(448, 64, 0) failed, expected point size 1.\n");
11402 /* ptsize = 1, ptsize_max = default(64), ptsize_min = 15 --> point has size 15 */
11403 ok(point_match(device
, 512, 64, 7), "point_match(512, 64, 7) failed, expected point size 15.\n");
11405 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
11407 /* The following code tests point sprites with two textures, to see if each texture coordinate unit
11408 * generates texture coordinates for the point(result: Yes, it does)
11410 * However, not all GL implementations support point sprites(they need GL_ARB_point_sprite), but there
11411 * is no point sprite cap bit in d3d because native d3d software emulates point sprites. Until the
11412 * SW emulation is implemented in wined3d, this test will fail on GL drivers that does not support them.
11414 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff0000ff, 1.0f
, 0);
11415 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr
);
11417 hr
= IDirect3DDevice9_CreateTexture(device
, 2, 2, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &tex1
, NULL
);
11418 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture failed hr=%08x\n", hr
);
11419 hr
= IDirect3DDevice9_CreateTexture(device
, 2, 2, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &tex2
, NULL
);
11420 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture failed hr=%08x\n", hr
);
11421 memset(&lr
, 0, sizeof(lr
));
11422 hr
= IDirect3DTexture9_LockRect(tex1
, 0, &lr
, NULL
, 0);
11423 ok(hr
== D3D_OK
, "IDirect3DTexture9_LockRect failed hr=%08x\n", hr
);
11424 memcpy(lr
.pBits
, tex1_data
, sizeof(tex1_data
));
11425 hr
= IDirect3DTexture9_UnlockRect(tex1
, 0);
11426 ok(hr
== D3D_OK
, "IDirect3DTexture9_UnlockRect failed hr=%08x\n", hr
);
11427 memset(&lr
, 0, sizeof(lr
));
11428 hr
= IDirect3DTexture9_LockRect(tex2
, 0, &lr
, NULL
, 0);
11429 ok(hr
== D3D_OK
, "IDirect3DTexture9_LockRect failed hr=%08x\n", hr
);
11430 memcpy(lr
.pBits
, tex2_data
, sizeof(tex2_data
));
11431 hr
= IDirect3DTexture9_UnlockRect(tex2
, 0);
11432 ok(hr
== D3D_OK
, "IDirect3DTexture9_UnlockRect failed hr=%08x\n", hr
);
11433 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) tex1
);
11434 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture failed hr=%08x\n", hr
);
11435 hr
= IDirect3DDevice9_SetTexture(device
, 1, (IDirect3DBaseTexture9
*) tex2
);
11436 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture failed hr=%08x\n", hr
);
11437 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
11438 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed hr=%08x\n", hr
);
11439 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
11440 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed hr=%08x\n", hr
);
11441 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_ADD
);
11442 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed hr=%08x\n", hr
);
11443 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
11444 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed hr=%08x\n", hr
);
11445 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLORARG2
, D3DTA_CURRENT
);
11446 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed hr=%08x\n", hr
);
11448 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSPRITEENABLE
, TRUE
);
11449 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed hr=%08x\n", hr
);
11451 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSIZE
, *((DWORD
*) (&ptsize
)));
11452 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed, hr=%08x\n", hr
);
11454 hr
= IDirect3DDevice9_BeginScene(device
);
11455 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
11456 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_POINTLIST
, 1, &vertices
[0], sizeof(float) * 3);
11457 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11458 hr
= IDirect3DDevice9_EndScene(device
);
11459 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
11461 color
= getPixelColor(device
, 64-4, 64-4);
11462 ok(color
== 0x00ff0000, "pSprite: Pixel (64-4),(64-4) has color 0x%08x, expected 0x00ff0000\n", color
);
11463 color
= getPixelColor(device
, 64-4, 64+4);
11464 ok(color
== 0x00000000, "pSprite: Pixel (64-4),(64+4) has color 0x%08x, expected 0x00000000\n", color
);
11465 color
= getPixelColor(device
, 64+4, 64+4);
11466 ok(color
== 0x0000ff00, "pSprite: Pixel (64+4),(64+4) has color 0x%08x, expected 0x0000ff00\n", color
);
11467 color
= getPixelColor(device
, 64+4, 64-4);
11468 ok(color
== 0x00ffff00, "pSprite: Pixel (64+4),(64-4) has color 0x%08x, expected 0x00ffff00\n", color
);
11469 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
11471 U(matrix
).m
[0][0] = 1.0f
/ 64.0f
;
11472 U(matrix
).m
[1][1] = -1.0f
/ 64.0f
;
11473 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_PROJECTION
, &matrix
);
11474 ok(SUCCEEDED(hr
), "SetTransform failed, hr %#x.\n", hr
);
11476 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &backbuffer
);
11477 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
11479 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 128, 128, D3DFMT_A8R8G8B8
,
11480 D3DMULTISAMPLE_NONE
, 0, TRUE
, &rt
, NULL
);
11481 ok(SUCCEEDED(hr
), "CreateRenderTarget failed, hr %#x.\n", hr
);
11483 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSCALE_A
, *(DWORD
*)&a
);
11484 ok(SUCCEEDED(hr
), "Failed setting point scale attenuation coefficient, hr %#x.\n", hr
);
11485 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSCALE_B
, *(DWORD
*)&b
);
11486 ok(SUCCEEDED(hr
), "Failed setting point scale attenuation coefficient, hr %#x.\n", hr
);
11487 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSCALE_C
, *(DWORD
*)&c
);
11488 ok(SUCCEEDED(hr
), "Failed setting point scale attenuation coefficient, hr %#x.\n", hr
);
11489 if (caps
.VertexShaderVersion
>= D3DVS_VERSION(1, 1))
11491 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 0, &S(U(matrix
))._11
, 4);
11492 ok(SUCCEEDED(hr
), "Failed to set vertex shader constants, hr %#x.\n", hr
);
11495 if (caps
.MaxPointSize
< 63.0f
)
11497 skip("MaxPointSize %f < 63.0, skipping some tests.\n", caps
.MaxPointSize
);
11501 for (i
= 0; i
< ARRAY_SIZE(test_setups
); ++i
)
11503 if (caps
.VertexShaderVersion
< test_setups
[i
].vs
->version
11504 || caps
.PixelShaderVersion
< test_setups
[i
].ps
->version
)
11506 skip("Vertex / pixel shader version not supported, skipping test.\n");
11509 if (test_setups
[i
].vs
->code
)
11511 hr
= IDirect3DDevice9_CreateVertexShader(device
, test_setups
[i
].vs
->code
, &vs
);
11512 ok(SUCCEEDED(hr
), "Failed to create vertex shader, hr %#x (case %u).\n", hr
, i
);
11518 if (test_setups
[i
].ps
->code
)
11520 hr
= IDirect3DDevice9_CreatePixelShader(device
, test_setups
[i
].ps
->code
, &ps
);
11521 ok(SUCCEEDED(hr
), "Failed to create pixel shader, hr %#x (case %u).\n", hr
, i
);
11528 hr
= IDirect3DDevice9_SetVertexShader(device
, vs
);
11529 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
11530 hr
= IDirect3DDevice9_SetPixelShader(device
, ps
);
11531 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
11533 for (j
= 0; j
< ARRAY_SIZE(tests
); ++j
)
11535 BOOL allow_broken
= test_setups
[i
].allow_broken
;
11536 unsigned int size
= tests
[j
].override_min
? 63 : tests
[j
].zero_size
? 0 : tests
[j
].scale
11537 ? test_setups
[i
].scaled_size
: test_setups
[i
].nonscaled_size
;
11539 if (test_setups
[i
].accepted_fvf
!= tests
[j
].fvf
)
11542 ptsize
= tests
[j
].zero_size
? 0.0f
: 32.0f
;
11543 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSIZE
, *(DWORD
*)&ptsize
);
11544 ok(SUCCEEDED(hr
), "Failed to set pointsize, hr %#x.\n", hr
);
11546 ptsize
= tests
[j
].override_min
? 63.0f
: tests
[j
].zero_size
? 0.0f
: ptsizemin_orig
;
11547 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSIZE_MIN
, *(DWORD
*)&ptsize
);
11548 ok(SUCCEEDED(hr
), "Failed to set minimum pointsize, hr %#x.\n", hr
);
11550 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSCALEENABLE
, tests
[j
].scale
);
11551 ok(SUCCEEDED(hr
), "Failed setting point scale state, hr %#x.\n", hr
);
11553 hr
= IDirect3DDevice9_SetFVF(device
, tests
[j
].fvf
);
11554 ok(SUCCEEDED(hr
), "Failed setting FVF, hr %#x.\n", hr
);
11556 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt
);
11557 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
11558 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff00ffff, 1.0f
, 0);
11559 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
11561 hr
= IDirect3DDevice9_BeginScene(device
);
11562 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
11563 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_POINTLIST
, 1,
11564 tests
[j
].vertex_data
, tests
[j
].vertex_size
);
11565 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11566 hr
= IDirect3DDevice9_EndScene(device
);
11567 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
11569 hr
= IDirect3DDevice9_StretchRect(device
, rt
, &rect
, backbuffer
, &rect
, D3DTEXF_NONE
);
11570 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
11571 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
11572 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
11574 if (tests
[j
].zero_size
)
11576 /* Technically 0 pointsize is undefined in OpenGL but in practice it seems like
11577 * it does the "useful" thing on all the drivers I tried. */
11578 /* On WARP it does draw some pixels, most of the time. */
11579 color
= getPixelColor(device
, 64, 64);
11580 ok(color_match(color
, 0x0000ffff, 0)
11581 || broken(color_match(color
, 0x00ff0000, 0))
11582 || broken(color_match(color
, 0x00ffff00, 0))
11583 || broken(color_match(color
, 0x00000000, 0))
11584 || broken(color_match(color
, 0x0000ff00, 0)),
11585 "Got unexpected color 0x%08x (case %u, %u, size %u).\n", color
, i
, j
, size
);
11589 struct surface_readback rb
;
11591 get_rt_readback(backbuffer
, &rb
);
11592 /* On AMD apparently only the first texcoord is modified by the point coordinates
11593 * when using SM2/3 pixel shaders. */
11594 color
= get_readback_color(&rb
, 64 - size
/ 2 + 1, 64 - size
/ 2 + 1);
11595 ok(color_match(color
, 0x00ff0000, 0),
11596 "Got unexpected color 0x%08x (case %u, %u, size %u).\n", color
, i
, j
, size
);
11597 color
= get_readback_color(&rb
, 64 + size
/ 2 - 1, 64 - size
/ 2 + 1);
11598 ok(color_match(color
, test_setups
[i
].gives_0_0_texcoord
? 0x00ff0000 : 0x00ffff00, 0)
11599 || (allow_broken
&& broken(color_match(color
, 0x00ff0000, 0))),
11600 "Got unexpected color 0x%08x (case %u, %u, size %u).\n", color
, i
, j
, size
);
11601 color
= get_readback_color(&rb
, 64 - size
/ 2 + 1, 64 + size
/ 2 - 1);
11602 ok(color_match(color
, test_setups
[i
].gives_0_0_texcoord
? 0x00ff0000 : 0x00000000, 0),
11603 "Got unexpected color 0x%08x (case %u, %u, size %u).\n", color
, i
, j
, size
);
11604 color
= get_readback_color(&rb
, 64 + size
/ 2 - 1, 64 + size
/ 2 - 1);
11605 ok(color_match(color
, test_setups
[i
].gives_0_0_texcoord
? 0x00ff0000 : 0x0000ff00, 0)
11606 || (allow_broken
&& broken(color_match(color
, 0x00000000, 0))),
11607 "Got unexpected color 0x%08x (case %u, %u, size %u).\n", color
, i
, j
, size
);
11609 color
= get_readback_color(&rb
, 64 - size
/ 2 - 1, 64 - size
/ 2 - 1);
11610 ok(color_match(color
, 0xff00ffff, 0),
11611 "Got unexpected color 0x%08x (case %u, %u, size %u).\n", color
, i
, j
, size
);
11612 color
= get_readback_color(&rb
, 64 + size
/ 2 + 1, 64 - size
/ 2 - 1);
11613 ok(color_match(color
, 0xff00ffff, 0),
11614 "Got unexpected color 0x%08x (case %u, %u, size %u).\n", color
, i
, j
, size
);
11615 color
= get_readback_color(&rb
, 64 - size
/ 2 - 1, 64 + size
/ 2 + 1);
11616 ok(color_match(color
, 0xff00ffff, 0),
11617 "Got unexpected color 0x%08x (case %u, %u, size %u).\n", color
, i
, j
, size
);
11618 color
= get_readback_color(&rb
, 64 + size
/ 2 + 1, 64 + size
/ 2 + 1);
11619 ok(color_match(color
, 0xff00ffff, 0),
11620 "Got unexpected color 0x%08x (case %u, %u, size %u).\n", color
, i
, j
, size
);
11622 release_surface_readback(&rb
);
11625 IDirect3DDevice9_SetVertexShader(device
, NULL
);
11626 IDirect3DDevice9_SetPixelShader(device
, NULL
);
11628 IDirect3DVertexShader9_Release(vs
);
11630 IDirect3DVertexShader9_Release(ps
);
11634 IDirect3DSurface9_Release(backbuffer
);
11635 IDirect3DSurface9_Release(rt
);
11637 IDirect3DTexture9_Release(tex1
);
11638 IDirect3DTexture9_Release(tex2
);
11639 refcount
= IDirect3DDevice9_Release(device
);
11640 ok(!refcount
, "Device has %u references left.\n", refcount
);
11642 IDirect3D9_Release(d3d
);
11643 DestroyWindow(window
);
11646 static void multiple_rendertargets_test(void)
11648 IDirect3DSurface9
*surf1
, *surf2
, *backbuf
, *readback
;
11649 IDirect3DPixelShader9
*ps1
, *ps2
;
11650 IDirect3DTexture9
*tex1
, *tex2
;
11651 IDirect3DVertexShader9
*vs
;
11652 IDirect3DDevice9
*device
;
11661 static const DWORD vshader_code
[] =
11663 0xfffe0300, /* vs_3_0 */
11664 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
11665 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
11666 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
11667 0x0000ffff /* end */
11669 static const DWORD pshader_code1
[] =
11671 0xffff0300, /* ps_3_0 */
11672 0x05000051, 0xa00f0000, 0x00000000, 0x3f800000, 0x00000000, 0x00000000, /* def c0, 0.0, 1.0, 0.0, 0.0 */
11673 0x02000001, 0x800f0800, 0xa0e40000, /* mov oC0, c0 */
11674 0x0000ffff /* end */
11676 static const DWORD pshader_code2
[] =
11678 0xffff0300, /* ps_3_0 */
11679 0x05000051, 0xa00f0000, 0x00000000, 0x3f800000, 0x00000000, 0x00000000, /* def c0, 0.0, 1.0, 0.0, 0.0 */
11680 0x05000051, 0xa00f0001, 0x00000000, 0x00000000, 0x3f800000, 0x00000000, /* def c1, 0.0, 0.0, 1.0, 0.0 */
11681 0x02000001, 0x800f0800, 0xa0e40000, /* mov oC0, c0 */
11682 0x02000001, 0x800f0801, 0xa0e40001, /* mov oC1, c1 */
11683 0x0000ffff /* end */
11685 static const float quad
[] =
11687 -1.0f
, -1.0f
, 0.1f
,
11692 static const float texquad
[] =
11694 -1.0f
, -1.0f
, 0.1f
, 0.0f
, 0.0f
,
11695 -1.0f
, 1.0f
, 0.1f
, 0.0f
, 1.0f
,
11696 0.0f
, -1.0f
, 0.1f
, 1.0f
, 0.0f
,
11697 0.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
,
11699 0.0f
, -1.0f
, 0.1f
, 0.0f
, 0.0f
,
11700 0.0f
, 1.0f
, 0.1f
, 0.0f
, 1.0f
,
11701 1.0f
, -1.0f
, 0.1f
, 1.0f
, 0.0f
,
11702 1.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
,
11705 window
= create_window();
11706 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
11707 ok(!!d3d
, "Failed to create a D3D object.\n");
11708 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
11710 skip("Failed to create a D3D device, skipping tests.\n");
11714 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
11715 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
11716 if (caps
.NumSimultaneousRTs
< 2)
11718 skip("Only 1 simultaneous render target supported, skipping MRT test.\n");
11719 IDirect3DDevice9_Release(device
);
11722 if (caps
.PixelShaderVersion
< D3DPS_VERSION(3, 0) || caps
.VertexShaderVersion
< D3DVS_VERSION(3, 0))
11724 skip("No shader model 3 support, skipping tests.\n");
11725 IDirect3DDevice9_Release(device
);
11729 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffff0000, 1.0f
, 0);
11730 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed, hr=%08x\n", hr
);
11732 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 16, 16,
11733 D3DFMT_A8R8G8B8
, D3DPOOL_SYSTEMMEM
, &readback
, NULL
);
11734 ok(SUCCEEDED(hr
), "CreateOffscreenPlainSurface failed, hr %#x.\n", hr
);
11736 hr
= IDirect3DDevice9_CreateTexture(device
, 16, 16, 1, D3DUSAGE_RENDERTARGET
,
11737 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex1
, NULL
);
11738 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture failed, hr=%08x\n", hr
);
11739 hr
= IDirect3DDevice9_CreateTexture(device
, 16, 16, 1, D3DUSAGE_RENDERTARGET
,
11740 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex2
, NULL
);
11741 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture failed, hr=%08x\n", hr
);
11742 hr
= IDirect3DDevice9_CreateVertexShader(device
, vshader_code
, &vs
);
11743 ok(SUCCEEDED(hr
), "CreateVertexShader failed, hr %#x.\n", hr
);
11744 hr
= IDirect3DDevice9_CreatePixelShader(device
, pshader_code1
, &ps1
);
11745 ok(SUCCEEDED(hr
), "Failed to create pixel shader, hr %#x.\n", hr
);
11746 hr
= IDirect3DDevice9_CreatePixelShader(device
, pshader_code2
, &ps2
);
11747 ok(SUCCEEDED(hr
), "Failed to create pixel shader, hr %#x.\n", hr
);
11749 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &backbuf
);
11750 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderTarget failed, hr=%08x\n", hr
);
11751 hr
= IDirect3DTexture9_GetSurfaceLevel(tex1
, 0, &surf1
);
11752 ok(hr
== D3D_OK
, "IDirect3DTexture9_GetSurfaceLevel failed, hr=%08x\n", hr
);
11753 hr
= IDirect3DTexture9_GetSurfaceLevel(tex2
, 0, &surf2
);
11754 ok(hr
== D3D_OK
, "IDirect3DTexture9_GetSurfaceLevel failed, hr=%08x\n", hr
);
11756 hr
= IDirect3DDevice9_SetVertexShader(device
, vs
);
11757 ok(SUCCEEDED(hr
), "SetVertexShader failed, hr %#x.\n", hr
);
11758 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, surf1
);
11759 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderTarget failed, hr=%08x\n", hr
);
11760 hr
= IDirect3DDevice9_SetRenderTarget(device
, 1, surf2
);
11761 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderTarget failed, hr=%08x\n", hr
);
11762 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
11763 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed, hr=%08x\n", hr
);
11765 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff0000ff, 0.0f
, 0);
11766 ok(SUCCEEDED(hr
), "Clear failed, hr %#x,\n", hr
);
11767 hr
= IDirect3DDevice9_GetRenderTargetData(device
, surf1
, readback
);
11768 ok(SUCCEEDED(hr
), "GetRenderTargetData failed, hr %#x.\n", hr
);
11769 color
= getPixelColorFromSurface(readback
, 8, 8);
11770 ok(color_match(color
, D3DCOLOR_ARGB(0xff, 0x00, 0x00, 0xff), 0),
11771 "Expected color 0x000000ff, got 0x%08x.\n", color
);
11772 hr
= IDirect3DDevice9_GetRenderTargetData(device
, surf2
, readback
);
11773 ok(SUCCEEDED(hr
), "GetRenderTargetData failed, hr %#x.\n", hr
);
11774 color
= getPixelColorFromSurface(readback
, 8, 8);
11775 ok(color_match(color
, D3DCOLOR_ARGB(0xff, 0x00, 0x00, 0xff), 0),
11776 "Expected color 0x000000ff, got 0x%08x.\n", color
);
11778 /* Render targets not written by the pixel shader should be unmodified. */
11779 hr
= IDirect3DDevice9_SetPixelShader(device
, ps1
);
11780 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
11781 hr
= IDirect3DDevice9_BeginScene(device
);
11782 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
11783 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 3 * sizeof(float));
11784 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
11785 hr
= IDirect3DDevice9_EndScene(device
);
11786 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
11787 hr
= IDirect3DDevice9_GetRenderTargetData(device
, surf1
, readback
);
11788 ok(SUCCEEDED(hr
), "GetRenderTargetData failed, hr %#x.\n", hr
);
11789 color
= getPixelColorFromSurface(readback
, 8, 8);
11790 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 0),
11791 "Expected color 0xff00ff00, got 0x%08x.\n", color
);
11792 hr
= IDirect3DDevice9_GetRenderTargetData(device
, surf2
, readback
);
11793 ok(SUCCEEDED(hr
), "GetRenderTargetData failed, hr %#x.\n", hr
);
11794 for (i
= 6; i
< 10; ++i
)
11796 for (j
= 6; j
< 10; ++j
)
11798 color
= getPixelColorFromSurface(readback
, j
, i
);
11799 ok(color_match(color
, D3DCOLOR_ARGB(0xff, 0x00, 0x00, 0xff), 0),
11800 "Expected color 0xff0000ff, got 0x%08x at %u, %u.\n", color
, j
, i
);
11804 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0f
, 0);
11805 ok(SUCCEEDED(hr
), "Clear failed, hr %#x,\n", hr
);
11806 hr
= IDirect3DDevice9_GetRenderTargetData(device
, surf1
, readback
);
11807 ok(SUCCEEDED(hr
), "GetRenderTargetData failed, hr %#x.\n", hr
);
11808 color
= getPixelColorFromSurface(readback
, 8, 8);
11809 ok(color_match(color
, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00), 0),
11810 "Expected color 0x0000ff00, got 0x%08x.\n", color
);
11811 hr
= IDirect3DDevice9_GetRenderTargetData(device
, surf2
, readback
);
11812 ok(SUCCEEDED(hr
), "GetRenderTargetData failed, hr %#x.\n", hr
);
11813 color
= getPixelColorFromSurface(readback
, 8, 8);
11814 ok(color_match(color
, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00), 0),
11815 "Expected color 0x0000ff00, got 0x%08x.\n", color
);
11817 hr
= IDirect3DDevice9_SetPixelShader(device
, ps2
);
11818 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
11820 hr
= IDirect3DDevice9_BeginScene(device
);
11821 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
11823 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 3 * sizeof(float));
11824 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11826 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
11827 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
11828 hr
= IDirect3DDevice9_SetVertexShader(device
, NULL
);
11829 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
11830 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
11831 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
11832 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuf
);
11833 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
11834 hr
= IDirect3DDevice9_SetRenderTarget(device
, 1, NULL
);
11835 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
11836 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
11837 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
11839 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) tex1
);
11840 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
11841 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &texquad
[0], 5 * sizeof(float));
11842 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11844 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) tex2
);
11845 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
11846 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &texquad
[20], 5 * sizeof(float));
11847 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11849 hr
= IDirect3DDevice9_EndScene(device
);
11850 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
11852 color
= getPixelColor(device
, 160, 240);
11853 ok(color
== 0x0000ff00, "Texture 1(output color 1) has color 0x%08x, expected 0x0000ff00\n", color
);
11854 color
= getPixelColor(device
, 480, 240);
11855 ok(color
== 0x000000ff, "Texture 2(output color 2) has color 0x%08x, expected 0x000000ff\n", color
);
11856 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
11858 IDirect3DPixelShader9_Release(ps2
);
11859 IDirect3DPixelShader9_Release(ps1
);
11860 IDirect3DVertexShader9_Release(vs
);
11861 IDirect3DTexture9_Release(tex1
);
11862 IDirect3DTexture9_Release(tex2
);
11863 IDirect3DSurface9_Release(surf1
);
11864 IDirect3DSurface9_Release(surf2
);
11865 IDirect3DSurface9_Release(backbuf
);
11866 IDirect3DSurface9_Release(readback
);
11867 refcount
= IDirect3DDevice9_Release(device
);
11868 ok(!refcount
, "Device has %u references left.\n", refcount
);
11870 IDirect3D9_Release(d3d
);
11871 DestroyWindow(window
);
11874 static void pixelshader_blending_test(void)
11876 IDirect3DSurface9
*backbuffer
= NULL
, *offscreen
= NULL
;
11877 IDirect3DTexture9
*offscreenTexture
= NULL
;
11878 IDirect3DDevice9
*device
;
11886 static const struct
11888 const char *fmtName
;
11889 D3DFORMAT textureFormat
;
11890 D3DCOLOR resultColorBlending
;
11891 D3DCOLOR resultColorNoBlending
;
11895 {"D3DFMT_G16R16", D3DFMT_G16R16
, 0x001820ff, 0x002010ff},
11896 {"D3DFMT_R16F", D3DFMT_R16F
, 0x0018ffff, 0x0020ffff},
11897 {"D3DFMT_G16R16F", D3DFMT_G16R16F
, 0x001820ff, 0x002010ff},
11898 {"D3DFMT_A16B16G16R16F", D3DFMT_A16B16G16R16F
, 0x00182000, 0x00201000},
11899 {"D3DFMT_R32F", D3DFMT_R32F
, 0x0018ffff, 0x0020ffff},
11900 {"D3DFMT_G32R32F", D3DFMT_G32R32F
, 0x001820ff, 0x002010ff},
11901 {"D3DFMT_A32B32G32R32F", D3DFMT_A32B32G32R32F
, 0x00182000, 0x00201000},
11902 {"D3DFMT_L8", D3DFMT_L8
, 0x00181818, 0x00202020},
11904 static const float quad
[][5] =
11906 {-0.5f
, -0.5f
, 0.1f
, 0.0f
, 0.0f
},
11907 {-0.5f
, 0.5f
, 0.1f
, 0.0f
, 1.0f
},
11908 { 0.5f
, -0.5f
, 0.1f
, 1.0f
, 0.0f
},
11909 { 0.5f
, 0.5f
, 0.1f
, 1.0f
, 1.0f
},
11911 static const struct
11913 struct vec3 position
;
11918 {{-1.0f
, -1.0f
, 0.1f
}, 0x80103000},
11919 {{-1.0f
, 1.0f
, 0.1f
}, 0x80103000},
11920 {{ 1.0f
, -1.0f
, 0.1f
}, 0x80103000},
11921 {{ 1.0f
, 1.0f
, 0.1f
}, 0x80103000},
11925 {{-1.0f
, -1.0f
, 0.1f
}, 0x80201000},
11926 {{-1.0f
, 1.0f
, 0.1f
}, 0x80201000},
11927 {{ 1.0f
, -1.0f
, 0.1f
}, 0x80201000},
11928 {{ 1.0f
, 1.0f
, 0.1f
}, 0x80201000},
11931 window
= create_window();
11932 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
11933 ok(!!d3d
, "Failed to create a D3D object.\n");
11934 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
11936 skip("Failed to create a D3D device, skipping tests.\n");
11940 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
11941 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %08x\n", hr
);
11943 for (fmt_index
= 0; fmt_index
< ARRAY_SIZE(test_formats
); ++fmt_index
)
11945 D3DFORMAT fmt
= test_formats
[fmt_index
].textureFormat
;
11947 if (IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
11948 D3DUSAGE_RENDERTARGET
, D3DRTYPE_TEXTURE
, fmt
) != D3D_OK
)
11950 skip("%s textures not supported as render targets.\n", test_formats
[fmt_index
].fmtName
);
11954 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffffff, 1.0f
, 0);
11955 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
11957 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
, fmt
, D3DPOOL_DEFAULT
, &offscreenTexture
, NULL
);
11958 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "Creating the offscreen render target failed, hr = %08x\n", hr
);
11959 if(!offscreenTexture
) {
11963 hr
= IDirect3DTexture9_GetSurfaceLevel(offscreenTexture
, 0, &offscreen
);
11964 ok(hr
== D3D_OK
, "Can't get offscreen surface, hr = %08x\n", hr
);
11969 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
11970 ok(hr
== D3D_OK
, "SetFVF failed, hr = %08x\n", hr
);
11972 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
11973 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
11974 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
11975 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
11976 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MINFILTER
, D3DTEXF_POINT
);
11977 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_MINFILTER failed (0x%08x)\n", hr
);
11978 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAGFILTER
, D3DTEXF_POINT
);
11979 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr
);
11980 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
11981 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
11983 /* Below we will draw two quads with different colors and try to blend
11984 * them together. The result color is compared with the expected
11986 hr
= IDirect3DDevice9_BeginScene(device
);
11987 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
11989 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, offscreen
);
11990 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
11991 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00ffffff, 1.0f
, 0);
11992 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
11994 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, TRUE
);
11995 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
11997 /* Draw a quad using color 0x0010200. */
11998 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_ONE
);
11999 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
12000 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_ZERO
);
12001 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
12002 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(quad1
[0]));
12003 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
12005 /* Draw a quad using color 0x0020100. */
12006 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_SRCALPHA
);
12007 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
12008 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
12009 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
12010 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(quad2
[0]));
12011 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
12013 /* We don't want to blend the result on the backbuffer. */
12014 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, FALSE
);
12015 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
12017 /* Prepare rendering the 'blended' texture quad to the backbuffer. */
12018 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
12019 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
12020 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)offscreenTexture
);
12021 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
12023 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
12024 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
12026 /* This time with the texture. */
12027 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(quad
[0]));
12028 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
12030 hr
= IDirect3DDevice9_EndScene(device
);
12031 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
12033 if (IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
12034 D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
, D3DRTYPE_TEXTURE
, fmt
) == D3D_OK
)
12036 /* Compare the color of the center quad with our expectation. */
12037 color
= getPixelColor(device
, 320, 240);
12038 ok(color_match(color
, test_formats
[fmt_index
].resultColorBlending
, 1),
12039 "Offscreen failed for %s: Got color 0x%08x, expected 0x%08x.\n",
12040 test_formats
[fmt_index
].fmtName
, color
, test_formats
[fmt_index
].resultColorBlending
);
12044 /* No pixel shader blending is supported so expect garbage. The
12045 * type of 'garbage' depends on the driver version and OS. E.g. on
12046 * G16R16 ATI reports (on old r9600 drivers) 0x00ffffff and on
12047 * modern ones 0x002010ff which is also what NVIDIA reports. On
12048 * Vista NVIDIA seems to report 0x00ffffff on Geforce7 cards. */
12049 color
= getPixelColor(device
, 320, 240);
12050 ok((color
== 0x00ffffff) || (color
== test_formats
[fmt_index
].resultColorNoBlending
),
12051 "Offscreen failed for %s: Got unexpected color 0x%08x, expected no color blending.\n",
12052 test_formats
[fmt_index
].fmtName
, color
);
12054 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
12056 IDirect3DDevice9_SetTexture(device
, 0, NULL
);
12057 if(offscreenTexture
) {
12058 IDirect3DTexture9_Release(offscreenTexture
);
12061 IDirect3DSurface9_Release(offscreen
);
12065 IDirect3DSurface9_Release(backbuffer
);
12066 refcount
= IDirect3DDevice9_Release(device
);
12067 ok(!refcount
, "Device has %u references left.\n", refcount
);
12069 IDirect3D9_Release(d3d
);
12070 DestroyWindow(window
);
12073 static void tssargtemp_test(void)
12075 IDirect3DDevice9
*device
;
12083 static const struct
12085 struct vec3 position
;
12090 {{-1.0f
, -1.0f
, 0.1f
}, 0x00ff0000},
12091 {{-1.0f
, 1.0f
, 0.1f
}, 0x00ff0000},
12092 {{ 1.0f
, -1.0f
, 0.1f
}, 0x00ff0000},
12093 {{ 1.0f
, 1.0f
, 0.1f
}, 0x00ff0000},
12096 window
= create_window();
12097 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
12098 ok(!!d3d
, "Failed to create a D3D object.\n");
12099 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
12101 skip("Failed to create a D3D device, skipping tests.\n");
12105 memset(&caps
, 0, sizeof(caps
));
12106 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
12107 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetDeviceCaps failed with %08x\n", hr
);
12108 if(!(caps
.PrimitiveMiscCaps
& D3DPMISCCAPS_TSSARGTEMP
)) {
12109 skip("D3DPMISCCAPS_TSSARGTEMP not supported\n");
12110 IDirect3DDevice9_Release(device
);
12114 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff000000, 1.0f
, 0);
12115 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
12117 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
12118 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
12119 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_DIFFUSE
);
12120 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
12122 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
12123 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
12124 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLORARG1
, D3DTA_TFACTOR
);
12125 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
12126 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_RESULTARG
, D3DTA_TEMP
);
12127 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
12129 hr
= IDirect3DDevice9_SetTextureStageState(device
, 2, D3DTSS_COLOROP
, D3DTOP_ADD
);
12130 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
12131 hr
= IDirect3DDevice9_SetTextureStageState(device
, 2, D3DTSS_COLORARG1
, D3DTA_CURRENT
);
12132 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
12133 hr
= IDirect3DDevice9_SetTextureStageState(device
, 2, D3DTSS_COLORARG2
, D3DTA_TEMP
);
12134 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
12136 hr
= IDirect3DDevice9_SetTextureStageState(device
, 3, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
12137 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
12139 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_TEXTUREFACTOR
, 0x0000ff00);
12140 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed, hr = %08x\n", hr
);
12141 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
12142 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
12143 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
12144 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed, hr = %08x\n", hr
);
12146 hr
= IDirect3DDevice9_BeginScene(device
);
12147 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
12148 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(quad
[0]));
12149 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
12150 hr
= IDirect3DDevice9_EndScene(device
);
12151 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
12153 color
= getPixelColor(device
, 320, 240);
12154 ok(color
== 0x00ffff00, "TSSARGTEMP test returned color 0x%08x, expected 0x00ffff00\n", color
);
12155 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
12157 refcount
= IDirect3DDevice9_Release(device
);
12158 ok(!refcount
, "Device has %u references left.\n", refcount
);
12160 IDirect3D9_Release(d3d
);
12161 DestroyWindow(window
);
12164 /* Drawing Indexed Geometry with instances*/
12165 static void stream_test(void)
12167 IDirect3DVertexDeclaration9
*pDecl
= NULL
;
12168 IDirect3DVertexShader9
*shader
= NULL
;
12169 IDirect3DVertexBuffer9
*vb3
= NULL
;
12170 IDirect3DVertexBuffer9
*vb2
= NULL
;
12171 IDirect3DVertexBuffer9
*vb
= NULL
;
12172 IDirect3DIndexBuffer9
*ib
= NULL
;
12173 IDirect3DDevice9
*device
;
12184 static const struct testdata
12186 DWORD idxVertex
; /* number of instances in the first stream */
12187 DWORD idxColor
; /* number of instances in the second stream */
12188 DWORD idxInstance
; /* should be 1 ?? */
12189 DWORD color1
; /* color 1 instance */
12190 DWORD color2
; /* color 2 instance */
12191 DWORD color3
; /* color 3 instance */
12192 DWORD color4
; /* color 4 instance */
12193 WORD strVertex
; /* specify which stream to use 0-2*/
12196 DWORD explicit_zero_freq
;
12200 {4, 4, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0, 1, 2}, /* 0 */
12201 {3, 4, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ffffff, 0, 1, 2}, /* 1 */
12202 {2, 4, 1, 0x00ff0000, 0x00ff0000, 0x00ffffff, 0x00ffffff, 0, 1, 2}, /* 2 */
12203 {1, 4, 1, 0x00ff0000, 0x00ffffff, 0x00ffffff, 0x00ffffff, 0, 1, 2}, /* 3 */
12204 {4, 3, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0, 1, 2}, /* 4 */
12205 {4, 2, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0, 1, 2}, /* 5 */
12206 {4, 1, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0, 1, 2}, /* 6 */
12207 {4, 0, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0, 1, 2}, /* 7 */
12208 {3, 3, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ffffff, 0, 1, 2}, /* 8 */
12209 {4, 4, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 1, 0, 2}, /* 9 */
12210 {4, 4, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0, 2, 1}, /* 10 */
12211 {4, 4, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 2, 0, 1}, /* 11 */
12213 /* The number of instances is read from stream zero, even if stream zero is not
12214 * in use. Exact behavior of this corner case depends on the presence or absence
12215 * of D3DSTREAMSOURCE_INDEXEDDATA. r500 GPUs need D3DSTREAMSOURCE_INDEXEDDATA
12216 * to be present, otherwise they disable instancing and behave like in a non-
12217 * instanced draw. Nvidia drivers do not show different behavior with or without
12218 * D3DSTREAMSOURCE_INDEXEDDATA. Note however that setting the value to 0 is not
12219 * allowed by the d3d runtime.
12221 * The meaning of (D3DSTREAMSOURCE_INDEXEDDATA | 0) is driver dependent. r500
12222 * will fall back to non-instanced drawing. Geforce 7 will draw 1 instance.
12223 * Geforce 8+ will draw nothing. */
12224 {3, 4, 1, 0x00ff0000, 0x00ffffff, 0x00ffffff, 0x00ffffff, 2, 3, 1, 1}, /* 12 */
12225 {4, 3, 1, 0x00ff0000, 0x00ff0000, 0x00ffffff, 0x00ffffff, 2, 3, 1, 2}, /* 13 */
12226 {1, 3, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ffffff, 2, 3, 1, 3}, /* 14 */
12227 {0, 0, 1, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 2, 3, 1, 4}, /* 15 */
12229 static const DWORD shader_code
[] =
12231 0xfffe0101, /* vs_1_1 */
12232 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
12233 0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
12234 0x0000001f, 0x80000005, 0x900f0002, /* dcl_texcoord v2 */
12235 0x00000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
12236 0x00000002, 0xc00f0000, 0x80e40000, 0x90e40002, /* add oPos, r0, v2 */
12237 0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
12240 /* Note that this set of coordinates and instancepos[] have an implicit
12241 * w = 1.0, which is added to w = 2.0, so the perspective divide divides
12242 * x, y and z by 2. */
12243 static const float quad
[][3] =
12245 {-0.5f
, -0.5f
, 1.1f
}, /*0 */
12246 {-0.5f
, 0.5f
, 1.1f
}, /*1 */
12247 { 0.5f
, -0.5f
, 1.1f
}, /*2 */
12248 { 0.5f
, 0.5f
, 1.1f
}, /*3 */
12250 static const float vertcolor
[][4] =
12252 {1.0f
, 0.0f
, 0.0f
, 1.0f
}, /*0 */
12253 {1.0f
, 0.0f
, 0.0f
, 1.0f
}, /*1 */
12254 {1.0f
, 0.0f
, 0.0f
, 1.0f
}, /*2 */
12255 {1.0f
, 0.0f
, 0.0f
, 1.0f
}, /*3 */
12257 /* 4 position for 4 instances */
12258 static const float instancepos
[][3] =
12260 {-0.6f
,-0.6f
, 0.0f
},
12261 { 0.6f
,-0.6f
, 0.0f
},
12262 { 0.6f
, 0.6f
, 0.0f
},
12263 {-0.6f
, 0.6f
, 0.0f
},
12265 static const short indices
[] = {0, 1, 2, 2, 1, 3};
12266 D3DVERTEXELEMENT9 decl
[] =
12268 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
12269 {1, 0, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
12270 {2, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
12274 window
= create_window();
12275 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
12276 ok(!!d3d
, "Failed to create a D3D object.\n");
12277 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
12279 skip("Failed to create a D3D device, skipping tests.\n");
12283 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
12284 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
12285 if (caps
.VertexShaderVersion
< D3DVS_VERSION(3, 0))
12287 skip("No vs_3_0 support, skipping tests.\n");
12288 IDirect3DDevice9_Release(device
);
12292 /* set the default value because it isn't done in wine? */
12293 hr
= IDirect3DDevice9_SetStreamSourceFreq(device
, 1, 1);
12294 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr
);
12296 /* check for D3DSTREAMSOURCE_INDEXEDDATA at stream0 */
12297 hr
= IDirect3DDevice9_SetStreamSourceFreq(device
, 0, (D3DSTREAMSOURCE_INSTANCEDATA
| 1));
12298 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr
);
12300 /* check wrong cases */
12301 hr
= IDirect3DDevice9_SetStreamSourceFreq(device
, 1, 0);
12302 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr
);
12303 hr
= IDirect3DDevice9_GetStreamSourceFreq(device
, 1, &ind
);
12304 ok(hr
== D3D_OK
&& ind
== 1, "IDirect3DDevice9_GetStreamSourceFreq failed with %08x\n", hr
);
12305 hr
= IDirect3DDevice9_SetStreamSourceFreq(device
, 1, 2);
12306 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr
);
12307 hr
= IDirect3DDevice9_GetStreamSourceFreq(device
, 1, &ind
);
12308 ok(hr
== D3D_OK
&& ind
== 2, "IDirect3DDevice9_GetStreamSourceFreq failed with %08x\n", hr
);
12309 hr
= IDirect3DDevice9_SetStreamSourceFreq(device
, 1, (D3DSTREAMSOURCE_INDEXEDDATA
| 0));
12310 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr
);
12311 hr
= IDirect3DDevice9_GetStreamSourceFreq(device
, 1, &ind
);
12312 ok(hr
== D3D_OK
&& ind
== (D3DSTREAMSOURCE_INDEXEDDATA
| 0), "IDirect3DDevice9_GetStreamSourceFreq failed with %08x\n", hr
);
12313 hr
= IDirect3DDevice9_SetStreamSourceFreq(device
, 1, (D3DSTREAMSOURCE_INSTANCEDATA
| 0));
12314 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr
);
12315 hr
= IDirect3DDevice9_GetStreamSourceFreq(device
, 1, &ind
);
12316 ok(hr
== D3D_OK
&& ind
== (0U | D3DSTREAMSOURCE_INSTANCEDATA
), "IDirect3DDevice9_GetStreamSourceFreq failed with %08x\n", hr
);
12317 hr
= IDirect3DDevice9_SetStreamSourceFreq(device
, 1, (D3DSTREAMSOURCE_INSTANCEDATA
| D3DSTREAMSOURCE_INDEXEDDATA
| 0));
12318 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr
);
12319 hr
= IDirect3DDevice9_GetStreamSourceFreq(device
, 1, &ind
);
12320 ok(hr
== D3D_OK
&& ind
== (0U | D3DSTREAMSOURCE_INSTANCEDATA
), "IDirect3DDevice9_GetStreamSourceFreq failed with %08x\n", hr
);
12322 /* set the default value back */
12323 hr
= IDirect3DDevice9_SetStreamSourceFreq(device
, 1, 1);
12324 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetStreamSourceFreq failed with %08x\n", hr
);
12326 /* create all VertexBuffers*/
12327 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, sizeof(quad
), 0, 0, D3DPOOL_MANAGED
, &vb
, NULL
);
12328 ok(hr
== D3D_OK
, "CreateVertexBuffer failed with %08x\n", hr
);
12330 skip("Failed to create a vertex buffer\n");
12331 IDirect3DDevice9_Release(device
);
12334 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, sizeof(vertcolor
), 0, 0, D3DPOOL_MANAGED
, &vb2
, NULL
);
12335 ok(hr
== D3D_OK
, "CreateVertexBuffer failed with %08x\n", hr
);
12337 skip("Failed to create a vertex buffer\n");
12340 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, sizeof(instancepos
), 0, 0, D3DPOOL_MANAGED
, &vb3
, NULL
);
12341 ok(hr
== D3D_OK
, "CreateVertexBuffer failed with %08x\n", hr
);
12343 skip("Failed to create a vertex buffer\n");
12347 /* create IndexBuffer*/
12348 hr
= IDirect3DDevice9_CreateIndexBuffer(device
, sizeof(indices
), 0, D3DFMT_INDEX16
, D3DPOOL_DEFAULT
, &ib
, NULL
);
12349 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateIndexBuffer failed with %08x\n", hr
);
12351 skip("Failed to create an index buffer\n");
12355 /* copy all Buffers (Vertex + Index)*/
12356 hr
= IDirect3DVertexBuffer9_Lock(vb
, 0, sizeof(quad
), (void **) &data
, 0);
12357 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr
);
12358 memcpy(data
, quad
, sizeof(quad
));
12359 hr
= IDirect3DVertexBuffer9_Unlock(vb
);
12360 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Unlock failed with %08x\n", hr
);
12361 hr
= IDirect3DVertexBuffer9_Lock(vb2
, 0, sizeof(vertcolor
), (void **) &data
, 0);
12362 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr
);
12363 memcpy(data
, vertcolor
, sizeof(vertcolor
));
12364 hr
= IDirect3DVertexBuffer9_Unlock(vb2
);
12365 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Unlock failed with %08x\n", hr
);
12366 hr
= IDirect3DVertexBuffer9_Lock(vb3
, 0, sizeof(instancepos
), (void **) &data
, 0);
12367 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Lock failed with %08x\n", hr
);
12368 memcpy(data
, instancepos
, sizeof(instancepos
));
12369 hr
= IDirect3DVertexBuffer9_Unlock(vb3
);
12370 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Unlock failed with %08x\n", hr
);
12371 hr
= IDirect3DIndexBuffer9_Lock(ib
, 0, sizeof(indices
), (void **) &data
, 0);
12372 ok(hr
== D3D_OK
, "IDirect3DIndexBuffer9_Lock failed with %08x\n", hr
);
12373 memcpy(data
, indices
, sizeof(indices
));
12374 hr
= IDirect3DIndexBuffer9_Unlock(ib
);
12375 ok(hr
== D3D_OK
, "IDirect3DIndexBuffer9_Unlock failed with %08x\n", hr
);
12377 /* create VertexShader */
12378 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_code
, &shader
);
12379 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateVertexShader failed hr=%08x\n", hr
);
12381 skip("Failed to create a vertex shader.\n");
12385 hr
= IDirect3DDevice9_SetVertexShader(device
, shader
);
12386 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShader failed hr=%08x\n", hr
);
12388 hr
= IDirect3DDevice9_SetIndices(device
, ib
);
12389 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetIndices failed with %08x\n", hr
);
12391 /* run all tests */
12392 for( i
= 0; i
< ARRAY_SIZE(testcases
); ++i
)
12394 struct testdata act
= testcases
[i
];
12395 decl
[0].Stream
= act
.strVertex
;
12396 decl
[1].Stream
= act
.strColor
;
12397 decl
[2].Stream
= act
.strInstance
;
12398 /* create VertexDeclarations */
12399 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl
, &pDecl
);
12400 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateVertexDeclaration failed hr=%08x (case %i)\n", hr
, i
);
12402 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffffff, 1.0f
, 0);
12403 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x (case %i)\n", hr
, i
);
12405 hr
= IDirect3DDevice9_BeginScene(device
);
12406 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
12408 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, pDecl
);
12409 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
12411 /* If stream 0 is unused, set the stream frequency regardless to show
12412 * that the number if instances is read from it. */
12413 if (act
.strVertex
&& act
.strColor
&& act
.strInstance
)
12415 hr
= IDirect3DDevice9_SetStreamSourceFreq(device
, 0,
12416 D3DSTREAMSOURCE_INDEXEDDATA
| act
.explicit_zero_freq
);
12417 ok(SUCCEEDED(hr
), "Failed to set stream source frequency, hr %#x.\n", hr
);
12420 hr
= IDirect3DDevice9_SetStreamSourceFreq(device
, act
.strVertex
,
12421 (D3DSTREAMSOURCE_INDEXEDDATA
| act
.idxVertex
));
12422 ok(SUCCEEDED(hr
), "Failed to set stream source frequency, hr %#x.\n", hr
);
12423 hr
= IDirect3DDevice9_SetStreamSource(device
, act
.strVertex
, vb
, 0, sizeof(quad
[0]));
12424 ok(SUCCEEDED(hr
), "Failed to set stream source, hr %#x.\n", hr
);
12426 hr
= IDirect3DDevice9_SetStreamSourceFreq(device
, act
.strColor
,
12427 (D3DSTREAMSOURCE_INDEXEDDATA
| act
.idxColor
));
12428 ok(SUCCEEDED(hr
), "Failed to set stream source frequency, hr %#x.\n", hr
);
12429 hr
= IDirect3DDevice9_SetStreamSource(device
, act
.strColor
, vb2
, 0, sizeof(vertcolor
[0]));
12430 ok(SUCCEEDED(hr
), "Failed to set stream source, hr %#x.\n", hr
);
12432 hr
= IDirect3DDevice9_SetStreamSourceFreq(device
, act
.strInstance
,
12433 (D3DSTREAMSOURCE_INSTANCEDATA
| act
.idxInstance
));
12434 ok(SUCCEEDED(hr
), "Failed to set stream source frequency, hr %#x.\n", hr
);
12435 hr
= IDirect3DDevice9_SetStreamSource(device
, act
.strInstance
, vb3
, 0, sizeof(instancepos
[0]));
12436 ok(SUCCEEDED(hr
), "Failed to set stream source, hr %#x.\n", hr
);
12438 hr
= IDirect3DDevice9_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, 0, 0, 4, 0, 2);
12439 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
12440 hr
= IDirect3DDevice9_EndScene(device
);
12441 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
12443 /* set all StreamSource && StreamSourceFreq back to default */
12444 hr
= IDirect3DDevice9_SetStreamSourceFreq(device
, act
.strVertex
, 1);
12445 ok(SUCCEEDED(hr
), "Failed to set stream source frequency, hr %#x.\n", hr
);
12446 hr
= IDirect3DDevice9_SetStreamSource(device
, act
.strVertex
, NULL
, 0, 0);
12447 ok(SUCCEEDED(hr
), "Failed to set stream source, hr %#x.\n", hr
);
12448 hr
= IDirect3DDevice9_SetStreamSourceFreq(device
, act
.idxColor
, 1);
12449 ok(SUCCEEDED(hr
), "Failed to set stream source frequency, hr %#x.\n", hr
);
12450 hr
= IDirect3DDevice9_SetStreamSource(device
, act
.idxColor
, NULL
, 0, 0);
12451 ok(SUCCEEDED(hr
), "Failed to set stream source, hr %#x.\n", hr
);
12452 hr
= IDirect3DDevice9_SetStreamSourceFreq(device
, act
.idxInstance
, 1);
12453 ok(SUCCEEDED(hr
), "Failed to set stream source frequency, hr %#x.\n", hr
);
12454 hr
= IDirect3DDevice9_SetStreamSource(device
, act
.idxInstance
, NULL
, 0, 0);
12455 ok(SUCCEEDED(hr
), "Failed to set stream source, hr %#x.\n", hr
);
12457 hr
= IDirect3DVertexDeclaration9_Release(pDecl
);
12458 ok(hr
== D3D_OK
, "IDirect3DVertexDeclaration9_Release failed with %08x (case %i)\n", hr
, i
);
12460 color
= getPixelColor(device
, 160, 360);
12461 ok(color
== act
.color1
, "has color 0x%08x, expected 0x%08x (case %i)\n", color
, act
.color1
, i
);
12462 color
= getPixelColor(device
, 480, 360);
12463 ok(color
== act
.color2
, "has color 0x%08x, expected 0x%08x (case %i)\n", color
, act
.color2
, i
);
12464 color
= getPixelColor(device
, 480, 120);
12465 ok(color
== act
.color3
, "has color 0x%08x, expected 0x%08x (case %i)\n", color
, act
.color3
, i
);
12466 color
= getPixelColor(device
, 160, 120);
12467 ok(color
== act
.color4
, "has color 0x%08x, expected 0x%08x (case %i)\n", color
, act
.color4
, i
);
12469 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
12470 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x (case %i)\n", hr
, i
);
12474 if(vb
) IDirect3DVertexBuffer9_Release(vb
);
12475 if(vb2
)IDirect3DVertexBuffer9_Release(vb2
);
12476 if(vb3
)IDirect3DVertexBuffer9_Release(vb3
);
12477 if(ib
)IDirect3DIndexBuffer9_Release(ib
);
12478 if(shader
)IDirect3DVertexShader9_Release(shader
);
12479 refcount
= IDirect3DDevice9_Release(device
);
12480 ok(!refcount
, "Device has %u references left.\n", refcount
);
12482 IDirect3D9_Release(d3d
);
12483 DestroyWindow(window
);
12486 static void np2_stretch_rect_test(void)
12488 IDirect3DSurface9
*src
= NULL
, *dst
= NULL
, *backbuffer
= NULL
;
12489 IDirect3DTexture9
*dsttex
= NULL
;
12490 IDirect3DDevice9
*device
;
12497 static const D3DRECT r1
= {0, 0, 50, 50 };
12498 static const D3DRECT r2
= {50, 0, 100, 50 };
12499 static const D3DRECT r3
= {50, 50, 100, 100};
12500 static const D3DRECT r4
= {0, 50, 50, 100};
12501 static const float quad
[] =
12503 -1.0f
, -1.0f
, 0.1f
, 0.0f
, 0.0f
,
12504 -1.0f
, 1.0f
, 0.1f
, 0.0f
, 1.0f
,
12505 1.0f
, -1.0f
, 0.1f
, 1.0f
, 0.0f
,
12506 1.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
,
12509 window
= create_window();
12510 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
12511 ok(!!d3d
, "Failed to create a D3D object.\n");
12512 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
12514 skip("Failed to create a D3D device, skipping tests.\n");
12518 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
12519 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetBackBuffer failed with %08x\n", hr
);
12521 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 100, 100, D3DFMT_A8R8G8B8
, D3DMULTISAMPLE_NONE
, 0, TRUE
, &src
, NULL
);
12522 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_CreateRenderTarget failed with %08x\n", hr
);
12523 hr
= IDirect3DDevice9_CreateTexture(device
, 25, 25, 1, D3DUSAGE_RENDERTARGET
, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &dsttex
, NULL
);
12524 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_CreateTexture failed with %08x\n", hr
);
12526 if(!src
|| !dsttex
) {
12527 skip("One or more test resources could not be created\n");
12531 hr
= IDirect3DTexture9_GetSurfaceLevel(dsttex
, 0, &dst
);
12532 ok(hr
== D3D_OK
, "IDirect3DTexture9_GetSurfaceLevel failed with %08x\n", hr
);
12534 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff00ffff, 1.0f
, 0);
12535 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
12537 /* Clear the StretchRect destination for debugging */
12538 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, dst
);
12539 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderTarget failed with %08x\n", hr
);
12540 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
12541 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
12543 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, src
);
12544 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderTarget failed with %08x\n", hr
);
12546 hr
= IDirect3DDevice9_Clear(device
, 1, &r1
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
12547 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
12548 hr
= IDirect3DDevice9_Clear(device
, 1, &r2
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0, 0);
12549 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
12550 hr
= IDirect3DDevice9_Clear(device
, 1, &r3
, D3DCLEAR_TARGET
, 0xff0000ff, 0.0, 0);
12551 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
12552 hr
= IDirect3DDevice9_Clear(device
, 1, &r4
, D3DCLEAR_TARGET
, 0xff000000, 0.0, 0);
12553 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
12555 /* Stretchrect before setting the render target back to the backbuffer. This will make Wine use
12556 * the target -> texture GL blit path
12558 hr
= IDirect3DDevice9_StretchRect(device
, src
, NULL
, dst
, NULL
, D3DTEXF_POINT
);
12559 ok(hr
== D3D_OK
, "IDirect3DDevice9_StretchRect failed with %08x\n", hr
);
12560 IDirect3DSurface9_Release(dst
);
12562 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
12563 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderTarget failed with %08x\n", hr
);
12565 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) dsttex
);
12566 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture failed with %08x\n", hr
);
12567 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
12568 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with %08x\n", hr
);
12569 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
12570 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed with %08x\n", hr
);
12571 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
12572 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed with %08x\n", hr
);
12574 hr
= IDirect3DDevice9_BeginScene(device
);
12575 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
12576 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(float) * 5);
12577 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
12578 hr
= IDirect3DDevice9_EndScene(device
);
12579 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
12581 color
= getPixelColor(device
, 160, 360);
12582 ok(color
== 0x00ff0000, "stretchrect: Pixel 160,360 has color 0x%08x, expected 0x00ff0000\n", color
);
12583 color
= getPixelColor(device
, 480, 360);
12584 ok(color
== 0x0000ff00, "stretchrect: Pixel 480,360 has color 0x%08x, expected 0x0000ff00\n", color
);
12585 color
= getPixelColor(device
, 480, 120);
12586 ok(color
== 0x000000ff, "stretchrect: Pixel 480,120 has color 0x%08x, expected 0x000000ff\n", color
);
12587 color
= getPixelColor(device
, 160, 120);
12588 ok(color
== 0x00000000, "stretchrect: Pixel 160,120 has color 0x%08x, expected 0x00000000\n", color
);
12589 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
12590 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
12593 if(src
) IDirect3DSurface9_Release(src
);
12594 if(backbuffer
) IDirect3DSurface9_Release(backbuffer
);
12595 if(dsttex
) IDirect3DTexture9_Release(dsttex
);
12596 refcount
= IDirect3DDevice9_Release(device
);
12597 ok(!refcount
, "Device has %u references left.\n", refcount
);
12599 IDirect3D9_Release(d3d
);
12600 DestroyWindow(window
);
12603 static void texop_test(void)
12605 IDirect3DVertexDeclaration9
*vertex_declaration
= NULL
;
12606 IDirect3DTexture9
*texture
= NULL
;
12607 D3DLOCKED_RECT locked_rect
;
12608 IDirect3DDevice9
*device
;
12617 static const struct {
12622 {-1.0f
, -1.0f
, 0.1f
, -1.0f
, -1.0f
, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00)},
12623 {-1.0f
, 1.0f
, 0.1f
, -1.0f
, 1.0f
, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00)},
12624 { 1.0f
, -1.0f
, 0.1f
, 1.0f
, -1.0f
, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00)},
12625 { 1.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
, D3DCOLOR_ARGB(0x55, 0xff, 0x00, 0x00)}
12628 static const D3DVERTEXELEMENT9 decl_elements
[] = {
12629 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
12630 {0, 12, D3DDECLTYPE_FLOAT2
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
12631 {0, 20, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
12635 static const struct {
12641 {D3DTOP_SELECTARG1
, "SELECTARG1", D3DTEXOPCAPS_SELECTARG1
, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00)},
12642 {D3DTOP_SELECTARG2
, "SELECTARG2", D3DTEXOPCAPS_SELECTARG2
, D3DCOLOR_ARGB(0x00, 0x33, 0x33, 0x33)},
12643 {D3DTOP_MODULATE
, "MODULATE", D3DTEXOPCAPS_MODULATE
, D3DCOLOR_ARGB(0x00, 0x00, 0x33, 0x00)},
12644 {D3DTOP_MODULATE2X
, "MODULATE2X", D3DTEXOPCAPS_MODULATE2X
, D3DCOLOR_ARGB(0x00, 0x00, 0x66, 0x00)},
12645 {D3DTOP_MODULATE4X
, "MODULATE4X", D3DTEXOPCAPS_MODULATE4X
, D3DCOLOR_ARGB(0x00, 0x00, 0xcc, 0x00)},
12646 {D3DTOP_ADD
, "ADD", D3DTEXOPCAPS_ADD
, D3DCOLOR_ARGB(0x00, 0x33, 0xff, 0x33)},
12647 {D3DTOP_ADDSIGNED
, "ADDSIGNED", D3DTEXOPCAPS_ADDSIGNED
, D3DCOLOR_ARGB(0x00, 0x00, 0xb2, 0x00)},
12648 {D3DTOP_ADDSIGNED2X
, "ADDSIGNED2X", D3DTEXOPCAPS_ADDSIGNED2X
, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00)},
12649 {D3DTOP_SUBTRACT
, "SUBTRACT", D3DTEXOPCAPS_SUBTRACT
, D3DCOLOR_ARGB(0x00, 0x00, 0xcc, 0x00)},
12650 {D3DTOP_ADDSMOOTH
, "ADDSMOOTH", D3DTEXOPCAPS_ADDSMOOTH
, D3DCOLOR_ARGB(0x00, 0x33, 0xff, 0x33)},
12651 {D3DTOP_BLENDDIFFUSEALPHA
, "BLENDDIFFUSEALPHA", D3DTEXOPCAPS_BLENDDIFFUSEALPHA
, D3DCOLOR_ARGB(0x00, 0x22, 0x77, 0x22)},
12652 {D3DTOP_BLENDTEXTUREALPHA
, "BLENDTEXTUREALPHA", D3DTEXOPCAPS_BLENDTEXTUREALPHA
, D3DCOLOR_ARGB(0x00, 0x14, 0xad, 0x14)},
12653 {D3DTOP_BLENDFACTORALPHA
, "BLENDFACTORALPHA", D3DTEXOPCAPS_BLENDFACTORALPHA
, D3DCOLOR_ARGB(0x00, 0x07, 0xe4, 0x07)},
12654 {D3DTOP_BLENDTEXTUREALPHAPM
, "BLENDTEXTUREALPHAPM", D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
, D3DCOLOR_ARGB(0x00, 0x14, 0xff, 0x14)},
12655 {D3DTOP_BLENDCURRENTALPHA
, "BLENDCURRENTALPHA", D3DTEXOPCAPS_BLENDCURRENTALPHA
, D3DCOLOR_ARGB(0x00, 0x22, 0x77, 0x22)},
12656 {D3DTOP_MODULATEALPHA_ADDCOLOR
, "MODULATEALPHA_ADDCOLOR", D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
, D3DCOLOR_ARGB(0x00, 0x1f, 0xff, 0x1f)},
12657 {D3DTOP_MODULATECOLOR_ADDALPHA
, "MODULATECOLOR_ADDALPHA", D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
, D3DCOLOR_ARGB(0x00, 0x99, 0xcc, 0x99)},
12658 {D3DTOP_MODULATEINVALPHA_ADDCOLOR
, "MODULATEINVALPHA_ADDCOLOR", D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
, D3DCOLOR_ARGB(0x00, 0x14, 0xff, 0x14)},
12659 {D3DTOP_MODULATEINVCOLOR_ADDALPHA
, "MODULATEINVCOLOR_ADDALPHA", D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
, D3DCOLOR_ARGB(0x00, 0xcc, 0x99, 0xcc)},
12660 /* BUMPENVMAP & BUMPENVMAPLUMINANCE have their own tests */
12661 {D3DTOP_DOTPRODUCT3
, "DOTPRODUCT3", D3DTEXOPCAPS_DOTPRODUCT3
, D3DCOLOR_ARGB(0x00, 0x99, 0x99, 0x99)},
12662 {D3DTOP_MULTIPLYADD
, "MULTIPLYADD", D3DTEXOPCAPS_MULTIPLYADD
, D3DCOLOR_ARGB(0x00, 0xff, 0x33, 0x00)},
12663 {D3DTOP_LERP
, "LERP", D3DTEXOPCAPS_LERP
, D3DCOLOR_ARGB(0x00, 0x00, 0x33, 0x33)},
12666 window
= create_window();
12667 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
12668 ok(!!d3d
, "Failed to create a D3D object.\n");
12669 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
12671 skip("Failed to create a D3D device, skipping tests.\n");
12675 memset(&caps
, 0, sizeof(caps
));
12676 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
12677 ok(SUCCEEDED(hr
), "GetDeviceCaps failed with 0x%08x\n", hr
);
12679 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &vertex_declaration
);
12680 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed with 0x%08x\n", hr
);
12681 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, vertex_declaration
);
12682 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed with 0x%08x\n", hr
);
12684 hr
= IDirect3DDevice9_CreateTexture(device
, 1, 1, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &texture
, NULL
);
12685 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateTexture failed with 0x%08x\n", hr
);
12686 hr
= IDirect3DTexture9_LockRect(texture
, 0, &locked_rect
, NULL
, 0);
12687 ok(SUCCEEDED(hr
), "LockRect failed with 0x%08x\n", hr
);
12688 *((DWORD
*)locked_rect
.pBits
) = D3DCOLOR_ARGB(0x99, 0x00, 0xff, 0x00);
12689 hr
= IDirect3DTexture9_UnlockRect(texture
, 0);
12690 ok(SUCCEEDED(hr
), "UnlockRect failed with 0x%08x\n", hr
);
12691 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)texture
);
12692 ok(SUCCEEDED(hr
), "SetTexture failed with 0x%08x\n", hr
);
12694 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG0
, D3DTA_DIFFUSE
);
12695 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
12696 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
12697 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
12698 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_TFACTOR
);
12699 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
12701 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
12702 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
12704 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
12705 ok(SUCCEEDED(hr
), "SetRenderState failed with 0x%08x\n", hr
);
12706 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_TEXTUREFACTOR
, 0xdd333333);
12707 ok(SUCCEEDED(hr
), "SetRenderState failed with 0x%08x\n", hr
);
12708 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_COLORWRITEENABLE
, D3DCOLORWRITEENABLE_RED
| D3DCOLORWRITEENABLE_GREEN
| D3DCOLORWRITEENABLE_BLUE
| D3DCOLORWRITEENABLE_ALPHA
);
12709 ok(SUCCEEDED(hr
), "SetRenderState failed with 0x%08x\n", hr
);
12711 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x00000000, 1.0f
, 0);
12712 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Clear failed with 0x%08x\n", hr
);
12714 for (i
= 0; i
< ARRAY_SIZE(test_data
); ++i
)
12716 if (!(caps
.TextureOpCaps
& test_data
[i
].caps_flag
))
12718 skip("tex operation %s not supported\n", test_data
[i
].name
);
12722 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, test_data
[i
].op
);
12723 ok(SUCCEEDED(hr
), "SetTextureStageState (%s) failed with 0x%08x\n", test_data
[i
].name
, hr
);
12725 hr
= IDirect3DDevice9_BeginScene(device
);
12726 ok(SUCCEEDED(hr
), "BeginScene failed with 0x%08x\n", hr
);
12728 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
12729 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed with 0x%08x\n", hr
);
12731 hr
= IDirect3DDevice9_EndScene(device
);
12732 ok(SUCCEEDED(hr
), "EndScene failed with 0x%08x\n", hr
);
12734 color
= getPixelColor(device
, 320, 240);
12735 ok(color_match(color
, test_data
[i
].result
, 3), "Operation %s returned color 0x%08x, expected 0x%08x\n",
12736 test_data
[i
].name
, color
, test_data
[i
].result
);
12738 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
12739 ok(SUCCEEDED(hr
), "Present failed with 0x%08x\n", hr
);
12742 IDirect3DTexture9_Release(texture
);
12743 IDirect3DVertexDeclaration9_Release(vertex_declaration
);
12744 refcount
= IDirect3DDevice9_Release(device
);
12745 ok(!refcount
, "Device has %u references left.\n", refcount
);
12747 IDirect3D9_Release(d3d
);
12748 DestroyWindow(window
);
12751 static void yuv_color_test(void)
12754 IDirect3DSurface9
*surface
, *target
;
12759 D3DFORMAT skip_once
= D3DFMT_UNKNOWN
;
12760 IDirect3DDevice9
*device
;
12761 D3DSURFACE_DESC desc
;
12765 static const struct
12769 const char *fmt_string
;
12770 D3DCOLOR left
, right
;
12774 {0x00000000, D3DFMT_UYVY
, "D3DFMT_UYVY", 0x00008700, 0x00008700},
12775 {0xff000000, D3DFMT_UYVY
, "D3DFMT_UYVY", 0x00008700, 0x004bff1c},
12776 {0x00ff0000, D3DFMT_UYVY
, "D3DFMT_UYVY", 0x00b30000, 0x00b30000},
12777 {0x0000ff00, D3DFMT_UYVY
, "D3DFMT_UYVY", 0x004bff1c, 0x00008700},
12778 {0x000000ff, D3DFMT_UYVY
, "D3DFMT_UYVY", 0x000030e1, 0x000030e1},
12779 {0xffff0000, D3DFMT_UYVY
, "D3DFMT_UYVY", 0x00b30000, 0x00ffd01c},
12780 {0xff00ff00, D3DFMT_UYVY
, "D3DFMT_UYVY", 0x004bff1c, 0x004bff1c},
12781 {0xff0000ff, D3DFMT_UYVY
, "D3DFMT_UYVY", 0x000030e1, 0x004bffff},
12782 {0x00ffff00, D3DFMT_UYVY
, "D3DFMT_UYVY", 0x00ffd01c, 0x00b30000},
12783 {0x00ff00ff, D3DFMT_UYVY
, "D3DFMT_UYVY", 0x00b300e1, 0x00b300e1},
12784 {0x0000ffff, D3DFMT_UYVY
, "D3DFMT_UYVY", 0x004bffff, 0x001030e1},
12785 {0xffffff00, D3DFMT_UYVY
, "D3DFMT_UYVY", 0x00ffd01c, 0x00ffd01c},
12786 {0xffff00ff, D3DFMT_UYVY
, "D3DFMT_UYVY", 0x00b300e1, 0x00ff79ff},
12787 {0xffffffff, D3DFMT_UYVY
, "D3DFMT_UYVY", 0x00ff79ff, 0x00ff79ff},
12788 {0x4cff4c54, D3DFMT_UYVY
, "D3DFMT_UYVY", 0x00ff0000, 0x00ff0000},
12789 {0x00800080, D3DFMT_UYVY
, "D3DFMT_UYVY", 0x00000000, 0x00000000},
12790 {0xff80ff80, D3DFMT_UYVY
, "D3DFMT_UYVY", 0x00ffffff, 0x00ffffff},
12791 {0x1c6b1cff, D3DFMT_UYVY
, "D3DFMT_UYVY", 0x000000fd, 0x000000fd},
12793 {0x00000000, D3DFMT_YUY2
, "D3DFMT_YUY2", 0x00008700, 0x00008700},
12794 {0xff000000, D3DFMT_YUY2
, "D3DFMT_YUY2", 0x00b30000, 0x00b30000},
12795 {0x00ff0000, D3DFMT_YUY2
, "D3DFMT_YUY2", 0x00008700, 0x004bff1c},
12796 {0x0000ff00, D3DFMT_YUY2
, "D3DFMT_YUY2", 0x000030e1, 0x000030e1},
12797 {0x000000ff, D3DFMT_YUY2
, "D3DFMT_YUY2", 0x004bff1c, 0x00008700},
12798 {0xffff0000, D3DFMT_YUY2
, "D3DFMT_YUY2", 0x00b30000, 0x00ffd01c},
12799 {0xff00ff00, D3DFMT_YUY2
, "D3DFMT_YUY2", 0x00b300e1, 0x00b300e1},
12800 {0xff0000ff, D3DFMT_YUY2
, "D3DFMT_YUY2", 0x00ffd01c, 0x00b30000},
12801 {0x00ffff00, D3DFMT_YUY2
, "D3DFMT_YUY2", 0x000030e1, 0x004bffff},
12802 {0x00ff00ff, D3DFMT_YUY2
, "D3DFMT_YUY2", 0x004bff1c, 0x004bff1c},
12803 {0x0000ffff, D3DFMT_YUY2
, "D3DFMT_YUY2", 0x004bffff, 0x000030e1},
12804 {0xffffff00, D3DFMT_YUY2
, "D3DFMT_YUY2", 0x00b300e1, 0x00ff79ff},
12805 {0xffff00ff, D3DFMT_YUY2
, "D3DFMT_YUY2", 0x00ffd01c, 0x00ffd01c},
12806 {0xffffffff, D3DFMT_YUY2
, "D3DFMT_YUY2", 0x00ff79ff, 0x00ff79ff},
12807 {0x4cff4c54, D3DFMT_YUY2
, "D3DFMT_YUY2", 0x000b8b00, 0x00b6ffa3},
12808 {0x00800080, D3DFMT_YUY2
, "D3DFMT_YUY2", 0x0000ff00, 0x0000ff00},
12809 {0xff80ff80, D3DFMT_YUY2
, "D3DFMT_YUY2", 0x00ff00ff, 0x00ff00ff},
12810 {0x1c6b1cff, D3DFMT_YUY2
, "D3DFMT_YUY2", 0x006dff45, 0x0000d500},
12813 window
= create_window();
12814 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
12815 ok(!!d3d
, "Failed to create a D3D object.\n");
12816 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
12818 skip("Failed to create a D3D device, skipping tests.\n");
12822 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &target
);
12823 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
12824 hr
= IDirect3DSurface9_GetDesc(target
, &desc
);
12825 ok(SUCCEEDED(hr
), "Failed to get surface description, hr %#x.\n", hr
);
12827 for (i
= 0; i
< ARRAY_SIZE(test_data
); i
++)
12829 /* Some(all?) Windows drivers do not support YUV 3D textures, only 2D surfaces in StretchRect.
12830 * Thus use StretchRect to draw the YUV surface onto the screen instead of drawPrimitive. */
12831 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
,
12832 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_SURFACE
, test_data
[i
].format
)))
12834 if (skip_once
!= test_data
[i
].format
)
12836 skip("%s is not supported.\n", test_data
[i
].fmt_string
);
12837 skip_once
= test_data
[i
].format
;
12841 if (FAILED(IDirect3D9_CheckDeviceFormatConversion(d3d
, 0,
12842 D3DDEVTYPE_HAL
, test_data
[i
].format
, desc
.Format
)))
12844 if (skip_once
!= test_data
[i
].format
)
12846 skip("Driver cannot blit %s surfaces.\n", test_data
[i
].fmt_string
);
12847 skip_once
= test_data
[i
].format
;
12852 /* A pixel is effectively 16 bit large, but two pixels are stored together, so the minimum size is 2x1.
12853 * However, Nvidia Windows drivers have problems with 2x1 YUY2/UYVY surfaces, so use a 4x1 surface and
12854 * fill the second block with dummy data. If the surface has a size of 2x1, those drivers ignore the
12855 * second luminance value, resulting in an incorrect color in the right pixel. */
12856 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 4, 1, test_data
[i
].format
,
12857 D3DPOOL_DEFAULT
, &surface
, NULL
);
12858 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
12861 hr
= IDirect3DSurface9_LockRect(surface
, &lr
, NULL
, 0);
12862 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
12863 ((DWORD
*)lr
.pBits
)[0] = test_data
[i
].in
;
12864 ((DWORD
*)lr
.pBits
)[1] = 0x00800080;
12865 hr
= IDirect3DSurface9_UnlockRect(surface
);
12866 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
12868 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00000000, 1.0f
, 0);
12869 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
12870 hr
= IDirect3DDevice9_StretchRect(device
, surface
, NULL
, target
, NULL
, D3DTEXF_POINT
);
12871 ok(SUCCEEDED(hr
), "Failed to draw surface onto backbuffer, hr %#x.\n", hr
);
12873 /* Some Windows drivers (mostly Nvidia, but also some VM drivers) insist on doing linear filtering
12874 * although we asked for point filtering. Be careful when reading the results and use the pixel
12875 * centers. In the future we may want to add tests for the filtered pixels as well.
12877 * Unfortunately different implementations(Windows-Nvidia and Mac-AMD tested) interpret some colors
12878 * vastly differently, so we need a max diff of 18. */
12879 color
= getPixelColor(device
, 1, 240);
12880 ok(color_match(color
, test_data
[i
].left
, 18),
12881 "Input 0x%08x: Got color 0x%08x for pixel 1/1, expected 0x%08x, format %s.\n",
12882 test_data
[i
].in
, color
, test_data
[i
].left
, test_data
[i
].fmt_string
);
12883 color
= getPixelColor(device
, 318, 240);
12884 ok(color_match(color
, test_data
[i
].right
, 18),
12885 "Input 0x%08x: Got color 0x%08x for pixel 2/1, expected 0x%08x, format %s.\n",
12886 test_data
[i
].in
, color
, test_data
[i
].right
, test_data
[i
].fmt_string
);
12887 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
12888 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
12889 IDirect3DSurface9_Release(surface
);
12892 IDirect3DSurface9_Release(target
);
12893 refcount
= IDirect3DDevice9_Release(device
);
12894 ok(!refcount
, "Device has %u references left.\n", refcount
);
12896 IDirect3D9_Release(d3d
);
12897 DestroyWindow(window
);
12900 static void yuv_layout_test(void)
12903 IDirect3DSurface9
*surface
, *target
;
12904 unsigned int fmt
, i
, x
, y
;
12906 const char *fmt_string
;
12911 BYTE
*buf
, *chroma_buf
, *u_buf
, *v_buf
;
12912 UINT width
= 20, height
= 16;
12913 IDirect3DDevice9
*device
;
12916 D3DSURFACE_DESC desc
;
12919 static const struct
12921 DWORD color1
, color2
;
12926 { 0x000000, 0xffffff, 0x00008800, 0x00ff7dff },
12927 { 0xff0000, 0x00ffff, 0x004aff14, 0x00b800ee },
12928 { 0x00ff00, 0xff00ff, 0x000024ee, 0x00ffe114 },
12929 { 0x0000ff, 0xffff00, 0x00b80000, 0x004affff },
12930 { 0xffff00, 0x0000ff, 0x004affff, 0x00b80000 },
12931 { 0xff00ff, 0x00ff00, 0x00ffe114, 0x000024ee },
12932 { 0x00ffff, 0xff0000, 0x00b800ee, 0x004aff14 },
12933 { 0xffffff, 0x000000, 0x00ff7dff, 0x00008800 },
12936 static const struct
12943 { D3DFMT_UYVY
, "D3DFMT_UYVY", },
12944 { D3DFMT_YUY2
, "D3DFMT_YUY2", },
12945 { MAKEFOURCC('Y','V','1','2'), "D3DFMT_YV12", },
12946 { MAKEFOURCC('N','V','1','2'), "D3DFMT_NV12", },
12949 window
= create_window();
12950 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
12951 ok(!!d3d
, "Failed to create a D3D object.\n");
12952 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
12954 skip("Failed to create a D3D device, skipping tests.\n");
12958 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
12959 ok(SUCCEEDED(hr
), "GetDeviceCaps failed, hr %#x.\n", hr
);
12960 if (caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
12961 && !(caps
.TextureCaps
& D3DPTEXTURECAPS_NONPOW2CONDITIONAL
))
12963 skip("No NP2 texture support, skipping YUV texture layout test.\n");
12964 IDirect3DDevice9_Release(device
);
12968 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &target
);
12969 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderTarget failed, hr = %#x.\n", hr
);
12970 hr
= IDirect3DSurface9_GetDesc(target
, &desc
);
12971 ok(SUCCEEDED(hr
), "Failed to get surface description, hr %#x.\n", hr
);
12973 for (fmt
= 0; fmt
< ARRAY_SIZE(formats
); fmt
++)
12975 format
= formats
[fmt
].format
;
12976 fmt_string
= formats
[fmt
].str
;
12978 /* Some (all?) Windows drivers do not support YUV 3D textures, only 2D surfaces in
12979 * StretchRect. Thus use StretchRect to draw the YUV surface onto the screen instead
12980 * of drawPrimitive. */
12981 if (IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
, 0,
12982 D3DRTYPE_SURFACE
, format
) != D3D_OK
)
12984 skip("%s is not supported.\n", fmt_string
);
12987 if (FAILED(IDirect3D9_CheckDeviceFormatConversion(d3d
, 0,
12988 D3DDEVTYPE_HAL
, format
, desc
.Format
)))
12990 skip("Driver cannot blit %s surfaces.\n", fmt_string
);
12994 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, width
, height
, format
, D3DPOOL_DEFAULT
, &surface
, NULL
);
12995 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateOffscreenPlainSurface failed, hr = %#x.\n", hr
);
12997 for (i
= 0; i
< ARRAY_SIZE(test_data
); i
++)
12999 hr
= IDirect3DSurface9_LockRect(surface
, &lr
, NULL
, 0);
13000 ok(hr
== D3D_OK
, "IDirect3DSurface9_LockRect failed, hr = %#x.\n", hr
);
13002 chroma_buf
= buf
+ lr
.Pitch
* height
;
13003 if (format
== MAKEFOURCC('Y','V','1','2'))
13005 v_buf
= chroma_buf
;
13006 u_buf
= chroma_buf
+ height
/ 2 * lr
.Pitch
/2;
13008 /* Draw the top left quarter of the screen with color1, the rest with color2 */
13009 for (y
= 0; y
< height
; y
++)
13011 for (x
= 0; x
< width
; x
+= 2)
13013 DWORD color
= (x
< width
/ 2 && y
< height
/ 2) ? test_data
[i
].color1
: test_data
[i
].color2
;
13014 BYTE Y
= (color
>> 16) & 0xff;
13015 BYTE U
= (color
>> 8) & 0xff;
13016 BYTE V
= (color
>> 0) & 0xff;
13017 if (format
== D3DFMT_UYVY
)
13019 buf
[y
* lr
.Pitch
+ 2 * x
+ 0] = U
;
13020 buf
[y
* lr
.Pitch
+ 2 * x
+ 1] = Y
;
13021 buf
[y
* lr
.Pitch
+ 2 * x
+ 2] = V
;
13022 buf
[y
* lr
.Pitch
+ 2 * x
+ 3] = Y
;
13024 else if (format
== D3DFMT_YUY2
)
13026 buf
[y
* lr
.Pitch
+ 2 * x
+ 0] = Y
;
13027 buf
[y
* lr
.Pitch
+ 2 * x
+ 1] = U
;
13028 buf
[y
* lr
.Pitch
+ 2 * x
+ 2] = Y
;
13029 buf
[y
* lr
.Pitch
+ 2 * x
+ 3] = V
;
13031 else if (format
== MAKEFOURCC('Y','V','1','2'))
13033 buf
[y
* lr
.Pitch
+ x
+ 0] = Y
;
13034 buf
[y
* lr
.Pitch
+ x
+ 1] = Y
;
13035 u_buf
[(y
/ 2) * (lr
.Pitch
/ 2) + (x
/ 2)] = U
;
13036 v_buf
[(y
/ 2) * (lr
.Pitch
/ 2) + (x
/ 2)] = V
;
13038 else if (format
== MAKEFOURCC('N','V','1','2'))
13040 buf
[y
* lr
.Pitch
+ x
+ 0] = Y
;
13041 buf
[y
* lr
.Pitch
+ x
+ 1] = Y
;
13042 chroma_buf
[(y
/ 2) * lr
.Pitch
+ 2 * (x
/ 2) + 0] = U
;
13043 chroma_buf
[(y
/ 2) * lr
.Pitch
+ 2 * (x
/ 2) + 1] = V
;
13047 hr
= IDirect3DSurface9_UnlockRect(surface
);
13048 ok(hr
== D3D_OK
, "IDirect3DSurface9_UnlockRect failed, hr = %#x.\n", hr
);
13050 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00000000, 1.0f
, 0);
13051 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %#x.\n", hr
);
13052 hr
= IDirect3DDevice9_StretchRect(device
, surface
, NULL
, target
, NULL
, D3DTEXF_POINT
);
13053 ok(hr
== D3D_OK
, "IDirect3DDevice9_StretchRect failed with %#x.\n", hr
);
13055 /* Some Windows drivers (mostly Nvidia, but also some VM drivers) insist on doing linear filtering
13056 * although we asked for point filtering. To prevent running into precision problems, read at points
13057 * with some margin within each quadrant.
13059 * Unfortunately different implementations(Windows-Nvidia and Mac-AMD tested) interpret some colors
13060 * vastly differently, so we need a max diff of 18. */
13061 for (y
= 0; y
< 4; y
++)
13063 for (x
= 0; x
< 4; x
++)
13065 UINT xcoord
= (1 + 2 * x
) * 640 / 8;
13066 UINT ycoord
= (1 + 2 * y
) * 480 / 8;
13067 ref_color
= (y
< 2 && x
< 2) ? test_data
[i
].rgb1
: test_data
[i
].rgb2
;
13068 color
= getPixelColor(device
, xcoord
, ycoord
);
13069 ok(color_match(color
, ref_color
, 18),
13070 "Format %s: Got color %#x for pixel (%d/%d)/(%d/%d), pixel %d %d, expected %#x.\n",
13071 fmt_string
, color
, x
, 4, y
, 4, xcoord
, ycoord
, ref_color
);
13074 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
13076 ok(SUCCEEDED(hr
), "Present failed with %#x.\n", hr
);
13078 IDirect3DSurface9_Release(surface
);
13081 IDirect3DSurface9_Release(target
);
13082 refcount
= IDirect3DDevice9_Release(device
);
13083 ok(!refcount
, "Device has %u references left.\n", refcount
);
13085 IDirect3D9_Release(d3d
);
13086 DestroyWindow(window
);
13089 static void texop_range_test(void)
13091 IDirect3DTexture9
*texture
;
13092 D3DLOCKED_RECT locked_rect
;
13093 IDirect3DDevice9
*device
;
13101 static const struct
13108 {-1.0f
, -1.0f
, 0.1f
, D3DCOLOR_ARGB(0xff, 0xff, 0xff, 0xff)},
13109 {-1.0f
, 1.0f
, 0.1f
, D3DCOLOR_ARGB(0xff, 0xff, 0xff, 0xff)},
13110 { 1.0f
, -1.0f
, 0.1f
, D3DCOLOR_ARGB(0xff, 0xff, 0xff, 0xff)},
13111 { 1.0f
, 1.0f
, 0.1f
, D3DCOLOR_ARGB(0xff, 0xff, 0xff, 0xff)}
13114 window
= create_window();
13115 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
13116 ok(!!d3d
, "Failed to create a D3D object.\n");
13117 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
13119 skip("Failed to create a D3D device, skipping tests.\n");
13123 /* We need ADD and SUBTRACT operations */
13124 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
13125 ok(SUCCEEDED(hr
), "GetDeviceCaps failed with 0x%08x\n", hr
);
13126 if (!(caps
.TextureOpCaps
& D3DTEXOPCAPS_ADD
))
13128 skip("D3DTOP_ADD is not supported, skipping value range test.\n");
13129 IDirect3DDevice9_Release(device
);
13132 if (!(caps
.TextureOpCaps
& D3DTEXOPCAPS_SUBTRACT
))
13134 skip("D3DTEXOPCAPS_SUBTRACT is not supported, skipping value range test.\n");
13135 IDirect3DDevice9_Release(device
);
13139 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
13140 ok(SUCCEEDED(hr
), "SetFVF failed with 0x%08x\n", hr
);
13141 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
13142 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
13143 /* Stage 1: result = diffuse(=1.0) + diffuse
13144 * stage 2: result = result - tfactor(= 0.5)
13146 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_TEXTUREFACTOR
, 0x80808080);
13147 ok(SUCCEEDED(hr
), "SetRenderState failed with 0x%08x\n", hr
);
13148 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_DIFFUSE
);
13149 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
13150 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_DIFFUSE
);
13151 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
13152 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_ADD
);
13153 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
13154 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLORARG1
, D3DTA_CURRENT
);
13155 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
13156 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLORARG2
, D3DTA_TFACTOR
);
13157 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
13158 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_SUBTRACT
);
13159 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
13161 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x00000000, 1.0f
, 0);
13162 ok(SUCCEEDED(hr
), "Failed to clear device, hr %#x.\n\n", hr
);
13163 hr
= IDirect3DDevice9_BeginScene(device
);
13164 ok(SUCCEEDED(hr
), "BeginScene failed with 0x%08x\n", hr
);
13165 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
13166 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed with 0x%08x\n", hr
);
13167 hr
= IDirect3DDevice9_EndScene(device
);
13168 ok(SUCCEEDED(hr
), "EndScene failed with 0x%08x\n", hr
);
13170 color
= getPixelColor(device
, 320, 240);
13171 ok(color_match(color
, 0x00808080, 1), "texop Range > 1.0 returned 0x%08x, expected 0x00808080\n",
13173 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
13174 ok(SUCCEEDED(hr
), "Present failed with 0x%08x\n", hr
);
13176 hr
= IDirect3DDevice9_CreateTexture(device
, 1, 1, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &texture
, NULL
);
13177 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateTexture failed with 0x%08x\n", hr
);
13178 hr
= IDirect3DTexture9_LockRect(texture
, 0, &locked_rect
, NULL
, 0);
13179 ok(SUCCEEDED(hr
), "LockRect failed with 0x%08x\n", hr
);
13180 *((DWORD
*)locked_rect
.pBits
) = D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00);
13181 hr
= IDirect3DTexture9_UnlockRect(texture
, 0);
13182 ok(SUCCEEDED(hr
), "UnlockRect failed with 0x%08x\n", hr
);
13183 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)texture
);
13184 ok(SUCCEEDED(hr
), "SetTexture failed with 0x%08x\n", hr
);
13186 /* Stage 1: result = texture(=0.0) - tfactor(= 0.5)
13187 * stage 2: result = result + diffuse(1.0)
13189 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_TEXTUREFACTOR
, 0x80808080);
13190 ok(SUCCEEDED(hr
), "SetRenderState failed with 0x%08x\n", hr
);
13191 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
13192 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
13193 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_TFACTOR
);
13194 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
13195 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SUBTRACT
);
13196 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
13197 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLORARG1
, D3DTA_CURRENT
);
13198 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
13199 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLORARG2
, D3DTA_DIFFUSE
);
13200 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
13201 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_ADD
);
13202 ok(SUCCEEDED(hr
), "SetTextureStageState failed with 0x%08x\n", hr
);
13204 hr
= IDirect3DDevice9_BeginScene(device
);
13205 ok(SUCCEEDED(hr
), "BeginScene failed with 0x%08x\n", hr
);
13206 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
13207 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed with 0x%08x\n", hr
);
13208 hr
= IDirect3DDevice9_EndScene(device
);
13209 ok(SUCCEEDED(hr
), "EndScene failed with 0x%08x\n", hr
);
13211 color
= getPixelColor(device
, 320, 240);
13212 ok(color_match(color
, 0x00ffffff, 1), "texop Range < 0.0 returned 0x%08x, expected 0x00ffffff\n",
13214 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
13215 ok(SUCCEEDED(hr
), "Present failed with 0x%08x\n", hr
);
13217 IDirect3DTexture9_Release(texture
);
13218 refcount
= IDirect3DDevice9_Release(device
);
13219 ok(!refcount
, "Device has %u references left.\n", refcount
);
13221 IDirect3D9_Release(d3d
);
13222 DestroyWindow(window
);
13225 static void alphareplicate_test(void)
13227 IDirect3DDevice9
*device
;
13234 static const struct
13236 struct vec3 position
;
13241 {{-1.0f
, -1.0f
, 0.1f
}, 0x80ff00ff},
13242 {{-1.0f
, 1.0f
, 0.1f
}, 0x80ff00ff},
13243 {{ 1.0f
, -1.0f
, 0.1f
}, 0x80ff00ff},
13244 {{ 1.0f
, 1.0f
, 0.1f
}, 0x80ff00ff},
13247 window
= create_window();
13248 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
13249 ok(!!d3d
, "Failed to create a D3D object.\n");
13250 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
13252 skip("Failed to create a D3D device, skipping tests.\n");
13256 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x00000000, 1.0f
, 0);
13257 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr
);
13259 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
13260 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with 0x%08x\n", hr
);
13262 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
13263 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr
);
13264 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_DIFFUSE
| D3DTA_ALPHAREPLICATE
);
13265 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr
);
13267 hr
= IDirect3DDevice9_BeginScene(device
);
13268 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
13269 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
13270 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
13271 hr
= IDirect3DDevice9_EndScene(device
);
13272 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
13274 color
= getPixelColor(device
, 320, 240);
13275 ok(color_match(color
, 0x00808080, 1), "alphareplicate test 0x%08x, expected 0x00808080\n",
13277 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
13278 ok(SUCCEEDED(hr
), "Present failed with 0x%08x\n", hr
);
13280 refcount
= IDirect3DDevice9_Release(device
);
13281 ok(!refcount
, "Device has %u references left.\n", refcount
);
13283 IDirect3D9_Release(d3d
);
13284 DestroyWindow(window
);
13287 static void dp3_alpha_test(void)
13289 IDirect3DDevice9
*device
;
13297 static const struct
13299 struct vec3 position
;
13304 {{-1.0f
, -1.0f
, 0.1f
}, 0x408080c0},
13305 {{-1.0f
, 1.0f
, 0.1f
}, 0x408080c0},
13306 {{ 1.0f
, -1.0f
, 0.1f
}, 0x408080c0},
13307 {{ 1.0f
, 1.0f
, 0.1f
}, 0x408080c0},
13310 window
= create_window();
13311 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
13312 ok(!!d3d
, "Failed to create a D3D object.\n");
13313 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
13315 skip("Failed to create a D3D device, skipping tests.\n");
13319 memset(&caps
, 0, sizeof(caps
));
13320 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
13321 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
13322 if (!(caps
.TextureOpCaps
& D3DTEXOPCAPS_DOTPRODUCT3
))
13324 skip("D3DTOP_DOTPRODUCT3 not supported\n");
13325 IDirect3DDevice9_Release(device
);
13329 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x00000000, 1.0f
, 0);
13330 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr
);
13332 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
13333 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with 0x%08x\n", hr
);
13335 /* dp3_x4 r0, diffuse_bias, tfactor_bias
13336 * mov r0.a, diffuse.a
13339 * It turns out that the 2nd line is ignored, and the dp3 result written into r0.a instead
13340 * 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
13341 * (0.0 * 0.5 + 0.0 * 0.5 + 0.25 * 0.5) * 4 = 0.125 * 4 = 0.5, with a bunch of inprecision.
13343 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_DOTPRODUCT3
);
13344 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr
);
13345 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_DIFFUSE
);
13346 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr
);
13347 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_TFACTOR
);
13348 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr
);
13349 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
);
13350 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr
);
13351 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_ALPHAARG1
, D3DTA_DIFFUSE
);
13352 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr
);
13353 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
13354 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr
);
13355 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLORARG1
, D3DTA_CURRENT
| D3DTA_ALPHAREPLICATE
);
13356 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr
);
13357 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_ALPHAOP
, D3DTOP_DISABLE
);
13358 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed with 0x%08x\n", hr
);
13359 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_TEXTUREFACTOR
, 0xffffffff);
13360 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr
);
13361 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
13362 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
13364 hr
= IDirect3DDevice9_BeginScene(device
);
13365 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
13366 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
13367 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
13368 hr
= IDirect3DDevice9_EndScene(device
);
13369 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
13371 color
= getPixelColor(device
, 320, 240);
13372 ok(color_match(color
, 0x00808080, 4), "dp3 alpha test 0x%08x, expected 0x00808080\n",
13374 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
13375 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Present failed with 0x%08x\n", hr
);
13377 refcount
= IDirect3DDevice9_Release(device
);
13378 ok(!refcount
, "Device has %u references left.\n", refcount
);
13380 IDirect3D9_Release(d3d
);
13381 DestroyWindow(window
);
13384 static void zwriteenable_test(void)
13386 IDirect3DDevice9
*device
;
13393 static const struct
13395 struct vec3 position
;
13400 {{-1.0f
, -1.0f
, 0.1f
}, 0x00ff0000},
13401 {{-1.0f
, 1.0f
, 0.1f
}, 0x00ff0000},
13402 {{ 1.0f
, -1.0f
, 0.1f
}, 0x00ff0000},
13403 {{ 1.0f
, 1.0f
, 0.1f
}, 0x00ff0000},
13407 {{-1.0f
, -1.0f
, 0.9f
}, 0x0000ff00},
13408 {{-1.0f
, 1.0f
, 0.9f
}, 0x0000ff00},
13409 {{ 1.0f
, -1.0f
, 0.9f
}, 0x0000ff00},
13410 {{ 1.0f
, 1.0f
, 0.9f
}, 0x0000ff00},
13413 window
= create_window();
13414 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
13415 ok(!!d3d
, "Failed to create a D3D object.\n");
13416 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
13418 skip("Failed to create a D3D device, skipping tests.\n");
13422 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x000000ff, 1.0f
, 0);
13423 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr
);
13425 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
13426 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with 0x%08x\n", hr
);
13427 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_FALSE
);
13428 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr
);
13429 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, TRUE
);
13430 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr
);
13431 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_LESSEQUAL
);
13432 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr
);
13433 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
13434 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
13436 hr
= IDirect3DDevice9_BeginScene(device
);
13437 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
13438 /* The Z buffer is filled with 1.0. Draw a red quad with z = 0.1,
13439 * zenable = D3DZB_FALSE, zwriteenable = TRUE. The red color is written
13440 * because the z test is disabled. The question is whether the z = 0.1
13441 * values are written into the Z buffer. After the draw, set
13442 * zenable = TRUE and draw a green quad at z = 0.9. If the values are
13443 * written, the z test will fail(0.9 > 0.1) and the red color remains. If
13444 * the values are not written, the z test succeeds(0.9 < 1.0) and the
13445 * green color is written. It turns out that the screen is green, so
13446 * zenable = D3DZB_FALSE and zwriteenable = TRUE does NOT write to the z
13448 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(*quad1
));
13449 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
13450 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_TRUE
);
13451 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
13452 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(*quad2
));
13453 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
13454 hr
= IDirect3DDevice9_EndScene(device
);
13455 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
13457 color
= getPixelColor(device
, 320, 240);
13458 ok(color_match(color
, 0x0000ff00, 1), "zwriteenable test returned 0x%08x, expected 0x0000ff00\n",
13460 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
13461 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Present failed with 0x%08x\n", hr
);
13463 refcount
= IDirect3DDevice9_Release(device
);
13464 ok(!refcount
, "Device has %u references left.\n", refcount
);
13466 IDirect3D9_Release(d3d
);
13467 DestroyWindow(window
);
13470 static void alphatest_test(void)
13472 #define ALPHATEST_PASSED 0x0000ff00
13473 #define ALPHATEST_FAILED 0x00ff0000
13474 IDirect3DDevice9
*device
;
13483 static const struct
13486 D3DCOLOR color_less
;
13487 D3DCOLOR color_equal
;
13488 D3DCOLOR color_greater
;
13492 {D3DCMP_NEVER
, ALPHATEST_FAILED
, ALPHATEST_FAILED
, ALPHATEST_FAILED
},
13493 {D3DCMP_LESS
, ALPHATEST_PASSED
, ALPHATEST_FAILED
, ALPHATEST_FAILED
},
13494 {D3DCMP_EQUAL
, ALPHATEST_FAILED
, ALPHATEST_PASSED
, ALPHATEST_FAILED
},
13495 {D3DCMP_LESSEQUAL
, ALPHATEST_PASSED
, ALPHATEST_PASSED
, ALPHATEST_FAILED
},
13496 {D3DCMP_GREATER
, ALPHATEST_FAILED
, ALPHATEST_FAILED
, ALPHATEST_PASSED
},
13497 {D3DCMP_NOTEQUAL
, ALPHATEST_PASSED
, ALPHATEST_FAILED
, ALPHATEST_PASSED
},
13498 {D3DCMP_GREATEREQUAL
, ALPHATEST_FAILED
, ALPHATEST_PASSED
, ALPHATEST_PASSED
},
13499 {D3DCMP_ALWAYS
, ALPHATEST_PASSED
, ALPHATEST_PASSED
, ALPHATEST_PASSED
},
13501 static const struct
13503 struct vec3 position
;
13508 {{-1.0f
, -1.0f
, 0.1f
}, ALPHATEST_PASSED
| 0x80000000},
13509 {{-1.0f
, 1.0f
, 0.1f
}, ALPHATEST_PASSED
| 0x80000000},
13510 {{ 1.0f
, -1.0f
, 0.1f
}, ALPHATEST_PASSED
| 0x80000000},
13511 {{ 1.0f
, 1.0f
, 0.1f
}, ALPHATEST_PASSED
| 0x80000000},
13514 window
= create_window();
13515 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
13516 ok(!!d3d
, "Failed to create a D3D object.\n");
13517 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
13519 skip("Failed to create a D3D device, skipping tests.\n");
13523 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff0000ff, 1.0f
, 0);
13524 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
13526 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
13527 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
13528 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ALPHATESTENABLE
, TRUE
);
13529 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr
);
13530 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
13531 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with 0x%08x\n", hr
);
13533 for (j
= 0; j
< 2; ++j
)
13537 /* Try a pixel shader instead of fixed function. The wined3d code
13538 * may emulate the alpha test either for performance reasons
13539 * (floating point RTs) or to work around driver bugs (GeForce
13540 * 7x00 cards on MacOS). There may be a different codepath for ffp
13541 * and shader in this case, and the test should cover both. */
13542 IDirect3DPixelShader9
*ps
;
13543 static const DWORD shader_code
[] =
13545 0xffff0101, /* ps_1_1 */
13546 0x00000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
13547 0x0000ffff /* end */
13549 memset(&caps
, 0, sizeof(caps
));
13550 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
13551 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetDeviceCaps failed with 0x%08x\n", hr
);
13552 if(caps
.PixelShaderVersion
< D3DPS_VERSION(1, 1)) {
13556 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code
, &ps
);
13557 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader failed with 0x%08x\n", hr
);
13558 hr
= IDirect3DDevice9_SetPixelShader(device
, ps
);
13559 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader failed with 0x%08x\n", hr
);
13560 IDirect3DPixelShader9_Release(ps
);
13563 for(i
= 0; i
< ARRAY_SIZE(testdata
); i
++)
13565 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ALPHAFUNC
, testdata
[i
].func
);
13566 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr
);
13568 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, ALPHATEST_FAILED
, 0.0, 0);
13569 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr
);
13570 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ALPHAREF
, 0x90);
13571 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr
);
13572 hr
= IDirect3DDevice9_BeginScene(device
);
13573 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
13574 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
13575 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
13576 hr
= IDirect3DDevice9_EndScene(device
);
13577 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
13578 color
= getPixelColor(device
, 320, 240);
13579 ok(color_match(color
, testdata
[i
].color_less
, 1), "Alphatest failed. Got color 0x%08x, expected 0x%08x. alpha < ref, func %u\n",
13580 color
, testdata
[i
].color_less
, testdata
[i
].func
);
13581 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
13582 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Present failed with 0x%08x\n", hr
);
13584 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, ALPHATEST_FAILED
, 0.0, 0);
13585 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr
);
13586 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ALPHAREF
, 0x80);
13587 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr
);
13588 hr
= IDirect3DDevice9_BeginScene(device
);
13589 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
13590 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
13591 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
13592 hr
= IDirect3DDevice9_EndScene(device
);
13593 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
13594 color
= getPixelColor(device
, 320, 240);
13595 ok(color_match(color
, testdata
[i
].color_equal
, 1), "Alphatest failed. Got color 0x%08x, expected 0x%08x. alpha == ref, func %u\n",
13596 color
, testdata
[i
].color_equal
, testdata
[i
].func
);
13597 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
13598 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Present failed with 0x%08x\n", hr
);
13600 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, ALPHATEST_FAILED
, 0.0, 0);
13601 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr
);
13602 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ALPHAREF
, 0x70);
13603 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed with 0x%08x\n", hr
);
13604 hr
= IDirect3DDevice9_BeginScene(device
);
13605 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
13606 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
13607 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
13608 hr
= IDirect3DDevice9_EndScene(device
);
13609 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
13610 color
= getPixelColor(device
, 320, 240);
13611 ok(color_match(color
, testdata
[i
].color_greater
, 1), "Alphatest failed. Got color 0x%08x, expected 0x%08x. alpha > ref, func %u\n",
13612 color
, testdata
[i
].color_greater
, testdata
[i
].func
);
13613 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
13614 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Present failed with 0x%08x\n", hr
);
13618 refcount
= IDirect3DDevice9_Release(device
);
13619 ok(!refcount
, "Device has %u references left.\n", refcount
);
13621 IDirect3D9_Release(d3d
);
13622 DestroyWindow(window
);
13625 static void sincos_test(void)
13627 IDirect3DVertexShader9
*sin_shader
, *cos_shader
;
13628 IDirect3DDevice9
*device
;
13629 struct vec3 data
[1280];
13637 static const DWORD sin_shader_code
[] =
13639 0xfffe0200, /* vs_2_0 */
13640 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
13641 0x05000051, 0xa00f0002, 0x40490fdb, 0x3f800000, 0x00000000, 0x3f59999a, /* def c2, 3.14159, 1, 0, 0.85 */
13642 0x03000005, 0x80010001, 0x90000000, 0xa0000002, /* mul r1.x, v0.x, c2.x */
13643 0x04000025, 0x80020000, 0x80000001, 0xa0e40000, 0xa0e40001, /* sincos r0.y, r1.x, c0, c1 */
13644 0x02000001, 0xc00d0000, 0x90e40000, /* mov oPos.xzw, v0 */
13645 0x03000005, 0xc0020000, 0x80550000, 0xa0ff0002, /* mul oPos.y, r0.y, c2.w */
13646 0x02000001, 0xd00f0000, 0xa0a60002, /* mov oD0, c2.zyzz */
13647 0x0000ffff /* end */
13649 static const DWORD cos_shader_code
[] =
13651 0xfffe0200, /* vs_2_0 */
13652 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
13653 0x05000051, 0xa00f0002, 0x40490fdb, 0x3f800000, 0x00000000, 0x3f59999a, /* def c2, 3.14159, 1, 0, 0.85 */
13654 0x03000005, 0x80010001, 0x90000000, 0xa0000002, /* mul r1.x, v0.x, c2.x */
13655 0x04000025, 0x80010000, 0x80000001, 0xa0e40000, 0xa0e40001, /* sincos r0.x, r1.x, c0, c1 */
13656 0x02000001, 0xc00d0000, 0x90e40000, /* mov oPos.xzw, v0 */
13657 0x03000005, 0xc0020000, 0x80000000, 0xa0ff0002, /* mul oPos.y, r0.x, c2.w */
13658 0x02000001, 0xd00f0000, 0xa0a90002, /* mov oD0, c2.yzzz */
13659 0x0000ffff /* end */
13661 static const float sincosc1
[4] = {D3DSINCOSCONST1
};
13662 static const float sincosc2
[4] = {D3DSINCOSCONST2
};
13664 window
= create_window();
13665 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
13666 ok(!!d3d
, "Failed to create a D3D object.\n");
13667 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
13669 skip("Failed to create a D3D device, skipping tests.\n");
13673 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
13674 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
13675 if (caps
.VertexShaderVersion
< D3DVS_VERSION(2, 0))
13677 skip("No vs_2_0 support, skipping tests.\n");
13678 IDirect3DDevice9_Release(device
);
13682 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x00000000, 1.0f
, 0);
13683 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr
);
13685 hr
= IDirect3DDevice9_CreateVertexShader(device
, sin_shader_code
, &sin_shader
);
13686 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr
);
13687 hr
= IDirect3DDevice9_CreateVertexShader(device
, cos_shader_code
, &cos_shader
);
13688 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with 0x%08x\n", hr
);
13689 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
13690 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with 0x%08x\n", hr
);
13691 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 0, sincosc1
, 1);
13692 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShaderConstantF failed with 0x%08x\n", hr
);
13693 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 1, sincosc2
, 1);
13694 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShaderConstantF failed with 0x%08x\n", hr
);
13696 /* Generate a point from -1 to 1 every 0.5 pixels */
13697 for(i
= 0; i
< 1280; i
++) {
13698 data
[i
].x
= (-640.0 + i
) / 640.0;
13703 hr
= IDirect3DDevice9_BeginScene(device
);
13704 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
13706 hr
= IDirect3DDevice9_SetVertexShader(device
, sin_shader
);
13707 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
13708 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_POINTLIST
, 1280, data
, sizeof(*data
));
13709 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
13711 hr
= IDirect3DDevice9_SetVertexShader(device
, cos_shader
);
13712 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
13713 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_POINTLIST
, 1280, data
, sizeof(*data
));
13714 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
13716 hr
= IDirect3DDevice9_EndScene(device
);
13717 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
13719 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
13720 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Present returned %#x.\n", hr
);
13721 /* TODO: Find a way to properly validate the lines. Precicion issues make this a kinda nasty task */
13723 IDirect3DVertexShader9_Release(sin_shader
);
13724 IDirect3DVertexShader9_Release(cos_shader
);
13725 refcount
= IDirect3DDevice9_Release(device
);
13726 ok(!refcount
, "Device has %u references left.\n", refcount
);
13728 IDirect3D9_Release(d3d
);
13729 DestroyWindow(window
);
13732 static void loop_index_test(void)
13734 IDirect3DVertexShader9
*shader
;
13735 IDirect3DDevice9
*device
;
13744 static const DWORD shader_code
[] =
13746 0xfffe0200, /* vs_2_0 */
13747 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
13748 0x02000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
13749 0x0200001b, 0xf0e40800, 0xf0e40000, /* loop aL, i0 */
13750 0x04000002, 0x800f0000, 0x80e40000, 0xa0e42001, 0xf0e40800, /* add r0, r0, c[aL + 1] */
13751 0x0000001d, /* endloop */
13752 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
13753 0x02000001, 0xd00f0000, 0x80e40000, /* mov oD0, r0 */
13754 0x0000ffff /* END */
13756 static const float quad
[] =
13758 -1.0f
, -1.0f
, 0.1f
,
13763 static const float zero
[4] = {0.0f
, 0.0f
, 0.0f
, 0.0f
};
13764 static const float one
[4] = {1.0f
, 1.0f
, 1.0f
, 1.0f
};
13765 static const int i0
[4] = {2, 10, -3, 0};
13767 window
= create_window();
13768 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
13769 ok(!!d3d
, "Failed to create a D3D object.\n");
13770 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
13772 skip("Failed to create a D3D device, skipping tests.\n");
13776 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
13777 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
13778 if (caps
.VertexShaderVersion
< D3DVS_VERSION(2, 0))
13780 skip("No vs_2_0 support, skipping tests.\n");
13781 IDirect3DDevice9_Release(device
);
13785 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_code
, &shader
);
13786 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader failed with %08x\n", hr
);
13787 hr
= IDirect3DDevice9_SetVertexShader(device
, shader
);
13788 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader failed with %08x\n", hr
);
13789 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
13790 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with %08x\n", hr
);
13791 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x00ff0000, 1.0f
, 0);
13792 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
13794 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 0, zero
, 1);
13795 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr
);
13796 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 1, one
, 1);
13797 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr
);
13798 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 2, one
, 1);
13799 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr
);
13800 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 3, one
, 1);
13801 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr
);
13802 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 4, one
, 1);
13803 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr
);
13804 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 5, one
, 1);
13805 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr
);
13806 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 6, one
, 1);
13807 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr
);
13808 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 7, one
, 1);
13809 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr
);
13814 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 8, values
, 1);
13815 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr
);
13816 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 9, one
, 1);
13817 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr
);
13818 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 10, one
, 1);
13819 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr
);
13824 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 11, values
, 1);
13825 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr
);
13826 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 12, one
, 1);
13827 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr
);
13828 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 13, one
, 1);
13829 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr
);
13830 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 14, one
, 1);
13831 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr
);
13832 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 15, one
, 1);
13833 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShaderConstantF returned %#x.\n", hr
);
13835 hr
= IDirect3DDevice9_SetVertexShaderConstantI(device
, 0, i0
, 1);
13836 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShaderConstantI returned %#x.\n", hr
);
13838 hr
= IDirect3DDevice9_BeginScene(device
);
13839 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
13840 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 3 * sizeof(float));
13841 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
13842 hr
= IDirect3DDevice9_EndScene(device
);
13843 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
13844 color
= getPixelColor(device
, 320, 240);
13845 ok(color_match(color
, 0x0000ff00, 1),
13846 "aL indexing test returned color 0x%08x, expected 0x0000ff00\n", color
);
13847 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
13848 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
13850 IDirect3DVertexShader9_Release(shader
);
13851 refcount
= IDirect3DDevice9_Release(device
);
13852 ok(!refcount
, "Device has %u references left.\n", refcount
);
13854 IDirect3D9_Release(d3d
);
13855 DestroyWindow(window
);
13858 static void sgn_test(void)
13860 IDirect3DVertexShader9
*shader
;
13861 IDirect3DDevice9
*device
;
13869 static const DWORD shader_code
[] =
13871 0xfffe0200, /* vs_2_0 */
13872 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position o0 */
13873 0x05000051, 0xa00f0000, 0xbf000000, 0x00000000, 0x3f000000, 0x41400000, /* def c0, -0.5, 0.0, 0.5, 12.0 */
13874 0x05000051, 0xa00f0001, 0x3fc00000, 0x00000000, 0x00000000, 0x00000000, /* def c1, 1.5, 0.0, 0.0, 0.0 */
13875 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
13876 0x04000022, 0x800f0000, 0xa0e40000, 0x80e40001, 0x80e40002, /* sgn r0, c0, r1, r2 */
13877 0x03000002, 0xd00f0000, 0x80e40000, 0xa0e40001, /* add oD0, r0, c1 */
13878 0x0000ffff /* end */
13880 static const float quad
[] =
13882 -1.0f
, -1.0f
, 0.1f
,
13888 window
= create_window();
13889 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
13890 ok(!!d3d
, "Failed to create a D3D object.\n");
13891 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
13893 skip("Failed to create a D3D device, skipping tests.\n");
13897 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
13898 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
13899 if (caps
.VertexShaderVersion
< D3DVS_VERSION(2, 0))
13901 skip("No vs_2_0 support, skipping tests.\n");
13902 IDirect3DDevice9_Release(device
);
13906 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_code
, &shader
);
13907 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader failed with %08x\n", hr
);
13908 hr
= IDirect3DDevice9_SetVertexShader(device
, shader
);
13909 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader failed with %08x\n", hr
);
13910 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
13911 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with %08x\n", hr
);
13912 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x00ff0000, 1.0f
, 0);
13913 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %08x\n", hr
);
13915 hr
= IDirect3DDevice9_BeginScene(device
);
13916 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
13917 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 3 * sizeof(float));
13918 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
13919 hr
= IDirect3DDevice9_EndScene(device
);
13920 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
13921 color
= getPixelColor(device
, 320, 240);
13922 ok(color_match(color
, 0x008000ff, 1),
13923 "sgn test returned color 0x%08x, expected 0x008000ff\n", color
);
13924 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
13925 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
13927 IDirect3DVertexShader9_Release(shader
);
13928 refcount
= IDirect3DDevice9_Release(device
);
13929 ok(!refcount
, "Device has %u references left.\n", refcount
);
13931 IDirect3D9_Release(d3d
);
13932 DestroyWindow(window
);
13935 static void test_viewport(void)
13937 static const struct
13940 RECT expected_rect
;
13941 const char *message
;
13945 {{ 0, 0, 640, 480}, { 0, 120, 479, 359}, "Viewport (0, 0) - (640, 480)"},
13946 {{ 0, 0, 320, 240}, { 0, 60, 239, 179}, "Viewport (0, 0) - (320, 240)"},
13947 {{ 0, 0, 1280, 960}, { 0, 240, 639, 479}, "Viewport (0, 0) - (1280, 960)"},
13948 {{ 0, 0, 2000, 1600}, { 0, 400, 639, 479}, "Viewport (0, 0) - (2000, 1600)"},
13949 {{100, 100, 640, 480}, {100, 220, 579, 459}, "Viewport (100, 100) - (640, 480)"},
13950 {{ 0, 0, 8192, 8192}, {-10, -10, -10, -10}, "Viewport (0, 0) - (8192, 8192)"},
13951 /* AMD HD 2600 on XP draws nothing visible for this one. */
13952 /* {{ 0, 0, 8192, 480}, {-10, -10, -1, -1}, "(0, 0) - (8192, 480) viewport"}, */
13954 static const struct vec3 quad
[] =
13956 {-1.5f
, -0.5f
, 0.1f
},
13957 {-1.5f
, 0.5f
, 0.1f
},
13958 { 0.5f
, -0.5f
, 0.1f
},
13959 { 0.5f
, 0.5f
, 0.1f
},
13961 IDirect3DSurface9
*backbuffer
;
13962 struct surface_readback rb
;
13963 IDirect3DDevice9
*device
;
13964 BOOL draw_succeeded
;
13971 window
= create_window();
13972 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
13973 ok(!!d3d
, "Failed to create a D3D object.\n");
13974 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
13976 skip("Failed to create a D3D device, skipping tests.\n");
13980 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
13981 ok(SUCCEEDED(hr
), "Failed to get backbuffer, hr %#x.\n", hr
);
13983 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
13984 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
13986 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
13987 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
13989 /* This crashes on Windows. */
13991 hr
= IDirect3DDevice9_SetViewport(device
, NULL
);
13993 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
13995 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff000000, 1.0f
, 0);
13996 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
13998 hr
= IDirect3DDevice9_SetViewport(device
, &tests
[i
].vp
);
13999 ok(SUCCEEDED(hr
), "Failed to set the viewport, hr %#x.\n", hr
);
14001 hr
= IDirect3DDevice9_BeginScene(device
);
14002 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
14003 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(quad
[0]));
14004 ok(SUCCEEDED(hr
) || broken(hr
== D3DERR_INVALIDCALL
), "Got unexpected hr %#x.\n", hr
);
14005 draw_succeeded
= SUCCEEDED(hr
);
14006 hr
= IDirect3DDevice9_EndScene(device
);
14007 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
14009 if (draw_succeeded
)
14011 get_rt_readback(backbuffer
, &rb
);
14012 check_rect(&rb
, tests
[i
].expected_rect
, tests
[i
].message
);
14013 release_surface_readback(&rb
);
14017 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
14018 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
14020 IDirect3DSurface9_Release(backbuffer
);
14021 refcount
= IDirect3DDevice9_Release(device
);
14022 ok(!refcount
, "Device has %u references left.\n", refcount
);
14024 IDirect3D9_Release(d3d
);
14025 DestroyWindow(window
);
14028 /* This test tests depth clamping / clipping behaviour:
14029 * - With software vertex processing, depth values are clamped to the
14030 * minimum / maximum z value when D3DRS_CLIPPING is disabled, and clipped
14031 * when D3DRS_CLIPPING is enabled. Pretransformed vertices behave the
14032 * same as regular vertices here.
14033 * - With hardware vertex processing, D3DRS_CLIPPING seems to be ignored.
14034 * Normal vertices are always clipped. Pretransformed vertices are
14035 * clipped when D3DPMISCCAPS_CLIPTLVERTS is set, clamped when it isn't.
14036 * - The viewport's MinZ/MaxZ is irrelevant for this.
14038 static void depth_clamp_test(void)
14040 IDirect3DDevice9
*device
;
14049 static const struct
14051 struct vec4 position
;
14056 {{ 0.0f
, 0.0f
, 5.0f
, 1.0f
}, 0xff002b7f},
14057 {{640.0f
, 0.0f
, 5.0f
, 1.0f
}, 0xff002b7f},
14058 {{ 0.0f
, 480.0f
, 5.0f
, 1.0f
}, 0xff002b7f},
14059 {{640.0f
, 480.0f
, 5.0f
, 1.0f
}, 0xff002b7f},
14063 {{ 0.0f
, 300.0f
, 10.0f
, 1.0f
}, 0xfff9e814},
14064 {{640.0f
, 300.0f
, 10.0f
, 1.0f
}, 0xfff9e814},
14065 {{ 0.0f
, 360.0f
, 10.0f
, 1.0f
}, 0xfff9e814},
14066 {{640.0f
, 360.0f
, 10.0f
, 1.0f
}, 0xfff9e814},
14070 {{112.0f
, 108.0f
, 5.0f
, 1.0f
}, 0xffffffff},
14071 {{208.0f
, 108.0f
, 5.0f
, 1.0f
}, 0xffffffff},
14072 {{112.0f
, 204.0f
, 5.0f
, 1.0f
}, 0xffffffff},
14073 {{208.0f
, 204.0f
, 5.0f
, 1.0f
}, 0xffffffff},
14077 {{ 42.0f
, 41.0f
, 10.0f
, 1.0f
}, 0xffffffff},
14078 {{112.0f
, 41.0f
, 10.0f
, 1.0f
}, 0xffffffff},
14079 {{ 42.0f
, 108.0f
, 10.0f
, 1.0f
}, 0xffffffff},
14080 {{112.0f
, 108.0f
, 10.0f
, 1.0f
}, 0xffffffff},
14082 static const struct
14084 struct vec3 position
;
14089 {{-0.5f
, 0.5f
, 10.0f
}, 0xff14f914},
14090 {{ 0.5f
, 0.5f
, 10.0f
}, 0xff14f914},
14091 {{-0.5f
, -0.5f
, 10.0f
}, 0xff14f914},
14092 {{ 0.5f
, -0.5f
, 10.0f
}, 0xff14f914},
14096 {{-1.0f
, 0.5f
, 10.0f
}, 0xfff91414},
14097 {{ 1.0f
, 0.5f
, 10.0f
}, 0xfff91414},
14098 {{-1.0f
, 0.25f
, 10.0f
}, 0xfff91414},
14099 {{ 1.0f
, 0.25f
, 10.0f
}, 0xfff91414},
14102 window
= create_window();
14103 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
14104 ok(!!d3d
, "Failed to create a D3D object.\n");
14105 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
14107 skip("Failed to create a D3D device, skipping tests.\n");
14111 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
14112 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
14121 hr
= IDirect3DDevice9_SetViewport(device
, &vp
);
14124 /* Windows 7 rejects MaxZ > 1.0, Windows XP allows it. This doesn't break
14125 * the tests because the 7.5 is just intended to show that it doesn't have
14126 * any influence on the drawing or D3DRS_CLIPPING = FALSE. Set an accepted
14127 * viewport and continue.
14129 ok(broken(hr
== D3DERR_INVALIDCALL
), "D3D rejected maxZ > 1.0\n");
14131 hr
= IDirect3DDevice9_SetViewport(device
, &vp
);
14133 ok(SUCCEEDED(hr
), "SetViewport failed, hr %#x.\n", hr
);
14135 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff00ff00, 1.0, 0);
14136 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
14138 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CLIPPING
, FALSE
);
14139 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14140 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
14141 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14142 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, TRUE
);
14143 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14144 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_LESSEQUAL
);
14145 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14147 hr
= IDirect3DDevice9_BeginScene(device
);
14148 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
14150 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
);
14151 ok(SUCCEEDED(hr
), "SetFVF failed, hr %#x.\n", hr
);
14153 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(*quad1
));
14154 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
14155 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(*quad2
));
14156 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
14158 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CLIPPING
, TRUE
);
14159 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14161 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, sizeof(*quad3
));
14162 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
14163 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, sizeof(*quad4
));
14164 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
14166 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CLIPPING
, FALSE
);
14167 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14169 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
14170 ok(SUCCEEDED(hr
), "SetFVF failed, hr %#x.\n", hr
);
14172 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad5
, sizeof(*quad5
));
14173 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
14175 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CLIPPING
, TRUE
);
14176 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14178 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad6
, sizeof(*quad6
));
14179 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
14181 hr
= IDirect3DDevice9_EndScene(device
);
14182 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
14184 if (caps
.PrimitiveMiscCaps
& D3DPMISCCAPS_CLIPTLVERTS
)
14186 color
= getPixelColor(device
, 75, 75);
14187 ok(color_match(color
, 0x0000ff00, 1), "color 0x%08x.\n", color
);
14188 color
= getPixelColor(device
, 150, 150);
14189 ok(color_match(color
, 0x0000ff00, 1), "color 0x%08x.\n", color
);
14190 color
= getPixelColor(device
, 320, 240);
14191 ok(color_match(color
, 0x0000ff00, 1), "color 0x%08x.\n", color
);
14192 color
= getPixelColor(device
, 320, 330);
14193 ok(color_match(color
, 0x0000ff00, 1), "color 0x%08x.\n", color
);
14194 color
= getPixelColor(device
, 320, 330);
14195 ok(color_match(color
, 0x0000ff00, 1), "color 0x%08x.\n", color
);
14199 color
= getPixelColor(device
, 75, 75);
14200 ok(color_match(color
, 0x00ffffff, 1), "color 0x%08x.\n", color
);
14201 color
= getPixelColor(device
, 150, 150);
14202 ok(color_match(color
, 0x00ffffff, 1), "color 0x%08x.\n", color
);
14203 color
= getPixelColor(device
, 320, 240);
14204 ok(color_match(color
, 0x00002b7f, 1), "color 0x%08x.\n", color
);
14205 color
= getPixelColor(device
, 320, 330);
14206 ok(color_match(color
, 0x00f9e814, 1), "color 0x%08x.\n", color
);
14207 color
= getPixelColor(device
, 320, 330);
14208 ok(color_match(color
, 0x00f9e814, 1), "color 0x%08x.\n", color
);
14211 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
14212 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
14214 refcount
= IDirect3DDevice9_Release(device
);
14215 ok(!refcount
, "Device has %u references left.\n", refcount
);
14217 IDirect3D9_Release(d3d
);
14218 DestroyWindow(window
);
14221 static void depth_bounds_test(void)
14223 static const struct
14225 struct vec4 position
;
14230 {{ 0.0f
, 0.0f
, 0.0f
, 1.0f
}, 0xfff9e814},
14231 {{640.0f
, 0.0f
, 0.0f
, 1.0f
}, 0xfff9e814},
14232 {{ 0.0f
, 480.0f
, 1.0f
, 1.0f
}, 0xfff9e814},
14233 {{640.0f
, 480.0f
, 1.0f
, 1.0f
}, 0xfff9e814},
14237 {{ 0.0f
, 0.0f
, 0.6f
, 1.0f
}, 0xff002b7f},
14238 {{640.0f
, 0.0f
, 0.6f
, 1.0f
}, 0xff002b7f},
14239 {{ 0.0f
, 480.0f
, 0.6f
, 1.0f
}, 0xff002b7f},
14240 {{640.0f
, 480.0f
, 0.6f
, 1.0f
}, 0xff002b7f},
14244 {{ 0.0f
, 100.0f
, 0.6f
, 1.0f
}, 0xfff91414},
14245 {{640.0f
, 100.0f
, 0.6f
, 1.0f
}, 0xfff91414},
14246 {{ 0.0f
, 160.0f
, 0.6f
, 1.0f
}, 0xfff91414},
14247 {{640.0f
, 160.0f
, 0.6f
, 1.0f
}, 0xfff91414},
14255 IDirect3DSurface9
*offscreen_surface
= NULL
;
14256 IDirect3DDevice9
*device
;
14263 window
= create_window();
14264 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
14265 ok(!!d3d
, "Failed to create a D3D object.\n");
14266 if (IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
,
14267 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_SURFACE
, MAKEFOURCC('N','V','D','B')) != D3D_OK
)
14269 skip("No NVDB (depth bounds test) support, skipping tests.\n");
14272 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
14274 skip("Failed to create a D3D device, skipping tests.\n");
14278 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 32, 32,
14279 MAKEFOURCC('N','V','D','B'), D3DPOOL_DEFAULT
, &offscreen_surface
, NULL
);
14280 ok(FAILED(hr
), "Able to create surface, hr %#x.\n", hr
);
14281 if (offscreen_surface
) IDirect3DSurface9_Release(offscreen_surface
);
14283 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffffff, 1.0, 0);
14284 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
14286 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
14287 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14288 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, TRUE
);
14289 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14290 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, TRUE
);
14291 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14292 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_ALWAYS
);
14293 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14296 hr
= IDirect3DDevice9_BeginScene(device
);
14297 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
14299 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
);
14300 ok(SUCCEEDED(hr
), "SetFVF failed, hr %#x.\n", hr
);
14302 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(*quad1
));
14303 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
14305 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ADAPTIVETESS_X
, MAKEFOURCC('N','V','D','B'));
14306 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14308 tmpvalue
.f
= 0.625;
14309 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ADAPTIVETESS_Z
, tmpvalue
.d
);
14310 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14313 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ADAPTIVETESS_W
, tmpvalue
.d
);
14314 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14316 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(*quad2
));
14317 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
14320 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ADAPTIVETESS_Z
, tmpvalue
.d
);
14321 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14323 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, sizeof(*quad3
));
14324 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
14326 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ADAPTIVETESS_X
, 0);
14327 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14329 hr
= IDirect3DDevice9_EndScene(device
);
14330 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
14332 color
= getPixelColor(device
, 150, 130);
14333 ok(color_match(color
, 0x00f9e814, 1), "color 0x%08x.\n", color
);
14334 color
= getPixelColor(device
, 150, 200);
14335 ok(color_match(color
, 0x00f9e814, 1), "color 0x%08x.\n", color
);
14336 color
= getPixelColor(device
, 150, 300-5);
14337 ok(color_match(color
, 0x00f9e814, 1), "color 0x%08x.\n", color
);
14338 color
= getPixelColor(device
, 150, 300+5);
14339 ok(color_match(color
, 0x00002b7f, 1), "color 0x%08x.\n", color
);/**/
14340 color
= getPixelColor(device
, 150, 330);
14341 ok(color_match(color
, 0x00002b7f, 1), "color 0x%08x.\n", color
);
14342 color
= getPixelColor(device
, 150, 360-5);
14343 ok(color_match(color
, 0x00002b7f, 1), "color 0x%08x.\n", color
);/**/
14344 color
= getPixelColor(device
, 150, 360+5);
14345 ok(color_match(color
, 0x00f9e814, 1), "color 0x%08x.\n", color
);
14347 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
14348 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
14349 refcount
= IDirect3DDevice9_Release(device
);
14350 ok(!refcount
, "Device has %u references left.\n", refcount
);
14352 IDirect3D9_Release(d3d
);
14353 DestroyWindow(window
);
14356 static void depth_buffer_test(void)
14358 static const struct
14360 struct vec3 position
;
14365 {{-1.0, 1.0, 0.33f
}, 0xff00ff00},
14366 {{ 1.0, 1.0, 0.33f
}, 0xff00ff00},
14367 {{-1.0, -1.0, 0.33f
}, 0xff00ff00},
14368 {{ 1.0, -1.0, 0.33f
}, 0xff00ff00},
14372 {{-1.0, 1.0, 0.50f
}, 0xffff00ff},
14373 {{ 1.0, 1.0, 0.50f
}, 0xffff00ff},
14374 {{-1.0, -1.0, 0.50f
}, 0xffff00ff},
14375 {{ 1.0, -1.0, 0.50f
}, 0xffff00ff},
14379 {{-1.0, 1.0, 0.66f
}, 0xffff0000},
14380 {{ 1.0, 1.0, 0.66f
}, 0xffff0000},
14381 {{-1.0, -1.0, 0.66f
}, 0xffff0000},
14382 {{ 1.0, -1.0, 0.66f
}, 0xffff0000},
14384 static const DWORD expected_colors
[4][4] =
14386 {0x000000ff, 0x000000ff, 0x0000ff00, 0x00ff0000},
14387 {0x000000ff, 0x000000ff, 0x0000ff00, 0x00ff0000},
14388 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x00ff0000},
14389 {0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000},
14392 IDirect3DSurface9
*backbuffer
, *rt1
, *rt2
, *rt3
;
14393 IDirect3DDevice9
*device
;
14402 window
= create_window();
14403 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
14404 ok(!!d3d
, "Failed to create a D3D object.\n");
14405 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
14407 skip("Failed to create a D3D device, skipping tests.\n");
14418 hr
= IDirect3DDevice9_SetViewport(device
, &vp
);
14419 ok(SUCCEEDED(hr
), "SetViewport failed, hr %#x.\n", hr
);
14421 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
14422 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14423 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_TRUE
);
14424 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14425 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, TRUE
);
14426 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14427 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_LESSEQUAL
);
14428 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14429 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
14430 ok(SUCCEEDED(hr
), "SetFVF failed, hr %#x.\n", hr
);
14432 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &backbuffer
);
14433 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
14434 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 320, 240, D3DFMT_A8R8G8B8
,
14435 D3DMULTISAMPLE_NONE
, 0, FALSE
, &rt1
, NULL
);
14436 ok(SUCCEEDED(hr
), "CreateRenderTarget failed, hr %#x.\n", hr
);
14437 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 480, 360, D3DFMT_A8R8G8B8
,
14438 D3DMULTISAMPLE_NONE
, 0, FALSE
, &rt2
, NULL
);
14439 ok(SUCCEEDED(hr
), "CreateRenderTarget failed, hr %#x.\n", hr
);
14440 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 640, 480, D3DFMT_A8R8G8B8
,
14441 D3DMULTISAMPLE_NONE
, 0, FALSE
, &rt3
, NULL
);
14442 ok(SUCCEEDED(hr
), "CreateRenderTarget failed, hr %#x.\n", hr
);
14444 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt3
);
14445 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
14446 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff0000ff, 0.0f
, 0);
14447 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
14449 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
14450 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
14451 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff0000ff, 1.0f
, 0);
14452 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
14454 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt1
);
14455 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
14456 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffffff, 0.0f
, 0);
14457 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
14459 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt2
);
14460 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
14461 hr
= IDirect3DDevice9_BeginScene(device
);
14462 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
14463 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(*quad2
));
14464 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
14465 hr
= IDirect3DDevice9_EndScene(device
);
14466 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
14468 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
14469 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
14471 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, FALSE
);
14472 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14474 hr
= IDirect3DDevice9_BeginScene(device
);
14475 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
14476 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(*quad1
));
14477 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
14478 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, sizeof(*quad3
));
14479 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
14480 hr
= IDirect3DDevice9_EndScene(device
);
14481 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
14483 for (i
= 0; i
< 4; ++i
)
14485 for (j
= 0; j
< 4; ++j
)
14487 unsigned int x
= 80 * ((2 * j
) + 1);
14488 unsigned int y
= 60 * ((2 * i
) + 1);
14489 color
= getPixelColor(device
, x
, y
);
14490 ok(color_match(color
, expected_colors
[i
][j
], 0),
14491 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors
[i
][j
], x
, y
, color
);
14495 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
14496 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
14498 IDirect3DSurface9_Release(backbuffer
);
14499 IDirect3DSurface9_Release(rt3
);
14500 IDirect3DSurface9_Release(rt2
);
14501 IDirect3DSurface9_Release(rt1
);
14502 refcount
= IDirect3DDevice9_Release(device
);
14503 ok(!refcount
, "Device has %u references left.\n", refcount
);
14505 IDirect3D9_Release(d3d
);
14506 DestroyWindow(window
);
14509 /* Test that partial depth copies work the way they're supposed to. The clear
14510 * on rt2 only needs a partial copy of the onscreen depth/stencil buffer, and
14511 * the following draw should only copy back the part that was modified. */
14512 static void depth_buffer2_test(void)
14514 static const struct
14516 struct vec3 position
;
14521 {{-1.0f
, 1.0f
, 0.66f
}, 0xffff0000},
14522 {{ 1.0f
, 1.0f
, 0.66f
}, 0xffff0000},
14523 {{-1.0f
, -1.0f
, 0.66f
}, 0xffff0000},
14524 {{ 1.0f
, -1.0f
, 0.66f
}, 0xffff0000},
14527 IDirect3DSurface9
*backbuffer
, *rt1
, *rt2
;
14528 IDirect3DDevice9
*device
;
14537 window
= create_window();
14538 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
14539 ok(!!d3d
, "Failed to create a D3D object.\n");
14540 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
14542 skip("Failed to create a D3D device, skipping tests.\n");
14553 hr
= IDirect3DDevice9_SetViewport(device
, &vp
);
14554 ok(SUCCEEDED(hr
), "SetViewport failed, hr %#x.\n", hr
);
14556 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
14557 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14558 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_TRUE
);
14559 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14560 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, TRUE
);
14561 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14562 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_LESSEQUAL
);
14563 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14564 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
14565 ok(SUCCEEDED(hr
), "SetFVF failed, hr %#x.\n", hr
);
14567 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 640, 480, D3DFMT_A8R8G8B8
,
14568 D3DMULTISAMPLE_NONE
, 0, FALSE
, &rt1
, NULL
);
14569 ok(SUCCEEDED(hr
), "CreateRenderTarget failed, hr %#x.\n", hr
);
14570 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 480, 360, D3DFMT_A8R8G8B8
,
14571 D3DMULTISAMPLE_NONE
, 0, FALSE
, &rt2
, NULL
);
14572 ok(SUCCEEDED(hr
), "CreateRenderTarget failed, hr %#x.\n", hr
);
14573 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &backbuffer
);
14574 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
14576 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt1
);
14577 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
14578 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff0000ff, 1.0f
, 0);
14579 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
14581 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
14582 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
14583 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff00ff00, 0.5f
, 0);
14584 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
14586 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt2
);
14587 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
14588 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffffff, 0.0f
, 0);
14589 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
14591 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
14592 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
14594 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, FALSE
);
14595 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14597 hr
= IDirect3DDevice9_BeginScene(device
);
14598 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
14599 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
14600 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
14601 hr
= IDirect3DDevice9_EndScene(device
);
14602 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
14604 for (i
= 0; i
< 4; ++i
)
14606 for (j
= 0; j
< 4; ++j
)
14608 unsigned int x
= 80 * ((2 * j
) + 1);
14609 unsigned int y
= 60 * ((2 * i
) + 1);
14610 color
= getPixelColor(device
, x
, y
);
14611 ok(color_match(color
, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00), 0),
14612 "Expected color 0x0000ff00 at %u,%u, got 0x%08x.\n", x
, y
, color
);
14616 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
14617 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
14619 IDirect3DSurface9_Release(backbuffer
);
14620 IDirect3DSurface9_Release(rt2
);
14621 IDirect3DSurface9_Release(rt1
);
14622 refcount
= IDirect3DDevice9_Release(device
);
14623 ok(!refcount
, "Device has %u references left.\n", refcount
);
14625 IDirect3D9_Release(d3d
);
14626 DestroyWindow(window
);
14629 static void depth_blit_test(void)
14631 static const struct
14633 struct vec3 position
;
14638 {{-1.0f
, 1.0f
, 0.33f
}, 0xff00ff00},
14639 {{ 1.0f
, 1.0f
, 0.33f
}, 0xff00ff00},
14640 {{-1.0f
, -1.0f
, 0.33f
}, 0xff00ff00},
14641 {{ 1.0f
, -1.0f
, 0.33f
}, 0xff00ff00},
14645 {{-1.0f
, 1.0f
, 0.66f
}, 0xff0000ff},
14646 {{ 1.0f
, 1.0f
, 0.66f
}, 0xff0000ff},
14647 {{-1.0f
, -1.0f
, 0.66f
}, 0xff0000ff},
14648 {{ 1.0f
, -1.0f
, 0.66f
}, 0xff0000ff},
14650 static const DWORD expected_colors
[4][4] =
14652 {0x000000ff, 0x000000ff, 0x0000ff00, 0x00ff0000},
14653 {0x000000ff, 0x000000ff, 0x0000ff00, 0x00ff0000},
14654 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x00ff0000},
14655 {0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000},
14658 IDirect3DSurface9
*backbuffer
, *ds1
, *ds2
, *ds3
;
14659 IDirect3DDevice9
*device
;
14660 RECT src_rect
, dst_rect
;
14669 window
= create_window();
14670 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
14671 ok(!!d3d
, "Failed to create a D3D object.\n");
14672 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
14674 skip("Failed to create a D3D device, skipping tests.\n");
14685 hr
= IDirect3DDevice9_SetViewport(device
, &vp
);
14686 ok(SUCCEEDED(hr
), "SetViewport failed, hr %#x.\n", hr
);
14688 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &backbuffer
);
14689 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
14690 hr
= IDirect3DDevice9_GetDepthStencilSurface(device
, &ds1
);
14691 ok(SUCCEEDED(hr
), "GetDepthStencilSurface failed, hr %#x.\n", hr
);
14692 hr
= IDirect3DDevice9_CreateDepthStencilSurface(device
, 640, 480, D3DFMT_D24S8
, 0, 0, FALSE
, &ds2
, NULL
);
14693 ok(SUCCEEDED(hr
), "CreateDepthStencilSurface failed, hr %#x.\n", hr
);
14694 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, ds2
);
14695 ok(SUCCEEDED(hr
), "SetDepthStencilSurface failed, hr %#x.\n", hr
);
14696 hr
= IDirect3DDevice9_CreateDepthStencilSurface(device
, 320, 240, D3DFMT_D24S8
, 0, 0, FALSE
, &ds3
, NULL
);
14697 ok(SUCCEEDED(hr
), "CreateDepthStencilSurface failed, hr %#x.\n", hr
);
14699 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
14700 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14701 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_TRUE
);
14702 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14703 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_LESSEQUAL
);
14704 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14705 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
14706 ok(SUCCEEDED(hr
), "SetFVF failed, hr %#x.\n", hr
);
14708 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0, 0.0f
, 0);
14709 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
14710 SetRect(&dst_rect
, 0, 0, 480, 360);
14711 hr
= IDirect3DDevice9_Clear(device
, 1, (D3DRECT
*)&dst_rect
, D3DCLEAR_ZBUFFER
, 0, 0.5f
, 0);
14712 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
14713 SetRect(&dst_rect
, 0, 0, 320, 240);
14714 hr
= IDirect3DDevice9_Clear(device
, 1, (D3DRECT
*)&dst_rect
, D3DCLEAR_ZBUFFER
, 0, 1.0f
, 0);
14715 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
14717 /* Partial blit. */
14718 SetRect(&src_rect
, 0, 0, 320, 240);
14719 SetRect(&dst_rect
, 0, 0, 320, 240);
14720 hr
= IDirect3DDevice9_StretchRect(device
, ds2
, &src_rect
, ds1
, &dst_rect
, D3DTEXF_POINT
);
14721 ok(hr
== D3DERR_INVALIDCALL
, "StretchRect returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
14723 SetRect(&src_rect
, 0, 0, 640, 480);
14724 SetRect(&dst_rect
, 0, 480, 640, 0);
14725 hr
= IDirect3DDevice9_StretchRect(device
, ds2
, &src_rect
, ds1
, &dst_rect
, D3DTEXF_POINT
);
14726 ok(hr
== D3DERR_INVALIDCALL
, "StretchRect returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
14727 /* Full, explicit. */
14728 SetRect(&src_rect
, 0, 0, 640, 480);
14729 SetRect(&dst_rect
, 0, 0, 640, 480);
14730 hr
= IDirect3DDevice9_StretchRect(device
, ds2
, &src_rect
, ds1
, &dst_rect
, D3DTEXF_POINT
);
14731 ok(SUCCEEDED(hr
), "StretchRect failed, hr %#x.\n", hr
);
14732 /* Filtered blit. */
14733 hr
= IDirect3DDevice9_StretchRect(device
, ds2
, NULL
, ds1
, NULL
, D3DTEXF_LINEAR
);
14734 ok(SUCCEEDED(hr
), "StretchRect failed, hr %#x.\n", hr
);
14735 /* Depth -> color blit.*/
14736 hr
= IDirect3DDevice9_StretchRect(device
, ds2
, NULL
, backbuffer
, NULL
, D3DTEXF_POINT
);
14737 ok(hr
== D3DERR_INVALIDCALL
, "StretchRect returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
14738 IDirect3DSurface9_Release(backbuffer
);
14739 /* Full surface, different sizes */
14740 hr
= IDirect3DDevice9_StretchRect(device
, ds3
, NULL
, ds1
, NULL
, D3DTEXF_POINT
);
14741 ok(hr
== D3DERR_INVALIDCALL
, "StretchRect returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
14742 hr
= IDirect3DDevice9_StretchRect(device
, ds1
, NULL
, ds3
, NULL
, D3DTEXF_POINT
);
14743 ok(hr
== D3DERR_INVALIDCALL
, "StretchRect returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
14745 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, ds1
);
14746 ok(SUCCEEDED(hr
), "SetDepthStencilSurface failed, hr %#x.\n", hr
);
14747 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
| D3DCLEAR_TARGET
, 0xffff0000, 1.0f
, 0);
14748 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
14749 hr
= IDirect3DDevice9_StretchRect(device
, ds2
, NULL
, ds1
, NULL
, D3DTEXF_POINT
);
14750 ok(SUCCEEDED(hr
), "StretchRect failed, hr %#x.\n", hr
);
14752 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, FALSE
);
14753 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14754 hr
= IDirect3DDevice9_BeginScene(device
);
14755 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
14756 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(*quad1
));
14757 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
14758 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(*quad2
));
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 for (i
= 0; i
< 4; ++i
)
14765 for (j
= 0; j
< 4; ++j
)
14767 unsigned int x
= 80 * ((2 * j
) + 1);
14768 unsigned int y
= 60 * ((2 * i
) + 1);
14769 color
= getPixelColor(device
, x
, y
);
14770 ok(color_match(color
, expected_colors
[i
][j
], 0),
14771 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors
[i
][j
], x
, y
, color
);
14775 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
14776 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
14778 IDirect3DSurface9_Release(ds3
);
14779 IDirect3DSurface9_Release(ds2
);
14780 IDirect3DSurface9_Release(ds1
);
14781 refcount
= IDirect3DDevice9_Release(device
);
14782 ok(!refcount
, "Device has %u references left.\n", refcount
);
14784 IDirect3D9_Release(d3d
);
14785 DestroyWindow(window
);
14788 static void intz_test(void)
14790 static const DWORD ps_code
[] =
14792 0xffff0200, /* ps_2_0 */
14793 0x0200001f, 0x90000000, 0xa00f0800, /* dcl_2d s0 */
14794 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
14795 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0.0, 0.0, 0.0, 1.0 */
14796 0x02000001, 0x800f0001, 0xa0e40000, /* mov r1, c0 */
14797 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texld r0, t0, s0 */
14798 0x03010042, 0x800f0001, 0xb0e40000, 0xa0e40800, /* texldp r1, t0, s0 */
14799 0x02000001, 0x80020000, 0x80000001, /* mov r0.y, r1.x */
14800 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
14801 0x0000ffff, /* end */
14810 { -1.0f
, 1.0f
, 0.0f
, 0.0f
, 1.0f
, 1.0f
, 0.5f
},
14811 { 1.0f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 0.5f
},
14812 { -1.0f
, -1.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.5f
},
14813 { 1.0f
, -1.0f
, 1.0f
, 1.0f
, 0.0f
, 0.0f
, 0.5f
},
14817 { -1.0f
, 0.0f
, 0.0f
, 0.0f
, 1.0f
, 1.0f
, 0.5f
},
14818 { 1.0f
, 0.0f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 0.5f
},
14819 { -1.0f
, -1.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.5f
},
14820 { 1.0f
, -1.0f
, 1.0f
, 1.0f
, 0.0f
, 0.0f
, 0.5f
},
14824 { -1.0f
, 1.0f
, 0.0f
, 0.0f
, 1.0f
, 1.0f
, 0.5f
},
14825 { 1.0f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 0.5f
},
14826 { -1.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.5f
},
14827 { 1.0f
, 0.0f
, 1.0f
, 1.0f
, 0.0f
, 0.0f
, 0.5f
},
14834 expected_colors
[] =
14836 { 80, 100, 0x20204020},
14837 {240, 100, 0x6060bf60},
14838 {400, 100, 0x9f9f409f},
14839 {560, 100, 0xdfdfbfdf},
14840 { 80, 450, 0x20204020},
14841 {240, 450, 0x6060bf60},
14842 {400, 450, 0x9f9f409f},
14843 {560, 450, 0xdfdfbfdf},
14846 IDirect3DSurface9
*original_rt
, *rt
;
14847 struct surface_readback rb
;
14848 IDirect3DTexture9
*texture
;
14849 IDirect3DPixelShader9
*ps
;
14850 IDirect3DDevice9
*device
;
14851 IDirect3DSurface9
*ds
;
14859 window
= create_window();
14860 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
14861 ok(!!d3d
, "Failed to create a D3D object.\n");
14862 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
14863 D3DFMT_X8R8G8B8
, D3DUSAGE_DEPTHSTENCIL
, D3DRTYPE_TEXTURE
, MAKEFOURCC('I','N','T','Z'))))
14865 skip("No INTZ support, skipping INTZ test.\n");
14868 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
14870 skip("Failed to create a D3D device, skipping tests.\n");
14874 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
14875 ok(SUCCEEDED(hr
), "GetDeviceCaps failed, hr %#x.\n", hr
);
14876 if (caps
.PixelShaderVersion
< D3DPS_VERSION(2, 0))
14878 skip("No pixel shader 2.0 support, skipping INTZ test.\n");
14879 IDirect3DDevice9_Release(device
);
14882 if (caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
)
14884 skip("No unconditional NP2 texture support, skipping INTZ test.\n");
14885 IDirect3DDevice9_Release(device
);
14889 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &original_rt
);
14890 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
14892 hr
= IDirect3DDevice9_CreateTexture(device
, 640, 480, 1,
14893 D3DUSAGE_DEPTHSTENCIL
, MAKEFOURCC('I','N','T','Z'), D3DPOOL_DEFAULT
, &texture
, NULL
);
14894 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
14895 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 640, 480, D3DFMT_A8R8G8B8
,
14896 D3DMULTISAMPLE_NONE
, 0, FALSE
, &rt
, NULL
);
14897 ok(SUCCEEDED(hr
), "CreateRenderTarget failed, hr %#x.\n", hr
);
14898 hr
= IDirect3DDevice9_CreatePixelShader(device
, ps_code
, &ps
);
14899 ok(SUCCEEDED(hr
), "CreatePixelShader failed, hr %#x.\n", hr
);
14901 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
| D3DFVF_TEXCOORDSIZE4(0));
14902 ok(SUCCEEDED(hr
), "SetFVF failed, hr %#x.\n", hr
);
14903 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_TRUE
);
14904 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14905 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_ALWAYS
);
14906 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14907 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, TRUE
);
14908 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14909 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
14910 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
14912 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSU
, D3DTADDRESS_WRAP
);
14913 ok(SUCCEEDED(hr
), "SetSamplerState failed, hr %#x.\n", hr
);
14914 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSV
, D3DTADDRESS_WRAP
);
14915 ok(SUCCEEDED(hr
), "SetSamplerState failed, hr %#x.\n", hr
);
14916 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAGFILTER
, D3DTEXF_POINT
);
14917 ok(SUCCEEDED(hr
), "SetSamplerState failed, hr %#x.\n", hr
);
14918 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MINFILTER
, D3DTEXF_POINT
);
14919 ok(SUCCEEDED(hr
), "SetSamplerState failed, hr %#x.\n", hr
);
14920 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MIPFILTER
, D3DTEXF_POINT
);
14921 ok(SUCCEEDED(hr
), "SetSamplerState failed, hr %#x.\n", hr
);
14923 /* Render offscreen, using the INTZ texture as depth buffer */
14924 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &ds
);
14925 ok(SUCCEEDED(hr
), "GetSurfaceLevel failed, hr %#x.\n", hr
);
14926 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, ds
);
14927 ok(SUCCEEDED(hr
), "SetDepthStencilSurface failed, hr %#x.\n", hr
);
14928 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt
);
14929 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
14930 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
14931 ok(SUCCEEDED(hr
), "SetPixelShader failed, hr %#x.\n", hr
);
14933 /* Setup the depth/stencil surface. */
14934 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0, 0.0f
, 0);
14935 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
14937 hr
= IDirect3DDevice9_BeginScene(device
);
14938 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
14939 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
14940 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
14941 hr
= IDirect3DDevice9_EndScene(device
);
14942 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
14944 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, NULL
);
14945 ok(SUCCEEDED(hr
), "SetDepthStencilSurface failed, hr %#x.\n", hr
);
14946 IDirect3DSurface9_Release(ds
);
14947 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, original_rt
);
14948 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
14949 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)texture
);
14950 ok(SUCCEEDED(hr
), "SetTexture failed, hr %#x.\n", hr
);
14951 hr
= IDirect3DDevice9_SetPixelShader(device
, ps
);
14952 ok(SUCCEEDED(hr
), "SetPixelShader failed, hr %#x.\n", hr
);
14954 /* Read the depth values back. */
14955 hr
= IDirect3DDevice9_BeginScene(device
);
14956 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
14957 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
14958 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
14959 hr
= IDirect3DDevice9_EndScene(device
);
14960 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
14962 get_rt_readback(original_rt
, &rb
);
14963 for (i
= 0; i
< ARRAY_SIZE(expected_colors
); ++i
)
14965 D3DCOLOR color
= get_readback_color(&rb
, expected_colors
[i
].x
, expected_colors
[i
].y
);
14966 ok(color_match(color
, expected_colors
[i
].color
, 1),
14967 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
14968 expected_colors
[i
].color
, expected_colors
[i
].x
, expected_colors
[i
].y
, color
);
14970 release_surface_readback(&rb
);
14972 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
14973 ok(SUCCEEDED(hr
), "Present failed, hr %#x.\n", hr
);
14975 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
14976 ok(SUCCEEDED(hr
), "SetTexture failed, hr %#x.\n", hr
);
14977 IDirect3DTexture9_Release(texture
);
14979 /* Render onscreen while using the INTZ texture as depth buffer */
14980 hr
= IDirect3DDevice9_CreateTexture(device
, 640, 480, 1,
14981 D3DUSAGE_DEPTHSTENCIL
, MAKEFOURCC('I','N','T','Z'), D3DPOOL_DEFAULT
, &texture
, NULL
);
14982 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &ds
);
14983 ok(SUCCEEDED(hr
), "GetSurfaceLevel failed, hr %#x.\n", hr
);
14984 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, ds
);
14985 ok(SUCCEEDED(hr
), "SetDepthStencilSurface failed, hr %#x.\n", hr
);
14986 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
14987 ok(SUCCEEDED(hr
), "SetPixelShader failed, hr %#x.\n", hr
);
14989 /* Setup the depth/stencil surface. */
14990 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0, 0.0f
, 0);
14991 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
14993 hr
= IDirect3DDevice9_BeginScene(device
);
14994 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
14995 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
14996 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
14997 hr
= IDirect3DDevice9_EndScene(device
);
14998 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
15000 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, NULL
);
15001 ok(SUCCEEDED(hr
), "SetDepthStencilSurface failed, hr %#x.\n", hr
);
15002 IDirect3DSurface9_Release(ds
);
15003 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)texture
);
15004 ok(SUCCEEDED(hr
), "SetTexture failed, hr %#x.\n", hr
);
15005 hr
= IDirect3DDevice9_SetPixelShader(device
, ps
);
15006 ok(SUCCEEDED(hr
), "SetPixelShader failed, hr %#x.\n", hr
);
15008 /* Read the depth values back. */
15009 hr
= IDirect3DDevice9_BeginScene(device
);
15010 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
15011 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
15012 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
15013 hr
= IDirect3DDevice9_EndScene(device
);
15014 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
15016 get_rt_readback(original_rt
, &rb
);
15017 for (i
= 0; i
< ARRAY_SIZE(expected_colors
); ++i
)
15019 D3DCOLOR color
= get_readback_color(&rb
, expected_colors
[i
].x
, expected_colors
[i
].y
);
15020 ok(color_match(color
, expected_colors
[i
].color
, 1),
15021 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
15022 expected_colors
[i
].color
, expected_colors
[i
].x
, expected_colors
[i
].y
, color
);
15024 release_surface_readback(&rb
);
15026 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
15027 ok(SUCCEEDED(hr
), "Present failed, hr %#x.\n", hr
);
15029 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
15030 ok(SUCCEEDED(hr
), "SetTexture failed, hr %#x.\n", hr
);
15031 IDirect3DTexture9_Release(texture
);
15033 /* Render offscreen, then onscreen, and finally check the INTZ texture in both areas */
15034 hr
= IDirect3DDevice9_CreateTexture(device
, 640, 480, 1,
15035 D3DUSAGE_DEPTHSTENCIL
, MAKEFOURCC('I','N','T','Z'), D3DPOOL_DEFAULT
, &texture
, NULL
);
15036 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &ds
);
15037 ok(SUCCEEDED(hr
), "GetSurfaceLevel failed, hr %#x.\n", hr
);
15039 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, ds
);
15040 ok(SUCCEEDED(hr
), "SetDepthStencilSurface failed, hr %#x.\n", hr
);
15041 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt
);
15042 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
15043 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
15044 ok(SUCCEEDED(hr
), "SetPixelShader failed, hr %#x.\n", hr
);
15046 /* Setup the depth/stencil surface. */
15047 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0, 0.0f
, 0);
15048 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
15050 hr
= IDirect3DDevice9_BeginScene(device
);
15051 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
15052 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, half_quad_1
, sizeof(*half_quad_1
));
15053 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
15054 hr
= IDirect3DDevice9_EndScene(device
);
15055 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
15057 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, original_rt
);
15058 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
15060 hr
= IDirect3DDevice9_BeginScene(device
);
15061 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
15062 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, half_quad_2
, sizeof(*half_quad_2
));
15063 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
15064 hr
= IDirect3DDevice9_EndScene(device
);
15065 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
15067 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, NULL
);
15068 ok(SUCCEEDED(hr
), "SetDepthStencilSurface failed, hr %#x.\n", hr
);
15069 IDirect3DSurface9_Release(ds
);
15070 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)texture
);
15071 ok(SUCCEEDED(hr
), "SetTexture failed, hr %#x.\n", hr
);
15072 hr
= IDirect3DDevice9_SetPixelShader(device
, ps
);
15073 ok(SUCCEEDED(hr
), "SetPixelShader failed, hr %#x.\n", hr
);
15075 /* Read the depth values back. */
15076 hr
= IDirect3DDevice9_BeginScene(device
);
15077 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
15078 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
15079 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
15080 hr
= IDirect3DDevice9_EndScene(device
);
15081 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
15083 get_rt_readback(original_rt
, &rb
);
15084 for (i
= 0; i
< ARRAY_SIZE(expected_colors
); ++i
)
15086 D3DCOLOR color
= get_readback_color(&rb
, expected_colors
[i
].x
, expected_colors
[i
].y
);
15087 ok(color_match(color
, expected_colors
[i
].color
, 1),
15088 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
15089 expected_colors
[i
].color
, expected_colors
[i
].x
, expected_colors
[i
].y
, color
);
15091 release_surface_readback(&rb
);
15093 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
15094 ok(SUCCEEDED(hr
), "Present failed, hr %#x.\n", hr
);
15096 IDirect3DTexture9_Release(texture
);
15097 IDirect3DPixelShader9_Release(ps
);
15098 IDirect3DSurface9_Release(original_rt
);
15099 IDirect3DSurface9_Release(rt
);
15100 refcount
= IDirect3DDevice9_Release(device
);
15101 ok(!refcount
, "Device has %u references left.\n", refcount
);
15103 IDirect3D9_Release(d3d
);
15104 DestroyWindow(window
);
15107 static void shadow_test(void)
15109 static const DWORD ps_code
[] =
15111 0xffff0200, /* ps_2_0 */
15112 0x0200001f, 0x90000000, 0xa00f0800, /* dcl_2d s0 */
15113 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
15114 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0.0, 0.0, 0.0, 1.0 */
15115 0x02000001, 0x800f0001, 0xa0e40000, /* mov r1, c0 */
15116 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texld r0, t0, s0 */
15117 0x03010042, 0x800f0001, 0xb0e40000, 0xa0e40800, /* texldp r1, t0, s0 */
15118 0x02000001, 0x80020000, 0x80000001, /* mov r0.y, r1.x */
15119 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
15120 0x0000ffff, /* end */
15129 {D3DFMT_D16_LOCKABLE
, "D3DFMT_D16_LOCKABLE"},
15130 {D3DFMT_D32
, "D3DFMT_D32"},
15131 {D3DFMT_D15S1
, "D3DFMT_D15S1"},
15132 {D3DFMT_D24S8
, "D3DFMT_D24S8"},
15133 {D3DFMT_D24X8
, "D3DFMT_D24X8"},
15134 {D3DFMT_D24X4S4
, "D3DFMT_D24X4S4"},
15135 {D3DFMT_D16
, "D3DFMT_D16"},
15136 {D3DFMT_D32F_LOCKABLE
, "D3DFMT_D32F_LOCKABLE"},
15137 {D3DFMT_D24FS8
, "D3DFMT_D24FS8"},
15146 { -1.0f
, 1.0f
, 0.0f
, 0.0f
, 1.0f
, 1.0f
, 0.0f
},
15147 { 1.0f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 0.0f
},
15148 { -1.0f
, -1.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 1.0f
},
15149 { 1.0f
, -1.0f
, 1.0f
, 1.0f
, 0.0f
, 0.0f
, 1.0f
},
15156 expected_colors
[] =
15158 {400, 60, 0x00000000},
15159 {560, 180, 0xffff00ff},
15160 {560, 300, 0xffff00ff},
15161 {400, 420, 0xffffffff},
15162 {240, 420, 0xffffffff},
15163 { 80, 300, 0x00000000},
15164 { 80, 180, 0x00000000},
15165 {240, 60, 0x00000000},
15168 IDirect3DSurface9
*original_ds
, *original_rt
, *rt
;
15169 struct surface_readback rb
;
15170 IDirect3DPixelShader9
*ps
;
15171 IDirect3DDevice9
*device
;
15179 window
= create_window();
15180 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
15181 ok(!!d3d
, "Failed to create a D3D object.\n");
15182 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
15184 skip("Failed to create a D3D device, skipping tests.\n");
15188 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
15189 ok(SUCCEEDED(hr
), "GetDeviceCaps failed, hr %#x.\n", hr
);
15190 if (caps
.PixelShaderVersion
< D3DPS_VERSION(2, 0))
15192 skip("No pixel shader 2.0 support, skipping shadow test.\n");
15193 IDirect3DDevice9_Release(device
);
15197 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &original_rt
);
15198 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
15199 hr
= IDirect3DDevice9_GetDepthStencilSurface(device
, &original_ds
);
15200 ok(SUCCEEDED(hr
), "GetDepthStencilSurface failed, hr %#x.\n", hr
);
15202 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 1024, 1024, D3DFMT_A8R8G8B8
,
15203 D3DMULTISAMPLE_NONE
, 0, FALSE
, &rt
, NULL
);
15204 ok(SUCCEEDED(hr
), "CreateRenderTarget failed, hr %#x.\n", hr
);
15205 hr
= IDirect3DDevice9_CreatePixelShader(device
, ps_code
, &ps
);
15206 ok(SUCCEEDED(hr
), "CreatePixelShader failed, hr %#x.\n", hr
);
15208 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
| D3DFVF_TEXCOORDSIZE4(0));
15209 ok(SUCCEEDED(hr
), "SetFVF failed, hr %#x.\n", hr
);
15210 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_TRUE
);
15211 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
15212 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_ALWAYS
);
15213 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
15214 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, TRUE
);
15215 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
15216 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
15217 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
15219 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSU
, D3DTADDRESS_WRAP
);
15220 ok(SUCCEEDED(hr
), "SetSamplerState failed, hr %#x.\n", hr
);
15221 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSV
, D3DTADDRESS_WRAP
);
15222 ok(SUCCEEDED(hr
), "SetSamplerState failed, hr %#x.\n", hr
);
15223 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAGFILTER
, D3DTEXF_POINT
);
15224 ok(SUCCEEDED(hr
), "SetSamplerState failed, hr %#x.\n", hr
);
15225 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MINFILTER
, D3DTEXF_POINT
);
15226 ok(SUCCEEDED(hr
), "SetSamplerState failed, hr %#x.\n", hr
);
15227 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MIPFILTER
, D3DTEXF_POINT
);
15228 ok(SUCCEEDED(hr
), "SetSamplerState failed, hr %#x.\n", hr
);
15230 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
)
15232 D3DFORMAT format
= formats
[i
].format
;
15233 IDirect3DTexture9
*texture
;
15234 IDirect3DSurface9
*ds
;
15237 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
15238 D3DFMT_X8R8G8B8
, D3DUSAGE_DEPTHSTENCIL
, D3DRTYPE_TEXTURE
, format
)))
15241 hr
= IDirect3DDevice9_CreateTexture(device
, 1024, 1024, 1,
15242 D3DUSAGE_DEPTHSTENCIL
, format
, D3DPOOL_DEFAULT
, &texture
, NULL
);
15243 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
15245 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &ds
);
15246 ok(SUCCEEDED(hr
), "GetSurfaceLevel failed, hr %#x.\n", hr
);
15248 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, ds
);
15249 ok(SUCCEEDED(hr
), "SetDepthStencilSurface failed, hr %#x.\n", hr
);
15251 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt
);
15252 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
15254 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
15255 ok(SUCCEEDED(hr
), "SetPixelShader failed, hr %#x.\n", hr
);
15257 /* Setup the depth/stencil surface. */
15258 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0, 0.0f
, 0);
15259 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
15261 hr
= IDirect3DDevice9_BeginScene(device
);
15262 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
15263 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
15264 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
15265 hr
= IDirect3DDevice9_EndScene(device
);
15266 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
15268 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, NULL
);
15269 ok(SUCCEEDED(hr
), "SetDepthStencilSurface failed, hr %#x.\n", hr
);
15270 IDirect3DSurface9_Release(ds
);
15272 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, original_rt
);
15273 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
15275 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)texture
);
15276 ok(SUCCEEDED(hr
), "SetTexture failed, hr %#x.\n", hr
);
15278 hr
= IDirect3DDevice9_SetPixelShader(device
, ps
);
15279 ok(SUCCEEDED(hr
), "SetPixelShader failed, hr %#x.\n", hr
);
15281 /* Do the actual shadow mapping. */
15282 hr
= IDirect3DDevice9_BeginScene(device
);
15283 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
15284 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
15285 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
15286 hr
= IDirect3DDevice9_EndScene(device
);
15287 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
15289 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
15290 ok(SUCCEEDED(hr
), "SetTexture failed, hr %#x.\n", hr
);
15291 IDirect3DTexture9_Release(texture
);
15293 get_rt_readback(original_rt
, &rb
);
15294 for (j
= 0; j
< ARRAY_SIZE(expected_colors
); ++j
)
15296 D3DCOLOR color
= get_readback_color(&rb
, expected_colors
[j
].x
, expected_colors
[j
].y
);
15297 /* Geforce 7 on Windows returns 1.0 in alpha when the depth format is D24S8 or D24X8,
15298 * whereas other GPUs (all AMD, newer Nvidia) return the same value they return in .rgb.
15299 * Accept alpha mismatches as broken but make sure to check the color channels. */
15300 ok(color_match(color
, expected_colors
[j
].color
, 0)
15301 || broken(color_match(color
& 0x00ffffff, expected_colors
[j
].color
& 0x00ffffff, 0)),
15302 "Expected color 0x%08x at (%u, %u) for format %s, got 0x%08x.\n",
15303 expected_colors
[j
].color
, expected_colors
[j
].x
, expected_colors
[j
].y
,
15304 formats
[i
].name
, color
);
15306 release_surface_readback(&rb
);
15308 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
15309 ok(SUCCEEDED(hr
), "Present failed, hr %#x.\n", hr
);
15312 IDirect3DPixelShader9_Release(ps
);
15313 IDirect3DSurface9_Release(original_ds
);
15314 IDirect3DSurface9_Release(original_rt
);
15315 IDirect3DSurface9_Release(rt
);
15316 refcount
= IDirect3DDevice9_Release(device
);
15317 ok(!refcount
, "Device has %u references left.\n", refcount
);
15319 IDirect3D9_Release(d3d
);
15320 DestroyWindow(window
);
15323 static void clip_planes(IDirect3DDevice9
*device
, const char *test_name
)
15325 static const struct
15327 struct vec3 position
;
15332 {{-1.0f
, -1.0f
, 0.0f
}, 0xfff9e814},
15333 {{-1.0f
, 1.0f
, 0.0f
}, 0xfff9e814},
15334 {{ 1.0f
, -1.0f
, 0.0f
}, 0xfff9e814},
15335 {{ 1.0f
, 1.0f
, 0.0f
}, 0xfff9e814},
15339 {{-1.0f
, -1.0f
, 0.0f
}, 0xff002b7f},
15340 {{-1.0f
, 1.0f
, 0.0f
}, 0xff002b7f},
15341 {{ 1.0f
, -1.0f
, 0.0f
}, 0xff002b7f},
15342 {{ 1.0f
, 1.0f
, 0.0f
}, 0xff002b7f},
15347 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 1.0, 0);
15348 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
15350 hr
= IDirect3DDevice9_BeginScene(device
);
15351 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
15353 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
15354 ok(SUCCEEDED(hr
), "SetFVF failed, hr %#x.\n", hr
);
15356 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CLIPPLANEENABLE
, 0);
15357 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
15358 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(*quad1
));
15359 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
15361 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CLIPPLANEENABLE
, 0x1);
15362 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
15363 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(*quad2
));
15364 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
15366 hr
= IDirect3DDevice9_EndScene(device
);
15367 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
15369 color
= getPixelColor(device
, 1, 240);
15370 ok(color_match(color
, 0x00002b7f, 1), "%s test: color 0x%08x.\n", test_name
, color
);
15371 color
= getPixelColor(device
, 638, 240);
15372 ok(color_match(color
, 0x00002b7f, 1), "%s test: color 0x%08x.\n", test_name
, color
);
15374 color
= getPixelColor(device
, 1, 241);
15375 ok(color_match(color
, 0x00f9e814, 1), "%s test: color 0x%08x.\n", test_name
, color
);
15376 color
= getPixelColor(device
, 638, 241);
15377 ok(color_match(color
, 0x00f9e814, 1), "%s test: color 0x%08x.\n", test_name
, color
);
15380 static void clip_planes_test(void)
15382 IDirect3DSurface9
*offscreen_surface
, *original_rt
;
15383 IDirect3DTexture9
*offscreen
= NULL
;
15384 IDirect3DVertexShader9
*shader
;
15385 IDirect3DDevice9
*device
;
15392 static const float plane0
[4] = {0.0f
, 1.0f
, 0.0f
, 0.5f
/ 480.0f
}; /* a quarter-pixel offset */
15393 static const DWORD shader_code
[] =
15395 0xfffe0200, /* vs_2_0 */
15396 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
15397 0x0200001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
15398 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
15399 0x02000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
15400 0x0000ffff /* end */
15403 window
= create_window();
15404 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
15405 ok(!!d3d
, "Failed to create a D3D object.\n");
15406 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
15408 skip("Failed to create a D3D device, skipping tests.\n");
15412 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
15413 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
15414 if (caps
.VertexShaderVersion
< D3DVS_VERSION(2, 0))
15416 skip("No vs_2_0 support, skipping tests.\n");
15417 IDirect3DDevice9_Release(device
);
15421 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &original_rt
);
15422 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
15424 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
15425 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
15426 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
15427 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
15428 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, FALSE
);
15429 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
15430 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CLIPPING
, TRUE
);
15431 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
15433 hr
= IDirect3DDevice9_SetVertexShader(device
, NULL
);
15434 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader failed, hr=%08x\n", hr
);
15435 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
15436 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader failed, hr=%08x\n", hr
);
15438 IDirect3DDevice9_SetClipPlane(device
, 0, plane0
);
15440 clip_planes(device
, "Onscreen FFP");
15442 hr
= IDirect3DDevice9_CreateTexture(device
, 640, 480, 1, D3DUSAGE_RENDERTARGET
, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &offscreen
, NULL
);
15443 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
15444 hr
= IDirect3DTexture9_GetSurfaceLevel(offscreen
, 0, &offscreen_surface
);
15445 ok(SUCCEEDED(hr
), "GetSurfaceLevel failed, hr %#x.\n", hr
);
15446 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, offscreen_surface
);
15447 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderTarget failed, hr=%08x\n", hr
);
15449 clip_planes(device
, "Offscreen FFP");
15451 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
15452 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
15454 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_code
, &shader
);
15455 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr
);
15456 hr
= IDirect3DDevice9_SetVertexShader(device
, shader
);
15457 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %08x\n", hr
);
15459 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, original_rt
);
15460 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderTarget failed, hr=%08x\n", hr
);
15462 clip_planes(device
, "Onscreen vertex shader");
15464 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, offscreen_surface
);
15465 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderTarget failed, hr=%08x\n", hr
);
15467 clip_planes(device
, "Offscreen vertex shader");
15469 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
15470 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
15472 IDirect3DVertexShader9_Release(shader
);
15473 IDirect3DSurface9_Release(original_rt
);
15474 IDirect3DSurface9_Release(offscreen_surface
);
15475 IDirect3DTexture9_Release(offscreen
);
15476 refcount
= IDirect3DDevice9_Release(device
);
15477 ok(!refcount
, "Device has %u references left.\n", refcount
);
15479 IDirect3D9_Release(d3d
);
15480 DestroyWindow(window
);
15483 static void fp_special_test(void)
15485 /* Microsoft's assembler generates nan and inf with "1.#QNAN" and "1.#INF." respectively */
15486 static const DWORD vs_header
[] =
15488 0xfffe0200, /* vs_2_0 */
15489 0x05000051, 0xa00f0000, 0x00000000, 0x3f000000, 0x3f800000, 0x40000000, /* def c0, 0.0, 0.5, 1.0, 2.0 */
15490 0x05000051, 0xa00f0001, 0x7fc00000, 0xff800000, 0x7f800000, 0x00000000, /* def c1, nan, -inf, inf, 0 */
15491 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
15492 0x0200001f, 0x80000005, 0x900f0001, /* dcl_texcoord0 v1 */
15495 static const DWORD vs_log
[] = {0x0200000f, 0x80010000, 0x90000001}; /* log r0.x, v1.x */
15496 static const DWORD vs_pow
[] =
15497 {0x03000020, 0x80010000, 0x90000001, 0x90000001}; /* pow r0.x, v1.x, v1.x */
15498 static const DWORD vs_nrm
[] = {0x02000024, 0x80070000, 0x90000001}; /* nrm r0.xyz, v1.x */
15499 static const DWORD vs_rcp1
[] = {0x02000006, 0x80010000, 0x90000001}; /* rcp r0.x, v1.x */
15500 static const DWORD vs_rcp2
[] = {0x02000006, 0x80010000, 0x91000001}; /* rcp r0.x, -v1.x */
15501 static const DWORD vs_rsq1
[] = {0x02000007, 0x80010000, 0x90000001}; /* rsq r0.x, v1.x */
15502 static const DWORD vs_rsq2
[] = {0x02000007, 0x80010000, 0x91000001}; /* rsq r0.x, -v1.x */
15503 static const DWORD vs_lit
[] = {0x02000010, 0x800f0000, 0x90000001, /* lit r0, v1.xxxx */
15504 0x02000001, 0x80010000, 0x80aa0000}; /* mov r0.x, v0.z */
15505 static const DWORD vs_def1
[] = {0x02000001, 0x80010000, 0xa0000001}; /* mov r0.x, c1.x */
15506 static const DWORD vs_def2
[] = {0x02000001, 0x80010000, 0xa0550001}; /* mov r0.x, c1.y */
15507 static const DWORD vs_def3
[] = {0x02000001, 0x80010000, 0xa0aa0001}; /* mov r0.x, c1.z */
15509 static const DWORD vs_footer
[] =
15511 0x03000005, 0x80020000, 0x80000000, 0xa0ff0000, /* mul r0.y, r0.x, c0.w */
15512 0x0300000d, 0x80040000, 0x80000000, 0x80550000, /* sge r0.z, r0.x, r0.y */
15513 0x0300000d, 0x80020000, 0x80e40000, 0x80000000, /* sge r0.y, r0, r0.x */
15514 0x03000005, 0x80040000, 0x80550000, 0x80e40000, /* mul r0.z, r0.y, r0 */
15515 0x0300000b, 0x80080000, 0x81aa0000, 0x80aa0000, /* max r0.w, -r0.z, r0.z */
15516 0x0300000c, 0x80020000, 0x80000000, 0x80000000, /* slt r0.y, r0.x, r0.x */
15517 0x03000002, 0x80040000, 0x80550000, 0x80550000, /* add r0.z, r0.y, r0.y */
15518 0x0300000c, 0x80020000, 0xa0000000, 0x80ff0000, /* slt r0.y, c0.x, r0.w */
15519 0x0300000b, 0x80080000, 0x81aa0000, 0x80aa0000, /* max r0.w, -r0.z, r0.z */
15520 0x03000002, 0x80040000, 0x81550000, 0xa0e40000, /* add r0.z, -r0.y, c0 */
15521 0x0300000c, 0x80080000, 0xa0000000, 0x80e40000, /* slt r0.w, c0.x, r0 */
15522 0x03000005, 0x80040000, 0x80ff0000, 0x80e40000, /* mul r0.z, r0.w, r0 */
15523 0x04000004, 0x80020000, 0x80aa0000, 0xa0e40000, 0x80e40000, /* mad r0.y, r0.z, c0, r0 */
15524 0x02000001, 0xe0030000, 0x80e40000, /* mov oT0.xy, r0 */
15525 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
15526 0x0000ffff, /* end */
15529 static const struct
15542 /* The basic ideas here are:
15543 * 2.0 * +/-INF == +/-INF
15546 * The vertex shader value is written to the red component, with 0.0
15547 * and +/-INF mapping to 0xff, and NAN to 0x7f. Anything else should
15548 * result in 0x00. The pixel shader value is written to the green
15549 * component, but here 0.0 also results in 0x00. The actual value is
15550 * written to the blue component.
15552 * There are considerable differences between graphics cards in how
15553 * these are handled, but pow and nrm never generate INF or NAN on
15554 * real hardware. */
15555 {"log", vs_log
, sizeof(vs_log
), 0x00000000, 0x00000000, 0x00ff0000, 0x00ff7f00, 0x00ff8000},
15556 {"pow", vs_pow
, sizeof(vs_pow
), 0x000000ff, 0x000000ff, 0x0000ff00, 0x000000ff, 0x00008000},
15557 {"nrm", vs_nrm
, sizeof(vs_nrm
), 0x00ff0000, 0x00ff0000, 0x0000ff00, 0x00ff0000, 0x00008000},
15558 {"rcp1", vs_rcp1
, sizeof(vs_rcp1
), 0x000000ff, 0x000000ff, 0x00ff00ff, 0x00ff7f00, 0x00ff8000},
15559 {"rcp2", vs_rcp2
, sizeof(vs_rcp2
), 0x000000ff, 0x00000000, 0x00ff0000, 0x00ff7f00, 0x00ff8000},
15560 {"rsq1", vs_rsq1
, sizeof(vs_rsq1
), 0x000000ff, 0x000000ff, 0x00ff00ff, 0x00ff7f00, 0x00ff8000},
15561 {"rsq2", vs_rsq2
, sizeof(vs_rsq2
), 0x000000ff, 0x000000ff, 0x00ff00ff, 0x00ff7f00, 0x00ff8000},
15562 {"lit", vs_lit
, sizeof(vs_lit
), 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000, 0x00ff0000},
15563 {"def1", vs_def1
, sizeof(vs_def1
), 0x000000ff, 0x00007f00, 0x0000ff00, 0x00007f00, 0x00008000},
15564 {"def2", vs_def2
, sizeof(vs_def2
), 0x00ff0000, 0x00ff7f00, 0x00ff0000, 0x00ff7f00, 0x00ff8000},
15565 {"def3", vs_def3
, sizeof(vs_def3
), 0x00ff00ff, 0x00ff7f00, 0x00ff00ff, 0x00ff7f00, 0x00ff8000},
15568 static const DWORD ps_code
[] =
15570 0xffff0200, /* ps_2_0 */
15571 0x05000051, 0xa00f0000, 0x00000000, 0x3f000000, 0x3f800000, 0x40000000, /* def c0, 0.0, 0.5, 1.0, 2.0 */
15572 0x0200001f, 0x80000000, 0xb0030000, /* dcl t0.xy */
15573 0x0300000b, 0x80010001, 0xb0e40000, 0xa0e40000, /* max r1.x, t0, c0 */
15574 0x0300000a, 0x80010000, 0xb0e40000, 0xa0e40000, /* min r0.x, t0, c0 */
15575 0x03000002, 0x80010000, 0x80e40000, 0x81e40001, /* add r0.x, r0, -r1 */
15576 0x04000004, 0x80010001, 0xb0e40000, 0xa0ff0000, 0xb1e40000, /* mad r1.x, t0, c0.w. -t0 */
15577 0x02000023, 0x80010002, 0x80e40001, /* abs r2.x, r1 */
15578 0x02000023, 0x80010000, 0x80e40000, /* abs r0.x, r0 */
15579 0x02000023, 0x80010001, 0xb0e40000, /* abs r1.x, t0 */
15580 0x04000058, 0x80010002, 0x81e40002, 0xa0aa0000, 0xa0e40000, /* cmp r2.x, -r2, c0.z, c0 */
15581 0x02000023, 0x80010002, 0x80e40002, /* abs r2.x, r2 */
15582 0x04000058, 0x80010001, 0x81e40001, 0xa0aa0000, 0xa0e40000, /* cmp r1.x, -r1, c0.z, c0 */
15583 0x02000023, 0x80010001, 0x80e40001, /* abs r1.x, r1 */
15584 0x04000058, 0x80010003, 0x81e40002, 0xa0aa0000, 0xa0e40000, /* cmp r3.x, -r2, c0.z, c0 */
15585 0x04000058, 0x80010002, 0x81e40001, 0xa0aa0000, 0xa0e40000, /* cmp r2.x, -r1, c0.z, c0 */
15586 0x04000058, 0x80010000, 0x81e40000, 0xa0550000, 0xa0e40000, /* cmp r0.x, -r0, c0.y, c0 */
15587 0x03000005, 0x80010002, 0x80e40002, 0x80e40003, /* mul r2.x, r2, r3 */
15588 0x04000058, 0x80010000, 0x81e40002, 0xa0aa0000, 0x80e40000, /* cmp r0.x, -r2, c0.z, r0 */
15589 0x04000058, 0x80020000, 0x81000001, 0x80000000, 0xa0000000, /* cmp r0.y, -r1.x, r0.x, c0.x */
15590 0x02000001, 0x80050000, 0xb0c90000, /* mov r0.xz, t0.yzxw */
15591 0x02000001, 0x80080000, 0xa0aa0000, /* mov r0.w, c0.z */
15592 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
15593 0x0000ffff, /* end */
15603 { -1.0f
, 1.0f
, 0.0f
, 0.0f
},
15604 { 1.0f
, 1.0f
, 1.0f
, 0.0f
},
15605 { -1.0f
, -1.0f
, 0.0f
, 0.0f
},
15606 { 1.0f
, -1.0f
, 1.0f
, 0.0f
},
15609 IDirect3DPixelShader9
*ps
;
15610 IDirect3DDevice9
*device
;
15611 UINT body_size
= 0;
15620 window
= create_window();
15621 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
15622 ok(!!d3d
, "Failed to create a D3D object.\n");
15623 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
15625 skip("Failed to create a D3D device, skipping tests.\n");
15629 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
15630 ok(SUCCEEDED(hr
), "GetDeviceCaps failed, hr %#x.\n", hr
);
15631 if (caps
.PixelShaderVersion
< D3DPS_VERSION(2, 0) || caps
.VertexShaderVersion
< D3DVS_VERSION(2, 0))
15633 skip("No shader model 2.0 support, skipping floating point specials test.\n");
15634 IDirect3DDevice9_Release(device
);
15638 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
| D3DFVF_TEXCOORDSIZE1(0));
15639 ok(SUCCEEDED(hr
), "SetFVF failed, hr %#x.\n", hr
);
15641 hr
= IDirect3DDevice9_CreatePixelShader(device
, ps_code
, &ps
);
15642 ok(SUCCEEDED(hr
), "CreatePixelShader failed, hr %#x.\n", hr
);
15643 hr
= IDirect3DDevice9_SetPixelShader(device
, ps
);
15644 ok(SUCCEEDED(hr
), "SetPixelShader failed, hr %#x.\n", hr
);
15646 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_FALSE
);
15647 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
15649 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0f
, 0);
15650 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
15652 for (i
= 0; i
< ARRAY_SIZE(vs_body
); ++i
)
15654 if (vs_body
[i
].size
> body_size
) body_size
= vs_body
[i
].size
;
15657 vs_code
= HeapAlloc(GetProcessHeap(), 0, sizeof(vs_header
) + body_size
+ sizeof(vs_footer
));
15658 memcpy(vs_code
, vs_header
, sizeof(vs_header
));
15660 for (i
= 0; i
< ARRAY_SIZE(vs_body
); ++i
)
15662 DWORD offset
= ARRAY_SIZE(vs_header
);
15663 IDirect3DVertexShader9
*vs
;
15666 memcpy(vs_code
+ offset
, vs_body
[i
].ops
, vs_body
[i
].size
);
15667 offset
+= vs_body
[i
].size
/ sizeof(*vs_body
[i
].ops
);
15668 memcpy(vs_code
+ offset
, vs_footer
, sizeof(vs_footer
));
15670 hr
= IDirect3DDevice9_CreateVertexShader(device
, vs_code
, &vs
);
15671 ok(SUCCEEDED(hr
), "CreateVertexShader failed, hr %#x.\n", hr
);
15672 hr
= IDirect3DDevice9_SetVertexShader(device
, vs
);
15673 ok(SUCCEEDED(hr
), "SetVertexShader failed, hr %#x.\n", hr
);
15675 hr
= IDirect3DDevice9_BeginScene(device
);
15676 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
15677 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
15678 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
15679 hr
= IDirect3DDevice9_EndScene(device
);
15680 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
15682 color
= getPixelColor(device
, 320, 240);
15683 ok(color_match(color
, vs_body
[i
].r500
, 1)
15684 || color_match(color
, vs_body
[i
].r600
, 1)
15685 || color_match(color
, vs_body
[i
].nv40
, 1)
15686 || color_match(color
, vs_body
[i
].nv50
, 1)
15687 || broken(color_match(color
, vs_body
[i
].warp
, 1)),
15688 "Expected color 0x%08x, 0x%08x, 0x%08x or 0x%08x for instruction \"%s\", got 0x%08x.\n",
15689 vs_body
[i
].r500
, vs_body
[i
].r600
, vs_body
[i
].nv40
, vs_body
[i
].nv50
, vs_body
[i
].name
, color
);
15691 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
15692 ok(SUCCEEDED(hr
), "Present failed, hr %#x.\n", hr
);
15694 hr
= IDirect3DDevice9_SetVertexShader(device
, NULL
);
15695 ok(SUCCEEDED(hr
), "SetVertexShader failed, hr %#x.\n", hr
);
15696 IDirect3DVertexShader9_Release(vs
);
15699 HeapFree(GetProcessHeap(), 0, vs_code
);
15701 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
15702 ok(SUCCEEDED(hr
), "SetPixelShader failed, hr %#x.\n", hr
);
15703 IDirect3DPixelShader9_Release(ps
);
15704 refcount
= IDirect3DDevice9_Release(device
);
15705 ok(!refcount
, "Device has %u references left.\n", refcount
);
15707 IDirect3D9_Release(d3d
);
15708 DestroyWindow(window
);
15711 static void srgbwrite_format_test(void)
15714 IDirect3DSurface9
*rt
, *backbuffer
;
15715 IDirect3DTexture9
*texture
;
15716 IDirect3DDevice9
*device
;
15721 DWORD color_rgb
= 0x00808080, color_srgb
= 0x00bcbcbc, color
;
15722 static const struct
15729 { D3DFMT_R5G6B5
, "D3DFMT_R5G6B5" },
15730 { D3DFMT_X8R8G8B8
, "D3DFMT_X8R8G8B8" },
15731 { D3DFMT_A8R8G8B8
, "D3DFMT_A8R8G8B8" },
15732 { D3DFMT_A16B16G16R16F
, "D3DFMT_A16B16G16R16F" },
15733 { D3DFMT_A32B32G32R32F
, "D3DFMT_A32B32G32R32F" },
15735 static const struct
15742 {-1.0f
, -1.0f
, 0.1f
, 0.0f
, 0.0f
},
15743 {-1.0f
, 1.0f
, 0.1f
, 1.0f
, 0.0f
},
15744 { 1.0f
, -1.0f
, 0.1f
, 0.0f
, 1.0f
},
15745 { 1.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
}
15748 window
= create_window();
15749 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
15750 ok(!!d3d
, "Failed to create a D3D object.\n");
15751 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
15753 skip("Failed to create a D3D device, skipping tests.\n");
15757 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
15758 ok(SUCCEEDED(hr
), "SetFVF failed, hr %#x.\n", hr
);
15759 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
15760 ok(SUCCEEDED(hr
), "GetBackBuffer failed, hr %#x.\n", hr
);
15761 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
15762 ok(SUCCEEDED(hr
), "SetTextureStageState failed, hr %#x.\n", hr
);
15763 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_TEXTUREFACTOR
, 0x80808080);
15764 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
15766 for(i
= 0; i
< ARRAY_SIZE(formats
); i
++)
15768 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
15769 D3DUSAGE_RENDERTARGET
, D3DRTYPE_TEXTURE
, formats
[i
].fmt
)))
15771 skip("Format %s not supported as render target, skipping test.\n",
15776 hr
= IDirect3DDevice9_CreateTexture(device
, 8, 8, 1, D3DUSAGE_RENDERTARGET
,
15777 formats
[i
].fmt
, D3DPOOL_DEFAULT
, &texture
, NULL
);
15778 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
15779 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x00ff0000, 1.0f
, 0);
15780 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
15782 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &rt
);
15783 ok(SUCCEEDED(hr
), "GetSurfaceLevel failed, hr %#x.\n", hr
);
15784 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt
);
15785 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
15786 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x000000ff, 0.0f
, 0);
15787 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
15789 hr
= IDirect3DDevice9_BeginScene(device
);
15790 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
15792 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SRGBWRITEENABLE
, TRUE
);
15793 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
15794 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TFACTOR
);
15795 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
15796 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
15797 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
15799 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SRGBWRITEENABLE
, FALSE
);
15800 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
15801 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
15802 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
15803 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) texture
);
15804 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
15805 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
15806 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
15807 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
15808 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
15809 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
15810 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
15812 hr
= IDirect3DDevice9_EndScene(device
);
15813 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
15815 IDirect3DSurface9_Release(rt
);
15816 IDirect3DTexture9_Release(texture
);
15818 color
= getPixelColor(device
, 360, 240);
15819 if(IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
15820 D3DUSAGE_QUERY_SRGBWRITE
,
15821 D3DRTYPE_TEXTURE
, formats
[i
].fmt
) == D3D_OK
)
15823 /* Big slop for R5G6B5 */
15824 ok(color_match(color
, color_srgb
, 5), "Format %s supports srgb, expected color 0x%08x, got 0x%08x\n",
15825 formats
[i
].name
, color_srgb
, color
);
15829 /* Big slop for R5G6B5 */
15830 ok(color_match(color
, color_rgb
, 5), "Format %s does not support srgb, expected color 0x%08x, got 0x%08x\n",
15831 formats
[i
].name
, color_rgb
, color
);
15834 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
15835 ok(SUCCEEDED(hr
), "Present failed, hr %#x.\n", hr
);
15838 IDirect3DSurface9_Release(backbuffer
);
15839 refcount
= IDirect3DDevice9_Release(device
);
15840 ok(!refcount
, "Device has %u references left.\n", refcount
);
15842 IDirect3D9_Release(d3d
);
15843 DestroyWindow(window
);
15846 static void ds_size_test(void)
15848 IDirect3DSurface9
*ds
, *rt
, *old_rt
, *old_ds
, *readback
;
15849 IDirect3DDevice9
*device
;
15856 static const struct
15862 {-1.0f
, -1.0f
, 0.0f
},
15863 {-1.0f
, 1.0f
, 0.0f
},
15864 { 1.0f
, -1.0f
, 0.0f
},
15865 { 1.0f
, 1.0f
, 0.0f
},
15868 window
= create_window();
15869 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
15870 ok(!!d3d
, "Failed to create a D3D object.\n");
15871 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
15873 skip("Failed to create a D3D device, skipping tests.\n");
15877 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 64, 64, D3DFMT_A8R8G8B8
, D3DMULTISAMPLE_NONE
, 0, FALSE
, &rt
, NULL
);
15878 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateRenderTarget failed, hr %#x.\n", hr
);
15879 hr
= IDirect3DDevice9_CreateDepthStencilSurface(device
, 32, 32, D3DFMT_D24X8
, D3DMULTISAMPLE_NONE
, 0, TRUE
, &ds
, NULL
);
15880 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateDepthStencilSurface failed, hr %#x.\n", hr
);
15881 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 64, 64, D3DFMT_A8R8G8B8
, D3DPOOL_SYSTEMMEM
, &readback
, NULL
);
15882 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateOffscreenPlainSurface failed, hr %#x.\n", hr
);
15884 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
15885 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
15887 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
15888 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr
);
15889 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILENABLE
, FALSE
);
15890 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr
);
15891 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, FALSE
);
15892 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr
);
15893 hr
= IDirect3DDevice9_ValidateDevice(device
, &num_passes
);
15894 ok(SUCCEEDED(hr
), "IDirect3DDevice9_ValidateDevice failed, hr %#x.\n", hr
);
15895 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &old_rt
);
15896 ok(SUCCEEDED(hr
), "IDirect3DDevice9_GetRenderTarget failed, hr %#x.\n", hr
);
15897 hr
= IDirect3DDevice9_GetDepthStencilSurface(device
, &old_ds
);
15898 ok(SUCCEEDED(hr
), "IDirect3DDevice9_GetDepthStencilSurface failed, hr %#x.\n", hr
);
15899 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt
);
15900 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetRenderTarget failed, hr %#x.\n", hr
);
15901 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, ds
);
15902 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetDepthStencilSurface failed, hr %#x.\n", hr
);
15903 hr
= IDirect3DDevice9_ValidateDevice(device
, &num_passes
);
15904 ok(SUCCEEDED(hr
), "IDirect3DDevice9_ValidateDevice failed, hr %#x.\n", hr
);
15906 /* The D3DCLEAR_TARGET clear works. D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER returns OK,
15907 * but does not change the surface's contents. */
15908 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x000000FF, 0.0f
, 0);
15909 ok(SUCCEEDED(hr
), "Target clear failed, hr %#x.\n", hr
);
15910 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0x00000000, 0.2f
, 0);
15911 ok(SUCCEEDED(hr
), "Z Buffer clear failed, hr %#x.\n", hr
);
15912 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x00ff0000, 0.5f
, 0);
15913 ok(SUCCEEDED(hr
), "Target and Z Buffer clear failed, hr %#x.\n", hr
);
15915 /* Nvidia does not clear the surface(The color is still 0x000000ff), AMD does(the color is 0x00ff0000) */
15917 /* Turning on any depth-related state results in a ValidateDevice failure */
15918 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_TRUE
);
15919 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr
);
15920 hr
= IDirect3DDevice9_ValidateDevice(device
, &num_passes
);
15921 ok(hr
== D3DERR_CONFLICTINGRENDERSTATE
|| hr
== D3D_OK
, "IDirect3DDevice9_ValidateDevice returned %#x, expected "
15922 "D3DERR_CONFLICTINGRENDERSTATE.\n", hr
);
15923 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_FALSE
);
15924 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr
);
15925 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, TRUE
);
15926 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetRenderState failed, hr %#x.\n", hr
);
15927 hr
= IDirect3DDevice9_ValidateDevice(device
, &num_passes
);
15928 ok(hr
== D3DERR_CONFLICTINGRENDERSTATE
|| hr
== D3D_OK
, "IDirect3DDevice9_ValidateDevice returned %#x, expected "
15929 "D3DERR_CONFLICTINGRENDERSTATE.\n", hr
);
15931 /* Try to draw with the device in an invalid state. */
15932 hr
= IDirect3DDevice9_BeginScene(device
);
15933 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
15934 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
15935 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
15936 hr
= IDirect3DDevice9_EndScene(device
);
15937 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
15939 /* Don't check the resulting draw unless we find an app that needs it. On
15940 * NVIDIA ValidateDevice() returns CONFLICTINGRENDERSTATE, so the result
15941 * is undefined. On AMD D3D seems to assume the stored Z buffer value is
15942 * 0.0 for all pixels, even those that are covered by the depth buffer. */
15944 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, old_rt
);
15945 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetRenderTarget failed, hr %#x.\n", hr
);
15946 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, old_ds
);
15947 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetDepthStencilSurface failed, hr %#x.\n", hr
);
15948 hr
= IDirect3DDevice9_ValidateDevice(device
, &num_passes
);
15949 ok(SUCCEEDED(hr
), "IDirect3DDevice9_ValidateDevice failed, hr %#x.\n", hr
);
15951 IDirect3DSurface9_Release(readback
);
15952 IDirect3DSurface9_Release(ds
);
15953 IDirect3DSurface9_Release(rt
);
15954 IDirect3DSurface9_Release(old_rt
);
15955 IDirect3DSurface9_Release(old_ds
);
15956 refcount
= IDirect3DDevice9_Release(device
);
15957 ok(!refcount
, "Device has %u references left.\n", refcount
);
15959 IDirect3D9_Release(d3d
);
15960 DestroyWindow(window
);
15963 static void unbound_sampler_test(void)
15965 IDirect3DPixelShader9
*ps
, *ps_cube
, *ps_volume
;
15966 IDirect3DSurface9
*rt
, *old_rt
;
15967 IDirect3DDevice9
*device
;
15975 static const DWORD ps_code
[] =
15977 0xffff0200, /* ps_2_0 */
15978 0x0200001f, 0x90000000, 0xa00f0800, /* dcl_2d s0 */
15979 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
15980 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texld r0, t0, s0 */
15981 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
15982 0x0000ffff, /* end */
15984 static const DWORD ps_code_cube
[] =
15986 0xffff0200, /* ps_2_0 */
15987 0x0200001f, 0x98000000, 0xa00f0800, /* dcl_cube s0 */
15988 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
15989 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texld r0, t0, s0 */
15990 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
15991 0x0000ffff, /* end */
15993 static const DWORD ps_code_volume
[] =
15995 0xffff0200, /* ps_2_0 */
15996 0x0200001f, 0xa0000000, 0xa00f0800, /* dcl_volume s0 */
15997 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
15998 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texld r0, t0, s0 */
15999 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
16000 0x0000ffff, /* end */
16003 static const struct
16010 {-1.0f
, -1.0f
, 0.1f
, 0.0f
, 0.0f
},
16011 {-1.0f
, 1.0f
, 0.1f
, 1.0f
, 0.0f
},
16012 { 1.0f
, -1.0f
, 0.1f
, 0.0f
, 1.0f
},
16013 { 1.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
}
16016 window
= create_window();
16017 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
16018 ok(!!d3d
, "Failed to create a D3D object.\n");
16019 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
16021 skip("Failed to create a D3D device, skipping tests.\n");
16025 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
16026 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
16027 if (caps
.PixelShaderVersion
< D3DPS_VERSION(2, 0))
16029 skip("No ps_2_0 support, skipping tests.\n");
16030 IDirect3DDevice9_Release(device
);
16033 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
) || !(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
))
16035 skip("No cube / volume texture support, skipping tests.\n");
16036 IDirect3DDevice9_Release(device
);
16040 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
16041 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStage failed, %#x.\n", hr
);
16043 hr
= IDirect3DDevice9_CreatePixelShader(device
, ps_code
, &ps
);
16044 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreatePixelShader failed, hr %#x.\n", hr
);
16045 hr
= IDirect3DDevice9_CreatePixelShader(device
, ps_code_cube
, &ps_cube
);
16046 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreatePixelShader failed, hr %#x.\n", hr
);
16047 hr
= IDirect3DDevice9_CreatePixelShader(device
, ps_code_volume
, &ps_volume
);
16048 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreatePixelShader failed, hr %#x.\n", hr
);
16050 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 64, 64, D3DFMT_A8R8G8B8
, D3DMULTISAMPLE_NONE
, 0, TRUE
, &rt
, NULL
);
16051 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateRenderTarget failed, hr %#x.\n", hr
);
16053 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &old_rt
);
16054 ok(SUCCEEDED(hr
), "IDirect3DDevice9_GetRenderTarget failed, hr %#x.\n", hr
);
16056 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt
);
16057 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetRenderTarget failed, hr %#x.\n", hr
);
16059 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
16060 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetFVF failed, hr %#x.\n", hr
);
16062 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x56ffffff, 1.0f
, 0);
16063 ok(SUCCEEDED(hr
), "IDirect3DDevice9_Clear failed, hr %#x.\n", hr
);
16065 hr
= IDirect3DDevice9_SetPixelShader(device
, ps
);
16066 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetPixelShader failed, hr %#x.\n", hr
);
16068 hr
= IDirect3DDevice9_BeginScene(device
);
16069 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
16070 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
16071 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
16072 hr
= IDirect3DDevice9_EndScene(device
);
16073 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
16075 color
= getPixelColorFromSurface(rt
, 32, 32);
16076 ok(color
== 0xff000000, "Unbound sampler color is %#x.\n", color
);
16078 /* Now try with a cube texture */
16079 hr
= IDirect3DDevice9_SetPixelShader(device
, ps_cube
);
16080 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetPixelShader failed, hr %#x.\n", hr
);
16082 hr
= IDirect3DDevice9_BeginScene(device
);
16083 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
16084 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
16085 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
16086 hr
= IDirect3DDevice9_EndScene(device
);
16087 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
16089 color
= getPixelColorFromSurface(rt
, 32, 32);
16090 ok(color
== 0xff000000, "Unbound sampler color is %#x.\n", color
);
16092 /* And then with a volume texture */
16093 hr
= IDirect3DDevice9_SetPixelShader(device
, ps_volume
);
16094 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetPixelShader failed, hr %#x.\n", hr
);
16096 hr
= IDirect3DDevice9_BeginScene(device
);
16097 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
16098 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
16099 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
16100 hr
= IDirect3DDevice9_EndScene(device
);
16101 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
16103 color
= getPixelColorFromSurface(rt
, 32, 32);
16104 ok(color
== 0xff000000, "Unbound sampler color is %#x.\n", color
);
16106 IDirect3DSurface9_Release(rt
);
16107 IDirect3DSurface9_Release(old_rt
);
16108 IDirect3DPixelShader9_Release(ps
);
16109 IDirect3DPixelShader9_Release(ps_cube
);
16110 IDirect3DPixelShader9_Release(ps_volume
);
16111 refcount
= IDirect3DDevice9_Release(device
);
16112 ok(!refcount
, "Device has %u references left.\n", refcount
);
16114 IDirect3D9_Release(d3d
);
16115 DestroyWindow(window
);
16118 static void update_surface_test(void)
16120 static const BYTE blocks
[][8] =
16122 {0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00}, /* White */
16123 {0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00}, /* Red */
16124 {0xe0, 0xff, 0xe0, 0xff, 0x00, 0x00, 0x00, 0x00}, /* Yellow */
16125 {0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00}, /* Green */
16126 {0xff, 0x07, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00}, /* Cyan */
16127 {0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00}, /* Blue */
16128 {0x1f, 0xf8, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00}, /* Magenta */
16130 static const struct
16135 expected_colors
[] =
16137 { 18, 240, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0xff)},
16138 { 57, 240, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0xff)},
16139 {109, 240, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0xff)},
16140 {184, 240, D3DCOLOR_ARGB(0x00, 0x00, 0xff, 0x00)},
16141 {290, 240, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x00)},
16142 {440, 240, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x00)},
16143 {584, 240, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0xff)},
16145 static const struct
16152 { 0.0f
, 480.0f
, 0.0f
, 1.0f
, 0.0f
, 0.0f
},
16153 { 0.0f
, 0.0f
, 0.0f
, 1.0f
, 0.0f
, 1.0f
},
16154 {640.0f
, 240.0f
, 0.0f
, 10.0f
, 100.0f
, 0.5f
},
16156 static const RECT rect_2x2
= {0, 0, 2, 2};
16157 static const struct
16164 block_size_tests
[] =
16166 {1, 0, NULL
, D3D_OK
},
16167 {0, 1, NULL
, D3DERR_INVALIDCALL
},
16168 {5, 4, NULL
, D3DERR_INVALIDCALL
},
16169 {4, 5, NULL
, D3DERR_INVALIDCALL
},
16170 {4, 5, &rect_2x2
, D3DERR_INVALIDCALL
},
16171 {5, 5, &rect_2x2
, D3D_OK
},
16174 IDirect3DSurface9
*src_surface
, *dst_surface
;
16175 IDirect3DTexture9
*src_tex
, *dst_tex
;
16176 IDirect3DDevice9
*device
;
16183 window
= create_window();
16184 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
16185 ok(!!d3d
, "Failed to create a D3D object.\n");
16186 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
16187 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_TEXTURE
, D3DFMT_DXT1
)))
16189 skip("DXT1 not supported, skipping tests.\n");
16192 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
16194 skip("Failed to create a D3D device, skipping tests.\n");
16198 hr
= IDirect3DDevice9_CreateTexture(device
, 64, 64, 0, 0, D3DFMT_DXT1
, D3DPOOL_SYSTEMMEM
, &src_tex
, NULL
);
16199 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
16200 hr
= IDirect3DDevice9_CreateTexture(device
, 64, 64, 0, 0, D3DFMT_DXT1
, D3DPOOL_DEFAULT
, &dst_tex
, NULL
);
16201 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
16203 count
= IDirect3DTexture9_GetLevelCount(src_tex
);
16204 ok(count
== 7, "Got level count %u, expected 7.\n", count
);
16206 for (i
= 0; i
< count
; ++i
)
16208 UINT row_count
, block_count
, x
, y
;
16209 D3DSURFACE_DESC desc
;
16213 hr
= IDirect3DTexture9_GetLevelDesc(src_tex
, i
, &desc
);
16214 ok(SUCCEEDED(hr
), "Failed to get level desc, hr %#x.\n", hr
);
16216 hr
= IDirect3DTexture9_LockRect(src_tex
, i
, &r
, NULL
, 0);
16217 ok(SUCCEEDED(hr
), "Failed to lock texture, hr %#x.\n", hr
);
16219 row_count
= ((desc
.Height
+ 3) & ~3) / 4;
16220 block_count
= ((desc
.Width
+ 3) & ~3) / 4;
16223 for (y
= 0; y
< row_count
; ++y
)
16226 for (x
= 0; x
< block_count
; ++x
)
16228 memcpy(block
, blocks
[i
], sizeof(blocks
[i
]));
16229 block
+= sizeof(blocks
[i
]);
16234 hr
= IDirect3DTexture9_UnlockRect(src_tex
, i
);
16235 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x.\n", hr
);
16238 for (i
= 0; i
< ARRAY_SIZE(block_size_tests
); ++i
)
16240 hr
= IDirect3DTexture9_GetSurfaceLevel(src_tex
, block_size_tests
[i
].src_level
, &src_surface
);
16241 ok(SUCCEEDED(hr
), "Failed to get texture surface, hr %#x.\n", hr
);
16242 hr
= IDirect3DTexture9_GetSurfaceLevel(dst_tex
, block_size_tests
[i
].dst_level
, &dst_surface
);
16243 ok(SUCCEEDED(hr
), "Failed to get texture surface, hr %#x.\n", hr
);
16245 hr
= IDirect3DDevice9_UpdateSurface(device
, src_surface
, block_size_tests
[i
].r
, dst_surface
, NULL
);
16246 ok(hr
== block_size_tests
[i
].hr
, "Update surface returned %#x for test %u, expected %#x.\n",
16247 hr
, i
, block_size_tests
[i
].hr
);
16249 IDirect3DSurface9_Release(dst_surface
);
16250 IDirect3DSurface9_Release(src_surface
);
16253 for (i
= 0; i
< count
; ++i
)
16255 hr
= IDirect3DTexture9_GetSurfaceLevel(src_tex
, i
, &src_surface
);
16256 ok(SUCCEEDED(hr
), "Failed to get texture surface, hr %#x.\n", hr
);
16257 hr
= IDirect3DTexture9_GetSurfaceLevel(dst_tex
, i
, &dst_surface
);
16258 ok(SUCCEEDED(hr
), "Failed to get texture surface, hr %#x.\n", hr
);
16260 hr
= IDirect3DDevice9_UpdateSurface(device
, src_surface
, NULL
, dst_surface
, NULL
);
16261 ok(SUCCEEDED(hr
), "Failed to update surface at level %u, hr %#x.\n", i
, hr
);
16263 IDirect3DSurface9_Release(dst_surface
);
16264 IDirect3DSurface9_Release(src_surface
);
16267 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
16268 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
16269 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MIPFILTER
, D3DTEXF_POINT
);
16270 ok(SUCCEEDED(hr
), "SetSamplerState failed, hr %#x.\n", hr
);
16271 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZRHW
| D3DFVF_TEX1
);
16272 ok(SUCCEEDED(hr
), "SetFVF failed, hr %#x.\n", hr
);
16273 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)dst_tex
);
16274 ok(SUCCEEDED(hr
), "SetTexture failed, hr %#x.\n", hr
);
16275 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
16276 ok(SUCCEEDED(hr
), "SetTextureStageState failed, hr %#x.\n", hr
);
16277 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
16278 ok(SUCCEEDED(hr
), "SetTextureStageState failed, hr %#x.\n", hr
);
16280 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff000000, 0.0f
, 0);
16281 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
16283 hr
= IDirect3DDevice9_BeginScene(device
);
16284 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
16285 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 1, tri
, sizeof(*tri
));
16286 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
16287 hr
= IDirect3DDevice9_EndScene(device
);
16288 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
16290 for (i
= 0; i
< ARRAY_SIZE(expected_colors
); ++i
)
16292 D3DCOLOR color
= getPixelColor(device
, expected_colors
[i
].x
, expected_colors
[i
].y
);
16293 ok(color_match(color
, expected_colors
[i
].color
, 0),
16294 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
16295 expected_colors
[i
].color
, expected_colors
[i
].x
, expected_colors
[i
].y
, color
);
16298 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
16299 ok(SUCCEEDED(hr
), "Present failed, hr %#x.\n", hr
);
16301 IDirect3DTexture9_Release(dst_tex
);
16302 IDirect3DTexture9_Release(src_tex
);
16303 refcount
= IDirect3DDevice9_Release(device
);
16304 ok(!refcount
, "Device has %u references left.\n", refcount
);
16306 IDirect3D9_Release(d3d
);
16307 DestroyWindow(window
);
16310 static void multisample_get_rtdata_test(void)
16312 IDirect3DSurface9
*original_ds
, *original_rt
, *rt
, *readback
;
16313 IDirect3DDevice9
*device
;
16319 window
= create_window();
16320 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
16321 ok(!!d3d
, "Failed to create a D3D object.\n");
16322 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
16323 D3DFMT_A8R8G8B8
, TRUE
, D3DMULTISAMPLE_2_SAMPLES
, NULL
)))
16325 skip("Multisampling not supported for D3DFMT_A8R8G8B8, skipping tests.\n");
16328 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
16330 skip("Failed to create a D3D device, skipping tests.\n");
16334 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 256, 256, D3DFMT_A8R8G8B8
,
16335 D3DMULTISAMPLE_2_SAMPLES
, 0, FALSE
, &rt
, NULL
);
16336 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
16337 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 256, 256, D3DFMT_A8R8G8B8
,
16338 D3DPOOL_SYSTEMMEM
, &readback
, NULL
);
16339 ok(SUCCEEDED(hr
), "Failed to create readback surface, hr %#x.\n", hr
);
16341 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &original_rt
);
16342 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
16343 hr
= IDirect3DDevice9_GetDepthStencilSurface(device
, &original_ds
);
16344 ok(SUCCEEDED(hr
), "Failed to get depth/stencil, hr %#x.\n", hr
);
16346 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt
);
16347 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
16348 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, NULL
);
16349 ok(SUCCEEDED(hr
), "Failed to set depth/stencil, hr %#x.\n", hr
);
16351 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0, 0);
16352 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
16353 hr
= IDirect3DDevice9_GetRenderTargetData(device
, rt
, readback
);
16354 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
16356 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, original_ds
);
16357 ok(SUCCEEDED(hr
), "Failed to set depth/stencil, hr %#x.\n", hr
);
16358 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, original_rt
);
16359 ok(SUCCEEDED(hr
), "Failed to restore original render target, hr %#x.\n", hr
);
16361 IDirect3DSurface9_Release(original_ds
);
16362 IDirect3DSurface9_Release(original_rt
);
16363 IDirect3DSurface9_Release(readback
);
16364 IDirect3DSurface9_Release(rt
);
16365 refcount
= IDirect3DDevice9_Release(device
);
16366 ok(!refcount
, "Device has %u references left.\n", refcount
);
16368 IDirect3D9_Release(d3d
);
16369 DestroyWindow(window
);
16372 static void test_multisample_get_front_buffer_data(void)
16374 IDirect3DSwapChain9
*swapchain
;
16375 D3DPRESENT_PARAMETERS d3dpp
;
16376 IDirect3DSurface9
*readback
;
16377 IDirect3DTexture9
*texture
;
16378 IDirect3DDevice9
*device
;
16385 window
= create_window();
16386 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
16387 ok(!!d3d
, "Failed to create D3D object.\n");
16388 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
16389 D3DFMT_A8R8G8B8
, TRUE
, D3DMULTISAMPLE_2_SAMPLES
, NULL
)))
16391 skip("Multisampling not supported for D3DFMT_A8R8G8B8.\n");
16394 if (!(device
= create_device(d3d
, window
, window
, FALSE
)))
16396 skip("Failed to create D3D device.\n");
16400 hr
= IDirect3DDevice9_GetSwapChain(device
, 0, &swapchain
);
16401 ok(hr
== D3D_OK
, "Failed to get the implicit swapchain, hr %#x.\n", hr
);
16402 hr
= IDirect3DSwapChain9_GetPresentParameters(swapchain
, &d3dpp
);
16403 ok(hr
== D3D_OK
, "Failed to get present parameters, hr %#x.\n", hr
);
16404 IDirect3DSwapChain9_Release(swapchain
);
16405 d3dpp
.MultiSampleType
= D3DMULTISAMPLE_2_SAMPLES
;
16406 d3dpp
.MultiSampleQuality
= 0;
16407 hr
= IDirect3DDevice9_Reset(device
, &d3dpp
);
16408 ok(hr
== D3D_OK
, "Failed to reset device, hr %#x.\n", hr
);
16410 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00f0ff0f, 0.0, 0);
16411 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
16412 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
16413 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
16415 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 640, 480, D3DFMT_A8R8G8B8
,
16416 D3DPOOL_SYSTEMMEM
, &readback
, NULL
);
16417 ok(SUCCEEDED(hr
), "Failed to create readback surface, hr %#x.\n", hr
);
16418 hr
= IDirect3DDevice9_GetFrontBufferData(device
, 0, readback
);
16419 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
16420 color
= getPixelColorFromSurface(readback
, 320, 240);
16421 ok(color
== 0x00f0ff0f, "Got unexpected color 0x%08x.\n", color
);
16422 IDirect3DSurface9_Release(readback
);
16424 hr
= IDirect3DDevice9_CreateTexture(device
, 640, 480, 1,
16425 0, D3DFMT_A8R8G8B8
, D3DPOOL_SYSTEMMEM
, &texture
, NULL
);
16426 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
16428 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &readback
);
16429 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
16430 hr
= IDirect3DDevice9_GetFrontBufferData(device
, 0, readback
);
16431 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
16432 color
= getPixelColorFromSurface(readback
, 320, 240);
16433 ok(color
== 0x00f0ff0f, "Got unexpected color 0x%08x.\n", color
);
16434 IDirect3DSurface9_Release(readback
);
16435 IDirect3DTexture9_Release(texture
);
16437 refcount
= IDirect3DDevice9_Release(device
);
16438 ok(!refcount
, "Device has %u references left.\n", refcount
);
16440 IDirect3D9_Release(d3d
);
16441 DestroyWindow(window
);
16444 static void multisampled_depth_buffer_test(void)
16446 IDirect3DDevice9
*device
= 0;
16447 IDirect3DSurface9
*original_rt
, *rt
, *readback
, *ds
, *original_ds
;
16451 D3DPRESENT_PARAMETERS present_parameters
;
16453 static const struct
16460 { -1.0f
, 1.0f
, 0.0f
, 0xffff0000},
16461 { 1.0f
, 1.0f
, 1.0f
, 0xffff0000},
16462 { -1.0f
, -1.0f
, 0.0f
, 0xffff0000},
16463 { 1.0f
, -1.0f
, 1.0f
, 0xffff0000},
16467 { -1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
16468 { 1.0f
, 1.0f
, 0.0f
, 0xff0000ff},
16469 { -1.0f
, -1.0f
, 1.0f
, 0xff0000ff},
16470 { 1.0f
, -1.0f
, 0.0f
, 0xff0000ff},
16472 static const struct
16477 expected_colors
[] =
16479 { 80, 100, D3DCOLOR_ARGB(0xff, 0xff, 0x00, 0x00)},
16480 {240, 100, D3DCOLOR_ARGB(0xff, 0xff, 0x00, 0x00)},
16481 {400, 100, D3DCOLOR_ARGB(0xff, 0x00, 0x00, 0xff)},
16482 {560, 100, D3DCOLOR_ARGB(0xff, 0x00, 0x00, 0xff)},
16483 { 80, 450, D3DCOLOR_ARGB(0xff, 0xff, 0x00, 0x00)},
16484 {240, 450, D3DCOLOR_ARGB(0xff, 0xff, 0x00, 0x00)},
16485 {400, 450, D3DCOLOR_ARGB(0xff, 0x00, 0x00, 0xff)},
16486 {560, 450, D3DCOLOR_ARGB(0xff, 0x00, 0x00, 0xff)},
16489 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
16490 ok(!!d3d
, "Failed to create a D3D object.\n");
16492 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
,
16493 D3DDEVTYPE_HAL
, D3DFMT_A8R8G8B8
, TRUE
, D3DMULTISAMPLE_2_SAMPLES
, NULL
)))
16495 skip("Multisampling not supported for D3DFMT_A8R8G8B8, skipping multisampled depth buffer test.\n");
16496 IDirect3D9_Release(d3d
);
16499 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
,
16500 D3DDEVTYPE_HAL
, D3DFMT_D24S8
, TRUE
, D3DMULTISAMPLE_2_SAMPLES
, NULL
)))
16502 skip("Multisampling not supported for D3DFMT_D24S8, skipping multisampled depth buffer test.\n");
16503 IDirect3D9_Release(d3d
);
16507 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
16508 present_parameters
.Windowed
= TRUE
;
16509 present_parameters
.hDeviceWindow
= create_window();
16510 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
16511 present_parameters
.BackBufferWidth
= 640;
16512 present_parameters
.BackBufferHeight
= 480;
16513 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
16514 present_parameters
.EnableAutoDepthStencil
= TRUE
;
16515 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
16516 present_parameters
.MultiSampleType
= D3DMULTISAMPLE_2_SAMPLES
;
16518 hr
= IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
16519 present_parameters
.hDeviceWindow
, D3DCREATE_HARDWARE_VERTEXPROCESSING
,
16520 &present_parameters
, &device
);
16521 ok(hr
== D3D_OK
, "Failed to create a device, hr %#x.\n", hr
);
16523 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
16524 ok(SUCCEEDED(hr
), "GetDeviceCaps failed, hr %#x.\n", hr
);
16525 if (caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
)
16527 skip("No unconditional NP2 texture support, skipping multisampled depth buffer test.\n");
16531 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 640, 480, D3DFMT_A8R8G8B8
,
16532 D3DMULTISAMPLE_2_SAMPLES
, 0, FALSE
, &rt
, NULL
);
16533 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
16534 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 640, 480, D3DFMT_A8R8G8B8
,
16535 D3DMULTISAMPLE_NONE
, 0, TRUE
, &readback
, NULL
);
16536 ok(SUCCEEDED(hr
), "Failed to create readback surface, hr %#x.\n", hr
);
16538 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &original_rt
);
16539 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
16540 hr
= IDirect3DDevice9_GetDepthStencilSurface(device
, &ds
);
16541 ok(SUCCEEDED(hr
), "Failed to get depth/stencil, hr %#x.\n", hr
);
16543 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
16544 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
16545 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_TRUE
);
16546 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
16547 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, TRUE
);
16548 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
16549 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_LESSEQUAL
);
16550 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
16551 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
16552 ok(SUCCEEDED(hr
), "SetFVF failed, hr %#x.\n", hr
);
16554 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff00ff00, 1.0f
, 0);
16555 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
16557 /* Render onscreen and then offscreen */
16558 hr
= IDirect3DDevice9_BeginScene(device
);
16559 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
16560 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad_1
, sizeof(*quad_1
));
16561 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
16562 hr
= IDirect3DDevice9_EndScene(device
);
16563 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
16565 hr
= IDirect3DDevice9_StretchRect(device
, original_rt
, NULL
, rt
, NULL
, D3DTEXF_POINT
);
16566 ok(SUCCEEDED(hr
), "StretchRect failed, hr %#x.\n", hr
);
16567 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt
);
16568 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
16570 hr
= IDirect3DDevice9_BeginScene(device
);
16571 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
16572 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad_2
, sizeof(*quad_2
));
16573 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
16574 hr
= IDirect3DDevice9_EndScene(device
);
16575 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
16577 hr
= IDirect3DDevice9_StretchRect(device
, rt
, NULL
, readback
, NULL
, D3DTEXF_POINT
);
16578 ok(SUCCEEDED(hr
), "StretchRect failed, hr %#x.\n", hr
);
16580 for (i
= 0; i
< ARRAY_SIZE(expected_colors
); ++i
)
16582 D3DCOLOR color
= getPixelColorFromSurface(readback
, expected_colors
[i
].x
, expected_colors
[i
].y
);
16583 ok(color_match(color
, expected_colors
[i
].color
, 1),
16584 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
16585 expected_colors
[i
].color
, expected_colors
[i
].x
, expected_colors
[i
].y
, color
);
16588 hr
= IDirect3DDevice9_StretchRect(device
, rt
, NULL
, original_rt
, NULL
, D3DTEXF_POINT
);
16589 ok(SUCCEEDED(hr
), "StretchRect failed, hr %#x.\n", hr
);
16590 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
16591 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
16593 /* Render offscreen and then onscreen */
16594 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, NULL
);
16595 ok(SUCCEEDED(hr
), "Failed to set depth/stencil, hr %#x.\n", hr
);
16596 IDirect3DSurface9_Release(ds
);
16597 hr
= IDirect3DDevice9_CreateDepthStencilSurface(device
, 640, 480, D3DFMT_D24S8
,
16598 D3DMULTISAMPLE_2_SAMPLES
, 0, TRUE
, &ds
, NULL
);
16599 ok(SUCCEEDED(hr
), "Failed to create depth/stencil, hr %#x.\n", hr
);
16600 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, ds
);
16601 ok(SUCCEEDED(hr
), "Failed to set depth/stencil, hr %#x.\n", hr
);
16603 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff00ff00, 1.0f
, 0);
16604 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
16606 hr
= IDirect3DDevice9_BeginScene(device
);
16607 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
16608 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad_1
, sizeof(*quad_1
));
16609 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
16610 hr
= IDirect3DDevice9_EndScene(device
);
16611 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
16613 hr
= IDirect3DDevice9_StretchRect(device
, rt
, NULL
, original_rt
, NULL
, D3DTEXF_POINT
);
16614 ok(SUCCEEDED(hr
), "StretchRect failed, hr %#x.\n", hr
);
16615 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, original_rt
);
16616 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
16618 hr
= IDirect3DDevice9_BeginScene(device
);
16619 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
16620 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad_2
, sizeof(*quad_2
));
16621 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
16622 hr
= IDirect3DDevice9_EndScene(device
);
16623 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
16625 hr
= IDirect3DDevice9_StretchRect(device
, original_rt
, NULL
, readback
, NULL
, D3DTEXF_POINT
);
16626 ok(SUCCEEDED(hr
), "StretchRect failed, hr %#x.\n", hr
);
16628 for (i
= 0; i
< ARRAY_SIZE(expected_colors
); ++i
)
16630 D3DCOLOR color
= getPixelColorFromSurface(readback
, expected_colors
[i
].x
, expected_colors
[i
].y
);
16631 ok(color_match(color
, expected_colors
[i
].color
, 1),
16632 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
16633 expected_colors
[i
].color
, expected_colors
[i
].x
, expected_colors
[i
].y
, color
);
16636 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
16637 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
16639 IDirect3DSurface9_Release(ds
);
16640 IDirect3DSurface9_Release(readback
);
16641 IDirect3DSurface9_Release(rt
);
16642 IDirect3DSurface9_Release(original_rt
);
16643 cleanup_device(device
);
16645 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
16646 present_parameters
.Windowed
= TRUE
;
16647 present_parameters
.hDeviceWindow
= create_window();
16648 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
16649 present_parameters
.BackBufferWidth
= 640;
16650 present_parameters
.BackBufferHeight
= 480;
16651 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
16652 present_parameters
.EnableAutoDepthStencil
= TRUE
;
16653 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
16654 present_parameters
.MultiSampleType
= D3DMULTISAMPLE_NONE
;
16656 hr
= IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
16657 present_parameters
.hDeviceWindow
, D3DCREATE_HARDWARE_VERTEXPROCESSING
,
16658 &present_parameters
, &device
);
16659 ok(hr
== D3D_OK
, "Failed to create a device, hr %#x.\n", hr
);
16661 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff00ffff, 1.0f
, 0);
16662 ok(SUCCEEDED(hr
), "Failed to clear depth buffer, hr %#x.\n", hr
);
16664 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 640, 480, D3DFMT_A8R8G8B8
,
16665 D3DMULTISAMPLE_2_SAMPLES
, 0, FALSE
, &rt
, NULL
);
16666 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
16667 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 640, 480, D3DFMT_A8R8G8B8
,
16668 D3DMULTISAMPLE_NONE
, 0, TRUE
, &readback
, NULL
);
16669 ok(SUCCEEDED(hr
), "Failed to create readback surface, hr %#x.\n", hr
);
16670 hr
= IDirect3DDevice9_CreateDepthStencilSurface(device
, 640, 480, D3DFMT_D24S8
,
16671 D3DMULTISAMPLE_2_SAMPLES
, 0, FALSE
, &ds
, NULL
);
16672 ok(SUCCEEDED(hr
), "CreateDepthStencilSurface failed, hr %#x.\n", hr
);
16674 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &original_rt
);
16675 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
16676 hr
= IDirect3DDevice9_GetDepthStencilSurface(device
, &original_ds
);
16677 ok(SUCCEEDED(hr
), "Failed to get depth/stencil, hr %#x.\n", hr
);
16678 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt
);
16679 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
16680 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, ds
);
16681 ok(SUCCEEDED(hr
), "Failed to set depth/stencil, hr %#x.\n", hr
);
16683 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
16684 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
16685 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_TRUE
);
16686 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
16687 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, TRUE
);
16688 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
16689 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_LESSEQUAL
);
16690 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
16691 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
16692 ok(SUCCEEDED(hr
), "SetFVF failed, hr %#x.\n", hr
);
16694 /* Render to a multisampled offscreen frame buffer and then blit to
16695 * the onscreen (not multisampled) frame buffer. */
16696 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff00ff00, 1.0f
, 0);
16697 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
16699 hr
= IDirect3DDevice9_BeginScene(device
);
16700 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
16701 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad_1
, sizeof(*quad_1
));
16702 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
16703 hr
= IDirect3DDevice9_EndScene(device
);
16704 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
16706 hr
= IDirect3DDevice9_StretchRect(device
, rt
, NULL
, original_rt
, NULL
, D3DTEXF_POINT
);
16707 ok(SUCCEEDED(hr
), "StretchRect failed, hr %#x.\n", hr
);
16708 hr
= IDirect3DDevice9_StretchRect(device
, ds
, NULL
, original_ds
, NULL
, D3DTEXF_POINT
);
16709 ok(SUCCEEDED(hr
), "StretchRect failed, hr %#x.\n", hr
);
16711 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, original_rt
);
16712 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
16713 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, original_ds
);
16714 ok(SUCCEEDED(hr
), "Failed to set depth/stencil, hr %#x.\n", hr
);
16716 hr
= IDirect3DDevice9_BeginScene(device
);
16717 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
16718 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad_2
, sizeof(*quad_2
));
16719 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
16720 hr
= IDirect3DDevice9_EndScene(device
);
16721 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
16723 hr
= IDirect3DDevice9_StretchRect(device
, original_rt
, NULL
, readback
, NULL
, D3DTEXF_POINT
);
16724 ok(SUCCEEDED(hr
), "StretchRect failed, hr %#x.\n", hr
);
16726 for (i
= 0; i
< ARRAY_SIZE(expected_colors
); ++i
)
16728 D3DCOLOR color
= getPixelColorFromSurface(readback
, expected_colors
[i
].x
, expected_colors
[i
].y
);
16729 ok(color_match(color
, expected_colors
[i
].color
, 1),
16730 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
16731 expected_colors
[i
].color
, expected_colors
[i
].x
, expected_colors
[i
].y
, color
);
16734 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
16735 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
16737 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, NULL
);
16738 ok(SUCCEEDED(hr
), "Failed to set depth/stencil, hr %#x.\n", hr
);
16739 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, original_rt
);
16740 ok(SUCCEEDED(hr
), "Failed to restore original render target, hr %#x.\n", hr
);
16742 IDirect3DSurface9_Release(original_ds
);
16743 IDirect3DSurface9_Release(original_rt
);
16744 IDirect3DSurface9_Release(ds
);
16745 IDirect3DSurface9_Release(readback
);
16746 IDirect3DSurface9_Release(rt
);
16748 cleanup_device(device
);
16749 IDirect3D9_Release(d3d
);
16752 static void resz_test(void)
16754 IDirect3DDevice9
*device
= 0;
16755 IDirect3DSurface9
*rt
, *original_rt
, *ds
, *readback
, *intz_ds
;
16758 D3DPRESENT_PARAMETERS present_parameters
;
16760 static const DWORD ps_code
[] =
16762 0xffff0200, /* ps_2_0 */
16763 0x0200001f, 0x90000000, 0xa00f0800, /* dcl_2d s0 */
16764 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
16765 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0.0, 0.0, 0.0, 1.0 */
16766 0x02000001, 0x800f0001, 0xa0e40000, /* mov r1, c0 */
16767 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texld r0, t0, s0 */
16768 0x02000001, 0x80010001, 0x80e40000, /* mov r1.x, r0 */
16769 0x03010042, 0x800f0000, 0xb0e40000, 0xa0e40800, /* texldp r0, t0, s0 */
16770 0x02000001, 0x80020001, 0x80000000, /* mov r1.y, r0.x */
16771 0x02000001, 0x800f0800, 0x80e40001, /* mov oC0, r1 */
16772 0x0000ffff, /* end */
16774 static const struct
16781 { -1.0f
, 1.0f
, 0.0f
, 0.0f
, 1.0f
, 1.0f
, 0.5f
},
16782 { 1.0f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 0.5f
},
16783 { -1.0f
, -1.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.5f
},
16784 { 1.0f
, -1.0f
, 1.0f
, 1.0f
, 0.0f
, 0.0f
, 0.5f
},
16786 static const struct
16791 expected_colors
[] =
16793 { 80, 100, D3DCOLOR_ARGB(0x00, 0x20, 0x40, 0x00)},
16794 {240, 100, D3DCOLOR_ARGB(0x00, 0x60, 0xbf, 0x00)},
16795 {400, 100, D3DCOLOR_ARGB(0x00, 0x9f, 0x40, 0x00)},
16796 {560, 100, D3DCOLOR_ARGB(0x00, 0xdf, 0xbf, 0x00)},
16797 { 80, 450, D3DCOLOR_ARGB(0x00, 0x20, 0x40, 0x00)},
16798 {240, 450, D3DCOLOR_ARGB(0x00, 0x60, 0xbf, 0x00)},
16799 {400, 450, D3DCOLOR_ARGB(0x00, 0x9f, 0x40, 0x00)},
16800 {560, 450, D3DCOLOR_ARGB(0x00, 0xdf, 0xbf, 0x00)},
16802 IDirect3DTexture9
*texture
;
16803 IDirect3DPixelShader9
*ps
;
16807 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
16808 ok(!!d3d
, "Failed to create a D3D object.\n");
16810 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
,
16811 D3DDEVTYPE_HAL
, D3DFMT_A8R8G8B8
, TRUE
, D3DMULTISAMPLE_2_SAMPLES
, NULL
)))
16813 skip("Multisampling not supported for D3DFMT_A8R8G8B8, skipping RESZ test.\n");
16814 IDirect3D9_Release(d3d
);
16817 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
,
16818 D3DDEVTYPE_HAL
, D3DFMT_D24S8
, TRUE
, D3DMULTISAMPLE_2_SAMPLES
, NULL
)))
16820 skip("Multisampling not supported for D3DFMT_D24S8, skipping RESZ test.\n");
16821 IDirect3D9_Release(d3d
);
16825 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
16826 D3DUSAGE_DEPTHSTENCIL
, D3DRTYPE_TEXTURE
, MAKEFOURCC('I','N','T','Z'))))
16828 skip("No INTZ support, skipping RESZ test.\n");
16829 IDirect3D9_Release(d3d
);
16833 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
16834 D3DUSAGE_RENDERTARGET
, D3DRTYPE_SURFACE
, MAKEFOURCC('R','E','S','Z'))))
16836 skip("No RESZ support, skipping RESZ test.\n");
16837 IDirect3D9_Release(d3d
);
16841 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
16842 present_parameters
.Windowed
= TRUE
;
16843 present_parameters
.hDeviceWindow
= create_window();
16844 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
16845 present_parameters
.BackBufferWidth
= 640;
16846 present_parameters
.BackBufferHeight
= 480;
16847 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
16848 present_parameters
.EnableAutoDepthStencil
= FALSE
;
16849 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
16850 present_parameters
.MultiSampleType
= D3DMULTISAMPLE_NONE
;
16852 hr
= IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
16853 present_parameters
.hDeviceWindow
, D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
16854 ok(hr
== D3D_OK
, "Failed to create a device, hr %#x.\n", hr
);
16856 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
16857 ok(SUCCEEDED(hr
), "GetDeviceCaps failed, hr %#x.\n", hr
);
16858 if (caps
.PixelShaderVersion
< D3DPS_VERSION(2, 0))
16860 skip("No pixel shader 2.0 support, skipping INTZ test.\n");
16861 cleanup_device(device
);
16862 IDirect3D9_Release(d3d
);
16865 if (caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
)
16867 skip("No unconditional NP2 texture support, skipping INTZ test.\n");
16868 cleanup_device(device
);
16869 IDirect3D9_Release(d3d
);
16873 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &original_rt
);
16874 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
16876 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 640, 480, D3DFMT_A8R8G8B8
,
16877 D3DMULTISAMPLE_2_SAMPLES
, 0, FALSE
, &rt
, NULL
);
16878 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
16879 hr
= IDirect3DDevice9_CreateDepthStencilSurface(device
, 640, 480, D3DFMT_D24S8
,
16880 D3DMULTISAMPLE_2_SAMPLES
, 0, TRUE
, &ds
, NULL
);
16881 ok(SUCCEEDED(hr
), "Failed to create depth/stencil, hr %#x.\n", hr
);
16882 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 640, 480, D3DFMT_A8R8G8B8
,
16883 D3DMULTISAMPLE_NONE
, 0, TRUE
, &readback
, NULL
);
16884 ok(SUCCEEDED(hr
), "Failed to create readback surface, hr %#x.\n", hr
);
16886 hr
= IDirect3DDevice9_CreateTexture(device
, 640, 480, 1,
16887 D3DUSAGE_DEPTHSTENCIL
, MAKEFOURCC('I','N','T','Z'), D3DPOOL_DEFAULT
, &texture
, NULL
);
16888 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
16889 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &intz_ds
);
16890 ok(SUCCEEDED(hr
), "GetSurfaceLevel failed, hr %#x.\n", hr
);
16891 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, intz_ds
);
16892 ok(SUCCEEDED(hr
), "Failed to set depth/stencil, hr %#x.\n", hr
);
16893 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0, 1.0f
, 0);
16894 ok(SUCCEEDED(hr
), "Failed to clear depth/stencil, hr %#x.\n", hr
);
16895 IDirect3DSurface9_Release(intz_ds
);
16896 hr
= IDirect3DDevice9_CreatePixelShader(device
, ps_code
, &ps
);
16897 ok(SUCCEEDED(hr
), "CreatePixelShader failed, hr %#x.\n", hr
);
16899 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
| D3DFVF_TEXCOORDSIZE4(0));
16900 ok(SUCCEEDED(hr
), "SetFVF failed, hr %#x.\n", hr
);
16901 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_TRUE
);
16902 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
16903 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_ALWAYS
);
16904 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
16905 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, TRUE
);
16906 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
16907 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
16908 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
16910 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSU
, D3DTADDRESS_WRAP
);
16911 ok(SUCCEEDED(hr
), "SetSamplerState failed, hr %#x.\n", hr
);
16912 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSV
, D3DTADDRESS_WRAP
);
16913 ok(SUCCEEDED(hr
), "SetSamplerState failed, hr %#x.\n", hr
);
16914 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAGFILTER
, D3DTEXF_POINT
);
16915 ok(SUCCEEDED(hr
), "SetSamplerState failed, hr %#x.\n", hr
);
16916 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MINFILTER
, D3DTEXF_POINT
);
16917 ok(SUCCEEDED(hr
), "SetSamplerState failed, hr %#x.\n", hr
);
16918 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MIPFILTER
, D3DTEXF_POINT
);
16919 ok(SUCCEEDED(hr
), "SetSamplerState failed, hr %#x.\n", hr
);
16921 /* Render offscreen (multisampled), blit the depth buffer
16922 * into the INTZ texture and then check its contents */
16923 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt
);
16924 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
16925 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, ds
);
16926 ok(SUCCEEDED(hr
), "Failed to set depth/stencil, hr %#x.\n", hr
);
16927 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff00ff00, 1.0f
, 0);
16928 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
16930 hr
= IDirect3DDevice9_BeginScene(device
);
16931 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
16932 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
16933 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
16935 /* The destination depth texture has to be bound to sampler 0 */
16936 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)texture
);
16937 ok(SUCCEEDED(hr
), "SetTexture failed, hr %#x.\n", hr
);
16939 /* the ATI "spec" says you have to do a dummy draw to ensure correct commands ordering */
16940 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
16941 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
16942 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, FALSE
);
16943 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
16944 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_COLORWRITEENABLE
, 0);
16945 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
16946 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
16947 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
16948 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, TRUE
);
16949 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
16950 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, TRUE
);
16951 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
16952 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_COLORWRITEENABLE
, 0xf);
16953 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
16955 /* The actual multisampled depth buffer resolve happens here */
16956 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSIZE
, 0x7fa05000);
16957 ok(SUCCEEDED(hr
), "SetRenderState (multisampled depth buffer resolve) failed, hr %#x.\n", hr
);
16958 hr
= IDirect3DDevice9_GetRenderState(device
, D3DRS_POINTSIZE
, &value
);
16959 ok(SUCCEEDED(hr
) && value
== 0x7fa05000, "GetRenderState failed, hr %#x, value %#x.\n", hr
, value
);
16961 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, original_rt
);
16962 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
16963 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, NULL
);
16964 ok(SUCCEEDED(hr
), "Failed to set depth/stencil, hr %#x.\n", hr
);
16965 hr
= IDirect3DDevice9_SetPixelShader(device
, ps
);
16966 ok(SUCCEEDED(hr
), "SetPixelShader failed, hr %#x.\n", hr
);
16968 /* Read the depth values back */
16969 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
16970 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
16971 hr
= IDirect3DDevice9_EndScene(device
);
16972 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
16974 for (i
= 0; i
< ARRAY_SIZE(expected_colors
); ++i
)
16976 D3DCOLOR color
= getPixelColor(device
, expected_colors
[i
].x
, expected_colors
[i
].y
);
16977 ok(color_match(color
, expected_colors
[i
].color
, 1),
16978 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
16979 expected_colors
[i
].color
, expected_colors
[i
].x
, expected_colors
[i
].y
, color
);
16982 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
16983 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
16985 IDirect3DSurface9_Release(ds
);
16986 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
16987 ok(SUCCEEDED(hr
), "SetTexture failed, hr %#x.\n", hr
);
16988 IDirect3DTexture9_Release(texture
);
16989 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
16990 ok(SUCCEEDED(hr
), "SetPixelShader failed, hr %#x.\n", hr
);
16991 IDirect3DPixelShader9_Release(ps
);
16992 IDirect3DSurface9_Release(readback
);
16993 IDirect3DSurface9_Release(original_rt
);
16994 IDirect3DSurface9_Release(rt
);
16995 cleanup_device(device
);
16997 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
16998 present_parameters
.Windowed
= TRUE
;
16999 present_parameters
.hDeviceWindow
= create_window();
17000 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
17001 present_parameters
.BackBufferWidth
= 640;
17002 present_parameters
.BackBufferHeight
= 480;
17003 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
17004 present_parameters
.EnableAutoDepthStencil
= TRUE
;
17005 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
17006 present_parameters
.MultiSampleType
= D3DMULTISAMPLE_2_SAMPLES
;
17008 hr
= IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
17009 present_parameters
.hDeviceWindow
, D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
17010 ok(hr
== D3D_OK
, "Failed to create a device, hr %#x.\n", hr
);
17012 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &original_rt
);
17013 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
17014 hr
= IDirect3DDevice9_GetDepthStencilSurface(device
, &ds
);
17015 ok(SUCCEEDED(hr
), "Failed to get depth/stencil, hr %#x.\n", hr
);
17016 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 640, 480, D3DFMT_A8R8G8B8
,
17017 D3DMULTISAMPLE_NONE
, 0, TRUE
, &readback
, NULL
);
17018 ok(SUCCEEDED(hr
), "Failed to create readback surface, hr %#x.\n", hr
);
17019 hr
= IDirect3DDevice9_CreateTexture(device
, 640, 480, 1,
17020 D3DUSAGE_DEPTHSTENCIL
, MAKEFOURCC('I','N','T','Z'), D3DPOOL_DEFAULT
, &texture
, NULL
);
17021 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
17022 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &intz_ds
);
17023 ok(SUCCEEDED(hr
), "GetSurfaceLevel failed, hr %#x.\n", hr
);
17024 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, readback
);
17025 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
17026 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, intz_ds
);
17027 ok(SUCCEEDED(hr
), "Failed to set depth/stencil, hr %#x.\n", hr
);
17028 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0, 1.0f
, 0);
17029 ok(SUCCEEDED(hr
), "Failed to clear depth/stencil, hr %#x.\n", hr
);
17030 IDirect3DSurface9_Release(intz_ds
);
17031 hr
= IDirect3DDevice9_CreatePixelShader(device
, ps_code
, &ps
);
17032 ok(SUCCEEDED(hr
), "CreatePixelShader failed, hr %#x.\n", hr
);
17034 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
| D3DFVF_TEXCOORDSIZE4(0));
17035 ok(SUCCEEDED(hr
), "SetFVF failed, hr %#x.\n", hr
);
17036 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_TRUE
);
17037 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
17038 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_ALWAYS
);
17039 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
17040 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, TRUE
);
17041 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
17042 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
17043 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
17045 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSU
, D3DTADDRESS_WRAP
);
17046 ok(SUCCEEDED(hr
), "SetSamplerState failed, hr %#x.\n", hr
);
17047 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSV
, D3DTADDRESS_WRAP
);
17048 ok(SUCCEEDED(hr
), "SetSamplerState failed, hr %#x.\n", hr
);
17049 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAGFILTER
, D3DTEXF_POINT
);
17050 ok(SUCCEEDED(hr
), "SetSamplerState failed, hr %#x.\n", hr
);
17051 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MINFILTER
, D3DTEXF_POINT
);
17052 ok(SUCCEEDED(hr
), "SetSamplerState failed, hr %#x.\n", hr
);
17053 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MIPFILTER
, D3DTEXF_POINT
);
17054 ok(SUCCEEDED(hr
), "SetSamplerState failed, hr %#x.\n", hr
);
17056 /* Render onscreen, blit the depth buffer into the INTZ texture
17057 * and then check its contents */
17058 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, original_rt
);
17059 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
17060 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, ds
);
17061 ok(SUCCEEDED(hr
), "Failed to set depth/stencil, hr %#x.\n", hr
);
17062 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff00ff00, 1.0f
, 0);
17063 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
17065 hr
= IDirect3DDevice9_BeginScene(device
);
17066 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
17067 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
17068 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
17069 hr
= IDirect3DDevice9_EndScene(device
);
17070 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
17072 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)texture
);
17073 ok(SUCCEEDED(hr
), "SetTexture failed, hr %#x.\n", hr
);
17075 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
17076 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
17077 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, FALSE
);
17078 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
17079 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_COLORWRITEENABLE
, 0);
17080 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
17081 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
17082 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
17083 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, TRUE
);
17084 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
17085 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, TRUE
);
17086 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
17087 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_COLORWRITEENABLE
, 0xf);
17088 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
17090 /* The actual multisampled depth buffer resolve happens here */
17091 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSIZE
, 0x7fa05000);
17092 ok(SUCCEEDED(hr
), "SetRenderState (multisampled depth buffer resolve) failed, hr %#x.\n", hr
);
17093 hr
= IDirect3DDevice9_GetRenderState(device
, D3DRS_POINTSIZE
, &value
);
17094 ok(SUCCEEDED(hr
) && value
== 0x7fa05000, "GetRenderState failed, hr %#x, value %#x.\n", hr
, value
);
17096 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, readback
);
17097 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
17098 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, NULL
);
17099 ok(SUCCEEDED(hr
), "Failed to set depth/stencil, hr %#x.\n", hr
);
17100 hr
= IDirect3DDevice9_SetPixelShader(device
, ps
);
17101 ok(SUCCEEDED(hr
), "SetPixelShader failed, hr %#x.\n", hr
);
17103 /* Read the depth values back */
17104 hr
= IDirect3DDevice9_BeginScene(device
);
17105 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
17106 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
17107 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
17108 hr
= IDirect3DDevice9_EndScene(device
);
17109 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
17111 for (i
= 0; i
< ARRAY_SIZE(expected_colors
); ++i
)
17113 D3DCOLOR color
= getPixelColor(device
, expected_colors
[i
].x
, expected_colors
[i
].y
);
17114 ok(color_match(color
, expected_colors
[i
].color
, 1),
17115 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
17116 expected_colors
[i
].color
, expected_colors
[i
].x
, expected_colors
[i
].y
, color
);
17119 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
17120 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
17123 /* Test edge cases - try with no texture at all */
17124 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
17125 ok(SUCCEEDED(hr
), "SetPixelShader failed, hr %#x.\n", hr
);
17126 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
17127 ok(SUCCEEDED(hr
), "SetTexture failed, hr %#x.\n", hr
);
17128 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, ds
);
17129 ok(SUCCEEDED(hr
), "Failed to set depth/stencil, hr %#x.\n", hr
);
17130 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, original_rt
);
17131 ok(SUCCEEDED(hr
), "Failed to set depth/stencil, hr %#x.\n", hr
);
17133 hr
= IDirect3DDevice9_BeginScene(device
);
17134 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
17135 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
17136 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
17137 hr
= IDirect3DDevice9_EndScene(device
);
17138 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
17140 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSIZE
, 0x7fa05000);
17141 ok(SUCCEEDED(hr
), "SetRenderState (multisampled depth buffer resolve) failed, hr %#x.\n", hr
);
17143 /* With a non-multisampled depth buffer */
17144 IDirect3DSurface9_Release(ds
);
17145 hr
= IDirect3DDevice9_CreateDepthStencilSurface(device
, 640, 480, D3DFMT_D24S8
,
17146 D3DMULTISAMPLE_NONE
, 0, TRUE
, &ds
, NULL
);
17147 ok(SUCCEEDED(hr
), "Failed to create depth stencil surface, hr %#x.\n", hr
);
17149 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, readback
);
17150 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
17151 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, ds
);
17152 ok(SUCCEEDED(hr
), "Failed to set depth/stencil, hr %#x.\n", hr
);
17153 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
17154 ok(SUCCEEDED(hr
), "SetTexture failed, hr %#x.\n", hr
);
17156 hr
= IDirect3DDevice9_BeginScene(device
);
17157 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
17158 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
17159 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
17161 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)texture
);
17162 ok(SUCCEEDED(hr
), "SetTexture failed, hr %#x.\n", hr
);
17164 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
17165 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
17166 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, FALSE
);
17167 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
17168 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_COLORWRITEENABLE
, 0);
17169 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
17170 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
17171 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
17172 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, TRUE
);
17173 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
17174 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, TRUE
);
17175 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
17176 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_COLORWRITEENABLE
, 0xf);
17177 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
17178 hr
= IDirect3DDevice9_EndScene(device
);
17179 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
17181 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSIZE
, 0x7fa05000);
17182 ok(SUCCEEDED(hr
), "SetRenderState (multisampled depth buffer resolve) failed, hr %#x.\n", hr
);
17184 hr
= IDirect3DDevice9_SetPixelShader(device
, ps
);
17185 ok(SUCCEEDED(hr
), "SetPixelShader failed, hr %#x.\n", hr
);
17187 /* Read the depth values back. */
17188 hr
= IDirect3DDevice9_BeginScene(device
);
17189 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
17190 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
17191 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
17192 hr
= IDirect3DDevice9_EndScene(device
);
17193 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
17195 for (i
= 0; i
< ARRAY_SIZE(expected_colors
); ++i
)
17197 D3DCOLOR color
= getPixelColor(device
, expected_colors
[i
].x
, expected_colors
[i
].y
);
17198 ok(color_match(color
, expected_colors
[i
].color
, 1),
17199 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
17200 expected_colors
[i
].color
, expected_colors
[i
].x
, expected_colors
[i
].y
, color
);
17203 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
17204 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
17206 /* Without a current depth-stencil buffer set */
17207 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
17208 ok(SUCCEEDED(hr
), "SetPixelShader failed, hr %#x.\n", hr
);
17209 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, NULL
);
17210 ok(SUCCEEDED(hr
), "Failed to set depth/stencil, hr %#x.\n", hr
);
17212 hr
= IDirect3DDevice9_BeginScene(device
);
17213 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
17214 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
17215 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
17216 hr
= IDirect3DDevice9_EndScene(device
);
17217 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
17219 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_POINTSIZE
, 0x7fa05000);
17220 ok(SUCCEEDED(hr
), "SetRenderState (multisampled depth buffer resolve) failed, hr %#x.\n", hr
);
17222 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, NULL
);
17223 ok(SUCCEEDED(hr
), "Failed to set depth/stencil, hr %#x.\n", hr
);
17224 IDirect3DSurface9_Release(ds
);
17225 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, original_rt
);
17226 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
17227 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
17228 ok(SUCCEEDED(hr
), "SetTexture failed, hr %#x.\n", hr
);
17229 IDirect3DTexture9_Release(texture
);
17230 IDirect3DPixelShader9_Release(ps
);
17231 IDirect3DSurface9_Release(readback
);
17232 IDirect3DSurface9_Release(original_rt
);
17233 cleanup_device(device
);
17234 IDirect3D9_Release(d3d
);
17237 static void zenable_test(void)
17239 static const struct
17241 struct vec4 position
;
17246 {{ 0.0f
, 480.0f
, -0.5f
, 1.0f
}, 0xff00ff00},
17247 {{ 0.0f
, 0.0f
, -0.5f
, 1.0f
}, 0xff00ff00},
17248 {{640.0f
, 480.0f
, 1.5f
, 1.0f
}, 0xff00ff00},
17249 {{640.0f
, 0.0f
, 1.5f
, 1.0f
}, 0xff00ff00},
17251 IDirect3DDevice9
*device
;
17261 IDirect3DSurface9
*ds
;
17263 window
= create_window();
17264 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
17265 ok(!!d3d
, "Failed to create a D3D object.\n");
17266 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
17268 skip("Failed to create a D3D device, skipping tests.\n");
17272 hr
= IDirect3DDevice9_GetDepthStencilSurface(device
, &ds
);
17273 ok(SUCCEEDED(hr
), "Failed to get depth stencil surface, hr %#x.\n", hr
);
17275 for (test
= 0; test
< 2; ++test
)
17277 /* The Windows 8 testbot (WARP) appears to clip with
17278 * ZENABLE = D3DZB_TRUE and no depth buffer set. */
17279 static const D3DCOLOR expected_broken
[] =
17281 0x00ff0000, 0x0000ff00, 0x0000ff00, 0x00ff0000,
17282 0x00ff0000, 0x0000ff00, 0x0000ff00, 0x00ff0000,
17283 0x00ff0000, 0x0000ff00, 0x0000ff00, 0x00ff0000,
17284 0x00ff0000, 0x0000ff00, 0x0000ff00, 0x00ff0000,
17289 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, NULL
);
17290 ok(SUCCEEDED(hr
), "Failed to set depth stencil surface, hr %#x.\n", hr
);
17294 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_FALSE
);
17295 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
17296 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, ds
);
17297 ok(SUCCEEDED(hr
), "Failed to set depth stencil surface, hr %#x.\n", hr
);
17298 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0x00000000, 0.0f
, 0);
17299 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
17301 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
);
17302 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
17304 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0f
, 0);
17305 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
17306 hr
= IDirect3DDevice9_BeginScene(device
);
17307 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
17308 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, tquad
, sizeof(*tquad
));
17309 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
17310 hr
= IDirect3DDevice9_EndScene(device
);
17311 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
17313 for (i
= 0; i
< 4; ++i
)
17315 for (j
= 0; j
< 4; ++j
)
17317 x
= 80 * ((2 * j
) + 1);
17318 y
= 60 * ((2 * i
) + 1);
17319 color
= getPixelColor(device
, x
, y
);
17320 ok(color_match(color
, 0x0000ff00, 1)
17321 || broken(color_match(color
, expected_broken
[i
* 4 + j
], 1) && !test
),
17322 "Expected color 0x0000ff00 at %u, %u, got 0x%08x, test %u.\n",
17323 x
, y
, color
, test
);
17327 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
17328 ok(SUCCEEDED(hr
), "Failed to present backbuffer, hr %#x.\n", hr
);
17331 IDirect3DSurface9_Release(ds
);
17333 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
17334 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
17336 if (caps
.PixelShaderVersion
>= D3DPS_VERSION(1, 1)
17337 && caps
.VertexShaderVersion
>= D3DVS_VERSION(1, 1))
17339 static const DWORD vs_code
[] =
17341 0xfffe0101, /* vs_1_1 */
17342 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
17343 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
17344 0x00000001, 0xd00f0000, 0x90e40000, /* mov oD0, v0 */
17347 static const DWORD ps_code
[] =
17349 0xffff0101, /* ps_1_1 */
17350 0x00000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
17351 0x0000ffff /* end */
17353 static const struct vec3 quad
[] =
17355 {-1.0f
, -1.0f
, -0.5f
},
17356 {-1.0f
, 1.0f
, -0.5f
},
17357 { 1.0f
, -1.0f
, 1.5f
},
17358 { 1.0f
, 1.0f
, 1.5f
},
17360 static const D3DCOLOR expected
[] =
17362 0x00ff0000, 0x0060df60, 0x009fdf9f, 0x00ff0000,
17363 0x00ff0000, 0x00609f60, 0x009f9f9f, 0x00ff0000,
17364 0x00ff0000, 0x00606060, 0x009f609f, 0x00ff0000,
17365 0x00ff0000, 0x00602060, 0x009f209f, 0x00ff0000,
17367 /* The Windows 8 testbot (WARP) appears to not clip z for regular
17368 * vertices either. */
17369 static const D3DCOLOR expected_broken
[] =
17371 0x0020df20, 0x0060df60, 0x009fdf9f, 0x00dfdfdf,
17372 0x00209f20, 0x00609f60, 0x009f9f9f, 0x00df9fdf,
17373 0x00206020, 0x00606060, 0x009f609f, 0x00df60df,
17374 0x00202020, 0x00602060, 0x009f209f, 0x00df20df,
17377 IDirect3DVertexShader9
*vs
;
17378 IDirect3DPixelShader9
*ps
;
17380 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
17381 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
17382 hr
= IDirect3DDevice9_CreateVertexShader(device
, vs_code
, &vs
);
17383 ok(SUCCEEDED(hr
), "Failed to create vertex shader, hr %#x.\n", hr
);
17384 hr
= IDirect3DDevice9_CreatePixelShader(device
, ps_code
, &ps
);
17385 ok(SUCCEEDED(hr
), "Failed to create pixel shader, hr %#x.\n", hr
);
17386 hr
= IDirect3DDevice9_SetVertexShader(device
, vs
);
17387 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
17388 hr
= IDirect3DDevice9_SetPixelShader(device
, ps
);
17389 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
17391 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffff0000, 0.0f
, 0);
17392 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
17393 hr
= IDirect3DDevice9_BeginScene(device
);
17394 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
17395 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
17396 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
17397 hr
= IDirect3DDevice9_EndScene(device
);
17398 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
17400 for (i
= 0; i
< 4; ++i
)
17402 for (j
= 0; j
< 4; ++j
)
17404 x
= 80 * ((2 * j
) + 1);
17405 y
= 60 * ((2 * i
) + 1);
17406 color
= getPixelColor(device
, x
, y
);
17407 ok(color_match(color
, expected
[i
* 4 + j
], 1)
17408 || broken(color_match(color
, expected_broken
[i
* 4 + j
], 1)),
17409 "Expected color 0x%08x at %u, %u, got 0x%08x.\n", expected
[i
* 4 + j
], x
, y
, color
);
17413 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
17414 ok(SUCCEEDED(hr
), "Failed to present backbuffer, hr %#x.\n", hr
);
17416 IDirect3DPixelShader9_Release(ps
);
17417 IDirect3DVertexShader9_Release(vs
);
17420 refcount
= IDirect3DDevice9_Release(device
);
17421 ok(!refcount
, "Device has %u references left.\n", refcount
);
17423 IDirect3D9_Release(d3d
);
17424 DestroyWindow(window
);
17427 static void fog_special_test(void)
17429 static const struct
17431 struct vec3 position
;
17436 {{ -1.0f
, -1.0f
, 0.0f
}, 0xff00ff00},
17437 {{ -1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
17438 {{ 1.0f
, -1.0f
, 1.0f
}, 0xff00ff00},
17439 {{ 1.0f
, 1.0f
, 1.0f
}, 0xff00ff00}
17441 static const struct
17443 DWORD vertexmode
, tablemode
;
17445 D3DCOLOR color_left
, color_right
;
17449 {D3DFOG_LINEAR
, D3DFOG_NONE
, FALSE
, FALSE
, 0x00ff0000, 0x00ff0000},
17450 {D3DFOG_LINEAR
, D3DFOG_NONE
, FALSE
, TRUE
, 0x00ff0000, 0x00ff0000},
17451 {D3DFOG_LINEAR
, D3DFOG_NONE
, TRUE
, FALSE
, 0x00ff0000, 0x00ff0000},
17452 {D3DFOG_LINEAR
, D3DFOG_NONE
, TRUE
, TRUE
, 0x00ff0000, 0x00ff0000},
17454 {D3DFOG_NONE
, D3DFOG_LINEAR
, FALSE
, FALSE
, 0x0000ff00, 0x00ff0000},
17455 {D3DFOG_NONE
, D3DFOG_LINEAR
, FALSE
, TRUE
, 0x0000ff00, 0x00ff0000},
17456 {D3DFOG_NONE
, D3DFOG_LINEAR
, TRUE
, FALSE
, 0x0000ff00, 0x00ff0000},
17457 {D3DFOG_NONE
, D3DFOG_LINEAR
, TRUE
, TRUE
, 0x0000ff00, 0x00ff0000},
17459 static const DWORD pixel_shader_code
[] =
17461 0xffff0101, /* ps_1_1 */
17462 0x00000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
17465 static const DWORD vertex_shader_code
[] =
17467 0xfffe0101, /* vs_1_1 */
17468 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
17469 0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
17470 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
17471 0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
17474 static const D3DMATRIX identity
=
17476 1.0f
, 0.0f
, 0.0f
, 0.0f
,
17477 0.0f
, 1.0f
, 0.0f
, 0.0f
,
17478 0.0f
, 0.0f
, 1.0f
, 0.0f
,
17479 0.0f
, 0.0f
, 0.0f
, 1.0f
,
17489 IDirect3DPixelShader9
*ps
;
17490 IDirect3DVertexShader9
*vs
;
17491 IDirect3DDevice9
*device
;
17497 window
= create_window();
17498 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
17499 ok(!!d3d
, "Failed to create a D3D object.\n");
17500 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
17502 skip("Failed to create a D3D device, skipping tests.\n");
17506 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
17507 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
17508 if (caps
.VertexShaderVersion
>= D3DVS_VERSION(1, 1))
17510 hr
= IDirect3DDevice9_CreateVertexShader(device
, vertex_shader_code
, &vs
);
17511 ok(SUCCEEDED(hr
), "Failed to create vertex shader, hr %#x.\n", hr
);
17515 skip("Vertex Shaders not supported, skipping some fog tests.\n");
17518 if (caps
.PixelShaderVersion
>= D3DPS_VERSION(1, 1))
17520 hr
= IDirect3DDevice9_CreatePixelShader(device
, pixel_shader_code
, &ps
);
17521 ok(SUCCEEDED(hr
), "Failed to create pixel shader, hr %#x.\n", hr
);
17525 skip("Pixel Shaders not supported, skipping some fog tests.\n");
17529 /* The table fog tests seem to depend on the projection matrix explicitly
17530 * being set to an identity matrix, even though that's the default.
17531 * (AMD Radeon HD 6310, Windows 7) */
17532 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_PROJECTION
, &identity
);
17533 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
17535 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
17536 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
17537 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
17538 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
17539 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGENABLE
, TRUE
);
17540 ok(SUCCEEDED(hr
), "Failed to enable fog, hr %#x.\n", hr
);
17541 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGCOLOR
, 0xffff0000);
17542 ok(SUCCEEDED(hr
), "Failed to set fog color, hr %#x.\n", hr
);
17545 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGSTART
, conv
.d
);
17546 ok(SUCCEEDED(hr
), "Failed to set fog start, hr %#x.\n", hr
);
17547 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGEND
, conv
.d
);
17548 ok(SUCCEEDED(hr
), "Failed to set fog end, hr %#x.\n", hr
);
17550 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
17552 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff0000ff, 1.0f
, 0);
17553 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
17557 hr
= IDirect3DDevice9_SetVertexShader(device
, NULL
);
17558 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
17562 hr
= IDirect3DDevice9_SetVertexShader(device
, vs
);
17563 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
17572 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
17573 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
17577 hr
= IDirect3DDevice9_SetPixelShader(device
, ps
);
17578 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
17585 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, tests
[i
].vertexmode
);
17586 ok(SUCCEEDED(hr
), "Failed to set fogvertexmode, hr %#x.\n", hr
);
17587 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGTABLEMODE
, tests
[i
].tablemode
);
17588 ok(SUCCEEDED(hr
), "Failed to set fogtablemode, hr %#x.\n", hr
);
17590 hr
= IDirect3DDevice9_BeginScene(device
);
17591 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
17592 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
17593 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
17594 hr
= IDirect3DDevice9_EndScene(device
);
17595 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
17597 color
= getPixelColor(device
, 310, 240);
17598 ok(color_match(color
, tests
[i
].color_left
, 1),
17599 "Expected left color 0x%08x, got 0x%08x, case %u.\n", tests
[i
].color_left
, color
, i
);
17600 color
= getPixelColor(device
, 330, 240);
17601 ok(color_match(color
, tests
[i
].color_right
, 1),
17602 "Expected right color 0x%08x, got 0x%08x, case %u.\n", tests
[i
].color_right
, color
, i
);
17604 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
17605 ok(SUCCEEDED(hr
), "Failed to present backbuffer, hr %#x.\n", hr
);
17609 IDirect3DVertexShader9_Release(vs
);
17611 IDirect3DPixelShader9_Release(ps
);
17612 refcount
= IDirect3DDevice9_Release(device
);
17613 ok(!refcount
, "Device has %u references left.\n", refcount
);
17615 IDirect3D9_Release(d3d
);
17616 DestroyWindow(window
);
17619 static void volume_srgb_test(void)
17623 IDirect3DVolumeTexture9
*tex1
, *tex2
;
17625 D3DLOCKED_BOX locked_box
;
17626 IDirect3DDevice9
*device
;
17632 static const struct
17639 /* Try toggling on and off */
17640 { FALSE
, 0x007f7f7f },
17641 { TRUE
, 0x00363636 },
17642 { FALSE
, 0x007f7f7f },
17644 static const struct
17647 struct vec3 texcrd
;
17651 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 0.0f
, 0.0f
}},
17652 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
, 0.0f
}},
17653 {{ 1.0f
, -1.0f
, 0.0f
}, {0.0f
, 0.0f
, 0.0f
}},
17654 {{ 1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
, 0.0f
}},
17657 window
= create_window();
17658 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
17659 ok(!!d3d
, "Failed to create a D3D object.\n");
17660 if (IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
17661 D3DUSAGE_QUERY_SRGBREAD
, D3DRTYPE_VOLUMETEXTURE
, D3DFMT_A8R8G8B8
) != D3D_OK
)
17663 skip("D3DFMT_A8R8G8B8 volume textures with SRGBREAD not supported.\n");
17666 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
17668 skip("Failed to create a D3D device, skipping tests.\n");
17672 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
17673 ok(SUCCEEDED(hr
), "Failed to set color op 0, hr %#x.\n", hr
);
17674 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
17675 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
17676 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
17677 ok(SUCCEEDED(hr
), "Failed to set color op 0, hr %#x.\n", hr
);
17678 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
| D3DFVF_TEXCOORDSIZE3(0));
17679 ok(SUCCEEDED(hr
), "Failed to set fvf, hr %#x.\n", hr
);
17681 for (i
= 0; i
< 2; i
++)
17684 pool
= D3DPOOL_SYSTEMMEM
;
17686 pool
= D3DPOOL_MANAGED
;
17688 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 1, 1, 1, 1, 0, D3DFMT_A8R8G8B8
, pool
, &tex1
, NULL
);
17689 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
17690 hr
= IDirect3DVolumeTexture9_LockBox(tex1
, 0, &locked_box
, NULL
, 0);
17691 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
17692 *((DWORD
*)locked_box
.pBits
) = 0x7f7f7f7f;
17693 hr
= IDirect3DVolumeTexture9_UnlockBox(tex1
, 0);
17694 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
17698 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 1, 1, 1, 1, 0,
17699 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex2
, NULL
);
17700 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
17701 hr
= IDirect3DDevice9_UpdateTexture(device
, (IDirect3DBaseTexture9
*)tex1
, (IDirect3DBaseTexture9
*)tex2
);
17702 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x.\n", hr
);
17703 IDirect3DVolumeTexture9_Release(tex1
);
17705 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)tex2
);
17706 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
17707 IDirect3DVolumeTexture9_Release(tex2
);
17711 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)tex1
);
17712 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
17713 IDirect3DVolumeTexture9_Release(tex1
);
17716 for (j
= 0; j
< ARRAY_SIZE(tests
); j
++)
17718 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_SRGBTEXTURE
, tests
[j
].srgb
);
17719 ok(SUCCEEDED(hr
), "Failed to set srgb state, hr %#x.\n", hr
);
17721 hr
= IDirect3DDevice9_BeginScene(device
);
17722 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
17723 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
17724 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
17725 hr
= IDirect3DDevice9_EndScene(device
);
17726 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
17728 color
= getPixelColor(device
, 320, 240);
17729 ok(color_match(color
, tests
[j
].color
, 2),
17730 "Expected color 0x%08x, got 0x%08x, i = %u, j = %u.\n", tests
[j
].color
, color
, i
, j
);
17732 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
17733 ok(SUCCEEDED(hr
), "Failed to present backbuffer, hr %#x.\n", hr
);
17737 refcount
= IDirect3DDevice9_Release(device
);
17738 ok(!refcount
, "Device has %u references left.\n", refcount
);
17740 IDirect3D9_Release(d3d
);
17741 DestroyWindow(window
);
17744 static void volume_dxtn_test(void)
17746 IDirect3DVolumeTexture9
*texture
;
17747 struct surface_readback rb
;
17748 IDirect3DDevice9
*device
;
17749 IDirect3DSurface9
*rt
;
17758 static const BYTE dxt1_data
[] =
17760 0x00, 0xf8, 0x00, 0xf8, 0xf0, 0xf0, 0xf0, 0xf0,
17761 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
17762 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
17763 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
17765 static const BYTE dxt3_data
[] =
17767 0xff, 0xee, 0xff, 0xee, 0xff, 0xee, 0xff, 0xee, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
17768 0xff, 0xdd, 0xff, 0xdd, 0xff, 0xdd, 0xff, 0xdd, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
17769 0xff, 0xcc, 0xff, 0xcc, 0xff, 0xcc, 0xff, 0xcc, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
17770 0xff, 0xbb, 0xff, 0xbb, 0xff, 0xbb, 0xff, 0xbb, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
17772 static const BYTE dxt5_data
[] =
17774 /* A 8x4x2 texture consisting of 4 4x4 blocks. The colours of the
17775 * blocks are red, green, blue and white. */
17776 0xff, 0xff, 0x80, 0x0d, 0xd8, 0x80, 0x0d, 0xd8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
17777 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
17778 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
17779 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
17781 static const DWORD dxt1_expected_colours
[] =
17783 0xffff0000, 0x00000000, 0xff00ff00, 0xff00ff00,
17784 0xff0000ff, 0xff0000ff, 0xffffffff, 0xffffffff,
17786 static const DWORD dxt3_expected_colours
[] =
17788 0xffff0000, 0xeeff0000, 0xff00ff00, 0xdd00ff00,
17789 0xff0000ff, 0xcc0000ff, 0xffffffff, 0xbbffffff,
17791 static const DWORD dxt5_expected_colours
[] =
17793 0xffff0000, 0x00ff0000, 0xff00ff00, 0xff00ff00,
17794 0xff0000ff, 0xff0000ff, 0xffffffff, 0xffffffff
17797 static const struct
17803 const DWORD
*expected_colours
;
17807 {"DXT1", D3DFMT_DXT1
, dxt1_data
, sizeof(dxt1_data
), dxt1_expected_colours
},
17808 {"DXT3", D3DFMT_DXT3
, dxt3_data
, sizeof(dxt3_data
), dxt3_expected_colours
},
17809 {"DXT5", D3DFMT_DXT5
, dxt5_data
, sizeof(dxt5_data
), dxt5_expected_colours
},
17812 static const struct
17814 struct vec3 position
;
17815 struct vec3 texcrd
;
17819 {{ -1.0f
, -1.0f
, 0.0f
}, { 0.0f
, 0.0f
, 0.25f
}},
17820 {{ -1.0f
, 1.0f
, 0.0f
}, { 0.0f
, 1.0f
, 0.25f
}},
17821 {{ 0.0f
, -1.0f
, 1.0f
}, { 1.0f
, 0.0f
, 0.25f
}},
17822 {{ 0.0f
, 1.0f
, 1.0f
}, { 1.0f
, 1.0f
, 0.25f
}},
17824 {{ 0.0f
, -1.0f
, 0.0f
}, { 0.0f
, 0.0f
, 0.75f
}},
17825 {{ 0.0f
, 1.0f
, 0.0f
}, { 0.0f
, 1.0f
, 0.75f
}},
17826 {{ 1.0f
, -1.0f
, 1.0f
}, { 1.0f
, 0.0f
, 0.75f
}},
17827 {{ 1.0f
, 1.0f
, 1.0f
}, { 1.0f
, 1.0f
, 0.75f
}},
17830 window
= create_window();
17831 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
17832 ok(!!d3d
, "Failed to create a D3D object.\n");
17834 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
17836 skip("Failed to create a D3D device, skipping tests.\n");
17840 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &rt
);
17841 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
17843 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
17845 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
17846 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_VOLUMETEXTURE
, tests
[i
].format
)))
17848 skip("%s volume textures are not supported, skipping test.\n", tests
[i
].name
);
17851 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 8, 4, 2, 1, 0,
17852 tests
[i
].format
, D3DPOOL_MANAGED
, &texture
, NULL
);
17853 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
17855 hr
= IDirect3DVolumeTexture9_LockBox(texture
, 0, &box
, NULL
, 0);
17856 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
17857 memcpy(box
.pBits
, tests
[i
].data
, tests
[i
].data_size
);
17858 hr
= IDirect3DVolumeTexture9_UnlockBox(texture
, 0);
17859 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
17861 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
| D3DFVF_TEXCOORDSIZE3(0));
17862 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
17863 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)texture
);
17864 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
17865 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
17866 ok(SUCCEEDED(hr
), "Failed to set colour op, hr %#x.\n", hr
);
17867 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
17868 ok(SUCCEEDED(hr
), "Failed to set colour arg, hr %#x.\n", hr
);
17869 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
17870 ok(SUCCEEDED(hr
), "Failed to set colour op, hr %#x.\n", hr
);
17871 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAGFILTER
, D3DTEXF_POINT
);
17872 ok(SUCCEEDED(hr
), "Failed to set mag filter, hr %#x.\n", hr
);
17874 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x00ff00ff, 1.0f
, 0);
17875 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
17876 hr
= IDirect3DDevice9_BeginScene(device
);
17877 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
17878 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[0], sizeof(*quads
));
17879 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
17880 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[4], sizeof(*quads
));
17881 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
17882 hr
= IDirect3DDevice9_EndScene(device
);
17883 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
17885 get_rt_readback(rt
, &rb
);
17886 for (j
= 0; j
< ARRAY_SIZE(dxt1_expected_colours
); ++j
)
17888 colour
= get_readback_color(&rb
, 40 + 80 * j
, 240);
17889 ok(color_match(colour
, tests
[i
].expected_colours
[j
], 1),
17890 "Expected colour 0x%08x, got 0x%08x, case %u.\n", tests
[i
].expected_colours
[j
], colour
, j
);
17892 release_surface_readback(&rb
);
17894 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
17895 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
17896 IDirect3DVolumeTexture9_Release(texture
);
17899 IDirect3DSurface9_Release(rt
);
17900 refcount
= IDirect3DDevice9_Release(device
);
17901 ok(!refcount
, "Device has %u references left.\n", refcount
);
17903 IDirect3D9_Release(d3d
);
17904 DestroyWindow(window
);
17907 static void volume_v16u16_test(void)
17909 IDirect3DVolumeTexture9
*texture
;
17910 IDirect3DPixelShader9
*shader
;
17911 IDirect3DDevice9
*device
;
17922 static const struct
17924 struct vec3 position
;
17925 struct vec3 texcrd
;
17929 {{ -1.0f
, -1.0f
, 0.0f
}, { 0.0f
, 0.0f
, 0.25f
}},
17930 {{ -1.0f
, 1.0f
, 0.0f
}, { 0.0f
, 1.0f
, 0.25f
}},
17931 {{ 0.0f
, -1.0f
, 1.0f
}, { 1.0f
, 0.0f
, 0.25f
}},
17932 {{ 0.0f
, 1.0f
, 1.0f
}, { 1.0f
, 1.0f
, 0.25f
}},
17934 {{ 0.0f
, -1.0f
, 0.0f
}, { 0.0f
, 0.0f
, 0.75f
}},
17935 {{ 0.0f
, 1.0f
, 0.0f
}, { 0.0f
, 1.0f
, 0.75f
}},
17936 {{ 1.0f
, -1.0f
, 1.0f
}, { 1.0f
, 0.0f
, 0.75f
}},
17937 {{ 1.0f
, 1.0f
, 1.0f
}, { 1.0f
, 1.0f
, 0.75f
}},
17939 static const DWORD shader_code
[] =
17941 0xffff0101, /* ps_1_1 */
17942 0x00000051, 0xa00f0000, 0x3f000000, 0x3f000000, /* def c0, 0.5, 0.5, */
17943 0x3f000000, 0x3f000000, /* 0.5, 0.5 */
17944 0x00000042, 0xb00f0000, /* tex t0 */
17945 0x00000004, 0x800f0000, 0xb0e40000, 0xa0e40000, 0xa0e40000, /* mad r0, t0, c0, c0 */
17946 0x0000ffff /* end */
17949 window
= create_window();
17950 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
17951 ok(!!d3d
, "Failed to create a D3D object.\n");
17952 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
17954 skip("Failed to create a D3D device, skipping tests.\n");
17958 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
17959 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
17960 if (caps
.PixelShaderVersion
< D3DPS_VERSION(1, 1))
17962 skip("No ps_1_1 support, skipping tests.\n");
17963 IDirect3DDevice9_Release(device
);
17966 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
17967 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_VOLUMETEXTURE
, D3DFMT_V16U16
)))
17969 skip("Volume V16U16 textures are not supported, skipping test.\n");
17970 IDirect3DDevice9_Release(device
);
17974 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
| D3DFVF_TEXCOORDSIZE3(0));
17975 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
17976 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code
, &shader
);
17977 ok(SUCCEEDED(hr
), "Failed to create pixel shader, hr %#x.\n", hr
);
17978 hr
= IDirect3DDevice9_SetPixelShader(device
, shader
);
17979 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
17980 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAGFILTER
, D3DTEXF_POINT
);
17981 ok(SUCCEEDED(hr
), "Failed to set filter, hr %#x.\n", hr
);
17983 for (i
= 0; i
< 2; i
++)
17988 pool
= D3DPOOL_SYSTEMMEM
;
17990 pool
= D3DPOOL_MANAGED
;
17992 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 1, 2, 2, 1, 0, D3DFMT_V16U16
,
17993 pool
, &texture
, NULL
);
17994 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
17996 hr
= IDirect3DVolumeTexture9_LockBox(texture
, 0, &box
, NULL
, 0);
17997 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
17999 texel
= (SHORT
*)((BYTE
*)box
.pBits
+ 0 * box
.RowPitch
+ 0 * box
.SlicePitch
);
18002 texel
= (SHORT
*)((BYTE
*)box
.pBits
+ 1 * box
.RowPitch
+ 0 * box
.SlicePitch
);
18005 texel
= (SHORT
*)((BYTE
*)box
.pBits
+ 0 * box
.RowPitch
+ 1 * box
.SlicePitch
);
18008 texel
= (SHORT
*)((BYTE
*)box
.pBits
+ 1 * box
.RowPitch
+ 1 * box
.SlicePitch
);
18012 hr
= IDirect3DVolumeTexture9_UnlockBox(texture
, 0);
18013 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
18017 IDirect3DVolumeTexture9
*texture2
;
18019 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 1, 2, 2, 1, 0, D3DFMT_V16U16
,
18020 D3DPOOL_DEFAULT
, &texture2
, NULL
);
18021 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
18023 hr
= IDirect3DDevice9_UpdateTexture(device
, (IDirect3DBaseTexture9
*)texture
,
18024 (IDirect3DBaseTexture9
*)texture2
);
18025 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x.\n", hr
);
18027 IDirect3DVolumeTexture9_Release(texture
);
18028 texture
= texture2
;
18031 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) texture
);
18032 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
18034 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x00ff00ff, 1.0f
, 0);
18035 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
18036 hr
= IDirect3DDevice9_BeginScene(device
);
18037 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
18038 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[0], sizeof(*quads
));
18039 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
18040 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[4], sizeof(*quads
));
18041 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
18042 hr
= IDirect3DDevice9_EndScene(device
);
18043 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
18045 color
= getPixelColor(device
, 120, 160);
18046 ok (color_match(color
, 0x000080ff, 2),
18047 "Expected color 0x000080ff, got 0x%08x, V16U16 input -32768, 0.\n", color
);
18048 color
= getPixelColor(device
, 120, 400);
18049 ok (color_match(color
, 0x00ffffff, 2),
18050 "Expected color 0x00ffffff, got 0x%08x, V16U16 input 32767, 32767.\n", color
);
18051 color
= getPixelColor(device
, 360, 160);
18052 ok (color_match(color
, 0x007f7fff, 2),
18053 "Expected color 0x007f7fff, got 0x%08x, V16U16 input 0, 0.\n", color
);
18054 color
= getPixelColor(device
, 360, 400);
18055 ok (color_match(color
, 0x0040c0ff, 2),
18056 "Expected color 0x0040c0ff, got 0x%08x, V16U16 input -16384, 16384.\n", color
);
18058 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18059 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18061 IDirect3DVolumeTexture9_Release(texture
);
18064 IDirect3DPixelShader9_Release(shader
);
18065 refcount
= IDirect3DDevice9_Release(device
);
18066 ok(!refcount
, "Device has %u references left.\n", refcount
);
18068 IDirect3D9_Release(d3d
);
18069 DestroyWindow(window
);
18072 static void add_dirty_rect_test_draw(IDirect3DDevice9
*device
)
18075 static const struct
18077 struct vec3 position
;
18078 struct vec2 texcoord
;
18082 {{-1.0, -1.0, 0.0}, {0.0, 0.0}},
18083 {{-1.0, 1.0, 0.0}, {0.0, 1.0}},
18084 {{ 1.0, -1.0, 0.0}, {1.0, 0.0}},
18085 {{ 1.0, 1.0, 0.0}, {1.0, 1.0}},
18088 hr
= IDirect3DDevice9_BeginScene(device
);
18089 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
18090 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad
, sizeof(*quad
));
18091 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
18092 hr
= IDirect3DDevice9_EndScene(device
);
18093 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
18096 static void add_dirty_rect_test(void)
18099 IDirect3DTexture9
*tex_dst1
, *tex_dst2
, *tex_src_red
, *tex_src_green
,
18100 *tex_managed
, *tex_dynamic
;
18101 IDirect3DSurface9
*surface_dst2
, *surface_src_green
, *surface_src_red
,
18102 *surface_managed0
, *surface_managed1
, *surface_dynamic
;
18103 IDirect3DDevice9
*device
;
18109 D3DLOCKED_RECT locked_rect
;
18110 static const RECT part_rect
= {96, 96, 160, 160};
18113 window
= create_window();
18114 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
18115 ok(!!d3d
, "Failed to create a D3D object.\n");
18116 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
18118 skip("Failed to create a D3D device, skipping tests.\n");
18119 IDirect3D9_Release(d3d
);
18120 DestroyWindow(window
);
18124 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 1, 0, D3DFMT_X8R8G8B8
,
18125 D3DPOOL_DEFAULT
, &tex_dst1
, NULL
);
18126 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
18127 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 1, 0, D3DFMT_X8R8G8B8
,
18128 D3DPOOL_DEFAULT
, &tex_dst2
, NULL
);
18129 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
18130 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 1, 0, D3DFMT_X8R8G8B8
,
18131 D3DPOOL_SYSTEMMEM
, &tex_src_red
, NULL
);
18132 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
18133 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 1, 0, D3DFMT_X8R8G8B8
,
18134 D3DPOOL_SYSTEMMEM
, &tex_src_green
, NULL
);
18135 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
18136 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 2, 0, D3DFMT_X8R8G8B8
,
18137 D3DPOOL_MANAGED
, &tex_managed
, NULL
);
18138 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
18139 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 1, D3DUSAGE_DYNAMIC
,
18140 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &tex_dynamic
, NULL
);
18141 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
18143 hr
= IDirect3DTexture9_GetSurfaceLevel(tex_dst2
, 0, &surface_dst2
);
18144 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
18145 hr
= IDirect3DTexture9_GetSurfaceLevel(tex_src_green
, 0, &surface_src_green
);
18146 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
18147 hr
= IDirect3DTexture9_GetSurfaceLevel(tex_src_red
, 0, &surface_src_red
);
18148 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
18149 hr
= IDirect3DTexture9_GetSurfaceLevel(tex_managed
, 0, &surface_managed0
);
18150 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
18151 hr
= IDirect3DTexture9_GetSurfaceLevel(tex_managed
, 1, &surface_managed1
);
18152 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
18153 hr
= IDirect3DTexture9_GetSurfaceLevel(tex_dynamic
, 0, &surface_dynamic
);
18154 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
18156 fill_surface(surface_src_red
, 0x00ff0000, 0);
18157 fill_surface(surface_src_green
, 0x0000ff00, 0);
18159 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
18160 ok(SUCCEEDED(hr
), "Failed to set fvf, hr %#x.\n", hr
);
18161 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
18162 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
18163 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
18164 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
18165 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MIPFILTER
, D3DTEXF_POINT
);
18166 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
18168 hr
= IDirect3DDevice9_UpdateTexture(device
, (IDirect3DBaseTexture9
*)tex_src_green
,
18169 (IDirect3DBaseTexture9
*)tex_dst1
);
18170 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x.\n", hr
);
18172 /* The second UpdateTexture call writing to tex_dst2 is ignored because tex_src_green is not dirty. */
18173 hr
= IDirect3DDevice9_UpdateTexture(device
, (IDirect3DBaseTexture9
*)tex_src_red
,
18174 (IDirect3DBaseTexture9
*)tex_dst2
);
18175 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x.\n", hr
);
18176 hr
= IDirect3DDevice9_UpdateTexture(device
, (IDirect3DBaseTexture9
*)tex_src_green
,
18177 (IDirect3DBaseTexture9
*)tex_dst2
);
18178 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x.\n", hr
);
18180 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)tex_dst1
);
18181 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
18182 add_dirty_rect_test_draw(device
);
18183 color
= getPixelColor(device
, 320, 240);
18184 ok(color_match(color
, 0x0000ff00, 1),
18185 "Expected color 0x0000ff00, got 0x%08x.\n", color
);
18186 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18187 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18189 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)tex_dst2
);
18190 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
18191 add_dirty_rect_test_draw(device
);
18192 color
= getPixelColor(device
, 320, 240);
18193 todo_wine
ok(color_match(color
, 0x00ff0000, 1),
18194 "Expected color 0x00ff0000, got 0x%08x.\n", color
);
18195 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18196 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18198 /* AddDirtyRect on the destination is ignored. */
18199 hr
= IDirect3DTexture9_AddDirtyRect(tex_dst2
, &part_rect
);
18200 ok(SUCCEEDED(hr
), "Failed to add dirty rect, hr %#x.\n", hr
);
18201 hr
= IDirect3DDevice9_UpdateTexture(device
, (IDirect3DBaseTexture9
*)tex_src_green
,
18202 (IDirect3DBaseTexture9
*)tex_dst2
);
18203 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x.\n", hr
);
18204 add_dirty_rect_test_draw(device
);
18205 color
= getPixelColor(device
, 320, 240);
18206 todo_wine
ok(color_match(color
, 0x00ff0000, 1),
18207 "Expected color 0x00ff0000, got 0x%08x.\n", color
);
18208 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18209 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18211 hr
= IDirect3DTexture9_AddDirtyRect(tex_dst2
, NULL
);
18212 ok(SUCCEEDED(hr
), "Failed to add dirty rect, hr %#x.\n", hr
);
18213 hr
= IDirect3DDevice9_UpdateTexture(device
, (IDirect3DBaseTexture9
*)tex_src_green
,
18214 (IDirect3DBaseTexture9
*)tex_dst2
);
18215 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x.\n", hr
);
18216 add_dirty_rect_test_draw(device
);
18217 color
= getPixelColor(device
, 320, 240);
18218 todo_wine
ok(color_match(color
, 0x00ff0000, 1),
18219 "Expected color 0x00ff0000, got 0x%08x.\n", color
);
18220 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18221 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18223 /* AddDirtyRect on the source makes UpdateTexture work. Partial rectangle
18224 * tracking is supported. */
18225 hr
= IDirect3DTexture9_AddDirtyRect(tex_src_green
, &part_rect
);
18226 ok(SUCCEEDED(hr
), "Failed to add dirty rect, hr %#x.\n", hr
);
18227 hr
= IDirect3DDevice9_UpdateTexture(device
, (IDirect3DBaseTexture9
*)tex_src_green
,
18228 (IDirect3DBaseTexture9
*)tex_dst2
);
18229 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x.\n", hr
);
18230 add_dirty_rect_test_draw(device
);
18231 color
= getPixelColor(device
, 320, 240);
18232 ok(color_match(color
, 0x0000ff00, 1),
18233 "Expected color 0x0000ff00, got 0x%08x.\n", color
);
18234 color
= getPixelColor(device
, 1, 1);
18235 todo_wine
ok(color_match(color
, 0x00ff0000, 1),
18236 "Expected color 0x00ff0000, got 0x%08x.\n", color
);
18237 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18238 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18240 hr
= IDirect3DTexture9_AddDirtyRect(tex_src_green
, NULL
);
18241 ok(SUCCEEDED(hr
), "Failed to add dirty rect, hr %#x.\n", hr
);
18242 hr
= IDirect3DDevice9_UpdateTexture(device
, (IDirect3DBaseTexture9
*)tex_src_green
,
18243 (IDirect3DBaseTexture9
*)tex_dst2
);
18244 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x.\n", hr
);
18245 add_dirty_rect_test_draw(device
);
18246 color
= getPixelColor(device
, 1, 1);
18247 ok(color_match(color
, 0x0000ff00, 1),
18248 "Expected color 0x0000ff00, got 0x%08x.\n", color
);
18250 /* Locks with NO_DIRTY_UPDATE are ignored. */
18251 fill_surface(surface_src_green
, 0x00000080, D3DLOCK_NO_DIRTY_UPDATE
);
18252 hr
= IDirect3DDevice9_UpdateTexture(device
, (IDirect3DBaseTexture9
*)tex_src_green
,
18253 (IDirect3DBaseTexture9
*)tex_dst2
);
18254 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x.\n", hr
);
18255 add_dirty_rect_test_draw(device
);
18256 color
= getPixelColor(device
, 320, 240);
18257 todo_wine
ok(color_match(color
, 0x0000ff00, 1),
18258 "Expected color 0x0000ff00, got 0x%08x.\n", color
);
18259 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18260 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18262 /* Readonly maps write to D3DPOOL_SYSTEMMEM, but don't record a dirty rectangle. */
18263 fill_surface(surface_src_green
, 0x000000ff, D3DLOCK_READONLY
);
18264 hr
= IDirect3DDevice9_UpdateTexture(device
, (IDirect3DBaseTexture9
*)tex_src_green
,
18265 (IDirect3DBaseTexture9
*)tex_dst2
);
18266 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x.\n", hr
);
18267 add_dirty_rect_test_draw(device
);
18268 color
= getPixelColor(device
, 320, 240);
18269 todo_wine
ok(color_match(color
, 0x0000ff00, 1),
18270 "Expected color 0x0000ff00, got 0x%08x.\n", color
);
18271 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18272 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18274 hr
= IDirect3DTexture9_AddDirtyRect(tex_src_green
, NULL
);
18275 hr
= IDirect3DDevice9_UpdateTexture(device
, (IDirect3DBaseTexture9
*)tex_src_green
,
18276 (IDirect3DBaseTexture9
*)tex_dst2
);
18277 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x.\n", hr
);
18278 add_dirty_rect_test_draw(device
);
18279 color
= getPixelColor(device
, 320, 240);
18280 ok(color_match(color
, 0x000000ff, 1),
18281 "Expected color 0x000000ff, got 0x%08x.\n", color
);
18282 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18283 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18285 /* Maps without either of these flags record a dirty rectangle. */
18286 fill_surface(surface_src_green
, 0x00ffffff, 0);
18287 hr
= IDirect3DDevice9_UpdateTexture(device
, (IDirect3DBaseTexture9
*)tex_src_green
,
18288 (IDirect3DBaseTexture9
*)tex_dst2
);
18289 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x.\n", hr
);
18290 add_dirty_rect_test_draw(device
);
18291 color
= getPixelColor(device
, 320, 240);
18292 ok(color_match(color
, 0x00ffffff, 1),
18293 "Expected color 0x00ffffff, got 0x%08x.\n", color
);
18294 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18295 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18297 /* Partial LockRect works just like a partial AddDirtyRect call. */
18298 hr
= IDirect3DTexture9_LockRect(tex_src_green
, 0, &locked_rect
, &part_rect
, 0);
18299 ok(SUCCEEDED(hr
), "Failed to lock texture, hr %#x.\n", hr
);
18300 texel
= locked_rect
.pBits
;
18301 for (i
= 0; i
< 64; i
++)
18302 texel
[i
] = 0x00ff00ff;
18303 for (i
= 1; i
< 64; i
++)
18304 memcpy((BYTE
*)locked_rect
.pBits
+ i
* locked_rect
.Pitch
, locked_rect
.pBits
, locked_rect
.Pitch
);
18305 hr
= IDirect3DTexture9_UnlockRect(tex_src_green
, 0);
18306 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x.\n", hr
);
18307 hr
= IDirect3DDevice9_UpdateTexture(device
, (IDirect3DBaseTexture9
*)tex_src_green
,
18308 (IDirect3DBaseTexture9
*)tex_dst2
);
18309 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x.\n", hr
);
18310 add_dirty_rect_test_draw(device
);
18311 color
= getPixelColor(device
, 320, 240);
18312 ok(color_match(color
, 0x00ff00ff, 1),
18313 "Expected color 0x00ff00ff, got 0x%08x.\n", color
);
18314 color
= getPixelColor(device
, 1, 1);
18315 ok(color_match(color
, 0x00ffffff, 1),
18316 "Expected color 0x00ffffff, got 0x%08x.\n", color
);
18317 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18318 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18320 fill_surface(surface_src_red
, 0x00ff0000, 0);
18321 fill_surface(surface_src_green
, 0x0000ff00, 0);
18323 hr
= IDirect3DDevice9_UpdateTexture(device
, (IDirect3DBaseTexture9
*)tex_src_green
,
18324 (IDirect3DBaseTexture9
*)tex_dst1
);
18325 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x.\n", hr
);
18326 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)tex_dst1
);
18327 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
18328 add_dirty_rect_test_draw(device
);
18329 color
= getPixelColor(device
, 320, 240);
18330 ok(color_match(color
, 0x0000ff00, 1),
18331 "Expected color 0x0000ff00, got 0x%08x.\n", color
);
18332 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18333 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18335 /* UpdateSurface ignores the missing dirty marker. */
18336 hr
= IDirect3DDevice9_UpdateTexture(device
, (IDirect3DBaseTexture9
*)tex_src_red
,
18337 (IDirect3DBaseTexture9
*)tex_dst2
);
18338 hr
= IDirect3DDevice9_UpdateSurface(device
, surface_src_green
, NULL
, surface_dst2
, NULL
);
18339 ok(SUCCEEDED(hr
), "Failed to update surface, hr %#x.\n", hr
);
18340 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)tex_dst2
);
18341 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
18342 add_dirty_rect_test_draw(device
);
18343 color
= getPixelColor(device
, 320, 240);
18344 ok(color_match(color
, 0x0000ff00, 1),
18345 "Expected color 0x0000ff00, got 0x%08x.\n", color
);
18346 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18347 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18349 /* Tests with managed textures. */
18350 fill_surface(surface_managed0
, 0x00ff0000, 0);
18351 fill_surface(surface_managed1
, 0x00ff0000, 0);
18352 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)tex_managed
);
18353 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
18354 add_dirty_rect_test_draw(device
);
18355 color
= getPixelColor(device
, 320, 240);
18356 ok(color_match(color
, 0x00ff0000, 1),
18357 "Expected color 0x00ff0000, got 0x%08x.\n", color
);
18358 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18359 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18360 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 1);
18361 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
18362 add_dirty_rect_test_draw(device
);
18363 color
= getPixelColor(device
, 320, 240);
18364 ok(color_match(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
18365 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18366 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18368 /* Managed textures also honor D3DLOCK_NO_DIRTY_UPDATE. */
18369 fill_surface(surface_managed0
, 0x0000ff00, D3DLOCK_NO_DIRTY_UPDATE
);
18370 fill_surface(surface_managed1
, 0x000000ff, D3DLOCK_NO_DIRTY_UPDATE
);
18371 add_dirty_rect_test_draw(device
);
18372 color
= getPixelColor(device
, 320, 240);
18373 ok(color_match(color
, 0x00ff0000, 1),
18374 "Expected color 0x00ff0000, got 0x%08x.\n", color
);
18375 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18376 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18377 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 0);
18378 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
18379 add_dirty_rect_test_draw(device
);
18380 color
= getPixelColor(device
, 320, 240);
18381 ok(color_match(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
18382 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18383 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18385 /* AddDirtyRect uploads the new contents.
18386 * Side note, not tested in the test: Partial surface updates work, and two separate
18387 * dirty rectangles are tracked individually. Tested on Nvidia Kepler, other drivers
18389 hr
= IDirect3DTexture9_AddDirtyRect(tex_managed
, NULL
);
18390 ok(SUCCEEDED(hr
), "Failed to add dirty rect, hr %#x.\n", hr
);
18391 add_dirty_rect_test_draw(device
);
18392 color
= getPixelColor(device
, 320, 240);
18393 ok(color_match(color
, 0x0000ff00, 1),
18394 "Expected color 0x0000ff00, got 0x%08x.\n", color
);
18395 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18396 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18397 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 1);
18398 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
18399 add_dirty_rect_test_draw(device
);
18400 color
= getPixelColor(device
, 320, 240);
18401 ok(color_match(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
18402 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18403 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18405 /* So does EvictManagedResources. */
18406 fill_surface(surface_managed0
, 0x00ffff00, D3DLOCK_NO_DIRTY_UPDATE
);
18407 fill_surface(surface_managed1
, 0x00ff00ff, D3DLOCK_NO_DIRTY_UPDATE
);
18408 hr
= IDirect3DDevice9_EvictManagedResources(device
);
18409 ok(SUCCEEDED(hr
), "Failed to evict managed resources, hr %#x.\n", hr
);
18410 add_dirty_rect_test_draw(device
);
18411 color
= getPixelColor(device
, 320, 240);
18412 ok(color_match(color
, 0x00ff00ff, 1), "Got unexpected color 0x%08x.\n", color
);
18413 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18414 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18415 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 0);
18416 ok(SUCCEEDED(hr
), "Failed to set sampler state, hr %#x.\n", hr
);
18417 add_dirty_rect_test_draw(device
);
18418 color
= getPixelColor(device
, 320, 240);
18419 ok(color_match(color
, 0x00ffff00, 1), "Got unexpected color 0x%08x.\n", color
);
18420 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18421 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18423 /* Tests with dynamic textures */
18424 fill_surface(surface_dynamic
, 0x0000ffff, 0);
18425 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)tex_dynamic
);
18426 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
18427 add_dirty_rect_test_draw(device
);
18428 color
= getPixelColor(device
, 320, 240);
18429 ok(color_match(color
, 0x0000ffff, 1),
18430 "Expected color 0x0000ffff, got 0x%08x.\n", color
);
18431 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18432 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18434 /* Dynamic textures don't honor D3DLOCK_NO_DIRTY_UPDATE. */
18435 fill_surface(surface_dynamic
, 0x00ffff00, D3DLOCK_NO_DIRTY_UPDATE
);
18436 add_dirty_rect_test_draw(device
);
18437 color
= getPixelColor(device
, 320, 240);
18438 ok(color_match(color
, 0x00ffff00, 1),
18439 "Expected color 0x00ffff00, got 0x%08x.\n", color
);
18440 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18441 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18443 /* AddDirtyRect on a locked texture is allowed. */
18444 hr
= IDirect3DTexture9_LockRect(tex_src_red
, 0, &locked_rect
, NULL
, 0);
18445 ok(SUCCEEDED(hr
), "Failed to lock texture, hr %#x.\n", hr
);
18446 hr
= IDirect3DTexture9_AddDirtyRect(tex_src_red
, NULL
);
18447 ok(SUCCEEDED(hr
), "Failed to add dirty rect, hr %#x.\n", hr
);
18448 hr
= IDirect3DTexture9_UnlockRect(tex_src_red
, 0);
18449 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x.\n", hr
);
18451 /* Redundant AddDirtyRect calls are ok. */
18452 hr
= IDirect3DTexture9_AddDirtyRect(tex_managed
, NULL
);
18453 ok(SUCCEEDED(hr
), "Failed to add dirty rect, hr %#x.\n", hr
);
18454 hr
= IDirect3DTexture9_AddDirtyRect(tex_managed
, NULL
);
18455 ok(SUCCEEDED(hr
), "Failed to add dirty rect, hr %#x.\n", hr
);
18457 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
18458 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
18459 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
18460 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
18461 IDirect3DSurface9_Release(surface_dst2
);
18462 IDirect3DSurface9_Release(surface_managed1
);
18463 IDirect3DSurface9_Release(surface_managed0
);
18464 IDirect3DSurface9_Release(surface_src_red
);
18465 IDirect3DSurface9_Release(surface_src_green
);
18466 IDirect3DSurface9_Release(surface_dynamic
);
18467 IDirect3DTexture9_Release(tex_src_red
);
18468 IDirect3DTexture9_Release(tex_src_green
);
18469 IDirect3DTexture9_Release(tex_dst1
);
18470 IDirect3DTexture9_Release(tex_dst2
);
18471 IDirect3DTexture9_Release(tex_managed
);
18472 IDirect3DTexture9_Release(tex_dynamic
);
18473 refcount
= IDirect3DDevice9_Release(device
);
18474 ok(!refcount
, "Device has %u references left.\n", refcount
);
18475 IDirect3D9_Release(d3d
);
18476 DestroyWindow(window
);
18479 static void test_per_stage_constant(void)
18481 IDirect3DDevice9
*device
;
18489 static const struct
18491 struct vec3 position
;
18496 {{-1.0f
, -1.0f
, 0.1f
}, 0xffff0000},
18497 {{-1.0f
, 1.0f
, 0.1f
}, 0xffff0000},
18498 {{ 1.0f
, -1.0f
, 0.1f
}, 0xffff0000},
18499 {{ 1.0f
, 1.0f
, 0.1f
}, 0xffff0000},
18502 window
= create_window();
18503 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
18504 ok(!!d3d
, "Failed to create a D3D object.\n");
18505 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
18507 skip("Failed to create a D3D device, skipping tests.\n");
18511 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
18512 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
18513 if (!(caps
.PrimitiveMiscCaps
& D3DPMISCCAPS_PERSTAGECONSTANT
))
18515 skip("Per-stage constants not supported, skipping tests.\n");
18516 IDirect3DDevice9_Release(device
);
18520 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
18521 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
18522 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, TRUE
);
18523 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
18524 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_SRCALPHA
);
18525 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
18526 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
18527 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
18528 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
18529 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
18531 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_CONSTANT
, 0x80a1b2c3);
18532 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
18533 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_CONSTANT
);
18534 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
18535 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
18536 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
18538 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x000000ff, 1.0f
, 0);
18539 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
18541 hr
= IDirect3DDevice9_BeginScene(device
);
18542 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
18543 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
18544 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
18545 hr
= IDirect3DDevice9_EndScene(device
);
18546 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
18548 color
= getPixelColor(device
, 320, 240);
18549 ok(color_match(color
, 0x00a1b2c3, 1), "Got unexpected color 0x%08x.\n", color
);
18550 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18551 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18553 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_CONSTANT
| D3DTA_COMPLEMENT
);
18554 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
18556 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x000000ff, 1.0f
, 0);
18557 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
18559 hr
= IDirect3DDevice9_BeginScene(device
);
18560 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
18561 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
18562 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
18563 hr
= IDirect3DDevice9_EndScene(device
);
18564 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
18566 color
= getPixelColor(device
, 320, 240);
18567 ok(color_match(color
, 0x005e4d3c, 1), "Got unexpected color 0x%08x.\n", color
);
18568 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18569 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18571 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_CONSTANT
| D3DTA_ALPHAREPLICATE
);
18572 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
18574 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x000000ff, 1.0f
, 0);
18575 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
18577 hr
= IDirect3DDevice9_BeginScene(device
);
18578 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
18579 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
18580 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
18581 hr
= IDirect3DDevice9_EndScene(device
);
18582 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
18584 color
= getPixelColor(device
, 320, 240);
18585 ok(color_match(color
, 0x00808080, 1), "Got unexpected color 0x%08x.\n", color
);
18586 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18587 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18589 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_ALPHAARG1
, D3DTA_CONSTANT
);
18590 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
18591 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
);
18592 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
18593 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_CURRENT
);
18594 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
18596 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x000000ff, 1.0f
, 0);
18597 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
18599 hr
= IDirect3DDevice9_BeginScene(device
);
18600 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
18601 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
18602 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
18603 hr
= IDirect3DDevice9_EndScene(device
);
18604 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
18606 color
= getPixelColor(device
, 320, 240);
18607 ok(color_match(color
, 0x0080007f, 1), "Got unexpected color 0x%08x.\n", color
);
18608 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18609 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18611 refcount
= IDirect3DDevice9_Release(device
);
18612 ok(!refcount
, "Device has %u references left.\n", refcount
);
18614 IDirect3D9_Release(d3d
);
18615 DestroyWindow(window
);
18618 static void test_3dc_formats(void)
18620 static const char ati1n_data
[] =
18622 /* A 4x4 texture with the color component at 50%. */
18623 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
18625 static const char ati2n_data
[] =
18627 /* A 8x4 texture consisting of 2 4x4 blocks. The first block has 50% first color component,
18628 * 0% second component. Second block is the opposite. */
18629 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
18630 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
18632 static const struct
18634 struct vec3 position
;
18635 struct vec2 texcoord
;
18639 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 0.0f
}},
18640 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
18641 {{ 0.0f
, -1.0f
, 1.0f
}, {1.0f
, 0.0f
}},
18642 {{ 0.0f
, 1.0f
, 1.0f
}, {1.0f
, 1.0f
}},
18644 {{ 0.0f
, -1.0f
, 0.0f
}, {0.0f
, 0.0f
}},
18645 {{ 0.0f
, 1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
18646 {{ 1.0f
, -1.0f
, 1.0f
}, {1.0f
, 0.0f
}},
18647 {{ 1.0f
, 1.0f
, 1.0f
}, {1.0f
, 1.0f
}},
18649 static const DWORD ati1n_fourcc
= MAKEFOURCC('A','T','I','1');
18650 static const DWORD ati2n_fourcc
= MAKEFOURCC('A','T','I','2');
18651 static const struct
18653 struct vec2 position
;
18656 D3DCOLOR nvidia_old
;
18657 D3DCOLOR nvidia_new
;
18659 expected_colors
[] =
18661 {{ 80, 240}, 0x007fffff, 0x003f3f3f, 0x007f7f7f, 0x007f0000},
18662 {{240, 240}, 0x007fffff, 0x003f3f3f, 0x007f7f7f, 0x007f0000},
18663 {{400, 240}, 0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff},
18664 {{560, 240}, 0x007f00ff, 0x007f00ff, 0x007f00ff, 0x007f00ff},
18667 IDirect3DDevice9
*device
;
18668 IDirect3DTexture9
*ati1n_texture
, *ati2n_texture
;
18670 D3DLOCKED_RECT rect
;
18677 window
= create_window();
18678 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
18679 ok(!!d3d
, "Failed to create a D3D object.\n");
18680 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
18681 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_TEXTURE
, ati1n_fourcc
)))
18683 skip("ATI1N textures are not supported, skipping test.\n");
18686 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
18687 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_TEXTURE
, ati2n_fourcc
)))
18689 skip("ATI2N textures are not supported, skipping test.\n");
18692 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
18694 skip("Failed to create a D3D device, skipping tests.\n");
18697 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
18698 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
18699 if (!(caps
.PrimitiveMiscCaps
& D3DPMISCCAPS_TSSARGTEMP
))
18701 skip("D3DTA_TEMP not supported, skipping tests.\n");
18702 IDirect3DDevice9_Release(device
);
18706 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, ati1n_fourcc
,
18707 D3DPOOL_MANAGED
, &ati1n_texture
, NULL
);
18708 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
18710 hr
= IDirect3DTexture9_LockRect(ati1n_texture
, 0, &rect
, NULL
, 0);
18711 ok(SUCCEEDED(hr
), "Failed to lock texture, hr %#x.\n", hr
);
18712 memcpy(rect
.pBits
, ati1n_data
, sizeof(ati1n_data
));
18713 hr
= IDirect3DTexture9_UnlockRect(ati1n_texture
, 0);
18714 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x.\n", hr
);
18716 hr
= IDirect3DDevice9_CreateTexture(device
, 8, 4, 1, 0, ati2n_fourcc
,
18717 D3DPOOL_MANAGED
, &ati2n_texture
, NULL
);
18718 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
18720 hr
= IDirect3DTexture9_LockRect(ati2n_texture
, 0, &rect
, NULL
, 0);
18721 ok(SUCCEEDED(hr
), "Failed to lock texture, hr %#x.\n", hr
);
18722 memcpy(rect
.pBits
, ati2n_data
, sizeof(ati2n_data
));
18723 hr
= IDirect3DTexture9_UnlockRect(ati2n_texture
, 0);
18724 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x.\n", hr
);
18726 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
| D3DFVF_TEXCOORDSIZE2(0));
18727 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
18728 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_BLENDTEXTUREALPHA
);
18729 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
18730 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
18731 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
18732 /* The temporary register is initialized to 0. */
18733 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_TEMP
);
18734 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
18735 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
);
18736 ok(SUCCEEDED(hr
), "Failed to set alpha op, hr %#x.\n", hr
);
18737 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_ALPHAARG1
, D3DTA_TEXTURE
);
18738 ok(SUCCEEDED(hr
), "Failed to set alpha arg, hr %#x.\n", hr
);
18739 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
18740 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
18741 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAGFILTER
, D3DTEXF_POINT
);
18742 ok(SUCCEEDED(hr
), "Failed to set mag filter, hr %#x.\n", hr
);
18744 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x00ff00ff, 1.0f
, 0);
18745 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
18746 hr
= IDirect3DDevice9_BeginScene(device
);
18747 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
18748 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)ati1n_texture
);
18749 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
18750 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[0], sizeof(*quads
));
18751 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
18752 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)ati2n_texture
);
18753 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
18754 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[4], sizeof(*quads
));
18755 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
18756 hr
= IDirect3DDevice9_EndScene(device
);
18757 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
18759 for (i
= 0; i
< 4; ++i
)
18761 color
= getPixelColor(device
, expected_colors
[i
].position
.x
, expected_colors
[i
].position
.y
);
18762 ok (color_match(color
, expected_colors
[i
].amd_r500
, 1)
18763 || color_match(color
, expected_colors
[i
].amd_r600
, 1)
18764 || color_match(color
, expected_colors
[i
].nvidia_old
, 1)
18765 || color_match(color
, expected_colors
[i
].nvidia_new
, 1),
18766 "Got unexpected color 0x%08x, case %u.\n", color
, i
);
18769 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18770 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18771 IDirect3DTexture9_Release(ati2n_texture
);
18772 IDirect3DTexture9_Release(ati1n_texture
);
18773 refcount
= IDirect3DDevice9_Release(device
);
18774 ok(!refcount
, "Device has %u references left.\n", refcount
);
18777 IDirect3D9_Release(d3d
);
18778 DestroyWindow(window
);
18781 static void test_fog_interpolation(void)
18784 IDirect3DDevice9
*device
;
18789 static const struct
18791 struct vec3 position
;
18797 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000, 0xff000000},
18798 {{-1.0f
, 1.0f
, 0.0f
}, 0xffff0000, 0xff000000},
18799 {{ 1.0f
, -1.0f
, 1.0f
}, 0xffff0000, 0x00000000},
18800 {{ 1.0f
, 1.0f
, 1.0f
}, 0xffff0000, 0x00000000},
18808 static const struct
18810 D3DFOGMODE vfog
, tfog
;
18811 D3DSHADEMODE shade
;
18812 D3DCOLOR middle_color
;
18817 {D3DFOG_NONE
, D3DFOG_NONE
, D3DSHADE_FLAT
, 0x00007f80, FALSE
},
18818 {D3DFOG_NONE
, D3DFOG_NONE
, D3DSHADE_GOURAUD
, 0x00007f80, FALSE
},
18819 {D3DFOG_EXP
, D3DFOG_NONE
, D3DSHADE_FLAT
, 0x00007f80, TRUE
},
18820 {D3DFOG_EXP
, D3DFOG_NONE
, D3DSHADE_GOURAUD
, 0x00007f80, TRUE
},
18821 {D3DFOG_NONE
, D3DFOG_EXP
, D3DSHADE_FLAT
, 0x0000ea15, FALSE
},
18822 {D3DFOG_NONE
, D3DFOG_EXP
, D3DSHADE_GOURAUD
, 0x0000ea15, FALSE
},
18823 {D3DFOG_EXP
, D3DFOG_EXP
, D3DSHADE_FLAT
, 0x0000ea15, FALSE
},
18824 {D3DFOG_EXP
, D3DFOG_EXP
, D3DSHADE_GOURAUD
, 0x0000ea15, FALSE
},
18826 static const D3DMATRIX ident_mat
=
18828 1.0f
, 0.0f
, 0.0f
, 0.0f
,
18829 0.0f
, 1.0f
, 0.0f
, 0.0f
,
18830 0.0f
, 0.0f
, 1.0f
, 0.0f
,
18831 0.0f
, 0.0f
, 0.0f
, 1.0f
18835 window
= create_window();
18836 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
18837 ok(!!d3d
, "Failed to create a D3D object.\n");
18839 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
18841 skip("Failed to create a D3D device, skipping tests.\n");
18842 IDirect3D9_Release(d3d
);
18843 DestroyWindow(window
);
18847 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
18848 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
18849 if (!(caps
.RasterCaps
& D3DPRASTERCAPS_FOGTABLE
))
18850 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests\n");
18852 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
);
18853 ok(SUCCEEDED(hr
), "Failed to set fvf, hr %#x.\n", hr
);
18854 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
18855 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
18856 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
18857 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
18858 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGENABLE
, TRUE
);
18859 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
18860 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGCOLOR
, 0x0000ff00);
18861 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
18863 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGDENSITY
, conv
.d
);
18864 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
18866 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
18867 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
18868 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TFACTOR
);
18869 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
18870 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_TEXTUREFACTOR
, 0x000000ff);
18871 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
18873 /* Some of the tests seem to depend on the projection matrix explicitly
18874 * being set to an identity matrix, even though that's the default.
18875 * (AMD Radeon X1600, AMD Radeon HD 6310, Windows 7). Without this,
18876 * the drivers seem to use a static z = 1.0 input for the fog equation.
18877 * The input value is independent of the actual z and w component of
18878 * the vertex position. */
18879 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_PROJECTION
, &ident_mat
);
18880 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
18882 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
18884 if(!(caps
.RasterCaps
& D3DPRASTERCAPS_FOGTABLE
) && tests
[i
].tfog
)
18887 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00808080, 0.0f
, 0);
18888 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
18890 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SHADEMODE
, tests
[i
].shade
);
18891 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
18892 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, tests
[i
].vfog
);
18893 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
18894 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGTABLEMODE
, tests
[i
].tfog
);
18895 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
18896 hr
= IDirect3DDevice9_BeginScene(device
);
18897 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
18898 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
18899 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
18900 hr
= IDirect3DDevice9_EndScene(device
);
18901 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
18903 color
= getPixelColor(device
, 0, 240);
18904 ok(color_match(color
, 0x000000ff, 2), "Got unexpected color 0x%08x, case %u.\n", color
, i
);
18905 color
= getPixelColor(device
, 320, 240);
18906 todo_wine_if (tests
[i
].todo
)
18907 ok(color_match(color
, tests
[i
].middle_color
, 2),
18908 "Got unexpected color 0x%08x, case %u.\n", color
, i
);
18909 color
= getPixelColor(device
, 639, 240);
18910 ok(color_match(color
, 0x0000fd02, 2), "Got unexpected color 0x%08x, case %u.\n", color
, i
);
18911 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
18912 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
18915 refcount
= IDirect3DDevice9_Release(device
);
18916 ok(!refcount
, "Device has %u references left.\n", refcount
);
18917 IDirect3D9_Release(d3d
);
18918 DestroyWindow(window
);
18921 static void test_negative_fixedfunction_fog(void)
18924 IDirect3DDevice9
*device
;
18929 static const struct
18931 struct vec3 position
;
18936 {{-1.0f
, -1.0f
, -0.5f
}, 0xffff0000},
18937 {{-1.0f
, 1.0f
, -0.5f
}, 0xffff0000},
18938 {{ 1.0f
, -1.0f
, -0.5f
}, 0xffff0000},
18939 {{ 1.0f
, 1.0f
, -0.5f
}, 0xffff0000},
18941 static const struct
18943 struct vec4 position
;
18948 {{ 0.0f
, 0.0f
, -0.5f
, 1.0f
}, 0xffff0000},
18949 {{640.0f
, 0.0f
, -0.5f
, 1.0f
}, 0xffff0000},
18950 {{ 0.0f
, 480.0f
, -0.5f
, 1.0f
}, 0xffff0000},
18951 {{640.0f
, 480.0f
, -0.5f
, 1.0f
}, 0xffff0000},
18954 static const D3DMATRIX zero
=
18956 1.0f
, 0.0f
, 0.0f
, 0.0f
,
18957 0.0f
, 1.0f
, 0.0f
, 0.0f
,
18958 0.0f
, 0.0f
, 0.0f
, 0.0f
,
18959 0.0f
, 0.0f
, 0.0f
, 1.0f
18961 /* Needed to make AMD drivers happy. Yeah, it is not supposed to
18962 * have an effect on RHW draws. */
18963 static const D3DMATRIX identity
=
18965 1.0f
, 0.0f
, 0.0f
, 0.0f
,
18966 0.0f
, 1.0f
, 0.0f
, 0.0f
,
18967 0.0f
, 0.0f
, 1.0f
, 0.0f
,
18968 0.0f
, 0.0f
, 0.0f
, 1.0f
18970 static const struct
18975 const D3DMATRIX
*matrix
;
18981 D3DFOGMODE vfog
, tfog
;
18982 DWORD color
, color_broken
, color_broken2
;
18986 /* Run the XYZRHW tests first. Depth clamping is broken after RHW draws on the testbot.
18988 * Geforce8+ GPUs on Windows abs() table fog, everything else does not. */
18989 {D3DFVF_XYZRHW
, tquad
, sizeof(*tquad
), &identity
, { 0.0f
}, {1.0f
},
18990 D3DFOG_NONE
, D3DFOG_LINEAR
, 0x00ff0000, 0x00808000, 0x00808000},
18991 /* r200 GPUs and presumably all d3d8 and older HW clamp the fog
18992 * parameters to 0.0 and 1.0 in the table fog case. */
18993 {D3DFVF_XYZRHW
, tquad
, sizeof(*tquad
), &identity
, {-1.0f
}, {0.0f
},
18994 D3DFOG_NONE
, D3DFOG_LINEAR
, 0x00808000, 0x00ff0000, 0x0000ff00},
18995 /* test_fog_interpolation shows that vertex fog evaluates the fog
18996 * equation in the vertex pipeline. Start = -1.0 && end = 0.0 shows
18997 * that the abs happens before the fog equation is evaluated.
18999 * Vertex fog abs() behavior is the same on all GPUs. */
19000 {D3DFVF_XYZ
, quad
, sizeof(*quad
), &zero
, { 0.0f
}, {1.0f
},
19001 D3DFOG_LINEAR
, D3DFOG_NONE
, 0x00808000, 0x00808000, 0x00808000},
19002 {D3DFVF_XYZ
, quad
, sizeof(*quad
), &zero
, {-1.0f
}, {0.0f
},
19003 D3DFOG_LINEAR
, D3DFOG_NONE
, 0x0000ff00, 0x0000ff00, 0x0000ff00},
19004 {D3DFVF_XYZ
, quad
, sizeof(*quad
), &zero
, { 0.0f
}, {1.0f
},
19005 D3DFOG_EXP
, D3DFOG_NONE
, 0x009b6400, 0x009b6400, 0x009b6400},
19009 window
= create_window();
19010 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
19011 ok(!!d3d
, "Failed to create a D3D object.\n");
19013 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
19015 skip("Failed to create a D3D device, skipping tests.\n");
19016 IDirect3D9_Release(d3d
);
19017 DestroyWindow(window
);
19021 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
19022 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
19023 if (!(caps
.RasterCaps
& D3DPRASTERCAPS_FOGTABLE
))
19024 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests.\n");
19026 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
19027 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
19028 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_FALSE
);
19029 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
19030 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGENABLE
, TRUE
);
19031 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
19032 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGCOLOR
, 0x0000ff00);
19033 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
19034 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CLIPPING
, FALSE
);
19035 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
19037 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
19039 if (!(caps
.RasterCaps
& D3DPRASTERCAPS_FOGTABLE
) && tests
[i
].tfog
)
19042 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x000000ff, 0.0f
, 0);
19043 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
19045 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_PROJECTION
, tests
[i
].matrix
);
19046 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
19047 hr
= IDirect3DDevice9_SetFVF(device
, tests
[i
].pos_type
| D3DFVF_DIFFUSE
);
19048 ok(SUCCEEDED(hr
), "Failed to set fvf, hr %#x.\n", hr
);
19049 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGSTART
, tests
[i
].start
.d
);
19050 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
19051 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGEND
, tests
[i
].end
.d
);
19052 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
19053 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, tests
[i
].vfog
);
19054 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
19055 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGTABLEMODE
, tests
[i
].tfog
);
19056 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
19058 hr
= IDirect3DDevice9_BeginScene(device
);
19059 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
19060 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, tests
[i
].quad
, tests
[i
].stride
);
19061 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
19062 hr
= IDirect3DDevice9_EndScene(device
);
19063 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
19065 color
= getPixelColor(device
, 320, 240);
19066 ok(color_match(color
, tests
[i
].color
, 2) || broken(color_match(color
, tests
[i
].color_broken
, 2))
19067 || broken(color_match(color
, tests
[i
].color_broken2
, 2)),
19068 "Got unexpected color 0x%08x, case %u.\n", color
, i
);
19069 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
19070 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
19073 refcount
= IDirect3DDevice9_Release(device
);
19074 ok(!refcount
, "Device has %u references left.\n", refcount
);
19075 IDirect3D9_Release(d3d
);
19076 DestroyWindow(window
);
19079 static void test_position_index(void)
19081 static const D3DVERTEXELEMENT9 decl_elements
[] =
19083 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
19084 {0, 12, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 1},
19087 /* Declaring (and using) a position1 output semantic in a VS fails at draw time on AMD
19088 * but works on Nvidia.
19089 * MSDN is not consistent on this point. */
19090 static const DWORD vs_code
[] =
19092 0xfffe0300, /* vs_3_0 */
19093 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position0 v0 */
19094 0x0200001f, 0x80010000, 0x900f0001, /* dcl_position1 v1 */
19095 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position0 o0 */
19096 0x0200001f, 0x80010000, 0xe00f0001, /* dcl_position1 o1 */
19097 0x0200001f, 0x80000005, 0xe00f0002, /* dcl_texcoord0 o2 */
19098 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
19099 0x02000001, 0xe00f0001, 0x90e40001, /* mov o1, v1 */
19100 0x02000001, 0xe00f0002, 0x90e40001, /* mov o2, v1 */
19101 0x0000ffff /* end */
19103 static const DWORD vs_code_2
[] =
19105 0xfffe0300, /* vs_3_0 */
19106 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position0 v0 */
19107 0x0200001f, 0x80010000, 0x900f0001, /* dcl_position1 v1 */
19108 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position0 o0 */
19109 0x0200001f, 0x80000005, 0xe00f0002, /* dcl_texcoord0 o2 */
19110 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
19111 0x02000001, 0xe00f0002, 0x90e40001, /* mov o2, v1 */
19112 0x0000ffff /* end */
19114 static const DWORD ps_code
[] =
19116 0xffff0300, /* ps_3_0 */
19117 0x0200001f, 0x80010000, 0x900f0000, /* dcl_position1 v0 */
19118 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
19119 0x0000ffff /* end */
19121 static const DWORD ps_code_2
[] =
19123 0xffff0300, /* ps_3_0 */
19124 0x0200001f, 0x80000005, 0x900f0000, /* dcl_texcoord0 v0 */
19125 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
19126 0x0000ffff /* end */
19128 /* This one is considered invalid by the native shader assembler. */
19129 static const DWORD ps_code_bad
[] =
19131 0xffff0300, /* ps_3_0 */
19132 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position0 v0 */
19133 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
19134 0x0000ffff /* end */
19136 static const struct
19138 struct vec3 position
;
19139 struct vec3 position1
;
19143 {{-1.0f
, -1.0f
, 0.5f
}, {1.0f
, 0.0f
, 0.0f
}},
19144 {{-1.0f
, 1.0f
, 0.5f
}, {1.0f
, 0.0f
, 0.0f
}},
19145 {{ 1.0f
, -1.0f
, 0.5f
}, {0.0f
, 1.0f
, 0.0f
}},
19146 {{ 1.0f
, 1.0f
, 0.5f
}, {0.0f
, 1.0f
, 0.0f
}},
19148 static const struct
19150 struct vec2 position
;
19151 D3DCOLOR expected_color
;
19152 D3DCOLOR broken_color
;
19154 expected_colors
[] =
19156 {{ 80, 240}, 0x00df2000, 0x00ff00ff},
19157 {{240, 240}, 0x009f6000, 0x00ff00ff},
19158 {{400, 240}, 0x00609f00, 0x00ff00ff},
19159 {{560, 240}, 0x0020df00, 0x00ff00ff},
19162 IDirect3DDevice9
*device
;
19163 IDirect3DVertexDeclaration9
*vertex_declaration
;
19164 IDirect3DVertexShader9
*vs
, *vs2
;
19165 IDirect3DPixelShader9
*ps
, *ps2
;
19173 window
= create_window();
19174 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
19175 ok(!!d3d
, "Failed to create a D3D object.\n");
19176 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
19178 skip("Failed to create a D3D device, skipping tests.\n");
19182 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
19183 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
19184 if (caps
.VertexShaderVersion
< D3DVS_VERSION(3, 0)
19185 || caps
.PixelShaderVersion
< D3DPS_VERSION(3, 0))
19187 skip("Shader model 3.0 unsupported, skipping tests.\n");
19188 IDirect3DDevice9_Release(device
);
19192 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &vertex_declaration
);
19193 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed, hr %#x\n", hr
);
19195 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, vertex_declaration
);
19196 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed, hr %#x\n", hr
);
19198 hr
= IDirect3DDevice9_CreateVertexShader(device
, vs_code
, &vs
);
19199 ok(SUCCEEDED(hr
), "CreateVertexShader failed, hr %#x.\n", hr
);
19200 hr
= IDirect3DDevice9_CreateVertexShader(device
, vs_code_2
, &vs2
);
19201 ok(SUCCEEDED(hr
), "CreateVertexShader failed, hr %#x.\n", hr
);
19203 hr
= IDirect3DDevice9_SetVertexShader(device
, vs
);
19204 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
19206 hr
= IDirect3DDevice9_CreatePixelShader(device
, ps_code_bad
, &ps
);
19207 ok(hr
== D3DERR_INVALIDCALL
, "CreatePixelShader returned hr %#x.\n", hr
);
19209 hr
= IDirect3DDevice9_CreatePixelShader(device
, ps_code
, &ps
);
19210 ok(SUCCEEDED(hr
), "CreatePixelShader failed, hr %#x.\n", hr
);
19211 hr
= IDirect3DDevice9_CreatePixelShader(device
, ps_code_2
, &ps2
);
19212 ok(SUCCEEDED(hr
), "CreatePixelShader failed, hr %#x.\n", hr
);
19214 hr
= IDirect3DDevice9_SetPixelShader(device
, ps
);
19215 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
19217 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x00ff00ff, 1.0f
, 0);
19218 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
19219 hr
= IDirect3DDevice9_BeginScene(device
);
19220 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
19221 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
19222 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
19223 hr
= IDirect3DDevice9_EndScene(device
);
19224 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
19226 for (i
= 0; i
< ARRAY_SIZE(expected_colors
); ++i
)
19228 color
= getPixelColor(device
, expected_colors
[i
].position
.x
, expected_colors
[i
].position
.y
);
19229 ok (color_match(color
, expected_colors
[i
].expected_color
, 1)
19230 || broken(color_match(color
, expected_colors
[i
].broken_color
, 1)),
19231 "Got unexpected color 0x%08x, case %u.\n", color
, i
);
19234 hr
= IDirect3DDevice9_SetPixelShader(device
, ps2
);
19235 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
19237 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x00ff00ff, 1.0f
, 0);
19238 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
19239 hr
= IDirect3DDevice9_BeginScene(device
);
19240 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
19241 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
19242 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
19243 hr
= IDirect3DDevice9_EndScene(device
);
19244 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
19246 for (i
= 0; i
< ARRAY_SIZE(expected_colors
); ++i
)
19248 color
= getPixelColor(device
, expected_colors
[i
].position
.x
, expected_colors
[i
].position
.y
);
19249 ok (color_match(color
, expected_colors
[i
].expected_color
, 1)
19250 || broken(color_match(color
, expected_colors
[i
].broken_color
, 1)),
19251 "Got unexpected color 0x%08x, case %u.\n", color
, i
);
19254 hr
= IDirect3DDevice9_SetVertexShader(device
, vs2
);
19255 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
19257 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x00ff00ff, 1.0f
, 0);
19258 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
19259 hr
= IDirect3DDevice9_BeginScene(device
);
19260 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
19261 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
19262 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
19263 hr
= IDirect3DDevice9_EndScene(device
);
19264 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
19266 for (i
= 0; i
< ARRAY_SIZE(expected_colors
); ++i
)
19268 color
= getPixelColor(device
, expected_colors
[i
].position
.x
, expected_colors
[i
].position
.y
);
19269 ok (color_match(color
, expected_colors
[i
].expected_color
, 1),
19270 "Got unexpected color 0x%08x, case %u.\n", color
, i
);
19273 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
19274 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
19276 IDirect3DPixelShader9_Release(ps2
);
19277 IDirect3DPixelShader9_Release(ps
);
19278 IDirect3DVertexShader9_Release(vs2
);
19279 IDirect3DVertexShader9_Release(vs
);
19280 IDirect3DVertexDeclaration9_Release(vertex_declaration
);
19281 refcount
= IDirect3DDevice9_Release(device
);
19282 ok(!refcount
, "Device has %u references left.\n", refcount
);
19285 IDirect3D9_Release(d3d
);
19286 DestroyWindow(window
);
19289 static void test_table_fog_zw(void)
19292 IDirect3DDevice9
*device
;
19300 struct vec4 position
;
19305 {{ 0.0f
, 0.0f
, 0.0f
, 0.0f
}, 0xffff0000},
19306 {{640.0f
, 0.0f
, 0.0f
, 0.0f
}, 0xffff0000},
19307 {{ 0.0f
, 480.0f
, 0.0f
, 0.0f
}, 0xffff0000},
19308 {{640.0f
, 480.0f
, 0.0f
, 0.0f
}, 0xffff0000},
19310 static const D3DMATRIX identity
=
19312 1.0f
, 0.0f
, 0.0f
, 0.0f
,
19313 0.0f
, 1.0f
, 0.0f
, 0.0f
,
19314 0.0f
, 0.0f
, 1.0f
, 0.0f
,
19315 0.0f
, 0.0f
, 0.0f
, 1.0f
19317 static const struct
19320 D3DZBUFFERTYPE z_test
;
19325 {0.7f
, 0.0f
, D3DZB_TRUE
, 0x004cb200},
19326 {0.7f
, 0.0f
, D3DZB_FALSE
, 0x004cb200},
19327 {0.7f
, 0.3f
, D3DZB_TRUE
, 0x004cb200},
19328 {0.7f
, 0.3f
, D3DZB_FALSE
, 0x004cb200},
19329 {0.7f
, 3.0f
, D3DZB_TRUE
, 0x004cb200},
19330 {0.7f
, 3.0f
, D3DZB_FALSE
, 0x004cb200},
19331 {0.3f
, 0.0f
, D3DZB_TRUE
, 0x00b24c00},
19332 {0.3f
, 0.0f
, D3DZB_FALSE
, 0x00b24c00},
19336 window
= create_window();
19337 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
19338 ok(!!d3d
, "Failed to create a D3D object.\n");
19340 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
19342 skip("Failed to create a D3D device, skipping tests.\n");
19343 IDirect3D9_Release(d3d
);
19344 DestroyWindow(window
);
19348 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
19349 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
19350 if (!(caps
.RasterCaps
& D3DPRASTERCAPS_FOGTABLE
))
19352 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping POSITIONT table fog test.\n");
19356 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
19357 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
19358 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGENABLE
, TRUE
);
19359 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
19360 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGCOLOR
, 0x0000ff00);
19361 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
19362 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CLIPPING
, FALSE
);
19363 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
19364 /* Work around an AMD Windows driver bug. Needs a proj matrix applied redundantly. */
19365 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_PROJECTION
, &identity
);
19366 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
19367 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGTABLEMODE
, D3DFOG_LINEAR
);
19368 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
19369 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
);
19370 ok(SUCCEEDED(hr
), "Failed to set fvf, hr %#x.\n", hr
);
19372 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
19374 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x000000ff, 1.0f
, 0);
19375 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
19377 quad
[0].position
.z
= tests
[i
].z
;
19378 quad
[1].position
.z
= tests
[i
].z
;
19379 quad
[2].position
.z
= tests
[i
].z
;
19380 quad
[3].position
.z
= tests
[i
].z
;
19381 quad
[0].position
.w
= tests
[i
].w
;
19382 quad
[1].position
.w
= tests
[i
].w
;
19383 quad
[2].position
.w
= tests
[i
].w
;
19384 quad
[3].position
.w
= tests
[i
].w
;
19385 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, tests
[i
].z_test
);
19386 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
19388 hr
= IDirect3DDevice9_BeginScene(device
);
19389 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
19390 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(quad
[0]));
19391 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
19392 hr
= IDirect3DDevice9_EndScene(device
);
19393 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
19395 color
= getPixelColor(device
, 320, 240);
19396 ok(color_match(color
, tests
[i
].color
, 2),
19397 "Got unexpected color 0x%08x, expected 0x%08x, case %u.\n", color
, tests
[i
].color
, i
);
19398 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
19399 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
19403 refcount
= IDirect3DDevice9_Release(device
);
19404 ok(!refcount
, "Device has %u references left.\n", refcount
);
19405 IDirect3D9_Release(d3d
);
19406 DestroyWindow(window
);
19409 static void test_signed_formats(void)
19411 IDirect3DDevice9
*device
;
19414 unsigned int i
, j
, x
, y
;
19415 IDirect3DTexture9
*texture
, *texture_sysmem
;
19416 IDirect3DSurface9
*src_surface
, *dst_surface
;
19417 D3DLOCKED_RECT locked_rect
;
19418 IDirect3DPixelShader9
*shader
, *shader_alpha
;
19424 /* The input data was designed for D3DFMT_L6V5U5 and then transferred
19425 * to the other formats because L6V5U5 is the lowest precision format.
19426 * It tests the extreme values -1.0 (-16) and 1.0 (15) for U/V and
19427 * 0.0 (0) and 1.0 (63) for L, the neutral point 0 as well as -1 and 1.
19428 * Some other intermediate values are tested too. The input value -15
19429 * (min + 1) is tested as well. Unlike what OpenGL 4.4 says in section
19430 * 2.3.4.1, this value does not represent -1.0. In the interest of re-
19431 * using the expected output data the 8 bit and 16 bit values in V8U8
19432 * and V16U16 match (post-normalization) the 5 bit input values. Thus
19433 * -1, 1 and -127 are not tested in V8U8.
19435 * 8 bit specific values like -127 are tested in the Q channel of
19436 * D3DFMT_Q8W8V8U8. Here d3d seems to follow the rules from the GL
19437 * spec. AMD's r200 is broken though and returns a value < -1.0 for
19438 * -128. The difference between using -127 or -128 as the lowest
19439 * possible value gets lost in the slop of 1 though. */
19440 static const USHORT content_v8u8
[4][4] =
19442 {0x0000, 0x7f7f, 0x8880, 0x0000},
19443 {0x0080, 0x8000, 0x7f00, 0x007f},
19444 {0x193b, 0xe8c8, 0x0808, 0xf8f8},
19445 {0x4444, 0xc0c0, 0xa066, 0x22e0},
19447 static const DWORD content_v16u16
[4][4] =
19449 {0x00000000, 0x7fff7fff, 0x88008000, 0x00000000},
19450 {0x00008000, 0x80000000, 0x7fff0000, 0x00007fff},
19451 {0x19993bbb, 0xe800c800, 0x08880888, 0xf800f800},
19452 {0x44444444, 0xc000c000, 0xa0006666, 0x2222e000},
19454 static const DWORD content_q8w8v8u8
[4][4] =
19456 {0x00000000, 0xff7f7f7f, 0x7f008880, 0x817f0000},
19457 {0x10000080, 0x20008000, 0x30007f00, 0x4000007f},
19458 {0x5020193b, 0x6028e8c8, 0x70020808, 0x807ff8f8},
19459 {0x90414444, 0xa000c0c0, 0x8261a066, 0x834922e0},
19461 static const DWORD content_x8l8v8u8
[4][4] =
19463 {0x00000000, 0x00ff7f7f, 0x00008880, 0x00ff0000},
19464 {0x00000080, 0x00008000, 0x00007f00, 0x0000007f},
19465 {0x0041193b, 0x0051e8c8, 0x00040808, 0x00fff8f8},
19466 {0x00824444, 0x0000c0c0, 0x00c2a066, 0x009222e0},
19468 /* D3DFMT_L6V5U5 has poor precision on some GPUs. On a GeForce 7 the highest V and U value (15)
19469 * results in the output color 0xfb, which is 4 steps away from the correct value 0xff. It is
19470 * not the ~0xf0 you'd get if you blindly left-shifted the 5 bit value to form an 8 bit value
19473 * There may also be an off-by-one bug involved: The value -7 should result in the output 0x47,
19474 * but ends up as 0x4d. Likewise, -3 becomes 0x6e instead of 0x67. Those values are close to
19475 * the proper results of -6 and -2.
19477 * On Wine the emulation with unsigned R5G6B5 has poor precision, e.g. the signed 0 becomes 16,
19478 * and ((16 / 31) - 0.5) * 2.0 is 0.032 instead of 0.000. The final output result we read back
19479 * is 0x84 instead of 0x80. */
19480 static const USHORT content_l6v5u5
[4][4] =
19482 {0x0000, 0xfdef, 0x0230, 0xfc00},
19483 {0x0010, 0x0200, 0x01e0, 0x000f},
19484 {0x4067, 0x53b9, 0x0421, 0xffff},
19485 {0x8108, 0x0318, 0xc28c, 0x909c},
19487 static const struct
19491 const void *content
;
19494 unsigned int slop
, slop_broken
, alpha_broken
;
19498 {D3DFMT_V8U8
, "D3DFMT_V8U8", content_v8u8
, sizeof(WORD
), FALSE
, FALSE
, 1, 0, FALSE
},
19499 {D3DFMT_V16U16
, "D3DFMT_V16U16", content_v16u16
, sizeof(DWORD
), FALSE
, FALSE
, 1, 0, FALSE
},
19500 {D3DFMT_Q8W8V8U8
, "D3DFMT_Q8W8V8U8", content_q8w8v8u8
, sizeof(DWORD
), TRUE
, TRUE
, 1, 0, TRUE
},
19501 {D3DFMT_X8L8V8U8
, "D3DFMT_X8L8V8U8", content_x8l8v8u8
, sizeof(DWORD
), TRUE
, FALSE
, 1, 0, FALSE
},
19502 {D3DFMT_L6V5U5
, "D3DFMT_L6V5U5", content_l6v5u5
, sizeof(WORD
), TRUE
, FALSE
, 4, 7, FALSE
},
19504 static const struct
19513 {D3DPOOL_SYSTEMMEM
, 4, {1, 1, 2, 3}, {2, 0}},
19514 {D3DPOOL_SYSTEMMEM
, 1, {0, 1, 1, 3}, {0, 0}},
19515 {D3DPOOL_MANAGED
, 4, {1, 1, 2, 3}, {2, 0}},
19516 {D3DPOOL_MANAGED
, 1, {0, 1, 1, 3}, {0, 0}},
19518 static const DWORD shader_code
[] =
19520 0xffff0101, /* ps_1_1 */
19521 0x00000051, 0xa00f0000, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, /* def c0, 0.5, 0.5, 0,5, 0,5 */
19522 0x00000042, 0xb00f0000, /* tex t0 */
19523 0x00000004, 0x800f0000, 0xb0e40000, 0xa0e40000, 0xa0e40000, /* mad r0, t0, c0, c0 */
19524 0x0000ffff /* end */
19526 static const DWORD shader_code_alpha
[] =
19528 /* The idea of this shader is to replicate the alpha value in .rg, and set
19529 * blue to 1.0 iff the alpha value is < -1.0 and 0.0 otherwise. */
19530 0xffff0101, /* ps_1_1 */
19531 0x00000051, 0xa00f0000, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, /* def c0, 0.5, 0.5, 0.5, 0.5 */
19532 0x00000051, 0xa00f0001, 0x3f800000, 0x3f800000, 0x00000000, 0x3f800000, /* def c1, 1.0, 1.0, 0.0, 1.0 */
19533 0x00000051, 0xa00f0002, 0x00000000, 0x00000000, 0x3f800000, 0x00000000, /* def c2, 0.0, 0.0, 1.0, 0.0 */
19534 0x00000042, 0xb00f0000, /* tex t0 */
19535 0x00000004, 0x80070000, 0xb0ff0000, 0xa0e40000, 0xa0e40000, /* mad r0.rgb, t0.a, c0, c0 */
19536 0x00000003, 0x80080000, 0xb1ff0000, 0xa0e40000, /* sub r0.a, -t0.a, c0 */
19537 0x00000050, 0x80080000, 0x80ff0000, 0xa0ff0001, 0xa0ff0002, /* cnd r0.a, r0.a, c1.a, c2.a */
19538 0x00000005, 0x80070001, 0xa0e40001, 0x80e40000, /* mul r1.rgb, c1, r0 */
19539 0x00000004, 0x80070000, 0x80ff0000, 0xa0e40002, 0x80e40001, /* mad r0.rgb, r0.a, c2, r1 */
19540 0x0000ffff /* end */
19542 static const struct
19544 struct vec3 position
;
19545 struct vec2 texcrd
;
19549 /* Flip the y coordinate to make the input and
19550 * output arrays easier to compare. */
19551 {{ -1.0f
, -1.0f
, 0.0f
}, { 0.0f
, 1.0f
}},
19552 {{ -1.0f
, 1.0f
, 0.0f
}, { 0.0f
, 0.0f
}},
19553 {{ 1.0f
, -1.0f
, 0.0f
}, { 1.0f
, 1.0f
}},
19554 {{ 1.0f
, 1.0f
, 0.0f
}, { 1.0f
, 0.0f
}},
19556 static const D3DCOLOR expected_alpha
[4][4] =
19558 {0x00808000, 0x007f7f00, 0x00ffff00, 0x00000000},
19559 {0x00909000, 0x00a0a000, 0x00b0b000, 0x00c0c000},
19560 {0x00d0d000, 0x00e0e000, 0x00f0f000, 0x00000000},
19561 {0x00101000, 0x00202000, 0x00010100, 0x00020200},
19563 static const BOOL alpha_broken
[4][4] =
19565 {FALSE
, FALSE
, FALSE
, FALSE
},
19566 {FALSE
, FALSE
, FALSE
, FALSE
},
19567 {FALSE
, FALSE
, FALSE
, TRUE
},
19568 {FALSE
, FALSE
, FALSE
, FALSE
},
19570 static const D3DCOLOR expected_colors
[4][4] =
19572 {0x00808080, 0x00fefeff, 0x00010780, 0x008080ff},
19573 {0x00018080, 0x00800180, 0x0080fe80, 0x00fe8080},
19574 {0x00ba98a0, 0x004767a8, 0x00888881, 0x007878ff},
19575 {0x00c3c3c0, 0x003f3f80, 0x00e51fe1, 0x005fa2c8},
19577 static const D3DCOLOR expected_colors2
[4][4] =
19579 {0x00808080, 0x00fefeff, 0x00800180, 0x008080ff},
19580 {0x00018080, 0x00800180, 0x004767a8, 0x00fe8080},
19581 {0x00ba98a0, 0x004767a8, 0x00888881, 0x007878ff},
19582 {0x00c3c3c0, 0x003f3f80, 0x00e51fe1, 0x005fa2c8},
19584 static const D3DCOLOR expected_colors3
[4] =
19591 D3DCOLOR expected_color
;
19593 window
= create_window();
19594 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
19595 ok(!!d3d
, "Failed to create a D3D object.\n");
19597 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
19599 skip("Failed to create a D3D device, skipping tests.\n");
19600 IDirect3D9_Release(d3d
);
19601 DestroyWindow(window
);
19605 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
19606 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
19608 if (caps
.PixelShaderVersion
< D3DPS_VERSION(1, 1))
19610 skip("Pixel shaders not supported, skipping converted format test.\n");
19614 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_FALSE
);
19615 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
19616 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
19617 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
19618 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code
, &shader
);
19619 ok(SUCCEEDED(hr
), "Failed to create pixel shader, hr %#x.\n", hr
);
19620 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_alpha
, &shader_alpha
);
19621 ok(SUCCEEDED(hr
), "Failed to create pixel shader, hr %#x.\n", hr
);
19623 for (i
= 0; i
< ARRAY_SIZE(formats
); i
++)
19625 hr
= IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
19626 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_TEXTURE
, formats
[i
].format
);
19629 skip("Format %s not supported, skipping.\n", formats
[i
].name
);
19633 for (j
= 0; j
< ARRAY_SIZE(tests
); j
++)
19635 texture_sysmem
= NULL
;
19636 hr
= IDirect3DDevice9_CreateTexture(device
, tests
[j
].width
, 4, 1, 0,
19637 formats
[i
].format
, tests
[j
].pool
, &texture
, NULL
);
19638 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
19640 hr
= IDirect3DTexture9_LockRect(texture
, 0, &locked_rect
, NULL
, 0);
19641 ok(SUCCEEDED(hr
), "Failed to lock texture, hr %#x.\n", hr
);
19642 for (y
= 0; y
< 4; y
++)
19644 memcpy((char *)locked_rect
.pBits
+ y
* locked_rect
.Pitch
,
19645 (char *)formats
[i
].content
+ y
* 4 * formats
[i
].pixel_size
,
19646 tests
[j
].width
* formats
[i
].pixel_size
);
19648 hr
= IDirect3DTexture9_UnlockRect(texture
, 0);
19649 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x.\n", hr
);
19651 if (tests
[j
].pool
== D3DPOOL_SYSTEMMEM
)
19653 texture_sysmem
= texture
;
19654 hr
= IDirect3DDevice9_CreateTexture(device
, tests
[j
].width
, 4, 1, 0,
19655 formats
[i
].format
, D3DPOOL_DEFAULT
, &texture
, NULL
);
19656 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
19658 hr
= IDirect3DDevice9_UpdateTexture(device
, (IDirect3DBaseTexture9
*)texture_sysmem
,
19659 (IDirect3DBaseTexture9
*)texture
);
19660 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x.\n", hr
);
19663 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)texture
);
19664 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
19665 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_alpha
);
19666 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
19668 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00330033, 0.0f
, 0);
19669 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
19670 hr
= IDirect3DDevice9_BeginScene(device
);
19671 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
19672 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad
[0], sizeof(*quad
));
19673 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
19674 hr
= IDirect3DDevice9_EndScene(device
);
19675 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
19677 for (y
= 0; y
< 4; y
++)
19679 for (x
= 0; x
< tests
[j
].width
; x
++)
19681 BOOL r200_broken
= formats
[i
].alpha_broken
&& alpha_broken
[y
][x
];
19682 if (formats
[i
].alpha
)
19683 expected_color
= expected_alpha
[y
][x
];
19685 expected_color
= 0x00ffff00;
19687 color
= getPixelColor(device
, 80 + 160 * x
, 60 + 120 * y
);
19688 ok(color_match(color
, expected_color
, 1) || broken(r200_broken
),
19689 "Expected color 0x%08x, got 0x%08x, format %s, test %u, location %ux%u.\n",
19690 expected_color
, color
, formats
[i
].name
, j
, x
, y
);
19693 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
19694 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
19696 hr
= IDirect3DDevice9_SetPixelShader(device
, shader
);
19697 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
19699 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00330033, 0.0f
, 0);
19700 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
19701 hr
= IDirect3DDevice9_BeginScene(device
);
19702 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
19703 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad
[0], sizeof(*quad
));
19704 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
19705 hr
= IDirect3DDevice9_EndScene(device
);
19706 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
19708 for (y
= 0; y
< 4; y
++)
19710 for (x
= 0; x
< tests
[j
].width
; x
++)
19712 expected_color
= expected_colors
[y
][x
];
19713 if (!formats
[i
].blue
)
19714 expected_color
|= 0x000000ff;
19716 color
= getPixelColor(device
, 80 + 160 * x
, 60 + 120 * y
);
19717 ok(color_match(color
, expected_color
, formats
[i
].slop
)
19718 || broken(color_match(color
, expected_color
, formats
[i
].slop_broken
)),
19719 "Expected color 0x%08x, got 0x%08x, format %s, test %u, location %ux%u.\n",
19720 expected_color
, color
, formats
[i
].name
, j
, x
, y
);
19723 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
19724 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
19726 if (tests
[j
].pool
!= D3DPOOL_SYSTEMMEM
)
19728 IDirect3DTexture9_Release(texture
);
19732 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &dst_surface
);
19733 ok(SUCCEEDED(hr
), "Failed to get surface, hr %#x.\n", hr
);
19734 IDirect3DTexture9_GetSurfaceLevel(texture_sysmem
, 0, &src_surface
);
19735 ok(SUCCEEDED(hr
), "Failed to get surface, hr %#x.\n", hr
);
19737 hr
= IDirect3DDevice9_UpdateSurface(device
, src_surface
,
19738 &tests
[j
].src_rect
, dst_surface
, &tests
[j
].dst_point
);
19739 ok(SUCCEEDED(hr
), "Failed to update surface, hr %#x.\n", hr
);
19741 IDirect3DSurface9_Release(dst_surface
);
19742 IDirect3DSurface9_Release(src_surface
);
19744 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00003300, 0.0f
, 0);
19745 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
19746 hr
= IDirect3DDevice9_BeginScene(device
);
19747 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
19748 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad
[0], sizeof(*quad
));
19749 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
19750 hr
= IDirect3DDevice9_EndScene(device
);
19751 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
19753 for (y
= 0; y
< 4; y
++)
19755 for (x
= 0; x
< tests
[j
].width
; x
++)
19757 if (tests
[j
].width
== 4)
19758 expected_color
= expected_colors2
[y
][x
];
19760 expected_color
= expected_colors3
[y
];
19762 if (!formats
[i
].blue
)
19763 expected_color
|= 0x000000ff;
19765 color
= getPixelColor(device
, 80 + 160 * x
, 60 + 120 * y
);
19766 ok(color_match(color
, expected_color
, formats
[i
].slop
)
19767 || broken(color_match(color
, expected_color
, formats
[i
].slop_broken
)),
19768 "Expected color 0x%08x, got 0x%08x, format %s, test %u, location %ux%u.\n",
19769 expected_color
, color
, formats
[i
].name
, j
, x
, y
);
19772 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
19773 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
19775 IDirect3DTexture9_Release(texture_sysmem
);
19776 IDirect3DTexture9_Release(texture
);
19780 IDirect3DPixelShader9_Release(shader
);
19781 IDirect3DPixelShader9_Release(shader_alpha
);
19784 refcount
= IDirect3DDevice9_Release(device
);
19785 ok(!refcount
, "Device has %u references left.\n", refcount
);
19786 IDirect3D9_Release(d3d
);
19787 DestroyWindow(window
);
19790 static void test_multisample_mismatch(void)
19792 IDirect3DDevice9
*device
;
19798 IDirect3DSurface9
*rt
, *rt_multi
, *ds
;
19799 static const struct
19801 struct vec3 position
;
19806 {{ -1.0f
, -1.0f
, 0.0f
}, 0x000000ff},
19807 {{ -1.0f
, 1.0f
, 0.0f
}, 0x000000ff},
19808 {{ 1.0f
, -1.0f
, 1.0f
}, 0x000000ff},
19809 {{ 1.0f
, 1.0f
, 1.0f
}, 0x000000ff},
19812 window
= create_window();
19813 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
19814 ok(!!d3d
, "Failed to create a D3D object.\n");
19815 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
19816 D3DFMT_A8R8G8B8
, TRUE
, D3DMULTISAMPLE_2_SAMPLES
, NULL
)))
19818 skip("Multisampling not supported for D3DFMT_A8R8G8B8, skipping multisample mismatch test.\n");
19819 IDirect3D9_Release(d3d
);
19822 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
19823 D3DFMT_D24X8
, TRUE
, D3DMULTISAMPLE_2_SAMPLES
, NULL
)))
19825 skip("Multisampling not supported for D3DFMT_D24X8, skipping multisample mismatch test.\n");
19826 IDirect3D9_Release(d3d
);
19830 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
19832 skip("Failed to create a D3D device, skipping tests.\n");
19833 IDirect3D9_Release(d3d
);
19834 DestroyWindow(window
);
19838 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 640, 480, D3DFMT_A8R8G8B8
,
19839 D3DMULTISAMPLE_2_SAMPLES
, 0, FALSE
, &rt_multi
, NULL
);
19840 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
19842 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0x00000000, 0.1f
, 0);
19843 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
19845 hr
= IDirect3DDevice9_GetDepthStencilSurface(device
, &ds
);
19846 ok(SUCCEEDED(hr
), "Failed to set depth stencil, hr %#x.\n", hr
);
19847 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &rt
);
19848 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
19849 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt_multi
);
19850 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
19852 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
19853 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
19854 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, FALSE
);
19855 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
19857 /* Clear with incompatible buffers. Partial and combined clears. */
19858 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00ff0000, 0.0f
, 0);
19859 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
19860 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0x00000000, 0.3f
, 0);
19861 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
19862 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x0000ff00, 0.5f
, 0);
19863 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
19865 /* The color buffer is reliably cleared on AMD and Nvidia GPUs. */
19866 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt
);
19867 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
19868 hr
= IDirect3DDevice9_StretchRect(device
, rt_multi
, NULL
, rt
, NULL
, D3DTEXF_POINT
);
19869 ok(SUCCEEDED(hr
), "StretchRect failed, hr %#x.\n", hr
);
19870 color
= getPixelColor(device
, 320, 240);
19871 ok(color_match(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
19872 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
19873 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
19875 /* Check depth buffer values. AMD GPUs (r500 and evergreen tested) clear
19876 * the depth buffer like you'd expect in a correct framebuffer
19877 * setup. Nvidia doesn't clear it, neither in the Z only clear case nor in
19878 * the combined clear case.
19879 * In Wine we currently happen to allow the depth only clear case but
19880 * disallow the combined one. */
19881 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
19882 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
19883 hr
= IDirect3DDevice9_BeginScene(device
);
19884 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
19885 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
19886 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
19887 hr
= IDirect3DDevice9_EndScene(device
);
19888 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
19889 color
= getPixelColor(device
, 62, 240);
19890 ok(color_match(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
19891 color
= getPixelColor(device
, 64, 240);
19892 ok(color_match(color
, 0x0000ff00, 1) || color_match(color
, 0x000000ff, 1),
19893 "Got unexpected color 0x%08x.\n", color
);
19894 color
= getPixelColor(device
, 318, 240);
19895 ok(color_match(color
, 0x0000ff00, 1) || broken(color_match(color
, 0x000000ff, 1)),
19896 "Got unexpected color 0x%08x.\n", color
);
19897 color
= getPixelColor(device
, 322, 240);
19898 ok(color_match(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
19899 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
19900 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
19902 /* Draw with incompatible buffers. AMD even performs Z testing, and the Z test
19903 * results appear to be correct for this simple draw. Nvidia doesn't draw unless
19904 * the depth test is disabled. Setting ZFUNC = ALWAYS doesn't make the geometry
19905 * show up either. Only test the ZENABLE = FALSE case for now. */
19906 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_FALSE
);
19907 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
19908 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt_multi
);
19909 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
19910 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00ff0000, 0.0f
, 0);
19911 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
19912 hr
= IDirect3DDevice9_BeginScene(device
);
19913 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
19914 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
19915 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
19916 hr
= IDirect3DDevice9_EndScene(device
);
19917 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
19919 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt
);
19920 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
19921 hr
= IDirect3DDevice9_StretchRect(device
, rt_multi
, NULL
, rt
, NULL
, D3DTEXF_POINT
);
19922 ok(SUCCEEDED(hr
), "StretchRect failed, hr %#x.\n", hr
);
19923 color
= getPixelColor(device
, 320, 240);
19924 ok(color_match(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
19925 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
19926 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
19928 IDirect3DSurface9_Release(ds
);
19930 /* Test the reverse situation: Multisampled depth buffer, single sampled color buffer.
19931 * Color clears work as expected, AMD also clears the depth buffer, Nvidia does not. */
19932 hr
= IDirect3DDevice9_CreateDepthStencilSurface(device
, 640, 480, D3DFMT_D24X8
,
19933 D3DMULTISAMPLE_2_SAMPLES
, 0, FALSE
, &ds
, NULL
);
19934 ok(SUCCEEDED(hr
), "Failed to create depth/stencil, hr %#x.\n", hr
);
19935 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, ds
);
19936 ok(SUCCEEDED(hr
), "Failed to set depth stencil surface, hr %#x.\n", hr
);
19937 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt_multi
);
19938 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
19939 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x00ffff00, 0.1f
, 0);
19940 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
19942 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt
);
19943 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
19944 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00ff0000, 0.0f
, 0);
19945 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
19946 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0x00000000, 0.3f
, 0);
19947 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
19948 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x0000ff00, 0.5f
, 0);
19949 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
19951 color
= getPixelColor(device
, 320, 240);
19952 ok(color_match(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
19953 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
19954 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
19956 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt_multi
);
19957 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
19958 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_TRUE
);
19959 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
19960 hr
= IDirect3DDevice9_BeginScene(device
);
19961 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
19962 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
19963 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
19964 hr
= IDirect3DDevice9_EndScene(device
);
19965 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
19967 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt
);
19968 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
19969 hr
= IDirect3DDevice9_StretchRect(device
, rt_multi
, NULL
, rt
, NULL
, D3DTEXF_POINT
);
19970 ok(SUCCEEDED(hr
), "StretchRect failed, hr %#x.\n", hr
);
19971 color
= getPixelColor(device
, 62, 240);
19972 ok(color_match(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
19973 color
= getPixelColor(device
, 318, 240);
19974 ok(color_match(color
, 0x00ffff00, 1) || broken(color_match(color
, 0x000000ff, 1)),
19975 "Got unexpected color 0x%08x.\n", color
);
19976 color
= getPixelColor(device
, 322, 240);
19977 ok(color_match(color
, 0x00ffff00, 1), "Got unexpected color 0x%08x.\n", color
);
19978 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
19979 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
19981 /* Draw with a single sampled color buffer and a multisampled depth buffer. Again
19982 * AMD seems to perform correct Z testing, Nvidia doesn't draw unless the Z test
19983 * is disabled. Again only test the ZENABLE = FALSE case. */
19984 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00ff0000, 0.0f
, 0);
19985 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
19986 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_FALSE
);
19987 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
19988 hr
= IDirect3DDevice9_BeginScene(device
);
19989 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
19990 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
19991 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
19992 hr
= IDirect3DDevice9_EndScene(device
);
19993 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
19994 color
= getPixelColor(device
, 320, 240);
19995 ok(color_match(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
19996 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
19997 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
19999 IDirect3DSurface9_Release(rt
);
20000 IDirect3DSurface9_Release(ds
);
20001 IDirect3DSurface9_Release(rt_multi
);
20003 refcount
= IDirect3DDevice9_Release(device
);
20004 ok(!refcount
, "Device has %u references left.\n", refcount
);
20005 IDirect3D9_Release(d3d
);
20006 DestroyWindow(window
);
20009 static void test_texcoordindex(void)
20011 static const D3DMATRIX mat
=
20013 1.0f
, 0.0f
, 0.0f
, 0.0f
,
20014 0.0f
, 0.0f
, 0.0f
, 0.0f
,
20015 0.0f
, 0.0f
, 0.0f
, 0.0f
,
20016 0.0f
, 0.0f
, 0.0f
, 0.0f
,
20018 static const struct
20021 struct vec2 texcoord1
;
20022 struct vec2 texcoord2
;
20023 struct vec2 texcoord3
;
20027 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
}, {0.0f
, 0.0f
}, {1.0f
, 1.0f
}},
20028 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
}, {0.0f
, 1.0f
}, {1.0f
, 0.0f
}},
20029 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 1.0f
}, {1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
20030 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
}, {1.0f
, 1.0f
}, {0.0f
, 0.0f
}},
20032 IDirect3DDevice9
*device
;
20036 IDirect3DTexture9
*texture1
, *texture2
;
20037 D3DLOCKED_RECT locked_rect
;
20042 window
= create_window();
20043 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
20044 ok(!!d3d9
, "Failed to create a D3D object.\n");
20045 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
20047 skip("Failed to create a D3D device, skipping tests.\n");
20048 IDirect3D9_Release(d3d9
);
20049 DestroyWindow(window
);
20053 hr
= IDirect3DDevice9_CreateTexture(device
, 2, 2, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &texture1
, NULL
);
20054 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
20055 hr
= IDirect3DDevice9_CreateTexture(device
, 2, 2, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &texture2
, NULL
);
20056 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
20058 hr
= IDirect3DTexture9_LockRect(texture1
, 0, &locked_rect
, NULL
, D3DLOCK_DISCARD
);
20059 ok(SUCCEEDED(hr
), "Failed to lock texture, hr %#x.\n", hr
);
20060 ptr
= locked_rect
.pBits
;
20061 ptr
[0] = 0xff000000;
20062 ptr
[1] = 0xff00ff00;
20063 ptr
[2] = 0xff0000ff;
20064 ptr
[3] = 0xff00ffff;
20065 hr
= IDirect3DTexture9_UnlockRect(texture1
, 0);
20066 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x.\n", hr
);
20068 hr
= IDirect3DTexture9_LockRect(texture2
, 0, &locked_rect
, NULL
, D3DLOCK_DISCARD
);
20069 ok(SUCCEEDED(hr
), "Failed to lock texture, hr %#x.\n", hr
);
20070 ptr
= locked_rect
.pBits
;
20071 ptr
[0] = 0xff000000;
20072 ptr
[1] = 0xff0000ff;
20073 ptr
[2] = 0xffff0000;
20074 ptr
[3] = 0xffff00ff;
20075 hr
= IDirect3DTexture9_UnlockRect(texture2
, 0);
20076 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x.\n", hr
);
20078 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)texture1
);
20079 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
20080 hr
= IDirect3DDevice9_SetTexture(device
, 1, (IDirect3DBaseTexture9
*)texture2
);
20081 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
20082 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX3
);
20083 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
20084 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
20085 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
20086 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
20087 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
20088 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
20089 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
20090 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_ADD
);
20091 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
20092 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
20093 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
20094 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLORARG2
, D3DTA_CURRENT
);
20095 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
20096 hr
= IDirect3DDevice9_SetTextureStageState(device
, 2, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
20097 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
20099 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXCOORDINDEX
, 1);
20100 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
20101 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_TEXCOORDINDEX
, 0);
20102 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
20104 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffff00, 1.0f
, 0);
20105 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
20107 hr
= IDirect3DDevice9_BeginScene(device
);
20108 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
20109 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
20110 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
20111 hr
= IDirect3DDevice9_EndScene(device
);
20112 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
20114 color
= getPixelColor(device
, 160, 120);
20115 ok(color_match(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
20116 color
= getPixelColor(device
, 480, 120);
20117 ok(color_match(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
20118 color
= getPixelColor(device
, 160, 360);
20119 ok(color_match(color
, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color
);
20120 color
= getPixelColor(device
, 480, 360);
20121 ok(color_match(color
, 0x00ffffff, 2), "Got unexpected color 0x%08x.\n", color
);
20123 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT2
);
20124 ok(SUCCEEDED(hr
), "Failed to set texture transform flags, hr %#x.\n", hr
);
20125 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE1
, &mat
);
20126 ok(SUCCEEDED(hr
), "Failed to set transformation matrix, hr %#x.\n", hr
);
20128 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffff00, 1.0f
, 0);
20129 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
20131 hr
= IDirect3DDevice9_BeginScene(device
);
20132 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
20133 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
20134 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
20135 hr
= IDirect3DDevice9_EndScene(device
);
20136 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
20138 color
= getPixelColor(device
, 160, 120);
20139 ok(color_match(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
20140 color
= getPixelColor(device
, 480, 120);
20141 ok(color_match(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
20142 color
= getPixelColor(device
, 160, 360);
20143 ok(color_match(color
, 0x00000000, 2), "Got unexpected color 0x%08x.\n", color
);
20144 color
= getPixelColor(device
, 480, 360);
20145 ok(color_match(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
20147 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_DISABLE
);
20148 ok(SUCCEEDED(hr
), "Failed to set texture transform flags, hr %#x.\n", hr
);
20149 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_TEXCOORDINDEX
, 2);
20150 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
20152 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffff00, 1.0f
, 0);
20153 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
20155 hr
= IDirect3DDevice9_BeginScene(device
);
20156 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
20157 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
20158 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
20159 hr
= IDirect3DDevice9_EndScene(device
);
20160 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
20162 color
= getPixelColor(device
, 160, 120);
20163 ok(color_match(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
20164 color
= getPixelColor(device
, 480, 120);
20165 ok(color_match(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
20166 color
= getPixelColor(device
, 160, 360);
20167 ok(color_match(color
, 0x00ff00ff, 2), "Got unexpected color 0x%08x.\n", color
);
20168 color
= getPixelColor(device
, 480, 360);
20169 ok(color_match(color
, 0x00ffff00, 2), "Got unexpected color 0x%08x.\n", color
);
20171 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
20172 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
20174 IDirect3DTexture9_Release(texture1
);
20175 IDirect3DTexture9_Release(texture2
);
20177 refcount
= IDirect3DDevice9_Release(device
);
20178 ok(!refcount
, "Device has %u references left.\n", refcount
);
20179 IDirect3D9_Release(d3d9
);
20180 DestroyWindow(window
);
20183 static void test_vertex_blending(void)
20185 IDirect3DVertexDeclaration9
*vertex_declaration
;
20186 IDirect3DDevice9
*device
;
20195 static const D3DMATRIX view_mat
=
20197 2.0f
/ 10.0f
, 0.0f
, 0.0f
, 0.0f
,
20198 0.0f
, 2.0f
/ 10.0f
, 0.0f
, 0.0f
,
20199 0.0f
, 0.0f
, 1.0f
, 0.0f
,
20200 0.0f
, 0.0f
, 0.0f
, 1.0f
20204 1.0f
, 0.0f
, 0.0f
, 0.0f
,
20205 0.0f
, 1.0f
, 0.0f
, 0.0f
,
20206 0.0f
, 0.0f
, 1.0f
, 0.0f
,
20207 -4.0f
, 4.0f
, 0.0f
, 1.0f
20211 1.0f
, 0.0f
, 0.0f
, 0.0f
,
20212 0.0f
, 1.0f
, 0.0f
, 0.0f
,
20213 0.0f
, 0.0f
, 1.0f
, 0.0f
,
20214 -4.0f
, -4.0f
, 0.0f
, 1.0f
20218 1.0f
, 0.0f
, 0.0f
, 0.0f
,
20219 0.0f
, 1.0f
, 0.0f
, 0.0f
,
20220 0.0f
, 0.0f
, 1.0f
, 0.0f
,
20221 4.0f
, 4.0f
, 0.0f
, 1.0f
20225 1.0f
, 0.0f
, 0.0f
, 0.0f
,
20226 0.0f
, 1.0f
, 0.0f
, 0.0f
,
20227 0.0f
, 0.0f
, 1.0f
, 0.0f
,
20228 4.0f
, -4.0f
, 0.0f
, 1.0f
20231 static const POINT quad_upper_right_points
[] =
20233 {576, 48}, {-1, -1},
20235 quad_upper_right_empty_points
[] =
20237 {64, 48}, {64, 432}, {576, 432}, {320, 240}, {-1, -1}
20239 quad_center_points
[] =
20241 {320, 240}, {-1, -1}
20243 quad_center_empty_points
[] =
20245 {64, 48}, {576, 48}, {64, 432}, {576, 432}, {-1, -1}
20247 quad_upper_center_points
[] =
20249 {320, 48}, {-1, -1}
20251 quad_upper_center_empty_points
[] =
20253 {320, 240}, {64, 48}, {576, 48}, {-1, -1}
20255 quad_fullscreen_points
[] =
20257 {320, 48}, {320, 240}, {64, 48}, {576, 48}, {64, 432}, {576, 432}, {-1, -1}
20259 quad_fullscreen_empty_points
[] =
20264 static const struct
20267 D3DVERTEXELEMENT9 decl_elements
[3];
20272 struct vec3 position
;
20273 struct vec3 blendweights
;
20275 vertex_data_float
[4];
20278 struct vec3 position
;
20279 D3DCOLOR blendweights
;
20281 vertex_data_d3dcolor
[4];
20283 const POINT
*quad_points
;
20284 const POINT
*empty_points
;
20292 {{{{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 0.0f
, 0.0f
}},
20293 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
, 0.0f
}},
20294 {{ 1.0f
, -1.0f
, 0.0f
}, {0.0f
, 0.0f
, 0.0f
}},
20295 {{ 1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
, 0.0f
}}}},
20296 quad_upper_right_points
, quad_upper_right_empty_points
20302 {{{{-1.0f
, -1.0f
, 0.0f
}, {0.25f
, 0.25f
, 0.25f
}},
20303 {{-1.0f
, 1.0f
, 0.0f
}, {0.25f
, 0.25f
, 0.25f
}},
20304 {{ 1.0f
, -1.0f
, 0.0f
}, {0.25f
, 0.25f
, 0.25f
}},
20305 {{ 1.0f
, 1.0f
, 0.0f
}, {0.25f
, 0.25f
, 0.25f
}}}},
20306 quad_center_points
, quad_center_empty_points
20312 {{{{-1.0f
, -1.0f
, 0.0f
}, {0.5f
, 0.0f
, 0.0f
}},
20313 {{-1.0f
, 1.0f
, 0.0f
}, {0.5f
, 0.0f
, 0.0f
}},
20314 {{ 1.0f
, -1.0f
, 0.0f
}, {0.5f
, 0.0f
, 0.0f
}},
20315 {{ 1.0f
, 1.0f
, 0.0f
}, {0.5f
, 0.0f
, 0.0f
}}}},
20316 quad_upper_center_points
, quad_upper_center_empty_points
20322 {{{{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
, 0.0f
}},
20323 {{-1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}},
20324 {{ 1.0f
, -1.0f
, 0.0f
}, {0.0f
, 0.0f
, 1.0f
}},
20325 {{ 1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
, 0.0f
}}}},
20326 quad_fullscreen_points
, quad_fullscreen_empty_points
20328 /* D3DCOLOR, full screen */
20332 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
20333 {0, 12, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_BLENDWEIGHT
, 0},
20337 {{{-1.0f
, -1.0f
, 0.0f
}, 0x0000ff00},
20338 {{-1.0f
, 1.0f
, 0.0f
}, 0x00ff0000},
20339 {{ 1.0f
, -1.0f
, 0.0f
}, 0x000000ff},
20340 {{ 1.0f
, 1.0f
, 0.0f
}, 0x00000000}}},
20341 quad_fullscreen_points
, quad_fullscreen_empty_points
20345 window
= create_window();
20346 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
20347 ok(!!d3d
, "Failed to create a D3D object.\n");
20348 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
20350 skip("Failed to create a D3D device, skipping tests.\n");
20354 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
20355 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
20356 if (caps
.MaxVertexBlendMatrices
< 4)
20358 skip("Only %u vertex blend matrices supported, skipping tests.\n", caps
.MaxVertexBlendMatrices
);
20359 IDirect3DDevice9_Release(device
);
20363 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
20364 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
20366 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_VIEW
, &view_mat
);
20367 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform returned %08x\n", hr
);
20369 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_WORLDMATRIX(0), &upper_left
);
20370 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform returned %08x\n", hr
);
20371 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_WORLDMATRIX(1), &lower_left
);
20372 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform returned %08x\n", hr
);
20373 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_WORLDMATRIX(2), &lower_right
);
20374 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform returned %08x\n", hr
);
20375 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_WORLDMATRIX(3), &upper_right
);
20376 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform returned %08x\n", hr
);
20378 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_VERTEXBLEND
, D3DVBF_3WEIGHTS
);
20379 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed %08x\n", hr
);
20381 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
20383 const POINT
*point
;
20387 hr
= IDirect3DDevice9_SetFVF(device
, tests
[i
].fvf
);
20388 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
20389 vertex_declaration
= NULL
;
20393 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, tests
[i
].decl_elements
, &vertex_declaration
);
20394 ok(SUCCEEDED(hr
), "Failed to create vertex declaration, hr %#x.\n", hr
);
20395 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, vertex_declaration
);
20396 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
20399 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff000000, 0.0, 0);
20400 ok(SUCCEEDED(hr
), "Failed to clear %08x\n", hr
);
20402 hr
= IDirect3DDevice9_BeginScene(device
);
20403 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
20406 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2,
20407 tests
[i
].s
.vertex_data_float
, sizeof(*tests
[i
].s
.vertex_data_float
));
20409 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2,
20410 tests
[i
].s
.vertex_data_d3dcolor
, sizeof(*tests
[i
].s
.vertex_data_d3dcolor
));
20411 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
20413 hr
= IDirect3DDevice9_EndScene(device
);
20414 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
20416 point
= tests
[i
].quad_points
;
20417 while (point
->x
!= -1 && point
->y
!= -1)
20419 color
= getPixelColor(device
, point
->x
, point
->y
);
20420 ok(color_match(color
, 0x00ffffff, 1), "Expected quad at %dx%d.\n", point
->x
, point
->y
);
20424 point
= tests
[i
].empty_points
;
20425 while (point
->x
!= -1 && point
->y
!= -1)
20427 color
= getPixelColor(device
, point
->x
, point
->y
);
20428 ok(color_match(color
, 0x00000000, 1), "Unexpected quad at %dx%d.\n", point
->x
, point
->y
);
20432 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
20433 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
20435 if (vertex_declaration
)
20436 IDirect3DVertexDeclaration9_Release(vertex_declaration
);
20439 refcount
= IDirect3DDevice9_Release(device
);
20440 ok(!refcount
, "Device has %u references left.\n", refcount
);
20443 IDirect3D9_Release(d3d
);
20444 DestroyWindow(window
);
20447 static void test_updatetexture(void)
20449 BOOL r32f_supported
, ati2n_supported
, do_visual_test
;
20450 IDirect3DBaseTexture9
*src
, *dst
;
20451 unsigned int t
, i
, f
, l
, x
, y
, z
;
20452 D3DLOCKED_RECT locked_rect
;
20453 D3DLOCKED_BOX locked_box
;
20454 IDirect3DDevice9
*device
;
20461 static const struct
20464 struct vec2 texcoord
;
20468 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
20469 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
}},
20470 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 1.0f
}},
20471 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
}},
20473 static const struct
20476 struct vec3 texcoord
;
20480 {{-1.0f
, -1.0f
, 0.0f
}, {1.0f
, -0.5f
, 0.5f
}},
20481 {{-1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.5f
, 0.5f
}},
20482 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, -0.5f
, -0.5f
}},
20483 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.5f
, -0.5f
}},
20485 static const struct
20487 UINT src_width
, src_height
;
20488 UINT dst_width
, dst_height
;
20489 UINT src_levels
, dst_levels
;
20490 D3DFORMAT src_format
, dst_format
;
20495 {8, 8, 8, 8, 0, 0, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
, FALSE
}, /* 0 */
20496 {8, 8, 8, 8, 4, 4, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
, FALSE
}, /* 1 */
20497 {8, 8, 8, 8, 2, 2, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
, FALSE
}, /* 2 */
20498 {8, 8, 8, 8, 1, 1, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
, FALSE
}, /* 3 */
20499 {8, 8, 8, 8, 4, 0, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
, FALSE
}, /* 4 */
20500 {8, 8, 2, 2, 4, 2, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
, FALSE
}, /* 5 */
20501 /* The WARP renderer doesn't handle these cases correctly. */
20502 {8, 8, 8, 8, 4, 2, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
, TRUE
}, /* 6 */
20503 {8, 8, 4, 4, 4, 2, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
, TRUE
}, /* 7 */
20504 /* Not clear what happens here on Windows, it doesn't make much sense
20505 * though (on Nvidia it seems to upload the 4x4 surface into the 7x7
20506 * one or something like that). */
20507 /* {8, 8, 7, 7, 4, 2, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, FALSE}, */
20508 {8, 8, 8, 8, 1, 4, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
, FALSE
}, /* 8 */
20509 {4, 4, 8, 8, 1, 1, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
, FALSE
}, /* 9 */
20510 /* This one causes weird behavior on Windows (it probably writes out
20511 * of the texture memory). */
20512 /* {8, 8, 4, 4, 1, 1, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, FALSE}, */
20513 {8, 4, 4, 2, 4, 2, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
, FALSE
}, /* 10 */
20514 {8, 4, 2, 4, 4, 2, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
, FALSE
}, /* 11 */
20515 {8, 8, 8, 8, 4, 4, D3DFMT_A8R8G8B8
, D3DFMT_X8R8G8B8
, FALSE
}, /* 12 */
20516 {8, 8, 8, 8, 4, 4, D3DFMT_X8R8G8B8
, D3DFMT_A8R8G8B8
, FALSE
}, /* 13 */
20517 /* The data is converted correctly on AMD, on Nvidia nothing happens
20518 * (it draws a black quad). */
20519 {8, 8, 8, 8, 4, 4, D3DFMT_A8R8G8B8
, D3DFMT_R5G6B5
, TRUE
}, /* 14 */
20520 /* Here the data is converted on AMD, just copied and "reinterpreted" as
20521 * a 32 bit float on Nvidia (specifically the tested value becomes a
20522 * very small float number which we get as 0 in the test). */
20523 {8, 8, 8, 8, 4, 4, D3DFMT_A8R8G8B8
, D3DFMT_R32F
, TRUE
}, /* 15 */
20524 /* This one doesn't seem to give the expected results on AMD. */
20525 /* {8, 8, 8, 8, 4, 4, D3DFMT_A8R8G8B8, D3DFMT_Q8W8V8U8, FALSE}, */
20526 {8, 8, 8, 8, 4, 4, MAKEFOURCC('A','T','I','2'), MAKEFOURCC('A','T','I','2'), FALSE
}, /* 16 */
20527 {8, 8, 8, 8, 4, 2, MAKEFOURCC('A','T','I','2'), MAKEFOURCC('A','T','I','2'), FALSE
}, /* 17 */
20528 {8, 8, 2, 2, 4, 2, MAKEFOURCC('A','T','I','2'), MAKEFOURCC('A','T','I','2'), FALSE
}, /* 18 */
20530 static const struct
20532 D3DRESOURCETYPE type
;
20535 unsigned int vertex_size
;
20541 {D3DRTYPE_TEXTURE
, D3DFVF_XYZ
| D3DFVF_TEX1
,
20542 quad
, sizeof(*quad
), D3DPTEXTURECAPS_MIPMAP
, "2D mipmapped"},
20544 {D3DRTYPE_CUBETEXTURE
, D3DFVF_XYZ
| D3DFVF_TEX1
| D3DFVF_TEXCOORDSIZE3(0),
20545 quad_cube_tex
, sizeof(*quad_cube_tex
), D3DPTEXTURECAPS_CUBEMAP
, "Cube"},
20547 {D3DRTYPE_VOLUMETEXTURE
, D3DFVF_XYZ
| D3DFVF_TEX1
,
20548 quad
, sizeof(*quad
), D3DPTEXTURECAPS_VOLUMEMAP
, "Volume"}
20551 window
= create_window();
20552 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
20553 ok(!!d3d9
, "Failed to create a D3D object.\n");
20554 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
20556 skip("Failed to create a D3D device, skipping tests.\n");
20557 IDirect3D9_Release(d3d9
);
20558 DestroyWindow(window
);
20562 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
20563 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
20565 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAGFILTER
, D3DTEXF_LINEAR
);
20566 ok(SUCCEEDED(hr
), "Failed to set texture filtering state, hr %#x.\n", hr
);
20567 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSU
, D3DTADDRESS_CLAMP
);
20568 ok(SUCCEEDED(hr
), "Failed to set texture clamping state, hr %#x.\n", hr
);
20569 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSV
, D3DTADDRESS_CLAMP
);
20570 ok(SUCCEEDED(hr
), "Failed to set texture clamping state, hr %#x.\n", hr
);
20571 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSW
, D3DTADDRESS_CLAMP
);
20572 ok(SUCCEEDED(hr
), "Failed to set texture clamping state, hr %#x.\n", hr
);
20573 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
20574 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
20575 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
20576 ok(hr
== D3D_OK
, "Failed to set texture stage state, hr %#x.\n", hr
);
20577 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
20578 ok(hr
== D3D_OK
, "Failed to set texture stage state, hr %#x.\n", hr
);
20580 for (t
= 0; t
< ARRAY_SIZE(texture_types
); ++t
)
20582 if (!(caps
.TextureCaps
& texture_types
[t
].cap
))
20584 skip("%s textures not supported, skipping some tests.\n", texture_types
[t
].name
);
20587 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
20588 D3DFMT_X8R8G8B8
, D3DUSAGE_QUERY_FILTER
, texture_types
[t
].type
, D3DFMT_A8R8G8B8
)))
20590 skip("%s D3DFMT_A8R8G8B8 texture filtering is not supported, skipping some tests.\n",
20591 texture_types
[t
].name
);
20594 r32f_supported
= TRUE
;
20595 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
20596 D3DFMT_X8R8G8B8
, D3DUSAGE_QUERY_FILTER
, texture_types
[t
].type
, D3DFMT_R32F
)))
20598 skip("%s R32F textures are not supported, skipping some tests.\n", texture_types
[t
].name
);
20599 r32f_supported
= FALSE
;
20601 ati2n_supported
= TRUE
;
20602 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
20603 D3DFMT_X8R8G8B8
, D3DUSAGE_QUERY_FILTER
, texture_types
[t
].type
, MAKEFOURCC('A','T','I','2'))))
20605 skip("%s ATI2N textures are not supported, skipping some tests.\n", texture_types
[t
].name
);
20606 ati2n_supported
= FALSE
;
20609 hr
= IDirect3DDevice9_SetFVF(device
, texture_types
[t
].fvf
);
20610 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
20612 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
20614 if (tests
[i
].dst_format
== D3DFMT_R32F
&& !r32f_supported
)
20616 if (tests
[i
].dst_format
== MAKEFOURCC('A','T','I','2') && !ati2n_supported
)
20619 switch (texture_types
[t
].type
)
20621 case D3DRTYPE_TEXTURE
:
20622 hr
= IDirect3DDevice9_CreateTexture(device
,
20623 tests
[i
].src_width
, tests
[i
].src_height
,
20624 tests
[i
].src_levels
, 0, tests
[i
].src_format
, D3DPOOL_SYSTEMMEM
,
20625 (IDirect3DTexture9
**)&src
, NULL
);
20626 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x, case %u, %u.\n", hr
, t
, i
);
20627 hr
= IDirect3DDevice9_CreateTexture(device
,
20628 tests
[i
].dst_width
, tests
[i
].dst_height
,
20629 tests
[i
].dst_levels
, 0, tests
[i
].dst_format
, D3DPOOL_DEFAULT
,
20630 (IDirect3DTexture9
**)&dst
, NULL
);
20631 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x, case %u, %u.\n", hr
, t
, i
);
20633 case D3DRTYPE_CUBETEXTURE
:
20634 hr
= IDirect3DDevice9_CreateCubeTexture(device
,
20635 tests
[i
].src_width
,
20636 tests
[i
].src_levels
, 0, tests
[i
].src_format
, D3DPOOL_SYSTEMMEM
,
20637 (IDirect3DCubeTexture9
**)&src
, NULL
);
20638 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x, case %u, %u.\n", hr
, t
, i
);
20639 hr
= IDirect3DDevice9_CreateCubeTexture(device
,
20640 tests
[i
].dst_width
,
20641 tests
[i
].dst_levels
, 0, tests
[i
].dst_format
, D3DPOOL_DEFAULT
,
20642 (IDirect3DCubeTexture9
**)&dst
, NULL
);
20643 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x, case %u, %u.\n", hr
, t
, i
);
20645 case D3DRTYPE_VOLUMETEXTURE
:
20646 hr
= IDirect3DDevice9_CreateVolumeTexture(device
,
20647 tests
[i
].src_width
, tests
[i
].src_height
, tests
[i
].src_width
,
20648 tests
[i
].src_levels
, 0, tests
[i
].src_format
, D3DPOOL_SYSTEMMEM
,
20649 (IDirect3DVolumeTexture9
**)&src
, NULL
);
20650 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x, case %u, %u.\n", hr
, t
, i
);
20651 hr
= IDirect3DDevice9_CreateVolumeTexture(device
,
20652 tests
[i
].dst_width
, tests
[i
].dst_height
, tests
[i
].dst_width
,
20653 tests
[i
].dst_levels
, 0, tests
[i
].dst_format
, D3DPOOL_DEFAULT
,
20654 (IDirect3DVolumeTexture9
**)&dst
, NULL
);
20655 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x, case %u, %u.\n", hr
, t
, i
);
20658 trace("Unexpected resource type.\n");
20661 /* Skip the visual part of the test for ATI2N (laziness) and cases that
20662 * give a different (and unlikely to be useful) result. */
20663 do_visual_test
= (tests
[i
].src_format
== D3DFMT_A8R8G8B8
|| tests
[i
].src_format
== D3DFMT_X8R8G8B8
)
20664 && tests
[i
].src_levels
!= 0
20665 && tests
[i
].src_width
>= tests
[i
].dst_width
&& tests
[i
].src_height
>= tests
[i
].dst_height
20666 && !(tests
[i
].src_width
> tests
[i
].src_height
&& tests
[i
].dst_width
< tests
[i
].dst_height
);
20668 if (do_visual_test
)
20671 unsigned int width
, height
, depth
, row_pitch
= 0, slice_pitch
= 0;
20673 for (f
= 0; f
< (texture_types
[t
].type
== D3DRTYPE_CUBETEXTURE
? 6 : 1); ++f
)
20675 width
= tests
[i
].src_width
;
20676 height
= texture_types
[t
].type
!= D3DRTYPE_CUBETEXTURE
? tests
[i
].src_height
: tests
[i
].src_width
;
20677 depth
= texture_types
[t
].type
== D3DRTYPE_VOLUMETEXTURE
? width
: 1;
20679 for (l
= 0; l
< tests
[i
].src_levels
; ++l
)
20681 switch (texture_types
[t
].type
)
20683 case D3DRTYPE_TEXTURE
:
20684 hr
= IDirect3DTexture9_LockRect((IDirect3DTexture9
*)src
,
20685 l
, &locked_rect
, NULL
, 0);
20686 ptr
= locked_rect
.pBits
;
20687 row_pitch
= locked_rect
.Pitch
/ sizeof(*ptr
);
20689 case D3DRTYPE_CUBETEXTURE
:
20690 hr
= IDirect3DCubeTexture9_LockRect((IDirect3DCubeTexture9
*)src
,
20691 f
, l
, &locked_rect
, NULL
, 0);
20692 ptr
= locked_rect
.pBits
;
20693 row_pitch
= locked_rect
.Pitch
/ sizeof(*ptr
);
20695 case D3DRTYPE_VOLUMETEXTURE
:
20696 hr
= IDirect3DVolumeTexture9_LockBox((IDirect3DVolumeTexture9
*)src
,
20697 l
, &locked_box
, NULL
, 0);
20698 ptr
= locked_box
.pBits
;
20699 row_pitch
= locked_box
.RowPitch
/ sizeof(*ptr
);
20700 slice_pitch
= locked_box
.SlicePitch
/ sizeof(*ptr
);
20703 trace("Unexpected resource type.\n");
20705 ok(SUCCEEDED(hr
), "Failed to lock texture, hr %#x.\n", hr
);
20707 for (z
= 0; z
< depth
; ++z
)
20709 for (y
= 0; y
< height
; ++y
)
20711 for (x
= 0; x
< width
; ++x
)
20713 ptr
[z
* slice_pitch
+ y
* row_pitch
+ x
] = 0xff000000
20714 | (DWORD
)(x
/ (width
- 1.0f
) * 255.0f
) << 16
20715 | (DWORD
)(y
/ (height
- 1.0f
) * 255.0f
) << 8;
20720 switch (texture_types
[t
].type
)
20722 case D3DRTYPE_TEXTURE
:
20723 hr
= IDirect3DTexture9_UnlockRect((IDirect3DTexture9
*)src
, l
);
20725 case D3DRTYPE_CUBETEXTURE
:
20726 hr
= IDirect3DCubeTexture9_UnlockRect((IDirect3DCubeTexture9
*)src
, f
, l
);
20728 case D3DRTYPE_VOLUMETEXTURE
:
20729 hr
= IDirect3DVolumeTexture9_UnlockBox((IDirect3DVolumeTexture9
*)src
, l
);
20732 trace("Unexpected resource type.\n");
20734 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x.\n", hr
);
20749 hr
= IDirect3DDevice9_UpdateTexture(device
, src
, dst
);
20752 todo_wine
ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x, case %u, %u.\n", hr
, t
, i
);
20753 IDirect3DBaseTexture9_Release(src
);
20754 IDirect3DBaseTexture9_Release(dst
);
20757 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x, case %u, %u.\n", hr
, t
, i
);
20759 if (do_visual_test
)
20761 hr
= IDirect3DDevice9_SetTexture(device
, 0, dst
);
20762 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
20764 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff0000ff, 1.0f
, 0);
20765 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
20767 hr
= IDirect3DDevice9_BeginScene(device
);
20768 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
20769 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2,
20770 texture_types
[t
].quad
, texture_types
[t
].vertex_size
);
20771 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
20772 hr
= IDirect3DDevice9_EndScene(device
);
20773 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
20775 color
= getPixelColor(device
, 320, 240);
20776 ok (color_match(color
, 0x007f7f00, 3) || broken(tests
[i
].broken
)
20777 || broken(color
== 0x00adbeef), /* WARP device often just breaks down. */
20778 "Got unexpected color 0x%08x, case %u, %u.\n", color
, t
, i
);
20781 IDirect3DBaseTexture9_Release(src
);
20782 IDirect3DBaseTexture9_Release(dst
);
20785 refcount
= IDirect3DDevice9_Release(device
);
20786 ok(!refcount
, "Device has %u references left.\n", refcount
);
20787 IDirect3D9_Release(d3d9
);
20788 DestroyWindow(window
);
20791 static void test_depthbias(void)
20793 IDirect3DDevice9
*device
;
20795 IDirect3DSurface9
*ds
;
20802 static const D3DFORMAT formats
[] =
20804 D3DFMT_D16
, D3DFMT_D24X8
, D3DFMT_D32
, D3DFMT_D24S8
, MAKEFOURCC('I','N','T','Z'),
20806 /* The scaling factor detection function detects the wrong factor for
20807 * float formats on Nvidia, therefore the following tests are disabled.
20808 * The wined3d function detects 2^23 like for fixed point formats but
20809 * the test needs 2^22 to pass.
20811 * AMD GPUs need a different scaling factor for float depth buffers
20812 * (2^24) than fixed point (2^23), but the wined3d detection function
20813 * works there, producing the right result in the test.
20815 * D3DFMT_D32F_LOCKABLE, D3DFMT_D24FS8,
20819 static const struct
20821 struct vec3 position
;
20825 {{-1.0f
, -1.0f
, 0.0f
}},
20826 {{-1.0f
, 1.0f
, 0.0f
}},
20827 {{ 1.0f
, -1.0f
, 1.0f
}},
20828 {{ 1.0f
, 1.0f
, 1.0f
}},
20836 window
= create_window();
20837 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
20838 ok(!!d3d
, "Failed to create a D3D object.\n");
20839 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
20841 skip("Failed to create a D3D device, skipping tests.\n");
20845 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
20846 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
20847 if (!(caps
.RasterCaps
& D3DPRASTERCAPS_DEPTHBIAS
))
20849 IDirect3DDevice9_Release(device
);
20850 skip("D3DPRASTERCAPS_DEPTHBIAS not supported.\n");
20854 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
20855 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
20856 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, FALSE
);
20857 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %08x\n", hr
);
20858 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
20859 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
20860 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TFACTOR
);
20861 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
20862 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
20863 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
20865 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
)
20867 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
20868 D3DFMT_X8R8G8B8
, D3DUSAGE_DEPTHSTENCIL
, D3DRTYPE_SURFACE
, formats
[i
])))
20870 skip("Depth format %u not supported, skipping.\n", formats
[i
]);
20874 hr
= IDirect3DDevice9_CreateDepthStencilSurface(device
, 640, 480, formats
[i
],
20875 D3DMULTISAMPLE_NONE
, 0, FALSE
, &ds
, NULL
);
20876 ok(SUCCEEDED(hr
), "Failed to create depth stencil surface, hr %#x.\n", hr
);
20877 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, ds
);
20878 ok(SUCCEEDED(hr
), "Failed to set depth stencil surface, hr %#x.\n", hr
);
20879 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x00000000, 0.5f
, 0);
20880 ok(SUCCEEDED(hr
), "Failed to clear %08x\n", hr
);
20882 hr
= IDirect3DDevice9_BeginScene(device
);
20883 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
20885 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_TEXTUREFACTOR
, 0x00ff0000);
20886 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
20888 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_DEPTHBIAS
, conv
.d
);
20889 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
20890 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
20891 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
20893 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_TEXTUREFACTOR
, 0x0000ff00);
20894 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
20896 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_DEPTHBIAS
, conv
.d
);
20897 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
20898 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
20899 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
20901 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_TEXTUREFACTOR
, 0x000000ff);
20902 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
20904 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_DEPTHBIAS
, conv
.d
);
20905 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
20906 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
20907 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
20909 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_TEXTUREFACTOR
, 0x00ffffff);
20910 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
20912 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_DEPTHBIAS
, conv
.d
);
20913 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
20914 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
20915 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
20917 color
= getPixelColor(device
, 61, 240);
20918 ok(color_match(color
, 0x00ffffff, 1), "Got unexpected color %08x at x=62, format %u.\n", color
, formats
[i
]);
20919 color
= getPixelColor(device
, 65, 240);
20921 /* The broken results are for the WARP driver on the testbot. It seems to initialize
20922 * a scaling factor based on the first depth format that is used. Other formats with
20923 * a different depth size then render incorrectly. */
20924 ok(color_match(color
, 0x000000ff, 1) || broken(color_match(color
, 0x00ffffff, 1)),
20925 "Got unexpected color %08x at x=64, format %u.\n", color
, formats
[i
]);
20926 color
= getPixelColor(device
, 190, 240);
20927 ok(color_match(color
, 0x000000ff, 1) || broken(color_match(color
, 0x00ffffff, 1)),
20928 "Got unexpected color %08x at x=190, format %u.\n", color
, formats
[i
]);
20930 color
= getPixelColor(device
, 194, 240);
20931 ok(color_match(color
, 0x0000ff00, 1) || broken(color_match(color
, 0x00ffffff, 1)),
20932 "Got unexpected color %08x at x=194, format %u.\n", color
, formats
[i
]);
20933 color
= getPixelColor(device
, 318, 240);
20934 ok(color_match(color
, 0x0000ff00, 1) || broken(color_match(color
, 0x00ffffff, 1)),
20935 "Got unexpected color %08x at x=318, format %u.\n", color
, formats
[i
]);
20937 color
= getPixelColor(device
, 322, 240);
20938 ok(color_match(color
, 0x00ff0000, 1) || broken(color_match(color
, 0x00000000, 1)),
20939 "Got unexpected color %08x at x=322, format %u.\n", color
, formats
[i
]);
20940 color
= getPixelColor(device
, 446, 240);
20941 ok(color_match(color
, 0x00ff0000, 1) || broken(color_match(color
, 0x00000000, 1)),
20942 "Got unexpected color %08x at x=446, format %u.\n", color
, formats
[i
]);
20944 color
= getPixelColor(device
, 450, 240);
20945 ok(color_match(color
, 0x00000000, 1), "Got unexpected color %08x at x=446, format %u.\n", color
, formats
[i
]);
20947 hr
= IDirect3DDevice9_EndScene(device
);
20948 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
20950 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
20951 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
20952 IDirect3DSurface9_Release(ds
);
20955 refcount
= IDirect3DDevice9_Release(device
);
20956 ok(!refcount
, "Device has %u references left.\n", refcount
);
20959 IDirect3D9_Release(d3d
);
20960 DestroyWindow(window
);
20963 static void test_flip(void)
20965 IDirect3DDevice9
*device
;
20970 IDirect3DSurface9
*back_buffers
[3], *test_surface
;
20973 D3DPRESENT_PARAMETERS present_parameters
= {0};
20975 window
= create_window();
20976 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
20977 ok(!!d3d
, "Failed to create a D3D object.\n");
20979 present_parameters
.BackBufferWidth
= 640;
20980 present_parameters
.BackBufferHeight
= 480;
20981 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
20982 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
20983 present_parameters
.hDeviceWindow
= window
;
20984 present_parameters
.Windowed
= TRUE
;
20985 present_parameters
.BackBufferCount
= 3;
20986 present_parameters
.Flags
= D3DPRESENTFLAG_LOCKABLE_BACKBUFFER
;
20987 hr
= IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
20988 window
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
20991 skip("Failed to create a D3D device, skipping tests.\n");
20992 IDirect3D9_Release(d3d
);
20993 DestroyWindow(window
);
20997 for (i
= 0; i
< ARRAY_SIZE(back_buffers
); ++i
)
20999 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, i
, D3DBACKBUFFER_TYPE_MONO
, &back_buffers
[i
]);
21000 ok(SUCCEEDED(hr
), "Failed to get back buffer, hr %#x.\n", hr
);
21002 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &test_surface
);
21003 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
21004 ok(test_surface
== back_buffers
[0], "Expected render target %p, got %p.\n", back_buffers
[0], test_surface
);
21005 IDirect3DSurface9_Release(test_surface
);
21007 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, back_buffers
[2]);
21008 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
21010 hr
= IDirect3DDevice9_ColorFill(device
, back_buffers
[0], NULL
, 0xffff0000);
21011 ok(SUCCEEDED(hr
), "Failed to color fill, hr %#x.\n", hr
);
21012 hr
= IDirect3DDevice9_ColorFill(device
, back_buffers
[1], NULL
, 0xff00ff00);
21013 ok(SUCCEEDED(hr
), "Failed to color fill, hr %#x.\n", hr
);
21014 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff0000ff, 0.0f
, 0);
21015 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x\n", hr
);
21017 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
21018 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
21020 /* Render target is unmodified. */
21021 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &test_surface
);
21022 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
21023 ok(test_surface
== back_buffers
[2], "Expected render target %p, got %p.\n", back_buffers
[2], test_surface
);
21024 IDirect3DSurface9_Release(test_surface
);
21026 /* Backbuffer surface pointers are unmodified */
21027 for (i
= 0; i
< ARRAY_SIZE(back_buffers
); ++i
)
21029 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, i
, D3DBACKBUFFER_TYPE_MONO
, &test_surface
);
21030 ok(SUCCEEDED(hr
), "Failed to get back buffer, hr %#x.\n", hr
);
21031 ok(test_surface
== back_buffers
[i
], "Expected back buffer %u = %p, got %p.\n",
21032 i
, back_buffers
[i
], test_surface
);
21033 IDirect3DSurface9_Release(test_surface
);
21036 /* Contents were changed. */
21037 color
= getPixelColorFromSurface(back_buffers
[0], 1, 1);
21038 ok(color
== 0xff00ff00, "Got unexpected color 0x%08x.\n", color
);
21039 color
= getPixelColorFromSurface(back_buffers
[1], 1, 1);
21040 ok(color
== 0xff0000ff, "Got unexpected color 0x%08x.\n", color
);
21042 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff808080, 0.0f
, 0);
21043 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x\n", hr
);
21045 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
21046 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
21048 color
= getPixelColorFromSurface(back_buffers
[0], 1, 1);
21049 ok(color
== 0xff0000ff, "Got unexpected color 0x%08x.\n", color
);
21050 color
= getPixelColorFromSurface(back_buffers
[1], 1, 1);
21051 ok(color
== 0xff808080, "Got unexpected color 0x%08x.\n", color
);
21053 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
21054 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
21056 color
= getPixelColorFromSurface(back_buffers
[0], 1, 1);
21057 ok(color
== 0xff808080, "Got unexpected color 0x%08x.\n", color
);
21059 for (i
= 0; i
< ARRAY_SIZE(back_buffers
); ++i
)
21060 IDirect3DSurface9_Release(back_buffers
[i
]);
21062 refcount
= IDirect3DDevice9_Release(device
);
21063 ok(!refcount
, "Device has %u references left.\n", refcount
);
21065 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
21066 D3DFMT_A8R8G8B8
, TRUE
, D3DMULTISAMPLE_2_SAMPLES
, NULL
)))
21068 skip("Multisampling not supported for D3DFMT_A8R8G8B8, skipping multisample flip test.\n");
21072 present_parameters
.BackBufferCount
= 2;
21073 present_parameters
.MultiSampleType
= D3DMULTISAMPLE_2_SAMPLES
;
21074 present_parameters
.Flags
= 0;
21075 hr
= IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
21076 window
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
21078 for (i
= 0; i
< present_parameters
.BackBufferCount
; ++i
)
21080 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, i
, D3DBACKBUFFER_TYPE_MONO
, &back_buffers
[i
]);
21081 ok(SUCCEEDED(hr
), "Failed to get back buffer, hr %#x.\n", hr
);
21084 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, back_buffers
[1]);
21085 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
21086 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff808080, 0.0f
, 0);
21087 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
21089 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
21090 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
21092 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 640, 480, D3DFMT_A8R8G8B8
,
21093 D3DMULTISAMPLE_NONE
, 0, TRUE
, &test_surface
, NULL
);
21094 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
21095 hr
= IDirect3DDevice9_StretchRect(device
, back_buffers
[0], NULL
, test_surface
, NULL
, D3DTEXF_POINT
);
21096 ok(SUCCEEDED(hr
), "StretchRect failed, hr %#x.\n", hr
);
21098 color
= getPixelColorFromSurface(test_surface
, 1, 1);
21099 ok(color
== 0xff808080, "Got unexpected color 0x%08x.\n", color
);
21101 IDirect3DSurface9_Release(test_surface
);
21102 for (i
= 0; i
< present_parameters
.BackBufferCount
; ++i
)
21103 IDirect3DSurface9_Release(back_buffers
[i
]);
21105 refcount
= IDirect3DDevice9_Release(device
);
21106 ok(!refcount
, "Device has %u references left.\n", refcount
);
21109 IDirect3D9_Release(d3d
);
21110 DestroyWindow(window
);
21113 static void test_uninitialized_varyings(void)
21115 static const D3DMATRIX mat
=
21117 1.0f
, 0.0f
, 0.0f
, 0.0f
,
21118 0.0f
, 1.0f
, 0.0f
, 0.0f
,
21119 0.0f
, 0.0f
, 1.0f
, 0.0f
,
21120 0.0f
, 0.0f
, 0.0f
, 1.0f
,
21122 static const struct vec3 quad
[] =
21124 {-1.0f
, -1.0f
, 0.1f
},
21125 {-1.0f
, 1.0f
, 0.1f
},
21126 { 1.0f
, -1.0f
, 0.1f
},
21127 { 1.0f
, 1.0f
, 0.1f
},
21129 static const DWORD vs1_code
[] =
21131 0xfffe0101, /* vs_1_1 */
21132 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
21133 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
21136 static const DWORD vs1_partial_code
[] =
21138 0xfffe0101, /* vs_1_1 */
21139 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
21140 0x00000051, 0xa00f0000, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, /* def c0, 0.5, 0.5, 0.5, 0.5 */
21141 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
21142 0x00000001, 0xd0010000, 0xa0e40000, /* mov oD0.x, c0 */
21143 0x00000001, 0xd0010001, 0xa0e40000, /* mov oD1.x, c0 */
21144 0x00000001, 0xe0010000, 0xa0e40000, /* mov oT0.x, c0 */
21147 static const DWORD vs2_code
[] =
21149 0xfffe0200, /* vs_2_0 */
21150 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
21151 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
21154 static const DWORD vs2_partial_code
[] =
21156 0xfffe0200, /* vs_2_0 */
21157 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
21158 0x05000051, 0xa00f0000, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, /* def c0, 0.5, 0.5, 0.5, 0.5 */
21159 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
21160 0x02000001, 0xd0010000, 0xa0e40000, /* mov oD0.x, c0 */
21161 0x02000001, 0xd0010001, 0xa0e40000, /* mov oD1.x, c0 */
21162 0x02000001, 0xe0010000, 0xa0e40000, /* mov oT0.x, c0 */
21165 static const DWORD vs3_code
[] =
21167 0xfffe0300, /* vs_3_0 */
21168 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
21169 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
21170 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
21173 static const DWORD vs3_partial_code
[] =
21175 0xfffe0300, /* vs_3_0 */
21176 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
21177 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
21178 0x0200001f, 0x8000000a, 0xe00f0001, /* dcl_color0 o1 */
21179 0x0200001f, 0x8001000a, 0xe00f0002, /* dcl_color1 o2 */
21180 0x0200001f, 0x80000005, 0xe00f0003, /* dcl_texcoord0 o3 */
21181 0x05000051, 0xa00f0000, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, /* def c0, 0.5, 0.5, 0.5, 0.5 */
21182 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
21183 0x02000001, 0xe0010001, 0xa0e40000, /* mov o1.x, c0 */
21184 0x02000001, 0xe0010002, 0xa0e40000, /* mov o2.x, c0 */
21185 0x02000001, 0xe0010003, 0xa0e40000, /* mov o3.x, c0 */
21188 static const DWORD ps1_diffuse_code
[] =
21190 0xffff0101, /* ps_1_1 */
21191 0x00000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
21194 static const DWORD ps1_specular_code
[] =
21196 0xffff0101, /* ps_1_1 */
21197 0x00000001, 0x800f0000, 0x90e40001, /* mov r0, v1 */
21200 static const DWORD ps1_texcoord_code
[] =
21202 0xffff0101, /* ps_1_1 */
21203 0x00000040, 0xb00f0000, /* texcoord t0 */
21204 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
21207 static const DWORD ps2_diffuse_code
[] =
21209 0xffff0200, /* ps_2_0 */
21210 0x0200001f, 0x80000000, 0x900f0000, /* dcl v0 */
21211 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
21214 static const DWORD ps2_specular_code
[] =
21216 0xffff0200, /* ps_2_0 */
21217 0x0200001f, 0x80000000, 0x900f0001, /* dcl v1 */
21218 0x02000001, 0x800f0800, 0x90e40001, /* mov oC0, v1 */
21221 static const DWORD ps2_texcoord_code
[] =
21223 0xffff0200, /* ps_2_0 */
21224 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
21225 0x02000001, 0x800f0800, 0xb0e40000, /* mov oC0, t0 */
21229 /* This has been left here for documentation purposes. It is referenced in disabled tests in the table below. */
21230 static const DWORD ps3_diffuse_code
[] =
21232 0xffff0300, /* ps_3_0 */
21233 0x0200001f, 0x8000000a, 0x900f0000, /* dcl_color0 v0 */
21234 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
21238 static const DWORD ps3_specular_code
[] =
21240 0xffff0300, /* ps_3_0 */
21241 0x0200001f, 0x8001000a, 0x900f0001, /* dcl_color1 v1 */
21242 0x02000001, 0x800f0800, 0x90e40001, /* mov oC0, v1 */
21245 static const DWORD ps3_texcoord_code
[] =
21247 0xffff0300, /* ps_3_0 */
21248 0x0200001f, 0x80000005, 0x900f0000, /* dcl_texcoord0 v0 */
21249 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
21252 static const struct
21259 BOOL allow_zero_alpha
;
21263 /* On AMD specular color is generally initialized to 0x00000000 and texcoords to 0xff000000
21264 * while on Nvidia it's the opposite. Just allow both.
21266 * Partially initialized varyings reliably handle the component that has been initialized.
21267 * The uninitialized components generally follow the rule above, with some exceptions on
21268 * radeon cards. r500 and r600 GPUs have been found to set uninitialized components to 0.0,
21269 * 0.5 and 1.0 without a sensible pattern. */
21272 {D3DVS_VERSION(1, 1), vs1_code
, 0, NULL
, 0xffffffff},
21273 { 0, NULL
, D3DPS_VERSION(1, 1), ps1_texcoord_code
, 0xff000000, TRUE
},
21274 { 0, NULL
, D3DPS_VERSION(2, 0), ps2_texcoord_code
, 0xff000000, TRUE
},
21275 {D3DVS_VERSION(1, 1), vs1_code
, D3DPS_VERSION(1, 1), ps1_diffuse_code
, 0xffffffff},
21276 {D3DVS_VERSION(1, 1), vs1_code
, D3DPS_VERSION(1, 1), ps1_specular_code
, 0xff000000, TRUE
, FALSE
, TRUE
},
21277 {D3DVS_VERSION(1, 1), vs1_code
, D3DPS_VERSION(1, 1), ps1_texcoord_code
, 0xff000000, TRUE
},
21278 {D3DVS_VERSION(2, 0), vs2_code
, D3DPS_VERSION(2, 0), ps2_diffuse_code
, 0xffffffff},
21279 {D3DVS_VERSION(2, 0), vs2_code
, D3DPS_VERSION(2, 0), ps2_specular_code
, 0xff000000, TRUE
, FALSE
, TRUE
},
21280 {D3DVS_VERSION(2, 0), vs2_code
, D3DPS_VERSION(2, 0), ps2_texcoord_code
, 0xff000000, TRUE
},
21281 /* This test shows a lot of combinations of alpha and color that involve 1.0 and 0.0. Disable it.
21283 * AMD r500 sets alpha = 1.0, color = 0.0. Nvidia sets alpha = 1.0, color = 1.0. r600 Sets Alpha = 0.0,
21284 * color = 0.0. So far no combination with Alpha = 0.0, color = 1.0 has been found though.
21285 * {D3DVS_VERSION(3, 0), vs3_code, D3DPS_VERSION(3, 0), ps3_diffuse_code, 0xffffffff, FALSE, FALSE},
21287 * The same issues apply to the partially initialized COLOR0 varying, in addition to unreliable results
21288 * with partially initialized varyings in general.
21289 * {D3DVS_VERSION(3, 0), vs3_partial_code, D3DPS_VERSION(3, 0), ps3_diffuse_code, 0xff7fffff, TRUE, TRUE}, */
21290 {D3DVS_VERSION(3, 0), vs3_code
, D3DPS_VERSION(3, 0), ps3_specular_code
, 0xff000000, TRUE
, FALSE
, TRUE
},
21291 {D3DVS_VERSION(3, 0), vs3_code
, D3DPS_VERSION(3, 0), ps3_texcoord_code
, 0xff000000, TRUE
, FALSE
, TRUE
},
21292 {D3DVS_VERSION(1, 1), vs1_partial_code
, 0, NULL
, 0xff7fffff, FALSE
, TRUE
},
21293 {D3DVS_VERSION(1, 1), vs1_partial_code
, D3DPS_VERSION(1, 1), ps1_diffuse_code
, 0xff7fffff, FALSE
, TRUE
},
21294 {D3DVS_VERSION(1, 1), vs1_partial_code
, D3DPS_VERSION(1, 1), ps1_specular_code
, 0xff7f0000, TRUE
, TRUE
},
21295 {D3DVS_VERSION(1, 1), vs1_partial_code
, D3DPS_VERSION(1, 1), ps1_texcoord_code
, 0xff7f0000, TRUE
, TRUE
},
21296 {D3DVS_VERSION(2, 0), vs2_partial_code
, D3DPS_VERSION(2, 0), ps2_diffuse_code
, 0xff7fffff, FALSE
, TRUE
},
21297 {D3DVS_VERSION(2, 0), vs2_partial_code
, D3DPS_VERSION(2, 0), ps2_specular_code
, 0xff7f0000, TRUE
, TRUE
},
21298 {D3DVS_VERSION(2, 0), vs2_partial_code
, D3DPS_VERSION(2, 0), ps2_texcoord_code
, 0xff7f0000, TRUE
, TRUE
},
21299 {D3DVS_VERSION(3, 0), vs3_partial_code
, D3DPS_VERSION(3, 0), ps3_specular_code
, 0x007f0000, FALSE
, TRUE
},
21300 {D3DVS_VERSION(3, 0), vs3_partial_code
, D3DPS_VERSION(3, 0), ps3_texcoord_code
, 0xff7f0000, TRUE
, TRUE
},
21302 IDirect3DDevice9
*device
;
21306 D3DADAPTER_IDENTIFIER9 identifier
;
21307 IDirect3DSurface9
*backbuffer
;
21308 struct surface_readback rb
;
21309 IDirect3DVertexShader9
*vs
;
21310 IDirect3DPixelShader9
*ps
;
21317 window
= create_window();
21318 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
21319 ok(!!d3d
, "Failed to create a D3D object.\n");
21320 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
21322 skip("Failed to create a D3D device, skipping tests.\n");
21323 IDirect3D9_Release(d3d
);
21324 DestroyWindow(window
);
21328 hr
= IDirect3D9_GetAdapterIdentifier(d3d
, D3DADAPTER_DEFAULT
, 0, &identifier
);
21329 ok(SUCCEEDED(hr
), "Failed to get adapter identifier, hr %#x.\n", hr
);
21330 warp
= adapter_is_warp(&identifier
);
21332 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
21333 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
21335 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &backbuffer
);
21336 ok(SUCCEEDED(hr
), "Failed to get backbuffer, hr %#x.\n", hr
);
21338 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_WORLD
, &mat
);
21339 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
21340 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_VIEW
, &mat
);
21341 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
21342 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_PROJECTION
, &mat
);
21343 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
21344 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CLIPPING
, FALSE
);
21345 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
21346 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
21347 ok(SUCCEEDED(hr
), "Failed to disable Z test, hr %#x.\n", hr
);
21348 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGENABLE
, FALSE
);
21349 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
21350 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILENABLE
, FALSE
);
21351 ok(SUCCEEDED(hr
), "Failed to disable stencil test, hr %#x.\n", hr
);
21352 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CULLMODE
, D3DCULL_NONE
);
21353 ok(SUCCEEDED(hr
), "Failed to disable culling, hr %#x.\n", hr
);
21355 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
21356 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
21358 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
21360 if (caps
.VertexShaderVersion
< tests
[i
].vs_version
21361 || caps
.PixelShaderVersion
< tests
[i
].ps_version
)
21363 skip("Vertex / pixel shader version not supported, skipping test %u.\n", i
);
21368 hr
= IDirect3DDevice9_CreateVertexShader(device
, tests
[i
].vs
, &vs
);
21369 ok(SUCCEEDED(hr
), "Failed to create vertex shader, hr %#x (case %u).\n", hr
, i
);
21377 hr
= IDirect3DDevice9_CreatePixelShader(device
, tests
[i
].ps
, &ps
);
21378 ok(SUCCEEDED(hr
), "Failed to create pixel shader, hr %#x (case %u).\n", hr
, i
);
21385 hr
= IDirect3DDevice9_SetVertexShader(device
, vs
);
21386 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
21387 hr
= IDirect3DDevice9_SetPixelShader(device
, ps
);
21388 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
21390 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0, 0);
21391 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
21393 hr
= IDirect3DDevice9_BeginScene(device
);
21394 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
21396 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(quad
[0]));
21397 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
21399 hr
= IDirect3DDevice9_EndScene(device
);
21400 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
21402 get_rt_readback(backbuffer
, &rb
);
21403 color
= get_readback_color(&rb
, 320, 240);
21404 ok(color_match(color
, tests
[i
].expected
, 1)
21405 || (tests
[i
].allow_zero_alpha
&& color_match(color
, tests
[i
].expected
& 0x00ffffff, 1))
21406 || (broken(warp
&& tests
[i
].broken_warp
))
21407 || broken(tests
[i
].partial
&& color_match(color
& 0x00ff0000, tests
[i
].expected
& 0x00ff0000, 1)),
21408 "Got unexpected color 0x%08x, case %u.\n", color
, i
);
21409 release_surface_readback(&rb
);
21412 IDirect3DVertexShader9_Release(vs
);
21414 IDirect3DVertexShader9_Release(ps
);
21417 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
21418 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
21420 IDirect3DSurface9_Release(backbuffer
);
21421 refcount
= IDirect3DDevice9_Release(device
);
21422 ok(!refcount
, "Device has %u references left.\n", refcount
);
21423 IDirect3D9_Release(d3d
);
21424 DestroyWindow(window
);
21427 static void test_multisample_init(void)
21429 IDirect3DDevice9
*device
;
21431 IDirect3DSurface9
*back
, *multi
;
21437 struct surface_readback rb
;
21438 BOOL all_zero
= TRUE
;
21440 window
= create_window();
21441 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
21442 ok(!!d3d
, "Failed to create a D3D object.\n");
21444 if (FAILED(IDirect3D9_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
21445 D3DFMT_A8R8G8B8
, TRUE
, D3DMULTISAMPLE_2_SAMPLES
, NULL
)))
21447 skip("Multisampling not supported for D3DFMT_A8R8G8B8, skipping multisample init test.\n");
21451 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
21453 skip("Failed to create a D3D device, skipping tests.\n");
21457 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &back
);
21458 ok(SUCCEEDED(hr
), "Failed to get back buffer, hr %#x.\n", hr
);
21459 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 640, 480, D3DFMT_A8R8G8B8
,
21460 D3DMULTISAMPLE_2_SAMPLES
, 0, FALSE
, &multi
, NULL
);
21461 ok(SUCCEEDED(hr
), "Failed to create multisampled render target, hr %#x.\n", hr
);
21463 hr
= IDirect3DDevice9_StretchRect(device
, multi
, NULL
, back
, NULL
, D3DTEXF_POINT
);
21464 ok(SUCCEEDED(hr
), "StretchRect failed, hr %#x.\n", hr
);
21466 get_rt_readback(back
, &rb
);
21467 for (y
= 0; y
< 480; ++y
)
21469 for (x
= 0; x
< 640; x
++)
21471 color
= get_readback_color(&rb
, x
, y
);
21472 if (!color_match(color
, 0x00000000, 0))
21481 release_surface_readback(&rb
);
21482 ok(all_zero
, "Got unexpected color 0x%08x, position %ux%u.\n", color
, x
, y
);
21484 IDirect3DSurface9_Release(multi
);
21485 IDirect3DSurface9_Release(back
);
21487 refcount
= IDirect3DDevice9_Release(device
);
21488 ok(!refcount
, "Device has %u references left.\n", refcount
);
21491 IDirect3D9_Release(d3d
);
21492 DestroyWindow(window
);
21495 static void test_depth_stencil_init(void)
21497 IDirect3DDevice9
*device
;
21498 IDirect3DSurface9
*ds
[2];
21499 IDirect3DSurface9
*rt
;
21506 static const struct
21508 struct vec3 position
;
21512 {{-1.0f
, -1.0f
, 0.0f
}},
21513 {{-1.0f
, 1.0f
, 0.0f
}},
21514 {{ 1.0f
, -1.0f
, 0.0f
}},
21515 {{ 1.0f
, 1.0f
, 0.0f
}},
21518 window
= create_window();
21519 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
21520 ok(!!d3d
, "Failed to create D3D object.\n");
21521 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
21523 skip("Failed to create D3D device.\n");
21527 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
21528 ok(hr
== S_OK
, "Failed to set render state, hr %#x.\n", hr
);
21529 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_TRUE
);
21530 ok(hr
== S_OK
, "Failed to set render state, hr %#x.\n", hr
);
21531 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_LESSEQUAL
);
21532 ok(hr
== S_OK
, "Failed to set render state, hr %#x.\n", hr
);
21533 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
21534 ok(hr
== S_OK
, "Failed to set color op, hr %#x.\n", hr
);
21535 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TFACTOR
);
21536 ok(hr
== S_OK
, "Failed to set color arg, hr %#x.\n", hr
);
21537 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
21538 ok(hr
== S_OK
, "Failed to set FVF, hr %#x.\n", hr
);
21540 hr
= IDirect3DDevice9_CreateDepthStencilSurface(device
, 640, 480, D3DFMT_D24S8
, 0, 0, FALSE
, &ds
[0], NULL
);
21541 ok(hr
== S_OK
, "Failed to create depth stencil surface, hr %#x.\n", hr
);
21542 hr
= IDirect3DDevice9_GetDepthStencilSurface(device
, &ds
[1]);
21543 ok(hr
== S_OK
, "Failed to get depth stencil surface, hr %#x.\n", hr
);
21545 for (i
= 0; i
< ARRAY_SIZE(ds
); ++i
)
21547 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, ds
[i
]);
21548 ok(hr
== S_OK
, "Failed to set depth stencil surface, hr %#x.\n", hr
);
21550 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
21551 ok(hr
== S_OK
, "Failed to clear, hr %#x.\n", hr
);
21553 hr
= IDirect3DDevice9_BeginScene(device
);
21554 ok(hr
== S_OK
, "Failed to begin scene, hr %#x.\n", hr
);
21555 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_TEXTUREFACTOR
, 0x000000ff);
21556 ok(hr
== S_OK
, "Failed to set render state, hr %#x.\n", hr
);
21557 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
21558 ok(hr
== S_OK
, "Failed to draw, hr %#x.\n", hr
);
21559 hr
= IDirect3DDevice9_EndScene(device
);
21560 ok(hr
== S_OK
, "Failed to end scene, hr %#x.\n", hr
);
21562 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &rt
);
21563 ok(hr
== S_OK
, "Failed to get render target, hr %#x.\n", hr
);
21564 check_rt_color(rt
, 0x000000ff);
21565 IDirect3DSurface9_Release(rt
);
21567 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
21568 ok(hr
== D3D_OK
, "Failed to present, hr %#x.\n", hr
);
21570 IDirect3DSurface9_Release(ds
[i
]);
21573 refcount
= IDirect3DDevice9_Release(device
);
21574 ok(!refcount
, "Device has %u references left.\n", refcount
);
21577 IDirect3D9_Release(d3d
);
21578 DestroyWindow(window
);
21581 static void test_texture_blending(void)
21583 #define STATE_END() {0xffffffff, 0xffffffff}
21584 #define IS_STATE_END(s) (s.name == 0xffffffff && s.value == 0xffffffff)
21586 IDirect3DTexture9
*texture_bumpmap
, *texture_red
;
21587 IDirect3DSurface9
*backbuffer
;
21588 struct surface_readback rb
;
21589 D3DLOCKED_RECT locked_rect
;
21590 IDirect3DDevice9
*device
;
21591 unsigned int i
, j
, k
;
21599 static const struct
21601 struct vec3 position
;
21606 {{-1.0f
, -1.0f
, 0.1f
}, D3DCOLOR_ARGB(0x80, 0xff, 0xff, 0x02)},
21607 {{-1.0f
, 1.0f
, 0.1f
}, D3DCOLOR_ARGB(0x80, 0xff, 0xff, 0x02)},
21608 {{ 1.0f
, -1.0f
, 0.1f
}, D3DCOLOR_ARGB(0x80, 0xff, 0xff, 0x02)},
21609 {{ 1.0f
, 1.0f
, 0.1f
}, D3DCOLOR_ARGB(0x80, 0xff, 0xff, 0x02)},
21612 static const float bumpenvmat
[4] = {1.0f
, 1.0f
, 0.0f
, 0.0f
};
21614 struct texture_stage_state
21616 D3DTEXTURESTAGESTATETYPE name
;
21620 struct texture_stage
21630 struct texture_stage_state state
[20];
21633 static const struct texture_stage default_stage_state
=
21637 {D3DTSS_COLOROP
, D3DTOP_DISABLE
},
21638 {D3DTSS_COLORARG1
, D3DTA_TEXTURE
},
21639 {D3DTSS_COLORARG2
, D3DTA_CURRENT
},
21640 {D3DTSS_ALPHAOP
, D3DTOP_DISABLE
},
21641 {D3DTSS_ALPHAARG1
, D3DTA_TEXTURE
},
21642 {D3DTSS_ALPHAARG2
, D3DTA_CURRENT
},
21643 {D3DTSS_BUMPENVMAT00
, 0},
21644 {D3DTSS_BUMPENVMAT01
, 0},
21645 {D3DTSS_BUMPENVMAT10
, 0},
21646 {D3DTSS_BUMPENVMAT11
, 0},
21647 {D3DTSS_BUMPENVLSCALE
, 0},
21648 {D3DTSS_BUMPENVLOFFSET
, 0},
21649 {D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_DISABLE
},
21650 {D3DTSS_COLORARG0
, D3DTA_CURRENT
},
21651 {D3DTSS_ALPHAARG0
, D3DTA_CURRENT
},
21652 {D3DTSS_RESULTARG
, D3DTA_CURRENT
},
21653 {D3DTSS_CONSTANT
, 0},
21661 D3DCOLOR expected_color
;
21662 struct texture_stage stage
[8];
21667 D3DTEXOPCAPS_DISABLE
,
21679 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
,
21685 {D3DTSS_COLOROP
, D3DTOP_SELECTARG1
},
21686 {D3DTSS_COLORARG1
, D3DTA_CURRENT
},
21694 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
,
21700 {D3DTSS_COLOROP
, D3DTOP_SELECTARG1
},
21701 {D3DTSS_COLORARG1
, D3DTA_CURRENT
},
21702 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
21703 {D3DTSS_ALPHAARG1
, D3DTA_CURRENT
},
21710 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
,
21716 {D3DTSS_COLOROP
, D3DTOP_SELECTARG1
},
21717 {D3DTSS_COLORARG1
, D3DTA_DIFFUSE
},
21718 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
21719 {D3DTSS_ALPHAARG1
, D3DTA_DIFFUSE
},
21726 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
,
21732 {D3DTSS_COLOROP
, D3DTOP_SELECTARG1
},
21733 {D3DTSS_COLORARG1
, D3DTA_TEMP
},
21734 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
21735 {D3DTSS_ALPHAARG1
, D3DTA_TEMP
},
21742 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_SUBTRACT
,
21748 {D3DTSS_COLOROP
, D3DTOP_SELECTARG1
},
21749 {D3DTSS_COLORARG1
, D3DTA_CURRENT
},
21756 {D3DTSS_COLOROP
, D3DTOP_SUBTRACT
},
21757 {D3DTSS_COLORARG1
, D3DTA_CURRENT
},
21758 {D3DTSS_COLORARG2
, D3DTA_CONSTANT
},
21759 {D3DTSS_CONSTANT
, 0x0f0f0f0f},
21767 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_SUBTRACT
,
21773 {D3DTSS_COLOROP
, D3DTOP_SELECTARG1
},
21774 {D3DTSS_COLORARG1
, D3DTA_CURRENT
},
21775 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
21776 {D3DTSS_ALPHAARG1
, D3DTA_CURRENT
},
21783 {D3DTSS_COLOROP
, D3DTOP_SUBTRACT
},
21784 {D3DTSS_COLORARG1
, D3DTA_CURRENT
},
21785 {D3DTSS_COLORARG2
, D3DTA_CONSTANT
},
21786 {D3DTSS_ALPHAOP
, D3DTOP_SUBTRACT
},
21787 {D3DTSS_ALPHAARG1
, D3DTA_CURRENT
},
21788 {D3DTSS_ALPHAARG2
, D3DTA_CONSTANT
},
21789 {D3DTSS_CONSTANT
, 0x0f0f0f0f},
21798 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_BUMPENVMAP
| D3DTEXOPCAPS_MODULATE
,
21804 {D3DTSS_COLOROP
, D3DTOP_BUMPENVMAP
},
21805 {D3DTSS_BUMPENVMAT00
, *(DWORD
*)&bumpenvmat
[0]},
21806 {D3DTSS_BUMPENVMAT01
, *(DWORD
*)&bumpenvmat
[1]},
21807 {D3DTSS_BUMPENVMAT10
, *(DWORD
*)&bumpenvmat
[2]},
21808 {D3DTSS_BUMPENVMAT11
, *(DWORD
*)&bumpenvmat
[3]},
21809 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
21810 {D3DTSS_ALPHAARG1
, D3DTA_TEXTURE
},
21818 {D3DTSS_COLOROP
, D3DTOP_MODULATE
},
21826 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_BUMPENVMAP
| D3DTEXOPCAPS_MODULATE
,
21832 {D3DTSS_COLOROP
, D3DTOP_BUMPENVMAP
},
21833 {D3DTSS_BUMPENVMAT00
, *(DWORD
*)&bumpenvmat
[0]},
21834 {D3DTSS_BUMPENVMAT01
, *(DWORD
*)&bumpenvmat
[1]},
21835 {D3DTSS_BUMPENVMAT10
, *(DWORD
*)&bumpenvmat
[2]},
21836 {D3DTSS_BUMPENVMAT11
, *(DWORD
*)&bumpenvmat
[3]},
21837 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
21838 {D3DTSS_ALPHAARG1
, D3DTA_DIFFUSE
},
21845 {D3DTSS_COLOROP
, D3DTOP_MODULATE
},
21853 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_BUMPENVMAP
| D3DTEXOPCAPS_MODULATE
,
21859 {D3DTSS_COLOROP
, D3DTOP_BUMPENVMAP
},
21860 {D3DTSS_BUMPENVMAT00
, *(DWORD
*)&bumpenvmat
[0]},
21861 {D3DTSS_BUMPENVMAT01
, *(DWORD
*)&bumpenvmat
[1]},
21862 {D3DTSS_BUMPENVMAT10
, *(DWORD
*)&bumpenvmat
[2]},
21863 {D3DTSS_BUMPENVMAT11
, *(DWORD
*)&bumpenvmat
[3]},
21864 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
21865 {D3DTSS_ALPHAARG1
, D3DTA_TEMP
},
21872 {D3DTSS_COLOROP
, D3DTOP_MODULATE
},
21873 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
21874 {D3DTSS_ALPHAARG1
, D3DTA_CURRENT
},
21882 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_BUMPENVMAP
| D3DTEXOPCAPS_MODULATE
,
21888 {D3DTSS_COLOROP
, D3DTOP_BUMPENVMAP
},
21889 {D3DTSS_BUMPENVMAT00
, *(DWORD
*)&bumpenvmat
[0]},
21890 {D3DTSS_BUMPENVMAT01
, *(DWORD
*)&bumpenvmat
[1]},
21891 {D3DTSS_BUMPENVMAT10
, *(DWORD
*)&bumpenvmat
[2]},
21892 {D3DTSS_BUMPENVMAT11
, *(DWORD
*)&bumpenvmat
[3]},
21893 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
21894 {D3DTSS_ALPHAARG1
, D3DTA_TEMP
},
21901 {D3DTSS_COLOROP
, D3DTOP_MODULATE
},
21902 {D3DTSS_COLORARG1
, D3DTA_TEXTURE
},
21903 {D3DTSS_COLORARG2
, D3DTA_CURRENT
},
21904 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
21905 {D3DTSS_ALPHAARG1
, D3DTA_TEMP
},
21913 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_BUMPENVMAP
| D3DTEXOPCAPS_MODULATE
,
21919 {D3DTSS_COLOROP
, D3DTOP_BUMPENVMAP
},
21920 {D3DTSS_BUMPENVMAT00
, *(DWORD
*)&bumpenvmat
[0]},
21921 {D3DTSS_BUMPENVMAT01
, *(DWORD
*)&bumpenvmat
[1]},
21922 {D3DTSS_BUMPENVMAT10
, *(DWORD
*)&bumpenvmat
[2]},
21923 {D3DTSS_BUMPENVMAT11
, *(DWORD
*)&bumpenvmat
[3]},
21924 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
21925 {D3DTSS_ALPHAARG1
, D3DTA_CURRENT
},
21932 {D3DTSS_COLOROP
, D3DTOP_MODULATE
},
21933 {D3DTSS_COLORARG1
, D3DTA_TEXTURE
},
21934 {D3DTSS_COLORARG2
, D3DTA_CURRENT
},
21935 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
21936 {D3DTSS_ALPHAARG1
, D3DTA_CURRENT
},
21945 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_BUMPENVMAP
| D3DTEXOPCAPS_MODULATE
21946 | D3DTEXOPCAPS_ADD
,
21952 {D3DTSS_COLOROP
, D3DTOP_BUMPENVMAP
},
21953 {D3DTSS_BUMPENVMAT00
, *(DWORD
*)&bumpenvmat
[0]},
21954 {D3DTSS_BUMPENVMAT01
, *(DWORD
*)&bumpenvmat
[1]},
21955 {D3DTSS_BUMPENVMAT10
, *(DWORD
*)&bumpenvmat
[2]},
21956 {D3DTSS_BUMPENVMAT11
, *(DWORD
*)&bumpenvmat
[3]},
21957 {D3DTSS_ALPHAOP
, D3DTOP_ADD
},
21958 {D3DTSS_ALPHAARG1
, D3DTA_DIFFUSE
},
21959 {D3DTSS_ALPHAARG2
, D3DTA_CONSTANT
},
21960 {D3DTSS_CONSTANT
, 0x0fffffff},
21967 {D3DTSS_COLOROP
, D3DTOP_MODULATE
},
21968 {D3DTSS_COLORARG1
, D3DTA_TEXTURE
},
21969 {D3DTSS_COLORARG2
, D3DTA_CURRENT
},
21970 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
21971 {D3DTSS_ALPHAARG1
, D3DTA_CURRENT
},
21979 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_BUMPENVMAP
| D3DTEXOPCAPS_MODULATE
21980 | D3DTEXOPCAPS_MODULATE2X
,
21986 {D3DTSS_COLOROP
, D3DTOP_BUMPENVMAP
},
21987 {D3DTSS_BUMPENVMAT00
, *(DWORD
*)&bumpenvmat
[0]},
21988 {D3DTSS_BUMPENVMAT01
, *(DWORD
*)&bumpenvmat
[1]},
21989 {D3DTSS_BUMPENVMAT10
, *(DWORD
*)&bumpenvmat
[2]},
21990 {D3DTSS_BUMPENVMAT11
, *(DWORD
*)&bumpenvmat
[3]},
21991 {D3DTSS_ALPHAOP
, D3DTOP_MODULATE2X
},
21992 {D3DTSS_ALPHAARG1
, D3DTA_DIFFUSE
},
21993 {D3DTSS_ALPHAARG2
, D3DTA_CONSTANT
},
21994 {D3DTSS_CONSTANT
, 0x01ffffff},
22001 {D3DTSS_COLOROP
, D3DTOP_MODULATE
},
22002 {D3DTSS_COLORARG1
, D3DTA_TEXTURE
},
22003 {D3DTSS_COLORARG2
, D3DTA_CURRENT
},
22004 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
22005 {D3DTSS_ALPHAARG1
, D3DTA_CURRENT
},
22013 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_BUMPENVMAP
| D3DTEXOPCAPS_MODULATE
22014 | D3DTEXOPCAPS_MODULATE2X
,
22020 {D3DTSS_COLOROP
, D3DTOP_BUMPENVMAP
},
22021 {D3DTSS_BUMPENVMAT00
, *(DWORD
*)&bumpenvmat
[0]},
22022 {D3DTSS_BUMPENVMAT01
, *(DWORD
*)&bumpenvmat
[1]},
22023 {D3DTSS_BUMPENVMAT10
, *(DWORD
*)&bumpenvmat
[2]},
22024 {D3DTSS_BUMPENVMAT11
, *(DWORD
*)&bumpenvmat
[3]},
22025 {D3DTSS_ALPHAOP
, D3DTOP_MODULATE2X
},
22026 {D3DTSS_ALPHAARG1
, D3DTA_CURRENT
},
22027 {D3DTSS_ALPHAARG2
, D3DTA_CONSTANT
},
22028 {D3DTSS_CONSTANT
, 0x01ffffff},
22035 {D3DTSS_COLOROP
, D3DTOP_MODULATE
},
22036 {D3DTSS_COLORARG1
, D3DTA_CURRENT
},
22037 {D3DTSS_COLORARG2
, D3DTA_CURRENT
},
22038 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
22039 {D3DTSS_ALPHAARG1
, D3DTA_CURRENT
},
22040 {D3DTSS_ALPHAARG2
, D3DTA_CONSTANT
},
22041 {D3DTSS_ALPHAARG0
, D3DTA_CONSTANT
},
22049 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_BUMPENVMAP
,
22055 {D3DTSS_COLOROP
, D3DTOP_SELECTARG1
},
22056 {D3DTSS_COLORARG1
, D3DTA_CONSTANT
},
22057 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
22058 {D3DTSS_ALPHAARG1
, D3DTA_CONSTANT
},
22059 {D3DTSS_RESULTARG
, D3DTA_TEMP
},
22060 {D3DTSS_CONSTANT
, 0x01234567},
22067 {D3DTSS_COLOROP
, D3DTOP_BUMPENVMAP
},
22068 {D3DTSS_BUMPENVMAT00
, *(DWORD
*)&bumpenvmat
[0]},
22069 {D3DTSS_BUMPENVMAT01
, *(DWORD
*)&bumpenvmat
[1]},
22070 {D3DTSS_BUMPENVMAT10
, *(DWORD
*)&bumpenvmat
[2]},
22071 {D3DTSS_BUMPENVMAT11
, *(DWORD
*)&bumpenvmat
[3]},
22072 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
22073 {D3DTSS_ALPHAARG1
, D3DTA_TEMP
},
22074 {D3DTSS_RESULTARG
, D3DTA_TEMP
},
22081 {D3DTSS_COLOROP
, D3DTOP_SELECTARG1
},
22082 {D3DTSS_COLORARG1
, D3DTA_TEXTURE
},
22083 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
22084 {D3DTSS_ALPHAARG1
, D3DTA_TEXTURE
},
22091 {D3DTSS_COLOROP
, D3DTOP_SELECTARG1
},
22092 {D3DTSS_COLORARG1
, D3DTA_TEMP
},
22093 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
22094 {D3DTSS_ALPHAARG1
, D3DTA_TEMP
},
22102 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_BUMPENVMAP
,
22108 {D3DTSS_COLOROP
, D3DTOP_SELECTARG1
},
22109 {D3DTSS_COLORARG1
, D3DTA_CONSTANT
},
22110 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
22111 {D3DTSS_ALPHAARG1
, D3DTA_CONSTANT
},
22112 {D3DTSS_RESULTARG
, D3DTA_TEMP
},
22113 {D3DTSS_CONSTANT
, 0x01234567},
22120 {D3DTSS_COLOROP
, D3DTOP_BUMPENVMAP
},
22121 {D3DTSS_BUMPENVMAT00
, *(DWORD
*)&bumpenvmat
[0]},
22122 {D3DTSS_BUMPENVMAT01
, *(DWORD
*)&bumpenvmat
[1]},
22123 {D3DTSS_BUMPENVMAT10
, *(DWORD
*)&bumpenvmat
[2]},
22124 {D3DTSS_BUMPENVMAT11
, *(DWORD
*)&bumpenvmat
[3]},
22125 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
22126 {D3DTSS_ALPHAARG1
, D3DTA_TEMP
},
22133 {D3DTSS_COLOROP
, D3DTOP_SELECTARG1
},
22134 {D3DTSS_COLORARG1
, D3DTA_TEXTURE
},
22135 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
22136 {D3DTSS_ALPHAARG1
, D3DTA_TEXTURE
},
22143 {D3DTSS_COLOROP
, D3DTOP_SELECTARG1
},
22144 {D3DTSS_COLORARG1
, D3DTA_TEMP
},
22152 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_BUMPENVMAP
,
22158 {D3DTSS_COLOROP
, D3DTOP_SELECTARG1
},
22159 {D3DTSS_COLORARG1
, D3DTA_CONSTANT
},
22160 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
22161 {D3DTSS_ALPHAARG1
, D3DTA_CONSTANT
},
22162 {D3DTSS_RESULTARG
, D3DTA_TEMP
},
22163 {D3DTSS_CONSTANT
, 0x01234567},
22170 {D3DTSS_COLOROP
, D3DTOP_BUMPENVMAP
},
22171 {D3DTSS_BUMPENVMAT00
, *(DWORD
*)&bumpenvmat
[0]},
22172 {D3DTSS_BUMPENVMAT01
, *(DWORD
*)&bumpenvmat
[1]},
22173 {D3DTSS_BUMPENVMAT10
, *(DWORD
*)&bumpenvmat
[2]},
22174 {D3DTSS_BUMPENVMAT11
, *(DWORD
*)&bumpenvmat
[3]},
22175 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
22176 {D3DTSS_ALPHAARG1
, D3DTA_TEMP
},
22177 {D3DTSS_RESULTARG
, D3DTA_TEMP
},
22184 {D3DTSS_COLOROP
, D3DTOP_SELECTARG1
},
22185 {D3DTSS_COLORARG1
, D3DTA_TEXTURE
},
22186 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
22187 {D3DTSS_ALPHAARG1
, D3DTA_TEXTURE
},
22194 {D3DTSS_COLOROP
, D3DTOP_SELECTARG1
},
22195 {D3DTSS_COLORARG1
, D3DTA_TEMP
},
22196 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
22197 {D3DTSS_ALPHAARG1
, D3DTA_TEMP
},
22205 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_BUMPENVMAP
,
22211 {D3DTSS_COLOROP
, D3DTOP_SELECTARG1
},
22212 {D3DTSS_COLORARG1
, D3DTA_CONSTANT
},
22213 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
22214 {D3DTSS_ALPHAARG1
, D3DTA_CONSTANT
},
22215 {D3DTSS_RESULTARG
, D3DTA_CURRENT
},
22216 {D3DTSS_CONSTANT
, 0x01234567},
22223 {D3DTSS_COLOROP
, D3DTOP_BUMPENVMAP
},
22224 {D3DTSS_BUMPENVMAT00
, *(DWORD
*)&bumpenvmat
[0]},
22225 {D3DTSS_BUMPENVMAT01
, *(DWORD
*)&bumpenvmat
[1]},
22226 {D3DTSS_BUMPENVMAT10
, *(DWORD
*)&bumpenvmat
[2]},
22227 {D3DTSS_BUMPENVMAT11
, *(DWORD
*)&bumpenvmat
[3]},
22228 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
22229 {D3DTSS_ALPHAARG1
, D3DTA_TEMP
},
22230 {D3DTSS_RESULTARG
, D3DTA_TEMP
},
22237 {D3DTSS_COLOROP
, D3DTOP_SELECTARG1
},
22238 {D3DTSS_COLORARG1
, D3DTA_TEXTURE
},
22239 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
22240 {D3DTSS_ALPHAARG1
, D3DTA_TEXTURE
},
22241 {D3DTSS_RESULTARG
, D3DTA_TEMP
},
22248 {D3DTSS_COLOROP
, D3DTOP_SELECTARG1
},
22249 {D3DTSS_COLORARG1
, D3DTA_CURRENT
},
22250 {D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
},
22251 {D3DTSS_ALPHAARG1
, D3DTA_CURRENT
},
22252 {D3DTSS_RESULTARG
, D3DTA_CURRENT
},
22261 window
= create_window();
22262 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
22263 ok(!!d3d
, "Failed to create a D3D object.\n");
22264 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
22266 skip("Failed to create a D3D device.\n");
22270 memset(&caps
, 0, sizeof(caps
));
22271 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
22272 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetDeviceCaps failed hr %#x.\n", hr
);
22274 if(!(caps
.PrimitiveMiscCaps
& D3DPMISCCAPS_TSSARGTEMP
))
22276 skip("D3DPMISCCAPS_TSSARGTEMP not supported.\n");
22277 IDirect3DDevice9_Release(device
);
22281 if (!(caps
.PrimitiveMiscCaps
& D3DPMISCCAPS_PERSTAGECONSTANT
))
22283 skip("D3DPMISCCAPS_PERSTAGECONSTANT not supported.\n");
22284 IDirect3DDevice9_Release(device
);
22288 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
,
22289 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_TEXTURE
, D3DFMT_V8U8
)))
22291 skip("D3DFMT_V8U8 not supported for legacy bump mapping.\n");
22292 IDirect3DDevice9_Release(device
);
22296 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
22297 ok(hr
== D3D_OK
, "Can't get back buffer, hr %#x.\n", hr
);
22299 hr
= IDirect3DDevice9_CreateTexture(device
, 1, 1, 1, 0, D3DFMT_V8U8
, D3DPOOL_MANAGED
, &texture_bumpmap
, NULL
);
22300 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture failed, hr %#x.\n", hr
);
22301 hr
= IDirect3DDevice9_CreateTexture(device
, 1, 1, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &texture_red
, NULL
);
22302 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture failed, hr %#x.\n", hr
);
22304 memset(&locked_rect
, 0, sizeof(locked_rect
));
22305 hr
= IDirect3DTexture9_LockRect(texture_bumpmap
, 0, &locked_rect
, NULL
, 0);
22306 ok(SUCCEEDED(hr
), "LockRect failed, hr %#x.\n", hr
);
22307 *((WORD
*)locked_rect
.pBits
) = 0xff00;
22308 hr
= IDirect3DTexture9_UnlockRect(texture_bumpmap
, 0);
22309 ok(SUCCEEDED(hr
), "UnlockRect failed, hr %#x.\n", hr
);
22311 memset(&locked_rect
, 0, sizeof(locked_rect
));
22312 hr
= IDirect3DTexture9_LockRect(texture_red
, 0, &locked_rect
, NULL
, 0);
22313 ok(SUCCEEDED(hr
), "LockRect failed, hr %#x.\n", hr
);
22314 *((DWORD
*)locked_rect
.pBits
) = 0x00ff0000;
22315 hr
= IDirect3DTexture9_UnlockRect(texture_red
, 0);
22316 ok(SUCCEEDED(hr
), "UnlockRect failed, hr %#x.\n", hr
);
22318 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
22319 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
22320 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
22321 ok(hr
== D3D_OK
, "Failed to disable lighting, hr %#x.\n", hr
);
22323 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
22325 const struct test
*current_test
= &tests
[i
];
22327 if ((caps
.TextureOpCaps
& current_test
->tex_op_caps
) != current_test
->tex_op_caps
)
22329 skip("Texture operations %#x not supported.\n", current_test
->tex_op_caps
);
22333 for (j
= 0; j
< caps
.MaxTextureBlendStages
; ++j
)
22335 IDirect3DTexture9
*current_texture
= NULL
;
22337 for (k
= 0; !IS_STATE_END(default_stage_state
.state
[k
]); ++k
)
22339 hr
= IDirect3DDevice9_SetTextureStageState(device
, j
,
22340 default_stage_state
.state
[k
].name
, default_stage_state
.state
[k
].value
);
22341 ok(SUCCEEDED(hr
), "Test %u: SetTextureStageState failed, hr %#x.\n", i
, hr
);
22344 if (current_test
->stage
[j
].texture
!= TEXTURE_INVALID
)
22346 const struct texture_stage_state
*current_state
= current_test
->stage
[j
].state
;
22348 switch (current_test
->stage
[j
].texture
)
22351 current_texture
= texture_red
;
22353 case TEXTURE_BUMPMAP
:
22354 current_texture
= texture_bumpmap
;
22357 current_texture
= NULL
;
22361 for (k
= 0; !IS_STATE_END(current_state
[k
]); ++k
)
22363 hr
= IDirect3DDevice9_SetTextureStageState(device
, j
,
22364 current_state
[k
].name
, current_state
[k
].value
);
22365 ok(SUCCEEDED(hr
), "Test %u: SetTextureStageState failed, hr %#x.\n", i
, hr
);
22369 hr
= IDirect3DDevice9_SetTexture(device
, j
, (IDirect3DBaseTexture9
*)current_texture
);
22370 ok(SUCCEEDED(hr
), "Test %u: SetTexture failed, hr %#x.\n", i
, hr
);
22373 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff00ff00, 1.0f
, 0);
22374 ok(hr
== D3D_OK
, "Test %u: IDirect3DDevice9_Clear failed, hr %#x.\n", i
, hr
);
22376 hr
= IDirect3DDevice9_BeginScene(device
);
22377 ok(SUCCEEDED(hr
), "Test %u: BeginScene failed, hr %#x.\n", i
, hr
);
22378 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad
[0], sizeof(quad
[0]));
22379 ok(SUCCEEDED(hr
), "Test %u: DrawPrimitiveUP failed, hr %#x.\n", i
, hr
);
22380 hr
= IDirect3DDevice9_EndScene(device
);
22381 ok(SUCCEEDED(hr
), "Test %u: EndScene failed, hr %#x.\n", i
, hr
);
22383 get_rt_readback(backbuffer
, &rb
);
22384 color
= get_readback_color(&rb
, 320, 240);
22385 ok(color_match(color
, current_test
->expected_color
, 1),
22386 "Test %u: Got color 0x%08x, expected 0x%08x.\n", i
, color
, current_test
->expected_color
);
22387 release_surface_readback(&rb
);
22388 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
22389 ok(SUCCEEDED(hr
), "Test %u: Present failed, hr %#x.\n", i
, hr
);
22392 IDirect3DTexture9_Release(texture_bumpmap
);
22393 IDirect3DTexture9_Release(texture_red
);
22394 IDirect3DSurface9_Release(backbuffer
);
22395 refcount
= IDirect3DDevice9_Release(device
);
22396 ok(!refcount
, "Device has %u references left.\n", refcount
);
22398 IDirect3D9_Release(d3d
);
22399 DestroyWindow(window
);
22402 static void test_color_clamping(void)
22404 static const D3DMATRIX mat
=
22406 1.0f
, 0.0f
, 0.0f
, 0.0f
,
22407 0.0f
, 1.0f
, 0.0f
, 0.0f
,
22408 0.0f
, 0.0f
, 1.0f
, 0.0f
,
22409 0.0f
, 0.0f
, 0.0f
, 1.0f
,
22411 static const struct vec3 quad
[] =
22413 {-1.0f
, -1.0f
, 0.1f
},
22414 {-1.0f
, 1.0f
, 0.1f
},
22415 { 1.0f
, -1.0f
, 0.1f
},
22416 { 1.0f
, 1.0f
, 0.1f
},
22418 static const DWORD vs1_code
[] =
22420 0xfffe0101, /* vs_1_1 */
22421 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
22422 0x00000051, 0xa00f0000, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c0, 1.0, 1.0, 1.0, 1.0 */
22423 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
22424 0x00000002, 0xd00f0000, 0xa0e40000, 0xa0e40000, /* add oD0, c0, c0 */
22425 0x00000002, 0xd00f0001, 0xa0e40000, 0xa0e40000, /* add oD1, c0, c0 */
22428 static const DWORD vs2_code
[] =
22430 0xfffe0200, /* vs_2_0 */
22431 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
22432 0x05000051, 0xa00f0000, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c0, 1.0, 1.0, 1.0, 1.0 */
22433 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
22434 0x03000002, 0xd00f0000, 0xa0e40000, 0xa0e40000, /* add oD0, c0, c0 */
22435 0x03000002, 0xd00f0001, 0xa0e40000, 0xa0e40000, /* add oD1, c0, c0 */
22438 static const DWORD vs3_code
[] =
22440 0xfffe0300, /* vs_3_0 */
22441 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
22442 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
22443 0x0200001f, 0x8000000a, 0xe00f0001, /* dcl_color0 o1 */
22444 0x0200001f, 0x8001000a, 0xe00f0002, /* dcl_color1 o2 */
22445 0x05000051, 0xa00f0000, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c0, 1.0, 1.0, 1.0, 1.0 */
22446 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
22447 0x03000002, 0xe00f0001, 0xa0e40000, 0xa0e40000, /* add o1, c0, c0 */
22448 0x03000002, 0xe00f0002, 0xa0e40000, 0xa0e40000, /* add o2, c0, c0 */
22451 static const DWORD ps1_code
[] =
22453 0xffff0101, /* ps_1_1 */
22454 0x00000051, 0xa00f0000, 0x3e800000, 0x3e800000, 0x3e800000, 0x3e800000, /* def c0, 0.25, 0.25, 0.25, 0.25 */
22455 0x00000002, 0x800f0000, 0x90e40000, 0x90e40001, /* add r0, v0, v1 */
22456 0x00000005, 0x800f0000, 0x80e40000, 0xa0e40000, /* mul r0, r0, c0 */
22459 static const DWORD ps2_code
[] =
22461 0xffff0200, /* ps_2_0 */
22462 0x0200001f, 0x80000000, 0x900f0000, /* dcl v0 */
22463 0x0200001f, 0x80000000, 0x900f0001, /* dcl v1 */
22464 0x05000051, 0xa00f0000, 0x3e800000, 0x3e800000, 0x3e800000, 0x3e800000, /* def c0, 0.25, 0.25, 0.25, 0.25 */
22465 0x02000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
22466 0x03000002, 0x800f0000, 0x80e40000, 0x90e40001, /* add r0, r0, v1 */
22467 0x03000005, 0x800f0000, 0x80e40000, 0xa0e40000, /* mul r0, r0, c0 */
22468 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
22471 static const DWORD ps3_code
[] =
22473 0xffff0300, /* ps_3_0 */
22474 0x0200001f, 0x8000000a, 0x900f0000, /* dcl_color0 v0 */
22475 0x0200001f, 0x8001000a, 0x900f0001, /* dcl_color1 v1 */
22476 0x05000051, 0xa00f0000, 0x3e800000, 0x3e800000, 0x3e800000, 0x3e800000, /* def c0, 0.25, 0.25, 0.25, 0.25 */
22477 0x02000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
22478 0x03000002, 0x800f0000, 0x80e40000, 0x90e40001, /* add r0, r0, v1 */
22479 0x03000005, 0x800f0800, 0x80e40000, 0xa0e40000, /* mul oC0, r0, c0 */
22482 static const struct
22488 D3DCOLOR expected
, broken
;
22492 {0, NULL
, 0, NULL
, 0x00404040},
22493 {0, NULL
, D3DPS_VERSION(1, 1), ps1_code
, 0x00404040, 0x00808080},
22494 {D3DVS_VERSION(1, 1), vs1_code
, 0, NULL
, 0x00404040},
22495 {D3DVS_VERSION(1, 1), vs1_code
, D3DPS_VERSION(1, 1), ps1_code
, 0x007f7f7f},
22496 {D3DVS_VERSION(2, 0), vs2_code
, D3DPS_VERSION(2, 0), ps2_code
, 0x007f7f7f},
22497 {D3DVS_VERSION(3, 0), vs3_code
, D3DPS_VERSION(3, 0), ps3_code
, 0x00ffffff},
22499 IDirect3DVertexShader9
*vs
;
22500 IDirect3DPixelShader9
*ps
;
22501 IDirect3DDevice9
*device
;
22510 window
= create_window();
22511 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
22512 ok(!!d3d9
, "Failed to create a D3D object.\n");
22513 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
22515 skip("Failed to create a D3D device, skipping tests.\n");
22516 IDirect3D9_Release(d3d9
);
22517 DestroyWindow(window
);
22521 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
22522 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
22524 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_WORLD
, &mat
);
22525 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
22526 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_VIEW
, &mat
);
22527 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
22528 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_PROJECTION
, &mat
);
22529 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
22530 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CLIPPING
, FALSE
);
22531 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
22532 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
22533 ok(SUCCEEDED(hr
), "Failed to disable Z test, hr %#x.\n", hr
);
22534 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGENABLE
, FALSE
);
22535 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
22536 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILENABLE
, FALSE
);
22537 ok(SUCCEEDED(hr
), "Failed to disable stencil test, hr %#x.\n", hr
);
22538 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CULLMODE
, D3DCULL_NONE
);
22539 ok(SUCCEEDED(hr
), "Failed to disable culling, hr %#x.\n", hr
);
22540 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
22541 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
22543 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_TEXTUREFACTOR
, 0xff404040);
22544 ok(SUCCEEDED(hr
), "Failed to set texture factor, hr %#x.\n", hr
);
22545 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_ADD
);
22546 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
22547 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_DIFFUSE
);
22548 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
22549 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_SPECULAR
);
22550 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
22551 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_MODULATE
);
22552 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
22553 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLORARG1
, D3DTA_TFACTOR
);
22554 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
22555 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLORARG2
, D3DTA_CURRENT
);
22556 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
22558 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
22559 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
22561 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
22563 if (caps
.VertexShaderVersion
< tests
[i
].vs_version
22564 || caps
.PixelShaderVersion
< tests
[i
].ps_version
)
22566 skip("Vertex / pixel shader version not supported, skipping test %u.\n", i
);
22571 hr
= IDirect3DDevice9_CreateVertexShader(device
, tests
[i
].vs
, &vs
);
22572 ok(SUCCEEDED(hr
), "Failed to create vertex shader, hr %#x (case %u).\n", hr
, i
);
22580 hr
= IDirect3DDevice9_CreatePixelShader(device
, tests
[i
].ps
, &ps
);
22581 ok(SUCCEEDED(hr
), "Failed to create pixel shader, hr %#x (case %u).\n", hr
, i
);
22588 hr
= IDirect3DDevice9_SetVertexShader(device
, vs
);
22589 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
22590 hr
= IDirect3DDevice9_SetPixelShader(device
, ps
);
22591 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
22593 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0f
, 0);
22594 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
22596 hr
= IDirect3DDevice9_BeginScene(device
);
22597 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
22599 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(quad
[0]));
22600 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
22602 hr
= IDirect3DDevice9_EndScene(device
);
22603 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
22605 color
= getPixelColor(device
, 320, 240);
22606 ok(color_match(color
, tests
[i
].expected
, 1) || broken(color_match(color
, tests
[i
].broken
, 1)),
22607 "Got unexpected color 0x%08x, case %u.\n", color
, i
);
22610 IDirect3DVertexShader9_Release(vs
);
22612 IDirect3DVertexShader9_Release(ps
);
22615 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
22616 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
22618 refcount
= IDirect3DDevice9_Release(device
);
22619 ok(!refcount
, "Device has %u references left.\n", refcount
);
22620 IDirect3D9_Release(d3d9
);
22621 DestroyWindow(window
);
22624 static void test_line_antialiasing_blending(void)
22626 IDirect3DDevice9
*device
;
22634 static const struct
22636 struct vec3 position
;
22641 {{-1.0f
, -1.0f
, 0.1f
}, D3DCOLOR_ARGB(0x7f, 0x00, 0xff, 0x00)},
22642 {{-1.0f
, 1.0f
, 0.1f
}, D3DCOLOR_ARGB(0x7f, 0x00, 0xff, 0x00)},
22643 {{ 1.0f
, -1.0f
, 0.1f
}, D3DCOLOR_ARGB(0x7f, 0x00, 0xff, 0x00)},
22644 {{ 1.0f
, 1.0f
, 0.1f
}, D3DCOLOR_ARGB(0x7f, 0x00, 0xff, 0x00)},
22646 static const struct
22648 struct vec3 position
;
22653 {{-1.0f
, -1.0f
, 0.1f
}, D3DCOLOR_ARGB(0xcc, 0xff, 0x00, 0x00)},
22654 {{-1.0f
, 1.0f
, 0.1f
}, D3DCOLOR_ARGB(0xcc, 0xff, 0x00, 0x00)},
22655 {{ 1.0f
, -1.0f
, 0.1f
}, D3DCOLOR_ARGB(0xcc, 0xff, 0x00, 0x00)},
22656 {{ 1.0f
, 1.0f
, 0.1f
}, D3DCOLOR_ARGB(0xcc, 0xff, 0x00, 0x00)},
22659 window
= create_window();
22660 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
22661 ok(!!d3d9
, "Failed to create a D3D object.\n");
22662 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
22664 skip("Failed to create a D3D device.\n");
22665 IDirect3D9_Release(d3d9
);
22666 DestroyWindow(window
);
22670 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
22671 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
22672 trace("Line antialiasing support: %#x.\n", caps
.LineCaps
& D3DLINECAPS_ANTIALIAS
);
22674 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CLIPPING
, FALSE
);
22675 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
22676 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
22677 ok(SUCCEEDED(hr
), "Failed to disable Z test, hr %#x.\n", hr
);
22678 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
22679 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
22681 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, TRUE
);
22682 ok(SUCCEEDED(hr
), "Failed to enable blending, hr %#x.\n", hr
);
22683 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_BLENDOP
, D3DBLENDOP_ADD
);
22684 ok(SUCCEEDED(hr
), "Failed to set blend op, hr %#x.\n", hr
);
22685 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_SRCALPHA
);
22686 ok(SUCCEEDED(hr
), "Failed to set src blend, hr %#x.\n", hr
);
22687 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_DESTALPHA
);
22688 ok(SUCCEEDED(hr
), "Failed to set dest blend, hr %#x.\n", hr
);
22690 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
22691 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
22692 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_DIFFUSE
);
22693 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
22694 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
);
22695 ok(SUCCEEDED(hr
), "Failed to set alpha op, hr %#x.\n", hr
);
22696 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_ALPHAARG1
, D3DTA_DIFFUSE
);
22697 ok(SUCCEEDED(hr
), "Failed to set alpha arg, hr %#x.\n", hr
);
22699 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
22700 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
22702 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xccff0000, 0.0f
, 0);
22703 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
22704 hr
= IDirect3DDevice9_BeginScene(device
);
22705 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
22706 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, green_quad
, sizeof(*green_quad
));
22707 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
22708 hr
= IDirect3DDevice9_EndScene(device
);
22709 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
22710 color
= getPixelColor(device
, 320, 240);
22711 ok(color_match(color
, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color
);
22713 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x7f00ff00, 0.0f
, 0);
22714 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
22715 hr
= IDirect3DDevice9_BeginScene(device
);
22716 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
22717 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, red_quad
, sizeof(*red_quad
));
22718 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
22719 hr
= IDirect3DDevice9_EndScene(device
);
22720 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
22721 color
= getPixelColor(device
, 320, 240);
22722 ok(color_match(color
, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color
);
22724 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, FALSE
);
22725 ok(SUCCEEDED(hr
), "Failed to disable blending, hr %#x.\n", hr
);
22727 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xccff0000, 0.0f
, 0);
22728 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
22729 hr
= IDirect3DDevice9_BeginScene(device
);
22730 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
22731 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, green_quad
, sizeof(*green_quad
));
22732 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
22733 hr
= IDirect3DDevice9_EndScene(device
);
22734 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
22735 color
= getPixelColor(device
, 320, 240);
22736 ok(color_match(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
22738 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x7f00ff00, 0.0f
, 0);
22739 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
22740 hr
= IDirect3DDevice9_BeginScene(device
);
22741 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
22742 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, red_quad
, sizeof(*red_quad
));
22743 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
22744 hr
= IDirect3DDevice9_EndScene(device
);
22745 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
22746 color
= getPixelColor(device
, 320, 240);
22747 ok(color_match(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
22749 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ANTIALIASEDLINEENABLE
, TRUE
);
22750 ok(SUCCEEDED(hr
), "Failed to enable line antialiasing, hr %#x.\n", hr
);
22752 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xccff0000, 0.0f
, 0);
22753 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
22754 hr
= IDirect3DDevice9_BeginScene(device
);
22755 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
22756 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, green_quad
, sizeof(*green_quad
));
22757 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
22758 hr
= IDirect3DDevice9_EndScene(device
);
22759 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
22760 color
= getPixelColor(device
, 320, 240);
22761 ok(color_match(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
22763 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x7f00ff00, 0.0f
, 0);
22764 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
22765 hr
= IDirect3DDevice9_BeginScene(device
);
22766 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
22767 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, red_quad
, sizeof(*red_quad
));
22768 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
22769 hr
= IDirect3DDevice9_EndScene(device
);
22770 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
22771 color
= getPixelColor(device
, 320, 240);
22772 ok(color_match(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
22774 refcount
= IDirect3DDevice9_Release(device
);
22775 ok(!refcount
, "Device has %u references left.\n", refcount
);
22776 IDirect3D9_Release(d3d9
);
22777 DestroyWindow(window
);
22780 static void test_dsy(void)
22782 static const DWORD vs_code
[] =
22784 0xfffe0300, /* vs_3_0 */
22785 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
22786 0x0200001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
22787 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
22788 0x0200001f, 0x8000000a, 0xe00f0001, /* dcl_color0 o1 */
22789 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
22790 0x02000001, 0xe00f0001, 0x90e40001, /* mov o1, v1 */
22793 static const DWORD ps_code
[] =
22795 0xffff0300, /* ps_3_0 */
22796 0x0200001f, 0x8000000a, 0x900f0000, /* dcl_color0 v0 */
22797 0x05000051, 0xa00f0000, 0x43700000, 0x3f000000, 0x00000000, 0x00000000, /* def c0, 240.0, 0.5, 0.0, 0.0 */
22798 0x0200005c, 0x800f0000, 0x90e40000, /* dsy r0, v0 */
22799 0x03000005, 0x800f0000, 0x80e40000, 0xa0000000, /* mul r0, r0, c0.x */
22800 0x03000002, 0x800f0800, 0x80e40000, 0xa0550000, /* add oC0, r0, c0.y */
22803 static const struct
22810 {{-1.0f
, -1.0f
, 0.1f
}, 0x00ff0000},
22811 {{-1.0f
, 1.0f
, 0.1f
}, 0x0000ff00},
22812 {{ 1.0f
, -1.0f
, 0.1f
}, 0x00ff0000},
22813 {{ 1.0f
, 1.0f
, 0.1f
}, 0x0000ff00},
22815 IDirect3DSurface9
*backbuffer
, *rt
;
22816 IDirect3DVertexShader9
*vs
;
22817 IDirect3DPixelShader9
*ps
;
22818 IDirect3DDevice9
*device
;
22826 window
= create_window();
22827 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
22828 ok(!!d3d
, "Failed to create a D3D object.\n");
22829 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
22831 skip("Failed to create a D3D device, skipping tests.\n");
22835 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
22836 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
22837 if (caps
.PixelShaderVersion
< D3DPS_VERSION(3, 0))
22839 skip("No ps_3_0 support, skipping dsy tests.\n");
22840 IDirect3DDevice9_Release(device
);
22844 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
22845 ok(SUCCEEDED(hr
), "Failed to get backbuffer, hr %#x.\n", hr
);
22847 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 640, 480, D3DFMT_A8R8G8B8
,
22848 D3DMULTISAMPLE_NONE
, 0, FALSE
, &rt
, NULL
);
22849 ok(SUCCEEDED(hr
), "Failed to create offscreen render target, hr %#x.\n", hr
);
22850 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, rt
);
22851 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
22853 hr
= IDirect3DDevice9_CreateVertexShader(device
, vs_code
, &vs
);
22854 ok(SUCCEEDED(hr
), "Failed to create vertex shader, hr %#x.\n", hr
);
22855 hr
= IDirect3DDevice9_CreatePixelShader(device
, ps_code
, &ps
);
22856 ok(SUCCEEDED(hr
), "Failed to create pixel shader, hr %#x.\n", hr
);
22858 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
22859 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
22860 hr
= IDirect3DDevice9_SetVertexShader(device
, vs
);
22861 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
22862 hr
= IDirect3DDevice9_SetPixelShader(device
, ps
);
22863 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
22865 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff000000, 1.0f
, 0);
22866 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
22867 hr
= IDirect3DDevice9_BeginScene(device
);
22868 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
22869 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
22870 ok(SUCCEEDED(hr
), "Failed to draw primitive, hr %#x.\n", hr
);
22871 hr
= IDirect3DDevice9_EndScene(device
);
22872 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
22874 color
= getPixelColor(device
, 360, 240);
22875 ok(color_match(color
, 0x00ff007f, 1), "Got unexpected color 0x%08x.\n", color
);
22877 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
22878 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
22880 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff000000, 1.0f
, 0);
22881 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
22882 hr
= IDirect3DDevice9_BeginScene(device
);
22883 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
22884 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(quad
[0]));
22885 ok(SUCCEEDED(hr
), "Failed to draw primitive, hr %#x.\n", hr
);
22886 hr
= IDirect3DDevice9_EndScene(device
);
22887 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
22889 color
= getPixelColor(device
, 360, 240);
22890 ok(color_match(color
, 0x00ff007f, 1), "Got unexpected color 0x%08x.\n", color
);
22892 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
22893 ok(SUCCEEDED(hr
), "Failed to present frame, hr %#x.\n", hr
);
22895 IDirect3DSurface9_Release(rt
);
22896 IDirect3DSurface9_Release(backbuffer
);
22897 IDirect3DVertexShader9_Release(vs
);
22898 IDirect3DPixelShader9_Release(ps
);
22900 refcount
= IDirect3DDevice9_Release(device
);
22901 ok(!refcount
, "Device has %u references left.\n", refcount
);
22903 IDirect3D9_Release(d3d
);
22904 DestroyWindow(window
);
22907 static void test_evict_bound_resources(void)
22909 IDirect3DVertexBuffer9
*vb
;
22910 IDirect3DIndexBuffer9
*ib
;
22911 IDirect3DDevice9
*device
;
22919 static const struct
22921 struct vec3 position
;
22926 {{-1.0f
, -1.0f
, 0.1f
}, D3DCOLOR_ARGB(0x7f, 0x00, 0xff, 0x00)},
22927 {{-1.0f
, 1.0f
, 0.1f
}, D3DCOLOR_ARGB(0x7f, 0x00, 0xff, 0x00)},
22928 {{ 1.0f
, -1.0f
, 0.1f
}, D3DCOLOR_ARGB(0x7f, 0x00, 0xff, 0x00)},
22929 {{ 1.0f
, 1.0f
, 0.1f
}, D3DCOLOR_ARGB(0x7f, 0x00, 0xff, 0x00)},
22931 static const unsigned short indices
[] = {0, 1, 2, 3, 2, 1};
22933 window
= create_window();
22934 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
22935 ok(!!d3d9
, "Failed to create a D3D object.\n");
22937 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
22939 skip("Failed to create a D3D device.\n");
22940 IDirect3D9_Release(d3d9
);
22941 DestroyWindow(window
);
22945 hr
= IDirect3DDevice9_CreateIndexBuffer(device
, sizeof(indices
), 0,
22946 D3DFMT_INDEX16
, D3DPOOL_MANAGED
, &ib
, NULL
);
22947 ok(SUCCEEDED(hr
), "Failed to create index buffer, hr %#x.\n", hr
);
22949 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, sizeof(green_quad
), 0,
22950 D3DFVF_XYZ
| D3DFVF_DIFFUSE
, D3DPOOL_MANAGED
, &vb
, NULL
);
22951 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
22953 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CLIPPING
, FALSE
);
22954 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
22955 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
22956 ok(SUCCEEDED(hr
), "Failed to disable Z test, hr %#x.\n", hr
);
22957 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
22958 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
22960 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
22961 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
22963 hr
= IDirect3DVertexBuffer9_Lock(vb
, 0, sizeof(green_quad
), &data
, 0);
22964 ok(hr
== D3D_OK
, "Failed to lock vertex buffer, hr %#x.\n", hr
);
22965 memcpy(data
, green_quad
, sizeof(green_quad
));
22966 hr
= IDirect3DVertexBuffer9_Unlock(vb
);
22967 ok(hr
== D3D_OK
, "Failed to unlock vertex buffer, hr %#x.\n", hr
);
22969 hr
= IDirect3DIndexBuffer9_Lock(ib
, 0, sizeof(indices
), &data
, 0);
22970 ok(hr
== D3D_OK
, "Failed to lock index buffer, hr %#x.\n", hr
);
22971 memcpy(data
, indices
, sizeof(indices
));
22972 hr
= IDirect3DIndexBuffer9_Unlock(ib
);
22973 ok(hr
== D3D_OK
, "Failed to unlock index buffer, hr %#x.\n", hr
);
22975 hr
= IDirect3DDevice9_SetIndices(device
, ib
);
22976 ok(hr
== D3D_OK
, "Failed to set index buffer, hr %#x.\n", hr
);
22977 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vb
, 0, sizeof(*green_quad
));
22978 ok(hr
== D3D_OK
, "Failed to set stream source, hr %#x.\n", hr
);
22980 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
22981 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
22982 hr
= IDirect3DDevice9_BeginScene(device
);
22983 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
22984 hr
= IDirect3DDevice9_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, 0, 0, 4, 0, 2);
22985 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
22986 hr
= IDirect3DDevice9_EndScene(device
);
22987 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
22988 color
= getPixelColor(device
, 320, 240);
22989 ok(color_match(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
22991 hr
= IDirect3DDevice9_EvictManagedResources(device
);
22992 ok(hr
== D3D_OK
, "Failed to evict managed resources, hr %#x.\n", hr
);
22994 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
22995 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
22996 hr
= IDirect3DDevice9_BeginScene(device
);
22997 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
22998 hr
= IDirect3DDevice9_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, 0, 0, 4, 0, 2);
22999 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
23000 hr
= IDirect3DDevice9_EndScene(device
);
23001 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
23002 color
= getPixelColor(device
, 320, 240);
23003 ok(color_match(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
23005 IDirect3DIndexBuffer9_Release(ib
);
23006 IDirect3DVertexBuffer9_Release(vb
);
23007 refcount
= IDirect3DDevice9_Release(device
);
23008 ok(!refcount
, "Device has %u references left.\n", refcount
);
23009 IDirect3D9_Release(d3d9
);
23010 DestroyWindow(window
);
23013 /* This test shows that 0xffff is valid index in D3D9. */
23014 static void test_max_index16(void)
23016 static const struct vertex
23018 struct vec3 position
;
23023 {{-1.0f
, -1.0f
, 0.1f
}, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00)},
23024 {{-1.0f
, 1.0f
, 0.1f
}, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00)},
23025 {{ 1.0f
, -1.0f
, 0.1f
}, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00)},
23026 {{ 1.0f
, 1.0f
, 0.1f
}, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00)},
23028 static const unsigned short indices
[] = {0, 1, 2, 0xffff};
23029 static const unsigned int vertex_count
= 0xffff + 1;
23031 D3DADAPTER_IDENTIFIER9 identifier
;
23032 IDirect3DVertexBuffer9
*vb
;
23033 IDirect3DIndexBuffer9
*ib
;
23034 IDirect3DDevice9
*device
;
23035 struct vertex
*vb_data
;
23045 window
= create_window();
23046 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
23047 ok(!!d3d9
, "Failed to create a D3D object.\n");
23049 hr
= IDirect3D9_GetAdapterIdentifier(d3d9
, D3DADAPTER_DEFAULT
, 0, &identifier
);
23050 ok(SUCCEEDED(hr
), "Failed to get adapter identifier, hr %#x.\n", hr
);
23051 warp
= adapter_is_warp(&identifier
);
23053 if (!(device
= create_device(d3d9
, window
, window
, TRUE
)))
23055 skip("Failed to create a D3D device.\n");
23056 IDirect3D9_Release(d3d9
);
23057 DestroyWindow(window
);
23061 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
23062 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
23063 if (caps
.MaxVertexIndex
< 0xffff)
23065 skip("Max vertex index is lower than 0xffff (%#x).\n", caps
.MaxVertexIndex
);
23066 IDirect3DDevice9_Release(device
);
23067 IDirect3D9_Release(d3d9
);
23068 DestroyWindow(window
);
23072 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, vertex_count
* sizeof(*green_quad
), 0,
23073 D3DFVF_XYZ
| D3DFVF_DIFFUSE
, D3DPOOL_MANAGED
, &vb
, NULL
);
23074 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
23076 hr
= IDirect3DDevice9_CreateIndexBuffer(device
, sizeof(indices
), 0,
23077 D3DFMT_INDEX16
, D3DPOOL_MANAGED
, &ib
, NULL
);
23078 ok(SUCCEEDED(hr
), "Failed to create index buffer, hr %#x.\n", hr
);
23080 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CLIPPING
, FALSE
);
23081 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
23082 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
23083 ok(SUCCEEDED(hr
), "Failed to disable Z test, hr %#x.\n", hr
);
23084 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
23085 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
23087 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
23088 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
23090 hr
= IDirect3DVertexBuffer9_Lock(vb
, 0, sizeof(green_quad
), (void **)&vb_data
, 0);
23091 ok(hr
== D3D_OK
, "Failed to lock vertex buffer, hr %#x.\n", hr
);
23092 vb_data
[0] = green_quad
[0];
23093 vb_data
[1] = green_quad
[1];
23094 vb_data
[2] = green_quad
[2];
23095 vb_data
[0xffff] = green_quad
[3];
23096 hr
= IDirect3DVertexBuffer9_Unlock(vb
);
23097 ok(hr
== D3D_OK
, "Failed to unlock vertex buffer, hr %#x.\n", hr
);
23099 hr
= IDirect3DIndexBuffer9_Lock(ib
, 0, sizeof(indices
), &data
, 0);
23100 ok(hr
== D3D_OK
, "Failed to lock index buffer, hr %#x.\n", hr
);
23101 memcpy(data
, indices
, sizeof(indices
));
23102 hr
= IDirect3DIndexBuffer9_Unlock(ib
);
23103 ok(hr
== D3D_OK
, "Failed to unlock index buffer, hr %#x.\n", hr
);
23105 hr
= IDirect3DDevice9_SetIndices(device
, ib
);
23106 ok(hr
== D3D_OK
, "Failed to set index buffer, hr %#x.\n", hr
);
23107 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vb
, 0, sizeof(struct vertex
));
23108 ok(hr
== D3D_OK
, "Failed to set stream source, hr %#x.\n", hr
);
23110 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
23111 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
23112 hr
= IDirect3DDevice9_BeginScene(device
);
23113 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
23114 hr
= IDirect3DDevice9_DrawIndexedPrimitive(device
, D3DPT_TRIANGLESTRIP
, 0, 0, vertex_count
, 0, 2);
23115 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
23116 hr
= IDirect3DDevice9_EndScene(device
);
23117 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
23118 color
= getPixelColor(device
, 20, 20);
23119 ok(color_match(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
23120 color
= getPixelColor(device
, 320, 240);
23121 ok(color_match(color
, 0x0000ff00, 1) || broken(warp
), "Got unexpected color 0x%08x.\n", color
);
23122 color
= getPixelColor(device
, 620, 460);
23123 ok(color_match(color
, 0x0000ff00, 1) || broken(warp
), "Got unexpected color 0x%08x.\n", color
);
23125 IDirect3DIndexBuffer9_Release(ib
);
23126 IDirect3DVertexBuffer9_Release(vb
);
23127 refcount
= IDirect3DDevice9_Release(device
);
23128 ok(!refcount
, "Device has %u references left.\n", refcount
);
23129 IDirect3D9_Release(d3d9
);
23130 DestroyWindow(window
);
23133 static void test_backbuffer_resize(void)
23135 D3DPRESENT_PARAMETERS present_parameters
= {0};
23136 IDirect3DSurface9
*backbuffer
;
23137 IDirect3DDevice9
*device
;
23144 static const struct
23146 struct vec3 position
;
23151 {{-1.0f
, -1.0f
, 0.1f
}, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00)},
23152 {{-1.0f
, 1.0f
, 0.1f
}, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00)},
23153 {{ 1.0f
, -1.0f
, 0.1f
}, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00)},
23154 {{ 1.0f
, 1.0f
, 0.1f
}, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00)},
23157 window
= create_window();
23158 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
23159 ok(!!d3d
, "Failed to create a D3D object.\n");
23160 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
23162 skip("Failed to create a D3D device.\n");
23166 /* Wine d3d9 implementation had a bug which was triggered by a
23167 * SetRenderTarget() call with an unreferenced surface. */
23168 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
23169 ok(SUCCEEDED(hr
), "Failed to get backbuffer, hr %#x.\n", hr
);
23170 refcount
= IDirect3DSurface9_Release(backbuffer
);
23171 ok(!refcount
, "Surface has %u references left.\n", refcount
);
23172 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
23173 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
23174 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
23175 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
23177 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 1.0f
, 0);
23178 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
23179 color
= getPixelColor(device
, 1, 1);
23180 ok(color
== 0x00ff0000, "Got unexpected color 0x%08x.\n", color
);
23182 present_parameters
.BackBufferWidth
= 800;
23183 present_parameters
.BackBufferHeight
= 600;
23184 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
23185 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
23186 present_parameters
.hDeviceWindow
= NULL
;
23187 present_parameters
.Windowed
= TRUE
;
23188 present_parameters
.EnableAutoDepthStencil
= TRUE
;
23189 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
23190 hr
= IDirect3DDevice9_Reset(device
, &present_parameters
);
23191 ok(SUCCEEDED(hr
), "Failed to reset, hr %#x.\n", hr
);
23193 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CLIPPING
, FALSE
);
23194 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
23195 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
23196 ok(SUCCEEDED(hr
), "Failed to disable Z test, hr %#x.\n", hr
);
23197 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
23198 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
23199 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
23200 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
23202 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
23203 ok(SUCCEEDED(hr
), "Failed to get backbuffer, hr %#x.\n", hr
);
23204 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
23205 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
23206 IDirect3DSurface9_Release(backbuffer
);
23208 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffff00, 1.0f
, 0);
23209 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
23210 color
= getPixelColor(device
, 1, 1);
23211 ok(color
== 0x00ffff00, "Got unexpected color 0x%08x.\n", color
);
23212 color
= getPixelColor(device
, 700, 500);
23213 ok(color
== 0x00ffff00, "Got unexpected color 0x%08x.\n", color
);
23215 hr
= IDirect3DDevice9_BeginScene(device
);
23216 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
23217 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
23218 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
23219 hr
= IDirect3DDevice9_EndScene(device
);
23220 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
23221 color
= getPixelColor(device
, 1, 1);
23222 ok(color
== 0x0000ff00, "Got unexpected color 0x%08x.\n", color
);
23223 color
= getPixelColor(device
, 700, 500);
23224 ok(color
== 0x0000ff00, "Got unexpected color 0x%08x.\n", color
);
23226 refcount
= IDirect3DDevice9_Release(device
);
23227 ok(!refcount
, "Device has %u references left.\n", refcount
);
23229 IDirect3D9_Release(d3d
);
23230 DestroyWindow(window
);
23233 static void test_drawindexedprimitiveup(void)
23235 static const struct vertex
23237 struct vec3 position
;
23242 {{-1.0f
, -1.0f
, 0.1f
}, 0xff00ff00},
23243 {{-1.0f
, 1.0f
, 0.1f
}, 0xff0000ff},
23244 {{ 1.0f
, -1.0f
, 0.1f
}, 0xffff0000},
23245 {{ 1.0f
, 1.0f
, 0.1f
}, 0xff0000ff},
23247 {{-1.0f
, -1.0f
, 0.1f
}, 0xff0000ff},
23248 {{-1.0f
, 1.0f
, 0.1f
}, 0xff00ff00},
23249 {{ 1.0f
, -1.0f
, 0.1f
}, 0xffff0000},
23250 {{ 1.0f
, 1.0f
, 0.1f
}, 0xff00ff00},
23252 static const unsigned short indices
[] = {0, 1, 2, 3, 4, 5, 6, 7};
23253 IDirect3DVertexBuffer9
*vb
;
23254 IDirect3DDevice9
*device
;
23255 UINT offset
, stride
;
23262 window
= create_window();
23263 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
23264 ok(!!d3d
, "Failed to create a D3D object.\n");
23266 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
23268 skip("Failed to create a D3D device.\n");
23269 IDirect3D9_Release(d3d
);
23270 DestroyWindow(window
);
23274 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CLIPPING
, FALSE
);
23275 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
23276 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
23277 ok(SUCCEEDED(hr
), "Failed to disable Z test, hr %#x.\n", hr
);
23278 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
23279 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
23281 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
23282 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
23284 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
23285 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
23287 hr
= IDirect3DDevice9_BeginScene(device
);
23288 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
23289 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 4, 4, 2, indices
+ 4, D3DFMT_INDEX16
, quad
, sizeof(*quad
));
23290 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
23291 hr
= IDirect3DDevice9_EndScene(device
);
23292 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
23294 color
= getPixelColor(device
, 160, 120);
23295 ok(color_match(color
, 0x0040bf00, 1), "Got unexpected color 0x%08x.\n", color
);
23296 color
= getPixelColor(device
, 480, 120);
23297 ok(color_match(color
, 0x0040bf00, 1), "Got unexpected color 0x%08x.\n", color
);
23298 color
= getPixelColor(device
, 160, 360);
23299 ok(color_match(color
, 0x00404080, 1), "Got unexpected color 0x%08x.\n", color
);
23300 color
= getPixelColor(device
, 480, 360);
23301 ok(color_match(color
, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color
);
23303 hr
= IDirect3DDevice9_GetStreamSource(device
, 0, &vb
, &offset
, &stride
);
23304 ok(SUCCEEDED(hr
), "GetStreamSource failed, hr %#x.\n", hr
);
23305 ok(!vb
, "Unexpected vb %p.\n", vb
);
23306 ok(!offset
, "Unexpected offset %u.\n", offset
);
23307 ok(!stride
, "Unexpected stride %u.\n", stride
);
23309 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
23310 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
23312 hr
= IDirect3DDevice9_BeginScene(device
);
23313 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
23314 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 0, 4, 2, indices
, D3DFMT_INDEX16
, quad
, sizeof(*quad
));
23315 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
23316 hr
= IDirect3DDevice9_EndScene(device
);
23317 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
23319 color
= getPixelColor(device
, 160, 120);
23320 ok(color_match(color
, 0x004000bf, 1), "Got unexpected color 0x%08x.\n", color
);
23321 color
= getPixelColor(device
, 480, 120);
23322 ok(color_match(color
, 0x004000bf, 1), "Got unexpected color 0x%08x.\n", color
);
23323 color
= getPixelColor(device
, 160, 360);
23324 ok(color_match(color
, 0x00408040, 1), "Got unexpected color 0x%08x.\n", color
);
23325 color
= getPixelColor(device
, 480, 360);
23326 ok(color_match(color
, 0x00bf0040, 1), "Got unexpected color 0x%08x.\n", color
);
23328 refcount
= IDirect3DDevice9_Release(device
);
23329 ok(!refcount
, "Device has %u references left.\n", refcount
);
23330 IDirect3D9_Release(d3d
);
23331 DestroyWindow(window
);
23334 static void test_vertex_texture(void)
23336 static const D3DVERTEXELEMENT9 decl_elements
[] =
23338 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
23341 static const struct vec3 quad
[] =
23343 {-1.0f
, -1.0f
, 0.0f
},
23344 {-1.0f
, 1.0f
, 0.0f
},
23345 { 1.0f
, -1.0f
, 0.0f
},
23346 { 1.0f
, 1.0f
, 0.0f
},
23348 static const DWORD vs_code
[] =
23350 0xfffe0300, /* vs_3_0 */
23351 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 0, 0, 0, 0 */
23352 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
23353 0x0200001f, 0x90000000, 0xa00f0800, /* dcl_2d s0 */
23354 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
23355 0x0200001f, 0x8000000a, 0xe00f0001, /* dcl_color o1 */
23356 0x0300005f, 0xe00f0001, 0xa0000000, 0xa0e40800, /* texldl o1, c0.x, s0 */
23357 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
23358 0x0000ffff, /* end */
23360 static const DWORD ps_code
[] =
23362 0xffff0300, /* ps_3_0 */
23363 0x0200001f, 0x8000000a, 0x900f0000, /* dcl_color v0 */
23364 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
23365 0x0000ffff, /* end */
23367 static const DWORD texture_data
[4] = {0x00ffff00, 0x00ffff00, 0x00ffff00, 0x00ffff00};
23368 IDirect3DVertexDeclaration9
*declaration
;
23369 IDirect3DTexture9
*texture
;
23370 IDirect3DVertexShader9
*vs
;
23371 IDirect3DPixelShader9
*ps
;
23372 IDirect3DDevice9
*device
;
23381 window
= create_window();
23382 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
23383 ok(!!d3d
, "Failed to create D3D object.\n");
23385 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
23387 skip("Failed to create D3D device.\n");
23388 IDirect3D9_Release(d3d
);
23389 DestroyWindow(window
);
23393 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
23394 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
23395 if (caps
.VertexShaderVersion
< D3DVS_VERSION(3, 0) || caps
.PixelShaderVersion
< D3DPS_VERSION(3, 0))
23397 skip("SM3 is not supported.\n");
23400 if (!(caps
.VertexTextureFilterCaps
& D3DPTFILTERCAPS_MAGFPOINT
)
23401 || !(caps
.VertexTextureFilterCaps
& D3DPTFILTERCAPS_MINFPOINT
))
23403 skip("Vertex texture point filtering is not supported, caps %#x.\n", caps
.VertexTextureFilterCaps
);
23406 hr
= IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
23407 D3DUSAGE_QUERY_VERTEXTEXTURE
, D3DRTYPE_TEXTURE
, D3DFMT_A8R8G8B8
);
23410 skip("No vertex texture fetch support for D3DFMT_A8R8G8B8, hr %#x.\n", hr
);
23414 hr
= IDirect3DDevice9_CreateTexture(device
, 2, 2, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &texture
, NULL
);
23415 ok(hr
== D3D_OK
, "Failed to create texture, hr %#x.\n", hr
);
23416 memset(&lr
, 0, sizeof(lr
));
23417 hr
= IDirect3DTexture9_LockRect(texture
, 0, &lr
, NULL
, 0);
23418 ok(hr
== D3D_OK
, "Failed to lock texture, hr %#x.\n", hr
);
23419 memcpy(lr
.pBits
, texture_data
, sizeof(texture_data
));
23420 hr
= IDirect3DTexture9_UnlockRect(texture
, 0);
23421 ok(hr
== D3D_OK
, "Failed to unlock texture, hr %#x.\n", hr
);
23423 hr
= IDirect3DDevice9_SetTexture(device
, D3DVERTEXTEXTURESAMPLER0
, (IDirect3DBaseTexture9
*)texture
);
23424 ok(hr
== D3D_OK
, "Failed to set texture, hr %#x.\n", hr
);
23426 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &declaration
);
23427 ok(SUCCEEDED(hr
), "Failed to create vertex declaration, hr %#x.\n", hr
);
23428 hr
= IDirect3DDevice9_CreateVertexShader(device
, vs_code
, &vs
);
23429 ok(SUCCEEDED(hr
), "Failed to create vertex shader, hr %#x.\n", hr
);
23430 hr
= IDirect3DDevice9_CreatePixelShader(device
, ps_code
, &ps
);
23431 ok(SUCCEEDED(hr
), "Failed to create pixel shader, hr %#x.\n", hr
);
23433 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, declaration
);
23434 ok(SUCCEEDED(hr
), "Failed to set vertex declaration, hr %#x.\n", hr
);
23435 hr
= IDirect3DDevice9_SetVertexShader(device
, vs
);
23436 ok(SUCCEEDED(hr
), "Failed to set vertex shader, hr %#x.\n", hr
);
23437 hr
= IDirect3DDevice9_SetPixelShader(device
, ps
);
23438 ok(SUCCEEDED(hr
), "Failed to set pixel shader, hr %#x.\n", hr
);
23440 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
23441 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
23442 hr
= IDirect3DDevice9_BeginScene(device
);
23443 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
23444 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
23445 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
23446 hr
= IDirect3DDevice9_EndScene(device
);
23447 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
23448 color
= getPixelColor(device
, 160, 360);
23449 ok(color
== texture_data
[0], "Got unexpected color 0x%08x.\n", color
);
23451 IDirect3DPixelShader9_Release(ps
);
23452 IDirect3DVertexShader9_Release(vs
);
23453 IDirect3DTexture9_Release(texture
);
23454 IDirect3DVertexDeclaration9_Release(declaration
);
23456 refcount
= IDirect3DDevice9_Release(device
);
23457 ok(!refcount
, "Device has %u references left.\n", refcount
);
23458 IDirect3D9_Release(d3d
);
23459 DestroyWindow(window
);
23462 static void test_mvp_software_vertex_shaders(void)
23464 IDirect3DVertexDeclaration9
*vertex_declaration
;
23465 D3DPRESENT_PARAMETERS present_parameters
= {0};
23466 IDirect3DVertexShader9
*pure_sw_shader
= NULL
;
23467 IDirect3DVertexShader9
*reladdr_shader
= NULL
;
23468 IDirect3DDevice9
*device
;
23469 DWORD expected_color
;
23477 static const float c_index
[4] = {256.0f
, 0.0f
, 0.0f
, 0.0f
};
23478 static const float c_color
[4] = {0.0f
, 1.0f
, 0.0f
, 1.0f
};
23479 static const DWORD reladdr_shader_code
[] =
23481 0xfffe0200, /* vs_2_0 */
23482 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
23483 0x05000051, 0xa00f0001, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c1, 1.0, 1.0, 1.0, 1.0 */
23484 0x0200002e, 0xb0010000, 0xa0000000, /* mova a0.x, c0.x */
23485 0x03000001, 0xd00f0000, 0xa0e42000, 0xb0000000, /* mov oD0, c[a0.x] */
23486 0x02000001, 0xd0040000, 0xa0e40001, /* mov oD0.z, c1 */
23487 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
23488 0x0000ffff /* END */
23490 static const DWORD pure_sw_shader_code
[] =
23492 0xfffe0200, /* vs_2_0 */
23493 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
23494 0x05000051, 0xa00f0100, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c256, 1.0, 1.0, 1.0, 1.0 */
23495 0x02000001, 0xd00f0000, 0xa0e40100, /* mov oD0, c256 */
23496 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
23497 0x0000ffff /* END */
23500 static const struct
23507 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
23508 {{-1.0f
, 1.0f
, 0.0f
}, 0xffff0000},
23509 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffff0000},
23510 {{ 1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
23512 static const D3DVERTEXELEMENT9 decl_elements
[] =
23514 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
23515 {0, 12, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
23519 window
= create_window();
23520 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
23521 ok(!!d3d
, "Failed to create a D3D object.\n");
23523 present_parameters
.Windowed
= TRUE
;
23524 present_parameters
.hDeviceWindow
= window
;
23525 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
23526 present_parameters
.BackBufferWidth
= 640;
23527 present_parameters
.BackBufferHeight
= 480;
23528 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
23529 present_parameters
.EnableAutoDepthStencil
= TRUE
;
23530 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
23532 if (FAILED(IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, window
,
23533 D3DCREATE_MIXED_VERTEXPROCESSING
, &present_parameters
, &device
)))
23535 skip("Failed to create a D3D device, skipping tests.\n");
23539 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
23540 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
23541 if (caps
.VertexShaderVersion
< D3DVS_VERSION(2, 0))
23543 skip("No vs_2_0 support, skipping tests.\n");
23544 IDirect3DDevice9_Release(device
);
23548 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
23549 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
23551 hr
= IDirect3DDevice9_SetSoftwareVertexProcessing(device
, 0);
23552 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23554 hr
= IDirect3DDevice9_CreateVertexShader(device
, reladdr_shader_code
, &reladdr_shader
);
23555 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23556 hr
= IDirect3DDevice9_CreateVertexShader(device
, pure_sw_shader_code
, &pure_sw_shader
);
23558 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23559 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &vertex_declaration
);
23560 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23561 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, vertex_declaration
);
23562 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23564 hr
= IDirect3DDevice9_SetVertexShader(device
, pure_sw_shader
);
23565 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23567 hr
= IDirect3DDevice9_BeginScene(device
);
23568 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23569 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
23571 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
23572 hr
= IDirect3DDevice9_EndScene(device
);
23573 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23575 expected_color
= 0; /* Nothing rendered. */
23576 color
= getPixelColor(device
, 5, 5);
23578 ok(color
== expected_color
, "Expected color 0x%08x, got 0x%08x (sw shader in hw mode).\n",
23579 expected_color
, color
);
23581 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
23582 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23583 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0, 0.0f
, 0);
23584 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23586 hr
= IDirect3DDevice9_BeginScene(device
);
23587 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23588 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
23589 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23590 hr
= IDirect3DDevice9_EndScene(device
);
23591 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23593 expected_color
= 0x00ff0000; /* Color from vertex data and not from the shader. */
23594 color
= getPixelColor(device
, 5, 5);
23595 ok(color
== expected_color
, "Expected color 0x%08x, got 0x%08x (sw shader in hw mode, second attempt).\n",
23596 expected_color
, color
);
23598 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
23599 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23600 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0, 0.0f
, 0);
23601 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23603 hr
= IDirect3DDevice9_BeginScene(device
);
23604 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23605 hr
= IDirect3DDevice9_SetSoftwareVertexProcessing(device
, 1);
23606 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23607 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
23608 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23609 hr
= IDirect3DDevice9_EndScene(device
);
23610 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23612 expected_color
= 0x00ffffff;
23613 color
= getPixelColor(device
, 5, 5);
23615 ok(color
== expected_color
, "Expected color 0x%08x, got 0x%08x (sw shader in sw mode).\n",
23616 expected_color
, color
);
23618 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
23619 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23620 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0, 0.0f
, 0);
23621 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23623 hr
= IDirect3DDevice9_SetSoftwareVertexProcessing(device
, 0);
23624 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23625 hr
= IDirect3DDevice9_SetVertexShader(device
, reladdr_shader
);
23626 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23628 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 0, c_index
, 1);
23629 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23630 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, (unsigned int)c_index
[0], c_color
, 1);
23632 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23634 hr
= IDirect3DDevice9_BeginScene(device
);
23635 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23636 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
23637 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23638 hr
= IDirect3DDevice9_EndScene(device
);
23639 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23641 /* Index 256 is out of bounds for selected shader in HW mode. c[256] is 0 most of the time. It
23642 is not guaranteed across all the adapters though, so disabling test. */
23644 expected_color
= 0x000000ff;
23645 color
= getPixelColor(device
, 5, 5);
23646 ok(color
== expected_color
, "Expected color 0x%08x, got 0x%08x (shader in hw mode).\n",
23647 expected_color
, color
);
23650 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
23651 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23652 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0, 0.0f
, 0);
23653 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23655 hr
= IDirect3DDevice9_BeginScene(device
);
23656 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23657 hr
= IDirect3DDevice9_SetSoftwareVertexProcessing(device
, 1);
23658 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
23659 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23660 hr
= IDirect3DDevice9_EndScene(device
);
23661 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
23663 expected_color
= 0x0000ffff; /* c[256] is c_color for SW shader. */
23664 color
= getPixelColor(device
, 5, 5);
23666 ok(color
== expected_color
, "Expected color 0x%08x, got 0x%08x (shader in sw mode).\n",
23667 expected_color
, color
);
23669 IDirect3DVertexDeclaration9_Release(vertex_declaration
);
23670 IDirect3DVertexShader9_Release(reladdr_shader
);
23671 if (pure_sw_shader
)
23672 IDirect3DVertexShader9_Release(pure_sw_shader
);
23673 refcount
= IDirect3DDevice9_Release(device
);
23674 ok(!refcount
, "Device has %u references left.\n", refcount
);
23676 IDirect3D9_Release(d3d
);
23677 DestroyWindow(window
);
23680 static void test_null_format(void)
23682 static const D3DVIEWPORT9 vp_lower
= {0, 60, 640, 420, 0.0f
, 1.0f
};
23683 static const D3DVIEWPORT9 vp_560
= {0, 180, 560, 300, 0.0f
, 1.0f
};
23684 static const D3DVIEWPORT9 vp_full
= {0, 0, 640, 480, 0.0f
, 1.0f
};
23685 static const DWORD null_fourcc
= MAKEFOURCC('N','U','L','L');
23686 static const struct
23693 {{-1.0f
, 0.5f
, 0.1f
}, 0x000000ff},
23694 {{ 0.5f
, 0.5f
, 0.1f
}, 0x000000ff},
23695 {{-1.0f
, -1.0f
, 0.1f
}, 0x000000ff},
23696 {{ 0.5f
, -1.0f
, 0.1f
}, 0x000000ff},
23700 {{-1.0f
, 1.0f
, 0.5f
}, 0x00ff0000},
23701 {{ 1.0f
, 1.0f
, 0.5f
}, 0x00ff0000},
23702 {{-1.0f
, -1.0f
, 0.5f
}, 0x00ff0000},
23703 {{ 1.0f
, -1.0f
, 0.5f
}, 0x00ff0000},
23707 {{-1.0f
, 1.0f
, 1.0f
}, 0x0000ff00},
23708 {{ 1.0f
, 1.0f
, 1.0f
}, 0x0000ff00},
23709 {{-1.0f
, -1.0f
, 1.0f
}, 0x0000ff00},
23710 {{ 1.0f
, -1.0f
, 1.0f
}, 0x0000ff00},
23712 static const struct
23717 expected_colors
[] =
23719 {200, 30, 0x0000ff00},
23720 {440, 30, 0x0000ff00},
23721 {520, 30, 0x0000ff00},
23722 {600, 30, 0x0000ff00},
23723 {200, 90, 0x00000000},
23724 {440, 90, 0x0000ff00},
23725 {520, 90, 0x0000ff00},
23726 {600, 90, 0x0000ff00},
23727 {200, 150, 0x000000ff},
23728 {440, 150, 0x000000ff},
23729 {520, 150, 0x0000ff00},
23730 {600, 150, 0x0000ff00},
23731 {200, 320, 0x000000ff},
23732 {440, 320, 0x000000ff},
23733 {520, 320, 0x00000000},
23734 {600, 320, 0x0000ff00},
23736 IDirect3DSurface9
*original_rt
, *small_rt
, *null_rt
, *small_null_rt
;
23737 IDirect3DDevice9
*device
;
23744 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
23745 ok(!!d3d
, "Failed to create a D3D object.\n");
23747 if (FAILED(IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
23748 D3DUSAGE_RENDERTARGET
, D3DRTYPE_SURFACE
, null_fourcc
)))
23750 skip("No NULL format support, skipping NULL test.\n");
23751 IDirect3D9_Release(d3d
);
23755 window
= create_window();
23756 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
23758 skip("Failed to create a D3D device.\n");
23759 IDirect3D9_Release(d3d
);
23760 DestroyWindow(window
);
23764 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &original_rt
);
23765 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
23767 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 400, 300, D3DFMT_A8R8G8B8
,
23768 D3DMULTISAMPLE_NONE
, 0, FALSE
, &small_rt
, NULL
);
23769 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
23770 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 640, 480, null_fourcc
,
23771 D3DMULTISAMPLE_NONE
, 0, FALSE
, &null_rt
, NULL
);
23772 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
23773 hr
= IDirect3DDevice9_CreateRenderTarget(device
, 400, 300, null_fourcc
,
23774 D3DMULTISAMPLE_NONE
, 0, FALSE
, &small_null_rt
, NULL
);
23775 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
23777 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
23778 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
23779 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_TRUE
);
23780 ok(SUCCEEDED(hr
), "Failed to enable depth test, hr %#x.\n", hr
);
23781 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_LESSEQUAL
);
23782 ok(SUCCEEDED(hr
), "Failed to set depth function, hr %#x.\n", hr
);
23783 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, TRUE
);
23784 ok(SUCCEEDED(hr
), "Failed to enable depth write, hr %#x.\n", hr
);
23785 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
23786 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
23788 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0, 1.0f
, 0);
23789 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
23791 /* Clear extends to viewport size > RT size even if format is not
23793 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, small_rt
);
23794 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
23796 hr
= IDirect3DDevice9_SetViewport(device
, &vp_full
);
23797 ok(hr
== D3D_OK
, "Failed to set viewport, hr %#x.\n", hr
);
23799 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0, 0.2f
, 0);
23800 ok(SUCCEEDED(hr
), "Failed to clear depth/stencil, hr %#x.\n", hr
);
23802 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, original_rt
);
23803 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
23805 hr
= IDirect3DDevice9_BeginScene(device
);
23806 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
23807 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
23808 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
23809 hr
= IDirect3DDevice9_EndScene(device
);
23810 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
23812 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, null_rt
);
23813 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
23814 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0, 1.0f
, 0);
23815 ok(SUCCEEDED(hr
), "Failed to clear depth/stencil, hr %#x.\n", hr
);
23817 /* Draw only extends to viewport size > RT size if format is "NULL". */
23818 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, small_rt
);
23819 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
23820 hr
= IDirect3DDevice9_SetViewport(device
, &vp_lower
);
23821 ok(hr
== D3D_OK
, "Failed to set viewport, hr %#x.\n", hr
);
23822 hr
= IDirect3DDevice9_BeginScene(device
);
23823 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
23824 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
23825 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
23826 hr
= IDirect3DDevice9_EndScene(device
);
23827 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
23829 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, small_null_rt
);
23830 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
23831 hr
= IDirect3DDevice9_SetViewport(device
, &vp_560
);
23832 ok(hr
== D3D_OK
, "Failed to set viewport, hr %#x.\n", hr
);
23833 hr
= IDirect3DDevice9_BeginScene(device
);
23834 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
23835 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
23836 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
23837 hr
= IDirect3DDevice9_EndScene(device
);
23838 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
23840 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, original_rt
);
23841 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
23843 hr
= IDirect3DDevice9_BeginScene(device
);
23844 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
23845 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad_partial
, sizeof(*quad_partial
));
23846 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
23847 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad_far
, sizeof(*quad_far
));
23848 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
23849 hr
= IDirect3DDevice9_EndScene(device
);
23850 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
23852 for (i
= 0; i
< ARRAY_SIZE(expected_colors
); ++i
)
23854 color
= getPixelColor(device
, expected_colors
[i
].x
, expected_colors
[i
].y
);
23855 ok(color_match(color
, expected_colors
[i
].color
, 1),
23856 "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
23857 expected_colors
[i
].color
, expected_colors
[i
].x
, expected_colors
[i
].y
, color
);
23860 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
23861 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
23863 IDirect3DSurface9_Release(small_null_rt
);
23864 IDirect3DSurface9_Release(null_rt
);
23865 IDirect3DSurface9_Release(small_rt
);
23866 IDirect3DSurface9_Release(original_rt
);
23867 cleanup_device(device
);
23868 IDirect3D9_Release(d3d
);
23871 static void test_map_synchronisation(void)
23873 LARGE_INTEGER frequency
, diff
, ts
[3];
23874 unsigned int i
, j
, tri_count
, size
;
23875 D3DADAPTER_IDENTIFIER9 identifier
;
23876 IDirect3DVertexBuffer9
*buffer
;
23877 IDirect3DDevice9
*device
;
23878 BOOL unsynchronised
, ret
;
23886 static const struct
23888 unsigned int flags
;
23889 BOOL unsynchronised
;
23894 {D3DLOCK_NOOVERWRITE
, TRUE
},
23895 {D3DLOCK_DISCARD
, FALSE
},
23896 {D3DLOCK_NOOVERWRITE
| D3DLOCK_DISCARD
, TRUE
},
23899 static const struct quad
23903 struct vec3 position
;
23910 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
23911 {{-1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
23912 {{ 1.0f
, -1.0f
, 0.0f
}, 0xff0000ff},
23913 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffffffff},
23919 {{-1.0f
, -1.0f
, 0.0f
}, 0xffffff00},
23920 {{-1.0f
, 1.0f
, 0.0f
}, 0xffffff00},
23921 {{ 1.0f
, -1.0f
, 0.0f
}, 0xffffff00},
23922 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffffff00},
23925 struct quad
*quads
;
23927 window
= create_window();
23928 ok(!!window
, "Failed to create a window.\n");
23930 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
23931 ok(!!d3d
, "Failed to create a D3D object.\n");
23932 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
23934 skip("Failed to create a D3D device, skipping tests.\n");
23935 IDirect3D9_Release(d3d
);
23936 DestroyWindow(window
);
23940 hr
= IDirect3D9_GetAdapterIdentifier(d3d
, D3DADAPTER_DEFAULT
, 0, &identifier
);
23941 ok(SUCCEEDED(hr
), "Failed to get adapter identifier, hr %#x.\n", hr
);
23942 /* Maps are always synchronised on WARP. */
23943 if (adapter_is_warp(&identifier
))
23945 skip("Running on WARP, skipping test.\n");
23949 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
23950 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
23952 tri_count
= 0x1000;
23953 if (tri_count
> caps
.MaxPrimitiveCount
)
23955 skip("Device supports only %u primitives, skipping test.\n", caps
.MaxPrimitiveCount
);
23958 size
= (tri_count
+ 2) * sizeof(*quad1
.strip
);
23960 ret
= QueryPerformanceFrequency(&frequency
);
23961 ok(ret
, "Failed to get performance counter frequency.\n");
23963 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, size
,
23964 D3DUSAGE_DYNAMIC
| D3DUSAGE_WRITEONLY
, 0, D3DPOOL_DEFAULT
, &buffer
, NULL
);
23965 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
23966 hr
= IDirect3DVertexBuffer9_Lock(buffer
, 0, size
, (void **)&quads
, D3DLOCK_DISCARD
);
23967 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
23968 for (j
= 0; j
< size
/ sizeof(*quads
); ++j
)
23972 hr
= IDirect3DVertexBuffer9_Unlock(buffer
);
23973 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
23975 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
23976 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
23977 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
23978 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
23979 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, buffer
, 0, sizeof(*quads
->strip
));
23980 ok(SUCCEEDED(hr
), "Failed to set stream source, hr %#x.\n", hr
);
23982 /* Initial draw to initialise states, compile shaders, etc. */
23983 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff0000ff, 0.0f
, 0);
23984 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
23985 hr
= IDirect3DDevice9_BeginScene(device
);
23986 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
23987 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 0, tri_count
);
23988 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
23989 hr
= IDirect3DDevice9_EndScene(device
);
23990 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
23991 /* Read the result to ensure the GPU has finished drawing. */
23992 colour
= getPixelColor(device
, 320, 240);
23994 /* Time drawing tri_count triangles. */
23995 ret
= QueryPerformanceCounter(&ts
[0]);
23996 ok(ret
, "Failed to read performance counter.\n");
23997 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff0000ff, 0.0f
, 0);
23998 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
23999 hr
= IDirect3DDevice9_BeginScene(device
);
24000 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
24001 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 0, tri_count
);
24002 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
24003 hr
= IDirect3DDevice9_EndScene(device
);
24004 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
24005 colour
= getPixelColor(device
, 320, 240);
24006 /* Time drawing a single triangle. */
24007 ret
= QueryPerformanceCounter(&ts
[1]);
24008 ok(ret
, "Failed to read performance counter.\n");
24009 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff0000ff, 0.0f
, 0);
24010 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
24011 hr
= IDirect3DDevice9_BeginScene(device
);
24012 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
24013 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 0, 1);
24014 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
24015 hr
= IDirect3DDevice9_EndScene(device
);
24016 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
24017 colour
= getPixelColor(device
, 320, 240);
24018 ret
= QueryPerformanceCounter(&ts
[2]);
24019 ok(ret
, "Failed to read performance counter.\n");
24021 IDirect3DVertexBuffer9_Release(buffer
);
24023 /* Estimate the number of triangles we can draw in 100ms. */
24024 diff
.QuadPart
= ts
[1].QuadPart
- ts
[0].QuadPart
+ ts
[1].QuadPart
- ts
[2].QuadPart
;
24025 tri_count
= (tri_count
* frequency
.QuadPart
) / (diff
.QuadPart
* 10);
24026 tri_count
= ((tri_count
+ 2 + 3) & ~3) - 2;
24027 if (tri_count
> caps
.MaxPrimitiveCount
)
24029 skip("Would need to draw %u triangles, but the device only supports %u primitives.\n",
24030 tri_count
, caps
.MaxPrimitiveCount
);
24033 size
= (tri_count
+ 2) * sizeof(*quad1
.strip
);
24035 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
24037 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, size
,
24038 D3DUSAGE_DYNAMIC
| D3DUSAGE_WRITEONLY
, 0, D3DPOOL_DEFAULT
, &buffer
, NULL
);
24039 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
24040 hr
= IDirect3DVertexBuffer9_Lock(buffer
, 0, size
, (void **)&quads
, D3DLOCK_DISCARD
);
24041 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
24042 for (j
= 0; j
< size
/ sizeof(*quads
); ++j
)
24046 hr
= IDirect3DVertexBuffer9_Unlock(buffer
);
24047 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
24049 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, buffer
, 0, sizeof(*quads
->strip
));
24050 ok(SUCCEEDED(hr
), "Failed to set stream source, hr %#x.\n", hr
);
24052 /* Start a draw operation. */
24053 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff0000ff, 0.0f
, 0);
24054 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
24055 hr
= IDirect3DDevice9_BeginScene(device
);
24056 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
24057 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 0, tri_count
);
24058 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
24059 hr
= IDirect3DDevice9_EndScene(device
);
24060 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
24062 /* Map the last quad while the draw is in progress. */
24063 hr
= IDirect3DVertexBuffer9_Lock(buffer
, size
- sizeof(quad2
),
24064 sizeof(quad2
), (void **)&quads
, tests
[i
].flags
);
24065 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
24067 hr
= IDirect3DVertexBuffer9_Unlock(buffer
);
24068 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
24070 colour
= getPixelColor(device
, 320, 240);
24071 unsynchronised
= color_match(colour
, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x00), 1);
24072 ok(tests
[i
].unsynchronised
== unsynchronised
, "Expected %s map for flags %#x.\n",
24073 tests
[i
].unsynchronised
? "unsynchronised" : "synchronised", tests
[i
].flags
);
24075 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
24076 ok(SUCCEEDED(hr
), "Failed to present, hr %#x.\n", hr
);
24078 IDirect3DVertexBuffer9_Release(buffer
);
24082 refcount
= IDirect3DDevice9_Release(device
);
24083 ok(!refcount
, "Device has %u references left.\n", refcount
);
24084 IDirect3D9_Release(d3d
);
24085 DestroyWindow(window
);
24088 static void test_color_vertex(void)
24090 IDirect3DDevice9
*device
;
24091 D3DMATERIAL9 material
;
24099 /* The idea here is to set up ambient light parameters in a way that the
24100 * ambient colour from the material is just passed through. The emissive
24101 * colour is just passed through anyway. The sum of ambient + emissive
24102 * should allow deduction of where the material colour came from.
24104 * Note that in cases without a D3DFVF_DIFFUSE flag the first colour value
24105 * in the struct will be fed into the specular vertex colour slot. */
24106 static const struct
24108 DWORD fvf
, color_vertex
, ambient
, emissive
, result
;
24112 {D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
, FALSE
, D3DMCS_COLOR1
, D3DMCS_COLOR2
, 0x000000c0},
24114 {D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
, TRUE
, D3DMCS_COLOR1
, D3DMCS_COLOR2
, 0x00ffff00},
24115 {D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
, TRUE
, D3DMCS_MATERIAL
, D3DMCS_COLOR2
, 0x0000ff80},
24116 {D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
, TRUE
, D3DMCS_COLOR1
, D3DMCS_MATERIAL
, 0x00ff0040},
24117 {D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
, TRUE
, D3DMCS_COLOR1
, D3DMCS_COLOR1
, 0x00ff0000},
24118 {D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
, TRUE
, D3DMCS_COLOR2
, D3DMCS_COLOR2
, 0x0000ff00},
24120 {D3DFVF_SPECULAR
, TRUE
, D3DMCS_COLOR1
, D3DMCS_COLOR2
, 0x00ff0080},
24121 {D3DFVF_SPECULAR
, TRUE
, D3DMCS_COLOR1
, D3DMCS_MATERIAL
, 0x000000c0},
24122 {D3DFVF_SPECULAR
, TRUE
, D3DMCS_MATERIAL
, D3DMCS_COLOR2
, 0x00ff0080},
24123 {D3DFVF_DIFFUSE
, TRUE
, D3DMCS_COLOR1
, D3DMCS_COLOR2
, 0x00ff0040},
24124 {D3DFVF_DIFFUSE
, TRUE
, D3DMCS_COLOR1
, D3DMCS_MATERIAL
, 0x00ff0040},
24125 {D3DFVF_DIFFUSE
, TRUE
, D3DMCS_COLOR2
, D3DMCS_MATERIAL
, 0x000000c0},
24127 {0, TRUE
, D3DMCS_COLOR1
, D3DMCS_COLOR2
, 0x000000c0},
24130 static const struct
24132 struct vec3 position
;
24138 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000, 0xff00ff00},
24139 {{-1.0f
, 1.0f
, 0.0f
}, 0xffff0000, 0xff00ff00},
24140 {{ 1.0f
, -1.0f
, 0.0f
}, 0xffff0000, 0xff00ff00},
24141 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffff0000, 0xff00ff00},
24144 window
= create_window();
24145 ok(!!window
, "Failed to create a window.\n");
24147 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
24148 ok(!!d3d
, "Failed to create a D3D object.\n");
24149 if (!(device
= create_device(d3d
, window
, window
, TRUE
)))
24151 skip("Failed to create a D3D device, skipping tests.\n");
24152 IDirect3D9_Release(d3d
);
24153 DestroyWindow(window
);
24157 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, TRUE
);
24158 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
24159 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_AMBIENT
, 0xffffffff);
24160 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
24162 memset(&material
, 0, sizeof(material
));
24163 material
.Ambient
.b
= 0.5f
;
24164 material
.Emissive
.b
= 0.25f
;
24165 hr
= IDirect3DDevice9_SetMaterial(device
, &material
);
24166 ok(SUCCEEDED(hr
), "Failed to set material, hr %#x\n", hr
);
24168 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
24170 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_COLORVERTEX
, tests
[i
].color_vertex
);
24171 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
24172 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_AMBIENTMATERIALSOURCE
, tests
[i
].ambient
);
24173 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
24174 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_EMISSIVEMATERIALSOURCE
, tests
[i
].emissive
);
24175 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
24176 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| tests
[i
].fvf
);
24177 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
24179 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x77777777, 0.0f
, 0);
24180 ok(SUCCEEDED(hr
), "Failed to clear depth/stencil, hr %#x.\n", hr
);
24182 hr
= IDirect3DDevice9_BeginScene(device
);
24183 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
24184 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(*quad
));
24185 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
24186 hr
= IDirect3DDevice9_EndScene(device
);
24187 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
24189 colour
= getPixelColor(device
, 320, 240);
24190 ok(color_match(colour
, tests
[i
].result
, 1),
24191 "Expected colour 0x%08x for test %u, got 0x%08x.\n",
24192 tests
[i
].result
, i
, colour
);
24195 refcount
= IDirect3DDevice9_Release(device
);
24196 ok(!refcount
, "Device has %u references left.\n", refcount
);
24197 IDirect3D9_Release(d3d
);
24198 DestroyWindow(window
);
24203 D3DADAPTER_IDENTIFIER9 identifier
;
24207 if (!(d3d
= Direct3DCreate9(D3D_SDK_VERSION
)))
24209 skip("could not create D3D9 object\n");
24213 memset(&identifier
, 0, sizeof(identifier
));
24214 hr
= IDirect3D9_GetAdapterIdentifier(d3d
, 0, 0, &identifier
);
24215 ok(SUCCEEDED(hr
), "Failed to get adapter identifier, hr %#x.\n", hr
);
24216 trace("Driver string: \"%s\"\n", identifier
.Driver
);
24217 trace("Description string: \"%s\"\n", identifier
.Description
);
24218 /* Only Windows XP's default VGA driver should have an empty description */
24219 ok(identifier
.Description
[0] || broken(!strcmp(identifier
.Driver
, "vga.dll")), "Empty driver description.\n");
24220 trace("Device name string: \"%s\"\n", identifier
.DeviceName
);
24221 ok(identifier
.DeviceName
[0], "Empty device name.\n");
24222 trace("Driver version %d.%d.%d.%d\n",
24223 HIWORD(U(identifier
.DriverVersion
).HighPart
), LOWORD(U(identifier
.DriverVersion
).HighPart
),
24224 HIWORD(U(identifier
.DriverVersion
).LowPart
), LOWORD(U(identifier
.DriverVersion
).LowPart
));
24226 IDirect3D9_Release(d3d
);
24229 depth_clamp_test();
24230 stretchrect_test();
24231 test_multisample_stretch_rect();
24233 test_specular_lighting();
24244 srgbtexture_test();
24245 release_buffer_test();
24246 float_texture_test();
24247 g16r16_texture_test();
24248 pixelshader_blending_test();
24249 texture_transform_flags_test();
24250 test_generate_mipmap();
24251 test_mipmap_autogen();
24252 fixed_function_decl_test();
24253 conditional_np2_repeat_test();
24254 fixed_function_bumpmap_test();
24257 np2_stretch_rect_test();
24260 zwriteenable_test();
24263 test_constant_clamp_vs();
24264 test_compare_instructions();
24269 clip_planes_test();
24270 test_vshader_input();
24271 test_vshader_float16();
24273 fog_with_shader_test();
24277 volume_v16u16_test();
24278 constant_clamp_ps_test();
24281 unbound_sampler_test();
24282 nested_loop_test();
24283 pretransformed_varying_test();
24284 vface_register_test();
24285 test_fragment_coords();
24286 multiple_rendertargets_test();
24288 texop_range_test();
24289 alphareplicate_test();
24291 depth_buffer_test();
24292 depth_buffer2_test();
24297 depth_bounds_test();
24298 srgbwrite_format_test();
24299 update_surface_test();
24300 multisample_get_rtdata_test();
24301 test_multisample_get_front_buffer_data();
24303 fog_special_test();
24304 volume_srgb_test();
24305 volume_dxtn_test();
24306 add_dirty_rect_test();
24307 multisampled_depth_buffer_test();
24309 stencil_cull_test();
24310 test_per_stage_constant();
24311 test_3dc_formats();
24312 test_fog_interpolation();
24313 test_negative_fixedfunction_fog();
24314 test_position_index();
24315 test_table_fog_zw();
24316 test_signed_formats();
24317 test_multisample_mismatch();
24318 test_texcoordindex();
24319 test_vertex_blending();
24320 test_updatetexture();
24323 test_uninitialized_varyings();
24324 test_multisample_init();
24325 test_depth_stencil_init();
24326 test_texture_blending();
24327 test_color_clamping();
24328 test_line_antialiasing_blending();
24330 test_evict_bound_resources();
24331 test_max_index16();
24332 test_backbuffer_resize();
24333 test_drawindexedprimitiveup();
24334 test_vertex_texture();
24335 test_mvp_software_vertex_shaders();
24336 test_null_format();
24337 test_map_synchronisation();
24338 test_color_vertex();