44 lines
1.3 KiB
C++
44 lines
1.3 KiB
C++
#ifndef MESHCACHE_H
|
|
#define MESHCACHE_H
|
|
|
|
#include <destrum/Graphics/Resources/Mesh.h>
|
|
|
|
#include <optional>
|
|
#include <string_view>
|
|
|
|
#include "../ids.h"
|
|
|
|
class GfxDevice;
|
|
|
|
class MeshCache {
|
|
public:
|
|
void cleanup(GfxDevice& gfxDevice);
|
|
|
|
MeshID addMesh(GfxDevice& gfxDevice, const CPUMesh& cpuMesh);
|
|
const GPUMesh& getMesh(MeshID id) const;
|
|
[[nodiscard]] const std::vector<GPUMesh>& getMeshes() const { return meshes; }
|
|
const CPUMesh& getCPUMesh(MeshID id) const;
|
|
[[nodiscard]] const std::string& getMeshKey(MeshID id) const;
|
|
[[nodiscard]] std::optional<MeshID> findMeshByKey(std::string_view key) const;
|
|
|
|
[[nodiscard]] const GPUBuffer& getIndexBuffer() const { return indexBuffer; }
|
|
[[nodiscard]] std::uint32_t getIndexCount() const { return indexCount; }
|
|
[[nodiscard]] std::uint32_t getIndexCapacity() const { return indexCapacity; }
|
|
|
|
private:
|
|
void uploadMesh(GfxDevice& gfxDevice, const CPUMesh& cpuMesh, GPUMesh& gpuMesh);
|
|
void ensureIndexCapacity(GfxDevice& gfxDevice, std::uint32_t requiredIndices);
|
|
|
|
static constexpr std::uint32_t InitialIndexCapacity = 1u << 20;
|
|
|
|
GPUBuffer indexBuffer;
|
|
std::uint32_t indexCount{0};
|
|
std::uint32_t indexCapacity{0};
|
|
|
|
std::vector<GPUMesh> meshes;
|
|
std::vector<CPUMesh> cpuMeshes;
|
|
std::vector<std::string> meshKeys;
|
|
};
|
|
|
|
#endif //MESHCACHE_H
|