AssetRegistry and small changes
This commit is contained in:
@@ -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
|
||||
@@ -33,7 +33,7 @@ class Canvas {
|
||||
private:
|
||||
friend class Application;
|
||||
|
||||
Canvas(Application* application);
|
||||
explicit Canvas(Application* application);
|
||||
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> impl;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -17,6 +17,4 @@ using s64 = int64_t;
|
||||
using f32 = float;
|
||||
using f64 = double;
|
||||
|
||||
using MeshHandle = u32;
|
||||
|
||||
} // namespace sophia
|
||||
|
||||
Reference in New Issue
Block a user