aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/renderer/opengl/Frame.zig
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-04-04 19:22:04 +0300
committerCan Celik <ogulcancelik@gmail.com>2026-04-05 01:23:06 +0300
commit41dd733ca7123c9ac4bfc6c781697a660e95b052 (patch)
tree3fc91815ca139ef2e0b281bba0abda4ef15175f4 /vendor/libghostty-vt/src/renderer/opengl/Frame.zig
parent55c138263e190a1e79d4b997bfb9397306c0ec1f (diff)
feat: finish ghostty pane backend integration
Diffstat (limited to 'vendor/libghostty-vt/src/renderer/opengl/Frame.zig')
-rw-r--r--vendor/libghostty-vt/src/renderer/opengl/Frame.zig71
1 files changed, 71 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/src/renderer/opengl/Frame.zig b/vendor/libghostty-vt/src/renderer/opengl/Frame.zig
new file mode 100644
index 00000000..289413b0
--- /dev/null
+++ b/vendor/libghostty-vt/src/renderer/opengl/Frame.zig
@@ -0,0 +1,71 @@
+//! Wrapper for handling render passes.
+const Self = @This();
+
+const std = @import("std");
+const Allocator = std.mem.Allocator;
+const gl = @import("opengl");
+
+const Renderer = @import("../generic.zig").Renderer(OpenGL);
+const OpenGL = @import("../OpenGL.zig");
+const Target = @import("Target.zig");
+const RenderPass = @import("RenderPass.zig");
+
+const Health = @import("../../renderer.zig").Health;
+
+const log = std.log.scoped(.opengl);
+
+/// Options for beginning a frame.
+pub const Options = struct {};
+
+renderer: *Renderer,
+target: *Target,
+
+/// Begin encoding a frame.
+pub fn begin(
+ opts: Options,
+ /// Once the frame has been completed, the `frameCompleted` method
+ /// on the renderer is called with the health status of the frame.
+ renderer: *Renderer,
+ /// The target is presented via the provided renderer's API when completed.
+ target: *Target,
+) !Self {
+ _ = opts;
+
+ return .{
+ .renderer = renderer,
+ .target = target,
+ };
+}
+
+/// Add a render pass to this frame with the provided attachments.
+/// Returns a RenderPass which allows render steps to be added.
+pub inline fn renderPass(
+ self: *const Self,
+ attachments: []const RenderPass.Options.Attachment,
+) RenderPass {
+ _ = self;
+ return RenderPass.begin(.{ .attachments = attachments });
+}
+
+/// Complete this frame and present the target.
+///
+/// If `sync` is true, this will block until the frame is presented.
+///
+/// NOTE: For OpenGL, `sync` is ignored and we always block.
+pub fn complete(self: *const Self, sync: bool) void {
+ _ = sync;
+ gl.finish();
+
+ // If there are any GL errors, consider the frame unhealthy.
+ const health: Health = if (gl.errors.getError()) .healthy else |_| .unhealthy;
+
+ // If the frame is healthy, present it.
+ if (health == .healthy) {
+ self.renderer.api.present(self.target.*) catch |err| {
+ log.err("Failed to present render target: err={}", .{err});
+ };
+ }
+
+ // Report the health to the renderer.
+ self.renderer.frameCompleted(health);
+}