From d50d08bd494764564f8f4d516667acf3daf09d30 Mon Sep 17 00:00:00 2001 From: assiduous Date: Tue, 1 Dec 2020 19:48:27 -0800 Subject: GLTFResourceManager: added texture allocation cache --- AssetLoader/interface/GLTFLoader.hpp | 13 +------------ AssetLoader/interface/GLTFResourceManager.hpp | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 16 deletions(-) (limited to 'AssetLoader/interface') diff --git a/AssetLoader/interface/GLTFLoader.hpp b/AssetLoader/interface/GLTFLoader.hpp index e66e808..b395c8c 100644 --- a/AssetLoader/interface/GLTFLoader.hpp +++ b/AssetLoader/interface/GLTFLoader.hpp @@ -316,18 +316,7 @@ struct Model { std::mutex TexturesMtx; - struct TextureInfo - { - RefCntWeakPtr wpTexture; - - const float4 UVScaleBias; - - TextureInfo(ITexture* pTex, const float4& _UVScaleBias) : - wpTexture{pTex}, - UVScaleBias{_UVScaleBias} - {} - }; - std::unordered_map Textures; + std::unordered_map> Textures; }; Model(IRenderDevice* pDevice, diff --git a/AssetLoader/interface/GLTFResourceManager.hpp b/AssetLoader/interface/GLTFResourceManager.hpp index 9a8397c..e0b007d 100644 --- a/AssetLoader/interface/GLTFResourceManager.hpp +++ b/AssetLoader/interface/GLTFResourceManager.hpp @@ -29,6 +29,7 @@ #include #include +#include #include "../../../DiligentCore/Graphics/GraphicsEngine/interface/RenderDevice.h" #include "../../../DiligentCore/Graphics/GraphicsEngine/interface/DeviceContext.h" @@ -94,11 +95,15 @@ public: TextureAllocation(IReferenceCounters* pRefCounters, RefCntAutoPtr pResourceMg, TextureCache& ParentCache, + Uint32 Width, + Uint32 Height, DynamicAtlasManager::Region&& Region) : // clang-format off ObjectBase{pRefCounters}, m_pResMgr {std::move(pResourceMg)}, m_ParentCache {ParentCache}, + m_Width {Width}, + m_Height {Height}, m_Region {std::move(Region)} // clang-format on { @@ -125,9 +130,14 @@ public: return m_Region; } + Uint32 GetWidth() const { return m_Width; } + Uint32 GetHeight() const { return m_Height; } + private: RefCntAutoPtr m_pResMgr; TextureCache& m_ParentCache; + const Uint32 m_Width; + const Uint32 m_Height; DynamicAtlasManager::Region m_Region; }; @@ -153,10 +163,9 @@ public: return m_Buffers[BufferIndex].Allocate(Size, Alignment); } - RefCntAutoPtr AllocateTextureSpace(Uint32 TextureIndex, Uint32 Width, Uint32 Height) - { - return m_Textures[TextureIndex].Allocate(Width, Height); - } + RefCntAutoPtr AllocateTextureSpace(Uint32 TextureIndex, Uint32 Width, Uint32 Height, const char* CacheId = nullptr); + + RefCntAutoPtr FindAllocation(const char* CacheId); private: template @@ -253,6 +262,9 @@ private: RefCntAutoPtr m_pTexture; }; std::vector m_Textures; + + std::mutex m_AllocationsMtx; + std::unordered_map> m_Allocations; }; } // namespace Diligent -- cgit v1.2.3