Special case Win9x platforms in the desktop visibility test, in Win98
[wine] / dlls / ddraw / d3d_private.h
1 /* Direct3D private include file
2  * Copyright (c) 1998-2004 Lionel ULMER
3  * Copyright (c) 2002-2004 Christian Costa
4  *
5  * This file contains all the structure that are not exported
6  * through d3d.h and all common macros.
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #ifndef __GRAPHICS_WINE_D3D_PRIVATE_H
24 #define __GRAPHICS_WINE_D3D_PRIVATE_H
25
26 /* THIS FILE MUST NOT CONTAIN X11 or MESA DEFINES */
27
28 #include <stdarg.h>
29
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "d3d.h"
34
35 #define MAX_TEXTURES 8
36 #define MAX_LIGHTS  16
37
38 #define HIGHEST_RENDER_STATE         152
39 #define HIGHEST_TEXTURE_STAGE_STATE   24
40
41 /*****************************************************************************
42  * Predeclare the interface implementation structures
43  */
44 typedef struct IDirect3DLightImpl IDirect3DLightImpl;
45 typedef struct IDirect3DMaterialImpl IDirect3DMaterialImpl;
46 typedef struct IDirect3DViewportImpl IDirect3DViewportImpl;
47 typedef struct IDirect3DExecuteBufferImpl IDirect3DExecuteBufferImpl;
48 typedef struct IDirect3DVertexBufferImpl IDirect3DVertexBufferImpl;
49
50 #include "ddraw_private.h"
51
52 typedef struct STATEBLOCKFLAGS {
53    BOOL render_state[HIGHEST_RENDER_STATE];
54    BOOL texture_stage_state[MAX_TEXTURES][HIGHEST_TEXTURE_STAGE_STATE];
55 } STATEBLOCKFLAGS;
56
57 typedef struct STATEBLOCK {
58    STATEBLOCKFLAGS set_flags; 
59    DWORD render_state[HIGHEST_RENDER_STATE];
60    DWORD texture_stage_state[MAX_TEXTURES][HIGHEST_TEXTURE_STAGE_STATE];
61 } STATEBLOCK;
62
63
64 /*****************************************************************************
65  * IDirect3DLight implementation structure
66  */
67 struct IDirect3DLightImpl
68 {
69     ICOM_VFIELD_MULTI(IDirect3DLight);
70     DWORD ref;
71     /* IDirect3DLight fields */
72     IDirectDrawImpl *d3d;
73     /* If this light is active for one viewport, put the viewport here */
74     IDirect3DViewportImpl *active_viewport;
75
76     D3DLIGHT2 light;
77     D3DLIGHT7 light7;
78
79     DWORD dwLightIndex;
80
81     /* Chained list used for adding / removing from viewports */
82     IDirect3DLightImpl *next;
83
84     /* Activation function */
85     void (*activate)(IDirect3DLightImpl*);
86     void (*desactivate)(IDirect3DLightImpl*);
87     void (*update)(IDirect3DLightImpl*);
88 };
89
90 /*****************************************************************************
91  * IDirect3DMaterial implementation structure
92  */
93 struct IDirect3DMaterialImpl
94 {
95     ICOM_VFIELD_MULTI(IDirect3DMaterial3);
96     ICOM_VFIELD_MULTI(IDirect3DMaterial2);
97     ICOM_VFIELD_MULTI(IDirect3DMaterial);
98     DWORD  ref;
99     /* IDirect3DMaterial2 fields */
100     IDirectDrawImpl *d3d;
101     IDirect3DDeviceImpl *active_device;
102
103     D3DMATERIAL mat;
104
105     void (*activate)(IDirect3DMaterialImpl* this);
106 };
107
108 /*****************************************************************************
109  * IDirect3DViewport implementation structure
110  */
111 struct IDirect3DViewportImpl
112 {
113     ICOM_VFIELD_MULTI(IDirect3DViewport3);
114     DWORD ref;
115     /* IDirect3DViewport fields */
116     IDirectDrawImpl *d3d;
117     /* If this viewport is active for one device, put the device here */
118     IDirect3DDeviceImpl *active_device;
119
120     DWORD num_lights;
121     DWORD map_lights;
122
123     int use_vp2;
124     union {
125         D3DVIEWPORT vp1;
126         D3DVIEWPORT2 vp2;
127     } viewports;
128
129     /* Activation function */
130     void (*activate)(IDirect3DViewportImpl*);
131
132     /* Field used to chain viewports together */
133     IDirect3DViewportImpl *next;
134
135     /* Lights list */
136     IDirect3DLightImpl *lights;
137
138     /* Background material */
139     IDirect3DMaterialImpl *background;
140 };
141
142 /*****************************************************************************
143  * IDirect3DExecuteBuffer implementation structure
144  */
145 struct IDirect3DExecuteBufferImpl
146 {
147     ICOM_VFIELD_MULTI(IDirect3DExecuteBuffer);
148     DWORD ref;
149     /* IDirect3DExecuteBuffer fields */
150     IDirectDrawImpl *d3d;
151     IDirect3DDeviceImpl* d3ddev;
152
153     D3DEXECUTEBUFFERDESC desc;
154     D3DEXECUTEDATA data;
155
156     /* This buffer will store the transformed vertices */
157     void* vertex_data;
158     WORD* indices;
159     int nb_indices;
160
161     /* This flags is set to TRUE if we allocated ourselves the
162        data buffer */
163     BOOL need_free;
164
165     void (*execute)(IDirect3DExecuteBufferImpl* this,
166                     IDirect3DDeviceImpl* dev,
167                     IDirect3DViewportImpl* vp);
168 };
169
170 /* Internal structure to store the state of the clipping planes */
171 typedef struct d3d7clippingplane 
172 {
173     D3DVALUE plane[4];
174 } d3d7clippingplane;
175
176 /*****************************************************************************
177  * IDirect3DDevice implementation structure
178  */
179
180 #define WORLDMAT_CHANGED (0x00000001 <<  0)
181 #define VIEWMAT_CHANGED  (0x00000001 <<  1)
182 #define PROJMAT_CHANGED  (0x00000001 <<  2)
183 #define TEXMAT0_CHANGED  (0x00000001 <<  3)
184 #define TEXMAT1_CHANGED  (0x00000001 <<  4)
185 #define TEXMAT2_CHANGED  (0x00000001 <<  5)
186 #define TEXMAT3_CHANGED  (0x00000001 <<  6)
187 #define TEXMAT4_CHANGED  (0x00000001 <<  7)
188 #define TEXMAT5_CHANGED  (0x00000001 <<  8)
189 #define TEXMAT6_CHANGED  (0x00000001 <<  9)
190 #define TEXMAT7_CHANGED  (0x00000001 << 10)
191
192 struct IDirect3DDeviceImpl
193 {
194     ICOM_VFIELD_MULTI(IDirect3DDevice7);
195     ICOM_VFIELD_MULTI(IDirect3DDevice3);
196     ICOM_VFIELD_MULTI(IDirect3DDevice2);
197     ICOM_VFIELD_MULTI(IDirect3DDevice);
198     DWORD  ref;
199
200     /* Version of the Direct3D object from which the device has been created */
201     DWORD version;
202
203     /* IDirect3DDevice fields */
204     IDirectDrawImpl *d3d;
205     IDirectDrawSurfaceImpl *surface;
206
207     IDirect3DViewportImpl *viewport_list;
208     IDirect3DViewportImpl *current_viewport;
209     D3DVIEWPORT7 active_viewport;
210
211     IDirectDrawSurfaceImpl *current_texture[MAX_TEXTURES];
212     IDirectDrawSurfaceImpl *current_zbuffer;
213     
214     /* Current transformation matrices */
215     D3DMATRIX *world_mat;
216     D3DMATRIX *view_mat;
217     D3DMATRIX *proj_mat;
218     D3DMATRIX *tex_mat[MAX_TEXTURES];
219     BOOLEAN tex_mat_is_identity[MAX_TEXTURES];
220     
221     /* Current material used in D3D7 mode */
222     D3DMATERIAL7 current_material;
223
224     /* Light state */
225     DWORD material;
226
227     /* Light parameters */
228     DWORD active_lights, set_lights;
229     D3DLIGHT7 light_parameters[MAX_LIGHTS];
230
231     /* clipping planes */
232     DWORD max_clipping_planes;
233     d3d7clippingplane *clipping_planes;
234     
235     void (*set_context)(IDirect3DDeviceImpl*);
236     HRESULT (*clear)(IDirect3DDeviceImpl *This,
237                      DWORD dwCount,
238                      LPD3DRECT lpRects,
239                      DWORD dwFlags,
240                      DWORD dwColor,
241                      D3DVALUE dvZ,
242                      DWORD dwStencil);
243     void (*matrices_updated)(IDirect3DDeviceImpl *This, DWORD matrices);
244     void (*set_matrices)(IDirect3DDeviceImpl *This, DWORD matrices,
245                          D3DMATRIX *world_mat, D3DMATRIX *view_mat, D3DMATRIX *proj_mat);
246     void (*flush_to_framebuffer)(IDirect3DDeviceImpl *This, LPCRECT pRect, IDirectDrawSurfaceImpl *surf);
247
248     STATEBLOCK state_block;
249
250     /* Used to prevent locks and rendering to overlap */
251     CRITICAL_SECTION crit;
252 };
253
254 /*****************************************************************************
255  * IDirect3DVertexBuffer implementation structure
256  */
257 struct IDirect3DVertexBufferImpl
258 {
259     ICOM_VFIELD_MULTI(IDirect3DVertexBuffer7);
260     ICOM_VFIELD_MULTI(IDirect3DVertexBuffer);
261     DWORD ref;
262     IDirectDrawImpl *d3d;
263     D3DVERTEXBUFFERDESC desc;
264     LPVOID *vertices;
265     DWORD vertex_buffer_size;
266
267     BOOLEAN processed;
268 };
269
270 /* Various dump and helper functions */
271 extern const char *_get_renderstate(D3DRENDERSTATETYPE type);
272 extern void dump_D3DMATERIAL7(LPD3DMATERIAL7 lpMat);
273 extern void dump_D3DCOLORVALUE(D3DCOLORVALUE *lpCol);
274 extern void dump_D3DLIGHT7(LPD3DLIGHT7 lpLight);
275 extern void dump_DPFLAGS(DWORD dwFlags);
276 extern void dump_D3DMATRIX(D3DMATRIX *mat);
277 extern void dump_D3DVECTOR(D3DVECTOR *lpVec);
278 extern void dump_flexible_vertex(DWORD d3dvtVertexType);
279 extern DWORD get_flexible_vertex_size(DWORD d3dvtVertexType);
280 extern void convert_FVF_to_strided_data(DWORD d3dvtVertexType, LPVOID lpvVertices, D3DDRAWPRIMITIVESTRIDEDDATA *strided, DWORD dwStartVertex);
281 extern void dump_D3DVOP(DWORD dwVertexOp);
282 extern void dump_D3DPV(DWORD dwFlags);
283 extern void multiply_matrix(LPD3DMATRIX,LPD3DMATRIX,LPD3DMATRIX);
284
285 extern const float id_mat[16];
286
287 #endif /* __GRAPHICS_WINE_D3D_PRIVATE_H */