57 lines
1.3 KiB
C++
57 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <unordered_map>
|
|
#include <string>
|
|
#include <atomic>
|
|
#include <glm/vec3.hpp>
|
|
|
|
#include <vulkan/vulkan.h>
|
|
|
|
class ModelManager
|
|
{
|
|
public:
|
|
struct Vertex
|
|
{
|
|
glm::vec3 pos, color;
|
|
static VkVertexInputBindingDescription get_binding_description();
|
|
static std::array<VkVertexInputAttributeDescription, 2> get_vertex_attribute_descriptions();
|
|
|
|
};
|
|
class StaticModel
|
|
{
|
|
VkPhysicalDevice physical_device_;
|
|
VkDevice device_;
|
|
VkBuffer vertex_buffer_;
|
|
VkBuffer index_buffer_;
|
|
|
|
|
|
public:
|
|
StaticModel(const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices,
|
|
VkPhysicalDevice physical_device, VkDevice device);
|
|
~StaticModel();
|
|
|
|
};
|
|
|
|
struct owner_counter
|
|
{
|
|
std::atomic_ullong counter;
|
|
StaticModel* model;
|
|
|
|
owner_counter() = default;
|
|
owner_counter(const owner_counter& other);
|
|
};
|
|
|
|
private:
|
|
VkPhysicalDevice physical_device_;
|
|
VkDevice device_;
|
|
std::unordered_map<unsigned int, owner_counter> models;
|
|
|
|
static unsigned int FNV1aHash (const char *buf);
|
|
|
|
public:
|
|
ModelManager(VkPhysicalDevice physical_device, VkDevice device);
|
|
~ModelManager();
|
|
|
|
StaticModel* LoadModel(const std::string& name);
|
|
void FreeModel(const std::string& name);
|
|
}; |