StapleGL
Header-only C++20 OpenGL wrapper
Loading...
Searching...
No Matches
staplegl::vertex_array Class Reference

Vertex Array Object (VAO) wrapper. More...

#include <vertex_array.hpp>

Collaboration diagram for staplegl::vertex_array:

Public Types

using iterator_t = std::list< vertex_buffer >::iterator
 Iterator type returned from add_vertex_buffer.
 

Public Member Functions

 vertex_array () noexcept
 Construct a new vertex array object.
 
 ~vertex_array ()
 
 vertex_array (const vertex_array &)=delete
 
auto operator= (const vertex_array &) -> vertex_array &=delete
 
 vertex_array (vertex_array &&other) noexcept
 Construct a new vertex array object from another one.
 
auto operator= (vertex_array &&other) noexcept -> vertex_array &
 Move assignment operator.
 
void bind () const
 Bind the vertex array object.
 
auto add_vertex_buffer (vertex_buffer &&vbo) -> vertex_array::iterator_t
 Add a vertex buffer to the vertex array object.
 
void set_instance_buffer (vertex_buffer_inst &&vbo)
 Set the instance buffer object.
 
void clear_instance_buffer ()
 Clear the instance buffer object.
 
void set_index_buffer (index_buffer &&ibo)
 Set the index buffer object.
 
constexpr auto id () const -> uint32_t
 Get the vertex array object id.
 
constexpr auto buffers_data () -> std::list< vertex_buffer > &
 Get the vertex buffer object at the specified index.
 
constexpr auto instanced_data () -> std::optional< vertex_buffer_inst > &
 Get the instance buffer object.
 
constexpr auto index_data () -> index_buffer &
 Get the index buffer object.
 

Static Public Member Functions

static void unbind ()
 Unbind the vertex array object.
 

Private Attributes

std::uint32_t m_id {}
 
std::list< vertex_bufferm_vertex_buffers
 
std::optional< vertex_buffer_instm_instanced_vbo
 
index_buffer m_index_buffer
 
uint32_t attrib_index {}
 

Detailed Description

Vertex Array Object (VAO) wrapper.

Vertex Array Objects are OpenGL objects that store all of the state needed to supply vertex data, that is, an index buffer (also called an Element Buffer Object) and one or more vertex buffers.

Rendering using VAOs is advised as it simplifies the process of rendering multiple objects with different vertex data and different rendering modes.

See also
https://www.khronos.org/opengl/wiki/Vertex_Specification#Vertex_Array_Object
vertex_buffer.hpp
index_buffer.hpp
vertex_buffer_layout.hpp
Examples
batches.cpp, sandbox.cpp, and teapot.cpp.

Definition at line 51 of file vertex_array.hpp.

Member Typedef Documentation

◆ iterator_t

using staplegl::vertex_array::iterator_t = std::list<vertex_buffer>::iterator

Iterator type returned from add_vertex_buffer.

Definition at line 111 of file vertex_array.hpp.

Constructor & Destructor Documentation

◆ vertex_array() [1/3]

staplegl::vertex_array::vertex_array ( )
inlinenoexcept

Construct a new vertex array object.

Constructs a VAO and generates an id for it, VBOs and EBOs can be added later.

See also
add_vertex_buffer
set_instance_buffer

Definition at line 203 of file vertex_array.hpp.

◆ ~vertex_array()

staplegl::vertex_array::~vertex_array ( )
inline

Definition at line 208 of file vertex_array.hpp.

◆ vertex_array() [2/3]

staplegl::vertex_array::vertex_array ( const vertex_array )
delete

◆ vertex_array() [3/3]

staplegl::vertex_array::vertex_array ( vertex_array &&  other)
inlinenoexcept

Construct a new vertex array object from another one.

constructs a VAO by stealing the ID and the attached VBOs and EBOs from another VAO.

Parameters
otherthe vertex array object to copy from.

Definition at line 76 of file vertex_array.hpp.

Member Function Documentation

◆ add_vertex_buffer()

auto staplegl::vertex_array::add_vertex_buffer ( vertex_buffer &&  vbo) -> vertex_array::iterator_t
inline

Add a vertex buffer to the vertex array object.

Parameters
vbothe vertex buffer object to add.
Returns
iterator_t an iterator to the newly added vertex buffer, it is guaranteed to be valid for the lifetime of the vertex array object, useful to keep track of the individual VBOs.
See also
vertex_buffer.hpp
Examples
batches.cpp, sandbox.cpp, and teapot.cpp.

Definition at line 223 of file vertex_array.hpp.

◆ bind()

void staplegl::vertex_array::bind ( ) const
inline

Bind the vertex array object.

Examples
batches.cpp, sandbox.cpp, and teapot.cpp.

Definition at line 213 of file vertex_array.hpp.

◆ buffers_data()

constexpr auto staplegl::vertex_array::buffers_data ( ) -> std::list<vertex_buffer>&
inlineconstexpr

Get the vertex buffer object at the specified index.

Returns
std::list<vertex_buffer>& the vertex buffer object at the specified index.

Definition at line 172 of file vertex_array.hpp.

◆ clear_instance_buffer()

void staplegl::vertex_array::clear_instance_buffer ( )
inline

Clear the instance buffer object.

Definition at line 149 of file vertex_array.hpp.

◆ id()

constexpr auto staplegl::vertex_array::id ( ) const -> uint32_t
inlineconstexpr

Get the vertex array object id.

Returns
uint32_t the vertex array object id.

Definition at line 165 of file vertex_array.hpp.

◆ index_data()

constexpr auto staplegl::vertex_array::index_data ( ) -> index_buffer&
inlineconstexpr

Get the index buffer object.

Returns
index_buffer& the index buffer object.
Examples
batches.cpp, and teapot.cpp.

Definition at line 186 of file vertex_array.hpp.

◆ instanced_data()

constexpr auto staplegl::vertex_array::instanced_data ( ) -> std::optional<vertex_buffer_inst>&
inlineconstexpr

Get the instance buffer object.

Returns
std::optional<vertex_buffer_inst>& the instance buffer object.
Examples
batches.cpp.

Definition at line 179 of file vertex_array.hpp.

◆ operator=() [1/2]

auto staplegl::vertex_array::operator= ( const vertex_array ) -> vertex_array &=delete
delete

◆ operator=() [2/2]

auto staplegl::vertex_array::operator= ( vertex_array &&  other) -> vertex_array&
inlinenoexcept

Move assignment operator.

Parameters
otherthe vertex array object to move from.
Returns
vertex_array& a reference to the moved vertex array object.

Definition at line 93 of file vertex_array.hpp.

◆ set_index_buffer()

void staplegl::vertex_array::set_index_buffer ( index_buffer &&  ibo)
inline

Set the index buffer object.

Parameters
ibothe index buffer object to set.
See also
index_buffer.hpp
Examples
batches.cpp, sandbox.cpp, and teapot.cpp.

Definition at line 267 of file vertex_array.hpp.

◆ set_instance_buffer()

void staplegl::vertex_array::set_instance_buffer ( vertex_buffer_inst &&  vbo)
inline

Set the instance buffer object.

Parameters
vbothe instance buffer object to set.
See also
vertex_buffer_inst.hpp
Examples
batches.cpp.

Definition at line 247 of file vertex_array.hpp.

◆ unbind()

void staplegl::vertex_array::unbind ( )
inlinestatic

Unbind the vertex array object.

Examples
teapot.cpp.

Definition at line 218 of file vertex_array.hpp.

Member Data Documentation

◆ attrib_index

uint32_t staplegl::vertex_array::attrib_index {}
private

Definition at line 194 of file vertex_array.hpp.

◆ m_id

std::uint32_t staplegl::vertex_array::m_id {}
private

Definition at line 189 of file vertex_array.hpp.

◆ m_index_buffer

index_buffer staplegl::vertex_array::m_index_buffer
private

Definition at line 192 of file vertex_array.hpp.

◆ m_instanced_vbo

std::optional<vertex_buffer_inst> staplegl::vertex_array::m_instanced_vbo
private

Definition at line 191 of file vertex_array.hpp.

◆ m_vertex_buffers

std::list<vertex_buffer> staplegl::vertex_array::m_vertex_buffers
private

Definition at line 190 of file vertex_array.hpp.


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