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