ReadConsoleA: use ir as pointer to (req+1).
[wine] / graphics / d3d_private.h
1 /* Direct3D private include file
2    (c) 1998 Lionel ULMER
3    
4    This files contains all the structure that are not exported
5    through d3d.h and all common macros. */
6
7 #ifndef __GRAPHICS_WINE_D3D_PRIVATE_H
8 #define __GRAPHICS_WINE_D3D_PRIVATE_H
9
10 #include "wine_gl.h"
11 #include "d3d.h"
12
13 #include "x11drv.h"
14
15 #undef USE_OSMESA
16
17 /*****************************************************************************
18  * Predeclare the interface implementation structures
19  */
20 typedef struct IDirect3DImpl IDirect3DImpl;
21 typedef struct IDirect3D2Impl IDirect3D2Impl;
22 typedef struct IDirect3DLightImpl IDirect3DLightImpl;
23 typedef struct IDirect3DMaterial2Impl IDirect3DMaterial2Impl;
24 typedef struct IDirect3DTexture2Impl IDirect3DTexture2Impl;
25 typedef struct IDirect3DViewport2Impl IDirect3DViewport2Impl;
26 typedef struct IDirect3DExecuteBufferImpl IDirect3DExecuteBufferImpl;
27 typedef struct IDirect3DDeviceImpl IDirect3DDeviceImpl;
28 typedef struct IDirect3DDevice2Impl IDirect3DDevice2Impl;
29
30 #include "ddraw_private.h"
31
32 /*****************************************************************************
33  * IDirect3D implementation structure
34  */
35 struct IDirect3DImpl
36 {
37     /* IUnknown fields */
38     ICOM_VTABLE(IDirect3D)* lpvtbl;
39     DWORD                   ref;
40     /* IDirect3D fields */
41     IDirectDrawImpl* ddraw;
42 };
43
44 /*****************************************************************************
45  * IDirect3D2 implementation structure
46  */
47 struct IDirect3D2Impl
48 {
49     /* IUnknown fields */
50     ICOM_VTABLE(IDirect3D2)* lpvtbl;
51     DWORD                    ref;
52     /* IDirect3D2 fields */
53     IDirectDrawImpl* ddraw;
54 };
55
56 /*****************************************************************************
57  * IDirect3DLight implementation structure
58  */
59 struct IDirect3DLightImpl
60 {
61     /* IUnknown fields */
62     ICOM_VTABLE(IDirect3DLight)* lpvtbl;
63     DWORD                        ref;
64     /* IDirect3DLight fields */
65     union {
66         IDirect3DImpl*  d3d1;
67         IDirect3D2Impl* d3d2;
68     } d3d;
69     int                 type;
70   
71     D3DLIGHT2           light;
72
73     /* Chained list used for adding / removing from viewports */
74     IDirect3DLightImpl *next, *prev;
75
76     /* Activation function */
77     void (*activate)(IDirect3DLightImpl*);
78     int                 is_active;
79   
80     /* Awful OpenGL code !!! */
81 #ifdef HAVE_MESAGL
82     GLenum              light_num;
83 #endif
84 };
85
86 /*****************************************************************************
87  * IDirect3DMaterial2 implementation structure
88  */
89 struct IDirect3DMaterial2Impl
90 {
91     /* IUnknown fields */
92     ICOM_VTABLE(IDirect3DMaterial2)* lpvtbl;
93     DWORD                            ref;
94     /* IDirect3DMaterial2 fields */
95     union {
96         IDirect3DImpl*        d3d1;
97         IDirect3D2Impl*       d3d2;
98     } d3d;
99     union {
100         IDirect3DDeviceImpl*  active_device1;
101         IDirect3DDevice2Impl* active_device2;
102     } device;
103     int                       use_d3d2;
104
105     D3DMATERIAL               mat;
106
107     void (*activate)(IDirect3DMaterial2Impl* this);
108 };
109
110 /*****************************************************************************
111  * IDirect3DTexture2 implementation structure
112  */
113 struct IDirect3DTexture2Impl
114 {
115     /* IUnknown fields */
116     ICOM_VTABLE(IDirect3DTexture2)* lpvtbl;
117     DWORD                           ref;
118     /* IDirect3DTexture2 fields */
119     void*                    D3Ddevice; /* I put (void *) to use the same pointer for both
120                                            Direct3D and Direct3D2 */
121 #ifdef HAVE_MESAGL
122     GLuint                   tex_name;
123 #endif  
124     IDirectDrawSurface4Impl* surface;
125 };
126
127 /*****************************************************************************
128  * IDirect3DViewport2 implementation structure
129  */
130 struct IDirect3DViewport2Impl
131 {
132     /* IUnknown fields */
133     ICOM_VTABLE(IDirect3DViewport2)* lpvtbl;
134     DWORD                            ref;
135     /* IDirect3DViewport2 fields */
136     union {
137         IDirect3DImpl*        d3d1;
138         IDirect3D2Impl*       d3d2;
139     } d3d;
140     /* If this viewport is active for one device, put the device here */
141     union {
142         IDirect3DDeviceImpl*  active_device1;
143         IDirect3DDevice2Impl* active_device2;
144     } device;
145     int                       use_d3d2;
146
147     union {
148         D3DVIEWPORT           vp1;
149         D3DVIEWPORT2          vp2;
150     } viewport;
151     int                       use_vp2;
152
153   /* Activation function */
154   void (*activate)(IDirect3DViewport2Impl*);
155   
156   /* Field used to chain viewports together */
157   IDirect3DViewport2Impl*     next;
158
159   /* Lights list */
160   IDirect3DLightImpl*         lights;
161
162   /* OpenGL code */
163 #ifdef HAVE_MESAGL
164   GLenum                      nextlight;
165 #endif
166 };
167
168 /*****************************************************************************
169  * IDirect3DExecuteBuffer implementation structure
170  */
171 struct IDirect3DExecuteBufferImpl
172 {
173     /* IUnknown fields */
174     ICOM_VTABLE(IDirect3DExecuteBuffer)* lpvtbl;
175     DWORD                                ref;
176     /* IDirect3DExecuteBuffer fields */
177     IDirect3DDeviceImpl* d3ddev;
178
179     D3DEXECUTEBUFFERDESC desc;
180     D3DEXECUTEDATA data;
181
182     /* This buffer will store the transformed vertices */
183     void* vertex_data;
184     D3DVERTEXTYPE vertex_type;
185
186     /* This flags is set to TRUE if we allocated ourselves the
187        data buffer */
188     BOOL need_free;
189
190     void (*execute)(IDirect3DExecuteBuffer* this,
191                     IDirect3DDevice* dev,
192                     IDirect3DViewport2* vp);
193 };
194
195 /*****************************************************************************
196  * IDirect3DDevice implementation structure
197  */
198 struct IDirect3DDeviceImpl
199 {
200     /* IUnknown fields */
201     ICOM_VTABLE(IDirect3DDevice)* lpvtbl;
202     DWORD                         ref;
203     /* IDirect3DDevice fields */
204     IDirect3DImpl*          d3d;
205     IDirectDrawSurfaceImpl* surface;
206
207     IDirect3DViewport2Impl*  viewport_list;
208     IDirect3DViewport2Impl*  current_viewport;
209
210     void (*set_context)(IDirect3DDeviceImpl*);
211 };
212
213 /*****************************************************************************
214  * IDirect3DDevice2 implementation structure
215  */
216 struct IDirect3DDevice2Impl
217 {
218     /* IUnknown fields */
219     ICOM_VTABLE(IDirect3DDevice2)* lpvtbl;
220     DWORD                          ref;
221     /* IDirect3DDevice fields */
222     IDirect3D2Impl*         d3d;
223     IDirectDrawSurfaceImpl* surface;
224
225     IDirect3DViewport2Impl* viewport_list;
226     IDirect3DViewport2Impl* current_viewport;
227
228     void (*set_context)(IDirect3DDevice2Impl*);
229 };
230
231
232
233 #ifdef HAVE_MESAGL
234
235 #ifdef USE_OSMESA
236 #define LEAVE_GL() ;
237 #define ENTER_GL() ;
238 #else
239 #define LEAVE_GL() LeaveCriticalSection( &X11DRV_CritSection )
240 #define ENTER_GL() EnterCriticalSection( &X11DRV_CritSection )
241 #endif
242
243 /* Matrix copy WITH transposition */
244 #define conv_mat2(mat,gl_mat)                   \
245 {                                               \
246   TRACE(ddraw, "%f %f %f %f\n", (mat)->_11, (mat)->_12, (mat)->_13, (mat)->_14); \
247   TRACE(ddraw, "%f %f %f %f\n", (mat)->_21, (mat)->_22, (mat)->_23, (mat)->_24); \
248   TRACE(ddraw, "%f %f %f %f\n", (mat)->_31, (mat)->_32, (mat)->_33, (mat)->_34); \
249   TRACE(ddraw, "%f %f %f %f\n", (mat)->_41, (mat)->_42, (mat)->_43, (mat)->_44); \
250   (gl_mat)[ 0] = (mat)->_11;                    \
251   (gl_mat)[ 1] = (mat)->_21;                    \
252   (gl_mat)[ 2] = (mat)->_31;                    \
253   (gl_mat)[ 3] = (mat)->_41;                    \
254   (gl_mat)[ 4] = (mat)->_12;                    \
255   (gl_mat)[ 5] = (mat)->_22;                    \
256   (gl_mat)[ 6] = (mat)->_32;                    \
257   (gl_mat)[ 7] = (mat)->_42;                    \
258   (gl_mat)[ 8] = (mat)->_13;                    \
259   (gl_mat)[ 9] = (mat)->_23;                    \
260   (gl_mat)[10] = (mat)->_33;                    \
261   (gl_mat)[11] = (mat)->_43;                    \
262   (gl_mat)[12] = (mat)->_14;                    \
263   (gl_mat)[13] = (mat)->_24;                    \
264   (gl_mat)[14] = (mat)->_34;                    \
265   (gl_mat)[15] = (mat)->_44;                    \
266 };
267
268 /* Matrix copy WITHOUT transposition */
269 #define conv_mat(mat,gl_mat)                    \
270 {                                               \
271   TRACE(ddraw, "%f %f %f %f\n", (mat)->_11, (mat)->_12, (mat)->_13, (mat)->_14); \
272   TRACE(ddraw, "%f %f %f %f\n", (mat)->_21, (mat)->_22, (mat)->_23, (mat)->_24); \
273   TRACE(ddraw, "%f %f %f %f\n", (mat)->_31, (mat)->_32, (mat)->_33, (mat)->_34); \
274   TRACE(ddraw, "%f %f %f %f\n", (mat)->_41, (mat)->_42, (mat)->_43, (mat)->_44); \
275   memcpy(gl_mat, (mat), 16 * sizeof(float));      \
276 };
277
278 #define dump_mat(mat) \
279   TRACE(ddraw, "%f %f %f %f\n", (mat)->_11, (mat)->_12, (mat)->_13, (mat)->_14); \
280   TRACE(ddraw, "%f %f %f %f\n", (mat)->_21, (mat)->_22, (mat)->_23, (mat)->_24); \
281   TRACE(ddraw, "%f %f %f %f\n", (mat)->_31, (mat)->_32, (mat)->_33, (mat)->_34); \
282   TRACE(ddraw, "%f %f %f %f\n", (mat)->_41, (mat)->_42, (mat)->_43, (mat)->_44);
283
284 typedef struct render_state {
285   /* This is used for the device mode */
286   GLenum src, dst;
287   /* This is used for textures */
288   GLenum mag, min;
289 } RenderState;
290
291 typedef struct OpenGL_IDirect3DDevice2 {
292   IDirect3DDevice2Impl common;
293   
294   /* These are the OpenGL-specific variables */
295 #ifdef USE_OSMESA
296   OSMesaContext ctx;
297   unsigned char *buffer;
298 #else
299   GLXContext ctx;
300 #endif
301   
302   /* The current render state */
303   RenderState rs;
304
305   /* The last type of vertex drawn */
306   D3DVERTEXTYPE vt;
307   
308   float world_mat[16];
309   float view_mat[16];
310   float proj_mat[16];
311 } OpenGL_IDirect3DDevice2;
312
313 typedef struct OpenGL_IDirect3DDevice {
314   IDirect3DDeviceImpl common;
315   
316   /* These are the OpenGL-specific variables */
317 #ifdef USE_OSMESA
318   OSMesaContext ctx;
319   unsigned char *buffer;
320 #else
321   GLXContext ctx;
322 #endif
323   
324   /* The current render state */
325   RenderState rs;
326   
327   D3DMATRIX *world_mat;
328   D3DMATRIX *view_mat;
329   D3DMATRIX *proj_mat;
330 } OpenGL_IDirect3DDevice;
331
332 #define _dump_colorvalue(s,v)                      \
333   TRACE(ddraw, " " s " : %f %f %f %f\n",           \
334         (v).r.r, (v).g.g, (v).b.b, (v).a.a);
335
336 /* Common functions defined in d3dcommon.c */
337 void set_render_state(D3DRENDERSTATETYPE dwRenderStateType,
338                       DWORD dwRenderState, RenderState *rs) ;
339
340 #endif /* HAVE_MESAGL */
341
342 /* All non-static functions 'exported' by various sub-objects */
343 extern LPDIRECT3DTEXTURE2 d3dtexture2_create(IDirectDrawSurface4Impl* surf);
344 extern LPDIRECT3DTEXTURE d3dtexture_create(IDirectDrawSurface4Impl* surf);
345
346 extern LPDIRECT3DLIGHT d3dlight_create_dx3(IDirect3DImpl* d3d1);
347 extern LPDIRECT3DLIGHT d3dlight_create(IDirect3D2Impl* d3d2);
348
349 extern LPDIRECT3DEXECUTEBUFFER d3dexecutebuffer_create(IDirect3DDeviceImpl* d3ddev, LPD3DEXECUTEBUFFERDESC lpDesc);
350
351 extern LPDIRECT3DMATERIAL d3dmaterial_create(IDirect3DImpl* d3d1);
352 extern LPDIRECT3DMATERIAL2 d3dmaterial2_create(IDirect3D2Impl* d3d2);
353
354 extern LPDIRECT3DVIEWPORT d3dviewport_create(IDirect3DImpl* d3d1);
355 extern LPDIRECT3DVIEWPORT2 d3dviewport2_create(IDirect3D2Impl* d3d2);
356
357 extern int is_OpenGL_dx3(REFCLSID rguid, IDirectDrawSurfaceImpl* surface, IDirect3DDeviceImpl** device);
358 extern int d3d_OpenGL_dx3(LPD3DENUMDEVICESCALLBACK cb, LPVOID context) ;
359 extern int d3d_OpenGL(LPD3DENUMDEVICESCALLBACK cb, LPVOID context) ;
360 extern int is_OpenGL(REFCLSID rguid, IDirectDrawSurfaceImpl* surface, IDirect3DDevice2Impl** device, IDirect3D2Impl* d3d);
361
362
363 #endif /* __GRAPHICS_WINE_D3D_PRIVATE_H */