2 * Copyright (C) 2006 Vitaliy Margolen
3 * Copyright (C) 2006 Chris Robinson
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
23 #include "wine/test.h"
25 static IDirect3D8
*(WINAPI
*pDirect3DCreate8
)(UINT
);
27 static BOOL (WINAPI
*pGetCursorInfo
)(PCURSORINFO
);
29 static const DWORD simple_vs
[] = {0xFFFE0101, /* vs_1_1 */
30 0x00000009, 0xC0010000, 0x90E40000, 0xA0E40000, /* dp4 oPos.x, v0, c0 */
31 0x00000009, 0xC0020000, 0x90E40000, 0xA0E40001, /* dp4 oPos.y, v0, c1 */
32 0x00000009, 0xC0040000, 0x90E40000, 0xA0E40002, /* dp4 oPos.z, v0, c2 */
33 0x00000009, 0xC0080000, 0x90E40000, 0xA0E40003, /* dp4 oPos.w, v0, c3 */
34 0x0000FFFF}; /* END */
35 static const DWORD simple_ps
[] = {0xFFFF0101, /* ps_1_1 */
36 0x00000051, 0xA00F0001, 0x3F800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
37 0x00000042, 0xB00F0000, /* tex t0 */
38 0x00000008, 0x800F0000, 0xA0E40001, 0xA0E40000, /* dp3 r0, c1, c0 */
39 0x00000005, 0x800F0000, 0x90E40000, 0x80E40000, /* mul r0, v0, r0 */
40 0x00000005, 0x800F0000, 0xB0E40000, 0x80E40000, /* mul r0, t0, r0 */
41 0x0000FFFF}; /* END */
43 static int get_refcount(IUnknown
*object
)
45 IUnknown_AddRef( object
);
46 return IUnknown_Release( object
);
49 #define CHECK_CALL(r,c,d,rc) \
51 int tmp1 = get_refcount( (IUnknown *)d ); \
53 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
55 trace("%s failed: %#08x\n", c, r); \
58 #define CHECK_RELEASE(obj,d,rc) \
60 int tmp1, rc_new = rc; \
61 IUnknown_Release( obj ); \
62 tmp1 = get_refcount( (IUnknown *)d ); \
63 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
66 #define CHECK_REFCOUNT(obj,rc) \
69 int count = get_refcount( (IUnknown *)obj ); \
70 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
73 #define CHECK_RELEASE_REFCOUNT(obj,rc) \
76 int count = IUnknown_Release( (IUnknown *)obj ); \
77 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
80 #define CHECK_ADDREF_REFCOUNT(obj,rc) \
83 int count = IUnknown_AddRef( (IUnknown *)obj ); \
84 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
87 #define CHECK_SURFACE_CONTAINER(obj,iid,expected) \
89 void *container_ptr = (void *)0x1337c0d3; \
90 hr = IDirect3DSurface8_GetContainer(obj, &iid, &container_ptr); \
91 ok(SUCCEEDED(hr) && container_ptr == expected, "GetContainer returned: hr %#08x, container_ptr %p. " \
92 "Expected hr %#08x, container_ptr %p\n", hr, container_ptr, S_OK, expected); \
93 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr); \
96 static void check_mipmap_levels(IDirect3DDevice8
*device
, UINT width
, UINT height
, UINT count
)
98 IDirect3DBaseTexture8
* texture
= NULL
;
99 HRESULT hr
= IDirect3DDevice8_CreateTexture( device
, width
, height
, 0, 0,
100 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, (IDirect3DTexture8
**) &texture
);
103 DWORD levels
= IDirect3DBaseTexture8_GetLevelCount(texture
);
104 ok(levels
== count
, "Invalid level count. Expected %d got %u\n", count
, levels
);
106 trace("CreateTexture failed: %#08x\n", hr
);
108 if (texture
) IUnknown_Release( texture
);
111 static void test_mipmap_levels(void)
117 IDirect3D8
*pD3d
= NULL
;
118 IDirect3DDevice8
*pDevice
= NULL
;
119 D3DPRESENT_PARAMETERS d3dpp
;
120 D3DDISPLAYMODE d3ddm
;
122 pD3d
= pDirect3DCreate8( D3D_SDK_VERSION
);
123 ok(pD3d
!= NULL
, "Failed to create IDirect3D8 object\n");
124 hwnd
= CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
125 ok(hwnd
!= NULL
, "Failed to create window\n");
126 if (!pD3d
|| !hwnd
) goto cleanup
;
128 IDirect3D8_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
129 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
130 d3dpp
.Windowed
= TRUE
;
131 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
132 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
134 hr
= IDirect3D8_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
135 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
138 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr
);
142 check_mipmap_levels(pDevice
, 32, 32, 6);
143 check_mipmap_levels(pDevice
, 256, 1, 9);
144 check_mipmap_levels(pDevice
, 1, 256, 9);
145 check_mipmap_levels(pDevice
, 1, 1, 1);
148 if (pD3d
) IUnknown_Release( pD3d
);
149 if (pDevice
) IUnknown_Release( pDevice
);
150 DestroyWindow( hwnd
);
153 static void test_swapchain(void)
157 IDirect3D8
*pD3d
= NULL
;
158 IDirect3DDevice8
*pDevice
= NULL
;
159 IDirect3DSwapChain8
*swapchain1
= NULL
;
160 IDirect3DSwapChain8
*swapchain2
= NULL
;
161 IDirect3DSwapChain8
*swapchain3
= NULL
;
162 IDirect3DSurface8
*backbuffer
= NULL
;
163 D3DPRESENT_PARAMETERS d3dpp
;
164 D3DDISPLAYMODE d3ddm
;
166 pD3d
= pDirect3DCreate8( D3D_SDK_VERSION
);
167 ok(pD3d
!= NULL
, "Failed to create IDirect3D8 object\n");
168 hwnd
= CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
169 ok(hwnd
!= NULL
, "Failed to create window\n");
170 if (!pD3d
|| !hwnd
) goto cleanup
;
172 IDirect3D8_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
173 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
174 d3dpp
.Windowed
= TRUE
;
175 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
176 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
177 d3dpp
.BackBufferCount
= 0;
179 hr
= IDirect3D8_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
180 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
183 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr
);
187 /* Check if the back buffer count was modified */
188 ok(d3dpp
.BackBufferCount
== 1, "The back buffer count in the presentparams struct is %d\n", d3dpp
.BackBufferCount
);
190 /* Create a bunch of swapchains */
191 d3dpp
.BackBufferCount
= 0;
192 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(pDevice
, &d3dpp
, &swapchain1
);
193 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%#08x)\n", hr
);
194 ok(d3dpp
.BackBufferCount
== 1, "The back buffer count in the presentparams struct is %d\n", d3dpp
.BackBufferCount
);
196 d3dpp
.BackBufferCount
= 1;
197 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(pDevice
, &d3dpp
, &swapchain2
);
198 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%#08x)\n", hr
);
200 d3dpp
.BackBufferCount
= 2;
201 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(pDevice
, &d3dpp
, &swapchain3
);
202 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%#08x)\n", hr
);
204 /* Swapchain 3, created with backbuffercount 2 */
205 backbuffer
= (void *) 0xdeadbeef;
206 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 0, 0, &backbuffer
);
207 ok(SUCCEEDED(hr
), "Failed to get the 1st back buffer (%#08x)\n", hr
);
208 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
209 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
211 backbuffer
= (void *) 0xdeadbeef;
212 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 1, 0, &backbuffer
);
213 ok(SUCCEEDED(hr
), "Failed to get the 2nd back buffer (%#08x)\n", hr
);
214 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
215 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
217 backbuffer
= (void *) 0xdeadbeef;
218 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 2, 0, &backbuffer
);
219 ok(hr
== D3DERR_INVALIDCALL
, "GetBackBuffer returned %#08x\n", hr
);
220 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
221 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
223 backbuffer
= (void *) 0xdeadbeef;
224 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 3, 0, &backbuffer
);
225 ok(FAILED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
226 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
227 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
230 /* Check the back buffers of the swapchains */
231 /* Swapchain 1, created with backbuffercount 0 */
232 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain1
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
233 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
234 ok(backbuffer
!= NULL
, "The back buffer is NULL (%#08x)\n", hr
);
235 if(backbuffer
) IDirect3DSurface8_Release(backbuffer
);
237 backbuffer
= (void *) 0xdeadbeef;
238 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain1
, 1, 0, &backbuffer
);
239 ok(FAILED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
240 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
241 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
243 /* Swapchain 2 - created with backbuffercount 1 */
244 backbuffer
= (void *) 0xdeadbeef;
245 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain2
, 0, 0, &backbuffer
);
246 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
247 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
248 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
250 backbuffer
= (void *) 0xdeadbeef;
251 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain2
, 1, 0, &backbuffer
);
252 ok(hr
== D3DERR_INVALIDCALL
, "GetBackBuffer returned %#08x\n", hr
);
253 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
254 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
256 backbuffer
= (void *) 0xdeadbeef;
257 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain2
, 2, 0, &backbuffer
);
258 ok(FAILED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
259 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
260 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
263 if(swapchain1
) IDirect3DSwapChain8_Release(swapchain1
);
264 if(swapchain2
) IDirect3DSwapChain8_Release(swapchain2
);
265 if(swapchain3
) IDirect3DSwapChain8_Release(swapchain3
);
266 if(pDevice
) IDirect3DDevice8_Release(pDevice
);
267 if(pD3d
) IDirect3DDevice8_Release(pD3d
);
268 DestroyWindow( hwnd
);
271 static void test_refcount(void)
275 IDirect3D8
*pD3d
= NULL
;
276 IDirect3DDevice8
*pDevice
= NULL
;
277 IDirect3DVertexBuffer8
*pVertexBuffer
= NULL
;
278 IDirect3DIndexBuffer8
*pIndexBuffer
= NULL
;
279 DWORD dVertexShader
= -1;
280 DWORD dPixelShader
= -1;
281 IDirect3DCubeTexture8
*pCubeTexture
= NULL
;
282 IDirect3DTexture8
*pTexture
= NULL
;
283 IDirect3DVolumeTexture8
*pVolumeTexture
= NULL
;
284 IDirect3DVolume8
*pVolumeLevel
= NULL
;
285 IDirect3DSurface8
*pStencilSurface
= NULL
;
286 IDirect3DSurface8
*pImageSurface
= NULL
;
287 IDirect3DSurface8
*pRenderTarget
= NULL
;
288 IDirect3DSurface8
*pRenderTarget2
= NULL
;
289 IDirect3DSurface8
*pRenderTarget3
= NULL
;
290 IDirect3DSurface8
*pTextureLevel
= NULL
;
291 IDirect3DSurface8
*pBackBuffer
= NULL
;
292 DWORD dStateBlock
= -1;
293 IDirect3DSwapChain8
*pSwapChain
= NULL
;
296 D3DPRESENT_PARAMETERS d3dpp
;
297 D3DDISPLAYMODE d3ddm
;
298 int refcount
= 0, tmp
;
303 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
304 D3DVSD_REG(D3DVSDE_DIFFUSE
, D3DVSDT_D3DCOLOR
), /* D3DVSDE_DIFFUSE, Register v5 */
308 pD3d
= pDirect3DCreate8( D3D_SDK_VERSION
);
309 ok(pD3d
!= NULL
, "Failed to create IDirect3D8 object\n");
310 hwnd
= CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
311 ok(hwnd
!= NULL
, "Failed to create window\n");
312 if (!pD3d
|| !hwnd
) goto cleanup
;
314 IDirect3D8_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
315 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
316 d3dpp
.Windowed
= TRUE
;
317 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
318 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
319 d3dpp
.EnableAutoDepthStencil
= TRUE
;
320 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
322 hr
= IDirect3D8_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
323 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
326 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr
);
329 IDirect3DDevice8_GetDeviceCaps(pDevice
, &caps
);
331 refcount
= get_refcount( (IUnknown
*)pDevice
);
332 ok(refcount
== 1, "Invalid device RefCount %d\n", refcount
);
335 * Check refcount of implicit surfaces. Findings:
336 * - the container is the device
337 * - they hold a reference to the device
338 * - they are created with a refcount of 0 (Get/Release returns original refcount)
339 * - they are not freed if refcount reaches 0.
340 * - the refcount is not forwarded to the container.
342 hr
= IDirect3DDevice8_GetRenderTarget(pDevice
, &pRenderTarget
);
343 CHECK_CALL( hr
, "GetRenderTarget", pDevice
, ++refcount
);
346 CHECK_SURFACE_CONTAINER( pRenderTarget
, IID_IDirect3DDevice8
, pDevice
);
347 CHECK_REFCOUNT( pRenderTarget
, 1);
349 CHECK_ADDREF_REFCOUNT(pRenderTarget
, 2);
350 CHECK_REFCOUNT(pDevice
, refcount
);
351 CHECK_RELEASE_REFCOUNT(pRenderTarget
, 1);
352 CHECK_REFCOUNT(pDevice
, refcount
);
354 hr
= IDirect3DDevice8_GetRenderTarget(pDevice
, &pRenderTarget
);
355 CHECK_CALL( hr
, "GetRenderTarget", pDevice
, refcount
);
356 CHECK_REFCOUNT( pRenderTarget
, 2);
357 CHECK_RELEASE_REFCOUNT( pRenderTarget
, 1);
358 CHECK_RELEASE_REFCOUNT( pRenderTarget
, 0);
359 CHECK_REFCOUNT( pDevice
, --refcount
);
361 /* The render target is released with the device, so AddRef with refcount=0 is fine here. */
362 CHECK_ADDREF_REFCOUNT(pRenderTarget
, 1);
363 CHECK_REFCOUNT(pDevice
, ++refcount
);
364 CHECK_RELEASE_REFCOUNT(pRenderTarget
, 0);
365 CHECK_REFCOUNT(pDevice
, --refcount
);
368 /* Render target and back buffer are identical. */
369 hr
= IDirect3DDevice8_GetBackBuffer(pDevice
, 0, 0, &pBackBuffer
);
370 CHECK_CALL( hr
, "GetBackBuffer", pDevice
, ++refcount
);
373 CHECK_RELEASE_REFCOUNT(pBackBuffer
, 0);
374 ok(pRenderTarget
== pBackBuffer
, "RenderTarget=%p and BackBuffer=%p should be the same.\n",
375 pRenderTarget
, pBackBuffer
);
378 CHECK_REFCOUNT( pDevice
, --refcount
);
380 hr
= IDirect3DDevice8_GetDepthStencilSurface(pDevice
, &pStencilSurface
);
381 CHECK_CALL( hr
, "GetDepthStencilSurface", pDevice
, ++refcount
);
384 CHECK_SURFACE_CONTAINER( pStencilSurface
, IID_IDirect3DDevice8
, pDevice
);
385 CHECK_REFCOUNT( pStencilSurface
, 1);
387 CHECK_ADDREF_REFCOUNT(pStencilSurface
, 2);
388 CHECK_REFCOUNT(pDevice
, refcount
);
389 CHECK_RELEASE_REFCOUNT(pStencilSurface
, 1);
390 CHECK_REFCOUNT(pDevice
, refcount
);
392 CHECK_RELEASE_REFCOUNT( pStencilSurface
, 0);
393 CHECK_REFCOUNT( pDevice
, --refcount
);
395 /* The stencil surface is released with the device, so AddRef with refcount=0 is fine here. */
396 CHECK_ADDREF_REFCOUNT(pStencilSurface
, 1);
397 CHECK_REFCOUNT(pDevice
, ++refcount
);
398 CHECK_RELEASE_REFCOUNT(pStencilSurface
, 0);
399 CHECK_REFCOUNT(pDevice
, --refcount
);
400 pStencilSurface
= NULL
;
404 hr
= IDirect3DDevice8_CreateIndexBuffer( pDevice
, 16, 0, D3DFMT_INDEX32
, D3DPOOL_DEFAULT
, &pIndexBuffer
);
405 CHECK_CALL( hr
, "CreateIndexBuffer", pDevice
, ++refcount
);
408 tmp
= get_refcount( (IUnknown
*)pIndexBuffer
);
410 hr
= IDirect3DDevice8_SetIndices(pDevice
, pIndexBuffer
, 0);
411 CHECK_CALL( hr
, "SetIndices", pIndexBuffer
, tmp
);
412 hr
= IDirect3DDevice8_SetIndices(pDevice
, NULL
, 0);
413 CHECK_CALL( hr
, "SetIndices", pIndexBuffer
, tmp
);
416 hr
= IDirect3DDevice8_CreateVertexBuffer( pDevice
, 16, 0, D3DFVF_XYZ
, D3DPOOL_DEFAULT
, &pVertexBuffer
);
417 CHECK_CALL( hr
, "CreateVertexBuffer", pDevice
, ++refcount
);
420 IDirect3DVertexBuffer8
*pVBuf
= (void*)~0;
423 tmp
= get_refcount( (IUnknown
*)pVertexBuffer
);
425 hr
= IDirect3DDevice8_SetStreamSource(pDevice
, 0, pVertexBuffer
, 3 * sizeof(float));
426 CHECK_CALL( hr
, "SetStreamSource", pVertexBuffer
, tmp
);
427 hr
= IDirect3DDevice8_SetStreamSource(pDevice
, 0, NULL
, 0);
428 CHECK_CALL( hr
, "SetStreamSource", pVertexBuffer
, tmp
);
430 hr
= IDirect3DDevice8_GetStreamSource(pDevice
, 0, &pVBuf
, &stride
);
431 ok(SUCCEEDED(hr
), "GetStreamSource did not succeed with NULL stream!\n");
432 ok(pVBuf
==NULL
, "pVBuf not NULL (%p)!\n", pVBuf
);
433 ok(stride
==3*sizeof(float), "stride not 3 floats (got %u)!\n", stride
);
437 hr
= IDirect3DDevice8_CreateVertexShader( pDevice
, decl
, simple_vs
, &dVertexShader
, 0 );
438 CHECK_CALL( hr
, "CreateVertexShader", pDevice
, refcount
);
439 if (caps
.PixelShaderVersion
>= D3DPS_VERSION(1, 0))
441 hr
= IDirect3DDevice8_CreatePixelShader( pDevice
, simple_ps
, &dPixelShader
);
442 CHECK_CALL( hr
, "CreatePixelShader", pDevice
, refcount
);
445 hr
= IDirect3DDevice8_CreateTexture( pDevice
, 32, 32, 3, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pTexture
);
446 CHECK_CALL( hr
, "CreateTexture", pDevice
, ++refcount
);
449 tmp
= get_refcount( (IUnknown
*)pTexture
);
451 /* SetTexture should not increase refcounts */
452 hr
= IDirect3DDevice8_SetTexture(pDevice
, 0, (IDirect3DBaseTexture8
*) pTexture
);
453 CHECK_CALL( hr
, "SetTexture", pTexture
, tmp
);
454 hr
= IDirect3DDevice8_SetTexture(pDevice
, 0, NULL
);
455 CHECK_CALL( hr
, "SetTexture", pTexture
, tmp
);
457 /* This should not increment device refcount */
458 hr
= IDirect3DTexture8_GetSurfaceLevel( pTexture
, 1, &pTextureLevel
);
459 CHECK_CALL( hr
, "GetSurfaceLevel", pDevice
, refcount
);
460 /* But should increment texture's refcount */
461 CHECK_REFCOUNT( pTexture
, tmp
+1 );
462 /* Because the texture and surface refcount are identical */
465 CHECK_REFCOUNT ( pTextureLevel
, tmp
+1 );
466 CHECK_ADDREF_REFCOUNT ( pTextureLevel
, tmp
+2 );
467 CHECK_REFCOUNT ( pTexture
, tmp
+2 );
468 CHECK_RELEASE_REFCOUNT( pTextureLevel
, tmp
+1 );
469 CHECK_REFCOUNT ( pTexture
, tmp
+1 );
470 CHECK_RELEASE_REFCOUNT( pTexture
, tmp
);
471 CHECK_REFCOUNT ( pTextureLevel
, tmp
);
474 if(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
)
476 hr
= IDirect3DDevice8_CreateCubeTexture( pDevice
, 32, 0, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pCubeTexture
);
477 CHECK_CALL( hr
, "CreateCubeTexture", pDevice
, ++refcount
);
481 skip("Cube textures not supported\n");
483 if(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
)
485 hr
= IDirect3DDevice8_CreateVolumeTexture( pDevice
, 32, 32, 2, 0, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pVolumeTexture
);
486 CHECK_CALL( hr
, "CreateVolumeTexture", pDevice
, ++refcount
);
490 skip("Volume textures not supported\n");
495 tmp
= get_refcount( (IUnknown
*)pVolumeTexture
);
497 /* This should not increment device refcount */
498 hr
= IDirect3DVolumeTexture8_GetVolumeLevel(pVolumeTexture
, 0, &pVolumeLevel
);
499 CHECK_CALL( hr
, "GetVolumeLevel", pDevice
, refcount
);
500 /* But should increment volume texture's refcount */
501 CHECK_REFCOUNT( pVolumeTexture
, tmp
+1 );
502 /* Because the volume texture and volume refcount are identical */
505 CHECK_REFCOUNT ( pVolumeLevel
, tmp
+1 );
506 CHECK_ADDREF_REFCOUNT ( pVolumeLevel
, tmp
+2 );
507 CHECK_REFCOUNT ( pVolumeTexture
, tmp
+2 );
508 CHECK_RELEASE_REFCOUNT( pVolumeLevel
, tmp
+1 );
509 CHECK_REFCOUNT ( pVolumeTexture
, tmp
+1 );
510 CHECK_RELEASE_REFCOUNT( pVolumeTexture
, tmp
);
511 CHECK_REFCOUNT ( pVolumeLevel
, tmp
);
515 hr
= IDirect3DDevice8_CreateDepthStencilSurface( pDevice
, 32, 32, D3DFMT_D16
, D3DMULTISAMPLE_NONE
, &pStencilSurface
);
516 CHECK_CALL( hr
, "CreateDepthStencilSurface", pDevice
, ++refcount
);
517 CHECK_REFCOUNT( pStencilSurface
, 1);
518 hr
= IDirect3DDevice8_CreateImageSurface( pDevice
, 32, 32, D3DFMT_X8R8G8B8
, &pImageSurface
);
519 CHECK_CALL( hr
, "CreateImageSurface", pDevice
, ++refcount
);
520 CHECK_REFCOUNT( pImageSurface
, 1);
521 hr
= IDirect3DDevice8_CreateRenderTarget( pDevice
, 32, 32, D3DFMT_X8R8G8B8
, D3DMULTISAMPLE_NONE
, TRUE
, &pRenderTarget3
);
522 CHECK_CALL( hr
, "CreateRenderTarget", pDevice
, ++refcount
);
523 CHECK_REFCOUNT( pRenderTarget3
, 1);
525 hr
= IDirect3DDevice8_CreateStateBlock( pDevice
, D3DSBT_ALL
, &dStateBlock
);
526 CHECK_CALL( hr
, "CreateStateBlock", pDevice
, refcount
);
527 hr
= IDirect3DDevice8_CreateAdditionalSwapChain( pDevice
, &d3dpp
, &pSwapChain
);
528 CHECK_CALL( hr
, "CreateAdditionalSwapChain", pDevice
, ++refcount
);
531 /* check implicit back buffer */
532 hr
= IDirect3DSwapChain8_GetBackBuffer(pSwapChain
, 0, 0, &pBackBuffer
);
533 CHECK_CALL( hr
, "GetBackBuffer", pDevice
, ++refcount
);
534 CHECK_REFCOUNT( pSwapChain
, 1);
537 CHECK_SURFACE_CONTAINER( pBackBuffer
, IID_IDirect3DDevice8
, pDevice
);
538 CHECK_REFCOUNT( pBackBuffer
, 1);
539 CHECK_RELEASE_REFCOUNT( pBackBuffer
, 0);
540 CHECK_REFCOUNT( pDevice
, --refcount
);
542 /* The back buffer is released with the swapchain, so AddRef with refcount=0 is fine here. */
543 CHECK_ADDREF_REFCOUNT(pBackBuffer
, 1);
544 CHECK_REFCOUNT(pDevice
, ++refcount
);
545 CHECK_RELEASE_REFCOUNT(pBackBuffer
, 0);
546 CHECK_REFCOUNT(pDevice
, --refcount
);
549 CHECK_REFCOUNT( pSwapChain
, 1);
555 /* Vertex buffers can be locked multiple times */
556 hr
= IDirect3DVertexBuffer8_Lock(pVertexBuffer
, 0, 0, &data
, 0);
557 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr
);
558 hr
= IDirect3DVertexBuffer8_Lock(pVertexBuffer
, 0, 0, &data
, 0);
559 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr
);
560 hr
= IDirect3DVertexBuffer8_Unlock(pVertexBuffer
);
561 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr
);
562 hr
= IDirect3DVertexBuffer8_Unlock(pVertexBuffer
);
563 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr
);
566 /* The implicit render target is not freed if refcount reaches 0.
567 * Otherwise GetRenderTarget would re-allocate it and the pointer would change.*/
568 hr
= IDirect3DDevice8_GetRenderTarget(pDevice
, &pRenderTarget2
);
569 CHECK_CALL( hr
, "GetRenderTarget", pDevice
, ++refcount
);
572 CHECK_RELEASE_REFCOUNT(pRenderTarget2
, 0);
573 ok(pRenderTarget
== pRenderTarget2
, "RenderTarget=%p and RenderTarget2=%p should be the same.\n",
574 pRenderTarget
, pRenderTarget2
);
575 CHECK_REFCOUNT( pDevice
, --refcount
);
576 pRenderTarget2
= NULL
;
578 pRenderTarget
= NULL
;
581 CHECK_RELEASE(pDevice
, pDevice
, --refcount
);
584 CHECK_RELEASE(pVertexBuffer
, pDevice
, --refcount
);
585 CHECK_RELEASE(pIndexBuffer
, pDevice
, --refcount
);
587 if (dVertexShader
!= ~0U) IDirect3DDevice8_DeleteVertexShader( pDevice
, dVertexShader
);
588 if (dPixelShader
!= ~0U) IDirect3DDevice8_DeletePixelShader( pDevice
, dPixelShader
);
590 CHECK_RELEASE(pTexture
, pDevice
, --refcount
);
591 CHECK_RELEASE(pCubeTexture
, pDevice
, --refcount
);
592 CHECK_RELEASE(pVolumeTexture
, pDevice
, --refcount
);
594 CHECK_RELEASE(pStencilSurface
, pDevice
, --refcount
);
595 CHECK_RELEASE(pImageSurface
, pDevice
, --refcount
);
596 CHECK_RELEASE(pRenderTarget3
, pDevice
, --refcount
);
598 if (dStateBlock
!= ~0U) IDirect3DDevice8_DeleteStateBlock( pDevice
, dStateBlock
);
599 /* This will destroy device - cannot check the refcount here */
600 if (pSwapChain
) CHECK_RELEASE_REFCOUNT( pSwapChain
, 0);
602 if (pD3d
) CHECK_RELEASE_REFCOUNT( pD3d
, 0);
604 DestroyWindow( hwnd
);
607 static void test_cursor(void)
611 IDirect3D8
*pD3d
= NULL
;
612 IDirect3DDevice8
*pDevice
= NULL
;
613 D3DPRESENT_PARAMETERS d3dpp
;
614 D3DDISPLAYMODE d3ddm
;
616 IDirect3DSurface8
*cursor
= NULL
;
618 HMODULE user32_handle
= GetModuleHandleA("user32.dll");
620 pGetCursorInfo
= (void *)GetProcAddress(user32_handle
, "GetCursorInfo");
623 win_skip("GetCursorInfo is not available\n");
627 memset(&info
, 0, sizeof(info
));
628 info
.cbSize
= sizeof(info
);
629 ok(pGetCursorInfo(&info
), "GetCursorInfo failed\n");
632 pD3d
= pDirect3DCreate8( D3D_SDK_VERSION
);
633 ok(pD3d
!= NULL
, "Failed to create IDirect3D8 object\n");
634 hwnd
= CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
635 ok(hwnd
!= NULL
, "Failed to create window\n");
636 if (!pD3d
|| !hwnd
) goto cleanup
;
638 IDirect3D8_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
639 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
640 d3dpp
.Windowed
= TRUE
;
641 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
642 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
644 hr
= IDirect3D8_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
645 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
648 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr
);
652 IDirect3DDevice8_CreateImageSurface(pDevice
, 32, 32, D3DFMT_A8R8G8B8
, &cursor
);
653 ok(cursor
!= NULL
, "IDirect3DDevice8_CreateOffscreenPlainSurface failed with %#08x\n", hr
);
655 /* Initially hidden */
656 hr
= IDirect3DDevice8_ShowCursor(pDevice
, TRUE
);
657 ok(hr
== FALSE
, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr
);
659 /* Not enabled without a surface*/
660 hr
= IDirect3DDevice8_ShowCursor(pDevice
, TRUE
);
661 ok(hr
== FALSE
, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr
);
664 hr
= IDirect3DDevice8_SetCursorProperties(pDevice
, 0, 0, NULL
);
665 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr
);
667 hr
= IDirect3DDevice8_SetCursorProperties(pDevice
, 0, 0, cursor
);
668 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr
);
670 IDirect3DSurface8_Release(cursor
);
672 memset(&info
, 0, sizeof(info
));
673 info
.cbSize
= sizeof(info
);
674 ok(pGetCursorInfo(&info
), "GetCursorInfo failed\n");
675 ok(info
.flags
& CURSOR_SHOWING
, "The gdi cursor is hidden (%08x)\n", info
.flags
);
676 ok(info
.hCursor
== cur
, "The cursor handle is %p\n", info
.hCursor
); /* unchanged */
679 hr
= IDirect3DDevice8_ShowCursor(pDevice
, TRUE
);
680 ok(hr
== FALSE
, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr
);
683 hr
= IDirect3DDevice8_ShowCursor(pDevice
, TRUE
);
684 ok(hr
== TRUE
, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr
);
686 /* GDI cursor unchanged */
687 memset(&info
, 0, sizeof(info
));
688 info
.cbSize
= sizeof(info
);
689 ok(pGetCursorInfo(&info
), "GetCursorInfo failed\n");
690 ok(info
.flags
& CURSOR_SHOWING
, "The gdi cursor is hidden (%08x)\n", info
.flags
);
691 ok(info
.hCursor
== cur
, "The cursor handle is %p\n", info
.hCursor
); /* unchanged */
694 if(pD3d
) IDirect3D8_Release(pD3d
);
695 if(pDevice
) IDirect3D8_Release(pDevice
);
698 static void test_states(void)
702 IDirect3D8
*pD3d
= NULL
;
703 IDirect3DDevice8
*pDevice
= NULL
;
704 D3DPRESENT_PARAMETERS d3dpp
;
705 D3DDISPLAYMODE d3ddm
;
707 pD3d
= pDirect3DCreate8( D3D_SDK_VERSION
);
708 ok(pD3d
!= NULL
, "Failed to create IDirect3D8 object\n");
709 hwnd
= CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
710 ok(hwnd
!= NULL
, "Failed to create window\n");
711 if (!pD3d
|| !hwnd
) goto cleanup
;
713 IDirect3D8_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
714 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
715 d3dpp
.Windowed
= TRUE
;
716 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
717 d3dpp
.BackBufferWidth
= 640;
718 d3dpp
.BackBufferHeight
= 480;
719 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
721 hr
= IDirect3D8_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
722 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
725 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr
);
729 hr
= IDirect3DDevice8_SetRenderState(pDevice
, D3DRS_ZVISIBLE
, TRUE
);
730 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, TRUE) returned %#08x\n", hr
);
731 hr
= IDirect3DDevice8_SetRenderState(pDevice
, D3DRS_ZVISIBLE
, FALSE
);
732 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, FALSE) returned %#08x\n", hr
);
735 if(pD3d
) IDirect3D8_Release(pD3d
);
736 if(pDevice
) IDirect3D8_Release(pDevice
);
739 static void test_shader_versions(void)
742 IDirect3D8
*pD3d
= NULL
;
745 pD3d
= pDirect3DCreate8( D3D_SDK_VERSION
);
746 ok(pD3d
!= NULL
, "Failed to create IDirect3D8 object\n");
748 hr
= IDirect3D8_GetDeviceCaps(pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, &d3dcaps
);
749 ok(SUCCEEDED(hr
) || hr
== D3DERR_NOTAVAILABLE
, "Failed to get D3D8 caps (%#08x)\n", hr
);
751 ok(d3dcaps
.VertexShaderVersion
<= D3DVS_VERSION(1,1), "Unexpected VertexShaderVersion (%#x > %#x)\n", d3dcaps
.VertexShaderVersion
, D3DVS_VERSION(1,1));
752 ok(d3dcaps
.PixelShaderVersion
<= D3DPS_VERSION(1,4), "Unexpected PixelShaderVersion (%#x > %#x)\n", d3dcaps
.PixelShaderVersion
, D3DPS_VERSION(1,4));
754 skip("No Direct3D support\n");
756 IDirect3D8_Release(pD3d
);
761 /* Test adapter display modes */
762 static void test_display_modes(void)
765 D3DDISPLAYMODE dmode
;
769 pD3d
= pDirect3DCreate8( D3D_SDK_VERSION
);
770 ok(pD3d
!= NULL
, "Failed to create IDirect3D8 object\n");
773 max_modes
= IDirect3D8_GetAdapterModeCount(pD3d
, D3DADAPTER_DEFAULT
);
775 broken(max_modes
== 0), /* VMware */
776 "GetAdapterModeCount(D3DADAPTER_DEFAULT) returned 0!\n");
778 for(i
=0; i
<max_modes
;i
++) {
779 res
= IDirect3D8_EnumAdapterModes(pD3d
, D3DADAPTER_DEFAULT
, i
, &dmode
);
780 ok(res
==D3D_OK
, "EnumAdapterModes returned %#08x for mode %u!\n", res
, i
);
784 ok(dmode
.Format
==D3DFMT_X8R8G8B8
|| dmode
.Format
==D3DFMT_R5G6B5
,
785 "Unexpected display mode returned for mode %u: %#x\n", i
, dmode
.Format
);
788 IDirect3D8_Release(pD3d
);
791 static void test_scene(void)
795 IDirect3D8
*pD3d
= NULL
;
796 IDirect3DDevice8
*pDevice
= NULL
;
797 D3DPRESENT_PARAMETERS d3dpp
;
798 D3DDISPLAYMODE d3ddm
;
800 pD3d
= pDirect3DCreate8( D3D_SDK_VERSION
);
801 ok(pD3d
!= NULL
, "Failed to create IDirect3D8 object\n");
802 hwnd
= CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
803 ok(hwnd
!= NULL
, "Failed to create window\n");
804 if (!pD3d
|| !hwnd
) goto cleanup
;
806 IDirect3D8_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
807 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
808 d3dpp
.Windowed
= TRUE
;
809 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
810 d3dpp
.BackBufferWidth
= 800;
811 d3dpp
.BackBufferHeight
= 600;
812 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
815 hr
= IDirect3D8_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
816 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
817 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
|| broken(hr
== D3DERR_NOTAVAILABLE
), "IDirect3D8_CreateDevice failed with %#08x\n", hr
);
820 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr
);
824 /* Test an EndScene without beginscene. Should return an error */
825 hr
= IDirect3DDevice8_EndScene(pDevice
);
826 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
828 /* Test a normal BeginScene / EndScene pair, this should work */
829 hr
= IDirect3DDevice8_BeginScene(pDevice
);
830 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr
);
833 hr
= IDirect3DDevice8_EndScene(pDevice
);
834 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed with %#08x\n", hr
);
837 /* Test another EndScene without having begun a new scene. Should return an error */
838 hr
= IDirect3DDevice8_EndScene(pDevice
);
839 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
841 /* Two nested BeginScene and EndScene calls */
842 hr
= IDirect3DDevice8_BeginScene(pDevice
);
843 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr
);
844 hr
= IDirect3DDevice8_BeginScene(pDevice
);
845 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_BeginScene returned %#08x\n", hr
);
846 hr
= IDirect3DDevice8_EndScene(pDevice
);
847 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed with %#08x\n", hr
);
848 hr
= IDirect3DDevice8_EndScene(pDevice
);
849 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
851 /* StretchRect does not exit in Direct3D8, so no equivalent to the d3d9 stretchrect tests */
854 if(pD3d
) IDirect3D8_Release(pD3d
);
855 if(pDevice
) IDirect3D8_Release(pDevice
);
856 if(hwnd
) DestroyWindow(hwnd
);
859 static void test_shader(void)
863 IDirect3D8
*pD3d
= NULL
;
864 IDirect3DDevice8
*pDevice
= NULL
;
865 D3DPRESENT_PARAMETERS d3dpp
;
866 D3DDISPLAYMODE d3ddm
;
867 DWORD hPixelShader
= 0, hVertexShader
= 0;
868 DWORD hPixelShader2
= 0, hVertexShader2
= 0;
871 DWORD fvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
875 static DWORD dwVertexDecl
[] =
878 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
),
881 DWORD decl_normal_float2
[] =
884 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
885 D3DVSD_REG(D3DVSDE_NORMAL
, D3DVSDT_FLOAT2
), /* D3DVSDE_NORMAL, Register v1 */
888 DWORD decl_normal_float4
[] =
891 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
892 D3DVSD_REG(D3DVSDE_NORMAL
, D3DVSDT_FLOAT4
), /* D3DVSDE_NORMAL, Register v1 */
895 DWORD decl_normal_d3dcolor
[] =
898 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
899 D3DVSD_REG(D3DVSDE_NORMAL
, D3DVSDT_D3DCOLOR
),/* D3DVSDE_NORMAL, Register v1 */
902 const DWORD vertex_decl_size
= sizeof(dwVertexDecl
);
903 const DWORD simple_vs_size
= sizeof(simple_vs
);
904 const DWORD simple_ps_size
= sizeof(simple_ps
);
906 pD3d
= pDirect3DCreate8( D3D_SDK_VERSION
);
907 ok(pD3d
!= NULL
, "Failed to create IDirect3D8 object\n");
908 hwnd
= CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
909 ok(hwnd
!= NULL
, "Failed to create window\n");
910 if (!pD3d
|| !hwnd
) goto cleanup
;
912 IDirect3D8_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
913 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
914 d3dpp
.Windowed
= TRUE
;
915 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
916 d3dpp
.BackBufferWidth
= 800;
917 d3dpp
.BackBufferHeight
= 600;
918 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
921 hr
= IDirect3D8_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
922 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
923 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
|| broken(hr
== D3DERR_NOTAVAILABLE
), "IDirect3D8_CreateDevice failed with %#08x\n", hr
);
926 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr
);
929 IDirect3DDevice8_GetDeviceCaps(pDevice
, &caps
);
931 /* Test setting and retrieving a FVF */
932 hr
= IDirect3DDevice8_SetVertexShader(pDevice
, fvf
);
933 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
934 hr
= IDirect3DDevice8_GetVertexShader(pDevice
, &hTempHandle
);
935 ok(SUCCEEDED(hr
), "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
936 ok(hTempHandle
== fvf
, "Vertex shader %#08x is set, expected %#08x\n", hTempHandle
, fvf
);
938 /* First create a vertex shader */
939 hr
= IDirect3DDevice8_SetVertexShader(pDevice
, 0);
940 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
941 hr
= IDirect3DDevice8_CreateVertexShader(pDevice
, dwVertexDecl
, simple_vs
, &hVertexShader
, 0);
942 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
943 /* Msdn says that the new vertex shader is set immediately. This is wrong, apparently */
944 hr
= IDirect3DDevice8_GetVertexShader(pDevice
, &hTempHandle
);
945 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
946 ok(hTempHandle
== 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, 0);
947 /* Assign the shader, then verify that GetVertexShader works */
948 hr
= IDirect3DDevice8_SetVertexShader(pDevice
, hVertexShader
);
949 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
950 hr
= IDirect3DDevice8_GetVertexShader(pDevice
, &hTempHandle
);
951 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
952 ok(hTempHandle
== hVertexShader
, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, hVertexShader
);
953 /* Verify that we can retrieve the declaration */
954 hr
= IDirect3DDevice8_GetVertexShaderDeclaration(pDevice
, hVertexShader
, NULL
, &data_size
);
955 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr
);
956 ok(data_size
== vertex_decl_size
, "Got data_size %u, expected %u\n", data_size
, vertex_decl_size
);
957 data
= HeapAlloc(GetProcessHeap(), 0, vertex_decl_size
);
959 hr
= IDirect3DDevice8_GetVertexShaderDeclaration(pDevice
, hVertexShader
, data
, &data_size
);
960 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_GetVertexShaderDeclaration returned (%#08x), "
961 "expected D3DERR_INVALIDCALL\n", hr
);
962 ok(data_size
== 1, "Got data_size %u, expected 1\n", data_size
);
963 data_size
= vertex_decl_size
;
964 hr
= IDirect3DDevice8_GetVertexShaderDeclaration(pDevice
, hVertexShader
, data
, &data_size
);
965 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr
);
966 ok(data_size
== vertex_decl_size
, "Got data_size %u, expected %u\n", data_size
, vertex_decl_size
);
967 ok(!memcmp(data
, dwVertexDecl
, vertex_decl_size
), "data not equal to shader declaration\n");
968 HeapFree(GetProcessHeap(), 0, data
);
969 /* Verify that we can retrieve the shader function */
970 hr
= IDirect3DDevice8_GetVertexShaderFunction(pDevice
, hVertexShader
, NULL
, &data_size
);
971 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr
);
972 ok(data_size
== simple_vs_size
, "Got data_size %u, expected %u\n", data_size
, simple_vs_size
);
973 data
= HeapAlloc(GetProcessHeap(), 0, simple_vs_size
);
975 hr
= IDirect3DDevice8_GetVertexShaderFunction(pDevice
, hVertexShader
, data
, &data_size
);
976 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_GetVertexShaderFunction returned (%#08x), "
977 "expected D3DERR_INVALIDCALL\n", hr
);
978 ok(data_size
== 1, "Got data_size %u, expected 1\n", data_size
);
979 data_size
= simple_vs_size
;
980 hr
= IDirect3DDevice8_GetVertexShaderFunction(pDevice
, hVertexShader
, data
, &data_size
);
981 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr
);
982 ok(data_size
== simple_vs_size
, "Got data_size %u, expected %u\n", data_size
, simple_vs_size
);
983 ok(!memcmp(data
, simple_vs
, simple_vs_size
), "data not equal to shader function\n");
984 HeapFree(GetProcessHeap(), 0, data
);
985 /* Delete the assigned shader. This is supposed to work */
986 hr
= IDirect3DDevice8_DeleteVertexShader(pDevice
, hVertexShader
);
987 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
988 /* The shader should be unset now */
989 hr
= IDirect3DDevice8_GetVertexShader(pDevice
, &hTempHandle
);
990 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
991 ok(hTempHandle
== 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, 0);
993 /* Test a broken declaration. 3DMark2001 tries to use normals with 2 components
994 * First try the fixed function shader function, then a custom one
996 hr
= IDirect3DDevice8_CreateVertexShader(pDevice
, decl_normal_float2
, 0, &hVertexShader
, 0);
997 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
998 if(SUCCEEDED(hr
)) IDirect3DDevice8_DeleteVertexShader(pDevice
, hVertexShader
);
999 hr
= IDirect3DDevice8_CreateVertexShader(pDevice
, decl_normal_float4
, 0, &hVertexShader
, 0);
1000 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1001 if(SUCCEEDED(hr
)) IDirect3DDevice8_DeleteVertexShader(pDevice
, hVertexShader
);
1002 hr
= IDirect3DDevice8_CreateVertexShader(pDevice
, decl_normal_d3dcolor
, 0, &hVertexShader
, 0);
1003 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1004 if(SUCCEEDED(hr
)) IDirect3DDevice8_DeleteVertexShader(pDevice
, hVertexShader
);
1006 hr
= IDirect3DDevice8_CreateVertexShader(pDevice
, decl_normal_float2
, simple_vs
, &hVertexShader
, 0);
1007 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1008 if(SUCCEEDED(hr
)) IDirect3DDevice8_DeleteVertexShader(pDevice
, hVertexShader
);
1010 if (caps
.PixelShaderVersion
>= D3DPS_VERSION(1, 0))
1012 /* The same with a pixel shader */
1013 hr
= IDirect3DDevice8_CreatePixelShader(pDevice
, simple_ps
, &hPixelShader
);
1014 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
1015 /* Msdn says that the new pixel shader is set immediately. This is wrong, apparently */
1016 hr
= IDirect3DDevice8_GetPixelShader(pDevice
, &hTempHandle
);
1017 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
1018 ok(hTempHandle
== 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, 0);
1019 /* Assign the shader, then verify that GetPixelShader works */
1020 hr
= IDirect3DDevice8_SetPixelShader(pDevice
, hPixelShader
);
1021 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr
);
1022 hr
= IDirect3DDevice8_GetPixelShader(pDevice
, &hTempHandle
);
1023 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
1024 ok(hTempHandle
== hPixelShader
, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, hPixelShader
);
1025 /* Verify that we can retrieve the shader function */
1026 hr
= IDirect3DDevice8_GetPixelShaderFunction(pDevice
, hPixelShader
, NULL
, &data_size
);
1027 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr
);
1028 ok(data_size
== simple_ps_size
, "Got data_size %u, expected %u\n", data_size
, simple_ps_size
);
1029 data
= HeapAlloc(GetProcessHeap(), 0, simple_ps_size
);
1031 hr
= IDirect3DDevice8_GetPixelShaderFunction(pDevice
, hPixelShader
, data
, &data_size
);
1032 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_GetPixelShaderFunction returned (%#08x), "
1033 "expected D3DERR_INVALIDCALL\n", hr
);
1034 ok(data_size
== 1, "Got data_size %u, expected 1\n", data_size
);
1035 data_size
= simple_ps_size
;
1036 hr
= IDirect3DDevice8_GetPixelShaderFunction(pDevice
, hPixelShader
, data
, &data_size
);
1037 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr
);
1038 ok(data_size
== simple_ps_size
, "Got data_size %u, expected %u\n", data_size
, simple_ps_size
);
1039 ok(!memcmp(data
, simple_ps
, simple_ps_size
), "data not equal to shader function\n");
1040 HeapFree(GetProcessHeap(), 0, data
);
1041 /* Delete the assigned shader. This is supposed to work */
1042 hr
= IDirect3DDevice8_DeletePixelShader(pDevice
, hPixelShader
);
1043 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
1044 /* The shader should be unset now */
1045 hr
= IDirect3DDevice8_GetPixelShader(pDevice
, &hTempHandle
);
1046 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
1047 ok(hTempHandle
== 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, 0);
1049 /* What happens if a non-bound shader is deleted? */
1050 hr
= IDirect3DDevice8_CreatePixelShader(pDevice
, simple_ps
, &hPixelShader
);
1051 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
1052 hr
= IDirect3DDevice8_CreatePixelShader(pDevice
, simple_ps
, &hPixelShader2
);
1053 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
1055 hr
= IDirect3DDevice8_SetPixelShader(pDevice
, hPixelShader
);
1056 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr
);
1057 hr
= IDirect3DDevice8_DeletePixelShader(pDevice
, hPixelShader2
);
1058 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
1059 hr
= IDirect3DDevice8_GetPixelShader(pDevice
, &hTempHandle
);
1060 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
1061 ok(hTempHandle
== hPixelShader
, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, hPixelShader
);
1062 hr
= IDirect3DDevice8_DeletePixelShader(pDevice
, hPixelShader
);
1063 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
1067 skip("Pixel shaders not supported\n");
1070 /* What happens if a non-bound shader is deleted? */
1071 hr
= IDirect3DDevice8_CreateVertexShader(pDevice
, dwVertexDecl
, NULL
, &hVertexShader
, 0);
1072 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1073 hr
= IDirect3DDevice8_CreateVertexShader(pDevice
, dwVertexDecl
, NULL
, &hVertexShader2
, 0);
1074 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1076 hr
= IDirect3DDevice8_SetVertexShader(pDevice
, hVertexShader
);
1077 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
1078 hr
= IDirect3DDevice8_DeleteVertexShader(pDevice
, hVertexShader2
);
1079 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
1080 hr
= IDirect3DDevice8_GetVertexShader(pDevice
, &hTempHandle
);
1081 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
1082 ok(hTempHandle
== hVertexShader
, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, hVertexShader
);
1083 hr
= IDirect3DDevice8_DeleteVertexShader(pDevice
, hVertexShader
);
1084 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
1087 if(pD3d
) IDirect3D8_Release(pD3d
);
1088 if(pDevice
) IDirect3D8_Release(pDevice
);
1089 if(hwnd
) DestroyWindow(hwnd
);
1092 static void test_limits(void)
1096 IDirect3D8
*pD3d
= NULL
;
1097 IDirect3DDevice8
*pDevice
= NULL
;
1098 D3DPRESENT_PARAMETERS d3dpp
;
1099 D3DDISPLAYMODE d3ddm
;
1100 IDirect3DTexture8
*pTexture
= NULL
;
1103 pD3d
= pDirect3DCreate8( D3D_SDK_VERSION
);
1104 ok(pD3d
!= NULL
, "Failed to create IDirect3D8 object\n");
1105 hwnd
= CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1106 ok(hwnd
!= NULL
, "Failed to create window\n");
1107 if (!pD3d
|| !hwnd
) goto cleanup
;
1109 IDirect3D8_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
1110 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1111 d3dpp
.Windowed
= TRUE
;
1112 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1113 d3dpp
.BackBufferWidth
= 800;
1114 d3dpp
.BackBufferHeight
= 600;
1115 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1116 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1117 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
1119 hr
= IDirect3D8_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1120 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
1121 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
|| broken(hr
== D3DERR_NOTAVAILABLE
), "IDirect3D8_CreateDevice failed with %#08x\n", hr
);
1124 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr
);
1128 hr
= IDirect3DDevice8_CreateTexture(pDevice
, 16, 16, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &pTexture
);
1129 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateTexture failed with %#08x\n", hr
);
1130 if(!pTexture
) goto cleanup
;
1132 /* There are 8 texture stages. We should be able to access all of them */
1133 for(i
= 0; i
< 8; i
++) {
1134 hr
= IDirect3DDevice8_SetTexture(pDevice
, i
, (IDirect3DBaseTexture8
*) pTexture
);
1135 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i
, hr
);
1136 hr
= IDirect3DDevice8_SetTexture(pDevice
, i
, NULL
);
1137 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i
, hr
);
1138 hr
= IDirect3DDevice8_SetTextureStageState(pDevice
, i
, D3DTSS_COLOROP
, D3DTOP_ADD
);
1139 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %#08x\n", i
, hr
);
1142 /* Investigations show that accessing higher textures stage states does not return an error either. Writing
1143 * to too high texture stages(approximately texture 40) causes memory corruption in windows, so there is no
1144 * bounds checking but how do I test that?
1148 if(pTexture
) IDirect3DTexture8_Release(pTexture
);
1149 if(pD3d
) IDirect3D8_Release(pD3d
);
1150 if(pDevice
) IDirect3D8_Release(pDevice
);
1151 if(hwnd
) DestroyWindow(hwnd
);
1154 static void test_lights(void)
1156 D3DPRESENT_PARAMETERS d3dpp
;
1157 IDirect3DDevice8
*device
= NULL
;
1164 D3DDISPLAYMODE d3ddm
;
1166 d3d8
= pDirect3DCreate8( D3D_SDK_VERSION
);
1167 ok(d3d8
!= NULL
, "Failed to create IDirect3D8 object\n");
1168 hwnd
= CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1169 ok(hwnd
!= NULL
, "Failed to create window\n");
1170 if (!d3d8
|| !hwnd
) goto cleanup
;
1172 IDirect3D8_GetAdapterDisplayMode( d3d8
, D3DADAPTER_DEFAULT
, &d3ddm
);
1173 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1174 d3dpp
.Windowed
= TRUE
;
1175 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1176 d3dpp
.BackBufferWidth
= 800;
1177 d3dpp
.BackBufferHeight
= 600;
1178 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1179 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1180 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
1182 hr
= IDirect3D8_CreateDevice( d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1183 D3DCREATE_HARDWARE_VERTEXPROCESSING
| D3DCREATE_PUREDEVICE
, &d3dpp
, &device
);
1184 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
|| hr
== D3DERR_INVALIDCALL
,
1185 "IDirect3D8_CreateDevice failed with %08x\n", hr
);
1188 skip("Failed to create a d3d device\n");
1192 memset(&caps
, 0, sizeof(caps
));
1193 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
1194 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetDeviceCaps failed with %08x\n", hr
);
1196 for(i
= 1; i
<= caps
.MaxActiveLights
; i
++) {
1197 hr
= IDirect3DDevice8_LightEnable(device
, i
, TRUE
);
1198 ok(hr
== D3D_OK
, "Enabling light %u failed with %08x\n", i
, hr
);
1199 hr
= IDirect3DDevice8_GetLightEnable(device
, i
, &enabled
);
1200 ok(hr
== D3D_OK
|| broken(hr
== D3DERR_INVALIDCALL
),
1201 "GetLightEnable on light %u failed with %08x\n", i
, hr
);
1202 ok(enabled
, "Light %d is %s\n", i
, enabled
? "enabled" : "disabled");
1205 /* TODO: Test the rendering results in this situation */
1206 hr
= IDirect3DDevice8_LightEnable(device
, i
+ 1, TRUE
);
1208 broken(hr
== D3DERR_INVALIDCALL
), /* Some Win9x and WinME */
1209 "Enabling one light more than supported returned %08x\n", hr
);
1210 hr
= IDirect3DDevice8_GetLightEnable(device
, i
+ 1, &enabled
);
1211 ok(hr
== D3D_OK
, "GetLightEnable on light %u failed with %08x\n", i
+ 1, hr
);
1212 ok(enabled
, "Light %d is %s\n", i
+ 1, enabled
? "enabled" : "disabled");
1213 hr
= IDirect3DDevice8_LightEnable(device
, i
+ 1, FALSE
);
1214 ok(hr
== D3D_OK
, "Disabling the additional returned %08x\n", hr
);
1216 for(i
= 1; i
<= caps
.MaxActiveLights
; i
++) {
1217 hr
= IDirect3DDevice8_LightEnable(device
, i
, FALSE
);
1218 ok(hr
== D3D_OK
, "Disabling light %u failed with %08x\n", i
, hr
);
1222 if(device
) IDirect3DDevice8_Release(device
);
1223 if(d3d8
) IDirect3D8_Release(d3d8
);
1226 static void test_render_zero_triangles(void)
1228 D3DPRESENT_PARAMETERS d3dpp
;
1229 IDirect3DDevice8
*device
= NULL
;
1233 D3DDISPLAYMODE d3ddm
;
1242 { 0.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
1243 { 0.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
1244 { 1.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
1245 { 1.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
1248 d3d8
= pDirect3DCreate8( D3D_SDK_VERSION
);
1249 ok(d3d8
!= NULL
, "Failed to create IDirect3D8 object\n");
1250 hwnd
= CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1251 ok(hwnd
!= NULL
, "Failed to create window\n");
1252 if (!d3d8
|| !hwnd
) goto cleanup
;
1254 IDirect3D8_GetAdapterDisplayMode( d3d8
, D3DADAPTER_DEFAULT
, &d3ddm
);
1255 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1256 d3dpp
.Windowed
= TRUE
;
1257 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1258 d3dpp
.BackBufferWidth
= 800;
1259 d3dpp
.BackBufferHeight
= 600;
1260 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1261 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1262 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
1264 hr
= IDirect3D8_CreateDevice( d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1265 D3DCREATE_HARDWARE_VERTEXPROCESSING
| D3DCREATE_PUREDEVICE
, &d3dpp
, &device
);
1266 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
|| hr
== D3DERR_INVALIDCALL
,
1267 "IDirect3D8_CreateDevice failed with %08x\n", hr
);
1270 skip("Failed to create a d3d device\n");
1274 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
1275 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
1277 hr
= IDirect3DDevice8_BeginScene(device
);
1278 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr
);
1281 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 0 /* NumVerts */,
1282 0 /*PrimCount */, NULL
, D3DFMT_INDEX16
, quad
, sizeof(quad
[0]));
1283 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr
);
1285 IDirect3DDevice8_EndScene(device
);
1286 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed with %#08x\n", hr
);
1289 IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
1292 if(device
) IDirect3DDevice8_Release(device
);
1293 if(d3d8
) IDirect3D8_Release(d3d8
);
1296 static void test_depth_stencil_reset(void)
1298 D3DPRESENT_PARAMETERS present_parameters
;
1299 D3DDISPLAYMODE display_mode
;
1300 IDirect3DSurface8
*surface
;
1301 IDirect3DDevice8
*device
= NULL
;
1306 d3d8
= pDirect3DCreate8(D3D_SDK_VERSION
);
1307 ok(d3d8
!= NULL
, "Failed to create IDirect3D8 object\n");
1308 hwnd
= CreateWindow("static", "d3d8_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1309 ok(hwnd
!= NULL
, "Failed to create window\n");
1310 if (!d3d8
|| !hwnd
) goto cleanup
;
1312 IDirect3D8_GetAdapterDisplayMode(d3d8
, D3DADAPTER_DEFAULT
, &display_mode
);
1313 memset(&present_parameters
, 0, sizeof(present_parameters
));
1314 present_parameters
.Windowed
= TRUE
;
1315 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1316 present_parameters
.BackBufferFormat
= display_mode
.Format
;
1317 present_parameters
.EnableAutoDepthStencil
= TRUE
;
1318 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1320 hr
= IDirect3D8_CreateDevice(d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
1321 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
1324 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr
);
1328 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
1329 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed with %#x\n", hr
);
1331 hr
= IDirect3DDevice8_SetRenderTarget(device
, NULL
, NULL
);
1332 ok(hr
== D3D_OK
, "SetRenderTarget failed with 0x%08x\n", hr
);
1334 hr
= IDirect3DDevice8_GetRenderTarget(device
, &surface
);
1335 ok(hr
== D3D_OK
, "GetRenderTarget failed with 0x%08x\n", hr
);
1336 ok(surface
!= NULL
, "Render target should not be NULL\n");
1337 if (surface
) IDirect3DSurface8_Release(surface
);
1339 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surface
);
1340 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr
);
1341 ok(surface
== NULL
, "Depth stencil should be NULL\n");
1343 present_parameters
.EnableAutoDepthStencil
= TRUE
;
1344 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1345 hr
= IDirect3DDevice8_Reset(device
, &present_parameters
);
1346 ok(hr
== D3D_OK
, "Reset failed with 0x%08x\n", hr
);
1348 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surface
);
1349 ok(hr
== D3D_OK
, "GetDepthStencilSurface failed with 0x%08x\n", hr
);
1350 ok(surface
!= NULL
, "Depth stencil should not be NULL\n");
1351 if (surface
) IDirect3DSurface8_Release(surface
);
1353 present_parameters
.EnableAutoDepthStencil
= FALSE
;
1354 hr
= IDirect3DDevice8_Reset(device
, &present_parameters
);
1355 ok(hr
== D3D_OK
, "Reset failed with 0x%08x\n", hr
);
1357 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surface
);
1358 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr
);
1359 ok(surface
== NULL
, "Depth stencil should be NULL\n");
1362 IDirect3D8_GetAdapterDisplayMode( d3d8
, D3DADAPTER_DEFAULT
, &display_mode
);
1364 ZeroMemory( &present_parameters
, sizeof(present_parameters
) );
1365 present_parameters
.Windowed
= TRUE
;
1366 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1367 present_parameters
.BackBufferFormat
= display_mode
.Format
;
1368 present_parameters
.EnableAutoDepthStencil
= FALSE
;
1369 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1371 hr
= IDirect3D8_CreateDevice( d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
1372 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
1376 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr
);
1380 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
1381 ok(hr
== D3D_OK
, "IDirect3DDevice8_TestCooperativeLevel after creation returned %#x\n", hr
);
1383 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1384 present_parameters
.Windowed
= TRUE
;
1385 present_parameters
.BackBufferWidth
= 400;
1386 present_parameters
.BackBufferHeight
= 300;
1387 present_parameters
.EnableAutoDepthStencil
= TRUE
;
1388 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1390 hr
= IDirect3DDevice8_Reset(device
, &present_parameters
);
1391 ok(hr
== D3D_OK
, "IDirect3DDevice8_Reset failed with 0x%08x\n", hr
);
1393 if (FAILED(hr
)) goto cleanup
;
1395 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surface
);
1396 ok(hr
== D3D_OK
, "GetDepthStencilSurface failed with 0x%08x\n", hr
);
1397 ok(surface
!= NULL
, "Depth stencil should not be NULL\n");
1398 if (surface
) IDirect3DSurface8_Release(surface
);
1401 if(d3d8
) IDirect3D8_Release(d3d8
);
1402 if(device
) IDirect3D8_Release(device
);
1407 HMODULE d3d8_handle
= LoadLibraryA( "d3d8.dll" );
1410 skip("Could not load d3d8.dll\n");
1414 pDirect3DCreate8
= (void *)GetProcAddress( d3d8_handle
, "Direct3DCreate8" );
1415 ok(pDirect3DCreate8
!= NULL
, "Failed to get address of Direct3DCreate8\n");
1416 if (pDirect3DCreate8
)
1419 d3d8
= pDirect3DCreate8( D3D_SDK_VERSION
);
1422 skip("could not create D3D8\n");
1425 IDirect3D8_Release(d3d8
);
1427 test_display_modes();
1428 test_shader_versions();
1431 test_mipmap_levels();
1438 test_render_zero_triangles();
1439 test_depth_stencil_reset();