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
Renderer.cpp
Go to the documentation of this file.
1
7
10
11#include "Renderer.hpp"
12
13#ifdef GALAXY_WIN_PLATFORM
16#endif
17
18namespace galaxy
19{
21 : m_quads {Settings::max_quads(), 4, galaxy::graphics::gen_default_indices()}
22 , m_pass {nullptr}
23 , m_pipeline {nullptr}
24 {
27 }
28
30 {
31 m_pass = nullptr;
32 m_pipeline = nullptr;
33 }
34
36 {
38
39 m_commands.clear();
40 m_uniform_data.clear();
41
42 m_pass = nullptr;
43 m_pipeline = nullptr;
44 }
45
47 {
48 glBindFramebuffer(GL_FRAMEBUFFER, pass.target);
49 glViewport(pass.viewport.x, pass.viewport.y, pass.viewport.z, pass.viewport.w);
50 glScissor(pass.scissor.x, pass.scissor.y, pass.scissor.z, pass.scissor.w);
51
52 glClearColor(pass.clear_col.x, pass.clear_col.y, pass.clear_col.z, pass.clear_col.w);
53 glClearDepth(pass.clear_depth);
54 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
55
56 m_pass = &pass;
57 }
58
60 {
61 for (const auto& feature : pipeline.enabled)
62 {
63 glEnable(feature);
64 }
65
66 for (const auto& feature : pipeline.disabled)
67 {
68 glDisable(feature);
69 }
70
71 glCullFace(pipeline.cull_face);
72 glDepthFunc(pipeline.depth_func);
73 glBlendEquation(pipeline.blend_equation);
74 glBlendFunc(GL_SRC_ALPHA, pipeline.blend_function);
75
76 glUseProgram(pipeline.shader);
77 glActiveTexture(GL_TEXTURE0);
78
79 // There is no texture sampler object to bind because we use bindless textures.
80
81 m_pipeline = &pipeline;
82 }
83
85 {
86 // Add uniform data first.
87 m_uniform_data.emplace_back(std::move(cmd.data));
88
89 // Our index will always be the last inserted element at the time.
90 const auto index = m_uniform_data.size() - 1;
91
92 // update uniform data location.
93 for (auto& vert : cmd.vertices)
94 {
95 vert.m_index = index;
96 }
97
98 // We want to batch quads and just draw the rest regularly.
99 if (cmd.type == GLRenderMode::QUADS)
100 {
101 m_quads.push(cmd.vertices);
102 }
103 else
104 {
105 m_commands.emplace_back(cmd);
106 }
107 }
108
110 {
112 m_camera_storage.buffer(1, &camera.get_data());
113
116
117 m_quads.flush();
118 m_quads.bind();
119
120 glDrawElements(GL_TRIANGLES, m_quads.count(), GL_UNSIGNED_INT, m_quads.offset());
121
122 for (const auto& cmd : m_commands)
123 {
124 cmd.vao->bind();
125 glDrawElements(static_cast<unsigned int>(cmd.type), cmd.vao->count(), GL_UNSIGNED_INT, cmd.vao->offset());
126 }
127 }
128} // namespace galaxy
129
130#ifdef GALAXY_WIN_PLATFORM
132#endif
#define GALAXY_DISABLE_WARNING_POP
Definition Pragma.hpp:57
#define GALAXY_DISABLE_WARNING(x)
Definition Pragma.hpp:58
#define GALAXY_DISABLE_WARNING_PUSH
Macro for windows platform detection.
Definition Pragma.hpp:56
Orthographic 2D camera.
Definition Camera.hpp:20
Data & get_data() noexcept
Get camera view and proj.
Definition Camera.cpp:246
ShaderBuffer m_camera_storage
Definition Renderer.hpp:87
std::vector< RenderCmd > m_commands
RenderCommands.
Definition Renderer.hpp:70
std::vector< RenderData > m_uniform_data
Definition Renderer.hpp:89
void end_pass(Camera &camera)
Definition Renderer.cpp:109
ShaderBuffer m_uniform_storage
Shader uniform data.
Definition Renderer.hpp:85
VertexBatch m_quads
All quads get batched.
Definition Renderer.hpp:65
void push_cmd(RenderCmd &&cmd)
Try not to push too many non-quads, only quads are batched.
Definition Renderer.cpp:84
void bind_pipeline(RenderPipeline &pipeline)
Definition Renderer.cpp:59
RenderPass * m_pass
Definition Renderer.hpp:75
void begin_pass(RenderPass &pass)
Definition Renderer.cpp:46
void prepare()
Called only in the update loop when we need to refresh data to render.
Definition Renderer.cpp:35
RenderPipeline * m_pipeline
Definition Renderer.hpp:80
void bind() const
Bind buffer.
void buffer(const unsigned int count, Object *data)
Buffer data.
void set_index(const GLBufferBinding index)
Set vertex shader binding point.
void bind() const noexcept
Bind this batchs vertex array object.
void push(const std::vector< Vertex > &vertices) noexcept
Add vertex and index data to batch.
void flush() noexcept
Copy all data to GPU.
int count() const noexcept
Get the index count.
void prepare() noexcept
Sets up counters to begin pushing vertices.
void * offset() noexcept
Gets index offset.
Animated.cpp galaxy.
Definition Animated.cpp:16
@ UNIFORMS
Shader uniforms.
@ CAMERA
Camera transform data.
Data required to draw an object.
The configuration for drawing something.
glm::vec4 scissor
OpenGL scissor region. https://gamedev.stackexchange.com/a/40713.
glm::vec4 viewport
This is the glViewport. z,w is width/height.
unsigned int target
This is the framebuffer to draw to.
glm::vec4 clear_col
Colour buffer clear colour.
float clear_depth
Depth buffer clear depth.
GPU configuration.
unsigned int blend_equation
glBlendEquation.
unsigned int cull_face
glCullFace.
std::vector< unsigned int > enabled
glEnable features.
unsigned int blend_function
glBlendFunc for GL_SRC_ALPHA.
unsigned int depth_func
glDepthFunc.
std::vector< unsigned int > disabled
glDisable features.
unsigned int shader
Pipeline Ubershader.
Helper class to encapsulate our global settings we want to quickly access across app.
Definition Settings.hpp:23