push e1d8a1293d44015bb0894687d02c5c53339996f7
[wine/hacks.git] / dlls / d3d8 / tests / device.c
blobf039a1b102faeb7f0e0372943912a470f63a2860
1 /*
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
20 #define COBJMACROS
21 #include <initguid.h>
22 #include <d3d8.h>
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) \
50 if (SUCCEEDED(r)) {\
51 int tmp1 = get_refcount( (IUnknown *)d ); \
52 int rc_new = rc; \
53 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
54 } else {\
55 trace("%s failed: %#08x\n", c, r); \
58 #define CHECK_RELEASE(obj,d,rc) \
59 if (obj) { \
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) \
67 { \
68 int rc_new = 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) \
74 { \
75 int rc_new = 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) \
81 { \
82 int rc_new = 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) \
88 { \
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 );
102 if (SUCCEEDED(hr)) {
103 DWORD levels = IDirect3DBaseTexture8_GetLevelCount(texture);
104 ok(levels == count, "Invalid level count. Expected %d got %u\n", count, levels);
105 } else
106 trace("CreateTexture failed: %#08x\n", hr);
108 if (texture) IUnknown_Release( texture );
111 static void test_mipmap_levels(void)
114 HRESULT hr;
115 HWND hwnd = NULL;
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 );
136 if(FAILED(hr))
138 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
139 goto cleanup;
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);
147 cleanup:
148 if (pD3d) IUnknown_Release( pD3d );
149 if (pDevice) IUnknown_Release( pDevice );
150 DestroyWindow( hwnd );
153 static void test_swapchain(void)
155 HRESULT hr;
156 HWND hwnd = NULL;
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 );
181 if(FAILED(hr))
183 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
184 goto cleanup;
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);
203 if(SUCCEEDED(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);
262 cleanup:
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)
273 HRESULT hr;
274 HWND hwnd = NULL;
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;
294 D3DCAPS8 caps;
296 D3DPRESENT_PARAMETERS d3dpp;
297 D3DDISPLAYMODE d3ddm;
298 int refcount = 0, tmp;
300 DWORD decl[] =
302 D3DVSD_STREAM(0),
303 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
304 D3DVSD_REG(D3DVSDE_DIFFUSE, D3DVSDT_D3DCOLOR), /* D3DVSDE_DIFFUSE, Register v5 */
305 D3DVSD_END()
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 );
324 if(FAILED(hr))
326 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
327 goto cleanup;
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);
344 if(pRenderTarget)
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);
371 if(pBackBuffer)
373 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
374 ok(pRenderTarget == pBackBuffer, "RenderTarget=%p and BackBuffer=%p should be the same.\n",
375 pRenderTarget, pBackBuffer);
376 pBackBuffer = NULL;
378 CHECK_REFCOUNT( pDevice, --refcount);
380 hr = IDirect3DDevice8_GetDepthStencilSurface(pDevice, &pStencilSurface);
381 CHECK_CALL( hr, "GetDepthStencilSurface", pDevice, ++refcount);
382 if(pStencilSurface)
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;
403 /* Buffers */
404 hr = IDirect3DDevice8_CreateIndexBuffer( pDevice, 16, 0, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &pIndexBuffer );
405 CHECK_CALL( hr, "CreateIndexBuffer", pDevice, ++refcount );
406 if(pIndexBuffer)
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 );
418 if(pVertexBuffer)
420 IDirect3DVertexBuffer8 *pVBuf = (void*)~0;
421 UINT stride = ~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);
436 /* Shaders */
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 );
444 /* Textures */
445 hr = IDirect3DDevice8_CreateTexture( pDevice, 32, 32, 3, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pTexture );
446 CHECK_CALL( hr, "CreateTexture", pDevice, ++refcount );
447 if (pTexture)
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 */
463 if (pTextureLevel)
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 );
479 else
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 );
488 else
490 skip("Volume textures not supported\n");
493 if (pVolumeTexture)
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 */
503 if (pVolumeLevel)
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 );
514 /* Surfaces */
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);
524 /* Misc */
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 );
529 if(pSwapChain)
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);
535 if(pBackBuffer)
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);
547 pBackBuffer = NULL;
549 CHECK_REFCOUNT( pSwapChain, 1);
552 if(pVertexBuffer)
554 BYTE *data;
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);
570 if(pRenderTarget2)
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;
580 cleanup:
581 CHECK_RELEASE(pDevice, pDevice, --refcount);
583 /* Buffers */
584 CHECK_RELEASE(pVertexBuffer, pDevice, --refcount);
585 CHECK_RELEASE(pIndexBuffer, pDevice, --refcount);
586 /* Shaders */
587 if (dVertexShader != ~0U) IDirect3DDevice8_DeleteVertexShader( pDevice, dVertexShader );
588 if (dPixelShader != ~0U) IDirect3DDevice8_DeletePixelShader( pDevice, dPixelShader );
589 /* Textures */
590 CHECK_RELEASE(pTexture, pDevice, --refcount);
591 CHECK_RELEASE(pCubeTexture, pDevice, --refcount);
592 CHECK_RELEASE(pVolumeTexture, pDevice, --refcount);
593 /* Surfaces */
594 CHECK_RELEASE(pStencilSurface, pDevice, --refcount);
595 CHECK_RELEASE(pImageSurface, pDevice, --refcount);
596 CHECK_RELEASE(pRenderTarget3, pDevice, --refcount);
597 /* Misc */
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)
609 HRESULT hr;
610 HWND hwnd = NULL;
611 IDirect3D8 *pD3d = NULL;
612 IDirect3DDevice8 *pDevice = NULL;
613 D3DPRESENT_PARAMETERS d3dpp;
614 D3DDISPLAYMODE d3ddm;
615 CURSORINFO info;
616 IDirect3DSurface8 *cursor = NULL;
617 HCURSOR cur;
618 HMODULE user32_handle = GetModuleHandleA("user32.dll");
620 pGetCursorInfo = (void *)GetProcAddress(user32_handle, "GetCursorInfo");
621 if (!pGetCursorInfo)
623 win_skip("GetCursorInfo is not available\n");
624 return;
627 memset(&info, 0, sizeof(info));
628 info.cbSize = sizeof(info);
629 ok(pGetCursorInfo(&info), "GetCursorInfo failed\n");
630 cur = info.hCursor;
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 );
646 if(FAILED(hr))
648 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
649 goto cleanup;
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);
663 /* Fails */
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 */
678 /* Still hidden */
679 hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
680 ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
682 /* Enabled now*/
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 */
693 cleanup:
694 if(pD3d) IDirect3D8_Release(pD3d);
695 if(pDevice) IDirect3D8_Release(pDevice);
698 static void test_states(void)
700 HRESULT hr;
701 HWND hwnd = NULL;
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 );
723 if(FAILED(hr))
725 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
726 goto cleanup;
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);
734 cleanup:
735 if(pD3d) IDirect3D8_Release(pD3d);
736 if(pDevice) IDirect3D8_Release(pDevice);
739 static void test_shader_versions(void)
741 HRESULT hr;
742 IDirect3D8 *pD3d = NULL;
743 D3DCAPS8 d3dcaps;
745 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
746 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
747 if (pD3d != NULL) {
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);
750 if (SUCCEEDED(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));
753 } else {
754 skip("No Direct3D support\n");
756 IDirect3D8_Release(pD3d);
761 /* Test adapter display modes */
762 static void test_display_modes(void)
764 UINT max_modes, i;
765 D3DDISPLAYMODE dmode;
766 HRESULT res;
767 IDirect3D8 *pD3d;
769 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
770 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
771 if(!pD3d) return;
773 max_modes = IDirect3D8_GetAdapterModeCount(pD3d, D3DADAPTER_DEFAULT);
774 ok(max_modes > 0 ||
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);
781 if(res != D3D_OK)
782 continue;
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)
793 HRESULT hr;
794 HWND hwnd = NULL;
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);
818 if(!pDevice)
820 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
821 goto cleanup;
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);
831 if(SUCCEEDED(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 */
853 cleanup:
854 if(pD3d) IDirect3D8_Release(pD3d);
855 if(pDevice) IDirect3D8_Release(pDevice);
856 if(hwnd) DestroyWindow(hwnd);
859 static void test_shader(void)
861 HRESULT hr;
862 HWND hwnd = NULL;
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;
869 DWORD hTempHandle;
870 D3DCAPS8 caps;
871 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
872 DWORD data_size;
873 void *data;
875 static DWORD dwVertexDecl[] =
877 D3DVSD_STREAM(0),
878 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3),
879 D3DVSD_END()
881 DWORD decl_normal_float2[] =
883 D3DVSD_STREAM(0),
884 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
885 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT2), /* D3DVSDE_NORMAL, Register v1 */
886 D3DVSD_END()
888 DWORD decl_normal_float4[] =
890 D3DVSD_STREAM(0),
891 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
892 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT4), /* D3DVSDE_NORMAL, Register v1 */
893 D3DVSD_END()
895 DWORD decl_normal_d3dcolor[] =
897 D3DVSD_STREAM(0),
898 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
899 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_D3DCOLOR),/* D3DVSDE_NORMAL, Register v1 */
900 D3DVSD_END()
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);
924 if(!pDevice)
926 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
927 goto cleanup;
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);
958 data_size = 1;
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);
974 data_size = 1;
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);
1030 data_size = 1;
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);
1065 /* Check for double delete. */
1066 hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader2);
1067 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1068 hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader);
1069 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1071 else
1073 skip("Pixel shaders not supported\n");
1076 /* What happens if a non-bound shader is deleted? */
1077 hr = IDirect3DDevice8_CreateVertexShader(pDevice, dwVertexDecl, NULL, &hVertexShader, 0);
1078 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1079 hr = IDirect3DDevice8_CreateVertexShader(pDevice, dwVertexDecl, NULL, &hVertexShader2, 0);
1080 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1082 hr = IDirect3DDevice8_SetVertexShader(pDevice, hVertexShader);
1083 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1084 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader2);
1085 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1086 hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
1087 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1088 ok(hTempHandle == hVertexShader, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, hVertexShader);
1089 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1090 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1092 /* Check for double delete. */
1093 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader2);
1094 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1095 hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1096 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1098 cleanup:
1099 if(pD3d) IDirect3D8_Release(pD3d);
1100 if(pDevice) IDirect3D8_Release(pDevice);
1101 if(hwnd) DestroyWindow(hwnd);
1104 static void test_limits(void)
1106 HRESULT hr;
1107 HWND hwnd = NULL;
1108 IDirect3D8 *pD3d = NULL;
1109 IDirect3DDevice8 *pDevice = NULL;
1110 D3DPRESENT_PARAMETERS d3dpp;
1111 D3DDISPLAYMODE d3ddm;
1112 IDirect3DTexture8 *pTexture = NULL;
1113 int i;
1115 pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
1116 ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
1117 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1118 ok(hwnd != NULL, "Failed to create window\n");
1119 if (!pD3d || !hwnd) goto cleanup;
1121 IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
1122 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1123 d3dpp.Windowed = TRUE;
1124 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1125 d3dpp.BackBufferWidth = 800;
1126 d3dpp.BackBufferHeight = 600;
1127 d3dpp.BackBufferFormat = d3ddm.Format;
1128 d3dpp.EnableAutoDepthStencil = TRUE;
1129 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
1131 hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1132 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
1133 ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL || broken(hr == D3DERR_NOTAVAILABLE), "IDirect3D8_CreateDevice failed with %#08x\n", hr);
1134 if(!pDevice)
1136 skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
1137 goto cleanup;
1140 hr = IDirect3DDevice8_CreateTexture(pDevice, 16, 16, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pTexture);
1141 ok(hr == D3D_OK, "IDirect3DDevice8_CreateTexture failed with %#08x\n", hr);
1142 if(!pTexture) goto cleanup;
1144 /* There are 8 texture stages. We should be able to access all of them */
1145 for(i = 0; i < 8; i++) {
1146 hr = IDirect3DDevice8_SetTexture(pDevice, i, (IDirect3DBaseTexture8 *) pTexture);
1147 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i, hr);
1148 hr = IDirect3DDevice8_SetTexture(pDevice, i, NULL);
1149 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i, hr);
1150 hr = IDirect3DDevice8_SetTextureStageState(pDevice, i, D3DTSS_COLOROP, D3DTOP_ADD);
1151 ok(hr == D3D_OK, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %#08x\n", i, hr);
1154 /* Investigations show that accessing higher textures stage states does not return an error either. Writing
1155 * to too high texture stages(approximately texture 40) causes memory corruption in windows, so there is no
1156 * bounds checking but how do I test that?
1159 cleanup:
1160 if(pTexture) IDirect3DTexture8_Release(pTexture);
1161 if(pD3d) IDirect3D8_Release(pD3d);
1162 if(pDevice) IDirect3D8_Release(pDevice);
1163 if(hwnd) DestroyWindow(hwnd);
1166 static void test_lights(void)
1168 D3DPRESENT_PARAMETERS d3dpp;
1169 IDirect3DDevice8 *device = NULL;
1170 IDirect3D8 *d3d8;
1171 HWND hwnd;
1172 HRESULT hr;
1173 unsigned int i;
1174 BOOL enabled;
1175 D3DCAPS8 caps;
1176 D3DDISPLAYMODE d3ddm;
1178 d3d8 = pDirect3DCreate8( D3D_SDK_VERSION );
1179 ok(d3d8 != NULL, "Failed to create IDirect3D8 object\n");
1180 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1181 ok(hwnd != NULL, "Failed to create window\n");
1182 if (!d3d8 || !hwnd) goto cleanup;
1184 IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &d3ddm );
1185 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1186 d3dpp.Windowed = TRUE;
1187 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1188 d3dpp.BackBufferWidth = 800;
1189 d3dpp.BackBufferHeight = 600;
1190 d3dpp.BackBufferFormat = d3ddm.Format;
1191 d3dpp.EnableAutoDepthStencil = TRUE;
1192 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
1194 hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1195 D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &d3dpp, &device );
1196 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE || hr == D3DERR_INVALIDCALL,
1197 "IDirect3D8_CreateDevice failed with %08x\n", hr);
1198 if(!device)
1200 skip("Failed to create a d3d device\n");
1201 goto cleanup;
1204 memset(&caps, 0, sizeof(caps));
1205 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
1206 ok(hr == D3D_OK, "IDirect3DDevice8_GetDeviceCaps failed with %08x\n", hr);
1208 for(i = 1; i <= caps.MaxActiveLights; i++) {
1209 hr = IDirect3DDevice8_LightEnable(device, i, TRUE);
1210 ok(hr == D3D_OK, "Enabling light %u failed with %08x\n", i, hr);
1211 hr = IDirect3DDevice8_GetLightEnable(device, i, &enabled);
1212 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL),
1213 "GetLightEnable on light %u failed with %08x\n", i, hr);
1214 ok(enabled, "Light %d is %s\n", i, enabled ? "enabled" : "disabled");
1217 /* TODO: Test the rendering results in this situation */
1218 hr = IDirect3DDevice8_LightEnable(device, i + 1, TRUE);
1219 ok(hr == D3D_OK ||
1220 broken(hr == D3DERR_INVALIDCALL), /* Some Win9x and WinME */
1221 "Enabling one light more than supported returned %08x\n", hr);
1222 hr = IDirect3DDevice8_GetLightEnable(device, i + 1, &enabled);
1223 ok(hr == D3D_OK, "GetLightEnable on light %u failed with %08x\n", i + 1, hr);
1224 ok(enabled, "Light %d is %s\n", i + 1, enabled ? "enabled" : "disabled");
1225 hr = IDirect3DDevice8_LightEnable(device, i + 1, FALSE);
1226 ok(hr == D3D_OK, "Disabling the additional returned %08x\n", hr);
1228 for(i = 1; i <= caps.MaxActiveLights; i++) {
1229 hr = IDirect3DDevice8_LightEnable(device, i, FALSE);
1230 ok(hr == D3D_OK, "Disabling light %u failed with %08x\n", i, hr);
1233 cleanup:
1234 if(device) IDirect3DDevice8_Release(device);
1235 if(d3d8) IDirect3D8_Release(d3d8);
1238 static void test_render_zero_triangles(void)
1240 D3DPRESENT_PARAMETERS d3dpp;
1241 IDirect3DDevice8 *device = NULL;
1242 IDirect3D8 *d3d8;
1243 HWND hwnd;
1244 HRESULT hr;
1245 D3DDISPLAYMODE d3ddm;
1247 struct nvertex
1249 float x, y, z;
1250 float nx, ny, nz;
1251 DWORD diffuse;
1252 } quad[] =
1254 { 0.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
1255 { 0.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
1256 { 1.0f, 0.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
1257 { 1.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff},
1260 d3d8 = pDirect3DCreate8( D3D_SDK_VERSION );
1261 ok(d3d8 != NULL, "Failed to create IDirect3D8 object\n");
1262 hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1263 ok(hwnd != NULL, "Failed to create window\n");
1264 if (!d3d8 || !hwnd) goto cleanup;
1266 IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &d3ddm );
1267 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1268 d3dpp.Windowed = TRUE;
1269 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1270 d3dpp.BackBufferWidth = 800;
1271 d3dpp.BackBufferHeight = 600;
1272 d3dpp.BackBufferFormat = d3ddm.Format;
1273 d3dpp.EnableAutoDepthStencil = TRUE;
1274 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
1276 hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1277 D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &d3dpp, &device );
1278 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE || hr == D3DERR_INVALIDCALL,
1279 "IDirect3D8_CreateDevice failed with %08x\n", hr);
1280 if(!device)
1282 skip("Failed to create a d3d device\n");
1283 goto cleanup;
1286 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
1287 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1289 hr = IDirect3DDevice8_BeginScene(device);
1290 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
1291 if(hr == D3D_OK)
1293 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 0 /* NumVerts */,
1294 0 /*PrimCount */, NULL, D3DFMT_INDEX16, quad, sizeof(quad[0]));
1295 ok(hr == D3D_OK, "IDirect3DDevice8_DrawIndexedPrimitiveUP failed with %#08x\n", hr);
1297 IDirect3DDevice8_EndScene(device);
1298 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
1301 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
1303 cleanup:
1304 if(device) IDirect3DDevice8_Release(device);
1305 if(d3d8) IDirect3D8_Release(d3d8);
1308 static void test_depth_stencil_reset(void)
1310 D3DPRESENT_PARAMETERS present_parameters;
1311 D3DDISPLAYMODE display_mode;
1312 IDirect3DSurface8 *surface;
1313 IDirect3DDevice8 *device = NULL;
1314 IDirect3D8 *d3d8;
1315 HRESULT hr;
1316 HWND hwnd;
1318 d3d8 = pDirect3DCreate8(D3D_SDK_VERSION);
1319 ok(d3d8 != NULL, "Failed to create IDirect3D8 object\n");
1320 hwnd = CreateWindow("static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL);
1321 ok(hwnd != NULL, "Failed to create window\n");
1322 if (!d3d8 || !hwnd) goto cleanup;
1324 IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &display_mode);
1325 memset(&present_parameters, 0, sizeof(present_parameters));
1326 present_parameters.Windowed = TRUE;
1327 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
1328 present_parameters.BackBufferFormat = display_mode.Format;
1329 present_parameters.EnableAutoDepthStencil = TRUE;
1330 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
1332 hr = IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
1333 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
1334 if(FAILED(hr))
1336 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr);
1337 goto cleanup;
1340 hr = IDirect3DDevice8_TestCooperativeLevel(device);
1341 ok(SUCCEEDED(hr), "TestCooperativeLevel failed with %#x\n", hr);
1343 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, NULL);
1344 ok(hr == D3D_OK, "SetRenderTarget failed with 0x%08x\n", hr);
1346 hr = IDirect3DDevice8_GetRenderTarget(device, &surface);
1347 ok(hr == D3D_OK, "GetRenderTarget failed with 0x%08x\n", hr);
1348 ok(surface != NULL, "Render target should not be NULL\n");
1349 if (surface) IDirect3DSurface8_Release(surface);
1351 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
1352 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr);
1353 ok(surface == NULL, "Depth stencil should be NULL\n");
1355 present_parameters.EnableAutoDepthStencil = TRUE;
1356 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
1357 hr = IDirect3DDevice8_Reset(device, &present_parameters);
1358 ok(hr == D3D_OK, "Reset failed with 0x%08x\n", hr);
1360 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
1361 ok(hr == D3D_OK, "GetDepthStencilSurface failed with 0x%08x\n", hr);
1362 ok(surface != NULL, "Depth stencil should not be NULL\n");
1363 if (surface) IDirect3DSurface8_Release(surface);
1365 present_parameters.EnableAutoDepthStencil = FALSE;
1366 hr = IDirect3DDevice8_Reset(device, &present_parameters);
1367 ok(hr == D3D_OK, "Reset failed with 0x%08x\n", hr);
1369 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
1370 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr);
1371 ok(surface == NULL, "Depth stencil should be NULL\n");
1373 device = NULL;
1374 IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &display_mode );
1376 ZeroMemory( &present_parameters, sizeof(present_parameters) );
1377 present_parameters.Windowed = TRUE;
1378 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
1379 present_parameters.BackBufferFormat = display_mode.Format;
1380 present_parameters.EnableAutoDepthStencil = FALSE;
1381 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
1383 hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
1384 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device );
1386 if(FAILED(hr))
1388 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr);
1389 goto cleanup;
1392 hr = IDirect3DDevice8_TestCooperativeLevel(device);
1393 ok(hr == D3D_OK, "IDirect3DDevice8_TestCooperativeLevel after creation returned %#x\n", hr);
1395 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
1396 present_parameters.Windowed = TRUE;
1397 present_parameters.BackBufferWidth = 400;
1398 present_parameters.BackBufferHeight = 300;
1399 present_parameters.EnableAutoDepthStencil = TRUE;
1400 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
1402 hr = IDirect3DDevice8_Reset(device, &present_parameters);
1403 ok(hr == D3D_OK, "IDirect3DDevice8_Reset failed with 0x%08x\n", hr);
1405 if (FAILED(hr)) goto cleanup;
1407 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
1408 ok(hr == D3D_OK, "GetDepthStencilSurface failed with 0x%08x\n", hr);
1409 ok(surface != NULL, "Depth stencil should not be NULL\n");
1410 if (surface) IDirect3DSurface8_Release(surface);
1412 cleanup:
1413 if(d3d8) IDirect3D8_Release(d3d8);
1414 if(device) IDirect3D8_Release(device);
1417 START_TEST(device)
1419 HMODULE d3d8_handle = LoadLibraryA( "d3d8.dll" );
1420 if (!d3d8_handle)
1422 skip("Could not load d3d8.dll\n");
1423 return;
1426 pDirect3DCreate8 = (void *)GetProcAddress( d3d8_handle, "Direct3DCreate8" );
1427 ok(pDirect3DCreate8 != NULL, "Failed to get address of Direct3DCreate8\n");
1428 if (pDirect3DCreate8)
1430 IDirect3D8 *d3d8;
1431 d3d8 = pDirect3DCreate8( D3D_SDK_VERSION );
1432 if(!d3d8)
1434 skip("could not create D3D8\n");
1435 return;
1437 IDirect3D8_Release(d3d8);
1439 test_display_modes();
1440 test_shader_versions();
1441 test_swapchain();
1442 test_refcount();
1443 test_mipmap_levels();
1444 test_cursor();
1445 test_states();
1446 test_scene();
1447 test_shader();
1448 test_limits();
1449 test_lights();
1450 test_render_zero_triangles();
1451 test_depth_stencil_reset();