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