53 lines
1.5 KiB
C++
53 lines
1.5 KiB
C++
#pragma once
|
|
#include <application/application.h>
|
|
#include <vulkan/vulkan.hpp>
|
|
|
|
#include "renderer.h"
|
|
|
|
class CORE_API buffer_vk {
|
|
public:
|
|
buffer_vk();
|
|
~buffer_vk() { destroy(); }
|
|
|
|
void create(uint32_t size, vk::BufferUsageFlagBits in_usage, vk::DescriptorType in_descriptor_type);
|
|
void create_storage(uint32_t size);
|
|
void create_uniform(uint32_t size);
|
|
void create_staging(uint32_t size);
|
|
void destroy() const;
|
|
|
|
template <typename T>
|
|
T* map() {
|
|
const auto& device = application::get()->get_renderer()->device;
|
|
void* mapped;
|
|
const auto err = device.mapMemory(memory, 0, VK_WHOLE_SIZE, vk::MemoryMapFlags(), &mapped);
|
|
check_vk_result(err);
|
|
return static_cast<T*>(mapped);
|
|
}
|
|
void unmap() const {
|
|
const auto& device = application::get()->get_renderer()->device;
|
|
device.unmapMemory(memory);
|
|
}
|
|
|
|
void update(const void* data, uint32_t size);
|
|
template <typename T>
|
|
void update(const T& data) {
|
|
update(&data, sizeof(T));
|
|
}
|
|
template <typename T>
|
|
void update(const std::vector<T>& data) {
|
|
update(data.data(), data.size() * sizeof(T));
|
|
}
|
|
|
|
operator vk::DescriptorBufferInfo() const {
|
|
vk::DescriptorBufferInfo descriptor_buffer_info;
|
|
descriptor_buffer_info.setBuffer(buffer);
|
|
descriptor_buffer_info.setOffset(0);
|
|
descriptor_buffer_info.setRange(VK_WHOLE_SIZE);
|
|
return descriptor_buffer_info;
|
|
}
|
|
|
|
vk::Buffer buffer;
|
|
vk::DeviceMemory memory;
|
|
vk::DescriptorType descriptor_type;
|
|
};
|