@babylonjs/lite-gl 1.18.0 → 1.20.0-preview
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/CHANGELOG.md +1350 -0
- package/LICENSE +201 -0
- package/README.md +31 -0
- package/index.d.ts +13 -0
- package/index.js +7 -0
- package/index.js.map +1 -1
- package/package.json +9 -3
- package/text/_gpu/text-effect.d.ts +1 -0
- package/text/_gpu/text-effect.js +70 -0
- package/text/_gpu/text-effect.js.map +1 -0
- package/text/_gpu/text-instances.d.ts +1 -0
- package/text/_gpu/text-instances.js +57 -0
- package/text/_gpu/text-instances.js.map +1 -0
- package/text/_gpu/text-textures.d.ts +1 -0
- package/text/_gpu/text-textures.js +82 -0
- package/text/_gpu/text-textures.js.map +1 -0
- package/text/_gpu/text-vao.d.ts +1 -0
- package/text/_gpu/text-vao.js +49 -0
- package/text/_gpu/text-vao.js.map +1 -0
- package/text/default-text-data.d.ts +28 -0
- package/text/default-text-data.js +103 -0
- package/text/default-text-data.js.map +1 -0
- package/text/font.d.ts +16 -0
- package/text/font.js +24 -0
- package/text/font.js.map +1 -0
- package/text/glyph-extraction.d.ts +19 -0
- package/text/glyph-extraction.js +115 -0
- package/text/glyph-extraction.js.map +1 -0
- package/text/glyph-storage.d.ts +68 -0
- package/text/glyph-storage.js +298 -0
- package/text/glyph-storage.js.map +1 -0
- package/text/layout.d.ts +18 -0
- package/text/layout.js +219 -0
- package/text/layout.js.map +1 -0
- package/text/set-font-weight-offset.d.ts +5 -0
- package/text/set-font-weight-offset.js +67 -0
- package/text/set-font-weight-offset.js.map +1 -0
- package/text/shaders/slug-shader.d.ts +1 -0
- package/text/shaders/slug-shader.js +181 -0
- package/text/shaders/slug-shader.js.map +1 -0
- package/text/shaders/text-shader-fragment.d.ts +1 -0
- package/text/shaders/text-shader-fragment.js +2 -0
- package/text/shaders/text-shader-fragment.js.map +1 -0
- package/text/shaders/weight-shader-fragment.d.ts +1 -0
- package/text/shaders/weight-shader-fragment.js +75 -0
- package/text/shaders/weight-shader-fragment.js.map +1 -0
- package/text/text-data.d.ts +109 -0
- package/text/text-data.js +723 -0
- package/text/text-data.js.map +1 -0
- package/text/text-renderer.d.ts +68 -0
- package/text/text-renderer.js +238 -0
- package/text/text-renderer.js.map +1 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { GLGlyphRun, GLTextData } from "./text-data.js";
|
|
2
|
+
/** Set a run's synthetic outward contour offset in font units, clamped to 0..100.
|
|
3
|
+
* Zero selects the base shader. Replacing the run descriptor drops its offset.
|
|
4
|
+
* This optional module owns all weight state and shader code; ordinary text does not retain it. */
|
|
5
|
+
export declare function setFontWeightOffset(data: GLTextData, run: GLGlyphRun | number, offset: number): void;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { _installTextStyleSeam, _resolveRunRef, updateTextData } from "./text-data.js";
|
|
2
|
+
import { _installTextVariantResolver, createTextProgram } from "./_gpu/text-effect.js";
|
|
3
|
+
import { composeSlugShader } from "./shaders/slug-shader.js";
|
|
4
|
+
import { WEIGHT_SHADER_FRAGMENT } from "./shaders/weight-shader-fragment.js";
|
|
5
|
+
let offsets = null;
|
|
6
|
+
let keys = null;
|
|
7
|
+
let shader = null;
|
|
8
|
+
function runOffset(run) {
|
|
9
|
+
return offsets?.get(run) ?? 0;
|
|
10
|
+
}
|
|
11
|
+
function runGroupKey(run) {
|
|
12
|
+
if (runOffset(run) === 0) {
|
|
13
|
+
return run.curveSet;
|
|
14
|
+
}
|
|
15
|
+
const cache = (keys ??= new Map());
|
|
16
|
+
let key = cache.get(run.curveSet);
|
|
17
|
+
if (!key) {
|
|
18
|
+
key = {};
|
|
19
|
+
cache.set(run.curveSet, key);
|
|
20
|
+
}
|
|
21
|
+
return key;
|
|
22
|
+
}
|
|
23
|
+
function createVariant(engine) {
|
|
24
|
+
return createTextProgram(engine, (shader ??= composeSlugShader(WEIGHT_SHADER_FRAGMENT)));
|
|
25
|
+
}
|
|
26
|
+
/** Set a run's synthetic outward contour offset in font units, clamped to 0..100.
|
|
27
|
+
* Zero selects the base shader. Replacing the run descriptor drops its offset.
|
|
28
|
+
* This optional module owns all weight state and shader code; ordinary text does not retain it. */
|
|
29
|
+
export function setFontWeightOffset(data, run, offset) {
|
|
30
|
+
if (!Number.isFinite(offset)) {
|
|
31
|
+
console.error("setFontWeightOffset: offset must be finite, got", offset);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const target = _resolveRunRef(data, run, "setFontWeightOffset");
|
|
35
|
+
const value = Math.min(Math.max(offset, 0), 100);
|
|
36
|
+
if (value !== offset) {
|
|
37
|
+
console.warn(`setFontWeightOffset: offset ${offset} clamped to ${value} (range 0-100 font units).`);
|
|
38
|
+
}
|
|
39
|
+
if (runOffset(target) === value) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (!offsets) {
|
|
43
|
+
offsets = new WeakMap();
|
|
44
|
+
_installTextStyleSeam({ _key: runGroupKey, _param: runOffset });
|
|
45
|
+
_installTextVariantResolver(createVariant);
|
|
46
|
+
}
|
|
47
|
+
const previous = offsets.get(target);
|
|
48
|
+
if (value === 0) {
|
|
49
|
+
offsets.delete(target);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
offsets.set(target, value);
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
updateTextData(data, { update: "reset" });
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (previous === undefined) {
|
|
59
|
+
offsets.delete(target);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
offsets.set(target, previous);
|
|
63
|
+
}
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=set-font-weight-offset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-font-weight-offset.js","sourceRoot":"","sources":["../../src/text/set-font-weight-offset.ts"],"names":[],"mappings":"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","sourcesContent":["import type { GLEngineContext } from \"../context.js\";\nimport type { GLCurveSetId } from \"./glyph-storage.js\";\nimport type { GLGlyphRun, GLTextData, TextGroupKey } from \"./text-data.js\";\nimport { _installTextStyleSeam, _resolveRunRef, updateTextData } from \"./text-data.js\";\nimport { _installTextVariantResolver, createTextProgram } from \"./_gpu/text-effect.js\";\nimport type { TextProgram } from \"./_gpu/text-effect.js\";\nimport { composeSlugShader } from \"./shaders/slug-shader.js\";\nimport type { ComposedSlugShader } from \"./shaders/slug-shader.js\";\nimport { WEIGHT_SHADER_FRAGMENT } from \"./shaders/weight-shader-fragment.js\";\n\nlet offsets: WeakMap<GLGlyphRun, number> | null = null;\nlet keys: Map<GLCurveSetId, object> | null = null;\nlet shader: ComposedSlugShader | null = null;\n\nfunction runOffset(run: GLGlyphRun): number {\n return offsets?.get(run) ?? 0;\n}\n\nfunction runGroupKey(run: GLGlyphRun): TextGroupKey {\n if (runOffset(run) === 0) {\n return run.curveSet;\n }\n const cache = (keys ??= new Map());\n let key = cache.get(run.curveSet);\n if (!key) {\n key = {};\n cache.set(run.curveSet, key);\n }\n return key;\n}\n\nfunction createVariant(engine: GLEngineContext): TextProgram {\n return createTextProgram(engine, (shader ??= composeSlugShader(WEIGHT_SHADER_FRAGMENT)));\n}\n\n/** Set a run's synthetic outward contour offset in font units, clamped to 0..100.\n * Zero selects the base shader. Replacing the run descriptor drops its offset.\n * This optional module owns all weight state and shader code; ordinary text does not retain it. */\nexport function setFontWeightOffset(data: GLTextData, run: GLGlyphRun | number, offset: number): void {\n if (!Number.isFinite(offset)) {\n console.error(\"setFontWeightOffset: offset must be finite, got\", offset);\n return;\n }\n const target = _resolveRunRef(data, run, \"setFontWeightOffset\");\n const value = Math.min(Math.max(offset, 0), 100);\n if (value !== offset) {\n console.warn(`setFontWeightOffset: offset ${offset} clamped to ${value} (range 0-100 font units).`);\n }\n if (runOffset(target) === value) {\n return;\n }\n if (!offsets) {\n offsets = new WeakMap();\n _installTextStyleSeam({ _key: runGroupKey, _param: runOffset });\n _installTextVariantResolver(createVariant);\n }\n const previous = offsets.get(target);\n if (value === 0) {\n offsets.delete(target);\n } else {\n offsets.set(target, value);\n }\n try {\n updateTextData(data, { update: \"reset\" });\n } catch (error) {\n if (previous === undefined) {\n offsets.delete(target);\n } else {\n offsets.set(target, previous);\n }\n throw error;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/** @internal Direct interpolation remains valid after production shader minification. */
|
|
2
|
+
export function composeSlugShader(fragment) {
|
|
3
|
+
const v = fragment?._vertexSlots;
|
|
4
|
+
const f = fragment?._fragmentSlots;
|
|
5
|
+
const bounds = v?.VB ? "sb" : "bounds";
|
|
6
|
+
return {
|
|
7
|
+
_key: fragment?._id ?? "",
|
|
8
|
+
_vert: `#version 300 es
|
|
9
|
+
precision highp float;
|
|
10
|
+
precision highp int;
|
|
11
|
+
precision highp sampler2D;
|
|
12
|
+
layout(location=0) in vec2 corner;
|
|
13
|
+
layout(location=1) in vec2 anchor;
|
|
14
|
+
layout(location=2) in uint glyphStyle;
|
|
15
|
+
uniform mat4 mvp;
|
|
16
|
+
uniform vec4 viewport;
|
|
17
|
+
uniform vec4 color;
|
|
18
|
+
uniform sampler2D glyphMetadata;
|
|
19
|
+
uniform sampler2D styles;
|
|
20
|
+
out vec2 texcoord;
|
|
21
|
+
flat out vec4 banding;
|
|
22
|
+
flat out vec4 glyph;
|
|
23
|
+
flat out vec4 glyphColor;
|
|
24
|
+
${v?.VO ?? ""}
|
|
25
|
+
vec4 tableFetch(sampler2D table, uint offset) {
|
|
26
|
+
return texelFetch(table, ivec2(int(offset & 255u), int(offset >> 8u)), 0);
|
|
27
|
+
}
|
|
28
|
+
void main() {
|
|
29
|
+
if (glyphStyle == 0xffffffffu) {
|
|
30
|
+
gl_Position = vec4(-2.0, -2.0, -2.0, 1.0);
|
|
31
|
+
texcoord = vec2(0.0);
|
|
32
|
+
banding = vec4(0.0);
|
|
33
|
+
glyph = vec4(0.0);
|
|
34
|
+
glyphColor = vec4(0.0);
|
|
35
|
+
${v?.VD ?? ""}
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
uint mi = (glyphStyle & 0xffffu) * 3u;
|
|
39
|
+
uint si = (glyphStyle >> 16u) * 2u;
|
|
40
|
+
vec4 bounds = tableFetch(glyphMetadata, mi);
|
|
41
|
+
vec4 styleColor = tableFetch(styles, si);
|
|
42
|
+
vec4 params = tableFetch(styles, si + 1u);
|
|
43
|
+
${v?.VB ?? ""}
|
|
44
|
+
vec2 tx = mix(${bounds}.xy, ${bounds}.zw, step(vec2(0.0), corner));
|
|
45
|
+
float iv = params.x;
|
|
46
|
+
float scale = iv != 0.0 ? 1.0 / iv : 0.0;
|
|
47
|
+
vec2 pos = anchor + tx * scale;
|
|
48
|
+
vec3 r0 = vec3(mvp[0].x, mvp[1].x, mvp[3].x);
|
|
49
|
+
vec3 r1 = vec3(mvp[0].y, mvp[1].y, mvp[3].y);
|
|
50
|
+
vec3 r3 = vec3(mvp[0].w, mvp[1].w, mvp[3].w);
|
|
51
|
+
vec2 n = normalize(corner);
|
|
52
|
+
float s = dot(r3.xy, pos) + r3.z;
|
|
53
|
+
float t = dot(r3.xy, n);
|
|
54
|
+
float u = (s * dot(r0.xy, n) - t * (dot(r0.xy, pos) + r0.z)) * viewport.x;
|
|
55
|
+
float v = (s * dot(r1.xy, n) - t * (dot(r1.xy, pos) + r1.z)) * viewport.y;
|
|
56
|
+
float uv = u * u + v * v;
|
|
57
|
+
float q = s * t;
|
|
58
|
+
vec2 dilation = corner * (s * s * (q + sqrt(uv)) / (uv - q * q));
|
|
59
|
+
gl_Position = mvp * vec4(pos + dilation, 0.0, 1.0);
|
|
60
|
+
texcoord = tx + dilation * iv;
|
|
61
|
+
glyph = tableFetch(glyphMetadata, mi + 1u);
|
|
62
|
+
banding = tableFetch(glyphMetadata, mi + 2u);
|
|
63
|
+
glyphColor = vec4(styleColor.rgb, styleColor.a * color.a);
|
|
64
|
+
${v?.VA ?? ""}
|
|
65
|
+
}`,
|
|
66
|
+
_frag: `#version 300 es
|
|
67
|
+
precision highp float;
|
|
68
|
+
precision highp int;
|
|
69
|
+
precision highp sampler2D;
|
|
70
|
+
precision highp usampler2D;
|
|
71
|
+
uniform sampler2D curveTex;
|
|
72
|
+
uniform usampler2D bandTex;
|
|
73
|
+
uniform vec4 color;
|
|
74
|
+
in vec2 texcoord;
|
|
75
|
+
flat in vec4 banding;
|
|
76
|
+
flat in vec4 glyph;
|
|
77
|
+
flat in vec4 glyphColor;
|
|
78
|
+
${f?.FI ?? ""}
|
|
79
|
+
out vec4 fragmentColor;
|
|
80
|
+
int rootCode(float y1, float y2, float y3) {
|
|
81
|
+
int s = (y1 < 0.0 ? 1 : 0) + (y2 < 0.0 ? 2 : 0) + (y3 < 0.0 ? 4 : 0);
|
|
82
|
+
return (0x2E74 >> s) & 0x0101;
|
|
83
|
+
}
|
|
84
|
+
vec2 solveHorizontal(vec4 p12, vec2 p3) {
|
|
85
|
+
vec2 a = p12.xy - 2.0 * p12.zw + p3;
|
|
86
|
+
vec2 b = p12.xy - p12.zw;
|
|
87
|
+
float ra = 1.0 / a.y;
|
|
88
|
+
float rb = 0.5 / b.y;
|
|
89
|
+
float d = sqrt(max(b.y * b.y - a.y * p12.y, 0.0));
|
|
90
|
+
float t1 = (b.y - d) * ra;
|
|
91
|
+
float t2 = (b.y + d) * ra;
|
|
92
|
+
if (abs(a.y) <= max(abs(b.y), abs(p12.y)) * 1.0e-4) {
|
|
93
|
+
t1 = p12.y * rb;
|
|
94
|
+
t2 = p12.y * rb;
|
|
95
|
+
}
|
|
96
|
+
return vec2((a.x * t1 - 2.0 * b.x) * t1 + p12.x, (a.x * t2 - 2.0 * b.x) * t2 + p12.x);
|
|
97
|
+
}
|
|
98
|
+
vec2 solveVertical(vec4 p12, vec2 p3) {
|
|
99
|
+
vec2 a = p12.xy - 2.0 * p12.zw + p3;
|
|
100
|
+
vec2 b = p12.xy - p12.zw;
|
|
101
|
+
float ra = 1.0 / a.x;
|
|
102
|
+
float rb = 0.5 / b.x;
|
|
103
|
+
float d = sqrt(max(b.x * b.x - a.x * p12.x, 0.0));
|
|
104
|
+
float t1 = (b.x - d) * ra;
|
|
105
|
+
float t2 = (b.x + d) * ra;
|
|
106
|
+
if (abs(a.x) <= max(abs(b.x), abs(p12.x)) * 1.0e-4) {
|
|
107
|
+
t1 = p12.x * rb;
|
|
108
|
+
t2 = p12.x * rb;
|
|
109
|
+
}
|
|
110
|
+
return vec2((a.y * t1 - 2.0 * b.y) * t1 + p12.y, (a.y * t2 - 2.0 * b.y) * t2 + p12.y);
|
|
111
|
+
}
|
|
112
|
+
float crossingCoverage(float r) { return clamp(r + 0.5, 0.0, 1.0); }
|
|
113
|
+
float crossingWeight(float r) { return clamp(1.0 - abs(r) * 2.0, 0.0, 1.0); }
|
|
114
|
+
ivec2 bandLocation(ivec2 origin, int offset) {
|
|
115
|
+
int x = origin.x + offset;
|
|
116
|
+
return ivec2(x & 4095, origin.y + (x >> 12));
|
|
117
|
+
}
|
|
118
|
+
${f?.FH ?? ""}
|
|
119
|
+
void main() {
|
|
120
|
+
if (!gl_FrontFacing) { discard; }
|
|
121
|
+
vec2 rc = texcoord;
|
|
122
|
+
vec2 pe = 1.0 / fwidth(rc);
|
|
123
|
+
ivec2 gp = ivec2(glyph.xy + 0.5);
|
|
124
|
+
ivec2 bm = ivec2(glyph.zw + 0.5);
|
|
125
|
+
ivec2 bi = clamp(ivec2(rc * banding.xy + banding.zw), ivec2(0), bm);
|
|
126
|
+
float xc = 0.0;
|
|
127
|
+
float xw = 0.0;
|
|
128
|
+
float yc = 0.0;
|
|
129
|
+
float yw = 0.0;
|
|
130
|
+
uvec4 hr = texelFetch(bandTex, ivec2(gp.x + bi.y, gp.y), 0);
|
|
131
|
+
int hn = int(hr.x);
|
|
132
|
+
ivec2 hl = bandLocation(gp, int(hr.y));
|
|
133
|
+
for (int i = 0; i < hn; i++) {
|
|
134
|
+
ivec2 cv = ivec2(texelFetch(bandTex, bandLocation(hl, i), 0).xy);
|
|
135
|
+
vec4 p12 = texelFetch(curveTex, cv, 0) - vec4(rc, rc);
|
|
136
|
+
vec2 p3 = texelFetch(curveTex, ivec2(cv.x + 1, cv.y), 0).xy - rc;
|
|
137
|
+
if (max(max(p12.x, p12.z), p3.x) * pe.x < -0.5) { break; }
|
|
138
|
+
int code = rootCode(p12.y, p12.w, p3.y);
|
|
139
|
+
if (code != 0) {
|
|
140
|
+
vec2 r = solveHorizontal(p12, p3) * pe.x;
|
|
141
|
+
if ((code & 1) != 0) {
|
|
142
|
+
xc += crossingCoverage(r.x);
|
|
143
|
+
xw = max(xw, crossingWeight(r.x));
|
|
144
|
+
}
|
|
145
|
+
if (code > 1) {
|
|
146
|
+
xc -= crossingCoverage(r.y);
|
|
147
|
+
xw = max(xw, crossingWeight(r.y));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
uvec4 vr = texelFetch(bandTex, ivec2(gp.x + bm.y + 1 + bi.x, gp.y), 0);
|
|
152
|
+
int vn = int(vr.x);
|
|
153
|
+
ivec2 vl = bandLocation(gp, int(vr.y));
|
|
154
|
+
for (int i = 0; i < vn; i++) {
|
|
155
|
+
ivec2 cv = ivec2(texelFetch(bandTex, bandLocation(vl, i), 0).xy);
|
|
156
|
+
vec4 p12 = texelFetch(curveTex, cv, 0) - vec4(rc, rc);
|
|
157
|
+
vec2 p3 = texelFetch(curveTex, ivec2(cv.x + 1, cv.y), 0).xy - rc;
|
|
158
|
+
if (max(max(p12.y, p12.w), p3.y) * pe.y < -0.5) { break; }
|
|
159
|
+
int code = rootCode(p12.x, p12.z, p3.x);
|
|
160
|
+
if (code != 0) {
|
|
161
|
+
vec2 r = solveVertical(p12, p3) * pe.y;
|
|
162
|
+
if ((code & 1) != 0) {
|
|
163
|
+
yc -= crossingCoverage(r.x);
|
|
164
|
+
yw = max(yw, crossingWeight(r.x));
|
|
165
|
+
}
|
|
166
|
+
if (code > 1) {
|
|
167
|
+
yc += crossingCoverage(r.y);
|
|
168
|
+
yw = max(yw, crossingWeight(r.y));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
float coverage = max(abs(xc * xw + yc * yw) / max(xw + yw, 1.0 / 65536.0), min(abs(xc), abs(yc)));
|
|
173
|
+
coverage = clamp(coverage, 0.0, 1.0);
|
|
174
|
+
${f?.CO ?? ""}
|
|
175
|
+
coverage = pow(coverage, color.x);
|
|
176
|
+
float alpha = glyphColor.a * coverage;
|
|
177
|
+
fragmentColor = vec4(glyphColor.rgb * alpha, alpha);
|
|
178
|
+
}`,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=slug-shader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slug-shader.js","sourceRoot":"","sources":["../../../src/text/shaders/slug-shader.ts"],"names":[],"mappings":"AAcA,yFAAyF;AACzF,MAAM,UAAU,iBAAiB,CAAC,QAAmC;IACjE,MAAM,CAAC,GAAG,QAAQ,EAAE,YAAY,CAAC;IACjC,MAAM,CAAC,GAAG,QAAQ,EAAE,cAAc,CAAC;IACnC,MAAM,MAAM,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC;IACvC,OAAO;QACH,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE;QACzB,KAAK,EAAE;;;;;;;;;;;;;;;;EAgBb,CAAC,EAAE,EAAE,IAAI,EAAE;;;;;;;;;;;UAWH,CAAC,EAAE,EAAE,IAAI,EAAE;;;;;;;;MAQf,CAAC,EAAE,EAAE,IAAI,EAAE;oBACG,MAAM,QAAQ,MAAM;;;;;;;;;;;;;;;;;;;;MAoBlC,CAAC,EAAE,EAAE,IAAI,EAAE;EACf;QACM,KAAK,EAAE;;;;;;;;;;;;EAYb,CAAC,EAAE,EAAE,IAAI,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwCX,CAAC,EAAE,EAAE,IAAI,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAwDP,CAAC,EAAE,EAAE,IAAI,EAAE;;;;EAIf;KACG,CAAC;AACN,CAAC","sourcesContent":["/** Analytic SLUG coverage, matching Lite's WGSL template. Original algorithm:\n * https://github.com/EricLengyel/Slug. Metadata/styles use lookup textures on GL. */\nimport type { TextShaderFragment } from \"./text-shader-fragment.js\";\n\n/** @internal */\nexport interface ComposedSlugShader {\n /** @internal */\n readonly _vert: string;\n /** @internal */\n readonly _frag: string;\n /** @internal */\n readonly _key: string;\n}\n\n/** @internal Direct interpolation remains valid after production shader minification. */\nexport function composeSlugShader(fragment: TextShaderFragment | null): ComposedSlugShader {\n const v = fragment?._vertexSlots;\n const f = fragment?._fragmentSlots;\n const bounds = v?.VB ? \"sb\" : \"bounds\";\n return {\n _key: fragment?._id ?? \"\",\n _vert: `#version 300 es\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\nlayout(location=0) in vec2 corner;\nlayout(location=1) in vec2 anchor;\nlayout(location=2) in uint glyphStyle;\nuniform mat4 mvp;\nuniform vec4 viewport;\nuniform vec4 color;\nuniform sampler2D glyphMetadata;\nuniform sampler2D styles;\nout vec2 texcoord;\nflat out vec4 banding;\nflat out vec4 glyph;\nflat out vec4 glyphColor;\n${v?.VO ?? \"\"}\nvec4 tableFetch(sampler2D table, uint offset) {\n return texelFetch(table, ivec2(int(offset & 255u), int(offset >> 8u)), 0);\n}\nvoid main() {\n if (glyphStyle == 0xffffffffu) {\n gl_Position = vec4(-2.0, -2.0, -2.0, 1.0);\n texcoord = vec2(0.0);\n banding = vec4(0.0);\n glyph = vec4(0.0);\n glyphColor = vec4(0.0);\n ${v?.VD ?? \"\"}\n return;\n }\n uint mi = (glyphStyle & 0xffffu) * 3u;\n uint si = (glyphStyle >> 16u) * 2u;\n vec4 bounds = tableFetch(glyphMetadata, mi);\n vec4 styleColor = tableFetch(styles, si);\n vec4 params = tableFetch(styles, si + 1u);\n ${v?.VB ?? \"\"}\n vec2 tx = mix(${bounds}.xy, ${bounds}.zw, step(vec2(0.0), corner));\n float iv = params.x;\n float scale = iv != 0.0 ? 1.0 / iv : 0.0;\n vec2 pos = anchor + tx * scale;\n vec3 r0 = vec3(mvp[0].x, mvp[1].x, mvp[3].x);\n vec3 r1 = vec3(mvp[0].y, mvp[1].y, mvp[3].y);\n vec3 r3 = vec3(mvp[0].w, mvp[1].w, mvp[3].w);\n vec2 n = normalize(corner);\n float s = dot(r3.xy, pos) + r3.z;\n float t = dot(r3.xy, n);\n float u = (s * dot(r0.xy, n) - t * (dot(r0.xy, pos) + r0.z)) * viewport.x;\n float v = (s * dot(r1.xy, n) - t * (dot(r1.xy, pos) + r1.z)) * viewport.y;\n float uv = u * u + v * v;\n float q = s * t;\n vec2 dilation = corner * (s * s * (q + sqrt(uv)) / (uv - q * q));\n gl_Position = mvp * vec4(pos + dilation, 0.0, 1.0);\n texcoord = tx + dilation * iv;\n glyph = tableFetch(glyphMetadata, mi + 1u);\n banding = tableFetch(glyphMetadata, mi + 2u);\n glyphColor = vec4(styleColor.rgb, styleColor.a * color.a);\n ${v?.VA ?? \"\"}\n}`,\n _frag: `#version 300 es\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\nprecision highp usampler2D;\nuniform sampler2D curveTex;\nuniform usampler2D bandTex;\nuniform vec4 color;\nin vec2 texcoord;\nflat in vec4 banding;\nflat in vec4 glyph;\nflat in vec4 glyphColor;\n${f?.FI ?? \"\"}\nout vec4 fragmentColor;\nint rootCode(float y1, float y2, float y3) {\n int s = (y1 < 0.0 ? 1 : 0) + (y2 < 0.0 ? 2 : 0) + (y3 < 0.0 ? 4 : 0);\n return (0x2E74 >> s) & 0x0101;\n}\nvec2 solveHorizontal(vec4 p12, vec2 p3) {\n vec2 a = p12.xy - 2.0 * p12.zw + p3;\n vec2 b = p12.xy - p12.zw;\n float ra = 1.0 / a.y;\n float rb = 0.5 / b.y;\n float d = sqrt(max(b.y * b.y - a.y * p12.y, 0.0));\n float t1 = (b.y - d) * ra;\n float t2 = (b.y + d) * ra;\n if (abs(a.y) <= max(abs(b.y), abs(p12.y)) * 1.0e-4) {\n t1 = p12.y * rb;\n t2 = p12.y * rb;\n }\n return vec2((a.x * t1 - 2.0 * b.x) * t1 + p12.x, (a.x * t2 - 2.0 * b.x) * t2 + p12.x);\n}\nvec2 solveVertical(vec4 p12, vec2 p3) {\n vec2 a = p12.xy - 2.0 * p12.zw + p3;\n vec2 b = p12.xy - p12.zw;\n float ra = 1.0 / a.x;\n float rb = 0.5 / b.x;\n float d = sqrt(max(b.x * b.x - a.x * p12.x, 0.0));\n float t1 = (b.x - d) * ra;\n float t2 = (b.x + d) * ra;\n if (abs(a.x) <= max(abs(b.x), abs(p12.x)) * 1.0e-4) {\n t1 = p12.x * rb;\n t2 = p12.x * rb;\n }\n return vec2((a.y * t1 - 2.0 * b.y) * t1 + p12.y, (a.y * t2 - 2.0 * b.y) * t2 + p12.y);\n}\nfloat crossingCoverage(float r) { return clamp(r + 0.5, 0.0, 1.0); }\nfloat crossingWeight(float r) { return clamp(1.0 - abs(r) * 2.0, 0.0, 1.0); }\nivec2 bandLocation(ivec2 origin, int offset) {\n int x = origin.x + offset;\n return ivec2(x & 4095, origin.y + (x >> 12));\n}\n${f?.FH ?? \"\"}\nvoid main() {\n if (!gl_FrontFacing) { discard; }\n vec2 rc = texcoord;\n vec2 pe = 1.0 / fwidth(rc);\n ivec2 gp = ivec2(glyph.xy + 0.5);\n ivec2 bm = ivec2(glyph.zw + 0.5);\n ivec2 bi = clamp(ivec2(rc * banding.xy + banding.zw), ivec2(0), bm);\n float xc = 0.0;\n float xw = 0.0;\n float yc = 0.0;\n float yw = 0.0;\n uvec4 hr = texelFetch(bandTex, ivec2(gp.x + bi.y, gp.y), 0);\n int hn = int(hr.x);\n ivec2 hl = bandLocation(gp, int(hr.y));\n for (int i = 0; i < hn; i++) {\n ivec2 cv = ivec2(texelFetch(bandTex, bandLocation(hl, i), 0).xy);\n vec4 p12 = texelFetch(curveTex, cv, 0) - vec4(rc, rc);\n vec2 p3 = texelFetch(curveTex, ivec2(cv.x + 1, cv.y), 0).xy - rc;\n if (max(max(p12.x, p12.z), p3.x) * pe.x < -0.5) { break; }\n int code = rootCode(p12.y, p12.w, p3.y);\n if (code != 0) {\n vec2 r = solveHorizontal(p12, p3) * pe.x;\n if ((code & 1) != 0) {\n xc += crossingCoverage(r.x);\n xw = max(xw, crossingWeight(r.x));\n }\n if (code > 1) {\n xc -= crossingCoverage(r.y);\n xw = max(xw, crossingWeight(r.y));\n }\n }\n }\n uvec4 vr = texelFetch(bandTex, ivec2(gp.x + bm.y + 1 + bi.x, gp.y), 0);\n int vn = int(vr.x);\n ivec2 vl = bandLocation(gp, int(vr.y));\n for (int i = 0; i < vn; i++) {\n ivec2 cv = ivec2(texelFetch(bandTex, bandLocation(vl, i), 0).xy);\n vec4 p12 = texelFetch(curveTex, cv, 0) - vec4(rc, rc);\n vec2 p3 = texelFetch(curveTex, ivec2(cv.x + 1, cv.y), 0).xy - rc;\n if (max(max(p12.y, p12.w), p3.y) * pe.y < -0.5) { break; }\n int code = rootCode(p12.x, p12.z, p3.x);\n if (code != 0) {\n vec2 r = solveVertical(p12, p3) * pe.y;\n if ((code & 1) != 0) {\n yc -= crossingCoverage(r.x);\n yw = max(yw, crossingWeight(r.x));\n }\n if (code > 1) {\n yc += crossingCoverage(r.y);\n yw = max(yw, crossingWeight(r.y));\n }\n }\n }\n float coverage = max(abs(xc * xw + yc * yw) / max(xw + yw, 1.0 / 65536.0), min(abs(xc), abs(yc)));\n coverage = clamp(coverage, 0.0, 1.0);\n ${f?.CO ?? \"\"}\n coverage = pow(coverage, color.x);\n float alpha = glyphColor.a * coverage;\n fragmentColor = vec4(glyphColor.rgb * alpha, alpha);\n}`,\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-shader-fragment.js","sourceRoot":"","sources":["../../../src/text/shaders/text-shader-fragment.ts"],"names":[],"mappings":"","sourcesContent":["/** @internal Typed composition slots; feature modules own all optional shader logic. */\nexport interface TextShaderFragment {\n /** @internal */\n readonly _id: string;\n /** @internal */\n readonly _vertexSlots?: Partial<Record<\"VO\" | \"VD\" | \"VB\" | \"VA\", string>>;\n /** @internal */\n readonly _fragmentSlots?: Partial<Record<\"FI\" | \"FH\" | \"CO\", string>>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** @internal GLSL counterpart of Lite's opt-in, radius-bounded contour-distance scan. */
|
|
2
|
+
export const WEIGHT_SHADER_FRAGMENT = {
|
|
3
|
+
_id: "w",
|
|
4
|
+
_vertexSlots: {
|
|
5
|
+
VO: "flat out float weightOffset;",
|
|
6
|
+
VD: "weightOffset = 0.0;",
|
|
7
|
+
VB: "float wo = params.y;\nvec4 sb = vec4(bounds.xy - vec2(wo), bounds.zw + vec2(wo));",
|
|
8
|
+
VA: "weightOffset = wo;",
|
|
9
|
+
},
|
|
10
|
+
_fragmentSlots: {
|
|
11
|
+
FI: "flat in float weightOffset;",
|
|
12
|
+
FH: `float dot2(vec2 v) { return dot(v, v); }
|
|
13
|
+
float quadraticDistance(vec2 p, vec2 A, vec2 B, vec2 C) {
|
|
14
|
+
vec2 a = B - A;
|
|
15
|
+
vec2 b = A - 2.0 * B + C;
|
|
16
|
+
vec2 c = a * 2.0;
|
|
17
|
+
vec2 d = A - p;
|
|
18
|
+
float bb = dot(b, b);
|
|
19
|
+
if (bb < 1.0e-7) {
|
|
20
|
+
vec2 ba = C - A;
|
|
21
|
+
float t = clamp(dot(p - A, ba) / max(dot(ba, ba), 1.0e-9), 0.0, 1.0);
|
|
22
|
+
return length(A + ba * t - p);
|
|
23
|
+
}
|
|
24
|
+
float kk = 1.0 / bb;
|
|
25
|
+
float kx = kk * dot(a, b);
|
|
26
|
+
float ky = kk * (2.0 * dot(a, a) + dot(d, b)) / 3.0;
|
|
27
|
+
float kz = kk * dot(d, a);
|
|
28
|
+
float pp = ky - kx * kx;
|
|
29
|
+
float q = kx * (2.0 * kx * kx - 3.0 * ky) + kz;
|
|
30
|
+
float h = q * q + 4.0 * pp * pp * pp;
|
|
31
|
+
float result;
|
|
32
|
+
if (h >= 0.0) {
|
|
33
|
+
float hh = sqrt(h);
|
|
34
|
+
vec2 x = (vec2(hh, -hh) - q) / 2.0;
|
|
35
|
+
vec2 uv = sign(x) * pow(abs(x), vec2(1.0 / 3.0));
|
|
36
|
+
float t = clamp(uv.x + uv.y - kx, 0.0, 1.0);
|
|
37
|
+
result = dot2(d + (c + b * t) * t);
|
|
38
|
+
} else {
|
|
39
|
+
float z = sqrt(-pp);
|
|
40
|
+
float v = acos(q / (pp * z * 2.0)) / 3.0;
|
|
41
|
+
float m = cos(v);
|
|
42
|
+
float n = sin(v) * 1.732050808;
|
|
43
|
+
vec3 t = clamp(vec3(m + m, -n - m, n - m) * z - kx, vec3(0.0), vec3(1.0));
|
|
44
|
+
result = min(dot2(d + (c + b * t.x) * t.x), dot2(d + (c + b * t.y) * t.y));
|
|
45
|
+
}
|
|
46
|
+
return sqrt(result);
|
|
47
|
+
}
|
|
48
|
+
// The coverage walk cannot be reused: nearby contours can lie in adjacent bands or behind its early exit.
|
|
49
|
+
float weightDistance(vec2 rc, ivec2 gp, ivec2 bm, vec4 bn, float radius) {
|
|
50
|
+
int y0 = clamp(int((rc.y - radius) * bn.y + bn.w), 0, bm.y);
|
|
51
|
+
int y1 = clamp(int((rc.y + radius) * bn.y + bn.w), 0, bm.y);
|
|
52
|
+
float left = rc.x - radius;
|
|
53
|
+
float nearest = 1.0e9;
|
|
54
|
+
for (int band = y0; band <= y1; band++) {
|
|
55
|
+
uvec4 header = texelFetch(bandTex, ivec2(gp.x + band, gp.y), 0);
|
|
56
|
+
int count = int(header.x);
|
|
57
|
+
ivec2 list = bandLocation(gp, int(header.y));
|
|
58
|
+
for (int i = 0; i < count; i++) {
|
|
59
|
+
ivec2 cv = ivec2(texelFetch(bandTex, bandLocation(list, i), 0).xy);
|
|
60
|
+
vec4 q12 = texelFetch(curveTex, cv, 0);
|
|
61
|
+
vec2 q3 = texelFetch(curveTex, ivec2(cv.x + 1, cv.y), 0).xy;
|
|
62
|
+
if (max(max(q12.x, q12.z), q3.x) < left) { break; }
|
|
63
|
+
nearest = min(nearest, quadraticDistance(rc, q12.xy, q12.zw, q3));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return nearest;
|
|
67
|
+
}`,
|
|
68
|
+
CO: `if (weightOffset != 0.0) {
|
|
69
|
+
float aaScale = max(max(pe.x, pe.y), 1.0e-8);
|
|
70
|
+
float distance = weightDistance(rc, gp, bm, banding, weightOffset + 1.0 / aaScale);
|
|
71
|
+
coverage = max(coverage, clamp((weightOffset - distance) * aaScale + 0.5, 0.0, 1.0));
|
|
72
|
+
}`,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=weight-shader-fragment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"weight-shader-fragment.js","sourceRoot":"","sources":["../../../src/text/shaders/weight-shader-fragment.ts"],"names":[],"mappings":"AAEA,yFAAyF;AACzF,MAAM,CAAC,MAAM,sBAAsB,GAAuB;IACtD,GAAG,EAAE,GAAG;IACR,YAAY,EAAE;QACV,EAAE,EAAE,8BAA8B;QAClC,EAAE,EAAE,qBAAqB;QACzB,EAAE,EAAE,mFAAmF;QACvF,EAAE,EAAE,oBAAoB;KAC3B;IACD,cAAc,EAAE;QACZ,EAAE,EAAE,6BAA6B;QACjC,EAAE,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuDV;QACM,EAAE,EAAE;;;;EAIV;KACG;CACJ,CAAC","sourcesContent":["import type { TextShaderFragment } from \"./text-shader-fragment.js\";\n\n/** @internal GLSL counterpart of Lite's opt-in, radius-bounded contour-distance scan. */\nexport const WEIGHT_SHADER_FRAGMENT: TextShaderFragment = {\n _id: \"w\",\n _vertexSlots: {\n VO: \"flat out float weightOffset;\",\n VD: \"weightOffset = 0.0;\",\n VB: \"float wo = params.y;\\nvec4 sb = vec4(bounds.xy - vec2(wo), bounds.zw + vec2(wo));\",\n VA: \"weightOffset = wo;\",\n },\n _fragmentSlots: {\n FI: \"flat in float weightOffset;\",\n FH: `float dot2(vec2 v) { return dot(v, v); }\nfloat quadraticDistance(vec2 p, vec2 A, vec2 B, vec2 C) {\n vec2 a = B - A;\n vec2 b = A - 2.0 * B + C;\n vec2 c = a * 2.0;\n vec2 d = A - p;\n float bb = dot(b, b);\n if (bb < 1.0e-7) {\n vec2 ba = C - A;\n float t = clamp(dot(p - A, ba) / max(dot(ba, ba), 1.0e-9), 0.0, 1.0);\n return length(A + ba * t - p);\n }\n float kk = 1.0 / bb;\n float kx = kk * dot(a, b);\n float ky = kk * (2.0 * dot(a, a) + dot(d, b)) / 3.0;\n float kz = kk * dot(d, a);\n float pp = ky - kx * kx;\n float q = kx * (2.0 * kx * kx - 3.0 * ky) + kz;\n float h = q * q + 4.0 * pp * pp * pp;\n float result;\n if (h >= 0.0) {\n float hh = sqrt(h);\n vec2 x = (vec2(hh, -hh) - q) / 2.0;\n vec2 uv = sign(x) * pow(abs(x), vec2(1.0 / 3.0));\n float t = clamp(uv.x + uv.y - kx, 0.0, 1.0);\n result = dot2(d + (c + b * t) * t);\n } else {\n float z = sqrt(-pp);\n float v = acos(q / (pp * z * 2.0)) / 3.0;\n float m = cos(v);\n float n = sin(v) * 1.732050808;\n vec3 t = clamp(vec3(m + m, -n - m, n - m) * z - kx, vec3(0.0), vec3(1.0));\n result = min(dot2(d + (c + b * t.x) * t.x), dot2(d + (c + b * t.y) * t.y));\n }\n return sqrt(result);\n}\n// The coverage walk cannot be reused: nearby contours can lie in adjacent bands or behind its early exit.\nfloat weightDistance(vec2 rc, ivec2 gp, ivec2 bm, vec4 bn, float radius) {\n int y0 = clamp(int((rc.y - radius) * bn.y + bn.w), 0, bm.y);\n int y1 = clamp(int((rc.y + radius) * bn.y + bn.w), 0, bm.y);\n float left = rc.x - radius;\n float nearest = 1.0e9;\n for (int band = y0; band <= y1; band++) {\n uvec4 header = texelFetch(bandTex, ivec2(gp.x + band, gp.y), 0);\n int count = int(header.x);\n ivec2 list = bandLocation(gp, int(header.y));\n for (int i = 0; i < count; i++) {\n ivec2 cv = ivec2(texelFetch(bandTex, bandLocation(list, i), 0).xy);\n vec4 q12 = texelFetch(curveTex, cv, 0);\n vec2 q3 = texelFetch(curveTex, ivec2(cv.x + 1, cv.y), 0).xy;\n if (max(max(q12.x, q12.z), q3.x) < left) { break; }\n nearest = min(nearest, quadraticDistance(rc, q12.xy, q12.zw, q3));\n }\n }\n return nearest;\n}`,\n CO: `if (weightOffset != 0.0) {\n float aaScale = max(max(pe.x, pe.y), 1.0e-8);\n float distance = weightDistance(rc, gp, bm, banding, weightOffset + 1.0 / aaScale);\n coverage = max(coverage, clamp((weightOffset - distance) * aaScale + 0.5, 0.0, 1.0));\n}`,\n },\n};\n"]}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/** GLTextData — slot-allocator-backed per-instance vertex buffer for a text block.
|
|
2
|
+
*
|
|
3
|
+
* Each draw group owns a contiguous slot range `[slotStart, slotStart + slotCount)`
|
|
4
|
+
* in the shared instance buffer. Live and dead slots intermix within that range;
|
|
5
|
+
* dead slots carry an all-ones packed word that the vertex shader detects and turns
|
|
6
|
+
* into a degenerate off-screen triangle. `addRun` / `replaceRun` reuse
|
|
7
|
+
* from the group's `freeSlots` LIFO when possible; otherwise they extend the
|
|
8
|
+
* group's range (shifting later *groups* — never other runs in the same group).
|
|
9
|
+
* `removeRun` writes the sentinel into its slots and returns them to the free-list.
|
|
10
|
+
*
|
|
11
|
+
* Each GLTextData is bound to one `GLGlyphStorage` for its glyph catalog. The storage is
|
|
12
|
+
* borrowed — caller owns its lifetime. `disposeTextData` releases the per-block
|
|
13
|
+
* instance buffer + style texture only.
|
|
14
|
+
*
|
|
15
|
+
* Cost per edit: O(touched glyphs) in the common single-font case, with an extra
|
|
16
|
+
* O(later-group slot count) shift only when the touched group must grow.
|
|
17
|
+
*/
|
|
18
|
+
import type { GLCurveSetId, GLGlyphStorage } from "./glyph-storage.js";
|
|
19
|
+
declare const textDataBrand: unique symbol;
|
|
20
|
+
/** Positioned glyph instance in pixel space, usually produced by layout before being packed into a `GLGlyphRun`. */
|
|
21
|
+
export type GLPlacedGlyph = {
|
|
22
|
+
readonly glyphId: number;
|
|
23
|
+
/** Pixel position of glyph baseline origin. */
|
|
24
|
+
readonly x: number;
|
|
25
|
+
readonly y: number;
|
|
26
|
+
/** Optional per-glyph color as linear RGBA in [0,1]. When present this overrides the
|
|
27
|
+
* run's `defaultColor` for this glyph. When omitted, the glyph falls back to the run's
|
|
28
|
+
* `defaultColor`, and if that is also omitted, to opaque white. The rendered alpha is
|
|
29
|
+
* additionally scaled by the whole-block opacity (e.g. `TextRenderable.opacity`). */
|
|
30
|
+
readonly color?: readonly [number, number, number, number];
|
|
31
|
+
};
|
|
32
|
+
/** Batch of placed glyphs that all use the same curve set and font-unit-to-pixel scale. */
|
|
33
|
+
export type GLGlyphRun = {
|
|
34
|
+
/** Which curve set this run's glyph ids index into. */
|
|
35
|
+
readonly curveSet: GLCurveSetId;
|
|
36
|
+
readonly glyphs: readonly GLPlacedGlyph[];
|
|
37
|
+
/** GLFont-units → pixels scale used by the layout. */
|
|
38
|
+
readonly pixelsPerFontUnit: number;
|
|
39
|
+
/** Optional default color for every glyph in this run, as linear RGBA in [0,1]. A glyph's
|
|
40
|
+
* own `GLPlacedGlyph.color` takes precedence over this. When omitted, glyphs default to
|
|
41
|
+
* opaque white. The rendered alpha is additionally scaled by the whole-block opacity. */
|
|
42
|
+
readonly defaultColor?: readonly [number, number, number, number];
|
|
43
|
+
};
|
|
44
|
+
/** Discriminated union driving `updateTextData`. Each variant's `update` field is the
|
|
45
|
+
* discriminator. Arrays/maps passed inside any variant are *adopted* by the `GLTextData`
|
|
46
|
+
* and must not be read or mutated by the caller afterward. */
|
|
47
|
+
export type GLTextDataUpdate = {
|
|
48
|
+
/** Rebuild runs and/or swap to a different storage. Both `runs` and `storage`
|
|
49
|
+
* are optional; missing fields default to the GLTextData's current value, so
|
|
50
|
+
* `{ update: "reset" }` with neither performs a pure compaction pass that
|
|
51
|
+
* re-lays-out the slot allocator without dead slots or gaps.
|
|
52
|
+
* Invalidates any previously-passed `GLGlyphRun` references when `runs` is set. */
|
|
53
|
+
update: "reset";
|
|
54
|
+
runs?: GLGlyphRun[];
|
|
55
|
+
storage?: GLGlyphStorage;
|
|
56
|
+
} | {
|
|
57
|
+
/** Append a new run to the live runs list, or insert it before the run currently at
|
|
58
|
+
* `insertBefore`. The run's `curveSet` must already exist in the bound storage. */
|
|
59
|
+
update: "addRun";
|
|
60
|
+
run: GLGlyphRun;
|
|
61
|
+
/** Index in `data.runs` to insert before. Default = append at end. */
|
|
62
|
+
insertBefore?: number;
|
|
63
|
+
} | {
|
|
64
|
+
/** Remove a previously-added run. Accepts either the `GLGlyphRun` reference or its
|
|
65
|
+
* current index in `data.runs`. */
|
|
66
|
+
update: "removeRun";
|
|
67
|
+
run: GLGlyphRun | number;
|
|
68
|
+
} | {
|
|
69
|
+
/** Replace one run's contents in place. The new run takes the slot in `data.runs`
|
|
70
|
+
* that the previous run occupied. Cheapest when the new run has the same glyph
|
|
71
|
+
* count and the same `curveSet` as the previous one. */
|
|
72
|
+
update: "replaceRun";
|
|
73
|
+
previous: GLGlyphRun | number;
|
|
74
|
+
run: GLGlyphRun;
|
|
75
|
+
};
|
|
76
|
+
/** Mutable text block data containing glyph runs and the packed per-glyph instance buffer consumed by text renderers. */
|
|
77
|
+
export interface GLTextData {
|
|
78
|
+
readonly [textDataBrand]: true;
|
|
79
|
+
/** Live, in-insertion-order view of the runs currently rendered. Mutated by
|
|
80
|
+
* `updateTextData`. Do not mutate from outside. */
|
|
81
|
+
readonly runs: readonly GLGlyphRun[];
|
|
82
|
+
}
|
|
83
|
+
/** Floats per instance: the anchor (x, y) plus one packed u32 holding the glyph index in its
|
|
84
|
+
* low 16 bits and the style index in its high 16. Everything else the shader needs is either
|
|
85
|
+
* glyph-invariant — the atlas's `GlyphMetadata` table, indexed by the glyph half — or shared
|
|
86
|
+
* by every glyph drawn at the same color and scale — this GLTextData's style palette, indexed
|
|
87
|
+
* by the style half. Neither is copied per instance. */
|
|
88
|
+
export declare const TEXT_INSTANCE_FLOATS = 3;
|
|
89
|
+
export declare const TEXT_INSTANCE_BYTES: number;
|
|
90
|
+
/** Floats per style-palette entry, matching the WGSL `TextStyle` struct: a `vec4<f32>` color
|
|
91
|
+
* followed by a `vec4<f32>` of params whose `.x` carries the run's `invScale` and whose `.y`
|
|
92
|
+
* carries the optional per-run style parameter (see {@link TextStyleSeam}; 0 when no styling
|
|
93
|
+
* feature is installed). The rest is reserved padding that keeps the struct naturally
|
|
94
|
+
* 16-byte aligned. */
|
|
95
|
+
export declare const TEXT_STYLE_FLOATS = 8;
|
|
96
|
+
export declare const TEXT_STYLE_BYTES: number;
|
|
97
|
+
/** Create a GLTextData bound to `storage`. If `runs` is omitted the GLTextData starts empty;
|
|
98
|
+
* runs can be appended later via `updateTextData({ update: "addRun", … })`. */
|
|
99
|
+
export declare function createTextData(storage: GLGlyphStorage, runs?: readonly GLGlyphRun[]): GLTextData;
|
|
100
|
+
/** Apply an incremental edit to a `GLTextData`, such as adding, removing, replacing, or compacting runs.
|
|
101
|
+
*
|
|
102
|
+
* @param data - Text data block to update.
|
|
103
|
+
* @param update - Discriminated update operation to apply. */
|
|
104
|
+
export declare function updateTextData(data: GLTextData, update: GLTextDataUpdate): void;
|
|
105
|
+
/** Release per-block GPU resources owned by `data`. Does NOT dispose the bound
|
|
106
|
+
* `GLGlyphStorage` — caller owns its lifetime and must dispose it separately via
|
|
107
|
+
* `disposeGlyphStorage` once no `GLTextData` references it. */
|
|
108
|
+
export declare function disposeTextData(data: GLTextData): void;
|
|
109
|
+
export {};
|