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(
97 IDirect3DDevice8
* device
,
98 int width
, int height
, int count
)
101 IDirect3DBaseTexture8
* texture
= NULL
;
102 HRESULT hr
= IDirect3DDevice8_CreateTexture( device
, width
, height
, 0, 0,
103 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, (IDirect3DTexture8
**) &texture
);
106 DWORD levels
= IDirect3DBaseTexture8_GetLevelCount(texture
);
107 ok(levels
== count
, "Invalid level count. Expected %d got %u\n", count
, levels
);
109 trace("CreateTexture failed: %#08x\n", hr
);
111 if (texture
) IUnknown_Release( texture
);
114 static void test_mipmap_levels(void)
120 IDirect3D8
*pD3d
= NULL
;
121 IDirect3DDevice8
*pDevice
= NULL
;
122 D3DPRESENT_PARAMETERS d3dpp
;
123 D3DDISPLAYMODE d3ddm
;
125 pD3d
= pDirect3DCreate8( D3D_SDK_VERSION
);
126 ok(pD3d
!= NULL
, "Failed to create IDirect3D8 object\n");
127 hwnd
= CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
128 ok(hwnd
!= NULL
, "Failed to create window\n");
129 if (!pD3d
|| !hwnd
) goto cleanup
;
131 IDirect3D8_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
132 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
133 d3dpp
.Windowed
= TRUE
;
134 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
135 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
137 hr
= IDirect3D8_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
138 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
141 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr
);
145 check_mipmap_levels(pDevice
, 32, 32, 6);
146 check_mipmap_levels(pDevice
, 256, 1, 9);
147 check_mipmap_levels(pDevice
, 1, 256, 9);
148 check_mipmap_levels(pDevice
, 1, 1, 1);
151 if (pD3d
) IUnknown_Release( pD3d
);
152 if (pDevice
) IUnknown_Release( pDevice
);
153 DestroyWindow( hwnd
);
156 static void test_swapchain(void)
160 IDirect3D8
*pD3d
= NULL
;
161 IDirect3DDevice8
*pDevice
= NULL
;
162 IDirect3DSwapChain8
*swapchain1
= NULL
;
163 IDirect3DSwapChain8
*swapchain2
= NULL
;
164 IDirect3DSwapChain8
*swapchain3
= NULL
;
165 IDirect3DSurface8
*backbuffer
= NULL
;
166 D3DPRESENT_PARAMETERS d3dpp
;
167 D3DDISPLAYMODE d3ddm
;
169 pD3d
= pDirect3DCreate8( D3D_SDK_VERSION
);
170 ok(pD3d
!= NULL
, "Failed to create IDirect3D8 object\n");
171 hwnd
= CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
172 ok(hwnd
!= NULL
, "Failed to create window\n");
173 if (!pD3d
|| !hwnd
) goto cleanup
;
175 IDirect3D8_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
176 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
177 d3dpp
.Windowed
= TRUE
;
178 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
179 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
180 d3dpp
.BackBufferCount
= 0;
182 hr
= IDirect3D8_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
183 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
186 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr
);
190 /* Check if the back buffer count was modified */
191 ok(d3dpp
.BackBufferCount
== 1, "The back buffer count in the presentparams struct is %d\n", d3dpp
.BackBufferCount
);
193 /* Create a bunch of swapchains */
194 d3dpp
.BackBufferCount
= 0;
195 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(pDevice
, &d3dpp
, &swapchain1
);
196 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%#08x)\n", hr
);
197 ok(d3dpp
.BackBufferCount
== 1, "The back buffer count in the presentparams struct is %d\n", d3dpp
.BackBufferCount
);
199 d3dpp
.BackBufferCount
= 1;
200 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(pDevice
, &d3dpp
, &swapchain2
);
201 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%#08x)\n", hr
);
203 d3dpp
.BackBufferCount
= 2;
204 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(pDevice
, &d3dpp
, &swapchain3
);
205 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%#08x)\n", hr
);
207 /* Swapchain 3, created with backbuffercount 2 */
208 backbuffer
= (void *) 0xdeadbeef;
209 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 0, 0, &backbuffer
);
210 ok(SUCCEEDED(hr
), "Failed to get the 1st back buffer (%#08x)\n", hr
);
211 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
212 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
214 backbuffer
= (void *) 0xdeadbeef;
215 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 1, 0, &backbuffer
);
216 ok(SUCCEEDED(hr
), "Failed to get the 2nd back buffer (%#08x)\n", hr
);
217 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
218 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
220 backbuffer
= (void *) 0xdeadbeef;
221 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 2, 0, &backbuffer
);
222 ok(hr
== D3DERR_INVALIDCALL
, "GetBackBuffer returned %#08x\n", hr
);
223 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
224 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
226 backbuffer
= (void *) 0xdeadbeef;
227 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 3, 0, &backbuffer
);
228 ok(FAILED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
229 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
230 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
233 /* Check the back buffers of the swapchains */
234 /* Swapchain 1, created with backbuffercount 0 */
235 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain1
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
236 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
237 ok(backbuffer
!= NULL
, "The back buffer is NULL (%#08x)\n", hr
);
238 if(backbuffer
) IDirect3DSurface8_Release(backbuffer
);
240 backbuffer
= (void *) 0xdeadbeef;
241 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain1
, 1, 0, &backbuffer
);
242 ok(FAILED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
243 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
244 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
246 /* Swapchain 2 - created with backbuffercount 1 */
247 backbuffer
= (void *) 0xdeadbeef;
248 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain2
, 0, 0, &backbuffer
);
249 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
250 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
251 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
253 backbuffer
= (void *) 0xdeadbeef;
254 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain2
, 1, 0, &backbuffer
);
255 ok(hr
== D3DERR_INVALIDCALL
, "GetBackBuffer returned %#08x\n", hr
);
256 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
257 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
259 backbuffer
= (void *) 0xdeadbeef;
260 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain2
, 2, 0, &backbuffer
);
261 ok(FAILED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
262 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
263 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
266 if(swapchain1
) IDirect3DSwapChain8_Release(swapchain1
);
267 if(swapchain2
) IDirect3DSwapChain8_Release(swapchain2
);
268 if(swapchain3
) IDirect3DSwapChain8_Release(swapchain3
);
269 if(pDevice
) IDirect3DDevice8_Release(pDevice
);
270 if(pD3d
) IDirect3DDevice8_Release(pD3d
);
271 DestroyWindow( hwnd
);
274 static void test_refcount(void)
278 IDirect3D8
*pD3d
= NULL
;
279 IDirect3DDevice8
*pDevice
= NULL
;
280 IDirect3DVertexBuffer8
*pVertexBuffer
= NULL
;
281 IDirect3DIndexBuffer8
*pIndexBuffer
= NULL
;
282 DWORD dVertexShader
= -1;
283 DWORD dPixelShader
= -1;
284 IDirect3DCubeTexture8
*pCubeTexture
= NULL
;
285 IDirect3DTexture8
*pTexture
= NULL
;
286 IDirect3DVolumeTexture8
*pVolumeTexture
= NULL
;
287 IDirect3DVolume8
*pVolumeLevel
= NULL
;
288 IDirect3DSurface8
*pStencilSurface
= NULL
;
289 IDirect3DSurface8
*pImageSurface
= NULL
;
290 IDirect3DSurface8
*pRenderTarget
= NULL
;
291 IDirect3DSurface8
*pRenderTarget2
= NULL
;
292 IDirect3DSurface8
*pRenderTarget3
= NULL
;
293 IDirect3DSurface8
*pTextureLevel
= NULL
;
294 IDirect3DSurface8
*pBackBuffer
= NULL
;
295 DWORD dStateBlock
= -1;
296 IDirect3DSwapChain8
*pSwapChain
= NULL
;
299 D3DPRESENT_PARAMETERS d3dpp
;
300 D3DDISPLAYMODE d3ddm
;
301 int refcount
= 0, tmp
;
306 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
307 D3DVSD_REG(D3DVSDE_DIFFUSE
, D3DVSDT_D3DCOLOR
), /* D3DVSDE_DIFFUSE, Register v5 */
311 pD3d
= pDirect3DCreate8( D3D_SDK_VERSION
);
312 ok(pD3d
!= NULL
, "Failed to create IDirect3D8 object\n");
313 hwnd
= CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
314 ok(hwnd
!= NULL
, "Failed to create window\n");
315 if (!pD3d
|| !hwnd
) goto cleanup
;
317 IDirect3D8_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
318 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
319 d3dpp
.Windowed
= TRUE
;
320 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
321 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
322 d3dpp
.EnableAutoDepthStencil
= TRUE
;
323 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
325 hr
= IDirect3D8_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
326 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
329 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr
);
332 IDirect3DDevice8_GetDeviceCaps(pDevice
, &caps
);
334 refcount
= get_refcount( (IUnknown
*)pDevice
);
335 ok(refcount
== 1, "Invalid device RefCount %d\n", refcount
);
338 * Check refcount of implicit surfaces. Findings:
339 * - the container is the device
340 * - they hold a reference to the device
341 * - they are created with a refcount of 0 (Get/Release returns original refcount)
342 * - they are not freed if refcount reaches 0.
343 * - the refcount is not forwarded to the container.
345 hr
= IDirect3DDevice8_GetRenderTarget(pDevice
, &pRenderTarget
);
346 CHECK_CALL( hr
, "GetRenderTarget", pDevice
, ++refcount
);
349 CHECK_SURFACE_CONTAINER( pRenderTarget
, IID_IDirect3DDevice8
, pDevice
);
350 CHECK_REFCOUNT( pRenderTarget
, 1);
352 CHECK_ADDREF_REFCOUNT(pRenderTarget
, 2);
353 CHECK_REFCOUNT(pDevice
, refcount
);
354 CHECK_RELEASE_REFCOUNT(pRenderTarget
, 1);
355 CHECK_REFCOUNT(pDevice
, refcount
);
357 hr
= IDirect3DDevice8_GetRenderTarget(pDevice
, &pRenderTarget
);
358 CHECK_CALL( hr
, "GetRenderTarget", pDevice
, refcount
);
359 CHECK_REFCOUNT( pRenderTarget
, 2);
360 CHECK_RELEASE_REFCOUNT( pRenderTarget
, 1);
361 CHECK_RELEASE_REFCOUNT( pRenderTarget
, 0);
362 CHECK_REFCOUNT( pDevice
, --refcount
);
364 /* The render target is released with the device, so AddRef with refcount=0 is fine here. */
365 CHECK_ADDREF_REFCOUNT(pRenderTarget
, 1);
366 CHECK_REFCOUNT(pDevice
, ++refcount
);
367 CHECK_RELEASE_REFCOUNT(pRenderTarget
, 0);
368 CHECK_REFCOUNT(pDevice
, --refcount
);
371 /* Render target and back buffer are identical. */
372 hr
= IDirect3DDevice8_GetBackBuffer(pDevice
, 0, 0, &pBackBuffer
);
373 CHECK_CALL( hr
, "GetBackBuffer", pDevice
, ++refcount
);
376 CHECK_RELEASE_REFCOUNT(pBackBuffer
, 0);
377 ok(pRenderTarget
== pBackBuffer
, "RenderTarget=%p and BackBuffer=%p should be the same.\n",
378 pRenderTarget
, pBackBuffer
);
381 CHECK_REFCOUNT( pDevice
, --refcount
);
383 hr
= IDirect3DDevice8_GetDepthStencilSurface(pDevice
, &pStencilSurface
);
384 CHECK_CALL( hr
, "GetDepthStencilSurface", pDevice
, ++refcount
);
387 CHECK_SURFACE_CONTAINER( pStencilSurface
, IID_IDirect3DDevice8
, pDevice
);
388 CHECK_REFCOUNT( pStencilSurface
, 1);
390 CHECK_ADDREF_REFCOUNT(pStencilSurface
, 2);
391 CHECK_REFCOUNT(pDevice
, refcount
);
392 CHECK_RELEASE_REFCOUNT(pStencilSurface
, 1);
393 CHECK_REFCOUNT(pDevice
, refcount
);
395 CHECK_RELEASE_REFCOUNT( pStencilSurface
, 0);
396 CHECK_REFCOUNT( pDevice
, --refcount
);
398 /* The stencil surface is released with the device, so AddRef with refcount=0 is fine here. */
399 CHECK_ADDREF_REFCOUNT(pStencilSurface
, 1);
400 CHECK_REFCOUNT(pDevice
, ++refcount
);
401 CHECK_RELEASE_REFCOUNT(pStencilSurface
, 0);
402 CHECK_REFCOUNT(pDevice
, --refcount
);
403 pStencilSurface
= NULL
;
407 hr
= IDirect3DDevice8_CreateIndexBuffer( pDevice
, 16, 0, D3DFMT_INDEX32
, D3DPOOL_DEFAULT
, &pIndexBuffer
);
408 CHECK_CALL( hr
, "CreateIndexBuffer", pDevice
, ++refcount
);
411 tmp
= get_refcount( (IUnknown
*)pIndexBuffer
);
413 hr
= IDirect3DDevice8_SetIndices(pDevice
, pIndexBuffer
, 0);
414 CHECK_CALL( hr
, "SetIndices", pIndexBuffer
, tmp
);
415 hr
= IDirect3DDevice8_SetIndices(pDevice
, NULL
, 0);
416 CHECK_CALL( hr
, "SetIndices", pIndexBuffer
, tmp
);
419 hr
= IDirect3DDevice8_CreateVertexBuffer( pDevice
, 16, 0, D3DFVF_XYZ
, D3DPOOL_DEFAULT
, &pVertexBuffer
);
420 CHECK_CALL( hr
, "CreateVertexBuffer", pDevice
, ++refcount
);
423 IDirect3DVertexBuffer8
*pVBuf
= (void*)~0;
426 tmp
= get_refcount( (IUnknown
*)pVertexBuffer
);
428 hr
= IDirect3DDevice8_SetStreamSource(pDevice
, 0, pVertexBuffer
, 3 * sizeof(float));
429 CHECK_CALL( hr
, "SetStreamSource", pVertexBuffer
, tmp
);
430 hr
= IDirect3DDevice8_SetStreamSource(pDevice
, 0, NULL
, 0);
431 CHECK_CALL( hr
, "SetStreamSource", pVertexBuffer
, tmp
);
433 hr
= IDirect3DDevice8_GetStreamSource(pDevice
, 0, &pVBuf
, &stride
);
434 ok(SUCCEEDED(hr
), "GetStreamSource did not succeed with NULL stream!\n");
435 ok(pVBuf
==NULL
, "pVBuf not NULL (%p)!\n", pVBuf
);
436 ok(stride
==3*sizeof(float), "stride not 3 floats (got %u)!\n", stride
);
440 hr
= IDirect3DDevice8_CreateVertexShader( pDevice
, decl
, simple_vs
, &dVertexShader
, 0 );
441 CHECK_CALL( hr
, "CreateVertexShader", pDevice
, refcount
);
442 if (caps
.PixelShaderVersion
>= D3DPS_VERSION(1, 0))
444 hr
= IDirect3DDevice8_CreatePixelShader( pDevice
, simple_ps
, &dPixelShader
);
445 CHECK_CALL( hr
, "CreatePixelShader", pDevice
, refcount
);
448 hr
= IDirect3DDevice8_CreateTexture( pDevice
, 32, 32, 3, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pTexture
);
449 CHECK_CALL( hr
, "CreateTexture", pDevice
, ++refcount
);
452 tmp
= get_refcount( (IUnknown
*)pTexture
);
454 /* SetTexture should not increase refcounts */
455 hr
= IDirect3DDevice8_SetTexture(pDevice
, 0, (IDirect3DBaseTexture8
*) pTexture
);
456 CHECK_CALL( hr
, "SetTexture", pTexture
, tmp
);
457 hr
= IDirect3DDevice8_SetTexture(pDevice
, 0, NULL
);
458 CHECK_CALL( hr
, "SetTexture", pTexture
, tmp
);
460 /* This should not increment device refcount */
461 hr
= IDirect3DTexture8_GetSurfaceLevel( pTexture
, 1, &pTextureLevel
);
462 CHECK_CALL( hr
, "GetSurfaceLevel", pDevice
, refcount
);
463 /* But should increment texture's refcount */
464 CHECK_REFCOUNT( pTexture
, tmp
+1 );
465 /* Because the texture and surface refcount are identical */
468 CHECK_REFCOUNT ( pTextureLevel
, tmp
+1 );
469 CHECK_ADDREF_REFCOUNT ( pTextureLevel
, tmp
+2 );
470 CHECK_REFCOUNT ( pTexture
, tmp
+2 );
471 CHECK_RELEASE_REFCOUNT( pTextureLevel
, tmp
+1 );
472 CHECK_REFCOUNT ( pTexture
, tmp
+1 );
473 CHECK_RELEASE_REFCOUNT( pTexture
, tmp
);
474 CHECK_REFCOUNT ( pTextureLevel
, tmp
);
477 if(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
)
479 hr
= IDirect3DDevice8_CreateCubeTexture( pDevice
, 32, 0, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pCubeTexture
);
480 CHECK_CALL( hr
, "CreateCubeTexture", pDevice
, ++refcount
);
484 skip("Cube textures not supported\n");
486 if(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
)
488 hr
= IDirect3DDevice8_CreateVolumeTexture( pDevice
, 32, 32, 2, 0, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pVolumeTexture
);
489 CHECK_CALL( hr
, "CreateVolumeTexture", pDevice
, ++refcount
);
493 skip("Volume textures not supported\n");
498 tmp
= get_refcount( (IUnknown
*)pVolumeTexture
);
500 /* This should not increment device refcount */
501 hr
= IDirect3DVolumeTexture8_GetVolumeLevel(pVolumeTexture
, 0, &pVolumeLevel
);
502 CHECK_CALL( hr
, "GetVolumeLevel", pDevice
, refcount
);
503 /* But should increment volume texture's refcount */
504 CHECK_REFCOUNT( pVolumeTexture
, tmp
+1 );
505 /* Because the volume texture and volume refcount are identical */
508 CHECK_REFCOUNT ( pVolumeLevel
, tmp
+1 );
509 CHECK_ADDREF_REFCOUNT ( pVolumeLevel
, tmp
+2 );
510 CHECK_REFCOUNT ( pVolumeTexture
, tmp
+2 );
511 CHECK_RELEASE_REFCOUNT( pVolumeLevel
, tmp
+1 );
512 CHECK_REFCOUNT ( pVolumeTexture
, tmp
+1 );
513 CHECK_RELEASE_REFCOUNT( pVolumeTexture
, tmp
);
514 CHECK_REFCOUNT ( pVolumeLevel
, tmp
);
518 hr
= IDirect3DDevice8_CreateDepthStencilSurface( pDevice
, 32, 32, D3DFMT_D16
, D3DMULTISAMPLE_NONE
, &pStencilSurface
);
519 CHECK_CALL( hr
, "CreateDepthStencilSurface", pDevice
, ++refcount
);
520 CHECK_REFCOUNT( pStencilSurface
, 1);
521 hr
= IDirect3DDevice8_CreateImageSurface( pDevice
, 32, 32, D3DFMT_X8R8G8B8
, &pImageSurface
);
522 CHECK_CALL( hr
, "CreateImageSurface", pDevice
, ++refcount
);
523 CHECK_REFCOUNT( pImageSurface
, 1);
524 hr
= IDirect3DDevice8_CreateRenderTarget( pDevice
, 32, 32, D3DFMT_X8R8G8B8
, D3DMULTISAMPLE_NONE
, TRUE
, &pRenderTarget3
);
525 CHECK_CALL( hr
, "CreateRenderTarget", pDevice
, ++refcount
);
526 CHECK_REFCOUNT( pRenderTarget3
, 1);
528 hr
= IDirect3DDevice8_CreateStateBlock( pDevice
, D3DSBT_ALL
, &dStateBlock
);
529 CHECK_CALL( hr
, "CreateStateBlock", pDevice
, refcount
);
530 hr
= IDirect3DDevice8_CreateAdditionalSwapChain( pDevice
, &d3dpp
, &pSwapChain
);
531 CHECK_CALL( hr
, "CreateAdditionalSwapChain", pDevice
, ++refcount
);
534 /* check implicit back buffer */
535 hr
= IDirect3DSwapChain8_GetBackBuffer(pSwapChain
, 0, 0, &pBackBuffer
);
536 CHECK_CALL( hr
, "GetBackBuffer", pDevice
, ++refcount
);
537 CHECK_REFCOUNT( pSwapChain
, 1);
540 CHECK_SURFACE_CONTAINER( pBackBuffer
, IID_IDirect3DDevice8
, pDevice
);
541 CHECK_REFCOUNT( pBackBuffer
, 1);
542 CHECK_RELEASE_REFCOUNT( pBackBuffer
, 0);
543 CHECK_REFCOUNT( pDevice
, --refcount
);
545 /* The back buffer is released with the swapchain, so AddRef with refcount=0 is fine here. */
546 CHECK_ADDREF_REFCOUNT(pBackBuffer
, 1);
547 CHECK_REFCOUNT(pDevice
, ++refcount
);
548 CHECK_RELEASE_REFCOUNT(pBackBuffer
, 0);
549 CHECK_REFCOUNT(pDevice
, --refcount
);
552 CHECK_REFCOUNT( pSwapChain
, 1);
558 /* Vertex buffers can be locked multiple times */
559 hr
= IDirect3DVertexBuffer8_Lock(pVertexBuffer
, 0, 0, &data
, 0);
560 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr
);
561 hr
= IDirect3DVertexBuffer8_Lock(pVertexBuffer
, 0, 0, &data
, 0);
562 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr
);
563 hr
= IDirect3DVertexBuffer8_Unlock(pVertexBuffer
);
564 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr
);
565 hr
= IDirect3DVertexBuffer8_Unlock(pVertexBuffer
);
566 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr
);
569 /* The implicit render target is not freed if refcount reaches 0.
570 * Otherwise GetRenderTarget would re-allocate it and the pointer would change.*/
571 hr
= IDirect3DDevice8_GetRenderTarget(pDevice
, &pRenderTarget2
);
572 CHECK_CALL( hr
, "GetRenderTarget", pDevice
, ++refcount
);
575 CHECK_RELEASE_REFCOUNT(pRenderTarget2
, 0);
576 ok(pRenderTarget
== pRenderTarget2
, "RenderTarget=%p and RenderTarget2=%p should be the same.\n",
577 pRenderTarget
, pRenderTarget2
);
578 CHECK_REFCOUNT( pDevice
, --refcount
);
579 pRenderTarget2
= NULL
;
581 pRenderTarget
= NULL
;
584 CHECK_RELEASE(pDevice
, pDevice
, --refcount
);
587 CHECK_RELEASE(pVertexBuffer
, pDevice
, --refcount
);
588 CHECK_RELEASE(pIndexBuffer
, pDevice
, --refcount
);
590 if (dVertexShader
!= -1) IDirect3DDevice8_DeleteVertexShader( pDevice
, dVertexShader
);
591 if (dPixelShader
!= -1) IDirect3DDevice8_DeletePixelShader( pDevice
, dPixelShader
);
593 CHECK_RELEASE(pTexture
, pDevice
, --refcount
);
594 CHECK_RELEASE(pCubeTexture
, pDevice
, --refcount
);
595 CHECK_RELEASE(pVolumeTexture
, pDevice
, --refcount
);
597 CHECK_RELEASE(pStencilSurface
, pDevice
, --refcount
);
598 CHECK_RELEASE(pImageSurface
, pDevice
, --refcount
);
599 CHECK_RELEASE(pRenderTarget3
, pDevice
, --refcount
);
601 if (dStateBlock
!= -1) IDirect3DDevice8_DeleteStateBlock( pDevice
, dStateBlock
);
602 /* This will destroy device - cannot check the refcount here */
603 if (pSwapChain
) CHECK_RELEASE_REFCOUNT( pSwapChain
, 0);
605 if (pD3d
) CHECK_RELEASE_REFCOUNT( pD3d
, 0);
607 DestroyWindow( hwnd
);
610 static void test_cursor(void)
614 IDirect3D8
*pD3d
= NULL
;
615 IDirect3DDevice8
*pDevice
= NULL
;
616 D3DPRESENT_PARAMETERS d3dpp
;
617 D3DDISPLAYMODE d3ddm
;
619 IDirect3DSurface8
*cursor
= NULL
;
621 HMODULE user32_handle
= GetModuleHandleA("user32.dll");
623 pGetCursorInfo
= (void *)GetProcAddress(user32_handle
, "GetCursorInfo");
626 skip("GetCursorInfo is not available\n");
630 memset(&info
, 0, sizeof(info
));
631 info
.cbSize
= sizeof(info
);
632 hr
= pGetCursorInfo(&info
);
635 pD3d
= pDirect3DCreate8( D3D_SDK_VERSION
);
636 ok(pD3d
!= NULL
, "Failed to create IDirect3D8 object\n");
637 hwnd
= CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
638 ok(hwnd
!= NULL
, "Failed to create window\n");
639 if (!pD3d
|| !hwnd
) goto cleanup
;
641 IDirect3D8_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
642 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
643 d3dpp
.Windowed
= TRUE
;
644 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
645 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
647 hr
= IDirect3D8_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
648 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
651 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr
);
655 IDirect3DDevice8_CreateImageSurface(pDevice
, 32, 32, D3DFMT_A8R8G8B8
, &cursor
);
656 ok(cursor
!= NULL
, "IDirect3DDevice8_CreateOffscreenPlainSurface failed with %#08x\n", hr
);
658 /* Initially hidden */
659 hr
= IDirect3DDevice8_ShowCursor(pDevice
, TRUE
);
660 ok(hr
== FALSE
, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr
);
662 /* Not enabled without a surface*/
663 hr
= IDirect3DDevice8_ShowCursor(pDevice
, TRUE
);
664 ok(hr
== FALSE
, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr
);
667 hr
= IDirect3DDevice8_SetCursorProperties(pDevice
, 0, 0, NULL
);
668 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr
);
670 hr
= IDirect3DDevice8_SetCursorProperties(pDevice
, 0, 0, cursor
);
671 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr
);
673 IDirect3DSurface8_Release(cursor
);
675 memset(&info
, 0, sizeof(info
));
676 info
.cbSize
= sizeof(info
);
677 hr
= pGetCursorInfo(&info
);
678 ok(hr
!= 0, "GetCursorInfo returned %#08x\n", hr
);
679 ok(info
.flags
& CURSOR_SHOWING
, "The gdi cursor is hidden (%08x)\n", info
.flags
);
680 ok(info
.hCursor
== cur
, "The cursor handle is %p\n", info
.hCursor
); /* unchanged */
683 hr
= IDirect3DDevice8_ShowCursor(pDevice
, TRUE
);
684 ok(hr
== FALSE
, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr
);
687 hr
= IDirect3DDevice8_ShowCursor(pDevice
, TRUE
);
688 ok(hr
== TRUE
, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr
);
690 /* GDI cursor unchanged */
691 memset(&info
, 0, sizeof(info
));
692 info
.cbSize
= sizeof(info
);
693 hr
= pGetCursorInfo(&info
);
694 ok(hr
!= 0, "GetCursorInfo returned %#08x\n", hr
);
695 ok(info
.flags
& CURSOR_SHOWING
, "The gdi cursor is hidden (%08x)\n", info
.flags
);
696 ok(info
.hCursor
== cur
, "The cursor handle is %p\n", info
.hCursor
); /* unchanged */
699 if(pD3d
) IDirect3D8_Release(pD3d
);
700 if(pDevice
) IDirect3D8_Release(pDevice
);
703 static void test_states(void)
707 IDirect3D8
*pD3d
= NULL
;
708 IDirect3DDevice8
*pDevice
= NULL
;
709 D3DPRESENT_PARAMETERS d3dpp
;
710 D3DDISPLAYMODE d3ddm
;
712 pD3d
= pDirect3DCreate8( D3D_SDK_VERSION
);
713 ok(pD3d
!= NULL
, "Failed to create IDirect3D8 object\n");
714 hwnd
= CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
715 ok(hwnd
!= NULL
, "Failed to create window\n");
716 if (!pD3d
|| !hwnd
) goto cleanup
;
718 IDirect3D8_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
719 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
720 d3dpp
.Windowed
= TRUE
;
721 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
722 d3dpp
.BackBufferWidth
= 640;
723 d3dpp
.BackBufferHeight
= 480;
724 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
726 hr
= IDirect3D8_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
727 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
730 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr
);
734 hr
= IDirect3DDevice8_SetRenderState(pDevice
, D3DRS_ZVISIBLE
, TRUE
);
735 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, TRUE) returned %#08x\n", hr
);
736 hr
= IDirect3DDevice8_SetRenderState(pDevice
, D3DRS_ZVISIBLE
, FALSE
);
737 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, FALSE) returned %#08x\n", hr
);
740 if(pD3d
) IDirect3D8_Release(pD3d
);
741 if(pDevice
) IDirect3D8_Release(pDevice
);
744 static void test_shader_versions(void)
747 IDirect3D8
*pD3d
= NULL
;
750 pD3d
= pDirect3DCreate8( D3D_SDK_VERSION
);
751 ok(pD3d
!= NULL
, "Failed to create IDirect3D8 object\n");
753 hr
= IDirect3D8_GetDeviceCaps(pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, &d3dcaps
);
754 ok(SUCCEEDED(hr
) || hr
== D3DERR_NOTAVAILABLE
, "Failed to get D3D8 caps (%#08x)\n", hr
);
756 ok(d3dcaps
.VertexShaderVersion
<= D3DVS_VERSION(1,1), "Unexpected VertexShaderVersion (%#x > %#x)\n", d3dcaps
.VertexShaderVersion
, D3DVS_VERSION(1,1));
757 ok(d3dcaps
.PixelShaderVersion
<= D3DPS_VERSION(1,4), "Unexpected PixelShaderVersion (%#x > %#x)\n", d3dcaps
.PixelShaderVersion
, D3DPS_VERSION(1,4));
759 skip("No Direct3D support\n");
761 IDirect3D8_Release(pD3d
);
766 /* Test adapter display modes */
767 static void test_display_modes(void)
770 D3DDISPLAYMODE dmode
;
774 pD3d
= pDirect3DCreate8( D3D_SDK_VERSION
);
775 ok(pD3d
!= NULL
, "Failed to create IDirect3D8 object\n");
778 max_modes
= IDirect3D8_GetAdapterModeCount(pD3d
, D3DADAPTER_DEFAULT
);
779 ok(max_modes
> 0, "GetAdapterModeCount(D3DADAPTER_DEFAULT) returned 0!\n");
781 for(i
=0; i
<max_modes
;i
++) {
782 res
= IDirect3D8_EnumAdapterModes(pD3d
, D3DADAPTER_DEFAULT
, i
, &dmode
);
783 ok(res
==D3D_OK
, "EnumAdapterModes returned %#08x for mode %u!\n", res
, i
);
787 ok(dmode
.Format
==D3DFMT_X8R8G8B8
|| dmode
.Format
==D3DFMT_R5G6B5
,
788 "Unexpected display mode returned for mode %u: %#x\n", i
, dmode
.Format
);
791 IDirect3D8_Release(pD3d
);
794 static void test_scene(void)
798 IDirect3D8
*pD3d
= NULL
;
799 IDirect3DDevice8
*pDevice
= NULL
;
800 D3DPRESENT_PARAMETERS d3dpp
;
801 D3DDISPLAYMODE d3ddm
;
803 pD3d
= pDirect3DCreate8( D3D_SDK_VERSION
);
804 ok(pD3d
!= NULL
, "Failed to create IDirect3D8 object\n");
805 hwnd
= CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
806 ok(hwnd
!= NULL
, "Failed to create window\n");
807 if (!pD3d
|| !hwnd
) goto cleanup
;
809 IDirect3D8_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
810 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
811 d3dpp
.Windowed
= TRUE
;
812 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
813 d3dpp
.BackBufferWidth
= 800;
814 d3dpp
.BackBufferHeight
= 600;
815 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
818 hr
= IDirect3D8_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
819 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
820 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "IDirect3D8_CreateDevice failed with %#08x\n", hr
);
823 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr
);
827 /* Test an EndScene without beginscene. Should return an error */
828 hr
= IDirect3DDevice8_EndScene(pDevice
);
829 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
831 /* Test a normal BeginScene / EndScene pair, this should work */
832 hr
= IDirect3DDevice8_BeginScene(pDevice
);
833 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr
);
836 hr
= IDirect3DDevice8_EndScene(pDevice
);
837 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed with %#08x\n", hr
);
840 /* Test another EndScene without having begun a new scene. Should return an error */
841 hr
= IDirect3DDevice8_EndScene(pDevice
);
842 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
844 /* Two nested BeginScene and EndScene calls */
845 hr
= IDirect3DDevice8_BeginScene(pDevice
);
846 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr
);
847 hr
= IDirect3DDevice8_BeginScene(pDevice
);
848 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_BeginScene returned %#08x\n", hr
);
849 hr
= IDirect3DDevice8_EndScene(pDevice
);
850 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed with %#08x\n", hr
);
851 hr
= IDirect3DDevice8_EndScene(pDevice
);
852 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
854 /* StretchRect does not exit in Direct3D8, so no equivalent to the d3d9 stretchrect tests */
857 if(pD3d
) IDirect3D8_Release(pD3d
);
858 if(pDevice
) IDirect3D8_Release(pDevice
);
859 if(hwnd
) DestroyWindow(hwnd
);
862 static void test_shader(void)
866 IDirect3D8
*pD3d
= NULL
;
867 IDirect3DDevice8
*pDevice
= NULL
;
868 D3DPRESENT_PARAMETERS d3dpp
;
869 D3DDISPLAYMODE d3ddm
;
870 DWORD hPixelShader
= 0, hVertexShader
= 0;
871 DWORD hPixelShader2
= 0, hVertexShader2
= 0;
877 static DWORD dwVertexDecl
[] =
880 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
),
883 DWORD decl_normal_float2
[] =
886 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
887 D3DVSD_REG(D3DVSDE_NORMAL
, D3DVSDT_FLOAT2
), /* D3DVSDE_NORMAL, Register v1 */
890 DWORD decl_normal_float4
[] =
893 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
894 D3DVSD_REG(D3DVSDE_NORMAL
, D3DVSDT_FLOAT4
), /* D3DVSDE_NORMAL, Register v1 */
897 DWORD decl_normal_d3dcolor
[] =
900 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
901 D3DVSD_REG(D3DVSDE_NORMAL
, D3DVSDT_D3DCOLOR
),/* D3DVSDE_NORMAL, Register v1 */
904 const DWORD vertex_decl_size
= sizeof(dwVertexDecl
);
905 const DWORD simple_vs_size
= sizeof(simple_vs
);
906 const DWORD simple_ps_size
= sizeof(simple_ps
);
908 pD3d
= pDirect3DCreate8( D3D_SDK_VERSION
);
909 ok(pD3d
!= NULL
, "Failed to create IDirect3D8 object\n");
910 hwnd
= CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
911 ok(hwnd
!= NULL
, "Failed to create window\n");
912 if (!pD3d
|| !hwnd
) goto cleanup
;
914 IDirect3D8_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
915 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
916 d3dpp
.Windowed
= TRUE
;
917 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
918 d3dpp
.BackBufferWidth
= 800;
919 d3dpp
.BackBufferHeight
= 600;
920 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
923 hr
= IDirect3D8_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
924 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
925 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "IDirect3D8_CreateDevice failed with %#08x\n", hr
);
928 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr
);
931 IDirect3DDevice8_GetDeviceCaps(pDevice
, &caps
);
933 /* First create a vertex shader */
934 hr
= IDirect3DDevice8_CreateVertexShader(pDevice
, dwVertexDecl
, simple_vs
, &hVertexShader
, 0);
935 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
936 /* Msdn says that the new vertex shader is set immediately. This is wrong, apparently */
937 hr
= IDirect3DDevice8_GetVertexShader(pDevice
, &hTempHandle
);
938 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
939 ok(hTempHandle
== 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, 0);
940 /* Assign the shader, then verify that GetVertexShader works */
941 hr
= IDirect3DDevice8_SetVertexShader(pDevice
, hVertexShader
);
942 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
943 hr
= IDirect3DDevice8_GetVertexShader(pDevice
, &hTempHandle
);
944 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
945 ok(hTempHandle
== hVertexShader
, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, hVertexShader
);
946 /* Verify that we can retrieve the declaration */
947 hr
= IDirect3DDevice8_GetVertexShaderDeclaration(pDevice
, hVertexShader
, NULL
, &data_size
);
948 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr
);
949 ok(data_size
== vertex_decl_size
, "Got data_size %u, expected %u\n", data_size
, vertex_decl_size
);
950 data
= HeapAlloc(GetProcessHeap(), 0, vertex_decl_size
);
952 hr
= IDirect3DDevice8_GetVertexShaderDeclaration(pDevice
, hVertexShader
, data
, &data_size
);
953 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_GetVertexShaderDeclaration returned (%#08x), "
954 "expected D3DERR_INVALIDCALL\n", hr
);
955 ok(data_size
== 1, "Got data_size %u, expected 1\n", data_size
);
956 data_size
= vertex_decl_size
;
957 hr
= IDirect3DDevice8_GetVertexShaderDeclaration(pDevice
, hVertexShader
, data
, &data_size
);
958 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr
);
959 ok(data_size
== vertex_decl_size
, "Got data_size %u, expected %u\n", data_size
, vertex_decl_size
);
960 ok(!memcmp(data
, dwVertexDecl
, vertex_decl_size
), "data not equal to shader declaration\n");
961 HeapFree(GetProcessHeap(), 0, data
);
962 /* Verify that we can retrieve the shader function */
963 hr
= IDirect3DDevice8_GetVertexShaderFunction(pDevice
, hVertexShader
, NULL
, &data_size
);
964 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr
);
965 ok(data_size
== simple_vs_size
, "Got data_size %u, expected %u\n", data_size
, simple_vs_size
);
966 data
= HeapAlloc(GetProcessHeap(), 0, simple_vs_size
);
968 hr
= IDirect3DDevice8_GetVertexShaderFunction(pDevice
, hVertexShader
, data
, &data_size
);
969 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_GetVertexShaderFunction returned (%#08x), "
970 "expected D3DERR_INVALIDCALL\n", hr
);
971 ok(data_size
== 1, "Got data_size %u, expected 1\n", data_size
);
972 data_size
= simple_vs_size
;
973 hr
= IDirect3DDevice8_GetVertexShaderFunction(pDevice
, hVertexShader
, data
, &data_size
);
974 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr
);
975 ok(data_size
== simple_vs_size
, "Got data_size %u, expected %u\n", data_size
, simple_vs_size
);
976 ok(!memcmp(data
, simple_vs
, simple_vs_size
), "data not equal to shader function\n");
977 HeapFree(GetProcessHeap(), 0, data
);
978 /* Delete the assigned shader. This is supposed to work */
979 hr
= IDirect3DDevice8_DeleteVertexShader(pDevice
, hVertexShader
);
980 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
981 /* The shader should be unset now */
982 hr
= IDirect3DDevice8_GetVertexShader(pDevice
, &hTempHandle
);
983 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
984 ok(hTempHandle
== 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, 0);
986 /* Test a broken declaration. 3DMark2001 tries to use normals with 2 components
987 * First try the fixed function shader function, then a custom one
989 hr
= IDirect3DDevice8_CreateVertexShader(pDevice
, decl_normal_float2
, 0, &hVertexShader
, 0);
990 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
991 if(SUCCEEDED(hr
)) IDirect3DDevice8_DeleteVertexShader(pDevice
, hVertexShader
);
992 hr
= IDirect3DDevice8_CreateVertexShader(pDevice
, decl_normal_float4
, 0, &hVertexShader
, 0);
993 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
994 if(SUCCEEDED(hr
)) IDirect3DDevice8_DeleteVertexShader(pDevice
, hVertexShader
);
995 hr
= IDirect3DDevice8_CreateVertexShader(pDevice
, decl_normal_d3dcolor
, 0, &hVertexShader
, 0);
996 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
997 if(SUCCEEDED(hr
)) IDirect3DDevice8_DeleteVertexShader(pDevice
, hVertexShader
);
999 hr
= IDirect3DDevice8_CreateVertexShader(pDevice
, decl_normal_float2
, simple_vs
, &hVertexShader
, 0);
1000 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1001 if(SUCCEEDED(hr
)) IDirect3DDevice8_DeleteVertexShader(pDevice
, hVertexShader
);
1003 if (caps
.PixelShaderVersion
>= D3DPS_VERSION(1, 0))
1005 /* The same with a pixel shader */
1006 hr
= IDirect3DDevice8_CreatePixelShader(pDevice
, simple_ps
, &hPixelShader
);
1007 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
1008 /* Msdn says that the new pixel shader is set immediately. This is wrong, apparently */
1009 hr
= IDirect3DDevice8_GetPixelShader(pDevice
, &hTempHandle
);
1010 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
1011 ok(hTempHandle
== 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, 0);
1012 /* Assign the shader, then verify that GetPixelShader works */
1013 hr
= IDirect3DDevice8_SetPixelShader(pDevice
, hPixelShader
);
1014 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr
);
1015 hr
= IDirect3DDevice8_GetPixelShader(pDevice
, &hTempHandle
);
1016 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
1017 ok(hTempHandle
== hPixelShader
, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, hPixelShader
);
1018 /* Verify that we can retrieve the shader function */
1019 hr
= IDirect3DDevice8_GetPixelShaderFunction(pDevice
, hPixelShader
, NULL
, &data_size
);
1020 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr
);
1021 ok(data_size
== simple_ps_size
, "Got data_size %u, expected %u\n", data_size
, simple_ps_size
);
1022 data
= HeapAlloc(GetProcessHeap(), 0, simple_ps_size
);
1024 hr
= IDirect3DDevice8_GetPixelShaderFunction(pDevice
, hPixelShader
, data
, &data_size
);
1025 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_GetPixelShaderFunction returned (%#08x), "
1026 "expected D3DERR_INVALIDCALL\n", hr
);
1027 ok(data_size
== 1, "Got data_size %u, expected 1\n", data_size
);
1028 data_size
= simple_ps_size
;
1029 hr
= IDirect3DDevice8_GetPixelShaderFunction(pDevice
, hPixelShader
, data
, &data_size
);
1030 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr
);
1031 ok(data_size
== simple_ps_size
, "Got data_size %u, expected %u\n", data_size
, simple_ps_size
);
1032 ok(!memcmp(data
, simple_ps
, simple_ps_size
), "data not equal to shader function\n");
1033 HeapFree(GetProcessHeap(), 0, data
);
1034 /* Delete the assigned shader. This is supposed to work */
1035 hr
= IDirect3DDevice8_DeletePixelShader(pDevice
, hPixelShader
);
1036 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
1037 /* The shader should be unset now */
1038 hr
= IDirect3DDevice8_GetPixelShader(pDevice
, &hTempHandle
);
1039 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
1040 ok(hTempHandle
== 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, 0);
1042 /* What happens if a non-bound shader is deleted? */
1043 hr
= IDirect3DDevice8_CreatePixelShader(pDevice
, simple_ps
, &hPixelShader
);
1044 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
1045 hr
= IDirect3DDevice8_CreatePixelShader(pDevice
, simple_ps
, &hPixelShader2
);
1046 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
1048 hr
= IDirect3DDevice8_SetPixelShader(pDevice
, hPixelShader
);
1049 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr
);
1050 hr
= IDirect3DDevice8_DeletePixelShader(pDevice
, hPixelShader2
);
1051 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
1052 hr
= IDirect3DDevice8_GetPixelShader(pDevice
, &hTempHandle
);
1053 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
1054 ok(hTempHandle
== hPixelShader
, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, hPixelShader
);
1055 hr
= IDirect3DDevice8_DeletePixelShader(pDevice
, hPixelShader
);
1056 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
1060 skip("Pixel shaders not supported\n");
1063 /* What happens if a non-bound shader is deleted? */
1064 hr
= IDirect3DDevice8_CreateVertexShader(pDevice
, dwVertexDecl
, NULL
, &hVertexShader
, 0);
1065 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1066 hr
= IDirect3DDevice8_CreateVertexShader(pDevice
, dwVertexDecl
, NULL
, &hVertexShader2
, 0);
1067 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
1069 hr
= IDirect3DDevice8_SetVertexShader(pDevice
, hVertexShader
);
1070 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
1071 hr
= IDirect3DDevice8_DeleteVertexShader(pDevice
, hVertexShader2
);
1072 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
1073 hr
= IDirect3DDevice8_GetVertexShader(pDevice
, &hTempHandle
);
1074 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
1075 ok(hTempHandle
== hVertexShader
, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, hVertexShader
);
1076 hr
= IDirect3DDevice8_DeleteVertexShader(pDevice
, hVertexShader
);
1077 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
1080 if(pD3d
) IDirect3D8_Release(pD3d
);
1081 if(pDevice
) IDirect3D8_Release(pDevice
);
1082 if(hwnd
) DestroyWindow(hwnd
);
1085 static void test_limits(void)
1089 IDirect3D8
*pD3d
= NULL
;
1090 IDirect3DDevice8
*pDevice
= NULL
;
1091 D3DPRESENT_PARAMETERS d3dpp
;
1092 D3DDISPLAYMODE d3ddm
;
1093 IDirect3DTexture8
*pTexture
= NULL
;
1096 pD3d
= pDirect3DCreate8( D3D_SDK_VERSION
);
1097 ok(pD3d
!= NULL
, "Failed to create IDirect3D8 object\n");
1098 hwnd
= CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1099 ok(hwnd
!= NULL
, "Failed to create window\n");
1100 if (!pD3d
|| !hwnd
) goto cleanup
;
1102 IDirect3D8_GetAdapterDisplayMode( pD3d
, D3DADAPTER_DEFAULT
, &d3ddm
);
1103 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1104 d3dpp
.Windowed
= TRUE
;
1105 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1106 d3dpp
.BackBufferWidth
= 800;
1107 d3dpp
.BackBufferHeight
= 600;
1108 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1109 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1110 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
1112 hr
= IDirect3D8_CreateDevice( pD3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1113 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &pDevice
);
1114 ok(hr
== D3D_OK
|| hr
== D3DERR_INVALIDCALL
, "IDirect3D8_CreateDevice failed with %#08x\n", hr
);
1117 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr
);
1121 hr
= IDirect3DDevice8_CreateTexture(pDevice
, 16, 16, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &pTexture
);
1122 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateTexture failed with %#08x\n", hr
);
1123 if(!pTexture
) goto cleanup
;
1125 /* There are 8 texture stages. We should be able to access all of them */
1126 for(i
= 0; i
< 8; i
++) {
1127 hr
= IDirect3DDevice8_SetTexture(pDevice
, i
, (IDirect3DBaseTexture8
*) pTexture
);
1128 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i
, hr
);
1129 hr
= IDirect3DDevice8_SetTexture(pDevice
, i
, NULL
);
1130 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i
, hr
);
1131 hr
= IDirect3DDevice8_SetTextureStageState(pDevice
, i
, D3DTSS_COLOROP
, D3DTOP_ADD
);
1132 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %#08x\n", i
, hr
);
1135 /* Investigations show that accessing higher textures stage states does not return an error either. Writing
1136 * to too high texture stages(approximately texture 40) causes memory corruption in windows, so there is no
1137 * bounds checking but how do I test that?
1141 if(pTexture
) IDirect3DTexture8_Release(pTexture
);
1142 if(pD3d
) IDirect3D8_Release(pD3d
);
1143 if(pDevice
) IDirect3D8_Release(pDevice
);
1144 if(hwnd
) DestroyWindow(hwnd
);
1147 static void test_lights(void)
1149 D3DPRESENT_PARAMETERS d3dpp
;
1150 IDirect3DDevice8
*device
= NULL
;
1157 D3DDISPLAYMODE d3ddm
;
1159 d3d8
= pDirect3DCreate8( D3D_SDK_VERSION
);
1160 ok(d3d8
!= NULL
, "Failed to create IDirect3D8 object\n");
1161 hwnd
= CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1162 ok(hwnd
!= NULL
, "Failed to create window\n");
1163 if (!d3d8
|| !hwnd
) goto cleanup
;
1165 IDirect3D8_GetAdapterDisplayMode( d3d8
, D3DADAPTER_DEFAULT
, &d3ddm
);
1166 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1167 d3dpp
.Windowed
= TRUE
;
1168 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1169 d3dpp
.BackBufferWidth
= 800;
1170 d3dpp
.BackBufferHeight
= 600;
1171 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1172 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1173 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
1175 hr
= IDirect3D8_CreateDevice( d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1176 D3DCREATE_HARDWARE_VERTEXPROCESSING
| D3DCREATE_PUREDEVICE
, &d3dpp
, &device
);
1177 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
|| hr
== D3DERR_INVALIDCALL
,
1178 "IDirect3D8_CreateDevice failed with %s\n", DXGetErrorString8(hr
));
1181 skip("Failed to create a d3d device\n");
1185 memset(&caps
, 0, sizeof(caps
));
1186 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
1187 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetDeviceCaps failed with %s\n", DXGetErrorString8(hr
));
1189 for(i
= 1; i
<= caps
.MaxActiveLights
; i
++) {
1190 hr
= IDirect3DDevice8_LightEnable(device
, i
, TRUE
);
1191 ok(hr
== D3D_OK
, "Enabling light %u failed with %s\n", i
, DXGetErrorString8(hr
));
1192 hr
= IDirect3DDevice8_GetLightEnable(device
, i
, &enabled
);
1193 ok(hr
== D3D_OK
, "GetLightEnable on light %u failed with %s\n", i
, DXGetErrorString8(hr
));
1194 ok(enabled
, "Light %d is %s\n", i
, enabled
? "enabled" : "disabled");
1197 /* TODO: Test the rendering results in this situation */
1198 hr
= IDirect3DDevice8_LightEnable(device
, i
+ 1, TRUE
);
1199 ok(hr
== D3D_OK
, "Enabling one light more than supported returned %s\n", DXGetErrorString8(hr
));
1200 hr
= IDirect3DDevice8_GetLightEnable(device
, i
+ 1, &enabled
);
1201 ok(hr
== D3D_OK
, "GetLightEnable on light %u failed with %s\n", i
+ 1, DXGetErrorString8(hr
));
1202 ok(enabled
, "Light %d is %s\n", i
+ 1, enabled
? "enabled" : "disabled");
1203 hr
= IDirect3DDevice8_LightEnable(device
, i
+ 1, FALSE
);
1204 ok(hr
== D3D_OK
, "Disabling the additional returned %s\n", DXGetErrorString8(hr
));
1206 for(i
= 1; i
<= caps
.MaxActiveLights
; i
++) {
1207 hr
= IDirect3DDevice8_LightEnable(device
, i
, FALSE
);
1208 ok(hr
== D3D_OK
, "Disabling light %u failed with %s\n", i
, DXGetErrorString8(hr
));
1212 if(device
) IDirect3DDevice8_Release(device
);
1213 if(d3d8
) IDirect3D8_Release(d3d8
);
1216 static void test_render_zero_triangles(void)
1218 D3DPRESENT_PARAMETERS d3dpp
;
1219 IDirect3DDevice8
*device
= NULL
;
1223 D3DDISPLAYMODE d3ddm
;
1232 { 0.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
1233 { 0.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
1234 { 1.0f
, 0.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
1235 { 1.0f
, -1.0f
, 0.1f
, 1.0f
, 1.0f
, 1.0f
, 0xff0000ff},
1238 d3d8
= pDirect3DCreate8( D3D_SDK_VERSION
);
1239 ok(d3d8
!= NULL
, "Failed to create IDirect3D8 object\n");
1240 hwnd
= CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1241 ok(hwnd
!= NULL
, "Failed to create window\n");
1242 if (!d3d8
|| !hwnd
) goto cleanup
;
1244 IDirect3D8_GetAdapterDisplayMode( d3d8
, D3DADAPTER_DEFAULT
, &d3ddm
);
1245 ZeroMemory( &d3dpp
, sizeof(d3dpp
) );
1246 d3dpp
.Windowed
= TRUE
;
1247 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1248 d3dpp
.BackBufferWidth
= 800;
1249 d3dpp
.BackBufferHeight
= 600;
1250 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1251 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1252 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
1254 hr
= IDirect3D8_CreateDevice( d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
/* no NULLREF here */, hwnd
,
1255 D3DCREATE_HARDWARE_VERTEXPROCESSING
| D3DCREATE_PUREDEVICE
, &d3dpp
, &device
);
1256 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
|| hr
== D3DERR_INVALIDCALL
,
1257 "IDirect3D8_CreateDevice failed with %s\n", DXGetErrorString8(hr
));
1260 skip("Failed to create a d3d device\n");
1264 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
1265 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
1267 hr
= IDirect3DDevice8_BeginScene(device
);
1268 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr
);
1271 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 0 /* NumVerts */,
1272 0 /*PrimCount */, NULL
, D3DFMT_INDEX16
, quad
, sizeof(quad
[0]));
1273 ok(hr
== D3D_OK
, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr
);
1275 IDirect3DDevice8_EndScene(device
);
1276 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed with %#08x\n", hr
);
1279 IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
1282 if(device
) IDirect3DDevice8_Release(device
);
1283 if(d3d8
) IDirect3D8_Release(d3d8
);
1286 static void test_set_material(void)
1288 D3DPRESENT_PARAMETERS present_parameters
;
1289 IDirect3DDevice8
*device
= NULL
;
1294 d3d8
= pDirect3DCreate8( D3D_SDK_VERSION
);
1295 ok(d3d8
!= NULL
, "Failed to create IDirect3D8 object\n");
1296 hwnd
= CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW
, 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1297 ok(hwnd
!= NULL
, "Failed to create window\n");
1298 if (!d3d8
|| !hwnd
) goto cleanup
;
1300 ZeroMemory(&present_parameters
, sizeof(present_parameters
));
1301 present_parameters
.Windowed
= TRUE
;
1302 present_parameters
.hDeviceWindow
= hwnd
;
1303 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1305 hr
= IDirect3D8_CreateDevice( d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
1306 D3DCREATE_HARDWARE_VERTEXPROCESSING
| D3DCREATE_PUREDEVICE
, &present_parameters
, &device
);
1307 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
|| hr
== D3DERR_INVALIDCALL
,
1308 "IDirect3D8_CreateDevice failed with %s\n", DXGetErrorString8(hr
));
1311 skip("Failed to create a d3d device\n");
1315 hr
= IDirect3DDevice8_SetMaterial(device
, NULL
);
1316 ok(hr
== D3DERR_INVALIDCALL
, "Expected D3DERR_INVALIDCALL, got %s\n", DXGetErrorString8(hr
));
1319 if(device
) IDirect3DDevice8_Release(device
);
1320 if(d3d8
) IDirect3D8_Release(d3d8
);
1325 HMODULE d3d8_handle
= LoadLibraryA( "d3d8.dll" );
1328 skip("Could not load d3d8.dll\n");
1332 pDirect3DCreate8
= (void *)GetProcAddress( d3d8_handle
, "Direct3DCreate8" );
1333 ok(pDirect3DCreate8
!= NULL
, "Failed to get address of Direct3DCreate8\n");
1334 if (pDirect3DCreate8
)
1336 test_display_modes();
1337 test_shader_versions();
1340 test_mipmap_levels();
1347 test_render_zero_triangles();
1348 test_set_material();