Skip to content

Commit

Permalink
Add WindowContext::set_vsync to allow for runtime vsync configuration (
Browse files Browse the repository at this point in the history
…#480)

Co-authored-by: Ivo Worms <[email protected]>
  • Loading branch information
BonsaiDen and Ivo Worms authored Sep 20, 2024
1 parent 6eea0ad commit 2884603
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/window/winit_window/windowed_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,18 @@ mod inner {
pub fn swap_buffers(&self) -> Result<(), WindowError> {
Ok(self.surface.swap_buffers(&self.glutin_context)?)
}

/// Enables or disabled vsync.
pub fn set_vsync(&self, enabled: bool) -> Result<(), WindowError> {
let swap_interval = if enabled {
glutin::surface::SwapInterval::Wait(std::num::NonZeroU32::new(1).unwrap())
} else {
glutin::surface::SwapInterval::DontWait
};
Ok(self
.surface
.set_swap_interval(&self.glutin_context, swap_interval)?)
}
}
}

Expand Down

0 comments on commit 2884603

Please sign in to comment.