sandbox
Loading...
Searching...
No Matches
renderer.hpp
1#ifndef LIBSBX_GRAPHICS_RENDERER_HPP_
2#define LIBSBX_GRAPHICS_RENDERER_HPP_
3
4#include <memory>
5#include <vector>
6#include <typeindex>
7
8#include <libsbx/utility/noncopyable.hpp>
9#include <libsbx/utility/concepts.hpp>
11
13
14#include <libsbx/graphics/commands/command_buffer.hpp>
15
16#include <libsbx/graphics/pipeline/pipeline.hpp>
17
18#include <libsbx/graphics/task.hpp>
19#include <libsbx/graphics/subrenderer.hpp>
20#include <libsbx/graphics/render_stage.hpp>
21#include <libsbx/graphics/render_graph.hpp>
22
23namespace sbx::graphics {
24
26
27public:
28
29 renderer() = default;
30
31 virtual ~renderer() = default;
32
33 virtual auto initialize() -> void = 0;
34
35 auto render(const pipeline::stage& stage, command_buffer& command_buffer) -> void {
36 for (const auto& [render_stage, index] : _subrenderer_stages) {
37 if (render_stage == stage) {
38 _subrenderers[index]->render(command_buffer);
39 }
40 }
41 }
42
43 auto execute_tasks(command_buffer& command_buffer) -> void {
44 for (const auto& task : _tasks) {
45 task->execute(command_buffer);
46 }
47 }
48
49 auto add_render_stage(std::vector<attachment>&& attachments, std::vector<subpass_binding>&& subpass_bindings, const viewport& viewport = graphics::viewport{}) -> void {
50 _render_stages.push_back(std::make_unique<graphics::render_stage>(std::move(attachments), std::move(subpass_bindings), viewport));
51 }
52
53 auto render_stages() const noexcept -> const std::vector<std::unique_ptr<graphics::render_stage>>& {
54 return _render_stages;
55 }
56
58 return *_render_stages.at(stage.renderpass);
59 }
60
61protected:
62
63 // template<utility::implements<subrenderer> Type, typename... Args>
64 template<typename Type, typename... Args>
65 requires (std::is_constructible_v<Type, const std::filesystem::path&, const pipeline::stage&, Args...>)
66 auto add_subrenderer(const std::filesystem::path& path, const pipeline::stage& stage, Args&&... args) -> Type& {
67 _subrenderer_stages.insert({stage, _subrenderers.size()});
68
69 _subrenderers.push_back(std::make_unique<Type>(path, stage, std::forward<Args>(args)...));
70
71 return *static_cast<Type*>(_subrenderers.back().get());
72 }
73
74 template<typename Type, typename... Args>
75 requires (std::is_constructible_v<Type, std::filesystem::path, Args...>)
76 auto add_task(const std::filesystem::path& path, Args&&... args) -> Type& {
77 _tasks.push_back(std::make_unique<Type>(path, std::forward<Args>(args)...));
78
79 return *static_cast<Type*>(_tasks.back().get());
80 }
81
82private:
83
84 std::vector<std::unique_ptr<graphics::task>> _tasks;
85
86 std::vector<std::unique_ptr<graphics::render_stage>> _render_stages;
87
88 std::vector<std::unique_ptr<subrenderer>> _subrenderers;
89 std::multimap<pipeline::stage, std::size_t> _subrenderer_stages;
90
91 render_graph _graph;
92
93}; // class renderer
94
95} // namespace sbx::graphics
96
97#endif // LIBSBX_GRAPHICS_RENDERER_HPP_
Definition: command_buffer.hpp:14
Definition: render_graph.hpp:43
Definition: render_stage.hpp:216
Definition: renderer.hpp:25
Definition: task.hpp:8
Definition: render_stage.hpp:125
Definition: pipeline.hpp:22
Definition: noncopyable.hpp:6