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
8
#include "
galaxy/logging/Log.hpp
"
9
10
#include "
ShaderBuffer.hpp
"
11
12
namespace
galaxy
13
{
14
ShaderBuffer::ShaderBuffer
()
15
: m_id {0}
16
, m_index {-1}
17
{
18
glCreateBuffers(1, &
m_id
);
19
}
20
21
ShaderBuffer::ShaderBuffer
(
const
GLBufferBinding
index)
22
: m_id {0}
23
, m_index {static_cast<int>(index)}
24
{
25
glCreateBuffers(1, &
m_id
);
26
}
27
28
ShaderBuffer::ShaderBuffer
(
ShaderBuffer
&& s)
noexcept
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
38
ShaderBuffer
&
ShaderBuffer::operator=
(
ShaderBuffer
&& s)
noexcept
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
53
ShaderBuffer::~ShaderBuffer
()
54
{
55
destroy
();
56
}
57
58
void
ShaderBuffer::set_index
(
const
GLBufferBinding
index)
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
73
void
ShaderBuffer::unbind
()
const
74
{
75
glBindBufferBase(GL_SHADER_STORAGE_BUFFER,
m_index
, 0);
76
}
77
78
void
ShaderBuffer::clear
()
const
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
86
void
ShaderBuffer::destroy
()
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
Log.hpp
GALAXY_LOG
#define GALAXY_LOG(level, msg,...)
Definition
Log.hpp:28
GALAXY_FATAL
#define GALAXY_FATAL
Definition
Log.hpp:25
ShaderBuffer.hpp
galaxy::ShaderBuffer
OpenGL Shader storage buffer.
Definition
ShaderBuffer.hpp:21
galaxy::ShaderBuffer::bind
void bind() const
Bind buffer.
Definition
ShaderBuffer.cpp:63
galaxy::ShaderBuffer::ShaderBuffer
ShaderBuffer()
Constructor.
Definition
ShaderBuffer.cpp:14
galaxy::ShaderBuffer::clear
void clear() const
Clears data from buffer.
Definition
ShaderBuffer.cpp:78
galaxy::ShaderBuffer::unbind
void unbind() const
Unbind buffer.
Definition
ShaderBuffer.cpp:73
galaxy::ShaderBuffer::~ShaderBuffer
~ShaderBuffer()
Destructor.
Definition
ShaderBuffer.cpp:53
galaxy::ShaderBuffer::id
unsigned int id() const noexcept
Get OpenGL handle.
Definition
ShaderBuffer.cpp:95
galaxy::ShaderBuffer::operator=
ShaderBuffer & operator=(ShaderBuffer &&) noexcept
Move assignment operator.
Definition
ShaderBuffer.cpp:38
galaxy::ShaderBuffer::m_index
int m_index
Index binding of SSBO in vertex shader.
Definition
ShaderBuffer.hpp:130
galaxy::ShaderBuffer::set_index
void set_index(const GLBufferBinding index)
Set vertex shader binding point.
Definition
ShaderBuffer.cpp:58
galaxy::ShaderBuffer::m_id
unsigned int m_id
OpenGL handle.
Definition
ShaderBuffer.hpp:125
galaxy::ShaderBuffer::destroy
void destroy()
Destroy shader.
Definition
ShaderBuffer.cpp:86
galaxy
Animated.cpp galaxy.
Definition
Animated.cpp:16
galaxy::GLBufferBinding
GLBufferBinding
Binding point for GPU buffers.
Definition
Enums.hpp:49
galaxy
src
galaxy
graphics
gl
ShaderBuffer.cpp
Generated on Sun Dec 28 2025 14:14:28 for galaxy by
1.12.0