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