#include #include #include "mesh.hpp" #include "pools/mesh_pool.hpp" #include "pools/render_target_pool.hpp" #include "render_target.hpp" namespace sophia { class ResourceRegistry::Impl { public: Impl(Device& device, vk::Format renderTargetFormat) : meshPool{device}, renderTargetPool{device, renderTargetFormat} {} MeshPool meshPool; RenderTargetPool renderTargetPool; // TexturePool texturePool; // MaterialPool materialPool; }; ResourceRegistry::ResourceRegistry(Device& device, u32 renderTargetFormat) : impl{std::make_unique( device, static_cast(renderTargetFormat))} {} ResourceRegistry::~ResourceRegistry() = default; template <> MeshHandle ResourceRegistry::load(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 ResourceTraits::Handle load(const std::string&) { static_assert(sizeof(T) == 0, "load is not implemented for this resource type"); } template <> void ResourceRegistry::release(MeshHandle handle) { impl->meshPool.release(handle); } template <> void ResourceRegistry::release(RenderTargetHandle handle) { impl->renderTargetPool.release(handle); } template <> const Mesh& ResourceRegistry::get(MeshHandle handle) const { return impl->meshPool.get(handle); } MeshHandle ResourceRegistry::createResource(std::type_identity, std::vector vertices, std::vector 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); } RenderTargetHandle ResourceRegistry::createResource( std::type_identity, u32 width, u32 height) { return impl->renderTargetPool.create(width, height); } void ResourceRegistry::requestResize(RenderTargetHandle handle, u32 width, u32 height) { impl->renderTargetPool.get(handle).requestResize(width, height); } glm::vec2 ResourceRegistry::getExtent(RenderTargetHandle handle) const { vk::Extent2D extent = std::as_const(impl->renderTargetPool).get(handle).getExtent(); return {static_cast(extent.width), static_cast(extent.height)}; } bool ResourceRegistry::isAlive(RenderTargetHandle handle) const { return impl->renderTargetPool.isAlive(handle); } RenderTarget& ResourceRegistry::getRenderTarget(RenderTargetHandle handle) { return impl->renderTargetPool.get(handle); } const RenderTarget& ResourceRegistry::getRenderTarget( RenderTargetHandle handle) const { return std::as_const(impl->renderTargetPool).get(handle); } void ResourceRegistry::applyPendingResizes() { impl->renderTargetPool.applyPendingResizes(); } } // namespace sophia