Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

ADevice.h

Go to the documentation of this file.
00001 /*
00002 CS Senior Project 2003
00003 Team : Leftfield
00004 Project : ModernWarfare
00005 Members :
00006 - Russ Christensen              <rchriste@cs.utah.edu>
00007 - Todd Smith                    <tcsmith@cs.utah.edu>
00008 - Usit Duongsaa                 <duongsaa@cs.utah.edu>
00009 Copyright 2003 Russ Christensen, Usit Duongsaa, and Todd Smith. All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
00012 
00013 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
00014 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 
00015 THIS SOFTWARE IS PROVIDED BY RUSS CHRISTENSEN, USIT DUONGSAA, AND TODD SMITH ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RUSS, USIT, TODD OR OTHER CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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); //So we can get an all 1's bit pattern
00034         AS.device_psh = static_cast<DWORD>(-1); //So we can get an all 1'1 bit pattern
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         // direct pass-through for now because I don't think there will be much repetitions/trashing
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

Generated on Wed Apr 23 05:50:13 2003 for Modern Warfare by doxygen1.3-rc2