From 09e4fcbf1460e35c234b1fbaf23644a9197a9379 Mon Sep 17 00:00:00 2001 From: Dennis Ranke Date: Fri, 11 Aug 2023 23:52:19 +0200 Subject: [PATCH] add --scale option --- uw8-window/src/gpu/mod.rs | 19 ++++++++++++++----- uw8-window/src/lib.rs | 9 ++++++++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/uw8-window/src/gpu/mod.rs b/uw8-window/src/gpu/mod.rs index 48dca6c..ba86853 100644 --- a/uw8-window/src/gpu/mod.rs +++ b/uw8-window/src/gpu/mod.rs @@ -41,7 +41,10 @@ impl Window { async fn create(window_config: WindowConfig) -> Result { let event_loop = EventLoop::new(); let window = WindowBuilder::new() - .with_inner_size(PhysicalSize::new(640u32, 480)) + .with_inner_size(PhysicalSize::new( + (320. * window_config.scale).round() as u32, + (240. * window_config.scale).round() as u32, + )) .with_min_inner_size(PhysicalSize::new(320u32, 240)) .with_title("MicroW8") .with_fullscreen(if window_config.fullscreen { @@ -72,7 +75,13 @@ impl Window { let surface_config = wgpu::SurfaceConfiguration { present_mode: wgpu::PresentMode::AutoNoVsync, - ..surface.get_default_config(&adapter, window.inner_size().width, window.inner_size().height).expect("Surface incompatible with adapter") + ..surface + .get_default_config( + &adapter, + window.inner_size().width, + window.inner_size().height, + ) + .expect("Surface incompatible with adapter") }; let filter: Box = create_filter( @@ -354,7 +363,7 @@ impl PaletteScreenMode { format: wgpu::TextureFormat::R8Uint, usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, label: None, - view_formats: &[] + view_formats: &[], }); let palette_texture = device.create_texture(&wgpu::TextureDescriptor { @@ -369,7 +378,7 @@ impl PaletteScreenMode { format: wgpu::TextureFormat::Rgba8UnormSrgb, usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, label: None, - view_formats: &[] + view_formats: &[], }); let screen_texture = device.create_texture(&wgpu::TextureDescriptor { @@ -384,7 +393,7 @@ impl PaletteScreenMode { format: wgpu::TextureFormat::Rgba8UnormSrgb, usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::RENDER_ATTACHMENT, label: None, - view_formats: &[] + view_formats: &[], }); let framebuffer_texture_view = diff --git a/uw8-window/src/lib.rs b/uw8-window/src/lib.rs index a0b4be8..bab2a6f 100644 --- a/uw8-window/src/lib.rs +++ b/uw8-window/src/lib.rs @@ -15,7 +15,7 @@ struct FpsCounter { } impl Window { - pub fn new(config: WindowConfig) -> Result { + pub fn new(mut config: WindowConfig) -> Result { let fps_counter = if config.fps_counter { Some(FpsCounter { start: Instant::now(), @@ -24,6 +24,7 @@ impl Window { } else { None }; + config.scale = config.scale.max(1.).min(20.); if config.enable_gpu { match gpu::Window::new(config) { Ok(window) => { @@ -71,6 +72,7 @@ pub struct WindowConfig { filter: u32, fullscreen: bool, fps_counter: bool, + scale: f32, } impl Default for WindowConfig { @@ -80,6 +82,7 @@ impl Default for WindowConfig { filter: 5, fullscreen: false, fps_counter: false, + scale: 2., } } } @@ -102,6 +105,10 @@ impl WindowConfig { } self.fullscreen = args.contains("--fullscreen"); self.fps_counter = args.contains("--fps"); + self.scale = args + .opt_value_from_str("--scale") + .unwrap() + .unwrap_or(self.scale); } }