From 8cb15ebb5da1fc825a211548d51a7e77bb981647 Mon Sep 17 00:00:00 2001 From: assiduous Date: Mon, 30 Nov 2020 21:40:10 -0800 Subject: GLTF Loader: added GetFirstIndexLocation and GetBaseVertex methods --- AssetLoader/src/GLTFLoader.cpp | 7 ++++--- AssetLoader/src/GLTFResourceManager.cpp | 14 ++++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'AssetLoader/src') diff --git a/AssetLoader/src/GLTFLoader.cpp b/AssetLoader/src/GLTFLoader.cpp index bfd074d..9fe0cd2 100644 --- a/AssetLoader/src/GLTFLoader.cpp +++ b/AssetLoader/src/GLTFLoader.cpp @@ -895,9 +895,10 @@ void Model::PrepareGPUResources(IDeviceContext* pCtx) auto UpdateBuffer = [&](BUFFER_ID BuffId, const void* pData, size_t Size) // { - Uint32 Offset = 0; - auto* pBuffer = GetBuffer(BuffId, Offset); - pCtx->UpdateBuffer(pBuffer, Offset, static_cast(Size), pData, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); + auto* pBuffer = GetBuffer(BuffId); + VERIFY_EXPR(pBuffer != nullptr); + auto Offset = Buffers[BuffId].CacheAllocation.IsValid() ? Buffers[BuffId].CacheAllocation.Region.UnalignedOffset : 0; + pCtx->UpdateBuffer(pBuffer, static_cast(Offset), static_cast(Size), pData, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); if (Buffers[BuffId].pBuffer != nullptr) { VERIFY_EXPR(Buffers[BuffId].pBuffer == pBuffer); diff --git a/AssetLoader/src/GLTFResourceManager.cpp b/AssetLoader/src/GLTFResourceManager.cpp index 54724ea..c6f627c 100644 --- a/AssetLoader/src/GLTFResourceManager.cpp +++ b/AssetLoader/src/GLTFResourceManager.cpp @@ -80,13 +80,16 @@ GLTFResourceManager::BufferAllocation GLTFResourceManager::AllocateBufferSpace(U std::lock_guard Lock{BuffCache.Mtx}; BufferAllocation Allocation; - Allocation.BufferIndex = BufferIndex; - Allocation.Region = BuffCache.Mgr.Allocate(Size, Alignment); + Allocation.Region = BuffCache.Mgr.Allocate(Size, Alignment); + if (Allocation.Region.IsValid()) + Allocation.BufferIndex = BufferIndex; return Allocation; } void GLTFResourceManager::FreeBufferSpace(BufferAllocation&& Allocation) { + VERIFY_EXPR(Allocation.IsValid()); + auto& BuffCache = m_Buffers[Allocation.BufferIndex]; std::lock_guard Lock{BuffCache.Mtx}; @@ -103,10 +106,11 @@ GLTFResourceManager::TextureAllocation GLTFResourceManager::AllocateTextureSpace std::lock_guard Lock{TexCache.Mtx}; TextureAllocation Allocation; - Allocation.TextureIndex = TextureIndex; - Allocation.Region = TexCache.Mgr.Allocate(Width, Height); + Allocation.Region = TexCache.Mgr.Allocate(Width, Height); if (!Allocation.Region.IsEmpty()) { + Allocation.TextureIndex = TextureIndex; + Allocation.Region.x *= TexCache.Granularity; Allocation.Region.y *= TexCache.Granularity; Allocation.Region.width *= TexCache.Granularity; @@ -117,6 +121,8 @@ GLTFResourceManager::TextureAllocation GLTFResourceManager::AllocateTextureSpace void GLTFResourceManager::FreeTextureSpace(TextureAllocation&& Allocation) { + VERIFY_EXPR(Allocation.IsValid()); + auto& TexCache = m_Textures[Allocation.TextureIndex]; auto& Region = Allocation.Region; -- cgit v1.2.3