Skip to content

Commit 78ef584

Browse files
committed
enable out of tree use of opengl renderer
1 parent fcb4f79 commit 78ef584

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
@@ -749,8 +749,9 @@ pub fn threadEnter(self: *const Metal, surface: *apprt.Surface) !void {
749749
}
750750

751751
/// Callback called by renderer.Thread when it exits.
752-
pub fn threadExit(self: *const Metal) void {
752+
pub fn threadExit(self: *const Metal, surface: *apprt.Surface) void {
753753
_ = self;
754+
_ = surface;
754755

755756
// Metal requires no per-thread state.
756757
}

src/renderer/OpenGL.zig

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

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

458458
apprt.gtk => {
459459
// GTK uses global OpenGL context so we load from null.
@@ -493,12 +493,13 @@ pub fn surfaceInit(surface: *apprt.Surface) !void {
493493
/// final main thread setup requirements.
494494
pub fn finalizeSurfaceInit(self: *const OpenGL, surface: *apprt.Surface) !void {
495495
_ = self;
496-
_ = surface;
497496

498497
// For GLFW, we grabbed the OpenGL context in surfaceInit and we
499498
// need to release it before we start the renderer thread.
500499
if (apprt.runtime == apprt.glfw) {
501500
glfw.makeContextCurrent(null);
501+
} else if (apprt.runtime == apprt.gtk) {} else {
502+
try surface.finalizeSurfaceInit();
502503
}
503504
}
504505

@@ -557,7 +558,7 @@ pub fn threadEnter(self: *const OpenGL, surface: *apprt.Surface) !void {
557558
_ = self;
558559

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

562563
apprt.gtk => {
563564
// GTK doesn't support threaded OpenGL operations as far as I can
@@ -595,11 +596,11 @@ pub fn threadEnter(self: *const OpenGL, surface: *apprt.Surface) !void {
595596
}
596597

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

601602
switch (apprt.runtime) {
602-
else => @compileError("unsupported app runtime for OpenGL"),
603+
else => surface.threadExit(),
603604

604605
apprt.gtk => {
605606
// We don't need to do any unloading for GTK because we may
@@ -2345,7 +2346,7 @@ pub fn drawFrame(self: *OpenGL, surface: *apprt.Surface) !void {
23452346
apprt.glfw => surface.window.swapBuffers(),
23462347
apprt.gtk => {},
23472348
apprt.embedded => {},
2348-
else => @compileError("unsupported runtime"),
2349+
else => try surface.swapBuffers(),
23492350
}
23502351
}
23512352

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)