Change Vsync setting to use Fifo present mode (#93)

And add a method to set `Mailbox` or other explicit modes.

Closes #88
This commit is contained in:
Jay Oster 2020-07-17 16:34:54 -07:00 committed by GitHub
parent 7779d682cf
commit b397eb4e48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 13 deletions

View file

@ -15,7 +15,7 @@ fn main() -> Result<(), Error> {
env_logger::init();
let event_loop = EventLoop::new();
let mut input = WinitInputHelper::new();
let (window, surface, p_width, p_height, mut hidpi_factor) =
let (window, surface, p_width, p_height, mut _hidpi_factor) =
create_window("Conway's Game of Life", &event_loop);
let surface_texture = SurfaceTexture::new(p_width, p_height, surface);
@ -110,7 +110,7 @@ fn main() -> Result<(), Error> {
}
// Adjust high DPI factor
if let Some(factor) = input.scale_factor_changed() {
hidpi_factor = factor;
_hidpi_factor = factor;
}
// Resize the window
if let Some(size) = input.window_resized() {

View file

@ -25,7 +25,7 @@ fn main() -> Result<(), Error> {
.parse()
.unwrap_or(false);
let (window, surface, width, height, mut hidpi_factor) =
let (window, surface, width, height, mut _hidpi_factor) =
create_window("pixel invaders", &event_loop);
let surface_texture = SurfaceTexture::new(width, height, surface);
let mut pixels = Pixels::new(SCREEN_WIDTH as u32, SCREEN_HEIGHT as u32, surface_texture)?;
@ -99,7 +99,7 @@ fn main() -> Result<(), Error> {
// Adjust high DPI factor
if let Some(factor) = input.scale_factor_changed() {
hidpi_factor = factor;
_hidpi_factor = factor;
}
// Resize the window

View file

@ -34,7 +34,6 @@ fn main() -> Result<(), Error> {
.build(&event_loop)
.unwrap()
};
let mut hidpi_factor = window.scale_factor();
let mut pixels = {
let surface = Surface::create(&window);
@ -65,11 +64,6 @@ fn main() -> Result<(), Error> {
return;
}
// Adjust high DPI factor
if let Some(factor) = input.scale_factor_changed() {
hidpi_factor = factor;
}
// Resize the window
if let Some(size) = input.window_resized() {
pixels.resize(size.width, size.height);

View file

@ -418,7 +418,7 @@ impl<'req> PixelsBuilder<'req> {
width,
height,
pixel_aspect_ratio: 1.0,
present_mode: wgpu::PresentMode::Mailbox,
present_mode: wgpu::PresentMode::Fifo,
surface_texture,
texture_format: wgpu::TextureFormat::Rgba8UnormSrgb,
renderer_factories: Vec::new(),
@ -469,18 +469,30 @@ impl<'req> PixelsBuilder<'req> {
self
}
/// Enable or disable vsync.
/// Enable or disable Vsync.
///
/// Vsync is enabled by default.
///
/// The `wgpu` present mode will be set to `Fifo` when Vsync is enabled, or `Immediate` when
/// Vsync is disabled. To set the present mode to `Mailbox` or another value, use the
/// [`present_mode`] method.
pub fn enable_vsync(mut self, enable_vsync: bool) -> PixelsBuilder<'req> {
self.present_mode = if enable_vsync {
wgpu::PresentMode::Mailbox
wgpu::PresentMode::Fifo
} else {
wgpu::PresentMode::Immediate
};
self
}
/// Set the `wgpu` present mode.
///
/// This differs from [`enable_vsync`] by allowing the present mode to be set to any value.
pub fn present_mode(mut self, present_mode: wgpu::PresentMode) -> PixelsBuilder<'req> {
self.present_mode = present_mode;
self
}
/// Set the texture format.
///
/// The default value is [`wgpu::TextureFormat::Rgba8UnormSrgb`], which is 4 unsigned bytes in