/* Copyright 2001-2002 TransGaming Technologies, Inc. */
#ifndef _D3DGL_PRIVATE_H_INCLUDED
#define _D3DGL_PRIVATE_H_INCLUDED

#include "wine/wine_gl.h"

#include "wine/d3dhalp.h"
#include "wine/d3dhalgl.h"

/* see http://oss.sgi.com/projects/ogl-sample/registry/ */
#define DD_GL_EXTENSION_LIST \
    DD_GL_EXT(ARB_imaging), \
    DD_GL_EXT(ARB_multitexture), \
    DD_GL_EXT(ARB_transpose_matrix), \
    DD_GL_EXT(ARB_multisample), /* TODO */ \
    DD_GL_EXT(ARB_texture_env_add), \
    DD_GL_EXT(ARB_texture_cube_map), \
    DD_GL_EXT(ARB_texture_compression), \
    DD_GL_EXT(ARB_texture_border_clamp), \
    DD_GL_EXT(ARB_point_parameters), /* TODO? */ \
    DD_GL_EXT(ARB_vertex_blend), \
    DD_GL_EXT(ARB_matrix_palette), /* TODO */ \
    DD_GL_EXT(ARB_texture_env_combine), \
    DD_GL_EXT(ARB_texture_env_crossbar), /* TODO? (use for D3DTOP_PREMODULATE) */ \
    DD_GL_EXT(ARB_texture_env_dot3), \
    DD_GL_EXT(ARB_texture_mirrored_repeat), \
    DD_GL_EXT(ARB_depth_texture), \
    DD_GL_EXT(ARB_shadow), \
    DD_GL_EXT(ARB_shadow_ambient), \
    DD_GL_EXT(ARB_window_pos), \
    DD_GL_EXT(ARB_vertex_program), \
    DD_GL_EXT(ARB_fragment_program), /* TODO */ \
    /* out of ARB extensions... what EXT extensions might also be useful? */ \
    DD_GL_EXT(EXT_point_parameters),		/* 54 - TODO */ \
    DD_GL_EXT(EXT_paletted_texture),		/* 78 */ \
    DD_GL_EXT(EXT_clip_volume_hint),		/* 79 */ \
    DD_GL_EXT(EXT_compiled_vertex_array),	/* 97 - maybe? */ \
    DD_GL_EXT(EXT_shared_texture_palette),	/* 141 */ \
    DD_GL_EXT(EXT_secondary_color),		/* 145 */ \
    DD_GL_EXT(EXT_fog_coord),			/* 149 */ \
    DD_GL_EXT(EXT_texture_env_combine),		/* 158 */ \
    DD_GL_EXT(EXT_blend_func_separate),		/* 173 - do we need this? */ \
    DD_GL_EXT(EXT_stencil_wrap),		/* 176 */ \
    DD_GL_EXT(EXT_texture_env_add),		/* 185 */ \
    DD_GL_EXT(EXT_texture_lod_bias),		/* 186 */ \
    DD_GL_EXT(EXT_texture_filter_anisotropic),	/* 187 */ \
    DD_GL_EXT(EXT_vertex_weighting),		/* 188 */ \
    DD_GL_EXT(EXT_texture_compression_s3tc),	/* 198 */ \
    DD_GL_EXT(EXT_texture_env_dot3),		/* 220 */ \
    DD_GL_EXT(EXT_vertex_shader),		/* 248 - TODO? */ \
    DD_GL_EXT(EXT_shadow_funcs),		/* 267 - ? */ \
    DD_GL_EXT(EXT_stencil_two_side),		/* 268 - TODO */ \
    /* out of EXT extensions... */ \
    DD_GL_EXT(NV_texgen_reflection),		/* 179 */ \
    DD_GL_EXT(NV_vertex_array_range),		/* 190 */ \
    DD_GL_EXT(NV_register_combiners),		/* 191 - TODO */ \
    DD_GL_EXT(NV_fog_distance),			/* 192 */ \
    DD_GL_EXT(NV_blend_square),			/* 194 */ \
    DD_GL_EXT(NV_texture_env_combine4),		/* 195 */ \
    DD_GL_EXT(ATI_texture_mirror_once),		/* 221 */ \
    DD_GL_EXT(NV_fence),			/* 222 */ \
    DD_GL_EXT(IBM_texture_mirrored_repeat),	/* 224 */ \
    DD_GL_EXT(NV_evaluators),			/* 225 - TODO */ \
    DD_GL_EXT(NV_register_combiners2),		/* 227 */ \
    DD_GL_EXT(NV_texture_rectangle),		/* 229 - TODO */ \
    DD_GL_EXT(NV_texture_shader),		/* 230 - TODO */ \
    DD_GL_EXT(NV_texture_shader2),		/* 231 - TODO */ \
    DD_GL_EXT(NV_vertex_array_range2),		/* 232 */ \
    DD_GL_EXT(NV_vertex_program),		/* 233 */ \
    DD_GL_EXT(ATI_envmap_bumpmap),		/* 244 - TODO */ \
    DD_GL_EXT(ATI_fragment_shader),		/* 245 - TODO? */ \
    DD_GL_EXT(ATI_pn_triangles),		/* 246 - TODO */ \
    DD_GL_EXT(ATI_vertex_array_object),		/* 247 - TODO? */ \
    DD_GL_EXT(ATI_vertex_streams),		/* 249 - TODO */ \
    DD_GL_EXT(ATI_element_array),		/* 256 - TODO */ \
    DD_GL_EXT(NV_multisample_filter_hint),	/* 259 - TODO */ \
    DD_GL_EXT(NV_depth_clamp),			/* 260 - ? */ \
    DD_GL_EXT(NV_point_sprite),			/* 262 - TODO */ \
    DD_GL_EXT(NV_texture_shader3),		/* 265 - TODO */ \
    DD_GL_EXT(NV_vertex_program1_1),		/* 266 */ \
    DD_GL_EXT(ATI_text_fragment_shader),	/* 269 - TODO */ \
    DD_GL_EXT(S3_s3tc),				/* 276 - TODO? */ \
    DD_GL_EXT(ATI_texture_env_combine3),	/* 279 */ \
    DD_GL_EXT(ATI_texture_float),		/* 280 - TODO */ \
    DD_GL_EXT(NV_float_buffer),			/* 281 - TODO */ \
    DD_GL_EXT(NV_fragment_program),		/* 282 - TODO */ \
    DD_GL_EXT(NV_half_float),			/* 283 - TODO */ \
    DD_GL_EXT(NV_vertex_program2),		/* 287 - TODO */ \
    DD_GL_EXT(ATI_separate_stencil)		/* 289 - TODO */

#define DD_GL_EXT(x) x
typedef enum {
    DD_GL_EXTENSION_LIST,
    DD_GL_EXTENSION_COUNT
} DD_GL_ext;
#undef DD_GL_EXT

#define DD_GL_PROC_LIST \
    DD_GL_PROC(PFNGLACTIVETEXTUREARBPROC,glActiveTextureARB) \
    DD_GL_PROC(PFNGLCLIENTACTIVETEXTUREARBPROC,glClientActiveTextureARB) \
    DD_GL_PROC(PFNGLMULTITEXCOORD2FARBPROC,glMultiTexCoord2fARB) \
    DD_GL_PROC(PFNGLSECONDARYCOLOR3UBEXTPROC,glSecondaryColor3ubEXT) \
    DD_GL_PROC(PFNGLSECONDARYCOLORPOINTEREXTPROC,glSecondaryColorPointerEXT) \
    DD_GL_PROC(PFNGLFOGCOORDFEXTPROC,glFogCoordfEXT) \
    DD_GL_PROC(PFNGLFOGCOORDPOINTEREXTPROC,glFogCoordPointerEXT) \
    DD_GL_PROC(PFNGLCOMPRESSEDTEXIMAGE2DARBPROC,glCompressedTexImage2DARB) \
    DD_GL_PROC(PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC,glCompressedTexSubImage2DARB) \
    DD_GL_PROC(PFNGLGETCOMPRESSEDTEXIMAGEARBPROC,glGetCompressedTexImageARB) \
    DD_GL_PROC(PFNGLWEIGHTPOINTERARBPROC,glWeightPointerARB) \
    DD_GL_PROC(PFNGLVERTEXBLENDARBPROC,glVertexBlendARB) \
    DD_GL_PROC(PFNGLVERTEXWEIGHTPOINTEREXTPROC,glVertexWeightPointerEXT) \
    DD_GL_PROC(PFNGLGENPROGRAMSNVPROC,glGenProgramsNV) \
    DD_GL_PROC(PFNGLLOADPROGRAMNVPROC,glLoadProgramNV) \
    DD_GL_PROC(PFNGLBINDPROGRAMNVPROC,glBindProgramNV) \
    DD_GL_PROC(PFNGLDELETEPROGRAMSNVPROC,glDeleteProgramsNV) \
    DD_GL_PROC(PFNGLPROGRAMPARAMETER4FNVPROC, glProgramParameter4fNV) \
    DD_GL_PROC(PFNGLPROGRAMPARAMETER4FVNVPROC, glProgramParameter4fvNV) \
    DD_GL_PROC(PFNGLPROGRAMPARAMETERS4FVNVPROC, glProgramParameters4fvNV) \
    DD_GL_PROC(PFNGLGETPROGRAMPARAMETERFVNVPROC, glGetProgramParameterfvNV) \
    DD_GL_PROC(PFNGLGETVERTEXATTRIBPOINTERVNVPROC, glGetVertexAttribPointervNV) \
    DD_GL_PROC(PFNGLVERTEXATTRIBPOINTERNVPROC, glVertexAttribPointerNV) \
    DD_GL_PROC(PFNGLGENPROGRAMSARBPROC, glGenProgramsARB) \
    DD_GL_PROC(PFNGLPROGRAMSTRINGARBPROC, glProgramStringARB) \
    DD_GL_PROC(PFNGLBINDPROGRAMARBPROC, glBindProgramARB) \
    DD_GL_PROC(PFNGLDELETEPROGRAMSARBPROC, glDeleteProgramsARB) \
    DD_GL_PROC(PFNGLPROGRAMENVPARAMETER4FARBPROC, glProgramEnvParameter4fARB) \
    DD_GL_PROC(PFNGLPROGRAMENVPARAMETER4FVARBPROC, glProgramEnvParameter4fvARB) \
    DD_GL_PROC(PFNGLPROGRAMLOCALPARAMETER4FARBPROC, glProgramLocalParameter4fARB) \
    DD_GL_PROC(PFNGLPROGRAMLOCALPARAMETER4FVARBPROC, glProgramLocalParameter4fvARB) \
    DD_GL_PROC(PFNGLVERTEXATTRIBPOINTERARBPROC, glVertexAttribPointerARB) \
    DD_GL_PROC(PFNGLENABLEVERTEXATTRIBARRAYARBPROC, glEnableVertexAttribArrayARB) \
    DD_GL_PROC(PFNGLDISABLEVERTEXATTRIBARRAYARBPROC, glDisableVertexAttribArrayARB) \
    DD_GL_PROC(PFNGLGETPROGRAMENVPARAMETERFVARBPROC, glGetProgramEnvParameterfvARB) \
    DD_GL_PROC(PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC, glGetProgramLocalParameterfvARB) \
    DD_GL_PROC(PFNGLGETVERTEXATTRIBPOINTERVARBPROC, glGetVertexAttribPointervARB) \
    DD_GL_PROC(PFNGLGETPROGRAMIVARBPROC, glGetProgramivARB)


#define DD_GL_PROC(x,y) x y;
typedef struct _DD_GL_data {
    char gl_ext[DD_GL_EXTENSION_COUNT];
    DD_GL_PROC_LIST
    D3DCAPS9 caps9;
    LPDDSURFACEDESC lpTextureFormats;
    DWORD dwNumTextureFormats;
    LPDDPIXELFORMAT lpZPixelFormats;
    DWORD dwNumZPixelFormats;
    LPDDHALSURFCB_LOCK old_lock;
    LPDDHALSURFCB_UNLOCK old_unlock;
    LPDDHALSURFCB_BLT old_blt;
} DD_GL_data;
#undef DD_GL_PROC

typedef struct
{
    D3DLIGHT7 *data;
    DWORD dwEnable;
} GL_D3D_light_state;
#define GL_D3D_LIGHT_ENABLE  1
#define GL_D3D_LIGHT_DISABLE 2

struct GL_D3D_state_block
{
    unsigned int list;
    DWORD renderstate[256];
    DWORD texstagestate[8][32];
    D3DMATRIX xfrm[8], txfrm[8];
    D3DVIEWPORT7 viewport;
    D3DMATERIAL7 material;
    D3DVALUE clipplane[32][4];
    DWORD num_lights;
    GL_D3D_light_state *light;
    DWORD vertex_decl;
    DWORD vertex_shader;
    float vertex_const[96*4];
    DWORD dirty_rs[8], dirty_tss[8][2], dirty_ts;
    DWORD dirty_xfrm, dirty_txfrm, dirty_clip_planes;
    DWORD dirty_vsc[3];
    BOOL dirty_viewport, dirty_material, dirty_vsd, dirty_vs;
};

typedef struct
{
    D3DLIGHT7 l;
    DWORD dwFlags, num;
    GLfloat pos[4];
} GL_D3D_light;

typedef struct
{
    struct _DD_GL_data *gl_data;
    LPDDRAWI_DIRECTDRAW_LCL dd_lcl;
    LPDDRAWI_DIRECTDRAW_GBL dd_gbl;
    LPD3DHAL_D3DEXTENDEDCAPS lpCaps;
    LPD3D_P d3dp;
    LPVOID color_array;
    DWORD color_array_size;
    LPVOID vertex_array;
    DWORD vertex_array_size;
    DWORD glFlags;
    DWORD dp2_dwFlags;
    DWORD dp2_dwVertexType;
    LPVOID dp2_lpVertices;
    DWORD dp2_dwVertexOffset;
    DWORD dp2_dwVertexLength;
    LPDDRAWI_DDRAWSURFACE_LCL dp2_VertexBuffer;
    D3DDRAWPRIMITIVESTRIDEDDATA sd;
    GLDRAWPRIMITIVESTRIDEDDATA stride;
    VertexShader *current_vs;
    DWORD lights, num_lights;
    DWORD light_user[32];
    GL_D3D_light *light;
    struct GL_D3D_state_block state;
    struct GL_D3D_state_block *block;
    DWORD material_flags;
    DWORD current_color_material;
    DWORD texture_flags;
    GLfloat texture_factor[4];
    GLenum texture_target[8];
    BOOL texture_used[8];
    const struct _GL_TEXOP *color_op[8], *alpha_op[8];
    GLuint dummy_texture;
    int d3d_version;
    struct GL_D3D_DriverCallbacks callbacks;
    LPDDRAWI_DDRAWPALETTE_GBL gbl_pal, gbl_pal_last;
    DWORD gbl_pal_stamp;
    BOOL isLightingEnabled;
    BOOL isVertexProgramEnabled;
    void *pVertexArray;
    DWORD sVertexArray;
    void *pNormalArray;
    DWORD sNormalArray;
    void *pColorArray;
    DWORD sColorArray;
    void *pSecondaryColorArray;
    DWORD sSecondaryColorArray;
    void *pFogCoordArray;
    DWORD sFogCoordArray;
    void *pTexCoordArray[8];
    DWORD sTexCoordArray[8];
    DWORD isClipPlaneEnabled;
    BOOL isFogEnabled, isFogLinear;
} GL_D3D_priv;

#define GLF_INITIALIZE			0x80000000
#define GLF_NEW_VIEW_XFRM		0x00000001 /* view matrix change - reload clip planes */
#define GLF_NEW_TRANSFORM		0x00000002 /* any transformation matrix or viewport change */
#define GLF_NEW_VIEW_LIGHT		0x00000004 /* view matrix change - reload light positions */
#define GLF_NEW_VIEW			0x00000005 /* view matrix change */
#define GLF_NEW_TNL_MODE		0x00000008 /* transformed vs untransformed vertices */
#define GLF_NEW_LIGHTING		0x00000010 /* lighting & material renderstates */
#define GLF_NEW_TEXCOORD_TRANSFORM	0x00000020 /* texture-coordinate generation change */
#define GLF_NEW_LIGHT_DATA		0x00000040 /* light property change */
#define GLF_NEW_CLIP_PLANES		0x00000080
#define GLF_NEW_RENDER_STATES		0x00000100
#define GLF_NEW_TEXTURE_STATES		0x00000200
#define GLF_USE_VERTEX_ARRAYS		0x00000400
#define GLF_STRIDED_DATA		0x00000800
#define GLF_VERTEX_BUFFER		0x00001000
#define GLF_VERTEX_DECLARATION		0x00002000
#define GLF_VERTEX_PROGRAM		0x00004000
#define GLF_RENDER_INVERTED		0x00008000
#define GLF_USE_CLIPMATRIX		0x00010000
#define GLF_NEW_VSHADER_CONSTS		0x00020000

/* values for material_flags */
#define GLMF_DO_DIFFUSE		0x001
#define GLMF_DO_SPECULAR	0x002
#define GLMF_DO_AMBIENT		0x004
#define GLMF_DO_EMISSIVE	0x008
#define GLMF_DIFFUSE_DIRTY	0x010
#define GLMF_SPECULAR_DIRTY	0x020
#define GLMF_AMBIENT_DIRTY	0x040
#define GLMF_EMISSIVE_DIRTY	0x080
#define GLMF_SHININESS_DIRTY	0x100
#define GLMF_COLOR_MATERIAL	0x200
#define GLMF_FOG_COORDINATE	0x400

#define GLMF_ALL_MATERIAL_DIRTY \
(GLMF_DIFFUSE_DIRTY|GLMF_SPECULAR_DIRTY|GLMF_AMBIENT_DIRTY|GLMF_EMISSIVE_DIRTY\
|GLMF_SHININESS_DIRTY)

/* values for texture_flags */
#define GLTF_DEFAULT_TEXCOORD_TRANSFORM	0x01


#define GL_FVF_NEW_TNL_BITS (D3DFVF_POSITION_MASK|D3DFVF_NORMAL)
#define GL_CHECK_NEW_TNL(x,y) (((x) ^ (y)) & GL_FVF_NEW_TNL_BITS)
#define GL_CHECK_NEW_TEXCOORD(x,y) (((x) ^ (y)) >> 16)

#define GLD(priv) ((priv)->gl_data)
#define HAVE_GL_EXT(priv,ext) (GLD(priv)->gl_ext[ext])

#define CHECK_GL_ERROR(x) do { GLenum err; err = glGetError(); if (err) ERR("glGetError returns %08x for %s\n", err, x); } while (0)

#define D3DTSS_TCI_MASK 0xFFFF0000U
#define D3DTTFF_COUNT_MASK 0xFFU

#define GL_IN_BLOCK(priv) ((priv)->block != &(priv)->state)

#define SET_DIRTY_RS(block, x) do { (block)->dirty_rs[(x) / 32] |= (1 << ((x) & 31)); } while (0)
#define SET_DIRTY_TSS(block, stage, x) do { (block)->dirty_tss[stage][(x) / 32] |= (1 << ((x) & 31)); } while (0)
#define SET_DIRTY_VSC(block, x) do { (block)->dirty_vsc[(x) / 32] |= (1 << ((x) & 31)); } while (0)

#if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
#define ATTR_PURE __attribute__((pure))
#else
#define ATTR_PURE
#endif

#define SURF_LCL(surf)  (&(surf)->lcl)
#define SURF_MORE(surf) (&(surf)->more)
#define SURF_GBL(surf)  (&(surf)->gbl)
#define TDATA(surf)     ((surf)->tdata)
#define TGLDEVICE(surf) (TDATA(surf)[0])
#define TGLFMT(surf)    (TDATA(surf)[1])
#define TGLTYPE(surf)   (TDATA(surf)[2])
#define TGLLEVEL(surf)  (TDATA(surf)[3])
#define TGLIFMT(surf)   (TDATA(surf)[4])
#define TPALETTE(surf)  (TDATA(surf)[5])
#define TPALSTAMP(surf) (TDATA(surf)[6])
#define TLOCKS(surf)    (TDATA(surf)[7])

#define TEXTURE_ID(surf) (GET_LPDDRAWSURFACE_GBL_MORE(SURF_GBL(surf))->dwDriverReserved)

#define TCONTEXTLESS(surf) ((!SURF_LCL(surf)->dwReserved1)||(!TGLDEVICE(surf)))

/* d3dgl_main.c */
HRESULT D3D_GL_initialize(GL_D3D_priv* priv);

/* light.c */
HRESULT D3D_GL_create_light(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
HRESULT D3D_GL_set_light(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
void GL_LoadLightPositions(GL_D3D_priv* priv, BOOL new_view);
void GL_LoadLights(GL_D3D_priv* priv, BOOL new_view);
HRESULT D3D_GL_light_enable(GL_D3D_priv* priv, DWORD dwIndex);
HRESULT D3D_GL_light_disable(GL_D3D_priv* priv, DWORD dwIndex);
HRESULT D3D_GL_set_light_data(GL_D3D_priv* priv, DWORD dwIndex, LPD3DLIGHT7 ldata);

/* prim.c */
HRESULT D3D_GL_draw(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
HRESULT D3D_GL_clear(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);

/* state.c */
HRESULT D3D_GL_set_render_state(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
HRESULT D3D_GL_update_render_states(GL_D3D_priv* priv);
HRESULT D3D_GL_viewport_info(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
HRESULT D3D_GL_z_range(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
HRESULT D3D_GL_set_material(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
HRESULT D3D_GL_set_transform(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
HRESULT D3D_GL_update_viewport(GL_D3D_priv* priv);
HRESULT D3D_GL_set_clip_plane(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
HRESULT D3D_GL_update_clip_planes(GL_D3D_priv* priv, BOOL new_view, BOOL fixed);
void GL_setup_linear_fog(GL_D3D_priv* priv, BOOL linear, BOOL enable);
HRESULT D3D_GL_set_current_material(GL_D3D_priv* priv, LPD3DMATERIAL7 mat);

/* texstate.c */
void GL_LoadTextureFactor(GL_D3D_priv* priv, GLfloat col[4]);
HRESULT D3D_GL_set_texture_stage_state(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
HRESULT D3D_GL_update_texture_stage_states(GL_D3D_priv* priv);
HRESULT GL_Direct3DDevice_validate_device(GL_D3D_priv* priv, LPDWORD lpdwPasses);

/* texture.c */
HRESULT GL_PrepTexture(GL_D3D_priv *priv, LPD3D_T texture, LPD3D_T srctex);
HRESULT D3D_GL_set_palette(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
HRESULT D3D_GL_update_palette(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
HRESULT D3D_GL_update_palettes(GL_D3D_priv* priv);
HRESULT D3D_GL_sync_texblt(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
HRESULT D3D_GL_async_texblt(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
DWORD PASCAL D3DGL_Lock(LPDDHAL_LOCKDATA data);
DWORD PASCAL D3DGL_Unlock(LPDDHAL_UNLOCKDATA data);
DWORD PASCAL D3DGL_Blt(LPDDHAL_BLTDATA data);

/* fixedfunc.c */
typedef DWORD (*GL_IndexFunc)(DWORD idx, LPVOID p);
void GL_draw_unlit_vertices(GL_D3D_priv* priv, GLenum gltype, DWORD vt,
			    DWORD start, DWORD count, GL_IndexFunc index,
			    LPVOID index_data, DWORD ibase);
void GL_setup_transforms(GL_D3D_priv* priv, DWORD vt);
void GL_setup_lighting(GL_D3D_priv* priv, DWORD vt);
DWORD D3D_GL_setup_fixed(GL_D3D_priv* priv, LPVOID data1, 
			 const WORD* indices, GLenum pt, 
			 DWORD dwCount, BOOL indexed);
void D3D_GL_finish_fixed(GL_D3D_priv* priv);

/* vprogram.c */
void GL_VP_disable(GL_D3D_priv* priv);
void D3D_GL_VertexProgram_Init(DD_GL_data *gld);
HRESULT D3D_GL_create_vertex_shader(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
HRESULT D3D_GL_create_vertex_shader_decl(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
HRESULT D3D_GL_create_vertex_shader_func(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
HRESULT D3D_GL_set_vertex_shader(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
HRESULT D3D_GL_set_vertex_shader_decl(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
HRESULT D3D_GL_set_vertex_shader_func(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
HRESULT D3D_GL_set_vertex_shader_const(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
HRESULT D3D_GL_delete_vertex_shader(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
HRESULT D3D_GL_delete_vertex_shader_decl(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
HRESULT D3D_GL_delete_vertex_shader_func(GL_D3D_priv* priv, LPD3DHAL_DP2COMMAND cmd, LPVOID data1, LPVOID data2);
HRESULT D3D_GL_set_current_vertex_shader(GL_D3D_priv* priv, DWORD dwHandle);
HRESULT D3D_GL_set_current_vertex_shader_decl(GL_D3D_priv* priv, DWORD dwHandle);
HRESULT D3D_GL_set_current_vertex_shader_func(GL_D3D_priv* priv, DWORD dwHandle);
void D3D_GL_setup_programmable(GL_D3D_priv* priv, LPVOID data1,
                               const WORD* indices, GLenum pt, 
                               DWORD dwCount, BOOL indexed);
void D3D_GL_finish_programmable(GL_D3D_priv* priv);

/* vertex shader declaration macros from d3d8types.h */

#define D3DVSDT_FLOAT1   0x00
#define D3DVSDT_FLOAT2   0x01
#define D3DVSDT_FLOAT3   0x02
#define D3DVSDT_FLOAT4   0x03
#define D3DVSDT_D3DCOLOR 0x04
#define D3DVSDT_UBYTE4   0x05
#define D3DVSDT_SHORT2   0x06
#define D3DVSDT_SHORT4   0x07

#define D3DVSDE_POSITION     0
#define D3DVSDE_BLENDWEIGHT  1
#define D3DVSDE_BLENDINDICES 2
#define D3DVSDE_NORMAL       3
#define D3DVSDE_PSIZE        4
#define D3DVSDE_DIFFUSE      5
#define D3DVSDE_SPECULAR     6
#define D3DVSDE_TEXCOORD0    7
#define D3DVSDE_TEXCOORD1    8
#define D3DVSDE_TEXCOORD2    9
#define D3DVSDE_TEXCOORD3   10
#define D3DVSDE_TEXCOORD4   11
#define D3DVSDE_TEXCOORD5   12
#define D3DVSDE_TEXCOORD6   13
#define D3DVSDE_TEXCOORD7   14
#define D3DVSDE_POSITION2   15
#define D3DVSDE_NORMAL2     16

#endif
