sandbox
Loading...
Searching...
No Matches
filter.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_POST_FILTER_HPP_
3#define LIBSBX_POST_FILTER_HPP_
4
5#include <string>
6#include <map>
7
8#include <libsbx/graphics/subrenderer.hpp>
9#include <libsbx/graphics/graphics_module.hpp>
10
11#include <libsbx/graphics/pipeline/graphics_pipeline.hpp>
12#include <libsbx/graphics/pipeline/vertex_input_description.hpp>
13
14#include <libsbx/graphics/descriptor/descriptor_handler.hpp>
15
16
17namespace sbx::post {
18
20
21public:
22
24
25 filter(const std::vector<graphics::attachment_description>& attachments, const std::filesystem::path& path, const graphics::pipeline_definition& pipeline_definition = default_pipeline_definition, const VkSpecializationInfo* specialization_info = nullptr)
27 _pipeline{path, attachments, pipeline_definition, specialization_info},
28 _descriptor_handler{_pipeline, 0u} { }
29
30 virtual ~filter() override = default;
31
32 auto descriptor_handler() noexcept -> graphics::descriptor_handler& {
33 return _descriptor_handler;
34 }
35
36 auto pipeline() noexcept -> pipeline_type& {
37 return _pipeline;
38 }
39
40 auto attachment(const std::string& descriptor_name, const graphics::descriptor& descriptor) -> const graphics::descriptor& {
41 if (auto it = _descriptors.find(descriptor_name); it != _descriptors.end()) {
42 return *(it->second);
43 }
44
45 return descriptor;
46 }
47
48 auto attachment(const std::string& descriptor_name, const std::string& render_attachment) -> const graphics::descriptor& {
49 if (auto it = _descriptors.find(descriptor_name); it != _descriptors.end()) {
50 return *(it->second);
51 }
52
53 auto& graphics_module = core::engine::get_module<graphics::graphics_module>();
54
55 return graphics_module.attachment(render_attachment);
56 }
57
58 auto set_attachment(const std::string& descriptor_name, const graphics::descriptor& descriptor) -> void {
59 if (auto entry = _descriptors.find(descriptor_name); entry != _descriptors.end()) {
60 entry->second = &descriptor;
61 } else {
62 _descriptors.emplace(descriptor_name, &descriptor);
63 }
64 }
65
66 auto remove_attachment(const std::string& descriptor_name) -> bool {
67 if (auto it = _descriptors.find(descriptor_name); it != _descriptors.end()) {
68 _descriptors.erase(it);
69 return true;
70 }
71
72 return false;
73 }
74
75protected:
76
77 inline static const auto default_pipeline_definition = graphics::pipeline_definition{
78 .depth = graphics::depth::disabled,
79 .uses_transparency = false,
80 .rasterization_state = graphics::rasterization_state{
81 .polygon_mode = graphics::polygon_mode::fill,
82 .cull_mode = graphics::cull_mode::none,
83 .front_face = graphics::front_face::counter_clockwise
84 }
85 };
86
87private:
88
89 std::map<std::string, memory::observer_ptr<const graphics::descriptor>> _descriptors;
90
91 pipeline_type _pipeline;
92 graphics::descriptor_handler _descriptor_handler;
93
94}; // class filter
95
96} // namespace sbx::post
97
98#endif // LIBSBX_POST_FILTER_HPP_
Definition: descriptor_handler.hpp:26
Definition: descriptor.hpp:38
Definition: graphics_pipeline.hpp:115
Definition: subrenderer.hpp:14
Definition: filter.hpp:19
Definition: graphics_pipeline.hpp:106
Definition: graphics_pipeline.hpp:67