Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Merged
merged 3 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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