NL3D::CVertexBufferHeap Class Reference

#include <vertex_buffer_heap.h>


Detailed Description

A vertex buffer used to group lot of static VB in it. Work with VBHard where available.
Author:
Lionel Berenguier

Nevrax France

Date:
2002

Definition at line 46 of file vertex_buffer_heap.h.

Public Member Functions

 CVertexBufferHeap ()
 Constructor.

 ~CVertexBufferHeap ()
Rendering. Those methods must be called only if enabled(), else crash
void activate ()
 activate the VB/VBHard as the current VB in the driver, for future rendering

uint8lock (uint indexStart)
 lock the VB/VBHard, for future filling

void unlock (uint startVert, uint endVert)
 unlock the VB/VBHard. Mirror the IVertexBufferHard::unlock(start, end) scheme.

Allocation.
bool allocate (uint numVertices, uint &indexStart)
 allocate a subset of the VB. false if cannot (not enough space/too big).

void free (uint indexStart)
 free a subset of the VB. nlstop if subset not found...

Init/Setup
bool enabled () const
 false if any error at init, or if init() not called

IDrivergetDriver () const
 return the driver used.

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

uint getVertexFormat () const
 get the vertexFormat

uint getVertexSize () const
 get the vertexSize

void init (IDriver *driver, uint vertexFormat, uint maxVertices)
 Create the vertex buffer heap. It use a VBHard if possible. else a std CVertexBuffer is used.

void release ()
 release the VB. init() can be called after this.


Private Attributes

NLMISC::CRefPtr< IDriver_Driver
bool _Enabled
bool _HardMode
NLMISC::CHeapMemory _HeapManager
uint8_HeapStart
uint _MaxVertices
NLMISC::CRefPtr< IVertexBufferHard_VBHard
CVertexBuffer _VBSoft
uint _VertexFormat
uint _VertexSize


Constructor & Destructor Documentation

NL3D::CVertexBufferHeap::CVertexBufferHeap  ) 
 

Constructor.

Definition at line 38 of file vertex_buffer_heap.cpp.

References _HardMode, _HeapStart, _MaxVertices, and _VertexFormat.

00039 {
00040         _Enabled= false;
00041         _HardMode= false;
00042 
00043         _HeapStart= NULL;
00044         _VertexFormat= 0;
00045         _VertexSize= 0;
00046         _MaxVertices= 0;
00047 }

NL3D::CVertexBufferHeap::~CVertexBufferHeap  ) 
 

Definition at line 50 of file vertex_buffer_heap.cpp.

References release().

00051 {
00052         release();
00053 }


Member Function Documentation

void NL3D::CVertexBufferHeap::activate  ) 
 

activate the VB/VBHard as the current VB in the driver, for future rendering

Definition at line 179 of file vertex_buffer_heap.cpp.

References _HardMode, _VBSoft, enabled(), and nlassert.

Referenced by NL3D::CMeshBlockManager::flush().

00180 {
00181         nlassert(enabled());
00182 
00183         if(_HardMode)
00184                 _Driver->activeVertexBufferHard(_VBHard);
00185         else
00186                 _Driver->activeVertexBuffer(_VBSoft);
00187 }

bool NL3D::CVertexBufferHeap::allocate uint  numVertices,
uint indexStart
 

allocate a subset of the VB. false if cannot (not enough space/too big).

Definition at line 125 of file vertex_buffer_heap.cpp.

References _HeapManager, _HeapStart, NLMISC::CHeapMemory::allocate(), enabled(), getVertexSize(), nlassert, uint, and uint8.

Referenced by NL3D::CMeshBlockManager::allocateMeshVBHeap().

00126 {
00127         nlassert(enabled());
00128 
00129         // allocate into the heap ?
00130         uint8   *ptr= (uint8*)_HeapManager.allocate(numVertices*getVertexSize());
00131         if(!ptr)
00132                 return false;
00133         else
00134         {
00135                 // compute vertex index
00136                 indexStart= (uint)(ptr-_HeapStart);
00137                 indexStart/= _VertexSize;
00138                 return true;
00139         }
00140 }

bool NL3D::CVertexBufferHeap::enabled  )  const [inline]
 

false if any error at init, or if init() not called

Definition at line 62 of file vertex_buffer_heap.h.

Referenced by activate(), allocate(), free(), lock(), and unlock().

00062 {return _Enabled;}

void NL3D::CVertexBufferHeap::free uint  indexStart  ) 
 

free a subset of the VB. nlstop if subset not found...

Definition at line 142 of file vertex_buffer_heap.cpp.

References _HeapManager, _HeapStart, enabled(), NLMISC::CHeapMemory::free(), nlassert, uint, and uint8.

Referenced by NL3D::CMeshBlockManager::freeMeshVBHeap().

00143 {
00144         nlassert(enabled());
00145 
00146         // compute ptr to free
00147         uint8   *ptr= _HeapStart + indexStart*_VertexSize;
00148         // free it.
00149         _HeapManager.free(ptr);
00150 }

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

return the driver used.

Definition at line 64 of file vertex_buffer_heap.h.

00064 {return _Driver;}

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

get max vertices the Buffer allows.

Definition at line 70 of file vertex_buffer_heap.h.

References _MaxVertices, and uint.

00070 {return _MaxVertices;}

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

get the vertexFormat

Definition at line 66 of file vertex_buffer_heap.h.

References _VertexFormat, and uint.

00066 {return _VertexFormat;}

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

get the vertexSize

Definition at line 68 of file vertex_buffer_heap.h.

References uint.

Referenced by allocate().

00068 {return _VertexSize;}

void NL3D::CVertexBufferHeap::init IDriver driver,
uint  vertexFormat,
uint  maxVertices
 

Create the vertex buffer heap. It use a VBHard if possible. else a std CVertexBuffer is used.

Definition at line 56 of file vertex_buffer_heap.cpp.

References _HardMode, _HeapManager, _HeapStart, _MaxVertices, _VBSoft, _VertexFormat, NL3D::CVertexBuffer::getUVRouting(), NL3D::CVertexBuffer::getValueTypePointer(), NL3D::CVertexBuffer::getVertexCoordPointer(), NL3D::CVertexBuffer::getVertexFormat(), NL3D::CVertexBuffer::getVertexSize(), NLMISC::CHeapMemory::initHeap(), nlassert, release(), NL3D::CVertexBuffer::setNumVertices(), NL3D::CVertexBuffer::setVertexFormat(), uint, and uint8.

Referenced by NL3D::CMeshBlockManager::addVBHeap().

00057 {
00058         nlassert(driver);
00059         // clean before.
00060         release();
00061 
00062         // setup
00063         _Driver= driver;
00064 
00065         // setup the vertexBuffer soft with queried info.
00066         _VBSoft.setVertexFormat(vertexFormat);
00067         // VertexSize must be a multitple of 4 (Heap alignement ...)
00068         nlassert( (_VBSoft.getVertexSize()&3) == 0);
00069 
00070         // create the VBHard, if possible
00071         _VBHard= driver->createVertexBufferHard(_VBSoft.getVertexFormat(), _VBSoft.getValueTypePointer(), maxVertices, IDriver::VBHardAGP, _VBSoft.getUVRouting());
00072 
00073         // Ok
00074         _Enabled= true;
00075         _VertexFormat= _VBSoft.getVertexFormat();
00076         _VertexSize= _VBSoft.getVertexSize();
00077         _MaxVertices= maxVertices;
00078 
00079         // Use hard or soft ???
00080         if(_VBHard)
00081         {
00082                 _HardMode= true;
00083                 // setup heap start with good AGP ptr.
00084                 _HeapStart= (uint8*)_VBHard->lock();
00085                 // just a gestion lock, no vertices have changed.
00086                 _VBHard->unlock(0,0);
00087                 // In essence, the VBHeap is rarely modified (but on mesh loading). => set it static
00088                 _VBHard->lockHintStatic(true);
00089         }
00090         else
00091         {
00092                 _HardMode= false;
00093                 // => allocate soft one.
00094                 _VBSoft.setNumVertices(maxVertices);
00095                 // setup heap start with good ptr.
00096                 _HeapStart= (uint8*)_VBSoft.getVertexCoordPointer();
00097         }
00098 
00099         // setup heap Manager with good ptr.
00100         _HeapManager.initHeap(_HeapStart, _MaxVertices*_VertexSize);
00101 }

uint8 * NL3D::CVertexBufferHeap::lock uint  indexStart  ) 
 

lock the VB/VBHard, for future filling

Definition at line 153 of file vertex_buffer_heap.cpp.

References _HardMode, _HeapStart, enabled(), nlassert, uint, and uint8.

Referenced by NL3D::CMeshBlockManager::allocateMeshVBHeap(), and NL3D::CMeshBlockManager::render().

00154 {
00155         nlassert(enabled());
00156 
00157         uint8   *ptr;
00158         if(_HardMode)
00159         {
00160                 // lock the vbHard
00161                 ptr= (uint8*)_VBHard->lock();
00162                 nlassert(ptr==_HeapStart);
00163         }
00164         else
00165                 ptr= _HeapStart;
00166 
00167         // index it with index
00168         return ptr + indexStart*_VertexSize;
00169 }

void NL3D::CVertexBufferHeap::release  ) 
 

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

Definition at line 103 of file vertex_buffer_heap.cpp.

References _HardMode, _HeapManager, _HeapStart, _MaxVertices, _VBSoft, _VertexFormat, and nlassert.

Referenced by init(), and ~CVertexBufferHeap().

00104 {
00105         if(_VBHard)
00106         {
00107                 nlassert(_Driver);
00108                 _Driver->deleteVertexBufferHard(_VBHard);
00109         }
00110         _VBHard= NULL;
00111         _Driver= NULL;
00112         _HeapStart= NULL;
00113         // release all memory
00114         contReset(_VBSoft);
00115         contReset(_HeapManager);
00116 
00117         _Enabled= false;
00118         _HardMode= false;
00119         _VertexFormat= 0;
00120         _VertexSize= 0;
00121         _MaxVertices= 0;
00122 }

void NL3D::CVertexBufferHeap::unlock uint  startVert,
uint  endVert
 

unlock the VB/VBHard. Mirror the IVertexBufferHard::unlock(start, end) scheme.

Definition at line 171 of file vertex_buffer_heap.cpp.

References _HardMode, enabled(), nlassert, and uint.

Referenced by NL3D::CMeshBlockManager::allocateMeshVBHeap(), and NL3D::CMeshBlockManager::render().

00172 {
00173         nlassert(enabled());
00174 
00175         if(_HardMode)
00176                 _VBHard->unlock(startVert, endVert);
00177 }


Field Documentation

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

Definition at line 100 of file vertex_buffer_heap.h.

bool NL3D::CVertexBufferHeap::_Enabled [private]
 

Definition at line 105 of file vertex_buffer_heap.h.

bool NL3D::CVertexBufferHeap::_HardMode [private]
 

Definition at line 106 of file vertex_buffer_heap.h.

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

NLMISC::CHeapMemory NL3D::CVertexBufferHeap::_HeapManager [private]
 

Definition at line 103 of file vertex_buffer_heap.h.

Referenced by allocate(), free(), init(), and release().

uint8* NL3D::CVertexBufferHeap::_HeapStart [private]
 

Definition at line 104 of file vertex_buffer_heap.h.

Referenced by allocate(), CVertexBufferHeap(), free(), init(), lock(), and release().

uint NL3D::CVertexBufferHeap::_MaxVertices [private]
 

Definition at line 110 of file vertex_buffer_heap.h.

Referenced by CVertexBufferHeap(), getMaxVertices(), init(), and release().

NLMISC::CRefPtr<IVertexBufferHard> NL3D::CVertexBufferHeap::_VBHard [private]
 

Definition at line 101 of file vertex_buffer_heap.h.

CVertexBuffer NL3D::CVertexBufferHeap::_VBSoft [private]
 

Definition at line 102 of file vertex_buffer_heap.h.

Referenced by activate(), init(), and release().

uint NL3D::CVertexBufferHeap::_VertexFormat [private]
 

Definition at line 108 of file vertex_buffer_heap.h.

Referenced by CVertexBufferHeap(), getVertexFormat(), init(), and release().

uint NL3D::CVertexBufferHeap::_VertexSize [private]
 

Definition at line 109 of file vertex_buffer_heap.h.


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