wined3d: WINED3DTEXF_NONE only makes sense as a mip filter.
[wine] / dlls / ddraw / ddraw_private.h
1 /*
2  * Copyright 2006 Stefan Dösinger
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #ifndef __WINE_DLLS_DDRAW_DDRAW_PRIVATE_H
20 #define __WINE_DLLS_DDRAW_DDRAW_PRIVATE_H
21
22 /* MAY NOT CONTAIN X11 or DGA specific includes/defines/structs! */
23
24 #include <stdarg.h>
25 #include <stdio.h>
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wtypes.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "ddraw.h"
33 #include "ddrawi.h"
34 #include "d3d.h"
35
36 #include "wine/list.h"
37 #ifdef DDRAW_INIT_GUID
38 #include "initguid.h"
39 #endif
40 #include "wine/wined3d.h"
41
42 /*****************************************************************************
43  * IParent - a helper interface
44  *****************************************************************************/
45 DEFINE_GUID(IID_IParent, 0xc20e4c88, 0x74e7, 0x4940, 0xba, 0x9f, 0x2e, 0x32, 0x3f, 0x9d, 0xc9, 0x81);
46 typedef struct IParent *LPPARENT, *PPARENT;
47
48 #define INTERFACE IParent
49 DECLARE_INTERFACE_(IParent,IUnknown)
50 {
51     /*** IUnknown methods ***/
52     STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
53     STDMETHOD_(ULONG,AddRef)(THIS) PURE;
54     STDMETHOD_(ULONG,Release)(THIS) PURE;
55 };
56 #undef INTERFACE
57
58 #if !defined(__cplusplus) || defined(CINTERFACE)
59 /*** IUnknown methods ***/
60 #define IParent_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
61 #define IParent_AddRef(p)             (p)->lpVtbl->AddRef(p)
62 #define IParent_Release(p)            (p)->lpVtbl->Release(p)
63 #endif
64
65
66 /* Typdef the interfaces */
67 typedef struct IDirectDrawImpl            IDirectDrawImpl;
68 typedef struct IDirectDrawSurfaceImpl     IDirectDrawSurfaceImpl;
69 typedef struct IDirectDrawClipperImpl     IDirectDrawClipperImpl;
70 typedef struct IDirectDrawPaletteImpl     IDirectDrawPaletteImpl;
71 typedef struct IDirect3DDeviceImpl        IDirect3DDeviceImpl;
72 typedef struct IDirect3DLightImpl         IDirect3DLightImpl;
73 typedef struct IDirect3DViewportImpl      IDirect3DViewportImpl;
74 typedef struct IDirect3DMaterialImpl      IDirect3DMaterialImpl;
75 typedef struct IDirect3DExecuteBufferImpl IDirect3DExecuteBufferImpl;
76 typedef struct IDirect3DVertexBufferImpl  IDirect3DVertexBufferImpl;
77 typedef struct IParentImpl                IParentImpl;
78
79 /* Callbacks for implicit object destruction */
80 extern ULONG WINAPI D3D7CB_DestroySwapChain(IWineD3DSwapChain *pSwapChain);
81
82 extern ULONG WINAPI D3D7CB_DestroyDepthStencilSurface(IWineD3DSurface *pSurface);
83
84 /* Global critical section */
85 extern CRITICAL_SECTION ddraw_cs;
86
87 extern DWORD force_refresh_rate;
88
89 /*****************************************************************************
90  * IDirectDraw implementation structure
91  *****************************************************************************/
92 struct FvfToDecl
93 {
94     DWORD fvf;
95     IWineD3DVertexDeclaration *decl;
96 };
97
98 struct IDirectDrawImpl
99 {
100     /* IUnknown fields */
101     const IDirectDraw7Vtbl *lpVtbl;
102     const IDirectDraw4Vtbl *IDirectDraw4_vtbl;
103     const IDirectDraw3Vtbl *IDirectDraw3_vtbl;
104     const IDirectDraw2Vtbl *IDirectDraw2_vtbl;
105     const IDirectDrawVtbl *IDirectDraw_vtbl;
106     const IDirect3D7Vtbl *IDirect3D7_vtbl;
107     const IDirect3D3Vtbl *IDirect3D3_vtbl;
108     const IDirect3D2Vtbl *IDirect3D2_vtbl;
109     const IDirect3DVtbl *IDirect3D_vtbl;
110     const IWineD3DDeviceParentVtbl *device_parent_vtbl;
111
112     /* See comment in IDirectDraw::AddRef */
113     LONG                    ref7, ref4, ref2, ref3, ref1, numIfaces;
114
115     /* WineD3D linkage */
116     IWineD3D                *wineD3D;
117     IWineD3DDevice          *wineD3DDevice;
118     IDirectDrawSurfaceImpl  *DepthStencilBuffer;
119     BOOL                    d3d_initialized;
120
121     /* Misc ddraw fields */
122     UINT                    total_vidmem;
123     DWORD                   cur_scanline;
124     BOOL                    fake_vblank;
125     BOOL                    initialized;
126
127     /* DirectDraw things, which are not handled by WineD3D */
128     DWORD                   cooperative_level;
129
130     DWORD                   orig_width, orig_height;
131     DWORD                   orig_bpp;
132
133     /* D3D things */
134     IDirectDrawSurfaceImpl  *d3d_target;
135     HWND                    d3d_window;
136     IDirect3DDeviceImpl     *d3ddevice;
137     int                     d3dversion;
138
139     /* Various HWNDs */
140     HWND                    focuswindow;
141     HWND                    devicewindow;
142     HWND                    dest_window;
143
144     /* The surface type to request */
145     WINED3DSURFTYPE         ImplType;
146
147
148     /* Our private window class */
149     char classname[32];
150     WNDCLASSA wnd_class;
151
152     /* Helpers for surface creation */
153     IDirectDrawSurfaceImpl *tex_root;
154     BOOL                    depthstencil;
155
156     /* For the dll unload cleanup code */
157     struct list ddraw_list_entry;
158     /* The surface list - can't relay this to WineD3D
159      * because of IParent
160      */
161     struct list surface_list;
162     LONG surfaces;
163
164     /* FVF management */
165     struct FvfToDecl       *decls;
166     UINT                    numConvertedDecls, declArraySize;
167 };
168
169 /* Declare the VTables. They can be found ddraw.c */
170 extern const IDirectDraw7Vtbl IDirectDraw7_Vtbl;
171 extern const IDirectDraw4Vtbl IDirectDraw4_Vtbl;
172 extern const IDirectDraw3Vtbl IDirectDraw3_Vtbl;
173 extern const IDirectDraw2Vtbl IDirectDraw2_Vtbl;
174 extern const IDirectDrawVtbl  IDirectDraw1_Vtbl;
175 extern const IWineD3DDeviceParentVtbl ddraw_wined3d_device_parent_vtbl;
176
177 /* Helper structures */
178 typedef struct EnumDisplayModesCBS
179 {
180     void *context;
181     LPDDENUMMODESCALLBACK2 callback;
182 } EnumDisplayModesCBS;
183
184 typedef struct EnumSurfacesCBS
185 {
186     void *context;
187     LPDDENUMSURFACESCALLBACK7 callback;
188     LPDDSURFACEDESC2 pDDSD;
189     DWORD Flags;
190 } EnumSurfacesCBS;
191
192 /* Utility functions */
193 void
194 DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS* pIn,
195                              DDSCAPS2* pOut);
196 void
197 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2* pIn,
198                                         DDDEVICEIDENTIFIER* pOut);
199 void
200 IDirectDrawImpl_Destroy(IDirectDrawImpl *This);
201
202 HRESULT WINAPI
203 IDirectDrawImpl_RecreateSurfacesCallback(IDirectDrawSurface7 *surf,
204                                          DDSURFACEDESC2 *desc,
205                                          void *Context);
206 IWineD3DVertexDeclaration *
207 IDirectDrawImpl_FindDecl(IDirectDrawImpl *This,
208                          DWORD fvf);
209
210 static inline IDirectDrawImpl *ddraw_from_d3d1(IDirect3D *iface)
211 {
212     return (IDirectDrawImpl *)((char*)iface - FIELD_OFFSET(IDirectDrawImpl, IDirect3D_vtbl));
213 }
214
215 static inline IDirectDrawImpl *ddraw_from_d3d2(IDirect3D2 *iface)
216 {
217     return (IDirectDrawImpl *)((char*)iface - FIELD_OFFSET(IDirectDrawImpl, IDirect3D2_vtbl));
218 }
219
220 static inline IDirectDrawImpl *ddraw_from_d3d3(IDirect3D3 *iface)
221 {
222     return (IDirectDrawImpl *)((char*)iface - FIELD_OFFSET(IDirectDrawImpl, IDirect3D3_vtbl));
223 }
224
225 static inline IDirectDrawImpl *ddraw_from_d3d7(IDirect3D7 *iface)
226 {
227     return (IDirectDrawImpl *)((char*)iface - FIELD_OFFSET(IDirectDrawImpl, IDirect3D7_vtbl));
228 }
229
230 static inline IDirectDrawImpl *ddraw_from_ddraw1(IDirectDraw *iface)
231 {
232     return (IDirectDrawImpl *)((char*)iface - FIELD_OFFSET(IDirectDrawImpl, IDirectDraw_vtbl));
233 }
234
235 static inline IDirectDrawImpl *ddraw_from_ddraw2(IDirectDraw2 *iface)
236 {
237     return (IDirectDrawImpl *)((char*)iface - FIELD_OFFSET(IDirectDrawImpl, IDirectDraw2_vtbl));
238 }
239
240 static inline IDirectDrawImpl *ddraw_from_ddraw3(IDirectDraw3 *iface)
241 {
242     return (IDirectDrawImpl *)((char*)iface - FIELD_OFFSET(IDirectDrawImpl, IDirectDraw3_vtbl));
243 }
244
245 static inline IDirectDrawImpl *ddraw_from_ddraw4(IDirectDraw4 *iface)
246 {
247     return (IDirectDrawImpl *)((char*)iface - FIELD_OFFSET(IDirectDrawImpl, IDirectDraw4_vtbl));
248 }
249
250 /* The default surface type */
251 extern WINED3DSURFTYPE DefaultSurfaceType;
252
253 /*****************************************************************************
254  * IDirectDrawSurface implementation structure
255  *****************************************************************************/
256
257 struct IDirectDrawSurfaceImpl
258 {
259     /* IUnknown fields */
260     const IDirectDrawSurface7Vtbl *lpVtbl;
261     const IDirectDrawSurface3Vtbl *IDirectDrawSurface3_vtbl;
262     const IDirectDrawGammaControlVtbl *IDirectDrawGammaControl_vtbl;
263     const IDirect3DTexture2Vtbl *IDirect3DTexture2_vtbl;
264     const IDirect3DTextureVtbl *IDirect3DTexture_vtbl;
265
266     LONG                     ref;
267     IUnknown                *ifaceToRelease;
268
269     int                     version;
270
271     /* Connections to other Objects */
272     IDirectDrawImpl         *ddraw;
273     IWineD3DSurface         *WineD3DSurface;
274     IWineD3DBaseTexture     *wineD3DTexture;
275     IWineD3DSwapChain       *wineD3DSwapChain;
276
277     /* This implementation handles attaching surfaces to other surfaces */
278     IDirectDrawSurfaceImpl  *next_attached;
279     IDirectDrawSurfaceImpl  *first_attached;
280
281     /* Complex surfaces are organized in a tree, although the tree is degenerated to a list in most cases.
282      * In mipmap and primary surfaces each level has only one attachment, which is the next surface level.
283      * Only the cube texture root has 6 surfaces attached, which then have a normal mipmap chain attached
284      * to them. So hardcode the array to 6, a dynamic array or a list would be an overkill.
285      */
286 #define MAX_COMPLEX_ATTACHED 6
287     IDirectDrawSurfaceImpl  *complex_array[MAX_COMPLEX_ATTACHED];
288     /* You can't traverse the tree upwards. Only a flag for Surface::Release because its needed there,
289      * but no pointer to prevent temptations to traverse it in the wrong direction.
290      */
291     BOOL                    is_complex_root;
292
293     /* Surface description, for GetAttachedSurface */
294     DDSURFACEDESC2          surface_desc;
295
296     /* Misc things */
297     DWORD                   uniqueness_value;
298     UINT                    mipmap_level;
299     WINED3DSURFTYPE         ImplType;
300
301     /* For D3DDevice creation */
302     BOOL                    isRenderTarget;
303
304     /* Clipper objects */
305     IDirectDrawClipperImpl  *clipper;
306
307     /* For the ddraw surface list */
308     struct list             surface_list_entry;
309
310     DWORD                   Handle;
311 };
312
313 /* VTable declaration. It's located in surface.c / surface_thunks.c */
314 extern const IDirectDrawSurface7Vtbl IDirectDrawSurface7_Vtbl;
315 extern const IDirectDrawSurface3Vtbl IDirectDrawSurface3_Vtbl;
316 extern const IDirectDrawGammaControlVtbl IDirectDrawGammaControl_Vtbl;
317 extern const IDirect3DTexture2Vtbl IDirect3DTexture2_Vtbl;
318 extern const IDirect3DTextureVtbl IDirect3DTexture1_Vtbl;
319
320 HRESULT WINAPI IDirectDrawSurfaceImpl_AddAttachedSurface(IDirectDrawSurfaceImpl *This, IDirectDrawSurfaceImpl *Surf);
321 void IDirectDrawSurfaceImpl_Destroy(IDirectDrawSurfaceImpl *This);
322
323 static inline IDirectDrawSurfaceImpl *surface_from_texture1(IDirect3DTexture *iface)
324 {
325     return (IDirectDrawSurfaceImpl *)((char*)iface - FIELD_OFFSET(IDirectDrawSurfaceImpl, IDirect3DTexture_vtbl));
326 }
327
328 static inline IDirectDrawSurfaceImpl *surface_from_texture2(IDirect3DTexture2 *iface)
329 {
330     return (IDirectDrawSurfaceImpl *)((char*)iface - FIELD_OFFSET(IDirectDrawSurfaceImpl, IDirect3DTexture2_vtbl));
331 }
332
333 static inline IDirectDrawSurfaceImpl *surface_from_surface3(IDirectDrawSurface3 *iface)
334 {
335     return (IDirectDrawSurfaceImpl *)((char*)iface - FIELD_OFFSET(IDirectDrawSurfaceImpl, IDirectDrawSurface3_vtbl));
336 }
337
338 /* Get the number of bytes per pixel for a given surface */
339 #define PFGET_BPP(pf) (pf.dwFlags&DDPF_PALETTEINDEXED8?1:((pf.dwRGBBitCount+7)/8))
340 #define GET_BPP(desc) PFGET_BPP(desc.ddpfPixelFormat)
341
342 /*****************************************************************************
343  * IParent Implementation
344  *****************************************************************************/
345 struct IParentImpl
346 {
347     /* IUnknown fields */
348     const IParentVtbl *lpVtbl;
349     LONG                    ref;
350
351     /* IParentImpl fields */
352     IUnknown      *child;
353
354 };
355
356 extern const IParentVtbl IParent_Vtbl;
357
358 /*****************************************************************************
359  * IDirect3DDevice implementation
360  *****************************************************************************/
361 typedef enum
362 {
363     DDrawHandle_Unknown       = 0,
364     DDrawHandle_Texture       = 1,
365     DDrawHandle_Material      = 2,
366     DDrawHandle_Matrix        = 3,
367     DDrawHandle_StateBlock    = 4
368 } DDrawHandleTypes;
369
370 struct HandleEntry
371 {
372     void    *ptr;
373     DDrawHandleTypes      type;
374 };
375
376 struct IDirect3DDeviceImpl
377 {
378     /* IUnknown */
379     const IDirect3DDevice7Vtbl *lpVtbl;
380     const IDirect3DDevice3Vtbl *IDirect3DDevice3_vtbl;
381     const IDirect3DDevice2Vtbl *IDirect3DDevice2_vtbl;
382     const IDirect3DDeviceVtbl *IDirect3DDevice_vtbl;
383     LONG                    ref;
384
385     /* Other object connections */
386     IWineD3DDevice          *wineD3DDevice;
387     IDirectDrawImpl         *ddraw;
388     IWineD3DBuffer          *indexbuffer;
389     IDirectDrawSurfaceImpl  *target;
390     BOOL                    OffScreenTarget;
391
392     /* Viewport management */
393     IDirect3DViewportImpl *viewport_list;
394     IDirect3DViewportImpl *current_viewport;
395     D3DVIEWPORT7 active_viewport;
396
397     /* Required to keep track which of two available texture blending modes in d3ddevice3 is used */
398     BOOL legacyTextureBlending;
399
400     /* Light state */
401     DWORD material;
402
403     /* Rendering functions to wrap D3D(1-3) to D3D7 */
404     D3DPRIMITIVETYPE primitive_type;
405     DWORD vertex_type;
406     DWORD render_flags;
407     DWORD nb_vertices;
408     LPBYTE vertex_buffer;
409     DWORD vertex_size;
410     DWORD buffer_size;
411
412     /* Handle management */
413     struct HandleEntry      *Handles;
414     DWORD                    numHandles;
415     D3DMATRIXHANDLE          world, proj, view;
416 };
417
418 /* Vtables in various versions */
419 extern const IDirect3DDevice7Vtbl IDirect3DDevice7_FPUSetup_Vtbl;
420 extern const IDirect3DDevice7Vtbl IDirect3DDevice7_FPUPreserve_Vtbl;
421 extern const IDirect3DDevice3Vtbl IDirect3DDevice3_Vtbl;
422 extern const IDirect3DDevice2Vtbl IDirect3DDevice2_Vtbl;
423 extern const IDirect3DDeviceVtbl  IDirect3DDevice1_Vtbl;
424
425 /* The IID */
426 extern const GUID IID_D3DDEVICE_WineD3D;
427
428 /* Helper functions */
429 HRESULT IDirect3DImpl_GetCaps(IWineD3D *WineD3D, D3DDEVICEDESC *Desc123, D3DDEVICEDESC7 *Desc7);
430 DWORD IDirect3DDeviceImpl_CreateHandle(IDirect3DDeviceImpl *This);
431 WINED3DZBUFFERTYPE IDirect3DDeviceImpl_UpdateDepthStencil(IDirect3DDeviceImpl *This);
432
433 static inline IDirect3DDeviceImpl *device_from_device1(IDirect3DDevice *iface)
434 {
435     return (IDirect3DDeviceImpl *)((char*)iface - FIELD_OFFSET(IDirect3DDeviceImpl, IDirect3DDevice_vtbl));
436 }
437
438 static inline IDirect3DDeviceImpl *device_from_device2(IDirect3DDevice2 *iface)
439 {
440     return (IDirect3DDeviceImpl *)((char*)iface - FIELD_OFFSET(IDirect3DDeviceImpl, IDirect3DDevice2_vtbl));
441 }
442
443 static inline IDirect3DDeviceImpl *device_from_device3(IDirect3DDevice3 *iface)
444 {
445     return (IDirect3DDeviceImpl *)((char*)iface - FIELD_OFFSET(IDirect3DDeviceImpl, IDirect3DDevice3_vtbl));
446 }
447
448 /* Structures */
449 struct EnumTextureFormatsCBS
450 {
451     LPD3DENUMTEXTUREFORMATSCALLBACK cbv2;
452     LPD3DENUMPIXELFORMATSCALLBACK cbv7;
453     void *Context;
454 };
455
456 /*****************************************************************************
457  * IDirect3D implementation
458  *****************************************************************************/
459
460 /* No implementation structure as this is only another interface to DirectDraw */
461
462 /* the Vtables */
463 extern const IDirect3DVtbl  IDirect3D1_Vtbl;
464 extern const IDirect3D2Vtbl IDirect3D2_Vtbl;
465 extern const IDirect3D3Vtbl IDirect3D3_Vtbl;
466 extern const IDirect3D7Vtbl IDirect3D7_Vtbl;
467
468 /* Structure for EnumZBufferFormats */
469 struct EnumZBufferFormatsData
470 {
471     LPD3DENUMPIXELFORMATSCALLBACK Callback;
472     void *Context;
473 };
474
475 /*****************************************************************************
476  * IDirectDrawClipper implementation structure
477  *****************************************************************************/
478 struct IDirectDrawClipperImpl
479 {
480     /* IUnknown fields */
481     const IDirectDrawClipperVtbl *lpVtbl;
482     LONG ref;
483
484     IWineD3DClipper           *wineD3DClipper;
485     IDirectDrawImpl           *ddraw_owner;
486 };
487
488 extern const IDirectDrawClipperVtbl IDirectDrawClipper_Vtbl;
489
490 typeof(WineDirect3DCreateClipper) *pWineDirect3DCreateClipper;
491
492 /*****************************************************************************
493  * IDirectDrawPalette implementation structure
494  *****************************************************************************/
495 struct IDirectDrawPaletteImpl
496 {
497     /* IUnknown fields */
498     const IDirectDrawPaletteVtbl *lpVtbl;
499     LONG ref;
500
501     /* WineD3D uplink */
502     IWineD3DPalette           *wineD3DPalette;
503
504     /* IDirectDrawPalette fields */
505     IDirectDrawImpl           *ddraw_owner;
506     IUnknown                  *ifaceToRelease;
507 };
508 extern const IDirectDrawPaletteVtbl IDirectDrawPalette_Vtbl;
509
510 /******************************************************************************
511  * DirectDraw ClassFactory implementation - incomplete
512  ******************************************************************************/
513 typedef struct
514 {
515     const IClassFactoryVtbl *lpVtbl;
516
517     LONG ref;
518     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, REFIID iid, LPVOID *ppObj);
519 } IClassFactoryImpl;
520
521 /* Helper structures */
522 struct object_creation_info
523 {
524     const CLSID *clsid;
525     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, REFIID riid,
526                                  void **ppObj);
527 };
528
529 /******************************************************************************
530  * IDirect3DLight implementation structure - Wraps to D3D7
531  ******************************************************************************/
532 struct IDirect3DLightImpl
533 {
534     const IDirect3DLightVtbl *lpVtbl;
535     LONG ref;
536
537     /* IDirect3DLight fields */
538     IDirectDrawImpl           *ddraw;
539
540     /* If this light is active for one viewport, put the viewport here */
541     IDirect3DViewportImpl     *active_viewport;
542
543     D3DLIGHT2 light;
544     D3DLIGHT7 light7;
545
546     DWORD dwLightIndex;
547
548     /* Chained list used for adding / removing from viewports */
549     IDirect3DLightImpl        *next;
550
551     /* Activation function */
552     void                      (*activate)(IDirect3DLightImpl*);
553     void                      (*desactivate)(IDirect3DLightImpl*);
554     void                      (*update)(IDirect3DLightImpl*);
555 };
556
557 /* Vtable */
558 extern const IDirect3DLightVtbl IDirect3DLight_Vtbl;
559
560 /* Helper functions */
561 void light_update(IDirect3DLightImpl* This);
562 void light_activate(IDirect3DLightImpl* This);
563 void light_desactivate(IDirect3DLightImpl* This);
564
565 /******************************************************************************
566  * IDirect3DMaterial implementation structure - Wraps to D3D7
567  ******************************************************************************/
568 struct IDirect3DMaterialImpl
569 {
570     const IDirect3DMaterial3Vtbl *lpVtbl;
571     const IDirect3DMaterial2Vtbl *IDirect3DMaterial2_vtbl;
572     const IDirect3DMaterialVtbl *IDirect3DMaterial_vtbl;
573     LONG  ref;
574
575     /* IDirect3DMaterial2 fields */
576     IDirectDrawImpl               *ddraw;
577     IDirect3DDeviceImpl           *active_device;
578
579     D3DMATERIAL mat;
580     DWORD Handle;
581
582     void (*activate)(IDirect3DMaterialImpl* this);
583 };
584
585 /* VTables in various versions */
586 extern const IDirect3DMaterialVtbl IDirect3DMaterial_Vtbl;
587 extern const IDirect3DMaterial2Vtbl IDirect3DMaterial2_Vtbl;
588 extern const IDirect3DMaterial3Vtbl IDirect3DMaterial3_Vtbl;
589
590 /* Helper functions */
591 void material_activate(IDirect3DMaterialImpl* This);
592
593 /*****************************************************************************
594  * IDirect3DViewport - Wraps to D3D7
595  *****************************************************************************/
596 struct IDirect3DViewportImpl
597 {
598     const IDirect3DViewport3Vtbl *lpVtbl;
599     LONG ref;
600
601     /* IDirect3DViewport fields */
602     IDirectDrawImpl           *ddraw;
603
604     /* If this viewport is active for one device, put the device here */
605     IDirect3DDeviceImpl       *active_device;
606
607     DWORD                     num_lights;
608     DWORD                     map_lights;
609
610     int                       use_vp2;
611
612     union
613     {
614         D3DVIEWPORT vp1;
615         D3DVIEWPORT2 vp2;
616     } viewports;
617
618     /* Activation function */
619     void                      (*activate)(IDirect3DViewportImpl*, BOOL);
620
621     /* Field used to chain viewports together */
622     IDirect3DViewportImpl     *next;
623
624     /* Lights list */
625     IDirect3DLightImpl        *lights;
626
627     /* Background material */
628     IDirect3DMaterialImpl     *background;
629 };
630
631 /* Vtable */
632 extern const IDirect3DViewport3Vtbl IDirect3DViewport3_Vtbl;
633
634 /* Helper functions */
635 void viewport_activate(IDirect3DViewportImpl* This, BOOL ignore_lights);
636
637 /*****************************************************************************
638  * IDirect3DExecuteBuffer - Wraps to D3D7
639  *****************************************************************************/
640 struct IDirect3DExecuteBufferImpl
641 {
642     /* IUnknown */
643     const IDirect3DExecuteBufferVtbl *lpVtbl;
644     LONG                 ref;
645
646     /* IDirect3DExecuteBuffer fields */
647     IDirectDrawImpl      *ddraw;
648     IDirect3DDeviceImpl  *d3ddev;
649
650     D3DEXECUTEBUFFERDESC desc;
651     D3DEXECUTEDATA       data;
652
653     /* This buffer will store the transformed vertices */
654     void                 *vertex_data;
655     WORD                 *indices;
656     int                  nb_indices;
657
658     /* This flags is set to TRUE if we allocated ourselves the
659      * data buffer
660      */
661     BOOL                 need_free;
662 };
663
664 /* The VTable */
665 extern const IDirect3DExecuteBufferVtbl IDirect3DExecuteBuffer_Vtbl;
666
667 /* The execute function */
668 void
669 IDirect3DExecuteBufferImpl_Execute(IDirect3DExecuteBufferImpl *This,
670                                    IDirect3DDeviceImpl *Device,
671                                    IDirect3DViewportImpl *ViewportImpl);
672
673 /*****************************************************************************
674  * IDirect3DVertexBuffer
675  *****************************************************************************/
676 struct IDirect3DVertexBufferImpl
677 {
678     /*** IUnknown Methods ***/
679     const IDirect3DVertexBuffer7Vtbl *lpVtbl;
680     const IDirect3DVertexBufferVtbl *IDirect3DVertexBuffer_vtbl;
681     LONG                 ref;
682
683     /*** WineD3D and ddraw links ***/
684     IWineD3DBuffer *wineD3DVertexBuffer;
685     IWineD3DVertexDeclaration *wineD3DVertexDeclaration;
686     IDirectDrawImpl *ddraw;
687
688     /*** Storage for D3D7 specific things ***/
689     DWORD                Caps;
690     DWORD                fvf;
691 };
692
693 /* The Vtables */
694 extern const IDirect3DVertexBuffer7Vtbl IDirect3DVertexBuffer7_Vtbl;
695 extern const IDirect3DVertexBufferVtbl IDirect3DVertexBuffer1_Vtbl;
696
697 static inline IDirect3DVertexBufferImpl *vb_from_vb1(IDirect3DVertexBuffer *iface)
698 {
699     return (IDirect3DVertexBufferImpl *)((char*)iface
700             - FIELD_OFFSET(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer_vtbl));
701 }
702
703 /*****************************************************************************
704  * Helper functions from utils.c
705  *****************************************************************************/
706
707 #define GET_TEXCOUNT_FROM_FVF(d3dvtVertexType) \
708     (((d3dvtVertexType) & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT)
709
710 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
711     (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
712
713 void PixelFormat_WineD3DtoDD(DDPIXELFORMAT *DDPixelFormat, WINED3DFORMAT WineD3DFormat);
714 WINED3DFORMAT PixelFormat_DD2WineD3D(const DDPIXELFORMAT *DDPixelFormat);
715 void DDRAW_dump_surface_desc(const DDSURFACEDESC2 *lpddsd);
716 void dump_D3DMATRIX(const D3DMATRIX *mat);
717 void DDRAW_dump_DDCAPS(const DDCAPS *lpcaps);
718 DWORD get_flexible_vertex_size(DWORD d3dvtVertexType);
719 void DDRAW_dump_DDSCAPS2(const DDSCAPS2 *in);
720 void DDRAW_dump_cooperativelevel(DWORD cooplevel);
721
722 /* This only needs to be here as long the processvertices functionality of
723  * IDirect3DExecuteBuffer isn't in WineD3D */
724 void multiply_matrix(LPD3DMATRIX dest, const D3DMATRIX *src1, const D3DMATRIX *src2);
725
726 void multiply_matrix_D3D_way(LPD3DMATRIX result, const D3DMATRIX *m1, const D3DMATRIX *m2);
727
728 /* Helper function in main.c */
729 BOOL LoadWineD3D(void);
730
731 /* Used for generic dumping */
732 typedef struct
733 {
734     DWORD val;
735     const char* name;
736 } flag_info;
737
738 #define FE(x) { x, #x }
739
740 typedef struct
741 {
742     DWORD val;
743     const char* name;
744     void (*func)(const void *);
745     ptrdiff_t offset;
746 } member_info;
747
748 /* Structure copy */
749 #define ME(x,f,e) { x, #x, (void (*)(const void *))(f), offsetof(STRUCT, e) }
750
751 #define DD_STRUCT_COPY_BYSIZE(to,from)                  \
752         do {                                            \
753                 DWORD __size = (to)->dwSize;            \
754                 DWORD __copysize = __size;              \
755                 DWORD __resetsize = __size;             \
756                 assert(to != from);                     \
757                 if (__resetsize > sizeof(*to))          \
758                     __resetsize = sizeof(*to);          \
759                 memset(to,0,__resetsize);               \
760                 if ((from)->dwSize < __size)            \
761                     __copysize = (from)->dwSize;        \
762                 memcpy(to,from,__copysize);             \
763                 (to)->dwSize = __size;/*restore size*/  \
764         } while (0)
765
766
767 #endif
768
769 HRESULT hr_ddraw_from_wined3d(HRESULT hr);