gdiplus: Tests for GdipLockBitmapBits/GdipUnlockBitmapBits.
[wine] / dlls / d3d8 / tests / device.c
1 /*
2  * Copyright (C) 2006 Vitaliy Margolen
3  * Copyright (C) 2006 Chris Robinson
4  *
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.
9  *
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.
14  *
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
18  */
19
20 #define COBJMACROS
21 #include <d3d8.h>
22 #include <dxerr8.h>
23 #include "wine/test.h"
24
25 static IDirect3D8 *(WINAPI *pDirect3DCreate8)(UINT);
26
27 static BOOL (WINAPI *pGetCursorInfo)(PCURSORINFO);
28
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                          */
42
43 static int get_refcount(IUnknown *object)
44 {
45     IUnknown_AddRef( object );
46     return IUnknown_Release( object );
47 }
48
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); \
56     }
57
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); \
64     }
65
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); \
71     }
72
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); \
78     }
79
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); \
85     }
86
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); \
94     }
95
96 static void check_mipmap_levels(
97     IDirect3DDevice8* device, 
98     int width, int height, int count) 
99 {
100
101     IDirect3DBaseTexture8* texture = NULL;
102     HRESULT hr = IDirect3DDevice8_CreateTexture( device, width, height, 0, 0, 
103         D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, (IDirect3DTexture8**) &texture );
104        
105     if (SUCCEEDED(hr)) {
106         DWORD levels = IDirect3DBaseTexture8_GetLevelCount(texture);
107         ok(levels == count, "Invalid level count. Expected %d got %u\n", count, levels);
108     } else 
109         trace("CreateTexture failed: %#08x\n", hr);
110
111     if (texture) IUnknown_Release( texture );
112 }
113
114 static void test_mipmap_levels(void)
115 {
116
117     HRESULT               hr;
118     HWND                  hwnd = NULL;
119
120     IDirect3D8            *pD3d = NULL;
121     IDirect3DDevice8      *pDevice = NULL;
122     D3DPRESENT_PARAMETERS d3dpp;
123     D3DDISPLAYMODE        d3ddm;
124  
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;
130
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;
136
137     hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
138                                   D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
139     if(FAILED(hr))
140     {
141         skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
142         goto cleanup;
143     }
144
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);
149
150     cleanup:
151     if (pD3d)     IUnknown_Release( pD3d );
152     if (pDevice)  IUnknown_Release( pDevice );
153     DestroyWindow( hwnd );
154 }
155
156 static void test_swapchain(void)
157 {
158     HRESULT                      hr;
159     HWND                         hwnd               = NULL;
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;
168
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;
174
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;
181
182     hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
183                                   D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
184     if(FAILED(hr))
185     {
186         skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
187         goto cleanup;
188     }
189
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);
192
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);
198
199     d3dpp.BackBufferCount  = 1;
200     hr = IDirect3DDevice8_CreateAdditionalSwapChain(pDevice, &d3dpp, &swapchain2);
201     ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr);
202
203     d3dpp.BackBufferCount  = 2;
204     hr = IDirect3DDevice8_CreateAdditionalSwapChain(pDevice, &d3dpp, &swapchain3);
205     ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr);
206     if(SUCCEEDED(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);
213
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);
219
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);
225
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);
231     }
232
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);
239
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);
245
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);
252
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);
258
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);
264
265     cleanup:
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 );
272 }
273
274 static void test_refcount(void)
275 {
276     HRESULT                      hr;
277     HWND                         hwnd               = NULL;
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;
297     D3DCAPS8                    caps;
298
299     D3DPRESENT_PARAMETERS        d3dpp;
300     D3DDISPLAYMODE               d3ddm;
301     int                          refcount = 0, tmp;
302
303     DWORD decl[] =
304     {
305         D3DVSD_STREAM(0),
306         D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3),  /* D3DVSDE_POSITION, Register v0 */
307         D3DVSD_REG(D3DVSDE_DIFFUSE, D3DVSDT_D3DCOLOR), /* D3DVSDE_DIFFUSE, Register v5 */
308         D3DVSD_END()
309     };
310
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;
316
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;
324
325     hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
326                                   D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
327     if(FAILED(hr))
328     {
329         skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
330         goto cleanup;
331     }
332     IDirect3DDevice8_GetDeviceCaps(pDevice, &caps);
333
334     refcount = get_refcount( (IUnknown *)pDevice );
335     ok(refcount == 1, "Invalid device RefCount %d\n", refcount);
336
337     /**
338      * Check refcount of implicit surfaces. Findings:
339      *   - the container is the device
340      *   - they hold a refernce to the device
341      *   - they are created with a refcount of 0 (Get/Release returns orignial refcount)
342      *   - they are not freed if refcount reaches 0.
343      *   - the refcount is not forwarded to the container.
344      */
345     hr = IDirect3DDevice8_GetRenderTarget(pDevice, &pRenderTarget);
346     CHECK_CALL( hr, "GetRenderTarget", pDevice, ++refcount);
347     if(pRenderTarget)
348     {
349         CHECK_SURFACE_CONTAINER( pRenderTarget, IID_IDirect3DDevice8, pDevice);
350         CHECK_REFCOUNT( pRenderTarget, 1);
351
352         CHECK_ADDREF_REFCOUNT(pRenderTarget, 2);
353         CHECK_REFCOUNT(pDevice, refcount);
354         CHECK_RELEASE_REFCOUNT(pRenderTarget, 1);
355         CHECK_REFCOUNT(pDevice, refcount);
356
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);
363
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);
369     }
370
371     /* Render target and back buffer are identical. */
372     hr = IDirect3DDevice8_GetBackBuffer(pDevice, 0, 0, &pBackBuffer);
373     CHECK_CALL( hr, "GetBackBuffer", pDevice, ++refcount);
374     if(pBackBuffer)
375     {
376         CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
377         ok(pRenderTarget == pBackBuffer, "RenderTarget=%p and BackBuffer=%p should be the same.\n",
378            pRenderTarget, pBackBuffer);
379         pBackBuffer = NULL;
380     }
381     CHECK_REFCOUNT( pDevice, --refcount);
382
383     hr = IDirect3DDevice8_GetDepthStencilSurface(pDevice, &pStencilSurface);
384     CHECK_CALL( hr, "GetDepthStencilSurface", pDevice, ++refcount);
385     if(pStencilSurface)
386     {
387         CHECK_SURFACE_CONTAINER( pStencilSurface, IID_IDirect3DDevice8, pDevice);
388         CHECK_REFCOUNT( pStencilSurface, 1);
389
390         CHECK_ADDREF_REFCOUNT(pStencilSurface, 2);
391         CHECK_REFCOUNT(pDevice, refcount);
392         CHECK_RELEASE_REFCOUNT(pStencilSurface, 1);
393         CHECK_REFCOUNT(pDevice, refcount);
394
395         CHECK_RELEASE_REFCOUNT( pStencilSurface, 0);
396         CHECK_REFCOUNT( pDevice, --refcount);
397
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;
404     }
405
406     /* Buffers */
407     hr = IDirect3DDevice8_CreateIndexBuffer( pDevice, 16, 0, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &pIndexBuffer );
408     CHECK_CALL( hr, "CreateIndexBuffer", pDevice, ++refcount );
409     if(pIndexBuffer)
410     {
411         tmp = get_refcount( (IUnknown *)pIndexBuffer );
412
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);
417     }
418
419     hr = IDirect3DDevice8_CreateVertexBuffer( pDevice, 16, 0, D3DFVF_XYZ, D3DPOOL_DEFAULT, &pVertexBuffer );
420     CHECK_CALL( hr, "CreateVertexBuffer", pDevice, ++refcount );
421     if(pVertexBuffer)
422     {
423         IDirect3DVertexBuffer8 *pVBuf = (void*)~0;
424         UINT stride = ~0;
425
426         tmp = get_refcount( (IUnknown *)pVertexBuffer );
427
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);
432
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);
437     }
438
439     /* Shaders */
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))
443     {
444         hr = IDirect3DDevice8_CreatePixelShader( pDevice, simple_ps, &dPixelShader );
445         CHECK_CALL( hr, "CreatePixelShader", pDevice, refcount );
446     }
447     /* Textures */
448     hr = IDirect3DDevice8_CreateTexture( pDevice, 32, 32, 3, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pTexture );
449     CHECK_CALL( hr, "CreateTexture", pDevice, ++refcount );
450     if (pTexture)
451     {
452         tmp = get_refcount( (IUnknown *)pTexture );
453
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);
459
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 */
466         if (pTextureLevel)
467         {
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   );
475         }
476     }
477     if(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP)
478     {
479         hr = IDirect3DDevice8_CreateCubeTexture( pDevice, 32, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pCubeTexture );
480         CHECK_CALL( hr, "CreateCubeTexture", pDevice, ++refcount );
481     }
482     else
483     {
484         skip("Cube textures not supported\n");
485     }
486     if(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP)
487     {
488         hr = IDirect3DDevice8_CreateVolumeTexture( pDevice, 32, 32, 2, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pVolumeTexture );
489         CHECK_CALL( hr, "CreateVolumeTexture", pDevice, ++refcount );
490     }
491     else
492     {
493         skip("Volume textures not supported\n");
494     }
495
496     if (pVolumeTexture)
497     {
498         tmp = get_refcount( (IUnknown *)pVolumeTexture );
499
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 */
506         if (pVolumeLevel)
507         {
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   );
515         }
516     }
517     /* Surfaces */
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);
527     /* Misc */
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 );
532     if(pSwapChain)
533     {
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);
538         if(pBackBuffer)
539         {
540             CHECK_SURFACE_CONTAINER( pBackBuffer, IID_IDirect3DDevice8, pDevice);
541             CHECK_REFCOUNT( pBackBuffer, 1);
542             CHECK_RELEASE_REFCOUNT( pBackBuffer, 0);
543             CHECK_REFCOUNT( pDevice, --refcount);
544
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);
550             pBackBuffer = NULL;
551         }
552         CHECK_REFCOUNT( pSwapChain, 1);
553     }
554
555     if(pVertexBuffer)
556     {
557         BYTE *data;
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);
567     }
568
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);
573     if(pRenderTarget2)
574     {
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;
580     }
581     pRenderTarget = NULL;
582
583 cleanup:
584     CHECK_RELEASE(pDevice,              pDevice, --refcount);
585
586     /* Buffers */
587     CHECK_RELEASE(pVertexBuffer,        pDevice, --refcount);
588     CHECK_RELEASE(pIndexBuffer,         pDevice, --refcount);
589     /* Shaders */
590     if (dVertexShader != -1)  IDirect3DDevice8_DeleteVertexShader( pDevice, dVertexShader );
591     if (dPixelShader != -1)   IDirect3DDevice8_DeletePixelShader( pDevice, dPixelShader );
592     /* Textures */
593     CHECK_RELEASE(pTexture,             pDevice, --refcount);
594     CHECK_RELEASE(pCubeTexture,         pDevice, --refcount);
595     CHECK_RELEASE(pVolumeTexture,       pDevice, --refcount);
596     /* Surfaces */
597     CHECK_RELEASE(pStencilSurface,      pDevice, --refcount);
598     CHECK_RELEASE(pImageSurface,        pDevice, --refcount);
599     CHECK_RELEASE(pRenderTarget3,       pDevice, --refcount);
600     /* Misc */
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);
604
605     if (pD3d)                 CHECK_RELEASE_REFCOUNT( pD3d, 0);
606
607     DestroyWindow( hwnd );
608 }
609
610 static void test_cursor(void)
611 {
612     HRESULT                      hr;
613     HWND                         hwnd               = NULL;
614     IDirect3D8                  *pD3d               = NULL;
615     IDirect3DDevice8            *pDevice            = NULL;
616     D3DPRESENT_PARAMETERS        d3dpp;
617     D3DDISPLAYMODE               d3ddm;
618     CURSORINFO                   info;
619     IDirect3DSurface8 *cursor = NULL;
620     HCURSOR cur;
621     HMODULE user32_handle = GetModuleHandleA("user32.dll");
622
623     pGetCursorInfo = (void *)GetProcAddress(user32_handle, "GetCursorInfo");
624     if (!pGetCursorInfo)
625     {
626         skip("GetCursorInfo is not available\n");
627         return;
628     }
629
630     memset(&info, 0, sizeof(info));
631     info.cbSize = sizeof(info);
632     hr = pGetCursorInfo(&info);
633     cur = info.hCursor;
634
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;
640
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;
646
647     hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
648                                   D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
649     if(FAILED(hr))
650     {
651         skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
652         goto cleanup;
653     }
654
655     IDirect3DDevice8_CreateImageSurface(pDevice, 32, 32, D3DFMT_A8R8G8B8, &cursor);
656     ok(cursor != NULL, "IDirect3DDevice8_CreateOffscreenPlainSurface failed with %#08x\n", hr);
657
658     /* Initially hidden */
659     hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
660     ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
661
662     /* Not enabled without a surface*/
663     hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
664     ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
665
666     /* Fails */
667     hr = IDirect3DDevice8_SetCursorProperties(pDevice, 0, 0, NULL);
668     ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr);
669
670     hr = IDirect3DDevice8_SetCursorProperties(pDevice, 0, 0, cursor);
671     ok(hr == D3D_OK, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr);
672
673     IDirect3DSurface8_Release(cursor);
674
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 */
681
682     /* Still hidden */
683     hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
684     ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
685
686     /* Enabled now*/
687     hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE);
688     ok(hr == TRUE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
689
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 */
697
698 cleanup:
699     if(pD3d) IDirect3D8_Release(pD3d);
700     if(pDevice) IDirect3D8_Release(pDevice);
701 }
702
703 static void test_states(void)
704 {
705     HRESULT                      hr;
706     HWND                         hwnd               = NULL;
707     IDirect3D8                  *pD3d               = NULL;
708     IDirect3DDevice8            *pDevice            = NULL;
709     D3DPRESENT_PARAMETERS        d3dpp;
710     D3DDISPLAYMODE               d3ddm;
711
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;
717
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;
725
726     hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
727                                   D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
728     if(FAILED(hr))
729     {
730         skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
731         goto cleanup;
732     }
733
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);
738
739 cleanup:
740     if(pD3d) IDirect3D8_Release(pD3d);
741     if(pDevice) IDirect3D8_Release(pDevice);
742 }
743
744 static void test_shader_versions(void)
745 {
746     HRESULT                      hr;
747     IDirect3D8                  *pD3d               = NULL;
748     D3DCAPS8                     d3dcaps;
749
750     pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
751     ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
752     if (pD3d != NULL) {
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);
755         if (SUCCEEDED(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));
758         } else {
759             skip("No Direct3D support\n");
760         }
761         IDirect3D8_Release(pD3d);
762     }
763 }
764
765
766 /* Test adapter display modes */
767 static void test_display_modes(void)
768 {
769     UINT max_modes, i;
770     D3DDISPLAYMODE dmode;
771     HRESULT res;
772     IDirect3D8 *pD3d;
773
774     pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
775     ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
776     if(!pD3d) return;
777
778     max_modes = IDirect3D8_GetAdapterModeCount(pD3d, D3DADAPTER_DEFAULT);
779     ok(max_modes > 0, "GetAdapterModeCount(D3DADAPTER_DEFAULT) returned 0!\n");
780
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);
784         if(res != D3D_OK)
785             continue;
786
787         ok(dmode.Format==D3DFMT_X8R8G8B8 || dmode.Format==D3DFMT_R5G6B5,
788            "Unexpected display mode returned for mode %u: %#x\n", i , dmode.Format);
789     }
790
791     IDirect3D8_Release(pD3d);
792 }
793
794 static void test_scene(void)
795 {
796     HRESULT                      hr;
797     HWND                         hwnd               = NULL;
798     IDirect3D8                  *pD3d               = NULL;
799     IDirect3DDevice8            *pDevice            = NULL;
800     D3DPRESENT_PARAMETERS        d3dpp;
801     D3DDISPLAYMODE               d3ddm;
802
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;
808
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;
816
817
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);
821     if(!pDevice)
822     {
823         skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
824         goto cleanup;
825     }
826
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);
830
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);
834     if(SUCCEEDED(hr))
835     {
836         hr = IDirect3DDevice8_EndScene(pDevice);
837         ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
838     }
839
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);
843
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);
853
854     /* StretchRect does not exit in Direct3D8, so no equivalent to the d3d9 stretchrect tests */
855
856 cleanup:
857     if(pD3d) IDirect3D8_Release(pD3d);
858     if(pDevice) IDirect3D8_Release(pDevice);
859     if(hwnd) DestroyWindow(hwnd);
860 }
861
862 static void test_shader(void)
863 {
864     HRESULT                      hr;
865     HWND                         hwnd               = NULL;
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;
872     DWORD                        hTempHandle;
873     D3DCAPS8                     caps;
874     DWORD data_size;
875     void *data;
876
877     static DWORD dwVertexDecl[] =
878     {
879         D3DVSD_STREAM(0),
880         D3DVSD_REG(D3DVSDE_POSITION,  D3DVSDT_FLOAT3),
881         D3DVSD_END()
882     };
883     const DWORD vertex_decl_size = sizeof(dwVertexDecl);
884     const DWORD simple_vs_size = sizeof(simple_vs);
885     const DWORD simple_ps_size = sizeof(simple_ps);
886
887     pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
888     ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
889     hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
890     ok(hwnd != NULL, "Failed to create window\n");
891     if (!pD3d || !hwnd) goto cleanup;
892
893     IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
894     ZeroMemory( &d3dpp, sizeof(d3dpp) );
895     d3dpp.Windowed         = TRUE;
896     d3dpp.SwapEffect       = D3DSWAPEFFECT_DISCARD;
897     d3dpp.BackBufferWidth  = 800;
898     d3dpp.BackBufferHeight  = 600;
899     d3dpp.BackBufferFormat = d3ddm.Format;
900
901
902     hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
903                                   D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
904     ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "IDirect3D8_CreateDevice failed with %#08x\n", hr);
905     if(!pDevice)
906     {
907         skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
908         goto cleanup;
909     }
910     IDirect3DDevice8_GetDeviceCaps(pDevice, &caps);
911
912     /* First create a vertex shader */
913     hr = IDirect3DDevice8_CreateVertexShader(pDevice, dwVertexDecl, simple_vs, &hVertexShader, 0);
914     ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
915     /* Msdn says that the new vertex shader is set immediately. This is wrong, apparently */
916     hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
917     ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
918     ok(hTempHandle == 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, 0);
919     /* Assign the shader, then verify that GetVertexShader works */
920     hr = IDirect3DDevice8_SetVertexShader(pDevice, hVertexShader);
921     ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
922     hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
923     ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
924     ok(hTempHandle == hVertexShader, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, hVertexShader);
925     /* Verify that we can retrieve the declaration */
926     hr = IDirect3DDevice8_GetVertexShaderDeclaration(pDevice, hVertexShader, NULL, &data_size);
927     ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr);
928     ok(data_size == vertex_decl_size, "Got data_size %u, expected %u\n", data_size, vertex_decl_size);
929     data = HeapAlloc(GetProcessHeap(), 0, vertex_decl_size);
930     data_size = 1;
931     hr = IDirect3DDevice8_GetVertexShaderDeclaration(pDevice, hVertexShader, data, &data_size);
932     ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetVertexShaderDeclaration returned (%#08x), "
933             "expected D3DERR_INVALIDCALL\n", hr);
934     ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
935     data_size = vertex_decl_size;
936     hr = IDirect3DDevice8_GetVertexShaderDeclaration(pDevice, hVertexShader, data, &data_size);
937     ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr);
938     ok(data_size == vertex_decl_size, "Got data_size %u, expected %u\n", data_size, vertex_decl_size);
939     ok(!memcmp(data, dwVertexDecl, vertex_decl_size), "data not equal to shader declaration\n");
940     HeapFree(GetProcessHeap(), 0, data);
941     /* Verify that we can retrieve the shader function */
942     hr = IDirect3DDevice8_GetVertexShaderFunction(pDevice, hVertexShader, NULL, &data_size);
943     ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr);
944     ok(data_size == simple_vs_size, "Got data_size %u, expected %u\n", data_size, simple_vs_size);
945     data = HeapAlloc(GetProcessHeap(), 0, simple_vs_size);
946     data_size = 1;
947     hr = IDirect3DDevice8_GetVertexShaderFunction(pDevice, hVertexShader, data, &data_size);
948     ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetVertexShaderFunction returned (%#08x), "
949             "expected D3DERR_INVALIDCALL\n", hr);
950     ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
951     data_size = simple_vs_size;
952     hr = IDirect3DDevice8_GetVertexShaderFunction(pDevice, hVertexShader, data, &data_size);
953     ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr);
954     ok(data_size == simple_vs_size, "Got data_size %u, expected %u\n", data_size, simple_vs_size);
955     ok(!memcmp(data, simple_vs, simple_vs_size), "data not equal to shader function\n");
956     HeapFree(GetProcessHeap(), 0, data);
957     /* Delete the assigned shader. This is supposed to work */
958     hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
959     ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
960     /* The shader should be unset now */
961     hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
962     ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
963     ok(hTempHandle == 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, 0);
964
965     if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 0))
966     {
967         /* The same with a pixel shader */
968         hr = IDirect3DDevice8_CreatePixelShader(pDevice, simple_ps, &hPixelShader);
969         ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
970         /* Msdn says that the new pixel shader is set immediately. This is wrong, apparently */
971         hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle);
972         ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
973         ok(hTempHandle == 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, 0);
974         /* Assign the shader, then verify that GetPixelShader works */
975         hr = IDirect3DDevice8_SetPixelShader(pDevice, hPixelShader);
976         ok(hr == D3D_OK, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr);
977         hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle);
978         ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
979         ok(hTempHandle == hPixelShader, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, hPixelShader);
980         /* Verify that we can retrieve the shader function */
981         hr = IDirect3DDevice8_GetPixelShaderFunction(pDevice, hPixelShader, NULL, &data_size);
982         ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr);
983         ok(data_size == simple_ps_size, "Got data_size %u, expected %u\n", data_size, simple_ps_size);
984         data = HeapAlloc(GetProcessHeap(), 0, simple_ps_size);
985         data_size = 1;
986         hr = IDirect3DDevice8_GetPixelShaderFunction(pDevice, hPixelShader, data, &data_size);
987         ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetPixelShaderFunction returned (%#08x), "
988                 "expected D3DERR_INVALIDCALL\n", hr);
989         ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
990         data_size = simple_ps_size;
991         hr = IDirect3DDevice8_GetPixelShaderFunction(pDevice, hPixelShader, data, &data_size);
992         ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr);
993         ok(data_size == simple_ps_size, "Got data_size %u, expected %u\n", data_size, simple_ps_size);
994         ok(!memcmp(data, simple_ps, simple_ps_size), "data not equal to shader function\n");
995         HeapFree(GetProcessHeap(), 0, data);
996         /* Delete the assigned shader. This is supposed to work */
997         hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader);
998         ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
999         /* The shader should be unset now */
1000         hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle);
1001         ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1002         ok(hTempHandle == 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, 0);
1003
1004         /* What happens if a non-bound shader is deleted? */
1005         hr = IDirect3DDevice8_CreatePixelShader(pDevice, simple_ps, &hPixelShader);
1006         ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
1007         hr = IDirect3DDevice8_CreatePixelShader(pDevice, simple_ps, &hPixelShader2);
1008         ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
1009
1010         hr = IDirect3DDevice8_SetPixelShader(pDevice, hPixelShader);
1011         ok(hr == D3D_OK, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr);
1012         hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader2);
1013         ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1014         hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle);
1015         ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1016         ok(hTempHandle == hPixelShader, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, hPixelShader);
1017         hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader);
1018         ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1019     }
1020     else
1021     {
1022         skip("Pixel shaders not supported\n");
1023     }
1024
1025     /* What happens if a non-bound shader is deleted? */
1026     hr = IDirect3DDevice8_CreateVertexShader(pDevice, dwVertexDecl, NULL, &hVertexShader, 0);
1027     ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1028     hr = IDirect3DDevice8_CreateVertexShader(pDevice, dwVertexDecl, NULL, &hVertexShader2, 0);
1029     ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1030
1031     hr = IDirect3DDevice8_SetVertexShader(pDevice, hVertexShader);
1032     ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1033     hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader2);
1034     ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1035     hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle);
1036     ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1037     ok(hTempHandle == hVertexShader, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, hVertexShader);
1038     hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader);
1039     ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1040
1041 cleanup:
1042     if(pD3d) IDirect3D8_Release(pD3d);
1043     if(pDevice) IDirect3D8_Release(pDevice);
1044     if(hwnd) DestroyWindow(hwnd);
1045 }
1046
1047 static void test_limits(void)
1048 {
1049     HRESULT                      hr;
1050     HWND                         hwnd               = NULL;
1051     IDirect3D8                  *pD3d               = NULL;
1052     IDirect3DDevice8            *pDevice            = NULL;
1053     D3DPRESENT_PARAMETERS        d3dpp;
1054     D3DDISPLAYMODE               d3ddm;
1055     IDirect3DTexture8           *pTexture           = NULL;
1056     int i;
1057
1058     pD3d = pDirect3DCreate8( D3D_SDK_VERSION );
1059     ok(pD3d != NULL, "Failed to create IDirect3D8 object\n");
1060     hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1061     ok(hwnd != NULL, "Failed to create window\n");
1062     if (!pD3d || !hwnd) goto cleanup;
1063
1064     IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
1065     ZeroMemory( &d3dpp, sizeof(d3dpp) );
1066     d3dpp.Windowed         = TRUE;
1067     d3dpp.SwapEffect       = D3DSWAPEFFECT_DISCARD;
1068     d3dpp.BackBufferWidth  = 800;
1069     d3dpp.BackBufferHeight  = 600;
1070     d3dpp.BackBufferFormat = d3ddm.Format;
1071     d3dpp.EnableAutoDepthStencil = TRUE;
1072     d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
1073
1074     hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1075                                   D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
1076     ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL, "IDirect3D8_CreateDevice failed with %#08x\n", hr);
1077     if(!pDevice)
1078     {
1079         skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr);
1080         goto cleanup;
1081     }
1082
1083     hr = IDirect3DDevice8_CreateTexture(pDevice, 16, 16, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pTexture);
1084     ok(hr == D3D_OK, "IDirect3DDevice8_CreateTexture failed with %#08x\n", hr);
1085     if(!pTexture) goto cleanup;
1086
1087     /* There are 8 texture stages. We should be able to access all of them */
1088     for(i = 0; i < 8; i++) {
1089         hr = IDirect3DDevice8_SetTexture(pDevice, i, (IDirect3DBaseTexture8 *) pTexture);
1090         ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i, hr);
1091         hr = IDirect3DDevice8_SetTexture(pDevice, i, NULL);
1092         ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i, hr);
1093         hr = IDirect3DDevice8_SetTextureStageState(pDevice, i, D3DTSS_COLOROP, D3DTOP_ADD);
1094         ok(hr == D3D_OK, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %#08x\n", i, hr);
1095     }
1096
1097     /* Investigations show that accessing higher textures stage states does not return an error either. Writing
1098      * to too high texture stages(approximately texture 40) causes memory corruption in windows, so there is no
1099      * bounds checking but how do I test that?
1100      */
1101
1102 cleanup:
1103     if(pTexture) IDirect3DTexture8_Release(pTexture);
1104     if(pD3d) IDirect3D8_Release(pD3d);
1105     if(pDevice) IDirect3D8_Release(pDevice);
1106     if(hwnd) DestroyWindow(hwnd);
1107 }
1108
1109 static void test_lights(void)
1110 {
1111     D3DPRESENT_PARAMETERS d3dpp;
1112     IDirect3DDevice8 *device = NULL;
1113     IDirect3D8 *d3d8;
1114     HWND hwnd;
1115     HRESULT hr;
1116     unsigned int i;
1117     BOOL enabled;
1118     D3DCAPS8 caps;
1119     D3DDISPLAYMODE               d3ddm;
1120
1121     d3d8 = pDirect3DCreate8( D3D_SDK_VERSION );
1122     ok(d3d8 != NULL, "Failed to create IDirect3D8 object\n");
1123     hwnd = CreateWindow( "static", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1124     ok(hwnd != NULL, "Failed to create window\n");
1125     if (!d3d8 || !hwnd) goto cleanup;
1126
1127     IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &d3ddm );
1128     ZeroMemory( &d3dpp, sizeof(d3dpp) );
1129     d3dpp.Windowed         = TRUE;
1130     d3dpp.SwapEffect       = D3DSWAPEFFECT_DISCARD;
1131     d3dpp.BackBufferWidth  = 800;
1132     d3dpp.BackBufferHeight  = 600;
1133     d3dpp.BackBufferFormat = d3ddm.Format;
1134     d3dpp.EnableAutoDepthStencil = TRUE;
1135     d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
1136
1137     hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1138                                   D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &d3dpp, &device );
1139     ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE, "IDirect3D8_CreateDevice failed with %s\n", DXGetErrorString8(hr));
1140     if(!device)
1141     {
1142         skip("Failed to create a d3d device\n");
1143         goto cleanup;
1144     }
1145
1146     memset(&caps, 0, sizeof(caps));
1147     hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
1148     ok(hr == D3D_OK, "IDirect3DDevice8_GetDeviceCaps failed with %s\n", DXGetErrorString8(hr));
1149
1150     for(i = 1; i <= caps.MaxActiveLights; i++) {
1151         hr = IDirect3DDevice8_LightEnable(device, i, TRUE);
1152         ok(hr == D3D_OK, "Enabling light %u failed with %s\n", i, DXGetErrorString8(hr));
1153         hr = IDirect3DDevice8_GetLightEnable(device, i, &enabled);
1154         ok(hr == D3D_OK, "GetLightEnable on light %u failed with %s\n", i, DXGetErrorString8(hr));
1155         ok(enabled, "Light %d is %s\n", i, enabled ? "enabled" : "disabled");
1156     }
1157
1158     /* TODO: Test the rendering results in this situation */
1159     hr = IDirect3DDevice8_LightEnable(device, i + 1, TRUE);
1160     ok(hr == D3D_OK, "Enabling one light more than supported returned %s\n", DXGetErrorString8(hr));
1161     hr = IDirect3DDevice8_GetLightEnable(device, i + 1, &enabled);
1162     ok(hr == D3D_OK, "GetLightEnable on light %u failed with %s\n", i + 1, DXGetErrorString8(hr));
1163     ok(enabled, "Light %d is %s\n", i + 1, enabled ? "enabled" : "disabled");
1164     hr = IDirect3DDevice8_LightEnable(device, i + 1, FALSE);
1165     ok(hr == D3D_OK, "Disabling the additional returned %s\n", DXGetErrorString8(hr));
1166
1167     for(i = 1; i <= caps.MaxActiveLights; i++) {
1168         hr = IDirect3DDevice8_LightEnable(device, i, FALSE);
1169         ok(hr == D3D_OK, "Disabling light %u failed with %s\n", i, DXGetErrorString8(hr));
1170     }
1171
1172     cleanup:
1173     if(device) IDirect3DDevice8_Release(device);
1174     if(d3d8) IDirect3D8_Release(d3d8);
1175 }
1176
1177 START_TEST(device)
1178 {
1179     HMODULE d3d8_handle = LoadLibraryA( "d3d8.dll" );
1180     if (!d3d8_handle)
1181     {
1182         skip("Could not load d3d8.dll\n");
1183         return;
1184     }
1185
1186     pDirect3DCreate8 = (void *)GetProcAddress( d3d8_handle, "Direct3DCreate8" );
1187     ok(pDirect3DCreate8 != NULL, "Failed to get address of Direct3DCreate8\n");
1188     if (pDirect3DCreate8)
1189     {
1190         test_display_modes();
1191         test_shader_versions();
1192         test_swapchain();
1193         test_refcount();
1194         test_mipmap_levels();
1195         test_cursor();
1196         test_states();
1197         test_scene();
1198         test_shader();
1199         test_limits();
1200         test_lights();
1201     }
1202 }