Completed a basic parallel renderer. Fixed warnings

This commit is contained in:
Ishan Jain 2020-02-16 20:47:43 +05:30
parent c52d148451
commit df6d27d5c8
2 changed files with 24 additions and 3 deletions

View File

@ -34,7 +34,7 @@ pub struct Chunk {
}
pub trait Demo: std::marker::Sync {
fn render(&self, buf: &mut [u8], width: usize, height: usize, samples: u8) {
fn render(&self, buf: &mut Vec<u8>, width: usize, height: usize, samples: u8) {
let nx = width / VERTICAL_PARTITION;
let ny = height / HORIZONTAL_PARTITION;
@ -61,7 +61,28 @@ pub trait Demo: std::marker::Sync {
.par_iter_mut()
.for_each(|mut chunk| self.render_chunk(&mut chunk, samples));
// ((y - j - 1) * x + i) * 4
for chunk in chunks {
let x = chunk.x;
let y = chunk.y;
let nx = chunk.nx;
let ny = chunk.ny;
let start_x = chunk.start_x;
let start_y = chunk.start_y;
let buffer = chunk.buffer;
let mut temp_offset = 0;
for j in start_y..start_y + ny {
for i in start_x..start_x + nx {
let real_offset = ((y - j - 1) * x + i) * 4;
for k in 0..4 {
buf[real_offset + k] = buffer[temp_offset + k];
}
temp_offset += 4;
}
}
}
}
fn render_chunk(&self, chunk: &mut Chunk, samples: u8);

View File

@ -7,7 +7,7 @@ impl Demo for SimpleRectangle {
"simple_rectangle"
}
fn render_chunk(&self, chunk: &mut Chunk, samples: u8) {
fn render_chunk(&self, chunk: &mut Chunk, _samples: u8) {
let x = chunk.x;
let y = chunk.y;
let nx = chunk.nx;