Skip to content

Commit

Permalink
GLTF resource manager: added update methods for vertex buffers, textu…
Browse files Browse the repository at this point in the history
…res and all resources
  • Loading branch information
TheMostDiligent committed Nov 18, 2023
1 parent 077ae29 commit 1ff1bfe
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
12 changes: 12 additions & 0 deletions AssetLoader/interface/GLTFResourceManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ class ResourceManager final : public ObjectBase<IObject>
/// Updates the index buffer, if necessary.
IBuffer* UpdateIndexBuffer(IRenderDevice* pDevice, IDeviceContext* pContext);

/// Updates the vertex buffers, if necessary.
void UpdateVertexBuffers(IRenderDevice* pDevice, IDeviceContext* pContext);

/// Returns a pointer to the index buffer.
IBuffer* GetIndexBuffer() const;

Expand All @@ -215,10 +218,19 @@ class ResourceManager final : public ObjectBase<IObject>
/// If the atlas does not exist, null is returned.
ITexture* UpdateTexture(TEXTURE_FORMAT Fmt, IRenderDevice* pDevice, IDeviceContext* pContext);

/// Updates all atlas textures.
void UpdateTextures(IRenderDevice* pDevice, IDeviceContext* pContext);

/// Returns the atlas texture for the given format.
/// If the atlas does not exist, null is returned.
ITexture* GetTexture(TEXTURE_FORMAT Fmt) const;

/// Updates all vertex buffers, index buffer and atlas textures.
///
/// \remarks This method is equivalent to calling UpdateIndexBuffer(),
/// UpdateVertexBuffers() and UpdateTextures().
void UpdateAllResources(IRenderDevice* pDevice, IDeviceContext* pContext);

// NB: can't return reference here!
TextureDesc GetAtlasDesc(TEXTURE_FORMAT Fmt);

Expand Down
25 changes: 25 additions & 0 deletions AssetLoader/src/GLTFResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,15 @@ IBuffer* ResourceManager::GetIndexBuffer() const
nullptr;
}

void ResourceManager::UpdateVertexBuffers(IRenderDevice* pDevice, IDeviceContext* pContext)
{
std::lock_guard<std::mutex> Guard{m_VertexPoolsMtx};
for (auto pool_it : m_VertexPools)
{
pool_it.second->UpdateAll(pDevice, pContext);
}
}

IVertexPool* ResourceManager::GetVertexPool(const VertexLayoutKey& Key)
{
decltype(m_VertexPools)::iterator pool_it; // NB: can't initialize it without locking the mutex
Expand All @@ -345,6 +354,15 @@ ITexture* ResourceManager::UpdateTexture(TEXTURE_FORMAT Fmt, IRenderDevice* pDev
return cache_it->second->Update(pDevice, pContext);
}

void ResourceManager::UpdateTextures(IRenderDevice* pDevice, IDeviceContext* pContext)
{
std::lock_guard<std::mutex> Guard{m_AtlasesMtx};
for (auto it : m_Atlases)
{
it.second->Update(pDevice, pContext);
}
}

ITexture* ResourceManager::GetTexture(TEXTURE_FORMAT Fmt) const
{
decltype(m_Atlases)::const_iterator cache_it; // NB: can't initialize it without locking the mutex
Expand All @@ -358,6 +376,13 @@ ITexture* ResourceManager::GetTexture(TEXTURE_FORMAT Fmt) const
return cache_it->second->GetTexture();
}

void ResourceManager::UpdateAllResources(IRenderDevice* pDevice, IDeviceContext* pContext)
{
UpdateIndexBuffer(pDevice, pContext);
UpdateVertexBuffers(pDevice, pContext);
UpdateTextures(pDevice, pContext);
}

TextureDesc ResourceManager::GetAtlasDesc(TEXTURE_FORMAT Fmt)
{
{
Expand Down

0 comments on commit 1ff1bfe

Please sign in to comment.