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

The VertexBuffer manages the lifetime of a bgfx::VertexBufferHandle. More...

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

Inheritance diagram for vcl::VertexBuffer:

Public Member Functions

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

Private Types

using Base = GenericBuffer< bgfx::VertexBufferHandle >
 

Private Attributes

bool mCompute = false
 

Friends

void swap (VertexBuffer &a, VertexBuffer &b)
 

Detailed Description

The VertexBuffer manages the lifetime of a bgfx::VertexBufferHandle.

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

Note
A VertexBuffer can be moved but not copied (a copy would require to create a new bgfx::VertexBufferHandle, that can be done only having access to the data). Any class that contains a VertexBuffer should implement the copy constructor and the copy assignment operator.

Constructor & Destructor Documentation

◆ VertexBuffer()

vcl::VertexBuffer::VertexBuffer ( )
default

Empty constructor.

It creates an invalid VertexBuffer object.

Member Function Documentation

◆ bind()

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

Bind the vertex buffer to the rendering pipeline.

If the buffer is invalid, it is not bound.

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

◆ create() [1/2]

void vcl::VertexBuffer::create ( const bgfx::Memory *  data,
const bgfx::VertexLayout &  layout,
uint64_t  flags = BGFX_BUFFER_NONE,
bool  compute = false 
)
inline

Creates the vertex buffer and sets the data.

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

Parameters
[in]datathe memory containing the data.
[in]layoutthe vertex layout.
[in]flagsthe flags for the buffer.
[in]computeif true, the buffer is used for compute shaders.

◆ create() [2/2]

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

Creates the vertex buffer and sets the data for rendering.

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

Note
The data must be available for two bgfx::frame calls, then it is safe to release the data. If you cannot guarantee this, you must provide a release function that will be called automatically when the data is no longer needed.
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.

◆ createForCompute()

void vcl::VertexBuffer::createForCompute ( const void bufferData,
const uint  vertNum,
bgfx::Attrib::Enum  attrib,
uint  attribNumPerVertex,
PrimitiveType  attribType,
bool  normalize = false,
bgfx::Access::Enum  access = bgfx::Access::Read,
bgfx::ReleaseFn  releaseFn = nullptr 
)
inline

Creates the vertex buffer and sets the data for compute shaders.

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

Note
The data must be available for two bgfx::frame calls, then it is safe to release the data. If you cannot guarantee this, you must provide a release function that will be called automatically when the data is no longer needed.
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]accessthe access type for the buffer.
[in]releaseFnthe release function to be called when the data is no longer needed.

◆ isCompute()

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

Check if the VertexBuffer is used for compute shaders.

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

◆ setCompute()

void vcl::VertexBuffer::setCompute ( bool  compute)
inline

Set if the VertexBuffer is used for compute shaders.

Parameters
[in]computeif true, the VertexBuffer is used for compute shaders.

◆ swap()

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

Swap the content of this object with another VertexBuffer object.

Parameters
[in]otherthe other VertexBuffer object.

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