@bloopjs/toodle 0.1.3 → 0.1.4
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/dist/backends/webgl2/WebGLFontPipeline.d.ts +26 -0
- package/dist/backends/webgl2/WebGLFontPipeline.d.ts.map +1 -0
- package/dist/backends/webgl2/WebGLTextShader.d.ts +10 -6
- package/dist/backends/webgl2/WebGLTextShader.d.ts.map +1 -1
- package/dist/backends/webgl2/glsl/text.glsl.d.ts +12 -0
- package/dist/backends/webgl2/glsl/text.glsl.d.ts.map +1 -0
- package/dist/backends/webgl2/mod.d.ts +1 -0
- package/dist/backends/webgl2/mod.d.ts.map +1 -1
- package/dist/mod.js +725 -371
- package/dist/mod.js.map +9 -7
- package/dist/textures/AssetManager.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/backends/webgl2/WebGLFontPipeline.ts +173 -0
- package/src/backends/webgl2/WebGLTextShader.ts +253 -13
- package/src/backends/webgl2/glsl/text.glsl.ts +132 -0
- package/src/backends/webgl2/mod.ts +1 -0
- package/src/textures/AssetManager.ts +10 -2
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { MsdfFont } from "../../text/MsdfFont";
|
|
2
|
+
/**
|
|
3
|
+
* Manages WebGL font resources for MSDF text rendering.
|
|
4
|
+
*
|
|
5
|
+
* Creates and manages:
|
|
6
|
+
* - Font atlas texture (MSDF image)
|
|
7
|
+
* - Character data texture (metrics as RGBA32F)
|
|
8
|
+
* - Text buffer texture (per-glyph positions)
|
|
9
|
+
*/
|
|
10
|
+
export declare class WebGLFontPipeline {
|
|
11
|
+
#private;
|
|
12
|
+
readonly font: MsdfFont;
|
|
13
|
+
readonly fontTexture: WebGLTexture;
|
|
14
|
+
readonly charDataTexture: WebGLTexture;
|
|
15
|
+
readonly textBufferTexture: WebGLTexture;
|
|
16
|
+
readonly maxCharCount: number;
|
|
17
|
+
readonly lineHeight: number;
|
|
18
|
+
private constructor();
|
|
19
|
+
static create(gl: WebGL2RenderingContext, font: MsdfFont, maxCharCount: number): WebGLFontPipeline;
|
|
20
|
+
/**
|
|
21
|
+
* Update the text buffer texture with glyph data.
|
|
22
|
+
*/
|
|
23
|
+
updateTextBuffer(data: Float32Array, glyphCount: number): void;
|
|
24
|
+
destroy(): void;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=WebGLFontPipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebGLFontPipeline.d.ts","sourceRoot":"","sources":["../../../src/backends/webgl2/WebGLFontPipeline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAGpD;;;;;;;GAOG;AACH,qBAAa,iBAAiB;;IAC5B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,WAAW,EAAE,YAAY,CAAC;IACnC,QAAQ,CAAC,eAAe,EAAE,YAAY,CAAC;IACvC,QAAQ,CAAC,iBAAiB,EAAE,YAAY,CAAC;IACzC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAI5B,OAAO;IAiBP,MAAM,CAAC,MAAM,CACX,EAAE,EAAE,sBAAsB,EAC1B,IAAI,EAAE,QAAQ,EACd,YAAY,EAAE,MAAM,GACnB,iBAAiB;IAwGpB;;OAEG;IACH,gBAAgB,CAAC,IAAI,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;IAiB9D,OAAO,IAAI,IAAI;CAMhB"}
|
|
@@ -2,19 +2,23 @@ import type { EngineUniform } from "../../coreTypes/EngineUniform";
|
|
|
2
2
|
import type { SceneNode } from "../../scene/SceneNode";
|
|
3
3
|
import type { MsdfFont } from "../../text/MsdfFont";
|
|
4
4
|
import type { ITextShader } from "../ITextShader";
|
|
5
|
+
import type { WebGLBackend } from "./WebGLBackend";
|
|
6
|
+
import type { WebGLFontPipeline } from "./WebGLFontPipeline";
|
|
5
7
|
/**
|
|
6
|
-
* WebGL text shader
|
|
8
|
+
* WebGL 2 text shader for MSDF font rendering.
|
|
7
9
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
+
* Unlike WebGPU which batches all text into storage buffers, WebGL renders
|
|
11
|
+
* each TextNode separately since WebGL2 doesn't support firstInstance.
|
|
10
12
|
*/
|
|
11
13
|
export declare class WebGLTextShader implements ITextShader {
|
|
14
|
+
#private;
|
|
12
15
|
readonly label = "text";
|
|
13
16
|
readonly font: MsdfFont;
|
|
14
17
|
readonly maxCharCount: number;
|
|
15
|
-
constructor(
|
|
16
|
-
startFrame(
|
|
17
|
-
processBatch(
|
|
18
|
+
constructor(backend: WebGLBackend, pipeline: WebGLFontPipeline);
|
|
19
|
+
startFrame(uniform: EngineUniform): void;
|
|
20
|
+
processBatch(nodes: SceneNode[]): number;
|
|
18
21
|
endFrame(): void;
|
|
22
|
+
destroy(): void;
|
|
19
23
|
}
|
|
20
24
|
//# sourceMappingURL=WebGLTextShader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebGLTextShader.d.ts","sourceRoot":"","sources":["../../../src/backends/webgl2/WebGLTextShader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"WebGLTextShader.d.ts","sourceRoot":"","sources":["../../../src/backends/webgl2/WebGLTextShader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAOpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D;;;;;GAKG;AACH,qBAAa,eAAgB,YAAW,WAAW;;IACjD,QAAQ,CAAC,KAAK,UAAU;IACxB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;gBAqBlB,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,iBAAiB;IAmD9D,UAAU,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI;IAIxC,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,MAAM;IA+IxC,QAAQ,IAAI,IAAI;IAyBhB,OAAO,IAAI,IAAI;CAMhB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GLSL ES 3.0 port of the WGSL text shader for MSDF font rendering.
|
|
3
|
+
*
|
|
4
|
+
* Key differences from WebGPU version:
|
|
5
|
+
* - Uses texelFetch() to read from data textures instead of storage buffers
|
|
6
|
+
* - Character metrics stored in RGBA32F texture (8 floats per char = 2 texels)
|
|
7
|
+
* - Per-glyph positions stored in RGBA32F texture (vec4: xy = pos, z = charIndex)
|
|
8
|
+
* - Each TextNode is rendered separately with uniforms (no firstInstance)
|
|
9
|
+
*/
|
|
10
|
+
export declare const vertexShader = "#version 300 es\nprecision highp float;\n\n// Engine uniforms\nuniform mat3 u_viewProjection;\n\n// Per-text-block uniforms\nuniform mat3 u_textTransform;\nuniform vec4 u_textColor;\nuniform float u_fontSize;\nuniform float u_blockWidth;\nuniform float u_blockHeight;\nuniform float u_lineHeight;\n\n// Character data texture (RGBA32F, 2 texels per character)\n// Texel 0: texOffset.xy, texExtent.xy\n// Texel 1: size.xy, offset.xy\nuniform sampler2D u_charData;\n\n// Text buffer texture (RGBA32F, 1 texel per glyph)\n// Each texel: xy = glyph position, z = char index\nuniform sampler2D u_textBuffer;\n\n// Outputs to fragment shader\nout vec2 v_texcoord;\n\n// Quad vertex positions for a character (matches WGSL)\nconst vec2 pos[4] = vec2[4](\n vec2(0.0, -1.0),\n vec2(1.0, -1.0),\n vec2(0.0, 0.0),\n vec2(1.0, 0.0)\n);\n\nvoid main() {\n // gl_VertexID gives us 0-3 for the quad vertices\n // gl_InstanceID gives us which glyph we're rendering\n int vertexIndex = gl_VertexID;\n int glyphIndex = gl_InstanceID;\n\n // Fetch glyph data from text buffer texture\n vec4 glyphData = texelFetch(u_textBuffer, ivec2(glyphIndex, 0), 0);\n vec2 glyphPos = glyphData.xy;\n int charIndex = int(glyphData.z);\n\n // Fetch character metrics (2 texels per char)\n // Texel 0: texOffset.x, texOffset.y, texExtent.x, texExtent.y\n // Texel 1: size.x, size.y, offset.x, offset.y\n vec4 charData0 = texelFetch(u_charData, ivec2(charIndex * 2, 0), 0);\n vec4 charData1 = texelFetch(u_charData, ivec2(charIndex * 2 + 1, 0), 0);\n\n vec2 texOffset = charData0.xy;\n vec2 texExtent = charData0.zw;\n vec2 charSize = charData1.xy;\n vec2 charOffset = charData1.zw;\n\n // Center text vertically; origin is mid-height\n vec2 offset = vec2(0.0, -u_blockHeight / 2.0);\n\n // Glyph position in ems (quad pos * size + per-char offset)\n vec2 emPos = pos[vertexIndex] * charSize + charOffset + glyphPos - offset;\n vec2 charPos = emPos * (u_fontSize / u_lineHeight);\n\n // Transform position through model and view-projection matrices\n vec3 worldPos = u_textTransform * vec3(charPos, 1.0);\n vec3 clipPos = u_viewProjection * worldPos;\n\n gl_Position = vec4(clipPos.xy, 0.0, 1.0);\n\n // Calculate texture coordinates\n v_texcoord = pos[vertexIndex] * vec2(1.0, -1.0);\n v_texcoord *= texExtent;\n v_texcoord += texOffset;\n}\n";
|
|
11
|
+
export declare const fragmentShader = "#version 300 es\nprecision highp float;\n\n// Font texture (MSDF atlas)\nuniform sampler2D u_fontTexture;\n\n// Text color\nuniform vec4 u_textColor;\n\n// Input from vertex shader\nin vec2 v_texcoord;\n\n// Output color\nout vec4 fragColor;\n\n// Signed distance function sampling for MSDF font rendering\n// Median of three: max(min(r,g), min(max(r,g), b))\nfloat sampleMsdf(vec2 texcoord) {\n vec4 c = texture(u_fontTexture, texcoord);\n return max(min(c.r, c.g), min(max(c.r, c.g), c.b));\n}\n\nvoid main() {\n // pxRange (AKA distanceRange) comes from the msdfgen tool\n float pxRange = 4.0;\n vec2 texSize = vec2(textureSize(u_fontTexture, 0));\n\n // Anti-aliasing technique by Paul Houx\n // https://github.com/Chlumsky/msdfgen/issues/22#issuecomment-234958005\n float dx = texSize.x * length(vec2(dFdx(v_texcoord.x), dFdy(v_texcoord.x)));\n float dy = texSize.y * length(vec2(dFdx(v_texcoord.y), dFdy(v_texcoord.y)));\n\n float toPixels = pxRange * inversesqrt(dx * dx + dy * dy);\n float sigDist = sampleMsdf(v_texcoord) - 0.5;\n float pxDist = sigDist * toPixels;\n\n float edgeWidth = 0.5;\n float alpha = smoothstep(-edgeWidth, edgeWidth, pxDist);\n\n if (alpha < 0.001) {\n discard;\n }\n\n fragColor = vec4(u_textColor.rgb, u_textColor.a * alpha);\n}\n";
|
|
12
|
+
//# sourceMappingURL=text.glsl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.glsl.d.ts","sourceRoot":"","sources":["../../../../src/backends/webgl2/glsl/text.glsl.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,eAAO,MAAM,YAAY,6yEA0ExB,CAAC;AAEF,eAAO,MAAM,cAAc,4wCA6C1B,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { WebGLBackend, type WebGLBackendOptions } from "./WebGLBackend";
|
|
2
|
+
export { WebGLFontPipeline } from "./WebGLFontPipeline";
|
|
2
3
|
export { WebGLQuadShader } from "./WebGLQuadShader";
|
|
3
4
|
export { WebGLTextShader } from "./WebGLTextShader";
|
|
4
5
|
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/backends/webgl2/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/backends/webgl2/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
|