00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_VEGETABLE_MANAGER_H
00027 #define NL_VEGETABLE_MANAGER_H
00028
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/misc/matrix.h"
00031 #include "nel/misc/rgba.h"
00032 #include "nel/misc/block_memory.h"
00033 #include "nel/misc/vector_2f.h"
00034 #include "nel/misc/smart_ptr.h"
00035 #include "3d/vegetable_clip_block.h"
00036 #include "3d/vegetable_sort_block.h"
00037 #include "3d/vegetable_instance_group.h"
00038 #include "3d/vegetable_shape.h"
00039 #include "3d/vegetablevb_allocator.h"
00040 #include "3d/material.h"
00041 #include "3d/driver.h"
00042 #include "3d/vegetable_uv8.h"
00043
00044
00045 namespace NL3D
00046 {
00047
00048
00049 class CVegetableBlendLayerModel;
00050 class CScene;
00051 class CVegetableLightEx;
00052
00053
00054
00055
00056 #define NL3D_VEGETABLE_DEFAULT_NUM_BLEND_LAYER 20
00057
00058 #define NL3D_VEGETABLE_DEFAULT_DIST_MAX 60.f
00059
00060
00061
00075 class CVegetableManager
00076 {
00077 public:
00079 enum TVegetableWater { AboveWater = 0, UnderWater, IntersectWater, VegetInfoLast };
00080
00081 public:
00082
00089 CVegetableManager(uint maxVertexVbHardUnlit, uint maxVertexVbHardLighted,
00090 uint nbBlendLayers= NL3D_VEGETABLE_DEFAULT_NUM_BLEND_LAYER,
00091 float blendLayerDistMax= NL3D_VEGETABLE_DEFAULT_DIST_MAX);
00092 ~CVegetableManager();
00093
00097 void createVegetableBlendLayersModels(CScene *scene);
00098
00099
00101
00102
00104 CVegetableShape *getVegetableShape(const std::string &shape);
00105
00106
00107
00108
00110
00111
00113 CVegetableClipBlock *createClipBlock();
00115 void deleteClipBlock(CVegetableClipBlock *clipBlock);
00116
00124 CVegetableSortBlock *createSortBlock(CVegetableClipBlock *clipBlock, const CVector ¢er, float radius);
00126 void deleteSortBlock(CVegetableSortBlock *sortBlock);
00127
00131 CVegetableInstanceGroup *createIg(CVegetableSortBlock *sortBlock);
00136 void deleteIg(CVegetableInstanceGroup *ig);
00137
00138
00139
00140
00142
00159
00160
00166 void reserveIgAddInstances(CVegetableInstanceGroupReserve &vegetIgReserve, CVegetableShape *shape, TVegetableWater vegetWaterState, uint numInstances);
00171 void reserveIgCompile(CVegetableInstanceGroup *ig, const CVegetableInstanceGroupReserve &vegetIgReserve);
00172
00173
00187 void addInstance(CVegetableInstanceGroup *ig,
00188 CVegetableShape *shape, const NLMISC::CMatrix &mat,
00189 const NLMISC::CRGBAF &ambientColor, const NLMISC::CRGBAF &diffuseColor,
00190 float bendFactor, float bendPhase, float bendFreqFactor, float blendDistMax,
00191 TVegetableWater vegetWaterState, CVegetableUV8 dlmUV);
00192
00193
00194
00195
00197
00198
00200 void updateDriver(IDriver *driver);
00201
00203 void loadTexture(const std::string &texName);
00205 void loadTexture(ITexture *itex);
00207 void setDirectionalLight(const CRGBA &ambient, const CRGBA &diffuse, const CVector &light);
00208
00213 void lockBuffers();
00215 void unlockBuffers();
00216
00221 void render(const CVector &viewCenter, const CVector &frontVector, const std::vector<CPlane> &pyramid,
00222 ITexture *textureDLM, IDriver *driver);
00223
00224
00225
00226
00228
00229
00239 void setWind(const CVector &windDir, float windFreq, float windPower, float windBendMin);
00240
00243 void setTime(double time);
00244
00245
00246
00247
00249
00250
00254 void setUpdateLightingTime(double time);
00255
00259 void updateLighting();
00260
00265 void setUpdateLightingFrequency(float freq);
00266
00270 void updateLightingAll();
00271
00272
00273
00274
00276
00277
00279 void resetNumVegetableFaceRendered();
00281 uint getNumVegetableFaceRendered() const;
00282
00283
00284
00285
00286 private:
00287 friend class CVegetableBlendLayerModel;
00288
00289 NLMISC::CBlockMemory<CVegetableClipBlock> _ClipBlockMemory;
00290 NLMISC::CBlockMemory<CVegetableSortBlock> _SortBlockMemory;
00291 NLMISC::CBlockMemory<CVegetableInstanceGroup> _InstanceGroupMemory;
00292
00293
00294 CTessList<CVegetableClipBlock> _ClipBlockList;
00295
00296 CTessList<CVegetableClipBlock> _EmptyClipBlockList;
00297
00298
00299
00300 typedef std::map<std::string, CVegetableShape> TShapeMap;
00301 typedef TShapeMap::iterator ItShapeMap;
00302 TShapeMap _ShapeMap;
00303
00304
00305
00306 CVegetableVBAllocator _VBHardAllocator[CVegetableVBAllocator::VBTypeCount];
00307
00308 CVegetableVBAllocator _VBSoftAllocator[CVegetableVBAllocator::VBTypeCount];
00309
00310 CVertexProgram *_VertexProgram[NL3D_VEGETABLE_NRDRPASS];
00311
00312
00313
00314 CMaterial _VegetableMaterial;
00315
00316 CVector _DirectionalLight;
00317 NLMISC::CRGBA _GlobalAmbient;
00318 NLMISC::CRGBA _GlobalDiffuse;
00319
00320
00322 uint _NumVegetableFaceRendered;
00323
00324
00325
00326 static bool doubleSidedRdrPass(uint rdrPass);
00327
00328
00330 uint getRdrPassInfoForShape(CVegetableShape *shape, TVegetableWater vegetWaterState,
00331 bool &instanceLighted, bool &instanceDoubleSided, bool &instanceZSort,
00332 bool &destLighted, bool &precomputeLighting);
00333
00334
00336 CVegetableVBAllocator &getVBAllocatorForRdrPassAndVBHardMode(uint rdrPass, uint vbHardMode);
00337
00338
00340 void initVertexProgram(uint vpType);
00341
00342
00344 void setupVertexProgramConstants(IDriver *driver);
00345
00346
00350 void swapIgRdrPassHardMode(CVegetableInstanceGroup *, uint rdrPass);
00351
00352
00354
00355 CVector _WindDirection;
00356 float _WindFrequency;
00357 float _WindPower;
00358 float _WindBendMin;
00359
00360 double _Time;
00361 double _WindPrecRenderTime;
00362
00363 double _WindAnimTime;
00364
00365
00366 float _CosTable[NL3D_VEGETABLE_VP_LUT_SIZE];
00367
00368 NLMISC::CVector2f _WindTable[NL3D_VEGETABLE_VP_LUT_SIZE];
00369 NLMISC::CVector2f _WindDeltaTable[NL3D_VEGETABLE_VP_LUT_SIZE];
00370
00371
00372
00373
00374
00376
00377
00378 CVector _AngleAxis;
00379 CVector _ViewCenter;
00380 bool _BkupFog;
00381
00382 NLMISC::CMatrix _ManagerMatrix;
00383
00384
00385
00386
00388
00389
00390
00392 uint _NumZSortBlendLayers;
00393 float _ZSortLayerDistMax;
00394 CScene *_ZSortScene;
00395 std::vector<CVegetableBlendLayerModel*> _ZSortModelLayers;
00396
00397 std::vector<CVegetableBlendLayerModel*> _ZSortModelLayersUW;
00398
00399
00401 void setupRenderStateForBlendLayerModel(IDriver *driver);
00402 void exitRenderStateForBlendLayerModel(IDriver *driver);
00403
00404
00405
00406
00408
00411
00412
00413
00414 double _ULPrecTime;
00415 bool _ULPrecTimeInit;
00416 double _ULTime;
00417
00419 float _ULFrequency;
00421 float _ULNVerticesToUpdate;
00423 uint _ULNTotalVertices;
00425 CVegetableInstanceGroup *_ULRootIg;
00427 uint _ULCurrentIgRdrPass;
00428 uint _ULCurrentIgInstance;
00429
00431 void doUpdateLighting();
00432
00436 bool updateLightingIGPart();
00437
00438
00442 uint updateInstanceLighting(CVegetableInstanceGroup *ig, uint rdrPassId, uint instanceId);
00443
00444
00445
00446
00447
00448 NLMISC::CRefPtr<IDriver> _LastDriver;
00449
00450
00451 };
00452
00453
00454 }
00455
00456
00457 #endif // NL_VEGETABLE_MANAGER_H
00458
00459