wined3d: Add two functions for GL context activation/restore.
[wine] / dlls / d3d8 / d3d8_private.h
1 /*
2  * Direct3D 8 private include file
3  *
4  * Copyright 2002-2004 Jason Edmeades
5  * Copyright 2003-2004 Raphael Junqueira
6  * Copyright 2004 Christian Costa
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #ifndef __WINE_D3D8_PRIVATE_H
24 #define __WINE_D3D8_PRIVATE_H
25
26 #include <stdarg.h>
27
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
30 #define COBJMACROS
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "wine/debug.h"
35 #include "d3d8.h"
36 #include "wine/wined3d.h"
37
38 /* CreateVertexShader can return > 0xFFFF */
39 #define VS_HIGHESTFIXEDFXF 0xF0000000
40
41 /* ===========================================================================
42     Macros
43    =========================================================================== */
44 /* Not nice, but it lets wined3d support different versions of directx */
45 #define WINECAPSTOD3D8CAPS(_pD3D8Caps, _pWineCaps) \
46     _pD3D8Caps->DeviceType                        = (D3DDEVTYPE) _pWineCaps->DeviceType; \
47     _pD3D8Caps->AdapterOrdinal                    = _pWineCaps->AdapterOrdinal; \
48     _pD3D8Caps->Caps                              = _pWineCaps->Caps; \
49     _pD3D8Caps->Caps2                             = _pWineCaps->Caps2; \
50     _pD3D8Caps->Caps3                             = _pWineCaps->Caps3; \
51     _pD3D8Caps->PresentationIntervals             = _pWineCaps->PresentationIntervals; \
52     _pD3D8Caps->CursorCaps                        = _pWineCaps->CursorCaps; \
53     _pD3D8Caps->DevCaps                           = _pWineCaps->DevCaps; \
54     _pD3D8Caps->PrimitiveMiscCaps                 = _pWineCaps->PrimitiveMiscCaps; \
55     _pD3D8Caps->RasterCaps                        = _pWineCaps->RasterCaps; \
56     _pD3D8Caps->ZCmpCaps                          = _pWineCaps->ZCmpCaps; \
57     _pD3D8Caps->SrcBlendCaps                      = _pWineCaps->SrcBlendCaps; \
58     _pD3D8Caps->DestBlendCaps                     = _pWineCaps->DestBlendCaps; \
59     _pD3D8Caps->AlphaCmpCaps                      = _pWineCaps->AlphaCmpCaps; \
60     _pD3D8Caps->ShadeCaps                         = _pWineCaps->ShadeCaps; \
61     _pD3D8Caps->TextureCaps                       = _pWineCaps->TextureCaps; \
62     _pD3D8Caps->TextureFilterCaps                 = _pWineCaps->TextureFilterCaps; \
63     _pD3D8Caps->CubeTextureFilterCaps             = _pWineCaps->CubeTextureFilterCaps; \
64     _pD3D8Caps->VolumeTextureFilterCaps           = _pWineCaps->VolumeTextureFilterCaps; \
65     _pD3D8Caps->TextureAddressCaps                = _pWineCaps->TextureAddressCaps; \
66     _pD3D8Caps->VolumeTextureAddressCaps          = _pWineCaps->VolumeTextureAddressCaps; \
67     _pD3D8Caps->LineCaps                          = _pWineCaps->LineCaps; \
68     _pD3D8Caps->MaxTextureWidth                   = _pWineCaps->MaxTextureWidth; \
69     _pD3D8Caps->MaxTextureHeight                  = _pWineCaps->MaxTextureHeight; \
70     _pD3D8Caps->MaxVolumeExtent                   = _pWineCaps->MaxVolumeExtent; \
71     _pD3D8Caps->MaxTextureRepeat                  = _pWineCaps->MaxTextureRepeat; \
72     _pD3D8Caps->MaxTextureAspectRatio             = _pWineCaps->MaxTextureAspectRatio; \
73     _pD3D8Caps->MaxAnisotropy                     = _pWineCaps->MaxAnisotropy; \
74     _pD3D8Caps->MaxVertexW                        = _pWineCaps->MaxVertexW; \
75     _pD3D8Caps->GuardBandLeft                     = _pWineCaps->GuardBandLeft; \
76     _pD3D8Caps->GuardBandTop                      = _pWineCaps->GuardBandTop; \
77     _pD3D8Caps->GuardBandRight                    = _pWineCaps->GuardBandRight; \
78     _pD3D8Caps->GuardBandBottom                   = _pWineCaps->GuardBandBottom; \
79     _pD3D8Caps->ExtentsAdjust                     = _pWineCaps->ExtentsAdjust; \
80     _pD3D8Caps->StencilCaps                       = _pWineCaps->StencilCaps; \
81     _pD3D8Caps->FVFCaps                           = _pWineCaps->FVFCaps; \
82     _pD3D8Caps->TextureOpCaps                     = _pWineCaps->TextureOpCaps; \
83     _pD3D8Caps->MaxTextureBlendStages             = _pWineCaps->MaxTextureBlendStages; \
84     _pD3D8Caps->MaxSimultaneousTextures           = _pWineCaps->MaxSimultaneousTextures; \
85     _pD3D8Caps->VertexProcessingCaps              = _pWineCaps->VertexProcessingCaps; \
86     _pD3D8Caps->MaxActiveLights                   = _pWineCaps->MaxActiveLights; \
87     _pD3D8Caps->MaxUserClipPlanes                 = _pWineCaps->MaxUserClipPlanes; \
88     _pD3D8Caps->MaxVertexBlendMatrices            = _pWineCaps->MaxVertexBlendMatrices; \
89     _pD3D8Caps->MaxVertexBlendMatrixIndex         = _pWineCaps->MaxVertexBlendMatrixIndex; \
90     _pD3D8Caps->MaxPointSize                      = _pWineCaps->MaxPointSize; \
91     _pD3D8Caps->MaxPrimitiveCount                 = _pWineCaps->MaxPrimitiveCount; \
92     _pD3D8Caps->MaxVertexIndex                    = _pWineCaps->MaxVertexIndex; \
93     _pD3D8Caps->MaxStreams                        = _pWineCaps->MaxStreams; \
94     _pD3D8Caps->MaxStreamStride                   = _pWineCaps->MaxStreamStride; \
95     _pD3D8Caps->VertexShaderVersion               = _pWineCaps->VertexShaderVersion; \
96     _pD3D8Caps->MaxVertexShaderConst              = _pWineCaps->MaxVertexShaderConst; \
97     _pD3D8Caps->PixelShaderVersion                = _pWineCaps->PixelShaderVersion; \
98     _pD3D8Caps->MaxPixelShaderValue               = _pWineCaps->PixelShader1xMaxValue;
99
100 void fixup_caps(WINED3DCAPS *pWineCaps) DECLSPEC_HIDDEN;
101
102 /* Direct3D8 Interfaces: */
103 typedef struct IDirect3DBaseTexture8Impl IDirect3DBaseTexture8Impl;
104 typedef struct IDirect3DVolumeTexture8Impl IDirect3DVolumeTexture8Impl;
105 typedef struct IDirect3D8Impl IDirect3D8Impl;
106 typedef struct IDirect3DDevice8Impl IDirect3DDevice8Impl;
107 typedef struct IDirect3DTexture8Impl IDirect3DTexture8Impl;
108 typedef struct IDirect3DCubeTexture8Impl IDirect3DCubeTexture8Impl;
109 typedef struct IDirect3DIndexBuffer8Impl IDirect3DIndexBuffer8Impl;
110 typedef struct IDirect3DSurface8Impl IDirect3DSurface8Impl;
111 typedef struct IDirect3DSwapChain8Impl IDirect3DSwapChain8Impl;
112 typedef struct IDirect3DVolume8Impl IDirect3DVolume8Impl;
113 typedef struct IDirect3DVertexBuffer8Impl IDirect3DVertexBuffer8Impl;
114 typedef struct IDirect3DVertexShader8Impl IDirect3DVertexShader8Impl;
115
116 /* ===========================================================================
117     The interfaces themselves
118    =========================================================================== */
119
120 /* ---------- */
121 /* IDirect3D8 */
122 /* ---------- */
123
124 /*****************************************************************************
125  * Predeclare the interface implementation structures
126  */
127 extern const IDirect3D8Vtbl Direct3D8_Vtbl DECLSPEC_HIDDEN;
128
129 /*****************************************************************************
130  * IDirect3D implementation structure
131  */
132 struct IDirect3D8Impl
133 {
134     IDirect3D8 IDirect3D8_iface;
135     LONG       ref;
136     struct wined3d *WineD3D;
137 };
138
139 /*****************************************************************************
140  * IDirect3DDevice8 implementation structure
141  */
142
143 #define D3D8_INITIAL_HANDLE_TABLE_SIZE 64
144 #define D3D8_INVALID_HANDLE ~0U
145
146 enum d3d8_handle_type
147 {
148     D3D8_HANDLE_FREE,
149     D3D8_HANDLE_VS,
150     D3D8_HANDLE_PS,
151     D3D8_HANDLE_SB,
152 };
153
154 struct d3d8_handle_entry
155 {
156     void *object;
157     enum d3d8_handle_type type;
158 };
159
160 struct d3d8_handle_table
161 {
162     struct d3d8_handle_entry *entries;
163     struct d3d8_handle_entry *free_entries;
164     UINT table_size;
165     UINT entry_count;
166 };
167
168 struct FvfToDecl
169 {
170     DWORD fvf;
171     struct IDirect3DVertexDeclaration8 *decl;
172 };
173
174 struct IDirect3DDevice8Impl
175 {
176     /* IUnknown fields */
177     IDirect3DDevice8        IDirect3DDevice8_iface;
178     IWineD3DDeviceParent    IWineD3DDeviceParent_iface;
179     LONG                    ref;
180 /* But what about baseVertexIndex in state blocks? hmm... it may be a better idea to pass this to wined3d */
181     IWineD3DDevice         *WineD3DDevice;
182     struct                  d3d8_handle_table handle_table;
183
184     /* FVF management */
185     struct FvfToDecl       *decls;
186     UINT                    numConvertedDecls, declArraySize;
187
188     /* Avoids recursion with nested ReleaseRef to 0 */
189     BOOL                    inDestruction;
190 };
191
192 HRESULT device_init(IDirect3DDevice8Impl *device, struct wined3d *wined3d, UINT adapter,
193         D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters) DECLSPEC_HIDDEN;
194
195 /* ---------------- */
196 /* IDirect3DVolume8 */
197 /* ---------------- */
198
199 /*****************************************************************************
200  * IDirect3DVolume8 implementation structure
201  */
202 struct IDirect3DVolume8Impl
203 {
204     IDirect3DVolume8    IDirect3DVolume8_iface;
205     LONG                ref;
206     struct wined3d_volume *wined3d_volume;
207     IUnknown *container;
208     IUnknown *forwardReference;
209 };
210
211 HRESULT volume_init(IDirect3DVolume8Impl *volume, IDirect3DDevice8Impl *device, UINT width, UINT height,
212         UINT depth, DWORD usage, enum wined3d_format_id format, WINED3DPOOL pool) DECLSPEC_HIDDEN;
213
214 /* ------------------- */
215 /* IDirect3DSwapChain8 */
216 /* ------------------- */
217
218 /*****************************************************************************
219  * IDirect3DSwapChain8 implementation structure
220  */
221 struct IDirect3DSwapChain8Impl
222 {
223     /* IUnknown fields */
224     IDirect3DSwapChain8 IDirect3DSwapChain8_iface;
225     LONG                ref;
226     struct wined3d_swapchain *wined3d_swapchain;
227     IDirect3DDevice8 *parentDevice;
228 };
229
230 HRESULT swapchain_init(IDirect3DSwapChain8Impl *swapchain, IDirect3DDevice8Impl *device,
231         D3DPRESENT_PARAMETERS *present_parameters) DECLSPEC_HIDDEN;
232
233 /* ----------------- */
234 /* IDirect3DSurface8 */
235 /* ----------------- */
236
237 /*****************************************************************************
238  * IDirect3DSurface8 implementation structure
239  */
240 struct IDirect3DSurface8Impl
241 {
242     /* IUnknown fields */
243     const IDirect3DSurface8Vtbl *lpVtbl;
244     LONG                         ref;
245
246     /* IDirect3DSurface8 fields */
247     IWineD3DSurface             *wineD3DSurface;
248
249     /* Parent reference */
250     LPDIRECT3DDEVICE8                  parentDevice;
251
252     /* The surface container */
253     IUnknown                    *container;
254
255     /* If set forward refcounting to this object */
256     IUnknown                    *forwardReference;
257 };
258
259 HRESULT surface_init(IDirect3DSurface8Impl *surface, IDirect3DDevice8Impl *device,
260         UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level,
261         DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality) DECLSPEC_HIDDEN;
262
263 /* ---------------------- */
264 /* IDirect3DVertexBuffer8 */
265 /* ---------------------- */
266
267 /*****************************************************************************
268  * IDirect3DVertexBuffer8 implementation structure
269  */
270 struct IDirect3DVertexBuffer8Impl
271 {
272     /* IUnknown fields */
273     const IDirect3DVertexBuffer8Vtbl *lpVtbl;
274     LONG                              ref;
275
276     struct wined3d_buffer *wineD3DVertexBuffer;
277     IDirect3DDevice8 *parentDevice;
278     DWORD fvf;
279 };
280
281 HRESULT vertexbuffer_init(IDirect3DVertexBuffer8Impl *buffer, IDirect3DDevice8Impl *device,
282         UINT size, DWORD usage, DWORD fvf, D3DPOOL pool) DECLSPEC_HIDDEN;
283
284 /* --------------------- */
285 /* IDirect3DIndexBuffer8 */
286 /* --------------------- */
287
288 /*****************************************************************************
289  * IDirect3DIndexBuffer8 implementation structure
290  */
291 struct IDirect3DIndexBuffer8Impl
292 {
293     /* IUnknown fields */
294     const IDirect3DIndexBuffer8Vtbl *lpVtbl;
295     LONG                             ref;
296
297     struct wined3d_buffer *wineD3DIndexBuffer;
298     IDirect3DDevice8 *parentDevice;
299     enum wined3d_format_id format;
300 };
301
302 HRESULT indexbuffer_init(IDirect3DIndexBuffer8Impl *buffer, IDirect3DDevice8Impl *device,
303         UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
304
305 /* --------------------- */
306 /* IDirect3DBaseTexture8 */
307 /* --------------------- */
308
309 /*****************************************************************************
310  * IDirect3DBaseTexture8 implementation structure
311  */
312 struct IDirect3DBaseTexture8Impl
313 {
314     /* IUnknown fields */
315     const IDirect3DBaseTexture8Vtbl *lpVtbl;
316     LONG                   ref;
317     struct wined3d_texture *wined3d_texture;
318 };
319
320 /* --------------------- */
321 /* IDirect3DCubeTexture8 */
322 /* --------------------- */
323
324 /*****************************************************************************
325  * IDirect3DCubeTexture8 implementation structure
326  */
327 struct IDirect3DCubeTexture8Impl
328 {
329     IDirect3DCubeTexture8   IDirect3DCubeTexture8_iface;
330     LONG                    ref;
331     struct wined3d_texture *wined3d_texture;
332     IDirect3DDevice8 *parentDevice;
333 };
334
335 HRESULT cubetexture_init(IDirect3DCubeTexture8Impl *texture, IDirect3DDevice8Impl *device,
336         UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
337
338 /* ----------------- */
339 /* IDirect3DTexture8 */
340 /* ----------------- */
341
342 /*****************************************************************************
343  * IDirect3DTexture8 implementation structure
344  */
345 struct IDirect3DTexture8Impl
346 {
347     IDirect3DTexture8   IDirect3DTexture8_iface;
348     LONG                ref;
349     struct wined3d_texture *wined3d_texture;
350     IDirect3DDevice8 *parentDevice;
351 };
352
353 HRESULT texture_init(IDirect3DTexture8Impl *texture, IDirect3DDevice8Impl *device,
354         UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
355
356 /* ----------------------- */
357 /* IDirect3DVolumeTexture8 */
358 /* ----------------------- */
359
360 /*****************************************************************************
361  * IDirect3DVolumeTexture8 implementation structure
362  */
363 struct IDirect3DVolumeTexture8Impl
364 {
365     IDirect3DVolumeTexture8 IDirect3DVolumeTexture8_iface;
366     LONG ref;
367     struct wined3d_texture *wined3d_texture;
368     IDirect3DDevice8 *parentDevice;
369 };
370
371 HRESULT volumetexture_init(IDirect3DVolumeTexture8Impl *texture, IDirect3DDevice8Impl *device,
372         UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
373
374 DEFINE_GUID(IID_IDirect3DVertexDeclaration8,
375 0x5dd7478d, 0xcbf3, 0x41a6, 0x8c, 0xfd, 0xfd, 0x19, 0x2b, 0x11, 0xc7, 0x90);
376
377 DEFINE_GUID(IID_IDirect3DVertexShader8,
378 0xefc5557e, 0x6265, 0x4613, 0x8a, 0x94, 0x43, 0x85, 0x78, 0x89, 0xeb, 0x36);
379
380 DEFINE_GUID(IID_IDirect3DPixelShader8,
381 0x6d3bdbdc, 0x5b02, 0x4415, 0xb8, 0x52, 0xce, 0x5e, 0x8b, 0xcc, 0xb2, 0x89);
382
383 /*****************************************************************************
384  * IDirect3DVertexDeclaration8 interface
385  */
386 #define INTERFACE IDirect3DVertexDeclaration8
387 DECLARE_INTERFACE_(IDirect3DVertexDeclaration8, IUnknown)
388 {
389     /*** IUnknown methods ***/
390     STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** obj_ptr) PURE;
391     STDMETHOD_(ULONG,AddRef)(THIS) PURE;
392     STDMETHOD_(ULONG,Release)(THIS) PURE;
393 };
394 #undef INTERFACE
395
396 /*** IUnknown methods ***/
397 #define IDirect3DVertexDeclaration8_QueryInterface(p,a,b)  (p)->lpVtbl->QueryInterface(p,a,b)
398 #define IDirect3DVertexDeclaration8_AddRef(p)              (p)->lpVtbl->AddRef(p)
399 #define IDirect3DVertexDeclaration8_Release(p)             (p)->lpVtbl->Release(p)
400
401 typedef struct {
402     const IDirect3DVertexDeclaration8Vtbl *lpVtbl;
403     LONG ref_count;
404
405     DWORD *elements;
406     DWORD elements_size; /* Size of elements, in bytes */
407
408     struct wined3d_vertex_declaration *wined3d_vertex_declaration;
409     DWORD shader_handle;
410 } IDirect3DVertexDeclaration8Impl;
411
412 HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration8Impl *declaration,
413         IDirect3DDevice8Impl *device, const DWORD *elements, DWORD shader_handle) DECLSPEC_HIDDEN;
414 HRESULT vertexdeclaration_init_fvf(IDirect3DVertexDeclaration8Impl *declaration,
415         IDirect3DDevice8Impl *device, DWORD fvf) DECLSPEC_HIDDEN;
416
417 /*****************************************************************************
418  * IDirect3DVertexShader8 interface
419  */
420 #define INTERFACE IDirect3DVertexShader8
421 DECLARE_INTERFACE_(IDirect3DVertexShader8, IUnknown)
422 {
423     /*** IUnknown methods ***/
424     STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
425     STDMETHOD_(ULONG,AddRef)(THIS) PURE;
426     STDMETHOD_(ULONG,Release)(THIS) PURE;
427 };
428 #undef INTERFACE
429
430 /*** IUnknown methods ***/
431 #define IDirect3DVertexShader8_QueryInterface(p,a,b)  (p)->lpVtbl->QueryInterface(p,a,b)
432 #define IDirect3DVertexShader8_AddRef(p)              (p)->lpVtbl->AddRef(p)
433 #define IDirect3DVertexShader8_Release(p)             (p)->lpVtbl->Release(p)
434
435 /* ------------------------- */
436 /* IDirect3DVertexShader8Impl */
437 /* ------------------------- */
438
439 /*****************************************************************************
440  * IDirect3DPixelShader8 interface
441  */
442 #define INTERFACE IDirect3DPixelShader8
443 DECLARE_INTERFACE_(IDirect3DPixelShader8,IUnknown)
444 {
445     /*** IUnknown methods ***/
446     STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
447     STDMETHOD_(ULONG,AddRef)(THIS) PURE;
448     STDMETHOD_(ULONG,Release)(THIS) PURE;
449 };
450 #undef INTERFACE
451
452 /*** IUnknown methods ***/
453 #define IDirect3DPixelShader8_QueryInterface(p,a,b)  (p)->lpVtbl->QueryInterface(p,a,b)
454 #define IDirect3DPixelShader8_AddRef(p)              (p)->lpVtbl->AddRef(p)
455 #define IDirect3DPixelShader8_Release(p)             (p)->lpVtbl->Release(p)
456
457 /*****************************************************************************
458  * IDirect3DVertexShader implementation structure
459  */
460
461 struct IDirect3DVertexShader8Impl {
462   IDirect3DVertexShader8            IDirect3DVertexShader8_iface;
463   LONG                              ref;
464   IDirect3DVertexDeclaration8 *vertex_declaration;
465   struct wined3d_shader *wined3d_shader;
466 };
467
468 HRESULT vertexshader_init(IDirect3DVertexShader8Impl *shader, IDirect3DDevice8Impl *device,
469         const DWORD *declaration, const DWORD *byte_code, DWORD shader_handle, DWORD usage) DECLSPEC_HIDDEN;
470
471 #define D3D8_MAX_VERTEX_SHADER_CONSTANTF 256
472
473 /*****************************************************************************
474  * IDirect3DPixelShader implementation structure
475  */
476 typedef struct IDirect3DPixelShader8Impl {
477     IDirect3DPixelShader8            IDirect3DPixelShader8_iface;
478     LONG                             ref;
479     DWORD handle;
480     struct wined3d_shader *wined3d_shader;
481 } IDirect3DPixelShader8Impl;
482
483 HRESULT pixelshader_init(IDirect3DPixelShader8Impl *shader, IDirect3DDevice8Impl *device,
484         const DWORD *byte_code, DWORD shader_handle) DECLSPEC_HIDDEN;
485
486 D3DFORMAT d3dformat_from_wined3dformat(enum wined3d_format_id format) DECLSPEC_HIDDEN;
487 enum wined3d_format_id wined3dformat_from_d3dformat(D3DFORMAT format) DECLSPEC_HIDDEN;
488 void load_local_constants(const DWORD *d3d8_elements, struct wined3d_shader *wined3d_vertex_shader) DECLSPEC_HIDDEN;
489 size_t parse_token(const DWORD *pToken) DECLSPEC_HIDDEN;
490
491 #endif /* __WINE_D3DX8_PRIVATE_H */