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.

feat(glyphgrid): sample CoreText's pixels — RGBA atlas, mip chain, LOD-clamped minification

enes4f3a624249a9
diff --git a/src/renderer/glyphgrid/atlas.test.ts b/src/renderer/glyphgrid/atlas.test.ts
index 450c922c4..9f916935c 100644
--- a/src/renderer/glyphgrid/atlas.test.ts
+++ b/src/renderer/glyphgrid/atlas.test.ts
@@ -130,10 +130,10 @@ describe('GlyphAtlas', () => {
// agree with whatever the atlas decided, including conflating the pitch with the extent.
//
// It is NOT a tie to the live GLSL: the shader side below is this test's own copy, so editing
- // the real shader leaves this green. AND, DURING PHASE 1c, THE LIVE SHADER DOES NOT YET MATCH IT:
- // the gutter term is Task 3's (`uploadAtlas` has to carry GUTTER_PX and VERT has to add it to
- // `slotOrigin`). This file is the CPU-side truth T3 aligns to; until it lands, the shader samples
- // a gutter-sized offset off every glyph.
+ // the real shader leaves this green. The live VERT performs the same derivation (`uAtlasStride`
+ // for the pitch, `uAtlasGutter` for the origin offset, `uAtlasCell` for the extent) — nothing
+ // headless can prove that, which is why this test transcribes the arithmetic independently and
+ // the device round checks the pixels.
//
// Run over an integer cell AND a fractional one: an integer cell has stride === extent + 2*gutter
// on both axes, so it alone cannot tell a pitch/extent conflation from a correct derivation.
diff --git a/src/renderer/glyphgrid/atlas.ts b/src/renderer/glyphgrid/atlas.ts
index f3f29f70c..e2933ecc8 100644
--- a/src/renderer/glyphgrid/atlas.ts
+++ b/src/renderer/glyphgrid/atlas.ts
@@ -72,7 +72,8 @@ export function slotPitch(cell: number): number {
* This exists for ONE open device bug: a single letter (`ç` in round 5, lowercase `x` in round 7)
* renders BLANK while its neighbours are fine. Every headless-auditable path was audited and is
* clean — box-glyphs claims nothing below U+0300 and never returns an empty op list, the raster
- * re-paints under the clip before it inks on BOTH branches, `cellXY` is the single copy of the
+ * repaints the slot's whole PITCH rect (unclipped, before the cell clip is installed) ahead of the
+ * ink on BOTH branches, `cellXY` is the single copy of the
* layout math and the shader recomputes it identically, `strideX >= cellW + 2*GUTTER_PX` always
* (the rasterizer's cell is captured at construction and never re-adopted), and the atlas's dirty
* flag is polled by the rAF driver every frame, so no wake-up can be missed. What is left needs a
@@ -315,11 +316,10 @@ export class GlyphAtlas {
/** The uv rect of a slot: the ORIGIN is the ink origin (pitch cell + gutter), the SIZE is the
* exact cell — the three numbers are not interchangeable (see `strideX` and `GUTTER_PX`).
*
- * The shader has to derive the same rect (`uAtlasStride` for the pitch, the gutter for the
- * origin offset, `uAtlasCell` for the extent). PHASE 1c INTERIM: it does NOT yet — gl-webgl2's
- * VERT is still missing the gutter term, so every glyph samples GUTTER_PX texels off until T3
- * adds it. This rect, and the uv-tie test that transcribes it, are the CPU-side truth T3
- * aligns to. */
+ * The shader derives the same rect per vertex (`uAtlasStride` for the pitch, `uAtlasGutter` for
+ * the origin offset, `uAtlasCell` for the extent) rather than reading it from here, because it
+ * has only the slot INDEX in the cell lane. This rect and the uv-tie test that transcribes it
+ * are the CPU-side truth that derivation has to keep agreeing with. */
slotRect(slot: number): { u0: number; v0: number; u1: number; v1: number } {
// A degenerate page has no sampleable area at all: return the ZERO rect rather than let the
// division produce NaN, which the shader would turn into undefined texture reads.
diff --git a/src/renderer/glyphgrid/gl-webgl2.ts b/src/renderer/glyphgrid/gl-webgl2.ts
index 7d6189999..7b7d2e35c 100644
--- a/src/renderer/glyphgrid/gl-webgl2.ts
+++ b/src/renderer/glyphgrid/gl-webgl2.ts
@@ -1,8 +1,27 @@
+import { GUTTER_PX } from './atlas'
import { snapPanToDevicePx, type Camera } from './camera'
import { CELL_STRIDE, unpackColor } from './cells'
import type { GlyphGL, GridDrawParams } from './gl'
import { plateRectDevice } from './plate'
+/**
+ * The deepest mip level the atlas may ever be sampled at (`TEXTURE_MAX_LOD`).
+ *
+ * DERIVED FROM `GUTTER_PX`, which is why it is computed rather than typed: a level-n texel is the
+ * average of an aligned 2^n x 2^n block of level-0 texels, and two slots' inks are separated by
+ * `2 * GUTTER_PX` ink-free texels (this slot's gutter plus its neighbour's — see GUTTER_PX in
+ * atlas.ts). A level-n block can therefore only reach ink from BOTH slots once 2^n exceeds that
+ * separation, so the last safe level is `floor(log2(2 * GUTTER_PX))` = 2 for the gutter of 2 this
+ * atlas lays out. Raising the gutter raises this on its own; the two can never disagree.
+ *
+ * Levels deeper than this are still GENERATED (generateMipmap builds the whole pyramid, and
+ * building fewer levels is not something the API offers) — they are simply never sampled, which is
+ * what the clamp buys. The residual it accepts is stated in GUTTER_PX's comment: at level 2 a
+ * bilinear tap can reach a pure-gutter texel holding a blend of two BACKGROUND colours. That is a
+ * soft edge between backgrounds at heavy zoom-out, never a ghost glyph.
+ */
+const MAX_SAFE_LOD = Math.floor(Math.log2(2 * GUTTER_PX))
+
const VERT = `#version 300 es
// One instance per CELL. Two triangles from gl_VertexID (0..5), no vertex buffer.
uniform vec2 uPan; // camera pan (screen px)
@@ -13,6 +32,7 @@ uniform vec2 uCell; // cell size (world px)
uniform float uCols;
uniform vec2 uAtlasCell; // glyph uv EXTENT (u1-u0, v1-v0) — the exact device cell
uniform vec2 uAtlasStride; // glyph uv PITCH — the whole-texel slot spacing (>= uAtlasCell)
+uniform float uAtlasGutter; // GUTTER_PX / atlasSizePx — the ink-free margin inside the pitch cell
uniform float uAtlasCols;
in uvec4 aCell; // [glyph, fg, bg, flags] — CELL_STRIDE lanes
out vec2 vUv;
@@ -28,83 +48,71 @@ void main() {
vec2 ndc = vec2(screen.x / uView.x * 2.0 - 1.0, 1.0 - screen.y / uView.y * 2.0);
gl_Position = vec4(ndc, 0.0, 1.0);
float slot = float(aCell.x);
- // PHASE 1c interim: uv lacks the gutter term — T3 adds uAtlasGutter; glyphs sample 2 texels off
- // until then. The atlas already lays every slot out with GUTTER_PX of ink-free margin inside its
- // pitch cell (atlas.ts), so this origin is one gutter short on both axes; the uv-tie test in
- // atlas.test.ts transcribes the derivation T3 has to land here.
- vec2 slotOrigin = vec2(mod(slot, uAtlasCols), floor(slot / uAtlasCols)) * uAtlasStride;
+ // THREE DIFFERENT NUMBERS, and conflating any two of them shifts every glyph. The slot's PITCH
+ // cell starts at (slot % cols, slot / cols) * uAtlasStride; the INK starts one GUTTER inside that
+ // cell on each axis (the atlas lays every slot out that way so the mip chain has an ink-free
+ // margin — see GUTTER_PX in atlas.ts); the sampled EXTENT is the exact device cell, uAtlasCell,
+ // which is fractional in general and must never be replaced by the pitch. This is the same
+ // derivation GlyphAtlas.slotRect performs on the CPU, and atlas.test.ts's uv-tie test
+ // transcribes it independently of both.
+ vec2 slotOrigin = vec2(mod(slot, uAtlasCols), floor(slot / uAtlasCols)) * uAtlasStride
+ + vec2(uAtlasGutter);
vUv = slotOrigin + unit * uAtlasCell;
vCell = aCell;
}`
const FRAG = `#version 300 es
precision highp float;
+// INT PRECISION IS DECLARED, not inherited: GLSL ES 3.00 predeclares only "precision mediump int"
+// for fragment shaders, and mediump is guaranteed no more than 16 bits — which is not enough for
+// the 32-bit RGBA8 colour lane rgba8() shifts apart below. Desktop drivers all give 32 bits
+// anyway, which is why the lanes read correctly before this line existed; saying it makes the
+// blank-cell branch's colour independent of that generosity.
+precision highp int;
uniform sampler2D uAtlas;
in vec2 vUv;
flat in uvec4 vCell;
out vec4 outColor;
-// The exponent the fg/bg coverage mix is performed under (see main()). NOT 2.2: this is a TEXT-AA
-// blend gamma, not a display EOTF, and the device bracketed it — 1.0 (a plain sRGB-space mix) read
-// thin, 2.2 (the full physical decode) read thick. One named constant so the next nudge, if the
-// reference device still reads a hair off in either direction, is a one-token change.
-const float BLEND_GAMMA = 1.45;
vec4 rgba8(uint c) {
return vec4(float(c & 255u), float((c >> 8) & 255u), float((c >> 16) & 255u),
float((c >> 24) & 255u)) / 255.0;
}
void main() {
- vec4 bg = rgba8(vCell.z);
- vec4 fg = rgba8(vCell.y);
- // COVERAGE COMES OFF THE RED CHANNEL, not alpha. raster.ts paints the atlas page opaque BLACK
- // and the ink WHITE: giving the platform rasterizer a real backdrop is what gets full-weight
- // glyphs out of CoreText on macOS (text drawn onto transparency comes out thin and soft), and it
- // is exactly what xterm's own TextureAtlas does: _drawToCache fills the tile with the
- // background color before every fillText. So the page's LUMINANCE is the coverage; its alpha is
- // 1 everywhere now and carries no information.
- float glyph = texture(uAtlas, vUv).r;
- float cov = glyph * fg.a;
- // THE MIX HAPPENS IN LINEAR LIGHT, NOT IN sRGB.
- //
- // Why: xterm's WebglAddon never mixes anything. It asks CoreText to rasterize the glyph in its
- // REAL fg colour over its REAL bg, so the platform produces the anti-aliased edge pixels itself
- // (with its own gamma-aware blending — which is what makes light-on-dark text come out full),
- // and then blits those pixels 1:1. We rasterize white-on-black COVERAGE once and tint it here,
- // which keeps the atlas key space small (one slot per code point, not per fg/bg pair) but moves
- // the blend into our shader. A mix() on sRGB-encoded values is a LINEAR interpolation of a
- // NON-LINEAR quantity: at coverage 0.5 it emits 0.5, which the display shows at ~0.5^2.2 = 22%
- // of full light instead of 50%. Every mid-coverage edge pixel is under-weighted, and the sum of
- // that over a glyph's outline is exactly the "WebGL text looks thinner/softer" defect the device
- // rounds kept reporting. Decoding, mixing in linear light and re-encoding is what fixes it.
- //
- // BUT THE EXPONENT IS BLEND_GAMMA (1.45), NOT THE PHYSICAL 2.2 — and that is the whole point of
- // this paragraph. The coverage in our atlas is not an abstract geometric coverage: it is
- // CoreText's OWN rasterization of white-on-black, which already carries its font-smoothing
- // compensation for light-on-dark. Compositing that with the full 2.2 decode applies the
- // compensation TWICE, and the device duly reported the result as slightly too thick. Text
- // rasterization stacks land in the same place for the same reason — Skia and FreeType's LCD-filter
- // era blend AA coverage at a gamma around 1.4-1.5, not at the display's 2.2 — because the value
- // being blended came out of a text rasterizer, not out of a photograph.
+ // THE ATLAS IS THE PICTURE. Every non-blank slot already holds CoreText's own rasterization of
+ // this exact glyph in its exact foreground over its exact background (raster.ts fills the slot
+ // with the bg and inks the glyph in the fg; the atlas is keyed by both colours), so the whole
+ // fragment stage is one texture read and a blit — precisely what xterm's WebglAddon does.
//
- // The answer is BRACKETED by device reports, which is why this number is trustworthy rather than
- // picked: 1.0 (a plain sRGB-space mix, rounds 1-6) read THIN, 2.2 (round 7) read THICK, 1.45 sits
- // between them. If the reference device still reads a hair off, move BLEND_GAMMA alone — down
- // toward 1.0 if it looks thick, up toward 2.2 if it looks thin. Nothing else in this shader is a
- // weight knob.
+ // WHAT WAS DELETED HERE, AND WHY IT MUST NOT COME BACK. This shader used to read a white-on-black
+ // COVERAGE off the red channel and mix the cell's fg/bg lanes by it under a tuned exponent
+ // (BLEND_GAMMA). That mix had no correct setting: the coverage was CoreText's OWN light-on-dark
+ // rasterization, which already carries the platform's font-smoothing compensation, so any
+ // exponent either under- or double-applied it — seven device rounds bracketed 1.0 as too thin and
+ // 2.2 as too thick and never converged. Asking the platform for the colours we actually want
+ // removes the mix, and with it the knob: there is nothing left in this shader to tune, which is
+ // the point of the change rather than a side effect of it. The cost is the key space (one slot
+ // per (code, style, fg, bg) instead of per glyph shape), which the atlas answers with
+ // reset-on-full.
//
- // Deliberately NOT stacked on top of this: the extra directional coverage boost some GPU text
- // stacks use (cov = pow(cov, 1.0/1.2) when fg is brighter than bg). It pulls in the same
- // direction as BLEND_GAMMA, so two knobs would fight over one device signal — and the bracket
- // above shows a single exponent already spans thin-to-thick. One knob, moved on evidence.
+ // THE BLANK BRANCH KEYS ON THE GLYPH LANE, NEVER ON SAMPLED ALPHA. A cell whose glyph lane is 0
+ // has no slot of its own — space, an unrenderable code point, a not-yet-packed row — so its
+ // background lives only in the bg LANE, and this is the branch that paints it. Slot 0 is
+ // permanently transparent-black, so sampling it (or alpha-testing the sample) would leave the
+ // plate's pixels showing through and a SELECTION OVER WHITESPACE or a BLOCK CURSOR ON AN EMPTY
+ // CELL would simply not be drawn — the severe case, since a shell prompt's cursor sits on a blank
+ // cell most of the time. An alpha test would also be wrong at zoom-out for a second reason: a
+ // minified sample is a mip average, so alpha there is a filtered quantity and not a statement
+ // about which slot the cell owns. The lane is exact at every zoom.
//
- // If a gap STILL survives this, stop tuning the compositing: the remaining structural difference
- // is that xterm rasterizes in colour at all. Checklist §2.7 already routes that (colour atlas
- // keyed by (code, style, fg, bg) with ink-box cropping — a Phase 2 rework, not a shader patch).
- //
- // Alpha is NOT gamma-encoded and stays a straight lerp, bit-for-bit what the old
- // mix(bg, vec4(fg.rgb, 1.0), cov) produced in that lane — the frame's alpha feeds the
- // SRC_ALPHA/ONE_MINUS_SRC_ALPHA blend and the page composite below it.
- vec3 lin = mix(pow(bg.rgb, vec3(BLEND_GAMMA)), pow(fg.rgb, vec3(BLEND_GAMMA)), cov);
- outColor = vec4(pow(lin, vec3(1.0 / BLEND_GAMMA)), mix(bg.a, 1.0, cov));
+ // Alpha comes from the lane rather than being forced to 1: the feed packs opaque backgrounds, so
+ // real cells are unaffected, while a grid drawn before its first packed row (a zeroed GPU buffer
+ // — see createGrid) keeps alpha 0 and lets its own plate show through instead of flashing opaque
+ // black over it for a frame.
+ if (vCell.x == 0u) {
+ outColor = rgba8(vCell.z);
+ return;
+ }
+ outColor = texture(uAtlas, vUv);
}`
export function createWebgl2GL(canvas: HTMLCanvasElement): GlyphGL | null {
@@ -132,6 +140,10 @@ export function createWebgl2GL(canvas: HTMLCanvasElement): GlyphGL | null {
let atlasCols = 1
let atlasCellUv: [number, number] = [0, 0]
let atlasStrideUv: [number, number] = [0, 0]
+ /** GUTTER_PX expressed in uv — the ink-free margin the VERT adds to every slot origin. Derived
+ * from the page size the atlas uploads with, so `uploadAtlas` keeps its signature: the gutter is
+ * a layout constant both sides already share, not a new piece of per-upload data. */
+ let atlasGutterUv = 0
let view: [number, number] = [1, 1]
/** Stored at resize because the plate's scissor rect is in DEVICE pixels and needs the
* drawing buffer's height to flip Y — neither is derivable from the CSS-px viewport alone. */
@@ -162,15 +174,21 @@ export function createWebgl2GL(canvas: HTMLCanvasElement): GlyphGL | null {
* So make the answer deterministic instead of hoping both sides agree:
* - **zoom >= 1 → NEAREST.** The pan is snapped to whole device pixels (`snapPanToDevicePx`)
* and the texels are 1:1, so NEAREST is bit-exact — whichever side of the tie the driver
- * picks, it now samples the same texel MAG would have.
- * - **zoom < 1 → LINEAR.** Genuine minification: several texels really do fall into one pixel,
- * and NEAREST there aliases a zoomed-out canvas into unreadable speckle. Thumbnails stay
- * readable.
+ * picks, it now samples the same texel MAG would have. The comparison stays `>=` for exactly
+ * that reason: zoom 1 IS the tie, and it belongs on the crisp side.
+ * - **zoom < 1 → LINEAR_MIPMAP_LINEAR.** Genuine minification: several texels really do fall
+ * into one pixel. Plain LINEAR (what this used to be) averages four LEVEL-0 texels however
+ * many actually land in the pixel, which is why a zoomed-out canvas shimmered and aliased —
+ * it is an undersample, not a filter. Trilinear over the mip chain `uploadAtlas` generates is
+ * the same thing every GPU text stack does, and it is what makes zoom-out read as GPU-mode
+ * class rather than as speckle. It is safe here only because the slots carry gutters and the
+ * sampler is clamped to MAX_SAFE_LOD — without both, a minified glyph would average in its
+ * neighbour's ink.
*
* MAG stays NEAREST unconditionally — it was never the ambiguous half.
*/
const applyAtlasMinFilter = (zoom: number): void => {
- const want = zoom >= 1 ? gl.NEAREST : gl.LINEAR
+ const want = zoom >= 1 ? gl.NEAREST : gl.LINEAR_MIPMAP_LINEAR
if (want === atlasMinFilter) return
atlasMinFilter = want
gl.bindTexture(gl.TEXTURE_2D, atlasTex)
@@ -228,7 +246,29 @@ export function createWebgl2GL(canvas: HTMLCanvasElement): GlyphGL | null {
uploadAtlas(source, sizePx, cellW, cellH, strideX, strideY) {
gl.bindTexture(gl.TEXTURE_2D, atlasTex)
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source)
+ // THE MIP CHAIN, rebuilt on every upload. A minifying sampler with no chain is either an
+ // undersample (LINEAR over four level-0 texels — the old zoom-out shimmer) or an INCOMPLETE
+ // texture that samples black (any *_MIPMAP_* filter), so the chain has to exist before the
+ // filter below can ask for it, and it has to be regenerated here because texImage2D replaces
+ // level 0 only and leaves the rest stale.
+ //
+ // COST: one full pyramid over the whole page (2048² today) per atlas-dirty upload. That rate
+ // is bounded by GLYPH ALLOCATION, not by frames — the atlas dirties when a new (code, style,
+ // fg, bg) key is rasterized, which on a settled canvas is never. Fine as it stands. If it
+ // ever shows up in a profile the escalation is a dirty-RECT texSubImage2D plus a manual mip
+ // of the touched tiles; that is Phase 2 work and must not be built speculatively.
+ //
+ // The page size is mip-friendly: 2048 is a power of two, so every level is an exact halving
+ // down to 1×1. WebGL2 also allows mipmaps on NPOT textures, so a future page size is not a
+ // correctness hazard here — only a rounding one at the deepest levels, which MAX_SAFE_LOD
+ // never lets the sampler reach.
+ gl.generateMipmap(gl.TEXTURE_2D)
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
+ // The clamp the gutters pay for: levels deeper than MAX_SAFE_LOD may mix a neighbouring
+ // slot's ink into this one, so the sampler is forbidden to reach them however far the canvas
+ // is zoomed out. `texParameterf` — MAX_LOD is a float parameter, and the `i` form would
+ // silently be the wrong entry point for it.
+ gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAX_LOD, MAX_SAFE_LOD)
// MIN belongs to the camera now (see applyAtlasMinFilter), but it is asserted HERE too, and
// not only in beginFrame: GL's default min filter is NEAREST_MIPMAP_LINEAR, which makes a
// texture with no mip chain INCOMPLETE (it samples black). Filter params live on the texture
@@ -239,6 +279,9 @@ export function createWebgl2GL(canvas: HTMLCanvasElement): GlyphGL | null {
atlasCols = Math.floor(sizePx / strideX)
atlasCellUv = [cellW / sizePx, cellH / sizePx]
atlasStrideUv = [strideX / sizePx, strideY / sizePx]
+ // The gutter is a LAYOUT constant shared with the atlas, so it is derived here from the page
+ // size rather than added to this signature — one fewer number for a caller to get wrong.
+ atlasGutterUv = GUTTER_PX / sizePx
},
createGrid(id, cols, rows) {
// Re-creating under a live id is the RESIZE path: drop the old buffer first, or every
@@ -294,6 +337,7 @@ export function createWebgl2GL(canvas: HTMLCanvasElement): GlyphGL | null {
gl.uniform1f(u('uAtlasCols'), atlasCols)
gl.uniform2f(u('uAtlasCell'), atlasCellUv[0], atlasCellUv[1])
gl.uniform2f(u('uAtlasStride'), atlasStrideUv[0], atlasStrideUv[1])
+ gl.uniform1f(u('uAtlasGutter'), atlasGutterUv)
gl.uniform1i(u('uAtlas'), 0)
},
drawGrid(g: GridDrawParams) {
diff --git a/src/renderer/glyphgrid/raster.ts b/src/renderer/glyphgrid/raster.ts
index dbc20cca8..8aadfa56d 100644
--- a/src/renderer/glyphgrid/raster.ts
+++ b/src/renderer/glyphgrid/raster.ts
@@ -101,13 +101,28 @@ function baselineIn(ctx: OffscreenCanvasRenderingContext2D, font: RasterFont): n
* the backing store's format, and an alpha-less canvas would additionally let Chromium turn on
* LCD/subpixel antialiasing, whose per-channel coverage the RGBA blit would bake in per channel.
*
- * THE PAGE INVARIANT, in one line: the backdrop is per-slot bg over the FULL PITCH rect; the
- * inter-slot page ground is transparent-black and is never sampled at LOD <= MAX_SAFE_LOD.
+ * THE PAGE INVARIANT, in one line: the backdrop is per-slot bg over the FULL PITCH rect, and no
+ * slot's INK can reach another slot's texels at any level up to MAX_SAFE_LOD.
+ *
+ * Stated that way on purpose — an earlier wording claimed the inter-slot page ground is "never
+ * sampled at LOD <= MAX_SAFE_LOD", which overstates it. Unallocated pitch cells DO enter a level-2
+ * texel wherever the page is not yet full: at the allocation frontier, in the page's right/bottom
+ * remainder strip, and throughout a repack that has just called `clearPage`. What enters there is
+ * transparent page ground blended into a slot's edge texel — the same accepted-residual class as
+ * the background-vs-background blend GUTTER_PX's comment already names, and it disappears as the
+ * page fills. The promise that actually matters, and the one the LOD derivation rests on, is about
+ * INK.
+ *
* Unpacked, the four things this file must not break:
* 1. The page ground starts (and `clearPage` returns to) TRANSPARENT-black. The atlas's slot 0 —
* the pitch cell at 0,0 — is permanently blank and is what every space/unknown code point
- * samples; `GlyphAtlas` never asks for slot 0, so nothing is ever drawn there and it stays
- * transparent, which is what lets the shader leave the plate's own pixels alone.
+ * names; `GlyphAtlas` never asks for slot 0, so nothing is ever drawn there and it stays
+ * transparent. Note what that no longer buys: the shader does NOT sample slot 0 for a blank
+ * cell — it branches on the glyph LANE being 0 and paints the cell's own bg lane, which is
+ * what keeps a selection or a block cursor visible on an empty cell. Slot 0 staying blank is
+ * therefore belt-and-braces (a lane that somehow reached it draws nothing rather than a
+ * stranger's glyph) plus one real duty: it is a mip neighbour like any other slot, and ink
+ * there would bleed into slot 1's minified texels.
* 2. A slot's whole pitch rect is REPAINTED with its background before it is inked, so reusing a
* cell after a reset can never leave a previous glyph's ink or a previous background behind.
* 3. INK NEVER ENTERS THE GUTTER. Every glyph is clipped to the CELL rect — one gutter inside the
@@ -161,9 +176,13 @@ export function createCanvasRasterizer(
// origin, so the pitch cell's corner is one gutter back on each axis; its extent is the
// pitch, which is `ceil(cell) + 2*GUTTER_PX`. Both are whole texels and consecutive pitch
// cells are exactly `pitch` apart, so this fill tiles its own slot and touches no other.
- // Unclipped on purpose: the rect is already exact, and the fill is what has to reach the
- // gutter (a gutter carrying this slot's own background is what makes mip bleed invisible).
// It also repaints everything a previous tenant of this slot left behind.
+ // UNCLIPPED, and the two candidate clips fail differently: a CELL clip — the one installed
+ // below for the ink — would be actively WRONG here, since it is exactly the gutter (the
+ // part of the pitch outside the cell) that has to carry this slot's background for the mip
+ // chain to blend background into background instead of into page ground. A PITCH clip
+ // would merely be REDUNDANT: the rect is already exact and `cellXY` is the only source of
+ // the origin, so there is nothing for it to catch.
ctx.fillStyle = cssColor(bg)
ctx.fillRect(x - GUTTER_PX, y - GUTTER_PX, pitchW, pitchH)
// 2. THE INK, clipped to the CELL rect — never the pitch rect. The cell always fits inside