renderer: make overlay features configurable

This commit is contained in:
Mitchell Hashimoto
2026-01-30 15:24:46 -08:00
parent fa06849dcc
commit daed17c58a
2 changed files with 55 additions and 3 deletions

View File

@@ -1,3 +1,15 @@
/// The debug overlay that can be drawn on top of the terminal
/// during the rendering process.
///
/// This is implemented by doing all the drawing on the CPU via z2d,
/// since the debug overlay isn't that common, z2d is pretty fast, and
/// it simplifies our implementation quite a bit by not relying on us
/// having a bunch of shaders that we have to write per-platform.
///
/// Initialize the overlay, apply features with `applyFeatures`, then
/// get the resulting image with `pendingImage` to upload to the GPU.
/// This works in concert with `renderer.image.State` to simplify. Draw
/// it on the GPU as an image composited on top of the terminal output.
const Overlay = @This();
const std = @import("std");
@@ -15,6 +27,11 @@ surface: z2d.Surface,
/// Cell size information so we can map grid coordinates to pixels.
cell_size: CellSize,
/// The set of available features and their configuration.
pub const Feature = union(enum) {
highlight_hyperlinks,
};
pub const InitError = Allocator.Error || error{
// The terminal dimensions are invalid to support an overlay.
// Either too small or too big.
@@ -60,12 +77,28 @@ pub fn pendingImage(self: *const Overlay) Image.Pending {
};
}
/// Apply the given features to this overlay. This will draw on top of
/// any pre-existing content in the overlay.
pub fn applyFeatures(
self: *Overlay,
alloc: Allocator,
state: *const terminal.RenderState,
features: []const Feature,
) void {
for (features) |f| switch (f) {
.highlight_hyperlinks => self.highlightHyperlinks(
alloc,
state,
),
};
}
/// Add rectangles around contiguous hyperlinks in the render state.
///
/// Note: this currently doesn't take into account unique hyperlink IDs
/// because the render state doesn't contain this. This will be added
/// later.
pub fn highlightHyperlinks(
fn highlightHyperlinks(
self: *Overlay,
alloc: Allocator,
state: *const terminal.RenderState,

View File

@@ -2207,9 +2207,28 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
}
}
fn rebuildOverlay(self: *Self, alloc: Allocator) Overlay.InitError!Overlay {
/// Build the overlay as configured. Returns null if there is no
/// overlay currently configured.
fn rebuildOverlay(
self: *Self,
alloc: Allocator,
) Overlay.InitError!?Overlay {
// Right now, the debug overlay is turned on and configured by
// modifying these and recompiling. In the future, we will expose
// all of this at runtime via the inspector.
const features: []const Overlay.Feature = &.{
//.highlight_hyperlinks,
};
// If we have no features enabled, don't build an overlay.
if (features.len == 0) return null;
var overlay: Overlay = try .init(alloc, self.size);
overlay.highlightHyperlinks(alloc, &self.terminal_state);
overlay.applyFeatures(
alloc,
&self.terminal_state,
features,
);
return overlay;
}