Skip to content

Commit

Permalink
Add present mode setters on Pixels (#373)
Browse files Browse the repository at this point in the history
* Add present mode setters on Pixels

* Add present mode getter on Pixels
  • Loading branch information
Kanabenki authored Aug 9, 2023
1 parent d140eba commit 705f22b
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,39 @@ impl Pixels {
Ok(())
}

/// Enable or disable Vsync.
///
/// Vsync is enabled by default. It cannot be disabled on Web targets.
///
/// The `wgpu` present mode will be set to `AutoVsync` when Vsync is enabled, or `AutoNoVsync`
/// when Vsync is disabled. To set the present mode to `Mailbox` or another value, use the
/// [`Pixels::set_present_mode`] method.
pub fn enable_vsync(&mut self, enable_vsync: bool) {
self.present_mode = if enable_vsync {
wgpu::PresentMode::AutoVsync
} else {
wgpu::PresentMode::AutoNoVsync
};
self.reconfigure_surface();
}

/// Get the `wgpu` present mode.
///
/// Returns the present mode currently in use by the surface, which can be changed through
/// [`Pixels::enable_vsync`] or [`Pixels::set_present_mode`].
pub fn present_mode(&self) -> wgpu::PresentMode {
self.present_mode
}

/// Set the `wgpu` present mode.
///
/// This differs from [`Pixels::enable_vsync`] by allowing the present mode to be set to
/// any value.
pub fn set_present_mode(&mut self, present_mode: wgpu::PresentMode) {
self.present_mode = present_mode;
self.reconfigure_surface();
}

/// Draw this pixel buffer to the configured [`SurfaceTexture`].
///
/// # Errors
Expand Down

0 comments on commit 705f22b

Please sign in to comment.