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:
parent
7779d682cf
commit
b397eb4e48
|
@ -15,7 +15,7 @@ fn main() -> Result<(), Error> {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
let event_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
let mut input = WinitInputHelper::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);
|
create_window("Conway's Game of Life", &event_loop);
|
||||||
|
|
||||||
let surface_texture = SurfaceTexture::new(p_width, p_height, surface);
|
let surface_texture = SurfaceTexture::new(p_width, p_height, surface);
|
||||||
|
@ -110,7 +110,7 @@ fn main() -> Result<(), Error> {
|
||||||
}
|
}
|
||||||
// Adjust high DPI factor
|
// Adjust high DPI factor
|
||||||
if let Some(factor) = input.scale_factor_changed() {
|
if let Some(factor) = input.scale_factor_changed() {
|
||||||
hidpi_factor = factor;
|
_hidpi_factor = factor;
|
||||||
}
|
}
|
||||||
// Resize the window
|
// Resize the window
|
||||||
if let Some(size) = input.window_resized() {
|
if let Some(size) = input.window_resized() {
|
||||||
|
|
|
@ -25,7 +25,7 @@ fn main() -> Result<(), Error> {
|
||||||
.parse()
|
.parse()
|
||||||
.unwrap_or(false);
|
.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);
|
create_window("pixel invaders", &event_loop);
|
||||||
let surface_texture = SurfaceTexture::new(width, height, surface);
|
let surface_texture = SurfaceTexture::new(width, height, surface);
|
||||||
let mut pixels = Pixels::new(SCREEN_WIDTH as u32, SCREEN_HEIGHT as u32, surface_texture)?;
|
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
|
// Adjust high DPI factor
|
||||||
if let Some(factor) = input.scale_factor_changed() {
|
if let Some(factor) = input.scale_factor_changed() {
|
||||||
hidpi_factor = factor;
|
_hidpi_factor = factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resize the window
|
// Resize the window
|
||||||
|
|
|
@ -34,7 +34,6 @@ fn main() -> Result<(), Error> {
|
||||||
.build(&event_loop)
|
.build(&event_loop)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
let mut hidpi_factor = window.scale_factor();
|
|
||||||
|
|
||||||
let mut pixels = {
|
let mut pixels = {
|
||||||
let surface = Surface::create(&window);
|
let surface = Surface::create(&window);
|
||||||
|
@ -65,11 +64,6 @@ fn main() -> Result<(), Error> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adjust high DPI factor
|
|
||||||
if let Some(factor) = input.scale_factor_changed() {
|
|
||||||
hidpi_factor = factor;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resize the window
|
// Resize the window
|
||||||
if let Some(size) = input.window_resized() {
|
if let Some(size) = input.window_resized() {
|
||||||
pixels.resize(size.width, size.height);
|
pixels.resize(size.width, size.height);
|
||||||
|
|
18
src/lib.rs
18
src/lib.rs
|
@ -418,7 +418,7 @@ impl<'req> PixelsBuilder<'req> {
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
pixel_aspect_ratio: 1.0,
|
pixel_aspect_ratio: 1.0,
|
||||||
present_mode: wgpu::PresentMode::Mailbox,
|
present_mode: wgpu::PresentMode::Fifo,
|
||||||
surface_texture,
|
surface_texture,
|
||||||
texture_format: wgpu::TextureFormat::Rgba8UnormSrgb,
|
texture_format: wgpu::TextureFormat::Rgba8UnormSrgb,
|
||||||
renderer_factories: Vec::new(),
|
renderer_factories: Vec::new(),
|
||||||
|
@ -469,18 +469,30 @@ impl<'req> PixelsBuilder<'req> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enable or disable vsync.
|
/// Enable or disable Vsync.
|
||||||
///
|
///
|
||||||
/// Vsync is enabled by default.
|
/// 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> {
|
pub fn enable_vsync(mut self, enable_vsync: bool) -> PixelsBuilder<'req> {
|
||||||
self.present_mode = if enable_vsync {
|
self.present_mode = if enable_vsync {
|
||||||
wgpu::PresentMode::Mailbox
|
wgpu::PresentMode::Fifo
|
||||||
} else {
|
} else {
|
||||||
wgpu::PresentMode::Immediate
|
wgpu::PresentMode::Immediate
|
||||||
};
|
};
|
||||||
self
|
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.
|
/// Set the texture format.
|
||||||
///
|
///
|
||||||
/// The default value is [`wgpu::TextureFormat::Rgba8UnormSrgb`], which is 4 unsigned bytes in
|
/// The default value is [`wgpu::TextureFormat::Rgba8UnormSrgb`], which is 4 unsigned bytes in
|
||||||
|
|
Loading…
Reference in a new issue