@babylonjs/lite-gl 1.20.0 → 1.20.1
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.
- package/README.md +58 -19
- package/context.js +2 -0
- package/context.js.map +1 -1
- package/depth-stencil.d.ts +1 -2
- package/depth-stencil.js +2 -2
- package/depth-stencil.js.map +1 -1
- package/dynamic-texture.d.ts +18 -18
- package/dynamic-texture.js +28 -24
- package/dynamic-texture.js.map +1 -1
- package/effect-ready.d.ts +1 -3
- package/effect-ready.js +3 -3
- package/effect-ready.js.map +1 -1
- package/effect-renderer.d.ts +39 -12
- package/effect-renderer.js +47 -17
- package/effect-renderer.js.map +1 -1
- package/effect.d.ts +25 -21
- package/effect.js +69 -51
- package/effect.js.map +1 -1
- package/gpu-frame-time.d.ts +49 -0
- package/gpu-frame-time.js +130 -0
- package/gpu-frame-time.js.map +1 -0
- package/html-texture.d.ts +24 -34
- package/html-texture.js +34 -55
- package/html-texture.js.map +1 -1
- package/index.d.ts +9 -8
- package/index.js +9 -6
- package/index.js.map +1 -1
- package/mesh.d.ts +8 -14
- package/mesh.js +23 -19
- package/mesh.js.map +1 -1
- package/package.json +3 -3
- package/render-loop.d.ts +14 -0
- package/render-loop.js +23 -0
- package/render-loop.js.map +1 -1
- package/render-target.d.ts +109 -39
- package/render-target.js +136 -58
- package/render-target.js.map +1 -1
- package/sprites.d.ts +8 -2
- package/sprites.js +17 -13
- package/sprites.js.map +1 -1
- package/state.d.ts +1 -1
- package/state.js.map +1 -1
- package/text/_gpu/text-effect.js +5 -5
- package/text/_gpu/text-effect.js.map +1 -1
- package/text/_gpu/text-instances.js +4 -4
- package/text/_gpu/text-instances.js.map +1 -1
- package/text/_gpu/text-textures.js +5 -3
- package/text/_gpu/text-textures.js.map +1 -1
- package/text/glyph-storage.js +3 -3
- package/text/glyph-storage.js.map +1 -1
- package/text/text-data.js +2 -2
- package/text/text-data.js.map +1 -1
- package/text/text-renderer.js +11 -11
- package/text/text-renderer.js.map +1 -1
- package/texture-3d.d.ts +10 -7
- package/texture-3d.js +27 -12
- package/texture-3d.js.map +1 -1
- package/texture-source.d.ts +3 -4
- package/texture-source.js +5 -5
- package/texture-source.js.map +1 -1
- package/texture.d.ts +195 -31
- package/texture.js +215 -35
- package/texture.js.map +1 -1
package/state.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;kFAekF;AAClF,gBAAgB,CAAC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AACnD,gBAAgB,CAAC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AACnD,gBAAgB,CAAC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AACnD,gBAAgB,CAAC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AACjD,gBAAgB,CAAC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AACjD,gBAAgB,CAAC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC;AAClD,gBAAgB,CAAC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAChD,gBAAgB,CAAC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAChD,gBAAgB,CAAC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAChD,gBAAgB,CAAC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAChD,gBAAgB,CAAC,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AACnD,gBAAgB,CAAC,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,CAAC;AAChD,gBAAgB,CAAC,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AACnD,gBAAgB,CAAC,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AACnD,gBAAgB,CAAC,M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,CAAC;IACrB,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;IACrB,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;AACzB,CAAC","sourcesContent":["import type { GLEngineContext } from \"./context.js\";\n\n/* ─── Deferred render-state index-array layout ────────────────────────────────\n * The deferred render-state (blend / depth / cull / stencil / color-mask) lives\n * in a flat `Float64Array(46)` on `GLState.rs`: slots `0..20` hold the ACTUAL\n * applied GL state, slots `21..41` (`RS_X + RS_DESIRED`) the DESIRED twin, and\n * slots `42..45` the standalone (no-desired-twin) cached `gl.clearColor` RGBA.\n * `setStencilOpSeparate` lazily expands it to 52 slots for back-face operations.\n *\n * These `@internal` index consts are imported by blend.ts / depth-stencil.ts /\n * apply-states.ts. Because they are plain `const` integers, esbuild inlines each\n * to a 1–2 char literal (`rs[RS_BLEND_SRC_RGB + RS_DESIRED]` → `rs[22]`) when\n * bundling a scene — far smaller than the old cross-module `.dBlendSrcRGB` named\n * props, which could not be mangled and shipped verbatim in every bundle.\n *\n * Float64Array (NOT Int32Array) is required: `RS_STENCIL_MASK` /\n * `RS_STENCIL_FUNC_MASK` can be `0xFFFFFFFF`, which Int32 would store as `-1` and\n * collide with the `-1` \"unset\" sentinel; Float64 keeps `4294967295` distinct. */\n/** @internal */ export const RS_BLEND_ENABLED = 0;\n/** @internal */ export const RS_BLEND_SRC_RGB = 1;\n/** @internal */ export const RS_BLEND_DST_RGB = 2;\n/** @internal */ export const RS_BLEND_SRC_A = 3;\n/** @internal */ export const RS_BLEND_DST_A = 4;\n/** @internal */ export const RS_BLEND_EQ_RGB = 5;\n/** @internal */ export const RS_BLEND_EQ_A = 6;\n/** @internal */ export const RS_DEPTH_TEST = 7;\n/** @internal */ export const RS_DEPTH_MASK = 8;\n/** @internal */ export const RS_DEPTH_FUNC = 9;\n/** @internal */ export const RS_CULL_ENABLED = 10;\n/** @internal */ export const RS_CULL_FACE = 11;\n/** @internal */ export const RS_STENCIL_TEST = 12;\n/** @internal */ export const RS_STENCIL_MASK = 13;\n/** @internal */ export const RS_STENCIL_FUNC_FUNC = 14;\n/** @internal */ export const RS_STENCIL_FUNC_REF = 15;\n/** @internal */ export const RS_STENCIL_FUNC_MASK = 16;\n/** @internal */ export const RS_STENCIL_OP_FAIL = 17;\n/** @internal */ export const RS_STENCIL_OP_ZFAIL = 18;\n/** @internal */ export const RS_STENCIL_OP_ZPASS = 19;\n/** @internal */ export const RS_COLOR_MASK = 20;\n/** @internal Offset from an ACTUAL slot (`0..20`) to its DESIRED twin (`21..41`). */\nexport const RS_DESIRED = 21;\n/* Standalone cached gl.clearColor RGBA slots (`42..45`) — NO desired twin; a\n * simple apply-on-clear cache like viewport/scissor, stored in `rs` (not as named\n * GLState fields) so the index access mangles small instead of shipping\n * `.clearColorR` verbatim in every bundle. */\n/** @internal */ export const RS_CLEAR_R = 42;\n/** @internal */ export const RS_CLEAR_G = 43;\n/** @internal */ export const RS_CLEAR_B = 44;\n/** @internal */ export const RS_CLEAR_A = 45;\n\n/**\n * GL-state cache type. Owned by `GLEngineContext._state`.\n *\n * Two flavours of cached state coexist here:\n *\n * - **Eager bindings** (program / buffers / textures / VAO / framebuffer /\n * viewport / scissor / unpack). Each binding setter issues its `gl.*` call\n * immediately and updates the matching field in lock-step, eliding the call\n * when the cache already matches.\n * - **Deferred render-state** (blend / depth / cull / stencil / color-mask),\n * stored in the {@link GLState.rs} index-array. These follow Babylon's\n * `applyStates()` model: each setter records only the DESIRED slot\n * (`rs[RS_X + RS_DESIRED]`) and sets `statesDirty`; the real `gl.*` calls are\n * flushed by {@link applyGLStates} (apply-states.ts) immediately before each\n * draw / clear, reconciling DESIRED → ACTUAL and writing the actual slots\n * (`rs[RS_X]`) in lock-step. Both halves keep their `-1`/`0` unset sentinels.\n *\n * See `00-lite-gl.md` §4 for the full table of cached operations and the\n * deferred-state flush sites.\n *\n * INVARIANTS:\n * - The cache is the source of truth. If consumers poke `engine.gl.*` directly\n * they will silently corrupt this state.\n * - On `webglcontextlost` the whole `rs` array (both the actual and desired\n * halves) is reset to its initial sentinels (handles are dead anyway;\n * subsequent setters bail out on `engine._isLost`, and a post-restore setter\n * re-marks `statesDirty`).\n */\nexport interface GLState {\n currentProgram: WebGLProgram | null;\n activeTextureUnit: number;\n /** Per-unit TEXTURE_2D binding; length === caps.maxTextureUnits. */\n boundTextures: (WebGLTexture | null)[];\n /** Per-unit TEXTURE_3D binding, allocated only when first used. @internal */\n _boundTextures3D?: (WebGLTexture | null | undefined)[];\n /** Cached zero WebGL2 unpack row/image/skip layout for 3D uploads. @internal */\n _unpack3DLayoutKnown?: boolean;\n boundArrayBuffer: WebGLBuffer | null;\n boundElementBuffer: WebGLBuffer | null;\n boundVao: WebGLVertexArrayObject | null;\n viewportX: number;\n viewportY: number;\n viewportW: number;\n viewportH: number;\n /**\n * Currently-bound draw framebuffer, or `null` for the default (canvas)\n * framebuffer. Owned by the render-target module's `bindRenderTarget`\n * (binding `null` returns to the canvas). Reset to `null` on context-lost.\n */\n boundFramebuffer: WebGLFramebuffer | null;\n /**\n * Deferred render-state (blend / depth / cull / stencil / color-mask) packed\n * into a flat `Float64Array(46)`. Slots `0..20` (indexed by the `RS_*`\n * consts) are the ACTUAL applied GL state — what {@link applyGLStates} last\n * wrote to the context; slots `21..41` (`rs[RS_X + RS_DESIRED]`) are the\n * DESIRED twin the setters record. The setters write ONLY the desired half\n * (never `gl.*`, never the actual half) and raise `statesDirty`;\n * `applyGLStates` reconciles each desired → its actual twin right before a\n * draw / clear, issuing only the GL calls that changed and updating the\n * actual half in lock-step. Both preset and arbitrary blend paths feed the\n * same desired slots, so they can never desync.\n *\n * Sentinels (identical for both halves): `-1` for the tri-state enables\n * (`RS_BLEND_ENABLED` / `RS_DEPTH_TEST` / `RS_DEPTH_MASK` / `RS_CULL_ENABLED`\n * / `RS_STENCIL_TEST`) and the mask caches (`RS_STENCIL_MASK` /\n * `RS_COLOR_MASK`), plus the leading stencil-op slot\n * (`RS_STENCIL_OP_FAIL`); `0` for every other func / equation / op / ref\n * slot. The leading op sentinel lets the first op\n * setter seed omitted fields to WebGL's `KEEP` defaults before merging. An\n * unset desired equals its unset actual and is never flushed; the `-1`\n * blend/test sentinels guarantee the first applied state is never elided.\n * The blend func/equation slots are only trusted while `RS_BLEND_ENABLED` is\n * `1` — the disabled→enabled transition re-issues both (matching Babylon's\n * `AlphaState`, which does not track them while blending is off).\n *\n * `setStencilOpSeparate` lazily replaces this array with a 52-slot copy; the\n * six appended slots cache actual and desired back-face operations without\n * moving any base index.\n *\n * Float64 (not Int32): `RS_STENCIL_MASK` / `RS_STENCIL_FUNC_MASK` can be\n * `0xFFFFFFFF`, which Int32 stores as `-1` — colliding with the `-1` unset\n * sentinel. Reset on context-lost. */\n rs: Float64Array;\n /** `true` when at least one deferred-state setter ran since the last\n * {@link applyGLStates}. Gates the flush so an unchanged frame issues no\n * reconciliation work. */\n statesDirty: boolean;\n /* ─── Deferred render-state appliers (per-category, lazily installed) ──────\n * Each category's reconciler (blend / depth+cull / stencil / color-mask) is\n * installed onto its slot the first time the matching setter runs — a runtime\n * assignment, NOT a module-level side effect. `applyGLStates` dispatches ONLY\n * through these slots, so the reconcilers (and their GL reconciliation code)\n * are reachable only when their setter is in the bundle: a scene that never\n * touches a category tree-shakes its reconciler out entirely (e.g. a clear-\n * only scene drops all four). Left undefined until installed; never cleared on\n * context-lost (a post-restore setter re-installs idempotently). */\n /** @internal Blend reconciler (Babylon's `_alphaState`). */\n _flushBlend?: (engine: GLEngineContext) => void;\n /** @internal Depth + cull reconciler (Babylon's `_depthCullingState`). */\n _flushDepthCull?: (engine: GLEngineContext) => void;\n /** @internal Stencil reconciler (Babylon's `_stencilState`). */\n _flushStencil?: (engine: GLEngineContext) => void;\n /** @internal Lazy hook that mirrors shared stencil operations to the back face. */\n _setStencilBack?: (cache: GLState, state: { opFail?: GLenum; opZFail?: GLenum; opZPass?: GLenum }) => void;\n /** @internal Color-write-mask reconciler (Babylon's `setColorWrite`). */\n _flushColorMask?: (engine: GLEngineContext) => void;\n /** Scissor-test enable tri-state (`-1` unset, `0` off, `1` on). */\n scissorEnabled: number;\n scissorX: number;\n scissorY: number;\n scissorW: number;\n scissorH: number;\n /** Cached `gl.pixelStorei(UNPACK_ALIGNMENT)`, or `-1` when unset. */\n unpackAlignment: number;\n /** Cached `gl.pixelStorei(UNPACK_FLIP_Y_WEBGL)`, or `-1` when unset. */\n unpackFlipY: number;\n /** Cached `gl.pixelStorei(UNPACK_PREMULTIPLY_ALPHA_WEBGL)`, or `-1` unset. */\n unpackPremultiplyAlpha: number;\n /**\n * Per-location vertex-attribute enable flags for the DEFAULT (null) VAO —\n * the mesh / instancing path (mirrors Babylon's `_vertexAttribArraysEnabled`).\n * Index is the attribute location. lite-gl's quad / sprite paths use their\n * own VAOs and do not touch this. Cleared on context-lost.\n */\n enabledAttribs: boolean[];\n /**\n * Attribute locations currently configured with a non-default vertex divisor\n * (instanced attributes), mirroring Babylon's `_currentInstanceLocations`.\n * Each location is recorded once, so repeated binds without an unbind stay bounded.\n * `unbindInstanceAttributes` resets each back to divisor 0 and clears this.\n */\n instanceLocations: number[];\n /** Shared fullscreen quad — lazily created on first `applyEffectWrapper`. */\n quadVbo: WebGLBuffer | null;\n quadIbo: WebGLBuffer | null;\n quadVao: WebGLVertexArrayObject | null;\n}\n\n/** Indices in `rs` whose unset sentinel is `-1` (the tri-state enables, the\n * `stencilMask` / `colorMask` caches, and the leading shared stencil-op slot).\n * Every other slot defaults to `0`. The sentinel is written to BOTH\n * the actual (`i`) and desired (`i + RS_DESIRED`) halves. Kept as a\n * function-local literal so it stays a runtime value (no module-level\n * allocation / side effect). */\nfunction applyRenderStateSentinels(rs: Float64Array): void {\n for (const i of [RS_BLEND_ENABLED, RS_DEPTH_TEST, RS_DEPTH_MASK, RS_CULL_ENABLED, RS_STENCIL_TEST, RS_STENCIL_MASK, RS_STENCIL_OP_FAIL, RS_COLOR_MASK]) {\n rs[i] = -1;\n rs[i + RS_DESIRED] = -1;\n }\n // clearColor RGBA (standalone, no DESIRED twin) — `-1` forces the first clear\n // to issue gl.clearColor (valid components are 0..1).\n rs[RS_CLEAR_R] = rs[RS_CLEAR_G] = rs[RS_CLEAR_B] = rs[RS_CLEAR_A] = -1;\n}\n\n/** Allocate the 46-slot deferred render-state array (21 actual + 21 desired + 4\n * standalone clearColor) initialised to its unset sentinels — a fresh\n * `Float64Array` is already all `0`, so only the `-1` slots need writing. */\nfunction createRenderStateArray(): Float64Array {\n const rs = new Float64Array(46);\n applyRenderStateSentinels(rs);\n return rs;\n}\n\n/** Re-initialise a live render-state array in place: zero every slot, then\n * restore the `-1` sentinels. */\nfunction resetRenderStateArray(rs: Float64Array): void {\n rs.fill(0);\n applyRenderStateSentinels(rs);\n}\n\n/** Allocate a fresh, fully-null GLState sized for `maxTextureUnits`. */\nexport function createGLState(maxTextureUnits: number): GLState {\n return {\n currentProgram: null,\n activeTextureUnit: 0,\n boundTextures: new Array<WebGLTexture | null>(maxTextureUnits).fill(null),\n boundArrayBuffer: null,\n boundElementBuffer: null,\n boundVao: null,\n viewportX: 0,\n viewportY: 0,\n viewportW: 0,\n viewportH: 0,\n boundFramebuffer: null,\n rs: createRenderStateArray(),\n statesDirty: false,\n scissorEnabled: -1,\n scissorX: 0,\n scissorY: 0,\n scissorW: 0,\n scissorH: 0,\n unpackAlignment: -1,\n unpackFlipY: -1,\n unpackPremultiplyAlpha: -1,\n enabledAttribs: [],\n instanceLocations: [],\n quadVbo: null,\n quadIbo: null,\n quadVao: null,\n };\n}\n\n/** Reset only the cached \"current GL state\" — every binding (program / buffers /\n * textures / VAO / framebuffer) and render-state (blend / depth / stencil /\n * scissor / color-mask / viewport / unpack) field, including the whole `rs`\n * deferred render-state array (BOTH the actual applied values and the DESIRED\n * twins) plus `statesDirty` — to its unset sentinel, WITHOUT discarding owned\n * GPU resources (the shared quad). After this, the next setter in each category\n * is re-issued rather than elided.\n *\n * Used by `resetGLState` (context-lost) and by `wipeGLStateCache` (a host that\n * shares the GL context calling in after mutating raw `gl.*` state). The shared\n * quad's GL objects are still alive in the latter case, so they are preserved\n * here to avoid leaking + needlessly rebuilding them every render scope. */\nexport function resetGLStateCache(state: GLState): void {\n state.currentProgram = null;\n state.activeTextureUnit = 0;\n state.boundTextures.fill(null);\n state.boundArrayBuffer = null;\n state.boundElementBuffer = null;\n state.boundVao = null;\n state.viewportX = 0;\n state.viewportY = 0;\n state.viewportW = 0;\n state.viewportH = 0;\n state.boundFramebuffer = null;\n resetRenderStateArray(state.rs);\n state.statesDirty = false;\n state.scissorEnabled = -1;\n state.scissorX = 0;\n state.scissorY = 0;\n state.scissorW = 0;\n state.scissorH = 0;\n state.unpackAlignment = -1;\n state.unpackFlipY = -1;\n state.unpackPremultiplyAlpha = -1;\n state.enabledAttribs.length = 0;\n state.instanceLocations.length = 0;\n}\n\n/** Zero the cache in-place. Used by the context-lost handler — GL handles are\n * already dead per WebGL spec; we forget what we knew about them (including the\n * shared quad, whose GL objects are gone and must be rebuilt) so the next\n * bind/use after restore is NOT incorrectly elided. */\nexport function resetGLState(state: GLState): void {\n resetGLStateCache(state);\n state.quadVbo = null;\n state.quadIbo = null;\n state.quadVao = null;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;kFAekF;AAClF,gBAAgB,CAAC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AACnD,gBAAgB,CAAC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AACnD,gBAAgB,CAAC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AACnD,gBAAgB,CAAC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AACjD,gBAAgB,CAAC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AACjD,gBAAgB,CAAC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC;AAClD,gBAAgB,CAAC,MAAM,CAAC,MA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AAC;IACnB,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC;IACnB,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC;IACnB,KAAK,CAAC,eAAe,GAAG,CAAC,CAAC,CAAC;IAC3B,KAAK,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;IACvB,KAAK,CAAC,sBAAsB,GAAG,CAAC,CAAC,CAAC;IAClC,KAAK,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC;IAChC,KAAK,CAAC,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC;AACvC,CAAC;AAED;;;wDAGwD;AACxD,MAAM,UAAU,YAAY,CAAC,KAAc;IACvC,iBAAiB,CAAC,KAAK,CAAC,CAAC;IACzB,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;IACrB,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;IACrB,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;AACzB,CAAC","sourcesContent":["import type { GLEngineContext } from \"./context.js\";\n\n/* ─── Deferred render-state index-array layout ────────────────────────────────\n * The deferred render-state (blend / depth / cull / stencil / color-mask) lives\n * in a flat `Float64Array(46)` on `GLState.rs`: slots `0..20` hold the ACTUAL\n * applied GL state, slots `21..41` (`RS_X + RS_DESIRED`) the DESIRED twin, and\n * slots `42..45` the standalone (no-desired-twin) cached `gl.clearColor` RGBA.\n * `setStencilOpSeparate` lazily expands it to 52 slots for back-face operations.\n *\n * These `@internal` index consts are imported by blend.ts / depth-stencil.ts /\n * apply-states.ts. Because they are plain `const` integers, esbuild inlines each\n * to a 1–2 char literal (`rs[RS_BLEND_SRC_RGB + RS_DESIRED]` → `rs[22]`) when\n * bundling a scene — far smaller than the old cross-module `.dBlendSrcRGB` named\n * props, which could not be mangled and shipped verbatim in every bundle.\n *\n * Float64Array (NOT Int32Array) is required: `RS_STENCIL_MASK` /\n * `RS_STENCIL_FUNC_MASK` can be `0xFFFFFFFF`, which Int32 would store as `-1` and\n * collide with the `-1` \"unset\" sentinel; Float64 keeps `4294967295` distinct. */\n/** @internal */ export const RS_BLEND_ENABLED = 0;\n/** @internal */ export const RS_BLEND_SRC_RGB = 1;\n/** @internal */ export const RS_BLEND_DST_RGB = 2;\n/** @internal */ export const RS_BLEND_SRC_A = 3;\n/** @internal */ export const RS_BLEND_DST_A = 4;\n/** @internal */ export const RS_BLEND_EQ_RGB = 5;\n/** @internal */ export const RS_BLEND_EQ_A = 6;\n/** @internal */ export const RS_DEPTH_TEST = 7;\n/** @internal */ export const RS_DEPTH_MASK = 8;\n/** @internal */ export const RS_DEPTH_FUNC = 9;\n/** @internal */ export const RS_CULL_ENABLED = 10;\n/** @internal */ export const RS_CULL_FACE = 11;\n/** @internal */ export const RS_STENCIL_TEST = 12;\n/** @internal */ export const RS_STENCIL_MASK = 13;\n/** @internal */ export const RS_STENCIL_FUNC_FUNC = 14;\n/** @internal */ export const RS_STENCIL_FUNC_REF = 15;\n/** @internal */ export const RS_STENCIL_FUNC_MASK = 16;\n/** @internal */ export const RS_STENCIL_OP_FAIL = 17;\n/** @internal */ export const RS_STENCIL_OP_ZFAIL = 18;\n/** @internal */ export const RS_STENCIL_OP_ZPASS = 19;\n/** @internal */ export const RS_COLOR_MASK = 20;\n/** @internal Offset from an ACTUAL slot (`0..20`) to its DESIRED twin (`21..41`). */\nexport const RS_DESIRED = 21;\n/* Standalone cached gl.clearColor RGBA slots (`42..45`) — NO desired twin; a\n * simple apply-on-clear cache like viewport/scissor, stored in `rs` (not as named\n * GLState fields) so the index access mangles small instead of shipping\n * `.clearColorR` verbatim in every bundle. */\n/** @internal */ export const RS_CLEAR_R = 42;\n/** @internal */ export const RS_CLEAR_G = 43;\n/** @internal */ export const RS_CLEAR_B = 44;\n/** @internal */ export const RS_CLEAR_A = 45;\n\n/**\n * GL-state cache type. Owned by `GLEngineContext._state`.\n *\n * Two flavours of cached state coexist here:\n *\n * - **Eager bindings** (program / buffers / textures / VAO / framebuffer /\n * viewport / scissor / unpack). Each binding setter issues its `gl.*` call\n * immediately and updates the matching field in lock-step, eliding the call\n * when the cache already matches.\n * - **Deferred render-state** (blend / depth / cull / stencil / color-mask),\n * stored in the {@link GLState.rs} index-array. These follow Babylon's\n * `applyStates()` model: each setter records only the DESIRED slot\n * (`rs[RS_X + RS_DESIRED]`) and sets `statesDirty`; the real `gl.*` calls are\n * flushed by {@link applyGLStates} (apply-states.ts) immediately before each\n * draw / clear, reconciling DESIRED → ACTUAL and writing the actual slots\n * (`rs[RS_X]`) in lock-step. Both halves keep their `-1`/`0` unset sentinels.\n *\n * See `00-lite-gl.md` §4 for the full table of cached operations and the\n * deferred-state flush sites.\n *\n * INVARIANTS:\n * - The cache is the source of truth. If consumers poke `engine.gl.*` directly\n * they will silently corrupt this state.\n * - On `webglcontextlost` the whole `rs` array (both the actual and desired\n * halves) is reset to its initial sentinels (handles are dead anyway;\n * subsequent setters bail out on `engine._isLost`, and a post-restore setter\n * re-marks `statesDirty`).\n */\nexport interface GLState {\n currentProgram: WebGLProgram | null;\n activeTextureUnit: number;\n /** Per-unit TEXTURE_2D binding; length === caps.maxTextureUnits. */\n boundTextures: (WebGLTexture | null)[];\n /** Per-unit TEXTURE_3D binding, allocated only when first used. @internal */\n _boundTextures3D?: (WebGLTexture | null | undefined)[];\n /** Cached zero WebGL2 unpack row/image/skip layout for 3D uploads. @internal */\n _unpack3DLayoutKnown?: boolean;\n boundArrayBuffer: WebGLBuffer | null;\n boundElementBuffer: WebGLBuffer | null;\n boundVao: WebGLVertexArrayObject | null;\n viewportX: number;\n viewportY: number;\n viewportW: number;\n viewportH: number;\n /**\n * Currently-bound draw framebuffer, or `null` for the default (canvas)\n * framebuffer. Owned by the render-target module's `bindRenderTarget`\n * (binding `null` returns to the canvas). Reset to `null` on context-lost.\n */\n boundFramebuffer: WebGLFramebuffer | null;\n /**\n * Deferred render-state (blend / depth / cull / stencil / color-mask) packed\n * into a flat `Float64Array(46)`. Slots `0..20` (indexed by the `RS_*`\n * consts) are the ACTUAL applied GL state — what {@link applyGLStates} last\n * wrote to the context; slots `21..41` (`rs[RS_X + RS_DESIRED]`) are the\n * DESIRED twin the setters record. The setters write ONLY the desired half\n * (never `gl.*`, never the actual half) and raise `statesDirty`;\n * `applyGLStates` reconciles each desired → its actual twin right before a\n * draw / clear, issuing only the GL calls that changed and updating the\n * actual half in lock-step. Both preset and arbitrary blend paths feed the\n * same desired slots, so they can never desync.\n *\n * Sentinels (identical for both halves): `-1` for the tri-state enables\n * (`RS_BLEND_ENABLED` / `RS_DEPTH_TEST` / `RS_DEPTH_MASK` / `RS_CULL_ENABLED`\n * / `RS_STENCIL_TEST`) and the mask caches (`RS_STENCIL_MASK` /\n * `RS_COLOR_MASK`), plus the leading stencil-op slot\n * (`RS_STENCIL_OP_FAIL`); `0` for every other func / equation / op / ref\n * slot. The leading op sentinel lets the first op\n * setter seed omitted fields to WebGL's `KEEP` defaults before merging. An\n * unset desired equals its unset actual and is never flushed; the `-1`\n * blend/test sentinels guarantee the first applied state is never elided.\n * The blend func/equation slots are only trusted while `RS_BLEND_ENABLED` is\n * `1` — the disabled→enabled transition re-issues both (matching Babylon's\n * `AlphaState`, which does not track them while blending is off).\n *\n * `setStencilOpSeparate` lazily replaces this array with a 52-slot copy; the\n * six appended slots cache actual and desired back-face operations without\n * moving any base index.\n *\n * Float64 (not Int32): `RS_STENCIL_MASK` / `RS_STENCIL_FUNC_MASK` can be\n * `0xFFFFFFFF`, which Int32 stores as `-1` — colliding with the `-1` unset\n * sentinel. Reset on context-lost. */\n rs: Float64Array;\n /** `true` when at least one deferred-state setter ran since the last\n * {@link applyGLStates}. Gates the flush so an unchanged frame issues no\n * reconciliation work. */\n statesDirty: boolean;\n /* ─── Deferred render-state appliers (per-category, lazily installed) ──────\n * Each category's reconciler (blend / depth+cull / stencil / color-mask) is\n * installed onto its slot the first time the matching setter runs — a runtime\n * assignment, NOT a module-level side effect. `applyGLStates` dispatches ONLY\n * through these slots, so the reconcilers (and their GL reconciliation code)\n * are reachable only when their setter is in the bundle: a scene that never\n * touches a category tree-shakes its reconciler out entirely (e.g. a clear-\n * only scene drops all four). Left undefined until installed; never cleared on\n * context-lost (a post-restore setter re-installs idempotently). */\n /** @internal Blend reconciler (Babylon's `_alphaState`). */\n _flushBlend?: (engine: GLEngineContext) => void;\n /** @internal Depth + cull reconciler (Babylon's `_depthCullingState`). */\n _flushDepthCull?: (engine: GLEngineContext) => void;\n /** @internal Stencil reconciler (Babylon's `_stencilState`). */\n _flushStencil?: (engine: GLEngineContext) => void;\n /** @internal Lazy hook that mirrors shared stencil operations to the back face. */\n _setStencilBack?: (cache: GLState, state: { opFail?: GLenum; opZFail?: GLenum; opZPass?: GLenum }) => void;\n /** @internal Color-write-mask reconciler (Babylon's `setColorWrite`). */\n _flushColorMask?: (engine: GLEngineContext) => void;\n /** Scissor-test enable tri-state (`-1` unset, `0` off, `1` on). */\n scissorEnabled: number;\n scissorX: number;\n scissorY: number;\n scissorW: number;\n scissorH: number;\n /** Cached `gl.pixelStorei(UNPACK_ALIGNMENT)`, or `-1` when unset. */\n unpackAlignment: number;\n /** Cached `gl.pixelStorei(UNPACK_FLIP_Y_WEBGL)`, or `-1` when unset. */\n unpackFlipY: number;\n /** Cached `gl.pixelStorei(UNPACK_PREMULTIPLY_ALPHA_WEBGL)`, or `-1` unset. */\n unpackPremultiplyAlpha: number;\n /**\n * Per-location vertex-attribute enable flags for the DEFAULT (null) VAO —\n * the mesh / instancing path (mirrors Babylon's `_vertexAttribArraysEnabled`).\n * Index is the attribute location. lite-gl's quad / sprite paths use their\n * own VAOs and do not touch this. Cleared on context-lost.\n */\n enabledAttribs: boolean[];\n /**\n * Attribute locations currently configured with a non-default vertex divisor\n * (instanced attributes), mirroring Babylon's `_currentInstanceLocations`.\n * Each location is recorded once, so repeated binds without an unbind stay bounded.\n * `unbindInstanceAttributes` resets each back to divisor 0 and clears this.\n */\n instanceLocations: number[];\n /** Shared fullscreen quad — lazily created on first `drawEffect`. */\n quadVbo: WebGLBuffer | null;\n quadIbo: WebGLBuffer | null;\n quadVao: WebGLVertexArrayObject | null;\n}\n\n/** Indices in `rs` whose unset sentinel is `-1` (the tri-state enables, the\n * `stencilMask` / `colorMask` caches, and the leading shared stencil-op slot).\n * Every other slot defaults to `0`. The sentinel is written to BOTH\n * the actual (`i`) and desired (`i + RS_DESIRED`) halves. Kept as a\n * function-local literal so it stays a runtime value (no module-level\n * allocation / side effect). */\nfunction applyRenderStateSentinels(rs: Float64Array): void {\n for (const i of [RS_BLEND_ENABLED, RS_DEPTH_TEST, RS_DEPTH_MASK, RS_CULL_ENABLED, RS_STENCIL_TEST, RS_STENCIL_MASK, RS_STENCIL_OP_FAIL, RS_COLOR_MASK]) {\n rs[i] = -1;\n rs[i + RS_DESIRED] = -1;\n }\n // clearColor RGBA (standalone, no DESIRED twin) — `-1` forces the first clear\n // to issue gl.clearColor (valid components are 0..1).\n rs[RS_CLEAR_R] = rs[RS_CLEAR_G] = rs[RS_CLEAR_B] = rs[RS_CLEAR_A] = -1;\n}\n\n/** Allocate the 46-slot deferred render-state array (21 actual + 21 desired + 4\n * standalone clearColor) initialised to its unset sentinels — a fresh\n * `Float64Array` is already all `0`, so only the `-1` slots need writing. */\nfunction createRenderStateArray(): Float64Array {\n const rs = new Float64Array(46);\n applyRenderStateSentinels(rs);\n return rs;\n}\n\n/** Re-initialise a live render-state array in place: zero every slot, then\n * restore the `-1` sentinels. */\nfunction resetRenderStateArray(rs: Float64Array): void {\n rs.fill(0);\n applyRenderStateSentinels(rs);\n}\n\n/** Allocate a fresh, fully-null GLState sized for `maxTextureUnits`. */\nexport function createGLState(maxTextureUnits: number): GLState {\n return {\n currentProgram: null,\n activeTextureUnit: 0,\n boundTextures: new Array<WebGLTexture | null>(maxTextureUnits).fill(null),\n boundArrayBuffer: null,\n boundElementBuffer: null,\n boundVao: null,\n viewportX: 0,\n viewportY: 0,\n viewportW: 0,\n viewportH: 0,\n boundFramebuffer: null,\n rs: createRenderStateArray(),\n statesDirty: false,\n scissorEnabled: -1,\n scissorX: 0,\n scissorY: 0,\n scissorW: 0,\n scissorH: 0,\n unpackAlignment: -1,\n unpackFlipY: -1,\n unpackPremultiplyAlpha: -1,\n enabledAttribs: [],\n instanceLocations: [],\n quadVbo: null,\n quadIbo: null,\n quadVao: null,\n };\n}\n\n/** Reset only the cached \"current GL state\" — every binding (program / buffers /\n * textures / VAO / framebuffer) and render-state (blend / depth / stencil /\n * scissor / color-mask / viewport / unpack) field, including the whole `rs`\n * deferred render-state array (BOTH the actual applied values and the DESIRED\n * twins) plus `statesDirty` — to its unset sentinel, WITHOUT discarding owned\n * GPU resources (the shared quad). After this, the next setter in each category\n * is re-issued rather than elided.\n *\n * Used by `resetGLState` (context-lost) and by `wipeGLStateCache` (a host that\n * shares the GL context calling in after mutating raw `gl.*` state). The shared\n * quad's GL objects are still alive in the latter case, so they are preserved\n * here to avoid leaking + needlessly rebuilding them every render scope. */\nexport function resetGLStateCache(state: GLState): void {\n state.currentProgram = null;\n state.activeTextureUnit = 0;\n state.boundTextures.fill(null);\n state.boundArrayBuffer = null;\n state.boundElementBuffer = null;\n state.boundVao = null;\n state.viewportX = 0;\n state.viewportY = 0;\n state.viewportW = 0;\n state.viewportH = 0;\n state.boundFramebuffer = null;\n resetRenderStateArray(state.rs);\n state.statesDirty = false;\n state.scissorEnabled = -1;\n state.scissorX = 0;\n state.scissorY = 0;\n state.scissorW = 0;\n state.scissorH = 0;\n state.unpackAlignment = -1;\n state.unpackFlipY = -1;\n state.unpackPremultiplyAlpha = -1;\n state.enabledAttribs.length = 0;\n state.instanceLocations.length = 0;\n}\n\n/** Zero the cache in-place. Used by the context-lost handler — GL handles are\n * already dead per WebGL spec; we forget what we knew about them (including the\n * shared quad, whose GL objects are gone and must be rebuilt) so the next\n * bind/use after restore is NOT incorrectly elided. */\nexport function resetGLState(state: GLState): void {\n resetGLStateCache(state);\n state.quadVbo = null;\n state.quadIbo = null;\n state.quadVao = null;\n}\n"]}
|
package/text/_gpu/text-effect.js
CHANGED
|
@@ -28,9 +28,9 @@ export function createTextProgram(engine, shader) {
|
|
|
28
28
|
return program;
|
|
29
29
|
}
|
|
30
30
|
/** @internal Skip unchanged projection work and uploads; relink always invalidates the cache. */
|
|
31
|
-
export function uploadTextUniforms(
|
|
31
|
+
export function uploadTextUniforms(program, layer, width, height) {
|
|
32
32
|
const effect = program._effect;
|
|
33
|
-
useEffect(
|
|
33
|
+
useEffect(effect);
|
|
34
34
|
const inputs = program._mvpInputs;
|
|
35
35
|
const px = layer.positionPx.x;
|
|
36
36
|
const py = layer.positionPx.y;
|
|
@@ -55,7 +55,7 @@ export function uploadTextUniforms(engine, program, layer, width, height) {
|
|
|
55
55
|
mvp[10] = mvp[15] = 1;
|
|
56
56
|
mvp[12] = (2 * px) / width - 1;
|
|
57
57
|
mvp[13] = 1 - (2 * py) / height;
|
|
58
|
-
setEffectMatrix(
|
|
58
|
+
setEffectMatrix(effect, "mvp", mvp);
|
|
59
59
|
inputs[0] = px;
|
|
60
60
|
inputs[1] = py;
|
|
61
61
|
inputs[2] = rotation;
|
|
@@ -64,7 +64,7 @@ export function uploadTextUniforms(engine, program, layer, width, height) {
|
|
|
64
64
|
inputs[5] = height;
|
|
65
65
|
program._uploadedProgram = effect.program;
|
|
66
66
|
}
|
|
67
|
-
setEffectFloat4(
|
|
68
|
-
setEffectFloat4(
|
|
67
|
+
setEffectFloat4(effect, "viewport", width, height, 0, 0);
|
|
68
|
+
setEffectFloat4(effect, "color", layer.coverageGamma > 0 ? 1 / layer.coverageGamma : 1, 1, 1, layer.opacity);
|
|
69
69
|
}
|
|
70
70
|
//# sourceMappingURL=text-effect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text-effect.js","sourceRoot":"","sources":["../../../src/text/_gpu/text-effect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5F,OAAO,EAAE,iBAAiB,EAAE,M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AAe,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;AACjH,CAAC","sourcesContent":["import type { GLEngineContext } from \"../../context.js\";\nimport { createEffect, setEffectFloat4, setEffectMatrix, useEffect } from \"../../effect.js\";\nimport type { GLEffect } from \"../../effect.js\";\nimport type { GLTextLayer } from \"../text-renderer.js\";\nimport { composeSlugShader } from \"../shaders/slug-shader.js\";\nimport type { ComposedSlugShader } from \"../shaders/slug-shader.js\";\n\n/** @internal Uniform caches belong to the shared program, not an individual layer/renderer. */\nexport interface TextProgram {\n /** @internal */\n _effect: GLEffect;\n /** @internal */\n _uploadedProgram: WebGLProgram | null;\n /** @internal */\n _mvpInputs: Float64Array;\n /** @internal */\n _mvp: Float32Array;\n}\n\nlet programs: WeakMap<GLEffect, TextProgram> | null = null;\nlet baseShader: ComposedSlugShader | null = null;\n\n/** @internal Optional feature-owned variant factory. */\nexport let _createTextVariant: ((engine: GLEngineContext) => TextProgram) | null = null;\n\n/** @internal */\nexport function _installTextVariantResolver(factory: (engine: GLEngineContext) => TextProgram): void {\n _createTextVariant = factory;\n}\n\n/** @internal Acquires one effect reference for this renderer. */\nexport function createTextProgram(engine: GLEngineContext, shader?: ComposedSlugShader): TextProgram {\n const source = shader ?? (baseShader ??= composeSlugShader(null));\n const effect = createEffect(engine, {\n name: \"text-slug\" + source._key,\n vertexSource: source._vert,\n fragmentSource: source._frag,\n uniformNames: [\"mvp\", \"viewport\", \"color\"],\n samplerNames: [\"curveTex\", \"bandTex\", \"glyphMetadata\", \"styles\"],\n attributeNames: [\"corner\", \"anchor\", \"glyphStyle\"],\n });\n const cache = (programs ??= new WeakMap());\n let program = cache.get(effect);\n if (!program) {\n program = { _effect: effect, _uploadedProgram: null, _mvpInputs: new Float64Array(6), _mvp: new Float32Array(16) };\n cache.set(effect, program);\n }\n return program;\n}\n\n/** @internal Skip unchanged projection work and uploads; relink always invalidates the cache. */\nexport function uploadTextUniforms(program: TextProgram, layer: GLTextLayer, width: number, height: number): void {\n const effect = program._effect;\n useEffect(effect);\n const inputs = program._mvpInputs;\n const px = layer.positionPx.x;\n const py = layer.positionPx.y;\n const rotation = layer.rotationRad;\n const scale = layer.scale;\n if (\n program._uploadedProgram !== effect.program ||\n inputs[0] !== px ||\n inputs[1] !== py ||\n inputs[2] !== rotation ||\n inputs[3] !== scale ||\n inputs[4] !== width ||\n inputs[5] !== height\n ) {\n const mvp = program._mvp;\n const cx = (2 * scale) / width;\n const cy = (2 * scale) / height;\n const cr = Math.cos(rotation);\n const sr = Math.sin(rotation);\n mvp[0] = cx * cr;\n mvp[1] = -cy * sr;\n mvp[4] = cx * sr;\n mvp[5] = cy * cr;\n mvp[10] = mvp[15] = 1;\n mvp[12] = (2 * px) / width - 1;\n mvp[13] = 1 - (2 * py) / height;\n setEffectMatrix(effect, \"mvp\", mvp);\n inputs[0] = px;\n inputs[1] = py;\n inputs[2] = rotation;\n inputs[3] = scale;\n inputs[4] = width;\n inputs[5] = height;\n program._uploadedProgram = effect.program;\n }\n setEffectFloat4(effect, \"viewport\", width, height, 0, 0);\n setEffectFloat4(effect, \"color\", layer.coverageGamma > 0 ? 1 / layer.coverageGamma : 1, 1, 1, layer.opacity);\n}\n"]}
|
|
@@ -22,14 +22,14 @@ export function ensureTextDataGpu(engine, data) {
|
|
|
22
22
|
data._gpu = gpu;
|
|
23
23
|
}
|
|
24
24
|
catch (error) {
|
|
25
|
-
disposeBuffer(
|
|
25
|
+
disposeBuffer(buffer);
|
|
26
26
|
throw error;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
else if (gpu._instanceBuf._data !== data._instances) {
|
|
30
30
|
// Retain the live CPU pool, including partial edits, for context restoration.
|
|
31
31
|
const buffer = createVertexBuffer(engine, data._instances, true);
|
|
32
|
-
disposeBuffer(
|
|
32
|
+
disposeBuffer(gpu._instanceBuf);
|
|
33
33
|
gpu._instanceBuf = buffer;
|
|
34
34
|
gpu._uploadedVersion = data._version;
|
|
35
35
|
}
|
|
@@ -38,10 +38,10 @@ export function ensureTextDataGpu(engine, data) {
|
|
|
38
38
|
const start = data._dirtyStart * TEXT_INSTANCE_FLOATS;
|
|
39
39
|
const end = data._dirtyEnd * TEXT_INSTANCE_FLOATS;
|
|
40
40
|
const source = start === 0 && end === data._instances.length ? data._instances : data._instances.subarray(start, end);
|
|
41
|
-
updateVertexBuffer(
|
|
41
|
+
updateVertexBuffer(gpu._instanceBuf, source, data._dirtyStart * TEXT_INSTANCE_BYTES);
|
|
42
42
|
}
|
|
43
43
|
else {
|
|
44
|
-
updateVertexBuffer(
|
|
44
|
+
updateVertexBuffer(gpu._instanceBuf, data._instances);
|
|
45
45
|
}
|
|
46
46
|
gpu._uploadedVersion = data._version;
|
|
47
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text-instances.js","sourceRoot":"","sources":["../../../src/text/_gpu/text-instances.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEtF,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC/F,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAElG,uFAAuF;AACvF,MAAM,UAAU,iBAAiB,CAAC,MAAuB,EAAE,IAAgB;IACvE,IAAI,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC;IACpB,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,KAAK,MAAM,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,oGAAoG,CAAC,CAAC;IAC1H,CAAC;IACD,IAAI,CAAC,GAAG,EAAE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../../mesh.js\";\nimport type { GLTextData, TextDataGpu } from \"../text-data.js\";\nimport { TEXT_INSTANCE_BYTES, TEXT_INSTANCE_FLOATS, TEXT_STYLE_FLOATS } from \"../text-data.js\";\nimport { createTextTexture, packTable, TABLE_WIDTH, uploadTextTexture } from \"./text-textures.js\";\n\n/** @internal One upload per data mutation, even when several layers share the data. */\nexport function ensureTextDataGpu(engine: GLEngineContext, data: GLTextData): TextDataGpu {\n let gpu = data._gpu;\n if (gpu && gpu._engine !== engine) {\n throw new Error(\"lite-gl: text data cannot be drawn on multiple engines. Create separate text data for each engine.\");\n }\n if (!gpu) {\n const pixels = packTable(data._styles, data._styleCount * TEXT_STYLE_FLOATS);\n const buffer = createVertexBuffer(engine, data._instances, true);\n try {\n gpu = {\n _engine: engine,\n _instanceBuf: buffer,\n _styleTex: createTextTexture(engine, pixels, TABLE_WIDTH, pixels.length / (TABLE_WIDTH * 4)),\n _stylePixels: pixels,\n _uploadedVersion: data._version,\n _uploadedStyleVersion: data._styleVersion,\n };\n data._gpu = gpu;\n } catch (error) {\n disposeBuffer(buffer);\n throw error;\n }\n } else if (gpu._instanceBuf._data !== data._instances) {\n // Retain the live CPU pool, including partial edits, for context restoration.\n const buffer = createVertexBuffer(engine, data._instances, true);\n disposeBuffer(gpu._instanceBuf);\n gpu._instanceBuf = buffer;\n gpu._uploadedVersion = data._version;\n } else if (gpu._uploadedVersion !== data._version) {\n if (data._dirtyEnd > data._dirtyStart) {\n const start = data._dirtyStart * TEXT_INSTANCE_FLOATS;\n const end = data._dirtyEnd * TEXT_INSTANCE_FLOATS;\n const source = start === 0 && end === data._instances.length ? data._instances : data._instances.subarray(start, end);\n updateVertexBuffer(gpu._instanceBuf, source, data._dirtyStart * TEXT_INSTANCE_BYTES);\n } else {\n updateVertexBuffer(gpu._instanceBuf, data._instances);\n }\n gpu._uploadedVersion = data._version;\n }\n data._dirtyStart = data._dirtyEnd = 0;\n if (gpu._uploadedStyleVersion !== data._styleVersion) {\n const pixels = packTable(data._styles, data._styleCount * TEXT_STYLE_FLOATS, gpu._stylePixels);\n uploadTextTexture(engine, gpu._styleTex, pixels, TABLE_WIDTH, pixels.length / (TABLE_WIDTH * 4));\n gpu._stylePixels = pixels;\n gpu._uploadedStyleVersion = data._styleVersion;\n }\n return gpu;\n}\n"]}
|
|
@@ -19,7 +19,9 @@ export function createTextTexture(engine, pixels, width, height) {
|
|
|
19
19
|
checkSize(engine, width, height);
|
|
20
20
|
const gl = engine.gl;
|
|
21
21
|
const integer = pixels instanceof Uint32Array;
|
|
22
|
-
return createRawTexture(engine, pixels, width, height,
|
|
22
|
+
return createRawTexture(engine, pixels, width, height, {
|
|
23
|
+
format: integer ? gl.RG_INTEGER : gl.RGBA,
|
|
24
|
+
type: integer ? gl.UNSIGNED_INT : gl.FLOAT,
|
|
23
25
|
internalFormat: integer ? gl.RG32UI : gl.RGBA32F,
|
|
24
26
|
minFilter: gl.NEAREST,
|
|
25
27
|
magFilter: gl.NEAREST,
|
|
@@ -28,7 +30,7 @@ export function createTextTexture(engine, pixels, width, height) {
|
|
|
28
30
|
/** @internal Preserve the texture object and its context-restore upload source. */
|
|
29
31
|
export function uploadTextTexture(engine, texture, pixels, width, height) {
|
|
30
32
|
checkSize(engine, width, height);
|
|
31
|
-
updateRawTexture(
|
|
33
|
+
updateRawTexture(texture, pixels, { width, height });
|
|
32
34
|
}
|
|
33
35
|
/** @internal Atlas resources are shared by every block using the same curve set. */
|
|
34
36
|
export function ensureSharedAtlasGpu(engine, atlas) {
|
|
@@ -65,7 +67,7 @@ export function ensureSharedAtlasGpu(engine, atlas) {
|
|
|
65
67
|
}
|
|
66
68
|
catch (error) {
|
|
67
69
|
for (const texture of textures) {
|
|
68
|
-
disposeTexture(
|
|
70
|
+
disposeTexture(texture);
|
|
69
71
|
}
|
|
70
72
|
throw error;
|
|
71
73
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text-textures.js","sourceRoot":"","sources":["../../../src/text/_gpu/text-text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.js\";\nimport type { GLTexture } from \"../../texture.js\";\nimport { GLYPH_METADATA_FLOATS, TEX_WIDTH } from \"../glyph-storage.js\";\nimport type { SharedAtlas, SharedAtlasGpu } from \"../glyph-storage.js\";\n\n/** @internal Lookup textures replace the WebGPU metadata/style storage buffers. */\nexport const TABLE_WIDTH = 256;\n\n/** @internal Pad a lookup table to complete rows, retaining its existing allocation. */\nexport function packTable(source: Float32Array, floatCount: number, previous?: Float32Array): Float32Array {\n const length = Math.max(1, Math.ceil(floatCount / (TABLE_WIDTH * 4))) * TABLE_WIDTH * 4;\n const pixels = previous && previous.length >= length ? previous : new Float32Array(length);\n pixels.set(source.subarray(0, floatCount));\n return pixels;\n}\n\nfunction checkSize(engine: GLEngineContext, width: number, height: number): void {\n if (width > engine.caps.maxTextureSize || height > engine.caps.maxTextureSize) {\n throw new Error(`lite-gl: text texture ${width}x${height} exceeds MAX_TEXTURE_SIZE ${engine.caps.maxTextureSize}.`);\n }\n}\n\n/** @internal Numeric tables use nearest-only RG uint or RGBA float texels. */\nexport function createTextTexture(engine: GLEngineContext, pixels: Float32Array | Uint32Array, width: number, height: number): GLTexture {\n checkSize(engine, width, height);\n const gl = engine.gl;\n const integer = pixels instanceof Uint32Array;\n return createRawTexture(engine, pixels, width, height, {\n format: integer ? gl.RG_INTEGER : gl.RGBA,\n type: integer ? gl.UNSIGNED_INT : gl.FLOAT,\n internalFormat: integer ? gl.RG32UI : gl.RGBA32F,\n minFilter: gl.NEAREST,\n magFilter: gl.NEAREST,\n });\n}\n\n/** @internal Preserve the texture object and its context-restore upload source. */\nexport function uploadTextTexture(engine: GLEngineContext, texture: GLTexture, pixels: Float32Array | Uint32Array, width: number, height: number): void {\n checkSize(engine, width, height);\n updateRawTexture(texture, pixels, { width, height });\n}\n\n/** @internal Atlas resources are shared by every block using the same curve set. */\nexport function ensureSharedAtlasGpu(engine: GLEngineContext, atlas: SharedAtlas): SharedAtlasGpu {\n let gpu = atlas._gpu;\n if (gpu) {\n if (gpu._engine !== engine) {\n throw new Error(\"lite-gl: a glyph storage cannot be drawn on multiple engines. Create a separate storage for each engine.\");\n }\n if (gpu._uploadedVersion === atlas._version) {\n return gpu;\n }\n }\n const curveRows = Math.max(1, Math.ceil(atlas._curveTexelsUsed / TEX_WIDTH));\n const bandRows = Math.max(1, Math.ceil(atlas._bandTexelsUsed / TEX_WIDTH));\n checkSize(engine, TEX_WIDTH, Math.max(curveRows, bandRows));\n const metaPixels = packTable(atlas._metaData, atlas._slotCount * GLYPH_METADATA_FLOATS, gpu?._metaPixels);\n const metaRows = metaPixels.length / (TABLE_WIDTH * 4);\n checkSize(engine, TABLE_WIDTH, metaRows);\n\n if (!gpu) {\n const textures: GLTexture[] = [];\n try {\n textures.push(createTextTexture(engine, atlas._curveTexData, TEX_WIDTH, curveRows));\n textures.push(createTextTexture(engine, atlas._bandTexData, TEX_WIDTH, bandRows));\n textures.push(createTextTexture(engine, metaPixels, TABLE_WIDTH, metaRows));\n gpu = {\n _engine: engine,\n _curveTex: textures[0]!,\n _bandTex: textures[1]!,\n _metaTex: textures[2]!,\n _metaPixels: metaPixels,\n _uploadedVersion: atlas._version,\n };\n atlas._gpu = gpu;\n } catch (error) {\n for (const texture of textures) {\n disposeTexture(texture);\n }\n throw error;\n }\n } else {\n uploadTextTexture(engine, gpu._curveTex, atlas._curveTexData, TEX_WIDTH, curveRows);\n uploadTextTexture(engine, gpu._bandTex, atlas._bandTexData, TEX_WIDTH, bandRows);\n uploadTextTexture(engine, gpu._metaTex, metaPixels, TABLE_WIDTH, metaRows);\n gpu._metaPixels = metaPixels;\n gpu._uploadedVersion = atlas._version;\n }\n return gpu;\n}\n"]}
|
package/text/glyph-storage.js
CHANGED
|
@@ -72,9 +72,9 @@ export function disposeGlyphStorage(storage) {
|
|
|
72
72
|
for (const cs of storage._curveSets.values()) {
|
|
73
73
|
const gpu = cs._atlas._gpu;
|
|
74
74
|
if (gpu) {
|
|
75
|
-
disposeTexture(gpu.
|
|
76
|
-
disposeTexture(gpu.
|
|
77
|
-
disposeTexture(gpu.
|
|
75
|
+
disposeTexture(gpu._curveTex);
|
|
76
|
+
disposeTexture(gpu._bandTex);
|
|
77
|
+
disposeTexture(gpu._metaTex);
|
|
78
78
|
cs._atlas._gpu = null;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"glyph-storage.js","sourceRoot":"","sources":["../../src/text/glyph-storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAsD/C,6EAA6E;AAC7E,mFAAmF;AACnF,qFAAqF;AACrF,gBAAgB;AAEhB,6DAA6D;AAC7D,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,CAAC;AAkB9B;;;;;wFAKwF;AACxF,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AA8DxC,6EAA6E;AAE7E;;yFAEyF;AACzF,MAAM,UAAU,kBAAkB,CAAC,OAAuD;IACtF,MAAM,UAAU,GAAG,IAAI,GAAG,EAAsC,CAAC;IACjE,IAAI,OAAO,EAAE,CAAC;QACV,KAAK,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;YACzC,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;QACrD,CAAC;IACL,CAAC;IACD,OAAO,EAAE,UAAU,EAA+B,CAAC;AACvD,CAAC;AAED;;;kBAGkB;AAClB,MAAM,UAAU,kBAAkB,CAAC,OAAuB,EAAE,UAAwB,EAAE,MAA0C;IAC5H,IAAI,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC5C,IAAI,CAAC,EAAE,EAAE,CAAC;QACN,EAAE,GAAG,YAAY,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;QAC7B,OAAO,CAAC,UAA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E,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;QAC/E,CAAC,CAAC,CAAC;IACP,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AAC9F,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,eAAe,CAAC,CAAgB;IAC5C,OAAO,CAAC,CAAC,CAAC,MAAM,KAAK,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC","sourcesContent":["/** Glyph storage: per-curve-set CPU outline catalog plus the GPU atlas packed from it.\n *\n * Layered:\n * - `GLGlyphStorage` is the opaque public handle. Holds one or more curve-sets keyed by\n * `GLCurveSetId` (typically a font family name). Each curve-set owns its glyph\n * outlines plus the `SharedAtlas` packed from them.\n * - `SharedAtlas` stages float32 curve control points and uint32 band headers/\n * curve-reference lists in append-only RGBA and RG arrays, respectively.\n * - Atlas packing (`packAppendGlyph`) and spatial-band partitioning (`buildGlyphBands`)\n * live here as internal helpers — they implement the storage's invariants and are\n * not callable from outside the module.\n * - GPU creation/upload (`SharedAtlasGpu`, `ensureSharedAtlasGpu`) lives in\n * `_gpu/text-textures.ts`; the shared types are exported from here. GPU teardown\n * is performed inline in `disposeGlyphStorage` to avoid a circular import edge.\n *\n * Lifetime is caller-owned (matches `Texture2D` semantics):\n * - `createGlyphStorage(initial?)` allocates a fresh storage, optionally seeded.\n * - `updateGlyphStorage(storage, curveSetId, curves)` adds glyphs (creating the\n * curve-set on demand). Glyph ids already present are skipped.\n * - `disposeGlyphStorage(storage)` releases every atlas. The caller must ensure no\n * `GLTextData` is still drawing from it — using a disposed storage is undefined\n * behavior. Idempotent.\n */\n\nimport type { GLEngineContext } from \"../context.js\";\nimport type { GLTexture } from \"../texture.js\";\nimport { disposeTexture } from \"../texture.js\";\n\ndeclare const glyphStorageBrand: unique symbol;\n\n// ─── Glyph outline geometry (public value types) ──────────────────────\n//\n// These describe the input contract for `updateGlyphStorage` /\n// `createGlyphStorage`. Live here (not with the default extraction module) so a\n// caller bringing their own outline source (DirectWrite, FreeType, hand-rolled)\n// can produce `GLGlyphCurves` values without importing `glyph-extraction.ts` or\n// pulling `text-shaper` into their bundle.\n\n/** Quadratic Bézier curve describing one segment of a glyph outline in font units. */\nexport type GLQuadCurve = {\n readonly p0x: number;\n readonly p0y: number;\n readonly p1x: number;\n readonly p1y: number;\n readonly p2x: number;\n readonly p2y: number;\n};\n\n/** Axis-aligned glyph extents in font units, used to size the rendered quad and spatial curve bands. */\nexport type GLGlyphBounds = {\n readonly xMin: number;\n readonly yMin: number;\n readonly xMax: number;\n readonly yMax: number;\n};\n\n/** Complete outline data for one glyph id, ready to be packed into a `GLGlyphStorage` atlas. */\nexport type GLGlyphCurves = {\n readonly glyphId: number;\n readonly curves: readonly GLQuadCurve[];\n readonly bounds: GLGlyphBounds;\n /** @internal Lazily-computed band partitioning (memoized by `buildGlyphBands`). */\n _bands?: GlyphBands;\n};\n\n// ─── Public types ─────────────────────────────────────────────────────────\n\n/** Identifier for a curve set (a font's glyph-curves map). Strings let callers use a\n * human-readable key (e.g. the font face name) for easy debugging. */\nexport type GLCurveSetId = string;\n\n/** Opaque bundle of glyph outlines (organized by curve-set) and the GPU atlases packed\n * from them. Holds an arbitrary number of curve-sets — each curve-set gets its own atlas.\n * Shared by reference across any number of `GLTextData`s that need the same glyph catalog. */\nexport interface GLGlyphStorage {\n readonly [glyphStorageBrand]: true;\n /** @internal Per-curve-set glyph outlines + the SharedAtlas they're packed into. */\n _curveSets: Map<GLCurveSetId, GlyphStorageCurveSet>;\n}\n\n// ─── Internal supporting types ────────────────────────────────────────────\n// Tagged `@internal` on the type itself so the d.ts trim pass strips them from the\n// published types. Fields still use `_` prefixes so production property mangling can\n// shorten them.\n\n/** @internal Width of the curve / band textures (texels). */\nexport const TEX_WIDTH = 4096;\n\n/** @internal Per-curve-set entry within a GLGlyphStorage. */\nexport type GlyphStorageCurveSet = {\n /** @internal */\n _curves: Map<number, GLGlyphCurves>;\n /** @internal */\n _atlas: SharedAtlas;\n};\n\n/** @internal Atlas slot for a single glyph inside a SharedAtlas. */\nexport type AtlasSlot = {\n /** @internal Dense index of this glyph's entry in `SharedAtlas._metaData`, and the value the vertex\n * shader uses to look it up in the GPU metadata texture. Slots are append-only and never\n * moved, so an index stays valid for the atlas's lifetime. */\n _index: number;\n};\n\n/** @internal Floats per glyph in `SharedAtlas._metaData`, laid out as three `vec4<f32>` to match\n * the shader's `GlyphMetadata`: bounds (xMin, yMin, xMax, yMax), atlas (glyphLocX, glyphLocY,\n * bandMaxX, bandMaxY), band (bandScaleX, bandScaleY, bandOffsetX, bandOffsetY).\n *\n * All twelve depend only on the glyph, so they live here — written once when the glyph is\n * appended — instead of being copied into every instance that references the glyph. */\nexport const GLYPH_METADATA_FLOATS = 12;\n\n/** @internal CPU + (lazy) GPU staging packed from a `GLGlyphStorage`'s glyph outlines.\n * One `SharedAtlas` per curve-set; lifetime is bound to the storage. */\nexport type SharedAtlas = {\n /** @internal Pooled curve texel staging (rgba32float, width 4096). */\n _curveTexData: Float32Array;\n /** @internal Number of curve texels actually used. */\n _curveTexelsUsed: number;\n /** @internal Pooled band texel staging (rg32uint, two components, width 4096). */\n _bandTexData: Uint32Array;\n /** @internal Number of band texels actually used. */\n _bandTexelsUsed: number;\n /** @internal Per-glyph atlas slot lookup. Slots are append-only and never moved. */\n _glyphSlots: Map<number, AtlasSlot>;\n /** @internal Glyph-invariant shader data, `GLYPH_METADATA_FLOATS` per slot, indexed by `AtlasSlot._index`.\n * Uploaded verbatim as the vertex shader's metadata lookup texture. */\n _metaData: Float32Array;\n /** @internal Number of slots appended so far; also the next `AtlasSlot._index`. */\n _slotCount: number;\n /** @internal Monotonic version bumped whenever a new glyph is appended. */\n _version: number;\n /** @internal Lazy GPU resources (one set per SharedAtlas; recreated only on capacity grow). */\n _gpu: SharedAtlasGpu | null;\n};\n\n/** @internal GPU-side companion to a `SharedAtlas`; populated lazily by\n * `ensureSharedAtlasGpu` in `_gpu/text-textures.ts`. */\nexport type SharedAtlasGpu = {\n /** @internal */\n _engine: GLEngineContext;\n /** @internal */\n _curveTex: GLTexture;\n /** @internal */\n _bandTex: GLTexture;\n /** @internal */\n _metaTex: GLTexture;\n /** @internal */\n _metaPixels: Float32Array;\n /** @internal */\n _uploadedVersion: number;\n};\n\n/** @internal Spatial-band partitioning for a glyph's curves. Memoized per `GLGlyphCurves`\n * via `GLGlyphCurves._bands`. */\nexport type GlyphBands = {\n /** @internal */\n _hBands: BandEntry[];\n /** @internal */\n _vBands: BandEntry[];\n /** @internal */\n _hBandCount: number;\n /** @internal */\n _vBandCount: number;\n};\n\n/** @internal */\nexport type BandEntry = {\n /** @internal */\n _curveIndices: number[];\n};\n\n// ─── Public API ───────────────────────────────────────────────────────────\n\n/** Build a `GLGlyphStorage`. If `initial` is provided, each curve-set is packed into its\n * own atlas synchronously. The passed inner maps are *adopted* by the storage — the\n * caller must not mutate them directly afterward (use `updateGlyphStorage` instead). */\nexport function createGlyphStorage(initial?: Map<GLCurveSetId, Map<number, GLGlyphCurves>>): GLGlyphStorage {\n const _curveSets = new Map<GLCurveSetId, GlyphStorageCurveSet>();\n if (initial) {\n for (const [curveSetId, curves] of initial) {\n _curveSets.set(curveSetId, makeCurveSet(curves));\n }\n }\n return { _curveSets } as unknown as GLGlyphStorage;\n}\n\n/** Add glyphs to the named curve-set, creating it if it doesn't exist yet. Glyph ids\n * already present in the curve-set are skipped (the existing outline + atlas slot wins).\n * Safe to call between frames: the atlas grows in place and the next render uploads the\n * new glyphs. */\nexport function updateGlyphStorage(storage: GLGlyphStorage, curveSetId: GLCurveSetId, curves: ReadonlyMap<number, GLGlyphCurves>): void {\n let cs = storage._curveSets.get(curveSetId);\n if (!cs) {\n cs = makeCurveSet(new Map());\n storage._curveSets.set(curveSetId, cs);\n }\n for (const [glyphId, glyph] of curves) {\n if (cs._curves.has(glyphId)) {\n continue;\n }\n cs._curves.set(glyphId, glyph);\n cs._atlas._glyphSlots.set(glyphId, packAppendGlyph(cs._atlas, glyph));\n }\n}\n\n/** Release every GPU atlas owned by `storage`. Idempotent. The caller is responsible for\n * ensuring no `GLTextData` is still drawing from this storage. */\nexport function disposeGlyphStorage(storage: GLGlyphStorage): void {\n for (const cs of storage._curveSets.values()) {\n const gpu = cs._atlas._gpu;\n if (gpu) {\n disposeTexture(gpu._engine, gpu._curveTex);\n disposeTexture(gpu._engine, gpu._bandTex);\n disposeTexture(gpu._engine, gpu._metaTex);\n cs._atlas._gpu = null;\n }\n }\n storage._curveSets.clear();\n}\n\n// ─── Internal: SharedAtlas construction + glyph packing ───────────────────\n\nconst ROW_COMPONENTS = TEX_WIDTH * 4;\n\n/** @internal Create an empty `SharedAtlas`. */\nexport function createSharedAtlas(): SharedAtlas {\n return {\n _curveTexData: new Float32Array(ROW_COMPONENTS),\n _curveTexelsUsed: 0,\n _bandTexData: new Uint32Array(TEX_WIDTH * 2),\n _bandTexelsUsed: 0,\n _glyphSlots: new Map(),\n _metaData: new Float32Array(GLYPH_METADATA_FLOATS * 16),\n _slotCount: 0,\n _version: 0,\n _gpu: null,\n };\n}\n\nfunction makeCurveSet(curves: Map<number, GLGlyphCurves>): GlyphStorageCurveSet {\n const atlas = createSharedAtlas();\n for (const [glyphId, glyph] of curves) {\n atlas._glyphSlots.set(glyphId, packAppendGlyph(atlas, glyph));\n }\n return { _curves: curves, _atlas: atlas };\n}\n\n/** Grow a texel-staging array to hold at least `neededTexels` texels,\n * rounded up to a whole 4096-texel row. Returns the same array when already large enough. */\nfunction ensureTexelCapacity<T extends Float32Array | Uint32Array>(current: T, neededTexels: number, ArrayType: new (length: number) => T, componentsPerTexel: 2 | 4 = 4): T {\n const neededComponents = neededTexels * componentsPerTexel;\n const rowComponents = TEX_WIDTH * componentsPerTexel;\n if (current.length >= neededComponents) {\n return current;\n }\n let newLength = Math.max(current.length * 2, rowComponents);\n while (newLength < neededComponents) {\n newLength *= 2;\n }\n // Round up to a whole row to keep texel math aligned.\n newLength = Math.ceil(newLength / rowComponents) * rowComponents;\n const grown = new ArrayType(newLength);\n grown.set(current);\n return grown;\n}\n\n/** @internal Append `glyph` to `atlas`. Returns the new slot. Caller must guarantee\n * glyph is not already present. */\nexport function packAppendGlyph(atlas: SharedAtlas, glyph: GLGlyphCurves): AtlasSlot {\n const bands = buildGlyphBands(glyph);\n const curves = glyph.curves;\n\n // ── Curve texels: 2 texels per curve, must not straddle a row boundary. ──\n let curveTexel = atlas._curveTexelsUsed;\n const curveTexelPositions: number[] = new Array(curves.length);\n for (let i = 0; i < curves.length; i++) {\n const row0 = (curveTexel / TEX_WIDTH) | 0;\n const row1 = ((curveTexel + 1) / TEX_WIDTH) | 0;\n if (row0 !== row1) {\n curveTexel = row1 * TEX_WIDTH;\n }\n curveTexelPositions[i] = curveTexel;\n curveTexel += 2;\n }\n const curveTexelsEnd = curveTexel;\n atlas._curveTexData = ensureTexelCapacity(atlas._curveTexData, curveTexelsEnd, Float32Array);\n\n const curveData = atlas._curveTexData;\n for (let i = 0; i < curves.length; i++) {\n const c = curves[i]!;\n const tl = curveTexelPositions[i]!;\n const o0 = tl * 4;\n curveData[o0] = c.p0x;\n curveData[o0 + 1] = c.p0y;\n curveData[o0 + 2] = c.p1x;\n curveData[o0 + 3] = c.p1y;\n const o1 = (tl + 1) * 4;\n curveData[o1] = c.p2x;\n curveData[o1 + 1] = c.p2y;\n // (.zw left zero; padded.)\n }\n atlas._curveTexelsUsed = curveTexelsEnd;\n\n // ── Band block: headers must not straddle a row; followed by curve-index lists. ──\n const headerCount = bands._hBandCount + bands._vBandCount;\n let bandStart = atlas._bandTexelsUsed;\n const curX = bandStart % TEX_WIDTH;\n if (curX + headerCount > TEX_WIDTH) {\n bandStart = (((bandStart / TEX_WIDTH) | 0) + 1) * TEX_WIDTH;\n }\n const glyphLocX = bandStart % TEX_WIDTH;\n const glyphLocY = (bandStart / TEX_WIDTH) | 0;\n\n const allBands = [...bands._hBands, ...bands._vBands];\n let curveListOffset = headerCount;\n const bandOffsets: number[] = new Array(allBands.length);\n for (let i = 0; i < allBands.length; i++) {\n bandOffsets[i] = curveListOffset;\n curveListOffset += allBands[i]!._curveIndices.length;\n }\n const bandTexelsEnd = bandStart + curveListOffset;\n atlas._bandTexData = ensureTexelCapacity(atlas._bandTexData, bandTexelsEnd, Uint32Array, 2);\n\n const bandData = atlas._bandTexData;\n // Headers.\n for (let i = 0; i < allBands.length; i++) {\n const tl = bandStart + i;\n const di = tl * 2;\n bandData[di] = allBands[i]!._curveIndices.length;\n bandData[di + 1] = bandOffsets[i]!;\n }\n // Curve refs.\n for (let i = 0; i < allBands.length; i++) {\n const band = allBands[i]!;\n const listStart = bandStart + bandOffsets[i]!;\n for (let j = 0; j < band._curveIndices.length; j++) {\n const ci = band._curveIndices[j]!;\n const curveTexelAbs = curveTexelPositions[ci]!;\n const cTexX = curveTexelAbs % TEX_WIDTH;\n const cTexY = (curveTexelAbs / TEX_WIDTH) | 0;\n const tl = listStart + j;\n const di = tl * 2;\n bandData[di] = cTexX;\n bandData[di + 1] = cTexY;\n }\n }\n atlas._bandTexelsUsed = bandTexelsEnd;\n\n atlas._version++;\n\n const { xMin, yMin, xMax, yMax } = glyph.bounds;\n const widthFu = xMax - xMin;\n const heightFu = yMax - yMin;\n const bandScaleX = widthFu > 0 ? bands._vBandCount / widthFu : 0;\n const bandScaleY = heightFu > 0 ? bands._hBandCount / heightFu : 0;\n\n // ── Glyph metadata: written once here, read by every instance that uses this glyph. ──\n const index = atlas._slotCount++;\n const needMetaFloats = atlas._slotCount * GLYPH_METADATA_FLOATS;\n if (atlas._metaData.length < needMetaFloats) {\n const grown = new Float32Array(Math.max(atlas._metaData.length * 2, needMetaFloats));\n grown.set(atlas._metaData);\n atlas._metaData = grown;\n }\n const m = index * GLYPH_METADATA_FLOATS;\n const meta = atlas._metaData;\n meta[m] = xMin;\n meta[m + 1] = yMin;\n meta[m + 2] = xMax;\n meta[m + 3] = yMax;\n meta[m + 4] = glyphLocX;\n meta[m + 5] = glyphLocY;\n meta[m + 6] = bands._vBandCount - 1;\n meta[m + 7] = bands._hBandCount - 1;\n meta[m + 8] = bandScaleX;\n meta[m + 9] = bandScaleY;\n meta[m + 10] = -xMin * bandScaleX;\n meta[m + 11] = -yMin * bandScaleY;\n\n return { _index: index };\n}\n\n// ─── Internal: spatial-band partitioning ──────────────────────────────────\n\nfunction curveAt(curves: readonly GLQuadCurve[], i: number): GLQuadCurve {\n const c = curves[i];\n if (!c) {\n throw new Error(\"buildGlyphBands: invalid curve index\");\n }\n return c;\n}\n\nfunction buildBandsInternal(g: GLGlyphCurves): GlyphBands {\n const { curves, bounds } = g;\n const numBands = Math.max(1, Math.min(8, Math.floor(curves.length / 2)));\n const { xMin, yMin, xMax, yMax } = bounds;\n const width = xMax - xMin;\n const height = yMax - yMin;\n const bandH = height / numBands;\n const bandW = width / numBands;\n\n const hBands: BandEntry[] = [];\n const vBands: BandEntry[] = [];\n for (let i = 0; i < numBands; i++) {\n hBands.push({ _curveIndices: [] });\n vBands.push({ _curveIndices: [] });\n }\n\n for (let ci = 0; ci < curves.length; ci++) {\n const c = curveAt(curves, ci);\n const cyMin = Math.min(c.p0y, c.p1y, c.p2y);\n const cyMax = Math.max(c.p0y, c.p1y, c.p2y);\n const cxMin = Math.min(c.p0x, c.p1x, c.p2x);\n const cxMax = Math.max(c.p0x, c.p1x, c.p2x);\n if (height > 0) {\n for (let b = 0; b < numBands; b++) {\n const bMinY = yMin + b * bandH;\n const bMaxY = yMin + (b + 1) * bandH;\n if (cyMax >= bMinY && cyMin <= bMaxY) {\n hBands[b]!._curveIndices.push(ci);\n }\n }\n }\n if (width > 0) {\n for (let b = 0; b < numBands; b++) {\n const bMinX = xMin + b * bandW;\n const bMaxX = xMin + (b + 1) * bandW;\n if (cxMax >= bMinX && cxMin <= bMaxX) {\n vBands[b]!._curveIndices.push(ci);\n }\n }\n }\n }\n\n // Sort curves: h-bands by descending max x, v-bands by descending max y (early-exit in shader).\n for (const band of hBands) {\n band._curveIndices.sort((a, b) => {\n const ca = curveAt(curves, a);\n const cb = curveAt(curves, b);\n return Math.max(cb.p0x, cb.p1x, cb.p2x) - Math.max(ca.p0x, ca.p1x, ca.p2x);\n });\n }\n for (const band of vBands) {\n band._curveIndices.sort((a, b) => {\n const ca = curveAt(curves, a);\n const cb = curveAt(curves, b);\n return Math.max(cb.p0y, cb.p1y, cb.p2y) - Math.max(ca.p0y, ca.p1y, ca.p2y);\n });\n }\n\n return { _hBands: hBands, _vBands: vBands, _hBandCount: numBands, _vBandCount: numBands };\n}\n\n/** @internal Get (and memoize) the band partitioning for a glyph's curves. */\nexport function buildGlyphBands(g: GLGlyphCurves): GlyphBands {\n return (g._bands ??= buildBandsInternal(g));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"glyph-storage.js","sourceRoot":"","sources":["../../src/text/glyph-storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAsD/C,6EAA6E;AAC7E,mFAAmF;AACnF,qFAAqF;AACrF,gBAAgB;AAEhB,6DAA6D;AAC7D,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,CAAC;AAkB9B;;;;;wFAKwF;AACxF,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AA8DxC,6EAA6E;AAE7E;;yFAEyF;AACzF,MAAM,UAAU,kBAAkB,CAAC,OAAuD;IACtF,MAAM,UAAU,GAAG,IAAI,GAAG,EAAsC,CAAC;IACjE,IAAI,OAAO,EAAE,CAAC;QACV,KAAK,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;YACzC,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;QACrD,CAAC;IACL,CAAC;IACD,OAAO,EAAE,UAAU,EAA+B,CAAC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EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;YAC9B,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;QAC/E,CAAC,CAAC,CAAC;IACP,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AAC9F,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,eAAe,CAAC,CAAgB;IAC5C,OAAO,CAAC,CAAC,CAAC,MAAM,KAAK,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC","sourcesContent":["/** Glyph storage: per-curve-set CPU outline catalog plus the GPU atlas packed from it.\n *\n * Layered:\n * - `GLGlyphStorage` is the opaque public handle. Holds one or more curve-sets keyed by\n * `GLCurveSetId` (typically a font family name). Each curve-set owns its glyph\n * outlines plus the `SharedAtlas` packed from them.\n * - `SharedAtlas` stages float32 curve control points and uint32 band headers/\n * curve-reference lists in append-only RGBA and RG arrays, respectively.\n * - Atlas packing (`packAppendGlyph`) and spatial-band partitioning (`buildGlyphBands`)\n * live here as internal helpers — they implement the storage's invariants and are\n * not callable from outside the module.\n * - GPU creation/upload (`SharedAtlasGpu`, `ensureSharedAtlasGpu`) lives in\n * `_gpu/text-textures.ts`; the shared types are exported from here. GPU teardown\n * is performed inline in `disposeGlyphStorage` to avoid a circular import edge.\n *\n * Lifetime is caller-owned (matches `Texture2D` semantics):\n * - `createGlyphStorage(initial?)` allocates a fresh storage, optionally seeded.\n * - `updateGlyphStorage(storage, curveSetId, curves)` adds glyphs (creating the\n * curve-set on demand). Glyph ids already present are skipped.\n * - `disposeGlyphStorage(storage)` releases every atlas. The caller must ensure no\n * `GLTextData` is still drawing from it — using a disposed storage is undefined\n * behavior. Idempotent.\n */\n\nimport type { GLEngineContext } from \"../context.js\";\nimport type { GLTexture } from \"../texture.js\";\nimport { disposeTexture } from \"../texture.js\";\n\ndeclare const glyphStorageBrand: unique symbol;\n\n// ─── Glyph outline geometry (public value types) ──────────────────────\n//\n// These describe the input contract for `updateGlyphStorage` /\n// `createGlyphStorage`. Live here (not with the default extraction module) so a\n// caller bringing their own outline source (DirectWrite, FreeType, hand-rolled)\n// can produce `GLGlyphCurves` values without importing `glyph-extraction.ts` or\n// pulling `text-shaper` into their bundle.\n\n/** Quadratic Bézier curve describing one segment of a glyph outline in font units. */\nexport type GLQuadCurve = {\n readonly p0x: number;\n readonly p0y: number;\n readonly p1x: number;\n readonly p1y: number;\n readonly p2x: number;\n readonly p2y: number;\n};\n\n/** Axis-aligned glyph extents in font units, used to size the rendered quad and spatial curve bands. */\nexport type GLGlyphBounds = {\n readonly xMin: number;\n readonly yMin: number;\n readonly xMax: number;\n readonly yMax: number;\n};\n\n/** Complete outline data for one glyph id, ready to be packed into a `GLGlyphStorage` atlas. */\nexport type GLGlyphCurves = {\n readonly glyphId: number;\n readonly curves: readonly GLQuadCurve[];\n readonly bounds: GLGlyphBounds;\n /** @internal Lazily-computed band partitioning (memoized by `buildGlyphBands`). */\n _bands?: GlyphBands;\n};\n\n// ─── Public types ─────────────────────────────────────────────────────────\n\n/** Identifier for a curve set (a font's glyph-curves map). Strings let callers use a\n * human-readable key (e.g. the font face name) for easy debugging. */\nexport type GLCurveSetId = string;\n\n/** Opaque bundle of glyph outlines (organized by curve-set) and the GPU atlases packed\n * from them. Holds an arbitrary number of curve-sets — each curve-set gets its own atlas.\n * Shared by reference across any number of `GLTextData`s that need the same glyph catalog. */\nexport interface GLGlyphStorage {\n readonly [glyphStorageBrand]: true;\n /** @internal Per-curve-set glyph outlines + the SharedAtlas they're packed into. */\n _curveSets: Map<GLCurveSetId, GlyphStorageCurveSet>;\n}\n\n// ─── Internal supporting types ────────────────────────────────────────────\n// Tagged `@internal` on the type itself so the d.ts trim pass strips them from the\n// published types. Fields still use `_` prefixes so production property mangling can\n// shorten them.\n\n/** @internal Width of the curve / band textures (texels). */\nexport const TEX_WIDTH = 4096;\n\n/** @internal Per-curve-set entry within a GLGlyphStorage. */\nexport type GlyphStorageCurveSet = {\n /** @internal */\n _curves: Map<number, GLGlyphCurves>;\n /** @internal */\n _atlas: SharedAtlas;\n};\n\n/** @internal Atlas slot for a single glyph inside a SharedAtlas. */\nexport type AtlasSlot = {\n /** @internal Dense index of this glyph's entry in `SharedAtlas._metaData`, and the value the vertex\n * shader uses to look it up in the GPU metadata texture. Slots are append-only and never\n * moved, so an index stays valid for the atlas's lifetime. */\n _index: number;\n};\n\n/** @internal Floats per glyph in `SharedAtlas._metaData`, laid out as three `vec4<f32>` to match\n * the shader's `GlyphMetadata`: bounds (xMin, yMin, xMax, yMax), atlas (glyphLocX, glyphLocY,\n * bandMaxX, bandMaxY), band (bandScaleX, bandScaleY, bandOffsetX, bandOffsetY).\n *\n * All twelve depend only on the glyph, so they live here — written once when the glyph is\n * appended — instead of being copied into every instance that references the glyph. */\nexport const GLYPH_METADATA_FLOATS = 12;\n\n/** @internal CPU + (lazy) GPU staging packed from a `GLGlyphStorage`'s glyph outlines.\n * One `SharedAtlas` per curve-set; lifetime is bound to the storage. */\nexport type SharedAtlas = {\n /** @internal Pooled curve texel staging (rgba32float, width 4096). */\n _curveTexData: Float32Array;\n /** @internal Number of curve texels actually used. */\n _curveTexelsUsed: number;\n /** @internal Pooled band texel staging (rg32uint, two components, width 4096). */\n _bandTexData: Uint32Array;\n /** @internal Number of band texels actually used. */\n _bandTexelsUsed: number;\n /** @internal Per-glyph atlas slot lookup. Slots are append-only and never moved. */\n _glyphSlots: Map<number, AtlasSlot>;\n /** @internal Glyph-invariant shader data, `GLYPH_METADATA_FLOATS` per slot, indexed by `AtlasSlot._index`.\n * Uploaded verbatim as the vertex shader's metadata lookup texture. */\n _metaData: Float32Array;\n /** @internal Number of slots appended so far; also the next `AtlasSlot._index`. */\n _slotCount: number;\n /** @internal Monotonic version bumped whenever a new glyph is appended. */\n _version: number;\n /** @internal Lazy GPU resources (one set per SharedAtlas; recreated only on capacity grow). */\n _gpu: SharedAtlasGpu | null;\n};\n\n/** @internal GPU-side companion to a `SharedAtlas`; populated lazily by\n * `ensureSharedAtlasGpu` in `_gpu/text-textures.ts`. */\nexport type SharedAtlasGpu = {\n /** @internal */\n _engine: GLEngineContext;\n /** @internal */\n _curveTex: GLTexture;\n /** @internal */\n _bandTex: GLTexture;\n /** @internal */\n _metaTex: GLTexture;\n /** @internal */\n _metaPixels: Float32Array;\n /** @internal */\n _uploadedVersion: number;\n};\n\n/** @internal Spatial-band partitioning for a glyph's curves. Memoized per `GLGlyphCurves`\n * via `GLGlyphCurves._bands`. */\nexport type GlyphBands = {\n /** @internal */\n _hBands: BandEntry[];\n /** @internal */\n _vBands: BandEntry[];\n /** @internal */\n _hBandCount: number;\n /** @internal */\n _vBandCount: number;\n};\n\n/** @internal */\nexport type BandEntry = {\n /** @internal */\n _curveIndices: number[];\n};\n\n// ─── Public API ───────────────────────────────────────────────────────────\n\n/** Build a `GLGlyphStorage`. If `initial` is provided, each curve-set is packed into its\n * own atlas synchronously. The passed inner maps are *adopted* by the storage — the\n * caller must not mutate them directly afterward (use `updateGlyphStorage` instead). */\nexport function createGlyphStorage(initial?: Map<GLCurveSetId, Map<number, GLGlyphCurves>>): GLGlyphStorage {\n const _curveSets = new Map<GLCurveSetId, GlyphStorageCurveSet>();\n if (initial) {\n for (const [curveSetId, curves] of initial) {\n _curveSets.set(curveSetId, makeCurveSet(curves));\n }\n }\n return { _curveSets } as unknown as GLGlyphStorage;\n}\n\n/** Add glyphs to the named curve-set, creating it if it doesn't exist yet. Glyph ids\n * already present in the curve-set are skipped (the existing outline + atlas slot wins).\n * Safe to call between frames: the atlas grows in place and the next render uploads the\n * new glyphs. */\nexport function updateGlyphStorage(storage: GLGlyphStorage, curveSetId: GLCurveSetId, curves: ReadonlyMap<number, GLGlyphCurves>): void {\n let cs = storage._curveSets.get(curveSetId);\n if (!cs) {\n cs = makeCurveSet(new Map());\n storage._curveSets.set(curveSetId, cs);\n }\n for (const [glyphId, glyph] of curves) {\n if (cs._curves.has(glyphId)) {\n continue;\n }\n cs._curves.set(glyphId, glyph);\n cs._atlas._glyphSlots.set(glyphId, packAppendGlyph(cs._atlas, glyph));\n }\n}\n\n/** Release every GPU atlas owned by `storage`. Idempotent. The caller is responsible for\n * ensuring no `GLTextData` is still drawing from this storage. */\nexport function disposeGlyphStorage(storage: GLGlyphStorage): void {\n for (const cs of storage._curveSets.values()) {\n const gpu = cs._atlas._gpu;\n if (gpu) {\n disposeTexture(gpu._curveTex);\n disposeTexture(gpu._bandTex);\n disposeTexture(gpu._metaTex);\n cs._atlas._gpu = null;\n }\n }\n storage._curveSets.clear();\n}\n\n// ─── Internal: SharedAtlas construction + glyph packing ───────────────────\n\nconst ROW_COMPONENTS = TEX_WIDTH * 4;\n\n/** @internal Create an empty `SharedAtlas`. */\nexport function createSharedAtlas(): SharedAtlas {\n return {\n _curveTexData: new Float32Array(ROW_COMPONENTS),\n _curveTexelsUsed: 0,\n _bandTexData: new Uint32Array(TEX_WIDTH * 2),\n _bandTexelsUsed: 0,\n _glyphSlots: new Map(),\n _metaData: new Float32Array(GLYPH_METADATA_FLOATS * 16),\n _slotCount: 0,\n _version: 0,\n _gpu: null,\n };\n}\n\nfunction makeCurveSet(curves: Map<number, GLGlyphCurves>): GlyphStorageCurveSet {\n const atlas = createSharedAtlas();\n for (const [glyphId, glyph] of curves) {\n atlas._glyphSlots.set(glyphId, packAppendGlyph(atlas, glyph));\n }\n return { _curves: curves, _atlas: atlas };\n}\n\n/** Grow a texel-staging array to hold at least `neededTexels` texels,\n * rounded up to a whole 4096-texel row. Returns the same array when already large enough. */\nfunction ensureTexelCapacity<T extends Float32Array | Uint32Array>(current: T, neededTexels: number, ArrayType: new (length: number) => T, componentsPerTexel: 2 | 4 = 4): T {\n const neededComponents = neededTexels * componentsPerTexel;\n const rowComponents = TEX_WIDTH * componentsPerTexel;\n if (current.length >= neededComponents) {\n return current;\n }\n let newLength = Math.max(current.length * 2, rowComponents);\n while (newLength < neededComponents) {\n newLength *= 2;\n }\n // Round up to a whole row to keep texel math aligned.\n newLength = Math.ceil(newLength / rowComponents) * rowComponents;\n const grown = new ArrayType(newLength);\n grown.set(current);\n return grown;\n}\n\n/** @internal Append `glyph` to `atlas`. Returns the new slot. Caller must guarantee\n * glyph is not already present. */\nexport function packAppendGlyph(atlas: SharedAtlas, glyph: GLGlyphCurves): AtlasSlot {\n const bands = buildGlyphBands(glyph);\n const curves = glyph.curves;\n\n // ── Curve texels: 2 texels per curve, must not straddle a row boundary. ──\n let curveTexel = atlas._curveTexelsUsed;\n const curveTexelPositions: number[] = new Array(curves.length);\n for (let i = 0; i < curves.length; i++) {\n const row0 = (curveTexel / TEX_WIDTH) | 0;\n const row1 = ((curveTexel + 1) / TEX_WIDTH) | 0;\n if (row0 !== row1) {\n curveTexel = row1 * TEX_WIDTH;\n }\n curveTexelPositions[i] = curveTexel;\n curveTexel += 2;\n }\n const curveTexelsEnd = curveTexel;\n atlas._curveTexData = ensureTexelCapacity(atlas._curveTexData, curveTexelsEnd, Float32Array);\n\n const curveData = atlas._curveTexData;\n for (let i = 0; i < curves.length; i++) {\n const c = curves[i]!;\n const tl = curveTexelPositions[i]!;\n const o0 = tl * 4;\n curveData[o0] = c.p0x;\n curveData[o0 + 1] = c.p0y;\n curveData[o0 + 2] = c.p1x;\n curveData[o0 + 3] = c.p1y;\n const o1 = (tl + 1) * 4;\n curveData[o1] = c.p2x;\n curveData[o1 + 1] = c.p2y;\n // (.zw left zero; padded.)\n }\n atlas._curveTexelsUsed = curveTexelsEnd;\n\n // ── Band block: headers must not straddle a row; followed by curve-index lists. ──\n const headerCount = bands._hBandCount + bands._vBandCount;\n let bandStart = atlas._bandTexelsUsed;\n const curX = bandStart % TEX_WIDTH;\n if (curX + headerCount > TEX_WIDTH) {\n bandStart = (((bandStart / TEX_WIDTH) | 0) + 1) * TEX_WIDTH;\n }\n const glyphLocX = bandStart % TEX_WIDTH;\n const glyphLocY = (bandStart / TEX_WIDTH) | 0;\n\n const allBands = [...bands._hBands, ...bands._vBands];\n let curveListOffset = headerCount;\n const bandOffsets: number[] = new Array(allBands.length);\n for (let i = 0; i < allBands.length; i++) {\n bandOffsets[i] = curveListOffset;\n curveListOffset += allBands[i]!._curveIndices.length;\n }\n const bandTexelsEnd = bandStart + curveListOffset;\n atlas._bandTexData = ensureTexelCapacity(atlas._bandTexData, bandTexelsEnd, Uint32Array, 2);\n\n const bandData = atlas._bandTexData;\n // Headers.\n for (let i = 0; i < allBands.length; i++) {\n const tl = bandStart + i;\n const di = tl * 2;\n bandData[di] = allBands[i]!._curveIndices.length;\n bandData[di + 1] = bandOffsets[i]!;\n }\n // Curve refs.\n for (let i = 0; i < allBands.length; i++) {\n const band = allBands[i]!;\n const listStart = bandStart + bandOffsets[i]!;\n for (let j = 0; j < band._curveIndices.length; j++) {\n const ci = band._curveIndices[j]!;\n const curveTexelAbs = curveTexelPositions[ci]!;\n const cTexX = curveTexelAbs % TEX_WIDTH;\n const cTexY = (curveTexelAbs / TEX_WIDTH) | 0;\n const tl = listStart + j;\n const di = tl * 2;\n bandData[di] = cTexX;\n bandData[di + 1] = cTexY;\n }\n }\n atlas._bandTexelsUsed = bandTexelsEnd;\n\n atlas._version++;\n\n const { xMin, yMin, xMax, yMax } = glyph.bounds;\n const widthFu = xMax - xMin;\n const heightFu = yMax - yMin;\n const bandScaleX = widthFu > 0 ? bands._vBandCount / widthFu : 0;\n const bandScaleY = heightFu > 0 ? bands._hBandCount / heightFu : 0;\n\n // ── Glyph metadata: written once here, read by every instance that uses this glyph. ──\n const index = atlas._slotCount++;\n const needMetaFloats = atlas._slotCount * GLYPH_METADATA_FLOATS;\n if (atlas._metaData.length < needMetaFloats) {\n const grown = new Float32Array(Math.max(atlas._metaData.length * 2, needMetaFloats));\n grown.set(atlas._metaData);\n atlas._metaData = grown;\n }\n const m = index * GLYPH_METADATA_FLOATS;\n const meta = atlas._metaData;\n meta[m] = xMin;\n meta[m + 1] = yMin;\n meta[m + 2] = xMax;\n meta[m + 3] = yMax;\n meta[m + 4] = glyphLocX;\n meta[m + 5] = glyphLocY;\n meta[m + 6] = bands._vBandCount - 1;\n meta[m + 7] = bands._hBandCount - 1;\n meta[m + 8] = bandScaleX;\n meta[m + 9] = bandScaleY;\n meta[m + 10] = -xMin * bandScaleX;\n meta[m + 11] = -yMin * bandScaleY;\n\n return { _index: index };\n}\n\n// ─── Internal: spatial-band partitioning ──────────────────────────────────\n\nfunction curveAt(curves: readonly GLQuadCurve[], i: number): GLQuadCurve {\n const c = curves[i];\n if (!c) {\n throw new Error(\"buildGlyphBands: invalid curve index\");\n }\n return c;\n}\n\nfunction buildBandsInternal(g: GLGlyphCurves): GlyphBands {\n const { curves, bounds } = g;\n const numBands = Math.max(1, Math.min(8, Math.floor(curves.length / 2)));\n const { xMin, yMin, xMax, yMax } = bounds;\n const width = xMax - xMin;\n const height = yMax - yMin;\n const bandH = height / numBands;\n const bandW = width / numBands;\n\n const hBands: BandEntry[] = [];\n const vBands: BandEntry[] = [];\n for (let i = 0; i < numBands; i++) {\n hBands.push({ _curveIndices: [] });\n vBands.push({ _curveIndices: [] });\n }\n\n for (let ci = 0; ci < curves.length; ci++) {\n const c = curveAt(curves, ci);\n const cyMin = Math.min(c.p0y, c.p1y, c.p2y);\n const cyMax = Math.max(c.p0y, c.p1y, c.p2y);\n const cxMin = Math.min(c.p0x, c.p1x, c.p2x);\n const cxMax = Math.max(c.p0x, c.p1x, c.p2x);\n if (height > 0) {\n for (let b = 0; b < numBands; b++) {\n const bMinY = yMin + b * bandH;\n const bMaxY = yMin + (b + 1) * bandH;\n if (cyMax >= bMinY && cyMin <= bMaxY) {\n hBands[b]!._curveIndices.push(ci);\n }\n }\n }\n if (width > 0) {\n for (let b = 0; b < numBands; b++) {\n const bMinX = xMin + b * bandW;\n const bMaxX = xMin + (b + 1) * bandW;\n if (cxMax >= bMinX && cxMin <= bMaxX) {\n vBands[b]!._curveIndices.push(ci);\n }\n }\n }\n }\n\n // Sort curves: h-bands by descending max x, v-bands by descending max y (early-exit in shader).\n for (const band of hBands) {\n band._curveIndices.sort((a, b) => {\n const ca = curveAt(curves, a);\n const cb = curveAt(curves, b);\n return Math.max(cb.p0x, cb.p1x, cb.p2x) - Math.max(ca.p0x, ca.p1x, ca.p2x);\n });\n }\n for (const band of vBands) {\n band._curveIndices.sort((a, b) => {\n const ca = curveAt(curves, a);\n const cb = curveAt(curves, b);\n return Math.max(cb.p0y, cb.p1y, cb.p2y) - Math.max(ca.p0y, ca.p1y, ca.p2y);\n });\n }\n\n return { _hBands: hBands, _vBands: vBands, _hBandCount: numBands, _vBandCount: numBands };\n}\n\n/** @internal Get (and memoize) the band partitioning for a glyph's curves. */\nexport function buildGlyphBands(g: GLGlyphCurves): GlyphBands {\n return (g._bands ??= buildBandsInternal(g));\n}\n"]}
|
package/text/text-data.js
CHANGED
|
@@ -709,8 +709,8 @@ export function updateTextData(data, update) {
|
|
|
709
709
|
export function disposeTextData(data) {
|
|
710
710
|
const gpu = data._gpu;
|
|
711
711
|
if (gpu) {
|
|
712
|
-
disposeBuffer(gpu.
|
|
713
|
-
disposeTexture(gpu.
|
|
712
|
+
disposeBuffer(gpu._instanceBuf);
|
|
713
|
+
disposeTexture(gpu._styleTex);
|
|
714
714
|
data._gpu = null;
|
|
715
715
|
}
|
|
716
716
|
data._groups = [];
|