2#ifndef LIBSBX_SCENES_DEBUG_SUBRENDERER_HPP_
3#define LIBSBX_SCENES_DEBUG_SUBRENDERER_HPP_
7#include <libsbx/math/vector4.hpp>
10#include <libsbx/graphics/subrenderer.hpp>
11#include <libsbx/graphics/render_graph.hpp>
12#include <libsbx/graphics/pipeline/graphics_pipeline.hpp>
13#include <libsbx/graphics/buffers/push_handler.hpp>
14#include <libsbx/graphics/buffers/storage_handler.hpp>
15#include <libsbx/graphics/descriptor/descriptor_handler.hpp>
17#include <libsbx/scenes/scenes_module.hpp>
19namespace sbx::scenes {
26 .depth = sbx::graphics::depth::disabled,
27 .uses_transparency =
false,
29 .polygon_mode = sbx::graphics::polygon_mode::fill,
30 .cull_mode = sbx::graphics::cull_mode::none,
31 .front_face = sbx::graphics::front_face::counter_clockwise
33 .primitive_topology = sbx::graphics::primitive_topology::line_list
40 pipeline(
const std::filesystem::path& path,
const std::vector<graphics::attachment_description>& attachments)
41 : base_type{path, attachments, pipeline_definition} { }
43 ~pipeline()
override =
default;
49 debug_subrenderer(
const std::vector<graphics::attachment_description>& attachments,
const std::filesystem::path& path)
51 _pipeline{path, attachments},
52 _push_handler{_pipeline},
53 _descriptor_handler{_pipeline, 0u} {
54 auto& graphics_module = core::engine::get_module<graphics::graphics_module>();
56 _storage_buffer = graphics_module.add_resource<
graphics::storage_buffer>(graphics::storage_buffer::min_size, VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
64 auto& graphics_module = core::engine::get_module<graphics::graphics_module>();
65 auto&
scenes_module = sbx::core::engine::get_module<sbx::scenes::scenes_module>();
75 auto camera_node =
scene.camera();
79 const auto& projection =
camera.projection();
81 const auto view = sbx::math::matrix4x4::inverted(
scene.world_transform(camera_node));
83 _pipeline.bind(command_buffer);
87 const auto required_size =
static_cast<std::uint32_t
>(lines.size() *
sizeof(
scenes_module::line));
89 if (storage_buffer.size() < required_size) {
90 storage_buffer.resize(
static_cast<std::size_t
>(
static_cast<std::float_t
>(required_size) * 1.5f));
93 storage_buffer.update(lines.data(), required_size);
95 _push_handler.push(
"mvp", projection * view);
96 _push_handler.push(
"vertices", storage_buffer.address());
99 if (!_descriptor_handler.update(_pipeline)) {
103 _descriptor_handler.bind_descriptors(command_buffer);
104 _push_handler.bind(command_buffer);
106 command_buffer.draw(
static_cast<std::uint32_t
>(lines.size()), 1u, 0u, 0u);
Definition: command_buffer.hpp:15
Definition: descriptor_handler.hpp:26
Definition: graphics_pipeline.hpp:113
Definition: push_handler.hpp:18
Definition: resource_storage.hpp:18
Definition: storage_buffer.hpp:17
Definition: subrenderer.hpp:14
Definition: camera.hpp:96
Definition: debug_subrenderer.hpp:21
Definition: scenes_module.hpp:21
RGBA color representation and utilities.
Definition: graphics_pipeline.hpp:104
Definition: graphics_pipeline.hpp:65
Definition: scenes_module.hpp:29