#ifndef _D3DXCORE_H
#define _D3DXCORE_H

/* D3DX core type and function definitions */

#include <d3d.h>
#include <limits.h>
#include "d3dxerr.h"

#ifndef __PODXAPI
#if __POCC__ >= 274
#define __PODXAPI  __declspec(dllimport)
#else
#define __PODXAPI
#endif
#endif /* __PODXAPI */

typedef struct ID3DXContext *LPD3DXCONTEXT;

DEFINE_GUID(IID_ID3DXContext,0x9b74ed7a,0xbbef,0x11d2,0x9f,0x8e,0x0,0x0,0xf8,0x8,0x8,0x35);

#define D3DX_DEFAULT  ULONG_MAX
#define D3DX_DEFAULT_FLOAT  FLT_MAX

#define D3DX_HWLEVEL_NULL  (D3DX_DEFAULT - 1)
#define D3DX_HWLEVEL_REFERENCE  (D3DX_DEFAULT - 2)
#define D3DX_HWLEVEL_2D  (D3DX_DEFAULT - 3) 
#define D3DX_HWLEVEL_RASTER  (D3DX_DEFAULT - 4) 
#define D3DX_HWLEVEL_TL  (D3DX_DEFAULT - 5) 

#define D3DX_SC_DEPTHBUFFER  0x01
#define D3DX_SC_STENCILBUFFER  0x02
#define D3DX_SC_COLORTEXTURE  0x04
#define D3DX_SC_BUMPMAP  0x08
#define D3DX_SC_LUMINANCEMAP  0x10
#define D3DX_SC_COLORRENDERTGT  0x20

#define D3DX_DRIVERDESC_LENGTH  256

#define D3DX_GVM_REFRESHRATE  0x00000001

#define D3DX_CONTEXT_FULLSCREEN  0x00000001
#define D3DX_CONTEXT_OFFSCREEN  0x00000002

#define D3DX_UPDATE_NOVSYNC  (1<<0)

#define D3DX_TEXTURE_NOMIPMAP  (1<<8)
#define D3DX_TEXTURE_STAGE0  (0)
#define D3DX_TEXTURE_STAGE1  (1)
#define D3DX_TEXTURE_STAGE2  (2)
#define D3DX_TEXTURE_STAGE3  (3)
#define D3DX_TEXTURE_STAGE4  (4)
#define D3DX_TEXTURE_STAGE5  (5)
#define D3DX_TEXTURE_STAGE6  (6)
#define D3DX_TEXTURE_STAGE7  (7)
#define D3DX_TEXTURE_STAGE_MASK  (0x7)

typedef enum _D3DX_SURFACEFORMAT {
    D3DX_SF_UNKNOWN = 0,
    D3DX_SF_R8G8B8 = 1,
    D3DX_SF_A8R8G8B8 = 2,
    D3DX_SF_X8R8G8B8 = 3,
    D3DX_SF_R5G6B5 = 4,
    D3DX_SF_R5G5B5 = 5,
    D3DX_SF_PALETTE4 = 6,
    D3DX_SF_PALETTE8 = 7,
    D3DX_SF_A1R5G5B5 = 8,
    D3DX_SF_X4R4G4B4 = 9,
    D3DX_SF_A4R4G4B4 =10,
    D3DX_SF_L8 = 11,
    D3DX_SF_A8L8 = 12,
    D3DX_SF_U8V8 = 13,
    D3DX_SF_U5V5L6 = 14,
    D3DX_SF_U8V8L8 = 15,
    D3DX_SF_UYVY = 16,
    D3DX_SF_YUY2 = 17,
    D3DX_SF_DXT1 = 18,
    D3DX_SF_DXT3 = 19,
    D3DX_SF_DXT5 = 20,
    D3DX_SF_R3G3B2 = 21,
    D3DX_SF_A8 = 22,
    D3DX_SF_TEXTUREMAX = 23,
    D3DX_SF_Z16S0 = 256,
    D3DX_SF_Z32S0 = 257,
    D3DX_SF_Z15S1 = 258,
    D3DX_SF_Z24S8 = 259,
    D3DX_SF_S1Z15 = 260,
    D3DX_SF_S8Z24 = 261,
    D3DX_SF_DEPTHMAX = 262,
    D3DX_SF_FORCEMAX = (DWORD)(-1)
} D3DX_SURFACEFORMAT;

typedef enum _D3DX_FILTERTYPE {
    D3DX_FT_POINT = 0x01,
    D3DX_FT_LINEAR = 0x02,
    D3DX_FT_DEFAULT = D3DX_DEFAULT
} D3DX_FILTERTYPE;

typedef struct _D3DX_VIDMODEDESC {
    DWORD width;
    DWORD height;
    DWORD bpp;
    DWORD refreshRate;
} D3DX_VIDMODEDESC;

typedef struct _D3DX_DEVICEDESC {
    DWORD deviceIndex;
    DWORD hwLevel;
    GUID ddGuid;
    GUID d3dDeviceGuid;
    GUID ddDeviceID;
    char driverDesc[D3DX_DRIVERDESC_LENGTH];
    HMONITOR monitor;
    BOOL onPrimary;
} D3DX_DEVICEDESC;

#ifdef __cplusplus
extern "C" {
#endif
    
__PODXAPI HRESULT WINAPI D3DXInitialize(void);
__PODXAPI HRESULT WINAPI D3DXUninitialize(void);
__PODXAPI DWORD WINAPI D3DXGetDeviceCount(void);
__PODXAPI HRESULT WINAPI D3DXGetDeviceDescription(DWORD,D3DX_DEVICEDESC*);
__PODXAPI DWORD WINAPI D3DXGetMaxNumVideoModes(DWORD,DWORD);
__PODXAPI HRESULT WINAPI D3DXGetVideoMode(DWORD,DWORD,DWORD,D3DX_VIDMODEDESC*);
__PODXAPI DWORD WINAPI D3DXGetMaxSurfaceFormats(DWORD,D3DX_VIDMODEDESC*,DWORD);
__PODXAPI HRESULT WINAPI D3DXGetSurfaceFormat(DWORD,D3DX_VIDMODEDESC*,DWORD,DWORD,D3DX_SURFACEFORMAT*);
__PODXAPI HRESULT WINAPI D3DXGetCurrentVideoMode(DWORD,D3DX_VIDMODEDESC*);
__PODXAPI HRESULT WINAPI D3DXGetDeviceCaps(DWORD,D3DX_VIDMODEDESC*,D3DDEVICEDESC7*,DDCAPS*,DDCAPS*);
__PODXAPI HRESULT WINAPI D3DXCreateContext(DWORD,DWORD,HWND,DWORD,DWORD,LPD3DXCONTEXT*);
__PODXAPI HRESULT WINAPI D3DXCreateContextEx(DWORD,DWORD,HWND,HWND,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,LPD3DXCONTEXT*);
__PODXAPI void WINAPI D3DXGetErrorString(HRESULT,DWORD,LPSTR);
__PODXAPI HRESULT WINAPI D3DXMakeDDPixelFormat(D3DX_SURFACEFORMAT,DDPIXELFORMAT*);
__PODXAPI D3DX_SURFACEFORMAT WINAPI D3DXMakeSurfaceFormat(DDPIXELFORMAT*);

#ifdef __cplusplus
}
#endif

DECLARE_INTERFACE_(ID3DXContext,IUnknown)
{
    STDMETHOD(QueryInterface)(THIS_ REFIID,LPVOID*) PURE;
    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
    STDMETHOD_(ULONG,Release)(THIS) PURE;
    STDMETHOD_(LPDIRECTDRAW7,GetDD)(THIS) PURE;
    STDMETHOD_(LPDIRECT3D7,GetD3D)(THIS) PURE;
    STDMETHOD_(LPDIRECT3DDEVICE7,GetD3DDevice)(THIS) PURE;
    STDMETHOD_(LPDIRECTDRAWSURFACE7,GetPrimary)(THIS) PURE;
    STDMETHOD_(LPDIRECTDRAWSURFACE7,GetZBuffer)(THIS) PURE;
    STDMETHOD_(LPDIRECTDRAWSURFACE7,GetBackBuffer)(THIS_ DWORD) PURE;
    STDMETHOD_(HWND,GetWindow)(THIS) PURE;
    STDMETHOD_(HWND,GetFocusWindow)(THIS) PURE;
    STDMETHOD(GetDeviceIndex)(THIS_ LPDWORD,LPDWORD) PURE;
    STDMETHOD_(DWORD,GetNumBackBuffers)(THIS) PURE;
    STDMETHOD(GetNumBits)(THIS_ LPDWORD,LPDWORD,LPDWORD,LPDWORD) PURE;
    STDMETHOD(GetBufferSize)(THIS_ LPDWORD,LPDWORD) PURE;
    STDMETHOD_(DWORD,GetCreationFlags)(THIS) PURE;
    STDMETHOD_(DWORD,GetRefreshRate)(THIS) PURE;
    STDMETHOD(RestoreSurfaces)(THIS) PURE;
    STDMETHOD(Resize)(THIS_ DWORD,DWORD) PURE;
    STDMETHOD(UpdateFrame)(THIS_ DWORD) PURE;
    STDMETHOD(DrawDebugText)(THIS_ float,float,D3DCOLOR,LPSTR) PURE;
    STDMETHOD(Clear)(THIS_ DWORD) PURE;
    STDMETHOD(SetClearColor)(THIS_ D3DCOLOR) PURE;
    STDMETHOD(SetClearDepth)(THIS_ float) PURE;
    STDMETHOD(SetClearStencil)(THIS_ DWORD) PURE;
};

#ifdef __cplusplus
extern "C" {
#endif

__PODXAPI HRESULT WINAPI D3DXCheckTextureRequirements(LPDIRECT3DDEVICE7,LPDWORD,LPDWORD,LPDWORD,D3DX_SURFACEFORMAT*);
__PODXAPI HRESULT WINAPI D3DXCreateTexture(LPDIRECT3DDEVICE7,LPDWORD,LPDWORD,LPDWORD,D3DX_SURFACEFORMAT*,LPDIRECTDRAWPALETTE,LPDIRECTDRAWSURFACE7*,LPDWORD);
__PODXAPI HRESULT WINAPI D3DXCreateCubeMapTexture(LPDIRECT3DDEVICE7,LPDWORD,DWORD,D3DCOLOR,LPDWORD,LPDWORD,D3DX_SURFACEFORMAT*,LPDIRECTDRAWPALETTE,LPDIRECTDRAWSURFACE7*,LPDWORD);
__PODXAPI HRESULT WINAPI D3DXCreateTextureFromFile(LPDIRECT3DDEVICE7,LPDWORD,LPDWORD,LPDWORD,D3DX_SURFACEFORMAT*,LPDIRECTDRAWPALETTE,LPDIRECTDRAWSURFACE7*,LPDWORD,LPSTR,D3DX_FILTERTYPE);
__PODXAPI HRESULT WINAPI D3DXLoadTextureFromFile(LPDIRECT3DDEVICE7,LPDIRECTDRAWSURFACE7,DWORD,LPSTR,RECT*,RECT*,D3DX_FILTERTYPE);
__PODXAPI HRESULT WINAPI D3DXLoadTextureFromSurface(LPDIRECT3DDEVICE7,LPDIRECTDRAWSURFACE7,DWORD,LPDIRECTDRAWSURFACE7,RECT*,RECT*,D3DX_FILTERTYPE);
__PODXAPI HRESULT WINAPI D3DXLoadTextureFromMemory( LPDIRECT3DDEVICE7,LPDIRECTDRAWSURFACE7,DWORD,LPVOID,LPDIRECTDRAWPALETTE,D3DX_SURFACEFORMAT,DWORD,RECT*,D3DX_FILTERTYPE);

#ifdef __cplusplus
}
#endif

#endif /* _D3DXCORE_H */
