#include <vertex_buffer_heap.h>
Nevrax France
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 | |
uint8 * | lock (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 | |
IDriver * | getDriver () 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.
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 } |
|
Definition at line 50 of file vertex_buffer_heap.cpp. References release().
00051 { 00052 release(); 00053 } |
|
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().
|
|
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 } |
|
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;} |
|
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 } |
|
return the driver used.
Definition at line 64 of file vertex_buffer_heap.h.
00064 {return _Driver;} |
|
get max vertices the Buffer allows.
Definition at line 70 of file vertex_buffer_heap.h. References _MaxVertices, and uint.
00070 {return _MaxVertices;} |
|
get the vertexFormat
Definition at line 66 of file vertex_buffer_heap.h. References _VertexFormat, and uint.
00066 {return _VertexFormat;} |
|
get the vertexSize
Definition at line 68 of file vertex_buffer_heap.h. References uint. Referenced by allocate().
00068 {return _VertexSize;} |
|
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 } |
|
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 } |
|
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 } |
|
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().
|
|
Definition at line 100 of file vertex_buffer_heap.h. |
|
Definition at line 105 of file vertex_buffer_heap.h. |
|
Definition at line 106 of file vertex_buffer_heap.h. Referenced by activate(), CVertexBufferHeap(), init(), lock(), release(), and unlock(). |
|
Definition at line 103 of file vertex_buffer_heap.h. Referenced by allocate(), free(), init(), and release(). |
|
Definition at line 104 of file vertex_buffer_heap.h. Referenced by allocate(), CVertexBufferHeap(), free(), init(), lock(), and release(). |
|
Definition at line 110 of file vertex_buffer_heap.h. Referenced by CVertexBufferHeap(), getMaxVertices(), init(), and release(). |
|
Definition at line 101 of file vertex_buffer_heap.h. |
|
Definition at line 102 of file vertex_buffer_heap.h. Referenced by activate(), init(), and release(). |
|
Definition at line 108 of file vertex_buffer_heap.h. Referenced by CVertexBufferHeap(), getVertexFormat(), init(), and release(). |
|
Definition at line 109 of file vertex_buffer_heap.h. |