Move backdrop color read out of compose_pixel

Former-commit-id: 20d5d8a35b5e7fa0ca46bea297b1b554ba98948d
Former-commit-id: f50dbe6b529fef91f5cf5a0a808d93b878f2adff
This commit is contained in:
sapir 2020-04-12 23:11:43 +03:00 committed by MishMish
parent 529c9752c4
commit 9d08ac13e6

View file

@ -73,6 +73,8 @@ impl Gpu {
/// Composes the render layers into a final scanline while applying needed special effects, and render it to the frame buffer /// Composes the render layers into a final scanline while applying needed special effects, and render it to the frame buffer
pub fn finalize_scanline(&mut self, bg_start: usize, bg_end: usize) { pub fn finalize_scanline(&mut self, bg_start: usize, bg_end: usize) {
let backdrop_color = Rgb15(self.palette_ram.read_16(0));
let y = self.vcount; let y = self.vcount;
let output = unsafe { let output = unsafe {
let ptr = self.frame_buffer[y * DISPLAY_WIDTH..].as_mut_ptr(); let ptr = self.frame_buffer[y * DISPLAY_WIDTH..].as_mut_ptr();
@ -82,7 +84,7 @@ impl Gpu {
let win = WindowInfo::new(WindowType::WinNone, WindowFlags::all()); let win = WindowInfo::new(WindowType::WinNone, WindowFlags::all());
let backgrounds = self.active_backgrounds_sorted(bg_start, bg_end, win.flags); let backgrounds = self.active_backgrounds_sorted(bg_start, bg_end, win.flags);
for x in 0..DISPLAY_WIDTH { for x in 0..DISPLAY_WIDTH {
let pixel = self.compose_pixel(x, y, &win, &backgrounds); let pixel = self.compose_pixel(x, y, &win, &backgrounds, backdrop_color);
output[x] = pixel.to_rgb24(); output[x] = pixel.to_rgb24();
} }
} else { } else {
@ -92,7 +94,7 @@ impl Gpu {
let win = WindowInfo::new(WindowType::Win0, self.win0.flags); let win = WindowInfo::new(WindowType::Win0, self.win0.flags);
let backgrounds = self.active_backgrounds_sorted(bg_start, bg_end, win.flags); let backgrounds = self.active_backgrounds_sorted(bg_start, bg_end, win.flags);
for x in self.win0.left()..self.win0.right() { for x in self.win0.left()..self.win0.right() {
let pixel = self.compose_pixel(x, y, &win, &backgrounds); let pixel = self.compose_pixel(x, y, &win, &backgrounds, backdrop_color);
output[x] = pixel.to_rgb24(); output[x] = pixel.to_rgb24();
occupied[x] = true; occupied[x] = true;
occupied_count += 1; occupied_count += 1;
@ -106,7 +108,7 @@ impl Gpu {
let backgrounds = self.active_backgrounds_sorted(bg_start, bg_end, win.flags); let backgrounds = self.active_backgrounds_sorted(bg_start, bg_end, win.flags);
for x in self.win1.left()..self.win1.right() { for x in self.win1.left()..self.win1.right() {
if !occupied[x] { if !occupied[x] {
let pixel = self.compose_pixel(x, y, &win, &backgrounds); let pixel = self.compose_pixel(x, y, &win, &backgrounds, backdrop_color);
output[x] = pixel.to_rgb24(); output[x] = pixel.to_rgb24();
occupied[x] = true; occupied[x] = true;
occupied_count += 1; occupied_count += 1;
@ -130,13 +132,25 @@ impl Gpu {
let obj_entry = self.obj_buffer_get(x, y); let obj_entry = self.obj_buffer_get(x, y);
if obj_entry.window { if obj_entry.window {
// WinObj // WinObj
let pixel = self.compose_pixel(x, y, &win_obj, &win_obj_backgrounds); let pixel = self.compose_pixel(
x,
y,
&win_obj,
&win_obj_backgrounds,
backdrop_color,
);
output[x] = pixel.to_rgb24(); output[x] = pixel.to_rgb24();
occupied[x] = true; occupied[x] = true;
occupied_count += 1; occupied_count += 1;
} else { } else {
// WinOut // WinOut
let pixel = self.compose_pixel(x, y, &win_out, &win_out_backgrounds); let pixel = self.compose_pixel(
x,
y,
&win_out,
&win_out_backgrounds,
backdrop_color,
);
output[x] = pixel.to_rgb24(); output[x] = pixel.to_rgb24();
occupied[x] = true; occupied[x] = true;
occupied_count += 1; occupied_count += 1;
@ -147,7 +161,8 @@ impl Gpu {
if occupied[x] { if occupied[x] {
continue; continue;
} }
let pixel = self.compose_pixel(x, y, &win_out, &win_out_backgrounds); let pixel =
self.compose_pixel(x, y, &win_out, &win_out_backgrounds, backdrop_color);
output[x] = pixel.to_rgb24(); output[x] = pixel.to_rgb24();
occupied[x] = true; occupied[x] = true;
occupied_count += 1; occupied_count += 1;
@ -156,9 +171,14 @@ impl Gpu {
} }
} }
fn compose_pixel(&self, x: usize, y: usize, win: &WindowInfo, backgrounds: &[usize]) -> Rgb15 { fn compose_pixel(
let backdrop_color = Rgb15(self.palette_ram.read_16(0)); &self,
x: usize,
y: usize,
win: &WindowInfo,
backgrounds: &[usize],
backdrop_color: Rgb15,
) -> Rgb15 {
let mut layers = ArrayVec::<[_; 7]>::new(); let mut layers = ArrayVec::<[_; 7]>::new();
unsafe { unsafe {
layers.push_unchecked(RenderLayer::backdrop(backdrop_color)); layers.push_unchecked(RenderLayer::backdrop(backdrop_color));