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
12
namespace
galaxy
13
{
14
namespace
graphics
15
{
16
17
InstanceBuffer::InstanceBuffer
()
18
: m_id {0}
19
, m_amount {0}
20
{
21
glCreateBuffers(1, &
m_id
);
22
}
23
24
InstanceBuffer::InstanceBuffer
(
InstanceBuffer
&& i)
25
{
26
this->
m_id
= i.m_id;
27
this->
m_amount
= i.m_amount;
28
29
i.m_id = 0;
30
}
31
32
InstanceBuffer
&
InstanceBuffer::operator=
(
InstanceBuffer
&& i)
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
45
InstanceBuffer::~InstanceBuffer
()
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
64
void
InstanceBuffer::clear
()
65
{
66
glNamedBufferData(
m_id
,
m_amount
*
sizeof
(glm::mat4),
nullptr
, GL_DYNAMIC_DRAW);
67
}
68
69
int
InstanceBuffer::amount
()
const
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
InstanceBuffer.hpp
galaxy::graphics::InstanceBuffer
Abstraction for OpenGL vertex buffer objects.
Definition
InstanceBuffer.hpp:23
galaxy::graphics::InstanceBuffer::~InstanceBuffer
~InstanceBuffer()
Destructor.
Definition
InstanceBuffer.cpp:45
galaxy::graphics::InstanceBuffer::operator=
InstanceBuffer & operator=(InstanceBuffer &&)
Move assignment operator.
Definition
InstanceBuffer.cpp:32
galaxy::graphics::InstanceBuffer::m_amount
int m_amount
Number of instances.
Definition
InstanceBuffer.hpp:100
galaxy::graphics::InstanceBuffer::id
unsigned int id() const
Get OpenGL handle.
Definition
InstanceBuffer.cpp:74
galaxy::graphics::InstanceBuffer::buffer
void buffer(std::span< glm::mat4 > transforms)
Create instance buffer.
Definition
InstanceBuffer.cpp:53
galaxy::graphics::InstanceBuffer::InstanceBuffer
InstanceBuffer()
Constructor.
Definition
InstanceBuffer.cpp:17
galaxy::graphics::InstanceBuffer::clear
void clear()
Clear buffer data.
Definition
InstanceBuffer.cpp:64
galaxy::graphics::InstanceBuffer::sub_buffer
void sub_buffer(const unsigned int index, std::span< glm::mat4 > transforms)
Sub-buffer instances.
Definition
InstanceBuffer.cpp:59
galaxy::graphics::InstanceBuffer::amount
int amount() const
Get the amount of instances.
Definition
InstanceBuffer.cpp:69
galaxy::graphics::InstanceBuffer::m_id
unsigned int m_id
ID returned by OpenGL when generating buffer.
Definition
InstanceBuffer.hpp:95
galaxy
Animated.cpp galaxy.
Definition
Animated.cpp:16
galaxy
src
galaxy
graphics
gl
InstanceBuffer.cpp
Generated on Fri Sep 12 2025 07:29:47 for galaxy by
1.12.0