Skip to content

Commit

Permalink
Allow setting present mode in vulkano util's window renderer (#1922)
Browse files Browse the repository at this point in the history
* Allow swapchain recreation with new present mode in utils

* Add doc text

* Add to changelog
  • Loading branch information
hakolao authored Jul 13, 2022
1 parent 18f6833 commit 5e298d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 13 additions & 1 deletion vulkano-util/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -87,6 +88,7 @@ impl VulkanoWindowRenderer {
recreate_swapchain: false,
previous_frame_end,
image_index: 0,
present_mode: descriptor.present_mode,
}
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5e298d6

Please sign in to comment.