From e5efcf6c765a6379bc5a132b80d2eeddc8105301 Mon Sep 17 00:00:00 2001 From: Altagos Date: Thu, 29 Feb 2024 22:23:14 +0100 Subject: [PATCH] changed render context --- src/rayray.zig | 4 ++-- src/renderer.zig | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/rayray.zig b/src/rayray.zig index 270d8fe..3093db9 100644 --- a/src/rayray.zig +++ b/src/rayray.zig @@ -60,8 +60,8 @@ pub const Raytracer = struct { const finished_threads = try self.allocator.alloc(bool, num_threads); for (0..num_threads) |row| { - const ctx = renderer.Context{ .cam = &self.camera, .world = &self.world, .done = &threads[row].done }; - const t = try std.Thread.spawn(.{}, renderer.renderThread, .{ ctx, row, row_height }); + const ctx = renderer.Context{ .cam = &self.camera, .world = &self.world }; + const t = try std.Thread.spawn(.{}, renderer.renderThread, .{ ctx, &threads[row].done, row, row_height }); threads[row].thread = t; } diff --git a/src/renderer.zig b/src/renderer.zig index 4c88b7b..52fed9e 100644 --- a/src/renderer.zig +++ b/src/renderer.zig @@ -17,7 +17,6 @@ const log = std.log.scoped(.renderer); pub const Context = struct { cam: *Camera, world: *hittable.HittableList, - done: *std.atomic.Value(bool), }; pub fn rayColor(r: *Ray, world: *hittable.HittableList) zm.Vec { @@ -30,7 +29,7 @@ pub fn rayColor(r: *Ray, world: *hittable.HittableList) zm.Vec { return zm.f32x4s(1.0 - a) * zm.f32x4s(1.0) + zm.f32x4s(a) * zm.f32x4(0.5, 0.7, 1.0, 1.0); } -pub fn render(ctx: Context, height: IntervalUsize, width: IntervalUsize) void { +pub fn run(ctx: Context, height: IntervalUsize, width: IntervalUsize) void { var height_iter = height.iter(); height_iter.upper_boundry = .inclusive; @@ -51,11 +50,9 @@ pub fn render(ctx: Context, height: IntervalUsize, width: IntervalUsize) void { ctx.cam.setPixel(i, j, col) catch break; } } - - ctx.done.store(true, .Release); } -pub fn renderThread(ctx: Context, row: usize, row_height: usize) void { +pub fn renderThread(ctx: Context, done: *std.atomic.Value(bool), row: usize, row_height: usize) void { spall.init_thread(); defer spall.deinit_thread(); @@ -67,7 +64,9 @@ pub fn renderThread(ctx: Context, row: usize, row_height: usize) void { const s = spall.trace(@src(), "Render Thread {}", .{row}); defer s.end(); - render(ctx, height, width); + run(ctx, height, width); + + done.store(true, .Release); } fn vecToRgba(v: zm.Vec) color.Rgba32 { -- 2.51.2