aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig56
1 files changed, 31 insertions, 25 deletions
diff --git a/src/main.zig b/src/main.zig
index 9b09945..0bf4cfc 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -120,14 +120,6 @@ pub fn main() !void {
var loops: u8 = 0;
- const stdout = std.fs.File.stdout();
- var tex_buffer: ?[]u8 = null;
-
- if (!stdout.isTty()) {
- tex_buffer = try allocator.alloc(u8, @intCast(config.width * config.height * 4));
- }
- defer if (tex_buffer) |buf| allocator.free(buf);
-
while (c.glfwWindowShouldClose(window) == c.GL_FALSE) {
c.glfwMakeContextCurrent(window);
@@ -145,24 +137,20 @@ pub fn main() !void {
// control.reload_requested = false;
// }
- if (control.dirty) {
+ const is_fresh = if (control.dirty) blk: {
c.glFinish();
var timer = try std.time.Timer.start();
- fbo.bind();
- c.glClear(c.GL_COLOR_BUFFER_BIT);
+ {
+ fbo.bind();
+ defer fbo.unbind();
- main_program.bind();
- constants.normalized_quad.draw();
+ c.glClear(c.GL_COLOR_BUFFER_BIT);
- if (tex_buffer) |buf| {
- fbo.read(config.width, config.height, buf);
- std.debug.print("writing {} bytes\n", .{buf.len});
- _ = try stdout.write(buf);
+ main_program.bind();
+ constants.normalized_quad.draw();
}
- fbo.unbind();
-
c.glFinish();
const fps = timer.read(); // ns
loops = (loops + 1) % 64;
@@ -171,18 +159,36 @@ pub fn main() !void {
}
control.dirty = false;
- }
+ break :blk true;
+ } else false;
+
+ var keep_running = false;
+ var i: usize = outputs.items.len;
+ while (i > 0) {
+ i -= 1;
+ const output = outputs.items[i];
+
+ var close_output = false;
+ if (output.update(fbo, is_fresh)) |res| {
+ if (res) |close| {
+ if (close) {
+ close_output = true;
+ } else {
+ keep_running = true;
+ }
+ }
+ } else |err| {
+ std.debug.print("Output {} closing due to error: {}\n", .{ output, err });
+ close_output = true;
+ }
- for (outputs.items, 0..) |output, i| {
- const close = output.update(fbo.texture_id);
- if (close) {
+ if (close_output) {
const removed = outputs.swapRemove(i);
removed.destroy(cfg_allocator);
- break;
}
}
- if (outputs.items.len == 0)
+ if (!keep_running)
break;
c.glfwMakeContextCurrent(window);