2 * Copyright 2005, 2007 Henri Verbeet
3 * Copyright (C) 2007 Stefan Dösinger(for CodeWeavers)
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 /* This test framework allows limited testing of rendering results. Things are rendered, shown on
21 * the framebuffer, read back from there and compared to expected colors.
23 * However, neither d3d nor opengl is guaranteed to be pixel exact, and thus the capability of this test
24 * is rather limited. As a general guideline for adding tests, do not rely on corner pixels. Draw a big enough
25 * area which shows specific behavior(like a quad on the whole screen), and try to get resulting colors with
26 * all bits set or unset in all channels(like pure red, green, blue, white, black). Hopefully everything that
27 * causes visible results in games can be tested in a way that does not depend on pixel exactness
33 #include "wine/test.h"
35 static HMODULE d3d9_handle
= 0;
37 static HWND
create_window(void)
41 wc
.lpfnWndProc
= &DefWindowProc
;
42 wc
.lpszClassName
= "d3d9_test_wc";
45 ret
= CreateWindow("d3d9_test_wc", "d3d9_test",
46 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
50 static DWORD
getPixelColor(IDirect3DDevice9
*device
, UINT x
, UINT y
)
53 IDirect3DSurface9
*surf
;
55 D3DLOCKED_RECT lockedRect
;
56 RECT rectToLock
= {x
, y
, x
+1, y
+1};
58 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 640, 480, D3DFMT_A8R8G8B8
, D3DPOOL_SYSTEMMEM
, &surf
, NULL
);
59 if(FAILED(hr
) || !surf
) /* This is not a test */
61 trace("Can't create an offscreen plain surface to read the render target data, hr=%s\n", DXGetErrorString9(hr
));
65 hr
= IDirect3DDevice9_GetFrontBufferData(device
, 0, surf
);
68 trace("Can't read the front buffer data, hr=%s\n", DXGetErrorString9(hr
));
73 hr
= IDirect3DSurface9_LockRect(surf
, &lockedRect
, &rectToLock
, D3DLOCK_READONLY
);
76 trace("Can't lock the offscreen surface, hr=%s\n", DXGetErrorString9(hr
));
81 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
82 * really important for these tests
84 ret
= ((DWORD
*) lockedRect
.pBits
)[0] & 0x00ffffff;
85 hr
= IDirect3DSurface9_UnlockRect(surf
);
88 trace("Can't unlock the offscreen surface, hr=%s\n", DXGetErrorString9(hr
));
92 if(surf
) IDirect3DSurface9_Release(surf
);
96 static IDirect3DDevice9
*init_d3d9(void)
98 IDirect3D9
* (__stdcall
* d3d9_create
)(UINT SDKVersion
) = 0;
99 IDirect3D9
*d3d9_ptr
= 0;
100 IDirect3DDevice9
*device_ptr
= 0;
101 D3DPRESENT_PARAMETERS present_parameters
;
104 d3d9_create
= (void *)GetProcAddress(d3d9_handle
, "Direct3DCreate9");
105 ok(d3d9_create
!= NULL
, "Failed to get address of Direct3DCreate9\n");
106 if (!d3d9_create
) return NULL
;
108 d3d9_ptr
= d3d9_create(D3D_SDK_VERSION
);
109 ok(d3d9_ptr
!= NULL
, "Failed to create IDirect3D9 object\n");
110 if (!d3d9_ptr
) return NULL
;
112 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
113 present_parameters
.Windowed
= FALSE
;
114 present_parameters
.hDeviceWindow
= create_window();
115 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
116 present_parameters
.BackBufferWidth
= 640;
117 present_parameters
.BackBufferHeight
= 480;
118 present_parameters
.BackBufferFormat
= D3DFMT_X8R8G8B8
;
119 present_parameters
.EnableAutoDepthStencil
= TRUE
;
120 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
122 hr
= IDirect3D9_CreateDevice(d3d9_ptr
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, present_parameters
.hDeviceWindow
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device_ptr
);
124 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D16
;
125 hr
= IDirect3D9_CreateDevice(d3d9_ptr
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, present_parameters
.hDeviceWindow
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device_ptr
);
127 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "IDirect3D_CreateDevice returned: %s\n", DXGetErrorString9(hr
));
151 static void lighting_test(IDirect3DDevice9
*device
)
154 DWORD fvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
155 DWORD nfvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_NORMAL
;
158 float mat
[16] = { 1.0f
, 0.0f
, 0.0f
, 0.0f
,
159 0.0f
, 1.0f
, 0.0f
, 0.0f
,
160 0.0f
, 0.0f
, 1.0f
, 0.0f
,
161 0.0f
, 0.0f
, 0.0f
, 1.0f
};
163 struct vertex unlitquad
[] =
165 {-1.0f
, -1.0f
, 0.1f
, 0xffff0000},
166 {-1.0f
, 0.0f
, 0.1f
, 0xffff0000},
167 { 0.0f
, 0.0f
, 0.1f
, 0xffff0000},
168 { 0.0f
, -1.0f
, 0.1f
, 0xffff0000},
170 struct vertex litquad
[] =
172 {-1.0f
, 0.0f
, 0.1f
, 0xff00ff00},
173 {-1.0f
, 1.0f
, 0.1f
, 0xff00ff00},
174 { 0.0f
, 1.0f
, 0.1f
, 0xff00ff00},
175 { 0.0f
, 0.0f
, 0.1f
, 0xff00ff00},
177 struct nvertex unlitnquad
[] =
179 { 0.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
180 { 0.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
181 { 1.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
182 { 1.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
184 struct nvertex litnquad
[] =
186 { 0.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
187 { 0.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
188 { 1.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
189 { 1.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
191 WORD Indices
[] = {0, 1, 2, 2, 3, 0};
193 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
194 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %s\n", DXGetErrorString9(hr
));
196 /* Setup some states that may cause issues */
197 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_WORLDMATRIX(0), (D3DMATRIX
*) mat
);
198 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform returned %s\n", DXGetErrorString9(hr
));
199 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_VIEW
, (D3DMATRIX
*)mat
);
200 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform returned %s\n", DXGetErrorString9(hr
));
201 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_PROJECTION
, (D3DMATRIX
*) mat
);
202 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform returned %s\n", DXGetErrorString9(hr
));
203 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CLIPPING
, FALSE
);
204 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
205 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
206 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
207 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGENABLE
, FALSE
);
208 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
209 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILENABLE
, FALSE
);
210 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
211 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ALPHATESTENABLE
, FALSE
);
212 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
213 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, FALSE
);
214 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
215 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SCISSORTESTENABLE
, FALSE
);
216 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
217 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CULLMODE
, D3DCULL_NONE
);
218 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed with %s\n", DXGetErrorString9(hr
));
219 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_COLORWRITEENABLE
, D3DCOLORWRITEENABLE_RED
| D3DCOLORWRITEENABLE_GREEN
| D3DCOLORWRITEENABLE_BLUE
);
220 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed with %s\n", DXGetErrorString9(hr
));
222 hr
= IDirect3DDevice9_SetFVF(device
, fvf
);
223 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF returned %s\n", DXGetErrorString9(hr
));
225 hr
= IDirect3DDevice9_BeginScene(device
);
226 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %s\n", DXGetErrorString9(hr
));
229 /* No lights are defined... That means, lit vertices should be entirely black */
230 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
231 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
232 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
233 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, unlitquad
, sizeof(unlitquad
[0]));
234 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawIndexedPrimitiveUP failed with %s\n", DXGetErrorString9(hr
));
236 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, TRUE
);
237 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
238 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
239 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, litquad
, sizeof(litquad
[0]));
240 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawIndexedPrimitiveUP failed with %s\n", DXGetErrorString9(hr
));
242 hr
= IDirect3DDevice9_SetFVF(device
, nfvf
);
243 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with %s\n", DXGetErrorString9(hr
));
245 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
246 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
247 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
248 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, unlitnquad
, sizeof(unlitnquad
[0]));
249 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawIndexedPrimitiveUP failed with %s\n", DXGetErrorString9(hr
));
251 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, TRUE
);
252 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
253 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
254 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, litnquad
, sizeof(litnquad
[0]));
255 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawIndexedPrimitiveUP failed with %s\n", DXGetErrorString9(hr
));
257 IDirect3DDevice9_EndScene(device
);
258 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %s\n", DXGetErrorString9(hr
));
261 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
263 color
= getPixelColor(device
, 160, 360); /* lower left quad - unlit without normals */
264 ok(color
== 0x00ff0000, "Unlit quad without normals has color %08x\n", color
);
265 color
= getPixelColor(device
, 160, 120); /* upper left quad - lit without normals */
266 ok(color
== 0x00000000, "Lit quad without normals has color %08x\n", color
);
267 color
= getPixelColor(device
, 480, 360); /* lower left quad - unlit with normals */
268 ok(color
== 0x000000ff, "Unlit quad with normals has color %08x\n", color
);
269 color
= getPixelColor(device
, 480, 120); /* upper left quad - lit with normals */
270 ok(color
== 0x00000000, "Lit quad with normals has color %08x\n", color
);
272 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
273 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
276 static void clear_test(IDirect3DDevice9
*device
)
278 /* Tests the correctness of clearing parameters */
283 D3DVIEWPORT9 old_vp
, vp
;
286 BOOL invalid_clear_failed
= FALSE
;
288 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
289 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %s\n", DXGetErrorString9(hr
));
291 /* Positive x, negative y */
297 /* Positive x, positive y */
302 /* Clear 2 rectangles with one call. The refrast returns an error in this case, every real driver tested so far
303 * returns D3D_OK, but ignores the rectangle silently
305 hr
= IDirect3DDevice9_Clear(device
, 2, rect
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
306 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Clear failed with %s\n", DXGetErrorString9(hr
));
307 if(hr
== D3DERR_INVALIDCALL
) invalid_clear_failed
= TRUE
;
309 /* negative x, negative y */
310 rect_negneg
.x1
= 640;
311 rect_negneg
.y1
= 240;
312 rect_negneg
.x2
= 320;
314 hr
= IDirect3DDevice9_Clear(device
, 1, &rect_negneg
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0, 0);
315 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice9_Clear failed with %s\n", DXGetErrorString9(hr
));
316 if(hr
== D3DERR_INVALIDCALL
) invalid_clear_failed
= TRUE
;
318 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
320 color
= getPixelColor(device
, 160, 360); /* lower left quad */
321 ok(color
== 0x00ffffff, "Clear rectangle 3(pos, neg) has color %08x\n", color
);
322 color
= getPixelColor(device
, 160, 120); /* upper left quad */
323 if(invalid_clear_failed
) {
324 /* If the negative rectangle was refused, the other rectangles in the list shouldn't be cleared either */
325 ok(color
== 0x00ffffff, "Clear rectangle 1(pos, pos) has color %08x\n", color
);
327 /* If the negative rectangle was dropped silently, the correct ones are cleared */
328 ok(color
== 0x00ff0000, "Clear rectangle 1(pos, pos) has color %08x\n", color
);
330 color
= getPixelColor(device
, 480, 360); /* lower right quad */
331 ok(color
== 0x00ffffff, "Clear rectangle 4(NULL) has color %08x\n", color
);
332 color
= getPixelColor(device
, 480, 120); /* upper right quad */
333 ok(color
== 0x00ffffff, "Clear rectangle 4(neg, neg) has color %08x\n", color
);
335 /* Test how the viewport affects clears */
336 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
337 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %s\n", DXGetErrorString9(hr
));
338 hr
= IDirect3DDevice9_GetViewport(device
, &old_vp
);
339 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetViewport failed with %s\n", DXGetErrorString9(hr
));
347 hr
= IDirect3DDevice9_SetViewport(device
, &vp
);
348 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetViewport failed with %s\n", DXGetErrorString9(hr
));
349 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff0000ff, 0.0, 0);
350 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %s\n", DXGetErrorString9(hr
));
358 hr
= IDirect3DDevice9_SetViewport(device
, &vp
);
359 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetViewport failed with %s\n", DXGetErrorString9(hr
));
364 hr
= IDirect3DDevice9_Clear(device
, 1, &rect
[0], D3DCLEAR_TARGET
, 0xff00ff00, 0.0, 0);
365 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %s\n", DXGetErrorString9(hr
));
367 hr
= IDirect3DDevice9_SetViewport(device
, &old_vp
);
368 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetViewport failed with %s\n", DXGetErrorString9(hr
));
370 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
371 color
= getPixelColor(device
, 158, 118);
372 ok(color
== 0x00ffffff, "(158,118) has color %08x\n", color
);
373 color
= getPixelColor(device
, 162, 118);
374 ok(color
== 0x00ffffff, "(162,118) has color %08x\n", color
);
375 color
= getPixelColor(device
, 158, 122);
376 ok(color
== 0x00ffffff, "(158,122) has color %08x\n", color
);
377 color
= getPixelColor(device
, 162, 122);
378 ok(color
== 0x000000ff, "(162,122) has color %08x\n", color
);
380 color
= getPixelColor(device
, 318, 238);
381 ok(color
== 0x000000ff, "(318,238) has color %08x\n", color
);
382 color
= getPixelColor(device
, 322, 238);
383 ok(color
== 0x00ffffff, "(322,328) has color %08x\n", color
);
384 color
= getPixelColor(device
, 318, 242);
385 ok(color
== 0x00ffffff, "(318,242) has color %08x\n", color
);
386 color
= getPixelColor(device
, 322, 242);
387 ok(color
== 0x0000ff00, "(322,242) has color %08x\n", color
);
389 color
= getPixelColor(device
, 478, 358);
390 ok(color
== 0x0000ff00, "(478,358 has color %08x\n", color
);
391 color
= getPixelColor(device
, 482, 358);
392 ok(color
== 0x00ffffff, "(482,358) has color %08x\n", color
);
393 color
= getPixelColor(device
, 478, 362);
394 ok(color
== 0x00ffffff, "(478,362) has color %08x\n", color
);
395 color
= getPixelColor(device
, 482, 362);
396 ok(color
== 0x00ffffff, "(482,362) has color %08x\n", color
);
398 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
399 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %s\n", DXGetErrorString9(hr
));
404 scissor
.bottom
= 360;
405 hr
= IDirect3DDevice9_SetScissorRect(device
, &scissor
);
406 ok(hr
== D3D_OK
, "IDirect3DDevice_SetScissorRect failed with %s\n", DXGetErrorString9(hr
));
407 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SCISSORTESTENABLE
, TRUE
);
408 ok(hr
== D3D_OK
, "IDirect3DDevice_SetScissorRect failed with %s\n", DXGetErrorString9(hr
));
410 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0, 0);
411 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %s\n", DXGetErrorString9(hr
));
412 hr
= IDirect3DDevice9_Clear(device
, 1, &rect
[1], D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
413 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %s\n", DXGetErrorString9(hr
));
415 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SCISSORTESTENABLE
, FALSE
);
416 ok(hr
== D3D_OK
, "IDirect3DDevice_SetScissorRect failed with %s\n", DXGetErrorString9(hr
));
418 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
419 color
= getPixelColor(device
, 158, 118);
420 ok(color
== 0x00ffffff, "Pixel 158/118 has color %08x\n", color
);
421 color
= getPixelColor(device
, 162, 118);
422 ok(color
== 0x00ffffff, "Pixel 162/118 has color %08x\n", color
);
423 color
= getPixelColor(device
, 158, 122);
424 ok(color
== 0x00ffffff, "Pixel 158/122 has color %08x\n", color
);
425 color
= getPixelColor(device
, 162, 122);
426 ok(color
== 0x00ff0000, "Pixel 162/122 has color %08x\n", color
);
428 color
= getPixelColor(device
, 158, 358);
429 ok(color
== 0x00ffffff, "Pixel 158/358 has color %08x\n", color
);
430 color
= getPixelColor(device
, 162, 358);
431 ok(color
== 0x0000ff00, "Pixel 162/358 has color %08x\n", color
);
432 color
= getPixelColor(device
, 158, 358);
433 ok(color
== 0x00ffffff, "Pixel 158/358 has color %08x\n", color
);
434 color
= getPixelColor(device
, 162, 362);
435 ok(color
== 0x00ffffff, "Pixel 162/362 has color %08x\n", color
);
437 color
= getPixelColor(device
, 478, 118);
438 ok(color
== 0x00ffffff, "Pixel 158/118 has color %08x\n", color
);
439 color
= getPixelColor(device
, 478, 122);
440 ok(color
== 0x0000ff00, "Pixel 162/118 has color %08x\n", color
);
441 color
= getPixelColor(device
, 482, 122);
442 ok(color
== 0x00ffffff, "Pixel 158/122 has color %08x\n", color
);
443 color
= getPixelColor(device
, 482, 358);
444 ok(color
== 0x00ffffff, "Pixel 162/122 has color %08x\n", color
);
446 color
= getPixelColor(device
, 478, 358);
447 ok(color
== 0x0000ff00, "Pixel 478/358 has color %08x\n", color
);
448 color
= getPixelColor(device
, 478, 362);
449 ok(color
== 0x00ffffff, "Pixel 478/118 has color %08x\n", color
);
450 color
= getPixelColor(device
, 482, 358);
451 ok(color
== 0x00ffffff, "Pixel 482/122 has color %08x\n", color
);
452 color
= getPixelColor(device
, 482, 362);
453 ok(color
== 0x00ffffff, "Pixel 482/122 has color %08x\n", color
);
455 color
= getPixelColor(device
, 318, 238);
456 ok(color
== 0x00ff0000, "Pixel 318/238 has color %08x\n", color
);
457 color
= getPixelColor(device
, 318, 242);
458 ok(color
== 0x0000ff00, "Pixel 318/242 has color %08x\n", color
);
459 color
= getPixelColor(device
, 322, 238);
460 ok(color
== 0x0000ff00, "Pixel 322/238 has color %08x\n", color
);
461 color
= getPixelColor(device
, 322, 242);
462 ok(color
== 0x0000ff00, "Pixel 322/242 has color %08x\n", color
);
464 hr
= IDirect3DDevice9_GetRenderState(device
, D3DRS_COLORWRITEENABLE
, &oldColorWrite
);
465 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetRenderState failed with %s\n", DXGetErrorString9(hr
));
466 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_COLORWRITEENABLE
, D3DCOLORWRITEENABLE_RED
);
467 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed with %s\n", DXGetErrorString9(hr
));
469 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
470 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %s\n", DXGetErrorString9(hr
));
472 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_COLORWRITEENABLE
, oldColorWrite
);
473 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed with %s\n", DXGetErrorString9(hr
));
475 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
477 /* Colorwriteenable does not affect the clear */
478 color
= getPixelColor(device
, 320, 240);
479 ok(color
== 0x00ffffff, "Color write protected clear returned color %08x\n", color
);
488 * c7 mova ARGB mov ARGB
489 * -2.4 -2 0x00ffff00 -3 0x00ff0000
490 * -1.6 -2 0x00ffff00 -2 0x00ffff00
491 * -0.4 0 0x0000ffff -1 0x0000ff00
492 * 0.4 0 0x0000ffff 0 0x0000ffff
493 * 1.6 2 0x00ff00ff 1 0x000000ff
494 * 2.4 2 0x00ff00ff 2 0x00ff00ff
496 static void test_mova(IDirect3DDevice9
*device
)
498 static const DWORD mova_test
[] = {
499 0xfffe0200, /* vs_2_0 */
500 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
501 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 1.0, 0.0, 0.0, 1.0 */
502 0x05000051, 0xa00f0001, 0x3f800000, 0x3f800000, 0x00000000, 0x3f800000, /* def c1, 1.0, 1.0, 0.0, 1.0 */
503 0x05000051, 0xa00f0002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, /* def c2, 0.0, 1.0, 0.0, 1.0 */
504 0x05000051, 0xa00f0003, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c3, 0.0, 1.0, 1.0, 1.0 */
505 0x05000051, 0xa00f0004, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, /* def c4, 0.0, 0.0, 1.0, 1.0 */
506 0x05000051, 0xa00f0005, 0x3f800000, 0x00000000, 0x3f800000, 0x3f800000, /* def c5, 1.0, 0.0, 1.0, 1.0 */
507 0x05000051, 0xa00f0006, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c6, 1.0, 1.0, 1.0, 1.0 */
508 0x0200002e, 0xb0010000, 0xa0000007, /* mova a0.x, c7.x */
509 0x03000001, 0xd00f0000, 0xa0e42003, 0xb0000000, /* mov oD0, c[a0.x + 3] */
510 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
513 static const DWORD mov_test
[] = {
514 0xfffe0101, /* vs_1_1 */
515 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
516 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 1.0, 0.0, 0.0, 1.0 */
517 0x00000051, 0xa00f0001, 0x3f800000, 0x3f800000, 0x00000000, 0x3f800000, /* def c1, 1.0, 1.0, 0.0, 1.0 */
518 0x00000051, 0xa00f0002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, /* def c2, 0.0, 1.0, 0.0, 1.0 */
519 0x00000051, 0xa00f0003, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c3, 0.0, 1.0, 1.0, 1.0 */
520 0x00000051, 0xa00f0004, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, /* def c4, 0.0, 0.0, 1.0, 1.0 */
521 0x00000051, 0xa00f0005, 0x3f800000, 0x00000000, 0x3f800000, 0x3f800000, /* def c5, 1.0, 0.0, 1.0, 1.0 */
522 0x00000051, 0xa00f0006, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c6, 1.0, 1.0, 1.0, 1.0 */
523 0x00000001, 0xb0010000, 0xa0000007, /* mov a0.x, c7.x */
524 0x00000001, 0xd00f0000, 0xa0e42003, /* mov oD0, c[a0.x + 3] */
525 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
529 static const test_data_t test_data
[2][6] = {
531 {{-2.4f
, 0.0f
, 0.0f
, 0.0f
}, 0x00ff0000},
532 {{-1.6f
, 0.0f
, 0.0f
, 0.0f
}, 0x00ffff00},
533 {{-0.4f
, 0.0f
, 0.0f
, 0.0f
}, 0x0000ff00},
534 {{ 0.4f
, 0.0f
, 0.0f
, 0.0f
}, 0x0000ffff},
535 {{ 1.6f
, 0.0f
, 0.0f
, 0.0f
}, 0x000000ff},
536 {{ 2.4f
, 0.0f
, 0.0f
, 0.0f
}, 0x00ff00ff}
539 {{-2.4f
, 0.0f
, 0.0f
, 0.0f
}, 0x00ffff00},
540 {{-1.6f
, 0.0f
, 0.0f
, 0.0f
}, 0x00ffff00},
541 {{-0.4f
, 0.0f
, 0.0f
, 0.0f
}, 0x0000ffff},
542 {{ 0.4f
, 0.0f
, 0.0f
, 0.0f
}, 0x0000ffff},
543 {{ 1.6f
, 0.0f
, 0.0f
, 0.0f
}, 0x00ff00ff},
544 {{ 2.4f
, 0.0f
, 0.0f
, 0.0f
}, 0x00ff00ff}
548 static const float quad
[][3] = {
549 {-1.0f
, -1.0f
, 0.0f
},
551 { 1.0f
, -1.0f
, 0.0f
},
555 static const D3DVERTEXELEMENT9 decl_elements
[] = {
556 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
560 IDirect3DVertexDeclaration9
*vertex_declaration
= NULL
;
561 IDirect3DVertexShader9
*mova_shader
= NULL
;
562 IDirect3DVertexShader9
*mov_shader
= NULL
;
566 hr
= IDirect3DDevice9_CreateVertexShader(device
, mova_test
, &mova_shader
);
567 ok(SUCCEEDED(hr
), "CreateVertexShader failed (%08x)\n", hr
);
568 hr
= IDirect3DDevice9_CreateVertexShader(device
, mov_test
, &mov_shader
);
569 ok(SUCCEEDED(hr
), "CreateVertexShader failed (%08x)\n", hr
);
570 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &vertex_declaration
);
571 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (%08x)\n", hr
);
572 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, vertex_declaration
);
573 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed (%08x)\n", hr
);
575 hr
= IDirect3DDevice9_SetVertexShader(device
, mov_shader
);
576 ok(SUCCEEDED(hr
), "SetVertexShader failed (%08x)\n", hr
);
577 for(j
= 0; j
< 2; ++j
)
579 for (i
= 0; i
< (sizeof(test_data
[0]) / sizeof(test_data_t
)); ++i
)
583 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 7, test_data
[j
][i
].in
, 1);
584 ok(SUCCEEDED(hr
), "SetVertexShaderConstantF failed (%08x)\n", hr
);
586 hr
= IDirect3DDevice9_BeginScene(device
);
587 ok(SUCCEEDED(hr
), "BeginScene failed (%08x)\n", hr
);
589 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad
[0], 3 * sizeof(float));
590 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
592 hr
= IDirect3DDevice9_EndScene(device
);
593 ok(SUCCEEDED(hr
), "EndScene failed (%08x)\n", hr
);
595 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
596 ok(SUCCEEDED(hr
), "Present failed (%08x)\n", hr
);
598 color
= getPixelColor(device
, 320, 240);
599 ok(color
== test_data
[j
][i
].out
, "Expected color %08x, got %08x (for input %f, instruction %s)\n",
600 test_data
[j
][i
].out
, color
, test_data
[j
][i
].in
[0], j
== 0 ? "mov" : "mova");
602 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0, 0.0f
, 0);
603 ok(SUCCEEDED(hr
), "Clear failed (%08x)\n", hr
);
605 hr
= IDirect3DDevice9_SetVertexShader(device
, mova_shader
);
606 ok(SUCCEEDED(hr
), "SetVertexShader failed (%08x)\n", hr
);
609 hr
= IDirect3DDevice9_SetVertexShader(device
, NULL
);
610 ok(SUCCEEDED(hr
), "SetVertexShader failed (%08x)\n", hr
);
612 IDirect3DVertexDeclaration9_Release(vertex_declaration
);
613 IDirect3DVertexShader9_Release(mova_shader
);
614 IDirect3DVertexShader9_Release(mov_shader
);
629 static void fog_test(IDirect3DDevice9
*device
)
633 float start
= 0.0f
, end
= 1.0f
;
636 /* Gets full z based fog with linear fog, no fog with specular color */
637 struct sVertex unstransformed_1
[] = {
638 {-1, -1, 0.1f
, 0xFFFF0000, 0xFF000000 },
639 {-1, 0, 0.1f
, 0xFFFF0000, 0xFF000000 },
640 { 0, 0, 0.1f
, 0xFFFF0000, 0xFF000000 },
641 { 0, -1, 0.1f
, 0xFFFF0000, 0xFF000000 },
643 /* Ok, I am too lazy to deal with transform matrices */
644 struct sVertex unstransformed_2
[] = {
645 {-1, 0, 1.0f
, 0xFFFF0000, 0xFF000000 },
646 {-1, 1, 1.0f
, 0xFFFF0000, 0xFF000000 },
647 { 0, 1, 1.0f
, 0xFFFF0000, 0xFF000000 },
648 { 0, 0, 1.0f
, 0xFFFF0000, 0xFF000000 },
650 /* Untransformed ones. Give them a different diffuse color to make the test look
651 * nicer. It also makes making sure that they are drawn correctly easier.
653 struct sVertexT transformed_1
[] = {
654 {320, 0, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
655 {640, 0, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
656 {640, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
657 {320, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
659 struct sVertexT transformed_2
[] = {
660 {320, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
661 {640, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
662 {640, 480, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
663 {320, 480, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
665 WORD Indices
[] = {0, 1, 2, 2, 3, 0};
667 memset(&caps
, 0, sizeof(caps
));
668 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
669 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetDeviceCaps returned %s\n", DXGetErrorString9(hr
));
670 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
671 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %s\n", DXGetErrorString9(hr
));
673 /* Setup initial states: No lighting, fog on, fog color */
674 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
675 ok(hr
== D3D_OK
, "Turning off lighting returned %s\n", DXGetErrorString9(hr
));
676 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGENABLE
, TRUE
);
677 ok(hr
== D3D_OK
, "Turning on fog calculations returned %s\n", DXGetErrorString9(hr
));
678 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGCOLOR
, 0xFF00FF00 /* A nice green */);
679 ok(hr
== D3D_OK
, "Turning on fog calculations returned %s\n", DXGetErrorString9(hr
));
681 /* First test: Both table fog and vertex fog off */
682 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGTABLEMODE
, D3DFOG_NONE
);
683 ok(hr
== D3D_OK
, "Turning off table fog returned %s\n", DXGetErrorString9(hr
));
684 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, D3DFOG_NONE
);
685 ok(hr
== D3D_OK
, "Turning off table fog returned %s\n", DXGetErrorString9(hr
));
687 /* Start = 0, end = 1. Should be default, but set them */
688 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGSTART
, *((DWORD
*) &start
));
689 ok(hr
== D3D_OK
, "Setting fog start returned %s\n", DXGetErrorString9(hr
));
690 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGEND
, *((DWORD
*) &end
));
691 ok(hr
== D3D_OK
, "Setting fog start returned %s\n", DXGetErrorString9(hr
));
693 if(IDirect3DDevice9_BeginScene(device
) == D3D_OK
)
695 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
);
696 ok( hr
== D3D_OK
, "SetFVF returned %s\n", DXGetErrorString9(hr
));
697 /* Untransformed, vertex fog = NONE, table fog = NONE: Read the fog weighting from the specular color */
698 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
699 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, unstransformed_1
,
700 sizeof(unstransformed_1
[0]));
701 ok(hr
== D3D_OK
, "DrawIndexedPrimitiveUP returned %s\n", DXGetErrorString9(hr
));
703 /* That makes it use the Z value */
704 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, D3DFOG_LINEAR
);
705 ok(hr
== D3D_OK
, "Turning off table fog returned %s\n", DXGetErrorString9(hr
));
706 /* Untransformed, vertex fog != none (or table fog != none):
707 * Use the Z value as input into the equation
709 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
710 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, unstransformed_2
,
711 sizeof(unstransformed_1
[0]));
712 ok(hr
== D3D_OK
, "DrawIndexedPrimitiveUP returned %s\n", DXGetErrorString9(hr
));
714 /* transformed verts */
715 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
);
716 ok( hr
== D3D_OK
, "SetFVF returned %s\n", DXGetErrorString9(hr
));
717 /* Transformed, vertex fog != NONE, pixel fog == NONE: Use specular color alpha component */
718 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
719 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, transformed_1
,
720 sizeof(transformed_1
[0]));
721 ok(hr
== D3D_OK
, "DrawIndexedPrimitiveUP returned %s\n", DXGetErrorString9(hr
));
723 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGTABLEMODE
, D3DFOG_LINEAR
);
724 ok( hr
== D3D_OK
, "Setting fog table mode to D3DFOG_LINEAR returned %s\n", DXGetErrorString9(hr
));
725 /* Transformed, table fog != none, vertex anything: Use Z value as input to the fog
728 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
729 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, transformed_2
,
730 sizeof(transformed_2
[0]));
732 hr
= IDirect3DDevice9_EndScene(device
);
733 ok(hr
== D3D_OK
, "EndScene returned %s\n", DXGetErrorString9(hr
));
737 ok(FALSE
, "BeginScene failed\n");
740 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
741 color
= getPixelColor(device
, 160, 360);
742 ok(color
== 0x00FF0000, "Untransformed vertex with no table or vertex fog has color %08x\n", color
);
743 color
= getPixelColor(device
, 160, 120);
744 ok(color
== 0x0000FF00, "Untransformed vertex with linear vertex fog has color %08x\n", color
);
745 color
= getPixelColor(device
, 480, 120);
746 ok(color
== 0x00FFFF00, "Transformed vertex with linear vertex fog has color %08x\n", color
);
747 if(caps
.RasterCaps
& D3DPRASTERCAPS_FOGTABLE
)
749 color
= getPixelColor(device
, 480, 360);
750 ok(color
== 0x0000FF00, "Transformed vertex with linear table fog has color %08x\n", color
);
754 /* Without fog table support the vertex fog is still applied, even though table fog is turned on.
755 * The settings above result in no fogging with vertex fog
757 color
= getPixelColor(device
, 480, 120);
758 ok(color
== 0x00FFFF00, "Transformed vertex with linear vertex fog has color %08x\n", color
);
759 trace("Info: Table fog not supported by this device\n");
762 /* Now test the special case fogstart == fogend */
763 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff0000ff, 0.0, 0);
764 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %s\n", DXGetErrorString9(hr
));
766 if(IDirect3DDevice9_BeginScene(device
) == D3D_OK
)
770 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGSTART
, *((DWORD
*) &start
));
771 ok(hr
== D3D_OK
, "Setting fog start returned %s\n", DXGetErrorString9(hr
));
772 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGEND
, *((DWORD
*) &end
));
773 ok(hr
== D3D_OK
, "Setting fog start returned %s\n", DXGetErrorString9(hr
));
775 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
);
776 ok( hr
== D3D_OK
, "SetFVF returned %s\n", DXGetErrorString9(hr
));
777 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, D3DFOG_LINEAR
);
778 ok( hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState %s\n", DXGetErrorString9(hr
));
779 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGTABLEMODE
, D3DFOG_NONE
);
780 ok( hr
== D3D_OK
, "Setting fog table mode to D3DFOG_LINEAR returned %s\n", DXGetErrorString9(hr
));
782 /* Untransformed vertex, z coord = 0.1, fogstart = 512, fogend = 512. Would result in
783 * a completely fog-free primitive because start > zcoord, but because start == end, the primitive
784 * is fully covered by fog. The same happens to the 2nd untransformed quad with z = 1.0.
785 * The third transformed quad remains unfogged because the fogcoords are read from the specular
786 * color and has fixed fogstart and fogend.
788 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
789 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, unstransformed_1
,
790 sizeof(unstransformed_1
[0]));
791 ok(hr
== D3D_OK
, "DrawIndexedPrimitiveUP returned %s\n", DXGetErrorString9(hr
));
792 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
793 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, unstransformed_2
,
794 sizeof(unstransformed_1
[0]));
795 ok(hr
== D3D_OK
, "DrawIndexedPrimitiveUP returned %s\n", DXGetErrorString9(hr
));
797 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
);
798 ok( hr
== D3D_OK
, "SetFVF returned %s\n", DXGetErrorString9(hr
));
799 /* Transformed, vertex fog != NONE, pixel fog == NONE: Use specular color alpha component */
800 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
801 2 /*PrimCount */, Indices
, D3DFMT_INDEX16
, transformed_1
,
802 sizeof(transformed_1
[0]));
803 ok(hr
== D3D_OK
, "DrawIndexedPrimitiveUP returned %s\n", DXGetErrorString9(hr
));
805 hr
= IDirect3DDevice9_EndScene(device
);
806 ok(hr
== D3D_OK
, "EndScene returned %s\n", DXGetErrorString9(hr
));
810 ok(FALSE
, "BeginScene failed\n");
812 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
813 color
= getPixelColor(device
, 160, 360);
814 ok(color
== 0x0000FF00, "Untransformed vertex with vertex fog and z = 0.1 has color %08x\n", color
);
815 color
= getPixelColor(device
, 160, 120);
816 ok(color
== 0x0000FF00, "Untransformed vertex with vertex fog and z = 1.0 has color %08x\n", color
);
817 color
= getPixelColor(device
, 480, 120);
818 ok(color
== 0x00FFFF00, "Transformed vertex with linear vertex fog has color %08x\n", color
);
820 /* Turn off the fog master switch to avoid confusing other tests */
821 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGENABLE
, FALSE
);
822 ok(hr
== D3D_OK
, "Turning off fog calculations returned %s\n", DXGetErrorString9(hr
));
825 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGSTART
, *((DWORD
*) &start
));
826 ok(hr
== D3D_OK
, "Setting fog start returned %s\n", DXGetErrorString9(hr
));
827 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGEND
, *((DWORD
*) &end
));
828 ok(hr
== D3D_OK
, "Setting fog end returned %s\n", DXGetErrorString9(hr
));
829 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, D3DFOG_LINEAR
);
830 ok( hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState %s\n", DXGetErrorString9(hr
));
831 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGTABLEMODE
, D3DFOG_LINEAR
);
832 ok( hr
== D3D_OK
, "Setting fog table mode to D3DFOG_LINEAR returned %s\n", DXGetErrorString9(hr
));
835 /* This test verifies the behaviour of cube maps wrt. texture wrapping.
836 * D3D cube map wrapping always behaves like GL_CLAMP_TO_EDGE,
837 * regardless of the actual addressing mode set. */
838 static void test_cube_wrap(IDirect3DDevice9
*device
)
840 static const float quad
[][6] = {
841 {-1.0f
, -1.0f
, 0.0f
, 1.0f
, 1.0f
, 1.0f
},
842 {-1.0f
, 1.0f
, 0.0f
, 1.0f
, 1.0f
, 1.0f
},
843 { 1.0f
, -1.0f
, 0.0f
, 1.0f
, 1.0f
, 1.0f
},
844 { 1.0f
, 1.0f
, 0.0f
, 1.0f
, 1.0f
, 1.0f
},
847 static const D3DVERTEXELEMENT9 decl_elements
[] = {
848 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
849 {0, 12, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
853 static const struct {
854 D3DTEXTUREADDRESS mode
;
856 } address_modes
[] = {
857 {D3DTADDRESS_WRAP
, "D3DTADDRESS_WRAP"},
858 {D3DTADDRESS_MIRROR
, "D3DTADDRESS_MIRROR"},
859 {D3DTADDRESS_CLAMP
, "D3DTADDRESS_CLAMP"},
860 {D3DTADDRESS_BORDER
, "D3DTADDRESS_BORDER"},
861 {D3DTADDRESS_MIRRORONCE
, "D3DTADDRESS_MIRRORONCE"},
864 IDirect3DVertexDeclaration9
*vertex_declaration
= NULL
;
865 IDirect3DCubeTexture9
*texture
= NULL
;
866 IDirect3DSurface9
*surface
= NULL
;
867 D3DLOCKED_RECT locked_rect
;
872 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &vertex_declaration
);
873 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (0x%08x)\n", hr
);
874 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, vertex_declaration
);
875 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed (0x%08x)\n", hr
);
877 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 128, 128,
878 D3DFMT_A8R8G8B8
, D3DPOOL_SYSTEMMEM
, &surface
, NULL
);
879 ok(SUCCEEDED(hr
), "CreateOffscreenPlainSurface failed (0x%08x)\n", hr
);
881 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, NULL
, 0);
882 ok(SUCCEEDED(hr
), "LockRect failed (0x%08x)\n", hr
);
884 for (y
= 0; y
< 128; ++y
)
886 DWORD
*ptr
= (DWORD
*)(((BYTE
*)locked_rect
.pBits
) + (y
* locked_rect
.Pitch
));
887 for (x
= 0; x
< 64; ++x
)
891 for (x
= 64; x
< 128; ++x
)
897 hr
= IDirect3DSurface9_UnlockRect(surface
);
898 ok(SUCCEEDED(hr
), "UnlockRect failed (0x%08x)\n", hr
);
900 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 128, 1, 0, D3DFMT_A8R8G8B8
,
901 D3DPOOL_DEFAULT
, &texture
, NULL
);
902 ok(SUCCEEDED(hr
), "CreateCubeTexture failed (0x%08x)\n", hr
);
904 /* Create cube faces */
905 for (face
= 0; face
< 6; ++face
)
907 IDirect3DSurface9
*face_surface
= NULL
;
909 hr
= IDirect3DCubeTexture9_GetCubeMapSurface(texture
, face
, 0, &face_surface
);
910 ok(SUCCEEDED(hr
), "GetCubeMapSurface failed (0x%08x)\n", hr
);
912 hr
= IDirect3DDevice9_UpdateSurface(device
, surface
, NULL
, face_surface
, NULL
);
913 ok(SUCCEEDED(hr
), "UpdateSurface failed (0x%08x)\n", hr
);
915 IDirect3DSurface9_Release(face_surface
);
918 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*)texture
);
919 ok(SUCCEEDED(hr
), "SetTexture failed (0x%08x)\n", hr
);
921 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MINFILTER
, D3DTEXF_LINEAR
);
922 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_MINFILTER failed (0x%08x)\n", hr
);
923 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAGFILTER
, D3DTEXF_LINEAR
);
924 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr
);
925 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_BORDERCOLOR
, 0xff00ff00);
926 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_BORDERCOLOR failed (0x%08x)\n", hr
);
928 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
929 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
931 for (x
= 0; x
< (sizeof(address_modes
) / sizeof(*address_modes
)); ++x
)
935 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSU
, address_modes
[x
].mode
);
936 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_ADDRESSU (%s) failed (0x%08x)\n", address_modes
[x
].name
, hr
);
937 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSV
, address_modes
[x
].mode
);
938 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_ADDRESSV (%s) failed (0x%08x)\n", address_modes
[x
].name
, hr
);
940 hr
= IDirect3DDevice9_BeginScene(device
);
941 ok(SUCCEEDED(hr
), "BeginScene failed (0x%08x)\n", hr
);
943 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad
[0], sizeof(quad
[0]));
944 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (0x%08x)\n", hr
);
946 hr
= IDirect3DDevice9_EndScene(device
);
947 ok(SUCCEEDED(hr
), "EndScene failed (0x%08x)\n", hr
);
949 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
950 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
952 /* Due to the nature of this test, we sample essentially at the edge
953 * between two faces. Because of this it's undefined from which face
954 * the driver will sample. Furtunately that's not important for this
955 * test, since all we care about is that it doesn't sample from the
956 * other side of the surface or from the border. */
957 color
= getPixelColor(device
, 320, 240);
958 ok(color
== 0x00ff0000 || color
== 0x000000ff,
959 "Got color 0x%08x for addressing mode %s, expected 0x00ff0000 or 0x000000ff.\n",
960 color
, address_modes
[x
].name
);
962 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0, 0.0f
, 0);
963 ok(SUCCEEDED(hr
), "Clear failed (0x%08x)\n", hr
);
966 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
967 ok(SUCCEEDED(hr
), "SetTexture failed (0x%08x)\n", hr
);
969 IDirect3DVertexDeclaration9_Release(vertex_declaration
);
970 IDirect3DCubeTexture9_Release(texture
);
971 IDirect3DSurface9_Release(surface
);
974 static void offscreen_test(IDirect3DDevice9
*device
)
977 IDirect3DTexture9
*offscreenTexture
= NULL
;
978 IDirect3DSurface9
*backbuffer
= NULL
, *offscreen
= NULL
;
981 static const float quad
[][5] = {
982 {-0.5f
, -0.5f
, 0.1f
, 0.0f
, 0.0f
},
983 {-0.5f
, 0.5f
, 0.1f
, 0.0f
, 1.0f
},
984 { 0.5f
, -0.5f
, 0.1f
, 1.0f
, 0.0f
},
985 { 0.5f
, 0.5f
, 0.1f
, 1.0f
, 1.0f
},
988 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
989 ok(hr
== D3D_OK
, "Clear failed, hr = %s\n", DXGetErrorString9(hr
));
991 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &offscreenTexture
, NULL
);
992 ok(hr
== D3D_OK
|| D3DERR_INVALIDCALL
, "Creating the offscreen render target failed, hr = %s\n", DXGetErrorString9(hr
));
993 if(!offscreenTexture
) {
994 trace("Failed to create an X8R8G8B8 offscreen texture, trying R5G6B5\n");
995 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
, D3DFMT_R5G6B5
, D3DPOOL_DEFAULT
, &offscreenTexture
, NULL
);
996 ok(hr
== D3D_OK
|| D3DERR_INVALIDCALL
, "Creating the offscreen render target failed, hr = %s\n", DXGetErrorString9(hr
));
997 if(!offscreenTexture
) {
998 skip("Cannot create an offscreen render target\n");
1003 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
1004 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %s\n", DXGetErrorString9(hr
));
1009 hr
= IDirect3DTexture9_GetSurfaceLevel(offscreenTexture
, 0, &offscreen
);
1010 ok(hr
== D3D_OK
, "Can't get offscreen surface, hr = %s\n", DXGetErrorString9(hr
));
1015 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
1016 ok(hr
== D3D_OK
, "SetFVF failed, hr = %s\n", DXGetErrorString9(hr
));
1018 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
1019 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %s\n", DXGetErrorString9(hr
));
1020 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
1021 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %s\n", DXGetErrorString9(hr
));
1022 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MINFILTER
, D3DTEXF_POINT
);
1023 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_MINFILTER failed (0x%08x)\n", hr
);
1024 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAGFILTER
, D3DTEXF_POINT
);
1025 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr
);
1026 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
1027 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
1029 if(IDirect3DDevice9_BeginScene(device
) == D3D_OK
) {
1030 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, offscreen
);
1031 ok(hr
== D3D_OK
, "SetRenderTarget failed, hr = %s\n", DXGetErrorString9(hr
));
1032 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
1033 ok(hr
== D3D_OK
, "Clear failed, hr = %s\n", DXGetErrorString9(hr
));
1035 /* Draw without textures - Should resut in a white quad */
1036 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(quad
[0]));
1037 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %s\n", DXGetErrorString9(hr
));
1039 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
1040 ok(hr
== D3D_OK
, "SetRenderTarget failed, hr = %s\n", DXGetErrorString9(hr
));
1041 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) offscreenTexture
);
1042 ok(hr
== D3D_OK
, "SetTexture failed, %s\n", DXGetErrorString9(hr
));
1044 /* This time with the texture */
1045 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(quad
[0]));
1046 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %s\n", DXGetErrorString9(hr
));
1048 IDirect3DDevice9_EndScene(device
);
1051 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
1053 /* Center quad - should be white */
1054 color
= getPixelColor(device
, 320, 240);
1055 ok(color
== 0x00ffffff, "Offscreen failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
1056 /* Some quad in the cleared part of the texture */
1057 color
= getPixelColor(device
, 170, 240);
1058 ok(color
== 0x00ff00ff, "Offscreen failed: Got color 0x%08x, expected 0x00ff00ff.\n", color
);
1059 /* Part of the originally cleared back buffer */
1060 color
= getPixelColor(device
, 10, 10);
1061 ok(color
== 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
1063 /* Lower left corner of the screen, where back buffer offscreen rendering draws the offscreen texture.
1064 * It should be red, but the offscreen texture may leave some junk there. Not tested yet. Depending on
1065 * the offscreen rendering mode this test would succeed or fail
1067 color
= getPixelColor(device
, 10, 470);
1068 ok(color
== 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
1072 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
1074 /* restore things */
1076 IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
1077 IDirect3DSurface9_Release(backbuffer
);
1079 if(offscreenTexture
) {
1080 IDirect3DTexture9_Release(offscreenTexture
);
1083 IDirect3DSurface9_Release(offscreen
);
1087 /* This test tests fog in combination with shaders.
1088 * What's tested: linear fog (vertex and table) with pixel shader
1089 * linear table fog with non foggy vertex shader
1090 * vertex fog with foggy vertex shader
1091 * What's not tested: non linear fog with shader
1092 * table fog with foggy vertex shader
1094 static void fog_with_shader_test(IDirect3DDevice9
*device
)
1104 /* basic vertex shader without fog computation ("non foggy") */
1105 static const DWORD vertex_shader_code1
[] = {
1106 0xfffe0101, /* vs_1_1 */
1107 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
1108 0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
1109 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
1110 0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
1113 /* basic vertex shader with reversed fog computation ("foggy") */
1114 static const DWORD vertex_shader_code2
[] = {
1115 0xfffe0101, /* vs_1_1 */
1116 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
1117 0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
1118 0x00000051, 0xa00f0000, 0xbfa00000, 0x00000000, 0xbf666666, 0x00000000, /* def c0, -1.25, 0.0, -0.9, 0.0 */
1119 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
1120 0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
1121 0x00000002, 0x800f0000, 0x90aa0000, 0xa0aa0000, /* add r0, v0.z, c0.z */
1122 0x00000005, 0xc00f0001, 0x80000000, 0xa0000000, /* mul oFog, r0.x, c0.x */
1125 /* basic pixel shader */
1126 static const DWORD pixel_shader_code
[] = {
1127 0xffff0101, /* ps_1_1 */
1128 0x00000001, 0x800f0000, 0x90e40000, /* mov r0, vo */
1132 static struct vertex quad
[] = {
1133 {-1.0f
, -1.0f
, 0.0f
, 0xFFFF0000 },
1134 {-1.0f
, 1.0f
, 0.0f
, 0xFFFF0000 },
1135 { 1.0f
, -1.0f
, 0.0f
, 0xFFFF0000 },
1136 { 1.0f
, 1.0f
, 0.0f
, 0xFFFF0000 },
1139 static const D3DVERTEXELEMENT9 decl_elements
[] = {
1140 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
1141 {0, 12, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
1145 IDirect3DVertexDeclaration9
*vertex_declaration
= NULL
;
1146 IDirect3DVertexShader9
*vertex_shader
[3] = {NULL
, NULL
, NULL
};
1147 IDirect3DPixelShader9
*pixel_shader
[2] = {NULL
, NULL
};
1149 /* This reference data was collected on a nVidia GeForce 7600GS driver version 84.19 DirectX version 9.0c on Windows XP */
1150 static const struct test_data_t
{
1155 unsigned int color
[11];
1157 /* only pixel shader: */
1159 {0x0000ff00, 0x0000ff00, 0x0020df00, 0x0040bf00, 0x005fa000, 0x007f8000,
1160 0x009f6000, 0x00bf4000, 0x00df2000, 0x00ff0000, 0x00ff0000}},
1162 {0x0000ff00, 0x0000ff00, 0x0020df00, 0x0040bf00, 0x005fa000, 0x007f8000,
1163 0x009f6000, 0x00bf4000, 0x00df2000, 0x00ff0000, 0x00ff0000}},
1165 {0x0000ff00, 0x0000ff00, 0x0020df00, 0x0040bf00, 0x005fa000, 0x007f8000,
1166 0x009f6000, 0x00bf4000, 0x00df2000, 0x00ff0000, 0x00ff0000}},
1168 {0x0000ff00, 0x0000ff00, 0x0020df00, 0x0040bf00, 0x005fa000, 0x007f8000,
1169 0x009f6000, 0x00bf4000, 0x00df2000, 0x00ff0000, 0x00ff0000}},
1171 {0x0000ff00, 0x0000ff00, 0x0020df00, 0x0040bf00, 0x005fa000, 0x007f8000,
1172 0x009f6000, 0x00bf4000, 0x00df2000, 0x00ff0000, 0x00ff0000}},
1176 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
1177 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00}},
1179 {0x0000ff00, 0x0000ff00, 0x0020df00, 0x0040bf00, 0x005fa000, 0x007f8000,
1180 0x009f6000, 0x00bf4000, 0x00df2000, 0x00ff0000, 0x00ff0000}},
1182 {0x0000ff00, 0x0000ff00, 0x0020df00, 0x0040bf00, 0x005fa000, 0x007f8000,
1183 0x009f6000, 0x00bf4000, 0x00df2000, 0x00ff0000, 0x00ff0000}},
1185 {0x0000ff00, 0x0000ff00, 0x0020df00, 0x0040bf00, 0x005fa000, 0x007f8000,
1186 0x009f6000, 0x00bf4000, 0x00df2000, 0x00ff0000, 0x00ff0000}},
1188 {0x0000ff00, 0x0000ff00, 0x0020df00, 0x0040bf00, 0x005fa000, 0x007f8000,
1189 0x009f6000, 0x00bf4000, 0x00df2000, 0x00ff0000, 0x00ff0000}},
1191 /* vertex shader and pixel shader */
1193 {0x0000ff00, 0x0000ff00, 0x0020df00, 0x0040bf00, 0x005fa000, 0x007f8000,
1194 0x009f6000, 0x00bf4000, 0x00df2000, 0x00ff0000, 0x00ff0000}},
1196 {0x0000ff00, 0x0000ff00, 0x0020df00, 0x0040bf00, 0x005fa000, 0x007f8000,
1197 0x009f6000, 0x00bf4000, 0x00df2000, 0x00ff0000, 0x00ff0000}},
1199 {0x0000ff00, 0x0000ff00, 0x0020df00, 0x0040bf00, 0x005fa000, 0x007f8000,
1200 0x009f6000, 0x00bf4000, 0x00df2000, 0x00ff0000, 0x00ff0000}},
1202 {0x0000ff00, 0x0000ff00, 0x0020df00, 0x0040bf00, 0x005fa000, 0x007f8000,
1203 0x009f6000, 0x00bf4000, 0x00df2000, 0x00ff0000, 0x00ff0000}},
1205 #if 0 /* FIXME: these fail on GeForce 8500 */
1206 /* foggy vertex shader */
1208 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
1209 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
1211 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
1212 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
1214 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
1215 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
1217 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
1218 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
1221 /* foggy vertex shader and pixel shader */
1223 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
1224 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
1226 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
1227 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
1229 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
1230 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
1232 {0x00ff0000, 0x00fe0100, 0x00de2100, 0x00bf4000, 0x009f6000, 0x007f8000,
1233 0x005fa000, 0x003fc000, 0x001fe000, 0x0000ff00, 0x0000ff00}},
1237 /* NOTE: changing these values will not affect the tests with foggy vertex shader, as the values are hardcoded in the shader*/
1241 hr
= IDirect3DDevice9_CreateVertexShader(device
, vertex_shader_code1
, &vertex_shader
[1]);
1242 ok(SUCCEEDED(hr
), "CreateVertexShader failed (%08x)\n", hr
);
1243 hr
= IDirect3DDevice9_CreateVertexShader(device
, vertex_shader_code2
, &vertex_shader
[2]);
1244 ok(SUCCEEDED(hr
), "CreateVertexShader failed (%08x)\n", hr
);
1245 hr
= IDirect3DDevice9_CreatePixelShader(device
, pixel_shader_code
, &pixel_shader
[1]);
1246 ok(SUCCEEDED(hr
), "CreatePixelShader failed (%08x)\n", hr
);
1247 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &vertex_declaration
);
1248 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (%08x)\n", hr
);
1250 /* Setup initial states: No lighting, fog on, fog color */
1251 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
1252 ok(hr
== D3D_OK
, "Turning off lighting failed (%08x)\n", hr
);
1253 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGENABLE
, TRUE
);
1254 ok(hr
== D3D_OK
, "Turning on fog calculations failed (%08x)\n", hr
);
1255 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGCOLOR
, 0xFF00FF00 /* A nice green */);
1256 ok(hr
== D3D_OK
, "Setting fog color failed (%08x)\n", hr
);
1257 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, vertex_declaration
);
1258 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed (%08x)\n", hr
);
1260 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGTABLEMODE
, D3DFOG_NONE
);
1261 ok(hr
== D3D_OK
, "Turning off table fog failed (%08x)\n", hr
);
1262 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, D3DFOG_NONE
);
1263 ok(hr
== D3D_OK
, "Turning off vertex fog failed (%08x)\n", hr
);
1265 /* Use fogtart = 0.1 and end = 0.9 to test behavior outside the fog transition phase, too*/
1266 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGSTART
, start
.i
);
1267 ok(hr
== D3D_OK
, "Setting fog start failed (%08x)\n", hr
);
1268 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGEND
, end
.i
);
1269 ok(hr
== D3D_OK
, "Setting fog end failed (%08x)\n", hr
);
1271 for (i
= 0; i
< sizeof(test_data
)/sizeof(test_data
[0]); i
++)
1273 hr
= IDirect3DDevice9_SetVertexShader(device
, vertex_shader
[test_data
[i
].vshader
]);
1274 ok(SUCCEEDED(hr
), "SetVertexShader failed (%08x)\n", hr
);
1275 hr
= IDirect3DDevice9_SetPixelShader(device
, pixel_shader
[test_data
[i
].pshader
]);
1276 ok(SUCCEEDED(hr
), "SetPixelShader failed (%08x)\n", hr
);
1277 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, test_data
[i
].vfog
);
1278 ok( hr
== D3D_OK
, "Setting fog vertex mode to D3DFOG_LINEAR failed (%08x)\n", hr
);
1279 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGTABLEMODE
, test_data
[i
].tfog
);
1280 ok( hr
== D3D_OK
, "Setting fog table mode to D3DFOG_LINEAR failed (%08x)\n", hr
);
1282 for(j
=0; j
< 11; j
++)
1284 /* Don't use the whole zrange to prevent rounding errors */
1285 quad
[0].z
= 0.001f
+ (float)j
/ 10.02f
;
1286 quad
[1].z
= 0.001f
+ (float)j
/ 10.02f
;
1287 quad
[2].z
= 0.001f
+ (float)j
/ 10.02f
;
1288 quad
[3].z
= 0.001f
+ (float)j
/ 10.02f
;
1290 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
1291 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed (%08x)\n", hr
);
1293 hr
= IDirect3DDevice9_BeginScene(device
);
1294 ok( hr
== D3D_OK
, "BeginScene returned failed (%08x)\n", hr
);
1296 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad
[0], sizeof(quad
[0]));
1297 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
1299 hr
= IDirect3DDevice9_EndScene(device
);
1300 ok(hr
== D3D_OK
, "EndScene failed (%08x)\n", hr
);
1302 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
1304 /* As the red and green component are the result of blending use 5% tolerance on the expected value */
1305 color
= getPixelColor(device
, 128, 240);
1306 ok((unsigned char)(color
) == ((unsigned char)test_data
[i
].color
[j
])
1307 && abs( ((unsigned char)(color
>>8)) - (unsigned char)(test_data
[i
].color
[j
]>>8) ) < 13
1308 && abs( ((unsigned char)(color
>>16)) - (unsigned char)(test_data
[i
].color
[j
]>>16) ) < 13,
1309 "fog ps%i vs%i fvm%i ftm%i %d: got color %08x, expected %08x +-5%%\n", test_data
[i
].vshader
, test_data
[i
].pshader
, test_data
[i
].vfog
, test_data
[i
].tfog
, j
, color
, test_data
[i
].color
[j
]);
1314 hr
= IDirect3DDevice9_SetVertexShader(device
, NULL
);
1315 ok(SUCCEEDED(hr
), "SetVertexShader failed (%08x)\n", hr
);
1316 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
1317 ok(SUCCEEDED(hr
), "SetPixelShader failed (%08x)\n", hr
);
1318 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
1319 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed (%08x)\n", hr
);
1320 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGENABLE
, FALSE
);
1321 ok(hr
== D3D_OK
, "Turning off fog calculations failed (%08x)\n", hr
);
1323 IDirect3DVertexShader9_Release(vertex_shader
[1]);
1324 IDirect3DVertexShader9_Release(vertex_shader
[2]);
1325 IDirect3DPixelShader9_Release(pixel_shader
[1]);
1326 IDirect3DVertexDeclaration9_Release(vertex_declaration
);
1329 static void generate_bumpmap_textures(IDirect3DDevice9
*device
) {
1330 unsigned int i
, x
, y
;
1332 IDirect3DTexture9
*texture
[2] = {NULL
, NULL
};
1333 D3DLOCKED_RECT locked_rect
;
1335 /* Generate the textures */
1338 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 1, 0, i
?D3DFMT_A8R8G8B8
:D3DFMT_V8U8
,
1339 D3DPOOL_MANAGED
, &texture
[i
], NULL
);
1340 ok(SUCCEEDED(hr
), "CreateTexture failed (0x%08x)\n", hr
);
1342 hr
= IDirect3DTexture9_LockRect(texture
[i
], 0, &locked_rect
, NULL
, 0);
1343 ok(SUCCEEDED(hr
), "LockRect failed (0x%08x)\n", hr
);
1344 for (y
= 0; y
< 128; ++y
)
1347 { /* Set up black texture with 2x2 texel white spot in the middle */
1348 DWORD
*ptr
= (DWORD
*)(((BYTE
*)locked_rect
.pBits
) + (y
* locked_rect
.Pitch
));
1349 for (x
= 0; x
< 128; ++x
)
1351 if(y
>62 && y
<66 && x
>62 && x
<66)
1352 *ptr
++ = 0xffffffff;
1354 *ptr
++ = 0xff000000;
1358 { /* Set up a displacement map which points away from the center parallel to the closest axis.
1359 * (if multiplied with bumpenvmat)
1361 WORD
*ptr
= (WORD
*)(((BYTE
*)locked_rect
.pBits
) + (y
* locked_rect
.Pitch
));
1362 for (x
= 0; x
< 128; ++x
)
1364 if(abs(x
-64)>abs(y
-64))
1381 hr
= IDirect3DTexture9_UnlockRect(texture
[i
], 0);
1382 ok(SUCCEEDED(hr
), "UnlockRect failed (0x%08x)\n", hr
);
1384 hr
= IDirect3DDevice9_SetTexture(device
, i
, (IDirect3DBaseTexture9
*)texture
[i
]);
1385 ok(SUCCEEDED(hr
), "SetTexture failed (0x%08x)\n", hr
);
1387 /* Disable texture filtering */
1388 hr
= IDirect3DDevice9_SetSamplerState(device
, i
, D3DSAMP_MINFILTER
, D3DTEXF_POINT
);
1389 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_MINFILTER failed (0x%08x)\n", hr
);
1390 hr
= IDirect3DDevice9_SetSamplerState(device
, i
, D3DSAMP_MAGFILTER
, D3DTEXF_POINT
);
1391 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr
);
1393 hr
= IDirect3DDevice9_SetSamplerState(device
, i
, D3DSAMP_ADDRESSU
, D3DTADDRESS_CLAMP
);
1394 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_ADDRESSU failed (0x%08x)\n", hr
);
1395 hr
= IDirect3DDevice9_SetSamplerState(device
, i
, D3DSAMP_ADDRESSV
, D3DTADDRESS_CLAMP
);
1396 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_ADDRESSV failed (0x%08x)\n", hr
);
1400 /* test the behavior of the texbem instruction
1401 * with normal 2D and projective 2D textures
1403 static void texbem_test(IDirect3DDevice9
*device
)
1409 static const DWORD pixel_shader_code
[] = {
1410 0xffff0101, /* ps_1_1*/
1411 0x00000042, 0xb00f0000, /* tex t0*/
1412 0x00000043, 0xb00f0001, 0xb0e40000, /* texbem t1, t0*/
1413 0x00000001, 0x800f0000, 0xb0e40001, /* mov r0, t1*/
1417 static const float quad
[][7] = {
1418 {-128.0f
/640.0f
, -128.0f
/480.0f
, 0.1f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
},
1419 {-128.0f
/640.0f
, 128.0f
/480.0f
, 0.1f
, 0.0f
, 1.0f
, 0.0f
, 1.0f
},
1420 { 128.0f
/640.0f
, -128.0f
/480.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
, 0.0f
},
1421 { 128.0f
/640.0f
, 128.0f
/480.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
},
1423 static const float quad_proj
[][9] = {
1424 {-128.0f
/640.0f
, -128.0f
/480.0f
, 0.1f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 128.0f
},
1425 {-128.0f
/640.0f
, 128.0f
/480.0f
, 0.1f
, 0.0f
, 1.0f
, 0.0f
, 128.0f
, 0.0f
, 128.0f
},
1426 { 128.0f
/640.0f
, -128.0f
/480.0f
, 0.1f
, 1.0f
, 0.0f
, 128.0f
, 0.0f
, 0.0f
, 128.0f
},
1427 { 128.0f
/640.0f
, 128.0f
/480.0f
, 0.1f
, 1.0f
, 1.0f
, 128.0f
, 128.0f
, 0.0f
, 128.0f
},
1430 static const D3DVERTEXELEMENT9 decl_elements
[][4] = { {
1431 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
1432 {0, 12, D3DDECLTYPE_FLOAT2
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
1433 {0, 20, D3DDECLTYPE_FLOAT2
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 1},
1436 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
1437 {0, 12, D3DDECLTYPE_FLOAT2
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
1438 {0, 20, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 1},
1442 /* use assymetric matrix to test loading */
1443 float bumpenvmat
[4] = {0.0,0.5,-0.5,0.0};
1445 IDirect3DVertexDeclaration9
*vertex_declaration
= NULL
;
1446 IDirect3DPixelShader9
*pixel_shader
= NULL
;
1447 IDirect3DTexture9
*texture
= NULL
;
1449 generate_bumpmap_textures(device
);
1451 IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_BUMPENVMAT00
, *(LPDWORD
)&bumpenvmat
[0]);
1452 IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_BUMPENVMAT01
, *(LPDWORD
)&bumpenvmat
[1]);
1453 IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_BUMPENVMAT10
, *(LPDWORD
)&bumpenvmat
[2]);
1454 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_BUMPENVMAT11
, *(LPDWORD
)&bumpenvmat
[3]);
1455 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
1457 hr
= IDirect3DDevice9_SetVertexShader(device
, NULL
);
1458 ok(SUCCEEDED(hr
), "SetVertexShader failed (%08x)\n", hr
);
1460 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
1461 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed (%08x)\n", hr
);
1467 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT4
|D3DTTFF_PROJECTED
);
1468 ok(SUCCEEDED(hr
), "SetTextureStageState D3DTSS_TEXTURETRANSFORMFLAGS failed (0x%08x)\n", hr
);
1471 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
[i
], &vertex_declaration
);
1472 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (0x%08x)\n", hr
);
1473 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, vertex_declaration
);
1474 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed (0x%08x)\n", hr
);
1476 hr
= IDirect3DDevice9_CreatePixelShader(device
, pixel_shader_code
, &pixel_shader
);
1477 ok(SUCCEEDED(hr
), "CreatePixelShader failed (%08x)\n", hr
);
1478 hr
= IDirect3DDevice9_SetPixelShader(device
, pixel_shader
);
1479 ok(SUCCEEDED(hr
), "SetPixelShader failed (%08x)\n", hr
);
1481 hr
= IDirect3DDevice9_BeginScene(device
);
1482 ok(SUCCEEDED(hr
), "BeginScene failed (0x%08x)\n", hr
);
1485 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad
[0], sizeof(quad
[0]));
1487 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad_proj
[0], sizeof(quad_proj
[0]));
1488 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (0x%08x)\n", hr
);
1490 hr
= IDirect3DDevice9_EndScene(device
);
1491 ok(SUCCEEDED(hr
), "EndScene failed (0x%08x)\n", hr
);
1493 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
1494 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
1496 color
= getPixelColor(device
, 320-32, 240);
1497 ok(color
== 0x00ffffff, "texbem failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
1498 color
= getPixelColor(device
, 320+32, 240);
1499 ok(color
== 0x00ffffff, "texbem failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
1500 color
= getPixelColor(device
, 320, 240-32);
1501 ok(color
== 0x00ffffff, "texbem failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
1502 color
= getPixelColor(device
, 320, 240+32);
1503 ok(color
== 0x00ffffff, "texbem failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
1505 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
1506 ok(SUCCEEDED(hr
), "SetPixelShader failed (%08x)\n", hr
);
1507 IDirect3DPixelShader9_Release(pixel_shader
);
1509 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
1510 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed (%08x)\n", hr
);
1511 IDirect3DVertexDeclaration9_Release(vertex_declaration
);
1515 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0, 0.0f
, 0);
1516 ok(SUCCEEDED(hr
), "Clear failed (0x%08x)\n", hr
);
1518 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT2
);
1519 ok(SUCCEEDED(hr
), "SetTextureStageState D3DTSS_TEXTURETRANSFORMFLAGS failed (0x%08x)\n", hr
);
1523 hr
= IDirect3DDevice9_GetTexture(device
, i
, (IDirect3DBaseTexture9
**) &texture
);
1524 ok(SUCCEEDED(hr
), "IDirect3DDevice9_GetTexture failed (0x%08x)\n", hr
);
1525 IDirect3DTexture9_Release(texture
); /* For the GetTexture */
1526 hr
= IDirect3DDevice9_SetTexture(device
, i
, NULL
);
1527 ok(SUCCEEDED(hr
), "SetTexture failed (0x%08x)\n", hr
);
1528 IDirect3DTexture9_Release(texture
);
1532 static void z_range_test(IDirect3DDevice9
*device
)
1534 const struct vertex quad
[] =
1536 {-1.0f
, 0.0f
, 1.1f
, 0xffff0000},
1537 {-1.0f
, 1.0f
, 1.1f
, 0xffff0000},
1538 { 1.0f
, 0.0f
, -1.1f
, 0xffff0000},
1539 { 1.0f
, 1.0f
, -1.1f
, 0xffff0000},
1541 const struct vertex quad2
[] =
1543 {-1.0f
, 0.0f
, 1.1f
, 0xff0000ff},
1544 {-1.0f
, 1.0f
, 1.1f
, 0xff0000ff},
1545 { 1.0f
, 0.0f
, -1.1f
, 0xff0000ff},
1546 { 1.0f
, 1.0f
, -1.1f
, 0xff0000ff},
1549 const struct tvertex quad3
[] =
1551 { 0, 240, 1.1f
, 1.0, 0xffffff00},
1552 { 0, 480, 1.1f
, 1.0, 0xffffff00},
1553 { 640, 240, -1.1f
, 1.0, 0xffffff00},
1554 { 640, 480, -1.1f
, 1.0, 0xffffff00},
1556 const struct tvertex quad4
[] =
1558 { 0, 240, 1.1f
, 1.0, 0xff00ff00},
1559 { 0, 480, 1.1f
, 1.0, 0xff00ff00},
1560 { 640, 240, -1.1f
, 1.0, 0xff00ff00},
1561 { 640, 480, -1.1f
, 1.0, 0xff00ff00},
1565 IDirect3DVertexShader9
*shader
;
1566 IDirect3DVertexDeclaration9
*decl
;
1568 const DWORD shader_code
[] = {
1569 0xfffe0101, /* vs_1_1 */
1570 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
1571 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
1572 0x00000001, 0xd00f0000, 0xa0e40000, /* mov oD0, c0 */
1573 0x0000ffff /* end */
1575 static const D3DVERTEXELEMENT9 decl_elements
[] = {
1576 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
1579 /* Does the Present clear the depth stencil? Clear the depth buffer with some value != 0,
1580 * then call Present. Then clear the color buffer to make sure it has some defined content
1581 * after the Present with D3DSWAPEFFECT_DISCARD. After that draw a plane that is somewhere cut
1582 * by the depth value.
1584 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffffff, 0.75, 0);
1585 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %s\n", DXGetErrorString9(hr
));
1586 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
1587 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.4, 0);
1589 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CLIPPING
, TRUE
);
1590 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
1591 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_TRUE
);
1592 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
1593 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, FALSE
);
1594 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
1595 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_GREATER
);
1596 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
1597 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
1598 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF returned %s\n", DXGetErrorString9(hr
));
1600 hr
= IDirect3DDevice9_BeginScene(device
);
1601 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %s\n", DXGetErrorString9(hr
));
1604 /* Test the untransformed vertex path */
1605 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2 /*PrimCount */, quad
, sizeof(quad
[0]));
1606 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawIndexedPrimitiveUP failed with %s\n", DXGetErrorString9(hr
));
1607 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_LESS
);
1608 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
1609 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2 /*PrimCount */, quad2
, sizeof(quad2
[0]));
1610 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawIndexedPrimitiveUP failed with %s\n", DXGetErrorString9(hr
));
1612 /* Test the transformed vertex path */
1613 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
);
1614 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF returned %s\n", DXGetErrorString9(hr
));
1616 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2 /*PrimCount */, quad4
, sizeof(quad4
[0]));
1617 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawIndexedPrimitiveUP failed with %s\n", DXGetErrorString9(hr
));
1618 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_GREATER
);
1619 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
1620 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2 /*PrimCount */, quad3
, sizeof(quad3
[0]));
1621 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawIndexedPrimitiveUP failed with %s\n", DXGetErrorString9(hr
));
1623 hr
= IDirect3DDevice9_EndScene(device
);
1624 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %s\n", DXGetErrorString9(hr
));
1627 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
1628 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
1630 /* Do not test the exact corner pixels, but go pretty close to them */
1632 /* Clipped because z > 1.0 */
1633 color
= getPixelColor(device
, 28, 238);
1634 ok(color
== 0x00ffffff, "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
1635 color
= getPixelColor(device
, 28, 241);
1636 ok(color
== 0x00ffffff, "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
1638 /* Not clipped, > z buffer clear value(0.75) */
1639 color
= getPixelColor(device
, 31, 238);
1640 ok(color
== 0x00ff0000, "Z range failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
1641 color
= getPixelColor(device
, 31, 241);
1642 ok(color
== 0x00ffff00, "Z range failed: Got color 0x%08x, expected 0x00ffff00.\n", color
);
1643 color
= getPixelColor(device
, 100, 238);
1644 ok(color
== 0x00ff0000, "Z range failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
1645 color
= getPixelColor(device
, 100, 241);
1646 ok(color
== 0x00ffff00, "Z range failed: Got color 0x%08x, expected 0x00ffff00.\n", color
);
1648 /* Not clipped, < z buffer clear value */
1649 color
= getPixelColor(device
, 104, 238);
1650 ok(color
== 0x000000ff, "Z range failed: Got color 0x%08x, expected 0x000000ff.\n", color
);
1651 color
= getPixelColor(device
, 104, 241);
1652 ok(color
== 0x0000ff00, "Z range failed: Got color 0x%08x, expected 0x0000ff00.\n", color
);
1653 color
= getPixelColor(device
, 318, 238);
1654 ok(color
== 0x000000ff, "Z range failed: Got color 0x%08x, expected 0x000000ff.\n", color
);
1655 color
= getPixelColor(device
, 318, 241);
1656 ok(color
== 0x0000ff00, "Z range failed: Got color 0x%08x, expected 0x0000ff00.\n", color
);
1658 /* Clipped because z < 0.0 */
1659 color
= getPixelColor(device
, 321, 238);
1660 ok(color
== 0x00ffffff, "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
1661 color
= getPixelColor(device
, 321, 241);
1662 ok(color
== 0x00ffffff, "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
1664 /* Test the shader path */
1665 IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
1666 if (caps
.VertexShaderVersion
< D3DVS_VERSION(1, 1)) {
1667 skip("Vertex shaders not supported\n");
1670 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_code
, &shader
);
1671 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %s\n", DXGetErrorString9(hr
));
1672 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &decl
);
1673 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
1675 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.4, 0);
1677 IDirect3DDevice9_SetVertexDeclaration(device
, decl
);
1678 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
1679 IDirect3DDevice9_SetVertexShader(device
, shader
);
1680 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
1682 hr
= IDirect3DDevice9_BeginScene(device
);
1683 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %s\n", DXGetErrorString9(hr
));
1686 float colorf
[] = {1.0, 0.0, 0.0, 1.0};
1687 float colorf2
[] = {0.0, 0.0, 1.0, 1.0};
1688 IDirect3DDevice9_SetVertexShaderConstantF(device
, 0, colorf
, 1);
1689 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2 /*PrimCount */, quad
, sizeof(quad
[0]));
1690 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawIndexedPrimitiveUP failed with %s\n", DXGetErrorString9(hr
));
1691 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_LESS
);
1692 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
1693 IDirect3DDevice9_SetVertexShaderConstantF(device
, 0, colorf2
, 1);
1694 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2 /*PrimCount */, quad2
, sizeof(quad2
[0]));
1695 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawIndexedPrimitiveUP failed with %s\n", DXGetErrorString9(hr
));
1697 hr
= IDirect3DDevice9_EndScene(device
);
1698 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %s\n", DXGetErrorString9(hr
));
1701 IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
1702 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
1703 IDirect3DDevice9_SetVertexShader(device
, NULL
);
1704 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
1706 IDirect3DVertexDeclaration9_Release(decl
);
1707 IDirect3DVertexShader9_Release(shader
);
1709 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
1710 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
1712 color
= getPixelColor(device
, 28, 238);
1713 ok(color
== 0x00ffffff, "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
1715 /* 1.0 < z < 0.75 */
1716 color
= getPixelColor(device
, 31, 238);
1717 ok(color
== 0x00ff0000, "Z range failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
1718 color
= getPixelColor(device
, 100, 238);
1719 ok(color
== 0x00ff0000, "Z range failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
1721 /* 0.75 < z < 0.0 */
1722 color
= getPixelColor(device
, 104, 238);
1723 ok(color
== 0x000000ff, "Z range failed: Got color 0x%08x, expected 0x000000ff.\n", color
);
1724 color
= getPixelColor(device
, 318, 238);
1725 ok(color
== 0x000000ff, "Z range failed: Got color 0x%08x, expected 0x000000ff.\n", color
);
1728 color
= getPixelColor(device
, 321, 238);
1729 ok(color
== 0x00ffffff, "Z range failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
1732 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_FALSE
);
1733 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
1734 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CLIPPING
, FALSE
);
1735 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
1736 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, TRUE
);
1737 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
1740 static void fill_surface(IDirect3DSurface9
*surface
, DWORD color
)
1742 D3DSURFACE_DESC desc
;
1748 memset(&desc
, 0, sizeof(desc
));
1749 memset(&l
, 0, sizeof(l
));
1750 hr
= IDirect3DSurface9_GetDesc(surface
, &desc
);
1751 ok(hr
== D3D_OK
, "IDirect3DSurface9_GetDesc failed with %s\n", DXGetErrorString9(hr
));
1752 hr
= IDirect3DSurface9_LockRect(surface
, &l
, NULL
, 0);
1753 ok(hr
== D3D_OK
, "IDirect3DSurface9_LockRect failed with %s\n", DXGetErrorString9(hr
));
1754 if(FAILED(hr
)) return;
1756 for(y
= 0; y
< desc
.Height
; y
++)
1758 mem
= (DWORD
*) ((BYTE
*) l
.pBits
+ y
* l
.Pitch
);
1759 for(x
= 0; x
< l
.Pitch
/ sizeof(DWORD
); x
++)
1764 hr
= IDirect3DSurface9_UnlockRect(surface
);
1765 ok(hr
== D3D_OK
, "IDirect3DSurface9_UnlockRect failed with %s\n", DXGetErrorString9(hr
));
1768 static void maxmip_test(IDirect3DDevice9
*device
)
1770 IDirect3DTexture9
*texture
= NULL
;
1771 IDirect3DSurface9
*surface
= NULL
;
1774 const float quads
[] = {
1775 -1.0, -1.0, 0.0, 0.0, 0.0,
1776 -1.0, 0.0, 0.0, 0.0, 1.0,
1777 0.0, -1.0, 0.0, 1.0, 0.0,
1778 0.0, 0.0, 0.0, 1.0, 1.0,
1780 0.0, -1.0, 0.0, 0.0, 0.0,
1781 0.0, 0.0, 0.0, 0.0, 1.0,
1782 1.0, -1.0, 0.0, 1.0, 0.0,
1783 1.0, 0.0, 0.0, 1.0, 1.0,
1785 0.0, 0.0, 0.0, 0.0, 0.0,
1786 0.0, 1.0, 0.0, 0.0, 1.0,
1787 1.0, 0.0, 0.0, 1.0, 0.0,
1788 1.0, 1.0, 0.0, 1.0, 1.0,
1790 -1.0, 0.0, 0.0, 0.0, 0.0,
1791 -1.0, 1.0, 0.0, 0.0, 1.0,
1792 0.0, 0.0, 0.0, 1.0, 0.0,
1793 0.0, 1.0, 0.0, 1.0, 1.0,
1796 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffffff, 0.0, 0);
1797 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %s\n", DXGetErrorString9(hr
));
1799 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 3, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
,
1801 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture failed with %s\n", DXGetErrorString9(hr
));
1804 skip("Failed to create test texture\n");
1808 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1809 fill_surface(surface
, 0xffff0000);
1810 IDirect3DSurface9_Release(surface
);
1811 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 1, &surface
);
1812 fill_surface(surface
, 0xff00ff00);
1813 IDirect3DSurface9_Release(surface
);
1814 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 2, &surface
);
1815 fill_surface(surface
, 0xff0000ff);
1816 IDirect3DSurface9_Release(surface
);
1818 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) texture
);
1819 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture failed with %s\n", DXGetErrorString9(hr
));
1820 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
1821 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with %s\n", DXGetErrorString9(hr
));
1823 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MIPFILTER
, D3DTEXF_NONE
);
1824 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState failed with %s\n", DXGetErrorString9(hr
));
1826 hr
= IDirect3DDevice9_BeginScene(device
);
1829 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 0);
1830 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState failed with %s\n", DXGetErrorString9(hr
));
1831 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[ 0], 5 * sizeof(float));
1832 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
1834 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 1);
1835 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState failed with %s\n", DXGetErrorString9(hr
));
1836 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[20], 5 * sizeof(float));
1837 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
1839 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 2);
1840 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState failed with %s\n", DXGetErrorString9(hr
));
1841 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[40], 5 * sizeof(float));
1842 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
1844 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 3);
1845 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState failed with %s\n", DXGetErrorString9(hr
));
1846 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[60], 5 * sizeof(float));
1847 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
1848 hr
= IDirect3DDevice9_EndScene(device
);
1851 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
1852 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
1853 /* With mipmapping disabled, the max mip level is ignored, only level 0 is used */
1854 color
= getPixelColor(device
, 160, 360);
1855 ok(color
== 0x00FF0000, "MapMip 0, no mipfilter has color %08x\n", color
);
1856 color
= getPixelColor(device
, 160, 120);
1857 ok(color
== 0x00FF0000, "MapMip 3, no mipfilter has color %08x\n", color
);
1858 color
= getPixelColor(device
, 480, 120);
1859 ok(color
== 0x00FF0000, "MapMip 2, no mipfilter has color %08x\n", color
);
1860 color
= getPixelColor(device
, 480, 360);
1861 ok(color
== 0x00FF0000, "MapMip 1, no mipfilter has color %08x\n", color
);
1863 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffffff, 0.0, 0);
1864 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %s\n", DXGetErrorString9(hr
));
1866 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MIPFILTER
, D3DTEXF_POINT
);
1867 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState failed with %s\n", DXGetErrorString9(hr
));
1869 hr
= IDirect3DDevice9_BeginScene(device
);
1872 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 0);
1873 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState failed with %s\n", DXGetErrorString9(hr
));
1874 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[ 0], 5 * sizeof(float));
1875 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
1877 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 1);
1878 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState failed with %s\n", DXGetErrorString9(hr
));
1879 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[20], 5 * sizeof(float));
1880 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
1882 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 2);
1883 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState failed with %s\n", DXGetErrorString9(hr
));
1884 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[40], 5 * sizeof(float));
1885 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
1887 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 3);
1888 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState failed with %s\n", DXGetErrorString9(hr
));
1889 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quads
[60], 5 * sizeof(float));
1890 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
1891 hr
= IDirect3DDevice9_EndScene(device
);
1894 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 0);
1895 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState failed with %s\n", DXGetErrorString9(hr
));
1896 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MIPFILTER
, D3DTEXF_NONE
);
1897 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState failed with %s\n", DXGetErrorString9(hr
));
1899 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
1900 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
1901 /* Max Mip level 0-2 sample from the specified texture level, Max Mip level 3(> levels in texture)
1902 * samples from the highest level in the texture(level 2)
1904 color
= getPixelColor(device
, 160, 360);
1905 ok(color
== 0x00FF0000, "MapMip 0, point mipfilter has color %08x\n", color
);
1906 color
= getPixelColor(device
, 160, 120);
1907 ok(color
== 0x000000FF, "MapMip 3, point mipfilter has color %08x\n", color
);
1908 color
= getPixelColor(device
, 480, 120);
1909 ok(color
== 0x000000FF, "MapMip 2, point mipfilter has color %08x\n", color
);
1910 color
= getPixelColor(device
, 480, 360);
1911 ok(color
== 0x0000FF00, "MapMip 1, point mipfilter has color %08x\n", color
);
1913 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
1914 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture failed with %s\n", DXGetErrorString9(hr
));
1915 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAXMIPLEVEL
, 0);
1916 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState failed with %s\n", DXGetErrorString9(hr
));
1917 IDirect3DTexture9_Release(texture
);
1920 static void release_buffer_test(IDirect3DDevice9
*device
)
1922 IDirect3DVertexBuffer9
*vb
= NULL
;
1923 IDirect3DIndexBuffer9
*ib
= NULL
;
1928 static const struct vertex quad
[] = {
1929 {-1.0, -1.0, 0.1, 0xffff0000},
1930 {-1.0, 1.0, 0.1, 0xffff0000},
1931 { 1.0, 1.0, 0.1, 0xffff0000},
1933 {-1.0, -1.0, 0.1, 0xff00ff00},
1934 {-1.0, 1.0, 0.1, 0xff00ff00},
1935 { 1.0, 1.0, 0.1, 0xff00ff00}
1937 short indices
[] = {3, 4, 5};
1939 /* Index and vertex buffers should always be creatable */
1940 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, sizeof(quad
), 0, D3DFVF_XYZ
| D3DFVF_DIFFUSE
,
1941 D3DPOOL_MANAGED
, &vb
, NULL
);
1942 ok(hr
== D3D_OK
, "CreateVertexBuffer failed with %s\n", DXGetErrorString9(hr
));
1944 skip("Failed to create a vertex buffer\n");
1947 hr
= IDirect3DDevice9_CreateIndexBuffer(device
, sizeof(indices
), 0, D3DFMT_INDEX16
, D3DPOOL_DEFAULT
, &ib
, NULL
);
1948 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateIndexBuffer failed with %s\n", DXGetErrorString9(hr
));
1950 skip("Failed to create an index buffer\n");
1954 hr
= IDirect3DVertexBuffer9_Lock(vb
, 0, sizeof(quad
), (void **) &data
, 0);
1955 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Lock failed with %s\n", DXGetErrorString9(hr
));
1956 memcpy(data
, quad
, sizeof(quad
));
1957 hr
= IDirect3DVertexBuffer9_Unlock(vb
);
1958 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Unlock failed with %s\n", DXGetErrorString9(hr
));
1960 hr
= IDirect3DIndexBuffer9_Lock(ib
, 0, sizeof(indices
), (void **) &data
, 0);
1961 ok(hr
== D3D_OK
, "IDirect3DIndexBuffer9_Lock failed with %s\n", DXGetErrorString9(hr
));
1962 memcpy(data
, indices
, sizeof(indices
));
1963 hr
= IDirect3DIndexBuffer9_Unlock(ib
);
1964 ok(hr
== D3D_OK
, "IDirect3DIndexBuffer9_Unlock failed with %s\n", DXGetErrorString9(hr
));
1966 hr
= IDirect3DDevice9_SetIndices(device
, ib
);
1967 ok(hr
== D3D_OK
, "IDirect3DIndexBuffer8_Unlock failed with %s\n", DXGetErrorString9(hr
));
1968 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vb
, 0, sizeof(quad
[0]));
1969 ok(hr
== D3D_OK
, "IDirect3DIndexBuffer8_Unlock failed with %s\n", DXGetErrorString9(hr
));
1970 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
1971 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with %s\n", DXGetErrorString9(hr
));
1973 /* Now destroy the bound index buffer and draw again */
1974 ref
= IDirect3DIndexBuffer9_Release(ib
);
1975 ok(ref
== 0, "Index Buffer reference count is %08ld\n", ref
);
1977 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff0000ff, 0.0, 0);
1978 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %08x\n", hr
);
1980 hr
= IDirect3DDevice9_BeginScene(device
);
1981 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %08x\n", hr
);
1984 /* Deliberately using minvertexindex = 0 and numVertices = 6 to prevent d3d from
1985 * making assumptions about the indices or vertices
1987 hr
= IDirect3DDevice9_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, 0, 3, 3, 0, 1);
1988 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawIndexedPrimitive failed with %08x\n", hr
);
1989 hr
= IDirect3DDevice9_EndScene(device
);
1990 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %08x\n", hr
);
1993 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
1994 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %08x\n", hr
);
1996 hr
= IDirect3DDevice9_SetIndices(device
, NULL
);
1997 ok(hr
== D3D_OK
, "IDirect3DIndexBuffer9_Unlock failed with %08x\n", hr
);
1998 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 0, 0);
1999 ok(hr
== D3D_OK
, "IDirect3DIndexBuffer9_Unlock failed with %08x\n", hr
);
2001 /* Index buffer was already destroyed as part of the test */
2002 IDirect3DVertexBuffer9_Release(vb
);
2005 static void float_texture_test(IDirect3DDevice9
*device
)
2007 IDirect3D9
*d3d
= NULL
;
2009 IDirect3DTexture9
*texture
= NULL
;
2014 -1.0, -1.0, 0.1, 0.0, 0.0,
2015 -1.0, 1.0, 0.1, 0.0, 1.0,
2016 1.0, -1.0, 0.1, 1.0, 0.0,
2017 1.0, 1.0, 0.1, 1.0, 1.0,
2020 memset(&lr
, 0, sizeof(lr
));
2021 IDirect3DDevice9_GetDirect3D(device
, &d3d
);
2022 if(IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
, 0,
2023 D3DRTYPE_TEXTURE
, D3DFMT_R32F
) != D3D_OK
) {
2024 skip("D3DFMT_R32F textures not supported\n");
2028 hr
= IDirect3DDevice9_CreateTexture(device
, 1, 1, 1, 0, D3DFMT_R32F
,
2029 D3DPOOL_MANAGED
, &texture
, NULL
);
2030 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture failed with %s\n", DXGetErrorString9(hr
));
2032 skip("Failed to create R32F texture\n");
2036 hr
= IDirect3DTexture9_LockRect(texture
, 0, &lr
, NULL
, 0);
2037 ok(hr
== D3D_OK
, "IDirect3DTexture9_LockRect failed with %s\n", DXGetErrorString9(hr
));
2040 hr
= IDirect3DTexture9_UnlockRect(texture
, 0);
2041 ok(hr
== D3D_OK
, "IDirect3DTexture9_UnlockRect failed with %s\n", DXGetErrorString9(hr
));
2043 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) texture
);
2044 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture failed with %s\n", DXGetErrorString9(hr
));
2046 hr
= IDirect3DDevice9_BeginScene(device
);
2047 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %s\n", DXGetErrorString9(hr
));
2050 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
2051 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with %s\n", DXGetErrorString9(hr
));
2053 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
2054 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
2056 hr
= IDirect3DDevice9_EndScene(device
);
2057 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %s\n", DXGetErrorString9(hr
));
2059 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
2060 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture failed with %s\n", DXGetErrorString9(hr
));
2062 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
2063 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
2065 color
= getPixelColor(device
, 240, 320);
2066 ok(color
== 0x0000FFFF, "R32F with value 0.0 has color %08x, expected 0x0000FFFF\n", color
);
2069 if(texture
) IDirect3DTexture9_Release(texture
);
2070 IDirect3D9_Release(d3d
);
2073 static void g16r16_texture_test(IDirect3DDevice9
*device
)
2075 IDirect3D9
*d3d
= NULL
;
2077 IDirect3DTexture9
*texture
= NULL
;
2080 DWORD color
, red
, green
, blue
;
2082 -1.0, -1.0, 0.1, 0.0, 0.0,
2083 -1.0, 1.0, 0.1, 0.0, 1.0,
2084 1.0, -1.0, 0.1, 1.0, 0.0,
2085 1.0, 1.0, 0.1, 1.0, 1.0,
2088 memset(&lr
, 0, sizeof(lr
));
2089 IDirect3DDevice9_GetDirect3D(device
, &d3d
);
2090 if(IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
, 0,
2091 D3DRTYPE_TEXTURE
, D3DFMT_G16R16
) != D3D_OK
) {
2092 skip("D3DFMT_G16R16 textures not supported\n");
2096 hr
= IDirect3DDevice9_CreateTexture(device
, 1, 1, 1, 0, D3DFMT_G16R16
,
2097 D3DPOOL_MANAGED
, &texture
, NULL
);
2098 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture failed with %s\n", DXGetErrorString9(hr
));
2100 skip("Failed to create D3DFMT_G16R16 texture\n");
2104 hr
= IDirect3DTexture9_LockRect(texture
, 0, &lr
, NULL
, 0);
2105 ok(hr
== D3D_OK
, "IDirect3DTexture9_LockRect failed with %s\n", DXGetErrorString9(hr
));
2108 hr
= IDirect3DTexture9_UnlockRect(texture
, 0);
2109 ok(hr
== D3D_OK
, "IDirect3DTexture9_UnlockRect failed with %s\n", DXGetErrorString9(hr
));
2111 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) texture
);
2112 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture failed with %s\n", DXGetErrorString9(hr
));
2114 hr
= IDirect3DDevice9_BeginScene(device
);
2115 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %s\n", DXGetErrorString9(hr
));
2118 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
2119 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with %s\n", DXGetErrorString9(hr
));
2121 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
2122 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
2124 hr
= IDirect3DDevice9_EndScene(device
);
2125 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %s\n", DXGetErrorString9(hr
));
2127 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
2128 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture failed with %s\n", DXGetErrorString9(hr
));
2130 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
2131 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
2133 color
= getPixelColor(device
, 240, 320);
2134 red
= (color
& 0x00ff0000) >> 16;
2135 green
= (color
& 0x0000ff00) >> 8;
2136 blue
= (color
& 0x000000ff) >> 0;
2137 ok(blue
== 0xff && red
>= 0xef && red
<= 0xf1 && green
>= 0x0e && green
<= 0x10,
2138 "D3DFMT_G16R16 with value 0x00ffff00 has color %08x, expected 0x00F00FFF\n", color
);
2141 if(texture
) IDirect3DTexture9_Release(texture
);
2142 IDirect3D9_Release(d3d
);
2145 static void texture_transform_flags_test(IDirect3DDevice9
*device
)
2149 D3DFORMAT fmt
= D3DFMT_X8R8G8B8
;
2151 IDirect3DTexture9
*texture
= NULL
;
2152 IDirect3DVolumeTexture9
*volume
= NULL
;
2153 unsigned int x
, y
, z
;
2157 IDirect3DVertexDeclaration9
*decl
, *decl2
;
2158 float identity
[16] = {1.0, 0.0, 0.0, 0.0,
2161 0.0, 0.0, 0.0, 1.0};
2162 static const D3DVERTEXELEMENT9 decl_elements
[] = {
2163 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
2164 {0, 12, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
2167 static const D3DVERTEXELEMENT9 decl_elements2
[] = {
2168 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
2169 {0, 12, D3DDECLTYPE_FLOAT1
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
2173 memset(&lr
, 0, sizeof(lr
));
2174 memset(&lb
, 0, sizeof(lb
));
2175 IDirect3DDevice9_GetDirect3D(device
, &d3d
);
2176 if(IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
, 0,
2177 D3DRTYPE_TEXTURE
, D3DFMT_A16B16G16R16
) == D3D_OK
) {
2178 fmt
= D3DFMT_A16B16G16R16
;
2180 IDirect3D9_Release(d3d
);
2182 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &decl
);
2183 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
2184 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements2
, &decl2
);
2185 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
2186 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_SRGBTEXTURE
, FALSE
);
2187 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState(D3DSAMP_SRGBTEXTURE) returned %s\n", DXGetErrorString9(hr
));
2188 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAGFILTER
, D3DTEXF_POINT
);
2189 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState(D3DSAMP_MAGFILTER) returned %s\n", DXGetErrorString9(hr
));
2190 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MINFILTER
, D3DTEXF_POINT
);
2191 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState(D3DSAMP_MINFILTER) returned %s\n", DXGetErrorString9(hr
));
2192 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MIPFILTER
, D3DTEXF_NONE
);
2193 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState(D3DSAMP_MIPFILTER) returned %s\n", DXGetErrorString9(hr
));
2194 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSU
, D3DTADDRESS_CLAMP
);
2195 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState(D3DSAMP_ADDRESSU) returned %s\n", DXGetErrorString9(hr
));
2196 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSV
, D3DTADDRESS_CLAMP
);
2197 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState(D3DSAMP_ADDRESSV) returned %s\n", DXGetErrorString9(hr
));
2198 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSW
, D3DTADDRESS_CLAMP
);
2199 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState(D3DSAMP_ADDRESSW) returned %s\n", DXGetErrorString9(hr
));
2200 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
2201 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState(D3DRS_LIGHTING) returned %s\n", DXGetErrorString9(hr
));
2202 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff0000ff, 0.0, 0);
2203 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %s\n", DXGetErrorString9(hr
));
2205 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
2206 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetDeviceCaps returned %s\n", DXGetErrorString9(hr
));
2207 hr
= IDirect3DDevice9_CreateTexture(device
, caps
.MaxTextureWidth
, caps
.MaxTextureHeight
, 1,
2208 0, fmt
, D3DPOOL_MANAGED
, &texture
, NULL
);
2209 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture returned %s\n", DXGetErrorString9(hr
));
2211 skip("Failed to create the test texture\n");
2215 /* Unfortunately there is no easy way to set up a texture coordinate passthrough
2216 * in d3d fixed function pipeline, so create a texture that has a gradient from 0.0 to
2217 * 1.0 in red and green for the x and y coords
2219 hr
= IDirect3DTexture9_LockRect(texture
, 0, &lr
, NULL
, 0);
2220 ok(hr
== D3D_OK
, "IDirect3DTexture9_LockRect returned %s\n", DXGetErrorString9(hr
));
2221 for(y
= 0; y
< caps
.MaxTextureHeight
; y
++) {
2222 for(x
= 0; x
< caps
.MaxTextureWidth
; x
++) {
2223 double r_f
= (double) y
/ (double) caps
.MaxTextureHeight
;
2224 double g_f
= (double) x
/ (double) caps
.MaxTextureWidth
;
2225 if(fmt
== D3DFMT_A16B16G16R16
) {
2226 unsigned short r
, g
;
2227 unsigned short *dst
= (unsigned short *) (((char *) lr
.pBits
) + y
* lr
.Pitch
+ x
* 8);
2228 r
= (unsigned short) (r_f
* 65536.0);
2229 g
= (unsigned short) (g_f
* 65536.0);
2235 unsigned char *dst
= ((unsigned char *) lr
.pBits
) + y
* lr
.Pitch
+ x
* 4;
2236 unsigned char r
= (unsigned char) (r_f
* 255.0);
2237 unsigned char g
= (unsigned char) (g_f
* 255.0);
2245 hr
= IDirect3DTexture9_UnlockRect(texture
, 0);
2246 ok(hr
== D3D_OK
, "IDirect3DTexture9_UnlockRect returned %s\n", DXGetErrorString9(hr
));
2247 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) texture
);
2248 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture returned %s\n", DXGetErrorString9(hr
));
2250 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
2251 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with %s\n", DXGetErrorString9(hr
));
2252 hr
= IDirect3DDevice9_BeginScene(device
);
2253 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %s\n", DXGetErrorString9(hr
));
2257 -1.0, -1.0, 0.1, 1.0, 1.0,
2258 -1.0, 0.0, 0.1, 1.0, 1.0,
2259 0.0, -1.0, 0.1, 1.0, 1.0,
2260 0.0, 0.0, 0.1, 1.0, 1.0,
2263 -1.0, 0.0, 0.1, 1.0, 1.0,
2264 -1.0, 1.0, 0.1, 1.0, 1.0,
2265 0.0, 0.0, 0.1, 1.0, 1.0,
2266 0.0, 1.0, 0.1, 1.0, 1.0,
2269 0.0, 0.0, 0.1, 0.5, 0.5,
2270 0.0, 1.0, 0.1, 0.5, 0.5,
2271 1.0, 0.0, 0.1, 0.5, 0.5,
2272 1.0, 1.0, 0.1, 0.5, 0.5,
2275 320, 480, 0.1, 1.0, 0.0, 1.0,
2276 320, 240, 0.1, 1.0, 0.0, 1.0,
2277 640, 480, 0.1, 1.0, 0.0, 1.0,
2278 640, 240, 0.1, 1.0, 0.0, 1.0,
2280 float mat
[16] = {0.0, 0.0, 0.0, 0.0,
2283 0.0, 0.0, 0.0, 0.0};
2285 /* What happens with the texture matrix if D3DTSS_TEXTURETRANSFORMFLAGS is disabled? */
2286 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, (D3DMATRIX
*) &mat
);
2287 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %s\n", DXGetErrorString9(hr
));
2288 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, 5 * sizeof(float));
2289 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
2291 /* What happens with transforms enabled? */
2292 IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT2
);
2293 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
2294 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, 5 * sizeof(float));
2295 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
2297 /* What happens if 4 coords are used, but only 2 given ?*/
2300 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, (D3DMATRIX
*) &mat
);
2301 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %s\n", DXGetErrorString9(hr
));
2302 IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT4
);
2303 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
2304 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, 5 * sizeof(float));
2305 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
2307 /* What happens with transformed geometry? This setup lead to 0/0 coords with untransformed
2308 * geometry. If the same applies to transformed vertices, the quad will be black, otherwise red,
2309 * due to the coords in the vertices. (turns out red, indeed)
2311 memset(mat
, 0, sizeof(mat
));
2312 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, (D3DMATRIX
*) &mat
);
2313 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %s\n", DXGetErrorString9(hr
));
2314 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZRHW
| D3DFVF_TEX1
);
2315 IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT2
);
2316 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
2317 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with %s\n", DXGetErrorString9(hr
));
2318 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, 6 * sizeof(float));
2319 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
2321 hr
= IDirect3DDevice9_EndScene(device
);
2322 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %s\n", DXGetErrorString9(hr
));
2324 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
2325 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
2326 color
= getPixelColor(device
, 160, 360);
2327 ok(color
== 0x00FFFF00 || color
== 0x00FEFE00, "quad 1 has color %08x, expected 0x00FFFF00\n", color
);
2328 color
= getPixelColor(device
, 160, 120);
2329 ok(color
== 0x00000000, "quad 2 has color %08x, expected 0x0000000\n", color
);
2330 color
= getPixelColor(device
, 480, 120);
2331 ok(color
== 0x0000FF00 || color
== 0x0000FE00, "quad 3 has color %08x, expected 0x0000FF00\n", color
);
2332 color
= getPixelColor(device
, 480, 360);
2333 ok(color
== 0x00FF0000 || 0x00FE0000, "quad 4 has color %08x, expected 0x00FF0000\n", color
);
2335 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff0000ff, 0.0, 0);
2336 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %s\n", DXGetErrorString9(hr
));
2338 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
2339 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with %s\n", DXGetErrorString9(hr
));
2340 hr
= IDirect3DDevice9_BeginScene(device
);
2341 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %s\n", DXGetErrorString9(hr
));
2345 -1.0, -1.0, 0.1, 0.8, 0.2,
2346 -1.0, 0.0, 0.1, 0.8, 0.2,
2347 0.0, -1.0, 0.1, 0.8, 0.2,
2348 0.0, 0.0, 0.1, 0.8, 0.2,
2351 -1.0, 0.0, 0.1, 0.5, 1.0,
2352 -1.0, 1.0, 0.1, 0.5, 1.0,
2353 0.0, 0.0, 0.1, 0.5, 1.0,
2354 0.0, 1.0, 0.1, 0.5, 1.0,
2357 0.0, 0.0, 0.1, 0.5, 1.0,
2358 0.0, 1.0, 0.1, 0.5, 1.0,
2359 1.0, 0.0, 0.1, 0.5, 1.0,
2360 1.0, 1.0, 0.1, 0.5, 1.0,
2363 0.0, -1.0, 0.1, 0.8, 0.2,
2364 0.0, 0.0, 0.1, 0.8, 0.2,
2365 1.0, -1.0, 0.1, 0.8, 0.2,
2366 1.0, 0.0, 0.1, 0.8, 0.2,
2368 float mat
[16] = {0.0, 0.0, 0.0, 0.0,
2371 0.0, 0.0, 0.0, 0.0};
2373 /* What happens to the default 1 in the 3rd coordinate if it is disabled?
2375 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, (D3DMATRIX
*) &mat
);
2376 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %s\n", DXGetErrorString9(hr
));
2377 IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT2
);
2378 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
2380 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, 5 * sizeof(float));
2381 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
2383 /* D3DTFF_COUNT1 does not work on Nvidia drivers. It behaves like D3DTTFF_DISABLE. On ATI drivers
2384 * it behaves like COUNT2 because normal textures require 2 coords
2386 IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT1
);
2387 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
2388 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, 5 * sizeof(float));
2389 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
2391 /* Just to be sure, the same as quad2 above */
2392 memset(mat
, 0, sizeof(mat
));
2393 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, (D3DMATRIX
*) &mat
);
2394 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %s\n", DXGetErrorString9(hr
));
2395 IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT2
);
2396 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
2397 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, 5 * sizeof(float));
2398 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
2400 /* Now, what happens to the 2nd coordinate(that is disabled in the matrix) if it is not
2401 * used? And what happens to the first?
2403 IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT1
);
2404 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
2405 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, 5 * sizeof(float));
2406 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (%08x)\n", hr
);
2408 hr
= IDirect3DDevice9_EndScene(device
);
2409 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %s\n", DXGetErrorString9(hr
));
2411 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
2412 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
2413 color
= getPixelColor(device
, 160, 360);
2414 ok(color
== 0x00FF0000 || color
== 0x00FE0000, "quad 1 has color %08x, expected 0x00FF0000\n", color
);
2415 color
= getPixelColor(device
, 160, 120);
2416 ok(color
== 0x00000000, "quad 2 has color %08x, expected 0x0000000\n", color
);
2417 color
= getPixelColor(device
, 480, 120);
2418 ok(color
== 0x00ff8000 || color
== 0x00fe7f00 || color
== 0x00000000,
2419 "quad 3 has color %08x, expected 0x00ff8000\n", color
);
2420 color
= getPixelColor(device
, 480, 360);
2421 ok(color
== 0x0033cc00 || color
== 0x0032cb00 || color
== 0x00FF0000 || color
== 0x00FE0000,
2422 "quad 4 has color %08x, expected 0x0033cc00\n", color
);
2424 IDirect3DTexture9_Release(texture
);
2426 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff203040, 0.0, 0);
2427 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %s\n", DXGetErrorString9(hr
));
2428 /* Use a smaller volume texture than the biggest possible size for memory and performance reasons
2429 * Thus watch out if sampling from texels between 0 and 1.
2431 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 32, 32, 32, 1, 0, fmt
, D3DPOOL_MANAGED
, &volume
, 0);
2432 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
,
2433 "IDirect3DDevice9_CreateVolumeTexture failed with %s\n", DXGetErrorString9(hr
));
2435 skip("Failed to create a volume texture\n");
2439 hr
= IDirect3DVolumeTexture9_LockBox(volume
, 0, &lb
, NULL
, 0);
2440 ok(hr
== D3D_OK
, "IDirect3DVolumeTexture9_LockBox failed with %s\n", DXGetErrorString9(hr
));
2441 for(z
= 0; z
< 32; z
++) {
2442 for(y
= 0; y
< 32; y
++) {
2443 for(x
= 0; x
< 32; x
++) {
2444 char size
= (fmt
== D3DFMT_A16B16G16R16
? 8 : 4);
2445 void *mem
= ((char *) lb
.pBits
) + y
* lb
.RowPitch
+ z
* lb
.SlicePitch
+ x
* size
;
2446 float r_f
= (float) x
/ 31.0;
2447 float g_f
= (float) y
/ 31.0;
2448 float b_f
= (float) z
/ 31.0;
2450 if(fmt
== D3DFMT_A16B16G16R16
) {
2451 unsigned short *mem_s
= mem
;
2452 mem_s
[0] = r_f
* 65535.0;
2453 mem_s
[1] = g_f
* 65535.0;
2454 mem_s
[2] = b_f
* 65535.0;
2457 unsigned char *mem_c
= mem
;
2458 mem_c
[0] = b_f
* 255.0;
2459 mem_c
[1] = g_f
* 255.0;
2460 mem_c
[2] = r_f
* 255.0;
2466 hr
= IDirect3DVolumeTexture9_UnlockBox(volume
, 0);
2467 ok(hr
== D3D_OK
, "IDirect3DVolumeTexture9_UnlockBox failed with %s\n", DXGetErrorString9(hr
));
2469 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) volume
);
2470 ok(hr
== D3D_OK
, "IDirect3DVolumeTexture9_UnlockBox failed with %s\n", DXGetErrorString9(hr
));
2472 hr
= IDirect3DDevice9_BeginScene(device
);
2473 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %s\n", DXGetErrorString9(hr
));
2477 -1.0, -1.0, 0.1, 1.0, 1.0, 1.0,
2478 -1.0, 0.0, 0.1, 1.0, 1.0, 1.0,
2479 0.0, -1.0, 0.1, 1.0, 1.0, 1.0,
2480 0.0, 0.0, 0.1, 1.0, 1.0, 1.0
2483 -1.0, 0.0, 0.1, 1.0, 1.0, 1.0,
2484 -1.0, 1.0, 0.1, 1.0, 1.0, 1.0,
2485 0.0, 0.0, 0.1, 1.0, 1.0, 1.0,
2486 0.0, 1.0, 0.1, 1.0, 1.0, 1.0
2489 0.0, 0.0, 0.1, 0.0, 0.0,
2490 0.0, 1.0, 0.1, 0.0, 0.0,
2491 1.0, 0.0, 0.1, 0.0, 0.0,
2492 1.0, 1.0, 0.1, 0.0, 0.0
2495 0.0, -1.0, 0.1, 1.0, 1.0, 1.0,
2496 0.0, 0.0, 0.1, 1.0, 1.0, 1.0,
2497 1.0, -1.0, 0.1, 1.0, 1.0, 1.0,
2498 1.0, 0.0, 0.1, 1.0, 1.0, 1.0
2500 float mat
[16] = {1.0, 0.0, 0.0, 0.0,
2503 0.0, 0.0, 0.0, 1.0};
2504 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl
);
2505 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed with %s\n", DXGetErrorString9(hr
));
2507 /* Draw a quad with all 3 coords enabled. Nothing fancy. v and w are swapped, but have the same
2510 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, (D3DMATRIX
*) mat
);
2511 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %s\n", DXGetErrorString9(hr
));
2512 IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT3
);
2513 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
2514 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, 6 * sizeof(float));
2515 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
2517 /* Now disable the w coordinate. Does that change the input, or the output. The coordinates
2518 * are swapped by the matrix. If it changes the input, the v coord will be missing(green),
2519 * otherwise the w will be missing(blue).
2520 * turns out that on nvidia cards the blue color is missing, so it is an output modification.
2521 * On ATI cards the COUNT2 is ignored, and it behaves in the same way as COUNT3.
2523 IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT2
);
2524 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
2525 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, 6 * sizeof(float));
2526 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
2528 /* default values? Set up the identity matrix, pass in 2 vertex coords, and enable 4 */
2529 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, (D3DMATRIX
*) identity
);
2530 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %s\n", DXGetErrorString9(hr
));
2531 IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT4
);
2532 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
2533 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
2534 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with %s\n", DXGetErrorString9(hr
));
2535 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, 5 * sizeof(float));
2536 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
2538 /* D3DTTFF_COUNT1. Set a NULL matrix, and count1, pass in all values as 1.0. Nvidia has count1 ==
2539 * disable. ATI extends it up to the amount of values needed for the volume texture
2541 memset(mat
, 0, sizeof(mat
));
2542 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, (D3DMATRIX
*) mat
);
2543 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %s\n", DXGetErrorString9(hr
));
2544 IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT1
);
2545 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
2546 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl
);
2547 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed with %s\n", DXGetErrorString9(hr
));
2548 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, 6 * sizeof(float));
2549 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
2551 hr
= IDirect3DDevice9_EndScene(device
);
2552 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %s\n", DXGetErrorString9(hr
));
2554 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
2555 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
2557 color
= getPixelColor(device
, 160, 360);
2558 ok(color
== 0x00ffffff, "quad 1 has color %08x, expected 0x00ffffff\n", color
);
2559 color
= getPixelColor(device
, 160, 120);
2560 ok(color
== 0x00ffff00 /* NV*/ || color
== 0x00ffffff /* ATI */,
2561 "quad 2 has color %08x, expected 0x00ffff00\n", color
);
2562 color
= getPixelColor(device
, 480, 120);
2563 ok(color
== 0x000000ff, "quad 3 has color %08x, expected 0x000000ff\n", color
);
2564 color
= getPixelColor(device
, 480, 360);
2565 ok(color
== 0x00ffffff || color
== 0x0000ff00, "quad 4 has color %08x, expected 0x00ffffff\n", color
);
2567 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff303030, 0.0, 0);
2568 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %s\n", DXGetErrorString9(hr
));
2569 hr
= IDirect3DDevice9_BeginScene(device
);
2570 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %s\n", DXGetErrorString9(hr
));
2574 -1.0, -1.0, 0.1, 1.0, 1.0, 1.0,
2575 -1.0, 0.0, 0.1, 1.0, 1.0, 1.0,
2576 0.0, -1.0, 0.1, 1.0, 1.0, 1.0,
2577 0.0, 0.0, 0.1, 1.0, 1.0, 1.0
2591 float mat
[16] = {0.0, 0.0, 0.0, 0.0,
2594 0.0, 1.0, 0.0, 0.0};
2595 float mat2
[16] = {0.0, 0.0, 0.0, 1.0,
2598 0.0, 0.0, 1.0, 0.0};
2599 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl
);
2600 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed with %s\n", DXGetErrorString9(hr
));
2602 /* Default values? 4 coords used, 3 passed. What happens to the 4th?
2604 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, (D3DMATRIX
*) mat
);
2605 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %s\n", DXGetErrorString9(hr
));
2606 IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT4
);
2607 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
2608 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, 6 * sizeof(float));
2609 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
2612 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, (D3DMATRIX
*) identity
);
2613 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %s\n", DXGetErrorString9(hr
));
2614 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
2615 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with %s\n", DXGetErrorString9(hr
));
2616 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, 3 * sizeof(float));
2617 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
2619 /* 4 used, 1 passed */
2620 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl2
);
2621 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed with %s\n", DXGetErrorString9(hr
));
2622 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, (D3DMATRIX
*) mat2
);
2623 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %s\n", DXGetErrorString9(hr
));
2624 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, 4 * sizeof(float));
2625 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
2627 hr
= IDirect3DDevice9_EndScene(device
);
2628 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %s\n", DXGetErrorString9(hr
));
2630 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
2631 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
2632 color
= getPixelColor(device
, 160, 360);
2633 ok(color
== 0x0000ff00, "quad 1 has color %08x, expected 0x0000ff00\n", color
);
2634 color
= getPixelColor(device
, 160, 120);
2635 ok(color
== 0x00000000, "quad 2 has color %08x, expected 0x00000000\n", color
);
2636 color
= getPixelColor(device
, 480, 120);
2637 ok(color
== 0x00ff0000, "quad 3 has color %08x, expected 0x00ff0000\n", color
);
2640 IDirect3DVolumeTexture9_Release(volume
);
2643 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
2644 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed with %s\n", DXGetErrorString9(hr
));
2645 IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_DISABLE
);
2646 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetTextureStageState failed (%08x)\n", hr
);
2647 hr
= IDirect3DDevice9_SetTransform(device
, D3DTS_TEXTURE0
, (D3DMATRIX
*) &identity
);
2648 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTransform failed with %s\n", DXGetErrorString9(hr
));
2649 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
2650 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture returned %s\n", DXGetErrorString9(hr
));
2651 IDirect3DVertexDeclaration9_Release(decl
);
2652 IDirect3DVertexDeclaration9_Release(decl2
);
2655 static void texdepth_test(IDirect3DDevice9
*device
)
2657 IDirect3DPixelShader9
*shader
;
2659 const float texdepth_test_data1
[] = { 0.25, 2.0, 0.0, 0.0};
2660 const float texdepth_test_data2
[] = { 0.25, 0.5, 0.0, 0.0};
2661 const float texdepth_test_data3
[] = {-1.00, 0.1, 0.0, 0.0};
2662 const float texdepth_test_data4
[] = {-0.25, -0.5, 0.0, 0.0};
2663 const float texdepth_test_data5
[] = { 1.00, -0.1, 0.0, 0.0};
2664 const float texdepth_test_data6
[] = { 1.00, 0.5, 0.0, 0.0};
2665 const float texdepth_test_data7
[] = { 0.50, 0.0, 0.0, 0.0};
2666 DWORD shader_code
[] = {
2667 0xffff0104, /* ps_1_4 */
2668 0x00000051, 0xa00f0001, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, /* def c1, 0, 0, 1, 1 */
2669 0x00000001, 0x800f0005, 0xa0e40000, /* mov r5, c0 */
2670 0x0000fffd, /* phase */
2671 0x00000057, 0x800f0005, /* texdepth r5 */
2672 0x00000001, 0x800f0000, 0xa0e40001, /* mov r0, c1 */
2673 0x0000ffff /* end */
2683 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code
, &shader
);
2684 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %s\n", DXGetErrorString9(hr
));
2686 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffff00, 0.0, 0);
2687 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %s\n", DXGetErrorString9(hr
));
2688 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_TRUE
);
2689 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
2690 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, TRUE
);
2691 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
2692 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_ALWAYS
);
2693 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
2694 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
2696 /* Fill the depth buffer with a gradient */
2697 hr
= IDirect3DDevice9_BeginScene(device
);
2698 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
2701 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, vertex
, 3 * sizeof(float));
2702 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
2703 hr
= IDirect3DDevice9_EndScene(device
);
2704 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
2707 /* Now perform the actual tests. Same geometry, but with the shader */
2708 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZFUNC
, D3DCMP_GREATER
);
2709 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
2710 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, FALSE
);
2711 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
2712 hr
= IDirect3DDevice9_SetPixelShader(device
, shader
);
2713 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader failed (%08x)\n", hr
);
2715 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 0, texdepth_test_data1
, 1);
2716 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %s\n", DXGetErrorString9(hr
));
2717 hr
= IDirect3DDevice9_BeginScene(device
);
2718 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
2721 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, vertex
, 3 * sizeof(float));
2722 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
2724 hr
= IDirect3DDevice9_EndScene(device
);
2725 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
2728 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
2729 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
2730 color
= getPixelColor(device
, 158, 240);
2731 ok(color
== 0x000000ff, "Pixel 158(25%% - 2 pixel) has color %08x, expected 0x000000ff\n", color
);
2732 color
= getPixelColor(device
, 162, 240);
2733 ok(color
== 0x00ffffff, "Pixel 158(25%% + 2 pixel) has color %08x, expected 0x00ffffff\n", color
);
2735 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffff00, 0.0, 0);
2737 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 0, texdepth_test_data2
, 1);
2738 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %s\n", DXGetErrorString9(hr
));
2739 hr
= IDirect3DDevice9_BeginScene(device
);
2740 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
2743 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, vertex
, 3 * sizeof(float));
2744 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
2746 hr
= IDirect3DDevice9_EndScene(device
);
2747 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
2750 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
2751 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
2752 color
= getPixelColor(device
, 318, 240);
2753 ok(color
== 0x000000ff, "Pixel 318(50%% - 2 pixel) has color %08x, expected 0x000000ff\n", color
);
2754 color
= getPixelColor(device
, 322, 240);
2755 ok(color
== 0x00ffff00, "Pixel 322(50%% + 2 pixel) has color %08x, expected 0x00ffff00\n", color
);
2757 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
2759 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 0, texdepth_test_data3
, 1);
2760 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %s\n", DXGetErrorString9(hr
));
2761 hr
= IDirect3DDevice9_BeginScene(device
);
2762 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
2765 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, vertex
, 3 * sizeof(float));
2766 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
2768 hr
= IDirect3DDevice9_EndScene(device
);
2769 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
2771 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
2772 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
2774 color
= getPixelColor(device
, 1, 240);
2775 ok(color
== 0x00ff0000, "Pixel 1(0%% + 2 pixel) has color %08x, expected 0x00ff0000\n", color
);
2777 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0, 0);
2779 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 0, texdepth_test_data4
, 1);
2780 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %s\n", DXGetErrorString9(hr
));
2781 hr
= IDirect3DDevice9_BeginScene(device
);
2782 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
2785 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, vertex
, 3 * sizeof(float));
2786 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
2788 hr
= IDirect3DDevice9_EndScene(device
);
2789 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
2791 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
2792 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
2793 color
= getPixelColor(device
, 318, 240);
2794 ok(color
== 0x000000ff, "Pixel 318(50%% - 2 pixel) has color %08x, expected 0x000000ff\n", color
);
2795 color
= getPixelColor(device
, 322, 240);
2796 ok(color
== 0x0000ff00, "Pixel 322(50%% + 2 pixel) has color %08x, expected 0x0000ff00\n", color
);
2798 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffff00, 0.0, 0);
2800 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 0, texdepth_test_data5
, 1);
2801 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %s\n", DXGetErrorString9(hr
));
2802 hr
= IDirect3DDevice9_BeginScene(device
);
2803 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
2806 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, vertex
, 3 * sizeof(float));
2807 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
2809 hr
= IDirect3DDevice9_EndScene(device
);
2810 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
2812 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
2813 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
2815 color
= getPixelColor(device
, 1, 240);
2816 ok(color
== 0x00ffff00, "Pixel 1(0%% + 2 pixel) has color %08x, expected 0x00ffff00\n", color
);
2818 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0, 0);
2820 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 0, texdepth_test_data6
, 1);
2821 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %s\n", DXGetErrorString9(hr
));
2822 hr
= IDirect3DDevice9_BeginScene(device
);
2823 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
2826 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, vertex
, 3 * sizeof(float));
2827 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
2829 hr
= IDirect3DDevice9_EndScene(device
);
2830 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
2832 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
2833 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
2835 color
= getPixelColor(device
, 638, 240);
2836 ok(color
== 0x000000ff, "Pixel 638(100%% + 2 pixel) has color %08x, expected 0x000000ff\n", color
);
2838 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
2840 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 0, texdepth_test_data7
, 1);
2841 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %s\n", DXGetErrorString9(hr
));
2842 hr
= IDirect3DDevice9_BeginScene(device
);
2843 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
2846 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, vertex
, 3 * sizeof(float));
2847 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
2849 hr
= IDirect3DDevice9_EndScene(device
);
2850 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
2852 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
2853 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
2855 color
= getPixelColor(device
, 638, 240);
2856 ok(color
== 0x000000ff, "Pixel 638(100%% + 2 pixel) has color %08x, expected 0x000000ff\n", color
);
2859 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
2860 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader failed (%08x)\n", hr
);
2861 IDirect3DPixelShader9_Release(shader
);
2863 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZENABLE
, D3DZB_FALSE
);
2864 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
2865 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ZWRITEENABLE
, TRUE
);
2866 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
2869 static void texkill_test(IDirect3DDevice9
*device
)
2871 IDirect3DPixelShader9
*shader
;
2875 const float vertex
[] = {
2876 /* bottom top right left */
2877 -1.0, -1.0, 1.0, -0.1, 0.9, 0.9, -0.1,
2878 1.0, -1.0, 0.0, 0.9, -0.1, 0.9, -0.1,
2879 -1.0, 1.0, 1.0, -0.1, 0.9, -0.1, 0.9,
2880 1.0, 1.0, 0.0, 0.9, -0.1, -0.1, 0.9,
2883 DWORD shader_code_11
[] = {
2884 0xffff0101, /* ps_1_1 */
2885 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 1.0, 0.0, 0.0, 1.0 */
2886 0x00000041, 0xb00f0000, /* texkill t0 */
2887 0x00000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
2888 0x0000ffff /* end */
2890 DWORD shader_code_20
[] = {
2891 0xffff0200, /* ps_2_0 */
2892 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
2893 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, /* def c0, 0.0, 0.0, 1.0, 1.0 */
2894 0x01000041, 0xb00f0000, /* texkill t0 */
2895 0x02000001, 0x800f0800, 0xa0e40000, /* mov oC0, c0 */
2896 0x0000ffff /* end */
2899 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0, 0);
2900 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %s\n", DXGetErrorString9(hr
));
2901 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_11
, &shader
);
2902 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %s\n", DXGetErrorString9(hr
));
2904 hr
= IDirect3DDevice9_SetPixelShader(device
, shader
);
2905 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
2906 hr
= IDirect3DDevice9_BeginScene(device
);
2907 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
2910 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEXCOORDSIZE4(0) | D3DFVF_TEX1
);
2911 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF returned %s\n", DXGetErrorString9(hr
));
2912 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, vertex
, 7 * sizeof(float));
2913 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
2914 hr
= IDirect3DDevice9_EndScene(device
);
2915 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
2917 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
2918 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
2919 color
= getPixelColor(device
, 63, 46);
2920 ok(color
== 0x0000ff00, "Pixel 63/46 has color %08x, expected 0x0000ff00\n", color
);
2921 color
= getPixelColor(device
, 66, 46);
2922 ok(color
== 0x0000ff00, "Pixel 66/64 has color %08x, expected 0x0000ff00\n", color
);
2923 color
= getPixelColor(device
, 63, 49);
2924 ok(color
== 0x0000ff00, "Pixel 63/49 has color %08x, expected 0x0000ff00\n", color
);
2925 color
= getPixelColor(device
, 66, 49);
2926 ok(color
== 0x00ff0000, "Pixel 66/49 has color %08x, expected 0x00ff0000\n", color
);
2928 color
= getPixelColor(device
, 578, 46);
2929 ok(color
== 0x0000ff00, "Pixel 578/46 has color %08x, expected 0x0000ff00\n", color
);
2930 color
= getPixelColor(device
, 575, 46);
2931 ok(color
== 0x0000ff00, "Pixel 575/64 has color %08x, expected 0x0000ff00\n", color
);
2932 color
= getPixelColor(device
, 578, 49);
2933 ok(color
== 0x0000ff00, "Pixel 578/49 has color %08x, expected 0x0000ff00\n", color
);
2934 color
= getPixelColor(device
, 575, 49);
2935 ok(color
== 0x00ff0000, "Pixel 575/49 has color %08x, expected 0x00ff0000\n", color
);
2937 color
= getPixelColor(device
, 63, 430);
2938 ok(color
== 0x0000ff00, "Pixel 578/46 has color %08x, expected 0x0000ff00\n", color
);
2939 color
= getPixelColor(device
, 63, 433);
2940 ok(color
== 0x0000ff00, "Pixel 575/64 has color %08x, expected 0x0000ff00\n", color
);
2941 color
= getPixelColor(device
, 66, 433);
2942 ok(color
== 0x00ff0000, "Pixel 578/49 has color %08x, expected 0x00ff0000\n", color
);
2943 color
= getPixelColor(device
, 66, 430);
2944 ok(color
== 0x00ff0000, "Pixel 575/49 has color %08x, expected 0x00ff0000\n", color
);
2946 color
= getPixelColor(device
, 578, 430);
2947 ok(color
== 0x0000ff00, "Pixel 578/46 has color %08x, expected 0x0000ff00\n", color
);
2948 color
= getPixelColor(device
, 578, 433);
2949 ok(color
== 0x0000ff00, "Pixel 575/64 has color %08x, expected 0x0000ff00\n", color
);
2950 color
= getPixelColor(device
, 575, 433);
2951 ok(color
== 0x00ff0000, "Pixel 578/49 has color %08x, expected 0x00ff0000\n", color
);
2952 color
= getPixelColor(device
, 575, 430);
2953 ok(color
== 0x00ff0000, "Pixel 575/49 has color %08x, expected 0x00ff0000\n", color
);
2955 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
2956 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
2957 IDirect3DPixelShader9_Release(shader
);
2959 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffff00, 0.0, 0);
2960 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %s\n", DXGetErrorString9(hr
));
2961 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_20
, &shader
);
2963 skip("Failed to create 2.0 test shader, most likely not supported\n");
2967 hr
= IDirect3DDevice9_SetPixelShader(device
, shader
);
2968 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
2969 hr
= IDirect3DDevice9_BeginScene(device
);
2970 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
2973 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, vertex
, 7 * sizeof(float));
2974 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
2975 hr
= IDirect3DDevice9_EndScene(device
);
2976 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
2978 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
2980 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
2981 color
= getPixelColor(device
, 63, 46);
2982 ok(color
== 0x00ffff00, "Pixel 63/46 has color %08x, expected 0x00ffff00\n", color
);
2983 color
= getPixelColor(device
, 66, 46);
2984 ok(color
== 0x00ffff00, "Pixel 66/64 has color %08x, expected 0x00ffff00\n", color
);
2985 color
= getPixelColor(device
, 63, 49);
2986 ok(color
== 0x00ffff00, "Pixel 63/49 has color %08x, expected 0x00ffff00\n", color
);
2987 color
= getPixelColor(device
, 66, 49);
2988 ok(color
== 0x000000ff, "Pixel 66/49 has color %08x, expected 0x000000ff\n", color
);
2990 color
= getPixelColor(device
, 578, 46);
2991 ok(color
== 0x00ffff00, "Pixel 578/46 has color %08x, expected 0x00ffff00\n", color
);
2992 color
= getPixelColor(device
, 575, 46);
2993 ok(color
== 0x00ffff00, "Pixel 575/64 has color %08x, expected 0x00ffff00\n", color
);
2994 color
= getPixelColor(device
, 578, 49);
2995 ok(color
== 0x00ffff00, "Pixel 578/49 has color %08x, expected 0x00ffff00\n", color
);
2996 color
= getPixelColor(device
, 575, 49);
2997 ok(color
== 0x000000ff, "Pixel 575/49 has color %08x, expected 0x000000ff\n", color
);
2999 color
= getPixelColor(device
, 63, 430);
3000 ok(color
== 0x00ffff00, "Pixel 578/46 has color %08x, expected 0x00ffff00\n", color
);
3001 color
= getPixelColor(device
, 63, 433);
3002 ok(color
== 0x00ffff00, "Pixel 575/64 has color %08x, expected 0x00ffff00\n", color
);
3003 color
= getPixelColor(device
, 66, 433);
3004 ok(color
== 0x00ffff00, "Pixel 578/49 has color %08x, expected 0x00ffff00\n", color
);
3005 color
= getPixelColor(device
, 66, 430);
3006 ok(color
== 0x000000ff, "Pixel 575/49 has color %08x, expected 0x000000ff\n", color
);
3008 color
= getPixelColor(device
, 578, 430);
3009 ok(color
== 0x00ffff00, "Pixel 578/46 has color %08x, expected 0x00ffff00\n", color
);
3010 color
= getPixelColor(device
, 578, 433);
3011 ok(color
== 0x00ffff00, "Pixel 575/64 has color %08x, expected 0x00ffff00\n", color
);
3012 color
= getPixelColor(device
, 575, 433);
3013 ok(color
== 0x00ffff00, "Pixel 578/49 has color %08x, expected 0x00ffff00\n", color
);
3014 color
= getPixelColor(device
, 575, 430);
3015 ok(color
== 0x000000ff, "Pixel 575/49 has color %08x, expected 0x000000ff\n", color
);
3018 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
3019 ok(SUCCEEDED(hr
), "SetPixelShader failed (%08x)\n", hr
);
3020 IDirect3DPixelShader9_Release(shader
);
3023 static void x8l8v8u8_test(IDirect3DDevice9
*device
)
3027 IDirect3DTexture9
*texture
;
3028 IDirect3DPixelShader9
*shader
;
3029 IDirect3DPixelShader9
*shader2
;
3032 DWORD shader_code
[] = {
3033 0xffff0101, /* ps_1_1 */
3034 0x00000042, 0xb00f0000, /* tex t0 */
3035 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
3036 0x0000ffff /* end */
3038 DWORD shader_code2
[] = {
3039 0xffff0101, /* ps_1_1 */
3040 0x00000042, 0xb00f0000, /* tex t0 */
3041 0x00000001, 0x800f0000, 0xb0ff0000, /* mov r0, t0.w */
3042 0x0000ffff /* end */
3046 -1.0, -1.0, 0.1, 0.5, 0.5,
3047 1.0, -1.0, 0.1, 0.5, 0.5,
3048 -1.0, 1.0, 0.1, 0.5, 0.5,
3049 1.0, 1.0, 0.1, 0.5, 0.5,
3052 memset(&lr
, 0, sizeof(lr
));
3053 IDirect3DDevice9_GetDirect3D(device
, &d3d9
);
3054 hr
= IDirect3D9_CheckDeviceFormat(d3d9
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
3055 0, D3DRTYPE_TEXTURE
, D3DFMT_X8L8V8U8
);
3056 IDirect3D9_Release(d3d9
);
3058 skip("No D3DFMT_X8L8V8U8 support\n");
3061 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
3062 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %s\n", DXGetErrorString9(hr
));
3064 hr
= IDirect3DDevice9_CreateTexture(device
, 1, 1, 1, 0, D3DFMT_X8L8V8U8
, D3DPOOL_MANAGED
, &texture
, NULL
);
3065 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture failed (%08x)\n", hr
);
3066 hr
= IDirect3DTexture9_LockRect(texture
, 0, &lr
, NULL
, 0);
3067 ok(hr
== D3D_OK
, "IDirect3DTexture9_LockRect failed (%08x)\n", hr
);
3068 *((DWORD
*) lr
.pBits
) = 0x11ca3141;
3069 hr
= IDirect3DTexture9_UnlockRect(texture
, 0);
3070 ok(hr
== D3D_OK
, "IDirect3DTexture9_UnlockRect failed (%08x)\n", hr
);
3072 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code
, &shader
);
3073 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateShader failed (%08x)\n", hr
);
3074 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code2
, &shader2
);
3075 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateShader failed (%08x)\n", hr
);
3077 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
3078 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed (%08x)\n", hr
);
3079 hr
= IDirect3DDevice9_SetPixelShader(device
, shader
);
3080 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader failed (%08x)\n", hr
);
3081 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) texture
);
3082 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture failed (%08x)\n", hr
);
3084 hr
= IDirect3DDevice9_BeginScene(device
);
3085 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed (%08x)\n", hr
);
3088 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
3089 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
3091 hr
= IDirect3DDevice9_EndScene(device
);
3092 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed (%08x)\n", hr
);
3094 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
3095 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
3096 color
= getPixelColor(device
, 578, 430);
3097 ok(color
== 0x008262ca || color
== 0x008363ca || color
== 0x008362ca,
3098 "D3DFMT_X8L8V8U8 = 0x112131ca returns color %08x, expected 0x008262ca\n", color
);
3100 hr
= IDirect3DDevice9_SetPixelShader(device
, shader2
);
3101 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader failed (%08x)\n", hr
);
3102 hr
= IDirect3DDevice9_BeginScene(device
);
3103 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed (%08x)\n", hr
);
3106 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
3107 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
3109 hr
= IDirect3DDevice9_EndScene(device
);
3110 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed (%08x)\n", hr
);
3112 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
3113 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
3114 color
= getPixelColor(device
, 578, 430);
3115 ok(color
== 0x00ffffff, "w component of D3DFMT_X8L8V8U8 = 0x11ca3141 returns color %08x\n", color
);
3117 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
3118 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader failed (%08x)\n", hr
);
3119 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
3120 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture failed (%08x)\n", hr
);
3121 IDirect3DPixelShader9_Release(shader
);
3122 IDirect3DPixelShader9_Release(shader2
);
3123 IDirect3DTexture9_Release(texture
);
3126 static void autogen_mipmap_test(IDirect3DDevice9
*device
)
3130 IDirect3DTexture9
*texture
= NULL
;
3131 IDirect3DSurface9
*surface
;
3133 const RECT r1
= {256, 256, 512, 512};
3134 const RECT r2
= {512, 256, 768, 512};
3135 const RECT r3
= {256, 512, 512, 768};
3136 const RECT r4
= {512, 512, 768, 768};
3139 memset(&lr
, 0, sizeof(lr
));
3141 IDirect3DDevice9_GetDirect3D(device
, &d3d
);
3142 if(IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
3143 D3DUSAGE_AUTOGENMIPMAP
, D3DRTYPE_TEXTURE
, D3DFMT_X8R8G8B8
) != D3D_OK
) {
3144 skip("No autogenmipmap support\n");
3145 IDirect3D9_Release(d3d
);
3148 IDirect3D9_Release(d3d
);
3150 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffff00, 0.0, 0);
3151 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %s\n", DXGetErrorString9(hr
));
3153 /* Make the mipmap big, so that a smaller mipmap is used
3155 hr
= IDirect3DDevice9_CreateTexture(device
, 1024, 1024, 0, D3DUSAGE_AUTOGENMIPMAP
,
3156 D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &texture
, 0);
3157 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture returned %s\n", DXGetErrorString9(hr
));
3159 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
3160 ok(hr
== D3D_OK
, "IDirect3DTexture9_GetSurfaceLevel returned %s\n", DXGetErrorString9(hr
));
3161 hr
= IDirect3DSurface9_LockRect(surface
, &lr
, NULL
, 0);
3162 ok(hr
== D3D_OK
, "IDirect3DSurface9_LockRect returned %s\n", DXGetErrorString9(hr
));
3163 for(y
= 0; y
< 1024; y
++) {
3164 for(x
= 0; x
< 1024; x
++) {
3165 DWORD
*dst
= (DWORD
*) (((BYTE
*) lr
.pBits
) + y
* lr
.Pitch
+ x
* 4);
3170 if(PtInRect(&r1
, pt
)) {
3172 } else if(PtInRect(&r2
, pt
)) {
3174 } else if(PtInRect(&r3
, pt
)) {
3176 } else if(PtInRect(&r4
, pt
)) {
3183 hr
= IDirect3DSurface9_UnlockRect(surface
);
3184 ok(hr
== D3D_OK
, "IDirect3DSurface9_UnlockRect returned %s\n", DXGetErrorString9(hr
));
3185 IDirect3DSurface9_Release(surface
);
3187 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) texture
);
3188 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture returned %s\n", DXGetErrorString9(hr
));
3189 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MIPFILTER
, D3DTEXF_POINT
);
3190 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState failed with %s\n", DXGetErrorString9(hr
));
3192 hr
= IDirect3DDevice9_BeginScene(device
);
3193 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
3195 const float quad
[] = {
3196 -0.5, -0.5, 0.1, 0.0, 0.0,
3197 -0.5, 0.5, 0.1, 0.0, 1.0,
3198 0.5, -0.5, 0.1, 1.0, 0.0,
3199 0.5, 0.5, 0.1, 1.0, 1.0
3202 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
3203 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF returned %s\n", DXGetErrorString9(hr
));
3204 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 5 * sizeof(float));
3205 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
3206 hr
= IDirect3DDevice9_EndScene(device
);
3207 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
3209 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
3210 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture returned %s\n", DXGetErrorString9(hr
));
3211 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MIPFILTER
, D3DTEXF_NONE
);
3212 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState failed with %s\n", DXGetErrorString9(hr
));
3213 IDirect3DTexture9_Release(texture
);
3215 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
3216 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
3217 color
= getPixelColor(device
, 200, 200);
3218 ok(color
== 0x00ffffff, "pixel 200/200 has color %08x, expected 0x00ffffff\n", color
);
3219 color
= getPixelColor(device
, 280, 200);
3220 ok(color
== 0x000000ff, "pixel 280/200 has color %08x, expected 0x000000ff\n", color
);
3221 color
= getPixelColor(device
, 360, 200);
3222 ok(color
== 0x00000000, "pixel 360/200 has color %08x, expected 0x00000000\n", color
);
3223 color
= getPixelColor(device
, 440, 200);
3224 ok(color
== 0x00ffffff, "pixel 440/200 has color %08x, expected 0x00ffffff\n", color
);
3225 color
= getPixelColor(device
, 200, 270);
3226 ok(color
== 0x00ffffff, "pixel 200/270 has color %08x, expected 0x00ffffff\n", color
);
3227 color
= getPixelColor(device
, 280, 270);
3228 ok(color
== 0x00ff0000, "pixel 280/270 has color %08x, expected 0x00ff0000\n", color
);
3229 color
= getPixelColor(device
, 360, 270);
3230 ok(color
== 0x0000ff00, "pixel 360/270 has color %08x, expected 0x0000ff00\n", color
);
3231 color
= getPixelColor(device
, 440, 270);
3232 ok(color
== 0x00ffffff, "pixel 440/200 has color %08x, expected 0x00ffffff\n", color
);
3235 static void test_constant_clamp_vs(IDirect3DDevice9
*device
)
3237 IDirect3DVertexShader9
*shader_11
, *shader_11_2
, *shader_20
, *shader_20_2
;
3238 IDirect3DVertexDeclaration9
*decl
;
3241 DWORD shader_code_11
[] = {
3242 0xfffe0101, /* vs_1_1 */
3243 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
3244 0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
3245 0x00000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
3246 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
3247 0x0000ffff /* end */
3249 DWORD shader_code_11_2
[] = {
3250 0xfffe0101, /* vs_1_1 */
3251 0x00000051, 0xa00f0001, 0x3fa00000, 0xbf000000, 0xbfc00000, 0x3f800000, /* dcl ... */
3252 0x00000051, 0xa00f0002, 0xbf000000, 0x3fa00000, 0x40000000, 0x3f800000, /* dcl ... */
3253 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
3254 0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
3255 0x00000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
3256 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
3257 0x0000ffff /* end */
3259 DWORD shader_code_20
[] = {
3260 0xfffe0200, /* vs_2_0 */
3261 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
3262 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
3263 0x03000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
3264 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
3265 0x0000ffff /* end */
3267 DWORD shader_code_20_2
[] = {
3268 0xfffe0200, /* vs_2_0 */
3269 0x05000051, 0xa00f0001, 0x3fa00000, 0xbf000000, 0xbfc00000, 0x3f800000,
3270 0x05000051, 0xa00f0002, 0xbf000000, 0x3fa00000, 0x40000000, 0x3f800000,
3271 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
3272 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
3273 0x03000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
3274 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
3275 0x0000ffff /* end */
3277 static const D3DVERTEXELEMENT9 decl_elements
[] = {
3278 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
3305 float test_data_c1
[4] = { 1.25, -0.50, -1.50, 1.0};
3306 float test_data_c2
[4] = { -0.50, 1.25, 2.00, 1.0};
3308 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ffff, 0.0, 0);
3309 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %s\n", DXGetErrorString9(hr
));
3311 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_code_11
, &shader_11
);
3312 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %s\n", DXGetErrorString9(hr
));
3313 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_code_11_2
, &shader_11_2
);
3314 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %s\n", DXGetErrorString9(hr
));
3315 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_code_20
, &shader_20
);
3316 if(FAILED(hr
)) shader_20
= NULL
;
3317 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_code_20_2
, &shader_20_2
);
3318 if(FAILED(hr
)) shader_20_2
= NULL
;
3319 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &decl
);
3320 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
3322 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 1, test_data_c1
, 1);
3323 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShaderConstantF returned %s\n", DXGetErrorString9(hr
));
3324 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 2, test_data_c2
, 1);
3325 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShaderConstantF returned %s\n", DXGetErrorString9(hr
));
3326 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl
);
3327 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
3329 hr
= IDirect3DDevice9_BeginScene(device
);
3330 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
3333 hr
= IDirect3DDevice9_SetVertexShader(device
, shader_11
);
3334 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
3335 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, 3 * sizeof(float));
3336 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
3338 hr
= IDirect3DDevice9_SetVertexShader(device
, shader_11_2
);
3339 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
3340 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, 3 * sizeof(float));
3341 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
3344 hr
= IDirect3DDevice9_SetVertexShader(device
, shader_20
);
3345 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
3346 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, 3 * sizeof(float));
3347 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
3351 hr
= IDirect3DDevice9_SetVertexShader(device
, shader_20_2
);
3352 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
3353 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, 3 * sizeof(float));
3354 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
3357 hr
= IDirect3DDevice9_EndScene(device
);
3358 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
3360 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
3361 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
3363 hr
= IDirect3DDevice9_SetVertexShader(device
, NULL
);
3364 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
3365 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
3366 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
3368 color
= getPixelColor(device
, 160, 360);
3369 ok(color
== 0x00bfbf80 || color
== 0x00bfbf7f || color
== 0x00bfbf81,
3370 "quad 1 has color %08x, expected 0x00bfbf80\n", color
);
3371 color
= getPixelColor(device
, 480, 360);
3372 ok(color
== 0x00bfbf80 || color
== 0x00bfbf7f || color
== 0x00bfbf81,
3373 "quad 2 has color %08x, expected 0x00bfbf80\n", color
);
3375 color
= getPixelColor(device
, 160, 120);
3376 ok(color
== 0x00bfbf80 || color
== 0x00bfbf7f || color
== 0x00bfbf81,
3377 "quad 3 has color %08x, expected 0x00bfbf80\n", color
);
3380 color
= getPixelColor(device
, 480, 120);
3381 ok(color
== 0x00bfbf80 || color
== 0x00bfbf7f || color
== 0x00bfbf81,
3382 "quad 4 has color %08x, expected 0x00bfbf80\n", color
);
3385 IDirect3DVertexDeclaration9_Release(decl
);
3386 if(shader_20_2
) IDirect3DVertexShader9_Release(shader_20_2
);
3387 if(shader_20
) IDirect3DVertexShader9_Release(shader_20
);
3388 IDirect3DVertexShader9_Release(shader_11_2
);
3389 IDirect3DVertexShader9_Release(shader_11
);
3392 static void constant_clamp_ps_test(IDirect3DDevice9
*device
)
3394 IDirect3DPixelShader9
*shader_11
, *shader_12
, *shader_14
, *shader_20
;
3397 DWORD shader_code_11
[] = {
3398 0xffff0101, /* ps_1_1 */
3399 0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
3400 0x00000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
3401 0x0000ffff /* end */
3403 DWORD shader_code_12
[] = {
3404 0xffff0102, /* ps_1_2 */
3405 0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
3406 0x00000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
3407 0x0000ffff /* end */
3409 /* Skip 1.3 shaders because we have only 4 quads(ok, could make them smaller if needed).
3410 * 1.2 and 1.4 shaders behave the same, so it's unlikely that 1.3 shaders are different.
3411 * During development of this test, 1.3 shaders were verified too
3413 DWORD shader_code_14
[] = {
3414 0xffff0104, /* ps_1_4 */
3415 /* Try to make one constant local. It gets clamped too, although the binary contains
3416 * the bigger numbers
3418 0x00000051, 0xa00f0002, 0xbf000000, 0x3fa00000, 0x40000000, 0x3f800000, /* def c2, -0.5, 1.25, 2, 1 */
3419 0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
3420 0x00000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
3421 0x0000ffff /* end */
3423 DWORD shader_code_20
[] = {
3424 0xffff0200, /* ps_2_0 */
3425 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
3426 0x03000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
3427 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
3428 0x0000ffff /* end */
3454 float test_data_c1
[4] = { 1.25, -0.50, -1.50, 1.0};
3455 float test_data_c2
[4] = { -0.50, 1.25, 2.00, 1.0};
3457 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ffff, 0.0, 0);
3458 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %s\n", DXGetErrorString9(hr
));
3460 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_11
, &shader_11
);
3461 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %s\n", DXGetErrorString9(hr
));
3462 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_12
, &shader_12
);
3463 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %s\n", DXGetErrorString9(hr
));
3464 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_14
, &shader_14
);
3465 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %s\n", DXGetErrorString9(hr
));
3466 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_20
, &shader_20
);
3467 if(FAILED(hr
)) shader_20
= NULL
;
3469 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 1, test_data_c1
, 1);
3470 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %s\n", DXGetErrorString9(hr
));
3471 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 2, test_data_c2
, 1);
3472 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %s\n", DXGetErrorString9(hr
));
3473 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
3474 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF returned %s\n", DXGetErrorString9(hr
));
3476 hr
= IDirect3DDevice9_BeginScene(device
);
3477 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
3480 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_11
);
3481 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
3482 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, 3 * sizeof(float));
3483 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
3485 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_12
);
3486 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
3487 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, 3 * sizeof(float));
3488 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
3490 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_14
);
3491 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
3492 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, 3 * sizeof(float));
3493 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
3496 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_20
);
3497 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
3498 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, 3 * sizeof(float));
3499 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
3502 hr
= IDirect3DDevice9_EndScene(device
);
3503 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
3505 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
3506 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
3508 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
3509 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
3511 color
= getPixelColor(device
, 160, 360);
3512 ok(color
== 0x00808000 || color
== 0x007f7f00 || color
== 0x00818100,
3513 "quad 1 has color %08x, expected 0x00808000\n", color
);
3514 color
= getPixelColor(device
, 480, 360);
3515 ok(color
== 0x00808000 || color
== 0x007f7f00 || color
== 0x00818100,
3516 "quad 2 has color %08x, expected 0x00808000\n", color
);
3517 color
= getPixelColor(device
, 480, 120);
3518 ok(color
== 0x00808000 || color
== 0x007f7f00 || color
== 0x00818100,
3519 "quad 3 has color %08x, expected 0x00808000\n", color
);
3521 color
= getPixelColor(device
, 160, 120);
3522 ok(color
== 0x00bfbf80 || color
== 0x00bfbf7f || color
== 0x00bfbf81,
3523 "quad 4 has color %08x, expected 0x00bfbf80\n", color
);
3526 if(shader_20
) IDirect3DPixelShader9_Release(shader_20
);
3527 IDirect3DPixelShader9_Release(shader_14
);
3528 IDirect3DPixelShader9_Release(shader_12
);
3529 IDirect3DPixelShader9_Release(shader_11
);
3532 static void cnd_test(IDirect3DDevice9
*device
)
3534 IDirect3DPixelShader9
*shader_11
, *shader_12
, *shader_13
, *shader_14
;
3535 IDirect3DPixelShader9
*shader_11_coissue
, *shader_12_coissue
, *shader_13_coissue
, *shader_14_coissue
;
3538 /* ps 1.x shaders are rather picky with writemasks and source swizzles. The dp3 is
3539 * used to copy r0.r to all components of r1, then copy r1.a to c0.a. Essentially it
3540 * does a mov r0.a, r0.r, which isn't allowed as-is in 1.x pixel shaders.
3542 DWORD shader_code_11
[] = {
3543 0xffff0101, /* ps_1_1 */
3544 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
3545 0x00000040, 0xb00f0000, /* texcoord t0 */
3546 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, ???(t0) */
3547 0x00000008, 0x800f0001, 0x80e40000, 0xa0e40000, /* dp3 r1, r0, c0 */
3548 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
3549 0x00000050, 0x800f0000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* cnd r0, r0.a, c1, c2 */
3550 0x0000ffff /* end */
3552 DWORD shader_code_12
[] = {
3553 0xffff0102, /* ps_1_2 */
3554 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
3555 0x00000040, 0xb00f0000, /* texcoord t0 */
3556 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
3557 0x00000008, 0x800f0001, 0x80e40000, 0xa0e40000, /* dp3 r1, r0, c0 */
3558 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
3559 0x00000050, 0x800f0000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* cnd r0, r0.a, c1, c2 */
3560 0x0000ffff /* end */
3562 DWORD shader_code_13
[] = {
3563 0xffff0103, /* ps_1_3 */
3564 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
3565 0x00000040, 0xb00f0000, /* texcoord t0 */
3566 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
3567 0x00000008, 0x800f0001, 0x80e40000, 0xa0e40000, /* dp3, r1, r0, c0 */
3568 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
3569 0x00000050, 0x800f0000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* cnd r0, r0.a, c1, c2 */
3570 0x0000ffff /* end */
3572 DWORD shader_code_14
[] = {
3573 0xffff0104, /* ps_1_3 */
3574 0x00000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0, 0, 0, 1 */
3575 0x00000040, 0x80070000, 0xb0e40000, /* texcrd r0, t0 */
3576 0x00000001, 0x80080000, 0xa0ff0000, /* mov r0.a, c0.a */
3577 0x00000050, 0x800f0000, 0x80e40000, 0xa0e40001, 0xa0e40002, /* cnd r0, r0, c1, c2 */
3578 0x0000ffff /* end */
3581 /* Special fun: The coissue flag on cnd: Apparently cnd always selects the 2nd source,
3582 * as if the src0 comparison against 0.5 always evaluates to true. The coissue flag isn't
3583 * set by the compiler, it was added manually after compilation. It isn't always allowed,
3584 * only if there's a mov r0.a, XXXX, and the cnd instruction writes to r0.xyz, otherwise
3585 * native CreatePixelShader returns an error.
3587 * The shader attempts to test the range [-1;1] against coissued cnd, which is a bit tricky.
3588 * The input from t0 is [0;1]. 0.5 is substracted, then we have to multiply with 2. Since
3589 * constants are clamped to [-1;1], a 2.0 is constructed by adding c0.r(=1.0) to c0.r into r1.r,
3590 * then r1(2.0, 0.0, 0.0, 0.0) is passed to dp3(explained above).
3592 DWORD shader_code_11_coissue
[] = {
3593 0xffff0101, /* ps_1_1 */
3594 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
3595 0x00000051, 0xa00f0003, 0x3f000000, 0x3f000000, 0x3f000000, 0x00000000, /* def c3, 0.5, 0.5, 0.5, 0 */
3596 0x00000040, 0xb00f0000, /* texcoord t0 */
3597 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
3598 0x00000003, 0x800f0000, 0x80e40000, 0xa0e40003, /* sub r0, r0, c3 */
3599 0x00000002, 0x800f0001, 0xa0e40000, 0xa0e40000, /* add r1, c0, c0 */
3600 0x00000008, 0x800f0001, 0x80e40000, 0x80e40001, /* dp3, r1, r0, r1 */
3601 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
3602 /* 0x40000000 = D3DSI_COISSUE */
3603 0x40000050, 0x80070000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* cnd r0.xyz, r0.a, c1, c2 */
3604 0x0000ffff /* end */
3606 DWORD shader_code_12_coissue
[] = {
3607 0xffff0102, /* ps_1_2 */
3608 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
3609 0x00000051, 0xa00f0003, 0x3f000000, 0x3f000000, 0x3f000000, 0x00000000, /* def c3, 0.5, 0.5, 0.5, 0 */
3610 0x00000040, 0xb00f0000, /* texcoord t0 */
3611 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
3612 0x00000003, 0x800f0000, 0x80e40000, 0xa0e40003, /* sub r0, r0, c3 */
3613 0x00000002, 0x800f0001, 0xa0e40000, 0xa0e40000, /* add r1, c0, c0 */
3614 0x00000008, 0x800f0001, 0x80e40000, 0x80e40001, /* dp3, r1, r0, r1 */
3615 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
3616 /* 0x40000000 = D3DSI_COISSUE */
3617 0x40000050, 0x80070000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* cnd r0.xyz, r0.a, c1, c2 */
3618 0x0000ffff /* end */
3620 DWORD shader_code_13_coissue
[] = {
3621 0xffff0103, /* ps_1_3 */
3622 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1, 0, 0, 0 */
3623 0x00000051, 0xa00f0003, 0x3f000000, 0x3f000000, 0x3f000000, 0x00000000, /* def c3, 0.5, 0.5, 0.5, 0 */
3624 0x00000040, 0xb00f0000, /* texcoord t0 */
3625 0x00000001, 0x800f0000, 0xb0e40000, /* mov r0, t0 */
3626 0x00000003, 0x800f0000, 0x80e40000, 0xa0e40003, /* sub r0, r0, c3 */
3627 0x00000002, 0x800f0001, 0xa0e40000, 0xa0e40000, /* add r1, c0, c0 */
3628 0x00000008, 0x800f0001, 0x80e40000, 0x80e40001, /* dp3, r1, r0, r1 */
3629 0x00000001, 0x80080000, 0x80ff0001, /* mov r0.a, r1.a */
3630 /* 0x40000000 = D3DSI_COISSUE */
3631 0x40000050, 0x80070000, 0x80ff0000, 0xa0e40001, 0xa0e40002, /* cnd r0.xyz, r0.a, c1, c2 */
3632 0x0000ffff /* end */
3634 /* ps_1_4 does not have a different cnd behavior, just pass the [0;1] texcrd result to cnd, it will
3635 * compare against 0.5
3637 DWORD shader_code_14_coissue
[] = {
3638 0xffff0104, /* ps_1_4 */
3639 0x00000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0, 0, 0, 1 */
3640 0x00000040, 0x80070000, 0xb0e40000, /* texcrd r0, t0 */
3641 0x00000001, 0x80080000, 0xa0ff0000, /* mov r0.a, c0.a */
3642 /* 0x40000000 = D3DSI_COISSUE */
3643 0x40000050, 0x80070000, 0x80e40000, 0xa0e40001, 0xa0e40002, /* cnd r0.xyz, r0, c1, c2 */
3644 0x0000ffff /* end */
3647 -1.0, -1.0, 0.1, 0.0, 0.0, 1.0,
3648 0.0, -1.0, 0.1, 1.0, 0.0, 1.0,
3649 -1.0, 0.0, 0.1, 0.0, 1.0, 0.0,
3650 0.0, 0.0, 0.1, 1.0, 1.0, 0.0
3653 0.0, -1.0, 0.1, 0.0, 0.0, 1.0,
3654 1.0, -1.0, 0.1, 1.0, 0.0, 1.0,
3655 0.0, 0.0, 0.1, 0.0, 1.0, 0.0,
3656 1.0, 0.0, 0.1, 1.0, 1.0, 0.0
3659 0.0, 0.0, 0.1, 0.0, 0.0, 1.0,
3660 1.0, 0.0, 0.1, 1.0, 0.0, 1.0,
3661 0.0, 1.0, 0.1, 0.0, 1.0, 0.0,
3662 1.0, 1.0, 0.1, 1.0, 1.0, 0.0
3665 -1.0, 0.0, 0.1, 0.0, 0.0, 1.0,
3666 0.0, 0.0, 0.1, 1.0, 0.0, 1.0,
3667 -1.0, 1.0, 0.1, 0.0, 1.0, 0.0,
3668 0.0, 1.0, 0.1, 1.0, 1.0, 0.0
3670 float test_data_c1
[4] = { 0.0, 0.0, 0.0, 0.0};
3671 float test_data_c2
[4] = { 1.0, 1.0, 1.0, 1.0};
3672 float test_data_c1_coi
[4] = { 0.0, 1.0, 0.0, 0.0};
3673 float test_data_c2_coi
[4] = { 1.0, 0.0, 1.0, 1.0};
3675 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ffff, 0.0, 0);
3676 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %s\n", DXGetErrorString9(hr
));
3678 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_11
, &shader_11
);
3679 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %s\n", DXGetErrorString9(hr
));
3680 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_12
, &shader_12
);
3681 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %s\n", DXGetErrorString9(hr
));
3682 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_13
, &shader_13
);
3683 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %s\n", DXGetErrorString9(hr
));
3684 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_14
, &shader_14
);
3685 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %s\n", DXGetErrorString9(hr
));
3686 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_11_coissue
, &shader_11_coissue
);
3687 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %s\n", DXGetErrorString9(hr
));
3688 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_12_coissue
, &shader_12_coissue
);
3689 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %s\n", DXGetErrorString9(hr
));
3690 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_13_coissue
, &shader_13_coissue
);
3691 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %s\n", DXGetErrorString9(hr
));
3692 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code_14_coissue
, &shader_14_coissue
);
3693 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %s\n", DXGetErrorString9(hr
));
3695 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 1, test_data_c1
, 1);
3696 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %s\n", DXGetErrorString9(hr
));
3697 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 2, test_data_c2
, 1);
3698 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %s\n", DXGetErrorString9(hr
));
3699 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
3700 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF returned %s\n", DXGetErrorString9(hr
));
3702 hr
= IDirect3DDevice9_BeginScene(device
);
3703 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
3706 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_11
);
3707 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
3708 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, 6 * sizeof(float));
3709 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
3711 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_12
);
3712 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
3713 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, 6 * sizeof(float));
3714 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
3716 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_13
);
3717 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
3718 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, 6 * sizeof(float));
3719 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
3721 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_14
);
3722 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
3723 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, 6 * sizeof(float));
3724 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
3726 hr
= IDirect3DDevice9_EndScene(device
);
3727 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
3729 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
3730 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
3732 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
3733 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
3735 /* This is the 1.4 test. Each component(r, g, b) is tested separately against 0.5 */
3736 color
= getPixelColor(device
, 158, 118);
3737 ok(color
== 0x00ff00ff, "pixel 158, 118 has color %08x, expected 0x00ff00ff\n", color
);
3738 color
= getPixelColor(device
, 162, 118);
3739 ok(color
== 0x000000ff, "pixel 162, 118 has color %08x, expected 0x000000ff\n", color
);
3740 color
= getPixelColor(device
, 158, 122);
3741 ok(color
== 0x00ffffff, "pixel 162, 122 has color %08x, expected 0x00ffffff\n", color
);
3742 color
= getPixelColor(device
, 162, 122);
3743 ok(color
== 0x0000ffff, "pixel 162, 122 has color %08x, expected 0x0000ffff\n", color
);
3745 /* 1.1 shader. All 3 components get set, based on the .w comparison */
3746 color
= getPixelColor(device
, 158, 358);
3747 ok(color
== 0x00ffffff, "pixel 158, 358 has color %08x, expected 0x00ffffff\n", color
);
3748 color
= getPixelColor(device
, 162, 358);
3749 ok(color
== 0x00000000, "pixel 162, 358 has color %08x, expected 0x00000000\n", color
);
3750 color
= getPixelColor(device
, 158, 362);
3751 ok(color
== 0x00ffffff, "pixel 158, 362 has color %08x, expected 0x00ffffff\n", color
);
3752 color
= getPixelColor(device
, 162, 362);
3753 ok(color
== 0x00000000, "pixel 162, 362 has color %08x, expected 0x00000000\n", color
);
3756 color
= getPixelColor(device
, 478, 358);
3757 ok(color
== 0x00ffffff, "pixel 478, 358 has color %08x, expected 0x00ffffff\n", color
);
3758 color
= getPixelColor(device
, 482, 358);
3759 ok(color
== 0x00000000, "pixel 482, 358 has color %08x, expected 0x00000000\n", color
);
3760 color
= getPixelColor(device
, 478, 362);
3761 ok(color
== 0x00ffffff, "pixel 478, 362 has color %08x, expected 0x00ffffff\n", color
);
3762 color
= getPixelColor(device
, 482, 362);
3763 ok(color
== 0x00000000, "pixel 482, 362 has color %08x, expected 0x00000000\n", color
);
3766 color
= getPixelColor(device
, 478, 118);
3767 ok(color
== 0x00ffffff, "pixel 478, 118 has color %08x, expected 0x00ffffff\n", color
);
3768 color
= getPixelColor(device
, 482, 118);
3769 ok(color
== 0x00000000, "pixel 482, 118 has color %08x, expected 0x00000000\n", color
);
3770 color
= getPixelColor(device
, 478, 122);
3771 ok(color
== 0x00ffffff, "pixel 478, 122 has color %08x, expected 0x00ffffff\n", color
);
3772 color
= getPixelColor(device
, 482, 122);
3773 ok(color
== 0x00000000, "pixel 482, 122 has color %08x, expected 0x00000000\n", color
);
3775 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ffff, 0.0, 0);
3776 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %s\n", DXGetErrorString9(hr
));
3777 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 1, test_data_c1_coi
, 1);
3778 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %s\n", DXGetErrorString9(hr
));
3779 hr
= IDirect3DDevice9_SetPixelShaderConstantF(device
, 2, test_data_c2_coi
, 1);
3780 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShaderConstantF returned %s\n", DXGetErrorString9(hr
));
3782 hr
= IDirect3DDevice9_BeginScene(device
);
3783 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
3786 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_11_coissue
);
3787 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
3788 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, 6 * sizeof(float));
3789 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
3791 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_12_coissue
);
3792 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
3793 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, 6 * sizeof(float));
3794 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
3796 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_13_coissue
);
3797 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
3798 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, 6 * sizeof(float));
3799 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
3801 hr
= IDirect3DDevice9_SetPixelShader(device
, shader_14_coissue
);
3802 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
3803 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, 6 * sizeof(float));
3804 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
3806 hr
= IDirect3DDevice9_EndScene(device
);
3807 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
3809 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
3810 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
3812 /* This is the 1.4 test. The coissue doesn't change the behavior here, but keep in mind
3813 * that we swapped the values in c1 and c2 to make the other tests return some color
3815 color
= getPixelColor(device
, 158, 118);
3816 ok(color
== 0x00ffffff, "pixel 158, 118 has color %08x, expected 0x00ffffff\n", color
);
3817 color
= getPixelColor(device
, 162, 118);
3818 ok(color
== 0x0000ffff, "pixel 162, 118 has color %08x, expected 0x0000ffff\n", color
);
3819 color
= getPixelColor(device
, 158, 122);
3820 ok(color
== 0x00ff00ff, "pixel 162, 122 has color %08x, expected 0x00ff00ff\n", color
);
3821 color
= getPixelColor(device
, 162, 122);
3822 ok(color
== 0x000000ff, "pixel 162, 122 has color %08x, expected 0x000000ff\n", color
);
3824 /* 1.1 shader. coissue flag changed the semantic of cnd, c1 is always selected */
3825 color
= getPixelColor(device
, 158, 358);
3826 ok(color
== 0x0000ff00, "pixel 158, 358 has color %08x, expected 0x0000ff00\n", color
);
3827 color
= getPixelColor(device
, 162, 358);
3828 ok(color
== 0x0000ff00, "pixel 162, 358 has color %08x, expected 0x0000ff00\n", color
);
3829 color
= getPixelColor(device
, 158, 362);
3830 ok(color
== 0x0000ff00, "pixel 158, 362 has color %08x, expected 0x0000ff00\n", color
);
3831 color
= getPixelColor(device
, 162, 362);
3832 ok(color
== 0x0000ff00, "pixel 162, 362 has color %08x, expected 0x0000ff00\n", color
);
3835 color
= getPixelColor(device
, 478, 358);
3836 ok(color
== 0x0000ff00, "pixel 478, 358 has color %08x, expected 0x0000ff00\n", color
);
3837 color
= getPixelColor(device
, 482, 358);
3838 ok(color
== 0x0000ff00, "pixel 482, 358 has color %08x, expected 0x0000ff00\n", color
);
3839 color
= getPixelColor(device
, 478, 362);
3840 ok(color
== 0x0000ff00, "pixel 478, 362 has color %08x, expected 0x0000ff00\n", color
);
3841 color
= getPixelColor(device
, 482, 362);
3842 ok(color
== 0x0000ff00, "pixel 482, 362 has color %08x, expected 0x0000ff00\n", color
);
3845 color
= getPixelColor(device
, 478, 118);
3846 ok(color
== 0x0000ff00, "pixel 478, 118 has color %08x, expected 0x0000ff00\n", color
);
3847 color
= getPixelColor(device
, 482, 118);
3848 ok(color
== 0x0000ff00, "pixel 482, 118 has color %08x, expected 0x0000ff00\n", color
);
3849 color
= getPixelColor(device
, 478, 122);
3850 ok(color
== 0x0000ff00, "pixel 478, 122 has color %08x, expected 0x0000ff00\n", color
);
3851 color
= getPixelColor(device
, 482, 122);
3852 ok(color
== 0x0000ff00, "pixel 482, 122 has color %08x, expected 0x0000ff00\n", color
);
3854 IDirect3DPixelShader9_Release(shader_14_coissue
);
3855 IDirect3DPixelShader9_Release(shader_13_coissue
);
3856 IDirect3DPixelShader9_Release(shader_12_coissue
);
3857 IDirect3DPixelShader9_Release(shader_11_coissue
);
3858 IDirect3DPixelShader9_Release(shader_14
);
3859 IDirect3DPixelShader9_Release(shader_13
);
3860 IDirect3DPixelShader9_Release(shader_12
);
3861 IDirect3DPixelShader9_Release(shader_11
);
3864 static void nested_loop_test(IDirect3DDevice9
*device
) {
3865 const DWORD shader_code
[] = {
3866 0xffff0300, /* ps_3_0 */
3867 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 0, 0, 0, 1 */
3868 0x05000051, 0xa00f0001, 0x3d000000, 0x00000000, 0x00000000, 0x00000000, /* def c1, 1/32, 0, 0, 0*/
3869 0x05000030, 0xf00f0000, 0x00000004, 0x00000000, 0x00000002, 0x00000000, /* defi i0, 4, 0, 2, 0 */
3870 0x02000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
3871 0x0200001b, 0xf0e40800, 0xf0e40000, /* loop aL, i0 */
3872 0x0200001b, 0xf0e40800, 0xf0e40000, /* loop aL, i0 */
3873 0x03000002, 0x800f0000, 0x80e40000, 0xa0e40001, /* add r0, r0, c1 */
3874 0x0000001d, /* endloop */
3875 0x0000001d, /* endloop */
3876 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
3877 0x0000ffff /* end */
3879 IDirect3DPixelShader9
*shader
;
3882 const float quad
[] = {
3889 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code
, &shader
);
3890 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader failed with %s\n", DXGetErrorString9(hr
));
3891 hr
= IDirect3DDevice9_SetPixelShader(device
, shader
);
3892 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader failed with %s\n", DXGetErrorString9(hr
));
3893 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
3894 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed with %s\n", DXGetErrorString9(hr
));
3895 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x0000ff00, 0.0, 0);
3896 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %s\n", DXGetErrorString9(hr
));
3898 hr
= IDirect3DDevice9_BeginScene(device
);
3899 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
3902 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, 3 * sizeof(float));
3903 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
3904 hr
= IDirect3DDevice9_EndScene(device
);
3905 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
3907 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
3908 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
3910 color
= getPixelColor(device
, 360, 240);
3911 ok(color
== 0x007f0000 || color
== 0x00800000 || color
== 0x00810000,
3912 "Nested loop test returned color 0x%08x, expected 0x00800000\n", color
);
3914 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
3915 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader failed with %s\n", DXGetErrorString9(hr
));
3916 IDirect3DPixelShader9_Release(shader
);
3919 struct varying_test_struct
3921 const DWORD
*shader_code
;
3922 IDirect3DPixelShader9
*shader
;
3923 DWORD color
, color_rhw
;
3925 BOOL todo
, todo_rhw
;
3930 float pos_x
, pos_y
, pos_z
, rhw
;
3931 float weight_1
, weight_2
, weight_3
, weight_4
;
3932 float index_1
, index_2
, index_3
, index_4
;
3933 float normal_1
, normal_2
, normal_3
, normal_4
;
3934 float fog_1
, fog_2
, fog_3
, fog_4
;
3935 float texcoord_1
, texcoord_2
, texcoord_3
, texcoord_4
;
3936 float tangent_1
, tangent_2
, tangent_3
, tangent_4
;
3937 float binormal_1
, binormal_2
, binormal_3
, binormal_4
;
3938 float depth_1
, depth_2
, depth_3
, depth_4
;
3939 DWORD diffuse
, specular
;
3942 static void fixed_function_varying_test(IDirect3DDevice9
*device
) {
3943 /* dcl_position: fails to compile */
3944 const DWORD blendweight_code
[] = {
3945 0xffff0300, /* ps_3_0 */
3946 0x0200001f, 0x80000001, 0x900f0000, /* dcl_blendweight, v0 */
3947 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
3948 0x0000ffff /* end */
3950 const DWORD blendindices_code
[] = {
3951 0xffff0300, /* ps_3_0 */
3952 0x0200001f, 0x80000002, 0x900f0000, /* dcl_blendindices, v0 */
3953 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
3954 0x0000ffff /* end */
3956 const DWORD normal_code
[] = {
3957 0xffff0300, /* ps_3_0 */
3958 0x0200001f, 0x80000003, 0x900f0000, /* dcl_normal, v0 */
3959 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
3960 0x0000ffff /* end */
3963 const DWORD texcoord0_code
[] = {
3964 0xffff0300, /* ps_3_0 */
3965 0x0200001f, 0x80000005, 0x900f0000, /* dcl_texcoord0, v0 */
3966 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
3967 0x0000ffff /* end */
3969 const DWORD tangent_code
[] = {
3970 0xffff0300, /* ps_3_0 */
3971 0x0200001f, 0x80000006, 0x900f0000, /* dcl_tangent, v0 */
3972 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
3973 0x0000ffff /* end */
3975 const DWORD binormal_code
[] = {
3976 0xffff0300, /* ps_3_0 */
3977 0x0200001f, 0x80000007, 0x900f0000, /* dcl_binormal, v0 */
3978 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
3979 0x0000ffff /* end */
3981 /* tessfactor: fails */
3982 /* positiont: fails */
3983 const DWORD color_code
[] = {
3984 0xffff0300, /* ps_3_0 */
3985 0x0200001f, 0x8000000a, 0x900f0000, /* dcl_color0, v0 */
3986 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
3987 0x0000ffff /* end */
3989 const DWORD fog_code
[] = {
3990 0xffff0300, /* ps_3_0 */
3991 0x0200001f, 0x8000000b, 0x900f0000, /* dcl_fog, v0 */
3992 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
3993 0x0000ffff /* end */
3995 const DWORD depth_code
[] = {
3996 0xffff0300, /* ps_3_0 */
3997 0x0200001f, 0x8000000c, 0x900f0000, /* dcl_depth, v0 */
3998 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
3999 0x0000ffff /* end */
4001 const DWORD specular_code
[] = {
4002 0xffff0300, /* ps_3_0 */
4003 0x0200001f, 0x8001000a, 0x900f0000, /* dcl_color1, v0 */
4004 0x02000001, 0x800f0800, 0x90e40000, /* mov oC0, v0 */
4005 0x0000ffff /* end */
4009 struct varying_test_struct tests
[] = {
4010 {blendweight_code
, NULL
, 0x00000000, 0x00191919, "blendweight" , FALSE
, TRUE
},
4011 {blendindices_code
, NULL
, 0x00000000, 0x00000000, "blendindices" , FALSE
, FALSE
},
4012 {normal_code
, NULL
, 0x00000000, 0x004c4c4c, "normal" , FALSE
, TRUE
},
4013 /* Why does dx not forward the texcoord? */
4014 {texcoord0_code
, NULL
, 0x00000000, 0x00808c8c, "texcoord0" , FALSE
, FALSE
},
4015 {tangent_code
, NULL
, 0x00000000, 0x00999999, "tangent" , FALSE
, TRUE
},
4016 {binormal_code
, NULL
, 0x00000000, 0x00b2b2b2, "binormal" , FALSE
, TRUE
},
4017 {color_code
, NULL
, 0x00e6e6e6, 0x00e6e6e6, "color" , FALSE
, FALSE
},
4018 {fog_code
, NULL
, 0x00000000, 0x00666666, "fog" , FALSE
, TRUE
},
4019 {depth_code
, NULL
, 0x00000000, 0x00cccccc, "depth" , FALSE
, TRUE
},
4020 {specular_code
, NULL
, 0x004488ff, 0x004488ff, "specular" , FALSE
, FALSE
}
4022 /* Declare a monster vertex type :-) */
4023 static const D3DVERTEXELEMENT9 decl_elements
[] = {
4024 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
4025 {0, 16, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_BLENDWEIGHT
, 0},
4026 {0, 32, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_BLENDINDICES
, 0},
4027 {0, 48, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_NORMAL
, 0},
4028 {0, 64, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_FOG
, 0},
4029 {0, 80, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
4030 {0, 96, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TANGENT
, 0},
4031 {0, 112, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_BINORMAL
, 0},
4032 {0, 128, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_DEPTH
, 0},
4033 {0, 144, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
4034 {0, 148, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 1},
4037 static const D3DVERTEXELEMENT9 decl_elements2
[] = {
4038 {0, 0, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITIONT
, 0},
4039 {0, 16, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_BLENDWEIGHT
, 0},
4040 {0, 32, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_BLENDINDICES
, 0},
4041 {0, 48, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_NORMAL
, 0},
4042 {0, 64, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_FOG
, 0},
4043 {0, 80, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
4044 {0, 96, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TANGENT
, 0},
4045 {0, 112, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_BINORMAL
, 0},
4046 {0, 128, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_DEPTH
, 0},
4047 {0, 144, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
4048 {0, 148, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 1},
4051 struct hugeVertex data
[4] = {
4053 -1.0, -1.0, 0.1, 1.0,
4058 0.50, 0.55, 0.55, 0.55,
4062 0xe6e6e6e6, /* 0.9 * 256 */
4063 0x224488ff /* Nothing special */
4066 1.0, -1.0, 0.1, 1.0,
4071 0.50, 0.55, 0.55, 0.55,
4075 0xe6e6e6e6, /* 0.9 * 256 */
4076 0x224488ff /* Nothing special */
4079 -1.0, 1.0, 0.1, 1.0,
4084 0.50, 0.55, 0.55, 0.55,
4088 0xe6e6e6e6, /* 0.9 * 256 */
4089 0x224488ff /* Nothing special */
4097 0.50, 0.55, 0.55, 0.55,
4101 0xe6e6e6e6, /* 0.9 * 256 */
4102 0x224488ff /* Nothing special */
4105 struct hugeVertex data2
[4];
4106 IDirect3DVertexDeclaration9
*decl
;
4107 IDirect3DVertexDeclaration9
*decl2
;
4110 DWORD color
, r
, g
, b
, r_e
, g_e
, b_e
;
4112 memcpy(data2
, data
, sizeof(data2
));
4113 data2
[0].pos_x
= 0; data2
[0].pos_y
= 0;
4114 data2
[1].pos_x
= 640; data2
[1].pos_y
= 0;
4115 data2
[2].pos_x
= 0; data2
[2].pos_y
= 480;
4116 data2
[3].pos_x
= 640; data2
[3].pos_y
= 480;
4118 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &decl
);
4119 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
4120 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements2
, &decl2
);
4121 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
4122 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl
);
4123 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
4125 for(i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); i
++)
4127 hr
= IDirect3DDevice9_CreatePixelShader(device
, tests
[i
].shader_code
, &tests
[i
].shader
);
4128 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader failed for shader %s, hr = %s\n",
4129 tests
[i
].name
, DXGetErrorString9(hr
));
4132 for(i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); i
++)
4134 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
4135 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %s\n", DXGetErrorString9(hr
));
4137 IDirect3DDevice9_SetPixelShader(device
, tests
[i
].shader
);
4138 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
4140 hr
= IDirect3DDevice9_BeginScene(device
);
4141 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
4144 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, data
, sizeof(data
[0]));
4145 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
4146 hr
= IDirect3DDevice9_EndScene(device
);
4147 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
4149 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
4150 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
4152 color
= getPixelColor(device
, 360, 240);
4153 r
= color
& 0x00ff0000 >> 16;
4154 g
= color
& 0x0000ff00 >> 8;
4155 b
= color
& 0x000000ff;
4156 r_e
= tests
[i
].color
& 0x00ff0000 >> 16;
4157 g_e
= tests
[i
].color
& 0x0000ff00 >> 8;
4158 b_e
= tests
[i
].color
& 0x000000ff;
4161 todo_wine
ok(abs(r
- r_e
) <= 1 && abs(g
- g_e
) <= 1 && abs(b
- b_e
) <= 1,
4162 "Test %s returned color 0x%08x, expected 0x%08x(todo)\n",
4163 tests
[i
].name
, color
, tests
[i
].color
);
4165 ok(abs(r
- r_e
) <= 1 && abs(g
- g_e
) <= 1 && abs(b
- b_e
) <= 1,
4166 "Test %s returned color 0x%08x, expected 0x%08x\n",
4167 tests
[i
].name
, color
, tests
[i
].color
);
4171 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl2
);
4172 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
4173 for(i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); i
++)
4175 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
4176 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %s\n", DXGetErrorString9(hr
));
4178 IDirect3DDevice9_SetPixelShader(device
, tests
[i
].shader
);
4179 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
4181 hr
= IDirect3DDevice9_BeginScene(device
);
4182 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
4185 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, data2
, sizeof(data2
[0]));
4186 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
4187 hr
= IDirect3DDevice9_EndScene(device
);
4188 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
4190 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
4191 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
4193 color
= getPixelColor(device
, 360, 240);
4194 r
= color
& 0x00ff0000 >> 16;
4195 g
= color
& 0x0000ff00 >> 8;
4196 b
= color
& 0x000000ff;
4197 r_e
= tests
[i
].color_rhw
& 0x00ff0000 >> 16;
4198 g_e
= tests
[i
].color_rhw
& 0x0000ff00 >> 8;
4199 b_e
= tests
[i
].color_rhw
& 0x000000ff;
4201 if(tests
[i
].todo_rhw
) {
4202 /* This isn't a weekend's job to fix, ignore the problem for now. Needs a replacement
4205 todo_wine
ok(abs(r
- r_e
) <= 1 && abs(g
- g_e
) <= 1 && abs(b
- b_e
) <= 1,
4206 "Test %s returned color 0x%08x, expected 0x%08x(todo)\n",
4207 tests
[i
].name
, color
, tests
[i
].color_rhw
);
4209 ok(abs(r
- r_e
) <= 1 && abs(g
- g_e
) <= 1 && abs(b
- b_e
) <= 1,
4210 "Test %s returned color 0x%08x, expected 0x%08x\n",
4211 tests
[i
].name
, color
, tests
[i
].color_rhw
);
4215 for(i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); i
++)
4217 IDirect3DPixelShader9_Release(tests
[i
].shader
);
4220 IDirect3DVertexDeclaration9_Release(decl2
);
4221 IDirect3DVertexDeclaration9_Release(decl
);
4224 static void vshader_version_varying_test(IDirect3DDevice9
*device
) {
4225 static const DWORD ps_code
[] = {
4226 0xffff0300, /* ps_3_0 */
4227 0x05000030, 0xf00f0000, 0x00000003, 0x00000003, 0x00000001, 0x00000000, /* defi i0, 3, 3, 1, 0 */
4228 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 0.0, 0.0, 0.0, 0.0 */
4229 0x0200001f, 0x8001000a, 0x900f0003, /* dcl_color1 v3 */
4230 0x0200001f, 0x8000000b, 0x900f0004, /* dcl_fog v4 */
4231 0x0200001f, 0x80030005, 0x900f0005, /* dcl_texcoord3 v5 */
4232 0x0200001f, 0x80000003, 0x900f0006,
4233 0x0200001f, 0x80000006, 0x900f0007,
4234 0x0200001f, 0x80000001, 0x900f0008,
4235 0x0200001f, 0x8000000c, 0x900f0009,
4237 0x02000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
4238 0x0200001b, 0xf0e40800, 0xf0e40000, /* loop aL, i0 */
4239 0x04000002, 0x800f0000, 0x80e40000, 0x90e42000, 0xf0e40800, /* add r0, r0, v0[aL] */
4240 0x0000001d, /* endloop */
4241 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
4242 0x0000ffff /* end */
4244 static const DWORD vs_1_code
[] = {
4245 0xfffe0101, /* vs_1_1 */
4246 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
4247 0x00000051, 0xa00f0000, 0x3dcccccd, 0x00000000, 0x00000000, 0x00000000, /* def c0, 0.1, 0.0, 0.0, 0.0 */
4248 0x00000051, 0xa00f0001, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00000000, /* def c1, 0.0, 0.2, 0.0, 0.0 */
4249 0x00000051, 0xa00f0002, 0x00000000, 0x00000000, 0x3ecccccd, 0x00000000, /* def c2, 0.0, 0.0, 0.4, 0.0 */
4250 0x00000051, 0xa00f0003, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c3, 1.0, 1.0, 1.0, 1.0 */
4251 0x00000001, 0xd00f0000, 0xa0e40002, /* mov oD0, c2 */
4252 0x00000001, 0xd00f0001, 0xa0e40000, /* mov oD1, c0 */
4253 0x00000001, 0xc00f0001, 0xa0550001, /* mov oFog, c1.g */
4254 0x00000001, 0xe00f0000, 0xa0e40003, /* mov oT0, c3 */
4255 0x00000001, 0xe00f0001, 0xa0e40003, /* mov oT1, c3 */
4256 0x00000001, 0xe00f0002, 0xa0e40003, /* mov oT2, c3 */
4257 0x00000001, 0xe00f0003, 0xa0e40002, /* mov oT3, c2 */
4258 0x00000001, 0xe00f0004, 0xa0e40003, /* mov oT4, c3 */
4259 0x00000001, 0xe00f0005, 0xa0e40003, /* mov oT5, c3 */
4260 0x00000001, 0xe00f0006, 0xa0e40003, /* mov oT6, c3 */
4261 0x00000001, 0xe00f0007, 0xa0e40003, /* mov oT7, c3 */
4262 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
4265 DWORD vs_2_code
[] = {
4266 0xfffe0200, /* vs_2_0 */
4267 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
4268 0x05000051, 0xa00f0000, 0x3dcccccd, 0x00000000, 0x00000000, 0x00000000, /* def c0, 0.5, 0.0, 0.0, 0.0 */
4269 0x05000051, 0xa00f0001, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00000000, /* def c1, 0.0, 0.5, 0.0, 0.0 */
4270 0x05000051, 0xa00f0002, 0x00000000, 0x00000000, 0x3ecccccd, 0x00000000, /* def c2, 0.0, 0.0, 0.5, 0.0 */
4271 0x05000051, 0xa00f0003, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c3, 1.0, 1.0, 1.0, 1.0 */
4272 0x02000001, 0xd00f0000, 0xa0e40002, /* mov oD0, c2 */
4273 0x02000001, 0xd00f0001, 0xa0e40000, /* mov oD1, c0 */
4274 0x02000001, 0xc00f0001, 0xa0550001, /* mov oFog, c1.g */
4275 0x02000001, 0xe00f0000, 0xa0e40003, /* mov oT0, c3 */
4276 0x02000001, 0xe00f0001, 0xa0e40003, /* mov oT1, c3 */
4277 0x02000001, 0xe00f0002, 0xa0e40003, /* mov oT2, c3 */
4278 0x02000001, 0xe00f0003, 0xa0e40002, /* mov oT3, c2 */
4279 0x02000001, 0xe00f0004, 0xa0e40003, /* mov oT4, c3 */
4280 0x02000001, 0xe00f0005, 0xa0e40003, /* mov oT5, c3 */
4281 0x02000001, 0xe00f0006, 0xa0e40003, /* mov oT6, c3 */
4282 0x02000001, 0xe00f0007, 0xa0e40003, /* mov oT7, c3 */
4283 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
4284 0x0000ffff /* end */
4286 /* TODO: Define normal, tangent, blendweight and depth here */
4287 static const DWORD vs_3_code
[] = {
4288 0xfffe0300, /* vs_3_0 */
4289 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
4290 0x0200001f, 0x8001000a, 0xe00f0009, /* dcl_color1 o9 */
4291 0x0200001f, 0x8000000b, 0xe00f0002, /* dcl_fog o2 */
4292 0x0200001f, 0x80030005, 0xe00f0005, /* dcl_texcoord3 o5 */
4293 0x0200001f, 0x80000000, 0xe00f000b, /* dcl_position o11 */
4294 0x05000051, 0xa00f0000, 0x3dcccccd, 0x00000000, 0x00000000, 0x00000000, /* def c0, 0.1, 0.0, 0.0, 0.0 */
4295 0x05000051, 0xa00f0001, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00000000, /* def c1, 0.0, 0.2, 0.0, 0.0 */
4296 0x05000051, 0xa00f0002, 0x00000000, 0x00000000, 0x3ecccccd, 0x00000000, /* def c2, 0.0, 0.0, 0.4, 0.0 */
4297 0x05000051, 0xa00f0003, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c3, 1.0, 1.0, 1.0, 1.0 */
4298 0x02000001, 0xe00f0009, 0xa0e40000, /* mov o9, c0 */
4299 0x02000001, 0xe00f0002, 0xa0e40001, /* mov o2, c1 */
4300 0x02000001, 0xe00f0005, 0xa0e40002, /* mov o5, c2 */
4301 0x02000001, 0xe00f000b, 0x90e40000, /* mov o11, v0 */
4302 0x0000ffff /* end */
4325 IDirect3DPixelShader9
*pixelshader
= NULL
;
4326 IDirect3DVertexShader9
*vs_1_shader
= NULL
;
4327 IDirect3DVertexShader9
*vs_2_shader
= NULL
;
4328 IDirect3DVertexShader9
*vs_3_shader
= NULL
;
4330 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff110000, 0.0, 0);
4332 hr
= IDirect3DDevice9_CreatePixelShader(device
, ps_code
, &pixelshader
);
4333 ok(hr
== D3D_OK
, "IDirect3DDevice_CreatePixelShader returned %s\n", DXGetErrorString9(hr
));
4334 hr
= IDirect3DDevice9_CreateVertexShader(device
, vs_1_code
, &vs_1_shader
);
4335 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %s\n", DXGetErrorString9(hr
));
4336 hr
= IDirect3DDevice9_CreateVertexShader(device
, vs_2_code
, &vs_2_shader
);
4337 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %s\n", DXGetErrorString9(hr
));
4338 hr
= IDirect3DDevice9_CreateVertexShader(device
, vs_3_code
, &vs_3_shader
);
4339 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %s\n", DXGetErrorString9(hr
));
4340 hr
= IDirect3DDevice9_SetPixelShader(device
, pixelshader
);
4341 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
4342 IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
4344 hr
= IDirect3DDevice9_BeginScene(device
);
4345 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
4348 hr
= IDirect3DDevice9_SetVertexShader(device
, vs_1_shader
);
4349 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
4350 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(float) * 3);
4351 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
4353 hr
= IDirect3DDevice9_SetVertexShader(device
, vs_2_shader
);
4354 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
4355 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(float) * 3);
4356 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
4358 hr
= IDirect3DDevice9_SetVertexShader(device
, vs_3_shader
);
4359 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
4360 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, sizeof(float) * 3);
4361 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
4363 hr
= IDirect3DDevice9_EndScene(device
);
4364 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
4366 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
4367 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
4369 color
= getPixelColor(device
, 160, 120);
4370 ok((color
& 0x00ff0000) >= 0x00190000 && (color
& 0x00ff0000) <= 0x00210000 &&
4371 (color
& 0x0000ff00) >= 0x00003300 && (color
& 0x0000ff00) <= 0x00003500 &&
4372 (color
& 0x000000ff) >= 0x00000066 && (color
& 0x000000ff) <= 0x00210068,
4373 "vs_3_0 returned color 0x%08x, expected 0x00203366\n", color
);
4374 color
= getPixelColor(device
, 160, 360);
4375 ok((color
& 0x00ff0000) >= 0x003c0000 && (color
& 0x00ff0000) <= 0x004e0000 &&
4376 (color
& 0x0000ff00) >= 0x00000000 && (color
& 0x0000ff00) <= 0x00000000 &&
4377 (color
& 0x000000ff) >= 0x00000066 && (color
& 0x000000ff) <= 0x00210068,
4378 "vs_1_1 returned color 0x%08x, expected 0x00808080\n", color
);
4379 color
= getPixelColor(device
, 480, 360);
4380 ok((color
& 0x00ff0000) >= 0x003c0000 && (color
& 0x00ff0000) <= 0x004e0000 &&
4381 (color
& 0x0000ff00) >= 0x00000000 && (color
& 0x0000ff00) <= 0x00000000 &&
4382 (color
& 0x000000ff) >= 0x00000066 && (color
& 0x000000ff) <= 0x00210068,
4383 "vs_2_0 returned color 0x%08x, expected 0x00000000\n", color
);
4386 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
4387 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
4388 hr
= IDirect3DDevice9_SetVertexShader(device
, NULL
);
4389 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
4390 if(pixelshader
) IDirect3DPixelShader9_Release(pixelshader
);
4391 if(vs_1_shader
) IDirect3DVertexShader9_Release(vs_1_shader
);
4392 if(vs_2_shader
) IDirect3DVertexShader9_Release(vs_2_shader
);
4393 if(vs_3_shader
) IDirect3DVertexShader9_Release(vs_3_shader
);
4396 static void pshader_version_varying_test(IDirect3DDevice9
*device
) {
4397 static const DWORD vs_code
[] = {
4398 0xfffe0300, /* vs_3_0 */
4399 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
4400 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
4401 0x0200001f, 0x8000000a, 0xe00f0001, /* dcl_color0 o1 */
4402 0x0200001f, 0x80000005, 0xe00f0002, /* dcl_texcoord0 o2 */
4403 0x0200001f, 0x8000000b, 0xe00f0003, /* dcl_fog o3 */
4404 0x0200001f, 0x80000003, 0xe00f0004, /* dcl_normal o4 */
4405 0x0200001f, 0x8000000c, 0xe00f0005, /* dcl_depth o5 */
4406 0x0200001f, 0x80000006, 0xe00f0006, /* dcl_tangent o6 */
4407 0x0200001f, 0x80000001, 0xe00f0007, /* dcl_blendweight o7 */
4408 0x05000051, 0xa00f0001, 0x3dcccccd, 0x00000000, 0x00000000, 0x00000000, /* def c1, 0.1, 0.0, 0.0, 0.0 */
4409 0x05000051, 0xa00f0002, 0x00000000, 0x3e4ccccd, 0x00000000, 0x3f800000, /* def c2, 0.0, 0.2, 0.0, 1.0 */
4410 0x05000051, 0xa00f0003, 0x3ecccccd, 0x3f59999a, 0x3f666666, 0x00000000, /* def c3, 0.4, 0.85,0.9, 0.0 */
4411 0x05000051, 0xa00f0000, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c0, 1.0, 1.0, 1.0, 1.0 */
4413 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
4414 0x02000001, 0xe00f0001, 0xa0e40001, /* mov o1, c1 */
4415 0x02000001, 0xe00f0002, 0xa0e40002, /* mov o2, c2 */
4416 0x02000001, 0xe00f0003, 0xa0e40003, /* mov o3, c3 */
4417 0x02000001, 0xe00f0004, 0xa0e40000, /* mov o4, c0 */
4418 0x02000001, 0xe00f0005, 0xa0e40000, /* mov o5, c0 */
4419 0x02000001, 0xe00f0006, 0xa0e40000, /* mov o6, c0 */
4420 0x02000001, 0xe00f0007, 0xa0e40000, /* mov o7, c0 */
4421 0x0000ffff /* end */
4423 static const DWORD ps_1_code
[] = {
4424 0xffff0104, /* ps_1_4 */
4425 0x00000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 0.0, 0.0, 0.0, 0.0 */
4426 0x00000040, 0x80070001, 0xb0e40000, /* texcrd r1.xyz, t0 */
4427 0x00000001, 0x80080001, 0xa0ff0000, /* mov r1.a, c0.a */
4428 0x00000002, 0x800f0000, 0x90e40000, 0x80e40001, /* add r0, v0, r1 */
4429 0x0000ffff /* end */
4431 static const DWORD ps_2_code
[] = {
4432 0xffff0200, /* ps_2_0 */
4433 0x0200001f, 0x80000000, 0xb00f0000, /* dcl t0 */
4434 0x0200001f, 0x80000000, 0x900f0000, /* dcl v0 */
4435 0x0200001f, 0x80000000, 0x900f0001, /* dcl v1 */
4437 0x02000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
4438 0x03000002, 0x800f0000, 0x80e40000,0xb0e40000, /* add r0, r0, t0 */
4439 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
4440 0x0000ffff /* end */
4442 static const DWORD ps_3_code
[] = {
4443 0xffff0300, /* ps_3_0 */
4444 0x0200001f, 0x80000005, 0x900f0000, /* dcl_texcoord0 v0 */
4445 0x0200001f, 0x8000000a, 0x900f0001, /* dcl_color0 v1 */
4446 0x0200001f, 0x8000000b, 0x900f0002, /* dcl_fog v2 */
4448 0x02000001, 0x800f0000, 0x90e40000, /* mov r0, v0 */
4449 0x03000002, 0x800f0000, 0x80e40000, 0x90e40001, /* add r0, r0, v1 */
4450 0x03000002, 0x800f0000, 0x80e40000, 0x90e40002, /* mov r0, r0, v2 */
4451 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
4452 0x0000ffff /* end */
4482 IDirect3DVertexShader9
*vertexshader
= NULL
;
4483 IDirect3DPixelShader9
*ps_1_shader
= NULL
;
4484 IDirect3DPixelShader9
*ps_2_shader
= NULL
;
4485 IDirect3DPixelShader9
*ps_3_shader
= NULL
;
4486 IDirect3DTexture9
*texture
= NULL
;
4490 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffff00, 0.0, 0);
4492 hr
= IDirect3DDevice9_CreateTexture(device
, 512, 512, 1, 0, D3DFMT_A16B16G16R16
, D3DPOOL_MANAGED
, &texture
, NULL
);
4493 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture returned %s\n", DXGetErrorString9(hr
));
4494 hr
= IDirect3DTexture9_LockRect(texture
, 0, &lr
, NULL
, 0);
4495 ok(hr
== D3D_OK
, "IDirect3DTexture9_LockRect returned %s\n", DXGetErrorString9(hr
));
4496 for(y
= 0; y
< 512; y
++) {
4497 for(x
= 0; x
< 512; x
++) {
4498 double r_f
= (double) x
/ (double) 512;
4499 double g_f
= (double) y
/ (double) 512;
4500 unsigned short *dst
= (unsigned short *) (((unsigned char *) lr
.pBits
) + y
* lr
.Pitch
+ x
* 8);
4501 unsigned short r
= (unsigned short) (r_f
* 65535.0);
4502 unsigned short g
= (unsigned short) (g_f
* 65535.0);
4509 hr
= IDirect3DTexture9_UnlockRect(texture
, 0);
4510 ok(hr
== D3D_OK
, "IDirect3DTexture9_UnlockRect returned %s\n", DXGetErrorString9(hr
));
4512 hr
= IDirect3DDevice9_CreateVertexShader(device
, vs_code
, &vertexshader
);
4513 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %s\n", DXGetErrorString9(hr
));
4514 hr
= IDirect3DDevice9_CreatePixelShader(device
, ps_1_code
, &ps_1_shader
);
4515 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %s\n", DXGetErrorString9(hr
));
4516 hr
= IDirect3DDevice9_CreatePixelShader(device
, ps_2_code
, &ps_2_shader
);
4517 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %s\n", DXGetErrorString9(hr
));
4518 hr
= IDirect3DDevice9_CreatePixelShader(device
, ps_3_code
, &ps_3_shader
);
4519 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %s\n", DXGetErrorString9(hr
));
4520 hr
= IDirect3DDevice9_SetVertexShader(device
, vertexshader
);
4521 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
4522 IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
4524 hr
= IDirect3DDevice9_BeginScene(device
);
4525 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
4528 hr
= IDirect3DDevice9_SetPixelShader(device
, ps_1_shader
);
4529 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
4530 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(float) * 3);
4531 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
4533 hr
= IDirect3DDevice9_SetPixelShader(device
, ps_2_shader
);
4534 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
4535 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(float) * 3);
4536 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
4538 hr
= IDirect3DDevice9_SetPixelShader(device
, ps_3_shader
);
4539 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
4540 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, sizeof(float) * 3);
4541 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
4543 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
4544 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
4545 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) texture
);
4546 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture returned %s\n", DXGetErrorString9(hr
));
4547 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
4548 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_ADD
);
4549 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
4550 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_DIFFUSE
);
4551 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, sizeof(float) * 3);
4552 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
4554 hr
= IDirect3DDevice9_EndScene(device
);
4555 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
4557 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
4558 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
4560 color
= getPixelColor(device
, 160, 120);
4561 ok((color
& 0x00ff0000) >= 0x00790000 && (color
& 0x00ff0000) <= 0x00810000 &&
4562 (color
& 0x0000ff00) == 0x0000ff00 &&
4563 (color
& 0x000000ff) >= 0x000000e4 && (color
& 0x000000ff) <= 0x000000e6,
4564 "ps_3_0 returned color 0x%08x, expected 0x0080ffe5\n", color
);
4565 color
= getPixelColor(device
, 160, 360);
4566 ok((color
& 0x00ff0000) >= 0x00190000 && (color
& 0x00ff0000) <= 0x00210000 &&
4567 (color
& 0x0000ff00) >= 0x00003300 && (color
& 0x0000ff00) <= 0x00003400 &&
4568 (color
& 0x000000ff) == 0x00000000,
4569 "ps_1_4 returned color 0x%08x, expected 0x00203300\n", color
);
4570 color
= getPixelColor(device
, 480, 360);
4571 ok((color
& 0x00ff0000) >= 0x00190000 && (color
& 0x00ff0000) <= 0x00210000 &&
4572 (color
& 0x0000ff00) >= 0x00003200 && (color
& 0x0000ff00) <= 0x00003400 &&
4573 (color
& 0x000000ff) == 0x00000000,
4574 "ps_2_0 returned color 0x%08x, expected 0x00203300\n", color
);
4575 color
= getPixelColor(device
, 480, 160);
4576 ok((color
& 0x00ff0000) >= 0x00190000 && (color
& 0x00ff0000) <= 0x00210000 &&
4577 (color
& 0x0000ff00) >= 0x00003200 && (color
& 0x0000ff00) <= 0x00003400 &&
4578 (color
& 0x000000ff) == 0x00000000,
4579 "fixed function fragment processing returned color 0x%08x, expected 0x00203300\n", color
);
4582 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
4583 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture returned %s\n", DXGetErrorString9(hr
));
4584 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
4585 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
4586 hr
= IDirect3DDevice9_SetVertexShader(device
, NULL
);
4587 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
4588 if(vertexshader
) IDirect3DVertexShader9_Release(vertexshader
);
4589 if(ps_1_shader
) IDirect3DPixelShader9_Release(ps_1_shader
);
4590 if(ps_2_shader
) IDirect3DPixelShader9_Release(ps_2_shader
);
4591 if(ps_3_shader
) IDirect3DPixelShader9_Release(ps_3_shader
);
4592 if(texture
) IDirect3DTexture9_Release(texture
);
4595 void test_compare_instructions(IDirect3DDevice9
*device
)
4597 DWORD shader_sge_vec_code
[] = {
4598 0xfffe0101, /* vs_1_1 */
4599 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
4600 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
4601 0x00000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
4602 0x0000000d, 0xd00f0000, 0x80e40000, 0xa0e40001, /* sge oD0, r0, c1 */
4603 0x0000ffff /* end */
4605 DWORD shader_slt_vec_code
[] = {
4606 0xfffe0101, /* vs_1_1 */
4607 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
4608 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
4609 0x00000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
4610 0x0000000c, 0xd00f0000, 0x80e40000, 0xa0e40001, /* slt oD0, r0, c1 */
4611 0x0000ffff /* end */
4613 DWORD shader_sge_scalar_code
[] = {
4614 0xfffe0101, /* vs_1_1 */
4615 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
4616 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
4617 0x00000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
4618 0x0000000d, 0xd0010000, 0x80000000, 0xa0550001, /* slt oD0.r, r0.r, c1.b */
4619 0x0000000d, 0xd0020000, 0x80550000, 0xa0aa0001, /* slt oD0.g, r0.g, c1.r */
4620 0x0000000d, 0xd0040000, 0x80aa0000, 0xa0000001, /* slt oD0.b, r0.b, c1.g */
4621 0x0000ffff /* end */
4623 DWORD shader_slt_scalar_code
[] = {
4624 0xfffe0101, /* vs_1_1 */
4625 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
4626 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
4627 0x00000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
4628 0x0000000c, 0xd0010000, 0x80000000, 0xa0aa0001, /* slt oD0.r, r0.r, c1.b */
4629 0x0000000c, 0xd0020000, 0x80550000, 0xa0000001, /* slt oD0.g, r0.g, c1.r */
4630 0x0000000c, 0xd0040000, 0x80aa0000, 0xa0550001, /* slt oD0.b, r0.b, c1.g */
4631 0x0000ffff /* end */
4633 IDirect3DVertexShader9
*shader_sge_vec
;
4634 IDirect3DVertexShader9
*shader_slt_vec
;
4635 IDirect3DVertexShader9
*shader_sge_scalar
;
4636 IDirect3DVertexShader9
*shader_slt_scalar
;
4662 const float const0
[4] = {0.8, 0.2, 0.2, 0.2};
4663 const float const1
[4] = {0.2, 0.8, 0.2, 0.2};
4665 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
4667 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_sge_vec_code
, &shader_sge_vec
);
4668 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %s\n", DXGetErrorString9(hr
));
4669 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_slt_vec_code
, &shader_slt_vec
);
4670 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %s\n", DXGetErrorString9(hr
));
4671 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_sge_scalar_code
, &shader_sge_scalar
);
4672 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %s\n", DXGetErrorString9(hr
));
4673 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_slt_scalar_code
, &shader_slt_scalar
);
4674 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %s\n", DXGetErrorString9(hr
));
4675 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 0, const0
, 1);
4676 ok(SUCCEEDED(hr
), "SetVertexShaderConstantF failed (%08x)\n", hr
);
4677 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 1, const1
, 1);
4678 ok(SUCCEEDED(hr
), "SetVertexShaderConstantF failed (%08x)\n", hr
);
4679 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
4680 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetFVF failed (%08x)\n", hr
);
4682 hr
= IDirect3DDevice9_BeginScene(device
);
4683 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
4686 hr
= IDirect3DDevice9_SetVertexShader(device
, shader_sge_vec
);
4687 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
4688 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(float) * 3);
4689 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
4691 hr
= IDirect3DDevice9_SetVertexShader(device
, shader_slt_vec
);
4692 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
4693 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(float) * 3);
4694 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
4696 hr
= IDirect3DDevice9_SetVertexShader(device
, shader_sge_scalar
);
4697 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
4698 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, sizeof(float) * 3);
4699 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
4701 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 0, const0
, 1);
4702 ok(SUCCEEDED(hr
), "SetVertexShaderConstantF failed (%08x)\n", hr
);
4704 hr
= IDirect3DDevice9_SetVertexShader(device
, shader_slt_scalar
);
4705 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
4706 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, sizeof(float) * 3);
4707 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
4709 hr
= IDirect3DDevice9_EndScene(device
);
4710 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
4713 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
4714 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
4716 color
= getPixelColor(device
, 160, 360);
4717 ok(color
== 0x00FF00FF, "Compare test: Quad 1(sge vec) returned color 0x%08x, expected 0x00FF00FF\n", color
);
4718 color
= getPixelColor(device
, 480, 360);
4719 ok(color
== 0x0000FF00, "Compare test: Quad 2(slt vec) returned color 0x%08x, expected 0x0000FF00\n", color
);
4720 color
= getPixelColor(device
, 160, 120);
4721 ok(color
== 0x00FFFFFF, "Compare test: Quad 3(sge scalar) returned color 0x%08x, expected 0x00FFFFFF\n", color
);
4722 color
= getPixelColor(device
, 480, 160);
4723 ok(color
== 0x000000ff, "Compare test: Quad 4(slt scalar) returned color 0x%08x, expected 0x000000ff\n", color
);
4725 IDirect3DVertexShader9_Release(shader_sge_vec
);
4726 IDirect3DVertexShader9_Release(shader_slt_vec
);
4727 IDirect3DVertexShader9_Release(shader_sge_scalar
);
4728 IDirect3DVertexShader9_Release(shader_slt_scalar
);
4731 void test_vshader_input(IDirect3DDevice9
*device
)
4733 DWORD swapped_shader_code_3
[] = {
4734 0xfffe0300, /* vs_3_0 */
4735 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
4736 0x0200001f, 0x8000000a, 0xe00f0001, /* dcl_color o1 */
4737 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
4738 0x0200001f, 0x80000005, 0x900f0001, /* dcl_texcoord0 v1 */
4739 0x0200001f, 0x80010005, 0x900f0002, /* dcl_texcoord1 v2 */
4740 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
4741 0x02000001, 0x800f0001, 0x90e40001, /* mov r1, v1 */
4742 0x03000002, 0xe00f0001, 0x80e40001, 0x91e40002, /* sub o1, r1, v2 */
4743 0x0000ffff /* end */
4745 DWORD swapped_shader_code_1
[] = {
4746 0xfffe0101, /* vs_1_1 */
4747 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
4748 0x0000001f, 0x80000005, 0x900f0001, /* dcl_texcoord0 v1 */
4749 0x0000001f, 0x80010005, 0x900f0002, /* dcl_texcoord1 v2 */
4750 0x00000001, 0xc00f0000, 0x90e40000, /* mov o0, v0 */
4751 0x00000001, 0x800f0001, 0x90e40001, /* mov r1, v1 */
4752 0x00000002, 0xd00f0000, 0x80e40001, 0x91e40002, /* sub o1, r1, v2 */
4753 0x0000ffff /* end */
4755 DWORD swapped_shader_code_2
[] = {
4756 0xfffe0200, /* vs_2_0 */
4757 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
4758 0x0200001f, 0x80000005, 0x900f0001, /* dcl_texcoord0 v1 */
4759 0x0200001f, 0x80010005, 0x900f0002, /* dcl_texcoord1 v2 */
4760 0x02000001, 0xc00f0000, 0x90e40000, /* mov o0, v0 */
4761 0x02000001, 0x800f0001, 0x90e40001, /* mov r1, v1 */
4762 0x03000002, 0xd00f0000, 0x80e40001, 0x91e40002, /* sub o1, r1, v2 */
4763 0x0000ffff /* end */
4765 DWORD texcoord_color_shader_code_3
[] = {
4766 0xfffe0300, /* vs_3_0 */
4767 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
4768 0x0200001f, 0x8000000a, 0xe00f0001, /* dcl_color o1 */
4769 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
4770 0x0200001f, 0x80000005, 0x900f0001, /* dcl_texcoord v1 */
4771 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
4772 0x02000001, 0xe00f0001, 0x90e40001, /* mov o1, v1 */
4773 0x0000ffff /* end */
4775 DWORD texcoord_color_shader_code_2
[] = {
4776 0xfffe0200, /* vs_2_0 */
4777 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
4778 0x0200001f, 0x80000005, 0x900f0001, /* dcl_texcoord v1 */
4779 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
4780 0x02000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
4781 0x0000ffff /* end */
4783 DWORD texcoord_color_shader_code_1
[] = {
4784 0xfffe0101, /* vs_1_1 */
4785 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
4786 0x0000001f, 0x80000005, 0x900f0001, /* dcl_texcoord v1 */
4787 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
4788 0x00000001, 0xd00f0000, 0x90e40001, /* mov oD0, v1 */
4789 0x0000ffff /* end */
4791 DWORD color_color_shader_code_3
[] = {
4792 0xfffe0300, /* vs_3_0 */
4793 0x0200001f, 0x80000000, 0xe00f0000, /* dcl_position o0 */
4794 0x0200001f, 0x8000000a, 0xe00f0001, /* dcl_color o1 */
4795 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
4796 0x0200001f, 0x8000000a, 0x900f0001, /* dcl_color v1 */
4797 0x02000001, 0xe00f0000, 0x90e40000, /* mov o0, v0 */
4798 0x03000005, 0xe00f0001, 0xa0e40000, 0x90e40001, /* mul o1, c0, v1 */
4799 0x0000ffff /* end */
4801 DWORD color_color_shader_code_2
[] = {
4802 0xfffe0200, /* vs_2_0 */
4803 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
4804 0x0200001f, 0x8000000a, 0x900f0001, /* dcl_color v1 */
4805 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
4806 0x03000005, 0xd00f0000, 0xa0e40000, 0x90e40001, /* mul oD0, c0, v1 */
4807 0x0000ffff /* end */
4809 DWORD color_color_shader_code_1
[] = {
4810 0xfffe0101, /* vs_1_1 */
4811 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
4812 0x0000001f, 0x8000000a, 0x900f0001, /* dcl_color v1 */
4813 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
4814 0x00000005, 0xd00f0000, 0xa0e40000, 0x90e40001, /* mul oD0, c0, v1 */
4815 0x0000ffff /* end */
4817 IDirect3DVertexShader9
*swapped_shader
, *texcoord_color_shader
, *color_color_shader
;
4819 DWORD color
, r
, g
, b
;
4821 -1.0, -1.0, 0.1, 1.0, 0.0, 1.0, 0.0, 0.0, -1.0, 0.5, 0.0,
4822 0.0, -1.0, 0.1, 1.0, 0.0, 1.0, 0.0, 0.0, -1.0, 0.5, 0.0,
4823 -1.0, 0.0, 0.1, 1.0, 0.0, 1.0, 0.0, 0.0, -1.0, 0.5, 0.0,
4824 0.0, 0.0, 0.1, 1.0, 0.0, 1.0, 0.0, 0.0, -1.0, 0.5, 0.0,
4827 0.0, -1.0, 0.1, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
4828 1.0, -1.0, 0.1, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
4829 0.0, 0.0, 0.1, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
4830 1.0, 0.0, 0.1, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
4833 -1.0, 0.0, 0.1, -1.0, 0.0, 0.0, 0.0, 1.0, -1.0, 0.0, 0.0,
4834 0.0, 0.0, 0.1, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0,
4835 -1.0, 1.0, 0.1, -1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 1.0, 0.0,
4836 0.0, 1.0, 0.1, -1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0,
4839 0.0, 0.0, 0.1, 1.0, 0.0, 1.0, 0.0, 0.0, -1.0, 0.5, 0.0,
4840 1.0, 0.0, 0.1, 1.0, 0.0, 1.0, 0.0, 0.0, -1.0, 0.5, 0.0,
4841 0.0, 1.0, 0.1, 1.0, 0.0, 1.0, 0.0, 0.0, -1.0, 0.5, 0.0,
4842 1.0, 1.0, 0.1, 1.0, 0.0, 1.0, 0.0, 0.0, -1.0, 0.5, 0.0,
4844 static const D3DVERTEXELEMENT9 decl_elements_twotexcrd
[] = {
4845 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
4846 {0, 12, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
4847 {0, 28, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 1},
4850 static const D3DVERTEXELEMENT9 decl_elements_twotexcrd_rightorder
[] = {
4851 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
4852 {0, 12, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 1},
4853 {0, 28, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
4856 static const D3DVERTEXELEMENT9 decl_elements_onetexcrd
[] = {
4857 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
4858 {0, 12, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
4861 static const D3DVERTEXELEMENT9 decl_elements_twotexcrd_wrongidx
[] = {
4862 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
4863 {0, 12, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 1},
4864 {0, 28, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 2},
4867 static const D3DVERTEXELEMENT9 decl_elements_texcoord_color
[] = {
4868 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
4869 {0, 12, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
4872 static const D3DVERTEXELEMENT9 decl_elements_color_color
[] = {
4873 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
4874 {0, 12, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
4877 static const D3DVERTEXELEMENT9 decl_elements_color_ubyte
[] = {
4878 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
4879 {0, 12, D3DDECLTYPE_UBYTE4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
4882 static const D3DVERTEXELEMENT9 decl_elements_color_float
[] = {
4883 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
4884 {0, 12, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
4887 IDirect3DVertexDeclaration9
*decl_twotexcrd
, *decl_onetexcrd
, *decl_twotex_wrongidx
, *decl_twotexcrd_rightorder
;
4888 IDirect3DVertexDeclaration9
*decl_texcoord_color
, *decl_color_color
, *decl_color_ubyte
, *decl_color_float
;
4890 float normalize
[4] = {1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0};
4891 float no_normalize
[4] = {1.0, 1.0, 1.0, 1.0};
4893 struct vertex quad1_color
[] = {
4894 {-1.0, -1.0, 0.1, 0x00ff8040},
4895 { 0.0, -1.0, 0.1, 0x00ff8040},
4896 {-1.0, 0.0, 0.1, 0x00ff8040},
4897 { 0.0, 0.0, 0.1, 0x00ff8040}
4899 struct vertex quad2_color
[] = {
4900 { 0.0, -1.0, 0.1, 0x00ff8040},
4901 { 1.0, -1.0, 0.1, 0x00ff8040},
4902 { 0.0, 0.0, 0.1, 0x00ff8040},
4903 { 1.0, 0.0, 0.1, 0x00ff8040}
4905 struct vertex quad3_color
[] = {
4906 {-1.0, 0.0, 0.1, 0x00ff8040},
4907 { 0.0, 0.0, 0.1, 0x00ff8040},
4908 {-1.0, 1.0, 0.1, 0x00ff8040},
4909 { 0.0, 1.0, 0.1, 0x00ff8040}
4911 float quad4_color
[] = {
4912 0.0, 0.0, 0.1, 1.0, 1.0, 0.0, 0.0,
4913 1.0, 0.0, 0.1, 1.0, 1.0, 0.0, 1.0,
4914 0.0, 1.0, 0.1, 1.0, 1.0, 0.0, 0.0,
4915 1.0, 1.0, 0.1, 1.0, 1.0, 0.0, 1.0,
4918 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_twotexcrd
, &decl_twotexcrd
);
4919 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
4920 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_onetexcrd
, &decl_onetexcrd
);
4921 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
4922 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_twotexcrd_wrongidx
, &decl_twotex_wrongidx
);
4923 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
4924 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_twotexcrd_rightorder
, &decl_twotexcrd_rightorder
);
4925 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
4927 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_texcoord_color
, &decl_texcoord_color
);
4928 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
4929 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_color_color
, &decl_color_color
);
4930 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
4931 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_color_ubyte
, &decl_color_ubyte
);
4932 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
4933 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_color_float
, &decl_color_float
);
4934 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
4936 for(i
= 1; i
<= 3; i
++) {
4937 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
4939 hr
= IDirect3DDevice9_CreateVertexShader(device
, swapped_shader_code_3
, &swapped_shader
);
4940 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %s\n", DXGetErrorString9(hr
));
4942 hr
= IDirect3DDevice9_CreateVertexShader(device
, swapped_shader_code_2
, &swapped_shader
);
4943 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %s\n", DXGetErrorString9(hr
));
4945 hr
= IDirect3DDevice9_CreateVertexShader(device
, swapped_shader_code_1
, &swapped_shader
);
4946 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %s\n", DXGetErrorString9(hr
));
4949 hr
= IDirect3DDevice9_BeginScene(device
);
4950 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
4953 hr
= IDirect3DDevice9_SetVertexShader(device
, swapped_shader
);
4954 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
4956 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl_twotexcrd
);
4957 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
4958 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(float) * 11);
4959 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
4961 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl_onetexcrd
);
4962 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
4963 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(float) * 11);
4964 if(i
== 3 || i
== 2) {
4965 ok(hr
== D3D_OK
, "DrawPrimitiveUP returned (%08x) i = %d\n", hr
, i
);
4967 /* Succeeds or fails, depending on SW or HW vertex processing */
4968 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "DrawPrimitiveUP returned (%08x), i = 1\n", hr
);
4971 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl_twotexcrd_rightorder
);
4972 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
4973 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, sizeof(float) * 11);
4974 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
4976 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl_twotex_wrongidx
);
4977 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
4978 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, sizeof(float) * 11);
4979 if(i
== 3 || i
== 2) {
4980 ok(hr
== D3D_OK
, "DrawPrimitiveUP returned (%08x) i = %d\n", hr
, i
);
4982 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "DrawPrimitiveUP returned (%08x) i = 1\n", hr
);
4985 hr
= IDirect3DDevice9_EndScene(device
);
4986 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
4989 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
4990 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
4992 if(i
== 3 || i
== 2) {
4993 color
= getPixelColor(device
, 160, 360);
4994 ok(color
== 0x00FFFF80 || color
== 0x00FFFF7f || color
== 0x00FFFF81,
4995 "Input test: Quad 1(2crd) returned color 0x%08x, expected 0x00FFFF80\n", color
);
4997 /* The last value of the read but undefined stream is used */
4998 color
= getPixelColor(device
, 480, 360);
4999 ok(color
== 0x00FFFF00, "Input test: Quad 2(1crd) returned color 0x%08x, expected 0x00FFFF00\n", color
);
5000 color
= getPixelColor(device
, 160, 120);
5001 ok(color
== 0x00FF0080 || color
== 0x00FF007f || color
== 0x00FF0081,
5002 "Input test: Quad 3(2crd-wrongidx) returned color 0x%08x, expected 0x00FF0080\n", color
);
5004 color
= getPixelColor(device
, 480, 160);
5005 ok(color
== 0x00000000, "Input test: Quad 4(2crd-rightorder) returned color 0x%08x, expected 0x00000000\n", color
);
5007 color
= getPixelColor(device
, 160, 360);
5008 ok(color
== 0x00FFFF80 || color
== 0x00FFFF7f || color
== 0x00FFFF81,
5009 "Input test: Quad 1(2crd) returned color 0x%08x, expected 0x00FFFF80\n", color
);
5010 color
= getPixelColor(device
, 480, 360);
5011 /* Accept the clear color as well in this case, since SW VP returns an error */
5012 ok(color
== 0x00FFFF00 || color
== 0x00FF0000, "Input test: Quad 2(1crd) returned color 0x%08x, expected 0x00FFFF00\n", color
);
5013 color
= getPixelColor(device
, 160, 120);
5014 ok(color
== 0x00FF0080 || color
== 0x00FF0000 || color
== 0x00FF007f || color
== 0x00FF0081,
5015 "Input test: Quad 3(2crd-wrongidx) returned color 0x%08x, expected 0x00FF0080\n", color
);
5016 color
= getPixelColor(device
, 480, 160);
5017 ok(color
== 0x00000000, "Input test: Quad 4(2crd-rightorder) returned color 0x%08x, expected 0x00000000\n", color
);
5020 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff808080, 0.0, 0);
5021 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %s\n", DXGetErrorString9(hr
));
5023 /* Now find out if the whole streams are re-read, or just the last active value for the
5026 hr
= IDirect3DDevice9_BeginScene(device
);
5027 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
5030 float quad1_modified
[] = {
5031 -1.0, -1.0, 0.1, 1.0, 0.0, 1.0, 0.0, -1.0, 0.0, 0.0, 0.0,
5032 0.0, -1.0, 0.1, 1.0, 0.0, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0,
5033 -1.0, 0.0, 0.1, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.0, 0.0,
5034 0.0, 0.0, 0.1, 1.0, 0.0, 1.0, 0.0, -1.0, -1.0, -1.0, 0.0,
5036 float quad2_modified
[] = {
5037 0.0, -1.0, 0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
5038 1.0, -1.0, 0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
5039 0.0, 0.0, 0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
5040 1.0, 0.0, 0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
5043 hr
= IDirect3DDevice9_SetVertexShader(device
, swapped_shader
);
5044 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
5046 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl_twotexcrd
);
5047 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
5048 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_POINTLIST
, 3, quad1_modified
, sizeof(float) * 11);
5049 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
5051 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl_onetexcrd
);
5052 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
5053 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2_modified
, sizeof(float) * 11);
5054 if(i
== 3 || i
== 2) {
5055 ok(hr
== D3D_OK
, "DrawPrimitiveUP returned (%08x) i = %d\n", hr
, i
);
5057 /* Succeeds or fails, depending on SW or HW vertex processing */
5058 ok(hr
== D3DERR_INVALIDCALL
|| hr
== D3D_OK
, "DrawPrimitiveUP returned (%08x), i = 1\n", hr
);
5061 hr
= IDirect3DDevice9_EndScene(device
);
5062 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
5064 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
5065 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
5067 color
= getPixelColor(device
, 480, 360);
5068 /* vs_1_1 may fail, accept the clear color
5070 * NOTE: This test fails on the reference rasterizer. In the refrast, the 4 vertices have different colors,
5071 * i.e., the whole old stream is read, and not just the last used attribute. Some games require that this
5072 * does *not* happen, otherwise they can crash because of a read from a bad pointer, so do not accept the
5075 * A test app for this behavior is Half Life 2 Episode 2 in dxlevel 95, and related games(Portal, TF2).
5077 ok(color
== 0x000000FF || color
== 0x00808080,
5078 "Input test: Quad 2(different colors) returned color 0x%08x, expected 0x000000FF\n", color
);
5079 color
= getPixelColor(device
, 160, 120);
5081 IDirect3DDevice9_SetVertexShader(device
, NULL
);
5082 IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
5084 IDirect3DVertexShader9_Release(swapped_shader
);
5087 for(i
= 1; i
<= 3; i
++) {
5088 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff0000ff, 0.0, 0);
5090 hr
= IDirect3DDevice9_CreateVertexShader(device
, texcoord_color_shader_code_3
, &texcoord_color_shader
);
5091 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %s\n", DXGetErrorString9(hr
));
5092 hr
= IDirect3DDevice9_CreateVertexShader(device
, color_color_shader_code_3
, &color_color_shader
);
5093 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %s\n", DXGetErrorString9(hr
));
5095 hr
= IDirect3DDevice9_CreateVertexShader(device
, texcoord_color_shader_code_2
, &texcoord_color_shader
);
5096 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %s\n", DXGetErrorString9(hr
));
5097 hr
= IDirect3DDevice9_CreateVertexShader(device
, color_color_shader_code_2
, &color_color_shader
);
5098 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %s\n", DXGetErrorString9(hr
));
5100 hr
= IDirect3DDevice9_CreateVertexShader(device
, texcoord_color_shader_code_1
, &texcoord_color_shader
);
5101 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %s\n", DXGetErrorString9(hr
));
5102 hr
= IDirect3DDevice9_CreateVertexShader(device
, color_color_shader_code_1
, &color_color_shader
);
5103 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %s\n", DXGetErrorString9(hr
));
5106 hr
= IDirect3DDevice9_BeginScene(device
);
5107 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
5110 hr
= IDirect3DDevice9_SetVertexShader(device
, texcoord_color_shader
);
5111 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
5112 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl_texcoord_color
);
5113 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
5114 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1_color
, sizeof(quad1_color
[0]));
5115 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
5117 hr
= IDirect3DDevice9_SetVertexShader(device
, color_color_shader
);
5118 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
5120 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 0, normalize
, 1);
5121 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
5122 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl_color_ubyte
);
5123 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
5124 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2_color
, sizeof(quad2_color
[0]));
5125 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
5127 hr
= IDirect3DDevice9_SetVertexShaderConstantF(device
, 0, no_normalize
, 1);
5128 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
5129 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl_color_color
);
5130 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
5131 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3_color
, sizeof(quad3_color
[0]));
5132 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
5134 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, decl_color_float
);
5135 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration returned %s\n", DXGetErrorString9(hr
));
5136 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4_color
, sizeof(float) * 7);
5137 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
5139 hr
= IDirect3DDevice9_EndScene(device
);
5140 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
5142 IDirect3DDevice9_SetVertexShader(device
, NULL
);
5143 IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
5145 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
5146 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
5148 color
= getPixelColor(device
, 160, 360);
5149 r
= (color
& 0x00ff0000) >> 16;
5150 g
= (color
& 0x0000ff00) >> 8;
5151 b
= (color
& 0x000000ff) >> 0;
5152 ok(r
>= 0xfe && r
<= 0xff && g
>= 0x7f && g
<= 0x81 && b
>= 0x3f && b
<= 0x41,
5153 "Input test: Quad 1(color-texcoord) returned color 0x%08x, expected 0x00ff8040\n", color
);
5154 color
= getPixelColor(device
, 480, 360);
5155 r
= (color
& 0x00ff0000) >> 16;
5156 g
= (color
& 0x0000ff00) >> 8;
5157 b
= (color
& 0x000000ff) >> 0;
5158 ok(r
>= 0x3f && r
<= 0x41 && g
>= 0x7f && g
<= 0x81 && b
>= 0xfe && b
<= 0xff,
5159 "Input test: Quad 2(color-ubyte) returned color 0x%08x, expected 0x004080ff\n", color
);
5160 color
= getPixelColor(device
, 160, 120);
5161 r
= (color
& 0x00ff0000) >> 16;
5162 g
= (color
& 0x0000ff00) >> 8;
5163 b
= (color
& 0x000000ff) >> 0;
5164 ok(r
>= 0xfe && r
<= 0xff && g
>= 0x7f && g
<= 0x81 && b
>= 0x3f && b
<= 0x41,
5165 "Input test: Quad 3(color-color) returned color 0x%08x, expected 0x00ff8040\n", color
);
5166 color
= getPixelColor(device
, 480, 160);
5167 r
= (color
& 0x00ff0000) >> 16;
5168 g
= (color
& 0x0000ff00) >> 8;
5169 b
= (color
& 0x000000ff) >> 0;
5170 ok(r
>= 0xfe && r
<= 0xff && g
>= 0xfe && g
<= 0xff && b
<= 0x01,
5171 "Input test: Quad 4(color-float) returned color 0x%08x, expected 0x00FFFF00\n", color
);
5173 IDirect3DVertexShader9_Release(texcoord_color_shader
);
5174 IDirect3DVertexShader9_Release(color_color_shader
);
5177 IDirect3DVertexDeclaration9_Release(decl_twotexcrd
);
5178 IDirect3DVertexDeclaration9_Release(decl_onetexcrd
);
5179 IDirect3DVertexDeclaration9_Release(decl_twotex_wrongidx
);
5180 IDirect3DVertexDeclaration9_Release(decl_twotexcrd_rightorder
);
5182 IDirect3DVertexDeclaration9_Release(decl_texcoord_color
);
5183 IDirect3DVertexDeclaration9_Release(decl_color_color
);
5184 IDirect3DVertexDeclaration9_Release(decl_color_ubyte
);
5185 IDirect3DVertexDeclaration9_Release(decl_color_float
);
5188 static void fog_srgbwrite_test(IDirect3DDevice9
*device
)
5190 /* Draw a black quad, half fogged with white fog -> grey color. Enable sRGB writing.
5191 * if sRGB writing is applied before fogging, the 0.0 will be multiplied with ~ 12.92, so still
5192 * stay 0.0. After that the fog gives 0.5. If sRGB writing is applied after fogging, the
5193 * 0.5 will run through the alternative path(0^5 ^ 0.41666 * 1.055 - 0.055), resulting in approx.
5196 * At the time of this writing, wined3d could not apply sRGB correction to fixed function rendering,
5197 * so use shaders for this task
5199 IDirect3DPixelShader9
*pshader
;
5200 IDirect3DVertexShader9
*vshader
;
5202 DWORD vshader_code
[] = {
5203 0xfffe0101, /* vs_1_1 */
5204 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
5205 0x00000051, 0xa00f0000, 0x3f000000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 0.5, 0.0, 0.0, 0.0 */
5206 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
5207 0x00000001, 0xc00f0001, 0xa0000000, /* mov oFog, c0.x */
5208 0x0000ffff /* end */
5210 DWORD pshader_code
[] = {
5211 0xffff0101, /* ps_1_1 */
5212 0x00000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 0.0, 0.0, 0.0, 0.0 */
5213 0x00000001, 0x800f0000, 0xa0e40000, /* mov r0, c0 */
5214 0x0000ffff /* end */
5216 const float quad
[] = {
5225 IDirect3DDevice9_GetDirect3D(device
, &d3d
);
5226 if(IDirect3D9_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5227 D3DUSAGE_RENDERTARGET
| D3DUSAGE_QUERY_SRGBWRITE
,
5228 D3DRTYPE_SURFACE
, D3DFMT_A8R8G8B8
) != D3D_OK
) {
5229 skip("No SRGBWRITEENABLE support on D3DFMT_X8R8G8B8\n");
5230 IDirect3D9_Release(d3d
);
5233 IDirect3D9_Release(d3d
);
5235 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffff00, 0.0, 0);
5236 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %s\n", DXGetErrorString9(hr
));
5238 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGENABLE
, TRUE
);
5239 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
5240 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGTABLEMODE
, D3DFOG_NONE
);
5241 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
5242 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGVERTEXMODE
, D3DFOG_LINEAR
);
5243 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
5244 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGCOLOR
, 0xffffffff);
5245 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
5246 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SRGBWRITEENABLE
, TRUE
);
5247 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
5249 hr
= IDirect3DDevice9_CreateVertexShader(device
, vshader_code
, &vshader
);
5250 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexShader returned %s\n", DXGetErrorString9(hr
));
5251 hr
= IDirect3DDevice9_CreatePixelShader(device
, pshader_code
, &pshader
);
5252 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader returned %s\n", DXGetErrorString9(hr
));
5253 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
5254 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF returned %s\n", DXGetErrorString9(hr
));
5255 hr
= IDirect3DDevice9_SetVertexShader(device
, vshader
);
5256 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
5257 hr
= IDirect3DDevice9_SetPixelShader(device
, pshader
);
5258 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
5260 hr
= IDirect3DDevice9_BeginScene(device
);
5261 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
5263 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(float) * 3);
5264 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
5266 hr
= IDirect3DDevice9_EndScene(device
);
5267 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
5270 hr
= IDirect3DDevice9_SetVertexShader(device
, NULL
);
5271 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexShader returned %s\n", DXGetErrorString9(hr
));
5272 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
5273 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader returned %s\n", DXGetErrorString9(hr
));
5274 IDirect3DPixelShader9_Release(pshader
);
5275 IDirect3DVertexShader9_Release(vshader
);
5277 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_FOGENABLE
, FALSE
);
5278 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
5279 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SRGBWRITEENABLE
, FALSE
);
5280 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
5282 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
5283 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
5284 color
= getPixelColor(device
, 160, 360);
5285 ok(color
== 0x00808080 || color
== 0x007f7f7f || color
== 0x00818181,
5286 "Fog with D3DRS_SRGBWRITEENABLE returned color 0x%08x, expected 0x00808080\n", color
);
5289 static void alpha_test(IDirect3DDevice9
*device
)
5292 IDirect3DTexture9
*offscreenTexture
;
5293 IDirect3DSurface9
*backbuffer
= NULL
, *offscreen
= NULL
;
5294 DWORD color
, red
, green
, blue
;
5296 struct vertex quad1
[] =
5298 {-1.0f
, -1.0f
, 0.1f
, 0x4000ff00},
5299 {-1.0f
, 0.0f
, 0.1f
, 0x4000ff00},
5300 { 1.0f
, -1.0f
, 0.1f
, 0x4000ff00},
5301 { 1.0f
, 0.0f
, 0.1f
, 0x4000ff00},
5303 struct vertex quad2
[] =
5305 {-1.0f
, 0.0f
, 0.1f
, 0xc00000ff},
5306 {-1.0f
, 1.0f
, 0.1f
, 0xc00000ff},
5307 { 1.0f
, 0.0f
, 0.1f
, 0xc00000ff},
5308 { 1.0f
, 1.0f
, 0.1f
, 0xc00000ff},
5310 static const float composite_quad
[][5] = {
5311 { 0.0f
, -1.0f
, 0.1f
, 0.0f
, 1.0f
},
5312 { 0.0f
, 1.0f
, 0.1f
, 0.0f
, 0.0f
},
5313 { 1.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
},
5314 { 1.0f
, 1.0f
, 0.1f
, 1.0f
, 0.0f
},
5317 /* Clear the render target with alpha = 0.5 */
5318 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x80ff0000, 0.0, 0);
5319 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
5321 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &offscreenTexture
, NULL
);
5322 ok(hr
== D3D_OK
|| D3DERR_INVALIDCALL
, "Creating the offscreen render target failed, hr = %#08x\n", hr
);
5324 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
5325 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %s\n", DXGetErrorString9(hr
));
5330 hr
= IDirect3DTexture9_GetSurfaceLevel(offscreenTexture
, 0, &offscreen
);
5331 ok(hr
== D3D_OK
, "Can't get offscreen surface, hr = %s\n", DXGetErrorString9(hr
));
5336 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
5337 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed, hr = %#08x\n", hr
);
5339 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
5340 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %s\n", DXGetErrorString9(hr
));
5341 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
5342 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %s\n", DXGetErrorString9(hr
));
5343 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MINFILTER
, D3DTEXF_POINT
);
5344 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_MINFILTER failed (0x%08x)\n", hr
);
5345 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_MAGFILTER
, D3DTEXF_POINT
);
5346 ok(SUCCEEDED(hr
), "SetSamplerState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr
);
5347 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
5348 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
5350 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, TRUE
);
5351 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed, hr = %08x\n", hr
);
5352 if(IDirect3DDevice9_BeginScene(device
) == D3D_OK
) {
5354 /* Draw two quads, one with src alpha blending, one with dest alpha blending. The
5355 * SRCALPHA / INVSRCALPHA blend doesn't give any surprises. Colors are blended based on
5358 * The DESTALPHA / INVDESTALPHA do not "work" on the regular buffer because there is no alpha.
5359 * They give essentially ZERO and ONE blend factors
5361 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_SRCALPHA
);
5362 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed, hr = %08x\n", hr
);
5363 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
5364 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed, hr = %08x\n", hr
);
5365 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(quad1
[0]));
5366 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
5368 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_DESTALPHA
);
5369 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed, hr = %08x\n", hr
);
5370 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVDESTALPHA
);
5371 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed, hr = %08x\n", hr
);
5372 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(quad2
[0]));
5373 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
5375 /* Switch to the offscreen buffer, and redo the testing. SRCALPHA and DESTALPHA. The offscreen buffer
5376 * has a alpha channel on its own. Clear the offscreen buffer with alpha = 0.5 again, then draw the
5377 * quads again. The SRCALPHA/INVSRCALPHA doesn't give any surprises, but the DESTALPHA/INVDESTALPHA
5378 * blending works as supposed now - blend factor is 0.5 in both cases, not 0.75 as from the input
5381 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, offscreen
);
5382 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %08x\n", hr
);
5383 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x80ff0000, 0.0, 0);
5384 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
5386 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_SRCALPHA
);
5387 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed, hr = %08x\n", hr
);
5388 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
5389 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed, hr = %08x\n", hr
);
5390 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(quad1
[0]));
5391 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
5393 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_SRCBLEND
, D3DBLEND_DESTALPHA
);
5394 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed, hr = %08x\n", hr
);
5395 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_DESTBLEND
, D3DBLEND_INVDESTALPHA
);
5396 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed, hr = %08x\n", hr
);
5397 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(quad2
[0]));
5398 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
5400 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
5401 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %08x\n", hr
);
5403 /* Render the offscreen texture onto the frame buffer to be able to compare it regularly.
5404 * Disable alpha blending for the final composition
5406 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_ALPHABLENDENABLE
, FALSE
);
5407 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState failed, hr = %08x\n", hr
);
5408 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
5409 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed, hr = %#08x\n", hr
);
5411 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) offscreenTexture
);
5412 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture failed, hr = %08x\n", hr
);
5413 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, composite_quad
, sizeof(float) * 5);
5414 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
5415 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
5416 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture failed, hr = %08x\n", hr
);
5418 hr
= IDirect3DDevice9_EndScene(device
);
5419 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndScene failed, hr = %08x\n", hr
);
5422 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
5424 color
= getPixelColor(device
, 160, 360);
5425 red
= (color
& 0x00ff0000) >> 16;
5426 green
= (color
& 0x0000ff00) >> 8;
5427 blue
= (color
& 0x000000ff);
5428 ok(red
>= 0xbe && red
<= 0xc0 && green
>= 0x39 && green
<= 0x41 && blue
== 0x00,
5429 "SRCALPHA on frame buffer returned color %08x, expected 0x00bf4000\n", color
);
5431 color
= getPixelColor(device
, 160, 120);
5432 red
= (color
& 0x00ff0000) >> 16;
5433 green
= (color
& 0x0000ff00) >> 8;
5434 blue
= (color
& 0x000000ff);
5435 ok(red
== 0x00 && green
== 0x00 && blue
>= 0xfe && blue
<= 0xff ,
5436 "DSTALPHA on frame buffer returned color %08x, expected 0x00ff0000\n", color
);
5438 color
= getPixelColor(device
, 480, 360);
5439 red
= (color
& 0x00ff0000) >> 16;
5440 green
= (color
& 0x0000ff00) >> 8;
5441 blue
= (color
& 0x000000ff);
5442 ok(red
>= 0xbe && red
<= 0xc0 && green
>= 0x39 && green
<= 0x41 && blue
== 0x00,
5443 "SRCALPHA on texture returned color %08x, expected bar\n", color
);
5445 color
= getPixelColor(device
, 480, 120);
5446 red
= (color
& 0x00ff0000) >> 16;
5447 green
= (color
& 0x0000ff00) >> 8;
5448 blue
= (color
& 0x000000ff);
5449 ok(red
>= 0x7e && red
<= 0x81 && green
== 0x00 && blue
>= 0x7e && blue
<= 0x81,
5450 "DSTALPHA on texture returned color %08x, expected foo\n", color
);
5453 /* restore things */
5455 IDirect3DSurface9_Release(backbuffer
);
5457 if(offscreenTexture
) {
5458 IDirect3DTexture9_Release(offscreenTexture
);
5461 IDirect3DSurface9_Release(offscreen
);
5465 struct vertex_shortcolor
{
5467 unsigned short r
, g
, b
, a
;
5469 struct vertex_floatcolor
{
5474 static void fixed_function_decl_test(IDirect3DDevice9
*device
)
5477 BOOL s_ok
, ub_ok
, f_ok
;
5478 DWORD color
, size
, i
;
5480 static const D3DVERTEXELEMENT9 decl_elements_d3dcolor
[] = {
5481 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
5482 {0, 12, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
5485 static const D3DVERTEXELEMENT9 decl_elements_d3dcolor_2streams
[] = {
5486 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
5487 {1, 0, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
5490 static const D3DVERTEXELEMENT9 decl_elements_ubyte4n
[] = {
5491 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
5492 {0, 12, D3DDECLTYPE_UBYTE4N
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
5495 static const D3DVERTEXELEMENT9 decl_elements_ubyte4n_2streams
[] = {
5496 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
5497 {1, 0, D3DDECLTYPE_UBYTE4N
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
5500 static const D3DVERTEXELEMENT9 decl_elements_short4
[] = {
5501 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
5502 {0, 12, D3DDECLTYPE_USHORT4N
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
5505 static const D3DVERTEXELEMENT9 decl_elements_float
[] = {
5506 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
5507 {0, 12, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
5510 static const D3DVERTEXELEMENT9 decl_elements_positiont
[] = {
5511 {0, 0, D3DDECLTYPE_FLOAT4
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITIONT
, 0},
5512 {0, 16, D3DDECLTYPE_D3DCOLOR
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
5515 IDirect3DVertexDeclaration9
*dcl_float
= NULL
, *dcl_short
= NULL
, *dcl_ubyte
= NULL
, *dcl_color
= NULL
;
5516 IDirect3DVertexDeclaration9
*dcl_color_2
= NULL
, *dcl_ubyte_2
= NULL
, *dcl_positiont
;
5517 IDirect3DVertexBuffer9
*vb
, *vb2
;
5518 struct vertex quad1
[] = /* D3DCOLOR */
5520 {-1.0f
, -1.0f
, 0.1f
, 0x00ffff00},
5521 {-1.0f
, 0.0f
, 0.1f
, 0x00ffff00},
5522 { 0.0f
, -1.0f
, 0.1f
, 0x00ffff00},
5523 { 0.0f
, 0.0f
, 0.1f
, 0x00ffff00},
5525 struct vertex quad2
[] = /* UBYTE4N */
5527 {-1.0f
, 0.0f
, 0.1f
, 0x00ffff00},
5528 {-1.0f
, 1.0f
, 0.1f
, 0x00ffff00},
5529 { 0.0f
, 0.0f
, 0.1f
, 0x00ffff00},
5530 { 0.0f
, 1.0f
, 0.1f
, 0x00ffff00},
5532 struct vertex_shortcolor quad3
[] = /* short */
5534 { 0.0f
, -1.0f
, 0.1f
, 0x0000, 0x0000, 0xffff, 0xffff},
5535 { 0.0f
, 0.0f
, 0.1f
, 0x0000, 0x0000, 0xffff, 0xffff},
5536 { 1.0f
, -1.0f
, 0.1f
, 0x0000, 0x0000, 0xffff, 0xffff},
5537 { 1.0f
, 0.0f
, 0.1f
, 0x0000, 0x0000, 0xffff, 0xffff},
5539 struct vertex_floatcolor quad4
[] =
5541 { 0.0f
, 0.0f
, 0.1f
, 1.0, 0.0, 0.0, 0.0},
5542 { 0.0f
, 1.0f
, 0.1f
, 1.0, 0.0, 0.0, 0.0},
5543 { 1.0f
, 0.0f
, 0.1f
, 1.0, 0.0, 0.0, 0.0},
5544 { 1.0f
, 1.0f
, 0.1f
, 1.0, 0.0, 0.0, 0.0},
5547 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
5548 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
5549 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
5550 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
5551 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
5552 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
5553 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
5554 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
5555 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
5556 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
5557 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
5558 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
5559 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
5560 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
5561 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
5562 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ffffff,
5585 struct tvertex quad_transformed
[] = {
5586 { 90, 110, 0.1, 2.0, 0x00ffff00},
5587 { 570, 110, 0.1, 2.0, 0x00ffff00},
5588 { 90, 300, 0.1, 2.0, 0x00ffff00},
5589 { 570, 300, 0.1, 2.0, 0x00ffff00}
5593 memset(&caps
, 0, sizeof(caps
));
5594 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
5595 ok(hr
== D3D_OK
, "GetDeviceCaps failed, hr = %08x\n", hr
);
5597 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
5598 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
5600 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_d3dcolor
, &dcl_color
);
5601 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (%08x)\n", hr
);
5602 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_short4
, &dcl_short
);
5603 ok(SUCCEEDED(hr
) || hr
== E_FAIL
, "CreateVertexDeclaration failed (%08x)\n", hr
);
5604 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_float
, &dcl_float
);
5605 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (%08x)\n", hr
);
5606 if(caps
.DeclTypes
& D3DDTCAPS_UBYTE4N
) {
5607 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_ubyte4n_2streams
, &dcl_ubyte_2
);
5608 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (%08x)\n", hr
);
5609 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_ubyte4n
, &dcl_ubyte
);
5610 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (%08x)\n", hr
);
5612 trace("D3DDTCAPS_UBYTE4N not supported\n");
5616 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_d3dcolor_2streams
, &dcl_color_2
);
5617 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (%08x)\n", hr
);
5618 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements_positiont
, &dcl_positiont
);
5619 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (%08x)\n", hr
);
5621 size
= max(sizeof(quad1
), max(sizeof(quad2
), max(sizeof(quad3
), max(sizeof(quad4
), sizeof(quads
)))));
5622 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, size
,
5623 0, 0, D3DPOOL_MANAGED
, &vb
, NULL
);
5624 ok(hr
== D3D_OK
, "CreateVertexBuffer failed with %s\n", DXGetErrorString9(hr
));
5626 hr
= IDirect3DDevice9_BeginScene(device
);
5627 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed (%08x)\n", hr
);
5628 f_ok
= FALSE
; s_ok
= FALSE
; ub_ok
= FALSE
;
5631 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_color
);
5632 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed (%08x)\n", hr
);
5633 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad1
, sizeof(quad1
[0]));
5634 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
5637 /* Tests with non-standard fixed function types fail on the refrast. The ATI driver partially
5638 * accepts them, the nvidia driver accepts them all. All those differences even though we're
5639 * using software vertex processing. Doh!
5642 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_ubyte
);
5643 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed (%08x)\n", hr
);
5644 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad2
, sizeof(quad2
[0]));
5645 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
5646 ub_ok
= SUCCEEDED(hr
);
5650 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_short
);
5651 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed (%08x)\n", hr
);
5652 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad3
, sizeof(quad3
[0]));
5653 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
5654 s_ok
= SUCCEEDED(hr
);
5658 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_float
);
5659 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed (%08x)\n", hr
);
5660 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad4
, sizeof(quad4
[0]));
5661 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "DrawPrimitiveUP failed, hr = %#08x\n", hr
);
5662 f_ok
= SUCCEEDED(hr
);
5665 hr
= IDirect3DDevice9_EndScene(device
);
5666 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed, hr = %#08x\n", hr
);
5669 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
5671 color
= getPixelColor(device
, 480, 360);
5672 ok(color
== 0x000000ff || !s_ok
,
5673 "D3DDECLTYPE_USHORT4N returned color %08x, expected 0x000000ff\n", color
);
5676 color
= getPixelColor(device
, 160, 120);
5677 ok(color
== 0x0000ffff || !ub_ok
,
5678 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x0000ffff\n", color
);
5681 color
= getPixelColor(device
, 160, 360);
5682 ok(color
== 0x00ffff00,
5683 "D3DDECLTYPE_D3DCOLOR returned color %08x, expected 0x00ffff00\n", color
);
5686 color
= getPixelColor(device
, 480, 120);
5687 ok(color
== 0x00ff0000 || !f_ok
,
5688 "D3DDECLTYPE_FLOAT4 returned color %08x, expected 0x00ff0000\n", color
);
5691 /* The following test with vertex buffers doesn't serve to find out new information from windows.
5692 * It is a plain regression test because wined3d uses different codepaths for attribute conversion
5693 * with vertex buffers. It makes sure that the vertex buffer one works, while the above tests
5694 * whether the immediate mode code works
5696 f_ok
= FALSE
; s_ok
= FALSE
; ub_ok
= FALSE
;
5697 hr
= IDirect3DDevice9_BeginScene(device
);
5698 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed (%08x)\n", hr
);
5701 hr
= IDirect3DVertexBuffer9_Lock(vb
, 0, sizeof(quad1
), (void **) &data
, 0);
5702 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Lock failed with %s\n", DXGetErrorString9(hr
));
5703 memcpy(data
, quad1
, sizeof(quad1
));
5704 hr
= IDirect3DVertexBuffer9_Unlock(vb
);
5705 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Unlock failed (%08x)\n", hr
);
5706 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_color
);
5707 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed (%08x)\n", hr
);
5708 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vb
, 0, sizeof(quad1
[0]));
5709 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetStreamSource failed with %s\n", DXGetErrorString9(hr
));
5710 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 0, 2);
5711 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawPrimitive failed, hr = %#08x\n", hr
);
5715 hr
= IDirect3DVertexBuffer9_Lock(vb
, 0, sizeof(quad2
), (void **) &data
, 0);
5716 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Lock failed with %s\n", DXGetErrorString9(hr
));
5717 memcpy(data
, quad2
, sizeof(quad2
));
5718 hr
= IDirect3DVertexBuffer9_Unlock(vb
);
5719 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Unlock failed (%08x)\n", hr
);
5720 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_ubyte
);
5721 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed (%08x)\n", hr
);
5722 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vb
, 0, sizeof(quad2
[0]));
5723 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetStreamSource failed with %s\n", DXGetErrorString9(hr
));
5724 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 0, 2);
5725 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
,
5726 "IDirect3DDevice9_DrawPrimitive failed, hr = %#08x\n", hr
);
5727 ub_ok
= SUCCEEDED(hr
);
5731 hr
= IDirect3DVertexBuffer9_Lock(vb
, 0, sizeof(quad3
), (void **) &data
, 0);
5732 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Lock failed with %s\n", DXGetErrorString9(hr
));
5733 memcpy(data
, quad3
, sizeof(quad3
));
5734 hr
= IDirect3DVertexBuffer9_Unlock(vb
);
5735 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Unlock failed (%08x)\n", hr
);
5736 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_short
);
5737 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed (%08x)\n", hr
);
5738 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vb
, 0, sizeof(quad3
[0]));
5739 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetStreamSource failed with %s\n", DXGetErrorString9(hr
));
5740 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 0, 2);
5741 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
,
5742 "IDirect3DDevice9_DrawPrimitive failed, hr = %#08x\n", hr
);
5743 s_ok
= SUCCEEDED(hr
);
5747 hr
= IDirect3DVertexBuffer9_Lock(vb
, 0, sizeof(quad4
), (void **) &data
, 0);
5748 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Lock failed with %s\n", DXGetErrorString9(hr
));
5749 memcpy(data
, quad4
, sizeof(quad4
));
5750 hr
= IDirect3DVertexBuffer9_Unlock(vb
);
5751 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Unlock failed (%08x)\n", hr
);
5752 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_float
);
5753 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed (%08x)\n", hr
);
5754 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vb
, 0, sizeof(quad4
[0]));
5755 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetStreamSource failed with %s\n", DXGetErrorString9(hr
));
5756 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 0, 2);
5757 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
,
5758 "IDirect3DDevice9_DrawPrimitive failed, hr = %#08x\n", hr
);
5759 f_ok
= SUCCEEDED(hr
);
5762 hr
= IDirect3DDevice9_EndScene(device
);
5763 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed, hr = %#08x\n", hr
);
5766 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 0, 0);
5767 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetStreamSource failed with %s\n", DXGetErrorString9(hr
));
5768 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
5769 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed (%08x)\n", hr
);
5771 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
5773 color
= getPixelColor(device
, 480, 360);
5774 ok(color
== 0x000000ff || !s_ok
,
5775 "D3DDECLTYPE_USHORT4N returned color %08x, expected 0x000000ff\n", color
);
5778 color
= getPixelColor(device
, 160, 120);
5779 ok(color
== 0x0000ffff || !ub_ok
,
5780 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x0000ffff\n", color
);
5783 color
= getPixelColor(device
, 160, 360);
5784 ok(color
== 0x00ffff00,
5785 "D3DDECLTYPE_D3DCOLOR returned color %08x, expected 0x00ffff00\n", color
);
5788 color
= getPixelColor(device
, 480, 120);
5789 ok(color
== 0x00ff0000 || !f_ok
,
5790 "D3DDECLTYPE_FLOAT4 returned color %08x, expected 0x00ff0000\n", color
);
5793 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff0000ff, 0.0, 0);
5794 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %s\n", DXGetErrorString9(hr
));
5796 hr
= IDirect3DVertexBuffer9_Lock(vb
, 0, sizeof(quad_transformed
), (void **) &data
, 0);
5797 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Lock failed with %s\n", DXGetErrorString9(hr
));
5798 memcpy(data
, quad_transformed
, sizeof(quad_transformed
));
5799 hr
= IDirect3DVertexBuffer9_Unlock(vb
);
5800 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Unlock failed (%08x)\n", hr
);
5802 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_positiont
);
5803 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed with %s\n", DXGetErrorString9(hr
));
5805 hr
= IDirect3DDevice9_BeginScene(device
);
5806 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed with %s\n", DXGetErrorString9(hr
));
5808 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vb
, 0, sizeof(quad_transformed
[0]));
5809 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetStreamSource failed with %s\n", DXGetErrorString9(hr
));
5810 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 0, 2);
5811 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawPrimitive failed, hr = %#08x\n", hr
);
5813 hr
= IDirect3DDevice9_EndScene(device
);
5814 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed with %s\n", DXGetErrorString9(hr
));
5817 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
5818 color
= getPixelColor(device
, 88, 108);
5819 ok(color
== 0x000000ff,
5820 "pixel 88/108 has color %08x, expected 0x000000ff\n", color
);
5821 color
= getPixelColor(device
, 92, 108);
5822 ok(color
== 0x000000ff,
5823 "pixel 92/108 has color %08x, expected 0x000000ff\n", color
);
5824 color
= getPixelColor(device
, 88, 112);
5825 ok(color
== 0x000000ff,
5826 "pixel 88/112 has color %08x, expected 0x000000ff\n", color
);
5827 color
= getPixelColor(device
, 92, 112);
5828 ok(color
== 0x00ffff00,
5829 "pixel 92/112 has color %08x, expected 0x00ffff00\n", color
);
5831 color
= getPixelColor(device
, 568, 108);
5832 ok(color
== 0x000000ff,
5833 "pixel 568/108 has color %08x, expected 0x000000ff\n", color
);
5834 color
= getPixelColor(device
, 572, 108);
5835 ok(color
== 0x000000ff,
5836 "pixel 572/108 has color %08x, expected 0x000000ff\n", color
);
5837 color
= getPixelColor(device
, 568, 112);
5838 ok(color
== 0x00ffff00,
5839 "pixel 568/112 has color %08x, expected 0x00ffff00\n", color
);
5840 color
= getPixelColor(device
, 572, 112);
5841 ok(color
== 0x000000ff,
5842 "pixel 572/112 has color %08x, expected 0x000000ff\n", color
);
5844 color
= getPixelColor(device
, 88, 298);
5845 ok(color
== 0x000000ff,
5846 "pixel 88/298 has color %08x, expected 0x000000ff\n", color
);
5847 color
= getPixelColor(device
, 92, 298);
5848 ok(color
== 0x00ffff00,
5849 "pixel 92/298 has color %08x, expected 0x00ffff00\n", color
);
5850 color
= getPixelColor(device
, 88, 302);
5851 ok(color
== 0x000000ff,
5852 "pixel 88/302 has color %08x, expected 0x000000ff\n", color
);
5853 color
= getPixelColor(device
, 92, 302);
5854 ok(color
== 0x000000ff,
5855 "pixel 92/302 has color %08x, expected 0x000000ff\n", color
);
5857 color
= getPixelColor(device
, 568, 298);
5858 ok(color
== 0x00ffff00,
5859 "pixel 568/298 has color %08x, expected 0x00ffff00\n", color
);
5860 color
= getPixelColor(device
, 572, 298);
5861 ok(color
== 0x000000ff,
5862 "pixel 572/298 has color %08x, expected 0x000000ff\n", color
);
5863 color
= getPixelColor(device
, 568, 302);
5864 ok(color
== 0x000000ff,
5865 "pixel 568/302 has color %08x, expected 0x000000ff\n", color
);
5866 color
= getPixelColor(device
, 572, 302);
5867 ok(color
== 0x000000ff,
5868 "pixel 572/302 has color %08x, expected 0x000000ff\n", color
);
5870 /* This test is pointless without those two declarations: */
5871 if((!dcl_color_2
) || (!dcl_ubyte_2
)) {
5872 skip("color-ubyte switching test declarations aren't supported\n");
5876 hr
= IDirect3DVertexBuffer9_Lock(vb
, 0, sizeof(quads
), (void **) &data
, 0);
5877 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Lock failed with %s\n", DXGetErrorString9(hr
));
5878 memcpy(data
, quads
, sizeof(quads
));
5879 hr
= IDirect3DVertexBuffer9_Unlock(vb
);
5880 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Unlock failed (%08x)\n", hr
);
5881 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, sizeof(colors
),
5882 0, 0, D3DPOOL_MANAGED
, &vb2
, NULL
);
5883 ok(hr
== D3D_OK
, "CreateVertexBuffer failed with %s\n", DXGetErrorString9(hr
));
5884 hr
= IDirect3DVertexBuffer9_Lock(vb2
, 0, sizeof(colors
), (void **) &data
, 0);
5885 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Lock failed with %s\n", DXGetErrorString9(hr
));
5886 memcpy(data
, colors
, sizeof(colors
));
5887 hr
= IDirect3DVertexBuffer9_Unlock(vb2
);
5888 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Unlock failed (%08x)\n", hr
);
5890 for(i
= 0; i
< 2; i
++) {
5891 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
5892 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed with %s\n", DXGetErrorString9(hr
));
5894 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, vb
, 0, sizeof(float) * 3);
5895 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetStreamSource failed with %s\n", DXGetErrorString9(hr
));
5897 hr
= IDirect3DDevice9_SetStreamSource(device
, 1, vb2
, 0, sizeof(DWORD
) * 4);
5899 hr
= IDirect3DDevice9_SetStreamSource(device
, 1, vb2
, 8, sizeof(DWORD
) * 4);
5901 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetStreamSource failed with %s\n", DXGetErrorString9(hr
));
5903 hr
= IDirect3DDevice9_BeginScene(device
);
5904 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed with %s\n", DXGetErrorString9(hr
));
5907 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_ubyte_2
);
5908 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed with %s\n", DXGetErrorString9(hr
));
5909 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 0, 2);
5910 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
,
5911 "IDirect3DDevice9_DrawPrimitive failed, hr = %#08x\n", hr
);
5912 ub_ok
= SUCCEEDED(hr
);
5914 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_color_2
);
5915 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed with %s\n", DXGetErrorString9(hr
));
5916 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 4, 2);
5917 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawPrimitive failed, hr = %#08x\n", hr
);
5919 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, dcl_ubyte_2
);
5920 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed with %s\n", DXGetErrorString9(hr
));
5921 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 8, 2);
5922 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
,
5923 "IDirect3DDevice9_DrawPrimitive failed, hr = %#08x\n", hr
);
5924 ub_ok
= (SUCCEEDED(hr
) && ub_ok
);
5926 hr
= IDirect3DDevice9_EndScene(device
);
5927 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed with %s\n", DXGetErrorString9(hr
));
5930 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
5932 color
= getPixelColor(device
, 480, 360);
5933 ok(color
== 0x00ff0000,
5934 "D3DDECLTYPE_D3DCOLOR returned color %08x, expected 0x00ff0000\n", color
);
5935 color
= getPixelColor(device
, 160, 120);
5936 ok(color
== 0x00ffffff,
5937 "Unused quad returned color %08x, expected 0x00ffffff\n", color
);
5938 color
= getPixelColor(device
, 160, 360);
5939 ok(color
== 0x000000ff || !ub_ok
,
5940 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x000000ff\n", color
);
5941 color
= getPixelColor(device
, 480, 120);
5942 ok(color
== 0x000000ff || !ub_ok
,
5943 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x000000ff\n", color
);
5945 color
= getPixelColor(device
, 480, 360);
5946 ok(color
== 0x000000ff,
5947 "D3DDECLTYPE_D3DCOLOR returned color %08x, expected 0x000000ff\n", color
);
5948 color
= getPixelColor(device
, 160, 120);
5949 ok(color
== 0x00ffffff,
5950 "Unused quad returned color %08x, expected 0x00ffffff\n", color
);
5951 color
= getPixelColor(device
, 160, 360);
5952 ok(color
== 0x00ff0000 || !ub_ok
,
5953 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x00ff0000\n", color
);
5954 color
= getPixelColor(device
, 480, 120);
5955 ok(color
== 0x00ff0000 || !ub_ok
,
5956 "D3DDECLTYPE_UBYTE4N returned color %08x, expected 0x00ff0000\n", color
);
5960 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 0, 0);
5961 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetStreamSource failed with %s\n", DXGetErrorString9(hr
));
5962 hr
= IDirect3DDevice9_SetStreamSource(device
, 1, NULL
, 0, 0);
5963 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetStreamSource failed with %s\n", DXGetErrorString9(hr
));
5964 IDirect3DVertexBuffer9_Release(vb2
);
5967 IDirect3DVertexBuffer9_Release(vb
);
5968 if(dcl_float
) IDirect3DVertexDeclaration9_Release(dcl_float
);
5969 if(dcl_short
) IDirect3DVertexDeclaration9_Release(dcl_short
);
5970 if(dcl_ubyte
) IDirect3DVertexDeclaration9_Release(dcl_ubyte
);
5971 if(dcl_color
) IDirect3DVertexDeclaration9_Release(dcl_color
);
5972 if(dcl_color_2
) IDirect3DVertexDeclaration9_Release(dcl_color_2
);
5973 if(dcl_ubyte_2
) IDirect3DVertexDeclaration9_Release(dcl_ubyte_2
);
5974 if(dcl_positiont
) IDirect3DVertexDeclaration9_Release(dcl_positiont
);
5977 struct vertex_float16color
{
5982 static void test_vshader_float16(IDirect3DDevice9
*device
)
5987 static const D3DVERTEXELEMENT9 decl_elements
[] = {
5988 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
5989 {0, 12, D3DDECLTYPE_FLOAT16_4
,D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_COLOR
, 0},
5992 IDirect3DVertexDeclaration9
*vdecl
= NULL
;
5993 IDirect3DVertexBuffer9
*buffer
= NULL
;
5994 IDirect3DVertexShader9
*shader
;
5995 DWORD shader_code
[] = {
5996 0xfffe0101, 0x0000001f, 0x80000000, 0x900f0000, 0x0000001f, 0x8000000a,
5997 0x900f0001, 0x00000001, 0xc00f0000, 0x90e40000, 0x00000001, 0xd00f0000,
5998 0x90e40001, 0x0000ffff
6000 struct vertex_float16color quad
[] = {
6001 { -1.0, -1.0, 0.1, 0x3c000000, 0x00000000 }, /* green */
6002 { -1.0, 0.0, 0.1, 0x3c000000, 0x00000000 },
6003 { 0.0, -1.0, 0.1, 0x3c000000, 0x00000000 },
6004 { 0.0, 0.0, 0.1, 0x3c000000, 0x00000000 },
6006 { 0.0, -1.0, 0.1, 0x00003c00, 0x00000000 }, /* red */
6007 { 0.0, 0.0, 0.1, 0x00003c00, 0x00000000 },
6008 { 1.0, -1.0, 0.1, 0x00003c00, 0x00000000 },
6009 { 1.0, 0.0, 0.1, 0x00003c00, 0x00000000 },
6011 { 0.0, 0.0, 0.1, 0x00000000, 0x00003c00 }, /* blue */
6012 { 0.0, 1.0, 0.1, 0x00000000, 0x00003c00 },
6013 { 1.0, 0.0, 0.1, 0x00000000, 0x00003c00 },
6014 { 1.0, 1.0, 0.1, 0x00000000, 0x00003c00 },
6016 { -1.0, 0.0, 0.1, 0x00000000, 0x3c000000 }, /* alpha */
6017 { -1.0, 1.0, 0.1, 0x00000000, 0x3c000000 },
6018 { 0.0, 0.0, 0.1, 0x00000000, 0x3c000000 },
6019 { 0.0, 1.0, 0.1, 0x00000000, 0x3c000000 },
6022 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff102030, 0.0, 0);
6023 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed, hr=%s\n", DXGetErrorString9(hr
));
6025 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &vdecl
);
6026 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateVertexDeclaration failed hr=%s\n", DXGetErrorString9(hr
));
6027 hr
= IDirect3DDevice9_CreateVertexShader(device
, shader_code
, &shader
);
6028 ok(SUCCEEDED(hr
), "IDirect3DDevice9_CreateVertexShader failed hr=%s\n", DXGetErrorString9(hr
));
6029 IDirect3DDevice9_SetVertexShader(device
, shader
);
6030 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShader failed hr=%s\n", DXGetErrorString9(hr
));
6032 hr
= IDirect3DDevice9_BeginScene(device
);
6033 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed hr=%s\n", DXGetErrorString9(hr
));
6035 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, vdecl
);
6036 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed, hr=%s\n", DXGetErrorString9(hr
));
6037 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
+ 0, sizeof(quad
[0]));
6038 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawPrimitiveUP failed, hr=%s\n", DXGetErrorString9(hr
));
6039 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
+ 4, sizeof(quad
[0]));
6040 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawPrimitiveUP failed, hr=%s\n", DXGetErrorString9(hr
));
6041 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
+ 8, sizeof(quad
[0]));
6042 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawPrimitiveUP failed, hr=%s\n", DXGetErrorString9(hr
));
6043 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
+ 12, sizeof(quad
[0]));
6044 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawPrimitiveUP failed, hr=%s\n", DXGetErrorString9(hr
));
6046 hr
= IDirect3DDevice9_EndScene(device
);
6047 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed, hr=%s\n", DXGetErrorString9(hr
));
6049 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
6050 color
= getPixelColor(device
, 480, 360);
6051 ok(color
== 0x00ff0000,
6052 "Input 0x00003c00, 0x00000000 returned color %08x, expected 0x00ff0000\n", color
);
6053 color
= getPixelColor(device
, 160, 120);
6054 ok(color
== 0x00000000,
6055 "Input 0x00000000, 0x3c000000 returned color %08x, expected 0x00000000\n", color
);
6056 color
= getPixelColor(device
, 160, 360);
6057 ok(color
== 0x0000ff00,
6058 "Input 0x3c000000, 0x00000000 returned color %08x, expected 0x0000ff00\n", color
);
6059 color
= getPixelColor(device
, 480, 120);
6060 ok(color
== 0x000000ff,
6061 "Input 0x00000000, 0x00003c00 returned color %08x, expected 0x000000ff\n", color
);
6063 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff102030, 0.0, 0);
6064 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed, hr=%s\n", DXGetErrorString9(hr
));
6066 hr
= IDirect3DDevice9_CreateVertexBuffer(device
, sizeof(quad
), 0, 0,
6067 D3DPOOL_MANAGED
, &buffer
, NULL
);
6068 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateVertexBuffer failed, hr=%s\n", DXGetErrorString9(hr
));
6069 hr
= IDirect3DVertexBuffer9_Lock(buffer
, 0, sizeof(quad
), (void **) &data
, 0);
6070 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Lock failed, hr=%s\n", DXGetErrorString9(hr
));
6071 memcpy(data
, quad
, sizeof(quad
));
6072 hr
= IDirect3DVertexBuffer9_Unlock(buffer
);
6073 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer9_Unlock failed, hr=%s\n", DXGetErrorString9(hr
));
6074 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, buffer
, 0, sizeof(quad
[0]));
6075 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetStreamSource failed, hr=%s\n", DXGetErrorString9(hr
));
6077 hr
= IDirect3DDevice9_BeginScene(device
);
6078 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed (%08x)\n", hr
);
6080 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 0, 2);
6081 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawPrimitive failed, hr = %#08x\n", hr
);
6082 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 4, 2);
6083 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawPrimitive failed, hr = %#08x\n", hr
);
6084 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 8, 2);
6085 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawPrimitive failed, hr = %#08x\n", hr
);
6086 hr
= IDirect3DDevice9_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 12, 2);
6087 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawPrimitive failed, hr = %#08x\n", hr
);
6089 hr
= IDirect3DDevice9_EndScene(device
);
6090 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed, hr=%s\n", DXGetErrorString9(hr
));
6093 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
6094 color
= getPixelColor(device
, 480, 360);
6095 ok(color
== 0x00ff0000,
6096 "Input 0x00003c00, 0x00000000 returned color %08x, expected 0x00ff0000\n", color
);
6097 color
= getPixelColor(device
, 160, 120);
6098 ok(color
== 0x00000000,
6099 "Input 0x00000000, 0x3c000000 returned color %08x, expected 0x00000000\n", color
);
6100 color
= getPixelColor(device
, 160, 360);
6101 ok(color
== 0x0000ff00,
6102 "Input 0x3c000000, 0x00000000 returned color %08x, expected 0x0000ff00\n", color
);
6103 color
= getPixelColor(device
, 480, 120);
6104 ok(color
== 0x000000ff,
6105 "Input 0x00000000, 0x00003c00 returned color %08x, expected 0x000000ff\n", color
);
6107 hr
= IDirect3DDevice9_SetStreamSource(device
, 0, NULL
, 0, 0);
6108 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetStreamSource failed, hr=%s\n", DXGetErrorString9(hr
));
6109 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
6110 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed, hr=%s\n", DXGetErrorString9(hr
));
6111 IDirect3DDevice9_SetVertexShader(device
, NULL
);
6112 ok(SUCCEEDED(hr
), "IDirect3DDevice9_SetVertexShader failed hr=%s\n", DXGetErrorString9(hr
));
6114 IDirect3DVertexDeclaration9_Release(vdecl
);
6115 IDirect3DVertexShader9_Release(shader
);
6116 IDirect3DVertexBuffer9_Release(buffer
);
6119 static void conditional_np2_repeat_test(IDirect3DDevice9
*device
)
6122 IDirect3DTexture9
*texture
;
6124 D3DLOCKED_RECT rect
;
6127 const float quad
[] = {
6128 -1.0, -1.0, 0.1, -0.2, -0.2,
6129 1.0, -1.0, 0.1, 1.2, -0.2,
6130 -1.0, 1.0, 0.1, -0.2, 1.2,
6131 1.0, 1.0, 0.1, 1.2, 1.2
6133 memset(&caps
, 0, sizeof(caps
));
6135 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
6136 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetDeviceCaps failed hr=%s\n", DXGetErrorString9(hr
));
6137 if(!(caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
)) {
6138 /* NP2 conditional requires the POW2 flag. Check that while we're at it */
6139 ok((caps
.TextureCaps
& D3DPTEXTURECAPS_NONPOW2CONDITIONAL
) == 0,
6140 "Card has conditional NP2 support without power of two restriction set\n");
6141 skip("Card has unconditional pow2 support, skipping conditional NP2 tests\n");
6143 } else if(!(caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
)) {
6144 skip("No conditional NP2 support, skipping conditional NP2 tests\n");
6148 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff000000, 0.0, 0);
6149 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed, hr=%s\n", DXGetErrorString9(hr
));
6151 hr
= IDirect3DDevice9_CreateTexture(device
, 10, 10, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &texture
, NULL
);
6152 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture failed hr=%s\n", DXGetErrorString9(hr
));
6154 memset(&rect
, 0, sizeof(rect
));
6155 hr
= IDirect3DTexture9_LockRect(texture
, 0, &rect
, NULL
, 0);
6156 ok(hr
== D3D_OK
, "IDirect3DTexture9_LockRect failed hr=%s\n", DXGetErrorString9(hr
));
6157 for(y
= 0; y
< 10; y
++) {
6158 for(x
= 0; x
< 10; x
++) {
6159 dst
= (DWORD
*) ((BYTE
*) rect
.pBits
+ y
* rect
.Pitch
+ x
* sizeof(DWORD
));
6160 if(x
== 0 || x
== 9 || y
== 0 || y
== 9) {
6167 hr
= IDirect3DTexture9_UnlockRect(texture
, 0);
6168 ok(hr
== D3D_OK
, "IDirect3DTexture9_UnlockRect failed hr=%s\n", DXGetErrorString9(hr
));
6170 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) texture
);
6171 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture failed hr=%s\n", DXGetErrorString9(hr
));
6172 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSU
, D3DTADDRESS_WRAP
);
6173 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState failed hr=%s\n", DXGetErrorString9(hr
));
6174 hr
= IDirect3DDevice9_SetSamplerState(device
, 0, D3DSAMP_ADDRESSV
, D3DTADDRESS_WRAP
);
6175 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetSamplerState failed hr=%s\n", DXGetErrorString9(hr
));
6176 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
6177 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetVertexDeclaration failed, hr=%s\n", DXGetErrorString9(hr
));
6179 hr
= IDirect3DDevice9_BeginScene(device
);
6180 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed hr=%s\n", DXGetErrorString9(hr
));
6182 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, quad
, sizeof(float) * 5);
6183 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawPrimitiveUP failed, hr=%s\n", DXGetErrorString9(hr
));
6185 hr
= IDirect3DDevice9_EndScene(device
);
6186 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed hr=%s\n", DXGetErrorString9(hr
));
6189 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
6191 color
= getPixelColor(device
, 1, 1);
6192 ok(color
== 0x00ff0000, "NP2: Pixel 1, 1 has color %08x, expected 0x00ff0000\n", color
);
6193 color
= getPixelColor(device
, 639, 479);
6194 ok(color
== 0x00ff0000, "NP2: Pixel 639, 479 has color %08x, expected 0x00ff0000\n", color
);
6196 color
= getPixelColor(device
, 135, 101);
6197 ok(color
== 0x00ff0000, "NP2: Pixel 135, 101 has color %08x, expected 0x00ff0000\n", color
);
6198 color
= getPixelColor(device
, 140, 101);
6199 ok(color
== 0x00ff0000, "NP2: Pixel 140, 101 has color %08x, expected 0x00ff0000\n", color
);
6200 color
= getPixelColor(device
, 135, 105);
6201 ok(color
== 0x00ff0000, "NP2: Pixel 135, 105 has color %08x, expected 0x00ff0000\n", color
);
6202 color
= getPixelColor(device
, 140, 105);
6203 ok(color
== 0x000000ff, "NP2: Pixel 140, 105 has color %08x, expected 0x000000ff\n", color
);
6205 color
= getPixelColor(device
, 135, 376);
6206 ok(color
== 0x00ff0000, "NP2: Pixel 135, 376 has color %08x, expected 0x00ff0000\n", color
);
6207 color
= getPixelColor(device
, 140, 376);
6208 ok(color
== 0x000000ff, "NP2: Pixel 140, 376 has color %08x, expected 0x000000ff\n", color
);
6209 color
= getPixelColor(device
, 135, 379);
6210 ok(color
== 0x00ff0000, "NP2: Pixel 135, 379 has color %08x, expected 0x00ff0000\n", color
);
6211 color
= getPixelColor(device
, 140, 379);
6212 ok(color
== 0x00ff0000, "NP2: Pixel 140, 379 has color %08x, expected 0x00ff0000\n", color
);
6214 color
= getPixelColor(device
, 500, 101);
6215 ok(color
== 0x00ff0000, "NP2: Pixel 500, 101 has color %08x, expected 0x00ff0000\n", color
);
6216 color
= getPixelColor(device
, 504, 101);
6217 ok(color
== 0x00ff0000, "NP2: Pixel 504, 101 has color %08x, expected 0x00ff0000\n", color
);
6218 color
= getPixelColor(device
, 500, 105);
6219 ok(color
== 0x000000ff, "NP2: Pixel 500, 105 has color %08x, expected 0x000000ff\n", color
);
6220 color
= getPixelColor(device
, 504, 105);
6221 ok(color
== 0x00ff0000, "NP2: Pixel 504, 105 has color %08x, expected 0x00ff0000\n", color
);
6223 color
= getPixelColor(device
, 500, 376);
6224 ok(color
== 0x000000ff, "NP2: Pixel 500, 376 has color %08x, expected 0x000000ff\n", color
);
6225 color
= getPixelColor(device
, 504, 376);
6226 ok(color
== 0x00ff0000, "NP2: Pixel 504, 376 has color %08x, expected 0x00ff0000\n", color
);
6227 color
= getPixelColor(device
, 500, 380);
6228 ok(color
== 0x00ff0000, "NP2: Pixel 500, 380 has color %08x, expected 0x00ff0000\n", color
);
6229 color
= getPixelColor(device
, 504, 380);
6230 ok(color
== 0x00ff0000, "NP2: Pixel 504, 380 has color %08x, expected 0x00ff0000\n", color
);
6232 hr
= IDirect3DDevice9_SetTexture(device
, 0, NULL
);
6233 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture failed hr=%s\n", DXGetErrorString9(hr
));
6234 IDirect3DTexture9_Release(texture
);
6237 static void vFace_register_test(IDirect3DDevice9
*device
)
6241 const DWORD shader_code
[] = {
6242 0xffff0300, /* ps_3_0 */
6243 0x05000051, 0xa00f0000, 0x00000000, 0x3f800000, 0x00000000, 0x00000000, /* def c0, 0.0, 1.0, 0.0, 0.0 */
6244 0x05000051, 0xa00f0001, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c1, 1.0, 0.0, 0.0, 0.0 */
6245 0x0200001f, 0x80000000, 0x900f1001, /* dcl vFace */
6246 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
6247 0x04000058, 0x800f0000, 0x90e41001, 0xa0e40000, 0x80e40001, /* cmp r0, vFace, c0, r1 */
6248 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
6249 0x0000ffff /* END */
6251 IDirect3DPixelShader9
*shader
;
6252 IDirect3DTexture9
*texture
;
6253 IDirect3DSurface9
*surface
, *backbuffer
;
6254 const float quad
[] = {
6271 const float blit
[] = {
6272 0.0, -1.0, 0.1, 0.0, 0.0,
6273 1.0, -1.0, 0.1, 1.0, 0.0,
6274 0.0, 1.0, 0.1, 0.0, 1.0,
6275 1.0, 1.0, 0.1, 1.0, 1.0,
6278 hr
= IDirect3DDevice9_CreatePixelShader(device
, shader_code
, &shader
);
6279 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreatePixelShader failed hr=%s\n", DXGetErrorString9(hr
));
6280 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &texture
, NULL
);
6281 ok(hr
== D3D_OK
, "IDirect3DDevice9_CreateTexture failed hr=%s\n", DXGetErrorString9(hr
));
6282 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
6283 ok(hr
== D3D_OK
, "IDirect3DTexture9_GetSurfaceLevel failed hr=%s\n", DXGetErrorString9(hr
));
6284 hr
= IDirect3DDevice9_SetPixelShader(device
, shader
);
6285 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader failed hr=%s\n", DXGetErrorString9(hr
));
6286 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
6287 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed hr=%s\n", DXGetErrorString9(hr
));
6288 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
6289 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetBackBuffer failed hr=%s\n", DXGetErrorString9(hr
));
6291 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff0000ff, 0.0, 0);
6292 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed, hr=%s\n", DXGetErrorString9(hr
));
6294 hr
= IDirect3DDevice9_BeginScene(device
);
6295 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene failed hr=%s\n", DXGetErrorString9(hr
));
6297 /* First, draw to the texture and the back buffer to test both offscreen and onscreen cases */
6298 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, surface
);
6299 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderTarget failed, hr=%s\n", DXGetErrorString9(hr
));
6300 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff0000ff, 0.0, 0);
6301 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed, hr=%s\n", DXGetErrorString9(hr
));
6302 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 4, quad
, sizeof(float) * 3);
6303 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawPrimitiveUP failed, hr=%s\n", DXGetErrorString9(hr
));
6304 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, backbuffer
);
6305 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderTarget failed, hr=%s\n", DXGetErrorString9(hr
));
6306 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 4, quad
, sizeof(float) * 3);
6307 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawPrimitiveUP failed, hr=%s\n", DXGetErrorString9(hr
));
6309 /* Blit the texture ontp the back buffer to make it visible */
6310 hr
= IDirect3DDevice9_SetPixelShader(device
, NULL
);
6311 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader failed, hr=%s\n", DXGetErrorString9(hr
));
6312 hr
= IDirect3DDevice9_SetTexture(device
, 0, (IDirect3DBaseTexture9
*) texture
);
6313 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTexture failed, hr=%s\n", DXGetErrorString9(hr
));
6314 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
6315 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed, hr=%s\n", DXGetErrorString9(hr
));
6316 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
6317 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetTextureStageState failed, hr=%s\n", DXGetErrorString9(hr
));
6318 hr
= IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_TEX1
);
6319 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetFVF failed hr=%s\n", DXGetErrorString9(hr
));
6321 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, blit
, sizeof(float) * 5);
6322 ok(hr
== D3D_OK
, "IDirect3DDevice9_DrawPrimitiveUP failed, hr=%s\n", DXGetErrorString9(hr
));
6324 hr
= IDirect3DDevice9_EndScene(device
);
6325 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene failed hr=%s\n", DXGetErrorString9(hr
));
6328 IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
6329 color
= getPixelColor(device
, 160, 360);
6330 ok(color
== 0x00ff0000, "vFace: Onscreen rendered front facing quad has color 0x%08x, expected 0x00ff0000\n", color
);
6331 color
= getPixelColor(device
, 160, 120);
6332 ok(color
== 0x0000ff00, "vFace: Onscreen rendered back facing quad has color 0x%08x, expected 0x0000ff00\n", color
);
6333 color
= getPixelColor(device
, 480, 360);
6334 ok(color
== 0x0000ff00, "vFace: Offscreen rendered back facing quad has color 0x%08x, expected 0x0000ff00\n", color
);
6335 color
= getPixelColor(device
, 480, 120);
6336 ok(color
== 0x00ff0000, "vFace: Offscreen rendered front facing quad has color 0x%08x, expected 0x00ff0000\n", color
);
6338 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetPixelShader failed hr=%s\n", DXGetErrorString9(hr
));
6339 IDirect3DDevice9_SetTexture(device
, 0, NULL
);
6340 IDirect3DPixelShader9_Release(shader
);
6341 IDirect3DSurface9_Release(surface
);
6342 IDirect3DSurface9_Release(backbuffer
);
6343 IDirect3DTexture9_Release(texture
);
6346 static void fixed_function_bumpmap_test(IDirect3DDevice9
*device
)
6353 static const float quad
[][7] = {
6354 {-128.0f
/640.0f
, -128.0f
/480.0f
, 0.1f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
},
6355 {-128.0f
/640.0f
, 128.0f
/480.0f
, 0.1f
, 0.0f
, 1.0f
, 0.0f
, 1.0f
},
6356 { 128.0f
/640.0f
, -128.0f
/480.0f
, 0.1f
, 1.0f
, 0.0f
, 1.0f
, 0.0f
},
6357 { 128.0f
/640.0f
, 128.0f
/480.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
},
6360 static const D3DVERTEXELEMENT9 decl_elements
[] = {
6361 {0, 0, D3DDECLTYPE_FLOAT3
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_POSITION
, 0},
6362 {0, 12, D3DDECLTYPE_FLOAT2
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 0},
6363 {0, 20, D3DDECLTYPE_FLOAT2
, D3DDECLMETHOD_DEFAULT
, D3DDECLUSAGE_TEXCOORD
, 1},
6367 /* use assymetric matrix to test loading */
6368 float bumpenvmat
[4] = {0.0,0.5,-0.5,0.0};
6370 IDirect3DVertexDeclaration9
*vertex_declaration
= NULL
;
6371 IDirect3DTexture9
*texture
= NULL
;
6373 memset(&caps
, 0, sizeof(caps
));
6374 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
6375 ok(hr
== D3D_OK
, "IDirect3DDevice9_GetDeviceCaps failed hr=%s\n", DXGetErrorString9(hr
));
6376 if(!(caps
.TextureOpCaps
& D3DTEXOPCAPS_BUMPENVMAP
)) {
6377 skip("D3DTEXOPCAPS_BUMPENVMAP not set, skipping bumpmap tests\n");
6382 IDirect3DDevice9_GetDirect3D(device
, &d3d9
);
6383 hr
= IDirect3D9_CheckDeviceFormat(d3d9
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
, D3DUSAGE_QUERY_LEGACYBUMPMAP
,
6384 D3DRTYPE_TEXTURE
, D3DFMT_V8U8
);
6385 IDirect3D9_Release(d3d9
);
6387 skip("D3DFMT_V8U8 not supported for legacy bump mapping\n");
6392 /* Generate the textures */
6393 generate_bumpmap_textures(device
);
6395 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_BUMPENVMAT00
, *(LPDWORD
)&bumpenvmat
[0]);
6396 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
6397 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_BUMPENVMAT01
, *(LPDWORD
)&bumpenvmat
[1]);
6398 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
6399 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_BUMPENVMAT10
, *(LPDWORD
)&bumpenvmat
[2]);
6400 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
6401 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_BUMPENVMAT11
, *(LPDWORD
)&bumpenvmat
[3]);
6402 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
6404 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_BUMPENVMAP
);
6405 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
6406 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
6407 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
6408 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_CURRENT
);
6409 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
6411 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
6412 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
6413 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
6414 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
6415 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLORARG2
, D3DTA_CURRENT
);
6416 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
6418 hr
= IDirect3DDevice9_SetTextureStageState(device
, 2, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
6419 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
6421 hr
= IDirect3DDevice9_SetVertexShader(device
, NULL
);
6422 ok(SUCCEEDED(hr
), "SetVertexShader failed (%08x)\n", hr
);
6424 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
6425 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear failed (%08x)\n", hr
);
6428 hr
= IDirect3DDevice9_CreateVertexDeclaration(device
, decl_elements
, &vertex_declaration
);
6429 ok(SUCCEEDED(hr
), "CreateVertexDeclaration failed (0x%08x)\n", hr
);
6430 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, vertex_declaration
);
6431 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed (0x%08x)\n", hr
);
6433 hr
= IDirect3DDevice9_BeginScene(device
);
6434 ok(SUCCEEDED(hr
), "BeginScene failed (0x%08x)\n", hr
);
6436 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, &quad
[0], sizeof(quad
[0]));
6437 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed (0x%08x)\n", hr
);
6439 hr
= IDirect3DDevice9_EndScene(device
);
6440 ok(SUCCEEDED(hr
), "EndScene failed (0x%08x)\n", hr
);
6442 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
6443 ok(SUCCEEDED(hr
), "Present failed (0x%08x)\n", hr
);
6445 color
= getPixelColor(device
, 320-32, 240);
6446 ok(color
== 0x00ffffff, "bumpmap failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
6447 color
= getPixelColor(device
, 320+32, 240);
6448 ok(color
== 0x00ffffff, "bumpmap failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
6449 color
= getPixelColor(device
, 320, 240-32);
6450 ok(color
== 0x00ffffff, "bumpmap failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
6451 color
= getPixelColor(device
, 320, 240+32);
6452 ok(color
== 0x00ffffff, "bumpmap failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
6453 color
= getPixelColor(device
, 320, 240);
6454 ok(color
== 0x00000000, "bumpmap failed: Got color 0x%08x, expected 0x00000000.\n", color
);
6455 color
= getPixelColor(device
, 320+32, 240+32);
6456 ok(color
== 0x00000000, "bumpmap failed: Got color 0x%08x, expected 0x00000000.\n", color
);
6457 color
= getPixelColor(device
, 320-32, 240+32);
6458 ok(color
== 0x00000000, "bumpmap failed: Got color 0x%08x, expected 0x00000000.\n", color
);
6459 color
= getPixelColor(device
, 320+32, 240-32);
6460 ok(color
== 0x00000000, "bumpmap failed: Got color 0x%08x, expected 0x00000000.\n", color
);
6461 color
= getPixelColor(device
, 320-32, 240-32);
6462 ok(color
== 0x00000000, "bumpmap failed: Got color 0x%08x, expected 0x00000000.\n", color
);
6464 hr
= IDirect3DDevice9_SetVertexDeclaration(device
, NULL
);
6465 ok(SUCCEEDED(hr
), "SetVertexDeclaration failed (%08x)\n", hr
);
6466 IDirect3DVertexDeclaration9_Release(vertex_declaration
);
6468 for(i
= 0; i
< 2; i
++) {
6469 hr
= IDirect3DDevice9_GetTexture(device
, i
, (IDirect3DBaseTexture9
**) &texture
);
6470 ok(SUCCEEDED(hr
), "IDirect3DDevice9_GetTexture failed (0x%08x)\n", hr
);
6471 IDirect3DTexture9_Release(texture
); /* For the GetTexture */
6472 hr
= IDirect3DDevice9_SetTexture(device
, i
, NULL
);
6473 ok(SUCCEEDED(hr
), "SetTexture failed (0x%08x)\n", hr
);
6474 IDirect3DTexture9_Release(texture
); /* To destroy it */
6477 hr
= IDirect3DDevice9_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
6478 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
6479 hr
= IDirect3DDevice9_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_MODULATE
);
6480 ok(SUCCEEDED(hr
), "SetTextureStageState failed (%08x)\n", hr
);
6484 static void stencil_cull_test(IDirect3DDevice9
*device
) {
6486 IDirect3DSurface9
*depthstencil
= NULL
;
6487 D3DSURFACE_DESC desc
;
6512 struct vertex painter
[] = {
6513 {-1.0, -1.0, 0.0, 0x00000000},
6514 { 1.0, -1.0, 0.0, 0x00000000},
6515 {-1.0, 1.0, 0.0, 0x00000000},
6516 { 1.0, 1.0, 0.0, 0x00000000},
6518 WORD indices_cw
[] = {0, 1, 3};
6519 WORD indices_ccw
[] = {0, 2, 3};
6523 IDirect3DDevice9_GetDepthStencilSurface(device
, &depthstencil
);
6524 if(depthstencil
== NULL
) {
6525 skip("No depth stencil buffer\n");
6528 hr
= IDirect3DSurface9_GetDesc(depthstencil
, &desc
);
6529 ok(hr
== D3D_OK
, "IDirect3DSurface9_GetDesc failed with %s\n", DXGetErrorString9(hr
));
6530 IDirect3DSurface9_Release(depthstencil
);
6531 if(desc
.Format
!= D3DFMT_D24S8
&& desc
.Format
!= D3DFMT_D24X4S4
) {
6532 skip("No 4 or 8 bit stencil surface\n");
6536 hr
= IDirect3DDevice9_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_STENCIL
, 0x00ff0000, 0.0, 0x8);
6537 ok(hr
== D3D_OK
, "IDirect3DDevice9_Clear returned %s\n", DXGetErrorString9(hr
));
6538 IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
);
6540 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILFAIL
, D3DSTENCILOP_INCR
);
6541 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
6542 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILZFAIL
, D3DSTENCILOP_DECR
);
6543 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
6544 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILPASS
, D3DSTENCILOP_REPLACE
);
6545 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
6546 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILREF
, 0x3);
6547 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
6549 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CCW_STENCILFAIL
, D3DSTENCILOP_REPLACE
);
6550 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
6551 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CCW_STENCILZFAIL
, D3DSTENCILOP_DECR
);
6552 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
6553 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CCW_STENCILPASS
, D3DSTENCILOP_INCR
);
6554 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
6556 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILENABLE
, TRUE
);
6557 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
6558 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_TWOSIDEDSTENCILMODE
, FALSE
);
6559 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
6561 /* First pass: Fill the stencil buffer with some values... */
6562 hr
= IDirect3DDevice9_BeginScene(device
);
6563 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
6566 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CULLMODE
, D3DCULL_CW
);
6567 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
6568 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
6569 1 /*PrimCount */, indices_cw
, D3DFMT_INDEX16
, quad1
, sizeof(float) * 3);
6570 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
6571 1 /*PrimCount */, indices_ccw
, D3DFMT_INDEX16
, quad1
, sizeof(float) * 3);
6573 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_TWOSIDEDSTENCILMODE
, TRUE
);
6574 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
6575 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CULLMODE
, D3DCULL_NONE
);
6576 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
6577 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
6578 1 /*PrimCount */, indices_cw
, D3DFMT_INDEX16
, quad2
, sizeof(float) * 3);
6579 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
6580 1 /*PrimCount */, indices_ccw
, D3DFMT_INDEX16
, quad2
, sizeof(float) * 3);
6582 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CULLMODE
, D3DCULL_CW
);
6583 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
6584 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
6585 1 /*PrimCount */, indices_cw
, D3DFMT_INDEX16
, quad3
, sizeof(float) * 3);
6586 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
6587 1 /*PrimCount */, indices_ccw
, D3DFMT_INDEX16
, quad3
, sizeof(float) * 3);
6589 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CULLMODE
, D3DCULL_CCW
);
6590 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
6591 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
6592 1 /*PrimCount */, indices_cw
, D3DFMT_INDEX16
, quad4
, sizeof(float) * 3);
6593 hr
= IDirect3DDevice9_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 4 /* NumVerts */,
6594 1 /*PrimCount */, indices_ccw
, D3DFMT_INDEX16
, quad4
, sizeof(float) * 3);
6596 hr
= IDirect3DDevice9_EndScene(device
);
6597 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
6600 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
6601 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILZFAIL
, D3DSTENCILOP_KEEP
);
6602 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
6603 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILPASS
, D3DSTENCILOP_KEEP
);
6604 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
6605 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILFAIL
, D3DSTENCILOP_KEEP
);
6606 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
6607 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_TWOSIDEDSTENCILMODE
, FALSE
);
6608 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
6609 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_CULLMODE
, D3DCULL_NONE
);
6610 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
6611 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILFUNC
, D3DCMP_EQUAL
);
6612 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
6614 /* 2nd pass: Make the stencil values visible */
6615 hr
= IDirect3DDevice9_BeginScene(device
);
6616 ok(hr
== D3D_OK
, "IDirect3DDevice9_BeginScene returned %s\n", DXGetErrorString9(hr
));
6619 IDirect3DDevice9_SetFVF(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
6620 for(i
= 0; i
< 16; i
++) {
6621 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILREF
, i
);
6622 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
6624 painter
[0].diffuse
= (i
* 16); /* Creates shades of blue */
6625 painter
[1].diffuse
= (i
* 16);
6626 painter
[2].diffuse
= (i
* 16);
6627 painter
[3].diffuse
= (i
* 16);
6628 hr
= IDirect3DDevice9_DrawPrimitiveUP(device
, D3DPT_TRIANGLESTRIP
, 2, painter
, sizeof(painter
[0]));
6629 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed (%08x)\n", hr
);
6631 hr
= IDirect3DDevice9_EndScene(device
);
6632 ok(hr
== D3D_OK
, "IDirect3DDevice9_EndScene returned %s\n", DXGetErrorString9(hr
));
6635 hr
= IDirect3DDevice9_Present(device
, NULL
, NULL
, NULL
, NULL
);
6636 ok(hr
== D3D_OK
, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr
));
6638 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_STENCILENABLE
, FALSE
);
6639 ok(hr
== D3D_OK
, "IDirect3DDevice9_SetRenderState returned %s\n", DXGetErrorString9(hr
));
6641 color
= getPixelColor(device
, 160, 420);
6642 ok(color
== 0x00000030, "CCW triangle, twoside FALSE, cull cw, replace, has color 0x%08x, expected 0x00000030\n", color
);
6643 color
= getPixelColor(device
, 160, 300);
6644 ok(color
== 0x00000080, "CW triangle, twoside FALSE, cull cw, culled, has color 0x%08x, expected 0x00000080\n", color
);
6646 color
= getPixelColor(device
, 480, 420);
6647 ok(color
== 0x00000090, "CCW triangle, twoside TRUE, cull off, incr, has color 0x%08x, expected 0x00000090\n", color
);
6648 color
= getPixelColor(device
, 480, 300);
6649 ok(color
== 0x00000030, "CW triangle, twoside TRUE, cull off, replace, has color 0x%08x, expected 0x00000030\n", color
);
6651 color
= getPixelColor(device
, 160, 180);
6652 ok(color
== 0x00000080, "CCW triangle, twoside TRUE, cull ccw, culled, has color 0x%08x, expected 0x00000080\n", color
);
6653 color
= getPixelColor(device
, 160, 60);
6654 ok(color
== 0x00000030, "CW triangle, twoside TRUE, cull ccw, replace, has color 0x%08x, expected 0x00000030\n", color
);
6656 color
= getPixelColor(device
, 480, 180);
6657 ok(color
== 0x00000090, "CCW triangle, twoside TRUE, cull cw, incr, has color 0x%08x, expected 0x00000090\n", color
);
6658 color
= getPixelColor(device
, 480, 60);
6659 ok(color
== 0x00000080, "CW triangle, twoside TRUE, cull cw, culled, has color 0x%08x, expected 0x00000080\n", color
);
6664 IDirect3DDevice9
*device_ptr
;
6669 d3d9_handle
= LoadLibraryA("d3d9.dll");
6672 skip("Could not load d3d9.dll\n");
6676 device_ptr
= init_d3d9();
6679 skip("Creating the device failed\n");
6683 IDirect3DDevice9_GetDeviceCaps(device_ptr
, &caps
);
6685 /* Check for the reliability of the returned data */
6686 hr
= IDirect3DDevice9_Clear(device_ptr
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
6689 trace("Clear failed, can't assure correctness of the test results, skipping\n");
6692 IDirect3DDevice9_Present(device_ptr
, NULL
, NULL
, NULL
, NULL
);
6694 color
= getPixelColor(device_ptr
, 1, 1);
6695 if(color
!=0x00ff0000)
6697 trace("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests, skipping\n", color
);
6701 hr
= IDirect3DDevice9_Clear(device_ptr
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ddee, 0.0, 0);
6704 trace("Clear failed, can't assure correctness of the test results, skipping\n");
6707 IDirect3DDevice9_Present(device_ptr
, NULL
, NULL
, NULL
, NULL
);
6709 color
= getPixelColor(device_ptr
, 639, 479);
6710 if(color
!= 0x0000ddee)
6712 trace("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests, skipping\n", color
);
6716 /* Now execute the real tests */
6717 lighting_test(device_ptr
);
6718 clear_test(device_ptr
);
6719 fog_test(device_ptr
);
6720 if(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
)
6722 test_cube_wrap(device_ptr
);
6724 skip("No cube texture support\n");
6726 z_range_test(device_ptr
);
6727 if(caps
.TextureCaps
& D3DPTEXTURECAPS_MIPMAP
)
6729 maxmip_test(device_ptr
);
6733 skip("No mipmap support\n");
6735 offscreen_test(device_ptr
);
6736 alpha_test(device_ptr
);
6737 release_buffer_test(device_ptr
);
6738 float_texture_test(device_ptr
);
6739 g16r16_texture_test(device_ptr
);
6740 texture_transform_flags_test(device_ptr
);
6741 autogen_mipmap_test(device_ptr
);
6742 fixed_function_decl_test(device_ptr
);
6743 conditional_np2_repeat_test(device_ptr
);
6744 fixed_function_bumpmap_test(device_ptr
);
6745 if(caps
.StencilCaps
& D3DSTENCILCAPS_TWOSIDED
) {
6746 stencil_cull_test(device_ptr
);
6748 skip("No two sided stencil support\n");
6751 if (caps
.VertexShaderVersion
>= D3DVS_VERSION(1, 1))
6753 test_constant_clamp_vs(device_ptr
);
6754 test_compare_instructions(device_ptr
);
6756 else skip("No vs_1_1 support\n");
6758 if (caps
.VertexShaderVersion
>= D3DVS_VERSION(2, 0))
6760 test_mova(device_ptr
);
6761 if (caps
.VertexShaderVersion
>= D3DVS_VERSION(3, 0)) {
6762 test_vshader_input(device_ptr
);
6763 test_vshader_float16(device_ptr
);
6765 skip("No vs_3_0 support\n");
6768 else skip("No vs_2_0 support\n");
6770 if (caps
.VertexShaderVersion
>= D3DVS_VERSION(1, 1) && caps
.PixelShaderVersion
>= D3DPS_VERSION(1, 1))
6772 fog_with_shader_test(device_ptr
);
6773 fog_srgbwrite_test(device_ptr
);
6775 else skip("No vs_1_1 and ps_1_1 support\n");
6777 if (caps
.PixelShaderVersion
>= D3DPS_VERSION(1, 1))
6779 texbem_test(device_ptr
);
6780 texdepth_test(device_ptr
);
6781 texkill_test(device_ptr
);
6782 x8l8v8u8_test(device_ptr
);
6783 if (caps
.PixelShaderVersion
>= D3DPS_VERSION(1, 4)) {
6784 constant_clamp_ps_test(device_ptr
);
6785 cnd_test(device_ptr
);
6786 if (caps
.PixelShaderVersion
>= D3DPS_VERSION(3, 0)) {
6787 nested_loop_test(device_ptr
);
6788 fixed_function_varying_test(device_ptr
);
6789 vFace_register_test(device_ptr
);
6790 if(caps
.VertexShaderVersion
>= D3DVS_VERSION(3, 0)) {
6791 vshader_version_varying_test(device_ptr
);
6792 pshader_version_varying_test(device_ptr
);
6794 skip("No vs_3_0 support\n");
6797 skip("No ps_3_0 support\n");
6801 else skip("No ps_1_1 support\n");
6807 D3DPRESENT_PARAMETERS present_parameters
;
6808 IDirect3DSwapChain9
*swapchain
;
6809 IDirect3DDevice9_GetSwapChain(device_ptr
, 0, &swapchain
);
6810 IDirect3DSwapChain9_GetPresentParameters(swapchain
, &present_parameters
);
6811 IDirect3DSwapChain9_Release(swapchain
);
6812 ref
= IDirect3DDevice9_Release(device_ptr
);
6813 DestroyWindow(present_parameters
.hDeviceWindow
);
6814 ok(ref
== 0, "The device was not properly freed: refcount %u\n", ref
);