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"
37 static IDirectDraw7
*DirectDraw
;
38 static IDirectDrawSurface7
*Surface
;
39 static IDirectDrawSurface7
*depth_buffer
;
40 static IDirect3D7
*Direct3D
;
41 static IDirect3DDevice7
*Direct3DDevice
;
43 static IDirectDraw
*DirectDraw1
;
44 static IDirectDrawSurface
*Surface1
;
45 static IDirect3D
*Direct3D1
;
46 static IDirect3DDevice
*Direct3DDevice1
;
47 static IDirect3DExecuteBuffer
*ExecuteBuffer
;
48 static IDirect3DViewport
*Viewport
;
50 static BOOL refdevice
= FALSE
;
52 static HRESULT (WINAPI
*pDirectDrawCreateEx
)(GUID
*driver_guid
,
53 void **ddraw
, REFIID interface_iid
, IUnknown
*outer
);
55 static BOOL
color_match(D3DCOLOR c1
, D3DCOLOR c2
, BYTE max_diff
)
57 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
59 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
61 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
63 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
67 static HRESULT WINAPI
enum_z_fmt(DDPIXELFORMAT
*fmt
, void *ctx
)
69 DDPIXELFORMAT
*zfmt
= ctx
;
71 if(U1(*fmt
).dwZBufferBitDepth
> U1(*zfmt
).dwZBufferBitDepth
)
78 static HRESULT WINAPI
enum_devtype_cb(char *desc_str
, char *name
, D3DDEVICEDESC7
*desc
, void *ctx
)
81 if (IsEqualGUID(&desc
->deviceGUID
, &IID_IDirect3DTnLHalDevice
))
84 return DDENUMRET_CANCEL
;
89 static BOOL
createObjects(void)
92 HMODULE hmod
= GetModuleHandleA("ddraw.dll");
97 const GUID
*devtype
= &IID_IDirect3DHALDevice
;
99 if(!hmod
) return FALSE
;
100 pDirectDrawCreateEx
= (void*)GetProcAddress(hmod
, "DirectDrawCreateEx");
101 if(!pDirectDrawCreateEx
) return FALSE
;
103 hr
= pDirectDrawCreateEx(NULL
, (void **) &DirectDraw
, &IID_IDirectDraw7
, NULL
);
104 ok(hr
==DD_OK
|| hr
==DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreateEx returned: %x\n", hr
);
105 if(!DirectDraw
) goto err
;
107 wc
.lpfnWndProc
= DefWindowProcA
;
108 wc
.lpszClassName
= "d3d7_test_wc";
110 window
= CreateWindowA("d3d7_test_wc", "d3d7_test", WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
,
111 0, 0, 640, 480, 0, 0, 0, 0);
113 hr
= IDirectDraw7_SetCooperativeLevel(DirectDraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
114 ok(hr
== DD_OK
, "IDirectDraw7_SetCooperativeLevel failed with %08x\n", hr
);
115 if(FAILED(hr
)) goto err
;
116 hr
= IDirectDraw7_SetDisplayMode(DirectDraw
, 640, 480, 32, 0, 0);
118 /* 24 bit is fine too */
119 hr
= IDirectDraw7_SetDisplayMode(DirectDraw
, 640, 480, 24, 0, 0);
122 ok(hr
== DD_OK
|| hr
== DDERR_UNSUPPORTED
, "IDirectDraw7_SetDisplayMode failed with %08x\n", hr
);
124 /* use trace, the caller calls skip() */
125 trace("SetDisplayMode failed\n");
129 hr
= IDirectDraw7_QueryInterface(DirectDraw
, &IID_IDirect3D7
, (void**) &Direct3D
);
130 if (hr
== E_NOINTERFACE
) goto err
;
131 ok(hr
==DD_OK
, "QueryInterface returned: %08x\n", hr
);
133 /* DirectDraw Flipping behavior doesn't seem that well-defined. The reference rasterizer behaves differently
134 * than hardware implementations. Request single buffering, that seems to work everywhere
136 memset(&ddsd
, 0, sizeof(ddsd
));
137 ddsd
.dwSize
= sizeof(ddsd
);
138 ddsd
.dwFlags
= DDSD_CAPS
;
139 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
;
140 ddsd
.dwBackBufferCount
= 1;
141 hr
= IDirectDraw7_CreateSurface(DirectDraw
, &ddsd
, &Surface
, NULL
);
142 if(FAILED(hr
)) goto err
;
144 hr
= IDirect3D7_EnumDevices(Direct3D
, enum_devtype_cb
, &hal_ok
);
145 ok(SUCCEEDED(hr
), "Failed to enumerate devices, hr %#x.\n", hr
);
146 if (hal_ok
) devtype
= &IID_IDirect3DTnLHalDevice
;
148 memset(&zfmt
, 0, sizeof(zfmt
));
149 hr
= IDirect3D7_EnumZBufferFormats(Direct3D
, devtype
, enum_z_fmt
, &zfmt
);
150 if (FAILED(hr
)) goto err
;
151 if (zfmt
.dwSize
== 0) goto err
;
153 memset(&ddsd
, 0, sizeof(ddsd
));
154 ddsd
.dwSize
= sizeof(ddsd
);
155 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
156 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
157 U4(ddsd
).ddpfPixelFormat
= zfmt
;
160 hr
= IDirectDraw7_CreateSurface(DirectDraw
, &ddsd
, &depth_buffer
, NULL
);
161 ok(SUCCEEDED(hr
), "CreateSurface failed, hr %#x.\n", hr
);
162 if (FAILED(hr
)) goto err
;
164 hr
= IDirectDrawSurface_AddAttachedSurface(Surface
, depth_buffer
);
165 ok(SUCCEEDED(hr
), "AddAttachedSurface failed, hr %#x.\n", hr
);
166 if (FAILED(hr
)) goto err
;
168 hr
= IDirect3D7_CreateDevice(Direct3D
, devtype
, Surface
, &Direct3DDevice
);
169 if (FAILED(hr
) || !Direct3DDevice
) goto err
;
173 if(DirectDraw
) IDirectDraw7_Release(DirectDraw
);
174 if (depth_buffer
) IDirectDrawSurface7_Release(depth_buffer
);
175 if(Surface
) IDirectDrawSurface7_Release(Surface
);
176 if(Direct3D
) IDirect3D7_Release(Direct3D
);
177 if(Direct3DDevice
) IDirect3DDevice7_Release(Direct3DDevice
);
178 if(window
) DestroyWindow(window
);
182 static void releaseObjects(void)
184 IDirect3DDevice7_Release(Direct3DDevice
);
185 IDirect3D7_Release(Direct3D
);
186 IDirectDrawSurface7_Release(depth_buffer
);
187 IDirectDrawSurface7_Release(Surface
);
188 IDirectDraw7_Release(DirectDraw
);
189 DestroyWindow(window
);
192 static DWORD
getPixelColor(IDirect3DDevice7
*device
, UINT x
, UINT y
)
197 RECT rectToLock
= {x
, y
, x
+1, y
+1};
198 IDirectDrawSurface7
*surf
= NULL
;
200 /* Some implementations seem to dislike direct locking on the front buffer. Thus copy the front buffer
201 * to an offscreen surface and lock it instead of the front buffer
203 memset(&ddsd
, 0, sizeof(ddsd
));
204 ddsd
.dwSize
= sizeof(ddsd
);
205 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
206 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
209 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
;
210 hr
= IDirectDraw7_CreateSurface(DirectDraw
, &ddsd
, &surf
, NULL
);
211 ok(hr
== DD_OK
, "IDirectDraw7_CreateSurface failed with %08x\n", hr
);
214 trace("cannot create helper surface\n");
218 memset(&ddsd
, 0, sizeof(ddsd
));
219 ddsd
.dwSize
= sizeof(ddsd
);
220 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
222 hr
= IDirectDrawSurface_BltFast(surf
, 0, 0, Surface
, NULL
, 0);
223 ok(hr
== DD_OK
, "IDirectDrawSurface7_BltFast returned %08x\n", hr
);
226 trace("Cannot blit\n");
231 hr
= IDirectDrawSurface7_Lock(surf
, &rectToLock
, &ddsd
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
234 trace("Can't lock the offscreen surface, hr=%08x\n", hr
);
239 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
240 * really important for these tests
242 ret
= ((DWORD
*) ddsd
.lpSurface
)[0] & 0x00ffffff;
243 hr
= IDirectDrawSurface7_Unlock(surf
, NULL
);
246 trace("Can't unlock the offscreen surface, hr=%08x\n", hr
);
250 IDirectDrawSurface7_Release(surf
);
254 static void set_viewport_size(IDirect3DDevice7
*device
)
256 D3DVIEWPORT7 vp
= {0};
259 IDirectDrawSurface7
*target
;
261 hr
= IDirect3DDevice7_GetRenderTarget(device
, &target
);
262 ok(hr
== D3D_OK
, "IDirect3DDevice7_GetRenderTarget returned %08x\n", hr
);
264 memset(&ddsd
, 0, sizeof(ddsd
));
265 ddsd
.dwSize
= sizeof(ddsd
);
266 hr
= IDirectDrawSurface7_GetSurfaceDesc(target
, &ddsd
);
267 ok(hr
== D3D_OK
, "IDirectDrawSurface7_GetSurfaceDesc returned %08x\n", hr
);
268 IDirectDrawSurface7_Release(target
);
270 vp
.dwWidth
= ddsd
.dwWidth
;
271 vp
.dwHeight
= ddsd
.dwHeight
;
272 hr
= IDirect3DDevice7_SetViewport(device
, &vp
);
273 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetViewport returned %08x\n", hr
);
277 static void lighting_test(IDirect3DDevice7
*device
)
280 DWORD fvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
281 DWORD nfvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_NORMAL
;
286 1.0f
, 0.0f
, 0.0f
, 0.0f
,
287 0.0f
, 1.0f
, 0.0f
, 0.0f
,
288 0.0f
, 0.0f
, 1.0f
, 0.0f
,
289 0.0f
, 0.0f
, 0.0f
, 1.0f
,
293 struct vec3 position
;
298 {{-1.0f
, -1.0f
, 0.1f
}, 0xffff0000},
299 {{-1.0f
, 0.0f
, 0.1f
}, 0xffff0000},
300 {{ 0.0f
, 0.0f
, 0.1f
}, 0xffff0000},
301 {{ 0.0f
, -1.0f
, 0.1f
}, 0xffff0000},
305 {{-1.0f
, 0.0f
, 0.1f
}, 0xff00ff00},
306 {{-1.0f
, 1.0f
, 0.1f
}, 0xff00ff00},
307 {{ 0.0f
, 1.0f
, 0.1f
}, 0xff00ff00},
308 {{ 0.0f
, 0.0f
, 0.1f
}, 0xff00ff00},
312 struct vec3 position
;
318 {{0.0f
, -1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
319 {{0.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
320 {{1.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
321 {{1.0f
, -1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
325 {{0.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
326 {{0.0f
, 1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
327 {{1.0f
, 1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
328 {{1.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
330 WORD Indices
[] = {0, 1, 2, 2, 3, 0};
332 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
333 ok(hr
== D3D_OK
, "IDirect3DDevice7_Clear failed with %08x\n", hr
);
335 /* Setup some states that may cause issues */
336 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
337 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetTransform returned %08x\n", hr
);
338 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
339 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetTransform returned %08x\n", hr
);
340 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
341 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetTransform returned %08x\n", hr
);
342 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
343 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
344 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
345 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
346 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
347 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
348 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_STENCILENABLE
, FALSE
);
349 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
350 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ALPHATESTENABLE
, FALSE
);
351 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
352 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
);
353 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
354 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
355 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed with %08x\n", hr
);
357 hr
= IDirect3DDevice7_BeginScene(device
);
358 ok(hr
== D3D_OK
, "IDirect3DDevice7_BeginScene failed with %08x\n", hr
);
361 /* No lights are defined... That means, lit vertices should be entirely black */
362 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
363 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
364 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, fvf
, unlitquad
, 4 /* NumVerts */,
365 Indices
, 6 /* Indexcount */, 0 /* flags */);
366 ok(hr
== D3D_OK
, "IDirect3DDevice7_DrawIndexedPrimitiveUP failed with %08x\n", hr
);
368 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
369 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
370 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, fvf
, litquad
, 4 /* NumVerts */,
371 Indices
, 6 /* Indexcount */, 0 /* flags */);
372 ok(hr
== D3D_OK
, "IDirect3DDevice7_DrawIndexedPrimitiveUP failed with %08x\n", hr
);
374 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
375 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
376 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, nfvf
, unlitnquad
, 4 /* NumVerts */,
377 Indices
, 6 /* Indexcount */, 0 /* flags */);
378 ok(hr
== D3D_OK
, "IDirect3DDevice7_DrawIndexedPrimitiveUP failed with %08x\n", hr
);
380 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
381 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
382 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, nfvf
, litnquad
, 4 /* NumVerts */,
383 Indices
, 6 /* Indexcount */, 0 /* flags */);
384 ok(hr
== D3D_OK
, "IDirect3DDevice7_DrawIndexedPrimitiveUP failed with %08x\n", hr
);
386 hr
= IDirect3DDevice7_EndScene(device
);
387 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndScene failed with %08x\n", hr
);
390 color
= getPixelColor(device
, 160, 360); /* Lower left quad - unlit without normals */
391 ok(color
== 0x00ff0000, "Unlit quad without normals has color 0x%08x, expected 0x00ff0000.\n", color
);
392 color
= getPixelColor(device
, 160, 120); /* Upper left quad - lit without normals */
393 ok(color
== 0x00000000, "Lit quad without normals has color 0x%08x, expected 0x00000000.\n", color
);
394 color
= getPixelColor(device
, 480, 360); /* Lower right quad - unlit with normals */
395 ok(color
== 0x000000ff, "Unlit quad with normals has color 0x%08x, expected 0x000000ff.\n", color
);
396 color
= getPixelColor(device
, 480, 120); /* Upper right quad - lit with normals */
397 ok(color
== 0x00000000, "Lit quad with normals has color 0x%08x, expected 0x00000000.\n", color
);
399 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
400 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned %08x\n", hr
);
403 static void clear_test(IDirect3DDevice7
*device
)
405 /* Tests the correctness of clearing parameters */
411 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
412 ok(hr
== D3D_OK
, "IDirect3DDevice7_Clear failed with %08x\n", hr
);
414 /* Positive x, negative y */
416 U2(rect
[0]).y1
= 480;
417 U3(rect
[0]).x2
= 320;
418 U4(rect
[0]).y2
= 240;
420 /* Positive x, positive y */
423 U3(rect
[1]).x2
= 320;
424 U4(rect
[1]).y2
= 240;
425 /* Clear 2 rectangles with one call. Shows that a positive value is returned, but the negative rectangle
426 * is ignored, the positive is still cleared afterwards
428 hr
= IDirect3DDevice7_Clear(device
, 2, rect
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
429 ok(hr
== D3D_OK
, "IDirect3DDevice7_Clear failed with %08x\n", hr
);
431 /* negative x, negative y */
432 U1(rect_negneg
).x1
= 640;
433 U2(rect_negneg
).y1
= 240;
434 U3(rect_negneg
).x2
= 320;
435 U4(rect_negneg
).y2
= 0;
436 hr
= IDirect3DDevice7_Clear(device
, 1, &rect_negneg
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0, 0);
437 ok(hr
== D3D_OK
, "IDirect3DDevice7_Clear failed with %08x\n", hr
);
439 color
= getPixelColor(device
, 160, 360); /* lower left quad */
440 ok(color
== 0x00ffffff, "Clear rectangle 3(pos, neg) has color %08x\n", color
);
441 color
= getPixelColor(device
, 160, 120); /* upper left quad */
442 ok(color
== 0x00ff0000, "Clear rectangle 1(pos, pos) has color %08x\n", color
);
443 color
= getPixelColor(device
, 480, 360); /* lower right quad */
444 ok(color
== 0x00ffffff, "Clear rectangle 4(NULL) has color %08x\n", color
);
445 color
= getPixelColor(device
, 480, 120); /* upper right quad */
446 ok(color
== 0x00ffffff, "Clear rectangle 4(neg, neg) has color %08x\n", color
);
461 static void fog_test(IDirect3DDevice7
*device
)
465 float start
= 0.0, end
= 1.0;
468 /* Gets full z based fog with linear fog, no fog with specular color */
469 struct sVertex untransformed_1
[] = {
470 {-1, -1, 0.1f
, 0xFFFF0000, 0xFF000000 },
471 {-1, 0, 0.1f
, 0xFFFF0000, 0xFF000000 },
472 { 0, 0, 0.1f
, 0xFFFF0000, 0xFF000000 },
473 { 0, -1, 0.1f
, 0xFFFF0000, 0xFF000000 },
475 /* Ok, I am too lazy to deal with transform matrices */
476 struct sVertex untransformed_2
[] = {
477 {-1, 0, 1.0f
, 0xFFFF0000, 0xFF000000 },
478 {-1, 1, 1.0f
, 0xFFFF0000, 0xFF000000 },
479 { 0, 1, 1.0f
, 0xFFFF0000, 0xFF000000 },
480 { 0, 0, 1.0f
, 0xFFFF0000, 0xFF000000 },
482 /* Untransformed ones. Give them a different diffuse color to make the test look
483 * nicer. It also makes making sure that they are drawn correctly easier.
485 struct sVertexT transformed_1
[] = {
486 {320, 0, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
487 {640, 0, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
488 {640, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
489 {320, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
491 struct sVertexT transformed_2
[] = {
492 {320, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
493 {640, 240, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
494 {640, 480, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
495 {320, 480, 1.0f
, 1.0f
, 0xFFFFFF00, 0xFF000000 },
497 WORD Indices
[] = {0, 1, 2, 2, 3, 0};
498 D3DMATRIX ident_mat
=
500 1.0f
, 0.0f
, 0.0f
, 0.0f
,
501 0.0f
, 1.0f
, 0.0f
, 0.0f
,
502 0.0f
, 0.0f
, 1.0f
, 0.0f
,
503 0.0f
, 0.0f
, 0.0f
, 1.0f
,
505 D3DMATRIX world_mat1
=
507 1.0f
, 0.0f
, 0.0f
, 0.0f
,
508 0.0f
, 1.0f
, 0.0f
, 0.0f
,
509 0.0f
, 0.0f
, 1.0f
, 0.0f
,
510 0.0f
, 0.0f
, -0.5f
, 1.0f
,
512 D3DMATRIX world_mat2
=
514 1.0f
, 0.0f
, 0.0f
, 0.0f
,
515 0.0f
, 1.0f
, 0.0f
, 0.0f
,
516 0.0f
, 0.0f
, 1.0f
, 0.0f
,
517 0.0f
, 0.0f
, 1.0f
, 1.0f
,
521 1.0f
, 0.0f
, 0.0f
, 0.0f
,
522 0.0f
, 1.0f
, 0.0f
, 0.0f
,
523 0.0f
, 0.0f
, 1.0f
, 0.0f
,
524 0.0f
, 0.0f
, -1.0f
, 1.0f
,
526 struct sVertex far_quad1
[] =
528 {-1.0f
, -1.0f
, 0.5f
, 0xffff0000, 0xff000000},
529 {-1.0f
, 0.0f
, 0.5f
, 0xffff0000, 0xff000000},
530 { 0.0f
, 0.0f
, 0.5f
, 0xffff0000, 0xff000000},
531 { 0.0f
, -1.0f
, 0.5f
, 0xffff0000, 0xff000000},
533 struct sVertex far_quad2
[] =
535 {-1.0f
, 0.0f
, 1.5f
, 0xffff0000, 0xff000000},
536 {-1.0f
, 1.0f
, 1.5f
, 0xffff0000, 0xff000000},
537 { 0.0f
, 1.0f
, 1.5f
, 0xffff0000, 0xff000000},
538 { 0.0f
, 0.0f
, 1.5f
, 0xffff0000, 0xff000000},
541 memset(&caps
, 0, sizeof(caps
));
542 hr
= IDirect3DDevice7_GetCaps(device
, &caps
);
543 ok(hr
== D3D_OK
, "IDirect3DDevice7_GetCaps returned %08x\n", hr
);
544 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
545 ok(hr
== D3D_OK
, "IDirect3DDevice7_Clear returned %08x\n", hr
);
547 /* Setup initial states: No lighting, fog on, fog color */
548 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
549 ok(hr
== D3D_OK
, "Turning off lighting returned %08x\n", hr
);
550 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, TRUE
);
551 ok(hr
== D3D_OK
, "Turning on fog calculations returned %08x\n", hr
);
552 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGCOLOR
, 0xFF00FF00 /* A nice green */);
553 ok(hr
== D3D_OK
, "Setting fog color returned %08x\n", hr
);
555 /* First test: Both table fog and vertex fog off */
556 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, D3DFOG_NONE
);
557 ok(hr
== D3D_OK
, "Turning off table fog returned %08x\n", hr
);
558 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGVERTEXMODE
, D3DFOG_NONE
);
559 ok(hr
== D3D_OK
, "Turning off vertex fog returned %08x\n", hr
);
561 /* Start = 0, end = 1. Should be default, but set them */
562 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGSTART
, *((DWORD
*) &start
));
563 ok(hr
== D3D_OK
, "Setting fog start returned %08x\n", hr
);
564 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGEND
, *((DWORD
*) &end
));
565 ok(hr
== D3D_OK
, "Setting fog end returned %08x\n", hr
);
567 if(IDirect3DDevice7_BeginScene(device
) == D3D_OK
)
569 /* Untransformed, vertex fog = NONE, table fog = NONE: Read the fog weighting from the specular color */
570 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
,
571 untransformed_1
, 4, Indices
, 6, 0);
572 ok(hr
== D3D_OK
, "DrawIndexedPrimitive returned %08x\n", hr
);
574 /* That makes it use the Z value */
575 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGVERTEXMODE
, D3DFOG_LINEAR
);
576 ok(hr
== D3D_OK
, "Setting fog vertex mode to D3DFOG_LINEAR returned %08x\n", hr
);
577 /* Untransformed, vertex fog != none (or table fog != none):
578 * Use the Z value as input into the equation
580 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
,
581 untransformed_2
, 4, Indices
, 6, 0);
582 ok(hr
== D3D_OK
, "DrawIndexedPrimitive returned %08x\n", hr
);
584 /* Transformed, vertex fog != NONE, pixel fog == NONE: Use specular color alpha component */
585 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
,
586 transformed_1
, 4, Indices
, 6, 0);
587 ok(hr
== D3D_OK
, "DrawIndexedPrimitive returned %08x\n", hr
);
589 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, D3DFOG_LINEAR
);
590 ok( hr
== D3D_OK
, "Setting fog table mode to D3DFOG_LINEAR returned %08x\n", hr
);
591 /* Transformed, table fog != none, vertex anything: Use Z value as input to the fog
594 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
,
595 transformed_2
, 4, Indices
, 6, 0);
596 ok(hr
== D3D_OK
, "DrawIndexedPrimitive returned %08x\n", hr
);
598 hr
= IDirect3DDevice7_EndScene(device
);
599 ok(hr
== D3D_OK
, "EndScene returned %08x\n", hr
);
603 ok(FALSE
, "BeginScene failed\n");
606 color
= getPixelColor(device
, 160, 360);
607 ok(color_match(color
, 0x00FF0000, 1), "Untransformed vertex with no table or vertex fog has color %08x\n", color
);
608 color
= getPixelColor(device
, 160, 120);
609 ok(color_match(color
, 0x0000FF00, 1), "Untransformed vertex with linear vertex fog has color %08x\n", color
);
610 color
= getPixelColor(device
, 480, 120);
611 ok(color_match(color
, 0x00FFFF00, 1), "Transformed vertex with linear vertex fog has color %08x\n", color
);
612 if(caps
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_FOGTABLE
)
614 color
= getPixelColor(device
, 480, 360);
615 ok(color_match(color
, 0x0000FF00, 1), "Transformed vertex with linear table fog has color %08x\n", color
);
619 /* Without fog table support the vertex fog is still applied, even though table fog is turned on.
620 * The settings above result in no fogging with vertex fog
622 color
= getPixelColor(device
, 480, 120);
623 ok(color
== 0x00FFFF00, "Transformed vertex with linear vertex fog has color %08x\n", color
);
624 trace("Info: Table fog not supported by this device\n");
627 if (caps
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_FOGTABLE
)
629 /* A simple fog + non-identity world matrix test */
630 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &world_mat1
);
631 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetTransform returned %#08x\n", hr
);
633 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, D3DFOG_LINEAR
);
634 ok(hr
== D3D_OK
, "Setting fog table mode to D3DFOG_LINEAR returned %#08x\n", hr
);
635 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGVERTEXMODE
, D3DFOG_NONE
);
636 ok(hr
== D3D_OK
, "Turning off vertex fog returned %#08x\n", hr
);
638 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
639 ok(hr
== D3D_OK
, "IDirect3DDevice7_Clear returned %#08x\n", hr
);
641 if (IDirect3DDevice7_BeginScene(device
) == D3D_OK
)
643 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
,
644 D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
, far_quad1
, 4, Indices
, 6, 0);
645 ok(hr
== D3D_OK
, "DrawIndexedPrimitive returned %#08x\n", hr
);
647 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
,
648 D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
, far_quad2
, 4, Indices
, 6, 0);
649 ok(hr
== D3D_OK
, "DrawIndexedPrimitive returned %#08x\n", hr
);
651 hr
= IDirect3DDevice7_EndScene(device
);
652 ok(hr
== D3D_OK
, "EndScene returned %#08x\n", hr
);
656 ok(FALSE
, "BeginScene failed\n");
659 color
= getPixelColor(device
, 160, 360);
660 ok(color_match(color
, 0x00ff0000, 4), "Unfogged quad has color %08x\n", color
);
661 color
= getPixelColor(device
, 160, 120);
662 ok(color_match(color
, 0x0000ff00, 1), "Fogged out quad has color %08x\n", color
);
664 /* Test fog behavior with an orthogonal (but not identity) projection matrix */
665 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &world_mat2
);
666 ok(hr
== D3D_OK
, "SetTransform returned %#08x\n", hr
);
667 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &proj_mat
);
668 ok(hr
== D3D_OK
, "SetTransform returned %#08x\n", hr
);
670 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
671 ok(hr
== D3D_OK
, "Clear returned %#08x\n", hr
);
673 if (IDirect3DDevice7_BeginScene(device
) == D3D_OK
)
675 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
,
676 D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
, untransformed_1
, 4, Indices
, 6, 0);
677 ok(hr
== D3D_OK
, "DrawIndexedPrimitiveUP returned %#08x\n", hr
);
679 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
,
680 D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
, untransformed_2
, 4, Indices
, 6, 0);
681 ok(hr
== D3D_OK
, "DrawIndexedPrimitiveUP returned %#08x\n", hr
);
683 hr
= IDirect3DDevice7_EndScene(device
);
684 ok(hr
== D3D_OK
, "EndScene returned %#08x\n", hr
);
688 ok(FALSE
, "BeginScene failed\n");
691 color
= getPixelColor(device
, 160, 360);
692 ok(color_match(color
, 0x00e51900, 4), "Partially fogged quad has color %08x\n", color
);
693 color
= getPixelColor(device
, 160, 120);
694 ok(color_match(color
, 0x0000ff00, 1), "Fogged out quad has color %08x\n", color
);
696 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &ident_mat
);
697 ok(hr
== D3D_OK
, "SetTransform returned %#08x\n", hr
);
698 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &ident_mat
);
699 ok(hr
== D3D_OK
, "SetTransform returned %#08x\n", hr
);
703 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests\n");
706 /* Turn off the fog master switch to avoid confusing other tests */
707 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
708 ok(hr
== D3D_OK
, "Turning off fog calculations returned %08x\n", hr
);
711 static void blt_test(IDirect3DDevice7
*device
)
713 IDirectDrawSurface7
*backbuffer
= NULL
, *offscreen
= NULL
;
717 memset(&ddsd
, 0, sizeof(ddsd
));
718 ddsd
.dwSize
= sizeof(ddsd
);
719 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
720 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
723 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_3DDEVICE
;
724 hr
= IDirectDraw7_CreateSurface(DirectDraw
, &ddsd
, &offscreen
, NULL
);
725 ok(hr
== D3D_OK
, "Creating the offscreen render target failed, hr = %08x\n", hr
);
727 /* Offscreen blits with the same source as destination */
730 RECT src_rect
, dst_rect
;
732 /* Blit the whole surface to itself */
733 hr
= IDirectDrawSurface_Blt(offscreen
, NULL
, offscreen
, NULL
, 0, NULL
);
734 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
736 /* Overlapped blit */
737 dst_rect
.left
= 0; dst_rect
.right
= 480;
738 dst_rect
.top
= 0; dst_rect
.bottom
= 480;
739 src_rect
.left
= 160; src_rect
.right
= 640;
740 src_rect
.top
= 0; src_rect
.bottom
= 480;
741 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, offscreen
, &src_rect
, 0, NULL
);
742 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
744 /* Overlapped blit, flip-y through source rectangle (not allowed) */
745 dst_rect
.left
= 0; dst_rect
.right
= 480;
746 dst_rect
.top
= 0; dst_rect
.bottom
= 480;
747 src_rect
.left
= 160; src_rect
.right
= 640;
748 src_rect
.top
= 480; src_rect
.bottom
= 0;
749 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, offscreen
, &src_rect
, 0, NULL
);
750 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
752 /* Overlapped blit, with shrinking in x */
753 dst_rect
.left
= 0; dst_rect
.right
= 480;
754 dst_rect
.top
= 0; dst_rect
.bottom
= 480;
755 src_rect
.left
= 160; src_rect
.right
= 480;
756 src_rect
.top
= 0; src_rect
.bottom
= 480;
757 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, offscreen
, &src_rect
, 0, NULL
);
758 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
761 hr
= IDirect3DDevice7_GetRenderTarget(device
, &backbuffer
);
762 ok(hr
== D3D_OK
, "Unable to obtain a surface pointer to the backbuffer, hr = %08x\n", hr
);
764 /* backbuffer ==> texture blits */
765 if(SUCCEEDED(hr
) && offscreen
)
767 RECT src_rect
, dst_rect
;
769 /* backbuffer ==> texture, src_rect=NULL, dst_rect=NULL, no scaling */
770 hr
= IDirectDrawSurface_Blt(offscreen
, NULL
, backbuffer
, NULL
, 0, NULL
);
771 ok(hr
== DD_OK
, "fullscreen Blt from backbuffer => texture failed with hr = %08x\n", hr
);
773 /* backbuffer ==> texture, full surface blits, no scaling */
774 dst_rect
.left
= 0; dst_rect
.right
= 640;
775 dst_rect
.top
= 0; dst_rect
.bottom
= 480;
776 src_rect
.left
= 0; src_rect
.right
= 640;
777 src_rect
.top
= 0; src_rect
.bottom
= 480;
778 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, backbuffer
, &src_rect
, 0, NULL
);
779 ok(hr
== DD_OK
, "fullscreen Blt from backbuffer => texture failed with hr = %08x\n", hr
);
781 /* backbuffer ==> texture, flip in y-direction through source rectangle, no scaling (allowed) */
782 dst_rect
.left
= 0; dst_rect
.right
= 640;
783 dst_rect
.top
= 480; dst_rect
.top
= 0;
784 src_rect
.left
= 0; src_rect
.right
= 640;
785 src_rect
.top
= 0; src_rect
.bottom
= 480;
786 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, backbuffer
, &src_rect
, 0, NULL
);
787 ok(hr
== DD_OK
, "backbuffer => texture flip-y src_rect failed with hr = %08x\n", hr
);
789 /* backbuffer ==> texture, flip in x-direction through source rectangle, no scaling (not allowed) */
790 dst_rect
.left
= 640; dst_rect
.right
= 0;
791 dst_rect
.top
= 0; dst_rect
.top
= 480;
792 src_rect
.left
= 0; src_rect
.right
= 640;
793 src_rect
.top
= 0; src_rect
.bottom
= 480;
794 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, backbuffer
, &src_rect
, 0, NULL
);
795 ok(hr
== DDERR_INVALIDRECT
, "backbuffer => texture flip-x src_rect failed with hr = %08x\n", hr
);
797 /* backbuffer ==> texture, flip in y-direction through destination rectangle (not allowed) */
798 dst_rect
.left
= 0; dst_rect
.right
= 640;
799 dst_rect
.top
= 0; dst_rect
.top
= 480;
800 src_rect
.left
= 0; src_rect
.right
= 640;
801 src_rect
.top
= 480; src_rect
.bottom
= 0;
802 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, backbuffer
, &src_rect
, 0, NULL
);
803 ok(hr
== DDERR_INVALIDRECT
, "backbuffer => texture flip-y dst_rect failed with hr = %08x\n", hr
);
805 /* backbuffer ==> texture, flip in x-direction through destination rectangle, no scaling (not allowed) */
806 dst_rect
.left
= 0; dst_rect
.right
= 640;
807 dst_rect
.top
= 0; dst_rect
.top
= 480;
808 src_rect
.left
= 640; src_rect
.right
= 0;
809 src_rect
.top
= 0; src_rect
.bottom
= 480;
810 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, backbuffer
, &src_rect
, 0, NULL
);
811 ok(hr
== DDERR_INVALIDRECT
, "backbuffer => texture flip-x dst_rect failed with hr = %08x\n", hr
);
814 if(offscreen
) IDirectDrawSurface7_Release(offscreen
);
815 if(backbuffer
) IDirectDrawSurface7_Release(backbuffer
);
818 static void offscreen_test(IDirect3DDevice7
*device
)
821 IDirectDrawSurface7
*backbuffer
= NULL
, *offscreen
= NULL
;
825 static float quad
[][5] = {
826 {-0.5f
, -0.5f
, 0.1f
, 0.0f
, 0.0f
},
827 {-0.5f
, 0.5f
, 0.1f
, 0.0f
, 1.0f
},
828 { 0.5f
, -0.5f
, 0.1f
, 1.0f
, 0.0f
},
829 { 0.5f
, 0.5f
, 0.1f
, 1.0f
, 1.0f
},
832 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
833 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
835 memset(&ddsd
, 0, sizeof(ddsd
));
836 ddsd
.dwSize
= sizeof(ddsd
);
837 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
838 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
841 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_3DDEVICE
;
842 hr
= IDirectDraw7_CreateSurface(DirectDraw
, &ddsd
, &offscreen
, NULL
);
843 ok(hr
== D3D_OK
, "Creating the offscreen render target failed, hr = %08x\n", hr
);
848 hr
= IDirect3DDevice7_GetRenderTarget(device
, &backbuffer
);
849 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %08x\n", hr
);
854 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
855 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
856 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
857 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
858 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_MINFILTER
, D3DFILTER_NEAREST
);
859 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MINFILTER failed (0x%08x)\n", hr
);
860 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_MAGFILTER
, D3DFILTER_NEAREST
);
861 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr
);
862 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
863 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned hr = %08x\n", hr
);
866 win_skip("Tests would crash on W2K with a refdevice\n");
870 if(IDirect3DDevice7_BeginScene(device
) == D3D_OK
) {
871 hr
= IDirect3DDevice7_SetRenderTarget(device
, offscreen
, 0);
872 ok(hr
== D3D_OK
, "SetRenderTarget failed, hr = %08x\n", hr
);
873 set_viewport_size(device
);
874 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
875 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
877 /* Draw without textures - Should result in a white quad */
878 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEX1
, quad
, 4, 0);
879 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
881 hr
= IDirect3DDevice7_SetRenderTarget(device
, backbuffer
, 0);
882 ok(hr
== D3D_OK
, "SetRenderTarget failed, hr = %08x\n", hr
);
883 set_viewport_size(device
);
885 hr
= IDirect3DDevice7_SetTexture(device
, 0, offscreen
);
886 ok(hr
== D3D_OK
, "SetTexture failed, %08x\n", hr
);
888 /* This time with the texture */
889 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEX1
, quad
, 4, 0);
890 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
892 IDirect3DDevice7_EndScene(device
);
895 /* Center quad - should be white */
896 color
= getPixelColor(device
, 320, 240);
897 ok(color
== 0x00ffffff, "Offscreen failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
898 /* Some quad in the cleared part of the texture */
899 color
= getPixelColor(device
, 170, 240);
900 ok(color
== 0x00ff00ff, "Offscreen failed: Got color 0x%08x, expected 0x00ff00ff.\n", color
);
901 /* Part of the originally cleared back buffer */
902 color
= getPixelColor(device
, 10, 10);
903 ok(color
== 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
905 /* Lower left corner of the screen, where back buffer offscreen rendering draws the offscreen texture.
906 * It should be red, but the offscreen texture may leave some junk there. Not tested yet. Depending on
907 * the offscreen rendering mode this test would succeed or fail
909 color
= getPixelColor(device
, 10, 470);
910 ok(color
== 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
914 hr
= IDirect3DDevice7_SetTexture(device
, 0, NULL
);
915 ok(SUCCEEDED(hr
), "IDirect3DDevice7_SetTexture returned %#x.\n", hr
);
919 hr
= IDirect3DDevice7_SetRenderTarget(device
, backbuffer
, 0);
920 ok(SUCCEEDED(hr
), "IDirect3DDevice7_SetRenderTarget returned %#x.\n", hr
);
921 IDirectDrawSurface7_Release(backbuffer
);
924 IDirectDrawSurface7_Release(offscreen
);
928 static void alpha_test(IDirect3DDevice7
*device
)
931 IDirectDrawSurface7
*backbuffer
= NULL
, *offscreen
= NULL
;
932 DWORD color
, red
, green
, blue
;
937 struct vec3 position
;
942 {{-1.0f
, -1.0f
, 0.1f
}, 0x4000ff00},
943 {{-1.0f
, 0.0f
, 0.1f
}, 0x4000ff00},
944 {{ 1.0f
, -1.0f
, 0.1f
}, 0x4000ff00},
945 {{ 1.0f
, 0.0f
, 0.1f
}, 0x4000ff00},
949 {{-1.0f
, 0.0f
, 0.1f
}, 0xc00000ff},
950 {{-1.0f
, 1.0f
, 0.1f
}, 0xc00000ff},
951 {{ 1.0f
, 0.0f
, 0.1f
}, 0xc00000ff},
952 {{ 1.0f
, 1.0f
, 0.1f
}, 0xc00000ff},
954 static float composite_quad
[][5] = {
955 { 0.0f
, -1.0f
, 0.1f
, 0.0f
, 1.0f
},
956 { 0.0f
, 1.0f
, 0.1f
, 0.0f
, 0.0f
},
957 { 1.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
},
958 { 1.0f
, 1.0f
, 0.1f
, 1.0f
, 0.0f
},
961 /* Clear the render target with alpha = 0.5 */
962 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x80ff0000, 0.0, 0);
963 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
965 memset(&ddsd
, 0, sizeof(ddsd
));
966 ddsd
.dwSize
= sizeof(ddsd
);
967 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
970 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_3DDEVICE
;
971 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
972 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
973 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
974 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
975 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
976 U5(U4(ddsd
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
977 hr
= IDirectDraw7_CreateSurface(DirectDraw
, &ddsd
, &offscreen
, NULL
);
978 ok(hr
== D3D_OK
, "Creating the offscreen render target failed, hr = %08x\n", hr
);
982 hr
= IDirect3DDevice7_GetRenderTarget(device
, &backbuffer
);
983 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %08x\n", hr
);
988 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
989 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
990 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
991 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
992 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_MINFILTER
, D3DFILTER_NEAREST
);
993 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MINFILTER failed (0x%08x)\n", hr
);
994 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_MAGFILTER
, D3DFILTER_NEAREST
);
995 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr
);
997 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
998 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1001 win_skip("Tests would crash on W2K with a refdevice\n");
1005 if(IDirect3DDevice7_BeginScene(device
) == D3D_OK
) {
1007 /* Draw two quads, one with src alpha blending, one with dest alpha blending. The
1008 * SRCALPHA / INVSRCALPHA blend doesn't give any surprises. Colors are blended based on
1011 * The DESTALPHA / INVDESTALPHA do not "work" on the regular buffer because there is no alpha.
1012 * They give essentially ZERO and ONE blend factors
1014 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
1015 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1016 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1017 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1018 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad1
, 4, 0);
1019 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
1021 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_DESTALPHA
);
1022 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1023 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVDESTALPHA
);
1024 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1025 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad2
, 4, 0);
1026 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
1028 /* Switch to the offscreen buffer, and redo the testing. SRCALPHA and DESTALPHA. The offscreen buffer
1029 * has an alpha channel on its own. Clear the offscreen buffer with alpha = 0.5 again, then draw the
1030 * quads again. The SRCALPHA/INVSRCALPHA doesn't give any surprises, but the DESTALPHA/INVDESTALPHA
1031 * blending works as supposed now - blend factor is 0.5 in both cases, not 0.75 as from the input
1034 hr
= IDirect3DDevice7_SetRenderTarget(device
, offscreen
, 0);
1035 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderTarget failed, hr = %08x\n", hr
);
1036 set_viewport_size(device
);
1037 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x80ff0000, 0.0, 0);
1038 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
1040 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
1041 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1042 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1043 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1044 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad1
, 4, 0);
1045 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
1047 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_DESTALPHA
);
1048 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1049 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVDESTALPHA
);
1050 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1051 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad2
, 4, 0);
1052 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
1054 hr
= IDirect3DDevice7_SetRenderTarget(device
, backbuffer
, 0);
1055 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderTarget failed, hr = %08x\n", hr
);
1056 set_viewport_size(device
);
1058 /* Render the offscreen texture onto the frame buffer to be able to compare it regularly.
1059 * Disable alpha blending for the final composition
1061 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
);
1062 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1064 hr
= IDirect3DDevice7_SetTexture(device
, 0, offscreen
);
1065 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetTexture failed, hr = %08x\n", hr
);
1066 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEX1
, composite_quad
, 4, 0);
1067 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
1068 hr
= IDirect3DDevice7_SetTexture(device
, 0, NULL
);
1069 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetTexture failed, hr = %08x\n", hr
);
1071 hr
= IDirect3DDevice7_EndScene(device
);
1072 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndScene failed, hr = %08x\n", hr
);
1075 color
= getPixelColor(device
, 160, 360);
1076 red
= (color
& 0x00ff0000) >> 16;
1077 green
= (color
& 0x0000ff00) >> 8;
1078 blue
= (color
& 0x000000ff);
1079 ok(red
>= 0xbe && red
<= 0xc0 && green
>= 0x39 && green
<= 0x41 && blue
== 0x00,
1080 "SRCALPHA on frame buffer returned color 0x%08x, expected 0x00bf4000\n", color
);
1082 color
= getPixelColor(device
, 160, 120);
1083 red
= (color
& 0x00ff0000) >> 16;
1084 green
= (color
& 0x0000ff00) >> 8;
1085 blue
= (color
& 0x000000ff);
1086 ok(red
== 0x00 && green
== 0x00 && blue
>= 0xfe && blue
<= 0xff ,
1087 "DSTALPHA on frame buffer returned color 0x%08x, expected 0x000000ff\n", color
);
1089 color
= getPixelColor(device
, 480, 360);
1090 red
= (color
& 0x00ff0000) >> 16;
1091 green
= (color
& 0x0000ff00) >> 8;
1092 blue
= (color
& 0x000000ff);
1093 ok(red
>= 0xbe && red
<= 0xc0 && green
>= 0x39 && green
<= 0x41 && blue
== 0x00,
1094 "SRCALPHA on texture returned color 0x%08x, expected 0x00bf4000\n", color
);
1096 color
= getPixelColor(device
, 480, 120);
1097 red
= (color
& 0x00ff0000) >> 16;
1098 green
= (color
& 0x0000ff00) >> 8;
1099 blue
= (color
& 0x000000ff);
1100 ok(red
>= 0x7e && red
<= 0x81 && green
== 0x00 && blue
>= 0x7e && blue
<= 0x81,
1101 "DSTALPHA on texture returned color 0x%08x, expected 0x00800080\n", color
);
1104 if(offscreen
) IDirectDrawSurface7_Release(offscreen
);
1105 if(backbuffer
) IDirectDrawSurface7_Release(backbuffer
);
1108 static void rhw_zero_test(IDirect3DDevice7
*device
)
1110 /* Test if it will render a quad correctly when vertex rhw = 0 */
1120 {0, 100, 0, 0, 0xffffffff},
1121 {0, 0, 0, 0, 0xffffffff},
1122 {100, 100, 0, 0, 0xffffffff},
1123 {100, 0, 0, 0, 0xffffffff},
1126 /* Clear to black */
1127 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0, 0.0, 0);
1128 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
1130 hr
= IDirect3DDevice7_BeginScene(device
);
1131 ok(hr
== D3D_OK
, "IDirect3DDevice7_BeginScene failed with %08x\n", hr
);
1133 if (SUCCEEDED(hr
)) {
1134 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, quad1
, 4, 0);
1135 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
1137 hr
= IDirect3DDevice7_EndScene(device
);
1138 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndScene failed, hr = %08x\n", hr
);
1141 color
= getPixelColor(device
, 5, 5);
1142 ok(color
== 0xffffff ||
1143 broken(color
== 0), /* VMware */
1144 "Got color %08x, expected 00ffffff\n", color
);
1146 color
= getPixelColor(device
, 105, 105);
1147 ok(color
== 0, "Got color %08x, expected 00000000\n", color
);
1150 static BOOL
D3D1_createObjects(void)
1155 D3DEXECUTEBUFFERDESC exdesc
;
1156 D3DVIEWPORT vp_data
;
1158 /* An IDirect3DDevice cannot be queryInterfaced from an IDirect3DDevice7 on windows */
1159 hr
= DirectDrawCreate(NULL
, &DirectDraw1
, NULL
);
1161 ok(hr
==DD_OK
|| hr
==DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreate returned: %x\n", hr
);
1166 wc
.lpfnWndProc
= DefWindowProcA
;
1167 wc
.lpszClassName
= "texturemapblend_test_wc";
1168 RegisterClassA(&wc
);
1169 window
= CreateWindowA("texturemapblend_test_wc", "texturemapblend_test",
1170 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
1172 hr
= IDirectDraw_SetCooperativeLevel(DirectDraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1173 ok(hr
==DD_OK
, "SetCooperativeLevel returned: %x\n", hr
);
1178 hr
= IDirectDraw_SetDisplayMode(DirectDraw1
, 640, 480, 32);
1180 /* 24 bit is fine too */
1181 hr
= IDirectDraw_SetDisplayMode(DirectDraw1
, 640, 480, 24);
1183 ok(hr
==DD_OK
|| hr
== DDERR_UNSUPPORTED
, "SetDisplayMode returned: %x\n", hr
);
1188 hr
= IDirectDraw_QueryInterface(DirectDraw1
, &IID_IDirect3D
, (void**) &Direct3D1
);
1189 ok(hr
==DD_OK
, "QueryInterface returned: %x\n", hr
);
1194 memset(&ddsd
, 0, sizeof(ddsd
));
1195 ddsd
.dwSize
= sizeof(ddsd
);
1196 ddsd
.dwFlags
= DDSD_CAPS
;
1197 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
;
1198 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &Surface1
, NULL
);
1199 ok(hr
==DD_OK
, "CreateSurface returned: %x\n", hr
);
1204 hr
= IDirectDrawSurface_QueryInterface(Surface1
, &IID_IDirect3DHALDevice
, (void **) &Direct3DDevice1
);
1206 trace("Creating a HAL device failed, trying Ref\n");
1207 hr
= IDirectDrawSurface_QueryInterface(Surface1
, &IID_IDirect3DRefDevice
, (void **) &Direct3DDevice1
);
1209 ok(hr
==D3D_OK
, "Creating 3D device returned: %x\n", hr
);
1214 hr
= IDirect3D_CreateViewport(Direct3D1
, &Viewport
, NULL
);
1215 ok(hr
== D3D_OK
, "IDirect3D_CreateViewport failed: %08x\n", hr
);
1220 hr
= IDirect3DViewport_Initialize(Viewport
, Direct3D1
);
1221 ok(hr
== D3D_OK
|| hr
== DDERR_ALREADYINITIALIZED
, "IDirect3DViewport_Initialize returned %08x\n", hr
);
1222 hr
= IDirect3DDevice_AddViewport(Direct3DDevice1
, Viewport
);
1223 ok(hr
== D3D_OK
, "IDirect3DDevice_AddViewport returned %08x\n", hr
);
1224 vp_data
.dwSize
= sizeof(vp_data
);
1227 vp_data
.dwWidth
= 640;
1228 vp_data
.dwHeight
= 480;
1229 vp_data
.dvScaleX
= 1;
1230 vp_data
.dvScaleY
= 1;
1231 vp_data
.dvMaxX
= 640;
1232 vp_data
.dvMaxY
= 480;
1235 hr
= IDirect3DViewport_SetViewport(Viewport
, &vp_data
);
1236 ok(hr
== D3D_OK
, "IDirect3DViewport_SetViewport returned %08x\n", hr
);
1238 memset(&exdesc
, 0, sizeof(D3DEXECUTEBUFFERDESC
));
1239 exdesc
.dwSize
= sizeof(D3DEXECUTEBUFFERDESC
);
1240 exdesc
.dwFlags
= D3DDEB_BUFSIZE
| D3DDEB_CAPS
;
1241 exdesc
.dwBufferSize
= 512;
1242 exdesc
.dwCaps
= D3DDEBCAPS_SYSTEMMEMORY
;
1243 hr
= IDirect3DDevice_CreateExecuteBuffer(Direct3DDevice1
, &exdesc
, &ExecuteBuffer
, NULL
);
1244 ok(hr
== D3D_OK
, "IDirect3DDevice_CreateExecuteBuffer failed with %08x\n", hr
);
1252 static void D3D1_releaseObjects(void)
1254 if(ExecuteBuffer
) IDirect3DExecuteBuffer_Release(ExecuteBuffer
);
1255 if(Surface1
) IDirectDrawSurface_Release(Surface1
);
1256 if(Viewport
) IDirect3DViewport_Release(Viewport
);
1257 if(Direct3DDevice1
) IDirect3DDevice_Release(Direct3DDevice1
);
1258 if(Direct3D1
) IDirect3D_Release(Direct3D1
);
1259 if(DirectDraw1
) IDirectDraw_Release(DirectDraw1
);
1260 if(window
) DestroyWindow(window
);
1263 static DWORD
D3D1_getPixelColor(IDirectDraw
*DirectDraw1
, IDirectDrawSurface
*Surface
, UINT x
, UINT y
)
1268 RECT rectToLock
= {x
, y
, x
+1, y
+1};
1269 IDirectDrawSurface
*surf
= NULL
;
1271 /* Some implementations seem to dislike direct locking on the front buffer. Thus copy the front buffer
1272 * to an offscreen surface and lock it instead of the front buffer
1274 memset(&ddsd
, 0, sizeof(ddsd
));
1275 ddsd
.dwSize
= sizeof(ddsd
);
1276 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
1277 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
1279 ddsd
.dwHeight
= 480;
1280 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
;
1281 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &surf
, NULL
);
1282 ok(hr
== DD_OK
, "IDirectDraw_CreateSurface failed with %08x\n", hr
);
1285 trace("cannot create helper surface\n");
1289 memset(&ddsd
, 0, sizeof(ddsd
));
1290 ddsd
.dwSize
= sizeof(ddsd
);
1291 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
1293 hr
= IDirectDrawSurface_BltFast(surf
, 0, 0, Surface
, NULL
, 0);
1294 ok(hr
== DD_OK
, "IDirectDrawSurface_BltFast returned %08x\n", hr
);
1297 trace("Cannot blit\n");
1302 hr
= IDirectDrawSurface_Lock(surf
, &rectToLock
, &ddsd
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
1305 trace("Can't lock the offscreen surface, hr=%08x\n", hr
);
1310 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
1311 * really important for these tests
1313 ret
= ((DWORD
*) ddsd
.lpSurface
)[0] & 0x00ffffff;
1314 hr
= IDirectDrawSurface_Unlock(surf
, NULL
);
1317 trace("Can't unlock the offscreen surface, hr=%08x\n", hr
);
1321 IDirectDrawSurface_Release(surf
);
1325 #define EXEBUF_START_RENDER_STATES(count, ptr) do {\
1326 ((D3DINSTRUCTION*)(ptr))->bOpcode = D3DOP_STATERENDER;\
1327 ((D3DINSTRUCTION*)(ptr))->bSize = sizeof(D3DSTATE);\
1328 ((D3DINSTRUCTION*)(ptr))->wCount = count;\
1329 ptr = ((D3DINSTRUCTION*)(ptr))+1; } while (0)
1331 #define EXEBUF_PUT_RENDER_STATE(state, value, ptr) do {\
1332 U1(*((D3DSTATE*)(ptr))).drstRenderStateType = state; \
1333 U2(*((D3DSTATE*)(ptr))).dwArg[0] = value; \
1334 ptr = ((D3DSTATE*)(ptr))+1; } while (0)
1336 #define EXEBUF_PUT_PROCESSVERTICES(nvertices, ptr) do {\
1337 ((D3DINSTRUCTION*)(ptr))->bOpcode = D3DOP_PROCESSVERTICES;\
1338 ((D3DINSTRUCTION*)(ptr))->bSize = sizeof(D3DPROCESSVERTICES);\
1339 ((D3DINSTRUCTION*)(ptr))->wCount = 1;\
1340 ptr = ((D3DINSTRUCTION*)(ptr))+1;\
1341 ((D3DPROCESSVERTICES*)(ptr))->dwFlags = D3DPROCESSVERTICES_COPY;\
1342 ((D3DPROCESSVERTICES*)(ptr))->wStart = 0;\
1343 ((D3DPROCESSVERTICES*)(ptr))->wDest = 0;\
1344 ((D3DPROCESSVERTICES*)(ptr))->dwCount = nvertices;\
1345 ((D3DPROCESSVERTICES*)(ptr))->dwReserved = 0;\
1346 ptr = ((D3DPROCESSVERTICES*)(ptr))+1; } while (0)
1348 #define EXEBUF_END(ptr) do {\
1349 ((D3DINSTRUCTION*)(ptr))->bOpcode = D3DOP_EXIT;\
1350 ((D3DINSTRUCTION*)(ptr))->bSize = 0;\
1351 ((D3DINSTRUCTION*)(ptr))->wCount = 0;\
1352 ptr = ((D3DINSTRUCTION*)(ptr))+1; } while (0)
1354 #define EXEBUF_PUT_QUAD(base_idx, ptr) do {\
1355 ((D3DINSTRUCTION*)(ptr))->bOpcode = D3DOP_TRIANGLE;\
1356 ((D3DINSTRUCTION*)(ptr))->bSize = sizeof(D3DTRIANGLE);\
1357 ((D3DINSTRUCTION*)(ptr))->wCount = 2;\
1358 ptr = ((D3DINSTRUCTION*)(ptr))+1;\
1359 U1(*((D3DTRIANGLE*)(ptr))).v1 = base_idx;\
1360 U2(*((D3DTRIANGLE*)(ptr))).v2 = (base_idx) + 1; \
1361 U3(*((D3DTRIANGLE*)(ptr))).v3 = (base_idx) + 3; \
1362 ((D3DTRIANGLE*)(ptr))->wFlags = 0;\
1363 ptr = ((D3DTRIANGLE*)ptr)+1;\
1364 U1(*((D3DTRIANGLE*)(ptr))).v1 = (base_idx) + 1; \
1365 U2(*((D3DTRIANGLE*)(ptr))).v2 = (base_idx) + 2; \
1366 U3(*((D3DTRIANGLE*)(ptr))).v3 = (base_idx) + 3; \
1367 ((D3DTRIANGLE*)(ptr))->wFlags = 0;\
1368 ptr = ((D3DTRIANGLE*)(ptr))+1;\
1371 static HRESULT CALLBACK
TextureFormatEnumCallback(DDSURFACEDESC
*lpDDSD
, void *lpContext
)
1373 if (lpDDSD
->ddpfPixelFormat
.dwFlags
& DDPF_PALETTEINDEXED8
) {
1374 *(BOOL
*)lpContext
= TRUE
;
1377 return DDENUMRET_OK
;
1380 static void D3D1_TextureMapBlendTest(void)
1384 D3DEXECUTEBUFFERDESC exdesc
;
1385 D3DEXECUTEDATA exdata
;
1387 RECT rect
= { 0, 0, 64, 128 };
1388 DWORD color
, red
, blue
, green
;
1389 void *exe_buffer_ptr
;
1391 D3DTEXTUREHANDLE htex
;
1393 IDirectDrawSurface
*TexSurface
= NULL
;
1394 IDirect3DTexture
*Texture
= NULL
;
1395 IDirectDrawPalette
*Palette
= NULL
;
1396 PALETTEENTRY table1
[256];
1397 BOOL p8_textures_supported
= FALSE
;
1407 {0.0f
, 0.0f
, 0.0f
, 1.0f
, 0xffffffff, 0, 0.0f
, 0.0f
},
1408 {640.0f
, 0.0f
, 0.0f
, 1.0f
, 0xffffffff, 0, 1.0f
, 0.0f
},
1409 {640.0f
, 240.0f
, 0.0f
, 1.0f
, 0xffffffff, 0, 1.0f
, 1.0f
},
1410 {0.0f
, 240.0f
, 0.0f
, 1.0f
, 0xffffffff, 0, 0.0f
, 1.0f
},
1411 {0.0f
, 240.0f
, 0.0f
, 1.0f
, 0x80ffffff, 0, 0.0f
, 0.0f
},
1412 {640.0f
, 240.0f
, 0.0f
, 1.0f
, 0x80ffffff, 0, 1.0f
, 0.0f
},
1413 {640.0f
, 480.0f
, 0.0f
, 1.0f
, 0x80ffffff, 0, 1.0f
, 1.0f
},
1414 {0.0f
, 480.0f
, 0.0f
, 1.0f
, 0x80ffffff, 0, 0.0f
, 1.0f
}
1417 {0.0f
, 0.0f
, 0.0f
, 1.0f
, 0x00ff0080, 0, 0.0f
, 0.0f
},
1418 {640.0f
, 0.0f
, 0.0f
, 1.0f
, 0x00ff0080, 0, 1.0f
, 0.0f
},
1419 {640.0f
, 240.0f
, 0.0f
, 1.0f
, 0x00ff0080, 0, 1.0f
, 1.0f
},
1420 {0.0f
, 240.0f
, 0.0f
, 1.0f
, 0x00ff0080, 0, 0.0f
, 1.0f
},
1421 {0.0f
, 240.0f
, 0.0f
, 1.0f
, 0x008000ff, 0, 0.0f
, 0.0f
},
1422 {640.0f
, 240.0f
, 0.0f
, 1.0f
, 0x008000ff, 0, 1.0f
, 0.0f
},
1423 {640.0f
, 480.0f
, 0.0f
, 1.0f
, 0x008000ff, 0, 1.0f
, 1.0f
},
1424 {0.0f
, 480.0f
, 0.0f
, 1.0f
, 0x008000ff, 0, 0.0f
, 1.0f
}
1427 /* 1) Test alpha with DDPF_ALPHAPIXELS texture - should be taken from texture alpha channel*/
1428 memset (&ddsd
, 0, sizeof (ddsd
));
1429 ddsd
.dwSize
= sizeof (ddsd
);
1430 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
1431 ddsd
.dwHeight
= 128;
1433 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1434 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
1435 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
1436 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1437 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1438 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1439 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1440 U5(ddsd
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
1441 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &TexSurface
, NULL
);
1442 ok(hr
==D3D_OK
, "CreateSurface returned: %x\n", hr
);
1444 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1448 hr
= IDirectDrawSurface_QueryInterface(TexSurface
, &IID_IDirect3DTexture
,
1450 ok(hr
==D3D_OK
, "IDirectDrawSurface_QueryInterface returned: %x\n", hr
);
1452 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1456 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
1457 ddbltfx
.dwSize
= sizeof(ddbltfx
);
1458 U5(ddbltfx
).dwFillColor
= 0;
1459 hr
= IDirectDrawSurface_Blt(Surface1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1460 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1462 U5(ddbltfx
).dwFillColor
= 0xff0000ff;
1463 hr
= IDirectDrawSurface_Blt(TexSurface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1464 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1465 U5(ddbltfx
).dwFillColor
= 0x800000ff;
1466 hr
= IDirectDrawSurface_Blt(TexSurface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1467 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1469 memset(&exdesc
, 0, sizeof(D3DEXECUTEBUFFERDESC
));
1470 exdesc
.dwSize
= sizeof(D3DEXECUTEBUFFERDESC
);
1471 hr
= IDirect3DExecuteBuffer_Lock(ExecuteBuffer
, &exdesc
);
1472 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr
);
1474 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1478 memcpy(exdesc
.lpData
, test1_quads
, sizeof(test1_quads
));
1480 exe_buffer_ptr
= sizeof(test1_quads
) + (char*)exdesc
.lpData
;
1482 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr
);
1484 EXEBUF_START_RENDER_STATES(12, exe_buffer_ptr
);
1485 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
, exe_buffer_ptr
);
1486 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ZENABLE
, FALSE
, exe_buffer_ptr
);
1487 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_FOGENABLE
, FALSE
, exe_buffer_ptr
);
1488 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_SPECULARENABLE
, FALSE
, exe_buffer_ptr
);
1489 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREMAG
, D3DFILTER_NEAREST
, exe_buffer_ptr
);
1490 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREMIN
, D3DFILTER_NEAREST
, exe_buffer_ptr
);
1491 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_FILLMODE
, D3DFILL_SOLID
, exe_buffer_ptr
);
1492 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
, exe_buffer_ptr
);
1493 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
, exe_buffer_ptr
);
1494 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
, exe_buffer_ptr
);
1495 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREMAPBLEND
, D3DTBLEND_MODULATE
, exe_buffer_ptr
);
1496 hr
= IDirect3DTexture_GetHandle(Texture
, Direct3DDevice1
, &htex
);
1497 ok(hr
== D3D_OK
, "IDirect3DTexture_GetHandle failed with %08x\n", hr
);
1498 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE
, htex
, exe_buffer_ptr
);
1500 EXEBUF_PUT_QUAD(0, exe_buffer_ptr
);
1501 EXEBUF_PUT_QUAD(4, exe_buffer_ptr
);
1503 EXEBUF_END(exe_buffer_ptr
);
1505 exe_length
= ((char*)exe_buffer_ptr
- (char*)exdesc
.lpData
) - sizeof(test1_quads
);
1507 hr
= IDirect3DExecuteBuffer_Unlock(ExecuteBuffer
);
1509 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr
);
1512 memset(&exdata
, 0, sizeof(exdata
));
1513 exdata
.dwSize
= sizeof(exdata
);
1514 exdata
.dwVertexCount
= 8;
1515 exdata
.dwInstructionOffset
= sizeof(test1_quads
);
1516 exdata
.dwInstructionLength
= exe_length
;
1517 hr
= IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer
, &exdata
);
1518 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr
);
1520 hr
= IDirect3DDevice_BeginScene(Direct3DDevice1
);
1521 ok(hr
== D3D_OK
, "IDirect3DDevice_BeginScene failed with %08x\n", hr
);
1523 if (SUCCEEDED(hr
)) {
1524 hr
= IDirect3DDevice_Execute(Direct3DDevice1
, ExecuteBuffer
, Viewport
, D3DEXECUTE_UNCLIPPED
);
1525 ok(hr
== D3D_OK
, "IDirect3DDevice_Execute failed, hr = %08x\n", hr
);
1526 hr
= IDirect3DDevice_EndScene(Direct3DDevice1
);
1527 ok(hr
== D3D_OK
, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr
);
1530 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 5);
1531 red
= (color
& 0x00ff0000) >> 16;
1532 green
= (color
& 0x0000ff00) >> 8;
1533 blue
= (color
& 0x000000ff);
1534 ok(red
== 0 && green
== 0 && blue
>= 0x7e && blue
<= 0x82, "Got color %08x, expected 00000080 or near\n", color
);
1536 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 5);
1537 red
= (color
& 0x00ff0000) >> 16;
1538 green
= (color
& 0x0000ff00) >> 8;
1539 blue
= (color
& 0x000000ff);
1540 ok(red
== 0 && green
== 0 && blue
== 0xff, "Got color %08x, expected 000000ff or near\n", color
);
1542 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 245);
1543 red
= (color
& 0x00ff0000) >> 16;
1544 green
= (color
& 0x0000ff00) >> 8;
1545 blue
= (color
& 0x000000ff);
1546 ok(red
== 0 && green
== 0 && blue
>= 0x7e && blue
<= 0x82, "Got color %08x, expected 00000080 or near\n", color
);
1548 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 245);
1549 red
= (color
& 0x00ff0000) >> 16;
1550 green
= (color
& 0x0000ff00) >> 8;
1551 blue
= (color
& 0x000000ff);
1552 ok(red
== 0 && green
== 0 && blue
== 0xff, "Got color %08x, expected 000000ff or near\n", color
);
1554 /* 2) Test alpha with texture that has no alpha channel - alpha should be taken from diffuse color */
1555 if(Texture
) IDirect3DTexture_Release(Texture
);
1557 if(TexSurface
) IDirectDrawSurface_Release(TexSurface
);
1560 memset (&ddsd
, 0, sizeof (ddsd
));
1561 ddsd
.dwSize
= sizeof (ddsd
);
1562 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
1563 ddsd
.dwHeight
= 128;
1565 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1566 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
1567 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1568 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1569 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1570 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1571 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1573 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &TexSurface
, NULL
);
1574 ok(hr
==D3D_OK
, "CreateSurface returned: %x\n", hr
);
1576 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1580 hr
= IDirectDrawSurface_QueryInterface(TexSurface
, &IID_IDirect3DTexture
,
1582 ok(hr
==D3D_OK
, "IDirectDrawSurface_QueryInterface returned: %x\n", hr
);
1584 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1588 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
1589 ddbltfx
.dwSize
= sizeof(ddbltfx
);
1590 U5(ddbltfx
).dwFillColor
= 0;
1591 hr
= IDirectDrawSurface_Blt(Surface1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1592 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1594 U5(ddbltfx
).dwFillColor
= 0xff0000ff;
1595 hr
= IDirectDrawSurface_Blt(TexSurface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1596 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1597 U5(ddbltfx
).dwFillColor
= 0x800000ff;
1598 hr
= IDirectDrawSurface_Blt(TexSurface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1599 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1601 memset(&exdesc
, 0, sizeof(D3DEXECUTEBUFFERDESC
));
1602 exdesc
.dwSize
= sizeof(D3DEXECUTEBUFFERDESC
);
1603 hr
= IDirect3DExecuteBuffer_Lock(ExecuteBuffer
, &exdesc
);
1604 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr
);
1606 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1610 memcpy(exdesc
.lpData
, test1_quads
, sizeof(test1_quads
));
1612 exe_buffer_ptr
= sizeof(test1_quads
) + (char*)exdesc
.lpData
;
1614 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr
);
1616 EXEBUF_START_RENDER_STATES(1, exe_buffer_ptr
);
1617 hr
= IDirect3DTexture_GetHandle(Texture
, Direct3DDevice1
, &htex
);
1618 ok(hr
== D3D_OK
, "IDirect3DTexture_GetHandle failed with %08x\n", hr
);
1619 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE
, htex
, exe_buffer_ptr
);
1621 EXEBUF_PUT_QUAD(0, exe_buffer_ptr
);
1622 EXEBUF_PUT_QUAD(4, exe_buffer_ptr
);
1624 EXEBUF_END(exe_buffer_ptr
);
1626 exe_length
= ((char*)exe_buffer_ptr
- (char*)exdesc
.lpData
) - sizeof(test1_quads
);
1628 hr
= IDirect3DExecuteBuffer_Unlock(ExecuteBuffer
);
1630 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr
);
1633 memset(&exdata
, 0, sizeof(exdata
));
1634 exdata
.dwSize
= sizeof(exdata
);
1635 exdata
.dwVertexCount
= 8;
1636 exdata
.dwInstructionOffset
= sizeof(test1_quads
);
1637 exdata
.dwInstructionLength
= exe_length
;
1638 hr
= IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer
, &exdata
);
1639 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr
);
1641 hr
= IDirect3DDevice_BeginScene(Direct3DDevice1
);
1642 ok(hr
== D3D_OK
, "IDirect3DDevice_BeginScene failed with %08x\n", hr
);
1644 if (SUCCEEDED(hr
)) {
1645 hr
= IDirect3DDevice_Execute(Direct3DDevice1
, ExecuteBuffer
, Viewport
, D3DEXECUTE_UNCLIPPED
);
1646 ok(hr
== D3D_OK
, "IDirect3DDevice_Execute failed, hr = %08x\n", hr
);
1647 hr
= IDirect3DDevice_EndScene(Direct3DDevice1
);
1648 ok(hr
== D3D_OK
, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr
);
1651 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 5);
1652 red
= (color
& 0x00ff0000) >> 16;
1653 green
= (color
& 0x0000ff00) >> 8;
1654 blue
= (color
& 0x000000ff);
1655 ok(red
== 0 && green
== 0 && blue
== 0xff, "Got color %08x, expected 000000ff or near\n", color
);
1657 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 5);
1658 red
= (color
& 0x00ff0000) >> 16;
1659 green
= (color
& 0x0000ff00) >> 8;
1660 blue
= (color
& 0x000000ff);
1661 ok(red
== 0 && green
== 0 && blue
== 0xff, "Got color %08x, expected 000000ff or near\n", color
);
1663 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 245);
1664 red
= (color
& 0x00ff0000) >> 16;
1665 green
= (color
& 0x0000ff00) >> 8;
1666 blue
= (color
& 0x000000ff);
1667 ok(red
== 0 && green
== 0 && blue
>= 0x7e && blue
<= 0x82, "Got color %08x, expected 00000080 or near\n", color
);
1669 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 245);
1670 red
= (color
& 0x00ff0000) >> 16;
1671 green
= (color
& 0x0000ff00) >> 8;
1672 blue
= (color
& 0x000000ff);
1673 ok(red
== 0 && green
== 0 && blue
>= 0x7e && blue
<= 0x82, "Got color %08x, expected 00000080 or near\n", color
);
1675 /* 3) Test RGB - should multiply color components from diffuse color and texture */
1676 if(Texture
) IDirect3DTexture_Release(Texture
);
1678 if(TexSurface
) IDirectDrawSurface_Release(TexSurface
);
1681 memset (&ddsd
, 0, sizeof (ddsd
));
1682 ddsd
.dwSize
= sizeof (ddsd
);
1683 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
1684 ddsd
.dwHeight
= 128;
1686 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1687 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
1688 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
1689 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1690 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1691 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1692 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1693 U5(ddsd
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
1694 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &TexSurface
, NULL
);
1695 ok(hr
==D3D_OK
, "CreateSurface returned: %x\n", hr
);
1697 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1701 hr
= IDirectDrawSurface_QueryInterface(TexSurface
, &IID_IDirect3DTexture
,
1703 ok(hr
==D3D_OK
, "IDirectDrawSurface_QueryInterface returned: %x\n", hr
);
1705 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1709 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
1710 ddbltfx
.dwSize
= sizeof(ddbltfx
);
1711 U5(ddbltfx
).dwFillColor
= 0;
1712 hr
= IDirectDrawSurface_Blt(Surface1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1713 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1715 U5(ddbltfx
).dwFillColor
= 0x00ffffff;
1716 hr
= IDirectDrawSurface_Blt(TexSurface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1717 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1718 U5(ddbltfx
).dwFillColor
= 0x00ffff80;
1719 hr
= IDirectDrawSurface_Blt(TexSurface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1720 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1722 memset(&exdesc
, 0, sizeof(D3DEXECUTEBUFFERDESC
));
1723 exdesc
.dwSize
= sizeof(D3DEXECUTEBUFFERDESC
);
1724 hr
= IDirect3DExecuteBuffer_Lock(ExecuteBuffer
, &exdesc
);
1725 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr
);
1727 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1731 memcpy(exdesc
.lpData
, test2_quads
, sizeof(test2_quads
));
1733 exe_buffer_ptr
= sizeof(test2_quads
) + (char*)exdesc
.lpData
;
1735 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr
);
1737 EXEBUF_START_RENDER_STATES(2, exe_buffer_ptr
);
1738 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
, exe_buffer_ptr
);
1739 hr
= IDirect3DTexture_GetHandle(Texture
, Direct3DDevice1
, &htex
);
1740 ok(hr
== D3D_OK
, "IDirect3DTexture_GetHandle failed with %08x\n", hr
);
1741 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE
, htex
, exe_buffer_ptr
);
1743 EXEBUF_PUT_QUAD(0, exe_buffer_ptr
);
1744 EXEBUF_PUT_QUAD(4, exe_buffer_ptr
);
1746 EXEBUF_END(exe_buffer_ptr
);
1748 exe_length
= ((char*)exe_buffer_ptr
- (char*)exdesc
.lpData
) - sizeof(test2_quads
);
1750 hr
= IDirect3DExecuteBuffer_Unlock(ExecuteBuffer
);
1752 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr
);
1755 memset(&exdata
, 0, sizeof(exdata
));
1756 exdata
.dwSize
= sizeof(exdata
);
1757 exdata
.dwVertexCount
= 8;
1758 exdata
.dwInstructionOffset
= sizeof(test2_quads
);
1759 exdata
.dwInstructionLength
= exe_length
;
1760 hr
= IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer
, &exdata
);
1761 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr
);
1763 hr
= IDirect3DDevice_BeginScene(Direct3DDevice1
);
1764 ok(hr
== D3D_OK
, "IDirect3DDevice_BeginScene failed with %08x\n", hr
);
1766 if (SUCCEEDED(hr
)) {
1767 hr
= IDirect3DDevice_Execute(Direct3DDevice1
, ExecuteBuffer
, Viewport
, D3DEXECUTE_UNCLIPPED
);
1768 ok(hr
== D3D_OK
, "IDirect3DDevice_Execute failed, hr = %08x\n", hr
);
1769 hr
= IDirect3DDevice_EndScene(Direct3DDevice1
);
1770 ok(hr
== D3D_OK
, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr
);
1773 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 5);
1774 red
= (color
& 0x00ff0000) >> 16;
1775 green
= (color
& 0x0000ff00) >> 8;
1776 blue
= (color
& 0x000000ff);
1777 ok(red
== 0xff && green
== 0 && blue
>= 0x3e && blue
<= 0x42, "Got color %08x, expected 00ff0040 or near\n", color
);
1779 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 5);
1780 red
= (color
& 0x00ff0000) >> 16;
1781 green
= (color
& 0x0000ff00) >> 8;
1782 blue
= (color
& 0x000000ff);
1783 ok(red
== 0xff && green
== 0 && blue
== 0x80, "Got color %08x, expected 00ff0080 or near\n", color
);
1785 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 245);
1786 red
= (color
& 0x00ff0000) >> 16;
1787 green
= (color
& 0x0000ff00) >> 8;
1788 blue
= (color
& 0x000000ff);
1789 ok(red
>= 0x7e && red
<= 0x82 && green
== 0 && blue
== 0x80, "Got color %08x, expected 00800080 or near\n", color
);
1791 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 245);
1792 red
= (color
& 0x00ff0000) >> 16;
1793 green
= (color
& 0x0000ff00) >> 8;
1794 blue
= (color
& 0x000000ff);
1795 ok(red
>= 0x7e && red
<= 0x82 && green
== 0 && blue
== 0xff, "Got color %08x, expected 008000ff or near\n", color
);
1797 /* 4) Test alpha again, now with color keyed texture (colorkey emulation in wine can interfere) */
1798 if(Texture
) IDirect3DTexture_Release(Texture
);
1800 if(TexSurface
) IDirectDrawSurface_Release(TexSurface
);
1803 memset (&ddsd
, 0, sizeof (ddsd
));
1804 ddsd
.dwSize
= sizeof (ddsd
);
1805 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
1806 ddsd
.dwHeight
= 128;
1808 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1809 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
1810 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1811 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 16;
1812 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0xf800;
1813 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x07e0;
1814 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x001f;
1816 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &TexSurface
, NULL
);
1817 ok(hr
==D3D_OK
, "CreateSurface returned: %x\n", hr
);
1819 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1823 hr
= IDirectDrawSurface_QueryInterface(TexSurface
, &IID_IDirect3DTexture
,
1825 ok(hr
==D3D_OK
, "IDirectDrawSurface_QueryInterface returned: %x\n", hr
);
1827 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1831 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
1832 ddbltfx
.dwSize
= sizeof(ddbltfx
);
1833 U5(ddbltfx
).dwFillColor
= 0;
1834 hr
= IDirectDrawSurface_Blt(Surface1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1835 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1836 U5(ddbltfx
).dwFillColor
= 0xf800;
1837 hr
= IDirectDrawSurface_Blt(TexSurface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1838 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1839 U5(ddbltfx
).dwFillColor
= 0x001f;
1840 hr
= IDirectDrawSurface_Blt(TexSurface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1841 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1843 clrKey
.dwColorSpaceLowValue
= 0x001f;
1844 clrKey
.dwColorSpaceHighValue
= 0x001f;
1845 hr
= IDirectDrawSurface_SetColorKey(TexSurface
, DDCKEY_SRCBLT
, &clrKey
);
1846 ok(hr
==D3D_OK
, "IDirectDrawSurfac_SetColorKey returned: %x\n", hr
);
1848 memset(&exdesc
, 0, sizeof(D3DEXECUTEBUFFERDESC
));
1849 exdesc
.dwSize
= sizeof(D3DEXECUTEBUFFERDESC
);
1850 hr
= IDirect3DExecuteBuffer_Lock(ExecuteBuffer
, &exdesc
);
1851 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr
);
1853 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1857 memcpy(exdesc
.lpData
, test1_quads
, sizeof(test1_quads
));
1859 exe_buffer_ptr
= sizeof(test1_quads
) + (char*)exdesc
.lpData
;
1861 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr
);
1863 EXEBUF_START_RENDER_STATES(2, exe_buffer_ptr
);
1864 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
, exe_buffer_ptr
);
1865 hr
= IDirect3DTexture_GetHandle(Texture
, Direct3DDevice1
, &htex
);
1866 ok(hr
== D3D_OK
, "IDirect3DTexture_GetHandle failed with %08x\n", hr
);
1867 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE
, htex
, exe_buffer_ptr
);
1869 EXEBUF_PUT_QUAD(0, exe_buffer_ptr
);
1870 EXEBUF_PUT_QUAD(4, exe_buffer_ptr
);
1872 EXEBUF_END(exe_buffer_ptr
);
1874 exe_length
= ((char*)exe_buffer_ptr
- (char*)exdesc
.lpData
) - sizeof(test1_quads
);
1876 hr
= IDirect3DExecuteBuffer_Unlock(ExecuteBuffer
);
1878 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr
);
1881 memset(&exdata
, 0, sizeof(exdata
));
1882 exdata
.dwSize
= sizeof(exdata
);
1883 exdata
.dwVertexCount
= 8;
1884 exdata
.dwInstructionOffset
= sizeof(test1_quads
);
1885 exdata
.dwInstructionLength
= exe_length
;
1886 hr
= IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer
, &exdata
);
1887 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr
);
1889 hr
= IDirect3DDevice_BeginScene(Direct3DDevice1
);
1890 ok(hr
== D3D_OK
, "IDirect3DDevice_BeginScene failed with %08x\n", hr
);
1892 if (SUCCEEDED(hr
)) {
1893 hr
= IDirect3DDevice_Execute(Direct3DDevice1
, ExecuteBuffer
, Viewport
, D3DEXECUTE_UNCLIPPED
);
1894 ok(hr
== D3D_OK
, "IDirect3DDevice_Execute failed, hr = %08x\n", hr
);
1895 hr
= IDirect3DDevice_EndScene(Direct3DDevice1
);
1896 ok(hr
== D3D_OK
, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr
);
1899 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 5);
1900 ok(color
== 0, "Got color %08x, expected 00000000\n", color
);
1902 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 5);
1903 red
= (color
& 0x00ff0000) >> 16;
1904 green
= (color
& 0x0000ff00) >> 8;
1905 blue
= (color
& 0x000000ff);
1906 ok(red
== 0xff && green
== 0 && blue
== 0, "Got color %08x, expected 00ff0000 or near\n", color
);
1908 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 245);
1909 ok(color
== 0, "Got color %08x, expected 00000000\n", color
);
1911 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 245);
1912 red
= (color
& 0x00ff0000) >> 16;
1913 green
= (color
& 0x0000ff00) >> 8;
1914 blue
= (color
& 0x000000ff);
1915 ok(red
>= 0x7e && red
<= 0x82 && green
== 0 && blue
== 0, "Got color %08x, expected 00800000 or near\n", color
);
1917 /* 5) Test alpha again, now with color keyed P8 texture */
1918 if(Texture
) IDirect3DTexture_Release(Texture
);
1920 if(TexSurface
) IDirectDrawSurface_Release(TexSurface
);
1923 hr
= IDirect3DDevice_EnumTextureFormats(Direct3DDevice1
, TextureFormatEnumCallback
,
1924 &p8_textures_supported
);
1925 ok(hr
== DD_OK
, "IDirect3DDevice_EnumTextureFormats returned %08x\n", hr
);
1927 if (!p8_textures_supported
) {
1928 skip("device has no P8 texture support, skipping test\n");
1930 memset (&ddsd
, 0, sizeof (ddsd
));
1931 ddsd
.dwSize
= sizeof (ddsd
);
1932 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
1933 ddsd
.dwHeight
= 128;
1935 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1936 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
1937 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_PALETTEINDEXED8
;
1938 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 8;
1940 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &TexSurface
, NULL
);
1941 ok(hr
==D3D_OK
, "CreateSurface returned: %x\n", hr
);
1943 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1947 memset(table1
, 0, sizeof(table1
));
1948 table1
[0].peBlue
= 0xff;
1949 table1
[1].peRed
= 0xff;
1951 hr
= IDirectDraw_CreatePalette(DirectDraw1
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, table1
, &Palette
, NULL
);
1952 ok(hr
== DD_OK
, "CreatePalette returned %08x\n", hr
);
1954 skip("IDirectDraw_CreatePalette failed; skipping further tests\n");
1958 hr
= IDirectDrawSurface_SetPalette(TexSurface
, Palette
);
1959 ok(hr
==D3D_OK
, "IDirectDrawSurface_SetPalette returned: %x\n", hr
);
1961 hr
= IDirectDrawSurface_QueryInterface(TexSurface
, &IID_IDirect3DTexture
,
1963 ok(hr
==D3D_OK
, "IDirectDrawSurface_QueryInterface returned: %x\n", hr
);
1965 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1969 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
1970 ddbltfx
.dwSize
= sizeof(ddbltfx
);
1971 U5(ddbltfx
).dwFillColor
= 0;
1972 hr
= IDirectDrawSurface_Blt(Surface1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1973 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1974 U5(ddbltfx
).dwFillColor
= 0;
1975 hr
= IDirectDrawSurface_Blt(TexSurface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1976 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1977 U5(ddbltfx
).dwFillColor
= 1;
1978 hr
= IDirectDrawSurface_Blt(TexSurface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1979 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1981 clrKey
.dwColorSpaceLowValue
= 1;
1982 clrKey
.dwColorSpaceHighValue
= 1;
1983 hr
= IDirectDrawSurface_SetColorKey(TexSurface
, DDCKEY_SRCBLT
, &clrKey
);
1984 ok(hr
==D3D_OK
, "IDirectDrawSurfac_SetColorKey returned: %x\n", hr
);
1986 memset(&exdesc
, 0, sizeof(D3DEXECUTEBUFFERDESC
));
1987 exdesc
.dwSize
= sizeof(D3DEXECUTEBUFFERDESC
);
1988 hr
= IDirect3DExecuteBuffer_Lock(ExecuteBuffer
, &exdesc
);
1989 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr
);
1991 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1995 memcpy(exdesc
.lpData
, test1_quads
, sizeof(test1_quads
));
1997 exe_buffer_ptr
= sizeof(test1_quads
) + (char*)exdesc
.lpData
;
1999 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr
);
2001 EXEBUF_START_RENDER_STATES(2, exe_buffer_ptr
);
2002 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
, exe_buffer_ptr
);
2003 hr
= IDirect3DTexture_GetHandle(Texture
, Direct3DDevice1
, &htex
);
2004 ok(hr
== D3D_OK
, "IDirect3DTexture_GetHandle failed with %08x\n", hr
);
2005 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE
, htex
, exe_buffer_ptr
);
2007 EXEBUF_PUT_QUAD(0, exe_buffer_ptr
);
2008 EXEBUF_PUT_QUAD(4, exe_buffer_ptr
);
2010 EXEBUF_END(exe_buffer_ptr
);
2012 exe_length
= ((char*)exe_buffer_ptr
- (char*)exdesc
.lpData
) - sizeof(test1_quads
);
2014 hr
= IDirect3DExecuteBuffer_Unlock(ExecuteBuffer
);
2016 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr
);
2019 memset(&exdata
, 0, sizeof(exdata
));
2020 exdata
.dwSize
= sizeof(exdata
);
2021 exdata
.dwVertexCount
= 8;
2022 exdata
.dwInstructionOffset
= sizeof(test1_quads
);
2023 exdata
.dwInstructionLength
= exe_length
;
2024 hr
= IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer
, &exdata
);
2025 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr
);
2027 hr
= IDirect3DDevice_BeginScene(Direct3DDevice1
);
2028 ok(hr
== D3D_OK
, "IDirect3DDevice_BeginScene failed with %08x\n", hr
);
2030 if (SUCCEEDED(hr
)) {
2031 hr
= IDirect3DDevice_Execute(Direct3DDevice1
, ExecuteBuffer
, Viewport
, D3DEXECUTE_UNCLIPPED
);
2032 ok(hr
== D3D_OK
, "IDirect3DDevice_Execute failed, hr = %08x\n", hr
);
2033 hr
= IDirect3DDevice_EndScene(Direct3DDevice1
);
2034 ok(hr
== D3D_OK
, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr
);
2037 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 5);
2038 ok(color
== 0, "Got color %08x, expected 00000000\n", color
);
2040 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 5);
2041 red
= (color
& 0x00ff0000) >> 16;
2042 green
= (color
& 0x0000ff00) >> 8;
2043 blue
= (color
& 0x000000ff);
2044 ok(red
== 0 && green
== 0 && blue
== 0xff, "Got color %08x, expected 000000ff or near\n", color
);
2046 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 245);
2047 ok(color
== 0, "Got color %08x, expected 00000000\n", color
);
2049 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 245);
2050 red
= (color
& 0x00ff0000) >> 16;
2051 green
= (color
& 0x0000ff00) >> 8;
2052 blue
= (color
& 0x000000ff);
2053 ok(red
== 0 && green
== 0 && blue
>= 0x7e && blue
<= 0x82, "Got color %08x, expected 00000080 or near\n", color
);
2058 if (Palette
) IDirectDrawPalette_Release(Palette
);
2059 if (TexSurface
) IDirectDrawSurface_Release(TexSurface
);
2060 if (Texture
) IDirect3DTexture_Release(Texture
);
2063 static void D3D1_ViewportClearTest(void)
2066 IDirect3DMaterial
*bgMaterial
= NULL
;
2068 D3DMATERIALHANDLE hMat
;
2069 D3DVIEWPORT vp_data
;
2070 IDirect3DViewport
*Viewport2
= NULL
;
2071 DWORD color
, red
, green
, blue
;
2073 hr
= IDirect3D_CreateMaterial(Direct3D1
, &bgMaterial
, NULL
);
2074 ok(hr
== D3D_OK
, "IDirect3D_CreateMaterial failed: %08x\n", hr
);
2079 hr
= IDirect3D_CreateViewport(Direct3D1
, &Viewport2
, NULL
);
2080 ok(hr
== D3D_OK
, "IDirect3D_CreateViewport failed: %08x\n", hr
);
2085 hr
= IDirect3DViewport_Initialize(Viewport2
, Direct3D1
);
2086 ok(hr
== D3D_OK
|| hr
== DDERR_ALREADYINITIALIZED
, "IDirect3DViewport_Initialize returned %08x\n", hr
);
2087 hr
= IDirect3DDevice_AddViewport(Direct3DDevice1
, Viewport2
);
2088 ok(hr
== D3D_OK
, "IDirect3DDevice_AddViewport returned %08x\n", hr
);
2089 vp_data
.dwSize
= sizeof(vp_data
);
2092 vp_data
.dwWidth
= 100;
2093 vp_data
.dwHeight
= 100;
2094 vp_data
.dvScaleX
= 1;
2095 vp_data
.dvScaleY
= 1;
2096 vp_data
.dvMaxX
= 100;
2097 vp_data
.dvMaxY
= 100;
2100 hr
= IDirect3DViewport_SetViewport(Viewport2
, &vp_data
);
2101 ok(hr
== D3D_OK
, "IDirect3DViewport_SetViewport returned %08x\n", hr
);
2103 memset(&mat
, 0, sizeof(mat
));
2104 mat
.dwSize
= sizeof(mat
);
2105 U1(U(mat
).diffuse
).r
= 1.0f
;
2106 hr
= IDirect3DMaterial_SetMaterial(bgMaterial
, &mat
);
2107 ok(hr
== D3D_OK
, "IDirect3DMaterial_SetMaterial failed: %08x\n", hr
);
2109 hr
= IDirect3DMaterial_GetHandle(bgMaterial
, Direct3DDevice1
, &hMat
);
2110 ok(hr
== D3D_OK
, "IDirect3DMaterial_GetHandle failed: %08x\n", hr
);
2112 hr
= IDirect3DViewport_SetBackground(Viewport
, hMat
);
2113 ok(hr
== D3D_OK
, "IDirect3DViewport_SetBackground failed: %08x\n", hr
);
2114 hr
= IDirect3DViewport_SetBackground(Viewport2
, hMat
);
2115 ok(hr
== D3D_OK
, "IDirect3DViewport_SetBackground failed: %08x\n", hr
);
2117 hr
= IDirect3DDevice_BeginScene(Direct3DDevice1
);
2118 ok(hr
== D3D_OK
, "IDirect3DDevice_BeginScene failed with %08x\n", hr
);
2120 if (SUCCEEDED(hr
)) {
2123 U1(rect
).x1
= U2(rect
).y1
= 0;
2127 hr
= IDirect3DViewport_Clear(Viewport
, 1, &rect
, D3DCLEAR_TARGET
);
2128 ok(hr
== D3D_OK
, "IDirect3DViewport_Clear failed: %08x\n", hr
);
2130 memset(&mat
, 0, sizeof(mat
));
2131 mat
.dwSize
= sizeof(mat
);
2132 U3(U(mat
).diffuse
).b
= 1.0f
;
2133 hr
= IDirect3DMaterial_SetMaterial(bgMaterial
, &mat
);
2134 ok(hr
== D3D_OK
, "IDirect3DMaterial_SetMaterial failed: %08x\n", hr
);
2136 hr
= IDirect3DViewport_Clear(Viewport2
, 1, &rect
, D3DCLEAR_TARGET
);
2137 ok(hr
== D3D_OK
, "IDirect3DViewport_Clear failed: %08x\n", hr
);
2139 hr
= IDirect3DDevice_EndScene(Direct3DDevice1
);
2140 ok(hr
== D3D_OK
, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr
);
2143 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 5);
2144 red
= (color
& 0x00ff0000) >> 16;
2145 green
= (color
& 0x0000ff00) >> 8;
2146 blue
= (color
& 0x000000ff);
2147 ok((red
== 0xff && green
== 0 && blue
== 0) ||
2148 broken(red
== 0 && green
== 0 && blue
== 0xff), /* VMware and some native boxes */
2149 "Got color %08x, expected 00ff0000\n", color
);
2151 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 205, 205);
2152 red
= (color
& 0x00ff0000) >> 16;
2153 green
= (color
& 0x0000ff00) >> 8;
2154 blue
= (color
& 0x000000ff);
2155 ok(red
== 0 && green
== 0 && blue
== 0xff, "Got color %08x, expected 000000ff\n", color
);
2159 if (bgMaterial
) IDirect3DMaterial_Release(bgMaterial
);
2160 if (Viewport2
) IDirect3DViewport_Release(Viewport2
);
2163 static DWORD
D3D3_getPixelColor(IDirectDraw4
*DirectDraw
, IDirectDrawSurface4
*Surface
, UINT x
, UINT y
)
2167 DDSURFACEDESC2 ddsd
;
2168 RECT rectToLock
= {x
, y
, x
+1, y
+1};
2169 IDirectDrawSurface4
*surf
= NULL
;
2171 /* Some implementations seem to dislike direct locking on the front buffer. Thus copy the front buffer
2172 * to an offscreen surface and lock it instead of the front buffer
2174 memset(&ddsd
, 0, sizeof(ddsd
));
2175 ddsd
.dwSize
= sizeof(ddsd
);
2176 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
2177 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
2179 ddsd
.dwHeight
= 480;
2180 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
;
2181 hr
= IDirectDraw4_CreateSurface(DirectDraw
, &ddsd
, &surf
, NULL
);
2182 ok(hr
== DD_OK
, "IDirectDraw_CreateSurface failed with %08x\n", hr
);
2185 trace("cannot create helper surface\n");
2189 memset(&ddsd
, 0, sizeof(ddsd
));
2190 ddsd
.dwSize
= sizeof(ddsd
);
2191 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
2193 hr
= IDirectDrawSurface4_BltFast(surf
, 0, 0, Surface
, NULL
, 0);
2194 ok(hr
== DD_OK
, "IDirectDrawSurface_BltFast returned %08x\n", hr
);
2197 trace("Cannot blit\n");
2202 hr
= IDirectDrawSurface4_Lock(surf
, &rectToLock
, &ddsd
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
2205 trace("Can't lock the offscreen surface, hr=%08x\n", hr
);
2210 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
2211 * really important for these tests
2213 ret
= ((DWORD
*) ddsd
.lpSurface
)[0] & 0x00ffffff;
2214 hr
= IDirectDrawSurface4_Unlock(surf
, NULL
);
2217 trace("Can't unlock the offscreen surface, hr=%08x\n", hr
);
2221 IDirectDrawSurface4_Release(surf
);
2225 static void D3D3_ViewportClearTest(void)
2228 IDirectDraw
*DirectDraw1
= NULL
;
2229 IDirectDraw4
*DirectDraw4
= NULL
;
2230 IDirectDrawSurface4
*Primary
= NULL
;
2231 IDirect3D3
*Direct3D3
= NULL
;
2232 IDirect3DViewport3
*Viewport3
= NULL
;
2233 IDirect3DViewport3
*SmallViewport3
= NULL
;
2234 IDirect3DDevice3
*Direct3DDevice3
= NULL
;
2236 DDSURFACEDESC2 ddsd
;
2237 D3DVIEWPORT2 vp_data
;
2238 DWORD color
, red
, green
, blue
;
2242 1.0f
, 0.0f
, 0.0f
, 0.0f
,
2243 0.0f
, 1.0f
, 0.0f
, 0.0f
,
2244 0.0f
, 0.0f
, 1.0f
, 0.0f
,
2245 0.0f
, 0.0f
, 0.0f
, 1.0f
,
2249 struct vec3 position
;
2254 {{-1.0f
, -1.0f
, 0.1f
}, 0xffffffff},
2255 {{-1.0f
, 1.0f
, 0.1f
}, 0xffffffff},
2256 {{ 1.0f
, 1.0f
, 0.1f
}, 0xffffffff},
2257 {{ 1.0f
, -1.0f
, 0.1f
}, 0xffffffff},
2260 WORD Indices
[] = {0, 1, 2, 2, 3, 0};
2261 DWORD fvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
2263 wc
.lpfnWndProc
= DefWindowProcA
;
2264 wc
.lpszClassName
= "D3D3_ViewportClearTest_wc";
2265 RegisterClassA(&wc
);
2266 window
= CreateWindowA("D3D3_ViewportClearTest_wc", "D3D3_ViewportClearTest",
2267 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
2269 hr
= DirectDrawCreate( NULL
, &DirectDraw1
, NULL
);
2270 ok(hr
==DD_OK
|| hr
==DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreate returned: %x\n", hr
);
2271 if(FAILED(hr
)) goto out
;
2273 hr
= IDirectDraw_SetCooperativeLevel(DirectDraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2274 ok(hr
==DD_OK
, "SetCooperativeLevel returned: %x\n", hr
);
2275 if(FAILED(hr
)) goto out
;
2277 hr
= IDirectDraw_SetDisplayMode(DirectDraw1
, 640, 480, 32);
2279 /* 24 bit is fine too */
2280 hr
= IDirectDraw_SetDisplayMode(DirectDraw1
, 640, 480, 24);
2282 ok(hr
==DD_OK
|| hr
== DDERR_UNSUPPORTED
, "SetDisplayMode returned: %x\n", hr
);
2283 if (FAILED(hr
)) goto out
;
2285 hr
= IDirectDraw_QueryInterface(DirectDraw1
, &IID_IDirectDraw4
, (void**)&DirectDraw4
);
2286 ok(hr
==DD_OK
, "QueryInterface returned: %08x\n", hr
);
2287 if(FAILED(hr
)) goto out
;
2289 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
2290 ddsd
.dwSize
= sizeof(DDSURFACEDESC2
);
2291 ddsd
.dwFlags
= DDSD_CAPS
;
2292 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
;
2294 hr
= IDirectDraw_CreateSurface(DirectDraw4
, &ddsd
, &Primary
, NULL
);
2295 ok(hr
==DD_OK
, "IDirectDraw_CreateSurface returned: %08x\n", hr
);
2296 if(FAILED(hr
)) goto out
;
2298 hr
= IDirectDraw4_QueryInterface(DirectDraw4
, &IID_IDirect3D3
, (void**)&Direct3D3
);
2299 ok(hr
==DD_OK
, "IDirectDraw4_QueryInterface returned: %08x\n", hr
);
2300 if(FAILED(hr
)) goto out
;
2302 hr
= IDirect3D3_CreateDevice(Direct3D3
, &IID_IDirect3DHALDevice
, Primary
, &Direct3DDevice3
, NULL
);
2304 trace("Creating a HAL device failed, trying Ref\n");
2305 hr
= IDirect3D3_CreateDevice(Direct3D3
, &IID_IDirect3DRefDevice
, Primary
, &Direct3DDevice3
, NULL
);
2307 ok(hr
==D3D_OK
, "Creating 3D device returned: %x\n", hr
);
2308 if(FAILED(hr
)) goto out
;
2310 hr
= IDirect3D3_CreateViewport(Direct3D3
, &Viewport3
, NULL
);
2311 ok(hr
==DD_OK
, "IDirect3D3_CreateViewport returned: %08x\n", hr
);
2312 if(FAILED(hr
)) goto out
;
2314 hr
= IDirect3DDevice3_AddViewport(Direct3DDevice3
, Viewport3
);
2315 ok(hr
==DD_OK
, "IDirect3DDevice3_AddViewport returned: %08x\n", hr
);
2317 memset(&vp_data
, 0, sizeof(D3DVIEWPORT2
));
2318 vp_data
.dwSize
= sizeof(D3DVIEWPORT2
);
2319 vp_data
.dwWidth
= 640;
2320 vp_data
.dwHeight
= 480;
2321 vp_data
.dvClipX
= -1.0f
;
2322 vp_data
.dvClipWidth
= 2.0f
;
2323 vp_data
.dvClipY
= 1.0f
;
2324 vp_data
.dvClipHeight
= 2.0f
;
2325 vp_data
.dvMaxZ
= 1.0f
;
2326 hr
= IDirect3DViewport3_SetViewport2(Viewport3
, &vp_data
);
2327 ok(hr
==DD_OK
, "IDirect3DViewport3_SetViewport2 returned: %08x\n", hr
);
2329 hr
= IDirect3D3_CreateViewport(Direct3D3
, &SmallViewport3
, NULL
);
2330 ok(hr
==DD_OK
, "IDirect3D3_CreateViewport returned: %08x\n", hr
);
2331 if(FAILED(hr
)) goto out
;
2333 hr
= IDirect3DDevice3_AddViewport(Direct3DDevice3
, SmallViewport3
);
2334 ok(hr
==DD_OK
, "IDirect3DDevice3_AddViewport returned: %08x\n", hr
);
2336 memset(&vp_data
, 0, sizeof(D3DVIEWPORT2
));
2337 vp_data
.dwSize
= sizeof(D3DVIEWPORT2
);
2340 vp_data
.dwWidth
= 100;
2341 vp_data
.dwHeight
= 100;
2342 vp_data
.dvClipX
= -1.0f
;
2343 vp_data
.dvClipWidth
= 2.0f
;
2344 vp_data
.dvClipY
= 1.0f
;
2345 vp_data
.dvClipHeight
= 2.0f
;
2346 vp_data
.dvMaxZ
= 1.0f
;
2347 hr
= IDirect3DViewport3_SetViewport2(SmallViewport3
, &vp_data
);
2348 ok(hr
==DD_OK
, "IDirect3DViewport3_SetViewport2 returned: %08x\n", hr
);
2350 hr
= IDirect3DDevice3_BeginScene(Direct3DDevice3
);
2351 ok(hr
== D3D_OK
, "IDirect3DDevice3_BeginScene failed with %08x\n", hr
);
2353 hr
= IDirect3DDevice3_SetTransform(Direct3DDevice3
, D3DTRANSFORMSTATE_WORLD
, &mat
);
2354 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetTransform returned %08x\n", hr
);
2355 hr
= IDirect3DDevice3_SetTransform(Direct3DDevice3
, D3DTRANSFORMSTATE_VIEW
, &mat
);
2356 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetTransform returned %08x\n", hr
);
2357 hr
= IDirect3DDevice3_SetTransform(Direct3DDevice3
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
2358 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetTransform returned %08x\n", hr
);
2359 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_CLIPPING
, FALSE
);
2360 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState returned %08x\n", hr
);
2361 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_ZENABLE
, FALSE
);
2362 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState returned %08x\n", hr
);
2363 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
2364 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState returned %08x\n", hr
);
2365 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_STENCILENABLE
, FALSE
);
2366 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState returned %08x\n", hr
);
2367 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_ALPHATESTENABLE
, FALSE
);
2368 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState returned %08x\n", hr
);
2369 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
);
2370 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState returned %08x\n", hr
);
2371 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
2372 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState failed with %08x\n", hr
);
2373 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_LIGHTING
, FALSE
);
2374 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState returned %08x\n", hr
);
2376 if (SUCCEEDED(hr
)) {
2377 U1(rect
).x1
= U2(rect
).y1
= 0;
2381 hr
= IDirect3DViewport3_Clear2(Viewport3
, 1, &rect
, D3DCLEAR_TARGET
, 0x00ff00, 0.0f
, 0);
2382 ok(hr
== D3D_OK
, "IDirect3DViewport3_Clear2 failed, hr = %08x\n", hr
);
2384 hr
= IDirect3DViewport3_Clear2(SmallViewport3
, 1, &rect
, D3DCLEAR_TARGET
, 0xff0000, 0.0f
, 0);
2385 ok(hr
== D3D_OK
, "IDirect3DViewport3_Clear2 failed, hr = %08x\n", hr
);
2387 hr
= IDirect3DDevice3_EndScene(Direct3DDevice3
);
2388 ok(hr
== D3D_OK
, "IDirect3DDevice3_EndScene failed, hr = %08x\n", hr
);
2391 color
= D3D3_getPixelColor(DirectDraw4
, Primary
, 5, 5);
2392 red
= (color
& 0x00ff0000) >> 16;
2393 green
= (color
& 0x0000ff00) >> 8;
2394 blue
= (color
& 0x000000ff);
2395 ok(red
== 0 && green
== 0xff && blue
== 0, "Got color %08x, expected 0000ff00\n", color
);
2397 color
= D3D3_getPixelColor(DirectDraw4
, Primary
, 405, 105);
2398 red
= (color
& 0x00ff0000) >> 16;
2399 green
= (color
& 0x0000ff00) >> 8;
2400 blue
= (color
& 0x000000ff);
2401 ok(red
== 0xff && green
== 0 && blue
== 0, "Got color %08x, expected 00ff0000\n", color
);
2403 /* Test that clearing viewport doesn't interfere with rendering to previously active viewport. */
2404 hr
= IDirect3DDevice3_BeginScene(Direct3DDevice3
);
2405 ok(hr
== D3D_OK
, "IDirect3DDevice3_BeginScene failed with %08x\n", hr
);
2407 if (SUCCEEDED(hr
)) {
2408 hr
= IDirect3DDevice3_SetCurrentViewport(Direct3DDevice3
, SmallViewport3
);
2409 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetCurrentViewport failed with %08x\n", hr
);
2411 hr
= IDirect3DViewport3_Clear2(Viewport3
, 1, &rect
, D3DCLEAR_TARGET
, 0x000000, 0.0f
, 0);
2412 ok(hr
== D3D_OK
, "IDirect3DViewport3_Clear2 failed, hr = %08x\n", hr
);
2414 hr
= IDirect3DDevice3_DrawIndexedPrimitive(Direct3DDevice3
, D3DPT_TRIANGLELIST
, fvf
, quad
, 4 /* NumVerts */,
2415 Indices
, 6 /* Indexcount */, 0 /* flags */);
2416 ok(hr
== D3D_OK
, "IDirect3DDevice3_DrawIndexedPrimitive failed with %08x\n", hr
);
2418 hr
= IDirect3DDevice3_EndScene(Direct3DDevice3
);
2419 ok(hr
== D3D_OK
, "IDirect3DDevice3_EndScene failed, hr = %08x\n", hr
);
2422 color
= D3D3_getPixelColor(DirectDraw4
, Primary
, 5, 5);
2423 red
= (color
& 0x00ff0000) >> 16;
2424 green
= (color
& 0x0000ff00) >> 8;
2425 blue
= (color
& 0x000000ff);
2426 ok(red
== 0 && green
== 0 && blue
== 0, "Got color %08x, expected 00000000\n", color
);
2428 color
= D3D3_getPixelColor(DirectDraw4
, Primary
, 405, 105);
2429 red
= (color
& 0x00ff0000) >> 16;
2430 green
= (color
& 0x0000ff00) >> 8;
2431 blue
= (color
& 0x000000ff);
2432 ok(red
== 0xff && green
== 0xff && blue
== 0xff, "Got color %08x, expected 00ffffff\n", color
);
2436 if (SmallViewport3
) IDirect3DViewport3_Release(SmallViewport3
);
2437 if (Viewport3
) IDirect3DViewport3_Release(Viewport3
);
2438 if (Direct3DDevice3
) IDirect3DDevice3_Release(Direct3DDevice3
);
2439 if (Direct3D3
) IDirect3D3_Release(Direct3D3
);
2440 if (Primary
) IDirectDrawSurface4_Release(Primary
);
2441 if (DirectDraw1
) IDirectDraw_Release(DirectDraw1
);
2442 if (DirectDraw4
) IDirectDraw4_Release(DirectDraw4
);
2443 if(window
) DestroyWindow(window
);
2446 static void p8_surface_fill_rect(IDirectDrawSurface
*dest
, UINT x
, UINT y
, UINT w
, UINT h
, BYTE colorindex
)
2453 memset(&ddsd
, 0, sizeof(ddsd
));
2454 ddsd
.dwSize
= sizeof(ddsd
);
2456 hr
= IDirectDrawSurface_Lock(dest
, NULL
, &ddsd
, DDLOCK_WRITEONLY
| DDLOCK_WAIT
, NULL
);
2457 ok(hr
==DD_OK
, "IDirectDrawSurface_Lock returned: %x\n", hr
);
2459 p
= (BYTE
*)ddsd
.lpSurface
+ U1(ddsd
).lPitch
* y
+ x
;
2461 for (i
= 0; i
< h
; i
++) {
2462 for (i1
= 0; i1
< w
; i1
++) {
2465 p
+= U1(ddsd
).lPitch
;
2468 hr
= IDirectDrawSurface_Unlock(dest
, NULL
);
2469 ok(hr
==DD_OK
, "IDirectDrawSurface_UnLock returned: %x\n", hr
);
2472 static COLORREF
getPixelColor_GDI(IDirectDrawSurface
*Surface
, UINT x
, UINT y
)
2474 COLORREF clr
= CLR_INVALID
;
2478 hr
= IDirectDrawSurface_GetDC(Surface
, &hdc
);
2479 ok(hr
==DD_OK
, "IDirectDrawSurface_GetDC returned: %x\n", hr
);
2481 if (SUCCEEDED(hr
)) {
2482 clr
= GetPixel(hdc
, x
, y
);
2484 hr
= IDirectDrawSurface_ReleaseDC(Surface
, hdc
);
2485 ok(hr
==DD_OK
, "IDirectDrawSurface_ReleaseDC returned: %x\n", hr
);
2491 static BOOL
colortables_check_equality(PALETTEENTRY table1
[256], RGBQUAD table2
[256])
2495 for (i
= 0; i
< 256; i
++) {
2496 if (table1
[i
].peRed
!= table2
[i
].rgbRed
|| table1
[i
].peGreen
!= table2
[i
].rgbGreen
||
2497 table1
[i
].peBlue
!= table2
[i
].rgbBlue
) return FALSE
;
2503 static void p8_primary_test(void)
2505 /* Test 8bit mode used by games like StarCraft, C&C Red Alert I etc */
2509 PALETTEENTRY entries
[256];
2510 RGBQUAD coltable
[256];
2512 IDirectDrawPalette
*ddprimpal
= NULL
;
2513 IDirectDrawSurface
*offscreen
= NULL
;
2519 unsigned differences
;
2521 /* An IDirect3DDevice cannot be queryInterfaced from an IDirect3DDevice7 on windows */
2522 hr
= DirectDrawCreate(NULL
, &DirectDraw1
, NULL
);
2524 ok(hr
==DD_OK
|| hr
==DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreate returned: %x\n", hr
);
2529 wc
.lpfnWndProc
= DefWindowProcA
;
2530 wc
.lpszClassName
= "p8_primary_test_wc";
2531 RegisterClassA(&wc
);
2532 window
= CreateWindowA("p8_primary_test_wc", "p8_primary_test",
2533 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
2535 hr
= IDirectDraw_SetCooperativeLevel(DirectDraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2536 ok(hr
==DD_OK
, "SetCooperativeLevel returned: %x\n", hr
);
2541 hr
= IDirectDraw_SetDisplayMode(DirectDraw1
, 640, 480, 8);
2542 ok(hr
==DD_OK
|| hr
== DDERR_UNSUPPORTED
, "SetDisplayMode returned: %x\n", hr
);
2547 memset(&ddsd
, 0, sizeof(ddsd
));
2548 ddsd
.dwSize
= sizeof(ddsd
);
2549 ddsd
.dwFlags
= DDSD_CAPS
;
2550 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2551 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &Surface1
, NULL
);
2552 ok(hr
==DD_OK
, "CreateSurface returned: %x\n", hr
);
2557 memset(entries
, 0, sizeof(entries
));
2558 entries
[0].peRed
= 0xff;
2559 entries
[1].peGreen
= 0xff;
2560 entries
[2].peBlue
= 0xff;
2562 hr
= IDirectDraw_CreatePalette(DirectDraw1
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, entries
, &ddprimpal
, NULL
);
2563 ok(hr
== DD_OK
, "CreatePalette returned %08x\n", hr
);
2565 skip("IDirectDraw_CreatePalette failed; skipping further tests\n");
2569 hr
= IDirectDrawSurface_SetPalette(Surface1
, ddprimpal
);
2570 ok(hr
==DD_OK
, "IDirectDrawSurface_SetPalette returned: %x\n", hr
);
2572 p8_surface_fill_rect(Surface1
, 0, 0, 640, 480, 2);
2574 color
= getPixelColor_GDI(Surface1
, 10, 10);
2575 ok(GetRValue(color
) == 0 && GetGValue(color
) == 0 && GetBValue(color
) == 0xFF,
2576 "got R %02X G %02X B %02X, expected R 00 G 00 B FF\n",
2577 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2579 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
2580 ddbltfx
.dwSize
= sizeof(ddbltfx
);
2581 U5(ddbltfx
).dwFillColor
= 0;
2582 hr
= IDirectDrawSurface_Blt(Surface1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
2583 ok(hr
== DD_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
2585 color
= getPixelColor_GDI(Surface1
, 10, 10);
2586 ok(GetRValue(color
) == 0xFF && GetGValue(color
) == 0 && GetBValue(color
) == 0,
2587 "got R %02X G %02X B %02X, expected R FF G 00 B 00\n",
2588 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2590 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
2591 ddbltfx
.dwSize
= sizeof(ddbltfx
);
2592 U5(ddbltfx
).dwFillColor
= 1;
2593 hr
= IDirectDrawSurface_Blt(Surface1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
2594 ok(hr
== DD_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
2596 color
= getPixelColor_GDI(Surface1
, 10, 10);
2597 ok(GetRValue(color
) == 0 && GetGValue(color
) == 0xFF && GetBValue(color
) == 0,
2598 "got R %02X G %02X B %02X, expected R 00 G FF B 00\n",
2599 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2601 memset (&ddsd
, 0, sizeof (ddsd
));
2602 ddsd
.dwSize
= sizeof (ddsd
);
2603 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
2606 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
;
2607 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
2608 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_PALETTEINDEXED8
;
2609 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 8;
2610 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &offscreen
, NULL
);
2612 broken(hr
== DDERR_INVALIDPIXELFORMAT
) || /* VMware */
2613 broken(hr
== DDERR_NODIRECTDRAWHW
), /* VMware */
2614 "IDirectDraw_CreateSurface returned %08x\n", hr
);
2615 if (FAILED(hr
)) goto out
;
2617 memset(entries
, 0, sizeof(entries
));
2618 for (i
= 0; i
< 256; i
++) {
2619 entries
[i
].peBlue
= i
;
2621 hr
= IDirectDrawPalette_SetEntries(ddprimpal
, 0, 0, 256, entries
);
2622 ok(hr
== DD_OK
, "IDirectDrawPalette_SetEntries failed with %08x\n", hr
);
2624 hr
= IDirectDrawSurface_GetDC(offscreen
, &hdc
);
2625 ok(hr
==DD_OK
, "IDirectDrawSurface_GetDC returned: %x\n", hr
);
2626 i
= GetDIBColorTable(hdc
, 0, 256, coltable
);
2627 ok(i
== 256, "GetDIBColorTable returned %u, last error: %x\n", i
, GetLastError());
2628 hr
= IDirectDrawSurface_ReleaseDC(offscreen
, hdc
);
2629 ok(hr
==DD_OK
, "IDirectDrawSurface_ReleaseDC returned: %x\n", hr
);
2631 ok(colortables_check_equality(entries
, coltable
), "unexpected colortable on offscreen surface\n");
2633 p8_surface_fill_rect(offscreen
, 0, 0, 16, 16, 2);
2635 memset(entries
, 0, sizeof(entries
));
2636 entries
[0].peRed
= 0xff;
2637 entries
[1].peGreen
= 0xff;
2638 entries
[2].peBlue
= 0xff;
2639 entries
[3].peRed
= 0x80;
2640 hr
= IDirectDrawPalette_SetEntries(ddprimpal
, 0, 0, 256, entries
);
2641 ok(hr
== DD_OK
, "IDirectDrawPalette_SetEntries failed with %08x\n", hr
);
2643 hr
= IDirectDrawSurface_BltFast(Surface1
, 0, 0, offscreen
, NULL
, 0);
2644 ok(hr
==DD_OK
, "IDirectDrawSurface_BltFast returned: %x\n", hr
);
2646 color
= getPixelColor_GDI(Surface1
, 1, 1);
2647 ok(GetRValue(color
) == 0 && GetGValue(color
) == 0x00 && GetBValue(color
) == 0xFF,
2648 "got R %02X G %02X B %02X, expected R 00 G 00 B FF\n",
2649 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2651 /* Color keyed blit. */
2652 p8_surface_fill_rect(offscreen
, 0, 0, 8, 8, 3);
2653 clrKey
.dwColorSpaceLowValue
= 3;
2654 clrKey
.dwColorSpaceHighValue
= 3;
2655 hr
= IDirectDrawSurface_SetColorKey(offscreen
, DDCKEY_SRCBLT
, &clrKey
);
2656 ok(hr
==D3D_OK
, "IDirectDrawSurfac_SetColorKey returned: %x\n", hr
);
2658 hr
= IDirectDrawSurface_BltFast(Surface1
, 100, 100, offscreen
, NULL
, DDBLTFAST_SRCCOLORKEY
);
2659 ok(hr
==DD_OK
, "IDirectDrawSurface_BltFast returned: %x\n", hr
);
2661 color
= getPixelColor_GDI(Surface1
, 105, 105);
2662 ok(GetRValue(color
) == 0 && GetGValue(color
) == 0xFF && GetBValue(color
) == 0,
2663 "got R %02X G %02X B %02X, expected R 00 G FF B 00\n",
2664 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2666 color
= getPixelColor_GDI(Surface1
, 112, 112);
2667 ok(GetRValue(color
) == 0 && GetGValue(color
) == 0x00 && GetBValue(color
) == 0xFF,
2668 "got R %02X G %02X B %02X, expected R 00 G 00 B FF\n",
2669 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2676 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
2677 ddbltfx
.dwSize
= sizeof(ddbltfx
);
2678 ddbltfx
.ddckSrcColorkey
.dwColorSpaceLowValue
= ddbltfx
.ddckSrcColorkey
.dwColorSpaceHighValue
= 2;
2679 hr
= IDirectDrawSurface_Blt(Surface1
, &rect
, offscreen
, NULL
,
2680 DDBLT_WAIT
| DDBLT_KEYSRC
| DDBLT_KEYSRCOVERRIDE
, &ddbltfx
);
2681 ok(hr
==DDERR_INVALIDPARAMS
, "IDirectDrawSurface_Blt returned: %x\n", hr
);
2682 hr
= IDirectDrawSurface_Blt(Surface1
, &rect
, offscreen
, NULL
,
2683 DDBLT_WAIT
| DDBLT_KEYSRCOVERRIDE
, &ddbltfx
);
2684 ok(hr
==DD_OK
, "IDirectDrawSurface_Blt returned: %x\n", hr
);
2686 color
= getPixelColor_GDI(Surface1
, 105, 205);
2687 ok(GetRValue(color
) == 0x80 && GetGValue(color
) == 0 && GetBValue(color
) == 0,
2688 "got R %02X G %02X B %02X, expected R 80 G 00 B 00\n",
2689 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2691 color
= getPixelColor_GDI(Surface1
, 112, 212);
2692 ok(GetRValue(color
) == 0 && GetGValue(color
) == 0xFF && GetBValue(color
) == 0,
2693 "got R %02X G %02X B %02X, expected R 00 G FF B 00\n",
2694 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2696 /* Test blitting and locking patterns that are likely to trigger bugs in opengl renderer (p8
2697 surface conversion and uploading/downloading to/from opengl texture). Similar patterns (
2698 blitting front buffer areas to/from an offscreen surface mixed with locking) are used by C&C
2700 IDirectDrawSurface_Release(offscreen
);
2702 memset (&ddsd
, 0, sizeof (ddsd
));
2703 ddsd
.dwSize
= sizeof (ddsd
);
2704 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
2706 ddsd
.dwHeight
= 480;
2707 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
2708 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
2709 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_PALETTEINDEXED8
;
2710 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 8;
2711 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &offscreen
, NULL
);
2712 ok(hr
== DD_OK
, "IDirectDraw_CreateSurface returned %08x\n", hr
);
2714 if (FAILED(hr
)) goto out
;
2716 /* Test two times, first time front buffer has a palette and second time front buffer
2717 has no palette; the latter is somewhat contrived example, but an app could set
2718 front buffer palette later. */
2719 for (i2
= 0; i2
< 2; i2
++) {
2721 hr
= IDirectDrawSurface_SetPalette(Surface1
, NULL
);
2722 ok(hr
==DD_OK
, "IDirectDrawSurface_SetPalette returned: %x\n", hr
);
2725 memset(&ddsd
, 0, sizeof(ddsd
));
2726 ddsd
.dwSize
= sizeof(ddsd
);
2727 hr
= IDirectDrawSurface_Lock(Surface1
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
2728 ok(hr
==DD_OK
, "IDirectDrawSurface_Lock returned: %x\n", hr
);
2730 for (i
= 0; i
< 256; i
++) {
2731 unsigned x
= (i
% 128) * 4;
2732 unsigned y
= (i
/ 128) * 4;
2733 BYTE
*p
= (BYTE
*)ddsd
.lpSurface
+ U1(ddsd
).lPitch
* y
+ x
;
2735 for (i1
= 0; i1
< 4; i1
++) {
2736 p
[0] = p
[1] = p
[2] = p
[3] = i
;
2737 p
+= U1(ddsd
).lPitch
;
2741 hr
= IDirectDrawSurface_Unlock(Surface1
, NULL
);
2742 ok(hr
==DD_OK
, "IDirectDrawSurface_UnLock returned: %x\n", hr
);
2744 hr
= IDirectDrawSurface_BltFast(offscreen
, 0, 0, Surface1
, NULL
, 0);
2745 ok(hr
==DD_OK
, "IDirectDrawSurface_BltFast returned: %x\n", hr
);
2747 /* This ensures offscreen surface contents will be downloaded to system memory. */
2748 memset(&ddsd
, 0, sizeof(ddsd
));
2749 ddsd
.dwSize
= sizeof(ddsd
);
2750 hr
= IDirectDrawSurface_Lock(offscreen
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
2751 ok(hr
==DD_OK
, "IDirectDrawSurface_Lock returned: %x\n", hr
);
2752 hr
= IDirectDrawSurface_Unlock(offscreen
, NULL
);
2753 ok(hr
==DD_OK
, "IDirectDrawSurface_UnLock returned: %x\n", hr
);
2755 /* Offscreen surface data will have to be converted and uploaded to texture. */
2760 hr
= IDirectDrawSurface_BltFast(offscreen
, 600, 400, Surface1
, &rect
, 0);
2761 ok(hr
==DD_OK
, "IDirectDrawSurface_BltFast returned: %x\n", hr
);
2763 /* This ensures offscreen surface contents will be downloaded to system memory. */
2764 memset(&ddsd
, 0, sizeof(ddsd
));
2765 ddsd
.dwSize
= sizeof(ddsd
);
2766 hr
= IDirectDrawSurface_Lock(offscreen
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
2767 ok(hr
==DD_OK
, "IDirectDrawSurface_Lock returned: %x\n", hr
);
2768 hr
= IDirectDrawSurface_Unlock(offscreen
, NULL
);
2769 ok(hr
==DD_OK
, "IDirectDrawSurface_UnLock returned: %x\n", hr
);
2771 hr
= IDirectDrawSurface_BltFast(Surface1
, 0, 0, offscreen
, NULL
, 0);
2772 ok(hr
==DD_OK
, "IDirectDrawSurface_BltFast returned: %x\n", hr
);
2774 memset(&ddsd
, 0, sizeof(ddsd
));
2775 ddsd
.dwSize
= sizeof(ddsd
);
2776 hr
= IDirectDrawSurface_Lock(Surface1
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
2777 ok(hr
==DD_OK
, "IDirectDrawSurface_Lock returned: %x\n", hr
);
2781 for (i
= 0; i
< 256; i
++) {
2782 unsigned x
= (i
% 128) * 4 + 1;
2783 unsigned y
= (i
/ 128) * 4 + 1;
2784 BYTE
*p
= (BYTE
*)ddsd
.lpSurface
+ U1(ddsd
).lPitch
* y
+ x
;
2786 if (*p
!= i
) differences
++;
2789 hr
= IDirectDrawSurface_Unlock(Surface1
, NULL
);
2790 ok(hr
==DD_OK
, "IDirectDrawSurface_UnLock returned: %x\n", hr
);
2792 ok(differences
== 0, i2
== 0 ? "Pass 1. Unexpected front buffer contents after blit (%u differences)\n" :
2793 "Pass 2 (with NULL front buffer palette). Unexpected front buffer contents after blit (%u differences)\n",
2799 if(ddprimpal
) IDirectDrawPalette_Release(ddprimpal
);
2800 if(offscreen
) IDirectDrawSurface_Release(offscreen
);
2801 if(Surface1
) IDirectDrawSurface_Release(Surface1
);
2802 if(DirectDraw1
) IDirectDraw_Release(DirectDraw1
);
2803 if(window
) DestroyWindow(window
);
2806 static void cubemap_test(IDirect3DDevice7
*device
)
2809 IDirectDraw7
*ddraw
;
2810 IDirectDrawSurface7
*cubemap
, *surface
;
2811 D3DDEVICEDESC7 d3dcaps
;
2814 DDSURFACEDESC2 ddsd
;
2817 static float quad
[] = {
2818 -1.0, -1.0, 0.1, 1.0, 0.0, 0.0, /* Lower left */
2819 0.0, -1.0, 0.1, 1.0, 0.0, 0.0,
2820 -1.0, 0.0, 0.1, 1.0, 0.0, 0.0,
2821 0.0, 0.0, 0.1, 1.0, 0.0, 0.0,
2823 0.0, -1.0, 0.1, 0.0, 1.0, 0.0, /* Lower right */
2824 1.0, -1.0, 0.1, 0.0, 1.0, 0.0,
2825 0.0, 0.0, 0.1, 0.0, 1.0, 0.0,
2826 1.0, 0.0, 0.1, 0.0, 1.0, 0.0,
2828 0.0, 0.0, 0.1, 0.0, 0.0, 1.0, /* upper right */
2829 1.0, 0.0, 0.1, 0.0, 0.0, 1.0,
2830 0.0, 1.0, 0.1, 0.0, 0.0, 1.0,
2831 1.0, 1.0, 0.1, 0.0, 0.0, 1.0,
2833 -1.0, 0.0, 0.1, -1.0, 0.0, 0.0, /* Upper left */
2834 0.0, 0.0, 0.1, -1.0, 0.0, 0.0,
2835 -1.0, 1.0, 0.1, -1.0, 0.0, 0.0,
2836 0.0, 1.0, 0.1, -1.0, 0.0, 0.0,
2839 memset(&DDBltFx
, 0, sizeof(DDBltFx
));
2840 DDBltFx
.dwSize
= sizeof(DDBltFx
);
2842 memset(&d3dcaps
, 0, sizeof(d3dcaps
));
2843 hr
= IDirect3DDevice7_GetCaps(device
, &d3dcaps
);
2844 ok(hr
== D3D_OK
, "IDirect3DDevice7_GetCaps returned %08x\n", hr
);
2845 if(!(d3dcaps
.dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_CUBEMAP
))
2847 skip("No cubemap support\n");
2851 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff000000, 0.0, 0);
2852 ok(hr
== D3D_OK
, "IDirect3DDevice7_Clear failed with %08x\n", hr
);
2854 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
2855 ok(hr
== D3D_OK
, "IDirect3DDevice7_GetDirect3D returned %08x\n", hr
);
2856 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **) &ddraw
);
2857 ok(hr
== D3D_OK
, "IDirect3D7_QueryInterface returned %08x\n", hr
);
2858 IDirect3D7_Release(d3d
);
2861 memset(&ddsd
, 0, sizeof(ddsd
));
2862 ddsd
.dwSize
= sizeof(ddsd
);
2863 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
2864 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
;
2867 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
;
2868 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
| DDSCAPS2_TEXTUREMANAGE
;
2869 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
2870 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
2871 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00FF0000;
2872 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000FF00;
2873 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000FF;
2875 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &cubemap
, NULL
);
2876 ok(hr
== DD_OK
, "IDirectDraw7_CreateSurface returned %08x\n", hr
);
2877 IDirectDraw7_Release(ddraw
);
2880 U5(DDBltFx
).dwFillColor
= 0x00ff0000;
2881 hr
= IDirectDrawSurface7_Blt(cubemap
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
, &DDBltFx
);
2882 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
2884 memset(&caps
, 0, sizeof(caps
));
2885 caps
.dwCaps
= DDSCAPS_TEXTURE
;
2886 caps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_NEGATIVEX
;
2887 hr
= IDirectDrawSurface_GetAttachedSurface(cubemap
, &caps
, &surface
);
2888 ok(hr
== DD_OK
, "IDirectDrawSurface7_Lock returned %08x\n", hr
);
2889 U5(DDBltFx
).dwFillColor
= 0x0000ffff;
2890 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
, &DDBltFx
);
2891 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
2893 caps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_NEGATIVEZ
;
2894 hr
= IDirectDrawSurface_GetAttachedSurface(cubemap
, &caps
, &surface
);
2895 ok(hr
== DD_OK
, "IDirectDrawSurface7_Lock returned %08x\n", hr
);
2896 U5(DDBltFx
).dwFillColor
= 0x0000ff00;
2897 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
, &DDBltFx
);
2898 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
2900 caps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_POSITIVEZ
;
2901 hr
= IDirectDrawSurface_GetAttachedSurface(cubemap
, &caps
, &surface
);
2902 ok(hr
== DD_OK
, "IDirectDrawSurface7_Lock returned %08x\n", hr
);
2903 U5(DDBltFx
).dwFillColor
= 0x000000ff;
2904 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
, &DDBltFx
);
2905 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
2907 caps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_NEGATIVEY
;
2908 hr
= IDirectDrawSurface_GetAttachedSurface(cubemap
, &caps
, &surface
);
2909 ok(hr
== DD_OK
, "IDirectDrawSurface7_Lock returned %08x\n", hr
);
2910 U5(DDBltFx
).dwFillColor
= 0x00ffff00;
2911 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
, &DDBltFx
);
2912 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
2914 caps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_POSITIVEY
;
2915 hr
= IDirectDrawSurface_GetAttachedSurface(cubemap
, &caps
, &surface
);
2916 ok(hr
== DD_OK
, "IDirectDrawSurface7_Lock returned %08x\n", hr
);
2917 U5(DDBltFx
).dwFillColor
= 0x00ff00ff;
2918 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
, &DDBltFx
);
2919 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
2921 hr
= IDirect3DDevice7_SetTexture(device
, 0, cubemap
);
2922 ok(hr
== DD_OK
, "IDirect3DDevice7_SetTexture returned %08x\n", hr
);
2923 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
2924 ok(hr
== DD_OK
, "IDirect3DDevice7_SetTextureStageState returned %08x\n", hr
);
2925 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
2926 ok(hr
== DD_OK
, "IDirect3DDevice7_SetTextureStageState returned %08x\n", hr
);
2928 hr
= IDirect3DDevice7_BeginScene(device
);
2929 ok(hr
== DD_OK
, "IDirect3DDevice7_BeginScene returned %08x\n", hr
);
2932 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1
, quad
+ 0 * 6, 4, 0);
2933 if (hr
== DDERR_UNSUPPORTED
|| hr
== DDERR_NODIRECTDRAWHW
)
2936 win_skip("IDirect3DDevice7_DrawPrimitive is not completely implemented, colors won't be tested\n");
2937 hr
= IDirect3DDevice7_EndScene(device
);
2938 ok(hr
== DD_OK
, "IDirect3DDevice7_EndScene returned %08x\n", hr
);
2941 ok(hr
== DD_OK
, "IDirect3DDevice7_DrawPrimitive returned %08x\n", hr
);
2942 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1
, quad
+ 4 * 6, 4, 0);
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
+ 8 * 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
+ 12* 6, 4, 0);
2947 ok(hr
== DD_OK
, "IDirect3DDevice7_DrawPrimitive returned %08x\n", hr
);
2949 hr
= IDirect3DDevice7_EndScene(device
);
2950 ok(hr
== DD_OK
, "IDirect3DDevice7_EndScene returned %08x\n", hr
);
2952 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
2953 ok(hr
== DD_OK
, "IDirect3DDevice7_SetTextureStageState returned %08x\n", hr
);
2955 color
= getPixelColor(device
, 160, 360); /* lower left quad - positivex */
2956 ok(color
== 0x00ff0000, "DDSCAPS2_CUBEMAP_POSITIVEX has color 0x%08x, expected 0x00ff0000\n", color
);
2957 color
= getPixelColor(device
, 160, 120); /* upper left quad - negativex */
2958 ok(color
== 0x0000ffff, "DDSCAPS2_CUBEMAP_NEGATIVEX has color 0x%08x, expected 0x0000ffff\n", color
);
2959 color
= getPixelColor(device
, 480, 360); /* lower right quad - positivey */
2960 ok(color
== 0x00ff00ff, "DDSCAPS2_CUBEMAP_POSITIVEY has color 0x%08x, expected 0x00ff00ff\n", color
);
2961 color
= getPixelColor(device
, 480, 120); /* upper right quad - positivez */
2962 ok(color
== 0x000000ff, "DDSCAPS2_CUBEMAP_POSITIVEZ has color 0x%08x, expected 0x000000ff\n", color
);
2965 hr
= IDirect3DDevice7_SetTexture(device
, 0, NULL
);
2966 ok(hr
== DD_OK
, "IDirect3DDevice7_SetTexture returned %08x\n", hr
);
2967 IDirectDrawSurface7_Release(cubemap
);
2970 /* This test tests depth clamping / clipping behaviour:
2971 * - With software vertex processing, depth values are clamped to the
2972 * minimum / maximum z value when D3DRS_CLIPPING is disabled, and clipped
2973 * when D3DRS_CLIPPING is enabled. Pretransformed vertices behave the
2974 * same as regular vertices here.
2975 * - With hardware vertex processing, D3DRS_CLIPPING seems to be ignored.
2976 * Normal vertices are always clipped. Pretransformed vertices are
2977 * clipped when D3DPMISCCAPS_CLIPTLVERTS is set, clamped when it isn't.
2978 * - The viewport's MinZ/MaxZ is irrelevant for this.
2980 static void depth_clamp_test(IDirect3DDevice7
*device
)
2984 struct vec4 position
;
2989 {{ 0.0f
, 0.0f
, 5.0f
, 1.0f
}, 0xff002b7f},
2990 {{640.0f
, 0.0f
, 5.0f
, 1.0f
}, 0xff002b7f},
2991 {{ 0.0f
, 480.0f
, 5.0f
, 1.0f
}, 0xff002b7f},
2992 {{640.0f
, 480.0f
, 5.0f
, 1.0f
}, 0xff002b7f},
2996 {{ 0.0f
, 300.0f
, 10.0f
, 1.0f
}, 0xfff9e814},
2997 {{640.0f
, 300.0f
, 10.0f
, 1.0f
}, 0xfff9e814},
2998 {{ 0.0f
, 360.0f
, 10.0f
, 1.0f
}, 0xfff9e814},
2999 {{640.0f
, 360.0f
, 10.0f
, 1.0f
}, 0xfff9e814},
3003 {{112.0f
, 108.0f
, 5.0f
, 1.0f
}, 0xffffffff},
3004 {{208.0f
, 108.0f
, 5.0f
, 1.0f
}, 0xffffffff},
3005 {{112.0f
, 204.0f
, 5.0f
, 1.0f
}, 0xffffffff},
3006 {{208.0f
, 204.0f
, 5.0f
, 1.0f
}, 0xffffffff},
3010 {{ 42.0f
, 41.0f
, 10.0f
, 1.0f
}, 0xffffffff},
3011 {{112.0f
, 41.0f
, 10.0f
, 1.0f
}, 0xffffffff},
3012 {{ 42.0f
, 108.0f
, 10.0f
, 1.0f
}, 0xffffffff},
3013 {{112.0f
, 108.0f
, 10.0f
, 1.0f
}, 0xffffffff},
3017 struct vec3 position
;
3022 {{-0.5f
, 0.5f
, 10.0f
}, 0xff14f914},
3023 {{ 0.5f
, 0.5f
, 10.0f
}, 0xff14f914},
3024 {{-0.5f
, -0.5f
, 10.0f
}, 0xff14f914},
3025 {{ 0.5f
, -0.5f
, 10.0f
}, 0xff14f914},
3029 {{-1.0f
, 0.5f
, 10.0f
}, 0xfff91414},
3030 {{ 1.0f
, 0.5f
, 10.0f
}, 0xfff91414},
3031 {{-1.0f
, 0.25f
, 10.0f
}, 0xfff91414},
3032 {{ 1.0f
, 0.25f
, 10.0f
}, 0xfff91414},
3046 hr
= IDirect3DDevice7_SetViewport(device
, &vp
);
3047 ok(SUCCEEDED(hr
), "SetViewport failed, hr %#x.\n", hr
);
3049 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff00ff00, 1.0, 0);
3050 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
3052 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
3053 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
3054 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
3055 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
3056 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZWRITEENABLE
, TRUE
);
3057 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
3058 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZFUNC
, D3DCMP_LESSEQUAL
);
3059 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
3061 hr
= IDirect3DDevice7_BeginScene(device
);
3062 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
3064 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, quad1
, 4, 0);
3065 ok(SUCCEEDED(hr
), "DrawPrimitive failed, hr %#x.\n", hr
);
3066 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, quad2
, 4, 0);
3067 ok(SUCCEEDED(hr
), "DrawPrimitive failed, hr %#x.\n", hr
);
3069 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, TRUE
);
3070 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
3072 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, quad3
, 4, 0);
3073 ok(SUCCEEDED(hr
), "DrawPrimitive failed, hr %#x.\n", hr
);
3074 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, quad4
, 4, 0);
3075 ok(SUCCEEDED(hr
), "DrawPrimitive failed, hr %#x.\n", hr
);
3077 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
3078 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
3080 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad5
, 4, 0);
3081 ok(SUCCEEDED(hr
), "DrawPrimitive failed, hr %#x.\n", hr
);
3083 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, TRUE
);
3084 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
3086 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad6
, 4, 0);
3087 ok(SUCCEEDED(hr
), "DrawPrimitive failed, hr %#x.\n", hr
);
3089 hr
= IDirect3DDevice7_EndScene(device
);
3090 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
3092 color
= getPixelColor(device
, 75, 75);
3093 ok(color_match(color
, 0x00ffffff, 1) || color_match(color
, 0x0000ff00, 1), "color 0x%08x.\n", color
);
3094 color
= getPixelColor(device
, 150, 150);
3095 ok(color_match(color
, 0x00ffffff, 1) || color_match(color
, 0x0000ff00, 1), "color 0x%08x.\n", color
);
3096 color
= getPixelColor(device
, 320, 240);
3097 ok(color_match(color
, 0x00002b7f, 1) || color_match(color
, 0x0000ff00, 1), "color 0x%08x.\n", color
);
3098 color
= getPixelColor(device
, 320, 330);
3099 ok(color_match(color
, 0x00f9e814, 1) || color_match(color
, 0x0000ff00, 1), "color 0x%08x.\n", color
);
3100 color
= getPixelColor(device
, 320, 330);
3101 ok(color_match(color
, 0x00f9e814, 1) || color_match(color
, 0x0000ff00, 1), "color 0x%08x.\n", color
);
3105 hr
= IDirect3DDevice7_SetViewport(device
, &vp
);
3106 ok(SUCCEEDED(hr
), "SetViewport failed, hr %#x.\n", hr
);
3109 static void DX1_BackBufferFlipTest(void)
3112 IDirectDraw
*DirectDraw1
= NULL
;
3113 IDirectDrawSurface
*Primary
= NULL
;
3114 IDirectDrawSurface
*Backbuffer
= NULL
;
3119 const DWORD white
= 0xffffff;
3120 const DWORD red
= 0xff0000;
3121 BOOL attached
= FALSE
;
3123 wc
.lpfnWndProc
= DefWindowProcA
;
3124 wc
.lpszClassName
= "DX1_BackBufferFlipTest_wc";
3125 RegisterClassA(&wc
);
3126 window
= CreateWindowA("DX1_BackBufferFlipTest_wc", "DX1_BackBufferFlipTest",
3127 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
3129 hr
= DirectDrawCreate( NULL
, &DirectDraw1
, NULL
);
3130 ok(hr
==DD_OK
|| hr
==DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreate returned: %x\n", hr
);
3131 if(FAILED(hr
)) goto out
;
3133 hr
= IDirectDraw_SetCooperativeLevel(DirectDraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3134 ok(hr
==DD_OK
, "SetCooperativeLevel returned: %x\n", hr
);
3135 if(FAILED(hr
)) goto out
;
3137 hr
= IDirectDraw_SetDisplayMode(DirectDraw1
, 640, 480, 32);
3139 /* 24 bit is fine too */
3140 hr
= IDirectDraw_SetDisplayMode(DirectDraw1
, 640, 480, 24);
3142 ok(hr
==DD_OK
|| hr
== DDERR_UNSUPPORTED
, "SetDisplayMode returned: %x\n", hr
);
3147 memset(&ddsd
, 0, sizeof(DDSURFACEDESC
));
3148 ddsd
.dwSize
= sizeof(DDSURFACEDESC
);
3149 ddsd
.dwFlags
= DDSD_CAPS
;
3150 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3152 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &Primary
, NULL
);
3153 ok(hr
==DD_OK
, "IDirectDraw_CreateSurface returned: %08x\n", hr
);
3155 memset(&ddsd
, 0, sizeof(DDSURFACEDESC
));
3156 ddsd
.dwSize
= sizeof(DDSURFACEDESC
);
3157 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
3158 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_BACKBUFFER
;
3160 ddsd
.dwHeight
= 480;
3161 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
3162 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
3163 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
3164 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
3165 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
3166 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
3168 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &Backbuffer
, NULL
);
3169 ok(hr
==DD_OK
, "IDirectDraw_CreateSurface returned: %08x\n", hr
);
3170 if(FAILED(hr
)) goto out
;
3172 hr
= IDirectDrawSurface_AddAttachedSurface(Primary
, Backbuffer
);
3173 todo_wine
ok(hr
== DD_OK
|| broken(hr
== DDERR_CANNOTATTACHSURFACE
),
3174 "Attaching a back buffer to a front buffer returned %08x\n", hr
);
3175 if (FAILED(hr
)) goto out
;
3179 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
3180 ddbltfx
.dwSize
= sizeof(ddbltfx
);
3181 U5(ddbltfx
).dwFillColor
= red
;
3182 hr
= IDirectDrawSurface_Blt(Backbuffer
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
3183 ok(hr
== DD_OK
, "IDirectDrawSurface_Blt returned: %x\n", hr
);
3185 U5(ddbltfx
).dwFillColor
= white
;
3186 hr
= IDirectDrawSurface_Blt(Primary
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
3187 ok(hr
== DD_OK
, "IDirectDrawSurface_Blt returned: %x\n", hr
);
3190 color
= getPixelColor_GDI(Primary
, 5, 5);
3191 ok(GetRValue(color
) == 0xFF && GetGValue(color
) == 0xFF && GetBValue(color
) == 0xFF,
3192 "got R %02X G %02X B %02X, expected R FF G FF B FF\n",
3193 GetRValue(color
), GetGValue(color
), GetBValue(color
));
3195 color
= getPixelColor_GDI(Backbuffer
, 5, 5);
3196 ok(GetRValue(color
) == 0xFF && GetGValue(color
) == 0 && GetBValue(color
) == 0,
3197 "got R %02X G %02X B %02X, expected R FF G 00 B 00\n",
3198 GetRValue(color
), GetGValue(color
), GetBValue(color
));
3200 hr
= IDirectDrawSurface_Flip(Primary
, NULL
, DDFLIP_WAIT
);
3201 todo_wine
ok(hr
== DD_OK
, "IDirectDrawSurface_Flip returned 0x%08x\n", hr
);
3205 color
= getPixelColor_GDI(Primary
, 5, 5);
3206 ok(GetRValue(color
) == 0xFF && GetGValue(color
) == 0 && GetBValue(color
) == 0,
3207 "got R %02X G %02X B %02X, expected R FF G 00 B 00\n",
3208 GetRValue(color
), GetGValue(color
), GetBValue(color
));
3210 color
= getPixelColor_GDI(Backbuffer
, 5, 5);
3211 ok((GetRValue(color
) == 0xFF && GetGValue(color
) == 0xFF && GetBValue(color
) == 0xFF) ||
3212 broken(GetRValue(color
) == 0xFF && GetGValue(color
) == 0 && GetBValue(color
) == 0), /* broken driver */
3213 "got R %02X G %02X B %02X, expected R FF G FF B FF\n",
3214 GetRValue(color
), GetGValue(color
), GetBValue(color
));
3222 IDirectDrawSurface_DeleteAttachedSurface(Primary
, 0, Backbuffer
);
3223 IDirectDrawSurface_Release(Backbuffer
);
3225 if (Primary
) IDirectDrawSurface_Release(Primary
);
3226 if (DirectDraw1
) IDirectDraw_Release(DirectDraw1
);
3227 if (window
) DestroyWindow(window
);
3234 if(!createObjects())
3236 skip("Cannot initialize DirectDraw and Direct3D, skipping\n");
3240 /* Check for the reliability of the returned data */
3241 hr
= IDirect3DDevice7_Clear(Direct3DDevice
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
3244 skip("Clear failed, can't assure correctness of the test results, skipping\n");
3248 color
= getPixelColor(Direct3DDevice
, 1, 1);
3249 if(color
!=0x00ff0000)
3251 skip("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests, skipping\n", color
);
3255 hr
= IDirect3DDevice7_Clear(Direct3DDevice
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ddee, 0.0, 0);
3258 skip("Clear failed, can't assure correctness of the test results, skipping\n");
3262 color
= getPixelColor(Direct3DDevice
, 639, 479);
3263 if(color
!= 0x0000ddee)
3265 skip("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests, skipping\n", color
);
3269 /* Now run the tests */
3270 blt_test(Direct3DDevice
);
3271 depth_clamp_test(Direct3DDevice
);
3272 lighting_test(Direct3DDevice
);
3273 clear_test(Direct3DDevice
);
3274 fog_test(Direct3DDevice
);
3275 offscreen_test(Direct3DDevice
);
3276 alpha_test(Direct3DDevice
);
3277 rhw_zero_test(Direct3DDevice
);
3278 cubemap_test(Direct3DDevice
);
3280 releaseObjects(); /* release DX7 interfaces to test D3D1 */
3282 if(!D3D1_createObjects()) {
3283 skip("Cannot initialize D3D1, skipping\n");
3286 D3D1_TextureMapBlendTest();
3287 D3D1_ViewportClearTest();
3289 D3D1_releaseObjects();
3291 D3D3_ViewportClearTest();
3293 DX1_BackBufferFlipTest();