Avoid crashes in ddraw.dll when loading it without x11drv, for
[wine] / dlls / ddraw / mesa_private.h
1 /* MESA private include file
2  * Copyright (c) 1998 Lionel ULMER
3  *
4  * This file contains all structures that are not exported
5  * through d3d.h and all common macros.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #ifndef __GRAPHICS_WINE_MESA_PRIVATE_H
23 #define __GRAPHICS_WINE_MESA_PRIVATE_H
24
25 #include "d3d_private.h"
26
27 #ifdef HAVE_OPENGL
28
29 #include "gl_private.h"
30
31 /* X11 locking */
32
33 extern void (*wine_tsx11_lock_ptr)(void);
34 extern void (*wine_tsx11_unlock_ptr)(void);
35
36 /* As GLX relies on X, this is needed */
37 #define ENTER_GL() wine_tsx11_lock_ptr()
38 #define LEAVE_GL() wine_tsx11_unlock_ptr()
39
40 extern const GUID IID_D3DDEVICE_OpenGL;
41
42 typedef enum {
43     SURFACE_GL,
44     SURFACE_MEMORY,
45     SURFACE_MEMORY_DIRTY
46 } SURFACE_STATE;
47
48 /* This structure is used for the 'd3d_private' field of the IDirectDraw structure */
49 typedef struct IDirect3DGLImpl
50 {
51     DWORD free_lights;
52     void (*light_released)(IDirectDrawImpl *, GLenum light_num);
53 } IDirect3DGLImpl;
54
55 typedef struct IDirect3DLightGLImpl
56 {
57     struct IDirect3DLightImpl parent;
58     GLenum light_num;
59 } IDirect3DLightGLImpl;
60
61 /* This structure is used for the 'private' field of the IDirectDrawSurfaceImpl structure */
62 typedef struct IDirect3DTextureGLImpl
63 {
64     GLuint tex_name;
65     BOOLEAN loaded; /* For the moment, this is here.. Should be part of surface management though */
66
67     /* Texture upload management */
68     BOOLEAN initial_upload_done;
69     SURFACE_STATE dirty_flag;
70
71     /* This is used to optimize dirty checking in case of mipmapping.
72        Note that a bitmap could have been used but it was not worth the pain as it will be very rare
73        to have only one mipmap level change...
74
75        The __global_dirty_flag will only be set for the main mipmap level.
76     */
77     SURFACE_STATE __global_dirty_flag;
78     SURFACE_STATE *global_dirty_flag;
79     
80     /* This is to optimize the 'per-texture' parameters. */
81     DWORD *tex_parameters;
82     
83     /* Surface optimization */
84     void *surface_ptr;
85
86     /* Used to detect a change in internal format when going from non-CK texture to CK-ed texture */
87     GLenum current_internal_format;
88     
89     /* This is for now used to override 'standard' surface stuff to be as transparent as possible */
90     void (*final_release)(struct IDirectDrawSurfaceImpl *This);
91     void (*lock_update)(IDirectDrawSurfaceImpl* This, LPCRECT pRect, DWORD dwFlags);
92     void (*unlock_update)(IDirectDrawSurfaceImpl* This, LPCRECT pRect);
93     void (*set_palette)(IDirectDrawSurfaceImpl* This, IDirectDrawPaletteImpl* pal);
94 } IDirect3DTextureGLImpl;
95
96 typedef enum {
97     GL_TRANSFORM_NONE = 0,
98     GL_TRANSFORM_ORTHO,
99     GL_TRANSFORM_NORMAL,
100     GL_TRANSFORM_VERTEXBUFFER
101 } GL_TRANSFORM_STATE;
102
103 typedef enum {
104     WINE_GL_BUFFER_BACK = 0,
105     WINE_GL_BUFFER_FRONT
106 } WINE_GL_BUFFER_TYPE;
107
108 typedef struct IDirect3DDeviceGLImpl
109 {
110     struct IDirect3DDeviceImpl parent;
111     
112     GLXContext gl_context;
113
114     /* This stores the textures which are actually bound to the GL context */
115     IDirectDrawSurfaceImpl *current_bound_texture[MAX_TEXTURES];
116
117     /* The last type of vertex drawn */
118     GL_TRANSFORM_STATE transform_state;
119
120     /* Maybe a hack, but it works */
121     DWORD version;
122     
123     /* Used to handle fogging faster... */
124     BYTE fog_table[3 * 0x10000]; /* 3 is for R, G and B
125                                     0x10000 is 0xFF for the vertex color and
126                                                0xFF for the fog intensity */
127     
128     Display  *display;
129     Drawable drawable;
130
131     /* Variables used for the flush to frame-buffer code using the texturing code */
132     GLuint unlock_tex;
133     void *surface_ptr;
134     GLenum current_internal_format;
135
136     /* 0 is back-buffer, 1 is front-buffer */
137     SURFACE_STATE state[2];
138     IDirectDrawSurfaceImpl *lock_surf[2];
139     RECT lock_rect[2];
140     /* This is just here to print-out a nice warning if we have two successive locks */
141     BOOLEAN lock_rect_valid[2];
142
143     /* This is used to optimize some stuff */
144     DWORD prev_clear_color;
145     DWORD prev_clear_stencil;
146     D3DVALUE prev_clear_Z;
147     BOOLEAN depth_mask, depth_test, alpha_test, stencil_test, cull_face, lighting, blending, fogging;
148     GLenum current_alpha_test_func;
149     GLclampf current_alpha_test_ref;
150     GLenum current_tex_env;
151     GLenum current_active_tex_unit;
152 } IDirect3DDeviceGLImpl;
153
154 /* This is for the OpenGL additions... */
155 typedef struct {
156     struct IDirect3DVertexBufferImpl parent;
157
158     DWORD dwVertexTypeDesc;
159     D3DMATRIX world_mat, view_mat, proj_mat;
160     LPVOID vertices;
161 } IDirect3DVertexBufferGLImpl;
162
163 /* This is for GL extension support.
164    
165    This can contain either only a boolean if no function pointer exists or a set
166    of function pointers.
167 */
168 typedef struct {
169     /* Mirrored Repeat */
170     BOOLEAN mirrored_repeat;
171     /* Mipmap lod-bias */
172     BOOLEAN mipmap_lodbias;
173     /* Multi-texturing */
174     GLint max_texture_units;
175     void (*glActiveTexture)(GLenum texture);
176     void (*glMultiTexCoord2fv)(GLenum target, const GLfloat *v);
177     void (*glClientActiveTexture)(GLenum texture);
178     /* S3TC/DXTN compressed texture */
179     BOOLEAN s3tc_compressed_texture;
180     void (*glCompressedTexImage2D)(GLenum target, GLint level, GLenum internalformat, GLsizei width,
181                                  GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data);
182     void (*glCompressedTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset,
183                                     GLsizei width, GLsizei height, GLsizei imageSize, const GLvoid *data);
184 } GL_EXTENSIONS_LIST; 
185 extern GL_EXTENSIONS_LIST GL_extensions;
186
187 /* All non-static functions 'exported' by various sub-objects */
188 extern HRESULT direct3d_create(IDirectDrawImpl *This);
189 extern HRESULT d3dtexture_create(IDirectDrawImpl *d3d, IDirectDrawSurfaceImpl *surf, BOOLEAN at_creation, IDirectDrawSurfaceImpl *main_surf);
190 extern HRESULT d3dlight_create(IDirect3DLightImpl **obj, IDirectDrawImpl *d3d, GLenum light_num);
191 extern HRESULT d3dexecutebuffer_create(IDirect3DExecuteBufferImpl **obj, IDirectDrawImpl *d3d, IDirect3DDeviceImpl *d3ddev, LPD3DEXECUTEBUFFERDESC lpDesc);
192 extern HRESULT d3dmaterial_create(IDirect3DMaterialImpl **obj, IDirectDrawImpl *d3d);
193 extern HRESULT d3dviewport_create(IDirect3DViewportImpl **obj, IDirectDrawImpl *d3d);
194 extern HRESULT d3dvertexbuffer_create(IDirect3DVertexBufferImpl **obj, IDirectDrawImpl *d3d, LPD3DVERTEXBUFFERDESC lpD3DVertBufDesc, DWORD dwFlags);
195 extern HRESULT d3ddevice_create(IDirect3DDeviceImpl **obj, IDirectDrawImpl *d3d, IDirectDrawSurfaceImpl *surface, BOOLEAN from_surface);
196
197 /* Used for Direct3D to request the device to enumerate itself */
198 extern HRESULT d3ddevice_enumerate(LPD3DENUMDEVICESCALLBACK cb, LPVOID context, DWORD version) ;
199 extern HRESULT d3ddevice_enumerate7(LPD3DENUMDEVICESCALLBACK7 cb, LPVOID context) ;
200 extern HRESULT d3ddevice_find(IDirectDrawImpl *d3d, LPD3DFINDDEVICESEARCH lpD3DDFS, LPD3DFINDDEVICERESULT lplpD3DDevice);
201
202 /* Used by the DLL init routine to set-up the GL context and stuff properly */
203 extern BOOL d3ddevice_init_at_startup(void *gl_handle);
204
205 /* Used to upload the texture */
206 extern HRESULT gltex_upload_texture(IDirectDrawSurfaceImpl *This, IDirect3DDeviceImpl *d3ddev, DWORD stage) ;
207
208 /* Used to set-up our orthographic projection */
209 extern void d3ddevice_set_ortho(IDirect3DDeviceImpl *This) ;
210
211 /* Rendering state management functions */
212 extern void set_render_state(IDirect3DDeviceImpl* This, D3DRENDERSTATETYPE dwRenderStateType, STATEBLOCK *lpStateBlock);
213 extern void store_render_state(IDirect3DDeviceImpl *This, D3DRENDERSTATETYPE dwRenderStateType, DWORD dwRenderState, STATEBLOCK* lpStateBlock);
214 extern void get_render_state(IDirect3DDeviceImpl *This, D3DRENDERSTATETYPE dwRenderStateType, LPDWORD lpdwRenderState, STATEBLOCK* lpStateBlock);
215 extern void apply_render_state(IDirect3DDeviceImpl* This, STATEBLOCK* lpStateBlock);
216
217 /* Memory to texture conversion code. Split in three functions to do some optimizations. */
218 extern HRESULT upload_surface_to_tex_memory_init(IDirectDrawSurfaceImpl *surface, GLuint level, GLenum *prev_internal_format,
219                                                  BOOLEAN need_to_alloc, BOOLEAN need_alpha_ck, DWORD tex_width, DWORD tex_height);
220 extern HRESULT upload_surface_to_tex_memory(RECT *rect, DWORD xoffset, DWORD yoffset, void **temp_buffer);
221 extern HRESULT upload_surface_to_tex_memory_release(void);
222
223 /* Some utilities functions needed to be shared.. */
224 extern GLenum convert_D3D_compare_to_GL(D3DCMPFUNC dwRenderState) ;
225
226 #endif /* HAVE_OPENGL */
227
228 #endif /* __GRAPHICS_WINE_MESA_PRIVATE_H */