diff --git a/gb-emu/build.rs b/gb-emu/build.rs index 743fbc1..85b807e 100644 --- a/gb-emu/build.rs +++ b/gb-emu/build.rs @@ -1,9 +1,9 @@ -const SHADER_SRC_DIR: &str = "src/renderer/vulkan/shaders"; -const SHADER_OUT_DIR: &str = "shaders"; - fn main() -> Result<(), Box> { #[cfg(feature = "vulkan")] { + const SHADER_SRC_DIR: &str = "src/renderer/vulkan/shaders"; + const SHADER_OUT_DIR: &str = "shaders"; + println!("cargo:rerun-if-changed={}", SHADER_SRC_DIR); std::fs::create_dir_all(SHADER_OUT_DIR)?; diff --git a/gb-emu/src/renderer/pixels.rs b/gb-emu/src/renderer/pixels.rs index cb18a7d..d7ede50 100644 --- a/gb-emu/src/renderer/pixels.rs +++ b/gb-emu/src/renderer/pixels.rs @@ -1,22 +1,38 @@ +use std::sync::Arc; + use pixels::{Pixels, SurfaceTexture}; use winit::window::Window; -pub struct Renderer { + +use super::ResolutionData; + +pub struct RendererBackendManager {} + +impl RendererBackendManager { + pub(super) fn new() -> Self { + Self {} + } +} + +pub struct WindowOptions {} + +pub struct RendererBackend { pub pixels: Pixels, } -impl Renderer { - pub fn new(factor: u32, window: &Window) -> Self { - let pixels = { - let window_size = window.inner_size(); - let width = window_size.width / factor; - let height = window_size.height / factor; - new_pixels(width, height, factor, window) - }; - Self { pixels } +impl RendererBackend { + pub fn new( + resolutions: ResolutionData, + window: &Window, + _: WindowOptions, + _: Arc, + ) -> Self { + Self { + pixels: new_pixels(resolutions, window), + } } - pub fn resize(&mut self, width: u32, height: u32, factor: u32, window: &Window) { - self.pixels = new_pixels(width, height, factor, window); + pub fn resize(&mut self, resolutions: ResolutionData, window: &Window) { + self.pixels = new_pixels(resolutions, window); } pub fn new_frame(&mut self, buffer: &[[u8; 4]]) { @@ -25,19 +41,23 @@ impl Renderer { .copy_from_slice(bytemuck::cast_slice(buffer)); } - pub fn render(&mut self) { + pub fn render(&mut self, _: ResolutionData, _: &RendererBackendManager) { self.pixels.render().unwrap(); } } -fn new_pixels(width: u32, height: u32, scaling: u32, window: &Window) -> Pixels { +fn new_pixels(resolutions: ResolutionData, window: &Window) -> Pixels { let surface_texture: SurfaceTexture<'_, Window> = - SurfaceTexture::new(width * scaling, height * scaling, window); - pixels::PixelsBuilder::new(width, height, surface_texture) - .request_adapter_options(pixels::wgpu::RequestAdapterOptionsBase { - power_preference: pixels::wgpu::PowerPreference::HighPerformance, - ..pixels::wgpu::RequestAdapterOptionsBase::default() - }) - .build() - .unwrap() + SurfaceTexture::new(resolutions.real_width, resolutions.real_height, window); + pixels::PixelsBuilder::new( + resolutions.scaled_width, + resolutions.scaled_height, + surface_texture, + ) + .request_adapter_options(pixels::wgpu::RequestAdapterOptionsBase { + power_preference: pixels::wgpu::PowerPreference::HighPerformance, + ..pixels::wgpu::RequestAdapterOptionsBase::default() + }) + .build() + .unwrap() } diff --git a/gb-emu/src/window.rs b/gb-emu/src/window.rs index 170bbe4..52d8ce1 100644 --- a/gb-emu/src/window.rs +++ b/gb-emu/src/window.rs @@ -8,6 +8,7 @@ use gilrs::{ ff::{BaseEffect, BaseEffectType, EffectBuilder, Replay, Ticks}, Button, Gilrs, }; +#[cfg(feature = "vulkan")] use raw_window_handle::HasRawDisplayHandle; use winit::{ dpi::PhysicalSize, @@ -157,11 +158,14 @@ impl WindowRenderer { scaled_height: inner_size.height / real_factor, }; + #[cfg(feature = "vulkan")] let options = WindowOptions { shader_path: std::path::PathBuf::from( "./test-roms/shaders/slang-shaders/bilinear.slangp", ), }; + #[cfg(feature = "pixels")] + let options = WindowOptions {}; let renderer = Mutex::new(RendererBackend::new(resolutions, &window, options, manager)); let id = window.id();