75 lines
1.9 KiB
C++
75 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include <sophia/aabb.hpp>
|
|
#include <sophia/handles.hpp>
|
|
#include <sophia/math.hpp>
|
|
#include <sophia/mesh_data.hpp>
|
|
#include <sophia/types.hpp>
|
|
#include <string>
|
|
#include <type_traits>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
namespace sophia {
|
|
|
|
class ResourceRegistry;
|
|
|
|
class ResourceRegistryRef {
|
|
public:
|
|
template <typename T>
|
|
Handle<T> load(const std::string& path);
|
|
|
|
template <typename T, typename... Args>
|
|
Handle<T> create(Args&&... args) {
|
|
return createResource(std::type_identity<T>{}, std::forward<Args>(args)...);
|
|
}
|
|
|
|
void requestResize(RenderTargetHandle handle, u32 width, u32 height);
|
|
|
|
glm::vec2 getExtent(RenderTargetHandle handle) const;
|
|
glm::vec2 getExtent(TextureHandle handle) const;
|
|
|
|
// In the mesh's own space.
|
|
AABB getBounds(MeshHandle handle) const;
|
|
|
|
bool isAlive(MeshHandle handle) const;
|
|
bool isAlive(RenderTargetHandle handle) const;
|
|
bool isAlive(TextureHandle handle) const;
|
|
|
|
template <typename T>
|
|
void release(Handle<T> handle);
|
|
|
|
private:
|
|
friend class Application;
|
|
|
|
explicit ResourceRegistryRef(ResourceRegistry& registry)
|
|
: registry{®istry} {}
|
|
|
|
MeshHandle createResource(std::type_identity<Mesh>, const MeshData& data);
|
|
|
|
RenderTargetHandle createResource(std::type_identity<RenderTarget>,
|
|
u32 width = 1, u32 height = 1);
|
|
|
|
TextureHandle createResource(std::type_identity<Texture>, u32 width,
|
|
u32 height, std::vector<u8> pixels);
|
|
|
|
ResourceRegistry* registry;
|
|
};
|
|
|
|
template <>
|
|
MeshHandle ResourceRegistryRef::load<Mesh>(const std::string& path);
|
|
|
|
template <>
|
|
TextureHandle ResourceRegistryRef::load<Texture>(const std::string& path);
|
|
|
|
template <>
|
|
void ResourceRegistryRef::release<Mesh>(MeshHandle handle);
|
|
|
|
template <>
|
|
void ResourceRegistryRef::release<RenderTarget>(RenderTargetHandle handle);
|
|
|
|
template <>
|
|
void ResourceRegistryRef::release<Texture>(TextureHandle handle);
|
|
|
|
} // namespace sophia
|