24#include <unordered_map>
102 void set_attribute_data(std::span<const float> uniform_data,
const std::string& name);
114 void set_attribute_data(std::span<const float> uniform_data,
const std::string& name, std::size_t offset);
117 size_t attribute_index);
120 size_t attribute_index,
139 constexpr auto id() const noexcept -> uint32_t {
return m_id; }
149 using attr_ref = std::reference_wrapper<const vertex_attribute>;
159 : m_binding_point { binding_point }
160 , m_layout { std::move(layout) }
162 glGenBuffers(1, &m_id);
163 glBindBuffer(GL_UNIFORM_BUFFER, m_id);
164 glBufferData(GL_UNIFORM_BUFFER,
165 static_cast<ptrdiff_t
>(contents.size_bytes()),
168 glBindBufferBase(GL_UNIFORM_BUFFER, m_binding_point, m_id);
170 glBindBuffer(GL_UNIFORM_BUFFER, 0);
173 for (
auto const& attr : m_layout.get_attributes()) {
174 m_attr_cache.emplace(attr.name, std::cref(attr));
179 : m_binding_point { binding_point }
180 , m_layout { layout }
182 glGenBuffers(1, &m_id);
183 glBindBuffer(GL_UNIFORM_BUFFER, m_id);
184 glBufferData(GL_UNIFORM_BUFFER,
static_cast<std::ptrdiff_t
>(layout.stride()),
nullptr, GL_DYNAMIC_DRAW);
185 glBindBufferBase(GL_UNIFORM_BUFFER, m_binding_point, m_id);
187 glBindBuffer(GL_UNIFORM_BUFFER, 0);
190 for (
auto const& attr : m_layout.get_attributes()) {
191 m_attr_cache.emplace(attr.name, std::cref(attr));
197 glBindBuffer(GL_UNIFORM_BUFFER,
m_id);
202 glBindBuffer(GL_UNIFORM_BUFFER, 0);
208 glDeleteBuffers(1, &
m_id);
213 : m_id { other.m_id }
214 , m_binding_point { other.m_binding_point }
215 , m_attr_cache { std::move(other.m_attr_cache) }
216 , m_layout { std::move(other.m_layout) }
223 if (
this != &other) {
224 glDeleteBuffers(1, &m_id);
226 m_binding_point = other.m_binding_point;
227 m_layout = std::move(other.m_layout);
228 m_attr_cache = std::move(other.m_attr_cache);
245 glBufferSubData(GL_UNIFORM_BUFFER,
246 static_cast<ptrdiff_t
>(attr.get().offset + offset *
sizeof(
float)),
247 static_cast<ptrdiff_t
>(uniform_data.size_bytes()),
248 uniform_data.data());
258 auto const& attr =
m_layout[attribute_index];
260 glBufferSubData(GL_UNIFORM_BUFFER,
261 static_cast<ptrdiff_t
>(attr.offset + offset *
sizeof(
float)),
262 static_cast<ptrdiff_t
>(uniform_data.size_bytes()),
263 uniform_data.data());
Vertex Buffer Layout abstraction.