handle special case in swapnchain creation

This commit is contained in:
hodasemi 2024-04-06 21:11:10 +02:00
parent d57137d798
commit 1fb136bed9

View file

@ -50,11 +50,15 @@ impl Swapchain {
image_usage: impl Into<VkImageUsageFlagBits>,
prefered_format: VkFormat,
array_layers: u32,
window_size: (u32, u32),
) -> Result<Arc<Swapchain>> {
let surface_caps = surface.capabilities(&device)?;
let extent = if surface_caps.currentExtent.width == u32::max_value() {
return Err(anyhow::Error::msg("Surface has no extent"));
VkExtent2D {
width: window_size.0,
height: window_size.1,
}
} else {
VkExtent2D {
width: surface_caps.currentExtent.width,
@ -178,7 +182,7 @@ impl Swapchain {
})
}
pub fn recreate(&self) -> Result<()> {
pub fn recreate(&self, window_size: (u32, u32)) -> Result<()> {
// wait for the device to get idle
self.device.wait_idle()?;
@ -187,7 +191,10 @@ impl Swapchain {
let extent = if surface_caps.currentExtent.width == u32::max_value()
|| surface_caps.currentExtent.height == u32::max_value()
{
return Err(anyhow::Error::msg("Surface has no extent"));
VkExtent2D {
width: window_size.0,
height: window_size.1,
}
} else if surface_caps.currentExtent.width == 0 || surface_caps.currentExtent.height == 0 {
// don't recreate swapchain
return Ok(());