Allow specification of "DLLMODE=native" for native dlls.
[wine] / dlls / ddraw / mesa_private.h
index 6b8790b..cfa36c4 100644 (file)
 
 #ifdef HAVE_OPENGL
 
-#undef APIENTRY
-#undef CALLBACK
-#undef WINAPI
-
-#define XMD_H /* This is to prevent the Xmd.h inclusion bug :-/ */
-#include <GL/gl.h>
-#include <GL/glx.h>
-#ifdef HAVE_GL_GLEXT_H
-# include <GL/glext.h>
-#endif
-#undef  XMD_H
-
-#undef APIENTRY
-#undef CALLBACK
-#undef WINAPI
-
-/* Redefines the constants */
-#define CALLBACK    __stdcall
-#define WINAPI      __stdcall
-#define APIENTRY    WINAPI
+#include "gl_private.h"
 
 /* X11 locking */
 
@@ -57,27 +38,18 @@ extern void (*wine_tsx11_unlock_ptr)(void);
 #define LEAVE_GL() wine_tsx11_unlock_ptr()
 
 extern const GUID IID_D3DDEVICE_OpenGL;
-extern const GUID IID_D3DDEVICE2_OpenGL;
-extern const GUID IID_D3DDEVICE3_OpenGL;
-extern const GUID IID_D3DDEVICE7_OpenGL;
-extern const GUID IID_D3DDEVICE_Default;
-
-typedef struct render_state {
-    /* This is used for the device mode */
-    GLenum src, dst;
-    /* This is used for textures */
-    GLenum mag, min;
-} RenderState;
-
-/* Common functions defined in d3dcommon.c */
-void set_render_state(D3DRENDERSTATETYPE dwRenderStateType,
-                     DWORD dwRenderState, RenderState *rs) ;
 
+typedef enum {
+    SURFACE_GL,
+    SURFACE_MEMORY,
+    SURFACE_MEMORY_DIRTY
+} SURFACE_STATE;
+
+/* This structure is used for the 'd3d_private' field of the IDirectDraw structure */
 typedef struct IDirect3DGLImpl
 {
-    struct IDirect3DImpl parent;
-    int free_lights;
-    void (*light_released)(IDirect3DImpl *, GLenum light_num);
+    DWORD free_lights;
+    void (*light_released)(IDirectDrawImpl *, GLenum light_num);
 } IDirect3DGLImpl;
 
 typedef struct IDirect3DLightGLImpl
@@ -86,90 +58,164 @@ typedef struct IDirect3DLightGLImpl
     GLenum light_num;
 } IDirect3DLightGLImpl;
 
+/* This structure is used for the 'private' field of the IDirectDrawSurfaceImpl structure */
 typedef struct IDirect3DTextureGLImpl
 {
-    struct IDirect3DTextureImpl parent;
     GLuint tex_name;
+    BOOLEAN loaded; /* For the moment, this is here.. Should be part of surface management though */
+
+    /* Texture upload management */
+    BOOLEAN initial_upload_done;
+    SURFACE_STATE dirty_flag;
+
+    /* This is used to optimize dirty checking in case of mipmapping.
+       Note that a bitmap could have been used but it was not worth the pain as it will be very rare
+       to have only one mipmap level change...
+
+       The __global_dirty_flag will only be set for the main mipmap level.
+    */
+    SURFACE_STATE __global_dirty_flag;
+    SURFACE_STATE *global_dirty_flag;
+    
+    /* This is to optimize the 'per-texture' parameters. */
+    DWORD *tex_parameters;
+    
+    /* Surface optimization */
+    void *surface_ptr;
+
+    /* Used to detect a change in internal format when going from non-CK texture to CK-ed texture */
+    GLenum current_internal_format;
+    
+    /* This is for now used to override 'standard' surface stuff to be as transparent as possible */
+    void (*final_release)(struct IDirectDrawSurfaceImpl *This);
+    void (*lock_update)(IDirectDrawSurfaceImpl* This, LPCRECT pRect, DWORD dwFlags);
+    void (*unlock_update)(IDirectDrawSurfaceImpl* This, LPCRECT pRect);
+    void (*set_palette)(IDirectDrawSurfaceImpl* This, IDirectDrawPaletteImpl* pal);
 } IDirect3DTextureGLImpl;
 
+typedef enum {
+    GL_TRANSFORM_NONE = 0,
+    GL_TRANSFORM_ORTHO,
+    GL_TRANSFORM_NORMAL,
+    GL_TRANSFORM_VERTEXBUFFER
+} GL_TRANSFORM_STATE;
+
+typedef enum {
+    WINE_GL_BUFFER_BACK = 0,
+    WINE_GL_BUFFER_FRONT
+} WINE_GL_BUFFER_TYPE;
+
 typedef struct IDirect3DDeviceGLImpl
 {
     struct IDirect3DDeviceImpl parent;
     
     GLXContext gl_context;
 
-    /* The current render state */
-    RenderState render_state;
+    /* This stores the textures which are actually bound to the GL context */
+    IDirectDrawSurfaceImpl *current_bound_texture[MAX_TEXTURES];
 
     /* The last type of vertex drawn */
-    D3DVERTEXTYPE vertex_type;
+    GL_TRANSFORM_STATE transform_state;
 
-    D3DMATRIX *world_mat;
-    D3DMATRIX *view_mat;
-    D3DMATRIX *proj_mat;
+    /* Maybe a hack, but it works */
+    DWORD version;
+    
+    /* Used to handle fogging faster... */
+    BYTE fog_table[3 * 0x10000]; /* 3 is for R, G and B
+                                   0x10000 is 0xFF for the vertex color and
+                                              0xFF for the fog intensity */
     
     Display  *display;
     Drawable drawable;
+
+    /* Variables used for the flush to frame-buffer code using the texturing code */
+    GLuint unlock_tex;
+    void *surface_ptr;
+    GLenum current_internal_format;
+
+    /* 0 is back-buffer, 1 is front-buffer */
+    SURFACE_STATE state[2];
+    IDirectDrawSurfaceImpl *lock_surf[2];
+    RECT lock_rect[2];
+    /* This is just here to print-out a nice warning if we have two successive locks */
+    BOOLEAN lock_rect_valid[2];
+
+    /* This is used to optimize some stuff */
+    DWORD prev_clear_color;
+    DWORD prev_clear_stencil;
+    D3DVALUE prev_clear_Z;
+    BOOLEAN depth_mask, depth_test, alpha_test, stencil_test, cull_face, lighting, blending, fogging;
+    GLenum current_alpha_test_func;
+    GLclampf current_alpha_test_ref;
+    GLenum current_tex_env;
+    GLenum current_active_tex_unit;
 } IDirect3DDeviceGLImpl;
 
+/* This is for the OpenGL additions... */
+typedef struct {
+    struct IDirect3DVertexBufferImpl parent;
+
+    DWORD dwVertexTypeDesc;
+    D3DMATRIX world_mat, view_mat, proj_mat;
+    LPVOID vertices;
+} IDirect3DVertexBufferGLImpl;
+
+/* This is for GL extension support.
+   
+   This can contain either only a boolean if no function pointer exists or a set
+   of function pointers.
+*/
+typedef struct {
+    /* Mirrored Repeat */
+    BOOLEAN mirrored_repeat;
+    /* Mipmap lod-bias */
+    BOOLEAN mipmap_lodbias;
+    /* Multi-texturing */
+    GLint max_texture_units;
+    void (*glActiveTexture)(GLenum texture);
+    void (*glMultiTexCoord2fv)(GLenum target, const GLfloat *v);
+    void (*glClientActiveTexture)(GLenum texture);
+} GL_EXTENSIONS_LIST; 
+extern GL_EXTENSIONS_LIST GL_extensions;
+
 /* All non-static functions 'exported' by various sub-objects */
-extern HRESULT direct3d_create(IDirect3DImpl **obj, IDirectDrawImpl *ddraw);
-extern HRESULT d3dtexture_create(IDirect3DTextureImpl **obj, IDirect3DImpl *d3d, IDirectDrawSurfaceImpl *surf);
-extern HRESULT d3dlight_create(IDirect3DLightImpl **obj, IDirect3DImpl *d3d, GLenum light_num);
-extern HRESULT d3dexecutebuffer_create(IDirect3DExecuteBufferImpl **obj, IDirect3DImpl *d3d, IDirect3DDeviceImpl *d3ddev, LPD3DEXECUTEBUFFERDESC lpDesc);
-extern HRESULT d3dmaterial_create(IDirect3DMaterialImpl **obj, IDirect3DImpl *d3d);
-extern HRESULT d3dviewport_create(IDirect3DViewportImpl **obj, IDirect3DImpl *d3d);
-extern HRESULT d3dvertexbuffer_create(IDirect3DVertexBufferImpl **obj, IDirect3DImpl *d3d, LPD3DVERTEXBUFFERDESC lpD3DVertBufDesc);
-extern HRESULT d3ddevice_create(IDirect3DDeviceImpl **obj, IDirect3DImpl *d3d, IDirectDrawSurfaceImpl *surface);
+extern HRESULT direct3d_create(IDirectDrawImpl *This);
+extern HRESULT d3dtexture_create(IDirectDrawImpl *d3d, IDirectDrawSurfaceImpl *surf, BOOLEAN at_creation, IDirectDrawSurfaceImpl *main_surf);
+extern HRESULT d3dlight_create(IDirect3DLightImpl **obj, IDirectDrawImpl *d3d, GLenum light_num);
+extern HRESULT d3dexecutebuffer_create(IDirect3DExecuteBufferImpl **obj, IDirectDrawImpl *d3d, IDirect3DDeviceImpl *d3ddev, LPD3DEXECUTEBUFFERDESC lpDesc);
+extern HRESULT d3dmaterial_create(IDirect3DMaterialImpl **obj, IDirectDrawImpl *d3d);
+extern HRESULT d3dviewport_create(IDirect3DViewportImpl **obj, IDirectDrawImpl *d3d);
+extern HRESULT d3dvertexbuffer_create(IDirect3DVertexBufferImpl **obj, IDirectDrawImpl *d3d, LPD3DVERTEXBUFFERDESC lpD3DVertBufDesc, DWORD dwFlags);
+extern HRESULT d3ddevice_create(IDirect3DDeviceImpl **obj, IDirectDrawImpl *d3d, IDirectDrawSurfaceImpl *surface, BOOLEAN from_surface);
 
 /* Used for Direct3D to request the device to enumerate itself */
-extern HRESULT d3device_enumerate(LPD3DENUMDEVICESCALLBACK cb, LPVOID context, DWORD interface_version) ;
-
-/* Matrix copy WITH transposition */
-#define conv_mat2(mat,gl_mat)                  \
-{                                              \
-    TRACE("%f %f %f %f\n", (mat)->_11, (mat)->_12, (mat)->_13, (mat)->_14); \
-    TRACE("%f %f %f %f\n", (mat)->_21, (mat)->_22, (mat)->_23, (mat)->_24); \
-    TRACE("%f %f %f %f\n", (mat)->_31, (mat)->_32, (mat)->_33, (mat)->_34); \
-    TRACE("%f %f %f %f\n", (mat)->_41, (mat)->_42, (mat)->_43, (mat)->_44); \
-    (gl_mat)[ 0] = (mat)->_11;                 \
-    (gl_mat)[ 1] = (mat)->_21;                 \
-    (gl_mat)[ 2] = (mat)->_31;                 \
-    (gl_mat)[ 3] = (mat)->_41;                 \
-    (gl_mat)[ 4] = (mat)->_12;                 \
-    (gl_mat)[ 5] = (mat)->_22;                 \
-    (gl_mat)[ 6] = (mat)->_32;                 \
-    (gl_mat)[ 7] = (mat)->_42;                 \
-    (gl_mat)[ 8] = (mat)->_13;                 \
-    (gl_mat)[ 9] = (mat)->_23;                 \
-    (gl_mat)[10] = (mat)->_33;                 \
-    (gl_mat)[11] = (mat)->_43;                 \
-    (gl_mat)[12] = (mat)->_14;                 \
-    (gl_mat)[13] = (mat)->_24;                 \
-    (gl_mat)[14] = (mat)->_34;                 \
-    (gl_mat)[15] = (mat)->_44;                 \
-};
-
-/* Matrix copy WITHOUT transposition */
-#define conv_mat(mat,gl_mat)                   \
-{                                               \
-    TRACE("%f %f %f %f\n", (mat)->_11, (mat)->_12, (mat)->_13, (mat)->_14); \
-    TRACE("%f %f %f %f\n", (mat)->_21, (mat)->_22, (mat)->_23, (mat)->_24); \
-    TRACE("%f %f %f %f\n", (mat)->_31, (mat)->_32, (mat)->_33, (mat)->_34); \
-    TRACE("%f %f %f %f\n", (mat)->_41, (mat)->_42, (mat)->_43, (mat)->_44); \
-    memcpy(gl_mat, (mat), 16 * sizeof(float));      \
-};
-
-#define _dump_colorvalue(s,v)                \
-    TRACE(" " s " : %f %f %f %f\n",          \
-    (v).u1.r, (v).u2.g, (v).u3.b, (v).u4.a);
-
-/* This structure contains all the function pointers to OpenGL extensions
-   that are used by Wine */
-typedef struct {
-  void (*ptr_ColorTableEXT) (GLenum target, GLenum internalformat,
-                            GLsizei width, GLenum format, GLenum type, const GLvoid *table);
-} Mesa_DeviceCapabilities;
+extern HRESULT d3ddevice_enumerate(LPD3DENUMDEVICESCALLBACK cb, LPVOID context, DWORD version) ;
+extern HRESULT d3ddevice_enumerate7(LPD3DENUMDEVICESCALLBACK7 cb, LPVOID context) ;
+extern HRESULT d3ddevice_find(IDirectDrawImpl *d3d, LPD3DFINDDEVICESEARCH lpD3DDFS, LPD3DFINDDEVICERESULT lplpD3DDevice);
+
+/* Used by the DLL init routine to set-up the GL context and stuff properly */
+extern BOOL d3ddevice_init_at_startup(void *gl_handle);
+
+/* Used to upload the texture */
+extern HRESULT gltex_upload_texture(IDirectDrawSurfaceImpl *This, IDirect3DDeviceImpl *d3ddev, DWORD stage) ;
+
+/* Used to set-up our orthographic projection */
+extern void d3ddevice_set_ortho(IDirect3DDeviceImpl *This) ;
+
+/* Rendering state management functions */
+extern void set_render_state(IDirect3DDeviceImpl* This, D3DRENDERSTATETYPE dwRenderStateType, STATEBLOCK *lpStateBlock);
+extern void store_render_state(IDirect3DDeviceImpl *This, D3DRENDERSTATETYPE dwRenderStateType, DWORD dwRenderState, STATEBLOCK* lpStateBlock);
+extern void get_render_state(IDirect3DDeviceImpl *This, D3DRENDERSTATETYPE dwRenderStateType, LPDWORD lpdwRenderState, STATEBLOCK* lpStateBlock);
+extern void apply_render_state(IDirect3DDeviceImpl* This, STATEBLOCK* lpStateBlock);
+
+/* Memory to texture conversion code. Split in three functions to do some optimizations. */
+extern HRESULT upload_surface_to_tex_memory_init(IDirectDrawSurfaceImpl *surface, GLuint level, GLenum *prev_internal_format,
+                                                BOOLEAN need_to_alloc, BOOLEAN need_alpha_ck, DWORD tex_width, DWORD tex_height);
+extern HRESULT upload_surface_to_tex_memory(RECT *rect, DWORD xoffset, DWORD yoffset, void **temp_buffer);
+extern HRESULT upload_surface_to_tex_memory_release(void);
+
+/* Some utilities functions needed to be shared.. */
+extern GLenum convert_D3D_compare_to_GL(D3DCMPFUNC dwRenderState) ;
 
 #endif /* HAVE_OPENGL */