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
  • Loading branch information
Ivo Worms committed Sep 13, 2024
1 parent e961b3d commit 6097bc7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/window/winit_window/windowed_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ mod inner {
pub fn swap_buffers(&self) -> Result<(), WindowError> {
Ok(())
}

/// Enables or disabled vsync.
pub fn set_vsync(&self, _enabled: bool) -> Result<(), WindowError> {
Ok(())
}
}
}

Expand Down Expand Up @@ -222,6 +227,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 6097bc7

Please sign in to comment.