AssetRegistry and small changes

This commit is contained in:
2026-09-15 02:20:38 -07:00
parent 6e2c6c0fc5
commit 12a1e6eca9
12 changed files with 164 additions and 73 deletions
+64
View File
@@ -0,0 +1,64 @@
#pragma once
#include <memory>
#include <sophia/handles.hpp>
#include <string>
#include <vector>
#include "sophia/canvas.hpp"
#include "sophia/types.hpp"
namespace sophia {
class Device;
class Mesh;
template <typename T>
struct AssetTraits;
template <>
struct AssetTraits<Mesh> {
using Handle = MeshHandle;
};
class AssetRegistry {
public:
~AssetRegistry();
AssetRegistry(const AssetRegistry&) = delete;
AssetRegistry& operator=(const AssetRegistry&) = delete;
template <typename T>
typename AssetTraits<T>::Handle load(const std::string& path);
/**
* TEMPORARY: Remove once load<Mesh> can read real model files from disk.
*/
MeshHandle loadMesh(std::vector<CanvasVertex> vertices,
std::vector<u32> indices);
template <typename T>
void release(typename AssetTraits<T>::Handle handle);
private:
friend class Application;
explicit AssetRegistry(Device& device);
template <typename T>
const T& get(typename AssetTraits<T>::Handle handle) const;
class Impl;
std::unique_ptr<Impl> impl;
};
template <>
MeshHandle AssetRegistry::load<Mesh>(const std::string& path);
template <>
void AssetRegistry::release<Mesh>(MeshHandle handle);
template <>
const Mesh& AssetRegistry::get<Mesh>(MeshHandle handle) const;
} // namespace sophia
+1 -1
View File
@@ -33,7 +33,7 @@ class Canvas {
private:
friend class Application;
Canvas(Application* application);
explicit Canvas(Application* application);
class Impl;
std::unique_ptr<Impl> impl;
+3 -1
View File
@@ -1,11 +1,13 @@
#pragma once
#include <sophia/asset_registry.hpp>
#include <string>
#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/quaternion.hpp>
#include <string>
namespace sophia {
+33
View File
@@ -0,0 +1,33 @@
#pragma once
#include <compare>
#include "sophia/types.hpp"
namespace sophia {
template <typename Tag>
struct Handle {
static constexpr u32 INVALID_INDEX = (1u << 20) - 1;
u32 index : 20 = INVALID_INDEX;
u32 generation : 12 = 1;
[[nodiscard]] static constexpr Handle invalid() {
return Handle{INVALID_INDEX, 0};
}
[[nodiscard]] constexpr bool isValid() const {
return index != INVALID_INDEX;
}
[[nodiscard]] auto operator<=>(const Handle&) const = default;
};
struct MeshTag {};
struct PanelTag {};
using MeshHandle = Handle<MeshTag>;
using PanelHandle = Handle<PanelTag>;
} // namespace sophia
-2
View File
@@ -17,6 +17,4 @@ using s64 = int64_t;
using f32 = float;
using f64 = double;
using MeshHandle = u32;
} // namespace sophia