From 02b5dd0c2169f78a7d951f787c68b428e7af4867 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sun, 5 May 2019 11:02:35 -0700 Subject: GLTF Loader: fixed mipmap generation issue on Vulkan on Mac --- AssetLoader/src/GLTFLoader.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'AssetLoader/src/GLTFLoader.cpp') diff --git a/AssetLoader/src/GLTFLoader.cpp b/AssetLoader/src/GLTFLoader.cpp index dd0532f..5cb6a24 100644 --- a/AssetLoader/src/GLTFLoader.cpp +++ b/AssetLoader/src/GLTFLoader.cpp @@ -89,14 +89,13 @@ RefCntAutoPtr TextureFromGLTFImage(IRenderDevice* pDevice, TexDesc.MipLevels = 0; TexDesc.MiscFlags = MISC_TEXTURE_FLAG_GENERATE_MIPS; RefCntAutoPtr pTexture; - + pDevice->CreateTexture(TexDesc, nullptr, &pTexture); Box UpdateBox; UpdateBox.MaxX = TexDesc.Width; UpdateBox.MaxY = TexDesc.Height; TextureSubResData Level0Data(pTextureData, gltfimage.width*4); pCtx->UpdateTexture(pTexture, 0, 0, UpdateBox, Level0Data, RESOURCE_STATE_TRANSITION_MODE_NONE, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); - pCtx->GenerateMips(pTexture->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE)); pTexture->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE)->SetSampler(pSampler); return pTexture; @@ -447,7 +446,6 @@ void Model::LoadTextures(IRenderDevice* pDevice, IDeviceContext* pCtx, const tinygltf::Model& gltf_model) { - std::vector Barriers; for (const tinygltf::Texture& gltf_tex : gltf_model.textures) { const tinygltf::Image& gltf_image = gltf_model.images[gltf_tex.source]; @@ -462,10 +460,17 @@ void Model::LoadTextures(IRenderDevice* pDevice, pSampler = TextureSamplers[gltf_tex.sampler]; } auto pTexture = TextureFromGLTFImage(pDevice, pCtx, gltf_image, pSampler); - StateTransitionDesc Barrier{pTexture, RESOURCE_STATE_UNKNOWN, RESOURCE_STATE_SHADER_RESOURCE}; + Textures.push_back(std::move(pTexture)); + } + + std::vector Barriers; + for (auto& Tex : Textures) + { + 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); - Textures.push_back(std::move(pTexture)); } pCtx->TransitionResourceStates(static_cast(Barriers.size()), Barriers.data()); } -- cgit v1.2.3