renderer/opengl: switch to new update vs draw

This commit is contained in:
Mitchell Hashimoto
2023-11-14 14:17:30 -08:00
parent 0e92f68228
commit 389712a698
4 changed files with 16 additions and 18 deletions

View File

@ -252,7 +252,7 @@ pub fn deinit(self: *Surface) void {
} }
fn render(self: *Surface) !void { fn render(self: *Surface) !void {
try self.core_surface.renderer.draw(); try self.core_surface.renderer.drawFrame(self);
} }
/// Queue the inspector to render if we have one. /// Queue the inspector to render if we have one.

View File

@ -574,7 +574,9 @@ pub fn updateFrame(
} }
/// Draw the frame to the screen. /// Draw the frame to the screen.
pub fn drawFrame(self: *Metal) !void { pub fn drawFrame(self: *Metal, surface: *apprt.Surface) !void {
_ = surface;
// @autoreleasepool {} // @autoreleasepool {}
const pool = objc.AutoreleasePool.init(); const pool = objc.AutoreleasePool.init();
defer pool.deinit(); defer pool.deinit();

View File

@ -576,12 +576,14 @@ fn resetFontMetrics(
} }
/// The primary render callback that is completely thread-safe. /// The primary render callback that is completely thread-safe.
pub fn render( pub fn updateFrame(
self: *OpenGL, self: *OpenGL,
surface: *apprt.Surface, surface: *apprt.Surface,
state: *renderer.State, state: *renderer.State,
cursor_blink_visible: bool, cursor_blink_visible: bool,
) !void { ) !void {
_ = surface;
// Data we extract out of the critical area. // Data we extract out of the critical area.
const Critical = struct { const Critical = struct {
gl_bg: terminal.color.RGB, gl_bg: terminal.color.RGB,
@ -669,19 +671,6 @@ pub fn render(
critical.cursor_style, critical.cursor_style,
); );
} }
// We're out of the critical path now. Let's render. We only render if
// we're not single threaded. If we're single threaded we expect the
// runtime to call draw.
if (single_threaded_draw) return;
try self.draw();
// Swap our window buffers
switch (apprt.runtime) {
else => @compileError("unsupported runtime"),
apprt.glfw => surface.window.swapBuffers(),
}
} }
/// rebuildCells rebuilds all the GPU cells from our CPU state. This is a /// rebuildCells rebuilds all the GPU cells from our CPU state. This is a
@ -1448,7 +1437,7 @@ fn flushAtlas(self: *OpenGL) !void {
/// Render renders the current cell state. This will not modify any of /// Render renders the current cell state. This will not modify any of
/// the cells. /// the cells.
pub fn draw(self: *OpenGL) !void { pub fn drawFrame(self: *OpenGL, surface: *apprt.Surface) !void {
const t = trace(@src()); const t = trace(@src());
defer t.end(); defer t.end();
@ -1507,6 +1496,13 @@ pub fn draw(self: *OpenGL) !void {
try self.drawCells(binding, self.cells_bg); try self.drawCells(binding, self.cells_bg);
try self.drawCells(binding, self.cells); try self.drawCells(binding, self.cells);
// Swap our window buffers
switch (apprt.runtime) {
apprt.glfw => surface.window.swapBuffers(),
apprt.gtk => {},
else => @compileError("unsupported runtime"),
}
} }
/// Loads some set of cell data into our buffer and issues a draw call. /// Loads some set of cell data into our buffer and issues a draw call.

View File

@ -364,7 +364,7 @@ fn renderCallback(
} }
// Draw // Draw
t.renderer.drawFrame() catch |err| t.renderer.drawFrame(t.surface) catch |err|
log.warn("error drawing err={}", .{err}); log.warn("error drawing err={}", .{err});
return .disarm; return .disarm;