00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00024 #ifndef INCLUDE_ADEVICE
00025 #define INCLUDE_ADEVICE
00026
00027 #include "AState.h"
00028
00029
00030
00031 inline void device_flushSettings()
00032 {
00033 AS.device_vsh = static_cast<DWORD>(-1);
00034 AS.device_psh = static_cast<DWORD>(-1);
00035 AS.device_ib = NULL;
00036 for( int i=0; i<MAX_STREAM; i++ ) AS.device_vb[i] = NULL;
00037 for( int i=0; i<MAX_STATE_TYPE; i++ ) AS.device_renderStates[i] = static_cast<UINT>(-1);
00038 for( int i=0; i<MAX_TEXTURE; i++ ) AS.device_texture[i] = NULL;
00039 }
00040
00041 inline void device_setTextureStageState( DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value )
00042 {
00043
00044 AS.pDevice->SetTextureStageState(Stage,Type,Value);
00045 }
00046
00047 inline void device_setRenderState( D3DRENDERSTATETYPE state, DWORD value )
00048 {
00049 assert( state>=0 && state<MAX_STATE_TYPE );
00050 if( AS.device_renderStates[state] != value )
00051 {
00052 AS.device_renderStates[state] = value;
00053 AS.pDevice->SetRenderState( state, value );
00054 }
00055 }
00056
00057 inline void device_setVertexShader( DWORD vsh )
00058 {
00059 if( AS.device_vsh != vsh )
00060 {
00061 AS.device_vsh = vsh;
00062 AS.pDevice->SetVertexShader(vsh);
00063 }
00064 }
00065
00066 inline void device_setPixelShader( DWORD psh )
00067 {
00068 if( AS.device_psh != psh )
00069 {
00070 AS.device_psh = psh;
00071 AS.pDevice->SetPixelShader(psh);
00072 }
00073 }
00074
00075 inline void device_setRenderStateBlendMode( int blendMode )
00076 {
00077 switch(blendMode)
00078 {
00079
00080 case BlendModes::NONE:
00081 device_setRenderState( D3DRS_ALPHABLENDENABLE, false );
00082 device_setRenderState( D3DRS_ALPHATESTENABLE, FALSE );
00083 device_setRenderState( D3DRS_ALPHAFUNC, D3DCMP_ALWAYS );
00084 break;
00085
00086 case BlendModes::KEY:
00087 device_setRenderState( D3DRS_ALPHATESTENABLE, TRUE );
00088 device_setRenderState( D3DRS_ALPHABLENDENABLE, false );
00089 device_setRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATER );
00090 device_setRenderState( D3DRS_ALPHAREF, 0x0 );
00091 break;
00092
00093 case BlendModes::ADD:
00094 device_setRenderState( D3DRS_ALPHABLENDENABLE, true );
00095 device_setRenderState( D3DRS_ALPHATESTENABLE, FALSE );
00096 device_setRenderState( D3DRS_ALPHAFUNC, D3DCMP_ALWAYS );
00097 device_setRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
00098 device_setRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
00099 break;
00100
00101 case BlendModes::MIX:
00102 device_setRenderState( D3DRS_ALPHABLENDENABLE, true );
00103 device_setRenderState( D3DRS_ALPHATESTENABLE, FALSE );
00104 device_setRenderState( D3DRS_ALPHAFUNC, D3DCMP_ALWAYS );
00105 device_setRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
00106 device_setRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
00107 break;
00108
00109 default:
00110 assert( false && "Invalid blendMode" );
00111 };
00112 }
00113
00114 inline void device_setStreamSource( int streamNum, IDirect3DVertexBuffer8* pStreamData, UINT Stride )
00115 {
00116 assert( streamNum>=0 && streamNum<MAX_STREAM );
00117 if( AS.device_vb[streamNum] != pStreamData )
00118 {
00119 AS.device_vb[streamNum] = pStreamData;
00120 AS.pDevice->SetStreamSource( streamNum, pStreamData, Stride );
00121 }
00122 }
00123
00124 inline void device_setIndexSource( LPDIRECT3DINDEXBUFFER8 pIB )
00125 {
00126 if( AS.device_ib != pIB )
00127 {
00128 AS.device_ib = pIB;
00129 AS.pDevice->SetIndices( pIB, 0 );
00130 }
00131 }
00132
00133 inline void device_setTexture( int stageNo, IDirect3DBaseTexture8 *pTexture )
00134 {
00135 assert( stageNo>=0 && stageNo<MAX_TEXTURE );
00136 if( AS.device_texture[stageNo] != pTexture )
00137 {
00138 AS.device_texture[stageNo] = pTexture;
00139 AS.pDevice->SetTexture( stageNo, pTexture );
00140 }
00141 }
00142
00143
00144
00145
00146
00147 #endif