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
29public:
30
31 skinning_task(const std::filesystem::path& path);
32
33 ~skinning_task() override;
34
35 auto execute(graphics::command_buffer& command_buffer) -> void override;
36
37 auto vertex_buffer_handle() const -> graphics::storage_buffer_handle;
38
39private:
40
41 template<typename Type>
42 static auto _resize_buffer(graphics::storage_buffer& buffer, std::uint32_t element_count) -> void {
43 const auto required_size = static_cast<std::size_t>(element_count) * sizeof(Type);
44
45 if (buffer.size() < required_size) {
46 buffer.resize(required_size + required_size / 2);
47 }
48 }
49
50 template<typename Type>
51 static auto _update_buffer(graphics::storage_buffer& buffer, const std::vector<Type>& data) -> void {
52 _resize_buffer<Type>(buffer, static_cast<std::uint32_t>(data.size()));
53
54 if (!data.empty()) {
55 buffer.update(data.data(), data.size() * sizeof(Type));
56 }
57 }
58
59 auto _dispatch_skinning(graphics::command_buffer& command_buffer, graphics::buffer::address_type bone_matrices_buffer_address) -> void;
60
61 graphics::storage_buffer_handle _vertex_buffer{};
63
65 graphics::push_handler _push_handler;
66
67}; // class skinning_task
68
69} // namespace sbx::animations
70
71#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