From 09e0d83e97b4dbaa74cde656874530da24ad2840 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Tue, 3 Oct 2023 15:57:57 +1100 Subject: [PATCH] shaders resizing and version bump! --- Cargo.lock | 2 +- gb-emu/Cargo.toml | 2 +- gb-emu/src/window.rs | 16 ++++++++-------- lib/src/processor/memory/mmio/gpu/types.rs | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 612f2da..915f0ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1220,7 +1220,7 @@ dependencies = [ [[package]] name = "gb-emu" -version = "0.3.3" +version = "0.4.0" dependencies = [ "ash", "ash-window", diff --git a/gb-emu/Cargo.toml b/gb-emu/Cargo.toml index 31125a3..4630877 100644 --- a/gb-emu/Cargo.toml +++ b/gb-emu/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gb-emu" -version = "0.3.3" +version = "0.4.0" edition = "2021" [features] diff --git a/gb-emu/src/window.rs b/gb-emu/src/window.rs index ebc55df..9d6e499 100644 --- a/gb-emu/src/window.rs +++ b/gb-emu/src/window.rs @@ -44,7 +44,7 @@ pub struct WindowInfo { struct WindowData { renderer: Mutex, window: Window, - real_factor: RwLock, + rendered_size: RwLock<(u32, u32)>, } pub struct WindowManager { @@ -111,13 +111,13 @@ impl WindowManager { if let Some(w) = self.windows.get(&window_id) { if let Ok(mut renderer) = w.renderer.lock() { let inner_size = w.window.inner_size(); - if let Ok(real_factor) = w.real_factor.read() { + if let Ok(rendered_size) = w.rendered_size.read() { renderer.render( ResolutionData { real_width: inner_size.width, real_height: inner_size.height, - scaled_width: inner_size.width / *real_factor, - scaled_height: inner_size.height / *real_factor, + scaled_width: rendered_size.0, + scaled_height: rendered_size.1, }, &self.window_data_manager, ); @@ -153,7 +153,7 @@ impl WindowRenderer { ) -> (Self, WindowInfo) { let window = WindowBuilder::new() .with_title("Gameboy") - .with_resizable(false) + .with_resizable(shader_path.is_some()) .build(event_loop) .unwrap(); @@ -177,7 +177,7 @@ impl WindowRenderer { let data = Arc::new(WindowData { renderer, window, - real_factor: RwLock::new(real_factor), + rendered_size: RwLock::new((1, 1)), }); let info = WindowInfo { @@ -211,8 +211,8 @@ impl Renderer<[u8; 4]> for WindowRenderer { let real_width = (width as u32) * real_factor; let real_height = (height as u32) * real_factor; - if let Ok(mut f) = self.data.real_factor.write() { - *f = real_factor; + if let Ok(mut f) = self.data.rendered_size.write() { + *f = (width as u32, height as u32); } self.data diff --git a/lib/src/processor/memory/mmio/gpu/types.rs b/lib/src/processor/memory/mmio/gpu/types.rs index fd4421d..04d2ae6 100644 --- a/lib/src/processor/memory/mmio/gpu/types.rs +++ b/lib/src/processor/memory/mmio/gpu/types.rs @@ -122,9 +122,9 @@ pub(super) fn rgb_from_bytes(bytes: u16) -> Colour { let g = (bytes & (0b11111 << 5)) >> 5; let r = bytes & 0b11111; // direct colour emulation: - // let blue = (raw_blue << 3) | (raw_blue >> 2); - // let green = (raw_green << 3) | (raw_green >> 2); - // let red = (raw_red << 3) | (raw_red >> 2); + // let blue = (b << 3) | (b >> 2); + // let green = (g << 3) | (g >> 2); + // let red = (r << 3) | (r >> 2); // colour emulation from // https://web.archive.org/web/20200322151952/https://byuu.net/video/color-emulation