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