Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add present mode setters on Pixels #373

Merged
merged 2 commits into from
Aug 9, 2023
Merged
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
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