#ifndef BUFFER_HPP #define BUFFER_HPP #include "core/device.hpp" #include #include namespace LSFG::Core { /// /// C++ wrapper class for a Vulkan buffer. /// /// This class manages the lifetime of a Vulkan buffer. /// class Buffer { public: Buffer() noexcept = default; /// /// Create the buffer. /// /// @param device Vulkan device /// @param data Initial data for the buffer, also specifies the size of the buffer. /// @param usage Usage flags for the buffer /// /// @throws LSFG::vulkan_error if object creation fails. /// template Buffer(const Core::Device& device, const T& data, VkBufferUsageFlags usage) : size(sizeof(T)) { construct(device, reinterpret_cast(&data), usage); } /// /// Create the buffer. /// /// @param device Vulkan device /// @param data Initial data for the buffer /// @param size Size of the buffer in bytes /// @param usage Usage flags for the buffer /// /// @throws LSFG::vulkan_error if object creation fails. /// Buffer(const Core::Device& device, const void* data, size_t size, VkBufferUsageFlags usage) : size(size) { construct(device, data, usage); } /// Get the Vulkan handle. [[nodiscard]] auto handle() const { return *this->buffer; } /// Get the size of the buffer. [[nodiscard]] size_t getSize() const { return this->size; } /// Trivially copyable, moveable and destructible Buffer(const Buffer&) noexcept = default; Buffer& operator=(const Buffer&) noexcept = default; Buffer(Buffer&&) noexcept = default; Buffer& operator=(Buffer&&) noexcept = default; ~Buffer() = default; private: void construct(const Core::Device& device, const void* data, VkBufferUsageFlags usage); std::shared_ptr buffer; std::shared_ptr memory; size_t size{}; }; } #endif // BUFFER_HPP