lmgl 1.0.0
A lightweight OpenGL graphics engine library written in C++
Loading...
Searching...
No Matches
buffer.hpp
Go to the documentation of this file.
1
12
13#pragma once
14
15#include <cstddef>
16#include <initializer_list>
17#include <string>
18#include <vector>
19
20namespace lmgl {
21
22namespace renderer {
23
33enum class ShaderDataType { None = 0, Float, Float2, Float3, Float4, Mat3, Mat4, Int, Int2, Int3, Int4, Bool };
34
45
47 std::string name;
48
51
53 unsigned int size;
54
56 size_t offset;
57
60
62 BufferElement() = default;
63
74 BufferElement(ShaderDataType type, const std::string &name, bool normalized = false);
75
84 unsigned int get_component_count() const;
85};
86
97 public:
100
109 BufferLayout(const std::initializer_list<BufferElement> &elements);
110
118 inline unsigned int get_stride() const { return m_stride; }
119
128 inline const std::vector<BufferElement> &get_elements() const { return m_elements; }
129
138 std::vector<BufferElement>::iterator begin();
139
148 std::vector<BufferElement>::iterator end();
149
158 std::vector<BufferElement>::const_iterator begin() const;
159
168 std::vector<BufferElement>::const_iterator end() const;
169
170 private:
177 void calculate_offsets_and_stride();
178
180 std::vector<BufferElement> m_elements;
181
183 unsigned int m_stride = 0;
184};
185
196 public:
207 VertexBuffer(const void *vertices, unsigned int size, bool dynamic = false);
208
211
217 void bind() const;
218
224 void unbind() const;
225
234 void set_data(const void *data, unsigned int size);
235
244 void set_layout(const BufferLayout &layout);
245
254 const BufferLayout &get_layout() const;
255
256 private:
258 unsigned int m_renderer_id;
259
261 unsigned int m_count;
262
264 BufferLayout m_layout;
265};
266
277 public:
286 IndexBuffer(const unsigned int *indices, unsigned int count);
287
289 ~IndexBuffer();
290
296 void bind() const;
297
303 void unbind() const;
304
312 inline unsigned int get_count() const { return m_count; }
313
314 private:
316 unsigned int m_renderer_id;
317
319 unsigned int m_count;
320};
321
322} // namespace renderer
323
324} // namespace lmgl
Defines the layout of a buffer, consisting of multiple buffer elements.
Definition buffer.hpp:96
unsigned int get_stride() const
Get the stride of the buffer layout.
Definition buffer.hpp:118
BufferLayout()
Default constructor.
Definition buffer.hpp:99
std::vector< BufferElement >::iterator end()
End iterator for mutable access.
Definition buffer.cpp:62
std::vector< BufferElement >::iterator begin()
Iterator support for the buffer layout elements.
Definition buffer.cpp:60
const std::vector< BufferElement > & get_elements() const
Get the elements of the buffer layout.
Definition buffer.hpp:128
IndexBuffer(const unsigned int *indices, unsigned int count)
Constructor for the IndexBuffer.
Definition buffer.cpp:99
unsigned int get_count() const
Get the count of indices in the buffer.
Definition buffer.hpp:312
void unbind() const
Unbind the index buffer.
Definition buffer.cpp:109
~IndexBuffer()
Destructor for the IndexBuffer.
Definition buffer.cpp:105
void bind() const
Bind the index buffer.
Definition buffer.cpp:107
~VertexBuffer()
Destructor for the VertexBuffer.
Definition buffer.cpp:82
VertexBuffer(const void *vertices, unsigned int size, bool dynamic=false)
Constructor for the VertexBuffer.
Definition buffer.cpp:76
void bind() const
Bind the vertex buffer.
Definition buffer.cpp:84
void set_data(const void *data, unsigned int size)
Set the data of the vertex buffer.
Definition buffer.cpp:88
void unbind() const
Unbind the vertex buffer.
Definition buffer.cpp:86
void set_layout(const BufferLayout &layout)
Set the layout of the vertex buffer.
Definition buffer.cpp:93
const BufferLayout & get_layout() const
Get the layout of the vertex buffer.
Definition buffer.cpp:95
Namespace for rendering-related classes and functions.
Definition buffer.cpp:9
ShaderDataType
Enumerates the various data types used in shaders.
Definition buffer.hpp:33
Forward declarations for Assimp Material structure.
Definition model_loader.cpp:12
size_t offset
Offset of the buffer element within the buffer.
Definition buffer.hpp:56
std::string name
Name of the buffer element.
Definition buffer.hpp:47
ShaderDataType type
Data type of the buffer element.
Definition buffer.hpp:50
bool normalized
Indicates if the data is normalized.
Definition buffer.hpp:59
unsigned int size
Size of the buffer element in bytes.
Definition buffer.hpp:53
BufferElement()=default
Default constructor.
unsigned int get_component_count() const
Get the number of components in the buffer element.
Definition buffer.cpp:33