diff --git a/README.md b/README.md index 1094a4f3..0bb6c261 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,6 @@ cargo build --release --features [optional_features] On by default * `sdl-resample` - Use the audio resampler from sdl2 library and a manual one I wrote * `push-audio` - Use a push methododlogy instead of pull for the delivery of the sound samples to sdl2 -* `static-scale` - Will use a fixed scale values for the renderer instead of addapting to the screen size * `u16pixel` - pixels are represented by 16 bits and not 32 bits - neccessary for interfacing the ili9341 spi lcd * `apu` - Turn on the apu (On by default) * `rpi` - Input is from the RPI GPIO pins and output is to an ili9341 spi lcd connected to the RPI GPIO pins, activates the `u16pixel` feature. diff --git a/gb/Cargo.toml b/gb/Cargo.toml index bb578edb..0133c5b8 100644 --- a/gb/Cargo.toml +++ b/gb/Cargo.toml @@ -30,7 +30,6 @@ sdl = ["sdl2"] sdl-resample = ["apu"] push-audio = ["apu"] static-sdl = ["sdl", "sdl2/bundled", "sdl2/static-link"] -static-scale = ["sdl"] u16pixel = ["lib_gb/u16pixel"] apu = ["lib_gb/apu", "sdl", "wav"] rpi = ["rppal", "u16pixel", "image_inter", "nix/signal"] diff --git a/gb/src/main.rs b/gb/src/main.rs index 2b0d6083..20bc140a 100644 --- a/gb/src/main.rs +++ b/gb/src/main.rs @@ -16,7 +16,6 @@ mod audio{ #[cfg(feature = "sdl")] mod sdl{ pub mod utils; - #[cfg(not(feature = "u16pixel"))] pub mod sdl_gfx_device; #[cfg(feature = "sdl-resample")] pub mod sdl_audio_resampler; diff --git a/gb/src/sdl/sdl_gfx_device.rs b/gb/src/sdl/sdl_gfx_device.rs index 5e3f1bf3..61cd731d 100644 --- a/gb/src/sdl/sdl_gfx_device.rs +++ b/gb/src/sdl/sdl_gfx_device.rs @@ -9,15 +9,12 @@ pub struct SdlGfxDevice{ texture: *mut SDL_Texture, discard:u8, turbo_mul:u8, - #[cfg(feature = "static-scale")] - screen_scale:usize, } +const SDL_PIXEL_FORMAT:u32 = if cfg!(feature = "u16pixel"){SDL_PixelFormatEnum::SDL_PIXELFORMAT_RGB565 as u32}else{SDL_PixelFormatEnum::SDL_PIXELFORMAT_RGB888 as u32}; + impl SdlGfxDevice{ pub fn new(window_name:&str, screen_scale: usize, turbo_mul:u8, disable_vsync:bool, full_screen:bool)->Self{ - #[cfg(feature = "u16pixel")] - std::compile_error("Sdl gfx device must have Pixel type = u32"); - let cs_wnd_name = CString::new(window_name).unwrap(); let (_window, renderer, texture): (*mut SDL_Window, *mut SDL_Renderer, *mut SDL_Texture) = unsafe{ @@ -25,23 +22,19 @@ impl SdlGfxDevice{ std::panic!("Init error: {}", get_sdl_error_message()); } - let window_flags = if full_screen{ - #[cfg(feature = "static-scale")] - log::warn!("Please notice that this binary have been compiled with the static-scale feature and you are running with the full screen option.\nThe rendering window might be in wrong scale."); - + let window_flags = if full_screen{ // Hide cursor SDL_ShowCursor(0); SDL_WindowFlags::SDL_WINDOW_FULLSCREEN_DESKTOP as u32 } else{ - 0 + SDL_WindowFlags::SDL_WINDOW_RESIZABLE as u32 }; let wind:*mut SDL_Window = SDL_CreateWindow( cs_wnd_name.as_ptr(), SDL_WINDOWPOS_UNDEFINED_MASK as i32, SDL_WINDOWPOS_UNDEFINED_MASK as i32, - SCREEN_WIDTH as i32 * screen_scale as i32, SCREEN_HEIGHT as i32 * screen_scale as i32, - window_flags); + SCREEN_WIDTH as i32 * screen_scale as i32, SCREEN_HEIGHT as i32 * screen_scale as i32, window_flags); let mut render_flags = SDL_RendererFlags::SDL_RENDERER_ACCELERATED as u32; if !disable_vsync{ @@ -49,28 +42,16 @@ impl SdlGfxDevice{ } let rend: *mut SDL_Renderer = SDL_CreateRenderer(wind, -1, render_flags); - - let texture_width:i32; - let texture_height:i32; - cfg_if::cfg_if!{ - if #[cfg(feature = "static-scale")]{ - texture_height = SCREEN_HEIGHT as i32 * screen_scale as i32; - texture_width = SCREEN_WIDTH as i32 * screen_scale as i32; - } - else{ - if SDL_RenderSetLogicalSize(rend, (SCREEN_WIDTH as u32) as i32, (SCREEN_HEIGHT as u32) as i32) != 0{ - std::panic!("Error while setting logical rendering\nError:{}", get_sdl_error_message()); - } - texture_height = SCREEN_HEIGHT as i32; - texture_width = SCREEN_WIDTH as i32; - } + if SDL_RenderSetLogicalSize(rend, (SCREEN_WIDTH as u32) as i32, (SCREEN_HEIGHT as u32) as i32) != 0{ + std::panic!("Error while setting logical rendering\nError:{}", get_sdl_error_message()); } - let tex: *mut SDL_Texture = SDL_CreateTexture(rend, - SDL_PixelFormatEnum::SDL_PIXELFORMAT_RGB888 as u32, SDL_TextureAccess::SDL_TEXTUREACCESS_STREAMING as i32, - texture_width, texture_height); - + let tex: *mut SDL_Texture = SDL_CreateTexture(rend, SDL_PIXEL_FORMAT, + SDL_TextureAccess::SDL_TEXTUREACCESS_STREAMING as i32, SCREEN_WIDTH as i32, SCREEN_HEIGHT as i32); + + SDL_SetWindowMinimumSize(wind, SCREEN_WIDTH as i32, SCREEN_HEIGHT as i32); + (wind, rend, tex) }; @@ -79,28 +60,9 @@ impl SdlGfxDevice{ renderer, texture, discard:0, - turbo_mul, - #[cfg(feature = "static-scale")] - screen_scale + turbo_mul } } - - #[cfg(feature = "static-scale")] - fn extend_vec(vec:&[u32], scale:usize, w:usize, h:usize)->Vec{ - let mut new_vec = vec![0;vec.len()*scale*scale]; - for y in 0..h{ - let sy = y*scale; - for x in 0..w{ - let sx = x*scale; - for i in 0..scale{ - for j in 0..scale{ - new_vec[(sy+i)*(w*scale)+sx+j] = vec[y*w+x]; - } - } - } - } - return new_vec; - } } impl GfxDevice for SdlGfxDevice{ @@ -110,17 +72,15 @@ impl GfxDevice for SdlGfxDevice{ return; } - #[cfg(feature = "static-scale")] - let buffer = Self::extend_vec(buffer, self.screen_scale, SCREEN_WIDTH, SCREEN_HEIGHT); - unsafe{ let mut pixels: *mut c_void = std::ptr::null_mut(); let mut length: std::os::raw::c_int = 0; SDL_LockTexture(self.texture, std::ptr::null(), &mut pixels, &mut length); - std::ptr::copy_nonoverlapping(buffer.as_ptr(),pixels as *mut u32, buffer.len()); + std::ptr::copy_nonoverlapping(buffer.as_ptr(),pixels as *mut Pixel, buffer.len()); SDL_UnlockTexture(self.texture); - //There is no need to call SDL_RenderClear since im replacing the whole buffer + // Clear renderer cause the window can be resized + SDL_RenderClear(self.renderer); SDL_RenderCopy(self.renderer, self.texture, std::ptr::null(), std::ptr::null()); SDL_RenderPresent(self.renderer); }