render_trav.h

Go to the documentation of this file.
00001 
00005 /* Copyright, 2000 Nevrax Ltd.
00006  *
00007  * This file is part of NEVRAX NEL.
00008  * NEVRAX NEL is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2, or (at your option)
00011  * any later version.
00012 
00013  * NEVRAX NEL is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * General Public License for more details.
00017 
00018  * You should have received a copy of the GNU General Public License
00019  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00020  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00021  * MA 02111-1307, USA.
00022  */
00023 
00024 #ifndef NL_RENDER_TRAV_H
00025 #define NL_RENDER_TRAV_H
00026 
00027 #include "nel/3d/trav_scene.h"
00028 #include "nel/3d/ordering_table.h"
00029 #include "nel/3d/layered_ordering_table.h"
00030 #include "nel/misc/rgba.h"
00031 #include "nel/3d/viewport.h"
00032 #include "nel/3d/light_contribution.h"
00033 #include "nel/3d/light.h"
00034 #include "nel/3d/mesh_block_manager.h"
00035 #include "nel/3d/shadow_map_manager.h"
00036 #include "nel/3d/u_scene.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   IDriver;
00048 class   CMaterial;
00049 
00050 class   CTransform;
00051 class   CLandscapeModel;
00052 
00053 class   CVertexStreamManager;
00054 class   CWaterModel;
00055 
00056 // ***************************************************************************
00057 /* Skin Manager setup
00058  * For the moment, the skin manager vertex buffer routes all its UV channel to UV0.
00059  * See void CVertexStreamManager::init(IDriver *driver, uint vertexFormat, uint maxVertices)
00060  *  use 8 VBswap for minimal(=> no) lock() time. 2 is not enough (saw 7 ms lost because of this)
00061  *  => size of the manager is 1280 Ko
00062  *  NB: 5000 vertices max for a model is a strong limitation, but it's OK for now...
00063  */
00064 #define NL3D_MESH_SKIN_MANAGER_VERTEXFORMAT     (CVertexBuffer::PositionFlag | CVertexBuffer::NormalFlag | CVertexBuffer::TexCoord0Flag)
00065 #define NL3D_MESH_SKIN_MANAGER_MAXVERTICES      5000
00066 #define NL3D_MESH_SKIN_MANAGER_NUMVB            8
00067 
00068 /* Same for Shadow Generation.
00069  * NB: need much less Vertices because: 1/ foolish to do more. 2/ Only position=> no UV/Normal discontinuities.
00070  *  => size of the manager is 1.3 Mo
00071  *  use 8 VBswap for minimal(=> no) lock() time. 2 is not enough (saw 7 ms lost because of this)
00072  *  => size of the manager is 280 Ko
00073  */
00074 #define NL3D_SHADOW_MESH_SKIN_MANAGER_VERTEXFORMAT      (CVertexBuffer::PositionFlag)
00075 #define NL3D_SHADOW_MESH_SKIN_MANAGER_MAXVERTICES       3000
00076 #define NL3D_SHADOW_MESH_SKIN_MANAGER_NUMVB             8
00077 
00078 
00079 
00080 // ***************************************************************************
00099 class CRenderTrav : public CTravCameraScene
00100 {
00101 public:
00102 
00104     CRenderTrav();
00105 
00107 
00108 
00113     void                traverse(UScene::TRenderPart renderPart, bool newRender);
00115 
00117 
00118 
00119     void            clearRenderList();
00122     void            addRenderModel(CTransform *m)
00123     {
00124         // for possible removeRenderModel()
00125         m->_IndexLSBInRenderList= uint8(_CurrentNumVisibleModels&255);
00126         // add the model in the list
00127         RenderList[_CurrentNumVisibleModels]= m;
00128         _CurrentNumVisibleModels++;
00129     }
00130     // for createModel().
00131     void            reserveRenderList(uint numModels);
00132 
00133     /* This is for the rare case where objects are deleted during CScene::render(). called by deleteModel()
00134      *  This method don't need to be called by ~CTransform
00135      */
00136     void            removeRenderModel(CTransform *m);
00137 
00139     void            clearWaterModelList();
00140 
00142 
00143 
00144     // setup the Driver for render
00145     void            setDriver(IDriver *drv) {Driver= drv;}
00146     IDriver         *getDriver() {return Driver;}
00147     // Yoyo: temporary. May be used later if we decide to support a PBuffer to render texture for ShadowMap
00148     IDriver         *getAuxDriver() {return Driver;}
00149     void            setViewport (const CViewport& viewport)
00150     {
00151         _Viewport = viewport;
00152     }
00153     CViewport       getViewport () const
00154     {
00155         return _Viewport;
00156     }
00157 
00158     bool isCurrentPassOpaque() { return _CurrentPassOpaque; }
00159 
00166     void  setLayersRenderingOrder(bool directOrder = true) { _LayersRenderingOrder = directOrder; }
00167     bool  getLayersRenderingOrder() const { return _LayersRenderingOrder; }
00168 
00177     void setupTransparencySorting(uint8 maxPriority = 0, uint NbDistanceEntries = 1024);
00178 
00179 
00180 
00182     // @{
00183 
00184     // False by default. setuped by CScene
00185     bool                        LightingSystemEnabled;
00186 
00187     // Global ambient. Default is (50,50,50).
00188     NLMISC::CRGBA               AmbientGlobal;
00189     // The Sun Setup.
00190     NLMISC::CRGBA               SunAmbient, SunDiffuse, SunSpecular;
00191     // set the direction of the sun. dir is normalized.
00192     void                        setSunDirection(const CVector &dir);
00193     const CVector               getSunDirection() const {return _SunDirection;}
00194 
00195     // @}
00196 
00197 
00202     void                        setMeshSkinManager(CVertexStreamManager *msm);
00203 
00205     CVertexStreamManager        *getMeshSkinManager() const {return _MeshSkinManager;}
00206 
00208     CShadowMapManager           &getShadowMapManager() {return _ShadowMapManager;}
00209     const CShadowMapManager     &getShadowMapManager() const {return _ShadowMapManager;}
00210 
00212     void                        setShadowMeshSkinManager(CVertexStreamManager *msm);
00213     CVertexStreamManager        *getShadowMeshSkinManager() const {return _ShadowMeshSkinManager;}
00214 
00215 
00216     // add a landscape. Special for CLandscapeModel::traverseRender();
00217     void            addRenderLandscape(CLandscapeModel *model);
00218 
00219 
00221 
00222     // Test Memory of water model render list (because someone crash it...)
00223     // Yoyo: this crash seems to be fixed, but i leave the code, in case of.....
00224     void            debugWaterModelMemory(const char *tag, bool dumpList= false);
00226 
00227 // ******************
00228 public:
00229 
00231     // @{
00232 
00233     // Max VP Light setup Infos.
00234     enum    {MaxVPLight= 4};
00235 
00240     void        resetLightSetup();
00241 
00252     void        changeLightSetup(CLightContribution *lightContribution, bool useLocalAttenuation);
00253 
00254 
00263     void        beginVPLightSetup(uint ctStart, bool supportSpecular, const CMatrix &invObjectWM);
00264 
00268     void        changeVPLightSetupMaterial(const CMaterial &mat, bool excludeStrongest);
00269 
00270 
00309     static  std::string     getLightVPFragment(uint numActivePointLights, uint ctStart, bool supportSpecular, bool normalize);
00310 
00314     const CLight  &getDriverLight(sint index) const
00315     {
00316         nlassert(index >= 0 && index < NL3D_MAX_LIGHT_CONTRIBUTION+1);
00317         return _DriverLight[index];
00318     }
00319 
00321     sint        getStrongestLightIndex() const;
00322 
00327     void        getStrongestLightColors(NLMISC::CRGBA &diffuse, NLMISC::CRGBA &specular);
00328 
00332     uint        getNumVPLights() const {return _VPNumLights;}
00333 
00334     // @}
00335 
00336 
00338     // @{
00339 
00341     CMeshBlockManager       MeshBlockManager;
00342 
00343     // @}
00344 
00345     // ReSetup the Driver Frustum/Camera. Called internally and by ShadowMapManager only.
00346     void            setupDriverCamera();
00347 
00348 private:
00349 
00350     // A grow only list of models to be rendered.
00351     std::vector<CTransform*>    RenderList;
00352     uint32                      _CurrentNumVisibleModels;
00353 
00354     // Ordering Table to sort transparent objects
00355     COrderingTable<CTransform>          OrderOpaqueList;
00356     std::vector<CLayeredOrderingTable<CTransform> > _OrderTransparentListByPriority;
00357     uint8                                           _MaxTransparencyPriority;
00358 
00359     IDriver         *Driver;
00360     CViewport       _Viewport;
00361 
00362     // Temporary for the render
00363     bool            _CurrentPassOpaque;
00364     bool            _LayersRenderingOrder;
00365 
00366 
00368     // @{
00369     // The last setup.
00370     CLightContribution          *_CacheLightContribution;
00371     bool                        _LastLocalAttenuation;
00372     // The number of light enabled
00373     uint                        _NumLightEnabled;
00374 
00375     // More precise setup
00376     uint                        _LastSunFactor;
00377     NLMISC::CRGBA               _LastFinalAmbient;
00378     CPointLight                 *_LastPointLight[NL3D_MAX_LIGHT_CONTRIBUTION];
00379     uint8                       _LastPointLightFactor[NL3D_MAX_LIGHT_CONTRIBUTION];
00380     bool                        _LastPointLightLocalAttenuation[NL3D_MAX_LIGHT_CONTRIBUTION];
00381 
00382     CVector                     _SunDirection;
00383 
00384     // driver Lights setuped in changeLightSetup()
00385     CLight                      _DriverLight[NL3D_MAX_LIGHT_CONTRIBUTION+1];
00386 
00387     // index of the strongest light (when used)
00388     mutable uint                _StrongestLightIndex;
00389     mutable bool                _StrongestLightTouched;
00390 
00391     // Current ctStart setuped with beginVPLightSetup()
00392     uint                        _VPCurrentCtStart;
00393     // Current num of VP lights enabled.
00394     uint                        _VPNumLights;
00395     // Current support of specular
00396     bool                        _VPSupportSpecular;
00397     // Sum of all ambiant of all lights + ambiantGlobal.
00398     NLMISC::CRGBAF              _VPFinalAmbient;
00399     // Diffuse/Spec comp of all light / 255.
00400     NLMISC::CRGBAF              _VPLightDiffuse[MaxVPLight];
00401     NLMISC::CRGBAF              _VPLightSpecular[MaxVPLight];
00402 
00403     NLMISC::CRGBA               _StrongestLightDiffuse;
00404     NLMISC::CRGBA               _StrongestLightSpecular;
00405 
00406     // Cache for changeVPLightSetupMaterial()
00407     bool                        _VPMaterialCacheDirty;
00408     uint32                      _VPMaterialCacheEmissive;
00409     uint32                      _VPMaterialCacheAmbient;
00410     uint32                      _VPMaterialCacheDiffuse;
00411     uint32                      _VPMaterialCacheSpecular;
00412     float                       _VPMaterialCacheShininess;
00413 
00414     // @}
00415 
00416 
00418     CVertexStreamManager        *_MeshSkinManager;
00419 
00420 
00422     CShadowMapManager           _ShadowMapManager;
00424     CVertexStreamManager        *_ShadowMeshSkinManager;
00425 
00426 
00432     // clear the list
00433     void            clearRenderLandscapeList();
00434     // render the landscapes
00435     void            renderLandscapes();
00436 
00437     // A grow only list of landscapes to be rendered.
00438     std::vector<CLandscapeModel*>   _LandscapeRenderList;
00439 
00440     // @}
00441 
00443 
00444     struct CWaterModelDump
00445     {
00446         void        *Address;
00447         void        *ClippedPolyBegin;
00448         void        *ClippedPolyEnd;
00449     };
00450     std::vector<CWaterModelDump>    _DebugWaterModelList;
00452 
00453 public:
00454     CWaterModel *_FirstWaterModel;
00455 };
00456 
00457 
00458 }
00459 
00460 
00461 #endif // NL_RENDER_TRAV_H
00462 
00463 /* End of render_trav.h */

Generated on Thu Jan 7 08:26:20 2010 for NeL by  doxygen 1.6.1