CUGL 4.0
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cugl::graphics::IndexBuffer Class Reference

#include <CUIndexBuffer.h>

Public Member Functions

 IndexBuffer ()
 
 ~IndexBuffer ()
 
void dispose ()
 
bool init (size_t size, BufferAccess access=BufferAccess::DYNAMIC)
 
bool initShort (size_t size, BufferAccess access=BufferAccess::DYNAMIC)
 
void setName (std::string name)
 
const std::string getName () const
 
BufferData * getImplementation ()
 
size_t getCapacity () const
 
BufferAccess getAccess () const
 
size_t getSize () const
 
bool isShort () const
 
bool loadData (const Uint32 *data, size_t size)
 
bool loadData (const std::vector< Uint32 > &data)
 
bool loadData (const Uint16 *data, size_t size)
 
bool loadData (const std::vector< Uint16 > &data)
 

Static Public Member Functions

static std::shared_ptr< IndexBufferalloc (size_t size, BufferAccess access=BufferAccess::DYNAMIC)
 
static std::shared_ptr< IndexBufferallocShort (size_t size, BufferAccess access=BufferAccess::DYNAMIC)
 

Protected Member Functions

void setup (size_t size)
 

Protected Attributes

std::string _name
 
BufferData * _data
 
size_t _capacity
 
BufferAccess _access
 
bool _short
 
size_t _size
 

Detailed Description

This class defines an index buffer for drawing with a shader.

A index buffer is a collection of integers refering to elements of a shader's vertex buffer(s). Typically a GraphicsShader takes both a vertex buffer and an index buffer, and previous versions of CUGL bundled them together. These are separate objects to allow shaders to work with multiple vertex buffers, one for each binding.

Index buffers can either be 16-bit (shorts) or 32-bit. This choice is made at creation time and cannot be changed. The variations of loadData will convert the data accordingly.

Constructor & Destructor Documentation

◆ IndexBuffer()

cugl::graphics::IndexBuffer::IndexBuffer ( )

Creates an uninitialized index buffer.

You must initialize the index buffer to allocate buffer memory.

◆ ~IndexBuffer()

cugl::graphics::IndexBuffer::~IndexBuffer ( )
inline

Deletes this index buffer, disposing all resources.

Member Function Documentation

◆ alloc()

static std::shared_ptr< IndexBuffer > cugl::graphics::IndexBuffer::alloc ( size_t  size,
BufferAccess  access = BufferAccess::DYNAMIC 
)
inlinestatic

Returns a new index buffer to support 32-bit integers

The size given is the maximum number of integers to store in this buffer, not the number of bytes.

Note that some access types such as BufferAccess#STATIC or BufferAccess#COMPUTE_ONLY can only be updated once. Any attempts to load data after the first time will fail.

Parameters
sizeThe maximum number of integers in this buffer
accessThe buffer access
Returns
a new index buffer to support 32-bit integers

◆ allocShort()

static std::shared_ptr< IndexBuffer > cugl::graphics::IndexBuffer::allocShort ( size_t  size,
BufferAccess  access = BufferAccess::DYNAMIC 
)
inlinestatic

Returns a new index buffer to support 16-bit integers

The size given is the maximum number of short integers to store in this buffer, not the number of bytes.

Note that some access types such as BufferAccess#STATIC or BufferAccess#COMPUTE_ONLY can only be updated once. Any attempts to load data after the first time will fail.

Parameters
sizeThe maximum number of short integers in this buffer
accessThe buffer access
Returns
a new index buffer to support 16-bit integers

◆ dispose()

void cugl::graphics::IndexBuffer::dispose ( )

Deletes the index buffer, freeing all resources.

You must reinitialize the index buffer to use it.

◆ getAccess()

BufferAccess cugl::graphics::IndexBuffer::getAccess ( ) const
inline

Returns the access policy of this index buffer

Returns
the access policy of this index buffer

◆ getCapacity()

size_t cugl::graphics::IndexBuffer::getCapacity ( ) const
inline

Returns the maximum capacity of this buffer.

The size determines the number of elements that can be loaded with the method loadData.

Returns
the maximum capacity of this buffer.

◆ getImplementation()

BufferData * cugl::graphics::IndexBuffer::getImplementation ( )
inline

Returns the platform-specific implementation for this buffer

The value returned is an opaque type encapsulating the information for either OpenGL or Vulkan.

Returns
the platform-specific implementation for this buffer

◆ getName()

const std::string cugl::graphics::IndexBuffer::getName ( ) const
inline

Returns the name of this index buffer.

A name is a user-defined way of identifying a buffer. It is used for debugging purposes only, and has no affect on the graphics pipeline.

Returns
the name of this index buffer.

◆ getSize()

size_t cugl::graphics::IndexBuffer::getSize ( ) const
inline

Returns the number of indices currently stored in this buffer

Returns
the number of indices currently stored in this buffer

◆ init()

bool cugl::graphics::IndexBuffer::init ( size_t  size,
BufferAccess  access = BufferAccess::DYNAMIC 
)

Initializes this index buffer to support 32-bit integers

The size given is the maximum number of integers to store in this buffer, not the number of bytes.

Note that some access types such as BufferAccess#STATIC or BufferAccess#COMPUTE_ONLY can only be updated once. Any attempts to load data after the first time will fail.

Parameters
sizeThe maximum number of integers in this buffer
accessThe buffer access
Returns
true if initialization was successful.

◆ initShort()

bool cugl::graphics::IndexBuffer::initShort ( size_t  size,
BufferAccess  access = BufferAccess::DYNAMIC 
)

Initializes this index buffer to support 16-bit integers

The size given is the maximum number of short integers to store in this buffer, not the number of bytes.

Note that some access types such as BufferAccess#STATIC or BufferAccess#COMPUTE_ONLY can only be updated once. Any attempts to load data after the first time will fail.

Parameters
sizeThe maximum number of short integers in this buffer
accessThe buffer access
Returns
true if initialization was successful.

◆ isShort()

bool cugl::graphics::IndexBuffer::isShort ( ) const
inline

Returns true if this buffer uses short (16-bit) indices

If the value is false, this buffer used 32-bit indices.

Returns
true if this buffer uses short (16-bit) indices

◆ loadData() [1/4]

bool cugl::graphics::IndexBuffer::loadData ( const std::vector< Uint16 > &  data)
inline

Loads the given index buffer with the given data.

If this is not a dynamic buffer, then this method can only be called once. Additional attempts to load into a static buffer will fail.

If this buffer only supports 32-bit indices, they will be converted before loading into this buffer.

Parameters
dataThe data to load
Returns
true if the data was successfully loaded

◆ loadData() [2/4]

bool cugl::graphics::IndexBuffer::loadData ( const std::vector< Uint32 > &  data)
inline

Loads the given index buffer with the given data.

If this is not a dynamic buffer, then this method can only be called once. Additional attempts to load into a static buffer will fail.

If this buffer only supports 16-bit indices, they will be converted before loading into this buffer. Note that this conversion may lose data.

Parameters
dataThe data to load
Returns
true if the data was successfully loaded

◆ loadData() [3/4]

bool cugl::graphics::IndexBuffer::loadData ( const Uint16 *  data,
size_t  size 
)

Loads the given index buffer with the given data.

If this is not a dynamic buffer, then this method can only be called once. Additional attempts to load into a static buffer will fail.

If this buffer only supports 32-bit indices, they will be converted before loading into this buffer.

Parameters
dataThe data to load
sizeThe number of elements to load
Returns
true if the data was successfully loaded

◆ loadData() [4/4]

bool cugl::graphics::IndexBuffer::loadData ( const Uint32 *  data,
size_t  size 
)

Loads the given index buffer with the given data.

If this is not a dynamic buffer, then this method can only be called once. Additional attempts to load into a static buffer will fail.

If this buffer only supports 16-bit indices, they will be converted before loading into this buffer. Note that this conversion may lose data.

Parameters
dataThe data to load
sizeThe number of elements to load
Returns
true if the data was successfully loaded

◆ setName()

void cugl::graphics::IndexBuffer::setName ( std::string  name)
inline

Sets the name of this index buffer.

A name is a user-defined way of identifying a buffer. It is used for debugging purposes only, and has no affect on the graphics pipeline.

Parameters
nameThe name of this index buffer.

◆ setup()

void cugl::graphics::IndexBuffer::setup ( size_t  size)
protected

Allocates the initial buffers for a index buffer

Parameters
sizeThe index byte size

Member Data Documentation

◆ _access

BufferAccess cugl::graphics::IndexBuffer::_access
protected

The buffer access

◆ _capacity

size_t cugl::graphics::IndexBuffer::_capacity
protected

The maximum number of indices supported

◆ _data

BufferData* cugl::graphics::IndexBuffer::_data
protected

The graphics API implementation of this buffer

◆ _name

std::string cugl::graphics::IndexBuffer::_name
protected

The name of this index buffer

◆ _short

bool cugl::graphics::IndexBuffer::_short
protected

Whether to use short indices

◆ _size

size_t cugl::graphics::IndexBuffer::_size
protected

The number of indices loaded into the buffer


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