Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
AssetRegistry.h
Go to the documentation of this file.
1#pragma once
2
11
12#include <filesystem>
13#include <optional>
14#include <string>
15#include <string_view>
16#include <unordered_map>
17#include <vector>
18
19namespace Engine::Core
20{
21 class AssetManager;
22
31
33 {
35 std::string nodeName;
36 uint32_t nodeIndex = 0;
37 uint32_t meshIndex = 0;
39 std::vector<Assets::MaterialHandle> primitiveMaterials;
41 bool isStatic = false;
42 };
43
45 {
46 public:
47 explicit GeometryMeshStore(AssetManager* assetManager = nullptr);
48
49 void setAssetManager(AssetManager* assetManager);
50
51 [[nodiscard]] Assets::GeometryMeshHandle load(const Asset::MeshPath& meshPath);
52 [[nodiscard]] bool isValid(Assets::GeometryMeshHandle handle) const;
53 [[nodiscard]] const Asset::MeshPath* path(Assets::GeometryMeshHandle handle) const;
55
56 private:
57 struct Record
58 {
60 uint32_t generation = 1;
61 uint64_t payloadGeneration = 0;
62 uint64_t residencyGeneration = 0;
63 };
64
65 [[nodiscard]] static std::string keyFor(const Asset::MeshPath& meshPath);
66
68 std::vector<Record> records_;
69 std::unordered_map<std::string, uint32_t> pathToIndex_;
70 };
71
73 {
74 public:
75 explicit MaterialStore(AssetManager* assetManager = nullptr);
76
77 void setAssetManager(AssetManager* assetManager);
78
79 [[nodiscard]] Assets::MaterialHandle load(const Asset::MeshPath& materialPath);
80 [[nodiscard]] bool isValid(Assets::MaterialHandle handle) const;
81 [[nodiscard]] const Asset::MeshPath* path(Assets::MaterialHandle handle) const;
83
84 private:
85 struct Record
86 {
88 uint32_t generation = 1;
89 uint64_t payloadGeneration = 0;
90 uint64_t residencyGeneration = 0;
91 };
92
93 [[nodiscard]] static std::string keyFor(const Asset::MeshPath& materialPath);
94
96 std::vector<Record> records_;
97 std::unordered_map<std::string, uint32_t> pathToIndex_;
98 };
99
101 {
102 public:
103 explicit Texture2DStore(AssetManager* assetManager = nullptr);
104
105 void setAssetManager(AssetManager* assetManager);
106
108 const std::filesystem::path& source,
110 );
111 [[nodiscard]] bool isValid(Assets::Texture2DHandle handle) const;
112 [[nodiscard]] const std::filesystem::path* sourcePath(Assets::Texture2DHandle handle) const;
115
116 private:
126
127 [[nodiscard]] static std::string keyFor(const std::filesystem::path& source);
128
130 std::vector<Record> records_;
131 std::unordered_map<std::string, uint32_t> sourceToIndex_;
132 };
133
135 {
136 public:
137 explicit AudioClipStore(AssetManager* assetManager = nullptr);
138
139 void setAssetManager(AssetManager* assetManager);
140
141 [[nodiscard]] Assets::AudioClipHandle load(const Asset::Path& source);
142 [[nodiscard]] Assets::AudioClipHandle load(const std::filesystem::path& source);
143 [[nodiscard]] bool isValid(Assets::AudioClipHandle handle) const;
144 [[nodiscard]] const Asset::Path* sourcePath(Assets::AudioClipHandle handle) const;
146
147 private:
148 struct Record
149 {
151 uint32_t generation = 1;
152 uint64_t payloadGeneration = 0;
154 };
155
156 [[nodiscard]] static std::string keyFor(const Asset::Path& source);
157
159 std::vector<Record> records_;
160 std::unordered_map<std::string, uint32_t> sourceToIndex_;
161 };
162
164 {
165 public:
167 AssetManager* assetManager = nullptr,
168 GeometryMeshStore* geometryMeshes = nullptr,
169 MaterialStore* materials = nullptr
170 );
171
172 void setAssetManager(AssetManager* assetManager);
175
176 [[nodiscard]] Assets::GltfHandle load(const std::filesystem::path& source);
179 std::string_view nodeName
180 );
183 [[nodiscard]] const std::filesystem::path* sourcePath(Assets::GltfHandle gltf) const;
184 [[nodiscard]] bool isValid(Assets::GltfHandle handle) const;
185 [[nodiscard]] bool isValid(Assets::GltfRenderableHandle handle) const;
186
187 private:
189 {
190 std::filesystem::path source;
191 uint32_t generation = 1;
192 uint64_t payloadGeneration = 0;
194 std::unordered_map<std::string, Assets::GltfRenderableHandle> renderablesByName;
195 };
196
204
205 [[nodiscard]] static std::string keyFor(const std::filesystem::path& source);
206 [[nodiscard]] static std::string fallbackNodeName(size_t nodeIndex);
208
212 std::vector<GltfRecord> gltfRecords_;
213 std::vector<RenderableRecord> renderableRecords_;
214 std::unordered_map<std::string, uint32_t> sourceToIndex_;
215 };
216
218 {
219 public:
220 explicit AssetRegistry(AssetManager* assetManager = nullptr);
221
222 void setAssetManager(AssetManager* assetManager);
223
224 [[nodiscard]] GltfStore& gltfs() { return gltfs_; }
225 [[nodiscard]] const GltfStore& gltfs() const { return gltfs_; }
227 [[nodiscard]] const GeometryMeshStore& geometryMeshes() const { return geometryMeshes_; }
228 [[nodiscard]] MaterialStore& materials() { return materials_; }
229 [[nodiscard]] const MaterialStore& materials() const { return materials_; }
230 [[nodiscard]] Texture2DStore& texture2Ds() { return texture2Ds_; }
231 [[nodiscard]] const Texture2DStore& texture2Ds() const { return texture2Ds_; }
232 [[nodiscard]] AudioClipStore& audioClips() { return audioClips_; }
233 [[nodiscard]] const AudioClipStore& audioClips() const { return audioClips_; }
234
240
241 private:
248 };
249} // namespace Engine::Core
Type-erased texture handle for runtime storage.
const GeometryMeshStore & geometryMeshes() const
Assets::GltfHandle resolve(Assets::Authored::GltfAssetRef ref)
MaterialStore & materials()
Assets::AudioClipHandle resolve(Assets::Authored::AudioAssetRef ref)
AssetRegistry(AssetManager *assetManager=nullptr)
const MaterialStore & materials() const
Texture2DStore & texture2Ds()
const AudioClipStore & audioClips() const
GeometryMeshStore & geometryMeshes()
GeometryMeshStore geometryMeshes_
AudioClipStore & audioClips()
const Texture2DStore & texture2Ds() const
Assets::GltfRenderableHandle resolve(Assets::Authored::GltfRenderableAssetRef ref)
Assets::GeometryMeshHandle resolve(Assets::Authored::GeometryMeshAssetRef ref)
const GltfStore & gltfs() const
void setAssetManager(AssetManager *assetManager)
Assets::Texture2DHandle resolve(Assets::Authored::Texture2DAssetRef ref)
static std::string keyFor(const Asset::Path &source)
std::unordered_map< std::string, uint32_t > sourceToIndex_
const Asset::Path * sourcePath(Assets::AudioClipHandle handle) const
AudioClipStore(AssetManager *assetManager=nullptr)
std::vector< Record > records_
Assets::AudioClipHandle load(const Asset::Path &source)
void setAssetManager(AssetManager *assetManager)
bool isValid(Assets::AudioClipHandle handle) const
Assets::AudioClipHandle load(const std::filesystem::path &source)
Assets::AudioAssetRef ref(Assets::AudioClipHandle handle) const
Assets::MeshAssetRef ref(Assets::GeometryMeshHandle handle) const
const Asset::MeshPath * path(Assets::GeometryMeshHandle handle) const
GeometryMeshStore(AssetManager *assetManager=nullptr)
bool isValid(Assets::GeometryMeshHandle handle) const
void setAssetManager(AssetManager *assetManager)
std::unordered_map< std::string, uint32_t > pathToIndex_
Assets::GeometryMeshHandle load(const Asset::MeshPath &meshPath)
static std::string keyFor(const Asset::MeshPath &meshPath)
std::vector< Record > records_
void setGeometryMeshStore(GeometryMeshStore *geometryMeshes)
const GltfRenderableRecord * get(Assets::GltfRenderableHandle renderable) const
Assets::GeometryMeshHandle geometryMesh(Assets::GltfRenderableHandle renderable) const
Assets::GltfRenderableHandle renderable(Assets::GltfHandle gltf, std::string_view nodeName)
const std::filesystem::path * sourcePath(Assets::GltfHandle gltf) const
Assets::GltfHandle load(const std::filesystem::path &source)
static std::string fallbackNodeName(size_t nodeIndex)
void importMetadata(Assets::GltfHandle gltf)
std::vector< RenderableRecord > renderableRecords_
GltfStore(AssetManager *assetManager=nullptr, GeometryMeshStore *geometryMeshes=nullptr, MaterialStore *materials=nullptr)
static std::string keyFor(const std::filesystem::path &source)
bool isValid(Assets::GltfHandle handle) const
GeometryMeshStore * geometryMeshes_
MaterialStore * materials_
void setMaterialStore(MaterialStore *materials)
std::vector< GltfRecord > gltfRecords_
std::unordered_map< std::string, uint32_t > sourceToIndex_
bool isValid(Assets::GltfRenderableHandle handle) const
AssetManager * assetManager_
void setAssetManager(AssetManager *assetManager)
const Asset::MeshPath * path(Assets::MaterialHandle handle) const
static std::string keyFor(const Asset::MeshPath &materialPath)
std::vector< Record > records_
Assets::MaterialAssetRef ref(Assets::MaterialHandle handle) const
MaterialStore(AssetManager *assetManager=nullptr)
void setAssetManager(AssetManager *assetManager)
std::unordered_map< std::string, uint32_t > pathToIndex_
bool isValid(Assets::MaterialHandle handle) const
Assets::MaterialHandle load(const Asset::MeshPath &materialPath)
bool isValid(Assets::Texture2DHandle handle) const
Texture2DStore(AssetManager *assetManager=nullptr)
static std::string keyFor(const std::filesystem::path &source)
Assets::TextureType usage(Assets::Texture2DHandle handle) const
const std::filesystem::path * sourcePath(Assets::Texture2DHandle handle) const
Assets::TextureHandle legacyHandle(Assets::Texture2DHandle handle) const
Assets::Texture2DHandle load(const std::filesystem::path &source, Assets::TextureType usage=Assets::TextureType::BaseColor)
void setAssetManager(AssetManager *assetManager)
std::vector< Record > records_
std::unordered_map< std::string, uint32_t > sourceToIndex_
AssetHandle< GltfRenderableHandleTag > GltfRenderableHandle
Asset::Ref< Asset::Path, Audio > AudioAssetRef
AssetHandle< Texture2DHandleTag > Texture2DHandle
AssetHandle< GltfHandleTag > GltfHandle
Asset::Ref< Asset::MeshPath, Mesh > MeshAssetRef
AssetHandle< GeometryMeshHandleTag > GeometryMeshHandle
Asset::Ref< Asset::MeshPath, Material > MaterialAssetRef
TextureType
Represents the semantic type of a texture, determining its Vulkan format.
Definition TextureType.h:15
@ BaseColor
Color data with gamma (SRGB format for 8-bit)
Definition TextureType.h:16
AssetHandle< AudioClipHandleTag > AudioClipHandle
AssetHandle< MaterialHandleTag > MaterialHandle
Manages IBL (Image-Based Lighting) resources for specular reflections.
Identifies a named mesh-like asset inside an asset file.
Definition AssetPath.h:40
Identifies a single asset file on disk.
Definition AssetPath.h:13
Assets::GeometryMeshHandle geometry
std::vector< Assets::MaterialHandle > primitiveMaterials
std::unordered_map< std::string, Assets::GltfRenderableHandle > renderablesByName