@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
package/README.md CHANGED
@@ -146,6 +146,37 @@ use.
146
146
  `setColorMask`, `clearEngine`; `setScissor`, `disableScissor`.
147
147
  - **Blend** — `setBlendMode` + `GLBlendMode` (`DISABLE` / `ADD` / `ALPHA` /
148
148
  `PREMULTIPLIED`), matching Babylon's `setAlphaMode` parameters.
149
+ - **Text (Slug)** — analytic, resolution-independent glyph rendering, the WebGL2
150
+ counterpart of Lite's `TextRenderer`: `loadFont` / `createFontFromBuffer`,
151
+ `createDefaultTextData` / `updateDefaultTextData` / `disposeDefaultTextData`
152
+ (shape + extract + pack in one call), or `createGlyphStorage` + `createTextData`
153
+ / `updateTextData` / `disposeTextData` to drive your own layout;
154
+ `createTextLayer` / `setTextLayerPosition`, `createTextRenderer`,
155
+ `registerTextRenderer` / `unregisterTextRenderer` / `renderText` /
156
+ `isTextRendererReady`, and the optional synthetic-weight setter
157
+ `setFontWeightOffset` (its shader is only bundled when you import it). Text uses `text-shaper` for shaping; it is a dependency, not bundled by
158
+ consumers that never import the text API. See [Text](#text-slug) below.
159
+
160
+ ### Text (Slug)
161
+
162
+ ```ts
163
+ import { createGLEngine, loadFont, createDefaultTextData, createTextLayer, createTextRenderer, registerTextRenderer } from "@babylonjs/lite-gl";
164
+
165
+ const engine = createGLEngine(canvas);
166
+ const font = await loadFont("/fonts/Inter-Regular.ttf");
167
+ const data = createDefaultTextData(font, 48, "Hello, WebGL2", [1, 1, 1, 1]);
168
+ const layer = createTextLayer(data, { positionPx: { x: 24, y: 80 } });
169
+ const renderer = createTextRenderer(engine, { layers: [layer], clearValue: { r: 0.1, g: 0.1, b: 0.12 } });
170
+ registerTextRenderer(renderer); // draws every frame; unregisterTextRenderer to stop
171
+ ```
172
+
173
+ Glyph outlines are stored as quadratic curves in a float texture with a spatial
174
+ band index in an `rg32uint` texture; the fragment shader resolves analytic
175
+ coverage per pixel, so text stays sharp at any scale or rotation. The text data
176
+ (and its glyph storage) is borrowed by layers and renderers — dispose it
177
+ yourself with `disposeDefaultTextData` / `disposeTextData`. One glyph storage
178
+ can be drawn by a single engine only. Text is blended as premultiplied
179
+ source-over, with no depth test.
149
180
 
150
181
  ### Already-decoded textures
151
182
 
package/index.d.ts CHANGED
@@ -28,3 +28,16 @@ export { createSpriteRenderer, renderSprites, setSpriteRendererTexture, disposeS
28
28
  export type { GLSprite, GLSpriteColor, GLSpriteRendererOptions, GLSpriteRenderer } from "./sprites.js";
29
29
  export { createHtmlElementTexture, updateHtmlElementTexture, GLSamplingMode } from "./html-texture.js";
30
30
  export type { GLHtmlElementTextureOptions } from "./html-texture.js";
31
+ export type { GLFont } from "./text/font.js";
32
+ export { loadFont, createFontFromBuffer } from "./text/font.js";
33
+ export { extractGlyphCurves, cubicToQuadratics } from "./text/glyph-extraction.js";
34
+ export type { GLTextLayoutOptions } from "./text/layout.js";
35
+ export type { GLGlyphStorage, GLCurveSetId, GLQuadCurve, GLGlyphBounds, GLGlyphCurves } from "./text/glyph-storage.js";
36
+ export { createGlyphStorage, updateGlyphStorage, disposeGlyphStorage } from "./text/glyph-storage.js";
37
+ export type { GLTextData, GLPlacedGlyph, GLGlyphRun, GLTextDataUpdate } from "./text/text-data.js";
38
+ export { createTextData, updateTextData, disposeTextData } from "./text/text-data.js";
39
+ export type { GLDefaultTextData } from "./text/default-text-data.js";
40
+ export { createDefaultTextData, updateDefaultTextData, disposeDefaultTextData } from "./text/default-text-data.js";
41
+ export type { GLTextLayer, GLTextLayerOptions, GLTextRenderer, GLTextRendererOptions } from "./text/text-renderer.js";
42
+ export { createTextLayer, setTextLayerPosition, createTextRenderer, renderText, isTextRendererReady, addTextRendererLayer, removeTextRendererLayer, registerTextRenderer, unregisterTextRenderer, disposeTextRenderer, } from "./text/text-renderer.js";
43
+ export { setFontWeightOffset } from "./text/set-font-weight-offset.js";
package/index.js CHANGED
@@ -44,4 +44,11 @@ export { createSpriteRenderer, renderSprites, setSpriteRendererTexture, disposeS
44
44
  // ─── HTML-element textures ───────────────────────────────────────────
45
45
  // GLSamplingMode is a const + same-name type; one value re-export carries both.
46
46
  export { createHtmlElementTexture, updateHtmlElementTexture, GLSamplingMode } from "./html-texture.js";
47
+ export { loadFont, createFontFromBuffer } from "./text/font.js";
48
+ export { extractGlyphCurves, cubicToQuadratics } from "./text/glyph-extraction.js";
49
+ export { createGlyphStorage, updateGlyphStorage, disposeGlyphStorage } from "./text/glyph-storage.js";
50
+ export { createTextData, updateTextData, disposeTextData } from "./text/text-data.js";
51
+ export { createDefaultTextData, updateDefaultTextData, disposeDefaultTextData } from "./text/default-text-data.js";
52
+ export { createTextLayer, setTextLayerPosition, createTextRenderer, renderText, isTextRendererReady, addTextRendererLayer, removeTextRendererLayer, registerTextRenderer, unregisterTextRenderer, disposeTextRenderer, } from "./text/text-renderer.js";
53
+ export { setFontWeightOffset } from "./text/set-font-weight-offset.js";
47
54
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,gFAAgF;AAChF,EAAE;AACF,iFAAiF;AACjF,4EAA4E;AAC5E,2EAA2E;AAC3E,yEAAyE;AACzE,+DAA+D;AAC/D,EAAE;AACF,gFAAgF;AAChF,8EAA8E;AAC9E,wCAAwC;AAExC,wEAAwE;AACxE,OAAO,EACH,cAAc,EACd,eAAe,EACf,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,EAClB,aAAa,E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AkB,EAClB,uBAAuB,EACvB,gBAAgB,EAChB,2BAA2B,EAC3B,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,GACtB,MAAM,oBAAoB,CAAC;AAG5B,wEAAwE;AACxE,OAAO,EACH,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,cAAc,EACd,wBAAwB,EACxB,WAAW,EACX,aAAa,EACb,WAAW,EACX,QAAQ,EACR,cAAc,GACjB,MAAM,WAAW,CAAC;AAGnB,wEAAwE;AACxE,sEAAsE;AACtE,0BAA0B;AAC1B,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGrG,wEAAwE;AACxE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,YAAY,EAAE,WAAW,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAGhK,wEAAwE;AACxE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE1D,wEAAwE;AACxE,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAGpH,wEAAwE;AACxE,gFAAgF;AAChF,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC","sourcesContent":["// @babylonjs/lite-gl — Public API\n// Function-based, tree-shakeable WebGL2 micro-engine. Import only what you use.\n//\n// Convention (mirrors @babylonjs/lite): the public API is re-exported EXPLICITLY\n// by name — never `export *`. This keeps the public surface intentional and\n// reviewable, lets `export type` mark type-only re-exports (required under\n// `isolatedModules`), and keeps internal helpers (e.g. `bindTextureRaw`,\n// `bindTextureForUpload`) out of consumers' bundles + `.d.ts`.\n//\n// The package is `sideEffects: false` and no module has top-level side effects,\n// so a consumer that imports only the symbols it needs tree-shakes everything\n// else (sprites, html-texture, …) away.\n\n// ─── Engine / context ────────────────────────────────────────────────\nexport {\n createGLEngine,\n disposeGLEngine,\n resizeGLEngine,\n setGLEngineSize,\n wipeGLStateCache,\n getRenderWidth,\n getRenderHeight,\n getHardwareScalingLevel,\n setHardwareScalingLevel,\n getRenderingCanvas,\n onContextLost,\n offContextLost,\n onContextRestored,\n offContextRestored,\n} from \"./context.js\";\nexport type { GLEngineOptions, GLEngineCaps, GLEngineContext } from \"./context.js\";\n\n// ─── Alpha-to-coverage (optional) ───────────────────────────────────\nexport { getAlphaToCoverage, getCurrentSampleCount, setAlphaToCoverage } from \"./alpha-to-coverage.js\";\n\n// ─── Render loop ─────────────────────────────────────────────────────\nexport { runRenderLoop, stopRenderLoop } from \"./render-loop.js\";\n\n// ─── Effects ─────────────────────────────────────────────────────────\nexport {\n createEffect,\n useEffect,\n isEffectReady,\n getEffectCompilationError,\n executeWhenCompiled,\n disposeEffect,\n setEffectFloat,\n setEffectFloat2,\n setEffectFloat3,\n setEffectFloat4,\n setEffectColor3,\n setEffectColor4,\n setEffectVector2,\n setEffectDirectColor4,\n setEffectInt,\n setEffectTexture,\n setEffectMatrix,\n setEffectMatrix3x3,\n setEffectFloatArray,\n setEffectFloatArray4,\n setEffectIntArray,\n} from \"./effect.js\";\nexport type { GLEffectOptions, GLEffect } from \"./effect.js\";\nexport { waitForEffect } from \"./effect-ready.js\";\nexport type { GLEffectWaitOptions } from \"./effect-ready.js\";\n\n// ─── Effect renderer (fullscreen quad) ───────────────────────────────\nexport { createEffectWrapper, applyEffectWrapper, drawEffect, setViewport, disposeEffectWrapper } from \"./effect-renderer.js\";\nexport type { GLEffectWrapperOptions, GLEffectWrapper, GLViewport } from \"./effect-renderer.js\";\n\n// ─── Textures ────────────────────────────────────────────────────────\nexport {\n createRawTexture,\n createFloatTexture,\n generateTextureMipMaps,\n loadTexture2D,\n bindTexture,\n disposeTexture,\n updateRawTexture,\n updateTextureSamplingMode,\n updateTextureWrapMode,\n createTextureFromHandle,\n} from \"./texture.js\";\nexport type { GLTextureOptions, GLFloatTextureOptions, GLTexture } from \"./texture.js\";\nexport { createTextureFromSource } from \"./texture-source.js\";\nexport type { GLTextureSourceOptions } from \"./texture-source.js\";\nexport {\n createTexture3DFromPixels,\n bindTexture3D,\n setEffectTexture3D,\n generateTexture3DMipMaps,\n updateTexture3DSamplingMode,\n updateTexture3DWrapMode,\n disposeTexture3D,\n} from \"./texture-3d.js\";\nexport type { GLPixelsTexture3DOptions, GLTexture3D } from \"./texture-3d.js\";\n\n// ─── Dynamic textures ────────────────────────────────────────────────\nexport { createDynamicTexture, updateDynamicTexture, clearDynamicTextureSource } from \"./dynamic-texture.js\";\n\n// ─── Render targets ──────────────────────────────────────────────────\nexport {\n createRenderTarget,\n createFloatRenderTarget,\n bindRenderTarget,\n generateRenderTargetMipMaps,\n resizeRenderTarget,\n readRenderTargetPixels,\n disposeRenderTarget,\n} from \"./render-target.js\";\nexport type { GLRenderTarget, GLRenderTargetOptions, GLFloatRenderTargetOptions } from \"./render-target.js\";\n\n// ─── Meshes / buffers / instancing ───────────────────────────────────\nexport {\n createVertexBuffer,\n updateVertexBuffer,\n createIndexBuffer,\n disposeBuffer,\n bindIndexBuffer,\n bindAttributes,\n unbindInstanceAttributes,\n drawIndexed,\n createMeshVao,\n bindMeshVao,\n drawMesh,\n disposeMeshVao,\n} from \"./mesh.js\";\nexport type { GLVertexBuffer, GLIndexBuffer, GLAttributeDescriptor, GLMeshVertexBuffer, GLMeshVao } from \"./mesh.js\";\n\n// ─── Blend modes ─────────────────────────────────────────────────────\n// GLBlendMode / GLBlendEquation are const + same-name type; one value\n// re-export carries both.\nexport { GLBlendMode, GLBlendEquation, setBlendMode, setBlendState, disableBlend } from \"./blend.js\";\nexport type { GLBlendState } from \"./blend.js\";\n\n// ─── Depth / stencil / color-mask / clear ────────────────────────────\nexport { setDepthState, setCullState, setStencilState, setStencilOpSeparate, setColorMask, clearEngine, generateRenderTargetStencil } from \"./depth-stencil.js\";\nexport type { GLDepthState, GLStencilState, GLStencilOpState, GLClearOptions } from \"./depth-stencil.js\";\n\n// ─── Scissor ─────────────────────────────────────────────────────────\nexport { setScissor, disableScissor } from \"./scissor.js\";\n\n// ─── Sprites ─────────────────────────────────────────────────────────\nexport { createSpriteRenderer, renderSprites, setSpriteRendererTexture, disposeSpriteRenderer } from \"./sprites.js\";\nexport type { GLSprite, GLSpriteColor, GLSpriteRendererOptions, GLSpriteRenderer } from \"./sprites.js\";\n\n// ─── HTML-element textures ───────────────────────────────────────────\n// GLSamplingMode is a const + same-name type; one value re-export carries both.\nexport { createHtmlElementTexture, updateHtmlElementTexture, GLSamplingMode } from \"./html-texture.js\";\nexport type { GLHtmlElementTextureOptions } from \"./html-texture.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,gFAAgF;AAChF,EAAE;AACF,iFAAiF;AACjF,4EAA4E;AAC5E,2EAA2E;AAC3E,yEAAyE;AACzE,+DAA+D;AAC/D,EAAE;AACF,gFAAgF;AAChF,8EAA8E;AAC9E,wCAAwC;AAExC,wEAAwE;AACxE,OAAO,EACH,cAAc,EACd,eAAe,EACf,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,kBAAkB,GACrB,MAAM,cAAc,CAAC;AAGtB,uEAAuE;AACvE,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEvG,wEAAwE;AACxE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEjE,wEAAwE;AACxE,OAAO,EACH,YAAY,EACZ,SAAS,EACT,aAAa,EACb,yBAAyB,EACzB,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,eAAe,EACf,eAAe,E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O,EAAE,WAAW,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGrG,wEAAwE;AACxE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,YAAY,EAAE,WAAW,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAGhK,wEAAwE;AACxE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE1D,wEAAwE;AACxE,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAGpH,wEAAwE;AACxE,gFAAgF;AAChF,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAKvG,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAGnF,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAEtG,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtF,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAEnH,OAAO,EACH,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,UAAU,EACV,mBAAmB,EACnB,oBAAoB,EACpB,uBAAuB,EACvB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,GACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC","sourcesContent":["// @babylonjs/lite-gl — Public API\n// Function-based, tree-shakeable WebGL2 micro-engine. Import only what you use.\n//\n// Convention (mirrors @babylonjs/lite): the public API is re-exported EXPLICITLY\n// by name — never `export *`. This keeps the public surface intentional and\n// reviewable, lets `export type` mark type-only re-exports (required under\n// `isolatedModules`), and keeps internal helpers (e.g. `bindTextureRaw`,\n// `bindTextureForUpload`) out of consumers' bundles + `.d.ts`.\n//\n// The package is `sideEffects: false` and no module has top-level side effects,\n// so a consumer that imports only the symbols it needs tree-shakes everything\n// else (sprites, html-texture, …) away.\n\n// ─── Engine / context ────────────────────────────────────────────────\nexport {\n createGLEngine,\n disposeGLEngine,\n resizeGLEngine,\n setGLEngineSize,\n wipeGLStateCache,\n getRenderWidth,\n getRenderHeight,\n getHardwareScalingLevel,\n setHardwareScalingLevel,\n getRenderingCanvas,\n onContextLost,\n offContextLost,\n onContextRestored,\n offContextRestored,\n} from \"./context.js\";\nexport type { GLEngineOptions, GLEngineCaps, GLEngineContext } from \"./context.js\";\n\n// ─── Alpha-to-coverage (optional) ───────────────────────────────────\nexport { getAlphaToCoverage, getCurrentSampleCount, setAlphaToCoverage } from \"./alpha-to-coverage.js\";\n\n// ─── Render loop ─────────────────────────────────────────────────────\nexport { runRenderLoop, stopRenderLoop } from \"./render-loop.js\";\n\n// ─── Effects ─────────────────────────────────────────────────────────\nexport {\n createEffect,\n useEffect,\n isEffectReady,\n getEffectCompilationError,\n executeWhenCompiled,\n disposeEffect,\n setEffectFloat,\n setEffectFloat2,\n setEffectFloat3,\n setEffectFloat4,\n setEffectColor3,\n setEffectColor4,\n setEffectVector2,\n setEffectDirectColor4,\n setEffectInt,\n setEffectTexture,\n setEffectMatrix,\n setEffectMatrix3x3,\n setEffectFloatArray,\n setEffectFloatArray4,\n setEffectIntArray,\n} from \"./effect.js\";\nexport type { GLEffectOptions, GLEffect } from \"./effect.js\";\nexport { waitForEffect } from \"./effect-ready.js\";\nexport type { GLEffectWaitOptions } from \"./effect-ready.js\";\n\n// ─── Effect renderer (fullscreen quad) ───────────────────────────────\nexport { createEffectWrapper, applyEffectWrapper, drawEffect, setViewport, disposeEffectWrapper } from \"./effect-renderer.js\";\nexport type { GLEffectWrapperOptions, GLEffectWrapper, GLViewport } from \"./effect-renderer.js\";\n\n// ─── Textures ────────────────────────────────────────────────────────\nexport {\n createRawTexture,\n createFloatTexture,\n generateTextureMipMaps,\n loadTexture2D,\n bindTexture,\n disposeTexture,\n updateRawTexture,\n updateTextureSamplingMode,\n updateTextureWrapMode,\n createTextureFromHandle,\n} from \"./texture.js\";\nexport type { GLTextureOptions, GLFloatTextureOptions, GLTexture } from \"./texture.js\";\nexport { createTextureFromSource } from \"./texture-source.js\";\nexport type { GLTextureSourceOptions } from \"./texture-source.js\";\nexport {\n createTexture3DFromPixels,\n bindTexture3D,\n setEffectTexture3D,\n generateTexture3DMipMaps,\n updateTexture3DSamplingMode,\n updateTexture3DWrapMode,\n disposeTexture3D,\n} from \"./texture-3d.js\";\nexport type { GLPixelsTexture3DOptions, GLTexture3D } from \"./texture-3d.js\";\n\n// ─── Dynamic textures ────────────────────────────────────────────────\nexport { createDynamicTexture, updateDynamicTexture, clearDynamicTextureSource } from \"./dynamic-texture.js\";\n\n// ─── Render targets ──────────────────────────────────────────────────\nexport {\n createRenderTarget,\n createFloatRenderTarget,\n bindRenderTarget,\n generateRenderTargetMipMaps,\n resizeRenderTarget,\n readRenderTargetPixels,\n disposeRenderTarget,\n} from \"./render-target.js\";\nexport type { GLRenderTarget, GLRenderTargetOptions, GLFloatRenderTargetOptions } from \"./render-target.js\";\n\n// ─── Meshes / buffers / instancing ───────────────────────────────────\nexport {\n createVertexBuffer,\n updateVertexBuffer,\n createIndexBuffer,\n disposeBuffer,\n bindIndexBuffer,\n bindAttributes,\n unbindInstanceAttributes,\n drawIndexed,\n createMeshVao,\n bindMeshVao,\n drawMesh,\n disposeMeshVao,\n} from \"./mesh.js\";\nexport type { GLVertexBuffer, GLIndexBuffer, GLAttributeDescriptor, GLMeshVertexBuffer, GLMeshVao } from \"./mesh.js\";\n\n// ─── Blend modes ─────────────────────────────────────────────────────\n// GLBlendMode / GLBlendEquation are const + same-name type; one value\n// re-export carries both.\nexport { GLBlendMode, GLBlendEquation, setBlendMode, setBlendState, disableBlend } from \"./blend.js\";\nexport type { GLBlendState } from \"./blend.js\";\n\n// ─── Depth / stencil / color-mask / clear ────────────────────────────\nexport { setDepthState, setCullState, setStencilState, setStencilOpSeparate, setColorMask, clearEngine, generateRenderTargetStencil } from \"./depth-stencil.js\";\nexport type { GLDepthState, GLStencilState, GLStencilOpState, GLClearOptions } from \"./depth-stencil.js\";\n\n// ─── Scissor ─────────────────────────────────────────────────────────\nexport { setScissor, disableScissor } from \"./scissor.js\";\n\n// ─── Sprites ─────────────────────────────────────────────────────────\nexport { createSpriteRenderer, renderSprites, setSpriteRendererTexture, disposeSpriteRenderer } from \"./sprites.js\";\nexport type { GLSprite, GLSpriteColor, GLSpriteRendererOptions, GLSpriteRenderer } from \"./sprites.js\";\n\n// ─── HTML-element textures ───────────────────────────────────────────\n// GLSamplingMode is a const + same-name type; one value re-export carries both.\nexport { createHtmlElementTexture, updateHtmlElementTexture, GLSamplingMode } from \"./html-texture.js\";\nexport type { GLHtmlElementTextureOptions } from \"./html-texture.js\";\n\n// ─── Text (analytic Slug coverage) ───────────────────────────────────\nexport type { GLFont } from \"./text/font.js\";\nexport { loadFont, createFontFromBuffer } from \"./text/font.js\";\nexport { extractGlyphCurves, cubicToQuadratics } from \"./text/glyph-extraction.js\";\nexport type { GLTextLayoutOptions } from \"./text/layout.js\";\nexport type { GLGlyphStorage, GLCurveSetId, GLQuadCurve, GLGlyphBounds, GLGlyphCurves } from \"./text/glyph-storage.js\";\nexport { createGlyphStorage, updateGlyphStorage, disposeGlyphStorage } from \"./text/glyph-storage.js\";\nexport type { GLTextData, GLPlacedGlyph, GLGlyphRun, GLTextDataUpdate } from \"./text/text-data.js\";\nexport { createTextData, updateTextData, disposeTextData } from \"./text/text-data.js\";\nexport type { GLDefaultTextData } from \"./text/default-text-data.js\";\nexport { createDefaultTextData, updateDefaultTextData, disposeDefaultTextData } from \"./text/default-text-data.js\";\nexport type { GLTextLayer, GLTextLayerOptions, GLTextRenderer, GLTextRendererOptions } from \"./text/text-renderer.js\";\nexport {\n createTextLayer,\n setTextLayerPosition,\n createTextRenderer,\n renderText,\n isTextRendererReady,\n addTextRendererLayer,\n removeTextRendererLayer,\n registerTextRenderer,\n unregisterTextRenderer,\n disposeTextRenderer,\n} from \"./text/text-renderer.js\";\nexport { setFontWeightOffset } from \"./text/set-font-weight-offset.js\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babylonjs/lite-gl",
3
- "version": "1.19.0",
3
+ "version": "1.20.0",
4
4
  "description": "Function-based, tree-shakeable WebGL2 micro-engine for fullscreen effects, sprites and dynamic textures — the WebGL counterpart of @babylonjs/lite.",
5
5
  "keywords": [
6
6
  "babylon",
@@ -25,6 +25,9 @@
25
25
  "module": "./index.js",
26
26
  "types": "./index.d.ts",
27
27
  "sideEffects": false,
28
+ "dependencies": {
29
+ "text-shaper": "^0.1.28"
30
+ },
28
31
  "exports": {
29
32
  ".": {
30
33
  "import": "./index.js",
@@ -32,7 +35,7 @@
32
35
  }
33
36
  },
34
37
  "babylonLiteRelease": {
35
- "azureBuildId": "61366",
36
- "sourceVersion": "1a2728c6d44383ef3a79cfc680e2e761b4f1e986"
38
+ "azureBuildId": "61732",
39
+ "sourceVersion": "3628bac1f882a6afb9db850d75364415e80cb992"
37
40
  }
38
41
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,70 @@
1
+ import { createEffect, setEffectFloat4, setEffectMatrix, useEffect } from "../../effect.js";
2
+ import { composeSlugShader } from "../shaders/slug-shader.js";
3
+ let programs = null;
4
+ let baseShader = null;
5
+ /** @internal Optional feature-owned variant factory. */
6
+ export let _createTextVariant = null;
7
+ /** @internal */
8
+ export function _installTextVariantResolver(factory) {
9
+ _createTextVariant = factory;
10
+ }
11
+ /** @internal Acquires one effect reference for this renderer. */
12
+ export function createTextProgram(engine, shader) {
13
+ const source = shader ?? (baseShader ??= composeSlugShader(null));
14
+ const effect = createEffect(engine, {
15
+ name: "text-slug" + source._key,
16
+ vertexSource: source._vert,
17
+ fragmentSource: source._frag,
18
+ uniformNames: ["mvp", "viewport", "color"],
19
+ samplerNames: ["curveTex", "bandTex", "glyphMetadata", "styles"],
20
+ attributeNames: ["corner", "anchor", "glyphStyle"],
21
+ });
22
+ const cache = (programs ??= new WeakMap());
23
+ let program = cache.get(effect);
24
+ if (!program) {
25
+ program = { _effect: effect, _uploadedProgram: null, _mvpInputs: new Float64Array(6), _mvp: new Float32Array(16) };
26
+ cache.set(effect, program);
27
+ }
28
+ return program;
29
+ }
30
+ /** @internal Skip unchanged projection work and uploads; relink always invalidates the cache. */
31
+ export function uploadTextUniforms(engine, program, layer, width, height) {
32
+ const effect = program._effect;
33
+ useEffect(engine, effect);
34
+ const inputs = program._mvpInputs;
35
+ const px = layer.positionPx.x;
36
+ const py = layer.positionPx.y;
37
+ const rotation = layer.rotationRad;
38
+ const scale = layer.scale;
39
+ if (program._uploadedProgram !== effect.program ||
40
+ inputs[0] !== px ||
41
+ inputs[1] !== py ||
42
+ inputs[2] !== rotation ||
43
+ inputs[3] !== scale ||
44
+ inputs[4] !== width ||
45
+ inputs[5] !== height) {
46
+ const mvp = program._mvp;
47
+ const cx = (2 * scale) / width;
48
+ const cy = (2 * scale) / height;
49
+ const cr = Math.cos(rotation);
50
+ const sr = Math.sin(rotation);
51
+ mvp[0] = cx * cr;
52
+ mvp[1] = -cy * sr;
53
+ mvp[4] = cx * sr;
54
+ mvp[5] = cy * cr;
55
+ mvp[10] = mvp[15] = 1;
56
+ mvp[12] = (2 * px) / width - 1;
57
+ mvp[13] = 1 - (2 * py) / height;
58
+ setEffectMatrix(engine, effect, "mvp", mvp);
59
+ inputs[0] = px;
60
+ inputs[1] = py;
61
+ inputs[2] = rotation;
62
+ inputs[3] = scale;
63
+ inputs[4] = width;
64
+ inputs[5] = height;
65
+ program._uploadedProgram = effect.program;
66
+ }
67
+ setEffectFloat4(engine, effect, "viewport", width, height, 0, 0);
68
+ setEffectFloat4(engine, effect, "color", layer.coverageGamma > 0 ? 1 / layer.coverageGamma : 1, 1, 1, layer.opacity);
69
+ }
70
+ //# sourceMappingURL=text-effect.js.map
@@ -0,0 +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,MAAM,2BAA2B,CAAC;AAe9D,IAAI,QAAQ,GAA0C,IAAI,CAAC;AAC3D,IAAI,UAAU,GAA8B,IAAI,CAAC;AAEjD,wDAAwD;AACxD,MAAM,CAAC,IAAI,kBAAkB,GAAsD,IAAI,CAAC;AAExF,gBAAgB;AAChB,MAAM,UAAU,2BAA2B,CAAC,OAAiD;IACzF,kBAAkB,GAAG,OAAO,CAAC;AACjC,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,iBAAiB,CAAC,MAAuB,EAAE,MAA2B;IAClF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,KAAK,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;IAClE,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,EAAE;QAChC,IAAI,EAAE,WAAW,GAAG,MAAM,CAAC,IAAI;QAC/B,YAAY,EAAE,MAAM,CAAC,KAAK;QAC1B,cAAc,EAAE,MAAM,CAAC,KAAK;QAC5B,YAAY,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC;QAC1C,YAAY,EAAE,CAAC,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,QAAQ,CAAC;QAChE,cAAc,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,CAAC;KACrD,CAAC,CAAC;IACH,MAAM,KAAK,GAAG,CAAC,QAAQ,KAAK,IAAI,OAAO,EAA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AC9C,CAAC;IACD,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACjE,eAAe,CAAC,MAAM,EAAE,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;AACzH,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(engine: GLEngineContext, program: TextProgram, layer: GLTextLayer, width: number, height: number): void {\n const effect = program._effect;\n useEffect(engine, 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(engine, 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(engine, effect, \"viewport\", width, height, 0, 0);\n setEffectFloat4(engine, effect, \"color\", layer.coverageGamma > 0 ? 1 / layer.coverageGamma : 1, 1, 1, layer.opacity);\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,57 @@
1
+ import { createVertexBuffer, disposeBuffer, updateVertexBuffer } from "../../mesh.js";
2
+ import { TEXT_INSTANCE_BYTES, TEXT_INSTANCE_FLOATS, TEXT_STYLE_FLOATS } from "../text-data.js";
3
+ import { createTextTexture, packTable, TABLE_WIDTH, uploadTextTexture } from "./text-textures.js";
4
+ /** @internal One upload per data mutation, even when several layers share the data. */
5
+ export function ensureTextDataGpu(engine, data) {
6
+ let gpu = data._gpu;
7
+ if (gpu && gpu._engine !== engine) {
8
+ throw new Error("lite-gl: text data cannot be drawn on multiple engines. Create separate text data for each engine.");
9
+ }
10
+ if (!gpu) {
11
+ const pixels = packTable(data._styles, data._styleCount * TEXT_STYLE_FLOATS);
12
+ const buffer = createVertexBuffer(engine, data._instances, true);
13
+ try {
14
+ gpu = {
15
+ _engine: engine,
16
+ _instanceBuf: buffer,
17
+ _styleTex: createTextTexture(engine, pixels, TABLE_WIDTH, pixels.length / (TABLE_WIDTH * 4)),
18
+ _stylePixels: pixels,
19
+ _uploadedVersion: data._version,
20
+ _uploadedStyleVersion: data._styleVersion,
21
+ };
22
+ data._gpu = gpu;
23
+ }
24
+ catch (error) {
25
+ disposeBuffer(engine, buffer);
26
+ throw error;
27
+ }
28
+ }
29
+ else if (gpu._instanceBuf._data !== data._instances) {
30
+ // Retain the live CPU pool, including partial edits, for context restoration.
31
+ const buffer = createVertexBuffer(engine, data._instances, true);
32
+ disposeBuffer(engine, gpu._instanceBuf);
33
+ gpu._instanceBuf = buffer;
34
+ gpu._uploadedVersion = data._version;
35
+ }
36
+ else if (gpu._uploadedVersion !== data._version) {
37
+ if (data._dirtyEnd > data._dirtyStart) {
38
+ const start = data._dirtyStart * TEXT_INSTANCE_FLOATS;
39
+ const end = data._dirtyEnd * TEXT_INSTANCE_FLOATS;
40
+ const source = start === 0 && end === data._instances.length ? data._instances : data._instances.subarray(start, end);
41
+ updateVertexBuffer(engine, gpu._instanceBuf, source, data._dirtyStart * TEXT_INSTANCE_BYTES);
42
+ }
43
+ else {
44
+ updateVertexBuffer(engine, gpu._instanceBuf, data._instances);
45
+ }
46
+ gpu._uploadedVersion = data._version;
47
+ }
48
+ data._dirtyStart = data._dirtyEnd = 0;
49
+ if (gpu._uploadedStyleVersion !== data._styleVersion) {
50
+ const pixels = packTable(data._styles, data._styleCount * TEXT_STYLE_FLOATS, gpu._stylePixels);
51
+ uploadTextTexture(engine, gpu._styleTex, pixels, TABLE_WIDTH, pixels.length / (TABLE_WIDTH * 4));
52
+ gpu._stylePixels = pixels;
53
+ gpu._uploadedStyleVersion = data._styleVersion;
54
+ }
55
+ return gpu;
56
+ }
57
+ //# sourceMappingURL=text-instances.js.map
@@ -0,0 +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,CAAC;QACP,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,GAAG,iBAAiB,CAAC,CAAC;QAC7E,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QACjE,IAAI,CAAC;YACD,GAAG,GAAG;gBACF,OAAO,EAAE,MAAM;gBACf,YAAY,EAAE,MAAM;gBACpB,SAAS,EAAE,iBAAiB,CAAC,MAAM,EAAE,MAA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,MAAM,EAAE,GAAG,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,CAAC,WAAW,GAAG,mBAAmB,CAAC,CAAC;QACjG,CAAC;aAAM,CAAC;YACJ,kBAAkB,CAAC,MAAM,EAAE,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAClE,CAAC;QACD,GAAG,CAAC,gBAAgB,GAAG,IAAI,CAAC,QAAQ,CAAC;IACzC,CAAC;IACD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;IACtC,IAAI,GAAG,CAAC,qBAAqB,KAAK,IAAI,CAAC,aAAa,EAAE,CAAC;QACnD,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,GAAG,iBAAiB,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC;QAC/F,iBAAiB,CAAC,MAAM,EAAE,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC;QACjG,GAAG,CAAC,YAAY,GAAG,MAAM,CAAC;QAC1B,GAAG,CAAC,qBAAqB,GAAG,IAAI,CAAC,aAAa,CAAC;IACnD,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC","sourcesContent":["import type { GLEngineContext } from \"../../context.js\";\nimport { createVertexBuffer, disposeBuffer, updateVertexBuffer } from \"../../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(engine, 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(engine, 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(engine, gpu._instanceBuf, source, data._dirtyStart * TEXT_INSTANCE_BYTES);\n } else {\n updateVertexBuffer(engine, 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"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,82 @@
1
+ import { createRawTexture, disposeTexture, updateRawTexture } from "../../texture.js";
2
+ import { GLYPH_METADATA_FLOATS, TEX_WIDTH } from "../glyph-storage.js";
3
+ /** @internal Lookup textures replace the WebGPU metadata/style storage buffers. */
4
+ export const TABLE_WIDTH = 256;
5
+ /** @internal Pad a lookup table to complete rows, retaining its existing allocation. */
6
+ export function packTable(source, floatCount, previous) {
7
+ const length = Math.max(1, Math.ceil(floatCount / (TABLE_WIDTH * 4))) * TABLE_WIDTH * 4;
8
+ const pixels = previous && previous.length >= length ? previous : new Float32Array(length);
9
+ pixels.set(source.subarray(0, floatCount));
10
+ return pixels;
11
+ }
12
+ function checkSize(engine, width, height) {
13
+ if (width > engine.caps.maxTextureSize || height > engine.caps.maxTextureSize) {
14
+ throw new Error(`lite-gl: text texture ${width}x${height} exceeds MAX_TEXTURE_SIZE ${engine.caps.maxTextureSize}.`);
15
+ }
16
+ }
17
+ /** @internal Numeric tables use nearest-only RG uint or RGBA float texels. */
18
+ export function createTextTexture(engine, pixels, width, height) {
19
+ checkSize(engine, width, height);
20
+ const gl = engine.gl;
21
+ const integer = pixels instanceof Uint32Array;
22
+ return createRawTexture(engine, pixels, width, height, integer ? gl.RG_INTEGER : gl.RGBA, integer ? gl.UNSIGNED_INT : gl.FLOAT, {
23
+ internalFormat: integer ? gl.RG32UI : gl.RGBA32F,
24
+ minFilter: gl.NEAREST,
25
+ magFilter: gl.NEAREST,
26
+ });
27
+ }
28
+ /** @internal Preserve the texture object and its context-restore upload source. */
29
+ export function uploadTextTexture(engine, texture, pixels, width, height) {
30
+ checkSize(engine, width, height);
31
+ updateRawTexture(engine, texture, pixels, { width, height });
32
+ }
33
+ /** @internal Atlas resources are shared by every block using the same curve set. */
34
+ export function ensureSharedAtlasGpu(engine, atlas) {
35
+ let gpu = atlas._gpu;
36
+ if (gpu) {
37
+ if (gpu._engine !== engine) {
38
+ throw new Error("lite-gl: a glyph storage cannot be drawn on multiple engines. Create a separate storage for each engine.");
39
+ }
40
+ if (gpu._uploadedVersion === atlas._version) {
41
+ return gpu;
42
+ }
43
+ }
44
+ const curveRows = Math.max(1, Math.ceil(atlas._curveTexelsUsed / TEX_WIDTH));
45
+ const bandRows = Math.max(1, Math.ceil(atlas._bandTexelsUsed / TEX_WIDTH));
46
+ checkSize(engine, TEX_WIDTH, Math.max(curveRows, bandRows));
47
+ const metaPixels = packTable(atlas._metaData, atlas._slotCount * GLYPH_METADATA_FLOATS, gpu?._metaPixels);
48
+ const metaRows = metaPixels.length / (TABLE_WIDTH * 4);
49
+ checkSize(engine, TABLE_WIDTH, metaRows);
50
+ if (!gpu) {
51
+ const textures = [];
52
+ try {
53
+ textures.push(createTextTexture(engine, atlas._curveTexData, TEX_WIDTH, curveRows));
54
+ textures.push(createTextTexture(engine, atlas._bandTexData, TEX_WIDTH, bandRows));
55
+ textures.push(createTextTexture(engine, metaPixels, TABLE_WIDTH, metaRows));
56
+ gpu = {
57
+ _engine: engine,
58
+ _curveTex: textures[0],
59
+ _bandTex: textures[1],
60
+ _metaTex: textures[2],
61
+ _metaPixels: metaPixels,
62
+ _uploadedVersion: atlas._version,
63
+ };
64
+ atlas._gpu = gpu;
65
+ }
66
+ catch (error) {
67
+ for (const texture of textures) {
68
+ disposeTexture(engine, texture);
69
+ }
70
+ throw error;
71
+ }
72
+ }
73
+ else {
74
+ uploadTextTexture(engine, gpu._curveTex, atlas._curveTexData, TEX_WIDTH, curveRows);
75
+ uploadTextTexture(engine, gpu._bandTex, atlas._bandTexData, TEX_WIDTH, bandRows);
76
+ uploadTextTexture(engine, gpu._metaTex, metaPixels, TABLE_WIDTH, metaRows);
77
+ gpu._metaPixels = metaPixels;
78
+ gpu._uploadedVersion = atlas._version;
79
+ }
80
+ return gpu;
81
+ }
82
+ //# sourceMappingURL=text-textures.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-textures.js","sourceRoot":"","sources":["../../../src/text/_gpu/text-textures.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEtF,OAA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AAO,KAAK,EAAE,CAAC;YACb,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;gBAC7B,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACpC,CAAC;YACD,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;SAAM,CAAC;QACJ,iBAAiB,CAAC,MAAM,EAAE,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,aAAa,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;QACpF,iBAAiB,CAAC,MAAM,EAAE,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,YAAY,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;QACjF,iBAAiB,CAAC,MAAM,EAAE,GAAG,CAAC,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;QAC3E,GAAG,CAAC,WAAW,GAAG,UAAU,CAAC;QAC7B,GAAG,CAAC,gBAAgB,GAAG,KAAK,CAAC,QAAQ,CAAC;IAC1C,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC","sourcesContent":["import type { GLEngineContext } from \"../../context.js\";\nimport { createRawTexture, disposeTexture, updateRawTexture } from \"../../texture.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, integer ? gl.RG_INTEGER : gl.RGBA, 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(engine, 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(engine, 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"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,49 @@
1
+ import { TEXT_INSTANCE_BYTES } from "../text-data.js";
2
+ /** @internal */
3
+ export function disposeTextVao(engine, vao) {
4
+ if (!engine._isLost && !engine._disposed) {
5
+ if (engine._state.boundVao === vao._handle) {
6
+ engine.gl.bindVertexArray(null);
7
+ engine._state.boundVao = null;
8
+ engine._state.boundElementBuffer = null;
9
+ }
10
+ engine.gl.deleteVertexArray(vao._handle);
11
+ }
12
+ }
13
+ /** @internal */
14
+ export function bindTextVao(engine, quad, instances, slotStart, previous) {
15
+ const gl = engine.gl;
16
+ const state = engine._state;
17
+ let vao = previous;
18
+ if (!vao || vao._quad !== quad.handle || vao._instances !== instances.handle || vao._slotStart !== slotStart) {
19
+ const handle = gl.createVertexArray();
20
+ if (!handle) {
21
+ throw new Error("lite-gl: gl.createVertexArray returned null (text)");
22
+ }
23
+ if (vao) {
24
+ disposeTextVao(engine, vao);
25
+ }
26
+ vao = { _handle: handle, _quad: quad.handle, _instances: instances.handle, _slotStart: slotStart };
27
+ gl.bindVertexArray(handle);
28
+ gl.bindBuffer(gl.ARRAY_BUFFER, quad.handle);
29
+ gl.enableVertexAttribArray(0);
30
+ gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 8, 0);
31
+ gl.bindBuffer(gl.ARRAY_BUFFER, instances.handle);
32
+ gl.enableVertexAttribArray(1);
33
+ gl.vertexAttribPointer(1, 2, gl.FLOAT, false, TEXT_INSTANCE_BYTES, slotStart * TEXT_INSTANCE_BYTES);
34
+ gl.vertexAttribDivisor(1, 1);
35
+ gl.enableVertexAttribArray(2);
36
+ gl.vertexAttribIPointer(2, 1, gl.UNSIGNED_INT, TEXT_INSTANCE_BYTES, slotStart * TEXT_INSTANCE_BYTES + 8);
37
+ gl.vertexAttribDivisor(2, 1);
38
+ state.boundArrayBuffer = instances.handle;
39
+ state.boundVao = handle;
40
+ state.boundElementBuffer = null;
41
+ }
42
+ else if (state.boundVao !== vao._handle) {
43
+ gl.bindVertexArray(vao._handle);
44
+ state.boundVao = vao._handle;
45
+ state.boundElementBuffer = null;
46
+ }
47
+ return vao;
48
+ }
49
+ //# sourceMappingURL=text-vao.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-vao.js","sourceRoot":"","sources":["../../../src/text/_gpu/text-vao.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AActD,gBAAgB;AAChB,MAAM,UAAU,cAAc,CAAC,MAAuB,EAAE,GAAY;IAChE,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;QACvC,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC;YACzC,MAAM,CAAC,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;YAChC,MAAM,CAAC,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC;YAC9B,MAAM,CAAC,MAAM,CAAC,kBAAkB,GAAG,IAAI,CAAC;QAC5C,CAAC;QACD,MAAM,CAAC,EAAE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,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;QACjD,EAAE,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC;QAC9B,EAAE,CAAC,mBAAmB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,mBAAmB,EAAE,SAAS,GAAG,mBAAmB,CAAC,CAAC;QACpG,EAAE,CAAC,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC7B,EAAE,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC;QAC9B,EAAE,CAAC,oBAAoB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,YAAY,EAAE,mBAAmB,EAAE,SAAS,GAAG,mBAAmB,GAAG,CAAC,CAAC,CAAC;QACzG,EAAE,CAAC,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC7B,KAAK,CAAC,gBAAgB,GAAG,SAAS,CAAC,MAAM,CAAC;QAC1C,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC;QACxB,KAAK,CAAC,kBAAkB,GAAG,IAAI,CAAC;IACpC,CAAC;SAAM,IAAI,KAAK,CAAC,QAAQ,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC;QACxC,EAAE,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAChC,KAAK,CAAC,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC;QAC7B,KAAK,CAAC,kBAAkB,GAAG,IAAI,CAAC;IACpC,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC","sourcesContent":["import type { GLEngineContext } from \"../../context.js\";\nimport type { GLVertexBuffer } from \"../../mesh.js\";\nimport { TEXT_INSTANCE_BYTES } from \"../text-data.js\";\n\n/** @internal WebGL2 has no base-instance draw; cache the group's attribute offsets in a VAO. */\nexport interface TextVao {\n /** @internal */\n _handle: WebGLVertexArrayObject;\n /** @internal */\n _quad: WebGLBuffer;\n /** @internal */\n _instances: WebGLBuffer;\n /** @internal */\n _slotStart: number;\n}\n\n/** @internal */\nexport function disposeTextVao(engine: GLEngineContext, vao: TextVao): void {\n if (!engine._isLost && !engine._disposed) {\n if (engine._state.boundVao === vao._handle) {\n engine.gl.bindVertexArray(null);\n engine._state.boundVao = null;\n engine._state.boundElementBuffer = null;\n }\n engine.gl.deleteVertexArray(vao._handle);\n }\n}\n\n/** @internal */\nexport function bindTextVao(engine: GLEngineContext, quad: GLVertexBuffer, instances: GLVertexBuffer, slotStart: number, previous?: TextVao): TextVao {\n const gl = engine.gl;\n const state = engine._state;\n let vao = previous;\n if (!vao || vao._quad !== quad.handle || vao._instances !== instances.handle || vao._slotStart !== slotStart) {\n const handle = gl.createVertexArray();\n if (!handle) {\n throw new Error(\"lite-gl: gl.createVertexArray returned null (text)\");\n }\n if (vao) {\n disposeTextVao(engine, vao);\n }\n vao = { _handle: handle, _quad: quad.handle, _instances: instances.handle, _slotStart: slotStart };\n gl.bindVertexArray(handle);\n gl.bindBuffer(gl.ARRAY_BUFFER, quad.handle);\n gl.enableVertexAttribArray(0);\n gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 8, 0);\n gl.bindBuffer(gl.ARRAY_BUFFER, instances.handle);\n gl.enableVertexAttribArray(1);\n gl.vertexAttribPointer(1, 2, gl.FLOAT, false, TEXT_INSTANCE_BYTES, slotStart * TEXT_INSTANCE_BYTES);\n gl.vertexAttribDivisor(1, 1);\n gl.enableVertexAttribArray(2);\n gl.vertexAttribIPointer(2, 1, gl.UNSIGNED_INT, TEXT_INSTANCE_BYTES, slotStart * TEXT_INSTANCE_BYTES + 8);\n gl.vertexAttribDivisor(2, 1);\n state.boundArrayBuffer = instances.handle;\n state.boundVao = handle;\n state.boundElementBuffer = null;\n } else if (state.boundVao !== vao._handle) {\n gl.bindVertexArray(vao._handle);\n state.boundVao = vao._handle;\n state.boundElementBuffer = null;\n }\n return vao;\n}\n"]}
@@ -0,0 +1,28 @@
1
+ /** Default convenience GLTextData: shapes text + extracts curves into a fresh GLGlyphStorage. */
2
+ import type { GLFont } from "./font.js";
3
+ import type { GLTextData } from "./text-data.js";
4
+ import type { GLTextLayoutOptions } from "./layout.js";
5
+ declare const defaultTextDataBrand: unique symbol;
6
+ /** Convenience text-data variant that owns its `GLGlyphStorage` and exposes the laid-out
7
+ * pixel-space `width` / `height` of the text block. Produced by `createDefaultTextData`. */
8
+ export interface GLDefaultTextData extends GLTextData {
9
+ readonly [defaultTextDataBrand]: true;
10
+ /** Pixel-space width of the laid-out run (max line width). */
11
+ readonly width: number;
12
+ /** Pixel-space height of the laid-out run (lines × line-height). */
13
+ readonly height: number;
14
+ }
15
+ /** Shape `text` with the default layout, extract glyph curves, and bundle into a
16
+ * `GLDefaultTextData`. `textColor` is applied as the run's defaultColor (per-glyph color
17
+ * overrides remain available via direct `updateTextData(replaceRun)` calls).
18
+ *
19
+ * The returned `GLDefaultTextData` owns its underlying `GLGlyphStorage` — release both with
20
+ * `disposeDefaultTextData(data)`. */
21
+ export declare function createDefaultTextData(font: GLFont, fontSizePx: number, text: string, textColor?: readonly [number, number, number, number], options?: GLTextLayoutOptions): GLDefaultTextData;
22
+ /** Re-shape `text` and apply the new run via `updateTextData(replaceRun)`. New glyphs are
23
+ * added to the storage in place. When `textColor` is omitted, the live run's existing
24
+ * `defaultColor` is preserved (so any caller-driven color override survives a text re-shape). */
25
+ export declare function updateDefaultTextData(data: GLDefaultTextData, text: string, textColor?: readonly [number, number, number, number]): void;
26
+ /** Release the per-block GPU resources AND the underlying `GLGlyphStorage` owned by `data`. */
27
+ export declare function disposeDefaultTextData(data: GLDefaultTextData): void;
28
+ export {};
@@ -0,0 +1,103 @@
1
+ /** Default convenience GLTextData: shapes text + extracts curves into a fresh GLGlyphStorage. */
2
+ import { extractGlyphCurves } from "./glyph-extraction.js";
3
+ import { createGlyphStorage, disposeGlyphStorage, updateGlyphStorage } from "./glyph-storage.js";
4
+ import { createTextData, disposeTextData, updateTextData } from "./text-data.js";
5
+ import { layoutText } from "./layout.js";
6
+ import { getFontFamily } from "text-shaper";
7
+ /** Mark every glyph in `glyphs` as seen, returning only the ids not seen before, or `null`
8
+ * when there are none.
9
+ *
10
+ * Re-shaped text almost always reuses the repertoire it already had — an 840-cell grid of
11
+ * changing numbers is ~37 distinct glyphs across 5,466 placements — so the common answer is
12
+ * "nothing new". Answering that with a typed-array probe per glyph keeps the steady state
13
+ * allocation free and lets the caller skip extraction and storage update entirely. That
14
+ * matters more than it looks: `extractGlyphCurves` only early-outs on ids already in the
15
+ * target map, so passing it a fresh map every call made it re-walk the whole repertoire, and
16
+ * glyphs with no outline (space) were re-extracted forever because an absent outline is
17
+ * never cached.
18
+ *
19
+ * A glyph id at or beyond `seen.length` reads `undefined`, which is not `=== 0`, so it is
20
+ * treated as already seen and never reaches extraction. That matches the old behaviour
21
+ * observably: `extractGlyphCurves` asks `extractOne` for such an id, gets `null`, and skips
22
+ * it without recording anything. */
23
+ function collectNewGlyphs(seen, glyphs) {
24
+ let added = null;
25
+ for (const g of glyphs) {
26
+ const id = g.glyphId;
27
+ if (seen[id] === 0) {
28
+ seen[id] = 1;
29
+ (added ??= new Set()).add(id);
30
+ }
31
+ }
32
+ return added;
33
+ }
34
+ /** Derive the curve-set id from the font's family name (e.g. "Inter", "Roboto"). Falls back
35
+ * to `"font"` for fonts that lack a usable name table. */
36
+ function familyCurveSetId(font) {
37
+ return (font._font.name && getFontFamily(font._font.name)) || "font";
38
+ }
39
+ /** Shape `text` with the default layout, extract glyph curves, and bundle into a
40
+ * `GLDefaultTextData`. `textColor` is applied as the run's defaultColor (per-glyph color
41
+ * overrides remain available via direct `updateTextData(replaceRun)` calls).
42
+ *
43
+ * The returned `GLDefaultTextData` owns its underlying `GLGlyphStorage` — release both with
44
+ * `disposeDefaultTextData(data)`. */
45
+ export function createDefaultTextData(font, fontSizePx, text, textColor, options) {
46
+ const laid = layoutText(font, text, fontSizePx, options);
47
+ const innerCurves = new Map();
48
+ const seenGlyphs = new Uint8Array(font._font.numGlyphs);
49
+ const ids = collectNewGlyphs(seenGlyphs, laid._glyphs);
50
+ if (ids) {
51
+ extractGlyphCurves(font, ids, innerCurves);
52
+ }
53
+ const curveSetId = familyCurveSetId(font);
54
+ const storage = createGlyphStorage(new Map([[curveSetId, innerCurves]]));
55
+ const run = {
56
+ curveSet: curveSetId,
57
+ glyphs: laid._glyphs,
58
+ pixelsPerFontUnit: laid._pixelsPerFontUnit,
59
+ defaultColor: textColor,
60
+ };
61
+ return Object.assign(createTextData(storage, [run]), {
62
+ width: laid._width,
63
+ height: laid._height,
64
+ _font: font,
65
+ _fontSizePx: fontSizePx,
66
+ _options: options,
67
+ _curveSetId: curveSetId,
68
+ _storage: storage,
69
+ _seenGlyphs: seenGlyphs,
70
+ });
71
+ }
72
+ /** Re-shape `text` and apply the new run via `updateTextData(replaceRun)`. New glyphs are
73
+ * added to the storage in place. When `textColor` is omitted, the live run's existing
74
+ * `defaultColor` is preserved (so any caller-driven color override survives a text re-shape). */
75
+ export function updateDefaultTextData(data, text, textColor) {
76
+ const laid = layoutText(data._font, text, data._fontSizePx, data._options);
77
+ // Extract any glyph outlines this data has not offered to the storage before. Text that
78
+ // reuses its existing repertoire — the overwhelmingly common case — does no work here.
79
+ const ids = collectNewGlyphs(data._seenGlyphs, laid._glyphs);
80
+ if (ids) {
81
+ const innerCurves = new Map();
82
+ extractGlyphCurves(data._font, ids, innerCurves);
83
+ updateGlyphStorage(data._storage, data._curveSetId, innerCurves);
84
+ }
85
+ // Always use the current `data.runs[0]` as the previous reference; a GLDefaultTextData
86
+ // owns exactly one run and the caller may have swapped it out via their own ops.
87
+ const previousRun = data.runs[0];
88
+ const newRun = {
89
+ curveSet: data._curveSetId,
90
+ glyphs: laid._glyphs,
91
+ pixelsPerFontUnit: laid._pixelsPerFontUnit,
92
+ defaultColor: textColor ?? previousRun.defaultColor,
93
+ };
94
+ updateTextData(data, { update: "replaceRun", previous: previousRun, run: newRun });
95
+ // Refresh the cached width/height on the branded object.
96
+ Object.assign(data, { width: laid._width, height: laid._height });
97
+ }
98
+ /** Release the per-block GPU resources AND the underlying `GLGlyphStorage` owned by `data`. */
99
+ export function disposeDefaultTextData(data) {
100
+ disposeTextData(data);
101
+ disposeGlyphStorage(data._storage);
102
+ }
103
+ //# sourceMappingURL=default-text-data.js.map