aboutsummaryrefslogtreecommitdiffstats
path: root/src/tsv.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/tsv.zig')
-rw-r--r--src/tsv.zig23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/tsv.zig b/src/tsv.zig
index 33c8c92..77c45ae 100644
--- a/src/tsv.zig
+++ b/src/tsv.zig
@@ -30,9 +30,11 @@ fn get_or_init_client() *c.GlClient {
pub const TSVSource = struct {
source: gl.Source,
name: [:0]const u8,
+ thread: *gl.Thread,
pub fn init(
allocator: std.mem.Allocator,
+ constants: *const gl.Constants,
name: [*:0]const u8,
texture_type: gl.Texture.Type,
) !*gl.Source {
@@ -43,10 +45,10 @@ pub const TSVSource = struct {
.source = .{
.texture = gl.Texture.create(texture_type),
- .update_fn = update,
.deinit_fn = deinit,
},
.name = try allocator.dupeZ(u8, std.mem.span(name)),
+ .thread = undefined,
};
errdefer allocator.free(self.name);
@@ -61,7 +63,8 @@ pub const TSVSource = struct {
c.GL_RGBA8,
);
- self.source.update();
+ self.update();
+ self.thread = try gl.Thread.init(allocator, constants, update_loop, .{self});
return &self.source;
}
@@ -69,23 +72,27 @@ pub const TSVSource = struct {
fn deinit(source: *const gl.Source, allocator: std.mem.Allocator) void {
const self: *const TSVSource = @fieldParentPtr("source", source);
+ self.thread.deinit(allocator);
allocator.free(self.name);
allocator.destroy(self);
}
- fn update(source: *const gl.Source) void {
- const self: *const TSVSource = @fieldParentPtr("source", source);
-
- var fbo: c.GLint = undefined;
- c.glGetIntegerv(c.GL_DRAW_FRAMEBUFFER_BINDING, &fbo);
+ fn update_loop(self: *TSVSource) !void {
+ while (!self.thread.quit) {
+ self.update();
+ c.glFlush();
+ try std.Thread.yield();
+ }
+ }
+ fn update(self: *TSVSource) void {
_ = c.gl_client_recv_image(
get_or_init_client(),
self.name.ptr,
self.source.texture.id,
@intFromEnum(self.source.texture.type),
false,
- @intCast(fbo),
+ 0,
null,
);
}