sandbox
Loading...
Searching...
No Matches
sprite_subrenderer.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_SPRITES_SPRITE_SUBRENDERER_HPP_
3#define LIBSBX_SPRITES_SPRITE_SUBRENDERER_HPP_
4
5#include <unordered_map>
6#include <array>
7
8#include <magic_enum/magic_enum.hpp>
9
10#include <libsbx/utility/fast_mod.hpp>
11#include <libsbx/utility/enum.hpp>
12
13#include <libsbx/core/engine.hpp>
14
15#include <libsbx/math/vector2.hpp>
16#include <libsbx/math/vector3.hpp>
17#include <libsbx/math/matrix4x4.hpp>
18
19#include <libsbx/graphics/subrenderer.hpp>
20#include <libsbx/graphics/graphics_module.hpp>
21
22#include <libsbx/graphics/pipeline/compiler.hpp>
23
24#include <libsbx/graphics/images/image.hpp>
25#include <libsbx/graphics/images/sampler_state.hpp>
26#include <libsbx/graphics/images/separate_image2d_array.hpp>
27#include <libsbx/graphics/images/depth_image.hpp>
28
29#include <libsbx/graphics/buffers/push_handler.hpp>
30#include <libsbx/graphics/buffers/uniform_handler.hpp>
31
32#include <libsbx/graphics/descriptor/descriptor_handler.hpp>
33
34#include <libsbx/scenes/scenes_module.hpp>
35
36#include <libsbx/sprites/sprites_module.hpp>
37
38namespace sbx::sprites {
39
41
42 static constexpr auto mode_count = magic_enum::enum_count<sprite_space>();
43
44 struct pipeline_key {
45 sprite_space space;
46
47 auto operator==(const pipeline_key& other) const -> bool = default;
48 }; // struct pipeline_key
49
50 struct pipeline_key_hash {
51 auto operator()(const pipeline_key& key) const -> std::size_t;
52 }; // struct pipeline_key_hash
53
54 struct pipeline_data {
56 graphics::push_handler push_handler;
57 graphics::descriptor_handler descriptor_handler;
58
59 pipeline_data(const graphics::graphics_pipeline_handle& handle);
60
61 }; // struct pipeline_data
62
63 inline static const auto default_shader_path = std::string_view{"engine://shaders/sprites"};
64
65public:
66
67 sprite_subrenderer(const std::vector<graphics::attachment_description>& attachments, const std::filesystem::path& path = default_shader_path);
68
69 ~sprite_subrenderer() override = default;
70
71 auto render(graphics::command_buffer& command_buffer) -> void override;
72
73private:
74
75 auto _get_or_create_pipeline(sprite_space space) -> pipeline_data&;
76
77 auto _update_buffer(sprite_space space) -> graphics::storage_buffer&;
78
79 auto _render_batch(graphics::command_buffer& command_buffer, sprite_space space) -> void;
80
81 inline static const auto _mode_specializations = std::array<std::string, 3u>{
82 "screen_overlay_mode",
83 "screen_camera_mode",
84 "world_space_mode"
85 };
86
87 std::vector<graphics::attachment_description> _attachments;
88 std::filesystem::path _shader_path;
89
90 std::unordered_map<pipeline_key, pipeline_data, pipeline_key_hash> _pipeline_cache;
91
92 std::array<graphics::storage_buffer_handle, mode_count> _sprite_buffers;
93
95
96}; // class sprite_subrenderer
97
98} // namespace sbx::sprites
99
100#endif // LIBSBX_SPRITES_SPRITE_SUBRENDERER_HPP_
Definition: command_buffer.hpp:15
Definition: descriptor_handler.hpp:26
Definition: push_handler.hpp:18
Definition: resource_storage.hpp:18
Definition: sampler_state.hpp:11
Definition: storage_buffer.hpp:17
Definition: subrenderer.hpp:14
Definition: sprite_subrenderer.hpp:40