# 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  

render_trav.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_RENDER_TRAV_H
00027 #define NL_RENDER_TRAV_H
00028 
00029 #include "3d/trav_scene.h"
00030 #include "3d/ordering_table.h"
00031 #include "3d/layered_ordering_table.h"
00032 #include "nel/misc/rgba.h"
00033 #include "nel/3d/viewport.h"
00034 #include "3d/light_contribution.h"
00035 #include "3d/light.h"
00036 #include "3d/mesh_block_manager.h"
00037 #include <vector>
00038 
00039 
00040 namespace       NL3D
00041 {
00042 
00043 using NLMISC::CVector;
00044 using NLMISC::CPlane;
00045 using NLMISC::CMatrix;
00046 
00047 class   IBaseRenderObs;
00048 class   IDriver;
00049 class   CMaterial;
00050 
00051 class   CTransform;
00052 
00053 class   CMeshSkinManager;
00054 
00055 
00056 // ***************************************************************************
00057 // Skin Manager setup
00058 #define NL3D_MESH_SKIN_MANAGER_VERTEXFORMAT             (CVertexBuffer::PositionFlag | CVertexBuffer::NormalFlag | CVertexBuffer::TexCoord0Flag)
00059 #define NL3D_MESH_SKIN_MANAGER_MAXVERTICES              10000
00060 
00061 
00062 // ***************************************************************************
00063 // ClassIds.
00064 const NLMISC::CClassId          RenderTravId= NLMISC::CClassId(0x572456ee, 0x3db55f23);
00065 
00066 
00067 // ***************************************************************************
00088 class CRenderTrav : public ITravCameraScene
00089 {
00090 public:
00091 
00093         CRenderTrav();
00094 
00096 
00097         IObs                            *createDefaultObs() const;
00098         NLMISC::CClassId        getClassId() const {return RenderTravId;}
00099         sint                            getRenderOrder() const {return 4000;}
00104         void                            traverse();
00106 
00108 
00109 
00110         void                    clearRenderList();
00114         void                    addRenderObs(IBaseRenderObs *o);
00116 
00117 
00118         void                    setDriver(IDriver *drv) {Driver= drv;}
00119         IDriver                 *getDriver() {return Driver;}
00120         void                    setViewport (const CViewport& viewport) 
00121         {
00122                 _Viewport = viewport;
00123         }
00124         CViewport               getViewport () const
00125         {
00126                 return _Viewport;
00127         }
00128 
00129         bool isCurrentPassOpaque() { return _CurrentPassOpaque; }
00130 
00137         void  setLayersRenderingOrder(bool directOrder = true) { _LayersRenderingOrder = directOrder; }
00138         bool  getLayersRenderingOrder() const { return _LayersRenderingOrder; }
00139 
00140 
00141 
00143         // @{
00144 
00145         // False by default. setuped by CScene
00146         bool                                            LightingSystemEnabled;
00147 
00148         // Global ambient. Default is (50,50,50).
00149         NLMISC::CRGBA                           AmbientGlobal;
00150         // The Sun Setup.
00151         NLMISC::CRGBA                           SunAmbient, SunDiffuse, SunSpecular;
00152         // set the direction of the sun. dir is normalized.
00153         void                                            setSunDirection(const CVector &dir);
00154         const CVector                           getSunDirection() const {return _SunDirection;}
00155 
00156         // @}
00157 
00158 
00163         void                                            setMeshSkinManager(CMeshSkinManager *msm);
00164 
00166         CMeshSkinManager                        *getMeshSkinManager() const {return _MeshSkinManager;}
00167 
00168 
00169 // ******************
00170 public:
00171 
00173         // @{
00174 
00175         // Max VP Light setup Infos.
00176         enum    {MaxVPLight= 4};
00177 
00182         void            resetLightSetup();
00183 
00194         void            changeLightSetup(CLightContribution     *lightContribution, bool useLocalAttenuation);
00195 
00196 
00205         void            beginVPLightSetup(uint ctStart, bool supportSpecular, const CMatrix &invObjectWM);
00206 
00210         void            changeVPLightSetupMaterial(const CMaterial &mat, bool excludeStrongest);
00211 
00212 
00251         static  std::string             getLightVPFragment(uint numActivePointLights, uint ctStart, bool supportSpecular, bool normalize);
00252 
00256         const CLight  &getDriverLight(sint index) const 
00257         { 
00258                 nlassert(index >= 0 && index < NL3D_MAX_LIGHT_CONTRIBUTION+1);
00259                 return _DriverLight[index]; 
00260         }
00261 
00263         sint            getStrongestLightIndex() const;
00264 
00269         void            getStrongestLightColors(NLMISC::CRGBA &diffuse, NLMISC::CRGBA &specular);
00270 
00274         uint            getNumVPLights() const {return _VPNumLights;}
00275 
00276         // @}
00277 
00278 
00280         // @{
00281 
00283         CMeshBlockManager               MeshBlockManager;
00284 
00285         // @}
00286 
00287 private:
00288         
00289         // A grow only list of observers to be rendered.
00290         std::vector<IBaseRenderObs*>    RenderList;
00291         // Ordering Table to sort transparent objects
00292         COrderingTable<IBaseRenderObs>                  OrderOpaqueList;
00293         CLayeredOrderingTable<IBaseRenderObs>   OrderTransparentList;
00294 
00295         IDriver                 *Driver;
00296         CViewport               _Viewport;
00297 
00298         // Temporary for the render
00299         bool                    _CurrentPassOpaque;     
00300         bool                    _LayersRenderingOrder;
00301 
00302 
00304         // @{
00305         // The last setup.
00306         CLightContribution                      *_CacheLightContribution;
00307         bool                                            _LastLocalAttenuation;
00308         // The number of light enabled
00309         uint                                            _NumLightEnabled;
00310 
00311         // More precise setup
00312         uint                                            _LastSunFactor;
00313         NLMISC::CRGBA                           _LastSunAmbient;
00314         CPointLight                                     *_LastPointLight[NL3D_MAX_LIGHT_CONTRIBUTION];
00315         uint8                                           _LastPointLightFactor[NL3D_MAX_LIGHT_CONTRIBUTION];
00316         bool                                            _LastPointLightLocalAttenuation[NL3D_MAX_LIGHT_CONTRIBUTION];
00317 
00318         CVector                                         _SunDirection;
00319 
00320         // driver Lights setuped in changeLightSetup()
00321         CLight                                          _DriverLight[NL3D_MAX_LIGHT_CONTRIBUTION+1];
00322 
00323         // index of the strongest light (when used)
00324         mutable uint                            _StrongestLightIndex;
00325         mutable bool                            _StrongestLightTouched;
00326 
00327         // Current ctStart setuped with beginVPLightSetup()
00328         uint                                            _VPCurrentCtStart;
00329         // Current num of VP lights enabled.
00330         uint                                            _VPNumLights;
00331         // Current support of specular
00332         bool                                            _VPSupportSpecular;
00333         // Sum of all ambiant of all lights + ambiantGlobal.
00334         NLMISC::CRGBAF                          _VPFinalAmbient;
00335         // Diffuse/Spec comp of all light / 255.
00336         NLMISC::CRGBAF                          _VPLightDiffuse[MaxVPLight];
00337         NLMISC::CRGBAF                          _VPLightSpecular[MaxVPLight];
00338 
00339         NLMISC::CRGBA                           _StrongestLightDiffuse;
00340         NLMISC::CRGBA                           _StrongestLightSpecular;        
00341 
00342         // Cache for changeVPLightSetupMaterial()
00343         bool                                            _VPMaterialCacheDirty;
00344         uint32                                          _VPMaterialCacheEmissive;
00345         uint32                                          _VPMaterialCacheAmbient;
00346         uint32                                          _VPMaterialCacheDiffuse;
00347         uint32                                          _VPMaterialCacheSpecular;
00348         float                                           _VPMaterialCacheShininess;
00349 
00350         // @}
00351 
00352 
00354         CMeshSkinManager                        *_MeshSkinManager;
00355 
00356 };
00357 
00358 
00359 }
00360 
00361 
00362 #endif // NL_RENDER_TRAV_H
00363 
00364 /* End of render_trav.h */