NL3D::CVertexStreamManager Class Reference

#include <vertex_stream_manager.h>


Detailed Description

A class used to fill a virtual Vertexbuffer, while rendering it, avoiding Stalls during Locks. Actually multiple versions of VertexBuffer are kept and the swapVBHard() method cycles around them. NB: it is used for instance to render all skins of a CSkeletonModel, in just one CVertexStreamManager. This allow optimisation because less VBuffer activation is needed.
Author:
Lionel Berenguier

Nevrax France

Date:
2002

Definition at line 50 of file vertex_stream_manager.h.

Public Member Functions

 CVertexStreamManager ()
 Constructor.

 ~CVertexStreamManager ()
Rendering. Those method assert if init() not called with correct parameters.
void activate ()
 activate the currentVBhard as the current VB in the driver, for future rendering

uint8lock ()
 lock the currently activated VBHard, for future filling

void swapVBHard ()
void unlock (uint numVertices)
 unlock the currently activated VBHard. Tell how many vertices have changed.

Init/Setup
IDrivergetDriver () const
 return the driver used.

uint getMaxVertices () const
 get max vertices the Buffer allows.

uint getNumVBHard () const
 get the numVBhard used (Nb: if !vbHardMode(), still returns the argument passed in init(), ie not 0 or 1)

uint getVertexFormat () const
 get the vertexFormat

uint getVertexSize () const
 get the vertexSize

void init (IDriver *driver, uint vertexFormat, uint maxVertices, uint numVBHard, const std::string &vbName)
void release ()
 release the VBHard. init() can be called after this.

bool vbHardMode () const
 true if vbHard (fast) mode.


Private Attributes

uint _CurentVBHard
NLMISC::CRefPtr< IDriver_Driver
bool _InitOk
uint _MaxVertices
uint _NumVBHard
std::vector< NLMISC::CRefPtr<
IVertexBufferHard > > 
_VBHard
bool _VBHardMode
CVertexBuffer _VBSoft
uint _VertexFormat
uint _VertexSize


Constructor & Destructor Documentation

NL3D::CVertexStreamManager::CVertexStreamManager  ) 
 

Constructor.

Definition at line 39 of file vertex_stream_manager.cpp.

References _CurentVBHard, _InitOk, and _VBHardMode.

00040 {
00041         _InitOk= false;
00042         _VBHardMode= false;
00043         _VertexFormat= 0;
00044         _VertexSize= 0;
00045         _MaxVertices= 0;
00046         _CurentVBHard= 0;
00047         _NumVBHard= 0;
00048 }

NL3D::CVertexStreamManager::~CVertexStreamManager  ) 
 

Definition at line 50 of file vertex_stream_manager.cpp.

References release().

00051 {
00052         release();
00053 }


Member Function Documentation

void NL3D::CVertexStreamManager::activate  ) 
 

activate the currentVBhard as the current VB in the driver, for future rendering

Definition at line 178 of file vertex_stream_manager.cpp.

References _CurentVBHard, _InitOk, _VBHardMode, H_AUTO, and nlassert.

Referenced by NL3D::CLodCharacterManager::endRender(), NL3D::CSkeletonModel::renderShadowSkins(), and NL3D::CSkeletonModel::renderSkinList().

00179 {
00180         H_AUTO( NL3D_VertexStreamManager_activate )
00181         nlassert(_InitOk);
00182         
00183         if(_VBHardMode)
00184                 _Driver->activeVertexBufferHard(_VBHard[_CurentVBHard]);
00185         else
00186                 _Driver->activeVertexBuffer(_VBSoft);
00187 }

IDriver* NL3D::CVertexStreamManager::getDriver void   )  const [inline]
 

return the driver used.

Definition at line 76 of file vertex_stream_manager.h.

Referenced by NL3D::CLodCharacterManager::addRenderCharacterKey(), NL3D::CLodCharacterManager::beginRender(), NL3D::CLodCharacterManager::endRender(), and NL3D::CRenderTrav::traverse().

00076 {return _Driver;}

uint NL3D::CVertexStreamManager::getMaxVertices  )  const [inline]
 

get max vertices the Buffer allows.

Definition at line 82 of file vertex_stream_manager.h.

References uint.

Referenced by NL3D::CLodCharacterManager::beginRender(), NL3D::CSkeletonModel::renderShadowSkins(), and NL3D::CSkeletonModel::renderSkinList().

00082 {return _MaxVertices;}

uint NL3D::CVertexStreamManager::getNumVBHard  )  const [inline]
 

get the numVBhard used (Nb: if !vbHardMode(), still returns the argument passed in init(), ie not 0 or 1)

Definition at line 74 of file vertex_stream_manager.h.

References uint.

Referenced by NL3D::CLodCharacterManager::beginRender().

00074 {return _NumVBHard;}

uint NL3D::CVertexStreamManager::getVertexFormat void   )  const [inline]
 

get the vertexFormat

Definition at line 78 of file vertex_stream_manager.h.

References uint.

00078 {return _VertexFormat;}

uint NL3D::CVertexStreamManager::getVertexSize void   )  const [inline]
 

get the vertexSize

Definition at line 80 of file vertex_stream_manager.h.

References uint.

Referenced by NL3D::CLodCharacterManager::beginRender(), NL3D::CSkeletonModel::renderShadowSkins(), and NL3D::CSkeletonModel::renderSkinList().

00080 {return _VertexSize;}

void NL3D::CVertexStreamManager::init IDriver driver,
uint  vertexFormat,
uint  maxVertices,
uint  numVBHard,
const std::string &  vbName
 

init the manager with a driver, allocate the VBHards, and setup the vertexFormat. Must call each time the drive changes. NB: if VBufferHard creation fail (not supported etc...), then a VBSoft is created instead (and just one since not usefull)

Parameters:
numVBHard the number of VBHard to create. The max you set, the lower lock you'll have.
vbName base, for Lock profiling

Definition at line 56 of file vertex_stream_manager.cpp.

References _CurentVBHard, _InitOk, _VBHardMode, NL3D::CVertexBuffer::getUVRouting(), NL3D::CVertexBuffer::getValueTypePointer(), NL3D::CVertexBuffer::getVertexFormat(), NL3D::CVertexBuffer::getVertexSize(), nlassert, release(), NL3D::CVertexBuffer::setNumVertices(), NL3D::CVertexBuffer::setUVRouting(), NL3D::CVertexBuffer::setVertexFormat(), and uint.

Referenced by NL3D::CLodCharacterManager::beginRender(), and NL3D::CRenderTrav::traverse().

00057 {
00058         nlassert(driver);
00059         // clean before.
00060         release();
00061 
00062         // Create VBHard placeholder
00063         if(numVBHard==0 || maxVertices==0)
00064                 return;
00065         _NumVBHard= numVBHard;
00066         _VBHard.resize(_NumVBHard, NULL);
00067 
00068         // setup, => correct for possible release below
00069         _Driver= driver;
00070 
00071         // setup the VB soft, for easy setup
00072         _VBSoft.setVertexFormat(vertexFormat);
00073 
00074         // For the moment, all UV channel are routed to UV0
00075         uint i;
00076         for (i=0; i<CVertexBuffer::MaxStage; i++)
00077                 _VBSoft.setUVRouting (i, 0);
00078 
00079         // create the VBHard, if possible
00080         _VBHardMode= true;
00081         for(i=0;i<_NumVBHard;i++)
00082         {
00083                 _VBHard[i]= _Driver->createVertexBufferHard(_VBSoft.getVertexFormat(), _VBSoft.getValueTypePointer(), maxVertices, IDriver::VBHardAGP, _VBSoft.getUVRouting());
00084                 // if filas, release all, and quit
00085                 if(_VBHard[i]==NULL)
00086                 {
00087                         _VBHardMode= false;
00088                         break;
00089                 }
00090                 // ok, set name for lock profiling
00091                 else
00092                 {
00093                         _VBHard[i]->setName(vbName + NLMISC::toString(i));
00094                 }
00095         }
00096 
00097         // if fails to create vbHard, abort, and create only one vbSoft
00098         if(!_VBHardMode)
00099         {
00100                 // release all vbhard created
00101                 for(uint i=0;i<_NumVBHard;i++)
00102                 {
00103                         if(_VBHard[i])
00104                                 _Driver->deleteVertexBufferHard(_VBHard[i]);
00105                 }
00106                 _VBHard.clear();
00107 
00108                 // create the Soft One
00109                 _VBSoft.setNumVertices(maxVertices);
00110         }
00111 
00112         // init misc
00113         _InitOk= true;
00114         _VertexFormat= _VBSoft.getVertexFormat();
00115         _VertexSize= _VBSoft.getVertexSize();
00116         _MaxVertices= maxVertices;
00117         _CurentVBHard= 0;
00118 
00119         // release the VBsoft if in vbHardMode (no more used)
00120         if(_VBHardMode)
00121         {
00122                 contReset(_VBSoft);
00123         }
00124 }

uint8 * NL3D::CVertexStreamManager::lock  ) 
 

lock the currently activated VBHard, for future filling

Definition at line 155 of file vertex_stream_manager.cpp.

References _CurentVBHard, _InitOk, _VBHardMode, NL3D::CVertexBuffer::getVertexCoordPointer(), H_AUTO, nlassert, and uint8.

Referenced by NL3D::CLodCharacterManager::addRenderCharacterKey(), NL3D::CSkeletonModel::renderShadowSkins(), and NL3D::CSkeletonModel::renderSkinList().

00156 {
00157         H_AUTO( NL3D_VertexStreamManager_lock )
00158         nlassert(_InitOk);
00159 
00160         if(_VBHardMode)
00161                 return  (uint8*)_VBHard[_CurentVBHard]->lock();
00162         else
00163                 return  (uint8*)_VBSoft.getVertexCoordPointer();
00164 }

void NL3D::CVertexStreamManager::release  ) 
 

release the VBHard. init() can be called after this.

Definition at line 126 of file vertex_stream_manager.cpp.

References _CurentVBHard, _InitOk, _VBHardMode, and uint.

Referenced by NL3D::CLodCharacterManager::beginRender(), init(), NL3D::CNELU::releaseDriver(), NL3D::CLodCharacterManager::reset(), NL3D::CRenderTrav::traverse(), and ~CVertexStreamManager().

00127 {
00128         // release driver/VBHard
00129         if(_Driver)
00130         {
00131                 for(uint i=0;i<_NumVBHard;i++)
00132                 {
00133                         if(_VBHard[i])
00134                                 _Driver->deleteVertexBufferHard(_VBHard[i]);
00135                         _VBHard[i]= NULL;
00136                 }
00137                 _Driver= NULL;
00138         }
00139 
00140         _VBHard.clear();
00141 
00142         // release VBSoft
00143         contReset(_VBSoft);
00144 
00145         // misc
00146         _InitOk= false;
00147         _VBHardMode= false;
00148         _VertexFormat= 0;
00149         _VertexSize= 0;
00150         _MaxVertices= 0;
00151         _CurentVBHard= 0;
00152         _NumVBHard= 0;
00153 }

void NL3D::CVertexStreamManager::swapVBHard  ) 
 

Swap to the next VBHard. This allow some parralelism, since CPU fill one VBHard while the other is rendered NB: no-op if the vertex stream manager falls down to the VBSoft solution.

Definition at line 189 of file vertex_stream_manager.cpp.

References _CurentVBHard, _InitOk, _VBHardMode, and nlassert.

Referenced by NL3D::CLodCharacterManager::endRender(), NL3D::CSkeletonModel::renderShadowSkins(), and NL3D::CSkeletonModel::renderSkinList().

00190 {
00191         nlassert(_InitOk);
00192         
00193         if(_VBHardMode)
00194         {
00195                 _CurentVBHard++;
00196                 _CurentVBHard= _CurentVBHard%_NumVBHard;
00197         }
00198 }

void NL3D::CVertexStreamManager::unlock uint  numVertices  ) 
 

unlock the currently activated VBHard. Tell how many vertices have changed.

Definition at line 166 of file vertex_stream_manager.cpp.

References _CurentVBHard, _InitOk, _VBHardMode, H_AUTO, nlassert, and uint.

Referenced by NL3D::CLodCharacterManager::endRender(), NL3D::CSkeletonModel::renderShadowSkins(), and NL3D::CSkeletonModel::renderSkinList().

00167 {
00168         H_AUTO( NL3D_VertexStreamManager_unlock )
00169         nlassert(_InitOk);
00170         
00171         if(_VBHardMode)
00172         {
00173                 // ATI: release only vertices used.
00174                 _VBHard[_CurentVBHard]->unlock(0, numVertices);
00175         }
00176 }

bool NL3D::CVertexStreamManager::vbHardMode  )  const [inline]
 

true if vbHard (fast) mode.

Definition at line 72 of file vertex_stream_manager.h.

References _VBHardMode.

00072 {return _VBHardMode;}


Field Documentation

uint NL3D::CVertexStreamManager::_CurentVBHard [private]
 

Definition at line 117 of file vertex_stream_manager.h.

Referenced by activate(), CVertexStreamManager(), init(), lock(), release(), swapVBHard(), and unlock().

NLMISC::CRefPtr<IDriver> NL3D::CVertexStreamManager::_Driver [private]
 

Definition at line 108 of file vertex_stream_manager.h.

bool NL3D::CVertexStreamManager::_InitOk [private]
 

Definition at line 112 of file vertex_stream_manager.h.

Referenced by activate(), CVertexStreamManager(), init(), lock(), release(), swapVBHard(), and unlock().

uint NL3D::CVertexStreamManager::_MaxVertices [private]
 

Definition at line 115 of file vertex_stream_manager.h.

uint NL3D::CVertexStreamManager::_NumVBHard [private]
 

Definition at line 106 of file vertex_stream_manager.h.

std::vector<NLMISC::CRefPtr<IVertexBufferHard> > NL3D::CVertexStreamManager::_VBHard [private]
 

Definition at line 109 of file vertex_stream_manager.h.

bool NL3D::CVertexStreamManager::_VBHardMode [private]
 

Definition at line 111 of file vertex_stream_manager.h.

Referenced by activate(), CVertexStreamManager(), init(), lock(), release(), swapVBHard(), unlock(), and vbHardMode().

CVertexBuffer NL3D::CVertexStreamManager::_VBSoft [private]
 

Definition at line 110 of file vertex_stream_manager.h.

uint NL3D::CVertexStreamManager::_VertexFormat [private]
 

Definition at line 113 of file vertex_stream_manager.h.

uint NL3D::CVertexStreamManager::_VertexSize [private]
 

Definition at line 114 of file vertex_stream_manager.h.


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