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

The IndexBuffer manages the lifetime of a bgfx::IndexBufferHandle. More...

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

Inheritance diagram for vcl::IndexBuffer:

Public Member Functions

 IndexBuffer ()=default
 Empty constructor.
 
void swap (IndexBuffer &other)
 Swap the content of this object with another IndexBuffer object.
 
bool isCompute () const
 Check if the IndexBuffer is used for compute shaders.
 
void setCompute (bool compute)
 Set if the IndexBuffer is used for compute shaders.
 
void create (const void *bufferIndices, const uint bufferSize, bool is32Bit=true, bgfx::ReleaseFn releaseFn=nullptr)
 Creates the index buffer and sets the data for rendering.
 
void createForCompute (const void *bufferIndices, const uint bufferSize, PrimitiveType type, bgfx::Access::Enum access=bgfx::Access::Read, bgfx::ReleaseFn releaseFn=nullptr)
 Creates the index buffer and sets the data for compute shaders.
 
void create (const bgfx::Memory *indices, uint64_t flags=BGFX_BUFFER_NONE, bool compute=false)
 Creates the index buffer and sets the data.
 
void bind (uint stage=UINT_NULL, bgfx::Access::Enum access=bgfx::Access::Read) const
 Bind the index buffer to the rendering pipeline.
 

Private Types

using Base = GenericBuffer< bgfx::IndexBufferHandle >
 

Private Attributes

bool mCompute = false
 

Friends

void swap (IndexBuffer &a, IndexBuffer &b)
 

Detailed Description

The IndexBuffer manages the lifetime of a bgfx::IndexBufferHandle.

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

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

Constructor & Destructor Documentation

◆ IndexBuffer()

vcl::IndexBuffer::IndexBuffer ( )
default

Empty constructor.

It creates an invalid IndexBuffer object.

Member Function Documentation

◆ bind()

void vcl::IndexBuffer::bind ( uint  stage = UINT_NULL,
bgfx::Access::Enum  access = bgfx::Access::Read 
) const
inline

Bind the index buffer to the rendering pipeline.

If the stage is not specified, the index buffer is bound to the rendering pipeline. Otherwise, it is bound to the compute shader with the specified stage and the given access type (Read, Write, ReadWrite).

Parameters
[in]stagethe stage to which the buffer is bound.
[in]accessthe access type for the buffer.

◆ create() [1/2]

void vcl::IndexBuffer::create ( const bgfx::Memory *  indices,
uint64_t  flags = BGFX_BUFFER_NONE,
bool  compute = false 
)
inline

Creates the index 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]indicesthe memory containing the data.
[in]flagsthe flags for the buffer.
[in]computeif true, the buffer is used for compute shaders.

◆ create() [2/2]

void vcl::IndexBuffer::create ( const void bufferIndices,
const uint  bufferSize,
bool  is32Bit = true,
bgfx::ReleaseFn  releaseFn = nullptr 
)
inline

Creates the index 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]bufferIndicesthe data to be copied in the index buffer.
[in]bufferSizethe size of the bufferIndices.
[in]is32Bitif true, the bufferIndices are 32-bit integers.
[in]releaseFnthe release function to be called when the data is no longer needed.

◆ createForCompute()

void vcl::IndexBuffer::createForCompute ( const void bufferIndices,
const uint  bufferSize,
PrimitiveType  type,
bgfx::Access::Enum  access = bgfx::Access::Read,
bgfx::ReleaseFn  releaseFn = nullptr 
)
inline

Creates the index 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]bufferIndicesthe data to be copied in the index buffer.
[in]bufferSizethe size of the bufferIndices.
[in]typethe type of the elements.
[in]accessthe access type for the buffer.
[in]releaseFnthe release function to be called when the data is no longer needed.

◆ isCompute()

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

Check if the IndexBuffer is used for compute shaders.

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

◆ setCompute()

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

Set if the IndexBuffer is used for compute shaders.

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

◆ swap()

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

Swap the content of this object with another IndexBuffer object.

Parameters
[in]otherthe other IndexBuffer object.

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