AssetRegistry and small changes
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
#include "assets/asset_manager.hpp"
|
||||
|
||||
#include "mesh.hpp"
|
||||
|
||||
namespace sophia {
|
||||
|
||||
AssetManager::AssetManager(Device& device) : device{device}, meshPool{device} {}
|
||||
|
||||
template <>
|
||||
MeshHandle AssetManager::create<Mesh>(const Mesh::Builder& builder) {
|
||||
return meshPool.create(builder);
|
||||
}
|
||||
|
||||
template <>
|
||||
const Mesh& AssetManager::get<Mesh>(MeshHandle handle) const {
|
||||
return meshPool.get(handle);
|
||||
}
|
||||
|
||||
template <>
|
||||
void AssetManager::release<Mesh>(MeshHandle handle) {
|
||||
meshPool.release(handle);
|
||||
}
|
||||
|
||||
} // namespace sophia
|
||||
@@ -1,41 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "device.hpp"
|
||||
#include "pools/mesh_pool.hpp"
|
||||
|
||||
namespace sophia {
|
||||
|
||||
class AssetManager {
|
||||
public:
|
||||
explicit AssetManager(Device& device);
|
||||
~AssetManager() = default;
|
||||
|
||||
AssetManager(const AssetManager&) = delete;
|
||||
AssetManager& operator=(const AssetManager&) = delete;
|
||||
|
||||
template <typename T>
|
||||
using HandleFor = typename T::HandleType;
|
||||
|
||||
template <typename T>
|
||||
HandleFor<T> load(const std::string& path);
|
||||
|
||||
template <typename T>
|
||||
HandleFor<T> create(const typename T::Builder& builder);
|
||||
|
||||
template <typename T>
|
||||
const T& get(HandleFor<T> handle) const;
|
||||
|
||||
template <typename T>
|
||||
void release(HandleFor<T> handle);
|
||||
|
||||
private:
|
||||
Device& device;
|
||||
|
||||
MeshPool meshPool;
|
||||
// TexturePool texturePool;
|
||||
// MaterialPool materialPool;
|
||||
};
|
||||
|
||||
} // namespace sophia
|
||||
@@ -0,0 +1,60 @@
|
||||
#include <sophia/asset_registry.hpp>
|
||||
#include <sophia/util/assert.hpp>
|
||||
|
||||
#include "mesh.hpp"
|
||||
#include "pools/mesh_pool.hpp"
|
||||
|
||||
namespace sophia {
|
||||
|
||||
class AssetRegistry::Impl {
|
||||
public:
|
||||
explicit Impl(Device& device) : meshPool{device} {}
|
||||
|
||||
MeshPool meshPool;
|
||||
// TexturePool texturePool;
|
||||
// MaterialPool materialPool;
|
||||
};
|
||||
|
||||
AssetRegistry::AssetRegistry(Device& device)
|
||||
: impl{std::make_unique<Impl>(device)} {}
|
||||
|
||||
AssetRegistry::~AssetRegistry() = default;
|
||||
|
||||
template <>
|
||||
MeshHandle AssetRegistry::load<Mesh>(const std::string& path) {
|
||||
(void)path;
|
||||
SOPHIA_ASSERT(false,
|
||||
"Mesh::load(path) is not implemented yet - no model file "
|
||||
"format is supported; build one via Mesh::Builder for now");
|
||||
return MeshHandle{};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename AssetTraits<T>::Handle load(const std::string&) {
|
||||
static_assert(sizeof(T) == 0,
|
||||
"load<T> is not implemented for this asset type");
|
||||
}
|
||||
|
||||
template <>
|
||||
void AssetRegistry::release<Mesh>(MeshHandle handle) {
|
||||
impl->meshPool.release(handle);
|
||||
}
|
||||
|
||||
template <>
|
||||
const Mesh& AssetRegistry::get<Mesh>(MeshHandle handle) const {
|
||||
return impl->meshPool.get(handle);
|
||||
}
|
||||
|
||||
MeshHandle AssetRegistry::loadMesh(std::vector<CanvasVertex> vertices,
|
||||
std::vector<u32> indices) {
|
||||
Mesh::Builder builder{};
|
||||
builder.vertices.reserve(vertices.size());
|
||||
for (const CanvasVertex& vertex : vertices) {
|
||||
builder.vertices.push_back({vertex.position, vertex.color});
|
||||
}
|
||||
builder.indices = std::move(indices);
|
||||
|
||||
return impl->meshPool.create(builder);
|
||||
}
|
||||
|
||||
} // namespace sophia
|
||||
Reference in New Issue
Block a user