Implement A->W call for GetNamedSecurityInfo.
[wine] / dlls / ddraw / d3ddevice / main.c
1 /* Direct3D Device
2  * Copyright (c) 1998-2004 Lionel ULMER
3  * Copyright (c) 2002-2004 Christian Costa
4  *
5  * This file contains all the common stuff for D3D devices.
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "config.h"
23
24 #include <stdarg.h>
25 #include <string.h>
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winerror.h"
30 #include "objbase.h"
31 #include "wingdi.h"
32 #include "ddraw.h"
33 #include "d3d.h"
34 #include "wine/debug.h"
35
36 #include "d3d_private.h"
37 #include "main.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
40
41 DWORD InitRenderStateTab[] = {
42     D3DRENDERSTATE_TEXTUREHANDLE,           (DWORD)NULL,
43     D3DRENDERSTATE_ANTIALIAS,               D3DANTIALIAS_NONE,
44     /* FIXME: D3DRENDERSTATE_TEXTUREADDRESS */
45     D3DRENDERSTATE_TEXTUREPERSPECTIVE,      TRUE,
46     /* FIXME: D3DRENDERSTATE_WRAPU */
47     /* FIXME: D3DRENDERSTATE_WRAPV */
48     D3DRENDERSTATE_ZENABLE,                 D3DZB_TRUE, /* This needs to be set differently according to the Z buffer status */
49     D3DRENDERSTATE_FILLMODE,                D3DFILL_SOLID,
50     D3DRENDERSTATE_SHADEMODE,               D3DSHADE_GOURAUD,
51     D3DRENDERSTATE_LINEPATTERN,             0,
52     D3DRENDERSTATE_MONOENABLE,              FALSE,
53     D3DRENDERSTATE_ROP2,                    R2_COPYPEN,
54     D3DRENDERSTATE_PLANEMASK,               0xFFFFFFFF,
55     D3DRENDERSTATE_ZWRITEENABLE,            TRUE,
56     D3DRENDERSTATE_ALPHATESTENABLE,         FALSE,
57     D3DRENDERSTATE_LASTPIXEL,               TRUE,
58     D3DRENDERSTATE_TEXTUREMAG,              D3DFILTER_NEAREST,
59     D3DRENDERSTATE_TEXTUREMIN,              D3DFILTER_NEAREST,
60     D3DRENDERSTATE_SRCBLEND,                D3DBLEND_ONE,
61     D3DRENDERSTATE_DESTBLEND,               D3DBLEND_ZERO,
62     D3DRENDERSTATE_TEXTUREMAPBLEND,         D3DTBLEND_MODULATE,
63     D3DRENDERSTATE_CULLMODE,                D3DCULL_CCW,
64     D3DRENDERSTATE_ZFUNC,                   D3DCMP_LESSEQUAL,
65     D3DRENDERSTATE_ALPHAREF,                0,
66     D3DRENDERSTATE_ALPHAFUNC,               D3DCMP_ALWAYS,
67     D3DRENDERSTATE_DITHERENABLE,            FALSE,
68     D3DRENDERSTATE_ALPHABLENDENABLE,        FALSE,
69     D3DRENDERSTATE_FOGENABLE,               FALSE,
70     D3DRENDERSTATE_SPECULARENABLE,          FALSE,
71     D3DRENDERSTATE_ZVISIBLE,                FALSE,
72     D3DRENDERSTATE_SUBPIXEL,                FALSE,
73     D3DRENDERSTATE_SUBPIXELX,               FALSE,
74     D3DRENDERSTATE_STIPPLEDALPHA,           FALSE,
75     D3DRENDERSTATE_FOGCOLOR,                D3DRGBA(0,0,0,0),
76     D3DRENDERSTATE_FOGTABLEMODE,            D3DFOG_NONE,
77     /* FIXME: D3DRENDERSTATE_FOGTABLESTART (same as D3DRENDERSTATE_FOGSTART) */
78     /* FIXME: D3DRENDERSTATE_FOGTABLEEND (same as D3DRENDERSTATE_FOGEND) */
79     D3DRENDERSTATE_FOGTABLEDENSITY,         0x3F80000, /* 1.0f (same as D3DRENDERSTATE_FOGDENSITY) */
80     /* FIXME: D3DRENDERSTATE_STIPPLEENABLE */
81     D3DRENDERSTATE_EDGEANTIALIAS,           FALSE,
82     D3DRENDERSTATE_COLORKEYENABLE,          FALSE,
83     /* FIXME: D3DRENDERSTATE_BORDERCOLOR */
84     D3DRENDERSTATE_TEXTUREADDRESSU,         D3DTADDRESS_WRAP,
85     D3DRENDERSTATE_TEXTUREADDRESSV,         D3DTADDRESS_WRAP,
86     D3DRENDERSTATE_MIPMAPLODBIAS,           0x00000000, /* 0.0f */
87     D3DRENDERSTATE_ZBIAS,                   0,
88     D3DRENDERSTATE_RANGEFOGENABLE,          FALSE,    
89     /* FIXME: D3DRENDERSTATE_ANISOTROPY */
90     /* FIXME: D3DRENDERSTATE_FLUSHBATCH */
91     /* FIXME: D3DRENDERSTATE_TRANSLUCENTSORTINDEPENDENT */
92     D3DRENDERSTATE_STENCILENABLE,           FALSE,
93     D3DRENDERSTATE_STENCILFAIL,             D3DSTENCILOP_KEEP,
94     D3DRENDERSTATE_STENCILZFAIL,            D3DSTENCILOP_KEEP,
95     D3DRENDERSTATE_STENCILPASS,             D3DSTENCILOP_KEEP,
96     D3DRENDERSTATE_STENCILFUNC,             D3DCMP_ALWAYS,
97     D3DRENDERSTATE_STENCILREF,              0,
98     D3DRENDERSTATE_STENCILMASK,             0xFFFFFFFF,
99     D3DRENDERSTATE_STENCILWRITEMASK,        0xFFFFFFFF,
100     /* FIXME: D3DRENDERSTATE_TEXTUREFACTOR */
101     /* FIXME: D3DRENDERSTATE_STIPPLEPATTERN00..31 */
102     D3DRENDERSTATE_WRAP0,                   0,
103     D3DRENDERSTATE_WRAP1,                   0,
104     D3DRENDERSTATE_WRAP2,                   0,
105     D3DRENDERSTATE_WRAP3,                   0,
106     D3DRENDERSTATE_WRAP4,                   0,
107     D3DRENDERSTATE_WRAP5,                   0,
108     D3DRENDERSTATE_WRAP6,                   0,
109     D3DRENDERSTATE_WRAP7,                   0,
110     D3DRENDERSTATE_CLIPPING,                FALSE,
111     D3DRENDERSTATE_LIGHTING,                TRUE,
112     D3DRENDERSTATE_EXTENTS,                 FALSE,
113     D3DRENDERSTATE_AMBIENT,                 D3DRGBA(0,0,0,0),
114     D3DRENDERSTATE_FOGVERTEXMODE,           D3DFOG_NONE,
115     D3DRENDERSTATE_COLORVERTEX,             TRUE,
116     D3DRENDERSTATE_LOCALVIEWER,             TRUE,
117     D3DRENDERSTATE_NORMALIZENORMALS,        FALSE,
118     /* FIXME: D3DRENDER_STATE_COLORKEYBLENDENABLE */
119     D3DRENDERSTATE_DIFFUSEMATERIALSOURCE,   D3DMCS_COLOR1,
120     D3DRENDERSTATE_SPECULARMATERIALSOURCE,  D3DMCS_COLOR2,
121     D3DRENDERSTATE_AMBIENTMATERIALSOURCE,   D3DMCS_COLOR2,
122     D3DRENDERSTATE_EMISSIVEMATERIALSOURCE,  D3DMCS_MATERIAL,
123     D3DRENDERSTATE_VERTEXBLEND,             D3DVBLEND_DISABLE,
124     D3DRENDERSTATE_CLIPPLANEENABLE,         0
125 };
126
127 DWORD InitLightStateTab[] = {
128     D3DLIGHTSTATE_MATERIAL,           (DWORD)NULL,
129     D3DLIGHTSTATE_AMBIENT,            D3DRGBA(0,0,0,0),
130     D3DLIGHTSTATE_COLORMODEL,         D3DCOLOR_RGB,
131     D3DLIGHTSTATE_FOGMODE,            D3DFOG_NONE,
132     D3DLIGHTSTATE_FOGSTART,           0x3F80000, /* 1.0f */
133     D3DLIGHTSTATE_FOGEND,             0x42C8000, /* 100.0f */
134     D3DLIGHTSTATE_FOGDENSITY,         0x3F80000  /* 1.0f */
135     /* FIXME: D3DLIGHTSTATE_COLORVERTEX */
136 };
137
138 DWORD InitTextureStageStateTab[] = {
139     D3DTSS_COLOROP,          D3DTOP_DISABLE, /* Note, it's manually set for stage 0 */
140     D3DTSS_COLORARG1,        D3DTA_TEXTURE,
141     D3DTSS_COLORARG2,        D3DTA_CURRENT,
142     D3DTSS_ALPHAOP,          D3DTOP_DISABLE, /* Note, it's manually set for stage 0 */
143     D3DTSS_ALPHAARG1,        D3DTA_TEXTURE,
144     D3DTSS_ALPHAARG2,        D3DTA_CURRENT,
145     /* FIXME: D3DTSS_BUMPENVMAT00,01,10,11 */
146     /* D3DTSS_TEXCOORDINDEX is set manually */
147     D3DTSS_ADDRESS,          D3DTADDRESS_WRAP,
148     D3DTSS_ADDRESSU,         D3DTADDRESS_WRAP,
149     D3DTSS_ADDRESSV,         D3DTADDRESS_WRAP,
150     D3DTSS_BORDERCOLOR,      0x00000000,
151     D3DTSS_MAGFILTER,        D3DTFG_POINT,
152     D3DTSS_MINFILTER,        D3DTFN_POINT,
153     D3DTSS_MIPFILTER,        D3DTFP_NONE,
154     D3DTSS_MIPMAPLODBIAS,    0x00000000, /* 0.0f */
155     D3DTSS_MAXMIPLEVEL,      0,
156     /* D3DTSS_MAXANISOTROPY,    1, */ /* This is to prevent warnings :-) */
157     /* FIXME: D3DTSS_BUMPENVLSCALE */
158     /* FIXME: D3DTSS_NUMPENVLOFFSET */
159     /* FIXME: D3DTSS_TEXTURETRANSFORMFLAGS */
160 };
161
162         
163 void InitDefaultStateBlock(STATEBLOCK* lpStateBlock, int version)
164 {
165     int i, j;  
166     TRACE("(%p,%d)\n", lpStateBlock, version);    
167     memset(lpStateBlock, 0, sizeof(STATEBLOCK));
168     
169     /* Initialize render states */
170     for (i = 0; i < sizeof(InitRenderStateTab) / sizeof(InitRenderStateTab[0]); i += 2)
171     {
172         lpStateBlock->render_state[InitRenderStateTab[i] - 1] = InitRenderStateTab[i + 1];
173         lpStateBlock->set_flags.render_state[InitRenderStateTab[i] - 1] = TRUE;
174     }
175
176     /* Initialize texture stages states */
177     for (i = 0; i < MAX_TEXTURES; i++)
178     {
179        for (j = 0; j < sizeof(InitTextureStageStateTab) / sizeof(InitTextureStageStateTab[0]); j += 2)
180        {
181            lpStateBlock->texture_stage_state[i][InitTextureStageStateTab[j] - 1] = InitTextureStageStateTab[j + 1];
182            lpStateBlock->set_flags.texture_stage_state[i][InitTextureStageStateTab[j] - 1] = TRUE;
183        }
184        /* Map texture coords 0 to stage 0, 1 to stage 1, etc... */
185        lpStateBlock->texture_stage_state[i][D3DTSS_TEXCOORDINDEX - 1] = i;
186        lpStateBlock->set_flags.texture_stage_state[i][D3DTSS_TEXCOORDINDEX - 1] = TRUE;
187     }
188     
189     /* The first texture is particular, update it consequently */
190     lpStateBlock->texture_stage_state[0][D3DTSS_COLOROP - 1] = D3DTOP_MODULATE;
191     lpStateBlock->texture_stage_state[0][D3DTSS_ALPHAOP - 1] = D3DTOP_SELECTARG1;
192     lpStateBlock->texture_stage_state[0][D3DTSS_COLORARG2 - 1] = D3DTA_DIFFUSE;
193     lpStateBlock->texture_stage_state[0][D3DTSS_ALPHAARG2 - 1] = D3DTA_DIFFUSE;
194     
195     /* Updates for particular versions */
196     if ((version == 1) || (version==2))
197        lpStateBlock->render_state[D3DRENDERSTATE_SPECULARENABLE - 1] = TRUE;
198 }
199
200 HRESULT WINAPI
201 Main_IDirect3DDeviceImpl_7_3T_2T_1T_QueryInterface(LPDIRECT3DDEVICE7 iface,
202                                                    REFIID riid,
203                                                    LPVOID* obp)
204 {
205     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
206     TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_guid(riid), obp);
207
208     *obp = NULL;
209
210     if ( IsEqualGUID( &IID_IUnknown,  riid ) ) {
211         IDirect3DDevice7_AddRef(ICOM_INTERFACE(This, IDirect3DDevice7));
212         *obp = iface;
213         TRACE("  Creating IUnknown interface at %p.\n", *obp);
214         return S_OK;
215     }
216     if ( IsEqualGUID( &IID_IDirect3DDevice, riid ) ) {
217         IDirect3DDevice7_AddRef(ICOM_INTERFACE(This, IDirect3DDevice7));
218         *obp = ICOM_INTERFACE(This, IDirect3DDevice);
219         TRACE("  Creating IDirect3DDevice interface %p\n", *obp);
220         return S_OK;
221     }
222     if ( IsEqualGUID( &IID_IDirect3DDevice2, riid ) ) {
223         IDirect3DDevice7_AddRef(ICOM_INTERFACE(This, IDirect3DDevice7));
224         *obp = ICOM_INTERFACE(This, IDirect3DDevice2);
225         TRACE("  Creating IDirect3DDevice2 interface %p\n", *obp);
226         return S_OK;
227     }
228     if ( IsEqualGUID( &IID_IDirect3DDevice3, riid ) ) {
229         IDirect3DDevice7_AddRef(ICOM_INTERFACE(This, IDirect3DDevice7));
230         *obp = ICOM_INTERFACE(This, IDirect3DDevice3);
231         TRACE("  Creating IDirect3DDevice3 interface %p\n", *obp);
232         return S_OK;
233     }
234     if ( IsEqualGUID( &IID_IDirect3DDevice7, riid ) ) {
235         IDirect3DDevice7_AddRef(ICOM_INTERFACE(This, IDirect3DDevice7));
236         *obp = ICOM_INTERFACE(This, IDirect3DDevice7);
237         TRACE("  Creating IDirect3DDevice7 interface %p\n", *obp);
238         return S_OK;
239     }
240     if ( IsEqualGUID( &IID_IDirectDrawSurface, riid ) ||
241          IsEqualGUID( &IID_IDirectDrawSurface2, riid ) ||
242          IsEqualGUID( &IID_IDirectDrawSurface3, riid ) ) {
243         IDirectDrawSurface7_AddRef(ICOM_INTERFACE(This->surface, IDirectDrawSurface7));
244         *obp = ICOM_INTERFACE(This->surface, IDirectDrawSurface3);
245         TRACE("  Return IDirectDrawSurface3 interface %p\n", *obp);
246         return S_OK;
247     }
248     if ( IsEqualGUID( &IID_IDirectDrawSurface4, riid ) ||
249          IsEqualGUID( &IID_IDirectDrawSurface7, riid ) ) {
250         IDirectDrawSurface7_AddRef(ICOM_INTERFACE(This->surface, IDirectDrawSurface7));
251         *obp = ICOM_INTERFACE(This->surface, IDirectDrawSurface7);
252         TRACE("  Return IDirectDrawSurface7 interface %p\n", *obp);
253         return S_OK;
254     }
255     FIXME("(%p): interface for IID %s NOT found!\n", This, debugstr_guid(riid));
256     return OLE_E_ENUM_NOMORE;
257 }
258
259 ULONG WINAPI
260 Main_IDirect3DDeviceImpl_7_3T_2T_1T_AddRef(LPDIRECT3DDEVICE7 iface)
261 {
262     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
263     TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, This->ref);
264     return ++(This->ref);
265 }
266
267 ULONG WINAPI
268 Main_IDirect3DDeviceImpl_7_3T_2T_1T_Release(LPDIRECT3DDEVICE7 iface)
269 {
270     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
271     TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref);
272     if (!--(This->ref)) {
273         int i;
274         /* Release texture associated with the device */
275         for (i = 0; i < MAX_TEXTURES; i++) {
276             if (This->current_texture[i] != NULL)
277                 IDirect3DTexture2_Release(ICOM_INTERFACE(This->current_texture[i], IDirect3DTexture2));
278         }
279                   
280         HeapFree(GetProcessHeap(), 0, This);
281         return 0;
282     }
283     return This->ref;
284 }
285
286 HRESULT WINAPI
287 Main_IDirect3DDeviceImpl_7_GetCaps(LPDIRECT3DDEVICE7 iface,
288                                    LPD3DDEVICEDESC7 lpD3DHELDevDesc)
289 {
290     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
291     FIXME("(%p/%p)->(%p): stub!\n", This, iface, lpD3DHELDevDesc);
292     return DD_OK;
293 }
294
295 HRESULT WINAPI
296 Main_IDirect3DDeviceImpl_7_3T_EnumTextureFormats(LPDIRECT3DDEVICE7 iface,
297                                                  LPD3DENUMPIXELFORMATSCALLBACK lpD3DEnumPixelProc,
298                                                  LPVOID lpArg)
299 {
300     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
301     FIXME("(%p/%p)->(%p,%p): stub!\n", This, iface, lpD3DEnumPixelProc, lpArg);
302     return DD_OK;
303 }
304
305 HRESULT WINAPI
306 Main_IDirect3DDeviceImpl_7_3T_2T_1T_BeginScene(LPDIRECT3DDEVICE7 iface)
307 {
308     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
309     TRACE("(%p/%p)->()\n", This, iface);
310     /* Nothing to do */
311     return DD_OK;
312 }
313
314 HRESULT WINAPI
315 Main_IDirect3DDeviceImpl_7_3T_2T_1T_EndScene(LPDIRECT3DDEVICE7 iface)
316 {
317     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
318     TRACE("(%p/%p)->()\n", This, iface);
319     /* Nothing to do */
320     return DD_OK;
321 }
322
323 HRESULT WINAPI
324 Main_IDirect3DDeviceImpl_7_3T_2T_1T_GetDirect3D(LPDIRECT3DDEVICE7 iface,
325                                                 LPDIRECT3D7* lplpDirect3D7)
326 {
327     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
328     TRACE("(%p/%p)->(%p)\n", This, iface, lplpDirect3D7);
329
330     *lplpDirect3D7 = ICOM_INTERFACE(This->d3d, IDirect3D7);
331     IDirect3D7_AddRef(ICOM_INTERFACE(This->d3d, IDirect3D7));
332     
333     TRACE(" returning interface %p\n", *lplpDirect3D7);
334     return DD_OK;
335 }
336
337 HRESULT WINAPI
338 Main_IDirect3DDeviceImpl_7_3T_2T_SetRenderTarget(LPDIRECT3DDEVICE7 iface,
339                                                  LPDIRECTDRAWSURFACE7 lpNewRenderTarget,
340                                                  DWORD dwFlags)
341 {
342     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
343     IDirectDrawSurfaceImpl *target_impl = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, lpNewRenderTarget);
344
345     TRACE("(%p/%p)->(%p,%08lx)\n", This, iface, lpNewRenderTarget, dwFlags);
346     if (target_impl != This->surface) {
347         WARN(" Change of rendering target not handled yet !\n");
348     }
349     return DD_OK;
350 }
351
352 HRESULT WINAPI
353 Main_IDirect3DDeviceImpl_7_3T_2T_GetRenderTarget(LPDIRECT3DDEVICE7 iface,
354                                                  LPDIRECTDRAWSURFACE7* lplpRenderTarget)
355 {
356     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
357     TRACE("(%p/%p)->(%p)\n", This, iface, lplpRenderTarget);
358
359     *lplpRenderTarget = ICOM_INTERFACE(This->surface, IDirectDrawSurface7);
360     IDirectDrawSurface7_AddRef(ICOM_INTERFACE(This->surface, IDirectDrawSurface7));
361     
362     TRACE(" returning surface at %p.\n", *lplpRenderTarget);
363     
364     return DD_OK;
365 }
366
367 HRESULT WINAPI
368 Main_IDirect3DDeviceImpl_7_Clear(LPDIRECT3DDEVICE7 iface,
369                                  DWORD dwCount,
370                                  LPD3DRECT lpRects,
371                                  DWORD dwFlags,
372                                  D3DCOLOR dwColor,
373                                  D3DVALUE dvZ,
374                                  DWORD dwStencil)
375 {
376     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
377     TRACE("(%p/%p)->(%08lx,%p,%08lx,%08lx,%f,%08lx)\n", This, iface, dwCount, lpRects, dwFlags, (DWORD) dwColor, dvZ, dwStencil);
378     return This->clear(This, dwCount, lpRects, dwFlags, dwColor, dvZ, dwStencil);
379 }
380
381 HRESULT WINAPI
382 Main_IDirect3DDeviceImpl_7_3T_2T_SetTransform(LPDIRECT3DDEVICE7 iface,
383                                               D3DTRANSFORMSTATETYPE dtstTransformStateType,
384                                               LPD3DMATRIX lpD3DMatrix)
385 {
386     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
387     DWORD matrix_changed = 0x00000000;
388
389     TRACE("(%p/%p)->(%08x,%p)\n", This, iface, dtstTransformStateType, lpD3DMatrix);
390
391     switch (dtstTransformStateType) {
392         case D3DTRANSFORMSTATE_WORLD: {
393             if (TRACE_ON(ddraw)) {
394                 TRACE(" D3DTRANSFORMSTATE_WORLD :\n"); dump_D3DMATRIX(lpD3DMatrix);
395             }
396             memcpy(This->world_mat, lpD3DMatrix, 16 * sizeof(float));
397             matrix_changed = WORLDMAT_CHANGED;
398         } break;
399
400         case D3DTRANSFORMSTATE_VIEW: {
401             if (TRACE_ON(ddraw)) {
402                 TRACE(" D3DTRANSFORMSTATE_VIEW :\n");  dump_D3DMATRIX(lpD3DMatrix);
403             }
404             memcpy(This->view_mat, lpD3DMatrix, 16 * sizeof(float));
405             matrix_changed = VIEWMAT_CHANGED;
406         } break;
407
408         case D3DTRANSFORMSTATE_PROJECTION: {
409             if (TRACE_ON(ddraw)) {
410                 TRACE(" D3DTRANSFORMSTATE_PROJECTION :\n");  dump_D3DMATRIX(lpD3DMatrix);
411             }
412             memcpy(This->proj_mat, lpD3DMatrix, 16 * sizeof(float));
413             matrix_changed = PROJMAT_CHANGED;
414         } break;
415
416         case D3DTRANSFORMSTATE_TEXTURE0:
417         case D3DTRANSFORMSTATE_TEXTURE1:
418         case D3DTRANSFORMSTATE_TEXTURE2:
419         case D3DTRANSFORMSTATE_TEXTURE3:
420         case D3DTRANSFORMSTATE_TEXTURE4:
421         case D3DTRANSFORMSTATE_TEXTURE5:
422         case D3DTRANSFORMSTATE_TEXTURE6:
423         case D3DTRANSFORMSTATE_TEXTURE7: {
424             DWORD mat_num = dtstTransformStateType - D3DTRANSFORMSTATE_TEXTURE0;
425             if (TRACE_ON(ddraw)) {
426                 TRACE(" D3DTRANSFORMSTATE_TEXTURE%ld :\n", mat_num);  dump_D3DMATRIX(lpD3DMatrix);
427             }
428             memcpy(This->tex_mat[mat_num], lpD3DMatrix, 16 * sizeof(float));
429             matrix_changed = TEXMAT0_CHANGED << mat_num;
430         } break;
431           
432         default:
433             ERR("Unknown transform type %08x !!!\n", dtstTransformStateType);
434             break;
435     }
436
437     if (matrix_changed != 0x00000000) This->matrices_updated(This, matrix_changed);
438
439     return DD_OK;
440 }
441
442 HRESULT WINAPI
443 Main_IDirect3DDeviceImpl_7_3T_2T_GetTransform(LPDIRECT3DDEVICE7 iface,
444                                               D3DTRANSFORMSTATETYPE dtstTransformStateType,
445                                               LPD3DMATRIX lpD3DMatrix)
446 {
447     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
448     TRACE("(%p/%p)->(%08x,%p)\n", This, iface, dtstTransformStateType, lpD3DMatrix);
449
450     switch (dtstTransformStateType) {
451         case D3DTRANSFORMSTATE_WORLD: {
452             memcpy(lpD3DMatrix, This->world_mat, 16 * sizeof(D3DVALUE));
453             if (TRACE_ON(ddraw)) {
454                 TRACE(" returning D3DTRANSFORMSTATE_WORLD :\n");
455                 dump_D3DMATRIX(lpD3DMatrix);
456             }
457         } break;
458
459         case D3DTRANSFORMSTATE_VIEW: {
460             memcpy(lpD3DMatrix, This->view_mat, 16 * sizeof(D3DVALUE));
461             if (TRACE_ON(ddraw)) {
462                 TRACE(" returning D3DTRANSFORMSTATE_VIEW :\n");
463                 dump_D3DMATRIX(lpD3DMatrix);
464             }
465         } break;
466
467         case D3DTRANSFORMSTATE_PROJECTION: {
468             memcpy(lpD3DMatrix, This->proj_mat, 16 * sizeof(D3DVALUE));
469             if (TRACE_ON(ddraw)) {
470                 TRACE(" returning D3DTRANSFORMSTATE_PROJECTION :\n");
471                 dump_D3DMATRIX(lpD3DMatrix);
472             }
473         } break;
474
475         case D3DTRANSFORMSTATE_TEXTURE0:
476         case D3DTRANSFORMSTATE_TEXTURE1:
477         case D3DTRANSFORMSTATE_TEXTURE2:
478         case D3DTRANSFORMSTATE_TEXTURE3:
479         case D3DTRANSFORMSTATE_TEXTURE4:
480         case D3DTRANSFORMSTATE_TEXTURE5:
481         case D3DTRANSFORMSTATE_TEXTURE6:
482         case D3DTRANSFORMSTATE_TEXTURE7: {
483             DWORD mat_num = dtstTransformStateType - D3DTRANSFORMSTATE_TEXTURE0;
484             memcpy(lpD3DMatrix, This->tex_mat[mat_num], 16 * sizeof(D3DVALUE));
485             if (TRACE_ON(ddraw)) {
486                 TRACE(" returning D3DTRANSFORMSTATE_TEXTURE%ld :\n", mat_num);
487                 dump_D3DMATRIX(lpD3DMatrix);
488             }
489         } break;
490           
491         default:
492             ERR("Unknown transform type %08x !!!\n", dtstTransformStateType);
493             return DDERR_INVALIDPARAMS;
494     }
495
496     return DD_OK;
497 }
498
499 HRESULT WINAPI
500 Main_IDirect3DDeviceImpl_7_3T_2T_MultiplyTransform(LPDIRECT3DDEVICE7 iface,
501                                                    D3DTRANSFORMSTATETYPE dtstTransformStateType,
502                                                    LPD3DMATRIX lpD3DMatrix)
503 {
504     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
505     LPD3DMATRIX mat;
506     DWORD matrix_changed = 0x00000000;
507
508     TRACE("(%p/%p)->(%08x,%p)\n", This, iface, dtstTransformStateType, lpD3DMatrix);
509     
510     if (TRACE_ON(ddraw)) {
511         TRACE(" Multiplying by :\n"); dump_D3DMATRIX(lpD3DMatrix);
512     }
513     
514     switch (dtstTransformStateType) {
515         case D3DTRANSFORMSTATE_WORLD: {
516             if (TRACE_ON(ddraw)) {
517                 TRACE(" Resulting D3DTRANSFORMSTATE_WORLD matrix is :\n");
518             }
519             mat = This->world_mat;
520             matrix_changed = WORLDMAT_CHANGED;
521         } break;
522
523         case D3DTRANSFORMSTATE_VIEW: {
524             if (TRACE_ON(ddraw)) {
525                 TRACE(" Resulting D3DTRANSFORMSTATE_VIEW matrix is :\n");
526             }
527             mat = This->view_mat;
528             matrix_changed = VIEWMAT_CHANGED;
529         } break;
530
531         case D3DTRANSFORMSTATE_PROJECTION: {
532             if (TRACE_ON(ddraw)) {
533                 TRACE(" Resulting D3DTRANSFORMSTATE_PROJECTION matrix is :\n");
534             }
535             mat = This->proj_mat;
536             matrix_changed = PROJMAT_CHANGED;
537         } break;
538
539         case D3DTRANSFORMSTATE_TEXTURE0:
540         case D3DTRANSFORMSTATE_TEXTURE1:
541         case D3DTRANSFORMSTATE_TEXTURE2:
542         case D3DTRANSFORMSTATE_TEXTURE3:
543         case D3DTRANSFORMSTATE_TEXTURE4:
544         case D3DTRANSFORMSTATE_TEXTURE5:
545         case D3DTRANSFORMSTATE_TEXTURE6:
546         case D3DTRANSFORMSTATE_TEXTURE7: {
547             DWORD mat_num = dtstTransformStateType - D3DTRANSFORMSTATE_TEXTURE0;
548             if (TRACE_ON(ddraw)) {
549                 TRACE(" Resulting D3DTRANSFORMSTATE_TEXTURE%ld matrix is :\n", mat_num);
550             }
551             mat = This->tex_mat[mat_num];
552             matrix_changed = TEXMAT0_CHANGED << mat_num;
553         } break;
554
555         default:
556             ERR("Unknown transform type %08x !!!\n", dtstTransformStateType);
557             return DDERR_INVALIDPARAMS;
558     }
559
560     multiply_matrix(mat,mat,lpD3DMatrix);
561     
562     if (TRACE_ON(ddraw)) {
563         dump_D3DMATRIX(mat);
564     }
565     
566     if (matrix_changed != 0x00000000) This->matrices_updated(This, matrix_changed);
567     
568     return DD_OK;
569 }
570
571 HRESULT WINAPI
572 Main_IDirect3DDeviceImpl_7_GetViewport(LPDIRECT3DDEVICE7 iface,
573                                        LPD3DVIEWPORT7 lpData)
574 {
575     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
576     TRACE("(%p/%p)->(%p)\n", This, iface, lpData);
577
578     *lpData = This->active_viewport;
579
580     if (TRACE_ON(ddraw)) {
581         TRACE(" returning viewport : \n");
582         TRACE("    - dwX = %ld   dwY = %ld\n",
583               lpData->dwX, lpData->dwY);
584         TRACE("    - dwWidth = %ld   dwHeight = %ld\n",
585               lpData->dwWidth, lpData->dwHeight);
586         TRACE("    - dvMinZ = %f   dvMaxZ = %f\n",
587               lpData->dvMinZ, lpData->dvMaxZ);
588     }
589
590     return DD_OK;
591 }
592
593 HRESULT WINAPI
594 Main_IDirect3DDeviceImpl_7_SetMaterial(LPDIRECT3DDEVICE7 iface,
595                                        LPD3DMATERIAL7 lpMat)
596 {
597     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
598     FIXME("(%p/%p)->(%p): stub!\n", This, iface, lpMat);
599     return DD_OK;
600 }
601
602 HRESULT WINAPI
603 Main_IDirect3DDeviceImpl_7_GetMaterial(LPDIRECT3DDEVICE7 iface,
604                                        LPD3DMATERIAL7 lpMat)
605 {
606     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
607     TRACE("(%p/%p)->(%p)\n", This, iface, lpMat);
608     
609     *lpMat = This->current_material;
610
611     if (TRACE_ON(ddraw)) {
612         TRACE(" returning material : \n");
613         dump_D3DMATERIAL7(lpMat);
614     }
615
616     return DD_OK;
617 }
618
619 HRESULT WINAPI
620 Main_IDirect3DDeviceImpl_7_SetLight(LPDIRECT3DDEVICE7 iface,
621                                     DWORD dwLightIndex,
622                                     LPD3DLIGHT7 lpLight)
623 {
624     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
625     FIXME("(%p/%p)->(%08lx,%p): stub!\n", This, iface, dwLightIndex, lpLight);
626     return DD_OK;
627 }
628
629 HRESULT WINAPI
630 Main_IDirect3DDeviceImpl_7_GetLight(LPDIRECT3DDEVICE7 iface,
631                                     DWORD dwLightIndex,
632                                     LPD3DLIGHT7 lpLight)
633 {
634     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
635     TRACE("(%p/%p)->(%08lx,%p)\n", This, iface, dwLightIndex, lpLight);
636
637     if (dwLightIndex > MAX_LIGHTS) return DDERR_INVALIDPARAMS;
638     *lpLight = This->light_parameters[dwLightIndex];
639
640     if (TRACE_ON(ddraw)) {
641         TRACE(" returning light : \n");
642         dump_D3DLIGHT7(lpLight);
643     }
644
645     return DD_OK;
646 }
647
648 HRESULT WINAPI
649 Main_IDirect3DDeviceImpl_7_3T_2T_SetRenderState(LPDIRECT3DDEVICE7 iface,
650                                                 D3DRENDERSTATETYPE dwRenderStateType,
651                                                 DWORD dwRenderState)
652 {
653     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
654     FIXME("(%p/%p)->(%08x,%08lx): stub!\n", This, iface, dwRenderStateType, dwRenderState);
655     return DD_OK;
656 }
657
658 HRESULT WINAPI
659 Main_IDirect3DDeviceImpl_7_3T_2T_GetRenderState(LPDIRECT3DDEVICE7 iface,
660                                                 D3DRENDERSTATETYPE dwRenderStateType,
661                                                 LPDWORD lpdwRenderState)
662 {
663     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
664     FIXME("(%p/%p)->(%08x,%p): stub!\n", This, iface, dwRenderStateType, lpdwRenderState);
665     return DD_OK;
666 }
667
668 HRESULT WINAPI
669 Main_IDirect3DDeviceImpl_7_BeginStateBlock(LPDIRECT3DDEVICE7 iface)
670 {
671     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
672     FIXME("(%p/%p)->(): stub!\n", This, iface);
673     return DD_OK;
674 }
675
676 HRESULT WINAPI
677 Main_IDirect3DDeviceImpl_7_EndStateBlock(LPDIRECT3DDEVICE7 iface,
678                                          LPDWORD lpdwBlockHandle)
679 {
680     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
681     FIXME("(%p/%p)->(%p): stub!\n", This, iface, lpdwBlockHandle);
682     return DD_OK;
683 }
684
685 HRESULT WINAPI
686 Main_IDirect3DDeviceImpl_7_PreLoad(LPDIRECT3DDEVICE7 iface,
687                                    LPDIRECTDRAWSURFACE7 lpddsTexture)
688 {
689     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
690     FIXME("(%p/%p)->(%p): stub!\n", This, iface, lpddsTexture);
691     return DD_OK;
692 }
693
694 HRESULT WINAPI
695 Main_IDirect3DDeviceImpl_7_3T_DrawPrimitive(LPDIRECT3DDEVICE7 iface,
696                                             D3DPRIMITIVETYPE d3dptPrimitiveType,
697                                             DWORD d3dvtVertexType,
698                                             LPVOID lpvVertices,
699                                             DWORD dwVertexCount,
700                                             DWORD dwFlags)
701 {
702     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
703     FIXME("(%p/%p)->(%08x,%08lx,%p,%08lx,%08lx): stub!\n", This, iface, d3dptPrimitiveType, d3dvtVertexType, lpvVertices, dwVertexCount, dwFlags);
704     return DD_OK;
705 }
706
707 HRESULT WINAPI
708 Main_IDirect3DDeviceImpl_7_3T_DrawIndexedPrimitive(LPDIRECT3DDEVICE7 iface,
709                                                    D3DPRIMITIVETYPE d3dptPrimitiveType,
710                                                    DWORD d3dvtVertexType,
711                                                    LPVOID lpvVertices,
712                                                    DWORD dwVertexCount,
713                                                    LPWORD dwIndices,
714                                                    DWORD dwIndexCount,
715                                                    DWORD dwFlags)
716 {
717     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
718     FIXME("(%p/%p)->(%08x,%08lx,%p,%08lx,%p,%08lx,%08lx): stub!\n", This, iface, d3dptPrimitiveType, d3dvtVertexType, lpvVertices, dwVertexCount, dwIndices, dwIndexCount, dwFlags);
719     return DD_OK;
720 }
721
722 HRESULT WINAPI
723 Main_IDirect3DDeviceImpl_7_3T_2T_SetClipStatus(LPDIRECT3DDEVICE7 iface,
724                                                LPD3DCLIPSTATUS lpD3DClipStatus)
725 {
726     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
727     FIXME("(%p/%p)->(%p): stub!\n", This, iface, lpD3DClipStatus);
728     return DD_OK;
729 }
730
731 HRESULT WINAPI
732 Main_IDirect3DDeviceImpl_7_3T_2T_GetClipStatus(LPDIRECT3DDEVICE7 iface,
733                                                LPD3DCLIPSTATUS lpD3DClipStatus)
734 {
735     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
736     FIXME("(%p/%p)->(%p): stub!\n", This, iface, lpD3DClipStatus);
737     return DD_OK;
738 }
739
740 HRESULT WINAPI
741 Main_IDirect3DDeviceImpl_7_3T_DrawPrimitiveStrided(LPDIRECT3DDEVICE7 iface,
742                                                    D3DPRIMITIVETYPE d3dptPrimitiveType,
743                                                    DWORD dwVertexType,
744                                                    LPD3DDRAWPRIMITIVESTRIDEDDATA lpD3DDrawPrimStrideData,
745                                                    DWORD dwVertexCount,
746                                                    DWORD dwFlags)
747 {
748     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
749     FIXME("(%p/%p)->(%08x,%08lx,%p,%08lx,%08lx): stub!\n", This, iface, d3dptPrimitiveType, dwVertexType, lpD3DDrawPrimStrideData, dwVertexCount, dwFlags);
750     return DD_OK;
751 }
752
753 HRESULT WINAPI
754 Main_IDirect3DDeviceImpl_7_3T_DrawIndexedPrimitiveStrided(LPDIRECT3DDEVICE7 iface,
755                                                           D3DPRIMITIVETYPE d3dptPrimitiveType,
756                                                           DWORD dwVertexType,
757                                                           LPD3DDRAWPRIMITIVESTRIDEDDATA lpD3DDrawPrimStrideData,
758                                                           DWORD dwVertexCount,
759                                                           LPWORD lpIndex,
760                                                           DWORD dwIndexCount,
761                                                           DWORD dwFlags)
762 {
763     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
764     FIXME("(%p/%p)->(%08x,%08lx,%p,%08lx,%p,%08lx,%08lx): stub!\n", This, iface, d3dptPrimitiveType, dwVertexType, lpD3DDrawPrimStrideData, dwVertexCount, lpIndex, dwIndexCount, dwFlags);
765     return DD_OK;
766 }
767
768 HRESULT WINAPI
769 Main_IDirect3DDeviceImpl_7_3T_DrawPrimitiveVB(LPDIRECT3DDEVICE7 iface,
770                                               D3DPRIMITIVETYPE d3dptPrimitiveType,
771                                               LPDIRECT3DVERTEXBUFFER7 lpD3DVertexBuf,
772                                               DWORD dwStartVertex,
773                                               DWORD dwNumVertices,
774                                               DWORD dwFlags)
775 {
776     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
777     FIXME("(%p/%p)->(%08x,%p,%08lx,%08lx,%08lx): stub!\n", This, iface, d3dptPrimitiveType, lpD3DVertexBuf, dwStartVertex, dwNumVertices, dwFlags);
778     return DD_OK;
779 }
780
781 HRESULT WINAPI
782 Main_IDirect3DDeviceImpl_7_3T_DrawIndexedPrimitiveVB(LPDIRECT3DDEVICE7 iface,
783                                                      D3DPRIMITIVETYPE d3dptPrimitiveType,
784                                                      LPDIRECT3DVERTEXBUFFER7 lpD3DVertexBuf,
785                                                      DWORD dwStartVertex,
786                                                      DWORD dwNumVertices,
787                                                      LPWORD lpwIndices,
788                                                      DWORD dwIndexCount,
789                                                      DWORD dwFlags)
790 {
791     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
792     FIXME("(%p/%p)->(%08x,%p,%08lx,%08lx,%p,%08lx,%08lx): stub!\n", This, iface, d3dptPrimitiveType, lpD3DVertexBuf, dwStartVertex, dwNumVertices, lpwIndices, dwIndexCount, dwFlags);
793     return DD_OK;
794 }
795
796 HRESULT WINAPI
797 Main_IDirect3DDeviceImpl_7_3T_ComputeSphereVisibility(LPDIRECT3DDEVICE7 iface,
798                                                       LPD3DVECTOR lpCenters,
799                                                       LPD3DVALUE lpRadii,
800                                                       DWORD dwNumSpheres,
801                                                       DWORD dwFlags,
802                                                       LPDWORD lpdwReturnValues)
803 {
804     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
805     FIXME("(%p/%p)->(%p,%p,%08lx,%08lx,%p): stub!\n", This, iface, lpCenters, lpRadii, dwNumSpheres, dwFlags, lpdwReturnValues);
806     return DD_OK;
807 }
808
809 HRESULT WINAPI
810 Main_IDirect3DDeviceImpl_7_3T_GetTexture(LPDIRECT3DDEVICE7 iface,
811                                          DWORD dwStage,
812                                          LPDIRECTDRAWSURFACE7* lpTexture)
813 {
814     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
815     TRACE("(%p/%p)->(%08lx,%p)\n", This, iface, dwStage, lpTexture);
816
817     if (This->current_texture[dwStage] != NULL) {
818         *lpTexture = ICOM_INTERFACE(This->current_texture[dwStage], IDirectDrawSurface7);
819         IDirectDrawSurface7_AddRef(*lpTexture);
820     } else {
821         *lpTexture = NULL;
822     }
823
824     TRACE(" returning interface at %p (for implementation at %p).\n", *lpTexture, This->current_texture[dwStage]);
825
826     return DD_OK;
827 }
828
829 HRESULT WINAPI
830 Main_IDirect3DDeviceImpl_7_3T_SetTexture(LPDIRECT3DDEVICE7 iface,
831                                          DWORD dwStage,
832                                          LPDIRECTDRAWSURFACE7 lpTexture)
833 {
834     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
835     FIXME("(%p/%p)->(%08lx,%p): stub!\n", This, iface, dwStage, lpTexture);
836     return DD_OK;
837 }
838
839 HRESULT WINAPI
840 Main_IDirect3DDeviceImpl_7_3T_GetTextureStageState(LPDIRECT3DDEVICE7 iface,
841                                                    DWORD dwStage,
842                                                    D3DTEXTURESTAGESTATETYPE d3dTexStageStateType,
843                                                    LPDWORD lpdwState)
844 {
845     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
846     TRACE("(%p/%p)->(%08lx,%08x,%p)\n", This, iface, dwStage, d3dTexStageStateType, lpdwState);
847     if (lpdwState && (dwStage < 8) && d3dTexStageStateType && (d3dTexStageStateType <= HIGHEST_TEXTURE_STAGE_STATE) ) {
848         *lpdwState = This->state_block.texture_stage_state[dwStage][d3dTexStageStateType-1];
849         return DD_OK;
850     }
851     return DDERR_INVALIDPARAMS;
852 }
853
854 HRESULT WINAPI
855 Main_IDirect3DDeviceImpl_7_3T_SetTextureStageState(LPDIRECT3DDEVICE7 iface,
856                                                    DWORD dwStage,
857                                                    D3DTEXTURESTAGESTATETYPE d3dTexStageStateType,
858                                                    DWORD dwState)
859 {
860     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
861     FIXME("(%p/%p)->(%08lx,%08x,%08lx): stub!\n", This, iface, dwStage, d3dTexStageStateType, dwState);
862     return DD_OK;
863 }
864
865 HRESULT WINAPI
866 Main_IDirect3DDeviceImpl_7_3T_ValidateDevice(LPDIRECT3DDEVICE7 iface,
867                                              LPDWORD lpdwPasses)
868 {
869     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
870     FIXME("(%p/%p)->(%p): semi-stub!\n", This, iface, lpdwPasses);
871
872     /* For the moment, we have a VERY good hardware which does everything in one pass :-) */
873     *lpdwPasses = 1;
874
875     return DD_OK;
876 }
877
878 HRESULT WINAPI
879 Main_IDirect3DDeviceImpl_7_ApplyStateBlock(LPDIRECT3DDEVICE7 iface,
880                                            DWORD dwBlockHandle)
881 {
882     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
883     FIXME("(%p/%p)->(%08lx): stub!\n", This, iface, dwBlockHandle);
884     return DD_OK;
885 }
886
887 HRESULT WINAPI
888 Main_IDirect3DDeviceImpl_7_CaptureStateBlock(LPDIRECT3DDEVICE7 iface,
889                                              DWORD dwBlockHandle)
890 {
891     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
892     FIXME("(%p/%p)->(%08lx): stub!\n", This, iface, dwBlockHandle);
893     return DD_OK;
894 }
895
896 HRESULT WINAPI
897 Main_IDirect3DDeviceImpl_7_DeleteStateBlock(LPDIRECT3DDEVICE7 iface,
898                                             DWORD dwBlockHandle)
899 {
900     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
901     FIXME("(%p/%p)->(%08lx): stub!\n", This, iface, dwBlockHandle);
902     return DD_OK;
903 }
904
905 HRESULT WINAPI
906 Main_IDirect3DDeviceImpl_7_CreateStateBlock(LPDIRECT3DDEVICE7 iface,
907                                             D3DSTATEBLOCKTYPE d3dsbType,
908                                             LPDWORD lpdwBlockHandle)
909 {
910     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
911     FIXME("(%p/%p)->(%08x,%p): stub!\n", This, iface, d3dsbType, lpdwBlockHandle);
912     return DD_OK;
913 }
914
915 HRESULT WINAPI
916 Main_IDirect3DDeviceImpl_7_Load(LPDIRECT3DDEVICE7 iface,
917                                 LPDIRECTDRAWSURFACE7 lpDestTex,
918                                 LPPOINT lpDestPoint,
919                                 LPDIRECTDRAWSURFACE7 lpSrcTex,
920                                 LPRECT lprcSrcRect,
921                                 DWORD dwFlags)
922 {
923     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
924     FIXME("(%p/%p)->(%p,%p,%p,%p,%08lx): Partially Implemented!\n", This, iface, lpDestTex, lpDestPoint, lpSrcTex, lprcSrcRect, dwFlags);
925     IDirect3DTexture2_Load(COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7, IDirect3DTexture2, lpDestTex),
926                            COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7, IDirect3DTexture2, lpSrcTex));
927     return DD_OK;
928 }
929
930 HRESULT WINAPI
931 Main_IDirect3DDeviceImpl_7_LightEnable(LPDIRECT3DDEVICE7 iface,
932                                        DWORD dwLightIndex,
933                                        BOOL bEnable)
934 {
935     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
936     FIXME("(%p/%p)->(%08lx,%d): stub!\n", This, iface, dwLightIndex, bEnable);
937     return DD_OK;
938 }
939
940 HRESULT WINAPI
941 Main_IDirect3DDeviceImpl_7_GetLightEnable(LPDIRECT3DDEVICE7 iface,
942                                           DWORD dwLightIndex,
943                                           BOOL* pbEnable)
944 {
945     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
946     TRACE("(%p/%p)->(%08lx,%p)\n", This, iface, dwLightIndex, pbEnable);
947
948     if (dwLightIndex > MAX_LIGHTS) *pbEnable = 0;
949     else *pbEnable = ((0x00000001 << dwLightIndex) & This->active_lights) != 0;
950     
951     TRACE(" returning %d.\n", *pbEnable);
952
953     return DD_OK;
954 }
955
956 HRESULT WINAPI
957 Main_IDirect3DDeviceImpl_7_SetClipPlane(LPDIRECT3DDEVICE7 iface,
958                                         DWORD dwIndex,
959                                         D3DVALUE* pPlaneEquation)
960 {
961     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
962     FIXME("(%p/%p)->(%08lx,%p): stub!\n", This, iface, dwIndex, pPlaneEquation);
963     return DD_OK;
964 }
965
966 HRESULT  WINAPI  
967 Main_IDirect3DDeviceImpl_7_GetClipPlane(LPDIRECT3DDEVICE7 iface, DWORD dwIndex, D3DVALUE* pPlaneEquation)
968 {
969     ICOM_THIS(IDirect3DDeviceImpl,iface);
970
971     TRACE("(%p)->(%ld,%p)\n", This, dwIndex, pPlaneEquation);
972
973     if (dwIndex>=This->max_clipping_planes) {
974         return DDERR_INVALIDPARAMS;
975     }
976
977     memcpy( pPlaneEquation, This->clipping_planes[dwIndex].plane, sizeof(D3DVALUE[4]));
978
979     return D3D_OK;
980 }
981
982 HRESULT WINAPI
983 Main_IDirect3DDeviceImpl_7_GetInfo(LPDIRECT3DDEVICE7 iface,
984                                    DWORD dwDevInfoID,
985                                    LPVOID pDevInfoStruct,
986                                    DWORD dwSize)
987 {
988     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
989     TRACE("(%p/%p)->(%08lx,%p,%08lx)\n", This, iface, dwDevInfoID, pDevInfoStruct, dwSize);
990
991     if (TRACE_ON(ddraw)) {
992         TRACE(" info requested : ");
993         switch (dwDevInfoID) {
994             case D3DDEVINFOID_TEXTUREMANAGER: TRACE("D3DDEVINFOID_TEXTUREMANAGER\n"); break;
995             case D3DDEVINFOID_D3DTEXTUREMANAGER: TRACE("D3DDEVINFOID_D3DTEXTUREMANAGER\n"); break;
996             case D3DDEVINFOID_TEXTURING: TRACE("D3DDEVINFOID_TEXTURING\n"); break;
997             default: ERR(" invalid flag !!!\n"); return DDERR_INVALIDPARAMS;
998         }
999     }
1000
1001     return S_FALSE; /* According to MSDN, this is valid for a non-debug driver */
1002 }
1003
1004 HRESULT WINAPI
1005 Main_IDirect3DDeviceImpl_3_2T_1T_GetCaps(LPDIRECT3DDEVICE3 iface,
1006                                          LPD3DDEVICEDESC lpD3DHWDevDesc,
1007                                          LPD3DDEVICEDESC lpD3DHELDevDesc)
1008 {
1009     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1010     FIXME("(%p/%p)->(%p,%p): stub!\n", This, iface, lpD3DHWDevDesc, lpD3DHELDevDesc);
1011     return DD_OK;
1012 }
1013
1014 HRESULT WINAPI
1015 Main_IDirect3DDeviceImpl_3_2T_1T_GetStats(LPDIRECT3DDEVICE3 iface,
1016                                           LPD3DSTATS lpD3DStats)
1017 {
1018     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1019     FIXME("(%p/%p)->(%p): stub!\n", This, iface, lpD3DStats);
1020     return DD_OK;
1021 }
1022
1023 HRESULT WINAPI
1024 Main_IDirect3DDeviceImpl_3_2T_1T_AddViewport(LPDIRECT3DDEVICE3 iface,
1025                                              LPDIRECT3DVIEWPORT3 lpDirect3DViewport3)
1026 {
1027     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1028     IDirect3DViewportImpl *lpDirect3DViewportImpl = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, lpDirect3DViewport3);
1029     
1030     TRACE("(%p/%p)->(%p)\n", This, iface, lpDirect3DViewport3);
1031
1032     lpDirect3DViewportImpl->next = This->viewport_list;
1033     This->viewport_list = lpDirect3DViewportImpl;
1034     
1035     return DD_OK;
1036 }
1037
1038 HRESULT WINAPI
1039 Main_IDirect3DDeviceImpl_3_2T_1T_DeleteViewport(LPDIRECT3DDEVICE3 iface,
1040                                                 LPDIRECT3DVIEWPORT3 lpDirect3DViewport3)
1041 {
1042     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1043     IDirect3DViewportImpl *lpDirect3DViewportImpl = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, lpDirect3DViewport3);
1044     IDirect3DViewportImpl *cur_viewport, *prev_viewport = NULL;
1045   
1046     TRACE("(%p/%p)->(%p)\n", This, iface, lpDirect3DViewport3);
1047
1048     cur_viewport = This->viewport_list;
1049     while (cur_viewport != NULL) {
1050         if (cur_viewport == lpDirect3DViewportImpl) {
1051             if (prev_viewport == NULL) This->viewport_list = cur_viewport->next;
1052             else prev_viewport->next = cur_viewport->next;
1053             /* TODO : add desactivate of the viewport and all associated lights... */
1054             return DD_OK;
1055         }
1056         prev_viewport = cur_viewport;
1057         cur_viewport = cur_viewport->next;
1058     }
1059     
1060     return DDERR_INVALIDPARAMS;
1061 }
1062
1063 HRESULT WINAPI
1064 Main_IDirect3DDeviceImpl_3_2T_1T_NextViewport(LPDIRECT3DDEVICE3 iface,
1065                                               LPDIRECT3DVIEWPORT3 lpDirect3DViewport3,
1066                                               LPDIRECT3DVIEWPORT3* lplpDirect3DViewport3,
1067                                               DWORD dwFlags)
1068 {
1069     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1070     IDirect3DViewportImpl *res = NULL;
1071
1072     TRACE("(%p/%p)->(%p,%p,%08lx)\n", This, iface, lpDirect3DViewport3, lplpDirect3DViewport3, dwFlags);
1073     
1074     switch (dwFlags) {
1075         case D3DNEXT_NEXT: {
1076             IDirect3DViewportImpl *lpDirect3DViewportImpl = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, lpDirect3DViewport3);
1077             res = lpDirect3DViewportImpl->next;
1078         } break;
1079         case D3DNEXT_HEAD: {
1080             res = This->viewport_list;
1081         } break;
1082         case D3DNEXT_TAIL: {
1083             IDirect3DViewportImpl *cur_viewport = This->viewport_list;
1084             if (cur_viewport != NULL) {
1085                 while (cur_viewport->next != NULL) cur_viewport = cur_viewport->next;
1086             }
1087             res = cur_viewport;
1088         } break;
1089         default:
1090             *lplpDirect3DViewport3 = NULL;
1091             return DDERR_INVALIDPARAMS;
1092     }
1093     *lplpDirect3DViewport3 = ICOM_INTERFACE(res, IDirect3DViewport3);
1094     return DD_OK;
1095 }
1096
1097 HRESULT WINAPI
1098 Main_IDirect3DDeviceImpl_3_2T_SetCurrentViewport(LPDIRECT3DDEVICE3 iface,
1099                                                  LPDIRECT3DVIEWPORT3 lpDirect3DViewport3)
1100 {
1101     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1102     TRACE("(%p/%p)->(%p)\n", This, iface, lpDirect3DViewport3);
1103
1104     /* Do nothing if the specified viewport is the same as the current one */
1105     if (This->current_viewport == ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, lpDirect3DViewport3))
1106       return DD_OK;
1107     
1108     /* Should check if the viewport was added or not */
1109
1110     /* Release previous viewport and AddRef the new one */
1111     if (This->current_viewport)
1112       IDirect3DViewport3_Release(ICOM_INTERFACE(This->current_viewport, IDirect3DViewport3));
1113     IDirect3DViewport3_AddRef(lpDirect3DViewport3);
1114     
1115     /* Set this viewport as the current viewport */
1116     This->current_viewport = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, lpDirect3DViewport3);
1117
1118     /* Activate this viewport */
1119     This->current_viewport->active_device = This;
1120     This->current_viewport->activate(This->current_viewport);
1121
1122     return DD_OK;
1123 }
1124
1125 HRESULT WINAPI
1126 Main_IDirect3DDeviceImpl_3_2T_GetCurrentViewport(LPDIRECT3DDEVICE3 iface,
1127                                                  LPDIRECT3DVIEWPORT3* lplpDirect3DViewport3)
1128 {
1129     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1130     TRACE("(%p/%p)->(%p)\n", This, iface, lplpDirect3DViewport3);
1131
1132     *lplpDirect3DViewport3 = ICOM_INTERFACE(This->current_viewport, IDirect3DViewport3);
1133
1134     /* AddRef the returned viewport */
1135     IDirect3DViewport3_AddRef(*lplpDirect3DViewport3);
1136     
1137     TRACE(" returning interface %p\n", *lplpDirect3DViewport3);
1138     
1139     return DD_OK;
1140 }
1141
1142 HRESULT WINAPI
1143 Main_IDirect3DDeviceImpl_3_Begin(LPDIRECT3DDEVICE3 iface,
1144                                  D3DPRIMITIVETYPE d3dptPrimitiveType,
1145                                  DWORD dwVertexTypeDesc,
1146                                  DWORD dwFlags)
1147 {
1148     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1149     FIXME("(%p/%p)->(%08x,%08lx,%08lx): stub!\n", This, iface, d3dptPrimitiveType, dwVertexTypeDesc, dwFlags);
1150     return DD_OK;
1151 }
1152
1153 HRESULT WINAPI
1154 Main_IDirect3DDeviceImpl_3_BeginIndexed(LPDIRECT3DDEVICE3 iface,
1155                                         D3DPRIMITIVETYPE d3dptPrimitiveType,
1156                                         DWORD d3dvtVertexType,
1157                                         LPVOID lpvVertices,
1158                                         DWORD dwNumVertices,
1159                                         DWORD dwFlags)
1160 {
1161     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1162     FIXME("(%p/%p)->(%08x,%08lx,%p,%08lx,%08lx): stub!\n", This, iface, d3dptPrimitiveType, d3dvtVertexType, lpvVertices, dwNumVertices, dwFlags);
1163     return DD_OK;
1164 }
1165
1166 HRESULT WINAPI
1167 Main_IDirect3DDeviceImpl_3_2T_Vertex(LPDIRECT3DDEVICE3 iface,
1168                                      LPVOID lpVertexType)
1169 {
1170     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1171     FIXME("(%p/%p)->(%p): stub!\n", This, iface, lpVertexType);
1172     return DD_OK;
1173 }
1174
1175 HRESULT WINAPI
1176 Main_IDirect3DDeviceImpl_3_2T_Index(LPDIRECT3DDEVICE3 iface,
1177                                     WORD wVertexIndex)
1178 {
1179     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1180     FIXME("(%p/%p)->(%04x): stub!\n", This, iface, wVertexIndex);
1181     return DD_OK;
1182 }
1183
1184 HRESULT WINAPI
1185 Main_IDirect3DDeviceImpl_3_2T_End(LPDIRECT3DDEVICE3 iface,
1186                                   DWORD dwFlags)
1187 {
1188     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1189     FIXME("(%p/%p)->(%08lx): stub!\n", This, iface, dwFlags);
1190     return DD_OK;
1191 }
1192
1193 HRESULT WINAPI
1194 Main_IDirect3DDeviceImpl_3_2T_GetLightState(LPDIRECT3DDEVICE3 iface,
1195                                             D3DLIGHTSTATETYPE dwLightStateType,
1196                                             LPDWORD lpdwLightState)
1197 {
1198     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1199     FIXME("(%p/%p)->(%08x,%p): stub !\n", This, iface, dwLightStateType, lpdwLightState);
1200     return DD_OK;
1201 }
1202
1203 HRESULT WINAPI
1204 Main_IDirect3DDeviceImpl_3_2T_SetLightState(LPDIRECT3DDEVICE3 iface,
1205                                             D3DLIGHTSTATETYPE dwLightStateType,
1206                                             DWORD dwLightState)
1207 {
1208     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1209     FIXME("(%p/%p)->(%08x,%08lx): stub!\n", This, iface, dwLightStateType, dwLightState);
1210     return DD_OK;
1211 }
1212
1213 HRESULT WINAPI
1214 Main_IDirect3DDeviceImpl_2_1T_SwapTextureHandles(LPDIRECT3DDEVICE2 iface,
1215                                                  LPDIRECT3DTEXTURE2 lpD3DTex1,
1216                                                  LPDIRECT3DTEXTURE2 lpD3DTex2)
1217 {
1218     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1219     IDirectDrawSurfaceImpl tmp,*surf1,*surf2;
1220     TRACE("(%p/%p)->(%p,%p):\n", This, iface, lpD3DTex1, lpD3DTex2);
1221
1222     surf1 = ICOM_OBJECT(IDirectDrawSurfaceImpl,IDirect3DTexture2,lpD3DTex1);
1223     surf2 = ICOM_OBJECT(IDirectDrawSurfaceImpl,IDirect3DTexture2,lpD3DTex2);
1224     tmp = *surf1;
1225     *surf1 = *surf2;
1226     *surf2 = tmp;
1227     
1228     return DD_OK;
1229 }
1230
1231 HRESULT WINAPI
1232 Main_IDirect3DDeviceImpl_2_NextViewport(LPDIRECT3DDEVICE2 iface,
1233                                         LPDIRECT3DVIEWPORT2 lpDirect3DViewport2,
1234                                         LPDIRECT3DVIEWPORT2* lplpDirect3DViewport2,
1235                                         DWORD dwFlags)
1236 {
1237     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1238     FIXME("(%p/%p)->(%p,%p,%08lx): stub!\n", This, iface, lpDirect3DViewport2, lplpDirect3DViewport2, dwFlags);
1239     return DD_OK;
1240 }
1241
1242 HRESULT WINAPI
1243 Main_IDirect3DDeviceImpl_2_1T_EnumTextureFormats(LPDIRECT3DDEVICE2 iface,
1244                                                  LPD3DENUMTEXTUREFORMATSCALLBACK lpD3DEnumTextureProc,
1245                                                  LPVOID lpArg)
1246 {
1247     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1248     FIXME("(%p/%p)->(%p,%p): stub!\n", This, iface, lpD3DEnumTextureProc, lpArg);
1249     return DD_OK;
1250 }
1251
1252 HRESULT WINAPI
1253 Main_IDirect3DDeviceImpl_2_Begin(LPDIRECT3DDEVICE2 iface,
1254                                  D3DPRIMITIVETYPE d3dpt,
1255                                  D3DVERTEXTYPE dwVertexTypeDesc,
1256                                  DWORD dwFlags)
1257 {
1258     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1259     FIXME("(%p/%p)->(%08x,%08x,%08lx): stub!\n", This, iface, d3dpt, dwVertexTypeDesc, dwFlags);
1260     return DD_OK;
1261 }
1262
1263 HRESULT WINAPI
1264 Main_IDirect3DDeviceImpl_2_BeginIndexed(LPDIRECT3DDEVICE2 iface,
1265                                         D3DPRIMITIVETYPE d3dptPrimitiveType,
1266                                         D3DVERTEXTYPE d3dvtVertexType,
1267                                         LPVOID lpvVertices,
1268                                         DWORD dwNumVertices,
1269                                         DWORD dwFlags)
1270 {
1271     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1272     FIXME("(%p/%p)->(%08x,%08x,%p,%08lx,%08lx): stub!\n", This, iface, d3dptPrimitiveType, d3dvtVertexType, lpvVertices, dwNumVertices, dwFlags);
1273     return DD_OK;
1274 }
1275
1276 HRESULT WINAPI
1277 Main_IDirect3DDeviceImpl_2_DrawPrimitive(LPDIRECT3DDEVICE2 iface,
1278                                          D3DPRIMITIVETYPE d3dptPrimitiveType,
1279                                          D3DVERTEXTYPE d3dvtVertexType,
1280                                          LPVOID lpvVertices,
1281                                          DWORD dwVertexCount,
1282                                          DWORD dwFlags)
1283 {
1284     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1285     FIXME("(%p/%p)->(%08x,%08x,%p,%08lx,%08lx): stub!\n", This, iface, d3dptPrimitiveType, d3dvtVertexType, lpvVertices, dwVertexCount, dwFlags);
1286     return DD_OK;
1287 }
1288
1289 HRESULT WINAPI
1290 Main_IDirect3DDeviceImpl_2_DrawIndexedPrimitive(LPDIRECT3DDEVICE2 iface,
1291                                                 D3DPRIMITIVETYPE d3dptPrimitiveType,
1292                                                 D3DVERTEXTYPE d3dvtVertexType,
1293                                                 LPVOID lpvVertices,
1294                                                 DWORD dwVertexCount,
1295                                                 LPWORD dwIndices,
1296                                                 DWORD dwIndexCount,
1297                                                 DWORD dwFlags)
1298 {
1299     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1300     FIXME("(%p/%p)->(%08x,%08x,%p,%08lx,%p,%08lx,%08lx): stub!\n", This, iface, d3dptPrimitiveType, d3dvtVertexType, lpvVertices, dwVertexCount, dwIndices, dwIndexCount, dwFlags);
1301     return DD_OK;
1302 }
1303
1304 HRESULT WINAPI
1305 Main_IDirect3DDeviceImpl_1_Initialize(LPDIRECT3DDEVICE iface,
1306                                       LPDIRECT3D lpDirect3D,
1307                                       LPGUID lpGUID,
1308                                       LPD3DDEVICEDESC lpD3DDVDesc)
1309 {
1310     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1311     FIXME("(%p/%p)->(%p,%p,%p): stub!\n", This, iface, lpDirect3D, lpGUID, lpD3DDVDesc);
1312     return DD_OK;
1313 }
1314
1315 HRESULT WINAPI
1316 Main_IDirect3DDeviceImpl_1_CreateExecuteBuffer(LPDIRECT3DDEVICE iface,
1317                                                LPD3DEXECUTEBUFFERDESC lpDesc,
1318                                                LPDIRECT3DEXECUTEBUFFER* lplpDirect3DExecuteBuffer,
1319                                                IUnknown* pUnkOuter)
1320 {
1321     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1322     FIXME("(%p/%p)->(%p,%p,%p): stub!\n", This, iface, lpDesc, lplpDirect3DExecuteBuffer, pUnkOuter);
1323     return DD_OK;
1324 }
1325
1326 HRESULT WINAPI
1327 Main_IDirect3DDeviceImpl_1_Execute(LPDIRECT3DDEVICE iface,
1328                                    LPDIRECT3DEXECUTEBUFFER lpDirect3DExecuteBuffer,
1329                                    LPDIRECT3DVIEWPORT lpDirect3DViewport,
1330                                    DWORD dwFlags)
1331 {
1332     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1333     IDirect3DExecuteBufferImpl *lpDirect3DExecuteBufferImpl = ICOM_OBJECT(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, lpDirect3DExecuteBuffer);
1334     IDirect3DViewportImpl *lpDirect3DViewportImpl = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, lpDirect3DViewport);
1335     
1336     TRACE("(%p/%p)->(%p,%p,%08lx)\n", This, iface, lpDirect3DExecuteBuffer, lpDirect3DViewport, dwFlags);
1337
1338     /* Put this as the default context */
1339
1340     /* Execute... */
1341     lpDirect3DExecuteBufferImpl->execute(lpDirect3DExecuteBufferImpl, This, lpDirect3DViewportImpl);
1342
1343     return DD_OK;
1344 }
1345
1346 HRESULT WINAPI
1347 Main_IDirect3DDeviceImpl_1_NextViewport(LPDIRECT3DDEVICE iface,
1348                                         LPDIRECT3DVIEWPORT lpDirect3DViewport,
1349                                         LPDIRECT3DVIEWPORT* lplpDirect3DViewport,
1350                                         DWORD dwFlags)
1351 {
1352     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1353     FIXME("(%p/%p)->(%p,%p,%08lx): stub!\n", This, iface, lpDirect3DViewport, lplpDirect3DViewport, dwFlags);
1354     return DD_OK;
1355 }
1356
1357 HRESULT WINAPI
1358 Main_IDirect3DDeviceImpl_1_Pick(LPDIRECT3DDEVICE iface,
1359                                 LPDIRECT3DEXECUTEBUFFER lpDirect3DExecuteBuffer,
1360                                 LPDIRECT3DVIEWPORT lpDirect3DViewport,
1361                                 DWORD dwFlags,
1362                                 LPD3DRECT lpRect)
1363 {
1364     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1365     FIXME("(%p/%p)->(%p,%p,%08lx,%p): stub!\n", This, iface, lpDirect3DExecuteBuffer, lpDirect3DViewport, dwFlags, lpRect);
1366     return DD_OK;
1367 }
1368
1369 HRESULT WINAPI
1370 Main_IDirect3DDeviceImpl_1_GetPickRecords(LPDIRECT3DDEVICE iface,
1371                                           LPDWORD lpCount,
1372                                           LPD3DPICKRECORD lpD3DPickRec)
1373 {
1374     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1375     FIXME("(%p/%p)->(%p,%p): stub!\n", This, iface, lpCount, lpD3DPickRec);
1376     return DD_OK;
1377 }
1378
1379 HRESULT WINAPI
1380 Main_IDirect3DDeviceImpl_1_CreateMatrix(LPDIRECT3DDEVICE iface,
1381                                         LPD3DMATRIXHANDLE lpD3DMatHandle)
1382 {
1383     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1384     TRACE("(%p/%p)->(%p)\n", This, iface, lpD3DMatHandle);
1385
1386     *lpD3DMatHandle = (D3DMATRIXHANDLE) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(D3DMATRIX));
1387     TRACE(" returning matrix handle %p\n", (void *) *lpD3DMatHandle);
1388     
1389     return DD_OK;
1390 }
1391
1392 HRESULT WINAPI
1393 Main_IDirect3DDeviceImpl_1_SetMatrix(LPDIRECT3DDEVICE iface,
1394                                      D3DMATRIXHANDLE D3DMatHandle,
1395                                      LPD3DMATRIX lpD3DMatrix)
1396 {
1397     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1398     TRACE("(%p/%p)->(%08lx,%p)\n", This, iface, (DWORD) D3DMatHandle, lpD3DMatrix);
1399
1400     if (TRACE_ON(ddraw)) {
1401         dump_D3DMATRIX(lpD3DMatrix);
1402     }
1403     *((D3DMATRIX *) D3DMatHandle) = *lpD3DMatrix;   
1404     
1405     return DD_OK;
1406 }
1407
1408 HRESULT WINAPI
1409 Main_IDirect3DDeviceImpl_1_GetMatrix(LPDIRECT3DDEVICE iface,
1410                                      D3DMATRIXHANDLE D3DMatHandle,
1411                                      LPD3DMATRIX lpD3DMatrix)
1412 {
1413     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1414     TRACE("(%p/%p)->(%08lx,%p)\n", This, iface, (DWORD) D3DMatHandle, lpD3DMatrix);
1415
1416     *lpD3DMatrix = *((D3DMATRIX *) D3DMatHandle);
1417     
1418     return DD_OK;
1419 }
1420
1421 HRESULT WINAPI
1422 Main_IDirect3DDeviceImpl_1_DeleteMatrix(LPDIRECT3DDEVICE iface,
1423                                         D3DMATRIXHANDLE D3DMatHandle)
1424 {
1425     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1426     TRACE("(%p/%p)->(%08lx)\n", This, iface, (DWORD) D3DMatHandle);
1427
1428     HeapFree(GetProcessHeap(), 0, (void *) D3DMatHandle);
1429     
1430     return DD_OK;
1431 }
1432
1433 HRESULT WINAPI
1434 Thunk_IDirect3DDeviceImpl_3_QueryInterface(LPDIRECT3DDEVICE3 iface,
1435                                            REFIID riid,
1436                                            LPVOID* obp)
1437 {
1438     TRACE("(%p)->(%s,%p) thunking to IDirect3DDevice7 interface.\n", iface, debugstr_guid(riid), obp);
1439     return IDirect3DDevice7_QueryInterface(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
1440                                            riid,
1441                                            obp);
1442 }
1443
1444 HRESULT WINAPI
1445 Thunk_IDirect3DDeviceImpl_2_QueryInterface(LPDIRECT3DDEVICE2 iface,
1446                                            REFIID riid,
1447                                            LPVOID* obp)
1448 {
1449     TRACE("(%p)->(%s,%p) thunking to IDirect3DDevice7 interface.\n", iface, debugstr_guid(riid), obp);
1450     return IDirect3DDevice7_QueryInterface(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice7, iface),
1451                                            riid,
1452                                            obp);
1453 }
1454
1455 HRESULT WINAPI
1456 Thunk_IDirect3DDeviceImpl_1_QueryInterface(LPDIRECT3DDEVICE iface,
1457                                            REFIID riid,
1458                                            LPVOID* obp)
1459 {
1460     TRACE("(%p)->(%s,%p) thunking to IDirect3DDevice7 interface.\n", iface, debugstr_guid(riid), obp);
1461     return IDirect3DDevice7_QueryInterface(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice7, iface),
1462                                            riid,
1463                                            obp);
1464 }
1465
1466 ULONG WINAPI
1467 Thunk_IDirect3DDeviceImpl_3_AddRef(LPDIRECT3DDEVICE3 iface)
1468 {
1469     TRACE("(%p)->() thunking to IDirect3DDevice7 interface.\n", iface);
1470     return IDirect3DDevice7_AddRef(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface));
1471 }
1472
1473 ULONG WINAPI
1474 Thunk_IDirect3DDeviceImpl_2_AddRef(LPDIRECT3DDEVICE2 iface)
1475 {
1476     TRACE("(%p)->() thunking to IDirect3DDevice7 interface.\n", iface);
1477     return IDirect3DDevice7_AddRef(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice7, iface));
1478 }
1479
1480 ULONG WINAPI
1481 Thunk_IDirect3DDeviceImpl_1_AddRef(LPDIRECT3DDEVICE iface)
1482 {
1483     TRACE("(%p)->() thunking to IDirect3DDevice7 interface.\n", iface);
1484     return IDirect3DDevice7_AddRef(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice7, iface));
1485 }
1486
1487 ULONG WINAPI
1488 Thunk_IDirect3DDeviceImpl_3_Release(LPDIRECT3DDEVICE3 iface)
1489 {
1490     TRACE("(%p)->() thunking to IDirect3DDevice7 interface.\n", iface);
1491     return IDirect3DDevice7_Release(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface));
1492 }
1493
1494 ULONG WINAPI
1495 Thunk_IDirect3DDeviceImpl_2_Release(LPDIRECT3DDEVICE2 iface)
1496 {
1497     TRACE("(%p)->() thunking to IDirect3DDevice7 interface.\n", iface);
1498     return IDirect3DDevice7_Release(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice7, iface));
1499 }
1500
1501 ULONG WINAPI
1502 Thunk_IDirect3DDeviceImpl_1_Release(LPDIRECT3DDEVICE iface)
1503 {
1504     TRACE("(%p)->() thunking to IDirect3DDevice7 interface.\n", iface);
1505     return IDirect3DDevice7_Release(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice7, iface));
1506 }
1507
1508 HRESULT WINAPI
1509 Thunk_IDirect3DDeviceImpl_2_AddViewport(LPDIRECT3DDEVICE2 iface,
1510                                         LPDIRECT3DVIEWPORT2 lpDirect3DViewport2)
1511 {
1512     TRACE("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", iface, lpDirect3DViewport2);
1513     return IDirect3DDevice3_AddViewport(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice3, iface),
1514                                         (LPDIRECT3DVIEWPORT3) lpDirect3DViewport2 /* No need to cast here as all interfaces are equivalent */);
1515 }
1516
1517 HRESULT WINAPI
1518 Thunk_IDirect3DDeviceImpl_1_AddViewport(LPDIRECT3DDEVICE iface,
1519                                         LPDIRECT3DVIEWPORT lpDirect3DViewport)
1520 {
1521     TRACE("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", iface, lpDirect3DViewport);
1522     return IDirect3DDevice3_AddViewport(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice3, iface),
1523                                         (LPDIRECT3DVIEWPORT3) lpDirect3DViewport /* No need to cast here as all interfaces are equivalent */);
1524 }
1525
1526 HRESULT WINAPI
1527 Thunk_IDirect3DDeviceImpl_2_DeleteViewport(LPDIRECT3DDEVICE2 iface,
1528                                            LPDIRECT3DVIEWPORT2 lpDirect3DViewport2)
1529 {
1530     TRACE("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", iface, lpDirect3DViewport2);
1531     return IDirect3DDevice3_DeleteViewport(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice3, iface),
1532                                            (LPDIRECT3DVIEWPORT3) lpDirect3DViewport2 /* No need to cast here as all interfaces are equivalent */);
1533 }
1534
1535 HRESULT WINAPI
1536 Thunk_IDirect3DDeviceImpl_1_DeleteViewport(LPDIRECT3DDEVICE iface,
1537                                            LPDIRECT3DVIEWPORT lpDirect3DViewport)
1538 {
1539     TRACE("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", iface, lpDirect3DViewport);
1540     return IDirect3DDevice3_DeleteViewport(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice3, iface),
1541                                            (LPDIRECT3DVIEWPORT3) lpDirect3DViewport /* No need to cast here as all interfaces are equivalent */);
1542 }
1543
1544 HRESULT WINAPI
1545 Thunk_IDirect3DDeviceImpl_2_NextViewport(LPDIRECT3DDEVICE3 iface,
1546                                          LPDIRECT3DVIEWPORT2 lpDirect3DViewport2,
1547                                          LPDIRECT3DVIEWPORT2* lplpDirect3DViewport2,
1548                                          DWORD dwFlags)
1549 {
1550     TRACE("(%p)->(%p,%p,%08lx) thunking to IDirect3DDevice3 interface.\n", iface, lpDirect3DViewport2, lplpDirect3DViewport2, dwFlags);
1551     return IDirect3DDevice3_NextViewport(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice3, iface),
1552                                          (LPDIRECT3DVIEWPORT3) lpDirect3DViewport2 /* No need to cast here as all interfaces are equivalent */,
1553                                          (LPDIRECT3DVIEWPORT3*) lplpDirect3DViewport2,
1554                                          dwFlags);
1555 }
1556
1557 HRESULT WINAPI
1558 Thunk_IDirect3DDeviceImpl_1_NextViewport(LPDIRECT3DDEVICE3 iface,
1559                                          LPDIRECT3DVIEWPORT lpDirect3DViewport,
1560                                          LPDIRECT3DVIEWPORT* lplpDirect3DViewport,
1561                                          DWORD dwFlags)
1562 {
1563     TRACE("(%p)->(%p,%p,%08lx) thunking to IDirect3DDevice3 interface.\n", iface, lpDirect3DViewport, lplpDirect3DViewport, dwFlags);
1564     return IDirect3DDevice3_NextViewport(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice3, iface),
1565                                          (LPDIRECT3DVIEWPORT3) lpDirect3DViewport /* No need to cast here as all interfaces are equivalent */,
1566                                          (LPDIRECT3DVIEWPORT3*) lplpDirect3DViewport,
1567                                          dwFlags);
1568 }
1569
1570 HRESULT WINAPI
1571 Thunk_IDirect3DDeviceImpl_3_GetDirect3D(LPDIRECT3DDEVICE3 iface,
1572                                         LPDIRECT3D3* lplpDirect3D3)
1573 {
1574     HRESULT ret;
1575     LPDIRECT3D7 ret_ptr;
1576   
1577     TRACE("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", iface, lplpDirect3D3);
1578     ret = IDirect3DDevice7_GetDirect3D(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
1579                                        &ret_ptr);
1580     *lplpDirect3D3 = COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirect3D3, ret_ptr);
1581     TRACE(" returning interface %p\n", *lplpDirect3D3);
1582     return ret;
1583 }
1584
1585 HRESULT WINAPI
1586 Thunk_IDirect3DDeviceImpl_2_GetDirect3D(LPDIRECT3DDEVICE2 iface,
1587                                         LPDIRECT3D2* lplpDirect3D2)
1588 {
1589     HRESULT ret;
1590     LPDIRECT3D7 ret_ptr;
1591   
1592     TRACE("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", iface, lplpDirect3D2);
1593     ret = IDirect3DDevice7_GetDirect3D(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice7, iface),
1594                                        &ret_ptr);
1595     *lplpDirect3D2 = COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirect3D2, ret_ptr);
1596     TRACE(" returning interface %p\n", *lplpDirect3D2);
1597     return ret;
1598 }
1599
1600 HRESULT WINAPI
1601 Thunk_IDirect3DDeviceImpl_1_GetDirect3D(LPDIRECT3DDEVICE iface,
1602                                         LPDIRECT3D* lplpDirect3D)
1603 {
1604     HRESULT ret;
1605     LPDIRECT3D7 ret_ptr;
1606   
1607     TRACE("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", iface, lplpDirect3D);
1608     ret = IDirect3DDevice7_GetDirect3D(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice7, iface),
1609                                        &ret_ptr);
1610     *lplpDirect3D = COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirect3D, ret_ptr);
1611     TRACE(" returning interface %p\n", *lplpDirect3D);
1612     return ret;
1613 }
1614
1615 HRESULT WINAPI
1616 Thunk_IDirect3DDeviceImpl_2_SetCurrentViewport(LPDIRECT3DDEVICE2 iface,
1617                                                LPDIRECT3DVIEWPORT2 lpDirect3DViewport2)
1618 {
1619     TRACE("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", iface, lpDirect3DViewport2);
1620     return IDirect3DDevice3_SetCurrentViewport(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice3, iface),
1621                                                (LPDIRECT3DVIEWPORT3) lpDirect3DViewport2 /* No need to cast here as all interfaces are equivalent */);
1622 }
1623
1624 HRESULT WINAPI
1625 Thunk_IDirect3DDeviceImpl_2_GetCurrentViewport(LPDIRECT3DDEVICE2 iface,
1626                                                LPDIRECT3DVIEWPORT2* lplpDirect3DViewport2)
1627 {
1628     TRACE("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", iface, lplpDirect3DViewport2);
1629     return IDirect3DDevice3_GetCurrentViewport(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice3, iface),
1630                                                (LPDIRECT3DVIEWPORT3*) lplpDirect3DViewport2 /* No need to cast here as all interfaces are equivalent */);
1631 }
1632
1633 HRESULT WINAPI
1634 Thunk_IDirect3DDeviceImpl_3_EnumTextureFormats(LPDIRECT3DDEVICE3 iface,
1635                                                LPD3DENUMPIXELFORMATSCALLBACK lpD3DEnumPixelProc,
1636                                                LPVOID lpArg)
1637 {
1638     TRACE("(%p)->(%p,%p) thunking to IDirect3DDevice7 interface.\n", iface, lpD3DEnumPixelProc, lpArg);
1639     return IDirect3DDevice7_EnumTextureFormats(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
1640                                                lpD3DEnumPixelProc,
1641                                                lpArg);
1642 }
1643
1644 HRESULT WINAPI
1645 Thunk_IDirect3DDeviceImpl_3_BeginScene(LPDIRECT3DDEVICE3 iface)
1646 {
1647     TRACE("(%p)->() thunking to IDirect3DDevice7 interface.\n", iface);
1648     return IDirect3DDevice7_BeginScene(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface));
1649 }
1650
1651 HRESULT WINAPI
1652 Thunk_IDirect3DDeviceImpl_2_BeginScene(LPDIRECT3DDEVICE2 iface)
1653 {
1654     TRACE("(%p)->() thunking to IDirect3DDevice7 interface.\n", iface);
1655     return IDirect3DDevice7_BeginScene(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice7, iface));
1656 }
1657
1658 HRESULT WINAPI
1659 Thunk_IDirect3DDeviceImpl_1_BeginScene(LPDIRECT3DDEVICE iface)
1660 {
1661     TRACE("(%p)->() thunking to IDirect3DDevice7 interface.\n", iface);
1662     return IDirect3DDevice7_BeginScene(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice7, iface));
1663 }
1664
1665 HRESULT WINAPI
1666 Thunk_IDirect3DDeviceImpl_3_EndScene(LPDIRECT3DDEVICE3 iface)
1667 {
1668     TRACE("(%p)->() thunking to IDirect3DDevice7 interface.\n", iface);
1669     return IDirect3DDevice7_EndScene(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface));
1670 }
1671
1672 HRESULT WINAPI
1673 Thunk_IDirect3DDeviceImpl_2_EndScene(LPDIRECT3DDEVICE2 iface)
1674 {
1675     TRACE("(%p)->() thunking to IDirect3DDevice7 interface.\n", iface);
1676     return IDirect3DDevice7_EndScene(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice7, iface));
1677 }
1678
1679 HRESULT WINAPI
1680 Thunk_IDirect3DDeviceImpl_1_EndScene(LPDIRECT3DDEVICE iface)
1681 {
1682     TRACE("(%p)->() thunking to IDirect3DDevice7 interface.\n", iface);
1683     return IDirect3DDevice7_EndScene(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice7, iface));
1684 }
1685
1686 HRESULT WINAPI
1687 Thunk_IDirect3DDeviceImpl_3_SetTransform(LPDIRECT3DDEVICE3 iface,
1688                                          D3DTRANSFORMSTATETYPE dtstTransformStateType,
1689                                          LPD3DMATRIX lpD3DMatrix)
1690 {
1691     TRACE("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", iface, dtstTransformStateType, lpD3DMatrix);
1692     return IDirect3DDevice7_SetTransform(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
1693                                          dtstTransformStateType,
1694                                          lpD3DMatrix);
1695 }
1696
1697 HRESULT WINAPI
1698 Thunk_IDirect3DDeviceImpl_2_SetTransform(LPDIRECT3DDEVICE2 iface,
1699                                          D3DTRANSFORMSTATETYPE dtstTransformStateType,
1700                                          LPD3DMATRIX lpD3DMatrix)
1701 {
1702     TRACE("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", iface, dtstTransformStateType, lpD3DMatrix);
1703     return IDirect3DDevice7_SetTransform(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice7, iface),
1704                                          dtstTransformStateType,
1705                                          lpD3DMatrix);
1706 }
1707
1708 HRESULT WINAPI
1709 Thunk_IDirect3DDeviceImpl_3_GetTransform(LPDIRECT3DDEVICE3 iface,
1710                                          D3DTRANSFORMSTATETYPE dtstTransformStateType,
1711                                          LPD3DMATRIX lpD3DMatrix)
1712 {
1713     TRACE("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", iface, dtstTransformStateType, lpD3DMatrix);
1714     return IDirect3DDevice7_GetTransform(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
1715                                          dtstTransformStateType,
1716                                          lpD3DMatrix);
1717 }
1718
1719 HRESULT WINAPI
1720 Thunk_IDirect3DDeviceImpl_2_GetTransform(LPDIRECT3DDEVICE2 iface,
1721                                          D3DTRANSFORMSTATETYPE dtstTransformStateType,
1722                                          LPD3DMATRIX lpD3DMatrix)
1723 {
1724     TRACE("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", iface, dtstTransformStateType, lpD3DMatrix);
1725     return IDirect3DDevice7_GetTransform(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice7, iface),
1726                                          dtstTransformStateType,
1727                                          lpD3DMatrix);
1728 }
1729
1730 HRESULT WINAPI
1731 Thunk_IDirect3DDeviceImpl_3_MultiplyTransform(LPDIRECT3DDEVICE3 iface,
1732                                               D3DTRANSFORMSTATETYPE dtstTransformStateType,
1733                                               LPD3DMATRIX lpD3DMatrix)
1734 {
1735     TRACE("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", iface, dtstTransformStateType, lpD3DMatrix);
1736     return IDirect3DDevice7_MultiplyTransform(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
1737                                               dtstTransformStateType,
1738                                               lpD3DMatrix);
1739 }
1740
1741 HRESULT WINAPI
1742 Thunk_IDirect3DDeviceImpl_2_MultiplyTransform(LPDIRECT3DDEVICE2 iface,
1743                                               D3DTRANSFORMSTATETYPE dtstTransformStateType,
1744                                               LPD3DMATRIX lpD3DMatrix)
1745 {
1746     TRACE("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", iface, dtstTransformStateType, lpD3DMatrix);
1747     return IDirect3DDevice7_MultiplyTransform(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice7, iface),
1748                                               dtstTransformStateType,
1749                                               lpD3DMatrix);
1750 }
1751
1752 HRESULT WINAPI
1753 Thunk_IDirect3DDeviceImpl_3_SetRenderState(LPDIRECT3DDEVICE3 iface,
1754                                            D3DRENDERSTATETYPE dwRenderStateType,
1755                                            DWORD dwRenderState)
1756 {
1757     TRACE("(%p)->(%08x,%08lx) thunking to IDirect3DDevice7 interface.\n", iface, dwRenderStateType, dwRenderState);
1758     return IDirect3DDevice7_SetRenderState(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
1759                                            dwRenderStateType,
1760                                            dwRenderState);
1761 }
1762
1763 HRESULT WINAPI
1764 Thunk_IDirect3DDeviceImpl_2_SetRenderState(LPDIRECT3DDEVICE2 iface,
1765                                            D3DRENDERSTATETYPE dwRenderStateType,
1766                                            DWORD dwRenderState)
1767 {
1768     TRACE("(%p)->(%08x,%08lx) thunking to IDirect3DDevice7 interface.\n", iface, dwRenderStateType, dwRenderState);
1769     return IDirect3DDevice7_SetRenderState(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice7, iface),
1770                                            dwRenderStateType,
1771                                            dwRenderState);
1772 }
1773
1774 HRESULT WINAPI
1775 Thunk_IDirect3DDeviceImpl_3_GetRenderState(LPDIRECT3DDEVICE3 iface,
1776                                            D3DRENDERSTATETYPE dwRenderStateType,
1777                                            LPDWORD lpdwRenderState)
1778 {
1779     TRACE("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", iface, dwRenderStateType, lpdwRenderState);
1780     return IDirect3DDevice7_GetRenderState(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
1781                                            dwRenderStateType,
1782                                            lpdwRenderState);
1783 }
1784
1785 HRESULT WINAPI
1786 Thunk_IDirect3DDeviceImpl_2_GetRenderState(LPDIRECT3DDEVICE2 iface,
1787                                            D3DRENDERSTATETYPE dwRenderStateType,
1788                                            LPDWORD lpdwRenderState)
1789 {
1790     TRACE("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", iface, dwRenderStateType, lpdwRenderState);
1791     return IDirect3DDevice7_GetRenderState(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice7, iface),
1792                                            dwRenderStateType,
1793                                            lpdwRenderState);
1794 }
1795
1796 HRESULT WINAPI
1797 Thunk_IDirect3DDeviceImpl_3_DrawPrimitive(LPDIRECT3DDEVICE3 iface,
1798                                           D3DPRIMITIVETYPE d3dptPrimitiveType,
1799                                           DWORD d3dvtVertexType,
1800                                           LPVOID lpvVertices,
1801                                           DWORD dwVertexCount,
1802                                           DWORD dwFlags)
1803 {
1804     TRACE("(%p)->(%08x,%08lx,%p,%08lx,%08lx) thunking to IDirect3DDevice7 interface.\n", iface, d3dptPrimitiveType, d3dvtVertexType, lpvVertices, dwVertexCount, dwFlags);
1805     return IDirect3DDevice7_DrawPrimitive(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
1806                                           d3dptPrimitiveType,
1807                                           d3dvtVertexType,
1808                                           lpvVertices,
1809                                           dwVertexCount,
1810                                           dwFlags);
1811 }
1812
1813 HRESULT WINAPI
1814 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitive(LPDIRECT3DDEVICE3 iface,
1815                                                  D3DPRIMITIVETYPE d3dptPrimitiveType,
1816                                                  DWORD d3dvtVertexType,
1817                                                  LPVOID lpvVertices,
1818                                                  DWORD dwVertexCount,
1819                                                  LPWORD dwIndices,
1820                                                  DWORD dwIndexCount,
1821                                                  DWORD dwFlags)
1822 {
1823     TRACE("(%p)->(%08x,%08lx,%p,%08lx,%p,%08lx,%08lx) thunking to IDirect3DDevice7 interface.\n", iface, d3dptPrimitiveType, d3dvtVertexType, lpvVertices, dwVertexCount, dwIndices, dwIndexCount, dwFlags);
1824     return IDirect3DDevice7_DrawIndexedPrimitive(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
1825                                                  d3dptPrimitiveType,
1826                                                  d3dvtVertexType,
1827                                                  lpvVertices,
1828                                                  dwVertexCount,
1829                                                  dwIndices,
1830                                                  dwIndexCount,
1831                                                  dwFlags);
1832 }
1833
1834 HRESULT WINAPI
1835 Thunk_IDirect3DDeviceImpl_3_SetClipStatus(LPDIRECT3DDEVICE3 iface,
1836                                           LPD3DCLIPSTATUS lpD3DClipStatus)
1837 {
1838     TRACE("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", iface, lpD3DClipStatus);
1839     return IDirect3DDevice7_SetClipStatus(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
1840                                           lpD3DClipStatus);
1841 }
1842
1843 HRESULT WINAPI
1844 Thunk_IDirect3DDeviceImpl_2_SetClipStatus(LPDIRECT3DDEVICE2 iface,
1845                                           LPD3DCLIPSTATUS lpD3DClipStatus)
1846 {
1847     TRACE("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", iface, lpD3DClipStatus);
1848     return IDirect3DDevice7_SetClipStatus(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice7, iface),
1849                                           lpD3DClipStatus);
1850 }
1851
1852 HRESULT WINAPI
1853 Thunk_IDirect3DDeviceImpl_3_GetClipStatus(LPDIRECT3DDEVICE3 iface,
1854                                           LPD3DCLIPSTATUS lpD3DClipStatus)
1855 {
1856     TRACE("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", iface, lpD3DClipStatus);
1857     return IDirect3DDevice7_GetClipStatus(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
1858                                           lpD3DClipStatus);
1859 }
1860
1861 HRESULT WINAPI
1862 Thunk_IDirect3DDeviceImpl_2_GetClipStatus(LPDIRECT3DDEVICE2 iface,
1863                                           LPD3DCLIPSTATUS lpD3DClipStatus)
1864 {
1865     TRACE("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", iface, lpD3DClipStatus);
1866     return IDirect3DDevice7_GetClipStatus(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice7, iface),
1867                                           lpD3DClipStatus);
1868 }
1869
1870 HRESULT WINAPI
1871 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveStrided(LPDIRECT3DDEVICE3 iface,
1872                                                  D3DPRIMITIVETYPE d3dptPrimitiveType,
1873                                                  DWORD dwVertexType,
1874                                                  LPD3DDRAWPRIMITIVESTRIDEDDATA lpD3DDrawPrimStrideData,
1875                                                  DWORD dwVertexCount,
1876                                                  DWORD dwFlags)
1877 {
1878     TRACE("(%p)->(%08x,%08lx,%p,%08lx,%08lx) thunking to IDirect3DDevice7 interface.\n", iface, d3dptPrimitiveType, dwVertexType, lpD3DDrawPrimStrideData, dwVertexCount, dwFlags);
1879     return IDirect3DDevice7_DrawPrimitiveStrided(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
1880                                                  d3dptPrimitiveType,
1881                                                  dwVertexType,
1882                                                  lpD3DDrawPrimStrideData,
1883                                                  dwVertexCount,
1884                                                  dwFlags);
1885 }
1886
1887 HRESULT WINAPI
1888 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveStrided(LPDIRECT3DDEVICE3 iface,
1889                                                         D3DPRIMITIVETYPE d3dptPrimitiveType,
1890                                                         DWORD dwVertexType,
1891                                                         LPD3DDRAWPRIMITIVESTRIDEDDATA lpD3DDrawPrimStrideData,
1892                                                         DWORD dwVertexCount,
1893                                                         LPWORD lpIndex,
1894                                                         DWORD dwIndexCount,
1895                                                         DWORD dwFlags)
1896 {
1897     TRACE("(%p)->(%08x,%08lx,%p,%08lx,%p,%08lx,%08lx) thunking to IDirect3DDevice7 interface.\n", iface, d3dptPrimitiveType, dwVertexType, lpD3DDrawPrimStrideData, dwVertexCount, lpIndex, dwIndexCount, dwFlags);
1898     return IDirect3DDevice7_DrawIndexedPrimitiveStrided(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
1899                                                         d3dptPrimitiveType,
1900                                                         dwVertexType,
1901                                                         lpD3DDrawPrimStrideData,
1902                                                         dwVertexCount,
1903                                                         lpIndex,
1904                                                         dwIndexCount,
1905                                                         dwFlags);
1906 }
1907
1908 HRESULT WINAPI
1909 Thunk_IDirect3DDeviceImpl_3_ComputeSphereVisibility(LPDIRECT3DDEVICE3 iface,
1910                                                     LPD3DVECTOR lpCenters,
1911                                                     LPD3DVALUE lpRadii,
1912                                                     DWORD dwNumSpheres,
1913                                                     DWORD dwFlags,
1914                                                     LPDWORD lpdwReturnValues)
1915 {
1916     TRACE("(%p)->(%p,%p,%08lx,%08lx,%p) thunking to IDirect3DDevice7 interface.\n", iface, lpCenters, lpRadii, dwNumSpheres, dwFlags, lpdwReturnValues);
1917     return IDirect3DDevice7_ComputeSphereVisibility(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
1918                                                     lpCenters,
1919                                                     lpRadii,
1920                                                     dwNumSpheres,
1921                                                     dwFlags,
1922                                                     lpdwReturnValues);
1923 }
1924
1925 HRESULT WINAPI
1926 Thunk_IDirect3DDeviceImpl_3_GetTextureStageState(LPDIRECT3DDEVICE3 iface,
1927                                                  DWORD dwStage,
1928                                                  D3DTEXTURESTAGESTATETYPE d3dTexStageStateType,
1929                                                  LPDWORD lpdwState)
1930 {
1931     TRACE("(%p)->(%08lx,%08x,%p) thunking to IDirect3DDevice7 interface.\n", iface, dwStage, d3dTexStageStateType, lpdwState);
1932     return IDirect3DDevice7_GetTextureStageState(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
1933                                                  dwStage,
1934                                                  d3dTexStageStateType,
1935                                                  lpdwState);
1936 }
1937
1938 HRESULT WINAPI
1939 Thunk_IDirect3DDeviceImpl_3_SetTextureStageState(LPDIRECT3DDEVICE3 iface,
1940                                                  DWORD dwStage,
1941                                                  D3DTEXTURESTAGESTATETYPE d3dTexStageStateType,
1942                                                  DWORD dwState)
1943 {
1944     TRACE("(%p)->(%08lx,%08x,%08lx) thunking to IDirect3DDevice7 interface.\n", iface, dwStage, d3dTexStageStateType, dwState);
1945     return IDirect3DDevice7_SetTextureStageState(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
1946                                                  dwStage,
1947                                                  d3dTexStageStateType,
1948                                                  dwState);
1949 }
1950
1951 HRESULT WINAPI
1952 Thunk_IDirect3DDeviceImpl_3_ValidateDevice(LPDIRECT3DDEVICE3 iface,
1953                                            LPDWORD lpdwPasses)
1954 {
1955     TRACE("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", iface, lpdwPasses);
1956     return IDirect3DDevice7_ValidateDevice(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
1957                                            lpdwPasses);
1958 }
1959
1960 HRESULT WINAPI
1961 Thunk_IDirect3DDeviceImpl_2_GetCaps(LPDIRECT3DDEVICE2 iface,
1962                                     LPD3DDEVICEDESC lpD3DHWDevDesc,
1963                                     LPD3DDEVICEDESC lpD3DHELDevDesc)
1964 {
1965     TRACE("(%p)->(%p,%p) thunking to IDirect3DDevice3 interface.\n", iface, lpD3DHWDevDesc, lpD3DHELDevDesc);
1966     return IDirect3DDevice3_GetCaps(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice3, iface),
1967                                     lpD3DHWDevDesc,
1968                                     lpD3DHELDevDesc);
1969 }
1970
1971 HRESULT WINAPI
1972 Thunk_IDirect3DDeviceImpl_1_GetCaps(LPDIRECT3DDEVICE iface,
1973                                     LPD3DDEVICEDESC lpD3DHWDevDesc,
1974                                     LPD3DDEVICEDESC lpD3DHELDevDesc)
1975 {
1976     TRACE("(%p)->(%p,%p) thunking to IDirect3DDevice3 interface.\n", iface, lpD3DHWDevDesc, lpD3DHELDevDesc);
1977     return IDirect3DDevice3_GetCaps(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice3, iface),
1978                                     lpD3DHWDevDesc,
1979                                     lpD3DHELDevDesc);
1980 }
1981
1982 HRESULT WINAPI
1983 Thunk_IDirect3DDeviceImpl_1_SwapTextureHandles(LPDIRECT3DDEVICE iface,
1984                                               LPDIRECT3DTEXTURE lpD3DTex1,
1985                                               LPDIRECT3DTEXTURE lpD3DTex2)
1986 {
1987     TRACE("(%p)->(%p,%p) thunking to IDirect3DDevice2 interface.\n", iface, lpD3DTex1, lpD3DTex2);
1988     return IDirect3DDevice2_SwapTextureHandles(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice2, iface),
1989                                                COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirect3DTexture, IDirect3DTexture2, lpD3DTex1),
1990                                                COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirect3DTexture, IDirect3DTexture2, lpD3DTex2));
1991 }
1992
1993 HRESULT WINAPI
1994 Thunk_IDirect3DDeviceImpl_2_GetStats(LPDIRECT3DDEVICE2 iface,
1995                                      LPD3DSTATS lpD3DStats)
1996 {
1997     TRACE("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", iface, lpD3DStats);
1998     return IDirect3DDevice3_GetStats(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice3, iface),
1999                                      lpD3DStats);
2000 }
2001
2002 HRESULT WINAPI
2003 Thunk_IDirect3DDeviceImpl_1_GetStats(LPDIRECT3DDEVICE iface,
2004                                      LPD3DSTATS lpD3DStats)
2005 {
2006     TRACE("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", iface, lpD3DStats);
2007     return IDirect3DDevice3_GetStats(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice3, iface),
2008                                      lpD3DStats);
2009 }
2010
2011 HRESULT WINAPI
2012 Thunk_IDirect3DDeviceImpl_3_SetRenderTarget(LPDIRECT3DDEVICE3 iface,
2013                                             LPDIRECTDRAWSURFACE4 lpNewRenderTarget,
2014                                             DWORD dwFlags)
2015 {
2016     TRACE("(%p)->(%p,%08lx) thunking to IDirect3DDevice7 interface.\n", iface, lpNewRenderTarget, dwFlags);
2017     return IDirect3DDevice7_SetRenderTarget(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
2018                                             (LPDIRECTDRAWSURFACE7) lpNewRenderTarget /* No cast needed as DSurf4 == DSurf7 */,
2019                                             dwFlags);
2020 }
2021
2022 HRESULT WINAPI
2023 Thunk_IDirect3DDeviceImpl_3_GetRenderTarget(LPDIRECT3DDEVICE3 iface,
2024                                             LPDIRECTDRAWSURFACE4* lplpRenderTarget)
2025 {
2026     TRACE("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", iface, lplpRenderTarget);
2027     return IDirect3DDevice7_GetRenderTarget(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
2028                                             (LPDIRECTDRAWSURFACE7*) lplpRenderTarget /* No cast needed as DSurf4 == DSurf7 */);
2029 }
2030
2031 HRESULT WINAPI
2032 Thunk_IDirect3DDeviceImpl_2_SetRenderTarget(LPDIRECT3DDEVICE2 iface,
2033                                             LPDIRECTDRAWSURFACE lpNewRenderTarget,
2034                                             DWORD dwFlags)
2035 {
2036     TRACE("(%p)->(%p,%08lx) thunking to IDirect3DDevice7 interface.\n", iface, lpNewRenderTarget, dwFlags);
2037     return IDirect3DDevice7_SetRenderTarget(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice7, iface),
2038                                             COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface3, IDirectDrawSurface7, lpNewRenderTarget),
2039                                             dwFlags);
2040 }
2041
2042 HRESULT WINAPI
2043 Thunk_IDirect3DDeviceImpl_2_GetRenderTarget(LPDIRECT3DDEVICE2 iface,
2044                                             LPDIRECTDRAWSURFACE* lplpRenderTarget)
2045 {
2046     HRESULT ret;
2047     LPDIRECTDRAWSURFACE7 ret_val;
2048   
2049     TRACE("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", iface, lplpRenderTarget);
2050     ret = IDirect3DDevice7_GetRenderTarget(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice7, iface),
2051                                            &ret_val);
2052     *lplpRenderTarget = (LPDIRECTDRAWSURFACE) COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7, IDirectDrawSurface3, ret_val);
2053     TRACE(" returning interface %p\n", *lplpRenderTarget);
2054     return ret;
2055 }
2056
2057 HRESULT WINAPI
2058 Thunk_IDirect3DDeviceImpl_2_Vertex(LPDIRECT3DDEVICE2 iface,
2059                                    LPVOID lpVertexType)
2060 {
2061     TRACE("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", iface, lpVertexType);
2062     return IDirect3DDevice3_Vertex(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice3, iface),
2063                                    lpVertexType);
2064 }
2065
2066 HRESULT WINAPI
2067 Thunk_IDirect3DDeviceImpl_2_Index(LPDIRECT3DDEVICE2 iface,
2068                                   WORD wVertexIndex)
2069 {
2070     TRACE("(%p)->(%04x) thunking to IDirect3DDevice3 interface.\n", iface, wVertexIndex);
2071     return IDirect3DDevice3_Index(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice3, iface),
2072                                   wVertexIndex);
2073 }
2074
2075 HRESULT WINAPI
2076 Thunk_IDirect3DDeviceImpl_2_End(LPDIRECT3DDEVICE2 iface,
2077                                 DWORD dwFlags)
2078 {
2079     TRACE("(%p)->(%08lx) thunking to IDirect3DDevice3 interface.\n", iface, dwFlags);
2080     return IDirect3DDevice3_End(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice3, iface),
2081                                 dwFlags);
2082 }
2083
2084 HRESULT WINAPI
2085 Thunk_IDirect3DDeviceImpl_2_GetLightState(LPDIRECT3DDEVICE2 iface,
2086                                           D3DLIGHTSTATETYPE dwLightStateType,
2087                                           LPDWORD lpdwLightState)
2088 {
2089     TRACE("(%p)->(%08x,%p) thunking to IDirect3DDevice3 interface.\n", iface, dwLightStateType, lpdwLightState);
2090     return IDirect3DDevice3_GetLightState(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice3, iface),
2091                                           dwLightStateType,
2092                                           lpdwLightState);
2093 }
2094
2095 HRESULT WINAPI
2096 Thunk_IDirect3DDeviceImpl_2_SetLightState(LPDIRECT3DDEVICE2 iface,
2097                                           D3DLIGHTSTATETYPE dwLightStateType,
2098                                           DWORD dwLightState)
2099 {
2100     TRACE("(%p)->(%08x,%08lx) thunking to IDirect3DDevice3 interface.\n", iface, dwLightStateType, dwLightState);
2101     return IDirect3DDevice3_SetLightState(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice3, iface),
2102                                           dwLightStateType,
2103                                           dwLightState);
2104 }
2105
2106 HRESULT WINAPI
2107 Thunk_IDirect3DDeviceImpl_1_EnumTextureFormats(LPDIRECT3DDEVICE iface,
2108                                                LPD3DENUMTEXTUREFORMATSCALLBACK lpD3DEnumTextureProc,
2109                                                LPVOID lpArg)
2110 {
2111     TRACE("(%p)->(%p,%p) thunking to IDirect3DDevice2 interface.\n", iface, lpD3DEnumTextureProc, lpArg);
2112     return IDirect3DDevice2_EnumTextureFormats(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice2, iface),
2113                                                lpD3DEnumTextureProc,
2114                                                lpArg);
2115 }
2116
2117 HRESULT WINAPI
2118 Thunk_IDirect3DDeviceImpl_3_SetTexture(LPDIRECT3DDEVICE3 iface,
2119                                        DWORD dwStage,
2120                                        LPDIRECT3DTEXTURE2 lpTexture2)
2121 {
2122     TRACE("(%p)->(%ld,%p) thunking to IDirect3DDevice7 interface.\n", iface, dwStage, lpTexture2);
2123     return IDirect3DDevice7_SetTexture(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
2124                                        dwStage,
2125                                        COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirect3DTexture2, IDirectDrawSurface7, lpTexture2));
2126 }
2127
2128 HRESULT WINAPI
2129 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveVB(LPDIRECT3DDEVICE3 iface,
2130                                             D3DPRIMITIVETYPE d3dptPrimitiveType,
2131                                             LPDIRECT3DVERTEXBUFFER lpD3DVertexBuf,
2132                                             DWORD dwStartVertex,
2133                                             DWORD dwNumVertices,
2134                                             DWORD dwFlags)
2135 {
2136     TRACE("(%p)->(%08x,%p,%08lx,%08lx,%08lx) thunking to IDirect3DDevice7 interface.\n", iface, 
2137           d3dptPrimitiveType, lpD3DVertexBuf, dwStartVertex, dwNumVertices, dwFlags);
2138     return IDirect3DDevice7_DrawPrimitiveVB(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
2139                                             d3dptPrimitiveType,
2140                                             COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, IDirect3DVertexBuffer7, lpD3DVertexBuf),
2141                                             dwStartVertex,
2142                                             dwNumVertices,
2143                                             dwFlags);
2144 }
2145
2146 HRESULT WINAPI
2147 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveVB(LPDIRECT3DDEVICE3 iface,
2148                                                    D3DPRIMITIVETYPE d3dptPrimitiveType,
2149                                                    LPDIRECT3DVERTEXBUFFER lpD3DVertexBuf,
2150                                                    LPWORD lpwIndices,
2151                                                    DWORD dwIndexCount,
2152                                                    DWORD dwFlags)
2153 {
2154     TRACE("(%p)->(%08x,%p,%p,%08lx,%08lx) thunking to IDirect3DDevice7 interface.\n", iface,
2155           d3dptPrimitiveType, lpD3DVertexBuf, lpwIndices, dwIndexCount, dwFlags);
2156     return IDirect3DDevice7_DrawIndexedPrimitiveVB(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
2157                                                    d3dptPrimitiveType,
2158                                                    COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, IDirect3DVertexBuffer7, lpD3DVertexBuf),
2159                                                    0,
2160                                                    dwIndexCount,
2161                                                    lpwIndices,
2162                                                    dwIndexCount,
2163                                                    dwFlags);
2164 }
2165
2166 HRESULT WINAPI
2167 Thunk_IDirect3DDeviceImpl_3_GetTexture(LPDIRECT3DDEVICE3 iface,
2168                                        DWORD dwStage,
2169                                        LPDIRECT3DTEXTURE2* lplpTexture2)
2170 {
2171     HRESULT ret;
2172     LPDIRECTDRAWSURFACE7 ret_val;
2173
2174     TRACE("(%p)->(%ld,%p) thunking to IDirect3DDevice7 interface.\n", iface, dwStage, lplpTexture2);
2175     ret = IDirect3DDevice7_GetTexture(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
2176                                       dwStage,
2177                                       &ret_val);
2178
2179     *lplpTexture2 = COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7, IDirect3DTexture2, ret_val);
2180
2181     TRACE(" returning interface %p.\n", *lplpTexture2);
2182     
2183     return ret;
2184 }