2 * Copyright (C) 2007 Stefan Dösinger(for CodeWeavers)
3 * Copyright (C) 2008 Alexander Dorofeyev
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 /* See comment in dlls/d3d9/tests/visual.c for general guidelines */
22 #include "wine/test.h"
32 static IDirectDraw7
*DirectDraw
;
33 static IDirectDrawSurface7
*Surface
;
34 static IDirectDrawSurface7
*depth_buffer
;
35 static IDirect3D7
*Direct3D
;
36 static IDirect3DDevice7
*Direct3DDevice
;
38 static IDirectDraw
*DirectDraw1
;
39 static IDirectDrawSurface
*Surface1
;
40 static IDirect3D
*Direct3D1
;
41 static IDirect3DDevice
*Direct3DDevice1
;
42 static IDirect3DExecuteBuffer
*ExecuteBuffer
;
43 static IDirect3DViewport
*Viewport
;
45 static BOOL refdevice
= FALSE
;
47 static HRESULT (WINAPI
*pDirectDrawCreateEx
)(GUID
*driver_guid
,
48 void **ddraw
, REFIID interface_iid
, IUnknown
*outer
);
50 static BOOL
color_match(D3DCOLOR c1
, D3DCOLOR c2
, BYTE max_diff
)
52 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
54 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
56 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
58 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
62 static HRESULT WINAPI
enum_z_fmt(DDPIXELFORMAT
*fmt
, void *ctx
)
64 DDPIXELFORMAT
*zfmt
= ctx
;
66 if(U1(*fmt
).dwZBufferBitDepth
> U1(*zfmt
).dwZBufferBitDepth
)
73 static HRESULT WINAPI
enum_devtype_cb(char *desc_str
, char *name
, D3DDEVICEDESC7
*desc
, void *ctx
)
76 if (IsEqualGUID(&desc
->deviceGUID
, &IID_IDirect3DTnLHalDevice
))
79 return DDENUMRET_CANCEL
;
84 static BOOL
createObjects(void)
87 HMODULE hmod
= GetModuleHandleA("ddraw.dll");
92 const GUID
*devtype
= &IID_IDirect3DHALDevice
;
94 if(!hmod
) return FALSE
;
95 pDirectDrawCreateEx
= (void*)GetProcAddress(hmod
, "DirectDrawCreateEx");
96 if(!pDirectDrawCreateEx
) return FALSE
;
98 hr
= pDirectDrawCreateEx(NULL
, (void **) &DirectDraw
, &IID_IDirectDraw7
, NULL
);
99 ok(hr
==DD_OK
|| hr
==DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreateEx returned: %x\n", hr
);
100 if(!DirectDraw
) goto err
;
102 wc
.lpfnWndProc
= DefWindowProcA
;
103 wc
.lpszClassName
= "d3d7_test_wc";
105 window
= CreateWindowA("d3d7_test_wc", "d3d7_test", WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
,
106 0, 0, 640, 480, 0, 0, 0, 0);
108 hr
= IDirectDraw7_SetCooperativeLevel(DirectDraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
109 ok(hr
== DD_OK
, "IDirectDraw7_SetCooperativeLevel failed with %08x\n", hr
);
110 if(FAILED(hr
)) goto err
;
111 hr
= IDirectDraw7_SetDisplayMode(DirectDraw
, 640, 480, 32, 0, 0);
113 /* 24 bit is fine too */
114 hr
= IDirectDraw7_SetDisplayMode(DirectDraw
, 640, 480, 24, 0, 0);
117 ok(hr
== DD_OK
|| hr
== DDERR_UNSUPPORTED
, "IDirectDraw7_SetDisplayMode failed with %08x\n", hr
);
119 /* use trace, the caller calls skip() */
120 trace("SetDisplayMode failed\n");
124 hr
= IDirectDraw7_QueryInterface(DirectDraw
, &IID_IDirect3D7
, (void**) &Direct3D
);
125 if (hr
== E_NOINTERFACE
) goto err
;
126 ok(hr
==DD_OK
, "QueryInterface returned: %08x\n", hr
);
128 /* DirectDraw Flipping behavior doesn't seem that well-defined. The reference rasterizer behaves differently
129 * than hardware implementations. Request single buffering, that seems to work everywhere
131 memset(&ddsd
, 0, sizeof(ddsd
));
132 ddsd
.dwSize
= sizeof(ddsd
);
133 ddsd
.dwFlags
= DDSD_CAPS
;
134 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
;
135 ddsd
.dwBackBufferCount
= 1;
136 hr
= IDirectDraw7_CreateSurface(DirectDraw
, &ddsd
, &Surface
, NULL
);
137 if(FAILED(hr
)) goto err
;
139 hr
= IDirect3D7_EnumDevices(Direct3D
, enum_devtype_cb
, &hal_ok
);
140 ok(SUCCEEDED(hr
), "Failed to enumerate devices, hr %#x.\n", hr
);
141 if (hal_ok
) devtype
= &IID_IDirect3DTnLHalDevice
;
143 memset(&zfmt
, 0, sizeof(zfmt
));
144 hr
= IDirect3D7_EnumZBufferFormats(Direct3D
, devtype
, enum_z_fmt
, &zfmt
);
145 if (FAILED(hr
)) goto err
;
146 if (zfmt
.dwSize
== 0) goto err
;
148 memset(&ddsd
, 0, sizeof(ddsd
));
149 ddsd
.dwSize
= sizeof(ddsd
);
150 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
151 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
152 U4(ddsd
).ddpfPixelFormat
= zfmt
;
155 hr
= IDirectDraw7_CreateSurface(DirectDraw
, &ddsd
, &depth_buffer
, NULL
);
156 ok(SUCCEEDED(hr
), "CreateSurface failed, hr %#x.\n", hr
);
157 if (FAILED(hr
)) goto err
;
159 hr
= IDirectDrawSurface_AddAttachedSurface(Surface
, depth_buffer
);
160 ok(SUCCEEDED(hr
), "AddAttachedSurface failed, hr %#x.\n", hr
);
161 if (FAILED(hr
)) goto err
;
163 hr
= IDirect3D7_CreateDevice(Direct3D
, devtype
, Surface
, &Direct3DDevice
);
164 if (FAILED(hr
) || !Direct3DDevice
) goto err
;
168 if(DirectDraw
) IDirectDraw7_Release(DirectDraw
);
169 if (depth_buffer
) IDirectDrawSurface7_Release(depth_buffer
);
170 if(Surface
) IDirectDrawSurface7_Release(Surface
);
171 if(Direct3D
) IDirect3D7_Release(Direct3D
);
172 if(Direct3DDevice
) IDirect3DDevice7_Release(Direct3DDevice
);
173 if(window
) DestroyWindow(window
);
177 static void releaseObjects(void)
179 IDirect3DDevice7_Release(Direct3DDevice
);
180 IDirect3D7_Release(Direct3D
);
181 IDirectDrawSurface7_Release(depth_buffer
);
182 IDirectDrawSurface7_Release(Surface
);
183 IDirectDraw7_Release(DirectDraw
);
184 DestroyWindow(window
);
187 static DWORD
getPixelColor(IDirect3DDevice7
*device
, UINT x
, UINT y
)
192 RECT rectToLock
= {x
, y
, x
+1, y
+1};
193 IDirectDrawSurface7
*surf
= NULL
;
195 /* Some implementations seem to dislike direct locking on the front buffer. Thus copy the front buffer
196 * to an offscreen surface and lock it instead of the front buffer
198 memset(&ddsd
, 0, sizeof(ddsd
));
199 ddsd
.dwSize
= sizeof(ddsd
);
200 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
201 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
204 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
;
205 hr
= IDirectDraw7_CreateSurface(DirectDraw
, &ddsd
, &surf
, NULL
);
206 ok(hr
== DD_OK
, "IDirectDraw7_CreateSurface failed with %08x\n", hr
);
209 trace("cannot create helper surface\n");
213 memset(&ddsd
, 0, sizeof(ddsd
));
214 ddsd
.dwSize
= sizeof(ddsd
);
215 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
217 hr
= IDirectDrawSurface_BltFast(surf
, 0, 0, Surface
, NULL
, 0);
218 ok(hr
== DD_OK
, "IDirectDrawSurface7_BltFast returned %08x\n", hr
);
221 trace("Cannot blit\n");
226 hr
= IDirectDrawSurface7_Lock(surf
, &rectToLock
, &ddsd
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
229 trace("Can't lock the offscreen surface, hr=%08x\n", hr
);
234 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
235 * really important for these tests
237 ret
= ((DWORD
*) ddsd
.lpSurface
)[0] & 0x00ffffff;
238 hr
= IDirectDrawSurface7_Unlock(surf
, NULL
);
241 trace("Can't unlock the offscreen surface, hr=%08x\n", hr
);
245 IDirectDrawSurface7_Release(surf
);
249 static void set_viewport_size(IDirect3DDevice7
*device
)
251 D3DVIEWPORT7 vp
= {0};
254 IDirectDrawSurface7
*target
;
256 hr
= IDirect3DDevice7_GetRenderTarget(device
, &target
);
257 ok(hr
== D3D_OK
, "IDirect3DDevice7_GetRenderTarget returned %08x\n", hr
);
259 memset(&ddsd
, 0, sizeof(ddsd
));
260 ddsd
.dwSize
= sizeof(ddsd
);
261 hr
= IDirectDrawSurface7_GetSurfaceDesc(target
, &ddsd
);
262 ok(hr
== D3D_OK
, "IDirectDrawSurface7_GetSurfaceDesc returned %08x\n", hr
);
263 IDirectDrawSurface7_Release(target
);
265 vp
.dwWidth
= ddsd
.dwWidth
;
266 vp
.dwHeight
= ddsd
.dwHeight
;
267 hr
= IDirect3DDevice7_SetViewport(device
, &vp
);
268 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetViewport returned %08x\n", hr
);
285 static void lighting_test(IDirect3DDevice7
*device
)
288 DWORD fvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
289 DWORD nfvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_NORMAL
;
294 1.0f
, 0.0f
, 0.0f
, 0.0f
,
295 0.0f
, 1.0f
, 0.0f
, 0.0f
,
296 0.0f
, 0.0f
, 1.0f
, 0.0f
,
297 0.0f
, 0.0f
, 0.0f
, 1.0f
,
301 struct vec3 position
;
306 {{-1.0f
, -1.0f
, 0.1f
}, 0xffff0000},
307 {{-1.0f
, 0.0f
, 0.1f
}, 0xffff0000},
308 {{ 0.0f
, 0.0f
, 0.1f
}, 0xffff0000},
309 {{ 0.0f
, -1.0f
, 0.1f
}, 0xffff0000},
313 {{-1.0f
, 0.0f
, 0.1f
}, 0xff00ff00},
314 {{-1.0f
, 1.0f
, 0.1f
}, 0xff00ff00},
315 {{ 0.0f
, 1.0f
, 0.1f
}, 0xff00ff00},
316 {{ 0.0f
, 0.0f
, 0.1f
}, 0xff00ff00},
318 struct nvertex unlitnquad
[] =
320 { 0.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
321 { 0.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
322 { 1.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
323 { 1.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
325 struct nvertex litnquad
[] =
327 { 0.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
328 { 0.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
329 { 1.0f
, 1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
330 { 1.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xffffff00},
332 WORD Indices
[] = {0, 1, 2, 2, 3, 0};
334 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
335 ok(hr
== D3D_OK
, "IDirect3DDevice7_Clear failed with %08x\n", hr
);
337 /* Setup some states that may cause issues */
338 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
339 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetTransform returned %08x\n", hr
);
340 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
341 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetTransform returned %08x\n", hr
);
342 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
343 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetTransform returned %08x\n", hr
);
344 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
345 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
346 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
347 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
348 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
349 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
350 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_STENCILENABLE
, FALSE
);
351 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
352 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ALPHATESTENABLE
, FALSE
);
353 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
354 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
);
355 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
356 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
357 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed with %08x\n", hr
);
359 hr
= IDirect3DDevice7_BeginScene(device
);
360 ok(hr
== D3D_OK
, "IDirect3DDevice7_BeginScene failed with %08x\n", hr
);
363 /* No lights are defined... That means, lit vertices should be entirely black */
364 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
365 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
366 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, fvf
, unlitquad
, 4 /* NumVerts */,
367 Indices
, 6 /* Indexcount */, 0 /* flags */);
368 ok(hr
== D3D_OK
, "IDirect3DDevice7_DrawIndexedPrimitiveUP failed with %08x\n", hr
);
370 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
371 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
372 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, fvf
, litquad
, 4 /* NumVerts */,
373 Indices
, 6 /* Indexcount */, 0 /* flags */);
374 ok(hr
== D3D_OK
, "IDirect3DDevice7_DrawIndexedPrimitiveUP failed with %08x\n", hr
);
376 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
377 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
378 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, nfvf
, unlitnquad
, 4 /* NumVerts */,
379 Indices
, 6 /* Indexcount */, 0 /* flags */);
380 ok(hr
== D3D_OK
, "IDirect3DDevice7_DrawIndexedPrimitiveUP failed with %08x\n", hr
);
382 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
383 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
384 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, nfvf
, litnquad
, 4 /* NumVerts */,
385 Indices
, 6 /* Indexcount */, 0 /* flags */);
386 ok(hr
== D3D_OK
, "IDirect3DDevice7_DrawIndexedPrimitiveUP failed with %08x\n", hr
);
388 hr
= IDirect3DDevice7_EndScene(device
);
389 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndScene failed with %08x\n", hr
);
392 color
= getPixelColor(device
, 160, 360); /* Lower left quad - unlit without normals */
393 ok(color
== 0x00ff0000, "Unlit quad without normals has color 0x%08x, expected 0x00ff0000.\n", color
);
394 color
= getPixelColor(device
, 160, 120); /* Upper left quad - lit without normals */
395 ok(color
== 0x00000000, "Lit quad without normals has color 0x%08x, expected 0x00000000.\n", color
);
396 color
= getPixelColor(device
, 480, 360); /* Lower right quad - unlit with normals */
397 ok(color
== 0x000000ff, "Unlit quad with normals has color 0x%08x, expected 0x000000ff.\n", color
);
398 color
= getPixelColor(device
, 480, 120); /* Upper right quad - lit with normals */
399 ok(color
== 0x00000000, "Lit quad with normals has color 0x%08x, expected 0x00000000.\n", color
);
401 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
402 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
405 static void clear_test(IDirect3DDevice7
*device
)
407 /* Tests the correctness of clearing parameters */
413 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
414 ok(hr
== D3D_OK
, "IDirect3DDevice7_Clear failed with %08x\n", hr
);
416 /* Positive x, negative y */
418 U2(rect
[0]).y1
= 480;
419 U3(rect
[0]).x2
= 320;
420 U4(rect
[0]).y2
= 240;
422 /* Positive x, positive y */
425 U3(rect
[1]).x2
= 320;
426 U4(rect
[1]).y2
= 240;
427 /* Clear 2 rectangles with one call. Shows that a positive value is returned, but the negative rectangle
428 * is ignored, the positive is still cleared afterwards
430 hr
= IDirect3DDevice7_Clear(device
, 2, rect
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
431 ok(hr
== D3D_OK
, "IDirect3DDevice7_Clear failed with %08x\n", hr
);
433 /* negative x, negative y */
434 U1(rect_negneg
).x1
= 640;
435 U2(rect_negneg
).y1
= 240;
436 U3(rect_negneg
).x2
= 320;
437 U4(rect_negneg
).y2
= 0;
438 hr
= IDirect3DDevice7_Clear(device
, 1, &rect_negneg
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0, 0);
439 ok(hr
== D3D_OK
, "IDirect3DDevice7_Clear failed with %08x\n", hr
);
441 color
= getPixelColor(device
, 160, 360); /* lower left quad */
442 ok(color
== 0x00ffffff, "Clear rectangle 3(pos, neg) has color %08x\n", color
);
443 color
= getPixelColor(device
, 160, 120); /* upper left quad */
444 ok(color
== 0x00ff0000, "Clear rectangle 1(pos, pos) has color %08x\n", color
);
445 color
= getPixelColor(device
, 480, 360); /* lower right quad */
446 ok(color
== 0x00ffffff, "Clear rectangle 4(NULL) has color %08x\n", color
);
447 color
= getPixelColor(device
, 480, 120); /* upper right quad */
448 ok(color
== 0x00ffffff, "Clear rectangle 4(neg, neg) has color %08x\n", color
);
463 static void fog_test(IDirect3DDevice7
*device
)
467 float start
= 0.0, end
= 1.0;
470 /* Gets full z based fog with linear fog, no fog with specular color */
471 struct sVertex untransformed_1
[] = {
472 {-1, -1, 0.1f
, 0xFFFF0000, 0xFF000000 },
473 {-1, 0, 0.1f
, 0xFFFF0000, 0xFF000000 },
474 { 0, 0, 0.1f
, 0xFFFF0000, 0xFF000000 },
475 { 0, -1, 0.1f
, 0xFFFF0000, 0xFF000000 },
477 /* Ok, I am too lazy to deal with transform matrices */
478 struct sVertex untransformed_2
[] = {
479 {-1, 0, 1.0f
, 0xFFFF0000, 0xFF000000 },
480 {-1, 1, 1.0f
, 0xFFFF0000, 0xFF000000 },
481 { 0, 1, 1.0f
, 0xFFFF0000, 0xFF000000 },
482 { 0, 0, 1.0f
, 0xFFFF0000, 0xFF000000 },
484 /* Untransformed ones. Give them a different diffuse color to make the test look
485 * nicer. It also makes making sure that they are drawn correctly easier.
487 struct sVertexT transformed_1
[] = {
488 {320, 0, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
489 {640, 0, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
490 {640, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
491 {320, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
493 struct sVertexT transformed_2
[] = {
494 {320, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
495 {640, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
496 {640, 480, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
497 {320, 480, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
499 WORD Indices
[] = {0, 1, 2, 2, 3, 0};
500 D3DMATRIX ident_mat
=
502 1.0f
, 0.0f
, 0.0f
, 0.0f
,
503 0.0f
, 1.0f
, 0.0f
, 0.0f
,
504 0.0f
, 0.0f
, 1.0f
, 0.0f
,
505 0.0f
, 0.0f
, 0.0f
, 1.0f
,
507 D3DMATRIX world_mat1
=
509 1.0f
, 0.0f
, 0.0f
, 0.0f
,
510 0.0f
, 1.0f
, 0.0f
, 0.0f
,
511 0.0f
, 0.0f
, 1.0f
, 0.0f
,
512 0.0f
, 0.0f
, -0.5f
, 1.0f
,
514 D3DMATRIX world_mat2
=
516 1.0f
, 0.0f
, 0.0f
, 0.0f
,
517 0.0f
, 1.0f
, 0.0f
, 0.0f
,
518 0.0f
, 0.0f
, 1.0f
, 0.0f
,
519 0.0f
, 0.0f
, 1.0f
, 1.0f
,
523 1.0f
, 0.0f
, 0.0f
, 0.0f
,
524 0.0f
, 1.0f
, 0.0f
, 0.0f
,
525 0.0f
, 0.0f
, 1.0f
, 0.0f
,
526 0.0f
, 0.0f
, -1.0f
, 1.0f
,
528 struct sVertex far_quad1
[] =
530 {-1.0f
, -1.0f
, 0.5f
, 0xffff0000, 0xff000000},
531 {-1.0f
, 0.0f
, 0.5f
, 0xffff0000, 0xff000000},
532 { 0.0f
, 0.0f
, 0.5f
, 0xffff0000, 0xff000000},
533 { 0.0f
, -1.0f
, 0.5f
, 0xffff0000, 0xff000000},
535 struct sVertex far_quad2
[] =
537 {-1.0f
, 0.0f
, 1.5f
, 0xffff0000, 0xff000000},
538 {-1.0f
, 1.0f
, 1.5f
, 0xffff0000, 0xff000000},
539 { 0.0f
, 1.0f
, 1.5f
, 0xffff0000, 0xff000000},
540 { 0.0f
, 0.0f
, 1.5f
, 0xffff0000, 0xff000000},
543 memset(&caps
, 0, sizeof(caps
));
544 hr
= IDirect3DDevice7_GetCaps(device
, &caps
);
545 ok(hr
== D3D_OK
, "IDirect3DDevice7_GetCaps returned %08x\n", hr
);
546 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
547 ok(hr
== D3D_OK
, "IDirect3DDevice7_Clear returned %08x\n", hr
);
549 /* Setup initial states: No lighting, fog on, fog color */
550 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
551 ok(hr
== D3D_OK
, "Turning off lighting returned %08x\n", hr
);
552 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, TRUE
);
553 ok(hr
== D3D_OK
, "Turning on fog calculations returned %08x\n", hr
);
554 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGCOLOR
, 0xFF00FF00 /* A nice green */);
555 ok(hr
== D3D_OK
, "Setting fog color returned %08x\n", hr
);
557 /* First test: Both table fog and vertex fog off */
558 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, D3DFOG_NONE
);
559 ok(hr
== D3D_OK
, "Turning off table fog returned %08x\n", hr
);
560 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGVERTEXMODE
, D3DFOG_NONE
);
561 ok(hr
== D3D_OK
, "Turning off vertex fog returned %08x\n", hr
);
563 /* Start = 0, end = 1. Should be default, but set them */
564 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGSTART
, *((DWORD
*) &start
));
565 ok(hr
== D3D_OK
, "Setting fog start returned %08x\n", hr
);
566 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGEND
, *((DWORD
*) &end
));
567 ok(hr
== D3D_OK
, "Setting fog end returned %08x\n", hr
);
569 if(IDirect3DDevice7_BeginScene(device
) == D3D_OK
)
571 /* Untransformed, vertex fog = NONE, table fog = NONE: Read the fog weighting from the specular color */
572 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
,
573 untransformed_1
, 4, Indices
, 6, 0);
574 ok(hr
== D3D_OK
, "DrawIndexedPrimitive returned %08x\n", hr
);
576 /* That makes it use the Z value */
577 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGVERTEXMODE
, D3DFOG_LINEAR
);
578 ok(hr
== D3D_OK
, "Setting fog vertex mode to D3DFOG_LINEAR returned %08x\n", hr
);
579 /* Untransformed, vertex fog != none (or table fog != none):
580 * Use the Z value as input into the equation
582 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
,
583 untransformed_2
, 4, Indices
, 6, 0);
584 ok(hr
== D3D_OK
, "DrawIndexedPrimitive returned %08x\n", hr
);
586 /* Transformed, vertex fog != NONE, pixel fog == NONE: Use specular color alpha component */
587 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
,
588 transformed_1
, 4, Indices
, 6, 0);
589 ok(hr
== D3D_OK
, "DrawIndexedPrimitive returned %08x\n", hr
);
591 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, D3DFOG_LINEAR
);
592 ok( hr
== D3D_OK
, "Setting fog table mode to D3DFOG_LINEAR returned %08x\n", hr
);
593 /* Transformed, table fog != none, vertex anything: Use Z value as input to the fog
596 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
,
597 transformed_2
, 4, Indices
, 6, 0);
598 ok(hr
== D3D_OK
, "DrawIndexedPrimitive returned %08x\n", hr
);
600 hr
= IDirect3DDevice7_EndScene(device
);
601 ok(hr
== D3D_OK
, "EndScene returned %08x\n", hr
);
605 ok(FALSE
, "BeginScene failed\n");
608 color
= getPixelColor(device
, 160, 360);
609 ok(color_match(color
, 0x00FF0000, 1), "Untransformed vertex with no table or vertex fog has color %08x\n", color
);
610 color
= getPixelColor(device
, 160, 120);
611 ok(color_match(color
, 0x0000FF00, 1), "Untransformed vertex with linear vertex fog has color %08x\n", color
);
612 color
= getPixelColor(device
, 480, 120);
613 ok(color_match(color
, 0x00FFFF00, 1), "Transformed vertex with linear vertex fog has color %08x\n", color
);
614 if(caps
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_FOGTABLE
)
616 color
= getPixelColor(device
, 480, 360);
617 ok(color_match(color
, 0x0000FF00, 1), "Transformed vertex with linear table fog has color %08x\n", color
);
621 /* Without fog table support the vertex fog is still applied, even though table fog is turned on.
622 * The settings above result in no fogging with vertex fog
624 color
= getPixelColor(device
, 480, 120);
625 ok(color
== 0x00FFFF00, "Transformed vertex with linear vertex fog has color %08x\n", color
);
626 trace("Info: Table fog not supported by this device\n");
629 if (caps
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_FOGTABLE
)
631 /* A simple fog + non-identity world matrix test */
632 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &world_mat1
);
633 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetTransform returned %#08x\n", hr
);
635 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, D3DFOG_LINEAR
);
636 ok(hr
== D3D_OK
, "Setting fog table mode to D3DFOG_LINEAR returned %#08x\n", hr
);
637 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGVERTEXMODE
, D3DFOG_NONE
);
638 ok(hr
== D3D_OK
, "Turning off vertex fog returned %#08x\n", hr
);
640 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
641 ok(hr
== D3D_OK
, "IDirect3DDevice7_Clear returned %#08x\n", hr
);
643 if (IDirect3DDevice7_BeginScene(device
) == D3D_OK
)
645 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
,
646 D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
, far_quad1
, 4, Indices
, 6, 0);
647 ok(hr
== D3D_OK
, "DrawIndexedPrimitive returned %#08x\n", hr
);
649 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
,
650 D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
, far_quad2
, 4, Indices
, 6, 0);
651 ok(hr
== D3D_OK
, "DrawIndexedPrimitive returned %#08x\n", hr
);
653 hr
= IDirect3DDevice7_EndScene(device
);
654 ok(hr
== D3D_OK
, "EndScene returned %#08x\n", hr
);
658 ok(FALSE
, "BeginScene failed\n");
661 color
= getPixelColor(device
, 160, 360);
662 ok(color_match(color
, 0x00ff0000, 4), "Unfogged quad has color %08x\n", color
);
663 color
= getPixelColor(device
, 160, 120);
664 ok(color_match(color
, 0x0000ff00, 1), "Fogged out quad has color %08x\n", color
);
666 /* Test fog behavior with an orthogonal (but not identity) projection matrix */
667 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &world_mat2
);
668 ok(hr
== D3D_OK
, "SetTransform returned %#08x\n", hr
);
669 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &proj_mat
);
670 ok(hr
== D3D_OK
, "SetTransform returned %#08x\n", hr
);
672 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
673 ok(hr
== D3D_OK
, "Clear returned %#08x\n", hr
);
675 if (IDirect3DDevice7_BeginScene(device
) == D3D_OK
)
677 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
,
678 D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
, untransformed_1
, 4, Indices
, 6, 0);
679 ok(hr
== D3D_OK
, "DrawIndexedPrimitiveUP returned %#08x\n", hr
);
681 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
,
682 D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
, untransformed_2
, 4, Indices
, 6, 0);
683 ok(hr
== D3D_OK
, "DrawIndexedPrimitiveUP returned %#08x\n", hr
);
685 hr
= IDirect3DDevice7_EndScene(device
);
686 ok(hr
== D3D_OK
, "EndScene returned %#08x\n", hr
);
690 ok(FALSE
, "BeginScene failed\n");
693 color
= getPixelColor(device
, 160, 360);
694 ok(color_match(color
, 0x00e51900, 4), "Partially fogged quad has color %08x\n", color
);
695 color
= getPixelColor(device
, 160, 120);
696 ok(color_match(color
, 0x0000ff00, 1), "Fogged out quad has color %08x\n", color
);
698 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &ident_mat
);
699 ok(hr
== D3D_OK
, "SetTransform returned %#08x\n", hr
);
700 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &ident_mat
);
701 ok(hr
== D3D_OK
, "SetTransform returned %#08x\n", hr
);
705 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests\n");
708 /* Turn off the fog master switch to avoid confusing other tests */
709 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
710 ok(hr
== D3D_OK
, "Turning off fog calculations returned %08x\n", hr
);
713 static void blt_test(IDirect3DDevice7
*device
)
715 IDirectDrawSurface7
*backbuffer
= NULL
, *offscreen
= NULL
;
719 memset(&ddsd
, 0, sizeof(ddsd
));
720 ddsd
.dwSize
= sizeof(ddsd
);
721 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
722 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
725 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_3DDEVICE
;
726 hr
= IDirectDraw7_CreateSurface(DirectDraw
, &ddsd
, &offscreen
, NULL
);
727 ok(hr
== D3D_OK
, "Creating the offscreen render target failed, hr = %08x\n", hr
);
729 /* Offscreen blits with the same source as destination */
732 RECT src_rect
, dst_rect
;
734 /* Blit the whole surface to itself */
735 hr
= IDirectDrawSurface_Blt(offscreen
, NULL
, offscreen
, NULL
, 0, NULL
);
736 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
738 /* Overlapped blit */
739 dst_rect
.left
= 0; dst_rect
.right
= 480;
740 dst_rect
.top
= 0; dst_rect
.bottom
= 480;
741 src_rect
.left
= 160; src_rect
.right
= 640;
742 src_rect
.top
= 0; src_rect
.bottom
= 480;
743 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, offscreen
, &src_rect
, 0, NULL
);
744 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
746 /* Overlapped blit, flip-y through source rectangle (not allowed) */
747 dst_rect
.left
= 0; dst_rect
.right
= 480;
748 dst_rect
.top
= 0; dst_rect
.bottom
= 480;
749 src_rect
.left
= 160; src_rect
.right
= 640;
750 src_rect
.top
= 480; src_rect
.bottom
= 0;
751 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, offscreen
, &src_rect
, 0, NULL
);
752 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
754 /* Overlapped blit, with shrinking in x */
755 dst_rect
.left
= 0; dst_rect
.right
= 480;
756 dst_rect
.top
= 0; dst_rect
.bottom
= 480;
757 src_rect
.left
= 160; src_rect
.right
= 480;
758 src_rect
.top
= 0; src_rect
.bottom
= 480;
759 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, offscreen
, &src_rect
, 0, NULL
);
760 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
763 hr
= IDirect3DDevice7_GetRenderTarget(device
, &backbuffer
);
764 ok(hr
== D3D_OK
, "Unable to obtain a surface pointer to the backbuffer, hr = %08x\n", hr
);
766 /* backbuffer ==> texture blits */
767 if(SUCCEEDED(hr
) && offscreen
)
769 RECT src_rect
, dst_rect
;
771 /* backbuffer ==> texture, src_rect=NULL, dst_rect=NULL, no scaling */
772 hr
= IDirectDrawSurface_Blt(offscreen
, NULL
, backbuffer
, NULL
, 0, NULL
);
773 ok(hr
== DD_OK
, "fullscreen Blt from backbuffer => texture failed with hr = %08x\n", hr
);
775 /* backbuffer ==> texture, full surface blits, no scaling */
776 dst_rect
.left
= 0; dst_rect
.right
= 640;
777 dst_rect
.top
= 0; dst_rect
.bottom
= 480;
778 src_rect
.left
= 0; src_rect
.right
= 640;
779 src_rect
.top
= 0; src_rect
.bottom
= 480;
780 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, backbuffer
, &src_rect
, 0, NULL
);
781 ok(hr
== DD_OK
, "fullscreen Blt from backbuffer => texture failed with hr = %08x\n", hr
);
783 /* backbuffer ==> texture, flip in y-direction through source rectangle, no scaling (allowed) */
784 dst_rect
.left
= 0; dst_rect
.right
= 640;
785 dst_rect
.top
= 480; dst_rect
.top
= 0;
786 src_rect
.left
= 0; src_rect
.right
= 640;
787 src_rect
.top
= 0; src_rect
.bottom
= 480;
788 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, backbuffer
, &src_rect
, 0, NULL
);
789 ok(hr
== DD_OK
, "backbuffer => texture flip-y src_rect failed with hr = %08x\n", hr
);
791 /* backbuffer ==> texture, flip in x-direction through source rectangle, no scaling (not allowed) */
792 dst_rect
.left
= 640; dst_rect
.right
= 0;
793 dst_rect
.top
= 0; dst_rect
.top
= 480;
794 src_rect
.left
= 0; src_rect
.right
= 640;
795 src_rect
.top
= 0; src_rect
.bottom
= 480;
796 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, backbuffer
, &src_rect
, 0, NULL
);
797 ok(hr
== DDERR_INVALIDRECT
, "backbuffer => texture flip-x src_rect failed with hr = %08x\n", hr
);
799 /* backbuffer ==> texture, flip in y-direction through destination rectangle (not allowed) */
800 dst_rect
.left
= 0; dst_rect
.right
= 640;
801 dst_rect
.top
= 0; dst_rect
.top
= 480;
802 src_rect
.left
= 0; src_rect
.right
= 640;
803 src_rect
.top
= 480; src_rect
.bottom
= 0;
804 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, backbuffer
, &src_rect
, 0, NULL
);
805 ok(hr
== DDERR_INVALIDRECT
, "backbuffer => texture flip-y dst_rect failed with hr = %08x\n", hr
);
807 /* backbuffer ==> texture, flip in x-direction through destination rectangle, no scaling (not allowed) */
808 dst_rect
.left
= 0; dst_rect
.right
= 640;
809 dst_rect
.top
= 0; dst_rect
.top
= 480;
810 src_rect
.left
= 640; src_rect
.right
= 0;
811 src_rect
.top
= 0; src_rect
.bottom
= 480;
812 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, backbuffer
, &src_rect
, 0, NULL
);
813 ok(hr
== DDERR_INVALIDRECT
, "backbuffer => texture flip-x dst_rect failed with hr = %08x\n", hr
);
816 if(offscreen
) IDirectDrawSurface7_Release(offscreen
);
817 if(backbuffer
) IDirectDrawSurface7_Release(backbuffer
);
820 static void offscreen_test(IDirect3DDevice7
*device
)
823 IDirectDrawSurface7
*backbuffer
= NULL
, *offscreen
= NULL
;
827 static float quad
[][5] = {
828 {-0.5f
, -0.5f
, 0.1f
, 0.0f
, 0.0f
},
829 {-0.5f
, 0.5f
, 0.1f
, 0.0f
, 1.0f
},
830 { 0.5f
, -0.5f
, 0.1f
, 1.0f
, 0.0f
},
831 { 0.5f
, 0.5f
, 0.1f
, 1.0f
, 1.0f
},
834 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
835 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
837 memset(&ddsd
, 0, sizeof(ddsd
));
838 ddsd
.dwSize
= sizeof(ddsd
);
839 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
840 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
843 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_3DDEVICE
;
844 hr
= IDirectDraw7_CreateSurface(DirectDraw
, &ddsd
, &offscreen
, NULL
);
845 ok(hr
== D3D_OK
, "Creating the offscreen render target failed, hr = %08x\n", hr
);
850 hr
= IDirect3DDevice7_GetRenderTarget(device
, &backbuffer
);
851 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %08x\n", hr
);
856 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
857 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
858 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
859 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
860 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_MINFILTER
, D3DFILTER_NEAREST
);
861 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MINFILTER failed (0x%08x)\n", hr
);
862 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_MAGFILTER
, D3DFILTER_NEAREST
);
863 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr
);
864 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
865 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned hr = %08x\n", hr
);
868 win_skip("Tests would crash on W2K with a refdevice\n");
872 if(IDirect3DDevice7_BeginScene(device
) == D3D_OK
) {
873 hr
= IDirect3DDevice7_SetRenderTarget(device
, offscreen
, 0);
874 ok(hr
== D3D_OK
, "SetRenderTarget failed, hr = %08x\n", hr
);
875 set_viewport_size(device
);
876 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
877 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
879 /* Draw without textures - Should result in a white quad */
880 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEX1
, quad
, 4, 0);
881 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
883 hr
= IDirect3DDevice7_SetRenderTarget(device
, backbuffer
, 0);
884 ok(hr
== D3D_OK
, "SetRenderTarget failed, hr = %08x\n", hr
);
885 set_viewport_size(device
);
887 hr
= IDirect3DDevice7_SetTexture(device
, 0, offscreen
);
888 ok(hr
== D3D_OK
, "SetTexture failed, %08x\n", hr
);
890 /* This time with the texture */
891 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEX1
, quad
, 4, 0);
892 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
894 IDirect3DDevice7_EndScene(device
);
897 /* Center quad - should be white */
898 color
= getPixelColor(device
, 320, 240);
899 ok(color
== 0x00ffffff, "Offscreen failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
900 /* Some quad in the cleared part of the texture */
901 color
= getPixelColor(device
, 170, 240);
902 ok(color
== 0x00ff00ff, "Offscreen failed: Got color 0x%08x, expected 0x00ff00ff.\n", color
);
903 /* Part of the originally cleared back buffer */
904 color
= getPixelColor(device
, 10, 10);
905 ok(color
== 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
907 /* Lower left corner of the screen, where back buffer offscreen rendering draws the offscreen texture.
908 * It should be red, but the offscreen texture may leave some junk there. Not tested yet. Depending on
909 * the offscreen rendering mode this test would succeed or fail
911 color
= getPixelColor(device
, 10, 470);
912 ok(color
== 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
916 hr
= IDirect3DDevice7_SetTexture(device
, 0, NULL
);
917 ok(SUCCEEDED(hr
), "IDirect3DDevice7_SetTexture returned %#x.\n", hr
);
921 hr
= IDirect3DDevice7_SetRenderTarget(device
, backbuffer
, 0);
922 ok(SUCCEEDED(hr
), "IDirect3DDevice7_SetRenderTarget returned %#x.\n", hr
);
923 IDirectDrawSurface7_Release(backbuffer
);
926 IDirectDrawSurface7_Release(offscreen
);
930 static void alpha_test(IDirect3DDevice7
*device
)
933 IDirectDrawSurface7
*backbuffer
= NULL
, *offscreen
= NULL
;
934 DWORD color
, red
, green
, blue
;
939 struct vec3 position
;
944 {{-1.0f
, -1.0f
, 0.1f
}, 0x4000ff00},
945 {{-1.0f
, 0.0f
, 0.1f
}, 0x4000ff00},
946 {{ 1.0f
, -1.0f
, 0.1f
}, 0x4000ff00},
947 {{ 1.0f
, 0.0f
, 0.1f
}, 0x4000ff00},
951 {{-1.0f
, 0.0f
, 0.1f
}, 0xc00000ff},
952 {{-1.0f
, 1.0f
, 0.1f
}, 0xc00000ff},
953 {{ 1.0f
, 0.0f
, 0.1f
}, 0xc00000ff},
954 {{ 1.0f
, 1.0f
, 0.1f
}, 0xc00000ff},
956 static float composite_quad
[][5] = {
957 { 0.0f
, -1.0f
, 0.1f
, 0.0f
, 1.0f
},
958 { 0.0f
, 1.0f
, 0.1f
, 0.0f
, 0.0f
},
959 { 1.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
},
960 { 1.0f
, 1.0f
, 0.1f
, 1.0f
, 0.0f
},
963 /* Clear the render target with alpha = 0.5 */
964 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x80ff0000, 0.0, 0);
965 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
967 memset(&ddsd
, 0, sizeof(ddsd
));
968 ddsd
.dwSize
= sizeof(ddsd
);
969 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
972 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_3DDEVICE
;
973 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
974 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
975 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
976 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
977 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
978 U5(U4(ddsd
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
979 hr
= IDirectDraw7_CreateSurface(DirectDraw
, &ddsd
, &offscreen
, NULL
);
980 ok(hr
== D3D_OK
, "Creating the offscreen render target failed, hr = %08x\n", hr
);
984 hr
= IDirect3DDevice7_GetRenderTarget(device
, &backbuffer
);
985 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %08x\n", hr
);
990 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
991 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
992 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
993 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
994 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_MINFILTER
, D3DFILTER_NEAREST
);
995 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MINFILTER failed (0x%08x)\n", hr
);
996 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_MAGFILTER
, D3DFILTER_NEAREST
);
997 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr
);
999 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
1000 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1003 win_skip("Tests would crash on W2K with a refdevice\n");
1007 if(IDirect3DDevice7_BeginScene(device
) == D3D_OK
) {
1009 /* Draw two quads, one with src alpha blending, one with dest alpha blending. The
1010 * SRCALPHA / INVSRCALPHA blend doesn't give any surprises. Colors are blended based on
1013 * The DESTALPHA / INVDESTALPHA do not "work" on the regular buffer because there is no alpha.
1014 * They give essentially ZERO and ONE blend factors
1016 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
1017 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1018 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1019 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1020 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad1
, 4, 0);
1021 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
1023 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_DESTALPHA
);
1024 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1025 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVDESTALPHA
);
1026 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1027 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad2
, 4, 0);
1028 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
1030 /* Switch to the offscreen buffer, and redo the testing. SRCALPHA and DESTALPHA. The offscreen buffer
1031 * has an alpha channel on its own. Clear the offscreen buffer with alpha = 0.5 again, then draw the
1032 * quads again. The SRCALPHA/INVSRCALPHA doesn't give any surprises, but the DESTALPHA/INVDESTALPHA
1033 * blending works as supposed now - blend factor is 0.5 in both cases, not 0.75 as from the input
1036 hr
= IDirect3DDevice7_SetRenderTarget(device
, offscreen
, 0);
1037 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderTarget failed, hr = %08x\n", hr
);
1038 set_viewport_size(device
);
1039 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x80ff0000, 0.0, 0);
1040 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
1042 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
1043 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1044 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1045 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1046 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad1
, 4, 0);
1047 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
1049 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_DESTALPHA
);
1050 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1051 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVDESTALPHA
);
1052 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1053 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad2
, 4, 0);
1054 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
1056 hr
= IDirect3DDevice7_SetRenderTarget(device
, backbuffer
, 0);
1057 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderTarget failed, hr = %08x\n", hr
);
1058 set_viewport_size(device
);
1060 /* Render the offscreen texture onto the frame buffer to be able to compare it regularly.
1061 * Disable alpha blending for the final composition
1063 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
);
1064 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1066 hr
= IDirect3DDevice7_SetTexture(device
, 0, offscreen
);
1067 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetTexture failed, hr = %08x\n", hr
);
1068 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEX1
, composite_quad
, 4, 0);
1069 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
1070 hr
= IDirect3DDevice7_SetTexture(device
, 0, NULL
);
1071 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetTexture failed, hr = %08x\n", hr
);
1073 hr
= IDirect3DDevice7_EndScene(device
);
1074 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndScene failed, hr = %08x\n", hr
);
1077 color
= getPixelColor(device
, 160, 360);
1078 red
= (color
& 0x00ff0000) >> 16;
1079 green
= (color
& 0x0000ff00) >> 8;
1080 blue
= (color
& 0x000000ff);
1081 ok(red
>= 0xbe && red
<= 0xc0 && green
>= 0x39 && green
<= 0x41 && blue
== 0x00,
1082 "SRCALPHA on frame buffer returned color 0x%08x, expected 0x00bf4000\n", color
);
1084 color
= getPixelColor(device
, 160, 120);
1085 red
= (color
& 0x00ff0000) >> 16;
1086 green
= (color
& 0x0000ff00) >> 8;
1087 blue
= (color
& 0x000000ff);
1088 ok(red
== 0x00 && green
== 0x00 && blue
>= 0xfe && blue
<= 0xff ,
1089 "DSTALPHA on frame buffer returned color 0x%08x, expected 0x000000ff\n", color
);
1091 color
= getPixelColor(device
, 480, 360);
1092 red
= (color
& 0x00ff0000) >> 16;
1093 green
= (color
& 0x0000ff00) >> 8;
1094 blue
= (color
& 0x000000ff);
1095 ok(red
>= 0xbe && red
<= 0xc0 && green
>= 0x39 && green
<= 0x41 && blue
== 0x00,
1096 "SRCALPHA on texture returned color 0x%08x, expected 0x00bf4000\n", color
);
1098 color
= getPixelColor(device
, 480, 120);
1099 red
= (color
& 0x00ff0000) >> 16;
1100 green
= (color
& 0x0000ff00) >> 8;
1101 blue
= (color
& 0x000000ff);
1102 ok(red
>= 0x7e && red
<= 0x81 && green
== 0x00 && blue
>= 0x7e && blue
<= 0x81,
1103 "DSTALPHA on texture returned color 0x%08x, expected 0x00800080\n", color
);
1106 if(offscreen
) IDirectDrawSurface7_Release(offscreen
);
1107 if(backbuffer
) IDirectDrawSurface7_Release(backbuffer
);
1110 static void rhw_zero_test(IDirect3DDevice7
*device
)
1112 /* Test if it will render a quad correctly when vertex rhw = 0 */
1122 {0, 100, 0, 0, 0xffffffff},
1123 {0, 0, 0, 0, 0xffffffff},
1124 {100, 100, 0, 0, 0xffffffff},
1125 {100, 0, 0, 0, 0xffffffff},
1128 /* Clear to black */
1129 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0, 0.0, 0);
1130 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
1132 hr
= IDirect3DDevice7_BeginScene(device
);
1133 ok(hr
== D3D_OK
, "IDirect3DDevice7_BeginScene failed with %08x\n", hr
);
1135 if (SUCCEEDED(hr
)) {
1136 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, quad1
, 4, 0);
1137 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
1139 hr
= IDirect3DDevice7_EndScene(device
);
1140 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndScene failed, hr = %08x\n", hr
);
1143 color
= getPixelColor(device
, 5, 5);
1144 ok(color
== 0xffffff ||
1145 broken(color
== 0), /* VMware */
1146 "Got color %08x, expected 00ffffff\n", color
);
1148 color
= getPixelColor(device
, 105, 105);
1149 ok(color
== 0, "Got color %08x, expected 00000000\n", color
);
1152 static BOOL
D3D1_createObjects(void)
1157 D3DEXECUTEBUFFERDESC exdesc
;
1158 D3DVIEWPORT vp_data
;
1160 /* An IDirect3DDevice cannot be queryInterfaced from an IDirect3DDevice7 on windows */
1161 hr
= DirectDrawCreate(NULL
, &DirectDraw1
, NULL
);
1163 ok(hr
==DD_OK
|| hr
==DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreate returned: %x\n", hr
);
1168 wc
.lpfnWndProc
= DefWindowProcA
;
1169 wc
.lpszClassName
= "texturemapblend_test_wc";
1170 RegisterClassA(&wc
);
1171 window
= CreateWindowA("texturemapblend_test_wc", "texturemapblend_test",
1172 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
1174 hr
= IDirectDraw_SetCooperativeLevel(DirectDraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1175 ok(hr
==DD_OK
, "SetCooperativeLevel returned: %x\n", hr
);
1180 hr
= IDirectDraw_SetDisplayMode(DirectDraw1
, 640, 480, 32);
1182 /* 24 bit is fine too */
1183 hr
= IDirectDraw_SetDisplayMode(DirectDraw1
, 640, 480, 24);
1185 ok(hr
==DD_OK
|| hr
== DDERR_UNSUPPORTED
, "SetDisplayMode returned: %x\n", hr
);
1190 hr
= IDirectDraw_QueryInterface(DirectDraw1
, &IID_IDirect3D
, (void**) &Direct3D1
);
1191 ok(hr
==DD_OK
, "QueryInterface returned: %x\n", hr
);
1196 memset(&ddsd
, 0, sizeof(ddsd
));
1197 ddsd
.dwSize
= sizeof(ddsd
);
1198 ddsd
.dwFlags
= DDSD_CAPS
;
1199 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
;
1200 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &Surface1
, NULL
);
1201 ok(hr
==DD_OK
, "CreateSurface returned: %x\n", hr
);
1206 hr
= IDirectDrawSurface_QueryInterface(Surface1
, &IID_IDirect3DHALDevice
, (void **) &Direct3DDevice1
);
1208 trace("Creating a HAL device failed, trying Ref\n");
1209 hr
= IDirectDrawSurface_QueryInterface(Surface1
, &IID_IDirect3DRefDevice
, (void **) &Direct3DDevice1
);
1211 ok(hr
==D3D_OK
, "Creating 3D device returned: %x\n", hr
);
1216 hr
= IDirect3D_CreateViewport(Direct3D1
, &Viewport
, NULL
);
1217 ok(hr
== D3D_OK
, "IDirect3D_CreateViewport failed: %08x\n", hr
);
1222 hr
= IDirect3DViewport_Initialize(Viewport
, Direct3D1
);
1223 ok(hr
== D3D_OK
|| hr
== DDERR_ALREADYINITIALIZED
, "IDirect3DViewport_Initialize returned %08x\n", hr
);
1224 hr
= IDirect3DDevice_AddViewport(Direct3DDevice1
, Viewport
);
1225 ok(hr
== D3D_OK
, "IDirect3DDevice_AddViewport returned %08x\n", hr
);
1226 vp_data
.dwSize
= sizeof(vp_data
);
1229 vp_data
.dwWidth
= 640;
1230 vp_data
.dwHeight
= 480;
1231 vp_data
.dvScaleX
= 1;
1232 vp_data
.dvScaleY
= 1;
1233 vp_data
.dvMaxX
= 640;
1234 vp_data
.dvMaxY
= 480;
1237 hr
= IDirect3DViewport_SetViewport(Viewport
, &vp_data
);
1238 ok(hr
== D3D_OK
, "IDirect3DViewport_SetViewport returned %08x\n", hr
);
1240 memset(&exdesc
, 0, sizeof(D3DEXECUTEBUFFERDESC
));
1241 exdesc
.dwSize
= sizeof(D3DEXECUTEBUFFERDESC
);
1242 exdesc
.dwFlags
= D3DDEB_BUFSIZE
| D3DDEB_CAPS
;
1243 exdesc
.dwBufferSize
= 512;
1244 exdesc
.dwCaps
= D3DDEBCAPS_SYSTEMMEMORY
;
1245 hr
= IDirect3DDevice_CreateExecuteBuffer(Direct3DDevice1
, &exdesc
, &ExecuteBuffer
, NULL
);
1246 ok(hr
== D3D_OK
, "IDirect3DDevice_CreateExecuteBuffer failed with %08x\n", hr
);
1254 static void D3D1_releaseObjects(void)
1256 if(ExecuteBuffer
) IDirect3DExecuteBuffer_Release(ExecuteBuffer
);
1257 if(Surface1
) IDirectDrawSurface_Release(Surface1
);
1258 if(Viewport
) IDirect3DViewport_Release(Viewport
);
1259 if(Direct3DDevice1
) IDirect3DDevice_Release(Direct3DDevice1
);
1260 if(Direct3D1
) IDirect3D_Release(Direct3D1
);
1261 if(DirectDraw1
) IDirectDraw_Release(DirectDraw1
);
1262 if(window
) DestroyWindow(window
);
1265 static DWORD
D3D1_getPixelColor(IDirectDraw
*DirectDraw1
, IDirectDrawSurface
*Surface
, UINT x
, UINT y
)
1270 RECT rectToLock
= {x
, y
, x
+1, y
+1};
1271 IDirectDrawSurface
*surf
= NULL
;
1273 /* Some implementations seem to dislike direct locking on the front buffer. Thus copy the front buffer
1274 * to an offscreen surface and lock it instead of the front buffer
1276 memset(&ddsd
, 0, sizeof(ddsd
));
1277 ddsd
.dwSize
= sizeof(ddsd
);
1278 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
1279 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
1281 ddsd
.dwHeight
= 480;
1282 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
;
1283 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &surf
, NULL
);
1284 ok(hr
== DD_OK
, "IDirectDraw_CreateSurface failed with %08x\n", hr
);
1287 trace("cannot create helper surface\n");
1291 memset(&ddsd
, 0, sizeof(ddsd
));
1292 ddsd
.dwSize
= sizeof(ddsd
);
1293 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
1295 hr
= IDirectDrawSurface_BltFast(surf
, 0, 0, Surface
, NULL
, 0);
1296 ok(hr
== DD_OK
, "IDirectDrawSurface_BltFast returned %08x\n", hr
);
1299 trace("Cannot blit\n");
1304 hr
= IDirectDrawSurface_Lock(surf
, &rectToLock
, &ddsd
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
1307 trace("Can't lock the offscreen surface, hr=%08x\n", hr
);
1312 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
1313 * really important for these tests
1315 ret
= ((DWORD
*) ddsd
.lpSurface
)[0] & 0x00ffffff;
1316 hr
= IDirectDrawSurface_Unlock(surf
, NULL
);
1319 trace("Can't unlock the offscreen surface, hr=%08x\n", hr
);
1323 IDirectDrawSurface_Release(surf
);
1327 #define EXEBUF_START_RENDER_STATES(count, ptr) do {\
1328 ((D3DINSTRUCTION*)(ptr))->bOpcode = D3DOP_STATERENDER;\
1329 ((D3DINSTRUCTION*)(ptr))->bSize = sizeof(D3DSTATE);\
1330 ((D3DINSTRUCTION*)(ptr))->wCount = count;\
1331 ptr = ((D3DINSTRUCTION*)(ptr))+1; } while (0)
1333 #define EXEBUF_PUT_RENDER_STATE(state, value, ptr) do {\
1334 U1(*((D3DSTATE*)(ptr))).drstRenderStateType = state; \
1335 U2(*((D3DSTATE*)(ptr))).dwArg[0] = value; \
1336 ptr = ((D3DSTATE*)(ptr))+1; } while (0)
1338 #define EXEBUF_PUT_PROCESSVERTICES(nvertices, ptr) do {\
1339 ((D3DINSTRUCTION*)(ptr))->bOpcode = D3DOP_PROCESSVERTICES;\
1340 ((D3DINSTRUCTION*)(ptr))->bSize = sizeof(D3DPROCESSVERTICES);\
1341 ((D3DINSTRUCTION*)(ptr))->wCount = 1;\
1342 ptr = ((D3DINSTRUCTION*)(ptr))+1;\
1343 ((D3DPROCESSVERTICES*)(ptr))->dwFlags = D3DPROCESSVERTICES_COPY;\
1344 ((D3DPROCESSVERTICES*)(ptr))->wStart = 0;\
1345 ((D3DPROCESSVERTICES*)(ptr))->wDest = 0;\
1346 ((D3DPROCESSVERTICES*)(ptr))->dwCount = nvertices;\
1347 ((D3DPROCESSVERTICES*)(ptr))->dwReserved = 0;\
1348 ptr = ((D3DPROCESSVERTICES*)(ptr))+1; } while (0)
1350 #define EXEBUF_END(ptr) do {\
1351 ((D3DINSTRUCTION*)(ptr))->bOpcode = D3DOP_EXIT;\
1352 ((D3DINSTRUCTION*)(ptr))->bSize = 0;\
1353 ((D3DINSTRUCTION*)(ptr))->wCount = 0;\
1354 ptr = ((D3DINSTRUCTION*)(ptr))+1; } while (0)
1356 #define EXEBUF_PUT_QUAD(base_idx, ptr) do {\
1357 ((D3DINSTRUCTION*)(ptr))->bOpcode = D3DOP_TRIANGLE;\
1358 ((D3DINSTRUCTION*)(ptr))->bSize = sizeof(D3DTRIANGLE);\
1359 ((D3DINSTRUCTION*)(ptr))->wCount = 2;\
1360 ptr = ((D3DINSTRUCTION*)(ptr))+1;\
1361 U1(*((D3DTRIANGLE*)(ptr))).v1 = base_idx;\
1362 U2(*((D3DTRIANGLE*)(ptr))).v2 = (base_idx) + 1; \
1363 U3(*((D3DTRIANGLE*)(ptr))).v3 = (base_idx) + 3; \
1364 ((D3DTRIANGLE*)(ptr))->wFlags = 0;\
1365 ptr = ((D3DTRIANGLE*)ptr)+1;\
1366 U1(*((D3DTRIANGLE*)(ptr))).v1 = (base_idx) + 1; \
1367 U2(*((D3DTRIANGLE*)(ptr))).v2 = (base_idx) + 2; \
1368 U3(*((D3DTRIANGLE*)(ptr))).v3 = (base_idx) + 3; \
1369 ((D3DTRIANGLE*)(ptr))->wFlags = 0;\
1370 ptr = ((D3DTRIANGLE*)(ptr))+1;\
1373 static HRESULT CALLBACK
TextureFormatEnumCallback(DDSURFACEDESC
*lpDDSD
, void *lpContext
)
1375 if (lpDDSD
->ddpfPixelFormat
.dwFlags
& DDPF_PALETTEINDEXED8
) {
1376 *(BOOL
*)lpContext
= TRUE
;
1379 return DDENUMRET_OK
;
1382 static void D3D1_TextureMapBlendTest(void)
1386 D3DEXECUTEBUFFERDESC exdesc
;
1387 D3DEXECUTEDATA exdata
;
1389 RECT rect
= { 0, 0, 64, 128 };
1390 DWORD color
, red
, blue
, green
;
1391 void *exe_buffer_ptr
;
1393 D3DTEXTUREHANDLE htex
;
1395 IDirectDrawSurface
*TexSurface
= NULL
;
1396 IDirect3DTexture
*Texture
= NULL
;
1397 IDirectDrawPalette
*Palette
= NULL
;
1398 PALETTEENTRY table1
[256];
1399 BOOL p8_textures_supported
= FALSE
;
1409 {0.0f
, 0.0f
, 0.0f
, 1.0f
, 0xffffffff, 0, 0.0f
, 0.0f
},
1410 {640.0f
, 0.0f
, 0.0f
, 1.0f
, 0xffffffff, 0, 1.0f
, 0.0f
},
1411 {640.0f
, 240.0f
, 0.0f
, 1.0f
, 0xffffffff, 0, 1.0f
, 1.0f
},
1412 {0.0f
, 240.0f
, 0.0f
, 1.0f
, 0xffffffff, 0, 0.0f
, 1.0f
},
1413 {0.0f
, 240.0f
, 0.0f
, 1.0f
, 0x80ffffff, 0, 0.0f
, 0.0f
},
1414 {640.0f
, 240.0f
, 0.0f
, 1.0f
, 0x80ffffff, 0, 1.0f
, 0.0f
},
1415 {640.0f
, 480.0f
, 0.0f
, 1.0f
, 0x80ffffff, 0, 1.0f
, 1.0f
},
1416 {0.0f
, 480.0f
, 0.0f
, 1.0f
, 0x80ffffff, 0, 0.0f
, 1.0f
}
1419 {0.0f
, 0.0f
, 0.0f
, 1.0f
, 0x00ff0080, 0, 0.0f
, 0.0f
},
1420 {640.0f
, 0.0f
, 0.0f
, 1.0f
, 0x00ff0080, 0, 1.0f
, 0.0f
},
1421 {640.0f
, 240.0f
, 0.0f
, 1.0f
, 0x00ff0080, 0, 1.0f
, 1.0f
},
1422 {0.0f
, 240.0f
, 0.0f
, 1.0f
, 0x00ff0080, 0, 0.0f
, 1.0f
},
1423 {0.0f
, 240.0f
, 0.0f
, 1.0f
, 0x008000ff, 0, 0.0f
, 0.0f
},
1424 {640.0f
, 240.0f
, 0.0f
, 1.0f
, 0x008000ff, 0, 1.0f
, 0.0f
},
1425 {640.0f
, 480.0f
, 0.0f
, 1.0f
, 0x008000ff, 0, 1.0f
, 1.0f
},
1426 {0.0f
, 480.0f
, 0.0f
, 1.0f
, 0x008000ff, 0, 0.0f
, 1.0f
}
1429 /* 1) Test alpha with DDPF_ALPHAPIXELS texture - should be taken from texture alpha channel*/
1430 memset (&ddsd
, 0, sizeof (ddsd
));
1431 ddsd
.dwSize
= sizeof (ddsd
);
1432 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
1433 ddsd
.dwHeight
= 128;
1435 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1436 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
1437 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
1438 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1439 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1440 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1441 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1442 U5(ddsd
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
1443 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &TexSurface
, NULL
);
1444 ok(hr
==D3D_OK
, "CreateSurface returned: %x\n", hr
);
1446 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1450 hr
= IDirectDrawSurface_QueryInterface(TexSurface
, &IID_IDirect3DTexture
,
1452 ok(hr
==D3D_OK
, "IDirectDrawSurface_QueryInterface returned: %x\n", hr
);
1454 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1458 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
1459 ddbltfx
.dwSize
= sizeof(ddbltfx
);
1460 U5(ddbltfx
).dwFillColor
= 0;
1461 hr
= IDirectDrawSurface_Blt(Surface1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1462 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1464 U5(ddbltfx
).dwFillColor
= 0xff0000ff;
1465 hr
= IDirectDrawSurface_Blt(TexSurface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1466 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1467 U5(ddbltfx
).dwFillColor
= 0x800000ff;
1468 hr
= IDirectDrawSurface_Blt(TexSurface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1469 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1471 memset(&exdesc
, 0, sizeof(D3DEXECUTEBUFFERDESC
));
1472 exdesc
.dwSize
= sizeof(D3DEXECUTEBUFFERDESC
);
1473 hr
= IDirect3DExecuteBuffer_Lock(ExecuteBuffer
, &exdesc
);
1474 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr
);
1476 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1480 memcpy(exdesc
.lpData
, test1_quads
, sizeof(test1_quads
));
1482 exe_buffer_ptr
= sizeof(test1_quads
) + (char*)exdesc
.lpData
;
1484 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr
);
1486 EXEBUF_START_RENDER_STATES(12, exe_buffer_ptr
);
1487 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
, exe_buffer_ptr
);
1488 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ZENABLE
, FALSE
, exe_buffer_ptr
);
1489 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_FOGENABLE
, FALSE
, exe_buffer_ptr
);
1490 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_SPECULARENABLE
, FALSE
, exe_buffer_ptr
);
1491 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREMAG
, D3DFILTER_NEAREST
, exe_buffer_ptr
);
1492 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREMIN
, D3DFILTER_NEAREST
, exe_buffer_ptr
);
1493 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_FILLMODE
, D3DFILL_SOLID
, exe_buffer_ptr
);
1494 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
, exe_buffer_ptr
);
1495 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
, exe_buffer_ptr
);
1496 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
, exe_buffer_ptr
);
1497 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREMAPBLEND
, D3DTBLEND_MODULATE
, exe_buffer_ptr
);
1498 hr
= IDirect3DTexture_GetHandle(Texture
, Direct3DDevice1
, &htex
);
1499 ok(hr
== D3D_OK
, "IDirect3DTexture_GetHandle failed with %08x\n", hr
);
1500 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE
, htex
, exe_buffer_ptr
);
1502 EXEBUF_PUT_QUAD(0, exe_buffer_ptr
);
1503 EXEBUF_PUT_QUAD(4, exe_buffer_ptr
);
1505 EXEBUF_END(exe_buffer_ptr
);
1507 exe_length
= ((char*)exe_buffer_ptr
- (char*)exdesc
.lpData
) - sizeof(test1_quads
);
1509 hr
= IDirect3DExecuteBuffer_Unlock(ExecuteBuffer
);
1511 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr
);
1514 memset(&exdata
, 0, sizeof(exdata
));
1515 exdata
.dwSize
= sizeof(exdata
);
1516 exdata
.dwVertexCount
= 8;
1517 exdata
.dwInstructionOffset
= sizeof(test1_quads
);
1518 exdata
.dwInstructionLength
= exe_length
;
1519 hr
= IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer
, &exdata
);
1520 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr
);
1522 hr
= IDirect3DDevice_BeginScene(Direct3DDevice1
);
1523 ok(hr
== D3D_OK
, "IDirect3DDevice_BeginScene failed with %08x\n", hr
);
1525 if (SUCCEEDED(hr
)) {
1526 hr
= IDirect3DDevice_Execute(Direct3DDevice1
, ExecuteBuffer
, Viewport
, D3DEXECUTE_UNCLIPPED
);
1527 ok(hr
== D3D_OK
, "IDirect3DDevice_Execute failed, hr = %08x\n", hr
);
1528 hr
= IDirect3DDevice_EndScene(Direct3DDevice1
);
1529 ok(hr
== D3D_OK
, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr
);
1532 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 5);
1533 red
= (color
& 0x00ff0000) >> 16;
1534 green
= (color
& 0x0000ff00) >> 8;
1535 blue
= (color
& 0x000000ff);
1536 ok(red
== 0 && green
== 0 && blue
>= 0x7e && blue
<= 0x82, "Got color %08x, expected 00000080 or near\n", color
);
1538 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 5);
1539 red
= (color
& 0x00ff0000) >> 16;
1540 green
= (color
& 0x0000ff00) >> 8;
1541 blue
= (color
& 0x000000ff);
1542 ok(red
== 0 && green
== 0 && blue
== 0xff, "Got color %08x, expected 000000ff or near\n", color
);
1544 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 245);
1545 red
= (color
& 0x00ff0000) >> 16;
1546 green
= (color
& 0x0000ff00) >> 8;
1547 blue
= (color
& 0x000000ff);
1548 ok(red
== 0 && green
== 0 && blue
>= 0x7e && blue
<= 0x82, "Got color %08x, expected 00000080 or near\n", color
);
1550 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 245);
1551 red
= (color
& 0x00ff0000) >> 16;
1552 green
= (color
& 0x0000ff00) >> 8;
1553 blue
= (color
& 0x000000ff);
1554 ok(red
== 0 && green
== 0 && blue
== 0xff, "Got color %08x, expected 000000ff or near\n", color
);
1556 /* 2) Test alpha with texture that has no alpha channel - alpha should be taken from diffuse color */
1557 if(Texture
) IDirect3DTexture_Release(Texture
);
1559 if(TexSurface
) IDirectDrawSurface_Release(TexSurface
);
1562 memset (&ddsd
, 0, sizeof (ddsd
));
1563 ddsd
.dwSize
= sizeof (ddsd
);
1564 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
1565 ddsd
.dwHeight
= 128;
1567 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1568 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
1569 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1570 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1571 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1572 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1573 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1575 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &TexSurface
, NULL
);
1576 ok(hr
==D3D_OK
, "CreateSurface returned: %x\n", hr
);
1578 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1582 hr
= IDirectDrawSurface_QueryInterface(TexSurface
, &IID_IDirect3DTexture
,
1584 ok(hr
==D3D_OK
, "IDirectDrawSurface_QueryInterface returned: %x\n", hr
);
1586 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1590 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
1591 ddbltfx
.dwSize
= sizeof(ddbltfx
);
1592 U5(ddbltfx
).dwFillColor
= 0;
1593 hr
= IDirectDrawSurface_Blt(Surface1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1594 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1596 U5(ddbltfx
).dwFillColor
= 0xff0000ff;
1597 hr
= IDirectDrawSurface_Blt(TexSurface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1598 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1599 U5(ddbltfx
).dwFillColor
= 0x800000ff;
1600 hr
= IDirectDrawSurface_Blt(TexSurface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1601 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1603 memset(&exdesc
, 0, sizeof(D3DEXECUTEBUFFERDESC
));
1604 exdesc
.dwSize
= sizeof(D3DEXECUTEBUFFERDESC
);
1605 hr
= IDirect3DExecuteBuffer_Lock(ExecuteBuffer
, &exdesc
);
1606 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr
);
1608 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1612 memcpy(exdesc
.lpData
, test1_quads
, sizeof(test1_quads
));
1614 exe_buffer_ptr
= sizeof(test1_quads
) + (char*)exdesc
.lpData
;
1616 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr
);
1618 EXEBUF_START_RENDER_STATES(1, exe_buffer_ptr
);
1619 hr
= IDirect3DTexture_GetHandle(Texture
, Direct3DDevice1
, &htex
);
1620 ok(hr
== D3D_OK
, "IDirect3DTexture_GetHandle failed with %08x\n", hr
);
1621 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE
, htex
, exe_buffer_ptr
);
1623 EXEBUF_PUT_QUAD(0, exe_buffer_ptr
);
1624 EXEBUF_PUT_QUAD(4, exe_buffer_ptr
);
1626 EXEBUF_END(exe_buffer_ptr
);
1628 exe_length
= ((char*)exe_buffer_ptr
- (char*)exdesc
.lpData
) - sizeof(test1_quads
);
1630 hr
= IDirect3DExecuteBuffer_Unlock(ExecuteBuffer
);
1632 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr
);
1635 memset(&exdata
, 0, sizeof(exdata
));
1636 exdata
.dwSize
= sizeof(exdata
);
1637 exdata
.dwVertexCount
= 8;
1638 exdata
.dwInstructionOffset
= sizeof(test1_quads
);
1639 exdata
.dwInstructionLength
= exe_length
;
1640 hr
= IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer
, &exdata
);
1641 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr
);
1643 hr
= IDirect3DDevice_BeginScene(Direct3DDevice1
);
1644 ok(hr
== D3D_OK
, "IDirect3DDevice_BeginScene failed with %08x\n", hr
);
1646 if (SUCCEEDED(hr
)) {
1647 hr
= IDirect3DDevice_Execute(Direct3DDevice1
, ExecuteBuffer
, Viewport
, D3DEXECUTE_UNCLIPPED
);
1648 ok(hr
== D3D_OK
, "IDirect3DDevice_Execute failed, hr = %08x\n", hr
);
1649 hr
= IDirect3DDevice_EndScene(Direct3DDevice1
);
1650 ok(hr
== D3D_OK
, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr
);
1653 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 5);
1654 red
= (color
& 0x00ff0000) >> 16;
1655 green
= (color
& 0x0000ff00) >> 8;
1656 blue
= (color
& 0x000000ff);
1657 ok(red
== 0 && green
== 0 && blue
== 0xff, "Got color %08x, expected 000000ff or near\n", color
);
1659 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 5);
1660 red
= (color
& 0x00ff0000) >> 16;
1661 green
= (color
& 0x0000ff00) >> 8;
1662 blue
= (color
& 0x000000ff);
1663 ok(red
== 0 && green
== 0 && blue
== 0xff, "Got color %08x, expected 000000ff or near\n", color
);
1665 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 245);
1666 red
= (color
& 0x00ff0000) >> 16;
1667 green
= (color
& 0x0000ff00) >> 8;
1668 blue
= (color
& 0x000000ff);
1669 ok(red
== 0 && green
== 0 && blue
>= 0x7e && blue
<= 0x82, "Got color %08x, expected 00000080 or near\n", color
);
1671 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 245);
1672 red
= (color
& 0x00ff0000) >> 16;
1673 green
= (color
& 0x0000ff00) >> 8;
1674 blue
= (color
& 0x000000ff);
1675 ok(red
== 0 && green
== 0 && blue
>= 0x7e && blue
<= 0x82, "Got color %08x, expected 00000080 or near\n", color
);
1677 /* 3) Test RGB - should multiply color components from diffuse color and texture */
1678 if(Texture
) IDirect3DTexture_Release(Texture
);
1680 if(TexSurface
) IDirectDrawSurface_Release(TexSurface
);
1683 memset (&ddsd
, 0, sizeof (ddsd
));
1684 ddsd
.dwSize
= sizeof (ddsd
);
1685 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
1686 ddsd
.dwHeight
= 128;
1688 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1689 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
1690 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
1691 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1692 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1693 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1694 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1695 U5(ddsd
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
1696 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &TexSurface
, NULL
);
1697 ok(hr
==D3D_OK
, "CreateSurface returned: %x\n", hr
);
1699 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1703 hr
= IDirectDrawSurface_QueryInterface(TexSurface
, &IID_IDirect3DTexture
,
1705 ok(hr
==D3D_OK
, "IDirectDrawSurface_QueryInterface returned: %x\n", hr
);
1707 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1711 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
1712 ddbltfx
.dwSize
= sizeof(ddbltfx
);
1713 U5(ddbltfx
).dwFillColor
= 0;
1714 hr
= IDirectDrawSurface_Blt(Surface1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1715 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1717 U5(ddbltfx
).dwFillColor
= 0x00ffffff;
1718 hr
= IDirectDrawSurface_Blt(TexSurface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1719 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1720 U5(ddbltfx
).dwFillColor
= 0x00ffff80;
1721 hr
= IDirectDrawSurface_Blt(TexSurface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1722 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1724 memset(&exdesc
, 0, sizeof(D3DEXECUTEBUFFERDESC
));
1725 exdesc
.dwSize
= sizeof(D3DEXECUTEBUFFERDESC
);
1726 hr
= IDirect3DExecuteBuffer_Lock(ExecuteBuffer
, &exdesc
);
1727 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr
);
1729 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1733 memcpy(exdesc
.lpData
, test2_quads
, sizeof(test2_quads
));
1735 exe_buffer_ptr
= sizeof(test2_quads
) + (char*)exdesc
.lpData
;
1737 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr
);
1739 EXEBUF_START_RENDER_STATES(2, exe_buffer_ptr
);
1740 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
, exe_buffer_ptr
);
1741 hr
= IDirect3DTexture_GetHandle(Texture
, Direct3DDevice1
, &htex
);
1742 ok(hr
== D3D_OK
, "IDirect3DTexture_GetHandle failed with %08x\n", hr
);
1743 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE
, htex
, exe_buffer_ptr
);
1745 EXEBUF_PUT_QUAD(0, exe_buffer_ptr
);
1746 EXEBUF_PUT_QUAD(4, exe_buffer_ptr
);
1748 EXEBUF_END(exe_buffer_ptr
);
1750 exe_length
= ((char*)exe_buffer_ptr
- (char*)exdesc
.lpData
) - sizeof(test2_quads
);
1752 hr
= IDirect3DExecuteBuffer_Unlock(ExecuteBuffer
);
1754 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr
);
1757 memset(&exdata
, 0, sizeof(exdata
));
1758 exdata
.dwSize
= sizeof(exdata
);
1759 exdata
.dwVertexCount
= 8;
1760 exdata
.dwInstructionOffset
= sizeof(test2_quads
);
1761 exdata
.dwInstructionLength
= exe_length
;
1762 hr
= IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer
, &exdata
);
1763 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr
);
1765 hr
= IDirect3DDevice_BeginScene(Direct3DDevice1
);
1766 ok(hr
== D3D_OK
, "IDirect3DDevice_BeginScene failed with %08x\n", hr
);
1768 if (SUCCEEDED(hr
)) {
1769 hr
= IDirect3DDevice_Execute(Direct3DDevice1
, ExecuteBuffer
, Viewport
, D3DEXECUTE_UNCLIPPED
);
1770 ok(hr
== D3D_OK
, "IDirect3DDevice_Execute failed, hr = %08x\n", hr
);
1771 hr
= IDirect3DDevice_EndScene(Direct3DDevice1
);
1772 ok(hr
== D3D_OK
, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr
);
1775 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 5);
1776 red
= (color
& 0x00ff0000) >> 16;
1777 green
= (color
& 0x0000ff00) >> 8;
1778 blue
= (color
& 0x000000ff);
1779 ok(red
== 0xff && green
== 0 && blue
>= 0x3e && blue
<= 0x42, "Got color %08x, expected 00ff0040 or near\n", color
);
1781 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 5);
1782 red
= (color
& 0x00ff0000) >> 16;
1783 green
= (color
& 0x0000ff00) >> 8;
1784 blue
= (color
& 0x000000ff);
1785 ok(red
== 0xff && green
== 0 && blue
== 0x80, "Got color %08x, expected 00ff0080 or near\n", color
);
1787 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 245);
1788 red
= (color
& 0x00ff0000) >> 16;
1789 green
= (color
& 0x0000ff00) >> 8;
1790 blue
= (color
& 0x000000ff);
1791 ok(red
>= 0x7e && red
<= 0x82 && green
== 0 && blue
== 0x80, "Got color %08x, expected 00800080 or near\n", color
);
1793 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 245);
1794 red
= (color
& 0x00ff0000) >> 16;
1795 green
= (color
& 0x0000ff00) >> 8;
1796 blue
= (color
& 0x000000ff);
1797 ok(red
>= 0x7e && red
<= 0x82 && green
== 0 && blue
== 0xff, "Got color %08x, expected 008000ff or near\n", color
);
1799 /* 4) Test alpha again, now with color keyed texture (colorkey emulation in wine can interfere) */
1800 if(Texture
) IDirect3DTexture_Release(Texture
);
1802 if(TexSurface
) IDirectDrawSurface_Release(TexSurface
);
1805 memset (&ddsd
, 0, sizeof (ddsd
));
1806 ddsd
.dwSize
= sizeof (ddsd
);
1807 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
1808 ddsd
.dwHeight
= 128;
1810 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1811 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
1812 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1813 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 16;
1814 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0xf800;
1815 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x07e0;
1816 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x001f;
1818 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &TexSurface
, NULL
);
1819 ok(hr
==D3D_OK
, "CreateSurface returned: %x\n", hr
);
1821 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1825 hr
= IDirectDrawSurface_QueryInterface(TexSurface
, &IID_IDirect3DTexture
,
1827 ok(hr
==D3D_OK
, "IDirectDrawSurface_QueryInterface returned: %x\n", hr
);
1829 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1833 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
1834 ddbltfx
.dwSize
= sizeof(ddbltfx
);
1835 U5(ddbltfx
).dwFillColor
= 0;
1836 hr
= IDirectDrawSurface_Blt(Surface1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1837 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1838 U5(ddbltfx
).dwFillColor
= 0xf800;
1839 hr
= IDirectDrawSurface_Blt(TexSurface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1840 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1841 U5(ddbltfx
).dwFillColor
= 0x001f;
1842 hr
= IDirectDrawSurface_Blt(TexSurface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1843 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1845 clrKey
.dwColorSpaceLowValue
= 0x001f;
1846 clrKey
.dwColorSpaceHighValue
= 0x001f;
1847 hr
= IDirectDrawSurface_SetColorKey(TexSurface
, DDCKEY_SRCBLT
, &clrKey
);
1848 ok(hr
==D3D_OK
, "IDirectDrawSurfac_SetColorKey returned: %x\n", hr
);
1850 memset(&exdesc
, 0, sizeof(D3DEXECUTEBUFFERDESC
));
1851 exdesc
.dwSize
= sizeof(D3DEXECUTEBUFFERDESC
);
1852 hr
= IDirect3DExecuteBuffer_Lock(ExecuteBuffer
, &exdesc
);
1853 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr
);
1855 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1859 memcpy(exdesc
.lpData
, test1_quads
, sizeof(test1_quads
));
1861 exe_buffer_ptr
= sizeof(test1_quads
) + (char*)exdesc
.lpData
;
1863 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr
);
1865 EXEBUF_START_RENDER_STATES(2, exe_buffer_ptr
);
1866 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
, exe_buffer_ptr
);
1867 hr
= IDirect3DTexture_GetHandle(Texture
, Direct3DDevice1
, &htex
);
1868 ok(hr
== D3D_OK
, "IDirect3DTexture_GetHandle failed with %08x\n", hr
);
1869 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE
, htex
, exe_buffer_ptr
);
1871 EXEBUF_PUT_QUAD(0, exe_buffer_ptr
);
1872 EXEBUF_PUT_QUAD(4, exe_buffer_ptr
);
1874 EXEBUF_END(exe_buffer_ptr
);
1876 exe_length
= ((char*)exe_buffer_ptr
- (char*)exdesc
.lpData
) - sizeof(test1_quads
);
1878 hr
= IDirect3DExecuteBuffer_Unlock(ExecuteBuffer
);
1880 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr
);
1883 memset(&exdata
, 0, sizeof(exdata
));
1884 exdata
.dwSize
= sizeof(exdata
);
1885 exdata
.dwVertexCount
= 8;
1886 exdata
.dwInstructionOffset
= sizeof(test1_quads
);
1887 exdata
.dwInstructionLength
= exe_length
;
1888 hr
= IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer
, &exdata
);
1889 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr
);
1891 hr
= IDirect3DDevice_BeginScene(Direct3DDevice1
);
1892 ok(hr
== D3D_OK
, "IDirect3DDevice_BeginScene failed with %08x\n", hr
);
1894 if (SUCCEEDED(hr
)) {
1895 hr
= IDirect3DDevice_Execute(Direct3DDevice1
, ExecuteBuffer
, Viewport
, D3DEXECUTE_UNCLIPPED
);
1896 ok(hr
== D3D_OK
, "IDirect3DDevice_Execute failed, hr = %08x\n", hr
);
1897 hr
= IDirect3DDevice_EndScene(Direct3DDevice1
);
1898 ok(hr
== D3D_OK
, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr
);
1901 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 5);
1902 ok(color
== 0, "Got color %08x, expected 00000000\n", color
);
1904 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 5);
1905 red
= (color
& 0x00ff0000) >> 16;
1906 green
= (color
& 0x0000ff00) >> 8;
1907 blue
= (color
& 0x000000ff);
1908 ok(red
== 0xff && green
== 0 && blue
== 0, "Got color %08x, expected 00ff0000 or near\n", color
);
1910 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 245);
1911 ok(color
== 0, "Got color %08x, expected 00000000\n", color
);
1913 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 245);
1914 red
= (color
& 0x00ff0000) >> 16;
1915 green
= (color
& 0x0000ff00) >> 8;
1916 blue
= (color
& 0x000000ff);
1917 ok(red
>= 0x7e && red
<= 0x82 && green
== 0 && blue
== 0, "Got color %08x, expected 00800000 or near\n", color
);
1919 /* 5) Test alpha again, now with color keyed P8 texture */
1920 if(Texture
) IDirect3DTexture_Release(Texture
);
1922 if(TexSurface
) IDirectDrawSurface_Release(TexSurface
);
1925 hr
= IDirect3DDevice_EnumTextureFormats(Direct3DDevice1
, TextureFormatEnumCallback
,
1926 &p8_textures_supported
);
1927 ok(hr
== DD_OK
, "IDirect3DDevice_EnumTextureFormats returned %08x\n", hr
);
1929 if (!p8_textures_supported
) {
1930 skip("device has no P8 texture support, skipping test\n");
1932 memset (&ddsd
, 0, sizeof (ddsd
));
1933 ddsd
.dwSize
= sizeof (ddsd
);
1934 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
1935 ddsd
.dwHeight
= 128;
1937 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1938 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
1939 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_PALETTEINDEXED8
;
1940 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 8;
1942 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &TexSurface
, NULL
);
1943 ok(hr
==D3D_OK
, "CreateSurface returned: %x\n", hr
);
1945 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1949 memset(table1
, 0, sizeof(table1
));
1950 table1
[0].peBlue
= 0xff;
1951 table1
[1].peRed
= 0xff;
1953 hr
= IDirectDraw_CreatePalette(DirectDraw1
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, table1
, &Palette
, NULL
);
1954 ok(hr
== DD_OK
, "CreatePalette returned %08x\n", hr
);
1956 skip("IDirectDraw_CreatePalette failed; skipping further tests\n");
1960 hr
= IDirectDrawSurface_SetPalette(TexSurface
, Palette
);
1961 ok(hr
==D3D_OK
, "IDirectDrawSurface_SetPalette returned: %x\n", hr
);
1963 hr
= IDirectDrawSurface_QueryInterface(TexSurface
, &IID_IDirect3DTexture
,
1965 ok(hr
==D3D_OK
, "IDirectDrawSurface_QueryInterface returned: %x\n", hr
);
1967 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1971 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
1972 ddbltfx
.dwSize
= sizeof(ddbltfx
);
1973 U5(ddbltfx
).dwFillColor
= 0;
1974 hr
= IDirectDrawSurface_Blt(Surface1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1975 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1976 U5(ddbltfx
).dwFillColor
= 0;
1977 hr
= IDirectDrawSurface_Blt(TexSurface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1978 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1979 U5(ddbltfx
).dwFillColor
= 1;
1980 hr
= IDirectDrawSurface_Blt(TexSurface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1981 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1983 clrKey
.dwColorSpaceLowValue
= 1;
1984 clrKey
.dwColorSpaceHighValue
= 1;
1985 hr
= IDirectDrawSurface_SetColorKey(TexSurface
, DDCKEY_SRCBLT
, &clrKey
);
1986 ok(hr
==D3D_OK
, "IDirectDrawSurfac_SetColorKey returned: %x\n", hr
);
1988 memset(&exdesc
, 0, sizeof(D3DEXECUTEBUFFERDESC
));
1989 exdesc
.dwSize
= sizeof(D3DEXECUTEBUFFERDESC
);
1990 hr
= IDirect3DExecuteBuffer_Lock(ExecuteBuffer
, &exdesc
);
1991 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr
);
1993 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1997 memcpy(exdesc
.lpData
, test1_quads
, sizeof(test1_quads
));
1999 exe_buffer_ptr
= sizeof(test1_quads
) + (char*)exdesc
.lpData
;
2001 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr
);
2003 EXEBUF_START_RENDER_STATES(2, exe_buffer_ptr
);
2004 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
, exe_buffer_ptr
);
2005 hr
= IDirect3DTexture_GetHandle(Texture
, Direct3DDevice1
, &htex
);
2006 ok(hr
== D3D_OK
, "IDirect3DTexture_GetHandle failed with %08x\n", hr
);
2007 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE
, htex
, exe_buffer_ptr
);
2009 EXEBUF_PUT_QUAD(0, exe_buffer_ptr
);
2010 EXEBUF_PUT_QUAD(4, exe_buffer_ptr
);
2012 EXEBUF_END(exe_buffer_ptr
);
2014 exe_length
= ((char*)exe_buffer_ptr
- (char*)exdesc
.lpData
) - sizeof(test1_quads
);
2016 hr
= IDirect3DExecuteBuffer_Unlock(ExecuteBuffer
);
2018 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr
);
2021 memset(&exdata
, 0, sizeof(exdata
));
2022 exdata
.dwSize
= sizeof(exdata
);
2023 exdata
.dwVertexCount
= 8;
2024 exdata
.dwInstructionOffset
= sizeof(test1_quads
);
2025 exdata
.dwInstructionLength
= exe_length
;
2026 hr
= IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer
, &exdata
);
2027 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr
);
2029 hr
= IDirect3DDevice_BeginScene(Direct3DDevice1
);
2030 ok(hr
== D3D_OK
, "IDirect3DDevice_BeginScene failed with %08x\n", hr
);
2032 if (SUCCEEDED(hr
)) {
2033 hr
= IDirect3DDevice_Execute(Direct3DDevice1
, ExecuteBuffer
, Viewport
, D3DEXECUTE_UNCLIPPED
);
2034 ok(hr
== D3D_OK
, "IDirect3DDevice_Execute failed, hr = %08x\n", hr
);
2035 hr
= IDirect3DDevice_EndScene(Direct3DDevice1
);
2036 ok(hr
== D3D_OK
, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr
);
2039 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 5);
2040 ok(color
== 0, "Got color %08x, expected 00000000\n", color
);
2042 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 5);
2043 red
= (color
& 0x00ff0000) >> 16;
2044 green
= (color
& 0x0000ff00) >> 8;
2045 blue
= (color
& 0x000000ff);
2046 ok(red
== 0 && green
== 0 && blue
== 0xff, "Got color %08x, expected 000000ff or near\n", color
);
2048 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 245);
2049 ok(color
== 0, "Got color %08x, expected 00000000\n", color
);
2051 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 245);
2052 red
= (color
& 0x00ff0000) >> 16;
2053 green
= (color
& 0x0000ff00) >> 8;
2054 blue
= (color
& 0x000000ff);
2055 ok(red
== 0 && green
== 0 && blue
>= 0x7e && blue
<= 0x82, "Got color %08x, expected 00000080 or near\n", color
);
2060 if (Palette
) IDirectDrawPalette_Release(Palette
);
2061 if (TexSurface
) IDirectDrawSurface_Release(TexSurface
);
2062 if (Texture
) IDirect3DTexture_Release(Texture
);
2065 static void D3D1_ViewportClearTest(void)
2068 IDirect3DMaterial
*bgMaterial
= NULL
;
2070 D3DMATERIALHANDLE hMat
;
2071 D3DVIEWPORT vp_data
;
2072 IDirect3DViewport
*Viewport2
= NULL
;
2073 DWORD color
, red
, green
, blue
;
2075 hr
= IDirect3D_CreateMaterial(Direct3D1
, &bgMaterial
, NULL
);
2076 ok(hr
== D3D_OK
, "IDirect3D_CreateMaterial failed: %08x\n", hr
);
2081 hr
= IDirect3D_CreateViewport(Direct3D1
, &Viewport2
, NULL
);
2082 ok(hr
== D3D_OK
, "IDirect3D_CreateViewport failed: %08x\n", hr
);
2087 hr
= IDirect3DViewport_Initialize(Viewport2
, Direct3D1
);
2088 ok(hr
== D3D_OK
|| hr
== DDERR_ALREADYINITIALIZED
, "IDirect3DViewport_Initialize returned %08x\n", hr
);
2089 hr
= IDirect3DDevice_AddViewport(Direct3DDevice1
, Viewport2
);
2090 ok(hr
== D3D_OK
, "IDirect3DDevice_AddViewport returned %08x\n", hr
);
2091 vp_data
.dwSize
= sizeof(vp_data
);
2094 vp_data
.dwWidth
= 100;
2095 vp_data
.dwHeight
= 100;
2096 vp_data
.dvScaleX
= 1;
2097 vp_data
.dvScaleY
= 1;
2098 vp_data
.dvMaxX
= 100;
2099 vp_data
.dvMaxY
= 100;
2102 hr
= IDirect3DViewport_SetViewport(Viewport2
, &vp_data
);
2103 ok(hr
== D3D_OK
, "IDirect3DViewport_SetViewport returned %08x\n", hr
);
2105 memset(&mat
, 0, sizeof(mat
));
2106 mat
.dwSize
= sizeof(mat
);
2107 U1(U(mat
).diffuse
).r
= 1.0f
;
2108 hr
= IDirect3DMaterial_SetMaterial(bgMaterial
, &mat
);
2109 ok(hr
== D3D_OK
, "IDirect3DMaterial_SetMaterial failed: %08x\n", hr
);
2111 hr
= IDirect3DMaterial_GetHandle(bgMaterial
, Direct3DDevice1
, &hMat
);
2112 ok(hr
== D3D_OK
, "IDirect3DMaterial_GetHandle failed: %08x\n", hr
);
2114 hr
= IDirect3DViewport_SetBackground(Viewport
, hMat
);
2115 ok(hr
== D3D_OK
, "IDirect3DViewport_SetBackground failed: %08x\n", hr
);
2116 hr
= IDirect3DViewport_SetBackground(Viewport2
, hMat
);
2117 ok(hr
== D3D_OK
, "IDirect3DViewport_SetBackground failed: %08x\n", hr
);
2119 hr
= IDirect3DDevice_BeginScene(Direct3DDevice1
);
2120 ok(hr
== D3D_OK
, "IDirect3DDevice_BeginScene failed with %08x\n", hr
);
2122 if (SUCCEEDED(hr
)) {
2125 U1(rect
).x1
= U2(rect
).y1
= 0;
2129 hr
= IDirect3DViewport_Clear(Viewport
, 1, &rect
, D3DCLEAR_TARGET
);
2130 ok(hr
== D3D_OK
, "IDirect3DViewport_Clear failed: %08x\n", hr
);
2132 memset(&mat
, 0, sizeof(mat
));
2133 mat
.dwSize
= sizeof(mat
);
2134 U3(U(mat
).diffuse
).b
= 1.0f
;
2135 hr
= IDirect3DMaterial_SetMaterial(bgMaterial
, &mat
);
2136 ok(hr
== D3D_OK
, "IDirect3DMaterial_SetMaterial failed: %08x\n", hr
);
2138 hr
= IDirect3DViewport_Clear(Viewport2
, 1, &rect
, D3DCLEAR_TARGET
);
2139 ok(hr
== D3D_OK
, "IDirect3DViewport_Clear failed: %08x\n", hr
);
2141 hr
= IDirect3DDevice_EndScene(Direct3DDevice1
);
2142 ok(hr
== D3D_OK
, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr
);
2145 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 5);
2146 red
= (color
& 0x00ff0000) >> 16;
2147 green
= (color
& 0x0000ff00) >> 8;
2148 blue
= (color
& 0x000000ff);
2149 ok((red
== 0xff && green
== 0 && blue
== 0) ||
2150 broken(red
== 0 && green
== 0 && blue
== 0xff), /* VMware and some native boxes */
2151 "Got color %08x, expected 00ff0000\n", color
);
2153 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 205, 205);
2154 red
= (color
& 0x00ff0000) >> 16;
2155 green
= (color
& 0x0000ff00) >> 8;
2156 blue
= (color
& 0x000000ff);
2157 ok(red
== 0 && green
== 0 && blue
== 0xff, "Got color %08x, expected 000000ff\n", color
);
2161 if (bgMaterial
) IDirect3DMaterial_Release(bgMaterial
);
2162 if (Viewport2
) IDirect3DViewport_Release(Viewport2
);
2165 static DWORD
D3D3_getPixelColor(IDirectDraw4
*DirectDraw
, IDirectDrawSurface4
*Surface
, UINT x
, UINT y
)
2169 DDSURFACEDESC2 ddsd
;
2170 RECT rectToLock
= {x
, y
, x
+1, y
+1};
2171 IDirectDrawSurface4
*surf
= NULL
;
2173 /* Some implementations seem to dislike direct locking on the front buffer. Thus copy the front buffer
2174 * to an offscreen surface and lock it instead of the front buffer
2176 memset(&ddsd
, 0, sizeof(ddsd
));
2177 ddsd
.dwSize
= sizeof(ddsd
);
2178 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
2179 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
2181 ddsd
.dwHeight
= 480;
2182 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
;
2183 hr
= IDirectDraw4_CreateSurface(DirectDraw
, &ddsd
, &surf
, NULL
);
2184 ok(hr
== DD_OK
, "IDirectDraw_CreateSurface failed with %08x\n", hr
);
2187 trace("cannot create helper surface\n");
2191 memset(&ddsd
, 0, sizeof(ddsd
));
2192 ddsd
.dwSize
= sizeof(ddsd
);
2193 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
2195 hr
= IDirectDrawSurface4_BltFast(surf
, 0, 0, Surface
, NULL
, 0);
2196 ok(hr
== DD_OK
, "IDirectDrawSurface_BltFast returned %08x\n", hr
);
2199 trace("Cannot blit\n");
2204 hr
= IDirectDrawSurface4_Lock(surf
, &rectToLock
, &ddsd
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
2207 trace("Can't lock the offscreen surface, hr=%08x\n", hr
);
2212 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
2213 * really important for these tests
2215 ret
= ((DWORD
*) ddsd
.lpSurface
)[0] & 0x00ffffff;
2216 hr
= IDirectDrawSurface4_Unlock(surf
, NULL
);
2219 trace("Can't unlock the offscreen surface, hr=%08x\n", hr
);
2223 IDirectDrawSurface4_Release(surf
);
2227 static void D3D3_ViewportClearTest(void)
2230 IDirectDraw
*DirectDraw1
= NULL
;
2231 IDirectDraw4
*DirectDraw4
= NULL
;
2232 IDirectDrawSurface4
*Primary
= NULL
;
2233 IDirect3D3
*Direct3D3
= NULL
;
2234 IDirect3DViewport3
*Viewport3
= NULL
;
2235 IDirect3DViewport3
*SmallViewport3
= NULL
;
2236 IDirect3DDevice3
*Direct3DDevice3
= NULL
;
2238 DDSURFACEDESC2 ddsd
;
2239 D3DVIEWPORT2 vp_data
;
2240 DWORD color
, red
, green
, blue
;
2244 1.0f
, 0.0f
, 0.0f
, 0.0f
,
2245 0.0f
, 1.0f
, 0.0f
, 0.0f
,
2246 0.0f
, 0.0f
, 1.0f
, 0.0f
,
2247 0.0f
, 0.0f
, 0.0f
, 1.0f
,
2251 struct vec3 position
;
2256 {{-1.0f
, -1.0f
, 0.1f
}, 0xffffffff},
2257 {{-1.0f
, 1.0f
, 0.1f
}, 0xffffffff},
2258 {{ 1.0f
, 1.0f
, 0.1f
}, 0xffffffff},
2259 {{ 1.0f
, -1.0f
, 0.1f
}, 0xffffffff},
2262 WORD Indices
[] = {0, 1, 2, 2, 3, 0};
2263 DWORD fvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
2265 wc
.lpfnWndProc
= DefWindowProcA
;
2266 wc
.lpszClassName
= "D3D3_ViewportClearTest_wc";
2267 RegisterClassA(&wc
);
2268 window
= CreateWindowA("D3D3_ViewportClearTest_wc", "D3D3_ViewportClearTest",
2269 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
2271 hr
= DirectDrawCreate( NULL
, &DirectDraw1
, NULL
);
2272 ok(hr
==DD_OK
|| hr
==DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreate returned: %x\n", hr
);
2273 if(FAILED(hr
)) goto out
;
2275 hr
= IDirectDraw_SetCooperativeLevel(DirectDraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2276 ok(hr
==DD_OK
, "SetCooperativeLevel returned: %x\n", hr
);
2277 if(FAILED(hr
)) goto out
;
2279 hr
= IDirectDraw_SetDisplayMode(DirectDraw1
, 640, 480, 32);
2281 /* 24 bit is fine too */
2282 hr
= IDirectDraw_SetDisplayMode(DirectDraw1
, 640, 480, 24);
2284 ok(hr
==DD_OK
|| hr
== DDERR_UNSUPPORTED
, "SetDisplayMode returned: %x\n", hr
);
2285 if (FAILED(hr
)) goto out
;
2287 hr
= IDirectDraw_QueryInterface(DirectDraw1
, &IID_IDirectDraw4
, (void**)&DirectDraw4
);
2288 ok(hr
==DD_OK
, "QueryInterface returned: %08x\n", hr
);
2289 if(FAILED(hr
)) goto out
;
2291 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
2292 ddsd
.dwSize
= sizeof(DDSURFACEDESC2
);
2293 ddsd
.dwFlags
= DDSD_CAPS
;
2294 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
;
2296 hr
= IDirectDraw_CreateSurface(DirectDraw4
, &ddsd
, &Primary
, NULL
);
2297 ok(hr
==DD_OK
, "IDirectDraw_CreateSurface returned: %08x\n", hr
);
2298 if(FAILED(hr
)) goto out
;
2300 hr
= IDirectDraw4_QueryInterface(DirectDraw4
, &IID_IDirect3D3
, (void**)&Direct3D3
);
2301 ok(hr
==DD_OK
, "IDirectDraw4_QueryInterface returned: %08x\n", hr
);
2302 if(FAILED(hr
)) goto out
;
2304 hr
= IDirect3D3_CreateDevice(Direct3D3
, &IID_IDirect3DHALDevice
, Primary
, &Direct3DDevice3
, NULL
);
2306 trace("Creating a HAL device failed, trying Ref\n");
2307 hr
= IDirect3D3_CreateDevice(Direct3D3
, &IID_IDirect3DRefDevice
, Primary
, &Direct3DDevice3
, NULL
);
2309 ok(hr
==D3D_OK
, "Creating 3D device returned: %x\n", hr
);
2310 if(FAILED(hr
)) goto out
;
2312 hr
= IDirect3D3_CreateViewport(Direct3D3
, &Viewport3
, NULL
);
2313 ok(hr
==DD_OK
, "IDirect3D3_CreateViewport returned: %08x\n", hr
);
2314 if(FAILED(hr
)) goto out
;
2316 hr
= IDirect3DDevice3_AddViewport(Direct3DDevice3
, Viewport3
);
2317 ok(hr
==DD_OK
, "IDirect3DDevice3_AddViewport returned: %08x\n", hr
);
2319 memset(&vp_data
, 0, sizeof(D3DVIEWPORT2
));
2320 vp_data
.dwSize
= sizeof(D3DVIEWPORT2
);
2321 vp_data
.dwWidth
= 640;
2322 vp_data
.dwHeight
= 480;
2323 vp_data
.dvClipX
= -1.0f
;
2324 vp_data
.dvClipWidth
= 2.0f
;
2325 vp_data
.dvClipY
= 1.0f
;
2326 vp_data
.dvClipHeight
= 2.0f
;
2327 vp_data
.dvMaxZ
= 1.0f
;
2328 hr
= IDirect3DViewport3_SetViewport2(Viewport3
, &vp_data
);
2329 ok(hr
==DD_OK
, "IDirect3DViewport3_SetViewport2 returned: %08x\n", hr
);
2331 hr
= IDirect3D3_CreateViewport(Direct3D3
, &SmallViewport3
, NULL
);
2332 ok(hr
==DD_OK
, "IDirect3D3_CreateViewport returned: %08x\n", hr
);
2333 if(FAILED(hr
)) goto out
;
2335 hr
= IDirect3DDevice3_AddViewport(Direct3DDevice3
, SmallViewport3
);
2336 ok(hr
==DD_OK
, "IDirect3DDevice3_AddViewport returned: %08x\n", hr
);
2338 memset(&vp_data
, 0, sizeof(D3DVIEWPORT2
));
2339 vp_data
.dwSize
= sizeof(D3DVIEWPORT2
);
2342 vp_data
.dwWidth
= 100;
2343 vp_data
.dwHeight
= 100;
2344 vp_data
.dvClipX
= -1.0f
;
2345 vp_data
.dvClipWidth
= 2.0f
;
2346 vp_data
.dvClipY
= 1.0f
;
2347 vp_data
.dvClipHeight
= 2.0f
;
2348 vp_data
.dvMaxZ
= 1.0f
;
2349 hr
= IDirect3DViewport3_SetViewport2(SmallViewport3
, &vp_data
);
2350 ok(hr
==DD_OK
, "IDirect3DViewport3_SetViewport2 returned: %08x\n", hr
);
2352 hr
= IDirect3DDevice3_BeginScene(Direct3DDevice3
);
2353 ok(hr
== D3D_OK
, "IDirect3DDevice3_BeginScene failed with %08x\n", hr
);
2355 hr
= IDirect3DDevice3_SetTransform(Direct3DDevice3
, D3DTRANSFORMSTATE_WORLD
, &mat
);
2356 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetTransform returned %08x\n", hr
);
2357 hr
= IDirect3DDevice3_SetTransform(Direct3DDevice3
, D3DTRANSFORMSTATE_VIEW
, &mat
);
2358 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetTransform returned %08x\n", hr
);
2359 hr
= IDirect3DDevice3_SetTransform(Direct3DDevice3
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
2360 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetTransform returned %08x\n", hr
);
2361 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_CLIPPING
, FALSE
);
2362 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState returned %08x\n", hr
);
2363 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_ZENABLE
, FALSE
);
2364 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState returned %08x\n", hr
);
2365 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
2366 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState returned %08x\n", hr
);
2367 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_STENCILENABLE
, FALSE
);
2368 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState returned %08x\n", hr
);
2369 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_ALPHATESTENABLE
, FALSE
);
2370 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState returned %08x\n", hr
);
2371 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
);
2372 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState returned %08x\n", hr
);
2373 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
2374 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState failed with %08x\n", hr
);
2375 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_LIGHTING
, FALSE
);
2376 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState returned %08x\n", hr
);
2378 if (SUCCEEDED(hr
)) {
2379 U1(rect
).x1
= U2(rect
).y1
= 0;
2383 hr
= IDirect3DViewport3_Clear2(Viewport3
, 1, &rect
, D3DCLEAR_TARGET
, 0x00ff00, 0.0f
, 0);
2384 ok(hr
== D3D_OK
, "IDirect3DViewport3_Clear2 failed, hr = %08x\n", hr
);
2386 hr
= IDirect3DViewport3_Clear2(SmallViewport3
, 1, &rect
, D3DCLEAR_TARGET
, 0xff0000, 0.0f
, 0);
2387 ok(hr
== D3D_OK
, "IDirect3DViewport3_Clear2 failed, hr = %08x\n", hr
);
2389 hr
= IDirect3DDevice3_EndScene(Direct3DDevice3
);
2390 ok(hr
== D3D_OK
, "IDirect3DDevice3_EndScene failed, hr = %08x\n", hr
);
2393 color
= D3D3_getPixelColor(DirectDraw4
, Primary
, 5, 5);
2394 red
= (color
& 0x00ff0000) >> 16;
2395 green
= (color
& 0x0000ff00) >> 8;
2396 blue
= (color
& 0x000000ff);
2397 ok(red
== 0 && green
== 0xff && blue
== 0, "Got color %08x, expected 0000ff00\n", color
);
2399 color
= D3D3_getPixelColor(DirectDraw4
, Primary
, 405, 105);
2400 red
= (color
& 0x00ff0000) >> 16;
2401 green
= (color
& 0x0000ff00) >> 8;
2402 blue
= (color
& 0x000000ff);
2403 ok(red
== 0xff && green
== 0 && blue
== 0, "Got color %08x, expected 00ff0000\n", color
);
2405 /* Test that clearing viewport doesn't interfere with rendering to previously active viewport. */
2406 hr
= IDirect3DDevice3_BeginScene(Direct3DDevice3
);
2407 ok(hr
== D3D_OK
, "IDirect3DDevice3_BeginScene failed with %08x\n", hr
);
2409 if (SUCCEEDED(hr
)) {
2410 hr
= IDirect3DDevice3_SetCurrentViewport(Direct3DDevice3
, SmallViewport3
);
2411 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetCurrentViewport failed with %08x\n", hr
);
2413 hr
= IDirect3DViewport3_Clear2(Viewport3
, 1, &rect
, D3DCLEAR_TARGET
, 0x000000, 0.0f
, 0);
2414 ok(hr
== D3D_OK
, "IDirect3DViewport3_Clear2 failed, hr = %08x\n", hr
);
2416 hr
= IDirect3DDevice3_DrawIndexedPrimitive(Direct3DDevice3
, D3DPT_TRIANGLELIST
, fvf
, quad
, 4 /* NumVerts */,
2417 Indices
, 6 /* Indexcount */, 0 /* flags */);
2418 ok(hr
== D3D_OK
, "IDirect3DDevice3_DrawIndexedPrimitive failed with %08x\n", hr
);
2420 hr
= IDirect3DDevice3_EndScene(Direct3DDevice3
);
2421 ok(hr
== D3D_OK
, "IDirect3DDevice3_EndScene failed, hr = %08x\n", hr
);
2424 color
= D3D3_getPixelColor(DirectDraw4
, Primary
, 5, 5);
2425 red
= (color
& 0x00ff0000) >> 16;
2426 green
= (color
& 0x0000ff00) >> 8;
2427 blue
= (color
& 0x000000ff);
2428 ok(red
== 0 && green
== 0 && blue
== 0, "Got color %08x, expected 00000000\n", color
);
2430 color
= D3D3_getPixelColor(DirectDraw4
, Primary
, 405, 105);
2431 red
= (color
& 0x00ff0000) >> 16;
2432 green
= (color
& 0x0000ff00) >> 8;
2433 blue
= (color
& 0x000000ff);
2434 ok(red
== 0xff && green
== 0xff && blue
== 0xff, "Got color %08x, expected 00ffffff\n", color
);
2438 if (SmallViewport3
) IDirect3DViewport3_Release(SmallViewport3
);
2439 if (Viewport3
) IDirect3DViewport3_Release(Viewport3
);
2440 if (Direct3DDevice3
) IDirect3DDevice3_Release(Direct3DDevice3
);
2441 if (Direct3D3
) IDirect3D3_Release(Direct3D3
);
2442 if (Primary
) IDirectDrawSurface4_Release(Primary
);
2443 if (DirectDraw1
) IDirectDraw_Release(DirectDraw1
);
2444 if (DirectDraw4
) IDirectDraw4_Release(DirectDraw4
);
2445 if(window
) DestroyWindow(window
);
2448 static void p8_surface_fill_rect(IDirectDrawSurface
*dest
, UINT x
, UINT y
, UINT w
, UINT h
, BYTE colorindex
)
2455 memset(&ddsd
, 0, sizeof(ddsd
));
2456 ddsd
.dwSize
= sizeof(ddsd
);
2458 hr
= IDirectDrawSurface_Lock(dest
, NULL
, &ddsd
, DDLOCK_WRITEONLY
| DDLOCK_WAIT
, NULL
);
2459 ok(hr
==DD_OK
, "IDirectDrawSurface_Lock returned: %x\n", hr
);
2461 p
= (BYTE
*)ddsd
.lpSurface
+ U1(ddsd
).lPitch
* y
+ x
;
2463 for (i
= 0; i
< h
; i
++) {
2464 for (i1
= 0; i1
< w
; i1
++) {
2467 p
+= U1(ddsd
).lPitch
;
2470 hr
= IDirectDrawSurface_Unlock(dest
, NULL
);
2471 ok(hr
==DD_OK
, "IDirectDrawSurface_UnLock returned: %x\n", hr
);
2474 static COLORREF
getPixelColor_GDI(IDirectDrawSurface
*Surface
, UINT x
, UINT y
)
2476 COLORREF clr
= CLR_INVALID
;
2480 hr
= IDirectDrawSurface_GetDC(Surface
, &hdc
);
2481 ok(hr
==DD_OK
, "IDirectDrawSurface_GetDC returned: %x\n", hr
);
2483 if (SUCCEEDED(hr
)) {
2484 clr
= GetPixel(hdc
, x
, y
);
2486 hr
= IDirectDrawSurface_ReleaseDC(Surface
, hdc
);
2487 ok(hr
==DD_OK
, "IDirectDrawSurface_ReleaseDC returned: %x\n", hr
);
2493 static BOOL
colortables_check_equality(PALETTEENTRY table1
[256], RGBQUAD table2
[256])
2497 for (i
= 0; i
< 256; i
++) {
2498 if (table1
[i
].peRed
!= table2
[i
].rgbRed
|| table1
[i
].peGreen
!= table2
[i
].rgbGreen
||
2499 table1
[i
].peBlue
!= table2
[i
].rgbBlue
) return FALSE
;
2505 static void p8_primary_test(void)
2507 /* Test 8bit mode used by games like StarCraft, C&C Red Alert I etc */
2511 PALETTEENTRY entries
[256];
2512 RGBQUAD coltable
[256];
2514 IDirectDrawPalette
*ddprimpal
= NULL
;
2515 IDirectDrawSurface
*offscreen
= NULL
;
2521 unsigned differences
;
2523 /* An IDirect3DDevice cannot be queryInterfaced from an IDirect3DDevice7 on windows */
2524 hr
= DirectDrawCreate(NULL
, &DirectDraw1
, NULL
);
2526 ok(hr
==DD_OK
|| hr
==DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreate returned: %x\n", hr
);
2531 wc
.lpfnWndProc
= DefWindowProcA
;
2532 wc
.lpszClassName
= "p8_primary_test_wc";
2533 RegisterClassA(&wc
);
2534 window
= CreateWindowA("p8_primary_test_wc", "p8_primary_test",
2535 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
2537 hr
= IDirectDraw_SetCooperativeLevel(DirectDraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2538 ok(hr
==DD_OK
, "SetCooperativeLevel returned: %x\n", hr
);
2543 hr
= IDirectDraw_SetDisplayMode(DirectDraw1
, 640, 480, 8);
2544 ok(hr
==DD_OK
|| hr
== DDERR_UNSUPPORTED
, "SetDisplayMode returned: %x\n", hr
);
2549 memset(&ddsd
, 0, sizeof(ddsd
));
2550 ddsd
.dwSize
= sizeof(ddsd
);
2551 ddsd
.dwFlags
= DDSD_CAPS
;
2552 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2553 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &Surface1
, NULL
);
2554 ok(hr
==DD_OK
, "CreateSurface returned: %x\n", hr
);
2559 memset(entries
, 0, sizeof(entries
));
2560 entries
[0].peRed
= 0xff;
2561 entries
[1].peGreen
= 0xff;
2562 entries
[2].peBlue
= 0xff;
2564 hr
= IDirectDraw_CreatePalette(DirectDraw1
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, entries
, &ddprimpal
, NULL
);
2565 ok(hr
== DD_OK
, "CreatePalette returned %08x\n", hr
);
2567 skip("IDirectDraw_CreatePalette failed; skipping further tests\n");
2571 hr
= IDirectDrawSurface_SetPalette(Surface1
, ddprimpal
);
2572 ok(hr
==DD_OK
, "IDirectDrawSurface_SetPalette returned: %x\n", hr
);
2574 p8_surface_fill_rect(Surface1
, 0, 0, 640, 480, 2);
2576 color
= getPixelColor_GDI(Surface1
, 10, 10);
2577 ok(GetRValue(color
) == 0 && GetGValue(color
) == 0 && GetBValue(color
) == 0xFF,
2578 "got R %02X G %02X B %02X, expected R 00 G 00 B FF\n",
2579 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2581 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
2582 ddbltfx
.dwSize
= sizeof(ddbltfx
);
2583 U5(ddbltfx
).dwFillColor
= 0;
2584 hr
= IDirectDrawSurface_Blt(Surface1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
2585 ok(hr
== DD_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
2587 color
= getPixelColor_GDI(Surface1
, 10, 10);
2588 ok(GetRValue(color
) == 0xFF && GetGValue(color
) == 0 && GetBValue(color
) == 0,
2589 "got R %02X G %02X B %02X, expected R FF G 00 B 00\n",
2590 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2592 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
2593 ddbltfx
.dwSize
= sizeof(ddbltfx
);
2594 U5(ddbltfx
).dwFillColor
= 1;
2595 hr
= IDirectDrawSurface_Blt(Surface1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
2596 ok(hr
== DD_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
2598 color
= getPixelColor_GDI(Surface1
, 10, 10);
2599 ok(GetRValue(color
) == 0 && GetGValue(color
) == 0xFF && GetBValue(color
) == 0,
2600 "got R %02X G %02X B %02X, expected R 00 G FF B 00\n",
2601 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2603 memset (&ddsd
, 0, sizeof (ddsd
));
2604 ddsd
.dwSize
= sizeof (ddsd
);
2605 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
2608 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
;
2609 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
2610 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_PALETTEINDEXED8
;
2611 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 8;
2612 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &offscreen
, NULL
);
2614 broken(hr
== DDERR_INVALIDPIXELFORMAT
) || /* VMware */
2615 broken(hr
== DDERR_NODIRECTDRAWHW
), /* VMware */
2616 "IDirectDraw_CreateSurface returned %08x\n", hr
);
2617 if (FAILED(hr
)) goto out
;
2619 memset(entries
, 0, sizeof(entries
));
2620 for (i
= 0; i
< 256; i
++) {
2621 entries
[i
].peBlue
= i
;
2623 hr
= IDirectDrawPalette_SetEntries(ddprimpal
, 0, 0, 256, entries
);
2624 ok(hr
== DD_OK
, "IDirectDrawPalette_SetEntries failed with %08x\n", hr
);
2626 hr
= IDirectDrawSurface_GetDC(offscreen
, &hdc
);
2627 ok(hr
==DD_OK
, "IDirectDrawSurface_GetDC returned: %x\n", hr
);
2628 i
= GetDIBColorTable(hdc
, 0, 256, coltable
);
2629 ok(i
== 256, "GetDIBColorTable returned %u, last error: %x\n", i
, GetLastError());
2630 hr
= IDirectDrawSurface_ReleaseDC(offscreen
, hdc
);
2631 ok(hr
==DD_OK
, "IDirectDrawSurface_ReleaseDC returned: %x\n", hr
);
2633 ok(colortables_check_equality(entries
, coltable
), "unexpected colortable on offscreen surface\n");
2635 p8_surface_fill_rect(offscreen
, 0, 0, 16, 16, 2);
2637 memset(entries
, 0, sizeof(entries
));
2638 entries
[0].peRed
= 0xff;
2639 entries
[1].peGreen
= 0xff;
2640 entries
[2].peBlue
= 0xff;
2641 entries
[3].peRed
= 0x80;
2642 hr
= IDirectDrawPalette_SetEntries(ddprimpal
, 0, 0, 256, entries
);
2643 ok(hr
== DD_OK
, "IDirectDrawPalette_SetEntries failed with %08x\n", hr
);
2645 hr
= IDirectDrawSurface_BltFast(Surface1
, 0, 0, offscreen
, NULL
, 0);
2646 ok(hr
==DD_OK
, "IDirectDrawSurface_BltFast returned: %x\n", hr
);
2648 color
= getPixelColor_GDI(Surface1
, 1, 1);
2649 ok(GetRValue(color
) == 0 && GetGValue(color
) == 0x00 && GetBValue(color
) == 0xFF,
2650 "got R %02X G %02X B %02X, expected R 00 G 00 B FF\n",
2651 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2653 /* Color keyed blit. */
2654 p8_surface_fill_rect(offscreen
, 0, 0, 8, 8, 3);
2655 clrKey
.dwColorSpaceLowValue
= 3;
2656 clrKey
.dwColorSpaceHighValue
= 3;
2657 hr
= IDirectDrawSurface_SetColorKey(offscreen
, DDCKEY_SRCBLT
, &clrKey
);
2658 ok(hr
==D3D_OK
, "IDirectDrawSurfac_SetColorKey returned: %x\n", hr
);
2660 hr
= IDirectDrawSurface_BltFast(Surface1
, 100, 100, offscreen
, NULL
, DDBLTFAST_SRCCOLORKEY
);
2661 ok(hr
==DD_OK
, "IDirectDrawSurface_BltFast returned: %x\n", hr
);
2663 color
= getPixelColor_GDI(Surface1
, 105, 105);
2664 ok(GetRValue(color
) == 0 && GetGValue(color
) == 0xFF && GetBValue(color
) == 0,
2665 "got R %02X G %02X B %02X, expected R 00 G FF B 00\n",
2666 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2668 color
= getPixelColor_GDI(Surface1
, 112, 112);
2669 ok(GetRValue(color
) == 0 && GetGValue(color
) == 0x00 && GetBValue(color
) == 0xFF,
2670 "got R %02X G %02X B %02X, expected R 00 G 00 B FF\n",
2671 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2678 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
2679 ddbltfx
.dwSize
= sizeof(ddbltfx
);
2680 ddbltfx
.ddckSrcColorkey
.dwColorSpaceLowValue
= ddbltfx
.ddckSrcColorkey
.dwColorSpaceHighValue
= 2;
2681 hr
= IDirectDrawSurface_Blt(Surface1
, &rect
, offscreen
, NULL
,
2682 DDBLT_WAIT
| DDBLT_KEYSRC
| DDBLT_KEYSRCOVERRIDE
, &ddbltfx
);
2683 ok(hr
==DDERR_INVALIDPARAMS
, "IDirectDrawSurface_Blt returned: %x\n", hr
);
2684 hr
= IDirectDrawSurface_Blt(Surface1
, &rect
, offscreen
, NULL
,
2685 DDBLT_WAIT
| DDBLT_KEYSRCOVERRIDE
, &ddbltfx
);
2686 ok(hr
==DD_OK
, "IDirectDrawSurface_Blt returned: %x\n", hr
);
2688 color
= getPixelColor_GDI(Surface1
, 105, 205);
2689 ok(GetRValue(color
) == 0x80 && GetGValue(color
) == 0 && GetBValue(color
) == 0,
2690 "got R %02X G %02X B %02X, expected R 80 G 00 B 00\n",
2691 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2693 color
= getPixelColor_GDI(Surface1
, 112, 212);
2694 ok(GetRValue(color
) == 0 && GetGValue(color
) == 0xFF && GetBValue(color
) == 0,
2695 "got R %02X G %02X B %02X, expected R 00 G FF B 00\n",
2696 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2698 /* Test blitting and locking patterns that are likely to trigger bugs in opengl renderer (p8
2699 surface conversion and uploading/downloading to/from opengl texture). Similar patterns (
2700 blitting front buffer areas to/from an offscreen surface mixed with locking) are used by C&C
2702 IDirectDrawSurface_Release(offscreen
);
2704 memset (&ddsd
, 0, sizeof (ddsd
));
2705 ddsd
.dwSize
= sizeof (ddsd
);
2706 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
2708 ddsd
.dwHeight
= 480;
2709 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
2710 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
2711 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_PALETTEINDEXED8
;
2712 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 8;
2713 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &offscreen
, NULL
);
2714 ok(hr
== DD_OK
, "IDirectDraw_CreateSurface returned %08x\n", hr
);
2716 if (FAILED(hr
)) goto out
;
2718 /* Test two times, first time front buffer has a palette and second time front buffer
2719 has no palette; the latter is somewhat contrived example, but an app could set
2720 front buffer palette later. */
2721 for (i2
= 0; i2
< 2; i2
++) {
2723 hr
= IDirectDrawSurface_SetPalette(Surface1
, NULL
);
2724 ok(hr
==DD_OK
, "IDirectDrawSurface_SetPalette returned: %x\n", hr
);
2727 memset(&ddsd
, 0, sizeof(ddsd
));
2728 ddsd
.dwSize
= sizeof(ddsd
);
2729 hr
= IDirectDrawSurface_Lock(Surface1
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
2730 ok(hr
==DD_OK
, "IDirectDrawSurface_Lock returned: %x\n", hr
);
2732 for (i
= 0; i
< 256; i
++) {
2733 unsigned x
= (i
% 128) * 4;
2734 unsigned y
= (i
/ 128) * 4;
2735 BYTE
*p
= (BYTE
*)ddsd
.lpSurface
+ U1(ddsd
).lPitch
* y
+ x
;
2737 for (i1
= 0; i1
< 4; i1
++) {
2738 p
[0] = p
[1] = p
[2] = p
[3] = i
;
2739 p
+= U1(ddsd
).lPitch
;
2743 hr
= IDirectDrawSurface_Unlock(Surface1
, NULL
);
2744 ok(hr
==DD_OK
, "IDirectDrawSurface_UnLock returned: %x\n", hr
);
2746 hr
= IDirectDrawSurface_BltFast(offscreen
, 0, 0, Surface1
, NULL
, 0);
2747 ok(hr
==DD_OK
, "IDirectDrawSurface_BltFast returned: %x\n", hr
);
2749 /* This ensures offscreen surface contents will be downloaded to system memory. */
2750 memset(&ddsd
, 0, sizeof(ddsd
));
2751 ddsd
.dwSize
= sizeof(ddsd
);
2752 hr
= IDirectDrawSurface_Lock(offscreen
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
2753 ok(hr
==DD_OK
, "IDirectDrawSurface_Lock returned: %x\n", hr
);
2754 hr
= IDirectDrawSurface_Unlock(offscreen
, NULL
);
2755 ok(hr
==DD_OK
, "IDirectDrawSurface_UnLock returned: %x\n", hr
);
2757 /* Offscreen surface data will have to be converted and uploaded to texture. */
2762 hr
= IDirectDrawSurface_BltFast(offscreen
, 600, 400, Surface1
, &rect
, 0);
2763 ok(hr
==DD_OK
, "IDirectDrawSurface_BltFast returned: %x\n", hr
);
2765 /* This ensures offscreen surface contents will be downloaded to system memory. */
2766 memset(&ddsd
, 0, sizeof(ddsd
));
2767 ddsd
.dwSize
= sizeof(ddsd
);
2768 hr
= IDirectDrawSurface_Lock(offscreen
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
2769 ok(hr
==DD_OK
, "IDirectDrawSurface_Lock returned: %x\n", hr
);
2770 hr
= IDirectDrawSurface_Unlock(offscreen
, NULL
);
2771 ok(hr
==DD_OK
, "IDirectDrawSurface_UnLock returned: %x\n", hr
);
2773 hr
= IDirectDrawSurface_BltFast(Surface1
, 0, 0, offscreen
, NULL
, 0);
2774 ok(hr
==DD_OK
, "IDirectDrawSurface_BltFast returned: %x\n", hr
);
2776 memset(&ddsd
, 0, sizeof(ddsd
));
2777 ddsd
.dwSize
= sizeof(ddsd
);
2778 hr
= IDirectDrawSurface_Lock(Surface1
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
2779 ok(hr
==DD_OK
, "IDirectDrawSurface_Lock returned: %x\n", hr
);
2783 for (i
= 0; i
< 256; i
++) {
2784 unsigned x
= (i
% 128) * 4 + 1;
2785 unsigned y
= (i
/ 128) * 4 + 1;
2786 BYTE
*p
= (BYTE
*)ddsd
.lpSurface
+ U1(ddsd
).lPitch
* y
+ x
;
2788 if (*p
!= i
) differences
++;
2791 hr
= IDirectDrawSurface_Unlock(Surface1
, NULL
);
2792 ok(hr
==DD_OK
, "IDirectDrawSurface_UnLock returned: %x\n", hr
);
2794 ok(differences
== 0, i2
== 0 ? "Pass 1. Unexpected front buffer contents after blit (%u differences)\n" :
2795 "Pass 2 (with NULL front buffer palette). Unexpected front buffer contents after blit (%u differences)\n",
2801 if(ddprimpal
) IDirectDrawPalette_Release(ddprimpal
);
2802 if(offscreen
) IDirectDrawSurface_Release(offscreen
);
2803 if(Surface1
) IDirectDrawSurface_Release(Surface1
);
2804 if(DirectDraw1
) IDirectDraw_Release(DirectDraw1
);
2805 if(window
) DestroyWindow(window
);
2808 static void cubemap_test(IDirect3DDevice7
*device
)
2811 IDirectDraw7
*ddraw
;
2812 IDirectDrawSurface7
*cubemap
, *surface
;
2813 D3DDEVICEDESC7 d3dcaps
;
2816 DDSURFACEDESC2 ddsd
;
2819 static float quad
[] = {
2820 -1.0, -1.0, 0.1, 1.0, 0.0, 0.0, /* Lower left */
2821 0.0, -1.0, 0.1, 1.0, 0.0, 0.0,
2822 -1.0, 0.0, 0.1, 1.0, 0.0, 0.0,
2823 0.0, 0.0, 0.1, 1.0, 0.0, 0.0,
2825 0.0, -1.0, 0.1, 0.0, 1.0, 0.0, /* Lower right */
2826 1.0, -1.0, 0.1, 0.0, 1.0, 0.0,
2827 0.0, 0.0, 0.1, 0.0, 1.0, 0.0,
2828 1.0, 0.0, 0.1, 0.0, 1.0, 0.0,
2830 0.0, 0.0, 0.1, 0.0, 0.0, 1.0, /* upper right */
2831 1.0, 0.0, 0.1, 0.0, 0.0, 1.0,
2832 0.0, 1.0, 0.1, 0.0, 0.0, 1.0,
2833 1.0, 1.0, 0.1, 0.0, 0.0, 1.0,
2835 -1.0, 0.0, 0.1, -1.0, 0.0, 0.0, /* Upper left */
2836 0.0, 0.0, 0.1, -1.0, 0.0, 0.0,
2837 -1.0, 1.0, 0.1, -1.0, 0.0, 0.0,
2838 0.0, 1.0, 0.1, -1.0, 0.0, 0.0,
2841 memset(&DDBltFx
, 0, sizeof(DDBltFx
));
2842 DDBltFx
.dwSize
= sizeof(DDBltFx
);
2844 memset(&d3dcaps
, 0, sizeof(d3dcaps
));
2845 hr
= IDirect3DDevice7_GetCaps(device
, &d3dcaps
);
2846 ok(hr
== D3D_OK
, "IDirect3DDevice7_GetCaps returned %08x\n", hr
);
2847 if(!(d3dcaps
.dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_CUBEMAP
))
2849 skip("No cubemap support\n");
2853 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff000000, 0.0, 0);
2854 ok(hr
== D3D_OK
, "IDirect3DDevice7_Clear failed with %08x\n", hr
);
2856 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
2857 ok(hr
== D3D_OK
, "IDirect3DDevice7_GetDirect3D returned %08x\n", hr
);
2858 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **) &ddraw
);
2859 ok(hr
== D3D_OK
, "IDirect3D7_QueryInterface returned %08x\n", hr
);
2860 IDirect3D7_Release(d3d
);
2863 memset(&ddsd
, 0, sizeof(ddsd
));
2864 ddsd
.dwSize
= sizeof(ddsd
);
2865 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
2866 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
;
2869 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
;
2870 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
| DDSCAPS2_TEXTUREMANAGE
;
2871 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
2872 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
2873 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00FF0000;
2874 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000FF00;
2875 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000FF;
2877 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &cubemap
, NULL
);
2878 ok(hr
== DD_OK
, "IDirectDraw7_CreateSurface returned %08x\n", hr
);
2879 IDirectDraw7_Release(ddraw
);
2882 U5(DDBltFx
).dwFillColor
= 0x00ff0000;
2883 hr
= IDirectDrawSurface7_Blt(cubemap
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
, &DDBltFx
);
2884 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
2886 memset(&caps
, 0, sizeof(caps
));
2887 caps
.dwCaps
= DDSCAPS_TEXTURE
;
2888 caps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_NEGATIVEX
;
2889 hr
= IDirectDrawSurface_GetAttachedSurface(cubemap
, &caps
, &surface
);
2890 ok(hr
== DD_OK
, "IDirectDrawSurface7_Lock returned %08x\n", hr
);
2891 U5(DDBltFx
).dwFillColor
= 0x0000ffff;
2892 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
, &DDBltFx
);
2893 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
2895 caps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_NEGATIVEZ
;
2896 hr
= IDirectDrawSurface_GetAttachedSurface(cubemap
, &caps
, &surface
);
2897 ok(hr
== DD_OK
, "IDirectDrawSurface7_Lock returned %08x\n", hr
);
2898 U5(DDBltFx
).dwFillColor
= 0x0000ff00;
2899 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
, &DDBltFx
);
2900 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
2902 caps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_POSITIVEZ
;
2903 hr
= IDirectDrawSurface_GetAttachedSurface(cubemap
, &caps
, &surface
);
2904 ok(hr
== DD_OK
, "IDirectDrawSurface7_Lock returned %08x\n", hr
);
2905 U5(DDBltFx
).dwFillColor
= 0x000000ff;
2906 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
, &DDBltFx
);
2907 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
2909 caps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_NEGATIVEY
;
2910 hr
= IDirectDrawSurface_GetAttachedSurface(cubemap
, &caps
, &surface
);
2911 ok(hr
== DD_OK
, "IDirectDrawSurface7_Lock returned %08x\n", hr
);
2912 U5(DDBltFx
).dwFillColor
= 0x00ffff00;
2913 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
, &DDBltFx
);
2914 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
2916 caps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_POSITIVEY
;
2917 hr
= IDirectDrawSurface_GetAttachedSurface(cubemap
, &caps
, &surface
);
2918 ok(hr
== DD_OK
, "IDirectDrawSurface7_Lock returned %08x\n", hr
);
2919 U5(DDBltFx
).dwFillColor
= 0x00ff00ff;
2920 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
, &DDBltFx
);
2921 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
2923 hr
= IDirect3DDevice7_SetTexture(device
, 0, cubemap
);
2924 ok(hr
== DD_OK
, "IDirect3DDevice7_SetTexture returned %08x\n", hr
);
2925 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
2926 ok(hr
== DD_OK
, "IDirect3DDevice7_SetTextureStageState returned %08x\n", hr
);
2927 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
2928 ok(hr
== DD_OK
, "IDirect3DDevice7_SetTextureStageState returned %08x\n", hr
);
2930 hr
= IDirect3DDevice7_BeginScene(device
);
2931 ok(hr
== DD_OK
, "IDirect3DDevice7_BeginScene returned %08x\n", hr
);
2934 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1
, quad
+ 0 * 6, 4, 0);
2935 if (hr
== DDERR_UNSUPPORTED
|| hr
== DDERR_NODIRECTDRAWHW
)
2938 win_skip("IDirect3DDevice7_DrawPrimitive is not completely implemented, colors won't be tested\n");
2939 hr
= IDirect3DDevice7_EndScene(device
);
2940 ok(hr
== DD_OK
, "IDirect3DDevice7_EndScene returned %08x\n", hr
);
2943 ok(hr
== DD_OK
, "IDirect3DDevice7_DrawPrimitive returned %08x\n", hr
);
2944 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1
, quad
+ 4 * 6, 4, 0);
2945 ok(hr
== DD_OK
, "IDirect3DDevice7_DrawPrimitive returned %08x\n", hr
);
2946 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1
, quad
+ 8 * 6, 4, 0);
2947 ok(hr
== DD_OK
, "IDirect3DDevice7_DrawPrimitive returned %08x\n", hr
);
2948 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1
, quad
+ 12* 6, 4, 0);
2949 ok(hr
== DD_OK
, "IDirect3DDevice7_DrawPrimitive returned %08x\n", hr
);
2951 hr
= IDirect3DDevice7_EndScene(device
);
2952 ok(hr
== DD_OK
, "IDirect3DDevice7_EndScene returned %08x\n", hr
);
2954 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
2955 ok(hr
== DD_OK
, "IDirect3DDevice7_SetTextureStageState returned %08x\n", hr
);
2957 color
= getPixelColor(device
, 160, 360); /* lower left quad - positivex */
2958 ok(color
== 0x00ff0000, "DDSCAPS2_CUBEMAP_POSITIVEX has color 0x%08x, expected 0x00ff0000\n", color
);
2959 color
= getPixelColor(device
, 160, 120); /* upper left quad - negativex */
2960 ok(color
== 0x0000ffff, "DDSCAPS2_CUBEMAP_NEGATIVEX has color 0x%08x, expected 0x0000ffff\n", color
);
2961 color
= getPixelColor(device
, 480, 360); /* lower right quad - positivey */
2962 ok(color
== 0x00ff00ff, "DDSCAPS2_CUBEMAP_POSITIVEY has color 0x%08x, expected 0x00ff00ff\n", color
);
2963 color
= getPixelColor(device
, 480, 120); /* upper right quad - positivez */
2964 ok(color
== 0x000000ff, "DDSCAPS2_CUBEMAP_POSITIVEZ has color 0x%08x, expected 0x000000ff\n", color
);
2967 hr
= IDirect3DDevice7_SetTexture(device
, 0, NULL
);
2968 ok(hr
== DD_OK
, "IDirect3DDevice7_SetTexture returned %08x\n", hr
);
2969 IDirectDrawSurface7_Release(cubemap
);
2972 /* This test tests depth clamping / clipping behaviour:
2973 * - With software vertex processing, depth values are clamped to the
2974 * minimum / maximum z value when D3DRS_CLIPPING is disabled, and clipped
2975 * when D3DRS_CLIPPING is enabled. Pretransformed vertices behave the
2976 * same as regular vertices here.
2977 * - With hardware vertex processing, D3DRS_CLIPPING seems to be ignored.
2978 * Normal vertices are always clipped. Pretransformed vertices are
2979 * clipped when D3DPMISCCAPS_CLIPTLVERTS is set, clamped when it isn't.
2980 * - The viewport's MinZ/MaxZ is irrelevant for this.
2982 static void depth_clamp_test(IDirect3DDevice7
*device
)
2984 struct tvertex quad1
[] =
2986 { 0.0f
, 0.0f
, 5.0f
, 1.0f
, 0xff002b7f},
2987 {640.0f
, 0.0f
, 5.0f
, 1.0f
, 0xff002b7f},
2988 { 0.0f
, 480.0f
, 5.0f
, 1.0f
, 0xff002b7f},
2989 {640.0f
, 480.0f
, 5.0f
, 1.0f
, 0xff002b7f},
2991 struct tvertex quad2
[] =
2993 { 0.0f
, 300.0f
, 10.0f
, 1.0f
, 0xfff9e814},
2994 {640.0f
, 300.0f
, 10.0f
, 1.0f
, 0xfff9e814},
2995 { 0.0f
, 360.0f
, 10.0f
, 1.0f
, 0xfff9e814},
2996 {640.0f
, 360.0f
, 10.0f
, 1.0f
, 0xfff9e814},
2998 struct tvertex quad3
[] =
3000 {112.0f
, 108.0f
, 5.0f
, 1.0f
, 0xffffffff},
3001 {208.0f
, 108.0f
, 5.0f
, 1.0f
, 0xffffffff},
3002 {112.0f
, 204.0f
, 5.0f
, 1.0f
, 0xffffffff},
3003 {208.0f
, 204.0f
, 5.0f
, 1.0f
, 0xffffffff},
3005 struct tvertex quad4
[] =
3007 { 42.0f
, 41.0f
, 10.0f
, 1.0f
, 0xffffffff},
3008 {112.0f
, 41.0f
, 10.0f
, 1.0f
, 0xffffffff},
3009 { 42.0f
, 108.0f
, 10.0f
, 1.0f
, 0xffffffff},
3010 {112.0f
, 108.0f
, 10.0f
, 1.0f
, 0xffffffff},
3014 struct vec3 position
;
3019 {{-0.5f
, 0.5f
, 10.0f
}, 0xff14f914},
3020 {{ 0.5f
, 0.5f
, 10.0f
}, 0xff14f914},
3021 {{-0.5f
, -0.5f
, 10.0f
}, 0xff14f914},
3022 {{ 0.5f
, -0.5f
, 10.0f
}, 0xff14f914},
3026 {{-1.0f
, 0.5f
, 10.0f
}, 0xfff91414},
3027 {{ 1.0f
, 0.5f
, 10.0f
}, 0xfff91414},
3028 {{-1.0f
, 0.25f
, 10.0f
}, 0xfff91414},
3029 {{ 1.0f
, 0.25f
, 10.0f
}, 0xfff91414},
3043 hr
= IDirect3DDevice7_SetViewport(device
, &vp
);
3044 ok(SUCCEEDED(hr
), "SetViewport failed, hr %#x.\n", hr
);
3046 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff00ff00, 1.0, 0);
3047 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
3049 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
3050 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
3051 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
3052 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
3053 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZWRITEENABLE
, TRUE
);
3054 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
3055 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZFUNC
, D3DCMP_LESSEQUAL
);
3056 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
3058 hr
= IDirect3DDevice7_BeginScene(device
);
3059 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
3061 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, quad1
, 4, 0);
3062 ok(SUCCEEDED(hr
), "DrawPrimitive failed, hr %#x.\n", hr
);
3063 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, quad2
, 4, 0);
3064 ok(SUCCEEDED(hr
), "DrawPrimitive failed, hr %#x.\n", hr
);
3066 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, TRUE
);
3067 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
3069 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, quad3
, 4, 0);
3070 ok(SUCCEEDED(hr
), "DrawPrimitive failed, hr %#x.\n", hr
);
3071 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, quad4
, 4, 0);
3072 ok(SUCCEEDED(hr
), "DrawPrimitive failed, hr %#x.\n", hr
);
3074 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
3075 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
3077 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad5
, 4, 0);
3078 ok(SUCCEEDED(hr
), "DrawPrimitive failed, hr %#x.\n", hr
);
3080 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, TRUE
);
3081 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
3083 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad6
, 4, 0);
3084 ok(SUCCEEDED(hr
), "DrawPrimitive failed, hr %#x.\n", hr
);
3086 hr
= IDirect3DDevice7_EndScene(device
);
3087 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
3089 color
= getPixelColor(device
, 75, 75);
3090 ok(color_match(color
, 0x00ffffff, 1) || color_match(color
, 0x0000ff00, 1), "color 0x%08x.\n", color
);
3091 color
= getPixelColor(device
, 150, 150);
3092 ok(color_match(color
, 0x00ffffff, 1) || color_match(color
, 0x0000ff00, 1), "color 0x%08x.\n", color
);
3093 color
= getPixelColor(device
, 320, 240);
3094 ok(color_match(color
, 0x00002b7f, 1) || color_match(color
, 0x0000ff00, 1), "color 0x%08x.\n", color
);
3095 color
= getPixelColor(device
, 320, 330);
3096 ok(color_match(color
, 0x00f9e814, 1) || color_match(color
, 0x0000ff00, 1), "color 0x%08x.\n", color
);
3097 color
= getPixelColor(device
, 320, 330);
3098 ok(color_match(color
, 0x00f9e814, 1) || color_match(color
, 0x0000ff00, 1), "color 0x%08x.\n", color
);
3102 hr
= IDirect3DDevice7_SetViewport(device
, &vp
);
3103 ok(SUCCEEDED(hr
), "SetViewport failed, hr %#x.\n", hr
);
3106 static void DX1_BackBufferFlipTest(void)
3109 IDirectDraw
*DirectDraw1
= NULL
;
3110 IDirectDrawSurface
*Primary
= NULL
;
3111 IDirectDrawSurface
*Backbuffer
= NULL
;
3116 const DWORD white
= 0xffffff;
3117 const DWORD red
= 0xff0000;
3118 BOOL attached
= FALSE
;
3120 wc
.lpfnWndProc
= DefWindowProcA
;
3121 wc
.lpszClassName
= "DX1_BackBufferFlipTest_wc";
3122 RegisterClassA(&wc
);
3123 window
= CreateWindowA("DX1_BackBufferFlipTest_wc", "DX1_BackBufferFlipTest",
3124 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
3126 hr
= DirectDrawCreate( NULL
, &DirectDraw1
, NULL
);
3127 ok(hr
==DD_OK
|| hr
==DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreate returned: %x\n", hr
);
3128 if(FAILED(hr
)) goto out
;
3130 hr
= IDirectDraw_SetCooperativeLevel(DirectDraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3131 ok(hr
==DD_OK
, "SetCooperativeLevel returned: %x\n", hr
);
3132 if(FAILED(hr
)) goto out
;
3134 hr
= IDirectDraw_SetDisplayMode(DirectDraw1
, 640, 480, 32);
3136 /* 24 bit is fine too */
3137 hr
= IDirectDraw_SetDisplayMode(DirectDraw1
, 640, 480, 24);
3139 ok(hr
==DD_OK
|| hr
== DDERR_UNSUPPORTED
, "SetDisplayMode returned: %x\n", hr
);
3144 memset(&ddsd
, 0, sizeof(DDSURFACEDESC
));
3145 ddsd
.dwSize
= sizeof(DDSURFACEDESC
);
3146 ddsd
.dwFlags
= DDSD_CAPS
;
3147 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3149 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &Primary
, NULL
);
3150 ok(hr
==DD_OK
, "IDirectDraw_CreateSurface returned: %08x\n", hr
);
3152 memset(&ddsd
, 0, sizeof(DDSURFACEDESC
));
3153 ddsd
.dwSize
= sizeof(DDSURFACEDESC
);
3154 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
3155 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_BACKBUFFER
;
3157 ddsd
.dwHeight
= 480;
3158 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
3159 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
3160 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
3161 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
3162 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
3163 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
3165 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &Backbuffer
, NULL
);
3166 ok(hr
==DD_OK
, "IDirectDraw_CreateSurface returned: %08x\n", hr
);
3167 if(FAILED(hr
)) goto out
;
3169 hr
= IDirectDrawSurface_AddAttachedSurface(Primary
, Backbuffer
);
3170 todo_wine
ok(hr
== DD_OK
|| broken(hr
== DDERR_CANNOTATTACHSURFACE
),
3171 "Attaching a back buffer to a front buffer returned %08x\n", hr
);
3172 if (FAILED(hr
)) goto out
;
3176 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
3177 ddbltfx
.dwSize
= sizeof(ddbltfx
);
3178 U5(ddbltfx
).dwFillColor
= red
;
3179 hr
= IDirectDrawSurface_Blt(Backbuffer
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
3180 ok(hr
== DD_OK
, "IDirectDrawSurface_Blt returned: %x\n", hr
);
3182 U5(ddbltfx
).dwFillColor
= white
;
3183 hr
= IDirectDrawSurface_Blt(Primary
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
3184 ok(hr
== DD_OK
, "IDirectDrawSurface_Blt returned: %x\n", hr
);
3187 color
= getPixelColor_GDI(Primary
, 5, 5);
3188 ok(GetRValue(color
) == 0xFF && GetGValue(color
) == 0xFF && GetBValue(color
) == 0xFF,
3189 "got R %02X G %02X B %02X, expected R FF G FF B FF\n",
3190 GetRValue(color
), GetGValue(color
), GetBValue(color
));
3192 color
= getPixelColor_GDI(Backbuffer
, 5, 5);
3193 ok(GetRValue(color
) == 0xFF && GetGValue(color
) == 0 && GetBValue(color
) == 0,
3194 "got R %02X G %02X B %02X, expected R FF G 00 B 00\n",
3195 GetRValue(color
), GetGValue(color
), GetBValue(color
));
3197 hr
= IDirectDrawSurface_Flip(Primary
, NULL
, DDFLIP_WAIT
);
3198 todo_wine
ok(hr
== DD_OK
, "IDirectDrawSurface_Flip returned 0x%08x\n", hr
);
3202 color
= getPixelColor_GDI(Primary
, 5, 5);
3203 ok(GetRValue(color
) == 0xFF && GetGValue(color
) == 0 && GetBValue(color
) == 0,
3204 "got R %02X G %02X B %02X, expected R FF G 00 B 00\n",
3205 GetRValue(color
), GetGValue(color
), GetBValue(color
));
3207 color
= getPixelColor_GDI(Backbuffer
, 5, 5);
3208 ok((GetRValue(color
) == 0xFF && GetGValue(color
) == 0xFF && GetBValue(color
) == 0xFF) ||
3209 broken(GetRValue(color
) == 0xFF && GetGValue(color
) == 0 && GetBValue(color
) == 0), /* broken driver */
3210 "got R %02X G %02X B %02X, expected R FF G FF B FF\n",
3211 GetRValue(color
), GetGValue(color
), GetBValue(color
));
3219 IDirectDrawSurface_DeleteAttachedSurface(Primary
, 0, Backbuffer
);
3220 IDirectDrawSurface_Release(Backbuffer
);
3222 if (Primary
) IDirectDrawSurface_Release(Primary
);
3223 if (DirectDraw1
) IDirectDraw_Release(DirectDraw1
);
3224 if (window
) DestroyWindow(window
);
3231 if(!createObjects())
3233 skip("Cannot initialize DirectDraw and Direct3D, skipping\n");
3237 /* Check for the reliability of the returned data */
3238 hr
= IDirect3DDevice7_Clear(Direct3DDevice
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
3241 skip("Clear failed, can't assure correctness of the test results, skipping\n");
3245 color
= getPixelColor(Direct3DDevice
, 1, 1);
3246 if(color
!=0x00ff0000)
3248 skip("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests, skipping\n", color
);
3252 hr
= IDirect3DDevice7_Clear(Direct3DDevice
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ddee, 0.0, 0);
3255 skip("Clear failed, can't assure correctness of the test results, skipping\n");
3259 color
= getPixelColor(Direct3DDevice
, 639, 479);
3260 if(color
!= 0x0000ddee)
3262 skip("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests, skipping\n", color
);
3266 /* Now run the tests */
3267 blt_test(Direct3DDevice
);
3268 depth_clamp_test(Direct3DDevice
);
3269 lighting_test(Direct3DDevice
);
3270 clear_test(Direct3DDevice
);
3271 fog_test(Direct3DDevice
);
3272 offscreen_test(Direct3DDevice
);
3273 alpha_test(Direct3DDevice
);
3274 rhw_zero_test(Direct3DDevice
);
3275 cubemap_test(Direct3DDevice
);
3277 releaseObjects(); /* release DX7 interfaces to test D3D1 */
3279 if(!D3D1_createObjects()) {
3280 skip("Cannot initialize D3D1, skipping\n");
3283 D3D1_TextureMapBlendTest();
3284 D3D1_ViewportClearTest();
3286 D3D1_releaseObjects();
3288 D3D3_ViewportClearTest();
3290 DX1_BackBufferFlipTest();