Unravel Engine C++ Reference
Loading...
Searching...
No Matches
rendering_system.cpp
Go to the documentation of this file.
1#include "rendering_system.h"
2#include "particle_system.h"
3
8
12#include <engine/engine.h>
13#include <engine/events.h>
14
17
21
22namespace unravel
23{
24
26{
27 APPLOG_TRACE("{}::{}", hpp::type_name_str(*this), __func__);
28 auto& ev = ctx.get_cached<events>();
29
30 ev.on_frame_end.connect(sentinel_, 1000, this, &rendering_system::on_frame_end);
31
32 debug_draw_callbacks_.reserve(128);
33 return true;
34}
35
37{
38 APPLOG_TRACE("{}::{}", hpp::type_name_str(*this), __func__);
39
40 return true;
41}
42
44{
45 debug_draw_callbacks_.clear();
46}
47
49{
50 auto& ctx = engine::context();
51 ctx.get_cached<transform_system>().on_frame_update(scn, dt);
52 ctx.get_cached<camera_system>().on_frame_update(scn, dt);
53 ctx.get_cached<model_system>().on_frame_update(scn, dt);
54 ctx.get_cached<animation_system>().on_frame_update(scn, dt);
55 ctx.get_cached<reflection_probe_system>().on_frame_update(scn, dt);
56}
57
59{
60 auto& ctx = engine::context();
61 ctx.get_cached<model_system>().on_frame_before_render(scn, dt);
62 ctx.get_cached<camera_system>().on_frame_before_render(scn, dt);
63 ctx.get_cached<particle_system>().on_frame_before_render(scn, dt);
64
65
66}
67
68void rendering_system::on_play_begin(hpp::span<const entt::handle> entities, delta_t dt)
69{
70 auto& ctx = engine::context();
71 ctx.get_cached<transform_system>().on_play_begin(entities, dt);
72 ctx.get_cached<camera_system>().on_play_begin(entities, dt);
73 ctx.get_cached<model_system>().on_play_begin(entities, dt);
74 ctx.get_cached<animation_system>().on_play_begin(entities, dt);
75 ctx.get_cached<reflection_probe_system>().on_play_begin(entities, dt);
76}
77
78auto rendering_system::render_scene(entt::handle camera_ent, camera_component& camera_comp, scene& scn, delta_t dt)
80{
81 auto& pipeline_data = camera_comp.get_pipeline_data();
82 auto& camera = pipeline_data.get_camera();
83 auto& pipeline = pipeline_data.get_pipeline();
84 auto& rview = camera_comp.get_render_view();
85
86 auto params = pipeline->create_run_params(camera_ent);
87
88 auto result = pipeline->run_pipeline(scn, camera, rview, dt, params, camera_comp.get_render_mask());
89
90 render_debug(camera_ent);
91
92 return result;
93}
94
96{
98 scn.registry->view<camera_component>().each(
99 [&](auto e, auto&& camera_comp)
100 {
101 auto handle = scn.create_handle(e);
102 output = render_scene(handle, camera_comp, scn, dt);
103 return;
104 });
105
106 return output;
107}
108
110 entt::handle camera_ent,
111 camera_component& camera_comp,
112 scene& scn,
113 delta_t dt)
114{
115 auto& pipeline_data = camera_comp.get_pipeline_data();
116 auto& camera = pipeline_data.get_camera();
117 auto& pipeline = pipeline_data.get_pipeline();
118 auto& rview = camera_comp.get_render_view();
119
120 auto params = pipeline->create_run_params(camera_ent);
121
122 pipeline->run_pipeline(output, scn, camera, rview, dt, params, camera_comp.get_render_mask());
123
124 render_debug(camera_ent);
125}
126
128{
129
130 scn.registry->view<camera_component>().each(
131 [&](auto e, auto&& camera_comp)
132 {
133 auto handle = scn.create_handle(e);
134 render_scene(output, handle, camera_comp, scn, dt);
135 });
136}
137
138void rendering_system::render_debug(entt::handle camera_entity)
139{
140 if(debug_draw_callbacks_.empty())
141 {
142 return;
143 }
144
145 auto& camera_comp = camera_entity.get<camera_component>();
146 const auto& rview = camera_comp.get_render_view();
147 const auto& camera = camera_comp.get_camera();
148 const auto& view = camera.get_view();
149 const auto& proj = camera.get_projection();
150 const auto& obuffer = rview.fbo_get("OBUFFER");
151
152 gfx::render_pass pass("debug_draw_pass");
153 pass.bind(obuffer.get());
154 pass.set_view_proj(view, proj);
155
156 gfx::dd_raii dd(pass.id);
157
158 for(const auto& callback : debug_draw_callbacks_)
159 {
160 callback(dd);
161 }
162}
163
164void rendering_system::add_debugdraw_call(const std::function<void(gfx::dd_raii& dd)>& callback)
165{
166 debug_draw_callbacks_.emplace_back(callback);
167}
168
169
170} // 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
System that manages and updates particle emitters in the ECS.
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:116
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:307
gfx::uniform_handle handle
Definition uniform.cpp:9