#ifndef WINE_D3DHALP_H_INCLUDED
#define WINE_D3DHALP_H_INCLUDED

#include "windef.h"
#include "ddrawi.h"
#include "d3dtypes.h"

struct _D3DHAL_CALLBACKS;
struct _D3DHAL_CALLBACKS2;
struct _VertexShader;

typedef struct {
    D3DLIGHT7 l;
    DWORD flags, devnum;
    D3DVALUE devpos[4];
} D3D_Light;

typedef struct
{
    DDRAWI_DDRAWSURFACE_LCL lcl;
    DDRAWI_DDRAWSURFACE_MORE more;
    LPDDRAWI_DDRAWSURFACE_GBL_MORE gmore;
    DDRAWI_DDRAWSURFACE_GBL gbl;
    DDRAWI_DDRAWSURFACE_GBL_MORE gbl_more;
    DWORD tdata[16];
} D3D_T,*LPD3D_T;

typedef struct
{
    LPDDRAWI_DIRECTDRAW_LCL lcl;
    LPDDRAWI_DDRAWSURFACE_LCL surf, zbuf;
    ULONG_PTR dwhContext;
    LPDDHAL_GETDRIVERINFO gdi;
    struct _D3DHAL_CALLBACKS *cbs1;
    struct _D3DHAL_CALLBACKS2 *cbs2;
    HANDLE surface_heap;
    BOOL in_scene;
    DWORD renderstate[256];
    DWORD texstagestate[8][32];
    D3DMATRIX xfrm[8], txfrm[8];
    D3DVIEWPORT7 viewport;
    D3DMATERIAL7 material;
    DWORD numlights;
    D3D_Light *light;
    D3DVALUE clipplane[32][4];
    struct _VertexShader* vertex_shader;
    DWORD vertex_fvf;
    float* vertex_const;
    struct {
      LPD3D_T data_t;  /* ptr to D3D_T field of IDirect3DVertexBuffer8Impl */
      UINT stride;
    } stream[16];
} D3D_P,*LPD3D_P;

/*----------------------------------------------------------------------------------
 * Private VertexShader structure and macros that are shared between D3D8 and D3DGL
 * - can be modified as necessary
 *----------------------------------------------------------------------------------*/

/* to distinguish a handle from a FVF, we'll use D3DFVF_RESERVED0,
 * assuming that HeapAlloc-ed memory is always DWORD-aligned so
 * that the lower bit of the returned pointer is always zero */
#define VS_TO_HANDLE(x) (((DWORD)x) | D3DFVF_RESERVED0)
#define VS_FROM_HANDLE(x) ((VertexShader*)(x & ~D3DFVF_RESERVED0))
#define IS_VS(x) (x & D3DFVF_RESERVED0)
#define IS_FVF(x) (!IS_VS(x))

#define SET_INPUT_REG_TYPE(x) ((x) | (1<<7))
#define GET_INPUT_REG_TYPE(x) ((x) & ~(1<<7))
#define IS_INPUT_REG_ENABLED(x) ((x) & (1<<7))

typedef struct _VertexShader {
  CONST DWORD* pDeclaration;
  CONST DWORD* pFunction;
  DWORD DeclarationLength;
  DWORD FunctionLength;
  DWORD Usage;
  DWORD FVF;
  DWORD DriverReserved0;      /* used by d3dgl to store driver specific info (name) */
  DWORD DriverReserved1;      /* (context) */
  char *programstring[2]; 
  struct _VertexShader *prev;
  struct _VertexShader *next;
  BYTE  has_fog;
  BYTE  has_pointsize;
  BYTE  inverted;
  struct {
    BYTE stream;   /* stream source number */
    BYTE offset;   /* offset into stream in BYTES */
    BYTE type;     /* D3DVSDT_* type of data, with high bit used a flag (see macros above) */
    int gltype;    /* gl type that the D3DVSDT_* type maps to */
    int size;	   /* the number of data elements in field of type */
    int normalize; /* should fixed point data be normalized when converting to floating point? */
  } input_reg[17];
} VertexShader;



#endif
