NL3D::CVegetableManager Class Reference

#include <vegetable_manager.h>


Detailed Description

Manager of vegetable. Instance Factory and rendering. A VegetableManager should be put into a CScene model which is Opaque (ie rendered in Opaque pass), and call vegetableManager::render() at this time. a good example is CLandscape.

Because during render(), it uses and setup special "Vegetable Blend Layer models" to render transparents alpha blended vegetables. Toses models are transparent so they are drawn during the transparent pass of the renderTrav's CScene (so after the Opaque pass).

Author:
Lionel Berenguier

Nevrax France

Date:
2001

Definition at line 75 of file vegetable_manager.h.

UpdateLighting management

void doUpdateLighting ()
 update lighting according to _ULNVerticesToUpdate

uint updateInstanceLighting (CVegetableInstanceGroup *ig, uint rdrPassId, uint instanceId)
bool updateLightingIGPart ()
uint _ULCurrentIgInstance
 update lighting according to _ULNVerticesToUpdate

uint _ULCurrentIgRdrPass
 Current instance to render in the first ig to update: rdrpass/instanceId.

float _ULFrequency
 Frequency of update.

uint _ULNTotalVertices
 Sum of all ig vertices to update.

float _ULNVerticesToUpdate
 Current number of vertices to update. If negative, I have some advance.

double _ULPrecTime
bool _ULPrecTimeInit
 update lighting according to _ULNVerticesToUpdate

CVegetableInstanceGroup_ULRootIg
 the priority list of ig to update

double _ULTime
 update lighting according to _ULNVerticesToUpdate


CVegetableBlendLayerModel mgt.

void exitRenderStateForBlendLayerModel (IDriver *driver)
void setupRenderStateForBlendLayerModel (IDriver *driver)
 called by CVegetableBlendLayerModel.

uint _NumZSortBlendLayers
 For Alpha Blend rdrPass, ordering into layers.

float _ZSortLayerDistMax
std::vector< CVegetableBlendLayerModel * > _ZSortModelLayers
std::vector< CVegetableBlendLayerModel * > _ZSortModelLayersUW
CScene_ZSortScene

Public Types

enum  TVegetableWater { AboveWater = 0, UnderWater, IntersectWater, VegetInfoLast }
 Micro vegetation position against Water. Above water is the default. More...


Public Member Functions

void createVegetableBlendLayersModels (CScene *scene)
 CVegetableManager (uint maxVertexVbHardUnlit, uint maxVertexVbHardLighted, uint nbBlendLayers=20, float blendLayerDistMax=60.f)
 ~CVegetableManager ()
Adding Instances to an Ig.
void addInstance (CVegetableInstanceGroup *ig, CVegetableShape *shape, const NLMISC::CMatrix &mat, const NLMISC::CRGBAF &ambientColor, const NLMISC::CRGBAF &diffuseColor, float bendFactor, float bendPhase, float bendFreqFactor, float blendDistMax, TVegetableWater vegetWaterState, CVegetableUV8 dlmUV)
void reserveIgAddInstances (CVegetableInstanceGroupReserve &vegetIgReserve, CVegetableShape *shape, TVegetableWater vegetWaterState, uint numInstances)
void reserveIgCompile (CVegetableInstanceGroup *ig, const CVegetableInstanceGroupReserve &vegetIgReserve)
instance management
CVegetableClipBlockcreateClipBlock ()
 Create a clipBlock where SortBlock will be created.

CVegetableInstanceGroupcreateIg (CVegetableSortBlock *sortBlock)
CVegetableSortBlockcreateSortBlock (CVegetableClipBlock *clipBlock, const CVector &center, float radius)
void deleteClipBlock (CVegetableClipBlock *clipBlock)
 delete such a clipBlock. all sortBlocks and so all ig must be deleted before.

void deleteIg (CVegetableInstanceGroup *ig)
void deleteSortBlock (CVegetableSortBlock *sortBlock)
 delete such a SortBlock. all ig must be deleted before.

Profile
uint getNumVegetableFaceRendered () const
 get the number of faces rendered by the vegetable manager

void resetNumVegetableFaceRendered ()
 set to 0 the number of faces rendered

Shape management
CVegetableShapegetVegetableShape (const std::string &shape)
 Load a shape if necessary, and return a shapeId for this shape.

render
void loadTexture (ITexture *itex)
 setup a global texture used for all vegetables (smartPtr-ized).

void loadTexture (const std::string &texName)
 load a global texture used for all vegetables (lookup into CPath).

void lockBuffers ()
void render (const CVector &viewCenter, const CVector &frontVector, const std::vector< CPlane > &pyramid, ITexture *textureDLM, IDriver *driver)
void setDirectionalLight (const CRGBA &ambient, const CRGBA &diffuse, const CVector &light)
 setup the directional light

void unlockBuffers ()
 unlock any AGP vertex buffers

void updateDriver (IDriver *driver)
 must give a driver to the vegetableManager, before any addInstance().

Wind animation
void setTime (double time)
void setWind (const CVector &windDir, float windFreq, float windPower, float windBendMin)
UpdateLighting management
void setUpdateLightingFrequency (float freq)
void setUpdateLightingTime (double time)
void updateLighting ()
void updateLightingAll ()

Private Types

typedef TShapeMap::iterator ItShapeMap
typedef std::map< std::string,
CVegetableShape
TShapeMap

Private Member Functions

uint getRdrPassInfoForShape (CVegetableShape *shape, TVegetableWater vegetWaterState, bool &instanceLighted, bool &instanceDoubleSided, bool &instanceZSort, bool &destLighted, bool &precomputeLighting)
 get the rdrPass and other info for a given shape.

CVegetableVBAllocatorgetVBAllocatorForRdrPassAndVBHardMode (uint rdrPass, uint vbHardMode)
 Get the good allocator for the appropriate rdr pass.

void initVertexProgram (uint vpType)
 init the ith vertexProgram.

void setupVertexProgramConstants (IDriver *driver)
 setup the vertexProgram constants.

void swapIgRdrPassHardMode (CVegetableInstanceGroup *, uint rdrPass)

Static Private Member Functions

bool doubleSidedRdrPass (uint rdrPass)

Private Attributes

CTessList< CVegetableClipBlock_ClipBlockList
NLMISC::CBlockMemory< CVegetableClipBlock_ClipBlockMemory
CVector _DirectionalLight
CTessList< CVegetableClipBlock_EmptyClipBlockList
NLMISC::CRGBA _GlobalAmbient
NLMISC::CRGBA _GlobalDiffuse
NLMISC::CBlockMemory< CVegetableInstanceGroup_InstanceGroupMemory
NLMISC::CRefPtr< IDriver_LastDriver
uint _NumVegetableFaceRendered
 profile

TShapeMap _ShapeMap
NLMISC::CBlockMemory< CVegetableSortBlock_SortBlockMemory
CVegetableVBAllocator _VBHardAllocator [CVegetableVBAllocator::VBTypeCount]
CVegetableVBAllocator _VBSoftAllocator [CVegetableVBAllocator::VBTypeCount]
CMaterial _VegetableMaterial
CVertexProgram_VertexProgram [NL3D_VEGETABLE_NRDRPASS]
Misc data to setup renderState (computed at each render())
CVector _AngleAxis
bool _BkupFog
NLMISC::CMatrix _ManagerMatrix
CVector _ViewCenter
Wind animation
float _CosTable [NL3D_VEGETABLE_VP_LUT_SIZE]
double _Time
double _WindAnimTime
float _WindBendMin
NLMISC::CVector2f _WindDeltaTable [NL3D_VEGETABLE_VP_LUT_SIZE]
CVector _WindDirection
float _WindFrequency
float _WindPower
double _WindPrecRenderTime
NLMISC::CVector2f _WindTable [NL3D_VEGETABLE_VP_LUT_SIZE]

Friends

class CVegetableBlendLayerModel


Member Typedef Documentation

typedef TShapeMap::iterator NL3D::CVegetableManager::ItShapeMap [private]
 

Definition at line 301 of file vegetable_manager.h.

Referenced by getVegetableShape().

typedef std::map<std::string, CVegetableShape> NL3D::CVegetableManager::TShapeMap [private]
 

Definition at line 300 of file vegetable_manager.h.


Member Enumeration Documentation

enum NL3D::CVegetableManager::TVegetableWater
 

Micro vegetation position against Water. Above water is the default.

Enumeration values:
AboveWater 
UnderWater 
IntersectWater 
VegetInfoLast 

Definition at line 79 of file vegetable_manager.h.


Constructor & Destructor Documentation

NL3D::CVegetableManager::CVegetableManager uint  maxVertexVbHardUnlit,
uint  maxVertexVbHardLighted,
uint  nbBlendLayers = 20,
float  blendLayerDistMax = 60.f
 

Parameters:
maxVertexVbHardUnlit maximum VertexCount in VBHard for Unlit (or precomputed lighted) vegetables
maxVertexVbHardLighted maximum VertexCount in VBHard for Lighted vegetables
nbBlendLayers for ZSort/AlphaBlend rdrPass: number of layers of vegetables rendered independently.
blendLayerDistMax for ZSort/AlphaBlend rdrPass: distance of the farest layer.

Definition at line 58 of file vegetable_manager.cpp.

References _DirectionalLight, _GlobalAmbient, _GlobalDiffuse, _NumVegetableFaceRendered, _NumZSortBlendLayers, _ULCurrentIgInstance, _ULCurrentIgRdrPass, _ULNTotalVertices, _ULNVerticesToUpdate, _ULRootIg, _VBHardAllocator, _VBSoftAllocator, _VegetableMaterial, _WindAnimTime, _WindBendMin, _WindDirection, _WindFrequency, _WindPower, _WindPrecRenderTime, _ZSortModelLayers, _ZSortModelLayersUW, NL3D::CVegetableVBAllocator::init(), NL3D::CMaterial::initUnlit(), NL3D_VEGETABLE_CLIP_BLOCK_BLOCKSIZE, NL3D_VEGETABLE_INSTANCE_GROUP_BLOCKSIZE, NL3D_VEGETABLE_NRDRPASS, NL3D_VEGETABLE_SORT_BLOCK_BLOCKSIZE, NL3D_VEGETABLE_VP_LUT_SIZE, nlassert, NLMISC::CVector::normed(), NLMISC::Pi, NLMISC::CVector::set(), NLMISC::CRGBA::set(), NL3D::CMaterial::setAlphaTest(), NL3D::CMaterial::setBlendFunc(), and uint.

00059                                                      : 
00060         _ClipBlockMemory(NL3D_VEGETABLE_CLIP_BLOCK_BLOCKSIZE),
00061         _SortBlockMemory(NL3D_VEGETABLE_SORT_BLOCK_BLOCKSIZE),
00062         _InstanceGroupMemory(NL3D_VEGETABLE_INSTANCE_GROUP_BLOCKSIZE),
00063         _NumZSortBlendLayers(nbBlendLayers), _ZSortLayerDistMax(blendLayerDistMax),
00064         _ZSortScene(NULL)
00065 {
00066         uint    i;
00067 
00068         // Init all the allocators
00069         nlassert((uint)(CVegetableVBAllocator::VBTypeCount) == 2);
00070         _VBHardAllocator[CVegetableVBAllocator::VBTypeLighted].init( CVegetableVBAllocator::VBTypeLighted, maxVertexVbHardLighted );
00071         _VBHardAllocator[CVegetableVBAllocator::VBTypeUnlit].init( CVegetableVBAllocator::VBTypeUnlit, maxVertexVbHardUnlit );
00072         // Init soft one, with no vbHard vertices.
00073         _VBSoftAllocator[CVegetableVBAllocator::VBTypeLighted].init( CVegetableVBAllocator::VBTypeLighted, 0 );
00074         _VBSoftAllocator[CVegetableVBAllocator::VBTypeUnlit].init( CVegetableVBAllocator::VBTypeUnlit, 0 );
00075 
00076         // NB Vertex programs are initilized during the first call to update driver.
00077 
00078         // setup the material. Unlit (doesn't matter, lighting in VP) Alpha Test.
00079         _VegetableMaterial.initUnlit();
00080         _VegetableMaterial.setAlphaTest(true);
00081         _VegetableMaterial.setBlendFunc(CMaterial::srcalpha, CMaterial::invsrcalpha);
00082 
00083         // default light.
00084         _DirectionalLight= (CVector(0,1, -1)).normed();
00085         _GlobalAmbient.set(64, 64, 64, 255);
00086         _GlobalDiffuse.set(150, 150, 150, 255);
00087 
00088         // Wind.
00089         _WindDirection.set(1,0,0);
00090         _WindFrequency= 1;
00091         _WindPower= 1;
00092         _WindBendMin= 0;
00093         _Time= 0;
00094         _WindPrecRenderTime= 0;
00095         _WindAnimTime= 0;
00096 
00097         // Init CosTable.
00098         for(i=0; i<NL3D_VEGETABLE_VP_LUT_SIZE; i++)
00099         {
00100                 _CosTable[i]= (float)cos( i*2*Pi / NL3D_VEGETABLE_VP_LUT_SIZE );
00101         }
00102 
00103         // init to NULL _ZSortModelLayers.
00104         _NumZSortBlendLayers= max(1U, _NumZSortBlendLayers);
00105         _ZSortModelLayers.resize(_NumZSortBlendLayers, NULL);
00106         _ZSortModelLayersUW.resize(_NumZSortBlendLayers, NULL);
00107 
00108 
00109         // UL
00110         _ULFrequency= 0;
00111         _ULNVerticesToUpdate=0;
00112         _ULNTotalVertices= 0;
00113         _ULRootIg= NULL;
00114         _ULCurrentIgRdrPass= 0;
00115         _ULCurrentIgInstance= 0;
00116         _ULPrecTime= 0;
00117         _ULPrecTimeInit= false;
00118         _ULTime= 0;
00119 
00120         // Misc.
00121         _NumVegetableFaceRendered= 0;
00122 
00123         std::fill(_VertexProgram, _VertexProgram + NL3D_VEGETABLE_NRDRPASS, (CVertexProgram *) NULL);
00124 
00125 }

NL3D::CVegetableManager::~CVegetableManager  ) 
 

Definition at line 129 of file vegetable_manager.cpp.

References _NumZSortBlendLayers, _ZSortModelLayers, _ZSortModelLayersUW, _ZSortScene, NL3D::CScene::deleteModel(), NL3D_VEGETABLE_NRDRPASS, sint, and uint.

00130 {
00131         // delete All VP
00132         for(sint i=0; i <NL3D_VEGETABLE_NRDRPASS; i++)
00133         {
00134                 delete  _VertexProgram[i];
00135                 _VertexProgram[i]= NULL;
00136         }
00137 
00138         // delete ZSort models.
00139         if(_ZSortScene)
00140         {
00141                 // remove models from scene.
00142                 for(uint i= 0; i<_NumZSortBlendLayers; i++)
00143                 {
00144                         _ZSortScene->deleteModel(_ZSortModelLayers[i]);
00145                         _ZSortModelLayers[i]= NULL;
00146                         _ZSortScene->deleteModel(_ZSortModelLayersUW[i]);
00147                         _ZSortModelLayersUW[i]= NULL;
00148                 }
00149 
00150                 _ZSortScene= NULL;
00151         }
00152 }


Member Function Documentation

void NL3D::CVegetableManager::addInstance CVegetableInstanceGroup ig,
CVegetableShape shape,
const NLMISC::CMatrix mat,
const NLMISC::CRGBAF ambientColor,
const NLMISC::CRGBAF diffuseColor,
float  bendFactor,
float  bendPhase,
float  bendFreqFactor,
float  blendDistMax,
TVegetableWater  vegetWaterState,
CVegetableUV8  dlmUV
 

add an instance to an ig, enlarging the associated clipBlock bbox. If the shape is not lighted, then only diffuseColor is used, to setup color per vertex. Warning! Use OptFastFloor()! So call must be enclosed with a OptFastFloorBegin()/OptFastFloorEnd().

Also, buffer must be locked.

ambientColor and diffuseColor should be in [0..1] (no clamp), else uint8 will wrap...

nlassert() if no sufficient space reserved in reserveIgCompile().

Parameters:
dlmUV is the dynamic lightmap UV for this vegetable.
See also:
reserveIgAddInstances() reserveIgCompile()

Definition at line 1036 of file vegetable_manager.cpp.

References NL3D::CVegetableSortBlock::_Center, NL3D::CVegetableInstanceGroup::_ClipOwner, _DirectionalLight, NL3D::CVegetableSortBlock::_Dirty, _GlobalAmbient, _GlobalDiffuse, NL3D::CVegetableInstanceGroup::_HasZSortPassInstances, NL3D::CVegetableSortBlock::_InstanceGroupList, NL3D::CVegetableSortBlock::_Radius, NL3D::CVegetableInstanceGroup::_RdrPass, NL3D::CVegetableInstanceGroup::_SortOwner, NL3D::CVegetableInstanceGroup::_TriangleQuadrantOrderNumTriangles, NL3D::CVegetableInstanceGroup::_TriangleQuadrantOrders, _ULNTotalVertices, NL3D::CVegetableInstanceGroup::_ULNumVertices, _ULRootIg, NL3D::CVegetableSortBlock::_UnderWater, NLMISC::CRGBA::A, NL3D::CVegetableVBAllocator::allocateVertex(), NLMISC::CRGBAF::B, NLMISC::CRGBA::B, NL3D::CTessList< CVegetableInstanceGroup >::begin(), NL3D::CVegetableShape::BendCenterMode, NL3D::CVegetableShape::BestSidedPreComputeLighting, NL3D::CVegetableLightEx::Color, NL3D::computeVegetVertexLighting(), NL3D::computeVegetVertexLightingForceBestSided(), NLMISC::CObjectVector< uint32, false >::copy(), NL3D::CVegetableInstanceGroup::CVegetableLightedInstance::DlmUV, NL3D::CVegetableVBAllocator::exceedMaxVertexInBufferHard(), NL3D::CVegetableClipBlock::extendBBoxOnly(), NL3D::CVegetableClipBlock::extendSphere(), NL3D::CVegetableVBAllocator::flushVertex(), NLMISC::CRGBAF::G, NLMISC::CRGBA::G, NL3D::CVertexBuffer::getNormalOff(), NL3D::CVertexBuffer::getNumVertices(), NLMISC::CMatrix::getPos(), getRdrPassInfoForShape(), NL3D::CVegetableVBAllocator::getSoftwareVertexBuffer(), NL3D::CVertexBuffer::getTexCoordOff(), NL3D::CVertexBuffer::getValueOffEx(), getVBAllocatorForRdrPassAndVBHardMode(), NL3D::CVertexBuffer::getVertexCoordPointer(), NL3D::CVegetableVBAllocator::getVertexPointer(), NL3D::CVegetableInstanceGroup::CVegetableRdrPass::HardMode, NL3D::CVegetableShape::InstanceVertices, NLMISC::CMatrix::invert(), NL3D::CVegetableInstanceGroup::CVegetableRdrPass::LightedInstances, NL3D::CVegetableInstanceGroup::linkBeforeUL(), NL3D::CVegetableInstanceGroup::CVegetableLightedInstance::MatAmbient, NL3D::CVegetableInstanceGroup::CVegetableLightedInstance::MatDiffuse, NLMISC::CRGBA::modulateFromColorRGBOnly(), NLMISC::CMatrix::mulVector(), NL3D::CTessNodeList::Next, NL3D_VEGETABLE_BLOCK_BLEND_TRANSITION_DIST, NL3D_VEGETABLE_FREQUENCY_FACTOR_PREC, NL3D_VEGETABLE_NUM_QUADRANT, NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT, NL3D_VEGETABLE_VPPOS_BENDINFO, NL3D_VEGETABLE_VPPOS_CENTER, NL3D_VEGETABLE_VPPOS_COLOR0, NL3D_VEGETABLE_VPPOS_COLOR1, NL3D_VEGETABLE_VPPOS_NORMAL, NL3D_VEGETABLE_VPPOS_TEX0, nlassert, NL3D::CVegetableInstanceGroup::CVegetableRdrPass::NLightedInstances, NLMISC::CVector::norm(), NLMISC::CVector::normalize(), NL3D::CVegetableInstanceGroup::CVegetableLightedInstance::NormalMat, NL3D::CVegetableInstanceGroup::CVegetableRdrPass::NTriangles, NL3D::CVegetableLightEx::NumLights, NL3D::CVegetableInstanceGroup::CVegetableRdrPass::NVertices, NLMISC::OptFastFloor(), NLMISC::CRGBAF::R, NLMISC::CRGBA::R, NLMISC::CMatrix::setRot(), NL3D::CVegetableInstanceGroup::CVegetableLightedInstance::Shape, sint, sint16, NLMISC::CObjectVector< CVegetableLightedInstance >::size(), NLMISC::CObjectVector< uint32, false >::size(), NL3D::CVegetableInstanceGroup::CVegetableLightedInstance::StartIdInRdrPass, swapIgRdrPassHardMode(), NLMISC::CMatrix::transpose(), NL3D::CVegetableInstanceGroup::CVegetableRdrPass::TriangleIndices, NL3D::CVegetableShape::TriangleIndices, NL3D::CVegetableInstanceGroup::CVegetableRdrPass::TriangleLocalIndices, NL3D::CVegetableUV8::U, uint, uint8, NL3D::CVegetableClipBlock::updateSphere(), v, NL3D::CVegetableUV8::V, NL3D::CVegetableShape::VB, NL3D::CVegetableInstanceGroup::VegetableLightEx, NL3D::CVegetableInstanceGroup::CVegetableRdrPass::Vertices, NLMISC::CVectorH::w, NLMISC::CVector::x, NLMISC::CVector::y, NLMISC::CVector::z, and NL3D::CVegetableSortBlock::ZSortHardMode.

Referenced by NL3D::CVegetable::generateInstance().

01041 {
01042         sint    i;
01043 
01044 
01045         // Some setup.
01046         //--------------------
01047         bool    instanceLighted;
01048         bool    instanceDoubleSided;
01049         bool    instanceZSort;
01050         bool    destLighted;
01051         bool    precomputeLighting;
01052 
01053         // get correct rdrPass / info
01054         uint    rdrPass;
01055         rdrPass= getRdrPassInfoForShape(shape, vegetWaterState, instanceLighted, instanceDoubleSided, 
01056                 instanceZSort, destLighted, precomputeLighting);
01057         // bestSided Precompute lighting or not??
01058         bool    bestSidedPrecomputeLighting= precomputeLighting && shape->BestSidedPreComputeLighting;
01059 
01060 
01061         // veget rdrPass
01062         CVegetableInstanceGroup::CVegetableRdrPass      &vegetRdrPass= ig->_RdrPass[rdrPass];
01063 
01064         // color.
01065         // setup using OptFastFloor.
01066         CRGBA           ambientRGBA, diffuseRGBA;
01067         CRGBA           primaryRGBA, secondaryRGBA;
01068         // diffuseColor
01069         diffuseRGBA.R= (uint8)NLMISC::OptFastFloor(diffuseColor.R*255);
01070         diffuseRGBA.G= (uint8)NLMISC::OptFastFloor(diffuseColor.G*255);
01071         diffuseRGBA.B= (uint8)NLMISC::OptFastFloor(diffuseColor.B*255);
01072         diffuseRGBA.A= 255;
01073         // ambientColor
01074         ambientRGBA.R= (uint8)NLMISC::OptFastFloor(ambientColor.R*255);
01075         ambientRGBA.G= (uint8)NLMISC::OptFastFloor(ambientColor.G*255);
01076         ambientRGBA.B= (uint8)NLMISC::OptFastFloor(ambientColor.B*255);
01077         ambientRGBA.A= 255;
01078 
01079         // For Lighted, modulate with global light.
01080         if(instanceLighted)
01081         {
01082                 primaryRGBA.modulateFromColorRGBOnly(diffuseRGBA, _GlobalDiffuse);
01083                 secondaryRGBA.modulateFromColorRGBOnly(ambientRGBA, _GlobalAmbient);
01084         }
01085         // if the instance is not lighted, then don't take care of lighting
01086         else
01087         {
01088                 primaryRGBA.R= diffuseRGBA.R;
01089                 primaryRGBA.G= diffuseRGBA.G;
01090                 primaryRGBA.B= diffuseRGBA.B;
01091                 // may not be useFull (2Sided lighting no more supported)
01092                 secondaryRGBA= primaryRGBA;
01093         }
01094 
01095         // Copy Dynamic Lightmap UV in Alpha part (save memory for an extra cost of 1 VP instruction)
01096         primaryRGBA.A= dlmUV.U;
01097         secondaryRGBA.A= dlmUV.V;
01098 
01099         // get ref on the vegetLex.
01100         CVegetableLightEx       &vegetLex= ig->VegetableLightEx;
01101         // Color of pointLights modulated by diffuse.
01102         CRGBA   diffusePL[2];
01103         if(vegetLex.NumLights>=1)
01104         {
01105                 diffusePL[0].modulateFromColorRGBOnly(diffuseRGBA, vegetLex.Color[0]);
01106                 if(vegetLex.NumLights>=2)
01107                 {
01108                         diffusePL[1].modulateFromColorRGBOnly(diffuseRGBA, vegetLex.Color[1]);
01109                 }
01110         }
01111 
01112         // normalize bendFreqFactor
01113         bendFreqFactor*= NL3D_VEGETABLE_FREQUENCY_FACTOR_PREC;
01114         bendFreqFactor= (float)floor(bendFreqFactor + 0.5f);
01115         bendFreqFactor/= NL3D_VEGETABLE_FREQUENCY_FACTOR_PREC;
01116 
01117 
01118         // Get allocator, and manage VBhard overriding.
01119         //--------------------
01120         CVegetableVBAllocator   *allocator;
01121         // if still in Sfot mode, keep it.
01122         if(!vegetRdrPass.HardMode)
01123         {
01124                 // get the soft allocator.
01125                 allocator= &getVBAllocatorForRdrPassAndVBHardMode(rdrPass, 0);
01126         }
01127         else
01128         {
01129                 // Get VB allocator Hard for this rdrPass
01130                 allocator= &getVBAllocatorForRdrPassAndVBHardMode(rdrPass, 1);
01131                 // Test if the instance don't add too many vertices for this VBHard
01132                 if(allocator->exceedMaxVertexInBufferHard(shape->VB.getNumVertices()))
01133                 {
01134                         // if exceed, then must pass ALL the IG in software mode. vertices/faces are correclty updated.
01135                         // special: if rdrPass is the ZSort one, 
01136                         if(rdrPass == NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT)
01137                         {
01138                                 nlassert(ig->_SortOwner->ZSortHardMode);
01139 
01140                                 // must do it on ALL igs of the sortBlock, for less VBuffer mode switching.
01141                                 CVegetableInstanceGroup         *pIg= ig->_SortOwner->_InstanceGroupList.begin();
01142                                 while(pIg)
01143                                 {
01144                                         // let's pass them in software mode.
01145                                         swapIgRdrPassHardMode(pIg, rdrPass);
01146                                         // next
01147                                         pIg= (CVegetableInstanceGroup*)pIg->Next;
01148                                 }
01149 
01150                                 // Then all The sortBlock is in SoftMode.
01151                                 ig->_SortOwner->ZSortHardMode= false;
01152                         }
01153                         else
01154                         {
01155                                 // just do it on this Ig (can mix hardMode in a SortBlock for normal rdrPass)
01156                                 swapIgRdrPassHardMode(ig, rdrPass);
01157                         }
01158 
01159                         // now, we can use the software only Allocator to append our instance
01160                         allocator= &getVBAllocatorForRdrPassAndVBHardMode(rdrPass, 0);
01161                 }
01162         }
01163 
01164 
01165         // get correct dstVB
01166         const CVertexBuffer     &dstVBInfo= allocator->getSoftwareVertexBuffer();
01167 
01168 
01169         // Transform vertices to a vegetable instance, and enlarge clipBlock
01170         //--------------------
01171         // compute matrix to multiply normals, ie (M-1)t
01172         CMatrix         normalMat;
01173         // need just rotation scale matrix.
01174         normalMat.setRot(mat);
01175         normalMat.invert();
01176         normalMat.transpose();
01177         // compute Instance position
01178         CVector         instancePos;
01179         mat.getPos(instancePos);
01180 
01181 
01182         // At least, the bbox of the clipBlock must include the center of the shape.
01183         ig->_ClipOwner->extendSphere(instancePos);
01184 
01185 
01186         // Vertex/triangle Info.
01187         uint    numNewVertices= shape->VB.getNumVertices();
01188         uint    numNewTris= shape->TriangleIndices.size()/3;
01189         uint    numNewIndices= shape->TriangleIndices.size();
01190 
01191         // src info.
01192         uint    srcNormalOff= (instanceLighted? shape->VB.getNormalOff() : 0);
01193         uint    srcTex0Off= shape->VB.getTexCoordOff(0);
01194         uint    srcTex1Off= shape->VB.getTexCoordOff(1);
01195 
01196         // dst info
01197         uint    dstNormalOff= (destLighted? dstVBInfo.getValueOffEx(NL3D_VEGETABLE_VPPOS_NORMAL) : 0);
01198         uint    dstColor0Off= dstVBInfo.getValueOffEx(NL3D_VEGETABLE_VPPOS_COLOR0);
01199         uint    dstColor1Off= dstVBInfo.getValueOffEx(NL3D_VEGETABLE_VPPOS_COLOR1);
01200         uint    dstTex0Off= dstVBInfo.getValueOffEx(NL3D_VEGETABLE_VPPOS_TEX0);
01201         uint    dstBendOff= dstVBInfo.getValueOffEx(NL3D_VEGETABLE_VPPOS_BENDINFO);
01202         uint    dstCenterOff= dstVBInfo.getValueOffEx(NL3D_VEGETABLE_VPPOS_CENTER);
01203 
01204 
01205         // Usefull For !destLighted only.
01206         CVector         deltaPos;
01207         float           deltaPosNorm=0.0;
01208 
01209 
01210         // UseFull for ZSORT rdrPass, the worldVertices.
01211         static  vector<CVector>         worldVertices;
01212         if(rdrPass == NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT)
01213         {
01214                 worldVertices.resize(numNewVertices);
01215         }
01216 
01217 
01218         // For all vertices of shape, transform and store manager indices in temp shape.
01219         for(i=0; i<(sint)numNewVertices;i++)
01220         {
01221                 // allocate a Vertex
01222                 uint    vid= allocator->allocateVertex();
01223                 // store in tmp shape.
01224                 shape->InstanceVertices[i]= vid;
01225 
01226                 // Fill this vertex.
01227                 uint8   *srcPtr= (uint8*)shape->VB.getVertexCoordPointer(i);
01228                 uint8   *dstPtr= (uint8*)allocator->getVertexPointer(vid);
01229 
01230                 // Get bendWeight for this vertex.
01231                 float   vertexBendWeight= ((CUV*)(srcPtr + srcTex1Off))->U * bendFactor;
01232 
01233                 // Pos.
01234                 //-------
01235                 // Separate Center and relative pos.
01236                 CVector relPos= mat.mulVector(*(CVector*)srcPtr);       // mulVector, because translation in v[center]
01237                 // compute bendCenterPos
01238                 CVector bendCenterPos;
01239                 if(shape->BendCenterMode == CVegetableShapeBuild::BendCenterNull)
01240                         bendCenterPos= CVector::Null;
01241                 else
01242                 {
01243                         CVector v= *(CVector*)srcPtr;
01244                         v.z= 0;
01245                         bendCenterPos= mat.mulVector(v);                                // mulVector, because translation in v[center]
01246                 }
01247                 // copy
01248                 deltaPos= relPos-bendCenterPos;
01249                 *(CVector*)dstPtr= deltaPos;
01250                 *(CVector*)(dstPtr + dstCenterOff)= instancePos + bendCenterPos;
01251                 // if !destLighted, then VP is different
01252                 if(!destLighted)
01253                 {
01254                         deltaPosNorm= deltaPos.norm();
01255                         // copy bendWeight in v.w
01256                         CVectorH        *vh= (CVectorH*)dstPtr;
01257                         // Mul by deltaPosNorm, to draw an arc circle.
01258                         vh->w= vertexBendWeight * deltaPosNorm;
01259                 }
01260 
01261                 // Enlarge the clipBlock of the IG.
01262                 // Since small shape, enlarge with each vertices. simpler and maybe faster.
01263                 // TODO_VEGET: bend and clipping ...
01264                 ig->_ClipOwner->extendBBoxOnly(instancePos + relPos);
01265 
01266                 // prepare for ZSort
01267                 if(rdrPass == NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT)
01268                 {
01269                         worldVertices[i]= instancePos + relPos;
01270                 }
01271 
01272 
01273                 // Color-ligthing.
01274                 //-------
01275                 if(!precomputeLighting)
01276                 {
01277                         // just copy the primary color (means diffuse part if lighted)
01278                         *(CRGBA*)(dstPtr + dstColor0Off)= primaryRGBA;
01279                         // normal and secondary color
01280                         if(destLighted)
01281                         {
01282                                 // normal
01283                                 *(CVector*)(dstPtr + dstNormalOff)= normalMat.mulVector( *(CVector*)(srcPtr + srcNormalOff) );
01284                         }
01285                         // If destLighted, secondaryRGBA is the ambient
01286                         // else secondaryRGBA is used only for Alpha (DLM uv.v).
01287                         *(CRGBA*)(dstPtr + dstColor1Off)= secondaryRGBA;
01288                 }
01289                 else
01290                 {
01291                         nlassert(!destLighted);
01292 
01293                         // compute normal.
01294                         CVector         rotNormal= normalMat.mulVector( *(CVector*)(srcPtr + srcNormalOff) );
01295                         // must normalize() because scale is possible.
01296                         rotNormal.normalize();
01297 
01298                         // Do the compute.
01299                         if(!bestSidedPrecomputeLighting)
01300                         {
01301                                 computeVegetVertexLighting(rotNormal, 
01302                                         _DirectionalLight, primaryRGBA, secondaryRGBA, 
01303                                         vegetLex, diffusePL, (CRGBA*)(dstPtr + dstColor0Off) );
01304                         }
01305                         else
01306                         {
01307                                 computeVegetVertexLightingForceBestSided(rotNormal, 
01308                                         _DirectionalLight, primaryRGBA, secondaryRGBA, 
01309                                         vegetLex, diffusePL, (CRGBA*)(dstPtr + dstColor0Off) );
01310                         }
01311 
01312                         // copy secondaryRGBA, used only for Alpha (DLM uv.v).
01313                         *(CRGBA*)(dstPtr + dstColor1Off)= secondaryRGBA;
01314                 }
01315 
01316 
01317                 // Texture.
01318                 //-------
01319                 *(CUV*)(dstPtr + dstTex0Off)= *(CUV*)(srcPtr + srcTex0Off);
01320 
01321                 // Bend.
01322                 //-------
01323                 CVector         *dstBendPtr= (CVector*)(dstPtr + dstBendOff);
01324                 // setup bend Phase.
01325                 dstBendPtr->y= bendPhase;
01326                 // setup bend Weight.
01327                 // if !destLighted, then VP is different, vertexBendWeight is stored in v[0].w
01328                 if(destLighted)
01329                         dstBendPtr->x= vertexBendWeight;
01330                 else
01331                         // the VP need the norm of relPos in v[9].x
01332                         dstBendPtr->x= deltaPosNorm;
01333                 // setup bendFreqFactor
01334                 dstBendPtr->z= bendFreqFactor;
01336                 if(rdrPass == NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT)
01337                 {
01338                         // get ptr on v[9].w NB: in Unlit mode, it has 4 components.
01339                         CVectorH                *dstBendPtr= (CVectorH*)(dstPtr + dstBendOff);
01340                         // setup the constant of linear formula:
01341                         // Alpha= -1/blendTransDist * dist + blendDistMax/blendTransDist
01342                         dstBendPtr->w= blendDistMax/NL3D_VEGETABLE_BLOCK_BLEND_TRANSITION_DIST;
01343                 }
01344 
01345 
01346                 // fill the vertex in AGP.
01347                 //-------
01348                 allocator->flushVertex(vid);
01349         }
01350 
01351 
01352         // must recompute the sphere according to the bbox.
01353         ig->_ClipOwner->updateSphere();
01354 
01355 
01356         // If ZSort, compute Triangle Centers and Orders for quadrant
01357         //--------------------
01358         if(rdrPass==NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT)
01359         {
01360                 // inform the SB that it must be updated.
01361                 ig->_SortOwner->_Dirty= true;
01362                 // For deletion, inform the ig that it has instances which impact the SB.
01363                 ig->_HasZSortPassInstances= true;
01364 
01365                 // change UnderWater falg of the SB
01366                 if(vegetWaterState == AboveWater)
01367                         ig->_SortOwner->_UnderWater= false;
01368                 else if(vegetWaterState == UnderWater)
01369                         ig->_SortOwner->_UnderWater= true;
01370 
01371                 // static to avoid reallocation
01372                 static  vector<CVector>         triangleCenters;
01373                 triangleCenters.resize(numNewTris);
01374 
01375                 // compute triangle centers
01376                 for(uint i=0; i<numNewTris; i++)
01377                 {
01378                         // get index in shape.
01379                         uint    v0= shape->TriangleIndices[i*3+0];
01380                         uint    v1= shape->TriangleIndices[i*3+1];
01381                         uint    v2= shape->TriangleIndices[i*3+2];
01382 
01383                         // get world coord.
01384                         const CVector   &vert0= worldVertices[v0];
01385                         const CVector   &vert1= worldVertices[v1];
01386                         const CVector   &vert2= worldVertices[v2];
01387 
01388                         // compute center
01389                         triangleCenters[i]= (vert0 + vert1 + vert2) / 3;
01390                         // relative to center of the sortBlock (for sint16 compression)
01391                         triangleCenters[i]-= ig->_SortOwner->_Center;
01392                 }
01393 
01394 
01395                 // resize the array. Actually only modify the number of triangles really setuped.
01396                 uint    offTri= ig->_TriangleQuadrantOrderNumTriangles;
01397                 ig->_TriangleQuadrantOrderNumTriangles+= numNewTris;
01398                 // verify user has correclty used reserveIg system.
01399                 nlassert(ig->_TriangleQuadrantOrderNumTriangles * NL3D_VEGETABLE_NUM_QUADRANT <= ig->_TriangleQuadrantOrderArray.size());
01400 
01401 
01402                 // compute distance for each quadrant. Since we are not sure of the sortBlockSize, mul with a (big: 16) security.
01403                 // NB: for landscape practical usage, this left us with more than 1mm precision.
01404                 float   distFactor=32768/(16*ig->_SortOwner->_Radius);
01405                 for(uint quadId=0; quadId<NL3D_VEGETABLE_NUM_QUADRANT; quadId++)
01406                 {
01407                         const CVector           &quadDir= CVegetableQuadrant::Dirs[quadId];
01408 
01409                         // For all tris.
01410                         for(uint i=0; i<numNewTris; i++)
01411                         {
01412                                 // compute the distance with orientation of the quadrant. (DotProduct)
01413                                 float   dist= triangleCenters[i] * quadDir;
01414                                 // compress to sint16. 
01415                                 ig->_TriangleQuadrantOrders[quadId][offTri + i]= (sint16)NLMISC::OptFastFloor(dist*distFactor);
01416                         }
01417                 }
01418         }
01419 
01420 
01421         // Append list of indices and list of triangles to the IG
01422         //--------------------
01423 
01424         // TODO_VEGET_OPTIM: system reallocation of array is very bad...
01425 
01426 
01427         // compute dest start idx.
01428         uint    offVertex= vegetRdrPass.NVertices;
01429         uint    offTri= vegetRdrPass.NTriangles;
01430         uint    offTriIdx= offTri*3;
01431 
01432         // verify user has correclty used reserveIg system.
01433         nlassert(offVertex + numNewVertices <= vegetRdrPass.Vertices.size());
01434         nlassert(offTriIdx + numNewIndices <= vegetRdrPass.TriangleIndices.size());
01435         nlassert(offTriIdx + numNewIndices <= vegetRdrPass.TriangleLocalIndices.size());
01436 
01437 
01438         // insert list of vertices to delete in ig vertices.
01439         vegetRdrPass.Vertices.copy(offVertex, offVertex+numNewVertices, &shape->InstanceVertices[0]);
01440 
01441         // insert array of triangles in ig.
01442         // for all indices, fill IG
01443         for(i=0; i<(sint)numNewIndices; i++)
01444         {
01445                 // get the index of the vertex in the shape
01446                 uint    vid= shape->TriangleIndices[i];
01447                 // re-direction, using InstanceVertices;
01448                 vegetRdrPass.TriangleIndices[offTriIdx + i]= shape->InstanceVertices[vid];
01449                 // local re-direction: adding vertexOffset.
01450                 vegetRdrPass.TriangleLocalIndices[offTriIdx + i]= offVertex + vid;
01451         }
01452 
01453         // new triangle and vertex size.
01454         vegetRdrPass.NTriangles+= numNewTris;
01455         vegetRdrPass.NVertices+= numNewVertices;
01456 
01457 
01458         // if lighted, must add a lightedInstance for lighting update.
01459         //--------------------
01460         if(instanceLighted)
01461         {
01462                 // first, update Ig.
01463                 ig->_ULNumVertices+= numNewVertices;
01464                 // and update the vegetable manager.
01465                 _ULNTotalVertices+= numNewVertices;
01466                 // link at the end of the circular list: link before the current root.
01467                 if(_ULRootIg==NULL)
01468                         _ULRootIg= ig;
01469                 else
01470                         ig->linkBeforeUL(_ULRootIg);
01471 
01472                 // check good use of reserveIg.
01473                 nlassert(vegetRdrPass.NLightedInstances < vegetRdrPass.LightedInstances.size());
01474 
01475                 // Fill instance info
01476                 CVegetableInstanceGroup::CVegetableLightedInstance      &vli= 
01477                         vegetRdrPass.LightedInstances[vegetRdrPass.NLightedInstances];
01478                 vli.Shape= shape;
01479                 vli.NormalMat= normalMat;
01480                 // copy colors unmodulated by global light.
01481                 vli.MatAmbient= ambientRGBA;
01482                 vli.MatDiffuse= diffuseRGBA;
01483                 // store dynamic lightmap UV
01484                 vli.DlmUV= dlmUV;
01485                 // where vertices of this instances are wrote in the VegetRdrPass
01486                 vli.StartIdInRdrPass= offVertex;
01487 
01488                 // Inc size setuped.
01489                 vegetRdrPass.NLightedInstances++;
01490         }
01491 
01492 }

CVegetableClipBlock * NL3D::CVegetableManager::createClipBlock  ) 
 

Create a clipBlock where SortBlock will be created.

Definition at line 607 of file vegetable_manager.cpp.

References _ClipBlockMemory, _EmptyClipBlockList, NLMISC::CBlockMemory< CVegetableClipBlock >::allocate(), and NL3D::CTessList< CVegetableClipBlock >::append().

Referenced by NL3D::CPatch::addRefTessBlocks().

00608 {
00609         // create a clipblock
00610         CVegetableClipBlock     *ret;
00611         ret= _ClipBlockMemory.allocate();
00612 
00613         // append to list.
00614         _EmptyClipBlockList.append(ret);
00615 
00616         return ret;
00617 }

CVegetableInstanceGroup * NL3D::CVegetableManager::createIg CVegetableSortBlock sortBlock  ) 
 

create an instance group in a sortBlock, where instances will be created. Instances will be frustum-clipped by the clipBlock, and sorted (for the ZSort rdrPass only) by sortBlock.

Definition at line 672 of file vegetable_manager.cpp.

References _ClipBlockList, NL3D::CVegetableInstanceGroup::_ClipOwner, _EmptyClipBlockList, NL3D::CVegetableSortBlock::_InstanceGroupList, _InstanceGroupMemory, NL3D::CVegetableClipBlock::_NumIgs, NL3D::CVegetableSortBlock::_Owner, NL3D::CVegetableInstanceGroup::_RdrPass, NL3D::CVegetableInstanceGroup::_SortOwner, NLMISC::CBlockMemory< CVegetableInstanceGroup >::allocate(), NL3D::CTessList< CVegetableInstanceGroup >::append(), NL3D::CTessList< CVegetableClipBlock >::append(), NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT, nlassert, NL3D::CTessList< CVegetableClipBlock >::remove(), and NL3D::CVegetableSortBlock::ZSortHardMode.

Referenced by NL3D::CLandscapeVegetableBlock::createVegetableIGForDistType().

00673 {
00674         nlassert(sortBlock);
00675         CVegetableClipBlock             *clipBlock= sortBlock->_Owner;
00676         
00677 
00678         // create an IG
00679         CVegetableInstanceGroup *ret;
00680         ret= _InstanceGroupMemory.allocate();
00681         ret->_SortOwner= sortBlock;
00682         ret->_ClipOwner= clipBlock;
00683 
00684         // if the clipBlock is empty, change list, because won't be no more.
00685         if(clipBlock->_NumIgs==0)
00686         {
00687                 // remove from empty list
00688                 _EmptyClipBlockList.remove(clipBlock);
00689                 // and append to not empty one.
00690                 _ClipBlockList.append(clipBlock);
00691         }
00692 
00693         // inc the number of igs appended to the clipBlock.
00694         clipBlock->_NumIgs++;
00695 
00696         // link ig to sortBlock.
00697         sortBlock->_InstanceGroupList.append(ret);
00698 
00699         // Special Init: The ZSort rdrPass must start with the same HardMode than SortBlock.
00700         ret->_RdrPass[NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT].HardMode= sortBlock->ZSortHardMode;
00701 
00702         return ret;
00703 }

CVegetableSortBlock * NL3D::CVegetableManager::createSortBlock CVegetableClipBlock clipBlock,
const CVector center,
float  radius
 

Create a SortBlock in a clipBlock where instance group (ig) will be created. All AlphaBlend instances created in a SortBlock should have the same vegetWaterState: AboveWater or UnderWater. Each time an instance is added to the sortBlock it changes the _UnderWater state of the sortBlock.

Parameters:
center you must give an approximate center for the sortBlock (for sorting)
radius you must give an approximate radius for the sortBlock (for the system to know when you are IN the sortBlock, and then to sort in a better way)

Definition at line 637 of file vegetable_manager.cpp.

References NL3D::CVegetableSortBlock::_Center, NL3D::CVegetableSortBlock::_Owner, NL3D::CVegetableSortBlock::_Radius, NL3D::CVegetableClipBlock::_SortBlockList, _SortBlockMemory, NLMISC::CBlockMemory< CVegetableSortBlock >::allocate(), NL3D::CTessList< CVegetableSortBlock >::append(), and nlassert.

Referenced by NL3D::CLandscapeVegetableBlock::init().

00638 {
00639         nlassert(clipBlock);
00640 
00641         // create a clipblock
00642         CVegetableSortBlock     *ret;
00643         ret= _SortBlockMemory.allocate();
00644         ret->_Owner= clipBlock;
00645         ret->_Center= center;
00646         ret->_Radius= radius;
00647 
00648         // append to list.
00649         clipBlock->_SortBlockList.append(ret);
00650 
00651         return ret;
00652 }

void NL3D::CVegetableManager::createVegetableBlendLayersModels CScene scene  ) 
 

Before any render(), you must call this method (else nlassert). It creates the necessary models in the scene, to manage AlphaBlending correctly. Those models are deleted in the object dtor.

Definition at line 156 of file vegetable_manager.cpp.

References _NumZSortBlendLayers, _ZSortModelLayers, _ZSortModelLayersUW, _ZSortScene, nlassert, uint, and NL3D::VegetableBlendLayerModelId.

Referenced by NL3D::CLandscape::createVegetableBlendLayersModels().

00157 {
00158         // setup scene
00159         nlassert(scene);
00160         _ZSortScene= scene;
00161 
00162         // create the layers models.
00163         for(uint i=0;i<_NumZSortBlendLayers; i++)
00164         {
00165                 // assert not already done.
00166                 nlassert(_ZSortModelLayers[i]==NULL);
00167                 nlassert(_ZSortModelLayersUW[i]==NULL);
00168 
00169                 _ZSortModelLayers[i]= (CVegetableBlendLayerModel*)scene->createModel(VegetableBlendLayerModelId);
00170                 _ZSortModelLayersUW[i]= (CVegetableBlendLayerModel*)scene->createModel(VegetableBlendLayerModelId);
00171                 // init owner.
00172                 _ZSortModelLayers[i]->VegetableManager= this;
00173                 _ZSortModelLayersUW[i]->VegetableManager= this;
00174 
00175                 // Set UnderWater layer for _ZSortModelLayersUW
00176                 _ZSortModelLayersUW[i]->setOrderingLayer(2);
00177         }
00178 }

void NL3D::CVegetableManager::deleteClipBlock CVegetableClipBlock clipBlock  ) 
 

delete such a clipBlock. all sortBlocks and so all ig must be deleted before.

Definition at line 620 of file vegetable_manager.cpp.

References _ClipBlockMemory, _EmptyClipBlockList, NL3D::CVegetableClipBlock::_SortBlockList, NLMISC::CBlockMemory< CVegetableClipBlock >::free(), nlassert, NL3D::CTessList< CVegetableClipBlock >::remove(), and NL3D::CTessList< CVegetableSortBlock >::size().

Referenced by NL3D::CPatch::clearTessBlocks().

00621 {
00622         if(!clipBlock)
00623                 return;
00624 
00625         // verify no more sortBlocks in this clipblock
00626         nlassert(clipBlock->_SortBlockList.size() == 0);
00627 
00628         // unlink from _EmptyClipBlockList, because _InstanceGroupList.size() == 0 ...
00629         _EmptyClipBlockList.remove(clipBlock);
00630 
00631         // delete
00632         _ClipBlockMemory.free(clipBlock);
00633 }

void NL3D::CVegetableManager::deleteIg CVegetableInstanceGroup ig  ) 
 

delete such an ig. After doing this, you must call igSortBlockOwner->updateSortBlock() If the sortBlock has many Igs, you can do it after deleting all your igs.

Definition at line 706 of file vegetable_manager.cpp.

References _ClipBlockList, NL3D::CVegetableInstanceGroup::_ClipOwner, NL3D::CVegetableSortBlock::_Dirty, _EmptyClipBlockList, NL3D::CVegetableInstanceGroup::_HasZSortPassInstances, NL3D::CVegetableSortBlock::_InstanceGroupList, _InstanceGroupMemory, NL3D::CVegetableClipBlock::_NumIgs, NL3D::CVegetableInstanceGroup::_RdrPass, NL3D::CVegetableInstanceGroup::_SortOwner, _ULCurrentIgInstance, _ULCurrentIgRdrPass, NL3D::CVegetableInstanceGroup::_ULNext, _ULNTotalVertices, NL3D::CVegetableInstanceGroup::_ULNumVertices, _ULRootIg, NL3D::CTessList< CVegetableClipBlock >::append(), NLMISC::CObjectVector< uint32, false >::clear(), NL3D::CVegetableVBAllocator::deleteVertex(), NLMISC::CBlockMemory< CVegetableInstanceGroup >::free(), getVBAllocatorForRdrPassAndVBHardMode(), NL3D::CVegetableInstanceGroup::CVegetableRdrPass::HardMode, NL3D_VEGETABLE_NRDRPASS, nlassert, NL3D::CVegetableInstanceGroup::CVegetableRdrPass::NVertices, NL3D::CTessList< CVegetableClipBlock >::remove(), NL3D::CTessList< CVegetableInstanceGroup >::remove(), sint, NLMISC::CObjectVector< uint32, false >::size(), uint, NL3D::CVegetableInstanceGroup::unlinkUL(), and NL3D::CVegetableInstanceGroup::CVegetableRdrPass::Vertices.

Referenced by NL3D::CLandscapeVegetableBlock::createVegetableIGForDistType(), NL3D::CLandscapeVegetableBlock::release(), and NL3D::CLandscapeVegetableBlock::update().

00707 {
00708         if(!ig)
00709                 return;
00710 
00711         // update lighting mgt: no more vertices.
00712         // -----------
00713         // If I delete the ig which is the current root
00714         if(_ULRootIg == ig)
00715         {
00716                 // switch to next
00717                 _ULRootIg= ig->_ULNext;
00718                 // if still the same, it means that the circular list is now empty
00719                 if(_ULRootIg == ig)
00720                         _ULRootIg= NULL;
00721                 // Reset UL instance info.
00722                 _ULCurrentIgRdrPass= 0;
00723                 _ULCurrentIgInstance= 0;
00724         }
00725         // remove UL vertex count of the deleted ig
00726         _ULNTotalVertices-= ig->_ULNumVertices;
00727         // unlink the ig for lighting update.
00728         ig->unlinkUL();
00729 
00730 
00731         // For all render pass of this instance, delete his vertices
00732         // -----------
00733         for(sint rdrPass=0; rdrPass < NL3D_VEGETABLE_NRDRPASS; rdrPass++)
00734         {
00735                 // rdrPass
00736                 CVegetableInstanceGroup::CVegetableRdrPass      &vegetRdrPass= ig->_RdrPass[rdrPass];
00737                 // which allocator?
00738                 CVegetableVBAllocator   &vbAllocator= getVBAllocatorForRdrPassAndVBHardMode(rdrPass, vegetRdrPass.HardMode);
00739 
00740                 // For all vertices of this rdrPass, delete it
00741                 sint    numVertices;
00742                 numVertices= vegetRdrPass.Vertices.size();
00743                 // all vertices must have been setuped.
00744                 nlassert((uint)numVertices == vegetRdrPass.NVertices);
00745                 for(sint i=0; i<numVertices;i++)
00746                 {
00747                         vbAllocator.deleteVertex(vegetRdrPass.Vertices[i]);
00748                 }
00749                 vegetRdrPass.Vertices.clear();
00750         }
00751 
00752         CVegetableClipBlock             *clipBlock= ig->_ClipOwner;
00753         CVegetableSortBlock             *sortBlock= ig->_SortOwner;
00754 
00755         // If I have got some faces in ZSort rdrPass
00756         if(ig->_HasZSortPassInstances)
00757                 // after my deletion, the sortBlock must be updated.
00758                 sortBlock->_Dirty= true;
00759 
00760 
00761         // unlink from sortBlock, and delete.
00762         sortBlock->_InstanceGroupList.remove(ig);
00763         _InstanceGroupMemory.free(ig);
00764 
00765 
00766         // decRef the clipBlock
00767         clipBlock->_NumIgs--;
00768         // if the clipBlock is now empty, change list
00769         if(clipBlock->_NumIgs==0)
00770         {
00771                 // remove from normal list
00772                 _ClipBlockList.remove(clipBlock);
00773                 // and append to empty list.
00774                 _EmptyClipBlockList.append(clipBlock);
00775         }
00776 
00777 }

void NL3D::CVegetableManager::deleteSortBlock CVegetableSortBlock sortBlock  ) 
 

delete such a SortBlock. all ig must be deleted before.

Definition at line 655 of file vegetable_manager.cpp.

References NL3D::CVegetableSortBlock::_InstanceGroupList, NL3D::CVegetableSortBlock::_Owner, NL3D::CVegetableClipBlock::_SortBlockList, _SortBlockMemory, NLMISC::CBlockMemory< CVegetableSortBlock >::free(), nlassert, NL3D::CTessList< CVegetableSortBlock >::remove(), and NL3D::CTessList< CVegetableInstanceGroup >::size().

Referenced by NL3D::CLandscapeVegetableBlock::release().

00656 {
00657         if(!sortBlock)
00658                 return;
00659 
00660         // verify no more IGs in this sortblock
00661         nlassert(sortBlock->_InstanceGroupList.size() == 0);
00662 
00663         // unlink from clipBlock
00664         sortBlock->_Owner->_SortBlockList.remove(sortBlock);
00665 
00666         // delete
00667         _SortBlockMemory.free(sortBlock);
00668 }

bool NL3D::CVegetableManager::doubleSidedRdrPass uint  rdrPass  )  [static, private]
 

Definition at line 1560 of file vegetable_manager.cpp.

References NL3D_VEGETABLE_NRDRPASS, NL3D_VEGETABLE_RDRPASS_LIGHTED_2SIDED, NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED, NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT, nlassert, and uint.

Referenced by render(), and setupRenderStateForBlendLayerModel().

01561 {
01562         nlassert(rdrPass<NL3D_VEGETABLE_NRDRPASS);
01563         return (rdrPass == NL3D_VEGETABLE_RDRPASS_LIGHTED_2SIDED) || 
01564                 (rdrPass == NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED) ||
01565                 (rdrPass == NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT);
01566 }

void NL3D::CVegetableManager::doUpdateLighting  )  [private]
 

update lighting according to _ULNVerticesToUpdate

Definition at line 2262 of file vegetable_manager.cpp.

References NL3D::CVegetableInstanceGroup::_ULNext, _ULNVerticesToUpdate, _ULRootIg, and updateLightingIGPart().

Referenced by updateLighting(), and updateLightingAll().

02263 {
02264         // while there is still some vertices to update.
02265         while(_ULNVerticesToUpdate > 0 && _ULRootIg)
02266         {
02267                 // update the current ig. if all updated, skip to next one.
02268                 if(updateLightingIGPart())
02269                 {
02270                         // next
02271                         _ULRootIg= _ULRootIg->_ULNext;
02272                 }
02273         }
02274 
02275         // Now, _ULNVerticesToUpdate should be <=0. (most of the time < 0)
02276 }

void NL3D::CVegetableManager::exitRenderStateForBlendLayerModel IDriver driver  )  [private]
 

Definition at line 2180 of file vegetable_manager.cpp.

References _BkupFog, NL3D::IDriver::activeVertexProgram(), and NL3D::IDriver::enableFog().

Referenced by NL3D::CVegetableBlendLayerModel::render().

02181 {
02182         // disable VertexProgram.
02183         driver->activeVertexProgram(NULL);
02184 
02185         // restore Fog.
02186         driver->enableFog(_BkupFog);
02187 }

uint NL3D::CVegetableManager::getNumVegetableFaceRendered  )  const
 

get the number of faces rendered by the vegetable manager

Definition at line 2173 of file vegetable_manager.cpp.

References _NumVegetableFaceRendered, and uint.

Referenced by NL3D::CLandscape::getNumVegetableFaceRendered().

02174 {
02175         return _NumVegetableFaceRendered;
02176 }

uint NL3D::CVegetableManager::getRdrPassInfoForShape CVegetableShape shape,
TVegetableWater  vegetWaterState,
bool &  instanceLighted,
bool &  instanceDoubleSided,
bool &  instanceZSort,
bool &  destLighted,
bool &  precomputeLighting
[private]
 

get the rdrPass and other info for a given shape.

Definition at line 817 of file vegetable_manager.cpp.

References NL3D::CVegetableShape::AlphaBlend, NL3D::CVegetableShape::DoubleSided, NL3D::CVegetableShape::Lighted, NL3D_VEGETABLE_RDRPASS_LIGHTED, NL3D_VEGETABLE_RDRPASS_LIGHTED_2SIDED, NL3D_VEGETABLE_RDRPASS_UNLIT, NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED, NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT, NL3D::CVegetableShape::PreComputeLighting, and uint.

Referenced by addInstance(), and reserveIgAddInstances().

00820 {
00821         instanceLighted= shape->Lighted;
00822         instanceDoubleSided= shape->DoubleSided;
00823         // Disable ZSorting when we intersect water.
00824         instanceZSort= shape->AlphaBlend && vegetWaterState!=IntersectWater;
00825         destLighted= instanceLighted && !shape->PreComputeLighting;
00826         precomputeLighting= instanceLighted && shape->PreComputeLighting;
00827 
00828         // get correct rdrPass
00829         uint    rdrPass;
00830         // get according to lighted / doubleSided state
00831         if(destLighted)
00832         {
00833                 if(instanceDoubleSided)
00834                         rdrPass= NL3D_VEGETABLE_RDRPASS_LIGHTED_2SIDED;
00835                 else
00836                         rdrPass= NL3D_VEGETABLE_RDRPASS_LIGHTED;
00837         }
00838         else
00839         {
00840                 if(instanceDoubleSided)
00841                 {
00842                         if(instanceZSort)
00843                                 rdrPass= NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT;
00844                         else
00845                                 rdrPass= NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED;
00846                 }
00847                 else
00848                         rdrPass= NL3D_VEGETABLE_RDRPASS_UNLIT;
00849         }
00850 
00851         return rdrPass;
00852 }

CVegetableVBAllocator & NL3D::CVegetableManager::getVBAllocatorForRdrPassAndVBHardMode uint  rdrPass,
uint  vbHardMode
[private]
 

Get the good allocator for the appropriate rdr pass.

Definition at line 182 of file vegetable_manager.cpp.

References _VBHardAllocator, _VBSoftAllocator, NL3D_VEGETABLE_RDRPASS_LIGHTED, NL3D_VEGETABLE_RDRPASS_LIGHTED_2SIDED, NL3D_VEGETABLE_RDRPASS_UNLIT, NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED, NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT, nlstop, and uint.

Referenced by addInstance(), deleteIg(), render(), NL3D::CVegetableBlendLayerModel::render(), swapIgRdrPassHardMode(), and updateInstanceLighting().

00183 {
00184         // If software VB
00185         if(vbHardMode==0)
00186         {
00187                 if(rdrPass == NL3D_VEGETABLE_RDRPASS_LIGHTED)
00188                         return _VBSoftAllocator[CVegetableVBAllocator::VBTypeLighted];
00189                 if(rdrPass == NL3D_VEGETABLE_RDRPASS_LIGHTED_2SIDED)
00190                         return _VBSoftAllocator[CVegetableVBAllocator::VBTypeLighted];
00191                 if(rdrPass == NL3D_VEGETABLE_RDRPASS_UNLIT)
00192                         return _VBSoftAllocator[CVegetableVBAllocator::VBTypeUnlit];
00193                 if(rdrPass == NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED)
00194                         return _VBSoftAllocator[CVegetableVBAllocator::VBTypeUnlit];
00195                 if(rdrPass == NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT)
00196                         return _VBSoftAllocator[CVegetableVBAllocator::VBTypeUnlit];
00197         }
00198         // If hard VB
00199         else
00200         {
00201                 if(rdrPass == NL3D_VEGETABLE_RDRPASS_LIGHTED)
00202                         return _VBHardAllocator[CVegetableVBAllocator::VBTypeLighted];
00203                 if(rdrPass == NL3D_VEGETABLE_RDRPASS_LIGHTED_2SIDED)
00204                         return _VBHardAllocator[CVegetableVBAllocator::VBTypeLighted];
00205                 if(rdrPass == NL3D_VEGETABLE_RDRPASS_UNLIT)
00206                         return _VBHardAllocator[CVegetableVBAllocator::VBTypeUnlit];
00207                 if(rdrPass == NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED)
00208                         return _VBHardAllocator[CVegetableVBAllocator::VBTypeUnlit];
00209                 if(rdrPass == NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT)
00210                         return _VBHardAllocator[CVegetableVBAllocator::VBTypeUnlit];
00211         }
00212 
00213         // abnormal case
00214         nlstop;
00215         // To avoid warning;
00216         return _VBSoftAllocator[0];
00217 }

CVegetableShape * NL3D::CVegetableManager::getVegetableShape const std::string &  shape  ) 
 

Load a shape if necessary, and return a shapeId for this shape.

Definition at line 781 of file vegetable_manager.cpp.

References ItShapeMap, NL3D::CVegetableShape::loadShape(), and nlwarning.

Referenced by NL3D::CVegetable::registerToManager().

00782 {
00783         ItShapeMap      it= _ShapeMap.find(shape);
00784         // if found
00785         if(it != _ShapeMap.end())
00786                 return &it->second;
00787         // else insert
00788         {
00789                 // insert.
00790                 CVegetableShape         *ret;
00791                 it= ( _ShapeMap.insert(make_pair(shape, CVegetableShape()) ) ).first;
00792                 ret= &it->second;
00793 
00794                 // fill.
00795                 try
00796                 {
00797                         ret->loadShape(shape);
00798                 }
00799                 catch (Exception &e)
00800                 {
00801                         // Warning
00802                         nlwarning ("CVegetableManager::getVegetableShape error while loading shape file '%s' : '%s'", shape.c_str (), e.what ());
00803 
00804                         // Remove from map
00805                         _ShapeMap.erase (shape);
00806 
00807                         // Return NULL
00808                         ret = NULL;
00809                 }
00810 
00811                 return ret;
00812         }
00813 }

void NL3D::CVegetableManager::initVertexProgram uint  vpType  )  [private]
 

init the ith vertexProgram.

Definition at line 562 of file vegetable_manager.cpp.

References _LastDriver, NL3D::NL3D_BendProgram, NL3D::NL3D_CommonEndVegetableProgram, NL3D::NL3D_FastBendProgram, NL3D::NL3D_LightedStartVegetableProgram, NL3D::NL3D_UnlitAlphaBlendVegetableProgram, NL3D::NL3D_UnlitStartVegetableProgram, NL3D_VEGETABLE_RDRPASS_LIGHTED, NL3D_VEGETABLE_RDRPASS_LIGHTED_2SIDED, NL3D_VEGETABLE_RDRPASS_UNLIT, NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED, NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT, nlassert, and uint.

Referenced by updateDriver().

00563 {
00564         nlassert(_LastDriver); // update driver should have been called at least once !
00565         // Init the Vertex Program.
00566         string  vpgram;
00567         // start always with Bend.
00568         if( vpType==NL3D_VEGETABLE_RDRPASS_LIGHTED || vpType==NL3D_VEGETABLE_RDRPASS_LIGHTED_2SIDED )
00569                 vpgram= NL3D_BendProgram;
00570         else
00571                 vpgram= NL3D_FastBendProgram;
00572 
00573         // combine the VP according to Type
00574         switch(vpType)
00575         {
00576         case NL3D_VEGETABLE_RDRPASS_LIGHTED:
00577         case NL3D_VEGETABLE_RDRPASS_LIGHTED_2SIDED:             
00578                 vpgram+= string(NL3D_LightedStartVegetableProgram);
00579                 break;
00580         case NL3D_VEGETABLE_RDRPASS_UNLIT:              
00581         case NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED:               
00582                 vpgram+= string(NL3D_UnlitStartVegetableProgram);
00583                 break;
00584         case NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT:         
00585                 vpgram+= string(NL3D_UnlitStartVegetableProgram);
00586                 vpgram+= string(NL3D_UnlitAlphaBlendVegetableProgram);
00587                 break;  
00588         }
00589 
00590         // common end of VP
00591         vpgram+= string(NL3D_CommonEndVegetableProgram);
00592 
00593         // create VP.
00594         _VertexProgram[vpType]= new CVertexProgram(vpgram.c_str());
00595 
00596 }

void NL3D::CVegetableManager::loadTexture ITexture itex  ) 
 

setup a global texture used for all vegetables (smartPtr-ized).

Definition at line 1604 of file vegetable_manager.cpp.

References _VegetableMaterial, and NL3D::CMaterial::setTexture().

01605 {
01606         // setup a ITexture (smartPtr-ized).
01607         // Store in stage1, for dynamicLightmaping
01608         _VegetableMaterial.setTexture(1, itex);
01609 }

void NL3D::CVegetableManager::loadTexture const std::string &  texName  ) 
 

load a global texture used for all vegetables (lookup into CPath).

Definition at line 1592 of file vegetable_manager.cpp.

References NL3D::ITexture::setFilterMode(), NL3D::ITexture::setWrapS(), and NL3D::ITexture::setWrapT().

Referenced by NL3D::CLandscape::loadVegetableTexture().

01593 {
01594         // setup a CTextureFile (smartPtr-ized).
01595         ITexture        *tex= new CTextureFile(texName);
01596         loadTexture(tex);
01597         // setup good params.
01598         tex->setFilterMode(ITexture::Linear, ITexture::LinearMipMapLinear);
01599         tex->setWrapS(ITexture::Clamp);
01600         tex->setWrapT(ITexture::Clamp);
01601 }

void NL3D::CVegetableManager::lockBuffers  ) 
 

lock any AGP vertex buffers. Do it wisely (just one time before refine as example). You MUST enclose calls to addInstance() (and so CVegetable::generateInstance()) with lockBuffers() / unlockBuffers().

Definition at line 1622 of file vegetable_manager.cpp.

References _VBHardAllocator, _VBSoftAllocator, NL3D::CVegetableVBAllocator::lockBuffer(), and uint.

Referenced by NL3D::CLandscape::lockBuffers().

01623 {
01624         // lock all buffers
01625         for(uint i=0; i <CVegetableVBAllocator::VBTypeCount; i++)
01626         {
01627                 _VBHardAllocator[i].lockBuffer();
01628                 _VBSoftAllocator[i].lockBuffer();
01629         }
01630 }

void NL3D::CVegetableManager::render const CVector viewCenter,
const CVector frontVector,
const std::vector< CPlane > &  pyramid,
ITexture textureDLM,
IDriver driver
 

render the manager into a driver, with current viewMatrix/frustum/fog setuped Buffers should be unlocked.

Parameters:
textureDLM is the dynamic lightmap to use. can be NULL if don't want DLM

Definition at line 1713 of file vegetable_manager.cpp.

References _AngleAxis, NL3D::CVegetableSortBlock::_Center, _ClipBlockList, NL3D::CVegetableSortBlock::_InstanceGroupList, _ManagerMatrix, NL3D::CVegetableSortBlock::_NTriangles, _NumVegetableFaceRendered, _NumZSortBlendLayers, NL3D::CVegetableSortBlock::_QuadrantId, NL3D::CVegetableSortBlock::_Radius, NL3D::CVegetableInstanceGroup::_RdrPass, NL3D::CVegetableClipBlock::_RenderNext, NL3D::CVegetableClipBlock::_SortBlockList, NL3D::CVegetableSortBlock::_SortKey, NL3D::CVegetableSortBlock::_UnderWater, _VegetableMaterial, _ViewCenter, _WindAnimTime, _WindBendMin, _WindDeltaTable, _WindDirection, _WindFrequency, _WindPower, _WindPrecRenderTime, _WindTable, _ZSortLayerDistMax, _ZSortModelLayers, _ZSortModelLayersUW, NL3D::CVegetableVBAllocator::activate(), NL3D::IDriver::activeVertexProgram(), NL3D::CTessList< CVegetableInstanceGroup >::begin(), NL3D::CTessList< CVegetableSortBlock >::begin(), NL3D::CTessList< CVegetableClipBlock >::begin(), NLMISC::clamp(), NL3D::CVegetableClipBlock::clip(), doubleSidedRdrPass(), NL3D::IDriver::enableFog(), NL3D::IDriver::fogEnabled(), NL3D::CVegetableVBAllocator::getNumUserVerticesAllocated(), getVBAllocatorForRdrPassAndVBHardMode(), H_AUTO, NL3D::CVegetableInstanceGroup::CVegetableRdrPass::HardMode, NLMISC::CMatrix::identity(), NL3D::CTessNodeList::Next, NL3D_VEGETABLE_FREQUENCY_FACTOR_PREC, NL3D_VEGETABLE_NRDRPASS, NL3D_VEGETABLE_NUM_QUADRANT, NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT, NL3D_VEGETABLE_VP_LUT_SIZE, nlassert, nlverify, NLMISC::CVector::norm(), NLMISC::CVector::normed(), NL3D::CVegetableInstanceGroup::CVegetableRdrPass::NTriangles, NL3D::CPrimitiveProfile::NTriangles, NLMISC::OptFastFloor(), NL3D::IDriver::profileRenderedPrimitives(), NL3D::IDriver::renderSimpleTriangles(), NLMISC::CVector::set(), NL3D::CMaterial::setAlphaTestThreshold(), NL3D::CMaterial::setBlend(), NL3D::CMaterial::setDoubleSided(), NLMISC::CMatrix::setPos(), NL3D::CMaterial::setTexture(), NL3D::IDriver::setupMaterial(), NL3D::IDriver::setupModelMatrix(), setupVertexProgramConstants(), NL3D::CMaterial::setZWrite(), sint, NL3D::CMaterial::texEnvArg0Alpha(), NL3D::CMaterial::texEnvArg0RGB(), NL3D::CMaterial::texEnvArg1Alpha(), NL3D::CMaterial::texEnvArg1RGB(), NL3D::CMaterial::texEnvOpAlpha(), NL3D::CMaterial::texEnvOpRGB(), NL3D::CVegetableInstanceGroup::CVegetableRdrPass::TriangleIndices, uint, updateDriver(), NLMISC::CVector::x, NLMISC::CVector::y, and z.

Referenced by NL3D::CLandscape::render().

01715 {
01716         H_AUTO( NL3D_Vegetable_Render );
01717 
01718         CVegetableClipBlock             *rootToRender= NULL;
01719 
01720         // get normalized front vector.
01721         CVector         frontVectorNormed= frontVector.normed();
01722 
01723         // For Speed debug only.
01724         /*extern        bool    YOYO_ATTest;
01725         if(YOYO_ATTest)
01726                 return;
01727         */
01728 
01729         // Clip.
01730         //--------------------
01731         // For all current not empty clipBlocks, clip against pyramid, and insert visibles in list.
01732         CVegetableClipBlock             *ptrClipBlock= _ClipBlockList.begin();
01733         while(ptrClipBlock)
01734         {
01735                 // if the clipBlock is visible and not empty
01736                 if(ptrClipBlock->clip(pyramid))
01737                 {
01738                         // insert into visible list.
01739                         ptrClipBlock->_RenderNext= rootToRender;
01740                         rootToRender= ptrClipBlock;
01741                 }
01742 
01743                 // next
01744                 ptrClipBlock= (CVegetableClipBlock*)ptrClipBlock->Next;
01745         }
01746 
01747 
01748         // If no clip block visible, just skip!!
01749         if(rootToRender==NULL)
01750                 return;
01751 
01752 
01753         // Prepare Render
01754         //--------------------
01755 
01756         // profile.
01757         CPrimitiveProfile       ppIn, ppOut;
01758         driver->profileRenderedPrimitives(ppIn, ppOut);
01759         uint    precNTriRdr= ppOut.NTriangles;
01760 
01761 
01762         // Disable Fog.
01763         bool    bkupFog;
01764         bkupFog= driver->fogEnabled();
01765         driver->enableFog(false);
01766 
01767 
01768         // Used by setupVertexProgramConstants(). The center of camera.
01769         // Used for AlphaBlending, and for ZBuffer precision problems.
01770         _ViewCenter= viewCenter;
01771 
01772 
01773         // The manager is identity in essence. But for ZBuffer improvements, must set it as close
01774         // to the camera. In the VertexProgram, _ViewCenter is substracted from bent vertex pos. So take it as position.
01775         _ManagerMatrix.identity();
01776         _ManagerMatrix.setPos(_ViewCenter);
01777 
01778 
01779         // set model matrix to the manager matrix.
01780         driver->setupModelMatrix(_ManagerMatrix);
01781 
01782 
01783         // set the driver for all allocators
01784         updateDriver(driver);
01785 
01786 
01787         // Compute Bend Anim.
01788 
01789         // AnimFrequency factor.
01790         // Doing it incrementaly allow change of of frequency each frame with good results.
01791         _WindAnimTime+= (_Time - _WindPrecRenderTime)*_WindFrequency;
01792         _WindAnimTime= fmod(_WindAnimTime, (float)NL3D_VEGETABLE_FREQUENCY_FACTOR_PREC);
01793         // NB: Leave timeBend (_WindAnimTime) as a time (ie [0..1]), because VP do a "EXP time".
01794         // For incremental computing.
01795         _WindPrecRenderTime= _Time;
01796 
01797 
01798         // compute the angleAxis corresponding to direction
01799         // perform a 90deg rotation to get correct angleAxis
01800         _AngleAxis.set(-_WindDirection.y,_WindDirection.x,0);
01801 
01802 
01803         // Fill LUT WindTable.
01804         uint    i;
01805         for(i=0; i<NL3D_VEGETABLE_VP_LUT_SIZE; i++)
01806         {
01807                 /* NB: this formula works quite well, because vertex BendFactor is expressed in Radian/2.
01808                         And since animFactor==(_CosTable[i] + 1) E [0..2], we have here an arc-cirle computing:
01809                         dmove= Radius * AngleRadian/2 *  animFactor. So at max of animFactor (ie 2), we have:
01810                         dmove= Radius * AngleRadian, which is by definition an arc-cirle computing...
01811                         And so this approximate the Bend-quaternion Vertex Program.
01812                 */
01813                 float   windForce= (_CosTable[(i+32)%64] + 1);
01814                 // Modify with _WindPower / _WindBendMin.
01815                 windForce= _WindBendMin*2 + windForce * (1-_WindBendMin);
01816                 windForce*= _WindPower;
01817                 // Compute direction of the wind, and multiply by windForce.
01818                 _WindTable[i]= CVector2f(_WindDirection.x, _WindDirection.y) * windForce;
01819         }
01820         // compute delta
01821         for(i=0; i<NL3D_VEGETABLE_VP_LUT_SIZE; i++)
01822         {
01823                 CVector2f               cur= _WindTable[i];
01824                 CVector2f               delta= _WindTable[ (i+1)%NL3D_VEGETABLE_VP_LUT_SIZE ] - cur;
01825                 _WindDeltaTable[i]= delta;
01826         }
01827 
01828 
01829         // setup VP constants.
01830         setupVertexProgramConstants(driver);
01831 
01832 
01833         // Setup TexEnvs for Dynamic lightmapping
01834         //--------------------
01835         // if the dynamic lightmap is provided
01836         if(textureDLM)
01837         {
01838                 // stage0 RGB is Diffuse + DLM.
01839                 _VegetableMaterial.setTexture(0, textureDLM);
01840                 _VegetableMaterial.texEnvOpRGB(0, CMaterial::Add);
01841                 _VegetableMaterial.texEnvArg0RGB(0, CMaterial::Texture, CMaterial::SrcColor);
01842                 _VegetableMaterial.texEnvArg1RGB(0, CMaterial::Diffuse, CMaterial::SrcColor);
01843                 // stage1 RGB is Previous * Texture
01844                 _VegetableMaterial.texEnvOpRGB(1, CMaterial::Modulate);
01845                 _VegetableMaterial.texEnvArg0RGB(1, CMaterial::Texture, CMaterial::SrcColor);
01846                 _VegetableMaterial.texEnvArg1RGB(1, CMaterial::Previous, CMaterial::SrcColor);
01847         }
01848         else
01849         {
01850                 // reset stage0 (to skip it)
01851                 _VegetableMaterial.setTexture(0, NULL);
01852                 // stage1 RGB is Diffuse * Texture
01853                 _VegetableMaterial.texEnvOpRGB(1, CMaterial::Modulate);
01854                 _VegetableMaterial.texEnvArg0RGB(1, CMaterial::Texture, CMaterial::SrcColor);
01855                 _VegetableMaterial.texEnvArg1RGB(1, CMaterial::Diffuse, CMaterial::SrcColor);
01856         }
01857         // stage1 Alpha is always "Modulate texture with diffuse Alpha"
01858         _VegetableMaterial.texEnvOpAlpha(1, CMaterial::Modulate);
01859         _VegetableMaterial.texEnvArg0Alpha(1, CMaterial::Texture, CMaterial::SrcAlpha);
01860         _VegetableMaterial.texEnvArg1Alpha(1, CMaterial::Diffuse, CMaterial::SrcAlpha);
01861 
01862 
01863 
01864         // Render !ZSORT pass
01865         //--------------------
01866 
01867         // setup material (may have change because of ZSORT / alphaBlend pass)
01868         _VegetableMaterial.setBlend(false);
01869         _VegetableMaterial.setZWrite(true);
01870         _VegetableMaterial.setAlphaTestThreshold(0.5f);
01871 
01872 
01873         /*
01874                 Prefer sort with Soft / Hard first.
01875                 Also, Prefer do VBsoft last, for better GPU //ism with Landscape.
01876         */
01877         // For both allocators: Hard(1) then Soft(0)
01878         for(sint vbHardMode= 1; vbHardMode>=0; vbHardMode--)
01879         {
01880                 // For all renderPass.
01881                 for(sint rdrPass=0; rdrPass < NL3D_VEGETABLE_NRDRPASS; rdrPass++)
01882                 {
01883                         // skip ZSORT rdrPass, done after.
01884                         if(rdrPass == NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT)
01885                                 continue;
01886 
01887                         // which allocator?
01888                         CVegetableVBAllocator   &vbAllocator= getVBAllocatorForRdrPassAndVBHardMode(rdrPass, vbHardMode);
01889 
01890                         // Do the pass only if there is some vertices to draw.
01891                         if(vbAllocator.getNumUserVerticesAllocated()>0)
01892                         {
01893                                 // additional setup to the material
01894                                 bool    doubleSided= doubleSidedRdrPass(rdrPass);
01895                                 // set the 2Sided flag in the material
01896                                 _VegetableMaterial.setDoubleSided( doubleSided );
01897 
01898 
01899                                 // Activate the unique material.
01900                                 driver->setupMaterial(_VegetableMaterial);
01901 
01902                                 // activate Vertex program first.
01903                                 //nlinfo("\nSTARTVP\n%s\nENDVP\n", _VertexProgram[rdrPass]->getProgram().c_str());
01904                                 nlverify(driver->activeVertexProgram(_VertexProgram[rdrPass]));
01905 
01906                                 // Activate the good VBuffer
01907                                 vbAllocator.activate();
01908 
01909                                 // For all visibles clipBlock, render their instance groups.
01910                                 ptrClipBlock= rootToRender;
01911                                 while(ptrClipBlock)
01912                                 {
01913                                         // For all sortBlock of the clipBlock
01914                                         CVegetableSortBlock     *ptrSortBlock= ptrClipBlock->_SortBlockList.begin();
01915                                         while(ptrSortBlock)
01916                                         {
01917                                                 // For all igs of the sortBlock
01918                                                 CVegetableInstanceGroup         *ptrIg= ptrSortBlock->_InstanceGroupList.begin();
01919                                                 while(ptrIg)
01920                                                 {
01921                                                         // rdrPass
01922                                                         CVegetableInstanceGroup::CVegetableRdrPass      &vegetRdrPass= ptrIg->_RdrPass[rdrPass];
01923 
01924                                                         // if this rdrPass is in same HardMode as we process now.
01925                                                         if( (vegetRdrPass.HardMode && vbHardMode==1) || (!vegetRdrPass.HardMode && vbHardMode==0) )
01926                                                         {
01927                                                                 // Ok, Render the faces.
01928                                                                 if(vegetRdrPass.NTriangles)
01929                                                                 {
01930                                                                         driver->renderSimpleTriangles(&vegetRdrPass.TriangleIndices[0], 
01931                                                                                 vegetRdrPass.NTriangles);
01932                                                                 }
01933                                                         }
01934 
01935                                                         // next ig.
01936                                                         ptrIg= (CVegetableInstanceGroup*)ptrIg->Next;
01937                                                 }
01938 
01939                                                 // next sortBlock
01940                                                 ptrSortBlock= (CVegetableSortBlock      *)(ptrSortBlock->Next);
01941                                         }
01942 
01943                                         // next clipBlock to render 
01944                                         ptrClipBlock= ptrClipBlock->_RenderNext;
01945                                 }
01946                         }
01947 
01948                 }
01949 
01950         }
01951 
01952         // Render ZSort pass.
01953         //--------------------
01954 
01955         // Debug Quadrants.
01956         /*static vector<CVector>                p0DebugLines;
01957         static vector<CVector>          p1DebugLines;
01958         p0DebugLines.clear();
01959         p1DebugLines.clear();*/
01960 
01961         // For all Blend model Layers, clear Sort Block list and setup.
01962         for(i=0; i<_NumZSortBlendLayers;i++)
01963         {
01964                 // must have been created.
01965                 nlassert(_ZSortModelLayers[i]);
01966                 nlassert(_ZSortModelLayersUW[i]);
01967                 // NB: don't refresh list, it is done in CVegetableBlendLayerModel.
01968                 // We must do it here, because if vegetableManger::render() is no more called (eg: disabled),
01969                 // then the models must do nothing.
01970 
01971                 // To get layers correclty sorted from fornt to back, must init their pos
01972                 // because it is the renderTraversal which sort them.
01973                 // compute distance to camera of this layer.
01974                 float   layerZ= i * _ZSortLayerDistMax / _NumZSortBlendLayers;
01975                 // compute position of this layer.
01976                 CVector         pos= viewCenter + frontVector * layerZ;
01977                 // special setup in the layer.
01978                 _ZSortModelLayers[i]->setWorldPos(pos);
01979                 _ZSortModelLayersUW[i]->setWorldPos(pos);
01980         }
01981 
01982         // If some vertices in arrays for ZSort rdrPass
01983         if( getVBAllocatorForRdrPassAndVBHardMode(NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT, 0).getNumUserVerticesAllocated()>0 ||
01984                 getVBAllocatorForRdrPassAndVBHardMode(NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT, 1).getNumUserVerticesAllocated()>0 )
01985         {
01986                 uint    rdrPass= NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT;
01987 
01988                 // sort
01989                 //-------------
01990                 // Array for sorting. (static to avoid reallocation)
01991                 static  vector<CSortVSB>                sortVegetSbs;
01992                 sortVegetSbs.clear();
01993 
01994                 // For all visibles clipBlock
01995                 ptrClipBlock= rootToRender;
01996                 while(ptrClipBlock)
01997                 {
01998                         // For all sortBlock, prepare to sort them
01999                         CVegetableSortBlock     *ptrSortBlock= ptrClipBlock->_SortBlockList.begin();
02000                         while(ptrSortBlock)
02001                         {
02002                                 // if the sortBlock has some sorted faces to render
02003                                 if(ptrSortBlock->_NTriangles != 0)
02004                                 {
02005                                         // Compute Distance to Viewer.
02006                                         /* NB: compute radial distance (with norm()) instead of linear distance 
02007                                                 (DotProduct with front vector) get less "ZSort poping".
02008                                         */
02009                                         CVector         dirToSb= ptrSortBlock->_Center - viewCenter;
02010                                         float           distToViewer= dirToSb.norm();
02011                                         // SortKey change if the center is behind the camera.
02012                                         if(dirToSb * frontVectorNormed<0)
02013                                         {
02014                                                 ptrSortBlock->_SortKey= - distToViewer;
02015                                         }
02016                                         else
02017                                         {
02018                                                 ptrSortBlock->_SortKey= distToViewer;
02019                                         }
02020 
02021                                         // Choose the quadrant for this sortBlock
02022                                         sint            bestDirIdx= 0;
02023                                         float           bestDirVal= -FLT_MAX;
02024                                         // If too near, must take the frontVector as key, to get better sort.
02025                                         // use ptrSortBlock->_SortKey to get correct negative values.
02026                                         if(ptrSortBlock->_SortKey < ptrSortBlock->_Radius)
02027                                         {
02028                                                 dirToSb= frontVectorNormed;
02029                                         }
02030 
02031                                         // NB: no need to normalize dirToSb, because need only to sort with DP
02032                                         // choose the good list of triangles according to quadrant.
02033                                         for(uint dirIdx=0; dirIdx<NL3D_VEGETABLE_NUM_QUADRANT; dirIdx++)
02034                                         {
02035                                                 float   dirVal= CVegetableQuadrant::Dirs[dirIdx] * dirToSb;
02036                                                 if(dirVal>bestDirVal)
02037                                                 {
02038                                                         bestDirVal= dirVal;
02039                                                         bestDirIdx= dirIdx;
02040                                                 }
02041                                         }
02042 
02043                                         // set the result.
02044                                         ptrSortBlock->_QuadrantId= bestDirIdx;
02045 
02046                                         // insert in list to sort.
02047                                         sortVegetSbs.push_back(CSortVSB(ptrSortBlock));
02048 
02049                                         // Debug Quadrants
02050                                         /*p0DebugLines.push_back(ptrSortBlock->_Center);
02051                                         p1DebugLines.push_back(ptrSortBlock->_Center + CVegetableQuadrant::Dirs[bestDirIdx]);*/
02052                                 }
02053 
02054                                 // next sortBlock
02055                                 ptrSortBlock= (CVegetableSortBlock      *)(ptrSortBlock->Next);
02056                         }
02057 
02058                         // next clipBlock to render 
02059                         ptrClipBlock= ptrClipBlock->_RenderNext;
02060                 }
02061 
02062                 // sort!
02063                 // QSort. (I tried, better than radix sort, guckk!!)
02064                 sort(sortVegetSbs.begin(), sortVegetSbs.end());
02065 
02066 
02067                 // setup material for this rdrPass. NB: rendered after (in LayerModels).
02068                 //-------------
02069                 bool    doubleSided= doubleSidedRdrPass(rdrPass);
02070                 // set the 2Sided flag in the material
02071                 _VegetableMaterial.setDoubleSided( doubleSided );
02072 
02073                 // setup the unique material.
02074                 _VegetableMaterial.setBlend(true);
02075                 _VegetableMaterial.setZWrite(false);
02076                 // leave AlphaTest but still kick low alpha values (for fillRate performance)
02077                 _VegetableMaterial.setAlphaTestThreshold(0.1f);
02078 
02079 
02080 
02081                 // order them in Layers.
02082                 //-------------
02083 
02084                 // render from back to front, to keep correct Z order in a single layer.
02085                 for(uint i=0; i<sortVegetSbs.size();i++)
02086                 {
02087                         CVegetableSortBlock     *ptrSortBlock= sortVegetSbs[i].Sb;
02088 
02089                         float   z= ptrSortBlock->_SortKey;
02090                         // compute in which layer must store this SB.
02091                         z= z*_NumZSortBlendLayers / _ZSortLayerDistMax;
02092                         // Avoid a floor(), using an OptFastFloor, but without the OptFastFloorBegin() End() group.
02093                         // => avoid the imprecision with such a trick; *256, then divide the integer by 256.
02094                         sint    layer= NLMISC::OptFastFloor(z*256) >> 8;
02095                         clamp(layer, 0, (sint)_NumZSortBlendLayers-1);
02096 
02097                         // Range in correct layer, according to water ordering
02098                         if(ptrSortBlock->_UnderWater)
02099                                 // range in the correct layermodel (NB: keep the same layer internal order).
02100                                 _ZSortModelLayersUW[layer]->SortBlocks.push_back(ptrSortBlock);
02101                         else
02102                                 _ZSortModelLayers[layer]->SortBlocks.push_back(ptrSortBlock);
02103                 }
02104                 
02105         }
02106 
02107 
02108         // Quit
02109         //--------------------
02110 
02111         // disable VertexProgram.
02112         driver->activeVertexProgram(NULL);
02113 
02114 
02115         // restore Fog.
02116         driver->enableFog(bkupFog);
02117 
02118 
02119         // Debug Quadrants
02120         /*for(uint l=0; l<p0DebugLines.size();l++)
02121         {
02122                 CVector dv= CVector::K;
02123                 CDRU::drawLine(p0DebugLines[l]+dv, p1DebugLines[l]+dv, CRGBA(255,0,0), *driver);
02124         }*/
02125 
02126         // profile: compute number of triangles rendered with vegetable manager.
02127         driver->profileRenderedPrimitives(ppIn, ppOut);
02128         _NumVegetableFaceRendered= ppOut.NTriangles-precNTriRdr;
02129 
02130 }

void NL3D::CVegetableManager::reserveIgAddInstances CVegetableInstanceGroupReserve vegetIgReserve,
CVegetableShape shape,
TVegetableWater  vegetWaterState,
uint  numInstances
 

reserve some instance space in an Ig. nothing is really done here, after doing this for all shapes of your ig, you must call reserveIgCompile()

Parameters:
vegetIgReserve the object where space required for the ig is added

Definition at line 856 of file vegetable_manager.cpp.

References NL3D::CVegetableInstanceGroupReserve::_RdrPass, NL3D::CVertexBuffer::getNumVertices(), getRdrPassInfoForShape(), NL3D::CVegetableInstanceGroupReserve::CVegetableRdrPass::NLightedInstances, NL3D::CVegetableInstanceGroupReserve::CVegetableRdrPass::NTriangles, NL3D::CVegetableInstanceGroupReserve::CVegetableRdrPass::NVertices, NL3D::CVegetableShape::TriangleIndices, uint, and NL3D::CVegetableShape::VB.

Referenced by NL3D::CVegetable::reserveIgAddInstances().

00857 {
00858         bool    instanceLighted;
00859         bool    instanceDoubleSided;
00860         bool    instanceZSort;
00861         bool    destLighted;
00862         bool    precomputeLighting;
00863 
00864         // get correct rdrPass / info
00865         uint    rdrPass;
00866         rdrPass= getRdrPassInfoForShape(shape, vegetWaterState, instanceLighted, instanceDoubleSided, 
00867                 instanceZSort, destLighted, precomputeLighting);
00868 
00869         // veget rdrPass
00870         CVegetableInstanceGroupReserve::CVegetableRdrPass       &vegetRdrPass= vegetIgReserve._RdrPass[rdrPass];
00871 
00872         // Reserve space in the rdrPass.
00873         vegetRdrPass.NVertices+= numInstances * shape->VB.getNumVertices();
00874         vegetRdrPass.NTriangles+= numInstances * shape->TriangleIndices.size()/3;
00875         // if the instances are lighted, reserve space for lighting updates
00876         if(instanceLighted)
00877                 vegetRdrPass.NLightedInstances+= numInstances;
00878 }

void NL3D::CVegetableManager::reserveIgCompile CVegetableInstanceGroup ig,
const CVegetableInstanceGroupReserve vegetIgReserve
 

reserve the space in the ig. nlassert() if the ig is not empty.

See also:
reserveIgAddInstances()

Definition at line 882 of file vegetable_manager.cpp.

References NL3D::CVegetableInstanceGroupReserve::_RdrPass, NL3D::CVegetableInstanceGroup::_RdrPass, NL3D::CVegetableInstanceGroup::_TriangleQuadrantOrderArray, NL3D::CVegetableInstanceGroup::_TriangleQuadrantOrderNumTriangles, NL3D::CVegetableInstanceGroup::_TriangleQuadrantOrders, NLMISC::CObjectVector< sint16, false >::getPtr(), NL3D::CVegetableInstanceGroup::CVegetableRdrPass::LightedInstances, NL3D_VEGETABLE_NRDRPASS, NL3D_VEGETABLE_NUM_QUADRANT, NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT, nlassert, NLMISC::CObjectVector< sint16, false >::resize(), NLMISC::CObjectVector< CVegetableLightedInstance >::resize(), NLMISC::CObjectVector< uint32, false >::resize(), sint16, NLMISC::CObjectVector< sint16, false >::size(), NLMISC::CObjectVector< CVegetableLightedInstance >::size(), NLMISC::CObjectVector< uint32, false >::size(), NL3D::CVegetableInstanceGroup::CVegetableRdrPass::TriangleIndices, NL3D::CVegetableInstanceGroup::CVegetableRdrPass::TriangleLocalIndices, uint, and NL3D::CVegetableInstanceGroup::CVegetableRdrPass::Vertices.

Referenced by NL3D::CPatch::generateTileVegetable().

00883 {
00884         uint    rdrPass;
00885 
00886 
00887         // Check.
00888         //===========
00889         // For all rdrPass of the ig, check empty
00890         for(rdrPass= 0; rdrPass<NL3D_VEGETABLE_NRDRPASS; rdrPass++)
00891         {
00892                 CVegetableInstanceGroup::CVegetableRdrPass      &vegetRdrPass= ig->_RdrPass[rdrPass];
00893                 nlassert(vegetRdrPass.TriangleIndices.size()==0);
00894                 nlassert(vegetRdrPass.TriangleLocalIndices.size()==0);
00895                 nlassert(vegetRdrPass.Vertices.size()==0);
00896                 nlassert(vegetRdrPass.LightedInstances.size()==0);
00897         }
00898         // Do the same for all quadrants of the zsort rdrPass.
00899         nlassert(ig->_TriangleQuadrantOrderArray.size()==0);
00900         nlassert(ig->_TriangleQuadrantOrderNumTriangles==0);
00901 
00902 
00903         // Reserve.
00904         //===========
00905         // For all rdrPass of the ig, reserve.
00906         for(rdrPass= 0; rdrPass<NL3D_VEGETABLE_NRDRPASS; rdrPass++)
00907         {
00908                 CVegetableInstanceGroup::CVegetableRdrPass      &vegetRdrPass= ig->_RdrPass[rdrPass];
00909                 uint    numVertices= vegetIgReserve._RdrPass[rdrPass].NVertices;
00910                 uint    numTris= vegetIgReserve._RdrPass[rdrPass].NTriangles;
00911                 uint    numLightedInstances= vegetIgReserve._RdrPass[rdrPass].NLightedInstances;
00912                 // reserve triangles indices and vertices for this rdrPass.
00913                 vegetRdrPass.TriangleIndices.resize(numTris*3);
00914                 vegetRdrPass.TriangleLocalIndices.resize(numTris*3);
00915                 vegetRdrPass.Vertices.resize(numVertices);
00916                 // reserve ligthedinstances space.
00917                 vegetRdrPass.LightedInstances.resize(numLightedInstances);
00918         }
00919 
00920         // Reserve space for the zsort rdrPass sorting.
00921         uint    numZSortTris= vegetIgReserve._RdrPass[NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT].NTriangles;
00922         // allocate sufficient space for all quadrants (1 alloc for all quadrants).
00923         ig->_TriangleQuadrantOrderArray.resize(numZSortTris * NL3D_VEGETABLE_NUM_QUADRANT);
00924 
00925         // And init ptrs.
00926         if(numZSortTris>0)
00927         {
00928                 sint16  *start= ig->_TriangleQuadrantOrderArray.getPtr();
00929                 // init ptr to each qaudrant
00930                 for(uint i=0; i<NL3D_VEGETABLE_NUM_QUADRANT; i++)
00931                 {
00932                         ig->_TriangleQuadrantOrders[i]= start + i*numZSortTris;
00933                 }
00934         }
00935 }

void NL3D::CVegetableManager::resetNumVegetableFaceRendered  ) 
 

set to 0 the number of faces rendered

Definition at line 2166 of file vegetable_manager.cpp.

References _NumVegetableFaceRendered.

Referenced by NL3D::CLandscape::render().

02167 {
02168         _NumVegetableFaceRendered= 0;
02169 }

void NL3D::CVegetableManager::setDirectionalLight const CRGBA ambient,
const CRGBA diffuse,
const CVector light
 

setup the directional light

Definition at line 1612 of file vegetable_manager.cpp.

References _DirectionalLight, _GlobalAmbient, _GlobalDiffuse, and NLMISC::CVector::normalize().

Referenced by NL3D::CLandscape::setupVegetableLighting().

01613 {
01614         _DirectionalLight= light;
01615         _DirectionalLight.normalize();
01616         // Setup ambient/Diffuse.
01617         _GlobalAmbient= ambient;
01618         _GlobalDiffuse= diffuse;
01619 }

void NL3D::CVegetableManager::setTime double  time  ) 
 

set the current Time (in seconds). For Wind animation

Definition at line 2206 of file vegetable_manager.cpp.

Referenced by NL3D::CLandscape::setVegetableTime().

02207 {
02208         // copy time
02209         _Time= time;
02210 }

void NL3D::CVegetableManager::setUpdateLightingFrequency float  freq  ) 
 

set the frequency of lighting update. If freq==1, ALL lighted igs are updated each second. e.g: if 1/20, then every 20 seconds, all Igs are updated. If you set 0, no update will be done at all (this is the default setup!!).

Definition at line 2280 of file vegetable_manager.cpp.

Referenced by NL3D::CLandscape::setVegetableUpdateLightingFrequency().

02281 {
02282         freq= max(freq, 0.f);
02283         _ULFrequency= freq;
02284 }

void NL3D::CVegetableManager::setUpdateLightingTime double  time  ) 
 

set the vegetable manager System Time (in seconds) This time is used for lighting update, and is independent of setTime()

Definition at line 2221 of file vegetable_manager.cpp.

Referenced by NL3D::CLandscape::setVegetableUpdateLightingTime().

02222 {
02223         _ULTime= time;
02224 }

void NL3D::CVegetableManager::setupRenderStateForBlendLayerModel IDriver driver  )  [private]
 

called by CVegetableBlendLayerModel.

Definition at line 2134 of file vegetable_manager.cpp.

References _BkupFog, _ManagerMatrix, _VegetableMaterial, NL3D::IDriver::activeVertexProgram(), doubleSidedRdrPass(), NL3D::IDriver::enableFog(), NL3D::IDriver::fogEnabled(), NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT, nlverify, NL3D::IDriver::setupMaterial(), NL3D::IDriver::setupModelMatrix(), setupVertexProgramConstants(), and uint.

Referenced by NL3D::CVegetableBlendLayerModel::render().

02135 {
02136         // Setup Global.
02137         //=============
02138         // disable fog, for faster VP.
02139         _BkupFog= driver->fogEnabled();
02140         driver->enableFog(false);
02141 
02142         // set model matrix to the manager matrix.
02143         driver->setupModelMatrix(_ManagerMatrix);
02144 
02145         // setup VP constants.
02146         setupVertexProgramConstants(driver);
02147 
02148         // Setup RdrPass.
02149         //=============
02150         uint    rdrPass= NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT;
02151 
02152         // setup doubleSidedmaterial for this rdrPass.
02153         bool    doubleSided= doubleSidedRdrPass(rdrPass);
02154 
02155         // Activate the unique material (correclty setuped for AlphaBlend in render()).
02156         driver->setupMaterial(_VegetableMaterial);
02157 
02158         // activate Vertex program first.
02159         //nlinfo("\nSTARTVP\n%s\nENDVP\n", _VertexProgram[rdrPass]->getProgram().c_str());
02160         nlverify(driver->activeVertexProgram(_VertexProgram[rdrPass]));
02161 
02162 }

void NL3D::CVegetableManager::setupVertexProgramConstants IDriver driver  )  [private]
 

setup the vertexProgram constants.

Definition at line 1664 of file vegetable_manager.cpp.

References _AngleAxis, _DirectionalLight, _ViewCenter, _WindAnimTime, _WindBendMin, _WindDeltaTable, _WindPower, _WindTable, NL3D_VEGETABLE_BLOCK_BLEND_TRANSITION_DIST, NL3D_VEGETABLE_VP_LUT_SIZE, NLMISC::Pi, NL3D::IDriver::setConstant(), NL3D::IDriver::setConstantMatrix(), uint, NLMISC::CVector2f::x, NLMISC::CVector::x, NLMISC::CVector2f::y, NLMISC::CVector::y, and NLMISC::CVector::z.

Referenced by render(), and setupRenderStateForBlendLayerModel().

01665 {
01666         // Standard
01667         // setup VertexProgram constants.
01668         // c[0..3] take the ModelViewProjection Matrix. After setupModelMatrix();
01669         driver->setConstantMatrix(0, IDriver::ModelViewProjection, IDriver::Identity);
01670         // c[4..7] take the ModelView Matrix. After setupModelMatrix();
01671         driver->setConstantMatrix(4, IDriver::ModelView, IDriver::Identity);
01672         // c[8] take usefull constants.
01673         driver->setConstant(8, 0, 1, 0.5f, 2);
01674         // c[9] take normalized directional light
01675         driver->setConstant(9, _DirectionalLight);
01676         // c[10] take pos of camera
01677         driver->setConstant(10, _ViewCenter);
01678         // c[11] take factor for Blend formula
01679         driver->setConstant(11, -1.f/NL3D_VEGETABLE_BLOCK_BLEND_TRANSITION_DIST, 0, 0, 0);
01680 
01681 
01682 
01683         // Bend.
01684         // c[16]= quaternion axis. w==1, and z must be 0
01685         driver->setConstant( 16, _AngleAxis.x, _AngleAxis.y, _AngleAxis.z, 1);
01686         // c[17]=       {timeAnim, WindPower, WindPower*(1-WindBendMin)/2, 0)}
01687         driver->setConstant( 17, (float)_WindAnimTime, _WindPower, _WindPower*(1-_WindBendMin)/2, 0 );
01688         // c[18]=       High order Taylor cos coefficient: { -1/2, 1/24, -1/720, 1/40320 }
01689         driver->setConstant( 18, -1/2.f, 1/24.f, -1/720.f, 1/40320.f );
01690         // c[19]=       Low order Taylor cos coefficient: { 1, -1/2, 1/24, -1/720 }
01691         driver->setConstant( 19, 1, -1/2.f, 1/24.f, -1/720.f );
01692         // c[20]=       Low order Taylor sin coefficient: { 1, -1/6, 1/120, -1/5040 }
01693         driver->setConstant( 20, 1, -1/6.f, 1/120.f, -1/5040.f );
01694         // c[21]=       Special constant vector for quatToMatrix: { 0, 1, -1, 0 }
01695         driver->setConstant( 21, 0.f, 1.f, -1.f, 0.f);
01696         // c[22]=       {0.5f, Pi, 2*Pi, 1/(2*Pi)}
01697         driver->setConstant( 22, 0.5f, (float)Pi, (float)(2*Pi), (float)(1/(2*Pi)) );
01698         // c[23]=       {NL3D_VEGETABLE_VP_LUT_SIZE, 0, 0, 0}. NL3D_VEGETABLE_VP_LUT_SIZE==64.
01699         driver->setConstant( 23, NL3D_VEGETABLE_VP_LUT_SIZE, 0.f, 0.f, 0.f );
01700 
01701 
01702         // Fill constant. Start at 32.
01703         for(uint i=0; i<NL3D_VEGETABLE_VP_LUT_SIZE; i++)
01704         {
01705                 CVector2f               cur= _WindTable[i];
01706                 CVector2f               delta= _WindDeltaTable[i];
01707                 driver->setConstant( 32+i, cur.x, cur.y, delta.x, delta.y );
01708         }
01709 }

void NL3D::CVegetableManager::setWind const CVector windDir,
float  windFreq,
float  windPower,
float  windBendMin
 

set the Wind for animation. All thoses variables may be modified each frame without penalty.

Parameters:
windDir is the direction of the wind. NB: only XY direction is kept.
windFreq is the frequency for the animation (speed)
windPower is the power of the wind, and is a factor (0..1) of Bend
windBendMin is a value in (0..1) which indicate how much the vegetables are bended at minimum (for very powerfull wind)

Definition at line 2192 of file vegetable_manager.cpp.

References _WindBendMin, _WindDirection, _WindFrequency, _WindPower, NLMISC::clamp(), NLMISC::CVector::normalize(), and NLMISC::CVector::z.

Referenced by NL3D::CLandscape::setVegetableWind().

02193 {
02194         // Keep only XY component of the Wind direction (because VP only support z==0 quaternions).
02195         _WindDirection= windDir;
02196         _WindDirection.z= 0;
02197         _WindDirection.normalize();
02198         // copy setup
02199         _WindFrequency= windFreq;
02200         _WindPower= windPower;
02201         _WindBendMin= windBendMin;
02202         clamp(_WindBendMin, 0, 1);
02203 }

void NL3D::CVegetableManager::swapIgRdrPassHardMode CVegetableInstanceGroup ,
uint  rdrPass
[private]
 

swap the RdrPass type (hard or soft) of the rdrPass of an instance group. vertices are allocated in other VBallocator, copied and freed in the old VBallocator.

Definition at line 1496 of file vegetable_manager.cpp.

References NL3D::CVegetableInstanceGroup::_RdrPass, NL3D::CVegetableVBAllocator::allocateVertex(), NL3D::CVegetableVBAllocator::deleteVertex(), NL3D::CVegetableVBAllocator::flushVertex(), NL3D::CVegetableVBAllocator::getSoftwareVertexBuffer(), getVBAllocatorForRdrPassAndVBHardMode(), NL3D::CVegetableVBAllocator::getVertexPointer(), NL3D::CVertexBuffer::getVertexSize(), NL3D::CVegetableInstanceGroup::CVegetableRdrPass::HardMode, nlassert, NL3D::CVegetableInstanceGroup::CVegetableRdrPass::NTriangles, NL3D::CVegetableInstanceGroup::CVegetableRdrPass::NVertices, NLMISC::CObjectVector< uint32, false >::size(), NL3D::CVegetableInstanceGroup::CVegetableRdrPass::TriangleIndices, NL3D::CVegetableInstanceGroup::CVegetableRdrPass::TriangleLocalIndices, uint, and NL3D::CVegetableInstanceGroup::CVegetableRdrPass::Vertices.

Referenced by addInstance().

01497 {
01498         CVegetableInstanceGroup::CVegetableRdrPass      &vegetRdrPass= ig->_RdrPass[rdrPass];
01499 
01500         // the allocator where vertices come from
01501         CVegetableVBAllocator   &srcAllocator= getVBAllocatorForRdrPassAndVBHardMode(rdrPass, vegetRdrPass.HardMode);
01502         // the allocator where vertices will go
01503         CVegetableVBAllocator   &dstAllocator= getVBAllocatorForRdrPassAndVBHardMode(rdrPass, !vegetRdrPass.HardMode);
01504 
01505         // vertex size
01506         uint    vbSize= srcAllocator.getSoftwareVertexBuffer().getVertexSize();
01507         nlassert(vbSize == dstAllocator.getSoftwareVertexBuffer().getVertexSize());
01508 
01509         // for all vertices of the IG, change of VBAllocator
01510         uint i;
01511         // Do it only for current Vertices setuped!!! because a swapIgRdrPassHardMode awlays arise when the ig is 
01512         // in construcion.
01513         // Hence here, we may have vegetRdrPass.NVertices < vegetRdrPass.Vertices.size() !!!
01514         for(i=0;i<vegetRdrPass.NVertices;i++)
01515         {
01516                 // get idx in src allocator.
01517                 uint    srcId= vegetRdrPass.Vertices[i];
01518                 // allocate a verex in the dst allocator.
01519                 uint    dstId= dstAllocator.allocateVertex();
01520 
01521                 // copy from VBsoft of src to dst.
01522                 void    *vbSrc= srcAllocator.getVertexPointer(srcId);
01523                 void    *vbDst= dstAllocator.getVertexPointer(dstId);
01524                 memcpy(vbDst, vbSrc, vbSize);
01525                 // release src vertex.
01526                 srcAllocator.deleteVertex(srcId);
01527 
01528                 // and copy new dest id in Vertices array.
01529                 vegetRdrPass.Vertices[i]= dstId;
01530 
01531                 // and flush this vertex into VBHard (if dst is aVBHard).
01532                 dstAllocator.flushVertex(dstId);
01533         }
01534 
01535         // For all triangles, bind correct triangles.
01536         nlassert(vegetRdrPass.TriangleIndices.size() == vegetRdrPass.TriangleLocalIndices.size());
01537         // Do it only for current Triangles setuped!!! same reason as vertices
01538         // For all setuped triangles indices
01539         for(i=0;i<vegetRdrPass.NTriangles*3;i++)
01540         {
01541                 // get the index in Vertices.
01542                 uint    localVid= vegetRdrPass.TriangleLocalIndices[i];
01543                 // get the index in new VBufffer (dstAllocator), and copy to TriangleIndices
01544                 vegetRdrPass.TriangleIndices[i]= vegetRdrPass.Vertices[localVid];
01545         }
01546 
01547         // Since change is made, flag the IG rdrpass
01548         vegetRdrPass.HardMode= !vegetRdrPass.HardMode;
01549 }

void NL3D::CVegetableManager::unlockBuffers  ) 
 

unlock any AGP vertex buffers

Definition at line 1633 of file vegetable_manager.cpp.

References _VBHardAllocator, _VBSoftAllocator, uint, and NL3D::CVegetableVBAllocator::unlockBuffer().

Referenced by NL3D::CLandscape::unlockBuffers().

01634 {
01635         // unlock all buffers
01636         for(uint i=0; i <CVegetableVBAllocator::VBTypeCount; i++)
01637         {
01638                 _VBHardAllocator[i].unlockBuffer();
01639                 _VBSoftAllocator[i].unlockBuffer();
01640         }
01641 }

void NL3D::CVegetableManager::updateDriver IDriver driver  ) 
 

must give a driver to the vegetableManager, before any addInstance().

Definition at line 1569 of file vegetable_manager.cpp.

References _LastDriver, _VBHardAllocator, _VBSoftAllocator, initVertexProgram(), NL3D_VEGETABLE_NRDRPASS, uint, and NL3D::CVegetableVBAllocator::updateDriver().

Referenced by render(), and NL3D::CLandscape::updateGlobalsAndLockBuffers().

01570 {
01571         // update all driver
01572         uint i;
01573         for(i=0; i <CVegetableVBAllocator::VBTypeCount; i++)
01574         {
01575                 _VBHardAllocator[i].updateDriver(driver);
01576                 _VBSoftAllocator[i].updateDriver(driver);
01577         }
01578         
01579         // if driver changed, recreate vertex programs
01580         if (driver != _LastDriver)
01581         {
01582                 _LastDriver = driver;
01583                 for(i=0; i <NL3D_VEGETABLE_NRDRPASS; i++)
01584                 {
01585                         initVertexProgram(i);
01586                 }               
01587         }       
01588 }

uint NL3D::CVegetableManager::updateInstanceLighting CVegetableInstanceGroup ig,
uint  rdrPassId,
uint  instanceId
[private]
 

update part of an ig. Do not use/modify _UL* return number of vertices processed (nb vertices of the shape)

Definition at line 2354 of file vegetable_manager.cpp.

References _DirectionalLight, _GlobalAmbient, _GlobalDiffuse, NL3D::CVegetableInstanceGroup::_RdrPass, NLMISC::CRGBA::A, NL3D::CVegetableShape::BestSidedPreComputeLighting, NL3D::CVegetableLightEx::Color, NL3D::computeVegetVertexLighting(), NL3D::computeVegetVertexLightingForceBestSided(), NL3D::CVegetableInstanceGroup::CVegetableLightedInstance::DlmUV, NL3D::CVegetableShape::DoubleSided, NL3D::CVegetableVBAllocator::flushVertex(), NL3D::CVertexBuffer::getNormalOff(), NLMISC::CObjectVector< uint32, false >::getPtr(), NL3D::CVegetableVBAllocator::getSoftwareVertexBuffer(), NL3D::CVertexBuffer::getValueOffEx(), getVBAllocatorForRdrPassAndVBHardMode(), NL3D::CVertexBuffer::getVertexCoordPointer(), NL3D::CVegetableVBAllocator::getVertexPointer(), NL3D::CVegetableInstanceGroup::CVegetableRdrPass::HardMode, NL3D::CVegetableShape::InstanceVertices, NL3D::CVegetableShape::Lighted, NL3D::CVegetableInstanceGroup::CVegetableRdrPass::LightedInstances, NL3D::CVegetableInstanceGroup::CVegetableLightedInstance::MatAmbient, NL3D::CVegetableInstanceGroup::CVegetableLightedInstance::MatDiffuse, NLMISC::CRGBA::modulateFromColorRGBOnly(), NLMISC::CMatrix::mulVector(), NL3D_VEGETABLE_NRDRPASS, NL3D_VEGETABLE_VPPOS_COLOR0, NL3D_VEGETABLE_VPPOS_COLOR1, nlassert, NLMISC::CVector::normalize(), NL3D::CVegetableInstanceGroup::CVegetableLightedInstance::NormalMat, NL3D::CVegetableLightEx::NumLights, NL3D::CVegetableShape::PreComputeLighting, NL3D::CVegetableInstanceGroup::CVegetableLightedInstance::Shape, sint, NLMISC::CObjectVector< CVegetableLightedInstance >::size(), NL3D::CVegetableInstanceGroup::CVegetableLightedInstance::StartIdInRdrPass, NL3D::CVegetableUV8::U, uint, uint32, uint8, NL3D::CVegetableUV8::V, NL3D::CVegetableShape::VB, NL3D::CVegetableInstanceGroup::VegetableLightEx, and NL3D::CVegetableInstanceGroup::CVegetableRdrPass::Vertices.

Referenced by updateLightingIGPart().

02355 {
02356         nlassert(ig);
02357         // get the rdrPass.
02358         nlassert(rdrPassId<NL3D_VEGETABLE_NRDRPASS);
02359         CVegetableInstanceGroup::CVegetableRdrPass      &vegetRdrPass= ig->_RdrPass[rdrPassId];
02360         // get the lighted instance.
02361         nlassert(instanceId<vegetRdrPass.LightedInstances.size());
02362         CVegetableInstanceGroup::CVegetableLightedInstance      &vegetLI= vegetRdrPass.LightedInstances[instanceId];
02363 
02364         // get the shape
02365         CVegetableShape         *shape= vegetLI.Shape;
02366         // it must be lighted.
02367         nlassert(shape->Lighted);
02368         bool    instanceLighted= true;
02369 
02370 
02371         // get ref on the vegetLex.
02372         CVegetableLightEx       &vegetLex= ig->VegetableLightEx;
02373         // Color of pointLights modulated by diffuse.
02374         CRGBA   diffusePL[2];
02375         if(vegetLex.NumLights>=1)
02376         {
02377                 diffusePL[0].modulateFromColorRGBOnly(vegetLI.MatDiffuse, vegetLex.Color[0]);
02378                 if(vegetLex.NumLights>=2)
02379                 {
02380                         diffusePL[1].modulateFromColorRGBOnly(vegetLI.MatDiffuse, vegetLex.Color[1]);
02381                 }
02382         }
02383 
02384         // Recompute lighting
02385         //===========
02386         
02387         // setup for this instance.
02388         //---------
02389         // 2Sided
02390         bool    instanceDoubleSided= shape->DoubleSided;
02391         // Precompute lighting or not??
02392         bool    precomputeLighting= instanceLighted && shape->PreComputeLighting;
02393         // bestSided Precompute lighting or not??
02394         bool    bestSidedPrecomputeLighting= precomputeLighting && shape->BestSidedPreComputeLighting;
02395         // destLighted?
02396         bool    destLighted= instanceLighted && !shape->PreComputeLighting;
02397         // Diffuse and ambient, modulated by current GlobalAmbient and GlobalDiffuse.
02398         CRGBA   primaryRGBA, secondaryRGBA;
02399         primaryRGBA.modulateFromColorRGBOnly(vegetLI.MatDiffuse, _GlobalDiffuse);
02400         secondaryRGBA.modulateFromColorRGBOnly(vegetLI.MatAmbient, _GlobalAmbient);
02401         // get normal matrix
02402         CMatrix         &normalMat= vegetLI.NormalMat;
02403         // array of vertex id to update
02404         uint32          *ptrVid= vegetRdrPass.Vertices.getPtr() + vegetLI.StartIdInRdrPass;
02405         uint            numVertices= shape->InstanceVertices.size();
02406 
02407         // Copy Dynamic Lightmap UV in Alpha part (save memory for an extra cost of 1 VP instruction)
02408         primaryRGBA.A= vegetLI.DlmUV.U;
02409         secondaryRGBA.A= vegetLI.DlmUV.V;
02410 
02411 
02412         // get VertexBuffer info.
02413         CVegetableVBAllocator   *allocator;
02414         allocator= &getVBAllocatorForRdrPassAndVBHardMode(rdrPassId, vegetRdrPass.HardMode);
02415         const CVertexBuffer     &dstVBInfo= allocator->getSoftwareVertexBuffer();
02416 
02417         uint    srcNormalOff= (instanceLighted? shape->VB.getNormalOff() : 0);
02418         uint    dstColor0Off= dstVBInfo.getValueOffEx(NL3D_VEGETABLE_VPPOS_COLOR0);
02419         uint    dstColor1Off= dstVBInfo.getValueOffEx(NL3D_VEGETABLE_VPPOS_COLOR1);
02420         
02421 
02422 
02423         // For all vertices, recompute lighting.
02424         //---------
02425         for(sint i=0; i<(sint)numVertices;i++)
02426         {
02427                 // get the Vertex in the VB.
02428                 uint    vid= ptrVid[i];
02429                 // store in tmp shape.
02430                 shape->InstanceVertices[i]= vid;
02431 
02432                 // Fill this vertex.
02433                 uint8   *srcPtr= (uint8*)shape->VB.getVertexCoordPointer(i);
02434                 uint8   *dstPtr= (uint8*)allocator->getVertexPointer(vid);
02435 
02436 
02437                 // if !precomputeLighting (means destLighted...)
02438                 if(!precomputeLighting)
02439                 {
02440                         // just copy the primary and secondary color
02441                         *(CRGBA*)(dstPtr + dstColor0Off)= primaryRGBA;
02442                         *(CRGBA*)(dstPtr + dstColor1Off)= secondaryRGBA;
02443                 }
02444                 else
02445                 {
02446                         nlassert(!destLighted);
02447 
02448                         // compute normal.
02449                         CVector         rotNormal= normalMat.mulVector( *(CVector*)(srcPtr + srcNormalOff) );
02450                         // must normalize() because scale is possible.
02451                         rotNormal.normalize();
02452 
02453                         // Do the compute.
02454                         if(!bestSidedPrecomputeLighting)
02455                         {
02456                                 computeVegetVertexLighting(rotNormal, 
02457                                         _DirectionalLight, primaryRGBA, secondaryRGBA, 
02458                                         vegetLex, diffusePL, (CRGBA*)(dstPtr + dstColor0Off) );
02459                         }
02460                         else
02461                         {
02462                                 computeVegetVertexLightingForceBestSided(rotNormal, 
02463                                         _DirectionalLight, primaryRGBA, secondaryRGBA, 
02464                                         vegetLex, diffusePL, (CRGBA*)(dstPtr + dstColor0Off) );
02465                         }
02466 
02467                 }
02468 
02469                 // flust the vertex in AGP.
02470                 allocator->flushVertex(vid);
02471         }
02472 
02473 
02474         // numVertices vertices are updated
02475         return numVertices;
02476 }

void NL3D::CVegetableManager::updateLighting  ) 
 

update the lighting of Igs, within a certain amount of time. You MUST enclose calls to updateLighting() with lockBuffers() / unlockBuffers().

Definition at line 2228 of file vegetable_manager.cpp.

References _ULNTotalVertices, _ULNVerticesToUpdate, doUpdateLighting(), and min.

Referenced by NL3D::CLandscape::refine().

02229 {
02230         // first time in this method??
02231         if(!_ULPrecTimeInit)
02232         {
02233                 _ULPrecTimeInit= true;
02234                 _ULPrecTime= _ULTime;
02235         }
02236         // compute delta time from last update.
02237         float dt= float(_ULTime - _ULPrecTime);
02238         _ULPrecTime= _ULTime;
02239 
02240         // compute number of vertices to update.
02241         _ULNVerticesToUpdate+= dt*_ULFrequency * _ULNTotalVertices;
02242         // maximize, so at max, it computes all Igs, just one time.
02243         _ULNVerticesToUpdate= min(_ULNVerticesToUpdate, (float)_ULNTotalVertices);
02244 
02245         // go.
02246         doUpdateLighting();
02247 }

void NL3D::CVegetableManager::updateLightingAll  ) 
 

like updateLighting(), but update ALL vegetable You MUST enclose calls to updateLighting() with lockBuffers() / unlockBuffers().

Definition at line 2251 of file vegetable_manager.cpp.

References _ULNTotalVertices, _ULNVerticesToUpdate, and doUpdateLighting().

Referenced by NL3D::CLandscape::updateLightingAll().

02252 {
02253         // maximize, so at max, it computes all Igs
02254         _ULNVerticesToUpdate= (float)_ULNTotalVertices;
02255 
02256         // go.
02257         doUpdateLighting();
02258 }

bool NL3D::CVegetableManager::updateLightingIGPart  )  [private]
 

update part of the RootIg, according to _ULNVerticesToUpdate (while > 0) if all Ig is updated, return true and _ULCurrentIgRdrPass and _ULCurrentIgInstance is updated.

Definition at line 2288 of file vegetable_manager.cpp.

References NL3D::CVegetableInstanceGroup::_RdrPass, _ULCurrentIgInstance, _ULCurrentIgRdrPass, _ULNVerticesToUpdate, _ULRootIg, NL3D::CVegetableLightEx::computeCurrentColors(), NL3D::CVegetableInstanceGroup::CVegetableRdrPass::LightedInstances, NL3D_VEGETABLE_NRDRPASS, nlassert, NLMISC::CObjectVector< CVegetableLightedInstance >::size(), updateInstanceLighting(), and NL3D::CVegetableInstanceGroup::VegetableLightEx.

Referenced by doUpdateLighting().

02289 {
02290         nlassert(_ULRootIg);
02291 
02292 
02293         // First, update lighting info global to the ig, ie update current 
02294         // colros of the PointLights which influence the ig.
02295         _ULRootIg->VegetableLightEx.computeCurrentColors();
02296 
02297         // while there is some vertices to update
02298         while(_ULNVerticesToUpdate>0)
02299         {
02300                 // if all rdrPass of the ig are processed.
02301                 if(_ULCurrentIgRdrPass>= NL3D_VEGETABLE_NRDRPASS)
02302                 {
02303                         // All this Ig is updated.
02304                         _ULCurrentIgRdrPass= 0;
02305                         _ULCurrentIgInstance= 0;
02306                         // skip to next Ig.
02307                         return true;
02308                 }
02309                 CVegetableInstanceGroup::CVegetableRdrPass      &vegetRdrPass= _ULRootIg->_RdrPass[_ULCurrentIgRdrPass];
02310 
02311                 // if all instances are processed for this pass (especially if size()==0 !!)
02312                 if(_ULCurrentIgInstance>= vegetRdrPass.LightedInstances.size())
02313                 {
02314                         // skip to the next rdrPass.
02315                         _ULCurrentIgRdrPass++;
02316                         _ULCurrentIgInstance= 0;
02317                         continue;
02318                 }
02319 
02320                 // Process this instance.
02321                 _ULNVerticesToUpdate-= updateInstanceLighting(_ULRootIg, _ULCurrentIgRdrPass, _ULCurrentIgInstance);
02322 
02323                 // next instance.
02324                 _ULCurrentIgInstance++;
02325 
02326                 // if all instances are processed for this pass
02327                 if(_ULCurrentIgInstance>= vegetRdrPass.LightedInstances.size())
02328                 {
02329                         // skip to the next rdrPass.
02330                         _ULCurrentIgRdrPass++;
02331                         _ULCurrentIgInstance= 0;
02332                 }
02333         }
02334 
02335         // If all rdrPass of the ig are processed.
02336         if(_ULCurrentIgRdrPass>= NL3D_VEGETABLE_NRDRPASS)
02337         {
02338                 // All this Ig is updated.
02339                 _ULCurrentIgRdrPass= 0;
02340                 _ULCurrentIgInstance= 0;
02341                 // skip to next Ig.
02342                 return true;
02343         }
02344         else
02345         {
02346                 // The Ig is not entirely updated.
02347                 return false;
02348         }
02349 
02350 }


Friends And Related Function Documentation

friend class CVegetableBlendLayerModel [friend]
 

Definition at line 287 of file vegetable_manager.h.


Field Documentation

CVector NL3D::CVegetableManager::_AngleAxis [private]
 

Definition at line 378 of file vegetable_manager.h.

Referenced by render(), and setupVertexProgramConstants().

bool NL3D::CVegetableManager::_BkupFog [private]
 

Definition at line 380 of file vegetable_manager.h.

Referenced by exitRenderStateForBlendLayerModel(), and setupRenderStateForBlendLayerModel().

CTessList<CVegetableClipBlock> NL3D::CVegetableManager::_ClipBlockList [private]
 

Definition at line 294 of file vegetable_manager.h.

Referenced by createIg(), deleteIg(), and render().

NLMISC::CBlockMemory<CVegetableClipBlock> NL3D::CVegetableManager::_ClipBlockMemory [private]
 

Definition at line 289 of file vegetable_manager.h.

Referenced by createClipBlock(), and deleteClipBlock().

float NL3D::CVegetableManager::_CosTable[NL3D_VEGETABLE_VP_LUT_SIZE] [private]
 

Definition at line 366 of file vegetable_manager.h.

CVector NL3D::CVegetableManager::_DirectionalLight [private]
 

Definition at line 316 of file vegetable_manager.h.

Referenced by addInstance(), CVegetableManager(), setDirectionalLight(), setupVertexProgramConstants(), and updateInstanceLighting().

CTessList<CVegetableClipBlock> NL3D::CVegetableManager::_EmptyClipBlockList [private]
 

Definition at line 296 of file vegetable_manager.h.

Referenced by createClipBlock(), createIg(), deleteClipBlock(), and deleteIg().

NLMISC::CRGBA NL3D::CVegetableManager::_GlobalAmbient [private]
 

Definition at line 317 of file vegetable_manager.h.

Referenced by addInstance(), CVegetableManager(), setDirectionalLight(), and updateInstanceLighting().

NLMISC::CRGBA NL3D::CVegetableManager::_GlobalDiffuse [private]
 

Definition at line 318 of file vegetable_manager.h.

Referenced by addInstance(), CVegetableManager(), setDirectionalLight(), and updateInstanceLighting().

NLMISC::CBlockMemory<CVegetableInstanceGroup> NL3D::CVegetableManager::_InstanceGroupMemory [private]
 

Definition at line 291 of file vegetable_manager.h.

Referenced by createIg(), and deleteIg().

NLMISC::CRefPtr<IDriver> NL3D::CVegetableManager::_LastDriver [private]
 

Definition at line 448 of file vegetable_manager.h.

Referenced by initVertexProgram(), and updateDriver().

NLMISC::CMatrix NL3D::CVegetableManager::_ManagerMatrix [private]
 

Definition at line 382 of file vegetable_manager.h.

Referenced by render(), and setupRenderStateForBlendLayerModel().

uint NL3D::CVegetableManager::_NumVegetableFaceRendered [private]
 

profile

Definition at line 322 of file vegetable_manager.h.

Referenced by CVegetableManager(), getNumVegetableFaceRendered(), render(), NL3D::CVegetableBlendLayerModel::render(), and resetNumVegetableFaceRendered().

uint NL3D::CVegetableManager::_NumZSortBlendLayers [private]
 

For Alpha Blend rdrPass, ordering into layers.

Definition at line 392 of file vegetable_manager.h.

Referenced by createVegetableBlendLayersModels(), CVegetableManager(), render(), and ~CVegetableManager().

TShapeMap NL3D::CVegetableManager::_ShapeMap [private]
 

Definition at line 302 of file vegetable_manager.h.

NLMISC::CBlockMemory<CVegetableSortBlock> NL3D::CVegetableManager::_SortBlockMemory [private]
 

Definition at line 290 of file vegetable_manager.h.

Referenced by createSortBlock(), and deleteSortBlock().

double NL3D::CVegetableManager::_Time [private]
 

Definition at line 360 of file vegetable_manager.h.

uint NL3D::CVegetableManager::_ULCurrentIgInstance [private]
 

update lighting according to _ULNVerticesToUpdate

Definition at line 428 of file vegetable_manager.h.

Referenced by CVegetableManager(), deleteIg(), and updateLightingIGPart().

uint NL3D::CVegetableManager::_ULCurrentIgRdrPass [private]
 

Current instance to render in the first ig to update: rdrpass/instanceId.

Definition at line 427 of file vegetable_manager.h.

Referenced by CVegetableManager(), deleteIg(), and updateLightingIGPart().

float NL3D::CVegetableManager::_ULFrequency [private]
 

Frequency of update.

Definition at line 419 of file vegetable_manager.h.

uint NL3D::CVegetableManager::_ULNTotalVertices [private]
 

Sum of all ig vertices to update.

Definition at line 423 of file vegetable_manager.h.

Referenced by addInstance(), CVegetableManager(), deleteIg(), updateLighting(), and updateLightingAll().

float NL3D::CVegetableManager::_ULNVerticesToUpdate [private]
 

Current number of vertices to update. If negative, I have some advance.

Definition at line 421 of file vegetable_manager.h.

Referenced by CVegetableManager(), doUpdateLighting(), updateLighting(), updateLightingAll(), and updateLightingIGPart().

double NL3D::CVegetableManager::_ULPrecTime [private]
 

NB: we update at the precision of a shape (a dozen of vertices).

Definition at line 414 of file vegetable_manager.h.

bool NL3D::CVegetableManager::_ULPrecTimeInit [private]
 

update lighting according to _ULNVerticesToUpdate

Definition at line 415 of file vegetable_manager.h.

CVegetableInstanceGroup* NL3D::CVegetableManager::_ULRootIg [private]
 

the priority list of ig to update

Definition at line 425 of file vegetable_manager.h.

Referenced by addInstance(), CVegetableManager(), deleteIg(), doUpdateLighting(), and updateLightingIGPart().

double NL3D::CVegetableManager::_ULTime [private]
 

update lighting according to _ULNVerticesToUpdate

Definition at line 416 of file vegetable_manager.h.

CVegetableVBAllocator NL3D::CVegetableManager::_VBHardAllocator[CVegetableVBAllocator::VBTypeCount] [private]
 

Definition at line 306 of file vegetable_manager.h.

Referenced by CVegetableManager(), getVBAllocatorForRdrPassAndVBHardMode(), lockBuffers(), unlockBuffers(), and updateDriver().

CVegetableVBAllocator NL3D::CVegetableManager::_VBSoftAllocator[CVegetableVBAllocator::VBTypeCount] [private]
 

Definition at line 308 of file vegetable_manager.h.

Referenced by CVegetableManager(), getVBAllocatorForRdrPassAndVBHardMode(), lockBuffers(), unlockBuffers(), and updateDriver().

CMaterial NL3D::CVegetableManager::_VegetableMaterial [private]
 

Definition at line 314 of file vegetable_manager.h.

Referenced by CVegetableManager(), loadTexture(), render(), and setupRenderStateForBlendLayerModel().

CVertexProgram* NL3D::CVegetableManager::_VertexProgram[NL3D_VEGETABLE_NRDRPASS] [private]
 

Definition at line 310 of file vegetable_manager.h.

CVector NL3D::CVegetableManager::_ViewCenter [private]
 

Definition at line 379 of file vegetable_manager.h.

Referenced by render(), and setupVertexProgramConstants().

double NL3D::CVegetableManager::_WindAnimTime [private]
 

Definition at line 363 of file vegetable_manager.h.

Referenced by CVegetableManager(), render(), and setupVertexProgramConstants().

float NL3D::CVegetableManager::_WindBendMin [private]
 

Definition at line 358 of file vegetable_manager.h.

Referenced by CVegetableManager(), render(), setupVertexProgramConstants(), and setWind().

NLMISC::CVector2f NL3D::CVegetableManager::_WindDeltaTable[NL3D_VEGETABLE_VP_LUT_SIZE] [private]
 

Definition at line 369 of file vegetable_manager.h.

Referenced by render(), and setupVertexProgramConstants().

CVector NL3D::CVegetableManager::_WindDirection [private]
 

Definition at line 355 of file vegetable_manager.h.

Referenced by CVegetableManager(), render(), and setWind().

float NL3D::CVegetableManager::_WindFrequency [private]
 

Definition at line 356 of file vegetable_manager.h.

Referenced by CVegetableManager(), render(), and setWind().

float NL3D::CVegetableManager::_WindPower [private]
 

Definition at line 357 of file vegetable_manager.h.

Referenced by CVegetableManager(), render(), setupVertexProgramConstants(), and setWind().

double NL3D::CVegetableManager::_WindPrecRenderTime [private]
 

Definition at line 361 of file vegetable_manager.h.

Referenced by CVegetableManager(), and render().

NLMISC::CVector2f NL3D::CVegetableManager::_WindTable[NL3D_VEGETABLE_VP_LUT_SIZE] [private]
 

Definition at line 368 of file vegetable_manager.h.

Referenced by render(), and setupVertexProgramConstants().

float NL3D::CVegetableManager::_ZSortLayerDistMax [private]
 

Definition at line 393 of file vegetable_manager.h.

Referenced by render().

std::vector<CVegetableBlendLayerModel*> NL3D::CVegetableManager::_ZSortModelLayers [private]
 

Definition at line 395 of file vegetable_manager.h.

Referenced by createVegetableBlendLayersModels(), CVegetableManager(), render(), and ~CVegetableManager().

std::vector<CVegetableBlendLayerModel*> NL3D::CVegetableManager::_ZSortModelLayersUW [private]
 

Definition at line 397 of file vegetable_manager.h.

Referenced by createVegetableBlendLayersModels(), CVegetableManager(), render(), and ~CVegetableManager().

CScene* NL3D::CVegetableManager::_ZSortScene [private]
 

Definition at line 394 of file vegetable_manager.h.

Referenced by createVegetableBlendLayersModels(), and ~CVegetableManager().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 08:22:15 2004 for NeL by doxygen 1.3.6