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