diff options
| author | nsfisis <nsfisis@gmail.com> | 2023-01-28 20:54:41 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2023-01-28 20:54:41 +0900 |
| commit | 84b019965f63d02f0d8f6e3a108f7d29ffa23076 (patch) | |
| tree | 81260fb8491dfb40f633a89510147e76e9d6a355 /src/rtw/texture.zig | |
| parent | f29f83f635e3c8d784241cdc26e67fe8cda72f08 (diff) | |
| download | RayTracingInOneWeekend.zig-84b019965f63d02f0d8f6e3a108f7d29ffa23076.tar.gz RayTracingInOneWeekend.zig-84b019965f63d02f0d8f6e3a108f7d29ffa23076.tar.zst RayTracingInOneWeekend.zig-84b019965f63d02f0d8f6e3a108f7d29ffa23076.zip | |
refactor: allocate internal random states in Perlin in heap
Diffstat (limited to 'src/rtw/texture.zig')
| -rw-r--r-- | src/rtw/texture.zig | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/rtw/texture.zig b/src/rtw/texture.zig index 537ce47..ebbf4cb 100644 --- a/src/rtw/texture.zig +++ b/src/rtw/texture.zig @@ -29,8 +29,8 @@ pub const Texture = union(TextureTag) { ) }; } - pub fn makeNoise(scale: f64, rng: Random) Texture { - return .{ .noise = .{ .perlin = Perlin.init(rng), .scale = scale } }; + pub fn makeNoise(allocator: std.mem.Allocator, scale: f64, rng: Random) !Texture { + return .{ .noise = try NoiseTexture.init(allocator, rng, scale) }; } pub fn value(tx: Texture, u: f64, v: f64, p: Vec3) Color { @@ -85,6 +85,17 @@ pub const NoiseTexture = struct { perlin: Perlin, scale: f64, + fn init(allocator: std.mem.Allocator, rng: Random, scale: f64) !NoiseTexture { + return .{ + .perlin = try Perlin.init(allocator, rng), + .scale = scale, + }; + } + + fn deinit(tx: NoiseTexture) void { + tx.perlin.deinit(); + } + fn value(tx: NoiseTexture, u: f64, v: f64, p: Vec3) Color { _ = u; _ = v; |
