sandbox
Loading...
Searching...
No Matches
skybox_subrenderer.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_SCENES_SKYBOX_SUBRENDERER_HPP_
3#define LIBSBX_SCENES_SKYBOX_SUBRENDERER_HPP_
4
5#include <libsbx/graphics/subrenderer.hpp>
6
7#include <libsbx/graphics/images/cube_image.hpp>
8
9#include <libsbx/graphics/pipeline/graphics_pipeline.hpp>
10#include <libsbx/graphics/pipeline/vertex_input_description.hpp>
11#include <libsbx/graphics/pipeline/mesh.hpp>
12
13#include <libsbx/graphics/descriptor/descriptor_handler.hpp>
14
15#include <libsbx/graphics/buffers/uniform_handler.hpp>
16
17#include <libsbx/assets/assets_module.hpp>
18
19#include <libsbx/scenes/components/skybox.hpp>
20#include <libsbx/scenes/components/camera.hpp>
21
22namespace sbx::scenes {
23
24struct vertex3d {
25 math::vector3 position;
26}; // struct vertex3d
27
28class mesh : public graphics::mesh<vertex3d> {
29
30public:
31
32 mesh(std::vector<vertex3d>&& vertices, std::vector<std::uint32_t>&& indices)
33 : graphics::mesh<vertex3d>{std::move(vertices), std::move(indices)} { }
34
35 ~mesh() override = default;
36
37}; // class mesh
38
40
41 inline static const auto pipeline_definition = graphics::pipeline_definition{
42 .depth = graphics::depth::read_only,
43 .compare_operation = graphics::compare_operation::less_or_equal,
44 .uses_transparency = false,
45 .rasterization_state = graphics::rasterization_state{
46 .polygon_mode = graphics::polygon_mode::fill,
47 .cull_mode = graphics::cull_mode::none,
48 .front_face = graphics::front_face::counter_clockwise
49 }
50 };
51
52 inline static constexpr auto default_shader_path = std::string_view{"engine://shaders/skybox"};
53
54public:
55
56 skybox_subrenderer(const std::vector<graphics::attachment_description>& attachments, const std::filesystem::path& path = default_shader_path)
58 _pipeline{path, attachments, pipeline_definition},
59 _descriptor_handler{_pipeline, 0u},
60 _push_handler{_pipeline} { }
61
62 ~skybox_subrenderer() override = default;
63
64 auto render(graphics::command_buffer& command_buffer) -> void override {
65 EASY_BLOCK("skybox_subrenderer::render", profiler::colors::Indigo500);
66
67 auto& assets_module = core::engine::get_module<assets::assets_module>();
68 auto& graphics_module = core::engine::get_module<graphics::graphics_module>();
69 auto& scenes_module = core::engine::get_module<scenes::scenes_module>();
70
71 auto& scene = scenes_module.active_scene();
72 auto& environment = scene.environment();
73 auto& graph = scene.graph();
74
75 const auto camera_node = environment.camera();
76
77 if (!graph.has_component<scenes::skybox>(camera_node)) {
78 utility::logger<"scenes">::warn("Skybox subrenderer: No camera node with skybox component found");
79 return;
80 }
81
82 const auto& skybox = graph.get_component<scenes::skybox>(camera_node);
83
84 _pipeline.bind(command_buffer);
85
86 _descriptor_handler.push("scene", environment.uniform_handler());
87 _descriptor_handler.push("skybox", graphics_module.get_resource<graphics::cube_image>(skybox.cube_image));
88
89 _push_handler.push("tint", skybox.tint);
90
91 if (!_descriptor_handler.update(_pipeline)) {
92 return;
93 }
94
95 _descriptor_handler.bind_descriptors(command_buffer);
96 _push_handler.bind(command_buffer);
97
98 command_buffer.draw(3u, 1u, 0u, 0u);
99 }
100
101private:
102
104
105 graphics::descriptor_handler _descriptor_handler;
106
107 graphics::push_handler _push_handler;
108
109}; // class skybox_subrenderer
110
111} // namespace sbx::scenes
112
113#endif // LIBSBX_SCENES_SKYBOX_SUBRENDERER_HPP_
Definition: command_buffer.hpp:15
Definition: cube_image.hpp:21
Definition: descriptor_handler.hpp:26
Definition: graphics_pipeline.hpp:115
Definition: mesh.hpp:43
Definition: push_handler.hpp:18
Definition: subrenderer.hpp:14
Definition: vector3.hpp:23
Definition: skybox_subrenderer.hpp:28
Definition: scene.hpp:27
Definition: scenes_module.hpp:26
Definition: skybox_subrenderer.hpp:39
Definition: logger.hpp:124
Definition: graphics_pipeline.hpp:106
Definition: graphics_pipeline.hpp:67
Definition: skybox.hpp:13
Definition: skybox_subrenderer.hpp:24