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 <easy/profiler.h>
9
10#include <libsbx/utility/noncopyable.hpp>
11#include <libsbx/utility/concepts.hpp>
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_graph.hpp>
21#include <libsbx/graphics/draw_list.hpp>
22#include <libsbx/graphics/viewport.hpp>
23
24namespace sbx::graphics {
25
27
28public:
29
30 renderer() = default;
31
32 virtual ~renderer() = default;
33
34 // virtual auto initialize() -> void = 0;
35
36 auto render(command_buffer& command_buffer, const swapchain& swapchain) -> void {
37 _graph.execute(command_buffer, swapchain, [this, &command_buffer](const auto& pass_name) {
38 if (auto entry = _subrenderers.find(pass_name); entry != _subrenderers.end()) {
39 for (auto& subrenderer : entry->second) {
40 subrenderer->render(command_buffer);
41 }
42 }
43 });
44 }
45
46 auto execute_tasks(command_buffer& command_buffer) -> void {
47 for (const auto& task : _tasks) {
48 task->execute(command_buffer);
49 }
50 }
51
52 auto resize(const viewport::type flags) -> void {
53 _graph.resize(flags);
54 }
55
56 auto attachment(const std::string& name) const -> const descriptor& {
57 return _graph.attachment(name);
58 }
59
60protected:
61
62 template<typename Type, typename... Args>
63 requires (std::is_constructible_v<Type, const render_graph::graphics_pass&, Args...>)
64 auto add_subrenderer(const render_graph::graphics_pass& pass, Args&&... args) -> Type& {
65 auto& subrenderers = _subrenderers[pass.name()];
66
67 subrenderers.emplace_back(std::make_unique<Type>(pass, std::forward<Args>(args)...));
68
69 return *static_cast<Type*>(subrenderers.back().get());
70 }
71
72 template<typename Type, typename... Args>
73 requires (std::is_constructible_v<Type, Args...>)
74 auto add_draw_list(const utility::hashed_string& name, Args&&... args) -> Type& {
75 return _graph.add_draw_list<Type>(name, std::forward<Args>(args)...);
76 }
77
78 template<typename... Callables>
79 requires (sizeof...(Callables) > 1u)
80 auto create_graph(Callables&&... callables) -> decltype(auto) {
81 auto passes = _graph.emplace(std::forward<Callables>(callables)...);
82
83 _graph.build();
84
85 return passes;
86 }
87
88 // template<typename Type, typename... Args>
89 // requires (std::is_constructible_v<Type, std::filesystem::path, Args...>)
90 // auto add_task(const std::filesystem::path& path, Args&&... args) -> Type& {
91 // _tasks.push_back(std::make_unique<Type>(path, std::forward<Args>(args)...));
92
93 // return *static_cast<Type*>(_tasks.back().get());
94 // }
95
96private:
97
98 std::vector<std::unique_ptr<graphics::task>> _tasks;
99
100 std::unordered_map<utility::hashed_string, std::vector<std::unique_ptr<subrenderer>>> _subrenderers;
101
102 render_graph _graph;
103
104}; // class renderer
105
106} // namespace sbx::graphics
107
108#endif // LIBSBX_GRAPHICS_RENDERER_HPP_
Definition: command_buffer.hpp:14
Definition: renderer.hpp:26
Definition: swapchain.hpp:12
Definition: task.hpp:8
Definition: noncopyable.hpp:6