Visual Computing Library
Loading...
Searching...
No Matches
vcl::DynamicVertexBuffer Class Reference

The DynamicVertexBuffer manages the lifetime of a bgfx::DynamicVertexBufferHandle. More...

#include <vclib/bgfx/buffers/dynamic_vertex_buffer.h>

Inheritance diagram for vcl::DynamicVertexBuffer:

Public Member Functions

 DynamicVertexBuffer ()=default
 Empty constructor.
 
void swap (DynamicVertexBuffer &other)
 Swap the content of this object with another DynamicVertexBuffer object.
 
bool isCompute () const
 Check if the VertexBuffer is used for compute shaders.
 
void create (uint vertNum, bgfx::Attrib::Enum attrib, uint attribNumPerVertex, PrimitiveType attribType, bool normalize=false, bool allowResize=true)
 Creates the dynamic vertex buffer data for rendering, with the layout given by the vertex attributes and without any data.
 
void create (const void *bufferData, uint vertNum, bgfx::Attrib::Enum attrib, uint attribNumPerVertex, PrimitiveType attribType, bool normalize=false, bgfx::ReleaseFn releaseFn=nullptr, bool allowResize=true)
 Creates the dynamic vertex buffer data for rendering, with the layout given by the vertex attributes and with the given data.
 
void create (uint vertNum, const bgfx::VertexLayout &layout, uint64_t flags=BGFX_BUFFER_NONE, bool compute=false)
 Creates the dynamic vertex buffer data for rendering, with the given layout and without any data.
 
void update (const void *bufferData, uint vertNum, uint attribNumPerVertex, PrimitiveType attribType, uint startIndex=0, bgfx::ReleaseFn releaseFn=nullptr)
 Updates the dynamic vertex buffer with the given data.
 
void update (uint startIndex, const bgfx::Memory *data)
 
void bind (uint stream, bgfx::Access::Enum access=bgfx::Access::Read) const
 Bind the dynamic vertex buffer to the rendering pipeline.
 

Private Types

using Base = GenericBuffer< bgfx::DynamicVertexBufferHandle >
 

Private Attributes

bool mCompute = false
 

Friends

void swap (DynamicVertexBuffer &a, DynamicVertexBuffer &b)
 

Detailed Description

The DynamicVertexBuffer manages the lifetime of a bgfx::DynamicVertexBufferHandle.

It provides an interface to set the dynamic vertex buffer data and bind it to the rendering pipeline. The dynamic vertex buffer can be used for rendering or for compute shaders.

Todo:
provide here the differences between a vertex buffer and a dynamic vertex buffer.
Note
A DynamicVertexBuffer can be moved but not copied (a copy would require to create a new bgfx::DynamicVertexBufferHandle, that can be done only having access to the data). Any class that contains a DynamicVertexBuffer should implement the copy constructor and the copy assignment operator.

Constructor & Destructor Documentation

◆ DynamicVertexBuffer()

vcl::DynamicVertexBuffer::DynamicVertexBuffer ( )
default

Empty constructor.

It creates an invalid DynamicVertexBuffer object.

Member Function Documentation

◆ bind()

void vcl::DynamicVertexBuffer::bind ( uint  stream,
bgfx::Access::Enum  access = bgfx::Access::Read 
) const
inline

Bind the dynamic vertex buffer to the rendering pipeline.

Parameters
[in]streamthe stream (or stage, in case of compute) to which the dynamic vertex buffer is bound.
[in]accessthe access type for the buffer (only for compute).

◆ create() [1/3]

void vcl::DynamicVertexBuffer::create ( const void bufferData,
uint  vertNum,
bgfx::Attrib::Enum  attrib,
uint  attribNumPerVertex,
PrimitiveType  attribType,
bool  normalize = false,
bgfx::ReleaseFn  releaseFn = nullptr,
bool  allowResize = true 
)
inline

Creates the dynamic vertex buffer data for rendering, with the layout given by the vertex attributes and with the given data.

If the buffer is already created (isValid() returns true), it is destroyed and a new one is created.

Parameters
[in]bufferDatathe data to be copied in the vertex buffer.
[in]vertNumthe number of vertices in the buffer.
[in]attribthe attribute to which the data of the buffer refers.
[in]attribNumPerVertexthe number of attributes per vertex.
[in]attribTypethe type of the attributes.
[in]normalizeif true, the data is normalized.
[in]releaseFnthe release function to be called when the data is no longer needed.
[in]allowResizeif true, the buffer can be resized.

◆ create() [2/3]

void vcl::DynamicVertexBuffer::create ( uint  vertNum,
bgfx::Attrib::Enum  attrib,
uint  attribNumPerVertex,
PrimitiveType  attribType,
bool  normalize = false,
bool  allowResize = true 
)
inline

Creates the dynamic vertex buffer data for rendering, with the layout given by the vertex attributes and without any data.

If the buffer is already created (isValid() returns true), it is destroyed and a new one is created.

Parameters
[in]vertNumthe number of vertices in the buffer.
[in]attribthe attribute to which the data of the buffer refers.
[in]attribNumPerVertexthe number of attributes per vertex.
[in]attribTypethe type of the attributes.
[in]normalizeif true, the data is normalized.
[in]allowResizeif true, the buffer can be resized.

◆ create() [3/3]

void vcl::DynamicVertexBuffer::create ( uint  vertNum,
const bgfx::VertexLayout &  layout,
uint64_t  flags = BGFX_BUFFER_NONE,
bool  compute = false 
)
inline

Creates the dynamic vertex buffer data for rendering, with the given layout and without any data.

Parameters
[in]vertNumthe number of vertices in the buffer.
[in]layoutthe vertex layout.
[in]flagsthe flags for the buffer.
[in]computeif true, the buffer is used for compute shaders.

◆ isCompute()

bool vcl::DynamicVertexBuffer::isCompute ( ) const
inline

Check if the VertexBuffer is used for compute shaders.

Returns
true if the VertexBuffer is used for compute shaders, false otherwise.

◆ swap()

void vcl::DynamicVertexBuffer::swap ( DynamicVertexBuffer other)
inline

Swap the content of this object with another DynamicVertexBuffer object.

Parameters
[in]otherthe other DynamicVertexBuffer object.

◆ update()

void vcl::DynamicVertexBuffer::update ( const void bufferData,
uint  vertNum,
uint  attribNumPerVertex,
PrimitiveType  attribType,
uint  startIndex = 0,
bgfx::ReleaseFn  releaseFn = nullptr 
)
inline

Updates the dynamic vertex buffer with the given data.

If the buffer is not valid, the data is not updated. If the buffer was created with the allowResize flag set to true, the buffer can be resized to fit the new data. Otherwise, only the data that fits the buffer is updated.

Parameters
[in]bufferDatathe data to be copied in the vertex buffer.
[in]vertNumthe number of vertices in the buffer.
[in]attribNumPerVertexthe number of attributes per vertex.
[in]attribTypethe type of the attributes.
[in]startIndexthe index of the first vertex to be updated.
[in]releaseFnthe release function to be called when the data is no longer needed.

The documentation for this class was generated from the following file: