diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-10-02 22:56:31 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-10-02 22:56:31 +0000 |
| commit | 6c1b48507f4dccf7353b17a0bd39e5ff8742af71 (patch) | |
| tree | 027ce550c7d46d6564ba0a1db9f783d7e9ca4ec1 /AssetLoader/src/GLTFLoader.cpp | |
| parent | GLTF Loader: enabled loading of DDS/KTX textures (diff) | |
| download | DiligentTools-6c1b48507f4dccf7353b17a0bd39e5ff8742af71.tar.gz DiligentTools-6c1b48507f4dccf7353b17a0bd39e5ff8742af71.zip | |
GLTF loader: fixed issue with state transition for DDS/KTX textures
Diffstat (limited to 'AssetLoader/src/GLTFLoader.cpp')
| -rw-r--r-- | AssetLoader/src/GLTFLoader.cpp | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/AssetLoader/src/GLTFLoader.cpp b/AssetLoader/src/GLTFLoader.cpp index 558f3ae..ac161d6 100644 --- a/AssetLoader/src/GLTFLoader.cpp +++ b/AssetLoader/src/GLTFLoader.cpp @@ -643,7 +643,7 @@ void Model::LoadTextures(IRenderDevice* pDevice, const std::string& BaseDir, TextureCacheType* pTextureCache) { - std::vector<ITexture*> MipMapGenList; + std::vector<ITexture*> NewTextures; for (const tinygltf::Texture& gltf_tex : gltf_model.textures) { const tinygltf::Image& gltf_image = gltf_model.images[gltf_tex.source]; @@ -692,7 +692,7 @@ void Model::LoadTextures(IRenderDevice* pDevice, if (gltf_image.width > 0 && gltf_image.height > 0) { pTexture = TextureFromGLTFImage(pDevice, pCtx, gltf_image, pSampler, AlphaCutoff); - MipMapGenList.push_back(pTexture); + pCtx->GenerateMips(pTexture->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE)); } else if (gltf_image.pixel_type == IMAGE_FILE_FORMAT_DDS || gltf_image.pixel_type == IMAGE_FILE_FORMAT_KTX) { @@ -714,6 +714,9 @@ void Model::LoadTextures(IRenderDevice* pDevice, } } + VERIFY_EXPR(pTexture); + NewTextures.emplace_back(pTexture); + if (pTextureCache != nullptr) { pTextureCache->emplace(BaseDir + gltf_image.uri, pTexture); @@ -723,17 +726,22 @@ void Model::LoadTextures(IRenderDevice* pDevice, Textures.push_back(std::move(pTexture)); } - std::vector<StateTransitionDesc> Barriers; - for (auto& Tex : MipMapGenList) + if (!NewTextures.empty()) { - pCtx->GenerateMips(Tex->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE)); - - StateTransitionDesc Barrier{Tex, RESOURCE_STATE_UNKNOWN, RESOURCE_STATE_SHADER_RESOURCE}; - Barrier.UpdateResourceState = true; - Barriers.emplace_back(Barrier); + std::vector<StateTransitionDesc> Barriers; + Barriers.reserve(NewTextures.size()); + for (auto& Tex : NewTextures) + { + if (Tex) + { + StateTransitionDesc Barrier{Tex, RESOURCE_STATE_UNKNOWN, RESOURCE_STATE_SHADER_RESOURCE}; + Barrier.UpdateResourceState = true; + Barriers.emplace_back(Barrier); + } + } + if (!Barriers.empty()) + pCtx->TransitionResourceStates(static_cast<Uint32>(Barriers.size()), Barriers.data()); } - if (!Barriers.empty()) - pCtx->TransitionResourceStates(static_cast<Uint32>(Barriers.size()), Barriers.data()); } namespace |
