diff options
Diffstat (limited to 'src/gl.zig')
| -rw-r--r-- | src/gl.zig | 68 |
1 files changed, 55 insertions, 13 deletions
@@ -879,6 +879,61 @@ pub const ShaderProgram = struct { } }; +pub const Thread = struct { + thread: std.Thread, + window: *c.GLFWwindow, + quit: bool, + + pub fn init( + allocator: std.mem.Allocator, + constants: *const Constants, + comptime f: anytype, + args: anytype, + ) !*Thread { + const thread = try allocator.create(Thread); + errdefer allocator.destroy(thread); + + thread.* = .{ + .thread = undefined, + .window = undefined, + .quit = false, + }; + + thread.thread = try std.Thread.spawn( + .{}, + Thread.runner(f), + .{ thread, constants, args }, + ); + + return thread; + } + + pub const InitFn = fn (*Thread, *const Constants, anytype) anyerror!void; + + fn runner(comptime f: anytype) InitFn { + const ReturnType = @typeInfo(@TypeOf(f)).@"fn".return_type.?; + const Impl = struct { + pub fn init(self: *Thread, constants: *const Constants, args: anytype) ReturnType { + c.glfwWindowHint(c.GLFW_VISIBLE, c.GLFW_FALSE); + self.window = c.glfwCreateWindow(200, 200, "glsl-view Thread", null, constants.main_window) orelse unreachable; + c.glfwMakeContextCurrent(self.window); + + return @call(.auto, f, args); + } + }; + + return Impl.init; + } + + pub fn deinit(self: *Thread, allocator: std.mem.Allocator) void { + self.quit = true; + self.thread.join(); + + c.glfwDestroyWindow(self.window); + allocator.destroy(self); + } +}; + pub const Source = struct { pub const Type = enum { file, @@ -886,14 +941,8 @@ pub const Source = struct { }; texture: Texture, - - update_fn: ?*const fn (self: *Source) void, deinit_fn: *const fn (self: *Source, allocator: std.mem.Allocator) void, - pub fn update(self: *Source) void { - if (self.update_fn) |inner| inner(self); - } - pub fn deinit(self: *Source, allocator: std.mem.Allocator) void { self.deinit_fn(self, allocator); } @@ -972,13 +1021,6 @@ pub const UniformCache = struct { } } } - - pub fn update(self: *UniformCache) void { - var it = self.textures.iterator(); - while (it.next()) |entry| { - entry.value_ptr.*.update(); - } - } }; pub const FramebufferObject = struct { |
