Unravel Engine C++ Reference
Loading...
Searching...
No Matches
rendering_system.cpp
Go to the documentation of this file.
1#include "rendering_system.h"
2
6
10#include <engine/engine.h>
11#include <engine/events.h>
12
15
19
20namespace unravel
21{
22
24{
25 APPLOG_TRACE("{}::{}", hpp::type_name_str(*this), __func__);
26 auto& ev = ctx.get_cached<events>();
27
28 ev.on_frame_end.connect(sentinel_, 1000, this, &rendering_system::on_frame_end);
29
30 debug_draw_callbacks_.reserve(128);
31 return true;
32}
33
35{
36 APPLOG_TRACE("{}::{}", hpp::type_name_str(*this), __func__);
37
38 return true;
39}
40
42{
43 debug_draw_callbacks_.clear();
44}
45
47{
48 auto& ctx = engine::context();
49 ctx.get_cached<transform_system>().on_frame_update(scn, dt);
50 ctx.get_cached<camera_system>().on_frame_update(scn, dt);
51 ctx.get_cached<model_system>().on_frame_update(scn, dt);
52 ctx.get_cached<animation_system>().on_frame_update(scn, dt);
53 ctx.get_cached<reflection_probe_system>().on_frame_update(scn, dt);
54}
55
57{
58 auto& ctx = engine::context();
59 ctx.get_cached<model_system>().on_frame_before_render(scn, dt);
60 ctx.get_cached<camera_system>().on_frame_before_render(scn, dt);
61
62}
63
64void rendering_system::on_play_begin(hpp::span<const entt::handle> entities, delta_t dt)
65{
66 auto& ctx = engine::context();
67 ctx.get_cached<transform_system>().on_play_begin(entities, dt);
68 ctx.get_cached<camera_system>().on_play_begin(entities, dt);
69 ctx.get_cached<model_system>().on_play_begin(entities, dt);
70 ctx.get_cached<animation_system>().on_play_begin(entities, dt);
71 ctx.get_cached<reflection_probe_system>().on_play_begin(entities, dt);
72}
73
74auto rendering_system::render_scene(entt::handle camera_ent, camera_component& camera_comp, scene& scn, delta_t dt)
76{
77 auto& pipeline_data = camera_comp.get_pipeline_data();
78 auto& camera = pipeline_data.get_camera();
79 auto& pipeline = pipeline_data.get_pipeline();
80 auto& rview = camera_comp.get_render_view();
81
82 auto params = pipeline->create_run_params(camera_ent);
83
84 auto result = pipeline->run_pipeline(scn, camera, rview, dt, params, camera_comp.get_render_mask());
85
86 render_debug(camera_ent);
87
88 return result;
89}
90
92{
94 scn.registry->view<camera_component>().each(
95 [&](auto e, auto&& camera_comp)
96 {
97 auto handle = scn.create_handle(e);
98 output = render_scene(handle, camera_comp, scn, dt);
99 return;
100 });
101
102 return output;
103}
104
106 entt::handle camera_ent,
107 camera_component& camera_comp,
108 scene& scn,
109 delta_t dt)
110{
111 auto& pipeline_data = camera_comp.get_pipeline_data();
112 auto& camera = pipeline_data.get_camera();
113 auto& pipeline = pipeline_data.get_pipeline();
114 auto& rview = camera_comp.get_render_view();
115
116 auto params = pipeline->create_run_params(camera_ent);
117
118 pipeline->run_pipeline(output, scn, camera, rview, dt, params, camera_comp.get_render_mask());
119 render_debug(camera_ent);
120}
121
123{
124
125 scn.registry->view<camera_component>().each(
126 [&](auto e, auto&& camera_comp)
127 {
128 auto handle = scn.create_handle(e);
129 render_scene(output, handle, camera_comp, scn, dt);
130 });
131}
132
133void rendering_system::render_debug(entt::handle camera_entity)
134{
135 if(debug_draw_callbacks_.empty())
136 {
137 return;
138 }
139
140 auto& camera_comp = camera_entity.get<camera_component>();
141 const auto& rview = camera_comp.get_render_view();
142 const auto& camera = camera_comp.get_camera();
143 const auto& view = camera.get_view();
144 const auto& proj = camera.get_projection();
145 const auto& obuffer = rview.fbo_get("OBUFFER");
146
147 gfx::render_pass pass("debug_draw_pass");
148 pass.bind(obuffer.get());
149 pass.set_view_proj(view, proj);
150
151 gfx::dd_raii dd(pass.id);
152
153 for(const auto& callback : debug_draw_callbacks_)
154 {
155 callback(dd);
156 }
157}
158
159void rendering_system::add_debugdraw_call(const std::function<void(gfx::dd_raii& dd)>& callback)
160{
161 debug_draw_callbacks_.emplace_back(callback);
162}
163
164} // namespace unravel
Class that contains core camera data, used for rendering and other purposes.
auto get_pipeline_data() -> pipeline_camera &
auto get_render_mask() const -> layer_mask
Gets the effective render mask (include - exclude).
auto get_render_view() -> gfx::render_view &
Gets the render view.
Class representing a camera. Contains functionality for manipulating and updating a camera....
Definition camera.h:35
void on_play_begin(hpp::span< const entt::handle > entities, delta_t dt)
auto init(rtti::context &ctx) -> bool
Initializes the rendering path with the given context.
void add_debugdraw_call(const std::function< void(gfx::dd_raii &dd)> &callback)
void on_frame_update(scene &scn, delta_t dt)
Prepares the scene for rendering.
void on_frame_before_render(scene &scn, delta_t dt)
void on_frame_end(rtti::context &ctx, delta_t)
auto render_scene(scene &scn, delta_t dt) -> gfx::frame_buffer::ptr
Renders the scene and returns the frame buffer.
auto deinit(rtti::context &ctx) -> bool
Deinitializes the rendering path with the given context.
std::chrono::duration< float > delta_t
#define APPLOG_TRACE(...)
Definition logging.h:17
static auto context() -> rtti::context &
Definition engine.cpp:115
hpp::event< void(rtti::context &, delta_t)> on_frame_end
Definition events.h:20
Represents a scene in the ACE framework, managing entities and their relationships.
Definition scene.h:21
std::unique_ptr< entt::registry > registry
The registry that manages all entities in the scene.
Definition scene.h:117
auto create_handle(entt::entity e) -> entt::handle
Creates an entity in the scene.
Definition scene.cpp:304
gfx::uniform_handle handle
Definition uniform.cpp:9