Fixed issue at window minimization.
This commit is contained in:
parent
cee0cad0bd
commit
ab947ad9f9
|
|
@ -9,10 +9,12 @@
|
|||
#include "physical_device.h"
|
||||
#include "window.h"
|
||||
|
||||
[[nodiscard]] vk::Extent2D GetExtent(const Window *window, vk::SurfaceCapabilitiesKHR *surfaceCapabilities);
|
||||
|
||||
Swapchain::Swapchain(const Window *window, const Device *device, NameString &&name)
|
||||
: m_Device(device)
|
||||
, m_Name(std::move(name))
|
||||
, m_Format(vk::Format::eUndefined)
|
||||
, m_Name(std::move(name))
|
||||
, m_Format(vk::Format::eUndefined)
|
||||
{
|
||||
this->Create(window);
|
||||
}
|
||||
|
|
@ -24,12 +26,12 @@ Swapchain::~Swapchain()
|
|||
|
||||
Swapchain::Swapchain(Swapchain &&other) noexcept
|
||||
: m_Device(other.m_Device)
|
||||
, m_Swapchain(Take(other.m_Swapchain))
|
||||
, m_Name(std::move(other.m_Name))
|
||||
, m_Extent(other.m_Extent)
|
||||
, m_Format(other.m_Format)
|
||||
, m_Images(std::move(other.m_Images))
|
||||
, m_ImageViews(std::move(other.m_ImageViews))
|
||||
, m_Swapchain(Take(other.m_Swapchain))
|
||||
, m_Name(std::move(other.m_Name))
|
||||
, m_Extent(other.m_Extent)
|
||||
, m_Format(other.m_Format)
|
||||
, m_Images(std::move(other.m_Images))
|
||||
, m_ImageViews(std::move(other.m_ImageViews))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -52,6 +54,15 @@ void
|
|||
Swapchain::Create(const Window *window)
|
||||
{
|
||||
auto surfaceCapabilities = GetSurfaceCapabilities(m_Device->m_PhysicalDevice, window->m_Surface);
|
||||
m_Extent = GetExtent(window, &surfaceCapabilities);
|
||||
|
||||
while (m_Extent.width == 0 || m_Extent.height == 0)
|
||||
{
|
||||
glfwWaitEvents();
|
||||
surfaceCapabilities = GetSurfaceCapabilities(m_Device->m_PhysicalDevice, window->m_Surface);
|
||||
m_Extent = GetExtent(window, &surfaceCapabilities);
|
||||
}
|
||||
|
||||
auto surfaceFormats = GetSurfaceFormats(m_Device->m_PhysicalDevice, window->m_Surface);
|
||||
auto presentModes = GetSurfacePresentModes(m_Device->m_PhysicalDevice, window->m_Surface);
|
||||
|
||||
|
|
@ -83,20 +94,6 @@ Swapchain::Create(const Window *window)
|
|||
}
|
||||
}
|
||||
|
||||
if (surfaceCapabilities.currentExtent.width != MaxValue<u32>)
|
||||
{
|
||||
m_Extent = surfaceCapabilities.currentExtent;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto [width, height] = window->GetSize();
|
||||
auto [minWidth, minHeight] = surfaceCapabilities.minImageExtent;
|
||||
auto [maxWidth, maxHeight] = surfaceCapabilities.maxImageExtent;
|
||||
|
||||
m_Extent.width = glm::clamp(width, minWidth, maxWidth);
|
||||
m_Extent.height = glm::clamp(height, minHeight, maxHeight);
|
||||
}
|
||||
|
||||
u32 swapchainImageCount = 3;
|
||||
if (surfaceCapabilities.maxImageCount > 0)
|
||||
{
|
||||
|
|
@ -207,3 +204,21 @@ Swapchain::Cleanup()
|
|||
DEBUG("Swapchain '{}' destroyed.", m_Name);
|
||||
}
|
||||
}
|
||||
|
||||
vk::Extent2D
|
||||
GetExtent(const Window *window, vk::SurfaceCapabilitiesKHR *surfaceCapabilities)
|
||||
{
|
||||
if (surfaceCapabilities->currentExtent.width != MaxValue<u32>)
|
||||
{
|
||||
return surfaceCapabilities->currentExtent;
|
||||
}
|
||||
|
||||
auto [width, height] = window->GetSize();
|
||||
auto [minWidth, minHeight] = surfaceCapabilities->minImageExtent;
|
||||
auto [maxWidth, maxHeight] = surfaceCapabilities->maxImageExtent;
|
||||
|
||||
return {
|
||||
.width = glm::clamp(width, minWidth, maxWidth),
|
||||
.height = glm::clamp(height, minHeight, maxHeight),
|
||||
};
|
||||
}
|
||||
|
|
@ -25,7 +25,7 @@ Window::GetSize() const
|
|||
{
|
||||
int width;
|
||||
int height;
|
||||
glfwGetWindowSize(m_Window, &width, &height);
|
||||
glfwGetFramebufferSize(m_Window, &width, &height);
|
||||
return {Cast<u32>(width), Cast<u32>(height)};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ struct Window final
|
|||
|
||||
void SetWindowSize(const vk::Extent2D &extent) const noexcept;
|
||||
void SetWindowSize(u32 width, u32 height) const noexcept;
|
||||
/// Actual size of the framebuffer being used for the window render.
|
||||
[[nodiscard]] vk::Extent2D GetSize() const;
|
||||
|
||||
// Ctor/Dtor
|
||||
|
|
|
|||
Loading…
Reference in New Issue