Skip to content

Commit f454bd9

Browse files
committed
enable out of tree use of opengl renderer
1 parent f46a36f commit f454bd9

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

src/ghostty.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ pub const input = @import("input.zig");
66
pub const internal_os = @import("os/main.zig");
77
pub const renderer = @import("renderer.zig");
88
pub const terminal = @import("terminal/main.zig");
9-
pub const CoreApp = @import("App.zig");
10-
pub const CoreSurface = @import("Surface.zig");
9+
pub const Surface = @import("Surface.zig");
1110
pub const config = @import("config.zig");
11+
pub const gl = @import("opengl");

src/renderer/Metal.zig

+2-1
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,9 @@ pub fn threadEnter(self: *const Metal, surface: *apprt.Surface) !void {
736736
}
737737

738738
/// Callback called by renderer.Thread when it exits.
739-
pub fn threadExit(self: *const Metal) void {
739+
pub fn threadExit(self: *const Metal, surface: *apprt.Surface) void {
740740
_ = self;
741+
_ = surface;
741742

742743
// Metal requires no per-thread state.
743744
}

src/renderer/OpenGL.zig

+7-6
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ pub fn surfaceInit(surface: *apprt.Surface) !void {
451451
const self: OpenGL = undefined;
452452

453453
switch (apprt.runtime) {
454-
else => @compileError("unsupported app runtime for OpenGL"),
454+
else => try self.threadEnter(surface),
455455

456456
apprt.gtk => {
457457
// GTK uses global OpenGL context so we load from null.
@@ -491,12 +491,13 @@ pub fn surfaceInit(surface: *apprt.Surface) !void {
491491
/// final main thread setup requirements.
492492
pub fn finalizeSurfaceInit(self: *const OpenGL, surface: *apprt.Surface) !void {
493493
_ = self;
494-
_ = surface;
495494

496495
// For GLFW, we grabbed the OpenGL context in surfaceInit and we
497496
// need to release it before we start the renderer thread.
498497
if (apprt.runtime == apprt.glfw) {
499498
glfw.makeContextCurrent(null);
499+
} else {
500+
try surface.finalizeSurfaceInit();
500501
}
501502
}
502503

@@ -555,7 +556,7 @@ pub fn threadEnter(self: *const OpenGL, surface: *apprt.Surface) !void {
555556
_ = self;
556557

557558
switch (apprt.runtime) {
558-
else => @compileError("unsupported app runtime for OpenGL"),
559+
else => try surface.threadEnter(),
559560

560561
apprt.gtk => {
561562
// GTK doesn't support threaded OpenGL operations as far as I can
@@ -593,11 +594,11 @@ pub fn threadEnter(self: *const OpenGL, surface: *apprt.Surface) !void {
593594
}
594595

595596
/// Callback called by renderer.Thread when it exits.
596-
pub fn threadExit(self: *const OpenGL) void {
597+
pub fn threadExit(self: *const OpenGL, surface: *apprt.Surface) void {
597598
_ = self;
598599

599600
switch (apprt.runtime) {
600-
else => @compileError("unsupported app runtime for OpenGL"),
601+
else => surface.threadExit(),
601602

602603
apprt.gtk => {
603604
// We don't need to do any unloading for GTK because we may
@@ -2332,7 +2333,7 @@ pub fn drawFrame(self: *OpenGL, surface: *apprt.Surface) !void {
23322333
apprt.glfw => surface.window.swapBuffers(),
23332334
apprt.gtk => {},
23342335
apprt.embedded => {},
2335-
else => @compileError("unsupported runtime"),
2336+
else => try surface.swapBuffers(),
23362337
}
23372338
}
23382339

src/renderer/Thread.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ fn threadMain_(self: *Thread) !void {
217217
// renderers have to do per-thread setup. For example, OpenGL has to set
218218
// some thread-local state since that is how it works.
219219
try self.renderer.threadEnter(self.surface);
220-
defer self.renderer.threadExit();
220+
defer self.renderer.threadExit(self.surface);
221221

222222
// Start the async handlers
223223
self.wakeup.wait(&self.loop, &self.wakeup_c, Thread, self, wakeupCallback);

0 commit comments

Comments
 (0)