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
VertexBatch.cpp
Go to the documentation of this file.
1
7
8#include "galaxy/error/Log.hpp"
9
10#include "VertexBatch.hpp"
11
12namespace galaxy
13{
14 namespace graphics
15 {
17 : m_max_quads {0}
18 , m_index {0}
19 {
20 }
21
23 {
24 this->m_vao = std::move(s.m_vao);
25 this->m_max_quads = s.m_max_quads;
26 this->m_index = s.m_index;
27 }
28
30 {
31 if (this != &s)
32 {
33 this->m_vao = std::move(s.m_vao);
34 this->m_max_quads = s.m_max_quads;
35 this->m_index = s.m_index;
36 }
37
38 return *this;
39 }
40
44
45 void VertexBatch::init(const int max_quads)
46 {
47 m_max_quads = max_quads;
48
49 if (m_max_quads > 0)
50 {
51 meta::vector<unsigned int> indices;
52 indices.reserve(m_max_quads * 6);
53
54 auto increment = 0;
55 for (auto counter = 0; counter < m_max_quads; counter++)
56 {
57 indices.push_back(0 + increment);
58 indices.push_back(1 + increment);
59 indices.push_back(3 + increment);
60 indices.push_back(1 + increment);
61 indices.push_back(2 + increment);
62 indices.push_back(3 + increment);
63
64 increment += 4;
65 }
66
68 }
69 else
70 {
71 GALAXY_LOG(GALAXY_FATAL, "Attempted to create vertexbatch with 0 quads.");
72 }
73 }
74
75 int VertexBatch::push(std::span<Vertex> vertices)
76 {
77 if (!(((m_index + vertices.size()) / 4) > m_max_quads))
78 {
80 m_index += 4;
81
82 return m_index - 4;
83 }
84 else
85 {
86 GALAXY_LOG(GALAXY_FATAL, "Attempted to upload too many quads to a vertexbatch.");
87 return -1;
88 }
89 }
90
91 void VertexBatch::sub_buffer(const unsigned int index, std::span<Vertex> vertices)
92 {
94 }
95
97 {
98 m_vao.vbo().clear();
99 }
100
102 {
103 return m_vao;
104 }
105 } // namespace graphics
106} // namespace galaxy
#define GALAXY_LOG(level, msg,...)
Definition Log.hpp:28
#define GALAXY_FATAL
Definition Log.hpp:25
thread_local const float vertices[]
Video.cpp galaxy.
Definition Video.cpp:19
thread_local const unsigned int indices[]
Definition Video.cpp:21
Abstraction for OpenGL vertex array objects.
void buffer(std::span< Vertex > vertices, std::span< unsigned int > indicies)
Create vertex array object.
void sub_buffer(const unsigned int index, std::span< Vertex > vertices)
Sub-buffer vertex array.
VertexBuffer & vbo()
Get vertex buffer.
Batches together vertex data to reduce draw calls.
VertexArray & vao()
Get vertex array object.
void clear()
Clears out vertex buffer.
int m_max_quads
Maximum quads allowed.
int push(std::span< Vertex > vertices)
Buffer some vertices into the spritebatch.
VertexBatch & operator=(VertexBatch &&)
Move assignment operator.
void sub_buffer(const unsigned int index, std::span< Vertex > vertices)
Sub-buffer vertex object.
VertexArray m_vao
Vertex data.
void init(const int max_quads)
Initialize vertex batch data.
void clear()
Clear buffer data.
Animated.cpp galaxy.
Definition Animated.cpp:16