Allow setting present mode in vulkano util's window renderer (#1922)

* Allow swapchain recreation with new present mode in utils

* Add doc text

* Add to changelog
This commit is contained in:
Okko Hakola 2022-07-13 13:25:32 +03:00 committed by GitHub
parent 18f68337a5
commit 5e298d6bb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -49,6 +49,7 @@
- Added an `is_signaled` method to `FenceSignalFuture`.
- Add a simple `general_purpose_image_view` method to `StorageImage` for less verbose image view creation for e.g. intermediary render targets.
- Add a `vulkano_util` crate to help reduce boilerplate in many use cases. `VulkanoContext` to hold access to device & instances, `VulkanoWindows` to organize windows and their renderers. `VulkanoRenderer` to hold the window and methods to `acquire` (swapchain) and `present` between which you are intended to execute your pipelines.
- Add option to change `PresentMode` at runtime in `vulkano_util` with `set_present_mode`
# Version 0.29.0 (2022-03-11)

View File

@ -53,6 +53,7 @@ pub struct VulkanoWindowRenderer {
recreate_swapchain: bool,
previous_frame_end: Option<Box<dyn GpuFuture>>,
image_index: usize,
present_mode: vulkano::swapchain::PresentMode,
}
impl VulkanoWindowRenderer {
@ -87,6 +88,7 @@ impl VulkanoWindowRenderer {
recreate_swapchain: false,
previous_frame_end,
image_index: 0,
present_mode: descriptor.present_mode,
}
}
@ -136,6 +138,14 @@ impl VulkanoWindowRenderer {
(swapchain, images)
}
/// Set window renderer present mode. This triggers a swapchain recreation.
pub fn set_present_mode(&mut self, present_mode: vulkano::swapchain::PresentMode) {
if self.present_mode != present_mode {
self.present_mode = present_mode;
self.recreate_swapchain = true;
}
}
/// Return swapchain image format
pub fn swapchain_format(&self) -> Format {
self.final_views[self.image_index].format().unwrap()
@ -197,7 +207,7 @@ impl VulkanoWindowRenderer {
dims[0] / dims[1]
}
/// Resize swapchain and camera view images at the beginning of next frame
/// Resize swapchain and camera view images at the beginning of next frame based on window dimensions
pub fn resize(&mut self) {
self.recreate_swapchain = true;
}
@ -301,6 +311,8 @@ impl VulkanoWindowRenderer {
let dimensions: [u32; 2] = self.window().inner_size().into();
let (new_swapchain, new_images) = match self.swap_chain.recreate(SwapchainCreateInfo {
image_extent: dimensions,
// Use present mode from current state
present_mode: self.present_mode,
..self.swap_chain.create_info()
}) {
Ok(r) => r,