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