Brenta Engine 1.2
Loading...
Searching...
No Matches
renderer.hpp
1// SPDX-License-Identifier: MIT
2// Author: Giovanni Santini
3// Mail: giovanni.santini@proton.me
4
5#pragma once
6
7#include <brenta/renderer/camera.hpp>
8#include <brenta/text.hpp>
9
10#include <glm/vec3.hpp>
11#include <glm/mat4x4.hpp>
12
13#include <tenno/vector.hpp>
14#include <tenno/memory.hpp>
15
16namespace brenta
17{
18
19class Model;
20class PointLight;
21class DirLight;
22class Skybox;
23class RenderPipeline;
24
25//
26// Renderer
27// --------
28//
29// The renderer is a logical abtraction that is responsible to draw a
30// "rendering unit" aka render command. When the renderer is flushed,
31// or when `end_frame()` is called, all render commands will be
32// drawn.
33//
34// Its usage usually looks like this:
35//
36// Renderer::begin_frame(camera);
37//
38// Renderer::submit({world_matrix, model});
39// Renderer::submit({world_matrix2, model2});
40// Renderer::submit_point_light(light);
41// // ...
42//
43// Renderer::end_frame(); // draws everything
44//
46{
47public:
48
49 struct Command;
50 struct RenderData;
51
52 Renderer() = delete;
53 ~Renderer() = delete;
54
55 // You can begin a frame withouth a camera, but eventually you will
56 // have to call set_camera if you want to see anything
57 static void begin_frame();
58 static void begin_frame(Camera &cam, int width, int height);
59
60 static void set_camera(Camera &cam, int width, int height);
61
62 // Transparent commands are rendered after non-transparent ones
63 static void submit(const Renderer::Command& it, bool transparent = false);
64 static void submit_point_light(tenno::shared_ptr<PointLight> point_light);
65 static void submit_point_lights(const tenno::vector<tenno::shared_ptr<PointLight>>& point_light);
66 static void submit_dir_light(tenno::shared_ptr<DirLight> dir_light);
67 static void submit_text(const Text& text);
68 static void submit_skybox(tenno::shared_ptr<Skybox> skybox);
69
70 static void end_frame(tenno::shared_ptr<RenderPipeline> pipeline);
71
72 // Draw and clear state
73 static void flush(tenno::shared_ptr<RenderPipeline> pipeline);
74 // Clear all state
75 static void clear();
76
77private:
78
79 static RenderData data;
80
81};
82
84{
85 glm::mat4 world_matrix;
86 tenno::shared_ptr<Model> model;
87
88 Command() = default;
89 Command(glm::mat4 world_matrix,
90 tenno::shared_ptr<Model> model)
91 : world_matrix(world_matrix), model(model) {}
92};
93
95{
96 glm::mat4 projection;
97 glm::mat4 view;
98 glm::vec3 cam_position;
99 int width;
100 int height;
101
102 tenno::vector<Command> opaque_queue;
103 tenno::vector<Command> transparent_queue;
104 tenno::vector<Text> ui_queue;
105
106 tenno::vector<tenno::shared_ptr<PointLight>> point_lights;
107 std::optional<tenno::shared_ptr<DirLight>> dir_light;
108 std::optional<tenno::shared_ptr<Skybox>> skybox;
109};
110
111} // namespace brenta