Vertex Buffer Object (VBO) wrapper.
More...
#include <vertex_buffer.hpp>
|
static void | unbind () |
| Unbind the vertex buffer object.
|
|
Vertex Buffer Object (VBO) wrapper.
Vertex Buffer Objects are OpenGL objects that store an array of data in the GPU's memory, the data is passed as a pointer and is then accessed through a user-specified layout.
- See also
- https://www.khronos.org/opengl/wiki/Vertex_Specification#Vertex_Buffer_Object
-
vertex_buffer_layout.hpp
- Examples
- batches.cpp, sandbox.cpp, and teapot.cpp.
Definition at line 79 of file vertex_buffer.hpp.
◆ vertex_buffer() [1/6]
staplegl::vertex_buffer::vertex_buffer |
( |
std::span< const float > |
vertices | ) |
|
|
inlinenoexcept |
Construct a new vertex buffer object.
- Note
- The vertices array is copied into the GPU's memory, so it can be safely deleted after the call.
-
By passing an empty std::span, the VBO will be initialized with no data.
- Parameters
-
vertices | a pointer to the vertices array, can be any contiguous container of floats. |
size | the size of the vertices array in bytes. |
Definition at line 232 of file vertex_buffer.hpp.
◆ vertex_buffer() [2/6]
staplegl::vertex_buffer::vertex_buffer |
( |
std::span< const float > |
vertices, |
|
|
driver_draw_hint |
hint |
|
) |
| |
|
inlinenoexcept |
◆ vertex_buffer() [3/6]
staplegl::vertex_buffer::vertex_buffer |
( |
std::span< const float > |
vertices, |
|
|
vertex_buffer_layout && |
layout |
|
) |
| |
|
inlinenoexcept |
◆ vertex_buffer() [4/6]
◆ ~vertex_buffer()
staplegl::vertex_buffer::~vertex_buffer |
( |
| ) |
|
|
inline |
◆ vertex_buffer() [5/6]
◆ vertex_buffer() [6/6]
◆ apply()
template<plain_old_data T>
Applies a function to the vertices of the vertex buffer object.
- Note
- Ensure that T is tightly packed (no padding), as the vertices of the vertex buffer object are tightly packed.
This function provides an API for low-level manipulation of the vertices of the vertex buffer object, this can be useful to perform a number of modifications to the vertices without issuing multiple API calls, for example in the case of an instanced vertex buffer, one can update the whole buffer with a single call.
Internally, this works by obtaining a pointer to the vertices of the vertex buffer object and reinterpreting it as a user-provided type
- Parameters
-
func | the function to be applied to the vertices of the vertex buffer object. |
access_specifier | the access mode of the buffer, defaults to READ_WRITE, take care not to violate the specifier (reading a write-only buffer, writing a read-only buffer, etc.) as it results in undefined behaviour. If unsure, use READ_WRITE. |
- Template Parameters
-
T | a type that represents a vertex of the vertex buffer object. |
- See also
- plain_old_data
Definition at line 301 of file vertex_buffer.hpp.
◆ bind()
void staplegl::vertex_buffer::bind |
( |
| ) |
const |
|
inline |
◆ draw_hint()
Return the driver draw hint of the vertex buffer object.
- Returns
- driver_draw_hint the hint of the vertex buffer object.
Definition at line 164 of file vertex_buffer.hpp.
◆ id()
constexpr auto staplegl::vertex_buffer::id |
( |
| ) |
const -> std::uint32_t |
|
inlineconstexprnoexcept |
Get the id of the vertex buffer object.
- Returns
- std::uint32_t the id of the vertex buffer object.
Definition at line 149 of file vertex_buffer.hpp.
◆ layout()
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ set_data() [1/2]
void staplegl::vertex_buffer::set_data |
( |
std::span< const float > |
vertices | ) |
const |
|
inlinenoexcept |
Give new data to the vertex buffer object, overwriting the old one.
- Parameters
-
vertices | std::span<const float> the new data to be given to the vertex buffer object. |
Definition at line 288 of file vertex_buffer.hpp.
◆ set_data() [2/2]
void staplegl::vertex_buffer::set_data |
( |
std::span< const float > |
vertices, |
|
|
driver_draw_hint |
hint |
|
) |
| const |
|
inlinenoexcept |
Give new data to the vertex buffer object, overwriting the old one. Also re-specify the hint.
- Parameters
-
vertices | std::span<const float> the new data to be given to the vertex buffer object. |
hint | staplegl::driver_draw_hint the new hint to be given to the vertex buffer object. |
- See also
- driver_draw_hint
Definition at line 294 of file vertex_buffer.hpp.
◆ set_layout()
◆ size()
constexpr auto staplegl::vertex_buffer::size |
( |
| ) |
const -> std::size_t |
|
inlineconstexprnoexcept |
Get the number of vertices in the vertex buffer object.
- Returns
- std::size_t the number of vertices in the vertex buffer object.
Definition at line 157 of file vertex_buffer.hpp.
◆ size_bytes()
constexpr auto staplegl::vertex_buffer::size_bytes |
( |
| ) |
const -> std::size_t |
|
inlineconstexprnoexcept |
Get the size of the vertex buffer object in bytes.
- Returns
- std::size_t the number of bytes the underlying OpenGL buffer takes up (assuming packed data).
Definition at line 171 of file vertex_buffer.hpp.
◆ unbind()
void staplegl::vertex_buffer::unbind |
( |
| ) |
|
|
inlinestatic |
◆ m_hint
◆ m_id
std::uint32_t staplegl::vertex_buffer::m_id {} |
|
protected |
◆ m_layout
◆ m_size
std::size_t staplegl::vertex_buffer::m_size {} |
|
protected |
The documentation for this class was generated from the following file: