#pragma once #include #include #include "vertex.hpp" #include "vk_mem_alloc.h" #include #include using std::unique_ptr; using std::shared_ptr; using std::make_shared; using std::make_unique; using std::optional; class Image; class Buffer { public: Buffer(VkDeviceSize bufferSize, VkBufferUsageFlags bufferUsage, VmaMemoryUsage memoryUsage, VmaAllocationCreateFlags vmaAllocationFlags, const std::string &name = ""); unique_ptr appended(void *data, VkDeviceSize appendSize, VkCommandBuffer commandBuffer) const; unique_ptr replaced(void *data, VkDeviceSize replaceSize, VkCommandBuffer commandBuffer) const; virtual ~Buffer(); VkBuffer handle = VK_NULL_HANDLE; VmaAllocation allocation = VK_NULL_HANDLE; VmaAllocationInfo allocationInfo {}; VkDeviceSize size; void setName(const std::string &newName); template T &access() { return *reinterpret_cast(allocationInfo.pMappedData); } void copyTo(Buffer *buffer) const; void copyTo(Image *image) const; void setData(void *data, VkDeviceSize offset, VkDeviceSize dataSize, VkCommandBuffer commandBuffer = VK_NULL_HANDLE); shared_ptr getStagingBuffer(); Buffer(const Buffer &other) = delete; Buffer &operator=(const Buffer &other) = delete; private: optional> stagingBufferOptional; std::string name; VkBufferUsageFlags bufferUsageFlags; VmaMemoryUsage memoryUsage; VmaAllocationCreateFlags allocationCreateFlags; };