Support Forum G3D Web Page |
A block of GPU memory within which G3D::AttributeArrays for vertex, texcoord, normal, etc.
More...
Inherits G3D::ReferenceCountedObject.
Public Types | |
typedef shared_ptr< class VertexBuffer > | Ref |
enum | UsageHint { WRITE_ONCE, WRITE_EVERY_FEW_FRAMES, WRITE_EVERY_FRAME } |
These values are hints. More... | |
Public Member Functions | |
~VertexBuffer () | |
size_t | allocatedSize () const |
uint64 | currentGeneration () const |
void | finish () |
Blocks the CPU until all rendering calls referencing this area have completed. More... | |
size_t | freeSize () const |
void * | openGLBasePointer () const |
Provided for breaking the VertexBuffer abstraction; use G3D::AttributeArray and G3D::RenderDevice in general. More... | |
uint32 | openGLVertexBufferObject () const |
Provided for breaking the VertexBuffer abstraction; use G3D::AttributeArray and G3D::RenderDevice in general. More... | |
size_t | peakAllocatedSize () const |
void | reset () |
Finishes, then frees all AttributeArray memory inside this area. More... | |
size_t | totalSize () const |
UsageHint | usageHint () const |
Static Public Member Functions | |
static void | cleanupAllVertexBuffers () |
Releases all VertexBuffers. More... | |
static shared_ptr< VertexBuffer > | create (size_t s, UsageHint h=WRITE_EVERY_FRAME) |
You should always create your VertexBuffers at least 8 bytes larger than needed for each individual AttributeArray because VertexBuffer tries to align AttributeArray starts in memory with dword boundaries. More... | |
static void | resetCacheMarkers () |
static size_t | sizeOfAllVertexBuffersInMemory () |
Returns the total m_size of all VertexBuffers allocated. More... | |
Static Protected Member Functions | |
template<class T , class ... ArgTypes> | |
static shared_ptr< T > | createShared (ArgTypes &&... args) |
Like std::make_shared, but works for protected constructors. More... | |
Friends | |
class | AttributeArray |
class | RenderDevice |
A block of GPU memory within which G3D::AttributeArrays for vertex, texcoord, normal, etc.
arrays or index lists can be allocated.
Allocate a VertexBuffer, then allocate AttributeArrays and IndexStreams within it. For example:
VertexBuffers are garbage collected: when no pointers remain to AttributeArrays inside it or the VertexBuffer itself, it will automatically be reclaimed by the system.
You cannot mix pointers from different VertexBuffers when rendering. For example, if the vertex AttributeArray is in one VertexBuffer, the normal AttributeArray and color AttributeArray must come from the same area.
This class corresponds closely to the OpenGL Vertex Buffer Object http://oss.sgi.com/projects/ogl-sample/registry/ARB/vertex_buffer_object.txt http://developer.nvidia.com/docs/IO/8230/GDC2003_OGL_BufferObjects.ppt
typedef shared_ptr<class VertexBuffer> G3D::VertexBuffer::Ref |
These values are hints.
Your program will work correctly regardless of which you use, but using the appropriate value lets the renderer optimize for your useage patterns and can increase performance.
Use WRITE_EVERY_FRAME if you write at least once per frame (e.g. software animation).
Use WRITE_EVERY_FEW_FRAMES if you write to the area as part of the rendering loop, but not every frame (e.g. impostors, deformable data).
Use WRITE_ONCE if you do not write to the area inside the rendering loop (e.g. rigid bodies loaded once at the beginning of a game level).
This does not mean you can't write multiple times to the area, just that writing might be very slow compared to rendering.
Correspond to OpenGL hints: WRITE_ONCE : GL_STATIC_DRAW_ARB WRITE_EVERY_FRAME : GL_STREAM_DRAW_ARB WRITE_EVERY_FEW_FRAMEs : DYNAMIC_DRAW_ARB
Enumerator | |
---|---|
WRITE_ONCE | |
WRITE_EVERY_FEW_FRAMES | |
WRITE_EVERY_FRAME |
G3D::VertexBuffer::~VertexBuffer | ( | ) |
|
inline |
|
static |
Releases all VertexBuffers.
Called before shutdown by RenderDevice.
|
static |
You should always create your VertexBuffers at least 8 bytes larger than needed for each individual AttributeArray because VertexBuffer tries to align AttributeArray starts in memory with dword boundaries.
|
inlinestaticprotectedinherited |
Like std::make_shared, but works for protected constructors.
Call as createShared<myclass>.
|
inline |
void G3D::VertexBuffer::finish | ( | ) |
Blocks the CPU until all rendering calls referencing this area have completed.
|
inline |
|
inline |
Provided for breaking the VertexBuffer abstraction; use G3D::AttributeArray and G3D::RenderDevice in general.
When using system memory, this is a pointer to the beginning of the system memory block in which data is stored. Null when using VBO.
|
inline |
Provided for breaking the VertexBuffer abstraction; use G3D::AttributeArray and G3D::RenderDevice in general.
When using the OpenGL vertex buffer API, this is the underlying OpenGL vertex buffer object. It is zero when using system memory. The caller cannot control whether VBO is used or not; G3D selects the best method automatically.
|
inline |
void G3D::VertexBuffer::reset | ( | ) |
Finishes, then frees all AttributeArray memory inside this area.
|
static |
|
inlinestatic |
Returns the total m_size of all VertexBuffers allocated.
Note that not all will be in video memory, and some will be backed by main memory even if nominally stored in video memory, so the total size may exceed the video memory size.
|
inline |
|
inline |
|
friend |
|
friend |