comctl32: Monthcal should send notifications when today link gets clicked.
[wine] / dlls / ddraw / tests / d3d.c
1 /*
2  * Some unit tests for d3d functions
3  *
4  * Copyright (C) 2005 Antoine Chavasse
5  * Copyright (C) 2006 Stefan Dösinger for CodeWeavers
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include <assert.h>
23 #include "wine/test.h"
24 #include "ddraw.h"
25 #include "d3d.h"
26
27 static LPDIRECTDRAW7           lpDD = NULL;
28 static LPDIRECT3D7             lpD3D = NULL;
29 static LPDIRECTDRAWSURFACE7    lpDDS = NULL;
30 static LPDIRECTDRAWSURFACE7    lpDDSdepth = NULL;
31 static LPDIRECT3DDEVICE7       lpD3DDevice = NULL;
32 static LPDIRECT3DVERTEXBUFFER7 lpVBufSrc = NULL;
33 static LPDIRECT3DVERTEXBUFFER7 lpVBufDest1 = NULL;
34 static LPDIRECT3DVERTEXBUFFER7 lpVBufDest2 = NULL;
35
36 typedef struct {
37     int total;
38     int rgb;
39     int hal;
40     int tnlhal;
41     int unk;
42 } D3D7ETest;
43
44 /* To compare bad floating point numbers. Not the ideal way to do it,
45  * but it should be enough for here */
46 #define comparefloat(a, b) ( (((a) - (b)) < 0.0001) && (((a) - (b)) > -0.0001) )
47
48 static HRESULT (WINAPI *pDirectDrawCreateEx)(LPGUID,LPVOID*,REFIID,LPUNKNOWN);
49
50 typedef struct _VERTEX
51 {
52     float x, y, z;  /* position */
53 } VERTEX, *LPVERTEX;
54
55 typedef struct _TVERTEX
56 {
57     float x, y, z;  /* position */
58     float rhw;
59 } TVERTEX, *LPTVERTEX;
60
61
62 static void init_function_pointers(void)
63 {
64     HMODULE hmod = GetModuleHandleA("ddraw.dll");
65     pDirectDrawCreateEx = (void*)GetProcAddress(hmod, "DirectDrawCreateEx");
66 }
67
68
69 static BOOL CreateDirect3D(void)
70 {
71     HRESULT rc;
72     DDSURFACEDESC2 ddsd;
73
74     rc = pDirectDrawCreateEx(NULL, (void**)&lpDD,
75         &IID_IDirectDraw7, NULL);
76     ok(rc==DD_OK || rc==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", rc);
77     if (!lpDD) {
78         trace("DirectDrawCreateEx() failed with an error %x\n", rc);
79         return FALSE;
80     }
81
82     rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
83     ok(rc==DD_OK, "SetCooperativeLevel returned: %x\n", rc);
84
85     rc = IDirectDraw7_QueryInterface(lpDD, &IID_IDirect3D7, (void**) &lpD3D);
86     if (rc == E_NOINTERFACE) return FALSE;
87     ok(rc==DD_OK, "QueryInterface returned: %x\n", rc);
88
89     memset(&ddsd, 0, sizeof(ddsd));
90     ddsd.dwSize = sizeof(ddsd);
91     ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
92     ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
93     ddsd.dwWidth = 256;
94     ddsd.dwHeight = 256;
95     rc = IDirectDraw7_CreateSurface(lpDD, &ddsd, &lpDDS, NULL);
96     if (!SUCCEEDED(rc))
97         return FALSE;
98
99     memset(&ddsd, 0, sizeof(ddsd));
100     ddsd.dwSize = sizeof(ddsd);
101     ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
102     ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
103     U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
104     U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
105     U1(U4(ddsd).ddpfPixelFormat).dwZBufferBitDepth = 16;
106     U3(U4(ddsd).ddpfPixelFormat).dwZBitMask = 0x0000FFFF;
107     ddsd.dwWidth = 256;
108     ddsd.dwHeight = 256;
109     rc = IDirectDraw7_CreateSurface(lpDD, &ddsd, &lpDDSdepth, NULL);
110     ok(rc==DD_OK, "CreateSurface returned: %x\n", rc);
111     if (!SUCCEEDED(rc)) {
112         lpDDSdepth = NULL;
113     } else {
114         rc = IDirectDrawSurface_AddAttachedSurface(lpDDS, lpDDSdepth);
115         ok(rc == DD_OK, "IDirectDrawSurface_AddAttachedSurface returned %x\n", rc);
116         if (!SUCCEEDED(rc))
117             return FALSE;
118     }
119
120     rc = IDirect3D7_CreateDevice(lpD3D, &IID_IDirect3DTnLHalDevice, lpDDS,
121         &lpD3DDevice);
122     ok(rc==D3D_OK || rc==DDERR_NOPALETTEATTACHED || rc==E_OUTOFMEMORY, "CreateDevice returned: %x\n", rc);
123     if (!lpD3DDevice) {
124         trace("IDirect3D7::CreateDevice() for a TnL Hal device failed with an error %x, trying HAL\n", rc);
125         rc = IDirect3D7_CreateDevice(lpD3D, &IID_IDirect3DHALDevice, lpDDS,
126             &lpD3DDevice);
127         if (!lpD3DDevice) {
128             trace("IDirect3D7::CreateDevice() for a HAL device failed with an error %x, trying RGB\n", rc);
129             rc = IDirect3D7_CreateDevice(lpD3D, &IID_IDirect3DRGBDevice, lpDDS,
130                 &lpD3DDevice);
131             if (!lpD3DDevice) {
132                 trace("IDirect3D7::CreateDevice() for a RGB device failed with an error %x, giving up\n", rc);
133                 return FALSE;
134             }
135         }
136     }
137
138     return TRUE;
139 }
140
141 static void ReleaseDirect3D(void)
142 {
143     if (lpD3DDevice != NULL)
144     {
145         IDirect3DDevice7_Release(lpD3DDevice);
146         lpD3DDevice = NULL;
147     }
148
149     if (lpDDSdepth != NULL)
150     {
151         IDirectDrawSurface_Release(lpDDSdepth);
152         lpDDSdepth = NULL;
153     }
154
155     if (lpDDS != NULL)
156     {
157         IDirectDrawSurface_Release(lpDDS);
158         lpDDS = NULL;
159     }
160
161     if (lpD3D != NULL)
162     {
163         IDirect3D7_Release(lpD3D);
164         lpD3D = NULL;
165     }
166
167     if (lpDD != NULL)
168     {
169         IDirectDraw_Release(lpDD);
170         lpDD = NULL;
171     }
172 }
173
174 static void LightTest(void)
175 {
176     HRESULT rc;
177     D3DLIGHT7 light;
178     D3DLIGHT7 defaultlight;
179     BOOL bEnabled = FALSE;
180     float one = 1.0f;
181     float zero= 0.0f;
182     D3DMATERIAL7 mat;
183
184     /* Set a few lights with funky indices. */
185     memset(&light, 0, sizeof(light));
186     light.dltType = D3DLIGHT_DIRECTIONAL;
187     U1(light.dcvDiffuse).r = 0.5f;
188     U2(light.dcvDiffuse).g = 0.6f;
189     U3(light.dcvDiffuse).b = 0.7f;
190     U2(light.dvDirection).y = 1.f;
191
192     rc = IDirect3DDevice7_SetLight(lpD3DDevice, 5, &light);
193     ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
194     rc = IDirect3DDevice7_SetLight(lpD3DDevice, 10, &light);
195     ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
196     rc = IDirect3DDevice7_SetLight(lpD3DDevice, 45, &light);
197     ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
198
199
200     /* Try to retrieve a light beyond the indices of the lights that have
201        been set. */
202     rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
203     ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %x\n", rc);
204     rc = IDirect3DDevice7_GetLight(lpD3DDevice, 2, &light);
205     ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %x\n", rc);
206
207
208     /* Try to retrieve one of the lights that have been set */
209     rc = IDirect3DDevice7_GetLight(lpD3DDevice, 10, &light);
210     ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
211
212
213     /* Enable a light that have been previously set. */
214     rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 10, TRUE);
215     ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
216
217
218     /* Enable some lights that have not been previously set, and verify that
219        they have been initialized with proper default values. */
220     memset(&defaultlight, 0, sizeof(D3DLIGHT7));
221     defaultlight.dltType = D3DLIGHT_DIRECTIONAL;
222     U1(defaultlight.dcvDiffuse).r = 1.f;
223     U2(defaultlight.dcvDiffuse).g = 1.f;
224     U3(defaultlight.dcvDiffuse).b = 1.f;
225     U3(defaultlight.dvDirection).z = 1.f;
226
227     rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, TRUE);
228     ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
229     memset(&light, 0, sizeof(D3DLIGHT7));
230     rc = IDirect3DDevice7_GetLight(lpD3DDevice, 20, &light);
231     ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
232     ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
233         "light data doesn't match expected default values\n" );
234
235     rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 50, TRUE);
236     ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
237     memset(&light, 0, sizeof(D3DLIGHT7));
238     rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
239     ok(rc==D3D_OK, "GetLight returned: %x\n", rc);
240     ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
241         "light data doesn't match expected default values\n" );
242
243
244     /* Disable one of the light that have been previously enabled. */
245     rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, FALSE);
246     ok(rc==D3D_OK, "LightEnable returned: %x\n", rc);
247
248     /* Try to retrieve the enable status of some lights */
249     /* Light 20 is supposed to be disabled */
250     rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 20, &bEnabled );
251     ok(rc==D3D_OK, "GetLightEnable returned: %x\n", rc);
252     ok(!bEnabled, "GetLightEnable says the light is enabled\n");
253
254     /* Light 10 is supposed to be enabled */
255     bEnabled = FALSE;
256     rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 10, &bEnabled );
257     ok(rc==D3D_OK, "GetLightEnable returned: %x\n", rc);
258     ok(bEnabled, "GetLightEnable says the light is disabled\n");
259
260     /* Light 80 has not been set */
261     rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 80, &bEnabled );
262     ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %x\n", rc);
263
264     /* Light 23 has not been set */
265     rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 23, &bEnabled );
266     ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %x\n", rc);
267
268     /* Set some lights with invalid parameters */
269     memset(&light, 0, sizeof(D3DLIGHT7));
270     light.dltType = 0;
271     U1(light.dcvDiffuse).r = 1.f;
272     U2(light.dcvDiffuse).g = 1.f;
273     U3(light.dcvDiffuse).b = 1.f;
274     U3(light.dvDirection).z = 1.f;
275     rc = IDirect3DDevice7_SetLight(lpD3DDevice, 100, &light);
276     ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
277
278     memset(&light, 0, sizeof(D3DLIGHT7));
279     light.dltType = 12345;
280     U1(light.dcvDiffuse).r = 1.f;
281     U2(light.dcvDiffuse).g = 1.f;
282     U3(light.dcvDiffuse).b = 1.f;
283     U3(light.dvDirection).z = 1.f;
284     rc = IDirect3DDevice7_SetLight(lpD3DDevice, 101, &light);
285     ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
286
287     rc = IDirect3DDevice7_SetLight(lpD3DDevice, 102, NULL);
288     ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
289
290     memset(&light, 0, sizeof(D3DLIGHT7));
291     light.dltType = D3DLIGHT_SPOT;
292     U1(light.dcvDiffuse).r = 1.f;
293     U2(light.dcvDiffuse).g = 1.f;
294     U3(light.dcvDiffuse).b = 1.f;
295     U3(light.dvDirection).z = 1.f;
296
297     light.dvAttenuation0 = -one / zero; /* -INFINITY */
298     rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
299     ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
300
301     light.dvAttenuation0 = -1.0;
302     rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
303     ok(rc==DDERR_INVALIDPARAMS, "SetLight returned: %x\n", rc);
304
305     light.dvAttenuation0 = 0.0;
306     rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
307     ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
308
309     light.dvAttenuation0 = 1.0;
310     rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
311     ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
312
313     light.dvAttenuation0 = one / zero; /* +INFINITY */
314     rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
315     ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
316
317     light.dvAttenuation0 = zero / zero; /* NaN */
318     rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
319     ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
320
321     /* Directional light ignores attenuation */
322     light.dltType = D3DLIGHT_DIRECTIONAL;
323     light.dvAttenuation0 = -1.0;
324     rc = IDirect3DDevice7_SetLight(lpD3DDevice, 103, &light);
325     ok(rc==D3D_OK, "SetLight returned: %x\n", rc);
326
327     memset(&mat, 0, sizeof(mat));
328     rc = IDirect3DDevice7_SetMaterial(lpD3DDevice, &mat);
329     ok(rc == D3D_OK, "IDirect3DDevice7_SetMaterial returned: %x\n", rc);
330
331     U4(mat).power = 129.0;
332     rc = IDirect3DDevice7_SetMaterial(lpD3DDevice, &mat);
333     ok(rc == D3D_OK, "IDirect3DDevice7_SetMaterial(power = 129.0) returned: %x\n", rc);
334     memset(&mat, 0, sizeof(mat));
335     rc = IDirect3DDevice7_GetMaterial(lpD3DDevice, &mat);
336     ok(rc == D3D_OK, "IDirect3DDevice7_GetMaterial returned: %x\n", rc);
337     ok(U4(mat).power == 129, "Returned power is %f\n", U4(mat).power);
338
339     U4(mat).power = -1.0;
340     rc = IDirect3DDevice7_SetMaterial(lpD3DDevice, &mat);
341     ok(rc == D3D_OK, "IDirect3DDevice7_SetMaterial(power = -1.0) returned: %x\n", rc);
342     memset(&mat, 0, sizeof(mat));
343     rc = IDirect3DDevice7_GetMaterial(lpD3DDevice, &mat);
344     ok(rc == D3D_OK, "IDirect3DDevice7_GetMaterial returned: %x\n", rc);
345     ok(U4(mat).power == -1, "Returned power is %f\n", U4(mat).power);
346 }
347
348 static void ProcessVerticesTest(void)
349 {
350     D3DVERTEXBUFFERDESC desc;
351     HRESULT rc;
352     VERTEX *in;
353     TVERTEX *out;
354     VERTEX *out2;
355     D3DVIEWPORT7 vp;
356     D3DMATRIX view = {  2.0, 0.0, 0.0, 0.0,
357                         0.0, -1.0, 0.0, 0.0,
358                         0.0, 0.0, 1.0, 0.0,
359                         0.0, 0.0, 0.0, 3.0 };
360
361     D3DMATRIX world = { 0.0, 1.0, 0.0, 0.0,
362                         1.0, 0.0, 0.0, 0.0,
363                         0.0, 0.0, 0.0, 1.0,
364                         0.0, 1.0, 1.0, 1.0 };
365
366     D3DMATRIX proj = {  1.0, 0.0, 0.0, 1.0,
367                         0.0, 1.0, 1.0, 0.0,
368                         0.0, 1.0, 1.0, 0.0,
369                         1.0, 0.0, 0.0, 1.0 };
370     /* Create some vertex buffers */
371
372     memset(&desc, 0, sizeof(desc));
373     desc.dwSize = sizeof(desc);
374     desc.dwCaps = 0;
375     desc.dwFVF = D3DFVF_XYZ;
376     desc.dwNumVertices = 16;
377     rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufSrc, 0);
378     ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
379     if (!lpVBufSrc)
380     {
381         trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
382         goto out;
383     }
384
385     memset(&desc, 0, sizeof(desc));
386     desc.dwSize = sizeof(desc);
387     desc.dwCaps = 0;
388     desc.dwFVF = D3DFVF_XYZRHW;
389     desc.dwNumVertices = 16;
390     /* Msdn says that the last parameter must be 0 - check that */
391     rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufDest1, 4);
392     ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
393     if (!lpVBufDest1)
394     {
395         trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
396         goto out;
397     }
398
399     memset(&desc, 0, sizeof(desc));
400     desc.dwSize = sizeof(desc);
401     desc.dwCaps = 0;
402     desc.dwFVF = D3DFVF_XYZ;
403     desc.dwNumVertices = 16;
404     /* Msdn says that the last parameter must be 0 - check that */
405     rc = IDirect3D7_CreateVertexBuffer(lpD3D, &desc, &lpVBufDest2, 12345678);
406     ok(rc==D3D_OK || rc==E_OUTOFMEMORY, "CreateVertexBuffer returned: %x\n", rc);
407     if (!lpVBufDest2)
408     {
409         trace("IDirect3D7::CreateVertexBuffer() failed with an error %x\n", rc);
410         goto out;
411     }
412
413     rc = IDirect3DVertexBuffer7_Lock(lpVBufSrc, 0, (void **) &in, NULL);
414     ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
415     if(!in) goto out;
416
417     /* Check basic transformation */
418
419     in[0].x = 0.0;
420     in[0].y = 0.0;
421     in[0].z = 0.0;
422
423     in[1].x = 1.0;
424     in[1].y = 1.0;
425     in[1].z = 1.0;
426
427     in[2].x = -1.0;
428     in[2].y = -1.0;
429     in[2].z = 0.5;
430
431     in[3].x = 0.5;
432     in[3].y = -0.5;
433     in[3].z = 0.25;
434     rc = IDirect3DVertexBuffer7_Unlock(lpVBufSrc);
435     ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
436
437     rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
438     ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
439
440     rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest2, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
441     ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
442
443     rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
444     ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
445     if(!out) goto out;
446
447     /* Check the results */
448     ok( comparefloat(out[0].x, 128.0 ) &&
449         comparefloat(out[0].y, 128.0 ) &&
450         comparefloat(out[0].z, 0.0 ) &&
451         comparefloat(out[0].rhw, 1.0 ),
452         "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
453
454     ok( comparefloat(out[1].x, 256.0 ) &&
455         comparefloat(out[1].y, 0.0 ) &&
456         comparefloat(out[1].z, 1.0 ) &&
457         comparefloat(out[1].rhw, 1.0 ),
458         "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
459
460     ok( comparefloat(out[2].x, 0.0 ) &&
461         comparefloat(out[2].y, 256.0 ) &&
462         comparefloat(out[2].z, 0.5 ) &&
463         comparefloat(out[2].rhw, 1.0 ),
464         "Output 2 vertex is (%f , %f , %f , %f)\n", out[2].x, out[2].y, out[2].z, out[2].rhw);
465
466     ok( comparefloat(out[3].x, 192.0 ) &&
467         comparefloat(out[3].y, 192.0 ) &&
468         comparefloat(out[3].z, 0.25 ) &&
469         comparefloat(out[3].rhw, 1.0 ),
470         "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
471
472     rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
473     ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
474     out = NULL;
475
476     rc = IDirect3DVertexBuffer7_Lock(lpVBufDest2, 0, (void **) &out2, NULL);
477     ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
478     if(!out2) goto out;
479     /* Small thing without much practial meaning, but I stumbled upon it,
480      * so let's check for it: If the output vertex buffer has to RHW value,
481      * The RHW value of the last vertex is written into the next vertex
482      */
483     ok( comparefloat(out2[4].x, 1.0 ) &&
484         comparefloat(out2[4].y, 0.0 ) &&
485         comparefloat(out2[4].z, 0.0 ),
486         "Output 4 vertex is (%f , %f , %f)\n", out2[4].x, out2[4].y, out2[4].z);
487
488     rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest2);
489     ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
490     out = NULL;
491
492     /* Try a more complicated viewport, same vertices */
493     memset(&vp, 0, sizeof(vp));
494     vp.dwX = 10;
495     vp.dwY = 5;
496     vp.dwWidth = 246;
497     vp.dwHeight = 130;
498     vp.dvMinZ = -2.0;
499     vp.dvMaxZ = 4.0;
500     rc = IDirect3DDevice7_SetViewport(lpD3DDevice, &vp);
501     ok(rc==D3D_OK, "IDirect3DDevice7_SetViewport failed with rc=%x\n", rc);
502
503     /* Process again */
504     rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
505     ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
506
507     rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
508     ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
509     if(!out) goto out;
510
511     /* Check the results */
512     ok( comparefloat(out[0].x, 133.0 ) &&
513         comparefloat(out[0].y, 70.0 ) &&
514         comparefloat(out[0].z, -2.0 ) &&
515         comparefloat(out[0].rhw, 1.0 ),
516         "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
517
518     ok( comparefloat(out[1].x, 256.0 ) &&
519         comparefloat(out[1].y, 5.0 ) &&
520         comparefloat(out[1].z, 4.0 ) &&
521         comparefloat(out[1].rhw, 1.0 ),
522         "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
523
524     ok( comparefloat(out[2].x, 10.0 ) &&
525         comparefloat(out[2].y, 135.0 ) &&
526         comparefloat(out[2].z, 1.0 ) &&
527         comparefloat(out[2].rhw, 1.0 ),
528         "Output 2 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
529
530     ok( comparefloat(out[3].x, 194.5 ) &&
531         comparefloat(out[3].y, 102.5 ) &&
532         comparefloat(out[3].z, -0.5 ) &&
533         comparefloat(out[3].rhw, 1.0 ),
534         "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
535
536     rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
537     ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
538     out = NULL;
539
540     /* Play with some matrices. */
541
542     rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_VIEW, &view);
543     ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
544
545     rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_PROJECTION, &proj);
546     ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
547
548     rc = IDirect3DDevice7_SetTransform(lpD3DDevice, D3DTRANSFORMSTATE_WORLD, &world);
549     ok(rc==D3D_OK, "IDirect3DDevice7_SetTransform failed\n");
550
551     rc = IDirect3DVertexBuffer7_ProcessVertices(lpVBufDest1, D3DVOP_TRANSFORM, 0, 4, lpVBufSrc, 0, lpD3DDevice, 0);
552     ok(rc==D3D_OK , "IDirect3DVertexBuffer::ProcessVertices returned: %x\n", rc);
553
554     rc = IDirect3DVertexBuffer7_Lock(lpVBufDest1, 0, (void **) &out, NULL);
555     ok(rc==D3D_OK , "IDirect3DVertexBuffer::Lock returned: %x\n", rc);
556     if(!out) goto out;
557
558     /* Keep the viewport simpler, otherwise we get bad numbers to compare */
559     vp.dwX = 0;
560     vp.dwY = 0;
561     vp.dwWidth = 100;
562     vp.dwHeight = 100;
563     vp.dvMinZ = 1.0;
564     vp.dvMaxZ = 0.0;
565     rc = IDirect3DDevice7_SetViewport(lpD3DDevice, &vp);
566     ok(rc==D3D_OK, "IDirect3DDevice7_SetViewport failed\n");
567
568     /* Check the results */
569     ok( comparefloat(out[0].x, 256.0 ) &&    /* X coordinate is cut at the surface edges */
570         comparefloat(out[0].y, 70.0 ) &&
571         comparefloat(out[0].z, -2.0 ) &&
572         comparefloat(out[0].rhw, (1.0 / 3.0)),
573         "Output 0 vertex is (%f , %f , %f , %f)\n", out[0].x, out[0].y, out[0].z, out[0].rhw);
574
575     ok( comparefloat(out[1].x, 256.0 ) &&
576         comparefloat(out[1].y, 78.125000 ) &&
577         comparefloat(out[1].z, -2.750000 ) &&
578         comparefloat(out[1].rhw, 0.125000 ),
579         "Output 1 vertex is (%f , %f , %f , %f)\n", out[1].x, out[1].y, out[1].z, out[1].rhw);
580
581     ok( comparefloat(out[2].x, 256.0 ) &&
582         comparefloat(out[2].y, 44.000000 ) &&
583         comparefloat(out[2].z, 0.400000 ) &&
584         comparefloat(out[2].rhw, 0.400000 ),
585         "Output 2 vertex is (%f , %f , %f , %f)\n", out[2].x, out[2].y, out[2].z, out[2].rhw);
586
587     ok( comparefloat(out[3].x, 256.0 ) &&
588         comparefloat(out[3].y, 81.818184 ) &&
589         comparefloat(out[3].z, -3.090909 ) &&
590         comparefloat(out[3].rhw, 0.363636 ),
591         "Output 3 vertex is (%f , %f , %f , %f)\n", out[3].x, out[3].y, out[3].z, out[3].rhw);
592
593     rc = IDirect3DVertexBuffer7_Unlock(lpVBufDest1);
594     ok(rc==D3D_OK , "IDirect3DVertexBuffer::Unlock returned: %x\n", rc);
595     out = NULL;
596
597 out:
598     IDirect3DVertexBuffer7_Release(lpVBufSrc);
599     IDirect3DVertexBuffer7_Release(lpVBufDest1);
600     IDirect3DVertexBuffer7_Release(lpVBufDest2);
601 }
602
603 static void StateTest( void )
604 {
605     HRESULT rc;
606
607     /* The msdn says its undocumented, does it return an error too? */
608     rc = IDirect3DDevice7_SetRenderState(lpD3DDevice, D3DRENDERSTATE_ZVISIBLE, TRUE);
609     ok(rc == D3D_OK, "IDirect3DDevice7_SetRenderState(D3DRENDERSTATE_ZVISIBLE, TRUE) returned %08x\n", rc);
610     rc = IDirect3DDevice7_SetRenderState(lpD3DDevice, D3DRENDERSTATE_ZVISIBLE, FALSE);
611     ok(rc == D3D_OK, "IDirect3DDevice7_SetRenderState(D3DRENDERSTATE_ZVISIBLE, FALSE) returned %08x\n", rc);
612 }
613
614
615 static void SceneTest(void)
616 {
617     HRESULT                      hr;
618
619     /* Test an EndScene without beginscene. Should return an error */
620     hr = IDirect3DDevice7_EndScene(lpD3DDevice);
621     ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
622
623     /* Test a normal BeginScene / EndScene pair, this should work */
624     hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
625     ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed with %08x\n", hr);
626     if(SUCCEEDED(hr))
627     {
628         DDBLTFX fx;
629         memset(&fx, 0, sizeof(fx));
630         fx.dwSize = sizeof(fx);
631
632         if(lpDDSdepth) {
633             hr = IDirectDrawSurface7_Blt(lpDDSdepth, NULL, NULL, NULL, DDBLT_DEPTHFILL, &fx);
634             ok(hr == D3D_OK, "Depthfill failed in a BeginScene / EndScene pair\n");
635         } else {
636             skip("Depth stencil creation failed at startup, skipping\n");
637         }
638         hr = IDirect3DDevice7_EndScene(lpD3DDevice);
639         ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed with %08x\n", hr);
640     }
641
642     /* Test another EndScene without having begun a new scene. Should return an error */
643     hr = IDirect3DDevice7_EndScene(lpD3DDevice);
644     ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
645
646     /* Two nested BeginScene and EndScene calls */
647     hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
648     ok(hr == D3D_OK, "IDirect3DDevice7_BeginScene failed with %08x\n", hr);
649     hr = IDirect3DDevice7_BeginScene(lpD3DDevice);
650     ok(hr == D3DERR_SCENE_IN_SCENE, "IDirect3DDevice7_BeginScene returned %08x\n", hr);
651     hr = IDirect3DDevice7_EndScene(lpD3DDevice);
652     ok(hr == D3D_OK, "IDirect3DDevice7_EndScene failed with %08x\n", hr);
653     hr = IDirect3DDevice7_EndScene(lpD3DDevice);
654     ok(hr == D3DERR_SCENE_NOT_IN_SCENE, "IDirect3DDevice7_EndScene returned %08x\n", hr);
655
656     /* TODO: Verify that blitting works in the same way as in d3d9 */
657 }
658
659 static void LimitTest(void)
660 {
661     IDirectDrawSurface7 *pTexture = NULL;
662     HRESULT hr;
663     int i;
664     DDSURFACEDESC2 ddsd;
665
666     memset(&ddsd, 0, sizeof(ddsd));
667     ddsd.dwSize = sizeof(ddsd);
668     ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
669     ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
670     ddsd.dwWidth = 16;
671     ddsd.dwHeight = 16;
672     hr = IDirectDraw7_CreateSurface(lpDD, &ddsd, &pTexture, NULL);
673     ok(hr==DD_OK,"CreateSurface returned: %x\n",hr);
674     if(!pTexture) return;
675
676     for(i = 0; i < 8; i++) {
677         hr = IDirect3DDevice7_SetTexture(lpD3DDevice, i, pTexture);
678         ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %08x\n", i, hr);
679         hr = IDirect3DDevice7_SetTexture(lpD3DDevice, i, NULL);
680         ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %08x\n", i, hr);
681         hr = IDirect3DDevice7_SetTextureStageState(lpD3DDevice, i, D3DTSS_COLOROP, D3DTOP_ADD);
682         ok(hr == D3D_OK, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %08x\n", i, hr);
683     }
684
685     IDirectDrawSurface7_Release(pTexture);
686 }
687
688 static HRESULT WINAPI enumDevicesCallback(GUID *Guid,LPSTR DeviceDescription,LPSTR DeviceName, D3DDEVICEDESC *hal, D3DDEVICEDESC *hel, VOID *ctx)
689 {
690     UINT ver = *((UINT *) ctx);
691     if(IsEqualGUID(&IID_IDirect3DRGBDevice, Guid))
692     {
693         ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
694            "RGB Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
695         ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
696            "RGB Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
697         ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
698            "RGB Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
699         ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
700            "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
701
702         ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
703            "RGB Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
704         ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
705            "RGB Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
706         ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
707            "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
708         ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
709            "RGB Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
710     }
711     else if(IsEqualGUID(&IID_IDirect3DHALDevice, Guid))
712     {
713         /* pow2 is hardware dependent */
714
715         ok(hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
716            "HAL Device %d hal line caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
717         ok(hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
718            "HAL Device %d hal tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
719         ok((hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
720            "HAL Device %d hel line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
721         ok((hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
722            "HAL Device %d hel tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
723     }
724     else if(IsEqualGUID(&IID_IDirect3DRefDevice, Guid))
725     {
726         ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
727            "REF Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
728         ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
729            "REF Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
730         ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
731            "REF Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
732         ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
733            "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
734
735         ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
736            "REF Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
737         ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
738            "REF Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
739         ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
740            "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
741         ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
742            "REF Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
743     }
744     else if(IsEqualGUID(&IID_IDirect3DRampDevice, Guid))
745     {
746         ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
747            "Ramp Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
748         ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
749            "Ramp Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
750         ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
751            "Ramp Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
752         ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
753            "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
754
755         ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
756            "Ramp Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
757         ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
758            "Ramp Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
759         ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
760            "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
761         ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
762            "Ramp Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
763     }
764     else if(IsEqualGUID(&IID_IDirect3DMMXDevice, Guid))
765     {
766         ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
767            "MMX Device %d hal line caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
768         ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0,
769            "MMX Device %d hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n", ver);
770         ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
771            "MMX Device %d hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
772         ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2,
773            "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n", ver);
774
775         ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
776            "MMX Device %d hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
777         ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0,
778            "MMX Device %d hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
779         ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
780            "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
781         ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE,
782            "MMX Device %d hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n", ver);
783     }
784     else
785     {
786         ok(FALSE, "Unexpected device enumerated: \"%s\" \"%s\"\n", DeviceDescription, DeviceName);
787         if(hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hal line has pow2 set\n");
788         else trace("hal line does NOT have pow2 set\n");
789         if(hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hal tri has pow2 set\n");
790         else trace("hal tri does NOT have pow2 set\n");
791         if(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hel line has pow2 set\n");
792         else trace("hel line does NOT have pow2 set\n");
793         if(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hel tri has pow2 set\n");
794         else trace("hel tri does NOT have pow2 set\n");
795     }
796     return DDENUMRET_OK;
797 }
798
799 static HRESULT WINAPI enumDevicesCallbackTest7(LPSTR DeviceDescription, LPSTR DeviceName, LPD3DDEVICEDESC7 lpdd7, LPVOID Context)
800 {
801     D3D7ETest *d3d7et = (D3D7ETest*)Context;
802     if(IsEqualGUID(&lpdd7->deviceGUID, &IID_IDirect3DRGBDevice))
803         d3d7et->rgb++;
804     else if(IsEqualGUID(&lpdd7->deviceGUID, &IID_IDirect3DHALDevice))
805         d3d7et->hal++;
806     else if(IsEqualGUID(&lpdd7->deviceGUID, &IID_IDirect3DTnLHalDevice))
807         d3d7et->tnlhal++;
808     else
809         d3d7et->unk++;
810
811     d3d7et->total++;
812
813     return DDENUMRET_OK;
814 }
815
816
817 /*  Check the deviceGUID of devices enumerated by
818     IDirect3D7_EnumDevices. */
819 static void D3D7EnumTest(void)
820 {
821     D3D7ETest d3d7et;
822
823     if (!lpD3D) {
824         skip("No Direct3D7 interface.\n");
825         return;
826     }
827
828     memset(&d3d7et, 0, sizeof(d3d7et));
829     IDirect3D7_EnumDevices(lpD3D, enumDevicesCallbackTest7, (LPVOID) &d3d7et);
830
831
832     /* A couple of games (Delta Force LW and TFD) rely on this behaviour */
833     ok(d3d7et.tnlhal < d3d7et.total, "TnLHal device enumerated as only device.\n");
834
835     /* We make two additional assumptions. */
836     ok(d3d7et.rgb, "No RGB Device enumerated.\n");
837
838     if(d3d7et.tnlhal)
839         ok(d3d7et.hal, "TnLHal device enumerated, but no Hal device found.\n");
840
841     return;
842 }
843
844 static void CapsTest(void)
845 {
846     IDirect3D3 *d3d3;
847     IDirect3D3 *d3d2;
848     IDirectDraw *dd1;
849     HRESULT hr;
850     UINT ver;
851
852     hr = DirectDrawCreate(NULL, &dd1, NULL);
853     ok(hr == DD_OK, "Cannot create a DirectDraw 1 interface, hr = %08x\n", hr);
854     hr = IDirectDraw_QueryInterface(dd1, &IID_IDirect3D3, (void **) &d3d3);
855     ok(hr == D3D_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
856     ver = 3;
857     IDirect3D3_EnumDevices(d3d3, enumDevicesCallback, &ver);
858
859     IDirect3D3_Release(d3d3);
860     IDirectDraw_Release(dd1);
861
862     hr = DirectDrawCreate(NULL, &dd1, NULL);
863     ok(hr == DD_OK, "Cannot create a DirectDraw 1 interface, hr = %08x\n", hr);
864     hr = IDirectDraw_QueryInterface(dd1, &IID_IDirect3D2, (void **) &d3d2);
865     ok(hr == D3D_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
866     ver = 2;
867     IDirect3D2_EnumDevices(d3d2, enumDevicesCallback, &ver);
868
869     IDirect3D2_Release(d3d2);
870     IDirectDraw_Release(dd1);
871 }
872
873 struct v_in {
874     float x, y, z;
875 };
876 struct v_out {
877     float x, y, z, rhw;
878 };
879
880 static void Direct3D1Test(void)
881 {
882     IDirect3DDevice *dev1 = NULL;
883     IDirectDraw *dd;
884     IDirect3D *d3d;
885     IDirectDrawSurface *dds;
886     IDirect3DExecuteBuffer *exebuf;
887     IDirect3DViewport *vp;
888     HRESULT hr;
889     DDSURFACEDESC ddsd;
890     D3DEXECUTEBUFFERDESC desc;
891     D3DVIEWPORT vp_data;
892     D3DINSTRUCTION *instr;
893     D3DBRANCH *branch;
894     unsigned int idx = 0;
895     static struct v_in testverts[] = {
896         {0.0, 0.0, 0.0},  { 1.0,  1.0,  1.0}, {-1.0, -1.0, -1.0},
897         {0.5, 0.5, 0.5},  {-0.5, -0.5, -0.5}, {-0.5, -0.5, 0.0},
898     };
899     static struct v_in cliptest[] = {
900         {25.59, 25.59, 1.0},  {-25.59, -25.59,  0.0},
901         {25.61, 25.61, 1.01}, {-25.60, -25.60, -0.01},
902     };
903     static struct v_in offscreentest[] = {
904         {128.1, 0.0, 0.0},
905     };
906     struct v_out out[sizeof(testverts) / sizeof(testverts[0])];
907     D3DHVERTEX outH[sizeof(testverts) / sizeof(testverts[0])];
908     D3DTRANSFORMDATA transformdata;
909     DWORD i = FALSE;
910
911     /* An IDirect3DDevice cannot be queryInterfaced from an IDirect3DDevice7 on windows */
912     hr = DirectDrawCreate(NULL, &dd, NULL);
913     ok(hr==DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreate returned: %x\n", hr);
914     if (!dd) {
915         trace("DirectDrawCreate() failed with an error %x\n", hr);
916         return;
917     }
918
919     hr = IDirectDraw_SetCooperativeLevel(dd, NULL, DDSCL_NORMAL);
920     ok(hr==DD_OK, "SetCooperativeLevel returned: %x\n", hr);
921
922     hr = IDirectDraw_QueryInterface(dd, &IID_IDirect3D, (void**) &d3d);
923     ok(hr==DD_OK, "QueryInterface returned: %x\n", hr);
924
925     memset(&ddsd, 0, sizeof(ddsd));
926     ddsd.dwSize = sizeof(ddsd);
927     ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
928     ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
929     ddsd.dwWidth = 256;
930     ddsd.dwHeight = 256;
931     hr = IDirectDraw_CreateSurface(dd, &ddsd, &dds, NULL);
932     ok(hr==DD_OK, "CreateSurface returned: %x\n", hr);
933
934     dev1 = NULL;
935     hr = IDirectDrawSurface_QueryInterface(dds, &IID_IDirect3DRGBDevice, (void **) &dev1);
936     ok(hr==D3D_OK || hr==DDERR_NOPALETTEATTACHED || hr==E_OUTOFMEMORY, "CreateDevice returned: %x\n", hr);
937     if(!dev1) return;
938
939     memset(&desc, 0, sizeof(desc));
940     desc.dwSize = sizeof(desc);
941     desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
942     desc.dwCaps = D3DDEBCAPS_VIDEOMEMORY;
943     desc.dwBufferSize = 128;
944     desc.lpData = NULL;
945     hr = IDirect3DDevice_CreateExecuteBuffer(dev1, &desc, &exebuf, NULL);
946     ok(hr == D3D_OK, "IDirect3DDevice_CreateExecuteBuffer failed: %08x\n", hr);
947
948     memset(&desc, 0, sizeof(desc));
949     desc.dwSize = sizeof(desc);
950
951     hr = IDirect3DExecuteBuffer_Lock(exebuf, &desc);
952     ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Lock failed: %08x\n", hr);
953     instr = desc.lpData;
954     instr[idx].bOpcode = D3DOP_BRANCHFORWARD;
955     instr[idx].bSize = sizeof(*branch);
956     instr[idx].wCount = 1;
957     idx++;
958     branch = (D3DBRANCH *) &instr[idx];
959     branch->dwMask = 0x0;
960     branch->dwValue = 1;
961     branch->bNegate = TRUE;
962     branch->dwOffset = 0;
963     idx += (sizeof(*branch) / sizeof(*instr));
964     instr[idx].bOpcode = D3DOP_EXIT;
965     instr[idx].bSize = 0;
966     instr[idx].bSize = 0;
967     hr = IDirect3DExecuteBuffer_Unlock(exebuf);
968     ok(hr == D3D_OK, "IDirect3DExecuteBuffer_Unlock failed: %08x\n", hr);
969
970     hr = IDirect3D_CreateViewport(d3d, &vp, NULL);
971     ok(hr == D3D_OK, "IDirect3D_CreateViewport failed: %08x\n", hr);
972     hr = IDirect3DViewport_Initialize(vp, d3d);
973     ok(hr == DDERR_ALREADYINITIALIZED, "IDirect3DViewport_Initialize returned %08x\n", hr);
974
975     hr = IDirect3DDevice_AddViewport(dev1, vp);
976     ok(hr == D3D_OK, "IDirect3DDevice_AddViewport returned %08x\n", hr);
977     vp_data.dwSize = sizeof(vp_data);
978     vp_data.dwX = 0;
979     vp_data.dwY = 0;
980     vp_data.dwWidth = 256;
981     vp_data.dwHeight = 256;
982     vp_data.dvScaleX = 1;
983     vp_data.dvScaleY = 1;
984     vp_data.dvMaxX = 256;
985     vp_data.dvMaxY = 256;
986     vp_data.dvMinZ = 0;
987     vp_data.dvMaxZ = 1;
988     hr = IDirect3DViewport_SetViewport(vp, &vp_data);
989     ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
990
991     hr = IDirect3DDevice_Execute(dev1, exebuf, vp, D3DEXECUTE_CLIPPED);
992     ok(hr == D3D_OK, "IDirect3DDevice_Execute returned %08x\n", hr);
993
994     memset(&transformdata, 0, sizeof(transformdata));
995     transformdata.dwSize = sizeof(transformdata);
996     transformdata.lpIn = (void *) testverts;
997     transformdata.dwInSize = sizeof(testverts[0]);
998     transformdata.lpOut = out;
999     transformdata.dwOutSize = sizeof(out[0]);
1000
1001     transformdata.lpHOut = NULL;
1002     hr = IDirect3DViewport_TransformVertices(vp, sizeof(testverts) / sizeof(testverts[0]),
1003                                              &transformdata, D3DTRANSFORM_UNCLIPPED,
1004                                              &i);
1005     ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1006
1007     transformdata.lpHOut = outH;
1008     memset(outH, 0xaa, sizeof(outH));
1009     hr = IDirect3DViewport_TransformVertices(vp, sizeof(testverts) / sizeof(testverts[0]),
1010                                              &transformdata, D3DTRANSFORM_UNCLIPPED,
1011                                              &i);
1012     ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1013     ok(i == 0, "Offscreen is %d\n", i);
1014
1015     for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
1016         static const struct v_out cmp[] = {
1017             {128.0, 128.0, 0.0, 1}, {129.0, 127.0,  1.0, 1}, {127.0, 129.0, -1, 1},
1018             {128.5, 127.5, 0.5, 1}, {127.5, 128.5, -0.5, 1}, {127.5, 128.5,  0, 1}
1019         };
1020
1021         ok(cmp[i].x == out[i].x && cmp[i].y == out[i].y &&
1022            cmp[i].z == out[i].z && cmp[i].rhw == out[i].rhw,
1023            "Vertex %d differs. Got %f %f %f %f, expexted %f %f %f %f\n", i + 1,
1024            out[i].x, out[i].y, out[i].z, out[i].rhw,
1025            cmp[i].x, cmp[i].y, cmp[i].z, cmp[i].rhw);
1026     }
1027     for(i = 0; i < sizeof(outH); i++) {
1028         if(((unsigned char *) outH)[i] != 0xaa) {
1029             ok(FALSE, "Homogenous output was generated despite UNCLIPPED flag\n");
1030             break;
1031         }
1032     }
1033
1034     vp_data.dvScaleX = 5;
1035     vp_data.dvScaleY = 5;
1036     vp_data.dvMinZ = -25;
1037     vp_data.dvMaxZ = 60;
1038     hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1039     ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1040     hr = IDirect3DViewport_TransformVertices(vp, sizeof(testverts) / sizeof(testverts[0]),
1041                                              &transformdata, D3DTRANSFORM_UNCLIPPED,
1042                                              &i);
1043     ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1044     ok(i == 0, "Offscreen is %d\n", i);
1045     for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
1046         static const struct v_out cmp[] = {
1047             {128.0, 128.0, 0.0, 1}, {133.0, 123.0,  1.0, 1}, {123.0, 133.0, -1, 1},
1048             {130.5, 125.5, 0.5, 1}, {125.5, 130.5, -0.5, 1}, {125.5, 130.5,  0, 1}
1049         };
1050         ok(cmp[i].x == out[i].x && cmp[i].y == out[i].y &&
1051            cmp[i].z == out[i].z && cmp[i].rhw == out[i].rhw,
1052            "Vertex %d differs. Got %f %f %f %f, expexted %f %f %f %f\n", i + 1,
1053            out[i].x, out[i].y, out[i].z, out[i].rhw,
1054            cmp[i].x, cmp[i].y, cmp[i].z, cmp[i].rhw);
1055     }
1056
1057     vp_data.dwX = 10;
1058     vp_data.dwY = 20;
1059     hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1060     ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1061     hr = IDirect3DViewport_TransformVertices(vp, sizeof(testverts) / sizeof(testverts[0]),
1062                                              &transformdata, D3DTRANSFORM_UNCLIPPED,
1063                                              &i);
1064     ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1065     ok(i == 0, "Offscreen is %d\n", i);
1066     for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
1067         static const struct v_out cmp[] = {
1068             {138.0, 148.0, 0.0, 1}, {143.0, 143.0,  1.0, 1}, {133.0, 153.0, -1, 1},
1069             {140.5, 145.5, 0.5, 1}, {135.5, 150.5, -0.5, 1}, {135.5, 150.5,  0, 1}
1070         };
1071         ok(cmp[i].x == out[i].x && cmp[i].y == out[i].y &&
1072            cmp[i].z == out[i].z && cmp[i].rhw == out[i].rhw,
1073            "Vertex %d differs. Got %f %f %f %f, expexted %f %f %f %f\n", i + 1,
1074            out[i].x, out[i].y, out[i].z, out[i].rhw,
1075            cmp[i].x, cmp[i].y, cmp[i].z, cmp[i].rhw);
1076     }
1077
1078     memset(out, 0xbb, sizeof(out));
1079     hr = IDirect3DViewport_TransformVertices(vp, sizeof(testverts) / sizeof(testverts[0]),
1080                                              &transformdata, D3DTRANSFORM_CLIPPED,
1081                                              &i);
1082     ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1083     ok(i == 0, "Offscreen is %d\n", i);
1084     for(i = 0; i < sizeof(testverts) / sizeof(testverts[0]); i++) {
1085         static const D3DHVERTEX cmpH[] = {
1086             {0,             { 0.0}, { 0.0}, { 0.0}}, {0, { 1.0}, { 1.0}, {1.0}},
1087             {D3DCLIP_FRONT, {-1.0}, {-1.0}, {-1.0}}, {0, { 0.5}, { 0.5}, {0.5}},
1088             {D3DCLIP_FRONT, {-0.5}, {-0.5}, {-0.5}}, {0, {-0.5}, {-0.5}, {0.0}}
1089         };
1090         ok(U1(cmpH[i]).hx == U1(outH[i]).hx && U2(cmpH[i]).hy == U2(outH[i]).hy &&
1091            U3(cmpH[i]).hz == U3(outH[i]).hz && cmpH[i].dwFlags == outH[i].dwFlags,
1092            "HVertex %d differs. Got %08x %f %f %f, expexted %08x %f %f %f\n", i + 1,
1093            outH[i].dwFlags, U1(outH[i]).hx, U2(outH[i]).hy, U3(outH[i]).hz,
1094            cmpH[i].dwFlags, U1(cmpH[i]).hx, U2(cmpH[i]).hy, U3(cmpH[i]).hz);
1095
1096         /* No scheme has been found behind those return values. It seems to be
1097          * whatever data windows has when throwing the vertex away. Modify the
1098          * input test vertices to test this more. Depending on the input data
1099          * it can happen that the z coord gets written into y, or similar things
1100          */
1101         if(0)
1102         {
1103             static const struct v_out cmp[] = {
1104                 {138.0, 148.0, 0.0, 1}, {143.0, 143.0,  1.0, 1}, { -1.0,  -1.0, 0.5, 1},
1105                 {140.5, 145.5, 0.5, 1}, { -0.5,  -0.5, -0.5, 1}, {135.5, 150.5, 0.0, 1}
1106             };
1107             ok(cmp[i].x == out[i].x && cmp[i].y == out[i].y &&
1108                cmp[i].z == out[i].z && cmp[i].rhw == out[i].rhw,
1109                 "Vertex %d differs. Got %f %f %f %f, expexted %f %f %f %f\n", i + 1,
1110                out[i].x, out[i].y, out[i].z, out[i].rhw,
1111                cmp[i].x, cmp[i].y, cmp[i].z, cmp[i].rhw);
1112         }
1113     }
1114     for(i = 0; i < sizeof(out) / sizeof(DWORD); i++) {
1115         ok(((DWORD *) out)[i] != 0xbbbbbbbb,
1116                 "Regular output DWORD %d remained untouched\n", i);
1117     }
1118
1119     transformdata.lpIn = (void *) cliptest;
1120     transformdata.dwInSize = sizeof(cliptest[0]);
1121     hr = IDirect3DViewport_TransformVertices(vp, sizeof(cliptest) / sizeof(cliptest[0]),
1122                                              &transformdata, D3DTRANSFORM_CLIPPED,
1123                                              &i);
1124     ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1125     ok(i == 0, "Offscreen is %d\n", i);
1126     for(i = 0; i < sizeof(cliptest) / sizeof(cliptest[0]); i++) {
1127         DWORD Flags[sizeof(cliptest) / sizeof(cliptest[0])] =
1128         {
1129             0,
1130             0,
1131             D3DCLIP_RIGHT | D3DCLIP_BACK   | D3DCLIP_TOP,
1132             D3DCLIP_LEFT  | D3DCLIP_BOTTOM | D3DCLIP_FRONT,
1133         };
1134         ok(Flags[i] == outH[i].dwFlags,
1135            "Cliptest %d differs. Got %08x expexted %08x\n", i + 1,
1136            outH[i].dwFlags, Flags[i]);
1137     }
1138
1139     vp_data.dwWidth = 10;
1140     vp_data.dwHeight = 1000;
1141     hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1142     i = 10;
1143     ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1144     hr = IDirect3DViewport_TransformVertices(vp, sizeof(cliptest) / sizeof(cliptest[0]),
1145                                              &transformdata, D3DTRANSFORM_CLIPPED,
1146                                              &i);
1147     ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1148     ok(i == 0, "Offscreen is %d\n", i);
1149     for(i = 0; i < sizeof(cliptest) / sizeof(cliptest[0]); i++) {
1150         DWORD Flags[sizeof(cliptest) / sizeof(cliptest[0])] =
1151         {
1152             D3DCLIP_RIGHT,
1153             D3DCLIP_LEFT,
1154             D3DCLIP_RIGHT | D3DCLIP_BACK,
1155             D3DCLIP_LEFT  | D3DCLIP_FRONT,
1156         };
1157         ok(Flags[i] == outH[i].dwFlags,
1158            "Cliptest %d differs. Got %08x expexted %08x\n", i + 1,
1159            outH[i].dwFlags, Flags[i]);
1160     }
1161     vp_data.dwWidth = 256;
1162     vp_data.dwHeight = 256;
1163     vp_data.dvScaleX = 1;
1164     vp_data.dvScaleY = 1;
1165     hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1166     ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1167     hr = IDirect3DViewport_TransformVertices(vp, sizeof(cliptest) / sizeof(cliptest[0]),
1168                                              &transformdata, D3DTRANSFORM_CLIPPED,
1169                                              &i);
1170     ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1171     ok(i == 0, "Offscreen is %s\n", i ? "TRUE" : "FALSE");
1172     for(i = 0; i < sizeof(cliptest) / sizeof(cliptest[0]); i++) {
1173         DWORD Flags[sizeof(cliptest) / sizeof(cliptest[0])] =
1174         {
1175             0,
1176             0,
1177             D3DCLIP_BACK,
1178             D3DCLIP_FRONT,
1179         };
1180         ok(Flags[i] == outH[i].dwFlags,
1181            "Cliptest %d differs. Got %08x expexted %08x\n", i + 1,
1182            outH[i].dwFlags, Flags[i]);
1183     }
1184
1185     /* Finally try to figure out how the DWORD dwOffscreen works.
1186      * Apparently no vertex is offscreen with clipping off,
1187      * and with clipping on the offscreen flag is set if only one vertex
1188      * is transformed, and this vertex is offscreen.
1189      */
1190     vp_data.dwWidth = 5;
1191     vp_data.dwHeight = 5;
1192     vp_data.dvScaleX = 10000;
1193     vp_data.dvScaleY = 10000;
1194     hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1195     ok(hr == D3D_OK, "IDirect3DViewport_SetViewport returned %08x\n", hr);
1196     transformdata.lpIn = cliptest;
1197     hr = IDirect3DViewport_TransformVertices(vp, 1,
1198                                              &transformdata, D3DTRANSFORM_UNCLIPPED,
1199                                              &i);
1200     ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1201     ok(i == 0, "Offscreen is %d\n", i);
1202     hr = IDirect3DViewport_TransformVertices(vp, 1,
1203                                              &transformdata, D3DTRANSFORM_CLIPPED,
1204                                              &i);
1205     ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1206     ok(i == (D3DCLIP_RIGHT | D3DCLIP_TOP), "Offscreen is %d\n", i);
1207     hr = IDirect3DViewport_TransformVertices(vp, 2,
1208                                              &transformdata, D3DTRANSFORM_CLIPPED,
1209                                              &i);
1210     ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1211     ok(i == 0, "Offscreen is %d\n", i);
1212     transformdata.lpIn = cliptest + 1;
1213     hr = IDirect3DViewport_TransformVertices(vp, 1,
1214                                              &transformdata, D3DTRANSFORM_CLIPPED,
1215                                              &i);
1216     ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1217     ok(i == (D3DCLIP_BOTTOM | D3DCLIP_LEFT), "Offscreen is %d\n", i);
1218
1219     transformdata.lpIn = (void *) offscreentest;
1220     transformdata.dwInSize = sizeof(offscreentest[0]);
1221     vp_data.dwWidth = 257;
1222     vp_data.dwHeight = 257;
1223     vp_data.dvScaleX = 1;
1224     vp_data.dvScaleY = 1;
1225     hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1226     i = 12345;
1227     hr = IDirect3DViewport_TransformVertices(vp, sizeof(offscreentest) / sizeof(offscreentest[0]),
1228                                              &transformdata, D3DTRANSFORM_CLIPPED,
1229                                              &i);
1230     ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1231     ok(i == 0, "Offscreen is %d\n", i);
1232     vp_data.dwWidth = 256;
1233     vp_data.dwHeight = 256;
1234     hr = IDirect3DViewport_SetViewport(vp, &vp_data);
1235     i = 12345;
1236     hr = IDirect3DViewport_TransformVertices(vp, sizeof(offscreentest) / sizeof(offscreentest[0]),
1237                                              &transformdata, D3DTRANSFORM_CLIPPED,
1238                                              &i);
1239     ok(hr == D3D_OK, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1240     ok(i == D3DCLIP_RIGHT, "Offscreen is %d\n", i);
1241
1242     hr = IDirect3DViewport_TransformVertices(vp, sizeof(testverts) / sizeof(testverts[0]),
1243                                              &transformdata, 0,
1244                                              &i);
1245     ok(hr == DDERR_INVALIDPARAMS, "IDirect3DViewport_TransformVertices returned %08x\n", hr);
1246
1247     hr = IDirect3DDevice_DeleteViewport(dev1, vp);
1248     ok(hr == D3D_OK, "IDirect3DDevice_DeleteViewport returned %08x\n", hr);
1249
1250     IDirect3DViewport_Release(vp);
1251     IDirect3DExecuteBuffer_Release(exebuf);
1252     IDirect3DDevice_Release(dev1);
1253     IDirectDrawSurface_Release(dds);
1254     IDirect3D_Release(d3d);
1255     IDirectDraw_Release(dd);
1256     return;
1257 }
1258
1259 START_TEST(d3d)
1260 {
1261     init_function_pointers();
1262     if(!pDirectDrawCreateEx) {
1263         skip("function DirectDrawCreateEx not available\n");
1264         return;
1265     }
1266
1267     if(!CreateDirect3D()) {
1268         trace("Skipping tests\n");
1269         return;
1270     }
1271     LightTest();
1272     ProcessVerticesTest();
1273     StateTest();
1274     SceneTest();
1275     LimitTest();
1276     D3D7EnumTest();
1277     CapsTest();
1278     ReleaseDirect3D();
1279     Direct3D1Test();
1280 }