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

panda/src/dxgsg8/dxGraphicsStateGuardian8.I

Go to the documentation of this file.
00001 // Filename: dxGraphicsStateGuardian8.I
00002 // Created by:  mike (02Feb99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 // for dxgsg8_cat stuff
00020 #include "config_dxgsg8.h"
00021 
00022 ////////////////////////////////////////////////////////////////////
00023 //     Function: DXGraphicsStateGuardian8::enable_line_smooth
00024 //       Access:
00025 //  Description:
00026 ////////////////////////////////////////////////////////////////////
00027 INLINE void DXGraphicsStateGuardian8::
00028 enable_line_smooth(bool val) {
00029   if(_line_smooth_enabled != val) {
00030     _line_smooth_enabled = val;
00031   #ifdef NDEBUG
00032     {
00033         if(val && (_pScrn->d3dcaps.RasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES))
00034            dxgsg8_cat.error() << "no HW support for line smoothing!!\n";
00035     }
00036   #endif
00037 
00038     _pD3DDevice->SetRenderState(D3DRS_EDGEANTIALIAS, (DWORD)val);
00039   }
00040 }
00041 
00042 ////////////////////////////////////////////////////////////////////
00043 //     Function: DXGraphicsStateGuardian8::enable_dither
00044 //       Access:
00045 //  Description:
00046 ////////////////////////////////////////////////////////////////////
00047 INLINE void DXGraphicsStateGuardian8::
00048 enable_dither(bool val) {
00049   if (_dither_enabled != val) {
00050 
00051   #ifdef _DEBUG
00052     {
00053         if(val && !(_pScrn->d3dcaps.RasterCaps & D3DPRASTERCAPS_DITHER))
00054            dxgsg8_cat.error() << "no HW support for color dithering!!\n";
00055         return;
00056     }
00057   #endif
00058 
00059     _dither_enabled = val;
00060     _pD3DDevice->SetRenderState(D3DRS_DITHERENABLE, (DWORD)val);
00061   }
00062 }
00063 
00064 ////////////////////////////////////////////////////////////////////
00065 //     Function: DXGraphicsStateGuardian8::enable_stencil_test
00066 //       Access:
00067 //  Description:
00068 ////////////////////////////////////////////////////////////////////
00069 INLINE void DXGraphicsStateGuardian8::
00070 enable_stencil_test(bool val) {
00071   if (_stencil_test_enabled != val) {
00072     _stencil_test_enabled = val;
00073     _pD3DDevice->SetRenderState(D3DRS_STENCILENABLE, (DWORD)val);
00074   }
00075 }
00076 
00077 ////////////////////////////////////////////////////////////////////
00078 //     Function: DXGraphicsStateGuardian8::enable_color_material
00079 //       Access:
00080 //  Description:
00081 ////////////////////////////////////////////////////////////////////
00082 INLINE void DXGraphicsStateGuardian8::
00083 enable_color_material(bool val) {
00084   if (_color_material_enabled != val) {
00085     _color_material_enabled = val;
00086   }
00087 }
00088 
00089 
00090 ////////////////////////////////////////////////////////////////////
00091 //     Function: DXGraphicsStateGuardian8::enable_blend
00092 //       Access:
00093 //  Description:
00094 ////////////////////////////////////////////////////////////////////
00095 INLINE void DXGraphicsStateGuardian8::
00096 enable_blend(bool val) {
00097   if (_blend_enabled != val) {
00098     _blend_enabled = val;
00099     _pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, (DWORD)val);
00100   }
00101 }
00102 
00103 ////////////////////////////////////////////////////////////////////
00104 //     Function: DXGraphicsStateGuardian8::set_color_writemask
00105 //       Access:
00106 //  Description:
00107 ////////////////////////////////////////////////////////////////////
00108 INLINE void DXGraphicsStateGuardian8::
00109 set_color_writemask(UINT color_writemask) {
00110   if (_color_writemask != color_writemask) {
00111     _color_writemask = color_writemask;
00112     if(_pScrn->bCanDirectDisableColorWrites) {
00113         // only newer HW supports this rstate
00114         _pD3DDevice->SetRenderState(D3DRS_COLORWRITEENABLE, (DWORD)color_writemask);
00115     } else {
00116         // blending can only handle on/off
00117         assert((color_writemask==0x0)||(color_writemask==0xFFFFFFFF));
00118         set_blend_mode(_color_write_mode, _color_blend_mode, _transparency_mode);        
00119     }
00120   }
00121 }
00122 
00123 ////////////////////////////////////////////////////////////////////
00124 //     Function: DXGraphicsStateGuardian8::enable_blend
00125 //       Access:
00126 //  Description:
00127 ////////////////////////////////////////////////////////////////////
00128 INLINE void DXGraphicsStateGuardian8::
00129 enable_gouraud_shading(bool val) {
00130   if (_bGouraudShadingOn != val) {
00131     _bGouraudShadingOn = val;
00132     _pD3DDevice->SetRenderState(D3DRS_SHADEMODE, (val ? D3DSHADE_GOURAUD : D3DSHADE_FLAT));
00133   }
00134 }
00135 
00136 INLINE void DXGraphicsStateGuardian8::
00137 enable_primitive_clipping(bool val) {
00138   if (_clipping_enabled != val) {
00139     _clipping_enabled = val;
00140     _pD3DDevice->SetRenderState(D3DRS_CLIPPING, (DWORD)val);
00141   }
00142 }
00143 
00144 ////////////////////////////////////////////////////////////////////
00145 //     Function: DXGraphicsStateGuardian8::enable_fog
00146 //       Access:
00147 //  Description:
00148 ////////////////////////////////////////////////////////////////////
00149 INLINE void DXGraphicsStateGuardian8::
00150 enable_fog(bool val) {
00151   if ((_fog_enabled != val) && (_doFogType!=None)) {
00152     _fog_enabled = val;
00153     _pD3DDevice->SetRenderState(D3DRS_FOGENABLE, (DWORD)val);
00154   }
00155 }
00156 
00157 ////////////////////////////////////////////////////////////////////
00158 //     Function: DXGraphicsStateGuardian8::set_vertex_format
00159 //       Access:
00160 //  Description:
00161 ////////////////////////////////////////////////////////////////////
00162 INLINE void DXGraphicsStateGuardian8::
00163 set_vertex_format(DWORD NewFvfType) {
00164 #ifdef USE_VERTEX_SHADERS
00165   if(_CurVertexShader!=NULL) {
00166     // this needs optimization
00167     HRESULT hr = _pD3DDevice->SetVertexShader(_CurVertexShader);
00168     #ifndef NDEBUG
00169     if(FAILED(hr)) {
00170            dxgsg8_cat.error() << "SetVertexShader for custom vtx shader failed" << D3DERRORSTRING(hr);
00171            exit(1);
00172     }
00173     #endif
00174     _CurFVFType = NewFvfType;    
00175     return;
00176   }
00177 #endif
00178 
00179   if (_CurFVFType != NewFvfType) {
00180     _CurFVFType = NewFvfType;
00181 
00182     HRESULT hr = _pD3DDevice->SetVertexShader(NewFvfType);
00183  #ifndef NDEBUG
00184     if(FAILED(hr)) {
00185            dxgsg8_cat.error() << "SetVertexShader(0x" << (void*)NewFvfType<<") failed" << D3DERRORSTRING(hr);
00186            exit(1);
00187     }
00188  #endif
00189   }
00190 }
00191 
00192 ////////////////////////////////////////////////////////////////////
00193 //     Function: DXGraphicsStateGuardian8::enable_alpha_test
00194 //       Access:
00195 //  Description:
00196 ////////////////////////////////////////////////////////////////////
00197 INLINE void DXGraphicsStateGuardian8::
00198 enable_alpha_test(bool val )
00199 {
00200   if (_alpha_test_enabled != val) {
00201     _alpha_test_enabled = val;
00202     _pD3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, (DWORD)val);
00203   }
00204 }
00205 
00206 ////////////////////////////////////////////////////////////////////
00207 //     Function: DXGraphicsStateGuardian8::call_dxLightModelAmbient
00208 //       Access:
00209 //  Description:
00210 ////////////////////////////////////////////////////////////////////
00211 INLINE void DXGraphicsStateGuardian8::
00212 call_dxLightModelAmbient( const Colorf& color)
00213 {
00214   if (_lmodel_ambient != color) {
00215     _lmodel_ambient = color;
00216 #ifdef GSG_VERBOSE
00217     dxgsg8_cat.debug() << "dxLightModel(LIGHT_MODEL_AMBIENT, " << color << ")" << endl;
00218 #endif
00219     _pD3DDevice->SetRenderState( D3DRS_AMBIENT,
00220                 D3DCOLOR_COLORVALUE(color[0], color[1], color[2], color[3]));
00221   }
00222 }
00223 
00224 
00225 ////////////////////////////////////////////////////////////////////
00226 //     Function: DXGraphicsStateGuardian8::call_dxAlphaFunc
00227 //       Access:
00228 //  Description:
00229 ////////////////////////////////////////////////////////////////////
00230 INLINE void DXGraphicsStateGuardian8::
00231 call_dxAlphaFunc(D3DCMPFUNC func, float reference_alpha) {
00232   if (_alpha_func != func) {
00233     _alpha_func = func;
00234 #ifdef GSG_VERBOSE
00235     dxgsg8_cat.debug() << "dxAlphaFunc(";
00236     switch (func) {
00237     case D3DCMP_NEVER:
00238       dxgsg8_cat.debug(false) << "D3DCMP_NEVER";
00239       break;
00240     case D3DCMP_LESS:
00241       dxgsg8_cat.debug(false) << "D3DCMP_LESS";
00242       break;
00243     case D3DCMP_EQUAL:
00244       dxgsg8_cat.debug(false) << "D3DCMP_EQUAL";
00245       break;
00246 #ifdef D3DCMP_LEQUAL
00247     case D3DCMP_LEQUAL:
00248       dxgsg8_cat.debug(false) << "D3DCMP_LEQUAL";
00249       break;
00250 #endif
00251     case D3DCMP_GREATER:
00252       dxgsg8_cat.debug(false) << "D3DCMP_GREATER";
00253       break;
00254     case D3DCMP_NOTEQUAL:
00255       dxgsg8_cat.debug(false) << "D3DCMP_NOTEQUAL";
00256       break;
00257 #ifdef D3DCMP_GEQUAL
00258     case D3DCMP_GEQUAL:
00259       dxgsg8_cat.debug(false) << "D3DCMP_GEQUAL";
00260       break;
00261 #endif
00262     case D3DCMP_ALWAYS:
00263       dxgsg8_cat.debug(false) << "D3DCMP_ALWAYS";
00264       break;
00265     }
00266     dxgsg8_cat.debug() << " , " << reference_alpha << ")" << endl;
00267 #endif
00268     _pD3DDevice->SetRenderState(D3DRS_ALPHAFUNC, func);
00269   }
00270 
00271   if(_alpha_func_refval != reference_alpha) {
00272       _alpha_func_refval = reference_alpha;
00273       _pD3DDevice->SetRenderState(D3DRS_ALPHAREF, (UINT) (reference_alpha*255.0f));  //d3d uses 0x0-0xFF, not a float
00274   }
00275 }
00276 
00277 
00278 INLINE void DXGraphicsStateGuardian8::
00279 call_dxBlendFunc(D3DBLEND sfunc, D3DBLEND dfunc )
00280 {
00281   if (_blend_source_func != sfunc)
00282     {
00283     _blend_source_func = sfunc;
00284     _pD3DDevice->SetRenderState(D3DRS_SRCBLEND, sfunc);
00285 #ifdef GSG_VERBOSE
00286     dxgsg8_cat.debug() << "dxSrcBlendFunc(";
00287     switch (sfunc)
00288         {
00289         case D3DBLEND_ZERO:
00290           dxgsg8_cat.debug(false) << "ZERO, ";
00291           break;
00292         case D3DBLEND_ONE:
00293           dxgsg8_cat.debug(false) << "ONE, ";
00294           break;
00295         case D3DBLEND_DESTCOLOR:
00296           dxgsg8_cat.debug(false) << "DESTCOLOR, ";
00297           break;
00298         case D3DBLEND_INVDESTCOLOR:
00299           dxgsg8_cat.debug(false) << "INVDESTCOLOR, ";
00300           break;
00301         case D3DBLEND_SRCALPHA:
00302           dxgsg8_cat.debug(false) << "SRCALPHA, ";
00303           break;
00304         case D3DBLEND_INVSRCALPHA:
00305           dxgsg8_cat.debug(false) << "INVSRCALPHA, ";
00306           break;
00307         case D3DBLEND_DESTALPHA:
00308           dxgsg8_cat.debug(false) << "DESTALPHA, ";
00309           break;
00310         case D3DBLEND_INVDESTALPHA:
00311           dxgsg8_cat.debug(false) << "INVDESTALPHA, ";
00312           break;
00313         case D3DBLEND_SRCALPHASAT:
00314           dxgsg8_cat.debug(false) << "SRCALPHASAT, ";
00315           break;
00316         default:
00317           dxgsg8_cat.debug(false) << "unknown, ";
00318           break;
00319         }
00320     dxgsg8_cat.debug(false) << endl;
00321 #endif
00322     }
00323   if ( _blend_dest_func != dfunc)
00324     {
00325     _blend_dest_func = dfunc;
00326     _pD3DDevice->SetRenderState(D3DRS_DESTBLEND, dfunc);
00327 #ifdef GSG_VERBOSE
00328     dxgsg8_cat.debug() << "dxDstBlendFunc(";
00329     switch (dfunc)
00330         {
00331         case D3DBLEND_ZERO:
00332           dxgsg8_cat.debug(false) << "ZERO, ";
00333           break;
00334         case D3DBLEND_ONE:
00335           dxgsg8_cat.debug(false) << "ONE, ";
00336           break;
00337         case D3DBLEND_DESTCOLOR:
00338           dxgsg8_cat.debug(false) << "DESTCOLOR, ";
00339           break;
00340         case D3DBLEND_INVDESTCOLOR:
00341           dxgsg8_cat.debug(false) << "INVDESTCOLOR, ";
00342           break;
00343         case D3DBLEND_SRCALPHA:
00344           dxgsg8_cat.debug(false) << "SRCALPHA, ";
00345           break;
00346         case D3DBLEND_INVSRCALPHA:
00347           dxgsg8_cat.debug(false) << "INVSRCALPHA, ";
00348           break;
00349         case D3DBLEND_DESTALPHA:
00350           dxgsg8_cat.debug(false) << "DESTALPHA, ";
00351           break;
00352         case D3DBLEND_INVDESTALPHA:
00353           dxgsg8_cat.debug(false) << "INVDESTALPHA, ";
00354           break;
00355         case D3DBLEND_SRCALPHASAT:
00356           dxgsg8_cat.debug(false) << "SRCALPHASAT, ";
00357           break;
00358         }
00359     dxgsg8_cat.debug(false) << endl;
00360 #endif
00361     }
00362 }
00363 
00364 INLINE void DXGraphicsStateGuardian8::
00365 enable_zwritemask(bool val) {
00366     if (_depth_write_enabled != val) {
00367         _depth_write_enabled = val;
00368         _pD3DDevice->SetRenderState(D3DRS_ZWRITEENABLE, val);
00369     }
00370 }
00371 
00372 /**  unimplemented
00373 
00374 ////////////////////////////////////////////////////////////////////
00375 //     Function: DXGraphicsStateGuardian8::enable_multisample
00376 //       Access:
00377 //  Description:
00378 ////////////////////////////////////////////////////////////////////
00379 INLINE void DXGraphicsStateGuardian8::
00380 enable_multisample(bool val) {
00381   _multisample_enabled = val;
00382   #ifdef NDEBUG
00383     dxgsg8_cat.error() << "dx multisample unimplemented!!\n";
00384   #endif
00385 }
00386 
00387 ////////////////////////////////////////////////////////////////////
00388 //     Function: DXGraphicsStateGuardian8::enable_multisample_alpha_one
00389 //       Access:
00390 //  Description:
00391 ////////////////////////////////////////////////////////////////////
00392 INLINE void DXGraphicsStateGuardian8::
00393 enable_multisample_alpha_one(bool val) {
00394   if (_multisample_alpha_one_enabled != val) {
00395     _multisample_alpha_one_enabled = val;
00396   }
00397 }
00398 
00399 ////////////////////////////////////////////////////////////////////
00400 //     Function: DXGraphicsStateGuardian8::enable_multisample_alpha_mask
00401 //       Access:
00402 //  Description:
00403 ////////////////////////////////////////////////////////////////////
00404 INLINE void DXGraphicsStateGuardian8::
00405 enable_multisample_alpha_mask(bool val) {
00406   if (_multisample_alpha_mask_enabled != val) {
00407     _multisample_alpha_mask_enabled = val;
00408   }
00409 }
00410 
00411 ////////////////////////////////////////////////////////////////////
00412 //     Function: DXGraphicsStateGuardian8::enable_point_smooth
00413 //       Access:
00414 //  Description:
00415 ////////////////////////////////////////////////////////////////////
00416 INLINE void DXGraphicsStateGuardian8::
00417 enable_point_smooth(bool val) {
00418   // _point_smooth_enabled = val;
00419 
00420   #ifdef NDEBUG
00421     dxgsg8_cat.error() << "dx point smoothing unimplemented!!\n";
00422   #endif
00423 }
00424 */
00425 

Generated on Fri May 2 00:37:16 2003 for Panda by doxygen1.3