sandbox
Loading...
Searching...
No Matches
skinning_task.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_ANIMATIONS_SKINNING_TASK_HPP_
3#define LIBSBX_ANIMATIONS_SKINNING_TASK_HPP_
4
5#include <algorithm>
6#include <cstdint>
7#include <filesystem>
8
9#include <vulkan/vulkan.h>
10
11#include <libsbx/core/engine.hpp>
12
13#include <libsbx/graphics/task.hpp>
14
15#include <libsbx/graphics/graphics_module.hpp>
16#include <libsbx/graphics/commands/command_buffer.hpp>
17
18#include <libsbx/graphics/buffers/storage_buffer.hpp>
19#include <libsbx/graphics/buffers/push_handler.hpp>
20
21#include <libsbx/graphics/pipeline/compute_pipeline.hpp>
22
23#include <libsbx/models/vertex3d.hpp>
24
25namespace sbx::animations {
26
27class skinning_task final : public graphics::task {
28
29 inline static constexpr auto default_pipeline_path = std::string_view{"engine://shaders/skinning"};
30
31public:
32
33 skinning_task(const std::filesystem::path& path = default_pipeline_path);
34
35 ~skinning_task() override;
36
37 auto execute(graphics::command_buffer& command_buffer) -> void override;
38
39 auto vertex_buffer_handle() const -> graphics::storage_buffer_handle;
40
41private:
42
43 template<typename Type>
44 static auto _resize_buffer(graphics::storage_buffer& buffer, std::uint32_t element_count) -> void {
45 const auto required_size = static_cast<std::size_t>(element_count) * sizeof(Type);
46
47 if (buffer.size() < required_size) {
48 buffer.resize(required_size + required_size / 2);
49 }
50 }
51
52 template<typename Type>
53 static auto _update_buffer(graphics::storage_buffer& buffer, const std::vector<Type>& data) -> void {
54 _resize_buffer<Type>(buffer, static_cast<std::uint32_t>(data.size()));
55
56 if (!data.empty()) {
57 buffer.update(data.data(), data.size() * sizeof(Type));
58 }
59 }
60
61 auto _dispatch_skinning(graphics::command_buffer& command_buffer, graphics::buffer::address_type bone_matrices_buffer_address) -> void;
62
63 graphics::storage_buffer_handle _vertex_buffer{};
65
67 graphics::push_handler _push_handler;
68
69}; // class skinning_task
70
71} // namespace sbx::animations
72
73#endif // LIBSBX_ANIMATIONS_SKINNING_TASK_HPP_
Definition: skinning_task.hpp:27
Definition: command_buffer.hpp:15
Definition: compute_pipeline.hpp:18
Definition: push_handler.hpp:18
Definition: resource_storage.hpp:18
Definition: storage_buffer.hpp:17
Definition: task.hpp:9