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

Uniform Buffer Object (UBO) wrapper. More...

#include <uniform_buffer.hpp>

Collaboration diagram for staplegl::uniform_buffer:

Public Member Functions

 uniform_buffer (std::span< const float > contents, vertex_buffer_layout layout, int32_t binding_point) noexcept
 Construct a new uniform buffer object.
 
 uniform_buffer (vertex_buffer_layout const &layout, int32_t binding_point) noexcept
 Construct a new uniform buffer object.
 
 uniform_buffer (const uniform_buffer &)=delete
 
auto operator= (const uniform_buffer &) -> uniform_buffer &=delete
 
 uniform_buffer (uniform_buffer &&other) noexcept
 Construct a new uniform buffer object by moving it.
 
auto operator= (uniform_buffer &&other) noexcept -> uniform_buffer &
 Move assignment operator.
 
void bind () const
 Bind the uniform to the OpenGL context.
 
void set_attribute_data (std::span< const float > uniform_data, const std::string &name)
 Set the attribute data object.
 
void set_attribute_data (std::span< const float > uniform_data, const std::string &name, std::size_t offset)
 Sets the data of an attribute of the UBO.
 
void set_attribute_data (std::span< const float > uniform_data, size_t attribute_index)
 
void set_attribute_data (std::span< const float > uniform_data, size_t attribute_index, std::size_t offset)
 
 ~uniform_buffer ()
 
constexpr auto binding_point () const noexcept -> int32_t
 Get the binding point.
 
constexpr auto id () const noexcept -> uint32_t
 Get the OpenGL identifier.
 
constexpr auto layout () const noexcept -> vertex_buffer_layout const &
 Gets the UBO's layout.
 

Static Public Member Functions

static void unbind ()
 Unbind any uniform from the OpenGL context.
 

Private Types

using attr_ref = std::reference_wrapper< const vertex_attribute >
 

Private Attributes

std::uint32_t m_id {}
 
int32_t m_binding_point {}
 
std::unordered_map< std::string_view, attr_refm_attr_cache
 
vertex_buffer_layout m_layout
 

Detailed Description

Uniform Buffer Object (UBO) wrapper.

Examples
batches.cpp, and teapot.cpp.

Definition at line 33 of file uniform_buffer.hpp.

Member Typedef Documentation

◆ attr_ref

using staplegl::uniform_buffer::attr_ref = std::reference_wrapper<const vertex_attribute>
private

Definition at line 149 of file uniform_buffer.hpp.

Constructor & Destructor Documentation

◆ uniform_buffer() [1/4]

staplegl::uniform_buffer::uniform_buffer ( std::span< const float >  contents,
vertex_buffer_layout  layout,
int32_t  binding_point 
)
inlinenoexcept

Construct a new uniform buffer object.

Warning
The driver will not respect the given layout 1:1, especially in terms of alignment. It is best to avoid using vec3 (as they might introduce padding) and explicitly specify an alignment standard such as std140 on every GLSL file that uses the uniform.
Parameters
contentsA buffer of floats that will be used to initialize the uniform buffer's contents
layoutThe layout of the UBO
binding_pointThe point on which this UBO will be bound

Definition at line 158 of file uniform_buffer.hpp.

◆ uniform_buffer() [2/4]

staplegl::uniform_buffer::uniform_buffer ( vertex_buffer_layout const &  layout,
int32_t  binding_point 
)
inlinenoexcept

Construct a new uniform buffer object.

Warning
The driver will not respect the given layout 1:1, especially in terms of alignment. It is best to avoid using vec3 (as they might introduce padding) and explicitly specify an alignment standard such as std140 on every GLSL file that uses the uniform.
Parameters
layoutThe layout of the UBO
binding_pointThe point on which this UBO will be bound

Definition at line 178 of file uniform_buffer.hpp.

◆ uniform_buffer() [3/4]

staplegl::uniform_buffer::uniform_buffer ( const uniform_buffer )
delete

◆ uniform_buffer() [4/4]

staplegl::uniform_buffer::uniform_buffer ( uniform_buffer &&  other)
inlinenoexcept

Construct a new uniform buffer object by moving it.

Note
the move constructor simply copies the underlying OpenGL identifier, it is very cheap and leaves the other object with an ID of 0.
Parameters
otherthe other object

Definition at line 212 of file uniform_buffer.hpp.

◆ ~uniform_buffer()

staplegl::uniform_buffer::~uniform_buffer ( )
inline

Definition at line 205 of file uniform_buffer.hpp.

Member Function Documentation

◆ bind()

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

Bind the uniform to the OpenGL context.

Examples
batches.cpp, and teapot.cpp.

Definition at line 195 of file uniform_buffer.hpp.

◆ binding_point()

constexpr auto staplegl::uniform_buffer::binding_point ( ) const -> int32_t
inlineconstexprnoexcept

Get the binding point.

Returns
int32_t the binding point of this UBO.

Definition at line 132 of file uniform_buffer.hpp.

◆ id()

constexpr auto staplegl::uniform_buffer::id ( ) const -> uint32_t
inlineconstexprnoexcept

Get the OpenGL identifier.

Returns
uint32_t the OpenGL identifier

Definition at line 139 of file uniform_buffer.hpp.

◆ layout()

constexpr auto staplegl::uniform_buffer::layout ( ) const -> vertex_buffer_layout const&
inlineconstexprnoexcept

Gets the UBO's layout.

Returns
vertex_buffer_layout const& The layout of the uniform buffer object

Definition at line 146 of file uniform_buffer.hpp.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

Move assignment operator.

Parameters
otherthe other uniform buffer object
Returns
uniform_buffer& a reference to the uniform buffer object

Definition at line 221 of file uniform_buffer.hpp.

◆ set_attribute_data() [1/4]

void staplegl::uniform_buffer::set_attribute_data ( std::span< const float >  uniform_data,
const std::string &  name 
)
inline

Set the attribute data object.

Warning
This method does NOT bind the UBO, so you should make sure that the UBO is bound before calling this method.
Parameters
attributethe attribute to set the data of.
namethe name of the attribute.

Definition at line 236 of file uniform_buffer.hpp.

◆ set_attribute_data() [2/4]

void staplegl::uniform_buffer::set_attribute_data ( std::span< const float >  uniform_data,
const std::string &  name,
std::size_t  offset 
)
inline

Sets the data of an attribute of the UBO.

Warning
This method does NOT bind the UBO, so you should make sure that the UBO is bound before calling this method.
Parameters
attributethe name of the attribute to set the data of.
namethe name of the attribute.
offsetthe offset of the data interval to set inside the attribute (always 0 for non-array attributes, can vary for array attributes).

Definition at line 241 of file uniform_buffer.hpp.

◆ set_attribute_data() [3/4]

void staplegl::uniform_buffer::set_attribute_data ( std::span< const float >  uniform_data,
size_t  attribute_index 
)
inline

Definition at line 251 of file uniform_buffer.hpp.

◆ set_attribute_data() [4/4]

void staplegl::uniform_buffer::set_attribute_data ( std::span< const float >  uniform_data,
size_t  attribute_index,
std::size_t  offset 
)
inline

Definition at line 256 of file uniform_buffer.hpp.

◆ unbind()

void staplegl::uniform_buffer::unbind ( )
inlinestatic

Unbind any uniform from the OpenGL context.

Definition at line 200 of file uniform_buffer.hpp.

Member Data Documentation

◆ m_attr_cache

std::unordered_map<std::string_view, attr_ref> staplegl::uniform_buffer::m_attr_cache
private

Definition at line 153 of file uniform_buffer.hpp.

◆ m_binding_point

int32_t staplegl::uniform_buffer::m_binding_point {}
private

Definition at line 152 of file uniform_buffer.hpp.

◆ m_id

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

Definition at line 151 of file uniform_buffer.hpp.

◆ m_layout

vertex_buffer_layout staplegl::uniform_buffer::m_layout
private

Definition at line 154 of file uniform_buffer.hpp.


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