@babylonjs/lite-gl 1.19.0 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +31 -0
  2. package/index.d.ts +13 -0
  3. package/index.js +7 -0
  4. package/index.js.map +1 -1
  5. package/package.json +6 -3
  6. package/text/_gpu/text-effect.d.ts +1 -0
  7. package/text/_gpu/text-effect.js +70 -0
  8. package/text/_gpu/text-effect.js.map +1 -0
  9. package/text/_gpu/text-instances.d.ts +1 -0
  10. package/text/_gpu/text-instances.js +57 -0
  11. package/text/_gpu/text-instances.js.map +1 -0
  12. package/text/_gpu/text-textures.d.ts +1 -0
  13. package/text/_gpu/text-textures.js +82 -0
  14. package/text/_gpu/text-textures.js.map +1 -0
  15. package/text/_gpu/text-vao.d.ts +1 -0
  16. package/text/_gpu/text-vao.js +49 -0
  17. package/text/_gpu/text-vao.js.map +1 -0
  18. package/text/default-text-data.d.ts +28 -0
  19. package/text/default-text-data.js +103 -0
  20. package/text/default-text-data.js.map +1 -0
  21. package/text/font.d.ts +16 -0
  22. package/text/font.js +24 -0
  23. package/text/font.js.map +1 -0
  24. package/text/glyph-extraction.d.ts +19 -0
  25. package/text/glyph-extraction.js +115 -0
  26. package/text/glyph-extraction.js.map +1 -0
  27. package/text/glyph-storage.d.ts +68 -0
  28. package/text/glyph-storage.js +298 -0
  29. package/text/glyph-storage.js.map +1 -0
  30. package/text/layout.d.ts +18 -0
  31. package/text/layout.js +219 -0
  32. package/text/layout.js.map +1 -0
  33. package/text/set-font-weight-offset.d.ts +5 -0
  34. package/text/set-font-weight-offset.js +67 -0
  35. package/text/set-font-weight-offset.js.map +1 -0
  36. package/text/shaders/slug-shader.d.ts +1 -0
  37. package/text/shaders/slug-shader.js +181 -0
  38. package/text/shaders/slug-shader.js.map +1 -0
  39. package/text/shaders/text-shader-fragment.d.ts +1 -0
  40. package/text/shaders/text-shader-fragment.js +2 -0
  41. package/text/shaders/text-shader-fragment.js.map +1 -0
  42. package/text/shaders/weight-shader-fragment.d.ts +1 -0
  43. package/text/shaders/weight-shader-fragment.js +75 -0
  44. package/text/shaders/weight-shader-fragment.js.map +1 -0
  45. package/text/text-data.d.ts +109 -0
  46. package/text/text-data.js +723 -0
  47. package/text/text-data.js.map +1 -0
  48. package/text/text-renderer.d.ts +68 -0
  49. package/text/text-renderer.js +238 -0
  50. package/text/text-renderer.js.map +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-data.js","sourceRoot":"","sources":["../../src/text/text-data.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAMH,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAiL/C;;;;yDAIyD;AACzD,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AACtC,MAAM,CAAC,MAAM,mBAAmB,GAAG,oBAAoB,GAAG,CAAC,CAAC;AAE5D;;;;uBAIuB;AACvB,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC;AACnC,MAAM,CAAC,MAAM,gBAAgB,GAAG,iBAAiB,GAAG,CAAC,CAAC;AAEtD;+FAC+F;AAC/F,MAAM,UAAU,GAAG,UAAU,CAAC;AAE9B;uCACuC;AACvC,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAChC,MAAM,iBAAiB,GAAG,gBAAgB,GAAG,CAAC,CAAC;AAE/C,MAAM,WAAW,GAA8C,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAuB5E,gBAAgB;AAChB,MAAM,CAAC,IAAI,cAAc,GAAyB,IAAI,CAAC;AAEvD,4EAA4E;AAC5E,MAAM,UAAU,qBAAqB,CAAC,IAAmB;IACrD,cAAc,GAAG,IAAI,CAAC;AAC1B,CAAC;AAED,yFAAyF;AACzF,SAAS,WAAW,CAAC,GAAe;IAChC,OAAO,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AAE,MAAM,CAAC,GAAG,CAAC,CAAC;YACjC,OAAO;QACX,KAAK,YAAY;YACb,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;YACnD,OAAO;IACf,CAAC;AACL,CAAC;AAED;;gEAEgE;AAChE,MAAM,UAAU,eAAe,CAAC,IAAgB;IAC5C,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC;IACtB,IAAI,GAAG,EAAE,CAAC;QACN,aAAa,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC;QAC7C,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC;QAC3C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;IACD,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;IAClB,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC;IACxB,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;IACrB,IAAI,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC;IAChC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IACtB,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;AAC7B,CAAC","sourcesContent":["/** GLTextData — slot-allocator-backed per-instance vertex buffer for a text block.\n *\n * Each draw group owns a contiguous slot range `[slotStart, slotStart + slotCount)`\n * in the shared instance buffer. Live and dead slots intermix within that range;\n * dead slots carry an all-ones packed word that the vertex shader detects and turns\n * into a degenerate off-screen triangle. `addRun` / `replaceRun` reuse\n * from the group's `freeSlots` LIFO when possible; otherwise they extend the\n * group's range (shifting later *groups* — never other runs in the same group).\n * `removeRun` writes the sentinel into its slots and returns them to the free-list.\n *\n * Each GLTextData is bound to one `GLGlyphStorage` for its glyph catalog. The storage is\n * borrowed — caller owns its lifetime. `disposeTextData` releases the per-block\n * instance buffer + style texture only.\n *\n * Cost per edit: O(touched glyphs) in the common single-font case, with an extra\n * O(later-group slot count) shift only when the touched group must grow.\n */\n\nimport type { GLCurveSetId, GLGlyphStorage, GlyphStorageCurveSet } from \"./glyph-storage.js\";\n\nimport type { GLEngineContext } from \"../context.js\";\nimport type { GLVertexBuffer } from \"../mesh.js\";\nimport { disposeBuffer } from \"../mesh.js\";\nimport type { GLTexture } from \"../texture.js\";\nimport { disposeTexture } from \"../texture.js\";\n\n/** @internal GPU resources shared by layers drawing this data on one engine. */\nexport interface TextDataGpu {\n /** @internal */\n _engine: GLEngineContext;\n /** @internal */\n _instanceBuf: GLVertexBuffer;\n /** @internal */\n _styleTex: GLTexture;\n /** @internal */\n _stylePixels: Float32Array;\n /** @internal */\n _uploadedVersion: number;\n /** @internal */\n _uploadedStyleVersion: number;\n}\n\ndeclare const textDataBrand: unique symbol;\n\n// ─── Public value types ───────────────────────────────────────────────────\n\n/** Positioned glyph instance in pixel space, usually produced by layout before being packed into a `GLGlyphRun`. */\nexport type GLPlacedGlyph = {\n readonly glyphId: number;\n /** Pixel position of glyph baseline origin. */\n readonly x: number;\n readonly y: number;\n /** Optional per-glyph color as linear RGBA in [0,1]. When present this overrides the\n * run's `defaultColor` for this glyph. When omitted, the glyph falls back to the run's\n * `defaultColor`, and if that is also omitted, to opaque white. The rendered alpha is\n * additionally scaled by the whole-block opacity (e.g. `TextRenderable.opacity`). */\n readonly color?: readonly [number, number, number, number];\n};\n\n/** Batch of placed glyphs that all use the same curve set and font-unit-to-pixel scale. */\nexport type GLGlyphRun = {\n /** Which curve set this run's glyph ids index into. */\n readonly curveSet: GLCurveSetId;\n readonly glyphs: readonly GLPlacedGlyph[];\n /** GLFont-units → pixels scale used by the layout. */\n readonly pixelsPerFontUnit: number;\n /** Optional default color for every glyph in this run, as linear RGBA in [0,1]. A glyph's\n * own `GLPlacedGlyph.color` takes precedence over this. When omitted, glyphs default to\n * opaque white. The rendered alpha is additionally scaled by the whole-block opacity. */\n readonly defaultColor?: readonly [number, number, number, number];\n};\n\n/** Discriminated union driving `updateTextData`. Each variant's `update` field is the\n * discriminator. Arrays/maps passed inside any variant are *adopted* by the `GLTextData`\n * and must not be read or mutated by the caller afterward. */\nexport type GLTextDataUpdate =\n | {\n /** Rebuild runs and/or swap to a different storage. Both `runs` and `storage`\n * are optional; missing fields default to the GLTextData's current value, so\n * `{ update: \"reset\" }` with neither performs a pure compaction pass that\n * re-lays-out the slot allocator without dead slots or gaps.\n * Invalidates any previously-passed `GLGlyphRun` references when `runs` is set. */\n update: \"reset\";\n runs?: GLGlyphRun[];\n storage?: GLGlyphStorage;\n }\n | {\n /** Append a new run to the live runs list, or insert it before the run currently at\n * `insertBefore`. The run's `curveSet` must already exist in the bound storage. */\n update: \"addRun\";\n run: GLGlyphRun;\n /** Index in `data.runs` to insert before. Default = append at end. */\n insertBefore?: number;\n }\n | {\n /** Remove a previously-added run. Accepts either the `GLGlyphRun` reference or its\n * current index in `data.runs`. */\n update: \"removeRun\";\n run: GLGlyphRun | number;\n }\n | {\n /** Replace one run's contents in place. The new run takes the slot in `data.runs`\n * that the previous run occupied. Cheapest when the new run has the same glyph\n * count and the same `curveSet` as the previous one. */\n update: \"replaceRun\";\n previous: GLGlyphRun | number;\n run: GLGlyphRun;\n };\n\n// ─── Branded public type + internal supporting types ──────────────────────\n\n/** Mutable text block data containing glyph runs and the packed per-glyph instance buffer consumed by text renderers. */\nexport interface GLTextData {\n readonly [textDataBrand]: true;\n /** @internal Lazily created, engine-owned GPU companion. */\n _gpu: TextDataGpu | null;\n /** Live, in-insertion-order view of the runs currently rendered. Mutated by\n * `updateTextData`. Do not mutate from outside. */\n readonly runs: readonly GLGlyphRun[];\n /** @internal Mutable alias of {@link runs} (same array reference). */\n _runs: GLGlyphRun[];\n /** @internal Draw groups. Length = number of unique draw-group keys referenced (one per\n * curve set unless a styling feature splits one further). */\n _groups: TextDataDrawGroup[];\n /** @internal Per-run bookkeeping records, keyed by `GLGlyphRun` reference. */\n _runRecords: Map<GLGlyphRun, RunRecord>;\n /** @internal Pooled per-instance float buffer (TEXT_INSTANCE_FLOATS per instance). */\n _instances: Float32Array;\n /** @internal Uint32 alias of {@link _instances} (same buffer), used for the packed glyph\n * index. Always reassigned together with `_instances`. */\n _instancesU32: Uint32Array;\n /** @internal Total *capacity* used (live + dead slots across all groups). */\n _instanceCount: number;\n /** @internal Style palette: `TEXT_STYLE_FLOATS` per entry, indexed by the high 16 bits of\n * an instance's packed word. */\n _styles: Float32Array;\n /** @internal High-water mark for allocated style entries. */\n _styleCount: number;\n /** @internal Reusable individual style indices. */\n _freeStyleSlots: number[];\n /** @internal Monotonic version bumped whenever `_styles` content changes, so renderers can\n * skip the palette upload entirely when nothing moved. */\n _styleVersion: number;\n /** @internal GLGlyphStorage backing this GLTextData. Borrowed reference — caller owns it. */\n _storage: GLGlyphStorage;\n /** @internal Monotonic version bumped whenever instance data changes. */\n _version: number;\n /** @internal Monotonic version bumped only when the draw structure changes, i.e. when a\n * group's slot range (`slotStart`/`slotCount`) moves. Content-only edits (same-length\n * replace, add-into-free-slot, partial remove) leave this stable so cached vertex arrays\n * stay valid. */\n _layoutVersion: number;\n /** @internal Inclusive-exclusive dirty range of instances awaiting upload. */\n _dirtyStart: number;\n /** @internal */ _dirtyEnd: number;\n}\n\n/** @internal Draw group within a GLTextData. One group per unique draw-group key — i.e. one per\n * unique font used by the live runs, unless an opt-in styling feature splits a curve set\n * further. Groups own a contiguous *slot range* in the shared instance buffer; live and dead\n * slots intermix within that range. The vertex shader emits a degenerate quad for dead slots\n * so they cost only a vertex-shader invocation. */\nexport type TextDataDrawGroup = {\n /** @internal Curve-set id (matches the key inside the parent storage's `_curveSets` map). */\n _curveSetId: GLCurveSetId;\n /** @internal Cached pointer to the curve-set entry within the parent GLTextData's `_storage`.\n * Refreshed whenever `_storage` swaps in `applyReset`; identity-compared to invalidate\n * the cached `_bindGroup`. */\n _curveSet: GlyphStorageCurveSet;\n /** @internal First slot index (in instances, not bytes) owned by this group. */\n _slotStart: number;\n /** @internal Number of slots reserved by this group (live + dead). The draw call covers\n * `[_slotStart, _slotStart + _slotCount)`. */\n _slotCount: number;\n /** @internal Number of *live* (non-dead) instances in this group. Tracked for stats. */\n _liveCount: number;\n /** @internal Indices (absolute, within `GLTextData._instances`) of dead slots inside this group's\n * range, available for reuse by `addRun`/`replaceRun`. LIFO order keeps recent frees\n * reusable first (locality). */\n _freeSlots: number[];\n /** @internal Draw-group identity. Equals `_curveSetId` unless an opt-in styling feature\n * interned a different key for these runs, in which case the group needs the composed\n * variant pipeline — `_groupKey !== _curveSetId` is exactly that test. */\n _groupKey: TextGroupKey;\n};\n\n/** @internal Per-run bookkeeping. Lets us locate a run's instances inside its draw group's\n * slot range in O(1) for add/remove/replace ops. Slots are not guaranteed to be contiguous\n * (the allocator may have reused freed slots from anywhere in the group's range). */\nexport type RunRecord = {\n /** @internal */\n _run: GLGlyphRun;\n /** @internal Index of the owning draw group in `GLTextData._groups`. */\n _groupIdx: number;\n /** @internal Absolute slot indices (within `GLTextData._instances`) currently occupied by this run.\n * Length === number of glyphs actually written (skipped glyphs do not occupy slots). */\n _slots: number[];\n /** @internal Style indices owned by this run: default first, then color overrides in glyph order. */\n _styleSlots: number[];\n};\n\n/** Floats per instance: the anchor (x, y) plus one packed u32 holding the glyph index in its\n * low 16 bits and the style index in its high 16. Everything else the shader needs is either\n * glyph-invariant — the atlas's `GlyphMetadata` table, indexed by the glyph half — or shared\n * by every glyph drawn at the same color and scale — this GLTextData's style palette, indexed\n * by the style half. Neither is copied per instance. */\nexport const TEXT_INSTANCE_FLOATS = 3;\nexport const TEXT_INSTANCE_BYTES = TEXT_INSTANCE_FLOATS * 4;\n\n/** Floats per style-palette entry, matching the WGSL `TextStyle` struct: a `vec4<f32>` color\n * followed by a `vec4<f32>` of params whose `.x` carries the run's `invScale` and whose `.y`\n * carries the optional per-run style parameter (see {@link TextStyleSeam}; 0 when no styling\n * feature is installed). The rest is reserved padding that keeps the struct naturally\n * 16-byte aligned. */\nexport const TEXT_STYLE_FLOATS = 8;\nexport const TEXT_STYLE_BYTES = TEXT_STYLE_FLOATS * 4;\n\n/** Value of the packed word marking a slot as dead (skipped by the vertex shader). Both halves\n * are all-ones, which `MAX_PACKED_INDEX` keeps unreachable for a real (glyph, style) pair. */\nconst DEAD_GLYPH = 0xffffffff;\n\n/** Largest glyph or style index representable in a packed half. `0xffff` is reserved so the\n * dead sentinel stays unambiguous. */\nconst MAX_PACKED_INDEX = 0xfffe;\nconst MAX_STYLE_ENTRIES = MAX_PACKED_INDEX + 1;\n\nconst WHITE_COLOR: readonly [number, number, number, number] = [1, 1, 1, 1];\n\n// ─── Optional per-run styling seam ─────────────────────────────────────────\n// Installed by an opt-in styling feature (currently `set-font-weight-offset.ts`) from\n// inside its setter; null otherwise. This module attaches no meaning to either result:\n// `_param` is a float copied verbatim into `TextStyle.params.y`, `_key` is a token\n// compared only with `===`. All feature semantics live in the installing module.\n\n/** @internal Opaque draw-group identity, compared by `===` only. The default is the run's\n * own {@link GLCurveSetId}; a styling feature may substitute an interned non-string token,\n * which by construction can never equal a curve-set id — so no composite/delimited key can\n * make one curve set's group alias another's. */\nexport type TextGroupKey = GLCurveSetId | object;\n\n/** @internal Per-run styling hooks supplied by an opt-in feature. */\nexport interface TextStyleSeam {\n /** @internal Draw-group key for a run — must be `run.curveSet` unless the run needs a\n * different pipeline variant, and must never equal another curve set's key. */\n _key(run: GLGlyphRun): TextGroupKey;\n /** @internal Extra style float, packed verbatim into `TextStyle.params.y`. */\n _param(run: GLGlyphRun): number;\n}\n\n/** @internal */\nexport let _textStyleSeam: TextStyleSeam | null = null;\n\n/** @internal Install the styling seam. Called once by the opt-in setter. */\nexport function _installTextStyleSeam(seam: TextStyleSeam): void {\n _textStyleSeam = seam;\n}\n\n/** Draw-group key for a run: its curve set unless a styling feature interned another. */\nfunction runGroupKey(run: GLGlyphRun): TextGroupKey {\n return _textStyleSeam?._key(run) ?? run.curveSet;\n}\n\n// ─── Per-slot packing ──────────────────────────────────────────────────────\n\nfunction packGlyphAtSlot(out: Float32Array, outU32: Uint32Array, slot: number, curveSet: GlyphStorageCurveSet, glyphId: number, x: number, y: number, styleIdx: number): boolean {\n // An atlas slot exists only for glyphs that are also in `curveSet._curves` (both maps are\n // written together and never pruned), so this single lookup doubles as the validity check.\n // It yields an index into the atlas's glyph-metadata table; everything glyph-invariant\n // lives there and is never copied into the instance.\n const atlasSlot = curveSet._atlas._glyphSlots.get(glyphId);\n if (!atlasSlot) {\n return false;\n }\n const glyphIdx = atlasSlot._index;\n // Both indices share one u32, so an out-of-range value would silently alias a different\n // glyph or style — or the dead sentinel. Drop the glyph instead; the caller already treats\n // a false return as an atlas miss and retires the slot.\n if (glyphIdx > MAX_PACKED_INDEX || styleIdx > MAX_PACKED_INDEX) {\n return false;\n }\n const w = slot * TEXT_INSTANCE_FLOATS;\n out[w] = x;\n out[w + 1] = y;\n outU32[w + 2] = glyphIdx | (styleIdx << 16);\n return true;\n}\n\nfunction markSlotDead(out: Float32Array, outU32: Uint32Array, slot: number): void {\n const base = slot * TEXT_INSTANCE_FLOATS;\n out[base] = 0;\n out[base + 1] = 0;\n outU32[base + 2] = DEAD_GLYPH;\n}\n\n// ─── Style palette ─────────────────────────────────────────────────────────\n\nfunction ensureStyleCapacity(data: GLTextData, requiredEntries: number): void {\n if (requiredEntries > MAX_STYLE_ENTRIES) {\n throw new Error(`GLTextData style palette cannot exceed ${MAX_STYLE_ENTRIES} entries.`);\n }\n const requiredFloats = requiredEntries * TEXT_STYLE_FLOATS;\n if (data._styles.length >= requiredFloats) {\n return;\n }\n let newLen = Math.max(data._styles.length * 2, TEXT_STYLE_FLOATS);\n while (newLen < requiredFloats) {\n newLen *= 2;\n }\n newLen = Math.min(newLen, MAX_STYLE_ENTRIES * TEXT_STYLE_FLOATS);\n const grown = new Float32Array(newLen);\n grown.set(data._styles);\n data._styles = grown;\n}\n\n/** Palette entries a run needs: one shared default plus one per glyph carrying its own `color`.\n * Overrides are deliberately not deduplicated — a dedicated entry per override glyph lets the\n * write loop hand them out in glyph order instead of searching the palette, and even the\n * pathological all-override case costs less per glyph (12 B instance + 32 B entry) than the\n * 80 B instances this format replaced. */\nfunction countRunStyles(run: GLGlyphRun): number {\n const glyphs = run.glyphs;\n let n = 1;\n for (let i = 0; i < glyphs.length; i++) {\n if (glyphs[i]!.color !== undefined) {\n n++;\n }\n }\n return n;\n}\n\nfunction releaseStyles(data: GLTextData, slots: number[]): void {\n for (let i = 0; i < slots.length; i++) {\n data._freeStyleSlots.push(slots[i]!);\n }\n}\n\nfunction allocateStyles(data: GLTextData, count: number, previous?: number[]): number[] {\n if (previous?.length === count) {\n return previous;\n }\n const free = data._freeStyleSlots;\n const needed = Math.max(0, count - free.length - (previous?.length ?? 0));\n ensureStyleCapacity(data, data._styleCount + needed);\n if (previous) {\n releaseStyles(data, previous);\n }\n const highWater = data._styleCount;\n const slots = new Array<number>(count);\n for (let i = 0; i < count; i++) {\n slots[i] = free.pop() ?? data._styleCount++;\n }\n // Growing past the high-water mark lengthens the upload, and `ensureStyleGpu` only uploads\n // when the version moved — so the bump cannot be left to `writeStyle`, which stays silent for\n // an entry whose contents already match (an all-zero style writes nothing). Slots taken from\n // the free list keep the upload length unchanged, so there `writeStyle` alone is enough.\n if (data._styleCount !== highWater) {\n data._styleVersion++;\n }\n return slots;\n}\n\n/** Write one palette entry, bumping `_styleVersion` only when the entry's contents actually\n * change. Comparing against the `Math.fround` of each value rather than the value itself is\n * what makes that check meaningful: the palette stores float32, so a double like `1 / 13.3`\n * never compares equal to its own stored form and every frame would look like a change. */\nfunction writeStyle(data: GLTextData, entry: number, color: readonly [number, number, number, number], invScale: number, styleParam: number): void {\n const w = entry * TEXT_STYLE_FLOATS;\n const s = data._styles;\n const r = Math.fround(color[0]);\n const g = Math.fround(color[1]);\n const b = Math.fround(color[2]);\n const a = Math.fround(color[3]);\n const iv = Math.fround(invScale);\n const sp = Math.fround(styleParam);\n if (s[w] === r && s[w + 1] === g && s[w + 2] === b && s[w + 3] === a && s[w + 4] === iv && s[w + 5] === sp) {\n return;\n }\n s[w] = r;\n s[w + 1] = g;\n s[w + 2] = b;\n s[w + 3] = a;\n s[w + 4] = iv;\n s[w + 5] = sp;\n data._styleVersion++;\n}\n\n// ─── Buffer + dirty-range helpers ──────────────────────────────────────────\n\nfunction ensureInstanceCapacity(data: GLTextData, requiredInstances: number): void {\n const requiredFloats = requiredInstances * TEXT_INSTANCE_FLOATS;\n if (data._instances.length >= requiredFloats) {\n return;\n }\n let newLen = Math.max(data._instances.length * 2, TEXT_INSTANCE_FLOATS);\n while (newLen < requiredFloats) {\n newLen *= 2;\n }\n const grown = new Float32Array(newLen);\n grown.set(data._instances.subarray(0, data._instanceCount * TEXT_INSTANCE_FLOATS));\n data._instances = grown;\n data._instancesU32 = new Uint32Array(grown.buffer);\n data._dirtyStart = 0;\n data._dirtyEnd = data._instanceCount;\n}\n\nfunction markDirty(data: GLTextData, startInstance: number, endInstance: number): void {\n if (endInstance <= startInstance) {\n return;\n }\n if (data._dirtyStart === data._dirtyEnd) {\n data._dirtyStart = startInstance;\n data._dirtyEnd = endInstance;\n } else {\n if (startInstance < data._dirtyStart) {\n data._dirtyStart = startInstance;\n }\n if (endInstance > data._dirtyEnd) {\n data._dirtyEnd = endInstance;\n }\n }\n data._version++;\n}\n\n// ─── Slot allocator ────────────────────────────────────────────────────────\n\n/** Pop a slot from `group._freeSlots`, or -1 if none. */\nfunction popFreeSlot(group: TextDataDrawGroup): number {\n return group._freeSlots.length > 0 ? group._freeSlots.pop()! : -1;\n}\n\n/** Shift every group `slotStart` / freeSlot / run-record slot at or after `threshold` by\n * `delta` (positive to open a gap, negative to close one). `exclude` — a group being grown\n * in place — is skipped so its own range isn't shifted; run-record slots are always shifted. */\nfunction shiftSlotsAtOrAfter(data: GLTextData, threshold: number, delta: number, exclude?: TextDataDrawGroup): void {\n for (const g of data._groups) {\n if (g !== exclude && g._slotStart >= threshold) {\n g._slotStart += delta;\n for (let i = 0; i < g._freeSlots.length; i++) {\n g._freeSlots[i] = g._freeSlots[i]! + delta;\n }\n }\n }\n for (const rec of data._runRecords.values()) {\n const slots = rec._slots;\n for (let i = 0; i < slots.length; i++) {\n if (slots[i]! >= threshold) {\n slots[i] = slots[i]! + delta;\n }\n }\n }\n // Slot ranges moved — cached vertex arrays keyed on `_layoutVersion` must rebuild.\n data._layoutVersion++;\n}\n\n/** Grow `group` by `extraSlots`. Returns the absolute index of the first newly-added\n * slot. Shifts later groups' slot ranges right by `extraSlots` and rewrites any run\n * slot indices that fall in the shifted range. Marks the shifted region dirty. */\nfunction growGroup(data: GLTextData, group: TextDataDrawGroup, extraSlots: number): number {\n const insertAt = group._slotStart + group._slotCount;\n if (extraSlots <= 0) {\n return insertAt;\n }\n ensureInstanceCapacity(data, data._instanceCount + extraSlots);\n const floatDelta = extraSlots * TEXT_INSTANCE_FLOATS;\n const moveStartFloat = insertAt * TEXT_INSTANCE_FLOATS;\n const moveEndFloat = data._instanceCount * TEXT_INSTANCE_FLOATS;\n if (moveEndFloat > moveStartFloat) {\n data._instances.copyWithin(moveStartFloat + floatDelta, moveStartFloat, moveEndFloat);\n }\n // Shift later groups (and their runs) right to open the gap for the new slots.\n shiftSlotsAtOrAfter(data, insertAt, extraSlots, group);\n data._instanceCount += extraSlots;\n group._slotCount += extraSlots;\n // Newly-added slots and the shifted region are dirty.\n markDirty(data, insertAt, data._instanceCount);\n return insertAt;\n}\n\n/** Allocate `count` slots for `group`. Reuses free slots first, then extends. Returns\n * the array of absolute slot indices in ascending order. */\nfunction allocateSlots(data: GLTextData, group: TextDataDrawGroup, count: number): number[] {\n // `.fill` is what keeps this PACKED_SMI_ELEMENTS in V8. A bare `new Array(count)` is\n // holey, and `writeRunToSlots` hands this exact array straight to a run record, so the\n // holeyness would leak into `shiftSlotsAtOrAfter`'s hot per-slot loop and halve its\n // throughput.\n const out: number[] = new Array(count).fill(-1);\n // Instances are drawn in slot order, so a run's glyphs have to land on ascending slots or\n // overlapping ones composite in the wrong order. `popFreeSlot` hands reclaimed slots back\n // LIFO, so a block that was just freed comes back reversed. Track that while filling instead\n // of rescanning afterwards, and sort only when it actually happened: `sort` runs a comparator\n // call per element even on already-ordered input, which is pure overhead on the common path.\n let sorted = true;\n let prevSlot = -1;\n let reused = count;\n for (let i = 0; i < count; i++) {\n const slot = popFreeSlot(group);\n // Nothing refills the free list mid-loop, so the rest of `out` comes from the extension.\n if (slot === -1) {\n reused = i;\n break;\n }\n out[i] = slot;\n sorted &&= slot >= prevSlot;\n prevSlot = slot;\n }\n if (reused < count) {\n const firstNewSlot = growGroup(data, group, count - reused);\n // Extension slots are appended past the group's tail and ascend from there, so only the\n // seam against the reused prefix can be out of order.\n sorted &&= firstNewSlot >= prevSlot;\n for (let i = reused, n = firstNewSlot; i < count; i++) {\n out[i] = n++;\n }\n }\n if (!sorted) {\n out.sort(ascendingSlot);\n }\n return out;\n}\n\nfunction ascendingSlot(a: number, b: number): number {\n return a - b;\n}\n\n/** Release `slots` back to `group._freeSlots`, marking each dead in the buffer. */\nfunction freeSlots(data: GLTextData, group: TextDataDrawGroup, slots: number[]): void {\n let minSlot = Number.POSITIVE_INFINITY;\n let maxSlot = -1;\n for (const s of slots) {\n markSlotDead(data._instances, data._instancesU32, s);\n group._freeSlots.push(s);\n if (s < minSlot) {\n minSlot = s;\n }\n if (s > maxSlot) {\n maxSlot = s;\n }\n }\n if (maxSlot >= 0) {\n markDirty(data, minSlot, maxSlot + 1);\n }\n}\n\n// ─── Draw-group helpers ────────────────────────────────────────────────────\n\nfunction findGroup(data: GLTextData, groupKey: TextGroupKey): TextDataDrawGroup | undefined {\n for (const g of data._groups) {\n if (g._groupKey === groupKey) {\n return g;\n }\n }\n return undefined;\n}\n\nfunction lookupCurveSet(storage: GLGlyphStorage, curveSetId: GLCurveSetId, op: string): GlyphStorageCurveSet {\n const cs = storage._curveSets.get(curveSetId);\n if (!cs) {\n throw new Error(`updateTextData ${op}: storage does not contain curveSet \"${curveSetId}\" — add it via updateGlyphStorage first.`);\n }\n return cs;\n}\n\n/** Build a fresh draw group for `groupKey` starting at absolute slot `slotStart`. */\nfunction makeDrawGroup(curveSetId: GLCurveSetId, curveSet: GlyphStorageCurveSet, slotStart: number, groupKey: TextGroupKey): TextDataDrawGroup {\n return {\n _curveSetId: curveSetId,\n _curveSet: curveSet,\n _slotStart: slotStart,\n _slotCount: 0,\n _liveCount: 0,\n _freeSlots: [],\n _groupKey: groupKey,\n };\n}\n\nfunction ensureGroup(data: GLTextData, curveSetId: GLCurveSetId, groupKey: TextGroupKey): TextDataDrawGroup {\n const existing = findGroup(data, groupKey);\n if (existing) {\n return existing;\n }\n const curveSet = lookupCurveSet(data._storage, curveSetId, \"addRun\");\n const group = makeDrawGroup(curveSetId, curveSet, data._instanceCount, groupKey);\n data._groups.push(group);\n return group;\n}\n\n/** Write a run's glyphs into the given (already-allocated) instance and style slots.\n * Returns the subset of instance slots that actually received\n * live glyphs (skipped glyphs leave their slot dead). When every glyph lands — the\n * overwhelmingly common case — that subset *is* `slots`, and the caller gets the same array\n * back rather than a freshly built copy. */\nfunction writeRunToSlots(data: GLTextData, group: TextDataDrawGroup, run: GLGlyphRun, slots: number[], styleSlots: number[]): number[] {\n const ratio = run.pixelsPerFontUnit;\n const invScale = ratio !== 0 ? 1 / ratio : 0;\n const styleParam = _textStyleSeam?._param(run) ?? 0;\n const defaultStyle = styleSlots[0]!;\n writeStyle(data, defaultStyle, run.defaultColor ?? WHITE_COLOR, invScale, styleParam);\n let overrideEntry = 0;\n // Materialized only once a glyph actually misses the atlas, seeded with the prefix that\n // did land; while it stays null, `slots` is by definition the live set.\n let liveSlots: number[] | null = null;\n let minSlot = Number.POSITIVE_INFINITY;\n let maxSlot = -1;\n for (let i = 0; i < run.glyphs.length; i++) {\n const pg = run.glyphs[i]!;\n const slot = slots[i]!;\n let styleIdx = defaultStyle;\n const color = pg.color;\n if (color !== undefined) {\n styleIdx = styleSlots[++overrideEntry]!;\n writeStyle(data, styleIdx, color, invScale, styleParam);\n }\n const ok = packGlyphAtSlot(data._instances, data._instancesU32, slot, group._curveSet, pg.glyphId, pg.x, pg.y, styleIdx);\n if (!ok) {\n if (liveSlots === null) {\n liveSlots = slots.slice(0, i);\n }\n markSlotDead(data._instances, data._instancesU32, slot);\n group._freeSlots.push(slot);\n } else if (liveSlots !== null) {\n liveSlots.push(slot);\n }\n if (slot < minSlot) {\n minSlot = slot;\n }\n if (slot > maxSlot) {\n maxSlot = slot;\n }\n }\n if (maxSlot >= 0) {\n markDirty(data, minSlot, maxSlot + 1);\n }\n return liveSlots ?? slots;\n}\n\n// ─── reset (also serves as compaction) ─────────────────────────────────────\n\nfunction applyReset(data: GLTextData, runs: readonly GLGlyphRun[], storage: GLGlyphStorage): void {\n // Pre-reserve capacity for total glyphs across all runs.\n let totalGlyphs = 0;\n let totalStyles = 0;\n for (const run of runs) {\n totalGlyphs += run.glyphs.length;\n totalStyles += countRunStyles(run);\n }\n ensureStyleCapacity(data, totalStyles);\n const required = totalGlyphs * TEXT_INSTANCE_FLOATS;\n if (data._instances.length < required) {\n let newLen = Math.max(data._instances.length * 2, TEXT_INSTANCE_FLOATS);\n while (newLen < required) {\n newLen *= 2;\n }\n data._instances = new Float32Array(newLen);\n data._instancesU32 = new Uint32Array(data._instances.buffer);\n }\n\n // Preserve previous groups for group reuse when the draw-group key matches. The key\n // is the run's exact `GLCurveSetId` unless a styling feature interned another token, and it\n // is compared by identity — never a delimited composite string, which would let a curve\n // set whose id already ends in the delimiter+suffix collide with another curve set's\n // variant group.\n const prevGroupByKey = new Map<TextGroupKey, TextDataDrawGroup>();\n for (const g of data._groups) {\n prevGroupByKey.set(g._groupKey, g);\n }\n\n data._storage = storage;\n\n // Group runs by draw-group key so each group's slots are contiguous initially.\n const runsByKey = new Map<TextGroupKey, GLGlyphRun[]>();\n for (const run of runs) {\n const key = runGroupKey(run);\n let list = runsByKey.get(key);\n if (!list) {\n list = [];\n runsByKey.set(key, list);\n }\n list.push(run);\n }\n\n const newGroups: TextDataDrawGroup[] = [];\n const newRunRecords = new Map<GLGlyphRun, RunRecord>();\n let writeSlot = 0;\n // A reset rebuilds the palette densely and drops all free-slot state.\n data._styleCount = 0;\n data._freeStyleSlots.length = 0;\n data._styleVersion++;\n\n for (const [key, groupRuns] of runsByKey) {\n // Every run in a group shares one curve set: the key is either the curve-set id\n // itself or a token the styling feature interned per curve set.\n const curveSetId = groupRuns[0]!.curveSet;\n const curveSet = lookupCurveSet(storage, curveSetId, \"reset\");\n\n const existing = prevGroupByKey.get(key);\n const group: TextDataDrawGroup = existing ?? makeDrawGroup(curveSetId, curveSet, writeSlot, key);\n group._curveSet = curveSet;\n group._slotStart = writeSlot;\n group._freeSlots = [];\n\n const groupIdx = newGroups.length;\n let liveInGroup = 0;\n for (const run of groupRuns) {\n // Packed for the same reason as in `allocateSlots` — this array becomes the run\n // record's slot list.\n const slots: number[] = new Array(run.glyphs.length).fill(-1);\n for (let i = 0; i < run.glyphs.length; i++) {\n slots[i] = writeSlot++;\n }\n const styleCount = countRunStyles(run);\n const styleSlots = new Array<number>(styleCount);\n for (let i = 0; i < styleCount; i++) {\n styleSlots[i] = data._styleCount++;\n }\n const live = writeRunToSlots(data, group, run, slots, styleSlots);\n liveInGroup += live.length;\n newRunRecords.set(run, { _run: run, _groupIdx: groupIdx, _slots: live, _styleSlots: styleSlots });\n }\n group._slotCount = writeSlot - group._slotStart;\n group._liveCount = liveInGroup;\n newGroups.push(group);\n }\n\n data._instanceCount = writeSlot;\n data._groups = newGroups;\n data._runs.length = 0;\n for (const r of runs) {\n data._runs.push(r);\n }\n data._runRecords = newRunRecords;\n\n data._dirtyStart = 0;\n data._dirtyEnd = writeSlot;\n data._version++;\n data._layoutVersion++;\n}\n\n// ─── addRun / removeRun / replaceRun ───────────────────────────────────────\n\nfunction resolveRun(data: GLTextData, ref: GLGlyphRun | number): GLGlyphRun {\n return typeof ref === \"number\" ? _resolveRunRef(data, ref, \"updateTextData\") : ref;\n}\n\n/** @internal Resolve a public `GLGlyphRun | number` reference against `data`'s live runs, so\n * an opt-in per-run feature setter validates its argument exactly the way `updateTextData`\n * does and throws the same shape of message. `op` prefixes that message.\n *\n * Unlike the internal `resolveRun`, an object reference is *checked for membership*: a\n * feature setter is a standalone entry point, so it cannot rely on a caller having already\n * looked the run's record up. `updateTextData`'s index path shares this function, so the\n * index bound check can never drift between the two. */\nexport function _resolveRunRef(data: GLTextData, ref: GLGlyphRun | number, op: string): GLGlyphRun {\n if (typeof ref === \"number\") {\n const r = data._runs[ref];\n if (!r) {\n throw new Error(`${op}: run index ${ref} out of range (0..${data._runs.length - 1}).`);\n }\n return r;\n }\n if (!data._runRecords.has(ref)) {\n throw new Error(`${op}: GLGlyphRun reference is not in this GLTextData.`);\n }\n return ref;\n}\n\n/** Index of `ref` within `data._runs`, or -1 when it is not present. A numeric ref *is* that\n * index (already range-checked by `resolveRun`), so it costs nothing; only an object ref\n * needs the O(run count) scan — resolve it lazily, and only when the answer is actually used. */\nfunction resolveRunIndex(data: GLTextData, ref: GLGlyphRun | number): number {\n return typeof ref === \"number\" ? ref : data._runs.indexOf(ref);\n}\n\nfunction applyAddRun(data: GLTextData, run: GLGlyphRun, insertBefore?: number): void {\n if (data._runRecords.has(run)) {\n throw new Error(\"updateTextData addRun: GLGlyphRun reference is already in this GLTextData.\");\n }\n const at = insertBefore ?? data._runs.length;\n lookupCurveSet(data._storage, run.curveSet, \"addRun\");\n const styleSlots = allocateStyles(data, countRunStyles(run));\n const group = ensureGroup(data, run.curveSet, runGroupKey(run));\n const groupIdx = data._groups.indexOf(group);\n const slots = allocateSlots(data, group, run.glyphs.length);\n const live = writeRunToSlots(data, group, run, slots, styleSlots);\n group._liveCount += live.length;\n data._runRecords.set(run, { _run: run, _groupIdx: groupIdx, _slots: live, _styleSlots: styleSlots });\n data._runs.splice(at, 0, run);\n}\n\nfunction applyRemoveRun(data: GLTextData, ref: GLGlyphRun | number): void {\n const run = resolveRun(data, ref);\n const rec = data._runRecords.get(run);\n if (!rec) {\n throw new Error(\"updateTextData removeRun: GLGlyphRun reference is not in this GLTextData.\");\n }\n const group = data._groups[rec._groupIdx]!;\n freeSlots(data, group, rec._slots);\n group._liveCount -= rec._slots.length;\n releaseStyles(data, rec._styleSlots);\n data._runRecords.delete(run);\n const runIdx = resolveRunIndex(data, ref);\n if (runIdx >= 0) {\n data._runs.splice(runIdx, 1);\n }\n // If the group has no live instances left and no remaining run (empty or whitespace-only runs\n // own no slots but still point at their group), drop it and shrink the buffer tail.\n if (group._liveCount === 0 && !isGroupReferenced(data, rec._groupIdx)) {\n dropEmptyGroup(data, group);\n }\n}\n\n/** True when any remaining run record points at the group at `groupIdx`. */\nfunction isGroupReferenced(data: GLTextData, groupIdx: number): boolean {\n for (const r of data._runRecords.values()) {\n if (r._groupIdx === groupIdx) {\n return true;\n }\n }\n return false;\n}\n\n/** Remove a group with no live instances. Shifts later groups left over the vacated range.\n * The group's borrowed curveSet is left intact — caller owns the GLGlyphStorage lifetime. */\nfunction dropEmptyGroup(data: GLTextData, group: TextDataDrawGroup): void {\n const idx = data._groups.indexOf(group);\n if (idx < 0) {\n return;\n }\n const removedStart = group._slotStart;\n const removedCount = group._slotCount;\n data._groups.splice(idx, 1);\n // Re-index groupIdx for runs in later groups.\n for (const r of data._runRecords.values()) {\n if (r._groupIdx > idx) {\n r._groupIdx--;\n }\n }\n if (removedCount > 0) {\n const floatDelta = removedCount * TEXT_INSTANCE_FLOATS;\n const moveStartFloat = (removedStart + removedCount) * TEXT_INSTANCE_FLOATS;\n const moveEndFloat = data._instanceCount * TEXT_INSTANCE_FLOATS;\n if (moveEndFloat > moveStartFloat) {\n data._instances.copyWithin(moveStartFloat - floatDelta, moveStartFloat, moveEndFloat);\n }\n // Close the gap left by the removed group (its runs are already gone).\n shiftSlotsAtOrAfter(data, removedStart, -removedCount);\n data._instanceCount -= removedCount;\n markDirty(data, removedStart, data._instanceCount);\n }\n}\n\nfunction applyReplaceRun(data: GLTextData, prevRef: GLGlyphRun | number, newRun: GLGlyphRun): void {\n const prev = resolveRun(data, prevRef);\n const rec = data._runRecords.get(prev);\n if (!rec) {\n throw new Error(\"updateTextData replaceRun: previous GLGlyphRun reference is not in this GLTextData.\");\n }\n if (prev !== newRun && data._runRecords.has(newRun)) {\n throw new Error(\"updateTextData replaceRun: new GLGlyphRun reference is already in this GLTextData.\");\n }\n const group = data._groups[rec._groupIdx]!;\n // Staying in the same draw group means the run keeps its position in `_runs`, so the whole\n // edit reduces to slot bookkeeping — no list splices, and no index scan to drive them. An\n // empty new run is the one exception: it can leave the group with nothing live, and only\n // the remove path knows how to retire a group.\n if (runGroupKey(newRun) === group._groupKey && newRun.glyphs.length > 0) {\n const styleSlots = allocateStyles(data, countRunStyles(newRun), rec._styleSlots);\n const prevSlotCount = rec._slots.length;\n let slots = rec._slots;\n if (newRun.glyphs.length !== prevSlotCount) {\n // Glyph count changed, so this run hands its slots back to the group's free list and\n // takes a fresh block. It reclaims most of them immediately — the allocator pops the\n // slots it just freed — so the write stays within roughly the same buffer range.\n freeSlots(data, group, slots);\n slots = allocateSlots(data, group, newRun.glyphs.length);\n }\n const live = writeRunToSlots(data, group, newRun, slots, styleSlots);\n // Absorbs both a changed glyph count and any glyph that missed the atlas.\n group._liveCount += live.length - prevSlotCount;\n if (prev === newRun) {\n // In-place glyph edits: the record and `_runs` already point at this run, so its\n // live instance and style slot lists are the only things that can have moved.\n rec._slots = live;\n rec._styleSlots = styleSlots;\n } else {\n data._runRecords.delete(prev);\n data._runRecords.set(newRun, { _run: newRun, _groupIdx: rec._groupIdx, _slots: live, _styleSlots: styleSlots });\n const runIdx = resolveRunIndex(data, prevRef);\n if (runIdx >= 0) {\n data._runs[runIdx] = newRun;\n }\n }\n return;\n }\n // Different curve set, or an empty replacement → remove + add at the same position.\n const insertPos = resolveRunIndex(data, prevRef);\n lookupCurveSet(data._storage, newRun.curveSet, \"replaceRun\");\n if (countRunStyles(newRun) > data._freeStyleSlots.length + rec._styleSlots.length + MAX_STYLE_ENTRIES - data._styleCount) {\n throw new Error(`GLTextData style palette cannot exceed ${MAX_STYLE_ENTRIES} entries.`);\n }\n applyRemoveRun(data, insertPos >= 0 ? insertPos : prev);\n applyAddRun(data, newRun, insertPos >= 0 ? insertPos : undefined);\n}\n\n// ─── Public API ────────────────────────────────────────────────────────────\n\n/** Create a GLTextData bound to `storage`. If `runs` is omitted the GLTextData starts empty;\n * runs can be appended later via `updateTextData({ update: \"addRun\", … })`. */\nexport function createTextData(storage: GLGlyphStorage, runs?: readonly GLGlyphRun[]): GLTextData {\n const runsArray: GLGlyphRun[] = [];\n const instances = new Float32Array(TEXT_INSTANCE_FLOATS);\n const data = {\n _gpu: null,\n runs: runsArray,\n _runs: runsArray,\n _groups: [],\n _runRecords: new Map(),\n _instances: instances,\n _instancesU32: new Uint32Array(instances.buffer),\n _instanceCount: 0,\n _styles: new Float32Array(TEXT_STYLE_FLOATS),\n _styleCount: 0,\n _freeStyleSlots: [],\n _styleVersion: 1,\n _storage: storage,\n _version: 1,\n _layoutVersion: 0,\n _dirtyStart: 0,\n _dirtyEnd: 0,\n } as unknown as GLTextData;\n if (runs && runs.length > 0) {\n applyReset(data, runs, storage);\n }\n return data;\n}\n\n/** Apply an incremental edit to a `GLTextData`, such as adding, removing, replacing, or compacting runs.\n *\n * @param data - Text data block to update.\n * @param update - Discriminated update operation to apply. */\nexport function updateTextData(data: GLTextData, update: GLTextDataUpdate): void {\n switch (update.update) {\n case \"reset\": {\n // Defaults for compaction: keep current runs (defensive copy — applyReset\n // mutates data._runs in place) and current storage.\n const runs = update.runs ?? data._runs.slice();\n const storage = update.storage ?? data._storage;\n applyReset(data, runs, storage);\n return;\n }\n case \"addRun\":\n applyAddRun(data, update.run, update.insertBefore);\n return;\n case \"removeRun\":\n applyRemoveRun(data, update.run);\n return;\n case \"replaceRun\":\n applyReplaceRun(data, update.previous, update.run);\n return;\n }\n}\n\n/** Release per-block GPU resources owned by `data`. Does NOT dispose the bound\n * `GLGlyphStorage` — caller owns its lifetime and must dispose it separately via\n * `disposeGlyphStorage` once no `GLTextData` references it. */\nexport function disposeTextData(data: GLTextData): void {\n const gpu = data._gpu;\n if (gpu) {\n disposeBuffer(gpu._engine, gpu._instanceBuf);\n disposeTexture(gpu._engine, gpu._styleTex);\n data._gpu = null;\n }\n data._groups = [];\n data._instanceCount = 0;\n data._styleCount = 0;\n data._freeStyleSlots.length = 0;\n data._runs.length = 0;\n data._runRecords.clear();\n}\n"]}
@@ -0,0 +1,68 @@
1
+ import type { GLEngineContext } from "../context.js";
2
+ import type { GLTextData } from "./text-data.js";
3
+ /** Pixel-space placement and compositing of one text block. */
4
+ export interface GLTextLayerOptions {
5
+ readonly positionPx?: {
6
+ readonly x: number;
7
+ readonly y: number;
8
+ };
9
+ readonly rotationRad?: number;
10
+ readonly scale?: number;
11
+ readonly order?: number;
12
+ readonly opacity?: number;
13
+ /** Raises analytic coverage to 1/gamma. Default 1; values above 1 darken edges. */
14
+ readonly coverageGamma?: number;
15
+ readonly visible?: boolean;
16
+ }
17
+ /** Mutable placement of borrowed text data. Positions are in target pixels, not CSS pixels. */
18
+ export interface GLTextLayer {
19
+ readonly data: GLTextData;
20
+ positionPx: {
21
+ x: number;
22
+ y: number;
23
+ };
24
+ rotationRad: number;
25
+ scale: number;
26
+ order: number;
27
+ opacity: number;
28
+ coverageGamma: number;
29
+ visible: boolean;
30
+ }
31
+ /** Create a pure-data layer; rendering does not transfer ownership of its text data. */
32
+ export declare function createTextLayer(data: GLTextData, options?: GLTextLayerOptions): GLTextLayer;
33
+ /** Set the layer's baseline origin in target pixels. */
34
+ export declare function setTextLayerPosition(layer: GLTextLayer, x: number, y: number): void;
35
+ /** Options for drawing text to the currently bound canvas or render target. */
36
+ export interface GLTextRendererOptions {
37
+ layers: readonly GLTextLayer[];
38
+ /** Default true. Disable to draw an overlay without clearing existing color. */
39
+ clear?: boolean;
40
+ /** Default opaque black. */
41
+ clearValue?: {
42
+ r: number;
43
+ g: number;
44
+ b: number;
45
+ a?: number;
46
+ };
47
+ }
48
+ /** Standalone WebGL2 analytic text renderer; owns programs/VAOs, not its layers' data. */
49
+ export interface GLTextRenderer {
50
+ readonly layers: readonly GLTextLayer[];
51
+ }
52
+ /** Create a renderer. Poll readiness before relying on its first draw. */
53
+ export declare function createTextRenderer(engine: GLEngineContext, options: GLTextRendererOptions): GLTextRenderer;
54
+ /** True only when all shader variants needed by visible layers have linked. */
55
+ export declare function isTextRendererReady(renderer: GLTextRenderer): boolean;
56
+ /** Draw visible layers to the bound target, respecting existing scissor/stencil clipping.
57
+ * Returns draw-call count. An unfinished shader or lost/disposed context draws nothing. */
58
+ export declare function renderText(renderer: GLTextRenderer): number;
59
+ /** Append a layer without transferring ownership. Duplicate references are ignored. */
60
+ export declare function addTextRendererLayer(renderer: GLTextRenderer, layer: GLTextLayer): void;
61
+ /** Remove a layer and release VAOs no longer used by any remaining layer. */
62
+ export declare function removeTextRendererLayer(renderer: GLTextRenderer, layer: GLTextLayer): boolean;
63
+ /** Register one automatic draw callback with the engine's render loop. Idempotent. */
64
+ export declare function registerTextRenderer(renderer: GLTextRenderer): void;
65
+ /** Remove only this renderer's automatic draw callback. */
66
+ export declare function unregisterTextRenderer(renderer: GLTextRenderer): void;
67
+ /** Release owned programs, quad and VAOs. Borrowed text data/storage stay alive. */
68
+ export declare function disposeTextRenderer(renderer: GLTextRenderer): void;
@@ -0,0 +1,238 @@
1
+ import { offContextLost, onContextLost } from "../context.js";
2
+ import { disposeEffect, isEffectReady, setEffectTexture } from "../effect.js";
3
+ import { createVertexBuffer, disposeBuffer } from "../mesh.js";
4
+ import { disableBlend, setBlendState } from "../blend.js";
5
+ import { applyGLStates } from "../apply-states.js";
6
+ import { clearEngine, setColorMask, setCullState, setDepthState } from "../depth-stencil.js";
7
+ import { setViewport } from "../effect-renderer.js";
8
+ import { runRenderLoop, stopRenderLoop } from "../render-loop.js";
9
+ import { ensureSharedAtlasGpu } from "./_gpu/text-textures.js";
10
+ import { ensureTextDataGpu } from "./_gpu/text-instances.js";
11
+ import { _createTextVariant, createTextProgram, uploadTextUniforms } from "./_gpu/text-effect.js";
12
+ import { bindTextVao, disposeTextVao } from "./_gpu/text-vao.js";
13
+ /** Create a pure-data layer; rendering does not transfer ownership of its text data. */
14
+ export function createTextLayer(data, options) {
15
+ return {
16
+ data,
17
+ positionPx: { x: options?.positionPx?.x ?? 0, y: options?.positionPx?.y ?? 0 },
18
+ rotationRad: options?.rotationRad ?? 0,
19
+ scale: options?.scale ?? 1,
20
+ order: options?.order ?? 0,
21
+ opacity: options?.opacity ?? 1,
22
+ coverageGamma: options?.coverageGamma ?? 1,
23
+ visible: options?.visible ?? true,
24
+ };
25
+ }
26
+ /** Set the layer's baseline origin in target pixels. */
27
+ export function setTextLayerPosition(layer, x, y) {
28
+ layer.positionPx.x = x;
29
+ layer.positionPx.y = y;
30
+ }
31
+ const QUAD_CORNERS = new Float32Array([-1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1]);
32
+ const TEXT_DEPTH_STATE = { test: false, write: false };
33
+ // Premultiplied source-over, including alpha (the general GL preset accumulates alpha).
34
+ const TEXT_BLEND_STATE = { srcRGB: 1, dstRGB: 0x0303, srcAlpha: 1, dstAlpha: 0x0303 };
35
+ /** Create a renderer. Poll readiness before relying on its first draw. */
36
+ export function createTextRenderer(engine, options) {
37
+ if (engine._isLost || engine._disposed) {
38
+ throw new Error("lite-gl: cannot create a text renderer on a lost or disposed engine.");
39
+ }
40
+ const base = createTextProgram(engine);
41
+ let quad;
42
+ try {
43
+ quad = createVertexBuffer(engine, QUAD_CORNERS);
44
+ }
45
+ catch (error) {
46
+ disposeEffect(engine, base._effect);
47
+ throw error;
48
+ }
49
+ const layers = options.layers.slice();
50
+ const drawState = new Map();
51
+ const onLost = () => drawState.clear();
52
+ const renderer = {
53
+ layers,
54
+ _layers: layers,
55
+ _engine: engine,
56
+ _base: base,
57
+ _variant: null,
58
+ _quad: quad,
59
+ _drawState: drawState,
60
+ _viewport: { x: 0, y: 0, w: 0, h: 0 },
61
+ _clearOptions: options.clear === false ? null : { color: options.clearValue ?? { r: 0, g: 0, b: 0, a: 1 } },
62
+ _loopFn: null,
63
+ _onLost: onLost,
64
+ _disposed: false,
65
+ };
66
+ onContextLost(engine, onLost);
67
+ return renderer;
68
+ }
69
+ function getDrawState(renderer, data) {
70
+ let state = renderer._drawState.get(data);
71
+ if (!state) {
72
+ state = { _layoutVersion: -1, _hasVariant: false, _vaos: [] };
73
+ renderer._drawState.set(data, state);
74
+ }
75
+ if (state._layoutVersion !== data._layoutVersion) {
76
+ state._hasVariant = false;
77
+ for (const group of data._groups) {
78
+ state._hasVariant ||= group._groupKey !== group._curveSetId;
79
+ }
80
+ for (let i = data._groups.length; i < state._vaos.length; i++) {
81
+ const vao = state._vaos[i];
82
+ if (vao) {
83
+ disposeTextVao(renderer._engine, vao);
84
+ }
85
+ }
86
+ state._vaos.length = Math.min(state._vaos.length, data._groups.length);
87
+ state._layoutVersion = data._layoutVersion;
88
+ }
89
+ return state;
90
+ }
91
+ /** True only when all shader variants needed by visible layers have linked. */
92
+ export function isTextRendererReady(renderer) {
93
+ const engine = renderer._engine;
94
+ if (renderer._disposed || engine._isLost || engine._disposed || !isEffectReady(engine, renderer._base._effect)) {
95
+ return false;
96
+ }
97
+ if (!renderer._variant && _createTextVariant) {
98
+ for (const layer of renderer._layers) {
99
+ if (layer.visible && getDrawState(renderer, layer.data)._hasVariant) {
100
+ renderer._variant = _createTextVariant(engine);
101
+ break;
102
+ }
103
+ }
104
+ }
105
+ return !renderer._variant || isEffectReady(engine, renderer._variant._effect);
106
+ }
107
+ function compareLayers(a, b) {
108
+ return a.order - b.order;
109
+ }
110
+ /** Draw visible layers to the bound target, respecting existing scissor/stencil clipping.
111
+ * Returns draw-call count. An unfinished shader or lost/disposed context draws nothing. */
112
+ export function renderText(renderer) {
113
+ if (!isTextRendererReady(renderer)) {
114
+ return 0;
115
+ }
116
+ const engine = renderer._engine;
117
+ const gl = engine.gl;
118
+ const target = engine._currentRenderTarget;
119
+ const width = target?.width ?? engine.canvas.width;
120
+ const height = target?.height ?? engine.canvas.height;
121
+ if (width === 0 || height === 0) {
122
+ return 0;
123
+ }
124
+ renderer._viewport.w = width;
125
+ renderer._viewport.h = height;
126
+ setViewport(engine, renderer._viewport);
127
+ setDepthState(engine, TEXT_DEPTH_STATE);
128
+ setCullState(engine, false);
129
+ setColorMask(engine, true, true, true, true);
130
+ setBlendState(engine, TEXT_BLEND_STATE);
131
+ gl.frontFace(gl.CCW);
132
+ if (renderer._clearOptions) {
133
+ clearEngine(engine, renderer._clearOptions);
134
+ }
135
+ applyGLStates(engine);
136
+ if (renderer._layers.length > 1) {
137
+ renderer._layers.sort(compareLayers);
138
+ }
139
+ let draws = 0;
140
+ for (const layer of renderer._layers) {
141
+ if (!layer.visible || layer.data._instanceCount === 0) {
142
+ continue;
143
+ }
144
+ const data = layer.data;
145
+ const gpu = ensureTextDataGpu(engine, data);
146
+ const state = getDrawState(renderer, data);
147
+ let currentProgram = null;
148
+ for (let i = 0; i < data._groups.length; i++) {
149
+ const group = data._groups[i];
150
+ if (group._slotCount === 0) {
151
+ continue;
152
+ }
153
+ const program = group._groupKey === group._curveSetId ? renderer._base : renderer._variant;
154
+ if (currentProgram !== program) {
155
+ uploadTextUniforms(engine, program, layer, width, height);
156
+ setEffectTexture(engine, program._effect, "styles", gpu._styleTex);
157
+ currentProgram = program;
158
+ }
159
+ const atlas = ensureSharedAtlasGpu(engine, group._curveSet._atlas);
160
+ setEffectTexture(engine, program._effect, "curveTex", atlas._curveTex);
161
+ setEffectTexture(engine, program._effect, "bandTex", atlas._bandTex);
162
+ setEffectTexture(engine, program._effect, "glyphMetadata", atlas._metaTex);
163
+ state._vaos[i] = bindTextVao(engine, renderer._quad, gpu._instanceBuf, group._slotStart, state._vaos[i]);
164
+ gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, group._slotCount);
165
+ draws++;
166
+ }
167
+ }
168
+ disableBlend(engine);
169
+ return draws;
170
+ }
171
+ /** Append a layer without transferring ownership. Duplicate references are ignored. */
172
+ export function addTextRendererLayer(renderer, layer) {
173
+ if (!renderer._disposed && !renderer._layers.includes(layer)) {
174
+ renderer._layers.push(layer);
175
+ }
176
+ }
177
+ /** Remove a layer and release VAOs no longer used by any remaining layer. */
178
+ export function removeTextRendererLayer(renderer, layer) {
179
+ const index = renderer._layers.indexOf(layer);
180
+ if (index < 0) {
181
+ return false;
182
+ }
183
+ renderer._layers.splice(index, 1);
184
+ if (!renderer._layers.some((remaining) => remaining.data === layer.data)) {
185
+ const state = renderer._drawState.get(layer.data);
186
+ if (state) {
187
+ for (const vao of state._vaos) {
188
+ if (vao) {
189
+ disposeTextVao(renderer._engine, vao);
190
+ }
191
+ }
192
+ renderer._drawState.delete(layer.data);
193
+ }
194
+ }
195
+ return true;
196
+ }
197
+ /** Register one automatic draw callback with the engine's render loop. Idempotent. */
198
+ export function registerTextRenderer(renderer) {
199
+ if (renderer._disposed || renderer._loopFn !== null) {
200
+ return;
201
+ }
202
+ renderer._loopFn = () => {
203
+ renderText(renderer);
204
+ };
205
+ runRenderLoop(renderer._engine, renderer._loopFn);
206
+ }
207
+ /** Remove only this renderer's automatic draw callback. */
208
+ export function unregisterTextRenderer(renderer) {
209
+ if (renderer._loopFn) {
210
+ stopRenderLoop(renderer._engine, renderer._loopFn);
211
+ renderer._loopFn = null;
212
+ }
213
+ }
214
+ /** Release owned programs, quad and VAOs. Borrowed text data/storage stay alive. */
215
+ export function disposeTextRenderer(renderer) {
216
+ if (renderer._disposed) {
217
+ return;
218
+ }
219
+ unregisterTextRenderer(renderer);
220
+ renderer._disposed = true;
221
+ const engine = renderer._engine;
222
+ offContextLost(engine, renderer._onLost);
223
+ for (const state of renderer._drawState.values()) {
224
+ for (const vao of state._vaos) {
225
+ if (vao) {
226
+ disposeTextVao(engine, vao);
227
+ }
228
+ }
229
+ }
230
+ renderer._drawState.clear();
231
+ disposeEffect(engine, renderer._base._effect);
232
+ if (renderer._variant) {
233
+ disposeEffect(engine, renderer._variant._effect);
234
+ }
235
+ disposeBuffer(engine, renderer._quad);
236
+ renderer._layers.length = 0;
237
+ }
238
+ //# sourceMappingURL=text-renderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-renderer.js","sourceRoot":"","sources":["../../src/text/text-renderer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE/D,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAE7F,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAElE,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAElG,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AA2BjE,wFAAwF;AACxF,MAAM,UAAU,eAAe,CAAC,IAAgB,EAAE,OAA4B;IAC1E,OAAO;QACH,IAAI;QACJ,UAAU,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE;QAC9E,WAAW,EAAE,OAAO,EAAE,WAAW,IA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,CAAC;YAC5B,IAAI,GAAG,EAAE,CAAC;gBACN,cAAc,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;YAChC,CAAC;QACL,CAAC;IACL,CAAC;IACD,QAAQ,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAC5B,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC9C,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACpB,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACrD,CAAC;IACD,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IACtC,QAAQ,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import type { GLEngineContext } from \"../context.js\";\nimport { offContextLost, onContextLost } from \"../context.js\";\nimport { disposeEffect, isEffectReady, setEffectTexture } from \"../effect.js\";\nimport { createVertexBuffer, disposeBuffer } from \"../mesh.js\";\nimport type { GLVertexBuffer } from \"../mesh.js\";\nimport { disableBlend, setBlendState } from \"../blend.js\";\nimport { applyGLStates } from \"../apply-states.js\";\nimport { clearEngine, setColorMask, setCullState, setDepthState } from \"../depth-stencil.js\";\nimport type { GLClearOptions } from \"../depth-stencil.js\";\nimport { setViewport } from \"../effect-renderer.js\";\nimport type { GLViewport } from \"../effect-renderer.js\";\nimport { runRenderLoop, stopRenderLoop } from \"../render-loop.js\";\nimport type { GLTextData } from \"./text-data.js\";\nimport { ensureSharedAtlasGpu } from \"./_gpu/text-textures.js\";\nimport { ensureTextDataGpu } from \"./_gpu/text-instances.js\";\nimport { _createTextVariant, createTextProgram, uploadTextUniforms } from \"./_gpu/text-effect.js\";\nimport type { TextProgram } from \"./_gpu/text-effect.js\";\nimport { bindTextVao, disposeTextVao } from \"./_gpu/text-vao.js\";\nimport type { TextVao } from \"./_gpu/text-vao.js\";\n\n/** Pixel-space placement and compositing of one text block. */\nexport interface GLTextLayerOptions {\n readonly positionPx?: { readonly x: number; readonly y: number };\n readonly rotationRad?: number;\n readonly scale?: number;\n readonly order?: number;\n readonly opacity?: number;\n /** Raises analytic coverage to 1/gamma. Default 1; values above 1 darken edges. */\n readonly coverageGamma?: number;\n readonly visible?: boolean;\n}\n\n/** Mutable placement of borrowed text data. Positions are in target pixels, not CSS pixels. */\nexport interface GLTextLayer {\n readonly data: GLTextData;\n positionPx: { x: number; y: number };\n rotationRad: number;\n scale: number;\n order: number;\n opacity: number;\n coverageGamma: number;\n visible: boolean;\n}\n\n/** Create a pure-data layer; rendering does not transfer ownership of its text data. */\nexport function createTextLayer(data: GLTextData, options?: GLTextLayerOptions): GLTextLayer {\n return {\n data,\n positionPx: { x: options?.positionPx?.x ?? 0, y: options?.positionPx?.y ?? 0 },\n rotationRad: options?.rotationRad ?? 0,\n scale: options?.scale ?? 1,\n order: options?.order ?? 0,\n opacity: options?.opacity ?? 1,\n coverageGamma: options?.coverageGamma ?? 1,\n visible: options?.visible ?? true,\n };\n}\n\n/** Set the layer's baseline origin in target pixels. */\nexport function setTextLayerPosition(layer: GLTextLayer, x: number, y: number): void {\n layer.positionPx.x = x;\n layer.positionPx.y = y;\n}\n\n/** Options for drawing text to the currently bound canvas or render target. */\nexport interface GLTextRendererOptions {\n layers: readonly GLTextLayer[];\n /** Default true. Disable to draw an overlay without clearing existing color. */\n clear?: boolean;\n /** Default opaque black. */\n clearValue?: { r: number; g: number; b: number; a?: number };\n}\n\n/** @internal */\ninterface DataDrawState {\n _layoutVersion: number;\n _hasVariant: boolean;\n _vaos: (TextVao | undefined)[];\n}\n\n/** Standalone WebGL2 analytic text renderer; owns programs/VAOs, not its layers' data. */\nexport interface GLTextRenderer {\n readonly layers: readonly GLTextLayer[];\n /** @internal */ _layers: GLTextLayer[];\n /** @internal */ _engine: GLEngineContext;\n /** @internal */ _base: TextProgram;\n /** @internal */ _variant: TextProgram | null;\n /** @internal */ _quad: GLVertexBuffer;\n /** @internal */ _drawState: Map<GLTextData, DataDrawState>;\n /** @internal */ _viewport: GLViewport;\n /** @internal */ _clearOptions: GLClearOptions | null;\n /** @internal */ _loopFn: ((dt: number) => void) | null;\n /** @internal */ _onLost: () => void;\n /** @internal */ _disposed: boolean;\n}\n\nconst QUAD_CORNERS = new Float32Array([-1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1]);\nconst TEXT_DEPTH_STATE = { test: false, write: false };\n// Premultiplied source-over, including alpha (the general GL preset accumulates alpha).\nconst TEXT_BLEND_STATE = { srcRGB: 1, dstRGB: 0x0303, srcAlpha: 1, dstAlpha: 0x0303 };\n\n/** Create a renderer. Poll readiness before relying on its first draw. */\nexport function createTextRenderer(engine: GLEngineContext, options: GLTextRendererOptions): GLTextRenderer {\n if (engine._isLost || engine._disposed) {\n throw new Error(\"lite-gl: cannot create a text renderer on a lost or disposed engine.\");\n }\n const base = createTextProgram(engine);\n let quad: GLVertexBuffer;\n try {\n quad = createVertexBuffer(engine, QUAD_CORNERS);\n } catch (error) {\n disposeEffect(engine, base._effect);\n throw error;\n }\n const layers = options.layers.slice();\n const drawState = new Map<GLTextData, DataDrawState>();\n const onLost = (): void => drawState.clear();\n const renderer: GLTextRenderer = {\n layers,\n _layers: layers,\n _engine: engine,\n _base: base,\n _variant: null,\n _quad: quad,\n _drawState: drawState,\n _viewport: { x: 0, y: 0, w: 0, h: 0 },\n _clearOptions: options.clear === false ? null : { color: options.clearValue ?? { r: 0, g: 0, b: 0, a: 1 } },\n _loopFn: null,\n _onLost: onLost,\n _disposed: false,\n };\n onContextLost(engine, onLost);\n return renderer;\n}\n\nfunction getDrawState(renderer: GLTextRenderer, data: GLTextData): DataDrawState {\n let state = renderer._drawState.get(data);\n if (!state) {\n state = { _layoutVersion: -1, _hasVariant: false, _vaos: [] };\n renderer._drawState.set(data, state);\n }\n if (state._layoutVersion !== data._layoutVersion) {\n state._hasVariant = false;\n for (const group of data._groups) {\n state._hasVariant ||= group._groupKey !== group._curveSetId;\n }\n for (let i = data._groups.length; i < state._vaos.length; i++) {\n const vao = state._vaos[i];\n if (vao) {\n disposeTextVao(renderer._engine, vao);\n }\n }\n state._vaos.length = Math.min(state._vaos.length, data._groups.length);\n state._layoutVersion = data._layoutVersion;\n }\n return state;\n}\n\n/** True only when all shader variants needed by visible layers have linked. */\nexport function isTextRendererReady(renderer: GLTextRenderer): boolean {\n const engine = renderer._engine;\n if (renderer._disposed || engine._isLost || engine._disposed || !isEffectReady(engine, renderer._base._effect)) {\n return false;\n }\n if (!renderer._variant && _createTextVariant) {\n for (const layer of renderer._layers) {\n if (layer.visible && getDrawState(renderer, layer.data)._hasVariant) {\n renderer._variant = _createTextVariant(engine);\n break;\n }\n }\n }\n return !renderer._variant || isEffectReady(engine, renderer._variant._effect);\n}\n\nfunction compareLayers(a: GLTextLayer, b: GLTextLayer): number {\n return a.order - b.order;\n}\n\n/** Draw visible layers to the bound target, respecting existing scissor/stencil clipping.\n * Returns draw-call count. An unfinished shader or lost/disposed context draws nothing. */\nexport function renderText(renderer: GLTextRenderer): number {\n if (!isTextRendererReady(renderer)) {\n return 0;\n }\n const engine = renderer._engine;\n const gl = engine.gl;\n const target = engine._currentRenderTarget;\n const width = target?.width ?? engine.canvas.width;\n const height = target?.height ?? engine.canvas.height;\n if (width === 0 || height === 0) {\n return 0;\n }\n renderer._viewport.w = width;\n renderer._viewport.h = height;\n setViewport(engine, renderer._viewport);\n setDepthState(engine, TEXT_DEPTH_STATE);\n setCullState(engine, false);\n setColorMask(engine, true, true, true, true);\n setBlendState(engine, TEXT_BLEND_STATE);\n gl.frontFace(gl.CCW);\n if (renderer._clearOptions) {\n clearEngine(engine, renderer._clearOptions);\n }\n applyGLStates(engine);\n if (renderer._layers.length > 1) {\n renderer._layers.sort(compareLayers);\n }\n let draws = 0;\n for (const layer of renderer._layers) {\n if (!layer.visible || layer.data._instanceCount === 0) {\n continue;\n }\n const data = layer.data;\n const gpu = ensureTextDataGpu(engine, data);\n const state = getDrawState(renderer, data);\n let currentProgram: TextProgram | null = null;\n for (let i = 0; i < data._groups.length; i++) {\n const group = data._groups[i]!;\n if (group._slotCount === 0) {\n continue;\n }\n const program = group._groupKey === group._curveSetId ? renderer._base : renderer._variant!;\n if (currentProgram !== program) {\n uploadTextUniforms(engine, program, layer, width, height);\n setEffectTexture(engine, program._effect, \"styles\", gpu._styleTex);\n currentProgram = program;\n }\n const atlas = ensureSharedAtlasGpu(engine, group._curveSet._atlas);\n setEffectTexture(engine, program._effect, \"curveTex\", atlas._curveTex);\n setEffectTexture(engine, program._effect, \"bandTex\", atlas._bandTex);\n setEffectTexture(engine, program._effect, \"glyphMetadata\", atlas._metaTex);\n state._vaos[i] = bindTextVao(engine, renderer._quad, gpu._instanceBuf, group._slotStart, state._vaos[i]);\n gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, group._slotCount);\n draws++;\n }\n }\n disableBlend(engine);\n return draws;\n}\n\n/** Append a layer without transferring ownership. Duplicate references are ignored. */\nexport function addTextRendererLayer(renderer: GLTextRenderer, layer: GLTextLayer): void {\n if (!renderer._disposed && !renderer._layers.includes(layer)) {\n renderer._layers.push(layer);\n }\n}\n\n/** Remove a layer and release VAOs no longer used by any remaining layer. */\nexport function removeTextRendererLayer(renderer: GLTextRenderer, layer: GLTextLayer): boolean {\n const index = renderer._layers.indexOf(layer);\n if (index < 0) {\n return false;\n }\n renderer._layers.splice(index, 1);\n if (!renderer._layers.some((remaining) => remaining.data === layer.data)) {\n const state = renderer._drawState.get(layer.data);\n if (state) {\n for (const vao of state._vaos) {\n if (vao) {\n disposeTextVao(renderer._engine, vao);\n }\n }\n renderer._drawState.delete(layer.data);\n }\n }\n return true;\n}\n\n/** Register one automatic draw callback with the engine's render loop. Idempotent. */\nexport function registerTextRenderer(renderer: GLTextRenderer): void {\n if (renderer._disposed || renderer._loopFn !== null) {\n return;\n }\n renderer._loopFn = (): void => {\n renderText(renderer);\n };\n runRenderLoop(renderer._engine, renderer._loopFn);\n}\n\n/** Remove only this renderer's automatic draw callback. */\nexport function unregisterTextRenderer(renderer: GLTextRenderer): void {\n if (renderer._loopFn) {\n stopRenderLoop(renderer._engine, renderer._loopFn);\n renderer._loopFn = null;\n }\n}\n\n/** Release owned programs, quad and VAOs. Borrowed text data/storage stay alive. */\nexport function disposeTextRenderer(renderer: GLTextRenderer): void {\n if (renderer._disposed) {\n return;\n }\n unregisterTextRenderer(renderer);\n renderer._disposed = true;\n const engine = renderer._engine;\n offContextLost(engine, renderer._onLost);\n for (const state of renderer._drawState.values()) {\n for (const vao of state._vaos) {\n if (vao) {\n disposeTextVao(engine, vao);\n }\n }\n }\n renderer._drawState.clear();\n disposeEffect(engine, renderer._base._effect);\n if (renderer._variant) {\n disposeEffect(engine, renderer._variant._effect);\n }\n disposeBuffer(engine, renderer._quad);\n renderer._layers.length = 0;\n}\n"]}