Class IndexBuffer
OpenGL element buffer object wrapper. More...
#include <IndexBuffer.h>
Inherits the following classes: Buffers
Public Functions
| Type | Name |
|---|---|
| void | Bind () const Binds this IBO to GL_ELEMENT_ARRAY_BUFFER. |
| GLuint | Count () const Returns the number of indices. |
| GLuint | GetID () const Returns the OpenGL buffer object ID (inherited from Buffers ). |
| IndexBuffer (const GLuint * data, GLuint size) Constructs IBO from an index array. |
|
| IndexBuffer () = default Default constructor (empty buffer, buf_ID = 0). |
|
| IndexBuffer (const IndexBuffer & ibo) Copy constructor. Deep-copies GPU buffer content. |
|
| IndexBuffer (IndexBuffer && ibo) noexcept Move constructor. Transfers ownership; ibo is left empty. |
|
| void | Unbind () const Unbinds the current IBO (binds GL_ELEMENT_ARRAY_BUFFER to 0). |
| IndexBuffer & | operator= (const IndexBuffer & ibo) Copy assignment. Deep-copies GPU buffer content. |
| IndexBuffer & | operator= (IndexBuffer && ibo) noexcept Move assignment. Transfers ownership; ibo is left empty. |
| ~IndexBuffer () = default Destructor. Releases OpenGL IBO (via Buffers ). |
Public Functions inherited from Buffers
See Buffers
| Type | Name |
|---|---|
| Buffers () = default |
|
| Buffers (const Buffers & buf) Copy constructor. Performs a GPU-side deep copy of buf . |
|
| Buffers (Buffers && buf) noexcept Move constructor. Transfers ownership from buf . |
|
| GLuint | GetID () const Returns the OpenGL buffer object ID. |
| GLuint | GetSize () const Returns the allocated buffer size in bytes. |
| Buffers & | operator= (const Buffers & buf) Copy assignment. Performs a GPU-side deep copy of buf . |
| Buffers & | operator= (Buffers && buf) noexcept Move assignment. Transfers ownership from buf . |
| ~Buffers () Destructor. Releases the OpenGL buffer object if valid. |
Protected Attributes inherited from Buffers
See Buffers
| Type | Name |
|---|---|
| GLuint | buf_ID = 0OpenGL buffer object ID (0 = invalid/empty) |
| GLuint | buf_size = 0Allocated buffer size in bytes. |
Protected Functions inherited from Buffers
See Buffers
| Type | Name |
|---|---|
| void | _deepCopyFrom (const Buffers & src) GPU-side deep copy from src . |
| void | _delBuffer () Deletes the OpenGL buffer object and resets buf_ID to 0. |
Detailed Description
IndexBuffer encapsulates a single IBO/EBO bound to GL_ELEMENT_ARRAY_BUFFER for indexed rendering. It inherits RAII resource management from Buffers, including GPU-side deep copy via glCopyBufferSubData.
Usage:
GLuint indices[] = {0, 1, 2, 2, 3, 0};
IndexBuffer ibo(indices, sizeof(indices));
ibo.Bind();
glDrawElements(GL_TRIANGLES, ibo.Count(), GL_UNSIGNED_INT, 0);
// Deep copy (new GPU buffer allocated):
IndexBuffer copy = ibo;
// Transfer ownership (ibo is empty after this):
IndexBuffer moved = std::move(ibo);
Note:
Thread-safety: Not thread-safe. Must be used from the OpenGL context thread.
Note:
Ownership: Inherits Buffers ownership; releases via glDeleteBuffers in destructor.
Note:
size parameter in the main constructor is in bytes, not element count.
Public Functions Documentation
function Bind
Binds this IBO to GL_ELEMENT_ARRAY_BUFFER.
void IndexBuffer::Bind () const
function Count
Returns the number of indices.
GLuint IndexBuffer::Count () const
Returns:
Index count (buf_size / sizeof(GLuint)).
Note:
Pass as the count argument to glDrawElements.
function GetID
Returns the OpenGL buffer object ID (inherited from Buffers ).
inline GLuint IndexBuffer::GetID () const
Returns:
buf_ID.
function IndexBuffer [1/4]
Constructs IBO from an index array.
IndexBuffer::IndexBuffer (
const GLuint * data,
GLuint size
)
Parameters:
dataPointer to index data (GLuint array)sizeSize in bytes (= element count * sizeof(GLuint))
Note:
Uploads data to GPU using GL_STATIC_DRAW. Sets buf_size accordingly.
function IndexBuffer [2/4]
Default constructor (empty buffer, buf_ID = 0).
IndexBuffer::IndexBuffer () = default
function IndexBuffer [3/4]
Copy constructor. Deep-copies GPU buffer content.
IndexBuffer::IndexBuffer (
const IndexBuffer & ibo
)
Parameters:
iboSource index buffer.
function IndexBuffer [4/4]
Move constructor. Transfers ownership; ibo is left empty.
IndexBuffer::IndexBuffer (
IndexBuffer && ibo
) noexcept
Parameters:
iboSource index buffer (invalidated after move).
function Unbind
Unbinds the current IBO (binds GL_ELEMENT_ARRAY_BUFFER to 0).
void IndexBuffer::Unbind () const
function operator=
Copy assignment. Deep-copies GPU buffer content.
IndexBuffer & IndexBuffer::operator= (
const IndexBuffer & ibo
)
Parameters:
iboSource index buffer.
Returns:
Reference to this.
function operator=
Move assignment. Transfers ownership; ibo is left empty.
IndexBuffer & IndexBuffer::operator= (
IndexBuffer && ibo
) noexcept
Parameters:
iboSource index buffer (invalidated after move).
Returns:
Reference to this.
function ~IndexBuffer
Destructor. Releases OpenGL IBO (via Buffers ).
IndexBuffer::~IndexBuffer () = default
The documentation for this class was generated from the following file src/render/buffers/IndexBuffer.h