better gpu?

This commit is contained in:
Alex Janka 2023-02-26 16:04:41 +11:00
parent e70e8d6ce5
commit 78bb6fc65f
2 changed files with 11 additions and 4 deletions

View file

@ -24,6 +24,7 @@ pub struct Gpu {
pub vram: Vram, pub vram: Vram,
pub oam: Oam, pub oam: Oam,
pub window: Box<dyn Renderer>, pub window: Box<dyn Renderer>,
is_bg_zero: Vec<bool>,
lcdc: Lcdc, lcdc: Lcdc,
stat: Stat, stat: Stat,
mode_clock: usize, mode_clock: usize,
@ -55,6 +56,7 @@ impl Gpu {
vram: Vram::default(), vram: Vram::default(),
oam: Oam::default(), oam: Oam::default(),
window, window,
is_bg_zero: vec![true; WIDTH],
lcdc: Lcdc::default(), lcdc: Lcdc::default(),
stat: Stat::default(), stat: Stat::default(),
mode_clock: 0, mode_clock: 0,
@ -153,6 +155,9 @@ impl Gpu {
} }
fn render_scanline(&mut self, scanline: u8) { fn render_scanline(&mut self, scanline: u8) {
for e in &mut self.is_bg_zero {
*e = true;
}
for x in 0..WIDTH { for x in 0..WIDTH {
self.buffer[(scanline as usize * WIDTH) + x] = Colour::from_u8_rgb(255, 0, 255); self.buffer[(scanline as usize * WIDTH) + x] = Colour::from_u8_rgb(255, 0, 255);
} }
@ -292,9 +297,7 @@ impl Gpu {
let x_coord = x_coord_uncorrected - 8; let x_coord = x_coord_uncorrected - 8;
if x_coord < WIDTH { if x_coord < WIDTH {
let buffer_index = (scanline as usize * WIDTH) + x_coord; let buffer_index = (scanline as usize * WIDTH) + x_coord;
if !object.flags.behind_bg_and_window if !object.flags.behind_bg_and_window || self.is_bg_zero[x_coord] {
|| self.buffer[buffer_index] == self.bg_palette.zero.as_rgb()
{
self.buffer[buffer_index] = colour.as_rgb(); self.buffer[buffer_index] = colour.as_rgb();
} }
} }
@ -340,6 +343,10 @@ impl Gpu {
let msb = get_bit(msbs, 7 - tile_px_x); let msb = get_bit(msbs, 7 - tile_px_x);
let colour = self.bg_palette.map_bits(lsb, msb); let colour = self.bg_palette.map_bits(lsb, msb);
if lsb || msb {
self.is_bg_zero[x] = false;
}
self.buffer[(scanline as usize * WIDTH) + x] = colour.as_rgb(); self.buffer[(scanline as usize * WIDTH) + x] = colour.as_rgb();
} }
} }

View file

@ -125,7 +125,7 @@ impl Colour {
} }
} }
#[derive(Clone, Copy)] #[derive(Clone, Copy, Debug)]
pub(super) struct Palette { pub(super) struct Palette {
pub(super) zero: Colour, pub(super) zero: Colour,
pub(super) one: Colour, pub(super) one: Colour,