galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
InstanceBuffer.cpp
Go to the documentation of this file.
1
7
8#include <glad/glad.h>
9
10#include "InstanceBuffer.hpp"
11
12namespace galaxy
13{
14 namespace graphics
15 {
16
18 : m_id {0}
19 , m_amount {0}
20 {
21 glCreateBuffers(1, &m_id);
22 }
23
25 {
26 this->m_id = i.m_id;
27 this->m_amount = i.m_amount;
28
29 i.m_id = 0;
30 }
31
33 {
34 if (this != &i)
35 {
36 this->m_id = i.m_id;
37 this->m_amount = i.m_amount;
38
39 i.m_id = 0;
40 }
41
42 return *this;
43 }
44
46 {
47 if (m_id != 0)
48 {
49 glDeleteBuffers(1, &m_id);
50 }
51 }
52
53 void InstanceBuffer::buffer(std::span<glm::mat4> transforms)
54 {
55 m_amount = static_cast<int>(transforms.size());
56 glNamedBufferData(m_id, transforms.size_bytes(), transforms.data(), GL_DYNAMIC_DRAW);
57 }
58
59 void InstanceBuffer::sub_buffer(const unsigned int index, std::span<glm::mat4> transforms)
60 {
61 glNamedBufferSubData(m_id, index * sizeof(glm::mat4), transforms.size_bytes(), transforms.data());
62 }
63
65 {
66 glNamedBufferData(m_id, m_amount * sizeof(glm::mat4), nullptr, GL_DYNAMIC_DRAW);
67 }
68
70 {
71 return m_amount;
72 }
73
74 unsigned int InstanceBuffer::id() const
75 {
76 return m_id;
77 }
78 } // namespace graphics
79} // namespace galaxy
Abstraction for OpenGL vertex buffer objects.
InstanceBuffer & operator=(InstanceBuffer &&)
Move assignment operator.
int m_amount
Number of instances.
unsigned int id() const
Get OpenGL handle.
void buffer(std::span< glm::mat4 > transforms)
Create instance buffer.
void clear()
Clear buffer data.
void sub_buffer(const unsigned int index, std::span< glm::mat4 > transforms)
Sub-buffer instances.
int amount() const
Get the amount of instances.
unsigned int m_id
ID returned by OpenGL when generating buffer.
Animated.cpp galaxy.
Definition Animated.cpp:16