Replace 10000000 with TICKSPERSEC to make it more obvious what the
[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     /* IDirect3DDevice fields */
201     IDirectDrawImpl *d3d;
202     IDirectDrawSurfaceImpl *surface;
203
204     IDirect3DViewportImpl *viewport_list;
205     IDirect3DViewportImpl *current_viewport;
206     D3DVIEWPORT7 active_viewport;
207
208     IDirectDrawSurfaceImpl *current_texture[MAX_TEXTURES];
209     IDirectDrawSurfaceImpl *current_zbuffer;
210     
211     /* Current transformation matrices */
212     D3DMATRIX *world_mat;
213     D3DMATRIX *view_mat;
214     D3DMATRIX *proj_mat;
215     D3DMATRIX *tex_mat[MAX_TEXTURES];
216     BOOLEAN tex_mat_is_identity[MAX_TEXTURES];
217     
218     /* Current material used in D3D7 mode */
219     D3DMATERIAL7 current_material;
220
221     /* Light state */
222     DWORD material;
223
224     /* Light parameters */
225     DWORD active_lights, set_lights;
226     D3DLIGHT7 light_parameters[MAX_LIGHTS];
227
228     /* clipping planes */
229     DWORD max_clipping_planes;
230     d3d7clippingplane *clipping_planes;
231     
232     void (*set_context)(IDirect3DDeviceImpl*);
233     HRESULT (*clear)(IDirect3DDeviceImpl *This,
234                      DWORD dwCount,
235                      LPD3DRECT lpRects,
236                      DWORD dwFlags,
237                      DWORD dwColor,
238                      D3DVALUE dvZ,
239                      DWORD dwStencil);
240     void (*matrices_updated)(IDirect3DDeviceImpl *This, DWORD matrices);
241     void (*set_matrices)(IDirect3DDeviceImpl *This, DWORD matrices,
242                          D3DMATRIX *world_mat, D3DMATRIX *view_mat, D3DMATRIX *proj_mat);
243     void (*flush_to_framebuffer)(IDirect3DDeviceImpl *This, LPCRECT pRect, IDirectDrawSurfaceImpl *surf);
244
245     STATEBLOCK state_block;
246
247     /* Used to prevent locks and rendering to overlap */
248     CRITICAL_SECTION crit;
249 };
250
251 /*****************************************************************************
252  * IDirect3DVertexBuffer implementation structure
253  */
254 struct IDirect3DVertexBufferImpl
255 {
256     ICOM_VFIELD_MULTI(IDirect3DVertexBuffer7);
257     ICOM_VFIELD_MULTI(IDirect3DVertexBuffer);
258     DWORD ref;
259     IDirectDrawImpl *d3d;
260     D3DVERTEXBUFFERDESC desc;
261     LPVOID *vertices;
262     DWORD vertex_buffer_size;
263
264     BOOLEAN processed;
265 };
266
267 /* Various dump and helper functions */
268 extern const char *_get_renderstate(D3DRENDERSTATETYPE type);
269 extern void dump_D3DMATERIAL7(LPD3DMATERIAL7 lpMat);
270 extern void dump_D3DCOLORVALUE(D3DCOLORVALUE *lpCol);
271 extern void dump_D3DLIGHT7(LPD3DLIGHT7 lpLight);
272 extern void dump_DPFLAGS(DWORD dwFlags);
273 extern void dump_D3DMATRIX(D3DMATRIX *mat);
274 extern void dump_D3DVECTOR(D3DVECTOR *lpVec);
275 extern void dump_flexible_vertex(DWORD d3dvtVertexType);
276 extern DWORD get_flexible_vertex_size(DWORD d3dvtVertexType);
277 extern void convert_FVF_to_strided_data(DWORD d3dvtVertexType, LPVOID lpvVertices, D3DDRAWPRIMITIVESTRIDEDDATA *strided, DWORD dwStartVertex);
278 extern void dump_D3DVOP(DWORD dwVertexOp);
279 extern void dump_D3DPV(DWORD dwFlags);
280 extern void multiply_matrix(LPD3DMATRIX,LPD3DMATRIX,LPD3DMATRIX);
281
282 extern const float id_mat[16];
283
284 #endif /* __GRAPHICS_WINE_D3D_PRIVATE_H */