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
ShaderBuffer.cpp
Go to the documentation of this file.
1
7
9
10#include "ShaderBuffer.hpp"
11
12namespace galaxy
13{
15 : m_id {0}
16 , m_index {-1}
17 {
18 glCreateBuffers(1, &m_id);
19 }
20
22 : m_id {0}
23 , m_index {static_cast<int>(index)}
24 {
25 glCreateBuffers(1, &m_id);
26 }
27
29 {
30 this->destroy();
31
32 this->m_id = s.m_id;
33 this->m_index = s.m_index;
34
35 s.m_id = 0;
36 }
37
39 {
40 if (this != &s)
41 {
42 this->destroy();
43
44 this->m_id = s.m_id;
45 this->m_index = s.m_index;
46
47 s.m_id = 0;
48 }
49
50 return *this;
51 }
52
57
59 {
60 m_index = static_cast<int>(index);
61 }
62
63 void ShaderBuffer::bind() const
64 {
65 if (m_index == -1)
66 {
67 GALAXY_LOG(GALAXY_FATAL, "Tried to bind SSBO with no index.");
68 }
69
70 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, m_index, m_id);
71 }
72
74 {
75 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, m_index, 0);
76 }
77
79 {
80 auto size = 0;
81
82 glGetNamedBufferParameteriv(m_id, GL_BUFFER_SIZE, &size);
83 glNamedBufferData(m_id, size, nullptr, GL_DYNAMIC_DRAW);
84 }
85
87 {
88 if (m_id != 0)
89 {
90 glDeleteBuffers(1, &m_id);
91 m_id = 0;
92 }
93 }
94
95 unsigned int ShaderBuffer::id() const noexcept
96 {
97 return m_id;
98 }
99} // namespace galaxy
#define GALAXY_LOG(level, msg,...)
Definition Log.hpp:28
#define GALAXY_FATAL
Definition Log.hpp:25
OpenGL Shader storage buffer.
void bind() const
Bind buffer.
ShaderBuffer()
Constructor.
void clear() const
Clears data from buffer.
void unbind() const
Unbind buffer.
~ShaderBuffer()
Destructor.
unsigned int id() const noexcept
Get OpenGL handle.
ShaderBuffer & operator=(ShaderBuffer &&) noexcept
Move assignment operator.
int m_index
Index binding of SSBO in vertex shader.
void set_index(const GLBufferBinding index)
Set vertex shader binding point.
unsigned int m_id
OpenGL handle.
void destroy()
Destroy shader.
Animated.cpp galaxy.
Definition Animated.cpp:16
GLBufferBinding
Binding point for GPU buffers.
Definition Enums.hpp:49