ImFusion SDK 4.3
IndexBuffer Class Reference

#include <ImFusion/Core/GL/IndexBuffer.h>

Specialization of Buffer to store vertex index data (GL_ELEMENT_ARRAY_BUFFER). More...

+ Inheritance diagram for IndexBuffer:

Detailed Description

Specialization of Buffer to store vertex index data (GL_ELEMENT_ARRAY_BUFFER).

Can be passed to a GL::VertexBuffer::draw() call for indexed rendering where the same vertex data can be used by multiple vertices to reduce memory usage.

Example for rendering a quad using indexed rendering:

// vertex data describing 4 vertices
std::vector<vec2f> vertices = {
vec2f(-1.0, -1.0),
vec2f( 1.0, -1.0),
vec2f(-1.0, 1.0),
vec2f( 1.0, 1.0)
};
vbo.bind();
vbo.setData(vertices);
// index data to render two triangles of 3 vertices each
0, 1, 2, 1, 2, 3
};
ibo.bind();
ibo.setData(indices);
// Note that this is an artificial example to showcase the usage of index buffers.
// You could achieve the same rendering result with the vertex data only and using
// the Primitive::TriangleStrip primitive instead.
void bind() const
Binds the buffer to the target given during construction.
Specialization of Buffer to store vertex index data (GL_ELEMENT_ARRAY_BUFFER).
Definition IndexBuffer.h:54
void setData(Utils::Span< uint8_t > indices)
Upload uint8_t vertex indices to the buffer.
Specialization of Buffer to store vertex array data.
Definition VertexBuffer.h:59
void draw(Primitive mode) const
Renders a single primitive using all vertices of this VBO.
void setData(const std::vector< Ts > &... arrays)
Upload data to the buffer.
Definition VertexBuffer.h:266
@ Triangles
Vertices 0, 1, and 2 form a triangle. Vertices 3, 4, and 5 form a triangle. And so on.
Definition Types.h:71
Warning
In WebGL, the PRIMITIVE_RESTART_FIXED_INDEX option is always enabled. If an index is the maximum for the data type (i.e. 0xFF, 0xFFFF or 0xFFFFFFFF), it is not treated as a regular index, but will restart the primitive. To maintain compatibility, make sure to only use indices smaller than the maximum and only use the maximum in setPrimitiveRestartIndex. See the WebGL Spec for details.
See also

Public Member Functions

 IndexBuffer (Usage usageHint=Buffer::Usage::StaticDraw)
 Default constructs an empty index buffer.
 
uint32_t primitiveRestartIndex () const
 Returns the OpenGL primitive restart index to use during indexed rendering.
 
void setPrimitiveRestartIndex (uint32_t value)
 Sets the OpenGL primitive restart index to use during indexed rendering.
 
size_t numElements () const
 Return the number of indices stored in the buffer.
 
PixelType type () const
 Return the index data type.
 
void setData (Utils::Span< uint8_t > indices)
 Upload uint8_t vertex indices to the buffer.
 
void setData (Utils::Span< uint16_t > indices)
 Upload uint16_t vertex indices to the buffer.
 
void setData (Utils::Span< uint32_t > indices)
 Upload uint32_t vertex indices to the buffer.
 
void setData (Utils::Span< vec3i > indices)
 Upload non-negative int32_t triplets describing a series of triangles to the vertex index buffer.
 
- Public Member Functions inherited from Buffer
 Buffer (Target target, Usage usage)
 Creates a new Buffer.
 
void bind () const
 Binds the buffer to the target given during construction.
 
Usage usageHint () const
 Returns the buffer usage hint passed to OpenGL during allocation.
 
void setUsageHint (Usage value)
 Sets the buffer usage hint passed to OpenGL during allocation.
 
uint32_t id () const
 Return a handle to the internal OpenGL buffer object.
 

Static Public Member Functions

static void unbind ()
 Unbind any bound index buffer.
 
- Static Public Member Functions inherited from Buffer
static void unbind (Target target)
 Binds 0 to the specified target.
 

Additional Inherited Members

- Public Types inherited from Buffer
enum class  Target {
  Array = 0x8892 , AtomicCounter = 0x92C0 , CopyRead = 0x8F36 , CopyWrite = 0x8F37 ,
  DrawIndirect = 0x8F3F , ElementArray = 0x8893 , PixelPack = 0x88EB , PixelUnpack = 0x88EC ,
  ShaderStorage = 0x90D2 , Texture = 0x8C2A , TransformFeedback = 0x8C8E , Uniform = 0x8A11
}
 Enumeration of the different OpenGL buffer types. More...
 
enum class  Usage {
  StreamDraw = 0x88E0 , StreamRead = 0x88E1 , StreamCopy = 0x88E2 , StaticDraw = 0x88E4 ,
  StaticRead = 0x88E5 , StaticCopy = 0x88E6 , DynamicDraw = 0x88E8 , DynamicRead = 0x88E9 ,
  DynamicCopy = 0x88EA
}
 Enumeration for usage pattern hints to provide to the GPU when allocating data. More...
 
- Protected Member Functions inherited from Buffer
void allocateBuffer (int64_t numBytes)
 Allocates storage on the GPU for this buffer object.
 
template<typename... Ts>
void setSubData (size_t offset, Utils::Span< Ts >... data)
 Upload data into the buffer starting at the given offset.
 
template<typename... Ts>
size_t getBufferSize (Utils::Span< Ts >... data) const
 Compute the total number of bytes used by all provided data together.
 
- Static Protected Member Functions inherited from Buffer
static void glBufferSubDataImpl (Target target, int64_t offset, int64_t size, const void *data)
 forwards to OpenGL's glBufferSubData().
 
static void glGetBufferSubDataImpl (Target target, int64_t offset, int64_t size, void *data)
 forwards to OpenGL's glGetBufferSubData().
 
- Protected Attributes inherited from Buffer
const Target m_target
 Target binding point for the buffer, will never change for a Buffer instance.
 
Usage m_usageHint
 Buffer usage hint passed to OpenGL unless explicitly specified otherwise.
 
uint32_t m_id = 0
 Internal OpenGL handle to buffer object.
 
int64_t m_bufferSize = 0
 Number of bytes allocated on the GPU.
 

Constructor & Destructor Documentation

◆ IndexBuffer()

Default constructs an empty index buffer.

Parameters
usageHintExpected usage pattern of the buffer
Exceptions
std::runtime_errorif the corresponding OpenGL buffer object could not be created.

Member Function Documentation

◆ primitiveRestartIndex()

uint32_t primitiveRestartIndex ( ) const

Returns the OpenGL primitive restart index to use during indexed rendering.

The primitive restart feature is disabled if the index is 0 (default behavior).

◆ setPrimitiveRestartIndex()

void setPrimitiveRestartIndex ( uint32_t value)

Sets the OpenGL primitive restart index to use during indexed rendering.

The primitive restart feature is disabled if the index is 0 (default behavior). On WebGL, the features is always enabled. Check the class documentation for details.

◆ setData() [1/4]

void setData ( Utils::Span< uint8_t > indices)

Upload uint8_t vertex indices to the buffer.

The buffer needs to be bound before this method is called. Any previous data will be deleted.

Parameters
indicesContiguous sequence of index data that should be copied to the buffer.

◆ setData() [2/4]

void setData ( Utils::Span< uint16_t > indices)

Upload uint16_t vertex indices to the buffer.

The buffer needs to be bound before this method is called. Any previous data will be deleted.

Parameters
indicesContiguous sequence of index data that should be copied to the buffer.

◆ setData() [3/4]

void setData ( Utils::Span< uint32_t > indices)

Upload uint32_t vertex indices to the buffer.

The buffer needs to be bound before this method is called. Any previous data will be deleted.

Parameters
indicesContiguous sequence of index data that should be copied to the buffer.

◆ setData() [4/4]

void setData ( Utils::Span< vec3i > indices)

Upload non-negative int32_t triplets describing a series of triangles to the vertex index buffer.

The buffer needs to be bound before this method is called. Any previous data will be deleted.

Parameters
indicesContiguous sequence of index data that should be copied to the buffer. Must not contain any negative elements.

The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close