00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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
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
00146 bool LightingSystemEnabled;
00147
00148
00149 NLMISC::CRGBA AmbientGlobal;
00150
00151 NLMISC::CRGBA SunAmbient, SunDiffuse, SunSpecular;
00152
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
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
00290 std::vector<IBaseRenderObs*> RenderList;
00291
00292 COrderingTable<IBaseRenderObs> OrderOpaqueList;
00293 CLayeredOrderingTable<IBaseRenderObs> OrderTransparentList;
00294
00295 IDriver *Driver;
00296 CViewport _Viewport;
00297
00298
00299 bool _CurrentPassOpaque;
00300 bool _LayersRenderingOrder;
00301
00302
00304
00305
00306 CLightContribution *_CacheLightContribution;
00307 bool _LastLocalAttenuation;
00308
00309 uint _NumLightEnabled;
00310
00311
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
00321 CLight _DriverLight[NL3D_MAX_LIGHT_CONTRIBUTION+1];
00322
00323
00324 mutable uint _StrongestLightIndex;
00325 mutable bool _StrongestLightTouched;
00326
00327
00328 uint _VPCurrentCtStart;
00329
00330 uint _VPNumLights;
00331
00332 bool _VPSupportSpecular;
00333
00334 NLMISC::CRGBAF _VPFinalAmbient;
00335
00336 NLMISC::CRGBAF _VPLightDiffuse[MaxVPLight];
00337 NLMISC::CRGBAF _VPLightSpecular[MaxVPLight];
00338
00339 NLMISC::CRGBA _StrongestLightDiffuse;
00340 NLMISC::CRGBA _StrongestLightSpecular;
00341
00342
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