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
);
449 static void fog_test(IDirect3DDevice7
*device
)
453 float start
= 0.0, end
= 1.0;
458 struct vec3 position
;
462 /* Gets full z based fog with linear fog, no fog with specular color */
465 {{-1.0f
, -1.0f
, 0.1f
}, 0xffff0000, 0xff000000},
466 {{-1.0f
, 0.0f
, 0.1f
}, 0xffff0000, 0xff000000},
467 {{ 0.0f
, 0.0f
, 0.1f
}, 0xffff0000, 0xff000000},
468 {{ 0.0f
, -1.0f
, 0.1f
}, 0xffff0000, 0xff000000},
470 /* Ok, I am too lazy to deal with transform matrices */
473 {{-1.0f
, 0.0f
, 1.0f
}, 0xffff0000, 0xff000000},
474 {{-1.0f
, 1.0f
, 1.0f
}, 0xffff0000, 0xff000000},
475 {{ 0.0f
, 1.0f
, 1.0f
}, 0xffff0000, 0xff000000},
476 {{ 0.0f
, 0.0f
, 1.0f
}, 0xffff0000, 0xff000000},
480 {{-1.0f
, -1.0f
, 0.5f
}, 0xffff0000, 0xff000000},
481 {{-1.0f
, 0.0f
, 0.5f
}, 0xffff0000, 0xff000000},
482 {{ 0.0f
, 0.0f
, 0.5f
}, 0xffff0000, 0xff000000},
483 {{ 0.0f
, -1.0f
, 0.5f
}, 0xffff0000, 0xff000000},
487 {{-1.0f
, 0.0f
, 1.5f
}, 0xffff0000, 0xff000000},
488 {{-1.0f
, 1.0f
, 1.5f
}, 0xffff0000, 0xff000000},
489 {{ 0.0f
, 1.0f
, 1.5f
}, 0xffff0000, 0xff000000},
490 {{ 0.0f
, 0.0f
, 1.5f
}, 0xffff0000, 0xff000000},
492 /* Untransformed ones. Give them a different diffuse color to make the
493 * test look nicer. It also helps making sure that they are drawn
497 struct vec4 position
;
503 {{320.0f
, 0.0f
, 1.0f
, 1.0f
}, 0xffffff00, 0xff000000},
504 {{640.0f
, 0.0f
, 1.0f
, 1.0f
}, 0xffffff00, 0xff000000},
505 {{640.0f
, 240.0f
, 1.0f
, 1.0f
}, 0xffffff00, 0xff000000},
506 {{320.0f
, 240.0f
, 1.0f
, 1.0f
}, 0xffffff00, 0xff000000},
510 {{320.0f
, 240.0f
, 1.0f
, 1.0f
}, 0xffffff00, 0xff000000},
511 {{640.0f
, 240.0f
, 1.0f
, 1.0f
}, 0xffffff00, 0xff000000},
512 {{640.0f
, 480.0f
, 1.0f
, 1.0f
}, 0xffffff00, 0xff000000},
513 {{320.0f
, 480.0f
, 1.0f
, 1.0f
}, 0xffffff00, 0xff000000},
515 WORD Indices
[] = {0, 1, 2, 2, 3, 0};
516 D3DMATRIX ident_mat
=
518 1.0f
, 0.0f
, 0.0f
, 0.0f
,
519 0.0f
, 1.0f
, 0.0f
, 0.0f
,
520 0.0f
, 0.0f
, 1.0f
, 0.0f
,
521 0.0f
, 0.0f
, 0.0f
, 1.0f
,
523 D3DMATRIX world_mat1
=
525 1.0f
, 0.0f
, 0.0f
, 0.0f
,
526 0.0f
, 1.0f
, 0.0f
, 0.0f
,
527 0.0f
, 0.0f
, 1.0f
, 0.0f
,
528 0.0f
, 0.0f
, -0.5f
, 1.0f
,
530 D3DMATRIX world_mat2
=
532 1.0f
, 0.0f
, 0.0f
, 0.0f
,
533 0.0f
, 1.0f
, 0.0f
, 0.0f
,
534 0.0f
, 0.0f
, 1.0f
, 0.0f
,
535 0.0f
, 0.0f
, 1.0f
, 1.0f
,
539 1.0f
, 0.0f
, 0.0f
, 0.0f
,
540 0.0f
, 1.0f
, 0.0f
, 0.0f
,
541 0.0f
, 0.0f
, 1.0f
, 0.0f
,
542 0.0f
, 0.0f
, -1.0f
, 1.0f
,
545 memset(&caps
, 0, sizeof(caps
));
546 hr
= IDirect3DDevice7_GetCaps(device
, &caps
);
547 ok(hr
== D3D_OK
, "IDirect3DDevice7_GetCaps returned %08x\n", hr
);
548 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
549 ok(hr
== D3D_OK
, "IDirect3DDevice7_Clear returned %08x\n", hr
);
551 /* Setup initial states: No lighting, fog on, fog color */
552 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
553 ok(hr
== D3D_OK
, "Turning off lighting returned %08x\n", hr
);
554 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, TRUE
);
555 ok(hr
== D3D_OK
, "Turning on fog calculations returned %08x\n", hr
);
556 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGCOLOR
, 0xFF00FF00 /* A nice green */);
557 ok(hr
== D3D_OK
, "Setting fog color returned %08x\n", hr
);
559 /* First test: Both table fog and vertex fog off */
560 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, D3DFOG_NONE
);
561 ok(hr
== D3D_OK
, "Turning off table fog returned %08x\n", hr
);
562 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGVERTEXMODE
, D3DFOG_NONE
);
563 ok(hr
== D3D_OK
, "Turning off vertex fog returned %08x\n", hr
);
565 /* Start = 0, end = 1. Should be default, but set them */
566 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGSTART
, *((DWORD
*) &start
));
567 ok(hr
== D3D_OK
, "Setting fog start returned %08x\n", hr
);
568 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGEND
, *((DWORD
*) &end
));
569 ok(hr
== D3D_OK
, "Setting fog end returned %08x\n", hr
);
571 if(IDirect3DDevice7_BeginScene(device
) == D3D_OK
)
573 /* Untransformed, vertex fog = NONE, table fog = NONE: Read the fog weighting from the specular color */
574 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
,
575 untransformed_1
, 4, Indices
, 6, 0);
576 ok(hr
== D3D_OK
, "DrawIndexedPrimitive returned %08x\n", hr
);
578 /* That makes it use the Z value */
579 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGVERTEXMODE
, D3DFOG_LINEAR
);
580 ok(hr
== D3D_OK
, "Setting fog vertex mode to D3DFOG_LINEAR returned %08x\n", hr
);
581 /* Untransformed, vertex fog != none (or table fog != none):
582 * Use the Z value as input into the equation
584 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
,
585 untransformed_2
, 4, Indices
, 6, 0);
586 ok(hr
== D3D_OK
, "DrawIndexedPrimitive returned %08x\n", hr
);
588 /* Transformed, vertex fog != NONE, pixel fog == NONE: Use specular color alpha component */
589 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
,
590 transformed_1
, 4, Indices
, 6, 0);
591 ok(hr
== D3D_OK
, "DrawIndexedPrimitive returned %08x\n", hr
);
593 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, D3DFOG_LINEAR
);
594 ok( hr
== D3D_OK
, "Setting fog table mode to D3DFOG_LINEAR returned %08x\n", hr
);
595 /* Transformed, table fog != none, vertex anything: Use Z value as input to the fog
598 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
,
599 transformed_2
, 4, Indices
, 6, 0);
600 ok(hr
== D3D_OK
, "DrawIndexedPrimitive returned %08x\n", hr
);
602 hr
= IDirect3DDevice7_EndScene(device
);
603 ok(hr
== D3D_OK
, "EndScene returned %08x\n", hr
);
607 ok(FALSE
, "BeginScene failed\n");
610 color
= getPixelColor(device
, 160, 360);
611 ok(color_match(color
, 0x00FF0000, 1), "Untransformed vertex with no table or vertex fog has color %08x\n", color
);
612 color
= getPixelColor(device
, 160, 120);
613 ok(color_match(color
, 0x0000FF00, 1), "Untransformed vertex with linear vertex fog has color %08x\n", color
);
614 color
= getPixelColor(device
, 480, 120);
615 ok(color_match(color
, 0x00FFFF00, 1), "Transformed vertex with linear vertex fog has color %08x\n", color
);
616 if(caps
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_FOGTABLE
)
618 color
= getPixelColor(device
, 480, 360);
619 ok(color_match(color
, 0x0000FF00, 1), "Transformed vertex with linear table fog has color %08x\n", color
);
623 /* Without fog table support the vertex fog is still applied, even though table fog is turned on.
624 * The settings above result in no fogging with vertex fog
626 color
= getPixelColor(device
, 480, 120);
627 ok(color
== 0x00FFFF00, "Transformed vertex with linear vertex fog has color %08x\n", color
);
628 trace("Info: Table fog not supported by this device\n");
631 if (caps
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_FOGTABLE
)
633 /* A simple fog + non-identity world matrix test */
634 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &world_mat1
);
635 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetTransform returned %#08x\n", hr
);
637 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, D3DFOG_LINEAR
);
638 ok(hr
== D3D_OK
, "Setting fog table mode to D3DFOG_LINEAR returned %#08x\n", hr
);
639 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGVERTEXMODE
, D3DFOG_NONE
);
640 ok(hr
== D3D_OK
, "Turning off vertex fog returned %#08x\n", hr
);
642 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
643 ok(hr
== D3D_OK
, "IDirect3DDevice7_Clear returned %#08x\n", hr
);
645 if (IDirect3DDevice7_BeginScene(device
) == D3D_OK
)
647 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
,
648 D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
, far_quad1
, 4, Indices
, 6, 0);
649 ok(hr
== D3D_OK
, "DrawIndexedPrimitive returned %#08x\n", hr
);
651 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
,
652 D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
, far_quad2
, 4, Indices
, 6, 0);
653 ok(hr
== D3D_OK
, "DrawIndexedPrimitive returned %#08x\n", hr
);
655 hr
= IDirect3DDevice7_EndScene(device
);
656 ok(hr
== D3D_OK
, "EndScene returned %#08x\n", hr
);
660 ok(FALSE
, "BeginScene failed\n");
663 color
= getPixelColor(device
, 160, 360);
664 ok(color_match(color
, 0x00ff0000, 4), "Unfogged quad has color %08x\n", color
);
665 color
= getPixelColor(device
, 160, 120);
666 ok(color_match(color
, 0x0000ff00, 1), "Fogged out quad has color %08x\n", color
);
668 /* Test fog behavior with an orthogonal (but not identity) projection matrix */
669 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &world_mat2
);
670 ok(hr
== D3D_OK
, "SetTransform returned %#08x\n", hr
);
671 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &proj_mat
);
672 ok(hr
== D3D_OK
, "SetTransform returned %#08x\n", hr
);
674 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
675 ok(hr
== D3D_OK
, "Clear returned %#08x\n", hr
);
677 if (IDirect3DDevice7_BeginScene(device
) == D3D_OK
)
679 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
,
680 D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
, untransformed_1
, 4, Indices
, 6, 0);
681 ok(hr
== D3D_OK
, "DrawIndexedPrimitiveUP returned %#08x\n", hr
);
683 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
,
684 D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
, untransformed_2
, 4, Indices
, 6, 0);
685 ok(hr
== D3D_OK
, "DrawIndexedPrimitiveUP returned %#08x\n", hr
);
687 hr
= IDirect3DDevice7_EndScene(device
);
688 ok(hr
== D3D_OK
, "EndScene returned %#08x\n", hr
);
692 ok(FALSE
, "BeginScene failed\n");
695 color
= getPixelColor(device
, 160, 360);
696 ok(color_match(color
, 0x00e51900, 4), "Partially fogged quad has color %08x\n", color
);
697 color
= getPixelColor(device
, 160, 120);
698 ok(color_match(color
, 0x0000ff00, 1), "Fogged out quad has color %08x\n", color
);
700 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &ident_mat
);
701 ok(hr
== D3D_OK
, "SetTransform returned %#08x\n", hr
);
702 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &ident_mat
);
703 ok(hr
== D3D_OK
, "SetTransform returned %#08x\n", hr
);
707 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests\n");
710 /* Turn off the fog master switch to avoid confusing other tests */
711 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
712 ok(hr
== D3D_OK
, "Turning off fog calculations returned %08x\n", hr
);
715 static void blt_test(IDirect3DDevice7
*device
)
717 IDirectDrawSurface7
*backbuffer
= NULL
, *offscreen
= NULL
;
721 memset(&ddsd
, 0, sizeof(ddsd
));
722 ddsd
.dwSize
= sizeof(ddsd
);
723 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
724 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
727 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_3DDEVICE
;
728 hr
= IDirectDraw7_CreateSurface(DirectDraw
, &ddsd
, &offscreen
, NULL
);
729 ok(hr
== D3D_OK
, "Creating the offscreen render target failed, hr = %08x\n", hr
);
731 /* Offscreen blits with the same source as destination */
734 RECT src_rect
, dst_rect
;
736 /* Blit the whole surface to itself */
737 hr
= IDirectDrawSurface_Blt(offscreen
, NULL
, offscreen
, NULL
, 0, NULL
);
738 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
740 /* Overlapped blit */
741 dst_rect
.left
= 0; dst_rect
.right
= 480;
742 dst_rect
.top
= 0; dst_rect
.bottom
= 480;
743 src_rect
.left
= 160; src_rect
.right
= 640;
744 src_rect
.top
= 0; src_rect
.bottom
= 480;
745 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, offscreen
, &src_rect
, 0, NULL
);
746 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
748 /* Overlapped blit, flip-y through source rectangle (not allowed) */
749 dst_rect
.left
= 0; dst_rect
.right
= 480;
750 dst_rect
.top
= 0; dst_rect
.bottom
= 480;
751 src_rect
.left
= 160; src_rect
.right
= 640;
752 src_rect
.top
= 480; src_rect
.bottom
= 0;
753 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, offscreen
, &src_rect
, 0, NULL
);
754 ok(hr
== DDERR_INVALIDRECT
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
756 /* Overlapped blit, with shrinking in x */
757 dst_rect
.left
= 0; dst_rect
.right
= 480;
758 dst_rect
.top
= 0; dst_rect
.bottom
= 480;
759 src_rect
.left
= 160; src_rect
.right
= 480;
760 src_rect
.top
= 0; src_rect
.bottom
= 480;
761 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, offscreen
, &src_rect
, 0, NULL
);
762 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
765 hr
= IDirect3DDevice7_GetRenderTarget(device
, &backbuffer
);
766 ok(hr
== D3D_OK
, "Unable to obtain a surface pointer to the backbuffer, hr = %08x\n", hr
);
768 /* backbuffer ==> texture blits */
769 if(SUCCEEDED(hr
) && offscreen
)
771 RECT src_rect
, dst_rect
;
773 /* backbuffer ==> texture, src_rect=NULL, dst_rect=NULL, no scaling */
774 hr
= IDirectDrawSurface_Blt(offscreen
, NULL
, backbuffer
, NULL
, 0, NULL
);
775 ok(hr
== DD_OK
, "fullscreen Blt from backbuffer => texture failed with hr = %08x\n", hr
);
777 /* backbuffer ==> texture, full surface blits, no scaling */
778 dst_rect
.left
= 0; dst_rect
.right
= 640;
779 dst_rect
.top
= 0; dst_rect
.bottom
= 480;
780 src_rect
.left
= 0; src_rect
.right
= 640;
781 src_rect
.top
= 0; src_rect
.bottom
= 480;
782 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, backbuffer
, &src_rect
, 0, NULL
);
783 ok(hr
== DD_OK
, "fullscreen Blt from backbuffer => texture failed with hr = %08x\n", hr
);
785 /* backbuffer ==> texture, flip in y-direction through source rectangle, no scaling (allowed) */
786 dst_rect
.left
= 0; dst_rect
.right
= 640;
787 dst_rect
.top
= 480; dst_rect
.top
= 0;
788 src_rect
.left
= 0; src_rect
.right
= 640;
789 src_rect
.top
= 0; src_rect
.bottom
= 480;
790 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, backbuffer
, &src_rect
, 0, NULL
);
791 ok(hr
== DD_OK
, "backbuffer => texture flip-y src_rect failed with hr = %08x\n", hr
);
793 /* backbuffer ==> texture, flip in x-direction through source rectangle, no scaling (not allowed) */
794 dst_rect
.left
= 640; dst_rect
.right
= 0;
795 dst_rect
.top
= 0; dst_rect
.top
= 480;
796 src_rect
.left
= 0; src_rect
.right
= 640;
797 src_rect
.top
= 0; src_rect
.bottom
= 480;
798 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, backbuffer
, &src_rect
, 0, NULL
);
799 ok(hr
== DDERR_INVALIDRECT
, "backbuffer => texture flip-x src_rect failed with hr = %08x\n", hr
);
801 /* backbuffer ==> texture, flip in y-direction through destination rectangle (not allowed) */
802 dst_rect
.left
= 0; dst_rect
.right
= 640;
803 dst_rect
.top
= 0; dst_rect
.top
= 480;
804 src_rect
.left
= 0; src_rect
.right
= 640;
805 src_rect
.top
= 480; src_rect
.bottom
= 0;
806 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, backbuffer
, &src_rect
, 0, NULL
);
807 ok(hr
== DDERR_INVALIDRECT
, "backbuffer => texture flip-y dst_rect failed with hr = %08x\n", hr
);
809 /* backbuffer ==> texture, flip in x-direction through destination rectangle, no scaling (not allowed) */
810 dst_rect
.left
= 0; dst_rect
.right
= 640;
811 dst_rect
.top
= 0; dst_rect
.top
= 480;
812 src_rect
.left
= 640; src_rect
.right
= 0;
813 src_rect
.top
= 0; src_rect
.bottom
= 480;
814 hr
= IDirectDrawSurface_Blt(offscreen
, &dst_rect
, backbuffer
, &src_rect
, 0, NULL
);
815 ok(hr
== DDERR_INVALIDRECT
, "backbuffer => texture flip-x dst_rect failed with hr = %08x\n", hr
);
818 if(offscreen
) IDirectDrawSurface7_Release(offscreen
);
819 if(backbuffer
) IDirectDrawSurface7_Release(backbuffer
);
822 static void offscreen_test(IDirect3DDevice7
*device
)
825 IDirectDrawSurface7
*backbuffer
= NULL
, *offscreen
= NULL
;
829 static float quad
[][5] = {
830 {-0.5f
, -0.5f
, 0.1f
, 0.0f
, 0.0f
},
831 {-0.5f
, 0.5f
, 0.1f
, 0.0f
, 1.0f
},
832 { 0.5f
, -0.5f
, 0.1f
, 1.0f
, 0.0f
},
833 { 0.5f
, 0.5f
, 0.1f
, 1.0f
, 1.0f
},
836 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
837 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
839 memset(&ddsd
, 0, sizeof(ddsd
));
840 ddsd
.dwSize
= sizeof(ddsd
);
841 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
842 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
845 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_3DDEVICE
;
846 hr
= IDirectDraw7_CreateSurface(DirectDraw
, &ddsd
, &offscreen
, NULL
);
847 ok(hr
== D3D_OK
, "Creating the offscreen render target failed, hr = %08x\n", hr
);
852 hr
= IDirect3DDevice7_GetRenderTarget(device
, &backbuffer
);
853 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %08x\n", hr
);
858 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
859 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
860 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
861 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
862 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_MINFILTER
, D3DFILTER_NEAREST
);
863 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MINFILTER failed (0x%08x)\n", hr
);
864 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_MAGFILTER
, D3DFILTER_NEAREST
);
865 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr
);
866 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
867 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState returned hr = %08x\n", hr
);
870 win_skip("Tests would crash on W2K with a refdevice\n");
874 if(IDirect3DDevice7_BeginScene(device
) == D3D_OK
) {
875 hr
= IDirect3DDevice7_SetRenderTarget(device
, offscreen
, 0);
876 ok(hr
== D3D_OK
, "SetRenderTarget failed, hr = %08x\n", hr
);
877 set_viewport_size(device
);
878 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff00ff, 0.0, 0);
879 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
881 /* Draw without textures - Should result in a white quad */
882 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEX1
, quad
, 4, 0);
883 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
885 hr
= IDirect3DDevice7_SetRenderTarget(device
, backbuffer
, 0);
886 ok(hr
== D3D_OK
, "SetRenderTarget failed, hr = %08x\n", hr
);
887 set_viewport_size(device
);
889 hr
= IDirect3DDevice7_SetTexture(device
, 0, offscreen
);
890 ok(hr
== D3D_OK
, "SetTexture failed, %08x\n", hr
);
892 /* This time with the texture */
893 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEX1
, quad
, 4, 0);
894 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
896 IDirect3DDevice7_EndScene(device
);
899 /* Center quad - should be white */
900 color
= getPixelColor(device
, 320, 240);
901 ok(color
== 0x00ffffff, "Offscreen failed: Got color 0x%08x, expected 0x00ffffff.\n", color
);
902 /* Some quad in the cleared part of the texture */
903 color
= getPixelColor(device
, 170, 240);
904 ok(color
== 0x00ff00ff, "Offscreen failed: Got color 0x%08x, expected 0x00ff00ff.\n", color
);
905 /* Part of the originally cleared back buffer */
906 color
= getPixelColor(device
, 10, 10);
907 ok(color
== 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
909 /* Lower left corner of the screen, where back buffer offscreen rendering draws the offscreen texture.
910 * It should be red, but the offscreen texture may leave some junk there. Not tested yet. Depending on
911 * the offscreen rendering mode this test would succeed or fail
913 color
= getPixelColor(device
, 10, 470);
914 ok(color
== 0x00ff0000, "Offscreen failed: Got color 0x%08x, expected 0x00ff0000.\n", color
);
918 hr
= IDirect3DDevice7_SetTexture(device
, 0, NULL
);
919 ok(SUCCEEDED(hr
), "IDirect3DDevice7_SetTexture returned %#x.\n", hr
);
923 hr
= IDirect3DDevice7_SetRenderTarget(device
, backbuffer
, 0);
924 ok(SUCCEEDED(hr
), "IDirect3DDevice7_SetRenderTarget returned %#x.\n", hr
);
925 IDirectDrawSurface7_Release(backbuffer
);
928 IDirectDrawSurface7_Release(offscreen
);
932 static void test_blend(IDirect3DDevice7
*device
)
935 IDirectDrawSurface7
*backbuffer
= NULL
, *offscreen
= NULL
;
936 DWORD color
, red
, green
, blue
;
941 struct vec3 position
;
946 {{-1.0f
, -1.0f
, 0.1f
}, 0x4000ff00},
947 {{-1.0f
, 0.0f
, 0.1f
}, 0x4000ff00},
948 {{ 1.0f
, -1.0f
, 0.1f
}, 0x4000ff00},
949 {{ 1.0f
, 0.0f
, 0.1f
}, 0x4000ff00},
953 {{-1.0f
, 0.0f
, 0.1f
}, 0xc00000ff},
954 {{-1.0f
, 1.0f
, 0.1f
}, 0xc00000ff},
955 {{ 1.0f
, 0.0f
, 0.1f
}, 0xc00000ff},
956 {{ 1.0f
, 1.0f
, 0.1f
}, 0xc00000ff},
958 static float composite_quad
[][5] = {
959 { 0.0f
, -1.0f
, 0.1f
, 0.0f
, 1.0f
},
960 { 0.0f
, 1.0f
, 0.1f
, 0.0f
, 0.0f
},
961 { 1.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
},
962 { 1.0f
, 1.0f
, 0.1f
, 1.0f
, 0.0f
},
965 /* Clear the render target with alpha = 0.5 */
966 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x80ff0000, 0.0, 0);
967 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
969 memset(&ddsd
, 0, sizeof(ddsd
));
970 ddsd
.dwSize
= sizeof(ddsd
);
971 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
974 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_3DDEVICE
;
975 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
976 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
977 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
978 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
979 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
980 U5(U4(ddsd
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
981 hr
= IDirectDraw7_CreateSurface(DirectDraw
, &ddsd
, &offscreen
, NULL
);
982 ok(hr
== D3D_OK
, "Creating the offscreen render target failed, hr = %08x\n", hr
);
986 hr
= IDirect3DDevice7_GetRenderTarget(device
, &backbuffer
);
987 ok(hr
== D3D_OK
, "Can't get back buffer, hr = %08x\n", hr
);
992 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
993 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
994 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
995 ok(hr
== D3D_OK
, "SetTextureStageState failed, hr = %08x\n", hr
);
996 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_MINFILTER
, D3DFILTER_NEAREST
);
997 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MINFILTER failed (0x%08x)\n", hr
);
998 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_MAGFILTER
, D3DFILTER_NEAREST
);
999 ok(SUCCEEDED(hr
), "SetTextureStageState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr
);
1001 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
1002 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1005 win_skip("Tests would crash on W2K with a refdevice\n");
1009 if(IDirect3DDevice7_BeginScene(device
) == D3D_OK
) {
1011 /* Draw two quads, one with src alpha blending, one with dest alpha blending. The
1012 * SRCALPHA / INVSRCALPHA blend doesn't give any surprises. Colors are blended based on
1015 * The DESTALPHA / INVDESTALPHA do not "work" on the regular buffer because there is no alpha.
1016 * They give essentially ZERO and ONE blend factors
1018 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
1019 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1020 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1021 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1022 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad1
, 4, 0);
1023 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
1025 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_DESTALPHA
);
1026 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1027 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVDESTALPHA
);
1028 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1029 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad2
, 4, 0);
1030 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
1032 /* Switch to the offscreen buffer, and redo the testing. SRCALPHA and DESTALPHA. The offscreen buffer
1033 * has an alpha channel on its own. Clear the offscreen buffer with alpha = 0.5 again, then draw the
1034 * quads again. The SRCALPHA/INVSRCALPHA doesn't give any surprises, but the DESTALPHA/INVDESTALPHA
1035 * blending works as supposed now - blend factor is 0.5 in both cases, not 0.75 as from the input
1038 hr
= IDirect3DDevice7_SetRenderTarget(device
, offscreen
, 0);
1039 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderTarget failed, hr = %08x\n", hr
);
1040 set_viewport_size(device
);
1041 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x80ff0000, 0.0, 0);
1042 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
1044 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
1045 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1046 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1047 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1048 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad1
, 4, 0);
1049 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
1051 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_DESTALPHA
);
1052 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1053 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVDESTALPHA
);
1054 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1055 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad2
, 4, 0);
1056 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
1058 hr
= IDirect3DDevice7_SetRenderTarget(device
, backbuffer
, 0);
1059 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderTarget failed, hr = %08x\n", hr
);
1060 set_viewport_size(device
);
1062 /* Render the offscreen texture onto the frame buffer to be able to compare it regularly.
1063 * Disable alpha blending for the final composition
1065 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
);
1066 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetRenderState failed, hr = %08x\n", hr
);
1068 hr
= IDirect3DDevice7_SetTexture(device
, 0, offscreen
);
1069 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetTexture failed, hr = %08x\n", hr
);
1070 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEX1
, composite_quad
, 4, 0);
1071 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
1072 hr
= IDirect3DDevice7_SetTexture(device
, 0, NULL
);
1073 ok(hr
== D3D_OK
, "IDirect3DDevice7_SetTexture failed, hr = %08x\n", hr
);
1075 hr
= IDirect3DDevice7_EndScene(device
);
1076 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndScene failed, hr = %08x\n", hr
);
1079 color
= getPixelColor(device
, 160, 360);
1080 red
= (color
& 0x00ff0000) >> 16;
1081 green
= (color
& 0x0000ff00) >> 8;
1082 blue
= (color
& 0x000000ff);
1083 ok(red
>= 0xbe && red
<= 0xc0 && green
>= 0x39 && green
<= 0x41 && blue
== 0x00,
1084 "SRCALPHA on frame buffer returned color 0x%08x, expected 0x00bf4000\n", color
);
1086 color
= getPixelColor(device
, 160, 120);
1087 red
= (color
& 0x00ff0000) >> 16;
1088 green
= (color
& 0x0000ff00) >> 8;
1089 blue
= (color
& 0x000000ff);
1090 ok(red
== 0x00 && green
== 0x00 && blue
>= 0xfe && blue
<= 0xff ,
1091 "DSTALPHA on frame buffer returned color 0x%08x, expected 0x000000ff\n", color
);
1093 color
= getPixelColor(device
, 480, 360);
1094 red
= (color
& 0x00ff0000) >> 16;
1095 green
= (color
& 0x0000ff00) >> 8;
1096 blue
= (color
& 0x000000ff);
1097 ok(red
>= 0xbe && red
<= 0xc0 && green
>= 0x39 && green
<= 0x41 && blue
== 0x00,
1098 "SRCALPHA on texture returned color 0x%08x, expected 0x00bf4000\n", color
);
1100 color
= getPixelColor(device
, 480, 120);
1101 red
= (color
& 0x00ff0000) >> 16;
1102 green
= (color
& 0x0000ff00) >> 8;
1103 blue
= (color
& 0x000000ff);
1104 ok(red
>= 0x7e && red
<= 0x81 && green
== 0x00 && blue
>= 0x7e && blue
<= 0x81,
1105 "DSTALPHA on texture returned color 0x%08x, expected 0x00800080\n", color
);
1108 if(offscreen
) IDirectDrawSurface7_Release(offscreen
);
1109 if(backbuffer
) IDirectDrawSurface7_Release(backbuffer
);
1112 static void rhw_zero_test(IDirect3DDevice7
*device
)
1114 /* Test if it will render a quad correctly when vertex rhw = 0 */
1124 {0, 100, 0, 0, 0xffffffff},
1125 {0, 0, 0, 0, 0xffffffff},
1126 {100, 100, 0, 0, 0xffffffff},
1127 {100, 0, 0, 0, 0xffffffff},
1130 /* Clear to black */
1131 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0, 0.0, 0);
1132 ok(hr
== D3D_OK
, "Clear failed, hr = %08x\n", hr
);
1134 hr
= IDirect3DDevice7_BeginScene(device
);
1135 ok(hr
== D3D_OK
, "IDirect3DDevice7_BeginScene failed with %08x\n", hr
);
1137 if (SUCCEEDED(hr
)) {
1138 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, quad1
, 4, 0);
1139 ok(hr
== D3D_OK
, "DrawPrimitive failed, hr = %08x\n", hr
);
1141 hr
= IDirect3DDevice7_EndScene(device
);
1142 ok(hr
== D3D_OK
, "IDirect3DDevice7_EndScene failed, hr = %08x\n", hr
);
1145 color
= getPixelColor(device
, 5, 5);
1146 ok(color
== 0xffffff ||
1147 broken(color
== 0), /* VMware */
1148 "Got color %08x, expected 00ffffff\n", color
);
1150 color
= getPixelColor(device
, 105, 105);
1151 ok(color
== 0, "Got color %08x, expected 00000000\n", color
);
1154 static BOOL
D3D1_createObjects(void)
1159 D3DEXECUTEBUFFERDESC exdesc
;
1160 D3DVIEWPORT vp_data
;
1162 /* An IDirect3DDevice cannot be queryInterfaced from an IDirect3DDevice7 on windows */
1163 hr
= DirectDrawCreate(NULL
, &DirectDraw1
, NULL
);
1165 ok(hr
==DD_OK
|| hr
==DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreate returned: %x\n", hr
);
1170 wc
.lpfnWndProc
= DefWindowProcA
;
1171 wc
.lpszClassName
= "texturemapblend_test_wc";
1172 RegisterClassA(&wc
);
1173 window
= CreateWindowA("texturemapblend_test_wc", "texturemapblend_test",
1174 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
1176 hr
= IDirectDraw_SetCooperativeLevel(DirectDraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1177 ok(hr
==DD_OK
, "SetCooperativeLevel returned: %x\n", hr
);
1182 hr
= IDirectDraw_SetDisplayMode(DirectDraw1
, 640, 480, 32);
1184 /* 24 bit is fine too */
1185 hr
= IDirectDraw_SetDisplayMode(DirectDraw1
, 640, 480, 24);
1187 ok(hr
==DD_OK
|| hr
== DDERR_UNSUPPORTED
, "SetDisplayMode returned: %x\n", hr
);
1192 hr
= IDirectDraw_QueryInterface(DirectDraw1
, &IID_IDirect3D
, (void**) &Direct3D1
);
1193 ok(hr
==DD_OK
, "QueryInterface returned: %x\n", hr
);
1198 memset(&ddsd
, 0, sizeof(ddsd
));
1199 ddsd
.dwSize
= sizeof(ddsd
);
1200 ddsd
.dwFlags
= DDSD_CAPS
;
1201 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
;
1202 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &Surface1
, NULL
);
1203 ok(hr
==DD_OK
, "CreateSurface returned: %x\n", hr
);
1208 hr
= IDirectDrawSurface_QueryInterface(Surface1
, &IID_IDirect3DHALDevice
, (void **) &Direct3DDevice1
);
1210 trace("Creating a HAL device failed, trying Ref\n");
1211 hr
= IDirectDrawSurface_QueryInterface(Surface1
, &IID_IDirect3DRefDevice
, (void **) &Direct3DDevice1
);
1213 ok(hr
==D3D_OK
, "Creating 3D device returned: %x\n", hr
);
1218 hr
= IDirect3D_CreateViewport(Direct3D1
, &Viewport
, NULL
);
1219 ok(hr
== D3D_OK
, "IDirect3D_CreateViewport failed: %08x\n", hr
);
1224 hr
= IDirect3DViewport_Initialize(Viewport
, Direct3D1
);
1225 ok(hr
== D3D_OK
|| hr
== DDERR_ALREADYINITIALIZED
, "IDirect3DViewport_Initialize returned %08x\n", hr
);
1226 hr
= IDirect3DDevice_AddViewport(Direct3DDevice1
, Viewport
);
1227 ok(hr
== D3D_OK
, "IDirect3DDevice_AddViewport returned %08x\n", hr
);
1228 vp_data
.dwSize
= sizeof(vp_data
);
1231 vp_data
.dwWidth
= 640;
1232 vp_data
.dwHeight
= 480;
1233 vp_data
.dvScaleX
= 1;
1234 vp_data
.dvScaleY
= 1;
1235 vp_data
.dvMaxX
= 640;
1236 vp_data
.dvMaxY
= 480;
1239 hr
= IDirect3DViewport_SetViewport(Viewport
, &vp_data
);
1240 ok(hr
== D3D_OK
, "IDirect3DViewport_SetViewport returned %08x\n", hr
);
1242 memset(&exdesc
, 0, sizeof(D3DEXECUTEBUFFERDESC
));
1243 exdesc
.dwSize
= sizeof(D3DEXECUTEBUFFERDESC
);
1244 exdesc
.dwFlags
= D3DDEB_BUFSIZE
| D3DDEB_CAPS
;
1245 exdesc
.dwBufferSize
= 512;
1246 exdesc
.dwCaps
= D3DDEBCAPS_SYSTEMMEMORY
;
1247 hr
= IDirect3DDevice_CreateExecuteBuffer(Direct3DDevice1
, &exdesc
, &ExecuteBuffer
, NULL
);
1248 ok(hr
== D3D_OK
, "IDirect3DDevice_CreateExecuteBuffer failed with %08x\n", hr
);
1256 static void D3D1_releaseObjects(void)
1258 if(ExecuteBuffer
) IDirect3DExecuteBuffer_Release(ExecuteBuffer
);
1259 if(Surface1
) IDirectDrawSurface_Release(Surface1
);
1260 if(Viewport
) IDirect3DViewport_Release(Viewport
);
1261 if(Direct3DDevice1
) IDirect3DDevice_Release(Direct3DDevice1
);
1262 if(Direct3D1
) IDirect3D_Release(Direct3D1
);
1263 if(DirectDraw1
) IDirectDraw_Release(DirectDraw1
);
1264 if(window
) DestroyWindow(window
);
1267 static DWORD
D3D1_getPixelColor(IDirectDraw
*DirectDraw1
, IDirectDrawSurface
*Surface
, UINT x
, UINT y
)
1272 RECT rectToLock
= {x
, y
, x
+1, y
+1};
1273 IDirectDrawSurface
*surf
= NULL
;
1275 /* Some implementations seem to dislike direct locking on the front buffer. Thus copy the front buffer
1276 * to an offscreen surface and lock it instead of the front buffer
1278 memset(&ddsd
, 0, sizeof(ddsd
));
1279 ddsd
.dwSize
= sizeof(ddsd
);
1280 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
1281 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
1283 ddsd
.dwHeight
= 480;
1284 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
;
1285 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &surf
, NULL
);
1286 ok(hr
== DD_OK
, "IDirectDraw_CreateSurface failed with %08x\n", hr
);
1289 trace("cannot create helper surface\n");
1293 memset(&ddsd
, 0, sizeof(ddsd
));
1294 ddsd
.dwSize
= sizeof(ddsd
);
1295 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
1297 hr
= IDirectDrawSurface_BltFast(surf
, 0, 0, Surface
, NULL
, 0);
1298 ok(hr
== DD_OK
, "IDirectDrawSurface_BltFast returned %08x\n", hr
);
1301 trace("Cannot blit\n");
1306 hr
= IDirectDrawSurface_Lock(surf
, &rectToLock
, &ddsd
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
1309 trace("Can't lock the offscreen surface, hr=%08x\n", hr
);
1314 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
1315 * really important for these tests
1317 ret
= ((DWORD
*) ddsd
.lpSurface
)[0] & 0x00ffffff;
1318 hr
= IDirectDrawSurface_Unlock(surf
, NULL
);
1321 trace("Can't unlock the offscreen surface, hr=%08x\n", hr
);
1325 IDirectDrawSurface_Release(surf
);
1329 #define EXEBUF_START_RENDER_STATES(count, ptr) do {\
1330 ((D3DINSTRUCTION*)(ptr))->bOpcode = D3DOP_STATERENDER;\
1331 ((D3DINSTRUCTION*)(ptr))->bSize = sizeof(D3DSTATE);\
1332 ((D3DINSTRUCTION*)(ptr))->wCount = count;\
1333 ptr = ((D3DINSTRUCTION*)(ptr))+1; } while (0)
1335 #define EXEBUF_PUT_RENDER_STATE(state, value, ptr) do {\
1336 U1(*((D3DSTATE*)(ptr))).drstRenderStateType = state; \
1337 U2(*((D3DSTATE*)(ptr))).dwArg[0] = value; \
1338 ptr = ((D3DSTATE*)(ptr))+1; } while (0)
1340 #define EXEBUF_PUT_PROCESSVERTICES(nvertices, ptr) do {\
1341 ((D3DINSTRUCTION*)(ptr))->bOpcode = D3DOP_PROCESSVERTICES;\
1342 ((D3DINSTRUCTION*)(ptr))->bSize = sizeof(D3DPROCESSVERTICES);\
1343 ((D3DINSTRUCTION*)(ptr))->wCount = 1;\
1344 ptr = ((D3DINSTRUCTION*)(ptr))+1;\
1345 ((D3DPROCESSVERTICES*)(ptr))->dwFlags = D3DPROCESSVERTICES_COPY;\
1346 ((D3DPROCESSVERTICES*)(ptr))->wStart = 0;\
1347 ((D3DPROCESSVERTICES*)(ptr))->wDest = 0;\
1348 ((D3DPROCESSVERTICES*)(ptr))->dwCount = nvertices;\
1349 ((D3DPROCESSVERTICES*)(ptr))->dwReserved = 0;\
1350 ptr = ((D3DPROCESSVERTICES*)(ptr))+1; } while (0)
1352 #define EXEBUF_END(ptr) do {\
1353 ((D3DINSTRUCTION*)(ptr))->bOpcode = D3DOP_EXIT;\
1354 ((D3DINSTRUCTION*)(ptr))->bSize = 0;\
1355 ((D3DINSTRUCTION*)(ptr))->wCount = 0;\
1356 ptr = ((D3DINSTRUCTION*)(ptr))+1; } while (0)
1358 #define EXEBUF_PUT_QUAD(base_idx, ptr) do {\
1359 ((D3DINSTRUCTION*)(ptr))->bOpcode = D3DOP_TRIANGLE;\
1360 ((D3DINSTRUCTION*)(ptr))->bSize = sizeof(D3DTRIANGLE);\
1361 ((D3DINSTRUCTION*)(ptr))->wCount = 2;\
1362 ptr = ((D3DINSTRUCTION*)(ptr))+1;\
1363 U1(*((D3DTRIANGLE*)(ptr))).v1 = base_idx;\
1364 U2(*((D3DTRIANGLE*)(ptr))).v2 = (base_idx) + 1; \
1365 U3(*((D3DTRIANGLE*)(ptr))).v3 = (base_idx) + 3; \
1366 ((D3DTRIANGLE*)(ptr))->wFlags = 0;\
1367 ptr = ((D3DTRIANGLE*)ptr)+1;\
1368 U1(*((D3DTRIANGLE*)(ptr))).v1 = (base_idx) + 1; \
1369 U2(*((D3DTRIANGLE*)(ptr))).v2 = (base_idx) + 2; \
1370 U3(*((D3DTRIANGLE*)(ptr))).v3 = (base_idx) + 3; \
1371 ((D3DTRIANGLE*)(ptr))->wFlags = 0;\
1372 ptr = ((D3DTRIANGLE*)(ptr))+1;\
1375 static HRESULT CALLBACK
TextureFormatEnumCallback(DDSURFACEDESC
*lpDDSD
, void *lpContext
)
1377 if (lpDDSD
->ddpfPixelFormat
.dwFlags
& DDPF_PALETTEINDEXED8
) {
1378 *(BOOL
*)lpContext
= TRUE
;
1381 return DDENUMRET_OK
;
1384 static void D3D1_TextureMapBlendTest(void)
1388 D3DEXECUTEBUFFERDESC exdesc
;
1389 D3DEXECUTEDATA exdata
;
1391 RECT rect
= { 0, 0, 64, 128 };
1392 DWORD color
, red
, blue
, green
;
1393 void *exe_buffer_ptr
;
1395 D3DTEXTUREHANDLE htex
;
1397 IDirectDrawSurface
*TexSurface
= NULL
;
1398 IDirect3DTexture
*Texture
= NULL
;
1399 IDirectDrawPalette
*Palette
= NULL
;
1400 PALETTEENTRY table1
[256];
1401 BOOL p8_textures_supported
= FALSE
;
1411 {0.0f
, 0.0f
, 0.0f
, 1.0f
, 0xffffffff, 0, 0.0f
, 0.0f
},
1412 {640.0f
, 0.0f
, 0.0f
, 1.0f
, 0xffffffff, 0, 1.0f
, 0.0f
},
1413 {640.0f
, 240.0f
, 0.0f
, 1.0f
, 0xffffffff, 0, 1.0f
, 1.0f
},
1414 {0.0f
, 240.0f
, 0.0f
, 1.0f
, 0xffffffff, 0, 0.0f
, 1.0f
},
1415 {0.0f
, 240.0f
, 0.0f
, 1.0f
, 0x80ffffff, 0, 0.0f
, 0.0f
},
1416 {640.0f
, 240.0f
, 0.0f
, 1.0f
, 0x80ffffff, 0, 1.0f
, 0.0f
},
1417 {640.0f
, 480.0f
, 0.0f
, 1.0f
, 0x80ffffff, 0, 1.0f
, 1.0f
},
1418 {0.0f
, 480.0f
, 0.0f
, 1.0f
, 0x80ffffff, 0, 0.0f
, 1.0f
}
1421 {0.0f
, 0.0f
, 0.0f
, 1.0f
, 0x00ff0080, 0, 0.0f
, 0.0f
},
1422 {640.0f
, 0.0f
, 0.0f
, 1.0f
, 0x00ff0080, 0, 1.0f
, 0.0f
},
1423 {640.0f
, 240.0f
, 0.0f
, 1.0f
, 0x00ff0080, 0, 1.0f
, 1.0f
},
1424 {0.0f
, 240.0f
, 0.0f
, 1.0f
, 0x00ff0080, 0, 0.0f
, 1.0f
},
1425 {0.0f
, 240.0f
, 0.0f
, 1.0f
, 0x008000ff, 0, 0.0f
, 0.0f
},
1426 {640.0f
, 240.0f
, 0.0f
, 1.0f
, 0x008000ff, 0, 1.0f
, 0.0f
},
1427 {640.0f
, 480.0f
, 0.0f
, 1.0f
, 0x008000ff, 0, 1.0f
, 1.0f
},
1428 {0.0f
, 480.0f
, 0.0f
, 1.0f
, 0x008000ff, 0, 0.0f
, 1.0f
}
1431 /* 1) Test alpha with DDPF_ALPHAPIXELS texture - should be taken from texture alpha channel*/
1432 memset (&ddsd
, 0, sizeof (ddsd
));
1433 ddsd
.dwSize
= sizeof (ddsd
);
1434 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
1435 ddsd
.dwHeight
= 128;
1437 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1438 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
1439 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
1440 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1441 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1442 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1443 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1444 U5(ddsd
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
1445 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &TexSurface
, NULL
);
1446 ok(hr
==D3D_OK
, "CreateSurface returned: %x\n", hr
);
1448 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1452 hr
= IDirectDrawSurface_QueryInterface(TexSurface
, &IID_IDirect3DTexture
,
1454 ok(hr
==D3D_OK
, "IDirectDrawSurface_QueryInterface returned: %x\n", hr
);
1456 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1460 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
1461 ddbltfx
.dwSize
= sizeof(ddbltfx
);
1462 U5(ddbltfx
).dwFillColor
= 0;
1463 hr
= IDirectDrawSurface_Blt(Surface1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1464 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1466 U5(ddbltfx
).dwFillColor
= 0xff0000ff;
1467 hr
= IDirectDrawSurface_Blt(TexSurface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1468 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1469 U5(ddbltfx
).dwFillColor
= 0x800000ff;
1470 hr
= IDirectDrawSurface_Blt(TexSurface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1471 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1473 memset(&exdesc
, 0, sizeof(D3DEXECUTEBUFFERDESC
));
1474 exdesc
.dwSize
= sizeof(D3DEXECUTEBUFFERDESC
);
1475 hr
= IDirect3DExecuteBuffer_Lock(ExecuteBuffer
, &exdesc
);
1476 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr
);
1478 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1482 memcpy(exdesc
.lpData
, test1_quads
, sizeof(test1_quads
));
1484 exe_buffer_ptr
= sizeof(test1_quads
) + (char*)exdesc
.lpData
;
1486 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr
);
1488 EXEBUF_START_RENDER_STATES(12, exe_buffer_ptr
);
1489 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
, exe_buffer_ptr
);
1490 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ZENABLE
, FALSE
, exe_buffer_ptr
);
1491 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_FOGENABLE
, FALSE
, exe_buffer_ptr
);
1492 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_SPECULARENABLE
, FALSE
, exe_buffer_ptr
);
1493 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREMAG
, D3DFILTER_NEAREST
, exe_buffer_ptr
);
1494 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREMIN
, D3DFILTER_NEAREST
, exe_buffer_ptr
);
1495 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_FILLMODE
, D3DFILL_SOLID
, exe_buffer_ptr
);
1496 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
, exe_buffer_ptr
);
1497 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
, exe_buffer_ptr
);
1498 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
, exe_buffer_ptr
);
1499 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREMAPBLEND
, D3DTBLEND_MODULATE
, exe_buffer_ptr
);
1500 hr
= IDirect3DTexture_GetHandle(Texture
, Direct3DDevice1
, &htex
);
1501 ok(hr
== D3D_OK
, "IDirect3DTexture_GetHandle failed with %08x\n", hr
);
1502 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE
, htex
, exe_buffer_ptr
);
1504 EXEBUF_PUT_QUAD(0, exe_buffer_ptr
);
1505 EXEBUF_PUT_QUAD(4, exe_buffer_ptr
);
1507 EXEBUF_END(exe_buffer_ptr
);
1509 exe_length
= ((char*)exe_buffer_ptr
- (char*)exdesc
.lpData
) - sizeof(test1_quads
);
1511 hr
= IDirect3DExecuteBuffer_Unlock(ExecuteBuffer
);
1513 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr
);
1516 memset(&exdata
, 0, sizeof(exdata
));
1517 exdata
.dwSize
= sizeof(exdata
);
1518 exdata
.dwVertexCount
= 8;
1519 exdata
.dwInstructionOffset
= sizeof(test1_quads
);
1520 exdata
.dwInstructionLength
= exe_length
;
1521 hr
= IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer
, &exdata
);
1522 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr
);
1524 hr
= IDirect3DDevice_BeginScene(Direct3DDevice1
);
1525 ok(hr
== D3D_OK
, "IDirect3DDevice_BeginScene failed with %08x\n", hr
);
1527 if (SUCCEEDED(hr
)) {
1528 hr
= IDirect3DDevice_Execute(Direct3DDevice1
, ExecuteBuffer
, Viewport
, D3DEXECUTE_UNCLIPPED
);
1529 ok(hr
== D3D_OK
, "IDirect3DDevice_Execute failed, hr = %08x\n", hr
);
1530 hr
= IDirect3DDevice_EndScene(Direct3DDevice1
);
1531 ok(hr
== D3D_OK
, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr
);
1534 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 5);
1535 red
= (color
& 0x00ff0000) >> 16;
1536 green
= (color
& 0x0000ff00) >> 8;
1537 blue
= (color
& 0x000000ff);
1538 ok(red
== 0 && green
== 0 && blue
>= 0x7e && blue
<= 0x82, "Got color %08x, expected 00000080 or near\n", color
);
1540 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 5);
1541 red
= (color
& 0x00ff0000) >> 16;
1542 green
= (color
& 0x0000ff00) >> 8;
1543 blue
= (color
& 0x000000ff);
1544 ok(red
== 0 && green
== 0 && blue
== 0xff, "Got color %08x, expected 000000ff or near\n", color
);
1546 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 245);
1547 red
= (color
& 0x00ff0000) >> 16;
1548 green
= (color
& 0x0000ff00) >> 8;
1549 blue
= (color
& 0x000000ff);
1550 ok(red
== 0 && green
== 0 && blue
>= 0x7e && blue
<= 0x82, "Got color %08x, expected 00000080 or near\n", color
);
1552 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 245);
1553 red
= (color
& 0x00ff0000) >> 16;
1554 green
= (color
& 0x0000ff00) >> 8;
1555 blue
= (color
& 0x000000ff);
1556 ok(red
== 0 && green
== 0 && blue
== 0xff, "Got color %08x, expected 000000ff or near\n", color
);
1558 /* 2) Test alpha with texture that has no alpha channel - alpha should be taken from diffuse color */
1559 if(Texture
) IDirect3DTexture_Release(Texture
);
1561 if(TexSurface
) IDirectDrawSurface_Release(TexSurface
);
1564 memset (&ddsd
, 0, sizeof (ddsd
));
1565 ddsd
.dwSize
= sizeof (ddsd
);
1566 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
1567 ddsd
.dwHeight
= 128;
1569 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1570 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
1571 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1572 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1573 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1574 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1575 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1577 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &TexSurface
, NULL
);
1578 ok(hr
==D3D_OK
, "CreateSurface returned: %x\n", hr
);
1580 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1584 hr
= IDirectDrawSurface_QueryInterface(TexSurface
, &IID_IDirect3DTexture
,
1586 ok(hr
==D3D_OK
, "IDirectDrawSurface_QueryInterface returned: %x\n", hr
);
1588 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1592 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
1593 ddbltfx
.dwSize
= sizeof(ddbltfx
);
1594 U5(ddbltfx
).dwFillColor
= 0;
1595 hr
= IDirectDrawSurface_Blt(Surface1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1596 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1598 U5(ddbltfx
).dwFillColor
= 0xff0000ff;
1599 hr
= IDirectDrawSurface_Blt(TexSurface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1600 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1601 U5(ddbltfx
).dwFillColor
= 0x800000ff;
1602 hr
= IDirectDrawSurface_Blt(TexSurface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1603 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1605 memset(&exdesc
, 0, sizeof(D3DEXECUTEBUFFERDESC
));
1606 exdesc
.dwSize
= sizeof(D3DEXECUTEBUFFERDESC
);
1607 hr
= IDirect3DExecuteBuffer_Lock(ExecuteBuffer
, &exdesc
);
1608 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr
);
1610 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1614 memcpy(exdesc
.lpData
, test1_quads
, sizeof(test1_quads
));
1616 exe_buffer_ptr
= sizeof(test1_quads
) + (char*)exdesc
.lpData
;
1618 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr
);
1620 EXEBUF_START_RENDER_STATES(1, exe_buffer_ptr
);
1621 hr
= IDirect3DTexture_GetHandle(Texture
, Direct3DDevice1
, &htex
);
1622 ok(hr
== D3D_OK
, "IDirect3DTexture_GetHandle failed with %08x\n", hr
);
1623 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE
, htex
, exe_buffer_ptr
);
1625 EXEBUF_PUT_QUAD(0, exe_buffer_ptr
);
1626 EXEBUF_PUT_QUAD(4, exe_buffer_ptr
);
1628 EXEBUF_END(exe_buffer_ptr
);
1630 exe_length
= ((char*)exe_buffer_ptr
- (char*)exdesc
.lpData
) - sizeof(test1_quads
);
1632 hr
= IDirect3DExecuteBuffer_Unlock(ExecuteBuffer
);
1634 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr
);
1637 memset(&exdata
, 0, sizeof(exdata
));
1638 exdata
.dwSize
= sizeof(exdata
);
1639 exdata
.dwVertexCount
= 8;
1640 exdata
.dwInstructionOffset
= sizeof(test1_quads
);
1641 exdata
.dwInstructionLength
= exe_length
;
1642 hr
= IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer
, &exdata
);
1643 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr
);
1645 hr
= IDirect3DDevice_BeginScene(Direct3DDevice1
);
1646 ok(hr
== D3D_OK
, "IDirect3DDevice_BeginScene failed with %08x\n", hr
);
1648 if (SUCCEEDED(hr
)) {
1649 hr
= IDirect3DDevice_Execute(Direct3DDevice1
, ExecuteBuffer
, Viewport
, D3DEXECUTE_UNCLIPPED
);
1650 ok(hr
== D3D_OK
, "IDirect3DDevice_Execute failed, hr = %08x\n", hr
);
1651 hr
= IDirect3DDevice_EndScene(Direct3DDevice1
);
1652 ok(hr
== D3D_OK
, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr
);
1655 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 5);
1656 red
= (color
& 0x00ff0000) >> 16;
1657 green
= (color
& 0x0000ff00) >> 8;
1658 blue
= (color
& 0x000000ff);
1659 ok(red
== 0 && green
== 0 && blue
== 0xff, "Got color %08x, expected 000000ff or near\n", color
);
1661 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 5);
1662 red
= (color
& 0x00ff0000) >> 16;
1663 green
= (color
& 0x0000ff00) >> 8;
1664 blue
= (color
& 0x000000ff);
1665 ok(red
== 0 && green
== 0 && blue
== 0xff, "Got color %08x, expected 000000ff or near\n", color
);
1667 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 245);
1668 red
= (color
& 0x00ff0000) >> 16;
1669 green
= (color
& 0x0000ff00) >> 8;
1670 blue
= (color
& 0x000000ff);
1671 ok(red
== 0 && green
== 0 && blue
>= 0x7e && blue
<= 0x82, "Got color %08x, expected 00000080 or near\n", color
);
1673 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 245);
1674 red
= (color
& 0x00ff0000) >> 16;
1675 green
= (color
& 0x0000ff00) >> 8;
1676 blue
= (color
& 0x000000ff);
1677 ok(red
== 0 && green
== 0 && blue
>= 0x7e && blue
<= 0x82, "Got color %08x, expected 00000080 or near\n", color
);
1679 /* 3) Test RGB - should multiply color components from diffuse color and texture */
1680 if(Texture
) IDirect3DTexture_Release(Texture
);
1682 if(TexSurface
) IDirectDrawSurface_Release(TexSurface
);
1685 memset (&ddsd
, 0, sizeof (ddsd
));
1686 ddsd
.dwSize
= sizeof (ddsd
);
1687 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
1688 ddsd
.dwHeight
= 128;
1690 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1691 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
1692 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
1693 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1694 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1695 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1696 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1697 U5(ddsd
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
1698 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &TexSurface
, NULL
);
1699 ok(hr
==D3D_OK
, "CreateSurface returned: %x\n", hr
);
1701 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1705 hr
= IDirectDrawSurface_QueryInterface(TexSurface
, &IID_IDirect3DTexture
,
1707 ok(hr
==D3D_OK
, "IDirectDrawSurface_QueryInterface returned: %x\n", hr
);
1709 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1713 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
1714 ddbltfx
.dwSize
= sizeof(ddbltfx
);
1715 U5(ddbltfx
).dwFillColor
= 0;
1716 hr
= IDirectDrawSurface_Blt(Surface1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1717 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1719 U5(ddbltfx
).dwFillColor
= 0x00ffffff;
1720 hr
= IDirectDrawSurface_Blt(TexSurface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1721 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1722 U5(ddbltfx
).dwFillColor
= 0x00ffff80;
1723 hr
= IDirectDrawSurface_Blt(TexSurface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1724 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1726 memset(&exdesc
, 0, sizeof(D3DEXECUTEBUFFERDESC
));
1727 exdesc
.dwSize
= sizeof(D3DEXECUTEBUFFERDESC
);
1728 hr
= IDirect3DExecuteBuffer_Lock(ExecuteBuffer
, &exdesc
);
1729 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr
);
1731 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1735 memcpy(exdesc
.lpData
, test2_quads
, sizeof(test2_quads
));
1737 exe_buffer_ptr
= sizeof(test2_quads
) + (char*)exdesc
.lpData
;
1739 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr
);
1741 EXEBUF_START_RENDER_STATES(2, exe_buffer_ptr
);
1742 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
, exe_buffer_ptr
);
1743 hr
= IDirect3DTexture_GetHandle(Texture
, Direct3DDevice1
, &htex
);
1744 ok(hr
== D3D_OK
, "IDirect3DTexture_GetHandle failed with %08x\n", hr
);
1745 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE
, htex
, exe_buffer_ptr
);
1747 EXEBUF_PUT_QUAD(0, exe_buffer_ptr
);
1748 EXEBUF_PUT_QUAD(4, exe_buffer_ptr
);
1750 EXEBUF_END(exe_buffer_ptr
);
1752 exe_length
= ((char*)exe_buffer_ptr
- (char*)exdesc
.lpData
) - sizeof(test2_quads
);
1754 hr
= IDirect3DExecuteBuffer_Unlock(ExecuteBuffer
);
1756 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr
);
1759 memset(&exdata
, 0, sizeof(exdata
));
1760 exdata
.dwSize
= sizeof(exdata
);
1761 exdata
.dwVertexCount
= 8;
1762 exdata
.dwInstructionOffset
= sizeof(test2_quads
);
1763 exdata
.dwInstructionLength
= exe_length
;
1764 hr
= IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer
, &exdata
);
1765 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr
);
1767 hr
= IDirect3DDevice_BeginScene(Direct3DDevice1
);
1768 ok(hr
== D3D_OK
, "IDirect3DDevice_BeginScene failed with %08x\n", hr
);
1770 if (SUCCEEDED(hr
)) {
1771 hr
= IDirect3DDevice_Execute(Direct3DDevice1
, ExecuteBuffer
, Viewport
, D3DEXECUTE_UNCLIPPED
);
1772 ok(hr
== D3D_OK
, "IDirect3DDevice_Execute failed, hr = %08x\n", hr
);
1773 hr
= IDirect3DDevice_EndScene(Direct3DDevice1
);
1774 ok(hr
== D3D_OK
, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr
);
1777 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 5);
1778 red
= (color
& 0x00ff0000) >> 16;
1779 green
= (color
& 0x0000ff00) >> 8;
1780 blue
= (color
& 0x000000ff);
1781 ok(red
== 0xff && green
== 0 && blue
>= 0x3e && blue
<= 0x42, "Got color %08x, expected 00ff0040 or near\n", color
);
1783 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 5);
1784 red
= (color
& 0x00ff0000) >> 16;
1785 green
= (color
& 0x0000ff00) >> 8;
1786 blue
= (color
& 0x000000ff);
1787 ok(red
== 0xff && green
== 0 && blue
== 0x80, "Got color %08x, expected 00ff0080 or near\n", color
);
1789 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 245);
1790 red
= (color
& 0x00ff0000) >> 16;
1791 green
= (color
& 0x0000ff00) >> 8;
1792 blue
= (color
& 0x000000ff);
1793 ok(red
>= 0x7e && red
<= 0x82 && green
== 0 && blue
== 0x80, "Got color %08x, expected 00800080 or near\n", color
);
1795 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 245);
1796 red
= (color
& 0x00ff0000) >> 16;
1797 green
= (color
& 0x0000ff00) >> 8;
1798 blue
= (color
& 0x000000ff);
1799 ok(red
>= 0x7e && red
<= 0x82 && green
== 0 && blue
== 0xff, "Got color %08x, expected 008000ff or near\n", color
);
1801 /* 4) Test alpha again, now with color keyed texture (colorkey emulation in wine can interfere) */
1802 if(Texture
) IDirect3DTexture_Release(Texture
);
1804 if(TexSurface
) IDirectDrawSurface_Release(TexSurface
);
1807 memset (&ddsd
, 0, sizeof (ddsd
));
1808 ddsd
.dwSize
= sizeof (ddsd
);
1809 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
1810 ddsd
.dwHeight
= 128;
1812 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1813 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
1814 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1815 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 16;
1816 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0xf800;
1817 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x07e0;
1818 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x001f;
1820 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &TexSurface
, NULL
);
1821 ok(hr
==D3D_OK
, "CreateSurface returned: %x\n", hr
);
1823 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1827 hr
= IDirectDrawSurface_QueryInterface(TexSurface
, &IID_IDirect3DTexture
,
1829 ok(hr
==D3D_OK
, "IDirectDrawSurface_QueryInterface returned: %x\n", hr
);
1831 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1835 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
1836 ddbltfx
.dwSize
= sizeof(ddbltfx
);
1837 U5(ddbltfx
).dwFillColor
= 0;
1838 hr
= IDirectDrawSurface_Blt(Surface1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1839 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1840 U5(ddbltfx
).dwFillColor
= 0xf800;
1841 hr
= IDirectDrawSurface_Blt(TexSurface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1842 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1843 U5(ddbltfx
).dwFillColor
= 0x001f;
1844 hr
= IDirectDrawSurface_Blt(TexSurface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1845 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1847 clrKey
.dwColorSpaceLowValue
= 0x001f;
1848 clrKey
.dwColorSpaceHighValue
= 0x001f;
1849 hr
= IDirectDrawSurface_SetColorKey(TexSurface
, DDCKEY_SRCBLT
, &clrKey
);
1850 ok(hr
==D3D_OK
, "IDirectDrawSurfac_SetColorKey returned: %x\n", hr
);
1852 memset(&exdesc
, 0, sizeof(D3DEXECUTEBUFFERDESC
));
1853 exdesc
.dwSize
= sizeof(D3DEXECUTEBUFFERDESC
);
1854 hr
= IDirect3DExecuteBuffer_Lock(ExecuteBuffer
, &exdesc
);
1855 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr
);
1857 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1861 memcpy(exdesc
.lpData
, test1_quads
, sizeof(test1_quads
));
1863 exe_buffer_ptr
= sizeof(test1_quads
) + (char*)exdesc
.lpData
;
1865 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr
);
1867 EXEBUF_START_RENDER_STATES(2, exe_buffer_ptr
);
1868 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
, exe_buffer_ptr
);
1869 hr
= IDirect3DTexture_GetHandle(Texture
, Direct3DDevice1
, &htex
);
1870 ok(hr
== D3D_OK
, "IDirect3DTexture_GetHandle failed with %08x\n", hr
);
1871 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE
, htex
, exe_buffer_ptr
);
1873 EXEBUF_PUT_QUAD(0, exe_buffer_ptr
);
1874 EXEBUF_PUT_QUAD(4, exe_buffer_ptr
);
1876 EXEBUF_END(exe_buffer_ptr
);
1878 exe_length
= ((char*)exe_buffer_ptr
- (char*)exdesc
.lpData
) - sizeof(test1_quads
);
1880 hr
= IDirect3DExecuteBuffer_Unlock(ExecuteBuffer
);
1882 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr
);
1885 memset(&exdata
, 0, sizeof(exdata
));
1886 exdata
.dwSize
= sizeof(exdata
);
1887 exdata
.dwVertexCount
= 8;
1888 exdata
.dwInstructionOffset
= sizeof(test1_quads
);
1889 exdata
.dwInstructionLength
= exe_length
;
1890 hr
= IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer
, &exdata
);
1891 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr
);
1893 hr
= IDirect3DDevice_BeginScene(Direct3DDevice1
);
1894 ok(hr
== D3D_OK
, "IDirect3DDevice_BeginScene failed with %08x\n", hr
);
1896 if (SUCCEEDED(hr
)) {
1897 hr
= IDirect3DDevice_Execute(Direct3DDevice1
, ExecuteBuffer
, Viewport
, D3DEXECUTE_UNCLIPPED
);
1898 ok(hr
== D3D_OK
, "IDirect3DDevice_Execute failed, hr = %08x\n", hr
);
1899 hr
= IDirect3DDevice_EndScene(Direct3DDevice1
);
1900 ok(hr
== D3D_OK
, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr
);
1903 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 5);
1904 ok(color
== 0, "Got color %08x, expected 00000000\n", color
);
1906 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 5);
1907 red
= (color
& 0x00ff0000) >> 16;
1908 green
= (color
& 0x0000ff00) >> 8;
1909 blue
= (color
& 0x000000ff);
1910 ok(red
== 0xff && green
== 0 && blue
== 0, "Got color %08x, expected 00ff0000 or near\n", color
);
1912 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 245);
1913 ok(color
== 0, "Got color %08x, expected 00000000\n", color
);
1915 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 245);
1916 red
= (color
& 0x00ff0000) >> 16;
1917 green
= (color
& 0x0000ff00) >> 8;
1918 blue
= (color
& 0x000000ff);
1919 ok(red
>= 0x7e && red
<= 0x82 && green
== 0 && blue
== 0, "Got color %08x, expected 00800000 or near\n", color
);
1921 /* 5) Test alpha again, now with color keyed P8 texture */
1922 if(Texture
) IDirect3DTexture_Release(Texture
);
1924 if(TexSurface
) IDirectDrawSurface_Release(TexSurface
);
1927 hr
= IDirect3DDevice_EnumTextureFormats(Direct3DDevice1
, TextureFormatEnumCallback
,
1928 &p8_textures_supported
);
1929 ok(hr
== DD_OK
, "IDirect3DDevice_EnumTextureFormats returned %08x\n", hr
);
1931 if (!p8_textures_supported
) {
1932 skip("device has no P8 texture support, skipping test\n");
1934 memset (&ddsd
, 0, sizeof (ddsd
));
1935 ddsd
.dwSize
= sizeof (ddsd
);
1936 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
1937 ddsd
.dwHeight
= 128;
1939 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1940 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
1941 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_PALETTEINDEXED8
;
1942 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 8;
1944 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &TexSurface
, NULL
);
1945 ok(hr
==D3D_OK
, "CreateSurface returned: %x\n", hr
);
1947 skip("IDirectDraw_CreateSurface failed; skipping further tests\n");
1951 memset(table1
, 0, sizeof(table1
));
1952 table1
[0].peBlue
= 0xff;
1953 table1
[1].peRed
= 0xff;
1955 hr
= IDirectDraw_CreatePalette(DirectDraw1
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, table1
, &Palette
, NULL
);
1956 ok(hr
== DD_OK
, "CreatePalette returned %08x\n", hr
);
1958 skip("IDirectDraw_CreatePalette failed; skipping further tests\n");
1962 hr
= IDirectDrawSurface_SetPalette(TexSurface
, Palette
);
1963 ok(hr
==D3D_OK
, "IDirectDrawSurface_SetPalette returned: %x\n", hr
);
1965 hr
= IDirectDrawSurface_QueryInterface(TexSurface
, &IID_IDirect3DTexture
,
1967 ok(hr
==D3D_OK
, "IDirectDrawSurface_QueryInterface returned: %x\n", hr
);
1969 skip("Can't get IDirect3DTexture interface; skipping further tests\n");
1973 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
1974 ddbltfx
.dwSize
= sizeof(ddbltfx
);
1975 U5(ddbltfx
).dwFillColor
= 0;
1976 hr
= IDirectDrawSurface_Blt(Surface1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1977 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1978 U5(ddbltfx
).dwFillColor
= 0;
1979 hr
= IDirectDrawSurface_Blt(TexSurface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1980 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1981 U5(ddbltfx
).dwFillColor
= 1;
1982 hr
= IDirectDrawSurface_Blt(TexSurface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
1983 ok(hr
== D3D_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
1985 clrKey
.dwColorSpaceLowValue
= 1;
1986 clrKey
.dwColorSpaceHighValue
= 1;
1987 hr
= IDirectDrawSurface_SetColorKey(TexSurface
, DDCKEY_SRCBLT
, &clrKey
);
1988 ok(hr
==D3D_OK
, "IDirectDrawSurfac_SetColorKey returned: %x\n", hr
);
1990 memset(&exdesc
, 0, sizeof(D3DEXECUTEBUFFERDESC
));
1991 exdesc
.dwSize
= sizeof(D3DEXECUTEBUFFERDESC
);
1992 hr
= IDirect3DExecuteBuffer_Lock(ExecuteBuffer
, &exdesc
);
1993 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_Lock failed with %08x\n", hr
);
1995 skip("IDirect3DExecuteBuffer_Lock failed; skipping further tests\n");
1999 memcpy(exdesc
.lpData
, test1_quads
, sizeof(test1_quads
));
2001 exe_buffer_ptr
= sizeof(test1_quads
) + (char*)exdesc
.lpData
;
2003 EXEBUF_PUT_PROCESSVERTICES(8, exe_buffer_ptr
);
2005 EXEBUF_START_RENDER_STATES(2, exe_buffer_ptr
);
2006 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
, exe_buffer_ptr
);
2007 hr
= IDirect3DTexture_GetHandle(Texture
, Direct3DDevice1
, &htex
);
2008 ok(hr
== D3D_OK
, "IDirect3DTexture_GetHandle failed with %08x\n", hr
);
2009 EXEBUF_PUT_RENDER_STATE(D3DRENDERSTATE_TEXTUREHANDLE
, htex
, exe_buffer_ptr
);
2011 EXEBUF_PUT_QUAD(0, exe_buffer_ptr
);
2012 EXEBUF_PUT_QUAD(4, exe_buffer_ptr
);
2014 EXEBUF_END(exe_buffer_ptr
);
2016 exe_length
= ((char*)exe_buffer_ptr
- (char*)exdesc
.lpData
) - sizeof(test1_quads
);
2018 hr
= IDirect3DExecuteBuffer_Unlock(ExecuteBuffer
);
2020 trace("IDirect3DExecuteBuffer_Unlock failed with %08x\n", hr
);
2023 memset(&exdata
, 0, sizeof(exdata
));
2024 exdata
.dwSize
= sizeof(exdata
);
2025 exdata
.dwVertexCount
= 8;
2026 exdata
.dwInstructionOffset
= sizeof(test1_quads
);
2027 exdata
.dwInstructionLength
= exe_length
;
2028 hr
= IDirect3DExecuteBuffer_SetExecuteData(ExecuteBuffer
, &exdata
);
2029 ok(hr
== D3D_OK
, "IDirect3DExecuteBuffer_SetExecuteData failed with %08x\n", hr
);
2031 hr
= IDirect3DDevice_BeginScene(Direct3DDevice1
);
2032 ok(hr
== D3D_OK
, "IDirect3DDevice_BeginScene failed with %08x\n", hr
);
2034 if (SUCCEEDED(hr
)) {
2035 hr
= IDirect3DDevice_Execute(Direct3DDevice1
, ExecuteBuffer
, Viewport
, D3DEXECUTE_UNCLIPPED
);
2036 ok(hr
== D3D_OK
, "IDirect3DDevice_Execute failed, hr = %08x\n", hr
);
2037 hr
= IDirect3DDevice_EndScene(Direct3DDevice1
);
2038 ok(hr
== D3D_OK
, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr
);
2041 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 5);
2042 ok(color
== 0, "Got color %08x, expected 00000000\n", color
);
2044 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 5);
2045 red
= (color
& 0x00ff0000) >> 16;
2046 green
= (color
& 0x0000ff00) >> 8;
2047 blue
= (color
& 0x000000ff);
2048 ok(red
== 0 && green
== 0 && blue
== 0xff, "Got color %08x, expected 000000ff or near\n", color
);
2050 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 245);
2051 ok(color
== 0, "Got color %08x, expected 00000000\n", color
);
2053 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 400, 245);
2054 red
= (color
& 0x00ff0000) >> 16;
2055 green
= (color
& 0x0000ff00) >> 8;
2056 blue
= (color
& 0x000000ff);
2057 ok(red
== 0 && green
== 0 && blue
>= 0x7e && blue
<= 0x82, "Got color %08x, expected 00000080 or near\n", color
);
2062 if (Palette
) IDirectDrawPalette_Release(Palette
);
2063 if (TexSurface
) IDirectDrawSurface_Release(TexSurface
);
2064 if (Texture
) IDirect3DTexture_Release(Texture
);
2067 static void D3D1_ViewportClearTest(void)
2070 IDirect3DMaterial
*bgMaterial
= NULL
;
2072 D3DMATERIALHANDLE hMat
;
2073 D3DVIEWPORT vp_data
;
2074 IDirect3DViewport
*Viewport2
= NULL
;
2075 DWORD color
, red
, green
, blue
;
2077 hr
= IDirect3D_CreateMaterial(Direct3D1
, &bgMaterial
, NULL
);
2078 ok(hr
== D3D_OK
, "IDirect3D_CreateMaterial failed: %08x\n", hr
);
2083 hr
= IDirect3D_CreateViewport(Direct3D1
, &Viewport2
, NULL
);
2084 ok(hr
== D3D_OK
, "IDirect3D_CreateViewport failed: %08x\n", hr
);
2089 hr
= IDirect3DViewport_Initialize(Viewport2
, Direct3D1
);
2090 ok(hr
== D3D_OK
|| hr
== DDERR_ALREADYINITIALIZED
, "IDirect3DViewport_Initialize returned %08x\n", hr
);
2091 hr
= IDirect3DDevice_AddViewport(Direct3DDevice1
, Viewport2
);
2092 ok(hr
== D3D_OK
, "IDirect3DDevice_AddViewport returned %08x\n", hr
);
2093 vp_data
.dwSize
= sizeof(vp_data
);
2096 vp_data
.dwWidth
= 100;
2097 vp_data
.dwHeight
= 100;
2098 vp_data
.dvScaleX
= 1;
2099 vp_data
.dvScaleY
= 1;
2100 vp_data
.dvMaxX
= 100;
2101 vp_data
.dvMaxY
= 100;
2104 hr
= IDirect3DViewport_SetViewport(Viewport2
, &vp_data
);
2105 ok(hr
== D3D_OK
, "IDirect3DViewport_SetViewport returned %08x\n", hr
);
2107 memset(&mat
, 0, sizeof(mat
));
2108 mat
.dwSize
= sizeof(mat
);
2109 U1(U(mat
).diffuse
).r
= 1.0f
;
2110 hr
= IDirect3DMaterial_SetMaterial(bgMaterial
, &mat
);
2111 ok(hr
== D3D_OK
, "IDirect3DMaterial_SetMaterial failed: %08x\n", hr
);
2113 hr
= IDirect3DMaterial_GetHandle(bgMaterial
, Direct3DDevice1
, &hMat
);
2114 ok(hr
== D3D_OK
, "IDirect3DMaterial_GetHandle failed: %08x\n", hr
);
2116 hr
= IDirect3DViewport_SetBackground(Viewport
, hMat
);
2117 ok(hr
== D3D_OK
, "IDirect3DViewport_SetBackground failed: %08x\n", hr
);
2118 hr
= IDirect3DViewport_SetBackground(Viewport2
, hMat
);
2119 ok(hr
== D3D_OK
, "IDirect3DViewport_SetBackground failed: %08x\n", hr
);
2121 hr
= IDirect3DDevice_BeginScene(Direct3DDevice1
);
2122 ok(hr
== D3D_OK
, "IDirect3DDevice_BeginScene failed with %08x\n", hr
);
2124 if (SUCCEEDED(hr
)) {
2127 U1(rect
).x1
= U2(rect
).y1
= 0;
2131 hr
= IDirect3DViewport_Clear(Viewport
, 1, &rect
, D3DCLEAR_TARGET
);
2132 ok(hr
== D3D_OK
, "IDirect3DViewport_Clear failed: %08x\n", hr
);
2134 memset(&mat
, 0, sizeof(mat
));
2135 mat
.dwSize
= sizeof(mat
);
2136 U3(U(mat
).diffuse
).b
= 1.0f
;
2137 hr
= IDirect3DMaterial_SetMaterial(bgMaterial
, &mat
);
2138 ok(hr
== D3D_OK
, "IDirect3DMaterial_SetMaterial failed: %08x\n", hr
);
2140 hr
= IDirect3DViewport_Clear(Viewport2
, 1, &rect
, D3DCLEAR_TARGET
);
2141 ok(hr
== D3D_OK
, "IDirect3DViewport_Clear failed: %08x\n", hr
);
2143 hr
= IDirect3DDevice_EndScene(Direct3DDevice1
);
2144 ok(hr
== D3D_OK
, "IDirect3DDevice_EndScene failed, hr = %08x\n", hr
);
2147 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 5, 5);
2148 red
= (color
& 0x00ff0000) >> 16;
2149 green
= (color
& 0x0000ff00) >> 8;
2150 blue
= (color
& 0x000000ff);
2151 ok((red
== 0xff && green
== 0 && blue
== 0) ||
2152 broken(red
== 0 && green
== 0 && blue
== 0xff), /* VMware and some native boxes */
2153 "Got color %08x, expected 00ff0000\n", color
);
2155 color
= D3D1_getPixelColor(DirectDraw1
, Surface1
, 205, 205);
2156 red
= (color
& 0x00ff0000) >> 16;
2157 green
= (color
& 0x0000ff00) >> 8;
2158 blue
= (color
& 0x000000ff);
2159 ok(red
== 0 && green
== 0 && blue
== 0xff, "Got color %08x, expected 000000ff\n", color
);
2163 if (bgMaterial
) IDirect3DMaterial_Release(bgMaterial
);
2164 if (Viewport2
) IDirect3DViewport_Release(Viewport2
);
2167 static DWORD
D3D3_getPixelColor(IDirectDraw4
*DirectDraw
, IDirectDrawSurface4
*Surface
, UINT x
, UINT y
)
2171 DDSURFACEDESC2 ddsd
;
2172 RECT rectToLock
= {x
, y
, x
+1, y
+1};
2173 IDirectDrawSurface4
*surf
= NULL
;
2175 /* Some implementations seem to dislike direct locking on the front buffer. Thus copy the front buffer
2176 * to an offscreen surface and lock it instead of the front buffer
2178 memset(&ddsd
, 0, sizeof(ddsd
));
2179 ddsd
.dwSize
= sizeof(ddsd
);
2180 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
2181 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
2183 ddsd
.dwHeight
= 480;
2184 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
;
2185 hr
= IDirectDraw4_CreateSurface(DirectDraw
, &ddsd
, &surf
, NULL
);
2186 ok(hr
== DD_OK
, "IDirectDraw_CreateSurface failed with %08x\n", hr
);
2189 trace("cannot create helper surface\n");
2193 memset(&ddsd
, 0, sizeof(ddsd
));
2194 ddsd
.dwSize
= sizeof(ddsd
);
2195 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
2197 hr
= IDirectDrawSurface4_BltFast(surf
, 0, 0, Surface
, NULL
, 0);
2198 ok(hr
== DD_OK
, "IDirectDrawSurface_BltFast returned %08x\n", hr
);
2201 trace("Cannot blit\n");
2206 hr
= IDirectDrawSurface4_Lock(surf
, &rectToLock
, &ddsd
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
2209 trace("Can't lock the offscreen surface, hr=%08x\n", hr
);
2214 /* Remove the X channel for now. DirectX and OpenGL have different ideas how to treat it apparently, and it isn't
2215 * really important for these tests
2217 ret
= ((DWORD
*) ddsd
.lpSurface
)[0] & 0x00ffffff;
2218 hr
= IDirectDrawSurface4_Unlock(surf
, NULL
);
2221 trace("Can't unlock the offscreen surface, hr=%08x\n", hr
);
2225 IDirectDrawSurface4_Release(surf
);
2229 static void D3D3_ViewportClearTest(void)
2232 IDirectDraw
*DirectDraw1
= NULL
;
2233 IDirectDraw4
*DirectDraw4
= NULL
;
2234 IDirectDrawSurface4
*Primary
= NULL
;
2235 IDirect3D3
*Direct3D3
= NULL
;
2236 IDirect3DViewport3
*Viewport3
= NULL
;
2237 IDirect3DViewport3
*SmallViewport3
= NULL
;
2238 IDirect3DDevice3
*Direct3DDevice3
= NULL
;
2240 DDSURFACEDESC2 ddsd
;
2241 D3DVIEWPORT2 vp_data
;
2242 DWORD color
, red
, green
, blue
;
2246 1.0f
, 0.0f
, 0.0f
, 0.0f
,
2247 0.0f
, 1.0f
, 0.0f
, 0.0f
,
2248 0.0f
, 0.0f
, 1.0f
, 0.0f
,
2249 0.0f
, 0.0f
, 0.0f
, 1.0f
,
2253 struct vec3 position
;
2258 {{-1.0f
, -1.0f
, 0.1f
}, 0xffffffff},
2259 {{-1.0f
, 1.0f
, 0.1f
}, 0xffffffff},
2260 {{ 1.0f
, 1.0f
, 0.1f
}, 0xffffffff},
2261 {{ 1.0f
, -1.0f
, 0.1f
}, 0xffffffff},
2264 WORD Indices
[] = {0, 1, 2, 2, 3, 0};
2265 DWORD fvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
2267 wc
.lpfnWndProc
= DefWindowProcA
;
2268 wc
.lpszClassName
= "D3D3_ViewportClearTest_wc";
2269 RegisterClassA(&wc
);
2270 window
= CreateWindowA("D3D3_ViewportClearTest_wc", "D3D3_ViewportClearTest",
2271 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
2273 hr
= DirectDrawCreate( NULL
, &DirectDraw1
, NULL
);
2274 ok(hr
==DD_OK
|| hr
==DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreate returned: %x\n", hr
);
2275 if(FAILED(hr
)) goto out
;
2277 hr
= IDirectDraw_SetCooperativeLevel(DirectDraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2278 ok(hr
==DD_OK
, "SetCooperativeLevel returned: %x\n", hr
);
2279 if(FAILED(hr
)) goto out
;
2281 hr
= IDirectDraw_SetDisplayMode(DirectDraw1
, 640, 480, 32);
2283 /* 24 bit is fine too */
2284 hr
= IDirectDraw_SetDisplayMode(DirectDraw1
, 640, 480, 24);
2286 ok(hr
==DD_OK
|| hr
== DDERR_UNSUPPORTED
, "SetDisplayMode returned: %x\n", hr
);
2287 if (FAILED(hr
)) goto out
;
2289 hr
= IDirectDraw_QueryInterface(DirectDraw1
, &IID_IDirectDraw4
, (void**)&DirectDraw4
);
2290 ok(hr
==DD_OK
, "QueryInterface returned: %08x\n", hr
);
2291 if(FAILED(hr
)) goto out
;
2293 memset(&ddsd
, 0, sizeof(DDSURFACEDESC2
));
2294 ddsd
.dwSize
= sizeof(DDSURFACEDESC2
);
2295 ddsd
.dwFlags
= DDSD_CAPS
;
2296 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
;
2298 hr
= IDirectDraw_CreateSurface(DirectDraw4
, &ddsd
, &Primary
, NULL
);
2299 ok(hr
==DD_OK
, "IDirectDraw_CreateSurface returned: %08x\n", hr
);
2300 if(FAILED(hr
)) goto out
;
2302 hr
= IDirectDraw4_QueryInterface(DirectDraw4
, &IID_IDirect3D3
, (void**)&Direct3D3
);
2303 ok(hr
==DD_OK
, "IDirectDraw4_QueryInterface returned: %08x\n", hr
);
2304 if(FAILED(hr
)) goto out
;
2306 hr
= IDirect3D3_CreateDevice(Direct3D3
, &IID_IDirect3DHALDevice
, Primary
, &Direct3DDevice3
, NULL
);
2308 trace("Creating a HAL device failed, trying Ref\n");
2309 hr
= IDirect3D3_CreateDevice(Direct3D3
, &IID_IDirect3DRefDevice
, Primary
, &Direct3DDevice3
, NULL
);
2311 ok(hr
==D3D_OK
, "Creating 3D device returned: %x\n", hr
);
2312 if(FAILED(hr
)) goto out
;
2314 hr
= IDirect3D3_CreateViewport(Direct3D3
, &Viewport3
, NULL
);
2315 ok(hr
==DD_OK
, "IDirect3D3_CreateViewport returned: %08x\n", hr
);
2316 if(FAILED(hr
)) goto out
;
2318 hr
= IDirect3DDevice3_AddViewport(Direct3DDevice3
, Viewport3
);
2319 ok(hr
==DD_OK
, "IDirect3DDevice3_AddViewport returned: %08x\n", hr
);
2321 memset(&vp_data
, 0, sizeof(D3DVIEWPORT2
));
2322 vp_data
.dwSize
= sizeof(D3DVIEWPORT2
);
2323 vp_data
.dwWidth
= 640;
2324 vp_data
.dwHeight
= 480;
2325 vp_data
.dvClipX
= -1.0f
;
2326 vp_data
.dvClipWidth
= 2.0f
;
2327 vp_data
.dvClipY
= 1.0f
;
2328 vp_data
.dvClipHeight
= 2.0f
;
2329 vp_data
.dvMaxZ
= 1.0f
;
2330 hr
= IDirect3DViewport3_SetViewport2(Viewport3
, &vp_data
);
2331 ok(hr
==DD_OK
, "IDirect3DViewport3_SetViewport2 returned: %08x\n", hr
);
2333 hr
= IDirect3D3_CreateViewport(Direct3D3
, &SmallViewport3
, NULL
);
2334 ok(hr
==DD_OK
, "IDirect3D3_CreateViewport returned: %08x\n", hr
);
2335 if(FAILED(hr
)) goto out
;
2337 hr
= IDirect3DDevice3_AddViewport(Direct3DDevice3
, SmallViewport3
);
2338 ok(hr
==DD_OK
, "IDirect3DDevice3_AddViewport returned: %08x\n", hr
);
2340 memset(&vp_data
, 0, sizeof(D3DVIEWPORT2
));
2341 vp_data
.dwSize
= sizeof(D3DVIEWPORT2
);
2344 vp_data
.dwWidth
= 100;
2345 vp_data
.dwHeight
= 100;
2346 vp_data
.dvClipX
= -1.0f
;
2347 vp_data
.dvClipWidth
= 2.0f
;
2348 vp_data
.dvClipY
= 1.0f
;
2349 vp_data
.dvClipHeight
= 2.0f
;
2350 vp_data
.dvMaxZ
= 1.0f
;
2351 hr
= IDirect3DViewport3_SetViewport2(SmallViewport3
, &vp_data
);
2352 ok(hr
==DD_OK
, "IDirect3DViewport3_SetViewport2 returned: %08x\n", hr
);
2354 hr
= IDirect3DDevice3_BeginScene(Direct3DDevice3
);
2355 ok(hr
== D3D_OK
, "IDirect3DDevice3_BeginScene failed with %08x\n", hr
);
2357 hr
= IDirect3DDevice3_SetTransform(Direct3DDevice3
, D3DTRANSFORMSTATE_WORLD
, &mat
);
2358 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetTransform returned %08x\n", hr
);
2359 hr
= IDirect3DDevice3_SetTransform(Direct3DDevice3
, D3DTRANSFORMSTATE_VIEW
, &mat
);
2360 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetTransform returned %08x\n", hr
);
2361 hr
= IDirect3DDevice3_SetTransform(Direct3DDevice3
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
2362 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetTransform returned %08x\n", hr
);
2363 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_CLIPPING
, FALSE
);
2364 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState returned %08x\n", hr
);
2365 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_ZENABLE
, FALSE
);
2366 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState returned %08x\n", hr
);
2367 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
2368 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState returned %08x\n", hr
);
2369 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_STENCILENABLE
, FALSE
);
2370 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState returned %08x\n", hr
);
2371 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_ALPHATESTENABLE
, FALSE
);
2372 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState returned %08x\n", hr
);
2373 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
);
2374 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState returned %08x\n", hr
);
2375 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
2376 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState failed with %08x\n", hr
);
2377 hr
= IDirect3DDevice3_SetRenderState(Direct3DDevice3
, D3DRENDERSTATE_LIGHTING
, FALSE
);
2378 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetRenderState returned %08x\n", hr
);
2380 if (SUCCEEDED(hr
)) {
2381 U1(rect
).x1
= U2(rect
).y1
= 0;
2385 hr
= IDirect3DViewport3_Clear2(Viewport3
, 1, &rect
, D3DCLEAR_TARGET
, 0x00ff00, 0.0f
, 0);
2386 ok(hr
== D3D_OK
, "IDirect3DViewport3_Clear2 failed, hr = %08x\n", hr
);
2388 hr
= IDirect3DViewport3_Clear2(SmallViewport3
, 1, &rect
, D3DCLEAR_TARGET
, 0xff0000, 0.0f
, 0);
2389 ok(hr
== D3D_OK
, "IDirect3DViewport3_Clear2 failed, hr = %08x\n", hr
);
2391 hr
= IDirect3DDevice3_EndScene(Direct3DDevice3
);
2392 ok(hr
== D3D_OK
, "IDirect3DDevice3_EndScene failed, hr = %08x\n", hr
);
2395 color
= D3D3_getPixelColor(DirectDraw4
, Primary
, 5, 5);
2396 red
= (color
& 0x00ff0000) >> 16;
2397 green
= (color
& 0x0000ff00) >> 8;
2398 blue
= (color
& 0x000000ff);
2399 ok(red
== 0 && green
== 0xff && blue
== 0, "Got color %08x, expected 0000ff00\n", color
);
2401 color
= D3D3_getPixelColor(DirectDraw4
, Primary
, 405, 105);
2402 red
= (color
& 0x00ff0000) >> 16;
2403 green
= (color
& 0x0000ff00) >> 8;
2404 blue
= (color
& 0x000000ff);
2405 ok(red
== 0xff && green
== 0 && blue
== 0, "Got color %08x, expected 00ff0000\n", color
);
2407 /* Test that clearing viewport doesn't interfere with rendering to previously active viewport. */
2408 hr
= IDirect3DDevice3_BeginScene(Direct3DDevice3
);
2409 ok(hr
== D3D_OK
, "IDirect3DDevice3_BeginScene failed with %08x\n", hr
);
2411 if (SUCCEEDED(hr
)) {
2412 hr
= IDirect3DDevice3_SetCurrentViewport(Direct3DDevice3
, SmallViewport3
);
2413 ok(hr
== D3D_OK
, "IDirect3DDevice3_SetCurrentViewport failed with %08x\n", hr
);
2415 hr
= IDirect3DViewport3_Clear2(Viewport3
, 1, &rect
, D3DCLEAR_TARGET
, 0x000000, 0.0f
, 0);
2416 ok(hr
== D3D_OK
, "IDirect3DViewport3_Clear2 failed, hr = %08x\n", hr
);
2418 hr
= IDirect3DDevice3_DrawIndexedPrimitive(Direct3DDevice3
, D3DPT_TRIANGLELIST
, fvf
, quad
, 4 /* NumVerts */,
2419 Indices
, 6 /* Indexcount */, 0 /* flags */);
2420 ok(hr
== D3D_OK
, "IDirect3DDevice3_DrawIndexedPrimitive failed with %08x\n", hr
);
2422 hr
= IDirect3DDevice3_EndScene(Direct3DDevice3
);
2423 ok(hr
== D3D_OK
, "IDirect3DDevice3_EndScene failed, hr = %08x\n", hr
);
2426 color
= D3D3_getPixelColor(DirectDraw4
, Primary
, 5, 5);
2427 red
= (color
& 0x00ff0000) >> 16;
2428 green
= (color
& 0x0000ff00) >> 8;
2429 blue
= (color
& 0x000000ff);
2430 ok(red
== 0 && green
== 0 && blue
== 0, "Got color %08x, expected 00000000\n", color
);
2432 color
= D3D3_getPixelColor(DirectDraw4
, Primary
, 405, 105);
2433 red
= (color
& 0x00ff0000) >> 16;
2434 green
= (color
& 0x0000ff00) >> 8;
2435 blue
= (color
& 0x000000ff);
2436 ok(red
== 0xff && green
== 0xff && blue
== 0xff, "Got color %08x, expected 00ffffff\n", color
);
2440 if (SmallViewport3
) IDirect3DViewport3_Release(SmallViewport3
);
2441 if (Viewport3
) IDirect3DViewport3_Release(Viewport3
);
2442 if (Direct3DDevice3
) IDirect3DDevice3_Release(Direct3DDevice3
);
2443 if (Direct3D3
) IDirect3D3_Release(Direct3D3
);
2444 if (Primary
) IDirectDrawSurface4_Release(Primary
);
2445 if (DirectDraw1
) IDirectDraw_Release(DirectDraw1
);
2446 if (DirectDraw4
) IDirectDraw4_Release(DirectDraw4
);
2447 if(window
) DestroyWindow(window
);
2450 static void p8_surface_fill_rect(IDirectDrawSurface
*dest
, UINT x
, UINT y
, UINT w
, UINT h
, BYTE colorindex
)
2457 memset(&ddsd
, 0, sizeof(ddsd
));
2458 ddsd
.dwSize
= sizeof(ddsd
);
2460 hr
= IDirectDrawSurface_Lock(dest
, NULL
, &ddsd
, DDLOCK_WRITEONLY
| DDLOCK_WAIT
, NULL
);
2461 ok(hr
==DD_OK
, "IDirectDrawSurface_Lock returned: %x\n", hr
);
2463 p
= (BYTE
*)ddsd
.lpSurface
+ U1(ddsd
).lPitch
* y
+ x
;
2465 for (i
= 0; i
< h
; i
++) {
2466 for (i1
= 0; i1
< w
; i1
++) {
2469 p
+= U1(ddsd
).lPitch
;
2472 hr
= IDirectDrawSurface_Unlock(dest
, NULL
);
2473 ok(hr
==DD_OK
, "IDirectDrawSurface_UnLock returned: %x\n", hr
);
2476 static COLORREF
getPixelColor_GDI(IDirectDrawSurface
*Surface
, UINT x
, UINT y
)
2478 COLORREF clr
= CLR_INVALID
;
2482 hr
= IDirectDrawSurface_GetDC(Surface
, &hdc
);
2483 ok(hr
==DD_OK
, "IDirectDrawSurface_GetDC returned: %x\n", hr
);
2485 if (SUCCEEDED(hr
)) {
2486 clr
= GetPixel(hdc
, x
, y
);
2488 hr
= IDirectDrawSurface_ReleaseDC(Surface
, hdc
);
2489 ok(hr
==DD_OK
, "IDirectDrawSurface_ReleaseDC returned: %x\n", hr
);
2495 static BOOL
colortables_check_equality(PALETTEENTRY table1
[256], RGBQUAD table2
[256])
2499 for (i
= 0; i
< 256; i
++) {
2500 if (table1
[i
].peRed
!= table2
[i
].rgbRed
|| table1
[i
].peGreen
!= table2
[i
].rgbGreen
||
2501 table1
[i
].peBlue
!= table2
[i
].rgbBlue
) return FALSE
;
2507 static void p8_primary_test(void)
2509 /* Test 8bit mode used by games like StarCraft, C&C Red Alert I etc */
2513 PALETTEENTRY entries
[256];
2514 RGBQUAD coltable
[256];
2516 IDirectDrawPalette
*ddprimpal
= NULL
;
2517 IDirectDrawSurface
*offscreen
= NULL
;
2523 unsigned differences
;
2525 /* An IDirect3DDevice cannot be queryInterfaced from an IDirect3DDevice7 on windows */
2526 hr
= DirectDrawCreate(NULL
, &DirectDraw1
, NULL
);
2528 ok(hr
==DD_OK
|| hr
==DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreate returned: %x\n", hr
);
2533 wc
.lpfnWndProc
= DefWindowProcA
;
2534 wc
.lpszClassName
= "p8_primary_test_wc";
2535 RegisterClassA(&wc
);
2536 window
= CreateWindowA("p8_primary_test_wc", "p8_primary_test",
2537 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
2539 hr
= IDirectDraw_SetCooperativeLevel(DirectDraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2540 ok(hr
==DD_OK
, "SetCooperativeLevel returned: %x\n", hr
);
2545 hr
= IDirectDraw_SetDisplayMode(DirectDraw1
, 640, 480, 8);
2546 ok(hr
==DD_OK
|| hr
== DDERR_UNSUPPORTED
, "SetDisplayMode returned: %x\n", hr
);
2551 memset(&ddsd
, 0, sizeof(ddsd
));
2552 ddsd
.dwSize
= sizeof(ddsd
);
2553 ddsd
.dwFlags
= DDSD_CAPS
;
2554 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2555 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &Surface1
, NULL
);
2556 ok(hr
==DD_OK
, "CreateSurface returned: %x\n", hr
);
2561 memset(entries
, 0, sizeof(entries
));
2562 entries
[0].peRed
= 0xff;
2563 entries
[1].peGreen
= 0xff;
2564 entries
[2].peBlue
= 0xff;
2566 hr
= IDirectDraw_CreatePalette(DirectDraw1
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, entries
, &ddprimpal
, NULL
);
2567 ok(hr
== DD_OK
, "CreatePalette returned %08x\n", hr
);
2569 skip("IDirectDraw_CreatePalette failed; skipping further tests\n");
2573 hr
= IDirectDrawSurface_SetPalette(Surface1
, ddprimpal
);
2574 ok(hr
==DD_OK
, "IDirectDrawSurface_SetPalette returned: %x\n", hr
);
2576 p8_surface_fill_rect(Surface1
, 0, 0, 640, 480, 2);
2578 color
= getPixelColor_GDI(Surface1
, 10, 10);
2579 ok(GetRValue(color
) == 0 && GetGValue(color
) == 0 && GetBValue(color
) == 0xFF,
2580 "got R %02X G %02X B %02X, expected R 00 G 00 B FF\n",
2581 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2583 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
2584 ddbltfx
.dwSize
= sizeof(ddbltfx
);
2585 U5(ddbltfx
).dwFillColor
= 0;
2586 hr
= IDirectDrawSurface_Blt(Surface1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
2587 ok(hr
== DD_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
2589 color
= getPixelColor_GDI(Surface1
, 10, 10);
2590 ok(GetRValue(color
) == 0xFF && GetGValue(color
) == 0 && GetBValue(color
) == 0,
2591 "got R %02X G %02X B %02X, expected R FF G 00 B 00\n",
2592 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2594 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
2595 ddbltfx
.dwSize
= sizeof(ddbltfx
);
2596 U5(ddbltfx
).dwFillColor
= 1;
2597 hr
= IDirectDrawSurface_Blt(Surface1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
2598 ok(hr
== DD_OK
, "IDirectDrawSurface_Blt failed with %08x\n", hr
);
2600 color
= getPixelColor_GDI(Surface1
, 10, 10);
2601 ok(GetRValue(color
) == 0 && GetGValue(color
) == 0xFF && GetBValue(color
) == 0,
2602 "got R %02X G %02X B %02X, expected R 00 G FF B 00\n",
2603 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2605 memset (&ddsd
, 0, sizeof (ddsd
));
2606 ddsd
.dwSize
= sizeof (ddsd
);
2607 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
2610 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
;
2611 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
2612 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_PALETTEINDEXED8
;
2613 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 8;
2614 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &offscreen
, NULL
);
2616 broken(hr
== DDERR_INVALIDPIXELFORMAT
) || /* VMware */
2617 broken(hr
== DDERR_NODIRECTDRAWHW
), /* VMware */
2618 "IDirectDraw_CreateSurface returned %08x\n", hr
);
2619 if (FAILED(hr
)) goto out
;
2621 memset(entries
, 0, sizeof(entries
));
2622 for (i
= 0; i
< 256; i
++) {
2623 entries
[i
].peBlue
= i
;
2625 hr
= IDirectDrawPalette_SetEntries(ddprimpal
, 0, 0, 256, entries
);
2626 ok(hr
== DD_OK
, "IDirectDrawPalette_SetEntries failed with %08x\n", hr
);
2628 hr
= IDirectDrawSurface_GetDC(offscreen
, &hdc
);
2629 ok(hr
==DD_OK
, "IDirectDrawSurface_GetDC returned: %x\n", hr
);
2630 i
= GetDIBColorTable(hdc
, 0, 256, coltable
);
2631 ok(i
== 256, "GetDIBColorTable returned %u, last error: %x\n", i
, GetLastError());
2632 hr
= IDirectDrawSurface_ReleaseDC(offscreen
, hdc
);
2633 ok(hr
==DD_OK
, "IDirectDrawSurface_ReleaseDC returned: %x\n", hr
);
2635 ok(colortables_check_equality(entries
, coltable
), "unexpected colortable on offscreen surface\n");
2637 p8_surface_fill_rect(offscreen
, 0, 0, 16, 16, 2);
2639 memset(entries
, 0, sizeof(entries
));
2640 entries
[0].peRed
= 0xff;
2641 entries
[1].peGreen
= 0xff;
2642 entries
[2].peBlue
= 0xff;
2643 entries
[3].peRed
= 0x80;
2644 hr
= IDirectDrawPalette_SetEntries(ddprimpal
, 0, 0, 256, entries
);
2645 ok(hr
== DD_OK
, "IDirectDrawPalette_SetEntries failed with %08x\n", hr
);
2647 hr
= IDirectDrawSurface_BltFast(Surface1
, 0, 0, offscreen
, NULL
, 0);
2648 ok(hr
==DD_OK
, "IDirectDrawSurface_BltFast returned: %x\n", hr
);
2650 color
= getPixelColor_GDI(Surface1
, 1, 1);
2651 ok(GetRValue(color
) == 0 && GetGValue(color
) == 0x00 && GetBValue(color
) == 0xFF,
2652 "got R %02X G %02X B %02X, expected R 00 G 00 B FF\n",
2653 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2655 /* Color keyed blit. */
2656 p8_surface_fill_rect(offscreen
, 0, 0, 8, 8, 3);
2657 clrKey
.dwColorSpaceLowValue
= 3;
2658 clrKey
.dwColorSpaceHighValue
= 3;
2659 hr
= IDirectDrawSurface_SetColorKey(offscreen
, DDCKEY_SRCBLT
, &clrKey
);
2660 ok(hr
==D3D_OK
, "IDirectDrawSurfac_SetColorKey returned: %x\n", hr
);
2662 hr
= IDirectDrawSurface_BltFast(Surface1
, 100, 100, offscreen
, NULL
, DDBLTFAST_SRCCOLORKEY
);
2663 ok(hr
==DD_OK
, "IDirectDrawSurface_BltFast returned: %x\n", hr
);
2665 color
= getPixelColor_GDI(Surface1
, 105, 105);
2666 ok(GetRValue(color
) == 0 && GetGValue(color
) == 0xFF && GetBValue(color
) == 0,
2667 "got R %02X G %02X B %02X, expected R 00 G FF B 00\n",
2668 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2670 color
= getPixelColor_GDI(Surface1
, 112, 112);
2671 ok(GetRValue(color
) == 0 && GetGValue(color
) == 0x00 && GetBValue(color
) == 0xFF,
2672 "got R %02X G %02X B %02X, expected R 00 G 00 B FF\n",
2673 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2680 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
2681 ddbltfx
.dwSize
= sizeof(ddbltfx
);
2682 ddbltfx
.ddckSrcColorkey
.dwColorSpaceLowValue
= ddbltfx
.ddckSrcColorkey
.dwColorSpaceHighValue
= 2;
2683 hr
= IDirectDrawSurface_Blt(Surface1
, &rect
, offscreen
, NULL
,
2684 DDBLT_WAIT
| DDBLT_KEYSRC
| DDBLT_KEYSRCOVERRIDE
, &ddbltfx
);
2685 ok(hr
==DDERR_INVALIDPARAMS
, "IDirectDrawSurface_Blt returned: %x\n", hr
);
2686 hr
= IDirectDrawSurface_Blt(Surface1
, &rect
, offscreen
, NULL
,
2687 DDBLT_WAIT
| DDBLT_KEYSRCOVERRIDE
, &ddbltfx
);
2688 ok(hr
==DD_OK
, "IDirectDrawSurface_Blt returned: %x\n", hr
);
2690 color
= getPixelColor_GDI(Surface1
, 105, 205);
2691 ok(GetRValue(color
) == 0x80 && GetGValue(color
) == 0 && GetBValue(color
) == 0,
2692 "got R %02X G %02X B %02X, expected R 80 G 00 B 00\n",
2693 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2695 color
= getPixelColor_GDI(Surface1
, 112, 212);
2696 ok(GetRValue(color
) == 0 && GetGValue(color
) == 0xFF && GetBValue(color
) == 0,
2697 "got R %02X G %02X B %02X, expected R 00 G FF B 00\n",
2698 GetRValue(color
), GetGValue(color
), GetBValue(color
));
2700 /* Test blitting and locking patterns that are likely to trigger bugs in opengl renderer (p8
2701 surface conversion and uploading/downloading to/from opengl texture). Similar patterns (
2702 blitting front buffer areas to/from an offscreen surface mixed with locking) are used by C&C
2704 IDirectDrawSurface_Release(offscreen
);
2706 memset (&ddsd
, 0, sizeof (ddsd
));
2707 ddsd
.dwSize
= sizeof (ddsd
);
2708 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
2710 ddsd
.dwHeight
= 480;
2711 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
2712 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
2713 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_PALETTEINDEXED8
;
2714 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 8;
2715 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &offscreen
, NULL
);
2716 ok(hr
== DD_OK
, "IDirectDraw_CreateSurface returned %08x\n", hr
);
2718 if (FAILED(hr
)) goto out
;
2720 /* Test two times, first time front buffer has a palette and second time front buffer
2721 has no palette; the latter is somewhat contrived example, but an app could set
2722 front buffer palette later. */
2723 for (i2
= 0; i2
< 2; i2
++) {
2725 hr
= IDirectDrawSurface_SetPalette(Surface1
, NULL
);
2726 ok(hr
==DD_OK
, "IDirectDrawSurface_SetPalette returned: %x\n", hr
);
2729 memset(&ddsd
, 0, sizeof(ddsd
));
2730 ddsd
.dwSize
= sizeof(ddsd
);
2731 hr
= IDirectDrawSurface_Lock(Surface1
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
2732 ok(hr
==DD_OK
, "IDirectDrawSurface_Lock returned: %x\n", hr
);
2734 for (i
= 0; i
< 256; i
++) {
2735 unsigned x
= (i
% 128) * 4;
2736 unsigned y
= (i
/ 128) * 4;
2737 BYTE
*p
= (BYTE
*)ddsd
.lpSurface
+ U1(ddsd
).lPitch
* y
+ x
;
2739 for (i1
= 0; i1
< 4; i1
++) {
2740 p
[0] = p
[1] = p
[2] = p
[3] = i
;
2741 p
+= U1(ddsd
).lPitch
;
2745 hr
= IDirectDrawSurface_Unlock(Surface1
, NULL
);
2746 ok(hr
==DD_OK
, "IDirectDrawSurface_UnLock returned: %x\n", hr
);
2748 hr
= IDirectDrawSurface_BltFast(offscreen
, 0, 0, Surface1
, NULL
, 0);
2749 ok(hr
==DD_OK
, "IDirectDrawSurface_BltFast returned: %x\n", hr
);
2751 /* This ensures offscreen surface contents will be downloaded to system memory. */
2752 memset(&ddsd
, 0, sizeof(ddsd
));
2753 ddsd
.dwSize
= sizeof(ddsd
);
2754 hr
= IDirectDrawSurface_Lock(offscreen
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
2755 ok(hr
==DD_OK
, "IDirectDrawSurface_Lock returned: %x\n", hr
);
2756 hr
= IDirectDrawSurface_Unlock(offscreen
, NULL
);
2757 ok(hr
==DD_OK
, "IDirectDrawSurface_UnLock returned: %x\n", hr
);
2759 /* Offscreen surface data will have to be converted and uploaded to texture. */
2764 hr
= IDirectDrawSurface_BltFast(offscreen
, 600, 400, Surface1
, &rect
, 0);
2765 ok(hr
==DD_OK
, "IDirectDrawSurface_BltFast returned: %x\n", hr
);
2767 /* This ensures offscreen surface contents will be downloaded to system memory. */
2768 memset(&ddsd
, 0, sizeof(ddsd
));
2769 ddsd
.dwSize
= sizeof(ddsd
);
2770 hr
= IDirectDrawSurface_Lock(offscreen
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
2771 ok(hr
==DD_OK
, "IDirectDrawSurface_Lock returned: %x\n", hr
);
2772 hr
= IDirectDrawSurface_Unlock(offscreen
, NULL
);
2773 ok(hr
==DD_OK
, "IDirectDrawSurface_UnLock returned: %x\n", hr
);
2775 hr
= IDirectDrawSurface_BltFast(Surface1
, 0, 0, offscreen
, NULL
, 0);
2776 ok(hr
==DD_OK
, "IDirectDrawSurface_BltFast returned: %x\n", hr
);
2778 memset(&ddsd
, 0, sizeof(ddsd
));
2779 ddsd
.dwSize
= sizeof(ddsd
);
2780 hr
= IDirectDrawSurface_Lock(Surface1
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
2781 ok(hr
==DD_OK
, "IDirectDrawSurface_Lock returned: %x\n", hr
);
2785 for (i
= 0; i
< 256; i
++) {
2786 unsigned x
= (i
% 128) * 4 + 1;
2787 unsigned y
= (i
/ 128) * 4 + 1;
2788 BYTE
*p
= (BYTE
*)ddsd
.lpSurface
+ U1(ddsd
).lPitch
* y
+ x
;
2790 if (*p
!= i
) differences
++;
2793 hr
= IDirectDrawSurface_Unlock(Surface1
, NULL
);
2794 ok(hr
==DD_OK
, "IDirectDrawSurface_UnLock returned: %x\n", hr
);
2796 ok(differences
== 0, i2
== 0 ? "Pass 1. Unexpected front buffer contents after blit (%u differences)\n" :
2797 "Pass 2 (with NULL front buffer palette). Unexpected front buffer contents after blit (%u differences)\n",
2803 if(ddprimpal
) IDirectDrawPalette_Release(ddprimpal
);
2804 if(offscreen
) IDirectDrawSurface_Release(offscreen
);
2805 if(Surface1
) IDirectDrawSurface_Release(Surface1
);
2806 if(DirectDraw1
) IDirectDraw_Release(DirectDraw1
);
2807 if(window
) DestroyWindow(window
);
2810 static void cubemap_test(IDirect3DDevice7
*device
)
2813 IDirectDraw7
*ddraw
;
2814 IDirectDrawSurface7
*cubemap
, *surface
;
2815 D3DDEVICEDESC7 d3dcaps
;
2818 DDSURFACEDESC2 ddsd
;
2821 static float quad
[] = {
2822 -1.0, -1.0, 0.1, 1.0, 0.0, 0.0, /* Lower left */
2823 0.0, -1.0, 0.1, 1.0, 0.0, 0.0,
2824 -1.0, 0.0, 0.1, 1.0, 0.0, 0.0,
2825 0.0, 0.0, 0.1, 1.0, 0.0, 0.0,
2827 0.0, -1.0, 0.1, 0.0, 1.0, 0.0, /* Lower right */
2828 1.0, -1.0, 0.1, 0.0, 1.0, 0.0,
2829 0.0, 0.0, 0.1, 0.0, 1.0, 0.0,
2830 1.0, 0.0, 0.1, 0.0, 1.0, 0.0,
2832 0.0, 0.0, 0.1, 0.0, 0.0, 1.0, /* upper right */
2833 1.0, 0.0, 0.1, 0.0, 0.0, 1.0,
2834 0.0, 1.0, 0.1, 0.0, 0.0, 1.0,
2835 1.0, 1.0, 0.1, 0.0, 0.0, 1.0,
2837 -1.0, 0.0, 0.1, -1.0, 0.0, 0.0, /* Upper left */
2838 0.0, 0.0, 0.1, -1.0, 0.0, 0.0,
2839 -1.0, 1.0, 0.1, -1.0, 0.0, 0.0,
2840 0.0, 1.0, 0.1, -1.0, 0.0, 0.0,
2843 memset(&DDBltFx
, 0, sizeof(DDBltFx
));
2844 DDBltFx
.dwSize
= sizeof(DDBltFx
);
2846 memset(&d3dcaps
, 0, sizeof(d3dcaps
));
2847 hr
= IDirect3DDevice7_GetCaps(device
, &d3dcaps
);
2848 ok(hr
== D3D_OK
, "IDirect3DDevice7_GetCaps returned %08x\n", hr
);
2849 if(!(d3dcaps
.dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_CUBEMAP
))
2851 skip("No cubemap support\n");
2855 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff000000, 0.0, 0);
2856 ok(hr
== D3D_OK
, "IDirect3DDevice7_Clear failed with %08x\n", hr
);
2858 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
2859 ok(hr
== D3D_OK
, "IDirect3DDevice7_GetDirect3D returned %08x\n", hr
);
2860 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **) &ddraw
);
2861 ok(hr
== D3D_OK
, "IDirect3D7_QueryInterface returned %08x\n", hr
);
2862 IDirect3D7_Release(d3d
);
2865 memset(&ddsd
, 0, sizeof(ddsd
));
2866 ddsd
.dwSize
= sizeof(ddsd
);
2867 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
2868 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
;
2871 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
;
2872 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
| DDSCAPS2_TEXTUREMANAGE
;
2873 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
2874 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
2875 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00FF0000;
2876 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000FF00;
2877 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000FF;
2879 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &cubemap
, NULL
);
2880 ok(hr
== DD_OK
, "IDirectDraw7_CreateSurface returned %08x\n", hr
);
2881 IDirectDraw7_Release(ddraw
);
2884 U5(DDBltFx
).dwFillColor
= 0x00ff0000;
2885 hr
= IDirectDrawSurface7_Blt(cubemap
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
, &DDBltFx
);
2886 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
2888 memset(&caps
, 0, sizeof(caps
));
2889 caps
.dwCaps
= DDSCAPS_TEXTURE
;
2890 caps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_NEGATIVEX
;
2891 hr
= IDirectDrawSurface_GetAttachedSurface(cubemap
, &caps
, &surface
);
2892 ok(hr
== DD_OK
, "IDirectDrawSurface7_Lock returned %08x\n", hr
);
2893 U5(DDBltFx
).dwFillColor
= 0x0000ffff;
2894 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
, &DDBltFx
);
2895 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
2897 caps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_NEGATIVEZ
;
2898 hr
= IDirectDrawSurface_GetAttachedSurface(cubemap
, &caps
, &surface
);
2899 ok(hr
== DD_OK
, "IDirectDrawSurface7_Lock returned %08x\n", hr
);
2900 U5(DDBltFx
).dwFillColor
= 0x0000ff00;
2901 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
, &DDBltFx
);
2902 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
2904 caps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_POSITIVEZ
;
2905 hr
= IDirectDrawSurface_GetAttachedSurface(cubemap
, &caps
, &surface
);
2906 ok(hr
== DD_OK
, "IDirectDrawSurface7_Lock returned %08x\n", hr
);
2907 U5(DDBltFx
).dwFillColor
= 0x000000ff;
2908 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
, &DDBltFx
);
2909 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
2911 caps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_NEGATIVEY
;
2912 hr
= IDirectDrawSurface_GetAttachedSurface(cubemap
, &caps
, &surface
);
2913 ok(hr
== DD_OK
, "IDirectDrawSurface7_Lock returned %08x\n", hr
);
2914 U5(DDBltFx
).dwFillColor
= 0x00ffff00;
2915 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
, &DDBltFx
);
2916 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
2918 caps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_POSITIVEY
;
2919 hr
= IDirectDrawSurface_GetAttachedSurface(cubemap
, &caps
, &surface
);
2920 ok(hr
== DD_OK
, "IDirectDrawSurface7_Lock returned %08x\n", hr
);
2921 U5(DDBltFx
).dwFillColor
= 0x00ff00ff;
2922 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
, &DDBltFx
);
2923 ok(hr
== DD_OK
, "IDirectDrawSurface7_Blt returned %08x\n", hr
);
2925 hr
= IDirect3DDevice7_SetTexture(device
, 0, cubemap
);
2926 ok(hr
== DD_OK
, "IDirect3DDevice7_SetTexture returned %08x\n", hr
);
2927 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
2928 ok(hr
== DD_OK
, "IDirect3DDevice7_SetTextureStageState returned %08x\n", hr
);
2929 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
2930 ok(hr
== DD_OK
, "IDirect3DDevice7_SetTextureStageState returned %08x\n", hr
);
2932 hr
= IDirect3DDevice7_BeginScene(device
);
2933 ok(hr
== DD_OK
, "IDirect3DDevice7_BeginScene returned %08x\n", hr
);
2936 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1
, quad
+ 0 * 6, 4, 0);
2937 if (hr
== DDERR_UNSUPPORTED
|| hr
== DDERR_NODIRECTDRAWHW
)
2940 win_skip("IDirect3DDevice7_DrawPrimitive is not completely implemented, colors won't be tested\n");
2941 hr
= IDirect3DDevice7_EndScene(device
);
2942 ok(hr
== DD_OK
, "IDirect3DDevice7_EndScene returned %08x\n", hr
);
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
+ 4 * 6, 4, 0);
2947 ok(hr
== DD_OK
, "IDirect3DDevice7_DrawPrimitive returned %08x\n", hr
);
2948 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1
, quad
+ 8 * 6, 4, 0);
2949 ok(hr
== DD_OK
, "IDirect3DDevice7_DrawPrimitive returned %08x\n", hr
);
2950 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEX1
, quad
+ 12* 6, 4, 0);
2951 ok(hr
== DD_OK
, "IDirect3DDevice7_DrawPrimitive returned %08x\n", hr
);
2953 hr
= IDirect3DDevice7_EndScene(device
);
2954 ok(hr
== DD_OK
, "IDirect3DDevice7_EndScene returned %08x\n", hr
);
2956 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
2957 ok(hr
== DD_OK
, "IDirect3DDevice7_SetTextureStageState returned %08x\n", hr
);
2959 color
= getPixelColor(device
, 160, 360); /* lower left quad - positivex */
2960 ok(color
== 0x00ff0000, "DDSCAPS2_CUBEMAP_POSITIVEX has color 0x%08x, expected 0x00ff0000\n", color
);
2961 color
= getPixelColor(device
, 160, 120); /* upper left quad - negativex */
2962 ok(color
== 0x0000ffff, "DDSCAPS2_CUBEMAP_NEGATIVEX has color 0x%08x, expected 0x0000ffff\n", color
);
2963 color
= getPixelColor(device
, 480, 360); /* lower right quad - positivey */
2964 ok(color
== 0x00ff00ff, "DDSCAPS2_CUBEMAP_POSITIVEY has color 0x%08x, expected 0x00ff00ff\n", color
);
2965 color
= getPixelColor(device
, 480, 120); /* upper right quad - positivez */
2966 ok(color
== 0x000000ff, "DDSCAPS2_CUBEMAP_POSITIVEZ has color 0x%08x, expected 0x000000ff\n", color
);
2969 hr
= IDirect3DDevice7_SetTexture(device
, 0, NULL
);
2970 ok(hr
== DD_OK
, "IDirect3DDevice7_SetTexture returned %08x\n", hr
);
2971 IDirectDrawSurface7_Release(cubemap
);
2974 /* This test tests depth clamping / clipping behaviour:
2975 * - With software vertex processing, depth values are clamped to the
2976 * minimum / maximum z value when D3DRS_CLIPPING is disabled, and clipped
2977 * when D3DRS_CLIPPING is enabled. Pretransformed vertices behave the
2978 * same as regular vertices here.
2979 * - With hardware vertex processing, D3DRS_CLIPPING seems to be ignored.
2980 * Normal vertices are always clipped. Pretransformed vertices are
2981 * clipped when D3DPMISCCAPS_CLIPTLVERTS is set, clamped when it isn't.
2982 * - The viewport's MinZ/MaxZ is irrelevant for this.
2984 static void depth_clamp_test(IDirect3DDevice7
*device
)
2988 struct vec4 position
;
2993 {{ 0.0f
, 0.0f
, 5.0f
, 1.0f
}, 0xff002b7f},
2994 {{640.0f
, 0.0f
, 5.0f
, 1.0f
}, 0xff002b7f},
2995 {{ 0.0f
, 480.0f
, 5.0f
, 1.0f
}, 0xff002b7f},
2996 {{640.0f
, 480.0f
, 5.0f
, 1.0f
}, 0xff002b7f},
3000 {{ 0.0f
, 300.0f
, 10.0f
, 1.0f
}, 0xfff9e814},
3001 {{640.0f
, 300.0f
, 10.0f
, 1.0f
}, 0xfff9e814},
3002 {{ 0.0f
, 360.0f
, 10.0f
, 1.0f
}, 0xfff9e814},
3003 {{640.0f
, 360.0f
, 10.0f
, 1.0f
}, 0xfff9e814},
3007 {{112.0f
, 108.0f
, 5.0f
, 1.0f
}, 0xffffffff},
3008 {{208.0f
, 108.0f
, 5.0f
, 1.0f
}, 0xffffffff},
3009 {{112.0f
, 204.0f
, 5.0f
, 1.0f
}, 0xffffffff},
3010 {{208.0f
, 204.0f
, 5.0f
, 1.0f
}, 0xffffffff},
3014 {{ 42.0f
, 41.0f
, 10.0f
, 1.0f
}, 0xffffffff},
3015 {{112.0f
, 41.0f
, 10.0f
, 1.0f
}, 0xffffffff},
3016 {{ 42.0f
, 108.0f
, 10.0f
, 1.0f
}, 0xffffffff},
3017 {{112.0f
, 108.0f
, 10.0f
, 1.0f
}, 0xffffffff},
3021 struct vec3 position
;
3026 {{-0.5f
, 0.5f
, 10.0f
}, 0xff14f914},
3027 {{ 0.5f
, 0.5f
, 10.0f
}, 0xff14f914},
3028 {{-0.5f
, -0.5f
, 10.0f
}, 0xff14f914},
3029 {{ 0.5f
, -0.5f
, 10.0f
}, 0xff14f914},
3033 {{-1.0f
, 0.5f
, 10.0f
}, 0xfff91414},
3034 {{ 1.0f
, 0.5f
, 10.0f
}, 0xfff91414},
3035 {{-1.0f
, 0.25f
, 10.0f
}, 0xfff91414},
3036 {{ 1.0f
, 0.25f
, 10.0f
}, 0xfff91414},
3050 hr
= IDirect3DDevice7_SetViewport(device
, &vp
);
3051 ok(SUCCEEDED(hr
), "SetViewport failed, hr %#x.\n", hr
);
3053 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff00ff00, 1.0, 0);
3054 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
3056 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
3057 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
3058 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
3059 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
3060 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZWRITEENABLE
, TRUE
);
3061 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
3062 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZFUNC
, D3DCMP_LESSEQUAL
);
3063 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
3065 hr
= IDirect3DDevice7_BeginScene(device
);
3066 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
3068 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, quad1
, 4, 0);
3069 ok(SUCCEEDED(hr
), "DrawPrimitive failed, hr %#x.\n", hr
);
3070 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, quad2
, 4, 0);
3071 ok(SUCCEEDED(hr
), "DrawPrimitive failed, hr %#x.\n", hr
);
3073 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, TRUE
);
3074 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
3076 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, quad3
, 4, 0);
3077 ok(SUCCEEDED(hr
), "DrawPrimitive failed, hr %#x.\n", hr
);
3078 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, quad4
, 4, 0);
3079 ok(SUCCEEDED(hr
), "DrawPrimitive failed, hr %#x.\n", hr
);
3081 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
3082 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
3084 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad5
, 4, 0);
3085 ok(SUCCEEDED(hr
), "DrawPrimitive failed, hr %#x.\n", hr
);
3087 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, TRUE
);
3088 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
3090 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad6
, 4, 0);
3091 ok(SUCCEEDED(hr
), "DrawPrimitive failed, hr %#x.\n", hr
);
3093 hr
= IDirect3DDevice7_EndScene(device
);
3094 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
3096 color
= getPixelColor(device
, 75, 75);
3097 ok(color_match(color
, 0x00ffffff, 1) || color_match(color
, 0x0000ff00, 1), "color 0x%08x.\n", color
);
3098 color
= getPixelColor(device
, 150, 150);
3099 ok(color_match(color
, 0x00ffffff, 1) || color_match(color
, 0x0000ff00, 1), "color 0x%08x.\n", color
);
3100 color
= getPixelColor(device
, 320, 240);
3101 ok(color_match(color
, 0x00002b7f, 1) || color_match(color
, 0x0000ff00, 1), "color 0x%08x.\n", color
);
3102 color
= getPixelColor(device
, 320, 330);
3103 ok(color_match(color
, 0x00f9e814, 1) || color_match(color
, 0x0000ff00, 1), "color 0x%08x.\n", color
);
3104 color
= getPixelColor(device
, 320, 330);
3105 ok(color_match(color
, 0x00f9e814, 1) || color_match(color
, 0x0000ff00, 1), "color 0x%08x.\n", color
);
3109 hr
= IDirect3DDevice7_SetViewport(device
, &vp
);
3110 ok(SUCCEEDED(hr
), "SetViewport failed, hr %#x.\n", hr
);
3113 static void DX1_BackBufferFlipTest(void)
3116 IDirectDraw
*DirectDraw1
= NULL
;
3117 IDirectDrawSurface
*Primary
= NULL
;
3118 IDirectDrawSurface
*Backbuffer
= NULL
;
3123 const DWORD white
= 0xffffff;
3124 const DWORD red
= 0xff0000;
3125 BOOL attached
= FALSE
;
3127 wc
.lpfnWndProc
= DefWindowProcA
;
3128 wc
.lpszClassName
= "DX1_BackBufferFlipTest_wc";
3129 RegisterClassA(&wc
);
3130 window
= CreateWindowA("DX1_BackBufferFlipTest_wc", "DX1_BackBufferFlipTest",
3131 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
3133 hr
= DirectDrawCreate( NULL
, &DirectDraw1
, NULL
);
3134 ok(hr
==DD_OK
|| hr
==DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreate returned: %x\n", hr
);
3135 if(FAILED(hr
)) goto out
;
3137 hr
= IDirectDraw_SetCooperativeLevel(DirectDraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3138 ok(hr
==DD_OK
, "SetCooperativeLevel returned: %x\n", hr
);
3139 if(FAILED(hr
)) goto out
;
3141 hr
= IDirectDraw_SetDisplayMode(DirectDraw1
, 640, 480, 32);
3143 /* 24 bit is fine too */
3144 hr
= IDirectDraw_SetDisplayMode(DirectDraw1
, 640, 480, 24);
3146 ok(hr
==DD_OK
|| hr
== DDERR_UNSUPPORTED
, "SetDisplayMode returned: %x\n", hr
);
3151 memset(&ddsd
, 0, sizeof(DDSURFACEDESC
));
3152 ddsd
.dwSize
= sizeof(DDSURFACEDESC
);
3153 ddsd
.dwFlags
= DDSD_CAPS
;
3154 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3156 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &Primary
, NULL
);
3157 ok(hr
==DD_OK
, "IDirectDraw_CreateSurface returned: %08x\n", hr
);
3159 memset(&ddsd
, 0, sizeof(DDSURFACEDESC
));
3160 ddsd
.dwSize
= sizeof(DDSURFACEDESC
);
3161 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
3162 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_BACKBUFFER
;
3164 ddsd
.dwHeight
= 480;
3165 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
3166 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
3167 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
3168 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
3169 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
3170 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
3172 hr
= IDirectDraw_CreateSurface(DirectDraw1
, &ddsd
, &Backbuffer
, NULL
);
3173 ok(hr
==DD_OK
, "IDirectDraw_CreateSurface returned: %08x\n", hr
);
3174 if(FAILED(hr
)) goto out
;
3176 hr
= IDirectDrawSurface_AddAttachedSurface(Primary
, Backbuffer
);
3177 todo_wine
ok(hr
== DD_OK
|| broken(hr
== DDERR_CANNOTATTACHSURFACE
),
3178 "Attaching a back buffer to a front buffer returned %08x\n", hr
);
3179 if (FAILED(hr
)) goto out
;
3183 memset(&ddbltfx
, 0, sizeof(ddbltfx
));
3184 ddbltfx
.dwSize
= sizeof(ddbltfx
);
3185 U5(ddbltfx
).dwFillColor
= red
;
3186 hr
= IDirectDrawSurface_Blt(Backbuffer
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
3187 ok(hr
== DD_OK
, "IDirectDrawSurface_Blt returned: %x\n", hr
);
3189 U5(ddbltfx
).dwFillColor
= white
;
3190 hr
= IDirectDrawSurface_Blt(Primary
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &ddbltfx
);
3191 ok(hr
== DD_OK
, "IDirectDrawSurface_Blt returned: %x\n", hr
);
3194 color
= getPixelColor_GDI(Primary
, 5, 5);
3195 ok(GetRValue(color
) == 0xFF && GetGValue(color
) == 0xFF && GetBValue(color
) == 0xFF,
3196 "got R %02X G %02X B %02X, expected R FF G FF B FF\n",
3197 GetRValue(color
), GetGValue(color
), GetBValue(color
));
3199 color
= getPixelColor_GDI(Backbuffer
, 5, 5);
3200 ok(GetRValue(color
) == 0xFF && GetGValue(color
) == 0 && GetBValue(color
) == 0,
3201 "got R %02X G %02X B %02X, expected R FF G 00 B 00\n",
3202 GetRValue(color
), GetGValue(color
), GetBValue(color
));
3204 hr
= IDirectDrawSurface_Flip(Primary
, NULL
, DDFLIP_WAIT
);
3205 todo_wine
ok(hr
== DD_OK
, "IDirectDrawSurface_Flip returned 0x%08x\n", hr
);
3209 color
= getPixelColor_GDI(Primary
, 5, 5);
3210 ok(GetRValue(color
) == 0xFF && GetGValue(color
) == 0 && GetBValue(color
) == 0,
3211 "got R %02X G %02X B %02X, expected R FF G 00 B 00\n",
3212 GetRValue(color
), GetGValue(color
), GetBValue(color
));
3214 color
= getPixelColor_GDI(Backbuffer
, 5, 5);
3215 ok((GetRValue(color
) == 0xFF && GetGValue(color
) == 0xFF && GetBValue(color
) == 0xFF) ||
3216 broken(GetRValue(color
) == 0xFF && GetGValue(color
) == 0 && GetBValue(color
) == 0), /* broken driver */
3217 "got R %02X G %02X B %02X, expected R FF G FF B FF\n",
3218 GetRValue(color
), GetGValue(color
), GetBValue(color
));
3226 IDirectDrawSurface_DeleteAttachedSurface(Primary
, 0, Backbuffer
);
3227 IDirectDrawSurface_Release(Backbuffer
);
3229 if (Primary
) IDirectDrawSurface_Release(Primary
);
3230 if (DirectDraw1
) IDirectDraw_Release(DirectDraw1
);
3231 if (window
) DestroyWindow(window
);
3238 if(!createObjects())
3240 skip("Cannot initialize DirectDraw and Direct3D, skipping\n");
3244 /* Check for the reliability of the returned data */
3245 hr
= IDirect3DDevice7_Clear(Direct3DDevice
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0, 0);
3248 skip("Clear failed, can't assure correctness of the test results, skipping\n");
3252 color
= getPixelColor(Direct3DDevice
, 1, 1);
3253 if(color
!=0x00ff0000)
3255 skip("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests, skipping\n", color
);
3259 hr
= IDirect3DDevice7_Clear(Direct3DDevice
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ddee, 0.0, 0);
3262 skip("Clear failed, can't assure correctness of the test results, skipping\n");
3266 color
= getPixelColor(Direct3DDevice
, 639, 479);
3267 if(color
!= 0x0000ddee)
3269 skip("Sanity check returned an incorrect color(%08x), can't assure the correctness of the tests, skipping\n", color
);
3273 /* Now run the tests */
3274 blt_test(Direct3DDevice
);
3275 depth_clamp_test(Direct3DDevice
);
3276 lighting_test(Direct3DDevice
);
3277 clear_test(Direct3DDevice
);
3278 fog_test(Direct3DDevice
);
3279 offscreen_test(Direct3DDevice
);
3280 test_blend(Direct3DDevice
);
3281 rhw_zero_test(Direct3DDevice
);
3282 cubemap_test(Direct3DDevice
);
3284 releaseObjects(); /* release DX7 interfaces to test D3D1 */
3286 if(!D3D1_createObjects()) {
3287 skip("Cannot initialize D3D1, skipping\n");
3290 D3D1_TextureMapBlendTest();
3291 D3D1_ViewportClearTest();
3293 D3D1_releaseObjects();
3295 D3D3_ViewportClearTest();
3297 DX1_BackBufferFlipTest();