diff options
Diffstat (limited to 'src/tsv.zig')
| -rw-r--r-- | src/tsv.zig | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/tsv.zig b/src/tsv.zig new file mode 100644 index 0000000..9f15f2f --- /dev/null +++ b/src/tsv.zig @@ -0,0 +1,77 @@ +const std = @import("std"); +const c = @import("c.zig"); +const gl = @import("gl.zig"); +const Output = @import("output.zig").Output; + +pub const TSVOutput = struct { + pub const Config = struct { + name: [:0]const u8, + + pub const default: Config = .{ + .name = "glsl-view", + }; + + pub fn create( + config: *const Config, + allocator: std.mem.Allocator, + constants: *gl.Constants, + ) *Output { + const self = allocator.create(TSVOutput) catch unreachable; + + _ = c.gl_client_initialize_external_gl() or unreachable; + + self.* = .{ + .output = .{ + .update_fn = update, + .destroy_fn = destroy, + }, + .config = config, + .client = c.gl_client_new(c.VK_SERVER_DEFAULT_SOCKET_PATH, 1000) orelse unreachable, + .image_size = .{ + .top_left = .{ 0, 0 }, + .bottom_right = .{ constants.config.width, constants.config.height }, + }, + }; + + _ = c.gl_client_init_image( + self.client, + config.name, + @intCast(constants.config.width), + @intCast(constants.config.height), + c.R8G8B8A8, + true, + ); + + return &self.output; + } + }; + + output: Output, + config: *const Config, + client: *c.GlClient, + image_size: c.GlImageExtent, + + fn update(output: *Output, texture_id: c.GLuint) bool { + const self: *TSVOutput = @fieldParentPtr("output", output); + + var fbo: c.GLint = undefined; + c.glGetIntegerv(c.GL_DRAW_FRAMEBUFFER_BINDING, &fbo); + + _ = c.gl_client_send_image( + self.client, + self.config.name, + texture_id, + c.GL_TEXTURE_2D, + false, + @intCast(fbo), + &self.image_size, + ); + return false; + } + + fn destroy(output: *Output, allocator: std.mem.Allocator) void { + const self: *TSVOutput = @fieldParentPtr("output", output); + + allocator.destroy(self); + } +}; |
