From df6d27d5c8cf4d7fa92484b34ed154f8c2d17881 Mon Sep 17 00:00:00 2001 From: ishanjain28 Date: Sun, 16 Feb 2020 20:47:43 +0530 Subject: [PATCH] Completed a basic parallel renderer. Fixed warnings --- src/demos/mod.rs | 25 +++++++++++++++++++++++-- src/demos/simple_rectangle.rs | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/demos/mod.rs b/src/demos/mod.rs index 13d7aa1..a801707 100644 --- a/src/demos/mod.rs +++ b/src/demos/mod.rs @@ -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, 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); diff --git a/src/demos/simple_rectangle.rs b/src/demos/simple_rectangle.rs index 9a0a511..0cb3a9f 100644 --- a/src/demos/simple_rectangle.rs +++ b/src/demos/simple_rectangle.rs @@ -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;