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
RenderSystem.cpp
Go to the documentation of this file.
1
7
13
14#include "RenderSystem.hpp"
15
16namespace galaxy
17{
18 namespace systems
19 {
20 template<typename GC>
21 void add_cmd(entt::registry& registry)
22 {
23 const auto group = registry.group<GC>(entt::get<components::Transform>, entt::exclude<flags::Disabled>);
24
25 for (auto&& [entity, gc, tf] : group.each())
26 {
28
29 if constexpr ((std::is_same_v<GC, components::Circle>) || (std::is_same_v<GC, components::Ellipse>) || (std::is_same_v<GC, components::Point>) ||
30 (std::is_same_v<GC, components::Polygon>) || (std::is_same_v<GC, components::Polyline>))
31 {
32 graphics::Shape* shape = &gc.m_shape;
33
34 cmd.count = shape->vao().count();
35 cmd.instances = shape->vao().instances();
36 cmd.mode = shape->mode();
37 cmd.offset = shape->vao().offset();
38 cmd.vao = shape->vao().id();
39 cmd.texture = 0;
40 cmd.uniforms.colour = shape->m_colour.vec4();
41 cmd.uniforms.entity = static_cast<int>(entt::to_integral(entity));
42 cmd.uniforms.textured = false;
43 cmd.uniforms.point = shape->mode() == GL_POINTS ? true : false;
44 }
45 else if constexpr (std::is_same<GC, components::Sprite>::value)
46 {
47 cmd.count = gc.m_vao.count();
48 cmd.instances = gc.m_vao.instances();
49 cmd.mode = GL_TRIANGLES;
50 cmd.offset = gc.m_vao.offset();
51 cmd.vao = gc.m_vao.id();
52 cmd.texture = gc.get_texture()->id();
53 cmd.uniforms.colour = gc.m_tint.vec4();
54 cmd.uniforms.entity = static_cast<int>(entt::to_integral(entity));
55 cmd.uniforms.textured = true;
56 cmd.uniforms.point = false;
57 }
58 else if constexpr (std::is_same<GC, components::Text>::value)
59 {
60 cmd.count = gc.m_text.vao().count();
61 cmd.instances = gc.m_text.vao().instances();
62 cmd.mode = GL_TRIANGLES;
63 cmd.offset = gc.m_text.vao().offset();
64 cmd.vao = gc.m_text.vao().id();
65 cmd.texture = gc.m_text.render_texture().texture();
66 cmd.uniforms.colour = gc.m_text.m_colour.vec4();
67 cmd.uniforms.entity = static_cast<int>(entt::to_integral(entity));
68 cmd.uniforms.textured = true;
69 cmd.uniforms.point = false;
70 }
71 else if constexpr (std::is_same_v<GC, components::TileMap>)
72 {
73 cmd.count = gc.m_batch.vao().count();
74 cmd.instances = 1;
75 cmd.layer = gc.m_render_layer;
76 cmd.mode = GL_TRIANGLES;
77 cmd.offset = gc.m_batch.vao().offset();
78 cmd.vao = gc.m_batch.vao().id();
79 cmd.texture = gc.get_texture()->id();
80 cmd.uniforms.colour = gc.m_tint;
81 cmd.uniforms.entity = static_cast<int>(entt::to_integral(entity));
82 cmd.uniforms.textured = true;
83 cmd.uniforms.point = false;
84 }
85
86 cmd.uniforms.transform = tf.m_tf.get_transform();
88 }
89 }
90
91 template<typename... GC>
92 void handle_renderables(entt::registry& registry)
93 {
94 (add_cmd<GC>(registry), ...);
95 }
96
100
104
117 } // namespace systems
118} // namespace galaxy
A sprite is a texture with vertex data.
Definition Sprite.hpp:25
String of glyphs rendered with a font.
Definition Text.hpp:22
Rendering data for a single level/map in a LDTK world.
Definition TileMap.hpp:22
glm::vec4 & vec4()
Get vec4.
Definition Colour.cpp:160
void submit_cmd(RenderCommand &command)
Add an entity rendering command.
Definition Renderer.cpp:81
static Renderer & ref()
Get reference to renderer singleton.
Definition Renderer.cpp:19
A generic 2D shape.
Definition Shape.hpp:22
Colour m_colour
Used by all primitives.
Definition Shape.hpp:84
VertexArray & vao()
Get vertex array object.
Definition Shape.cpp:65
unsigned int mode() const
Get OpenGL rendering mode.
Definition Shape.cpp:50
int count() const
Get the index count.
void * offset()
Gets index offset.
int instances() const
Number of instances to render.
unsigned int id() const
Get vertex array handle.
virtual ~RenderSystem()
Destructor.
void update(entt::registry &registry) override
Abstract implementation for updating the system. Use the manager to retreive your components.
void handle_renderables(entt::registry &registry)
void add_cmd(entt::registry &registry)
Animated.cpp galaxy.
Definition Animated.cpp:16
Data to be passed to the renderer.
unsigned int mode
Type to render i.e. GL_LINES, GL_TRIANGLES, etc.
unsigned int vao
OpenGL vertex array object.
unsigned int count
OpenGL index (element) buffer count.
void * offset
Offset in vertex buffer marking beginning of element data.
int instances
Number of instances to render.
int layer
Layer to render on.
RenderData uniforms
Shader uniform data.
glm::mat4 transform
Orthographic transform.
bool textured
Are we rendering as a texture.
glm::vec4 colour
Colour / tint.
bool point
Is this being rendered with GL_POINTS.