# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

vegetable_blend_layer_model.cpp

Go to the documentation of this file.
00001 
00007 /* Copyright, 2001 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #include "std3d.h"
00027 
00028 #include "3d/vegetable_blend_layer_model.h"
00029 #include "3d/vegetable_manager.h"
00030 #include "3d/vegetable_sort_block.h"
00031 #include "3d/render_trav.h"
00032 #include "3d/clip_trav.h"
00033 #include "nel/misc/debug.h"
00034 #include "nel/misc/hierarchical_timer.h"
00035 
00036 
00037 using namespace NLMISC;
00038 
00039 namespace NL3D {
00040 
00041 
00042 // ***************************************************************************
00043 void    CVegetableBlendLayerModel::registerBasic()
00044 {
00045         CMOT::registerModel(VegetableBlendLayerModelId, TransformId, CVegetableBlendLayerModel::creator);
00046         CMOT::registerObs(RenderTravId, VegetableBlendLayerModelId, CVegetableBlendLayerRenderObs::creator);
00047         CMOT::registerObs(ClipTravId, VegetableBlendLayerModelId, CVegetableBlendLayerClipObs::creator);
00048 }
00049 
00050 
00051 // ***************************************************************************
00052 CVegetableBlendLayerModel::CVegetableBlendLayerModel()
00053 {
00054         VegetableManager= NULL;
00055 
00056         // The model must always be renderer in transparency pass only.
00057         setTransparency(true);
00058         setOpacity(false);
00059 
00060         // The model is of course renderable
00061         CTransform::setIsRenderable(true);
00062 }
00063 
00064 
00065 // ***************************************************************************
00066 void    CVegetableBlendLayerModel::initModel()
00067 {
00068         CTransform::initModel();
00069 
00070         _HrcObs= safe_cast<CTransformHrcObs     *>(getObs(HrcTravId));
00071 }
00072 
00073 
00074 // ***************************************************************************
00075 void    CVegetableBlendLayerModel::setWorldPos(const CVector &pos)
00076 {
00077         // setup directly in the hrcObs the local matrix.
00078         _HrcObs->LocalMatrix.setPos(pos);
00079 
00080         // setup directly in the hrcObs the world matrix.
00081         _HrcObs->WorldMatrix.setPos(pos);
00082         
00083 }
00084 
00085 
00086 // ***************************************************************************
00087 void    CVegetableBlendLayerModel::render(IDriver *driver)
00088 {
00089         H_AUTO( NL3D_Vegetable_Render );
00090 
00091         nlassert(VegetableManager);
00092 
00093         if(SortBlocks.size()==0)
00094                 return;
00095 
00096         // Setup VegetableManager renderState (like pre-setuped material)
00097         //==================
00098         VegetableManager->setupRenderStateForBlendLayerModel(driver);
00099 
00100 
00101         // Render SortBlocks of this layer
00102         //==================
00103         uint    rdrPass= NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT;
00104 
00105         // first time, activate the hard VB.
00106         bool    precVBHardMode= true;
00107         CVegetableVBAllocator   *vbAllocator= &VegetableManager->getVBAllocatorForRdrPassAndVBHardMode(rdrPass, 1);
00108         vbAllocator->activate();
00109 
00110         // profile
00111         CPrimitiveProfile       ppIn, ppOut;
00112         driver->profileRenderedPrimitives(ppIn, ppOut);
00113         uint    precNTriRdr= ppOut.NTriangles;
00114 
00115         // render from back to front the list setuped in CVegetableManager::render()
00116         for(uint i=0; i<SortBlocks.size();i++)
00117         {
00118                 CVegetableSortBlock     *ptrSortBlock= SortBlocks[i];
00119 
00120                 // change of VertexBuffer (soft / hard) if needed.
00121                 if(ptrSortBlock->ZSortHardMode != precVBHardMode)
00122                 {
00123                         // setup new VB for hardMode.
00124                         CVegetableVBAllocator   *vbAllocator= &VegetableManager->getVBAllocatorForRdrPassAndVBHardMode(rdrPass, ptrSortBlock->ZSortHardMode);
00125                         vbAllocator->activate();
00126                         // prec.
00127                         precVBHardMode= ptrSortBlock->ZSortHardMode;
00128                 }
00129 
00130                 // render him. we are sure that size > 0, because tested before.
00131                 driver->renderSimpleTriangles(
00132                         ptrSortBlock->_SortedTriangleIndices[ptrSortBlock->_QuadrantId], 
00133                         ptrSortBlock->_NTriangles);
00134         }
00135 
00136         // add number of triangles rendered with vegetable manager.
00137         driver->profileRenderedPrimitives(ppIn, ppOut);
00138         VegetableManager->_NumVegetableFaceRendered+= ppOut.NTriangles-precNTriRdr;
00139 
00140 
00141         // refresh list now!
00142         // We must do it here, because if CVegetableManager::render() is no more called (eg: disabled),
00143         // then the blend layers models must do nothing.
00144         SortBlocks.clear();
00145 
00146 
00147         // Reset RenderState.
00148         //==================
00149         VegetableManager->exitRenderStateForBlendLayerModel(driver);
00150 
00151 }
00152 
00153 
00154 // ***************************************************************************
00155 void    CVegetableBlendLayerRenderObs::traverse(IObs *caller)
00156 {
00157         CRenderTrav             *rTrav= safe_cast<CRenderTrav*>(Trav);
00158         safe_cast<CVegetableBlendLayerModel*>(Model)->render(rTrav->getDriver());
00159 }
00160 
00161 
00162 } // NL3D