sandbox
Loading...
Searching...
No Matches
grid_subrenderer.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_SCENES_GRID_SUBRENDERER_HPP_
3#define LIBSBX_SCENES_GRID_SUBRENDERER_HPP_
4
5#include <libsbx/math/vector4.hpp>
7
8#include <libsbx/graphics/subrenderer.hpp>
9#include <libsbx/graphics/pipeline/graphics_pipeline.hpp>
10#include <libsbx/graphics/buffers/push_handler.hpp>
11#include <libsbx/graphics/buffers/storage_handler.hpp>
12#include <libsbx/graphics/descriptor/descriptor_handler.hpp>
13
14namespace sbx::scenes {
15
17
18 class pipeline : public sbx::graphics::graphics_pipeline {
19
20 inline static const auto pipeline_definition = sbx::graphics::pipeline_definition{
21 .depth = sbx::graphics::depth::read_only,
22 .uses_transparency = true,
23 .rasterization_state = sbx::graphics::rasterization_state{
24 .polygon_mode = sbx::graphics::polygon_mode::fill,
25 .cull_mode = sbx::graphics::cull_mode::none,
26 .front_face = sbx::graphics::front_face::counter_clockwise
27 }
28 };
29
30 using base_type = sbx::graphics::graphics_pipeline;
31
32 public:
33
34 pipeline(const std::filesystem::path& path, const std::vector<graphics::attachment_description>& attachments)
35 : base_type{path, attachments, pipeline_definition} { }
36
37 ~pipeline() override = default;
38
39 }; // class pipeline
40
41public:
42
43 grid_subrenderer(const std::vector<graphics::attachment_description>& attachments, const std::filesystem::path& path)
45 _pipeline{path, attachments},
46 _push_handler{_pipeline},
47 _descriptor_handler{_pipeline, 0u} { }
48
49 ~grid_subrenderer() override {
50
51 }
52
53 auto render(sbx::graphics::command_buffer& command_buffer) -> void override {
54 auto& scenes_module = sbx::core::engine::get_module<sbx::scenes::scenes_module>();
55 auto& scene = scenes_module.scene();
56
57 auto camera_node = scene.camera();
58
59 auto& camera = scene.get_component<sbx::scenes::camera>(camera_node);
60
61 const auto& projection = camera.projection();
62
63 const auto camera_position = scene.world_position(camera_node);
64
65 const auto view = sbx::math::matrix4x4::inverted(scene.world_transform(camera_node));
66
67 _pipeline.bind(command_buffer);
68
69 _push_handler.push("mvp", projection * view);
70 _push_handler.push("camera_position", camera_position);
71 _push_handler.push("origin", sbx::math::vector4::zero);
72
73 // _descriptor_handler.push("push", _push_handler);
74
75 if (!_descriptor_handler.update(_pipeline)) {
76 return;
77 }
78
79 _descriptor_handler.bind_descriptors(command_buffer);
80 _push_handler.bind(command_buffer);
81
82 command_buffer.draw(6u, 1u, 0u, 0u);
83 }
84
85private:
86
87 pipeline _pipeline;
88
89 sbx::graphics::push_handler _push_handler;
90
91 sbx::graphics::descriptor_handler _descriptor_handler;
92
93}; // class debug_subrenderer
94
95} // namespace sbx::scenes
96
97#endif // LIBSBX_SCENES_GRID_SUBRENDERER_HPP_
Definition: command_buffer.hpp:15
Definition: descriptor_handler.hpp:26
Definition: graphics_pipeline.hpp:113
Definition: push_handler.hpp:18
Definition: subrenderer.hpp:14
Definition: camera.hpp:96
Definition: grid_subrenderer.hpp:16
Definition: scene.hpp:70
Definition: scenes_module.hpp:21
RGBA color representation and utilities.
Definition: graphics_pipeline.hpp:104
Definition: graphics_pipeline.hpp:65