Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(glyphgrid): final-review fixes — drawGrid doc, atlas-order pin, harness overlay

enes0b4e2fb35608
diff --git a/src/renderer/glyphgrid/engine.test.ts b/src/renderer/glyphgrid/engine.test.ts
index 5f72456be..31cdd2a3f 100644
--- a/src/renderer/glyphgrid/engine.test.ts
+++ b/src/renderer/glyphgrid/engine.test.ts
@@ -9,8 +9,9 @@ function fakeGL(): GlyphGL & { drawn: string[] } {
return {
drawn,
resize: vi.fn(),
- // Recorded in `drawn` too: the atlas upload MUST land before any drawGrid of the same
- // frame, or the shader samples an incomplete texture (solid blocks).
+ // Recorded in `drawn` too: the atlas upload MUST land before beginFrame (which pushes the
+ // atlas uniforms), let alone before any drawGrid of the same frame — otherwise the shader
+ // samples an incomplete texture (solid blocks) with stale metrics.
uploadAtlas: vi.fn(() => {
drawn.push('ATLAS')
}),
@@ -184,7 +185,7 @@ describe('GlyphGridEngine', () => {
expect(() => e.register(spec('a', 10))).toThrow(/already registered/)
})
- it('uploads the atlas with the rasterizer metrics before any drawGrid', () => {
+ it('uploads the atlas with the rasterizer metrics before beginFrame', () => {
const gl = fakeGL()
const { atlas: a, source } = loadedAtlas(512, 7, 15)
const e = new GlyphGridEngine(gl, a)
@@ -194,6 +195,10 @@ describe('GlyphGridEngine', () => {
a.glyphFor(0x41, false, false) // dirties the atlas
expect(e.frame()).toBe(true)
expect(gl.uploadAtlas).toHaveBeenCalledWith(source, 512, 7, 15)
+ // Stronger than "before the first drawGrid": beginFrame pushes uAtlasCols/uAtlasCell from
+ // the values uploadAtlas stored, so an upload landing after it would leave frame 1 sampling
+ // slot 0 everywhere and the uniforms permanently one upload stale.
+ expect(gl.drawn.indexOf('ATLAS')).toBeLessThan(gl.drawn.indexOf('BEGIN'))
expect(gl.drawn.indexOf('ATLAS')).toBeLessThan(gl.drawn.indexOf('grid@0,0'))
expect(a.dirty).toBe(false)
})
diff --git a/src/renderer/glyphgrid/engine.ts b/src/renderer/glyphgrid/engine.ts
index 5bdb89de7..ddd244283 100644
--- a/src/renderer/glyphgrid/engine.ts
+++ b/src/renderer/glyphgrid/engine.ts
@@ -52,9 +52,12 @@ interface Grid extends GridSpec {
* - **Idle frames cost nothing.** `frame()` draws only when something actually changed and
* reports whether it drew, so the rAF driver (and the tests) can prove an untouched canvas
* issues zero GL calls.
- * - **The atlas is uploaded before the first `drawGrid` of a frame.** A draw that samples a
- * texture the glyphs have not been uploaded into paints solid blocks; the engine is the only
- * place that sees both, so it is the enforcer.
+ * - **The atlas is uploaded before `beginFrame`** — not merely before the first `drawGrid`.
+ * `beginFrame` pushes the uAtlasCols/uAtlasCell uniforms from the values `uploadAtlas`
+ * stored, so an upload squeezed between `beginFrame` and `drawGrid` would leave frame 1
+ * sampling slot 0 everywhere and the uniforms permanently one upload stale. A draw that
+ * samples a texture the glyphs have not been uploaded into paints solid blocks; the engine
+ * is the only place that sees both, so it is the enforcer.
*/
export class GlyphGridEngine {
private grids = new Map<string, Grid>()
@@ -168,7 +171,8 @@ export class GlyphGridEngine {
if (!this.dirty && !uploadAtlas) return false
this.dirty = false
if (uploadAtlas && this.atlas.source) {
- // BEFORE any drawGrid, always: see the class contract.
+ // BEFORE beginFrame, always (it reads back the atlas metrics as uniforms): see the
+ // class contract.
this.gl.uploadAtlas(this.atlas.source, this.atlas.sizePx, this.atlas.cellW, this.atlas.cellH)
this.atlas.clearDirty()
this.atlasUploaded = true
diff --git a/src/renderer/glyphgrid/gl.ts b/src/renderer/glyphgrid/gl.ts
index 52bd7d5ab..a414fd8ba 100644
--- a/src/renderer/glyphgrid/gl.ts
+++ b/src/renderer/glyphgrid/gl.ts
@@ -31,7 +31,8 @@ export interface GlyphGL {
uploadAtlas(source: TexImageSource, sizePx: number, cellW: number, cellH: number): void
/** Clears the frame and sets the camera uniforms. */
beginFrame(camera: Camera): void
- /** Draws the background quad then the instanced cells, in call order. */
+ /** Draws the instanced cells in call order. Phase 0 paints each cell's own bg lane; the
+ * separate bgColor plate lands in Phase 1 — see gl-webgl2.ts drawGrid. */
drawGrid(g: GridDraw): void
endFrame(): void
dispose(): void
diff --git a/src/renderer/glyphgrid/harness/GlyphGridHarness.tsx b/src/renderer/glyphgrid/harness/GlyphGridHarness.tsx
index b37fe7641..e535592a7 100644
--- a/src/renderer/glyphgrid/harness/GlyphGridHarness.tsx
+++ b/src/renderer/glyphgrid/harness/GlyphGridHarness.tsx
@@ -203,7 +203,17 @@ export function GlyphGridHarness() {
ref={canvasRef}
style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}
/>
- <div style={{ position: 'absolute', top: 8, left: 8, color: '#8f8', font: '12px monospace' }}>
+ <div
+ style={{
+ position: 'absolute',
+ top: 8,
+ left: 8,
+ color: '#8f8',
+ font: '12px monospace',
+ // Overlay is read-only: never swallow a mousedown/wheel meant for the canvas below.
+ pointerEvents: 'none'
+ }}
+ >
{stats}
</div>
</div>