# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

driver_material_inline.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #ifndef NL_DRIVER_MATERIAL_INLINE_H
00027 #define NL_DRIVER_MATERIAL_INLINE_H
00028 
00029 #include "nel/misc/debug.h"
00030 
00031 namespace NL3D
00032 {
00033 
00034 // --------------------------------------------------
00035 
00036 inline bool CMaterial::texturePresent(uint8 n) const
00037 {
00038         nlassert(n<IDRV_MAT_MAXTEXTURES);
00039         if (_Textures[n])
00040         {
00041                 return(true);
00042         }
00043         return(false);
00044 }
00045 
00046 inline ITexture*                CMaterial::getTexture(uint8 n) const
00047 { 
00048         nlassert(n<IDRV_MAT_MAXTEXTURES);
00049         return(_Textures[n]); 
00050 }
00051 
00052 inline void CMaterial::setSrcBlend(TBlend val)
00053 {
00054         _SrcBlend=val;
00055         _Touched|=IDRV_TOUCHED_BLENDFUNC;
00056 }
00057 
00058 inline void CMaterial::setDstBlend(TBlend val)
00059 {
00060         _DstBlend=val;
00061         _Touched|=IDRV_TOUCHED_BLENDFUNC;
00062 }
00063 
00064 inline void CMaterial::setBlend(bool active)
00065 {
00066         if (active)     _Flags|=IDRV_MAT_BLEND;
00067         else            _Flags&=~IDRV_MAT_BLEND;
00068         _Touched|=IDRV_TOUCHED_BLEND;
00069 }
00070 
00071 inline void CMaterial::setDoubleSided(bool active)
00072 {
00073         if (active)     _Flags|=IDRV_MAT_DOUBLE_SIDED;
00074         else            _Flags&=~IDRV_MAT_DOUBLE_SIDED;
00075         _Touched|=IDRV_TOUCHED_DOUBLE_SIDED;
00076 }
00077 
00078 inline void CMaterial::setAlphaTest(bool active)
00079 {
00080         if (active)     _Flags|=IDRV_MAT_ALPHA_TEST;
00081         else            _Flags&=~IDRV_MAT_ALPHA_TEST;
00082         _Touched|=IDRV_TOUCHED_ALPHA_TEST;
00083 }
00084 
00085 inline void CMaterial::setAlphaTestThreshold(float thre)
00086 {
00087         _AlphaTestThreshold= thre;
00088         _Touched|=IDRV_TOUCHED_ALPHA_TEST_THRE;
00089 }
00090 
00091 inline void     CMaterial::setBlendFunc(TBlend src, TBlend dst)
00092 {
00093         _SrcBlend=src;
00094         _DstBlend=dst;
00095         _Touched|=IDRV_TOUCHED_BLENDFUNC;
00096 }
00097 
00098 
00099 inline void CMaterial::setZFunc(ZFunc val)
00100 {
00101         _ZFunction=val;
00102         _Touched|=IDRV_TOUCHED_ZFUNC;
00103 }
00104 
00105 inline void     CMaterial::setZWrite(bool active)
00106 {
00107         if (active)     _Flags|=IDRV_MAT_ZWRITE;
00108         else            _Flags&=~IDRV_MAT_ZWRITE;
00109         _Touched|=IDRV_TOUCHED_ZWRITE;
00110 }
00111 
00112 inline void CMaterial::setZBias(float val)
00113 {
00114         _ZBias=val;
00115         _Touched|=IDRV_TOUCHED_ZBIAS;
00116 }
00117 
00118 inline void CMaterial::setColor(NLMISC::CRGBA rgba)
00119 {
00120         if (_Color != rgba)
00121         {
00122                 _Color=rgba;
00123                 _Touched|=IDRV_TOUCHED_COLOR;
00124         }
00125 }
00126 
00127 inline void CMaterial::setLighting(     bool active, 
00128                                                                         NLMISC::CRGBA emissive, 
00129                                                                         NLMISC::CRGBA ambient, 
00130                                                                         NLMISC::CRGBA diffuse, 
00131                                                                         NLMISC::CRGBA specular,
00132                                                                         float   shininess)
00133 {
00134         if (active)
00135         {
00136                 _Flags|=IDRV_MAT_LIGHTING;
00137         }
00138         else
00139         {
00140                 _Flags&=~IDRV_MAT_LIGHTING;
00141         }
00142         _Emissive=emissive;
00143         _Ambient=ambient;
00144         _Diffuse=diffuse;
00145         _Specular=specular;
00146         _Shininess= shininess;
00147         _Touched|=IDRV_TOUCHED_LIGHTING;
00148 }
00149 
00150 
00151 // ***************************************************************************
00152 inline void     CMaterial::setEmissive( CRGBA emissive)
00153 {
00154         _Emissive= emissive;
00155         _Touched|=IDRV_TOUCHED_LIGHTING;
00156 }
00157 // ***************************************************************************
00158 inline void     CMaterial::setAmbient( CRGBA ambient)
00159 {
00160         _Ambient= ambient;
00161         _Touched|=IDRV_TOUCHED_LIGHTING;
00162 }
00163 // ***************************************************************************
00164 inline void     CMaterial::setDiffuse( CRGBA diffuse)
00165 {
00166         // Keep opacity.
00167         _Diffuse.R= diffuse.R;
00168         _Diffuse.G= diffuse.G;
00169         _Diffuse.B= diffuse.B;
00170         _Touched|=IDRV_TOUCHED_LIGHTING;
00171 }
00172 // ***************************************************************************
00173 inline void     CMaterial::setOpacity( uint8    opa )
00174 {
00175         _Diffuse.A= opa;
00176         _Touched|=IDRV_TOUCHED_LIGHTING;
00177 }
00178 // ***************************************************************************
00179 inline void     CMaterial::setSpecular( CRGBA specular)
00180 {
00181         _Specular= specular;
00182         _Touched|=IDRV_TOUCHED_LIGHTING;
00183 }
00184 // ***************************************************************************
00185 inline void     CMaterial::setShininess( float shininess )
00186 {
00187         _Shininess= shininess;
00188         _Touched|=IDRV_TOUCHED_LIGHTING;
00189 }
00190 // ***************************************************************************
00191 inline void     CMaterial::setLightedVertexColor( bool useLightedVertexColor )
00192 {
00193         if (useLightedVertexColor)
00194                 _Flags |= IDRV_MAT_LIGHTED_VERTEX_COLOR;
00195         else
00196                 _Flags &= ~IDRV_MAT_LIGHTED_VERTEX_COLOR;
00197         _Touched|=IDRV_TOUCHED_LIGHTING;
00198 }
00199 
00200 // ***************************************************************************
00201 inline bool             CMaterial::getLightedVertexColor () const
00202 {
00203         return (_Flags & IDRV_MAT_LIGHTED_VERTEX_COLOR) != 0;
00204 }
00205 
00206 
00207 // ***************************************************************************
00208 // ***************************************************************************
00209 // ***************************************************************************
00210 
00211 
00212 
00213 // ***************************************************************************
00214 inline void                                     CMaterial::texEnvOpRGB(uint stage, TTexOperator ope)
00215 {
00216         nlassert(_ShaderType==CMaterial::Normal);
00217         nlassert(stage>=0 && stage<IDRV_MAT_MAXTEXTURES);
00218         _TexEnvs[stage].Env.OpRGB= ope;
00219 }
00220 // ***************************************************************************
00221 inline void                                     CMaterial::texEnvArg0RGB(uint stage, TTexSource src, TTexOperand oper)
00222 {
00223         nlassert(_ShaderType==CMaterial::Normal);
00224         nlassert(stage>=0 && stage<IDRV_MAT_MAXTEXTURES);
00225         _TexEnvs[stage].Env.SrcArg0RGB= src;
00226         _TexEnvs[stage].Env.OpArg0RGB= oper;
00227 }
00228 // ***************************************************************************
00229 inline void                                     CMaterial::texEnvArg1RGB(uint stage, TTexSource src, TTexOperand oper)
00230 {
00231         nlassert(_ShaderType==CMaterial::Normal);
00232         nlassert(stage>=0 && stage<IDRV_MAT_MAXTEXTURES);
00233         nlassert(src!=Texture);
00234         _TexEnvs[stage].Env.SrcArg1RGB= src;
00235         _TexEnvs[stage].Env.OpArg1RGB= oper;
00236 }
00237 
00238 
00239 // ***************************************************************************
00240 inline void                                     CMaterial::texEnvOpAlpha(uint stage, TTexOperator ope)
00241 {
00242         nlassert(_ShaderType==CMaterial::Normal);
00243         nlassert(stage>=0 && stage<IDRV_MAT_MAXTEXTURES);
00244         _TexEnvs[stage].Env.OpAlpha= ope;
00245 }
00246 // ***************************************************************************
00247 inline void                                     CMaterial::texEnvArg0Alpha(uint stage, TTexSource src, TTexOperand oper)
00248 {
00249         nlassert(_ShaderType==CMaterial::Normal);
00250         nlassert(stage>=0 && stage<IDRV_MAT_MAXTEXTURES);
00251         nlassert(oper==SrcAlpha || oper==InvSrcAlpha);
00252         _TexEnvs[stage].Env.SrcArg0Alpha= src;
00253         _TexEnvs[stage].Env.OpArg0Alpha= oper;
00254 }
00255 // ***************************************************************************
00256 inline void                                     CMaterial::texEnvArg1Alpha(uint stage, TTexSource src, TTexOperand oper)
00257 {
00258         nlassert(_ShaderType==CMaterial::Normal);
00259         nlassert(stage>=0 && stage<IDRV_MAT_MAXTEXTURES);
00260         nlassert(oper==SrcAlpha || oper==InvSrcAlpha);
00261         nlassert(src!=Texture);
00262         _TexEnvs[stage].Env.SrcArg1Alpha= src;
00263         _TexEnvs[stage].Env.OpArg1Alpha= oper;
00264 }
00265 
00266 
00267 // ***************************************************************************
00268 inline void                                     CMaterial::texConstantColor(uint stage, CRGBA color)
00269 {
00270         nlassert(_ShaderType==CMaterial::Normal);
00271         nlassert(stage>=0 && stage<IDRV_MAT_MAXTEXTURES);
00272         _TexEnvs[stage].ConstantColor= color;
00273 }
00274 
00275 
00276 // ***************************************************************************
00277 inline uint32                           CMaterial::getTexEnvMode(uint stage)
00278 {
00279         nlassert(_ShaderType==CMaterial::Normal);
00280         nlassert(stage>=0 && stage<IDRV_MAT_MAXTEXTURES);
00281         return _TexEnvs[stage].EnvPacked;
00282 }
00283 // ***************************************************************************
00284 inline void                                     CMaterial::setTexEnvMode(uint stage, uint32 packed)
00285 {
00286         nlassert(_ShaderType==CMaterial::Normal);
00287         nlassert(stage>=0 && stage<IDRV_MAT_MAXTEXTURES);
00288         _TexEnvs[stage].EnvPacked= packed;
00289 }
00290 // ***************************************************************************
00291 inline CRGBA                            CMaterial::getTexConstantColor(uint stage)
00292 {
00293         nlassert(_ShaderType==CMaterial::Normal);
00294         nlassert(stage>=0 && stage<IDRV_MAT_MAXTEXTURES);
00295         return _TexEnvs[stage].ConstantColor;
00296 }
00297 // ***************************************************************************
00298 inline bool                                     CMaterial::getTexCoordGen(uint stage) const
00299 {
00300         nlassert(stage>=0 && stage<IDRV_MAT_MAXTEXTURES);
00301         return (_Flags&(IDRV_MAT_GEN_TEX_0<<stage))!=0;
00302 }
00303 // ***************************************************************************
00304 inline void                                     CMaterial::setTexCoordGen(uint stage, bool generate)
00305 {
00306         nlassert(stage>=0 && stage<IDRV_MAT_MAXTEXTURES);
00307         if (generate)
00308                 _Flags|=(IDRV_MAT_GEN_TEX_0<<stage);
00309         else
00310                 _Flags&=~(IDRV_MAT_GEN_TEX_0<<stage);
00311 }
00312 
00313 
00314 // ***************************************************************************
00315 // ***************************************************************************
00316 // ***************************************************************************
00317 
00318 
00319 
00320 // ***************************************************************************
00321 inline void                                     CMaterial::setUserColor(CRGBA userColor)
00322 {
00323         nlassert(_ShaderType==CMaterial::UserColor);
00324         // setup stage 0 constant color (don't use texConstantColor() because of assert).
00325         _TexEnvs[0].ConstantColor= userColor;
00326 }
00327 
00328 // ***************************************************************************
00329 inline CRGBA                            CMaterial::getUserColor() const
00330 {
00331         nlassert(_ShaderType==CMaterial::UserColor);
00332         // setup stage 0 constant color (don't use getTexConstantColor() because of assert).
00333         return _TexEnvs[0].ConstantColor;
00334 }
00335 
00336 // ***************************************************************************
00337 inline void                 CMaterial::enableUserTexMat(uint stage, bool enabled /*= true*/)
00338 {
00339         nlassert(stage < IDRV_MAT_MAXTEXTURES);
00340         if (enabled)
00341         {
00342                 if (!(_Flags & IDRV_MAT_USER_TEX_MAT_ALL)) // not usr tex mat setupped before?
00343                 {
00344                         nlassert(_TexUserMat.get() == NULL);
00345                         _TexUserMat.reset(new CUserTexMat);
00346                 }
00347                 _Flags |= (IDRV_MAT_USER_TEX_0_MAT << stage);
00348                 _TexUserMat->TexMat[stage].identity();
00349         }
00350         else
00351         {
00352                 if (!(_Flags & IDRV_MAT_USER_TEX_MAT_ALL)) return; // nothing to do
00353                 _Flags &= ~(IDRV_MAT_USER_TEX_0_MAT << stage);     // clear the stage flag
00354                 if (!(_Flags & IDRV_MAT_USER_TEX_MAT_ALL))                 // no more user textures used ?
00355                 {
00356                         _TexUserMat.reset();
00357                 }
00358         }
00359 }
00360 
00361 // ***************************************************************************
00362 inline bool               CMaterial::isUserTexMatEnabled(uint stage) const
00363 {
00364         nlassert(stage < IDRV_MAT_MAXTEXTURES);
00365         return (_Flags & (IDRV_MAT_USER_TEX_0_MAT << stage)) != 0;
00366 }
00367 
00368 // ***************************************************************************
00369 inline void                               CMaterial::setUserTexMat(uint stage, const NLMISC::CMatrix &m)
00370 {
00371         nlassert(isUserTexMatEnabled(stage));
00372         nlassert(_TexUserMat.get() != NULL);
00373         _TexUserMat->TexMat[stage] = m;
00374 }
00375 
00376 // ***************************************************************************
00377 inline const NLMISC::CMatrix  &CMaterial::getUserTexMat(uint stage) const
00378 {
00379         nlassert(isUserTexMatEnabled(stage));
00380         nlassert(_TexUserMat.get() != NULL);
00381         return _TexUserMat->TexMat[stage];
00382 }
00383 
00384 
00385 }
00386 
00387 #endif
00388