From e167df35a6c1fb7f957cff421166918bc0d8a586 Mon Sep 17 00:00:00 2001 From: assiduous Date: Thu, 23 Apr 2020 23:15:37 -0700 Subject: VK swap chain resize: added orientation change detection --- .../GraphicsEngineVulkan/src/SwapChainVkImpl.cpp | 30 +++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp index 6b577d95..113d1aa3 100644 --- a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp @@ -763,7 +763,35 @@ void SwapChainVkImpl::RecreateVulkanSwapchain(DeviceContextVkImpl* pImmediateCtx void SwapChainVkImpl::Resize(Uint32 NewWidth, Uint32 NewHeight, SURFACE_TRANSFORM NewPreTransform) { - if (TSwapChainBase::Resize(NewWidth, NewHeight, NewPreTransform)) + auto RecreateSwapChain = TSwapChainBase::Resize(NewWidth, NewHeight, NewPreTransform); + +#if PLATFORM_ANDROID || PLATFORM_IOS + if (!RecreateSwapChain && m_VkSurface != VK_NULL_HANDLE) + { + // Check orinetation change + const auto* pRenderDeviceVk = m_pRenderDevice.RawPtr(); + const auto& PhysicalDevice = pRenderDeviceVk->GetPhysicalDevice(); + const auto vkDeviceHandle = PhysicalDevice.GetVkDeviceHandle(); + + VkSurfaceCapabilitiesKHR surfCapabilities = {}; + + auto err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(vkDeviceHandle, m_VkSurface, &surfCapabilities); + if (err == VK_SUCCESS) + { + auto CurrentTransform = VkSurfaceTransformFlagToSurfaceTransform(surfCapabilities.currentTransform); + if (CurrentTransform != m_SwapChainDesc.PreTransform) + { + RecreateSwapChain = true; + } + } + else + { + LOG_ERROR_MESSAGE(err, "Failed to query physical device surface capabilities"); + } + } +#endif + + if (RecreateSwapChain) { auto pDeviceContext = m_wpDeviceContext.Lock(); VERIFY(pDeviceContext, "Immediate context has been released"); -- cgit v1.2.3