Sparkle 0.0.1
Loading...
Searching...
No Matches
spk_index_buffer_object.hpp
1#pragma once
2
3#include "structure/opengl/spk_buffer_object.hpp"
4#include "structure/opengl/spk_opengl_includes.hpp"
5#include <cstdint>
6#include <initializer_list>
7#include <span>
8#include <vector>
9
10namespace spk
11{
12 namespace OpenGL
13 {
20 {
21 private:
30
31 public:
36 IndexBufferObject(Usage p_usage);
41 IndexBufferObject(const IndexBufferObject &p_other) = default;
47 IndexBufferObject &operator=(const IndexBufferObject &p_other) = default;
48
53 void reserve(size_t p_nbIndexes);
58 void resize(size_t p_nbIndexes);
59
64 void setIndexes(const std::vector<uint32_t> &p_indexes);
65
70 void pushIndex(uint32_t p_index);
75 void pushIndexes(const std::vector<uint32_t> &p_indexes);
80 void pushIndexes(std::initializer_list<uint32_t> p_values);
81
86 size_t nbIndexes() const;
91 size_t nbTriangles() const;
96 std::vector<uint32_t> pull() const;
97
102 std::span<uint32_t> indices();
107 std::span<const uint32_t> indices() const;
108 };
109
110 using IBO = IndexBufferObject;
111 }
112}
void reserve(size_t p_size)
Reserves CPU-side storage without changing size.
Definition spk_buffer_object.cpp:104
void pushData(const void *p_data, size_t p_size)
Appends raw data to CPU buffer.
Definition spk_buffer_object.cpp:132
Buffer::value_type * data()
Mutable pointer to underlying bytes.
Definition spk_buffer_object.cpp:183
Usage
Usage hints forwarded to the OpenGL driver.
Definition spk_buffer_object.hpp:61
void resize(size_t p_size)
Resizes CPU-side buffer and marks for sync.
Definition spk_buffer_object.cpp:109
void swapData(std::vector< uint8_t > &p_data)
Swaps CPU staging buffer with external vector.
Definition spk_buffer_object.cpp:114
void editData(const void *p_data, size_t p_offset, size_t p_size)
Overwrites a range of the CPU buffer.
Definition spk_buffer_object.cpp:144
BufferObject(const Type &p_type, const Usage &p_usage)
Constructs a buffer with target type and usage hint.
Definition spk_buffer_object.cpp:45
size_t size() const
Returns the current CPU buffer size.
Definition spk_buffer_object.cpp:168
void setData(const std::vector< TType > &p_data)
Replaces buffer contents with a vector of trivially copyable values.
Definition spk_buffer_object.hpp:154
Convenience wrapper for element array buffers storing 32-bit indices.
Definition spk_index_buffer_object.hpp:20
size_t nbIndexes() const
Returns the number of stored indices.
Definition spk_index_buffer_object.cpp:49
size_t nbTriangles() const
Returns the number of triangles (indices / 3).
Definition spk_index_buffer_object.cpp:54
void reserve(size_t p_nbIndexes)
Reserves capacity for a number of indices.
Definition spk_index_buffer_object.cpp:19
void pushIndex(uint32_t p_index)
Appends a single index.
Definition spk_index_buffer_object.cpp:34
std::vector< uint32_t > pull() const
Returns a copy of the indices.
Definition spk_index_buffer_object.cpp:59
IndexBufferObject(const IndexBufferObject &p_other)=default
Copies buffer configuration and stored indices.
void setIndexes(const std::vector< uint32_t > &p_indexes)
Replaces indices by moving a vector.
Definition spk_index_buffer_object.cpp:29
IndexBufferObject(Usage p_usage)
Constructs an index buffer with a usage hint.
Definition spk_index_buffer_object.cpp:14
std::span< uint32_t > indices()
Mutable span over index data.
Definition spk_index_buffer_object.cpp:77
IndexBufferObject & operator=(const IndexBufferObject &p_other)=default
Assigns index buffer contents from another instance.
void resize(size_t p_nbIndexes)
Resizes index storage and marks for sync.
Definition spk_index_buffer_object.cpp:24
void pushIndexes(const std::vector< uint32_t > &p_indexes)
Appends multiple indices from vector.
Definition spk_index_buffer_object.cpp:39