39concept plain_old_data = std::is_standard_layout_v<T> && std::is_trivial_v<T>;
130 void set_data(std::span<const
float> vertices) const noexcept;
149 [[nodiscard]] constexpr auto
id() const noexcept -> std::uint32_t {
return m_id; }
157 [[nodiscard]]
constexpr auto size() const noexcept -> std::
size_t {
return m_size; }
195 template <plain_old_data T>
214 , m_layout(std::move(layout))
215 , m_size((m_layout.stride()) ? vertices.size_bytes() / m_layout.stride() : static_cast<size_t>(0))
217 glGenBuffers(1, &m_id);
218 glBindBuffer(GL_ARRAY_BUFFER, m_id);
219 glBufferData(GL_ARRAY_BUFFER,
static_cast<ptrdiff_t
>(vertices.size_bytes()), vertices.data(), hint);
240 glDeleteBuffers(1, &
m_id);
245 : m_id { other.m_id }
246 , m_hint { other.m_hint }
247 , m_layout { std::move(other.m_layout) }
248 , m_size { other.m_size }
255 if (
this != &other) {
256 glDeleteBuffers(1, &m_id);
258 m_layout = other.m_layout;
259 m_hint = other.m_hint;
260 m_size = other.m_size;
270 glBindBuffer(GL_ARRAY_BUFFER,
m_id);
275 glBindBuffer(GL_ARRAY_BUFFER, 0);
291 this->set_data(vertices, m_hint);
296 glBindBuffer(GL_ARRAY_BUFFER, m_id);
297 glBufferData(GL_ARRAY_BUFFER,
static_cast<ptrdiff_t
>(vertices.size_bytes()), vertices.data(), hint);
300template <plain_old_data T>
303 glBindBuffer(GL_ARRAY_BUFFER, m_id);
305 func(std::span {
reinterpret_cast<T*
>(glMapBuffer(GL_ARRAY_BUFFER, access_specifier)),
308 glUnmapBuffer(GL_ARRAY_BUFFER);
constexpr auto stride() const noexcept -> std::size_t
Get the stride of the vertex buffer layout.
Vertex Buffer Object (VBO) wrapper.
constexpr auto layout() const -> const vertex_buffer_layout &
vertex_buffer_layout m_layout
constexpr auto draw_hint() const noexcept -> driver_draw_hint
Return the driver draw hint of the vertex buffer object.
vertex_buffer(const vertex_buffer &)=delete
void set_layout(const vertex_buffer_layout &layout)
Set the layout object.
staplegl::driver_draw_hint m_hint
auto operator=(const vertex_buffer &) -> vertex_buffer &=delete
void apply(const std::function< void(std::span< T > vertices)> &func, driver_access_specifier access_specifier=staplegl::READ_WRITE) noexcept
Applies a function to the vertices of the vertex buffer object.
void bind() const
Bind the vertex buffer object.
static void unbind()
Unbind the vertex buffer object.
vertex_buffer(std::span< const float > vertices) noexcept
Construct a new vertex buffer object.
constexpr auto size_bytes() const noexcept -> std::size_t
Get the size of the vertex buffer object in bytes.
constexpr auto size() const noexcept -> std::size_t
Get the number of vertices in the vertex buffer object.
void set_data(std::span< const float > vertices) const noexcept
Give new data to the vertex buffer object, overwriting the old one.
Concept that specifies that a type is a Plain Old Data (POD) type.
driver_draw_hint
Enum that specifies the usage hint of a buffer.
driver_access_specifier
Enum that specifies the access specifier of a buffer.
Vertex Buffer Layout abstraction.