diff options
Diffstat (limited to 'src/output.zig')
| -rw-r--r-- | src/output.zig | 164 |
1 files changed, 47 insertions, 117 deletions
diff --git a/src/output.zig b/src/output.zig index 593caac..c236f4a 100644 --- a/src/output.zig +++ b/src/output.zig @@ -12,11 +12,14 @@ pub const Output = struct { allocator: std.mem.Allocator, config: *const cfg.OutputConfig, constants: *gl.Constants, - ) *Output { - return switch (config.*) { - .window => |*con| WindowOutput.create(allocator, con, constants), - .texture_share_vk => |*con| if (build_config.have_tsv) TSVOutput.create(allocator, con, constants) else unreachable, - }; + ) !*Output { + switch (config.*) { + inline else => |*con| { + const ConfigType = @TypeOf(con.*); + if (ConfigType == void) return error.supportDisabled; + return con.create(allocator, constants); + }, + } } pub fn update(self: *Output, texture_id: c.GLuint) bool { @@ -28,79 +31,6 @@ pub const Output = struct { } }; -pub const TSVOutput = struct { - pub const Config = struct { - name: [:0]const u8, - - pub const default: Config = .{ - .name = "glsl-view", - }; - }; - - output: Output, - config: *const Config, - client: *c.GlClient, - image_size: c.GlImageExtent, - - pub fn create( - allocator: std.mem.Allocator, - config: *const Config, - 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; - } - - 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); - } -}; - pub const WindowOutput = struct { pub const Config = struct { const FilterMode = enum(c.GLuint) { @@ -122,6 +52,45 @@ pub const WindowOutput = struct { .monitor = "", .fullscreen = false, }; + + pub fn create( + config: *const Config, + allocator: std.mem.Allocator, + constants: *gl.Constants, + ) *Output { + const self = allocator.create(WindowOutput) catch unreachable; + + c.glfwDefaultWindowHints(); + c.glfwWindowHint(c.GLFW_FOCUSED, c.GLFW_FALSE); + c.glfwWindowHint(c.GLFW_FLOATING, c.GLFW_TRUE); + c.glfwWindowHint(c.GLFW_TRANSPARENT_FRAMEBUFFER, c.GL_TRUE); + + self.* = .{ + .constants = constants, + .output = .{ + .update_fn = update, + .destroy_fn = destroy, + }, + .window = c.glfwCreateWindow( + config.width, + config.height, + "glsl-view output", + null, + constants.main_window, + ) orelse { + std.debug.panic("unable to create output window\n", .{}); + }, + }; + + c.glfwSetWindowUserPointer(self.window, @as(*anyopaque, @ptrCast(self))); + _ = c.glfwSetKeyCallback(self.window, keyCallback); + _ = c.glfwSetFramebufferSizeCallback(self.window, sizeCallback); + + c.glfwMakeContextCurrent(self.window); + constants.normalized_quad.bind(0); + + return &self.output; + } }; output: Output, @@ -130,45 +99,6 @@ pub const WindowOutput = struct { resized: bool = false, - pub fn create( - allocator: std.mem.Allocator, - config: *const Config, - constants: *gl.Constants, - ) *Output { - const self = allocator.create(WindowOutput) catch unreachable; - - c.glfwDefaultWindowHints(); - c.glfwWindowHint(c.GLFW_FOCUSED, c.GLFW_FALSE); - c.glfwWindowHint(c.GLFW_FLOATING, c.GLFW_TRUE); - c.glfwWindowHint(c.GLFW_TRANSPARENT_FRAMEBUFFER, c.GL_TRUE); - - self.* = .{ - .constants = constants, - .output = .{ - .update_fn = update, - .destroy_fn = destroy, - }, - .window = c.glfwCreateWindow( - config.width, - config.height, - "glsl-view output", - null, - constants.main_window, - ) orelse { - std.debug.panic("unable to create output window\n", .{}); - }, - }; - - c.glfwSetWindowUserPointer(self.window, @as(*anyopaque, @ptrCast(self))); - _ = c.glfwSetKeyCallback(self.window, keyCallback); - _ = c.glfwSetFramebufferSizeCallback(self.window, sizeCallback); - - c.glfwMakeContextCurrent(self.window); - constants.normalized_quad.bind(0); - - return &self.output; - } - fn update(output: *Output, texture_id: c.GLuint) bool { const self: *WindowOutput = @fieldParentPtr("output", output); |
