@bloopjs/toodle 0.0.100
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/LICENSE +21 -0
- package/README.md +44 -0
- package/dist/Toodle.d.ts +304 -0
- package/dist/Toodle.d.ts.map +1 -0
- package/dist/colors/mod.d.ts +872 -0
- package/dist/colors/mod.d.ts.map +1 -0
- package/dist/coreTypes/Color.d.ts +7 -0
- package/dist/coreTypes/Color.d.ts.map +1 -0
- package/dist/coreTypes/Point.d.ts +8 -0
- package/dist/coreTypes/Point.d.ts.map +1 -0
- package/dist/coreTypes/Size.d.ts +5 -0
- package/dist/coreTypes/Size.d.ts.map +1 -0
- package/dist/coreTypes/Transform.d.ts +16 -0
- package/dist/coreTypes/Transform.d.ts.map +1 -0
- package/dist/coreTypes/Vec2.d.ts +8 -0
- package/dist/coreTypes/Vec2.d.ts.map +1 -0
- package/dist/coreTypes/mod.d.ts +6 -0
- package/dist/coreTypes/mod.d.ts.map +1 -0
- package/dist/docs/snippets/add-remove-children.d.ts +1 -0
- package/dist/docs/snippets/basic-quad.d.ts +1 -0
- package/dist/docs/snippets/filter-linear.d.ts +1 -0
- package/dist/docs/snippets/filter-nearest.d.ts +1 -0
- package/dist/docs/snippets/flipxy.d.ts +1 -0
- package/dist/docs/snippets/hello-text.d.ts +1 -0
- package/dist/docs/snippets/jumbo-textures.d.ts +1 -0
- package/dist/docs/snippets/layer.d.ts +1 -0
- package/dist/docs/snippets/layout-edges.d.ts +1 -0
- package/dist/docs/snippets/layout-screen-and-world-space.d.ts +1 -0
- package/dist/docs/snippets/postprocess.d.ts +1 -0
- package/dist/docs/snippets/quad-size-scale.d.ts +1 -0
- package/dist/docs/snippets/quickstart.d.ts +1 -0
- package/dist/docs/snippets/repeat-texture-loading.d.ts +1 -0
- package/dist/docs/snippets/screen-shaders.d.ts +1 -0
- package/dist/docs/snippets/shader-color-flash.d.ts +1 -0
- package/dist/docs/snippets/shader-default.d.ts +1 -0
- package/dist/docs/snippets/shader-fill.d.ts +1 -0
- package/dist/docs/snippets/shapes-line.d.ts +1 -0
- package/dist/docs/snippets/sprite-region.d.ts +1 -0
- package/dist/docs/snippets/text-alignment.d.ts +1 -0
- package/dist/docs/snippets/text-shrink-to-fit.d.ts +1 -0
- package/dist/docs/snippets/text-word-wrap.d.ts +1 -0
- package/dist/docs/snippets/texture-bundles-prebaked.d.ts +1 -0
- package/dist/docs/snippets/texture-bundles.d.ts +1 -0
- package/dist/docs/snippets/transforms.d.ts +1 -0
- package/dist/docs/snippets/transparent-cropping.d.ts +1 -0
- package/dist/examples/0-hello.d.ts +1 -0
- package/dist/examples/1-hello.d.ts +1 -0
- package/dist/examples/1-hello.d.ts.map +1 -0
- package/dist/examples/1-quad.d.ts +1 -0
- package/dist/examples/10-resize.d.ts +1 -0
- package/dist/examples/10-resize.d.ts.map +1 -0
- package/dist/examples/11-bundle-test.d.ts +1 -0
- package/dist/examples/11-bundle-test.d.ts.map +1 -0
- package/dist/examples/12-transparent-pixel-cropping.d.ts +1 -0
- package/dist/examples/12-transparent-pixel-cropping.d.ts.map +1 -0
- package/dist/examples/13-crop.d.ts +1 -0
- package/dist/examples/13-crop.d.ts.map +1 -0
- package/dist/examples/14-bundle-bench.d.ts +1 -0
- package/dist/examples/14-bundle-bench.d.ts.map +1 -0
- package/dist/examples/15-text-layer.d.ts +1 -0
- package/dist/examples/15-text-layer.d.ts.map +1 -0
- package/dist/examples/16-jumbo-texture.d.ts +1 -0
- package/dist/examples/16-jumbo-textures.d.ts +1 -0
- package/dist/examples/16-screen-shader.d.ts +1 -0
- package/dist/examples/16-screen-shader.d.ts.map +1 -0
- package/dist/examples/17-lighting.d.ts +1 -0
- package/dist/examples/17-lighting.d.ts.map +1 -0
- package/dist/examples/17-translations.d.ts +1 -0
- package/dist/examples/18-blur.d.ts +1 -0
- package/dist/examples/19-postprocess.d.ts +1 -0
- package/dist/examples/19-screenshader.d.ts +1 -0
- package/dist/examples/2-shapes.d.ts +1 -0
- package/dist/examples/2-shapes.d.ts.map +1 -0
- package/dist/examples/3-shader.d.ts +1 -0
- package/dist/examples/3-shader.d.ts.map +1 -0
- package/dist/examples/4-shader-bench.d.ts +1 -0
- package/dist/examples/4-shader-bench.d.ts.map +1 -0
- package/dist/examples/5-z.d.ts +1 -0
- package/dist/examples/5-z.d.ts.map +1 -0
- package/dist/examples/6-atlas.d.ts +1 -0
- package/dist/examples/6-atlas.d.ts.map +1 -0
- package/dist/examples/7-text.d.ts +1 -0
- package/dist/examples/7-text.d.ts.map +1 -0
- package/dist/examples/8-text-bench.d.ts +1 -0
- package/dist/examples/8-text-bench.d.ts.map +1 -0
- package/dist/examples/9-alignment.d.ts +1 -0
- package/dist/examples/9-alignment.d.ts.map +1 -0
- package/dist/examples/main.d.ts +1 -0
- package/dist/examples/main.d.ts.map +1 -0
- package/dist/examples/util.d.ts +82 -0
- package/dist/examples/util.d.ts.map +1 -0
- package/dist/limits.d.ts +23 -0
- package/dist/limits.d.ts.map +1 -0
- package/dist/math/angle.d.ts +13 -0
- package/dist/math/angle.d.ts.map +1 -0
- package/dist/math/matrix.d.ts +26 -0
- package/dist/math/matrix.d.ts.map +1 -0
- package/dist/math/mod.d.ts +3 -0
- package/dist/math/mod.d.ts.map +1 -0
- package/dist/mod.d.ts +17 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +19665 -0
- package/dist/mod.js.map +41 -0
- package/dist/postprocess.d.ts +10 -0
- package/dist/postprocess.d.ts.map +1 -0
- package/dist/scene/Batcher.d.ts +20 -0
- package/dist/scene/Batcher.d.ts.map +1 -0
- package/dist/scene/Camera.d.ts +16 -0
- package/dist/scene/Camera.d.ts.map +1 -0
- package/dist/scene/JumboQuadNode.d.ts +29 -0
- package/dist/scene/JumboQuadNode.d.ts.map +1 -0
- package/dist/scene/QuadNode.d.ts +159 -0
- package/dist/scene/QuadNode.d.ts.map +1 -0
- package/dist/scene/RenderComponent.d.ts +11 -0
- package/dist/scene/RenderComponent.d.ts.map +1 -0
- package/dist/scene/SceneNode.d.ts +300 -0
- package/dist/scene/SceneNode.d.ts.map +1 -0
- package/dist/scene/mod.d.ts +5 -0
- package/dist/scene/mod.d.ts.map +1 -0
- package/dist/screen/mod.d.ts +2 -0
- package/dist/screen/mod.d.ts.map +1 -0
- package/dist/screen/resolution.d.ts +5 -0
- package/dist/screen/resolution.d.ts.map +1 -0
- package/dist/shaders/EngineUniform.d.ts +9 -0
- package/dist/shaders/EngineUniform.d.ts.map +1 -0
- package/dist/shaders/IShader.d.ts +15 -0
- package/dist/shaders/IShader.d.ts.map +1 -0
- package/dist/shaders/QuadShader.d.ts +18 -0
- package/dist/shaders/QuadShader.d.ts.map +1 -0
- package/dist/shaders/ShaderDescriptor.d.ts +7 -0
- package/dist/shaders/ShaderDescriptor.d.ts.map +1 -0
- package/dist/shaders/mod.d.ts +6 -0
- package/dist/shaders/mod.d.ts.map +1 -0
- package/dist/shaders/parser.d.ts +8 -0
- package/dist/shaders/parser.d.ts.map +1 -0
- package/dist/shaders/postprocess/blur.d.ts +3 -0
- package/dist/shaders/postprocess/blur.d.ts.map +1 -0
- package/dist/shaders/postprocess/mod.d.ts +17 -0
- package/dist/shaders/postprocess/mod.d.ts.map +1 -0
- package/dist/shaders/samplers.d.ts +3 -0
- package/dist/shaders/samplers.d.ts.map +1 -0
- package/dist/shaders/wgsl/example.wgsl.d.ts +3 -0
- package/dist/shaders/wgsl/example.wgsl.d.ts.map +1 -0
- package/dist/shaders/wgsl/hello.wgsl.d.ts +3 -0
- package/dist/shaders/wgsl/hello.wgsl.d.ts.map +1 -0
- package/dist/shaders/wgsl/helloInstanced.wgsl.d.ts +3 -0
- package/dist/shaders/wgsl/helloInstanced.wgsl.d.ts.map +1 -0
- package/dist/shaders/wgsl/quad.wgsl.d.ts +3 -0
- package/dist/shaders/wgsl/quad.wgsl.d.ts.map +1 -0
- package/dist/src/Toodle.d.ts +303 -0
- package/dist/src/Toodle.d.ts.map +1 -0
- package/dist/src/colors/mod.d.ts +871 -0
- package/dist/src/coreTypes/Color.d.ts +6 -0
- package/dist/src/coreTypes/Color.d.ts.map +1 -0
- package/dist/src/coreTypes/Point.d.ts +7 -0
- package/dist/src/coreTypes/Point.d.ts.map +1 -0
- package/dist/src/coreTypes/Size.d.ts +4 -0
- package/dist/src/coreTypes/Size.d.ts.map +1 -0
- package/dist/src/coreTypes/Transform.d.ts +15 -0
- package/dist/src/coreTypes/Transform.d.ts.map +1 -0
- package/dist/src/coreTypes/Vec2.d.ts +7 -0
- package/dist/src/coreTypes/Vec2.d.ts.map +1 -0
- package/dist/src/coreTypes/mod.d.ts +5 -0
- package/dist/src/coreTypes/mod.d.ts.map +1 -0
- package/dist/src/limits.d.ts +22 -0
- package/dist/src/limits.d.ts.map +1 -0
- package/dist/src/math/angle.d.ts +12 -0
- package/dist/src/math/angle.d.ts.map +1 -0
- package/dist/src/math/matrix.d.ts +25 -0
- package/dist/src/math/matrix.d.ts.map +1 -0
- package/dist/src/math/mod.d.ts +2 -0
- package/dist/src/math/mod.d.ts.map +1 -0
- package/dist/src/mod.d.ts +16 -0
- package/dist/src/mod.d.ts.map +1 -0
- package/dist/src/postprocess.d.ts +10 -0
- package/dist/src/postprocess.d.ts.map +1 -0
- package/dist/src/scene/Batcher.d.ts +19 -0
- package/dist/src/scene/Batcher.d.ts.map +1 -0
- package/dist/src/scene/Camera.d.ts +15 -0
- package/dist/src/scene/Camera.d.ts.map +1 -0
- package/dist/src/scene/JumboQuadNode.d.ts +28 -0
- package/dist/src/scene/QuadNode.d.ts +158 -0
- package/dist/src/scene/QuadNode.d.ts.map +1 -0
- package/dist/src/scene/RenderComponent.d.ts +10 -0
- package/dist/src/scene/RenderComponent.d.ts.map +1 -0
- package/dist/src/scene/SceneNode.d.ts +299 -0
- package/dist/src/scene/SceneNode.d.ts.map +1 -0
- package/dist/src/scene/mod.d.ts +4 -0
- package/dist/src/scene/mod.d.ts.map +1 -0
- package/dist/src/screen/mod.d.ts +1 -0
- package/dist/src/screen/mod.d.ts.map +1 -0
- package/dist/src/screen/resolution.d.ts +4 -0
- package/dist/src/screen/resolution.d.ts.map +1 -0
- package/dist/src/shaders/EngineUniform.d.ts +8 -0
- package/dist/src/shaders/EngineUniform.d.ts.map +1 -0
- package/dist/src/shaders/IShader.d.ts +14 -0
- package/dist/src/shaders/IShader.d.ts.map +1 -0
- package/dist/src/shaders/QuadShader.d.ts +17 -0
- package/dist/src/shaders/QuadShader.d.ts.map +1 -0
- package/dist/src/shaders/ShaderDescriptor.d.ts +6 -0
- package/dist/src/shaders/ShaderDescriptor.d.ts.map +1 -0
- package/dist/src/shaders/mod.d.ts +5 -0
- package/dist/src/shaders/mod.d.ts.map +1 -0
- package/dist/src/shaders/parser.d.ts +7 -0
- package/dist/src/shaders/parser.d.ts.map +1 -0
- package/dist/src/shaders/postprocess/blur.d.ts +2 -0
- package/dist/src/shaders/postprocess/mod.d.ts +16 -0
- package/dist/src/shaders/postprocess/postprocess.d.ts +8 -0
- package/dist/src/shaders/postprocess/util.d.ts +2 -0
- package/dist/src/shaders/samplers.d.ts +2 -0
- package/dist/src/shaders/samplers.d.ts.map +1 -0
- package/dist/src/shaders/wgsl/example.wgsl.d.ts +2 -0
- package/dist/src/shaders/wgsl/example.wgsl.d.ts.map +1 -0
- package/dist/src/shaders/wgsl/hello.wgsl.d.ts +2 -0
- package/dist/src/shaders/wgsl/hello.wgsl.d.ts.map +1 -0
- package/dist/src/shaders/wgsl/helloInstanced.wgsl.d.ts +2 -0
- package/dist/src/shaders/wgsl/helloInstanced.wgsl.d.ts.map +1 -0
- package/dist/src/shaders/wgsl/quad.wgsl.d.ts +2 -0
- package/dist/src/shaders/wgsl/quad.wgsl.d.ts.map +1 -0
- package/dist/src/text/FontPipeline.d.ts +13 -0
- package/dist/src/text/FontPipeline.d.ts.map +1 -0
- package/dist/src/text/MsdfFont.d.ts +81 -0
- package/dist/src/text/MsdfFont.d.ts.map +1 -0
- package/dist/src/text/TextFormatting.d.ts +18 -0
- package/dist/src/text/TextFormatting.d.ts.map +1 -0
- package/dist/src/text/TextNode.d.ts +18 -0
- package/dist/src/text/TextNode.d.ts.map +1 -0
- package/dist/src/text/TextShader.d.ts +14 -0
- package/dist/src/text/TextShader.d.ts.map +1 -0
- package/dist/src/text/mod.d.ts +3 -0
- package/dist/src/text/mod.d.ts.map +1 -0
- package/dist/src/text/shaping.d.ts +38 -0
- package/dist/src/text/shaping.d.ts.map +1 -0
- package/dist/src/text/text.wgsl.d.ts +2 -0
- package/dist/src/text/text.wgsl.d.ts.map +1 -0
- package/dist/src/textures/AssetManager.d.ts +181 -0
- package/dist/src/textures/AssetManager.d.ts.map +1 -0
- package/dist/src/textures/NewTextureComputeShader.d.ts +28 -0
- package/dist/src/textures/TextureComputeShader.d.ts +20 -0
- package/dist/src/textures/TextureComputeShader.d.ts.map +1 -0
- package/dist/src/textures/crop.wgsl.d.ts +2 -0
- package/dist/src/textures/mod.d.ts +1 -0
- package/dist/src/textures/mod.d.ts.map +1 -0
- package/dist/src/textures/pixel-scraping.wgsl.d.ts +2 -0
- package/dist/src/textures/pixel-scraping.wgsl.d.ts.map +1 -0
- package/dist/src/textures/texture-processing.wgsl.d.ts +2 -0
- package/dist/src/textures/types.d.ts +176 -0
- package/dist/src/textures/types.d.ts.map +1 -0
- package/dist/src/textures/util.d.ts +7 -0
- package/dist/src/textures/util.d.ts.map +1 -0
- package/dist/src/utils/assert.d.ts +1 -0
- package/dist/src/utils/assert.d.ts.map +1 -0
- package/dist/src/utils/boilerplate.d.ts +10 -0
- package/dist/src/utils/boilerplate.d.ts.map +1 -0
- package/dist/src/utils/error.d.ts +7 -0
- package/dist/src/utils/error.d.ts.map +1 -0
- package/dist/src/utils/mod.d.ts +2 -0
- package/dist/src/utils/mod.d.ts.map +1 -0
- package/dist/src/utils/pool.d.ts +22 -0
- package/dist/src/utils/pool.d.ts.map +1 -0
- package/dist/test/math/matrix.test.d.ts +1 -0
- package/dist/test/scene/Batcher.test.d.ts +1 -0
- package/dist/test/scene/SceneNode.test.d.ts +1 -0
- package/dist/test/shader/parser.test.d.ts +1 -0
- package/dist/text/FontPipeline.d.ts +14 -0
- package/dist/text/FontPipeline.d.ts.map +1 -0
- package/dist/text/MsdfFont.d.ts +82 -0
- package/dist/text/MsdfFont.d.ts.map +1 -0
- package/dist/text/TextFormatting.d.ts +19 -0
- package/dist/text/TextFormatting.d.ts.map +1 -0
- package/dist/text/TextNode.d.ts +19 -0
- package/dist/text/TextNode.d.ts.map +1 -0
- package/dist/text/TextShader.d.ts +15 -0
- package/dist/text/TextShader.d.ts.map +1 -0
- package/dist/text/mod.d.ts +4 -0
- package/dist/text/mod.d.ts.map +1 -0
- package/dist/text/shaping.d.ts +39 -0
- package/dist/text/shaping.d.ts.map +1 -0
- package/dist/text/text.wgsl.d.ts +3 -0
- package/dist/text/text.wgsl.d.ts.map +1 -0
- package/dist/textures/AssetManager.d.ts +182 -0
- package/dist/textures/AssetManager.d.ts.map +1 -0
- package/dist/textures/TextureComputeShader.d.ts +21 -0
- package/dist/textures/TextureComputeShader.d.ts.map +1 -0
- package/dist/textures/mod.d.ts +2 -0
- package/dist/textures/mod.d.ts.map +1 -0
- package/dist/textures/pixel-scraping.wgsl.d.ts +3 -0
- package/dist/textures/pixel-scraping.wgsl.d.ts.map +1 -0
- package/dist/textures/types.d.ts +177 -0
- package/dist/textures/types.d.ts.map +1 -0
- package/dist/textures/util.d.ts +8 -0
- package/dist/textures/util.d.ts.map +1 -0
- package/dist/utils/assert.d.ts +2 -0
- package/dist/utils/assert.d.ts.map +1 -0
- package/dist/utils/boilerplate.d.ts +11 -0
- package/dist/utils/boilerplate.d.ts.map +1 -0
- package/dist/utils/error.d.ts +8 -0
- package/dist/utils/error.d.ts.map +1 -0
- package/dist/utils/mod.d.ts +3 -0
- package/dist/utils/mod.d.ts.map +1 -0
- package/dist/utils/pool.d.ts +23 -0
- package/dist/utils/pool.d.ts.map +1 -0
- package/package.json +47 -0
- package/src/Toodle.ts +853 -0
- package/src/colors/mod.ts +151 -0
- package/src/coreTypes/Color.ts +1 -0
- package/src/coreTypes/Point.ts +7 -0
- package/src/coreTypes/Size.ts +4 -0
- package/src/coreTypes/Transform.ts +16 -0
- package/src/coreTypes/Vec2.ts +7 -0
- package/src/coreTypes/mod.ts +5 -0
- package/src/globals.d.ts +4 -0
- package/src/limits.ts +23 -0
- package/src/math/angle.ts +17 -0
- package/src/math/matrix.ts +99 -0
- package/src/math/mod.ts +2 -0
- package/src/mod.ts +22 -0
- package/src/scene/Batcher.ts +61 -0
- package/src/scene/Camera.ts +69 -0
- package/src/scene/JumboQuadNode.ts +219 -0
- package/src/scene/QuadNode.ts +403 -0
- package/src/scene/RenderComponent.ts +12 -0
- package/src/scene/SceneNode.ts +668 -0
- package/src/scene/mod.ts +4 -0
- package/src/screen/mod.ts +1 -0
- package/src/screen/resolution.ts +1 -0
- package/src/shaders/EngineUniform.ts +11 -0
- package/src/shaders/IShader.ts +20 -0
- package/src/shaders/QuadShader.ts +288 -0
- package/src/shaders/ShaderDescriptor.ts +6 -0
- package/src/shaders/mod.ts +5 -0
- package/src/shaders/parser.ts +221 -0
- package/src/shaders/postprocess/blur.ts +245 -0
- package/src/shaders/postprocess/mod.ts +71 -0
- package/src/shaders/samplers.ts +13 -0
- package/src/shaders/wgsl/example.wgsl.ts +24 -0
- package/src/shaders/wgsl/hello.wgsl.ts +62 -0
- package/src/shaders/wgsl/helloInstanced.wgsl.ts +46 -0
- package/src/shaders/wgsl/quad.wgsl.ts +140 -0
- package/src/text/FontPipeline.ts +212 -0
- package/src/text/MsdfFont.ts +190 -0
- package/src/text/TextFormatting.ts +28 -0
- package/src/text/TextNode.ts +82 -0
- package/src/text/TextShader.ts +223 -0
- package/src/text/mod.ts +8 -0
- package/src/text/shaping.ts +280 -0
- package/src/text/text.wgsl.ts +149 -0
- package/src/textures/AssetManager.ts +746 -0
- package/src/textures/TextureComputeShader.ts +434 -0
- package/src/textures/mod.ts +1 -0
- package/src/textures/pixel-scraping.wgsl.ts +131 -0
- package/src/textures/types.ts +182 -0
- package/src/textures/util.ts +352 -0
- package/src/utils/assert.ts +5 -0
- package/src/utils/boilerplate.ts +110 -0
- package/src/utils/error.ts +14 -0
- package/src/utils/mod.ts +2 -0
- package/src/utils/pool.ts +42 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A simple pool for creating and reusing objects to avoid allocation between frames
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
*
|
|
6
|
+
* const pool = new Pool(() => new SomeObject(), 10);
|
|
7
|
+
*
|
|
8
|
+
* function animate() {
|
|
9
|
+
* const obj = pool.get();
|
|
10
|
+
* console.log(obj);
|
|
11
|
+
* pool.free();
|
|
12
|
+
* requestAnimationFrame(animate);
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* requestAnimationFrame(animate);
|
|
16
|
+
*/
|
|
17
|
+
export declare class Pool<T> {
|
|
18
|
+
#private;
|
|
19
|
+
constructor(create: () => T, initialSize?: number);
|
|
20
|
+
get(): T;
|
|
21
|
+
free(): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../../src/utils/pool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,IAAI,CAAC,CAAC;;gBAKL,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,SAAI;IAS5C,GAAG;IAQH,IAAI;CAGL"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { MsdfFont } from "./MsdfFont";
|
|
2
|
+
/**
|
|
3
|
+
* A webgpu pipeline for rendering blocks of text with a given font.
|
|
4
|
+
*/
|
|
5
|
+
export declare class FontPipeline {
|
|
6
|
+
pipeline: GPURenderPipeline;
|
|
7
|
+
font: MsdfFont;
|
|
8
|
+
fontBindGroup: GPUBindGroup;
|
|
9
|
+
maxCharCount: number;
|
|
10
|
+
constructor(pipeline: GPURenderPipeline, font: MsdfFont, fontBindGroup: GPUBindGroup, maxCharCount: number);
|
|
11
|
+
static create(device: GPUDevice, font: MsdfFont, colorFormat: GPUTextureFormat, maxCharCount: number): Promise<FontPipeline>;
|
|
12
|
+
}
|
|
13
|
+
export declare function pipelinePromise(device: GPUDevice, colorFormat: GPUTextureFormat, label: string): Promise<GPURenderPipeline>;
|
|
14
|
+
//# sourceMappingURL=FontPipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FontPipeline.d.ts","sourceRoot":"","sources":["../../src/text/FontPipeline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG3C;;GAEG;AACH,qBAAa,YAAY;IAEd,QAAQ,EAAE,iBAAiB;IAC3B,IAAI,EAAE,QAAQ;IACd,aAAa,EAAE,YAAY;IAC3B,YAAY,EAAE,MAAM;gBAHpB,QAAQ,EAAE,iBAAiB,EAC3B,IAAI,EAAE,QAAQ,EACd,aAAa,EAAE,YAAY,EAC3B,YAAY,EAAE,MAAM;WAGhB,MAAM,CACjB,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,QAAQ,EACd,WAAW,EAAE,gBAAgB,EAC7B,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,YAAY,CAAC;CAuEzB;AAED,wBAAgB,eAAe,CAC7B,MAAM,EAAE,SAAS,EACjB,WAAW,EAAE,gBAAgB,EAC7B,KAAK,EAAE,MAAM,8BA4Cd"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export type KerningMap = Map<number, Map<number, number>>;
|
|
2
|
+
export interface MsdfChar {
|
|
3
|
+
id: number;
|
|
4
|
+
index: number;
|
|
5
|
+
char: string;
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
xoffset: number;
|
|
9
|
+
yoffset: number;
|
|
10
|
+
xadvance: number;
|
|
11
|
+
chnl: number;
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
page: number;
|
|
15
|
+
charIndex: number;
|
|
16
|
+
}
|
|
17
|
+
export declare class MsdfFont {
|
|
18
|
+
#private;
|
|
19
|
+
id: string;
|
|
20
|
+
json: MsdfFontJson;
|
|
21
|
+
imageBitmap: ImageBitmap;
|
|
22
|
+
/** the name of the font */
|
|
23
|
+
name: string;
|
|
24
|
+
/** the set of available characters in the font texture */
|
|
25
|
+
charset: string[];
|
|
26
|
+
charCount: number;
|
|
27
|
+
lineHeight: number;
|
|
28
|
+
/** a binary buffer of character data for loading into the gpu */
|
|
29
|
+
charBuffer: Float32Array;
|
|
30
|
+
constructor(id: string, json: MsdfFontJson, imageBitmap: ImageBitmap);
|
|
31
|
+
getChar(charCode: number): MsdfChar;
|
|
32
|
+
getXAdvance(charCode: number, nextCharCode?: number): number;
|
|
33
|
+
static create(id: string, fontJsonUrl: URL): Promise<MsdfFont>;
|
|
34
|
+
set fallbackCharacter(character: string);
|
|
35
|
+
}
|
|
36
|
+
type MsdfFontJson = {
|
|
37
|
+
pages: string[];
|
|
38
|
+
chars: MsdfChar[];
|
|
39
|
+
info: {
|
|
40
|
+
face: string;
|
|
41
|
+
size: string;
|
|
42
|
+
bold: number;
|
|
43
|
+
italic: number;
|
|
44
|
+
charset: string[];
|
|
45
|
+
unicode: number;
|
|
46
|
+
stretchH: number;
|
|
47
|
+
smooth: number;
|
|
48
|
+
aa: number;
|
|
49
|
+
padding: number[];
|
|
50
|
+
spacing: number[];
|
|
51
|
+
};
|
|
52
|
+
common: {
|
|
53
|
+
lineHeight: number;
|
|
54
|
+
base: number;
|
|
55
|
+
scaleW: number;
|
|
56
|
+
scaleH: number;
|
|
57
|
+
pages: number;
|
|
58
|
+
packed: number;
|
|
59
|
+
alphaChnl: number;
|
|
60
|
+
redChnl: number;
|
|
61
|
+
greenChnl: number;
|
|
62
|
+
blueChnl: number;
|
|
63
|
+
};
|
|
64
|
+
distanceField: {
|
|
65
|
+
fieldType: string;
|
|
66
|
+
distanceRange: number;
|
|
67
|
+
};
|
|
68
|
+
kernings: Kerning[];
|
|
69
|
+
};
|
|
70
|
+
type Kerning = {
|
|
71
|
+
first: number;
|
|
72
|
+
second: number;
|
|
73
|
+
amount: number;
|
|
74
|
+
};
|
|
75
|
+
export declare enum WhitespaceKeyCodes {
|
|
76
|
+
HorizontalTab = 9,
|
|
77
|
+
Newline = 10,
|
|
78
|
+
CarriageReturn = 13,
|
|
79
|
+
Space = 32
|
|
80
|
+
}
|
|
81
|
+
export {};
|
|
82
|
+
//# sourceMappingURL=MsdfFont.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MsdfFont.d.ts","sourceRoot":"","sources":["../../src/text/MsdfFont.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAE1D,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,QAAQ;;IAgBV,EAAE,EAAE,MAAM;IACV,IAAI,EAAE,YAAY;IAClB,WAAW,EAAE,WAAW;IAjBjC,2BAA2B;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IAEnB,iEAAiE;IACjE,UAAU,EAAE,YAAY,CAAC;gBAOhB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,YAAY,EAClB,WAAW,EAAE,WAAW;IA0CjC,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ;IAiBnC,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,SAAK,GAAG,MAAM;WAW3C,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC;IAuBpE,IAAI,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAWtC;CACF;AAED,KAAK,YAAY,GAAG;IAClB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,EAAE,EAAE,MAAM,CAAC;QACX,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,OAAO,EAAE,MAAM,EAAE,CAAC;KACnB,CAAC;IACF,MAAM,EAAE;QACN,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,aAAa,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5D,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB,CAAC;AAEF,KAAK,OAAO,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjE,oBAAY,kBAAkB;IAC5B,aAAa,IAAI;IACjB,OAAO,KAAK;IACZ,cAAc,KAAK;IACnB,KAAK,KAAK;CACX"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Color } from "../coreTypes/Color";
|
|
2
|
+
export interface TextFormatting {
|
|
3
|
+
align?: "left" | "right" | "center";
|
|
4
|
+
fontSize?: number;
|
|
5
|
+
color?: Color;
|
|
6
|
+
wordWrap?: WordWrapOptions;
|
|
7
|
+
shrinkToFit?: ShrinkToFitOptions;
|
|
8
|
+
}
|
|
9
|
+
export type WordWrapOptions = {
|
|
10
|
+
emWidth: number;
|
|
11
|
+
breakOn?: "word" | "character";
|
|
12
|
+
};
|
|
13
|
+
export type ShrinkToFitOptions = {
|
|
14
|
+
minFontSize: number;
|
|
15
|
+
maxFontSize?: number;
|
|
16
|
+
maxLines?: number;
|
|
17
|
+
padding?: number;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=TextFormatting.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextFormatting.d.ts","sourceRoot":"","sources":["../../src/text/TextFormatting.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD,MAAM,WAAW,cAAc;IAE7B,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;IAEpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,KAAK,CAAC,EAAE,KAAK,CAAC;IAGd,QAAQ,CAAC,EAAE,eAAe,CAAC;IAG3B,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Color } from "../coreTypes/Color";
|
|
2
|
+
import { type NodeOptions, SceneNode } from "../scene/SceneNode";
|
|
3
|
+
import type { MsdfFont } from "./MsdfFont";
|
|
4
|
+
import type { TextFormatting } from "./TextFormatting";
|
|
5
|
+
import type { TextShader } from "./TextShader";
|
|
6
|
+
export declare const DEFAULT_FONT_SIZE = 14;
|
|
7
|
+
export declare class TextNode extends SceneNode {
|
|
8
|
+
#private;
|
|
9
|
+
constructor(shader: TextShader, text: string, opts?: TextOptions);
|
|
10
|
+
get text(): string;
|
|
11
|
+
get formatting(): TextFormatting;
|
|
12
|
+
get font(): MsdfFont;
|
|
13
|
+
set text(text: string);
|
|
14
|
+
get tint(): Color;
|
|
15
|
+
set tint(tint: Color);
|
|
16
|
+
set formatting(formatting: TextFormatting);
|
|
17
|
+
}
|
|
18
|
+
export type TextOptions = Omit<NodeOptions, "render"> & TextFormatting;
|
|
19
|
+
//# sourceMappingURL=TextNode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextNode.d.ts","sourceRoot":"","sources":["../../src/text/TextNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,KAAK,WAAW,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC,qBAAa,QAAS,SAAQ,SAAS;;gBAKzB,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,WAAgB;IAgCpE,IAAI,IAAI,IAYO,MAAM,CAVpB;IAED,IAAI,UAAU,IAyBa,cAAc,CAvBxC;IAED,IAAI,IAAI,aAEP;IAED,IAAI,IAAI,CAAC,IAAI,EAAE,MAAM,EAMpB;IAED,IAAI,IAAI,IAIO,KAAK,CAFnB;IAED,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAGnB;IAED,IAAI,UAAU,CAAC,UAAU,EAAE,cAAc,EAGxC;CACF;AAED,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,GAAG,cAAc,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SceneNode } from "../scene/SceneNode";
|
|
2
|
+
import type { EngineUniform } from "../shaders/EngineUniform";
|
|
3
|
+
import type { IShader } from "../shaders/IShader";
|
|
4
|
+
import type { FontPipeline } from "./FontPipeline";
|
|
5
|
+
import type { MsdfFont } from "./MsdfFont";
|
|
6
|
+
export declare class TextShader implements IShader {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(device: GPUDevice, pipeline: FontPipeline, font: MsdfFont, colorFormat: GPUTextureFormat, instanceCount: number);
|
|
9
|
+
startFrame(device: GPUDevice, uniform: EngineUniform): void;
|
|
10
|
+
processBatch(renderPass: GPURenderPassEncoder, nodes: SceneNode[]): number;
|
|
11
|
+
endFrame(): void;
|
|
12
|
+
get font(): MsdfFont;
|
|
13
|
+
get maxCharCount(): number;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=TextShader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextShader.d.ts","sourceRoot":"","sources":["../../src/text/TextShader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAY3C,qBAAa,UAAW,YAAW,OAAO;;gBAetC,MAAM,EAAE,SAAS,EACjB,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAE,QAAQ,EACd,WAAW,EAAE,gBAAgB,EAC7B,aAAa,EAAE,MAAM;IAoEvB,UAAU,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI;IAU3D,YAAY,CAAC,UAAU,EAAE,oBAAoB,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,MAAM;IAiG1E,QAAQ,IAAI,IAAI;IAIhB,IAAI,IAAI,aAEP;IAED,IAAI,YAAY,WAEf;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/text/mod.ts"],"names":[],"mappings":"AAKA,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Size } from "../coreTypes/Size";
|
|
2
|
+
import { type MsdfChar, type MsdfFont } from "./MsdfFont";
|
|
3
|
+
import type { TextFormatting, WordWrapOptions } from "./TextFormatting";
|
|
4
|
+
export interface MsdfTextMeasurements {
|
|
5
|
+
/** The width of the text block in em units. */
|
|
6
|
+
width: number;
|
|
7
|
+
/** The height of the text block in em units. */
|
|
8
|
+
height: number;
|
|
9
|
+
/** The width of each line in em units. */
|
|
10
|
+
lineWidths: number[];
|
|
11
|
+
/** The number of lines in the text block. */
|
|
12
|
+
lineCount: number;
|
|
13
|
+
/** The number of characters printed in the text block. */
|
|
14
|
+
printedCharCount: number;
|
|
15
|
+
/** All words in the text block */
|
|
16
|
+
words: Word[];
|
|
17
|
+
}
|
|
18
|
+
export type Glyph = {
|
|
19
|
+
char: MsdfChar;
|
|
20
|
+
offset: [number, number];
|
|
21
|
+
line: number;
|
|
22
|
+
};
|
|
23
|
+
export type Word = {
|
|
24
|
+
glyphs: Glyph[];
|
|
25
|
+
width: number;
|
|
26
|
+
startX: number;
|
|
27
|
+
startY: number;
|
|
28
|
+
};
|
|
29
|
+
export declare function shapeText(font: MsdfFont, text: string, blockSize: Size, fontSize: number, formatting: TextFormatting, textArray: Float32Array, initialFloatOffset?: number, debug?: boolean): void;
|
|
30
|
+
/**
|
|
31
|
+
* Measure the text and return measurements for block + each glyph.
|
|
32
|
+
* @param font - The font to use.
|
|
33
|
+
* @param text - The text to measure
|
|
34
|
+
* @param wordWrap - Maximum word length before word wrapping
|
|
35
|
+
* @returns The measurements of the text in em units.
|
|
36
|
+
*/
|
|
37
|
+
export declare function measureText(font: MsdfFont, text: string, wordWrap?: WordWrapOptions): MsdfTextMeasurements;
|
|
38
|
+
export declare function findLargestFontSize(font: MsdfFont, text: string, size: Size, formatting: TextFormatting): number | undefined;
|
|
39
|
+
//# sourceMappingURL=shaping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shaping.d.ts","sourceRoot":"","sources":["../../src/text/shaping.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAsB,MAAM,YAAY,CAAC;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AASxE,MAAM,WAAW,oBAAoB;IACnC,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,0CAA0C;IAC1C,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,6CAA6C;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,gBAAgB,EAAE,MAAM,CAAC;IAEzB,kCAAkC;IAClC,KAAK,EAAE,IAAI,EAAE,CAAC;CACf;AAED,MAAM,MAAM,KAAK,GAAG;IAClB,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,IAAI,GAAG;IACjB,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAgB,SAAS,CACvB,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,IAAI,EACf,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,cAAc,EAC1B,SAAS,EAAE,YAAY,EACvB,kBAAkB,SAAI,EACtB,KAAK,UAAQ,QAgEd;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE,MAAM,EACZ,QAAQ,CAAC,EAAE,eAAe,GACzB,oBAAoB,CA+GtB;AACD,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,cAAc,GACzB,MAAM,GAAG,SAAS,CAqCpB"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const _default: "\n// Adapted from: https://webgpu.github.io/webgpu-samples/?sample=textRenderingMsdf\n\n// Quad vertex positions for a character\nconst pos = array(\n vec2f(0, -1),\n vec2f(1, -1),\n vec2f(0, 0),\n vec2f(1, 0),\n);\n\n// Debug colors for visualization\nconst debugColors = array(\n vec4f(1, 0, 0, 1),\n vec4f(0, 1, 0, 1),\n vec4f(0, 0, 1, 1),\n vec4f(1, 1, 1, 1),\n);\n\n// Vertex input from GPU\nstruct VertexInput {\n @builtin(vertex_index) vertex: u32,\n @builtin(instance_index) instance: u32,\n};\n\n// Output from vertex shader to fragment shader\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location(0) texcoord: vec2f,\n @location(1) debugColor: vec4f,\n @location(2) @interpolate(flat) instanceIndex: u32,\n};\n\n// Metadata for a single character glyph\nstruct Char {\n texOffset: vec2f, // Offset to top-left in MSDF texture (pixels)\n texExtent: vec2f, // Size in texture (pixels)\n size: vec2f, // Glyph size in ems\n offset: vec2f, // Position offset in ems\n};\n\n// Metadata for a text block\nstruct TextBlockDescriptor {\n transform: mat3x3f, // Text transform matrix (model matrix)\n color: vec4f, // Text color\n fontSize: f32, // Font size\n blockWidth: f32, // Total width of text block\n blockHeight: f32, // Total height of text block\n bufferPosition: f32 // Index and length in textBuffer\n};\n\n// Font bindings\n@group(0) @binding(0) var fontTexture: texture_2d<f32>;\n@group(0) @binding(1) var fontSampler: sampler;\n@group(0) @binding(2) var<storage> chars: array<Char>;\n@group(0) @binding(3) var<uniform> fontData: vec4f; // Contains line height (x)\n\n// Text bindings\n@group(1) @binding(0) var<storage> texts: array<TextBlockDescriptor>;\n@group(1) @binding(1) var<storage> textBuffer: array<vec4f>; // Each vec4: xy = glyph pos, z = char index\n\n// Global uniforms\n@group(2) @binding(0) var<uniform> viewProjectionMatrix: mat3x3f;\n\n// Vertex shader\n@vertex\nfn vertexMain(input: VertexInput) -> VertexOutput {\n // Because the instance index is used for character indexing, we are\n // overloading the vertex index to store the instance of the text metadata.\n //\n // I.e...\n // Vertex 0-4 = Instance 0, Vertex 0-4\n // Vertex 4-8 = Instance 1, Vertex 0-4\n // Vertex 8-12 = Instance 2, Vertex 0-4\n let vertexIndex = input.vertex % 4;\n let textIndex = input.vertex / 4;\n\n let text = texts[textIndex];\n let textElement = textBuffer[u32(text.bufferPosition) + input.instance];\n let char = chars[u32(textElement.z)];\n\n let lineHeight = fontData.x;\n let textWidth = text.blockWidth;\n let textHeight = text.blockHeight;\n\n // Center text vertically; origin is mid-height\n let offset = vec2f(0, -textHeight / 2);\n\n // Glyph position in ems (quad pos * size + per-char offset)\n let emPos = pos[vertexIndex] * char.size + char.offset + textElement.xy - offset;\n let charPos = emPos * (text.fontSize / lineHeight);\n\n var output: VertexOutput;\n let transformedPosition = viewProjectionMatrix * text.transform * vec3f(charPos, 1);\n\n output.position = vec4f(transformedPosition, 1);\n output.texcoord = pos[vertexIndex] * vec2f(1, -1);\n output.texcoord *= char.texExtent;\n output.texcoord += char.texOffset;\n output.debugColor = debugColors[vertexIndex];\n output.instanceIndex = textIndex;\n return output;\n\n // To debug - hardcode quad in bottom right quarter of the screen:\n // output.position = vec4f(pos[input.vertex], 0, 1);\n}\n\n// Signed distance function sampling for MSDF font rendering\nfn sampleMsdf(texcoord: vec2f) -> f32 {\n let c = textureSample(fontTexture, fontSampler, texcoord);\n return max(min(c.r, c.g), min(max(c.r, c.g), c.b));\n}\n\n// Fragment shader\n// Anti-aliasing technique by Paul Houx\n// more details here:\n// https://github.com/Chlumsky/msdfgen/issues/22#issuecomment-234958005\n@fragment\nfn fragmentMain(input: VertexOutput) -> @location(0) vec4f {\n let text = texts[input.instanceIndex];\n\n // pxRange (AKA distanceRange) comes from the msdfgen tool.\n let pxRange = 4.0;\n let texSize = vec2f(textureDimensions(fontTexture, 0));\n\n let dx = texSize.x * length(vec2f(dpdxFine(input.texcoord.x), dpdyFine(input.texcoord.x)));\n let dy = texSize.y * length(vec2f(dpdxFine(input.texcoord.y), dpdyFine(input.texcoord.y)));\n\n let toPixels = pxRange * inverseSqrt(dx * dx + dy * dy);\n let sigDist = sampleMsdf(input.texcoord) - 0.5;\n let pxDist = sigDist * toPixels;\n\n let edgeWidth = 0.5;\n let alpha = smoothstep(-edgeWidth, edgeWidth, pxDist);\n\n if (alpha < 0.001) {\n discard;\n }\n\n let msdfColor = vec4f(text.color.rgb, text.color.a * alpha);\n return msdfColor;\n\n // Debug options:\n // return text.color;\n // return input.debugColor;\n // return vec4f(1, 0, 1, 1); // hardcoded magenta\n // return textureSample(fontTexture, fontSampler, input.texcoord);\n}\n";
|
|
2
|
+
export default _default;
|
|
3
|
+
//# sourceMappingURL=text.wgsl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.wgsl.d.ts","sourceRoot":"","sources":["../../src/text/text.wgsl.ts"],"names":[],"mappings":";AAAA,wBAoJE"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import type { Size } from "../coreTypes/Size";
|
|
2
|
+
import type { Vec2 } from "../coreTypes/Vec2";
|
|
3
|
+
import type { Limits } from "../limits";
|
|
4
|
+
import { QuadNode } from "../scene/QuadNode";
|
|
5
|
+
import type { SceneNode } from "../scene/SceneNode";
|
|
6
|
+
import { TextShader } from "../text/TextShader";
|
|
7
|
+
import type { AtlasBundleOpts, AtlasCoords, CpuTextureAtlas, TextureBundleOpts } from "./types";
|
|
8
|
+
export type TextureId = string;
|
|
9
|
+
export type BundleId = string;
|
|
10
|
+
export type FontId = string;
|
|
11
|
+
export declare class AssetManager {
|
|
12
|
+
#private;
|
|
13
|
+
readonly textureAtlas: GPUTexture;
|
|
14
|
+
constructor(device: GPUDevice, presentationFormat: GPUTextureFormat, limits: Limits, format?: "rgba8unorm" | "rg8unorm");
|
|
15
|
+
/**
|
|
16
|
+
* True dimensions of a loaded texture, prior to any transparent pixel cropping.
|
|
17
|
+
*
|
|
18
|
+
* @param id - The id of the texture to get the size of
|
|
19
|
+
* @returns The size of the texture
|
|
20
|
+
*/
|
|
21
|
+
getSize(id: TextureId): Size;
|
|
22
|
+
/**
|
|
23
|
+
* Dimensions of a loaded texture, cropped to a minimal bounding box.
|
|
24
|
+
*
|
|
25
|
+
* @param id - The id of the texture to get the size of
|
|
26
|
+
* @returns The size of the texture
|
|
27
|
+
*/
|
|
28
|
+
getCroppedSize(id: TextureId): Size;
|
|
29
|
+
/**
|
|
30
|
+
* Whether the texture has been cropped for extra transparency.
|
|
31
|
+
*
|
|
32
|
+
* @param id - The id of the texture to be checked
|
|
33
|
+
* @returns Whether the image has been cropped (i.e. if it has uvScaledCropped)
|
|
34
|
+
*/
|
|
35
|
+
isCropped(id: TextureId): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* A read-only map of all currently loaded textures.
|
|
38
|
+
*/
|
|
39
|
+
get textures(): Map<string, AtlasCoords[]>;
|
|
40
|
+
/**
|
|
41
|
+
* A read-only array of all currently loaded texture ids.
|
|
42
|
+
*/
|
|
43
|
+
get textureIds(): string[];
|
|
44
|
+
/**
|
|
45
|
+
* Debug method to load a set of textures from a record of URLS.
|
|
46
|
+
*
|
|
47
|
+
* @param textures Collection of strings and URLs representing the texture name and target file
|
|
48
|
+
* @param options LoadingOptions used to modify the loading process
|
|
49
|
+
*
|
|
50
|
+
* Note: this will consume one texture atlas per texture.
|
|
51
|
+
* For more efficient loading of multiple textures, consider {@link loadBundle}
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
*
|
|
55
|
+
* await toodle.assets.loadTextures({
|
|
56
|
+
* "myImage": new URL("assets/image.png", "https://mywebsite.com"),
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* @deprecated use {@link registerBundle} instead. or {@link loadTexture} for debugging
|
|
60
|
+
*/
|
|
61
|
+
loadTextures(opts: TextureBundleOpts["textures"]): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Debug method to load a single texture.
|
|
64
|
+
*
|
|
65
|
+
* @param id ID used to name the texture
|
|
66
|
+
* @param url URL or ImageBitmap target for the image
|
|
67
|
+
* @param options LoadingOptions used to modify the loading process
|
|
68
|
+
*
|
|
69
|
+
* Note: this will consume one texture atlas per texture.
|
|
70
|
+
* For more efficient loading of multiple textures, consider {@link loadBundle}
|
|
71
|
+
*/
|
|
72
|
+
loadTexture(id: TextureId, url: URL | ImageBitmap, options?: Partial<TextureBundleOpts>): Promise<{
|
|
73
|
+
id: string;
|
|
74
|
+
coords: AtlasCoords;
|
|
75
|
+
}>;
|
|
76
|
+
/**
|
|
77
|
+
* Register a bundle of textures.
|
|
78
|
+
*
|
|
79
|
+
* @param bundleId ID used to name the bundle
|
|
80
|
+
* @param bundle Collection of strings and URLs representing the texture name and target file
|
|
81
|
+
* @param options LoadingOptions used to modify the loading process
|
|
82
|
+
*
|
|
83
|
+
* See: https://toodle.gg/f849595b3ed13fc956fc1459a5cb5f0228f9d259/examples/texture-bundles.html
|
|
84
|
+
*/
|
|
85
|
+
registerBundle(bundleId: BundleId, opts: TextureBundleOpts | AtlasBundleOpts): Promise<BundleId>;
|
|
86
|
+
/**
|
|
87
|
+
* Load a bundle of textures to the gpu
|
|
88
|
+
*
|
|
89
|
+
* See: https://toodle.gg/f849595b3ed13fc956fc1459a5cb5f0228f9d259/examples/texture-bundles.html
|
|
90
|
+
*/
|
|
91
|
+
loadBundle(bundleId: BundleId): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Unload a bundle of textures from the gpu - this marks the gpu-side texture atlas
|
|
94
|
+
* as available for future texture loading.
|
|
95
|
+
*
|
|
96
|
+
* @param bundleId - The id of the bundle to unload
|
|
97
|
+
*/
|
|
98
|
+
unloadBundle(bundleId: BundleId): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Load a font to the gpu
|
|
101
|
+
*
|
|
102
|
+
* @param id - The id of the font to load
|
|
103
|
+
* @param url - The url of the font to load
|
|
104
|
+
* @param fallbackCharacter - The character to use as a fallback if the font does not contain a character to be rendererd
|
|
105
|
+
*/
|
|
106
|
+
loadFont(id: string, url: URL, fallbackCharacter?: string): Promise<string>;
|
|
107
|
+
getFont(id: string): TextShader;
|
|
108
|
+
validateTextureReference(node: SceneNode | QuadNode): void;
|
|
109
|
+
/**
|
|
110
|
+
* Advanced and niche features
|
|
111
|
+
*/
|
|
112
|
+
extra: {
|
|
113
|
+
getRegisteredBundleIds: () => string[];
|
|
114
|
+
getLoadedBundleIds: () => string[];
|
|
115
|
+
/**
|
|
116
|
+
* Set the atlas coordinates for a texture.
|
|
117
|
+
*
|
|
118
|
+
* This should not be necessary for most use cases. This allows for UV precision
|
|
119
|
+
*
|
|
120
|
+
* @param id - The id of the texture to set the atlas coordinates for
|
|
121
|
+
* @param coords - The atlas coordinates to set
|
|
122
|
+
*/
|
|
123
|
+
setAtlasCoords: (id: TextureId, coords: AtlasCoords) => void;
|
|
124
|
+
/**
|
|
125
|
+
* Get the atlas coordinates for a texture.
|
|
126
|
+
*
|
|
127
|
+
* @param id - The id of the texture to get the atlas coordinates for
|
|
128
|
+
* @returns An array of the atlas coordinates for the texture
|
|
129
|
+
*/
|
|
130
|
+
getAtlasCoords: (id: TextureId) => AtlasCoords[];
|
|
131
|
+
/**
|
|
132
|
+
* Get the texture default offset
|
|
133
|
+
*
|
|
134
|
+
* @param id - The id of the texture to get the atlas coordinates for
|
|
135
|
+
* @returns Point of the texture's associated X,Y offset
|
|
136
|
+
*/
|
|
137
|
+
getTextureOffset: (id: TextureId) => Vec2;
|
|
138
|
+
/**
|
|
139
|
+
* Get diagnostics on texture atlas usage
|
|
140
|
+
*
|
|
141
|
+
* @returns Usage stats for texture atlases
|
|
142
|
+
*/
|
|
143
|
+
getAtlasUsage: () => {
|
|
144
|
+
/**
|
|
145
|
+
* The number of texture atlases that are currently unused
|
|
146
|
+
* and available to load textures into.
|
|
147
|
+
*/
|
|
148
|
+
available: number;
|
|
149
|
+
/**
|
|
150
|
+
* The number of texture atlases that are currently in use.
|
|
151
|
+
*/
|
|
152
|
+
used: number;
|
|
153
|
+
/**
|
|
154
|
+
* The total number of texture atlases that can be loaded.
|
|
155
|
+
*/
|
|
156
|
+
total: number;
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* Consume the next available atlas index.
|
|
160
|
+
*
|
|
161
|
+
*/
|
|
162
|
+
nextAvailableAtlasIndex: () => number;
|
|
163
|
+
/**
|
|
164
|
+
* Load a texture atlas from a CpuTextureAtlas.
|
|
165
|
+
*
|
|
166
|
+
* @param atlas - The texture atlas to load
|
|
167
|
+
* @returns The index of the atlas
|
|
168
|
+
*/
|
|
169
|
+
loadAtlas: (atlas: CpuTextureAtlas) => Promise<number>;
|
|
170
|
+
/**
|
|
171
|
+
* Unload an atlas from the texture atlas.
|
|
172
|
+
*
|
|
173
|
+
* @param atlasIndex - The index of the atlas to unload
|
|
174
|
+
*/
|
|
175
|
+
unloadAtlas: (atlasIndex: number) => Promise<void>;
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Destroy the texture atlas. This should free up ~4gb of gpu memory (and make all draw calls fail)
|
|
179
|
+
*/
|
|
180
|
+
destroy(): void;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=AssetManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AssetManager.d.ts","sourceRoot":"","sources":["../../src/textures/AssetManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAGpD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,eAAe,EAEf,iBAAiB,EAGlB,MAAM,SAAS,CAAC;AAGjB,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAC/B,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAC9B,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC;AAQ5B,qBAAa,YAAY;;IACvB,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC;gBAWhC,MAAM,EAAE,SAAS,EACjB,kBAAkB,EAAE,gBAAgB,EACpC,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,YAAY,GAAG,UAAyB;IAwBlD;;;;;OAKG;IACH,OAAO,CAAC,EAAE,EAAE,SAAS,GAAG,IAAI;IAS5B;;;;;OAKG;IACH,cAAc,CAAC,EAAE,EAAE,SAAS,GAAG,IAAI;IAWnC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,EAAE,SAAS,GAAG,OAAO;IAUjC;;OAEG;IACH,IAAI,QAAQ,+BAEX;IAED;;OAEG;IACH,IAAI,UAAU,aAEb;IAED;;;;;;;;;;;;;;;;OAgBG;IACG,YAAY,CAAC,IAAI,EAAE,iBAAiB,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAMtE;;;;;;;;;OASG;IACG,WAAW,CACf,EAAE,EAAE,SAAS,EACb,GAAG,EAAE,GAAG,GAAG,WAAW,EACtB,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC;;;;IAwCtC;;;;;;;;OAQG;IACG,cAAc,CAClB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,iBAAiB,GAAG,eAAe,GACxC,OAAO,CAAC,QAAQ,CAAC;IAapB;;;;OAIG;IACG,UAAU,CAAC,QAAQ,EAAE,QAAQ;IAmBnC;;;;;OAKG;IACG,YAAY,CAAC,QAAQ,EAAE,QAAQ;IAqBrC;;;;;;OAMG;IACG,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,iBAAiB,SAAM;IAqB5D,OAAO,CAAC,EAAE,EAAE,MAAM;IASlB,wBAAwB,CAAC,IAAI,EAAE,SAAS,GAAG,QAAQ;IAqNnD;;OAEG;IACH,KAAK;sCAEyB,MAAM,EAAE;kCAKZ,MAAM,EAAE;QAMhC;;;;;;;WAOG;6BACkB,SAAS,UAAU,WAAW;QAWnD;;;;;WAKG;6BACkB,SAAS,KAAG,WAAW,EAAE;QAS9C;;;;;WAKG;+BACoB,SAAS,KAAG,IAAI;QAUvC;;;;WAIG;;YAGC;;;eAGG;;YAEH;;eAEG;;YAEH;;eAEG;;;QAKP;;;WAGG;;QAWH;;;;;WAKG;2BACsB,eAAe;QAyCxC;;;;WAIG;kCAC6B,MAAM;MActC;IAmCF;;OAEG;IACH,OAAO;CAGR"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { TextureWithMetadata } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* A GPU-based texture processor that uses compute shaders to:
|
|
4
|
+
* 1. Find the non-transparent bounding box in a texture.
|
|
5
|
+
* 2. Crop the texture to that bounding box.
|
|
6
|
+
* 3. Create a fallback texture if no non-transparent pixels are found.
|
|
7
|
+
*/
|
|
8
|
+
export declare class TextureComputeShader {
|
|
9
|
+
#private;
|
|
10
|
+
constructor(device: GPUDevice, cropPipeline: GPUComputePipeline, boundPipeline: GPUComputePipeline, missingTexturePipeline: GPUComputePipeline);
|
|
11
|
+
/**
|
|
12
|
+
* Factory method to initialize pipelines and return an instance of TextureComputeShader.
|
|
13
|
+
*/
|
|
14
|
+
static create(device: GPUDevice): TextureComputeShader;
|
|
15
|
+
/**
|
|
16
|
+
* Main entry point to process a texture.
|
|
17
|
+
* Returns a cropped ImageBitmap and metadata.
|
|
18
|
+
*/
|
|
19
|
+
processTexture(textureWrapper: TextureWithMetadata): Promise<TextureWithMetadata>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=TextureComputeShader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextureComputeShader.d.ts","sourceRoot":"","sources":["../../src/textures/TextureComputeShader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAwBnD;;;;;GAKG;AACH,qBAAa,oBAAoB;;gBAQ7B,MAAM,EAAE,SAAS,EACjB,YAAY,EAAE,kBAAkB,EAChC,aAAa,EAAE,kBAAkB,EACjC,sBAAsB,EAAE,kBAAkB;IAiB5C;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS;IAU/B;;;OAGG;IACG,cAAc,CAClB,cAAc,EAAE,mBAAmB,GAClC,OAAO,CAAC,mBAAmB,CAAC;CAwQhC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/textures/mod.ts"],"names":[],"mappings":"AAAA,mBAAmB,SAAS,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const _default: "\n// ==============================\n// === BOUNDING BOX PASS =======\n// ==============================\n\n// Input texture from which to compute the non-transparent bounding box\n@group(0) @binding(0)\nvar input_texture: texture_2d<f32>;\n\n// Atomic bounding box storage structure\nstruct bounding_box_atomic {\n min_x: atomic<u32>,\n min_y: atomic<u32>,\n max_x: atomic<u32>,\n max_y: atomic<u32>,\n};\n\n// Storage buffer to hold atomic bounding box updates\n@group(0) @binding(1)\nvar<storage, read_write> bounds: bounding_box_atomic;\n\n// Compute shader to find the bounding box of non-transparent pixels\n@compute @workgroup_size(8, 8)\nfn find_bounds(@builtin(global_invocation_id) gid: vec3<u32>) {\n let size = textureDimensions(input_texture).xy;\n if (gid.x >= size.x || gid.y >= size.y) {\n return;\n }\n\n let pixel = textureLoad(input_texture, vec2<i32>(gid.xy), 0);\n if (pixel.a > 0.0) {\n atomicMin(&bounds.min_x, gid.x);\n atomicMin(&bounds.min_y, gid.y);\n atomicMax(&bounds.max_x, gid.x);\n atomicMax(&bounds.max_y, gid.y);\n }\n}\n\n// ==============================\n// === CROP + OUTPUT PASS ======\n// ==============================\n\n// Input texture from which cropped data is read\n@group(0) @binding(0)\nvar input_texture_crop: texture_2d<f32>;\n\n// Output texture where cropped image is written\n@group(0) @binding(1)\nvar output_texture: texture_storage_2d<rgba8unorm, write>;\n\n// Bounding box passed in as a uniform (not atomic anymore)\nstruct bounding_box_uniform {\n min_x: u32,\n min_y: u32,\n max_x: u32,\n max_y: u32,\n};\n\n@group(0) @binding(2)\nvar<uniform> bounds_uniform: bounding_box_uniform;\n\n// Struct to store both original and cropped texture dimensions\nstruct image_dimensions {\n original_width: u32,\n original_height: u32,\n cropped_width: u32,\n cropped_height: u32,\n};\n\n// Storage buffer to output the result dimensions\n@group(0) @binding(3)\nvar<storage, read_write> dimensions_out: image_dimensions;\n\n// Compute shader to crop the input texture to the bounding box and output it\n@compute @workgroup_size(8, 8)\nfn crop_and_output(@builtin(global_invocation_id) gid: vec3<u32>) {\n let size = textureDimensions(input_texture_crop).xy;\n\n let crop_width = bounds_uniform.max_x - bounds_uniform.min_x + 1u;\n let crop_height = bounds_uniform.max_y - bounds_uniform.min_y + 1u;\n\n if (gid.x >= crop_width || gid.y >= crop_height) {\n return;\n }\n\n let src_coord = vec2<i32>(\n i32(bounds_uniform.min_x + gid.x),\n i32(bounds_uniform.min_y + gid.y)\n );\n\n let dst_coord = vec2<i32>(i32(gid.x), i32(gid.y));\n let pixel = textureLoad(input_texture_crop, src_coord, 0);\n textureStore(output_texture, dst_coord, pixel);\n\n // Output dimensions from workgroup (0,0) only\n if (gid.x == 0u && gid.y == 0u) {\n dimensions_out.original_width = size.x;\n dimensions_out.original_height = size.y;\n dimensions_out.cropped_width = crop_width;\n dimensions_out.cropped_height = crop_height;\n }\n}\n\n// ==============================\n// === MISSING TEXTURE FILL ====\n// ==============================\n\n// Output texture to draw a fallback checkerboard\n@group(0) @binding(0)\nvar checker_texture: texture_storage_2d<rgba8unorm, write>;\n\n// Compute shader to fill a texture with a purple & green checkerboard\n@compute @workgroup_size(8, 8)\nfn missing_texture(@builtin(global_invocation_id) id: vec3<u32>) {\n let size = textureDimensions(checker_texture);\n if (id.x >= size.x || id.y >= size.y) {\n return;\n }\n\n let checker_size = 25u;\n let on_color = ((id.x / checker_size + id.y / checker_size) % 2u) == 0u;\n\n let color = select(\n vec4<f32>(0.5, 0.0, 0.5, 1.0), // Purple\n vec4<f32>(0.0, 1.0, 0.0, 1.0), // Green\n on_color\n );\n\n textureStore(checker_texture, vec2<i32>(id.xy), color);\n}\n";
|
|
2
|
+
export default _default;
|
|
3
|
+
//# sourceMappingURL=pixel-scraping.wgsl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pixel-scraping.wgsl.d.ts","sourceRoot":"","sources":["../../src/textures/pixel-scraping.wgsl.ts"],"names":[],"mappings":";AAAA,wBAkIE"}
|