#pragma once

#ifdef _WIN32_WCE

#ifdef DEBUG
#define VBDEBUG 1
#endif

// D3DMVALUEではなく、floatを持つ型を定義する

/**
 * D3DVECTOR
 * D3DMVECTORのD3DMVALUEをfloatに置換している
 */
typedef struct _D3DVECTOR {
    float x;
    float y;
    float z;
} D3DVECTOR;

/**
 * D3DCOLORVALUE
 * D3DMCOLORVALUEのD3DMVALUEをfloatに置換している
 */
typedef struct _D3DCOLORVALUE {
    float r;
    float g;
    float b;
    float a;
} D3DCOLORVALUE;

typedef struct _D3DMATERIAL9 {
    D3DCOLORVALUE  Diffuse;        // Diffuse color RGBA
    D3DCOLORVALUE  Ambient;        // Ambient color RGB
    D3DCOLORVALUE  Specular;       // Specular 'shininess'
    float  Power;          // Sharpness if specular highlight
} D3DMATERIAL9;

/**
 * D3DLIGHT9
 * D3DMLIGHTの代用
 */
typedef struct _D3DLIGHT9 {
    D3DMLIGHTTYPE   Type;          // Type of light source
    D3DCOLORVALUE   Diffuse;       // Diffuse color of light
    D3DCOLORVALUE   Specular;      // Specular color of light
    D3DCOLORVALUE   Ambient;       // Ambient color of light
    D3DVECTOR       Position;      // Position in world space
    D3DVECTOR       Direction;     // Direction in world space
    float           Range;         // Cutoff range
    float           Attenuation0;  // Constant attenuation
    float           Attenuation1;  // Linear attenuation
    float           Attenuation2;  // Quadratic attenuation
} D3DLIGHT9;


// floatへの置換ここまで


// Direct3D Mobileの型に置換する

#define D3DDEVTYPE			D3DMDEVTYPE
#define D3DFORMAT			D3DMFORMAT
#define D3DRENDERSTATETYPE	D3DMRENDERSTATETYPE
#define D3DCAPS9			D3DMCAPS
#define D3DMULTISAMPLE_TYPE	D3DMMULTISAMPLE_TYPE

#define D3DADAPTER_IDENTIFIER9	D3DMADAPTER_IDENTIFIER
#define D3DDISPLAYMODE		D3DMDISPLAYMODE
#define D3DCOLOR			D3DMCOLOR
#define D3DMATRIX			D3DMMATRIX
#define D3DXMATRIX			D3DMXMATRIX
#define D3DSWAPEFFECT		D3DMSWAPEFFECT

#define D3DBLEND_ZERO		D3DMBLEND_ZERO
#define D3DBLEND_ONE		D3DMBLEND_ONE
#define D3DBLEND_SRCALPHA	D3DMBLEND_SRCALPHA
#define D3DBLEND_INVSRCALPHA	D3DMBLEND_INVSRCALPHA 
#define D3DBLEND_DESTCOLOR	D3DMBLEND_DESTCOLOR
#define D3DBLEND_SRCCOLOR	D3DMBLEND_SRCCOLOR	
#define D3DBLEND_INVSRCCOLOR	D3DMBLEND_INVSRCCOLOR
#define D3DBLEND_SRCCOLOR	D3DMBLEND_SRCCOLOR

#define D3DTOP_SELECTARG1	D3DMTOP_SELECTARG1
#define D3DTOP_MODULATE		D3DMTOP_MODULATE		
#define D3DTOP_MODULATE2X	D3DMTOP_MODULATE2X
#define D3DTOP_MODULATE4X	D3DMTOP_MODULATE4X
#define D3DTOP_ADD			D3DMTOP_ADD
#define D3DTOP_ADDSIGNED	D3DMTOP_ADDSIGNED
#define D3DTOP_ADDSIGNED2X	D3DMTOP_ADDSIGNED2X
#define D3DTOP_SUBTRACT		D3DMTOP_SUBTRACT
#define D3DTOP_LERP			D3DMTOP_LERP
#define D3DTOP_DOTPRODUCT3	D3DMTOP_DOTPRODUCT3
#define D3DTOP_DISABLE		D3DMTOP_DISABLE
#define D3DTOP_BLENDTEXTUREALPHA	D3DMTOP_BLENDTEXTUREALPHA

#define D3DTA_DIFFUSE		D3DMTA_DIFFUSE
#define	D3DTA_COMPLEMENT	D3DMTA_COMPLEMENT
#define D3DTA_ALPHAREPLICATE	D3DMTA_ALPHAREPLICATE
#define D3DTA_TEXTURE		D3DMTA_TEXTURE
#define D3DTA_TFACTOR		D3DMTA_TFACTOR
#define D3DTA_CURRENT		D3DMTA_CURRENT

#define D3DFOG_LINEAR		D3DMFOG_LINEAR
#define D3DFOG_EXP			D3DMFOG_EXP

#define D3DRS_FOGCOLOR		D3DMRS_FOGCOLOR
#define D3DRS_FOGSTART		D3DMRS_FOGSTART
#define D3DRS_FOGEND		D3DMRS_FOGEND
#define D3DRS_FOGENABLE		D3DMRS_FOGENABLE
#define D3DRS_FOGDENSITY	D3DMRS_FOGDENSITY
#define D3DRS_AMBIENT			D3DMRS_AMBIENT
#define D3DRS_LIGHTING			D3DMRS_LIGHTING
#define D3DRS_ZWRITEENABLE		D3DMRS_ZWRITEENABLE
#define D3DRS_ZFUNC				D3DMRS_ZFUNC
#define D3DRS_ZENABLE			D3DMRS_ZENABLE
#define D3DRS_ALPHAFUNC			D3DMRS_ALPHAFUNC
#define D3DRS_ALPHAREF			D3DMRS_ALPHAREF
#define D3DRS_STENCILFUNC		D3DMRS_STENCILFUNC
#define D3DRS_STENCILREF		D3DMRS_STENCILREF
#define D3DRS_STENCILMASK		D3DMRS_STENCILMASK
#define D3DRS_STENCILWRITEMASK	D3DMRS_STENCILWRITEMASK
#define D3DRS_STENCILFAIL		D3DMRS_STENCILFAIL
#define D3DRS_STENCILZFAIL		D3DMRS_STENCILZFAIL
#define D3DRS_STENCILPASS		D3DMRS_STENCILPASS
#define D3DRS_STENCILENABLE		D3DMRS_STENCILENABLE
#define D3DRS_ALPHATESTENABLE	D3DMRS_ALPHATESTENABLE
#define D3DRS_FILLMODE			D3DMRS_FILLMODE
#define D3DRS_CULLMODE			D3DMRS_CULLMODE
#define D3DRS_DEPTHBIAS			D3DMRS_DEPTHBIAS
#define D3DRS_TEXTUREFACTOR		D3DMRS_TEXTUREFACTOR
#define D3DRS_DIFFUSEMATERIALSOURCE D3DMRS_DIFFUSEMATERIALSOURCE
#define D3DRS_SPECULARMATERIALSOURCE	D3DMRS_SPECULARMATERIALSOURCE
#define D3DRS_AMBIENTMATERIALSOURCE		D3DMRS_AMBIENTMATERIALSOURCE
#define D3DRS_ALPHABLENDENABLE			D3DMRS_ALPHABLENDENABLE
#define D3DRS_SRCBLEND					D3DMRS_SRCBLEND
#define D3DRS_DESTBLEND					D3DMRS_DESTBLEND
#define D3DRS_SHADEMODE					D3DMRS_SHADEMODE
#define D3DRS_SPECULARENABLE			D3DMRS_SPECULARENABLE
#define D3DRS_LOCALVIEWER				D3DMRS_LOCALVIEWER
#define D3DRS_CLIPPING					D3DMRS_CLIPPING
#define D3DRS_NORMALIZENORMALS			D3DMRS_NORMALIZENORMALS
#define D3DRS_RANGEFOGENABLE			D3DMRS_RANGEFOGENABLE
#define D3DRS_FOGTABLEMODE				D3DMRS_FOGTABLEMODE
#define D3DRS_FOGVERTEXMODE				D3DMRS_FOGVERTEXMODE

// 対応する Direct3D Mobileの定数なし
#define D3DRS_POINTSIZE			D3DMRS_FORCE_ULONG
//#define D3DRS_EMISSIVEMATERIALSOURCE	D3DMRS_EMISSIVEMATERIALSOURCE
//#define D3DRS_CLIPPLANEENABLE	D3DMRS_CLIPPLANEENABLE
//#define D3DRS_MULTISAMPLEANTIALIAS

#define D3DSHADE_GOURAUD		D3DMSHADE_GOURAUD
#define D3DSHADE_FLAT			D3DMSHADE_FLAT


// 対応する Direct3D Mobileの定数なし
//#define D3DSAMP_MINFILTER	D3DMSAMP_MINFILTER
//#define D3DSAMP_MIPFILTER	D3DMSAMP_MIPFILTER
//#define D3DSAMP_ADDRESSU	D3DMSAMP_ADDRESSU
//#define D3DSAMP_ADDRESSV	D3DMSAMP_ADDRESSV
//#define D3DSAMP_ADDRESSW	D3DMSAMP_ADDRESSW
//#define D3DSAMP_BORDERCOLOR	D3DMSAMP_BORDERCOLOR
//#define D3DSAMP_MAXANISOTROPY	D3DMSAMP_MAXANISOTROPY

#define D3DTEXF_POINT		D3DMTEXF_POINT
#define D3DTEXF_ANISOTROPIC	D3DMTEXF_ANISOTROPIC
#define D3DTEXF_LINEAR		D3DMTEXF_LINEAR

#define D3DTADDRESS_WRAP	D3DMTADDRESS_WRAP
#define D3DTADDRESS_CLAMP	D3DMTADDRESS_CLAMP
#define D3DTADDRESS_BORDER	D3DMTADDRESS_BORDER

#define D3DSTENCILOP_KEEP	D3DMSTENCILOP_KEEP
#define D3DSTENCILOP_ZERO	D3DMSTENCILOP_ZERO
#define D3DSTENCILOP_REPLACE	D3DMSTENCILOP_REPLACE
#define D3DSTENCILOP_INCRSAT	D3DMSTENCILOP_INCRSAT
#define D3DSTENCILOP_DECRSAT	D3DMSTENCILOP_DECRSAT
#define D3DSTENCILOP_INVERT		D3DMSTENCILOP_INVERT

#define D3DCMP_ALWAYS			D3DMCMP_ALWAYS
#define D3DCMP_NEVER			D3DMCMP_NEVER
#define D3DCMP_EQUAL			D3DMCMP_EQUAL
#define D3DCMP_LESS				D3DMCMP_LESS
#define D3DCMP_NOTEQUAL			D3DMCMP_NOTEQUAL
#define D3DCMP_LESSEQUAL		D3DMCMP_LESSEQUAL
#define D3DCMP_GREATER			D3DMCMP_GREATER
#define D3DCMP_GREATEREQUAL		D3DMCMP_GREATEREQUAL

#define D3DZB_TRUE				D3DMZB_TRUE
#define D3DZB_FALSE				D3DMZB_FALSE

#define D3DCULL_CW				D3DMCULL_CW
#define D3DCULL_NONE			D3DMCULL_NONE
#define D3DCULL_CCW				D3DMCULL_CCW

#define D3DFILL_SOLID			D3DMFILL_SOLID
#define D3DFILL_POINT			D3DMFILL_POINT
#define D3DFILL_WIREFRAME		D3DMFILL_WIREFRAME

#define D3DTRANSFORMSTATETYPE	D3DMTRANSFORMSTATETYPE

#define D3DCOLOR_COLORVALUE(r,g,b,a) \
    D3DMCOLOR_RGBA((DWORD)((r)*255.f),(DWORD)((g)*255.f),(DWORD)((b)*255.f),(DWORD)((a)*255.f))

#define D3DCOLOR_RGBA D3DMCOLOR_RGBA

#define D3DTS_WORLD			D3DMTS_WORLD
#define D3DTS_VIEW			D3DMTS_VIEW
#define D3DTS_PROJECTION	D3DMTS_PROJECTION
#define D3DTS_TEXTURE0		D3DMTS_TEXTURE0
#define D3DTS_TEXTURE1		D3DMTS_TEXTURE1
#define D3DTS_TEXTURE2		D3DMTS_TEXTURE2
#define D3DTS_TEXTURE3		D3DMTS_TEXTURE3
#define D3DTS_TEXTURE4		D3DMTS_FORCE_ULONG
#define D3DTS_TEXTURE5		D3DMTS_FORCE_ULONG
#define D3DTS_TEXTURE6		D3DMTS_FORCE_ULONG
#define D3DTS_TEXTURE7		D3DMTS_FORCE_ULONG

#define D3DTSS_TEXCOORDINDEX  D3DMTSS_TEXCOORDINDEX
#define D3DTSS_COLOROP		  D3DMTSS_COLOROP
#define D3DTSS_COLORARG0	  D3DMTSS_COLORARG0
#define D3DTSS_COLORARG1	  D3DMTSS_COLORARG1
#define D3DTSS_COLORARG2	  D3DMTSS_COLORARG2
#define D3DTSS_ALPHAOP		  D3DMTSS_ALPHAOP
#define D3DTSS_ALPHAARG0	  D3DMTSS_ALPHAARG0
#define D3DTSS_ALPHAARG1	  D3DMTSS_ALPHAARG1
#define D3DTSS_ALPHAARG2	  D3DMTSS_ALPHAARG2
#define D3DTSS_ADDRESSU		  D3DMTSS_ADDRESSU
#define D3DTSS_ADDRESSV       D3DMTSS_ADDRESSV
#define D3DTSS_BORDERCOLOR    D3DMTSS_BORDERCOLOR
#define D3DTSS_MAGFILTER      D3DMTSS_MAGFILTER
#define D3DTSS_MINFILTER      D3DMTSS_MINFILTER
#define D3DTSS_MIPFILTER      D3DMTSS_MIPFILTER
#define D3DTSS_MIPMAPLODBIAS  D3DMTSS_MIPMAPLODBIAS
#define D3DTSS_MAXMIPLEVEL    D3DMTSS_MAXMIPLEVEL
#define D3DTSS_MAXANISOTROPY  D3DMTSS_MAXANISOTROPY
#define D3DTSS_TEXTURETRANSFORMFLAGS D3DMTSS_TEXTURETRANSFORMFLAGS
#define D3DTSS_ADDRESSW       D3DMTSS_ADDRESSW
#define D3DTSS_RESULTARG      D3DMTSS_RESULTARG

#define D3DTSS_TCI_PASSTHRU                    D3DMTSS_TCI_PASSTHRU
#define D3DTSS_TCI_CAMERASPACENORMAL           D3DMTSS_TCI_CAMERASPACENORMAL
#define D3DTSS_TCI_CAMERASPACEPOSITION         D3DMTSS_TCI_CAMERASPACEPOSITION
#define D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR D3DMTSS_TCI_CAMERASPACEREFLECTIONVECTOR

#define D3DTTFF_DISABLE		D3DMTTFF_DISABLE
#define D3DTTFF_COUNT1		D3DMTTFF_COUNT1
#define D3DTTFF_COUNT2		D3DMTTFF_COUNT2
#define D3DTTFF_COUNT3		D3DMTTFF_COUNT3
#define D3DTTFF_PROJECTED	D3DMTTFF_PROJECTED
#define D3DTTFF_FORCE_ULONG	D3DMTTFF_FORCE_ULONG
// Direct3D Mobileには存在しない定数
#define D3DTTFF_COUNT4		(D3DMTTFF_COUNT3+1)

#define D3DVIEWPORT9		D3DMVIEWPORT

#define D3DPRESENT_PARAMETERS	D3DMPRESENT_PARAMETERS
#define D3DPRIMITIVETYPE		D3DMPRIMITIVETYPE

#define D3DMCS_COLOR1			D3DMMCS_COLOR1
#define D3DMCS_MATERIAL			D3DMMCS_MATERIAL



#define LPDIRECT3DVERTEXBUFFER9	LPDIRECT3DMOBILEVERTEXBUFFER
#define LPDIRECT3DINDEXBUFFER9	LPDIRECT3DMOBILEINDEXBUFFER
#define LPDIRECT3DRESOURCE9		LPDIRECT3DMOBILERESOURCE
#define	LPDIRECT3D9				LPDIRECT3DMOBILE
#define LPDIRECT3DDEVICE9		LPDIRECT3DMOBILEDEVICE
#define LPDIRECT3DSURFACE9		LPDIRECT3DMOBILESURFACE
#define LPDIRECT3DTEXTURE9		LPDIRECT3DMOBILETEXTURE
#define LPDIRECT3DBASETEXTURE9	LPDIRECT3DMOBILEBASETEXTURE

#define LPDIRECT3DVOLUMETEXTURE9	LPVOID

#define D3DCLEAR_STENCIL	D3DMCLEAR_STENCIL
#define D3DCLEAR_TARGET		D3DMCLEAR_TARGET
#define D3DCLEAR_ZBUFFER	D3DMCLEAR_ZBUFFER

#define D3DERR_INVALIDCALL		D3DMERR_INVALIDCALL
#define D3DERR_DEVICELOST		D3DMERR_DEVICELOST
#define D3DERR_DEVICENOTRESET	D3DMERR_DEVICENOTRESET

#define D3DPT_POINTLIST     D3DMPT_POINTLIST
#define D3DPT_LINELIST      D3DMPT_LINELIST
#define D3DPT_LINESTRIP     D3DMPT_LINESTRIP
#define D3DPT_TRIANGLELIST  D3DMPT_TRIANGLELIST
#define D3DPT_TRIANGLESTRIP D3DMPT_TRIANGLESTRIP
#define D3DPT_TRIANGLEFAN   D3DMPT_TRIANGLEFAN
#define D3DPT_FORCE_DWORD	D3DMPT_FORCE_ULONG

#define D3DFVF_POSITION_MASK	D3DMFVF_POSITION_MASK

#define D3DFVF_TEX1				D3DMFVF_TEX1
#define D3DFVF_TEX2				D3DMFVF_TEX2
#define D3DFVF_TEX3				D3DMFVF_TEX3
#define D3DFVF_TEX4				D3DMFVF_TEX4
#define D3DFVF_TEXCOORDSIZE2	D3DMFVF_TEXCOORDSIZE2

#define D3DFVF_DIFFUSE			D3DMFVF_DIFFUSE
#define D3DFVF_SPECULAR			D3DMFVF_SPECULAR

#define D3DFVF_TEXCOUNT_SHIFT		D3DMFVF_TEXCOUNT_SHIFT
#define D3DFVF_TEXCOUNT_MASK		D3DMFVF_TEXCOUNT_MASK
#define D3DFVF_NORMAL			D3DMFVF_NORMAL_FLOAT
#define D3DFVF_XYZ			D3DMFVF_XYZ_FLOAT
#define D3DFVF_XYZRHW			D3DMFVF_XYZRHW_FLOAT

#define D3DBACKBUFFER_TYPE_MONO	D3DMBACKBUFFER_TYPE_MONO

// 対応する定義なし
//#define	D3DFVF_XYZ			D3DMFVF_XYZ

#define D3D_SDK_VERSION	D3DM_SDK_VERSION

#define D3DFMT_UNKNOWN	  D3DMFMT_UNKNOWN
#define D3DFMT_R8G8B8     D3DMFMT_R8G8B8
#define D3DFMT_A8R8G8B8	  D3DMFMT_A8R8G8B8
#define D3DFMT_X8R8G8B8   D3DMFMT_X8R8G8B8
#define D3DFMT_R5G6B5     D3DMFMT_R5G6B5
#define D3DFMT_X1R5G5B5   D3DMFMT_X1R5G5B5
#define D3DFMT_A1R5G5B5   D3DMFMT_A1R5G5B5
#define D3DFMT_A4R4G4B4   D3DMFMT_A4R4G4B4
#define D3DFMT_R3G3B2     D3DMFMT_R3G3B2
#define D3DFMT_A8R3G3B2   D3DMFMT_A8R3G3B2
#define D3DFMT_X4R4G4B4   D3DMFMT_X4R4G4B4
#define D3DFMT_A8P8       D3DMFMT_A8P8
#define D3DFMT_P8         D3DMFMT_P8
#define D3DFMT_A8         D3DMFMT_A8
#define D3DFMT_UYVY       D3DMFMT_UYVY
#define D3DFMT_YUY2       D3DMFMT_YUY2
#define D3DFMT_DXT1       D3DMFMT_DXT1
#define D3DFMT_DXT2       D3DMFMT_DXT2
#define D3DFMT_DXT3       D3DMFMT_DXT3
#define D3DFMT_DXT4       D3DMFMT_DXT4
#define D3DFMT_DXT5       D3DMFMT_DXT5
#define D3DFMT_D32        D3DMFMT_D32
#define D3DFMT_D15S1      D3DMFMT_D15S1
#define D3DFMT_D24S8      D3DMFMT_D24S8
#define D3DFMT_D16        D3DMFMT_D16
#define D3DFMT_D24X8      D3DMFMT_D24X8
#define D3DFMT_D24X4S4    D3DMFMT_D24X4S4
#define D3DFMT_INDEX16    D3DMFMT_INDEX16
#define D3DFMT_INDEX32    D3DMFMT_INDEX32
#define D3DFMT_VERTEXDATA       D3DMFMT_VERTEXDATA
#define D3DFMT_D3DMVALUE_FLOAT  D3DMFMT_D3DMVALUE_FLOAT
#define D3DFMT_D3DMVALUE_FIXED  D3DMFMT_D3DMVALUE_FIXED
#define D3DFMT_NUMFORMAT        D3DMFMT_NUMFORMAT

// Direct3D Mobileには存在しない定数値
#define D3DFMT_L8				(D3DMFORMAT)(D3DMFMT_NUMFORMAT+1)
#define D3DFMT_A8L8				(D3DMFORMAT)(D3DMFMT_NUMFORMAT+2)
#define D3DFMT_A4L4				(D3DMFORMAT)(D3DMFMT_NUMFORMAT+3)
#define D3DFMT_V8U8				(D3DMFORMAT)(D3DMFMT_NUMFORMAT+4)
#define D3DFMT_L6V5U5			(D3DMFORMAT)(D3DMFMT_NUMFORMAT+5)
#define D3DFMT_X8L8V8U8			(D3DMFORMAT)(D3DMFMT_NUMFORMAT+6)
#define D3DFMT_Q8W8V8U8			(D3DMFORMAT)(D3DMFMT_NUMFORMAT+7)
#define D3DFMT_V16U16			(D3DMFORMAT)(D3DMFMT_NUMFORMAT+8)
#define D3DFMT_D16_LOCKABLE		D3DMFMT_D16

#define D3DPOOL			D3DMPOOL
//#define D3DPOOL_DEFAULT	D3DMPOOL_DEFAULT
//#define D3DPOOL_MANAGED	D3DMPOOL_MANAGED
#define D3DPOOL_MANAGED		D3DMPOOL_SYSTEMMEM

// 対応する定義なし
// #define D3DPOOL_SCRATCH	

#define D3DDEVTYPE_HAL		D3DMDEVTYPE_DEFAULT	
#define D3DDEVTYPE_REF		D3DMDEVTYPE_DEFAULT	


#define D3DMULTISAMPLE_NONE	D3DMMULTISAMPLE_NONE

#define D3DPRESENTFLAG_LOCKABLE_BACKBUFFER D3DMPRESENTFLAG_LOCKABLE_BACKBUFFER

#define D3DSWAPEFFECT_DISCARD	D3DMSWAPEFFECT_DISCARD
#define D3DSWAPEFFECT_FLIP		D3DMSWAPEFFECT_FLIP
#define D3DSWAPEFFECT_COPY		D3DMSWAPEFFECT_COPY

#define D3DPRESENT_INTERVAL_DEFAULT		D3DMPRESENT_INTERVAL_DEFAULT
#define D3DPRESENT_INTERVAL_ONE			D3DMPRESENT_INTERVAL_ONE
#define D3DPRESENT_INTERVAL_TWO			D3DMPRESENT_INTERVAL_TWO
#define D3DPRESENT_INTERVAL_THREE		D3DMPRESENT_INTERVAL_THREE
#define D3DPRESENT_INTERVAL_FOUR		D3DMPRESENT_INTERVAL_FOUR
#define D3DPRESENT_INTERVAL_IMMEDIATE	D3DMPRESENT_INTERVAL_IMMEDIATE

#define D3DUSAGE_RENDERTARGET       D3DMUSAGE_RENDERTARGET
#define D3DUSAGE_TEXTURE            D3DMUSAGE_TEXTURE
#define D3DUSAGE_LOCKABLE           D3DMUSAGE_LOCKABLE
#define D3DUSAGE_DYNAMIC            D3DMUSAGE_DYNAMIC
#define D3DUSAGE_DONOTCLIP			D3DMUSAGE_DONOTCLIP
#define D3DUSAGE_WRITEONLY			D3DMUSAGE_WRITEONLY
#define D3DUSAGE_VALID              D3DMUSAGE_VALID

// 対応する定義なし
#define D3DUSAGE_SOFTWAREPROCESSING 0
#define D3DUSAGE_POINTS				0
#define D3DUSAGE_AUTOGENMIPMAP		0

#define D3DLOCK_READONLY		D3DMLOCK_READONLY
#define D3DLOCK_NO_DIRTY_UPDATE	D3DMLOCK_NO_DIRTY_UPDATE
#define D3DLOCK_NOOVERWRITE		D3DMLOCK_NOOVERWRITE
#define D3DLOCK_DISCARD			D3DMLOCK_DISCARD
// Direct3D Mobileには対応する定数なし
#define D3DLOCK_NOSYSLOCK		0

#define D3DDEVCAPS_CANRENDERDURINGPRESENT	D3DMDEVCAPS_CANRENDERDURINGPRESENT
#define D3DDEVCAPS_HWTRANSFORMANDLIGHT		D3DMDEVCAPS_HWTRANSFORMANDLIGHT
#define D3DDEVCAPS_HWRASTERIZATION			D3DMDEVCAPS_HWRASTERIZATION
#define D3DDEVCAPS_NATIVEFLOAT				D3DMDEVCAPS_NATIVEFLOAT
#define D3DDEVCAPS_TEXTURE					D3DMDEVCAPS_TEXTURE
#define D3DDEVCAPS_SPECULAR					D3DMDEVCAPS_SPECULAR

#define D3DPTEXTURECAPS_PERSPECTIVE			D3DMPTEXTURECAPS_PERSPECTIVE
#define D3DPTEXTURECAPS_POW2				D3DMPTEXTURECAPS_POW2
#define D3DPTEXTURECAPS_ALPHA				D3DMPTEXTURECAPS_ALPHA
#define D3DPTEXTURECAPS_SQUAREONLY			D3DMPTEXTURECAPS_SQUAREONLY
#define D3DPTEXTURECAPS_ALPHAPALETTE		D3DMPTEXTURECAPS_ALPHAPALETTE
#define D3DPTEXTURECAPS_PROJECTEDSUPPORT	D3DMPTEXTURECAPS_PROJECTEDSUPPORT
#define D3DPTEXTURECAPS_PROJECTED			D3DMPTEXTURECAPS_PROJECTED
#define D3DPTEXTURECAPS_MIPMAP				D3DMPTEXTURECAPS_MIPMAP

#define D3DPRASTERCAPS_DITHER				D3DMPRASTERCAPS_DITHER
#define D3DPRASTERCAPS_EXPFOG				D3DMPRASTERCAPS_EXPFOG
#define D3DPRASTERCAPS_EXP2FOG				D3DMPRASTERCAPS_EXP2FOG
#define D3DPRASTERCAPS_FOGVERTEX			D3DMPRASTERCAPS_FOGVERTEX
#define D3DPRASTERCAPS_FOGTABLE				D3DMPRASTERCAPS_FOGTABLE
#define D3DPRASTERCAPS_MIPMAPLODBIAS		D3DMPRASTERCAPS_MIPMAPLODBIAS
#define D3DPRASTERCAPS_DEPTHBIAS			D3DMPRASTERCAPS_DEPTHBIAS
#define D3DPRASTERCAPS_ZBUFFERLESSHSR		D3DMPRASTERCAPS_ZBUFFERLESSHSR
#define D3DPRASTERCAPS_FOGRANGE				D3DMPRASTERCAPS_FOGRANGE
#define D3DPRASTERCAPS_ANISOTROPY			D3DMPRASTERCAPS_ANISOTROPY
#define D3DPRASTERCAPS_WBUFFER				D3DMPRASTERCAPS_WBUFFER
#define D3DPRASTERCAPS_STENCIL				D3DMPRASTERCAPS_STENCIL
#define D3DPRASTERCAPS_WFOG					D3DMPRASTERCAPS_WFOG
#define D3DPRASTERCAPS_ZFOG					D3DMPRASTERCAPS_ZFOG
#define D3DPRASTERCAPS_COLORPERSPECTIVE		D3DMPRASTERCAPS_COLORPERSPECTIVE
#define D3DPRASTERCAPS_STRETCHBLTMULTISAMPLE	D3DMPRASTERCAPS_STRETCHBLTMULTISAMPLE
#define D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS	D3DMPRASTERCAPS_SLOPESCALEDEPTHBIAS

#define D3DPTADDRESSCAPS_WRAP			D3DMPTADDRESSCAPS_WRAP
#define D3DPTADDRESSCAPS_MIRROR			D3DMPTADDRESSCAPS_MIRROR
#define D3DPTADDRESSCAPS_CLAMP			D3DMPTADDRESSCAPS_CLAMP
#define D3DPTADDRESSCAPS_BORDER			D3DMPTADDRESSCAPS_BORDER
#define D3DPTADDRESSCAPS_INDEPENDENTUV	D3DMPTADDRESSCAPS_INDEPENDENTUV

#define D3DTEXOPCAPS_SELECTARG1					D3DMTEXOPCAPS_SELECTARG1
#define D3DTEXOPCAPS_SELECTARG2					D3DMTEXOPCAPS_SELECTARG2
#define D3DTEXOPCAPS_MODULATE					D3DMTEXOPCAPS_MODULATE
#define D3DTEXOPCAPS_MODULATE2X					D3DMTEXOPCAPS_MODULATE2X
#define D3DTEXOPCAPS_MODULATE4X					D3DMTEXOPCAPS_MODULATE4X
#define D3DTEXOPCAPS_ADD						D3DMTEXOPCAPS_ADD
#define D3DTEXOPCAPS_ADDSIGNED					D3DMTEXOPCAPS_ADDSIGNED
#define D3DTEXOPCAPS_ADDSIGNED2X				D3DMTEXOPCAPS_ADDSIGNED2X
#define D3DTEXOPCAPS_SUBTRACT					D3DMTEXOPCAPS_SUBTRACT
#define D3DTEXOPCAPS_ADDSMOOTH					D3DMTEXOPCAPS_ADDSMOOTH
#define D3DTEXOPCAPS_BLENDDIFFUSEALPHA			D3DMTEXOPCAPS_BLENDDIFFUSEALPHA
#define D3DTEXOPCAPS_BLENDTEXTUREALPHA			D3DMTEXOPCAPS_BLENDTEXTUREALPHA
#define D3DTEXOPCAPS_BLENDFACTORALPHA			D3DMTEXOPCAPS_BLENDFACTORALPHA
#define D3DTEXOPCAPS_BLENDTEXTUREALPHAPM		D3DMTEXOPCAPS_BLENDTEXTUREALPHAPM
#define D3DTEXOPCAPS_BLENDCURRENTALPHA			D3DMTEXOPCAPS_BLENDCURRENTALPHA
#define D3DTEXOPCAPS_PREMODULATE				D3DMTEXOPCAPS_PREMODULATE
#define D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR		D3DMTEXOPCAPS_MODULATEALPHA_ADDCOLOR
#define D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA		D3DMTEXOPCAPS_MODULATECOLOR_ADDALPHA
#define D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR	D3DMTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
#define D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA	D3DMTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
#define D3DTEXOPCAPS_DOTPRODUCT3				D3DMTEXOPCAPS_DOTPRODUCT3
#define D3DTEXOPCAPS_MULTIPLYADD				D3DMTEXOPCAPS_MULTIPLYADD
#define D3DTEXOPCAPS_LERP						D3DMTEXOPCAPS_LERP

#define D3DPRASTERCAPS_DITHER                D3DMPRASTERCAPS_DITHER
#define D3DPRASTERCAPS_EXPFOG                D3DMPRASTERCAPS_EXPFOG
#define D3DPRASTERCAPS_EXP2FOG               D3DMPRASTERCAPS_EXP2FOG
#define D3DPRASTERCAPS_FOGVERTEX             D3DMPRASTERCAPS_FOGVERTEX
#define D3DPRASTERCAPS_FOGTABLE              D3DMPRASTERCAPS_FOGTABLE
#define D3DPRASTERCAPS_MIPMAPLODBIAS         D3DMPRASTERCAPS_MIPMAPLODBIAS
#define D3DPRASTERCAPS_DEPTHBIAS             D3DMPRASTERCAPS_DEPTHBIAS
#define D3DPRASTERCAPS_ZBUFFERLESSHSR        D3DMPRASTERCAPS_ZBUFFERLESSHSR
#define D3DPRASTERCAPS_FOGRANGE              D3DMPRASTERCAPS_FOGRANGE
#define D3DPRASTERCAPS_ANISOTROPY            D3DMPRASTERCAPS_ANISOTROPY
#define D3DPRASTERCAPS_WBUFFER               D3DMPRASTERCAPS_WBUFFER
#define D3DPRASTERCAPS_STENCIL               D3DMPRASTERCAPS_STENCIL
#define D3DPRASTERCAPS_WFOG                  D3DMPRASTERCAPS_WFOG
#define D3DPRASTERCAPS_ZFOG                  D3DMPRASTERCAPS_ZFOG
#define D3DPRASTERCAPS_COLORPERSPECTIVE      D3DMPRASTERCAPS_COLORPERSPECTIVE
#define D3DPRASTERCAPS_STRETCHBLTMULTISAMPLE D3DMPRASTERCAPS_STRETCHBLTMULTISAMPLE
#define D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS   D3DMPRASTERCAPS_SLOPESCALEDEPTHBIAS

#define D3DRTYPE_SURFACE      D3DMRTYPE_SURFACE
#define D3DRTYPE_DEPTHSTENCIL D3DMRTYPE_DEPTHSTENCIL
#define D3DRTYPE_TEXTURE      D3DMRTYPE_TEXTURE
#define D3DRTYPE_FRONTBUFFER  D3DMRTYPE_FRONTBUFFER
#define D3DRTYPE_BACKBUFFER   D3DMRTYPE_BACKBUFFER
#define D3DRTYPE_VERTEXBUFFER D3DMRTYPE_VERTEXBUFFER
#define D3DRTYPE_INDEXBUFFER  D3DMRTYPE_INDEXBUFFER

#define D3DMULTISAMPLE_NONE        D3DMMULTISAMPLE_NONE
#define D3DMULTISAMPLE_2_SAMPLES   D3DMMULTISAMPLE_2_SAMPLES
#define D3DMULTISAMPLE_3_SAMPLES   D3DMMULTISAMPLE_3_SAMPLES
#define D3DMULTISAMPLE_4_SAMPLES   D3DMMULTISAMPLE_4_SAMPLES
#define D3DMULTISAMPLE_5_SAMPLES   D3DMMULTISAMPLE_5_SAMPLES
#define D3DMULTISAMPLE_6_SAMPLES   D3DMMULTISAMPLE_6_SAMPLES
#define D3DMULTISAMPLE_7_SAMPLES   D3DMMULTISAMPLE_7_SAMPLES
#define D3DMULTISAMPLE_8_SAMPLES   D3DMMULTISAMPLE_8_SAMPLES
#define D3DMULTISAMPLE_9_SAMPLES   D3DMMULTISAMPLE_9_SAMPLES
#define D3DMULTISAMPLE_10_SAMPLES  D3DMMULTISAMPLE_10_SAMPLES
#define D3DMULTISAMPLE_11_SAMPLES  D3DMMULTISAMPLE_11_SAMPLES
#define D3DMULTISAMPLE_12_SAMPLES  D3DMMULTISAMPLE_12_SAMPLES
#define D3DMULTISAMPLE_13_SAMPLES  D3DMMULTISAMPLE_13_SAMPLES
#define D3DMULTISAMPLE_14_SAMPLES  D3DMMULTISAMPLE_14_SAMPLES
#define D3DMULTISAMPLE_15_SAMPLES  D3DMMULTISAMPLE_15_SAMPLES
#define D3DMULTISAMPLE_16_SAMPLES  D3DMMULTISAMPLE_16_SAMPLES

#define D3DLIGHT_POINT			D3DMLIGHT_POINT
#define D3DLIGHT_DIRECTIONAL	D3DMLIGHT_DIRECTIONAL

// Direct3D MobileにはD3DLIGHT_SPOTに対応する定数が存在しないので
// D3DMLIGHT_DIRECTIONALでごまかす
#define D3DLIGHT_SPOT	D3DMLIGHT_DIRECTIONAL


#define D3DLOCKED_RECT	    D3DMLOCKED_RECT
#define	D3DSURFACE_DESC	    D3DMSURFACE_DESC
#define D3DINDEXBUFFER_DESC D3DMINDEXBUFFER_DESC

#define D3DDP_MAXTEXCOORD   8



// 関数
#define Direct3DCreate9	  Direct3DMobileCreate
#define D3DXCreateTexture D3DMXCreateTexture

// Direct3D Mobileには存在しない関数
extern char *DXGetErrorString9(HRESULT hr);
extern UINT D3DXGetFVFVertexSize(DWORD FVF);

// IDirect3DDevice9との違いをごまかす
// IDirect3DDevice9::GetFrontBufferData()
#define GetFrontBufferData(iSwapChain,pDestSurface)	GetFrontBuffer(pDestSurface)

// IDirect3DDevice9::SetVertexShader()
// 副作用のなさそうな関数に置き換えてしまう
#define SetVertexShader(pShader)	GetAvailablePoolMem(D3DMPOOL_VIDEOMEM)
// IDirect3DDevice9::SetFVF()
// 副作用のなさそうな関数に置き換えてしまう
#define SetFVF(FVF)					GetAvailablePoolMem(D3DMPOOL_VIDEOMEM)

// IDirectDevice9::SetSoftwareVertexProcessing()
#define SetSoftwareVertexProcessing(bSoftware) GetAvailablePoolMem(D3DMPOOL_VIDEOMEM)


// ダミー変数。
extern D3DMFORMAT dummy_d3dmfmt_float[1];

// 引数の違いをごまかす
// IDirect3DMobileDevice::SetLight()
#define SetLight(a, b)	SetLight(a, (D3DMLIGHT*)b, D3DMFMT_D3DMVALUE_FLOAT)
// IDirect3DMobileDevice::GetLight()
#define GetLight(Index,pLight)	GetLight(Index,(D3DMLIGHT*)pLight,dummy_d3dmfmt_float)	
// IDirect3DMobileDevice::SetMaterial()
#define SetMaterial(pMaterial)	SetMaterial((D3DMMATERIAL*)pMaterial,D3DMFMT_D3DMVALUE_FLOAT)
// IDirect3DMobileDevice::GetMaterial()
#define GetMaterial(pMaterial)	GetMaterial((D3DMMATERIAL*)pMaterial,dummy_d3dmfmt_float)
// IDirect3DMobileDevice::SetTransform()
#define SetTransform(State,pMatrix)	SetTransform(State,(const D3DMMATRIX*)pMatrix,D3DMFMT_D3DMVALUE_FLOAT)
// IDirect3DMobileDevice::GetTransform()
#define GetTransform(State,pMatrix)	GetTransform(State,(D3DMMATRIX*)pMatrix,dummy_d3dmfmt_float)

// IDirect3DMobileDevice::GetBackBuffer()
#define GetBackBuffer(iSwapChain,BackBuffer,Type,ppBackBuffer)	GetBackBuffer(BackBuffer,Type,ppBackBuffer)
// IDirect3DMobileDevice::SetStreamSource
#define SetStreamSource(StreamNumber,pStreamData,OffsetInBytes,Stride)	SetStreamSource(StreamNumber,pStreamData,Stride)
// IDirect3DMobileDevice::CreateVertexBuffer()
#define CreateVertexBuffer(Length,Usage,FVF,Pool,ppVertexBuffer,pSharedHandle)	CreateVertexBuffer(Length,Usage,FVF,Pool,ppVertexBuffer)
// IDirect3DMobileDevice::CreateIndexBuffer()
#define CreateIndexBuffer(Length,Usage,Format,Pool,ppIndexBuffer,pSharedHandle)	CreateIndexBuffer(Length,Usage,Format,Pool,ppIndexBuffer)
// IDirect3DMobile::CheckDeviceMultiSampleType()
#define CheckDeviceMultiSampleType(Adapter,DeviceType,SurfaceFormat,Windowed,MultiSampleType,pQualityLevels)	CheckDeviceMultiSampleType(Adapter,DeviceType,SurfaceFormat,Windowed,MultiSampleType)	
// IDirect3DMobile::ProcessVertices()
#define ProcessVertices(SrcStartIndex,DestIndex,VertexCount,pDestBuffer,pVertexDecl,Flags)	ProcessVertices(SrcStartIndex,DestIndex,VertexCount,pDestBuffer,Flags)
// IDirect3DDevice9::CreateOffscreenPlainSurface()
#define CreateOffscreenPlainSurface(Width,Height,Format,Pool,ppSurface,pSharedHandle)	CreateImageSurface(Width,Height,Format,ppSurface)

// stricmp()
#define stricmp(a,b)	_stricmp(a,b)

// DeviceCaps
extern D3DMCAPS g_deviceCaps;

// CreateIndexBuffer()の引数D3DMPOOLに渡す変数
extern D3DMPOOL g_indexBufferPool;

// CreateVertexBuffer()の引数D3DMPOOLに渡す変数
extern D3DMPOOL g_vertexBufferPool;

#endif