diff options
Diffstat (limited to 'src/sketch/root.zig')
| -rw-r--r-- | src/sketch/root.zig | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/sketch/root.zig b/src/sketch/root.zig index 434478c..cb20ab9 100644 --- a/src/sketch/root.zig +++ b/src/sketch/root.zig @@ -232,6 +232,12 @@ pub const Frame = struct { kept.draws = draws; f.emit(.{ .gpu = kept }); } + /// Samples the source color and optionally depth into a distinct image. + pub fn postProcess(f: *Frame, source: Image, destination: Image, post: abi.gpu.PostProcess) void { + var kept = post; + kept.fragment_uniforms = f.keep(u8, post.fragment_uniforms); + f.emit(.{ .post_process = .{ .source = source, .target = destination, .effect = kept } }); + } /// `bytes` into a buffer made by `Host.newBuffer`. pub fn upload(f: *Frame, buffer: abi.Buffer, offset: u32, bytes: []const u8) void { f.emit(.{ .upload = .{ .buffer = buffer, .offset = offset, .bytes = bytes } }); @@ -469,3 +475,24 @@ test "setup receives session resources without a Frame and reports errors" { try std.testing.expectEqual(@as(u32, 1), session.calls); try std.testing.expect(seen); } + +test "postprocess preserves image handles and copies transient uniforms" { + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + var commands: std.ArrayList(abi.Command) = .empty; + var ctx: abi.Context = undefined; + ctx.commands = &commands; + var frame: Frame = undefined; + frame.ctx = &ctx; + frame.scratch = arena.allocator(); + var uniforms = [_]u8{ 1, 2, 3, 4 }; + const source: Image = @fromBackingInt(@intCast(1)); + const target: Image = @fromBackingInt(@intCast(2)); + frame.postProcess(source, target, .{ .vertex = .{ .code = "vertex" }, .fragment = .{ .code = "fragment" }, .sample_depth = true, .fragment_uniforms = &uniforms }); + uniforms[0] = 9; + const post = commands.items[0].post_process; + try std.testing.expectEqual(source, post.source); + try std.testing.expectEqual(target, post.target); + try std.testing.expect(post.effect.sample_depth); + try std.testing.expectEqualSlices(u8, &.{ 1, 2, 3, 4 }, post.effect.fragment_uniforms); +} |
